@oscarpalmer/oui 0.24.0 → 0.26.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/{tooltip.css → floatable.css} +59 -24
- package/dist/css/reset.css +17 -0
- package/dist/js/dialog.d.mts +38 -0
- package/dist/js/dialog.mjs +92 -0
- package/dist/js/embedded-CHK82Uh5.d.mts +76 -0
- package/dist/js/embedded-ai6cqURc.d.mts +68 -0
- package/dist/js/floatable/embedded.d.mts +2 -0
- package/dist/js/floatable/embedded.mjs +157 -0
- package/dist/js/floatable/standalone.d.mts +2 -0
- package/dist/js/floatable/standalone.mjs +2 -0
- package/dist/js/focus-trap/embedded.d.mts +2 -26
- package/dist/js/focus-trap/embedded.mjs +158 -80
- package/dist/js/focus-trap/standalone.d.mts +2 -1
- package/dist/js/focus-trap/standalone.mjs +3 -3
- package/dist/js/index.d.mts +6 -3
- package/dist/js/index.mjs +9 -5
- package/dist/js/internal/draggable.d.mts +2 -2
- package/dist/js/internal/draggable.mjs +3 -3
- package/dist/js/{movable-BKFgoaOl.d.mts → movable-dNqBctx3.d.mts} +16 -16
- package/dist/js/movable.d.mts +2 -2
- package/dist/js/movable.mjs +4 -4
- package/dist/js/popover.d.mts +38 -1
- package/dist/js/popover.mjs +83 -44
- package/dist/js/sortable.d.mts +2 -2
- package/dist/js/sortable.mjs +5 -5
- package/dist/js/splitter.mjs +49 -48
- package/dist/js/toolbar.d.mts +1 -0
- package/dist/js/toolbar.mjs +107 -0
- package/dist/js/tooltip.d.mts +27 -1
- package/dist/js/tooltip.mjs +85 -49
- package/package.json +14 -2
- package/src/css/{tooltip.scss → floatable.scss} +47 -5
- package/src/css/mixins.scss +0 -2
- package/src/css/reset.scss +17 -0
- package/src/js/dialog.ts +188 -0
- package/src/js/floatable/embedded.ts +323 -0
- package/src/js/floatable/standalone.ts +1 -0
- package/src/js/focus-trap/embedded.ts +219 -93
- package/src/js/focus-trap/standalone.ts +4 -2
- package/src/js/index.ts +6 -4
- package/src/js/internal/draggable.ts +20 -20
- package/src/js/movable.ts +17 -17
- package/src/js/popover.ts +143 -61
- package/src/js/sortable.ts +26 -26
- package/src/js/splitter.ts +98 -96
- package/src/js/toolbar.ts +214 -0
- package/src/js/tooltip.ts +138 -54
- package/dist/css/popover.css +0 -30
- package/dist/js/floatable.d.mts +0 -59
- package/dist/js/floatable.mjs +0 -130
- package/src/css/popover.scss +0 -10
- package/src/js/floatable.ts +0 -237
|
@@ -1,4 +1,62 @@
|
|
|
1
1
|
|
|
2
|
+
:where([oui-dialog], [oui-popover], [oui-tooltip-content]),
|
|
3
|
+
:where([oui-dialog])::backdrop {
|
|
4
|
+
opacity: 0;
|
|
5
|
+
transition: 0.125s ease-in-out;
|
|
6
|
+
transition-property: opacity, scale;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
:where([oui-dialog], [oui-popover], [oui-tooltip-content]) {
|
|
10
|
+
box-shadow: inset 0 1px 0 0 transparent, 0 0 0 1px rgba(0, 0, 0, 0.05), 0 1px 2px -0.5px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.05), 0 4px 8px -2px rgba(0, 0, 0, 0.05), 0 8px 16px -4px rgba(0, 0, 0, 0.05), 0 16px 32px -8px rgba(0, 0, 0, 0.05), 0 32px 64px -16px rgba(0, 0, 0, 0.05), 0 64px 128px -32px rgba(0, 0, 0, 0.05);
|
|
11
|
+
background-color: var(--oui-absolute);
|
|
12
|
+
scale: 0.9;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
:where([oui-dialog]:focus, [oui-popover]:focus, [oui-tooltip-content]:focus) {
|
|
16
|
+
outline: none;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
:where([oui-dialog][oui-dialog-open],
|
|
20
|
+
[oui-popover][oui-popover-open],
|
|
21
|
+
[oui-tooltip-content][oui-tooltip-content-open]),
|
|
22
|
+
:where([oui-dialog][oui-dialog-open])::backdrop {
|
|
23
|
+
opacity: 1;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
:where([oui-dialog][oui-dialog-open],
|
|
27
|
+
[oui-popover][oui-popover-open],
|
|
28
|
+
[oui-tooltip-content][oui-tooltip-content-open]) {
|
|
29
|
+
scale: 1;
|
|
30
|
+
transition-delay: 0.125s;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
:where([oui-popover], [oui-tooltip-content]) {
|
|
34
|
+
--margin-bottom: 0.5em;
|
|
35
|
+
--margin-left: 0.5em;
|
|
36
|
+
--margin-right: 0.5em;
|
|
37
|
+
--margin-top: 0.5em;
|
|
38
|
+
inset-block: var(--margin-top) var(--margin-bottom);
|
|
39
|
+
inset-inline: var(--margin-left) var(--margin-right);
|
|
40
|
+
}
|
|
41
|
+
:where([oui-popover], [oui-tooltip-content])[oui-position$=bottom] {
|
|
42
|
+
--margin-bottom: 0;
|
|
43
|
+
}
|
|
44
|
+
:where([oui-popover], [oui-tooltip-content])[oui-position$=end] {
|
|
45
|
+
--margin-right: 0;
|
|
46
|
+
}
|
|
47
|
+
:where([oui-popover], [oui-tooltip-content])[oui-position$=start] {
|
|
48
|
+
--margin-left: 0;
|
|
49
|
+
}
|
|
50
|
+
:where([oui-popover], [oui-tooltip-content])[oui-position$=top] {
|
|
51
|
+
--margin-top: 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
:where([oui-popover]) {
|
|
55
|
+
padding: 1rem;
|
|
56
|
+
background-color: var(--oui-absolute);
|
|
57
|
+
border-radius: 0.25rem;
|
|
58
|
+
}
|
|
59
|
+
|
|
2
60
|
:where([oui-tooltip]:is(abbr,
|
|
3
61
|
b,
|
|
4
62
|
cite,
|
|
@@ -25,27 +83,6 @@ var)) {
|
|
|
25
83
|
cursor: help;
|
|
26
84
|
}
|
|
27
85
|
|
|
28
|
-
:where([oui-tooltip-content]) {
|
|
29
|
-
box-shadow: inset 0 1px 0 0 transparent, 0 0 0 1px rgba(0, 0, 0, 0.05), 0 1px 2px -0.5px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.05), 0 4px 8px -2px rgba(0, 0, 0, 0.05), 0 8px 16px -4px rgba(0, 0, 0, 0.05), 0 16px 32px -8px rgba(0, 0, 0, 0.05), 0 32px 64px -16px rgba(0, 0, 0, 0.05), 0 64px 128px -32px rgba(0, 0, 0, 0.05);
|
|
30
|
-
--margin-bottom: 0.5em;
|
|
31
|
-
--margin-left: 0.5em;
|
|
32
|
-
--margin-right: 0.5em;
|
|
33
|
-
--margin-top: 0.5em;
|
|
34
|
-
inset-block: var(--margin-top) var(--margin-bottom);
|
|
35
|
-
inset-inline: var(--margin-left) var(--margin-right);
|
|
36
|
-
}
|
|
37
|
-
:where([oui-tooltip-content])[oui-position$=bottom] {
|
|
38
|
-
--margin-bottom: 0;
|
|
39
|
-
}
|
|
40
|
-
:where([oui-tooltip-content])[oui-position$=end] {
|
|
41
|
-
--margin-right: 0;
|
|
42
|
-
}
|
|
43
|
-
:where([oui-tooltip-content])[oui-position$=start] {
|
|
44
|
-
--margin-left: 0;
|
|
45
|
-
}
|
|
46
|
-
:where([oui-tooltip-content])[oui-position$=top] {
|
|
47
|
-
--margin-top: 0;
|
|
48
|
-
}
|
|
49
86
|
:where([oui-tooltip-content]) {
|
|
50
87
|
max-width: 48ch;
|
|
51
88
|
padding: 0.75em 1em;
|
|
@@ -55,8 +92,6 @@ var)) {
|
|
|
55
92
|
border-radius: 0.25rem;
|
|
56
93
|
font-size: 0.875rem;
|
|
57
94
|
pointer-events: none;
|
|
58
|
-
transition: opacity 0.125s ease-in-out 0s;
|
|
59
|
-
transition-behavior: allow-discrete;
|
|
60
95
|
}
|
|
61
96
|
:where([oui-tooltip-content])::after {
|
|
62
97
|
content: "";
|
|
@@ -84,7 +119,7 @@ var)) {
|
|
|
84
119
|
inset: 0 0 0 calc(100% - 0.5em);
|
|
85
120
|
}
|
|
86
121
|
|
|
87
|
-
:where([oui-tooltip-content][oui-tooltip-content-
|
|
122
|
+
:where([oui-tooltip-content][oui-tooltip-content-open]) {
|
|
88
123
|
opacity: 1;
|
|
89
124
|
pointer-events: all;
|
|
90
125
|
}
|
package/dist/css/reset.css
CHANGED
|
@@ -124,6 +124,23 @@ summary) {
|
|
|
124
124
|
display: list-item;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
:where(dialog) {
|
|
128
|
+
display: none !important;
|
|
129
|
+
overscroll-behavior: contain;
|
|
130
|
+
border: none;
|
|
131
|
+
color: currentcolor;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
:where([oui-dialog][aria-modal=true i]) {
|
|
135
|
+
position: fixed;
|
|
136
|
+
inset: 50% auto auto 50%;
|
|
137
|
+
transform: translate3d(-50%, -50%, 0);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
:where(dialog[open]) {
|
|
141
|
+
display: inherit !important;
|
|
142
|
+
}
|
|
143
|
+
|
|
127
144
|
:where(dl, ol, ul) :where(dl, ol, ul) {
|
|
128
145
|
/** Remove the margin on nested lists in Chrome, Edge, and Safari [SE] */
|
|
129
146
|
margin: 0;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { RemovableEventListener } from "@oscarpalmer/toretto/models";
|
|
2
|
+
|
|
3
|
+
//#region src/js/dialog.d.ts
|
|
4
|
+
declare class OuiDialog {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* Is the dialog open?
|
|
8
|
+
*/
|
|
9
|
+
get open(): boolean;
|
|
10
|
+
constructor(state: OuiDialogState);
|
|
11
|
+
/**
|
|
12
|
+
* Closes the dialog by request
|
|
13
|
+
*/
|
|
14
|
+
hide(request: true, value?: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Closes the dialog
|
|
17
|
+
*/
|
|
18
|
+
hide(value?: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Opens the dialog
|
|
21
|
+
*/
|
|
22
|
+
show(modal?: boolean): void;
|
|
23
|
+
}
|
|
24
|
+
type OuiDialogState = {
|
|
25
|
+
dialog: OuiDialog;
|
|
26
|
+
element: HTMLDialogElement;
|
|
27
|
+
listeners: RemovableEventListener[];
|
|
28
|
+
modal: boolean;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Get the _OuiDialog_ for an element
|
|
32
|
+
*
|
|
33
|
+
* @param element Element to get _OuiDialog_ for
|
|
34
|
+
* @returns _OuiDialog_ instance
|
|
35
|
+
*/
|
|
36
|
+
declare function getDialog(element: HTMLDialogElement): OuiDialog | undefined;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { type OuiDialog, getDialog };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { getOnBeforeToggleListener } from "./floatable/embedded.mjs";
|
|
2
|
+
import { attributable } from "./internal/attributable.mjs";
|
|
3
|
+
import { on } from "@oscarpalmer/toretto/event";
|
|
4
|
+
//#region src/js/dialog.ts
|
|
5
|
+
var OuiDialog = class {
|
|
6
|
+
#state;
|
|
7
|
+
/**
|
|
8
|
+
* Is the dialog open?
|
|
9
|
+
*/
|
|
10
|
+
get open() {
|
|
11
|
+
return this.#state.element.open;
|
|
12
|
+
}
|
|
13
|
+
constructor(state) {
|
|
14
|
+
this.#state = state;
|
|
15
|
+
}
|
|
16
|
+
hide(first, second) {
|
|
17
|
+
if (!this.#state.element.open) return;
|
|
18
|
+
if (first === true) this.#state.element.requestClose(typeof second === "string" ? second : void 0);
|
|
19
|
+
else this.#state.element.close(typeof first === "string" ? first : void 0);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Opens the dialog
|
|
23
|
+
*/
|
|
24
|
+
show(modal) {
|
|
25
|
+
const { element } = this.#state;
|
|
26
|
+
if (element == null || element.open) return;
|
|
27
|
+
const isModal = modal !== false;
|
|
28
|
+
element.setAttribute(ARIA_MODAL, String(isModal));
|
|
29
|
+
if (isModal) element.showModal();
|
|
30
|
+
else element.show();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
function addDialog(element) {
|
|
34
|
+
if (!(element instanceof HTMLDialogElement)) throw new TypeError(MESSAGE);
|
|
35
|
+
if (!states.has(element)) states.set(element, getState(element));
|
|
36
|
+
}
|
|
37
|
+
function destroyDialog(state) {
|
|
38
|
+
state.element.close();
|
|
39
|
+
state.element.setAttribute(ARIA_MODAL, String(state.modal));
|
|
40
|
+
state.element.removeAttribute(ATTRIBUTE_OPEN);
|
|
41
|
+
for (const listener of state.listeners) listener();
|
|
42
|
+
state.dialog = void 0;
|
|
43
|
+
state.element = void 0;
|
|
44
|
+
state.listeners = void 0;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get the _OuiDialog_ for an element
|
|
48
|
+
*
|
|
49
|
+
* @param element Element to get _OuiDialog_ for
|
|
50
|
+
* @returns _OuiDialog_ instance
|
|
51
|
+
*/
|
|
52
|
+
function getDialog(element) {
|
|
53
|
+
return states.get(element)?.dialog;
|
|
54
|
+
}
|
|
55
|
+
function getState(element) {
|
|
56
|
+
const state = {
|
|
57
|
+
element,
|
|
58
|
+
dialog: void 0,
|
|
59
|
+
listeners: [getOnBeforeToggleListener(element), on(element, EVENT_TOGGLE, (event) => {
|
|
60
|
+
const { source } = event;
|
|
61
|
+
if (element.open) {
|
|
62
|
+
const modal = source instanceof HTMLButtonElement && source.command === COMMAND_SHOW_MODAL || element.matches(SELECTOR_MODAL);
|
|
63
|
+
element.setAttribute(ARIA_MODAL, String(modal));
|
|
64
|
+
element.setAttribute(ATTRIBUTE_OPEN, "");
|
|
65
|
+
} else {
|
|
66
|
+
element.removeAttribute(ATTRIBUTE_OPEN);
|
|
67
|
+
element.setAttribute(ARIA_MODAL, String(state.modal));
|
|
68
|
+
}
|
|
69
|
+
})],
|
|
70
|
+
modal: element.getAttribute(ARIA_MODAL) === TRUE
|
|
71
|
+
};
|
|
72
|
+
state.dialog = new OuiDialog(state);
|
|
73
|
+
return state;
|
|
74
|
+
}
|
|
75
|
+
function removeDialog(element) {
|
|
76
|
+
const state = states.get(element);
|
|
77
|
+
if (state == null) return;
|
|
78
|
+
destroyDialog(state);
|
|
79
|
+
states.delete(element);
|
|
80
|
+
}
|
|
81
|
+
const ARIA_MODAL = "aria-modal";
|
|
82
|
+
const ATTRIBUTE = "oui-dialog";
|
|
83
|
+
const ATTRIBUTE_OPEN = `${ATTRIBUTE}-open`;
|
|
84
|
+
const COMMAND_SHOW_MODAL = "show-modal";
|
|
85
|
+
const EVENT_TOGGLE = "toggle";
|
|
86
|
+
const MESSAGE = "The element must be an instance of HTMLDialogElement";
|
|
87
|
+
const SELECTOR_MODAL = ":modal";
|
|
88
|
+
const TRUE = "true";
|
|
89
|
+
const states = /* @__PURE__ */ new WeakMap();
|
|
90
|
+
attributable(ATTRIBUTE, addDialog, removeDialog);
|
|
91
|
+
//#endregion
|
|
92
|
+
export { getDialog };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
//#region src/js/focus-trap/embedded.d.ts
|
|
2
|
+
declare class OuiFocusTrap {
|
|
3
|
+
#private;
|
|
4
|
+
/**
|
|
5
|
+
* Is focused maintained within the _FocusTrap_ when clicking outside of it?
|
|
6
|
+
*/
|
|
7
|
+
get contain(): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Should focus be maintained within the _FocusTrap_ when clicking outside of it?
|
|
10
|
+
*/
|
|
11
|
+
set contain(value: boolean);
|
|
12
|
+
/**
|
|
13
|
+
* Is the _FocusTrap_ disabled?
|
|
14
|
+
*/
|
|
15
|
+
get disabled(): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Should the _FocusTrap_ be disabled?
|
|
18
|
+
*/
|
|
19
|
+
set disabled(value: boolean);
|
|
20
|
+
/**
|
|
21
|
+
* Is focus allowed to escape when pressing _Escape_ within the _FocusTrap_?
|
|
22
|
+
*/
|
|
23
|
+
get noescape(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Should the _FocusTrap_ allow focus to escape when pressing _Escape_?
|
|
26
|
+
*/
|
|
27
|
+
set noescape(value: boolean);
|
|
28
|
+
constructor(state: OuiFocusTrapState);
|
|
29
|
+
/**
|
|
30
|
+
* Destroys the _FocusTrap_
|
|
31
|
+
*/
|
|
32
|
+
destroy(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Disables the _FocusTrap_
|
|
35
|
+
*/
|
|
36
|
+
disable(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Enables the _FocusTrap_
|
|
39
|
+
*/
|
|
40
|
+
enable(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Focuses the _FocusTrap_
|
|
43
|
+
*
|
|
44
|
+
* @param last When `true`, focuses the last focusable element within the _FocusTrap_ instead of the first
|
|
45
|
+
*/
|
|
46
|
+
focus(last: boolean): void;
|
|
47
|
+
}
|
|
48
|
+
type OuiFocusTrapOptions = {
|
|
49
|
+
/**
|
|
50
|
+
* Should focus be maintained within the _FocusTrap_ when clicking outside of it?
|
|
51
|
+
*/
|
|
52
|
+
contain?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Should the _FocusTrap_ allow focus to escape when pressing _Escape_?
|
|
55
|
+
*/
|
|
56
|
+
noescape?: boolean;
|
|
57
|
+
};
|
|
58
|
+
type OuiFocusTrapState = {
|
|
59
|
+
disabled: boolean;
|
|
60
|
+
element: HTMLElement;
|
|
61
|
+
options: Required<OuiFocusTrapOptions>;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Creates _(or retrieves)_ a _FocusTrap_ for an element
|
|
65
|
+
*
|
|
66
|
+
* @param element Element to trap focus within
|
|
67
|
+
* @param options _FocusTrap_ options
|
|
68
|
+
* @returns _FocusTrap_ instance
|
|
69
|
+
*/
|
|
70
|
+
declare function createFocusTrap(element: HTMLElement, options?: OuiFocusTrapOptions): OuiFocusTrap;
|
|
71
|
+
declare function removeFocusTrap(element: HTMLElement): void;
|
|
72
|
+
declare const ATTRIBUTE_FOCUSTRAP = "oui-focus-trap";
|
|
73
|
+
declare const ATTRIBUTE_FOCUSTRAP_CONTAIN = "oui-focus-trap-contain";
|
|
74
|
+
declare const ATTRIBUTE_FOCUSTRAP_NOESCAPE = "oui-focus-trap-noescape";
|
|
75
|
+
//#endregion
|
|
76
|
+
export { createFocusTrap as a, OuiFocusTrap as i, ATTRIBUTE_FOCUSTRAP_CONTAIN as n, removeFocusTrap as o, ATTRIBUTE_FOCUSTRAP_NOESCAPE as r, ATTRIBUTE_FOCUSTRAP as t };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { RemovableEventListener } from "@oscarpalmer/toretto/models";
|
|
2
|
+
|
|
3
|
+
//#region src/js/floatable/embedded.d.ts
|
|
4
|
+
type CreateOuiFloatableOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Open the _OuiFloatable_ when created? _(defaults to `true`)_
|
|
7
|
+
*/
|
|
8
|
+
open?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Position of the _OuiFloatable_ _(defaults to `below`)_
|
|
11
|
+
*/
|
|
12
|
+
position?: OuiFloatablePosition;
|
|
13
|
+
};
|
|
14
|
+
declare class OuiFloatable {
|
|
15
|
+
#private;
|
|
16
|
+
/**
|
|
17
|
+
* Is the _OuiFloatable_ open?
|
|
18
|
+
*/
|
|
19
|
+
get open(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Open or close the _OuiFloatable_
|
|
22
|
+
*/
|
|
23
|
+
set open(value: boolean);
|
|
24
|
+
constructor(state: OuiFloatableState, standalone: boolean);
|
|
25
|
+
/**
|
|
26
|
+
* Destroy the _OuiFloatable_, removing it from the DOM and cleaning up references
|
|
27
|
+
*/
|
|
28
|
+
destroy(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Closes the _OuiFloatable_
|
|
31
|
+
*/
|
|
32
|
+
hide(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Opens the _OuiFloatable_
|
|
35
|
+
*/
|
|
36
|
+
show(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Update the position of the _OuiFloatable_, with an optional new position
|
|
39
|
+
*
|
|
40
|
+
* @param position Optional new position
|
|
41
|
+
*/
|
|
42
|
+
update(position?: OuiFloatablePosition): void;
|
|
43
|
+
}
|
|
44
|
+
type OuiFloatableOptions = {
|
|
45
|
+
attribute?: string;
|
|
46
|
+
position: OuiFloatablePosition;
|
|
47
|
+
};
|
|
48
|
+
type OuiFloatablePosition = 'above' | 'above-end' | 'above-start' | 'below' | 'below-end' | 'below-start' | 'end' | 'end-bottom' | 'end-top' | 'start' | 'start-bottom' | 'start-top';
|
|
49
|
+
type OuiFloatableState = {
|
|
50
|
+
anchor: HTMLElement;
|
|
51
|
+
content: HTMLElement;
|
|
52
|
+
options: OuiFloatableOptions;
|
|
53
|
+
};
|
|
54
|
+
declare function createEmbeddedFloatable(anchor: HTMLElement, content: HTMLElement, options: OuiFloatableOptions): OuiFloatable;
|
|
55
|
+
/**
|
|
56
|
+
* Create a _OuiFloatable_ for an anchor and content element
|
|
57
|
+
*
|
|
58
|
+
* @param anchor Anchor element
|
|
59
|
+
* @param content Content element
|
|
60
|
+
* @param options _OuiFloatable_ options
|
|
61
|
+
* @returns _OuiFloatable_ instance
|
|
62
|
+
*/
|
|
63
|
+
declare function createFloatable(anchor: HTMLElement, content: HTMLElement, options?: CreateOuiFloatableOptions): OuiFloatable;
|
|
64
|
+
declare function getOnBeforeToggleListener(element: HTMLElement): RemovableEventListener;
|
|
65
|
+
declare function removeFloatable(content: HTMLElement): void;
|
|
66
|
+
declare const ATTRIBUTE_FLOATABLE = "oui-floatable";
|
|
67
|
+
//#endregion
|
|
68
|
+
export { createEmbeddedFloatable as a, removeFloatable as c, OuiFloatablePosition as i, OuiFloatable as n, createFloatable as o, OuiFloatableOptions as r, getOnBeforeToggleListener as s, ATTRIBUTE_FLOATABLE as t };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as createEmbeddedFloatable, c as removeFloatable, i as OuiFloatablePosition, n as OuiFloatable, o as createFloatable, r as OuiFloatableOptions, s as getOnBeforeToggleListener, t as ATTRIBUTE_FLOATABLE } from "../embedded-ai6cqURc.mjs";
|
|
2
|
+
export { ATTRIBUTE_FLOATABLE, OuiFloatable, OuiFloatableOptions, OuiFloatablePosition, createEmbeddedFloatable, createFloatable, getOnBeforeToggleListener, removeFloatable };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { on } from "@oscarpalmer/toretto/event";
|
|
2
|
+
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
3
|
+
import { isHTMLOrSVGElement } from "@oscarpalmer/toretto/is";
|
|
4
|
+
//#region src/js/floatable/embedded.ts
|
|
5
|
+
var OuiFloatable = class {
|
|
6
|
+
#destroyed = false;
|
|
7
|
+
#state;
|
|
8
|
+
/**
|
|
9
|
+
* Is the _OuiFloatable_ open?
|
|
10
|
+
*/
|
|
11
|
+
get open() {
|
|
12
|
+
return this.#state.content.checkVisibility();
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Open or close the _OuiFloatable_
|
|
16
|
+
*/
|
|
17
|
+
set open(value) {
|
|
18
|
+
if (value === true) this.show();
|
|
19
|
+
else if (value === false) this.hide();
|
|
20
|
+
}
|
|
21
|
+
constructor(state, standalone) {
|
|
22
|
+
this.#state = state;
|
|
23
|
+
const { anchor, content } = state;
|
|
24
|
+
if (standalone) {
|
|
25
|
+
content.setAttribute(ATTRIBUTE_FLOATABLE, "");
|
|
26
|
+
content.popover = "manual";
|
|
27
|
+
}
|
|
28
|
+
const anchorName = getAnchorName(anchor);
|
|
29
|
+
anchor.style.anchorName = anchorName;
|
|
30
|
+
content.style.positionAnchor = anchorName;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Destroy the _OuiFloatable_, removing it from the DOM and cleaning up references
|
|
34
|
+
*/
|
|
35
|
+
destroy() {
|
|
36
|
+
if (this.#destroyed) return;
|
|
37
|
+
this.#destroyed = true;
|
|
38
|
+
removeFloatable(this.#state.content);
|
|
39
|
+
this.#state.anchor = null;
|
|
40
|
+
this.#state.content = null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Closes the _OuiFloatable_
|
|
44
|
+
*/
|
|
45
|
+
hide() {
|
|
46
|
+
if (!this.#destroyed && this.open) this.#state.content.hidePopover();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Opens the _OuiFloatable_
|
|
50
|
+
*/
|
|
51
|
+
show() {
|
|
52
|
+
if (!this.#destroyed && !this.open) this.#state.content.showPopover();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Update the position of the _OuiFloatable_, with an optional new position
|
|
56
|
+
*
|
|
57
|
+
* @param position Optional new position
|
|
58
|
+
*/
|
|
59
|
+
update(position) {
|
|
60
|
+
if (!this.#destroyed) setPosition(this.#state, position);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
function getAnchorName(anchor) {
|
|
64
|
+
let { anchorName } = anchor.style;
|
|
65
|
+
if (anchorName.length > 0) return anchorName;
|
|
66
|
+
index += 1;
|
|
67
|
+
return `--oui-floatable-anchor-${index}`;
|
|
68
|
+
}
|
|
69
|
+
function createEmbeddedFloatable(anchor, content, options) {
|
|
70
|
+
return createInstance(anchor, content, options, false);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create a _OuiFloatable_ for an anchor and content element
|
|
74
|
+
*
|
|
75
|
+
* @param anchor Anchor element
|
|
76
|
+
* @param content Content element
|
|
77
|
+
* @param options _OuiFloatable_ options
|
|
78
|
+
* @returns _OuiFloatable_ instance
|
|
79
|
+
*/
|
|
80
|
+
function createFloatable(anchor, content, options) {
|
|
81
|
+
const { open, position } = getOptions(options);
|
|
82
|
+
const floatable = createInstance(anchor, content, { position }, true);
|
|
83
|
+
floatable?.update(position);
|
|
84
|
+
if (open) floatable?.show();
|
|
85
|
+
return floatable;
|
|
86
|
+
}
|
|
87
|
+
function createInstance(anchor, content, options, standalone) {
|
|
88
|
+
if (!isHTMLOrSVGElement(anchor) || !isHTMLOrSVGElement(content)) throw new TypeError(MESSAGE);
|
|
89
|
+
let floatable = instances.get(content);
|
|
90
|
+
if (floatable == null) {
|
|
91
|
+
floatable = new OuiFloatable(getState(anchor, content, options), standalone);
|
|
92
|
+
instances.set(content, floatable);
|
|
93
|
+
}
|
|
94
|
+
return floatable;
|
|
95
|
+
}
|
|
96
|
+
function getOnBeforeToggleListener(element) {
|
|
97
|
+
return on(element, EVENT_BEFORE, (event) => {
|
|
98
|
+
const { newState, source } = event;
|
|
99
|
+
if (newState === STATE_OPEN && source?.getAttribute(ARIA_DISABLED) === TRUE) event.preventDefault();
|
|
100
|
+
}, { passive: false });
|
|
101
|
+
}
|
|
102
|
+
function getOptions(input) {
|
|
103
|
+
const object = isPlainObject(input) ? input : {};
|
|
104
|
+
return {
|
|
105
|
+
open: typeof object.open === "boolean" ? object.open : true,
|
|
106
|
+
position: object.position != null && object.position in AREAS ? object.position : "below"
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function getPosition$1(state, override) {
|
|
110
|
+
if (override != null && override in AREAS) return override;
|
|
111
|
+
const { anchor, options } = state;
|
|
112
|
+
if (options.attribute == null) return options.position;
|
|
113
|
+
const attribute = anchor.getAttribute(options.attribute) ?? "";
|
|
114
|
+
return attribute in AREAS ? attribute : options.position;
|
|
115
|
+
}
|
|
116
|
+
function getState(anchor, content, options) {
|
|
117
|
+
return {
|
|
118
|
+
anchor,
|
|
119
|
+
content,
|
|
120
|
+
options
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function removeFloatable(content) {
|
|
124
|
+
instances.get(content)?.destroy();
|
|
125
|
+
instances.delete(content);
|
|
126
|
+
}
|
|
127
|
+
function setPosition(state, override) {
|
|
128
|
+
const area = AREAS[getPosition$1(state, override)];
|
|
129
|
+
state.content.style.positionArea = area;
|
|
130
|
+
state.content.setAttribute(ATTRIBUTE_POSITION, POSITIONS[area]);
|
|
131
|
+
}
|
|
132
|
+
const AREAS = {
|
|
133
|
+
above: "block-start",
|
|
134
|
+
"above-end": "start span-start",
|
|
135
|
+
"above-start": "start span-end",
|
|
136
|
+
below: "block-end",
|
|
137
|
+
"below-end": "end span-start",
|
|
138
|
+
"below-start": "end span-end",
|
|
139
|
+
end: "center end",
|
|
140
|
+
"end-bottom": "span-start end",
|
|
141
|
+
"end-top": "span-end end",
|
|
142
|
+
start: "center start",
|
|
143
|
+
"start-bottom": "span-start start",
|
|
144
|
+
"start-top": "span-end start"
|
|
145
|
+
};
|
|
146
|
+
const ARIA_DISABLED = "aria-disabled";
|
|
147
|
+
const ATTRIBUTE_FLOATABLE = "oui-floatable";
|
|
148
|
+
const ATTRIBUTE_POSITION = "oui-position";
|
|
149
|
+
const EVENT_BEFORE = "beforetoggle";
|
|
150
|
+
const MESSAGE = "Anchor and content must be an HTMLElement or SVGElement";
|
|
151
|
+
const POSITIONS = Object.fromEntries(Object.entries(AREAS).map(([position, area]) => [area, position]));
|
|
152
|
+
const STATE_OPEN = "open";
|
|
153
|
+
const TRUE = "true";
|
|
154
|
+
const instances = /* @__PURE__ */ new WeakMap();
|
|
155
|
+
let index = 0;
|
|
156
|
+
//#endregion
|
|
157
|
+
export { ATTRIBUTE_FLOATABLE, OuiFloatable, createEmbeddedFloatable, createFloatable, getOnBeforeToggleListener, removeFloatable };
|
|
@@ -1,26 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
disabled: boolean;
|
|
4
|
-
connected: boolean;
|
|
5
|
-
element: HTMLElement;
|
|
6
|
-
embedded: boolean;
|
|
7
|
-
get contain(): boolean;
|
|
8
|
-
get noescape(): boolean;
|
|
9
|
-
constructor(element: HTMLElement, options?: Options);
|
|
10
|
-
connect(): void;
|
|
11
|
-
destroy(): void;
|
|
12
|
-
disable(): void;
|
|
13
|
-
disconnect(): void;
|
|
14
|
-
enable(): void;
|
|
15
|
-
focus(last: boolean): void;
|
|
16
|
-
}
|
|
17
|
-
type Options = {
|
|
18
|
-
noescape: boolean;
|
|
19
|
-
};
|
|
20
|
-
declare function createFocusTrap(element: HTMLElement, options?: Options): FocusTrap;
|
|
21
|
-
declare function removeFocusTrap(element: HTMLElement): void;
|
|
22
|
-
declare const FOCUS_TRAP_SELECTOR = "oui-focus-trap";
|
|
23
|
-
declare const FOCUS_TRAP_CONTAIN = "oui-focus-trap-contain";
|
|
24
|
-
declare const FOCUS_TRAP_NOESCAPE = "oui-focus-trap-noescape";
|
|
25
|
-
//#endregion
|
|
26
|
-
export { FOCUS_TRAP_CONTAIN, FOCUS_TRAP_NOESCAPE, FOCUS_TRAP_SELECTOR, FocusTrap, createFocusTrap, removeFocusTrap };
|
|
1
|
+
import { a as createFocusTrap, i as OuiFocusTrap, n as ATTRIBUTE_FOCUSTRAP_CONTAIN, o as removeFocusTrap, r as ATTRIBUTE_FOCUSTRAP_NOESCAPE, t as ATTRIBUTE_FOCUSTRAP } from "../embedded-CHK82Uh5.mjs";
|
|
2
|
+
export { ATTRIBUTE_FOCUSTRAP, ATTRIBUTE_FOCUSTRAP_CONTAIN, ATTRIBUTE_FOCUSTRAP_NOESCAPE, OuiFocusTrap, createFocusTrap, removeFocusTrap };
|