@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
package/src/js/floatable.ts
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import {isPlainObject} from '@oscarpalmer/atoms/is';
|
|
2
|
-
import {isHTMLOrSVGElement} from '@oscarpalmer/toretto/is';
|
|
3
|
-
|
|
4
|
-
export class Floatable {
|
|
5
|
-
#destroyed = false;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Is the _Floatable_ open?
|
|
9
|
-
*/
|
|
10
|
-
get open(): boolean {
|
|
11
|
-
return this.content.checkVisibility();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
constructor(
|
|
15
|
-
public anchor: HTMLElement,
|
|
16
|
-
public content: HTMLElement,
|
|
17
|
-
public options: FloatableOptions,
|
|
18
|
-
standalone: boolean,
|
|
19
|
-
) {
|
|
20
|
-
if (standalone) {
|
|
21
|
-
content.setAttribute(ATTRIBUTE_FLOATABLE, '');
|
|
22
|
-
|
|
23
|
-
content.popover = 'manual';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const anchorName = getAnchorName(anchor);
|
|
27
|
-
|
|
28
|
-
anchor.style.anchorName = anchorName;
|
|
29
|
-
content.style.positionAnchor = anchorName;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Destroy the floatable, removing it from the DOM and cleaning up references
|
|
34
|
-
*/
|
|
35
|
-
destroy(): void {
|
|
36
|
-
if (this.#destroyed) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
this.#destroyed = true;
|
|
41
|
-
|
|
42
|
-
removeFloatable(this.content);
|
|
43
|
-
|
|
44
|
-
this.anchor = null as never;
|
|
45
|
-
this.content = null as never;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Hide the floatable
|
|
50
|
-
*/
|
|
51
|
-
hide(): void {
|
|
52
|
-
if (!this.#destroyed) {
|
|
53
|
-
this.content.hidePopover();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Show the floatable
|
|
59
|
-
*/
|
|
60
|
-
show(): void {
|
|
61
|
-
if (!this.#destroyed) {
|
|
62
|
-
this.content.showPopover();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Update the position of the floatable, with an optional new position
|
|
68
|
-
*
|
|
69
|
-
* @param position Optional new position
|
|
70
|
-
*/
|
|
71
|
-
update(position?: FloatablePosition): void {
|
|
72
|
-
if (!this.#destroyed) {
|
|
73
|
-
setPosition(this, position);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export type FloatableOptions = {
|
|
79
|
-
attribute?: string;
|
|
80
|
-
position: FloatablePosition;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export type FloatablePosition =
|
|
84
|
-
| 'above'
|
|
85
|
-
| 'above-end'
|
|
86
|
-
| 'above-start'
|
|
87
|
-
| 'below'
|
|
88
|
-
| 'below-end'
|
|
89
|
-
| 'below-start'
|
|
90
|
-
| 'end'
|
|
91
|
-
| 'end-bottom'
|
|
92
|
-
| 'end-top'
|
|
93
|
-
| 'start'
|
|
94
|
-
| 'start-bottom'
|
|
95
|
-
| 'start-top';
|
|
96
|
-
|
|
97
|
-
type GetFloatableOptions = {
|
|
98
|
-
/**
|
|
99
|
-
* Open the _Floatable_ when created? _(defaults to `true`)_
|
|
100
|
-
*/
|
|
101
|
-
open?: boolean;
|
|
102
|
-
/**
|
|
103
|
-
* Position of the _Floatable_ _(defaults to `below`)_
|
|
104
|
-
*/
|
|
105
|
-
position?: FloatablePosition;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
export function createFloatable(
|
|
109
|
-
anchor: HTMLElement,
|
|
110
|
-
content: HTMLElement,
|
|
111
|
-
options: FloatableOptions,
|
|
112
|
-
standalone: boolean,
|
|
113
|
-
): Floatable {
|
|
114
|
-
if (!isHTMLOrSVGElement(anchor) || !isHTMLOrSVGElement(content)) {
|
|
115
|
-
throw new TypeError('Anchor and content must be an HTMLElement or SVGElement.');
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
let floatable = instances.get(content);
|
|
119
|
-
|
|
120
|
-
if (floatable == null) {
|
|
121
|
-
floatable = new Floatable(anchor, content, options, standalone);
|
|
122
|
-
|
|
123
|
-
instances.set(content, floatable);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return floatable;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function getAnchorName(anchor: HTMLElement): string {
|
|
130
|
-
let {anchorName} = anchor.style;
|
|
131
|
-
|
|
132
|
-
if (anchorName.length > 0) {
|
|
133
|
-
return anchorName;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
index += 1;
|
|
137
|
-
|
|
138
|
-
return `--oui-floatable-anchor-${index}`;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Create a _Floatable_ for an anchor and content element
|
|
143
|
-
*
|
|
144
|
-
* @param anchor Anchor element
|
|
145
|
-
* @param content Content element
|
|
146
|
-
* @param options _Floatable_ options
|
|
147
|
-
* @returns _Floatable_ instance
|
|
148
|
-
*/
|
|
149
|
-
export function getFloatable(
|
|
150
|
-
anchor: HTMLElement | SVGElement,
|
|
151
|
-
content: HTMLElement | SVGElement,
|
|
152
|
-
options?: GetFloatableOptions,
|
|
153
|
-
): Floatable {
|
|
154
|
-
const {open, position} = getOptions(options);
|
|
155
|
-
|
|
156
|
-
const floatable = createFloatable(
|
|
157
|
-
anchor as HTMLElement,
|
|
158
|
-
content as HTMLElement,
|
|
159
|
-
{
|
|
160
|
-
position,
|
|
161
|
-
},
|
|
162
|
-
true,
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
floatable?.update(position);
|
|
166
|
-
|
|
167
|
-
if (open) {
|
|
168
|
-
floatable?.show();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return floatable;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function getOptions(input?: GetFloatableOptions): Required<GetFloatableOptions> {
|
|
175
|
-
const object = isPlainObject(input) ? input : {};
|
|
176
|
-
|
|
177
|
-
return {
|
|
178
|
-
open: typeof object.open === 'boolean' ? object.open : true,
|
|
179
|
-
position: object.position != null && object.position in AREAS ? object.position : 'below',
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function getPosition(floatable: Floatable, override?: FloatablePosition): FloatablePosition {
|
|
184
|
-
if (override != null && override in AREAS) {
|
|
185
|
-
return override;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (floatable.options.attribute == null) {
|
|
189
|
-
return floatable.options.position;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const attribute = floatable.anchor.getAttribute(floatable.options.attribute) ?? '';
|
|
193
|
-
|
|
194
|
-
return attribute in AREAS ? (attribute as FloatablePosition) : floatable.options.position;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export function removeFloatable(content: HTMLElement): void {
|
|
198
|
-
instances.get(content)?.destroy();
|
|
199
|
-
instances.delete(content);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function setPosition(floatable: Floatable, override?: FloatablePosition): void {
|
|
203
|
-
const position = getPosition(floatable, override);
|
|
204
|
-
|
|
205
|
-
const area = AREAS[position];
|
|
206
|
-
|
|
207
|
-
floatable.content.style.positionArea = area;
|
|
208
|
-
|
|
209
|
-
floatable.content.setAttribute(ATTRIBUTE_POSITION, POSITIONS[area]);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const AREAS: Record<FloatablePosition, string> = {
|
|
213
|
-
above: 'block-start',
|
|
214
|
-
'above-end': 'start span-start',
|
|
215
|
-
'above-start': 'start span-end',
|
|
216
|
-
below: 'block-end',
|
|
217
|
-
'below-end': 'end span-start',
|
|
218
|
-
'below-start': 'end span-end',
|
|
219
|
-
end: 'center end',
|
|
220
|
-
'end-bottom': 'span-start end',
|
|
221
|
-
'end-top': 'span-end end',
|
|
222
|
-
start: 'center start',
|
|
223
|
-
'start-bottom': 'span-start start',
|
|
224
|
-
'start-top': 'span-end start',
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
export const ATTRIBUTE_FLOATABLE = 'oui-floatable';
|
|
228
|
-
|
|
229
|
-
const ATTRIBUTE_POSITION = 'oui-position';
|
|
230
|
-
|
|
231
|
-
const POSITIONS = Object.fromEntries(
|
|
232
|
-
Object.entries(AREAS).map(([position, area]) => [area, position]),
|
|
233
|
-
) as Record<string, FloatablePosition>;
|
|
234
|
-
|
|
235
|
-
const instances = new WeakMap<HTMLElement, Floatable>();
|
|
236
|
-
|
|
237
|
-
let index = 0;
|