@oscarpalmer/oui 0.39.0 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/css/color-picker.css +80 -69
- package/dist/css/listbox.css +169 -0
- package/dist/js/color-picker/color-picker.constants.d.mts +2 -0
- package/dist/js/color-picker/{constants.color-picker.mjs → color-picker.constants.mjs} +7 -4
- package/dist/js/color-picker/{dom.color-picker.d.mts → color-picker.dom.d.mts} +2 -2
- package/dist/js/color-picker/{dom.color-picker.mjs → color-picker.dom.mjs} +33 -16
- package/dist/js/color-picker/{event.color-picker.d.mts → color-picker.event.d.mts} +3 -3
- package/dist/js/color-picker/color-picker.event.mjs +233 -0
- package/dist/js/color-picker/{form.color-picker.d.mts → color-picker.form.d.mts} +2 -2
- package/dist/js/color-picker/{form.color-picker.mjs → color-picker.form.mjs} +9 -8
- package/dist/js/color-picker/color-picker.misc.d.mts +2 -0
- package/dist/js/color-picker/color-picker.misc.mjs +104 -0
- package/dist/js/color-picker/color-picker.model.d.mts +2 -0
- package/dist/js/color-picker/{models.color-picker.mjs → color-picker.model.mjs} +1 -1
- package/dist/js/color-picker/{output.color-picker.d.mts → color-picker.output.d.mts} +2 -2
- package/dist/js/color-picker/{output.color-picker.mjs → color-picker.output.mjs} +19 -18
- package/dist/js/color-picker/color-picker.state.d.mts +8 -0
- package/dist/js/color-picker/color-picker.state.mjs +168 -0
- package/dist/js/color-picker/index.d.mts +172 -2
- package/dist/js/color-picker/index.mjs +66 -59
- package/dist/js/color-picker.constants-BZgXQr5o.d.mts +177 -0
- package/dist/js/color-picker.misc-BIS3R6jk.d.mts +31 -0
- package/dist/js/combobox/combobox.constants.d.mts +2 -0
- package/dist/js/combobox/{constants.combobox.mjs → combobox.constants.mjs} +21 -21
- package/dist/js/combobox/combobox.dom.d.mts +25 -0
- package/dist/js/combobox/{dom.combobox.mjs → combobox.dom.mjs} +51 -49
- package/dist/js/combobox/{event.combobox.d.mts → combobox.event.d.mts} +9 -9
- package/dist/js/combobox/{event.combobox.mjs → combobox.event.mjs} +1 -1
- package/dist/js/combobox/combobox.misc.d.mts +2 -0
- package/dist/js/combobox/combobox.misc.mjs +2 -0
- package/dist/js/combobox/combobox.model.d.mts +2 -0
- package/dist/js/combobox/combobox.state.d.mts +9 -0
- package/dist/js/combobox/combobox.state.mjs +2 -0
- package/dist/js/combobox/index.d.mts +152 -2
- package/dist/js/combobox/index.mjs +54 -55
- package/dist/js/combobox.constants-Hb3bqqQJ.d.mts +19 -0
- package/dist/js/combobox.misc-DRDFk6X8.d.mts +26 -0
- package/dist/js/combobox.model-gjEI2VqZ.d.mts +46 -0
- package/dist/js/{state.combobox-BWDFHwoi.mjs → combobox.state-AstCICiH.mjs} +109 -106
- package/dist/js/dialog/dialog.model.d.mts +2 -0
- package/dist/js/dialog/dialog.model.mjs +11 -0
- package/dist/js/dialog/index.d.mts +12 -0
- package/dist/js/dialog/index.mjs +123 -0
- package/dist/js/dialog.model-HVzYWoDo.d.mts +45 -0
- package/dist/js/floatable/floatable.embedded.d.mts +2 -2
- package/dist/js/floatable/floatable.embedded.mjs +64 -92
- package/dist/js/floatable/floatable.model.d.mts +2 -0
- package/dist/js/floatable/floatable.model.mjs +23 -0
- package/dist/js/floatable/floatable.standalone.d.mts +2 -1
- package/dist/js/floatable.embedded-ncshL3Sa.d.mts +17 -0
- package/dist/js/{floatable.embedded-DQYkXt8X.d.mts → floatable.model-DXsQgoU7.d.mts} +13 -20
- package/dist/js/focus-trap/focus-trap.embedded.d.mts +2 -2
- package/dist/js/focus-trap/focus-trap.embedded.mjs +117 -138
- package/dist/js/focus-trap/focus-trap.model.d.mts +2 -0
- package/dist/js/focus-trap/focus-trap.model.mjs +15 -0
- package/dist/js/focus-trap/focus-trap.standalone.d.mts +2 -1
- package/dist/js/focus-trap.embedded-DpcPkP7c.d.mts +13 -0
- package/dist/js/{focus-trap.embedded-CjyFQYow.d.mts → focus-trap.model-CpltX5B5.d.mts} +16 -18
- package/dist/js/index.d.mts +26 -14
- package/dist/js/index.mjs +18 -17
- package/dist/js/internal/attributable.d.mts +1 -1
- package/dist/js/internal/attributable.mjs +3 -2
- package/dist/js/internal/draggable/draggable.model.d.mts +2 -0
- package/dist/js/internal/draggable/draggable.model.mjs +37 -0
- package/dist/js/internal/draggable/index.d.mts +13 -0
- package/dist/js/internal/draggable/index.mjs +243 -0
- package/dist/js/internal/l10n/index.d.mts +5 -0
- package/dist/js/internal/l10n/index.mjs +147 -0
- package/dist/js/internal/l10n/l10n.model.d.mts +2 -0
- package/dist/js/internal/l10n/l10n.model.mjs +12 -0
- package/dist/js/internal/misc.d.mts +3 -2
- package/dist/js/internal/misc.mjs +4 -6
- package/dist/js/internal/navigable/index.d.mts +6 -0
- package/dist/js/internal/navigable/index.mjs +125 -0
- package/dist/js/internal/navigable/navigable.model.d.mts +2 -0
- package/dist/js/internal/navigable/navigable.model.mjs +18 -0
- package/dist/js/internal/option-list/option-list.constants.d.mts +8 -0
- package/dist/js/internal/option-list/option-list.constants.mjs +22 -0
- package/dist/js/internal/option-list/option-list.data.d.mts +21 -0
- package/dist/js/internal/option-list/option-list.data.mjs +2 -0
- package/dist/js/internal/option-list/option-list.dom.d.mts +18 -0
- package/dist/js/internal/option-list/option-list.dom.mjs +2 -0
- package/dist/js/internal/option-list/option-list.event.d.mts +6 -0
- package/dist/js/internal/option-list/option-list.event.mjs +66 -0
- package/dist/js/internal/option-list/option-list.form.d.mts +7 -0
- package/dist/js/internal/option-list/option-list.form.mjs +53 -0
- package/dist/js/internal/option-list/option-list.misc.d.mts +13 -0
- package/dist/js/internal/option-list/option-list.misc.mjs +2 -0
- package/dist/js/internal/option-list/option-list.model.d.mts +2 -0
- package/dist/js/internal/option-list/option-list.state.d.mts +8 -0
- package/dist/js/internal/option-list/option-list.state.mjs +39 -0
- package/dist/js/l10n/index.d.mts +3 -0
- package/dist/js/l10n/index.mjs +2 -0
- package/dist/js/l10n.model-D1E1u35L.d.mts +54 -0
- package/dist/js/listbox/index.d.mts +9 -18
- package/dist/js/listbox/index.mjs +49 -52
- package/dist/js/listbox/listbox.constants.d.mts +2 -0
- package/dist/js/listbox/{constants.listbox.mjs → listbox.constants.mjs} +11 -15
- package/dist/js/listbox/listbox.dom.d.mts +5 -0
- package/dist/js/listbox/listbox.dom.mjs +2 -0
- package/dist/js/listbox/listbox.event.d.mts +9 -0
- package/dist/js/listbox/listbox.event.mjs +2 -0
- package/dist/js/listbox/listbox.misc.d.mts +2 -0
- package/dist/js/listbox/listbox.misc.mjs +2 -0
- package/dist/js/listbox/listbox.model.d.mts +2 -0
- package/dist/js/listbox/listbox.model.mjs +1 -0
- package/dist/js/listbox/listbox.state.d.mts +9 -0
- package/dist/js/listbox/listbox.state.mjs +2 -0
- package/dist/js/listbox.constants-DOBMwKup.d.mts +9 -0
- package/dist/js/listbox.misc-DwfB4Mu_.d.mts +24 -0
- package/dist/js/listbox.model-C0MYWXZe.d.mts +20 -0
- package/dist/js/listbox.state-BrN296BM.mjs +240 -0
- package/dist/js/menu/index.mjs +171 -0
- package/dist/js/menu/menu.model.d.mts +33 -0
- package/dist/js/menu/menu.model.mjs +15 -0
- package/dist/js/movable/movable.embedded.d.mts +2 -2
- package/dist/js/movable/movable.embedded.mjs +77 -86
- package/dist/js/movable/movable.model.d.mts +2 -0
- package/dist/js/movable/movable.model.mjs +12 -0
- package/dist/js/movable/movable.standalone.d.mts +2 -1
- package/dist/js/movable.embedded-C1bDTLGs.d.mts +11 -0
- package/dist/js/movable.model-D9nnPWKk.d.mts +186 -0
- package/dist/js/navigable.model-BqoR6iBv.d.mts +44 -0
- package/dist/js/option-list.data-CgMyUwPc.mjs +441 -0
- package/dist/js/option-list.model-CCPUlPeX.d.mts +169 -0
- package/dist/js/popover/index.d.mts +12 -0
- package/dist/js/{popover.mjs → popover/index.mjs} +41 -51
- package/dist/js/popover/popover.model.d.mts +2 -0
- package/dist/js/popover/popover.model.mjs +12 -0
- package/dist/js/popover.model-DiLdz0Hc.d.mts +38 -0
- package/dist/js/resizable/resizable.embedded.d.mts +2 -2
- package/dist/js/resizable/resizable.embedded.mjs +43 -58
- package/dist/js/resizable/resizable.model.d.mts +2 -0
- package/dist/js/resizable/resizable.model.mjs +21 -0
- package/dist/js/resizable/resizable.standalone.d.mts +2 -1
- package/dist/js/resizable.embedded-BemH-7Re.d.mts +11 -0
- package/dist/js/resizable.model-YEtcC9li.d.mts +46 -0
- package/dist/js/sortable/sortable.embedded.d.mts +2 -2
- package/dist/js/sortable/sortable.embedded.mjs +111 -116
- package/dist/js/sortable/sortable.model.d.mts +2 -0
- package/dist/js/sortable/sortable.model.mjs +24 -0
- package/dist/js/sortable/sortable.standalone.d.mts +2 -1
- package/dist/js/sortable.embedded-CrEGff9k.d.mts +11 -0
- package/dist/js/{splitter.d.mts → splitter/index.d.mts} +6 -4
- package/dist/js/{splitter.mjs → splitter/index.mjs} +90 -128
- package/dist/js/splitter/splitter.model.d.mts +2 -0
- package/dist/js/splitter/splitter.model.mjs +37 -0
- package/dist/js/splitter.model-C24W6eZ7.d.mts +57 -0
- package/dist/js/{tabs.d.mts → tabs/index.d.mts} +8 -8
- package/dist/js/{tabs.mjs → tabs/index.mjs} +58 -58
- package/dist/js/tabs/tabs.model.d.mts +2 -0
- package/dist/js/tabs/tabs.model.mjs +18 -0
- package/dist/js/tabs.model-BHPy7fPo.d.mts +40 -0
- package/dist/js/toolbar/index.mjs +27 -0
- package/dist/js/toolbar/toolbar.model.d.mts +11 -0
- package/dist/js/toolbar/toolbar.model.mjs +7 -0
- package/dist/js/tooltip/index.d.mts +19 -0
- package/dist/js/{tooltip.mjs → tooltip/index.mjs} +61 -86
- package/dist/js/tooltip/tooltip.model.d.mts +2 -0
- package/dist/js/tooltip/tooltip.model.mjs +15 -0
- package/dist/js/tooltip.model-BpNStw5z.d.mts +37 -0
- package/package.json +30 -24
- package/dist/js/color-picker/constants.color-picker.d.mts +0 -2
- package/dist/js/color-picker/event.color-picker.mjs +0 -2
- package/dist/js/color-picker/misc.color-picker.d.mts +0 -2
- package/dist/js/color-picker/misc.color-picker.mjs +0 -2
- package/dist/js/color-picker/models.color-picker.d.mts +0 -2
- package/dist/js/color-picker/state.color-picker.d.mts +0 -8
- package/dist/js/color-picker/state.color-picker.mjs +0 -2
- package/dist/js/combobox/constants.combobox.d.mts +0 -2
- package/dist/js/combobox/dom.combobox.d.mts +0 -26
- package/dist/js/combobox/misc.combobox.d.mts +0 -2
- package/dist/js/combobox/misc.combobox.mjs +0 -2
- package/dist/js/combobox/models.combobox.d.mts +0 -43
- package/dist/js/combobox/state.combobox.d.mts +0 -11
- package/dist/js/combobox/state.combobox.mjs +0 -2
- package/dist/js/constants.color-picker-B-gFjL8m.d.mts +0 -364
- package/dist/js/constants.combobox-8EMRmv09.d.mts +0 -18
- package/dist/js/constants.listbox-DGnX32kv.d.mts +0 -8
- package/dist/js/dialog.d.mts +0 -47
- package/dist/js/dialog.mjs +0 -131
- package/dist/js/draggable-B5-70SZm.d.mts +0 -155
- package/dist/js/event.color-picker-BEpq0Adu.mjs +0 -485
- package/dist/js/index-C5D3-oiI.d.mts +0 -177
- package/dist/js/internal/draggable.d.mts +0 -2
- package/dist/js/internal/draggable.mjs +0 -265
- package/dist/js/internal/listbox/listbox.constants.d.mts +0 -8
- package/dist/js/internal/listbox/listbox.constants.mjs +0 -22
- package/dist/js/internal/listbox/listbox.data.d.mts +0 -19
- package/dist/js/internal/listbox/listbox.data.mjs +0 -2
- package/dist/js/internal/listbox/listbox.dom.d.mts +0 -65
- package/dist/js/internal/listbox/listbox.dom.mjs +0 -2
- package/dist/js/internal/listbox/listbox.event.d.mts +0 -4
- package/dist/js/internal/listbox/listbox.event.mjs +0 -63
- package/dist/js/internal/listbox/listbox.form.d.mts +0 -5
- package/dist/js/internal/listbox/listbox.form.mjs +0 -53
- package/dist/js/internal/listbox/listbox.misc.d.mts +0 -11
- package/dist/js/internal/listbox/listbox.misc.mjs +0 -2
- package/dist/js/internal/listbox/listbox.model.d.mts +0 -2
- package/dist/js/internal/listbox/listbox.state.d.mts +0 -6
- package/dist/js/internal/listbox/listbox.state.mjs +0 -40
- package/dist/js/internal/navigable.d.mts +0 -36
- package/dist/js/internal/navigable.mjs +0 -135
- package/dist/js/l10n-Bn-7RcwR.d.mts +0 -20
- package/dist/js/l10n.d.mts +0 -2
- package/dist/js/l10n.mjs +0 -80
- package/dist/js/listbox/constants.listbox.d.mts +0 -2
- package/dist/js/listbox/event.listbox.d.mts +0 -7
- package/dist/js/listbox/event.listbox.mjs +0 -2
- package/dist/js/listbox/misc.listbox.d.mts +0 -2
- package/dist/js/listbox/misc.listbox.mjs +0 -2
- package/dist/js/listbox/state.listbox.d.mts +0 -10
- package/dist/js/listbox/state.listbox.mjs +0 -2
- package/dist/js/listbox.data-DQ7-x2uY.mjs +0 -425
- package/dist/js/listbox.model-BHPA7GM4.d.mts +0 -125
- package/dist/js/menu.mjs +0 -172
- package/dist/js/misc.listbox-DKB-j0UK.mjs +0 -196
- package/dist/js/misc.listbox-mZMuYOxg.d.mts +0 -20
- package/dist/js/popover.d.mts +0 -38
- package/dist/js/resizable.embedded-dvhdfQgt.d.mts +0 -34
- package/dist/js/toolbar.mjs +0 -31
- package/dist/js/tooltip.d.mts +0 -45
- /package/dist/js/combobox/{models.combobox.mjs → combobox.model.mjs} +0 -0
- /package/dist/js/internal/{listbox/listbox.model.mjs → option-list/option-list.model.mjs} +0 -0
- /package/dist/js/{menu.d.mts → menu/index.d.mts} +0 -0
- /package/dist/js/{toolbar.d.mts → toolbar/index.d.mts} +0 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { DRAGGABLE_SELECTOR, DRAGGABLE_SELECTOR_MOVABLE_HANDLE, DRAGGABLE_SELECTOR_SORTABLE_HANDLE, DRAGGABLE_SELECTOR_SORTABLE_ITEM, DRAGGABLE_SYMBOL, draggableContainers, draggableGlobals, draggableHorizontals, draggableProperties, draggableStyleToggler, draggableStyles, draggableVerticals } from "./draggable.model.mjs";
|
|
2
|
+
import { MOVABLE_ATTRIBUTE } from "../../movable/movable.model.mjs";
|
|
3
|
+
import { getAttribute, setAttribute } from "@oscarpalmer/toretto/attribute";
|
|
4
|
+
import { dispatch, getEventPosition, on } from "@oscarpalmer/toretto/event";
|
|
5
|
+
import { findAncestor } from "@oscarpalmer/toretto/find";
|
|
6
|
+
import { isHTMLOrSVGElement } from "@oscarpalmer/toretto/is";
|
|
7
|
+
import { setStyle, setStyles, toggleStyles } from "@oscarpalmer/toretto/style";
|
|
8
|
+
import { clamp } from "@oscarpalmer/atoms/number";
|
|
9
|
+
import { supportsTouch } from "@oscarpalmer/toretto/touch";
|
|
10
|
+
//#region src/js/internal/draggable/index.ts
|
|
11
|
+
function addDraggable(element, options) {
|
|
12
|
+
let instances = draggableGlobals.instances.get(element);
|
|
13
|
+
if (instances == null) {
|
|
14
|
+
instances = {};
|
|
15
|
+
draggableGlobals.instances.set(element, instances);
|
|
16
|
+
}
|
|
17
|
+
instances[this.property] ??= new this.constructor(element, options);
|
|
18
|
+
return instances[this.property];
|
|
19
|
+
}
|
|
20
|
+
function cancelDrag(item) {
|
|
21
|
+
if (item == null) return;
|
|
22
|
+
item.state.options.drag.onCancel?.(item);
|
|
23
|
+
dispatch(item.state.element, `oui:${item.state.name}:cancel`, { detail: { element: item.state.options.getOrigin() } });
|
|
24
|
+
reset();
|
|
25
|
+
}
|
|
26
|
+
function destroyDraggable(draggable) {
|
|
27
|
+
const state = draggable[DRAGGABLE_SYMBOL];
|
|
28
|
+
if (state.destroyed) return;
|
|
29
|
+
state.destroyed = true;
|
|
30
|
+
destroyInstance(draggable, state);
|
|
31
|
+
}
|
|
32
|
+
function destroyInstance(instance, state) {
|
|
33
|
+
unsetContainer({
|
|
34
|
+
instance,
|
|
35
|
+
state
|
|
36
|
+
});
|
|
37
|
+
state.element.removeAttribute(state.attribute);
|
|
38
|
+
state.styling.remove();
|
|
39
|
+
state.container = void 0;
|
|
40
|
+
state.element = void 0;
|
|
41
|
+
state.options = void 0;
|
|
42
|
+
state.styling = void 0;
|
|
43
|
+
}
|
|
44
|
+
function getDraggableStates(element) {
|
|
45
|
+
return draggableGlobals.states.get(element);
|
|
46
|
+
}
|
|
47
|
+
function getDraggableElement() {
|
|
48
|
+
return this[DRAGGABLE_SYMBOL].element;
|
|
49
|
+
}
|
|
50
|
+
function getHandle(event, isMovable) {
|
|
51
|
+
return findAncestor(event, isMovable ? DRAGGABLE_SELECTOR_MOVABLE_HANDLE : DRAGGABLE_SELECTOR_SORTABLE_HANDLE);
|
|
52
|
+
}
|
|
53
|
+
function getNextPosition(item, position) {
|
|
54
|
+
let x = draggableGlobals.original?.x ?? 0;
|
|
55
|
+
let y = draggableGlobals.original?.y ?? 0;
|
|
56
|
+
if (item.state.horizontal) {
|
|
57
|
+
x = position.x - (draggableGlobals.offset?.x ?? 0);
|
|
58
|
+
if (draggableGlobals.container != null && draggableGlobals.element != null) x = clamp(x, draggableGlobals.container.left, draggableGlobals.container.right - draggableGlobals.element.rectangle.width);
|
|
59
|
+
}
|
|
60
|
+
if (item.state.vertical) {
|
|
61
|
+
y = position.y - (draggableGlobals.offset?.y ?? 0);
|
|
62
|
+
if (draggableGlobals.container != null && draggableGlobals.element != null) y = clamp(y, draggableGlobals.container.top, draggableGlobals.container.bottom - draggableGlobals.element.rectangle.height);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
x,
|
|
66
|
+
y
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function initializeDraggable(draggable, name, event, attribute, element, options, extras) {
|
|
70
|
+
const state = {
|
|
71
|
+
...extras,
|
|
72
|
+
attribute,
|
|
73
|
+
element,
|
|
74
|
+
event,
|
|
75
|
+
name,
|
|
76
|
+
options,
|
|
77
|
+
destroyed: false,
|
|
78
|
+
horizontal: true,
|
|
79
|
+
styling: toggleStyles(element, draggableStyles),
|
|
80
|
+
vertical: true
|
|
81
|
+
};
|
|
82
|
+
const item = {
|
|
83
|
+
state,
|
|
84
|
+
instance: draggable
|
|
85
|
+
};
|
|
86
|
+
setContainer(item);
|
|
87
|
+
setDirection(item);
|
|
88
|
+
setAttribute(element, attribute, "");
|
|
89
|
+
let states = draggableGlobals.states.get(element);
|
|
90
|
+
states ??= {};
|
|
91
|
+
states[state.name] = state;
|
|
92
|
+
draggableGlobals.states.set(element, states);
|
|
93
|
+
return state;
|
|
94
|
+
}
|
|
95
|
+
function onKeydown(event) {
|
|
96
|
+
if (current != null && event.key === "Escape") cancelDrag(current);
|
|
97
|
+
}
|
|
98
|
+
function onPointerdown(event) {
|
|
99
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || (supportsTouch.value ? event.type === "mousedown" : event.type === "touchstart" || event.button !== 0)) return;
|
|
100
|
+
const container = findAncestor(event, DRAGGABLE_SELECTOR);
|
|
101
|
+
if (container == null) return;
|
|
102
|
+
const instances = draggableGlobals.instances.get(container);
|
|
103
|
+
const states = draggableGlobals.states.get(container);
|
|
104
|
+
if (instances == null || states == null) return;
|
|
105
|
+
const isMovable = container.hasAttribute(MOVABLE_ATTRIBUTE);
|
|
106
|
+
const item = {
|
|
107
|
+
instance: isMovable ? instances.movable : instances.sortable,
|
|
108
|
+
state: isMovable ? states.movable : states.sortable
|
|
109
|
+
};
|
|
110
|
+
if (item.instance == null || item.state == null) return;
|
|
111
|
+
if (supportsTouch.value) event.preventDefault();
|
|
112
|
+
let element = container;
|
|
113
|
+
if (!isMovable) {
|
|
114
|
+
element = findAncestor(event, DRAGGABLE_SELECTOR_SORTABLE_ITEM);
|
|
115
|
+
if (element == null || element.parentElement !== container) return;
|
|
116
|
+
}
|
|
117
|
+
let handle = element;
|
|
118
|
+
item.state.hasHandles ??= element.querySelector(DRAGGABLE_SELECTOR_SORTABLE_HANDLE) != null;
|
|
119
|
+
if (item.state.hasHandles) handle = getHandle(event, isMovable);
|
|
120
|
+
if (handle == null) return;
|
|
121
|
+
const dragged = item.state.options.getDragged();
|
|
122
|
+
const rectangle = dragged.getBoundingClientRect();
|
|
123
|
+
const position = getEventPosition(event) ?? {
|
|
124
|
+
x: 0,
|
|
125
|
+
y: 0
|
|
126
|
+
};
|
|
127
|
+
current = item;
|
|
128
|
+
draggableGlobals.container = item.state.container?.getBoundingClientRect();
|
|
129
|
+
draggableGlobals.element = {
|
|
130
|
+
rectangle,
|
|
131
|
+
node: dragged
|
|
132
|
+
};
|
|
133
|
+
draggableGlobals.offset = item.state.options.position.getOffset(item, element, position);
|
|
134
|
+
draggableGlobals.original = item.state.options.position.getOriginal(item, position);
|
|
135
|
+
if (dispatch(item.state.element, `oui:${item.state.name}:begin`, { detail: {
|
|
136
|
+
element,
|
|
137
|
+
position: { ...draggableGlobals.original }
|
|
138
|
+
} }).defaultPrevented) {
|
|
139
|
+
item.state.options.drag.onCancel?.(item);
|
|
140
|
+
reset();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const next = getNextPosition(item, position);
|
|
144
|
+
setStyles(dragged, {
|
|
145
|
+
position: "fixed",
|
|
146
|
+
inset: `${next.y}px auto auto ${next.x}px`,
|
|
147
|
+
transform: "translate3d(0, 0, 0)"
|
|
148
|
+
});
|
|
149
|
+
item.state.options.drag.onBegin?.(event, item, element, handle, next);
|
|
150
|
+
item.state.styling.set();
|
|
151
|
+
draggableStyleToggler.set();
|
|
152
|
+
}
|
|
153
|
+
function onPointermove(event) {
|
|
154
|
+
if (current == null) return;
|
|
155
|
+
const position = getEventPosition(event);
|
|
156
|
+
if (position == null) return;
|
|
157
|
+
const next = getNextPosition(current, position);
|
|
158
|
+
if (draggableGlobals.element != null) setStyle(draggableGlobals.element.node, "inset", `${next.y}px auto auto ${next.x}px`);
|
|
159
|
+
const detail = current.state.options.drag.onMove(event, current, {
|
|
160
|
+
calculated: next,
|
|
161
|
+
original: position
|
|
162
|
+
});
|
|
163
|
+
if (dispatch(current.state.element, `oui:${current.state.name}:move`, { detail }).defaultPrevented) cancelDrag(current);
|
|
164
|
+
}
|
|
165
|
+
function onPointerup(event) {
|
|
166
|
+
current?.state.options.drag.onEnd?.(event, current, reset);
|
|
167
|
+
}
|
|
168
|
+
function removeDraggable(element) {
|
|
169
|
+
const { property } = this;
|
|
170
|
+
removeInstance(draggableGlobals.instances, property, element);
|
|
171
|
+
removeState(draggableGlobals.states, property, element);
|
|
172
|
+
}
|
|
173
|
+
function removeInstance(instances, name, element) {
|
|
174
|
+
removeStored(instances, name, element);
|
|
175
|
+
}
|
|
176
|
+
function removeState(map, name, element) {
|
|
177
|
+
removeStored(map, name, element);
|
|
178
|
+
}
|
|
179
|
+
function removeStored(map, name, element) {
|
|
180
|
+
const stored = map.get(element);
|
|
181
|
+
const item = stored?.[name];
|
|
182
|
+
if (stored == null || item == null) return;
|
|
183
|
+
const itemAsPlainObject = item;
|
|
184
|
+
if (typeof itemAsPlainObject.destroy === "function") itemAsPlainObject.destroy();
|
|
185
|
+
stored[name] = void 0;
|
|
186
|
+
if (stored[draggableProperties[name]] == null) map.delete(element);
|
|
187
|
+
}
|
|
188
|
+
function reset() {
|
|
189
|
+
current?.state.styling.remove();
|
|
190
|
+
draggableStyleToggler.remove();
|
|
191
|
+
current = void 0;
|
|
192
|
+
draggableGlobals.container = void 0;
|
|
193
|
+
draggableGlobals.element = void 0;
|
|
194
|
+
draggableGlobals.offset = void 0;
|
|
195
|
+
draggableGlobals.original = void 0;
|
|
196
|
+
}
|
|
197
|
+
function setContainer(item) {
|
|
198
|
+
const { container } = item.state.options.input ?? {};
|
|
199
|
+
if (isHTMLOrSVGElement(container)) {
|
|
200
|
+
setContainerElement(item, container);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const selector = container ?? getAttribute(item.state.element, item.state.options.container.attribute);
|
|
204
|
+
if (typeof selector !== "string") return;
|
|
205
|
+
const element = draggableContainers.has(selector) ? item.state.element.ownerDocument.body : document.querySelector(selector) ?? void 0;
|
|
206
|
+
if (isHTMLOrSVGElement(element)) setContainerElement(item, element);
|
|
207
|
+
}
|
|
208
|
+
function setContainerElement(item, element) {
|
|
209
|
+
item.state.container = element;
|
|
210
|
+
const set = item.state.options.container.map.get(element);
|
|
211
|
+
if (set == null) item.state.options.container.map.set(element, /* @__PURE__ */ new Set([item.instance]));
|
|
212
|
+
else set.add(item.instance);
|
|
213
|
+
item.state.options.container.onInitialize?.(item);
|
|
214
|
+
}
|
|
215
|
+
function setDirection(item) {
|
|
216
|
+
const direction = getAttribute(item.state.element, item.state.options.direction.attribute);
|
|
217
|
+
if (draggableHorizontals.has(direction)) item.state.vertical = false;
|
|
218
|
+
else if (draggableVerticals.has(direction)) item.state.horizontal = false;
|
|
219
|
+
item.state.options.direction.onAfter?.(item);
|
|
220
|
+
}
|
|
221
|
+
function unsetContainer(item) {
|
|
222
|
+
const { container } = item.state;
|
|
223
|
+
if (container == null) return;
|
|
224
|
+
const set = item.state.options.container.map.get(container);
|
|
225
|
+
let empty = false;
|
|
226
|
+
if (set != null) {
|
|
227
|
+
set.delete(item.instance);
|
|
228
|
+
if (set.size === 0) {
|
|
229
|
+
empty = true;
|
|
230
|
+
item.state.options.container.map.delete(container);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
item.state.options.container.onDestroy?.(item, container, empty);
|
|
234
|
+
}
|
|
235
|
+
let current;
|
|
236
|
+
on(document, "keydown", onKeydown);
|
|
237
|
+
on(document, "mousedown", onPointerdown);
|
|
238
|
+
on(document, "pointermove", onPointermove);
|
|
239
|
+
on(document, "pointerup", onPointerup);
|
|
240
|
+
on(document, "touchcancel", onPointerup);
|
|
241
|
+
on(document, "touchstart", onPointerdown, { passive: false });
|
|
242
|
+
//#endregion
|
|
243
|
+
export { addDraggable, destroyDraggable, getDraggableElement, getDraggableStates, initializeDraggable, removeDraggable };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { _ as OuiLocalizationsValues, p as OuiLocalizations, u as OuiDefaultLocalizations } from "../../l10n.model-D1E1u35L.mjs";
|
|
2
|
+
//#region src/js/internal/l10n/index.d.ts
|
|
3
|
+
export declare function createDefaultLocalizations<Localizations extends OuiLocalizationsValues>(values: Localizations): OuiDefaultLocalizations<Localizations>;
|
|
4
|
+
export declare function createLocalizations<Localizations extends OuiLocalizationsValues>(defaults: OuiDefaultLocalizations<Localizations>): OuiLocalizations<Localizations>;
|
|
5
|
+
//#endregion
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { L10N_MESSAGE_DEFAULT, L10N_MESSAGE_ITEM_CREATE, L10N_MESSAGE_ITEM_UPDATE_KEY, L10N_MESSAGE_ITEM_UPDATE_VALUE, L10N_MESSAGE_OBJECT_CREATE, L10N_MESSAGE_OBJECT_UPDATE, L10N_SYMBOL, L10N_TYPE_DEFAULT, L10N_TYPE_INSTANCE } from "./l10n.model.mjs";
|
|
2
|
+
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
3
|
+
//#region src/js/internal/l10n/index.ts
|
|
4
|
+
function OuiDefaultLocalizations(values) {
|
|
5
|
+
this[L10N_SYMBOL] = {
|
|
6
|
+
defaults: values,
|
|
7
|
+
keys: new Set(Object.keys(values)),
|
|
8
|
+
type: L10N_TYPE_DEFAULT,
|
|
9
|
+
values: {}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
OuiDefaultLocalizations.prototype.localize = localizeDefault;
|
|
13
|
+
OuiDefaultLocalizations.prototype.setDefaults = setDefaultLocalizations;
|
|
14
|
+
OuiDefaultLocalizations.prototype.setLanguages = setLocalizations;
|
|
15
|
+
Object.defineProperties(OuiDefaultLocalizations.prototype, {
|
|
16
|
+
keys: {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: getKeys
|
|
19
|
+
},
|
|
20
|
+
values: {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: getValues
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
function OuiLocalizations(defaults) {
|
|
26
|
+
this[L10N_SYMBOL] = {
|
|
27
|
+
defaults,
|
|
28
|
+
keys: new Set(defaults.keys),
|
|
29
|
+
values: {},
|
|
30
|
+
type: L10N_TYPE_INSTANCE
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
OuiLocalizations.prototype.localize = localizeWithLanguage;
|
|
34
|
+
OuiLocalizations.prototype.set = setLocalizations;
|
|
35
|
+
Object.defineProperties(OuiLocalizations.prototype, { defaults: {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: getDefaults
|
|
38
|
+
} });
|
|
39
|
+
function createDefaultLocalizations(values) {
|
|
40
|
+
validateDefaultValues(values);
|
|
41
|
+
return new OuiDefaultLocalizations(values);
|
|
42
|
+
}
|
|
43
|
+
function createLocalizations(defaults) {
|
|
44
|
+
validateDefaultInstance(defaults);
|
|
45
|
+
return new OuiLocalizations(defaults);
|
|
46
|
+
}
|
|
47
|
+
function getDefaults() {
|
|
48
|
+
return this[L10N_SYMBOL].defaults;
|
|
49
|
+
}
|
|
50
|
+
function getKeys() {
|
|
51
|
+
return [...this[L10N_SYMBOL].keys];
|
|
52
|
+
}
|
|
53
|
+
function getLanguage(parameters) {
|
|
54
|
+
return (typeof parameters?.language === "string" ? parameters.language : parameters?.element?.closest("[lang]")?.getAttribute("lang") ?? document.documentElement.lang).toLowerCase();
|
|
55
|
+
}
|
|
56
|
+
function getLocalization(key, parameters, defaultLocalizations, instanceLocalizations) {
|
|
57
|
+
const defaultState = defaultLocalizations?.[L10N_SYMBOL];
|
|
58
|
+
const instanceState = instanceLocalizations?.[L10N_SYMBOL];
|
|
59
|
+
const language = getLanguage(parameters);
|
|
60
|
+
const values = defaultState == null ? instanceState == null ? [] : [instanceState.values, instanceState.defaults.values.languages] : [defaultState.values];
|
|
61
|
+
const { length } = values;
|
|
62
|
+
let localization;
|
|
63
|
+
let shortLanguage;
|
|
64
|
+
for (let index = 0; index < length; index += 1) {
|
|
65
|
+
const value = values[index];
|
|
66
|
+
localization = value?.[language]?.[key];
|
|
67
|
+
if (localization != null) break;
|
|
68
|
+
shortLanguage ??= language.split("-")[0];
|
|
69
|
+
if (shortLanguage === language) continue;
|
|
70
|
+
localization = value?.[shortLanguage]?.[key];
|
|
71
|
+
if (localization != null) break;
|
|
72
|
+
}
|
|
73
|
+
if (localization != null) return localization;
|
|
74
|
+
return defaultState?.defaults[key] ?? instanceState?.defaults.values.defaults[key] ?? "";
|
|
75
|
+
}
|
|
76
|
+
function getValues() {
|
|
77
|
+
const { defaults, values } = this[L10N_SYMBOL];
|
|
78
|
+
return {
|
|
79
|
+
defaults,
|
|
80
|
+
languages: values
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function isValidLocalization(value) {
|
|
84
|
+
return typeof value === "string" || typeof value === "function";
|
|
85
|
+
}
|
|
86
|
+
function localizeDefault(key, parameters) {
|
|
87
|
+
return localizeValue(key, parameters, this, void 0);
|
|
88
|
+
}
|
|
89
|
+
function localizeWithLanguage(key, parameters) {
|
|
90
|
+
return localizeValue(key, parameters, void 0, this);
|
|
91
|
+
}
|
|
92
|
+
function localizeValue(key, parameters, defaultLocalizations, instanceLocalizations) {
|
|
93
|
+
const localization = getLocalization(key, parameters, defaultLocalizations, instanceLocalizations);
|
|
94
|
+
if (typeof localization === "function") return localization(...Array.isArray(parameters?.arguments) ? parameters.arguments : []);
|
|
95
|
+
return localization;
|
|
96
|
+
}
|
|
97
|
+
async function setDefaultLocalizations(values) {
|
|
98
|
+
if (typeof values !== "object" || values == null) throw new TypeError(L10N_MESSAGE_OBJECT_UPDATE);
|
|
99
|
+
const state = this[L10N_SYMBOL];
|
|
100
|
+
return updateLocalizationValues(state, state.defaults, values).then((count) => count > 0);
|
|
101
|
+
}
|
|
102
|
+
function setLocalizations(first, second) {
|
|
103
|
+
return updateLocalizations(this, typeof first === "string" ? { [first]: second } : first);
|
|
104
|
+
}
|
|
105
|
+
async function updateLocalizationValues(state, to, from) {
|
|
106
|
+
const keys = Object.keys(from);
|
|
107
|
+
const keysLength = keys.length;
|
|
108
|
+
const toAsPlainObject = to;
|
|
109
|
+
let count = 0;
|
|
110
|
+
for (let keysIndex = 0; keysIndex < keysLength; keysIndex += 1) {
|
|
111
|
+
const key = keys[keysIndex];
|
|
112
|
+
const keyValue = from[key];
|
|
113
|
+
const normalizedKey = key.toLowerCase();
|
|
114
|
+
if (!state.keys.has(normalizedKey)) throw new TypeError(L10N_MESSAGE_ITEM_UPDATE_KEY);
|
|
115
|
+
if (!isValidLocalization(keyValue)) throw new TypeError(L10N_MESSAGE_ITEM_UPDATE_VALUE);
|
|
116
|
+
if (state.keys.has(normalizedKey) && isValidLocalization(keyValue)) {
|
|
117
|
+
count += 1;
|
|
118
|
+
toAsPlainObject[normalizedKey] = keyValue;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return count;
|
|
122
|
+
}
|
|
123
|
+
async function updateLocalizations(localizations, values) {
|
|
124
|
+
if (typeof values !== "object" || values == null) throw new TypeError(L10N_MESSAGE_OBJECT_UPDATE);
|
|
125
|
+
const state = localizations[L10N_SYMBOL];
|
|
126
|
+
const languages = Object.keys(values);
|
|
127
|
+
const languagesLength = languages.length;
|
|
128
|
+
let count = 0;
|
|
129
|
+
for (let languagesIndex = 0; languagesIndex < languagesLength; languagesIndex += 1) {
|
|
130
|
+
const language = languages[languagesIndex];
|
|
131
|
+
const languageValue = values[language];
|
|
132
|
+
if (typeof languageValue !== "object" || languageValue == null) throw new TypeError(L10N_MESSAGE_OBJECT_UPDATE);
|
|
133
|
+
const normalizedLanguage = language.toLowerCase();
|
|
134
|
+
state.values[normalizedLanguage] ??= {};
|
|
135
|
+
count += await updateLocalizationValues(state, state.values[normalizedLanguage], languageValue);
|
|
136
|
+
}
|
|
137
|
+
return count > 0;
|
|
138
|
+
}
|
|
139
|
+
function validateDefaultInstance(value) {
|
|
140
|
+
if (typeof value !== "object" || value === null || !(L10N_SYMBOL in value)) throw new TypeError(L10N_MESSAGE_DEFAULT);
|
|
141
|
+
}
|
|
142
|
+
function validateDefaultValues(value) {
|
|
143
|
+
if (!isPlainObject(value) || Object.keys(value).length === 0) throw new TypeError(L10N_MESSAGE_OBJECT_CREATE);
|
|
144
|
+
if (!Object.values(value).every(isValidLocalization)) throw new TypeError(L10N_MESSAGE_ITEM_CREATE);
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
export { createDefaultLocalizations, createLocalizations };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as OuiLocalizationsValues, a as L10N_MESSAGE_OBJECT_CREATE, c as L10N_TYPE_DEFAULT, d as OuiDefaultLocalizationsState, f as OuiDefaultLocalizationsValues, g as OuiLocalizationsType, h as OuiLocalizationsState, i as L10N_MESSAGE_ITEM_UPDATE_VALUE, l as L10N_TYPE_INSTANCE, m as OuiLocalizationsParameters, n as L10N_MESSAGE_ITEM_CREATE, o as L10N_MESSAGE_OBJECT_UPDATE, p as OuiLocalizations, r as L10N_MESSAGE_ITEM_UPDATE_KEY, s as L10N_SYMBOL, t as L10N_MESSAGE_DEFAULT, u as OuiDefaultLocalizations } from "../../l10n.model-D1E1u35L.mjs";
|
|
2
|
+
export { L10N_MESSAGE_DEFAULT, L10N_MESSAGE_ITEM_CREATE, L10N_MESSAGE_ITEM_UPDATE_KEY, L10N_MESSAGE_ITEM_UPDATE_VALUE, L10N_MESSAGE_OBJECT_CREATE, L10N_MESSAGE_OBJECT_UPDATE, L10N_SYMBOL, L10N_TYPE_DEFAULT, L10N_TYPE_INSTANCE, OuiDefaultLocalizations, OuiDefaultLocalizationsState, OuiDefaultLocalizationsValues, OuiLocalizations, OuiLocalizationsParameters, OuiLocalizationsState, OuiLocalizationsType, OuiLocalizationsValues };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/js/internal/l10n/l10n.model.ts
|
|
2
|
+
const L10N_MESSAGE_DEFAULT = "Default localizations must be an instance of OuiDefaultLocalizations.";
|
|
3
|
+
const L10N_MESSAGE_ITEM_CREATE = "Localization item must be a string or a function.";
|
|
4
|
+
const L10N_MESSAGE_ITEM_UPDATE_KEY = "Localization item key must be known.";
|
|
5
|
+
const L10N_MESSAGE_ITEM_UPDATE_VALUE = "Localization item value must be a string or a function.";
|
|
6
|
+
const L10N_MESSAGE_OBJECT_CREATE = "Default localizations must be a non-empty plain object.";
|
|
7
|
+
const L10N_MESSAGE_OBJECT_UPDATE = "Localizations update object must be a plain object.";
|
|
8
|
+
const L10N_TYPE_DEFAULT = "default";
|
|
9
|
+
const L10N_TYPE_INSTANCE = "instance";
|
|
10
|
+
const L10N_SYMBOL = Symbol("l10n");
|
|
11
|
+
//#endregion
|
|
12
|
+
export { L10N_MESSAGE_DEFAULT, L10N_MESSAGE_ITEM_CREATE, L10N_MESSAGE_ITEM_UPDATE_KEY, L10N_MESSAGE_ITEM_UPDATE_VALUE, L10N_MESSAGE_OBJECT_CREATE, L10N_MESSAGE_OBJECT_UPDATE, L10N_SYMBOL, L10N_TYPE_DEFAULT, L10N_TYPE_INSTANCE };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AnyAriaBooleanAttribute } from "@oscarpalmer/toretto/models";
|
|
2
2
|
//#region src/js/internal/misc.d.ts
|
|
3
3
|
export declare function copyValue(value: string, onSuccess?: () => void, onError?: () => void): void;
|
|
4
|
-
export declare function getAttributeValue<Value>(element:
|
|
5
|
-
export declare function getBooleanAriaValue(element:
|
|
4
|
+
export declare function getAttributeValue<Value>(element: Element, attribute: string, possible: Set<Value>, defaultValue: Value): Value;
|
|
5
|
+
export declare function getBooleanAriaValue(element: Element, attribute: AnyAriaBooleanAttribute): boolean;
|
|
6
|
+
export declare const EXPRESSION_WHITESPACE: RegExp;
|
|
6
7
|
//#endregion
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { getAria } from "@oscarpalmer/toretto/aria";
|
|
2
2
|
import { getAttribute } from "@oscarpalmer/toretto/attribute";
|
|
3
3
|
import { noop } from "@oscarpalmer/atoms/function";
|
|
4
|
+
import { attempt } from "@oscarpalmer/atoms/result";
|
|
4
5
|
//#region src/js/internal/misc.ts
|
|
5
6
|
function copyValue(value, onSuccess, onError) {
|
|
6
|
-
|
|
7
|
-
navigator.clipboard.writeText(value).then(onSuccess ?? noop, onError ?? noop);
|
|
8
|
-
} catch {
|
|
9
|
-
onError?.();
|
|
10
|
-
}
|
|
7
|
+
if (!attempt(() => navigator.clipboard.writeText(value).then(onSuccess ?? noop, onError ?? noop)).ok) onError?.();
|
|
11
8
|
}
|
|
12
9
|
function getAttributeValue(element, attribute, possible, defaultValue) {
|
|
13
10
|
const value = getAttribute(element, attribute);
|
|
@@ -17,5 +14,6 @@ function getBooleanAriaValue(element, attribute) {
|
|
|
17
14
|
const value = getAria(element, attribute);
|
|
18
15
|
return value === true || value === "true";
|
|
19
16
|
}
|
|
17
|
+
const EXPRESSION_WHITESPACE = /\s+/;
|
|
20
18
|
//#endregion
|
|
21
|
-
export { copyValue, getAttributeValue, getBooleanAriaValue };
|
|
19
|
+
export { EXPRESSION_WHITESPACE, copyValue, getAttributeValue, getBooleanAriaValue };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { d as OuiNavigable, h as OuiNavigableOrientation, m as OuiNavigableOptions } from "../../navigable.model-BqoR6iBv.mjs";
|
|
2
|
+
//#region src/js/internal/navigable/index.d.ts
|
|
3
|
+
export declare function getNavigable(element: Element, options: OuiNavigableOptions): OuiNavigable;
|
|
4
|
+
export declare function getNavigableOrientation(element: Element, vertical: boolean, aria?: boolean): OuiNavigableOrientation;
|
|
5
|
+
export declare function updateNavigableFocus(navigable: OuiNavigable, focus: boolean, items?: HTMLElement[]): void;
|
|
6
|
+
//#endregion
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { NAVIGABLE_KEYS_ABSOLUTE, NAVIGABLE_KEYS_ACTIVATE, NAVIGABLE_KEYS_ALL, NAVIGABLE_KEYS_HORIZONTAL, NAVIGABLE_KEYS_NEXT, NAVIGABLE_ORIENTATIONS, NAVIGABLE_ORIENTATION_HORIZONTAL, NAVIGABLE_ORIENTATION_VERTICAL, NAVIGABLE_SYMBOL } from "./navigable.model.mjs";
|
|
2
|
+
import { getAria, setAria, setRole } from "@oscarpalmer/toretto/aria";
|
|
3
|
+
import { getAttribute } from "@oscarpalmer/toretto/attribute";
|
|
4
|
+
import { on } from "@oscarpalmer/toretto/event";
|
|
5
|
+
import { findAncestor } from "@oscarpalmer/toretto/find";
|
|
6
|
+
import { isHTMLOrSVGElement } from "@oscarpalmer/toretto/is";
|
|
7
|
+
import { filter } from "@oscarpalmer/atoms/array/filter";
|
|
8
|
+
import { clamp } from "@oscarpalmer/atoms/number";
|
|
9
|
+
//#region src/js/internal/navigable/index.ts
|
|
10
|
+
function OuiNavigable(element, options) {
|
|
11
|
+
this[NAVIGABLE_SYMBOL] = {
|
|
12
|
+
element,
|
|
13
|
+
options,
|
|
14
|
+
active: { index: 0 },
|
|
15
|
+
listeners: [
|
|
16
|
+
on(element, "click", (event) => {
|
|
17
|
+
onClick(this, event);
|
|
18
|
+
}, { passive: false }),
|
|
19
|
+
on(element, "focusin", (event) => {
|
|
20
|
+
onFocusin(this, event);
|
|
21
|
+
}),
|
|
22
|
+
on(element, "keydown", (event) => {
|
|
23
|
+
onKeydown(this, event);
|
|
24
|
+
}, { passive: false })
|
|
25
|
+
],
|
|
26
|
+
orientation: options?.orientation ?? getNavigableOrientation(element, options.vertical)
|
|
27
|
+
};
|
|
28
|
+
setAria(element, "orientation", this[NAVIGABLE_SYMBOL].orientation);
|
|
29
|
+
if (options.role != null) setRole(element, options.role);
|
|
30
|
+
}
|
|
31
|
+
OuiNavigable.prototype.destroy = destroyNavigable;
|
|
32
|
+
OuiNavigable.prototype.navigate = navigateWithNavigable;
|
|
33
|
+
function destroyNavigable() {
|
|
34
|
+
const state = this[NAVIGABLE_SYMBOL];
|
|
35
|
+
const listeners = state.listeners.splice(0);
|
|
36
|
+
for (const listener of listeners) listener();
|
|
37
|
+
state.active.element = void 0;
|
|
38
|
+
state.element = void 0;
|
|
39
|
+
}
|
|
40
|
+
function getItems(container, selector) {
|
|
41
|
+
return filter([...container.querySelectorAll(selector)], isValidItem);
|
|
42
|
+
}
|
|
43
|
+
function getNavigable(element, options) {
|
|
44
|
+
return new OuiNavigable(element, options);
|
|
45
|
+
}
|
|
46
|
+
function getNavigableOrientation(element, vertical, aria) {
|
|
47
|
+
const attribute = aria ?? true ? getAria(element, "orientation") : getAttribute(element, "orientation");
|
|
48
|
+
return NAVIGABLE_ORIENTATIONS.has(attribute) ? attribute : vertical ? NAVIGABLE_ORIENTATION_VERTICAL : NAVIGABLE_ORIENTATION_HORIZONTAL;
|
|
49
|
+
}
|
|
50
|
+
function isValidItem(element) {
|
|
51
|
+
return "disabled" in element ? element.disabled !== true : true;
|
|
52
|
+
}
|
|
53
|
+
function navigateWithNavigable(index, focus) {
|
|
54
|
+
const { element, options } = this[NAVIGABLE_SYMBOL];
|
|
55
|
+
const items = getItems(element, options.selector);
|
|
56
|
+
if (index >= 0 && index < items.length) onNavigate(this, index, items, focus ?? false);
|
|
57
|
+
}
|
|
58
|
+
function onClick(navigable, event) {
|
|
59
|
+
const { active, element, options } = navigable[NAVIGABLE_SYMBOL];
|
|
60
|
+
const item = findAncestor(event, options.selector);
|
|
61
|
+
const items = getItems(element, options.selector);
|
|
62
|
+
const index = items.indexOf(item);
|
|
63
|
+
if (index === -1) return;
|
|
64
|
+
if (index !== active.index) onNavigate(navigable, index, items, false);
|
|
65
|
+
options.onActivate?.(navigable);
|
|
66
|
+
item?.focus?.();
|
|
67
|
+
}
|
|
68
|
+
function onNavigate(navigable, index, items, focus) {
|
|
69
|
+
const { active, options } = navigable[NAVIGABLE_SYMBOL];
|
|
70
|
+
active.element = items[index];
|
|
71
|
+
active.index = index;
|
|
72
|
+
updateNavigableFocus(navigable, focus, items);
|
|
73
|
+
options.onNavigation?.(navigable);
|
|
74
|
+
}
|
|
75
|
+
function onFocusin(navigable, event) {
|
|
76
|
+
const { active, element, options } = navigable[NAVIGABLE_SYMBOL];
|
|
77
|
+
const item = findAncestor(event, options.selector);
|
|
78
|
+
if (!isHTMLOrSVGElement(item) || !isValidItem(item)) return;
|
|
79
|
+
const items = getItems(element, options.selector);
|
|
80
|
+
const index = items.indexOf(item);
|
|
81
|
+
if (index === -1) return;
|
|
82
|
+
active.element = item;
|
|
83
|
+
active.index = index;
|
|
84
|
+
updateNavigableFocus(navigable, false, items);
|
|
85
|
+
}
|
|
86
|
+
function onKeydown(navigable, event) {
|
|
87
|
+
const { active, element, options, orientation } = navigable[NAVIGABLE_SYMBOL];
|
|
88
|
+
const escaped = event.key === "Escape";
|
|
89
|
+
const stopPropagation = options.onShouldDeactivate?.(event, navigable);
|
|
90
|
+
if (escaped || stopPropagation != null) {
|
|
91
|
+
if (escaped || stopPropagation) event.stopPropagation();
|
|
92
|
+
options.onDeactivate?.(event, navigable);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (!NAVIGABLE_KEYS_ALL.has(event.key)) return;
|
|
96
|
+
const mustActivate = NAVIGABLE_KEYS_ACTIVATE.has(event.key);
|
|
97
|
+
const shouldActivate = options.onShouldActivate?.(event, navigable) === true;
|
|
98
|
+
if (mustActivate || shouldActivate || options.onPreventNavigation?.(event, navigable) === true) event.stopPropagation();
|
|
99
|
+
if (mustActivate || shouldActivate) {
|
|
100
|
+
options.onActivate?.(navigable);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const items = getItems(element, options.selector);
|
|
104
|
+
const { length } = items;
|
|
105
|
+
if (length === 0) return;
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
let index;
|
|
108
|
+
if (NAVIGABLE_KEYS_ABSOLUTE.has(event.key)) index = event.key === "Home" ? 0 : items.length - 1;
|
|
109
|
+
else if (orientation === (NAVIGABLE_KEYS_HORIZONTAL.has(event.key) ? "horizontal" : "vertical")) {
|
|
110
|
+
if (active.element instanceof HTMLSelectElement) event.preventDefault();
|
|
111
|
+
index = clamp(active.index + (NAVIGABLE_KEYS_NEXT.has(event.key) ? 1 : -1), 0, length - 1, true);
|
|
112
|
+
}
|
|
113
|
+
if (index != null && index !== active.index) onNavigate(navigable, index, items, true);
|
|
114
|
+
}
|
|
115
|
+
function updateNavigableFocus(navigable, focus, items) {
|
|
116
|
+
const { active, element, options } = navigable[NAVIGABLE_SYMBOL];
|
|
117
|
+
const updated = items ?? getItems(element, options.selector);
|
|
118
|
+
const { length } = updated;
|
|
119
|
+
if (length === 0) return;
|
|
120
|
+
for (let index = 0; index < length; index += 1) updated[index].tabIndex = index === active.index ? 0 : -1;
|
|
121
|
+
active.element ??= updated[active.index];
|
|
122
|
+
if (focus) active.element?.focus();
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
export { getNavigable, getNavigableOrientation, updateNavigableFocus };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as NAVIGABLE_KEYS_NEXT, c as NAVIGABLE_ORIENTATION_HORIZONTAL, d as OuiNavigable, f as OuiNavigableActive, g as OuiNavigableState, h as OuiNavigableOrientation, i as NAVIGABLE_KEYS_HORIZONTAL, l as NAVIGABLE_ORIENTATION_VERTICAL, m as OuiNavigableOptions, n as NAVIGABLE_KEYS_ACTIVATE, o as NAVIGABLE_KEYS_VERTICAL, p as OuiNavigableCallback, r as NAVIGABLE_KEYS_ALL, s as NAVIGABLE_ORIENTATIONS, t as NAVIGABLE_KEYS_ABSOLUTE, u as NAVIGABLE_SYMBOL } from "../../navigable.model-BqoR6iBv.mjs";
|
|
2
|
+
export { NAVIGABLE_KEYS_ABSOLUTE, NAVIGABLE_KEYS_ACTIVATE, NAVIGABLE_KEYS_ALL, NAVIGABLE_KEYS_HORIZONTAL, NAVIGABLE_KEYS_NEXT, NAVIGABLE_KEYS_VERTICAL, NAVIGABLE_ORIENTATIONS, NAVIGABLE_ORIENTATION_HORIZONTAL, NAVIGABLE_ORIENTATION_VERTICAL, NAVIGABLE_SYMBOL, OuiNavigable, OuiNavigableActive, OuiNavigableCallback, OuiNavigableOptions, OuiNavigableOrientation, OuiNavigableState };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/js/internal/navigable/navigable.model.ts
|
|
2
|
+
const NAVIGABLE_KEYS_ABSOLUTE = /* @__PURE__ */ new Set(["End", "Home"]);
|
|
3
|
+
const NAVIGABLE_KEYS_ACTIVATE = /* @__PURE__ */ new Set(["Enter", " "]);
|
|
4
|
+
const NAVIGABLE_KEYS_HORIZONTAL = /* @__PURE__ */ new Set(["ArrowRight", "ArrowLeft"]);
|
|
5
|
+
const NAVIGABLE_KEYS_VERTICAL = /* @__PURE__ */ new Set(["ArrowDown", "ArrowUp"]);
|
|
6
|
+
const NAVIGABLE_KEYS_ALL = /* @__PURE__ */ new Set([
|
|
7
|
+
...NAVIGABLE_KEYS_ABSOLUTE,
|
|
8
|
+
...NAVIGABLE_KEYS_ACTIVATE,
|
|
9
|
+
...NAVIGABLE_KEYS_HORIZONTAL,
|
|
10
|
+
...NAVIGABLE_KEYS_VERTICAL
|
|
11
|
+
]);
|
|
12
|
+
const NAVIGABLE_KEYS_NEXT = /* @__PURE__ */ new Set(["ArrowDown", "ArrowRight"]);
|
|
13
|
+
const NAVIGABLE_ORIENTATION_HORIZONTAL = "horizontal";
|
|
14
|
+
const NAVIGABLE_ORIENTATION_VERTICAL = "vertical";
|
|
15
|
+
const NAVIGABLE_ORIENTATIONS = /* @__PURE__ */ new Set([NAVIGABLE_ORIENTATION_HORIZONTAL, NAVIGABLE_ORIENTATION_VERTICAL]);
|
|
16
|
+
const NAVIGABLE_SYMBOL = Symbol("oui-navigable");
|
|
17
|
+
//#endregion
|
|
18
|
+
export { NAVIGABLE_KEYS_ABSOLUTE, NAVIGABLE_KEYS_ACTIVATE, NAVIGABLE_KEYS_ALL, NAVIGABLE_KEYS_HORIZONTAL, NAVIGABLE_KEYS_NEXT, NAVIGABLE_KEYS_VERTICAL, NAVIGABLE_ORIENTATIONS, NAVIGABLE_ORIENTATION_HORIZONTAL, NAVIGABLE_ORIENTATION_VERTICAL, NAVIGABLE_SYMBOL };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { _ as OptionListType } from "../../option-list.model-CCPUlPeX.mjs";
|
|
2
|
+
//#region src/js/internal/option-list/option-list.constants.d.ts
|
|
3
|
+
export declare const OPTION_LIST_KEYS_ACTIVATION: Set<string>;
|
|
4
|
+
export declare const LISTBOX_KEYS_NAVIGATION: Set<string>;
|
|
5
|
+
export declare const OPTION_LIST_KEYS_SELECTION: Set<string>;
|
|
6
|
+
export declare const OPTION_LIST_TYPES: Set<OptionListType>;
|
|
7
|
+
export declare const optionListScrollOptions: ScrollIntoViewOptions;
|
|
8
|
+
//#endregion
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/js/internal/option-list/option-list.constants.ts
|
|
2
|
+
const OPTION_LIST_KEYS_ACTIVATION = /* @__PURE__ */ new Set([
|
|
3
|
+
" ",
|
|
4
|
+
"Backspace",
|
|
5
|
+
"Delete",
|
|
6
|
+
"Enter"
|
|
7
|
+
]);
|
|
8
|
+
const LISTBOX_KEYS_NAVIGATION = /* @__PURE__ */ new Set([
|
|
9
|
+
"ArrowDown",
|
|
10
|
+
"ArrowUp",
|
|
11
|
+
"PageDown",
|
|
12
|
+
"PageUp"
|
|
13
|
+
]);
|
|
14
|
+
const OPTION_LIST_KEYS_SELECTION = /* @__PURE__ */ new Set(["ArrowRight", "End"]);
|
|
15
|
+
const OPTION_LIST_TYPES = /* @__PURE__ */ new Set(["autocomplete", "select"]);
|
|
16
|
+
const optionListScrollOptions = {
|
|
17
|
+
behavior: "auto",
|
|
18
|
+
block: "nearest",
|
|
19
|
+
inline: "nearest"
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { LISTBOX_KEYS_NAVIGATION, OPTION_LIST_KEYS_ACTIVATION, OPTION_LIST_KEYS_SELECTION, OPTION_LIST_TYPES, optionListScrollOptions };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { _ as OuiLocalizationsValues } from "../../l10n.model-D1E1u35L.mjs";
|
|
2
|
+
import { g as OptionListState } from "../../option-list.model-CCPUlPeX.mjs";
|
|
3
|
+
import { PlainObject } from "@oscarpalmer/atoms/models";
|
|
4
|
+
//#region src/js/internal/option-list/option-list.data.d.ts
|
|
5
|
+
type ApplySelectionParameters<State extends PlainObject, Localizations extends OuiLocalizationsValues> = {
|
|
6
|
+
added: boolean;
|
|
7
|
+
emit?: boolean;
|
|
8
|
+
option?: HTMLElement;
|
|
9
|
+
scroll?: boolean;
|
|
10
|
+
selected?: HTMLElement[];
|
|
11
|
+
state: OptionListState<State, Localizations>;
|
|
12
|
+
values?: string[];
|
|
13
|
+
};
|
|
14
|
+
export declare function applyOptionListSelection<State extends PlainObject, Localizations extends OuiLocalizationsValues>(parameters: ApplySelectionParameters<State, Localizations>): void;
|
|
15
|
+
export declare function filterOptionList<State extends PlainObject, Localizations extends OuiLocalizationsValues>(type: InputEvent["inputType"], state: OptionListState<State, Localizations>): void;
|
|
16
|
+
export declare function filterOptionListOption<State extends PlainObject, Localizations extends OuiLocalizationsValues>(state: OptionListState<State, Localizations>, value: unknown, textContent?: boolean): HTMLElement | undefined;
|
|
17
|
+
export declare function filterOptionListOptions<State extends PlainObject, Localizations extends OuiLocalizationsValues>(state: OptionListState<State, Localizations>): HTMLElement | undefined;
|
|
18
|
+
export declare function setOptionListValue<State extends PlainObject, Localizations extends OuiLocalizationsValues>(state: OptionListState<State, Localizations>, value: unknown, emit?: boolean): void;
|
|
19
|
+
export declare function setOptionListValues<State extends PlainObject, Localizations extends OuiLocalizationsValues>(state: OptionListState<State, Localizations>, value: unknown[], emit?: boolean): void;
|
|
20
|
+
export declare function toggleOptionListOption<State extends PlainObject, Localizations extends OuiLocalizationsValues>(state: OptionListState<State, Localizations>, option?: HTMLElement): void;
|
|
21
|
+
//#endregion
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as setOptionListValue, i as filterOptionListOptions, n as filterOptionList, o as setOptionListValues, r as filterOptionListOption, s as toggleOptionListOption, t as applyOptionListSelection } from "../../option-list.data-CgMyUwPc.mjs";
|
|
2
|
+
export { applyOptionListSelection, filterOptionList, filterOptionListOption, filterOptionListOptions, setOptionListValue, setOptionListValues, toggleOptionListOption };
|