@hkdigital/lib-core 0.4.64 → 0.4.66

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.
@@ -364,6 +364,17 @@ export default class SceneBase {
364
364
  /* ==== Internal methods */
365
365
 
366
366
  #startLoading() {
367
+ // Handle empty scenes - immediately transition to loaded if no sources
368
+ if (this.sources.length === 0) {
369
+ // Use setTimeout to avoid re-entrant state machine calls
370
+ setTimeout(() => {
371
+ if (this.#state.current === STATE_LOADING) {
372
+ this.#state.send(LOADED);
373
+ }
374
+ }, 0);
375
+ return;
376
+ }
377
+
367
378
  for (let i = 0; i < this.sources.length; i++) {
368
379
  const source = this.sources[i];
369
380
  const loader = this.getLoaderFromSource(source);
@@ -18,7 +18,8 @@
18
18
  * zone?: string,
19
19
  * group?: string,
20
20
  * disabled?: boolean,
21
- * accepts?: (dragData: any, target: { zone:string, group: string }) => boolean,
21
+ * accepts?: (dragData: DragData, target: { zone:string, group: string }) => boolean,
22
+ * enableDebug?: boolean,
22
23
  * base?: string,
23
24
  * classes?: string,
24
25
  * minHeight?: string,
@@ -63,6 +64,7 @@
63
64
  group = 'default',
64
65
  disabled = false,
65
66
  accepts = () => true,
67
+ enableDebug = false,
66
68
  base = '',
67
69
  classes = '',
68
70
  minHeight = '',
@@ -86,7 +88,9 @@
86
88
  const dropZoneId = generateLocalId();
87
89
 
88
90
  let currentState = $state(READY);
89
- let dropZoneElement = $state(null);
91
+
92
+ /** @type {HTMLElement|undefined} */
93
+ let dropZoneElement = $state();
90
94
 
91
95
  // Computed height classes based on mode
92
96
  let heightClasses = $derived.by(() => {
@@ -137,24 +141,91 @@
137
141
  dragState.registerDropZone(dropZoneId, {
138
142
  zone,
139
143
  group,
140
- accepts: (dragData) => {
141
- if (disabled) return false;
142
- if (!dragData) return false;
144
+ accepts: (/** @type {DragData} */ dragData) => {
145
+ if (enableDebug) {
146
+ console.debug(
147
+ `[DropZone] accepts() called for zone="${zone}", group="${group}"`,
148
+ {
149
+ disabled,
150
+ dragData: dragData
151
+ ? {
152
+ group: dragData.group,
153
+ source: dragData.source,
154
+ item: dragData.item
155
+ }
156
+ : null
157
+ }
158
+ );
159
+ }
160
+
161
+ if (disabled) {
162
+ if (enableDebug) console.debug(`[DropZone] Rejected: disabled`);
163
+ return false;
164
+ }
165
+ if (!dragData) {
166
+ if (enableDebug) console.debug(`[DropZone] Rejected: no dragData`);
167
+ return false;
168
+ }
169
+
170
+ const result = accepts(dragData, { zone, group });
171
+
172
+ if (enableDebug) {
173
+ console.debug(`[DropZone] User accepts() result: ${result}`, {
174
+ dragGroup: dragData.group,
175
+ targetGroup: group,
176
+ groupsMatch: dragData.group === group
177
+ });
178
+ }
143
179
 
144
- return accepts(dragData, { zone, group });
180
+ return result;
145
181
  },
146
- onDragEnter: (detail) => {
182
+ onDragEnter: (
183
+ /** @type {{ event: DragEvent, zone: string, canDrop: boolean }} */ detail
184
+ ) => {
185
+ if (enableDebug) {
186
+ console.debug(
187
+ `[DropZone] onDragEnter zone="${zone}", group="${group}"`,
188
+ {
189
+ canDrop: detail.canDrop,
190
+ newState: detail.canDrop ? 'CAN_DROP' : 'CANNOT_DROP'
191
+ }
192
+ );
193
+ }
147
194
  currentState = detail.canDrop ? CAN_DROP : CANNOT_DROP;
148
195
  onDragEnter?.(detail);
149
196
  },
150
- onDragOver: (detail) => {
197
+ onDragOver: (
198
+ /** @type {{ event: DragEvent, zone: string }} */ detail
199
+ ) => {
151
200
  onDragOver?.(detail);
152
201
  },
153
- onDragLeave: (detail) => {
202
+ onDragLeave: (
203
+ /** @type {{ event: DragEvent, zone: string }} */ detail
204
+ ) => {
205
+ if (enableDebug) {
206
+ console.debug(
207
+ `[DropZone] onDragLeave zone="${zone}", group="${group}"`
208
+ );
209
+ }
154
210
  currentState = READY;
155
211
  onDragLeave?.(detail);
156
212
  },
157
213
  onDrop: async (dropData) => {
214
+ if (enableDebug) {
215
+ console.debug(
216
+ `[DropZone] onDrop zone="${zone}", group="${group}"`,
217
+ {
218
+ dropData: {
219
+ zone: dropData.zone,
220
+ source: dropData.source,
221
+ item: dropData.item,
222
+ x: dropData.x,
223
+ y: dropData.y
224
+ }
225
+ }
226
+ );
227
+ }
228
+
158
229
  currentState = READY;
159
230
 
160
231
  try {
@@ -166,6 +237,10 @@
166
237
 
167
238
  const result = await onDrop?.(dropData);
168
239
 
240
+ if (enableDebug) {
241
+ console.debug(`[DropZone] onDrop completed successfully`);
242
+ }
243
+
169
244
  onDropEnd?.({
170
245
  event: dropData.drop.event,
171
246
  zone: dropData.zone,
@@ -175,13 +250,18 @@
175
250
 
176
251
  return result;
177
252
  } catch (error) {
253
+ if (enableDebug) {
254
+ console.debug(`[DropZone] onDrop failed:`, error);
255
+ }
256
+
178
257
  onDropEnd?.({
179
258
  event: dropData.drop.event,
180
259
  zone: dropData.zone,
181
260
  data: dropData.drag,
182
261
  success: false,
183
- error
262
+ error: /** @type {Error} */ (error)
184
263
  });
264
+
185
265
  throw error;
186
266
  }
187
267
  },
@@ -6,10 +6,11 @@ type DropZone = {
6
6
  zone?: string | undefined;
7
7
  group?: string | undefined;
8
8
  disabled?: boolean | undefined;
9
- accepts?: ((dragData: any, target: {
9
+ accepts?: ((dragData: DragData, target: {
10
10
  zone: string;
11
11
  group: string;
12
12
  }) => boolean) | undefined;
13
+ enableDebug?: boolean | undefined;
13
14
  base?: string | undefined;
14
15
  classes?: string | undefined;
15
16
  minHeight?: string | undefined;
@@ -53,10 +54,11 @@ declare const DropZone: import("svelte").Component<{
53
54
  zone?: string;
54
55
  group?: string;
55
56
  disabled?: boolean;
56
- accepts?: (dragData: any, target: {
57
+ accepts?: (dragData: import("../../typedef.js").DragData, target: {
57
58
  zone: string;
58
59
  group: string;
59
60
  }) => boolean;
61
+ enableDebug?: boolean;
60
62
  base?: string;
61
63
  classes?: string;
62
64
  minHeight?: string;
@@ -12,6 +12,10 @@ export type DragData = {
12
12
  * - Source identifier
13
13
  */
14
14
  source?: string | undefined;
15
+ /**
16
+ * - Group identifier
17
+ */
18
+ group?: string | undefined;
15
19
  };
16
20
  export type SimulatedDragEvent = {
17
21
  type: "dragstart" | "dragover" | "dragleave" | "drop" | "dragend";
@@ -5,6 +5,7 @@
5
5
  * @property {number} offsetY
6
6
  * @property {any} item - The item being dragged
7
7
  * @property {string} [source] - Source identifier
8
+ * @property {string} [group] - Group identifier
8
9
  */
9
10
 
10
11
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.4.64",
3
+ "version": "0.4.66",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"