@oscarpalmer/oui 0.37.0 → 0.39.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/a11y.css +1 -0
- package/dist/css/badge.css +12 -8
- package/dist/css/button.css +111 -14
- package/dist/css/color-picker.css +859 -0
- package/dist/css/color.css +86 -87
- package/dist/css/combobox.css +105 -4
- package/dist/css/content.css +8 -6
- package/dist/css/floatable.css +3 -3
- package/dist/css/form.css +106 -6
- package/dist/css/icon.css +99 -0
- package/dist/css/listbox.css +5 -0
- package/dist/css/message.css +6 -3
- package/dist/css/mixins/badge.mixins.css +2 -0
- package/dist/css/mixins/button.mixins.css +3 -0
- package/dist/css/mixins/message.mixins.css +1 -0
- package/dist/css/mixins/misc.mixins.css +2 -0
- package/dist/css/mixins/shadow.mixins.css +1 -0
- package/dist/css/reset.css +3 -3
- package/dist/css/splitter.css +1 -1
- package/dist/css/tabs.css +115 -23
- package/dist/css/typography.css +90 -0
- package/dist/js/color-picker/constants.color-picker.d.mts +2 -0
- package/dist/js/color-picker/constants.color-picker.mjs +59 -0
- package/dist/js/color-picker/dom.color-picker.d.mts +8 -0
- package/dist/js/color-picker/dom.color-picker.mjs +191 -0
- package/dist/js/color-picker/event.color-picker.d.mts +9 -0
- package/dist/js/color-picker/event.color-picker.mjs +2 -0
- package/dist/js/color-picker/form.color-picker.d.mts +5 -0
- package/dist/js/color-picker/form.color-picker.mjs +24 -0
- package/dist/js/color-picker/index.d.mts +2 -0
- package/dist/js/color-picker/index.mjs +303 -0
- package/dist/js/color-picker/misc.color-picker.d.mts +2 -0
- package/dist/js/color-picker/misc.color-picker.mjs +2 -0
- package/dist/js/color-picker/models.color-picker.d.mts +2 -0
- package/dist/js/color-picker/models.color-picker.mjs +24 -0
- package/dist/js/color-picker/output.color-picker.d.mts +8 -0
- package/dist/js/color-picker/output.color-picker.mjs +233 -0
- package/dist/js/color-picker/state.color-picker.d.mts +8 -0
- package/dist/js/color-picker/state.color-picker.mjs +2 -0
- package/dist/js/combobox/constants.combobox.d.mts +1 -1
- package/dist/js/combobox/dom.combobox.d.mts +12 -13
- package/dist/js/combobox/dom.combobox.mjs +12 -5
- package/dist/js/combobox/event.combobox.d.mts +20 -21
- package/dist/js/combobox/event.combobox.mjs +1 -1
- package/dist/js/combobox/index.d.mts +1 -1
- package/dist/js/combobox/index.mjs +56 -2
- package/dist/js/combobox/misc.combobox.d.mts +1 -1
- package/dist/js/combobox/misc.combobox.mjs +1 -1
- package/dist/js/combobox/models.combobox.d.mts +12 -13
- package/dist/js/combobox/state.combobox.d.mts +8 -9
- package/dist/js/combobox/state.combobox.mjs +1 -1
- package/dist/js/constants.color-picker-B-gFjL8m.d.mts +364 -0
- package/dist/js/constants.combobox-8EMRmv09.d.mts +18 -0
- package/dist/js/constants.listbox-DGnX32kv.d.mts +8 -0
- package/dist/js/dialog.d.mts +2 -2
- package/dist/js/dialog.mjs +1 -1
- package/dist/js/{draggable-a6w0J1OD.d.mts → draggable-B5-70SZm.d.mts} +5 -4
- package/dist/js/event.color-picker-BEpq0Adu.mjs +485 -0
- package/dist/js/floatable/floatable.embedded.d.mts +1 -1
- package/dist/js/floatable/floatable.embedded.mjs +11 -8
- package/dist/js/floatable/floatable.standalone.d.mts +1 -1
- package/dist/js/{floatable.embedded-Bct4U5Dm.d.mts → floatable.embedded-DQYkXt8X.d.mts} +1 -1
- package/dist/js/focus-trap/focus-trap.embedded.d.mts +1 -1
- package/dist/js/focus-trap/focus-trap.standalone.d.mts +1 -1
- package/dist/js/{focus-trap.embedded-DR8NpZfr.d.mts → focus-trap.embedded-CjyFQYow.d.mts} +2 -2
- package/dist/js/{index-EfkUSals.d.mts → index-C5D3-oiI.d.mts} +41 -3
- package/dist/js/index.d.mts +8 -7
- package/dist/js/index.mjs +6 -3
- package/dist/js/internal/attributable.d.mts +2 -3
- package/dist/js/internal/draggable.d.mts +1 -1
- package/dist/js/internal/draggable.mjs +1 -1
- package/dist/js/internal/listbox/listbox.constants.d.mts +7 -10
- package/dist/js/internal/listbox/listbox.constants.mjs +15 -16
- package/dist/js/internal/listbox/listbox.data.d.mts +9 -10
- package/dist/js/internal/listbox/listbox.data.mjs +1 -1
- package/dist/js/internal/listbox/listbox.dom.d.mts +19 -20
- package/dist/js/internal/listbox/listbox.dom.mjs +1 -1
- package/dist/js/internal/listbox/listbox.event.d.mts +3 -4
- package/dist/js/internal/listbox/listbox.event.mjs +4 -4
- package/dist/js/internal/listbox/listbox.form.d.mts +4 -5
- package/dist/js/internal/listbox/listbox.form.mjs +16 -15
- package/dist/js/internal/listbox/listbox.misc.d.mts +10 -11
- package/dist/js/internal/listbox/listbox.misc.mjs +1 -1
- package/dist/js/internal/listbox/listbox.model.d.mts +1 -1
- package/dist/js/internal/listbox/listbox.state.d.mts +5 -6
- package/dist/js/internal/listbox/listbox.state.mjs +3 -3
- package/dist/js/internal/misc.d.mts +4 -4
- package/dist/js/internal/misc.mjs +9 -1
- package/dist/js/internal/navigable.d.mts +9 -10
- package/dist/js/internal/navigable.mjs +1 -0
- package/dist/js/listbox/constants.listbox.d.mts +1 -1
- package/dist/js/listbox/event.listbox.d.mts +6 -7
- package/dist/js/listbox/event.listbox.mjs +1 -1
- package/dist/js/listbox/index.d.mts +43 -5
- package/dist/js/listbox/index.mjs +56 -2
- 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 +7 -8
- package/dist/js/listbox/state.listbox.mjs +1 -1
- package/dist/js/{listbox.data-BWd0PCy7.mjs → listbox.data-DQ7-x2uY.mjs} +8 -7
- package/dist/js/{listbox.model-CRReGOmu.d.mts → listbox.model-BHPA7GM4.d.mts} +3 -3
- package/dist/js/menu.mjs +1 -1
- package/dist/js/{misc.listbox-BI-XsTOf.mjs → misc.listbox-DKB-j0UK.mjs} +4 -5
- package/dist/js/{misc.listbox-gnoJhrTr.d.mts → misc.listbox-mZMuYOxg.d.mts} +1 -1
- package/dist/js/movable/movable.embedded.d.mts +1 -1
- package/dist/js/movable/movable.standalone.d.mts +1 -1
- package/dist/js/popover.d.mts +2 -2
- package/dist/js/popover.mjs +1 -1
- package/dist/js/resizable/resizable.embedded.d.mts +1 -1
- package/dist/js/resizable/resizable.embedded.mjs +1 -1
- package/dist/js/resizable/resizable.standalone.d.mts +1 -1
- package/dist/js/{resizable.embedded-3qoR0Bjm.d.mts → resizable.embedded-dvhdfQgt.d.mts} +1 -1
- package/dist/js/sortable/sortable.embedded.d.mts +1 -1
- package/dist/js/sortable/sortable.standalone.d.mts +1 -1
- package/dist/js/splitter.d.mts +2 -3
- package/dist/js/splitter.mjs +2 -2
- package/dist/js/{state.combobox-4xq0FPCF.mjs → state.combobox-BWDFHwoi.mjs} +9 -9
- package/dist/js/tabs.d.mts +4 -5
- package/dist/js/tabs.mjs +4 -7
- package/dist/js/tooltip.d.mts +1 -1
- package/package.json +24 -22
- package/dist/js/constants.combobox-DmRAMC64.d.mts +0 -26
- package/dist/js/constants.listbox-DRsXUxd3.d.mts +0 -14
- package/src/css/a11y.scss +0 -13
- package/src/css/badge.scss +0 -62
- package/src/css/button.scss +0 -50
- package/src/css/color.scss +0 -115
- package/src/css/combobox.scss +0 -252
- package/src/css/content.scss +0 -180
- package/src/css/flex.scss +0 -107
- package/src/css/floatable.scss +0 -152
- package/src/css/form.scss +0 -573
- package/src/css/listbox.scss +0 -120
- package/src/css/message.scss +0 -73
- package/src/css/mixins.scss +0 -419
- package/src/css/reset.scss +0 -392
- package/src/css/splitter.scss +0 -89
- package/src/css/table.scss +0 -107
- package/src/css/tabs.scss +0 -85
- package/src/js/combobox/constants.combobox.ts +0 -83
- package/src/js/combobox/dom.combobox.ts +0 -407
- package/src/js/combobox/event.combobox.ts +0 -365
- package/src/js/combobox/index.ts +0 -320
- package/src/js/combobox/misc.combobox.ts +0 -104
- package/src/js/combobox/models.combobox.ts +0 -54
- package/src/js/combobox/state.combobox.ts +0 -246
- package/src/js/dialog.ts +0 -255
- package/src/js/floatable/floatable.embedded.ts +0 -332
- package/src/js/floatable/floatable.standalone.ts +0 -6
- package/src/js/focus-trap/focus-trap.embedded.ts +0 -411
- package/src/js/focus-trap/focus-trap.standalone.ts +0 -1
- package/src/js/index.ts +0 -15
- package/src/js/internal/attributable.ts +0 -73
- package/src/js/internal/draggable.ts +0 -657
- package/src/js/internal/listbox/listbox.constants.ts +0 -25
- package/src/js/internal/listbox/listbox.data.ts +0 -287
- package/src/js/internal/listbox/listbox.dom.ts +0 -445
- package/src/js/internal/listbox/listbox.event.ts +0 -129
- package/src/js/internal/listbox/listbox.form.ts +0 -115
- package/src/js/internal/listbox/listbox.misc.ts +0 -135
- package/src/js/internal/listbox/listbox.model.ts +0 -169
- package/src/js/internal/listbox/listbox.state.ts +0 -82
- package/src/js/internal/misc.ts +0 -27
- package/src/js/internal/navigable.ts +0 -315
- package/src/js/l10n.ts +0 -192
- package/src/js/listbox/constants.listbox.ts +0 -61
- package/src/js/listbox/event.listbox.ts +0 -106
- package/src/js/listbox/index.ts +0 -302
- package/src/js/listbox/misc.listbox.ts +0 -70
- package/src/js/listbox/state.listbox.ts +0 -196
- package/src/js/menu.ts +0 -348
- package/src/js/movable/movable.embedded.ts +0 -318
- package/src/js/movable/movable.standalone.ts +0 -2
- package/src/js/popover.ts +0 -229
- package/src/js/resizable/resizable.embedded.ts +0 -413
- package/src/js/resizable/resizable.standalone.ts +0 -5
- package/src/js/sortable/sortable.embedded.ts +0 -527
- package/src/js/sortable/sortable.standalone.ts +0 -2
- package/src/js/splitter.ts +0 -583
- package/src/js/tabs.ts +0 -447
- package/src/js/toolbar.ts +0 -63
- package/src/js/tooltip.ts +0 -367
- /package/dist/css/{mixins.css → mixins/input.mixins.css} +0 -0
package/src/js/popover.ts
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import {getAria, setAria} from '@oscarpalmer/toretto/aria';
|
|
2
|
-
import {setAttribute} from '@oscarpalmer/toretto/attribute';
|
|
3
|
-
import {on} from '@oscarpalmer/toretto/event';
|
|
4
|
-
import {isHTMLOrSVGElement} from '@oscarpalmer/toretto/is';
|
|
5
|
-
import type {RemovableEventListener} from '@oscarpalmer/toretto/models';
|
|
6
|
-
import {
|
|
7
|
-
ATTRIBUTE_FLOATABLE,
|
|
8
|
-
createEmbeddedFloatable,
|
|
9
|
-
getOnBeforeToggleListener,
|
|
10
|
-
type OuiFloatable,
|
|
11
|
-
type OuiFloatableOptions,
|
|
12
|
-
} from './floatable/floatable.embedded';
|
|
13
|
-
import {createFocusTrap, type OuiFocusTrap} from './focus-trap/focus-trap.embedded';
|
|
14
|
-
import {attributable} from './internal/attributable';
|
|
15
|
-
|
|
16
|
-
// #region Types
|
|
17
|
-
|
|
18
|
-
class OuiPopover {
|
|
19
|
-
readonly #state: OuiPopoverState;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Is the popover open?
|
|
23
|
-
*/
|
|
24
|
-
get open(): boolean {
|
|
25
|
-
return this.#state.content.checkVisibility();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
set open(value: boolean) {
|
|
29
|
-
if (value === true) {
|
|
30
|
-
this.show();
|
|
31
|
-
} else if (value === false) {
|
|
32
|
-
this.hide();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
constructor(state: OuiPopoverState) {
|
|
37
|
-
this.#state = state;
|
|
38
|
-
|
|
39
|
-
initialize(state);
|
|
40
|
-
|
|
41
|
-
this.#state.floatable.update();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Closes the popover
|
|
46
|
-
*/
|
|
47
|
-
hide(): void {
|
|
48
|
-
this.#state.floatable.hide();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Opens the popover
|
|
53
|
-
*/
|
|
54
|
-
show(): void {
|
|
55
|
-
this.#state.floatable.show();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
type OuiPopoverState = {
|
|
60
|
-
anchor: HTMLElement;
|
|
61
|
-
content: HTMLElement;
|
|
62
|
-
floatable: OuiFloatable;
|
|
63
|
-
focusTrap?: OuiFocusTrap;
|
|
64
|
-
listeners: RemovableEventListener[];
|
|
65
|
-
popover: OuiPopover;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// #endregion
|
|
69
|
-
|
|
70
|
-
// #region Functions
|
|
71
|
-
|
|
72
|
-
function addPopover(element: HTMLElement): void {
|
|
73
|
-
if (states.has(element) || element.hasAttribute(ATTRIBUTE_FLOATABLE)) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const anchor = element.ownerDocument.querySelector(`[popovertarget="${element.id}"]`);
|
|
78
|
-
|
|
79
|
-
if (isHTMLOrSVGElement(anchor)) {
|
|
80
|
-
states.set(element, getState(anchor, element));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function destroyPopover(state: OuiPopoverState): void {
|
|
85
|
-
state.floatable.destroy();
|
|
86
|
-
state.focusTrap?.destroy();
|
|
87
|
-
|
|
88
|
-
for (const listener of state.listeners) {
|
|
89
|
-
listener();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
state.anchor = undefined as never;
|
|
93
|
-
state.content = undefined as never;
|
|
94
|
-
state.floatable = undefined as never;
|
|
95
|
-
state.focusTrap = undefined as never;
|
|
96
|
-
state.listeners = undefined as never;
|
|
97
|
-
state.popover = undefined as never;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function getId(element: HTMLElement, value?: string): string {
|
|
101
|
-
let {id} = element;
|
|
102
|
-
|
|
103
|
-
if (id == null || id.trim().length === 0) {
|
|
104
|
-
id = value == null ? `oui_popover_${++index}` : `${value}_toggle`;
|
|
105
|
-
|
|
106
|
-
element.id = id;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return id;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Get the _OuiPopover_ for an element
|
|
114
|
-
*
|
|
115
|
-
* @param element Element to get _OuiPopover_ for
|
|
116
|
-
* @returns _OuiPopover_ instance
|
|
117
|
-
*/
|
|
118
|
-
function getPopover(element: HTMLElement): OuiPopover | undefined {
|
|
119
|
-
return states.get(element)?.popover;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function getState(anchor: HTMLElement, content: HTMLElement): OuiPopoverState {
|
|
123
|
-
const state: OuiPopoverState = {
|
|
124
|
-
anchor,
|
|
125
|
-
content,
|
|
126
|
-
floatable: createEmbeddedFloatable(anchor, content, options),
|
|
127
|
-
focusTrap:
|
|
128
|
-
getAria(content, 'modal') === 'true'
|
|
129
|
-
? createFocusTrap(content, {
|
|
130
|
-
noescape: true,
|
|
131
|
-
})
|
|
132
|
-
: undefined,
|
|
133
|
-
listeners: [
|
|
134
|
-
getOnBeforeToggleListener(content),
|
|
135
|
-
on(content, 'toggle', event => {
|
|
136
|
-
const expanded = event.newState === 'open';
|
|
137
|
-
|
|
138
|
-
if (expanded) {
|
|
139
|
-
ignoreFocus = false;
|
|
140
|
-
|
|
141
|
-
state.floatable?.update();
|
|
142
|
-
|
|
143
|
-
content.focus();
|
|
144
|
-
} else {
|
|
145
|
-
if (!ignoreFocus) {
|
|
146
|
-
anchor?.focus();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
setAria(anchor, 'expanded', expanded);
|
|
151
|
-
setAttribute(content, ATTRIBUTE_OPEN, expanded ? '' : undefined);
|
|
152
|
-
}),
|
|
153
|
-
],
|
|
154
|
-
popover: undefined as never,
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
state.popover = new OuiPopover(state);
|
|
158
|
-
|
|
159
|
-
return state;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function initialize(state: OuiPopoverState): void {
|
|
163
|
-
const id = getId(state.content);
|
|
164
|
-
|
|
165
|
-
setAria(state.anchor, {
|
|
166
|
-
controls: id,
|
|
167
|
-
expanded: 'false',
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
const label = getAria(state.content, 'label') ?? getAria(state.content, 'labelledby');
|
|
171
|
-
|
|
172
|
-
if (label == null) {
|
|
173
|
-
setAria(state.content, 'labelledby', getId(state.anchor, id));
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function onPointerdown(): void {
|
|
178
|
-
ignoreFocus = true;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function removePopover(element: HTMLElement): void {
|
|
182
|
-
const state = states.get(element);
|
|
183
|
-
|
|
184
|
-
if (state == null) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
destroyPopover(state);
|
|
189
|
-
|
|
190
|
-
states.delete(element);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// #endregion
|
|
194
|
-
|
|
195
|
-
// #region Variables
|
|
196
|
-
|
|
197
|
-
const ATTRIBUTE = 'oui-popover';
|
|
198
|
-
|
|
199
|
-
const ATTRIBUTE_OPEN = `${ATTRIBUTE}-open`;
|
|
200
|
-
|
|
201
|
-
const options: OuiFloatableOptions = {
|
|
202
|
-
attribute: `${ATTRIBUTE}-position`,
|
|
203
|
-
position: 'below-start',
|
|
204
|
-
reusable: false,
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
const states = new WeakMap<HTMLElement, OuiPopoverState>();
|
|
208
|
-
|
|
209
|
-
let ignoreFocus = false;
|
|
210
|
-
|
|
211
|
-
let index = 0;
|
|
212
|
-
|
|
213
|
-
// #endregion
|
|
214
|
-
|
|
215
|
-
// #region Initialization
|
|
216
|
-
|
|
217
|
-
on(document, 'pointerdown', onPointerdown, {
|
|
218
|
-
capture: true,
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
attributable(ATTRIBUTE, addPopover, removePopover);
|
|
222
|
-
|
|
223
|
-
// #endregion
|
|
224
|
-
|
|
225
|
-
// #region Exports
|
|
226
|
-
|
|
227
|
-
export {getPopover, type OuiPopover};
|
|
228
|
-
|
|
229
|
-
// #endregion
|
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
import {isPlainObject} from '@oscarpalmer/atoms/is';
|
|
2
|
-
import type {EventPosition} from '@oscarpalmer/atoms/models';
|
|
3
|
-
import {getNumber} from '@oscarpalmer/atoms/number';
|
|
4
|
-
import {getAttribute, setAttribute} from '@oscarpalmer/toretto/attribute';
|
|
5
|
-
import {dispatch, getEventPosition, on} from '@oscarpalmer/toretto/event';
|
|
6
|
-
import {findAncestor} from '@oscarpalmer/toretto/find';
|
|
7
|
-
import {isHTMLOrSVGElement} from '@oscarpalmer/toretto/is';
|
|
8
|
-
import {setStyles, toggleStyles, type StyleToggler} from '@oscarpalmer/toretto/style';
|
|
9
|
-
import supportsTouch from '@oscarpalmer/toretto/touch';
|
|
10
|
-
import {attributable} from '../internal/attributable';
|
|
11
|
-
|
|
12
|
-
// #region Types
|
|
13
|
-
|
|
14
|
-
export type CreateOuiResizableOptions = {
|
|
15
|
-
maximumHeight?: number;
|
|
16
|
-
maximumWidth?: number;
|
|
17
|
-
minimumHeight?: number;
|
|
18
|
-
minimumWidth?: number;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export class OuiResizable {
|
|
22
|
-
readonly #state: OuiResizableState;
|
|
23
|
-
|
|
24
|
-
constructor(state: OuiResizableState) {
|
|
25
|
-
this.#state = state;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
destroy(): void {
|
|
29
|
-
destroyResizable(this.#state);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
set(): void {
|
|
33
|
-
const [width, height] = getAndSetDimensions(this.#state.element, this.#state.options);
|
|
34
|
-
|
|
35
|
-
this.#state.width = width;
|
|
36
|
-
this.#state.height = height;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
reset(): void {
|
|
40
|
-
setStyles(this.#state.element, {
|
|
41
|
-
height: '',
|
|
42
|
-
width: '',
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
type OuiResizableItem = {
|
|
48
|
-
instance: OuiResizable;
|
|
49
|
-
state: OuiResizableState;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
type OuiResizableState = {
|
|
53
|
-
element: HTMLElement;
|
|
54
|
-
handle: HTMLElement;
|
|
55
|
-
height: number;
|
|
56
|
-
options: Required<CreateOuiResizableOptions>;
|
|
57
|
-
styles: StyleToggler;
|
|
58
|
-
width: number;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// #endregion
|
|
62
|
-
|
|
63
|
-
// #region Functions
|
|
64
|
-
|
|
65
|
-
function addResizable(
|
|
66
|
-
element: HTMLElement,
|
|
67
|
-
options?: CreateOuiResizableOptions,
|
|
68
|
-
): OuiResizable | undefined {
|
|
69
|
-
let item = items.get(element);
|
|
70
|
-
|
|
71
|
-
if (item == null) {
|
|
72
|
-
const handle = element.querySelector(SELECTOR_HANDLE_SCOPED);
|
|
73
|
-
|
|
74
|
-
if (!isHTMLOrSVGElement(handle)) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const state = getState(element, handle, options);
|
|
79
|
-
const instance = new OuiResizable(state);
|
|
80
|
-
|
|
81
|
-
item = {
|
|
82
|
-
instance,
|
|
83
|
-
state,
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
items.set(element, item);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return item?.instance;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function cancelResize(item?: OuiResizableItem): void {
|
|
93
|
-
if (item == null) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
setStyles(item.state.element, {
|
|
98
|
-
height: `${item.state.height}px`,
|
|
99
|
-
width: `${item.state.width}px`,
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
resetResizable();
|
|
103
|
-
|
|
104
|
-
dispatch(item.state.element, 'oui:resizable:cancel');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Creates _(or retrieves)_ a _OuiResizable_ instance for an element
|
|
109
|
-
*
|
|
110
|
-
* @param element Element to make resizable
|
|
111
|
-
* @returns _OuiResizable_ instance
|
|
112
|
-
*/
|
|
113
|
-
export function createResizable(
|
|
114
|
-
element: HTMLElement,
|
|
115
|
-
options?: CreateOuiResizableOptions,
|
|
116
|
-
): OuiResizable {
|
|
117
|
-
if (!isHTMLOrSVGElement(element)) {
|
|
118
|
-
throw new TypeError(MESSAGE_ELEMENT);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (!isHTMLOrSVGElement(element.querySelector(SELECTOR_HANDLE_SCOPED))) {
|
|
122
|
-
throw new Error(MESSAGE_HANDLE);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return addResizable(element, options ?? {})!;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function destroyResizable(state: OuiResizableState): void {
|
|
129
|
-
state.element = undefined as never;
|
|
130
|
-
state.handle = undefined as never;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function getAndSetDimensions(
|
|
134
|
-
element: HTMLElement,
|
|
135
|
-
options: Required<CreateOuiResizableOptions>,
|
|
136
|
-
input?: Pick<DOMRect, 'height' | 'width'>,
|
|
137
|
-
): [number, number] {
|
|
138
|
-
let {height, width} = input ?? element.getBoundingClientRect();
|
|
139
|
-
|
|
140
|
-
if (options.maximumWidth > -1 && width > options.maximumWidth) {
|
|
141
|
-
width = options.maximumWidth;
|
|
142
|
-
} else if (options.minimumWidth > -1 && width < options.minimumWidth) {
|
|
143
|
-
width = options.minimumWidth;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (options.maximumHeight > -1 && height > options.maximumHeight) {
|
|
147
|
-
height = options.maximumHeight;
|
|
148
|
-
} else if (options.minimumHeight > -1 && height < options.minimumHeight) {
|
|
149
|
-
height = options.minimumHeight;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (element.checkVisibility()) {
|
|
153
|
-
setStyles(element, {
|
|
154
|
-
height: `${height}px`,
|
|
155
|
-
width: `${width}px`,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return [width, height];
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function getProperties(
|
|
163
|
-
element: HTMLElement,
|
|
164
|
-
widthProperty: 'maxWidth' | 'minWidth',
|
|
165
|
-
heightProperty: 'maxHeight' | 'minHeight',
|
|
166
|
-
): [string, string] {
|
|
167
|
-
const computed = getComputedStyle(element);
|
|
168
|
-
|
|
169
|
-
return [computed[widthProperty], computed[heightProperty]];
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function getRestrictions(
|
|
173
|
-
maximum: string | [unknown, unknown],
|
|
174
|
-
minimum: string | [unknown, unknown],
|
|
175
|
-
): Required<CreateOuiResizableOptions> {
|
|
176
|
-
const [maximumWidth, maximumHeight] = getXAndY.apply(
|
|
177
|
-
null,
|
|
178
|
-
typeof maximum === 'string' ? [maximum] : maximum,
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
const [minimumWidth, minimumHeight] = getXAndY.apply(
|
|
182
|
-
null,
|
|
183
|
-
typeof minimum === 'string' ? [minimum] : minimum,
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
if (maximumWidth > -1 && minimumWidth > -1 && maximumWidth <= minimumWidth) {
|
|
187
|
-
throw new Error(MESSAGE_WIDTH);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (maximumHeight > -1 && minimumHeight > -1 && maximumHeight <= minimumHeight) {
|
|
191
|
-
throw new Error(MESSAGE_HEIGHT);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return {
|
|
195
|
-
maximumHeight,
|
|
196
|
-
maximumWidth,
|
|
197
|
-
minimumHeight,
|
|
198
|
-
minimumWidth,
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function getState(
|
|
203
|
-
element: HTMLElement,
|
|
204
|
-
handle: HTMLElement,
|
|
205
|
-
input?: CreateOuiResizableOptions,
|
|
206
|
-
): OuiResizableState {
|
|
207
|
-
setAttribute(element, RESIZABLE_ATTRIBUTE, '');
|
|
208
|
-
|
|
209
|
-
const options = getValidOptions(element, input);
|
|
210
|
-
|
|
211
|
-
const [width, height] = getAndSetDimensions(element, options);
|
|
212
|
-
|
|
213
|
-
return {
|
|
214
|
-
element,
|
|
215
|
-
handle,
|
|
216
|
-
height,
|
|
217
|
-
options,
|
|
218
|
-
width,
|
|
219
|
-
styles: toggleStyles(element, styles),
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function getValidOptions(
|
|
224
|
-
element: HTMLElement,
|
|
225
|
-
input?: CreateOuiResizableOptions,
|
|
226
|
-
): Required<CreateOuiResizableOptions> {
|
|
227
|
-
const original = isPlainObject(input) ? input : {};
|
|
228
|
-
|
|
229
|
-
return {
|
|
230
|
-
...getRestrictions(
|
|
231
|
-
input == null
|
|
232
|
-
? (getAttribute(element, ATTRIBUTE_MAXIMUM) ??
|
|
233
|
-
getProperties(element, 'maxWidth', 'maxHeight'))
|
|
234
|
-
: [original.maximumWidth, original.maximumHeight],
|
|
235
|
-
input == null
|
|
236
|
-
? (getAttribute(element, ATTRIBUTE_MINIMUM) ??
|
|
237
|
-
getProperties(element, 'minWidth', 'minHeight'))
|
|
238
|
-
: [original.minimumWidth, original.minimumHeight],
|
|
239
|
-
),
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function getXAndY(first: unknown, second?: unknown): [number, number] {
|
|
244
|
-
const [x, y] = typeof first === 'string' && second == null ? first.split(',') : [first, second];
|
|
245
|
-
|
|
246
|
-
let xAsNumber = typeof x === 'string' ? Number.parseFloat(x) : getNumber(x);
|
|
247
|
-
let yAsNumber = typeof y === 'string' ? Number.parseFloat(y) : getNumber(y);
|
|
248
|
-
|
|
249
|
-
if (Number.isNaN(xAsNumber) || xAsNumber <= 0) {
|
|
250
|
-
xAsNumber = -1;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (Number.isNaN(yAsNumber) || yAsNumber <= 0) {
|
|
254
|
-
yAsNumber = -1;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return [xAsNumber, yAsNumber];
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function onKeydown(event: KeyboardEvent): void {
|
|
261
|
-
if (current != null && event.key === 'Escape') {
|
|
262
|
-
cancelResize(current);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function onPointerdown(event: MouseEvent | TouchEvent): void {
|
|
267
|
-
if (
|
|
268
|
-
event.altKey ||
|
|
269
|
-
event.ctrlKey ||
|
|
270
|
-
event.metaKey ||
|
|
271
|
-
event.shiftKey ||
|
|
272
|
-
(supportsTouch.value
|
|
273
|
-
? event.type === 'mousedown'
|
|
274
|
-
: event.type === 'touchstart' || (event as MouseEvent).button !== 0)
|
|
275
|
-
) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
const handle = findAncestor(event, SELECTOR_HANDLE);
|
|
280
|
-
const element = handle && findAncestor(handle, SELECTOR);
|
|
281
|
-
const stored = element && items.get(element as HTMLElement);
|
|
282
|
-
const position = getEventPosition(event);
|
|
283
|
-
|
|
284
|
-
if (stored == null || position == null) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (supportsTouch.value) {
|
|
289
|
-
event.preventDefault();
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
if (dispatch(element!, 'oui:resizable:begin').defaultPrevented) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
current = stored;
|
|
297
|
-
start = position;
|
|
298
|
-
|
|
299
|
-
current.state.styles.set();
|
|
300
|
-
styleToggler.set();
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
function onPointermove(event: MouseEvent | TouchEvent): void {
|
|
304
|
-
if (current == null) {
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const {x, y} = getEventPosition(event) ?? {};
|
|
309
|
-
|
|
310
|
-
if (x == null || y == null) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const width = current.state.width + (x - (start?.x ?? 0));
|
|
315
|
-
const height = current.state.height + (y - (start?.y ?? 0));
|
|
316
|
-
|
|
317
|
-
getAndSetDimensions(current.state.element, current.state.options, {height, width});
|
|
318
|
-
|
|
319
|
-
if (
|
|
320
|
-
dispatch(current.state.element, 'oui:resizable:resize', {
|
|
321
|
-
detail: {
|
|
322
|
-
height,
|
|
323
|
-
width,
|
|
324
|
-
},
|
|
325
|
-
}).defaultPrevented
|
|
326
|
-
) {
|
|
327
|
-
cancelResize(current);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function onPointerup(): void {
|
|
332
|
-
if (current == null || dispatch(current.state.element, 'oui:resizable:end').defaultPrevented) {
|
|
333
|
-
cancelResize(current);
|
|
334
|
-
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
const {height, width} = current.state.element.getBoundingClientRect();
|
|
339
|
-
|
|
340
|
-
current.state.height = height;
|
|
341
|
-
current.state.width = width;
|
|
342
|
-
|
|
343
|
-
resetResizable();
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
function removeResizable(element: HTMLElement): void {
|
|
347
|
-
items.get(element)?.instance.destroy();
|
|
348
|
-
|
|
349
|
-
items.delete(element);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
function resetResizable(): void {
|
|
353
|
-
current?.state.styles.remove();
|
|
354
|
-
styleToggler.remove();
|
|
355
|
-
|
|
356
|
-
current = undefined;
|
|
357
|
-
start = undefined;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// #endregion
|
|
361
|
-
|
|
362
|
-
// #region Variables
|
|
363
|
-
|
|
364
|
-
export const RESIZABLE_ATTRIBUTE = 'oui-resizable';
|
|
365
|
-
|
|
366
|
-
export const RESIZABLE_ATTRIBUTE_HANDLE = `${RESIZABLE_ATTRIBUTE}-handle`;
|
|
367
|
-
|
|
368
|
-
const ATTRIBUTE_MAXIMUM = `${RESIZABLE_ATTRIBUTE}-maximum`;
|
|
369
|
-
|
|
370
|
-
const ATTRIBUTE_MINIMUM = `${RESIZABLE_ATTRIBUTE}-minimum`;
|
|
371
|
-
|
|
372
|
-
const MESSAGE_ELEMENT = 'The element must be an instance of HTMLElement or SVGElement';
|
|
373
|
-
|
|
374
|
-
const MESSAGE_HEIGHT = 'The maximum height must be greater than the minimum height';
|
|
375
|
-
|
|
376
|
-
const MESSAGE_HANDLE = `The element must contain a child with the attribute "${RESIZABLE_ATTRIBUTE_HANDLE}"`;
|
|
377
|
-
|
|
378
|
-
const MESSAGE_WIDTH = 'The maximum width must be greater than the minimum width';
|
|
379
|
-
|
|
380
|
-
const SELECTOR = `[${RESIZABLE_ATTRIBUTE}]`;
|
|
381
|
-
|
|
382
|
-
const SELECTOR_HANDLE = `[${RESIZABLE_ATTRIBUTE_HANDLE}]`;
|
|
383
|
-
|
|
384
|
-
const SELECTOR_HANDLE_SCOPED = `:scope > ${SELECTOR_HANDLE}`;
|
|
385
|
-
|
|
386
|
-
const items = new WeakMap<HTMLElement, OuiResizableItem>();
|
|
387
|
-
|
|
388
|
-
const styles = {
|
|
389
|
-
touchAction: 'none',
|
|
390
|
-
userSelect: 'none',
|
|
391
|
-
webkitUserSelect: 'none',
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
const styleToggler = toggleStyles(document.body, styles);
|
|
395
|
-
|
|
396
|
-
let current: OuiResizableItem | undefined;
|
|
397
|
-
|
|
398
|
-
let start: EventPosition | undefined;
|
|
399
|
-
|
|
400
|
-
// #endregion
|
|
401
|
-
|
|
402
|
-
// #region Initialization
|
|
403
|
-
|
|
404
|
-
on(document, 'keydown', onKeydown);
|
|
405
|
-
on(document, 'mousedown', onPointerdown);
|
|
406
|
-
on(document, 'pointermove', onPointermove);
|
|
407
|
-
on(document, 'pointerup', onPointerup);
|
|
408
|
-
on(document, 'touchcancel', onPointerup);
|
|
409
|
-
on(document, 'touchstart', onPointerdown, {passive: false});
|
|
410
|
-
|
|
411
|
-
attributable(RESIZABLE_ATTRIBUTE, addResizable, removeResizable);
|
|
412
|
-
|
|
413
|
-
// #endregion
|