@chocbite/ts-lib-ui 1.1.5 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/AGENTS.md +547 -9
  2. package/README.md +3 -0
  3. package/SOURCE.md +10313 -7355
  4. package/base/index.d.mts +2 -2
  5. package/base/index.mjs +68 -5
  6. package/base/index.mjs.map +1 -1
  7. package/canvas/index.d.mts +1 -1
  8. package/canvas/index.mjs +1 -1
  9. package/composition/index.d.mts +283 -0
  10. package/composition/index.mjs +2 -0
  11. package/composition-7xlf0UjB.mjs +869 -0
  12. package/composition-7xlf0UjB.mjs.map +1 -0
  13. package/context-menu/index.d.mts +1 -1
  14. package/context-menu/index.mjs +1 -1
  15. package/{context-menu-CZxEGjBi.mjs → context-menu-DSVerkvr.mjs} +2 -2
  16. package/{context-menu-CZxEGjBi.mjs.map → context-menu-DSVerkvr.mjs.map} +1 -1
  17. package/depot_ui/index.d.mts +60 -0
  18. package/depot_ui/index.mjs +280 -0
  19. package/depot_ui/index.mjs.map +1 -0
  20. package/form/index.d.mts +2 -758
  21. package/form/index.mjs +1 -2953
  22. package/form-CnIHz2Bp.mjs +2961 -0
  23. package/form-CnIHz2Bp.mjs.map +1 -0
  24. package/icons/index.d.mts +1 -1
  25. package/{index-YNZjMIO7.d.mts → index-CApVOEcI.d.mts} +2 -2
  26. package/{index-BDWg5GX2.d.mts → index-Czy8O3me.d.mts} +6 -2
  27. package/index-DD09-bGe.d.mts +761 -0
  28. package/{index-DlBJdGaQ.d.mts → index-U3pqQjLg.d.mts} +4 -4
  29. package/{index-CvzH3M_5.d.mts → index-_y7vmunA.d.mts} +72 -8
  30. package/keyboard/index.d.mts +1 -1
  31. package/keyboard/index.mjs +1 -1
  32. package/list/index.d.mts +1 -1
  33. package/list/index.mjs +1 -1
  34. package/{list-C52-ExFw.mjs → list-ByNP3ZG2.mjs} +3 -3
  35. package/{list-C52-ExFw.mjs.map → list-ByNP3ZG2.mjs.map} +1 -1
  36. package/package.json +2 -2
  37. package/prompts/index.d.mts +48 -0
  38. package/prompts/index.mjs +107 -0
  39. package/prompts/index.mjs.map +1 -0
  40. package/spinner/index.d.mts +1 -1
  41. package/spinner/index.mjs +1 -1
  42. package/style.css +2049 -1640
  43. package/svg/index.d.mts +1 -1
  44. package/svg-Yz7elqnU.mjs.map +1 -1
  45. package/theme/index.d.mts +1 -1
  46. package/theme/index.mjs +1 -1
  47. package/{theme-D3YluyYr.mjs → theme-ycsugrdT.mjs} +2 -2
  48. package/{theme-D3YluyYr.mjs.map → theme-ycsugrdT.mjs.map} +1 -1
  49. package/form/index.mjs.map +0 -1
  50. package/test/index.d.mts +0 -98
  51. package/test/index.mjs +0 -193
  52. package/test/index.mjs.map +0 -1
