From b1fe4cc735fc12f4f7d9540623465d6fed1f7e76 Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Mon, 6 Jan 2025 20:31:19 +0100 Subject: [PATCH] chore: sort templates in template picker fix: #1250 --- src/addon.ts | 2 +- src/extras/templatePicker.ts | 3 ++- src/modules/template/picker.ts | 9 +++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/addon.ts b/src/addon.ts index 3281755..9c84926 100644 --- a/src/addon.ts +++ b/src/addon.ts @@ -66,7 +66,7 @@ class Addon { templates: string[]; }; picker: { - mode: "insert" | "create" | "export"; + mode: "insert" | "create" | "export" | "pick"; data: Record; }; }; diff --git a/src/extras/templatePicker.ts b/src/extras/templatePicker.ts index 9de3a3d..7003f13 100644 --- a/src/extras/templatePicker.ts +++ b/src/extras/templatePicker.ts @@ -11,7 +11,8 @@ let args = window.arguments[0] as any; if (!args._initPromise) { args = args.wrappedJSObject; } -const templateData = args.templates; +const templateData = (args.templates as string[]) || []; +templateData.sort(); const multiSelect = args.multiSelect; let tableHelper: VirtualizedTableHelper; diff --git a/src/modules/template/picker.ts b/src/modules/template/picker.ts index e21bea3..828a1b7 100644 --- a/src/modules/template/picker.ts +++ b/src/modules/template/picker.ts @@ -20,14 +20,19 @@ async function showTemplatePicker( mode: "export", data?: Record, ): Promise; -async function showTemplatePicker(): Promise; +async function showTemplatePicker(mode: "pick"): Promise; +async function showTemplatePicker(): Promise; async function showTemplatePicker( mode: typeof addon.data.template.picker.mode = "insert", data: Record = {}, -) { +): Promise { addon.data.template.picker.mode = mode; addon.data.template.picker.data = data; const selected = await openTemplatePicker(); + // For pick mode, return selected templates + if (mode === "pick") { + return selected; + } if (!selected.length) { return; }