@oscarpalmer/oui 0.19.0 → 0.21.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 +0 -1
- package/dist/css/form.css +0 -1
- package/dist/css/popover.css +22 -0
- package/dist/css/reset.css +8 -8
- package/dist/css/table.css +1 -1
- package/dist/css/tooltip.css +43 -0
- package/dist/js/focus-trap/embedded.d.mts +26 -0
- package/dist/js/focus-trap/{embedded.js → embedded.mjs} +11 -9
- package/dist/js/focus-trap/standalone.d.mts +1 -0
- package/dist/js/focus-trap/{standalone.js → standalone.mjs} +5 -2
- package/dist/js/index.d.mts +4 -0
- package/dist/js/index.mjs +7 -0
- package/dist/js/internal/attributable.d.mts +4 -0
- package/dist/js/{attributable.full.js → internal/attributable.mjs} +8 -1
- package/dist/js/internal/draggable.d.mts +2 -0
- package/dist/js/internal/draggable.mjs +212 -0
- package/dist/js/internal/floatable.d.mts +26 -0
- package/dist/js/{floatable.js → internal/floatable.mjs} +73 -50
- package/dist/js/movable-BEo2LbUI.d.mts +101 -0
- package/dist/js/movable.d.mts +2 -0
- package/dist/js/movable.mjs +152 -0
- package/dist/js/popover.d.mts +20 -0
- package/dist/js/{popover.js → popover.mjs} +10 -8
- package/dist/js/sortable.d.mts +2 -0
- package/dist/js/sortable.mjs +243 -0
- package/dist/js/splitter.d.mts +25 -0
- package/dist/js/{splitter.js → splitter.mjs} +62 -60
- package/dist/js/tooltip.d.mts +4 -0
- package/dist/js/{tooltip.js → tooltip.mjs} +22 -20
- package/package.json +66 -69
- package/src/css/mixins.scss +30 -1
- package/src/css/popover.scss +6 -1
- package/src/css/reset.scss +4 -4
- package/src/css/table.scss +1 -1
- package/src/css/tooltip.scss +55 -1
- package/src/js/focus-trap/embedded.ts +4 -10
- package/src/js/focus-trap/standalone.ts +1 -1
- package/src/js/index.ts +3 -1
- package/src/js/{attributable.ts → internal/attributable.ts} +11 -1
- package/src/js/internal/draggable.ts +515 -0
- package/src/js/{floatable.ts → internal/floatable.ts} +141 -63
- package/src/js/movable.ts +260 -0
- package/src/js/popover.ts +1 -1
- package/src/js/sortable.ts +467 -0
- package/src/js/splitter.ts +3 -9
- package/src/js/tooltip.ts +11 -9
- package/dist/js/attributable.js +0 -36
- package/dist/js/floatable.full.js +0 -398
- package/dist/js/focus-trap/embedded.full.js +0 -408
- package/dist/js/focus-trap/standalone.full.js +0 -447
- package/dist/js/index.js +0 -5
- package/dist/js/oui.full.js +0 -1573
- package/dist/js/popover.full.js +0 -760
- package/dist/js/splitter.full.js +0 -769
- package/dist/js/tooltip.full.js +0 -613
- package/types/attributable.d.ts +0 -1
- package/types/floatable.d.ts +0 -24
- package/types/focus-trap/embedded.d.ts +0 -24
- package/types/focus-trap/standalone.d.ts +0 -1
- package/types/index.d.ts +0 -4
- package/types/popover.d.ts +0 -17
- package/types/splitter.d.ts +0 -23
- package/types/tooltip.d.ts +0 -2
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { attributable } from "./internal/attributable.mjs";
|
|
2
|
+
import { Draggable, addDraggable, removeDraggable } from "./internal/draggable.mjs";
|
|
3
|
+
import { getPosition } from "@oscarpalmer/toretto/event";
|
|
4
|
+
import { findAncestor, getElementFromPosition } from "@oscarpalmer/toretto/find";
|
|
5
|
+
import { createElement } from "@oscarpalmer/toretto/create";
|
|
6
|
+
//#region src/js/sortable.ts
|
|
7
|
+
var Sortable = class extends Draggable {
|
|
8
|
+
connections;
|
|
9
|
+
origin;
|
|
10
|
+
get dragged() {
|
|
11
|
+
return getDragPlaceholder();
|
|
12
|
+
}
|
|
13
|
+
constructor(element) {
|
|
14
|
+
super("sort", element, {
|
|
15
|
+
container: {
|
|
16
|
+
attribute: ATTRIBUTE_CONTAINER,
|
|
17
|
+
map: CONTAINERS
|
|
18
|
+
},
|
|
19
|
+
direction: { attribute: ATTRIBUTE_DIRECTION },
|
|
20
|
+
drag: {
|
|
21
|
+
onBegin,
|
|
22
|
+
onCancel,
|
|
23
|
+
onEnd,
|
|
24
|
+
onMove
|
|
25
|
+
},
|
|
26
|
+
position: {
|
|
27
|
+
getOffset: getOffsetPosition,
|
|
28
|
+
getOriginal: getOriginalPosition
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
this.connections = this.element.getAttribute(ATTRIBUTE_CONNECTIONS);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
function afterEnd(insert, from, events, elements, position, valid) {
|
|
35
|
+
elements.origin?.removeAttribute(ATTRIBUTE_ORIGIN);
|
|
36
|
+
from.origin = void 0;
|
|
37
|
+
resetPlaceholders();
|
|
38
|
+
if (!valid || events.some((event) => event.defaultPrevented)) return;
|
|
39
|
+
if (insert !== "insert") {
|
|
40
|
+
elements.target.append(elements.origin);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (position == null) return;
|
|
44
|
+
const { height, top } = elements.target.getBoundingClientRect();
|
|
45
|
+
let insertion;
|
|
46
|
+
if (position.y < top + height / 2) insertion = INSERT_BEFORE;
|
|
47
|
+
else insertion = INSERT_AFTER;
|
|
48
|
+
elements.target?.insertAdjacentElement(insertion, elements.origin);
|
|
49
|
+
document.body.removeAttribute(ATTRIBUTE_ACTIVE);
|
|
50
|
+
}
|
|
51
|
+
function getDragPlaceholder() {
|
|
52
|
+
placeholder.drag.default ??= createElement("div");
|
|
53
|
+
return placeholder.drag.custom ?? placeholder.drag.default;
|
|
54
|
+
}
|
|
55
|
+
function getOffsetPosition(_, draggable, element, position) {
|
|
56
|
+
const rectangle = element.getBoundingClientRect();
|
|
57
|
+
return {
|
|
58
|
+
x: draggable.horizontal ? 0 : position.x - rectangle.left,
|
|
59
|
+
y: draggable.vertical ? 0 : position.y - rectangle.top
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function getOriginalPosition(_, __, position) {
|
|
63
|
+
return position;
|
|
64
|
+
}
|
|
65
|
+
function getPositionPlaceholder(sortable) {
|
|
66
|
+
placeholder.position ??= createElement("div");
|
|
67
|
+
placeholder.position.setAttribute(ATTRIBUTE_PLACEHOLDER_POSITION, "");
|
|
68
|
+
if (sortable.origin != null) placeholder.position.style.setProperty("--placeholder-height", `${sortable.origin.getBoundingClientRect().height}px`);
|
|
69
|
+
return placeholder.position;
|
|
70
|
+
}
|
|
71
|
+
function onBegin(_, state, draggable, element) {
|
|
72
|
+
const sortable = draggable;
|
|
73
|
+
sortable.origin = element;
|
|
74
|
+
setPlaceholder(state, sortable, element);
|
|
75
|
+
element.setAttribute(ATTRIBUTE_ORIGIN, "");
|
|
76
|
+
document.body.setAttribute(ATTRIBUTE_ACTIVE, "");
|
|
77
|
+
}
|
|
78
|
+
function onCancel(_, draggable) {
|
|
79
|
+
const sortable = draggable;
|
|
80
|
+
const { origin } = sortable;
|
|
81
|
+
origin?.removeAttribute(ATTRIBUTE_ORIGIN);
|
|
82
|
+
document.body.removeAttribute(ATTRIBUTE_ACTIVE);
|
|
83
|
+
resetPlaceholders();
|
|
84
|
+
sortable.origin = void 0;
|
|
85
|
+
}
|
|
86
|
+
function onEnd(event, state, draggable, reset) {
|
|
87
|
+
const from = draggable;
|
|
88
|
+
const { origin } = from;
|
|
89
|
+
const position = getPosition(event) ?? {
|
|
90
|
+
x: 0,
|
|
91
|
+
y: 0
|
|
92
|
+
};
|
|
93
|
+
const target = getElementFromPosition(position)[0];
|
|
94
|
+
let element = findAncestor(target, SELECTOR_ITEM);
|
|
95
|
+
if (element?.hasAttribute(ATTRIBUTE_PLACEHOLDER_POSITION)) if (element.getAttribute(ATTRIBUTE_PLACEHOLDER_POSITION) === "after") element = element.previousElementSibling;
|
|
96
|
+
else element = element.nextElementSibling;
|
|
97
|
+
let insert = "insert";
|
|
98
|
+
let to;
|
|
99
|
+
if (element == null) {
|
|
100
|
+
element = findAncestor(target, SELECTOR);
|
|
101
|
+
to = state.instances.get(element)?.sortable;
|
|
102
|
+
insert = element == null ? void 0 : element.children.length === 0 ? "append" : "prepend";
|
|
103
|
+
} else to = state.instances.get(element.parentElement)?.sortable;
|
|
104
|
+
const valid = insert != null && validatePosition(state, from, to, position);
|
|
105
|
+
const options = {
|
|
106
|
+
detail: valid ? {
|
|
107
|
+
from: {
|
|
108
|
+
element: origin,
|
|
109
|
+
position: { ...state.original }
|
|
110
|
+
},
|
|
111
|
+
to: {
|
|
112
|
+
element,
|
|
113
|
+
position: { ...position }
|
|
114
|
+
}
|
|
115
|
+
} : void 0,
|
|
116
|
+
bubbles: false,
|
|
117
|
+
cancelable: true
|
|
118
|
+
};
|
|
119
|
+
const fromEvent = new CustomEvent(EVENT_END, options);
|
|
120
|
+
const toEvent = new CustomEvent(EVENT_END, options);
|
|
121
|
+
from.element.dispatchEvent(fromEvent);
|
|
122
|
+
if (from !== to) to?.element.dispatchEvent(toEvent);
|
|
123
|
+
setTimeout(() => {
|
|
124
|
+
afterEnd(insert, from, [fromEvent, toEvent], {
|
|
125
|
+
origin,
|
|
126
|
+
target: element
|
|
127
|
+
}, position, valid);
|
|
128
|
+
reset();
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function onMove(event, state, draggable, position) {
|
|
132
|
+
const from = draggable;
|
|
133
|
+
const fromElement = from.origin;
|
|
134
|
+
const toElement = findAncestor(event, SELECTOR_ITEM);
|
|
135
|
+
let to;
|
|
136
|
+
if (toElement == null) to = state.instances.get(findAncestor(event, SELECTOR))?.sortable;
|
|
137
|
+
else to = state.instances.get(toElement.parentElement)?.sortable;
|
|
138
|
+
if (!validatePosition(state, from, to, position.original)) return;
|
|
139
|
+
const placeholder = getPositionPlaceholder(from);
|
|
140
|
+
if (toElement != null && toElement !== fromElement) {
|
|
141
|
+
const { height, top } = toElement.getBoundingClientRect();
|
|
142
|
+
let place;
|
|
143
|
+
if (position.calculated.y < top + height / 2) {
|
|
144
|
+
place = "before";
|
|
145
|
+
toElement.insertAdjacentElement(INSERT_BEFORE, placeholder);
|
|
146
|
+
} else {
|
|
147
|
+
place = "after";
|
|
148
|
+
toElement.insertAdjacentElement(INSERT_AFTER, placeholder);
|
|
149
|
+
}
|
|
150
|
+
placeholder.setAttribute(ATTRIBUTE_PLACEHOLDER_POSITION, place);
|
|
151
|
+
} else placeholder.remove();
|
|
152
|
+
return {
|
|
153
|
+
from: {
|
|
154
|
+
element: fromElement,
|
|
155
|
+
position: { ...state.original }
|
|
156
|
+
},
|
|
157
|
+
to: {
|
|
158
|
+
element: toElement,
|
|
159
|
+
position: { ...position.calculated }
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function resetPlaceholders() {
|
|
164
|
+
placeholder.drag.custom?.remove();
|
|
165
|
+
placeholder.drag.default?.remove();
|
|
166
|
+
placeholder.position?.remove();
|
|
167
|
+
placeholder.drag.custom = void 0;
|
|
168
|
+
}
|
|
169
|
+
function setPlaceholder(state, sortable, origin) {
|
|
170
|
+
const element = getDragPlaceholder();
|
|
171
|
+
placeholder.drag.default.innerHTML = "";
|
|
172
|
+
updatePlaceholder(sortable, element);
|
|
173
|
+
const event = new CustomEvent(EVENT_PLACEHOLDER, {
|
|
174
|
+
cancelable: true,
|
|
175
|
+
detail: {
|
|
176
|
+
origin,
|
|
177
|
+
parent: sortable.element,
|
|
178
|
+
placeholder: element,
|
|
179
|
+
create: (value) => {
|
|
180
|
+
if (!(value instanceof HTMLElement)) return;
|
|
181
|
+
placeholder.drag.custom = value;
|
|
182
|
+
updatePlaceholder(sortable, value);
|
|
183
|
+
state.element = {
|
|
184
|
+
rectangle: value.getBoundingClientRect(),
|
|
185
|
+
node: value
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
sortable.element.dispatchEvent(event);
|
|
191
|
+
setTimeout(() => {
|
|
192
|
+
if (!event.defaultPrevented && placeholder.drag.custom == null) placeholder.drag.default?.append(element.cloneNode(true));
|
|
193
|
+
document.body.append(placeholder.drag.custom ?? placeholder.drag.default ?? "");
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function updatePlaceholder(sortable, element) {
|
|
197
|
+
element.style.position = "fixed";
|
|
198
|
+
element.setAttribute(ATTRIBUTE_PLACEHOLDER_DRAG, "");
|
|
199
|
+
if (sortable.horizontal) element.setAttribute(ATTRIBUTE_HORIZONTAL, "");
|
|
200
|
+
else element.removeAttribute(ATTRIBUTE_HORIZONTAL);
|
|
201
|
+
if (sortable.vertical) element.setAttribute(ATTRIBUTE_VERTICAL, "");
|
|
202
|
+
else element.removeAttribute(ATTRIBUTE_VERTICAL);
|
|
203
|
+
}
|
|
204
|
+
function validatePosition(_, from, to, position) {
|
|
205
|
+
let valid = true;
|
|
206
|
+
const rectangle = from.origin?.getBoundingClientRect();
|
|
207
|
+
if (rectangle != null && !from.horizontal) valid = position.x >= rectangle.left && position.x <= rectangle.right;
|
|
208
|
+
if (valid && rectangle != null && !from.vertical) valid = position.y >= rectangle.top && position.y <= rectangle.bottom;
|
|
209
|
+
if (valid && from.connections != null) valid = to?.element.matches(from.connections) ?? true;
|
|
210
|
+
if (valid && to?.connections != null) valid = from.element.matches(to.connections);
|
|
211
|
+
return valid;
|
|
212
|
+
}
|
|
213
|
+
const ATTRIBUTE = "oui-sortable";
|
|
214
|
+
const ATTRIBUTE_ACTIVE = `${ATTRIBUTE}-active`;
|
|
215
|
+
const ATTRIBUTE_CONNECTIONS = `${ATTRIBUTE}-connections`;
|
|
216
|
+
const ATTRIBUTE_CONTAINER = `${ATTRIBUTE}-container`;
|
|
217
|
+
const ATTRIBUTE_DIRECTION = `${ATTRIBUTE}-direction`;
|
|
218
|
+
const ATTRIBUTE_HORIZONTAL = `${ATTRIBUTE}-horizontal`;
|
|
219
|
+
const ATTRIBUTE_ORIGIN = `${ATTRIBUTE}-origin`;
|
|
220
|
+
const ATTRIBUTE_PLACEHOLDER_DRAG = `${ATTRIBUTE}-placeholder-drag`;
|
|
221
|
+
const ATTRIBUTE_PLACEHOLDER_POSITION = `${ATTRIBUTE}-placeholder-position`;
|
|
222
|
+
const ATTRIBUTE_VERTICAL = `${ATTRIBUTE}-vertical`;
|
|
223
|
+
const CONTAINERS = /* @__PURE__ */ new Map();
|
|
224
|
+
const EVENT_END = "sort:end";
|
|
225
|
+
const EVENT_PLACEHOLDER = "sort:placeholder";
|
|
226
|
+
const INSERT_AFTER = "afterend";
|
|
227
|
+
const INSERT_BEFORE = "beforebegin";
|
|
228
|
+
const SELECTOR = `[${ATTRIBUTE}]`;
|
|
229
|
+
const SELECTOR_ITEM = `[${ATTRIBUTE}] > *`;
|
|
230
|
+
const bound = {
|
|
231
|
+
constructor: Sortable,
|
|
232
|
+
property: "sortable"
|
|
233
|
+
};
|
|
234
|
+
const placeholder = {
|
|
235
|
+
drag: {
|
|
236
|
+
custom: void 0,
|
|
237
|
+
default: void 0
|
|
238
|
+
},
|
|
239
|
+
position: void 0
|
|
240
|
+
};
|
|
241
|
+
attributable(ATTRIBUTE, addDraggable.bind(bound), removeDraggable.bind(bound));
|
|
242
|
+
//#endregion
|
|
243
|
+
export { Sortable };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/js/splitter.d.ts
|
|
2
|
+
declare global {
|
|
3
|
+
interface HTMLElementTagNameMap {
|
|
4
|
+
[SELECTOR]: OuiSplitterElement;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
declare class OuiSplitterElement extends HTMLElement {
|
|
8
|
+
#private;
|
|
9
|
+
static readonly observedAttributes: string[];
|
|
10
|
+
get max(): number;
|
|
11
|
+
set max(value: number);
|
|
12
|
+
get min(): number;
|
|
13
|
+
set min(value: number);
|
|
14
|
+
get size(): number;
|
|
15
|
+
set size(value: number);
|
|
16
|
+
get type(): string;
|
|
17
|
+
set type(value: string);
|
|
18
|
+
constructor();
|
|
19
|
+
connectedCallback(): void;
|
|
20
|
+
disconnectedCallback(): void;
|
|
21
|
+
attributeChangedCallback(name: string): void;
|
|
22
|
+
}
|
|
23
|
+
declare const SELECTOR = "oui-splitter";
|
|
24
|
+
//#endregion
|
|
25
|
+
export { OuiSplitterElement };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { clamp } from "@oscarpalmer/atoms/number";
|
|
1
2
|
import { getPosition, on } from "@oscarpalmer/toretto/event";
|
|
2
3
|
import { findAncestor } from "@oscarpalmer/toretto/find";
|
|
3
|
-
import { clamp } from "@oscarpalmer/atoms/number";
|
|
4
|
-
import { isNullableOrWhitespace } from "@oscarpalmer/atoms/is";
|
|
5
|
-
import { round } from "@oscarpalmer/atoms/math";
|
|
6
4
|
import { toggleStyles } from "@oscarpalmer/toretto/style";
|
|
7
5
|
import supportsTouch from "@oscarpalmer/toretto/touch";
|
|
6
|
+
import { isNullableOrWhitespace } from "@oscarpalmer/atoms/is";
|
|
7
|
+
import { round } from "@oscarpalmer/atoms/math";
|
|
8
|
+
//#region src/js/splitter.ts
|
|
8
9
|
var OuiSplitterElement = class extends HTMLElement {
|
|
9
10
|
static observedAttributes = [
|
|
10
11
|
"max",
|
|
@@ -63,7 +64,7 @@ var OuiSplitterElement = class extends HTMLElement {
|
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
};
|
|
66
|
-
|
|
67
|
+
let index = 0;
|
|
67
68
|
var Splitter = class {
|
|
68
69
|
element;
|
|
69
70
|
handle;
|
|
@@ -114,11 +115,11 @@ function createHandle() {
|
|
|
114
115
|
handle.setAttribute(ATTRIBUTE_HANDLE, "");
|
|
115
116
|
return handle;
|
|
116
117
|
}
|
|
117
|
-
function createSeparator(splitter
|
|
118
|
+
function createSeparator(splitter) {
|
|
118
119
|
const separator = document.createElement("div");
|
|
119
120
|
separator.role = "separator";
|
|
120
121
|
separator.tabIndex = 0;
|
|
121
|
-
separator.setAttribute("aria-controls", splitter
|
|
122
|
+
separator.setAttribute("aria-controls", splitter.element.id);
|
|
122
123
|
separator.setAttribute("aria-label", "Resize panels");
|
|
123
124
|
separator.setAttribute(ATTRIBUTE_SEPARATOR, "");
|
|
124
125
|
return separator;
|
|
@@ -126,20 +127,20 @@ function createSeparator(splitter$1) {
|
|
|
126
127
|
function getContained(min, value, max) {
|
|
127
128
|
return round(clamp(value, min, max), VALUE_DECIMALS);
|
|
128
129
|
}
|
|
129
|
-
function getSize(splitter
|
|
130
|
-
const { height, left, top, width } = splitter
|
|
131
|
-
const fraction = (value - (splitter
|
|
132
|
-
return getContained(splitter
|
|
130
|
+
function getSize(splitter, value) {
|
|
131
|
+
const { height, left, top, width } = splitter.rectangle;
|
|
132
|
+
const fraction = (value - (splitter.types.horizontal ? top : left)) / (splitter.types.horizontal ? height : width);
|
|
133
|
+
return getContained(splitter.values.min, fraction, splitter.values.max);
|
|
133
134
|
}
|
|
134
|
-
function getTypes(splitter
|
|
135
|
-
const type = splitter
|
|
135
|
+
function getTypes(splitter, width, height) {
|
|
136
|
+
const type = splitter.element.getAttribute("type")?.trim() ?? "";
|
|
136
137
|
if (type === "horizontal") return {
|
|
137
138
|
auto: false,
|
|
138
139
|
horizontal: true
|
|
139
140
|
};
|
|
140
141
|
if (type === "auto") return {
|
|
141
142
|
auto: true,
|
|
142
|
-
horizontal: (height ?? splitter
|
|
143
|
+
horizontal: (height ?? splitter.rectangle.height) > (width ?? splitter.rectangle.width)
|
|
143
144
|
};
|
|
144
145
|
return {
|
|
145
146
|
auto: false,
|
|
@@ -189,34 +190,34 @@ function onKeydown(event) {
|
|
|
189
190
|
}
|
|
190
191
|
}
|
|
191
192
|
function onNavigate(event) {
|
|
192
|
-
const splitter
|
|
193
|
-
if (splitter
|
|
194
|
-
const { types, values } = splitter
|
|
193
|
+
const splitter = MAPPED_ELEMENTS.get(findAncestor(event, "[oui-splitter-separator]"));
|
|
194
|
+
if (splitter == null) return;
|
|
195
|
+
const { types, values } = splitter;
|
|
195
196
|
if (KEYS_ABSOLUTE.has(event.key)) {
|
|
196
|
-
setSize(splitter
|
|
197
|
+
setSize(splitter, event.key === "End" ? values.max : values.min, true);
|
|
197
198
|
return;
|
|
198
199
|
}
|
|
199
200
|
if (types.horizontal && !KEYS_HORIZONTAL.has(event.key) || !(types.horizontal || KEYS_VERTICAL.has(event.key))) return;
|
|
200
201
|
const offset = KEYS_NEGATIVE.has(event.key) ? -1 : 1;
|
|
201
|
-
setSize(splitter
|
|
202
|
+
setSize(splitter, getContained(values.min, values.now.current + offset * NAVIGATION_MODIFIER, values.max), true);
|
|
202
203
|
}
|
|
203
204
|
function onObservation(entries) {
|
|
204
205
|
if (frame != null) cancelAnimationFrame(frame);
|
|
205
206
|
frame = requestAnimationFrame(() => {
|
|
206
207
|
for (const entry of entries) {
|
|
207
|
-
const splitter
|
|
208
|
-
if (splitter
|
|
209
|
-
splitter
|
|
210
|
-
if (splitter
|
|
211
|
-
else splitter
|
|
212
|
-
setAriaOrientation(splitter
|
|
208
|
+
const splitter = MAPPED_ELEMENTS.get(entry.target);
|
|
209
|
+
if (splitter == null) return;
|
|
210
|
+
splitter.types = getTypes(splitter, entry.contentRect.width, entry.contentRect.height);
|
|
211
|
+
if (splitter.types.horizontal) splitter.element.setAttribute(ATTRIBUTE_HORIZONTAL, "");
|
|
212
|
+
else splitter.element.removeAttribute(ATTRIBUTE_HORIZONTAL);
|
|
213
|
+
setAriaOrientation(splitter);
|
|
213
214
|
}
|
|
214
215
|
frame = void 0;
|
|
215
216
|
});
|
|
216
217
|
}
|
|
217
218
|
function onPointerdown(event) {
|
|
218
|
-
if (event.type === "mousedown"
|
|
219
|
-
splitter = MAPPED_ELEMENTS.get(findAncestor(event
|
|
219
|
+
if (supportsTouch.value ? event.type === "mousedown" : event.type === "touchstart") return;
|
|
220
|
+
splitter = MAPPED_ELEMENTS.get(findAncestor(event, SELECTOR_HANDLE));
|
|
220
221
|
if (splitter == null) return;
|
|
221
222
|
if (supportsTouch.value) event.preventDefault();
|
|
222
223
|
splitter.handle.setAttribute(ATTRIBUTE_ACTIVE, "");
|
|
@@ -235,51 +236,51 @@ function onPointermove(event) {
|
|
|
235
236
|
function onPointerup() {
|
|
236
237
|
if (splitter != null) onEnd(false);
|
|
237
238
|
}
|
|
238
|
-
function setAriaOrientation(splitter
|
|
239
|
-
splitter
|
|
239
|
+
function setAriaOrientation(splitter) {
|
|
240
|
+
splitter.separator.setAttribute("aria-orientation", splitter.types.horizontal ? "horizontal" : "vertical");
|
|
240
241
|
}
|
|
241
|
-
function setAriaValue(splitter
|
|
242
|
-
splitter
|
|
243
|
-
splitter
|
|
244
|
-
splitter
|
|
242
|
+
function setAriaValue(splitter) {
|
|
243
|
+
splitter.separator.setAttribute("aria-valuemax", String(splitter.values.max));
|
|
244
|
+
splitter.separator.setAttribute("aria-valuemin", String(splitter.values.min));
|
|
245
|
+
splitter.separator.setAttribute("aria-valuenow", String(splitter.values.now.current));
|
|
245
246
|
}
|
|
246
|
-
function setSize(splitter
|
|
247
|
-
splitter
|
|
248
|
-
if (previous) splitter
|
|
249
|
-
splitter
|
|
250
|
-
setAriaValue(splitter
|
|
247
|
+
function setSize(splitter, size, previous) {
|
|
248
|
+
splitter.values.now.current = size;
|
|
249
|
+
if (previous) splitter.values.now.previous = size;
|
|
250
|
+
splitter.element.style.setProperty("--oui-splitter-size", `${size}`);
|
|
251
|
+
setAriaValue(splitter);
|
|
251
252
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
253
|
+
const SELECTOR = "oui-splitter";
|
|
254
|
+
const ATTRIBUTE_ACTIVE = `${SELECTOR}-active`;
|
|
255
|
+
const ATTRIBUTE_HANDLE = `${SELECTOR}-handle`;
|
|
256
|
+
const ATTRIBUTE_HORIZONTAL = `${SELECTOR}-horizontal`;
|
|
257
|
+
const ATTRIBUTE_SEPARATOR = `${SELECTOR}-separator`;
|
|
258
|
+
const KEYS_ABSOLUTE = new Set(["End", "Home"]);
|
|
259
|
+
const KEYS_HORIZONTAL = new Set(["ArrowDown", "ArrowUp"]);
|
|
260
|
+
const KEYS_NEGATIVE = new Set(["ArrowLeft", "ArrowUp"]);
|
|
261
|
+
const KEYS_VERTICAL = new Set(["ArrowLeft", "ArrowRight"]);
|
|
262
|
+
const KEYS_ALL = new Set([
|
|
262
263
|
...KEYS_ABSOLUTE,
|
|
263
264
|
...KEYS_HORIZONTAL,
|
|
264
265
|
...KEYS_VERTICAL
|
|
265
266
|
]);
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
267
|
+
const MAPPED_ELEMENTS = /* @__PURE__ */ new WeakMap();
|
|
268
|
+
const METHODS_CONNECT = ["delete", "set"];
|
|
269
|
+
const METHODS_OBSERVE = ["unobserve", "observe"];
|
|
270
|
+
const NAVIGATION_MAXIMUM_PERCENTAGE = .9;
|
|
271
|
+
const NAVIGATION_MAXIMUM_TOTAL = 100;
|
|
272
|
+
const NAVIGATION_MINIMUM_PERCENTAGE = .1;
|
|
273
|
+
const NAVIGATION_MODIFIER = .05;
|
|
274
|
+
const RESIZE_OBSERVER = new ResizeObserver(onObservation);
|
|
275
|
+
const SELECTOR_HANDLE = `[${ATTRIBUTE_HANDLE}]`;
|
|
276
|
+
const STYLING_TOGGLER = toggleStyles(document.body, {
|
|
276
277
|
touchAction: "none",
|
|
277
278
|
userSelect: "none",
|
|
278
279
|
webkitUserSelect: "none"
|
|
279
280
|
});
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
281
|
+
const VALUE_DECIMALS = 6;
|
|
282
|
+
let frame;
|
|
283
|
+
let splitter;
|
|
283
284
|
customElements.define(SELECTOR, OuiSplitterElement);
|
|
284
285
|
on(document, "keydown", onKeydown);
|
|
285
286
|
on(document, "mousedown", onPointerdown);
|
|
@@ -287,4 +288,5 @@ on(document, "pointermove", onPointermove);
|
|
|
287
288
|
on(document, "pointerup", onPointerup);
|
|
288
289
|
on(document, "touchcancel", onPointerup, { passive: false });
|
|
289
290
|
on(document, "touchstart", onPointerdown, { passive: false });
|
|
291
|
+
//#endregion
|
|
290
292
|
export { OuiSplitterElement };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { attributable } from "./attributable.
|
|
2
|
-
import { Floatable } from "./floatable.
|
|
1
|
+
import { attributable } from "./internal/attributable.mjs";
|
|
2
|
+
import { Floatable } from "./internal/floatable.mjs";
|
|
3
3
|
import { on } from "@oscarpalmer/toretto/event";
|
|
4
4
|
import { findAncestor } from "@oscarpalmer/toretto/find";
|
|
5
5
|
import { isNullableOrWhitespace } from "@oscarpalmer/atoms/is";
|
|
6
|
+
//#region src/js/tooltip.ts
|
|
6
7
|
var Tooltip = class {
|
|
7
8
|
attributes;
|
|
8
9
|
floatable;
|
|
@@ -42,11 +43,11 @@ function closeTooltips(next) {
|
|
|
42
43
|
for (const active of tooltips) {
|
|
43
44
|
if (active === next) continue;
|
|
44
45
|
if (active.timer != null) clearTimeout(active.timer);
|
|
45
|
-
active.floatable
|
|
46
|
+
active.floatable?.options.content.removeAttribute("oui-tooltip-content-active");
|
|
46
47
|
requestAnimationFrame(() => {
|
|
47
48
|
active.timer = setTimeout(() => {
|
|
48
49
|
TOOLTIPS_ACTIVE.delete(active);
|
|
49
|
-
active.floatable
|
|
50
|
+
active.floatable?.toggle(false);
|
|
50
51
|
}, delay);
|
|
51
52
|
});
|
|
52
53
|
}
|
|
@@ -114,7 +115,7 @@ function onActivate(event) {
|
|
|
114
115
|
onToggle(event, true);
|
|
115
116
|
}
|
|
116
117
|
function onClick(event) {
|
|
117
|
-
if (findAncestor(event
|
|
118
|
+
if (findAncestor(event, SELECTOR_CONTENT) != null) event.stopPropagation();
|
|
118
119
|
}
|
|
119
120
|
function onDeactivate(event) {
|
|
120
121
|
onToggle(event, false);
|
|
@@ -123,7 +124,7 @@ function onToggle(event, activate) {
|
|
|
123
124
|
if (toggle != null) cancelAnimationFrame(toggle);
|
|
124
125
|
toggle = requestAnimationFrame(() => {
|
|
125
126
|
toggle = void 0;
|
|
126
|
-
const element = findAncestor(event
|
|
127
|
+
const element = findAncestor(event, SELECTOR_FULL);
|
|
127
128
|
const tooltip = TOOLTIPS_ALL.get(element);
|
|
128
129
|
if (TOOLTIPS_ACTIVE.size > 0) closeTooltips(tooltip);
|
|
129
130
|
if (tooltip == null || tooltip.floatable.options.content.hasAttribute("oui-tooltip-content-active") === activate) return;
|
|
@@ -150,25 +151,26 @@ function reset(anchor, attributes) {
|
|
|
150
151
|
if (attributes.ariaDescribedby == null) anchor.removeAttribute("aria-describedby");
|
|
151
152
|
else anchor.setAttribute("aria-describedby", attributes.ariaDescribedby);
|
|
152
153
|
}
|
|
153
|
-
function
|
|
154
|
+
function setTooltipDelay(value) {
|
|
154
155
|
delay = typeof value === "number" && value >= 0 ? value : delay;
|
|
155
156
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
157
|
+
const SELECTOR = "oui-tooltip";
|
|
158
|
+
const ATTRIBUTE_CLASS = `${SELECTOR}-class`;
|
|
159
|
+
const ATTRIBUTE_CONTENT = `${SELECTOR}-content`;
|
|
160
|
+
const ATTRIBUTE_POSITION = `${SELECTOR}-position`;
|
|
161
|
+
const SELECTOR_CONTENT = `[${ATTRIBUTE_CONTENT}]`;
|
|
162
|
+
const SELECTOR_FULL = `[${SELECTOR}], [${ATTRIBUTE_CONTENT}]`;
|
|
163
|
+
const EXPRESSION_WHITESPACE = /\s+/;
|
|
164
|
+
const TOOLTIPS_ACTIVE = /* @__PURE__ */ new Set();
|
|
165
|
+
const TOOLTIPS_ALL = /* @__PURE__ */ new WeakMap();
|
|
166
|
+
let delay = 500;
|
|
167
|
+
let index = 0;
|
|
168
|
+
let toggle;
|
|
168
169
|
attributable(SELECTOR, addTooltip, removeTooltip);
|
|
169
170
|
on(document, "click", onClick, { capture: true });
|
|
170
171
|
on(document, "focusin", onActivate);
|
|
171
172
|
on(document, "focusout", onDeactivate);
|
|
172
173
|
on(document, "mousemove", onActivate);
|
|
173
174
|
on(document, "touchstart", onActivate);
|
|
174
|
-
|
|
175
|
+
//#endregion
|
|
176
|
+
export { setTooltipDelay };
|