@bevelo/dnd 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/a11y-BOpF8vx8.d.cts +30 -0
- package/dist/a11y-Bbm_a0mw.d.ts +30 -0
- package/dist/index-DDuIvuzA.d.cts +258 -0
- package/dist/index-kH3SGg1R.d.ts +258 -0
- package/dist/index.cjs +413 -0
- package/dist/index.d.cts +139 -0
- package/dist/index.d.ts +139 -0
- package/dist/index.js +357 -0
- package/dist/live/animate-settle.cjs +20 -0
- package/dist/live/animate-settle.d.cts +14 -0
- package/dist/live/animate-settle.d.ts +14 -0
- package/dist/live/animate-settle.js +19 -0
- package/dist/live/flip.cjs +39 -0
- package/dist/live/flip.d.cts +9 -0
- package/dist/live/flip.d.ts +9 -0
- package/dist/live/flip.js +38 -0
- package/dist/live/index.cjs +22 -0
- package/dist/live/index.d.cts +4 -0
- package/dist/live/index.d.ts +4 -0
- package/dist/live/index.js +4 -0
- package/dist/live-BUYwbSUp.cjs +899 -0
- package/dist/live-Clc3aswx.js +840 -0
- package/dist/pure/a11y.cjs +85 -0
- package/dist/pure/a11y.d.cts +2 -0
- package/dist/pure/a11y.d.ts +2 -0
- package/dist/pure/a11y.js +81 -0
- package/dist/pure/apply.cjs +130 -0
- package/dist/pure/apply.d.cts +29 -0
- package/dist/pure/apply.d.ts +29 -0
- package/dist/pure/apply.js +127 -0
- package/dist/pure/reorder.cjs +121 -0
- package/dist/pure/reorder.d.cts +77 -0
- package/dist/pure/reorder.d.ts +77 -0
- package/dist/pure/reorder.js +117 -0
- package/dist/pure/sensors.cjs +243 -0
- package/dist/pure/sensors.d.cts +2 -0
- package/dist/pure/sensors.d.ts +2 -0
- package/dist/pure/sensors.js +240 -0
- package/dist/pure/spatial.cjs +121 -0
- package/dist/pure/spatial.d.cts +64 -0
- package/dist/pure/spatial.d.ts +64 -0
- package/dist/pure/spatial.js +119 -0
- package/dist/pure/state.cjs +15 -0
- package/dist/pure/state.d.cts +2 -0
- package/dist/pure/state.d.ts +2 -0
- package/dist/pure/state.js +1 -0
- package/dist/pure/tree.cjs +164 -0
- package/dist/pure/tree.d.cts +36 -0
- package/dist/pure/tree.d.ts +36 -0
- package/dist/pure/tree.js +161 -0
- package/dist/rows-B2C7Yf94.cjs +56 -0
- package/dist/rows-BIT_Rkhr.js +45 -0
- package/dist/sensors-C9RnMr6P.d.cts +212 -0
- package/dist/sensors-C9RnMr6P.d.ts +212 -0
- package/dist/settle-BiwZ0ZDt.js +235 -0
- package/dist/settle-COFsW7ul.cjs +282 -0
- package/dist/settle-Dl5Y9uOw.d.ts +59 -0
- package/dist/settle-DzdqbH4S.d.cts +59 -0
- package/dist/state-BEKGNZY1.d.cts +323 -0
- package/dist/state-BEKGNZY1.d.ts +323 -0
- package/dist/state-BK9W_RZn.cjs +672 -0
- package/dist/state-CYXS6GIb.js +595 -0
- package/package.json +89 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bevelo contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @bevelo/dnd
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Drag and drop as data. `dragReducer` advances one drag from lift to drop, pointer and
|
|
4
|
+
keyboard alike, and derives the target, the shifts and the drop result from the state. The
|
|
5
|
+
apply helpers turn a drop result into new app data by key. `createDnd` is the one DOM
|
|
6
|
+
coordinator: zones, items, the preview and the live region. One list zone with pointer and
|
|
7
|
+
keyboard moves is the core; several zones, trees, virtual zones, selection, copy, swap and
|
|
8
|
+
link, autoscroll and resize observation are plugins passed in `plugins`, so an app ships
|
|
9
|
+
only the ones it imports.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pnpm add @bevelo/dnd
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { createDnd } from "@bevelo/dnd/dom";
|
|
21
|
+
import { applyListDrop } from "@bevelo/dnd/apply";
|
|
22
|
+
|
|
23
|
+
const dnd = createDnd({
|
|
24
|
+
onDrop: (result) => render(applyListDrop(items, result, { key: (item) => item.id })),
|
|
25
|
+
});
|
|
26
|
+
dnd.zone({ id: "list", items: items.map((item) => item.id) }).attach(listElement);
|
|
27
|
+
for (const row of rows) dnd.item(row.dataset.id, row);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Drop animations
|
|
31
|
+
|
|
32
|
+
`createDnd` snaps a drop into place unless you pass `settle`. `animateSettle()` from
|
|
33
|
+
`@bevelo/dnd/animate-settle` runs a timed FLIP on the Web Animations API (200 ms by default)
|
|
34
|
+
and adds about 0.5 kB. `springSettle()` from `@bevelo/dnd/flip` runs the same FLIP on a
|
|
35
|
+
spring from `@bevelo/motion` and adds about 2 kB. Measured with
|
|
36
|
+
`node scripts/check-size.mjs --verbose --only dnd/` (fully minified, gzip level 9): a list
|
|
37
|
+
is 11,901 B, a kanban (`boardZones`, `operations`, `autoscroll`) with no settle 13,717 B,
|
|
38
|
+
with `animateSettle` 14,233 B and with `springSettle` 15,753 B.
|
|
39
|
+
|
|
40
|
+
## Stability
|
|
41
|
+
|
|
42
|
+
Spatial navigation, sensors, reorder and transform are `@stable` and follow semver. The drag
|
|
43
|
+
state, tree projection, apply helpers, announcements, gestures, measurement and the
|
|
44
|
+
coordinator are `@experimental` and may change in any minor release.
|
|
45
|
+
|
|
46
|
+
## Docs
|
|
47
|
+
|
|
48
|
+
See the drag-and-drop and direct-manipulation pages in the
|
|
49
|
+
[Bevelo docs](https://github.com/bevelo/bevelo/tree/main/apps/docs/src/content/docs/core/behaviors).
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { b as Operation, c as DragState } from "./state-BEKGNZY1.cjs";
|
|
2
|
+
interface MessageContext {
|
|
3
|
+
readonly label: string;
|
|
4
|
+
/** How many ids travel, the primary included. */
|
|
5
|
+
readonly count: number;
|
|
6
|
+
readonly operation: Operation | null;
|
|
7
|
+
/** 1-based position among the target's siblings. */
|
|
8
|
+
readonly position: number;
|
|
9
|
+
readonly total: number;
|
|
10
|
+
/** The tree parent of the gap, or null at the root and in lists. */
|
|
11
|
+
readonly parentLabel: string | null;
|
|
12
|
+
/** The swap or link target, or null for a gap. */
|
|
13
|
+
readonly targetLabel: string | null;
|
|
14
|
+
readonly depth: number;
|
|
15
|
+
}
|
|
16
|
+
interface DragMessages {
|
|
17
|
+
lift(c: MessageContext): string;
|
|
18
|
+
move(c: MessageContext): string;
|
|
19
|
+
blocked(c: MessageContext): string;
|
|
20
|
+
drop(c: MessageContext): string;
|
|
21
|
+
cancel(c: MessageContext): string;
|
|
22
|
+
}
|
|
23
|
+
/** English. */
|
|
24
|
+
declare const defaultMessages: DragMessages;
|
|
25
|
+
declare const keyboardInstructions = "Press space to lift. Arrow keys move, Alt copies, space drops, escape cancels.";
|
|
26
|
+
/** One message for a state change, or undefined when nothing a listener can notice changed. */
|
|
27
|
+
declare function announcement(prev: DragState, next: DragState, messages: DragMessages, label: (key: string) => string): string | undefined;
|
|
28
|
+
/** role, tabindex, aria-roledescription, aria-describedby, and aria-pressed while lifted. */
|
|
29
|
+
declare function handleAttributes(state: DragState, key: string, instructionsId: string): Readonly<Record<string, string>>;
|
|
30
|
+
export { handleAttributes as a, defaultMessages as i, MessageContext as n, keyboardInstructions as o, announcement as r, DragMessages as t };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { b as Operation, c as DragState } from "./state-BEKGNZY1.js";
|
|
2
|
+
interface MessageContext {
|
|
3
|
+
readonly label: string;
|
|
4
|
+
/** How many ids travel, the primary included. */
|
|
5
|
+
readonly count: number;
|
|
6
|
+
readonly operation: Operation | null;
|
|
7
|
+
/** 1-based position among the target's siblings. */
|
|
8
|
+
readonly position: number;
|
|
9
|
+
readonly total: number;
|
|
10
|
+
/** The tree parent of the gap, or null at the root and in lists. */
|
|
11
|
+
readonly parentLabel: string | null;
|
|
12
|
+
/** The swap or link target, or null for a gap. */
|
|
13
|
+
readonly targetLabel: string | null;
|
|
14
|
+
readonly depth: number;
|
|
15
|
+
}
|
|
16
|
+
interface DragMessages {
|
|
17
|
+
lift(c: MessageContext): string;
|
|
18
|
+
move(c: MessageContext): string;
|
|
19
|
+
blocked(c: MessageContext): string;
|
|
20
|
+
drop(c: MessageContext): string;
|
|
21
|
+
cancel(c: MessageContext): string;
|
|
22
|
+
}
|
|
23
|
+
/** English. */
|
|
24
|
+
declare const defaultMessages: DragMessages;
|
|
25
|
+
declare const keyboardInstructions = "Press space to lift. Arrow keys move, Alt copies, space drops, escape cancels.";
|
|
26
|
+
/** One message for a state change, or undefined when nothing a listener can notice changed. */
|
|
27
|
+
declare function announcement(prev: DragState, next: DragState, messages: DragMessages, label: (key: string) => string): string | undefined;
|
|
28
|
+
/** role, tabindex, aria-roledescription, aria-describedby, and aria-pressed while lifted. */
|
|
29
|
+
declare function handleAttributes(state: DragState, key: string, instructionsId: string): Readonly<Record<string, string>>;
|
|
30
|
+
export { handleAttributes as a, defaultMessages as i, MessageContext as n, keyboardInstructions as o, announcement as r, DragMessages as t };
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { t as DragMessages } from "./a11y-BOpF8vx8.cjs";
|
|
2
|
+
import { A as ZoneBase, D as TreeRules, b as Operation, c as DragState, d as DropResult, k as Zone, l as Dragging, o as DragPlugin, r as DragConfig, x as Outline } from "./state-BEKGNZY1.cjs";
|
|
3
|
+
import { i as SettleStrategy } from "./settle-DzdqbH4S.cjs";
|
|
4
|
+
import { AutoscrollPolicy } from "@bevelo/runtime/geometry";
|
|
5
|
+
import { ActivationOptions, Axis as Axis$1, FrameLoop, ItemTrack as ItemTrack$1, Point as Point$1, ReadableStore, Rect as Rect$1, Scroller, TrackSource } from "@bevelo/runtime";
|
|
6
|
+
interface Preview {
|
|
7
|
+
readonly el: HTMLElement;
|
|
8
|
+
/** True when the engine created `el` and removes it after the drop. */
|
|
9
|
+
readonly owned: boolean;
|
|
10
|
+
/** Read pass: the viewport top-left the writer translates from; absent, the element's layout rect. */
|
|
11
|
+
readonly base?: () => Point$1;
|
|
12
|
+
}
|
|
13
|
+
/** Builds the preview at lift from the item, the registered overlay element and the item's layout rect. */
|
|
14
|
+
type PreviewStrategy = (item: HTMLElement, overlay: HTMLElement | null, rect: Rect$1) => Preview;
|
|
15
|
+
/** The item itself follows the pointer. The default. */
|
|
16
|
+
declare const inPlacePreview: PreviewStrategy;
|
|
17
|
+
/** A fixed clone of the item, which no clipping column can hide. */
|
|
18
|
+
declare const clonePreview: PreviewStrategy;
|
|
19
|
+
/** The element registered with `overlay`; a clone while none is registered. */
|
|
20
|
+
declare const overlayPreview: PreviewStrategy;
|
|
21
|
+
/** Where the engine's paint goes. One channel per coordinator; `reset` restores what it wrote. */
|
|
22
|
+
interface DragChannel {
|
|
23
|
+
/** Translates `el` by `by`; null puts it back. */
|
|
24
|
+
move(el: HTMLElement, by: Point$1 | null): void;
|
|
25
|
+
/** Hides a move's source while it travels, or shows it again. */
|
|
26
|
+
hide(el: HTMLElement, hidden: boolean): void;
|
|
27
|
+
/** A settle's inverse transform, from the top-left corner. A channel that leaves it to the animation omits it. */
|
|
28
|
+
readonly inverse?: (el: HTMLElement, transform: string) => void;
|
|
29
|
+
/**
|
|
30
|
+
* The offset `el` is painted at right now, when a stylesheet animates the translate this
|
|
31
|
+
* channel feeds and the paint lags what was written; undefined when it is what was written.
|
|
32
|
+
*/
|
|
33
|
+
readonly painted?: (el: Element) => Point$1 | undefined;
|
|
34
|
+
reset(): void;
|
|
35
|
+
}
|
|
36
|
+
/** Builds a coordinator's channel: `styleChannel` (the default) or `varsChannel`. */
|
|
37
|
+
type DragChannelFactory = () => DragChannel;
|
|
38
|
+
/**
|
|
39
|
+
* Inline `transform` and `visibility`, each element's own value remembered at the first write
|
|
40
|
+
* and restored by `reset`. The default.
|
|
41
|
+
*/
|
|
42
|
+
declare const styleChannel: DragChannelFactory;
|
|
43
|
+
/** The custom properties `varsChannel` writes. */
|
|
44
|
+
declare const DRAG_X = "--bevelo-drag-x";
|
|
45
|
+
declare const DRAG_Y = "--bevelo-drag-y";
|
|
46
|
+
/** The attribute `varsChannel` sets on a hidden move source. */
|
|
47
|
+
declare const DRAG_HIDDEN = "data-drag-hidden";
|
|
48
|
+
/**
|
|
49
|
+
* The engine's own channel: `--bevelo-drag-x` and `--bevelo-drag-y` (px) for every translate,
|
|
50
|
+
* and `data-drag-hidden` on a hidden move source. It never writes `transform` or `visibility`,
|
|
51
|
+
* so a part whose `style` a framework renders keeps it; the stylesheet consumes the channel:
|
|
52
|
+
*
|
|
53
|
+
* ```css
|
|
54
|
+
* @property --bevelo-drag-x { syntax: "<length>"; inherits: false; initial-value: 0px; }
|
|
55
|
+
* @property --bevelo-drag-y { syntax: "<length>"; inherits: false; initial-value: 0px; }
|
|
56
|
+
* [data-part] { translate: var(--bevelo-drag-x) var(--bevelo-drag-y); }
|
|
57
|
+
* [data-drag-hidden] { visibility: hidden; }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* A settle paints no inverse: `animateSettle` animates `transform` with the Web Animations
|
|
61
|
+
* API, which writes no inline style, and `springSettle` springs these same properties.
|
|
62
|
+
*/
|
|
63
|
+
declare const varsChannel: DragChannelFactory;
|
|
64
|
+
/** What every zone spec has. */
|
|
65
|
+
interface ZoneSpecBase {
|
|
66
|
+
readonly id: string;
|
|
67
|
+
/** Main axis of the zone's items. Default "y". */
|
|
68
|
+
readonly axis?: Axis$1;
|
|
69
|
+
readonly disabled?: boolean;
|
|
70
|
+
}
|
|
71
|
+
/** A measured zone: the host renders `items` in order. */
|
|
72
|
+
interface ItemsShape {
|
|
73
|
+
/** The zone's order. A change after a drop is the signal that the app committed. */
|
|
74
|
+
readonly items: readonly string[];
|
|
75
|
+
readonly source?: never;
|
|
76
|
+
}
|
|
77
|
+
/** A zone over a virtualizer's rows, with `virtualZones()`. */
|
|
78
|
+
interface SourceShape {
|
|
79
|
+
/** A virtualizer's rows: every key, mounted or not. */
|
|
80
|
+
readonly source: TrackSource;
|
|
81
|
+
readonly items?: never;
|
|
82
|
+
}
|
|
83
|
+
/** A tree zone's rules and its hover hook, with `treeZones()`. */
|
|
84
|
+
type TreeSpec = TreeRules & {
|
|
85
|
+
/** Hears the row the preview rests on (null when it leaves every row); `expandAfter` turns a long rest into an expand. */
|
|
86
|
+
readonly expand?: (key: string | null) => void;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* What a host registers for one drop zone: `items` in the core, and the shapes and fields its
|
|
90
|
+
* plugins add. `Shape` is an alternative to `items`; `Extra` is added to every spec.
|
|
91
|
+
*/
|
|
92
|
+
type ZoneSpec<Shape = never, Extra = never> = ZoneSpecBase & ([Extra] extends [never] ? unknown : Extra) & (ItemsShape | Shape);
|
|
93
|
+
/** A spec as the engine reads it, whatever its plugins. */
|
|
94
|
+
type AnyZoneSpec = ZoneSpecBase & {
|
|
95
|
+
readonly items?: readonly string[];
|
|
96
|
+
readonly source?: TrackSource;
|
|
97
|
+
readonly tree?: TreeSpec;
|
|
98
|
+
};
|
|
99
|
+
interface ZoneRecord {
|
|
100
|
+
spec: AnyZoneSpec;
|
|
101
|
+
el: HTMLElement | null;
|
|
102
|
+
/** The measured track is stale. */
|
|
103
|
+
dirty: boolean;
|
|
104
|
+
track: ItemTrack$1 | null;
|
|
105
|
+
zone: Zone | null;
|
|
106
|
+
/** What `zone` was built from; an equal list reuses it. */
|
|
107
|
+
inputs: readonly unknown[];
|
|
108
|
+
scrollers: readonly Scroller[] | null;
|
|
109
|
+
stopSize?: (() => void) | undefined;
|
|
110
|
+
}
|
|
111
|
+
/** How a plugin reads a zone: its origin and track, and the zone it builds over the base. */
|
|
112
|
+
interface ZoneReader {
|
|
113
|
+
/** The origin and track of a zone the engine does not measure; undefined measures it. */
|
|
114
|
+
readonly measure?: (spec: AnyZoneSpec) => {
|
|
115
|
+
readonly origin: Point$1;
|
|
116
|
+
readonly track: ItemTrack$1;
|
|
117
|
+
} | undefined;
|
|
118
|
+
/** The zone over `base`; undefined makes it a list. `spec` reads the host's latest spec. */
|
|
119
|
+
readonly build?: (base: ZoneBase, spec: () => AnyZoneSpec) => Zone | undefined;
|
|
120
|
+
/** Watches an attached zone element; `stale` re-measures its track. Returns the unwatch. */
|
|
121
|
+
readonly observe?: (el: HTMLElement, stale: () => void) => () => void;
|
|
122
|
+
}
|
|
123
|
+
/** What a plugin sees of the running drag. One per drag, from lift until it settles. */
|
|
124
|
+
interface LiveDrag {
|
|
125
|
+
readonly frame: FrameLoop;
|
|
126
|
+
/** The drag now; null once it dropped. */
|
|
127
|
+
state(): Dragging | null;
|
|
128
|
+
/** The registered zones, live. */
|
|
129
|
+
readonly zones: ReadonlySet<ZoneRecord>;
|
|
130
|
+
/** Scratch space a plugin keeps for the length of one drag. */
|
|
131
|
+
readonly memo: Record<string, unknown>;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* A coordinator plugin: reducer hooks plus the live ones below. Pass plugins in `plugins`;
|
|
135
|
+
* one that is never imported ships none of its code. The type parameters say what it allows:
|
|
136
|
+
* operations, a zone spec shape beside `items`, and fields on every zone spec.
|
|
137
|
+
*/
|
|
138
|
+
interface DndPlugin<Op extends Operation = never, Shape = never, Extra = never> extends DragPlugin<Op, Shape, Extra>, ZoneReader {
|
|
139
|
+
/** `selection()`: the keys chosen when a lift starts. */
|
|
140
|
+
readonly ids?: () => Iterable<string>;
|
|
141
|
+
/** Runs once a drag lifted, with how; returns what undoes it when the drag ends. */
|
|
142
|
+
readonly lift?: (drag: LiveDrag, pointer: boolean) => (() => void) | undefined;
|
|
143
|
+
/** Hears every state change of a drag; null once it ends. */
|
|
144
|
+
readonly change?: (drag: LiveDrag, state: Dragging | null) => void;
|
|
145
|
+
/** What a zone's commit signal is when it is not its `items`. */
|
|
146
|
+
readonly signal?: (spec: AnyZoneSpec) => unknown;
|
|
147
|
+
/** Read pass of a keyboard step: the write that brings `index` of the zone into view, or undefined to scroll it the measured way. */
|
|
148
|
+
readonly reveal?: (spec: AnyZoneSpec, index: number) => (() => void) | undefined;
|
|
149
|
+
}
|
|
150
|
+
/** Plugins as `createDnd` takes them. */
|
|
151
|
+
type DndPlugins = readonly DndPlugin<any, any, any>[];
|
|
152
|
+
type TypesOf<P> = P extends DragPlugin<infer Op, infer Shape, infer Extra> ? {
|
|
153
|
+
op: Op;
|
|
154
|
+
shape: Shape;
|
|
155
|
+
extra: Extra;
|
|
156
|
+
} : never;
|
|
157
|
+
type Intersect<U> = (U extends unknown ? (u: U) => void : never) extends ((i: infer I) => void) ? I : never;
|
|
158
|
+
/** The operations `plugins` allow: `operations()`'s list, else "move". */
|
|
159
|
+
type OperationsOf<P extends DndPlugins> = [TypesOf<P[number]>["op"]] extends [never] ? "move" : TypesOf<P[number]>["op"];
|
|
160
|
+
/** The zone spec `plugins` accept. */
|
|
161
|
+
type ZoneSpecOf<P extends DndPlugins> = ZoneSpec<TypesOf<P[number]>["shape"], [TypesOf<P[number]>["extra"]] extends [never] ? never : Intersect<TypesOf<P[number]>["extra"]>>;
|
|
162
|
+
/** A registered drop zone. Attach its element; call `update` with the latest spec every render. */
|
|
163
|
+
interface DndZone<Spec = ZoneSpec> {
|
|
164
|
+
/** The element whose box is the zone and whose content holds the items. Returns the detach. */
|
|
165
|
+
attach(el: HTMLElement): () => void;
|
|
166
|
+
/** Replaces the spec. Changed `items` after a drop is the signal that the app committed. */
|
|
167
|
+
update(spec: Spec): void;
|
|
168
|
+
dispose(): void;
|
|
169
|
+
}
|
|
170
|
+
/** Options for {@link createDnd}. Pass the latest through `update` on every render. */
|
|
171
|
+
interface DndOptions<Op extends Operation = "move", P extends DndPlugins = DndPlugins> extends Omit<DragConfig<Op>, "plugins"> {
|
|
172
|
+
/** Called once per drop, synchronously in the drop event handler. Never for a null result. */
|
|
173
|
+
onDrop(result: DropResult<Op>): void;
|
|
174
|
+
/** What the drag can do beyond one list: `boardZones()`, `treeZones()`, `virtualZones()`, `selection()`, `operations()`, `autoscroll()`. */
|
|
175
|
+
readonly plugins?: P;
|
|
176
|
+
/** Live-region text for a key. Default: the key. */
|
|
177
|
+
readonly label?: (key: string) => string;
|
|
178
|
+
/** Live-region messages; false writes none. Default: English, on. */
|
|
179
|
+
readonly messages?: DragMessages | false;
|
|
180
|
+
/** What follows the pointer: `clonePreview`, `overlayPreview` or the default `inPlacePreview`. */
|
|
181
|
+
readonly preview?: PreviewStrategy;
|
|
182
|
+
/** Animates the drop, such as `flipSettle(animate)`. Default: snap. */
|
|
183
|
+
readonly settle?: SettleStrategy;
|
|
184
|
+
/** Where shifts and hiding are written: `styleChannel` (the default) or `varsChannel`. Read once, at creation. */
|
|
185
|
+
readonly channel?: DragChannelFactory;
|
|
186
|
+
/** How long to wait for the app's commit after `onDrop`, in ms. Default 250. */
|
|
187
|
+
readonly commitTimeoutMs?: number;
|
|
188
|
+
/** When a press becomes a drag; a function decides per press, null refuses it. */
|
|
189
|
+
readonly activation?: ActivationOptions | ((event: PointerEvent) => ActivationOptions | null);
|
|
190
|
+
readonly document?: Document;
|
|
191
|
+
readonly frame?: FrameLoop;
|
|
192
|
+
}
|
|
193
|
+
/** The coordinator handle. Its store is read-only; only input advances a drag. */
|
|
194
|
+
interface Dnd<Op extends Operation = Operation, Spec = ZoneSpec> {
|
|
195
|
+
readonly state: ReadableStore<DragState<Op>>;
|
|
196
|
+
/** The id of the instructions node handles name in `aria-describedby`. */
|
|
197
|
+
readonly instructionsId: string;
|
|
198
|
+
/** Registers a zone. A second zone needs `boardZones()`. */
|
|
199
|
+
zone(spec: Spec): DndZone<Spec>;
|
|
200
|
+
/** Registers an item element; it is also the handle until `handle` names another. Returns the unregister. */
|
|
201
|
+
item(key: string, el: HTMLElement, options?: {
|
|
202
|
+
readonly disabled?: boolean;
|
|
203
|
+
}): () => void;
|
|
204
|
+
/** Makes `el` the only element that starts drags of `key`. Returns the unregister. */
|
|
205
|
+
handle(key: string, el: HTMLElement): () => void;
|
|
206
|
+
/** The element `overlayPreview` moves. Returns the unregister. */
|
|
207
|
+
overlay(el: HTMLElement): () => void;
|
|
208
|
+
update(options: DndOptions<Op, DndPlugins>): void;
|
|
209
|
+
/** Cancels a running drag; it settles back like Escape. */
|
|
210
|
+
cancel(): void;
|
|
211
|
+
dispose(): void;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* @experimental
|
|
215
|
+
* Creates the drag-and-drop coordinator: register zones and items, and it runs pointer and
|
|
216
|
+
* keyboard drags through `dragReducer`, writes sibling shifts and the preview, announces,
|
|
217
|
+
* and calls `onDrop` with a key-based result. One list zone and moves out of the box;
|
|
218
|
+
* `plugins` add the rest.
|
|
219
|
+
*/
|
|
220
|
+
declare function createDnd<const P extends DndPlugins = []>(options: DndOptions<OperationsOf<P>, P>): Dnd<OperationsOf<P>, ZoneSpecOf<P>>;
|
|
221
|
+
/**
|
|
222
|
+
* Edge autoscroll of the zone under the pointer, or the zone the drag started in, during a
|
|
223
|
+
* pointer drag: the nearest scroller on each axis moves, faster closer to its edge. Keyboard
|
|
224
|
+
* drags scroll their target into view without it.
|
|
225
|
+
*/
|
|
226
|
+
declare function autoscroll(policy?: AutoscrollPolicy): DndPlugin;
|
|
227
|
+
/**
|
|
228
|
+
* Re-measures a zone whenever its element resizes, through the shared size observer: content
|
|
229
|
+
* that reflows mid-drag without a render (an image loading, a font swapping) moves the gaps
|
|
230
|
+
* with it. Without it a zone re-measures at lift, on every render and on a window resize.
|
|
231
|
+
*/
|
|
232
|
+
declare function observeZones(): DndPlugin;
|
|
233
|
+
/**
|
|
234
|
+
* Zones over a virtualizer: a spec's `source` replaces `items`. Unmounted rows are targets, the
|
|
235
|
+
* carried rows stay mounted for the drag (`retain`), a keyboard step reveals its target row,
|
|
236
|
+
* and the source's track version is the commit signal.
|
|
237
|
+
*/
|
|
238
|
+
declare function virtualZones(): DndPlugin<never, SourceShape>;
|
|
239
|
+
/**
|
|
240
|
+
* Tree zones: a spec's `tree` makes the zone an outline, with `outline` from
|
|
241
|
+
* `@bevelo/dnd/tree` (or a host's own) doing the projection. A lift carries the row's visible
|
|
242
|
+
* descendants, horizontal travel and the cross-axis arrows set the depth, and `tree.expand`
|
|
243
|
+
* hears the row the preview rests on.
|
|
244
|
+
*/
|
|
245
|
+
declare function treeZones(outline: Outline): DndPlugin<never, never, {
|
|
246
|
+
readonly tree?: TreeSpec;
|
|
247
|
+
}>;
|
|
248
|
+
/**
|
|
249
|
+
* Selection: `selected` is read at lift, and a primary key in it carries the whole set, in zone
|
|
250
|
+
* then track order. A pressed key outside it lifts alone.
|
|
251
|
+
*/
|
|
252
|
+
declare function selection(selected: () => Iterable<string>): DndPlugin;
|
|
253
|
+
/**
|
|
254
|
+
* A tree zone's `expand`: calls `onExpand` once the preview has rested on the same row for
|
|
255
|
+
* `afterMs`. Any other row, or none, restarts the wait.
|
|
256
|
+
*/
|
|
257
|
+
declare function expandAfter(afterMs: number, onExpand: (key: string) => void): (key: string | null) => void;
|
|
258
|
+
export { PreviewStrategy as A, DRAG_X as C, styleChannel as D, DragChannelFactory as E, inPlacePreview as M, overlayPreview as N, varsChannel as O, DRAG_HIDDEN as S, DragChannel as T, ItemsShape as _, treeZones as a, ZoneSpec as b, DndOptions as c, DndZone as d, LiveDrag as f, AnyZoneSpec as g, createDnd as h, selection as i, clonePreview as j, Preview as k, DndPlugin as l, ZoneSpecOf as m, autoscroll as n, virtualZones as o, OperationsOf as p, observeZones as r, Dnd as s, expandAfter as t, DndPlugins as u, SourceShape as v, DRAG_Y as w, ZoneSpecBase as x, TreeSpec as y };
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { t as DragMessages } from "./a11y-Bbm_a0mw.js";
|
|
2
|
+
import { A as ZoneBase, D as TreeRules, b as Operation, c as DragState, d as DropResult, k as Zone, l as Dragging, o as DragPlugin, r as DragConfig, x as Outline } from "./state-BEKGNZY1.js";
|
|
3
|
+
import { i as SettleStrategy } from "./settle-Dl5Y9uOw.js";
|
|
4
|
+
import { AutoscrollPolicy } from "@bevelo/runtime/geometry";
|
|
5
|
+
import { ActivationOptions, Axis as Axis$1, FrameLoop, ItemTrack as ItemTrack$1, Point as Point$1, ReadableStore, Rect as Rect$1, Scroller, TrackSource } from "@bevelo/runtime";
|
|
6
|
+
interface Preview {
|
|
7
|
+
readonly el: HTMLElement;
|
|
8
|
+
/** True when the engine created `el` and removes it after the drop. */
|
|
9
|
+
readonly owned: boolean;
|
|
10
|
+
/** Read pass: the viewport top-left the writer translates from; absent, the element's layout rect. */
|
|
11
|
+
readonly base?: () => Point$1;
|
|
12
|
+
}
|
|
13
|
+
/** Builds the preview at lift from the item, the registered overlay element and the item's layout rect. */
|
|
14
|
+
type PreviewStrategy = (item: HTMLElement, overlay: HTMLElement | null, rect: Rect$1) => Preview;
|
|
15
|
+
/** The item itself follows the pointer. The default. */
|
|
16
|
+
declare const inPlacePreview: PreviewStrategy;
|
|
17
|
+
/** A fixed clone of the item, which no clipping column can hide. */
|
|
18
|
+
declare const clonePreview: PreviewStrategy;
|
|
19
|
+
/** The element registered with `overlay`; a clone while none is registered. */
|
|
20
|
+
declare const overlayPreview: PreviewStrategy;
|
|
21
|
+
/** Where the engine's paint goes. One channel per coordinator; `reset` restores what it wrote. */
|
|
22
|
+
interface DragChannel {
|
|
23
|
+
/** Translates `el` by `by`; null puts it back. */
|
|
24
|
+
move(el: HTMLElement, by: Point$1 | null): void;
|
|
25
|
+
/** Hides a move's source while it travels, or shows it again. */
|
|
26
|
+
hide(el: HTMLElement, hidden: boolean): void;
|
|
27
|
+
/** A settle's inverse transform, from the top-left corner. A channel that leaves it to the animation omits it. */
|
|
28
|
+
readonly inverse?: (el: HTMLElement, transform: string) => void;
|
|
29
|
+
/**
|
|
30
|
+
* The offset `el` is painted at right now, when a stylesheet animates the translate this
|
|
31
|
+
* channel feeds and the paint lags what was written; undefined when it is what was written.
|
|
32
|
+
*/
|
|
33
|
+
readonly painted?: (el: Element) => Point$1 | undefined;
|
|
34
|
+
reset(): void;
|
|
35
|
+
}
|
|
36
|
+
/** Builds a coordinator's channel: `styleChannel` (the default) or `varsChannel`. */
|
|
37
|
+
type DragChannelFactory = () => DragChannel;
|
|
38
|
+
/**
|
|
39
|
+
* Inline `transform` and `visibility`, each element's own value remembered at the first write
|
|
40
|
+
* and restored by `reset`. The default.
|
|
41
|
+
*/
|
|
42
|
+
declare const styleChannel: DragChannelFactory;
|
|
43
|
+
/** The custom properties `varsChannel` writes. */
|
|
44
|
+
declare const DRAG_X = "--bevelo-drag-x";
|
|
45
|
+
declare const DRAG_Y = "--bevelo-drag-y";
|
|
46
|
+
/** The attribute `varsChannel` sets on a hidden move source. */
|
|
47
|
+
declare const DRAG_HIDDEN = "data-drag-hidden";
|
|
48
|
+
/**
|
|
49
|
+
* The engine's own channel: `--bevelo-drag-x` and `--bevelo-drag-y` (px) for every translate,
|
|
50
|
+
* and `data-drag-hidden` on a hidden move source. It never writes `transform` or `visibility`,
|
|
51
|
+
* so a part whose `style` a framework renders keeps it; the stylesheet consumes the channel:
|
|
52
|
+
*
|
|
53
|
+
* ```css
|
|
54
|
+
* @property --bevelo-drag-x { syntax: "<length>"; inherits: false; initial-value: 0px; }
|
|
55
|
+
* @property --bevelo-drag-y { syntax: "<length>"; inherits: false; initial-value: 0px; }
|
|
56
|
+
* [data-part] { translate: var(--bevelo-drag-x) var(--bevelo-drag-y); }
|
|
57
|
+
* [data-drag-hidden] { visibility: hidden; }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* A settle paints no inverse: `animateSettle` animates `transform` with the Web Animations
|
|
61
|
+
* API, which writes no inline style, and `springSettle` springs these same properties.
|
|
62
|
+
*/
|
|
63
|
+
declare const varsChannel: DragChannelFactory;
|
|
64
|
+
/** What every zone spec has. */
|
|
65
|
+
interface ZoneSpecBase {
|
|
66
|
+
readonly id: string;
|
|
67
|
+
/** Main axis of the zone's items. Default "y". */
|
|
68
|
+
readonly axis?: Axis$1;
|
|
69
|
+
readonly disabled?: boolean;
|
|
70
|
+
}
|
|
71
|
+
/** A measured zone: the host renders `items` in order. */
|
|
72
|
+
interface ItemsShape {
|
|
73
|
+
/** The zone's order. A change after a drop is the signal that the app committed. */
|
|
74
|
+
readonly items: readonly string[];
|
|
75
|
+
readonly source?: never;
|
|
76
|
+
}
|
|
77
|
+
/** A zone over a virtualizer's rows, with `virtualZones()`. */
|
|
78
|
+
interface SourceShape {
|
|
79
|
+
/** A virtualizer's rows: every key, mounted or not. */
|
|
80
|
+
readonly source: TrackSource;
|
|
81
|
+
readonly items?: never;
|
|
82
|
+
}
|
|
83
|
+
/** A tree zone's rules and its hover hook, with `treeZones()`. */
|
|
84
|
+
type TreeSpec = TreeRules & {
|
|
85
|
+
/** Hears the row the preview rests on (null when it leaves every row); `expandAfter` turns a long rest into an expand. */
|
|
86
|
+
readonly expand?: (key: string | null) => void;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* What a host registers for one drop zone: `items` in the core, and the shapes and fields its
|
|
90
|
+
* plugins add. `Shape` is an alternative to `items`; `Extra` is added to every spec.
|
|
91
|
+
*/
|
|
92
|
+
type ZoneSpec<Shape = never, Extra = never> = ZoneSpecBase & ([Extra] extends [never] ? unknown : Extra) & (ItemsShape | Shape);
|
|
93
|
+
/** A spec as the engine reads it, whatever its plugins. */
|
|
94
|
+
type AnyZoneSpec = ZoneSpecBase & {
|
|
95
|
+
readonly items?: readonly string[];
|
|
96
|
+
readonly source?: TrackSource;
|
|
97
|
+
readonly tree?: TreeSpec;
|
|
98
|
+
};
|
|
99
|
+
interface ZoneRecord {
|
|
100
|
+
spec: AnyZoneSpec;
|
|
101
|
+
el: HTMLElement | null;
|
|
102
|
+
/** The measured track is stale. */
|
|
103
|
+
dirty: boolean;
|
|
104
|
+
track: ItemTrack$1 | null;
|
|
105
|
+
zone: Zone | null;
|
|
106
|
+
/** What `zone` was built from; an equal list reuses it. */
|
|
107
|
+
inputs: readonly unknown[];
|
|
108
|
+
scrollers: readonly Scroller[] | null;
|
|
109
|
+
stopSize?: (() => void) | undefined;
|
|
110
|
+
}
|
|
111
|
+
/** How a plugin reads a zone: its origin and track, and the zone it builds over the base. */
|
|
112
|
+
interface ZoneReader {
|
|
113
|
+
/** The origin and track of a zone the engine does not measure; undefined measures it. */
|
|
114
|
+
readonly measure?: (spec: AnyZoneSpec) => {
|
|
115
|
+
readonly origin: Point$1;
|
|
116
|
+
readonly track: ItemTrack$1;
|
|
117
|
+
} | undefined;
|
|
118
|
+
/** The zone over `base`; undefined makes it a list. `spec` reads the host's latest spec. */
|
|
119
|
+
readonly build?: (base: ZoneBase, spec: () => AnyZoneSpec) => Zone | undefined;
|
|
120
|
+
/** Watches an attached zone element; `stale` re-measures its track. Returns the unwatch. */
|
|
121
|
+
readonly observe?: (el: HTMLElement, stale: () => void) => () => void;
|
|
122
|
+
}
|
|
123
|
+
/** What a plugin sees of the running drag. One per drag, from lift until it settles. */
|
|
124
|
+
interface LiveDrag {
|
|
125
|
+
readonly frame: FrameLoop;
|
|
126
|
+
/** The drag now; null once it dropped. */
|
|
127
|
+
state(): Dragging | null;
|
|
128
|
+
/** The registered zones, live. */
|
|
129
|
+
readonly zones: ReadonlySet<ZoneRecord>;
|
|
130
|
+
/** Scratch space a plugin keeps for the length of one drag. */
|
|
131
|
+
readonly memo: Record<string, unknown>;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* A coordinator plugin: reducer hooks plus the live ones below. Pass plugins in `plugins`;
|
|
135
|
+
* one that is never imported ships none of its code. The type parameters say what it allows:
|
|
136
|
+
* operations, a zone spec shape beside `items`, and fields on every zone spec.
|
|
137
|
+
*/
|
|
138
|
+
interface DndPlugin<Op extends Operation = never, Shape = never, Extra = never> extends DragPlugin<Op, Shape, Extra>, ZoneReader {
|
|
139
|
+
/** `selection()`: the keys chosen when a lift starts. */
|
|
140
|
+
readonly ids?: () => Iterable<string>;
|
|
141
|
+
/** Runs once a drag lifted, with how; returns what undoes it when the drag ends. */
|
|
142
|
+
readonly lift?: (drag: LiveDrag, pointer: boolean) => (() => void) | undefined;
|
|
143
|
+
/** Hears every state change of a drag; null once it ends. */
|
|
144
|
+
readonly change?: (drag: LiveDrag, state: Dragging | null) => void;
|
|
145
|
+
/** What a zone's commit signal is when it is not its `items`. */
|
|
146
|
+
readonly signal?: (spec: AnyZoneSpec) => unknown;
|
|
147
|
+
/** Read pass of a keyboard step: the write that brings `index` of the zone into view, or undefined to scroll it the measured way. */
|
|
148
|
+
readonly reveal?: (spec: AnyZoneSpec, index: number) => (() => void) | undefined;
|
|
149
|
+
}
|
|
150
|
+
/** Plugins as `createDnd` takes them. */
|
|
151
|
+
type DndPlugins = readonly DndPlugin<any, any, any>[];
|
|
152
|
+
type TypesOf<P> = P extends DragPlugin<infer Op, infer Shape, infer Extra> ? {
|
|
153
|
+
op: Op;
|
|
154
|
+
shape: Shape;
|
|
155
|
+
extra: Extra;
|
|
156
|
+
} : never;
|
|
157
|
+
type Intersect<U> = (U extends unknown ? (u: U) => void : never) extends ((i: infer I) => void) ? I : never;
|
|
158
|
+
/** The operations `plugins` allow: `operations()`'s list, else "move". */
|
|
159
|
+
type OperationsOf<P extends DndPlugins> = [TypesOf<P[number]>["op"]] extends [never] ? "move" : TypesOf<P[number]>["op"];
|
|
160
|
+
/** The zone spec `plugins` accept. */
|
|
161
|
+
type ZoneSpecOf<P extends DndPlugins> = ZoneSpec<TypesOf<P[number]>["shape"], [TypesOf<P[number]>["extra"]] extends [never] ? never : Intersect<TypesOf<P[number]>["extra"]>>;
|
|
162
|
+
/** A registered drop zone. Attach its element; call `update` with the latest spec every render. */
|
|
163
|
+
interface DndZone<Spec = ZoneSpec> {
|
|
164
|
+
/** The element whose box is the zone and whose content holds the items. Returns the detach. */
|
|
165
|
+
attach(el: HTMLElement): () => void;
|
|
166
|
+
/** Replaces the spec. Changed `items` after a drop is the signal that the app committed. */
|
|
167
|
+
update(spec: Spec): void;
|
|
168
|
+
dispose(): void;
|
|
169
|
+
}
|
|
170
|
+
/** Options for {@link createDnd}. Pass the latest through `update` on every render. */
|
|
171
|
+
interface DndOptions<Op extends Operation = "move", P extends DndPlugins = DndPlugins> extends Omit<DragConfig<Op>, "plugins"> {
|
|
172
|
+
/** Called once per drop, synchronously in the drop event handler. Never for a null result. */
|
|
173
|
+
onDrop(result: DropResult<Op>): void;
|
|
174
|
+
/** What the drag can do beyond one list: `boardZones()`, `treeZones()`, `virtualZones()`, `selection()`, `operations()`, `autoscroll()`. */
|
|
175
|
+
readonly plugins?: P;
|
|
176
|
+
/** Live-region text for a key. Default: the key. */
|
|
177
|
+
readonly label?: (key: string) => string;
|
|
178
|
+
/** Live-region messages; false writes none. Default: English, on. */
|
|
179
|
+
readonly messages?: DragMessages | false;
|
|
180
|
+
/** What follows the pointer: `clonePreview`, `overlayPreview` or the default `inPlacePreview`. */
|
|
181
|
+
readonly preview?: PreviewStrategy;
|
|
182
|
+
/** Animates the drop, such as `flipSettle(animate)`. Default: snap. */
|
|
183
|
+
readonly settle?: SettleStrategy;
|
|
184
|
+
/** Where shifts and hiding are written: `styleChannel` (the default) or `varsChannel`. Read once, at creation. */
|
|
185
|
+
readonly channel?: DragChannelFactory;
|
|
186
|
+
/** How long to wait for the app's commit after `onDrop`, in ms. Default 250. */
|
|
187
|
+
readonly commitTimeoutMs?: number;
|
|
188
|
+
/** When a press becomes a drag; a function decides per press, null refuses it. */
|
|
189
|
+
readonly activation?: ActivationOptions | ((event: PointerEvent) => ActivationOptions | null);
|
|
190
|
+
readonly document?: Document;
|
|
191
|
+
readonly frame?: FrameLoop;
|
|
192
|
+
}
|
|
193
|
+
/** The coordinator handle. Its store is read-only; only input advances a drag. */
|
|
194
|
+
interface Dnd<Op extends Operation = Operation, Spec = ZoneSpec> {
|
|
195
|
+
readonly state: ReadableStore<DragState<Op>>;
|
|
196
|
+
/** The id of the instructions node handles name in `aria-describedby`. */
|
|
197
|
+
readonly instructionsId: string;
|
|
198
|
+
/** Registers a zone. A second zone needs `boardZones()`. */
|
|
199
|
+
zone(spec: Spec): DndZone<Spec>;
|
|
200
|
+
/** Registers an item element; it is also the handle until `handle` names another. Returns the unregister. */
|
|
201
|
+
item(key: string, el: HTMLElement, options?: {
|
|
202
|
+
readonly disabled?: boolean;
|
|
203
|
+
}): () => void;
|
|
204
|
+
/** Makes `el` the only element that starts drags of `key`. Returns the unregister. */
|
|
205
|
+
handle(key: string, el: HTMLElement): () => void;
|
|
206
|
+
/** The element `overlayPreview` moves. Returns the unregister. */
|
|
207
|
+
overlay(el: HTMLElement): () => void;
|
|
208
|
+
update(options: DndOptions<Op, DndPlugins>): void;
|
|
209
|
+
/** Cancels a running drag; it settles back like Escape. */
|
|
210
|
+
cancel(): void;
|
|
211
|
+
dispose(): void;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* @experimental
|
|
215
|
+
* Creates the drag-and-drop coordinator: register zones and items, and it runs pointer and
|
|
216
|
+
* keyboard drags through `dragReducer`, writes sibling shifts and the preview, announces,
|
|
217
|
+
* and calls `onDrop` with a key-based result. One list zone and moves out of the box;
|
|
218
|
+
* `plugins` add the rest.
|
|
219
|
+
*/
|
|
220
|
+
declare function createDnd<const P extends DndPlugins = []>(options: DndOptions<OperationsOf<P>, P>): Dnd<OperationsOf<P>, ZoneSpecOf<P>>;
|
|
221
|
+
/**
|
|
222
|
+
* Edge autoscroll of the zone under the pointer, or the zone the drag started in, during a
|
|
223
|
+
* pointer drag: the nearest scroller on each axis moves, faster closer to its edge. Keyboard
|
|
224
|
+
* drags scroll their target into view without it.
|
|
225
|
+
*/
|
|
226
|
+
declare function autoscroll(policy?: AutoscrollPolicy): DndPlugin;
|
|
227
|
+
/**
|
|
228
|
+
* Re-measures a zone whenever its element resizes, through the shared size observer: content
|
|
229
|
+
* that reflows mid-drag without a render (an image loading, a font swapping) moves the gaps
|
|
230
|
+
* with it. Without it a zone re-measures at lift, on every render and on a window resize.
|
|
231
|
+
*/
|
|
232
|
+
declare function observeZones(): DndPlugin;
|
|
233
|
+
/**
|
|
234
|
+
* Zones over a virtualizer: a spec's `source` replaces `items`. Unmounted rows are targets, the
|
|
235
|
+
* carried rows stay mounted for the drag (`retain`), a keyboard step reveals its target row,
|
|
236
|
+
* and the source's track version is the commit signal.
|
|
237
|
+
*/
|
|
238
|
+
declare function virtualZones(): DndPlugin<never, SourceShape>;
|
|
239
|
+
/**
|
|
240
|
+
* Tree zones: a spec's `tree` makes the zone an outline, with `outline` from
|
|
241
|
+
* `@bevelo/dnd/tree` (or a host's own) doing the projection. A lift carries the row's visible
|
|
242
|
+
* descendants, horizontal travel and the cross-axis arrows set the depth, and `tree.expand`
|
|
243
|
+
* hears the row the preview rests on.
|
|
244
|
+
*/
|
|
245
|
+
declare function treeZones(outline: Outline): DndPlugin<never, never, {
|
|
246
|
+
readonly tree?: TreeSpec;
|
|
247
|
+
}>;
|
|
248
|
+
/**
|
|
249
|
+
* Selection: `selected` is read at lift, and a primary key in it carries the whole set, in zone
|
|
250
|
+
* then track order. A pressed key outside it lifts alone.
|
|
251
|
+
*/
|
|
252
|
+
declare function selection(selected: () => Iterable<string>): DndPlugin;
|
|
253
|
+
/**
|
|
254
|
+
* A tree zone's `expand`: calls `onExpand` once the preview has rested on the same row for
|
|
255
|
+
* `afterMs`. Any other row, or none, restarts the wait.
|
|
256
|
+
*/
|
|
257
|
+
declare function expandAfter(afterMs: number, onExpand: (key: string) => void): (key: string | null) => void;
|
|
258
|
+
export { PreviewStrategy as A, DRAG_X as C, styleChannel as D, DragChannelFactory as E, inPlacePreview as M, overlayPreview as N, varsChannel as O, DRAG_HIDDEN as S, DragChannel as T, ItemsShape as _, treeZones as a, ZoneSpec as b, DndOptions as c, DndZone as d, LiveDrag as f, AnyZoneSpec as g, createDnd as h, selection as i, clonePreview as j, Preview as k, DndPlugin as l, ZoneSpecOf as m, autoscroll as n, virtualZones as o, OperationsOf as p, observeZones as r, Dnd as s, expandAfter as t, DndPlugins as u, SourceShape as v, DRAG_Y as w, ZoneSpecBase as x, TreeSpec as y };
|