2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
<template>
|
2023-01-06 01:59:17 +01:00
|
|
|
<MkWindow
|
2022-06-20 10:38:49 +02:00
|
|
|
ref="windowEl"
|
2023-05-19 06:58:09 +02:00
|
|
|
:initialWidth="500"
|
|
|
|
:initialHeight="500"
|
|
|
|
:canResize="true"
|
|
|
|
:closeButton="true"
|
|
|
|
:buttonsLeft="buttonsLeft"
|
|
|
|
:buttonsRight="buttonsRight"
|
2020-10-24 18:21:41 +02:00
|
|
|
:contextmenu="contextmenu"
|
|
|
|
@closed="$emit('closed')"
|
|
|
|
>
|
2020-10-17 13:12:00 +02:00
|
|
|
<template #header>
|
2022-06-20 10:38:49 +02:00
|
|
|
<template v-if="pageMetadata?.value">
|
2023-05-15 09:25:44 +02:00
|
|
|
<i v-if="pageMetadata.value.icon" :class="pageMetadata.value.icon" style="margin-right: 0.5em;"></i>
|
2022-06-20 10:38:49 +02:00
|
|
|
<span>{{ pageMetadata.value.title }}</span>
|
2021-10-08 15:03:06 +02:00
|
|
|
</template>
|
|
|
|
</template>
|
2021-12-24 04:34:24 +01:00
|
|
|
|
2023-07-08 08:30:36 +02:00
|
|
|
<div ref="contents" :class="$style.root" style="container-type: inline-size;">
|
2023-02-22 09:43:10 +01:00
|
|
|
<RouterView :key="reloadCount" :router="router"/>
|
2020-10-17 13:12:00 +02:00
|
|
|
</div>
|
2023-01-06 01:59:17 +01:00
|
|
|
</MkWindow>
|
2020-10-17 13:12:00 +02:00
|
|
|
</template>
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
<script lang="ts" setup>
|
2023-12-07 06:42:09 +01:00
|
|
|
import { ComputedRef, onMounted, onUnmounted, provide, shallowRef, ref, computed } from 'vue';
|
2022-08-30 17:24:33 +02:00
|
|
|
import RouterView from '@/components/global/RouterView.vue';
|
2023-01-06 01:59:17 +01:00
|
|
|
import MkWindow from '@/components/MkWindow.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { popout as _popout } from '@/scripts/popout.js';
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
|
|
|
|
import { url } from '@/config.js';
|
|
|
|
import { mainRouter, routes, page } from '@/router.js';
|
|
|
|
import { $i } from '@/account.js';
|
2023-07-08 08:30:36 +02:00
|
|
|
import { Router, useScrollPositionManager } from '@/nirax';
|
2023-09-19 09:37:43 +02:00
|
|
|
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';
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
initialPath: string;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
defineEmits<{
|
|
|
|
(ev: 'closed'): void;
|
|
|
|
}>();
|
|
|
|
|
2023-07-08 01:58:35 +02:00
|
|
|
const router = new Router(routes, props.initialPath, !!$i, page(() => import('@/pages/not-found.vue')));
|
2022-06-20 10:38:49 +02:00
|
|
|
|
2023-07-08 08:30:36 +02:00
|
|
|
const contents = shallowRef<HTMLElement>();
|
2023-12-07 06:42:09 +01:00
|
|
|
const pageMetadata = ref<null | ComputedRef<PageMetadata>>();
|
|
|
|
const windowEl = shallowRef<InstanceType<typeof MkWindow>>();
|
|
|
|
const history = ref<{ path: string; key: any; }[]>([{
|
2022-07-02 05:12:10 +02:00
|
|
|
path: router.getCurrentPath(),
|
|
|
|
key: router.getCurrentKey(),
|
|
|
|
}]);
|
2023-12-07 06:42:09 +01:00
|
|
|
const buttonsLeft = computed(() => {
|
2022-06-20 10:38:49 +02:00
|
|
|
const buttons = [];
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
if (history.value.length > 1) {
|
2022-06-20 10:38:49 +02:00
|
|
|
buttons.push({
|
2023-11-03 23:20:53 +01:00
|
|
|
icon: 'ph-arrow-left ph-bold ph-lg',
|
2022-06-20 10:38:49 +02:00
|
|
|
onClick: back,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return buttons;
|
|
|
|
});
|
2023-12-07 06:42:09 +01:00
|
|
|
const buttonsRight = computed(() => {
|
2022-06-20 10:38:49 +02:00
|
|
|
const buttons = [{
|
2023-09-30 21:53:52 +02:00
|
|
|
icon: 'ph-arrow-clockwise ph-bold ph-lg',
|
2023-02-22 09:43:10 +01:00
|
|
|
title: i18n.ts.reload,
|
|
|
|
onClick: reload,
|
|
|
|
}, {
|
2023-11-03 23:20:53 +01:00
|
|
|
icon: 'ph-eject ph-bold ph-lg',
|
2022-06-20 10:38:49 +02:00
|
|
|
title: i18n.ts.showInPage,
|
|
|
|
onClick: expand,
|
|
|
|
}];
|
|
|
|
|
|
|
|
return buttons;
|
|
|
|
});
|
2023-12-07 06:42:09 +01:00
|
|
|
const reloadCount = ref(0);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
router.addListener('push', ctx => {
|
2023-12-07 06:42:09 +01:00
|
|
|
history.value.push({ path: ctx.path, key: ctx.key });
|
2022-06-20 10:38:49 +02:00
|
|
|
});
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
provide('router', router);
|
|
|
|
provideMetadataReceiver((info) => {
|
2023-12-07 06:42:09 +01:00
|
|
|
pageMetadata.value = info;
|
2022-06-20 10:38:49 +02:00
|
|
|
});
|
|
|
|
provide('shouldOmitHeaderTitle', true);
|
|
|
|
provide('shouldHeaderThin', true);
|
2023-01-07 06:33:33 +01:00
|
|
|
provide('forceSpacerMin', true);
|
2023-12-03 19:09:15 +01:00
|
|
|
provide('shouldBackButton', false);
|
2022-06-20 10:38:49 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const contextmenu = computed(() => ([{
|
2023-11-03 23:20:53 +01:00
|
|
|
icon: 'ph-eject ph-bold ph-lg',
|
2022-06-20 10:38:49 +02:00
|
|
|
text: i18n.ts.showInPage,
|
|
|
|
action: expand,
|
|
|
|
}, {
|
2023-10-01 00:46:42 +02:00
|
|
|
icon: 'ph-frame-corners ph-bold ph-lg',
|
2022-06-20 10:38:49 +02:00
|
|
|
text: i18n.ts.popout,
|
|
|
|
action: popout,
|
|
|
|
}, {
|
2023-09-30 21:53:52 +02:00
|
|
|
icon: 'ph-arrow-square-out ph-bold ph-lg',
|
2022-06-20 10:38:49 +02:00
|
|
|
text: i18n.ts.openInNewTab,
|
|
|
|
action: () => {
|
2023-12-08 09:48:18 +01:00
|
|
|
window.open(url + router.getCurrentPath(), '_blank', 'noopener');
|
2023-12-07 06:42:09 +01:00
|
|
|
windowEl.value.close();
|
2020-10-28 14:21:53 +01:00
|
|
|
},
|
2022-06-20 10:38:49 +02:00
|
|
|
}, {
|
2023-09-30 21:53:52 +02:00
|
|
|
icon: 'ph-link ph-bold ph-lg',
|
2022-06-20 10:38:49 +02:00
|
|
|
text: i18n.ts.copyLink,
|
|
|
|
action: () => {
|
|
|
|
copyToClipboard(url + router.getCurrentPath());
|
2020-10-24 18:21:41 +02:00
|
|
|
},
|
2022-06-20 10:38:49 +02:00
|
|
|
}]));
|
2020-10-24 18:21:41 +02:00
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
function back() {
|
2023-12-07 06:42:09 +01:00
|
|
|
history.value.pop();
|
|
|
|
router.replace(history.value.at(-1)!.path, history.value.at(-1)!.key);
|
2022-06-20 10:38:49 +02:00
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2023-02-22 09:43:10 +01:00
|
|
|
function reload() {
|
2023-12-07 06:42:09 +01:00
|
|
|
reloadCount.value++;
|
2023-02-22 09:43:10 +01:00
|
|
|
}
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
function close() {
|
2023-12-07 06:42:09 +01:00
|
|
|
windowEl.value.close();
|
2022-06-20 10:38:49 +02:00
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
function expand() {
|
2022-07-16 22:12:22 +02:00
|
|
|
mainRouter.push(router.getCurrentPath(), 'forcePage');
|
2023-12-07 06:42:09 +01:00
|
|
|
windowEl.value.close();
|
2022-06-20 10:38:49 +02:00
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
function popout() {
|
2023-12-07 06:42:09 +01:00
|
|
|
_popout(router.getCurrentPath(), windowEl.value.$el);
|
|
|
|
windowEl.value.close();
|
2022-06-20 10:38:49 +02:00
|
|
|
}
|
|
|
|
|
2023-07-08 08:30:36 +02:00
|
|
|
useScrollPositionManager(() => getScrollContainer(contents.value), router);
|
|
|
|
|
2023-01-21 07:30:29 +01:00
|
|
|
onMounted(() => {
|
|
|
|
openingWindowsCount.value++;
|
|
|
|
if (openingWindowsCount.value >= 3) {
|
|
|
|
claimAchievement('open3windows');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
openingWindowsCount.value--;
|
|
|
|
});
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
defineExpose({
|
|
|
|
close,
|
2020-10-17 13:12:00 +02:00
|
|
|
});
|
|
|
|
</script>
|
2020-10-19 12:29:04 +02:00
|
|
|
|
2023-01-14 09:23:49 +01:00
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2023-11-04 00:56:48 +01:00
|
|
|
overscroll-behavior: contain;
|
2023-10-30 01:12:20 +01:00
|
|
|
|
2021-04-10 05:40:50 +02:00
|
|
|
min-height: 100%;
|
2022-07-02 07:00:37 +02:00
|
|
|
background: var(--bg);
|
2023-01-07 06:33:33 +01:00
|
|
|
|
|
|
|
--margin: var(--marginHalf);
|
2020-10-19 12:29:04 +02:00
|
|
|
}
|
|
|
|
</style>
|