From d890383a008b542c46819a1ce98a2646725a10e7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 5 Jan 2023 17:09:36 +0900 Subject: add Ui:C:folder for AiScript --- packages/frontend/src/scripts/aiscript/ui.ts | 33 +++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'packages/frontend/src/scripts') diff --git a/packages/frontend/src/scripts/aiscript/ui.ts b/packages/frontend/src/scripts/aiscript/ui.ts index f4c89b8276..6e0e312116 100644 --- a/packages/frontend/src/scripts/aiscript/ui.ts +++ b/packages/frontend/src/scripts/aiscript/ui.ts @@ -100,6 +100,13 @@ export type AsUiSelect = AsUiComponentBase & { caption?: string; }; +export type AsUiFolder = AsUiComponentBase & { + type: 'folder'; + children?: AsUiComponent['id'][]; + title?: string; + opened?: boolean; +}; + export type AsUiPostFormButton = AsUiComponentBase & { type: 'postFormButton'; text?: string; @@ -110,7 +117,7 @@ export type AsUiPostFormButton = AsUiComponentBase & { }; }; -export type AsUiComponent = AsUiRoot | AsUiContainer | AsUiText | AsUiMfm | AsUiButton | AsUiButtons | AsUiSwitch | AsUiTextarea | AsUiTextInput | AsUiNumberInput | AsUiSelect | AsUiPostFormButton; +export type AsUiComponent = AsUiRoot | AsUiContainer | AsUiText | AsUiMfm | AsUiButton | AsUiButtons | AsUiSwitch | AsUiTextarea | AsUiTextInput | AsUiNumberInput | AsUiSelect | AsUiFolder | AsUiPostFormButton; export function patch(id: string, def: values.Value, call: (fn: values.VFn, args: values.Value[]) => Promise) { // TODO @@ -389,6 +396,26 @@ function getSelectOptions(def: values.Value | undefined, call: (fn: values.VFn, }; } +function getFolderOptions(def: values.Value | undefined): Omit { + utils.assertObject(def); + + const children = def.value.get('children'); + if (children) utils.assertArray(children); + const title = def.value.get('title'); + if (title) utils.assertString(title); + const opened = def.value.get('opened'); + if (opened) utils.assertBoolean(opened); + + return { + children: children ? children.value.map(v => { + utils.assertObject(v); + return v.value.get('id').value; + }) : [], + title: title?.value ?? '', + opened: opened?.value ?? true, + }; +} + function getPostFormButtonOptions(def: values.Value | undefined, call: (fn: values.VFn, args: values.Value[]) => Promise): Omit { utils.assertObject(def); @@ -519,6 +546,10 @@ export function registerAsUiLib(components: Ref[], done: (root: R return createComponentInstance('select', def, id, getSelectOptions, opts.call); }), + 'Ui:C:folder': values.FN_NATIVE(async ([def, id], opts) => { + return createComponentInstance('folder', def, id, getFolderOptions, opts.call); + }), + 'Ui:C:postFormButton': values.FN_NATIVE(async ([def, id], opts) => { return createComponentInstance('postFormButton', def, id, getPostFormButtonOptions, opts.call); }), -- cgit v1.3.1-freya