@oscarpalmer/oui 0.26.1 → 0.28.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/floatable.css +9 -2
- package/dist/css/message.css +1 -0
- package/dist/css/reset.css +1 -0
- package/dist/js/dialog.d.mts +4 -0
- package/dist/js/dialog.mjs +33 -1
- package/dist/js/draggable-zszaW1qS.d.mts +155 -0
- package/dist/js/floatable/floatable.embedded.d.mts +2 -0
- package/dist/js/floatable/{embedded.mjs → floatable.embedded.mjs} +16 -11
- package/dist/js/floatable/floatable.standalone.d.mts +2 -0
- package/dist/js/floatable/floatable.standalone.mjs +2 -0
- package/dist/js/{embedded-CSOh5njI.d.mts → floatable.embedded-YxGwzgbE.d.mts} +5 -2
- package/dist/js/focus-trap/focus-trap.embedded.d.mts +2 -0
- package/dist/js/focus-trap/{embedded.mjs → focus-trap.embedded.mjs} +17 -15
- package/dist/js/focus-trap/focus-trap.standalone.d.mts +2 -0
- package/dist/js/focus-trap/focus-trap.standalone.mjs +2 -0
- package/dist/js/{embedded-CHK82Uh5.d.mts → focus-trap.embedded-DR8NpZfr.d.mts} +18 -18
- package/dist/js/index.d.mts +5 -3
- package/dist/js/index.mjs +11 -7
- package/dist/js/internal/draggable.d.mts +2 -2
- package/dist/js/internal/draggable.mjs +147 -95
- package/dist/js/movable/movable.embedded.d.mts +2 -0
- package/dist/js/movable/movable.embedded.mjs +184 -0
- package/dist/js/movable/movable.standalone.d.mts +2 -0
- package/dist/js/movable/movable.standalone.mjs +2 -0
- package/dist/js/popover.d.mts +2 -2
- package/dist/js/popover.mjs +4 -3
- package/dist/js/resizable/resizable.embedded.d.mts +2 -0
- package/dist/js/resizable/resizable.embedded.mjs +186 -0
- package/dist/js/resizable/resizable.standalone.d.mts +2 -0
- package/dist/js/resizable/resizable.standalone.mjs +2 -0
- package/dist/js/resizable.embedded-CXrUVPzR.d.mts +35 -0
- package/dist/js/sortable/sortable.embedded.d.mts +2 -0
- package/dist/js/{sortable.mjs → sortable/sortable.embedded.mjs} +88 -63
- package/dist/js/sortable/sortable.standalone.d.mts +2 -0
- package/dist/js/sortable/sortable.standalone.mjs +2 -0
- package/dist/js/splitter.mjs +6 -6
- package/dist/js/toolbar.mjs +6 -6
- package/dist/js/tooltip.d.mts +2 -2
- package/dist/js/tooltip.mjs +36 -33
- package/package.json +15 -11
- package/src/css/floatable.scss +9 -2
- package/src/css/form.scss +6 -6
- package/src/css/message.scss +1 -0
- package/src/css/reset.scss +1 -0
- package/src/js/dialog.ts +61 -1
- package/src/js/floatable/{embedded.ts → floatable.embedded.ts} +18 -10
- package/src/js/floatable/floatable.standalone.ts +6 -0
- package/src/js/focus-trap/{embedded.ts → focus-trap.embedded.ts} +20 -17
- package/src/js/focus-trap/focus-trap.standalone.ts +1 -0
- package/src/js/index.ts +5 -4
- package/src/js/internal/draggable.ts +310 -169
- package/src/js/movable/movable.embedded.ts +328 -0
- package/src/js/movable/movable.standalone.ts +2 -0
- package/src/js/popover.ts +3 -2
- package/src/js/resizable/resizable.embedded.ts +383 -0
- package/src/js/resizable/resizable.standalone.ts +5 -0
- package/src/js/{sortable.ts → sortable/sortable.embedded.ts} +170 -103
- package/src/js/sortable/sortable.standalone.ts +2 -0
- package/src/js/splitter.ts +1 -1
- package/src/js/tooltip.ts +49 -43
- package/dist/js/floatable/embedded.d.mts +0 -2
- package/dist/js/floatable/standalone.d.mts +0 -2
- package/dist/js/floatable/standalone.mjs +0 -2
- package/dist/js/focus-trap/embedded.d.mts +0 -2
- package/dist/js/focus-trap/standalone.d.mts +0 -2
- package/dist/js/focus-trap/standalone.mjs +0 -6
- package/dist/js/movable-dNqBctx3.d.mts +0 -101
- package/dist/js/movable.d.mts +0 -2
- package/dist/js/movable.mjs +0 -152
- package/dist/js/sortable.d.mts +0 -2
- package/src/js/floatable/standalone.ts +0 -1
- package/src/js/focus-trap/standalone.ts +0 -6
- package/src/js/movable.ts +0 -260
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { attributable } from "../internal/attributable.mjs";
|
|
2
|
+
import { getPosition, on } from "@oscarpalmer/toretto/event";
|
|
3
|
+
import { isPlainObject } from "@oscarpalmer/atoms/is";
|
|
4
|
+
import { isHTMLOrSVGElement } from "@oscarpalmer/toretto/is";
|
|
5
|
+
import { getNumber } from "@oscarpalmer/atoms/number";
|
|
6
|
+
import { findAncestor } from "@oscarpalmer/toretto/find";
|
|
7
|
+
import { toggleStyles } from "@oscarpalmer/toretto/style";
|
|
8
|
+
import supportsTouch from "@oscarpalmer/toretto/touch";
|
|
9
|
+
//#region src/js/resizable/resizable.embedded.ts
|
|
10
|
+
var OuiResizable = class {
|
|
11
|
+
#state;
|
|
12
|
+
constructor(state) {
|
|
13
|
+
this.#state = state;
|
|
14
|
+
}
|
|
15
|
+
destroy() {
|
|
16
|
+
destroyResizable(this.#state);
|
|
17
|
+
}
|
|
18
|
+
set() {
|
|
19
|
+
const [width, height] = getAndSetDimensions(this.#state.element, this.#state.options);
|
|
20
|
+
console.log("set", width, height);
|
|
21
|
+
this.#state.width = width;
|
|
22
|
+
this.#state.height = height;
|
|
23
|
+
}
|
|
24
|
+
reset() {
|
|
25
|
+
this.#state.element.style.height = "";
|
|
26
|
+
this.#state.element.style.width = "";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
function addResizable(element, options) {
|
|
30
|
+
let item = items.get(element);
|
|
31
|
+
if (item == null) {
|
|
32
|
+
const handle = element.querySelector(SELECTOR_HANDLE_SCOPED);
|
|
33
|
+
if (!isHTMLOrSVGElement(handle)) return;
|
|
34
|
+
const state = getState(element, handle, options);
|
|
35
|
+
item = {
|
|
36
|
+
instance: new OuiResizable(state),
|
|
37
|
+
state
|
|
38
|
+
};
|
|
39
|
+
items.set(element, item);
|
|
40
|
+
}
|
|
41
|
+
return item?.instance;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates _(or retrieves)_ a _OuiResizable_ instance for an element
|
|
45
|
+
*
|
|
46
|
+
* @param element Element to make resizable
|
|
47
|
+
* @returns _OuiResizable_ instance
|
|
48
|
+
*/
|
|
49
|
+
function createResizable(element, options) {
|
|
50
|
+
if (!isHTMLOrSVGElement(element)) throw new TypeError(MESSAGE_ELEMENT);
|
|
51
|
+
if (!isHTMLOrSVGElement(element.querySelector(SELECTOR_HANDLE_SCOPED))) throw new Error(MESSAGE_HANDLE);
|
|
52
|
+
return addResizable(element, options ?? {});
|
|
53
|
+
}
|
|
54
|
+
function destroyResizable(state) {
|
|
55
|
+
state.element = void 0;
|
|
56
|
+
state.handle = void 0;
|
|
57
|
+
}
|
|
58
|
+
function getAndSetDimensions(element, options, input) {
|
|
59
|
+
let { height, width } = input ?? element.getBoundingClientRect();
|
|
60
|
+
if (options.maximumWidth > -1 && width > options.maximumWidth) width = options.maximumWidth;
|
|
61
|
+
else if (options.minimumWidth > -1 && width < options.minimumWidth) width = options.minimumWidth;
|
|
62
|
+
if (options.maximumHeight > -1 && height > options.maximumHeight) height = options.maximumHeight;
|
|
63
|
+
else if (options.minimumHeight > -1 && height < options.minimumHeight) height = options.minimumHeight;
|
|
64
|
+
if (element.checkVisibility()) {
|
|
65
|
+
element.style.height = `${height}px`;
|
|
66
|
+
element.style.width = `${width}px`;
|
|
67
|
+
}
|
|
68
|
+
return [width, height];
|
|
69
|
+
}
|
|
70
|
+
function getProperties(element, widthProperty, heightProperty) {
|
|
71
|
+
const computed = getComputedStyle(element);
|
|
72
|
+
return [computed[widthProperty], computed[heightProperty]];
|
|
73
|
+
}
|
|
74
|
+
function getRestrictions(maximum, minimum) {
|
|
75
|
+
const [maximumWidth, maximumHeight] = getXAndY.apply(null, typeof maximum === "string" ? [maximum] : maximum);
|
|
76
|
+
const [minimumWidth, minimumHeight] = getXAndY.apply(null, typeof minimum === "string" ? [minimum] : minimum);
|
|
77
|
+
if (maximumWidth > -1 && minimumWidth > -1 && maximumWidth <= minimumWidth) throw new Error(MESSAGE_WIDTH);
|
|
78
|
+
if (maximumHeight > -1 && minimumHeight > -1 && maximumHeight <= minimumHeight) throw new Error(MESSAGE_HEIGHT);
|
|
79
|
+
return {
|
|
80
|
+
maximumHeight,
|
|
81
|
+
maximumWidth,
|
|
82
|
+
minimumHeight,
|
|
83
|
+
minimumWidth
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function getState(element, handle, input) {
|
|
87
|
+
element.setAttribute(RESIZABLE_ATTRIBUTE, "");
|
|
88
|
+
const options = getValidOptions(element, input);
|
|
89
|
+
const [width, height] = getAndSetDimensions(element, options);
|
|
90
|
+
return {
|
|
91
|
+
element,
|
|
92
|
+
handle,
|
|
93
|
+
height,
|
|
94
|
+
options,
|
|
95
|
+
width,
|
|
96
|
+
styles: toggleStyles(element, styles)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function getValidOptions(element, input) {
|
|
100
|
+
const original = isPlainObject(input) ? input : {};
|
|
101
|
+
return { ...getRestrictions(input == null ? element.getAttribute(ATTRIBUTE_MAXIMUM) ?? getProperties(element, "maxWidth", "maxHeight") : [original.maximumWidth, original.maximumHeight], input == null ? element.getAttribute(ATTRIBUTE_MINIMUM) ?? getProperties(element, "minWidth", "minHeight") : [original.minimumWidth, original.minimumHeight]) };
|
|
102
|
+
}
|
|
103
|
+
function getXAndY(first, second) {
|
|
104
|
+
const [x, y] = typeof first === "string" && second == null ? first.split(",") : [first, second];
|
|
105
|
+
let xAsNumber = typeof x === "string" ? Number.parseFloat(x) : getNumber(x);
|
|
106
|
+
let yAsNumber = typeof y === "string" ? Number.parseFloat(y) : getNumber(y);
|
|
107
|
+
if (Number.isNaN(xAsNumber) || xAsNumber <= 0) xAsNumber = -1;
|
|
108
|
+
if (Number.isNaN(yAsNumber) || yAsNumber <= 0) yAsNumber = -1;
|
|
109
|
+
return [xAsNumber, yAsNumber];
|
|
110
|
+
}
|
|
111
|
+
function onKeydown(event) {
|
|
112
|
+
if (current == null || event.key !== "Escape") return;
|
|
113
|
+
current.state.element.style.height = `${current.state.height}px`;
|
|
114
|
+
current.state.element.style.width = `${current.state.width}px`;
|
|
115
|
+
resetResizable();
|
|
116
|
+
}
|
|
117
|
+
function onPointerdown(event) {
|
|
118
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || (supportsTouch.value ? event.type === "mousedown" : event.type === "touchstart" || event.button !== 0)) return;
|
|
119
|
+
const handle = findAncestor(event, SELECTOR_HANDLE);
|
|
120
|
+
const element = handle && findAncestor(handle, SELECTOR);
|
|
121
|
+
const stored = element && items.get(element);
|
|
122
|
+
const position = getPosition(event);
|
|
123
|
+
if (stored == null || position == null) return;
|
|
124
|
+
if (supportsTouch.value) event.preventDefault();
|
|
125
|
+
current = stored;
|
|
126
|
+
start = position;
|
|
127
|
+
current.state.styles.set();
|
|
128
|
+
styleToggler.set();
|
|
129
|
+
}
|
|
130
|
+
function onPointermove(event) {
|
|
131
|
+
if (current == null) return;
|
|
132
|
+
const { x, y } = getPosition(event) ?? {};
|
|
133
|
+
if (x == null || y == null) return;
|
|
134
|
+
const width = current.state.width + (x - (start?.x ?? 0));
|
|
135
|
+
const height = current.state.height + (y - (start?.y ?? 0));
|
|
136
|
+
getAndSetDimensions(current.state.element, current.state.options, {
|
|
137
|
+
height,
|
|
138
|
+
width
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function onPointerup() {
|
|
142
|
+
if (current == null) return;
|
|
143
|
+
const { height, width } = current.state.element.getBoundingClientRect();
|
|
144
|
+
current.state.height = height;
|
|
145
|
+
current.state.width = width;
|
|
146
|
+
resetResizable();
|
|
147
|
+
}
|
|
148
|
+
function removeResizable(element) {
|
|
149
|
+
items.get(element)?.instance.destroy();
|
|
150
|
+
items.delete(element);
|
|
151
|
+
}
|
|
152
|
+
function resetResizable() {
|
|
153
|
+
current?.state.styles.remove();
|
|
154
|
+
styleToggler.remove();
|
|
155
|
+
current = void 0;
|
|
156
|
+
start = void 0;
|
|
157
|
+
}
|
|
158
|
+
const RESIZABLE_ATTRIBUTE = "oui-resizable";
|
|
159
|
+
const RESIZABLE_ATTRIBUTE_HANDLE = `${RESIZABLE_ATTRIBUTE}-handle`;
|
|
160
|
+
const ATTRIBUTE_MAXIMUM = `${RESIZABLE_ATTRIBUTE}-maximum`;
|
|
161
|
+
const ATTRIBUTE_MINIMUM = `${RESIZABLE_ATTRIBUTE}-minimum`;
|
|
162
|
+
const MESSAGE_ELEMENT = "The element must be an instance of HTMLElement or SVGElement";
|
|
163
|
+
const MESSAGE_HEIGHT = "The maximum height must be greater than the minimum height";
|
|
164
|
+
const MESSAGE_HANDLE = `The element must contain a child with the attribute "${RESIZABLE_ATTRIBUTE_HANDLE}"`;
|
|
165
|
+
const MESSAGE_WIDTH = "The maximum width must be greater than the minimum width";
|
|
166
|
+
const SELECTOR = `[${RESIZABLE_ATTRIBUTE}]`;
|
|
167
|
+
const SELECTOR_HANDLE = `[${RESIZABLE_ATTRIBUTE_HANDLE}]`;
|
|
168
|
+
const SELECTOR_HANDLE_SCOPED = `:scope > ${SELECTOR_HANDLE}`;
|
|
169
|
+
const items = /* @__PURE__ */ new WeakMap();
|
|
170
|
+
const styles = {
|
|
171
|
+
touchAction: "none",
|
|
172
|
+
userSelect: "none",
|
|
173
|
+
webkitUserSelect: "none"
|
|
174
|
+
};
|
|
175
|
+
const styleToggler = toggleStyles(document.body, styles);
|
|
176
|
+
let current;
|
|
177
|
+
let start;
|
|
178
|
+
on(document, "keydown", onKeydown);
|
|
179
|
+
on(document, "mousedown", onPointerdown);
|
|
180
|
+
on(document, "pointermove", onPointermove);
|
|
181
|
+
on(document, "pointerup", onPointerup);
|
|
182
|
+
on(document, "touchcancel", onPointerup);
|
|
183
|
+
on(document, "touchstart", onPointerdown, { passive: false });
|
|
184
|
+
attributable(RESIZABLE_ATTRIBUTE, addResizable, removeResizable);
|
|
185
|
+
//#endregion
|
|
186
|
+
export { OuiResizable, RESIZABLE_ATTRIBUTE, RESIZABLE_ATTRIBUTE_HANDLE, createResizable };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { StyleToggler } from "@oscarpalmer/toretto/style";
|
|
2
|
+
|
|
3
|
+
//#region src/js/resizable/resizable.embedded.d.ts
|
|
4
|
+
type CreateOuiResizableOptions = {
|
|
5
|
+
maximumHeight?: number;
|
|
6
|
+
maximumWidth?: number;
|
|
7
|
+
minimumHeight?: number;
|
|
8
|
+
minimumWidth?: number;
|
|
9
|
+
};
|
|
10
|
+
declare class OuiResizable {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(state: OuiResizableState);
|
|
13
|
+
destroy(): void;
|
|
14
|
+
set(): void;
|
|
15
|
+
reset(): void;
|
|
16
|
+
}
|
|
17
|
+
type OuiResizableState = {
|
|
18
|
+
element: HTMLElement;
|
|
19
|
+
handle: HTMLElement;
|
|
20
|
+
height: number;
|
|
21
|
+
options: Required<CreateOuiResizableOptions>;
|
|
22
|
+
styles: StyleToggler;
|
|
23
|
+
width: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Creates _(or retrieves)_ a _OuiResizable_ instance for an element
|
|
27
|
+
*
|
|
28
|
+
* @param element Element to make resizable
|
|
29
|
+
* @returns _OuiResizable_ instance
|
|
30
|
+
*/
|
|
31
|
+
declare function createResizable(element: HTMLElement, options?: CreateOuiResizableOptions): OuiResizable;
|
|
32
|
+
declare const RESIZABLE_ATTRIBUTE = "oui-resizable";
|
|
33
|
+
declare const RESIZABLE_ATTRIBUTE_HANDLE = "oui-resizable-handle";
|
|
34
|
+
//#endregion
|
|
35
|
+
export { createResizable as a, RESIZABLE_ATTRIBUTE_HANDLE as i, OuiResizable as n, RESIZABLE_ATTRIBUTE as r, CreateOuiResizableOptions as t };
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import { attributable } from "
|
|
2
|
-
import { OuiDraggable, addDraggable, removeDraggable } from "
|
|
1
|
+
import { attributable } from "../internal/attributable.mjs";
|
|
2
|
+
import { OuiDraggable, addDraggable, getDraggableStates, removeDraggable } from "../internal/draggable.mjs";
|
|
3
3
|
import { getPosition } from "@oscarpalmer/toretto/event";
|
|
4
4
|
import { isHTMLOrSVGElement } from "@oscarpalmer/toretto/is";
|
|
5
5
|
import { findAncestor, getElementFromPosition } from "@oscarpalmer/toretto/find";
|
|
6
6
|
import { createElement } from "@oscarpalmer/toretto/create";
|
|
7
|
-
//#region src/js/sortable.ts
|
|
7
|
+
//#region src/js/sortable/sortable.embedded.ts
|
|
8
8
|
var OuiSortable = class extends OuiDraggable {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
get dragged() {
|
|
12
|
-
return getDragPlaceholder();
|
|
13
|
-
}
|
|
14
|
-
constructor(element) {
|
|
15
|
-
super("sort", element, {
|
|
9
|
+
constructor(element, options) {
|
|
10
|
+
super("sortable", "sort", ATTRIBUTE, element, {
|
|
16
11
|
container: {
|
|
17
12
|
attribute: ATTRIBUTE_CONTAINER,
|
|
18
13
|
map: CONTAINERS
|
|
@@ -24,17 +19,19 @@ var OuiSortable = class extends OuiDraggable {
|
|
|
24
19
|
onEnd,
|
|
25
20
|
onMove
|
|
26
21
|
},
|
|
22
|
+
input: options,
|
|
27
23
|
position: {
|
|
28
24
|
getOffset: getOffsetPosition,
|
|
29
25
|
getOriginal: getOriginalPosition
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
},
|
|
27
|
+
getDragged: getDragPlaceholder,
|
|
28
|
+
getOrigin: () => (getDraggableStates(element)?.sortable)?.origin
|
|
29
|
+
}, { connections: element.getAttribute(ATTRIBUTE_CONNECTIONS) });
|
|
33
30
|
}
|
|
34
31
|
};
|
|
35
32
|
function afterEnd(insert, from, events, elements, position, valid) {
|
|
36
33
|
elements.origin?.removeAttribute(ATTRIBUTE_ORIGIN);
|
|
37
|
-
from.origin = void 0;
|
|
34
|
+
from.state.origin = void 0;
|
|
38
35
|
resetPlaceholders();
|
|
39
36
|
if (!valid || events.some((event) => event.defaultPrevented)) return;
|
|
40
37
|
if (insert !== "insert") {
|
|
@@ -49,44 +46,50 @@ function afterEnd(insert, from, events, elements, position, valid) {
|
|
|
49
46
|
elements.target?.insertAdjacentElement(insertion, elements.origin);
|
|
50
47
|
document.body.removeAttribute(ATTRIBUTE_ACTIVE);
|
|
51
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates _(or retrieves)_ a _OuiSortable_ instance for an element
|
|
51
|
+
*
|
|
52
|
+
* @param element Element to make sortable
|
|
53
|
+
* @returns _OuiSortable_ instance
|
|
54
|
+
*/
|
|
55
|
+
function createSortable(element, options) {
|
|
56
|
+
if (!isHTMLOrSVGElement(element)) throw new TypeError(MESSAGE);
|
|
57
|
+
return addSortable(element, options);
|
|
58
|
+
}
|
|
52
59
|
function getDragPlaceholder() {
|
|
53
60
|
placeholder.drag.default ??= createElement("div");
|
|
54
61
|
return placeholder.drag.custom ?? placeholder.drag.default;
|
|
55
62
|
}
|
|
56
|
-
function getOffsetPosition(_,
|
|
63
|
+
function getOffsetPosition(_, item, element, position) {
|
|
57
64
|
const rectangle = element.getBoundingClientRect();
|
|
58
65
|
return {
|
|
59
|
-
x:
|
|
60
|
-
y:
|
|
66
|
+
x: item.state.horizontal ? 0 : position.x - rectangle.left,
|
|
67
|
+
y: item.state.vertical ? 0 : position.y - rectangle.top
|
|
61
68
|
};
|
|
62
69
|
}
|
|
63
70
|
function getOriginalPosition(_, __, position) {
|
|
64
71
|
return position;
|
|
65
72
|
}
|
|
66
|
-
function getPositionPlaceholder(
|
|
73
|
+
function getPositionPlaceholder(item) {
|
|
67
74
|
placeholder.position ??= createElement("div");
|
|
68
75
|
placeholder.position.setAttribute(ATTRIBUTE_PLACEHOLDER_POSITION, "");
|
|
69
|
-
if (
|
|
76
|
+
if (item.state.origin != null) placeholder.position.style.setProperty("--placeholder-height", `${item.state.origin.getBoundingClientRect().height}px`);
|
|
70
77
|
return placeholder.position;
|
|
71
78
|
}
|
|
72
|
-
function onBegin(_,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
setPlaceholder(state, sortable, element);
|
|
79
|
+
function onBegin(_, globals, item, element) {
|
|
80
|
+
item.state.origin = element;
|
|
81
|
+
setPlaceholder(globals, item, element);
|
|
76
82
|
element.setAttribute(ATTRIBUTE_ORIGIN, "");
|
|
77
83
|
document.body.setAttribute(ATTRIBUTE_ACTIVE, "");
|
|
78
84
|
}
|
|
79
|
-
function onCancel(_,
|
|
80
|
-
|
|
81
|
-
const { origin } = sortable;
|
|
82
|
-
origin?.removeAttribute(ATTRIBUTE_ORIGIN);
|
|
85
|
+
function onCancel(_, item) {
|
|
86
|
+
item.state.origin?.removeAttribute(ATTRIBUTE_ORIGIN);
|
|
83
87
|
document.body.removeAttribute(ATTRIBUTE_ACTIVE);
|
|
84
88
|
resetPlaceholders();
|
|
85
|
-
|
|
89
|
+
item.state.origin = void 0;
|
|
86
90
|
}
|
|
87
|
-
function onEnd(event,
|
|
88
|
-
const
|
|
89
|
-
const { origin } = from;
|
|
91
|
+
function onEnd(event, globals, item, reset) {
|
|
92
|
+
const { origin } = item.state;
|
|
90
93
|
const position = getPosition(event) ?? {
|
|
91
94
|
x: 0,
|
|
92
95
|
y: 0
|
|
@@ -96,18 +99,26 @@ function onEnd(event, state, draggable, reset) {
|
|
|
96
99
|
if (element?.hasAttribute(ATTRIBUTE_PLACEHOLDER_POSITION)) if (element.getAttribute(ATTRIBUTE_PLACEHOLDER_POSITION) === "after") element = element.previousElementSibling;
|
|
97
100
|
else element = element.nextElementSibling;
|
|
98
101
|
let insert = "insert";
|
|
99
|
-
let
|
|
102
|
+
let toInstance;
|
|
103
|
+
let toState;
|
|
100
104
|
if (element == null) {
|
|
101
105
|
element = findAncestor(target, SELECTOR);
|
|
102
|
-
|
|
106
|
+
toInstance = globals.instances.get(element)?.sortable;
|
|
107
|
+
toState = globals.states.get(element)?.sortable;
|
|
103
108
|
insert = element == null ? void 0 : element.children.length === 0 ? "append" : "prepend";
|
|
104
|
-
} else
|
|
105
|
-
|
|
109
|
+
} else {
|
|
110
|
+
toInstance = globals.instances.get(element.parentElement)?.sortable;
|
|
111
|
+
toState = globals.states.get(element.parentElement)?.sortable;
|
|
112
|
+
}
|
|
113
|
+
const valid = insert != null && validatePosition(globals, item, {
|
|
114
|
+
instance: toInstance,
|
|
115
|
+
state: toState
|
|
116
|
+
}, position);
|
|
106
117
|
const options = {
|
|
107
118
|
detail: valid ? {
|
|
108
119
|
from: {
|
|
109
120
|
element: origin,
|
|
110
|
-
position: { ...
|
|
121
|
+
position: { ...globals.original }
|
|
111
122
|
},
|
|
112
123
|
to: {
|
|
113
124
|
element,
|
|
@@ -119,25 +130,34 @@ function onEnd(event, state, draggable, reset) {
|
|
|
119
130
|
};
|
|
120
131
|
const fromEvent = new CustomEvent(EVENT_END, options);
|
|
121
132
|
const toEvent = new CustomEvent(EVENT_END, options);
|
|
122
|
-
|
|
123
|
-
if (
|
|
133
|
+
item.instance.element.dispatchEvent(fromEvent);
|
|
134
|
+
if (item.instance !== toInstance) toInstance?.element.dispatchEvent(toEvent);
|
|
124
135
|
setTimeout(() => {
|
|
125
|
-
afterEnd(insert,
|
|
136
|
+
afterEnd(insert, item, [fromEvent, toEvent], {
|
|
126
137
|
origin,
|
|
127
138
|
target: element
|
|
128
139
|
}, position, valid);
|
|
129
140
|
reset();
|
|
130
141
|
});
|
|
131
142
|
}
|
|
132
|
-
function onMove(event,
|
|
133
|
-
const
|
|
134
|
-
const fromElement = from.origin;
|
|
143
|
+
function onMove(event, globals, item, position) {
|
|
144
|
+
const fromElement = item.state.origin;
|
|
135
145
|
const toElement = findAncestor(event, SELECTOR_ITEM);
|
|
136
|
-
let
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
146
|
+
let toInstance;
|
|
147
|
+
let toState;
|
|
148
|
+
if (toElement == null) {
|
|
149
|
+
const element = findAncestor(event, SELECTOR);
|
|
150
|
+
toInstance = globals.instances.get(element)?.sortable;
|
|
151
|
+
toState = globals.states.get(element)?.sortable;
|
|
152
|
+
} else {
|
|
153
|
+
toInstance = globals.instances.get(toElement.parentElement)?.sortable;
|
|
154
|
+
toState = globals.states.get(toElement.parentElement)?.sortable;
|
|
155
|
+
}
|
|
156
|
+
if (toInstance == null || !validatePosition(globals, item, {
|
|
157
|
+
instance: toInstance,
|
|
158
|
+
state: toState
|
|
159
|
+
}, position.original)) return;
|
|
160
|
+
const placeholder = getPositionPlaceholder(item);
|
|
141
161
|
if (toElement != null && toElement !== fromElement) {
|
|
142
162
|
const { height, top } = toElement.getBoundingClientRect();
|
|
143
163
|
let place;
|
|
@@ -153,7 +173,7 @@ function onMove(event, state, draggable, position) {
|
|
|
153
173
|
return {
|
|
154
174
|
from: {
|
|
155
175
|
element: fromElement,
|
|
156
|
-
position: { ...
|
|
176
|
+
position: { ...globals.original }
|
|
157
177
|
},
|
|
158
178
|
to: {
|
|
159
179
|
element: toElement,
|
|
@@ -167,21 +187,21 @@ function resetPlaceholders() {
|
|
|
167
187
|
placeholder.position?.remove();
|
|
168
188
|
placeholder.drag.custom = void 0;
|
|
169
189
|
}
|
|
170
|
-
function setPlaceholder(state,
|
|
190
|
+
function setPlaceholder(state, item, origin) {
|
|
171
191
|
const element = getDragPlaceholder();
|
|
172
192
|
placeholder.drag.default.innerHTML = "";
|
|
173
|
-
updatePlaceholder(
|
|
193
|
+
updatePlaceholder(item, element);
|
|
174
194
|
const event = new CustomEvent(EVENT_PLACEHOLDER, {
|
|
175
195
|
cancelable: true,
|
|
176
196
|
detail: {
|
|
177
197
|
origin,
|
|
178
|
-
parent:
|
|
198
|
+
parent: item.state.element,
|
|
179
199
|
placeholder: element,
|
|
180
200
|
create: (value) => {
|
|
181
201
|
if (!isHTMLOrSVGElement(value)) return;
|
|
182
202
|
const element = value;
|
|
183
203
|
placeholder.drag.custom = element;
|
|
184
|
-
updatePlaceholder(
|
|
204
|
+
updatePlaceholder(item, element);
|
|
185
205
|
state.element = {
|
|
186
206
|
rectangle: element.getBoundingClientRect(),
|
|
187
207
|
node: element
|
|
@@ -189,27 +209,30 @@ function setPlaceholder(state, sortable, origin) {
|
|
|
189
209
|
}
|
|
190
210
|
}
|
|
191
211
|
});
|
|
192
|
-
|
|
212
|
+
item.instance.element.dispatchEvent(event);
|
|
193
213
|
setTimeout(() => {
|
|
194
214
|
if (!event.defaultPrevented && placeholder.drag.custom == null) placeholder.drag.default?.append(element.cloneNode(true));
|
|
195
215
|
document.body.append(placeholder.drag.custom ?? placeholder.drag.default ?? "");
|
|
196
216
|
});
|
|
197
217
|
}
|
|
198
|
-
function updatePlaceholder(
|
|
218
|
+
function updatePlaceholder(item, element) {
|
|
199
219
|
element.style.position = "fixed";
|
|
200
220
|
element.setAttribute(ATTRIBUTE_PLACEHOLDER_DRAG, "");
|
|
201
|
-
|
|
221
|
+
const state = getDraggableStates(item.state.element)?.sortable;
|
|
222
|
+
if (state == null) return;
|
|
223
|
+
if (state.horizontal) element.setAttribute(ATTRIBUTE_HORIZONTAL, "");
|
|
202
224
|
else element.removeAttribute(ATTRIBUTE_HORIZONTAL);
|
|
203
|
-
if (
|
|
225
|
+
if (state.vertical) element.setAttribute(ATTRIBUTE_VERTICAL, "");
|
|
204
226
|
else element.removeAttribute(ATTRIBUTE_VERTICAL);
|
|
205
227
|
}
|
|
206
228
|
function validatePosition(_, from, to, position) {
|
|
207
229
|
let valid = true;
|
|
208
|
-
const rectangle = from.origin?.getBoundingClientRect();
|
|
209
|
-
|
|
210
|
-
if (
|
|
211
|
-
if (valid &&
|
|
212
|
-
if (valid &&
|
|
230
|
+
const rectangle = from.state.origin?.getBoundingClientRect();
|
|
231
|
+
const fromState = getDraggableStates(from.state.element)?.sortable;
|
|
232
|
+
if (rectangle != null && !(fromState?.horizontal ?? true)) valid = position.x >= rectangle.left && position.x <= rectangle.right;
|
|
233
|
+
if (valid && rectangle != null && !(fromState?.vertical ?? true)) valid = position.y >= rectangle.top && position.y <= rectangle.bottom;
|
|
234
|
+
if (valid && from.state.connections != null) valid = to?.state.element.matches(from.state.connections) ?? true;
|
|
235
|
+
if (valid && to?.state.connections != null) valid = from.state.element.matches(to.state.connections);
|
|
213
236
|
return valid;
|
|
214
237
|
}
|
|
215
238
|
const ATTRIBUTE = "oui-sortable";
|
|
@@ -227,6 +250,7 @@ const EVENT_END = "sort:end";
|
|
|
227
250
|
const EVENT_PLACEHOLDER = "sort:placeholder";
|
|
228
251
|
const INSERT_AFTER = "afterend";
|
|
229
252
|
const INSERT_BEFORE = "beforebegin";
|
|
253
|
+
const MESSAGE = "The element must be an instance of HTMLElement or SVGElement";
|
|
230
254
|
const SELECTOR = `[${ATTRIBUTE}]`;
|
|
231
255
|
const SELECTOR_ITEM = `[${ATTRIBUTE}] > *`;
|
|
232
256
|
const bound = {
|
|
@@ -240,6 +264,7 @@ const placeholder = {
|
|
|
240
264
|
},
|
|
241
265
|
position: void 0
|
|
242
266
|
};
|
|
243
|
-
|
|
267
|
+
const addSortable = addDraggable.bind(bound);
|
|
268
|
+
attributable(ATTRIBUTE, addSortable, removeDraggable.bind(bound));
|
|
244
269
|
//#endregion
|
|
245
|
-
export { OuiSortable };
|
|
270
|
+
export { OuiSortable, createSortable };
|
package/dist/js/splitter.mjs
CHANGED
|
@@ -282,11 +282,11 @@ const ATTRIBUTE_ACTIVE = `${SELECTOR}-active`;
|
|
|
282
282
|
const ATTRIBUTE_HANDLE = `${SELECTOR}-handle`;
|
|
283
283
|
const ATTRIBUTE_HORIZONTAL = `${SELECTOR}-horizontal`;
|
|
284
284
|
const ATTRIBUTE_SEPARATOR = `${SELECTOR}-separator`;
|
|
285
|
-
const KEYS_ABSOLUTE = new Set(["End", "Home"]);
|
|
286
|
-
const KEYS_HORIZONTAL = new Set(["ArrowDown", "ArrowUp"]);
|
|
287
|
-
const KEYS_NEGATIVE = new Set(["ArrowLeft", "ArrowUp"]);
|
|
288
|
-
const KEYS_VERTICAL = new Set(["ArrowLeft", "ArrowRight"]);
|
|
289
|
-
const KEYS_ALL = new Set([
|
|
285
|
+
const KEYS_ABSOLUTE = /* @__PURE__ */ new Set(["End", "Home"]);
|
|
286
|
+
const KEYS_HORIZONTAL = /* @__PURE__ */ new Set(["ArrowDown", "ArrowUp"]);
|
|
287
|
+
const KEYS_NEGATIVE = /* @__PURE__ */ new Set(["ArrowLeft", "ArrowUp"]);
|
|
288
|
+
const KEYS_VERTICAL = /* @__PURE__ */ new Set(["ArrowLeft", "ArrowRight"]);
|
|
289
|
+
const KEYS_ALL = /* @__PURE__ */ new Set([
|
|
290
290
|
...KEYS_ABSOLUTE,
|
|
291
291
|
...KEYS_HORIZONTAL,
|
|
292
292
|
...KEYS_VERTICAL
|
|
@@ -315,7 +315,7 @@ on(document, "keydown", onKeydown);
|
|
|
315
315
|
on(document, "mousedown", onPointerdown);
|
|
316
316
|
on(document, "pointermove", onPointermove);
|
|
317
317
|
on(document, "pointerup", onPointerup);
|
|
318
|
-
on(document, "touchcancel", onPointerup
|
|
318
|
+
on(document, "touchcancel", onPointerup);
|
|
319
319
|
on(document, "touchstart", onPointerdown, { passive: false });
|
|
320
320
|
//#endregion
|
|
321
321
|
export { OuiSplitterElement };
|
package/dist/js/toolbar.mjs
CHANGED
|
@@ -88,17 +88,17 @@ const KEY_ARROW_DOWN = "ArrowDown";
|
|
|
88
88
|
const KEY_ARROW_RIGHT = "ArrowRight";
|
|
89
89
|
const KEY_END = "End";
|
|
90
90
|
const KEY_HOME = "Home";
|
|
91
|
-
const KEYS_ABSOLUTE = new Set([KEY_END, KEY_HOME]);
|
|
92
|
-
const KEYS_HORIZONTAL = new Set([KEY_ARROW_RIGHT, "ArrowLeft"]);
|
|
93
|
-
const KEYS_VERTICAL = new Set([KEY_ARROW_DOWN, "ArrowUp"]);
|
|
94
|
-
const KEYS_ALL = new Set([
|
|
91
|
+
const KEYS_ABSOLUTE = /* @__PURE__ */ new Set([KEY_END, KEY_HOME]);
|
|
92
|
+
const KEYS_HORIZONTAL = /* @__PURE__ */ new Set([KEY_ARROW_RIGHT, "ArrowLeft"]);
|
|
93
|
+
const KEYS_VERTICAL = /* @__PURE__ */ new Set([KEY_ARROW_DOWN, "ArrowUp"]);
|
|
94
|
+
const KEYS_ALL = /* @__PURE__ */ new Set([
|
|
95
95
|
...KEYS_ABSOLUTE,
|
|
96
96
|
...KEYS_HORIZONTAL,
|
|
97
97
|
...KEYS_VERTICAL
|
|
98
98
|
]);
|
|
99
|
-
const KEYS_NEXT = new Set([KEY_ARROW_DOWN, KEY_ARROW_RIGHT]);
|
|
99
|
+
const KEYS_NEXT = /* @__PURE__ */ new Set([KEY_ARROW_DOWN, KEY_ARROW_RIGHT]);
|
|
100
100
|
const ORIENTATION_HORIZONTAL = "horizontal";
|
|
101
|
-
const ORIENTATIONS = new Set([ORIENTATION_HORIZONTAL, "vertical"]);
|
|
101
|
+
const ORIENTATIONS = /* @__PURE__ */ new Set([ORIENTATION_HORIZONTAL, "vertical"]);
|
|
102
102
|
const PROPERTY_DISABLED = "disabled";
|
|
103
103
|
const SELECTOR = `[${ATTRIBUTE}-item]`;
|
|
104
104
|
const instances = /* @__PURE__ */ new WeakMap();
|
package/dist/js/tooltip.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as OuiFloatable } from "./floatable.embedded-YxGwzgbE.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/js/tooltip.d.ts
|
|
4
4
|
declare class OuiTooltip {
|
|
@@ -23,7 +23,7 @@ declare class OuiTooltip {
|
|
|
23
23
|
}
|
|
24
24
|
type OuiTooltipState = {
|
|
25
25
|
anchor: HTMLElement;
|
|
26
|
-
|
|
26
|
+
elements: HTMLElement[];
|
|
27
27
|
floatable: OuiFloatable;
|
|
28
28
|
timer?: number;
|
|
29
29
|
tooltip: OuiTooltip;
|