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