@oscarpalmer/oui 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/js/embedded-CHK82Uh5.d.mts +76 -0
- package/dist/js/{embedded-84gxpReS.d.mts → embedded-ai6cqURc.d.mts} +21 -17
- package/dist/js/floatable/embedded.d.mts +2 -2
- package/dist/js/floatable/embedded.mjs +27 -16
- package/dist/js/floatable/standalone.d.mts +2 -2
- package/dist/js/floatable/standalone.mjs +2 -2
- package/dist/js/focus-trap/embedded.d.mts +2 -2
- package/dist/js/focus-trap/embedded.mjs +157 -79
- package/dist/js/focus-trap/standalone.d.mts +2 -1
- package/dist/js/focus-trap/standalone.mjs +3 -3
- package/dist/js/index.d.mts +3 -2
- package/dist/js/index.mjs +4 -2
- package/dist/js/internal/draggable.d.mts +2 -2
- package/dist/js/internal/draggable.mjs +2 -2
- package/dist/js/{movable-BKFgoaOl.d.mts → movable-dNqBctx3.d.mts} +16 -16
- package/dist/js/movable.d.mts +2 -2
- package/dist/js/movable.mjs +4 -4
- package/dist/js/popover.d.mts +3 -3
- package/dist/js/popover.mjs +9 -9
- package/dist/js/sortable.d.mts +2 -2
- package/dist/js/sortable.mjs +4 -4
- package/dist/js/splitter.mjs +48 -47
- package/dist/js/toolbar.d.mts +1 -0
- package/dist/js/toolbar.mjs +107 -0
- package/dist/js/tooltip.d.mts +1 -1
- package/dist/js/tooltip.mjs +7 -7
- package/package.json +13 -1
- package/src/js/floatable/embedded.ts +65 -44
- package/src/js/floatable/standalone.ts +1 -1
- package/src/js/focus-trap/embedded.ts +219 -93
- package/src/js/focus-trap/standalone.ts +4 -2
- package/src/js/index.ts +1 -0
- package/src/js/internal/draggable.ts +20 -20
- package/src/js/movable.ts +17 -17
- package/src/js/popover.ts +18 -18
- package/src/js/sortable.ts +26 -26
- package/src/js/splitter.ts +98 -96
- package/src/js/toolbar.ts +214 -0
- package/src/js/tooltip.ts +14 -10
- package/dist/js/embedded-BpwzMSEF.d.mts +0 -26
|
@@ -4,14 +4,14 @@ import {getPosition, on} from '@oscarpalmer/toretto/event';
|
|
|
4
4
|
import {findAncestor} from '@oscarpalmer/toretto/find';
|
|
5
5
|
import {toggleStyles} from '@oscarpalmer/toretto/style';
|
|
6
6
|
import supportsTouch from '@oscarpalmer/toretto/touch';
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
7
|
+
import type {OuiMovable} from '../movable';
|
|
8
|
+
import type {OuiSortable} from '../sortable';
|
|
9
9
|
|
|
10
10
|
// #region Types
|
|
11
11
|
|
|
12
12
|
type Direction = 'horizontal' | 'vertical' | 'x' | 'y';
|
|
13
13
|
|
|
14
|
-
export abstract class
|
|
14
|
+
export abstract class OuiDraggable {
|
|
15
15
|
container: HTMLElement | undefined;
|
|
16
16
|
|
|
17
17
|
hasHandles: boolean | undefined;
|
|
@@ -45,25 +45,25 @@ export abstract class Draggable {
|
|
|
45
45
|
type DragBegin = (
|
|
46
46
|
event: MouseEvent | TouchEvent,
|
|
47
47
|
state: DraggableState,
|
|
48
|
-
draggable:
|
|
48
|
+
draggable: OuiDraggable,
|
|
49
49
|
element: HTMLElement,
|
|
50
50
|
handle: HTMLElement,
|
|
51
51
|
position: EventPosition,
|
|
52
52
|
) => void;
|
|
53
53
|
|
|
54
|
-
type DragCancel = (state: DraggableState, draggable:
|
|
54
|
+
type DragCancel = (state: DraggableState, draggable: OuiDraggable) => void;
|
|
55
55
|
|
|
56
56
|
type DragEnd = (
|
|
57
57
|
event: MouseEvent | TouchEvent,
|
|
58
58
|
state: DraggableState,
|
|
59
|
-
draggable:
|
|
59
|
+
draggable: OuiDraggable,
|
|
60
60
|
reset: () => void,
|
|
61
61
|
) => void;
|
|
62
62
|
|
|
63
63
|
type DragMove = (
|
|
64
64
|
event: MouseEvent | TouchEvent,
|
|
65
65
|
state: DraggableState,
|
|
66
|
-
draggable:
|
|
66
|
+
draggable: OuiDraggable,
|
|
67
67
|
position: DragMovePosition,
|
|
68
68
|
) => PlainObject | undefined;
|
|
69
69
|
|
|
@@ -81,8 +81,8 @@ export type DraggableBound<
|
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
type DraggableInstances = {
|
|
84
|
-
movable?:
|
|
85
|
-
sortable?:
|
|
84
|
+
movable?: OuiMovable;
|
|
85
|
+
sortable?: OuiSortable;
|
|
86
86
|
};
|
|
87
87
|
|
|
88
88
|
type DraggableOptions = {
|
|
@@ -94,25 +94,25 @@ type DraggableOptions = {
|
|
|
94
94
|
|
|
95
95
|
type DraggableOptionsContainer = {
|
|
96
96
|
attribute: string;
|
|
97
|
-
map: Map<HTMLElement, Set<
|
|
97
|
+
map: Map<HTMLElement, Set<OuiDraggable>>;
|
|
98
98
|
onDestroy?: DraggableOptionsContainerOnDestroy;
|
|
99
99
|
onInitialize?: DraggableOptionsContainerOnInitialize;
|
|
100
100
|
};
|
|
101
101
|
|
|
102
102
|
type DraggableOptionsContainerOnDestroy = (
|
|
103
|
-
draggable:
|
|
103
|
+
draggable: OuiDraggable,
|
|
104
104
|
container: HTMLElement,
|
|
105
105
|
empty: boolean,
|
|
106
106
|
) => void;
|
|
107
107
|
|
|
108
|
-
type DraggableOptionsContainerOnInitialize = (draggable:
|
|
108
|
+
type DraggableOptionsContainerOnInitialize = (draggable: OuiDraggable) => void;
|
|
109
109
|
|
|
110
110
|
type DraggableOptionsDirection = {
|
|
111
111
|
attribute: string;
|
|
112
112
|
onAfter?: DraggableOptionsDirectionOnAfter;
|
|
113
113
|
};
|
|
114
114
|
|
|
115
|
-
type DraggableOptionsDirectionOnAfter = (draggable:
|
|
115
|
+
type DraggableOptionsDirectionOnAfter = (draggable: OuiDraggable) => void;
|
|
116
116
|
|
|
117
117
|
type DraggableOptionsDrag = {
|
|
118
118
|
onBegin: DragBegin;
|
|
@@ -128,14 +128,14 @@ type DraggableOptionsPosition = {
|
|
|
128
128
|
|
|
129
129
|
type DraggableOptionsPositionGetOffset = (
|
|
130
130
|
state: DraggableState,
|
|
131
|
-
draggable:
|
|
131
|
+
draggable: OuiDraggable,
|
|
132
132
|
element: HTMLElement,
|
|
133
133
|
position: EventPosition,
|
|
134
134
|
) => EventPosition;
|
|
135
135
|
|
|
136
136
|
type DraggableOptionsPositionGetOriginal = (
|
|
137
137
|
state: DraggableState,
|
|
138
|
-
draggable:
|
|
138
|
+
draggable: OuiDraggable,
|
|
139
139
|
position: EventPosition,
|
|
140
140
|
) => EventPosition;
|
|
141
141
|
|
|
@@ -178,7 +178,7 @@ function getHandle(event: Event, isMovable: boolean): HTMLElement | null {
|
|
|
178
178
|
) as HTMLElement;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
function getNextPosition(draggable:
|
|
181
|
+
function getNextPosition(draggable: OuiDraggable, position: EventPosition): EventPosition {
|
|
182
182
|
let x = state.original?.x ?? 0;
|
|
183
183
|
let y = state.original?.y ?? 0;
|
|
184
184
|
|
|
@@ -394,7 +394,7 @@ function reset(): void {
|
|
|
394
394
|
styleToggler.remove();
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
function setContainer(draggable:
|
|
397
|
+
function setContainer(draggable: OuiDraggable, options: DraggableOptions): void {
|
|
398
398
|
const selector = draggable.element.getAttribute(options.container.attribute);
|
|
399
399
|
|
|
400
400
|
if (typeof selector !== 'string') {
|
|
@@ -420,7 +420,7 @@ function setContainer(draggable: Draggable, options: DraggableOptions): void {
|
|
|
420
420
|
options.container.onInitialize?.(draggable);
|
|
421
421
|
}
|
|
422
422
|
|
|
423
|
-
function setDirection(draggable:
|
|
423
|
+
function setDirection(draggable: OuiDraggable, options: DraggableOptions): void {
|
|
424
424
|
const direction = draggable.element.getAttribute(options.direction.attribute);
|
|
425
425
|
|
|
426
426
|
if (horizontals.has(direction as Direction)) {
|
|
@@ -432,7 +432,7 @@ function setDirection(draggable: Draggable, options: DraggableOptions): void {
|
|
|
432
432
|
options.direction.onAfter?.(draggable);
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
-
function unsetContainer(draggable:
|
|
435
|
+
function unsetContainer(draggable: OuiDraggable, options: DraggableOptions): void {
|
|
436
436
|
const {container} = draggable;
|
|
437
437
|
|
|
438
438
|
if (container == null) {
|
|
@@ -499,7 +499,7 @@ const styleToggler = toggleStyles(document.body, {
|
|
|
499
499
|
|
|
500
500
|
const verticals = new Set<Direction>(['vertical', 'y']);
|
|
501
501
|
|
|
502
|
-
let current:
|
|
502
|
+
let current: OuiMovable | OuiSortable | undefined;
|
|
503
503
|
|
|
504
504
|
// #endregion
|
|
505
505
|
|
package/src/js/movable.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {getPosition, on} from '@oscarpalmer/toretto/event';
|
|
|
3
3
|
import {attributable} from './internal/attributable';
|
|
4
4
|
import {
|
|
5
5
|
addDraggable,
|
|
6
|
-
|
|
6
|
+
OuiDraggable,
|
|
7
7
|
removeDraggable,
|
|
8
8
|
type DraggableBound,
|
|
9
9
|
type DraggableState,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
|
|
13
13
|
// #region Types
|
|
14
14
|
|
|
15
|
-
export class
|
|
15
|
+
export class OuiMovable extends OuiDraggable {
|
|
16
16
|
inset: string;
|
|
17
17
|
|
|
18
18
|
moved = false;
|
|
@@ -73,15 +73,15 @@ export class Movable extends Draggable {
|
|
|
73
73
|
|
|
74
74
|
// #region Functions
|
|
75
75
|
|
|
76
|
-
function afterDirection(draggable:
|
|
76
|
+
function afterDirection(draggable: OuiDraggable): void {
|
|
77
77
|
const container = draggable.container?.getBoundingClientRect();
|
|
78
78
|
|
|
79
79
|
if (container != null) {
|
|
80
|
-
setOffset(draggable as
|
|
80
|
+
setOffset(draggable as OuiMovable, container);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
function destroyContainer(_:
|
|
84
|
+
function destroyContainer(_: OuiDraggable, container: HTMLElement, empty: boolean): void {
|
|
85
85
|
if (empty) {
|
|
86
86
|
resizer.unobserve(container);
|
|
87
87
|
}
|
|
@@ -89,7 +89,7 @@ function destroyContainer(_: Draggable, container: HTMLElement, empty: boolean):
|
|
|
89
89
|
|
|
90
90
|
function getOffsetPosition(
|
|
91
91
|
state: DraggableState,
|
|
92
|
-
_:
|
|
92
|
+
_: OuiDraggable,
|
|
93
93
|
__: HTMLElement,
|
|
94
94
|
position: EventPosition,
|
|
95
95
|
): EventPosition {
|
|
@@ -106,14 +106,14 @@ function getOriginalPosition(state: DraggableState): EventPosition {
|
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
function initializeContainer(draggable:
|
|
109
|
+
function initializeContainer(draggable: OuiDraggable): void {
|
|
110
110
|
resizer.observe(draggable.container!);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
function onBegin(): void {}
|
|
114
114
|
|
|
115
|
-
function onCancel(state: DraggableState, draggable:
|
|
116
|
-
const movable = draggable as
|
|
115
|
+
function onCancel(state: DraggableState, draggable: OuiDraggable): void {
|
|
116
|
+
const movable = draggable as OuiMovable;
|
|
117
117
|
|
|
118
118
|
const {element, inset, moved, position} = movable;
|
|
119
119
|
const {x, y} = state.original ?? {x: 0, y: 0};
|
|
@@ -129,10 +129,10 @@ function onCancel(state: DraggableState, draggable: Draggable): void {
|
|
|
129
129
|
function onEnd(
|
|
130
130
|
event: MouseEvent | TouchEvent,
|
|
131
131
|
state: DraggableState,
|
|
132
|
-
draggable:
|
|
132
|
+
draggable: OuiDraggable,
|
|
133
133
|
reset: () => void,
|
|
134
134
|
): void {
|
|
135
|
-
const movable = draggable as
|
|
135
|
+
const movable = draggable as OuiMovable;
|
|
136
136
|
|
|
137
137
|
if (!movable.moved) {
|
|
138
138
|
movable.moved = true;
|
|
@@ -170,7 +170,7 @@ function onEnd(
|
|
|
170
170
|
function onMove(
|
|
171
171
|
_: MouseEvent | TouchEvent,
|
|
172
172
|
state: DraggableState,
|
|
173
|
-
__:
|
|
173
|
+
__: OuiDraggable,
|
|
174
174
|
position: DragMovePosition,
|
|
175
175
|
): PlainObject | undefined {
|
|
176
176
|
return {
|
|
@@ -202,7 +202,7 @@ function onScroll(): void {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
function reposition(movable:
|
|
205
|
+
function reposition(movable: OuiMovable): void {
|
|
206
206
|
if (!movable.moved || movable.container == null) {
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
@@ -215,7 +215,7 @@ function reposition(movable: Movable): void {
|
|
|
215
215
|
movable.element.style.inset = `${y}px auto auto ${x}px`;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
function setOffset(movable:
|
|
218
|
+
function setOffset(movable: OuiMovable, container: DOMRect): void {
|
|
219
219
|
movable.offset = {};
|
|
220
220
|
|
|
221
221
|
const element = movable.element.getBoundingClientRect();
|
|
@@ -234,16 +234,16 @@ const ATTRIBUTE_CONTAINER = `${ATTRIBUTE}-container`;
|
|
|
234
234
|
|
|
235
235
|
const ATTRIBUTE_DIRECTION = `${ATTRIBUTE}-direction`;
|
|
236
236
|
|
|
237
|
-
const CONTAINERS = new Map<HTMLElement, Set<
|
|
237
|
+
const CONTAINERS = new Map<HTMLElement, Set<OuiMovable>>();
|
|
238
238
|
|
|
239
239
|
const EVENT_END = 'move:end';
|
|
240
240
|
|
|
241
|
-
const MOVED = new Set<
|
|
241
|
+
const MOVED = new Set<OuiMovable>();
|
|
242
242
|
|
|
243
243
|
const SELECTOR_HANDLE = `[${ATTRIBUTE}-handle]`;
|
|
244
244
|
|
|
245
245
|
const bound: DraggableBound = {
|
|
246
|
-
constructor:
|
|
246
|
+
constructor: OuiMovable,
|
|
247
247
|
property: 'movable',
|
|
248
248
|
};
|
|
249
249
|
|
package/src/js/popover.ts
CHANGED
|
@@ -3,12 +3,12 @@ import {isHTMLOrSVGElement} from '@oscarpalmer/toretto/is';
|
|
|
3
3
|
import type {RemovableEventListener} from '@oscarpalmer/toretto/models';
|
|
4
4
|
import {
|
|
5
5
|
ATTRIBUTE_FLOATABLE,
|
|
6
|
-
|
|
6
|
+
createEmbeddedFloatable,
|
|
7
7
|
getOnBeforeToggleListener,
|
|
8
8
|
type OuiFloatable,
|
|
9
9
|
type OuiFloatableOptions,
|
|
10
10
|
} from './floatable/embedded';
|
|
11
|
-
import {createFocusTrap, type
|
|
11
|
+
import {createFocusTrap, type OuiFocusTrap} from './focus-trap/embedded';
|
|
12
12
|
import {attributable} from './internal/attributable';
|
|
13
13
|
|
|
14
14
|
// #region Types
|
|
@@ -48,7 +48,7 @@ type OuiPopoverState = {
|
|
|
48
48
|
anchor: HTMLElement;
|
|
49
49
|
content: HTMLElement;
|
|
50
50
|
floatable: OuiFloatable;
|
|
51
|
-
focusTrap?:
|
|
51
|
+
focusTrap?: OuiFocusTrap;
|
|
52
52
|
listeners: RemovableEventListener[];
|
|
53
53
|
popover: OuiPopover;
|
|
54
54
|
};
|
|
@@ -57,6 +57,18 @@ type OuiPopoverState = {
|
|
|
57
57
|
|
|
58
58
|
// #region Functions
|
|
59
59
|
|
|
60
|
+
function addPopover(element: HTMLElement): void {
|
|
61
|
+
if (states.has(element) || element.hasAttribute(ATTRIBUTE_FLOATABLE)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const anchor = element.ownerDocument.querySelector(`[popovertarget="${element.id}"]`);
|
|
66
|
+
|
|
67
|
+
if (isHTMLOrSVGElement(anchor)) {
|
|
68
|
+
states.set(element, getState(anchor, element));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
60
72
|
function destroyPopover(state: OuiPopoverState): void {
|
|
61
73
|
state.floatable.destroy();
|
|
62
74
|
state.focusTrap?.destroy();
|
|
@@ -87,7 +99,7 @@ function getState(anchor: HTMLElement, content: HTMLElement): OuiPopoverState {
|
|
|
87
99
|
const state: OuiPopoverState = {
|
|
88
100
|
anchor,
|
|
89
101
|
content,
|
|
90
|
-
floatable:
|
|
102
|
+
floatable: createEmbeddedFloatable(anchor, content, options),
|
|
91
103
|
focusTrap:
|
|
92
104
|
content.getAttribute(ARIA_MODAL) === TRUE
|
|
93
105
|
? createFocusTrap(content, {
|
|
@@ -122,23 +134,11 @@ function getState(anchor: HTMLElement, content: HTMLElement): OuiPopoverState {
|
|
|
122
134
|
return state;
|
|
123
135
|
}
|
|
124
136
|
|
|
125
|
-
function onAdd(element: HTMLElement): void {
|
|
126
|
-
if (states.has(element) || element.hasAttribute(ATTRIBUTE_FLOATABLE)) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const anchor = element.ownerDocument.querySelector(`[popovertarget="${element.id}"]`);
|
|
131
|
-
|
|
132
|
-
if (isHTMLOrSVGElement(anchor)) {
|
|
133
|
-
states.set(element, getState(anchor, element));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
137
|
function onPointerdown(): void {
|
|
138
138
|
ignoreFocus = true;
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
function
|
|
141
|
+
function removePopover(element: HTMLElement): void {
|
|
142
142
|
const state = states.get(element);
|
|
143
143
|
|
|
144
144
|
if (state == null) {
|
|
@@ -183,7 +183,7 @@ on(document, 'pointerdown', onPointerdown, {
|
|
|
183
183
|
capture: true,
|
|
184
184
|
});
|
|
185
185
|
|
|
186
|
-
attributable(ATTRIBUTE,
|
|
186
|
+
attributable(ATTRIBUTE, addPopover, removePopover);
|
|
187
187
|
|
|
188
188
|
// #endregion
|
|
189
189
|
|
package/src/js/sortable.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {isHTMLOrSVGElement} from '@oscarpalmer/toretto/is';
|
|
|
6
6
|
import {attributable} from './internal/attributable';
|
|
7
7
|
import {
|
|
8
8
|
addDraggable,
|
|
9
|
-
|
|
9
|
+
OuiDraggable,
|
|
10
10
|
removeDraggable,
|
|
11
11
|
type DraggableBound,
|
|
12
12
|
type DraggableState,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
|
|
16
16
|
// #region Types
|
|
17
17
|
|
|
18
|
-
export class
|
|
18
|
+
export class OuiSortable extends OuiDraggable {
|
|
19
19
|
connections: string | null;
|
|
20
20
|
|
|
21
21
|
origin: HTMLElement | undefined;
|
|
@@ -49,12 +49,12 @@ export class Sortable extends Draggable {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
type
|
|
53
|
-
drag:
|
|
52
|
+
type OuiSortablePlaceholder = {
|
|
53
|
+
drag: OuiSortablePlaceholderDrag;
|
|
54
54
|
position: HTMLElement | undefined;
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
type
|
|
57
|
+
type OuiSortablePlaceholderDrag = {
|
|
58
58
|
custom: HTMLElement | undefined;
|
|
59
59
|
default: HTMLElement | undefined;
|
|
60
60
|
};
|
|
@@ -65,7 +65,7 @@ type SortablePlaceholderDrag = {
|
|
|
65
65
|
|
|
66
66
|
function afterEnd(
|
|
67
67
|
insert: 'append' | 'insert' | 'prepend' | undefined,
|
|
68
|
-
from:
|
|
68
|
+
from: OuiSortable,
|
|
69
69
|
events: CustomEvent[],
|
|
70
70
|
elements: {origin?: HTMLElement; target: HTMLElement},
|
|
71
71
|
position: EventPosition | undefined,
|
|
@@ -114,7 +114,7 @@ function getDragPlaceholder(): HTMLElement {
|
|
|
114
114
|
|
|
115
115
|
function getOffsetPosition(
|
|
116
116
|
_: DraggableState,
|
|
117
|
-
draggable:
|
|
117
|
+
draggable: OuiDraggable,
|
|
118
118
|
element: HTMLElement,
|
|
119
119
|
position: EventPosition,
|
|
120
120
|
): EventPosition {
|
|
@@ -128,13 +128,13 @@ function getOffsetPosition(
|
|
|
128
128
|
|
|
129
129
|
function getOriginalPosition(
|
|
130
130
|
_: DraggableState,
|
|
131
|
-
__:
|
|
131
|
+
__: OuiDraggable,
|
|
132
132
|
position: EventPosition,
|
|
133
133
|
): EventPosition {
|
|
134
134
|
return position;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
function getPositionPlaceholder(sortable:
|
|
137
|
+
function getPositionPlaceholder(sortable: OuiSortable): HTMLElement {
|
|
138
138
|
placeholder.position ??= createElement('div');
|
|
139
139
|
|
|
140
140
|
placeholder.position.setAttribute(ATTRIBUTE_PLACEHOLDER_POSITION, '');
|
|
@@ -152,10 +152,10 @@ function getPositionPlaceholder(sortable: Sortable): HTMLElement {
|
|
|
152
152
|
function onBegin(
|
|
153
153
|
_: MouseEvent | TouchEvent,
|
|
154
154
|
state: DraggableState,
|
|
155
|
-
draggable:
|
|
155
|
+
draggable: OuiDraggable,
|
|
156
156
|
element: HTMLElement,
|
|
157
157
|
): void {
|
|
158
|
-
const sortable = draggable as
|
|
158
|
+
const sortable = draggable as OuiSortable;
|
|
159
159
|
|
|
160
160
|
sortable.origin = element;
|
|
161
161
|
|
|
@@ -166,8 +166,8 @@ function onBegin(
|
|
|
166
166
|
document.body.setAttribute(ATTRIBUTE_ACTIVE, '');
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
function onCancel(_: DraggableState, draggable:
|
|
170
|
-
const sortable = draggable as
|
|
169
|
+
function onCancel(_: DraggableState, draggable: OuiDraggable): void {
|
|
170
|
+
const sortable = draggable as OuiSortable;
|
|
171
171
|
|
|
172
172
|
const {origin} = sortable;
|
|
173
173
|
|
|
@@ -183,10 +183,10 @@ function onCancel(_: DraggableState, draggable: Draggable): void {
|
|
|
183
183
|
function onEnd(
|
|
184
184
|
event: MouseEvent | TouchEvent,
|
|
185
185
|
state: DraggableState,
|
|
186
|
-
draggable:
|
|
186
|
+
draggable: OuiDraggable,
|
|
187
187
|
reset: () => void,
|
|
188
188
|
): void {
|
|
189
|
-
const from = draggable as
|
|
189
|
+
const from = draggable as OuiSortable;
|
|
190
190
|
const {origin} = from;
|
|
191
191
|
|
|
192
192
|
const position = getPosition(event) ?? {x: 0, y: 0};
|
|
@@ -206,7 +206,7 @@ function onEnd(
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
let insert: 'append' | 'insert' | 'prepend' | undefined = 'insert';
|
|
209
|
-
let to:
|
|
209
|
+
let to: OuiSortable | undefined;
|
|
210
210
|
|
|
211
211
|
if (element == null) {
|
|
212
212
|
element = findAncestor(target, SELECTOR) as HTMLElement;
|
|
@@ -258,15 +258,15 @@ function onEnd(
|
|
|
258
258
|
function onMove(
|
|
259
259
|
event: MouseEvent | TouchEvent,
|
|
260
260
|
state: DraggableState,
|
|
261
|
-
draggable:
|
|
261
|
+
draggable: OuiDraggable,
|
|
262
262
|
position: DragMovePosition,
|
|
263
263
|
): PlainObject | undefined {
|
|
264
|
-
const from = draggable as
|
|
264
|
+
const from = draggable as OuiSortable;
|
|
265
265
|
|
|
266
266
|
const fromElement = from.origin;
|
|
267
267
|
const toElement = findAncestor(event, SELECTOR_ITEM) as HTMLElement;
|
|
268
268
|
|
|
269
|
-
let to:
|
|
269
|
+
let to: OuiSortable | undefined;
|
|
270
270
|
|
|
271
271
|
if (toElement == null) {
|
|
272
272
|
to = state.instances.get(findAncestor(event, SELECTOR) as HTMLElement)?.sortable;
|
|
@@ -320,7 +320,7 @@ function resetPlaceholders(): void {
|
|
|
320
320
|
placeholder.drag.custom = undefined;
|
|
321
321
|
}
|
|
322
322
|
|
|
323
|
-
function setPlaceholder(state: DraggableState, sortable:
|
|
323
|
+
function setPlaceholder(state: DraggableState, sortable: OuiSortable, origin: HTMLElement): void {
|
|
324
324
|
const element = getDragPlaceholder();
|
|
325
325
|
|
|
326
326
|
placeholder.drag.default!.innerHTML = '';
|
|
@@ -363,7 +363,7 @@ function setPlaceholder(state: DraggableState, sortable: Sortable, origin: HTMLE
|
|
|
363
363
|
});
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
-
function updatePlaceholder(sortable:
|
|
366
|
+
function updatePlaceholder(sortable: OuiSortable, element: HTMLElement): void {
|
|
367
367
|
element.style.position = 'fixed';
|
|
368
368
|
|
|
369
369
|
element.setAttribute(ATTRIBUTE_PLACEHOLDER_DRAG, '');
|
|
@@ -383,8 +383,8 @@ function updatePlaceholder(sortable: Sortable, element: HTMLElement): void {
|
|
|
383
383
|
|
|
384
384
|
function validatePosition(
|
|
385
385
|
_: DraggableState,
|
|
386
|
-
from:
|
|
387
|
-
to:
|
|
386
|
+
from: OuiSortable,
|
|
387
|
+
to: OuiSortable | undefined,
|
|
388
388
|
position: EventPosition,
|
|
389
389
|
): boolean {
|
|
390
390
|
let valid = true;
|
|
@@ -434,7 +434,7 @@ const ATTRIBUTE_PLACEHOLDER_POSITION = `${ATTRIBUTE}-placeholder-position`;
|
|
|
434
434
|
|
|
435
435
|
const ATTRIBUTE_VERTICAL = `${ATTRIBUTE}-vertical`;
|
|
436
436
|
|
|
437
|
-
const CONTAINERS = new Map<HTMLElement, Set<
|
|
437
|
+
const CONTAINERS = new Map<HTMLElement, Set<OuiSortable>>();
|
|
438
438
|
|
|
439
439
|
const EVENT_END = 'sort:end';
|
|
440
440
|
|
|
@@ -449,11 +449,11 @@ const SELECTOR = `[${ATTRIBUTE}]`;
|
|
|
449
449
|
const SELECTOR_ITEM = `[${ATTRIBUTE}] > *`;
|
|
450
450
|
|
|
451
451
|
const bound: DraggableBound = {
|
|
452
|
-
constructor:
|
|
452
|
+
constructor: OuiSortable,
|
|
453
453
|
property: 'sortable',
|
|
454
454
|
};
|
|
455
455
|
|
|
456
|
-
const placeholder:
|
|
456
|
+
const placeholder: OuiSortablePlaceholder = {
|
|
457
457
|
drag: {
|
|
458
458
|
custom: undefined,
|
|
459
459
|
default: undefined,
|