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