@oscarpalmer/oui 0.17.0 → 0.18.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/dist/css/badge.css +3 -3
- package/dist/css/content.css +9 -11
- package/dist/css/form.css +36 -22
- package/dist/css/message.css +4 -0
- package/dist/css/reset.css +176 -56
- package/dist/css/tooltip.css +8 -0
- package/dist/js/attributable.full.js +48 -0
- package/dist/js/attributable.js +30 -45
- package/dist/js/floatable.full.js +413 -0
- package/dist/js/floatable.js +254 -169
- package/dist/js/focus-trap/embedded.full.js +351 -0
- package/dist/js/focus-trap/embedded.js +131 -131
- package/dist/js/focus-trap/standalone.full.js +402 -0
- package/dist/js/focus-trap/standalone.js +4 -4
- package/dist/js/index.js +4 -5
- package/dist/js/oui.full.js +1596 -0
- package/dist/js/popover.full.js +822 -0
- package/dist/js/popover.js +83 -162
- package/dist/js/splitter.full.js +605 -0
- package/dist/js/splitter.js +263 -245
- package/dist/js/tooltip.full.js +679 -0
- package/dist/js/tooltip.js +159 -150
- package/package.json +31 -59
- package/src/css/content.scss +1 -2
- package/src/css/form.scss +12 -4
- package/src/css/message.scss +3 -0
- package/src/css/mixins.scss +7 -0
- package/src/css/reset.scss +180 -54
- package/src/css/tooltip.scss +8 -0
- package/src/js/floatable.ts +380 -133
- package/src/js/focus-trap/embedded.ts +149 -64
- package/src/js/focus-trap/standalone.ts +4 -4
- package/src/js/index.ts +1 -0
- package/src/js/popover.ts +50 -120
- package/src/js/splitter.ts +250 -103
- package/src/js/tooltip.ts +155 -68
- package/types/floatable.d.ts +17 -10
- package/types/focus-trap/embedded.d.ts +18 -5
- package/types/index.d.ts +1 -0
- package/types/popover.d.ts +2 -0
- package/types/splitter.d.ts +13 -1
- package/types/tooltip.d.ts +2 -1
- package/dist/js/attributable.cjs +0 -51
- package/dist/js/floatable.cjs +0 -176
- package/dist/js/focus-trap/embedded.cjs +0 -150
- package/dist/js/focus-trap/standalone.cjs +0 -8
- package/dist/js/index.cjs +0 -6
- package/dist/js/popover.cjs +0 -166
- package/dist/js/splitter.cjs +0 -272
- package/dist/js/tooltip.cjs +0 -166
- package/types/attributable.d.cts +0 -5
- package/types/floatable.d.cts +0 -20
- package/types/focus-trap/embedded.d.cts +0 -15
- package/types/focus-trap/standalone.d.cts +0 -3
- package/types/index.d.cts +0 -14
- package/types/popover.d.cts +0 -14
- package/types/splitter.d.cts +0 -10
- package/types/tooltip.d.cts +0 -3
package/dist/js/popover.js
CHANGED
|
@@ -1,166 +1,87 @@
|
|
|
1
|
+
import { Floatable } from "./floatable.js";
|
|
2
|
+
import { createFocusTrap } from "./focus-trap/embedded.js";
|
|
1
3
|
import { isNullableOrWhitespace } from "@oscarpalmer/atoms/is";
|
|
2
|
-
import { on } from "@oscarpalmer/toretto/event";
|
|
3
|
-
import { findAncestor } from "@oscarpalmer/toretto/find";
|
|
4
4
|
import { getFocusable } from "@oscarpalmer/toretto/focusable";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return options;
|
|
75
|
-
}
|
|
76
|
-
if (this.#floatable.active) {
|
|
77
|
-
this.hidePopover();
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
this.showPopover();
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function closeAll() {
|
|
85
|
-
for (const floatable of active) {
|
|
86
|
-
deactivate(floatable, active, order);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function closeAbove(element) {
|
|
90
|
-
const index2 = order.findIndex(
|
|
91
|
-
(floatable) => floatable.anchor === element || floatable.content === element
|
|
92
|
-
);
|
|
93
|
-
if (index2 === -1 || index2 === order.length - 1) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
while (index2 < order.length - 1) {
|
|
97
|
-
const floatable = order.pop();
|
|
98
|
-
if (floatable != null) {
|
|
99
|
-
deactivate(floatable, active, order);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
focus(order[index2].content);
|
|
103
|
-
}
|
|
5
|
+
var index = 0;
|
|
6
|
+
var OuiPopoverElement = class extends HTMLElement {
|
|
7
|
+
#floatable;
|
|
8
|
+
#focusTrap;
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
const content = this.querySelector(SELECTOR_CONTENT);
|
|
12
|
+
const toggle = this.querySelector(SELECTOR_TOGGLE);
|
|
13
|
+
if (!(content instanceof HTMLElement)) throw new Error("A oui-popover must have a direct child element with the [oui-popover-content]-attribute");
|
|
14
|
+
if (!(toggle instanceof HTMLButtonElement)) throw new Error("A oui-popover must have a direct child element with the [oui-popover-toggle]-attribute and be a button");
|
|
15
|
+
content.hidden = true;
|
|
16
|
+
content.setAttribute("role", "dialog");
|
|
17
|
+
content.setAttribute("aria-modal", "true");
|
|
18
|
+
if (isNullableOrWhitespace(content.id)) content.setAttribute("id", `${ATTRIBUTE_ID_PREFIX}_${++index}`);
|
|
19
|
+
toggle.setAttribute("aria-controls", content.id);
|
|
20
|
+
toggle.setAttribute("aria-haspopup", "dialog");
|
|
21
|
+
this.#floatable = new Floatable({
|
|
22
|
+
content,
|
|
23
|
+
anchor: toggle,
|
|
24
|
+
defaultPosition: "below-start",
|
|
25
|
+
interactive: true,
|
|
26
|
+
positionAttribute: "position",
|
|
27
|
+
preferAbove: false,
|
|
28
|
+
onAfter: (active) => {
|
|
29
|
+
if (active) focus(content);
|
|
30
|
+
else if (!this.#floatable.ignoreFocus) toggle.focus();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
this.#focusTrap = createFocusTrap(content, { noescape: true });
|
|
34
|
+
POPOVERS.set(toggle, this.#floatable);
|
|
35
|
+
POPOVERS.set(content, this.#floatable);
|
|
36
|
+
}
|
|
37
|
+
close() {
|
|
38
|
+
this.hidePopover();
|
|
39
|
+
}
|
|
40
|
+
connectedCallback() {
|
|
41
|
+
this.#floatable.enable();
|
|
42
|
+
this.#focusTrap.connect();
|
|
43
|
+
}
|
|
44
|
+
disconnectedCallback() {
|
|
45
|
+
this.#floatable.disable();
|
|
46
|
+
this.#focusTrap.disconnect();
|
|
47
|
+
}
|
|
48
|
+
hidePopover() {
|
|
49
|
+
if (this.#floatable.active && this.isConnected) this.#floatable.toggle(false);
|
|
50
|
+
}
|
|
51
|
+
open() {
|
|
52
|
+
this.showPopover();
|
|
53
|
+
}
|
|
54
|
+
showPopover() {
|
|
55
|
+
if (!this.#floatable.active && this.isConnected) this.#floatable.toggle(true);
|
|
56
|
+
}
|
|
57
|
+
toggle() {
|
|
58
|
+
this.togglePopover();
|
|
59
|
+
}
|
|
60
|
+
togglePopover(options) {
|
|
61
|
+
if (typeof options === "boolean") {
|
|
62
|
+
if (options === true) this.showPopover();
|
|
63
|
+
else this.hidePopover();
|
|
64
|
+
return options;
|
|
65
|
+
}
|
|
66
|
+
if (this.#floatable.active) {
|
|
67
|
+
this.hidePopover();
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
this.showPopover();
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
104
74
|
function focus(content) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
target.focus();
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
function onClick(event) {
|
|
114
|
-
const related = findAncestor(
|
|
115
|
-
event.target,
|
|
116
|
-
"[oui-popover-toggle], [oui-popover-content]"
|
|
117
|
-
);
|
|
118
|
-
if (!(related instanceof HTMLElement)) {
|
|
119
|
-
closeAll();
|
|
120
|
-
} else if (related.hasAttribute("oui-popover-content")) {
|
|
121
|
-
closeAbove(related);
|
|
122
|
-
} else {
|
|
123
|
-
toggle(related);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
function onKeydown(event) {
|
|
127
|
-
if (event.key !== "Escape" || order.length === 0) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
const related = findAncestor(event.target, "[oui-popover-content]");
|
|
131
|
-
if (!(related instanceof HTMLElement)) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
closeAbove(related);
|
|
135
|
-
const floatable = mapped.get(related);
|
|
136
|
-
if (floatable != null) {
|
|
137
|
-
deactivate(floatable, active, order);
|
|
138
|
-
floatable.anchor.focus();
|
|
139
|
-
}
|
|
75
|
+
let target = getFocusable(content)[0];
|
|
76
|
+
if (!(target instanceof HTMLElement)) target = content;
|
|
77
|
+
requestAnimationFrame(() => {
|
|
78
|
+
target.focus();
|
|
79
|
+
});
|
|
140
80
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const floatable = mapped.get(anchor);
|
|
149
|
-
if (floatable == null) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
if (floatable.active) {
|
|
153
|
-
deactivate(floatable, active, order);
|
|
154
|
-
} else {
|
|
155
|
-
activate(floatable, active, order);
|
|
156
|
-
focus(floatable.content);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
customElements.define("oui-popover", OuiPopoverElement);
|
|
160
|
-
on(document, "click", onClick);
|
|
161
|
-
on(document, "keydown", onKeydown);
|
|
162
|
-
const active = /* @__PURE__ */ new Set();
|
|
163
|
-
const order = [];
|
|
164
|
-
export {
|
|
165
|
-
OuiPopoverElement
|
|
166
|
-
};
|
|
81
|
+
var ATTRIBUTE_ID_PREFIX = "oui_popover_content_";
|
|
82
|
+
var POPOVERS = /* @__PURE__ */ new Map();
|
|
83
|
+
var SELECTOR = "oui-popover";
|
|
84
|
+
var SELECTOR_CONTENT = `:scope > [${SELECTOR}-content]`;
|
|
85
|
+
var SELECTOR_TOGGLE = `:scope > [${SELECTOR}-toggle]`;
|
|
86
|
+
customElements.define(SELECTOR, OuiPopoverElement);
|
|
87
|
+
export { OuiPopoverElement };
|