diff --git a/configuration/homeScreenAdvancedEditor.js b/configuration/homeScreenAdvancedEditor.js
index 975bbb0..32c8d7a 100644
--- a/configuration/homeScreenAdvancedEditor.js
+++ b/configuration/homeScreenAdvancedEditor.js
@@ -51,6 +51,7 @@
const DEFAULT_SECTION_QUERY_LIMIT = window.KefinHomeScreenEditorConstants?.DEFAULT_SECTION_QUERY_LIMIT ?? 16;
const LIMIT_ZERO_MODAL_ID = 'kefin-hsae-limit-zero';
+ const ADD_QUERY_MODAL_ID = 'kefin-hsae-add-query';
const LIMIT_ZERO_MESSAGE = 'Setting the limit to 0 can result in queries requesting a lot of items from the server and may result in slow response times. This is fine to use if you know there are only a few hundred results at maximum. If you expect thousands of results, this is probably not a good idea unless you use a fairly long cache time.';
/** Live editor state for collectData (which only receives a dialog element). */
@@ -118,6 +119,79 @@
});
}
+ function queryCopyLabel(query, index) {
+ const name = query?.name != null ? String(query.name).trim() : '';
+ return name || `Query ${index + 1}`;
+ }
+
+ /**
+ * Choose whether the next query is a copy of an existing one or a blank query.
+ * Cancel, backdrop, and Escape add nothing.
+ * @param {{ queries?: Array, onAdd?: (choice: string) => void }} opts
+ */
+ function openAddQueryModal({ queries, onAdd } = {}) {
+ if (!window.ModalSystem?.create) return;
+
+ let settled = false;
+ const finish = (choice) => {
+ if (settled) return;
+ settled = true;
+ if (choice == null) return;
+ onAdd?.(choice);
+ };
+
+ if (window.ModalSystem.isOpen?.(ADD_QUERY_MODAL_ID)) {
+ window.ModalSystem.close(ADD_QUERY_MODAL_ID);
+ }
+
+ const list = Array.isArray(queries) ? queries : [];
+ const nextNumber = list.length + 1;
+ const choices = list.map((query, index) => ({
+ value: String(index),
+ label: `Copy from ${queryCopyLabel(query, index)}`
+ }));
+ choices.push({ value: 'new', label: 'New Query' });
+ const selected = list.length ? '0' : 'new';
+ const optionsHtml = choices.map((opt) => {
+ const selectedAttr = opt.value === selected ? ' selected' : '';
+ return ``;
+ }).join('');
+ const content = `
+