mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-25 21:43:09 +02:00
185 lines
4.4 KiB
Vue
185 lines
4.4 KiB
Vue
<!--
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
-->
|
|
|
|
<template>
|
|
<MkWindow
|
|
ref="windowEl"
|
|
:initialWidth="500"
|
|
:initialHeight="500"
|
|
:canResize="true"
|
|
:closeButton="true"
|
|
:buttonsLeft="buttonsLeft"
|
|
:buttonsRight="buttonsRight"
|
|
:contextmenu="contextmenu"
|
|
@closed="$emit('closed')"
|
|
>
|
|
<template #header>
|
|
<template v-if="pageMetadata?.value">
|
|
<i v-if="pageMetadata.value.icon" :class="pageMetadata.value.icon" style="margin-right: 0.5em;"></i>
|
|
<span>{{ pageMetadata.value.title }}</span>
|
|
</template>
|
|
</template>
|
|
|
|
<div ref="contents" :class="$style.root" style="container-type: inline-size;">
|
|
<RouterView :key="reloadCount" :router="windowRouter"/>
|
|
</div>
|
|
</MkWindow>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { computed, ComputedRef, onMounted, onUnmounted, provide, ref, shallowRef } from 'vue';
|
|
import RouterView from '@/components/global/RouterView.vue';
|
|
import MkWindow from '@/components/MkWindow.vue';
|
|
import { popout as _popout } from '@/scripts/popout.js';
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
|
|
import { url } from '@/config.js';
|
|
import { useScrollPositionManager } from '@/nirax.js';
|
|
import { i18n } from '@/i18n.js';
|
|
import { PageMetadata, provideMetadataReceiver } from '@/scripts/page-metadata.js';
|
|
import { openingWindowsCount } from '@/os.js';
|
|
import { claimAchievement } from '@/scripts/achievements.js';
|
|
import { getScrollContainer } from '@/scripts/scroll.js';
|
|
import { useRouterFactory } from '@/router/supplier.js';
|
|
import { mainRouter } from '@/router/main.js';
|
|
|
|
const props = defineProps<{
|
|
initialPath: string;
|
|
}>();
|
|
|
|
defineEmits<{
|
|
(ev: 'closed'): void;
|
|
}>();
|
|
|
|
const routerFactory = useRouterFactory();
|
|
const windowRouter = routerFactory(props.initialPath);
|
|
|
|
const contents = shallowRef<HTMLElement | null>(null);
|
|
const pageMetadata = ref<null | ComputedRef<PageMetadata>>();
|
|
const windowEl = shallowRef<InstanceType<typeof MkWindow>>();
|
|
const history = ref<{ path: string; key: any; }[]>([{
|
|
path: windowRouter.getCurrentPath(),
|
|
key: windowRouter.getCurrentKey(),
|
|
}]);
|
|
const buttonsLeft = computed(() => {
|
|
const buttons: Record<string, unknown>[] = [];
|
|
|
|
if (history.value.length > 1) {
|
|
buttons.push({
|
|
icon: 'ph-arrow-left ph-bold ph-lg',
|
|
onClick: back,
|
|
});
|
|
}
|
|
|
|
return buttons;
|
|
});
|
|
const buttonsRight = computed(() => {
|
|
const buttons = [{
|
|
icon: 'ph-arrows-clockwise ph-bold ph-lg',
|
|
title: i18n.ts.reload,
|
|
onClick: reload,
|
|
}, {
|
|
icon: 'ph-eject ph-bold ph-lg',
|
|
title: i18n.ts.showInPage,
|
|
onClick: expand,
|
|
}];
|
|
|
|
return buttons;
|
|
});
|
|
const reloadCount = ref(0);
|
|
|
|
windowRouter.addListener('push', ctx => {
|
|
history.value.push({ path: ctx.path, key: ctx.key });
|
|
});
|
|
|
|
windowRouter.addListener('replace', ctx => {
|
|
history.value.pop();
|
|
history.value.push({ path: ctx.path, key: ctx.key });
|
|
});
|
|
|
|
windowRouter.init();
|
|
|
|
provide('router', windowRouter);
|
|
provideMetadataReceiver((info) => {
|
|
pageMetadata.value = info;
|
|
});
|
|
provide('shouldOmitHeaderTitle', true);
|
|
provide('shouldHeaderThin', true);
|
|
provide('forceSpacerMin', true);
|
|
provide('shouldBackButton', false);
|
|
|
|
const contextmenu = computed(() => ([{
|
|
icon: 'ph-eject ph-bold ph-lg',
|
|
text: i18n.ts.showInPage,
|
|
action: expand,
|
|
}, {
|
|
icon: 'ph-frame-corners ph-bold ph-lg',
|
|
text: i18n.ts.popout,
|
|
action: popout,
|
|
}, {
|
|
icon: 'ph-arrow-square-out ph-bold ph-lg',
|
|
text: i18n.ts.openInNewTab,
|
|
action: () => {
|
|
window.open(url + windowRouter.getCurrentPath(), '_blank', 'noopener');
|
|
windowEl.value?.close();
|
|
},
|
|
}, {
|
|
icon: 'ph-link ph-bold ph-lg',
|
|
text: i18n.ts.copyLink,
|
|
action: () => {
|
|
copyToClipboard(url + windowRouter.getCurrentPath());
|
|
},
|
|
}]));
|
|
|
|
function back() {
|
|
history.value.pop();
|
|
windowRouter.replace(history.value.at(-1)!.path, history.value.at(-1)!.key);
|
|
}
|
|
|
|
function reload() {
|
|
reloadCount.value++;
|
|
}
|
|
|
|
function close() {
|
|
windowEl.value?.close();
|
|
}
|
|
|
|
function expand() {
|
|
mainRouter.push(windowRouter.getCurrentPath(), 'forcePage');
|
|
windowEl.value?.close();
|
|
}
|
|
|
|
function popout() {
|
|
_popout(windowRouter.getCurrentPath(), windowEl.value?.$el);
|
|
windowEl.value?.close();
|
|
}
|
|
|
|
useScrollPositionManager(() => getScrollContainer(contents.value), windowRouter);
|
|
|
|
onMounted(() => {
|
|
openingWindowsCount.value++;
|
|
if (openingWindowsCount.value >= 3) {
|
|
claimAchievement('open3windows');
|
|
}
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
openingWindowsCount.value--;
|
|
});
|
|
|
|
defineExpose({
|
|
close,
|
|
});
|
|
</script>
|
|
|
|
<style lang="scss" module>
|
|
.root {
|
|
overscroll-behavior: contain;
|
|
|
|
min-height: 100%;
|
|
background: var(--bg);
|
|
|
|
--margin: var(--marginHalf);
|
|
}
|
|
</style>
|