@chocbite/ts-lib-ui 1.0.5 → 1.1.0

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 (53) hide show
  1. package/AGENTS.md +164 -3
  2. package/SOURCE.md +2000 -268
  3. package/base/index.mjs +7 -7
  4. package/base/index.mjs.map +1 -1
  5. package/canvas/index.mjs +8 -8
  6. package/canvas/index.mjs.map +1 -1
  7. package/context-menu/index.d.mts +2 -2
  8. package/context-menu/index.mjs +1 -1
  9. package/{context-menu-CA4o4fXx.mjs → context-menu-DE3EUtY8.mjs} +149 -111
  10. package/context-menu-DE3EUtY8.mjs.map +1 -0
  11. package/document/index.mjs +1 -1
  12. package/document/index.mjs.map +1 -1
  13. package/dom/index.mjs +1 -1
  14. package/dom/index.mjs.map +1 -1
  15. package/form/index.d.mts +4 -3
  16. package/form/index.mjs +30 -29
  17. package/form/index.mjs.map +1 -1
  18. package/icons/index.mjs +1 -1
  19. package/{icons-e2J_Ojic.mjs → icons-B88i-7MC.mjs} +2 -2
  20. package/index-Cw4AcuUl.d.mts +371 -0
  21. package/{index-DhRb2iA8.d.mts → index-YNZjMIO7.d.mts} +32 -16
  22. package/keyboard/index.mjs +12 -12
  23. package/keyboard/index.mjs.map +1 -1
  24. package/list/index.d.mts +2 -2
  25. package/list/index.mjs +1 -1
  26. package/list-D08epOjk.mjs +1566 -0
  27. package/list-D08epOjk.mjs.map +1 -0
  28. package/package.json +5 -80
  29. package/selection/index.mjs +1 -1
  30. package/selection/index.mjs.map +1 -1
  31. package/settings/index.mjs +1 -1
  32. package/settings/index.mjs.map +1 -1
  33. package/spinner/index.mjs +3 -3
  34. package/spinner/index.mjs.map +1 -1
  35. package/state_ui/index.mjs +1 -1
  36. package/{state_ui-Bm3TeKNL.mjs → state_ui-Dtm2y5RU.mjs} +3 -3
  37. package/state_ui-Dtm2y5RU.mjs.map +1 -0
  38. package/style.css +307 -63
  39. package/svg/index.mjs +1 -1
  40. package/{svg-1bp-yIPC.mjs → svg-Yz7elqnU.mjs} +16 -16
  41. package/svg-Yz7elqnU.mjs.map +1 -0
  42. package/test/index.mjs +1 -1
  43. package/test/index.mjs.map +1 -1
  44. package/theme/index.mjs +1 -1
  45. package/{theme-ChmpRObz.mjs → theme-BJS5z1iW.mjs} +9 -9
  46. package/theme-BJS5z1iW.mjs.map +1 -0
  47. package/context-menu-CA4o4fXx.mjs.map +0 -1
  48. package/index-DCn7acFY.d.mts +0 -173
  49. package/list-CNYJ3sm-.mjs +0 -715
  50. package/list-CNYJ3sm-.mjs.map +0 -1
  51. package/state_ui-Bm3TeKNL.mjs.map +0 -1
  52. package/svg-1bp-yIPC.mjs.map +0 -1
  53. package/theme-ChmpRObz.mjs.map +0 -1
