This repository has been archived on 2025-01-27. You can view files and clone it, but cannot push or open issues or pull requests.
puyoskey-firefish/packages/client/src/components/MkPageWindow.vue
naskya d096da02e6 🎉 First Commit
release: v20240729

Co-authored-by: Laura Hausmann <laura@hausmann.dev>
Co-authored-by: GitLab CI <project_7_bot_1bfaee5701aed20091a86249a967a6c1@noreply.firefish.dev>
Co-authored-by: Hosted Weblate <hosted@weblate.org>
Co-authored-by: Saamkhaih Kyakya <70475761+hiohlan@users.noreply.github.com>

See merge request firefish/firefish!11214
2024-08-01 00:03:39 +09:00

163 lines
3.5 KiB
Vue

<template>
<XWindow
ref="windowEl"
:initial-width="500"
:initial-height="500"
:can-resize="true"
:close-button="true"
:buttons-left="buttonsLeft"
:buttons-right="buttonsRight"
:contextmenu="contextmenu"
class="page-window"
@closed="$emit('closed')"
>
<template #header>
<template v-if="pageMetadata?.value">
<i
v-if="pageMetadata.value.icon"
class="icon"
:class="pageMetadata.value.icon"
style="margin-right: 0.5em"
></i>
<span>{{ pageMetadata.value.title }}</span>
</template>
</template>
<div class="yrolvcoq" :style="{ background: pageMetadata?.value?.bg }">
<RouterView :router="router" />
</div>
</XWindow>
</template>
<script lang="ts" setup>
import type { ComputedRef } from "vue";
import { computed, provide, ref } from "vue";
import RouterView from "@/components/global/RouterView.vue";
import XWindow from "@/components/MkWindow.vue";
import { popout as _popout } from "@/scripts/popout";
import copyToClipboard from "@/scripts/copy-to-clipboard";
import { url } from "@/config";
import { mainRouter, routes } from "@/router";
import { Router } from "@/nirax";
import { i18n } from "@/i18n";
import type { PageMetadata } from "@/scripts/page-metadata";
import { provideMetadataReceiver } from "@/scripts/page-metadata";
import icon from "@/scripts/icon";
import * as os from "@/os";
const props = defineProps<{
initialPath: string;
}>();
defineEmits<{
(ev: "closed"): void;
}>();
const router = new Router(routes, props.initialPath);
const pageMetadata = ref<null | ComputedRef<PageMetadata>>();
const windowEl = ref<InstanceType<typeof XWindow>>();
const history = ref<{ path: string; key: string }[]>([
{
path: router.getCurrentPath(),
key: router.getCurrentKey(),
},
]);
const buttonsLeft = computed(() => {
if (history.value.length > 1) {
return [
{
icon: `${icon("ph-caret-left")}`,
onClick: back,
},
];
}
return [];
});
const buttonsRight = computed(() => {
const buttons = [
{
icon: `${icon("ph-arrows-out-simple")}`,
title: i18n.ts.showInPage,
onClick: expand,
},
];
return buttons;
});
router.addListener("push", (ctx) => {
history.value.push({ path: ctx.path, key: ctx.key });
});
provide("router", router);
provideMetadataReceiver((info) => {
pageMetadata.value = info;
});
provide("shouldOmitHeaderTitle", true);
provide("shouldBackButton", false);
provide("shouldHeaderThin", true);
const contextmenu = computed(() => [
{
icon: `${icon("ph-arrows-out-simple")}`,
text: i18n.ts.showInPage,
action: expand,
},
{
icon: `${icon("ph-arrow-square-out")}`,
text: i18n.ts.popout,
action: popout,
},
{
icon: `${icon("ph-arrow-square-out")}`,
text: i18n.ts.openInNewTab,
action: () => {
window.open(url + router.getCurrentPath(), "_blank");
windowEl.value!.close();
},
},
{
icon: `${icon("ph-link-simple")}`,
text: i18n.ts.copyLink,
action: () => {
copyToClipboard(url + router.getCurrentPath());
os.success();
},
},
]);
function back() {
history.value.pop();
router.replace(
history.value[history.value.length - 1].path,
history.value[history.value.length - 1].key,
);
}
function close() {
windowEl.value!.close();
}
function expand() {
mainRouter.push(router.getCurrentPath(), "forcePage");
windowEl.value!.close();
}
function popout() {
_popout(router.getCurrentPath(), windowEl.value!.$el);
windowEl.value!.close();
}
defineExpose({
close,
});
</script>
<style lang="scss" scoped>
.yrolvcoq {
overscroll-behavior: none;
min-height: 100%;
background: var(--bg);
}
</style>