svelte-dnd-action 0.9.79 → 0.9.80
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/README.md +14 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +533 -293
- package/dist/index.mjs +533 -293
- package/package.json +1 -1
- package/src/constants.js +1 -0
- package/src/helpers/aria.js +50 -28
- package/src/helpers/dispatcher.js +12 -8
- package/src/helpers/intersection.js +17 -12
- package/src/helpers/multiScroller.js +8 -10
- package/src/helpers/observer.js +14 -4
- package/src/helpers/scroller.js +5 -4
- package/src/helpers/styler.js +9 -6
- package/src/helpers/util.js +31 -0
- package/src/keyboardAction.js +201 -84
- package/src/pointerAction.js +109 -79
- package/src/wrappers/withDragHandles.js +11 -5
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ An options-object with the following attributes:
|
|
|
116
116
|
| `dropTargetStyle` | Object<String> | No | `{outline: 'rgba(255, 255, 102, 0.7) solid 2px'}` | An object of styles to apply to the dnd-zone when items can be dragged into it. Note: the styles override any inline styles applied to the dnd-zone. When the styles are removed, any original inline styles will be lost |
|
|
117
117
|
| `dropTargetClasses`| Array<String> | No | `[]` | A list of classes to apply to the dnd-zone when items can be dragged into it. Note: make sure the classes you use are global. |
|
|
118
118
|
| `transformDraggedElement` | Function | No | `() => {}` | A function that is invoked when the draggable element enters the dnd-zone or hover overs a new index in the current dnd-zone. <br />Signature:<br />function(element, data, index) {}<br />**element**: The dragged element. <br />**data**: The data of the item from the items array.<br />**index**: The index the dragged element will become in the new dnd-zone.<br /><br />This allows you to override properties on the dragged element, such as innerHTML to change how it displays. If what you are after is altering styles, do it to the children, not to the dragged element itself |
|
|
119
|
-
| `autoAriaDisabled` | Boolean | No | `false` | Setting it to true will disable all the automatically added aria attributes and aria alerts (for example when the user starts/ stops dragging using the keyboard).<br /> **Use it only if you intend to implement your own custom instructions, roles and alerts.** In such a case, you might find the exported function `alertToScreenReader(string)` useful. <br />**If you only want to change the wording (ex: to translate it), use `setAriaStrings` instead and leave this off.** |
|
|
119
|
+
| `autoAriaDisabled` | Boolean | No | `false` | Setting it to true will disable all the automatically added aria attributes and aria alerts (for example when the user starts/ stops dragging using the keyboard).<br /> **Use it only if you intend to implement your own custom instructions, roles and alerts.** In such a case, you might find the exported function `alertToScreenReader(string, document?)` useful (pass the zone's document when the zone is in another window, such as an iframe or a popup). <br />**If you only want to change the wording (ex: to translate it), use `setAriaStrings` instead and leave this off.** |
|
|
120
120
|
| `centreDraggedOnCursor` | Boolean | No | `false` | Setting it to true will cause elements from this dnd-zone to position their center on the cursor on drag start, effectively turning the cursor to the focal point that triggers all the dnd events (ex: entering another zone). Useful for dnd-zones with large items that can be dragged over small items. |
|
|
121
121
|
| `useCursorForDetection` | Boolean | No | `false` | Setting it to true will use the cursor position instead of the dragged element's center for drop zone detection. This improves accuracy when dragging large elements over small drop targets. Unlike `centreDraggedOnCursor`, this option does not reposition the dragged element. |
|
|
122
122
|
| `dropAnimationDisabled` | Boolean | No | `false` | Setting it to true will disable the animation of the dropped element to its final place. |
|
|
@@ -309,6 +309,7 @@ Notes:
|
|
|
309
309
|
- [Super basic, single list, no animation](https://svelte.dev/playground/bbd709b1a00b453e94658392c97a018a?version=3)
|
|
310
310
|
- [Super basic, single list, with animation](https://svelte.dev/playground/3d544791e5c24fd4aa1eb983d749f776?version=3)
|
|
311
311
|
- [Multiple dndzones, multiple types](https://svelte.dev/playground/4d23eb3b9e184b90b58f0867010ad258?version=3)
|
|
312
|
+
- [Zones in same-origin iframes and popup windows](https://svelte.dev/playground/be37a2f642a14a21ae8c5c11bf0a8055?version=4.2.20) — for the full demo, log in, fork/save and reload, or download/run locally; Playground isolates other documents for visitors.
|
|
312
313
|
- [Board (nested zones and multiple types), scrolling containers, scrolling page](https://svelte.dev/playground/e2ef044af75c4b16b424b8219fb31fd9?version=3)
|
|
313
314
|
- [Experimental: make an entire board skippable in the Tab order while preserving keyboard drag and drop](https://svelte.dev/playground/14286b9c0f924d8e94d5267d219f8424?version=5.56.8) — a prototype wrapper built using the existing tabindex options; see the example for current limitations.
|
|
314
315
|
- [Selectively enable/disable drag/drop](https://svelte.dev/playground/44c9229556f3456e9883c10fc0aa0ee9?version=3)
|
|
@@ -332,6 +333,18 @@ Notes:
|
|
|
332
333
|
- [Fade in/out but without using Svelte transitions](https://svelte.dev/playground/3f1e68203ef140969a8240eba3475a8d?version=3)
|
|
333
334
|
- [Nested fade in/out without using Svelte transitions](https://svelte.dev/playground/49b09aedfe0543b4bc8f575c8dbf9a53?version=3)
|
|
334
335
|
|
|
336
|
+
### Zones in iframes and other windows
|
|
337
|
+
|
|
338
|
+
A dndzone can live in another window than the one that loaded the library: a same-origin iframe, a popup opened with `window.open`, or another Electron window. Each zone uses its own window's events, timers and document, so drags keep working while the loading window is hidden.
|
|
339
|
+
|
|
340
|
+
This is useful when one app mounts components into several documents (for example, a pop-out editor). A self-contained iframe that loads its own app and imports the library there could already use it without this feature. The difference is that the code can now be loaded in one document while its zones live in another; it does not add dragging between documents.
|
|
341
|
+
|
|
342
|
+
See the [official example REPL](https://svelte.dev/playground/be37a2f642a14a21ae8c5c11bf0a8055?version=4.2.20) and its [source and setup instructions](examples/other-windows/README.md). For iframe/popup interaction inside Playground, fork/save and reload under your account, or download and run locally.
|
|
343
|
+
|
|
344
|
+
- Both pointer and keyboard drags stay in the document they started in. They can move items between eligible same-type zones inside that document, but not between the page and an iframe, between sibling iframes, or between popup windows.
|
|
345
|
+
- Each document with zones gets its own screen-reader instructions and announcements. For a custom announcement about a zone in another document, pass that document: `alertToScreenReader(text, zone.ownerDocument)`.
|
|
346
|
+
- If a window closes, or an iframe is removed, during a drag, the drag ends and the zones get their usual `finalize` event (pointer) or `consider` event with the `dragStopped` trigger (keyboard).
|
|
347
|
+
|
|
335
348
|
### Rules/ assumptions to keep in mind
|
|
336
349
|
|
|
337
350
|
- Only one element can be dragged in any given time
|
package/dist/index.d.ts
CHANGED
|
@@ -79,8 +79,10 @@ export interface DndZoneAttributes<T> {
|
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* Will make the screen reader alert the provided text to the user
|
|
82
|
+
* @param doc - the document to announce in, for a zone in another window such as an iframe or a popup.
|
|
83
|
+
* Defaults to the document that loaded the library.
|
|
82
84
|
*/
|
|
83
|
-
export declare function alertToScreenReader(txt: string): void;
|
|
85
|
+
export declare function alertToScreenReader(txt: string, doc?: Document): void;
|
|
84
86
|
|
|
85
87
|
// Every message key receives the same core context - itemLabel, zoneLabel, position, count -
|
|
86
88
|
// so a consumer can word any of them positionally. Only dragStarted carries an extra.
|