@pantograph/sortable 1.15.6

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/src/index.d.ts ADDED
@@ -0,0 +1,549 @@
1
+ import {
2
+ AutoScrollOptions,
3
+ AutoScrollPlugin,
4
+ MultiDragOptions,
5
+ MultiDragPlugin,
6
+ OnSpillOptions,
7
+ OnSpillPlugin,
8
+ SortablePlugin,
9
+ SwapOptions,
10
+ SwapPlugin,
11
+ FlatTreeOptions,
12
+ FlatTreePlugin,
13
+ } from './plugins'
14
+
15
+ export = Sortable
16
+
17
+ declare class Sortable {
18
+ public options: Sortable.Options
19
+ public el: HTMLElement
20
+
21
+ /**
22
+ * Sortable's main constructor.
23
+ * @param element Any variety of HTMLElement.
24
+ * @param options Sortable options object.
25
+ */
26
+ constructor(element: HTMLElement, options: Sortable.Options)
27
+
28
+ static active: Sortable | null
29
+ static utils: Sortable.Utils
30
+
31
+ /**
32
+ * Mounts a plugin to Sortable
33
+ * @param sortablePlugin a sortable plugin.
34
+ *
35
+ * @example
36
+ *
37
+ * Sortable.mount(new MultiDrag(), new AutoScroll())
38
+ */
39
+ static mount(...sortablePlugins: SortablePlugin[]): void
40
+
41
+ /**
42
+ * Creation of new instances.
43
+ * @param element Any variety of HTMLElement.
44
+ * @param options Sortable options object.
45
+ */
46
+ static create(element: HTMLElement, options?: Sortable.Options): Sortable
47
+
48
+ /** The element being dragged. */
49
+ static dragged: HTMLElement | null
50
+
51
+ /** The ghost element.*/
52
+ static ghost: HTMLElement | null
53
+
54
+ /** The clone element. */
55
+ static clone: HTMLElement | null
56
+
57
+ /** Get the Sortable instance on an element. */
58
+ static get(element: HTMLElement): Sortable | undefined
59
+
60
+ /** Get the Sortable version */
61
+ static readonly version: string
62
+
63
+ /**
64
+ * Options getter/setter
65
+ * @param name a Sortable.Options property.
66
+ * @param value a value.
67
+ */
68
+ option<K extends keyof Sortable.Options>(name: K, value: Sortable.Options[K]): void
69
+ option<K extends keyof Sortable.Options>(name: K): Sortable.Options[K]
70
+
71
+ /**
72
+ * For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
73
+ * @param element an HTMLElement or selector string.
74
+ * @param selector default: `options.draggable`
75
+ */
76
+ closest(element: HTMLElement, selector?: string): HTMLElement | null
77
+
78
+ /**
79
+ * Sorts the elements according to the array.
80
+ * @param order an array of strings to sort.
81
+ * @param useAnimation default: false.
82
+ */
83
+ sort(order: readonly string[], useAnimation?: boolean): void
84
+
85
+ /**
86
+ * Saving and restoring of the sort.
87
+ */
88
+ save(): void
89
+
90
+ /**
91
+ * Removes the sortable functionality completely.
92
+ */
93
+ destroy(): void
94
+
95
+ /**
96
+ * Serializes the sortable's item data-id's (dataIdAttr option) into an array of string.
97
+ */
98
+ toArray(): string[]
99
+ }
100
+
101
+ declare namespace Sortable {
102
+ export interface Options
103
+ extends SortableOptions,
104
+ AutoScrollOptions,
105
+ MultiDragOptions,
106
+ OnSpillOptions,
107
+ SwapOptions,
108
+ FlatTreeOptions {}
109
+
110
+ /**
111
+ * A class that all plugins inherit from for the sake of type inference.
112
+ */
113
+ export class Plugin extends SortablePlugin {}
114
+ export class MultiDrag extends MultiDragPlugin {}
115
+ export class AutoScroll extends AutoScrollPlugin {}
116
+ export class Swap extends SwapPlugin {}
117
+ export class FlatTree extends FlatTreePlugin {}
118
+ export class OnSpill extends OnSpillPlugin {}
119
+
120
+ export interface SortableEvent extends Event {
121
+ clone: HTMLElement
122
+ /**
123
+ * previous list
124
+ */
125
+ from: HTMLElement
126
+ /**
127
+ * dragged element
128
+ */
129
+ item: HTMLElement
130
+ /**
131
+ * dragged elements
132
+ */
133
+ items: HTMLElement[]
134
+ /**
135
+ * new index within parent
136
+ */
137
+ newIndex: number | undefined
138
+ /**
139
+ * old index within parent
140
+ */
141
+ oldIndex: number | undefined
142
+ target: HTMLElement
143
+ /**
144
+ * list, in which moved element.
145
+ */
146
+ to: HTMLElement
147
+ /**
148
+ * Old index within parent, only counting draggable elements
149
+ */
150
+ oldDraggableIndex: number | undefined
151
+ /**
152
+ * New index within parent, only counting draggable elements
153
+ */
154
+ newDraggableIndex: number | undefined
155
+ /**
156
+ * Pull mode if dragging into another sortable
157
+ */
158
+ pullMode: 'clone' | boolean | undefined
159
+ /**
160
+ * When MultiDrag is used to sort, this holds a HTMLElement and oldIndex for each item selected.
161
+ *
162
+ * `oldIndicies[number]` is directly related to `newIndicies[number]`
163
+ *
164
+ * If MultiDrag is not used to sort, this array will be empty.
165
+ */
166
+ oldIndicies: Array<{ multiDragElement: HTMLElement; index: number }>
167
+ /**
168
+ * When MultiDrag is used to sort, this holds a HTMLElement and newIndex for each item.
169
+ *
170
+ * `oldIndicies[number]` is directly related to `newIndicies[number]`
171
+ *
172
+ * If MultiDrag is not used to sort, this array will be empty.
173
+ */
174
+ newIndicies: Array<{ multiDragElement: HTMLElement; index: number }>
175
+ /** When Swap is used to sort, this will contain the dragging item that was dropped on.*/
176
+ swapItem: HTMLElement | null
177
+ }
178
+
179
+ export interface MoveEvent extends Event {
180
+ dragged: HTMLElement
181
+ draggedRect: DOMRect
182
+ from: HTMLElement
183
+ /**
184
+ * element on which have guided
185
+ */
186
+ related: HTMLElement
187
+ relatedRect: DOMRect
188
+ to: HTMLElement
189
+ willInsertAfter?: boolean | undefined
190
+ }
191
+
192
+ type PullResult = readonly string[] | boolean | 'clone'
193
+ type PutResult = readonly string[] | boolean
194
+ export interface GroupOptions {
195
+ /**
196
+ * group name
197
+ */
198
+ name: string
199
+ /**
200
+ * ability to move from the list. clone — copy the item, rather than move.
201
+ */
202
+ pull?:
203
+ | PullResult
204
+ | ((to: Sortable, from: Sortable, dragEl: HTMLElement, event: SortableEvent) => PullResult)
205
+ | undefined
206
+ /**
207
+ * whether elements can be added from other lists, or an array of group names from which elements can be taken.
208
+ */
209
+ put?:
210
+ | PutResult
211
+ | ((to: Sortable, from: Sortable, dragEl: HTMLElement, event: SortableEvent) => PutResult)
212
+ | undefined
213
+ /**
214
+ * a canonical version of pull, created by Sortable
215
+ */
216
+ checkPull?:
217
+ | ((
218
+ sortable: Sortable,
219
+ activeSortable: Sortable,
220
+ dragEl: HTMLElement,
221
+ event: SortableEvent,
222
+ ) => boolean | string | string[])
223
+ | undefined
224
+ /**
225
+ * a canonical version of put, created by Sortable
226
+ */
227
+ checkPut?:
228
+ | ((
229
+ sortable: Sortable,
230
+ activeSortable: Sortable,
231
+ dragEl: HTMLElement,
232
+ event: SortableEvent,
233
+ ) => boolean | string | 'clone' | string[])
234
+ | undefined
235
+ /**
236
+ * revert cloned element to initial position after moving to a another list.
237
+ */
238
+ revertClone?: boolean | undefined
239
+ }
240
+ type Direction = 'vertical' | 'horizontal'
241
+ export interface SortableOptions {
242
+ getGhostFallback?: (dragEl: HTMLElement) => HTMLElement
243
+ getPlaceholder?: (dragEl: HTMLElement) => HTMLElement
244
+ getPlaceholderOnMove?: (event: MoveEvent) => HTMLElement
245
+ /**
246
+ * ms, animation speed moving items when sorting, `0` — without animation
247
+ */
248
+ animation?: number | undefined
249
+ /**
250
+ * Class name for the chosen item
251
+ */
252
+ chosenClass?: string | undefined
253
+ dataIdAttr?: string | undefined
254
+ /**
255
+ * time in milliseconds to define when the sorting should start
256
+ */
257
+ delay?: number | undefined
258
+ /**
259
+ * Only delay if user is using touch
260
+ */
261
+ delayOnTouchOnly?: boolean | undefined
262
+ /**
263
+ * Direction of Sortable
264
+ * (will be detected automatically if not given)
265
+ */
266
+ direction?:
267
+ | ((evt: SortableEvent, target: HTMLElement, dragEl: HTMLElement) => Direction)
268
+ | Direction
269
+ | undefined
270
+ /**
271
+ * Disables the sortable if set to true.
272
+ */
273
+ disabled?: boolean | undefined
274
+ /**
275
+ * Class name for the dragging item
276
+ */
277
+ dragClass?: string | undefined
278
+ /**
279
+ * Specifies which items inside the element should be draggable
280
+ */
281
+ draggable?: string | undefined
282
+ dragoverBubble?: boolean | undefined
283
+ dropBubble?: boolean | undefined
284
+ /**
285
+ * distance mouse must be from empty sortable
286
+ * to insert drag element into it
287
+ */
288
+ emptyInsertThreshold?: number | undefined
289
+
290
+ /**
291
+ * Easing for animation. Defaults to null.
292
+ *
293
+ * See https://easings.net/ for examples.
294
+ *
295
+ * For other possible values, see
296
+ * https://www.w3schools.com/cssref/css3_pr_animation-timing-function.asp
297
+ *
298
+ * @example
299
+ *
300
+ * // CSS functions
301
+ * | 'steps(int, start | end)'
302
+ * | 'cubic-bezier(n, n, n, n)'
303
+ *
304
+ * // CSS values
305
+ * | 'linear'
306
+ * | 'ease'
307
+ * | 'ease-in'
308
+ * | 'ease-out'
309
+ * | 'ease-in-out'
310
+ * | 'step-start'
311
+ * | 'step-end'
312
+ * | 'initial'
313
+ * | 'inherit'
314
+ */
315
+ easing?: string | undefined
316
+ /**
317
+ * Class name for the cloned DOM Element when using forceFallback
318
+ */
319
+ fallbackClass?: string | undefined
320
+ /**
321
+ * Appends the cloned DOM Element into the Document's Body
322
+ */
323
+ fallbackOnBody?: boolean | undefined
324
+ /**
325
+ * Specify in pixels how far the mouse should move before it's considered as a drag.
326
+ */
327
+ fallbackTolerance?: number | undefined
328
+ fallbackOffset?: { x: number; y: number } | undefined
329
+ /**
330
+ * Selectors that do not lead to dragging (String or Function)
331
+ */
332
+ filter?:
333
+ | string
334
+ | ((
335
+ this: Sortable,
336
+ event: Event | TouchEvent,
337
+ target: HTMLElement,
338
+ sortable: Sortable,
339
+ ) => boolean)
340
+ | undefined
341
+ /**
342
+ * ignore the HTML5 DnD behaviour and force the fallback to kick in
343
+ */
344
+ forceFallback?: boolean | undefined
345
+ /**
346
+ * Class name for the drop placeholder
347
+ */
348
+ ghostClass?: string | undefined
349
+ /**
350
+ * To drag elements from one list into another, both lists must have the same group value.
351
+ * You can also define whether lists can give away, give and keep a copy (clone), and receive elements.
352
+ */
353
+ group?: string | GroupOptions | undefined
354
+ /**
355
+ * Drag handle selector within list items
356
+ */
357
+ handle?: string | undefined
358
+ ignore?: string | undefined
359
+ /**
360
+ * Will always use inverted swap zone if set to true
361
+ */
362
+ invertSwap?: boolean | undefined
363
+ /**
364
+ * Threshold of the inverted swap zone
365
+ * (will be set to `swapThreshold` value by default)
366
+ */
367
+ invertedSwapThreshold?: number | undefined
368
+ /**
369
+ * Call `event.preventDefault()` when triggered `filter`
370
+ */
371
+ preventOnFilter?: boolean | undefined
372
+ /**
373
+ * Remove the clone element when it is not showing,
374
+ * rather than just hiding it
375
+ */
376
+ removeCloneOnHide?: boolean | undefined
377
+ /**
378
+ * sorting inside list
379
+ */
380
+ sort?: boolean | undefined
381
+ store?:
382
+ | {
383
+ get: (sortable: Sortable) => string[]
384
+ set: (sortable: Sortable) => void
385
+ }
386
+ | undefined
387
+ /**
388
+ * Threshold of the swap zone.
389
+ * Defaults to `1`
390
+ */
391
+ swapThreshold?: number | undefined
392
+ /**
393
+ * How many *pixels* the point should move before cancelling a delayed drag event
394
+ */
395
+ touchStartThreshold?: number | undefined
396
+
397
+ setData?: ((dataTransfer: DataTransfer, draggedElement: HTMLElement) => void) | undefined
398
+ /**
399
+ * Element dragging started
400
+ */
401
+ onStart?: ((event: SortableEvent) => void) | undefined
402
+ /**
403
+ * Element dragging ended
404
+ */
405
+ onEnd?: ((event: SortableEvent) => void) | undefined
406
+ /**
407
+ * Element is dropped into the list from another list
408
+ */
409
+ onAdd?: ((event: SortableEvent) => void) | undefined
410
+ /**
411
+ * Created a clone of an element
412
+ */
413
+ onClone?: ((event: SortableEvent) => void) | undefined
414
+ /**
415
+ * Element is chosen
416
+ */
417
+ onChoose?: ((event: SortableEvent) => void) | undefined
418
+ /**
419
+ * Element is unchosen
420
+ */
421
+ onUnchoose?: ((event: SortableEvent) => void) | undefined
422
+ /**
423
+ * Changed sorting within list
424
+ */
425
+ onUpdate?: ((event: SortableEvent) => void) | undefined
426
+ /**
427
+ * Called by any change to the list (add / update / remove)
428
+ */
429
+ onSort?: ((event: SortableEvent) => void) | undefined
430
+ /**
431
+ * Element is removed from the list into another list
432
+ */
433
+ onRemove?: ((event: SortableEvent) => void) | undefined
434
+ /**
435
+ * Attempt to drag a filtered element
436
+ */
437
+ onFilter?: ((event: SortableEvent) => void) | undefined
438
+ /**
439
+ * Event when you move an item in the list or between lists
440
+ */
441
+ // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
442
+ onMove?: ((evt: MoveEvent, originalEvent: Event) => boolean | -1 | 1 | void) | undefined
443
+ /**
444
+ * Called when dragging element changes position
445
+ */
446
+ onChange?: ((evt: SortableEvent) => void) | undefined
447
+ }
448
+
449
+ interface Utils {
450
+ /**
451
+ * Attach an event handler function
452
+ * @param element an HTMLElement.
453
+ * @param event an Event context.
454
+ * @param fn
455
+ */
456
+ on(element: HTMLElement, event: string, fn: EventListenerOrEventListenerObject): void
457
+
458
+ /**
459
+ * Remove an event handler function
460
+ * @param element an HTMLElement.
461
+ * @param event an Event context.
462
+ * @param fn a callback.
463
+ */
464
+ off(element: HTMLElement, event: string, fn: EventListenerOrEventListenerObject): void
465
+
466
+ /**
467
+ * Get the values of all the CSS properties.
468
+ * @param element an HTMLElement.
469
+ */
470
+ css(element: HTMLElement): CSSStyleDeclaration
471
+
472
+ /**
473
+ * Get the value of style properties.
474
+ * @param element an HTMLElement.
475
+ * @param prop a property key.
476
+ */
477
+ css<K extends keyof CSSStyleDeclaration>(element: HTMLElement, prop: K): CSSStyleDeclaration[K]
478
+
479
+ /**
480
+ * Set one CSS property.
481
+ * @param element an HTMLElement.
482
+ * @param prop a property key.
483
+ * @param value a property value.
484
+ */
485
+ css<K extends keyof CSSStyleDeclaration>(
486
+ element: HTMLElement,
487
+ prop: K,
488
+ value: CSSStyleDeclaration[K],
489
+ ): void
490
+
491
+ /**
492
+ * Get elements by tag name.
493
+ * @param context an HTMLElement.
494
+ * @param tagName A tag name.
495
+ * @param iterator An iterator.
496
+ */
497
+ find(
498
+ context: HTMLElement,
499
+ tagName: string,
500
+ iterator?: (value: HTMLElement, index: number) => void,
501
+ ): NodeListOf<HTMLElement>
502
+
503
+ /**
504
+ * Check the current matched set of elements against a selector.
505
+ * @param element an HTMLElement.
506
+ * @param selector an element selector.
507
+ */
508
+ is(element: HTMLElement, selector: string): boolean
509
+
510
+ /**
511
+ * For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
512
+ * @param element an HTMLElement.
513
+ * @param selector an element seletor.
514
+ * @param context a specific element's context.
515
+ */
516
+ closest(element: HTMLElement, selector: string, context?: HTMLElement): HTMLElement | null
517
+
518
+ /**
519
+ * Add or remove one classes from each element
520
+ * @param element an HTMLElement.
521
+ * @param name a class name.
522
+ * @param state a class's state.
523
+ */
524
+ toggleClass(element: HTMLElement, name: string, state: boolean): void
525
+
526
+ /**
527
+ * Selects the provided multi-drag item
528
+ * @param element The element to be selected
529
+ */
530
+ select(element: HTMLElement): void
531
+
532
+ /**
533
+ * Deselects the provided multi-drag item
534
+ * @param element The element to be deselected
535
+ */
536
+ deselect(element: HTMLElement): void
537
+ }
538
+
539
+ interface DOMRect {
540
+ bottom: number
541
+ height: number
542
+ left: number
543
+ right: number
544
+ top: number
545
+ width: number
546
+ x: number
547
+ y: number
548
+ }
549
+ }
@@ -0,0 +1,117 @@
1
+ import * as Sortable from './index'
2
+ import { SortableEvent } from './index'
3
+
4
+ declare class SortablePlugin {}
5
+ declare class AutoScrollPlugin {}
6
+ declare class OnSpillPlugin {}
7
+ declare class MultiDragPlugin {}
8
+ declare class SwapPlugin {}
9
+ declare class FlatTreePlugin {}
10
+
11
+ export interface FlatTreeOptions {
12
+ /**
13
+ * Enable the plugin.
14
+ */
15
+ tree?: boolean
16
+ /**
17
+ * Enable the plugin.
18
+ */
19
+ treeItemLevelAttr?: string
20
+ treeIndentThreshold?: number
21
+ }
22
+ export interface AutoScrollOptions {
23
+ /**
24
+ * Enable the plugin. Can be `HTMLElement`.
25
+ */
26
+ scroll?: boolean | HTMLElement | undefined
27
+ /**
28
+ * force the autoscroll fallback to kick in
29
+ */
30
+ forceAutoScrollFallback?: boolean | undefined
31
+ /**
32
+ * if you have custom scrollbar scrollFn may be used for autoscrolling.
33
+ */
34
+ scrollFn?:
35
+ | ((
36
+ this: Sortable,
37
+ offsetX: number,
38
+ offsetY: number,
39
+ originalEvent: Event,
40
+ touchEvt: TouchEvent,
41
+ hoverTargetEl: HTMLElement,
42
+ // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
43
+ ) => 'continue' | void)
44
+ | undefined
45
+ /**
46
+ * `px`, how near the mouse must be to an edge to start scrolling.
47
+ */
48
+ scrollSensitivity?: number | undefined
49
+ /**
50
+ * `px`, speed of the scrolling.`
51
+ */
52
+ scrollSpeed?: number | undefined
53
+ /**
54
+ * apply autoscroll to all parent elements, allowing for easier movement.
55
+ */
56
+ bubbleScroll?: boolean | undefined
57
+ }
58
+ export interface OnSpillOptions {
59
+ /**
60
+ * This plugin, when enabled,
61
+ * will cause the dragged item to be reverted to it's original position if it is *spilled*
62
+ * (ie. it is dropped outside of a valid Sortable drop target)
63
+ */
64
+ revertOnSpill?: boolean | undefined
65
+ /**
66
+ * This plugin, when enabled,
67
+ * will cause the dragged item to be removed from the DOM if it is *spilled*
68
+ * (ie. it is dropped outside of a valid Sortable drop target)
69
+ */
70
+ removeOnSpill?: boolean | undefined
71
+ /**
72
+ * Called when either `revertOnSpill` or `RemoveOnSpill` plugins are enabled.
73
+ */
74
+ onSpill?: ((evt: SortableEvent) => void) | undefined
75
+ }
76
+ export interface MultiDragOptions {
77
+ /**
78
+ * Enable the plugin
79
+ */
80
+ multiDrag?: boolean | undefined
81
+ /**
82
+ * Class name for selected item
83
+ */
84
+ selectedClass?: string | undefined
85
+ /**
86
+ * The key that must be down for multiple items to be selected.
87
+ * The default is null, meaning no key must be down.
88
+ * For special keys, such as the CTRL key,
89
+ * simply specify the option as 'CTRL' (casing does not matter).
90
+ */
91
+ multiDragKey?: null | undefined | string
92
+
93
+ /**
94
+ * If you don't want to deselect items on outside click
95
+ */
96
+ avoidImplicitDeselect?: boolean | undefined
97
+
98
+ /**
99
+ * Called when an item is selected
100
+ */
101
+ onSelect?: ((event: SortableEvent) => void) | undefined
102
+
103
+ /**
104
+ * Called when an item is deselected
105
+ */
106
+ onDeselect?: ((event: SortableEvent) => void) | undefined
107
+ }
108
+ export interface SwapOptions {
109
+ /**
110
+ * Enable swap mode
111
+ */
112
+ swap?: boolean | undefined
113
+ /**
114
+ * Class name for swap item (if swap mode is enabled)
115
+ */
116
+ swapClass?: string | undefined
117
+ }