@chocbite/ts-lib-ui 1.0.2 → 1.0.4
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.
- package/README.md +16 -1
- package/base/index.d.mts +2 -2
- package/base/index.mjs +69 -77
- package/base/index.mjs.map +1 -1
- package/canvas/index.d.mts +117 -60
- package/canvas/index.mjs +652 -584
- package/canvas/index.mjs.map +1 -1
- package/context-menu/index.d.mts +1 -1
- package/context-menu/index.mjs +1 -1
- package/{context-menu-CiNcuP-a.mjs → context-menu-Cz9rqUaM.mjs} +71 -37
- package/context-menu-Cz9rqUaM.mjs.map +1 -0
- package/document/index.mjs +3 -1
- package/document/index.mjs.map +1 -1
- package/form/index.d.mts +16 -5
- package/form/index.mjs +412 -153
- package/form/index.mjs.map +1 -1
- package/icons/index.d.mts +1 -1
- package/icons/index.mjs +1 -1
- package/icons-e2J_Ojic.mjs +4124 -0
- package/{index-BcidwqIy.d.mts → index-BDWg5GX2.d.mts} +7 -18
- package/{index-BND79jZp.d.mts → index-CvzH3M_5.d.mts} +16 -9
- package/{index-CugtUzv_.d.mts → index-DCn7acFY.d.mts} +30 -12
- package/{index-CB3-qP6l.d.mts → index-DhRb2iA8.d.mts} +7 -5
- package/keyboard/index.d.mts +1 -1
- package/keyboard/index.mjs +121 -50
- package/keyboard/index.mjs.map +1 -1
- package/list/index.d.mts +1 -1
- package/list/index.mjs +1 -1
- package/{list-CQDnxsLV.mjs → list-DXkEJKjx.mjs} +218 -117
- package/list-DXkEJKjx.mjs.map +1 -0
- package/package.json +7 -7
- package/selection/index.mjs +9 -11
- package/selection/index.mjs.map +1 -1
- package/settings/index.d.mts +23 -5
- package/settings/index.mjs +17 -10
- package/settings/index.mjs.map +1 -1
- package/spinner/index.d.mts +1 -1
- package/spinner/index.mjs +2 -2
- package/state/index.d.mts +36 -0
- package/state/index.mjs +2 -0
- package/state-OCzEmq3j.mjs +87 -0
- package/state-OCzEmq3j.mjs.map +1 -0
- package/style.css +423 -142
- package/svg/index.d.mts +1 -1
- package/svg/index.mjs +1 -1
- package/{svg-golJPaR4.mjs → svg-1bp-yIPC.mjs} +20 -17
- package/svg-1bp-yIPC.mjs.map +1 -0
- package/theme/index.d.mts +21 -2
- package/theme/index.mjs +1 -1
- package/{theme-9ib89_3b.mjs → theme-CFeGnUuF.mjs} +125 -44
- package/theme-CFeGnUuF.mjs.map +1 -0
- package/context-menu-CiNcuP-a.mjs.map +0 -1
- package/icons-CY4BLQ2F.mjs +0 -4123
- package/list-CQDnxsLV.mjs.map +0 -1
- package/svg-golJPaR4.mjs.map +0 -1
- package/theme-9ib89_3b.mjs.map +0 -1
- package/viewport/index.d.mts +0 -1
- package/viewport/index.mjs +0 -2
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import "./style.css";
|
|
2
2
|
import { Base, define_element } from "./base/index.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { t as state_ui } from "./state-OCzEmq3j.mjs";
|
|
4
|
+
import { a as px_to_rem, i as theme_init_variable_root } from "./theme-CFeGnUuF.mjs";
|
|
5
|
+
import { t as ctm } from "./context-menu-Cz9rqUaM.mjs";
|
|
5
6
|
import { state as state$1 } from "@chocbite/ts-lib/state";
|
|
6
7
|
import { none, some } from "@chocbite/ts-lib/result";
|
|
8
|
+
import { GREY, ORANGE, RED } from "@chocbite/ts-lib/colors";
|
|
7
9
|
import { array_from_length } from "@chocbite/ts-lib/common";
|
|
8
|
-
import { GREY, ORANGE } from "@chocbite/ts-lib/colors";
|
|
9
10
|
// src/list/key_field.ts
|
|
10
11
|
var ListKeyField = class extends Base {
|
|
11
12
|
static element_name() {
|
|
@@ -44,7 +45,7 @@ var ListKeyField = class extends Base {
|
|
|
44
45
|
}
|
|
45
46
|
set options(options) {
|
|
46
47
|
if (state$1.is.state(options?.icon)) this.attach_state_to_prop("icon", options.icon, () => some(void 0));
|
|
47
|
-
else this.icon = options?.icon;
|
|
48
|
+
else this.detach_state_from_prop("icon").icon = options?.icon;
|
|
48
49
|
}
|
|
49
50
|
set icon(value) {
|
|
50
51
|
if (this.#icon) this.#icon.remove();
|
|
@@ -72,23 +73,34 @@ var ListAddRow = class extends Base {
|
|
|
72
73
|
return "list";
|
|
73
74
|
}
|
|
74
75
|
#button;
|
|
76
|
+
#text;
|
|
77
|
+
#icon;
|
|
78
|
+
#parent;
|
|
75
79
|
depth;
|
|
76
80
|
constructor(root, parent) {
|
|
77
81
|
super();
|
|
82
|
+
this.#parent = parent;
|
|
78
83
|
this.depth = parent.depth + 1;
|
|
79
84
|
if (root.sub_rows) this.appendChild(new ListKeyField(this));
|
|
80
85
|
this.#button = this.appendChild(document.createElement("span"));
|
|
81
86
|
this.#button.tabIndex = 0;
|
|
87
|
+
this.#text = this.#button.appendChild(document.createTextNode(""));
|
|
82
88
|
}
|
|
83
89
|
set options(options) {
|
|
84
90
|
this.#button.onclick = options.on_add;
|
|
85
91
|
if (state$1.is.state(options.text)) this.attach_state_to_prop("text", options.text, (e) => some(e));
|
|
86
|
-
else this.text = options.text;
|
|
92
|
+
else this.detach_state_from_prop("text").text = options.text;
|
|
87
93
|
if (state$1.is.state(options.disabled)) this.attach_state_to_prop("disabled", options.disabled, () => some(false));
|
|
88
|
-
else
|
|
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;
|
|
89
97
|
}
|
|
90
98
|
set text(value) {
|
|
91
|
-
this.#
|
|
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;
|
|
92
104
|
}
|
|
93
105
|
set disabled(value) {
|
|
94
106
|
if (value) this.inert = true;
|
|
@@ -102,9 +114,10 @@ var ListAddRow = class extends Base {
|
|
|
102
114
|
get global_index() {
|
|
103
115
|
return 0;
|
|
104
116
|
}
|
|
117
|
+
/**Rows the add row adds to, the state of its parent */
|
|
105
118
|
set state(_value) {}
|
|
106
119
|
get state() {
|
|
107
|
-
|
|
120
|
+
return this.#parent.state;
|
|
108
121
|
}
|
|
109
122
|
get global_amount() {
|
|
110
123
|
return 0;
|
|
@@ -112,7 +125,73 @@ var ListAddRow = class extends Base {
|
|
|
112
125
|
select_adjacent() {}
|
|
113
126
|
};
|
|
114
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
|
+
}
|
|
115
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
|
+
}
|
|
116
195
|
var ListField = class extends Base {
|
|
117
196
|
static element_name() {
|
|
118
197
|
return "@abstract@";
|
|
@@ -129,7 +208,7 @@ var ListTextField = class extends ListField {
|
|
|
129
208
|
return "textfield";
|
|
130
209
|
}
|
|
131
210
|
set text(value) {
|
|
132
|
-
this.
|
|
211
|
+
this.textContent = value;
|
|
133
212
|
}
|
|
134
213
|
};
|
|
135
214
|
define_element(ListTextField);
|
|
@@ -141,7 +220,7 @@ var ListNumberField = class extends ListField {
|
|
|
141
220
|
return "numberfield";
|
|
142
221
|
}
|
|
143
222
|
set number(value) {
|
|
144
|
-
this.
|
|
223
|
+
this.textContent = value.toString();
|
|
145
224
|
}
|
|
146
225
|
};
|
|
147
226
|
define_element(ListNumberField);
|
|
@@ -184,6 +263,13 @@ var ListRow = class ListRow extends Base {
|
|
|
184
263
|
#child_box;
|
|
185
264
|
#add_row;
|
|
186
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;
|
|
187
273
|
#state_sub;
|
|
188
274
|
state;
|
|
189
275
|
constructor(root, parent, data) {
|
|
@@ -198,19 +284,46 @@ var ListRow = class ListRow extends Base {
|
|
|
198
284
|
}
|
|
199
285
|
this.#field_box = this.appendChild(document.createElement("div"));
|
|
200
286
|
this.#child_box = this.appendChild(document.createElement("span"));
|
|
201
|
-
this.#
|
|
202
|
-
|
|
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);
|
|
203
299
|
if (this.#root.observer) field.attach_to_intersect_observer(this.#root.observer);
|
|
204
300
|
return field;
|
|
205
301
|
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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();
|
|
209
321
|
}
|
|
210
322
|
select_adjacent(direction, field) {
|
|
211
323
|
if (!this.#key_field) return;
|
|
324
|
+
const has_rows = this.#child_box.childElementCount > 0;
|
|
212
325
|
if (direction === "next" || direction === "p_next") {
|
|
213
|
-
if (direction === "next" &&
|
|
326
|
+
if (direction === "next" && has_rows) this.#child_box.firstElementChild.#key_field.focus();
|
|
214
327
|
else {
|
|
215
328
|
const sibling = this.nextElementSibling;
|
|
216
329
|
if (sibling instanceof ListRow) sibling.#key_field.focus();
|
|
@@ -224,36 +337,63 @@ var ListRow = class ListRow extends Base {
|
|
|
224
337
|
} else this.#parent.select_adjacent("p_previous", field);
|
|
225
338
|
} else if (direction === "p_previous") this.#key_field.focus();
|
|
226
339
|
else if (direction === "last") {
|
|
227
|
-
if (
|
|
340
|
+
if (has_rows) this.#child_box.lastElementChild.select_adjacent("last", field);
|
|
228
341
|
else this.#key_field.focus();
|
|
229
342
|
}
|
|
230
343
|
}
|
|
231
344
|
set data(data) {
|
|
232
|
-
const
|
|
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
|
+
}
|
|
233
355
|
if (this.#key_field) this.#key_field.options = row_options.key_field;
|
|
234
356
|
this.#sub_rows = row_options.sub_rows;
|
|
235
357
|
this.add_row = row_options.add_row;
|
|
236
|
-
this.#
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if (state$1.is.state(row_options.openable))
|
|
240
|
-
this
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
|
|
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;
|
|
244
366
|
this.detach_state_from_prop("openable");
|
|
245
|
-
this.openable = row_options.openable;
|
|
367
|
+
this.openable = Boolean(row_options.openable);
|
|
368
|
+
if (!was_open && row_options.opened) this.open = true;
|
|
246
369
|
}
|
|
247
|
-
if (
|
|
248
|
-
if (this.
|
|
249
|
-
|
|
250
|
-
} else this.open = true;
|
|
251
|
-
} else if (this.open) {
|
|
252
|
-
if (this.#sub_rows) this.rows = this.#sub_rows?.();
|
|
253
|
-
else this.open = false;
|
|
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;
|
|
254
373
|
}
|
|
255
374
|
ctm.detach(this);
|
|
256
|
-
|
|
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;
|
|
257
397
|
}
|
|
258
398
|
set add_row(options) {
|
|
259
399
|
if (!options && this.#add_row) {
|
|
@@ -271,6 +411,10 @@ var ListRow = class ListRow extends Base {
|
|
|
271
411
|
set openable(value) {
|
|
272
412
|
if (!value) this.open = false;
|
|
273
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
|
+
}
|
|
274
418
|
}
|
|
275
419
|
get openable() {
|
|
276
420
|
return this.#key_field?.openable ?? false;
|
|
@@ -296,42 +440,16 @@ var ListRow = class ListRow extends Base {
|
|
|
296
440
|
if (this.#state_sub) this.detach_state(this.#state_sub);
|
|
297
441
|
this.#state_sub = void 0;
|
|
298
442
|
this.state = rows;
|
|
299
|
-
if (state$1.is.state(rows)) this.#state_sub = this.attach_state(rows, (r) => this.#update_rows(r.ok ? r.value : []));
|
|
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));
|
|
300
444
|
else this.#update_rows(rows);
|
|
301
445
|
}
|
|
302
|
-
#update_rows(rows) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
for (let i = 0; i < read.length; i++) {
|
|
310
|
-
const row = read[i];
|
|
311
|
-
if (row.type === "fresh") {
|
|
312
|
-
const min = Math.min(this.#child_box.childElementCount, row.items.length);
|
|
313
|
-
for (let i = 0; i < min; i++) this.#child_box.children[i].data = row.items[i];
|
|
314
|
-
if (row.items.length > this.#child_box.childElementCount) this.#child_box.append(...row.items.slice(this.#child_box.childElementCount).map((row) => new ListRow(this.#root, this, row)));
|
|
315
|
-
else if (row.items.length < this.#child_box.childElementCount) for (let i = this.#child_box.childElementCount - 1; i >= row.items.length; i--) this.#child_box.children[i].remove();
|
|
316
|
-
} else if (row.type === "added") {
|
|
317
|
-
const child = this.#child_box.children[row.index];
|
|
318
|
-
const rows = row.items.map((row) => new ListRow(this.#root, this, row));
|
|
319
|
-
if (child) child.before(...rows);
|
|
320
|
-
else this.#child_box.append(...rows);
|
|
321
|
-
} else if (row.type === "removed") for (let i = 0; i < row.items.length; i++) this.#child_box.children[row.index].remove();
|
|
322
|
-
else if (row.type === "changed") for (let i = 0; i < row.items.length; i++) this.#child_box.children[row.index + i].data = row.items[i];
|
|
323
|
-
else if (row.type === "moved") {
|
|
324
|
-
const extracted = [];
|
|
325
|
-
for (let i = 0; i < row.items.length; i++) {
|
|
326
|
-
const child = this.#child_box.children[row.from_index + i];
|
|
327
|
-
extracted.push(child);
|
|
328
|
-
child.remove();
|
|
329
|
-
}
|
|
330
|
-
const child = this.#child_box.children[row.to_index];
|
|
331
|
-
for (let i = 0; i < extracted.length; i++) if (child) child.before(extracted[i]);
|
|
332
|
-
else this.#child_box.append(extracted[i]);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
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
|
+
});
|
|
335
453
|
}
|
|
336
454
|
};
|
|
337
455
|
define_element(ListRow);
|
|
@@ -344,12 +462,13 @@ colors_text.make_variable("header", "Header Text Color", "Header text color in l
|
|
|
344
462
|
colors_text.make_variable("field", "Field Text Color", "Text color of list field elements", GREY["800"], GREY["100"], "Color", void 0);
|
|
345
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);
|
|
346
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);
|
|
347
466
|
const colors_icon = colors.make_sub_group("icon", "Icon Colors", "Icon colors used in all form elements");
|
|
348
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);
|
|
349
468
|
colors_icon.make_variable("key_icon", "Key Field Icon Color", "Color of the key field icon", GREY["800"], GREY["200"], "Color", void 0);
|
|
350
469
|
colors_icon.make_variable("add_icon", "Add Row Icon Color", "Color of the add row icon", GREY["800"], GREY["200"], "Color", void 0);
|
|
351
470
|
const colors_background = colors.make_sub_group("background", "Background Colors", "Background colors used in all list elements");
|
|
352
|
-
colors_background.make_variable("row_even", "Even Row Background Color", "Color of even row element backgrounds", GREY["
|
|
471
|
+
colors_background.make_variable("row_even", "Even Row Background Color", "Color of even row element backgrounds", GREY["200"], GREY["800"], "Color", void 0);
|
|
353
472
|
colors_background.make_variable("row_odd", "Odd Row Background Color", "Color of odd row element backgrounds", GREY["50"], GREY["900"], "Color", void 0);
|
|
354
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);
|
|
355
474
|
const colors_border = colors.make_sub_group("border", "Border Colors", "Border colors used in all list elements");
|
|
@@ -405,7 +524,7 @@ var HeaderField = class extends Base {
|
|
|
405
524
|
if (text) this.text = text;
|
|
406
525
|
}
|
|
407
526
|
set text(value) {
|
|
408
|
-
this.#text.
|
|
527
|
+
this.#text.textContent = value;
|
|
409
528
|
}
|
|
410
529
|
sizable(sizeable, sizer) {
|
|
411
530
|
if (sizeable) {
|
|
@@ -469,6 +588,7 @@ var Container = class extends Base {
|
|
|
469
588
|
#box = this.appendChild(document.createElement("div"));
|
|
470
589
|
#header;
|
|
471
590
|
#child_box;
|
|
591
|
+
#error;
|
|
472
592
|
#add_row;
|
|
473
593
|
#state_sub;
|
|
474
594
|
constructor(columns, transform, rows, options) {
|
|
@@ -478,7 +598,7 @@ var Container = class extends Base {
|
|
|
478
598
|
columns: /* @__PURE__ */ new Map(),
|
|
479
599
|
columns_visible: [],
|
|
480
600
|
transform,
|
|
481
|
-
observer: options?.observer
|
|
601
|
+
observer: options?.observer
|
|
482
602
|
};
|
|
483
603
|
this.#parent = {
|
|
484
604
|
depth: -1,
|
|
@@ -495,20 +615,26 @@ var Container = class extends Base {
|
|
|
495
615
|
}
|
|
496
616
|
set columns(columns) {
|
|
497
617
|
this.#root.columns.clear();
|
|
498
|
-
|
|
499
|
-
|
|
618
|
+
const order = /* @__PURE__ */ new Map();
|
|
619
|
+
let index = 0;
|
|
500
620
|
for (const key in columns) {
|
|
501
|
-
this.#root.columns.set(key, columns[key]);
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
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;
|
|
507
632
|
this.#update_column_widths();
|
|
508
633
|
});
|
|
509
|
-
|
|
634
|
+
return header;
|
|
635
|
+
});
|
|
510
636
|
this.#update_column_widths();
|
|
511
|
-
|
|
637
|
+
for (let i = 0; i < this.#child_box.childElementCount; i++) this.#child_box.children[i].columns_changed();
|
|
512
638
|
}
|
|
513
639
|
#update_column_widths() {
|
|
514
640
|
const widths = this.#root.columns_visible.map((key) => {
|
|
@@ -546,41 +672,15 @@ var Container = class extends Base {
|
|
|
546
672
|
if (this.#state_sub) this.detach_state(this.#state_sub);
|
|
547
673
|
this.#state_sub = void 0;
|
|
548
674
|
this.#parent.state = rows;
|
|
549
|
-
if (state$1.is.state(rows)) this.#state_sub = this.attach_state(rows, (r) => this.#update_rows(r.ok ? r.value : []));
|
|
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));
|
|
550
676
|
else this.#update_rows(rows);
|
|
551
677
|
}
|
|
552
|
-
#update_rows(rows) {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
for (let i = 0; i < read.length; i++) {
|
|
559
|
-
const row = read[i];
|
|
560
|
-
if (row.type === "fresh") {
|
|
561
|
-
const min = Math.min(this.#child_box.childElementCount, row.items.length);
|
|
562
|
-
for (let i = 0; i < min; i++) this.#child_box.children[i].data = row.items[i];
|
|
563
|
-
if (row.items.length > this.#child_box.childElementCount) this.#child_box.append(...row.items.slice(this.#child_box.childElementCount).map((row) => new ListRow(this.#root, this.#parent, row)));
|
|
564
|
-
else if (row.items.length < this.#child_box.childElementCount) for (let i = this.#child_box.childElementCount - 1; i >= row.items.length; i--) this.#child_box.children[i].remove();
|
|
565
|
-
} else if (row.type === "added") {
|
|
566
|
-
const child = this.#child_box.children[row.index];
|
|
567
|
-
const rows = row.items.map((row) => new ListRow(this.#root, this.#parent, row));
|
|
568
|
-
if (child) child.before(...rows);
|
|
569
|
-
else this.#child_box.append(...rows);
|
|
570
|
-
} else if (row.type === "removed") for (let i = 0; i < row.items.length; i++) this.#child_box.children[row.index].remove();
|
|
571
|
-
else if (row.type === "changed") for (let i = 0; i < row.items.length; i++) this.#child_box.children[row.index + i].data = row.items[i];
|
|
572
|
-
else if (row.type === "moved") {
|
|
573
|
-
const extracted = [];
|
|
574
|
-
for (let i = 0; i < row.items.length; i++) {
|
|
575
|
-
const child = this.#child_box.children[row.from_index + i];
|
|
576
|
-
extracted.push(child);
|
|
577
|
-
child.remove();
|
|
578
|
-
}
|
|
579
|
-
const child = this.#child_box.children[row.to_index];
|
|
580
|
-
for (let i = 0; i < extracted.length; i++) if (child) child.before(extracted[i]);
|
|
581
|
-
else this.#child_box.append(extracted[i]);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
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
|
+
});
|
|
584
684
|
}
|
|
585
685
|
};
|
|
586
686
|
define_element(Container);
|
|
@@ -593,9 +693,10 @@ function column(options) {
|
|
|
593
693
|
return options;
|
|
594
694
|
}
|
|
595
695
|
/**Special helper to create a string value column */
|
|
596
|
-
function column_string(title) {
|
|
696
|
+
function column_string(title, options) {
|
|
597
697
|
return {
|
|
598
698
|
title,
|
|
699
|
+
align: options?.align,
|
|
599
700
|
field_gen: () => list.text_field(),
|
|
600
701
|
field_apply: (field, value) => field.text = value
|
|
601
702
|
};
|
|
@@ -611,4 +712,4 @@ const list = {
|
|
|
611
712
|
};
|
|
612
713
|
export { ListField as n, list as t };
|
|
613
714
|
|
|
614
|
-
//# sourceMappingURL=list-
|
|
715
|
+
//# sourceMappingURL=list-DXkEJKjx.mjs.map
|