diff options
Diffstat (limited to 'packages/frontend/src/scripts/aiscript/ui.ts')
| -rw-r--r-- | packages/frontend/src/scripts/aiscript/ui.ts | 63 |
1 files changed, 50 insertions, 13 deletions
diff --git a/packages/frontend/src/scripts/aiscript/ui.ts b/packages/frontend/src/scripts/aiscript/ui.ts index c26ae5a4df..d326b956e8 100644 --- a/packages/frontend/src/scripts/aiscript/ui.ts +++ b/packages/frontend/src/scripts/aiscript/ui.ts @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: syuilo and other misskey contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + import { utils, values } from '@syuilo/aiscript'; import { v4 as uuid } from 'uuid'; import { ref, Ref } from 'vue'; @@ -119,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 @@ -457,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 = {}; @@ -518,51 +551,55 @@ export function registerAsUiLib(components: Ref<AsUiComponent>[], done: (root: R }), 'Ui:C:container': values.FN_NATIVE(([def, id], opts) => { - return createComponentInstance('container', def, id, getContainerOptions, opts.call); + return createComponentInstance('container', def, id, getContainerOptions, opts.topCall); }), 'Ui:C:text': values.FN_NATIVE(([def, id], opts) => { - return createComponentInstance('text', def, id, getTextOptions, opts.call); + return createComponentInstance('text', def, id, getTextOptions, opts.topCall); }), 'Ui:C:mfm': values.FN_NATIVE(([def, id], opts) => { - return createComponentInstance('mfm', def, id, getMfmOptions, opts.call); + return createComponentInstance('mfm', def, id, getMfmOptions, opts.topCall); }), 'Ui:C:textarea': values.FN_NATIVE(([def, id], opts) => { - return createComponentInstance('textarea', def, id, getTextareaOptions, opts.call); + return createComponentInstance('textarea', def, id, getTextareaOptions, opts.topCall); }), 'Ui:C:textInput': values.FN_NATIVE(([def, id], opts) => { - return createComponentInstance('textInput', def, id, getTextInputOptions, opts.call); + return createComponentInstance('textInput', def, id, getTextInputOptions, opts.topCall); }), 'Ui:C:numberInput': values.FN_NATIVE(([def, id], opts) => { - return createComponentInstance('numberInput', def, id, getNumberInputOptions, opts.call); + return createComponentInstance('numberInput', def, id, getNumberInputOptions, opts.topCall); }), 'Ui:C:button': values.FN_NATIVE(([def, id], opts) => { - return createComponentInstance('button', def, id, getButtonOptions, opts.call); + return createComponentInstance('button', def, id, getButtonOptions, opts.topCall); }), 'Ui:C:buttons': values.FN_NATIVE(([def, id], opts) => { - return createComponentInstance('buttons', def, id, getButtonsOptions, opts.call); + return createComponentInstance('buttons', def, id, getButtonsOptions, opts.topCall); }), 'Ui:C:switch': values.FN_NATIVE(([def, id], opts) => { - return createComponentInstance('switch', def, id, getSwitchOptions, opts.call); + return createComponentInstance('switch', def, id, getSwitchOptions, opts.topCall); }), 'Ui:C:select': values.FN_NATIVE(([def, id], opts) => { - return createComponentInstance('select', def, id, getSelectOptions, opts.call); + return createComponentInstance('select', def, id, getSelectOptions, opts.topCall); }), 'Ui:C:folder': values.FN_NATIVE(([def, id], opts) => { - return createComponentInstance('folder', def, id, getFolderOptions, opts.call); + return createComponentInstance('folder', def, id, getFolderOptions, opts.topCall); }), 'Ui:C:postFormButton': values.FN_NATIVE(([def, id], opts) => { - return createComponentInstance('postFormButton', def, id, getPostFormButtonOptions, opts.call); + return createComponentInstance('postFormButton', def, id, getPostFormButtonOptions, opts.topCall); + }), + + 'Ui:C:postForm': values.FN_NATIVE(([def, id], opts) => { + return createComponentInstance('postForm', def, id, getPostFormOptions, opts.topCall); }), }; } |