@chocbite/ts-lib-ui 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -2
- package/base/index.d.mts +3 -0
- package/base/index.mjs +521 -0
- package/base/index.mjs.map +1 -0
- package/canvas/index.d.mts +74 -0
- package/canvas/index.mjs +619 -0
- package/canvas/index.mjs.map +1 -0
- package/context-menu/index.d.mts +3 -0
- package/context-menu/index.mjs +2 -0
- package/context-menu-3OazryD0.mjs +527 -0
- package/context-menu-3OazryD0.mjs.map +1 -0
- package/document/index.d.mts +27 -0
- package/document/index.mjs +50 -0
- package/document/index.mjs.map +1 -0
- package/dom/index.d.mts +3 -0
- package/dom/index.mjs +8 -0
- package/dom/index.mjs.map +1 -0
- package/form/index.d.mts +747 -0
- package/form/index.mjs +2694 -0
- package/form/index.mjs.map +1 -0
- package/icons/index.d.mts +4109 -0
- package/icons/index.mjs +2 -0
- package/icons/mixins.scss +12 -0
- package/icons-CY4BLQ2F.mjs +4123 -0
- package/index-BND79jZp.d.mts +212 -0
- package/index-BcidwqIy.d.mts +167 -0
- package/index-CB3-qP6l.d.mts +120 -0
- package/index-CugtUzv_.d.mts +155 -0
- package/keyboard/index.d.mts +85 -0
- package/keyboard/index.mjs +1499 -0
- package/keyboard/index.mjs.map +1 -0
- package/list/index.d.mts +3 -0
- package/list/index.mjs +2 -0
- package/list-BcNSxtNm.mjs +617 -0
- package/list-BcNSxtNm.mjs.map +1 -0
- package/package.json +95 -4
- package/selection/index.d.mts +16 -0
- package/selection/index.mjs +96 -0
- package/selection/index.mjs.map +1 -0
- package/settings/index.d.mts +43 -0
- package/settings/index.mjs +110 -0
- package/settings/index.mjs.map +1 -0
- package/spinner/index.d.mts +10 -0
- package/spinner/index.mjs +39 -0
- package/spinner/index.mjs.map +1 -0
- package/style.css +2994 -0
- package/svg/index.d.mts +3 -0
- package/svg/index.mjs +2 -0
- package/svg-golJPaR4.mjs +358 -0
- package/svg-golJPaR4.mjs.map +1 -0
- package/theme/index.d.mts +179 -0
- package/theme/index.mjs +2 -0
- package/theme/mixins.scss +39 -0
- package/theme-DhIVwHQw.mjs +338 -0
- package/theme-DhIVwHQw.mjs.map +1 -0
- package/viewport/index.d.mts +1 -0
- package/viewport/index.mjs +2 -0
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
import "./style.css";
|
|
2
|
+
import { Base, define_element } from "./base/index.mjs";
|
|
3
|
+
import { i as px_to_rem, r as theme_init_variable_root } from "./theme-DhIVwHQw.mjs";
|
|
4
|
+
import { t as ctm } from "./context-menu-3OazryD0.mjs";
|
|
5
|
+
import { state as state$1 } from "@chocbite/ts-lib/state";
|
|
6
|
+
import { none, some } from "@chocbite/ts-lib/result";
|
|
7
|
+
import { array_from_length } from "@chocbite/ts-lib/common";
|
|
8
|
+
import { GREY, ORANGE } from "@chocbite/ts-lib/colors";
|
|
9
|
+
// src/list/key_field.ts
|
|
10
|
+
var ListKeyField = class extends Base {
|
|
11
|
+
static element_name() {
|
|
12
|
+
return "keyfield";
|
|
13
|
+
}
|
|
14
|
+
static element_name_space() {
|
|
15
|
+
return "list";
|
|
16
|
+
}
|
|
17
|
+
#opener;
|
|
18
|
+
#text_box;
|
|
19
|
+
#icon;
|
|
20
|
+
constructor(parent) {
|
|
21
|
+
super();
|
|
22
|
+
this.tabIndex = 0;
|
|
23
|
+
this.onkeydown = (e) => {
|
|
24
|
+
if (e.key === "Enter" || e.key === " ") parent.open = !parent.open;
|
|
25
|
+
else if (e.key === "ArrowRight") parent.open = true;
|
|
26
|
+
else if (e.key === "ArrowLeft") parent.open = false;
|
|
27
|
+
else if (e.key === "ArrowDown") parent.select_adjacent("next", none());
|
|
28
|
+
else if (e.key === "ArrowUp") parent.select_adjacent("previous", none());
|
|
29
|
+
else return;
|
|
30
|
+
e.preventDefault();
|
|
31
|
+
};
|
|
32
|
+
const opener_box = document.createElement("span");
|
|
33
|
+
this.#opener = opener_box.appendChild(document.createElement("div"));
|
|
34
|
+
this.replaceChildren(...array_from_length(parent.depth, (i) => {
|
|
35
|
+
const div = document.createElement("div");
|
|
36
|
+
div.style.borderColor = "var(--i-" + i + ")";
|
|
37
|
+
return div;
|
|
38
|
+
}), opener_box);
|
|
39
|
+
this.#opener.addEventListener("click", (e) => {
|
|
40
|
+
e.stopPropagation();
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
parent.open = !parent.open;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
set options(options) {
|
|
46
|
+
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
|
+
}
|
|
49
|
+
set icon(value) {
|
|
50
|
+
if (this.#icon) this.#icon.remove();
|
|
51
|
+
this.#icon = void 0;
|
|
52
|
+
if (!value) return;
|
|
53
|
+
this.#icon = value();
|
|
54
|
+
if (this.#text_box) this.insertBefore(this.#icon, this.#text_box);
|
|
55
|
+
else this.appendChild(this.#icon);
|
|
56
|
+
}
|
|
57
|
+
set openable(value) {
|
|
58
|
+
if (value) this.classList.add("openable");
|
|
59
|
+
else this.classList.remove("openable");
|
|
60
|
+
}
|
|
61
|
+
get openable() {
|
|
62
|
+
return this.classList.contains("openable");
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
define_element(ListKeyField);
|
|
66
|
+
// src/list/add_row.ts
|
|
67
|
+
var ListAddRow = class extends Base {
|
|
68
|
+
static element_name() {
|
|
69
|
+
return "addrow";
|
|
70
|
+
}
|
|
71
|
+
static element_name_space() {
|
|
72
|
+
return "list";
|
|
73
|
+
}
|
|
74
|
+
#button;
|
|
75
|
+
depth;
|
|
76
|
+
constructor(root, parent) {
|
|
77
|
+
super();
|
|
78
|
+
this.depth = parent.depth + 1;
|
|
79
|
+
if (root.sub_rows) this.appendChild(new ListKeyField(this));
|
|
80
|
+
this.#button = this.appendChild(document.createElement("span"));
|
|
81
|
+
this.#button.tabIndex = 0;
|
|
82
|
+
}
|
|
83
|
+
set options(options) {
|
|
84
|
+
this.#button.onclick = options.on_add;
|
|
85
|
+
if (state$1.is.state(options.text)) this.attach_state_to_prop("text", options.text, (e) => some(e));
|
|
86
|
+
else this.text = options.text;
|
|
87
|
+
if (state$1.is.state(options.disabled)) this.attach_state_to_prop("disabled", options.disabled, () => some(false));
|
|
88
|
+
else if (options.disabled) this.disabled = options.disabled;
|
|
89
|
+
}
|
|
90
|
+
set text(value) {
|
|
91
|
+
this.#button.innerHTML = value;
|
|
92
|
+
}
|
|
93
|
+
set disabled(value) {
|
|
94
|
+
if (value) this.inert = true;
|
|
95
|
+
else this.inert = false;
|
|
96
|
+
}
|
|
97
|
+
set open(_value) {}
|
|
98
|
+
get open() {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
set global_index(_value) {}
|
|
102
|
+
get global_index() {
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
set state(_value) {}
|
|
106
|
+
get state() {
|
|
107
|
+
throw new Error("Method not implemented.");
|
|
108
|
+
}
|
|
109
|
+
get global_amount() {
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
select_adjacent() {}
|
|
113
|
+
};
|
|
114
|
+
define_element(ListAddRow);
|
|
115
|
+
// src/list/field.ts
|
|
116
|
+
var ListField = class extends Base {
|
|
117
|
+
static element_name() {
|
|
118
|
+
return "@abstract@";
|
|
119
|
+
}
|
|
120
|
+
static element_name_space() {
|
|
121
|
+
return "list";
|
|
122
|
+
}
|
|
123
|
+
constructor() {
|
|
124
|
+
super();
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
var ListTextField = class extends ListField {
|
|
128
|
+
static element_name() {
|
|
129
|
+
return "textfield";
|
|
130
|
+
}
|
|
131
|
+
set text(value) {
|
|
132
|
+
this.innerHTML = value;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
define_element(ListTextField);
|
|
136
|
+
function text_field() {
|
|
137
|
+
return new ListTextField();
|
|
138
|
+
}
|
|
139
|
+
var ListNumberField = class extends ListField {
|
|
140
|
+
static element_name() {
|
|
141
|
+
return "numberfield";
|
|
142
|
+
}
|
|
143
|
+
set number(value) {
|
|
144
|
+
this.innerHTML = value.toString();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
define_element(ListNumberField);
|
|
148
|
+
function number_field() {
|
|
149
|
+
return new ListNumberField();
|
|
150
|
+
}
|
|
151
|
+
var ListNodeField = class extends ListField {
|
|
152
|
+
static element_name() {
|
|
153
|
+
return "nodefield";
|
|
154
|
+
}
|
|
155
|
+
constructor(node) {
|
|
156
|
+
super();
|
|
157
|
+
this.appendChild(node);
|
|
158
|
+
}
|
|
159
|
+
set node(node) {
|
|
160
|
+
this.replaceChildren(node);
|
|
161
|
+
}
|
|
162
|
+
get node() {
|
|
163
|
+
return this.firstChild;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
define_element(ListNodeField);
|
|
167
|
+
function node_field(node) {
|
|
168
|
+
return new ListNodeField(node);
|
|
169
|
+
}
|
|
170
|
+
// src/list/row.ts
|
|
171
|
+
var ListRow = class ListRow extends Base {
|
|
172
|
+
static element_name() {
|
|
173
|
+
return "row";
|
|
174
|
+
}
|
|
175
|
+
static element_name_space() {
|
|
176
|
+
return "list";
|
|
177
|
+
}
|
|
178
|
+
#root;
|
|
179
|
+
#parent;
|
|
180
|
+
#sub_rows;
|
|
181
|
+
depth;
|
|
182
|
+
#key_field;
|
|
183
|
+
#field_box;
|
|
184
|
+
#child_box;
|
|
185
|
+
#add_row;
|
|
186
|
+
#fields;
|
|
187
|
+
#state_sub;
|
|
188
|
+
state;
|
|
189
|
+
constructor(root, parent, data) {
|
|
190
|
+
super();
|
|
191
|
+
this.#root = root;
|
|
192
|
+
this.#parent = parent;
|
|
193
|
+
this.depth = parent.depth + 1;
|
|
194
|
+
this.style.setProperty("--i-" + this.depth, "var(--c)");
|
|
195
|
+
if (this.#root.sub_rows) {
|
|
196
|
+
this.#key_field = new ListKeyField(this);
|
|
197
|
+
if (this.#root.observer) this.#key_field.attach_to_intersect_observer(this.#root.observer);
|
|
198
|
+
}
|
|
199
|
+
this.#field_box = this.appendChild(document.createElement("div"));
|
|
200
|
+
this.#child_box = this.appendChild(document.createElement("span"));
|
|
201
|
+
this.#fields = this.#root.columns_visible.map((key) => {
|
|
202
|
+
const field = this.#root.columns.get(key).field_gen();
|
|
203
|
+
if (this.#root.observer) field.attach_to_intersect_observer(this.#root.observer);
|
|
204
|
+
return field;
|
|
205
|
+
});
|
|
206
|
+
if (this.#key_field) this.#field_box.replaceChildren(this.#key_field, ...this.#fields);
|
|
207
|
+
else this.#field_box.replaceChildren(...this.#fields);
|
|
208
|
+
this.data = data;
|
|
209
|
+
}
|
|
210
|
+
select_adjacent(direction, field) {
|
|
211
|
+
if (!this.#key_field) return;
|
|
212
|
+
if (direction === "next" || direction === "p_next") {
|
|
213
|
+
if (direction === "next" && this.open) this.#child_box.firstElementChild.#key_field.focus();
|
|
214
|
+
else {
|
|
215
|
+
const sibling = this.nextElementSibling;
|
|
216
|
+
if (sibling instanceof ListRow) sibling.#key_field.focus();
|
|
217
|
+
else this.#parent.select_adjacent("p_next", field);
|
|
218
|
+
}
|
|
219
|
+
} else if (direction === "previous") {
|
|
220
|
+
const sibling = this.previousElementSibling;
|
|
221
|
+
if (sibling instanceof ListRow) {
|
|
222
|
+
if (sibling.open) sibling.select_adjacent("last", field);
|
|
223
|
+
else sibling.#key_field.focus();
|
|
224
|
+
} else this.#parent.select_adjacent("p_previous", field);
|
|
225
|
+
} else if (direction === "p_previous") this.#key_field.focus();
|
|
226
|
+
else if (direction === "last") {
|
|
227
|
+
if (this.open) this.#child_box.lastElementChild.select_adjacent("last", field);
|
|
228
|
+
else this.#key_field.focus();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
set data(data) {
|
|
232
|
+
const row_options = this.#root.transform(data, this, this.#parent.state);
|
|
233
|
+
if (this.#key_field) this.#key_field.options = row_options.key_field;
|
|
234
|
+
this.#sub_rows = row_options.sub_rows;
|
|
235
|
+
this.add_row = row_options.add_row;
|
|
236
|
+
this.#root.columns_visible.forEach((key, index) => {
|
|
237
|
+
this.#root.columns.get(key).field_apply(this.#fields[index], row_options.values[key]);
|
|
238
|
+
});
|
|
239
|
+
if (state$1.is.state(row_options.openable)) this.attach_state_to_prop("openable", row_options.openable, () => {
|
|
240
|
+
this.open = false;
|
|
241
|
+
return some(false);
|
|
242
|
+
});
|
|
243
|
+
else if (row_options.openable) {
|
|
244
|
+
this.detach_state_from_prop("openable");
|
|
245
|
+
this.openable = row_options.openable;
|
|
246
|
+
}
|
|
247
|
+
if (row_options.opened) {
|
|
248
|
+
if (this.open) {
|
|
249
|
+
if (this.#sub_rows) this.rows = this.#sub_rows?.();
|
|
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;
|
|
254
|
+
}
|
|
255
|
+
ctm.detach(this);
|
|
256
|
+
if (row_options.context_menu) ctm.attach(this, row_options.context_menu);
|
|
257
|
+
}
|
|
258
|
+
set add_row(options) {
|
|
259
|
+
if (!options && this.#add_row) {
|
|
260
|
+
this.#add_row.remove();
|
|
261
|
+
this.classList.remove("addrow");
|
|
262
|
+
this.#add_row = void 0;
|
|
263
|
+
} else if (options) {
|
|
264
|
+
if (!this.#add_row) {
|
|
265
|
+
this.classList.add("addrow");
|
|
266
|
+
this.#add_row = this.appendChild(new ListAddRow(this.#root, this));
|
|
267
|
+
}
|
|
268
|
+
this.#add_row.options = options;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
set openable(value) {
|
|
272
|
+
if (!value) this.open = false;
|
|
273
|
+
if (this.#key_field) this.#key_field.openable = value;
|
|
274
|
+
}
|
|
275
|
+
get openable() {
|
|
276
|
+
return this.#key_field?.openable ?? false;
|
|
277
|
+
}
|
|
278
|
+
set open(open) {
|
|
279
|
+
if (!this.openable) return;
|
|
280
|
+
if (open && this.#child_box.childElementCount === 0) {
|
|
281
|
+
if (this.#sub_rows) this.rows = this.#sub_rows?.();
|
|
282
|
+
if (this.#child_box.childElementCount > 0 || this.#add_row) this.classList.add("open");
|
|
283
|
+
} else if (!open && this.open) {
|
|
284
|
+
this.rows = [];
|
|
285
|
+
this.classList.remove("open");
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
get open() {
|
|
289
|
+
return this.classList.contains("open");
|
|
290
|
+
}
|
|
291
|
+
get index() {
|
|
292
|
+
return Array.prototype.indexOf.call(this.parentElement.children, this);
|
|
293
|
+
}
|
|
294
|
+
amount_rows(rec = false) {
|
|
295
|
+
let count = this.#child_box.childElementCount;
|
|
296
|
+
if (rec) for (let i = 0; i < this.#child_box.childElementCount; i++) count += this.#child_box.children[i].amount_rows(true);
|
|
297
|
+
return count;
|
|
298
|
+
}
|
|
299
|
+
set rows(rows) {
|
|
300
|
+
if (this.#state_sub) this.detach_state(this.#state_sub);
|
|
301
|
+
this.#state_sub = void 0;
|
|
302
|
+
this.state = rows;
|
|
303
|
+
if (state$1.is.state(rows)) this.#state_sub = this.attach_state(rows, (r) => this.#update_rows(r.ok ? r.value : []));
|
|
304
|
+
else this.#update_rows(rows);
|
|
305
|
+
}
|
|
306
|
+
#update_rows(rows) {
|
|
307
|
+
if (rows.length === 0) {
|
|
308
|
+
this.#child_box.replaceChildren();
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const read = state$1.a.read(rows);
|
|
312
|
+
for (let i = 0; i < read.length; i++) {
|
|
313
|
+
const row = read[i];
|
|
314
|
+
if (row.type === "fresh") {
|
|
315
|
+
const min = Math.min(this.#child_box.childElementCount, row.items.length);
|
|
316
|
+
for (let i = 0; i < min; i++) this.#child_box.children[i].data = row.items[i];
|
|
317
|
+
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)));
|
|
318
|
+
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();
|
|
319
|
+
} else if (row.type === "added") {
|
|
320
|
+
const child = this.#child_box.children[row.index];
|
|
321
|
+
const rows = row.items.map((row) => new ListRow(this.#root, this, row));
|
|
322
|
+
if (child) child.before(...rows);
|
|
323
|
+
else this.#child_box.append(...rows);
|
|
324
|
+
} else if (row.type === "removed") for (let i = 0; i < row.items.length; i++) this.#child_box.children[row.index].remove();
|
|
325
|
+
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];
|
|
326
|
+
else if (row.type === "moved") {
|
|
327
|
+
const extracted = [];
|
|
328
|
+
for (let i = 0; i < row.items.length; i++) {
|
|
329
|
+
const child = this.#child_box.children[row.from_index + i];
|
|
330
|
+
extracted.push(child);
|
|
331
|
+
child.remove();
|
|
332
|
+
}
|
|
333
|
+
const child = this.#child_box.children[row.to_index];
|
|
334
|
+
for (let i = 0; i < extracted.length; i++) if (child) child.before(extracted[i]);
|
|
335
|
+
else this.#child_box.append(extracted[i]);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
define_element(ListRow);
|
|
341
|
+
// src/list/shared.ts
|
|
342
|
+
const theme_root = theme_init_variable_root("list", "UI List Elements", "Theme variables for UI list elements");
|
|
343
|
+
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);
|
|
344
|
+
const colors = theme_root.make_sub_group("colors", "Colors", "Colors used in all list elements");
|
|
345
|
+
const colors_text = colors.make_sub_group("text", "Text Colors", "Text colors used in all list elements");
|
|
346
|
+
colors_text.make_variable("header", "Header Text Color", "Header text color in list elements", GREY["900"], GREY["50"], "Color", void 0);
|
|
347
|
+
colors_text.make_variable("field", "Field Text Color", "Text color of list field elements", GREY["800"], GREY["100"], "Color", void 0);
|
|
348
|
+
colors_text.make_variable("key_field", "Special Column Text Color", "Text color of special first column elements", GREY["900"], GREY["50"], "Color", void 0);
|
|
349
|
+
colors_text.make_variable("add", "Row Adder Text Color", "Text color of row adder button", GREY["900"], GREY["50"], "Color", void 0);
|
|
350
|
+
const colors_icon = colors.make_sub_group("icon", "Icon Colors", "Icon colors used in all form elements");
|
|
351
|
+
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);
|
|
352
|
+
colors_icon.make_variable("key_icon", "Key Field Icon Color", "Color of the key field icon", GREY["800"], GREY["200"], "Color", void 0);
|
|
353
|
+
colors_icon.make_variable("add_icon", "Add Row Icon Color", "Color of the add row icon", GREY["800"], GREY["200"], "Color", void 0);
|
|
354
|
+
const colors_background = colors.make_sub_group("background", "Background Colors", "Background colors used in all list elements");
|
|
355
|
+
colors_background.make_variable("row_even", "Even Row Background Color", "Color of even row element backgrounds", GREY["100"], GREY["800"], "Color", void 0);
|
|
356
|
+
colors_background.make_variable("row_odd", "Odd Row Background Color", "Color of odd row element backgrounds", GREY["50"], GREY["900"], "Color", void 0);
|
|
357
|
+
colors_background.make_variable("row_hover", "Hover Row Background Color", "Color of row element backgrounds when hovering", GREY["300"], GREY["700"], "Color", void 0);
|
|
358
|
+
const colors_border = colors.make_sub_group("border", "Border Colors", "Border colors used in all list elements");
|
|
359
|
+
colors_border.make_variable("header", "Header Border Color", "Color of borders under header", GREY["600"], GREY["400"], "Color", void 0);
|
|
360
|
+
colors_border.make_variable("row", "Row Border Color", "Color of borders between rows", GREY["400"], GREY["600"], "Color", void 0);
|
|
361
|
+
colors_border.make_variable("column", "Column Border Color", "Color of border between columns", GREY["500"], GREY["500"], "Color", void 0);
|
|
362
|
+
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);
|
|
363
|
+
const sizes = theme_root.make_sub_group("size", "Size", "Sizes used in all list elements");
|
|
364
|
+
sizes.make_variable("row_min", "Row Minimum Height", "Minimum height for list rows", "1.4rem", "1.4rem", "Length", {
|
|
365
|
+
min: .1,
|
|
366
|
+
max: 10
|
|
367
|
+
});
|
|
368
|
+
sizes.make_variable("touch_row_min", "Touch Row Minimum Height", "Minimum height for list rows on touch devices", "2.6rem", "2.6rem", "Length", {
|
|
369
|
+
min: .1,
|
|
370
|
+
max: 10
|
|
371
|
+
});
|
|
372
|
+
sizes.make_variable("add_min", "Add Row Minimum Height", "Minimum height for add row button", "1rem", "1rem", "Length", {
|
|
373
|
+
min: .1,
|
|
374
|
+
max: 10
|
|
375
|
+
});
|
|
376
|
+
sizes.make_variable("touch_add_min", "Touch Add Row Minimum Height", "Minimum height for add row button on touch devices", "2rem", "2rem", "Length", {
|
|
377
|
+
min: .1,
|
|
378
|
+
max: 10
|
|
379
|
+
});
|
|
380
|
+
const animation = theme_root.make_sub_group("animation", "Animation", "Animation settings used in all list elements");
|
|
381
|
+
animation.make_variable("transitionType", "Transition Type", "Type of transition used in list element animations", "ease-in-out", "ease-in-out", "TransitionType", void 0);
|
|
382
|
+
animation.make_variable("transitionDuration", "Transition Duration", "Duration of transitions used in list element animations", "200ms", "200ms", "Time", {
|
|
383
|
+
min: 0,
|
|
384
|
+
max: 5e3
|
|
385
|
+
});
|
|
386
|
+
const font = theme_root.make_sub_group("font", "Font", "Font settings used in all list elements");
|
|
387
|
+
font.make_variable("size", "Font Size", "Default font size used in all list elements", "1rem", "1rem", "Length", {
|
|
388
|
+
min: .1,
|
|
389
|
+
max: 10
|
|
390
|
+
});
|
|
391
|
+
font.make_variable("touchSize", "Touch Font Size", "Font size used in all list elements for touch devices", "1.2rem", "1.2rem", "Length", {
|
|
392
|
+
min: .1,
|
|
393
|
+
max: 10
|
|
394
|
+
});
|
|
395
|
+
// src/list/container.ts
|
|
396
|
+
var HeaderField = class extends Base {
|
|
397
|
+
static element_name() {
|
|
398
|
+
return "headerfield";
|
|
399
|
+
}
|
|
400
|
+
static element_name_space() {
|
|
401
|
+
return "list";
|
|
402
|
+
}
|
|
403
|
+
#box = this.appendChild(document.createElement("div"));
|
|
404
|
+
#text = this.#box.appendChild(document.createElement("span"));
|
|
405
|
+
#sizer;
|
|
406
|
+
constructor(text) {
|
|
407
|
+
super();
|
|
408
|
+
if (text) this.text = text;
|
|
409
|
+
}
|
|
410
|
+
set text(value) {
|
|
411
|
+
this.#text.innerHTML = value;
|
|
412
|
+
}
|
|
413
|
+
sizable(sizeable, sizer) {
|
|
414
|
+
if (sizeable) {
|
|
415
|
+
this.#sizer = this.#box.appendChild(document.createElement("div"));
|
|
416
|
+
let double_timeout;
|
|
417
|
+
this.#sizer.onpointerdown = (e) => {
|
|
418
|
+
e.preventDefault();
|
|
419
|
+
if (double_timeout) {
|
|
420
|
+
sizer(void 0);
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
double_timeout = window.setTimeout(() => {
|
|
424
|
+
double_timeout = 0;
|
|
425
|
+
}, 300);
|
|
426
|
+
this.setPointerCapture(e.pointerId);
|
|
427
|
+
const start_x = e.pageX;
|
|
428
|
+
const start_width = this.#box.offsetWidth;
|
|
429
|
+
this.onpointermove = (ev) => {
|
|
430
|
+
sizer(px_to_rem(start_width + (ev.pageX - start_x)));
|
|
431
|
+
};
|
|
432
|
+
this.onpointerup = () => {
|
|
433
|
+
this.releasePointerCapture(e.pointerId);
|
|
434
|
+
this.onpointermove = null;
|
|
435
|
+
this.onpointerup = null;
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
} else if (this.#sizer) {
|
|
439
|
+
this.#sizer.remove();
|
|
440
|
+
this.#sizer = void 0;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
define_element(HeaderField);
|
|
445
|
+
var HeaderRow = class extends Base {
|
|
446
|
+
static element_name() {
|
|
447
|
+
return "headerrow";
|
|
448
|
+
}
|
|
449
|
+
static element_name_space() {
|
|
450
|
+
return "list";
|
|
451
|
+
}
|
|
452
|
+
set fields(fields) {
|
|
453
|
+
if (this.#root.sub_rows) this.replaceChildren(text_field(), ...fields);
|
|
454
|
+
else this.replaceChildren(...fields);
|
|
455
|
+
}
|
|
456
|
+
#root;
|
|
457
|
+
constructor(root) {
|
|
458
|
+
super();
|
|
459
|
+
this.#root = root;
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
define_element(HeaderRow);
|
|
463
|
+
var Container = class extends Base {
|
|
464
|
+
static element_name() {
|
|
465
|
+
return "container";
|
|
466
|
+
}
|
|
467
|
+
static element_name_space() {
|
|
468
|
+
return "list";
|
|
469
|
+
}
|
|
470
|
+
#root;
|
|
471
|
+
#parent;
|
|
472
|
+
#box = this.appendChild(document.createElement("div"));
|
|
473
|
+
#header;
|
|
474
|
+
#child_box;
|
|
475
|
+
#add_row;
|
|
476
|
+
#state_sub;
|
|
477
|
+
constructor(columns, transform, rows, options) {
|
|
478
|
+
super();
|
|
479
|
+
this.#root = {
|
|
480
|
+
sub_rows: options?.sub_rows ?? false,
|
|
481
|
+
columns: /* @__PURE__ */ new Map(),
|
|
482
|
+
columns_visible: [],
|
|
483
|
+
transform,
|
|
484
|
+
observer: options?.observer ? this.intersect_observer(options.observer) : void 0
|
|
485
|
+
};
|
|
486
|
+
this.#parent = {
|
|
487
|
+
depth: -1,
|
|
488
|
+
open: false,
|
|
489
|
+
select_adjacent() {},
|
|
490
|
+
state: rows
|
|
491
|
+
};
|
|
492
|
+
if (!options?.headless) this.#header = this.#box.appendChild(new HeaderRow(this.#root));
|
|
493
|
+
this.#child_box = this.#box.appendChild(document.createElement("div"));
|
|
494
|
+
if (options?.sub_rows) this.#box.classList.add("sub-rows");
|
|
495
|
+
this.add_row = options?.add_row;
|
|
496
|
+
this.columns = columns;
|
|
497
|
+
this.rows = rows;
|
|
498
|
+
}
|
|
499
|
+
set columns(columns) {
|
|
500
|
+
this.#root.columns.clear();
|
|
501
|
+
this.#root.columns_visible = [];
|
|
502
|
+
const fields = [];
|
|
503
|
+
for (const key in columns) {
|
|
504
|
+
this.#root.columns.set(key, columns[key]);
|
|
505
|
+
this.#root.columns_visible.push(key);
|
|
506
|
+
const header = new HeaderField(columns[key].title);
|
|
507
|
+
fields.push(header);
|
|
508
|
+
header.sizable(typeof columns[key].fixed_width === "undefined", (width) => {
|
|
509
|
+
this.#root.columns.get(key).init_width = width;
|
|
510
|
+
this.#update_column_widths();
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
this.#update_column_widths();
|
|
514
|
+
if (this.#header) this.#header.fields = fields;
|
|
515
|
+
}
|
|
516
|
+
#update_column_widths() {
|
|
517
|
+
const widths = this.#root.columns_visible.map((key) => {
|
|
518
|
+
const col = this.#root.columns.get(key);
|
|
519
|
+
const width = col.fixed_width ?? col.init_width;
|
|
520
|
+
if (width) {
|
|
521
|
+
if (width === "min") return "min-content";
|
|
522
|
+
else if (width === "max") return "max-content";
|
|
523
|
+
return `${Math.max(width, 1)}rem`;
|
|
524
|
+
}
|
|
525
|
+
return "auto";
|
|
526
|
+
});
|
|
527
|
+
if (this.#root.sub_rows) widths.unshift("min-content");
|
|
528
|
+
this.#box.style.gridTemplateColumns = widths.join(" ");
|
|
529
|
+
}
|
|
530
|
+
set add_row(options) {
|
|
531
|
+
if (!options && this.#add_row) {
|
|
532
|
+
this.#add_row.remove();
|
|
533
|
+
this.#box.classList.remove("addrow");
|
|
534
|
+
this.#add_row = void 0;
|
|
535
|
+
} else if (options) {
|
|
536
|
+
if (!this.#add_row) {
|
|
537
|
+
this.#box.classList.add("addrow");
|
|
538
|
+
this.#add_row = this.#box.appendChild(new ListAddRow(this.#root, this.#parent));
|
|
539
|
+
}
|
|
540
|
+
this.#add_row.options = options;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
amount_rows(rec = false) {
|
|
544
|
+
let count = this.#child_box.childElementCount;
|
|
545
|
+
if (rec) for (let i = 0; i < this.#child_box.childElementCount; i++) count += this.#child_box.children[i].amount_rows(true);
|
|
546
|
+
return count;
|
|
547
|
+
}
|
|
548
|
+
set rows(rows) {
|
|
549
|
+
if (this.#state_sub) this.detach_state(this.#state_sub);
|
|
550
|
+
this.#state_sub = void 0;
|
|
551
|
+
this.#parent.state = rows;
|
|
552
|
+
if (state$1.is.state(rows)) this.#state_sub = this.attach_state(rows, (r) => this.#update_rows(r.ok ? r.value : []));
|
|
553
|
+
else this.#update_rows(rows);
|
|
554
|
+
}
|
|
555
|
+
#update_rows(rows) {
|
|
556
|
+
if (rows.length === 0) {
|
|
557
|
+
this.#child_box.replaceChildren();
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
const read = state$1.a.read(rows);
|
|
561
|
+
for (let i = 0; i < read.length; i++) {
|
|
562
|
+
const row = read[i];
|
|
563
|
+
if (row.type === "fresh") {
|
|
564
|
+
const min = Math.min(this.#child_box.childElementCount, row.items.length);
|
|
565
|
+
for (let i = 0; i < min; i++) this.#child_box.children[i].data = row.items[i];
|
|
566
|
+
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)));
|
|
567
|
+
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();
|
|
568
|
+
} else if (row.type === "added") {
|
|
569
|
+
const child = this.#child_box.children[row.index];
|
|
570
|
+
const rows = row.items.map((row) => new ListRow(this.#root, this.#parent, row));
|
|
571
|
+
if (child) child.before(...rows);
|
|
572
|
+
else this.#child_box.append(...rows);
|
|
573
|
+
} else if (row.type === "removed") for (let i = 0; i < row.items.length; i++) this.#child_box.children[row.index].remove();
|
|
574
|
+
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];
|
|
575
|
+
else if (row.type === "moved") {
|
|
576
|
+
const extracted = [];
|
|
577
|
+
for (let i = 0; i < row.items.length; i++) {
|
|
578
|
+
const child = this.#child_box.children[row.from_index + i];
|
|
579
|
+
extracted.push(child);
|
|
580
|
+
child.remove();
|
|
581
|
+
}
|
|
582
|
+
const child = this.#child_box.children[row.to_index];
|
|
583
|
+
for (let i = 0; i < extracted.length; i++) if (child) child.before(extracted[i]);
|
|
584
|
+
else this.#child_box.append(extracted[i]);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
define_element(Container);
|
|
590
|
+
function container(columns, transform, rows, options) {
|
|
591
|
+
return new Container(columns, transform, rows, options);
|
|
592
|
+
}
|
|
593
|
+
// src/list/types.ts
|
|
594
|
+
/**Helper to create a column object */
|
|
595
|
+
function column(options) {
|
|
596
|
+
return options;
|
|
597
|
+
}
|
|
598
|
+
/**Special helper to create a string value column */
|
|
599
|
+
function column_string(title) {
|
|
600
|
+
return {
|
|
601
|
+
title,
|
|
602
|
+
field_gen: () => list.text_field(),
|
|
603
|
+
field_apply: (field, value) => field.text = value
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
// src/list/index.ts
|
|
607
|
+
const list = {
|
|
608
|
+
column,
|
|
609
|
+
column_string,
|
|
610
|
+
container,
|
|
611
|
+
text_field,
|
|
612
|
+
number_field,
|
|
613
|
+
node_field
|
|
614
|
+
};
|
|
615
|
+
export { ListField as n, list as t };
|
|
616
|
+
|
|
617
|
+
//# sourceMappingURL=list-BcNSxtNm.mjs.map
|