@@ -0,0 +1,280 @@
1
+ import "../style.css";
2
+ import { Base, define_element } from "../base/index.mjs";
3
+ import { t as form } from "../form-CnIHz2Bp.mjs";
4
+ import { n as ListField, t as list } from "../list-ByNP3ZG2.mjs";
5
+ import { i as theme_init_variable_root } from "../theme-ycsugrdT.mjs";
6
+ import state from "@chocbite/ts-lib/state";
7
+ import { ok } from "@chocbite/ts-lib/result";
8
+ import { GREY } from "@chocbite/ts-lib/colors";
9
+ import depot from "@chocbite/ts-lib/depot";
10
+ // depot_ui/shared.ts
11
+ const colors = theme_init_variable_root("depot", "Depot", "Theme variables for depot selectors").make_sub_group("colors", "Colors", "Colors used in depot selectors");
12
+ colors.make_variable("backdrop", "Backdrop Color", "Covers the page behind an open selector", GREY["900"] + "66", GREY["900"] + "99", "Color", void 0);
13
+ colors.make_variable("background", "Background Color", "Background of the selector", GREY["50"], GREY["900"], "Color", void 0);
14
+ colors.make_variable("text", "Text Color", "Title text of the selector", GREY["900"], GREY["50"], "Color", void 0);
15
+ colors.make_variable("shadow", "Shadow Color", "Shadow around the selector", GREY["900"] + "88", GREY["50"] + "33", "Color", void 0);
16
+ // depot_ui/tree.ts
17
+ /**A filtered view of a group and everything below it, following the children states of the depot.
18
+ * Entries are shown when they pass the filter and the search, groups when something below them is shown*/
19
+ var DepotTree = class {
20
+ #root;
21
+ #filter;
22
+ #search = "";
23
+ /**Rows shown per group*/
24
+ #rows = /* @__PURE__ */ new Map();
25
+ /**Subscriptions to the children of every group below the root*/
26
+ #subs = /* @__PURE__ */ new Map();
27
+ #pending = false;
28
+ #disposed = false;
29
+ constructor(root, filter) {
30
+ this.#root = root;
31
+ this.#filter = filter ?? (() => true);
32
+ this.#update(false);
33
+ }
34
+ /**Rows shown for a group, the root rows when no group is given*/
35
+ rows(group = this.#root) {
36
+ return this.#rows_of(group).read_only;
37
+ }
38
+ /**True while a search text is set, rows of groups should be open then*/
39
+ get searching() {
40
+ return this.#search !== "";
41
+ }
42
+ /**Text matched against the names and paths of entries, case insensitive*/
43
+ set search(text) {
44
+ const search = text.trim().toLowerCase();
45
+ if (search === this.#search) return;
46
+ this.#search = search;
47
+ this.#update(true);
48
+ }
49
+ /**Drops the subscriptions to the depot*/
50
+ dispose() {
51
+ this.#disposed = true;
52
+ for (const [group, sub] of this.#subs) group.children.unsub(sub);
53
+ this.#subs.clear();
54
+ }
55
+ #rows_of(group) {
56
+ let rows = this.#rows.get(group);
57
+ if (!rows) this.#rows.set(group, rows = state.ros(ok([])));
58
+ return rows;
59
+ }
60
+ #matches(entry) {
61
+ if (!this.#filter(entry)) return false;
62
+ if (!this.#search) return true;
63
+ return entry.name.toLowerCase().includes(this.#search) || entry.path.toLowerCase().includes(this.#search);
64
+ }
65
+ /**Changes in the depot often come in bursts, like a group being registered, so they are handled once after the burst*/
66
+ #changed = () => {
67
+ if (this.#pending || this.#disposed) return;
68
+ this.#pending = true;
69
+ queueMicrotask(() => {
70
+ this.#pending = false;
71
+ if (!this.#disposed) this.#update(false);
72
+ });
73
+ };
74
+ /**Works out the shown rows of every group again
75
+ * @param fresh give every group its rows again, even when they did not change*/
76
+ #update(fresh) {
77
+ const seen = /* @__PURE__ */ new Set();
78
+ const visit = (group) => {
79
+ seen.add(group);
80
+ if (!this.#subs.has(group)) this.#subs.set(group, group.children.sub(this.#changed));
81
+ const shown = [];
82
+ for (const child of group.children.ok()) if (child.kind === "entry" ? this.#matches(child) : visit(child).length) shown.push(child);
83
+ const rows = this.#rows_of(group);
84
+ const old = rows.ok();
85
+ if (fresh || old.length !== shown.length || old.some((child, i) => child !== shown[i])) rows.set_ok(shown);
86
+ return shown;
87
+ };
88
+ visit(this.#root);
89
+ for (const [group, sub] of this.#subs) {
90
+ if (seen.has(group)) continue;
91
+ group.children.unsub(sub);
92
+ this.#subs.delete(group);
93
+ this.#rows.get(group)?.set_ok([]);
94
+ this.#rows.delete(group);
95
+ }
96
+ }
97
+ };
98
+ // depot_ui/kind.ts
99
+ /**Value of a sync state right now, undefined for async states and errors*/
100
+ function now(s) {
101
+ return s && state.is.res(s) ? s.get().unwrap_or(void 0) : void 0;
102
+ }
103
+ /**Kind of a state, from its helper, or else from the current value of a sync state.
104
+ * Undefined when it can not be known, like an async state without a helper*/
105
+ function state_kind(s) {
106
+ const related = s.related().unwrap_or(void 0);
107
+ if (state.n.is_related(related)) return "number";
108
+ if (state.e.is_related(related)) return "enum";
109
+ if (state.s.is_related(related)) return "string";
110
+ if (state.b.is_related(related)) return "boolean";
111
+ const value = now(s);
112
+ if (typeof value === "number") return "number";
113
+ if (typeof value === "string") return "string";
114
+ if (typeof value === "boolean") return "boolean";
115
+ }
116
+ /**Turns values of a state into text, using the unit and decimals of a number helper and the names of an enum helper.
117
+ * Objects are shown as JSON, "(object)" when they can not be*/
118
+ function state_format(s) {
119
+ const related = s.related().unwrap_or(void 0);
120
+ if (state.n.is_related(related)) {
121
+ const unit = now(related.unit);
122
+ const decimals = now(related.decimals);
123
+ return (value) => (typeof value === "number" && decimals !== void 0 ? value.toFixed(decimals) : String(value)) + (unit ? " " + unit : "");
124
+ }
125
+ if (state.e.is_related(related)) {
126
+ const list = now(related.list);
127
+ return (value) => (typeof value === "string" ? list?.[value]?.name : void 0) ?? String(value);
128
+ }
129
+ return (value) => {
130
+ if (typeof value !== "object" || value === null) return String(value);
131
+ try {
132
+ return JSON.stringify(value);
133
+ } catch {
134
+ return "(object)";
135
+ }
136
+ };
137
+ }
138
+ // depot_ui/value.ts
139
+ const VALUE = Symbol("value");
140
+ /**List field showing the live value of the state of an entry, nothing for groups.
141
+ * The state is only subscribed while the field is in the document*/
142
+ var DepotValueField = class extends ListField {
143
+ static element_name() {
144
+ return "value";
145
+ }
146
+ static element_name_space() {
147
+ return "depot";
148
+ }
149
+ set child(child) {
150
+ if (child.kind !== "entry") {
151
+ this.detach_state_from_symbol(VALUE);
152
+ this.textContent = "";
153
+ this.classList.remove("error");
154
+ return;
155
+ }
156
+ const format = state_format(child.value);
157
+ this.attach_state_to_symbol(VALUE, child.value, (result) => {
158
+ this.classList.toggle("error", !result.ok);
159
+ this.textContent = result.ok ? format(result.value) : result.error;
160
+ });
161
+ }
162
+ };
163
+ define_element(DepotValueField);
164
+ // depot_ui/selector.ts
165
+ var DepotSelector = class extends Base {
166
+ static element_name() {
167
+ return "selector";
168
+ }
169
+ static element_name_space() {
170
+ return "depot";
171
+ }
172
+ #panel = this.appendChild(document.createElement("div"));
173
+ #title = this.#panel.appendChild(document.createElement("h2"));
174
+ #tree;
175
+ #selection = state.ok_w([]);
176
+ #resolve;
177
+ /**Opens the selector, the promise gives the selected entries, none when cancelled
178
+ * @param values show a column with the live value of the content of entries*/
179
+ open(from, options, values = false) {
180
+ const mode = options.mode ?? "single";
181
+ const tree = this.#tree = new DepotTree(from, options.filter);
182
+ this.#title.textContent = options.title ?? from.name;
183
+ this.#selection.set_ok([...options.selected ?? []]);
184
+ const search = this.#panel.appendChild(form.text_input({ placeholder: "Search" }));
185
+ search.oninput = (e) => {
186
+ if (e.target instanceof HTMLInputElement) tree.search = e.target.value;
187
+ };
188
+ const columns = { description: list.column_string("Description") };
189
+ if (values) columns.value = list.column({
190
+ title: "Value",
191
+ field_gen: () => new DepotValueField(),
192
+ field_apply: (field, child) => field.child = child
193
+ });
194
+ const rows = this.#panel.appendChild(list.container(columns, (child) => ok({
195
+ key_field: {
196
+ icon: child.icon,
197
+ text: child.name
198
+ },
199
+ values: {
200
+ description: child.description,
201
+ value: child
202
+ },
203
+ openable: child.kind !== "entry",
204
+ opened: tree.searching,
205
+ sub_rows: child.kind === "entry" ? void 0 : () => tree.rows(child),
206
+ selectable: child.kind === "entry"
207
+ }), tree.rows(), {
208
+ sub_rows: true,
209
+ selection: { mode }
210
+ }).bind({ selection: this.#selection }));
211
+ if (mode === "single") rows.ondblclick = () => {
212
+ if (this.#selection.ok().length) this.#close(true);
213
+ };
214
+ const buttons = this.#panel.appendChild(document.createElement("div"));
215
+ buttons.appendChild(form.button({
216
+ text: "Cancel",
217
+ on_click: () => this.#close(false)
218
+ }));
219
+ buttons.appendChild(form.button({
220
+ text: "Select",
221
+ on_click: () => this.#close(true)
222
+ }));
223
+ this.onpointerdown = (e) => {
224
+ if (e.target === this) this.#close(false);
225
+ };
226
+ document.body.appendChild(this);
227
+ return new Promise((resolve) => this.#resolve = resolve);
228
+ }
229
+ #close(picked) {
230
+ const resolve = this.#resolve;
231
+ if (!resolve) return;
232
+ this.#resolve = void 0;
233
+ const entries = picked ? this.#selection.ok().filter((child) => child.kind === "entry") : [];
234
+ this.#tree?.dispose();
235
+ this.remove();
236
+ resolve(entries);
237
+ }
238
+ };
239
+ define_element(DepotSelector);
240
+ /**Opens a selector for the entries of a type or group, the promise gives the selected entries, none when cancelled.
241
+ * The selector follows the depot while it is open*/
242
+ function depot_select(from, options = {}) {
243
+ return new DepotSelector().open(from, options);
244
+ }
245
+ /**Opens the selector with a column of the live values, for the states type*/
246
+ function depot_select_values(from, options) {
247
+ return new DepotSelector().open(from, options, true);
248
+ }
249
+ // depot_ui/state.ts
250
+ /**Opens a selector for the states of the depot with their live values, the promise gives the selected entries, none when cancelled.
251
+ * The state of an entry is its value, entry.value*/
252
+ function depot_select_state(options = {}) {
253
+ const from = options.from ?? depot.states;
254
+ if (from.type !== depot.states) throw new Error(`Depot group "${from.path}" is not in the states type`);
255
+ const kinds = options.kind === void 0 ? void 0 : typeof options.kind === "string" ? [options.kind] : options.kind;
256
+ const { writable, filter } = options;
257
+ return depot_select_values(from, {
258
+ mode: options.mode,
259
+ selected: options.selected,
260
+ title: options.title,
261
+ filter: (entry) => {
262
+ if (writable && !entry.value.writable) return false;
263
+ if (kinds) {
264
+ const kind = state_kind(entry.value);
265
+ if (!kind || !kinds.includes(kind)) return false;
266
+ }
267
+ return !filter || filter(entry);
268
+ }
269
+ });
270
+ }
271
+ // depot_ui/index.ts
272
+ const depot_ui = {
273
+ /**Opens a selector for the entries of a type or group, the promise gives the selected entries, none when cancelled*/
274
+ select: depot_select,
275
+ /**Opens a selector for the states of the depot with their live values, the promise gives the selected entries, none when cancelled*/
276
+ select_state: depot_select_state
277
+ };
278
+ export { DepotTree, depot_ui as default, depot_ui };
279
+
280
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../package-ui/depot_ui/shared.ts","../../../package-ui/depot_ui/tree.ts","../../../package-ui/depot_ui/kind.ts","../../../package-ui/depot_ui/value.ts","../../../package-ui/depot_ui/selector.ts","../../../package-ui/depot_ui/state.ts","../../../package-ui/depot_ui/index.ts"],"sourcesContent":["import { theme_init_variable_root } from \"#theme\";\nimport { GREY } from \"@chocbite/ts-lib/colors\";\n\nconst theme_root = theme_init_variable_root(\n \"depot\",\n \"Depot\",\n \"Theme variables for depot selectors\",\n);\n\nconst colors = theme_root.make_sub_group(\n \"colors\",\n \"Colors\",\n \"Colors used in depot selectors\",\n);\ncolors.make_variable(\n \"backdrop\",\n \"Backdrop Color\",\n \"Covers the page behind an open selector\",\n GREY[\"900\"] + \"66\",\n GREY[\"900\"] + \"99\",\n \"Color\",\n undefined,\n);\ncolors.make_variable(\n \"background\",\n \"Background Color\",\n \"Background of the selector\",\n GREY[\"50\"],\n GREY[\"900\"],\n \"Color\",\n undefined,\n);\ncolors.make_variable(\n \"text\",\n \"Text Color\",\n \"Title text of the selector\",\n GREY[\"900\"],\n GREY[\"50\"],\n \"Color\",\n undefined,\n);\ncolors.make_variable(\n \"shadow\",\n \"Shadow Color\",\n \"Shadow around the selector\",\n GREY[\"900\"] + \"88\",\n GREY[\"50\"] + \"33\",\n \"Color\",\n undefined,\n);\n","import type {\n DepotChild,\n DepotEntry,\n DepotGroup,\n} from \"@chocbite/ts-lib/depot\";\nimport { ok } from \"@chocbite/ts-lib/result\";\nimport state, {\n type StateLocalROS,\n type StateROS,\n} from \"@chocbite/ts-lib/state\";\n\n/**A filtered view of a group and everything below it, following the children states of the depot.\n * Entries are shown when they pass the filter and the search, groups when something below them is shown*/\nexport class DepotTree<T> {\n #root: DepotGroup<T>;\n #filter: (entry: DepotEntry<T>) => boolean;\n #search = \"\";\n /**Rows shown per group*/\n #rows = new Map<DepotGroup<T>, StateLocalROS<DepotChild<T>[]>>();\n /**Subscriptions to the children of every group below the root*/\n #subs = new Map<DepotGroup<T>, () => void>();\n #pending = false;\n #disposed = false;\n\n constructor(root: DepotGroup<T>, filter?: (entry: DepotEntry<T>) => boolean) {\n this.#root = root;\n this.#filter = filter ?? (() => true);\n this.#update(false);\n }\n\n /**Rows shown for a group, the root rows when no group is given*/\n rows(group: DepotGroup<T> = this.#root): StateROS<DepotChild<T>[]> {\n return this.#rows_of(group).read_only;\n }\n\n /**True while a search text is set, rows of groups should be open then*/\n get searching(): boolean {\n return this.#search !== \"\";\n }\n\n /**Text matched against the names and paths of entries, case insensitive*/\n set search(text: string) {\n const search = text.trim().toLowerCase();\n if (search === this.#search) return;\n this.#search = search;\n //Every row is given again, so the rows of groups open or close with the search\n this.#update(true);\n }\n\n /**Drops the subscriptions to the depot*/\n dispose(): void {\n this.#disposed = true;\n for (const [group, sub] of this.#subs) group.children.unsub(sub);\n this.#subs.clear();\n }\n\n #rows_of(group: DepotGroup<T>): StateLocalROS<DepotChild<T>[]> {\n let rows = this.#rows.get(group);\n if (!rows)\n this.#rows.set(group, (rows = state.ros(ok<DepotChild<T>[]>([]))));\n return rows;\n }\n\n #matches(entry: DepotEntry<T>): boolean {\n if (!this.#filter(entry)) return false;\n if (!this.#search) return true;\n return (\n entry.name.toLowerCase().includes(this.#search) ||\n entry.path.toLowerCase().includes(this.#search)\n );\n }\n\n /**Changes in the depot often come in bursts, like a group being registered, so they are handled once after the burst*/\n #changed = () => {\n if (this.#pending || this.#disposed) return;\n this.#pending = true;\n queueMicrotask(() => {\n this.#pending = false;\n if (!this.#disposed) this.#update(false);\n });\n };\n\n /**Works out the shown rows of every group again\n * @param fresh give every group its rows again, even when they did not change*/\n #update(fresh: boolean): void {\n const seen = new Set<DepotGroup<T>>();\n const visit = (group: DepotGroup<T>): DepotChild<T>[] => {\n seen.add(group);\n if (!this.#subs.has(group))\n this.#subs.set(group, group.children.sub(this.#changed));\n const shown: DepotChild<T>[] = [];\n for (const child of group.children.ok())\n if (child.kind === \"entry\" ? this.#matches(child) : visit(child).length)\n shown.push(child);\n const rows = this.#rows_of(group);\n const old = rows.ok();\n if (\n fresh ||\n old.length !== shown.length ||\n old.some((child, i) => child !== shown[i])\n )\n rows.set_ok(shown);\n return shown;\n };\n visit(this.#root);\n //Groups that were removed, or are below a removed group\n for (const [group, sub] of this.#subs) {\n if (seen.has(group)) continue;\n group.children.unsub(sub);\n this.#subs.delete(group);\n this.#rows.get(group)?.set_ok([]);\n this.#rows.delete(group);\n }\n }\n}\n","import state, { type State } from \"@chocbite/ts-lib/state\";\n\n/**Kind of value a state holds, as far as it can be known at runtime*/\nexport type DepotStateKind = \"number\" | \"string\" | \"boolean\" | \"enum\";\n\n/**Value of a sync state right now, undefined for async states and errors*/\nexport function now<V>(s: State<V> | undefined): V | undefined {\n return s && state.is.res(s) ? s.get().unwrap_or(undefined) : undefined;\n}\n\n/**Kind of a state, from its helper, or else from the current value of a sync state.\n * Undefined when it can not be known, like an async state without a helper*/\nexport function state_kind(s: State<unknown>): DepotStateKind | undefined {\n const related = s.related().unwrap_or(undefined);\n if (state.n.is_related(related)) return \"number\";\n if (state.e.is_related(related)) return \"enum\";\n if (state.s.is_related(related)) return \"string\";\n if (state.b.is_related(related)) return \"boolean\";\n const value = now(s);\n if (typeof value === \"number\") return \"number\";\n if (typeof value === \"string\") return \"string\";\n if (typeof value === \"boolean\") return \"boolean\";\n return undefined;\n}\n\n/**Turns values of a state into text, using the unit and decimals of a number helper and the names of an enum helper.\n * Objects are shown as JSON, \"(object)\" when they can not be*/\nexport function state_format(s: State<unknown>): (value: unknown) => string {\n const related = s.related().unwrap_or(undefined);\n if (state.n.is_related(related)) {\n const unit = now(related.unit);\n const decimals = now(related.decimals);\n return (value) =>\n (typeof value === \"number\" && decimals !== undefined\n ? value.toFixed(decimals)\n : String(value)) + (unit ? \" \" + unit : \"\");\n }\n if (state.e.is_related(related)) {\n const list = now(related.list);\n return (value) =>\n (typeof value === \"string\" ? list?.[value]?.name : undefined) ??\n String(value);\n }\n return (value) => {\n if (typeof value !== \"object\" || value === null) return String(value);\n try {\n return JSON.stringify(value);\n } catch {\n return \"(object)\";\n }\n };\n}\n","import { define_element } from \"#base\";\nimport { ListField } from \"#list\";\nimport type { DepotChild } from \"@chocbite/ts-lib/depot\";\nimport type { Result } from \"@chocbite/ts-lib/result\";\nimport \"./value.scss\";\nimport { state_format } from \"./kind\";\n\nconst VALUE = Symbol(\"value\");\n\n/**List field showing the live value of the state of an entry, nothing for groups.\n * The state is only subscribed while the field is in the document*/\nexport class DepotValueField extends ListField {\n static element_name() {\n return \"value\";\n }\n static element_name_space(): string {\n return \"depot\";\n }\n\n set child(child: DepotChild<unknown>) {\n if (child.kind !== \"entry\") {\n this.detach_state_from_symbol(VALUE);\n this.textContent = \"\";\n this.classList.remove(\"error\");\n return;\n }\n const format = state_format(child.value);\n this.attach_state_to_symbol(\n VALUE,\n child.value,\n (result: Result<unknown, string>) => {\n this.classList.toggle(\"error\", !result.ok);\n this.textContent = result.ok ? format(result.value) : result.error;\n },\n );\n }\n}\ndefine_element(DepotValueField);\n","import { Base, define_element } from \"#base\";\nimport form from \"#form\";\nimport list from \"#list\";\nimport type {\n DepotChild,\n DepotEntry,\n DepotGroup,\n} from \"@chocbite/ts-lib/depot\";\nimport { ok } from \"@chocbite/ts-lib/result\";\nimport state from \"@chocbite/ts-lib/state\";\nimport \"./selector.scss\";\nimport \"./shared\";\nimport { DepotTree } from \"./tree\";\nimport { DepotValueField } from \"./value\";\n\nexport interface DepotSelectOptions<T> {\n /**Single selects one entry, multi any number, single when undefined*/\n mode?: \"single\" | \"multi\";\n /**Only entries passing the filter are shown and can be selected, like only writable states.\n * Groups with no shown entries below them are hidden*/\n filter?: (entry: DepotEntry<T>) => boolean;\n /**Entries selected when the selector opens*/\n selected?: readonly DepotEntry<T>[];\n /**Title of the selector, the name of the group when undefined*/\n title?: string;\n}\n\ninterface SelectorValues<T> {\n description: string;\n value?: DepotChild<T>;\n}\ntype ListColumnOf<V> = ReturnType<typeof list.column<V, any>>;\n\nclass DepotSelector<T> extends Base {\n static element_name() {\n return \"selector\";\n }\n static element_name_space(): string {\n return \"depot\";\n }\n\n #panel = this.appendChild(document.createElement(\"div\"));\n #title = this.#panel.appendChild(document.createElement(\"h2\"));\n #tree?: DepotTree<T>;\n #selection = state.ok_w<DepotChild<T>[]>([]);\n #resolve?: (entries: DepotEntry<T>[]) => void;\n\n /**Opens the selector, the promise gives the selected entries, none when cancelled\n * @param values show a column with the live value of the content of entries*/\n open(\n from: DepotGroup<T>,\n options: DepotSelectOptions<T>,\n values = false,\n ): Promise<DepotEntry<T>[]> {\n const mode = options.mode ?? \"single\";\n const tree = (this.#tree = new DepotTree(from, options.filter));\n this.#title.textContent = options.title ?? from.name;\n this.#selection.set_ok([...(options.selected ?? [])]);\n //Filters while typing, the input itself only gives its value on change\n const search = this.#panel.appendChild(\n form.text_input({ placeholder: \"Search\" }),\n );\n search.oninput = (e) => {\n if (e.target instanceof HTMLInputElement) tree.search = e.target.value;\n };\n const columns: {\n [K in keyof SelectorValues<T>]: ListColumnOf<\n NonNullable<SelectorValues<T>[K]>\n >;\n } = { description: list.column_string(\"Description\") };\n if (values)\n columns.value = list.column({\n title: \"Value\",\n field_gen: () => new DepotValueField(),\n field_apply: (field, child: DepotChild<T>) =>\n (field.child = child as DepotChild<unknown>),\n });\n const rows = this.#panel.appendChild(\n list\n .container(\n columns,\n (child) =>\n ok({\n key_field: { icon: child.icon, text: child.name },\n values: { description: child.description, value: child },\n openable: child.kind !== \"entry\",\n opened: tree.searching,\n sub_rows:\n child.kind === \"entry\" ? undefined : () => tree.rows(child),\n selectable: child.kind === \"entry\",\n }),\n tree.rows(),\n { sub_rows: true, selection: { mode } },\n )\n .bind({ selection: this.#selection }),\n );\n //A double click on an entry in single mode picks it right away\n if (mode === \"single\")\n rows.ondblclick = () => {\n if (this.#selection.ok().length) this.#close(true);\n };\n\n const buttons = this.#panel.appendChild(document.createElement(\"div\"));\n buttons.appendChild(\n form.button({ text: \"Cancel\", on_click: () => this.#close(false) }),\n );\n buttons.appendChild(\n form.button({ text: \"Select\", on_click: () => this.#close(true) }),\n );\n //A click on the backdrop cancels, clicks in the panel stay there\n this.onpointerdown = (e) => {\n if (e.target === this) this.#close(false);\n };\n\n document.body.appendChild(this);\n return new Promise((resolve) => (this.#resolve = resolve));\n }\n\n #close(picked: boolean): void {\n const resolve = this.#resolve;\n if (!resolve) return;\n this.#resolve = undefined;\n const entries = picked\n ? this.#selection\n .ok()\n .filter((child): child is DepotEntry<T> => child.kind === \"entry\")\n : [];\n this.#tree?.dispose();\n this.remove();\n resolve(entries);\n }\n}\ndefine_element(DepotSelector);\n\n/**Opens a selector for the entries of a type or group, the promise gives the selected entries, none when cancelled.\n * The selector follows the depot while it is open*/\nexport function depot_select<T>(\n from: DepotGroup<T>,\n options: DepotSelectOptions<T> = {},\n): Promise<DepotEntry<T>[]> {\n return new DepotSelector<T>().open(from, options);\n}\n\n/**Opens the selector with a column of the live values, for the states type*/\nexport function depot_select_values<T>(\n from: DepotGroup<T>,\n options: DepotSelectOptions<T>,\n): Promise<DepotEntry<T>[]> {\n return new DepotSelector<T>().open(from, options, true);\n}\n","import depot, {\n type DepotEntry,\n type DepotGroup,\n} from \"@chocbite/ts-lib/depot\";\nimport { type DepotStateKind, state_kind } from \"./kind\";\nimport { depot_select_values } from \"./selector\";\n\nexport interface DepotStateSelectOptions {\n /**Group of the states type to select from, all states when undefined*/\n from?: DepotGroup<unknown>;\n /**Single selects one state, multi any number, single when undefined*/\n mode?: \"single\" | \"multi\";\n /**Only writable states can be selected*/\n writable?: boolean;\n /**Only states of these kinds can be selected, states of unknown kind are hidden then*/\n kind?: DepotStateKind | readonly DepotStateKind[];\n /**Further filter on the entries, after writable and kind*/\n filter?: (entry: DepotEntry<unknown>) => boolean;\n /**States selected when the selector opens*/\n selected?: readonly DepotEntry<unknown>[];\n /**Title of the selector, the name of the group when undefined*/\n title?: string;\n}\n\n/**Opens a selector for the states of the depot with their live values, the promise gives the selected entries, none when cancelled.\n * The state of an entry is its value, entry.value*/\nexport function depot_select_state(\n options: DepotStateSelectOptions = {},\n): Promise<DepotEntry<unknown>[]> {\n const from = options.from ?? depot.states;\n if (from.type !== depot.states)\n throw new Error(`Depot group \"${from.path}\" is not in the states type`);\n const kinds =\n options.kind === undefined\n ? undefined\n : typeof options.kind === \"string\"\n ? [options.kind]\n : options.kind;\n const { writable, filter } = options;\n return depot_select_values(from, {\n mode: options.mode,\n selected: options.selected,\n title: options.title,\n filter: (entry) => {\n if (writable && !entry.value.writable) return false;\n if (kinds) {\n const kind = state_kind(entry.value);\n if (!kind || !kinds.includes(kind)) return false;\n }\n return !filter || filter(entry);\n },\n });\n}\n","import { depot_select } from \"./selector\";\nimport { depot_select_state } from \"./state\";\n\nexport const depot_ui = {\n /**Opens a selector for the entries of a type or group, the promise gives the selected entries, none when cancelled*/\n select: depot_select,\n /**Opens a selector for the states of the depot with their live values, the promise gives the selected entries, none when cancelled*/\n select_state: depot_select_state,\n};\nexport default depot_ui;\n\nexport type { DepotStateKind } from \"./kind\";\nexport type { DepotSelectOptions } from \"./selector\";\nexport type { DepotStateSelectOptions } from \"./state\";\nexport { DepotTree } from \"./tree\";\n"],"mappings":";;;;;;;;;;AASA,MAAM,SANa,yBACjB,SACA,SACA,qCAGsB,CAAC,CAAC,eACxB,UACA,UACA,gCACF;AACA,OAAO,cACL,YACA,kBACA,2CACA,KAAK,SAAS,MACd,KAAK,SAAS,MACd,SACA,KAAA,CACF;AACA,OAAO,cACL,cACA,oBACA,8BACA,KAAK,OACL,KAAK,QACL,SACA,KAAA,CACF;AACA,OAAO,cACL,QACA,cACA,8BACA,KAAK,QACL,KAAK,OACL,SACA,KAAA,CACF;AACA,OAAO,cACL,UACA,gBACA,8BACA,KAAK,SAAS,MACd,KAAK,QAAQ,MACb,SACA,KAAA,CACF;;;;ACpCA,IAAa,YAAb,MAA0B;CACxB;CACA;CACA,UAAU;;CAEV,wBAAQ,IAAI,IAAmD;;CAE/D,wBAAQ,IAAI,IAA+B;CAC3C,WAAW;CACX,YAAY;CAEZ,YAAY,MAAqB,QAA4C;EAC3E,KAAK,QAAQ;EACb,KAAK,UAAU,iBAAiB;EAChC,KAAK,QAAQ,KAAK;CACpB;;CAGA,KAAK,QAAuB,KAAK,OAAkC;EACjE,OAAO,KAAK,SAAS,KAAK,CAAC,CAAC;CAC9B;;CAGA,IAAI,YAAqB;EACvB,OAAO,KAAK,YAAY;CAC1B;;CAGA,IAAI,OAAO,MAAc;EACvB,MAAM,SAAS,KAAK,KAAK,CAAC,CAAC,YAAY;EACvC,IAAI,WAAW,KAAK,SAAS;EAC7B,KAAK,UAAU;EAEf,KAAK,QAAQ,IAAI;CACnB;;CAGA,UAAgB;EACd,KAAK,YAAY;EACjB,KAAK,MAAM,CAAC,OAAO,QAAQ,KAAK,OAAO,MAAM,SAAS,MAAM,GAAG;EAC/D,KAAK,MAAM,MAAM;CACnB;CAEA,SAAS,OAAsD;EAC7D,IAAI,OAAO,KAAK,MAAM,IAAI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