@oscarpalmer/oui 0.25.0 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/js/dialog.d.mts +4 -0
- package/dist/js/dialog.mjs +7 -0
- package/dist/js/embedded-CHK82Uh5.d.mts +76 -0
- package/dist/js/{embedded-84gxpReS.d.mts → embedded-CSOh5njI.d.mts} +25 -21
- package/dist/js/floatable/embedded.d.mts +2 -2
- package/dist/js/floatable/embedded.mjs +31 -20
- package/dist/js/floatable/standalone.d.mts +2 -2
- package/dist/js/floatable/standalone.mjs +2 -2
- package/dist/js/focus-trap/embedded.d.mts +2 -2
- package/dist/js/focus-trap/embedded.mjs +157 -79
- 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 +3 -2
- package/dist/js/index.mjs +4 -2
- package/dist/js/internal/draggable.d.mts +2 -2
- package/dist/js/internal/draggable.mjs +2 -2
- 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 +4 -3
- package/dist/js/popover.mjs +13 -9
- package/dist/js/sortable.d.mts +2 -2
- package/dist/js/sortable.mjs +4 -4
- package/dist/js/splitter.d.mts +24 -0
- package/dist/js/splitter.mjs +76 -51
- package/dist/js/toolbar.d.mts +1 -0
- package/dist/js/toolbar.mjs +107 -0
- package/dist/js/tooltip.d.mts +11 -1
- package/dist/js/tooltip.mjs +20 -7
- package/package.json +13 -1
- package/src/js/dialog.ts +11 -0
- package/src/js/floatable/embedded.ts +69 -48
- package/src/js/floatable/standalone.ts +1 -1
- package/src/js/focus-trap/embedded.ts +219 -93
- package/src/js/focus-trap/standalone.ts +4 -2
- package/src/js/index.ts +1 -0
- package/src/js/internal/draggable.ts +20 -20
- package/src/js/movable.ts +17 -17
- package/src/js/popover.ts +26 -18
- package/src/js/sortable.ts +26 -26
- package/src/js/splitter.ts +126 -100
- package/src/js/toolbar.ts +214 -0
- package/src/js/tooltip.ts +31 -10
- package/dist/js/embedded-BpwzMSEF.d.mts +0 -26
package/dist/js/tooltip.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createEmbeddedFloatable } from "./floatable/embedded.mjs";
|
|
2
2
|
import { attributable } from "./internal/attributable.mjs";
|
|
3
3
|
import { on } from "@oscarpalmer/toretto/event";
|
|
4
4
|
import { isNullableOrWhitespace } from "@oscarpalmer/atoms/is";
|
|
@@ -14,6 +14,13 @@ var OuiTooltip = class {
|
|
|
14
14
|
get open() {
|
|
15
15
|
return this.#state.content.checkVisibility();
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Open or close the tooltip
|
|
19
|
+
*/
|
|
20
|
+
set open(value) {
|
|
21
|
+
if (value === true) this.show();
|
|
22
|
+
else if (value === false) this.hide();
|
|
23
|
+
}
|
|
17
24
|
constructor(state) {
|
|
18
25
|
this.#state = state;
|
|
19
26
|
state.floatable.update();
|
|
@@ -57,6 +64,9 @@ function activate(event, focus) {
|
|
|
57
64
|
});
|
|
58
65
|
}, shouldDelay ? delay : 0);
|
|
59
66
|
}
|
|
67
|
+
function addTooltip(element) {
|
|
68
|
+
if (!states.has(element)) createTooltip(element);
|
|
69
|
+
}
|
|
60
70
|
function closeTooltip(state) {
|
|
61
71
|
if (state == null) return;
|
|
62
72
|
if (state.timer != null) clearTimeout(state.timer);
|
|
@@ -120,18 +130,21 @@ function getState(anchor, content) {
|
|
|
120
130
|
const state = {
|
|
121
131
|
anchor,
|
|
122
132
|
content,
|
|
123
|
-
floatable:
|
|
133
|
+
floatable: createEmbeddedFloatable(anchor, content, options),
|
|
124
134
|
tooltip: null
|
|
125
135
|
};
|
|
126
136
|
state.tooltip = new OuiTooltip(state);
|
|
127
137
|
return state;
|
|
128
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Get the _OuiTooltip_ for an element
|
|
141
|
+
*
|
|
142
|
+
* @param element Element to get _OuiTooltip_ for
|
|
143
|
+
* @returns _OuiTooltip_ instance
|
|
144
|
+
*/
|
|
129
145
|
function getTooltip(element) {
|
|
130
146
|
return states.get(element)?.tooltip;
|
|
131
147
|
}
|
|
132
|
-
function onAdd(element) {
|
|
133
|
-
if (!states.has(element)) createTooltip(element);
|
|
134
|
-
}
|
|
135
148
|
function onFocusin(event) {
|
|
136
149
|
activate(event, true);
|
|
137
150
|
}
|
|
@@ -148,7 +161,7 @@ function onFocusout() {
|
|
|
148
161
|
function onPointermove(event) {
|
|
149
162
|
activate(event, false);
|
|
150
163
|
}
|
|
151
|
-
function
|
|
164
|
+
function removeTooltip(element) {
|
|
152
165
|
const state = states.get(element);
|
|
153
166
|
if (state == null) return;
|
|
154
167
|
destroyTooltip(state);
|
|
@@ -187,6 +200,6 @@ let focusTimer;
|
|
|
187
200
|
on(document, "focusin", onFocusin);
|
|
188
201
|
on(document, "focusout", onFocusout);
|
|
189
202
|
on(document, "pointermove", onPointermove);
|
|
190
|
-
attributable(ATTRIBUTE,
|
|
203
|
+
attributable(ATTRIBUTE, addTooltip, removeTooltip);
|
|
191
204
|
//#endregion
|
|
192
205
|
export { getTooltip, setTooltipDelay };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oscarpalmer/oui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.1",
|
|
4
4
|
"description": "Styles, components, and utilities for building websites and applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -33,6 +33,14 @@
|
|
|
33
33
|
"types": "./dist/js/index.d.mts",
|
|
34
34
|
"default": "./dist/js/index.mjs"
|
|
35
35
|
},
|
|
36
|
+
"./dialog": {
|
|
37
|
+
"types": "./dist/js/dialog.d.mts",
|
|
38
|
+
"default": "./dist/js/dialog.mjs"
|
|
39
|
+
},
|
|
40
|
+
"./floatable": {
|
|
41
|
+
"types": "./dist/js/floatable/standalone.d.mts",
|
|
42
|
+
"default": "./dist/js/floatable/standalone.mjs"
|
|
43
|
+
},
|
|
36
44
|
"./focus-trap": {
|
|
37
45
|
"types": "./dist/js/focus-trap/standalone.d.mts",
|
|
38
46
|
"default": "./dist/js/focus-trap/standalone.mjs"
|
|
@@ -53,6 +61,10 @@
|
|
|
53
61
|
"types": "./dist/js/splitter.d.mts",
|
|
54
62
|
"default": "./dist/js/splitter.mjs"
|
|
55
63
|
},
|
|
64
|
+
"./toolbar": {
|
|
65
|
+
"types": "./dist/js/toolbar.d.mts",
|
|
66
|
+
"default": "./dist/js/toolbar.mjs"
|
|
67
|
+
},
|
|
56
68
|
"./tooltip": {
|
|
57
69
|
"types": "./dist/js/tooltip.d.mts",
|
|
58
70
|
"default": "./dist/js/tooltip.mjs"
|
package/src/js/dialog.ts
CHANGED
|
@@ -15,6 +15,17 @@ class OuiDialog {
|
|
|
15
15
|
return this.#state.element.open;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Open or close the dialog
|
|
20
|
+
*/
|
|
21
|
+
set open(value: boolean) {
|
|
22
|
+
if (value === true) {
|
|
23
|
+
this.show();
|
|
24
|
+
} else if (value === false) {
|
|
25
|
+
this.hide();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
18
29
|
constructor(state: OuiDialogState) {
|
|
19
30
|
this.#state = state;
|
|
20
31
|
}
|
|
@@ -5,18 +5,40 @@ import type {RemovableEventListener} from '@oscarpalmer/toretto/models';
|
|
|
5
5
|
|
|
6
6
|
// #region Types
|
|
7
7
|
|
|
8
|
+
type CreateOuiFloatableOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* Open the floatable when created? _(defaults to `true`)_
|
|
11
|
+
*/
|
|
12
|
+
open?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Position of the floatable _(defaults to `below`)_
|
|
15
|
+
*/
|
|
16
|
+
position?: OuiFloatablePosition;
|
|
17
|
+
};
|
|
18
|
+
|
|
8
19
|
export class OuiFloatable {
|
|
9
20
|
#destroyed = false;
|
|
10
21
|
|
|
11
22
|
readonly #state: OuiFloatableState;
|
|
12
23
|
|
|
13
24
|
/**
|
|
14
|
-
* Is the
|
|
25
|
+
* Is the floatable open?
|
|
15
26
|
*/
|
|
16
27
|
get open(): boolean {
|
|
17
28
|
return this.#state.content.checkVisibility();
|
|
18
29
|
}
|
|
19
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Open or close the floatable
|
|
33
|
+
*/
|
|
34
|
+
set open(value: boolean) {
|
|
35
|
+
if (value === true) {
|
|
36
|
+
this.show();
|
|
37
|
+
} else if (value === false) {
|
|
38
|
+
this.hide();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
20
42
|
constructor(state: OuiFloatableState, standalone: boolean) {
|
|
21
43
|
this.#state = state;
|
|
22
44
|
|
|
@@ -35,7 +57,7 @@ export class OuiFloatable {
|
|
|
35
57
|
}
|
|
36
58
|
|
|
37
59
|
/**
|
|
38
|
-
* Destroy the
|
|
60
|
+
* Destroy the floatable, removing it from the DOM and cleaning up references
|
|
39
61
|
*/
|
|
40
62
|
destroy(): void {
|
|
41
63
|
if (this.#destroyed) {
|
|
@@ -51,7 +73,7 @@ export class OuiFloatable {
|
|
|
51
73
|
}
|
|
52
74
|
|
|
53
75
|
/**
|
|
54
|
-
* Closes the
|
|
76
|
+
* Closes the floatable
|
|
55
77
|
*/
|
|
56
78
|
hide(): void {
|
|
57
79
|
if (!this.#destroyed && this.open) {
|
|
@@ -60,7 +82,7 @@ export class OuiFloatable {
|
|
|
60
82
|
}
|
|
61
83
|
|
|
62
84
|
/**
|
|
63
|
-
* Opens the
|
|
85
|
+
* Opens the floatable
|
|
64
86
|
*/
|
|
65
87
|
show(): void {
|
|
66
88
|
if (!this.#destroyed && !this.open) {
|
|
@@ -69,7 +91,7 @@ export class OuiFloatable {
|
|
|
69
91
|
}
|
|
70
92
|
|
|
71
93
|
/**
|
|
72
|
-
* Update the position of the
|
|
94
|
+
* Update the position of the floatable, with an optional new position
|
|
73
95
|
*
|
|
74
96
|
* @param position Optional new position
|
|
75
97
|
*/
|
|
@@ -105,42 +127,10 @@ type OuiFloatableState = {
|
|
|
105
127
|
options: OuiFloatableOptions;
|
|
106
128
|
};
|
|
107
129
|
|
|
108
|
-
type GetOuiFloatableOptions = {
|
|
109
|
-
/**
|
|
110
|
-
* Open the _OuiFloatable_ when created? _(defaults to `true`)_
|
|
111
|
-
*/
|
|
112
|
-
open?: boolean;
|
|
113
|
-
/**
|
|
114
|
-
* Position of the _OuiFloatable_ _(defaults to `below`)_
|
|
115
|
-
*/
|
|
116
|
-
position?: OuiFloatablePosition;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
130
|
// #endregion
|
|
120
131
|
|
|
121
132
|
// #region Functions
|
|
122
133
|
|
|
123
|
-
export function createFloatable(
|
|
124
|
-
anchor: HTMLElement,
|
|
125
|
-
content: HTMLElement,
|
|
126
|
-
options: OuiFloatableOptions,
|
|
127
|
-
standalone: boolean,
|
|
128
|
-
): OuiFloatable {
|
|
129
|
-
if (!isHTMLOrSVGElement(anchor) || !isHTMLOrSVGElement(content)) {
|
|
130
|
-
throw new TypeError('Anchor and content must be an HTMLElement or SVGElement.');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
let floatable = instances.get(content);
|
|
134
|
-
|
|
135
|
-
if (floatable == null) {
|
|
136
|
-
floatable = new OuiFloatable(getState(anchor, content, options), standalone);
|
|
137
|
-
|
|
138
|
-
instances.set(content, floatable);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return floatable;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
134
|
function getAnchorName(anchor: HTMLElement): string {
|
|
145
135
|
let {anchorName} = anchor.style;
|
|
146
136
|
|
|
@@ -153,24 +143,32 @@ function getAnchorName(anchor: HTMLElement): string {
|
|
|
153
143
|
return `--oui-floatable-anchor-${index}`;
|
|
154
144
|
}
|
|
155
145
|
|
|
146
|
+
export function createEmbeddedFloatable(
|
|
147
|
+
anchor: HTMLElement,
|
|
148
|
+
content: HTMLElement,
|
|
149
|
+
options: OuiFloatableOptions,
|
|
150
|
+
): OuiFloatable {
|
|
151
|
+
return createInstance(anchor, content, options, false);
|
|
152
|
+
}
|
|
153
|
+
|
|
156
154
|
/**
|
|
157
|
-
* Create a
|
|
155
|
+
* Create a _OuiFloatable_ for an anchor and content element
|
|
158
156
|
*
|
|
159
157
|
* @param anchor Anchor element
|
|
160
158
|
* @param content Content element
|
|
161
|
-
* @param options
|
|
162
|
-
* @returns
|
|
159
|
+
* @param options _OuiFloatable_ options
|
|
160
|
+
* @returns _OuiFloatable_ instance
|
|
163
161
|
*/
|
|
164
|
-
export function
|
|
165
|
-
anchor: HTMLElement
|
|
166
|
-
content: HTMLElement
|
|
167
|
-
options?:
|
|
162
|
+
export function createFloatable(
|
|
163
|
+
anchor: HTMLElement,
|
|
164
|
+
content: HTMLElement,
|
|
165
|
+
options?: CreateOuiFloatableOptions,
|
|
168
166
|
): OuiFloatable {
|
|
169
167
|
const {open, position} = getOptions(options);
|
|
170
168
|
|
|
171
|
-
const floatable =
|
|
172
|
-
anchor
|
|
173
|
-
content
|
|
169
|
+
const floatable = createInstance(
|
|
170
|
+
anchor,
|
|
171
|
+
content,
|
|
174
172
|
{
|
|
175
173
|
position,
|
|
176
174
|
},
|
|
@@ -186,6 +184,27 @@ export function getFloatable(
|
|
|
186
184
|
return floatable;
|
|
187
185
|
}
|
|
188
186
|
|
|
187
|
+
function createInstance(
|
|
188
|
+
anchor: HTMLElement,
|
|
189
|
+
content: HTMLElement,
|
|
190
|
+
options: OuiFloatableOptions,
|
|
191
|
+
standalone: boolean,
|
|
192
|
+
): OuiFloatable {
|
|
193
|
+
if (!isHTMLOrSVGElement(anchor) || !isHTMLOrSVGElement(content)) {
|
|
194
|
+
throw new TypeError(MESSAGE);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let floatable = instances.get(content);
|
|
198
|
+
|
|
199
|
+
if (floatable == null) {
|
|
200
|
+
floatable = new OuiFloatable(getState(anchor, content, options), standalone);
|
|
201
|
+
|
|
202
|
+
instances.set(content, floatable);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return floatable;
|
|
206
|
+
}
|
|
207
|
+
|
|
189
208
|
export function getOnBeforeToggleListener(element: HTMLElement): RemovableEventListener {
|
|
190
209
|
return on(
|
|
191
210
|
element,
|
|
@@ -203,7 +222,7 @@ export function getOnBeforeToggleListener(element: HTMLElement): RemovableEventL
|
|
|
203
222
|
);
|
|
204
223
|
}
|
|
205
224
|
|
|
206
|
-
function getOptions(input?:
|
|
225
|
+
function getOptions(input?: CreateOuiFloatableOptions): Required<CreateOuiFloatableOptions> {
|
|
207
226
|
const object = isPlainObject(input) ? input : {};
|
|
208
227
|
|
|
209
228
|
return {
|
|
@@ -287,6 +306,8 @@ const ATTRIBUTE_POSITION = 'oui-position';
|
|
|
287
306
|
|
|
288
307
|
const EVENT_BEFORE = 'beforetoggle';
|
|
289
308
|
|
|
309
|
+
const MESSAGE = 'Anchor and content must be an HTMLElement or SVGElement';
|
|
310
|
+
|
|
290
311
|
const POSITIONS = Object.fromEntries(
|
|
291
312
|
Object.entries(AREAS).map(([position, area]) => [area, position]),
|
|
292
313
|
) as Record<string, OuiFloatablePosition>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {createFloatable, type OuiFloatable, type OuiFloatablePosition} from './embedded';
|