summaryrefslogtreecommitdiff
path: root/packages/frontend/src
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-09-09 09:54:54 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-09-09 09:54:54 +0900
commit55d392818cd73b3f3f68758ccdbde0064bdff4b0 (patch)
tree50d08d0a9f3cd5e1531207bca8a9232ff02860a8 /packages/frontend/src
parent2023.9.0-beta.5 (diff)
downloadsharkey-55d392818cd73b3f3f68758ccdbde0064bdff4b0.tar.gz
sharkey-55d392818cd73b3f3f68758ccdbde0064bdff4b0.tar.bz2
sharkey-55d392818cd73b3f3f68758ccdbde0064bdff4b0.zip
enhance(frontend): add Ui:C:postForm to play
Diffstat (limited to 'packages/frontend/src')
-rw-r--r--packages/frontend/src/components/MkAsUi.vue13
-rw-r--r--packages/frontend/src/components/MkPostForm.vue2
-rw-r--r--packages/frontend/src/scripts/aiscript/ui.ts34
3 files changed, 48 insertions, 1 deletions
diff --git a/packages/frontend/src/components/MkAsUi.vue b/packages/frontend/src/components/MkAsUi.vue
index b663bef1db..76156e69d0 100644
--- a/packages/frontend/src/components/MkAsUi.vue
+++ b/packages/frontend/src/components/MkAsUi.vue
@@ -38,6 +38,13 @@ SPDX-License-Identifier: AGPL-3.0-only
<option v-for="item in c.items" :key="item.value" :value="item.value">{{ item.text }}</option>
</MkSelect>
<MkButton v-else-if="c.type === 'postFormButton'" :primary="c.primary" :rounded="c.rounded" :small="size === 'small'" inline @click="openPostForm">{{ c.text }}</MkButton>
+ <div v-else-if="c.type === 'postForm'" :class="$style.postForm">
+ <MkPostForm
+ fixed
+ :instant="true"
+ :initialText="c.form.text"
+ />
+ </div>
<MkFolder v-else-if="c.type === 'folder'" :defaultOpen="c.opened">
<template #label>{{ c.title }}</template>
<template v-for="child in c.children" :key="child">
@@ -62,6 +69,7 @@ import MkTextarea from '@/components/MkTextarea.vue';
import MkSelect from '@/components/MkSelect.vue';
import { AsUiComponent } from '@/scripts/aiscript/ui';
import MkFolder from '@/components/MkFolder.vue';
+import MkPostForm from '@/components/MkPostForm.vue';
const props = withDefaults(defineProps<{
component: AsUiComponent;
@@ -114,4 +122,9 @@ function openPostForm() {
.fontMonospace {
font-family: Fira code, Fira Mono, Consolas, Menlo, Courier, monospace;
}
+
+.postForm {
+ background: var(--bg);
+ border-radius: 8px;
+}
</style>
diff --git a/packages/frontend/src/components/MkPostForm.vue b/packages/frontend/src/components/MkPostForm.vue
index f29995d849..9ee9ac9ba0 100644
--- a/packages/frontend/src/components/MkPostForm.vue
+++ b/packages/frontend/src/components/MkPostForm.vue
@@ -629,6 +629,8 @@ function onDrop(ev): void {
}
function saveDraft() {
+ if (props.instant) return;
+
const draftData = JSON.parse(miLocalStorage.getItem('drafts') ?? '{}');
draftData[draftKey] = {
diff --git a/packages/frontend/src/scripts/aiscript/ui.ts b/packages/frontend/src/scripts/aiscript/ui.ts
index 3d059b04de..7e17563ec8 100644
--- a/packages/frontend/src/scripts/aiscript/ui.ts
+++ b/packages/frontend/src/scripts/aiscript/ui.ts
@@ -124,7 +124,14 @@ export type AsUiPostFormButton = AsUiComponentBase & {
};
};
-export type AsUiComponent = AsUiRoot | AsUiContainer | AsUiText | AsUiMfm | AsUiButton | AsUiButtons | AsUiSwitch | AsUiTextarea | AsUiTextInput | AsUiNumberInput | AsUiSelect | AsUiFolder | AsUiPostFormButton;
+export type AsUiPostForm = AsUiComponentBase & {
+ type: 'postForm';
+ form?: {
+ text: string;
+ };
+};
+
+export type AsUiComponent = AsUiRoot | AsUiContainer | AsUiText | AsUiMfm | AsUiButton | AsUiButtons | AsUiSwitch | AsUiTextarea | AsUiTextInput | AsUiNumberInput | AsUiSelect | AsUiFolder | AsUiPostFormButton | AsUiPostForm;
export function patch(id: string, def: values.Value, call: (fn: values.VFn, args: values.Value[]) => Promise<values.Value>) {
// TODO
@@ -462,6 +469,27 @@ function getPostFormButtonOptions(def: values.Value | undefined, call: (fn: valu
};
}
+function getPostFormOptions(def: values.Value | undefined, call: (fn: values.VFn, args: values.Value[]) => Promise<values.Value>): Omit<AsUiPostForm, 'id' | 'type'> {
+ utils.assertObject(def);
+
+ const form = def.value.get('form');
+ if (form) utils.assertObject(form);
+
+ const getForm = () => {
+ const text = form!.value.get('text');
+ utils.assertString(text);
+ return {
+ text: text.value,
+ };
+ };
+
+ return {
+ form: form ? getForm() : {
+ text: '',
+ },
+ };
+}
+
export function registerAsUiLib(components: Ref<AsUiComponent>[], done: (root: Ref<AsUiRoot>) => void) {
const instances = {};
@@ -569,5 +597,9 @@ export function registerAsUiLib(components: Ref<AsUiComponent>[], done: (root: R
'Ui:C:postFormButton': values.FN_NATIVE(([def, id], opts) => {
return createComponentInstance('postFormButton', def, id, getPostFormButtonOptions, opts.call);
}),
+
+ 'Ui:C:postForm': values.FN_NATIVE(([def, id], opts) => {
+ return createComponentInstance('postForm', def, id, getPostFormOptions, opts.call);
+ }),
};
}