@dnd-kit/abstract 0.0.3 → 0.0.4-beta-20240621030124
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/index.cjs +247 -168
- package/index.cjs.map +1 -1
- package/index.d.cts +445 -0
- package/index.d.ts +18 -17
- package/index.js +248 -169
- package/index.js.map +1 -1
- package/modifiers.cjs +27 -17
- package/modifiers.cjs.map +1 -1
- package/modifiers.d.cts +36 -0
- package/modifiers.js +27 -17
- package/modifiers.js.map +1 -1
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -1,17 +1,86 @@
|
|
|
1
|
-
import { untracked, reactive,
|
|
1
|
+
import { untracked, reactive, signal, computed, deepEqual, effect, batch, derived, effects } from '@dnd-kit/state';
|
|
2
2
|
import { Position } from '@dnd-kit/geometry';
|
|
3
3
|
|
|
4
|
+
var __create = Object.create;
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
6
|
+
var __defProps = Object.defineProperties;
|
|
5
7
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return result;
|
|
8
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
9
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
13
|
+
var __typeError = (msg) => {
|
|
14
|
+
throw TypeError(msg);
|
|
14
15
|
};
|
|
16
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
17
|
+
var __spreadValues = (a, b) => {
|
|
18
|
+
for (var prop in b || (b = {}))
|
|
19
|
+
if (__hasOwnProp.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
if (__getOwnPropSymbols)
|
|
22
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
23
|
+
if (__propIsEnum.call(b, prop))
|
|
24
|
+
__defNormalProp(a, prop, b[prop]);
|
|
25
|
+
}
|
|
26
|
+
return a;
|
|
27
|
+
};
|
|
28
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
29
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
30
|
+
var __objRest = (source, exclude) => {
|
|
31
|
+
var target = {};
|
|
32
|
+
for (var prop in source)
|
|
33
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
34
|
+
target[prop] = source[prop];
|
|
35
|
+
if (source != null && __getOwnPropSymbols)
|
|
36
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
37
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
38
|
+
target[prop] = source[prop];
|
|
39
|
+
}
|
|
40
|
+
return target;
|
|
41
|
+
};
|
|
42
|
+
var __decoratorStart = (base) => {
|
|
43
|
+
var _a;
|
|
44
|
+
return [, , , __create((_a = base == null ? void 0 : base[__knownSymbol("metadata")]) != null ? _a : null)];
|
|
45
|
+
};
|
|
46
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
47
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
48
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
49
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
50
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
51
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
52
|
+
return value;
|
|
53
|
+
};
|
|
54
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
55
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
56
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
57
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
58
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
59
|
+
return __privateGet(this, extra);
|
|
60
|
+
}, set [name](x) {
|
|
61
|
+
return __privateSet(this, extra, x);
|
|
62
|
+
} }, name));
|
|
63
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
64
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
65
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
66
|
+
if (k) {
|
|
67
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
68
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
69
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
70
|
+
}
|
|
71
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
72
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
73
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
74
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
75
|
+
}
|
|
76
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
77
|
+
};
|
|
78
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
79
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
80
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
81
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
82
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
83
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
15
84
|
|
|
16
85
|
// src/core/plugins/utilities.ts
|
|
17
86
|
function configure(plugin, options) {
|
|
@@ -36,12 +105,14 @@ function descriptor(plugin) {
|
|
|
36
105
|
}
|
|
37
106
|
|
|
38
107
|
// src/core/plugins/plugin.ts
|
|
108
|
+
var _disabled_dec, _init, _disabled;
|
|
109
|
+
_disabled_dec = [reactive];
|
|
39
110
|
var Plugin = class {
|
|
40
111
|
constructor(manager, options) {
|
|
41
112
|
this.manager = manager;
|
|
42
113
|
this.options = options;
|
|
114
|
+
__privateAdd(this, _disabled, __runInitializers(_init, 8, this, false)), __runInitializers(_init, 11, this);
|
|
43
115
|
}
|
|
44
|
-
disabled = false;
|
|
45
116
|
/**
|
|
46
117
|
* Enable a disabled plugin instance.
|
|
47
118
|
* Triggers effects.
|
|
@@ -85,26 +156,28 @@ var Plugin = class {
|
|
|
85
156
|
return configure(this, options);
|
|
86
157
|
}
|
|
87
158
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
159
|
+
_init = __decoratorStart(null);
|
|
160
|
+
_disabled = new WeakMap();
|
|
161
|
+
__decorateElement(_init, 4, "disabled", _disabled_dec, Plugin, _disabled);
|
|
162
|
+
__decoratorMetadata(_init, Plugin);
|
|
91
163
|
var CorePlugin = class extends Plugin {
|
|
92
164
|
};
|
|
93
165
|
|
|
94
166
|
// src/core/plugins/registry.ts
|
|
167
|
+
var _previousValues;
|
|
95
168
|
var PluginRegistry = class {
|
|
96
169
|
constructor(manager) {
|
|
97
170
|
this.manager = manager;
|
|
171
|
+
this.instances = /* @__PURE__ */ new Map();
|
|
172
|
+
__privateAdd(this, _previousValues, []);
|
|
98
173
|
}
|
|
99
|
-
instances = /* @__PURE__ */ new Map();
|
|
100
174
|
get values() {
|
|
101
175
|
return Array.from(this.instances.values());
|
|
102
176
|
}
|
|
103
|
-
#previousValues = [];
|
|
104
177
|
set values(entries) {
|
|
105
178
|
const descriptors = entries.map(descriptor);
|
|
106
179
|
const constructors = descriptors.map(({ plugin }) => plugin);
|
|
107
|
-
for (const plugin of this
|
|
180
|
+
for (const plugin of __privateGet(this, _previousValues)) {
|
|
108
181
|
if (!constructors.includes(plugin)) {
|
|
109
182
|
if (plugin.prototype instanceof CorePlugin) {
|
|
110
183
|
continue;
|
|
@@ -115,7 +188,7 @@ var PluginRegistry = class {
|
|
|
115
188
|
for (const { plugin, options } of descriptors) {
|
|
116
189
|
this.register(plugin, options);
|
|
117
190
|
}
|
|
118
|
-
this
|
|
191
|
+
__privateSet(this, _previousValues, constructors);
|
|
119
192
|
}
|
|
120
193
|
get(plugin) {
|
|
121
194
|
const instance = this.instances.get(plugin);
|
|
@@ -144,6 +217,7 @@ var PluginRegistry = class {
|
|
|
144
217
|
this.instances.clear();
|
|
145
218
|
}
|
|
146
219
|
};
|
|
220
|
+
_previousValues = new WeakMap();
|
|
147
221
|
|
|
148
222
|
// src/core/collision/utilities.ts
|
|
149
223
|
function sortCollisions(a, b) {
|
|
@@ -155,11 +229,14 @@ function sortCollisions(a, b) {
|
|
|
155
229
|
|
|
156
230
|
// src/core/collision/observer.ts
|
|
157
231
|
var DEFAULT_VALUE = [];
|
|
232
|
+
var _collisions;
|
|
158
233
|
var CollisionObserver = class extends Plugin {
|
|
159
234
|
constructor(manager) {
|
|
160
235
|
super(manager);
|
|
236
|
+
this.forceUpdateCount = signal(0);
|
|
237
|
+
__privateAdd(this, _collisions);
|
|
161
238
|
this.computeCollisions = this.computeCollisions.bind(this);
|
|
162
|
-
this
|
|
239
|
+
__privateSet(this, _collisions, computed(this.computeCollisions, deepEqual));
|
|
163
240
|
this.destroy = effect(() => {
|
|
164
241
|
const { dragOperation } = this.manager;
|
|
165
242
|
if (dragOperation.status.initialized) {
|
|
@@ -167,7 +244,6 @@ var CollisionObserver = class extends Plugin {
|
|
|
167
244
|
}
|
|
168
245
|
});
|
|
169
246
|
}
|
|
170
|
-
forceUpdateCount = signal(0);
|
|
171
247
|
forceUpdate(refresh = true) {
|
|
172
248
|
untracked(() => {
|
|
173
249
|
const { source } = this.manager.dragOperation;
|
|
@@ -192,14 +268,14 @@ var CollisionObserver = class extends Plugin {
|
|
|
192
268
|
}
|
|
193
269
|
const collisions = [];
|
|
194
270
|
this.forceUpdateCount.value;
|
|
195
|
-
for (const entry of entries
|
|
271
|
+
for (const entry of entries != null ? entries : registry.droppables) {
|
|
196
272
|
if (entry.disabled) {
|
|
197
273
|
continue;
|
|
198
274
|
}
|
|
199
275
|
if (source && !entry.accepts(source)) {
|
|
200
276
|
continue;
|
|
201
277
|
}
|
|
202
|
-
const detectCollision = collisionDetector
|
|
278
|
+
const detectCollision = collisionDetector != null ? collisionDetector : entry.collisionDetector;
|
|
203
279
|
if (!detectCollision) {
|
|
204
280
|
continue;
|
|
205
281
|
}
|
|
@@ -220,14 +296,16 @@ var CollisionObserver = class extends Plugin {
|
|
|
220
296
|
return collisions;
|
|
221
297
|
}
|
|
222
298
|
get collisions() {
|
|
223
|
-
return this
|
|
299
|
+
return __privateGet(this, _collisions).value;
|
|
224
300
|
}
|
|
225
|
-
#collisions;
|
|
226
301
|
};
|
|
302
|
+
_collisions = new WeakMap();
|
|
227
303
|
|
|
228
304
|
// src/core/manager/events.ts
|
|
229
305
|
var Monitor = class {
|
|
230
|
-
|
|
306
|
+
constructor() {
|
|
307
|
+
this.registry = /* @__PURE__ */ new Map();
|
|
308
|
+
}
|
|
231
309
|
addEventListener(name, handler) {
|
|
232
310
|
const { registry } = this;
|
|
233
311
|
const listeners = new Set(registry.get(name));
|
|
@@ -264,8 +342,7 @@ var DragDropMonitor = class extends Monitor {
|
|
|
264
342
|
};
|
|
265
343
|
function defaultPreventable(event, cancelable = true) {
|
|
266
344
|
let defaultPrevented = false;
|
|
267
|
-
return {
|
|
268
|
-
...event,
|
|
345
|
+
return __spreadProps(__spreadValues({}, event), {
|
|
269
346
|
cancelable,
|
|
270
347
|
get defaultPrevented() {
|
|
271
348
|
return defaultPrevented;
|
|
@@ -276,7 +353,7 @@ function defaultPreventable(event, cancelable = true) {
|
|
|
276
353
|
}
|
|
277
354
|
defaultPrevented = true;
|
|
278
355
|
}
|
|
279
|
-
};
|
|
356
|
+
});
|
|
280
357
|
}
|
|
281
358
|
|
|
282
359
|
// src/core/collision/notifier.ts
|
|
@@ -298,9 +375,10 @@ var CollisionNotifier = class extends CorePlugin {
|
|
|
298
375
|
}
|
|
299
376
|
const [firstCollision] = collisions;
|
|
300
377
|
untracked(() => {
|
|
301
|
-
|
|
378
|
+
var _a;
|
|
379
|
+
if ((firstCollision == null ? void 0 : firstCollision.id) !== ((_a = manager.dragOperation.target) == null ? void 0 : _a.id)) {
|
|
302
380
|
collisionObserver.disable();
|
|
303
|
-
manager.actions.setDropTarget(firstCollision
|
|
381
|
+
manager.actions.setDropTarget(firstCollision == null ? void 0 : firstCollision.id).then(() => {
|
|
304
382
|
collisionObserver.enable();
|
|
305
383
|
});
|
|
306
384
|
}
|
|
@@ -321,6 +399,8 @@ var CollisionPriority = /* @__PURE__ */ ((CollisionPriority2) => {
|
|
|
321
399
|
function getDefaultEffects() {
|
|
322
400
|
return [];
|
|
323
401
|
}
|
|
402
|
+
var _disabled_dec2, _data_dec, _id_dec, _manager_dec, _init2, _manager, _id, _data, _disabled2;
|
|
403
|
+
_manager_dec = [reactive], _id_dec = [reactive], _data_dec = [reactive], _disabled_dec2 = [reactive];
|
|
324
404
|
var Entity = class {
|
|
325
405
|
/**
|
|
326
406
|
* Creates a new instance of the `Entity` class.
|
|
@@ -329,6 +409,10 @@ var Entity = class {
|
|
|
329
409
|
* @param manager - The manager that controls the drag and drop operations.
|
|
330
410
|
*/
|
|
331
411
|
constructor(input, manager) {
|
|
412
|
+
__privateAdd(this, _manager, __runInitializers(_init2, 8, this)), __runInitializers(_init2, 11, this);
|
|
413
|
+
__privateAdd(this, _id, __runInitializers(_init2, 12, this)), __runInitializers(_init2, 15, this);
|
|
414
|
+
__privateAdd(this, _data, __runInitializers(_init2, 16, this)), __runInitializers(_init2, 19, this);
|
|
415
|
+
__privateAdd(this, _disabled2, __runInitializers(_init2, 20, this)), __runInitializers(_init2, 23, this);
|
|
332
416
|
const {
|
|
333
417
|
effects: getEffects = getDefaultEffects,
|
|
334
418
|
id,
|
|
@@ -343,52 +427,82 @@ var Entity = class {
|
|
|
343
427
|
this.disabled = disabled;
|
|
344
428
|
this.effects = () => [
|
|
345
429
|
() => {
|
|
430
|
+
const { id: _, manager: manager2 } = this;
|
|
346
431
|
if (id === previousId) {
|
|
347
432
|
return;
|
|
348
433
|
}
|
|
349
|
-
|
|
350
|
-
return () =>
|
|
434
|
+
manager2 == null ? void 0 : manager2.registry.register(this);
|
|
435
|
+
return () => manager2 == null ? void 0 : manager2.registry.unregister(this);
|
|
351
436
|
},
|
|
352
437
|
...getEffects()
|
|
353
438
|
];
|
|
354
439
|
this.destroy = this.destroy.bind(this);
|
|
355
|
-
if (options
|
|
440
|
+
if ((options == null ? void 0 : options.register) !== false) {
|
|
356
441
|
queueMicrotask(() => {
|
|
357
|
-
|
|
442
|
+
var _a;
|
|
443
|
+
(_a = this.manager) == null ? void 0 : _a.registry.register(this);
|
|
358
444
|
});
|
|
359
445
|
}
|
|
360
446
|
}
|
|
361
|
-
manager;
|
|
362
|
-
id;
|
|
363
|
-
data;
|
|
364
|
-
disabled;
|
|
365
|
-
/**
|
|
366
|
-
* An array of effects that are applied to the entity.
|
|
367
|
-
*/
|
|
368
|
-
effects;
|
|
369
447
|
/**
|
|
370
448
|
* A method that cleans up the entity when it is no longer needed.
|
|
371
449
|
* @returns void
|
|
372
450
|
*/
|
|
373
451
|
destroy() {
|
|
374
|
-
|
|
452
|
+
var _a;
|
|
453
|
+
(_a = this.manager) == null ? void 0 : _a.registry.unregister(this);
|
|
375
454
|
}
|
|
376
455
|
};
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
reactive
|
|
388
|
-
], Entity.prototype, "disabled", 2);
|
|
456
|
+
_init2 = __decoratorStart(null);
|
|
457
|
+
_manager = new WeakMap();
|
|
458
|
+
_id = new WeakMap();
|
|
459
|
+
_data = new WeakMap();
|
|
460
|
+
_disabled2 = new WeakMap();
|
|
461
|
+
__decorateElement(_init2, 4, "manager", _manager_dec, Entity, _manager);
|
|
462
|
+
__decorateElement(_init2, 4, "id", _id_dec, Entity, _id);
|
|
463
|
+
__decorateElement(_init2, 4, "data", _data_dec, Entity, _data);
|
|
464
|
+
__decorateElement(_init2, 4, "disabled", _disabled_dec2, Entity, _disabled2);
|
|
465
|
+
__decoratorMetadata(_init2, Entity);
|
|
389
466
|
var EntityRegistry = class {
|
|
390
|
-
|
|
391
|
-
|
|
467
|
+
constructor() {
|
|
468
|
+
this.map = signal(/* @__PURE__ */ new Map());
|
|
469
|
+
this.cleanupFunctions = /* @__PURE__ */ new WeakMap();
|
|
470
|
+
/**
|
|
471
|
+
* Registers a entity in the registry.
|
|
472
|
+
* @param key - The unique identifier of the entity.
|
|
473
|
+
* @param value - The entity to register.
|
|
474
|
+
* @returns A function that unregisters the entity.
|
|
475
|
+
*/
|
|
476
|
+
this.register = (key, value) => {
|
|
477
|
+
const current = this.map.peek();
|
|
478
|
+
if (current.get(key) === value) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const updatedMap = new Map(current);
|
|
482
|
+
updatedMap.set(key, value);
|
|
483
|
+
this.map.value = updatedMap;
|
|
484
|
+
const cleanup = effects(...value.effects());
|
|
485
|
+
this.cleanupFunctions.set(value, cleanup);
|
|
486
|
+
return () => this.unregister(key, value);
|
|
487
|
+
};
|
|
488
|
+
/**
|
|
489
|
+
* Unregisters an entity from the registry.
|
|
490
|
+
* @param key - The unique identifier of the entity.
|
|
491
|
+
* @param value - The entity instance to unregister.
|
|
492
|
+
*/
|
|
493
|
+
this.unregister = (key, value) => {
|
|
494
|
+
const current = this.map.peek();
|
|
495
|
+
if (current.get(key) !== value) {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
const cleanup = this.cleanupFunctions.get(value);
|
|
499
|
+
cleanup == null ? void 0 : cleanup();
|
|
500
|
+
this.cleanupFunctions.delete(value);
|
|
501
|
+
const updatedMap = new Map(current);
|
|
502
|
+
updatedMap.delete(key);
|
|
503
|
+
this.map.value = updatedMap;
|
|
504
|
+
};
|
|
505
|
+
}
|
|
392
506
|
/**
|
|
393
507
|
* Iterator for the EntityRegistry class.
|
|
394
508
|
* @returns An iterator for the values in the map.
|
|
@@ -415,106 +529,85 @@ var EntityRegistry = class {
|
|
|
415
529
|
get(identifier) {
|
|
416
530
|
return this.map.value.get(identifier);
|
|
417
531
|
}
|
|
418
|
-
/**
|
|
419
|
-
* Registers a entity in the registry.
|
|
420
|
-
* @param key - The unique identifier of the entity.
|
|
421
|
-
* @param value - The entity to register.
|
|
422
|
-
* @returns A function that unregisters the entity.
|
|
423
|
-
*/
|
|
424
|
-
register = (key, value) => {
|
|
425
|
-
const current = this.map.peek();
|
|
426
|
-
if (current.get(key) === value) {
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
const updatedMap = new Map(current);
|
|
430
|
-
updatedMap.set(key, value);
|
|
431
|
-
this.map.value = updatedMap;
|
|
432
|
-
const cleanup = effects(...value.effects());
|
|
433
|
-
this.cleanupFunctions.set(value, cleanup);
|
|
434
|
-
return () => this.unregister(key, value);
|
|
435
|
-
};
|
|
436
|
-
/**
|
|
437
|
-
* Unregisters an entity from the registry.
|
|
438
|
-
* @param key - The unique identifier of the entity.
|
|
439
|
-
* @param value - The entity instance to unregister.
|
|
440
|
-
*/
|
|
441
|
-
unregister = (key, value) => {
|
|
442
|
-
const current = this.map.peek();
|
|
443
|
-
if (current.get(key) !== value) {
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
const cleanup = this.cleanupFunctions.get(value);
|
|
447
|
-
cleanup?.();
|
|
448
|
-
this.cleanupFunctions.delete(value);
|
|
449
|
-
const updatedMap = new Map(current);
|
|
450
|
-
updatedMap.delete(key);
|
|
451
|
-
this.map.value = updatedMap;
|
|
452
|
-
};
|
|
453
532
|
/**
|
|
454
533
|
* Destroys all entries in the registry and clears the registry.
|
|
455
534
|
*/
|
|
456
535
|
destroy() {
|
|
457
536
|
for (const entry of this) {
|
|
458
537
|
const cleanup = this.cleanupFunctions.get(entry);
|
|
459
|
-
cleanup
|
|
538
|
+
cleanup == null ? void 0 : cleanup();
|
|
460
539
|
entry.destroy();
|
|
461
540
|
}
|
|
462
541
|
this.map.value = /* @__PURE__ */ new Map();
|
|
463
542
|
}
|
|
464
543
|
};
|
|
465
|
-
var
|
|
466
|
-
|
|
544
|
+
var _isDragSource_dec, _type_dec, _c, _modifiers, _init3, _type;
|
|
545
|
+
var Draggable = class extends (_c = Entity, _type_dec = [reactive], _isDragSource_dec = [derived], _c) {
|
|
546
|
+
constructor(_a, manager) {
|
|
547
|
+
var _b = _a, { modifiers, type, sensors } = _b, input = __objRest(_b, ["modifiers", "type", "sensors"]);
|
|
467
548
|
super(input, manager);
|
|
468
|
-
|
|
549
|
+
__runInitializers(_init3, 5, this);
|
|
550
|
+
__privateAdd(this, _modifiers);
|
|
551
|
+
__privateAdd(this, _type, __runInitializers(_init3, 8, this)), __runInitializers(_init3, 11, this);
|
|
469
552
|
this.type = type;
|
|
470
553
|
this.sensors = sensors;
|
|
471
554
|
this.modifiers = modifiers;
|
|
472
555
|
}
|
|
473
|
-
sensors;
|
|
474
|
-
#modifiers;
|
|
475
556
|
set modifiers(modifiers) {
|
|
476
|
-
|
|
477
|
-
|
|
557
|
+
var _a;
|
|
558
|
+
const { manager } = this;
|
|
559
|
+
(_a = __privateGet(this, _modifiers)) == null ? void 0 : _a.forEach((modifier) => modifier.destroy());
|
|
560
|
+
if (!manager) return;
|
|
561
|
+
__privateSet(this, _modifiers, modifiers == null ? void 0 : modifiers.map((modifier) => {
|
|
478
562
|
const { plugin, options } = descriptor(modifier);
|
|
479
|
-
return new plugin(
|
|
480
|
-
});
|
|
563
|
+
return new plugin(manager, options);
|
|
564
|
+
}));
|
|
481
565
|
}
|
|
482
566
|
get modifiers() {
|
|
483
|
-
return this
|
|
567
|
+
return __privateGet(this, _modifiers);
|
|
484
568
|
}
|
|
485
|
-
type;
|
|
486
569
|
get isDragSource() {
|
|
487
|
-
|
|
488
|
-
return dragOperation.source
|
|
570
|
+
var _a, _b;
|
|
571
|
+
return ((_b = (_a = this.manager) == null ? void 0 : _a.dragOperation.source) == null ? void 0 : _b.id) === this.id;
|
|
489
572
|
}
|
|
490
573
|
destroy() {
|
|
574
|
+
var _a;
|
|
491
575
|
super.destroy();
|
|
492
|
-
this.modifiers
|
|
576
|
+
(_a = this.modifiers) == null ? void 0 : _a.forEach((modifier) => modifier.destroy());
|
|
493
577
|
}
|
|
494
578
|
};
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
var
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
579
|
+
_init3 = __decoratorStart(_c);
|
|
580
|
+
_modifiers = new WeakMap();
|
|
581
|
+
_type = new WeakMap();
|
|
582
|
+
__decorateElement(_init3, 4, "type", _type_dec, Draggable, _type);
|
|
583
|
+
__decorateElement(_init3, 2, "isDragSource", _isDragSource_dec, Draggable);
|
|
584
|
+
__decoratorMetadata(_init3, Draggable);
|
|
585
|
+
var _isDropTarget_dec, _shape_dec, _collisionPriority_dec, _collisionDetector_dec, _type_dec2, _accept_dec, _c2, _init4, _accept, _type2, _collisionDetector, _collisionPriority, _shape;
|
|
586
|
+
var Droppable = class extends (_c2 = Entity, _accept_dec = [reactive], _type_dec2 = [reactive], _collisionDetector_dec = [reactive], _collisionPriority_dec = [reactive], _shape_dec = [reactive], _isDropTarget_dec = [derived], _c2) {
|
|
587
|
+
constructor(_a, manager) {
|
|
588
|
+
var _b = _a, {
|
|
589
|
+
accept,
|
|
590
|
+
collisionDetector,
|
|
591
|
+
collisionPriority = 2 /* Normal */,
|
|
592
|
+
type
|
|
593
|
+
} = _b, input = __objRest(_b, [
|
|
594
|
+
"accept",
|
|
595
|
+
"collisionDetector",
|
|
596
|
+
"collisionPriority",
|
|
597
|
+
"type"
|
|
598
|
+
]);
|
|
509
599
|
super(input, manager);
|
|
510
|
-
|
|
600
|
+
__runInitializers(_init4, 5, this);
|
|
601
|
+
__privateAdd(this, _accept, __runInitializers(_init4, 8, this)), __runInitializers(_init4, 11, this);
|
|
602
|
+
__privateAdd(this, _type2, __runInitializers(_init4, 12, this)), __runInitializers(_init4, 15, this);
|
|
603
|
+
__privateAdd(this, _collisionDetector, __runInitializers(_init4, 16, this)), __runInitializers(_init4, 19, this);
|
|
604
|
+
__privateAdd(this, _collisionPriority, __runInitializers(_init4, 20, this)), __runInitializers(_init4, 23, this);
|
|
605
|
+
__privateAdd(this, _shape, __runInitializers(_init4, 24, this)), __runInitializers(_init4, 27, this);
|
|
511
606
|
this.accept = accept;
|
|
512
607
|
this.collisionDetector = collisionDetector;
|
|
513
608
|
this.collisionPriority = collisionPriority;
|
|
514
609
|
this.type = type;
|
|
515
610
|
}
|
|
516
|
-
accept;
|
|
517
|
-
type;
|
|
518
611
|
/**
|
|
519
612
|
* Checks whether or not the droppable accepts a given draggable.
|
|
520
613
|
*
|
|
@@ -537,33 +630,26 @@ var Droppable = class extends Entity {
|
|
|
537
630
|
}
|
|
538
631
|
return draggable.type === accept;
|
|
539
632
|
}
|
|
540
|
-
collisionDetector;
|
|
541
|
-
collisionPriority;
|
|
542
|
-
shape;
|
|
543
633
|
get isDropTarget() {
|
|
544
|
-
|
|
634
|
+
var _a, _b;
|
|
635
|
+
return ((_b = (_a = this.manager) == null ? void 0 : _a.dragOperation.target) == null ? void 0 : _b.id) === this.id;
|
|
545
636
|
}
|
|
546
637
|
refreshShape() {
|
|
547
638
|
}
|
|
548
639
|
};
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
reactive
|
|
563
|
-
], Droppable.prototype, "shape", 2);
|
|
564
|
-
__decorateClass([
|
|
565
|
-
derived
|
|
566
|
-
], Droppable.prototype, "isDropTarget", 1);
|
|
640
|
+
_init4 = __decoratorStart(_c2);
|
|
641
|
+
_accept = new WeakMap();
|
|
642
|
+
_type2 = new WeakMap();
|
|
643
|
+
_collisionDetector = new WeakMap();
|
|
644
|
+
_collisionPriority = new WeakMap();
|
|
645
|
+
_shape = new WeakMap();
|
|
646
|
+
__decorateElement(_init4, 4, "accept", _accept_dec, Droppable, _accept);
|
|
647
|
+
__decorateElement(_init4, 4, "type", _type_dec2, Droppable, _type2);
|
|
648
|
+
__decorateElement(_init4, 4, "collisionDetector", _collisionDetector_dec, Droppable, _collisionDetector);
|
|
649
|
+
__decorateElement(_init4, 4, "collisionPriority", _collisionPriority_dec, Droppable, _collisionPriority);
|
|
650
|
+
__decorateElement(_init4, 4, "shape", _shape_dec, Droppable, _shape);
|
|
651
|
+
__decorateElement(_init4, 2, "isDropTarget", _isDropTarget_dec, Droppable);
|
|
652
|
+
__decoratorMetadata(_init4, Droppable);
|
|
567
653
|
|
|
568
654
|
// src/core/sensors/sensor.ts
|
|
569
655
|
var Sensor = class extends Plugin {
|
|
@@ -589,15 +675,12 @@ var Modifier = class extends Plugin {
|
|
|
589
675
|
// src/core/manager/registry.ts
|
|
590
676
|
var DragDropRegistry = class {
|
|
591
677
|
constructor(manager) {
|
|
678
|
+
this.draggables = new EntityRegistry();
|
|
679
|
+
this.droppables = new EntityRegistry();
|
|
592
680
|
this.plugins = new PluginRegistry(manager);
|
|
593
681
|
this.sensors = new PluginRegistry(manager);
|
|
594
682
|
this.modifiers = new PluginRegistry(manager);
|
|
595
683
|
}
|
|
596
|
-
draggables = new EntityRegistry();
|
|
597
|
-
droppables = new EntityRegistry();
|
|
598
|
-
plugins;
|
|
599
|
-
sensors;
|
|
600
|
-
modifiers;
|
|
601
684
|
register(input, options) {
|
|
602
685
|
if (input instanceof Draggable) {
|
|
603
686
|
return this.draggables.register(input.id, input);
|
|
@@ -676,22 +759,24 @@ function DragOperationManager(manager) {
|
|
|
676
759
|
const dragended = signal(true);
|
|
677
760
|
let previousSource;
|
|
678
761
|
const source = computed(() => {
|
|
762
|
+
var _a;
|
|
679
763
|
const identifier = sourceIdentifier.value;
|
|
680
|
-
if (identifier == null)
|
|
681
|
-
return null;
|
|
764
|
+
if (identifier == null) return null;
|
|
682
765
|
const value = draggables.get(identifier);
|
|
683
766
|
if (value) {
|
|
684
767
|
previousSource = value;
|
|
685
768
|
}
|
|
686
|
-
return value
|
|
769
|
+
return (_a = value != null ? value : previousSource) != null ? _a : null;
|
|
687
770
|
});
|
|
688
771
|
const target = computed(() => {
|
|
772
|
+
var _a;
|
|
689
773
|
const identifier = targetIdentifier.value;
|
|
690
|
-
return identifier != null ? droppables.get(identifier)
|
|
774
|
+
return identifier != null ? (_a = droppables.get(identifier)) != null ? _a : null : null;
|
|
691
775
|
});
|
|
692
776
|
const transform = computed(() => {
|
|
777
|
+
var _a, _b;
|
|
693
778
|
const { x, y } = position.delta;
|
|
694
|
-
const modifiers = source
|
|
779
|
+
const modifiers = (_b = (_a = source == null ? void 0 : source.value) == null ? void 0 : _a.modifiers) != null ? _b : manager.modifiers;
|
|
695
780
|
let transform2 = { x, y };
|
|
696
781
|
const initialShape = shape.initial.peek();
|
|
697
782
|
const currentShape = shape.current.peek();
|
|
@@ -713,7 +798,7 @@ function DragOperationManager(manager) {
|
|
|
713
798
|
position
|
|
714
799
|
};
|
|
715
800
|
for (const modifier of modifiers) {
|
|
716
|
-
transform2 = modifier.apply({
|
|
801
|
+
transform2 = modifier.apply(__spreadProps(__spreadValues({}, operation2), { transform: transform2 }));
|
|
717
802
|
}
|
|
718
803
|
return transform2;
|
|
719
804
|
});
|
|
@@ -759,7 +844,8 @@ function DragOperationManager(manager) {
|
|
|
759
844
|
return initial && current ? { initial, current } : null;
|
|
760
845
|
},
|
|
761
846
|
set shape(value) {
|
|
762
|
-
|
|
847
|
+
var _a;
|
|
848
|
+
if (value && ((_a = shape.current.peek()) == null ? void 0 : _a.equals(value))) {
|
|
763
849
|
return;
|
|
764
850
|
}
|
|
765
851
|
const initial = shape.initial.peek();
|
|
@@ -790,7 +876,7 @@ function DragOperationManager(manager) {
|
|
|
790
876
|
sourceIdentifier.value = identifier;
|
|
791
877
|
},
|
|
792
878
|
setDropTarget(identifier) {
|
|
793
|
-
const id = identifier
|
|
879
|
+
const id = identifier != null ? identifier : null;
|
|
794
880
|
if (targetIdentifier.peek() === id) {
|
|
795
881
|
return Promise.resolve();
|
|
796
882
|
}
|
|
@@ -852,7 +938,7 @@ function DragOperationManager(manager) {
|
|
|
852
938
|
if (event.defaultPrevented) {
|
|
853
939
|
return;
|
|
854
940
|
}
|
|
855
|
-
const coordinates = to
|
|
941
|
+
const coordinates = to != null ? to : {
|
|
856
942
|
x: position.current.x + by.x,
|
|
857
943
|
y: position.current.y + by.y
|
|
858
944
|
};
|
|
@@ -899,9 +985,7 @@ function DragOperationManager(manager) {
|
|
|
899
985
|
};
|
|
900
986
|
}
|
|
901
987
|
function snapshot(obj) {
|
|
902
|
-
return {
|
|
903
|
-
...obj
|
|
904
|
-
};
|
|
988
|
+
return __spreadValues({}, obj);
|
|
905
989
|
}
|
|
906
990
|
|
|
907
991
|
// src/core/manager/renderer.ts
|
|
@@ -913,19 +997,13 @@ var defaultRenderer = {
|
|
|
913
997
|
|
|
914
998
|
// src/core/manager/manager.ts
|
|
915
999
|
var DragDropManager = class {
|
|
916
|
-
actions;
|
|
917
|
-
collisionObserver;
|
|
918
|
-
dragOperation;
|
|
919
|
-
monitor;
|
|
920
|
-
registry;
|
|
921
|
-
renderer;
|
|
922
1000
|
constructor(config) {
|
|
923
1001
|
const {
|
|
924
1002
|
plugins = [],
|
|
925
1003
|
sensors = [],
|
|
926
1004
|
modifiers = [],
|
|
927
1005
|
renderer = defaultRenderer
|
|
928
|
-
} = config
|
|
1006
|
+
} = config != null ? config : {};
|
|
929
1007
|
const monitor = new DragDropMonitor(this);
|
|
930
1008
|
const registry = new DragDropRegistry(this);
|
|
931
1009
|
this.registry = registry;
|
|
@@ -938,6 +1016,7 @@ var DragDropManager = class {
|
|
|
938
1016
|
this.plugins = [CollisionNotifier, ...plugins];
|
|
939
1017
|
this.modifiers = modifiers;
|
|
940
1018
|
this.sensors = sensors;
|
|
1019
|
+
this.destroy = this.destroy.bind(this);
|
|
941
1020
|
}
|
|
942
1021
|
get plugins() {
|
|
943
1022
|
return this.registry.plugins.values;
|