2023-07-27 00:31:52 -05:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2023-01-04 22:59:48 -06:00
|
|
|
<template>
|
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
2023-05-19 06:52:15 -05:00
|
|
|
<MkSpacer :contentMax="700">
|
2023-03-31 23:42:40 -05:00
|
|
|
<Transition :name="defaultStore.state.animation ? 'fade' : ''" mode="out-in">
|
2023-01-04 22:59:48 -06:00
|
|
|
<div v-if="flash" :key="flash.id">
|
2023-03-31 23:42:40 -05:00
|
|
|
<Transition :name="defaultStore.state.animation ? 'zoom' : ''" mode="out-in">
|
2023-01-04 22:59:48 -06:00
|
|
|
<div v-if="started" :class="$style.started">
|
|
|
|
<div class="main _panel">
|
|
|
|
<MkAsUi v-if="root" :component="root" :components="components"/>
|
|
|
|
</div>
|
|
|
|
<div class="actions _panel">
|
2023-05-19 06:52:15 -05:00
|
|
|
<MkButton v-if="flash.isLiked" v-tooltip="i18n.ts.unlike" asLike class="button" rounded primary @click="unlike()"><i class="ti ti-heart"></i><span v-if="flash.likedCount > 0" style="margin-left: 6px;">{{ flash.likedCount }}</span></MkButton>
|
|
|
|
<MkButton v-else v-tooltip="i18n.ts.like" asLike class="button" rounded @click="like()"><i class="ti ti-heart"></i><span v-if="flash.likedCount > 0" style="margin-left: 6px;">{{ flash.likedCount }}</span></MkButton>
|
2023-01-04 22:59:48 -06:00
|
|
|
<MkButton v-tooltip="i18n.ts.shareWithNote" class="button" rounded @click="shareWithNote"><i class="ti ti-repeat ti-fw"></i></MkButton>
|
2023-11-29 17:15:13 -06:00
|
|
|
<MkButton v-tooltip="i18n.ts.copyLink" class="button" rounded @click="copyLink"><i class="ti ti-link ti-fw"></i></MkButton>
|
|
|
|
<MkButton v-if="isSupportShare()" v-tooltip="i18n.ts.share" class="button" rounded @click="share"><i class="ti ti-share ti-fw"></i></MkButton>
|
2023-01-04 22:59:48 -06:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-else :class="$style.ready">
|
|
|
|
<div class="_panel main">
|
|
|
|
<div class="title">{{ flash.title }}</div>
|
|
|
|
<div class="summary">{{ flash.summary }}</div>
|
|
|
|
<MkButton class="start" gradate rounded large @click="start">Play</MkButton>
|
|
|
|
<div class="info">
|
|
|
|
<span v-tooltip="i18n.ts.numberOfLikes"><i class="ti ti-heart"></i> {{ flash.likedCount }}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Transition>
|
2023-05-19 06:52:15 -05:00
|
|
|
<MkFolder :defaultOpen="false" :max-height="280" class="_margin">
|
2023-01-04 22:59:48 -06:00
|
|
|
<template #icon><i class="ti ti-code"></i></template>
|
|
|
|
<template #label>{{ i18n.ts._play.viewSource }}</template>
|
|
|
|
|
2023-10-29 00:12:40 -05:00
|
|
|
<MkCode :code="flash.script" lang="is" :inline="false" class="_monospace"/>
|
2023-01-08 18:41:25 -06:00
|
|
|
</MkFolder>
|
2023-01-04 22:59:48 -06:00
|
|
|
<div :class="$style.footer">
|
|
|
|
<Mfm :text="`By @${flash.user.username}`"/>
|
|
|
|
<div class="date">
|
|
|
|
<div v-if="flash.createdAt != flash.updatedAt"><i class="ti ti-clock"></i> {{ i18n.ts.updatedAt }}: <MkTime :time="flash.updatedAt" mode="detail"/></div>
|
|
|
|
<div><i class="ti ti-clock"></i> {{ i18n.ts.createdAt }}: <MkTime :time="flash.createdAt" mode="detail"/></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<MkA v-if="$i && $i.id === flash.userId" :to="`/play/${flash.id}/edit`" style="color: var(--accent);">{{ i18n.ts._play.editThisPage }}</MkA>
|
|
|
|
<MkAd :prefer="['horizontal', 'horizontal-big']"/>
|
|
|
|
</div>
|
|
|
|
<MkError v-else-if="error" @retry="fetchPage()"/>
|
|
|
|
<MkLoading v-else/>
|
|
|
|
</Transition>
|
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-12-06 23:42:09 -06:00
|
|
|
import { computed, onDeactivated, onUnmounted, Ref, ref, watch, shallowRef } from 'vue';
|
2023-02-16 08:09:41 -06:00
|
|
|
import { Interpreter, Parser, values } from '@syuilo/aiscript';
|
2023-01-04 22:59:48 -06:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-09-19 02:37:43 -05:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { url } from '@/config.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
2023-01-04 22:59:48 -06:00
|
|
|
import MkAsUi from '@/components/MkAsUi.vue';
|
2023-09-19 02:37:43 -05:00
|
|
|
import { AsUiComponent, AsUiRoot, registerAsUiLib } from '@/scripts/aiscript/ui.js';
|
|
|
|
import { createAiScriptEnv } from '@/scripts/aiscript/api.js';
|
2023-01-08 18:41:25 -06:00
|
|
|
import MkFolder from '@/components/MkFolder.vue';
|
2023-02-28 02:38:43 -06:00
|
|
|
import MkCode from '@/components/MkCode.vue';
|
2023-09-19 02:37:43 -05:00
|
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
import { $i } from '@/account.js';
|
2023-11-29 17:15:13 -06:00
|
|
|
import { isSupportShare } from '@/scripts/navigator.js';
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
|
2023-01-04 22:59:48 -06:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
id: string;
|
|
|
|
}>();
|
|
|
|
|
2023-12-06 23:42:09 -06:00
|
|
|
const flash = ref(null);
|
|
|
|
const error = ref(null);
|
2023-01-04 22:59:48 -06:00
|
|
|
|
|
|
|
function fetchFlash() {
|
2023-12-06 23:42:09 -06:00
|
|
|
flash.value = null;
|
2023-01-04 22:59:48 -06:00
|
|
|
os.api('flash/show', {
|
|
|
|
flashId: props.id,
|
|
|
|
}).then(_flash => {
|
2023-12-06 23:42:09 -06:00
|
|
|
flash.value = _flash;
|
2023-01-04 22:59:48 -06:00
|
|
|
}).catch(err => {
|
2023-12-06 23:42:09 -06:00
|
|
|
error.value = err;
|
2023-01-04 22:59:48 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-11-29 17:15:13 -06:00
|
|
|
function copyLink() {
|
2023-12-06 23:42:09 -06:00
|
|
|
copyToClipboard(`${url}/play/${flash.value.id}`);
|
2023-11-29 17:15:13 -06:00
|
|
|
os.success();
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:59:48 -06:00
|
|
|
function share() {
|
|
|
|
navigator.share({
|
2023-12-06 23:42:09 -06:00
|
|
|
title: flash.value.title,
|
|
|
|
text: flash.value.summary,
|
|
|
|
url: `${url}/play/${flash.value.id}`,
|
2023-01-04 22:59:48 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function shareWithNote() {
|
|
|
|
os.post({
|
2023-12-06 23:42:09 -06:00
|
|
|
initialText: `${flash.value.title} ${url}/play/${flash.value.id}`,
|
2023-01-04 22:59:48 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function like() {
|
|
|
|
os.apiWithDialog('flash/like', {
|
2023-12-06 23:42:09 -06:00
|
|
|
flashId: flash.value.id,
|
2023-01-04 22:59:48 -06:00
|
|
|
}).then(() => {
|
2023-12-06 23:42:09 -06:00
|
|
|
flash.value.isLiked = true;
|
|
|
|
flash.value.likedCount++;
|
2023-01-04 22:59:48 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function unlike() {
|
|
|
|
const confirm = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.ts.unlikeConfirm,
|
|
|
|
});
|
|
|
|
if (confirm.canceled) return;
|
|
|
|
os.apiWithDialog('flash/unlike', {
|
2023-12-06 23:42:09 -06:00
|
|
|
flashId: flash.value.id,
|
2023-01-04 22:59:48 -06:00
|
|
|
}).then(() => {
|
2023-12-06 23:42:09 -06:00
|
|
|
flash.value.isLiked = false;
|
|
|
|
flash.value.likedCount--;
|
2023-01-04 22:59:48 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
watch(() => props.id, fetchFlash, { immediate: true });
|
|
|
|
|
|
|
|
const parser = new Parser();
|
|
|
|
|
2023-12-06 23:42:09 -06:00
|
|
|
const started = ref(false);
|
|
|
|
const aiscript = shallowRef<Interpreter | null>(null);
|
2023-01-04 22:59:48 -06:00
|
|
|
const root = ref<AsUiRoot>();
|
2023-12-06 23:42:09 -06:00
|
|
|
const components = ref<Ref<AsUiComponent>[]>([]);
|
2023-01-04 22:59:48 -06:00
|
|
|
|
|
|
|
function start() {
|
2023-12-06 23:42:09 -06:00
|
|
|
started.value = true;
|
2023-01-04 22:59:48 -06:00
|
|
|
run();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function run() {
|
2023-12-06 23:42:09 -06:00
|
|
|
if (aiscript.value) aiscript.value.abort();
|
2023-01-04 22:59:48 -06:00
|
|
|
|
2023-12-06 23:42:09 -06:00
|
|
|
aiscript.value = new Interpreter({
|
2023-01-04 22:59:48 -06:00
|
|
|
...createAiScriptEnv({
|
2023-12-06 23:42:09 -06:00
|
|
|
storageKey: 'flash:' + flash.value.id,
|
2023-01-04 22:59:48 -06:00
|
|
|
}),
|
2023-12-06 23:42:09 -06:00
|
|
|
...registerAsUiLib(components.value, (_root) => {
|
2023-01-04 22:59:48 -06:00
|
|
|
root.value = _root.value;
|
|
|
|
}),
|
2023-12-06 23:42:09 -06:00
|
|
|
THIS_ID: values.STR(flash.value.id),
|
|
|
|
THIS_URL: values.STR(`${url}/play/${flash.value.id}`),
|
2023-01-04 22:59:48 -06:00
|
|
|
}, {
|
|
|
|
in: (q) => {
|
|
|
|
return new Promise(ok => {
|
|
|
|
os.inputText({
|
|
|
|
title: q,
|
2023-12-15 17:57:45 -06:00
|
|
|
}).then(({ result: a }) => {
|
|
|
|
ok(a ?? '');
|
2023-01-04 22:59:48 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
out: (value) => {
|
|
|
|
// nop
|
|
|
|
},
|
|
|
|
log: (type, params) => {
|
|
|
|
// nop
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
let ast;
|
|
|
|
try {
|
2023-12-06 23:42:09 -06:00
|
|
|
ast = parser.parse(flash.value.script);
|
2023-01-04 22:59:48 -06:00
|
|
|
} catch (err) {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
text: 'Syntax error :(',
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
2023-12-06 23:42:09 -06:00
|
|
|
await aiscript.value.exec(ast);
|
2023-01-04 22:59:48 -06:00
|
|
|
} catch (err) {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
title: 'AiScript Error',
|
|
|
|
text: err.message,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeactivated(() => {
|
2023-12-06 23:42:09 -06:00
|
|
|
if (aiscript.value) aiscript.value.abort();
|
2023-01-04 22:59:48 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
2023-12-06 23:42:09 -06:00
|
|
|
if (aiscript.value) aiscript.value.abort();
|
2023-01-04 22:59:48 -06:00
|
|
|
});
|
|
|
|
|
2023-12-06 23:42:09 -06:00
|
|
|
const headerActions = computed(() => []);
|
2023-01-04 22:59:48 -06:00
|
|
|
|
2023-12-06 23:42:09 -06:00
|
|
|
const headerTabs = computed(() => []);
|
2023-01-04 22:59:48 -06:00
|
|
|
|
2023-12-06 23:42:09 -06:00
|
|
|
definePageMetadata(computed(() => flash.value ? {
|
|
|
|
title: flash.value.title,
|
|
|
|
avatar: flash.value.user,
|
|
|
|
path: `/play/${flash.value.id}`,
|
2023-01-04 22:59:48 -06:00
|
|
|
share: {
|
2023-12-06 23:42:09 -06:00
|
|
|
title: flash.value.title,
|
|
|
|
text: flash.value.summary,
|
2023-01-04 22:59:48 -06:00
|
|
|
},
|
|
|
|
} : null));
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.ready {
|
|
|
|
&:global {
|
|
|
|
> .main {
|
|
|
|
padding: 32px;
|
|
|
|
|
|
|
|
> .title {
|
|
|
|
font-size: 1.4em;
|
|
|
|
font-weight: bold;
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .summary {
|
|
|
|
font-size: 1.1em;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .start {
|
|
|
|
margin: 1em auto 1em auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .info {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.footer {
|
|
|
|
margin-top: 16px;
|
|
|
|
|
|
|
|
&:global {
|
|
|
|
> .date {
|
|
|
|
margin: 8px 0;
|
|
|
|
opacity: 0.6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.started {
|
|
|
|
&:global {
|
|
|
|
> .main {
|
|
|
|
padding: 32px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .actions {
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
gap: 12px;
|
|
|
|
margin-top: 16px;
|
|
|
|
padding: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.fade-enter-active,
|
|
|
|
.fade-leave-active {
|
|
|
|
transition: opacity 0.125s ease;
|
|
|
|
}
|
|
|
|
.fade-enter-from,
|
|
|
|
.fade-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.zoom-enter-active,
|
|
|
|
.zoom-leave-active {
|
|
|
|
transition: opacity 0.3s cubic-bezier(0,0,.35,1), transform 0.3s cubic-bezier(0,0,.35,1);
|
|
|
|
}
|
|
|
|
.zoom-enter-from {
|
|
|
|
opacity: 0;
|
|
|
|
transform: scale(0.7);
|
|
|
|
}
|
|
|
|
.zoom-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
transform: scale(1.3);
|
|
|
|
}
|
|
|
|
</style>
|