@chocbite/ts-lib-ui 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -1
- package/base/index.d.mts +2 -2
- package/base/index.mjs +69 -77
- package/base/index.mjs.map +1 -1
- package/canvas/index.d.mts +117 -60
- package/canvas/index.mjs +652 -584
- package/canvas/index.mjs.map +1 -1
- package/context-menu/index.d.mts +1 -1
- package/context-menu/index.mjs +1 -1
- package/{context-menu-CiNcuP-a.mjs → context-menu-Cz9rqUaM.mjs} +71 -37
- package/context-menu-Cz9rqUaM.mjs.map +1 -0
- package/document/index.mjs +3 -1
- package/document/index.mjs.map +1 -1
- package/form/index.d.mts +16 -5
- package/form/index.mjs +412 -153
- package/form/index.mjs.map +1 -1
- package/icons/index.d.mts +1 -1
- package/icons/index.mjs +1 -1
- package/icons-e2J_Ojic.mjs +4124 -0
- package/{index-BcidwqIy.d.mts → index-BDWg5GX2.d.mts} +7 -18
- package/{index-BND79jZp.d.mts → index-CvzH3M_5.d.mts} +16 -9
- package/{index-CugtUzv_.d.mts → index-DCn7acFY.d.mts} +30 -12
- package/{index-CB3-qP6l.d.mts → index-DhRb2iA8.d.mts} +7 -5
- package/keyboard/index.d.mts +1 -1
- package/keyboard/index.mjs +121 -50
- package/keyboard/index.mjs.map +1 -1
- package/list/index.d.mts +1 -1
- package/list/index.mjs +1 -1
- package/{list-CQDnxsLV.mjs → list-DXkEJKjx.mjs} +218 -117
- package/list-DXkEJKjx.mjs.map +1 -0
- package/package.json +7 -7
- package/selection/index.mjs +9 -11
- package/selection/index.mjs.map +1 -1
- package/settings/index.d.mts +23 -5
- package/settings/index.mjs +17 -10
- package/settings/index.mjs.map +1 -1
- package/spinner/index.d.mts +1 -1
- package/spinner/index.mjs +2 -2
- package/state/index.d.mts +36 -0
- package/state/index.mjs +2 -0
- package/state-OCzEmq3j.mjs +87 -0
- package/state-OCzEmq3j.mjs.map +1 -0
- package/style.css +423 -142
- package/svg/index.d.mts +1 -1
- package/svg/index.mjs +1 -1
- package/{svg-golJPaR4.mjs → svg-1bp-yIPC.mjs} +20 -17
- package/svg-1bp-yIPC.mjs.map +1 -0
- package/theme/index.d.mts +21 -2
- package/theme/index.mjs +1 -1
- package/{theme-9ib89_3b.mjs → theme-CFeGnUuF.mjs} +125 -44
- package/theme-CFeGnUuF.mjs.map +1 -0
- package/context-menu-CiNcuP-a.mjs.map +0 -1
- package/icons-CY4BLQ2F.mjs +0 -4123
- package/list-CQDnxsLV.mjs.map +0 -1
- package/svg-golJPaR4.mjs.map +0 -1
- package/theme-9ib89_3b.mjs.map +0 -1
- package/viewport/index.d.mts +0 -1
- package/viewport/index.mjs +0 -2
package/form/index.mjs
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import "../style.css";
|
|
2
2
|
import { AccessTypes, Base, define_element } from "../base/index.mjs";
|
|
3
|
-
import { c as
|
|
3
|
+
import { c as ANIMATION_SPEED, i as theme_init_variable_root, l as AnimationLevels, s as ANIMATION_LEVEL } from "../theme-CFeGnUuF.mjs";
|
|
4
4
|
import { node_clone } from "../dom/index.mjs";
|
|
5
|
-
import { B1 as material_remove_rounded, Fx as material_drag_handle_rounded, Qot as material_unfold_less_rounded, U2 as material_schedule_rounded, dn as material_add_rounded, est as material_unfold_more_rounded, if as material_calendar_month_rounded, xI as material_keyboard_arrow_down_rounded, xh as material_close_rounded } from "../icons-
|
|
6
|
-
import { n as ListField } from "../list-
|
|
5
|
+
import { B1 as material_remove_rounded, Fx as material_drag_handle_rounded, Qot as material_unfold_less_rounded, U2 as material_schedule_rounded, dn as material_add_rounded, est as material_unfold_more_rounded, if as material_calendar_month_rounded, xI as material_keyboard_arrow_down_rounded, xh as material_close_rounded } from "../icons-e2J_Ojic.mjs";
|
|
6
|
+
import { n as ListField } from "../list-DXkEJKjx.mjs";
|
|
7
7
|
import { get_cursor_position, set_cursor_end, set_cursor_position, set_selection_all } from "../selection/index.mjs";
|
|
8
|
+
import { DOCUMENT_HANDLER } from "../document/index.mjs";
|
|
8
9
|
import state from "@chocbite/ts-lib/state";
|
|
9
10
|
import { err, none, ok, some } from "@chocbite/ts-lib/result";
|
|
10
|
-
import { IPAddress, IPVersion, sleep, sync_resolve } from "@chocbite/ts-lib/common";
|
|
11
|
-
import { number_step_start_decimal } from "@chocbite/ts-lib/math";
|
|
12
11
|
import { BLUE, GREEN, GREY, ORANGE, RED, YELLOW } from "@chocbite/ts-lib/colors";
|
|
12
|
+
import { number_step_start_decimal } from "@chocbite/ts-lib/math";
|
|
13
|
+
import { IPAddress, IPVersion, sleep, sync_resolve } from "@chocbite/ts-lib/common";
|
|
13
14
|
import { string_byte_length, string_byte_limit } from "@chocbite/ts-lib/string";
|
|
14
15
|
// src/form/shared.ts
|
|
15
16
|
const theme_root = theme_init_variable_root("form", "UI Form Elements", "Theme variables for UI form Elements");
|
|
@@ -88,7 +89,7 @@ var FormValue = class extends FormElement {
|
|
|
88
89
|
}
|
|
89
90
|
static apply_options(element, options) {
|
|
90
91
|
if (options.description) element.description = options.description;
|
|
91
|
-
|
|
92
|
+
if (options.value !== void 0) element.value = options.value;
|
|
92
93
|
super.apply_options(element, options);
|
|
93
94
|
}
|
|
94
95
|
form_id;
|
|
@@ -97,9 +98,11 @@ var FormValue = class extends FormElement {
|
|
|
97
98
|
this.form_id = id;
|
|
98
99
|
}
|
|
99
100
|
_description;
|
|
100
|
-
/**Sets the
|
|
101
|
+
/**Sets the description of the element, shown as a tooltip*/
|
|
101
102
|
set description(text) {
|
|
102
103
|
this._description = text;
|
|
104
|
+
if (text) this.title = text;
|
|
105
|
+
else this.removeAttribute("title");
|
|
103
106
|
}
|
|
104
107
|
get description() {
|
|
105
108
|
return this._description || "";
|
|
@@ -111,16 +114,19 @@ var FormValue = class extends FormElement {
|
|
|
111
114
|
_state;
|
|
112
115
|
#func;
|
|
113
116
|
bind(opts) {
|
|
114
|
-
if (this.#func)
|
|
117
|
+
if (this.#func) {
|
|
118
|
+
this.detach_state(this.#func);
|
|
119
|
+
this.#func = void 0;
|
|
120
|
+
}
|
|
115
121
|
if (opts.value) {
|
|
116
|
-
|
|
122
|
+
const related = opts.value.related();
|
|
123
|
+
this.state_related(related.some ? related.value : {});
|
|
124
|
+
this.#func = this.attach_state(opts.value, (val) => {
|
|
117
125
|
if (val.ok) {
|
|
118
126
|
this.value = val.value;
|
|
119
127
|
if (this.#error) this.error = void 0;
|
|
120
128
|
} else this.error = val.error;
|
|
121
129
|
});
|
|
122
|
-
const related = opts.value.related();
|
|
123
|
-
if (related.some) this.state_related(related.value);
|
|
124
130
|
} else this.state_related({});
|
|
125
131
|
this._state = opts.value;
|
|
126
132
|
return this;
|
|
@@ -151,10 +157,11 @@ var FormValue = class extends FormElement {
|
|
|
151
157
|
this._buffer = void 0;
|
|
152
158
|
this.clear_value();
|
|
153
159
|
this.clear_error();
|
|
160
|
+
this.#error = false;
|
|
154
161
|
}
|
|
155
162
|
};
|
|
156
163
|
/**Shared class for all components with values*/
|
|
157
|
-
var FormValueWrite = class extends FormValue {
|
|
164
|
+
var FormValueWrite = class FormValueWrite extends FormValue {
|
|
158
165
|
static element_name() {
|
|
159
166
|
return "@abstract@";
|
|
160
167
|
}
|
|
@@ -204,12 +211,10 @@ var FormValueWrite = class extends FormValue {
|
|
|
204
211
|
else return sync_resolve(err("Not writable"));
|
|
205
212
|
} else return sync_resolve(ok(val));
|
|
206
213
|
}
|
|
207
|
-
/**Function to check value */
|
|
214
|
+
/**Function to check value, a state checks the value itself when it is written, so it is not checked here*/
|
|
208
215
|
check_value(val) {
|
|
209
|
-
if (this._state)
|
|
210
|
-
|
|
211
|
-
else return sync_resolve(err("Not writable"));
|
|
212
|
-
} else return sync_resolve(ok(val));
|
|
216
|
+
if (this._state && !this._state.writable) return sync_resolve(err("Not writable"));
|
|
217
|
+
return sync_resolve(ok(val));
|
|
213
218
|
}
|
|
214
219
|
/**Function to update value*/
|
|
215
220
|
async set_value_limit(val) {
|
|
@@ -218,8 +223,7 @@ var FormValueWrite = class extends FormValue {
|
|
|
218
223
|
this.warn(limited.error);
|
|
219
224
|
return limited;
|
|
220
225
|
}
|
|
221
|
-
this.#set_value(limited.value);
|
|
222
|
-
return limited;
|
|
226
|
+
return this.#set_value(limited.value);
|
|
223
227
|
}
|
|
224
228
|
/**Function to update value*/
|
|
225
229
|
async set_value_check(val) {
|
|
@@ -228,30 +232,40 @@ var FormValueWrite = class extends FormValue {
|
|
|
228
232
|
this.warn(checked.error);
|
|
229
233
|
return checked;
|
|
230
234
|
}
|
|
231
|
-
this.#set_value(checked.value);
|
|
232
|
-
return checked;
|
|
235
|
+
return this.#set_value(checked.value);
|
|
233
236
|
}
|
|
234
|
-
|
|
235
|
-
|
|
237
|
+
/**Shows the value and writes it to the state, a value the state rejects is reverted and warned about.
|
|
238
|
+
* The change listener is only called with accepted values*/
|
|
239
|
+
async #set_value(val) {
|
|
236
240
|
this.new_value(val);
|
|
241
|
+
if (this._buffer === val) return ok(val);
|
|
237
242
|
if (this._state) {
|
|
238
243
|
const buff = this._buffer;
|
|
239
|
-
this._state.write(val)
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
244
|
+
const written = await this._state.write(val);
|
|
245
|
+
if (written.err) {
|
|
246
|
+
if (buff !== void 0) this.new_value(buff);
|
|
247
|
+
this.warn(written.error);
|
|
248
|
+
return err(written.error);
|
|
249
|
+
}
|
|
245
250
|
} else {
|
|
246
251
|
this._buffer = val;
|
|
247
252
|
this.#changed = true;
|
|
248
253
|
}
|
|
254
|
+
this.call_change(val);
|
|
255
|
+
return ok(val);
|
|
256
|
+
}
|
|
257
|
+
/**Calls the change listener with a value the user changed, and lets a parent group know*/
|
|
258
|
+
call_change(val) {
|
|
249
259
|
if (this.#change) try {
|
|
250
260
|
this.#change(val);
|
|
251
261
|
} catch (e) {
|
|
252
262
|
console.error("Failed while updating change listener", e);
|
|
253
263
|
}
|
|
264
|
+
const parent = this.parentElement;
|
|
265
|
+
if (this.form_id !== void 0 && parent instanceof FormValueWrite) parent.child_changed(this);
|
|
254
266
|
}
|
|
267
|
+
/**Called when a child value element with a form id was changed by the user*/
|
|
268
|
+
child_changed(_child) {}
|
|
255
269
|
};
|
|
256
270
|
// src/form/boolean/button/button.ts
|
|
257
271
|
var FormButton = class extends FormValueWrite {
|
|
@@ -283,6 +297,13 @@ var FormButton = class extends FormValueWrite {
|
|
|
283
297
|
if (this.#toggle) this.set_value_check(!this.buffer);
|
|
284
298
|
else this.set_value_check(false);
|
|
285
299
|
this.onpointerup = null;
|
|
300
|
+
this.onpointercancel = null;
|
|
301
|
+
};
|
|
302
|
+
this.onpointercancel = (ev) => {
|
|
303
|
+
this.releasePointerCapture(ev.pointerId);
|
|
304
|
+
if (!this.#toggle) this.set_value_check(false);
|
|
305
|
+
this.onpointerup = null;
|
|
306
|
+
this.onpointercancel = null;
|
|
286
307
|
};
|
|
287
308
|
}
|
|
288
309
|
};
|
|
@@ -295,8 +316,14 @@ var FormButton = class extends FormValueWrite {
|
|
|
295
316
|
if (this.#toggle) this.set_value_check(!this.buffer);
|
|
296
317
|
else this.set_value_check(false);
|
|
297
318
|
this.ontouchend = null;
|
|
319
|
+
this.ontouchcancel = null;
|
|
298
320
|
}
|
|
299
321
|
};
|
|
322
|
+
this.ontouchcancel = () => {
|
|
323
|
+
if (!this.#toggle) this.set_value_check(false);
|
|
324
|
+
this.ontouchend = null;
|
|
325
|
+
this.ontouchcancel = null;
|
|
326
|
+
};
|
|
300
327
|
};
|
|
301
328
|
this.onkeydown = (e) => {
|
|
302
329
|
switch (e.key) {
|
|
@@ -311,11 +338,11 @@ var FormButton = class extends FormValueWrite {
|
|
|
311
338
|
case " ":
|
|
312
339
|
e.stopPropagation();
|
|
313
340
|
e.preventDefault();
|
|
341
|
+
this.onkeyup = null;
|
|
314
342
|
if (this.#toggle) this.set_value_check(!this.buffer);
|
|
315
343
|
else this.set_value_check(false);
|
|
316
344
|
if (this.#on_click) this.#on_click();
|
|
317
345
|
}
|
|
318
|
-
this.onkeyup = null;
|
|
319
346
|
};
|
|
320
347
|
}
|
|
321
348
|
};
|
|
@@ -332,11 +359,8 @@ var FormButton = class extends FormValueWrite {
|
|
|
332
359
|
}
|
|
333
360
|
/**Changes the icon of the button*/
|
|
334
361
|
set icon(icon) {
|
|
335
|
-
if (
|
|
336
|
-
|
|
337
|
-
this.removeChild(this.#icon);
|
|
338
|
-
this.#icon = void 0;
|
|
339
|
-
}
|
|
362
|
+
if (this.#icon) this.removeChild(this.#icon);
|
|
363
|
+
this.#icon = icon ? this.insertBefore(icon(), this.#text) : void 0;
|
|
340
364
|
}
|
|
341
365
|
/**Function to call on button click*/
|
|
342
366
|
set on_click(func) {
|
|
@@ -414,11 +438,8 @@ var FormLamp = class extends FormValue {
|
|
|
414
438
|
}
|
|
415
439
|
/**Changes the icon of the lamp*/
|
|
416
440
|
set icon(icon) {
|
|
417
|
-
if (
|
|
418
|
-
|
|
419
|
-
this.removeChild(this.#icon);
|
|
420
|
-
this.#icon = void 0;
|
|
421
|
-
}
|
|
441
|
+
if (this.#icon) this.removeChild(this.#icon);
|
|
442
|
+
this.#icon = icon ? this.insertBefore(icon(), this.#text) : void 0;
|
|
422
443
|
}
|
|
423
444
|
/** Sets the background color of the lamp*/
|
|
424
445
|
set colors(colors) {
|
|
@@ -489,9 +510,9 @@ var FormSwitch = class extends FormValueWrite {
|
|
|
489
510
|
case " ":
|
|
490
511
|
e.stopPropagation();
|
|
491
512
|
e.preventDefault();
|
|
513
|
+
this.onkeyup = null;
|
|
492
514
|
this.set_value_check(!this.buffer);
|
|
493
515
|
}
|
|
494
|
-
this.onkeyup = null;
|
|
495
516
|
};
|
|
496
517
|
}
|
|
497
518
|
};
|
|
@@ -511,14 +532,19 @@ var FormSwitch = class extends FormValueWrite {
|
|
|
511
532
|
} else if (this.buffer) this.set_value_check(false);
|
|
512
533
|
} else if (Math.abs(e.clientX - ev.clientX) > 10 || Math.abs(e.clientY - ev.clientY) > 10) has_moved = true;
|
|
513
534
|
};
|
|
514
|
-
|
|
515
|
-
ev.stopPropagation();
|
|
535
|
+
const release = () => {
|
|
516
536
|
this.#switch.classList.remove("active");
|
|
517
|
-
if (!has_moved) this.set_value_check(!this.buffer);
|
|
518
537
|
this.#switch.releasePointerCapture(e.pointerId);
|
|
519
538
|
this.#switch.onpointerup = null;
|
|
520
539
|
this.#switch.onpointermove = null;
|
|
540
|
+
this.#switch.onpointercancel = null;
|
|
541
|
+
};
|
|
542
|
+
this.#switch.onpointerup = (ev) => {
|
|
543
|
+
ev.stopPropagation();
|
|
544
|
+
release();
|
|
545
|
+
if (!has_moved) this.set_value_check(!this.buffer);
|
|
521
546
|
};
|
|
547
|
+
this.#switch.onpointercancel = release;
|
|
522
548
|
}
|
|
523
549
|
};
|
|
524
550
|
this.#switch.onclick = (e) => e.stopPropagation();
|
|
@@ -530,11 +556,8 @@ var FormSwitch = class extends FormValueWrite {
|
|
|
530
556
|
}
|
|
531
557
|
/**Changes the icon of the switch*/
|
|
532
558
|
set icon(icon) {
|
|
533
|
-
if (
|
|
534
|
-
|
|
535
|
-
this.removeChild(this.#icon);
|
|
536
|
-
this.#icon = void 0;
|
|
537
|
-
}
|
|
559
|
+
if (this.#icon) this.removeChild(this.#icon);
|
|
560
|
+
this.#icon = icon ? this.insertBefore(icon(), this.#switch) : void 0;
|
|
538
561
|
}
|
|
539
562
|
set on_color(color) {
|
|
540
563
|
if (color === FormColors.None) this.#switch.removeAttribute("on-color");
|
|
@@ -598,7 +621,7 @@ var FormGroupBase = class extends FormValueWrite {
|
|
|
598
621
|
}
|
|
599
622
|
/**This places the group at an absolute position in one of the corners of the container*/
|
|
600
623
|
set border(border) {
|
|
601
|
-
this.classList.remove(FormGroupBorderStyle.Inset, FormGroupBorderStyle.Outset);
|
|
624
|
+
this.classList.remove(FormGroupBorderStyle.Inset, FormGroupBorderStyle.Outset, FormGroupBorderStyle.Line);
|
|
602
625
|
if (border && border !== FormGroupBorderStyle.None) this.classList.add(border);
|
|
603
626
|
}
|
|
604
627
|
set max_height(height) {
|
|
@@ -627,13 +650,20 @@ var FormGroupBase = class extends FormValueWrite {
|
|
|
627
650
|
/**Returns partial value of the group, containing all values of components that have values*/
|
|
628
651
|
get value_partial() {
|
|
629
652
|
if (this._state) return err("State based component");
|
|
653
|
+
return ok(this.#partial());
|
|
654
|
+
}
|
|
655
|
+
#partial() {
|
|
630
656
|
const result = {};
|
|
631
657
|
for (const [key, comp] of this._value_elements) {
|
|
632
658
|
const val = comp.get_value;
|
|
633
659
|
if (val.err) continue;
|
|
634
660
|
result[key] = val.value;
|
|
635
661
|
}
|
|
636
|
-
return
|
|
662
|
+
return result;
|
|
663
|
+
}
|
|
664
|
+
/**The change listener of the group gets the values of all components that have values*/
|
|
665
|
+
child_changed(child) {
|
|
666
|
+
if (this._value_elements.get(child.form_id) === child) this.call_change(this.#partial());
|
|
637
667
|
}
|
|
638
668
|
/**Returns partial value of the group, only containing values of components where value has changed*/
|
|
639
669
|
get value_changed() {
|
|
@@ -700,6 +730,7 @@ var FormGroup = class extends FormGroupBase {
|
|
|
700
730
|
else this.style.gridTemplateRows = row.map((col) => "minmax(" + col + ", 1fr)").join(" ");
|
|
701
731
|
}
|
|
702
732
|
}
|
|
733
|
+
#elements = [];
|
|
703
734
|
set elements(elements) {
|
|
704
735
|
for (let i = 0, n = elements.length; i < n; i++) {
|
|
705
736
|
const comp = elements[i];
|
|
@@ -710,11 +741,12 @@ var FormGroup = class extends FormGroupBase {
|
|
|
710
741
|
}
|
|
711
742
|
this._value_elements.set(comp.form_id, comp);
|
|
712
743
|
}
|
|
713
|
-
this.appendChild(comp);
|
|
744
|
+
this.#elements.push(this.appendChild(comp));
|
|
714
745
|
}
|
|
715
746
|
}
|
|
747
|
+
/**All elements added to the group, also those without a form id*/
|
|
716
748
|
get elements() {
|
|
717
|
-
return [...this
|
|
749
|
+
return [...this.#elements];
|
|
718
750
|
}
|
|
719
751
|
};
|
|
720
752
|
define_element(FormGroup);
|
|
@@ -748,6 +780,8 @@ var FormGroupCollapser = class extends FormElement {
|
|
|
748
780
|
#group;
|
|
749
781
|
#collapse_button;
|
|
750
782
|
#collapsed = false;
|
|
783
|
+
/**Running collapse or open animation, cancelled when the other one starts*/
|
|
784
|
+
#animation;
|
|
751
785
|
#open_text = node_clone(opened_text);
|
|
752
786
|
#close_text = node_clone(closed_text);
|
|
753
787
|
constructor(group, collapsed) {
|
|
@@ -760,7 +794,7 @@ var FormGroupCollapser = class extends FormElement {
|
|
|
760
794
|
this.#collapse_button = this.appendChild(document.createElement("span"));
|
|
761
795
|
this.#collapse_button.tabIndex = 0;
|
|
762
796
|
this.#collapse_button.appendChild(collapsed ? this.#close_text : this.#open_text);
|
|
763
|
-
this.#collapse_button.appendChild(material_unfold_less_rounded());
|
|
797
|
+
this.#collapse_button.appendChild(collapsed ? material_unfold_more_rounded() : material_unfold_less_rounded());
|
|
764
798
|
this.#collapse_button.onclick = () => this.collapsed = !this.collapsed;
|
|
765
799
|
this.#collapse_button.onkeydown = (e) => {
|
|
766
800
|
if (e.key === "Enter" || e.key === " ") {
|
|
@@ -770,44 +804,46 @@ var FormGroupCollapser = class extends FormElement {
|
|
|
770
804
|
};
|
|
771
805
|
}
|
|
772
806
|
set group(group) {
|
|
773
|
-
|
|
774
|
-
this.#group =
|
|
807
|
+
this.replaceChild(group, this.#group);
|
|
808
|
+
this.#group = group;
|
|
775
809
|
}
|
|
776
810
|
get group() {
|
|
777
811
|
return this.#group;
|
|
778
812
|
}
|
|
779
813
|
set collapsed(collapsed) {
|
|
780
814
|
if (collapsed && !this.#collapsed) {
|
|
815
|
+
this.#animation?.cancel();
|
|
781
816
|
this.#collapse_button.replaceChildren(this.#close_text, material_unfold_more_rounded());
|
|
782
817
|
if (ANIMATION_LEVEL.get().value === AnimationLevels.All) {
|
|
783
818
|
this.#group.style.overflowY = "auto";
|
|
784
819
|
const full_height = this.#group.getBoundingClientRect().height + "px";
|
|
785
|
-
|
|
820
|
+
this.#animation = this.#group.animate([{ maxHeight: full_height }, {
|
|
786
821
|
maxHeight: "0px",
|
|
787
822
|
paddingBlock: "0px"
|
|
788
823
|
}], {
|
|
789
824
|
duration: ANIMATION_SPEED.get().value,
|
|
790
825
|
easing: "ease-in-out"
|
|
791
826
|
});
|
|
792
|
-
animation.onfinish =
|
|
827
|
+
this.#animation.onfinish = () => {
|
|
793
828
|
this.classList.add("collapsed");
|
|
794
829
|
this.#group.style.overflowY = "";
|
|
795
830
|
};
|
|
796
831
|
} else this.classList.add("collapsed");
|
|
797
832
|
} else if (!collapsed && this.#collapsed) {
|
|
833
|
+
this.#animation?.cancel();
|
|
798
834
|
this.classList.remove("collapsed");
|
|
799
835
|
this.#collapse_button.replaceChildren(this.#open_text, material_unfold_less_rounded());
|
|
800
836
|
if (ANIMATION_LEVEL.get().value === AnimationLevels.All) {
|
|
801
837
|
this.#group.style.overflowY = "auto";
|
|
802
838
|
const full_height = this.#group.getBoundingClientRect().height + "px";
|
|
803
|
-
|
|
839
|
+
this.#animation = this.#group.animate([{
|
|
804
840
|
maxHeight: "0px",
|
|
805
841
|
paddingBlock: "0px"
|
|
806
842
|
}, { maxHeight: full_height }], {
|
|
807
843
|
duration: ANIMATION_SPEED.get().value,
|
|
808
844
|
easing: "ease-in-out"
|
|
809
845
|
});
|
|
810
|
-
animation.onfinish = () => this.#group.style.overflowY = "";
|
|
846
|
+
this.#animation.onfinish = () => this.#group.style.overflowY = "";
|
|
811
847
|
}
|
|
812
848
|
}
|
|
813
849
|
this.#collapsed = collapsed;
|
|
@@ -865,21 +901,35 @@ var FormNumberWrite = class extends FormValueWrite {
|
|
|
865
901
|
if (options.start) element.start = options.start;
|
|
866
902
|
super.apply_options(element, options);
|
|
867
903
|
}
|
|
904
|
+
/**Related states of the last bound state, a prop is only reset when it followed one of them*/
|
|
905
|
+
#related = {};
|
|
868
906
|
state_related(related) {
|
|
907
|
+
const old = this.#related;
|
|
908
|
+
this.#related = related;
|
|
869
909
|
if (related.min) this.attach_state_to_prop("min", related.min, () => none());
|
|
870
|
-
else this.detach_state_from_prop("min");
|
|
910
|
+
else if (old.min) this.detach_state_from_prop("min").min = void 0;
|
|
871
911
|
if (related.max) this.attach_state_to_prop("max", related.max, () => none());
|
|
872
|
-
else this.detach_state_from_prop("max");
|
|
912
|
+
else if (old.max) this.detach_state_from_prop("max").max = void 0;
|
|
873
913
|
if (related.step) this.attach_state_to_prop("step", related.step, () => none());
|
|
874
|
-
else this.detach_state_from_prop("step");
|
|
914
|
+
else if (old.step) this.detach_state_from_prop("step").step = void 0;
|
|
875
915
|
if (related.start) this.attach_state_to_prop("start", related.start, () => none());
|
|
876
|
-
else this.detach_state_from_prop("start");
|
|
916
|
+
else if (old.start) this.detach_state_from_prop("start").start = void 0;
|
|
877
917
|
if (related.decimals) this.attach_state_to_prop("decimals", related.decimals, () => none());
|
|
878
|
-
else this.detach_state_from_prop("decimals");
|
|
918
|
+
else if (old.decimals) this.detach_state_from_prop("decimals").decimals = void 0;
|
|
879
919
|
if (related.unit) this.attach_state_to_prop("unit", related.unit, () => none());
|
|
880
|
-
else this.detach_state_from_prop("unit");
|
|
920
|
+
else if (old.unit) this.detach_state_from_prop("unit").unit = void 0;
|
|
881
921
|
}
|
|
882
922
|
};
|
|
923
|
+
/**Decimals to show and round to, the given decimals, or without them enough for the step and start*/
|
|
924
|
+
function number_decimals(decimals, step, start) {
|
|
925
|
+
return decimals ?? Math.max(fraction_digits(step), fraction_digits(start));
|
|
926
|
+
}
|
|
927
|
+
/**Amount of decimals needed to show a number, at most 10*/
|
|
928
|
+
function fraction_digits(val) {
|
|
929
|
+
let dec = 0;
|
|
930
|
+
for (let scaled = val; dec < 10; dec++, scaled = val * 10 ** dec) if (Math.abs(scaled - Math.round(scaled)) < 1e-9) break;
|
|
931
|
+
return dec;
|
|
932
|
+
}
|
|
883
933
|
// src/form/number/number_input/number_input.ts
|
|
884
934
|
var FormNumberInput = class extends FormNumberWrite {
|
|
885
935
|
static element_name() {
|
|
@@ -893,7 +943,11 @@ var FormNumberInput = class extends FormNumberWrite {
|
|
|
893
943
|
#max = Infinity;
|
|
894
944
|
#step = 0;
|
|
895
945
|
#start = 0;
|
|
946
|
+
#decimals_set;
|
|
896
947
|
#decimals = 0;
|
|
948
|
+
/**Text last drawn from a value, and whether the user typed since*/
|
|
949
|
+
#shown = "";
|
|
950
|
+
#edited = false;
|
|
897
951
|
#value_box = this.appendChild(document.createElement("span"));
|
|
898
952
|
#unit_box = this.appendChild(document.createElement("span"));
|
|
899
953
|
#legend = this.appendChild(document.createElement("div"));
|
|
@@ -922,6 +976,7 @@ var FormNumberInput = class extends FormNumberWrite {
|
|
|
922
976
|
this.#set(false);
|
|
923
977
|
}, 0);
|
|
924
978
|
};
|
|
979
|
+
this.#value_box.oninput = () => this.#edited = true;
|
|
925
980
|
this.onkeydown = (e) => {
|
|
926
981
|
if (e.key === "Enter") this.#set(true);
|
|
927
982
|
else if (e.key === "Escape") {
|
|
@@ -943,9 +998,15 @@ var FormNumberInput = class extends FormNumberWrite {
|
|
|
943
998
|
};
|
|
944
999
|
}
|
|
945
1000
|
async #set(cur) {
|
|
1001
|
+
const text = this.#value_box.textContent || "";
|
|
1002
|
+
if (!this.#edited && text === this.#shown) {
|
|
1003
|
+
const shown = this.buffer?.toFixed(this.#decimals);
|
|
1004
|
+
if (shown !== void 0 && shown !== text) this.new_value(this.buffer);
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
946
1007
|
const sel = get_cursor_position(this.#value_box);
|
|
947
1008
|
const buff = this.buffer;
|
|
948
|
-
(await this.set_value_check(parseFloat(
|
|
1009
|
+
(await this.set_value_check(parseFloat(text.replace(",", ".")) || 0)).map_err(() => {
|
|
949
1010
|
this.new_value(buff || Math.max(Math.min(0, this.#max), this.#min));
|
|
950
1011
|
set_cursor_end(this.#value_box);
|
|
951
1012
|
}).map(() => {
|
|
@@ -961,9 +1022,17 @@ var FormNumberInput = class extends FormNumberWrite {
|
|
|
961
1022
|
this.#unit_box.textContent = this.#unit;
|
|
962
1023
|
}
|
|
963
1024
|
set decimals(dec) {
|
|
964
|
-
this.#
|
|
1025
|
+
this.#decimals_set = dec;
|
|
1026
|
+
this.#update_decimals();
|
|
1027
|
+
}
|
|
1028
|
+
/**Updates the decimals from the set decimals, step and start, and redraws with them*/
|
|
1029
|
+
#update_decimals() {
|
|
1030
|
+
const dec = number_decimals(this.#decimals_set, this.#step, this.#start);
|
|
1031
|
+
if (dec === this.#decimals) return;
|
|
1032
|
+
this.#decimals = dec;
|
|
965
1033
|
this.#update_min_legend();
|
|
966
1034
|
this.#update_max_lengend();
|
|
1035
|
+
if (this.buffer !== void 0 && !this.selected) this.new_value(this.buffer);
|
|
967
1036
|
}
|
|
968
1037
|
set min(min) {
|
|
969
1038
|
this.#min = min ?? -Infinity;
|
|
@@ -981,15 +1050,19 @@ var FormNumberInput = class extends FormNumberWrite {
|
|
|
981
1050
|
}
|
|
982
1051
|
set step(step) {
|
|
983
1052
|
this.#step = step || 0;
|
|
1053
|
+
this.#update_decimals();
|
|
984
1054
|
}
|
|
985
1055
|
set start(step) {
|
|
986
1056
|
this.#start = step || 0;
|
|
1057
|
+
this.#update_decimals();
|
|
987
1058
|
}
|
|
988
1059
|
new_value(val) {
|
|
989
|
-
this.#value_box.textContent = val.toFixed(this.#decimals);
|
|
1060
|
+
this.#value_box.textContent = this.#shown = val.toFixed(this.#decimals);
|
|
1061
|
+
this.#edited = false;
|
|
990
1062
|
}
|
|
991
1063
|
clear_value() {
|
|
992
|
-
this.#value_box.textContent = "";
|
|
1064
|
+
this.#value_box.textContent = this.#shown = "";
|
|
1065
|
+
this.#edited = false;
|
|
993
1066
|
}
|
|
994
1067
|
new_error(_val) {}
|
|
995
1068
|
clear_error() {}
|
|
@@ -1008,7 +1081,7 @@ var FormNumberInput = class extends FormNumberWrite {
|
|
|
1008
1081
|
return super.check_value(lim);
|
|
1009
1082
|
}
|
|
1010
1083
|
#step_value(dir) {
|
|
1011
|
-
const step = this.#step || Math.max(this.#decimals ?
|
|
1084
|
+
const step = this.#step || Math.max(this.#decimals ? 10 ** -this.#decimals : 1, Math.floor(Math.abs(this.buffer || 0) / 150));
|
|
1012
1085
|
return this.set_value_check((this.buffer || 0) + (dir ? step : -step));
|
|
1013
1086
|
}
|
|
1014
1087
|
};
|
|
@@ -1038,20 +1111,27 @@ var FormProgress = class extends FormValue {
|
|
|
1038
1111
|
set min(min) {
|
|
1039
1112
|
this.#min = min;
|
|
1040
1113
|
this.#span = this.#max - this.#min;
|
|
1114
|
+
this.#redraw();
|
|
1041
1115
|
}
|
|
1042
1116
|
/**Set the minimum value*/
|
|
1043
1117
|
set max(max) {
|
|
1044
1118
|
this.#max = max;
|
|
1045
1119
|
this.#span = this.#max - this.#min;
|
|
1120
|
+
this.#redraw();
|
|
1046
1121
|
}
|
|
1047
1122
|
/**Sets the amount of decimals the element can have*/
|
|
1048
1123
|
set decimals(dec) {
|
|
1049
1124
|
this.#decimals = Math.max(dec ?? 0, 0);
|
|
1125
|
+
this.#redraw();
|
|
1050
1126
|
}
|
|
1051
1127
|
/**Sets the unit of the element*/
|
|
1052
1128
|
set unit(unit) {
|
|
1053
1129
|
this.#unit.textContent = unit ?? "";
|
|
1054
1130
|
}
|
|
1131
|
+
/**Shows the value again, after a change to how it is shown*/
|
|
1132
|
+
#redraw() {
|
|
1133
|
+
if (this._buffer !== void 0) this.new_value(this._buffer);
|
|
1134
|
+
}
|
|
1055
1135
|
new_value(value) {
|
|
1056
1136
|
this.#bar.style.width = Math.min(Math.max((value - this.#min) / this.#span * 100, 0), 100) + "%";
|
|
1057
1137
|
this.#val.textContent = value.toFixed(this.#decimals);
|
|
@@ -1064,15 +1144,19 @@ var FormProgress = class extends FormValue {
|
|
|
1064
1144
|
console.error(err);
|
|
1065
1145
|
}
|
|
1066
1146
|
clear_error() {}
|
|
1147
|
+
/**Related states of the last bound state, a prop is only reset when it followed one of them*/
|
|
1148
|
+
#related = {};
|
|
1067
1149
|
state_related(related) {
|
|
1150
|
+
const old = this.#related;
|
|
1151
|
+
this.#related = related;
|
|
1068
1152
|
if (related.min) this.attach_state_to_prop("min", related.min, () => none());
|
|
1069
|
-
else this.detach_state_from_prop("min");
|
|
1153
|
+
else if (old.min) this.detach_state_from_prop("min").min = 0;
|
|
1070
1154
|
if (related.max) this.attach_state_to_prop("max", related.max, () => none());
|
|
1071
|
-
else this.detach_state_from_prop("max");
|
|
1155
|
+
else if (old.max) this.detach_state_from_prop("max").max = 100;
|
|
1072
1156
|
if (related.decimals) this.attach_state_to_prop("decimals", related.decimals, () => none());
|
|
1073
|
-
else this.detach_state_from_prop("decimals");
|
|
1157
|
+
else if (old.decimals) this.detach_state_from_prop("decimals").decimals = void 0;
|
|
1074
1158
|
if (related.unit) this.attach_state_to_prop("unit", related.unit, () => none());
|
|
1075
|
-
else this.detach_state_from_prop("unit");
|
|
1159
|
+
else if (old.unit) this.detach_state_from_prop("unit").unit = void 0;
|
|
1076
1160
|
}
|
|
1077
1161
|
};
|
|
1078
1162
|
define_element(FormProgress);
|
|
@@ -1098,6 +1182,7 @@ var FormSlider = class extends FormNumberWrite {
|
|
|
1098
1182
|
return "form";
|
|
1099
1183
|
}
|
|
1100
1184
|
#unit = "";
|
|
1185
|
+
#decimals_set;
|
|
1101
1186
|
#decimals = 0;
|
|
1102
1187
|
#min = -Infinity;
|
|
1103
1188
|
#max = Infinity;
|
|
@@ -1151,6 +1236,8 @@ var FormSlider = class extends FormNumberWrite {
|
|
|
1151
1236
|
this.#slider.releasePointerCapture(e.pointerId);
|
|
1152
1237
|
this.#slider.onpointermove = null;
|
|
1153
1238
|
this.#slider.onpointerup = null;
|
|
1239
|
+
this.#slider.onpointercancel = null;
|
|
1240
|
+
this.#slider.onkeydown = null;
|
|
1154
1241
|
this.#move_slide(50);
|
|
1155
1242
|
clearInterval(interval);
|
|
1156
1243
|
};
|
|
@@ -1159,6 +1246,11 @@ var FormSlider = class extends FormNumberWrite {
|
|
|
1159
1246
|
reset();
|
|
1160
1247
|
if (!this.#live) this.set_value_limit(value);
|
|
1161
1248
|
};
|
|
1249
|
+
this.#slider.onpointercancel = () => {
|
|
1250
|
+
reset();
|
|
1251
|
+
if (this.buffer !== void 0) this.new_value(this.buffer);
|
|
1252
|
+
else this.clear_value();
|
|
1253
|
+
};
|
|
1162
1254
|
this.#slider.onkeydown = (e) => {
|
|
1163
1255
|
if (e.key === "Escape") {
|
|
1164
1256
|
e.preventDefault();
|
|
@@ -1182,12 +1274,19 @@ var FormSlider = class extends FormNumberWrite {
|
|
|
1182
1274
|
this.#slider.releasePointerCapture(e.pointerId);
|
|
1183
1275
|
this.#slider.onpointermove = null;
|
|
1184
1276
|
this.#slider.onpointerup = null;
|
|
1277
|
+
this.#slider.onpointercancel = null;
|
|
1278
|
+
this.#slider.onkeydown = null;
|
|
1185
1279
|
};
|
|
1186
1280
|
this.#slider.onpointerup = (ev) => {
|
|
1187
1281
|
ev.stopPropagation();
|
|
1188
1282
|
reset();
|
|
1189
1283
|
this.#move_absolute(ev.clientX + offset, value);
|
|
1190
1284
|
};
|
|
1285
|
+
this.#slider.onpointercancel = () => {
|
|
1286
|
+
reset();
|
|
1287
|
+
if (this.buffer !== void 0) this.new_value(this.buffer);
|
|
1288
|
+
else this.clear_value();
|
|
1289
|
+
};
|
|
1191
1290
|
this.#slider.onkeydown = (e) => {
|
|
1192
1291
|
if (e.key === "Escape") {
|
|
1193
1292
|
e.preventDefault();
|
|
@@ -1236,29 +1335,43 @@ var FormSlider = class extends FormNumberWrite {
|
|
|
1236
1335
|
else if (this.buffer !== void 0) this.new_value(this.buffer);
|
|
1237
1336
|
}
|
|
1238
1337
|
set decimals(dec) {
|
|
1239
|
-
this.#
|
|
1240
|
-
this.#
|
|
1241
|
-
this.#update_max_legend();
|
|
1338
|
+
this.#decimals_set = dec;
|
|
1339
|
+
this.#update_decimals();
|
|
1242
1340
|
}
|
|
1243
1341
|
set step(step) {
|
|
1244
1342
|
this.#step = step || 0;
|
|
1343
|
+
this.#update_decimals();
|
|
1245
1344
|
}
|
|
1246
1345
|
set start(step) {
|
|
1247
1346
|
this.#start = step || 0;
|
|
1347
|
+
this.#update_decimals();
|
|
1348
|
+
}
|
|
1349
|
+
/**Updates the decimals from the set decimals, step and start, and redraws with them*/
|
|
1350
|
+
#update_decimals() {
|
|
1351
|
+
const dec = number_decimals(this.#decimals_set, this.#step, this.#start);
|
|
1352
|
+
if (dec === this.#decimals) return;
|
|
1353
|
+
this.#decimals = dec;
|
|
1354
|
+
this.#update_min_legend();
|
|
1355
|
+
this.#update_max_legend();
|
|
1356
|
+
if (this.buffer !== void 0 && !this.selected) this.new_value(this.buffer);
|
|
1248
1357
|
}
|
|
1249
1358
|
/**Set wether the slider is in live mode*/
|
|
1250
1359
|
set live(live) {
|
|
1251
1360
|
this.#live = live || false;
|
|
1252
1361
|
}
|
|
1253
1362
|
set icon_decrease(icon) {
|
|
1254
|
-
this
|
|
1363
|
+
const old = this.#icon_dec;
|
|
1364
|
+
this.#icon_dec = this.#stepper_func(icon ? icon() : material_remove_rounded(), false);
|
|
1365
|
+
this.replaceChild(this.#icon_dec, old);
|
|
1255
1366
|
}
|
|
1256
1367
|
set icon_increase(icon) {
|
|
1257
|
-
this
|
|
1368
|
+
const old = this.#icon_inc;
|
|
1369
|
+
this.#icon_inc = this.#stepper_func(icon ? icon() : material_add_rounded(), true);
|
|
1370
|
+
this.replaceChild(this.#icon_inc, old);
|
|
1258
1371
|
}
|
|
1259
1372
|
new_value(value) {
|
|
1260
1373
|
this.#move_value(value);
|
|
1261
|
-
this.#move_slide(Math.min(Math.max((-this.#min + value) / this.#span * 100, 0), 100));
|
|
1374
|
+
this.#move_slide(this.#span === Infinity ? 50 : Math.min(Math.max((-this.#min + value) / this.#span * 100, 0), 100));
|
|
1262
1375
|
}
|
|
1263
1376
|
clear_value() {
|
|
1264
1377
|
this.#value_box.textContent = "";
|
|
@@ -1313,6 +1426,7 @@ var FormSlider = class extends FormNumberWrite {
|
|
|
1313
1426
|
clearInterval(scaler_interval);
|
|
1314
1427
|
clearTimeout(timeout);
|
|
1315
1428
|
icon.onpointerup = null;
|
|
1429
|
+
icon.onpointercancel = null;
|
|
1316
1430
|
icon.releasePointerCapture(e.pointerId);
|
|
1317
1431
|
icon.classList.remove("active");
|
|
1318
1432
|
};
|
|
@@ -1331,12 +1445,13 @@ var FormSlider = class extends FormNumberWrite {
|
|
|
1331
1445
|
if (interval === 0) this.#step_value(dir);
|
|
1332
1446
|
release();
|
|
1333
1447
|
};
|
|
1448
|
+
icon.onpointercancel = release;
|
|
1334
1449
|
}
|
|
1335
1450
|
};
|
|
1336
1451
|
return icon;
|
|
1337
1452
|
}
|
|
1338
1453
|
#step_value(dir) {
|
|
1339
|
-
const step = this.#step || Math.max(this.#decimals ?
|
|
1454
|
+
const step = this.#step || Math.max(this.#decimals ? 10 ** -this.#decimals : 1, Math.floor(Math.abs(this.buffer || 0) / 150));
|
|
1340
1455
|
return this.set_value_check((this.buffer || 0) + (dir ? step : -step));
|
|
1341
1456
|
}
|
|
1342
1457
|
#move_slide(perc) {
|
|
@@ -1368,7 +1483,11 @@ var FormStepper = class extends FormNumberWrite {
|
|
|
1368
1483
|
return "form";
|
|
1369
1484
|
}
|
|
1370
1485
|
#unit = "";
|
|
1486
|
+
#decimals_set;
|
|
1371
1487
|
#decimals = 0;
|
|
1488
|
+
/**Text last drawn from a value, and whether the user typed since*/
|
|
1489
|
+
#shown = "";
|
|
1490
|
+
#edited = false;
|
|
1372
1491
|
#min = -Infinity;
|
|
1373
1492
|
#max = Infinity;
|
|
1374
1493
|
#step = 0;
|
|
@@ -1394,8 +1513,12 @@ var FormStepper = class extends FormNumberWrite {
|
|
|
1394
1513
|
this.#value_box.onblur = async () => {
|
|
1395
1514
|
this.selected = false;
|
|
1396
1515
|
await sleep(0);
|
|
1397
|
-
this
|
|
1516
|
+
const text = this.#value_box.textContent || "";
|
|
1517
|
+
if (!this.#edited && text === this.#shown) {
|
|
1518
|
+
if (this.buffer !== void 0) this.new_value(this.buffer);
|
|
1519
|
+
} else this.set_value_check(parseFloat(text.replace(",", ".")) || 0);
|
|
1398
1520
|
};
|
|
1521
|
+
this.#value_box.oninput = () => this.#edited = true;
|
|
1399
1522
|
this.#value_box.onpointerdown = () => {
|
|
1400
1523
|
this.selected = true;
|
|
1401
1524
|
};
|
|
@@ -1403,9 +1526,13 @@ var FormStepper = class extends FormNumberWrite {
|
|
|
1403
1526
|
const reset = () => {
|
|
1404
1527
|
this.selected = false;
|
|
1405
1528
|
this.#value_box.contentEditable = "true";
|
|
1406
|
-
if (pointer_id)
|
|
1529
|
+
if (pointer_id !== void 0) {
|
|
1530
|
+
this.#text.releasePointerCapture(pointer_id);
|
|
1531
|
+
pointer_id = void 0;
|
|
1532
|
+
}
|
|
1407
1533
|
this.#text.onpointermove = null;
|
|
1408
1534
|
this.#text.onpointerup = null;
|
|
1535
|
+
this.#text.onpointercancel = null;
|
|
1409
1536
|
};
|
|
1410
1537
|
this.#text.onpointerdown = (e) => {
|
|
1411
1538
|
if (e.button === 0 && !this.selected) {
|
|
@@ -1426,20 +1553,17 @@ var FormStepper = class extends FormNumberWrite {
|
|
|
1426
1553
|
this.#text.onpointerup = (ev) => {
|
|
1427
1554
|
ev.stopPropagation();
|
|
1428
1555
|
reset();
|
|
1429
|
-
if (!moving && e.target !== this.#value_box)
|
|
1430
|
-
|
|
1431
|
-
const range = document.createRange();
|
|
1432
|
-
range.setStartAfter(this.#value_box.firstChild);
|
|
1433
|
-
const selection = this.ownerDocument?.defaultView?.getSelection();
|
|
1434
|
-
if (selection) {
|
|
1435
|
-
selection.removeAllRanges();
|
|
1436
|
-
selection.addRange(range);
|
|
1437
|
-
}
|
|
1438
|
-
} else if (moving) {
|
|
1556
|
+
if (!moving && e.target !== this.#value_box) set_cursor_end(this.#value_box);
|
|
1557
|
+
else if (moving) {
|
|
1439
1558
|
this.#move_diff(initial_val + (ev.clientX - e.clientX) / 10 * (this.#step || 1), true);
|
|
1440
1559
|
moving = false;
|
|
1441
1560
|
}
|
|
1442
1561
|
};
|
|
1562
|
+
this.#text.onpointercancel = () => {
|
|
1563
|
+
reset();
|
|
1564
|
+
if (this.buffer !== void 0) this.new_value(this.buffer);
|
|
1565
|
+
else this.clear_value();
|
|
1566
|
+
};
|
|
1443
1567
|
}
|
|
1444
1568
|
};
|
|
1445
1569
|
this.onkeydown = (e) => {
|
|
@@ -1472,7 +1596,7 @@ var FormStepper = class extends FormNumberWrite {
|
|
|
1472
1596
|
if (e.data) {
|
|
1473
1597
|
if (!/[\d,.-]/g.test(e.data)) e.preventDefault();
|
|
1474
1598
|
else if (/[,.]/g.test(e.data) && this.#decimals === 0) e.preventDefault();
|
|
1475
|
-
else if (
|
|
1599
|
+
else if (/-/g.test(e.data) && (this.#min >= 0 || this.#value_box.textContent?.includes("-"))) e.preventDefault();
|
|
1476
1600
|
}
|
|
1477
1601
|
};
|
|
1478
1602
|
}
|
|
@@ -1484,9 +1608,17 @@ var FormStepper = class extends FormNumberWrite {
|
|
|
1484
1608
|
this.#unit_box.textContent = this.#unit;
|
|
1485
1609
|
}
|
|
1486
1610
|
set decimals(dec) {
|
|
1487
|
-
this.#
|
|
1611
|
+
this.#decimals_set = dec;
|
|
1612
|
+
this.#update_decimals();
|
|
1613
|
+
}
|
|
1614
|
+
/**Updates the decimals from the set decimals, step and start, and redraws with them*/
|
|
1615
|
+
#update_decimals() {
|
|
1616
|
+
const dec = number_decimals(this.#decimals_set, this.#step, this.#start);
|
|
1617
|
+
if (dec === this.#decimals) return;
|
|
1618
|
+
this.#decimals = dec;
|
|
1488
1619
|
this.#update_min_legend();
|
|
1489
1620
|
this.#update_max_lengend();
|
|
1621
|
+
if (this.buffer !== void 0 && !this.selected) this.new_value(this.buffer);
|
|
1490
1622
|
}
|
|
1491
1623
|
set min(min) {
|
|
1492
1624
|
this.#min = min ?? -Infinity;
|
|
@@ -1504,25 +1636,33 @@ var FormStepper = class extends FormNumberWrite {
|
|
|
1504
1636
|
}
|
|
1505
1637
|
set step(step) {
|
|
1506
1638
|
this.#step = step || 0;
|
|
1639
|
+
this.#update_decimals();
|
|
1507
1640
|
}
|
|
1508
1641
|
set start(step) {
|
|
1509
1642
|
this.#start = step || 0;
|
|
1643
|
+
this.#update_decimals();
|
|
1510
1644
|
}
|
|
1511
1645
|
/**Set wether the slider is in live mode*/
|
|
1512
1646
|
set live(live) {
|
|
1513
1647
|
this.#live = live || false;
|
|
1514
1648
|
}
|
|
1515
1649
|
set icon_decrease(icon) {
|
|
1516
|
-
this
|
|
1650
|
+
const old = this.#icon_dec;
|
|
1651
|
+
this.#icon_dec = this.#stepper_func(icon ? icon() : material_remove_rounded(), false);
|
|
1652
|
+
this.replaceChild(this.#icon_dec, old);
|
|
1517
1653
|
}
|
|
1518
1654
|
set icon_increase(icon) {
|
|
1519
|
-
this
|
|
1655
|
+
const old = this.#icon_inc;
|
|
1656
|
+
this.#icon_inc = this.#stepper_func(icon ? icon() : material_add_rounded(), true);
|
|
1657
|
+
this.replaceChild(this.#icon_inc, old);
|
|
1520
1658
|
}
|
|
1521
1659
|
new_value(value) {
|
|
1522
|
-
this.#
|
|
1660
|
+
this.#value_box.textContent = this.#shown = value.toFixed(this.#decimals);
|
|
1661
|
+
this.#edited = false;
|
|
1523
1662
|
}
|
|
1524
1663
|
clear_value() {
|
|
1525
|
-
this.#value_box.textContent = "";
|
|
1664
|
+
this.#value_box.textContent = this.#shown = "";
|
|
1665
|
+
this.#edited = false;
|
|
1526
1666
|
}
|
|
1527
1667
|
new_error(err) {
|
|
1528
1668
|
console.error(err);
|
|
@@ -1568,6 +1708,7 @@ var FormStepper = class extends FormNumberWrite {
|
|
|
1568
1708
|
clearInterval(scaler_interval);
|
|
1569
1709
|
clearTimeout(timeout);
|
|
1570
1710
|
icon.onpointerup = null;
|
|
1711
|
+
icon.onpointercancel = null;
|
|
1571
1712
|
icon.releasePointerCapture(e.pointerId);
|
|
1572
1713
|
icon.classList.remove("active");
|
|
1573
1714
|
};
|
|
@@ -1586,12 +1727,13 @@ var FormStepper = class extends FormNumberWrite {
|
|
|
1586
1727
|
if (interval === 0) this.#step_value(dir);
|
|
1587
1728
|
release();
|
|
1588
1729
|
};
|
|
1730
|
+
icon.onpointercancel = release;
|
|
1589
1731
|
}
|
|
1590
1732
|
};
|
|
1591
1733
|
return icon;
|
|
1592
1734
|
}
|
|
1593
1735
|
#step_value(dir) {
|
|
1594
|
-
const step = this.#step || Math.max(this.#decimals ?
|
|
1736
|
+
const step = this.#step || Math.max(this.#decimals ? 10 ** -this.#decimals : 1, Math.floor(Math.abs(this.buffer || 0) / 150));
|
|
1595
1737
|
return this.set_value_check((this.buffer || 0) + (dir ? step : -step));
|
|
1596
1738
|
}
|
|
1597
1739
|
};
|
|
@@ -1614,6 +1756,7 @@ var FormSelectorBase = class extends FormValueWrite {
|
|
|
1614
1756
|
if (options.selections) element.selections = options.selections;
|
|
1615
1757
|
super.apply_options(element, options);
|
|
1616
1758
|
}
|
|
1759
|
+
#related_list = false;
|
|
1617
1760
|
state_related(related) {
|
|
1618
1761
|
if (related.list) this.attach_state_to_prop_map("selections", related.list, () => some([]), (val) => {
|
|
1619
1762
|
return some(state.e.map(val, (key, val) => {
|
|
@@ -1624,6 +1767,8 @@ var FormSelectorBase = class extends FormValueWrite {
|
|
|
1624
1767
|
};
|
|
1625
1768
|
}));
|
|
1626
1769
|
});
|
|
1770
|
+
else if (this.#related_list) this.detach_state_from_prop("selections").selections = void 0;
|
|
1771
|
+
this.#related_list = !!related.list;
|
|
1627
1772
|
}
|
|
1628
1773
|
};
|
|
1629
1774
|
// src/form/selectors/drop_down/drop_down.ts
|
|
@@ -1643,6 +1788,8 @@ var FormDropdown = class extends FormSelectorBase {
|
|
|
1643
1788
|
#open = this.appendChild(material_keyboard_arrow_down_rounded());
|
|
1644
1789
|
#default = document.createTextNode("Select something");
|
|
1645
1790
|
#default_icon;
|
|
1791
|
+
/**Popup of the document the dropdown was opened in*/
|
|
1792
|
+
#box;
|
|
1646
1793
|
is_open = false;
|
|
1647
1794
|
constructor(id) {
|
|
1648
1795
|
super(id);
|
|
@@ -1709,12 +1856,13 @@ var FormDropdown = class extends FormSelectorBase {
|
|
|
1709
1856
|
const old = this.#open;
|
|
1710
1857
|
this.#open = material_unfold_less_rounded();
|
|
1711
1858
|
old.replaceWith(this.#open);
|
|
1712
|
-
|
|
1859
|
+
this.#box = boxes.get(this.ownerDocument) ?? main_box;
|
|
1860
|
+
this.#box.open_menu(this.#map, this, this.buffer);
|
|
1713
1861
|
} else if (!open && this.is_open) {
|
|
1714
1862
|
const old = this.#open;
|
|
1715
1863
|
this.#open = material_keyboard_arrow_down_rounded();
|
|
1716
1864
|
old.replaceWith(this.#open);
|
|
1717
|
-
box
|
|
1865
|
+
this.#box?.close_menu();
|
|
1718
1866
|
}
|
|
1719
1867
|
this.is_open = open;
|
|
1720
1868
|
}
|
|
@@ -1810,7 +1958,7 @@ var DropDownBox = class extends Base {
|
|
|
1810
1958
|
e.preventDefault();
|
|
1811
1959
|
};
|
|
1812
1960
|
this.#closer.appendChild(document.createElement("div")).appendChild(material_close_rounded());
|
|
1813
|
-
this.#closer.appendChild(document.createElement("div")).
|
|
1961
|
+
this.#closer.appendChild(document.createElement("div")).textContent = "Close";
|
|
1814
1962
|
this.#closer.tabIndex = 0;
|
|
1815
1963
|
this.#closer.onclick = (e) => {
|
|
1816
1964
|
e.stopPropagation();
|
|
@@ -1831,6 +1979,7 @@ var DropDownBox = class extends Base {
|
|
|
1831
1979
|
this.close_menu();
|
|
1832
1980
|
}
|
|
1833
1981
|
open_menu(map, parent, value) {
|
|
1982
|
+
if (this.#is_open) this.close_menu(false);
|
|
1834
1983
|
const inner_height = this.ownerDocument.defaultView?.innerHeight || 0;
|
|
1835
1984
|
this.classList.add("open");
|
|
1836
1985
|
const bounds = parent.getBoundingClientRect();
|
|
@@ -1850,8 +1999,6 @@ var DropDownBox = class extends Base {
|
|
|
1850
1999
|
this.#container.style.left = bounds.x + "px";
|
|
1851
2000
|
this.#container.style.width = bounds.width + "px";
|
|
1852
2001
|
this.#dropdown = parent;
|
|
1853
|
-
if (this.#scroll.scrollHeight > this.#scroll.clientHeight) this.#scroll.classList.add("scroll");
|
|
1854
|
-
else this.#scroll.classList.remove("scroll");
|
|
1855
2002
|
let focus = void 0;
|
|
1856
2003
|
this.#table.replaceChildren(...Array.from(map).map(([val, opt]) => {
|
|
1857
2004
|
const line = document.createElement("div");
|
|
@@ -1877,6 +2024,8 @@ var DropDownBox = class extends Base {
|
|
|
1877
2024
|
const box_area = box.width * box.height;
|
|
1878
2025
|
const html = this.ownerDocument.documentElement;
|
|
1879
2026
|
if (box_area > html.clientWidth * html.clientHeight * .5) this.#table.prepend(this.#closer);
|
|
2027
|
+
if (this.#scroll.scrollHeight > this.#scroll.clientHeight) this.#scroll.classList.add("scroll");
|
|
2028
|
+
else this.#scroll.classList.remove("scroll");
|
|
1880
2029
|
if (focus) {
|
|
1881
2030
|
focus.focus();
|
|
1882
2031
|
focus.classList.add("selected");
|
|
@@ -1884,21 +2033,34 @@ var DropDownBox = class extends Base {
|
|
|
1884
2033
|
this.ownerDocument.defaultView?.addEventListener("resize", this.#window_resize_handler, { passive: true });
|
|
1885
2034
|
this.#is_open = true;
|
|
1886
2035
|
}
|
|
1887
|
-
close_menu() {
|
|
2036
|
+
close_menu(focus = true) {
|
|
1888
2037
|
if (!this.#is_open) return;
|
|
1889
2038
|
this.#is_open = false;
|
|
1890
2039
|
if (this.#dropdown) this.#dropdown.open = false;
|
|
1891
2040
|
this.classList.remove("open");
|
|
1892
2041
|
this.#table.replaceChildren();
|
|
1893
2042
|
if (this.#dropdown) {
|
|
1894
|
-
this.#dropdown.focus();
|
|
2043
|
+
if (focus) this.#dropdown.focus();
|
|
1895
2044
|
this.#dropdown.is_open = false;
|
|
1896
2045
|
}
|
|
1897
2046
|
this.ownerDocument.defaultView?.removeEventListener("resize", this.#window_resize_handler);
|
|
1898
2047
|
}
|
|
1899
2048
|
};
|
|
1900
2049
|
define_element(DropDownBox);
|
|
1901
|
-
|
|
2050
|
+
/**One popup per document, so dropdowns in popout windows open in their own window*/
|
|
2051
|
+
const boxes = /* @__PURE__ */ new Map();
|
|
2052
|
+
const add_box = (doc) => {
|
|
2053
|
+
const box = doc.documentElement.appendChild(new DropDownBox());
|
|
2054
|
+
boxes.set(doc, box);
|
|
2055
|
+
return box;
|
|
2056
|
+
};
|
|
2057
|
+
/**Used for dropdowns in documents not registered with the document handler*/
|
|
2058
|
+
const main_box = add_box(DOCUMENT_HANDLER.main);
|
|
2059
|
+
DOCUMENT_HANDLER.for_documents((doc) => {
|
|
2060
|
+
if (doc !== DOCUMENT_HANDLER.main) add_box(doc);
|
|
2061
|
+
});
|
|
2062
|
+
DOCUMENT_HANDLER.events.on("added", (e) => add_box(e.data));
|
|
2063
|
+
DOCUMENT_HANDLER.events.on("removed", (e) => boxes.delete(e.data));
|
|
1902
2064
|
// src/form/selectors/toggle_button/toggle_button.ts
|
|
1903
2065
|
/**Toggle buttons, displays all options in a multi toggler*/
|
|
1904
2066
|
var FormToggleButton = class extends FormSelectorBase {
|
|
@@ -1976,7 +2138,7 @@ var FormToggleButton = class extends FormSelectorBase {
|
|
|
1976
2138
|
opt.bot.classList.add("selected");
|
|
1977
2139
|
this.#selected = this.#values.indexOf(value);
|
|
1978
2140
|
if (this.contains(document.activeElement)) opt.top.focus();
|
|
1979
|
-
}
|
|
2141
|
+
} else this.#selected = -1;
|
|
1980
2142
|
}
|
|
1981
2143
|
clear_value() {
|
|
1982
2144
|
const prev = this.#map.get(this.#values[this.#selected]);
|
|
@@ -1984,6 +2146,7 @@ var FormToggleButton = class extends FormSelectorBase {
|
|
|
1984
2146
|
prev.top.classList.remove("selected");
|
|
1985
2147
|
prev.bot.classList.remove("selected");
|
|
1986
2148
|
}
|
|
2149
|
+
this.#selected = -1;
|
|
1987
2150
|
}
|
|
1988
2151
|
new_error(_val) {}
|
|
1989
2152
|
clear_error() {}
|
|
@@ -2080,6 +2243,21 @@ const FormDateTimeMode = {
|
|
|
2080
2243
|
STRING: "string",
|
|
2081
2244
|
NUMBER: "number"
|
|
2082
2245
|
};
|
|
2246
|
+
const TIME_ONLY = /^\d{2}:\d{2}/;
|
|
2247
|
+
const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
|
|
2248
|
+
const INPUT_FORMAT = {
|
|
2249
|
+
date: DATE_ONLY,
|
|
2250
|
+
time: /^\d{2}:\d{2}(:\d{2})?$/,
|
|
2251
|
+
datetime: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?$/
|
|
2252
|
+
};
|
|
2253
|
+
/**Returns the wall clock time of a string as UTC milliseconds, like the input uses
|
|
2254
|
+
* Time only strings give the time since midnight, strings without time zone are local*/
|
|
2255
|
+
const string_wall_time = (value) => {
|
|
2256
|
+
if (TIME_ONLY.test(value)) return Date.parse("1970-01-01T" + value + "Z");
|
|
2257
|
+
if (DATE_ONLY.test(value)) return Date.parse(value);
|
|
2258
|
+
const date = new Date(value);
|
|
2259
|
+
return date.getTime() - date.getTimezoneOffset() * 6e4;
|
|
2260
|
+
};
|
|
2083
2261
|
var FormDateTime = class extends FormValueWrite {
|
|
2084
2262
|
static element_name() {
|
|
2085
2263
|
return "datetimeinput";
|
|
@@ -2098,6 +2276,7 @@ var FormDateTime = class extends FormValueWrite {
|
|
|
2098
2276
|
};
|
|
2099
2277
|
this.warn_input.onblur = () => {
|
|
2100
2278
|
this.selected = false;
|
|
2279
|
+
if (this._buffer !== void 0) this.new_value(this._buffer);
|
|
2101
2280
|
};
|
|
2102
2281
|
this.warn_input.type = "datetime-local";
|
|
2103
2282
|
this.warn_input.lang = "da-DK";
|
|
@@ -2107,8 +2286,13 @@ var FormDateTime = class extends FormValueWrite {
|
|
|
2107
2286
|
this.appendChild(material_schedule_rounded()).onclick = () => this.warn_input.showPicker();
|
|
2108
2287
|
this.warn_input.onchange = () => {
|
|
2109
2288
|
if (this.warn_input.value) {
|
|
2110
|
-
if (this.#mode === FormDateTimeMode.DATE)
|
|
2111
|
-
|
|
2289
|
+
if (this.#mode === FormDateTimeMode.DATE) {
|
|
2290
|
+
const wall = new Date(this.warn_input.valueAsNumber);
|
|
2291
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
2292
|
+
date.setFullYear(wall.getUTCFullYear(), wall.getUTCMonth(), wall.getUTCDate());
|
|
2293
|
+
date.setHours(wall.getUTCHours(), wall.getUTCMinutes(), wall.getUTCSeconds(), wall.getUTCMilliseconds());
|
|
2294
|
+
this.set_value_check(date);
|
|
2295
|
+
} else if (this.#mode === FormDateTimeMode.STRING) this.set_value_check(this.warn_input.value);
|
|
2112
2296
|
else this.set_value_check(this.warn_input.valueAsNumber);
|
|
2113
2297
|
}
|
|
2114
2298
|
};
|
|
@@ -2146,8 +2330,11 @@ var FormDateTime = class extends FormValueWrite {
|
|
|
2146
2330
|
let time;
|
|
2147
2331
|
if (typeof value === "number") time = value;
|
|
2148
2332
|
else if (typeof value === "string") {
|
|
2149
|
-
|
|
2150
|
-
|
|
2333
|
+
if (INPUT_FORMAT[this.#type].test(value)) {
|
|
2334
|
+
this.warn_input.value = value;
|
|
2335
|
+
return;
|
|
2336
|
+
}
|
|
2337
|
+
time = string_wall_time(value);
|
|
2151
2338
|
} else time = value.getTime() - value.getTimezoneOffset() * 6e4;
|
|
2152
2339
|
this.warn_input.valueAsNumber = this.#milliseconds ? time : time - time % 1e3;
|
|
2153
2340
|
}
|
|
@@ -2177,6 +2364,10 @@ var FormIp = class extends FormValueWrite {
|
|
|
2177
2364
|
return "form";
|
|
2178
2365
|
}
|
|
2179
2366
|
#type;
|
|
2367
|
+
/**Amount of parts of the current type*/
|
|
2368
|
+
get #count() {
|
|
2369
|
+
return this.#type === IPVersion.V4 ? 4 : 8;
|
|
2370
|
+
}
|
|
2180
2371
|
#parts = Array.from({ length: 8 }, (_, i) => {
|
|
2181
2372
|
const inp = this.appendChild(document.createElement("div"));
|
|
2182
2373
|
if (i < 7) this.appendChild(document.createElement("span"));
|
|
@@ -2184,38 +2375,41 @@ var FormIp = class extends FormValueWrite {
|
|
|
2184
2375
|
inp.onbeforeinput = async (ev) => {
|
|
2185
2376
|
if (ev.inputType === "insertParagraph") ev.preventDefault();
|
|
2186
2377
|
else if (ev.inputType === "deleteContentBackward") {
|
|
2187
|
-
if (inp.textContent.length === 0 && i > 0) set_cursor_end(
|
|
2378
|
+
if (inp.textContent.length === 0 && i > 0) set_cursor_end(this.#parts[i - 1]);
|
|
2188
2379
|
} else if (ev.inputType === "deleteContentForward") {
|
|
2189
|
-
if (inp.textContent.length === 0 && i <
|
|
2380
|
+
if (inp.textContent.length === 0 && i < this.#count - 1) {
|
|
2190
2381
|
await sleep(0);
|
|
2191
|
-
|
|
2382
|
+
this.#parts[i + 1].focus();
|
|
2192
2383
|
}
|
|
2193
2384
|
} else if (ev.data) {
|
|
2194
|
-
if ((ev.data === "." || ev.data === ":" || ev.data === ",") && i <
|
|
2195
|
-
set_selection_all(
|
|
2385
|
+
if ((ev.data === "." || ev.data === ":" || ev.data === ",") && i < this.#count - 1) {
|
|
2386
|
+
set_selection_all(this.#parts[i + 1]);
|
|
2196
2387
|
ev.preventDefault();
|
|
2197
2388
|
} else if (!ev.data.match(this.#type === IPVersion.V4 ? /^[\d]*$/ : /^[\dA-Fa-f]*$/)) ev.preventDefault();
|
|
2198
|
-
else if (inp.textContent.length >= (this.#type === IPVersion.V4 ? 3 : 4)) ev.preventDefault();
|
|
2199
2389
|
else {
|
|
2200
|
-
const
|
|
2201
|
-
const potential = inp.textContent.slice(0,
|
|
2390
|
+
const [start, end] = this.#selection_in(inp);
|
|
2391
|
+
const potential = inp.textContent.slice(0, start) + ev.data + inp.textContent.slice(end);
|
|
2392
|
+
if (potential.length > (this.#type === IPVersion.V4 ? 3 : 4)) {
|
|
2393
|
+
ev.preventDefault();
|
|
2394
|
+
return;
|
|
2395
|
+
}
|
|
2202
2396
|
const num = this.#type === IPVersion.V4 ? parseInt(potential, 10) : parseInt(potential, 16);
|
|
2203
2397
|
if (this.#type === IPVersion.V4 && num > 255 || this.#type === IPVersion.V6 && num > 65535) {
|
|
2204
|
-
if (i < this.#
|
|
2398
|
+
if (i < this.#count - 1) set_selection_all(this.#parts[i + 1]);
|
|
2205
2399
|
else ev.preventDefault();
|
|
2206
2400
|
}
|
|
2207
2401
|
}
|
|
2208
2402
|
}
|
|
2209
2403
|
};
|
|
2210
2404
|
inp.oninput = () => {
|
|
2211
|
-
if (inp.textContent.length === (this.#type === IPVersion.V4 ? 3 : 4) && get_cursor_position(inp) === inp.textContent.length && i < this.#
|
|
2405
|
+
if (inp.textContent.length === (this.#type === IPVersion.V4 ? 3 : 4) && get_cursor_position(inp) === inp.textContent.length && i < this.#count - 1) set_selection_all(this.#parts[i + 1]);
|
|
2212
2406
|
};
|
|
2213
2407
|
inp.onkeydown = async (e) => {
|
|
2214
2408
|
if (e.key === "ArrowUp") {} else if (e.key === "ArrowDown") {} else if (e.key === "ArrowLeft" && i > 0) {
|
|
2215
|
-
if (get_cursor_position(inp) === 0 || inp.textContent.length === 0) set_cursor_end(
|
|
2409
|
+
if (get_cursor_position(inp) === 0 || inp.textContent.length === 0) set_cursor_end(this.#parts[i - 1]);
|
|
2216
2410
|
else return;
|
|
2217
|
-
} else if (e.key === "ArrowRight" && i < this.#
|
|
2218
|
-
if (get_cursor_position(inp) === inp.textContent.length || inp.textContent.length === 0)
|
|
2411
|
+
} else if (e.key === "ArrowRight" && i < this.#count - 1) {
|
|
2412
|
+
if (get_cursor_position(inp) === inp.textContent.length || inp.textContent.length === 0) this.#parts[i + 1].focus();
|
|
2219
2413
|
else return;
|
|
2220
2414
|
} else return;
|
|
2221
2415
|
e.preventDefault();
|
|
@@ -2250,10 +2444,10 @@ var FormIp = class extends FormValueWrite {
|
|
|
2250
2444
|
});
|
|
2251
2445
|
this.addEventListener("focusout", (e) => {
|
|
2252
2446
|
if (e.relatedTarget && this.contains(e.relatedTarget)) return;
|
|
2253
|
-
this
|
|
2447
|
+
this.#commit_typed();
|
|
2254
2448
|
});
|
|
2255
2449
|
this.onkeydown = (e) => {
|
|
2256
|
-
if (e.key === "Enter") this
|
|
2450
|
+
if (e.key === "Enter") this.#commit_typed();
|
|
2257
2451
|
else if (e.key === "Escape") {
|
|
2258
2452
|
if (this.buffer) this.new_value(this.buffer);
|
|
2259
2453
|
else this.clear_value();
|
|
@@ -2261,16 +2455,56 @@ var FormIp = class extends FormValueWrite {
|
|
|
2261
2455
|
};
|
|
2262
2456
|
this.oncopy = (e) => {
|
|
2263
2457
|
e.preventDefault();
|
|
2264
|
-
|
|
2458
|
+
const typed = this.#typed();
|
|
2459
|
+
if (typed.ok) e.clipboardData?.setData("text/plain", typed.value.to_string());
|
|
2265
2460
|
};
|
|
2266
2461
|
this.onpaste = (e) => {
|
|
2267
2462
|
e.preventDefault();
|
|
2268
2463
|
const paste = e.clipboardData?.getData("text/plain") || "";
|
|
2269
|
-
|
|
2464
|
+
let new_ip;
|
|
2465
|
+
try {
|
|
2466
|
+
new_ip = new IPAddress(paste);
|
|
2467
|
+
} catch (error) {
|
|
2468
|
+
return this.warn(error instanceof Error ? error.message : String(error));
|
|
2469
|
+
}
|
|
2270
2470
|
if (new_ip.version !== this.#type) return;
|
|
2271
|
-
this
|
|
2471
|
+
this.#commit(new_ip);
|
|
2272
2472
|
};
|
|
2273
2473
|
}
|
|
2474
|
+
/**Start and end of the selection in a part, both the cursor position when nothing is selected*/
|
|
2475
|
+
#selection_in(part) {
|
|
2476
|
+
const selection = part.ownerDocument.getSelection();
|
|
2477
|
+
if (selection?.rangeCount && part.contains(selection.anchorNode)) {
|
|
2478
|
+
const range = selection.getRangeAt(0);
|
|
2479
|
+
const before = range.cloneRange();
|
|
2480
|
+
before.selectNodeContents(part);
|
|
2481
|
+
before.setEnd(range.startContainer, range.startOffset);
|
|
2482
|
+
const start = before.toString().length;
|
|
2483
|
+
return [start, start + range.toString().length];
|
|
2484
|
+
}
|
|
2485
|
+
const position = get_cursor_position(part);
|
|
2486
|
+
return [position, position];
|
|
2487
|
+
}
|
|
2488
|
+
/**The typed address, or why the typed parts are not an address*/
|
|
2489
|
+
#typed() {
|
|
2490
|
+
if (this.#parts.slice(0, this.#count).some((part) => !part.textContent)) return err("All parts of the address must be filled in");
|
|
2491
|
+
try {
|
|
2492
|
+
return ok(this.value_as_ip);
|
|
2493
|
+
} catch (error) {
|
|
2494
|
+
return err(error instanceof Error ? error.message : String(error));
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
/**Commits the typed address, or warns why it is not an address*/
|
|
2498
|
+
#commit_typed() {
|
|
2499
|
+
const typed = this.#typed();
|
|
2500
|
+
if (typed.ok) this.#commit(typed.value);
|
|
2501
|
+
else this.warn(typed.error);
|
|
2502
|
+
}
|
|
2503
|
+
/**Commits an address, unless it is the current address, a new IPAddress object is never the same object as the current one*/
|
|
2504
|
+
#commit(ip) {
|
|
2505
|
+
if (this.buffer?.equals(ip)) return;
|
|
2506
|
+
this.set_value_check(ip);
|
|
2507
|
+
}
|
|
2274
2508
|
focus(options) {
|
|
2275
2509
|
this.#parts[0].focus(options);
|
|
2276
2510
|
}
|
|
@@ -2286,7 +2520,7 @@ var FormIp = class extends FormValueWrite {
|
|
|
2286
2520
|
this.#type = val;
|
|
2287
2521
|
this.classList.toggle("ipv4", val === IPVersion.V4);
|
|
2288
2522
|
this.classList.toggle("ipv6", val === IPVersion.V6);
|
|
2289
|
-
this.replaceChildren(...this.#parts.slice(0,
|
|
2523
|
+
this.replaceChildren(...this.#parts.slice(0, this.#count).flatMap((v, i) => i < this.#count - 1 ? [v, document.createTextNode(val === IPVersion.V4 ? "." : ":")] : [v]), this.warn_input);
|
|
2290
2524
|
}
|
|
2291
2525
|
new_value(val) {
|
|
2292
2526
|
this.type = val.version;
|
|
@@ -2329,13 +2563,15 @@ var FormPassword = class extends FormValueWrite {
|
|
|
2329
2563
|
};
|
|
2330
2564
|
this.warn_input.onblur = () => {
|
|
2331
2565
|
this.selected = false;
|
|
2566
|
+
if (this._buffer !== void 0 && this.warn_input.value !== this._buffer) this.new_value(this._buffer);
|
|
2332
2567
|
};
|
|
2333
2568
|
this.warn_input.onchange = () => {
|
|
2334
2569
|
this.set_value_check(this.warn_input.value);
|
|
2335
2570
|
};
|
|
2336
2571
|
this.warn_input.onbeforeinput = (ev) => {
|
|
2337
|
-
if (ev.data) {
|
|
2338
|
-
|
|
2572
|
+
if (ev.data && this.#filter) {
|
|
2573
|
+
this.#filter.lastIndex = 0;
|
|
2574
|
+
if (!this.#filter.test(ev.data)) {
|
|
2339
2575
|
ev.preventDefault();
|
|
2340
2576
|
this.warn("Invalid character entered");
|
|
2341
2577
|
}
|
|
@@ -2376,6 +2612,8 @@ var FormTextInput = class extends FormValueWrite {
|
|
|
2376
2612
|
#filter;
|
|
2377
2613
|
#max_length;
|
|
2378
2614
|
#max_bytes;
|
|
2615
|
+
#related_length = false;
|
|
2616
|
+
#related_bytes = false;
|
|
2379
2617
|
constructor(id) {
|
|
2380
2618
|
super(id);
|
|
2381
2619
|
this.warn_input.onfocus = () => {
|
|
@@ -2383,6 +2621,7 @@ var FormTextInput = class extends FormValueWrite {
|
|
|
2383
2621
|
};
|
|
2384
2622
|
this.warn_input.onblur = () => {
|
|
2385
2623
|
this.selected = false;
|
|
2624
|
+
if (this._buffer !== void 0 && this.warn_input.value !== this._buffer) this.new_value(this._buffer);
|
|
2386
2625
|
};
|
|
2387
2626
|
this.warn_input.type = "text";
|
|
2388
2627
|
this.appendChild(this.warn_input);
|
|
@@ -2391,15 +2630,20 @@ var FormTextInput = class extends FormValueWrite {
|
|
|
2391
2630
|
this.warn("");
|
|
2392
2631
|
const data = e.data || e.dataTransfer?.getData("text/plain");
|
|
2393
2632
|
if (data) {
|
|
2633
|
+
if (this.#filter) this.#filter.lastIndex = 0;
|
|
2394
2634
|
if (this.#filter && !this.#filter.test(data)) {
|
|
2395
2635
|
e.preventDefault();
|
|
2396
2636
|
this.warn("Invalid character entered");
|
|
2397
|
-
} else {
|
|
2398
|
-
|
|
2637
|
+
} else if (this.#max_length || this.#max_bytes) {
|
|
2638
|
+
const input = this.warn_input;
|
|
2639
|
+
const value = input.value;
|
|
2640
|
+
const start = input.selectionStart ?? value.length;
|
|
2641
|
+
const end = input.selectionEnd ?? start;
|
|
2642
|
+
if (this.#max_length && value.length - (end - start) + data.length > this.#max_length) {
|
|
2399
2643
|
e.preventDefault();
|
|
2400
2644
|
this.warn(`A maximum of ${this.#max_length} characters is allowed`);
|
|
2401
2645
|
}
|
|
2402
|
-
if (this.#max_bytes && string_byte_length(
|
|
2646
|
+
if (this.#max_bytes && string_byte_length(value) - string_byte_length(value.slice(start, end)) + string_byte_length(data) > this.#max_bytes) {
|
|
2403
2647
|
e.preventDefault();
|
|
2404
2648
|
this.warn(`A maximum of ${this.#max_bytes} bytes is allowed`);
|
|
2405
2649
|
}
|
|
@@ -2436,7 +2680,8 @@ var FormTextInput = class extends FormValueWrite {
|
|
|
2436
2680
|
}
|
|
2437
2681
|
set max_length(val) {
|
|
2438
2682
|
this.#max_length = val;
|
|
2439
|
-
this.warn_input.
|
|
2683
|
+
if (val === void 0) this.warn_input.removeAttribute("maxlength");
|
|
2684
|
+
else this.warn_input.maxLength = val;
|
|
2440
2685
|
}
|
|
2441
2686
|
get max_length() {
|
|
2442
2687
|
return this.#max_length;
|
|
@@ -2467,9 +2712,11 @@ var FormTextInput = class extends FormValueWrite {
|
|
|
2467
2712
|
}
|
|
2468
2713
|
state_related(related) {
|
|
2469
2714
|
if (related.max_length) this.attach_state_to_prop("max_length", related.max_length, () => none());
|
|
2470
|
-
else this.detach_state_from_prop("max_length");
|
|
2715
|
+
else if (this.#related_length) this.detach_state_from_prop("max_length").max_length = void 0;
|
|
2716
|
+
this.#related_length = !!related.max_length;
|
|
2471
2717
|
if (related.max_length_bytes) this.attach_state_to_prop("max_bytes", related.max_length_bytes, () => none());
|
|
2472
|
-
else this.detach_state_from_prop("max_bytes");
|
|
2718
|
+
else if (this.#related_bytes) this.detach_state_from_prop("max_bytes").max_bytes = void 0;
|
|
2719
|
+
this.#related_bytes = !!related.max_length_bytes;
|
|
2473
2720
|
}
|
|
2474
2721
|
};
|
|
2475
2722
|
define_element(FormTextInput);
|
|
@@ -2496,6 +2743,8 @@ var FormTextMultiline = class extends FormValueWrite {
|
|
|
2496
2743
|
#filter;
|
|
2497
2744
|
#max_length;
|
|
2498
2745
|
#max_bytes;
|
|
2746
|
+
#related_length = false;
|
|
2747
|
+
#related_bytes = false;
|
|
2499
2748
|
#value_box = this.appendChild(document.createElement("textarea"));
|
|
2500
2749
|
#resizer = this.appendChild(document.createElement("div"));
|
|
2501
2750
|
constructor(id) {
|
|
@@ -2505,6 +2754,7 @@ var FormTextMultiline = class extends FormValueWrite {
|
|
|
2505
2754
|
};
|
|
2506
2755
|
this.#value_box.onblur = () => {
|
|
2507
2756
|
this.selected = false;
|
|
2757
|
+
if (this._buffer !== void 0 && this.#value_box.value !== this._buffer) this.new_value(this._buffer);
|
|
2508
2758
|
};
|
|
2509
2759
|
this.appendChild(this.warn_input);
|
|
2510
2760
|
this.#resizer.appendChild(material_drag_handle_rounded());
|
|
@@ -2523,23 +2773,25 @@ var FormTextMultiline = class extends FormValueWrite {
|
|
|
2523
2773
|
this.#resizer.onpointerup = null;
|
|
2524
2774
|
};
|
|
2525
2775
|
};
|
|
2526
|
-
this.#value_box.onkeydown = (e) => {
|
|
2527
|
-
if (e.key === "Enter" && !e.shiftKey) e.stopPropagation();
|
|
2528
|
-
};
|
|
2529
2776
|
this.#value_box.onchange = () => this.#set();
|
|
2530
2777
|
this.#value_box.onbeforeinput = (e) => {
|
|
2531
2778
|
this.warn("");
|
|
2532
2779
|
const data = e.data || e.dataTransfer?.getData("text/plain");
|
|
2533
2780
|
if (data) {
|
|
2781
|
+
if (this.#filter) this.#filter.lastIndex = 0;
|
|
2534
2782
|
if (this.#filter && !this.#filter.test(data)) {
|
|
2535
2783
|
e.preventDefault();
|
|
2536
2784
|
this.warn("Invalid character entered");
|
|
2537
|
-
} else {
|
|
2538
|
-
|
|
2785
|
+
} else if (this.#max_length || this.#max_bytes) {
|
|
2786
|
+
const box = this.#value_box;
|
|
2787
|
+
const value = box.value;
|
|
2788
|
+
const start = box.selectionStart;
|
|
2789
|
+
const end = box.selectionEnd;
|
|
2790
|
+
if (this.#max_length && value.length - (end - start) + data.length > this.#max_length) {
|
|
2539
2791
|
e.preventDefault();
|
|
2540
2792
|
this.warn(`A maximum of ${this.#max_length} characters is allowed`);
|
|
2541
2793
|
}
|
|
2542
|
-
if (this.#max_bytes && string_byte_length(
|
|
2794
|
+
if (this.#max_bytes && string_byte_length(value) - string_byte_length(value.slice(start, end)) + string_byte_length(data) > this.#max_bytes) {
|
|
2543
2795
|
e.preventDefault();
|
|
2544
2796
|
this.warn(`A maximum of ${this.#max_bytes} bytes is allowed`);
|
|
2545
2797
|
}
|
|
@@ -2552,9 +2804,12 @@ var FormTextMultiline = class extends FormValueWrite {
|
|
|
2552
2804
|
e.stopPropagation();
|
|
2553
2805
|
if (this.buffer) this.new_value(this.buffer);
|
|
2554
2806
|
else this.clear_value();
|
|
2555
|
-
} else if (e.key === "Enter"
|
|
2556
|
-
e.
|
|
2557
|
-
|
|
2807
|
+
} else if (e.key === "Enter") {
|
|
2808
|
+
if (!e.shiftKey) e.stopPropagation();
|
|
2809
|
+
if (e.ctrlKey) {
|
|
2810
|
+
e.preventDefault();
|
|
2811
|
+
this.#set();
|
|
2812
|
+
}
|
|
2558
2813
|
}
|
|
2559
2814
|
};
|
|
2560
2815
|
}
|
|
@@ -2582,7 +2837,8 @@ var FormTextMultiline = class extends FormValueWrite {
|
|
|
2582
2837
|
}
|
|
2583
2838
|
set max_length(val) {
|
|
2584
2839
|
this.#max_length = val;
|
|
2585
|
-
this.#value_box.
|
|
2840
|
+
if (val === void 0) this.#value_box.removeAttribute("maxlength");
|
|
2841
|
+
else this.#value_box.maxLength = val;
|
|
2586
2842
|
}
|
|
2587
2843
|
get max_length() {
|
|
2588
2844
|
return this.#max_length;
|
|
@@ -2613,9 +2869,11 @@ var FormTextMultiline = class extends FormValueWrite {
|
|
|
2613
2869
|
}
|
|
2614
2870
|
state_related(related) {
|
|
2615
2871
|
if (related.max_length) this.attach_state_to_prop("max_length", related.max_length, () => none());
|
|
2616
|
-
else this.detach_state_from_prop("max_length");
|
|
2872
|
+
else if (this.#related_length) this.detach_state_from_prop("max_length").max_length = void 0;
|
|
2873
|
+
this.#related_length = !!related.max_length;
|
|
2617
2874
|
if (related.max_length_bytes) this.attach_state_to_prop("max_bytes", related.max_length_bytes, () => none());
|
|
2618
|
-
else this.detach_state_from_prop("max_bytes");
|
|
2875
|
+
else if (this.#related_bytes) this.detach_state_from_prop("max_bytes").max_bytes = void 0;
|
|
2876
|
+
this.#related_bytes = !!related.max_length_bytes;
|
|
2619
2877
|
}
|
|
2620
2878
|
};
|
|
2621
2879
|
define_element(FormTextMultiline);
|
|
@@ -2623,6 +2881,7 @@ define_element(FormTextMultiline);
|
|
|
2623
2881
|
function form_text_multiline(options) {
|
|
2624
2882
|
const input = new FormTextMultiline(options?.id);
|
|
2625
2883
|
if (options) {
|
|
2884
|
+
if (options.filter) input.filter = options.filter;
|
|
2626
2885
|
if (options.placeholder) input.placeholder = options.placeholder;
|
|
2627
2886
|
if (options.max_length) input.max_length = options.max_length;
|
|
2628
2887
|
if (options.max_bytes) input.max_bytes = options.max_bytes;
|