@oscarpalmer/oui 0.39.0 → 0.40.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/js/color-picker/color-picker.constants.d.mts +2 -0
- package/dist/js/color-picker/{constants.color-picker.mjs → color-picker.constants.mjs} +5 -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} +3 -3
- package/dist/js/color-picker/{event.color-picker.d.mts → color-picker.event.d.mts} +2 -2
- package/dist/js/color-picker/{event.color-picker.mjs → color-picker.event.mjs} +1 -1
- 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 -6
- package/dist/js/color-picker/color-picker.misc.d.mts +2 -0
- package/dist/js/color-picker/{misc.color-picker.mjs → color-picker.misc.mjs} +1 -1
- 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} +13 -11
- package/dist/js/color-picker/color-picker.state.d.mts +8 -0
- package/dist/js/color-picker/color-picker.state.mjs +2 -0
- package/dist/js/color-picker/index.d.mts +180 -2
- package/dist/js/color-picker/index.mjs +59 -57
- package/dist/js/color-picker.constants-D1mxw_Le.d.mts +179 -0
- package/dist/js/{event.color-picker-BEpq0Adu.mjs → color-picker.event-Cksj5TvS.mjs} +105 -90
- package/dist/js/color-picker.misc-CtsXGrOe.d.mts +27 -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/{dom.combobox.d.mts → combobox.dom.d.mts} +3 -3
- package/dist/js/combobox/{dom.combobox.mjs → combobox.dom.mjs} +40 -36
- package/dist/js/combobox/{event.combobox.d.mts → combobox.event.d.mts} +3 -3
- 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/{misc.combobox.mjs → combobox.misc.mjs} +1 -1
- package/dist/js/combobox/combobox.model.d.mts +2 -0
- package/dist/js/combobox/combobox.state.d.mts +10 -0
- package/dist/js/combobox/combobox.state.mjs +2 -0
- package/dist/js/combobox/index.d.mts +163 -2
- package/dist/js/combobox/index.mjs +53 -52
- package/dist/js/combobox.constants-DZVkMP5g.d.mts +19 -0
- package/dist/js/combobox.misc-C1tPZZDi.d.mts +22 -0
- package/dist/js/combobox.model-oDV06XCN.d.mts +44 -0
- package/dist/js/{state.combobox-BWDFHwoi.mjs → combobox.state-BfJ3Hxg8.mjs} +94 -80
- package/dist/js/constants.listbox-C5Ap6Ag_.d.mts +9 -0
- 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-DX2mndMh.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-MeTyXjFn.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 +113 -135
- 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-DIU05m1z.d.mts +13 -0
- package/dist/js/{focus-trap.embedded-CjyFQYow.d.mts → focus-trap.model-BeX6UYlw.d.mts} +16 -18
- package/dist/js/index.d.mts +26 -14
- package/dist/js/index.mjs +18 -17
- 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.mjs → draggable/index.mjs} +82 -113
- package/dist/js/internal/listbox/listbox.constants.d.mts +1 -1
- package/dist/js/internal/listbox/listbox.data.d.mts +1 -1
- package/dist/js/internal/listbox/listbox.data.mjs +1 -1
- package/dist/js/internal/listbox/listbox.dom.d.mts +1 -1
- package/dist/js/internal/listbox/listbox.dom.mjs +1 -1
- package/dist/js/internal/listbox/listbox.event.d.mts +1 -1
- package/dist/js/internal/listbox/listbox.event.mjs +20 -17
- package/dist/js/internal/listbox/listbox.form.d.mts +1 -1
- package/dist/js/internal/listbox/listbox.form.mjs +15 -12
- package/dist/js/internal/listbox/listbox.misc.d.mts +1 -1
- package/dist/js/internal/listbox/listbox.misc.mjs +1 -1
- package/dist/js/internal/listbox/listbox.model.d.mts +2 -2
- package/dist/js/internal/listbox/listbox.state.d.mts +4 -4
- package/dist/js/internal/listbox/listbox.state.mjs +19 -20
- package/dist/js/internal/misc.d.mts +1 -0
- 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/l10n/index.d.mts +9 -0
- package/dist/js/{l10n.mjs → l10n/index.mjs} +50 -23
- package/dist/js/l10n/l10n.model.d.mts +2 -0
- package/dist/js/l10n/l10n.model.mjs +9 -0
- package/dist/js/l10n.model-D6a9frgl.d.mts +26 -0
- package/dist/js/listbox/constants.listbox.d.mts +2 -2
- package/dist/js/listbox/constants.listbox.mjs +10 -14
- package/dist/js/listbox/event.listbox.d.mts +1 -1
- package/dist/js/listbox/event.listbox.mjs +47 -1
- package/dist/js/listbox/index.d.mts +6 -4
- package/dist/js/listbox/index.mjs +47 -49
- package/dist/js/listbox/misc.listbox.d.mts +1 -1
- package/dist/js/listbox/misc.listbox.mjs +1 -1
- package/dist/js/listbox/state.listbox.d.mts +4 -5
- package/dist/js/listbox/state.listbox.mjs +2 -2
- package/dist/js/{listbox.data-DQ7-x2uY.mjs → listbox.data-BQyZGKgr.mjs} +87 -70
- package/dist/js/{listbox.model-BHPA7GM4.d.mts → listbox.model-CuBOj4qe.d.mts} +12 -8
- package/dist/js/menu/index.mjs +167 -0
- package/dist/js/menu/menu.model.d.mts +33 -0
- package/dist/js/menu/menu.model.mjs +15 -0
- package/dist/js/{misc.listbox-DKB-j0UK.mjs → misc.listbox-CjfBUbHD.mjs} +25 -67
- package/dist/js/{misc.listbox-mZMuYOxg.d.mts → misc.listbox-CtoGvXQo.d.mts} +2 -2
- package/dist/js/movable/movable.embedded.d.mts +2 -2
- package/dist/js/movable/movable.embedded.mjs +60 -72
- 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-DoyXLegc.d.mts +11 -0
- package/dist/js/{draggable-B5-70SZm.d.mts → movable.model-BHaK_mKw.d.mts} +81 -50
- package/dist/js/navigable.model-BPOM8DZk.d.mts +44 -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-ubKNG612.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-Bf1qBUdt.d.mts +11 -0
- package/dist/js/resizable.model-BwzJcTVJ.d.mts +46 -0
- package/dist/js/sortable/sortable.embedded.d.mts +2 -2
- package/dist/js/sortable/sortable.embedded.mjs +69 -82
- 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-DzBKAwSG.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-DOLNjLVS.d.mts +57 -0
- package/dist/js/{tabs.d.mts → tabs/index.d.mts} +7 -7
- 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-DRBX_JtI.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-DRkY_BsL.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/misc.color-picker.d.mts +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/misc.combobox.d.mts +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/index-C5D3-oiI.d.mts +0 -177
- package/dist/js/internal/draggable.d.mts +0 -2
- 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/menu.mjs +0 -172
- 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/{menu.d.mts → menu/index.d.mts} +0 -0
- /package/dist/js/{toolbar.d.mts → toolbar/index.d.mts} +0 -0
|
@@ -1,70 +1,24 @@
|
|
|
1
|
+
import { FLOATABLE_AREAS, FLOATABLE_ATTRIBUTE, FLOATABLE_ATTRIBUTE_POSITION, FLOATABLE_MESSAGE, FLOATABLE_POSITIONS, FLOATABLE_SYMBOL, floatables } from "./floatable.model.mjs";
|
|
1
2
|
import { getAria } from "@oscarpalmer/toretto/aria";
|
|
3
|
+
import { getAttribute, setAttribute } from "@oscarpalmer/toretto/attribute";
|
|
2
4
|
import { on } from "@oscarpalmer/toretto/event";
|
|
3
5
|
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
4
|
-
import { getAttribute, setAttribute } from "@oscarpalmer/toretto/attribute";
|
|
5
6
|
import { isHTMLOrSVGElement } from "@oscarpalmer/toretto/is";
|
|
6
7
|
import { setStyle, setStyles } from "@oscarpalmer/toretto/style";
|
|
7
8
|
//#region src/js/floatable/floatable.embedded.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (value === true) this.show();
|
|
22
|
-
else if (value === false) this.hide();
|
|
23
|
-
}
|
|
24
|
-
constructor(state, standalone) {
|
|
25
|
-
this.#state = state;
|
|
26
|
-
this.#initialize(state, standalone);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Destroy the floatable, removing it from the DOM and cleaning up references
|
|
30
|
-
*/
|
|
31
|
-
destroy() {
|
|
32
|
-
if (this.#destroyed) return;
|
|
33
|
-
this.#destroyed = true;
|
|
34
|
-
removeFloatable(this.#state.content);
|
|
35
|
-
this.#state.anchor = null;
|
|
36
|
-
this.#state.content = null;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Closes the floatable
|
|
40
|
-
*/
|
|
41
|
-
hide() {
|
|
42
|
-
if (!this.#destroyed && this.open) this.#state.content.hidePopover();
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Opens the floatable
|
|
46
|
-
*/
|
|
47
|
-
show() {
|
|
48
|
-
if (!this.#destroyed && !this.open) this.#state.content.showPopover();
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Update the position of the floatable, with an optional new position
|
|
52
|
-
*
|
|
53
|
-
* @param position Optional new position
|
|
54
|
-
*/
|
|
55
|
-
update(position) {
|
|
56
|
-
if (!this.#destroyed) setPosition(this.#state, position);
|
|
57
|
-
}
|
|
58
|
-
#initialize(state, standalone) {
|
|
59
|
-
const { anchor, content } = state;
|
|
60
|
-
if (standalone) {
|
|
61
|
-
setAttribute(content, ATTRIBUTE_FLOATABLE, "");
|
|
62
|
-
content.popover = "manual";
|
|
63
|
-
} else content.popover ??= "auto";
|
|
64
|
-
setStyle(anchor, "anchorName", state.name);
|
|
65
|
-
setStyle(content, "positionAnchor", state.name);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
9
|
+
function OuiFloatable(state, standalone) {
|
|
10
|
+
this[FLOATABLE_SYMBOL] = state;
|
|
11
|
+
initialize(state, standalone);
|
|
12
|
+
}
|
|
13
|
+
OuiFloatable.prototype.destroy = destroyFloatable;
|
|
14
|
+
OuiFloatable.prototype.hide = hideFloatable;
|
|
15
|
+
OuiFloatable.prototype.show = showFloatable;
|
|
16
|
+
OuiFloatable.prototype.update = updateFloatable;
|
|
17
|
+
Object.defineProperties(OuiFloatable.prototype, { open: {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: getOpen,
|
|
20
|
+
set: setOpen
|
|
21
|
+
} });
|
|
68
22
|
function getAnchorName(anchor) {
|
|
69
23
|
let { anchorName } = anchor.style;
|
|
70
24
|
if (anchorName.length > 0) return anchorName;
|
|
@@ -93,74 +47,92 @@ function createFloatable(anchor, content, options) {
|
|
|
93
47
|
return floatable;
|
|
94
48
|
}
|
|
95
49
|
function createInstance(anchor, content, options, standalone) {
|
|
96
|
-
if (!isHTMLOrSVGElement(anchor) || !isHTMLOrSVGElement(content)) throw new TypeError(
|
|
97
|
-
let floatable = options.reusable ? void 0 :
|
|
50
|
+
if (!isHTMLOrSVGElement(anchor) || !isHTMLOrSVGElement(content)) throw new TypeError(FLOATABLE_MESSAGE);
|
|
51
|
+
let floatable = options.reusable ? void 0 : floatables.get(content);
|
|
98
52
|
if (floatable == null) {
|
|
99
53
|
floatable = new OuiFloatable(getState(anchor, content, options), standalone);
|
|
100
|
-
if (!options.reusable)
|
|
54
|
+
if (!options.reusable) floatables.set(content, floatable);
|
|
101
55
|
}
|
|
102
56
|
return floatable;
|
|
103
57
|
}
|
|
58
|
+
function destroyFloatable() {
|
|
59
|
+
const state = this[FLOATABLE_SYMBOL];
|
|
60
|
+
if (state.destroyed) return;
|
|
61
|
+
state.destroyed = true;
|
|
62
|
+
removeFloatable(state.content);
|
|
63
|
+
state.anchor = null;
|
|
64
|
+
state.content = null;
|
|
65
|
+
}
|
|
104
66
|
function getOnBeforeToggleListener(element) {
|
|
105
67
|
return on(element, "beforetoggle", (event) => {
|
|
106
68
|
const { newState, source } = event;
|
|
107
69
|
if (newState === "open" && source != null && getAria(source, "disabled") === true) event.preventDefault();
|
|
108
70
|
}, { passive: false });
|
|
109
71
|
}
|
|
72
|
+
function getOpen() {
|
|
73
|
+
return this[FLOATABLE_SYMBOL].content.checkVisibility();
|
|
74
|
+
}
|
|
110
75
|
function getOptions(input) {
|
|
111
76
|
const object = isPlainObject(input) ? input : {};
|
|
112
77
|
return {
|
|
113
78
|
open: typeof object.open === "boolean" ? object.open : true,
|
|
114
|
-
position: object.position != null && object.position in
|
|
79
|
+
position: object.position != null && object.position in FLOATABLE_AREAS ? object.position : "below"
|
|
115
80
|
};
|
|
116
81
|
}
|
|
117
82
|
function getPosition(state, override) {
|
|
118
|
-
if (override != null && override in
|
|
83
|
+
if (override != null && override in FLOATABLE_AREAS) return override;
|
|
119
84
|
const { anchor, options } = state;
|
|
120
85
|
if (options.attribute == null) return options.position;
|
|
121
86
|
const attribute = getAttribute(anchor, options.attribute);
|
|
122
|
-
return attribute != null && attribute in
|
|
87
|
+
return attribute != null && attribute in FLOATABLE_AREAS ? attribute : options.position;
|
|
123
88
|
}
|
|
124
89
|
function getState(anchor, content, options) {
|
|
125
90
|
return {
|
|
126
91
|
anchor,
|
|
127
92
|
content,
|
|
128
93
|
name: getAnchorName(anchor),
|
|
129
|
-
options
|
|
94
|
+
options,
|
|
95
|
+
destroyed: false
|
|
130
96
|
};
|
|
131
97
|
}
|
|
98
|
+
function hideFloatable() {
|
|
99
|
+
const { content, destroyed } = this[FLOATABLE_SYMBOL];
|
|
100
|
+
if (!destroyed && this.open) content.hidePopover();
|
|
101
|
+
}
|
|
102
|
+
function initialize(state, standalone) {
|
|
103
|
+
const { anchor, content } = state;
|
|
104
|
+
if (standalone) {
|
|
105
|
+
setAttribute(content, FLOATABLE_ATTRIBUTE, "");
|
|
106
|
+
content.popover = "manual";
|
|
107
|
+
} else content.popover ??= "auto";
|
|
108
|
+
setStyle(anchor, "anchorName", state.name);
|
|
109
|
+
setStyle(content, "positionAnchor", state.name);
|
|
110
|
+
}
|
|
132
111
|
function removeFloatable(content) {
|
|
133
|
-
|
|
134
|
-
|
|
112
|
+
floatables.get(content)?.destroy();
|
|
113
|
+
floatables.delete(content);
|
|
114
|
+
}
|
|
115
|
+
function setOpen(value) {
|
|
116
|
+
if (value === true) this.show();
|
|
117
|
+
else if (value === false) this.hide();
|
|
135
118
|
}
|
|
136
119
|
function setPosition(state, override) {
|
|
137
120
|
const position = getPosition(state, override);
|
|
138
|
-
const area =
|
|
139
|
-
setAttribute(state.content,
|
|
121
|
+
const area = FLOATABLE_AREAS[position];
|
|
122
|
+
setAttribute(state.content, FLOATABLE_ATTRIBUTE_POSITION, FLOATABLE_POSITIONS[area]);
|
|
140
123
|
setStyles(state.content, {
|
|
141
124
|
positionAnchor: state.name,
|
|
142
125
|
positionArea: area
|
|
143
126
|
});
|
|
144
127
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
"end-bottom": "span-start end",
|
|
154
|
-
"end-top": "span-end end",
|
|
155
|
-
start: "center start",
|
|
156
|
-
"start-bottom": "span-start start",
|
|
157
|
-
"start-top": "span-end start"
|
|
158
|
-
};
|
|
159
|
-
const ATTRIBUTE_FLOATABLE = "oui-floatable";
|
|
160
|
-
const ATTRIBUTE_POSITION = "oui-position";
|
|
161
|
-
const MESSAGE = "Anchor and content must be an HTMLElement or SVGElement";
|
|
162
|
-
const POSITIONS = Object.fromEntries(Object.entries(AREAS).map(([position, area]) => [area, position]));
|
|
163
|
-
const instances = /* @__PURE__ */ new WeakMap();
|
|
128
|
+
function showFloatable() {
|
|
129
|
+
const { content, destroyed } = this[FLOATABLE_SYMBOL];
|
|
130
|
+
if (!destroyed && !this.open) content.showPopover();
|
|
131
|
+
}
|
|
132
|
+
function updateFloatable(position) {
|
|
133
|
+
const state = this[FLOATABLE_SYMBOL];
|
|
134
|
+
if (!state.destroyed) setPosition(state, position);
|
|
135
|
+
}
|
|
164
136
|
let index = 0;
|
|
165
137
|
//#endregion
|
|
166
|
-
export {
|
|
138
|
+
export { createEmbeddedFloatable, createFloatable, getOnBeforeToggleListener, removeFloatable };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as FLOATABLE_MESSAGE, c as OuiFloatable, d as OuiFloatableState, f as floatables, i as FLOATABLE_ATTRIBUTE_POSITION, l as OuiFloatableOptions, n as FLOATABLE_AREAS, o as FLOATABLE_POSITIONS, r as FLOATABLE_ATTRIBUTE, s as FLOATABLE_SYMBOL, t as CreateOuiFloatableOptions, u as OuiFloatablePosition } from "../floatable.model-DXsQgoU7.mjs";
|
|
2
|
+
export { CreateOuiFloatableOptions, FLOATABLE_AREAS, FLOATABLE_ATTRIBUTE, FLOATABLE_ATTRIBUTE_POSITION, FLOATABLE_MESSAGE, FLOATABLE_POSITIONS, FLOATABLE_SYMBOL, OuiFloatable, OuiFloatableOptions, OuiFloatablePosition, OuiFloatableState, floatables };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/js/floatable/floatable.model.ts
|
|
2
|
+
const FLOATABLE_AREAS = {
|
|
3
|
+
above: "block-start",
|
|
4
|
+
"above-end": "start span-start",
|
|
5
|
+
"above-start": "start span-end",
|
|
6
|
+
below: "block-end",
|
|
7
|
+
"below-end": "end span-start",
|
|
8
|
+
"below-start": "end span-end",
|
|
9
|
+
end: "center end",
|
|
10
|
+
"end-bottom": "span-start end",
|
|
11
|
+
"end-top": "span-end end",
|
|
12
|
+
start: "center start",
|
|
13
|
+
"start-bottom": "span-start start",
|
|
14
|
+
"start-top": "span-end start"
|
|
15
|
+
};
|
|
16
|
+
const FLOATABLE_ATTRIBUTE = "oui-floatable";
|
|
17
|
+
const FLOATABLE_ATTRIBUTE_POSITION = "oui-position";
|
|
18
|
+
const FLOATABLE_MESSAGE = "Anchor and content must be an HTMLElement or SVGElement";
|
|
19
|
+
const FLOATABLE_POSITIONS = Object.fromEntries(Object.entries(FLOATABLE_AREAS).map(([position, area]) => [area, position]));
|
|
20
|
+
const FLOATABLE_SYMBOL = Symbol(FLOATABLE_ATTRIBUTE);
|
|
21
|
+
const floatables = /* @__PURE__ */ new WeakMap();
|
|
22
|
+
//#endregion
|
|
23
|
+
export { FLOATABLE_AREAS, FLOATABLE_ATTRIBUTE, FLOATABLE_ATTRIBUTE_POSITION, FLOATABLE_MESSAGE, FLOATABLE_POSITIONS, FLOATABLE_SYMBOL, floatables };
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as OuiFloatable, t as CreateOuiFloatableOptions, u as OuiFloatablePosition } from "../floatable.model-DXsQgoU7.mjs";
|
|
2
|
+
import { n as createFloatable } from "../floatable.embedded-MeTyXjFn.mjs";
|
|
2
3
|
export { type CreateOuiFloatableOptions, type OuiFloatable, type OuiFloatablePosition, createFloatable };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { c as OuiFloatable, l as OuiFloatableOptions, t as CreateOuiFloatableOptions } from "./floatable.model-DXsQgoU7.mjs";
|
|
2
|
+
import { RemovableEventListener } from "@oscarpalmer/toretto/models";
|
|
3
|
+
//#region src/js/floatable/floatable.embedded.d.ts
|
|
4
|
+
declare function createEmbeddedFloatable(anchor: HTMLElement, content: HTMLElement, options: OuiFloatableOptions): OuiFloatable;
|
|
5
|
+
/**
|
|
6
|
+
* Create a _OuiFloatable_ for an anchor and content element
|
|
7
|
+
*
|
|
8
|
+
* @param anchor Anchor element
|
|
9
|
+
* @param content Content element
|
|
10
|
+
* @param options _OuiFloatable_ options
|
|
11
|
+
* @returns _OuiFloatable_ instance
|
|
12
|
+
*/
|
|
13
|
+
declare function createFloatable(anchor: HTMLElement, content: HTMLElement, options?: CreateOuiFloatableOptions): OuiFloatable;
|
|
14
|
+
declare function getOnBeforeToggleListener(element: HTMLElement): RemovableEventListener;
|
|
15
|
+
declare function removeFloatable(content: HTMLElement): void;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { removeFloatable as i, createFloatable as n, getOnBeforeToggleListener as r, createEmbeddedFloatable as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/js/floatable/floatable.embedded.d.ts
|
|
1
|
+
//#region src/js/floatable/floatable.model.d.ts
|
|
3
2
|
type CreateOuiFloatableOptions = {
|
|
4
3
|
/**
|
|
5
4
|
* Open the floatable when created? _(defaults to `true`)_
|
|
@@ -10,8 +9,8 @@ type CreateOuiFloatableOptions = {
|
|
|
10
9
|
*/
|
|
11
10
|
position?: OuiFloatablePosition;
|
|
12
11
|
};
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
type OuiFloatable = {
|
|
13
|
+
[FLOATABLE_SYMBOL]: OuiFloatableState;
|
|
15
14
|
/**
|
|
16
15
|
* Is the floatable open?
|
|
17
16
|
*/
|
|
@@ -20,7 +19,6 @@ declare class OuiFloatable {
|
|
|
20
19
|
* Open or close the floatable
|
|
21
20
|
*/
|
|
22
21
|
set open(value: boolean);
|
|
23
|
-
constructor(state: OuiFloatableState, standalone: boolean);
|
|
24
22
|
/**
|
|
25
23
|
* Destroy the floatable, removing it from the DOM and cleaning up references
|
|
26
24
|
*/
|
|
@@ -39,7 +37,7 @@ declare class OuiFloatable {
|
|
|
39
37
|
* @param position Optional new position
|
|
40
38
|
*/
|
|
41
39
|
update(position?: OuiFloatablePosition): void;
|
|
42
|
-
}
|
|
40
|
+
};
|
|
43
41
|
type OuiFloatableOptions = {
|
|
44
42
|
attribute?: string;
|
|
45
43
|
position: OuiFloatablePosition;
|
|
@@ -49,21 +47,16 @@ type OuiFloatablePosition = "above" | "above-end" | "above-start" | "below" | "b
|
|
|
49
47
|
type OuiFloatableState = {
|
|
50
48
|
anchor: HTMLElement;
|
|
51
49
|
content: HTMLElement;
|
|
50
|
+
destroyed: boolean;
|
|
52
51
|
name: string;
|
|
53
52
|
options: OuiFloatableOptions;
|
|
54
53
|
};
|
|
55
|
-
declare
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
* @returns _OuiFloatable_ instance
|
|
63
|
-
*/
|
|
64
|
-
declare function createFloatable(anchor: HTMLElement, content: HTMLElement, options?: CreateOuiFloatableOptions): OuiFloatable;
|
|
65
|
-
declare function getOnBeforeToggleListener(element: HTMLElement): RemovableEventListener;
|
|
66
|
-
declare function removeFloatable(content: HTMLElement): void;
|
|
67
|
-
declare const ATTRIBUTE_FLOATABLE = "oui-floatable";
|
|
54
|
+
declare const FLOATABLE_AREAS: Record<OuiFloatablePosition, string>;
|
|
55
|
+
declare const FLOATABLE_ATTRIBUTE = "oui-floatable";
|
|
56
|
+
declare const FLOATABLE_ATTRIBUTE_POSITION = "oui-position";
|
|
57
|
+
declare const FLOATABLE_MESSAGE = "Anchor and content must be an HTMLElement or SVGElement";
|
|
58
|
+
declare const FLOATABLE_POSITIONS: Record<string, OuiFloatablePosition>;
|
|
59
|
+
declare const FLOATABLE_SYMBOL: unique symbol;
|
|
60
|
+
declare const floatables: WeakMap<HTMLElement, OuiFloatable>;
|
|
68
61
|
//#endregion
|
|
69
|
-
export {
|
|
62
|
+
export { FLOATABLE_MESSAGE as a, OuiFloatable as c, OuiFloatableState as d, floatables as f, FLOATABLE_ATTRIBUTE_POSITION as i, OuiFloatableOptions as l, FLOATABLE_AREAS as n, FLOATABLE_POSITIONS as o, FLOATABLE_ATTRIBUTE as r, FLOATABLE_SYMBOL as s, CreateOuiFloatableOptions as t, OuiFloatablePosition as u };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { n as removeFocusTrap, t as createFocusTrap } from "../focus-trap.embedded-DIU05m1z.mjs";
|
|
2
|
+
export { createFocusTrap, removeFocusTrap };
|
|
@@ -1,100 +1,41 @@
|
|
|
1
1
|
import { attributable } from "../internal/attributable.mjs";
|
|
2
|
+
import { FOCUSTRAP_ATTRIBUTE, FOCUSTRAP_ATTRIBUTE_CONTAIN, FOCUSTRAP_ATTRIBUTE_NOESCAPE, FOCUSTRAP_EVENT_OPTIONS, FOCUSTRAP_MESSAGE, FOCUSTRAP_SELECTOR, FOCUSTRAP_SYMBOL, disabledFocusTraps, focusTraps } from "./focus-trap.model.mjs";
|
|
3
|
+
import { setAttribute } from "@oscarpalmer/toretto/attribute";
|
|
2
4
|
import { dispatch, on } from "@oscarpalmer/toretto/event";
|
|
5
|
+
import { findAncestor } from "@oscarpalmer/toretto/find";
|
|
3
6
|
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
4
|
-
import { setAttribute } from "@oscarpalmer/toretto/attribute";
|
|
5
7
|
import { isHTMLOrSVGElement } from "@oscarpalmer/toretto/is";
|
|
6
8
|
import { clamp } from "@oscarpalmer/atoms/number";
|
|
7
|
-
import { findAncestor } from "@oscarpalmer/toretto/find";
|
|
8
9
|
import { getFocusable } from "@oscarpalmer/toretto/focusable";
|
|
9
10
|
//#region src/js/focus-trap/focus-trap.embedded.ts
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
else if (value === false) this.enable();
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Is focus allowed to escape when pressing _Escape_ within the _focus trap_?
|
|
42
|
-
*/
|
|
43
|
-
get noescape() {
|
|
44
|
-
return this.#state.element.hasAttribute(ATTRIBUTE_FOCUSTRAP_NOESCAPE);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Should the _focus trap_ allow focus to escape when pressing _Escape_?
|
|
48
|
-
*/
|
|
49
|
-
set noescape(value) {
|
|
50
|
-
if (value === true) setAttribute(this.#state.element, ATTRIBUTE_FOCUSTRAP_NOESCAPE, "");
|
|
51
|
-
else if (value === false) setAttribute(this.#state.element, ATTRIBUTE_FOCUSTRAP_NOESCAPE, void 0);
|
|
52
|
-
}
|
|
53
|
-
constructor(state) {
|
|
54
|
-
this.#state = state;
|
|
55
|
-
this.#tabIndex = state.element.tabIndex;
|
|
56
|
-
state.element.tabIndex = -1;
|
|
57
|
-
setAttribute(state.element, ATTRIBUTE_FOCUSTRAP, "");
|
|
58
|
-
this.contain = state.options.contain;
|
|
59
|
-
this.noescape = state.options.noescape;
|
|
60
|
-
states.set(this, state);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Destroys the _focus trap_
|
|
64
|
-
*/
|
|
65
|
-
destroy() {
|
|
66
|
-
if (this.#destroyed) return;
|
|
67
|
-
this.#destroyed = true;
|
|
68
|
-
disabled.delete(this);
|
|
69
|
-
instances.delete(this.#state.element);
|
|
70
|
-
states.delete(this);
|
|
71
|
-
this.#state.element.tabIndex = this.#tabIndex;
|
|
72
|
-
this.#state.element.removeAttribute(ATTRIBUTE_FOCUSTRAP);
|
|
73
|
-
this.#state.element.removeAttribute(ATTRIBUTE_FOCUSTRAP_CONTAIN);
|
|
74
|
-
this.#state.element.removeAttribute(ATTRIBUTE_FOCUSTRAP_NOESCAPE);
|
|
75
|
-
this.#state.element = void 0;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Disables the _focus trap_
|
|
79
|
-
*/
|
|
80
|
-
disable() {
|
|
81
|
-
if (!this.#destroyed && !(this.disabled || this.#state.options.noescape)) setDisabled(this, this.#state, true);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Enables the _focus trap_
|
|
85
|
-
*/
|
|
86
|
-
enable() {
|
|
87
|
-
if (!this.#destroyed && this.disabled) setDisabled(this, this.#state, false);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Focuses the _focus trap_
|
|
91
|
-
*
|
|
92
|
-
* @param last When `true`, focuses the last focusable element within the _focus trap_ instead of the first
|
|
93
|
-
*/
|
|
94
|
-
focus(last) {
|
|
95
|
-
if (!this.#destroyed && !this.disabled) tabToTrap(this, getFocusable(this.#state.element), this.#state.element, last ? -1 : 0);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
11
|
+
function OuiFocusTrap(state) {
|
|
12
|
+
this[FOCUSTRAP_SYMBOL] = state;
|
|
13
|
+
state.element.tabIndex = -1;
|
|
14
|
+
setAttribute(state.element, FOCUSTRAP_ATTRIBUTE, "");
|
|
15
|
+
this.contain = state.options.contain;
|
|
16
|
+
this.noescape = state.options.noescape;
|
|
17
|
+
}
|
|
18
|
+
OuiFocusTrap.prototype.destroy = destroyFocusTrap;
|
|
19
|
+
OuiFocusTrap.prototype.disable = disableFocusTrap;
|
|
20
|
+
OuiFocusTrap.prototype.enable = enableFocusTrap;
|
|
21
|
+
OuiFocusTrap.prototype.focus = focusFocusTrap;
|
|
22
|
+
Object.defineProperties(OuiFocusTrap.prototype, {
|
|
23
|
+
contain: {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: getContain,
|
|
26
|
+
set: setContain
|
|
27
|
+
},
|
|
28
|
+
disabled: {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: getDisabled,
|
|
31
|
+
set: setDisabled
|
|
32
|
+
},
|
|
33
|
+
noescape: {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: getNoEscape,
|
|
36
|
+
set: setNoEscape
|
|
37
|
+
}
|
|
38
|
+
});
|
|
98
39
|
/**
|
|
99
40
|
* Creates _(or retrieves)_ a _focus trap_ for an element
|
|
100
41
|
*
|
|
@@ -103,44 +44,79 @@ var OuiFocusTrap = class {
|
|
|
103
44
|
* @returns _Focus trap_ instance
|
|
104
45
|
*/
|
|
105
46
|
function createFocusTrap(element, options) {
|
|
106
|
-
if (!isHTMLOrSVGElement(element)) throw new TypeError(
|
|
107
|
-
let instance =
|
|
47
|
+
if (!isHTMLOrSVGElement(element)) throw new TypeError(FOCUSTRAP_MESSAGE);
|
|
48
|
+
let instance = focusTraps.get(element);
|
|
108
49
|
if (instance == null) {
|
|
109
50
|
instance = new OuiFocusTrap(getState(element, options));
|
|
110
|
-
|
|
51
|
+
focusTraps.set(element, instance);
|
|
111
52
|
}
|
|
112
53
|
return instance;
|
|
113
54
|
}
|
|
55
|
+
function destroyFocusTrap() {
|
|
56
|
+
const state = this[FOCUSTRAP_SYMBOL];
|
|
57
|
+
if (state.destroyed) return;
|
|
58
|
+
state.destroyed = true;
|
|
59
|
+
disabledFocusTraps.delete(this);
|
|
60
|
+
focusTraps.delete(state.element);
|
|
61
|
+
state.element.tabIndex = state.tabIndex;
|
|
62
|
+
state.element.removeAttribute(FOCUSTRAP_ATTRIBUTE);
|
|
63
|
+
state.element.removeAttribute(FOCUSTRAP_ATTRIBUTE_CONTAIN);
|
|
64
|
+
state.element.removeAttribute(FOCUSTRAP_ATTRIBUTE_NOESCAPE);
|
|
65
|
+
state.element = void 0;
|
|
66
|
+
}
|
|
67
|
+
function disableFocusTrap() {
|
|
68
|
+
const state = this[FOCUSTRAP_SYMBOL];
|
|
69
|
+
if (!state.destroyed && !(this.disabled || state.options.noescape)) setDisabledState(this, state, true);
|
|
70
|
+
}
|
|
71
|
+
function enableFocusTrap() {
|
|
72
|
+
const state = this[FOCUSTRAP_SYMBOL];
|
|
73
|
+
if (!state.destroyed && this.disabled) setDisabledState(this, state, false);
|
|
74
|
+
}
|
|
75
|
+
function focusFocusTrap(last) {
|
|
76
|
+
const state = this[FOCUSTRAP_SYMBOL];
|
|
77
|
+
if (!state.destroyed && !this.disabled) tabToTrap(this, getFocusable(state.element), state.element, last ? -1 : 0);
|
|
78
|
+
}
|
|
79
|
+
function getContain() {
|
|
80
|
+
return this[FOCUSTRAP_SYMBOL].element.hasAttribute(FOCUSTRAP_ATTRIBUTE_CONTAIN);
|
|
81
|
+
}
|
|
82
|
+
function getDisabled() {
|
|
83
|
+
return this[FOCUSTRAP_SYMBOL].disabled;
|
|
84
|
+
}
|
|
85
|
+
function getNoEscape() {
|
|
86
|
+
return this[FOCUSTRAP_SYMBOL].element.hasAttribute(FOCUSTRAP_ATTRIBUTE_NOESCAPE);
|
|
87
|
+
}
|
|
114
88
|
function getOptions(element, input) {
|
|
115
89
|
const options = isPlainObject(input) ? input : {};
|
|
116
90
|
return {
|
|
117
|
-
contain: typeof options.contain === "boolean" ? options.contain : element.hasAttribute(
|
|
118
|
-
noescape: typeof options.noescape === "boolean" ? options.noescape : element.hasAttribute(
|
|
91
|
+
contain: typeof options.contain === "boolean" ? options.contain : element.hasAttribute(FOCUSTRAP_ATTRIBUTE_CONTAIN),
|
|
92
|
+
noescape: typeof options.noescape === "boolean" ? options.noescape : element.hasAttribute(FOCUSTRAP_ATTRIBUTE_NOESCAPE)
|
|
119
93
|
};
|
|
120
94
|
}
|
|
121
95
|
function getState(element, options) {
|
|
122
96
|
return {
|
|
123
97
|
element,
|
|
98
|
+
destroyed: false,
|
|
124
99
|
disabled: false,
|
|
125
|
-
options: getOptions(element, options)
|
|
100
|
+
options: getOptions(element, options),
|
|
101
|
+
tabIndex: element.tabIndex
|
|
126
102
|
};
|
|
127
103
|
}
|
|
128
104
|
function onEscape(event) {
|
|
129
|
-
let element = findAncestor(event,
|
|
130
|
-
let instance =
|
|
131
|
-
let state =
|
|
105
|
+
let element = findAncestor(event, FOCUSTRAP_SELECTOR);
|
|
106
|
+
let instance = focusTraps.get(element);
|
|
107
|
+
let state = instance?.[FOCUSTRAP_SYMBOL];
|
|
132
108
|
if (element == null || instance == null || state == null) return;
|
|
133
109
|
while (state.disabled) {
|
|
134
|
-
element = findAncestor(state.element.parentElement,
|
|
135
|
-
instance =
|
|
136
|
-
state =
|
|
110
|
+
element = findAncestor(state.element.parentElement, FOCUSTRAP_SELECTOR);
|
|
111
|
+
instance = focusTraps.get(element);
|
|
112
|
+
state = instance?.[FOCUSTRAP_SYMBOL];
|
|
137
113
|
if (element == null || instance == null || state == null) return;
|
|
138
114
|
if (!state.disabled) break;
|
|
139
115
|
}
|
|
140
116
|
instance?.disable();
|
|
141
117
|
}
|
|
142
118
|
function onFocusIn(event) {
|
|
143
|
-
lastTarget =
|
|
119
|
+
lastTarget = focusTraps.get(findAncestor(event, FOCUSTRAP_SELECTOR)) == null ? void 0 : event.target;
|
|
144
120
|
}
|
|
145
121
|
function onKeydown(event) {
|
|
146
122
|
switch (event.key) {
|
|
@@ -154,23 +130,23 @@ function onKeydown(event) {
|
|
|
154
130
|
}
|
|
155
131
|
}
|
|
156
132
|
function onPointerdown(event) {
|
|
157
|
-
const last = findAncestor(lastTarget,
|
|
158
|
-
const next = findAncestor(event,
|
|
133
|
+
const last = findAncestor(lastTarget, FOCUSTRAP_SELECTOR);
|
|
134
|
+
const next = findAncestor(event, FOCUSTRAP_SELECTOR);
|
|
159
135
|
if (last != null && next !== last) {
|
|
160
|
-
if (
|
|
136
|
+
if (focusTraps.get(last)?.[FOCUSTRAP_SYMBOL]?.options.contain ?? false) {
|
|
161
137
|
event.preventDefault();
|
|
162
138
|
lastTarget?.focus();
|
|
163
139
|
}
|
|
164
140
|
}
|
|
165
|
-
if (
|
|
166
|
-
for (const focusTrap of
|
|
167
|
-
const state =
|
|
141
|
+
if (disabledFocusTraps.size === 0) return;
|
|
142
|
+
for (const focusTrap of disabledFocusTraps) {
|
|
143
|
+
const state = focusTrap?.[FOCUSTRAP_SYMBOL];
|
|
168
144
|
if (state != null && state.element !== next) focusTrap.enable();
|
|
169
145
|
}
|
|
170
146
|
}
|
|
171
147
|
function onTab(event) {
|
|
172
|
-
const element = findAncestor(event,
|
|
173
|
-
const instance =
|
|
148
|
+
const element = findAncestor(event, FOCUSTRAP_SELECTOR);
|
|
149
|
+
const instance = focusTraps.get(element);
|
|
174
150
|
if (instance == null || dispatch(element, "oui:focus-trap").defaultPrevented) return;
|
|
175
151
|
if (!instance.disabled) event.preventDefault();
|
|
176
152
|
const elements = getFocusable(element);
|
|
@@ -179,13 +155,27 @@ function onTab(event) {
|
|
|
179
155
|
else tabToElement(instance, elements, index, event.shiftKey ? -1 : 1);
|
|
180
156
|
}
|
|
181
157
|
function removeFocusTrap(element) {
|
|
182
|
-
|
|
183
|
-
|
|
158
|
+
focusTraps.get(element)?.destroy();
|
|
159
|
+
focusTraps.delete(element);
|
|
184
160
|
}
|
|
185
|
-
function
|
|
161
|
+
function setContain(value) {
|
|
162
|
+
const { element } = this[FOCUSTRAP_SYMBOL];
|
|
163
|
+
if (value === true) setAttribute(element, FOCUSTRAP_ATTRIBUTE_CONTAIN, "");
|
|
164
|
+
else if (value === false) setAttribute(element, FOCUSTRAP_ATTRIBUTE_CONTAIN, void 0);
|
|
165
|
+
}
|
|
166
|
+
function setDisabled(value) {
|
|
167
|
+
if (value === true) this.disable();
|
|
168
|
+
else if (value === false) this.enable();
|
|
169
|
+
}
|
|
170
|
+
function setDisabledState(focusTrap, state, value) {
|
|
186
171
|
state.disabled = value;
|
|
187
|
-
if (value)
|
|
188
|
-
else
|
|
172
|
+
if (value) disabledFocusTraps.add(focusTrap);
|
|
173
|
+
else disabledFocusTraps.delete(focusTrap);
|
|
174
|
+
}
|
|
175
|
+
function setNoEscape(value) {
|
|
176
|
+
const { element } = this[FOCUSTRAP_SYMBOL];
|
|
177
|
+
if (value === true) setAttribute(element, FOCUSTRAP_ATTRIBUTE_NOESCAPE, "");
|
|
178
|
+
else if (value === false) setAttribute(element, FOCUSTRAP_ATTRIBUTE_NOESCAPE, void 0);
|
|
189
179
|
}
|
|
190
180
|
function tabToElement(instance, elements, index, modifier) {
|
|
191
181
|
const { length } = elements;
|
|
@@ -198,7 +188,7 @@ function tabToElement(instance, elements, index, modifier) {
|
|
|
198
188
|
return;
|
|
199
189
|
}
|
|
200
190
|
const element = elements[next];
|
|
201
|
-
const elementFocusTrap =
|
|
191
|
+
const elementFocusTrap = focusTraps.get(element);
|
|
202
192
|
if (elementFocusTrap != null) elementFocusTrap.focus(modifier === -1);
|
|
203
193
|
else {
|
|
204
194
|
elements[next].focus();
|
|
@@ -215,23 +205,11 @@ function tabToTrap(instance, elements, element, index) {
|
|
|
215
205
|
lastTarget = next;
|
|
216
206
|
}
|
|
217
207
|
}
|
|
218
|
-
const ATTRIBUTE_FOCUSTRAP = "oui-focus-trap";
|
|
219
|
-
const ATTRIBUTE_FOCUSTRAP_CONTAIN = `${ATTRIBUTE_FOCUSTRAP}-contain`;
|
|
220
|
-
const ATTRIBUTE_FOCUSTRAP_NOESCAPE = `${ATTRIBUTE_FOCUSTRAP}-noescape`;
|
|
221
|
-
const EVENT_OPTIONS = {
|
|
222
|
-
capture: true,
|
|
223
|
-
passive: false
|
|
224
|
-
};
|
|
225
|
-
const MESSAGE = "Element must be an HTMLElement or SVGElement";
|
|
226
|
-
const SELECTOR = `[${ATTRIBUTE_FOCUSTRAP}]`;
|
|
227
|
-
const disabled = /* @__PURE__ */ new Set();
|
|
228
|
-
const instances = /* @__PURE__ */ new WeakMap();
|
|
229
|
-
const states = /* @__PURE__ */ new WeakMap();
|
|
230
208
|
let lastTarget;
|
|
231
|
-
attributable(
|
|
232
|
-
on(document, "focusin", onFocusIn,
|
|
233
|
-
on(document, "keydown", onKeydown,
|
|
234
|
-
on(document, "mousedown", onPointerdown,
|
|
235
|
-
on(document, "touchstart", onPointerdown,
|
|
209
|
+
attributable(FOCUSTRAP_ATTRIBUTE, createFocusTrap, removeFocusTrap);
|
|
210
|
+
on(document, "focusin", onFocusIn, FOCUSTRAP_EVENT_OPTIONS);
|
|
211
|
+
on(document, "keydown", onKeydown, FOCUSTRAP_EVENT_OPTIONS);
|
|
212
|
+
on(document, "mousedown", onPointerdown, FOCUSTRAP_EVENT_OPTIONS);
|
|
213
|
+
on(document, "touchstart", onPointerdown, FOCUSTRAP_EVENT_OPTIONS);
|
|
236
214
|
//#endregion
|
|
237
|
-
export {
|
|
215
|
+
export { createFocusTrap, removeFocusTrap };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as FOCUSTRAP_MESSAGE, c as OuiFocusTrap, d as disabledFocusTraps, f as focusTraps, i as FOCUSTRAP_EVENT_OPTIONS, l as OuiFocusTrapOptions, n as FOCUSTRAP_ATTRIBUTE_CONTAIN, o as FOCUSTRAP_SELECTOR, r as FOCUSTRAP_ATTRIBUTE_NOESCAPE, s as FOCUSTRAP_SYMBOL, t as FOCUSTRAP_ATTRIBUTE, u as OuiFocusTrapState } from "../focus-trap.model-BeX6UYlw.mjs";
|
|
2
|
+
export { FOCUSTRAP_ATTRIBUTE, FOCUSTRAP_ATTRIBUTE_CONTAIN, FOCUSTRAP_ATTRIBUTE_NOESCAPE, FOCUSTRAP_EVENT_OPTIONS, FOCUSTRAP_MESSAGE, FOCUSTRAP_SELECTOR, FOCUSTRAP_SYMBOL, OuiFocusTrap, OuiFocusTrapOptions, OuiFocusTrapState, disabledFocusTraps, focusTraps };
|