package/list-CNYJ3sm-.mjs DELETED
@@ -1,715 +0,0 @@
1
- import "./style.css";
2
- import { Base, define_element } from "./base/index.mjs";
3
- import { a as px_to_rem, i as theme_init_variable_root } from "./theme-ChmpRObz.mjs";
4
- import { t as state_ui } from "./state_ui-Bm3TeKNL.mjs";
5
- import { t as ctm } from "./context-menu-CA4o4fXx.mjs";
6
- import { state as state$1 } from "@chocbite/ts-lib/state";
7
- import { none, some } from "@chocbite/ts-lib/result";
8
- import { GREY, ORANGE, RED } from "@chocbite/ts-lib/colors";
9
- import { array_from_length } from "@chocbite/ts-lib/common";
10
- // src/list/key_field.ts
11
- var ListKeyField = class extends Base {
12
- static element_name() {
13
- return "keyfield";
14
- }
15
- static element_name_space() {
16
- return "list";
17
- }
18
- #opener;
19
- #text_box;
20
- #icon;
21
- constructor(parent) {
22
- super();
23
- this.tabIndex = 0;
24
- this.onkeydown = (e) => {
25
- if (e.key === "Enter" || e.key === " ") parent.open = !parent.open;
26
- else if (e.key === "ArrowRight") parent.open = true;
27
- else if (e.key === "ArrowLeft") parent.open = false;
28
- else if (e.key === "ArrowDown") parent.select_adjacent("next", none());
29
- else if (e.key === "ArrowUp") parent.select_adjacent("previous", none());
30
- else return;
31
- e.preventDefault();
32
- };
33
- const opener_box = document.createElement("span");
34
- this.#opener = opener_box.appendChild(document.createElement("div"));
35
- this.replaceChildren(...array_from_length(parent.depth, (i) => {
36
- const div = document.createElement("div");
37
- div.style.borderColor = "var(--i-" + i + ")";
38
- return div;
39
- }), opener_box);
40
- this.#opener.addEventListener("click", (e) => {
41
- e.stopPropagation();
42
- e.preventDefault();
43
- parent.open = !parent.open;
44
- });
45
- }
46
- set options(options) {
47
- if (state$1.is.state(options?.icon)) this.attach_state_to_prop("icon", options.icon, () => some(void 0));
48
- else this.detach_state_from_prop("icon").icon = options?.icon;
49
- }
50
- set icon(value) {
51
- if (this.#icon) this.#icon.remove();
52
- this.#icon = void 0;
53
- if (!value) return;
54
- this.#icon = value();
55
- if (this.#text_box) this.insertBefore(this.#icon, this.#text_box);
56
- else this.appendChild(this.#icon);
57
- }
58
- set openable(value) {
59
- if (value) this.classList.add("openable");
60
- else this.classList.remove("openable");
61
- }
62
- get openable() {
63
- return this.classList.contains("openable");
64
- }
65
- };
66
- define_element(ListKeyField);
67
- // src/list/add_row.ts
68
- var ListAddRow = class extends Base {
69
- static element_name() {
70
- return "addrow";
71
- }
72
- static element_name_space() {
73
- return "list";
74
- }
75
- #button;
76
- #text;
77
- #icon;
78
- #parent;
79
- depth;
80
- constructor(root, parent) {
81
- super();
82
- this.#parent = parent;
83
- this.depth = parent.depth + 1;
84
- if (root.sub_rows) this.appendChild(new ListKeyField(this));
85
- this.#button = this.appendChild(document.createElement("span"));
86
- this.#button.tabIndex = 0;
87
- this.#text = this.#button.appendChild(document.createTextNode(""));
88
- }
89
- set options(options) {
90
- this.#button.onclick = options.on_add;
91
- if (state$1.is.state(options.text)) this.attach_state_to_prop("text", options.text, (e) => some(e));
92
- else this.detach_state_from_prop("text").text = options.text;
93
- if (state$1.is.state(options.disabled)) this.attach_state_to_prop("disabled", options.disabled, () => some(false));
94
- else this.detach_state_from_prop("disabled").disabled = Boolean(options.disabled);
95
- if (state$1.is.state(options.icon)) this.attach_state_to_prop("icon", options.icon, () => some(void 0));
96
- else this.detach_state_from_prop("icon").icon = options.icon;
97
- }
98
- set text(value) {
99
- this.#text.data = value;
100
- }
101
- set icon(value) {
102
- this.#icon?.remove();
103
- this.#icon = value ? this.#button.insertBefore(value(), this.#text) : void 0;
104
- }
105
- set disabled(value) {
106
- if (value) this.inert = true;
107
- else this.inert = false;
108
- }
109
- set open(_value) {}
110
- get open() {
111
- return false;
112
- }
113
- set global_index(_value) {}
114
- get global_index() {
115
- return 0;
116
- }
117
- /**Rows the add row adds to, the state of its parent */
118
- set state(_value) {}
119
- get state() {
120
- return this.#parent.state;
121
- }
122
- get global_amount() {
123
- return 0;
124
- }
125
- select_adjacent() {}
126
- };
127
- define_element(ListAddRow);
128
- // src/list/error.ts
129
- /**Error text shown instead of the fields of an invalid row */
130
- var ListError = class extends Base {
131
- static element_name() {
132
- return "error";
133
- }
134
- static element_name_space() {
135
- return "list";
136
- }
137
- set text(value) {
138
- this.textContent = value;
139
- }
140
- };
141
- define_element(ListError);
142
- /**Error text shown instead of the rows of a parent, has a key field to continue the tree lines like an add row */
143
- var ListRowsError = class extends Base {
144
- static element_name() {
145
- return "rowserror";
146
- }
147
- static element_name_space() {
148
- return "list";
149
- }
150
- #text = new ListError();
151
- #parent;
152
- depth;
153
- constructor(sub_rows, parent) {
154
- super();
155
- this.#parent = parent;
156
- this.depth = parent.depth + 1;
157
- if (sub_rows) this.appendChild(new ListKeyField(this));
158
- this.appendChild(this.#text);
159
- }
160
- set text(value) {
161
- this.#text.text = value;
162
- }
163
- set open(_value) {}
164
- get open() {
165
- return false;
166
- }
167
- /**Rows the error is shown for, the state of its parent */
168
- set state(_value) {}
169
- get state() {
170
- return this.#parent.state;
171
- }
172
- select_adjacent() {}
173
- };
174
- define_element(ListRowsError);
175
- /**Shows the text in an error element directly after the row box, removes the element when there is no text
176
- * @returns the element to give next time, undefined when there is no text*/
177
- function list_rows_error_update(row_box, current, text, sub_rows, parent) {
178
- if (text === void 0) {
179
- current?.remove();
180
- return;
181
- }
182
- if (!current) {
183
- current = new ListRowsError(sub_rows, parent);
184
- row_box.after(current);
185
- }
186
- current.text = text;
187
- return current;
188
- }
189
- // src/list/field.ts
190
- /**Adds the class for the alignment, center is the default and adds nothing
191
- * Only the styling of an element decides if the class does anything, so complex fields just do not follow it */
192
- function list_align_apply(element, align) {
193
- if (align === "left" || align === "right") element.classList.add("align-" + align);
194
- }
195
- var ListField = class extends Base {
196
- static element_name() {
197
- return "@abstract@";
198
- }
199
- static element_name_space() {
200
- return "list";
201
- }
202
- constructor() {
203
- super();
204
- }
205
- };
206
- var ListTextField = class extends ListField {
207
- static element_name() {
208
- return "textfield";
209
- }
210
- set text(value) {
211
- this.textContent = value;
212
- }
213
- };
214
- define_element(ListTextField);
215
- function text_field() {
216
- return new ListTextField();
217
- }
218
- var ListNumberField = class extends ListField {
219
- static element_name() {
220
- return "numberfield";
221
- }
222
- set number(value) {
223
- this.textContent = value.toString();
224
- }
225
- };
226
- define_element(ListNumberField);
227
- function number_field() {
228
- return new ListNumberField();
229
- }
230
- var ListNodeField = class extends ListField {
231
- static element_name() {
232
- return "nodefield";
233
- }
234
- constructor(node) {
235
- super();
236
- this.appendChild(node);
237
- }
238
- set node(node) {
239
- this.replaceChildren(node);
240
- }
241
- get node() {
242
- return this.firstChild;
243
- }
244
- };
245
- define_element(ListNodeField);
246
- function node_field(node) {
247
- return new ListNodeField(node);
248
- }
249
- // src/list/row.ts
250
- var ListRow = class ListRow extends Base {
251
- static element_name() {
252
- return "row";
253
- }
254
- static element_name_space() {
255
- return "list";
256
- }
257
- #root;
258
- #parent;
259
- #sub_rows;
260
- depth;
261
- #key_field;
262
- #field_box;
263
- #child_box;
264
- #add_row;
265
- #fields;
266
- #values;
267
- /**Shown instead of the fields while the row is invalid */
268
- #invalid;
269
- /**Shown instead of the sub rows while their state has an error */
270
- #error;
271
- #open_pending = false;
272
- #sub_row_menu = false;
273
- #state_sub;
274
- state;
275
- constructor(root, parent, data) {
276
- super();
277
- this.#root = root;
278
- this.#parent = parent;
279
- this.depth = parent.depth + 1;
280
- this.style.setProperty("--i-" + this.depth, "var(--c)");
281
- if (this.#root.sub_rows) {
282
- this.#key_field = new ListKeyField(this);
283
- if (this.#root.observer) this.#key_field.attach_to_intersect_observer(this.#root.observer);
284
- }
285
- this.#field_box = this.appendChild(document.createElement("div"));
286
- this.#child_box = this.appendChild(document.createElement("span"));
287
- if (this.#root.sub_rows) this.#child_box.oncontextmenu = () => {
288
- this.#sub_row_menu = true;
289
- };
290
- this.#fields = this.#generate_fields();
291
- this.#show_cells(this.#fields);
292
- this.data = data;
293
- }
294
- #generate_fields() {
295
- return this.#root.columns_visible.map((key) => {
296
- const column = this.#root.columns.get(key);
297
- const field = column.field_gen();
298
- list_align_apply(field, column.align);
299
- if (this.#root.observer) field.attach_to_intersect_observer(this.#root.observer);
300
- return field;
301
- });
302
- }
303
- /**Shows the cells after the key field, which stays so an invalid row keeps its indent and arrow key navigation */
304
- #show_cells(cells) {
305
- if (this.#key_field) this.#field_box.replaceChildren(this.#key_field, ...cells);
306
- else this.#field_box.replaceChildren(...cells);
307
- }
308
- #apply_values() {
309
- this.#root.columns_visible.forEach((key, index) => {
310
- this.#root.columns.get(key).field_apply(this.#fields[index], this.#values[key]);
311
- });
312
- }
313
- /**Regenerates the fields of the row and its sub rows after the columns changed */
314
- columns_changed() {
315
- this.#fields = this.#generate_fields();
316
- if (!this.#invalid) {
317
- this.#show_cells(this.#fields);
318
- this.#apply_values();
319
- }
320
- for (let i = 0; i < this.#child_box.childElementCount; i++) this.#child_box.children[i].columns_changed();
321
- }
322
- select_adjacent(direction, field) {
323
- if (!this.#key_field) return;
324
- const has_rows = this.#child_box.childElementCount > 0;
325
- if (direction === "next" || direction === "p_next") {
326
- if (direction === "next" && has_rows) this.#child_box.firstElementChild.#key_field.focus();
327
- else {
328
- const sibling = this.nextElementSibling;
329
- if (sibling instanceof ListRow) sibling.#key_field.focus();
330
- else this.#parent.select_adjacent("p_next", field);
331
- }
332
- } else if (direction === "previous") {
333
- const sibling = this.previousElementSibling;
334
- if (sibling instanceof ListRow) {
335
- if (sibling.open) sibling.select_adjacent("last", field);
336
- else sibling.#key_field.focus();
337
- } else this.#parent.select_adjacent("p_previous", field);
338
- } else if (direction === "p_previous") this.#key_field.focus();
339
- else if (direction === "last") {
340
- if (has_rows) this.#child_box.lastElementChild.select_adjacent("last", field);
341
- else this.#key_field.focus();
342
- }
343
- }
344
- set data(data) {
345
- const result = this.#root.transform(data, this, this.#parent.state);
346
- if (!result.ok) {
347
- this.#set_invalid(result.error);
348
- return;
349
- }
350
- const row_options = result.value;
351
- if (this.#invalid) {
352
- this.#invalid = void 0;
353
- this.#show_cells(this.#fields);
354
- }
355
- if (this.#key_field) this.#key_field.options = row_options.key_field;
356
- this.#sub_rows = row_options.sub_rows;
357
- this.add_row = row_options.add_row;
358
- this.#values = row_options.values;
359
- this.#apply_values();
360
- const was_open = this.open;
361
- if (state$1.is.state(row_options.openable)) {
362
- this.#open_pending = !was_open && Boolean(row_options.opened);
363
- this.attach_state_to_prop("openable", row_options.openable, () => some(false));
364
- } else {
365
- this.#open_pending = false;
366
- this.detach_state_from_prop("openable");
367
- this.openable = Boolean(row_options.openable);
368
- if (!was_open && row_options.opened) this.open = true;
369
- }
370
- if (was_open && this.open) {
371
- if (this.#sub_rows) this.rows = this.#sub_rows();
372
- else if (!row_options.opened) this.open = false;
373
- }
374
- ctm.detach(this);
375
- this.#sub_row_menu = false;
376
- if (row_options.context_menu) ctm.attach(this, row_options.context_menu, () => {
377
- const from_sub_row = this.#sub_row_menu;
378
- this.#sub_row_menu = false;
379
- return from_sub_row;
380
- });
381
- }
382
- /**Replaces the fields with the text and removes everything else the row options gave */
383
- #set_invalid(text) {
384
- if (this.#key_field) this.#key_field.options = void 0;
385
- this.#sub_rows = void 0;
386
- this.add_row = void 0;
387
- this.#open_pending = false;
388
- this.detach_state_from_prop("openable");
389
- this.openable = false;
390
- ctm.detach(this);
391
- this.#sub_row_menu = false;
392
- if (!this.#invalid) {
393
- this.#invalid = new ListError();
394
- this.#show_cells([this.#invalid]);
395
- }
396
- this.#invalid.text = text;
397
- }
398
- set add_row(options) {
399
- if (!options && this.#add_row) {
400
- this.#add_row.remove();
401
- this.classList.remove("addrow");
402
- this.#add_row = void 0;
403
- } else if (options) {
404
- if (!this.#add_row) {
405
- this.classList.add("addrow");
406
- this.#add_row = this.appendChild(new ListAddRow(this.#root, this));
407
- }
408
- this.#add_row.options = options;
409
- }
410
- }
411
- set openable(value) {
412
- if (!value) this.open = false;
413
- if (this.#key_field) this.#key_field.openable = value;
414
- if (this.#open_pending) {
415
- this.#open_pending = false;
416
- if (value) this.open = true;
417
- }
418
- }
419
- get openable() {
420
- return this.#key_field?.openable ?? false;
421
- }
422
- set open(open) {
423
- if (!this.openable) return;
424
- if (open && this.#child_box.childElementCount === 0) {
425
- if (this.#sub_rows) this.rows = this.#sub_rows?.();
426
- } else if (!open && this.open) this.rows = [];
427
- }
428
- get open() {
429
- return this.classList.contains("open");
430
- }
431
- get index() {
432
- return Array.prototype.indexOf.call(this.parentElement.children, this);
433
- }
434
- amount_rows(rec = false) {
435
- let count = this.#child_box.childElementCount;
436
- if (rec) for (let i = 0; i < this.#child_box.childElementCount; i++) count += this.#child_box.children[i].amount_rows(true);
437
- return count;
438
- }
439
- set rows(rows) {
440
- if (this.#state_sub) this.detach_state(this.#state_sub);
441
- this.#state_sub = void 0;
442
- this.state = rows;
443
- if (state$1.is.state(rows)) this.#state_sub = this.attach_state(rows, (r) => this.#update_rows(r.ok ? r.value : [], r.ok ? void 0 : r.error));
444
- else this.#update_rows(rows);
445
- }
446
- #update_rows(rows, error) {
447
- this.#error = list_rows_error_update(this.#child_box, this.#error, error, this.#root.sub_rows, this);
448
- this.classList.toggle("open", rows.length > 0 || error !== void 0);
449
- state_ui.a.apply(this.#child_box, rows, {
450
- create: (row) => new ListRow(this.#root, this, row),
451
- update: (element, row) => element.data = row
452
- });
453
- }
454
- };
455
- define_element(ListRow);
456
- // src/list/shared.ts
457
- const theme_root = theme_init_variable_root("list", "UI List Elements", "Theme variables for UI list elements");
458
- theme_root.make_sub_group("read", "Read Only", "Settings for list elements in read only mode").make_variable("filter", "Read Only Filter", "Filter applied to list elements in read only mode", "opacity(0.6)", "opacity(0.6)", "Filter", void 0);
459
- const colors = theme_root.make_sub_group("colors", "Colors", "Colors used in all list elements");
460
- const colors_text = colors.make_sub_group("text", "Text Colors", "Text colors used in all list elements");
461
- colors_text.make_variable("header", "Header Text Color", "Header text color in list elements", GREY["900"], GREY["50"], "Color", void 0);
462
- colors_text.make_variable("field", "Field Text Color", "Text color of list field elements", GREY["800"], GREY["100"], "Color", void 0);
463
- colors_text.make_variable("key_field", "Special Column Text Color", "Text color of special first column elements", GREY["900"], GREY["50"], "Color", void 0);
464
- colors_text.make_variable("add", "Row Adder Text Color", "Text color of row adder button", GREY["900"], GREY["50"], "Color", void 0);
465
- colors_text.make_variable("error", "Error Text Color", "Text color of list errors and invalid rows", RED["800"], RED["200"], "Color", void 0);
466
- const colors_icon = colors.make_sub_group("icon", "Icon Colors", "Icon colors used in all form elements");
467
- colors_icon.make_variable("sub_opener", "Sub Row Opener Icon Color", "Color of the sub row opener icon", GREY["800"], GREY["200"], "Color", void 0);
468
- colors_icon.make_variable("key_icon", "Key Field Icon Color", "Color of the key field icon", GREY["800"], GREY["200"], "Color", void 0);
469
- colors_icon.make_variable("add_icon", "Add Row Icon Color", "Color of the add row icon", GREY["800"], GREY["200"], "Color", void 0);
470
- const colors_background = colors.make_sub_group("background", "Background Colors", "Background colors used in all list elements");
471
- colors_background.make_variable("row_even", "Even Row Background Color", "Color of even row element backgrounds", GREY["200"], GREY["800"], "Color", void 0);
472
- colors_background.make_variable("row_odd", "Odd Row Background Color", "Color of odd row element backgrounds", GREY["50"], GREY["900"], "Color", void 0);
473
- colors_background.make_variable("row_hover", "Hover Row Background Color", "Color of row element backgrounds when hovering", GREY["300"], GREY["700"], "Color", void 0);
474
- const colors_border = colors.make_sub_group("border", "Border Colors", "Border colors used in all list elements");
475
- colors_border.make_variable("header", "Header Border Color", "Color of borders under header", GREY["600"], GREY["400"], "Color", void 0);
476
- colors_border.make_variable("row", "Row Border Color", "Color of borders between rows", GREY["400"], GREY["600"], "Color", void 0);
477
- colors_border.make_variable("column", "Column Border Color", "Color of border between columns", GREY["500"], GREY["500"], "Color", void 0);
478
- colors.make_sub_group("focus", "Focus Colors", "Focus colors used in all list elements").make_variable("normal", "Focus Color", "Color of focussed list element", ORANGE["600"], ORANGE["300"], "Color", void 0);
479
- const sizes = theme_root.make_sub_group("size", "Size", "Sizes used in all list elements");
480
- sizes.make_variable("row_min", "Row Minimum Height", "Minimum height for list rows", "1.4rem", "1.4rem", "Length", {
481
- min: .1,
482
- max: 10
483
- });
484
- sizes.make_variable("touch_row_min", "Touch Row Minimum Height", "Minimum height for list rows on touch devices", "2.6rem", "2.6rem", "Length", {
485
- min: .1,
486
- max: 10
487
- });
488
- sizes.make_variable("add_min", "Add Row Minimum Height", "Minimum height for add row button", "1rem", "1rem", "Length", {
489
- min: .1,
490
- max: 10
491
- });
492
- sizes.make_variable("touch_add_min", "Touch Add Row Minimum Height", "Minimum height for add row button on touch devices", "2rem", "2rem", "Length", {
493
- min: .1,
494
- max: 10
495
- });
496
- const animation = theme_root.make_sub_group("animation", "Animation", "Animation settings used in all list elements");
497
- animation.make_variable("transitionType", "Transition Type", "Type of transition used in list element animations", "ease-in-out", "ease-in-out", "TransitionType", void 0);
498
- animation.make_variable("transitionDuration", "Transition Duration", "Duration of transitions used in list element animations", "200ms", "200ms", "Time", {
499
- min: 0,
500
- max: 5e3
501
- });
502
- const font = theme_root.make_sub_group("font", "Font", "Font settings used in all list elements");
503
- font.make_variable("size", "Font Size", "Default font size used in all list elements", "1rem", "1rem", "Length", {
504
- min: .1,
505
- max: 10
506
- });
507
- font.make_variable("touchSize", "Touch Font Size", "Font size used in all list elements for touch devices", "1.2rem", "1.2rem", "Length", {
508
- min: .1,
509
- max: 10
510
- });
511
- // src/list/container.ts
512
- var HeaderField = class extends Base {
513
- static element_name() {
514
- return "headerfield";
515
- }
516
- static element_name_space() {
517
- return "list";
518
- }
519
- #box = this.appendChild(document.createElement("div"));
520
- #text = this.#box.appendChild(document.createElement("span"));
521
- #sizer;
522
- constructor(text) {
523
- super();
524
- if (text) this.text = text;
525
- }
526
- set text(value) {
527
- this.#text.textContent = value;
528
- }
529
- sizable(sizeable, sizer) {
530
- if (sizeable) {
531
- this.#sizer = this.#box.appendChild(document.createElement("div"));
532
- let double_timeout;
533
- this.#sizer.onpointerdown = (e) => {
534
- e.preventDefault();
535
- if (double_timeout) {
536
- sizer(void 0);
537
- return;
538
- }
539
- double_timeout = window.setTimeout(() => {
540
- double_timeout = 0;
541
- }, 300);
542
- this.setPointerCapture(e.pointerId);
543
- const start_x = e.pageX;
544
- const start_width = this.#box.offsetWidth;
545
- this.onpointermove = (ev) => {
546
- sizer(px_to_rem(start_width + (ev.pageX - start_x)));
547
- };
548
- this.onpointerup = () => {
549
- this.releasePointerCapture(e.pointerId);
550
- this.onpointermove = null;
551
- this.onpointerup = null;
552
- };
553
- };
554
- } else if (this.#sizer) {
555
- this.#sizer.remove();
556
- this.#sizer = void 0;
557
- }
558
- }
559
- };
560
- define_element(HeaderField);
561
- var HeaderRow = class extends Base {
562
- static element_name() {
563
- return "headerrow";
564
- }
565
- static element_name_space() {
566
- return "list";
567
- }
568
- set fields(fields) {
569
- if (this.#root.sub_rows) this.replaceChildren(text_field(), ...fields);
570
- else this.replaceChildren(...fields);
571
- }
572
- #root;
573
- constructor(root) {
574
- super();
575
- this.#root = root;
576
- }
577
- };
578
- define_element(HeaderRow);
579
- var Container = class extends Base {
580
- static element_name() {
581
- return "container";
582
- }
583
- static element_name_space() {
584
- return "list";
585
- }
586
- #root;
587
- #parent;
588
- #box = this.appendChild(document.createElement("div"));
589
- #header;
590
- #child_box;
591
- #error;
592
- #add_row;
593
- #state_sub;
594
- constructor(columns, transform, rows, options) {
595
- super();
596
- this.#root = {
597
- sub_rows: options?.sub_rows ?? false,
598
- columns: /* @__PURE__ */ new Map(),
599
- columns_visible: [],
600
- transform,
601
- observer: options?.observer
602
- };
603
- this.#parent = {
604
- depth: -1,
605
- open: false,
606
- select_adjacent() {},
607
- state: rows
608
- };
609
- if (!options?.headless) this.#header = this.#box.appendChild(new HeaderRow(this.#root));
610
- this.#child_box = this.#box.appendChild(document.createElement("div"));
611
- if (options?.sub_rows) this.#box.classList.add("sub-rows");
612
- this.add_row = options?.add_row;
613
- this.columns = columns;
614
- this.rows = rows;
615
- }
616
- set columns(columns) {
617
- this.#root.columns.clear();
618
- const order = /* @__PURE__ */ new Map();
619
- let index = 0;
620
- for (const key in columns) {
621
- this.#root.columns.set(key, { ...columns[key] });
622
- order.set(key, columns[key].order ?? index);
623
- index++;
624
- }
625
- this.#root.columns_visible = [...order.keys()].sort((a, b) => order.get(a) - order.get(b));
626
- if (this.#header) this.#header.fields = this.#root.columns_visible.map((key) => {
627
- const column = this.#root.columns.get(key);
628
- const header = new HeaderField(column.title);
629
- list_align_apply(header, column.align);
630
- header.sizable(typeof column.fixed_width === "undefined", (width) => {
631
- column.init_width = width;
632
- this.#update_column_widths();
633
- });
634
- return header;
635
- });
636
- this.#update_column_widths();
637
- for (let i = 0; i < this.#child_box.childElementCount; i++) this.#child_box.children[i].columns_changed();
638
- }
639
- #update_column_widths() {
640
- const widths = this.#root.columns_visible.map((key) => {
641
- const col = this.#root.columns.get(key);
642
- const width = col.fixed_width ?? col.init_width;
643
- if (width) {
644
- if (width === "min") return "min-content";
645
- else if (width === "max") return "max-content";
646
- return `${Math.max(width, 1)}rem`;
647
- }
648
- return "auto";
649
- });
650
- if (this.#root.sub_rows) widths.unshift("min-content");
651
- this.#box.style.gridTemplateColumns = widths.join(" ");
652
- }
653
- set add_row(options) {
654
- if (!options && this.#add_row) {
655
- this.#add_row.remove();
656
- this.#box.classList.remove("addrow");
657
- this.#add_row = void 0;
658
- } else if (options) {
659
- if (!this.#add_row) {
660
- this.#box.classList.add("addrow");
661
- this.#add_row = this.#box.appendChild(new ListAddRow(this.#root, this.#parent));
662
- }
663
- this.#add_row.options = options;
664
- }
665
- }
666
- amount_rows(rec = false) {
667
- let count = this.#child_box.childElementCount;
668
- if (rec) for (let i = 0; i < this.#child_box.childElementCount; i++) count += this.#child_box.children[i].amount_rows(true);
669
- return count;
670
- }
671
- set rows(rows) {
672
- if (this.#state_sub) this.detach_state(this.#state_sub);
673
- this.#state_sub = void 0;
674
- this.#parent.state = rows;
675
- if (state$1.is.state(rows)) this.#state_sub = this.attach_state(rows, (r) => this.#update_rows(r.ok ? r.value : [], r.ok ? void 0 : r.error));
676
- else this.#update_rows(rows);
677
- }
678
- #update_rows(rows, error) {
679
- this.#error = list_rows_error_update(this.#child_box, this.#error, error, this.#root.sub_rows, this.#parent);
680
- state_ui.a.apply(this.#child_box, rows, {
681
- create: (row) => new ListRow(this.#root, this.#parent, row),
682
- update: (element, row) => element.data = row
683
- });
684
- }
685
- };
686
- define_element(Container);
687
- function container(columns, transform, rows, options) {
688
- return new Container(columns, transform, rows, options);
689
- }
690
- // src/list/types.ts
691
- /**Helper to create a column object */
692
- function column(options) {
693
- return options;
694
- }
695
- /**Special helper to create a string value column */
696
- function column_string(title, options) {
697
- return {
698
- title,
699
- align: options?.align,
700
- field_gen: () => list.text_field(),
701
- field_apply: (field, value) => field.text = value
702
- };
703
- }
704
- // src/list/index.ts
705
- const list = {
706
- column,
707
- column_string,
708
- container,
709
- text_field,
710
- number_field,
711
- node_field
712
- };
713
- export { ListField as n, list as t };
714
-
715
- //# sourceMappingURL=list-CNYJ3sm-.mjs.map