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