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);
|
||||||
os.popup(defineAsyncComponent(() => import('@/components/url-preview-popup.vue')), {
|
const url = new URL(props.url);
|
||||||
showing,
|
let el: HTMLElement | null = $ref(null);
|
||||||
url: props.url,
|
|
||||||
source: el.value,
|
|
||||||
}, {}, 'closed');
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
let schema = $ref(url.protocol);
|
||||||
local,
|
let hostname = $ref(decodePunycode(url.hostname));
|
||||||
schema: url.protocol,
|
let port = $ref(url.port);
|
||||||
hostname: decodePunycode(url.hostname),
|
let pathname = $ref(safeURIDecode(url.pathname));
|
||||||
port: url.port,
|
let query = $ref(safeURIDecode(url.search));
|
||||||
pathname: safeURIDecode(url.pathname),
|
let hash = $ref(safeURIDecode(url.hash));
|
||||||
query: safeURIDecode(url.search),
|
let attr = $ref(self ? 'to' : 'href');
|
||||||
hash: safeURIDecode(url.hash),
|
let target = $ref(self ? null : '_blank');
|
||||||
self,
|
|
||||||
attr: self ? 'to' : 'href',
|
useTooltip($$(el), (showing) => {
|
||||||
target: self ? null : '_blank',
|
os.popup(defineAsyncComponent(() => import('@/components/url-preview-popup.vue')), {
|
||||||
el,
|
showing,
|
||||||
};
|
url: props.url,
|
||||||
},
|
source: el,
|
||||||
|
}, {}, 'closed');
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue