@chocbite/ts-lib-ui 1.0.6 → 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.
- package/AGENTS.md +164 -3
- package/SOURCE.md +2000 -268
- package/base/index.d.mts +1 -1
- package/base/index.mjs +7 -7
- package/base/index.mjs.map +1 -1
- package/canvas/index.d.mts +1 -1
- package/canvas/index.mjs +8 -8
- package/canvas/index.mjs.map +1 -1
- package/context-menu/index.d.mts +2 -2
- package/context-menu/index.mjs +1 -1
- package/{context-menu-Bo8R6DmK.mjs → context-menu-DE3EUtY8.mjs} +149 -111
- package/context-menu-DE3EUtY8.mjs.map +1 -0
- package/document/index.mjs +1 -1
- package/document/index.mjs.map +1 -1
- package/dom/index.mjs +1 -1
- package/dom/index.mjs.map +1 -1
- package/form/index.d.mts +6 -5
- package/form/index.mjs +30 -29
- 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 → icons-B88i-7MC.mjs} +2 -2
- package/{index-ClIBfrHy.d.mts → index-BDWg5GX2.d.mts} +2 -2
- package/{index-ClfL2SQR.d.mts → index-CvzH3M_5.d.mts} +2 -2
- package/index-Cw4AcuUl.d.mts +371 -0
- package/{index-Pr2sLv9e.d.mts → index-YNZjMIO7.d.mts} +33 -17
- package/keyboard/index.d.mts +1 -1
- package/keyboard/index.mjs +12 -12
- package/keyboard/index.mjs.map +1 -1
- package/list/index.d.mts +2 -2
- package/list/index.mjs +1 -1
- package/list-D08epOjk.mjs +1566 -0
- package/list-D08epOjk.mjs.map +1 -0
- package/package.json +5 -80
- package/selection/index.mjs +1 -1
- package/selection/index.mjs.map +1 -1
- package/settings/index.mjs +1 -1
- package/settings/index.mjs.map +1 -1
- package/spinner/index.d.mts +1 -1
- package/spinner/index.mjs +3 -3
- package/spinner/index.mjs.map +1 -1
- package/state_ui/index.mjs +1 -1
- package/{state_ui-Bm3TeKNL.mjs → state_ui-Dtm2y5RU.mjs} +3 -3
- package/state_ui-Dtm2y5RU.mjs.map +1 -0
- package/style.css +307 -63
- package/svg/index.d.mts +1 -1
- package/svg/index.mjs +1 -1
- package/{svg-1bp-yIPC.mjs → svg-Yz7elqnU.mjs} +16 -16
- package/svg-Yz7elqnU.mjs.map +1 -0
- package/test/index.d.mts +1 -1
- package/test/index.mjs +1 -1
- package/test/index.mjs.map +1 -1
- package/theme/index.d.mts +1 -1
- package/theme/index.mjs +1 -1
- package/{theme-DgVtLDzP.mjs → theme-BJS5z1iW.mjs} +9 -9
- package/theme-BJS5z1iW.mjs.map +1 -0
- package/context-menu-Bo8R6DmK.mjs.map +0 -1
- package/index-BTUFkF9s.d.mts +0 -173
- package/list-DOXIQOEY.mjs +0 -715
- package/list-DOXIQOEY.mjs.map +0 -1
- package/state_ui-Bm3TeKNL.mjs.map +0 -1
- package/svg-1bp-yIPC.mjs.map +0 -1
- package/theme-DgVtLDzP.mjs.map +0 -1
|
@@ -0,0 +1,1566 @@
|
|
|
1
|
+
import "./style.css";
|
|
2
|
+
import { Base, define_element } from "./base/index.mjs";
|
|
3
|
+
import { t as ctm } from "./context-menu-DE3EUtY8.mjs";
|
|
4
|
+
import { a as px_to_rem, i as theme_init_variable_root } from "./theme-BJS5z1iW.mjs";
|
|
5
|
+
import { t as state_ui } from "./state_ui-Dtm2y5RU.mjs";
|
|
6
|
+
import { state as state$1 } from "@chocbite/ts-lib/state";
|
|
7
|
+
import { none, some } from "@chocbite/ts-lib/result";
|
|
8
|
+
import { BLUE, GREY, ORANGE, RED } from "@chocbite/ts-lib/colors";
|
|
9
|
+
import { array_from_length } from "@chocbite/ts-lib/common";
|
|
10
|
+
// 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
|
+
#tail;
|
|
22
|
+
constructor(parent) {
|
|
23
|
+
super();
|
|
24
|
+
this.tabIndex = 0;
|
|
25
|
+
this.style.setProperty("--list-key-depth", String(parent.depth));
|
|
26
|
+
this.onkeydown = (e) => {
|
|
27
|
+
if (parent.key_down?.(e)) e.preventDefault();
|
|
28
|
+
else if (e.key === "Enter" || e.key === " ") parent.open = !parent.open;
|
|
29
|
+
else if (e.key === "ArrowRight") parent.open = true;
|
|
30
|
+
else if (e.key === "ArrowLeft") parent.open = false;
|
|
31
|
+
else if (e.key === "ArrowDown") parent.select_adjacent("next", none());
|
|
32
|
+
else if (e.key === "ArrowUp") parent.select_adjacent("previous", none());
|
|
33
|
+
else return;
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
};
|
|
36
|
+
const opener_box = document.createElement("span");
|
|
37
|
+
opener_box.className = "opener";
|
|
38
|
+
this.#opener = opener_box.appendChild(document.createElement("div"));
|
|
39
|
+
this.replaceChildren(...array_from_length(parent.depth, (i) => {
|
|
40
|
+
const div = document.createElement("div");
|
|
41
|
+
div.style.borderColor = "var(--i-" + i + ")";
|
|
42
|
+
return div;
|
|
43
|
+
}), opener_box);
|
|
44
|
+
this.#opener.addEventListener("click", (e) => {
|
|
45
|
+
e.stopPropagation();
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
parent.open = !parent.open;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
set options(options) {
|
|
51
|
+
if (state$1.is.state(options?.icon)) this.attach_state_to_prop("icon", options.icon, () => some(void 0));
|
|
52
|
+
else this.detach_state_from_prop("icon").icon = options?.icon;
|
|
53
|
+
if (state$1.is.state(options?.text)) this.attach_state_to_prop("text", options.text, (e) => some(e));
|
|
54
|
+
else this.detach_state_from_prop("text").text = options?.text;
|
|
55
|
+
}
|
|
56
|
+
set icon(value) {
|
|
57
|
+
if (this.#icon) this.#icon.remove();
|
|
58
|
+
this.#icon = void 0;
|
|
59
|
+
this.classList.toggle("has-icon", Boolean(value));
|
|
60
|
+
if (!value) return;
|
|
61
|
+
this.#icon = value();
|
|
62
|
+
this.insertBefore(this.#icon, this.#text_box ?? this.#tail ?? null);
|
|
63
|
+
}
|
|
64
|
+
/**Element filling the rest of the key field, the button of an add row or the text of an error
|
|
65
|
+
* A key field with a tail spans from the key column to the end of the row, so it works without value columns */
|
|
66
|
+
set tail(value) {
|
|
67
|
+
if (value === this.#tail) return;
|
|
68
|
+
this.#tail?.remove();
|
|
69
|
+
this.#tail = value;
|
|
70
|
+
this.classList.toggle("tail", Boolean(value));
|
|
71
|
+
if (value) this.appendChild(value);
|
|
72
|
+
}
|
|
73
|
+
get tail() {
|
|
74
|
+
return this.#tail;
|
|
75
|
+
}
|
|
76
|
+
/**Text after the icon, an empty string removes the text element */
|
|
77
|
+
set text(value) {
|
|
78
|
+
this.classList.toggle("has-text", Boolean(value));
|
|
79
|
+
if (!value) {
|
|
80
|
+
this.#text_box?.remove();
|
|
81
|
+
this.#text_box = void 0;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (!this.#text_box) {
|
|
85
|
+
this.#text_box = document.createElement("span");
|
|
86
|
+
this.#text_box.className = "text";
|
|
87
|
+
this.insertBefore(this.#text_box, this.#tail ?? null);
|
|
88
|
+
}
|
|
89
|
+
this.#text_box.textContent = value;
|
|
90
|
+
}
|
|
91
|
+
set openable(value) {
|
|
92
|
+
if (value) this.classList.add("openable");
|
|
93
|
+
else this.classList.remove("openable");
|
|
94
|
+
}
|
|
95
|
+
get openable() {
|
|
96
|
+
return this.classList.contains("openable");
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
define_element(ListKeyField);
|
|
100
|
+
// list/add_row.ts
|
|
101
|
+
var ListAddRow = class extends Base {
|
|
102
|
+
static element_name() {
|
|
103
|
+
return "addrow";
|
|
104
|
+
}
|
|
105
|
+
static element_name_space() {
|
|
106
|
+
return "list";
|
|
107
|
+
}
|
|
108
|
+
#button;
|
|
109
|
+
#text;
|
|
110
|
+
#icon;
|
|
111
|
+
#parent;
|
|
112
|
+
depth;
|
|
113
|
+
constructor(root, parent) {
|
|
114
|
+
super();
|
|
115
|
+
this.#parent = parent;
|
|
116
|
+
this.depth = parent.depth + 1;
|
|
117
|
+
this.#button = document.createElement("span");
|
|
118
|
+
this.#button.className = "add";
|
|
119
|
+
this.#button.tabIndex = 0;
|
|
120
|
+
if (root.sub_rows) this.appendChild(new ListKeyField(this)).tail = this.#button;
|
|
121
|
+
else this.appendChild(this.#button);
|
|
122
|
+
this.#text = this.#button.appendChild(document.createTextNode(""));
|
|
123
|
+
}
|
|
124
|
+
set options(options) {
|
|
125
|
+
this.#button.onclick = options.on_add;
|
|
126
|
+
if (state$1.is.state(options.text)) this.attach_state_to_prop("text", options.text, (e) => some(e));
|
|
127
|
+
else this.detach_state_from_prop("text").text = options.text;
|
|
128
|
+
if (state$1.is.state(options.disabled)) this.attach_state_to_prop("disabled", options.disabled, () => some(false));
|
|
129
|
+
else this.detach_state_from_prop("disabled").disabled = Boolean(options.disabled);
|
|
130
|
+
if (state$1.is.state(options.icon)) this.attach_state_to_prop("icon", options.icon, () => some(void 0));
|
|
131
|
+
else this.detach_state_from_prop("icon").icon = options.icon;
|
|
132
|
+
}
|
|
133
|
+
set text(value) {
|
|
134
|
+
this.#text.data = value;
|
|
135
|
+
}
|
|
136
|
+
set icon(value) {
|
|
137
|
+
this.#icon?.remove();
|
|
138
|
+
this.#icon = value ? this.#button.insertBefore(value(), this.#text) : void 0;
|
|
139
|
+
}
|
|
140
|
+
set disabled(value) {
|
|
141
|
+
if (value) this.inert = true;
|
|
142
|
+
else this.inert = false;
|
|
143
|
+
}
|
|
144
|
+
set open(_value) {}
|
|
145
|
+
get open() {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
set global_index(_value) {}
|
|
149
|
+
get global_index() {
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
/**Rows the add row adds to, the state of its parent */
|
|
153
|
+
set state(_value) {}
|
|
154
|
+
get state() {
|
|
155
|
+
return this.#parent.state;
|
|
156
|
+
}
|
|
157
|
+
get global_amount() {
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
select_adjacent() {}
|
|
161
|
+
};
|
|
162
|
+
define_element(ListAddRow);
|
|
163
|
+
// list/drag.ts
|
|
164
|
+
/**Lists that rows can be dragged between, rows are given from one list to another of the same group
|
|
165
|
+
* The type is checked both ways, so only lists with exactly the same row type can join */
|
|
166
|
+
var ListDragGroup = class {};
|
|
167
|
+
/**Drag handle cell in front of a row, empty in the header */
|
|
168
|
+
var ListDragField = class extends Base {
|
|
169
|
+
static element_name() {
|
|
170
|
+
return "dragfield";
|
|
171
|
+
}
|
|
172
|
+
static element_name_space() {
|
|
173
|
+
return "list";
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
define_element(ListDragField);
|
|
177
|
+
/**Pixels the pointer moves before a press on the handle becomes a drag */
|
|
178
|
+
const DRAG_THRESHOLD = 5;
|
|
179
|
+
/**Milliseconds hovering into a closed row before it opens */
|
|
180
|
+
const OPEN_DELAY = 600;
|
|
181
|
+
/**Thickness of the drop line in pixels, it is drawn inside the row it is about */
|
|
182
|
+
const LINE_WIDTH = 5;
|
|
183
|
+
/**Distance from the top or bottom edge of a list in pixels where dragging scrolls it */
|
|
184
|
+
const SCROLL_EDGE = 32;
|
|
185
|
+
/**A rows state that the list can write moves to */
|
|
186
|
+
function writable(rows) {
|
|
187
|
+
return state$1.is.state(rows) && rows.writable;
|
|
188
|
+
}
|
|
189
|
+
/**Moving rows of a list by dragging their handle or with alt and the arrow keys
|
|
190
|
+
* Like the selection, moves are only written to the rows states, the rows move when the states give the change back */
|
|
191
|
+
var ListReorder = class {
|
|
192
|
+
group;
|
|
193
|
+
container;
|
|
194
|
+
#options;
|
|
195
|
+
#warn;
|
|
196
|
+
/**Shows where rows are dropped in this list */
|
|
197
|
+
#indicator;
|
|
198
|
+
constructor(container, options, warn) {
|
|
199
|
+
this.container = container;
|
|
200
|
+
this.group = options.group ?? new ListDragGroup();
|
|
201
|
+
this.#options = options;
|
|
202
|
+
this.#warn = warn;
|
|
203
|
+
this.#indicator = container.appendChild(document.createElement("span"));
|
|
204
|
+
this.#indicator.className = "list-drop";
|
|
205
|
+
this.#indicator.hidden = true;
|
|
206
|
+
}
|
|
207
|
+
/**Makes the handle cell of a row */
|
|
208
|
+
handle(row) {
|
|
209
|
+
const handle = new ListDragField();
|
|
210
|
+
handle.onpointerdown = (e) => this.#press(row, handle, e);
|
|
211
|
+
return handle;
|
|
212
|
+
}
|
|
213
|
+
#press(row, handle, e) {
|
|
214
|
+
if (e.button !== 0 || !row.movable) return;
|
|
215
|
+
e.preventDefault();
|
|
216
|
+
handle.setPointerCapture(e.pointerId);
|
|
217
|
+
const start_x = e.clientX;
|
|
218
|
+
const start_y = e.clientY;
|
|
219
|
+
let x = start_x;
|
|
220
|
+
let y = start_y;
|
|
221
|
+
let rows;
|
|
222
|
+
let place;
|
|
223
|
+
let shown;
|
|
224
|
+
let frame = 0;
|
|
225
|
+
let open_timer = 0;
|
|
226
|
+
let open_row;
|
|
227
|
+
const label = document.createElement("span");
|
|
228
|
+
label.className = "list-drag-label";
|
|
229
|
+
const update = () => {
|
|
230
|
+
frame = requestAnimationFrame(update);
|
|
231
|
+
this.#scroll(x, y);
|
|
232
|
+
const next = this.#place(x, y, rows);
|
|
233
|
+
shown?.indicate(void 0);
|
|
234
|
+
shown = next?.row.reorder;
|
|
235
|
+
shown?.indicate(next);
|
|
236
|
+
place = next;
|
|
237
|
+
label.style.left = x + 12 + "px";
|
|
238
|
+
label.style.top = y + 12 + "px";
|
|
239
|
+
label.classList.toggle("none", !next);
|
|
240
|
+
const hover = next?.mode === "into" && !next.row.open ? next.row : void 0;
|
|
241
|
+
if (hover !== open_row) {
|
|
242
|
+
clearTimeout(open_timer);
|
|
243
|
+
open_row = hover;
|
|
244
|
+
if (hover) open_timer = window.setTimeout(() => hover.open = true, OPEN_DELAY);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
const end = (drop) => {
|
|
248
|
+
handle.onpointermove = null;
|
|
249
|
+
handle.onpointerup = null;
|
|
250
|
+
handle.onpointercancel = null;
|
|
251
|
+
handle.onlostpointercapture = null;
|
|
252
|
+
document.removeEventListener("keydown", escape, true);
|
|
253
|
+
cancelAnimationFrame(frame);
|
|
254
|
+
clearTimeout(open_timer);
|
|
255
|
+
shown?.indicate(void 0);
|
|
256
|
+
label.remove();
|
|
257
|
+
if (!rows) return;
|
|
258
|
+
for (const dragged of rows) dragged.classList.remove("dragging");
|
|
259
|
+
if (drop && place) this.#drop(rows, place);
|
|
260
|
+
};
|
|
261
|
+
const escape = (ev) => {
|
|
262
|
+
if (ev.key !== "Escape") return;
|
|
263
|
+
ev.preventDefault();
|
|
264
|
+
ev.stopPropagation();
|
|
265
|
+
end(false);
|
|
266
|
+
};
|
|
267
|
+
handle.onpointermove = (ev) => {
|
|
268
|
+
x = ev.clientX;
|
|
269
|
+
y = ev.clientY;
|
|
270
|
+
if (rows) return;
|
|
271
|
+
if (Math.hypot(x - start_x, y - start_y) < DRAG_THRESHOLD) return;
|
|
272
|
+
rows = this.#dragged(row);
|
|
273
|
+
for (const dragged of rows) dragged.classList.add("dragging");
|
|
274
|
+
label.textContent = rows.length > 1 ? rows.length + " rows" : row.label || "1 row";
|
|
275
|
+
document.body.appendChild(label);
|
|
276
|
+
document.addEventListener("keydown", escape, true);
|
|
277
|
+
update();
|
|
278
|
+
};
|
|
279
|
+
handle.onpointerup = () => end(true);
|
|
280
|
+
handle.onpointercancel = () => end(false);
|
|
281
|
+
handle.onlostpointercapture = () => end(false);
|
|
282
|
+
}
|
|
283
|
+
/**Rows a drag from the row moves, the visible selected movable rows when the row is selected in multi mode
|
|
284
|
+
* Sub rows of a dragged row move with it, so they are left out */
|
|
285
|
+
#dragged(row) {
|
|
286
|
+
if (!row.selected || !row.multi_selected) return [row];
|
|
287
|
+
const rows = [...this.container.querySelectorAll("list-row.selected.movable")].filter((selected) => selected.reorder === this);
|
|
288
|
+
const dragged = new Set(rows);
|
|
289
|
+
return rows.filter((selected) => {
|
|
290
|
+
for (let parent = selected.parent_row; parent; parent = parent.parent_row) if (dragged.has(parent)) return false;
|
|
291
|
+
return true;
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
/**Scrolls the list under the pointer when the pointer is near its top or bottom edge */
|
|
295
|
+
#scroll(x, y) {
|
|
296
|
+
const target = document.elementFromPoint(x, y)?.closest("list-container") ?? this.container;
|
|
297
|
+
const rect = target.getBoundingClientRect();
|
|
298
|
+
if (x < rect.left || x > rect.right) return;
|
|
299
|
+
if (y < rect.top + SCROLL_EDGE) target.scrollTop -= Math.ceil((rect.top + SCROLL_EDGE - y) / 4);
|
|
300
|
+
else if (y > rect.bottom - SCROLL_EDGE) target.scrollTop += Math.ceil((y - rect.bottom + SCROLL_EDGE) / 4);
|
|
301
|
+
}
|
|
302
|
+
/**The place under the pointer, undefined when the rows can not be dropped there */
|
|
303
|
+
#place(x, y, rows) {
|
|
304
|
+
const element = document.elementFromPoint(x, y);
|
|
305
|
+
let row = element?.closest("list-row") ?? void 0;
|
|
306
|
+
let mode;
|
|
307
|
+
if (!row) {
|
|
308
|
+
const last = (element?.closest("list-container"))?.querySelector(":scope > div > div > list-row:last-child");
|
|
309
|
+
if (!last?.anchor || y < last.anchor.getBoundingClientRect().bottom) return void 0;
|
|
310
|
+
row = last;
|
|
311
|
+
mode = "after";
|
|
312
|
+
} else {
|
|
313
|
+
const rect = row.anchor?.getBoundingClientRect();
|
|
314
|
+
if (!rect) return void 0;
|
|
315
|
+
const part = (y - rect.top) / rect.height;
|
|
316
|
+
if (row.openable) mode = part < .25 ? "before" : part > .75 ? "after" : "into";
|
|
317
|
+
else mode = part < .5 ? "before" : "after";
|
|
318
|
+
}
|
|
319
|
+
const reorder = row.reorder;
|
|
320
|
+
if (reorder?.group !== this.group) return void 0;
|
|
321
|
+
if (mode === "after" && row.open) {
|
|
322
|
+
const first = row.first_sub_row;
|
|
323
|
+
if (first) {
|
|
324
|
+
row = first;
|
|
325
|
+
mode = "before";
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const place = {
|
|
329
|
+
row,
|
|
330
|
+
mode
|
|
331
|
+
};
|
|
332
|
+
return reorder.#allowed(place, rows) ? place : void 0;
|
|
333
|
+
}
|
|
334
|
+
/**Whether the rows can be dropped at the place of this list */
|
|
335
|
+
#allowed(place, rows) {
|
|
336
|
+
const parent = place.mode === "into" ? place.row : place.row.parent_row;
|
|
337
|
+
if (place.mode !== "into" && rows.includes(place.row)) return false;
|
|
338
|
+
for (let up = parent; up; up = up.parent_row) if (rows.includes(up)) return false;
|
|
339
|
+
if (place.mode === "into" ? !place.row.droppable : !place.row.movable) return false;
|
|
340
|
+
const options = this.#options;
|
|
341
|
+
if (!options.can_drop) return true;
|
|
342
|
+
const target = {
|
|
343
|
+
parent: parent?.data,
|
|
344
|
+
list: this.container
|
|
345
|
+
};
|
|
346
|
+
return rows.every((row) => options.can_drop(row.data, target));
|
|
347
|
+
}
|
|
348
|
+
/**Shows where rows are dropped in this list, undefined hides it */
|
|
349
|
+
indicate(place) {
|
|
350
|
+
const indicator = this.#indicator;
|
|
351
|
+
const cell = place?.row.anchor;
|
|
352
|
+
if (!place || !cell) {
|
|
353
|
+
indicator.hidden = true;
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const list = this.container;
|
|
357
|
+
const box = list.getBoundingClientRect();
|
|
358
|
+
const rect = cell.getBoundingClientRect();
|
|
359
|
+
const top = rect.top - box.top + list.scrollTop;
|
|
360
|
+
const left = ((place.mode === "into" ? void 0 : place.row.querySelector(":scope > div > list-keyfield > span:not(.text)")) ?? cell).getBoundingClientRect().left - box.left + list.scrollLeft;
|
|
361
|
+
const right = (list.querySelector(":scope > div") ?? list).getBoundingClientRect().right - box.left + list.scrollLeft;
|
|
362
|
+
indicator.hidden = false;
|
|
363
|
+
indicator.className = "list-drop " + place.mode;
|
|
364
|
+
indicator.style.left = left + "px";
|
|
365
|
+
indicator.style.width = Math.max(Math.floor(right - left), 0) + "px";
|
|
366
|
+
indicator.style.top = (place.mode === "after" ? top + rect.height - LINE_WIDTH : top) + "px";
|
|
367
|
+
indicator.style.height = (place.mode === "into" ? rect.height : LINE_WIDTH) + "px";
|
|
368
|
+
}
|
|
369
|
+
/**Writes the moves of the rows to the place, rows next to each other in one parent move with one write
|
|
370
|
+
* Moving to another parent inserts first and removes after, so a failure can leave a row twice but never loses it */
|
|
371
|
+
async #drop(rows, place) {
|
|
372
|
+
const errors = [];
|
|
373
|
+
const into = place.mode === "into" ? place.row : void 0;
|
|
374
|
+
const before = place.mode === "before" ? place.row : place.mode === "after" ? place.row.next_row : void 0;
|
|
375
|
+
const target_box = place.mode === "into" ? void 0 : place.row.parentElement;
|
|
376
|
+
const target_rows = into ? into.drop_rows() : place.row.parent_rows;
|
|
377
|
+
if (!writable(target_rows)) return;
|
|
378
|
+
for (const chunk of this.#chunks(rows)) {
|
|
379
|
+
const first = chunk[0];
|
|
380
|
+
const source_box = first.parentElement;
|
|
381
|
+
if (into ? first.parent_row === into : source_box === target_box) {
|
|
382
|
+
const from = first.index;
|
|
383
|
+
const end = before ? before.index : source_box.childElementCount;
|
|
384
|
+
const to = from < end ? end - chunk.length : end;
|
|
385
|
+
if (from === to) continue;
|
|
386
|
+
const result = await target_rows.write(state$1.a.write.move(from, to, chunk.length));
|
|
387
|
+
if (result.err) errors.push(result.error);
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
const items = chunk.map((row) => row.data);
|
|
391
|
+
const inserted = await target_rows.write(before ? state$1.a.write.splice(before.index, 0, ...items) : state$1.a.write.push(...items));
|
|
392
|
+
if (inserted.err) {
|
|
393
|
+
errors.push(inserted.error);
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (this.#options.no_remove || !first.parentElement) continue;
|
|
397
|
+
const source_rows = first.parent_rows;
|
|
398
|
+
if (!writable(source_rows)) continue;
|
|
399
|
+
const removed = await source_rows.write(state$1.a.write.splice(first.index, chunk.length));
|
|
400
|
+
if (removed.err) errors.push(removed.error);
|
|
401
|
+
}
|
|
402
|
+
if (into && errors.length === 0) into.open = true;
|
|
403
|
+
if (errors.length) place.row.reorder?.warn(place.row, [...new Set(errors)].join("\n"));
|
|
404
|
+
}
|
|
405
|
+
/**Splits rows in display order into runs of rows next to each other in one parent */
|
|
406
|
+
#chunks(rows) {
|
|
407
|
+
const chunks = [];
|
|
408
|
+
for (const row of rows) {
|
|
409
|
+
const last = chunks[chunks.length - 1]?.at(-1);
|
|
410
|
+
if (last && last.parentElement === row.parentElement && last.next_row === row) chunks[chunks.length - 1].push(row);
|
|
411
|
+
else chunks.push([row]);
|
|
412
|
+
}
|
|
413
|
+
return chunks;
|
|
414
|
+
}
|
|
415
|
+
/**Shows why a move failed at the row, in the list of the row */
|
|
416
|
+
warn(row, message) {
|
|
417
|
+
this.#warn.show(row.anchor, message);
|
|
418
|
+
}
|
|
419
|
+
/**Moves the row one place up or down in its parent, from the keyboard, the row keeps the focus */
|
|
420
|
+
async key_move(row, direction) {
|
|
421
|
+
const rows = row.parent_rows;
|
|
422
|
+
if (!row.movable || !writable(rows)) return;
|
|
423
|
+
const from = row.index;
|
|
424
|
+
const to = from + direction;
|
|
425
|
+
if (to < 0 || to >= row.parentElement.childElementCount) return;
|
|
426
|
+
const result = await rows.write(state$1.a.write.move(from, to, 1));
|
|
427
|
+
row.focus_cell();
|
|
428
|
+
if (result.err) this.warn(row, result.error);
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
// list/error.ts
|
|
432
|
+
/**Error text shown instead of the fields of an invalid row */
|
|
433
|
+
var ListError = class extends Base {
|
|
434
|
+
static element_name() {
|
|
435
|
+
return "error";
|
|
436
|
+
}
|
|
437
|
+
static element_name_space() {
|
|
438
|
+
return "list";
|
|
439
|
+
}
|
|
440
|
+
set text(value) {
|
|
441
|
+
this.textContent = value;
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
define_element(ListError);
|
|
445
|
+
/**Error text shown instead of the rows of a parent, has a key field to continue the tree lines like an add row */
|
|
446
|
+
var ListRowsError = class extends Base {
|
|
447
|
+
static element_name() {
|
|
448
|
+
return "rowserror";
|
|
449
|
+
}
|
|
450
|
+
static element_name_space() {
|
|
451
|
+
return "list";
|
|
452
|
+
}
|
|
453
|
+
#text = new ListError();
|
|
454
|
+
#parent;
|
|
455
|
+
depth;
|
|
456
|
+
constructor(sub_rows, parent) {
|
|
457
|
+
super();
|
|
458
|
+
this.#parent = parent;
|
|
459
|
+
this.depth = parent.depth + 1;
|
|
460
|
+
if (sub_rows) this.appendChild(new ListKeyField(this)).tail = this.#text;
|
|
461
|
+
else this.appendChild(this.#text);
|
|
462
|
+
}
|
|
463
|
+
set text(value) {
|
|
464
|
+
this.#text.text = value;
|
|
465
|
+
}
|
|
466
|
+
set open(_value) {}
|
|
467
|
+
get open() {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
/**Rows the error is shown for, the state of its parent */
|
|
471
|
+
set state(_value) {}
|
|
472
|
+
get state() {
|
|
473
|
+
return this.#parent.state;
|
|
474
|
+
}
|
|
475
|
+
select_adjacent() {}
|
|
476
|
+
};
|
|
477
|
+
define_element(ListRowsError);
|
|
478
|
+
/**Shows the text in an error element directly after the row box, removes the element when there is no text
|
|
479
|
+
* @returns the element to give next time, undefined when there is no text*/
|
|
480
|
+
function list_rows_error_update(row_box, current, text, sub_rows, parent) {
|
|
481
|
+
if (text === void 0) {
|
|
482
|
+
current?.remove();
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (!current) {
|
|
486
|
+
current = new ListRowsError(sub_rows, parent);
|
|
487
|
+
row_box.after(current);
|
|
488
|
+
}
|
|
489
|
+
current.text = text;
|
|
490
|
+
return current;
|
|
491
|
+
}
|
|
492
|
+
// list/field.ts
|
|
493
|
+
/**Adds the class for the alignment, center is the default and adds nothing
|
|
494
|
+
* Only the styling of an element decides if the class does anything, so complex fields just do not follow it */
|
|
495
|
+
function list_align_apply(element, align) {
|
|
496
|
+
if (align === "left" || align === "right") element.classList.add("align-" + align);
|
|
497
|
+
}
|
|
498
|
+
var ListField = class extends Base {
|
|
499
|
+
static element_name() {
|
|
500
|
+
return "@abstract@";
|
|
501
|
+
}
|
|
502
|
+
static element_name_space() {
|
|
503
|
+
return "list";
|
|
504
|
+
}
|
|
505
|
+
constructor() {
|
|
506
|
+
super();
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
var ListTextField = class extends ListField {
|
|
510
|
+
static element_name() {
|
|
511
|
+
return "textfield";
|
|
512
|
+
}
|
|
513
|
+
set text(value) {
|
|
514
|
+
this.textContent = value;
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
define_element(ListTextField);
|
|
518
|
+
function text_field() {
|
|
519
|
+
return new ListTextField();
|
|
520
|
+
}
|
|
521
|
+
var ListNumberField = class extends ListField {
|
|
522
|
+
static element_name() {
|
|
523
|
+
return "numberfield";
|
|
524
|
+
}
|
|
525
|
+
set number(value) {
|
|
526
|
+
this.textContent = value.toString();
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
define_element(ListNumberField);
|
|
530
|
+
function number_field() {
|
|
531
|
+
return new ListNumberField();
|
|
532
|
+
}
|
|
533
|
+
var ListNodeField = class extends ListField {
|
|
534
|
+
static element_name() {
|
|
535
|
+
return "nodefield";
|
|
536
|
+
}
|
|
537
|
+
constructor(node) {
|
|
538
|
+
super();
|
|
539
|
+
this.appendChild(node);
|
|
540
|
+
}
|
|
541
|
+
set node(node) {
|
|
542
|
+
this.replaceChildren(node);
|
|
543
|
+
}
|
|
544
|
+
get node() {
|
|
545
|
+
return this.firstChild;
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
define_element(ListNodeField);
|
|
549
|
+
function node_field(node) {
|
|
550
|
+
return new ListNodeField(node);
|
|
551
|
+
}
|
|
552
|
+
// list/selection.ts
|
|
553
|
+
/**Selection of the rows of a list, kept in an array state of keys owned by the app
|
|
554
|
+
* The list shows the keys of the state that have a visible row, and writes the state only on user actions,
|
|
555
|
+
* keys of rows it does not show are left alone, except by select all and deselect all which replace the selection */
|
|
556
|
+
var ListSelection = class {
|
|
557
|
+
multi;
|
|
558
|
+
key;
|
|
559
|
+
/**Called after a change of the shown selection or of the selectable rows */
|
|
560
|
+
on_change;
|
|
561
|
+
/**Called when the state rejects a write, with the row the user acted on */
|
|
562
|
+
on_error;
|
|
563
|
+
/**State user actions are written to */
|
|
564
|
+
target;
|
|
565
|
+
/**Element holding all rows of the list, sub rows included, in display order */
|
|
566
|
+
#box;
|
|
567
|
+
#rows = /* @__PURE__ */ new Map();
|
|
568
|
+
/**Mirror of the state array, the removed and changed entries of an update only give positions or new items */
|
|
569
|
+
#keys = [];
|
|
570
|
+
/**How often each key is in the state, a key that is in it twice stays selected when one is removed */
|
|
571
|
+
#counts = /* @__PURE__ */ new Map();
|
|
572
|
+
/**Amount of visible rows that are selected */
|
|
573
|
+
#shown = 0;
|
|
574
|
+
#anchor;
|
|
575
|
+
#batch = 0;
|
|
576
|
+
#changed = false;
|
|
577
|
+
constructor(options, box) {
|
|
578
|
+
this.multi = options.mode === "multi";
|
|
579
|
+
this.key = options.key ?? ((data) => data);
|
|
580
|
+
this.#box = box;
|
|
581
|
+
}
|
|
582
|
+
/**Runs the function with the change notification delayed until all nested batches are done */
|
|
583
|
+
batch(func) {
|
|
584
|
+
this.#batch++;
|
|
585
|
+
try {
|
|
586
|
+
return func();
|
|
587
|
+
} finally {
|
|
588
|
+
if (--this.#batch === 0 && this.#changed) {
|
|
589
|
+
this.#changed = false;
|
|
590
|
+
this.on_change?.();
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
/**Applies a value of the state, only the changed keys are touched when the value carries its changes */
|
|
595
|
+
apply(value) {
|
|
596
|
+
this.batch(() => {
|
|
597
|
+
if (!value.ok) {
|
|
598
|
+
this.#fresh([]);
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
for (const change of state$1.a.read(value.value)) if (change.type === "fresh") this.#fresh(change.items);
|
|
602
|
+
else if (change.type === "added") {
|
|
603
|
+
this.#keys.splice(change.index, 0, ...change.items);
|
|
604
|
+
for (const key of change.items) this.#add(key);
|
|
605
|
+
} else if (change.type === "removed") for (const key of this.#keys.splice(change.index, change.items.length)) this.#remove(key);
|
|
606
|
+
else if (change.type === "changed") change.items.forEach((key, i) => {
|
|
607
|
+
const old = this.#keys[change.index + i];
|
|
608
|
+
this.#keys[change.index + i] = key;
|
|
609
|
+
this.#remove(old);
|
|
610
|
+
this.#add(key);
|
|
611
|
+
});
|
|
612
|
+
else {
|
|
613
|
+
const moved = this.#keys.splice(change.from_index, change.items.length);
|
|
614
|
+
this.#keys.splice(change.to_index, 0, ...moved);
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
#fresh(keys) {
|
|
619
|
+
const old = this.#counts;
|
|
620
|
+
this.#keys = [...keys];
|
|
621
|
+
this.#counts = /* @__PURE__ */ new Map();
|
|
622
|
+
for (const key of keys) this.#counts.set(key, (this.#counts.get(key) ?? 0) + 1);
|
|
623
|
+
for (const key of old.keys()) if (!this.#counts.has(key)) this.#show(key, false);
|
|
624
|
+
for (const key of this.#counts.keys()) if (!old.has(key)) this.#show(key, true);
|
|
625
|
+
}
|
|
626
|
+
#add(key) {
|
|
627
|
+
const count = this.#counts.get(key) ?? 0;
|
|
628
|
+
this.#counts.set(key, count + 1);
|
|
629
|
+
if (count === 0) this.#show(key, true);
|
|
630
|
+
}
|
|
631
|
+
#remove(key) {
|
|
632
|
+
const count = this.#counts.get(key);
|
|
633
|
+
if (!count) return;
|
|
634
|
+
if (count > 1) this.#counts.set(key, count - 1);
|
|
635
|
+
else {
|
|
636
|
+
this.#counts.delete(key);
|
|
637
|
+
this.#show(key, false);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
#show(key, selected) {
|
|
641
|
+
const row = this.#rows.get(key);
|
|
642
|
+
if (!row) return;
|
|
643
|
+
row.selected = selected;
|
|
644
|
+
this.#shown += selected ? 1 : -1;
|
|
645
|
+
this.#changed = true;
|
|
646
|
+
}
|
|
647
|
+
/**Writes the state, a rejected write is reported at the row of the key the user acted on */
|
|
648
|
+
#write(value, key) {
|
|
649
|
+
const write = this.target?.write(value);
|
|
650
|
+
if (!write) return;
|
|
651
|
+
const row = key === void 0 ? void 0 : this.#rows.get(key);
|
|
652
|
+
write.then((result) => {
|
|
653
|
+
if (result.err) this.on_error?.(row, result.error);
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
/**Adds a visible row that can be selected, it shows whether its key is in the state */
|
|
657
|
+
register(key, row) {
|
|
658
|
+
this.#rows.set(key, row);
|
|
659
|
+
row.selected = this.#counts.has(key);
|
|
660
|
+
if (row.selected) this.#shown++;
|
|
661
|
+
this.#changed = true;
|
|
662
|
+
}
|
|
663
|
+
/**Removes a row that is no longer visible or selectable, the state keeps its key */
|
|
664
|
+
unregister(key, row) {
|
|
665
|
+
if (this.#rows.get(key) === row) {
|
|
666
|
+
this.#rows.delete(key);
|
|
667
|
+
if (this.#counts.has(key)) this.#shown--;
|
|
668
|
+
}
|
|
669
|
+
row.selected = false;
|
|
670
|
+
this.#changed = true;
|
|
671
|
+
}
|
|
672
|
+
/**Amount of visible rows that can be selected */
|
|
673
|
+
get amount_selectable() {
|
|
674
|
+
return this.#rows.size;
|
|
675
|
+
}
|
|
676
|
+
/**Amount of visible rows that are selected */
|
|
677
|
+
get amount_selected() {
|
|
678
|
+
return this.#shown;
|
|
679
|
+
}
|
|
680
|
+
is_selected(key) {
|
|
681
|
+
return this.#counts.has(key);
|
|
682
|
+
}
|
|
683
|
+
/**Keys of the selectable rows from one row to another in display order, both included */
|
|
684
|
+
#range(from, to) {
|
|
685
|
+
const keys = [];
|
|
686
|
+
let inside = false;
|
|
687
|
+
const rows = this.#box.querySelectorAll("list-row");
|
|
688
|
+
const from_row = this.#rows.get(from);
|
|
689
|
+
const to_row = this.#rows.get(to);
|
|
690
|
+
for (let i = 0; i < rows.length; i++) {
|
|
691
|
+
const row = rows[i];
|
|
692
|
+
const edge = row === from_row || row === to_row;
|
|
693
|
+
if (edge || inside) {
|
|
694
|
+
const key = row.selection_key;
|
|
695
|
+
if (key !== void 0 && this.#rows.get(key) === row) keys.push(key);
|
|
696
|
+
}
|
|
697
|
+
if (edge) {
|
|
698
|
+
if (inside || from_row === to_row) break;
|
|
699
|
+
inside = true;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return keys;
|
|
703
|
+
}
|
|
704
|
+
#select_range(to, add) {
|
|
705
|
+
if (!this.#rows.has(to)) return;
|
|
706
|
+
const anchor = this.#anchor !== void 0 && this.#rows.has(this.#anchor) ? this.#anchor : to;
|
|
707
|
+
const keys = this.#range(anchor, to);
|
|
708
|
+
this.#anchor = anchor;
|
|
709
|
+
if (!add) return this.#write(state$1.a.write.fresh(keys), to);
|
|
710
|
+
const added = keys.filter((key) => !this.#counts.has(key));
|
|
711
|
+
if (added.length) this.#write(state$1.a.write.push(...added), to);
|
|
712
|
+
}
|
|
713
|
+
/**Replaces the selection with only the row */
|
|
714
|
+
select_only(key) {
|
|
715
|
+
if (!this.#rows.has(key)) return;
|
|
716
|
+
this.#anchor = key;
|
|
717
|
+
if (this.#keys.length === 1 && this.#keys[0] === key) return;
|
|
718
|
+
this.#write(state$1.a.write.fresh([key]), key);
|
|
719
|
+
}
|
|
720
|
+
/**Adds the row to the selection, in single mode it replaces the selection */
|
|
721
|
+
select(key) {
|
|
722
|
+
if (!this.multi) return this.select_only(key);
|
|
723
|
+
if (!this.#rows.has(key)) return;
|
|
724
|
+
this.#anchor = key;
|
|
725
|
+
if (!this.#counts.has(key)) this.#write(state$1.a.write.push(key), key);
|
|
726
|
+
}
|
|
727
|
+
/**Removes the row from the selection */
|
|
728
|
+
deselect(key) {
|
|
729
|
+
if (this.#counts.has(key)) this.#write(state$1.a.write.delete(key), key);
|
|
730
|
+
}
|
|
731
|
+
/**Toggles the row, in single mode selecting replaces the selection */
|
|
732
|
+
toggle(key) {
|
|
733
|
+
if (!this.#rows.has(key)) return;
|
|
734
|
+
if (this.#counts.has(key)) {
|
|
735
|
+
this.#anchor = key;
|
|
736
|
+
this.deselect(key);
|
|
737
|
+
} else this.select(key);
|
|
738
|
+
}
|
|
739
|
+
/**Replaces the selection with all visible selectable rows, multi mode only */
|
|
740
|
+
select_all() {
|
|
741
|
+
if (this.multi) this.#write(state$1.a.write.fresh([...this.#rows.keys()]));
|
|
742
|
+
}
|
|
743
|
+
/**Clears the selection, also of keys without a visible row */
|
|
744
|
+
clear() {
|
|
745
|
+
if (this.#keys.length) this.#write(state$1.a.write.fresh([]));
|
|
746
|
+
}
|
|
747
|
+
/**Click on the checkbox or radio button of a row */
|
|
748
|
+
check_click(key) {
|
|
749
|
+
if (this.multi) this.toggle(key);
|
|
750
|
+
else this.select_only(key);
|
|
751
|
+
}
|
|
752
|
+
/**Click on a row outside its checkbox or radio button */
|
|
753
|
+
click(key, e) {
|
|
754
|
+
if (this.multi && e.shiftKey) this.#select_range(key, e.ctrlKey || e.metaKey);
|
|
755
|
+
else if (e.ctrlKey || e.metaKey) this.toggle(key);
|
|
756
|
+
else this.select_only(key);
|
|
757
|
+
}
|
|
758
|
+
/**Focus moved to a row with the arrow keys, only shift in multi mode extends the range, otherwise the focus moves alone and space selects */
|
|
759
|
+
focus_moved(key, e) {
|
|
760
|
+
if (this.multi && e.shiftKey) this.#select_range(key, e.ctrlKey || e.metaKey);
|
|
761
|
+
}
|
|
762
|
+
/**Handles selection keys pressed on a row, returns true when the key was used */
|
|
763
|
+
key_down(key, e) {
|
|
764
|
+
if (e.key === " ") {
|
|
765
|
+
if (key === void 0) return true;
|
|
766
|
+
if (this.multi || e.ctrlKey || e.metaKey) this.toggle(key);
|
|
767
|
+
else this.select_only(key);
|
|
768
|
+
} else if (e.key === "Escape") this.clear();
|
|
769
|
+
else if (this.multi && (e.ctrlKey || e.metaKey) && e.key === "a") this.select_all();
|
|
770
|
+
else return false;
|
|
771
|
+
return true;
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
/**Checkbox or radio button cell in front of a row or in the header, its look comes from the selected class of the row or the header */
|
|
775
|
+
var ListCheckField = class extends Base {
|
|
776
|
+
static element_name() {
|
|
777
|
+
return "checkfield";
|
|
778
|
+
}
|
|
779
|
+
static element_name_space() {
|
|
780
|
+
return "list";
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
define_element(ListCheckField);
|
|
784
|
+
// list/row.ts
|
|
785
|
+
var ListRow = class ListRow extends Base {
|
|
786
|
+
static element_name() {
|
|
787
|
+
return "row";
|
|
788
|
+
}
|
|
789
|
+
static element_name_space() {
|
|
790
|
+
return "list";
|
|
791
|
+
}
|
|
792
|
+
#root;
|
|
793
|
+
#parent;
|
|
794
|
+
#sub_rows;
|
|
795
|
+
depth;
|
|
796
|
+
#key_field;
|
|
797
|
+
/**Drag handle cell, only with reorder */
|
|
798
|
+
#drag;
|
|
799
|
+
/**Checkbox or radio button cell, only with selection */
|
|
800
|
+
#check;
|
|
801
|
+
#data;
|
|
802
|
+
/**Sub rows of a closed row given for a drop, used when it opens so the sub rows function is called once */
|
|
803
|
+
#drop_rows;
|
|
804
|
+
/**Key of the row in the selection, undefined when the row can not be selected */
|
|
805
|
+
selection_key;
|
|
806
|
+
#field_box;
|
|
807
|
+
#child_box;
|
|
808
|
+
#add_row;
|
|
809
|
+
#fields;
|
|
810
|
+
#values;
|
|
811
|
+
/**Shown instead of the fields while the row is invalid */
|
|
812
|
+
#invalid;
|
|
813
|
+
/**Shown instead of the sub rows while their state has an error */
|
|
814
|
+
#error;
|
|
815
|
+
#open_pending = false;
|
|
816
|
+
#sub_row_menu = false;
|
|
817
|
+
#state_sub;
|
|
818
|
+
state;
|
|
819
|
+
constructor(root, parent, data) {
|
|
820
|
+
super();
|
|
821
|
+
this.#root = root;
|
|
822
|
+
this.#parent = parent;
|
|
823
|
+
this.depth = parent.depth + 1;
|
|
824
|
+
this.style.setProperty("--i-" + this.depth, "var(--c)");
|
|
825
|
+
if (this.#root.sub_rows) {
|
|
826
|
+
this.#key_field = new ListKeyField(this);
|
|
827
|
+
if (this.#root.observer) this.#key_field.attach_to_intersect_observer(this.#root.observer);
|
|
828
|
+
}
|
|
829
|
+
this.#field_box = this.appendChild(document.createElement("div"));
|
|
830
|
+
this.#child_box = this.appendChild(document.createElement("span"));
|
|
831
|
+
if (this.#root.reorder) this.#drag = this.#root.reorder.handle(this);
|
|
832
|
+
if (this.#root.selection) this.#selection_setup(this.#root.selection);
|
|
833
|
+
if (this.#root.sub_rows) this.#child_box.oncontextmenu = () => {
|
|
834
|
+
this.#sub_row_menu = true;
|
|
835
|
+
};
|
|
836
|
+
this.#fields = this.#generate_fields();
|
|
837
|
+
this.#show_cells(this.#fields);
|
|
838
|
+
this.data = data;
|
|
839
|
+
}
|
|
840
|
+
#generate_fields() {
|
|
841
|
+
return this.#root.columns_visible.map((key) => {
|
|
842
|
+
const column = this.#root.columns.get(key);
|
|
843
|
+
const field = column.field_gen();
|
|
844
|
+
list_align_apply(field, column.align);
|
|
845
|
+
if (this.#root.observer) field.attach_to_intersect_observer(this.#root.observer);
|
|
846
|
+
return field;
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
/**Shows the cells after the key field, which stays so an invalid row keeps its indent and arrow key navigation */
|
|
850
|
+
#show_cells(cells) {
|
|
851
|
+
const lead = [];
|
|
852
|
+
if (this.#drag) lead.push(this.#drag);
|
|
853
|
+
if (this.#check) lead.push(this.#check);
|
|
854
|
+
if (this.#key_field) lead.push(this.#key_field);
|
|
855
|
+
this.#field_box.replaceChildren(...lead, ...cells);
|
|
856
|
+
}
|
|
857
|
+
#apply_values() {
|
|
858
|
+
this.#root.columns_visible.forEach((key, index) => {
|
|
859
|
+
this.#root.columns.get(key).field_apply(this.#fields[index], this.#values[key]);
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
/**Regenerates the fields of the row and its sub rows after the columns changed */
|
|
863
|
+
columns_changed() {
|
|
864
|
+
this.#fields = this.#generate_fields();
|
|
865
|
+
if (!this.#invalid) {
|
|
866
|
+
this.#show_cells(this.#fields);
|
|
867
|
+
this.#apply_values();
|
|
868
|
+
}
|
|
869
|
+
for (let i = 0; i < this.#child_box.childElementCount; i++) this.#child_box.children[i].columns_changed();
|
|
870
|
+
}
|
|
871
|
+
select_adjacent(direction, field) {
|
|
872
|
+
if (!this.#key_field && !this.#check) return;
|
|
873
|
+
const has_rows = this.#child_box.childElementCount > 0;
|
|
874
|
+
if (direction === "next" || direction === "p_next") {
|
|
875
|
+
if (direction === "next" && has_rows) this.#child_box.firstElementChild.#focus();
|
|
876
|
+
else {
|
|
877
|
+
const sibling = this.nextElementSibling;
|
|
878
|
+
if (sibling instanceof ListRow) sibling.#focus();
|
|
879
|
+
else this.#parent.select_adjacent("p_next", field);
|
|
880
|
+
}
|
|
881
|
+
} else if (direction === "previous") {
|
|
882
|
+
const sibling = this.previousElementSibling;
|
|
883
|
+
if (sibling instanceof ListRow) {
|
|
884
|
+
if (sibling.open) sibling.select_adjacent("last", field);
|
|
885
|
+
else sibling.#focus();
|
|
886
|
+
} else this.#parent.select_adjacent("p_previous", field);
|
|
887
|
+
} else if (direction === "p_previous") this.#focus();
|
|
888
|
+
else if (direction === "last") {
|
|
889
|
+
if (has_rows) this.#child_box.lastElementChild.select_adjacent("last", field);
|
|
890
|
+
else this.#focus();
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
/**Focuses the cell used for keyboard navigation, the key field or else the checkbox */
|
|
894
|
+
#focus(options) {
|
|
895
|
+
(this.#key_field ?? this.#check)?.focus(options);
|
|
896
|
+
}
|
|
897
|
+
/**Focuses the cell used for keyboard navigation */
|
|
898
|
+
focus_cell() {
|
|
899
|
+
this.#focus({ preventScroll: true });
|
|
900
|
+
}
|
|
901
|
+
/**Moves the focus to the keyboard cell after a click, so the selection keys work right away
|
|
902
|
+
* Unless the click focused something in the row itself, like an input of a field */
|
|
903
|
+
#focus_after_click() {
|
|
904
|
+
const active = document.activeElement;
|
|
905
|
+
if (active && active !== document.body && this.#field_box.contains(active)) return;
|
|
906
|
+
const cell = this.#key_field ?? this.#check;
|
|
907
|
+
if (!cell) return;
|
|
908
|
+
cell.focus({ preventScroll: true });
|
|
909
|
+
cell.classList.add("click-focus");
|
|
910
|
+
}
|
|
911
|
+
key_down(e) {
|
|
912
|
+
const selection = this.#root.selection;
|
|
913
|
+
if (e.altKey && (e.key === "ArrowDown" || e.key === "ArrowUp")) {
|
|
914
|
+
if (!this.#root.reorder) return false;
|
|
915
|
+
this.#root.reorder.key_move(this, e.key === "ArrowDown" ? 1 : -1);
|
|
916
|
+
return true;
|
|
917
|
+
}
|
|
918
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
919
|
+
this.select_adjacent(e.key === "ArrowDown" ? "next" : "previous", none());
|
|
920
|
+
const focused = document.activeElement?.closest("list-row");
|
|
921
|
+
if (selection && focused !== this && focused instanceof ListRow && focused.selection_key !== void 0) selection.focus_moved(focused.selection_key, e);
|
|
922
|
+
return true;
|
|
923
|
+
}
|
|
924
|
+
return selection ? selection.key_down(this.selection_key, e) : false;
|
|
925
|
+
}
|
|
926
|
+
set data(data) {
|
|
927
|
+
this.#data = data;
|
|
928
|
+
this.#drop_rows = void 0;
|
|
929
|
+
this.classList.toggle("movable", Boolean(this.#drag) && state$1.is.state(this.#parent.state) && this.#parent.state.writable);
|
|
930
|
+
const result = this.#root.transform(data, this, this.#parent.state);
|
|
931
|
+
if (!result.ok) {
|
|
932
|
+
this.#set_invalid(result.error);
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
const row_options = result.value;
|
|
936
|
+
if (this.#invalid) {
|
|
937
|
+
this.#invalid = void 0;
|
|
938
|
+
if (this.#key_field) this.#key_field.tail = void 0;
|
|
939
|
+
this.#show_cells(this.#fields);
|
|
940
|
+
}
|
|
941
|
+
this.#selection_update(row_options.selectable ?? true, data);
|
|
942
|
+
if (this.#key_field) this.#key_field.options = row_options.key_field;
|
|
943
|
+
this.#sub_rows = row_options.sub_rows;
|
|
944
|
+
this.add_row = row_options.add_row;
|
|
945
|
+
this.#values = row_options.values;
|
|
946
|
+
this.#apply_values();
|
|
947
|
+
const was_open = this.open;
|
|
948
|
+
if (state$1.is.state(row_options.openable)) {
|
|
949
|
+
this.#open_pending = !was_open && Boolean(row_options.opened);
|
|
950
|
+
this.attach_state_to_prop("openable", row_options.openable, () => some(false));
|
|
951
|
+
} else {
|
|
952
|
+
this.#open_pending = false;
|
|
953
|
+
this.detach_state_from_prop("openable");
|
|
954
|
+
this.openable = Boolean(row_options.openable);
|
|
955
|
+
if (!was_open && row_options.opened) this.open = true;
|
|
956
|
+
}
|
|
957
|
+
if (was_open && this.open) {
|
|
958
|
+
if (this.#sub_rows) this.rows = this.#sub_rows();
|
|
959
|
+
else if (!row_options.opened) this.open = false;
|
|
960
|
+
}
|
|
961
|
+
ctm.detach(this);
|
|
962
|
+
this.#sub_row_menu = false;
|
|
963
|
+
const menu = this.#root.sub_rows && Boolean(row_options.openable) || this.selection_key !== void 0 ? ctm.combine(() => this.#open_lines(), () => this.#selection_lines(), row_options.context_menu) : row_options.context_menu;
|
|
964
|
+
if (menu) ctm.attach(this, menu, () => {
|
|
965
|
+
const from_sub_row = this.#sub_row_menu;
|
|
966
|
+
this.#sub_row_menu = false;
|
|
967
|
+
return from_sub_row;
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
/**Replaces the fields with the text and removes everything else the row options gave */
|
|
971
|
+
#set_invalid(text) {
|
|
972
|
+
this.#selection_update(false);
|
|
973
|
+
if (this.#key_field) this.#key_field.options = void 0;
|
|
974
|
+
this.#sub_rows = void 0;
|
|
975
|
+
this.add_row = void 0;
|
|
976
|
+
this.#open_pending = false;
|
|
977
|
+
this.detach_state_from_prop("openable");
|
|
978
|
+
this.openable = false;
|
|
979
|
+
ctm.detach(this);
|
|
980
|
+
this.#sub_row_menu = false;
|
|
981
|
+
if (!this.#invalid) {
|
|
982
|
+
this.#invalid = new ListError();
|
|
983
|
+
if (this.#key_field) {
|
|
984
|
+
this.#key_field.tail = this.#invalid;
|
|
985
|
+
this.#show_cells([]);
|
|
986
|
+
} else this.#show_cells([this.#invalid]);
|
|
987
|
+
}
|
|
988
|
+
this.#invalid.text = text;
|
|
989
|
+
}
|
|
990
|
+
set add_row(options) {
|
|
991
|
+
if (!options && this.#add_row) {
|
|
992
|
+
this.#add_row.remove();
|
|
993
|
+
this.classList.remove("addrow");
|
|
994
|
+
this.#add_row = void 0;
|
|
995
|
+
} else if (options) {
|
|
996
|
+
if (!this.#add_row) {
|
|
997
|
+
this.classList.add("addrow");
|
|
998
|
+
this.#add_row = this.appendChild(new ListAddRow(this.#root, this));
|
|
999
|
+
}
|
|
1000
|
+
this.#add_row.options = options;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
set openable(value) {
|
|
1004
|
+
if (!value) this.open = false;
|
|
1005
|
+
if (this.#key_field) this.#key_field.openable = value;
|
|
1006
|
+
if (this.#open_pending) {
|
|
1007
|
+
this.#open_pending = false;
|
|
1008
|
+
if (value) this.open = true;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
get openable() {
|
|
1012
|
+
return this.#key_field?.openable ?? false;
|
|
1013
|
+
}
|
|
1014
|
+
set open(open) {
|
|
1015
|
+
if (!this.openable) return;
|
|
1016
|
+
if (open && this.#child_box.childElementCount === 0) {
|
|
1017
|
+
const rows = this.#drop_rows ?? this.#sub_rows?.();
|
|
1018
|
+
this.#drop_rows = void 0;
|
|
1019
|
+
if (rows) this.rows = rows;
|
|
1020
|
+
} else if (!open && this.open) this.rows = [];
|
|
1021
|
+
}
|
|
1022
|
+
get open() {
|
|
1023
|
+
return this.classList.contains("open");
|
|
1024
|
+
}
|
|
1025
|
+
get index() {
|
|
1026
|
+
return Array.prototype.indexOf.call(this.parentElement.children, this);
|
|
1027
|
+
}
|
|
1028
|
+
amount_rows(rec = false) {
|
|
1029
|
+
let count = this.#child_box.childElementCount;
|
|
1030
|
+
if (rec) for (let i = 0; i < this.#child_box.childElementCount; i++) count += this.#child_box.children[i].amount_rows(true);
|
|
1031
|
+
return count;
|
|
1032
|
+
}
|
|
1033
|
+
set rows(rows) {
|
|
1034
|
+
if (this.#state_sub) this.detach_state(this.#state_sub);
|
|
1035
|
+
this.#state_sub = void 0;
|
|
1036
|
+
this.state = rows;
|
|
1037
|
+
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));
|
|
1038
|
+
else this.#update_rows(rows);
|
|
1039
|
+
}
|
|
1040
|
+
#update_rows(rows, error) {
|
|
1041
|
+
this.#error = list_rows_error_update(this.#child_box, this.#error, error, this.#root.sub_rows, this);
|
|
1042
|
+
this.classList.toggle("open", rows.length > 0 || error !== void 0);
|
|
1043
|
+
list_rows_apply(this.#root, this, this.#child_box, rows);
|
|
1044
|
+
}
|
|
1045
|
+
#selection_setup(selection) {
|
|
1046
|
+
const clear_click_focus = (e) => e.currentTarget.classList.remove("click-focus");
|
|
1047
|
+
this.#check = new ListCheckField();
|
|
1048
|
+
if (!this.#key_field) this.#check.tabIndex = 0;
|
|
1049
|
+
this.#check.onkeydown = (e) => {
|
|
1050
|
+
if (this.key_down(e)) e.preventDefault();
|
|
1051
|
+
};
|
|
1052
|
+
for (const cell of [this.#check, this.#key_field]) if (cell) {
|
|
1053
|
+
cell.addEventListener("keydown", clear_click_focus);
|
|
1054
|
+
cell.addEventListener("blur", clear_click_focus);
|
|
1055
|
+
}
|
|
1056
|
+
this.#check.onclick = (e) => {
|
|
1057
|
+
e.stopPropagation();
|
|
1058
|
+
if (this.selection_key !== void 0) selection.check_click(this.selection_key);
|
|
1059
|
+
this.#focus_after_click();
|
|
1060
|
+
};
|
|
1061
|
+
this.#field_box.onclick = (e) => {
|
|
1062
|
+
if (this.selection_key !== void 0) selection.click(this.selection_key, e);
|
|
1063
|
+
this.#focus_after_click();
|
|
1064
|
+
};
|
|
1065
|
+
this.#field_box.onmousedown = (e) => {
|
|
1066
|
+
if (e.shiftKey && selection.multi) e.preventDefault();
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
/**Registers the row in the selection with the key of its data, or removes it when not selectable */
|
|
1070
|
+
#selection_update(selectable, data) {
|
|
1071
|
+
const selection = this.#root.selection;
|
|
1072
|
+
if (!selection) return;
|
|
1073
|
+
const key = selectable ? selection.key(data) : void 0;
|
|
1074
|
+
if (key === this.selection_key) return;
|
|
1075
|
+
if (this.selection_key !== void 0) selection.unregister(this.selection_key, this);
|
|
1076
|
+
this.selection_key = key;
|
|
1077
|
+
if (key !== void 0) selection.register(key, this);
|
|
1078
|
+
this.classList.toggle("selectable", key !== void 0);
|
|
1079
|
+
}
|
|
1080
|
+
/**Context menu line to open or close the sub rows, empty when the row can not be opened */
|
|
1081
|
+
#open_lines() {
|
|
1082
|
+
if (!this.openable) return [];
|
|
1083
|
+
return [this.open ? ctm.line("Close", () => this.open = false) : ctm.line("Open", () => this.open = true)];
|
|
1084
|
+
}
|
|
1085
|
+
/**Context menu lines to select or deselect the row, and in multi mode all rows
|
|
1086
|
+
* Empty when the row can not be selected */
|
|
1087
|
+
#selection_lines() {
|
|
1088
|
+
const selection = this.#root.selection;
|
|
1089
|
+
const key = this.selection_key;
|
|
1090
|
+
if (!selection || key === void 0) return [];
|
|
1091
|
+
const lines = [selection.is_selected(key) ? ctm.line("Deselect", () => selection.deselect(key)) : ctm.line("Select", () => selection.select(key))];
|
|
1092
|
+
if (selection.multi) lines.push(ctm.line("Select all", () => selection.select_all(), void 0, "Ctrl+A"), ctm.line("Deselect all", () => selection.clear(), void 0, "Esc"));
|
|
1093
|
+
return lines;
|
|
1094
|
+
}
|
|
1095
|
+
get data() {
|
|
1096
|
+
return this.#data;
|
|
1097
|
+
}
|
|
1098
|
+
/**Moving of the list the row is in, undefined when its rows can not be moved */
|
|
1099
|
+
get reorder() {
|
|
1100
|
+
return this.#root.reorder;
|
|
1101
|
+
}
|
|
1102
|
+
/**Rows of the parent the row is in */
|
|
1103
|
+
get parent_rows() {
|
|
1104
|
+
return this.#parent.state;
|
|
1105
|
+
}
|
|
1106
|
+
/**Row the row is a sub row of, undefined for top level rows */
|
|
1107
|
+
get parent_row() {
|
|
1108
|
+
return this.#parent instanceof ListRow ? this.#parent : void 0;
|
|
1109
|
+
}
|
|
1110
|
+
get next_row() {
|
|
1111
|
+
const next = this.nextElementSibling;
|
|
1112
|
+
return next instanceof ListRow ? next : void 0;
|
|
1113
|
+
}
|
|
1114
|
+
get first_sub_row() {
|
|
1115
|
+
const first = this.#child_box.firstElementChild;
|
|
1116
|
+
return first instanceof ListRow ? first : void 0;
|
|
1117
|
+
}
|
|
1118
|
+
/**Whether the row has a handle and its parent rows can be written */
|
|
1119
|
+
get movable() {
|
|
1120
|
+
return this.classList.contains("movable");
|
|
1121
|
+
}
|
|
1122
|
+
/**Whether rows can be dropped into the row, it must be openable with sub rows in a writable state */
|
|
1123
|
+
get droppable() {
|
|
1124
|
+
if (!this.openable) return false;
|
|
1125
|
+
const rows = this.drop_rows();
|
|
1126
|
+
return state$1.is.state(rows) && rows.writable;
|
|
1127
|
+
}
|
|
1128
|
+
/**The sub rows rows are dropped into, also of a closed row */
|
|
1129
|
+
drop_rows() {
|
|
1130
|
+
if (this.open) return this.state;
|
|
1131
|
+
return this.#drop_rows ??= this.#sub_rows?.();
|
|
1132
|
+
}
|
|
1133
|
+
/**Whether the row is selected in a list with multi selection, a drag of it moves all selected rows */
|
|
1134
|
+
get multi_selected() {
|
|
1135
|
+
return this.selected && Boolean(this.#root.selection?.multi);
|
|
1136
|
+
}
|
|
1137
|
+
/**Text naming the row while it is dragged, the key field text or the text of the first cell */
|
|
1138
|
+
get label() {
|
|
1139
|
+
return (this.#key_field?.querySelector(".text")?.textContent || this.#fields[0]?.textContent || "").trim();
|
|
1140
|
+
}
|
|
1141
|
+
/**First visible cell of the row, the row itself is display contents and has no box */
|
|
1142
|
+
get anchor() {
|
|
1143
|
+
return this.#field_box.firstElementChild ?? void 0;
|
|
1144
|
+
}
|
|
1145
|
+
set selected(value) {
|
|
1146
|
+
this.classList.toggle("selected", value);
|
|
1147
|
+
}
|
|
1148
|
+
get selected() {
|
|
1149
|
+
return this.classList.contains("selected");
|
|
1150
|
+
}
|
|
1151
|
+
/**Removes the row and its sub rows from the selection, when the row is removed */
|
|
1152
|
+
selection_leave() {
|
|
1153
|
+
const selection = this.#root.selection;
|
|
1154
|
+
if (!selection) return;
|
|
1155
|
+
if (this.selection_key !== void 0) selection.unregister(this.selection_key, this);
|
|
1156
|
+
this.selection_key = void 0;
|
|
1157
|
+
for (let i = 0; i < this.#child_box.childElementCount; i++) this.#child_box.children[i].selection_leave();
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
define_element(ListRow);
|
|
1161
|
+
/**Applies rows to a row box, removed rows leave the selection, which updates once after all changes */
|
|
1162
|
+
function list_rows_apply(root, parent, box, rows) {
|
|
1163
|
+
const apply = () => state_ui.a.apply(box, rows, {
|
|
1164
|
+
create: (row) => new ListRow(root, parent, row),
|
|
1165
|
+
update: (element, row) => element.data = row,
|
|
1166
|
+
destroy: (element) => element.selection_leave()
|
|
1167
|
+
});
|
|
1168
|
+
if (root.selection) root.selection.batch(apply);
|
|
1169
|
+
else apply();
|
|
1170
|
+
}
|
|
1171
|
+
// list/shared.ts
|
|
1172
|
+
const theme_root = theme_init_variable_root("list", "UI List Elements", "Theme variables for UI list elements");
|
|
1173
|
+
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);
|
|
1174
|
+
const colors = theme_root.make_sub_group("colors", "Colors", "Colors used in all list elements");
|
|
1175
|
+
const colors_text = colors.make_sub_group("text", "Text Colors", "Text colors used in all list elements");
|
|
1176
|
+
colors_text.make_variable("header", "Header Text Color", "Header text color in list elements", GREY["900"], GREY["50"], "Color", void 0);
|
|
1177
|
+
colors_text.make_variable("field", "Field Text Color", "Text color of list field elements", GREY["800"], GREY["100"], "Color", void 0);
|
|
1178
|
+
colors_text.make_variable("key_field", "Special Column Text Color", "Text color of special first column elements", GREY["900"], GREY["50"], "Color", void 0);
|
|
1179
|
+
colors_text.make_variable("add", "Row Adder Text Color", "Text color of row adder button", GREY["900"], GREY["50"], "Color", void 0);
|
|
1180
|
+
colors_text.make_variable("error", "Error Text Color", "Text color of list errors and invalid rows", RED["800"], RED["200"], "Color", void 0);
|
|
1181
|
+
const colors_icon = colors.make_sub_group("icon", "Icon Colors", "Icon colors used in all form elements");
|
|
1182
|
+
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);
|
|
1183
|
+
colors_icon.make_variable("key_icon", "Key Field Icon Color", "Color of the key field icon", GREY["800"], GREY["200"], "Color", void 0);
|
|
1184
|
+
colors_icon.make_variable("drag", "Drag Handle Color", "Color of the drag handles that move rows", GREY["600"], GREY["400"], "Color", void 0);
|
|
1185
|
+
colors_icon.make_variable("check", "Selection Checkbox Color", "Color of the selection checkboxes", GREY["800"], GREY["200"], "Color", void 0);
|
|
1186
|
+
colors_icon.make_variable("add_icon", "Add Row Icon Color", "Color of the add row icon", GREY["800"], GREY["200"], "Color", void 0);
|
|
1187
|
+
const colors_background = colors.make_sub_group("background", "Background Colors", "Background colors used in all list elements");
|
|
1188
|
+
colors_background.make_variable("row_even", "Even Row Background Color", "Color of even row element backgrounds", GREY["200"], GREY["800"], "Color", void 0);
|
|
1189
|
+
colors_background.make_variable("row_odd", "Odd Row Background Color", "Color of odd row element backgrounds", GREY["50"], GREY["900"], "Color", void 0);
|
|
1190
|
+
colors_background.make_variable("row_hover", "Hover Row Background Color", "Color of row element backgrounds when hovering", GREY["300"], GREY["700"], "Color", void 0);
|
|
1191
|
+
colors_background.make_variable("row_selected", "Selected Row Background Color", "Color of selected row element backgrounds", BLUE["100"], BLUE["900"], "Color", void 0);
|
|
1192
|
+
colors_background.make_variable("row_selected_hover", "Selected Hover Row Background Color", "Color of selected row element backgrounds when hovering", BLUE["200"], BLUE["800"], "Color", void 0);
|
|
1193
|
+
const colors_border = colors.make_sub_group("border", "Border Colors", "Border colors used in all list elements");
|
|
1194
|
+
colors_border.make_variable("header", "Header Border Color", "Color of borders under header", GREY["600"], GREY["400"], "Color", void 0);
|
|
1195
|
+
colors_border.make_variable("row", "Row Border Color", "Color of borders between rows", GREY["400"], GREY["600"], "Color", void 0);
|
|
1196
|
+
colors_border.make_variable("column", "Column Border Color", "Color of border between columns", GREY["500"], GREY["500"], "Color", void 0);
|
|
1197
|
+
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);
|
|
1198
|
+
const sizes = theme_root.make_sub_group("size", "Size", "Sizes used in all list elements");
|
|
1199
|
+
sizes.make_variable("row_min", "Row Minimum Height", "Minimum height for list rows", "1.4rem", "1.4rem", "Length", {
|
|
1200
|
+
min: .1,
|
|
1201
|
+
max: 10
|
|
1202
|
+
});
|
|
1203
|
+
sizes.make_variable("touch_row_min", "Touch Row Minimum Height", "Minimum height for list rows on touch devices", "2.6rem", "2.6rem", "Length", {
|
|
1204
|
+
min: .1,
|
|
1205
|
+
max: 10
|
|
1206
|
+
});
|
|
1207
|
+
sizes.make_variable("add_min", "Add Row Minimum Height", "Minimum height for add row button", "1rem", "1rem", "Length", {
|
|
1208
|
+
min: .1,
|
|
1209
|
+
max: 10
|
|
1210
|
+
});
|
|
1211
|
+
sizes.make_variable("touch_add_min", "Touch Add Row Minimum Height", "Minimum height for add row button on touch devices", "2rem", "2rem", "Length", {
|
|
1212
|
+
min: .1,
|
|
1213
|
+
max: 10
|
|
1214
|
+
});
|
|
1215
|
+
const animation = theme_root.make_sub_group("animation", "Animation", "Animation settings used in all list elements");
|
|
1216
|
+
animation.make_variable("transitionType", "Transition Type", "Type of transition used in list element animations", "ease-in-out", "ease-in-out", "TransitionType", void 0);
|
|
1217
|
+
animation.make_variable("transitionDuration", "Transition Duration", "Duration of transitions used in list element animations", "200ms", "200ms", "Time", {
|
|
1218
|
+
min: 0,
|
|
1219
|
+
max: 5e3
|
|
1220
|
+
});
|
|
1221
|
+
const font = theme_root.make_sub_group("font", "Font", "Font settings used in all list elements");
|
|
1222
|
+
font.make_variable("size", "Font Size", "Default font size used in all list elements", "1rem", "1rem", "Length", {
|
|
1223
|
+
min: .1,
|
|
1224
|
+
max: 10
|
|
1225
|
+
});
|
|
1226
|
+
font.make_variable("touchSize", "Touch Font Size", "Font size used in all list elements for touch devices", "1.2rem", "1.2rem", "Length", {
|
|
1227
|
+
min: .1,
|
|
1228
|
+
max: 10
|
|
1229
|
+
});
|
|
1230
|
+
// list/warn.ts
|
|
1231
|
+
/**Shows why a write of the list failed as the validation message of the browser, at the row it is about, like the form elements do
|
|
1232
|
+
* One hidden input in the container is placed over the row before the message is shown, it clears after 5 seconds */
|
|
1233
|
+
var ListWarn = class {
|
|
1234
|
+
#container;
|
|
1235
|
+
#input;
|
|
1236
|
+
#timeout;
|
|
1237
|
+
constructor(container) {
|
|
1238
|
+
this.#container = container;
|
|
1239
|
+
this.#input = container.appendChild(document.createElement("input"));
|
|
1240
|
+
this.#input.className = "list-warn";
|
|
1241
|
+
this.#input.tabIndex = -1;
|
|
1242
|
+
}
|
|
1243
|
+
/**Shows the message at the element, or at the top of the list without element
|
|
1244
|
+
* @param at element to point at, rows are display contents, so give one of their cells */
|
|
1245
|
+
show(at, message) {
|
|
1246
|
+
const input = this.#input;
|
|
1247
|
+
const container = this.#container;
|
|
1248
|
+
const box = container.getBoundingClientRect();
|
|
1249
|
+
const rect = at?.getBoundingClientRect() ?? box;
|
|
1250
|
+
input.style.top = rect.top - box.top + container.scrollTop + "px";
|
|
1251
|
+
input.style.left = Math.max(rect.left - box.left, 0) + container.scrollLeft + "px";
|
|
1252
|
+
input.style.width = rect.width + "px";
|
|
1253
|
+
input.style.height = rect.height + "px";
|
|
1254
|
+
const focused = document.activeElement;
|
|
1255
|
+
input.setCustomValidity(message);
|
|
1256
|
+
input.reportValidity();
|
|
1257
|
+
if (focused instanceof HTMLElement && focused !== document.activeElement) focused.focus({ preventScroll: true });
|
|
1258
|
+
if (this.#timeout) clearTimeout(this.#timeout);
|
|
1259
|
+
this.#timeout = window.setTimeout(() => {
|
|
1260
|
+
input.setCustomValidity("");
|
|
1261
|
+
input.reportValidity();
|
|
1262
|
+
}, 5e3);
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
// list/container.ts
|
|
1266
|
+
var HeaderField = class extends Base {
|
|
1267
|
+
static element_name() {
|
|
1268
|
+
return "headerfield";
|
|
1269
|
+
}
|
|
1270
|
+
static element_name_space() {
|
|
1271
|
+
return "list";
|
|
1272
|
+
}
|
|
1273
|
+
#box = this.appendChild(document.createElement("div"));
|
|
1274
|
+
#text = this.#box.appendChild(document.createElement("span"));
|
|
1275
|
+
#sizer;
|
|
1276
|
+
constructor(text) {
|
|
1277
|
+
super();
|
|
1278
|
+
if (text) this.text = text;
|
|
1279
|
+
}
|
|
1280
|
+
set text(value) {
|
|
1281
|
+
this.#text.textContent = value;
|
|
1282
|
+
}
|
|
1283
|
+
sizable(sizeable, sizer) {
|
|
1284
|
+
if (sizeable) {
|
|
1285
|
+
this.#sizer = this.#box.appendChild(document.createElement("div"));
|
|
1286
|
+
let double_timeout;
|
|
1287
|
+
this.#sizer.onpointerdown = (e) => {
|
|
1288
|
+
e.preventDefault();
|
|
1289
|
+
if (double_timeout) {
|
|
1290
|
+
sizer(void 0);
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
double_timeout = window.setTimeout(() => {
|
|
1294
|
+
double_timeout = 0;
|
|
1295
|
+
}, 300);
|
|
1296
|
+
this.setPointerCapture(e.pointerId);
|
|
1297
|
+
const handle = e.currentTarget;
|
|
1298
|
+
handle.classList.add("active");
|
|
1299
|
+
const start_x = e.pageX;
|
|
1300
|
+
const start_width = this.#box.offsetWidth;
|
|
1301
|
+
this.onpointermove = (ev) => {
|
|
1302
|
+
sizer(px_to_rem(start_width + (ev.pageX - start_x)));
|
|
1303
|
+
};
|
|
1304
|
+
const end = () => {
|
|
1305
|
+
if (this.hasPointerCapture(e.pointerId)) this.releasePointerCapture(e.pointerId);
|
|
1306
|
+
handle.classList.remove("active");
|
|
1307
|
+
this.onpointermove = null;
|
|
1308
|
+
this.onpointerup = null;
|
|
1309
|
+
this.onpointercancel = null;
|
|
1310
|
+
this.onlostpointercapture = null;
|
|
1311
|
+
};
|
|
1312
|
+
this.onpointerup = end;
|
|
1313
|
+
this.onpointercancel = end;
|
|
1314
|
+
this.onlostpointercapture = end;
|
|
1315
|
+
};
|
|
1316
|
+
} else if (this.#sizer) {
|
|
1317
|
+
this.#sizer.remove();
|
|
1318
|
+
this.#sizer = void 0;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1322
|
+
define_element(HeaderField);
|
|
1323
|
+
var HeaderRow = class extends Base {
|
|
1324
|
+
static element_name() {
|
|
1325
|
+
return "headerrow";
|
|
1326
|
+
}
|
|
1327
|
+
static element_name_space() {
|
|
1328
|
+
return "list";
|
|
1329
|
+
}
|
|
1330
|
+
set fields(fields) {
|
|
1331
|
+
const lead = [];
|
|
1332
|
+
if (this.#drag_header) lead.push(this.#drag_header);
|
|
1333
|
+
if (this.#check_header) lead.push(this.#check_header);
|
|
1334
|
+
if (this.#key_header) lead.push(this.#key_header);
|
|
1335
|
+
this.replaceChildren(...lead, ...fields);
|
|
1336
|
+
}
|
|
1337
|
+
/**Header of the key field column, only with sub rows */
|
|
1338
|
+
#key_header;
|
|
1339
|
+
/**Empty header of the drag handle column */
|
|
1340
|
+
#drag_header;
|
|
1341
|
+
/**Header of the checkbox or radio button column, in multi mode it selects or deselects all rows */
|
|
1342
|
+
#check_header;
|
|
1343
|
+
constructor(root, key_sizer) {
|
|
1344
|
+
super();
|
|
1345
|
+
if (root.sub_rows) {
|
|
1346
|
+
this.#key_header = new HeaderField();
|
|
1347
|
+
this.#key_header.classList.add("key");
|
|
1348
|
+
this.#key_header.sizable(true, key_sizer);
|
|
1349
|
+
}
|
|
1350
|
+
if (root.reorder) this.#drag_header = new ListDragField();
|
|
1351
|
+
const selection = root.selection;
|
|
1352
|
+
if (selection) this.#check_header = new ListCheckField();
|
|
1353
|
+
if (selection?.multi) {
|
|
1354
|
+
const check = this.#check_header;
|
|
1355
|
+
check.onclick = () => {
|
|
1356
|
+
if (selection.amount_selected > 0) selection.clear();
|
|
1357
|
+
else selection.select_all();
|
|
1358
|
+
};
|
|
1359
|
+
ctm.attach(check, ctm.menu([ctm.line("Select all", () => selection.select_all(), void 0, "Ctrl+A"), ctm.line("Deselect all", () => selection.clear(), void 0, "Esc")]));
|
|
1360
|
+
selection.on_change = () => {
|
|
1361
|
+
const selected = selection.amount_selected;
|
|
1362
|
+
check.classList.toggle("some", selected > 0);
|
|
1363
|
+
check.classList.toggle("all", selected > 0 && selected === selection.amount_selectable);
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
define_element(HeaderRow);
|
|
1369
|
+
var Container = class extends Base {
|
|
1370
|
+
static element_name() {
|
|
1371
|
+
return "container";
|
|
1372
|
+
}
|
|
1373
|
+
static element_name_space() {
|
|
1374
|
+
return "list";
|
|
1375
|
+
}
|
|
1376
|
+
#root;
|
|
1377
|
+
#selection;
|
|
1378
|
+
#selection_sub;
|
|
1379
|
+
#parent;
|
|
1380
|
+
#box = this.appendChild(document.createElement("div"));
|
|
1381
|
+
#header;
|
|
1382
|
+
#child_box;
|
|
1383
|
+
#error;
|
|
1384
|
+
#add_row;
|
|
1385
|
+
#state_sub;
|
|
1386
|
+
/**Width of the key field column in rem set by resizing, fits the key fields when undefined */
|
|
1387
|
+
#key_width;
|
|
1388
|
+
constructor(columns, transform, rows, options) {
|
|
1389
|
+
super();
|
|
1390
|
+
this.#root = {
|
|
1391
|
+
sub_rows: options?.sub_rows ?? false,
|
|
1392
|
+
columns: /* @__PURE__ */ new Map(),
|
|
1393
|
+
columns_visible: [],
|
|
1394
|
+
transform,
|
|
1395
|
+
observer: options?.observer
|
|
1396
|
+
};
|
|
1397
|
+
this.#parent = {
|
|
1398
|
+
depth: -1,
|
|
1399
|
+
open: false,
|
|
1400
|
+
select_adjacent() {},
|
|
1401
|
+
state: rows
|
|
1402
|
+
};
|
|
1403
|
+
this.#child_box = document.createElement("div");
|
|
1404
|
+
const warn = options?.selection || options?.reorder ? new ListWarn(this) : void 0;
|
|
1405
|
+
if (options?.reorder) {
|
|
1406
|
+
this.#root.reorder = new ListReorder(this, options.reorder, warn);
|
|
1407
|
+
this.#box.classList.add("drag");
|
|
1408
|
+
}
|
|
1409
|
+
if (options?.selection) {
|
|
1410
|
+
this.#selection = new ListSelection(options.selection, this.#child_box);
|
|
1411
|
+
this.#root.selection = this.#selection;
|
|
1412
|
+
this.#box.classList.add("check", this.#selection.multi ? "multi" : "single");
|
|
1413
|
+
this.#selection.on_error = (row, message) => warn.show(row?.anchor ?? this.#header ?? this.#box, message);
|
|
1414
|
+
}
|
|
1415
|
+
const lead = Number(Boolean(options?.reorder)) + Number(Boolean(options?.selection));
|
|
1416
|
+
if (lead) this.#box.classList.add("lead-" + lead);
|
|
1417
|
+
if (!options?.headless) this.#header = this.#box.appendChild(new HeaderRow(this.#root, (width) => {
|
|
1418
|
+
this.#key_width = width;
|
|
1419
|
+
this.#update_column_widths();
|
|
1420
|
+
}));
|
|
1421
|
+
this.#box.appendChild(this.#child_box);
|
|
1422
|
+
if (options?.sub_rows) this.#box.classList.add("sub-rows");
|
|
1423
|
+
this.add_row = options?.add_row;
|
|
1424
|
+
this.columns = columns;
|
|
1425
|
+
this.rows = rows;
|
|
1426
|
+
if (this.#selection) this.bind({});
|
|
1427
|
+
}
|
|
1428
|
+
set columns(columns) {
|
|
1429
|
+
this.#root.columns.clear();
|
|
1430
|
+
const order = /* @__PURE__ */ new Map();
|
|
1431
|
+
let index = 0;
|
|
1432
|
+
for (const key in columns) {
|
|
1433
|
+
this.#root.columns.set(key, { ...columns[key] });
|
|
1434
|
+
order.set(key, columns[key].order ?? index);
|
|
1435
|
+
index++;
|
|
1436
|
+
}
|
|
1437
|
+
this.#root.columns_visible = [...order.keys()].sort((a, b) => order.get(a) - order.get(b));
|
|
1438
|
+
if (this.#header) {
|
|
1439
|
+
const headers = this.#root.columns_visible.map((key) => {
|
|
1440
|
+
const column = this.#root.columns.get(key);
|
|
1441
|
+
const header = new HeaderField(column.title);
|
|
1442
|
+
list_align_apply(header, column.align);
|
|
1443
|
+
header.sizable(typeof column.fixed_width === "undefined", (width) => {
|
|
1444
|
+
if (width !== void 0) this.#freeze_auto_widths(headers);
|
|
1445
|
+
column.init_width = width;
|
|
1446
|
+
this.#update_column_widths();
|
|
1447
|
+
});
|
|
1448
|
+
return header;
|
|
1449
|
+
});
|
|
1450
|
+
this.#header.fields = headers;
|
|
1451
|
+
}
|
|
1452
|
+
this.#update_column_widths();
|
|
1453
|
+
for (let i = 0; i < this.#child_box.childElementCount; i++) this.#child_box.children[i].columns_changed();
|
|
1454
|
+
}
|
|
1455
|
+
/**Gives the auto width columns their current width, so resizing one column does not resize the others
|
|
1456
|
+
* Only measures while there are auto width columns, so after the first resize a move does no layout here*/
|
|
1457
|
+
#freeze_auto_widths(headers) {
|
|
1458
|
+
const auto = this.#root.columns_visible.flatMap((key, i) => {
|
|
1459
|
+
const col = this.#root.columns.get(key);
|
|
1460
|
+
return col.fixed_width === void 0 && !col.init_width ? [i] : [];
|
|
1461
|
+
});
|
|
1462
|
+
const widths = auto.map((i) => px_to_rem(headers[i].offsetWidth));
|
|
1463
|
+
auto.forEach((i, j) => {
|
|
1464
|
+
this.#root.columns.get(this.#root.columns_visible[i]).init_width = widths[j];
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
#update_column_widths() {
|
|
1468
|
+
const widths = this.#root.columns_visible.map((key) => {
|
|
1469
|
+
const col = this.#root.columns.get(key);
|
|
1470
|
+
const width = col.fixed_width ?? col.init_width;
|
|
1471
|
+
if (width) {
|
|
1472
|
+
if (width === "min") return "min-content";
|
|
1473
|
+
else if (width === "max") return "max-content";
|
|
1474
|
+
return `${Math.max(width, 1)}rem`;
|
|
1475
|
+
}
|
|
1476
|
+
return "auto";
|
|
1477
|
+
});
|
|
1478
|
+
if (this.#root.sub_rows) widths.unshift("max-content");
|
|
1479
|
+
this.#box.classList.toggle("key-sized", Boolean(this.#key_width));
|
|
1480
|
+
if (this.#key_width) this.#box.style.setProperty("--list-key-width", `${Math.max(this.#key_width, 1)}rem`);
|
|
1481
|
+
else this.#box.style.removeProperty("--list-key-width");
|
|
1482
|
+
if (this.#selection) widths.unshift("var(--list-check-width)");
|
|
1483
|
+
if (this.#root.reorder) widths.unshift("var(--list-drag-width)");
|
|
1484
|
+
this.#box.style.gridTemplateColumns = widths.join(" ");
|
|
1485
|
+
}
|
|
1486
|
+
set add_row(options) {
|
|
1487
|
+
if (!options && this.#add_row) {
|
|
1488
|
+
this.#add_row.remove();
|
|
1489
|
+
this.#box.classList.remove("addrow");
|
|
1490
|
+
this.#add_row = void 0;
|
|
1491
|
+
} else if (options) {
|
|
1492
|
+
if (!this.#add_row) {
|
|
1493
|
+
this.#box.classList.add("addrow");
|
|
1494
|
+
this.#add_row = this.#box.appendChild(new ListAddRow(this.#root, this.#parent));
|
|
1495
|
+
}
|
|
1496
|
+
this.#add_row.options = options;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
amount_rows(rec = false) {
|
|
1500
|
+
let count = this.#child_box.childElementCount;
|
|
1501
|
+
if (rec) for (let i = 0; i < this.#child_box.childElementCount; i++) count += this.#child_box.children[i].amount_rows(true);
|
|
1502
|
+
return count;
|
|
1503
|
+
}
|
|
1504
|
+
set rows(rows) {
|
|
1505
|
+
if (this.#state_sub) this.detach_state(this.#state_sub);
|
|
1506
|
+
this.#state_sub = void 0;
|
|
1507
|
+
this.#parent.state = rows;
|
|
1508
|
+
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));
|
|
1509
|
+
else this.#update_rows(rows);
|
|
1510
|
+
}
|
|
1511
|
+
#update_rows(rows, error) {
|
|
1512
|
+
this.#error = list_rows_error_update(this.#child_box, this.#error, error, this.#root.sub_rows, this.#parent);
|
|
1513
|
+
list_rows_apply(this.#root, this.#parent, this.#child_box, rows);
|
|
1514
|
+
}
|
|
1515
|
+
/**Binds the selection to an array state of keys, which can be shared with other lists and elements
|
|
1516
|
+
* The list shows the keys that have a visible row, and only writes the state on user actions,
|
|
1517
|
+
* with array write instructions, so it must be a state that applies them, like a local writable state
|
|
1518
|
+
* Without a state the selection is kept in a state of the list that nobody else can reach
|
|
1519
|
+
* Needs the selection option */
|
|
1520
|
+
bind(opts) {
|
|
1521
|
+
const selection = this.#selection;
|
|
1522
|
+
if (!selection) {
|
|
1523
|
+
if (opts.selection) console.error("List has no selection option", this);
|
|
1524
|
+
return this;
|
|
1525
|
+
}
|
|
1526
|
+
if (this.#selection_sub) this.detach_state(this.#selection_sub);
|
|
1527
|
+
const target = opts.selection ?? state$1.ok_w([]);
|
|
1528
|
+
selection.target = target;
|
|
1529
|
+
this.#selection_sub = this.attach_state(target, (value) => selection.apply(value));
|
|
1530
|
+
return this;
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
define_element(Container);
|
|
1534
|
+
function container(columns, transform, rows, options) {
|
|
1535
|
+
return new Container(columns, transform, rows, options);
|
|
1536
|
+
}
|
|
1537
|
+
// list/types.ts
|
|
1538
|
+
/**Helper to create a column object */
|
|
1539
|
+
function column(options) {
|
|
1540
|
+
return options;
|
|
1541
|
+
}
|
|
1542
|
+
/**Special helper to create a string value column */
|
|
1543
|
+
function column_string(title, options) {
|
|
1544
|
+
return {
|
|
1545
|
+
title,
|
|
1546
|
+
align: options?.align,
|
|
1547
|
+
field_gen: () => list.text_field(),
|
|
1548
|
+
field_apply: (field, value) => field.text = value
|
|
1549
|
+
};
|
|
1550
|
+
}
|
|
1551
|
+
// list/index.ts
|
|
1552
|
+
const list = {
|
|
1553
|
+
column,
|
|
1554
|
+
column_string,
|
|
1555
|
+
container,
|
|
1556
|
+
text_field,
|
|
1557
|
+
number_field,
|
|
1558
|
+
node_field,
|
|
1559
|
+
/**Group of lists that can give rows to each other by dragging, all lists of a group must have the same row type */
|
|
1560
|
+
drag_group() {
|
|
1561
|
+
return new ListDragGroup();
|
|
1562
|
+
}
|
|
1563
|
+
};
|
|
1564
|
+
export { ListField as n, list as t };
|
|
1565
|
+
|
|
1566
|
+
//# sourceMappingURL=list-D08epOjk.mjs.map
|