@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
package/form/index.mjs
ADDED
|
@@ -0,0 +1,2694 @@
|
|
|
1
|
+
import "../style.css";
|
|
2
|
+
import { AccessTypes, Base, define_element } from "../base/index.mjs";
|
|
3
|
+
import { c as AnimationLevels, o as ANIMATION_LEVEL, r as theme_init_variable_root, s as ANIMATION_SPEED } from "../theme-DhIVwHQw.mjs";
|
|
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-CY4BLQ2F.mjs";
|
|
6
|
+
import { n as ListField } from "../list-BcNSxtNm.mjs";
|
|
7
|
+
import { get_cursor_position, set_cursor_end, set_cursor_position, set_selection_all } from "../selection/index.mjs";
|
|
8
|
+
import state from "@chocbite/ts-lib/state";
|
|
9
|
+
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
|
+
import { BLUE, GREEN, GREY, ORANGE, RED, YELLOW } from "@chocbite/ts-lib/colors";
|
|
13
|
+
import { string_byte_length, string_byte_limit } from "@chocbite/ts-lib/string";
|
|
14
|
+
// src/form/shared.ts
|
|
15
|
+
const theme_root = theme_init_variable_root("form", "UI Form Elements", "Theme variables for UI form Elements");
|
|
16
|
+
theme_root.make_sub_group("read", "Read Only", "Settings for form elements in read only mode").make_variable("filter", "Read Only Filter", "Filter applied to form elements in read only mode", "opacity(0.6)", "opacity(0.6)", "Filter", void 0);
|
|
17
|
+
const colors = theme_root.make_sub_group("colors", "Colors", "Colors used in all form elements");
|
|
18
|
+
const colors_text = colors.make_sub_group("text", "Text Colors", "Text colors used in all form elements");
|
|
19
|
+
colors_text.make_variable("label", "Label Color", "Color of form elements labels", GREY["700"], GREY["300"], "Color", void 0);
|
|
20
|
+
colors_text.make_variable("normal", "Normal Text Color", "Normal text color in form elements", GREY["800"], GREY["200"], "Color", void 0);
|
|
21
|
+
colors_text.make_variable("selected", "Selected Text Color", "Selected text color in form elements", GREY["900"], GREY["50"], "Color", void 0);
|
|
22
|
+
colors_text.make_variable("unselected", "Unselected Text Color", "Unselected text color in form elements", GREY["600"], GREY["400"], "Color", void 0);
|
|
23
|
+
const colors_text_black = colors.make_sub_group("textBlack", "Text Colors Black Background", "Text colors used for black background in all form elements");
|
|
24
|
+
colors_text_black.make_variable("normal", "Normal Text Color", "Normal text color in form elements", GREY["200"], GREY["200"], "Color", void 0);
|
|
25
|
+
colors_text_black.make_variable("selected", "Selected Text Color", "Selected text color in form elements", GREY["50"], GREY["50"], "Color", void 0);
|
|
26
|
+
colors_text_black.make_variable("unselected", "Unselected Text Color", "Unselected text color in form elements", GREY["600"], GREY["400"], "Color", void 0);
|
|
27
|
+
const colors_icon = colors.make_sub_group("icon", "Icon Colors", "Icon colors used in all form elements");
|
|
28
|
+
colors_icon.make_variable("normal", "Normal Icon Color", "Color of icons in form elements", GREY["800"], GREY["200"], "Color", void 0);
|
|
29
|
+
colors_icon.make_variable("selected", "Selected Icon Color", "Color of selected icons in form elements", GREY["900"], GREY["50"], "Color", void 0);
|
|
30
|
+
colors_icon.make_variable("unselected", "Unselected Icon Color", "Color of unselected icons in form elements", GREY["600"], GREY["400"], "Color", void 0);
|
|
31
|
+
const colors_background = colors.make_sub_group("background", "Background Colors", "Background colors used in all form elements");
|
|
32
|
+
colors_background.make_variable("normal", "Normal Background Color", "Color of normal form element backgrounds", GREY["50"], GREY["900"], "Color", void 0);
|
|
33
|
+
colors_background.make_variable("hover", "Hover Background Color", "Color of form element backgrounds when hovering", GREY["400"], GREY["700"], "Color", void 0);
|
|
34
|
+
colors_background.make_variable("unselected", "Unselected Background Color", "Color of unselected form element backgrounds", GREY["300"], GREY["800"], "Color", void 0);
|
|
35
|
+
const colors_border = colors.make_sub_group("border", "Border Colors", "Border colors used in all form elements");
|
|
36
|
+
colors_border.make_variable("normal", "Normal Border Color", "Color of normal form element borders", GREY["700"], GREY["300"], "Color", void 0);
|
|
37
|
+
colors_border.make_variable("unselected", "Unselected Border Color", "Color of unselected form element borders", GREY["700"], GREY["300"], "Color", void 0);
|
|
38
|
+
colors.make_sub_group("focus", "Focus Colors", "Focus colors used in all form elements").make_variable("normal", "Focus Color", "Color of focussed form element", ORANGE["600"], ORANGE["300"], "Color", void 0);
|
|
39
|
+
const colors_basic = colors.make_sub_group("basic", "Basic Colors", "Basic colors used in all form elements");
|
|
40
|
+
colors_basic.make_variable("black", "Basic Black Color", "Commonly used black color in form elements", GREY["900"], GREY["900"], "Color", void 0);
|
|
41
|
+
colors_basic.make_variable("white", "Basic White Color", "Commonly used white color in form elements", GREY["100"], GREY["100"], "Color", void 0);
|
|
42
|
+
colors_basic.make_variable("green", "Basic Green Color", "Commonly used green color in form elements", GREEN["300"], GREEN["900"], "Color", void 0);
|
|
43
|
+
colors_basic.make_variable("red", "Basic Red Color", "Commonly used red color in form elements", RED["300"], RED["900"], "Color", void 0);
|
|
44
|
+
colors_basic.make_variable("blue", "Basic Blue Color", "Commonly used blue color in form elements", BLUE["300"], BLUE["900"], "Color", void 0);
|
|
45
|
+
colors_basic.make_variable("yellow", "Basic Yellow Color", "Commonly used yellow color in form elements", YELLOW["300"], ORANGE["900"], "Color", void 0);
|
|
46
|
+
const sizes = theme_root.make_sub_group("size", "Size", "Sizes used in all form elements");
|
|
47
|
+
sizes.make_variable("height", "Height", "Default height used in all form elements", "1.3rem", "1.3rem", "Length", {
|
|
48
|
+
min: .1,
|
|
49
|
+
max: 10
|
|
50
|
+
});
|
|
51
|
+
sizes.make_variable("touchHeight", "Touch Height", "Minimum height for touch devices used in all form elements", "2.0rem", "2.0rem", "Length", {
|
|
52
|
+
min: .1,
|
|
53
|
+
max: 10
|
|
54
|
+
});
|
|
55
|
+
const font = theme_root.make_sub_group("font", "Font", "Font settings used in all form elements");
|
|
56
|
+
font.make_variable("size", "Font Size", "Default font size used in all form elements", "0.9rem", "0.9rem", "Length", {
|
|
57
|
+
min: .1,
|
|
58
|
+
max: 10
|
|
59
|
+
});
|
|
60
|
+
font.make_variable("touch_size", "Touch Font Size", "Font size used in all form elements for touch devices", "1.1rem", "1.1rem", "Length", {
|
|
61
|
+
min: .1,
|
|
62
|
+
max: 10
|
|
63
|
+
});
|
|
64
|
+
// src/form/base.ts
|
|
65
|
+
/**Colors for form elements that have selectable colors*/
|
|
66
|
+
const FormColors = {
|
|
67
|
+
None: "none",
|
|
68
|
+
Black: "black",
|
|
69
|
+
Green: "green",
|
|
70
|
+
Red: "red",
|
|
71
|
+
Blue: "blue",
|
|
72
|
+
Yellow: "yellow"
|
|
73
|
+
};
|
|
74
|
+
/**Shared component class for other components to inherit from*/
|
|
75
|
+
var FormElement = class extends Base {
|
|
76
|
+
static element_name() {
|
|
77
|
+
return "@abstract@";
|
|
78
|
+
}
|
|
79
|
+
static element_name_space() {
|
|
80
|
+
return "form";
|
|
81
|
+
}
|
|
82
|
+
static apply_options(_element, _options) {}
|
|
83
|
+
};
|
|
84
|
+
/**Shared class for all components with values*/
|
|
85
|
+
var FormValue = class extends FormElement {
|
|
86
|
+
static element_name() {
|
|
87
|
+
return "@abstract@";
|
|
88
|
+
}
|
|
89
|
+
static apply_options(element, options) {
|
|
90
|
+
if (options.description) element.description = options.description;
|
|
91
|
+
else if (options.value !== void 0) element.value = options.value;
|
|
92
|
+
super.apply_options(element, options);
|
|
93
|
+
}
|
|
94
|
+
form_id;
|
|
95
|
+
constructor(id) {
|
|
96
|
+
super();
|
|
97
|
+
this.form_id = id;
|
|
98
|
+
}
|
|
99
|
+
_description;
|
|
100
|
+
/**Sets the current label of the element*/
|
|
101
|
+
set description(text) {
|
|
102
|
+
this._description = text;
|
|
103
|
+
}
|
|
104
|
+
get description() {
|
|
105
|
+
return this._description || "";
|
|
106
|
+
}
|
|
107
|
+
_buffer;
|
|
108
|
+
get buffer() {
|
|
109
|
+
return this._buffer;
|
|
110
|
+
}
|
|
111
|
+
_state;
|
|
112
|
+
#func;
|
|
113
|
+
bind(opts) {
|
|
114
|
+
if (this.#func) this.detach_state(this.#func);
|
|
115
|
+
if (opts.value) {
|
|
116
|
+
this.attach_state(opts.value, (val) => {
|
|
117
|
+
if (val.ok) {
|
|
118
|
+
this.value = val.value;
|
|
119
|
+
if (this.#error) this.error = void 0;
|
|
120
|
+
} else this.error = val.error;
|
|
121
|
+
});
|
|
122
|
+
const related = opts.value.related();
|
|
123
|
+
if (related.some) this.state_related(related.value);
|
|
124
|
+
} else this.state_related({});
|
|
125
|
+
this._state = opts.value;
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
/**This sets the value of the component*/
|
|
129
|
+
set value(val) {
|
|
130
|
+
if (typeof this._buffer !== "undefined" && this._buffer === val) return;
|
|
131
|
+
this._buffer = val;
|
|
132
|
+
this.new_value(val);
|
|
133
|
+
}
|
|
134
|
+
/**Returns value of the component*/
|
|
135
|
+
get get_value() {
|
|
136
|
+
return this._state ? err("State based component") : typeof this._buffer === "undefined" ? err("No value yet") : ok(this._buffer);
|
|
137
|
+
}
|
|
138
|
+
#error = false;
|
|
139
|
+
set error(err) {
|
|
140
|
+
if (err) {
|
|
141
|
+
this.new_error(err);
|
|
142
|
+
this.#error = true;
|
|
143
|
+
} else if (this.#error) {
|
|
144
|
+
this.clear_error();
|
|
145
|
+
this.#error = false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**Clears the value and error of the component if not state based*/
|
|
149
|
+
clear() {
|
|
150
|
+
if (this._state) return;
|
|
151
|
+
this._buffer = void 0;
|
|
152
|
+
this.clear_value();
|
|
153
|
+
this.clear_error();
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
/**Shared class for all components with values*/
|
|
157
|
+
var FormValueWrite = class extends FormValue {
|
|
158
|
+
static element_name() {
|
|
159
|
+
return "@abstract@";
|
|
160
|
+
}
|
|
161
|
+
selected = false;
|
|
162
|
+
warn_input = document.createElement("input");
|
|
163
|
+
#warn_timeout;
|
|
164
|
+
#changed = false;
|
|
165
|
+
#change;
|
|
166
|
+
static apply_options(element, options) {
|
|
167
|
+
if (options.change) element.change = options.change;
|
|
168
|
+
super.apply_options(element, options);
|
|
169
|
+
}
|
|
170
|
+
constructor(id) {
|
|
171
|
+
super(id);
|
|
172
|
+
this.warn_input.name = "val";
|
|
173
|
+
}
|
|
174
|
+
focus(options) {
|
|
175
|
+
this.warn_input.focus(options);
|
|
176
|
+
}
|
|
177
|
+
set change(func) {
|
|
178
|
+
this.#change = func;
|
|
179
|
+
}
|
|
180
|
+
get change() {
|
|
181
|
+
return this.#change;
|
|
182
|
+
}
|
|
183
|
+
/**Returns true if the value of the component has changed*/
|
|
184
|
+
get changed() {
|
|
185
|
+
return this.#changed;
|
|
186
|
+
}
|
|
187
|
+
set value(val) {
|
|
188
|
+
if (!this.selected) super.value = val;
|
|
189
|
+
else this._buffer = val;
|
|
190
|
+
}
|
|
191
|
+
warn(message) {
|
|
192
|
+
this.warn_input.setCustomValidity(message);
|
|
193
|
+
this.warn_input.reportValidity();
|
|
194
|
+
if (this.#warn_timeout) clearTimeout(this.#warn_timeout);
|
|
195
|
+
this.#warn_timeout = setTimeout(() => {
|
|
196
|
+
this.warn_input.setCustomValidity("");
|
|
197
|
+
this.warn_input.reportValidity();
|
|
198
|
+
}, 5e3);
|
|
199
|
+
}
|
|
200
|
+
/**Function to limit value entered */
|
|
201
|
+
limit_value(val) {
|
|
202
|
+
if (this._state) {
|
|
203
|
+
if (this._state.writable) return this._state.limit(val);
|
|
204
|
+
else return sync_resolve(err("Not writable"));
|
|
205
|
+
} else return sync_resolve(ok(val));
|
|
206
|
+
}
|
|
207
|
+
/**Function to check value */
|
|
208
|
+
check_value(val) {
|
|
209
|
+
if (this._state) {
|
|
210
|
+
if (this._state.writable) return this._state.check(val);
|
|
211
|
+
else return sync_resolve(err("Not writable"));
|
|
212
|
+
} else return sync_resolve(ok(val));
|
|
213
|
+
}
|
|
214
|
+
/**Function to update value*/
|
|
215
|
+
async set_value_limit(val) {
|
|
216
|
+
const limited = await this.limit_value(val);
|
|
217
|
+
if (limited.err) {
|
|
218
|
+
this.warn(limited.error);
|
|
219
|
+
return limited;
|
|
220
|
+
}
|
|
221
|
+
this.#set_value(limited.value);
|
|
222
|
+
return limited;
|
|
223
|
+
}
|
|
224
|
+
/**Function to update value*/
|
|
225
|
+
async set_value_check(val) {
|
|
226
|
+
const checked = await this.check_value(val);
|
|
227
|
+
if (checked.err) {
|
|
228
|
+
this.warn(checked.error);
|
|
229
|
+
return checked;
|
|
230
|
+
}
|
|
231
|
+
this.#set_value(checked.value);
|
|
232
|
+
return checked;
|
|
233
|
+
}
|
|
234
|
+
#set_value(val) {
|
|
235
|
+
if (this._buffer === val) return;
|
|
236
|
+
this.new_value(val);
|
|
237
|
+
if (this._state) {
|
|
238
|
+
const buff = this._buffer;
|
|
239
|
+
this._state.write(val).then((err) => {
|
|
240
|
+
if (err.err) {
|
|
241
|
+
if (buff !== void 0) this.new_value(buff);
|
|
242
|
+
this.warn(err.error);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
} else {
|
|
246
|
+
this._buffer = val;
|
|
247
|
+
this.#changed = true;
|
|
248
|
+
}
|
|
249
|
+
if (this.#change) try {
|
|
250
|
+
this.#change(val);
|
|
251
|
+
} catch (e) {
|
|
252
|
+
console.error("Failed while updating change listener", e);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
// src/form/boolean/button/button.ts
|
|
257
|
+
var FormButton = class extends FormValueWrite {
|
|
258
|
+
static element_name() {
|
|
259
|
+
return "button";
|
|
260
|
+
}
|
|
261
|
+
static element_name_space() {
|
|
262
|
+
return "form";
|
|
263
|
+
}
|
|
264
|
+
#text = this.appendChild(document.createElement("span"));
|
|
265
|
+
#on_click;
|
|
266
|
+
#toggle;
|
|
267
|
+
#icon;
|
|
268
|
+
constructor(id) {
|
|
269
|
+
super(id);
|
|
270
|
+
this.appendChild(this.warn_input);
|
|
271
|
+
this.setAttribute("tabindex", "0");
|
|
272
|
+
this.onclick = () => {
|
|
273
|
+
if (this.#on_click) this.#on_click();
|
|
274
|
+
};
|
|
275
|
+
this.onpointerdown = (e) => {
|
|
276
|
+
if (e.pointerType !== "touch" && e.button === 0) {
|
|
277
|
+
e.stopPropagation();
|
|
278
|
+
this.setPointerCapture(e.pointerId);
|
|
279
|
+
if (!this.#toggle) this.set_value_check(true);
|
|
280
|
+
this.onpointerup = (ev) => {
|
|
281
|
+
ev.stopPropagation();
|
|
282
|
+
this.releasePointerCapture(ev.pointerId);
|
|
283
|
+
if (this.#toggle) this.set_value_check(!this.buffer);
|
|
284
|
+
else this.set_value_check(false);
|
|
285
|
+
this.onpointerup = null;
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
this.ontouchstart = (e) => {
|
|
290
|
+
e.stopPropagation();
|
|
291
|
+
if (!this.#toggle) this.set_value_check(true);
|
|
292
|
+
this.ontouchend = (ev) => {
|
|
293
|
+
ev.stopPropagation();
|
|
294
|
+
if (ev.targetTouches.length === 0) {
|
|
295
|
+
if (this.#toggle) this.set_value_check(!this.buffer);
|
|
296
|
+
else this.set_value_check(false);
|
|
297
|
+
this.ontouchend = null;
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
this.onkeydown = (e) => {
|
|
302
|
+
switch (e.key) {
|
|
303
|
+
case " ":
|
|
304
|
+
case "Enter":
|
|
305
|
+
e.stopPropagation();
|
|
306
|
+
e.preventDefault();
|
|
307
|
+
if (!this.#toggle) this.set_value_check(true);
|
|
308
|
+
this.onkeyup = (e) => {
|
|
309
|
+
switch (e.key) {
|
|
310
|
+
case "Enter":
|
|
311
|
+
case " ":
|
|
312
|
+
e.stopPropagation();
|
|
313
|
+
e.preventDefault();
|
|
314
|
+
if (this.#toggle) this.set_value_check(!this.buffer);
|
|
315
|
+
else this.set_value_check(false);
|
|
316
|
+
if (this.#on_click) this.#on_click();
|
|
317
|
+
}
|
|
318
|
+
this.onkeyup = null;
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
focus(options) {
|
|
324
|
+
HTMLElement.prototype.focus.call(this, options);
|
|
325
|
+
}
|
|
326
|
+
/**Sets the current text of the button*/
|
|
327
|
+
set text(label) {
|
|
328
|
+
this.#text.textContent = label;
|
|
329
|
+
}
|
|
330
|
+
get text() {
|
|
331
|
+
return this.#text.textContent;
|
|
332
|
+
}
|
|
333
|
+
/**Changes the icon of the button*/
|
|
334
|
+
set icon(icon) {
|
|
335
|
+
if (icon) this.#icon = this.insertBefore(icon(), this.#text);
|
|
336
|
+
else if (this.#icon) {
|
|
337
|
+
this.removeChild(this.#icon);
|
|
338
|
+
this.#icon = void 0;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/**Function to call on button click*/
|
|
342
|
+
set on_click(func) {
|
|
343
|
+
this.#on_click = func;
|
|
344
|
+
}
|
|
345
|
+
get on_click() {
|
|
346
|
+
return this.#on_click;
|
|
347
|
+
}
|
|
348
|
+
/**Changes the color of the button*/
|
|
349
|
+
set color(color) {
|
|
350
|
+
if (color === FormColors.None) this.removeAttribute("color");
|
|
351
|
+
else this.setAttribute("color", color);
|
|
352
|
+
}
|
|
353
|
+
/**Centers text and icon */
|
|
354
|
+
set center(center) {
|
|
355
|
+
if (center) this.classList.add("center");
|
|
356
|
+
else this.classList.remove("center");
|
|
357
|
+
}
|
|
358
|
+
get center() {
|
|
359
|
+
return this.classList.contains("center");
|
|
360
|
+
}
|
|
361
|
+
/**Called when value is changed */
|
|
362
|
+
new_value(value) {
|
|
363
|
+
if (value) this.classList.add("active");
|
|
364
|
+
else this.classList.remove("active");
|
|
365
|
+
}
|
|
366
|
+
clear_value() {
|
|
367
|
+
this.new_value(false);
|
|
368
|
+
}
|
|
369
|
+
new_error(err) {
|
|
370
|
+
console.error("TODO", err);
|
|
371
|
+
}
|
|
372
|
+
clear_error() {}
|
|
373
|
+
state_related(_related) {}
|
|
374
|
+
/**Changes whether the button is maintained or momentary*/
|
|
375
|
+
set toggle(toggle) {
|
|
376
|
+
this.#toggle = Boolean(toggle);
|
|
377
|
+
}
|
|
378
|
+
get toggle() {
|
|
379
|
+
return this.#toggle;
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
define_element(FormButton);
|
|
383
|
+
/**Creates a button form element */
|
|
384
|
+
function form_button(options) {
|
|
385
|
+
const butt = new FormButton(options?.id);
|
|
386
|
+
if (options) {
|
|
387
|
+
if (options.text) butt.text = options.text;
|
|
388
|
+
if (options.icon) butt.icon = options.icon;
|
|
389
|
+
if (options.on_click) butt.on_click = options.on_click;
|
|
390
|
+
if (options.toggle) butt.toggle = options.toggle;
|
|
391
|
+
if (options.color) butt.color = options.color;
|
|
392
|
+
if (options.center) butt.center = options.center;
|
|
393
|
+
FormValueWrite.apply_options(butt, options);
|
|
394
|
+
}
|
|
395
|
+
return butt;
|
|
396
|
+
}
|
|
397
|
+
// src/form/boolean/lamp/lamp.ts
|
|
398
|
+
var FormLamp = class extends FormValue {
|
|
399
|
+
static element_name() {
|
|
400
|
+
return "lamp";
|
|
401
|
+
}
|
|
402
|
+
static element_name_space() {
|
|
403
|
+
return "form";
|
|
404
|
+
}
|
|
405
|
+
#text = this.appendChild(document.createElement("span"));
|
|
406
|
+
#icon;
|
|
407
|
+
#colors = [];
|
|
408
|
+
/**Sets the current text of the lamp*/
|
|
409
|
+
set text(label) {
|
|
410
|
+
this.#text.textContent = label;
|
|
411
|
+
}
|
|
412
|
+
get text() {
|
|
413
|
+
return this.#text.textContent;
|
|
414
|
+
}
|
|
415
|
+
/**Changes the icon of the lamp*/
|
|
416
|
+
set icon(icon) {
|
|
417
|
+
if (icon) this.#icon = this.insertBefore(icon(), this.#text);
|
|
418
|
+
else if (this.#icon) {
|
|
419
|
+
this.removeChild(this.#icon);
|
|
420
|
+
this.#icon = void 0;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
/** Sets the background color of the lamp*/
|
|
424
|
+
set colors(colors) {
|
|
425
|
+
this.#colors = colors;
|
|
426
|
+
this.new_value(this.buffer);
|
|
427
|
+
}
|
|
428
|
+
/**Centers text and icon */
|
|
429
|
+
set center(center) {
|
|
430
|
+
if (center) this.classList.add("center");
|
|
431
|
+
else this.classList.remove("center");
|
|
432
|
+
}
|
|
433
|
+
get center() {
|
|
434
|
+
return this.classList.contains("center");
|
|
435
|
+
}
|
|
436
|
+
/**Called when value is changed */
|
|
437
|
+
new_value(value) {
|
|
438
|
+
const color = this.#colors[Number(value)];
|
|
439
|
+
if (color) this.setAttribute("color", color);
|
|
440
|
+
else this.removeAttribute("color");
|
|
441
|
+
}
|
|
442
|
+
clear_value() {
|
|
443
|
+
this.removeAttribute("color");
|
|
444
|
+
}
|
|
445
|
+
new_error(err) {
|
|
446
|
+
console.error(err);
|
|
447
|
+
}
|
|
448
|
+
clear_error() {}
|
|
449
|
+
state_related(_related) {}
|
|
450
|
+
};
|
|
451
|
+
define_element(FormLamp);
|
|
452
|
+
function from(options) {
|
|
453
|
+
const lamp = new FormLamp(options?.id);
|
|
454
|
+
if (options) {
|
|
455
|
+
lamp.colors = options.colors;
|
|
456
|
+
if (options.text) lamp.text = options.text;
|
|
457
|
+
if (options.icon) lamp.icon = options.icon;
|
|
458
|
+
if (options.center) lamp.center = options.center;
|
|
459
|
+
FormValue.apply_options(lamp, options);
|
|
460
|
+
}
|
|
461
|
+
return lamp;
|
|
462
|
+
}
|
|
463
|
+
/**Creates a button form element */
|
|
464
|
+
const form_lamp = from;
|
|
465
|
+
// src/form/boolean/switch/switch.ts
|
|
466
|
+
var FormSwitch = class extends FormValueWrite {
|
|
467
|
+
static element_name() {
|
|
468
|
+
return "switch";
|
|
469
|
+
}
|
|
470
|
+
static element_name_space() {
|
|
471
|
+
return "form";
|
|
472
|
+
}
|
|
473
|
+
#switch = this.appendChild(document.createElement("div"));
|
|
474
|
+
#icon;
|
|
475
|
+
#prevent_click = false;
|
|
476
|
+
constructor(id) {
|
|
477
|
+
super(id);
|
|
478
|
+
this.appendChild(this.warn_input);
|
|
479
|
+
this.#switch.setAttribute("tabindex", "0");
|
|
480
|
+
this.#switch.onkeydown = (e) => {
|
|
481
|
+
switch (e.key) {
|
|
482
|
+
case "Enter":
|
|
483
|
+
case " ":
|
|
484
|
+
e.stopPropagation();
|
|
485
|
+
e.preventDefault();
|
|
486
|
+
this.onkeyup = (e) => {
|
|
487
|
+
switch (e.key) {
|
|
488
|
+
case "Enter":
|
|
489
|
+
case " ":
|
|
490
|
+
e.stopPropagation();
|
|
491
|
+
e.preventDefault();
|
|
492
|
+
this.set_value_check(!this.buffer);
|
|
493
|
+
}
|
|
494
|
+
this.onkeyup = null;
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
this.#switch.onpointerdown = (e) => {
|
|
499
|
+
if (e.button === 0) {
|
|
500
|
+
e.stopPropagation();
|
|
501
|
+
this.#switch.classList.add("active");
|
|
502
|
+
this.#switch.setPointerCapture(e.pointerId);
|
|
503
|
+
let has_moved = false;
|
|
504
|
+
this.#switch.onpointermove = (ev) => {
|
|
505
|
+
ev.stopPropagation();
|
|
506
|
+
if (has_moved) {
|
|
507
|
+
const box = this.#switch.getBoundingClientRect();
|
|
508
|
+
const mid_cord = box.x + box.width / 2;
|
|
509
|
+
if (ev.clientX > mid_cord) {
|
|
510
|
+
if (!this.buffer) this.set_value_check(true);
|
|
511
|
+
} else if (this.buffer) this.set_value_check(false);
|
|
512
|
+
} else if (Math.abs(e.clientX - ev.clientX) > 10 || Math.abs(e.clientY - ev.clientY) > 10) has_moved = true;
|
|
513
|
+
};
|
|
514
|
+
this.#switch.onpointerup = (ev) => {
|
|
515
|
+
ev.stopPropagation();
|
|
516
|
+
this.#switch.classList.remove("active");
|
|
517
|
+
if (!has_moved) this.set_value_check(!this.buffer);
|
|
518
|
+
this.#switch.releasePointerCapture(e.pointerId);
|
|
519
|
+
this.#switch.onpointerup = null;
|
|
520
|
+
this.#switch.onpointermove = null;
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
this.#switch.onclick = (e) => e.stopPropagation();
|
|
525
|
+
this.onclick = (e) => {
|
|
526
|
+
e.stopPropagation();
|
|
527
|
+
if (this.#prevent_click) return this.#prevent_click = false;
|
|
528
|
+
this.set_value_check(!this.buffer);
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
/**Changes the icon of the switch*/
|
|
532
|
+
set icon(icon) {
|
|
533
|
+
if (icon) this.#icon = this.insertBefore(icon(), this.#switch);
|
|
534
|
+
else if (this.#icon) {
|
|
535
|
+
this.removeChild(this.#icon);
|
|
536
|
+
this.#icon = void 0;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
set on_color(color) {
|
|
540
|
+
if (color === FormColors.None) this.#switch.removeAttribute("on-color");
|
|
541
|
+
else this.#switch.setAttribute("on-color", color);
|
|
542
|
+
}
|
|
543
|
+
set off_color(color) {
|
|
544
|
+
if (color === FormColors.None) this.#switch.removeAttribute("off-color");
|
|
545
|
+
else this.#switch.setAttribute("off-color", color);
|
|
546
|
+
}
|
|
547
|
+
set error_color(color) {
|
|
548
|
+
if (color === FormColors.None) this.#switch.removeAttribute("error-color");
|
|
549
|
+
else this.#switch.setAttribute("error-color", color);
|
|
550
|
+
}
|
|
551
|
+
/**Called when value is changed */
|
|
552
|
+
new_value(value) {
|
|
553
|
+
if (value) this.#switch.classList.add("on");
|
|
554
|
+
else this.#switch.classList.remove("on");
|
|
555
|
+
}
|
|
556
|
+
clear_value() {
|
|
557
|
+
this.new_value(false);
|
|
558
|
+
}
|
|
559
|
+
new_error(_err) {
|
|
560
|
+
this.#switch.classList.add("error");
|
|
561
|
+
}
|
|
562
|
+
clear_error() {
|
|
563
|
+
this.#switch.classList.remove("error");
|
|
564
|
+
}
|
|
565
|
+
state_related(_related) {}
|
|
566
|
+
};
|
|
567
|
+
define_element(FormSwitch);
|
|
568
|
+
/**Creates a switch form element */
|
|
569
|
+
function form_switch(options) {
|
|
570
|
+
const swit = new FormSwitch(options?.id);
|
|
571
|
+
if (options) {
|
|
572
|
+
if (options.icon) swit.icon = options.icon;
|
|
573
|
+
if (options.on_color) swit.on_color = options.on_color;
|
|
574
|
+
if (options.off_color) swit.off_color = options.off_color;
|
|
575
|
+
FormValueWrite.apply_options(swit, options);
|
|
576
|
+
}
|
|
577
|
+
return swit;
|
|
578
|
+
}
|
|
579
|
+
// src/form/group/group_base.ts
|
|
580
|
+
/**Different border styles for the component group*/
|
|
581
|
+
const FormGroupBorderStyle = {
|
|
582
|
+
None: "none",
|
|
583
|
+
Inset: "inset",
|
|
584
|
+
Outset: "outset",
|
|
585
|
+
Line: "line"
|
|
586
|
+
};
|
|
587
|
+
var FormGroupBase = class extends FormValueWrite {
|
|
588
|
+
static element_name() {
|
|
589
|
+
return "@abstract@";
|
|
590
|
+
}
|
|
591
|
+
static element_name_space() {
|
|
592
|
+
return "form";
|
|
593
|
+
}
|
|
594
|
+
_value_elements = /* @__PURE__ */ new Map();
|
|
595
|
+
/**Returns form elements indexed by their form IDs*/
|
|
596
|
+
get value_elements() {
|
|
597
|
+
return Object.fromEntries(this._value_elements);
|
|
598
|
+
}
|
|
599
|
+
/**This places the group at an absolute position in one of the corners of the container*/
|
|
600
|
+
set border(border) {
|
|
601
|
+
this.classList.remove(FormGroupBorderStyle.Inset, FormGroupBorderStyle.Outset);
|
|
602
|
+
if (border && border !== FormGroupBorderStyle.None) this.classList.add(border);
|
|
603
|
+
}
|
|
604
|
+
set max_height(height) {
|
|
605
|
+
this.style.setProperty("--max_height", height ? height + "rem" : "none");
|
|
606
|
+
if (height) this.classList.add("max_height");
|
|
607
|
+
else this.classList.remove("max_height");
|
|
608
|
+
}
|
|
609
|
+
set embed(embed) {
|
|
610
|
+
if (embed) this.classList.add("embed");
|
|
611
|
+
else this.classList.remove("embed");
|
|
612
|
+
}
|
|
613
|
+
set value(val) {
|
|
614
|
+
super.value = val;
|
|
615
|
+
}
|
|
616
|
+
/**Returns value of the group, returning err if any component has no value*/
|
|
617
|
+
get get_value() {
|
|
618
|
+
if (this._state) return err("State based component");
|
|
619
|
+
const result = {};
|
|
620
|
+
for (const [key, comp] of this._value_elements) {
|
|
621
|
+
const val = comp.get_value;
|
|
622
|
+
if (val.err) return err("Component with id " + key + " has no value");
|
|
623
|
+
result[key] = val.value;
|
|
624
|
+
}
|
|
625
|
+
return ok(result);
|
|
626
|
+
}
|
|
627
|
+
/**Returns partial value of the group, containing all values of components that have values*/
|
|
628
|
+
get value_partial() {
|
|
629
|
+
if (this._state) return err("State based component");
|
|
630
|
+
const result = {};
|
|
631
|
+
for (const [key, comp] of this._value_elements) {
|
|
632
|
+
const val = comp.get_value;
|
|
633
|
+
if (val.err) continue;
|
|
634
|
+
result[key] = val.value;
|
|
635
|
+
}
|
|
636
|
+
return ok(result);
|
|
637
|
+
}
|
|
638
|
+
/**Returns partial value of the group, only containing values of components where value has changed*/
|
|
639
|
+
get value_changed() {
|
|
640
|
+
if (this._state) return err("State based component");
|
|
641
|
+
const result = {};
|
|
642
|
+
for (const [key, comp] of this._value_elements) {
|
|
643
|
+
const val = comp.get_value;
|
|
644
|
+
if (val.err) continue;
|
|
645
|
+
if (comp.changed) result[key] = val.value;
|
|
646
|
+
}
|
|
647
|
+
return ok(result);
|
|
648
|
+
}
|
|
649
|
+
new_value(val) {
|
|
650
|
+
for (const key in val) if (this._value_elements.has(key)) this._value_elements.get(key).value = val[key];
|
|
651
|
+
}
|
|
652
|
+
clear_value() {
|
|
653
|
+
for (const comp of this._value_elements.values()) comp.clear();
|
|
654
|
+
}
|
|
655
|
+
new_error(err) {
|
|
656
|
+
console.error(err);
|
|
657
|
+
}
|
|
658
|
+
clear_error() {}
|
|
659
|
+
state_related(_related) {}
|
|
660
|
+
on_access(access) {
|
|
661
|
+
switch (access) {
|
|
662
|
+
case AccessTypes.Read:
|
|
663
|
+
this.tabIndex = 0;
|
|
664
|
+
this.onfocus = () => document.body.focus();
|
|
665
|
+
break;
|
|
666
|
+
case AccessTypes.Write:
|
|
667
|
+
this.removeAttribute("tabIndex");
|
|
668
|
+
this.onfocus = null;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
// src/form/group/group.ts
|
|
673
|
+
/**Component group class which allows to add elements and controls the flow of the elements*/
|
|
674
|
+
var FormGroup = class extends FormGroupBase {
|
|
675
|
+
static element_name() {
|
|
676
|
+
return "group";
|
|
677
|
+
}
|
|
678
|
+
static element_name_space() {
|
|
679
|
+
return "form";
|
|
680
|
+
}
|
|
681
|
+
constructor(id) {
|
|
682
|
+
super(id);
|
|
683
|
+
this.classList.add("flex-col");
|
|
684
|
+
}
|
|
685
|
+
set column(column) {
|
|
686
|
+
this.classList.remove("grid-row", "grid-col", "flex-row", "flex-col");
|
|
687
|
+
if (column === true) this.classList.add("flex-col");
|
|
688
|
+
else {
|
|
689
|
+
this.classList.add("grid-col");
|
|
690
|
+
if (typeof column === "string") this.style.gridTemplateColumns = "repeat(auto-fit, minmax(" + column + ", 1fr))";
|
|
691
|
+
else this.style.gridTemplateColumns = column.map((col) => "minmax(" + col + ", 1fr)").join(" ");
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
set row(row) {
|
|
695
|
+
this.classList.remove("grid-row", "grid-col", "flex-row", "flex-col");
|
|
696
|
+
if (row === true) this.classList.add("flex-row");
|
|
697
|
+
else {
|
|
698
|
+
this.classList.add("grid-row");
|
|
699
|
+
if (typeof row === "string") this.style.gridTemplateRows = "repeat(auto-fit, minmax(" + row + ", 1fr))";
|
|
700
|
+
else this.style.gridTemplateRows = row.map((col) => "minmax(" + col + ", 1fr)").join(" ");
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
set elements(elements) {
|
|
704
|
+
for (let i = 0, n = elements.length; i < n; i++) {
|
|
705
|
+
const comp = elements[i];
|
|
706
|
+
if (comp instanceof FormValueWrite && comp.form_id) {
|
|
707
|
+
if (this._value_elements.has(comp.form_id)) {
|
|
708
|
+
console.error("Form element with form id " + comp.form_id + " already exists in group");
|
|
709
|
+
continue;
|
|
710
|
+
}
|
|
711
|
+
this._value_elements.set(comp.form_id, comp);
|
|
712
|
+
}
|
|
713
|
+
this.appendChild(comp);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
get elements() {
|
|
717
|
+
return [...this._value_elements.values()];
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
define_element(FormGroup);
|
|
721
|
+
/**Creates a form group with elements */
|
|
722
|
+
function form_group(options) {
|
|
723
|
+
const group = new FormGroup(options?.id);
|
|
724
|
+
if (options) {
|
|
725
|
+
if (options.border) group.border = options.border;
|
|
726
|
+
if (options.elements) group.elements = options.elements;
|
|
727
|
+
if (options.max_height) group.max_height = options.max_height;
|
|
728
|
+
if (options.embed) group.embed = options.embed;
|
|
729
|
+
if (options.column) group.column = options.column;
|
|
730
|
+
else if (options.row) group.row = options.row;
|
|
731
|
+
FormValueWrite.apply_options(group, options);
|
|
732
|
+
}
|
|
733
|
+
return group;
|
|
734
|
+
}
|
|
735
|
+
// src/form/group/group_collapser.ts
|
|
736
|
+
const opened_text = document.createElement("span");
|
|
737
|
+
opened_text.textContent = "Collapse";
|
|
738
|
+
const closed_text = document.createElement("span");
|
|
739
|
+
closed_text.textContent = "Expand";
|
|
740
|
+
/**Component group class which allows to add elements and controls the flow of the elements*/
|
|
741
|
+
var FormGroupCollapser = class extends FormElement {
|
|
742
|
+
static element_name() {
|
|
743
|
+
return "group-collapser";
|
|
744
|
+
}
|
|
745
|
+
static element_name_space() {
|
|
746
|
+
return "form";
|
|
747
|
+
}
|
|
748
|
+
#group;
|
|
749
|
+
#collapse_button;
|
|
750
|
+
#collapsed = false;
|
|
751
|
+
#open_text = node_clone(opened_text);
|
|
752
|
+
#close_text = node_clone(closed_text);
|
|
753
|
+
constructor(group, collapsed) {
|
|
754
|
+
super();
|
|
755
|
+
this.#group = this.appendChild(group);
|
|
756
|
+
if (collapsed) {
|
|
757
|
+
this.classList.add("collapsed");
|
|
758
|
+
this.#collapsed = true;
|
|
759
|
+
}
|
|
760
|
+
this.#collapse_button = this.appendChild(document.createElement("span"));
|
|
761
|
+
this.#collapse_button.tabIndex = 0;
|
|
762
|
+
this.#collapse_button.appendChild(collapsed ? this.#close_text : this.#open_text);
|
|
763
|
+
this.#collapse_button.appendChild(material_unfold_less_rounded());
|
|
764
|
+
this.#collapse_button.onclick = () => this.collapsed = !this.collapsed;
|
|
765
|
+
this.#collapse_button.onkeydown = (e) => {
|
|
766
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
767
|
+
e.preventDefault();
|
|
768
|
+
this.collapsed = !this.collapsed;
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
set group(group) {
|
|
773
|
+
const old_group = this.#group;
|
|
774
|
+
this.#group = this.replaceChild(group, old_group);
|
|
775
|
+
}
|
|
776
|
+
get group() {
|
|
777
|
+
return this.#group;
|
|
778
|
+
}
|
|
779
|
+
set collapsed(collapsed) {
|
|
780
|
+
if (collapsed && !this.#collapsed) {
|
|
781
|
+
this.#collapse_button.replaceChildren(this.#close_text, material_unfold_more_rounded());
|
|
782
|
+
if (ANIMATION_LEVEL.get().value === AnimationLevels.All) {
|
|
783
|
+
this.#group.style.overflowY = "auto";
|
|
784
|
+
const full_height = this.#group.getBoundingClientRect().height + "px";
|
|
785
|
+
const animation = this.#group.animate([{ maxHeight: full_height }, {
|
|
786
|
+
maxHeight: "0px",
|
|
787
|
+
paddingBlock: "0px"
|
|
788
|
+
}], {
|
|
789
|
+
duration: ANIMATION_SPEED.get().value,
|
|
790
|
+
easing: "ease-in-out"
|
|
791
|
+
});
|
|
792
|
+
animation.onfinish = async () => {
|
|
793
|
+
this.classList.add("collapsed");
|
|
794
|
+
this.#group.style.overflowY = "";
|
|
795
|
+
};
|
|
796
|
+
} else this.classList.add("collapsed");
|
|
797
|
+
} else if (!collapsed && this.#collapsed) {
|
|
798
|
+
this.classList.remove("collapsed");
|
|
799
|
+
this.#collapse_button.replaceChildren(this.#open_text, material_unfold_less_rounded());
|
|
800
|
+
if (ANIMATION_LEVEL.get().value === AnimationLevels.All) {
|
|
801
|
+
this.#group.style.overflowY = "auto";
|
|
802
|
+
const full_height = this.#group.getBoundingClientRect().height + "px";
|
|
803
|
+
const animation = this.#group.animate([{
|
|
804
|
+
maxHeight: "0px",
|
|
805
|
+
paddingBlock: "0px"
|
|
806
|
+
}, { maxHeight: full_height }], {
|
|
807
|
+
duration: ANIMATION_SPEED.get().value,
|
|
808
|
+
easing: "ease-in-out"
|
|
809
|
+
});
|
|
810
|
+
animation.onfinish = () => this.#group.style.overflowY = "";
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
this.#collapsed = collapsed;
|
|
814
|
+
}
|
|
815
|
+
get collapsed() {
|
|
816
|
+
return this.#collapsed;
|
|
817
|
+
}
|
|
818
|
+
set opened_text(text) {
|
|
819
|
+
this.#open_text.textContent = text;
|
|
820
|
+
}
|
|
821
|
+
set closed_text(text) {
|
|
822
|
+
this.#close_text.textContent = text;
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
define_element(FormGroupCollapser);
|
|
826
|
+
/**Creates a dropdown form element */
|
|
827
|
+
function form_group_collapser(group, options) {
|
|
828
|
+
const slide = new FormGroupCollapser(group, options?.collapsed);
|
|
829
|
+
if (options) {
|
|
830
|
+
if (options.opened_text) slide.opened_text = options.opened_text;
|
|
831
|
+
if (options.closed_text) slide.closed_text = options.closed_text;
|
|
832
|
+
FormElement.apply_options(slide, options);
|
|
833
|
+
}
|
|
834
|
+
return slide;
|
|
835
|
+
}
|
|
836
|
+
// src/form/list/list_field.ts
|
|
837
|
+
var ListFormField = class extends ListField {
|
|
838
|
+
static element_name() {
|
|
839
|
+
return "listfield";
|
|
840
|
+
}
|
|
841
|
+
static element_name_space() {
|
|
842
|
+
return "form";
|
|
843
|
+
}
|
|
844
|
+
set element(component) {
|
|
845
|
+
this.replaceChildren(component);
|
|
846
|
+
}
|
|
847
|
+
get element() {
|
|
848
|
+
return this.firstElementChild;
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
define_element(ListFormField);
|
|
852
|
+
function form_list_field(element) {
|
|
853
|
+
const field = new ListFormField();
|
|
854
|
+
field.element = element;
|
|
855
|
+
return field;
|
|
856
|
+
}
|
|
857
|
+
// src/form/number/number_base.ts
|
|
858
|
+
var FormNumberWrite = class extends FormValueWrite {
|
|
859
|
+
static apply_options(element, options) {
|
|
860
|
+
if (options.unit) element.unit = options.unit;
|
|
861
|
+
if (options.decimals) element.decimals = options.decimals;
|
|
862
|
+
if (options.min !== void 0) element.min = options.min;
|
|
863
|
+
if (options.max !== void 0) element.max = options.max;
|
|
864
|
+
if (options.step) element.step = options.step;
|
|
865
|
+
if (options.start) element.start = options.start;
|
|
866
|
+
super.apply_options(element, options);
|
|
867
|
+
}
|
|
868
|
+
state_related(related) {
|
|
869
|
+
if (related.min) this.attach_state_to_prop("min", related.min, () => none());
|
|
870
|
+
else this.detach_state_from_prop("min");
|
|
871
|
+
if (related.max) this.attach_state_to_prop("max", related.max, () => none());
|
|
872
|
+
else this.detach_state_from_prop("max");
|
|
873
|
+
if (related.step) this.attach_state_to_prop("step", related.step, () => none());
|
|
874
|
+
else this.detach_state_from_prop("step");
|
|
875
|
+
if (related.start) this.attach_state_to_prop("start", related.start, () => none());
|
|
876
|
+
else this.detach_state_from_prop("start");
|
|
877
|
+
if (related.decimals) this.attach_state_to_prop("decimals", related.decimals, () => none());
|
|
878
|
+
else this.detach_state_from_prop("decimals");
|
|
879
|
+
if (related.unit) this.attach_state_to_prop("unit", related.unit, () => none());
|
|
880
|
+
else this.detach_state_from_prop("unit");
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
// src/form/number/number_input/number_input.ts
|
|
884
|
+
var FormNumberInput = class extends FormNumberWrite {
|
|
885
|
+
static element_name() {
|
|
886
|
+
return "numberinput";
|
|
887
|
+
}
|
|
888
|
+
static element_name_space() {
|
|
889
|
+
return "form";
|
|
890
|
+
}
|
|
891
|
+
#unit = "";
|
|
892
|
+
#min = -Infinity;
|
|
893
|
+
#max = Infinity;
|
|
894
|
+
#step = 0;
|
|
895
|
+
#start = 0;
|
|
896
|
+
#decimals = 0;
|
|
897
|
+
#value_box = this.appendChild(document.createElement("span"));
|
|
898
|
+
#unit_box = this.appendChild(document.createElement("span"));
|
|
899
|
+
#legend = this.appendChild(document.createElement("div"));
|
|
900
|
+
#max_legend = this.#legend.appendChild(document.createElement("span"));
|
|
901
|
+
#min_legend = this.#legend.appendChild(document.createElement("span"));
|
|
902
|
+
constructor(id) {
|
|
903
|
+
super(id);
|
|
904
|
+
this.appendChild(this.warn_input);
|
|
905
|
+
this.#value_box.contentEditable = "true";
|
|
906
|
+
this.onpointerdown = (e) => {
|
|
907
|
+
this.selected = true;
|
|
908
|
+
if (e.target !== this.#value_box) {
|
|
909
|
+
e.preventDefault();
|
|
910
|
+
set_cursor_end(this.#value_box);
|
|
911
|
+
} else this.#value_box.focus();
|
|
912
|
+
};
|
|
913
|
+
this.#value_box.addEventListener("focusin", (e) => {
|
|
914
|
+
e.preventDefault();
|
|
915
|
+
if (this.selected) return;
|
|
916
|
+
set_selection_all(this.#value_box);
|
|
917
|
+
this.selected = true;
|
|
918
|
+
});
|
|
919
|
+
this.#value_box.onblur = () => {
|
|
920
|
+
this.selected = false;
|
|
921
|
+
setTimeout(() => {
|
|
922
|
+
this.#set(false);
|
|
923
|
+
}, 0);
|
|
924
|
+
};
|
|
925
|
+
this.onkeydown = (e) => {
|
|
926
|
+
if (e.key === "Enter") this.#set(true);
|
|
927
|
+
else if (e.key === "Escape") {
|
|
928
|
+
if (this.buffer !== void 0) this.new_value(this.buffer);
|
|
929
|
+
else this.clear_value();
|
|
930
|
+
} else if (e.key === "ArrowUp") this.#step_value(true);
|
|
931
|
+
else if (e.key === "ArrowDown") this.#step_value(false);
|
|
932
|
+
else return;
|
|
933
|
+
e.preventDefault();
|
|
934
|
+
e.stopPropagation();
|
|
935
|
+
};
|
|
936
|
+
this.onbeforeinput = (e) => {
|
|
937
|
+
if (e.inputType === "insertParagraph") e.preventDefault();
|
|
938
|
+
else if (e.data) {
|
|
939
|
+
if (!/[\d,.-]/g.test(e.data)) e.preventDefault();
|
|
940
|
+
else if (/[,.]/g.test(e.data) && this.#decimals === 0) e.preventDefault();
|
|
941
|
+
else if (this.#min >= 0 && /-/g.test(e.data)) e.preventDefault();
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
async #set(cur) {
|
|
946
|
+
const sel = get_cursor_position(this.#value_box);
|
|
947
|
+
const buff = this.buffer;
|
|
948
|
+
(await this.set_value_check(parseFloat(this.#value_box.textContent?.replace(",", ".") || "") || 0)).map_err(() => {
|
|
949
|
+
this.new_value(buff || Math.max(Math.min(0, this.#max), this.#min));
|
|
950
|
+
set_cursor_end(this.#value_box);
|
|
951
|
+
}).map(() => {
|
|
952
|
+
if (!cur) return;
|
|
953
|
+
set_cursor_position(this.#value_box, sel);
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
focus(options) {
|
|
957
|
+
this.#value_box.focus(options);
|
|
958
|
+
}
|
|
959
|
+
set unit(unit) {
|
|
960
|
+
this.#unit = unit || "";
|
|
961
|
+
this.#unit_box.textContent = this.#unit;
|
|
962
|
+
}
|
|
963
|
+
set decimals(dec) {
|
|
964
|
+
this.#decimals = dec || 0;
|
|
965
|
+
this.#update_min_legend();
|
|
966
|
+
this.#update_max_lengend();
|
|
967
|
+
}
|
|
968
|
+
set min(min) {
|
|
969
|
+
this.#min = min ?? -Infinity;
|
|
970
|
+
this.#update_min_legend();
|
|
971
|
+
}
|
|
972
|
+
#update_min_legend() {
|
|
973
|
+
this.#min_legend.textContent = this.#min === -Infinity ? "" : "Min:" + this.#min.toFixed(this.#decimals);
|
|
974
|
+
}
|
|
975
|
+
set max(max) {
|
|
976
|
+
this.#max = max ?? Infinity;
|
|
977
|
+
this.#update_max_lengend();
|
|
978
|
+
}
|
|
979
|
+
#update_max_lengend() {
|
|
980
|
+
this.#max_legend.textContent = this.#max === Infinity ? "" : "Max:" + this.#max.toFixed(this.#decimals);
|
|
981
|
+
}
|
|
982
|
+
set step(step) {
|
|
983
|
+
this.#step = step || 0;
|
|
984
|
+
}
|
|
985
|
+
set start(step) {
|
|
986
|
+
this.#start = step || 0;
|
|
987
|
+
}
|
|
988
|
+
new_value(val) {
|
|
989
|
+
this.#value_box.textContent = val.toFixed(this.#decimals);
|
|
990
|
+
}
|
|
991
|
+
clear_value() {
|
|
992
|
+
this.#value_box.textContent = "";
|
|
993
|
+
}
|
|
994
|
+
new_error(_val) {}
|
|
995
|
+
clear_error() {}
|
|
996
|
+
limit_value(val) {
|
|
997
|
+
let lim = number_step_start_decimal(Math.min(Math.max(val, this.#min), this.#max), this.#step, this.#start, this.#decimals);
|
|
998
|
+
if (lim < this.#min) lim += this.#step;
|
|
999
|
+
if (lim > this.#max) lim -= this.#step;
|
|
1000
|
+
return super.limit_value(lim);
|
|
1001
|
+
}
|
|
1002
|
+
check_value(val) {
|
|
1003
|
+
if (val < this.#min) return sync_resolve(err("Minimum value " + this.#min.toFixed(this.#decimals) + this.#unit));
|
|
1004
|
+
if (val > this.#max) return sync_resolve(err("Maximum value " + this.#max.toFixed(this.#decimals) + this.#unit));
|
|
1005
|
+
let lim = number_step_start_decimal(val, this.#step, this.#start, this.#decimals);
|
|
1006
|
+
if (lim < this.#min) lim += this.#step;
|
|
1007
|
+
if (lim > this.#max) lim -= this.#step;
|
|
1008
|
+
return super.check_value(lim);
|
|
1009
|
+
}
|
|
1010
|
+
#step_value(dir) {
|
|
1011
|
+
const step = this.#step || Math.max(this.#decimals ? 1 / this.#decimals : 1, Math.floor(Math.abs(this.buffer || 0) / 150));
|
|
1012
|
+
return this.set_value_check((this.buffer || 0) + (dir ? step : -step));
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
define_element(FormNumberInput);
|
|
1016
|
+
/**Creates a number input form element */
|
|
1017
|
+
function form_number_input(options) {
|
|
1018
|
+
const input = new FormNumberInput(options?.id);
|
|
1019
|
+
if (options) FormNumberWrite.apply_options(input, options);
|
|
1020
|
+
return input;
|
|
1021
|
+
}
|
|
1022
|
+
// src/form/number/progress/progress.ts
|
|
1023
|
+
var FormProgress = class extends FormValue {
|
|
1024
|
+
static element_name() {
|
|
1025
|
+
return "progress";
|
|
1026
|
+
}
|
|
1027
|
+
static element_name_space() {
|
|
1028
|
+
return "form";
|
|
1029
|
+
}
|
|
1030
|
+
#min = 0;
|
|
1031
|
+
#max = 100;
|
|
1032
|
+
#span = 100;
|
|
1033
|
+
#decimals = 0;
|
|
1034
|
+
#bar = this.appendChild(document.createElement("div"));
|
|
1035
|
+
#val = this.appendChild(document.createElement("span"));
|
|
1036
|
+
#unit = this.appendChild(document.createElement("span"));
|
|
1037
|
+
/**Set the minimum value*/
|
|
1038
|
+
set min(min) {
|
|
1039
|
+
this.#min = min;
|
|
1040
|
+
this.#span = this.#max - this.#min;
|
|
1041
|
+
}
|
|
1042
|
+
/**Set the minimum value*/
|
|
1043
|
+
set max(max) {
|
|
1044
|
+
this.#max = max;
|
|
1045
|
+
this.#span = this.#max - this.#min;
|
|
1046
|
+
}
|
|
1047
|
+
/**Sets the amount of decimals the element can have*/
|
|
1048
|
+
set decimals(dec) {
|
|
1049
|
+
this.#decimals = Math.max(dec ?? 0, 0);
|
|
1050
|
+
}
|
|
1051
|
+
/**Sets the unit of the element*/
|
|
1052
|
+
set unit(unit) {
|
|
1053
|
+
this.#unit.textContent = unit ?? "";
|
|
1054
|
+
}
|
|
1055
|
+
new_value(value) {
|
|
1056
|
+
this.#bar.style.width = Math.min(Math.max((value - this.#min) / this.#span * 100, 0), 100) + "%";
|
|
1057
|
+
this.#val.textContent = value.toFixed(this.#decimals);
|
|
1058
|
+
}
|
|
1059
|
+
clear_value() {
|
|
1060
|
+
this.#bar.style.width = "0%";
|
|
1061
|
+
this.#val.textContent = "";
|
|
1062
|
+
}
|
|
1063
|
+
new_error(err) {
|
|
1064
|
+
console.error(err);
|
|
1065
|
+
}
|
|
1066
|
+
clear_error() {}
|
|
1067
|
+
state_related(related) {
|
|
1068
|
+
if (related.min) this.attach_state_to_prop("min", related.min, () => none());
|
|
1069
|
+
else this.detach_state_from_prop("min");
|
|
1070
|
+
if (related.max) this.attach_state_to_prop("max", related.max, () => none());
|
|
1071
|
+
else this.detach_state_from_prop("max");
|
|
1072
|
+
if (related.decimals) this.attach_state_to_prop("decimals", related.decimals, () => none());
|
|
1073
|
+
else this.detach_state_from_prop("decimals");
|
|
1074
|
+
if (related.unit) this.attach_state_to_prop("unit", related.unit, () => none());
|
|
1075
|
+
else this.detach_state_from_prop("unit");
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
1078
|
+
define_element(FormProgress);
|
|
1079
|
+
/**Creates a progress form element */
|
|
1080
|
+
function form_progress(options) {
|
|
1081
|
+
const prog = new FormProgress(options?.id);
|
|
1082
|
+
if (options) {
|
|
1083
|
+
if (typeof options.min !== "undefined") prog.min = options.min;
|
|
1084
|
+
if (typeof options.max !== "undefined") prog.max = options.max;
|
|
1085
|
+
prog.decimals = options.decimals;
|
|
1086
|
+
prog.unit = options.unit;
|
|
1087
|
+
FormValue.apply_options(prog, options);
|
|
1088
|
+
}
|
|
1089
|
+
return prog;
|
|
1090
|
+
}
|
|
1091
|
+
// src/form/number/slider/slider.ts
|
|
1092
|
+
/**Slide Selector, displays all options in a slider*/
|
|
1093
|
+
var FormSlider = class extends FormNumberWrite {
|
|
1094
|
+
static element_name() {
|
|
1095
|
+
return "slider";
|
|
1096
|
+
}
|
|
1097
|
+
static element_name_space() {
|
|
1098
|
+
return "form";
|
|
1099
|
+
}
|
|
1100
|
+
#unit = "";
|
|
1101
|
+
#decimals = 0;
|
|
1102
|
+
#min = -Infinity;
|
|
1103
|
+
#max = Infinity;
|
|
1104
|
+
#span = Infinity;
|
|
1105
|
+
#step = 0;
|
|
1106
|
+
#start = 0;
|
|
1107
|
+
#live = false;
|
|
1108
|
+
#icon_dec = this.#stepper_func(this.appendChild(material_remove_rounded()), false);
|
|
1109
|
+
#slide = this.appendChild(document.createElement("div"));
|
|
1110
|
+
#legend = this.appendChild(document.createElement("span"));
|
|
1111
|
+
#left_legend = this.#legend.appendChild(document.createElement("span"));
|
|
1112
|
+
#right_legend = this.#legend.appendChild(document.createElement("span"));
|
|
1113
|
+
#icon_inc = this.#stepper_func(this.appendChild(material_add_rounded()), true);
|
|
1114
|
+
#slider = this.#slide.appendChild(document.createElement("div"));
|
|
1115
|
+
#value_box = this.#slider.appendChild(document.createElement("span"));
|
|
1116
|
+
#unit_box = this.#slider.appendChild(document.createElement("span"));
|
|
1117
|
+
constructor(id) {
|
|
1118
|
+
super(id);
|
|
1119
|
+
this.#slider.setAttribute("tabindex", "0");
|
|
1120
|
+
this.appendChild(this.warn_input);
|
|
1121
|
+
this.onpointerdown = (e) => {
|
|
1122
|
+
if (e.button !== 0) return;
|
|
1123
|
+
if (e.pointerType !== "mouse" && !this.#slider.contains(e.target)) return;
|
|
1124
|
+
e.stopPropagation();
|
|
1125
|
+
this.#slider.classList.add("active");
|
|
1126
|
+
this.selected = true;
|
|
1127
|
+
const box = this.#slider.getBoundingClientRect();
|
|
1128
|
+
const offset = this.#slider.contains(e.target) ? e.clientX >= box.x ? e.clientX <= box.x + box.width ? box.x - e.clientX : -box.width : 0 : -box.width / 2;
|
|
1129
|
+
if (this.#min === -Infinity || this.#max === Infinity) {
|
|
1130
|
+
let value = this.buffer || 0;
|
|
1131
|
+
const interval = setInterval(async () => {
|
|
1132
|
+
const val = value += diff / 50;
|
|
1133
|
+
if (this.#live) (await this.set_value_limit(val)).map((v) => value = v);
|
|
1134
|
+
else (await this.limit_value(val)).map((v) => {
|
|
1135
|
+
this.#move_value(v);
|
|
1136
|
+
value = v;
|
|
1137
|
+
});
|
|
1138
|
+
}, 100);
|
|
1139
|
+
let diff = this.#x_to_perc(e.clientX + offset) - 50;
|
|
1140
|
+
this.#move_slide(this.#x_to_perc(e.clientX + offset));
|
|
1141
|
+
this.#slider.setPointerCapture(e.pointerId);
|
|
1142
|
+
this.#slider.onpointermove = (ev) => {
|
|
1143
|
+
ev.stopPropagation();
|
|
1144
|
+
const perc = this.#x_to_perc(ev.clientX + offset);
|
|
1145
|
+
diff = (this.#step || 1) * ((perc - 50) * 2);
|
|
1146
|
+
this.#move_slide(perc);
|
|
1147
|
+
};
|
|
1148
|
+
const reset = () => {
|
|
1149
|
+
this.#slider.classList.remove("active");
|
|
1150
|
+
this.selected = false;
|
|
1151
|
+
this.#slider.releasePointerCapture(e.pointerId);
|
|
1152
|
+
this.#slider.onpointermove = null;
|
|
1153
|
+
this.#slider.onpointerup = null;
|
|
1154
|
+
this.#move_slide(50);
|
|
1155
|
+
clearInterval(interval);
|
|
1156
|
+
};
|
|
1157
|
+
this.#slider.onpointerup = (ev) => {
|
|
1158
|
+
ev.stopPropagation();
|
|
1159
|
+
reset();
|
|
1160
|
+
if (!this.#live) this.set_value_limit(value);
|
|
1161
|
+
};
|
|
1162
|
+
this.#slider.onkeydown = (e) => {
|
|
1163
|
+
if (e.key === "Escape") {
|
|
1164
|
+
e.preventDefault();
|
|
1165
|
+
e.stopPropagation();
|
|
1166
|
+
reset();
|
|
1167
|
+
if (this.buffer !== void 0) this.new_value(this.buffer);
|
|
1168
|
+
else this.clear_value();
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
} else {
|
|
1172
|
+
const value = this.buffer || 0;
|
|
1173
|
+
this.#move_absolute(e.clientX + offset);
|
|
1174
|
+
this.#slider.setPointerCapture(e.pointerId);
|
|
1175
|
+
this.#slider.onpointermove = (ev) => {
|
|
1176
|
+
ev.stopPropagation();
|
|
1177
|
+
this.#move_absolute(ev.clientX + offset);
|
|
1178
|
+
};
|
|
1179
|
+
const reset = () => {
|
|
1180
|
+
this.#slider.classList.remove("active");
|
|
1181
|
+
this.selected = false;
|
|
1182
|
+
this.#slider.releasePointerCapture(e.pointerId);
|
|
1183
|
+
this.#slider.onpointermove = null;
|
|
1184
|
+
this.#slider.onpointerup = null;
|
|
1185
|
+
};
|
|
1186
|
+
this.#slider.onpointerup = (ev) => {
|
|
1187
|
+
ev.stopPropagation();
|
|
1188
|
+
reset();
|
|
1189
|
+
this.#move_absolute(ev.clientX + offset, value);
|
|
1190
|
+
};
|
|
1191
|
+
this.#slider.onkeydown = (e) => {
|
|
1192
|
+
if (e.key === "Escape") {
|
|
1193
|
+
e.preventDefault();
|
|
1194
|
+
e.stopPropagation();
|
|
1195
|
+
reset();
|
|
1196
|
+
if (this.buffer !== void 0) this.new_value(this.buffer);
|
|
1197
|
+
else this.clear_value();
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
this.#slide.onkeydown = (e) => {
|
|
1203
|
+
if (e.key === "ArrowRight") this.#step_value(true);
|
|
1204
|
+
else if (e.key === "ArrowLeft") this.#step_value(false);
|
|
1205
|
+
else return;
|
|
1206
|
+
e.preventDefault();
|
|
1207
|
+
e.stopPropagation();
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
focus(options) {
|
|
1211
|
+
this.#slider.focus(options);
|
|
1212
|
+
}
|
|
1213
|
+
set unit(unit) {
|
|
1214
|
+
this.#unit = unit || "";
|
|
1215
|
+
this.#unit_box.textContent = this.#unit;
|
|
1216
|
+
}
|
|
1217
|
+
set min(min) {
|
|
1218
|
+
this.#min = min ?? -Infinity;
|
|
1219
|
+
this.#update_min_max();
|
|
1220
|
+
this.#update_min_legend();
|
|
1221
|
+
}
|
|
1222
|
+
#update_min_legend() {
|
|
1223
|
+
this.#left_legend.textContent = this.#min === -Infinity ? "" : "Min:" + this.#min.toFixed(this.#decimals);
|
|
1224
|
+
}
|
|
1225
|
+
set max(max) {
|
|
1226
|
+
this.#max = max ?? Infinity;
|
|
1227
|
+
this.#update_min_max();
|
|
1228
|
+
this.#update_max_legend();
|
|
1229
|
+
}
|
|
1230
|
+
#update_max_legend() {
|
|
1231
|
+
this.#right_legend.textContent = this.#max === Infinity ? "" : this.#max.toFixed(this.#decimals) + ":Max";
|
|
1232
|
+
}
|
|
1233
|
+
#update_min_max() {
|
|
1234
|
+
this.#span = this.#max - this.#min;
|
|
1235
|
+
if (this.#span === Infinity) this.#move_slide(50);
|
|
1236
|
+
else if (this.buffer !== void 0) this.new_value(this.buffer);
|
|
1237
|
+
}
|
|
1238
|
+
set decimals(dec) {
|
|
1239
|
+
this.#decimals = dec || 0;
|
|
1240
|
+
this.#update_min_legend();
|
|
1241
|
+
this.#update_max_legend();
|
|
1242
|
+
}
|
|
1243
|
+
set step(step) {
|
|
1244
|
+
this.#step = step || 0;
|
|
1245
|
+
}
|
|
1246
|
+
set start(step) {
|
|
1247
|
+
this.#start = step || 0;
|
|
1248
|
+
}
|
|
1249
|
+
/**Set wether the slider is in live mode*/
|
|
1250
|
+
set live(live) {
|
|
1251
|
+
this.#live = live || false;
|
|
1252
|
+
}
|
|
1253
|
+
set icon_decrease(icon) {
|
|
1254
|
+
this.replaceChild(this.#icon_dec, this.#stepper_func(icon ? icon() : material_remove_rounded(), false));
|
|
1255
|
+
}
|
|
1256
|
+
set icon_increase(icon) {
|
|
1257
|
+
this.replaceChild(this.#icon_inc, this.#stepper_func(icon ? icon() : material_add_rounded(), true));
|
|
1258
|
+
}
|
|
1259
|
+
new_value(value) {
|
|
1260
|
+
this.#move_value(value);
|
|
1261
|
+
this.#move_slide(Math.min(Math.max((-this.#min + value) / this.#span * 100, 0), 100));
|
|
1262
|
+
}
|
|
1263
|
+
clear_value() {
|
|
1264
|
+
this.#value_box.textContent = "";
|
|
1265
|
+
this.#move_slide(50);
|
|
1266
|
+
}
|
|
1267
|
+
new_error(err) {
|
|
1268
|
+
console.error(err);
|
|
1269
|
+
}
|
|
1270
|
+
clear_error() {}
|
|
1271
|
+
limit_value(val) {
|
|
1272
|
+
let lim = number_step_start_decimal(Math.min(Math.max(val, this.#min), this.#max), this.#step, this.#start, this.#decimals);
|
|
1273
|
+
if (lim < this.#min) lim += this.#step;
|
|
1274
|
+
if (lim > this.#max) lim -= this.#step;
|
|
1275
|
+
return super.limit_value(lim);
|
|
1276
|
+
}
|
|
1277
|
+
check_value(val) {
|
|
1278
|
+
if (val < this.#min) return sync_resolve(err("Minimum value " + this.#min.toFixed(this.#decimals) + this.#unit));
|
|
1279
|
+
if (val > this.#max) return sync_resolve(err("Maximum value " + this.#max.toFixed(this.#decimals) + this.#unit));
|
|
1280
|
+
let lim = number_step_start_decimal(val, this.#step, this.#start, this.#decimals);
|
|
1281
|
+
if (lim < this.#min) lim += this.#step;
|
|
1282
|
+
if (lim > this.#max) lim -= this.#step;
|
|
1283
|
+
return super.check_value(lim);
|
|
1284
|
+
}
|
|
1285
|
+
async #move_absolute(x, last) {
|
|
1286
|
+
const perc = this.#x_to_perc(x);
|
|
1287
|
+
if (this.#live) this.set_value_limit(this.#perc_to_value(perc));
|
|
1288
|
+
else if (last === void 0) {
|
|
1289
|
+
const value = await this.limit_value(this.#perc_to_value(perc));
|
|
1290
|
+
if (value.ok) {
|
|
1291
|
+
this.#move_slide((-this.#min + value.value) / this.#span * 100);
|
|
1292
|
+
this.#move_value(value.value);
|
|
1293
|
+
}
|
|
1294
|
+
} else this.set_value_limit(this.#perc_to_value(perc));
|
|
1295
|
+
}
|
|
1296
|
+
#x_to_perc(x) {
|
|
1297
|
+
const box = this.#slide.getBoundingClientRect();
|
|
1298
|
+
return Math.min(100, Math.max(0, (x - box.x) / box.width * 100));
|
|
1299
|
+
}
|
|
1300
|
+
#perc_to_value(perc) {
|
|
1301
|
+
return perc / 100 * this.#span + this.#min;
|
|
1302
|
+
}
|
|
1303
|
+
/**Attaches click action to over time increase speed of stepping when holding step buttons */
|
|
1304
|
+
#stepper_func(icon, dir) {
|
|
1305
|
+
icon.onpointerdown = (e) => {
|
|
1306
|
+
if (e.button === 0) {
|
|
1307
|
+
e.stopPropagation();
|
|
1308
|
+
let interval = 0;
|
|
1309
|
+
let scaler_interval = 0;
|
|
1310
|
+
let scaler = 250;
|
|
1311
|
+
const release = () => {
|
|
1312
|
+
clearInterval(interval);
|
|
1313
|
+
clearInterval(scaler_interval);
|
|
1314
|
+
clearTimeout(timeout);
|
|
1315
|
+
icon.onpointerup = null;
|
|
1316
|
+
icon.releasePointerCapture(e.pointerId);
|
|
1317
|
+
icon.classList.remove("active");
|
|
1318
|
+
};
|
|
1319
|
+
icon.setPointerCapture(e.pointerId);
|
|
1320
|
+
icon.classList.add("active");
|
|
1321
|
+
const timeout = setTimeout(() => {
|
|
1322
|
+
this.#step_value(dir);
|
|
1323
|
+
interval = setInterval(() => this.#step_value(dir), scaler);
|
|
1324
|
+
scaler_interval = setInterval(() => {
|
|
1325
|
+
if (scaler > 20) scaler /= 1.1;
|
|
1326
|
+
clearInterval(interval);
|
|
1327
|
+
interval = setInterval(() => this.#step_value(dir), scaler);
|
|
1328
|
+
}, 1e3);
|
|
1329
|
+
}, 500);
|
|
1330
|
+
icon.onpointerup = () => {
|
|
1331
|
+
if (interval === 0) this.#step_value(dir);
|
|
1332
|
+
release();
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1336
|
+
return icon;
|
|
1337
|
+
}
|
|
1338
|
+
#step_value(dir) {
|
|
1339
|
+
const step = this.#step || Math.max(this.#decimals ? 1 / this.#decimals : 1, Math.floor(Math.abs(this.buffer || 0) / 150));
|
|
1340
|
+
return this.set_value_check((this.buffer || 0) + (dir ? step : -step));
|
|
1341
|
+
}
|
|
1342
|
+
#move_slide(perc) {
|
|
1343
|
+
this.#slider.style.left = perc + "%";
|
|
1344
|
+
}
|
|
1345
|
+
#move_value(value) {
|
|
1346
|
+
this.#value_box.textContent = value.toFixed(this.#decimals);
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
define_element(FormSlider);
|
|
1350
|
+
/**Creates a dropdown form element */
|
|
1351
|
+
function form_slider(options) {
|
|
1352
|
+
const slide = new FormSlider(options?.id);
|
|
1353
|
+
if (options) {
|
|
1354
|
+
if (options.live) slide.live = options.live;
|
|
1355
|
+
if (options.icon_decrease) slide.icon_decrease = options.icon_decrease;
|
|
1356
|
+
if (options.icon_increase) slide.icon_increase = options.icon_increase;
|
|
1357
|
+
FormNumberWrite.apply_options(slide, options);
|
|
1358
|
+
}
|
|
1359
|
+
return slide;
|
|
1360
|
+
}
|
|
1361
|
+
// src/form/number/stepper/stepper.ts
|
|
1362
|
+
/**Slide Selector, displays all options in a slider*/
|
|
1363
|
+
var FormStepper = class extends FormNumberWrite {
|
|
1364
|
+
static element_name() {
|
|
1365
|
+
return "stepper";
|
|
1366
|
+
}
|
|
1367
|
+
static element_name_space() {
|
|
1368
|
+
return "form";
|
|
1369
|
+
}
|
|
1370
|
+
#unit = "";
|
|
1371
|
+
#decimals = 0;
|
|
1372
|
+
#min = -Infinity;
|
|
1373
|
+
#max = Infinity;
|
|
1374
|
+
#step = 0;
|
|
1375
|
+
#start = 0;
|
|
1376
|
+
#live = false;
|
|
1377
|
+
#icon_dec = this.#stepper_func(this.appendChild(material_remove_rounded()), false);
|
|
1378
|
+
#text = this.appendChild(document.createElement("span"));
|
|
1379
|
+
#icon_inc = this.#stepper_func(this.appendChild(material_add_rounded()), true);
|
|
1380
|
+
#value_box = this.#text.appendChild(document.createElement("span"));
|
|
1381
|
+
#unit_box = this.#text.appendChild(document.createElement("span"));
|
|
1382
|
+
#legend = this.#text.appendChild(document.createElement("span"));
|
|
1383
|
+
#max_legend = this.#legend.appendChild(document.createElement("span"));
|
|
1384
|
+
#min_legend = this.#legend.appendChild(document.createElement("span"));
|
|
1385
|
+
constructor(id) {
|
|
1386
|
+
super(id);
|
|
1387
|
+
this.setAttribute("tabindex", "0");
|
|
1388
|
+
this.appendChild(this.warn_input);
|
|
1389
|
+
this.#value_box.setAttribute("tabindex", "-1");
|
|
1390
|
+
this.#value_box.contentEditable = "true";
|
|
1391
|
+
this.#value_box.onfocus = async () => {
|
|
1392
|
+
this.selected = true;
|
|
1393
|
+
};
|
|
1394
|
+
this.#value_box.onblur = async () => {
|
|
1395
|
+
this.selected = false;
|
|
1396
|
+
await sleep(0);
|
|
1397
|
+
this.set_value_check(parseFloat(this.#value_box.textContent?.replace(",", ".") || "") || 0);
|
|
1398
|
+
};
|
|
1399
|
+
this.#value_box.onpointerdown = () => {
|
|
1400
|
+
this.selected = true;
|
|
1401
|
+
};
|
|
1402
|
+
let pointer_id;
|
|
1403
|
+
const reset = () => {
|
|
1404
|
+
this.selected = false;
|
|
1405
|
+
this.#value_box.contentEditable = "true";
|
|
1406
|
+
if (pointer_id) this.#text.releasePointerCapture(pointer_id);
|
|
1407
|
+
this.#text.onpointermove = null;
|
|
1408
|
+
this.#text.onpointerup = null;
|
|
1409
|
+
};
|
|
1410
|
+
this.#text.onpointerdown = (e) => {
|
|
1411
|
+
if (e.button === 0 && !this.selected) {
|
|
1412
|
+
e.stopPropagation();
|
|
1413
|
+
this.selected = true;
|
|
1414
|
+
const initial_val = this.buffer || 0;
|
|
1415
|
+
let moving = false;
|
|
1416
|
+
this.#text.setPointerCapture(e.pointerId);
|
|
1417
|
+
pointer_id = e.pointerId;
|
|
1418
|
+
this.#text.onpointermove = (ev) => {
|
|
1419
|
+
ev.stopPropagation();
|
|
1420
|
+
if (moving) this.#move_diff(initial_val + (ev.clientX - e.clientX) / 10 * (this.#step || 1));
|
|
1421
|
+
else if (Math.abs(e.clientX - ev.clientX) > 5) {
|
|
1422
|
+
this.#value_box.contentEditable = "false";
|
|
1423
|
+
moving = true;
|
|
1424
|
+
}
|
|
1425
|
+
};
|
|
1426
|
+
this.#text.onpointerup = (ev) => {
|
|
1427
|
+
ev.stopPropagation();
|
|
1428
|
+
reset();
|
|
1429
|
+
if (!moving && e.target !== this.#value_box) {
|
|
1430
|
+
this.#value_box.focus();
|
|
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) {
|
|
1439
|
+
this.#move_diff(initial_val + (ev.clientX - e.clientX) / 10 * (this.#step || 1), true);
|
|
1440
|
+
moving = false;
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
this.onkeydown = (e) => {
|
|
1446
|
+
if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
|
|
1447
|
+
e.preventDefault();
|
|
1448
|
+
e.stopPropagation();
|
|
1449
|
+
this.#step_value(e.key === "ArrowRight");
|
|
1450
|
+
} else if (e.key === "Escape") {
|
|
1451
|
+
e.preventDefault();
|
|
1452
|
+
e.stopPropagation();
|
|
1453
|
+
if (reset) reset();
|
|
1454
|
+
if (this.buffer !== void 0) this.new_value(this.buffer);
|
|
1455
|
+
else this.clear_value();
|
|
1456
|
+
} else if (this.ownerDocument.activeElement !== this.#value_box && /[\d,.-]/g.test(e.key)) {
|
|
1457
|
+
this.#value_box.textContent = "";
|
|
1458
|
+
this.#value_box.focus();
|
|
1459
|
+
}
|
|
1460
|
+
};
|
|
1461
|
+
this.#value_box.onkeydown = (e) => {
|
|
1462
|
+
if (e.key === "Enter") HTMLElement.prototype.focus.call(this);
|
|
1463
|
+
else if (e.key === "Escape") {
|
|
1464
|
+
e.preventDefault();
|
|
1465
|
+
e.stopPropagation();
|
|
1466
|
+
if (this.buffer !== void 0) this.new_value(this.buffer);
|
|
1467
|
+
else this.clear_value();
|
|
1468
|
+
} else if (e.key === "ArrowRight" || e.key === "ArrowLeft") e.stopPropagation();
|
|
1469
|
+
};
|
|
1470
|
+
this.#value_box.onbeforeinput = (e) => {
|
|
1471
|
+
if (e.inputType === "insertParagraph") e.preventDefault();
|
|
1472
|
+
if (e.data) {
|
|
1473
|
+
if (!/[\d,.-]/g.test(e.data)) e.preventDefault();
|
|
1474
|
+
else if (/[,.]/g.test(e.data) && this.#decimals === 0) e.preventDefault();
|
|
1475
|
+
else if (this.#min >= 0 && /-/g.test(e.data) || this.#value_box.textContent?.includes("-")) e.preventDefault();
|
|
1476
|
+
}
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
focus(options) {
|
|
1480
|
+
this.#value_box.focus(options);
|
|
1481
|
+
}
|
|
1482
|
+
set unit(unit) {
|
|
1483
|
+
this.#unit = unit || "";
|
|
1484
|
+
this.#unit_box.textContent = this.#unit;
|
|
1485
|
+
}
|
|
1486
|
+
set decimals(dec) {
|
|
1487
|
+
this.#decimals = dec || 0;
|
|
1488
|
+
this.#update_min_legend();
|
|
1489
|
+
this.#update_max_lengend();
|
|
1490
|
+
}
|
|
1491
|
+
set min(min) {
|
|
1492
|
+
this.#min = min ?? -Infinity;
|
|
1493
|
+
this.#update_min_legend();
|
|
1494
|
+
}
|
|
1495
|
+
#update_min_legend() {
|
|
1496
|
+
this.#min_legend.textContent = this.#min === -Infinity ? "" : "Min:" + this.#min.toFixed(this.#decimals);
|
|
1497
|
+
}
|
|
1498
|
+
set max(max) {
|
|
1499
|
+
this.#max = max ?? Infinity;
|
|
1500
|
+
this.#update_max_lengend();
|
|
1501
|
+
}
|
|
1502
|
+
#update_max_lengend() {
|
|
1503
|
+
this.#max_legend.textContent = this.#max === Infinity ? "" : "Max:" + this.#max.toFixed(this.#decimals);
|
|
1504
|
+
}
|
|
1505
|
+
set step(step) {
|
|
1506
|
+
this.#step = step || 0;
|
|
1507
|
+
}
|
|
1508
|
+
set start(step) {
|
|
1509
|
+
this.#start = step || 0;
|
|
1510
|
+
}
|
|
1511
|
+
/**Set wether the slider is in live mode*/
|
|
1512
|
+
set live(live) {
|
|
1513
|
+
this.#live = live || false;
|
|
1514
|
+
}
|
|
1515
|
+
set icon_decrease(icon) {
|
|
1516
|
+
this.replaceChild(this.#icon_dec, this.#stepper_func(icon ? icon() : material_remove_rounded(), false));
|
|
1517
|
+
}
|
|
1518
|
+
set icon_increase(icon) {
|
|
1519
|
+
this.replaceChild(this.#icon_inc, this.#stepper_func(icon ? icon() : material_add_rounded(), true));
|
|
1520
|
+
}
|
|
1521
|
+
new_value(value) {
|
|
1522
|
+
this.#move_value(value);
|
|
1523
|
+
}
|
|
1524
|
+
clear_value() {
|
|
1525
|
+
this.#value_box.textContent = "";
|
|
1526
|
+
}
|
|
1527
|
+
new_error(err) {
|
|
1528
|
+
console.error(err);
|
|
1529
|
+
}
|
|
1530
|
+
clear_error() {}
|
|
1531
|
+
limit_value(val) {
|
|
1532
|
+
let lim = number_step_start_decimal(Math.min(Math.max(val, this.#min), this.#max), this.#step, this.#start, this.#decimals);
|
|
1533
|
+
if (lim < this.#min) lim += this.#step;
|
|
1534
|
+
if (lim > this.#max) lim -= this.#step;
|
|
1535
|
+
return super.limit_value(lim);
|
|
1536
|
+
}
|
|
1537
|
+
check_value(val) {
|
|
1538
|
+
if (val < this.#min) return sync_resolve(err("Minimum value " + this.#min.toFixed(this.#decimals) + this.#unit));
|
|
1539
|
+
if (val > this.#max) return sync_resolve(err("Maximum value " + this.#max.toFixed(this.#decimals) + this.#unit));
|
|
1540
|
+
let lim = number_step_start_decimal(val, this.#step, this.#start, this.#decimals);
|
|
1541
|
+
if (lim < this.#min) lim += this.#step;
|
|
1542
|
+
if (lim > this.#max) lim -= this.#step;
|
|
1543
|
+
return super.check_value(lim);
|
|
1544
|
+
}
|
|
1545
|
+
/**Moves the value to a position by the mouse x coordinates*/
|
|
1546
|
+
async #move_diff(value, last = false) {
|
|
1547
|
+
if (this.#live) this.set_value_limit(value);
|
|
1548
|
+
else if (last) this.set_value_limit(value);
|
|
1549
|
+
else {
|
|
1550
|
+
const lim = await this.limit_value(value);
|
|
1551
|
+
if (lim.ok) this.#move_value(lim.value);
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
/**Moves the slider to the given percent position*/
|
|
1555
|
+
#move_value(value) {
|
|
1556
|
+
this.#value_box.textContent = value.toFixed(this.#decimals);
|
|
1557
|
+
}
|
|
1558
|
+
/**Attaches click action to over time increase speed of stepping when holding step buttons */
|
|
1559
|
+
#stepper_func(icon, dir) {
|
|
1560
|
+
icon.onpointerdown = (e) => {
|
|
1561
|
+
if (e.button === 0) {
|
|
1562
|
+
e.stopPropagation();
|
|
1563
|
+
let interval = 0;
|
|
1564
|
+
let scaler_interval = 0;
|
|
1565
|
+
let scaler = 250;
|
|
1566
|
+
const release = () => {
|
|
1567
|
+
clearInterval(interval);
|
|
1568
|
+
clearInterval(scaler_interval);
|
|
1569
|
+
clearTimeout(timeout);
|
|
1570
|
+
icon.onpointerup = null;
|
|
1571
|
+
icon.releasePointerCapture(e.pointerId);
|
|
1572
|
+
icon.classList.remove("active");
|
|
1573
|
+
};
|
|
1574
|
+
icon.setPointerCapture(e.pointerId);
|
|
1575
|
+
icon.classList.add("active");
|
|
1576
|
+
const timeout = setTimeout(() => {
|
|
1577
|
+
this.#step_value(dir);
|
|
1578
|
+
interval = setInterval(() => this.#step_value(dir), scaler);
|
|
1579
|
+
scaler_interval = setInterval(() => {
|
|
1580
|
+
if (scaler > 20) scaler /= 1.1;
|
|
1581
|
+
clearInterval(interval);
|
|
1582
|
+
interval = setInterval(() => this.#step_value(dir), scaler);
|
|
1583
|
+
}, 1e3);
|
|
1584
|
+
}, 500);
|
|
1585
|
+
icon.onpointerup = () => {
|
|
1586
|
+
if (interval === 0) this.#step_value(dir);
|
|
1587
|
+
release();
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
return icon;
|
|
1592
|
+
}
|
|
1593
|
+
#step_value(dir) {
|
|
1594
|
+
const step = this.#step || Math.max(this.#decimals ? 1 / this.#decimals : 1, Math.floor(Math.abs(this.buffer || 0) / 150));
|
|
1595
|
+
return this.set_value_check((this.buffer || 0) + (dir ? step : -step));
|
|
1596
|
+
}
|
|
1597
|
+
};
|
|
1598
|
+
define_element(FormStepper);
|
|
1599
|
+
/**Creates a dropdown form element */
|
|
1600
|
+
function form_stepper(options) {
|
|
1601
|
+
const slide = new FormStepper(options?.id);
|
|
1602
|
+
if (options) {
|
|
1603
|
+
if (options.live) slide.live = options.live;
|
|
1604
|
+
if (options.icon_decrease) slide.icon_decrease = options.icon_decrease;
|
|
1605
|
+
if (options.icon_increase) slide.icon_increase = options.icon_increase;
|
|
1606
|
+
FormNumberWrite.apply_options(slide, options);
|
|
1607
|
+
}
|
|
1608
|
+
return slide;
|
|
1609
|
+
}
|
|
1610
|
+
// src/form/selectors/selector_base.ts
|
|
1611
|
+
/**Base for number elements elements*/
|
|
1612
|
+
var FormSelectorBase = class extends FormValueWrite {
|
|
1613
|
+
static apply_options(element, options) {
|
|
1614
|
+
if (options.selections) element.selections = options.selections;
|
|
1615
|
+
super.apply_options(element, options);
|
|
1616
|
+
}
|
|
1617
|
+
state_related(related) {
|
|
1618
|
+
if (related.list) this.attach_state_to_prop_map("selections", related.list, () => some([]), (val) => {
|
|
1619
|
+
return some(state.e.map(val, (key, val) => {
|
|
1620
|
+
return {
|
|
1621
|
+
text: val.name,
|
|
1622
|
+
value: key,
|
|
1623
|
+
icon: val.icon
|
|
1624
|
+
};
|
|
1625
|
+
}));
|
|
1626
|
+
});
|
|
1627
|
+
}
|
|
1628
|
+
};
|
|
1629
|
+
// src/form/selectors/drop_down/drop_down.ts
|
|
1630
|
+
/**Dropdown box for selecting between multiple choices in a small space*/
|
|
1631
|
+
var FormDropdown = class extends FormSelectorBase {
|
|
1632
|
+
static element_name() {
|
|
1633
|
+
return "dropdown";
|
|
1634
|
+
}
|
|
1635
|
+
static element_name_space() {
|
|
1636
|
+
return "form";
|
|
1637
|
+
}
|
|
1638
|
+
#map = /* @__PURE__ */ new Map();
|
|
1639
|
+
#values = [];
|
|
1640
|
+
#selected = -1;
|
|
1641
|
+
#icon;
|
|
1642
|
+
#text = this.appendChild(document.createElement("div"));
|
|
1643
|
+
#open = this.appendChild(material_keyboard_arrow_down_rounded());
|
|
1644
|
+
#default = document.createTextNode("Select something");
|
|
1645
|
+
#default_icon;
|
|
1646
|
+
is_open = false;
|
|
1647
|
+
constructor(id) {
|
|
1648
|
+
super(id);
|
|
1649
|
+
this.#text.append(this.#default);
|
|
1650
|
+
this.appendChild(this.warn_input);
|
|
1651
|
+
this.tabIndex = 0;
|
|
1652
|
+
this.onclick = () => this.open = true;
|
|
1653
|
+
this.onpointerdown = (e) => {
|
|
1654
|
+
if (e.pointerType === "mouse") {
|
|
1655
|
+
this.open = true;
|
|
1656
|
+
e.preventDefault();
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
this.onkeydown = (e) => {
|
|
1660
|
+
switch (e.key) {
|
|
1661
|
+
case " ":
|
|
1662
|
+
case "Enter":
|
|
1663
|
+
e.preventDefault();
|
|
1664
|
+
this.open = true;
|
|
1665
|
+
break;
|
|
1666
|
+
case "ArrowDown":
|
|
1667
|
+
case "ArrowUp":
|
|
1668
|
+
e.preventDefault();
|
|
1669
|
+
e.stopPropagation();
|
|
1670
|
+
this.#select_adjacent(e.key === "ArrowDown");
|
|
1671
|
+
}
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
focus(options) {
|
|
1675
|
+
HTMLElement.prototype.focus.call(this, options);
|
|
1676
|
+
}
|
|
1677
|
+
/**Gets the default text displayed when nothing has been selected yet */
|
|
1678
|
+
get default() {
|
|
1679
|
+
return this.#default.nodeValue || "";
|
|
1680
|
+
}
|
|
1681
|
+
/**Sets the default text displayed when nothing has been selected yet */
|
|
1682
|
+
set default(def) {
|
|
1683
|
+
this.#default.nodeValue = def;
|
|
1684
|
+
}
|
|
1685
|
+
/**Sets the default text displayed when nothing has been selected yet */
|
|
1686
|
+
set default_icon(def) {
|
|
1687
|
+
this.#default_icon = def;
|
|
1688
|
+
if (def && this.#selected === -1) this.#set_icon = def;
|
|
1689
|
+
}
|
|
1690
|
+
set selections(selections) {
|
|
1691
|
+
this.open = false;
|
|
1692
|
+
if (this.#map.size > 0) {
|
|
1693
|
+
this.#map.clear();
|
|
1694
|
+
this.#values = [];
|
|
1695
|
+
this.#selected = -1;
|
|
1696
|
+
}
|
|
1697
|
+
for (let i = 0; selections && i < selections.length; i++) {
|
|
1698
|
+
const { value, text, icon } = selections[i];
|
|
1699
|
+
this.#map.set(value, {
|
|
1700
|
+
text,
|
|
1701
|
+
icon
|
|
1702
|
+
});
|
|
1703
|
+
this.#values.push(value);
|
|
1704
|
+
}
|
|
1705
|
+
if (this.buffer !== void 0) this.new_value(this.buffer);
|
|
1706
|
+
}
|
|
1707
|
+
set open(open) {
|
|
1708
|
+
if (open && !this.is_open) {
|
|
1709
|
+
const old = this.#open;
|
|
1710
|
+
this.#open = material_unfold_less_rounded();
|
|
1711
|
+
old.replaceWith(this.#open);
|
|
1712
|
+
box.open_menu(this.#map, this, this.buffer);
|
|
1713
|
+
} else if (!open && this.is_open) {
|
|
1714
|
+
const old = this.#open;
|
|
1715
|
+
this.#open = material_keyboard_arrow_down_rounded();
|
|
1716
|
+
old.replaceWith(this.#open);
|
|
1717
|
+
box.close_menu();
|
|
1718
|
+
}
|
|
1719
|
+
this.is_open = open;
|
|
1720
|
+
}
|
|
1721
|
+
/**Changes the icon of the button*/
|
|
1722
|
+
set #set_icon(icon) {
|
|
1723
|
+
if (icon) {
|
|
1724
|
+
const i = icon();
|
|
1725
|
+
if (this.#icon) this.replaceChild(i, this.#icon);
|
|
1726
|
+
else this.insertBefore(i, this.#text);
|
|
1727
|
+
this.#icon = i;
|
|
1728
|
+
} else if (this.#icon) {
|
|
1729
|
+
this.removeChild(this.#icon);
|
|
1730
|
+
this.#icon = void 0;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
/**Selects the previous or next selection in the element
|
|
1734
|
+
* @param dir false is next true is previous*/
|
|
1735
|
+
#select_adjacent(dir) {
|
|
1736
|
+
const y = Math.min(this.#values.length - 1, Math.max(0, dir ? this.#selected + 1 : this.#selected - 1));
|
|
1737
|
+
if (y !== this.#selected) this.set_value_check(this.#values[y]);
|
|
1738
|
+
}
|
|
1739
|
+
#clear() {
|
|
1740
|
+
this.default_icon = this.#default_icon ? this.#set_icon = this.#default_icon : this.#set_icon = void 0;
|
|
1741
|
+
this.#text.replaceChildren(this.#default);
|
|
1742
|
+
}
|
|
1743
|
+
/**Called when Value is changed */
|
|
1744
|
+
new_value(value) {
|
|
1745
|
+
if (!this.#map.has(value)) {
|
|
1746
|
+
this.#clear();
|
|
1747
|
+
this.#selected = -1;
|
|
1748
|
+
return;
|
|
1749
|
+
}
|
|
1750
|
+
const opt = this.#map.get(value);
|
|
1751
|
+
this.#text.innerText = opt.text;
|
|
1752
|
+
this.#selected = this.#values.indexOf(value);
|
|
1753
|
+
if (opt.icon) this.#set_icon = opt.icon;
|
|
1754
|
+
else this.#set_icon = void 0;
|
|
1755
|
+
}
|
|
1756
|
+
clear_value() {
|
|
1757
|
+
this.#clear();
|
|
1758
|
+
}
|
|
1759
|
+
new_error(_val) {}
|
|
1760
|
+
clear_error() {}
|
|
1761
|
+
warn(message) {
|
|
1762
|
+
setTimeout(() => {
|
|
1763
|
+
super.warn(message);
|
|
1764
|
+
}, 0);
|
|
1765
|
+
}
|
|
1766
|
+
};
|
|
1767
|
+
define_element(FormDropdown);
|
|
1768
|
+
/**Creates a dropdown form element */
|
|
1769
|
+
function form_dropdown(options) {
|
|
1770
|
+
const drop = new FormDropdown(options?.id);
|
|
1771
|
+
if (options) {
|
|
1772
|
+
if (options.default) drop.default = options.default;
|
|
1773
|
+
if (options.default_icon) drop.default_icon = options.default_icon;
|
|
1774
|
+
FormSelectorBase.apply_options(drop, options);
|
|
1775
|
+
}
|
|
1776
|
+
return drop;
|
|
1777
|
+
}
|
|
1778
|
+
var DropDownBox = class extends Base {
|
|
1779
|
+
static element_name() {
|
|
1780
|
+
return "dropdownbox";
|
|
1781
|
+
}
|
|
1782
|
+
static element_name_space() {
|
|
1783
|
+
return "form";
|
|
1784
|
+
}
|
|
1785
|
+
#closer = document.createElement("div");
|
|
1786
|
+
#container = this.appendChild(document.createElement("div"));
|
|
1787
|
+
#scroll = this.#container.appendChild(document.createElement("div"));
|
|
1788
|
+
#table = this.#scroll.appendChild(document.createElement("div"));
|
|
1789
|
+
#dropdown;
|
|
1790
|
+
#focus_out_handler = (e) => {
|
|
1791
|
+
e.preventDefault();
|
|
1792
|
+
e.stopPropagation();
|
|
1793
|
+
if (!e.relatedTarget || !this.contains(e.relatedTarget)) this.close_menu();
|
|
1794
|
+
};
|
|
1795
|
+
#window_resize_handler = () => this.close_menu();
|
|
1796
|
+
#is_open = false;
|
|
1797
|
+
constructor() {
|
|
1798
|
+
super();
|
|
1799
|
+
this.#container.tabIndex = 0;
|
|
1800
|
+
this.#container.onkeydown = (e) => {
|
|
1801
|
+
if (e.key === "Escape") this.close_menu();
|
|
1802
|
+
else if (e.key === "ArrowUp" || e.shiftKey && e.key === "Tab") {
|
|
1803
|
+
const elem = e.target === this.#container ? this.#table.lastElementChild : e.target.previousElementSibling;
|
|
1804
|
+
if (elem) elem.focus();
|
|
1805
|
+
} else if (e.key === "ArrowDown" || e.key === "Tab") {
|
|
1806
|
+
const elem = e.target === this.#container ? this.#table.firstElementChild : e.target.nextElementSibling;
|
|
1807
|
+
if (elem) elem.focus();
|
|
1808
|
+
} else return;
|
|
1809
|
+
e.stopPropagation();
|
|
1810
|
+
e.preventDefault();
|
|
1811
|
+
};
|
|
1812
|
+
this.#closer.appendChild(document.createElement("div")).appendChild(material_close_rounded());
|
|
1813
|
+
this.#closer.appendChild(document.createElement("div")).innerHTML = "Close";
|
|
1814
|
+
this.#closer.tabIndex = 0;
|
|
1815
|
+
this.#closer.onclick = (e) => {
|
|
1816
|
+
e.stopPropagation();
|
|
1817
|
+
e.preventDefault();
|
|
1818
|
+
this.close_menu();
|
|
1819
|
+
};
|
|
1820
|
+
this.#closer.onkeydown = (e) => {
|
|
1821
|
+
if (e.key === " " || e.key === "Enter") {
|
|
1822
|
+
e.stopPropagation();
|
|
1823
|
+
e.preventDefault();
|
|
1824
|
+
this.close_menu();
|
|
1825
|
+
}
|
|
1826
|
+
};
|
|
1827
|
+
this.addEventListener("focusout", this.#focus_out_handler, { capture: true });
|
|
1828
|
+
}
|
|
1829
|
+
#set_value(value) {
|
|
1830
|
+
if (this.#dropdown) this.#dropdown.set_value_check(value);
|
|
1831
|
+
this.close_menu();
|
|
1832
|
+
}
|
|
1833
|
+
open_menu(map, parent, value) {
|
|
1834
|
+
const inner_height = this.ownerDocument.defaultView?.innerHeight || 0;
|
|
1835
|
+
this.classList.add("open");
|
|
1836
|
+
const bounds = parent.getBoundingClientRect();
|
|
1837
|
+
if (bounds.y + bounds.height / 2 < inner_height / 2) {
|
|
1838
|
+
const top = bounds.y + bounds.height;
|
|
1839
|
+
this.#container.style.top = top + "px";
|
|
1840
|
+
this.#container.style.bottom = "";
|
|
1841
|
+
this.#container.style.maxHeight = inner_height - top - 10 + "px";
|
|
1842
|
+
this.#container.style.flexDirection = "column";
|
|
1843
|
+
} else {
|
|
1844
|
+
const bottom = inner_height - bounds.y;
|
|
1845
|
+
this.#container.style.top = "";
|
|
1846
|
+
this.#container.style.bottom = bottom + "px";
|
|
1847
|
+
this.#container.style.maxHeight = inner_height - bottom - 10 + "px";
|
|
1848
|
+
this.#container.style.flexDirection = "column-reverse";
|
|
1849
|
+
}
|
|
1850
|
+
this.#container.style.left = bounds.x + "px";
|
|
1851
|
+
this.#container.style.width = bounds.width + "px";
|
|
1852
|
+
this.#dropdown = parent;
|
|
1853
|
+
if (this.#scroll.scrollHeight > this.#scroll.clientHeight) this.#scroll.classList.add("scroll");
|
|
1854
|
+
else this.#scroll.classList.remove("scroll");
|
|
1855
|
+
let focus = void 0;
|
|
1856
|
+
this.#table.replaceChildren(...Array.from(map).map(([val, opt]) => {
|
|
1857
|
+
const line = document.createElement("div");
|
|
1858
|
+
const icon = line.appendChild(document.createElement("div"));
|
|
1859
|
+
if (opt.icon) icon.appendChild(opt.icon());
|
|
1860
|
+
const text = line.appendChild(document.createElement("div"));
|
|
1861
|
+
text.textContent = opt.text;
|
|
1862
|
+
line.onpointerup = (e) => {
|
|
1863
|
+
if (e.pointerType !== "touch") this.#set_value(val);
|
|
1864
|
+
};
|
|
1865
|
+
line.onclick = () => this.#set_value(val);
|
|
1866
|
+
line.tabIndex = 0;
|
|
1867
|
+
line.onkeydown = (e) => {
|
|
1868
|
+
if (e.key === " " || e.key === "Enter") {
|
|
1869
|
+
e.preventDefault();
|
|
1870
|
+
this.#set_value(val);
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
if (val === value) focus = line;
|
|
1874
|
+
return line;
|
|
1875
|
+
}));
|
|
1876
|
+
const box = this.#scroll.getBoundingClientRect();
|
|
1877
|
+
const box_area = box.width * box.height;
|
|
1878
|
+
const html = this.ownerDocument.documentElement;
|
|
1879
|
+
if (box_area > html.clientWidth * html.clientHeight * .5) this.#table.prepend(this.#closer);
|
|
1880
|
+
if (focus) {
|
|
1881
|
+
focus.focus();
|
|
1882
|
+
focus.classList.add("selected");
|
|
1883
|
+
} else this.#container.focus();
|
|
1884
|
+
this.ownerDocument.defaultView?.addEventListener("resize", this.#window_resize_handler, { passive: true });
|
|
1885
|
+
this.#is_open = true;
|
|
1886
|
+
}
|
|
1887
|
+
close_menu() {
|
|
1888
|
+
if (!this.#is_open) return;
|
|
1889
|
+
this.#is_open = false;
|
|
1890
|
+
if (this.#dropdown) this.#dropdown.open = false;
|
|
1891
|
+
this.classList.remove("open");
|
|
1892
|
+
this.#table.replaceChildren();
|
|
1893
|
+
if (this.#dropdown) {
|
|
1894
|
+
this.#dropdown.focus();
|
|
1895
|
+
this.#dropdown.is_open = false;
|
|
1896
|
+
}
|
|
1897
|
+
this.ownerDocument.defaultView?.removeEventListener("resize", this.#window_resize_handler);
|
|
1898
|
+
}
|
|
1899
|
+
};
|
|
1900
|
+
define_element(DropDownBox);
|
|
1901
|
+
const box = document.documentElement.appendChild(new DropDownBox());
|
|
1902
|
+
// src/form/selectors/toggle_button/toggle_button.ts
|
|
1903
|
+
/**Toggle buttons, displays all options in a multi toggler*/
|
|
1904
|
+
var FormToggleButton = class extends FormSelectorBase {
|
|
1905
|
+
/**Returns the name used to define the element*/
|
|
1906
|
+
static element_name() {
|
|
1907
|
+
return "togglebutton";
|
|
1908
|
+
}
|
|
1909
|
+
static element_name_space() {
|
|
1910
|
+
return "form";
|
|
1911
|
+
}
|
|
1912
|
+
#map = /* @__PURE__ */ new Map();
|
|
1913
|
+
#values = [];
|
|
1914
|
+
#selected = -1;
|
|
1915
|
+
focus(options) {
|
|
1916
|
+
this.firstElementChild?.focus(options);
|
|
1917
|
+
}
|
|
1918
|
+
set selections(selections) {
|
|
1919
|
+
if (this.#map.size > 0) {
|
|
1920
|
+
this.#map.clear();
|
|
1921
|
+
this.#values = [];
|
|
1922
|
+
this.#selected = -1;
|
|
1923
|
+
this.replaceChildren();
|
|
1924
|
+
}
|
|
1925
|
+
for (let i = 0; selections && i < selections.length; i++) {
|
|
1926
|
+
const { value } = selections[i];
|
|
1927
|
+
this.#map.set(value, this.#add_selection(selections[i]));
|
|
1928
|
+
this.#values.push(selections[i].value);
|
|
1929
|
+
}
|
|
1930
|
+
if (this.buffer !== void 0) this.new_value(this.buffer);
|
|
1931
|
+
}
|
|
1932
|
+
#add_selection(selection) {
|
|
1933
|
+
const top = this.appendChild(document.createElement("div"));
|
|
1934
|
+
top.tabIndex = 0;
|
|
1935
|
+
const bot = this.appendChild(document.createElement("div"));
|
|
1936
|
+
if (selection.icon) {
|
|
1937
|
+
top.appendChild(selection.icon());
|
|
1938
|
+
bot.textContent = selection.text;
|
|
1939
|
+
} else top.textContent = selection.text;
|
|
1940
|
+
const click = () => {
|
|
1941
|
+
top.appendChild(this.warn_input);
|
|
1942
|
+
this.set_value_check(selection.value);
|
|
1943
|
+
};
|
|
1944
|
+
top.onclick = click;
|
|
1945
|
+
bot.onclick = click;
|
|
1946
|
+
top.onkeydown = (e) => {
|
|
1947
|
+
if (e.key === " " || e.key === "Enter") click();
|
|
1948
|
+
else if (e.key === "ArrowRight") this.#select_adjacent(true);
|
|
1949
|
+
else if (e.key === "ArrowLeft") this.#select_adjacent(false);
|
|
1950
|
+
else return;
|
|
1951
|
+
e.preventDefault();
|
|
1952
|
+
e.stopPropagation();
|
|
1953
|
+
};
|
|
1954
|
+
return {
|
|
1955
|
+
top,
|
|
1956
|
+
bot
|
|
1957
|
+
};
|
|
1958
|
+
}
|
|
1959
|
+
/**Selects the previous or next selection in the element
|
|
1960
|
+
* @param dir false is next true is previous*/
|
|
1961
|
+
#select_adjacent(dir) {
|
|
1962
|
+
const sel = this.#map.get(this.#values[this.#selected]);
|
|
1963
|
+
if (sel) sel.top.appendChild(this.warn_input);
|
|
1964
|
+
const y = Math.min(this.#values.length - 1, Math.max(0, dir ? this.#selected + 1 : this.#selected - 1));
|
|
1965
|
+
if (y !== this.#selected) this.set_value_check(this.#values[y]);
|
|
1966
|
+
}
|
|
1967
|
+
new_value(value) {
|
|
1968
|
+
const prev = this.#map.get(this.#values[this.#selected]);
|
|
1969
|
+
if (prev) {
|
|
1970
|
+
prev.top.classList.remove("selected");
|
|
1971
|
+
prev.bot.classList.remove("selected");
|
|
1972
|
+
}
|
|
1973
|
+
const opt = this.#map.get(value);
|
|
1974
|
+
if (opt) {
|
|
1975
|
+
opt.top.classList.add("selected");
|
|
1976
|
+
opt.bot.classList.add("selected");
|
|
1977
|
+
this.#selected = this.#values.indexOf(value);
|
|
1978
|
+
if (this.contains(document.activeElement)) opt.top.focus();
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
clear_value() {
|
|
1982
|
+
const prev = this.#map.get(this.#values[this.#selected]);
|
|
1983
|
+
if (prev) {
|
|
1984
|
+
prev.top.classList.remove("selected");
|
|
1985
|
+
prev.bot.classList.remove("selected");
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
new_error(_val) {}
|
|
1989
|
+
clear_error() {}
|
|
1990
|
+
};
|
|
1991
|
+
define_element(FormToggleButton);
|
|
1992
|
+
/**Creates a toggle button form element */
|
|
1993
|
+
function form_toggle_button(options) {
|
|
1994
|
+
const togg = new FormToggleButton(options?.id);
|
|
1995
|
+
if (options) FormSelectorBase.apply_options(togg, options);
|
|
1996
|
+
return togg;
|
|
1997
|
+
}
|
|
1998
|
+
// src/form/spacing/spacer.ts
|
|
1999
|
+
var FormSpacer = class extends FormElement {
|
|
2000
|
+
static element_name() {
|
|
2001
|
+
return "spacer";
|
|
2002
|
+
}
|
|
2003
|
+
static element_name_space() {
|
|
2004
|
+
return "form";
|
|
2005
|
+
}
|
|
2006
|
+
constructor() {
|
|
2007
|
+
super();
|
|
2008
|
+
}
|
|
2009
|
+
/**Sets the amount of space, in rem */
|
|
2010
|
+
set space(space) {
|
|
2011
|
+
this.style.height = `${space}rem`;
|
|
2012
|
+
}
|
|
2013
|
+
get space() {
|
|
2014
|
+
return parseFloat(this.style.height);
|
|
2015
|
+
}
|
|
2016
|
+
};
|
|
2017
|
+
define_element(FormSpacer);
|
|
2018
|
+
/**Creates a spacer form element */
|
|
2019
|
+
function form_spacer(options) {
|
|
2020
|
+
const spacer = new FormSpacer();
|
|
2021
|
+
if (options) {
|
|
2022
|
+
if (options.space) spacer.space = options.space;
|
|
2023
|
+
}
|
|
2024
|
+
return spacer;
|
|
2025
|
+
}
|
|
2026
|
+
// src/form/special/color/color_input.ts
|
|
2027
|
+
var FormColor = class extends FormValueWrite {
|
|
2028
|
+
static element_name() {
|
|
2029
|
+
return "colorinput";
|
|
2030
|
+
}
|
|
2031
|
+
static element_name_space() {
|
|
2032
|
+
return "form";
|
|
2033
|
+
}
|
|
2034
|
+
#live = false;
|
|
2035
|
+
constructor(id) {
|
|
2036
|
+
super(id);
|
|
2037
|
+
this.appendChild(this.warn_input);
|
|
2038
|
+
this.warn_input.type = "color";
|
|
2039
|
+
this.warn_input.oninput = () => {
|
|
2040
|
+
if (this.#live) this.set_value_check(this.warn_input.value);
|
|
2041
|
+
};
|
|
2042
|
+
this.warn_input.onchange = () => {
|
|
2043
|
+
if (!this.#live) this.set_value_check(this.warn_input.value);
|
|
2044
|
+
};
|
|
2045
|
+
}
|
|
2046
|
+
set live(val) {
|
|
2047
|
+
this.#live = val;
|
|
2048
|
+
}
|
|
2049
|
+
get live() {
|
|
2050
|
+
return this.#live;
|
|
2051
|
+
}
|
|
2052
|
+
new_value(val) {
|
|
2053
|
+
this.warn_input.value = val;
|
|
2054
|
+
}
|
|
2055
|
+
clear_value() {
|
|
2056
|
+
this.warn_input.value = "#000000";
|
|
2057
|
+
}
|
|
2058
|
+
new_error(_val) {}
|
|
2059
|
+
clear_error() {}
|
|
2060
|
+
state_related(_related) {}
|
|
2061
|
+
};
|
|
2062
|
+
define_element(FormColor);
|
|
2063
|
+
/**Creates a color input form element */
|
|
2064
|
+
function form_color(options) {
|
|
2065
|
+
const input = new FormColor(options?.id);
|
|
2066
|
+
if (options) {
|
|
2067
|
+
if (options.live) input.live = options.live;
|
|
2068
|
+
FormValueWrite.apply_options(input, options);
|
|
2069
|
+
}
|
|
2070
|
+
return input;
|
|
2071
|
+
}
|
|
2072
|
+
// src/form/special/date_time/date_time_input.ts
|
|
2073
|
+
const FormDateTimeType = {
|
|
2074
|
+
DATE: "date",
|
|
2075
|
+
TIME: "time",
|
|
2076
|
+
DATETIME: "datetime"
|
|
2077
|
+
};
|
|
2078
|
+
const FormDateTimeMode = {
|
|
2079
|
+
DATE: "date",
|
|
2080
|
+
STRING: "string",
|
|
2081
|
+
NUMBER: "number"
|
|
2082
|
+
};
|
|
2083
|
+
var FormDateTime = class extends FormValueWrite {
|
|
2084
|
+
static element_name() {
|
|
2085
|
+
return "datetimeinput";
|
|
2086
|
+
}
|
|
2087
|
+
static element_name_space() {
|
|
2088
|
+
return "form";
|
|
2089
|
+
}
|
|
2090
|
+
#type = FormDateTimeType.DATETIME;
|
|
2091
|
+
#mode;
|
|
2092
|
+
#milliseconds = false;
|
|
2093
|
+
constructor(mode, id) {
|
|
2094
|
+
super(id);
|
|
2095
|
+
this.#mode = mode;
|
|
2096
|
+
this.warn_input.onfocus = () => {
|
|
2097
|
+
this.selected = true;
|
|
2098
|
+
};
|
|
2099
|
+
this.warn_input.onblur = () => {
|
|
2100
|
+
this.selected = false;
|
|
2101
|
+
};
|
|
2102
|
+
this.warn_input.type = "datetime-local";
|
|
2103
|
+
this.warn_input.lang = "da-DK";
|
|
2104
|
+
this.warn_input.step = "1";
|
|
2105
|
+
this.appendChild(this.warn_input);
|
|
2106
|
+
this.appendChild(material_calendar_month_rounded()).onclick = () => this.warn_input.showPicker();
|
|
2107
|
+
this.appendChild(material_schedule_rounded()).onclick = () => this.warn_input.showPicker();
|
|
2108
|
+
this.warn_input.onchange = () => {
|
|
2109
|
+
if (this.warn_input.value) {
|
|
2110
|
+
if (this.#mode === FormDateTimeMode.DATE) this.set_value_check(new Date(this.warn_input.valueAsNumber + (/* @__PURE__ */ new Date()).getTimezoneOffset() * 6e4));
|
|
2111
|
+
else if (this.#mode === FormDateTimeMode.STRING) this.set_value_check(this.warn_input.value);
|
|
2112
|
+
else this.set_value_check(this.warn_input.valueAsNumber);
|
|
2113
|
+
}
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
/**Returns the date time type*/
|
|
2117
|
+
get type() {
|
|
2118
|
+
return this.#type;
|
|
2119
|
+
}
|
|
2120
|
+
/**Sets the date time type*/
|
|
2121
|
+
set type(type) {
|
|
2122
|
+
if (type === FormDateTimeType.DATE) this.warn_input.type = "date";
|
|
2123
|
+
if (type === FormDateTimeType.TIME) this.warn_input.type = "time";
|
|
2124
|
+
if (type === FormDateTimeType.DATETIME) this.warn_input.type = "datetime-local";
|
|
2125
|
+
this.#type = type;
|
|
2126
|
+
}
|
|
2127
|
+
/**Returns true if the input is set to show milliseconds*/
|
|
2128
|
+
get milliseconds() {
|
|
2129
|
+
return this.#milliseconds;
|
|
2130
|
+
}
|
|
2131
|
+
/**Sets the input to show milliseconds*/
|
|
2132
|
+
set milliseconds(value) {
|
|
2133
|
+
this.#milliseconds = value;
|
|
2134
|
+
if (value) this.warn_input.step = "0.001";
|
|
2135
|
+
else this.warn_input.step = "1";
|
|
2136
|
+
}
|
|
2137
|
+
/**Returns the date time type*/
|
|
2138
|
+
get step() {
|
|
2139
|
+
return Number(this.warn_input.step);
|
|
2140
|
+
}
|
|
2141
|
+
/**Sets the date time type*/
|
|
2142
|
+
set step(step) {
|
|
2143
|
+
this.warn_input.step = String(step);
|
|
2144
|
+
}
|
|
2145
|
+
new_value(value) {
|
|
2146
|
+
let time;
|
|
2147
|
+
if (typeof value === "number") time = value;
|
|
2148
|
+
else if (typeof value === "string") {
|
|
2149
|
+
const date = new Date(value);
|
|
2150
|
+
time = date.getTime() - date.getTimezoneOffset() * 6e4;
|
|
2151
|
+
} else time = value.getTime() - value.getTimezoneOffset() * 6e4;
|
|
2152
|
+
this.warn_input.valueAsNumber = this.#milliseconds ? time : time - time % 1e3;
|
|
2153
|
+
}
|
|
2154
|
+
clear_value() {
|
|
2155
|
+
this.warn_input.value = "";
|
|
2156
|
+
}
|
|
2157
|
+
new_error(_val) {}
|
|
2158
|
+
clear_error() {}
|
|
2159
|
+
state_related(_related) {}
|
|
2160
|
+
};
|
|
2161
|
+
define_element(FormDateTime);
|
|
2162
|
+
/**Creates a date time input form element
|
|
2163
|
+
* Number type is always UTC, Date and String is always local*/
|
|
2164
|
+
function form_date_time(options) {
|
|
2165
|
+
const input = new FormDateTime(options.mode, options.id);
|
|
2166
|
+
if (options.type) input.type = options.type;
|
|
2167
|
+
if (options.milliseconds !== void 0) input.milliseconds = options.milliseconds;
|
|
2168
|
+
FormValueWrite.apply_options(input, options);
|
|
2169
|
+
return input;
|
|
2170
|
+
}
|
|
2171
|
+
// src/form/special/ip/ip_input.ts
|
|
2172
|
+
var FormIp = class extends FormValueWrite {
|
|
2173
|
+
static element_name() {
|
|
2174
|
+
return "ipinput";
|
|
2175
|
+
}
|
|
2176
|
+
static element_name_space() {
|
|
2177
|
+
return "form";
|
|
2178
|
+
}
|
|
2179
|
+
#type;
|
|
2180
|
+
#parts = Array.from({ length: 8 }, (_, i) => {
|
|
2181
|
+
const inp = this.appendChild(document.createElement("div"));
|
|
2182
|
+
if (i < 7) this.appendChild(document.createElement("span"));
|
|
2183
|
+
inp.contentEditable = "true";
|
|
2184
|
+
inp.onbeforeinput = async (ev) => {
|
|
2185
|
+
if (ev.inputType === "insertParagraph") ev.preventDefault();
|
|
2186
|
+
else if (ev.inputType === "deleteContentBackward") {
|
|
2187
|
+
if (inp.textContent.length === 0 && i > 0) set_cursor_end(inp.previousElementSibling);
|
|
2188
|
+
} else if (ev.inputType === "deleteContentForward") {
|
|
2189
|
+
if (inp.textContent.length === 0 && i < length - 1) {
|
|
2190
|
+
await sleep(0);
|
|
2191
|
+
inp.nextElementSibling?.focus();
|
|
2192
|
+
}
|
|
2193
|
+
} else if (ev.data) {
|
|
2194
|
+
if ((ev.data === "." || ev.data === ":" || ev.data === ",") && i < length - 1) {
|
|
2195
|
+
set_selection_all(inp.nextElementSibling);
|
|
2196
|
+
ev.preventDefault();
|
|
2197
|
+
} 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
|
+
else {
|
|
2200
|
+
const pos = get_cursor_position(inp);
|
|
2201
|
+
const potential = inp.textContent.slice(0, pos) + ev.data + inp.textContent.slice(pos);
|
|
2202
|
+
const num = this.#type === IPVersion.V4 ? parseInt(potential, 10) : parseInt(potential, 16);
|
|
2203
|
+
if (this.#type === IPVersion.V4 && num > 255 || this.#type === IPVersion.V6 && num > 65535) {
|
|
2204
|
+
if (i < this.#parts.length - 1) set_selection_all(inp.nextElementSibling);
|
|
2205
|
+
else ev.preventDefault();
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
};
|
|
2210
|
+
inp.oninput = () => {
|
|
2211
|
+
if (inp.textContent.length === (this.#type === IPVersion.V4 ? 3 : 4) && get_cursor_position(inp) === inp.textContent.length && i < this.#parts.length - 1) set_selection_all(inp.nextElementSibling);
|
|
2212
|
+
};
|
|
2213
|
+
inp.onkeydown = async (e) => {
|
|
2214
|
+
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(inp.previousElementSibling);
|
|
2216
|
+
else return;
|
|
2217
|
+
} else if (e.key === "ArrowRight" && i < this.#parts.length - 1) {
|
|
2218
|
+
if (get_cursor_position(inp) === inp.textContent.length || inp.textContent.length === 0) inp.nextElementSibling?.focus();
|
|
2219
|
+
else return;
|
|
2220
|
+
} else return;
|
|
2221
|
+
e.preventDefault();
|
|
2222
|
+
e.stopPropagation();
|
|
2223
|
+
};
|
|
2224
|
+
return inp;
|
|
2225
|
+
});
|
|
2226
|
+
constructor(type, id) {
|
|
2227
|
+
super(id);
|
|
2228
|
+
this.type = type;
|
|
2229
|
+
this.#type = type;
|
|
2230
|
+
this.appendChild(this.warn_input);
|
|
2231
|
+
this.addEventListener("focusin", () => {
|
|
2232
|
+
this.selected = true;
|
|
2233
|
+
});
|
|
2234
|
+
this.addEventListener("focusout", () => {
|
|
2235
|
+
this.selected = false;
|
|
2236
|
+
});
|
|
2237
|
+
this.onpointerdown = (e) => {
|
|
2238
|
+
if (!this.#parts.includes(e.target)) {
|
|
2239
|
+
e.preventDefault();
|
|
2240
|
+
set_cursor_end(this.#parts[this.#type === IPVersion.V4 ? 3 : 7]);
|
|
2241
|
+
}
|
|
2242
|
+
};
|
|
2243
|
+
this.ondblclick = (e) => {
|
|
2244
|
+
if (e.target !== this) return;
|
|
2245
|
+
e.preventDefault();
|
|
2246
|
+
set_selection_all(this.#parts[0]);
|
|
2247
|
+
};
|
|
2248
|
+
this.addEventListener("focusin", (e) => {
|
|
2249
|
+
e.preventDefault();
|
|
2250
|
+
});
|
|
2251
|
+
this.addEventListener("focusout", (e) => {
|
|
2252
|
+
if (e.relatedTarget && this.contains(e.relatedTarget)) return;
|
|
2253
|
+
this.set_value_check(this.value_as_ip);
|
|
2254
|
+
});
|
|
2255
|
+
this.onkeydown = (e) => {
|
|
2256
|
+
if (e.key === "Enter") this.set_value_check(this.value_as_ip);
|
|
2257
|
+
else if (e.key === "Escape") {
|
|
2258
|
+
if (this.buffer) this.new_value(this.buffer);
|
|
2259
|
+
else this.clear_value();
|
|
2260
|
+
}
|
|
2261
|
+
};
|
|
2262
|
+
this.oncopy = (e) => {
|
|
2263
|
+
e.preventDefault();
|
|
2264
|
+
e.clipboardData?.setData("text/plain", this.value_as_ip.to_string());
|
|
2265
|
+
};
|
|
2266
|
+
this.onpaste = (e) => {
|
|
2267
|
+
e.preventDefault();
|
|
2268
|
+
const paste = e.clipboardData?.getData("text/plain") || "";
|
|
2269
|
+
const new_ip = new IPAddress(paste);
|
|
2270
|
+
if (new_ip.version !== this.#type) return;
|
|
2271
|
+
this.set_value_check(new_ip);
|
|
2272
|
+
};
|
|
2273
|
+
}
|
|
2274
|
+
focus(options) {
|
|
2275
|
+
this.#parts[0].focus(options);
|
|
2276
|
+
}
|
|
2277
|
+
get value_as_ip() {
|
|
2278
|
+
return new IPAddress(this.#parts.slice(0, this.#type === IPVersion.V4 ? 4 : 8).reduce((acc, part, i) => {
|
|
2279
|
+
acc += part.innerText;
|
|
2280
|
+
if (i < (this.#type === IPVersion.V4 ? 4 : 8) - 1) acc += this.#type === IPVersion.V4 ? "." : ":";
|
|
2281
|
+
return acc;
|
|
2282
|
+
}, ""));
|
|
2283
|
+
}
|
|
2284
|
+
set type(val) {
|
|
2285
|
+
if (this.#type === val) return;
|
|
2286
|
+
this.#type = val;
|
|
2287
|
+
this.classList.toggle("ipv4", val === IPVersion.V4);
|
|
2288
|
+
this.classList.toggle("ipv6", val === IPVersion.V6);
|
|
2289
|
+
this.replaceChildren(...this.#parts.slice(0, val === IPVersion.V4 ? 4 : 8).flatMap((v, i) => i < (val === IPVersion.V4 ? 4 : 8) - 1 ? [v, document.createTextNode(val === IPVersion.V4 ? "." : ":")] : [v]));
|
|
2290
|
+
}
|
|
2291
|
+
new_value(val) {
|
|
2292
|
+
this.type = val.version;
|
|
2293
|
+
val.as_array.forEach((part, i) => {
|
|
2294
|
+
this.#parts[i].textContent = val.version === IPVersion.V4 ? part.toString() : part.toString(16);
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
clear_value() {
|
|
2298
|
+
this.#parts.forEach((part) => {
|
|
2299
|
+
part.textContent = "";
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
new_error(_val) {}
|
|
2303
|
+
clear_error() {}
|
|
2304
|
+
state_related(_related) {}
|
|
2305
|
+
};
|
|
2306
|
+
define_element(FormIp);
|
|
2307
|
+
/**Creates an IP input form element */
|
|
2308
|
+
function form_ip(options) {
|
|
2309
|
+
const input = new FormIp(options.type, options?.id);
|
|
2310
|
+
if (options) FormValueWrite.apply_options(input, options);
|
|
2311
|
+
return input;
|
|
2312
|
+
}
|
|
2313
|
+
// src/form/special/password/password_input.ts
|
|
2314
|
+
var FormPassword = class extends FormValueWrite {
|
|
2315
|
+
static element_name() {
|
|
2316
|
+
return "passwordinput";
|
|
2317
|
+
}
|
|
2318
|
+
static element_name_space() {
|
|
2319
|
+
return "form";
|
|
2320
|
+
}
|
|
2321
|
+
#filter;
|
|
2322
|
+
constructor(id) {
|
|
2323
|
+
super(id);
|
|
2324
|
+
this.appendChild(this.warn_input);
|
|
2325
|
+
this.warn_input.type = "password";
|
|
2326
|
+
this.warn_input.onfocus = () => {
|
|
2327
|
+
this.warn_input.value = "";
|
|
2328
|
+
this.selected = true;
|
|
2329
|
+
};
|
|
2330
|
+
this.warn_input.onblur = () => {
|
|
2331
|
+
this.selected = false;
|
|
2332
|
+
};
|
|
2333
|
+
this.warn_input.onchange = () => {
|
|
2334
|
+
this.set_value_check(this.warn_input.value);
|
|
2335
|
+
};
|
|
2336
|
+
this.warn_input.onbeforeinput = (ev) => {
|
|
2337
|
+
if (ev.data) {
|
|
2338
|
+
if (this.#filter && !this.#filter.test(ev.data)) {
|
|
2339
|
+
ev.preventDefault();
|
|
2340
|
+
this.warn("Invalid character entered");
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
};
|
|
2344
|
+
}
|
|
2345
|
+
set filter(val) {
|
|
2346
|
+
this.#filter = val;
|
|
2347
|
+
}
|
|
2348
|
+
new_value(val) {
|
|
2349
|
+
this.warn_input.value = val;
|
|
2350
|
+
}
|
|
2351
|
+
clear_value() {
|
|
2352
|
+
this.warn_input.value = "";
|
|
2353
|
+
}
|
|
2354
|
+
new_error(_val) {}
|
|
2355
|
+
clear_error() {}
|
|
2356
|
+
state_related(_related) {}
|
|
2357
|
+
};
|
|
2358
|
+
define_element(FormPassword);
|
|
2359
|
+
/**Creates a password input form element */
|
|
2360
|
+
function form_password(options) {
|
|
2361
|
+
const input = new FormPassword(options?.id);
|
|
2362
|
+
if (options) {
|
|
2363
|
+
if (options.filter) input.filter = options.filter;
|
|
2364
|
+
FormValueWrite.apply_options(input, options);
|
|
2365
|
+
}
|
|
2366
|
+
return input;
|
|
2367
|
+
}
|
|
2368
|
+
// src/form/text/input/text_input.ts
|
|
2369
|
+
var FormTextInput = class extends FormValueWrite {
|
|
2370
|
+
static element_name() {
|
|
2371
|
+
return "textinput";
|
|
2372
|
+
}
|
|
2373
|
+
static element_name_space() {
|
|
2374
|
+
return "form";
|
|
2375
|
+
}
|
|
2376
|
+
#filter;
|
|
2377
|
+
#max_length;
|
|
2378
|
+
#max_bytes;
|
|
2379
|
+
constructor(id) {
|
|
2380
|
+
super(id);
|
|
2381
|
+
this.warn_input.onfocus = () => {
|
|
2382
|
+
this.selected = true;
|
|
2383
|
+
};
|
|
2384
|
+
this.warn_input.onblur = () => {
|
|
2385
|
+
this.selected = false;
|
|
2386
|
+
};
|
|
2387
|
+
this.warn_input.type = "text";
|
|
2388
|
+
this.appendChild(this.warn_input);
|
|
2389
|
+
this.warn_input.onchange = () => this.#set();
|
|
2390
|
+
this.onbeforeinput = (e) => {
|
|
2391
|
+
this.warn("");
|
|
2392
|
+
const data = e.data || e.dataTransfer?.getData("text/plain");
|
|
2393
|
+
if (data) {
|
|
2394
|
+
if (this.#filter && !this.#filter.test(data)) {
|
|
2395
|
+
e.preventDefault();
|
|
2396
|
+
this.warn("Invalid character entered");
|
|
2397
|
+
} else {
|
|
2398
|
+
if (this.#max_length && this.warn_input.value.length + data.length > this.#max_length) {
|
|
2399
|
+
e.preventDefault();
|
|
2400
|
+
this.warn(`A maximum of ${this.#max_length} characters is allowed`);
|
|
2401
|
+
}
|
|
2402
|
+
if (this.#max_bytes && string_byte_length(this.warn_input.value) + string_byte_length(data) > this.#max_bytes) {
|
|
2403
|
+
e.preventDefault();
|
|
2404
|
+
this.warn(`A maximum of ${this.#max_bytes} bytes is allowed`);
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
};
|
|
2409
|
+
this.onkeydown = (e) => {
|
|
2410
|
+
if (e.key === "Escape") {
|
|
2411
|
+
e.preventDefault();
|
|
2412
|
+
e.stopPropagation();
|
|
2413
|
+
if (this.buffer) this.new_value(this.buffer);
|
|
2414
|
+
else this.clear_value();
|
|
2415
|
+
}
|
|
2416
|
+
};
|
|
2417
|
+
}
|
|
2418
|
+
async #set() {
|
|
2419
|
+
const buff = this.buffer;
|
|
2420
|
+
(await this.set_value_check(this.warn_input.value || "")).map_err(() => {
|
|
2421
|
+
this.new_value(buff || "");
|
|
2422
|
+
set_cursor_end(this.warn_input);
|
|
2423
|
+
});
|
|
2424
|
+
}
|
|
2425
|
+
set filter(val) {
|
|
2426
|
+
this.#filter = val;
|
|
2427
|
+
}
|
|
2428
|
+
get filter() {
|
|
2429
|
+
return this.#filter;
|
|
2430
|
+
}
|
|
2431
|
+
set placeholder(val) {
|
|
2432
|
+
this.warn_input.placeholder = val;
|
|
2433
|
+
}
|
|
2434
|
+
get placeholder() {
|
|
2435
|
+
return this.warn_input.placeholder;
|
|
2436
|
+
}
|
|
2437
|
+
set max_length(val) {
|
|
2438
|
+
this.#max_length = val;
|
|
2439
|
+
this.warn_input.maxLength = val ?? -1;
|
|
2440
|
+
}
|
|
2441
|
+
get max_length() {
|
|
2442
|
+
return this.#max_length;
|
|
2443
|
+
}
|
|
2444
|
+
set max_bytes(val) {
|
|
2445
|
+
this.#max_bytes = val;
|
|
2446
|
+
}
|
|
2447
|
+
get max_bytes() {
|
|
2448
|
+
return this.#max_bytes;
|
|
2449
|
+
}
|
|
2450
|
+
new_value(val) {
|
|
2451
|
+
this.warn_input.value = val;
|
|
2452
|
+
}
|
|
2453
|
+
clear_value() {
|
|
2454
|
+
this.warn_input.value = "";
|
|
2455
|
+
}
|
|
2456
|
+
new_error(_val) {}
|
|
2457
|
+
clear_error() {}
|
|
2458
|
+
limit_value(val) {
|
|
2459
|
+
if (this.#max_length && val.length > this.#max_length) val = val.slice(0, this.#max_length);
|
|
2460
|
+
if (this.#max_bytes) val = string_byte_limit(val, this.#max_bytes);
|
|
2461
|
+
return super.limit_value(val);
|
|
2462
|
+
}
|
|
2463
|
+
check_value(val) {
|
|
2464
|
+
if (this.#max_length && val.length > this.#max_length) return sync_resolve(err(`A maximum of ${this.#max_length} characters is allowed`));
|
|
2465
|
+
if (this.#max_bytes && string_byte_length(val) > this.#max_bytes) return sync_resolve(err(`A maximum of ${this.#max_bytes} bytes is allowed`));
|
|
2466
|
+
return super.check_value(val);
|
|
2467
|
+
}
|
|
2468
|
+
state_related(related) {
|
|
2469
|
+
if (related.max_length) this.attach_state_to_prop("max_length", related.max_length, () => none());
|
|
2470
|
+
else this.detach_state_from_prop("max_length");
|
|
2471
|
+
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");
|
|
2473
|
+
}
|
|
2474
|
+
};
|
|
2475
|
+
define_element(FormTextInput);
|
|
2476
|
+
/**Creates a single line text input form element */
|
|
2477
|
+
function form_text_input(options) {
|
|
2478
|
+
const input = new FormTextInput(options?.id);
|
|
2479
|
+
if (options) {
|
|
2480
|
+
if (options.filter) input.filter = options.filter;
|
|
2481
|
+
if (options.placeholder) input.placeholder = options.placeholder;
|
|
2482
|
+
if (options.max_length) input.max_length = options.max_length;
|
|
2483
|
+
if (options.max_bytes) input.max_bytes = options.max_bytes;
|
|
2484
|
+
FormValueWrite.apply_options(input, options);
|
|
2485
|
+
}
|
|
2486
|
+
return input;
|
|
2487
|
+
}
|
|
2488
|
+
// src/form/text/multi_line/text_multi_line.ts
|
|
2489
|
+
var FormTextMultiline = class extends FormValueWrite {
|
|
2490
|
+
static element_name() {
|
|
2491
|
+
return "textmultiline";
|
|
2492
|
+
}
|
|
2493
|
+
static element_name_space() {
|
|
2494
|
+
return "form";
|
|
2495
|
+
}
|
|
2496
|
+
#filter;
|
|
2497
|
+
#max_length;
|
|
2498
|
+
#max_bytes;
|
|
2499
|
+
#value_box = this.appendChild(document.createElement("textarea"));
|
|
2500
|
+
#resizer = this.appendChild(document.createElement("div"));
|
|
2501
|
+
constructor(id) {
|
|
2502
|
+
super(id);
|
|
2503
|
+
this.#value_box.onfocus = () => {
|
|
2504
|
+
this.selected = true;
|
|
2505
|
+
};
|
|
2506
|
+
this.#value_box.onblur = () => {
|
|
2507
|
+
this.selected = false;
|
|
2508
|
+
};
|
|
2509
|
+
this.appendChild(this.warn_input);
|
|
2510
|
+
this.#resizer.appendChild(material_drag_handle_rounded());
|
|
2511
|
+
this.#resizer.onpointerdown = (e) => {
|
|
2512
|
+
e.preventDefault();
|
|
2513
|
+
const height = this.#value_box.getBoundingClientRect().height;
|
|
2514
|
+
const start_y = e.clientY;
|
|
2515
|
+
this.#resizer.setPointerCapture(e.pointerId);
|
|
2516
|
+
this.#resizer.onpointermove = (ev) => {
|
|
2517
|
+
const dy = ev.clientY - start_y;
|
|
2518
|
+
this.#value_box.style.height = `${height + dy}px`;
|
|
2519
|
+
};
|
|
2520
|
+
this.#resizer.onpointerup = (_ev) => {
|
|
2521
|
+
this.#resizer.releasePointerCapture(e.pointerId);
|
|
2522
|
+
this.#resizer.onpointermove = null;
|
|
2523
|
+
this.#resizer.onpointerup = null;
|
|
2524
|
+
};
|
|
2525
|
+
};
|
|
2526
|
+
this.#value_box.onkeydown = (e) => {
|
|
2527
|
+
if (e.key === "Enter" && !e.shiftKey) e.stopPropagation();
|
|
2528
|
+
};
|
|
2529
|
+
this.#value_box.onchange = () => this.#set();
|
|
2530
|
+
this.#value_box.onbeforeinput = (e) => {
|
|
2531
|
+
this.warn("");
|
|
2532
|
+
const data = e.data || e.dataTransfer?.getData("text/plain");
|
|
2533
|
+
if (data) {
|
|
2534
|
+
if (this.#filter && !this.#filter.test(data)) {
|
|
2535
|
+
e.preventDefault();
|
|
2536
|
+
this.warn("Invalid character entered");
|
|
2537
|
+
} else {
|
|
2538
|
+
if (this.#max_length && this.#value_box.value.length + data.length > this.#max_length) {
|
|
2539
|
+
e.preventDefault();
|
|
2540
|
+
this.warn(`A maximum of ${this.#max_length} characters is allowed`);
|
|
2541
|
+
}
|
|
2542
|
+
if (this.#max_bytes && string_byte_length(this.#value_box.value) + string_byte_length(data) > this.#max_bytes) {
|
|
2543
|
+
e.preventDefault();
|
|
2544
|
+
this.warn(`A maximum of ${this.#max_bytes} bytes is allowed`);
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
};
|
|
2549
|
+
this.#value_box.onkeydown = (e) => {
|
|
2550
|
+
if (e.key === "Escape") {
|
|
2551
|
+
e.preventDefault();
|
|
2552
|
+
e.stopPropagation();
|
|
2553
|
+
if (this.buffer) this.new_value(this.buffer);
|
|
2554
|
+
else this.clear_value();
|
|
2555
|
+
} else if (e.key === "Enter" && e.ctrlKey) {
|
|
2556
|
+
e.preventDefault();
|
|
2557
|
+
this.#set();
|
|
2558
|
+
}
|
|
2559
|
+
};
|
|
2560
|
+
}
|
|
2561
|
+
focus(options) {
|
|
2562
|
+
this.#value_box.focus(options);
|
|
2563
|
+
}
|
|
2564
|
+
async #set() {
|
|
2565
|
+
const buff = this.buffer;
|
|
2566
|
+
(await this.set_value_check(this.#value_box.value || "")).map_err(() => {
|
|
2567
|
+
this.new_value(buff || "");
|
|
2568
|
+
set_cursor_end(this.#value_box);
|
|
2569
|
+
});
|
|
2570
|
+
}
|
|
2571
|
+
set filter(val) {
|
|
2572
|
+
this.#filter = val;
|
|
2573
|
+
}
|
|
2574
|
+
get filter() {
|
|
2575
|
+
return this.#filter;
|
|
2576
|
+
}
|
|
2577
|
+
set placeholder(val) {
|
|
2578
|
+
this.#value_box.placeholder = val;
|
|
2579
|
+
}
|
|
2580
|
+
get placeholder() {
|
|
2581
|
+
return this.#value_box.placeholder;
|
|
2582
|
+
}
|
|
2583
|
+
set max_length(val) {
|
|
2584
|
+
this.#max_length = val;
|
|
2585
|
+
this.#value_box.maxLength = val ?? -1;
|
|
2586
|
+
}
|
|
2587
|
+
get max_length() {
|
|
2588
|
+
return this.#max_length;
|
|
2589
|
+
}
|
|
2590
|
+
set max_bytes(val) {
|
|
2591
|
+
this.#max_bytes = val;
|
|
2592
|
+
}
|
|
2593
|
+
get max_bytes() {
|
|
2594
|
+
return this.#max_bytes;
|
|
2595
|
+
}
|
|
2596
|
+
new_value(val) {
|
|
2597
|
+
this.#value_box.value = val;
|
|
2598
|
+
}
|
|
2599
|
+
clear_value() {
|
|
2600
|
+
this.#value_box.value = "";
|
|
2601
|
+
}
|
|
2602
|
+
new_error(_val) {}
|
|
2603
|
+
clear_error() {}
|
|
2604
|
+
limit_value(val) {
|
|
2605
|
+
if (this.#max_length && val.length > this.#max_length) val = val.slice(0, this.#max_length);
|
|
2606
|
+
if (this.#max_bytes) val = string_byte_limit(val, this.#max_bytes);
|
|
2607
|
+
return super.limit_value(val);
|
|
2608
|
+
}
|
|
2609
|
+
check_value(val) {
|
|
2610
|
+
if (this.#max_length && val.length > this.#max_length) return sync_resolve(err(`A maximum of ${this.#max_length} characters is allowed`));
|
|
2611
|
+
if (this.#max_bytes && string_byte_length(val) > this.#max_bytes) return sync_resolve(err(`A maximum of ${this.#max_bytes} bytes is allowed`));
|
|
2612
|
+
return super.check_value(val);
|
|
2613
|
+
}
|
|
2614
|
+
state_related(related) {
|
|
2615
|
+
if (related.max_length) this.attach_state_to_prop("max_length", related.max_length, () => none());
|
|
2616
|
+
else this.detach_state_from_prop("max_length");
|
|
2617
|
+
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");
|
|
2619
|
+
}
|
|
2620
|
+
};
|
|
2621
|
+
define_element(FormTextMultiline);
|
|
2622
|
+
/**Creates a multi line text input form element */
|
|
2623
|
+
function form_text_multiline(options) {
|
|
2624
|
+
const input = new FormTextMultiline(options?.id);
|
|
2625
|
+
if (options) {
|
|
2626
|
+
if (options.placeholder) input.placeholder = options.placeholder;
|
|
2627
|
+
if (options.max_length) input.max_length = options.max_length;
|
|
2628
|
+
if (options.max_bytes) input.max_bytes = options.max_bytes;
|
|
2629
|
+
FormValueWrite.apply_options(input, options);
|
|
2630
|
+
}
|
|
2631
|
+
return input;
|
|
2632
|
+
}
|
|
2633
|
+
// src/form/text/text/text.ts
|
|
2634
|
+
/**Component for simple text */
|
|
2635
|
+
var FormText = class extends FormElement {
|
|
2636
|
+
static element_name() {
|
|
2637
|
+
return "text";
|
|
2638
|
+
}
|
|
2639
|
+
static element_name_space() {
|
|
2640
|
+
return "form";
|
|
2641
|
+
}
|
|
2642
|
+
constructor(options) {
|
|
2643
|
+
super();
|
|
2644
|
+
if (options.text) this.text = options.text;
|
|
2645
|
+
if (options.size) this.size = options.size;
|
|
2646
|
+
}
|
|
2647
|
+
/**Sets the current text of the element*/
|
|
2648
|
+
set text(text) {
|
|
2649
|
+
this.textContent = text;
|
|
2650
|
+
}
|
|
2651
|
+
get text() {
|
|
2652
|
+
return this.textContent;
|
|
2653
|
+
}
|
|
2654
|
+
/**Sets the current text of the element*/
|
|
2655
|
+
set size(size) {
|
|
2656
|
+
this.style.fontSize = size + "rem";
|
|
2657
|
+
this.style.lineHeight = size + "rem";
|
|
2658
|
+
}
|
|
2659
|
+
};
|
|
2660
|
+
define_element(FormText);
|
|
2661
|
+
/**Creates a button form element */
|
|
2662
|
+
function form_text(options) {
|
|
2663
|
+
return new FormText(options);
|
|
2664
|
+
}
|
|
2665
|
+
// src/form/index.ts
|
|
2666
|
+
/**Form elements with label */
|
|
2667
|
+
const form = {
|
|
2668
|
+
FormColors,
|
|
2669
|
+
button: form_button,
|
|
2670
|
+
switch: form_switch,
|
|
2671
|
+
lamp: form_lamp,
|
|
2672
|
+
group: form_group,
|
|
2673
|
+
group_collapser: form_group_collapser,
|
|
2674
|
+
color: form_color,
|
|
2675
|
+
date_time: form_date_time,
|
|
2676
|
+
FormDateTimeMode,
|
|
2677
|
+
FormDateTimeType,
|
|
2678
|
+
ip: form_ip,
|
|
2679
|
+
password: form_password,
|
|
2680
|
+
progress: form_progress,
|
|
2681
|
+
number_input: form_number_input,
|
|
2682
|
+
slider: form_slider,
|
|
2683
|
+
stepper: form_stepper,
|
|
2684
|
+
dropdown: form_dropdown,
|
|
2685
|
+
toggle_button: form_toggle_button,
|
|
2686
|
+
spacer: form_spacer,
|
|
2687
|
+
text: form_text,
|
|
2688
|
+
text_input: form_text_input,
|
|
2689
|
+
text_multiline: form_text_multiline,
|
|
2690
|
+
list_field: form_list_field
|
|
2691
|
+
};
|
|
2692
|
+
export { FormColors, FormDateTimeMode, FormDateTimeType, FormElement, FormValue, FormValueWrite, form as default, form };
|
|
2693
|
+
|
|
2694
|
+
//# sourceMappingURL=index.mjs.map
|