@oscarpalmer/oui 0.26.0 → 0.27.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 +0 -2
- package/dist/css/message.css +1 -0
- package/dist/css/reset.css +1 -0
- package/dist/js/dialog.d.mts +6 -0
- package/dist/js/dialog.mjs +23 -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} +22 -17
- package/dist/js/floatable/floatable.standalone.d.mts +2 -0
- package/dist/js/floatable/floatable.standalone.mjs +2 -0
- package/dist/js/{embedded-ai6cqURc.d.mts → floatable.embedded-YxGwzgbE.d.mts} +13 -10
- 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 +4 -3
- package/dist/js/index.mjs +8 -7
- package/dist/js/internal/draggable.d.mts +2 -2
- package/dist/js/internal/draggable.mjs +146 -94
- 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 +3 -2
- package/dist/js/popover.mjs +8 -3
- 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.d.mts +24 -0
- package/dist/js/splitter.mjs +33 -9
- package/dist/js/toolbar.mjs +6 -6
- package/dist/js/tooltip.d.mts +12 -2
- package/dist/js/tooltip.mjs +49 -33
- package/package.json +11 -11
- package/src/css/floatable.scss +0 -2
- package/src/css/message.scss +1 -0
- package/src/css/reset.scss +1 -0
- package/src/js/dialog.ts +42 -1
- package/src/js/floatable/{embedded.ts → floatable.embedded.ts} +26 -18
- 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 +4 -4
- package/src/js/internal/draggable.ts +309 -168
- package/src/js/movable/movable.embedded.ts +328 -0
- package/src/js/movable/movable.standalone.ts +2 -0
- package/src/js/popover.ts +11 -2
- 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 +28 -4
- package/src/js/tooltip.ts +66 -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,184 @@
|
|
|
1
|
+
import { attributable } from "../internal/attributable.mjs";
|
|
2
|
+
import { OuiDraggable, addDraggable, getDraggableStates, removeDraggable } from "../internal/draggable.mjs";
|
|
3
|
+
import { getPosition, on } from "@oscarpalmer/toretto/event";
|
|
4
|
+
import { isHTMLOrSVGElement } from "@oscarpalmer/toretto/is";
|
|
5
|
+
//#region src/js/movable/movable.embedded.ts
|
|
6
|
+
var OuiMovable = class extends OuiDraggable {
|
|
7
|
+
#element;
|
|
8
|
+
#style;
|
|
9
|
+
constructor(element, options) {
|
|
10
|
+
const style = {
|
|
11
|
+
inset: element.style.inset,
|
|
12
|
+
position: element.style.position
|
|
13
|
+
};
|
|
14
|
+
super("movable", "move", ATTRIBUTE_MOVABLE, element, {
|
|
15
|
+
container: {
|
|
16
|
+
attribute: ATTRIBUTE_CONTAINER,
|
|
17
|
+
map: CONTAINERS,
|
|
18
|
+
onDestroy: destroyContainer,
|
|
19
|
+
onInitialize: initializeContainer
|
|
20
|
+
},
|
|
21
|
+
direction: {
|
|
22
|
+
attribute: ATTRIBUTE_DIRECTION,
|
|
23
|
+
onAfter: afterDirection
|
|
24
|
+
},
|
|
25
|
+
drag: {
|
|
26
|
+
onBegin,
|
|
27
|
+
onCancel,
|
|
28
|
+
onEnd,
|
|
29
|
+
onMove
|
|
30
|
+
},
|
|
31
|
+
input: options,
|
|
32
|
+
position: {
|
|
33
|
+
getOffset: getOffsetPosition,
|
|
34
|
+
getOriginal: getOriginalPosition
|
|
35
|
+
},
|
|
36
|
+
getDragged() {
|
|
37
|
+
return element;
|
|
38
|
+
},
|
|
39
|
+
getOrigin() {
|
|
40
|
+
return element;
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
style,
|
|
44
|
+
hasHandles: element.querySelector(SELECTOR_HANDLE) != null,
|
|
45
|
+
moved: false
|
|
46
|
+
});
|
|
47
|
+
this.#element = element;
|
|
48
|
+
this.#style = style;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Destroys the _Movable_
|
|
52
|
+
*/
|
|
53
|
+
destroy() {
|
|
54
|
+
MOVED.delete(this);
|
|
55
|
+
this.#element.style.inset = this.#style.inset;
|
|
56
|
+
this.#element.style.position = this.#style.position;
|
|
57
|
+
this.#element = void 0;
|
|
58
|
+
this.#style = void 0;
|
|
59
|
+
super.destroy();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
function afterDirection(item) {
|
|
63
|
+
const container = item.state.container?.getBoundingClientRect();
|
|
64
|
+
if (container != null) setOffset(item.state, container);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Creates _(or retrieves)_ a _OuiMovable_ instance for an element
|
|
68
|
+
*
|
|
69
|
+
* @param element Element to make movable
|
|
70
|
+
* @returns _OuiMovable_ instance
|
|
71
|
+
*/
|
|
72
|
+
function createMovable(element, options) {
|
|
73
|
+
if (!isHTMLOrSVGElement(element)) throw new TypeError(MESSAGE);
|
|
74
|
+
return addMovable(element, options);
|
|
75
|
+
}
|
|
76
|
+
function destroyContainer(_, container, empty) {
|
|
77
|
+
if (empty) resizer.unobserve(container);
|
|
78
|
+
}
|
|
79
|
+
function getOffsetPosition(globals, _, __, position) {
|
|
80
|
+
return {
|
|
81
|
+
x: position.x - (globals.element?.rectangle.left ?? 0),
|
|
82
|
+
y: position.y - (globals.element?.rectangle.top ?? 0)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function getOriginalPosition(globals) {
|
|
86
|
+
return {
|
|
87
|
+
x: globals.element?.rectangle.left ?? 0,
|
|
88
|
+
y: globals.element?.rectangle.top ?? 0
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function initializeContainer(item) {
|
|
92
|
+
resizer.observe(item.state.container);
|
|
93
|
+
}
|
|
94
|
+
function onBegin() {}
|
|
95
|
+
function onCancel(globals, item) {
|
|
96
|
+
const { element, moved, style } = item.state;
|
|
97
|
+
const { x, y } = globals.original ?? {
|
|
98
|
+
x: 0,
|
|
99
|
+
y: 0
|
|
100
|
+
};
|
|
101
|
+
if (moved) element.style.inset = `${y}px auto auto ${x}px`;
|
|
102
|
+
else {
|
|
103
|
+
element.style.position = style.position;
|
|
104
|
+
element.style.inset = style.inset;
|
|
105
|
+
}
|
|
106
|
+
element.removeAttribute(ATTRIBUTE_MOVING);
|
|
107
|
+
}
|
|
108
|
+
function onEnd(event, globals, item, reset) {
|
|
109
|
+
const movable = item.instance;
|
|
110
|
+
const state = item.state;
|
|
111
|
+
state.element.removeAttribute(ATTRIBUTE_MOVING);
|
|
112
|
+
if (!state.moved) {
|
|
113
|
+
state.moved = true;
|
|
114
|
+
if (state.container != null) MOVED.add(movable);
|
|
115
|
+
}
|
|
116
|
+
const container = state.container?.getBoundingClientRect();
|
|
117
|
+
if (container != null) setOffset(state, container);
|
|
118
|
+
const end = new CustomEvent(EVENT_END, {
|
|
119
|
+
detail: {
|
|
120
|
+
from: { ...globals.original },
|
|
121
|
+
to: getPosition(event)
|
|
122
|
+
},
|
|
123
|
+
cancelable: true
|
|
124
|
+
});
|
|
125
|
+
state.element.dispatchEvent(end);
|
|
126
|
+
setTimeout(() => {
|
|
127
|
+
if (end.defaultPrevented) onCancel(globals, item);
|
|
128
|
+
reset();
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function onMove(_, globals, __, position) {
|
|
132
|
+
globals.element?.node.setAttribute(ATTRIBUTE_MOVING, "");
|
|
133
|
+
return {
|
|
134
|
+
from: { ...globals.original },
|
|
135
|
+
to: { ...position.calculated }
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function onResize(entries) {
|
|
139
|
+
const { length } = entries;
|
|
140
|
+
for (let index = 0; index < length; index += 1) {
|
|
141
|
+
const entry = entries[index];
|
|
142
|
+
const set = CONTAINERS.get(entry.target);
|
|
143
|
+
if (set == null) continue;
|
|
144
|
+
for (const movable of set) reposition(movable);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function onScroll() {
|
|
148
|
+
for (const moved of MOVED) reposition(moved);
|
|
149
|
+
}
|
|
150
|
+
function reposition(movable) {
|
|
151
|
+
const state = getDraggableStates(movable.element)?.movable;
|
|
152
|
+
if (state == null || !state.moved || state.container == null) return;
|
|
153
|
+
const container = state.container.getBoundingClientRect();
|
|
154
|
+
const x = container.left + (state.offset?.x ?? 0);
|
|
155
|
+
const y = container.top + (state.offset?.y ?? 0);
|
|
156
|
+
state.element.style.inset = `${y}px auto auto ${x}px`;
|
|
157
|
+
}
|
|
158
|
+
function setOffset(state, container) {
|
|
159
|
+
state.offset = {};
|
|
160
|
+
const element = state.element.getBoundingClientRect();
|
|
161
|
+
state.offset.y = element.top - container.top;
|
|
162
|
+
state.offset.x = element.left - container.left;
|
|
163
|
+
}
|
|
164
|
+
const ATTRIBUTE_MOVABLE = "oui-movable";
|
|
165
|
+
const ATTRIBUTE_CONTAINER = `${ATTRIBUTE_MOVABLE}-container`;
|
|
166
|
+
const ATTRIBUTE_DIRECTION = `${ATTRIBUTE_MOVABLE}-direction`;
|
|
167
|
+
const ATTRIBUTE_MOVABLE_HANDLE = `${ATTRIBUTE_MOVABLE}-handle`;
|
|
168
|
+
const ATTRIBUTE_MOVING = `${ATTRIBUTE_MOVABLE}-moving`;
|
|
169
|
+
const CONTAINERS = /* @__PURE__ */ new Map();
|
|
170
|
+
const EVENT_END = "move:end";
|
|
171
|
+
const MESSAGE = "The element must be an instance of HTMLElement or SVGElement";
|
|
172
|
+
const MOVED = /* @__PURE__ */ new Set();
|
|
173
|
+
const SELECTOR_HANDLE = `[${ATTRIBUTE_MOVABLE_HANDLE}]`;
|
|
174
|
+
const bound = {
|
|
175
|
+
constructor: OuiMovable,
|
|
176
|
+
property: "movable"
|
|
177
|
+
};
|
|
178
|
+
const resizer = new ResizeObserver(onResize);
|
|
179
|
+
const addMovable = addDraggable.bind(bound);
|
|
180
|
+
const removeMovable = removeDraggable.bind(bound);
|
|
181
|
+
on(document, "scroll", onScroll);
|
|
182
|
+
attributable(ATTRIBUTE_MOVABLE, addMovable, removeMovable);
|
|
183
|
+
//#endregion
|
|
184
|
+
export { ATTRIBUTE_MOVABLE, ATTRIBUTE_MOVABLE_HANDLE, OuiMovable, createMovable };
|
package/dist/js/popover.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as OuiFocusTrap } from "./embedded-
|
|
1
|
+
import { i as OuiFloatable } from "./floatable.embedded-YxGwzgbE.mjs";
|
|
2
|
+
import { i as OuiFocusTrap } from "./focus-trap.embedded-DR8NpZfr.mjs";
|
|
3
3
|
import { RemovableEventListener } from "@oscarpalmer/toretto/models";
|
|
4
4
|
|
|
5
5
|
//#region src/js/popover.d.ts
|
|
@@ -9,6 +9,7 @@ declare class OuiPopover {
|
|
|
9
9
|
* Is the popover open?
|
|
10
10
|
*/
|
|
11
11
|
get open(): boolean;
|
|
12
|
+
set open(value: boolean);
|
|
12
13
|
constructor(state: OuiPopoverState);
|
|
13
14
|
/**
|
|
14
15
|
* Closes the popover
|
package/dist/js/popover.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createEmbeddedFloatable, getOnBeforeToggleListener } from "./floatable/embedded.mjs";
|
|
1
|
+
import { createEmbeddedFloatable, getOnBeforeToggleListener } from "./floatable/floatable.embedded.mjs";
|
|
2
2
|
import { attributable } from "./internal/attributable.mjs";
|
|
3
|
-
import { createFocusTrap } from "./focus-trap/embedded.mjs";
|
|
3
|
+
import { createFocusTrap } from "./focus-trap/focus-trap.embedded.mjs";
|
|
4
4
|
import { on } from "@oscarpalmer/toretto/event";
|
|
5
5
|
import { isHTMLOrSVGElement } from "@oscarpalmer/toretto/is";
|
|
6
6
|
//#region src/js/popover.ts
|
|
@@ -12,6 +12,10 @@ var OuiPopover = class {
|
|
|
12
12
|
get open() {
|
|
13
13
|
return this.#state.content.checkVisibility();
|
|
14
14
|
}
|
|
15
|
+
set open(value) {
|
|
16
|
+
if (value === true) this.show();
|
|
17
|
+
else if (value === false) this.hide();
|
|
18
|
+
}
|
|
15
19
|
constructor(state) {
|
|
16
20
|
this.#state = state;
|
|
17
21
|
this.#state.floatable.update();
|
|
@@ -93,7 +97,8 @@ const STATE_OPEN = "open";
|
|
|
93
97
|
const TRUE = "true";
|
|
94
98
|
const options = {
|
|
95
99
|
attribute: `${ATTRIBUTE}position`,
|
|
96
|
-
position: "below-start"
|
|
100
|
+
position: "below-start",
|
|
101
|
+
reusable: false
|
|
97
102
|
};
|
|
98
103
|
const states = /* @__PURE__ */ new WeakMap();
|
|
99
104
|
let ignoreFocus = false;
|
|
@@ -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.d.mts
CHANGED
|
@@ -7,13 +7,37 @@ declare global {
|
|
|
7
7
|
declare class OuiSplitterElement extends HTMLElement {
|
|
8
8
|
#private;
|
|
9
9
|
static readonly observedAttributes: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Maximum size for the first panel
|
|
12
|
+
*/
|
|
10
13
|
get max(): number;
|
|
14
|
+
/**
|
|
15
|
+
* Maximum size for the first panel
|
|
16
|
+
*/
|
|
11
17
|
set max(value: number);
|
|
18
|
+
/**
|
|
19
|
+
* Minimum size for the first panel
|
|
20
|
+
*/
|
|
12
21
|
get min(): number;
|
|
22
|
+
/**
|
|
23
|
+
* Minimum size for the first panel
|
|
24
|
+
*/
|
|
13
25
|
set min(value: number);
|
|
26
|
+
/**
|
|
27
|
+
* Current size for the first panel
|
|
28
|
+
*/
|
|
14
29
|
get size(): number;
|
|
30
|
+
/**
|
|
31
|
+
* Current size for the first panel
|
|
32
|
+
*/
|
|
15
33
|
set size(value: number);
|
|
34
|
+
/**
|
|
35
|
+
* Orientation of the splitter
|
|
36
|
+
*/
|
|
16
37
|
get type(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Orientation of the splitter
|
|
40
|
+
*/
|
|
17
41
|
set type(value: string);
|
|
18
42
|
constructor();
|
|
19
43
|
connectedCallback(): void;
|
package/dist/js/splitter.mjs
CHANGED
|
@@ -62,29 +62,53 @@ var OuiSplitterElement = class extends HTMLElement {
|
|
|
62
62
|
ATTRIBUTE_TYPE
|
|
63
63
|
];
|
|
64
64
|
#splitter;
|
|
65
|
+
/**
|
|
66
|
+
* Maximum size for the first panel
|
|
67
|
+
*/
|
|
65
68
|
get max() {
|
|
66
69
|
return this.#splitter.values.max;
|
|
67
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Maximum size for the first panel
|
|
73
|
+
*/
|
|
68
74
|
set max(value) {
|
|
69
75
|
this.setAttribute(ATTRIBUTE_MAX, String(value));
|
|
70
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Minimum size for the first panel
|
|
79
|
+
*/
|
|
71
80
|
get min() {
|
|
72
81
|
return this.#splitter.values.min;
|
|
73
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Minimum size for the first panel
|
|
85
|
+
*/
|
|
74
86
|
set min(value) {
|
|
75
|
-
this.setAttribute(
|
|
87
|
+
this.setAttribute(ATTRIBUTE_MIN, String(value));
|
|
76
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Current size for the first panel
|
|
91
|
+
*/
|
|
77
92
|
get size() {
|
|
78
93
|
return this.#splitter.values.now.current;
|
|
79
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Current size for the first panel
|
|
97
|
+
*/
|
|
80
98
|
set size(value) {
|
|
81
|
-
this.setAttribute(
|
|
99
|
+
this.setAttribute(ATTRIBUTE_SIZE, String(value));
|
|
82
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Orientation of the splitter
|
|
103
|
+
*/
|
|
83
104
|
get type() {
|
|
84
|
-
return this.getAttribute(
|
|
105
|
+
return this.getAttribute(ATTRIBUTE_TYPE) ?? "vertical";
|
|
85
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Orientation of the splitter
|
|
109
|
+
*/
|
|
86
110
|
set type(value) {
|
|
87
|
-
this.setAttribute(
|
|
111
|
+
this.setAttribute(ATTRIBUTE_TYPE, value);
|
|
88
112
|
}
|
|
89
113
|
constructor() {
|
|
90
114
|
super();
|
|
@@ -258,11 +282,11 @@ const ATTRIBUTE_ACTIVE = `${SELECTOR}-active`;
|
|
|
258
282
|
const ATTRIBUTE_HANDLE = `${SELECTOR}-handle`;
|
|
259
283
|
const ATTRIBUTE_HORIZONTAL = `${SELECTOR}-horizontal`;
|
|
260
284
|
const ATTRIBUTE_SEPARATOR = `${SELECTOR}-separator`;
|
|
261
|
-
const KEYS_ABSOLUTE = new Set(["End", "Home"]);
|
|
262
|
-
const KEYS_HORIZONTAL = new Set(["ArrowDown", "ArrowUp"]);
|
|
263
|
-
const KEYS_NEGATIVE = new Set(["ArrowLeft", "ArrowUp"]);
|
|
264
|
-
const KEYS_VERTICAL = new Set(["ArrowLeft", "ArrowRight"]);
|
|
265
|
-
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([
|
|
266
290
|
...KEYS_ABSOLUTE,
|
|
267
291
|
...KEYS_HORIZONTAL,
|
|
268
292
|
...KEYS_VERTICAL
|
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();
|