diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-01-05 17:09:36 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2023-01-05 17:09:36 +0900 |
| commit | d890383a008b542c46819a1ce98a2646725a10e7 (patch) | |
| tree | 00a6a6831f07610f873f37a10343cc719f930913 /packages/frontend/src/scripts | |
| parent | update aiscript (diff) | |
| download | misskey-d890383a008b542c46819a1ce98a2646725a10e7.tar.gz misskey-d890383a008b542c46819a1ce98a2646725a10e7.tar.bz2 misskey-d890383a008b542c46819a1ce98a2646725a10e7.zip | |
add Ui:C:folder for AiScript
Diffstat (limited to 'packages/frontend/src/scripts')
| -rw-r--r-- | packages/frontend/src/scripts/aiscript/ui.ts | 33 |
1 files changed, 32 insertions, 1 deletions
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<values.Value>) { // TODO @@ -389,6 +396,26 @@ function getSelectOptions(def: values.Value | undefined, call: (fn: values.VFn, }; } +function getFolderOptions(def: values.Value | undefined): Omit<AsUiFolder, 'id' | 'type'> { + 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<values.Value>): Omit<AsUiPostFormButton, 'id' | 'type'> { utils.assertObject(def); @@ -519,6 +546,10 @@ export function registerAsUiLib(components: Ref<AsUiComponent>[], 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); }), |