@oscarpalmer/oui 0.26.1 → 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 +2 -0
- package/dist/js/dialog.mjs +16 -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 +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 +2 -2
- package/dist/js/popover.mjs +4 -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.mjs +5 -5
- 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 +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 +31 -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 +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 +3 -2
- package/src/js/{sortable.ts → sortable/sortable.embedded.ts} +170 -103
- package/src/js/sortable/sortable.standalone.ts +2 -0
- 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
|
@@ -3,49 +3,56 @@ import {createElement} from '@oscarpalmer/toretto/create';
|
|
|
3
3
|
import {getPosition} from '@oscarpalmer/toretto/event';
|
|
4
4
|
import {findAncestor, getElementFromPosition} from '@oscarpalmer/toretto/find';
|
|
5
5
|
import {isHTMLOrSVGElement} from '@oscarpalmer/toretto/is';
|
|
6
|
-
import {attributable} from '
|
|
6
|
+
import {attributable} from '../internal/attributable';
|
|
7
7
|
import {
|
|
8
8
|
addDraggable,
|
|
9
|
+
getDraggableStates,
|
|
9
10
|
OuiDraggable,
|
|
10
11
|
removeDraggable,
|
|
11
|
-
type
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
|
|
12
|
+
type CreateOuiDraggableOptions,
|
|
13
|
+
type OuiDraggableBound,
|
|
14
|
+
type OuiDraggableGlobals,
|
|
15
|
+
type OuiDraggableItem,
|
|
16
|
+
type OuiDraggableState,
|
|
17
|
+
type OuiDragMovePosition,
|
|
18
|
+
} from '../internal/draggable';
|
|
15
19
|
|
|
16
20
|
// #region Types
|
|
17
21
|
|
|
18
|
-
export class OuiSortable extends OuiDraggable {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
export class OuiSortable extends OuiDraggable<OuiSortableState> {
|
|
23
|
+
constructor(element: HTMLElement, options?: CreateOuiDraggableOptions) {
|
|
24
|
+
super(
|
|
25
|
+
'sortable',
|
|
26
|
+
'sort',
|
|
27
|
+
ATTRIBUTE,
|
|
28
|
+
element,
|
|
29
|
+
{
|
|
30
|
+
container: {
|
|
31
|
+
attribute: ATTRIBUTE_CONTAINER,
|
|
32
|
+
map: CONTAINERS,
|
|
33
|
+
},
|
|
34
|
+
direction: {
|
|
35
|
+
attribute: ATTRIBUTE_DIRECTION,
|
|
36
|
+
},
|
|
37
|
+
drag: {
|
|
38
|
+
onBegin,
|
|
39
|
+
onCancel,
|
|
40
|
+
onEnd,
|
|
41
|
+
onMove,
|
|
42
|
+
},
|
|
43
|
+
input: options,
|
|
44
|
+
position: {
|
|
45
|
+
getOffset: getOffsetPosition,
|
|
46
|
+
getOriginal: getOriginalPosition,
|
|
47
|
+
},
|
|
48
|
+
getDragged: getDragPlaceholder,
|
|
49
|
+
getOrigin: () =>
|
|
50
|
+
(getDraggableStates(element)?.sortable as OuiDraggableState & OuiSortableState)?.origin,
|
|
41
51
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
getOriginal: getOriginalPosition,
|
|
52
|
+
{
|
|
53
|
+
connections: element.getAttribute(ATTRIBUTE_CONNECTIONS),
|
|
45
54
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.connections = this.element.getAttribute(ATTRIBUTE_CONNECTIONS);
|
|
55
|
+
);
|
|
49
56
|
}
|
|
50
57
|
}
|
|
51
58
|
|
|
@@ -59,13 +66,18 @@ type OuiSortablePlaceholderDrag = {
|
|
|
59
66
|
default: HTMLElement | undefined;
|
|
60
67
|
};
|
|
61
68
|
|
|
69
|
+
type OuiSortableState = {
|
|
70
|
+
connections: string | null;
|
|
71
|
+
origin?: HTMLElement;
|
|
72
|
+
};
|
|
73
|
+
|
|
62
74
|
// #endregion
|
|
63
75
|
|
|
64
76
|
// #region Functions
|
|
65
77
|
|
|
66
78
|
function afterEnd(
|
|
67
79
|
insert: 'append' | 'insert' | 'prepend' | undefined,
|
|
68
|
-
from:
|
|
80
|
+
from: OuiDraggableItem<OuiSortableState>,
|
|
69
81
|
events: CustomEvent[],
|
|
70
82
|
elements: {origin?: HTMLElement; target: HTMLElement},
|
|
71
83
|
position: EventPosition | undefined,
|
|
@@ -73,7 +85,7 @@ function afterEnd(
|
|
|
73
85
|
): void {
|
|
74
86
|
elements.origin?.removeAttribute(ATTRIBUTE_ORIGIN);
|
|
75
87
|
|
|
76
|
-
from.origin = undefined;
|
|
88
|
+
from.state.origin = undefined;
|
|
77
89
|
|
|
78
90
|
resetPlaceholders();
|
|
79
91
|
|
|
@@ -106,6 +118,23 @@ function afterEnd(
|
|
|
106
118
|
document.body.removeAttribute(ATTRIBUTE_ACTIVE);
|
|
107
119
|
}
|
|
108
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Creates _(or retrieves)_ a _OuiSortable_ instance for an element
|
|
123
|
+
*
|
|
124
|
+
* @param element Element to make sortable
|
|
125
|
+
* @returns _OuiSortable_ instance
|
|
126
|
+
*/
|
|
127
|
+
export function createSortable(
|
|
128
|
+
element: HTMLElement,
|
|
129
|
+
options?: CreateOuiDraggableOptions,
|
|
130
|
+
): OuiSortable {
|
|
131
|
+
if (!isHTMLOrSVGElement(element)) {
|
|
132
|
+
throw new TypeError(MESSAGE);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return addSortable(element, options) as OuiSortable;
|
|
136
|
+
}
|
|
137
|
+
|
|
109
138
|
function getDragPlaceholder(): HTMLElement {
|
|
110
139
|
placeholder.drag.default ??= createElement('div');
|
|
111
140
|
|
|
@@ -113,36 +142,36 @@ function getDragPlaceholder(): HTMLElement {
|
|
|
113
142
|
}
|
|
114
143
|
|
|
115
144
|
function getOffsetPosition(
|
|
116
|
-
_:
|
|
117
|
-
|
|
145
|
+
_: OuiDraggableGlobals,
|
|
146
|
+
item: OuiDraggableItem,
|
|
118
147
|
element: HTMLElement,
|
|
119
148
|
position: EventPosition,
|
|
120
149
|
): EventPosition {
|
|
121
150
|
const rectangle = element.getBoundingClientRect();
|
|
122
151
|
|
|
123
152
|
return {
|
|
124
|
-
x:
|
|
125
|
-
y:
|
|
153
|
+
x: item.state.horizontal ? 0 : position.x - rectangle.left,
|
|
154
|
+
y: item.state.vertical ? 0 : position.y - rectangle.top,
|
|
126
155
|
};
|
|
127
156
|
}
|
|
128
157
|
|
|
129
158
|
function getOriginalPosition(
|
|
130
|
-
_:
|
|
131
|
-
__:
|
|
159
|
+
_: OuiDraggableGlobals,
|
|
160
|
+
__: OuiDraggableItem,
|
|
132
161
|
position: EventPosition,
|
|
133
162
|
): EventPosition {
|
|
134
163
|
return position;
|
|
135
164
|
}
|
|
136
165
|
|
|
137
|
-
function getPositionPlaceholder(
|
|
166
|
+
function getPositionPlaceholder(item: OuiDraggableItem<OuiSortableState>): HTMLElement {
|
|
138
167
|
placeholder.position ??= createElement('div');
|
|
139
168
|
|
|
140
169
|
placeholder.position.setAttribute(ATTRIBUTE_PLACEHOLDER_POSITION, '');
|
|
141
170
|
|
|
142
|
-
if (
|
|
171
|
+
if (item.state.origin != null) {
|
|
143
172
|
placeholder.position.style.setProperty(
|
|
144
173
|
'--placeholder-height',
|
|
145
|
-
`${
|
|
174
|
+
`${item.state.origin.getBoundingClientRect().height}px`,
|
|
146
175
|
);
|
|
147
176
|
}
|
|
148
177
|
|
|
@@ -151,43 +180,36 @@ function getPositionPlaceholder(sortable: OuiSortable): HTMLElement {
|
|
|
151
180
|
|
|
152
181
|
function onBegin(
|
|
153
182
|
_: MouseEvent | TouchEvent,
|
|
154
|
-
|
|
155
|
-
|
|
183
|
+
globals: OuiDraggableGlobals,
|
|
184
|
+
item: OuiDraggableItem<OuiSortableState>,
|
|
156
185
|
element: HTMLElement,
|
|
157
186
|
): void {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
sortable.origin = element;
|
|
187
|
+
item.state.origin = element;
|
|
161
188
|
|
|
162
|
-
setPlaceholder(
|
|
189
|
+
setPlaceholder(globals, item, element);
|
|
163
190
|
|
|
164
191
|
element.setAttribute(ATTRIBUTE_ORIGIN, '');
|
|
165
192
|
|
|
166
193
|
document.body.setAttribute(ATTRIBUTE_ACTIVE, '');
|
|
167
194
|
}
|
|
168
195
|
|
|
169
|
-
function onCancel(_:
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const {origin} = sortable;
|
|
173
|
-
|
|
174
|
-
origin?.removeAttribute(ATTRIBUTE_ORIGIN);
|
|
196
|
+
function onCancel(_: OuiDraggableGlobals, item: OuiDraggableItem<OuiSortableState>): void {
|
|
197
|
+
item.state.origin?.removeAttribute(ATTRIBUTE_ORIGIN);
|
|
175
198
|
|
|
176
199
|
document.body.removeAttribute(ATTRIBUTE_ACTIVE);
|
|
177
200
|
|
|
178
201
|
resetPlaceholders();
|
|
179
202
|
|
|
180
|
-
|
|
203
|
+
item.state.origin = undefined;
|
|
181
204
|
}
|
|
182
205
|
|
|
183
206
|
function onEnd(
|
|
184
207
|
event: MouseEvent | TouchEvent,
|
|
185
|
-
|
|
186
|
-
|
|
208
|
+
globals: OuiDraggableGlobals,
|
|
209
|
+
item: OuiDraggableItem<OuiSortableState>,
|
|
187
210
|
reset: () => void,
|
|
188
211
|
): void {
|
|
189
|
-
const
|
|
190
|
-
const {origin} = from;
|
|
212
|
+
const {origin} = item.state;
|
|
191
213
|
|
|
192
214
|
const position = getPosition(event) ?? {x: 0, y: 0};
|
|
193
215
|
|
|
@@ -206,25 +228,38 @@ function onEnd(
|
|
|
206
228
|
}
|
|
207
229
|
|
|
208
230
|
let insert: 'append' | 'insert' | 'prepend' | undefined = 'insert';
|
|
209
|
-
let
|
|
231
|
+
let toInstance: OuiSortable | undefined;
|
|
232
|
+
let toState: OuiDraggableState | undefined;
|
|
210
233
|
|
|
211
234
|
if (element == null) {
|
|
212
235
|
element = findAncestor(target, SELECTOR) as HTMLElement;
|
|
213
236
|
|
|
214
|
-
|
|
237
|
+
toInstance = globals.instances.get(element)?.sortable;
|
|
238
|
+
toState = globals.states.get(element)?.sortable;
|
|
215
239
|
|
|
216
240
|
insert = element == null ? undefined : element.children.length === 0 ? 'append' : 'prepend';
|
|
217
241
|
} else {
|
|
218
|
-
|
|
242
|
+
toInstance = globals.instances.get(element.parentElement!)?.sortable;
|
|
243
|
+
toState = globals.states.get(element.parentElement!)?.sortable;
|
|
219
244
|
}
|
|
220
245
|
|
|
221
|
-
const valid =
|
|
246
|
+
const valid =
|
|
247
|
+
insert != null &&
|
|
248
|
+
validatePosition(
|
|
249
|
+
globals,
|
|
250
|
+
item,
|
|
251
|
+
{
|
|
252
|
+
instance: toInstance as OuiDraggable<OuiSortableState>,
|
|
253
|
+
state: toState as OuiDraggableState & OuiSortableState,
|
|
254
|
+
},
|
|
255
|
+
position,
|
|
256
|
+
);
|
|
222
257
|
|
|
223
258
|
const detail = valid
|
|
224
259
|
? {
|
|
225
260
|
from: {
|
|
226
261
|
element: origin,
|
|
227
|
-
position: {...
|
|
262
|
+
position: {...globals.original},
|
|
228
263
|
},
|
|
229
264
|
to: {
|
|
230
265
|
element: element,
|
|
@@ -242,14 +277,14 @@ function onEnd(
|
|
|
242
277
|
const fromEvent = new CustomEvent(EVENT_END, options);
|
|
243
278
|
const toEvent = new CustomEvent(EVENT_END, options);
|
|
244
279
|
|
|
245
|
-
|
|
280
|
+
item.instance.element.dispatchEvent(fromEvent);
|
|
246
281
|
|
|
247
|
-
if (
|
|
248
|
-
|
|
282
|
+
if (item.instance !== toInstance) {
|
|
283
|
+
toInstance?.element.dispatchEvent(toEvent);
|
|
249
284
|
}
|
|
250
285
|
|
|
251
286
|
setTimeout(() => {
|
|
252
|
-
afterEnd(insert,
|
|
287
|
+
afterEnd(insert, item, [fromEvent, toEvent], {origin, target: element}, position, valid);
|
|
253
288
|
|
|
254
289
|
reset();
|
|
255
290
|
});
|
|
@@ -257,28 +292,42 @@ function onEnd(
|
|
|
257
292
|
|
|
258
293
|
function onMove(
|
|
259
294
|
event: MouseEvent | TouchEvent,
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
position:
|
|
295
|
+
globals: OuiDraggableGlobals,
|
|
296
|
+
item: OuiDraggableItem<OuiSortableState>,
|
|
297
|
+
position: OuiDragMovePosition,
|
|
263
298
|
): PlainObject | undefined {
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
const fromElement = from.origin;
|
|
299
|
+
const fromElement = item.state.origin;
|
|
267
300
|
const toElement = findAncestor(event, SELECTOR_ITEM) as HTMLElement;
|
|
268
301
|
|
|
269
|
-
let
|
|
302
|
+
let toInstance: OuiSortable | undefined;
|
|
303
|
+
let toState: OuiDraggableState | undefined;
|
|
270
304
|
|
|
271
305
|
if (toElement == null) {
|
|
272
|
-
|
|
306
|
+
const element = findAncestor(event, SELECTOR) as HTMLElement;
|
|
307
|
+
|
|
308
|
+
toInstance = globals.instances.get(element)?.sortable;
|
|
309
|
+
toState = globals.states.get(element)?.sortable;
|
|
273
310
|
} else {
|
|
274
|
-
|
|
311
|
+
toInstance = globals.instances.get(toElement.parentElement!)?.sortable;
|
|
312
|
+
toState = globals.states.get(toElement.parentElement!)?.sortable;
|
|
275
313
|
}
|
|
276
314
|
|
|
277
|
-
if (
|
|
315
|
+
if (
|
|
316
|
+
toInstance == null ||
|
|
317
|
+
!validatePosition(
|
|
318
|
+
globals,
|
|
319
|
+
item,
|
|
320
|
+
{
|
|
321
|
+
instance: toInstance as OuiDraggable<OuiSortableState>,
|
|
322
|
+
state: toState as OuiDraggableState & OuiSortableState,
|
|
323
|
+
},
|
|
324
|
+
position.original,
|
|
325
|
+
)
|
|
326
|
+
) {
|
|
278
327
|
return;
|
|
279
328
|
}
|
|
280
329
|
|
|
281
|
-
const placeholder = getPositionPlaceholder(
|
|
330
|
+
const placeholder = getPositionPlaceholder(item);
|
|
282
331
|
|
|
283
332
|
if (toElement != null && toElement !== fromElement) {
|
|
284
333
|
const {height, top} = toElement.getBoundingClientRect();
|
|
@@ -303,7 +352,7 @@ function onMove(
|
|
|
303
352
|
return {
|
|
304
353
|
from: {
|
|
305
354
|
element: fromElement,
|
|
306
|
-
position: {...
|
|
355
|
+
position: {...globals.original},
|
|
307
356
|
},
|
|
308
357
|
to: {
|
|
309
358
|
element: toElement,
|
|
@@ -320,18 +369,22 @@ function resetPlaceholders(): void {
|
|
|
320
369
|
placeholder.drag.custom = undefined;
|
|
321
370
|
}
|
|
322
371
|
|
|
323
|
-
function setPlaceholder(
|
|
372
|
+
function setPlaceholder(
|
|
373
|
+
state: OuiDraggableGlobals,
|
|
374
|
+
item: OuiDraggableItem<OuiSortableState>,
|
|
375
|
+
origin: HTMLElement,
|
|
376
|
+
): void {
|
|
324
377
|
const element = getDragPlaceholder();
|
|
325
378
|
|
|
326
379
|
placeholder.drag.default!.innerHTML = '';
|
|
327
380
|
|
|
328
|
-
updatePlaceholder(
|
|
381
|
+
updatePlaceholder(item, element);
|
|
329
382
|
|
|
330
383
|
const event = new CustomEvent(EVENT_PLACEHOLDER, {
|
|
331
384
|
cancelable: true,
|
|
332
385
|
detail: {
|
|
333
386
|
origin,
|
|
334
|
-
parent:
|
|
387
|
+
parent: item.state.element,
|
|
335
388
|
placeholder: element,
|
|
336
389
|
create: (value: unknown) => {
|
|
337
390
|
if (!isHTMLOrSVGElement(value)) {
|
|
@@ -342,7 +395,7 @@ function setPlaceholder(state: DraggableState, sortable: OuiSortable, origin: HT
|
|
|
342
395
|
|
|
343
396
|
placeholder.drag.custom = element;
|
|
344
397
|
|
|
345
|
-
updatePlaceholder(
|
|
398
|
+
updatePlaceholder(item, element);
|
|
346
399
|
|
|
347
400
|
state.element = {
|
|
348
401
|
rectangle: element.getBoundingClientRect(),
|
|
@@ -352,7 +405,7 @@ function setPlaceholder(state: DraggableState, sortable: OuiSortable, origin: HT
|
|
|
352
405
|
},
|
|
353
406
|
});
|
|
354
407
|
|
|
355
|
-
|
|
408
|
+
item.instance.element.dispatchEvent(event);
|
|
356
409
|
|
|
357
410
|
setTimeout(() => {
|
|
358
411
|
if (!event.defaultPrevented && placeholder.drag.custom == null) {
|
|
@@ -363,18 +416,24 @@ function setPlaceholder(state: DraggableState, sortable: OuiSortable, origin: HT
|
|
|
363
416
|
});
|
|
364
417
|
}
|
|
365
418
|
|
|
366
|
-
function updatePlaceholder(
|
|
419
|
+
function updatePlaceholder(item: OuiDraggableItem<OuiSortableState>, element: HTMLElement): void {
|
|
367
420
|
element.style.position = 'fixed';
|
|
368
421
|
|
|
369
422
|
element.setAttribute(ATTRIBUTE_PLACEHOLDER_DRAG, '');
|
|
370
423
|
|
|
371
|
-
|
|
424
|
+
const state = getDraggableStates(item.state.element)?.sortable;
|
|
425
|
+
|
|
426
|
+
if (state == null) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (state.horizontal) {
|
|
372
431
|
element.setAttribute(ATTRIBUTE_HORIZONTAL, '');
|
|
373
432
|
} else {
|
|
374
433
|
element.removeAttribute(ATTRIBUTE_HORIZONTAL);
|
|
375
434
|
}
|
|
376
435
|
|
|
377
|
-
if (
|
|
436
|
+
if (state.vertical) {
|
|
378
437
|
element.setAttribute(ATTRIBUTE_VERTICAL, '');
|
|
379
438
|
} else {
|
|
380
439
|
element.removeAttribute(ATTRIBUTE_VERTICAL);
|
|
@@ -382,29 +441,31 @@ function updatePlaceholder(sortable: OuiSortable, element: HTMLElement): void {
|
|
|
382
441
|
}
|
|
383
442
|
|
|
384
443
|
function validatePosition(
|
|
385
|
-
_:
|
|
386
|
-
from:
|
|
387
|
-
to:
|
|
444
|
+
_: OuiDraggableGlobals,
|
|
445
|
+
from: OuiDraggableItem<OuiSortableState>,
|
|
446
|
+
to: OuiDraggableItem<OuiSortableState> | undefined,
|
|
388
447
|
position: EventPosition,
|
|
389
448
|
): boolean {
|
|
390
449
|
let valid = true;
|
|
391
450
|
|
|
392
|
-
const rectangle = from.origin?.getBoundingClientRect();
|
|
451
|
+
const rectangle = from.state.origin?.getBoundingClientRect();
|
|
393
452
|
|
|
394
|
-
|
|
453
|
+
const fromState = getDraggableStates(from.state.element)?.sortable;
|
|
454
|
+
|
|
455
|
+
if (rectangle != null && !(fromState?.horizontal ?? true)) {
|
|
395
456
|
valid = position.x >= rectangle.left && position.x <= rectangle.right;
|
|
396
457
|
}
|
|
397
458
|
|
|
398
|
-
if (valid && rectangle != null && !
|
|
459
|
+
if (valid && rectangle != null && !(fromState?.vertical ?? true)) {
|
|
399
460
|
valid = position.y >= rectangle.top && position.y <= rectangle.bottom;
|
|
400
461
|
}
|
|
401
462
|
|
|
402
|
-
if (valid && from.connections != null) {
|
|
403
|
-
valid = to?.element.matches(from.connections) ?? true;
|
|
463
|
+
if (valid && from.state.connections != null) {
|
|
464
|
+
valid = to?.state.element.matches(from.state.connections) ?? true;
|
|
404
465
|
}
|
|
405
466
|
|
|
406
|
-
if (valid && to?.connections != null) {
|
|
407
|
-
valid = from.element.matches(to.connections);
|
|
467
|
+
if (valid && to?.state.connections != null) {
|
|
468
|
+
valid = from.state.element.matches(to.state.connections);
|
|
408
469
|
}
|
|
409
470
|
|
|
410
471
|
return valid;
|
|
@@ -444,11 +505,13 @@ const INSERT_AFTER = 'afterend';
|
|
|
444
505
|
|
|
445
506
|
const INSERT_BEFORE = 'beforebegin';
|
|
446
507
|
|
|
508
|
+
const MESSAGE = 'The element must be an instance of HTMLElement or SVGElement';
|
|
509
|
+
|
|
447
510
|
const SELECTOR = `[${ATTRIBUTE}]`;
|
|
448
511
|
|
|
449
512
|
const SELECTOR_ITEM = `[${ATTRIBUTE}] > *`;
|
|
450
513
|
|
|
451
|
-
const bound:
|
|
514
|
+
const bound: OuiDraggableBound = {
|
|
452
515
|
constructor: OuiSortable,
|
|
453
516
|
property: 'sortable',
|
|
454
517
|
};
|
|
@@ -461,10 +524,14 @@ const placeholder: OuiSortablePlaceholder = {
|
|
|
461
524
|
position: undefined,
|
|
462
525
|
};
|
|
463
526
|
|
|
527
|
+
const addSortable = addDraggable.bind(bound);
|
|
528
|
+
|
|
529
|
+
const removeSortable = removeDraggable.bind(bound);
|
|
530
|
+
|
|
464
531
|
// #endregion
|
|
465
532
|
|
|
466
533
|
// #region Initialization
|
|
467
534
|
|
|
468
|
-
attributable(ATTRIBUTE,
|
|
535
|
+
attributable(ATTRIBUTE, addSortable, removeSortable);
|
|
469
536
|
|
|
470
537
|
// #endregion
|