@mapples/dnd 1.1.2 → 1.2.1
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/components/DnDRootView.d.ts +1 -1
- package/dist/components/DnDRootView.d.ts.map +1 -1
- package/dist/components/DnDRootView.js +86 -13
- package/dist/components/DnDRootView.js.map +1 -1
- package/dist/components/DropArea.d.ts.map +1 -1
- package/dist/components/DropArea.js +6 -3
- package/dist/components/DropArea.js.map +1 -1
- package/dist/context/DropContext.d.ts +8 -0
- package/dist/context/DropContext.d.ts.map +1 -1
- package/dist/context/DropContext.js +8 -0
- package/dist/context/DropContext.js.map +1 -1
- package/dist/context/FrameSpaceContext.d.ts +27 -0
- package/dist/context/FrameSpaceContext.d.ts.map +1 -0
- package/dist/context/FrameSpaceContext.js +15 -0
- package/dist/context/FrameSpaceContext.js.map +1 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +2 -0
- package/dist/context/index.js.map +1 -1
- package/dist/hooks/useDrag.d.ts.map +1 -1
- package/dist/hooks/useDrag.js +12 -0
- package/dist/hooks/useDrag.js.map +1 -1
- package/dist/hooks/useDrop.d.ts.map +1 -1
- package/dist/hooks/useDrop.js +74 -9
- package/dist/hooks/useDrop.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/monitor/Monitor.d.ts +107 -22
- package/dist/monitor/Monitor.d.ts.map +1 -1
- package/dist/monitor/Monitor.js +378 -111
- package/dist/monitor/Monitor.js.map +1 -1
- package/dist/types/index.d.ts +86 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LayoutRectangle } from 'react-native';
|
|
2
2
|
import { Subject } from 'rxjs';
|
|
3
|
-
import { DnDEvent, DragCoords, DragElementTarget, DragItem, DropTarget, DropTargetConfig, MonitorConfig } from '../types';
|
|
3
|
+
import { DnDEvent, DragCoords, DragElementTarget, DragItem, DropTarget, DropTargetConfig, FrameEntry, MonitorConfig } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* Core monitor class that manages drag and drop operations.
|
|
6
6
|
* This class tracks drag elements, drop targets, handles hit detection, and emits events.
|
|
@@ -22,8 +22,25 @@ export declare class Monitor<DragData extends object, DropData extends object =
|
|
|
22
22
|
private dragElements;
|
|
23
23
|
/** Tree structure of registered drop elements */
|
|
24
24
|
private dropElementsTree;
|
|
25
|
+
/**
|
|
26
|
+
* Flat index of every registered drop element and its parent id. Kept in
|
|
27
|
+
* lockstep with the tree by register/unregister/update — the only writers —
|
|
28
|
+
* so id lookups and frame-key resolution are O(1)/O(depth) instead of a
|
|
29
|
+
* full recursive tree walk per layout event.
|
|
30
|
+
*/
|
|
31
|
+
private dropNodesById;
|
|
32
|
+
private dropParentById;
|
|
33
|
+
/** Pending coalesced force-layout broadcast (one per animation frame). */
|
|
34
|
+
private forceLayoutUpdatePending;
|
|
35
|
+
/** Registered frame coordinate spaces by key */
|
|
36
|
+
private frames;
|
|
25
37
|
/** ID of the currently active drag target */
|
|
26
38
|
private dragTargetId;
|
|
39
|
+
/** Active move-drag source (an existing canvas element being moved) */
|
|
40
|
+
private moveSource;
|
|
41
|
+
/** Pointer coords at drag start / most recent drag tick (drop space) */
|
|
42
|
+
private dragStartCoords;
|
|
43
|
+
private lastDragCoords;
|
|
27
44
|
/** Currently active drop target */
|
|
28
45
|
private dropTarget;
|
|
29
46
|
/** Index position within the current drop target */
|
|
@@ -35,6 +52,26 @@ export declare class Monitor<DragData extends object, DropData extends object =
|
|
|
35
52
|
* @param config - Configuration options for the monitor
|
|
36
53
|
*/
|
|
37
54
|
constructor(config: MonitorConfig);
|
|
55
|
+
/**
|
|
56
|
+
* Registers (or replaces) a frame coordinate space. Drop elements whose
|
|
57
|
+
* config carries the same `frameKey` are stored and hit-tested in
|
|
58
|
+
* coordinates relative to this frame's origin.
|
|
59
|
+
*/
|
|
60
|
+
registerFrame(frameKey: string, entry: FrameEntry): void;
|
|
61
|
+
/**
|
|
62
|
+
* Moves a frame's world origin. O(1): no element re-measures needed since
|
|
63
|
+
* frame content layouts are origin-relative.
|
|
64
|
+
*/
|
|
65
|
+
updateFrameOrigin(frameKey: string, origin: DragCoords): void;
|
|
66
|
+
/** Removes a frame coordinate space. */
|
|
67
|
+
unregisterFrame(frameKey: string): void;
|
|
68
|
+
/** Gets a registered frame space by key. */
|
|
69
|
+
getFrame(frameKey: string): FrameEntry | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Converts world coordinates into a frame's local space.
|
|
72
|
+
* Falls through unchanged when the frame isn't registered.
|
|
73
|
+
*/
|
|
74
|
+
toFrameLocal(coords: DragCoords, frameKey: string): DragCoords;
|
|
38
75
|
/**
|
|
39
76
|
* Gets the ID of the currently active drag target.
|
|
40
77
|
* @returns The drag target ID or null if no drag is active
|
|
@@ -47,7 +84,10 @@ export declare class Monitor<DragData extends object, DropData extends object =
|
|
|
47
84
|
private setDragTargetId;
|
|
48
85
|
/**
|
|
49
86
|
* Triggers a force layout update event.
|
|
50
|
-
* This causes all registered elements to recalculate their layout
|
|
87
|
+
* This causes all registered elements to recalculate their layout
|
|
88
|
+
* information. Every registered element answers with a forced layout read,
|
|
89
|
+
* so calls are coalesced to at most one broadcast per animation frame —
|
|
90
|
+
* scroll handlers and settle timers may call this at input rate.
|
|
51
91
|
*/
|
|
52
92
|
triggerForceLayoutUpdate(): void;
|
|
53
93
|
/**
|
|
@@ -103,35 +143,90 @@ export declare class Monitor<DragData extends object, DropData extends object =
|
|
|
103
143
|
updateDragElementLayout(id: number, layout: LayoutRectangle): void;
|
|
104
144
|
/**
|
|
105
145
|
* Handles the start of a drag operation.
|
|
106
|
-
* @param dragCoords -
|
|
146
|
+
* @param dragCoords - Coordinates in drop-target space (world space when a
|
|
147
|
+
* pointer transform is installed), or `null` when the press began outside
|
|
148
|
+
* that space entirely. A palette press is exactly that case — the palette
|
|
149
|
+
* lives beside the canvas, not on it — so a null here must never abort the
|
|
150
|
+
* drag; it only rules out grabbing an existing element to move.
|
|
151
|
+
* @param windowCoords - Raw window coordinates for drag-*source* hit
|
|
152
|
+
* testing (palette items live outside any frame); defaults to `dragCoords`
|
|
107
153
|
*/
|
|
108
|
-
onDragStart(dragCoords: DragCoords): void;
|
|
154
|
+
onDragStart(dragCoords: DragCoords | null, windowCoords?: DragCoords): void;
|
|
109
155
|
/**
|
|
110
156
|
* Handles drag movement during a drag operation.
|
|
111
157
|
* @param dragCoords - The current coordinates of the drag
|
|
112
158
|
*/
|
|
113
159
|
onDrag(dragCoords: DragCoords): void;
|
|
160
|
+
/**
|
|
161
|
+
* The pointer left the drop coordinate space entirely — reported by the
|
|
162
|
+
* host when its `pointerTransform` cannot place the pointer (e.g. it moved
|
|
163
|
+
* off the canvas viewport onto surrounding chrome). Equivalent to hovering
|
|
164
|
+
* empty space: the pending drop clears, so a release here cancels.
|
|
165
|
+
*/
|
|
166
|
+
onDragOutside(): void;
|
|
167
|
+
/**
|
|
168
|
+
* Hit-tests a point in drop space with no drag registered. Drags that start
|
|
169
|
+
* outside the app — files dragged in from the OS — never register a drag
|
|
170
|
+
* element, so they cannot go through {@link onDrag}; this gives them the
|
|
171
|
+
* same target and insert-index resolution the in-app drag path uses.
|
|
172
|
+
* @param dropCoords - The coordinates to hit-test, in drop space
|
|
173
|
+
*/
|
|
174
|
+
hitTest(dropCoords: DragCoords): {
|
|
175
|
+
dropTarget: DropTarget<DropData> | null;
|
|
176
|
+
dropTargetIndex: number | null;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Publishes an external drag's current position, so the drop chrome
|
|
180
|
+
* (hover highlight, insert line) tracks a file dragged in from the OS
|
|
181
|
+
* exactly as it tracks an in-app drag. Pass `null` coordinates while the
|
|
182
|
+
* pointer sits outside the drop space — that clears the pending drop the
|
|
183
|
+
* same way hovering off a droppable area does mid-drag.
|
|
184
|
+
* @param dropCoords - The pointer position in drop space, or null
|
|
185
|
+
*/
|
|
186
|
+
onExternalDrag(dropCoords: DragCoords | null): void;
|
|
187
|
+
/**
|
|
188
|
+
* Ends an external drag — the files were dropped, or the drag left the
|
|
189
|
+
* window. Always `cancelled`: whatever the drop produces is inserted by
|
|
190
|
+
* the host once its uploads finish, never by the DnD path.
|
|
191
|
+
*/
|
|
192
|
+
onExternalDragEnd(): void;
|
|
114
193
|
/**
|
|
115
194
|
* Handles selection/tap events.
|
|
116
195
|
* @param dragCoords - The coordinates where the selection occurred
|
|
117
196
|
*/
|
|
118
197
|
onSelect(dragCoords: DragCoords): void;
|
|
119
198
|
/**
|
|
120
|
-
* Checks if the given coordinates are inside
|
|
121
|
-
*
|
|
122
|
-
* @returns True if inside the first root element
|
|
199
|
+
* Checks if the given coordinates are inside any root drop element,
|
|
200
|
+
* converting into frame-local space for frame-rooted elements.
|
|
123
201
|
* @private
|
|
124
202
|
*/
|
|
125
|
-
private
|
|
203
|
+
private isInsideAnyRootElement;
|
|
204
|
+
/**
|
|
205
|
+
* Looks up a registered drop target (with its current layout and frame
|
|
206
|
+
* key) by matching data properties — e.g. `{ id: componentId }`.
|
|
207
|
+
*
|
|
208
|
+
* @param frameKey - Restrict the search to one frame's subtree. Required
|
|
209
|
+
* whenever ids are only unique per frame (every page root shares the id
|
|
210
|
+
* `root`, so an unscoped lookup can return another frame's element).
|
|
211
|
+
*/
|
|
212
|
+
getDropTargetByData(dataQuery: Partial<DropData>, frameKey?: string): DropTarget<DropData> | null;
|
|
126
213
|
/**
|
|
127
214
|
* Handles external selection by data query.
|
|
128
215
|
* @param dataQuery - Partial data to match against drop targets
|
|
129
216
|
*/
|
|
130
217
|
onExternalSelect(dataQuery: Partial<DropData>): void;
|
|
131
218
|
/**
|
|
132
|
-
* Handles the end of a drag operation.
|
|
219
|
+
* Handles the end of a drag operation. Releasing the pointer outside every
|
|
220
|
+
* droppable area cancels the drag: `DragEnd` still fires — overlays, the
|
|
221
|
+
* drag ghost and `isDragging` all reset on it — but carries a null
|
|
222
|
+
* `dropTarget` and `cancelled: true`, so nothing is inserted or moved.
|
|
133
223
|
*/
|
|
134
224
|
onDragEnd(): void;
|
|
225
|
+
/**
|
|
226
|
+
* Clears every piece of per-drag state.
|
|
227
|
+
* @private
|
|
228
|
+
*/
|
|
229
|
+
private resetDragState;
|
|
135
230
|
/**
|
|
136
231
|
* Registers a new drop element with the monitor.
|
|
137
232
|
* @param layout - The layout rectangle of the drop element
|
|
@@ -155,13 +250,11 @@ export declare class Monitor<DragData extends object, DropData extends object =
|
|
|
155
250
|
*/
|
|
156
251
|
updateDropElement(id: number, layout: LayoutRectangle, config?: DropTargetConfig, data?: DropData): void;
|
|
157
252
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* @param tree - The tree to search in
|
|
161
|
-
* @returns The drop item or null if not found
|
|
253
|
+
* Resolves the frame space an element (or any of its ancestors) belongs to
|
|
254
|
+
* by walking the parent chain — O(depth).
|
|
162
255
|
* @private
|
|
163
256
|
*/
|
|
164
|
-
private
|
|
257
|
+
private findFrameKeyFor;
|
|
165
258
|
/**
|
|
166
259
|
* Finds a drop target by matching data properties.
|
|
167
260
|
* @param dataQuery - Partial data to match against
|
|
@@ -178,14 +271,6 @@ export declare class Monitor<DragData extends object, DropData extends object =
|
|
|
178
271
|
* @private
|
|
179
272
|
*/
|
|
180
273
|
private partialMatch;
|
|
181
|
-
/**
|
|
182
|
-
* Finds the parent of a drop target by ID.
|
|
183
|
-
* @param id - The ID of the child drop target
|
|
184
|
-
* @param tree - The tree to search in
|
|
185
|
-
* @returns The parent drop item or null if not found
|
|
186
|
-
* @private
|
|
187
|
-
*/
|
|
188
|
-
private findDropTargetParent;
|
|
189
274
|
/**
|
|
190
275
|
* Gets all drop targets that contain the given coordinates.
|
|
191
276
|
* @param dropCoords - The coordinates to check
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Monitor.d.ts","sourceRoot":"","sources":["../../src/monitor/Monitor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,OAAO,EACL,QAAQ,EAER,UAAU,EACV,iBAAiB,EACjB,QAAQ,EAER,UAAU,EACV,gBAAgB,EAGhB,aAAa,
|
|
1
|
+
{"version":3,"file":"Monitor.d.ts","sourceRoot":"","sources":["../../src/monitor/Monitor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,OAAO,EACL,QAAQ,EAER,UAAU,EACV,iBAAiB,EACjB,QAAQ,EAER,UAAU,EACV,gBAAgB,EAGhB,UAAU,EACV,aAAa,EAEd,MAAM,UAAU,CAAC;AAElB;;;;;;;GAOG;AACH,qBAAa,OAAO,CAClB,QAAQ,SAAS,MAAM,EACvB,QAAQ,SAAS,MAAM,GAAG,QAAQ;IAElC,gDAAgD;IAChD,MAAM,wCAA+C;IAErD,oDAAoD;IACpD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;IAErC,qDAAqD;IACrD,OAAO,CAAC,cAAc,CAAK;IAC3B,qDAAqD;IACrD,OAAO,CAAC,cAAc,CAAK;IAE3B,4CAA4C;IAC5C,OAAO,CAAC,YAAY,CAAkD;IACtE,iDAAiD;IACjD,OAAO,CAAC,gBAAgB,CAAiC;IACzD;;;;;OAKG;IACH,OAAO,CAAC,aAAa,CAAyC;IAC9D,OAAO,CAAC,cAAc,CAAoC;IAC1D,0EAA0E;IAC1E,OAAO,CAAC,wBAAwB,CAAS;IACzC,gDAAgD;IAChD,OAAO,CAAC,MAAM,CAAiC;IAE/C,6CAA6C;IAC7C,OAAO,CAAC,YAAY,CAAuB;IAC3C,uEAAuE;IACvE,OAAO,CAAC,UAAU,CAA+B;IACjD,w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