forked from FoundKeyGang/FoundKey
refactor: url.vue to composition api
This commit is contained in:
parent
6a3d98fbc1
commit
16e9cf91f7
1 changed files with 29 additions and 42 deletions
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<component
|
<component
|
||||||
:is="self ? 'MkA' : 'a'" ref="el" class="ieqqeuvs _link" :[attr]="self ? url.substr(local.length) : url" :rel="rel" :target="target"
|
:is="self ? 'MkA' : 'a'" ref="el" class="ieqqeuvs _link" :[attr]="self ? url.slice(local.length) : url" :rel="rel" :target="target"
|
||||||
@contextmenu.stop="() => {}"
|
@contextmenu.stop="() => {}"
|
||||||
>
|
>
|
||||||
<template v-if="!self">
|
<template v-if="!self">
|
||||||
|
@ -11,60 +11,47 @@
|
||||||
<template v-if="pathname === '/' && self">
|
<template v-if="pathname === '/' && self">
|
||||||
<span class="self">{{ hostname }}</span>
|
<span class="self">{{ hostname }}</span>
|
||||||
</template>
|
</template>
|
||||||
<span v-if="pathname != ''" class="pathname">{{ self ? pathname.substr(1) : pathname }}</span>
|
<span v-if="pathname != ''" class="pathname">{{ self ? pathname.slice(1) : pathname }}</span>
|
||||||
<span class="query">{{ query }}</span>
|
<span class="query">{{ query }}</span>
|
||||||
<span class="hash">{{ hash }}</span>
|
<span class="hash">{{ hash }}</span>
|
||||||
<i v-if="target === '_blank'" class="fas fa-external-link-square-alt icon"></i>
|
<i v-if="target === '_blank'" class="fas fa-external-link-square-alt icon"></i>
|
||||||
</component>
|
</component>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineAsyncComponent, defineComponent, ref } from 'vue';
|
import { defineAsyncComponent } from 'vue';
|
||||||
import { toUnicode as decodePunycode } from 'punycode/';
|
import { toUnicode as decodePunycode } from 'punycode/';
|
||||||
import { url as local } from '@/config';
|
import { url as local } from '@/config';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
import { useTooltip } from '@/scripts/use-tooltip';
|
import { useTooltip } from '@/scripts/use-tooltip';
|
||||||
import { safeURIDecode } from '@/scripts/safe-uri-decode';
|
import { safeURIDecode } from '@/scripts/safe-uri-decode';
|
||||||
|
|
||||||
export default defineComponent({
|
const props = withDefaults(defineProps<{
|
||||||
props: {
|
url: string;
|
||||||
url: {
|
rel?: string | null;
|
||||||
type: String,
|
}>(), {
|
||||||
required: true,
|
rel: null,
|
||||||
},
|
});
|
||||||
rel: {
|
|
||||||
type: String,
|
|
||||||
required: false,
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
setup(props) {
|
|
||||||
const self = props.url.startsWith(local);
|
|
||||||
const url = new URL(props.url);
|
|
||||||
const el = ref();
|
|
||||||
|
|
||||||
useTooltip(el, (showing) => {
|
const self = props.url.startsWith(local);
|
||||||
|
const url = new URL(props.url);
|
||||||
|
let el: HTMLElement | null = $ref(null);
|
||||||
|
|
||||||
|
let schema = $ref(url.protocol);
|
||||||
|
let hostname = $ref(decodePunycode(url.hostname));
|
||||||
|
let port = $ref(url.port);
|
||||||
|
let pathname = $ref(safeURIDecode(url.pathname));
|
||||||
|
let query = $ref(safeURIDecode(url.search));
|
||||||
|
let hash = $ref(safeURIDecode(url.hash));
|
||||||
|
let attr = $ref(self ? 'to' : 'href');
|
||||||
|
let target = $ref(self ? null : '_blank');
|
||||||
|
|
||||||
|
useTooltip($$(el), (showing) => {
|
||||||
os.popup(defineAsyncComponent(() => import('@/components/url-preview-popup.vue')), {
|
os.popup(defineAsyncComponent(() => import('@/components/url-preview-popup.vue')), {
|
||||||
showing,
|
showing,
|
||||||
url: props.url,
|
url: props.url,
|
||||||
source: el.value,
|
source: el,
|
||||||
}, {}, 'closed');
|
}, {}, 'closed');
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
local,
|
|
||||||
schema: url.protocol,
|
|
||||||
hostname: decodePunycode(url.hostname),
|
|
||||||
port: url.port,
|
|
||||||
pathname: safeURIDecode(url.pathname),
|
|
||||||
query: safeURIDecode(url.search),
|
|
||||||
hash: safeURIDecode(url.hash),
|
|
||||||
self,
|
|
||||||
attr: self ? 'to' : 'href',
|
|
||||||
target: self ? null : '_blank',
|
|
||||||
el,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue