@measured/puck-plugin-heading-analyzer 0.19.0-canary.32a6f78 → 0.19.0-canary.46835fd

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/index.mjs CHANGED
@@ -21,6 +21,12 @@ var __spreadValues = (a, b) => {
21
21
  return a;
22
22
  };
23
23
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
25
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
26
+ }) : x)(function(x) {
27
+ if (typeof require !== "undefined") return require.apply(this, arguments);
28
+ throw Error('Dynamic require of "' + x + '" is not supported');
29
+ });
24
30
  var __objRest = (source, exclude) => {
25
31
  var target = {};
26
32
  for (var prop in source)
@@ -36,7 +42,7 @@ var __objRest = (source, exclude) => {
36
42
  var __esm = (fn, res) => function __init() {
37
43
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
38
44
  };
39
- var __commonJS = (cb, mod) => function __require() {
45
+ var __commonJS = (cb, mod) => function __require2() {
40
46
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
41
47
  };
42
48
  var __copyProps = (to, from, except, desc) => {
@@ -55,6 +61,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
55
61
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
56
62
  mod
57
63
  ));
64
+ var __async = (__this, __arguments, generator) => {
65
+ return new Promise((resolve, reject) => {
66
+ var fulfilled = (value) => {
67
+ try {
68
+ step(generator.next(value));
69
+ } catch (e) {
70
+ reject(e);
71
+ }
72
+ };
73
+ var rejected = (value) => {
74
+ try {
75
+ step(generator.throw(value));
76
+ } catch (e) {
77
+ reject(e);
78
+ }
79
+ };
80
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
81
+ step((generator = generator.apply(__this, __arguments)).next());
82
+ });
83
+ };
58
84
 
59
85
  // ../tsup-config/react-import.js
60
86
  import React from "react";
@@ -126,19 +152,338 @@ var require_classnames = __commonJS({
126
152
  }
127
153
  });
128
154
 
155
+ // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js
156
+ var require_use_sync_external_store_shim_production = __commonJS({
157
+ "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js"(exports) {
158
+ "use strict";
159
+ init_react_import();
160
+ var React2 = __require("react");
161
+ function is(x, y) {
162
+ return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
163
+ }
164
+ var objectIs = "function" === typeof Object.is ? Object.is : is;
165
+ var useState2 = React2.useState;
166
+ var useEffect7 = React2.useEffect;
167
+ var useLayoutEffect = React2.useLayoutEffect;
168
+ var useDebugValue2 = React2.useDebugValue;
169
+ function useSyncExternalStore$2(subscribe, getSnapshot) {
170
+ var value = getSnapshot(), _useState = useState2({ inst: { value, getSnapshot } }), inst = _useState[0].inst, forceUpdate = _useState[1];
171
+ useLayoutEffect(
172
+ function() {
173
+ inst.value = value;
174
+ inst.getSnapshot = getSnapshot;
175
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
176
+ },
177
+ [subscribe, value, getSnapshot]
178
+ );
179
+ useEffect7(
180
+ function() {
181
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
182
+ return subscribe(function() {
183
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
184
+ });
185
+ },
186
+ [subscribe]
187
+ );
188
+ useDebugValue2(value);
189
+ return value;
190
+ }
191
+ function checkIfSnapshotChanged(inst) {
192
+ var latestGetSnapshot = inst.getSnapshot;
193
+ inst = inst.value;
194
+ try {
195
+ var nextValue = latestGetSnapshot();
196
+ return !objectIs(inst, nextValue);
197
+ } catch (error) {
198
+ return true;
199
+ }
200
+ }
201
+ function useSyncExternalStore$1(subscribe, getSnapshot) {
202
+ return getSnapshot();
203
+ }
204
+ var shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
205
+ exports.useSyncExternalStore = void 0 !== React2.useSyncExternalStore ? React2.useSyncExternalStore : shim;
206
+ }
207
+ });
208
+
209
+ // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js
210
+ var require_use_sync_external_store_shim_development = __commonJS({
211
+ "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js"(exports) {
212
+ "use strict";
213
+ init_react_import();
214
+ "production" !== process.env.NODE_ENV && function() {
215
+ function is(x, y) {
216
+ return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
217
+ }
218
+ function useSyncExternalStore$2(subscribe, getSnapshot) {
219
+ didWarnOld18Alpha || void 0 === React2.startTransition || (didWarnOld18Alpha = true, console.error(
220
+ "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
221
+ ));
222
+ var value = getSnapshot();
223
+ if (!didWarnUncachedGetSnapshot) {
224
+ var cachedValue = getSnapshot();
225
+ objectIs(value, cachedValue) || (console.error(
226
+ "The result of getSnapshot should be cached to avoid an infinite loop"
227
+ ), didWarnUncachedGetSnapshot = true);
228
+ }
229
+ cachedValue = useState2({
230
+ inst: { value, getSnapshot }
231
+ });
232
+ var inst = cachedValue[0].inst, forceUpdate = cachedValue[1];
233
+ useLayoutEffect(
234
+ function() {
235
+ inst.value = value;
236
+ inst.getSnapshot = getSnapshot;
237
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
238
+ },
239
+ [subscribe, value, getSnapshot]
240
+ );
241
+ useEffect7(
242
+ function() {
243
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
244
+ return subscribe(function() {
245
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
246
+ });
247
+ },
248
+ [subscribe]
249
+ );
250
+ useDebugValue2(value);
251
+ return value;
252
+ }
253
+ function checkIfSnapshotChanged(inst) {
254
+ var latestGetSnapshot = inst.getSnapshot;
255
+ inst = inst.value;
256
+ try {
257
+ var nextValue = latestGetSnapshot();
258
+ return !objectIs(inst, nextValue);
259
+ } catch (error) {
260
+ return true;
261
+ }
262
+ }
263
+ function useSyncExternalStore$1(subscribe, getSnapshot) {
264
+ return getSnapshot();
265
+ }
266
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
267
+ var React2 = __require("react"), objectIs = "function" === typeof Object.is ? Object.is : is, useState2 = React2.useState, useEffect7 = React2.useEffect, useLayoutEffect = React2.useLayoutEffect, useDebugValue2 = React2.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
268
+ exports.useSyncExternalStore = void 0 !== React2.useSyncExternalStore ? React2.useSyncExternalStore : shim;
269
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
270
+ }();
271
+ }
272
+ });
273
+
274
+ // ../../node_modules/use-sync-external-store/shim/index.js
275
+ var require_shim = __commonJS({
276
+ "../../node_modules/use-sync-external-store/shim/index.js"(exports, module) {
277
+ "use strict";
278
+ init_react_import();
279
+ if (process.env.NODE_ENV === "production") {
280
+ module.exports = require_use_sync_external_store_shim_production();
281
+ } else {
282
+ module.exports = require_use_sync_external_store_shim_development();
283
+ }
284
+ }
285
+ });
286
+
287
+ // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js
288
+ var require_with_selector_production = __commonJS({
289
+ "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js"(exports) {
290
+ "use strict";
291
+ init_react_import();
292
+ var React2 = __require("react");
293
+ var shim = require_shim();
294
+ function is(x, y) {
295
+ return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
296
+ }
297
+ var objectIs = "function" === typeof Object.is ? Object.is : is;
298
+ var useSyncExternalStore = shim.useSyncExternalStore;
299
+ var useRef = React2.useRef;
300
+ var useEffect7 = React2.useEffect;
301
+ var useMemo2 = React2.useMemo;
302
+ var useDebugValue2 = React2.useDebugValue;
303
+ exports.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
304
+ var instRef = useRef(null);
305
+ if (null === instRef.current) {
306
+ var inst = { hasValue: false, value: null };
307
+ instRef.current = inst;
308
+ } else inst = instRef.current;
309
+ instRef = useMemo2(
310
+ function() {
311
+ function memoizedSelector(nextSnapshot) {
312
+ if (!hasMemo) {
313
+ hasMemo = true;
314
+ memoizedSnapshot = nextSnapshot;
315
+ nextSnapshot = selector(nextSnapshot);
316
+ if (void 0 !== isEqual && inst.hasValue) {
317
+ var currentSelection = inst.value;
318
+ if (isEqual(currentSelection, nextSnapshot))
319
+ return memoizedSelection = currentSelection;
320
+ }
321
+ return memoizedSelection = nextSnapshot;
322
+ }
323
+ currentSelection = memoizedSelection;
324
+ if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;
325
+ var nextSelection = selector(nextSnapshot);
326
+ if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
327
+ return memoizedSnapshot = nextSnapshot, currentSelection;
328
+ memoizedSnapshot = nextSnapshot;
329
+ return memoizedSelection = nextSelection;
330
+ }
331
+ var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
332
+ return [
333
+ function() {
334
+ return memoizedSelector(getSnapshot());
335
+ },
336
+ null === maybeGetServerSnapshot ? void 0 : function() {
337
+ return memoizedSelector(maybeGetServerSnapshot());
338
+ }
339
+ ];
340
+ },
341
+ [getSnapshot, getServerSnapshot, selector, isEqual]
342
+ );
343
+ var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
344
+ useEffect7(
345
+ function() {
346
+ inst.hasValue = true;
347
+ inst.value = value;
348
+ },
349
+ [value]
350
+ );
351
+ useDebugValue2(value);
352
+ return value;
353
+ };
354
+ }
355
+ });
356
+
357
+ // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js
358
+ var require_with_selector_development = __commonJS({
359
+ "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js"(exports) {
360
+ "use strict";
361
+ init_react_import();
362
+ "production" !== process.env.NODE_ENV && function() {
363
+ function is(x, y) {
364
+ return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
365
+ }
366
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
367
+ var React2 = __require("react"), shim = require_shim(), objectIs = "function" === typeof Object.is ? Object.is : is, useSyncExternalStore = shim.useSyncExternalStore, useRef = React2.useRef, useEffect7 = React2.useEffect, useMemo2 = React2.useMemo, useDebugValue2 = React2.useDebugValue;
368
+ exports.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
369
+ var instRef = useRef(null);
370
+ if (null === instRef.current) {
371
+ var inst = { hasValue: false, value: null };
372
+ instRef.current = inst;
373
+ } else inst = instRef.current;
374
+ instRef = useMemo2(
375
+ function() {
376
+ function memoizedSelector(nextSnapshot) {
377
+ if (!hasMemo) {
378
+ hasMemo = true;
379
+ memoizedSnapshot = nextSnapshot;
380
+ nextSnapshot = selector(nextSnapshot);
381
+ if (void 0 !== isEqual && inst.hasValue) {
382
+ var currentSelection = inst.value;
383
+ if (isEqual(currentSelection, nextSnapshot))
384
+ return memoizedSelection = currentSelection;
385
+ }
386
+ return memoizedSelection = nextSnapshot;
387
+ }
388
+ currentSelection = memoizedSelection;
389
+ if (objectIs(memoizedSnapshot, nextSnapshot))
390
+ return currentSelection;
391
+ var nextSelection = selector(nextSnapshot);
392
+ if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
393
+ return memoizedSnapshot = nextSnapshot, currentSelection;
394
+ memoizedSnapshot = nextSnapshot;
395
+ return memoizedSelection = nextSelection;
396
+ }
397
+ var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
398
+ return [
399
+ function() {
400
+ return memoizedSelector(getSnapshot());
401
+ },
402
+ null === maybeGetServerSnapshot ? void 0 : function() {
403
+ return memoizedSelector(maybeGetServerSnapshot());
404
+ }
405
+ ];
406
+ },
407
+ [getSnapshot, getServerSnapshot, selector, isEqual]
408
+ );
409
+ var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
410
+ useEffect7(
411
+ function() {
412
+ inst.hasValue = true;
413
+ inst.value = value;
414
+ },
415
+ [value]
416
+ );
417
+ useDebugValue2(value);
418
+ return value;
419
+ };
420
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
421
+ }();
422
+ }
423
+ });
424
+
425
+ // ../../node_modules/use-sync-external-store/shim/with-selector.js
426
+ var require_with_selector = __commonJS({
427
+ "../../node_modules/use-sync-external-store/shim/with-selector.js"(exports, module) {
428
+ "use strict";
429
+ init_react_import();
430
+ if (process.env.NODE_ENV === "production") {
431
+ module.exports = require_with_selector_production();
432
+ } else {
433
+ module.exports = require_with_selector_development();
434
+ }
435
+ }
436
+ });
437
+
438
+ // ../../node_modules/fast-deep-equal/index.js
439
+ var require_fast_deep_equal = __commonJS({
440
+ "../../node_modules/fast-deep-equal/index.js"(exports, module) {
441
+ "use strict";
442
+ init_react_import();
443
+ module.exports = function equal(a, b) {
444
+ if (a === b) return true;
445
+ if (a && b && typeof a == "object" && typeof b == "object") {
446
+ if (a.constructor !== b.constructor) return false;
447
+ var length, i, keys;
448
+ if (Array.isArray(a)) {
449
+ length = a.length;
450
+ if (length != b.length) return false;
451
+ for (i = length; i-- !== 0; )
452
+ if (!equal(a[i], b[i])) return false;
453
+ return true;
454
+ }
455
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
456
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
457
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
458
+ keys = Object.keys(a);
459
+ length = keys.length;
460
+ if (length !== Object.keys(b).length) return false;
461
+ for (i = length; i-- !== 0; )
462
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
463
+ for (i = length; i-- !== 0; ) {
464
+ var key = keys[i];
465
+ if (!equal(a[key], b[key])) return false;
466
+ }
467
+ return true;
468
+ }
469
+ return a !== a && b !== b;
470
+ };
471
+ }
472
+ });
473
+
129
474
  // index.ts
130
475
  init_react_import();
131
476
 
132
477
  // src/HeadingAnalyzer.tsx
133
478
  init_react_import();
134
- import { useEffect as useEffect4, useState as useState5 } from "react";
479
+ import { useEffect as useEffect6, useState } from "react";
135
480
 
136
481
  // css-module:/home/runner/work/puck/puck/packages/plugin-heading-analyzer/src/HeadingAnalyzer.module.css#css-module
137
482
  init_react_import();
138
483
  var HeadingAnalyzer_module_default = { "HeadingAnalyzer": "_HeadingAnalyzer_116v6_1", "HeadingAnalyzer-cssWarning": "_HeadingAnalyzer-cssWarning_116v6_5", "HeadingAnalyzerItem": "_HeadingAnalyzerItem_116v6_9", "HeadingAnalyzerItem--missing": "_HeadingAnalyzerItem--missing_116v6_13" };
139
484
 
140
485
  // src/HeadingAnalyzer.tsx
141
- import { usePuck } from "@measured/puck";
486
+ import { createUsePuck } from "@measured/puck";
142
487
 
143
488
  // ../core/components/SidebarSection/index.tsx
144
489
  init_react_import();
@@ -292,142 +637,523 @@ var ChevronRight = createLucideIcon("ChevronRight", [
292
637
 
293
638
  // ../core/lib/use-breadcrumbs.ts
294
639
  init_react_import();
295
- import { useContext as useContext2, useMemo as useMemo2 } from "react";
640
+ import { useMemo } from "react";
296
641
 
297
- // ../core/components/DropZone/context.tsx
642
+ // ../core/store/index.ts
298
643
  init_react_import();
299
- import {
300
- createContext as createContext2,
301
- useCallback as useCallback3,
302
- useMemo,
303
- useState as useState4
304
- } from "react";
305
644
 
306
- // ../core/components/Puck/context.tsx
645
+ // ../core/reducer/index.ts
307
646
  init_react_import();
308
- import {
309
- createContext,
310
- useContext,
311
- useEffect as useEffect3,
312
- useState as useState3
313
- } from "react";
314
647
 
315
- // ../core/lib/get-item.ts
648
+ // ../core/reducer/data.ts
316
649
  init_react_import();
317
650
 
651
+ // ../core/lib/reorder.ts
652
+ init_react_import();
653
+ var reorder = (list, startIndex, endIndex) => {
654
+ const result = Array.from(list);
655
+ const [removed] = result.splice(startIndex, 1);
656
+ result.splice(endIndex, 0, removed);
657
+ return result;
658
+ };
659
+
318
660
  // ../core/lib/root-droppable-id.ts
319
661
  init_react_import();
320
- var rootDroppableId = "default-zone";
662
+ var rootAreaId = "root";
663
+ var rootZone = "default-zone";
664
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
665
+
666
+ // ../core/lib/insert.ts
667
+ init_react_import();
668
+ var insert = (list, index, item) => {
669
+ const result = Array.from(list);
670
+ result.splice(index, 0, item);
671
+ return result;
672
+ };
673
+
674
+ // ../core/lib/remove.ts
675
+ init_react_import();
676
+ var remove = (list, index) => {
677
+ const result = Array.from(list);
678
+ result.splice(index, 1);
679
+ return result;
680
+ };
321
681
 
322
682
  // ../core/lib/setup-zone.ts
323
683
  init_react_import();
684
+ var setupZone = (data, zoneKey) => {
685
+ if (zoneKey === rootDroppableId) {
686
+ return data;
687
+ }
688
+ const newData = __spreadProps(__spreadValues({}, data), {
689
+ zones: data.zones ? __spreadValues({}, data.zones) : {}
690
+ });
691
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
692
+ return newData;
693
+ };
324
694
 
325
- // ../core/components/ViewportControls/default-viewports.ts
695
+ // ../core/lib/replace.ts
326
696
  init_react_import();
327
- var defaultViewports = [
328
- { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
329
- { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
330
- { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
331
- ];
697
+ var replace = (list, index, newItem) => {
698
+ const result = Array.from(list);
699
+ result.splice(index, 1);
700
+ result.splice(index, 0, newItem);
701
+ return result;
702
+ };
332
703
 
333
- // ../core/lib/use-resolved-permissions.ts
704
+ // ../core/lib/get-item.ts
334
705
  init_react_import();
335
- import { useCallback, useEffect, useState } from "react";
706
+ function getItem(selector, data, dynamicProps = {}) {
707
+ if (!selector.zone || selector.zone === rootDroppableId) {
708
+ const item2 = data.content[selector.index];
709
+ return (item2 == null ? void 0 : item2.props) ? __spreadProps(__spreadValues({}, item2), { props: dynamicProps[item2.props.id] || item2.props }) : void 0;
710
+ }
711
+ const item = setupZone(data, selector.zone).zones[selector.zone][selector.index];
712
+ return (item == null ? void 0 : item.props) ? __spreadProps(__spreadValues({}, item), { props: dynamicProps[item.props.id] || item.props }) : void 0;
713
+ }
336
714
 
337
- // ../core/lib/flatten-data.ts
715
+ // ../core/lib/reduce-related-zones.ts
338
716
  init_react_import();
339
717
 
340
- // ../core/lib/get-changed.ts
718
+ // ../core/lib/generate-id.ts
341
719
  init_react_import();
342
720
 
343
- // ../core/lib/use-resolved-data.ts
721
+ // ../../node_modules/uuid/dist/esm-node/index.js
344
722
  init_react_import();
345
- import { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
346
723
 
347
- // ../core/lib/resolve-component-data.ts
724
+ // ../../node_modules/uuid/dist/esm-node/rng.js
348
725
  init_react_import();
726
+ import crypto from "crypto";
727
+ var rnds8Pool = new Uint8Array(256);
728
+ var poolPtr = rnds8Pool.length;
729
+ function rng() {
730
+ if (poolPtr > rnds8Pool.length - 16) {
731
+ crypto.randomFillSync(rnds8Pool);
732
+ poolPtr = 0;
733
+ }
734
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
735
+ }
349
736
 
350
- // ../core/lib/apply-dynamic-props.ts
737
+ // ../../node_modules/uuid/dist/esm-node/stringify.js
351
738
  init_react_import();
739
+ var byteToHex = [];
740
+ for (let i = 0; i < 256; ++i) {
741
+ byteToHex.push((i + 256).toString(16).slice(1));
742
+ }
743
+ function unsafeStringify(arr, offset = 0) {
744
+ return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
745
+ }
352
746
 
353
- // ../core/lib/resolve-root-data.ts
747
+ // ../../node_modules/uuid/dist/esm-node/v4.js
354
748
  init_react_import();
355
749
 
356
- // ../core/components/Puck/context.tsx
357
- import { jsx as jsx2 } from "react/jsx-runtime";
358
- var defaultAppState = {
359
- data: { content: [], root: {} },
360
- ui: {
361
- leftSideBarVisible: true,
362
- rightSideBarVisible: true,
363
- arrayState: {},
364
- itemSelector: null,
365
- componentList: {},
366
- isDragging: false,
367
- previewMode: "edit",
368
- viewports: {
369
- current: {
370
- width: defaultViewports[0].width,
371
- height: defaultViewports[0].height || "auto"
750
+ // ../../node_modules/uuid/dist/esm-node/native.js
751
+ init_react_import();
752
+ import crypto2 from "crypto";
753
+ var native_default = {
754
+ randomUUID: crypto2.randomUUID
755
+ };
756
+
757
+ // ../../node_modules/uuid/dist/esm-node/v4.js
758
+ function v4(options, buf, offset) {
759
+ if (native_default.randomUUID && !buf && !options) {
760
+ return native_default.randomUUID();
761
+ }
762
+ options = options || {};
763
+ const rnds = options.random || (options.rng || rng)();
764
+ rnds[6] = rnds[6] & 15 | 64;
765
+ rnds[8] = rnds[8] & 63 | 128;
766
+ if (buf) {
767
+ offset = offset || 0;
768
+ for (let i = 0; i < 16; ++i) {
769
+ buf[offset + i] = rnds[i];
770
+ }
771
+ return buf;
772
+ }
773
+ return unsafeStringify(rnds);
774
+ }
775
+ var v4_default = v4;
776
+
777
+ // ../core/lib/generate-id.ts
778
+ var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
779
+
780
+ // ../core/lib/get-zone-id.ts
781
+ init_react_import();
782
+ var getZoneId = (zoneCompound) => {
783
+ if (!zoneCompound) {
784
+ return [];
785
+ }
786
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
787
+ return zoneCompound.split(":");
788
+ }
789
+ return [rootDroppableId, zoneCompound];
790
+ };
791
+
792
+ // ../core/lib/reduce-related-zones.ts
793
+ function reduceRelatedZones(item, data, fn) {
794
+ return __spreadProps(__spreadValues({}, data), {
795
+ zones: Object.keys(data.zones || {}).reduce(
796
+ (acc, key) => {
797
+ const [parentId] = getZoneId(key);
798
+ if (parentId === item.props.id) {
799
+ const zones = data.zones;
800
+ return fn(acc, key, zones[key]);
801
+ }
802
+ return __spreadProps(__spreadValues({}, acc), { [key]: data.zones[key] });
372
803
  },
373
- options: [],
374
- controlsVisible: true
804
+ {}
805
+ )
806
+ });
807
+ }
808
+ var findRelatedByZoneId = (zoneId, data) => {
809
+ const [zoneParentId] = getZoneId(zoneId);
810
+ return (data.zones[zoneId] || []).reduce(
811
+ (acc, zoneItem) => {
812
+ const related = findRelatedByItem(zoneItem, data);
813
+ if (zoneItem.props.id === zoneParentId) {
814
+ return __spreadProps(__spreadValues(__spreadValues({}, acc), related), { [zoneId]: zoneItem });
815
+ }
816
+ return __spreadValues(__spreadValues({}, acc), related);
375
817
  },
376
- field: { focus: null }
818
+ {}
819
+ );
820
+ };
821
+ var findRelatedByItem = (item, data) => {
822
+ return Object.keys(data.zones || {}).reduce(
823
+ (acc, zoneId) => {
824
+ const [zoneParentId] = getZoneId(zoneId);
825
+ if (item.props.id === zoneParentId) {
826
+ const related = findRelatedByZoneId(zoneId, data);
827
+ return __spreadProps(__spreadValues(__spreadValues({}, acc), related), {
828
+ [zoneId]: data.zones[zoneId]
829
+ });
830
+ }
831
+ return acc;
832
+ },
833
+ {}
834
+ );
835
+ };
836
+ var removeRelatedZones = (item, data) => {
837
+ const newData = __spreadValues({}, data);
838
+ const related = findRelatedByItem(item, data);
839
+ Object.keys(related).forEach((key) => {
840
+ delete newData.zones[key];
841
+ });
842
+ return newData;
843
+ };
844
+ function duplicateRelatedZones(item, data, newId) {
845
+ return reduceRelatedZones(item, data, (acc, key, zone) => {
846
+ const dupedZone = zone.map((zoneItem) => __spreadProps(__spreadValues({}, zoneItem), {
847
+ props: __spreadProps(__spreadValues({}, zoneItem.props), { id: generateId(zoneItem.type) })
848
+ }));
849
+ const dupeOfDupes = dupedZone.reduce(
850
+ (dupeOfDupes2, item2, index) => __spreadValues(__spreadValues({}, dupeOfDupes2), duplicateRelatedZones(zone[index], data, item2.props.id).zones),
851
+ acc
852
+ );
853
+ const [_, zoneId] = getZoneId(key);
854
+ return __spreadProps(__spreadValues({}, dupeOfDupes), {
855
+ [key]: zone,
856
+ [`${newId}:${zoneId}`]: dupedZone
857
+ });
858
+ });
859
+ }
860
+
861
+ // ../core/reducer/data.ts
862
+ var zoneCache = {};
863
+ var replaceAction = (data, action) => {
864
+ if (action.destinationZone === rootDroppableId) {
865
+ return __spreadProps(__spreadValues({}, data), {
866
+ content: replace(data.content, action.destinationIndex, action.data)
867
+ });
377
868
  }
869
+ const newData = setupZone(data, action.destinationZone);
870
+ return __spreadProps(__spreadValues({}, newData), {
871
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
872
+ [action.destinationZone]: replace(
873
+ newData.zones[action.destinationZone],
874
+ action.destinationIndex,
875
+ action.data
876
+ )
877
+ })
878
+ });
378
879
  };
379
- var defaultContext = {
380
- state: defaultAppState,
381
- dispatch: () => null,
382
- config: { components: {} },
383
- componentState: {},
384
- setComponentState: () => {
385
- },
386
- resolveData: () => {
387
- },
388
- plugins: [],
389
- overrides: {},
390
- history: {},
391
- viewports: defaultViewports,
392
- zoomConfig: {
393
- autoZoom: 1,
394
- rootHeight: 0,
395
- zoom: 1
396
- },
397
- setZoomConfig: () => null,
398
- status: "LOADING",
399
- setStatus: () => null,
400
- iframe: {},
401
- globalPermissions: {},
402
- getPermissions: () => ({}),
403
- refreshPermissions: () => null,
404
- metadata: {}
405
- };
406
- var appContext = createContext(defaultContext);
407
- function useAppContext() {
408
- const mainContext = useContext(appContext);
409
- return __spreadProps(__spreadValues({}, mainContext), {
410
- // Helpers
411
- setUi: (ui, recordHistory) => {
412
- return mainContext.dispatch({
413
- type: "setUi",
414
- ui,
415
- recordHistory
880
+ function insertAction(data, action, config) {
881
+ const emptyComponentData = {
882
+ type: action.componentType,
883
+ props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
884
+ id: action.id || generateId(action.componentType)
885
+ })
886
+ };
887
+ if (action.destinationZone === rootDroppableId) {
888
+ return __spreadProps(__spreadValues({}, data), {
889
+ content: insert(
890
+ data.content,
891
+ action.destinationIndex,
892
+ emptyComponentData
893
+ )
894
+ });
895
+ }
896
+ const newData = setupZone(data, action.destinationZone);
897
+ return __spreadProps(__spreadValues({}, data), {
898
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
899
+ [action.destinationZone]: insert(
900
+ newData.zones[action.destinationZone],
901
+ action.destinationIndex,
902
+ emptyComponentData
903
+ )
904
+ })
905
+ });
906
+ }
907
+ var reorderAction = (data, action) => {
908
+ if (action.destinationZone === rootDroppableId) {
909
+ return __spreadProps(__spreadValues({}, data), {
910
+ content: reorder(
911
+ data.content,
912
+ action.sourceIndex,
913
+ action.destinationIndex
914
+ )
915
+ });
916
+ }
917
+ const newData = setupZone(data, action.destinationZone);
918
+ return __spreadProps(__spreadValues({}, data), {
919
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
920
+ [action.destinationZone]: reorder(
921
+ newData.zones[action.destinationZone],
922
+ action.sourceIndex,
923
+ action.destinationIndex
924
+ )
925
+ })
926
+ });
927
+ };
928
+ function reduceData(data, action, config) {
929
+ if (action.type === "insert") {
930
+ return insertAction(data, action, config);
931
+ }
932
+ if (action.type === "duplicate") {
933
+ const item = getItem(
934
+ { index: action.sourceIndex, zone: action.sourceZone },
935
+ data
936
+ );
937
+ const newItem = __spreadProps(__spreadValues({}, item), {
938
+ props: __spreadProps(__spreadValues({}, item.props), {
939
+ id: generateId(item.type)
940
+ })
941
+ });
942
+ const dataWithRelatedDuplicated = duplicateRelatedZones(
943
+ item,
944
+ data,
945
+ newItem.props.id
946
+ );
947
+ if (action.sourceZone === rootDroppableId) {
948
+ return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
949
+ content: insert(data.content, action.sourceIndex + 1, newItem)
416
950
  });
417
951
  }
418
- });
952
+ return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
953
+ zones: __spreadProps(__spreadValues({}, dataWithRelatedDuplicated.zones), {
954
+ [action.sourceZone]: insert(
955
+ dataWithRelatedDuplicated.zones[action.sourceZone],
956
+ action.sourceIndex + 1,
957
+ newItem
958
+ )
959
+ })
960
+ });
961
+ }
962
+ if (action.type === "reorder") {
963
+ return reorderAction(data, action);
964
+ }
965
+ if (action.type === "move") {
966
+ if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
967
+ return data;
968
+ }
969
+ const newData = setupZone(
970
+ setupZone(data, action.sourceZone),
971
+ action.destinationZone
972
+ );
973
+ const item = getItem(
974
+ { zone: action.sourceZone, index: action.sourceIndex },
975
+ newData
976
+ );
977
+ if (action.sourceZone === action.destinationZone) {
978
+ return reorderAction(data, __spreadProps(__spreadValues({}, action), { type: "reorder" }));
979
+ }
980
+ if (action.sourceZone === rootDroppableId) {
981
+ return __spreadProps(__spreadValues({}, newData), {
982
+ content: remove(newData.content, action.sourceIndex),
983
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
984
+ [action.destinationZone]: insert(
985
+ newData.zones[action.destinationZone],
986
+ action.destinationIndex,
987
+ item
988
+ )
989
+ })
990
+ });
991
+ }
992
+ if (action.destinationZone === rootDroppableId) {
993
+ return __spreadProps(__spreadValues({}, newData), {
994
+ content: insert(newData.content, action.destinationIndex, item),
995
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
996
+ [action.sourceZone]: remove(
997
+ newData.zones[action.sourceZone],
998
+ action.sourceIndex
999
+ )
1000
+ })
1001
+ });
1002
+ }
1003
+ return __spreadProps(__spreadValues({}, newData), {
1004
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
1005
+ [action.sourceZone]: remove(
1006
+ newData.zones[action.sourceZone],
1007
+ action.sourceIndex
1008
+ ),
1009
+ [action.destinationZone]: insert(
1010
+ newData.zones[action.destinationZone],
1011
+ action.destinationIndex,
1012
+ item
1013
+ )
1014
+ })
1015
+ });
1016
+ }
1017
+ if (action.type === "replace") {
1018
+ return replaceAction(data, action);
1019
+ }
1020
+ if (action.type === "remove") {
1021
+ const item = getItem({ index: action.index, zone: action.zone }, data);
1022
+ const dataWithRelatedRemoved = setupZone(
1023
+ removeRelatedZones(item, data),
1024
+ action.zone
1025
+ );
1026
+ if (action.zone === rootDroppableId) {
1027
+ return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
1028
+ content: remove(data.content, action.index)
1029
+ });
1030
+ }
1031
+ return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
1032
+ zones: __spreadProps(__spreadValues({}, dataWithRelatedRemoved.zones), {
1033
+ [action.zone]: remove(
1034
+ dataWithRelatedRemoved.zones[action.zone],
1035
+ action.index
1036
+ )
1037
+ })
1038
+ });
1039
+ }
1040
+ if (action.type === "registerZone") {
1041
+ if (zoneCache[action.zone]) {
1042
+ return __spreadProps(__spreadValues({}, data), {
1043
+ zones: __spreadProps(__spreadValues({}, data.zones), {
1044
+ [action.zone]: zoneCache[action.zone]
1045
+ })
1046
+ });
1047
+ }
1048
+ return setupZone(data, action.zone);
1049
+ }
1050
+ if (action.type === "unregisterZone") {
1051
+ const _zones = __spreadValues({}, data.zones || {});
1052
+ if (_zones[action.zone]) {
1053
+ zoneCache[action.zone] = _zones[action.zone];
1054
+ delete _zones[action.zone];
1055
+ }
1056
+ return __spreadProps(__spreadValues({}, data), { zones: _zones });
1057
+ }
1058
+ if (action.type === "setData") {
1059
+ if (typeof action.data === "object") {
1060
+ return __spreadValues(__spreadValues({}, data), action.data);
1061
+ }
1062
+ return __spreadValues(__spreadValues({}, data), action.data(data));
1063
+ }
1064
+ return data;
419
1065
  }
420
1066
 
1067
+ // ../core/reducer/state.ts
1068
+ init_react_import();
1069
+ var reduceUi = (ui, action) => {
1070
+ if (action.type === "setUi") {
1071
+ if (typeof action.ui === "object") {
1072
+ return __spreadValues(__spreadValues({}, ui), action.ui);
1073
+ }
1074
+ return __spreadValues(__spreadValues({}, ui), action.ui(ui));
1075
+ }
1076
+ if (action.type === "duplicate") {
1077
+ return __spreadProps(__spreadValues({}, ui), {
1078
+ itemSelector: { index: action.sourceIndex + 1, zone: action.sourceZone }
1079
+ });
1080
+ }
1081
+ if (action.type === "remove") {
1082
+ return __spreadProps(__spreadValues({}, ui), {
1083
+ itemSelector: null
1084
+ });
1085
+ }
1086
+ return ui;
1087
+ };
1088
+
1089
+ // ../core/reducer/actions.tsx
1090
+ init_react_import();
1091
+
1092
+ // ../core/reducer/index.ts
1093
+ function storeInterceptor(reducer, record, onAction) {
1094
+ return (state, action) => {
1095
+ const newAppState = reducer(state, action);
1096
+ const isValidType = ![
1097
+ "registerZone",
1098
+ "unregisterZone",
1099
+ "setData",
1100
+ "setUi",
1101
+ "set"
1102
+ ].includes(action.type);
1103
+ if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1104
+ if (record) record(newAppState);
1105
+ }
1106
+ onAction == null ? void 0 : onAction(action, newAppState, state);
1107
+ return newAppState;
1108
+ };
1109
+ }
1110
+ var setAction = (state, action) => {
1111
+ if (typeof action.state === "object") {
1112
+ return __spreadValues(__spreadValues({}, state), action.state);
1113
+ }
1114
+ return __spreadValues(__spreadValues({}, state), action.state(state));
1115
+ };
1116
+ function createReducer({
1117
+ config,
1118
+ record,
1119
+ onAction
1120
+ }) {
1121
+ return storeInterceptor(
1122
+ (state, action) => {
1123
+ const data = reduceData(state.data, action, config);
1124
+ const ui = reduceUi(state.ui, action);
1125
+ if (action.type === "set") {
1126
+ return setAction(state, action);
1127
+ }
1128
+ return { data, ui };
1129
+ },
1130
+ record,
1131
+ onAction
1132
+ );
1133
+ }
1134
+
1135
+ // ../core/components/ViewportControls/default-viewports.ts
1136
+ init_react_import();
1137
+ var defaultViewports = [
1138
+ { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
1139
+ { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
1140
+ { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
1141
+ ];
1142
+
1143
+ // ../../node_modules/zustand/esm/index.mjs
1144
+ init_react_import();
1145
+
421
1146
  // ../../node_modules/zustand/esm/vanilla.mjs
422
1147
  init_react_import();
1148
+ var import_meta = {};
423
1149
  var createStoreImpl = (createState) => {
424
1150
  let state;
425
1151
  const listeners = /* @__PURE__ */ new Set();
426
- const setState = (partial, replace) => {
1152
+ const setState = (partial, replace2) => {
427
1153
  const nextState = typeof partial === "function" ? partial(state) : partial;
428
1154
  if (!Object.is(nextState, state)) {
429
1155
  const previousState = state;
430
- state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
1156
+ state = (replace2 != null ? replace2 : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
431
1157
  listeners.forEach((listener) => listener(state, previousState));
432
1158
  }
433
1159
  };
@@ -437,100 +1163,732 @@ var createStoreImpl = (createState) => {
437
1163
  listeners.add(listener);
438
1164
  return () => listeners.delete(listener);
439
1165
  };
440
- const api = { setState, getState, getInitialState, subscribe };
1166
+ const destroy = () => {
1167
+ if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
1168
+ console.warn(
1169
+ "[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."
1170
+ );
1171
+ }
1172
+ listeners.clear();
1173
+ };
1174
+ const api = { setState, getState, getInitialState, subscribe, destroy };
441
1175
  const initialState = state = createState(setState, getState, api);
442
1176
  return api;
443
1177
  };
444
1178
  var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
445
1179
 
446
- // ../core/components/DropZone/context.tsx
447
- import { Fragment, jsx as jsx3 } from "react/jsx-runtime";
448
- var dropZoneContext = createContext2(null);
449
- var ZoneStoreContext = createContext2(
450
- createStore(() => ({
451
- zoneDepthIndex: {},
452
- nextZoneDepthIndex: {},
453
- areaDepthIndex: {},
454
- nextAreaDepthIndex: {},
455
- draggedItem: null,
456
- previewIndex: {}
457
- }))
458
- );
459
-
460
- // ../core/lib/get-zone-id.ts
461
- init_react_import();
462
- var getZoneId = (zoneCompound) => {
463
- if (!zoneCompound) {
464
- return [];
1180
+ // ../../node_modules/zustand/esm/index.mjs
1181
+ var import_with_selector = __toESM(require_with_selector(), 1);
1182
+ import ReactExports from "react";
1183
+ var import_meta2 = {};
1184
+ var { useDebugValue } = ReactExports;
1185
+ var { useSyncExternalStoreWithSelector } = import_with_selector.default;
1186
+ var didWarnAboutEqualityFn = false;
1187
+ var identity = (arg) => arg;
1188
+ function useStore(api, selector = identity, equalityFn) {
1189
+ if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production" && equalityFn && !didWarnAboutEqualityFn) {
1190
+ console.warn(
1191
+ "[DEPRECATED] Use `createWithEqualityFn` instead of `create` or use `useStoreWithEqualityFn` instead of `useStore`. They can be imported from 'zustand/traditional'. https://github.com/pmndrs/zustand/discussions/1937"
1192
+ );
1193
+ didWarnAboutEqualityFn = true;
465
1194
  }
466
- if (zoneCompound && zoneCompound.indexOf(":") > -1) {
467
- return zoneCompound.split(":");
1195
+ const slice = useSyncExternalStoreWithSelector(
1196
+ api.subscribe,
1197
+ api.getState,
1198
+ api.getServerState || api.getInitialState,
1199
+ selector,
1200
+ equalityFn
1201
+ );
1202
+ useDebugValue(slice);
1203
+ return slice;
1204
+ }
1205
+ var createImpl = (createState) => {
1206
+ if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production" && typeof createState !== "function") {
1207
+ console.warn(
1208
+ "[DEPRECATED] Passing a vanilla store will be unsupported in a future version. Instead use `import { useStore } from 'zustand'`."
1209
+ );
468
1210
  }
469
- return [rootDroppableId, zoneCompound];
1211
+ const api = typeof createState === "function" ? createStore(createState) : createState;
1212
+ const useBoundStore = (selector, equalityFn) => useStore(api, selector, equalityFn);
1213
+ Object.assign(useBoundStore, api);
1214
+ return useBoundStore;
470
1215
  };
1216
+ var create = (createState) => createState ? createImpl(createState) : createImpl;
471
1217
 
472
- // ../core/lib/use-breadcrumbs.ts
473
- var convertPathDataToBreadcrumbs = (selectedItem, pathData, data) => {
474
- const id = selectedItem ? selectedItem == null ? void 0 : selectedItem.props.id : "";
475
- const currentPathData = pathData && id && pathData[id] ? __spreadValues({}, pathData[id]) : { label: "Page", path: [] };
476
- if (!id) {
477
- return [];
478
- }
479
- return currentPathData == null ? void 0 : currentPathData.path.reduce((acc, zoneCompound) => {
480
- const [area] = getZoneId(zoneCompound);
481
- if (area === rootDroppableId) {
482
- return [
483
- {
484
- label: "Page",
485
- selector: null
1218
+ // ../../node_modules/zustand/esm/middleware.mjs
1219
+ init_react_import();
1220
+ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
1221
+ const origSubscribe = api.subscribe;
1222
+ api.subscribe = (selector, optListener, options) => {
1223
+ let listener = selector;
1224
+ if (optListener) {
1225
+ const equalityFn = (options == null ? void 0 : options.equalityFn) || Object.is;
1226
+ let currentSlice = selector(api.getState());
1227
+ listener = (state) => {
1228
+ const nextSlice = selector(state);
1229
+ if (!equalityFn(currentSlice, nextSlice)) {
1230
+ const previousSlice = currentSlice;
1231
+ optListener(currentSlice = nextSlice, previousSlice);
486
1232
  }
487
- ];
1233
+ };
1234
+ if (options == null ? void 0 : options.fireImmediately) {
1235
+ optListener(currentSlice, currentSlice);
1236
+ }
488
1237
  }
489
- const parentZoneCompound = acc.length > 0 ? acc[acc.length - 1].zoneCompound : rootDroppableId;
490
- let parentZone = data.content;
491
- if (parentZoneCompound && parentZoneCompound !== rootDroppableId) {
492
- parentZone = data.zones[parentZoneCompound];
1238
+ return origSubscribe(listener);
1239
+ };
1240
+ const initialState = fn(set, get, api);
1241
+ return initialState;
1242
+ };
1243
+ var subscribeWithSelector = subscribeWithSelectorImpl;
1244
+
1245
+ // ../core/lib/resolve-data.ts
1246
+ init_react_import();
1247
+
1248
+ // ../core/lib/resolve-component-data.ts
1249
+ init_react_import();
1250
+
1251
+ // ../core/lib/get-changed.ts
1252
+ init_react_import();
1253
+ var getChanged = (newItem, oldItem) => {
1254
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1255
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1256
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1257
+ return __spreadProps(__spreadValues({}, acc), {
1258
+ [item]: oldItemProps[item] !== newItemProps[item]
1259
+ });
1260
+ }, {}) : {};
1261
+ };
1262
+
1263
+ // ../core/lib/resolve-component-data.ts
1264
+ var cache = { lastChange: {} };
1265
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd) {
1266
+ const configForItem = config.components[item.type];
1267
+ if (configForItem.resolveData) {
1268
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
1269
+ if (item && item === oldItem) {
1270
+ return resolved;
493
1271
  }
494
- if (!parentZone) {
495
- return acc;
1272
+ const changed = getChanged(item, oldItem);
1273
+ if (onResolveStart) {
1274
+ onResolveStart(item);
1275
+ }
1276
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1277
+ changed,
1278
+ lastData: oldItem,
1279
+ metadata
1280
+ });
1281
+ const resolvedItem = __spreadProps(__spreadValues({}, item), {
1282
+ props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1283
+ });
1284
+ if (Object.keys(readOnly).length) {
1285
+ resolvedItem.readOnly = readOnly;
1286
+ }
1287
+ cache.lastChange[item.props.id] = {
1288
+ item,
1289
+ resolved: resolvedItem
1290
+ };
1291
+ if (onResolveEnd) {
1292
+ onResolveEnd(resolvedItem);
1293
+ }
1294
+ return resolvedItem;
1295
+ }
1296
+ return item;
1297
+ });
1298
+
1299
+ // ../core/lib/apply-dynamic-props.ts
1300
+ init_react_import();
1301
+ var applyDynamicProps = (data, dynamicProps, rootData) => {
1302
+ return __spreadProps(__spreadValues({}, data), {
1303
+ root: rootData ? __spreadValues(__spreadValues({}, data.root), rootData ? rootData : {}) : data.root,
1304
+ content: data.content.map((item) => {
1305
+ return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
1306
+ }),
1307
+ zones: Object.keys(data.zones || {}).reduce((acc, zoneKey) => {
1308
+ return __spreadProps(__spreadValues({}, acc), {
1309
+ [zoneKey]: data.zones[zoneKey].map((item) => {
1310
+ return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
1311
+ })
1312
+ });
1313
+ }, {})
1314
+ });
1315
+ };
1316
+
1317
+ // ../core/lib/resolve-root-data.ts
1318
+ init_react_import();
1319
+ var cache2 = {};
1320
+ function resolveRootData(data, config, metadata) {
1321
+ return __async(this, null, function* () {
1322
+ var _a, _b, _c, _d, _e;
1323
+ if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
1324
+ if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
1325
+ return cache2.lastChange.resolved;
1326
+ }
1327
+ const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
1328
+ const rootWithProps = data.root;
1329
+ const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
1330
+ changed,
1331
+ lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {},
1332
+ metadata: metadata || {}
1333
+ });
1334
+ cache2.lastChange = {
1335
+ original: data.root,
1336
+ resolved: resolvedRoot
1337
+ };
1338
+ return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
1339
+ props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
1340
+ });
496
1341
  }
497
- const itemIndex = parentZone.findIndex(
498
- (queryItem) => queryItem.props.id === area
1342
+ return data.root;
1343
+ });
1344
+ }
1345
+
1346
+ // ../core/lib/flatten-data.ts
1347
+ init_react_import();
1348
+ var flattenData = (data) => {
1349
+ return Object.keys(data.zones || {}).reduce(
1350
+ (acc, zone) => [...acc, ...data.zones[zone]],
1351
+ data.content
1352
+ );
1353
+ };
1354
+
1355
+ // ../core/lib/resolve-data.ts
1356
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1357
+ var resolveData = (newAppState, appStoreData) => {
1358
+ const {
1359
+ state: appState,
1360
+ config,
1361
+ dispatch,
1362
+ resolveDataRuns,
1363
+ setComponentLoading,
1364
+ unsetComponentLoading,
1365
+ metadata,
1366
+ permissions
1367
+ } = appStoreData;
1368
+ const deferredSetStates = {};
1369
+ const _setComponentLoading = (id, loading, defer = 0) => {
1370
+ if (deferredSetStates[id]) {
1371
+ clearTimeout(deferredSetStates[id]);
1372
+ delete deferredSetStates[id];
1373
+ }
1374
+ deferredSetStates[id] = setTimeout(() => {
1375
+ if (loading) {
1376
+ setComponentLoading(id);
1377
+ } else {
1378
+ unsetComponentLoading(id);
1379
+ }
1380
+ delete deferredSetStates[id];
1381
+ }, defer);
1382
+ };
1383
+ const runResolvers = () => __async(void 0, null, function* () {
1384
+ const newData = newAppState.data;
1385
+ const flatContent = flattenData(newData).filter(
1386
+ (item) => {
1387
+ var _a;
1388
+ return !!((_a = config.components[item.type]) == null ? void 0 : _a.resolveData);
1389
+ }
499
1390
  );
500
- const item = parentZone[itemIndex];
501
- if (!item) {
502
- return acc;
1391
+ const applyIfChange = (dynamicDataMap, dynamicRoot) => {
1392
+ const processed = applyDynamicProps(
1393
+ __spreadValues({}, appState.data),
1394
+ dynamicDataMap,
1395
+ dynamicRoot
1396
+ );
1397
+ const processedAppState = __spreadProps(__spreadValues({}, appState), { data: processed });
1398
+ const containsChanges = !(0, import_fast_deep_equal.default)(appState, processedAppState);
1399
+ if (containsChanges) {
1400
+ dispatch({
1401
+ type: "set",
1402
+ state: (prev) => __spreadProps(__spreadValues({}, prev), {
1403
+ data: applyDynamicProps(prev.data, dynamicDataMap, dynamicRoot),
1404
+ ui: resolveDataRuns > 0 ? __spreadValues(__spreadValues({}, prev.ui), newAppState.ui) : prev.ui
1405
+ }),
1406
+ recordHistory: resolveDataRuns > 0
1407
+ });
1408
+ }
1409
+ };
1410
+ const promises = [];
1411
+ promises.push(
1412
+ (() => __async(void 0, null, function* () {
1413
+ _setComponentLoading("puck-root", true, 50);
1414
+ const dynamicRoot = yield resolveRootData(newData, config, metadata);
1415
+ applyIfChange({}, dynamicRoot);
1416
+ _setComponentLoading("puck-root", false);
1417
+ }))()
1418
+ );
1419
+ flatContent.forEach((item) => {
1420
+ promises.push(
1421
+ (() => __async(void 0, null, function* () {
1422
+ permissions.resolvePermissions({ item }, true);
1423
+ const dynamicData = yield resolveComponentData(
1424
+ item,
1425
+ config,
1426
+ metadata,
1427
+ (item2) => {
1428
+ _setComponentLoading(item2.props.id, true, 50);
1429
+ },
1430
+ (item2) => {
1431
+ deferredSetStates[item2.props.id];
1432
+ _setComponentLoading(item2.props.id, false);
1433
+ }
1434
+ );
1435
+ const dynamicDataMap = { [item.props.id]: dynamicData };
1436
+ applyIfChange(dynamicDataMap);
1437
+ }))()
1438
+ );
1439
+ });
1440
+ yield Promise.all(promises);
1441
+ });
1442
+ return runResolvers();
1443
+ };
1444
+
1445
+ // ../core/store/index.ts
1446
+ import { createContext, useContext } from "react";
1447
+
1448
+ // ../core/store/slices/history.ts
1449
+ init_react_import();
1450
+ import { useEffect as useEffect2 } from "react";
1451
+
1452
+ // ../core/lib/use-hotkey.ts
1453
+ init_react_import();
1454
+ import { useEffect } from "react";
1455
+ var useHotkeyStore = create()(
1456
+ subscribeWithSelector((set) => ({
1457
+ held: {},
1458
+ hold: (key) => set((s) => s.held[key] ? s : { held: __spreadProps(__spreadValues({}, s.held), { [key]: true }) }),
1459
+ release: (key) => set((s) => s.held[key] ? { held: __spreadProps(__spreadValues({}, s.held), { [key]: false }) } : s),
1460
+ reset: (held = {}) => set(() => ({ held })),
1461
+ triggers: {}
1462
+ }))
1463
+ );
1464
+
1465
+ // ../core/store/slices/history.ts
1466
+ var EMPTY_HISTORY_INDEX = 0;
1467
+ function debounce(func, timeout = 300) {
1468
+ let timer;
1469
+ return (...args) => {
1470
+ clearTimeout(timer);
1471
+ timer = setTimeout(() => {
1472
+ func(...args);
1473
+ }, timeout);
1474
+ };
1475
+ }
1476
+ var tidyState = (state) => {
1477
+ return __spreadProps(__spreadValues({}, state), {
1478
+ ui: __spreadProps(__spreadValues({}, state.ui), {
1479
+ field: {
1480
+ focus: null
1481
+ }
1482
+ })
1483
+ });
1484
+ };
1485
+ var createHistorySlice = (set, get) => {
1486
+ const record = debounce((state) => {
1487
+ const { histories, index } = get().history;
1488
+ const history = {
1489
+ state,
1490
+ id: generateId("history")
1491
+ };
1492
+ const newHistories = [...histories.slice(0, index + 1), history];
1493
+ set({
1494
+ history: __spreadProps(__spreadValues({}, get().history), {
1495
+ histories: newHistories,
1496
+ index: newHistories.length - 1
1497
+ })
1498
+ });
1499
+ }, 250);
1500
+ return {
1501
+ initialAppState: {},
1502
+ index: EMPTY_HISTORY_INDEX,
1503
+ histories: [],
1504
+ hasPast: () => get().history.index > EMPTY_HISTORY_INDEX,
1505
+ hasFuture: () => get().history.index < get().history.histories.length - 1,
1506
+ prevHistory: () => {
1507
+ const { history } = get();
1508
+ return history.hasPast() ? history.histories[history.index - 1] : null;
1509
+ },
1510
+ nextHistory: () => {
1511
+ const s = get().history;
1512
+ return s.hasFuture() ? s.histories[s.index + 1] : null;
1513
+ },
1514
+ currentHistory: () => get().history.histories[get().history.index],
1515
+ back: () => {
1516
+ var _a;
1517
+ const { history, dispatch } = get();
1518
+ if (history.hasPast()) {
1519
+ const state = tidyState(
1520
+ ((_a = history.prevHistory()) == null ? void 0 : _a.state) || history.initialAppState
1521
+ );
1522
+ dispatch({
1523
+ type: "set",
1524
+ state
1525
+ });
1526
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index - 1 }) });
1527
+ }
1528
+ },
1529
+ forward: () => {
1530
+ var _a;
1531
+ const { history, dispatch } = get();
1532
+ if (history.hasFuture()) {
1533
+ const state = (_a = history.nextHistory()) == null ? void 0 : _a.state;
1534
+ dispatch({ type: "set", state: state ? tidyState(state) : {} });
1535
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index + 1 }) });
1536
+ }
1537
+ },
1538
+ setHistories: (histories) => {
1539
+ var _a;
1540
+ const { dispatch, history } = get();
1541
+ dispatch({
1542
+ type: "set",
1543
+ state: ((_a = history.histories[history.histories.length - 1]) == null ? void 0 : _a.state) || history.initialAppState
1544
+ });
1545
+ set({ history: __spreadProps(__spreadValues({}, history), { histories, index: histories.length - 1 }) });
1546
+ },
1547
+ setHistoryIndex: (index) => {
1548
+ var _a;
1549
+ const { dispatch, history } = get();
1550
+ dispatch({
1551
+ type: "set",
1552
+ state: ((_a = history.histories[history.index]) == null ? void 0 : _a.state) || history.initialAppState
1553
+ });
1554
+ set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1555
+ },
1556
+ record
1557
+ };
1558
+ };
1559
+
1560
+ // ../core/store/slices/nodes.ts
1561
+ init_react_import();
1562
+ var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
1563
+ import { useEffect as useEffect3 } from "react";
1564
+ var partialDeepEqual = (newItem, existingItem) => {
1565
+ const filteredExistingItem = Object.keys(newItem).reduce(
1566
+ (acc, key) => __spreadProps(__spreadValues({}, acc), { [key]: existingItem[key] }),
1567
+ {}
1568
+ );
1569
+ return (0, import_fast_deep_equal2.default)(newItem, filteredExistingItem);
1570
+ };
1571
+ var createNodesSlice = (set, get) => ({
1572
+ nodes: {},
1573
+ registerNode: (id, node) => {
1574
+ const s = get().nodes;
1575
+ if (s.nodes[id] && partialDeepEqual(node, s.nodes[id])) {
1576
+ return;
503
1577
  }
504
- return [
505
- ...acc,
506
- {
507
- label: item.type.toString(),
508
- selector: {
509
- index: itemIndex,
510
- zone: parentZoneCompound
1578
+ const emptyNode = {
1579
+ id,
1580
+ methods: { sync: () => null },
1581
+ data: { props: { id }, type: "unknown" },
1582
+ parentId: "",
1583
+ zone: "",
1584
+ path: [],
1585
+ element: null,
1586
+ index: -1
1587
+ };
1588
+ const existingNode = s.nodes[id];
1589
+ set({
1590
+ nodes: __spreadProps(__spreadValues({}, s), {
1591
+ nodes: __spreadProps(__spreadValues({}, s.nodes), {
1592
+ [id]: __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, emptyNode), existingNode), node), {
1593
+ id
1594
+ })
1595
+ })
1596
+ })
1597
+ });
1598
+ },
1599
+ unregisterNode: (id) => {
1600
+ const s = get().nodes;
1601
+ const existingNode = s.nodes[id];
1602
+ if (existingNode) {
1603
+ const newNodes = __spreadValues({}, s.nodes);
1604
+ delete newNodes[id];
1605
+ set({
1606
+ nodes: __spreadProps(__spreadValues({}, s), {
1607
+ nodes: newNodes
1608
+ })
1609
+ });
1610
+ }
1611
+ }
1612
+ });
1613
+
1614
+ // ../core/store/slices/permissions.ts
1615
+ init_react_import();
1616
+ import { useEffect as useEffect4 } from "react";
1617
+ var createPermissionsSlice = (set, get) => {
1618
+ const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1619
+ const { state, permissions } = get();
1620
+ const { cache: cache3, globalPermissions } = permissions;
1621
+ const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1622
+ var _a, _b, _c;
1623
+ const {
1624
+ config,
1625
+ state: appState,
1626
+ setComponentLoading,
1627
+ unsetComponentLoading
1628
+ } = get();
1629
+ const componentConfig = item2.type === "root" ? config.root : config.components[item2.type];
1630
+ if (!componentConfig) {
1631
+ return;
1632
+ }
1633
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1634
+ if (componentConfig.resolvePermissions) {
1635
+ const changed = getChanged(item2, (_a = cache3[item2.props.id]) == null ? void 0 : _a.lastData);
1636
+ if (Object.values(changed).some((el) => el === true) || force2) {
1637
+ setComponentLoading(item2.props.id);
1638
+ const resolvedPermissions = yield componentConfig.resolvePermissions(
1639
+ item2,
1640
+ {
1641
+ changed,
1642
+ lastPermissions: ((_b = cache3[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1643
+ permissions: initialPermissions,
1644
+ appState,
1645
+ lastData: ((_c = cache3[item2.props.id]) == null ? void 0 : _c.lastData) || null
1646
+ }
1647
+ );
1648
+ const latest = get().permissions;
1649
+ set({
1650
+ permissions: __spreadProps(__spreadValues({}, latest), {
1651
+ cache: __spreadProps(__spreadValues({}, latest.cache), {
1652
+ [item2.props.id]: {
1653
+ lastData: item2,
1654
+ lastPermissions: resolvedPermissions
1655
+ }
1656
+ }),
1657
+ resolvedPermissions: __spreadProps(__spreadValues({}, latest.resolvedPermissions), {
1658
+ [item2.props.id]: resolvedPermissions
1659
+ })
1660
+ })
1661
+ });
1662
+ unsetComponentLoading(item2.props.id);
1663
+ }
1664
+ }
1665
+ });
1666
+ const resolveDataForRoot = (force2 = false) => {
1667
+ const { state: appState } = get();
1668
+ resolveDataForItem(
1669
+ // Shim the root data in by conforming to component data shape
1670
+ {
1671
+ type: "root",
1672
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "puck-root" })
511
1673
  },
512
- zoneCompound
1674
+ force2
1675
+ );
1676
+ };
1677
+ const { item, type, root } = params;
1678
+ if (item) {
1679
+ yield resolveDataForItem(item, force);
1680
+ } else if (type) {
1681
+ flattenData(state.data).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1682
+ yield resolveDataForItem(item2, force);
1683
+ }));
1684
+ } else if (root) {
1685
+ resolveDataForRoot(force);
1686
+ } else {
1687
+ resolveDataForRoot(force);
1688
+ flattenData(state.data).map((item2) => __async(void 0, null, function* () {
1689
+ yield resolveDataForItem(item2, force);
1690
+ }));
1691
+ }
1692
+ });
1693
+ const refreshPermissions = (params) => resolvePermissions(params, true);
1694
+ return {
1695
+ cache: {},
1696
+ globalPermissions: {
1697
+ drag: true,
1698
+ edit: true,
1699
+ delete: true,
1700
+ duplicate: true,
1701
+ insert: true
1702
+ },
1703
+ resolvedPermissions: {},
1704
+ getPermissions: ({ item, type, root } = {}) => {
1705
+ const { config, permissions } = get();
1706
+ const { globalPermissions, resolvedPermissions } = permissions;
1707
+ if (item) {
1708
+ const componentConfig = config.components[item.type];
1709
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1710
+ const resolvedForItem = resolvedPermissions[item.props.id];
1711
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1712
+ } else if (type) {
1713
+ const componentConfig = config.components[type];
1714
+ return __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1715
+ } else if (root) {
1716
+ const rootConfig = config.root;
1717
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1718
+ const resolvedForItem = resolvedPermissions["puck-root"];
1719
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
513
1720
  }
514
- ];
515
- }, []);
1721
+ return globalPermissions;
1722
+ },
1723
+ resolvePermissions,
1724
+ refreshPermissions
1725
+ };
1726
+ };
1727
+
1728
+ // ../core/store/slices/fields.ts
1729
+ init_react_import();
1730
+ import { useCallback, useEffect as useEffect5 } from "react";
1731
+ var createFieldsStore = (_set, _get) => {
1732
+ return {
1733
+ fields: {},
1734
+ loading: false,
1735
+ lastResolvedData: {}
1736
+ };
1737
+ };
1738
+
1739
+ // ../core/store/index.ts
1740
+ var defaultAppState = {
1741
+ data: { content: [], root: {}, zones: {} },
1742
+ ui: {
1743
+ leftSideBarVisible: true,
1744
+ rightSideBarVisible: true,
1745
+ arrayState: {},
1746
+ itemSelector: null,
1747
+ componentList: {},
1748
+ isDragging: false,
1749
+ previewMode: "edit",
1750
+ viewports: {
1751
+ current: {
1752
+ width: defaultViewports[0].width,
1753
+ height: defaultViewports[0].height || "auto"
1754
+ },
1755
+ options: [],
1756
+ controlsVisible: true
1757
+ },
1758
+ field: { focus: null }
1759
+ }
1760
+ };
1761
+ var defaultPageFields = {
1762
+ title: { type: "text" }
516
1763
  };
1764
+ var createAppStore = (initialAppStore) => create()(
1765
+ subscribeWithSelector((set, get) => __spreadProps(__spreadValues({
1766
+ state: defaultAppState,
1767
+ config: { components: {} },
1768
+ componentState: {},
1769
+ plugins: [],
1770
+ overrides: {},
1771
+ viewports: defaultViewports,
1772
+ zoomConfig: {
1773
+ autoZoom: 1,
1774
+ rootHeight: 0,
1775
+ zoom: 1
1776
+ },
1777
+ status: "LOADING",
1778
+ iframe: {},
1779
+ metadata: {}
1780
+ }, initialAppStore), {
1781
+ fields: createFieldsStore(set, get),
1782
+ history: createHistorySlice(set, get),
1783
+ nodes: createNodesSlice(set, get),
1784
+ permissions: createPermissionsSlice(set, get),
1785
+ getComponentConfig: (type) => {
1786
+ var _a;
1787
+ const { config, selectedItem } = get();
1788
+ const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
1789
+ return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1790
+ },
1791
+ dispatch: (action) => set((s) => {
1792
+ var _a, _b;
1793
+ const { record } = get().history;
1794
+ const dispatch = createReducer({ config: s.config, record });
1795
+ const state = dispatch(s.state, action);
1796
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state.data) : null;
1797
+ (_b = (_a = get()).onAction) == null ? void 0 : _b.call(_a, action, state, get().state);
1798
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1799
+ }),
1800
+ setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1801
+ setStatus: (status) => set({ status }),
1802
+ setComponentState: (componentState) => set({ componentState }),
1803
+ setComponentLoading: (id) => {
1804
+ var _a;
1805
+ const { setComponentState, componentState } = get();
1806
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1807
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1808
+ loadingCount: (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1809
+ })
1810
+ }));
1811
+ },
1812
+ unsetComponentLoading: (id) => {
1813
+ var _a;
1814
+ const { setComponentState, componentState } = get();
1815
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1816
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1817
+ loadingCount: Math.max(
1818
+ (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) - 1,
1819
+ 0
1820
+ )
1821
+ })
1822
+ }));
1823
+ },
1824
+ // Helper
1825
+ setUi: (ui, recordHistory) => set((s) => {
1826
+ const dispatch = createReducer({
1827
+ config: s.config,
1828
+ record: () => {
1829
+ }
1830
+ });
1831
+ const state = dispatch(s.state, {
1832
+ type: "setUi",
1833
+ ui,
1834
+ recordHistory
1835
+ });
1836
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state.data) : null;
1837
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1838
+ }),
1839
+ resolveDataRuns: 0,
1840
+ resolveData: (newAppState) => set((s) => {
1841
+ resolveData(newAppState, get());
1842
+ return __spreadProps(__spreadValues({}, s), { resolveDataRuns: s.resolveDataRuns + 1 });
1843
+ })
1844
+ }))
1845
+ );
1846
+ var appStoreContext = createContext(createAppStore());
1847
+ function useAppStore(selector) {
1848
+ const context = useContext(appStoreContext);
1849
+ return useStore(context, selector);
1850
+ }
1851
+ function useAppStoreApi() {
1852
+ return useContext(appStoreContext);
1853
+ }
1854
+
1855
+ // ../core/lib/use-breadcrumbs.ts
517
1856
  var useBreadcrumbs = (renderCount) => {
518
- const {
519
- state: { data },
520
- selectedItem
521
- } = useAppContext();
522
- const dzContext = useContext2(dropZoneContext);
523
- return useMemo2(() => {
524
- const breadcrumbs = convertPathDataToBreadcrumbs(
525
- selectedItem,
526
- dzContext == null ? void 0 : dzContext.pathData,
527
- data
528
- );
1857
+ const selectedId = useAppStore((s) => {
1858
+ var _a;
1859
+ return (_a = s.selectedItem) == null ? void 0 : _a.props.id;
1860
+ });
1861
+ const config = useAppStore((s) => s.config);
1862
+ const path = useAppStore((s) => {
1863
+ var _a;
1864
+ return (_a = s.nodes.nodes[selectedId]) == null ? void 0 : _a.path;
1865
+ });
1866
+ const appStore = useAppStoreApi();
1867
+ return useMemo(() => {
1868
+ const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
1869
+ var _a, _b;
1870
+ const [componentId] = zoneCompound.split(":");
1871
+ if (componentId === "root") {
1872
+ return {
1873
+ label: "Page",
1874
+ selector: null
1875
+ };
1876
+ }
1877
+ const node = appStore.getState().nodes.nodes[componentId];
1878
+ const label = node ? (_b = (_a = config.components[node.data.type]) == null ? void 0 : _a.label) != null ? _b : node.data.type : "Component";
1879
+ return {
1880
+ label,
1881
+ selector: node ? {
1882
+ index: node.index,
1883
+ zone: node.path[node.path.length - 1]
1884
+ } : null
1885
+ };
1886
+ })) || [];
529
1887
  if (renderCount) {
530
1888
  return breadcrumbs.slice(breadcrumbs.length - renderCount);
531
1889
  }
532
1890
  return breadcrumbs;
533
- }, [selectedItem, dzContext == null ? void 0 : dzContext.pathData, renderCount]);
1891
+ }, [path, renderCount]);
534
1892
  };
535
1893
 
536
1894
  // ../core/components/Loader/index.tsx
@@ -542,18 +1900,12 @@ init_react_import();
542
1900
  // ../core/lib/filter.ts
543
1901
  init_react_import();
544
1902
 
545
- // ../core/lib/reorder.ts
546
- init_react_import();
547
-
548
- // ../core/lib/replace.ts
549
- init_react_import();
550
-
551
1903
  // css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
552
1904
  init_react_import();
553
1905
  var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
554
1906
 
555
1907
  // ../core/components/Loader/index.tsx
556
- import { jsx as jsx4 } from "react/jsx-runtime";
1908
+ import { jsx as jsx2 } from "react/jsx-runtime";
557
1909
  var getClassName2 = get_class_name_factory_default("Loader", styles_module_default3);
558
1910
  var Loader = (_a) => {
559
1911
  var _b = _a, {
@@ -563,7 +1915,7 @@ var Loader = (_a) => {
563
1915
  "color",
564
1916
  "size"
565
1917
  ]);
566
- return /* @__PURE__ */ jsx4(
1918
+ return /* @__PURE__ */ jsx2(
567
1919
  "span",
568
1920
  __spreadValues({
569
1921
  className: getClassName2(),
@@ -578,7 +1930,7 @@ var Loader = (_a) => {
578
1930
  };
579
1931
 
580
1932
  // ../core/components/SidebarSection/index.tsx
581
- import { jsx as jsx5, jsxs } from "react/jsx-runtime";
1933
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
582
1934
  var getClassName3 = get_class_name_factory_default("SidebarSection", styles_module_default);
583
1935
  var SidebarSection = ({
584
1936
  children,
@@ -589,7 +1941,7 @@ var SidebarSection = ({
589
1941
  noPadding,
590
1942
  isLoading
591
1943
  }) => {
592
- const { setUi } = useAppContext();
1944
+ const setUi = useAppStore((s) => s.setUi);
593
1945
  const breadcrumbs = useBreadcrumbs(1);
594
1946
  return /* @__PURE__ */ jsxs(
595
1947
  "div",
@@ -597,9 +1949,9 @@ var SidebarSection = ({
597
1949
  className: getClassName3({ noBorderTop, noPadding }),
598
1950
  style: { background },
599
1951
  children: [
600
- /* @__PURE__ */ jsx5("div", { className: getClassName3("title"), children: /* @__PURE__ */ jsxs("div", { className: getClassName3("breadcrumbs"), children: [
1952
+ /* @__PURE__ */ jsx3("div", { className: getClassName3("title"), children: /* @__PURE__ */ jsxs("div", { className: getClassName3("breadcrumbs"), children: [
601
1953
  showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ jsxs("div", { className: getClassName3("breadcrumb"), children: [
602
- /* @__PURE__ */ jsx5(
1954
+ /* @__PURE__ */ jsx3(
603
1955
  "button",
604
1956
  {
605
1957
  type: "button",
@@ -608,12 +1960,12 @@ var SidebarSection = ({
608
1960
  children: breadcrumb.label
609
1961
  }
610
1962
  ),
611
- /* @__PURE__ */ jsx5(ChevronRight, { size: 16 })
1963
+ /* @__PURE__ */ jsx3(ChevronRight, { size: 16 })
612
1964
  ] }, i)) : null,
613
- /* @__PURE__ */ jsx5("div", { className: getClassName3("heading"), children: /* @__PURE__ */ jsx5(Heading, { rank: "2", size: "xs", children: title }) })
1965
+ /* @__PURE__ */ jsx3("div", { className: getClassName3("heading"), children: /* @__PURE__ */ jsx3(Heading, { rank: "2", size: "xs", children: title }) })
614
1966
  ] }) }),
615
- /* @__PURE__ */ jsx5("div", { className: getClassName3("content"), children }),
616
- isLoading && /* @__PURE__ */ jsx5("div", { className: getClassName3("loadingOverlay"), children: /* @__PURE__ */ jsx5(Loader, { size: 32 }) })
1967
+ /* @__PURE__ */ jsx3("div", { className: getClassName3("content"), children }),
1968
+ isLoading && /* @__PURE__ */ jsx3("div", { className: getClassName3("loadingOverlay"), children: /* @__PURE__ */ jsx3(Loader, { size: 32 }) })
617
1969
  ]
618
1970
  }
619
1971
  );
@@ -627,18 +1979,18 @@ init_react_import();
627
1979
  var styles_module_default4 = { "OutlineList": "_OutlineList_w4lzv_1", "OutlineListItem": "_OutlineListItem_w4lzv_25", "OutlineListItem--clickable": "_OutlineListItem--clickable_w4lzv_45" };
628
1980
 
629
1981
  // ../core/components/OutlineList/index.tsx
630
- import { jsx as jsx6 } from "react/jsx-runtime";
1982
+ import { jsx as jsx4 } from "react/jsx-runtime";
631
1983
  var getClassName4 = get_class_name_factory_default("OutlineList", styles_module_default4);
632
1984
  var getClassNameItem = get_class_name_factory_default("OutlineListItem", styles_module_default4);
633
1985
  var OutlineList = ({ children }) => {
634
- return /* @__PURE__ */ jsx6("ul", { className: getClassName4(), children });
1986
+ return /* @__PURE__ */ jsx4("ul", { className: getClassName4(), children });
635
1987
  };
636
- OutlineList.Clickable = ({ children }) => /* @__PURE__ */ jsx6("div", { className: getClassNameItem({ clickable: true }), children });
1988
+ OutlineList.Clickable = ({ children }) => /* @__PURE__ */ jsx4("div", { className: getClassNameItem({ clickable: true }), children });
637
1989
  OutlineList.Item = ({
638
1990
  children,
639
1991
  onClick
640
1992
  }) => {
641
- return /* @__PURE__ */ jsx6(
1993
+ return /* @__PURE__ */ jsx4(
642
1994
  "li",
643
1995
  {
644
1996
  className: getClassNameItem({ clickable: !!onClick }),
@@ -672,7 +2024,7 @@ var getFrame = () => {
672
2024
 
673
2025
  // src/HeadingAnalyzer.tsx
674
2026
  import ReactFromJSONModule from "react-from-json";
675
- import { Fragment as Fragment2, jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
2027
+ import { Fragment, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
676
2028
  var getClassName5 = get_class_name_factory_default("HeadingAnalyzer", HeadingAnalyzer_module_default);
677
2029
  var getClassNameItem2 = get_class_name_factory_default("HeadingAnalyzerItem", HeadingAnalyzer_module_default);
678
2030
  var ReactFromJSON = ReactFromJSONModule.default || ReactFromJSONModule;
@@ -680,6 +2032,9 @@ var getOutline = ({ frame } = {}) => {
680
2032
  const headings = (frame == null ? void 0 : frame.querySelectorAll("h1,h2,h3,h4,h5,h6")) || [];
681
2033
  const _outline = [];
682
2034
  headings.forEach((item, i) => {
2035
+ if (item.closest("[data-dnd-dragging]")) {
2036
+ return;
2037
+ }
683
2038
  _outline.push({
684
2039
  rank: parseInt(item.tagName.split("H")[1]),
685
2040
  text: item.textContent,
@@ -722,10 +2077,11 @@ function buildHierarchy(frame) {
722
2077
  }
723
2078
  return root.children;
724
2079
  }
2080
+ var usePuck = createUsePuck();
725
2081
  var HeadingAnalyzer = () => {
726
- const { appState } = usePuck();
727
- const [hierarchy, setHierarchy] = useState5([]);
728
- useEffect4(() => {
2082
+ const data = usePuck((s) => s.appState.data);
2083
+ const [hierarchy, setHierarchy] = useState([]);
2084
+ useEffect6(() => {
729
2085
  const frame = getFrame();
730
2086
  const entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
731
2087
  if (!entry) return;
@@ -737,7 +2093,7 @@ var HeadingAnalyzer = () => {
737
2093
  return () => {
738
2094
  observer.disconnect();
739
2095
  };
740
- }, [appState.data]);
2096
+ }, [data]);
741
2097
  return /* @__PURE__ */ jsxs2("div", { className: getClassName5(), children: [
742
2098
  /* @__PURE__ */ jsxs2(
743
2099
  "small",
@@ -751,19 +2107,19 @@ var HeadingAnalyzer = () => {
751
2107
  children: [
752
2108
  "Heading analyzer styles not loaded. Please review the",
753
2109
  " ",
754
- /* @__PURE__ */ jsx7("a", { href: "https://github.com/measuredco/puck/blob/main/packages/plugin-heading-analyzer/README.md", children: "README" }),
2110
+ /* @__PURE__ */ jsx5("a", { href: "https://github.com/measuredco/puck/blob/main/packages/plugin-heading-analyzer/README.md", children: "README" }),
755
2111
  "."
756
2112
  ]
757
2113
  }
758
2114
  ),
759
- hierarchy.length === 0 && /* @__PURE__ */ jsx7("div", { children: "No headings." }),
760
- /* @__PURE__ */ jsx7(OutlineList, { children: /* @__PURE__ */ jsx7(
2115
+ hierarchy.length === 0 && /* @__PURE__ */ jsx5("div", { children: "No headings." }),
2116
+ /* @__PURE__ */ jsx5(OutlineList, { children: /* @__PURE__ */ jsx5(
761
2117
  ReactFromJSON,
762
2118
  {
763
2119
  mapping: {
764
- Root: (props) => /* @__PURE__ */ jsx7(Fragment2, { children: props.children }),
2120
+ Root: (props) => /* @__PURE__ */ jsx5(Fragment, { children: props.children }),
765
2121
  OutlineListItem: (props) => /* @__PURE__ */ jsxs2(OutlineList.Item, { children: [
766
- /* @__PURE__ */ jsx7(OutlineList.Clickable, { children: /* @__PURE__ */ jsx7(
2122
+ /* @__PURE__ */ jsx5(OutlineList.Clickable, { children: /* @__PURE__ */ jsx5(
767
2123
  "small",
768
2124
  {
769
2125
  className: getClassNameItem2({ missing: props.missing }),
@@ -781,13 +2137,13 @@ var HeadingAnalyzer = () => {
781
2137
  }, 2e3);
782
2138
  }
783
2139
  },
784
- children: props.missing ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
2140
+ children: props.missing ? /* @__PURE__ */ jsxs2(Fragment, { children: [
785
2141
  /* @__PURE__ */ jsxs2("b", { children: [
786
2142
  "H",
787
2143
  props.rank
788
2144
  ] }),
789
2145
  ": Missing"
790
- ] }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
2146
+ ] }) : /* @__PURE__ */ jsxs2(Fragment, { children: [
791
2147
  /* @__PURE__ */ jsxs2("b", { children: [
792
2148
  "H",
793
2149
  props.rank
@@ -797,7 +2153,7 @@ var HeadingAnalyzer = () => {
797
2153
  ] })
798
2154
  }
799
2155
  ) }),
800
- /* @__PURE__ */ jsx7(OutlineList, { children: props.children })
2156
+ /* @__PURE__ */ jsx5(OutlineList, { children: props.children })
801
2157
  ] })
802
2158
  },
803
2159
  entry: {
@@ -819,9 +2175,9 @@ var HeadingAnalyzer = () => {
819
2175
  };
820
2176
  var headingAnalyzer = {
821
2177
  overrides: {
822
- fields: ({ children, itemSelector }) => /* @__PURE__ */ jsxs2(Fragment2, { children: [
2178
+ fields: ({ children, itemSelector }) => /* @__PURE__ */ jsxs2(Fragment, { children: [
823
2179
  children,
824
- /* @__PURE__ */ jsx7("div", { style: { display: itemSelector ? "none" : "block" }, children: /* @__PURE__ */ jsx7(SidebarSection, { title: "Heading Outline", children: /* @__PURE__ */ jsx7(HeadingAnalyzer, {}) }) })
2180
+ /* @__PURE__ */ jsx5("div", { style: { display: itemSelector ? "none" : "block" }, children: /* @__PURE__ */ jsx5(SidebarSection, { title: "Heading Outline", children: /* @__PURE__ */ jsx5(HeadingAnalyzer, {}) }) })
825
2181
  ] })
826
2182
  }
827
2183
  };
@@ -838,6 +2194,50 @@ classnames/index.js:
838
2194
  http://jedwatson.github.io/classnames
839
2195
  *)
840
2196
 
2197
+ use-sync-external-store/cjs/use-sync-external-store-shim.production.js:
2198
+ (**
2199
+ * @license React
2200
+ * use-sync-external-store-shim.production.js
2201
+ *
2202
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
2203
+ *
2204
+ * This source code is licensed under the MIT license found in the
2205
+ * LICENSE file in the root directory of this source tree.
2206
+ *)
2207
+
2208
+ use-sync-external-store/cjs/use-sync-external-store-shim.development.js:
2209
+ (**
2210
+ * @license React
2211
+ * use-sync-external-store-shim.development.js
2212
+ *
2213
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
2214
+ *
2215
+ * This source code is licensed under the MIT license found in the
2216
+ * LICENSE file in the root directory of this source tree.
2217
+ *)
2218
+
2219
+ use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js:
2220
+ (**
2221
+ * @license React
2222
+ * use-sync-external-store-shim/with-selector.production.js
2223
+ *
2224
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
2225
+ *
2226
+ * This source code is licensed under the MIT license found in the
2227
+ * LICENSE file in the root directory of this source tree.
2228
+ *)
2229
+
2230
+ use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js:
2231
+ (**
2232
+ * @license React
2233
+ * use-sync-external-store-shim/with-selector.development.js
2234
+ *
2235
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
2236
+ *
2237
+ * This source code is licensed under the MIT license found in the
2238
+ * LICENSE file in the root directory of this source tree.
2239
+ *)
2240
+
841
2241
  lucide-react/dist/esm/shared/src/utils.js:
842
2242
  (**
843
2243
  * @license lucide-react v0.468.0 - ISC