@puckeditor/plugin-heading-analyzer 0.23.0-canary.fb9392de → 0.24.0-canary.03e660bb

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
@@ -55,26 +55,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
55
55
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
56
56
  mod
57
57
  ));
58
- var __async = (__this, __arguments, generator) => {
59
- return new Promise((resolve, reject) => {
60
- var fulfilled = (value) => {
61
- try {
62
- step(generator.next(value));
63
- } catch (e) {
64
- reject(e);
65
- }
66
- };
67
- var rejected = (value) => {
68
- try {
69
- step(generator.throw(value));
70
- } catch (e) {
71
- reject(e);
72
- }
73
- };
74
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
75
- step((generator = generator.apply(__this, __arguments)).next());
76
- });
77
- };
78
58
 
79
59
  // ../tsup-config/react-import.js
80
60
  import React from "react";
@@ -84,14 +64,14 @@ var init_react_import = __esm({
84
64
  }
85
65
  });
86
66
 
87
- // ../../node_modules/classnames/index.js
67
+ // ../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
88
68
  var require_classnames = __commonJS({
89
- "../../node_modules/classnames/index.js"(exports, module) {
69
+ "../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports, module) {
90
70
  "use strict";
91
71
  init_react_import();
92
72
  (function() {
93
73
  "use strict";
94
- var hasOwn2 = {}.hasOwnProperty;
74
+ var hasOwn = {}.hasOwnProperty;
95
75
  function classNames() {
96
76
  var classes = "";
97
77
  for (var i = 0; i < arguments.length; i++) {
@@ -117,7 +97,7 @@ var require_classnames = __commonJS({
117
97
  }
118
98
  var classes = "";
119
99
  for (var key in arg) {
120
- if (hasOwn2.call(arg, key) && arg[key]) {
100
+ if (hasOwn.call(arg, key) && arg[key]) {
121
101
  classes = appendClass(classes, key);
122
102
  }
123
103
  }
@@ -146,21 +126,21 @@ var require_classnames = __commonJS({
146
126
  }
147
127
  });
148
128
 
149
- // ../../node_modules/flat/index.js
129
+ // ../../node_modules/.pnpm/flat@5.0.2/node_modules/flat/index.js
150
130
  var require_flat = __commonJS({
151
- "../../node_modules/flat/index.js"(exports, module) {
131
+ "../../node_modules/.pnpm/flat@5.0.2/node_modules/flat/index.js"(exports, module) {
152
132
  "use strict";
153
133
  init_react_import();
154
- module.exports = flatten3;
155
- flatten3.flatten = flatten3;
156
- flatten3.unflatten = unflatten2;
134
+ module.exports = flatten2;
135
+ flatten2.flatten = flatten2;
136
+ flatten2.unflatten = unflatten2;
157
137
  function isBuffer(obj) {
158
138
  return obj && obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
159
139
  }
160
140
  function keyIdentity(key) {
161
141
  return key;
162
142
  }
163
- function flatten3(target, opts) {
143
+ function flatten2(target, opts) {
164
144
  opts = opts || {};
165
145
  const delimiter = opts.delimiter || ".";
166
146
  const maxDepth = opts.maxDepth;
@@ -206,11 +186,11 @@ var require_flat = __commonJS({
206
186
  }
207
187
  function isEmpty(val) {
208
188
  const type = Object.prototype.toString.call(val);
209
- const isArray2 = type === "[object Array]";
189
+ const isArray = type === "[object Array]";
210
190
  const isObject = type === "[object Object]";
211
191
  if (!val) {
212
192
  return true;
213
- } else if (isArray2) {
193
+ } else if (isArray) {
214
194
  return !val.length;
215
195
  } else if (isObject) {
216
196
  return !Object.keys(val).length;
@@ -226,7 +206,7 @@ var require_flat = __commonJS({
226
206
  return addKeys(
227
207
  key,
228
208
  result2,
229
- flatten3(target[key], opts)
209
+ flatten2(target[key], opts)
230
210
  );
231
211
  }
232
212
  }, {});
@@ -352,25 +332,25 @@ var getFrame = () => {
352
332
  return (frameEl == null ? void 0 : frameEl.ownerDocument) || document;
353
333
  };
354
334
 
355
- // ../../node_modules/lucide-react/dist/esm/lucide-react.js
335
+ // ../../node_modules/.pnpm/lucide-react@0.468.0_react@19.2.6/node_modules/lucide-react/dist/esm/lucide-react.js
356
336
  init_react_import();
357
337
 
358
- // ../../node_modules/lucide-react/dist/esm/createLucideIcon.js
338
+ // ../../node_modules/.pnpm/lucide-react@0.468.0_react@19.2.6/node_modules/lucide-react/dist/esm/createLucideIcon.js
359
339
  init_react_import();
360
340
  import { forwardRef as forwardRef2, createElement as createElement2 } from "react";
361
341
 
362
- // ../../node_modules/lucide-react/dist/esm/shared/src/utils.js
342
+ // ../../node_modules/.pnpm/lucide-react@0.468.0_react@19.2.6/node_modules/lucide-react/dist/esm/shared/src/utils.js
363
343
  init_react_import();
364
344
  var toKebabCase = (string) => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
365
345
  var mergeClasses = (...classes) => classes.filter((className, index, array) => {
366
346
  return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
367
347
  }).join(" ").trim();
368
348
 
369
- // ../../node_modules/lucide-react/dist/esm/Icon.js
349
+ // ../../node_modules/.pnpm/lucide-react@0.468.0_react@19.2.6/node_modules/lucide-react/dist/esm/Icon.js
370
350
  init_react_import();
371
351
  import { forwardRef, createElement } from "react";
372
352
 
373
- // ../../node_modules/lucide-react/dist/esm/defaultAttributes.js
353
+ // ../../node_modules/.pnpm/lucide-react@0.468.0_react@19.2.6/node_modules/lucide-react/dist/esm/defaultAttributes.js
374
354
  init_react_import();
375
355
  var defaultAttributes = {
376
356
  xmlns: "http://www.w3.org/2000/svg",
@@ -384,7 +364,7 @@ var defaultAttributes = {
384
364
  strokeLinejoin: "round"
385
365
  };
386
366
 
387
- // ../../node_modules/lucide-react/dist/esm/Icon.js
367
+ // ../../node_modules/.pnpm/lucide-react@0.468.0_react@19.2.6/node_modules/lucide-react/dist/esm/Icon.js
388
368
  var Icon = forwardRef(
389
369
  (_a, ref) => {
390
370
  var _b = _a, {
@@ -423,7 +403,7 @@ var Icon = forwardRef(
423
403
  }
424
404
  );
425
405
 
426
- // ../../node_modules/lucide-react/dist/esm/createLucideIcon.js
406
+ // ../../node_modules/.pnpm/lucide-react@0.468.0_react@19.2.6/node_modules/lucide-react/dist/esm/createLucideIcon.js
427
407
  var createLucideIcon = (iconName, iconNode) => {
428
408
  const Component = forwardRef2(
429
409
  (_a, ref) => {
@@ -439,7 +419,7 @@ var createLucideIcon = (iconName, iconNode) => {
439
419
  return Component;
440
420
  };
441
421
 
442
- // ../../node_modules/lucide-react/dist/esm/icons/heading-1.js
422
+ // ../../node_modules/.pnpm/lucide-react@0.468.0_react@19.2.6/node_modules/lucide-react/dist/esm/icons/heading-1.js
443
423
  init_react_import();
444
424
  var Heading1 = createLucideIcon("Heading1", [
445
425
  ["path", { d: "M4 12h8", key: "17cfdx" }],
@@ -487,188 +467,11 @@ var rootAreaId = "root";
487
467
  var rootZone = "default-zone";
488
468
  var rootDroppableId = `${rootAreaId}:${rootZone}`;
489
469
 
490
- // ../core/lib/get-zone-id.ts
491
- var getZoneId = (zoneCompound) => {
492
- if (!zoneCompound) {
493
- return [];
494
- }
495
- if (zoneCompound && zoneCompound.indexOf(":") > -1) {
496
- return zoneCompound.split(":");
497
- }
498
- return [rootDroppableId, zoneCompound];
499
- };
500
-
501
- // ../core/lib/data/for-related-zones.ts
502
- function forRelatedZones(item, data, cb, path = []) {
503
- Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
504
- const [parentId] = getZoneId(zoneCompound);
505
- if (parentId === item.props.id) {
506
- cb(path, zoneCompound, content);
507
- }
508
- });
509
- }
510
-
511
470
  // ../core/lib/data/map-fields.ts
512
471
  init_react_import();
513
472
 
514
473
  // ../core/lib/data/default-slots.ts
515
474
  init_react_import();
516
- var defaultSlots = (value, fields) => Object.keys(fields).reduce(
517
- (acc, fieldName) => fields[fieldName].type === "slot" ? __spreadValues({ [fieldName]: [] }, acc) : acc,
518
- value
519
- );
520
-
521
- // ../core/lib/data/map-fields.ts
522
- var isPromise = (v) => !!v && typeof v.then === "function";
523
- var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
524
- var containsPromise = (arr) => arr.some(isPromise);
525
- var walkField = ({
526
- value,
527
- fields,
528
- mappers,
529
- propKey = "",
530
- propPath = "",
531
- id = "",
532
- config,
533
- recurseSlots = false
534
- }) => {
535
- var _a, _b, _c, _d;
536
- const fieldType = (_a = fields[propKey]) == null ? void 0 : _a.type;
537
- const map = mappers[fieldType];
538
- if (map && fieldType === "slot") {
539
- const content = value || [];
540
- const mappedContent = recurseSlots ? content.map((el) => {
541
- if (!config.components[el.type]) {
542
- throw new Error(`Could not find component config for ${el.type}`);
543
- }
544
- return mapFields(el, mappers, config, recurseSlots);
545
- }) : content;
546
- if (containsPromise(mappedContent)) {
547
- return Promise.all(mappedContent);
548
- }
549
- return map({
550
- value: mappedContent,
551
- parentId: id,
552
- propName: propPath,
553
- field: fields[propKey],
554
- propPath
555
- });
556
- } else if (map && fields[propKey]) {
557
- return map({
558
- value,
559
- parentId: id,
560
- propName: propKey,
561
- field: fields[propKey],
562
- propPath
563
- });
564
- }
565
- if (value && typeof value === "object") {
566
- if (Array.isArray(value)) {
567
- const arrayFields = ((_b = fields[propKey]) == null ? void 0 : _b.type) === "array" ? fields[propKey].arrayFields : null;
568
- if (!arrayFields) return value;
569
- const newValue = value.map(
570
- (el, idx) => walkField({
571
- value: el,
572
- fields: arrayFields,
573
- mappers,
574
- propKey,
575
- propPath: `${propPath}[${idx}]`,
576
- id,
577
- config,
578
- recurseSlots
579
- })
580
- );
581
- if (containsPromise(newValue)) {
582
- return Promise.all(newValue);
583
- }
584
- return newValue;
585
- } else if ("$$typeof" in value) {
586
- return value;
587
- } else {
588
- const objectFields = ((_c = fields[propKey]) == null ? void 0 : _c.type) === "object" ? fields[propKey].objectFields : fields;
589
- return walkObject({
590
- value,
591
- fields: objectFields,
592
- mappers,
593
- id,
594
- getPropPath: (k) => `${propPath}.${k}`,
595
- config,
596
- recurseSlots,
597
- // Only default missing fields when objectFields describe this value
598
- ownedFields: ((_d = fields[propKey]) == null ? void 0 : _d.type) === "object"
599
- });
600
- }
601
- }
602
- return value;
603
- };
604
- var walkObject = ({
605
- value,
606
- fields,
607
- mappers,
608
- id,
609
- getPropPath,
610
- config,
611
- recurseSlots,
612
- ownedFields
613
- }) => {
614
- const keys2 = Object.keys(value);
615
- if (ownedFields) {
616
- for (const fieldName in fields) {
617
- const fieldType = fields[fieldName].type;
618
- if (fieldType !== "slot" && mappers[fieldType] && !(fieldName in value)) {
619
- keys2.push(fieldName);
620
- }
621
- }
622
- }
623
- const newProps = keys2.map((k) => {
624
- const opts = {
625
- value: value[k],
626
- fields,
627
- mappers,
628
- propKey: k,
629
- propPath: getPropPath(k),
630
- id,
631
- config,
632
- recurseSlots
633
- };
634
- const newValue = walkField(opts);
635
- if (isPromise(newValue)) {
636
- return newValue.then((resolvedValue) => ({
637
- [k]: resolvedValue
638
- }));
639
- }
640
- return {
641
- [k]: newValue
642
- };
643
- }, {});
644
- if (containsPromise(newProps)) {
645
- return Promise.all(newProps).then(flatten);
646
- }
647
- return flatten(newProps);
648
- };
649
- function mapFields(item, mappers, config, recurseSlots = false, shouldDefaultSlots = true) {
650
- var _a, _b, _c, _d, _e;
651
- const itemType = "type" in item ? item.type : "root";
652
- const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
653
- const newProps = walkObject({
654
- value: shouldDefaultSlots ? defaultSlots((_b = item.props) != null ? _b : {}, (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {}) : item.props,
655
- fields: (_d = componentConfig == null ? void 0 : componentConfig.fields) != null ? _d : {},
656
- mappers,
657
- id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
658
- getPropPath: (k) => k,
659
- config,
660
- recurseSlots,
661
- ownedFields: true
662
- });
663
- if (isPromise(newProps)) {
664
- return newProps.then((resolvedProps) => __spreadProps(__spreadValues({}, item), {
665
- props: resolvedProps
666
- }));
667
- }
668
- return __spreadProps(__spreadValues({}, item), {
669
- props: newProps
670
- });
671
- }
672
475
 
673
476
  // ../core/lib/data/flatten-node.ts
674
477
  init_react_import();
@@ -676,194 +479,18 @@ var import_flat = __toESM(require_flat());
676
479
 
677
480
  // ../core/lib/data/strip-slots.ts
678
481
  init_react_import();
679
- var stripSlots = (data, config) => {
680
- return mapFields(data, { slot: () => null }, config);
681
- };
682
482
 
683
483
  // ../core/lib/data/flatten-node.ts
684
- var { flatten: flatten2, unflatten } = import_flat.default;
685
- var isPureObject = (val) => val != null && Object.prototype.toString.call(val) === "[object Object]";
686
- var emptyArrayStr = "__puck_[]";
687
- var emptyObjectStr = "__puck_{}";
688
- function encodeEmptyObjects(props = {}) {
689
- const result = {};
690
- for (const key in props) {
691
- if (!Object.prototype.hasOwnProperty.call(props, key)) continue;
692
- const val = props[key];
693
- if (Array.isArray(val) && val.length === 0) {
694
- result[key] = emptyArrayStr;
695
- } else if (isPureObject(val) && Object.keys(val).length === 0) {
696
- result[key] = emptyObjectStr;
697
- } else {
698
- result[key] = val;
699
- }
700
- }
701
- return result;
702
- }
703
- var flattenNode = (node, config) => {
704
- return __spreadProps(__spreadValues({}, node), {
705
- props: encodeEmptyObjects(flatten2(stripSlots(node, config).props))
706
- });
707
- };
484
+ var { flatten, unflatten } = import_flat.default;
708
485
 
709
486
  // ../core/lib/data/to-component.ts
710
487
  init_react_import();
711
- var toComponent = (item) => {
712
- return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
713
- props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
714
- type: "root"
715
- });
716
- };
717
-
718
- // ../core/lib/data/walk-app-state.ts
719
- function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
720
- var _a;
721
- let newZones = {};
722
- const newZoneIndex = {};
723
- const newNodeIndex = {};
724
- const processContent = (path, zoneCompound, content, zoneType, newId) => {
725
- var _a2;
726
- const [parentId] = zoneCompound.split(":");
727
- const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
728
- const [_2, zone] = zoneCompound.split(":");
729
- const newZoneCompound = `${newId || parentId}:${zone}`;
730
- const newContent2 = mappedContent.map(
731
- (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
732
- );
733
- newZoneIndex[newZoneCompound] = {
734
- contentIds: newContent2.map((item) => item.props.id),
735
- type: zoneType
736
- };
737
- return [newZoneCompound, newContent2];
738
- };
739
- const processRelatedZones = (item, newId, initialPath) => {
740
- forRelatedZones(
741
- item,
742
- state.data,
743
- (relatedPath, relatedZoneCompound, relatedContent) => {
744
- const [zoneCompound, newContent2] = processContent(
745
- relatedPath,
746
- relatedZoneCompound,
747
- relatedContent,
748
- "dropzone",
749
- newId
750
- );
751
- newZones[zoneCompound] = newContent2;
752
- },
753
- initialPath
754
- );
755
- };
756
- const processItem = (item, path, index) => {
757
- const mappedItem = mapNodeOrSkip(item, path, index);
758
- if (!mappedItem) return item;
759
- const id = mappedItem.props.id;
760
- const newProps = __spreadProps(__spreadValues({}, mapFields(
761
- mappedItem,
762
- {
763
- slot: ({ value, parentId: parentId2, propPath }) => {
764
- const content = value;
765
- const zoneCompound = `${parentId2}:${propPath}`;
766
- const [_2, newContent2] = processContent(
767
- path,
768
- zoneCompound,
769
- content,
770
- "slot",
771
- parentId2
772
- );
773
- return newContent2;
774
- }
775
- },
776
- config
777
- ).props), {
778
- id
779
- });
780
- processRelatedZones(item, id, path);
781
- const newItem = __spreadProps(__spreadValues({}, mappedItem), { props: newProps });
782
- const thisZoneCompound = path[path.length - 1];
783
- const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
784
- newNodeIndex[id] = {
785
- data: newItem,
786
- flatData: flattenNode(newItem, config),
787
- path,
788
- parentId,
789
- zone
790
- };
791
- const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
792
- if (newProps.id === "root") {
793
- delete finalData["type"];
794
- delete finalData.props["id"];
795
- }
796
- return finalData;
797
- };
798
- const zones = state.data.zones || {};
799
- const [_, newContent] = processContent(
800
- [],
801
- rootDroppableId,
802
- state.data.content,
803
- "root"
804
- );
805
- const processedContent = newContent;
806
- const zonesAlreadyProcessed = Object.keys(newZones);
807
- Object.keys(zones || {}).forEach((zoneCompound) => {
808
- const [parentId] = zoneCompound.split(":");
809
- if (zonesAlreadyProcessed.includes(zoneCompound)) {
810
- return;
811
- }
812
- const [_2, newContent2] = processContent(
813
- [rootDroppableId],
814
- zoneCompound,
815
- zones[zoneCompound],
816
- "dropzone",
817
- parentId
818
- );
819
- newZones[zoneCompound] = newContent2;
820
- }, newZones);
821
- let rootAsComponent = toComponent({
822
- props: __spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root)
823
- });
824
- if (state.data.root.readOnly) {
825
- rootAsComponent.readOnly = state.data.root.readOnly;
826
- }
827
- const processedRoot = processItem(rootAsComponent, [], -1);
828
- const root = __spreadValues(__spreadValues({}, state.data.root), processedRoot);
829
- return __spreadProps(__spreadValues({}, state), {
830
- data: {
831
- root,
832
- content: processedContent,
833
- zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
834
- },
835
- indexes: {
836
- nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
837
- zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
838
- }
839
- });
840
- }
841
-
842
- // ../core/reducer/actions/set.ts
843
- var setAction = (state, action, appStore) => {
844
- if (typeof action.state === "object") {
845
- const newState = __spreadValues(__spreadValues({}, state), action.state);
846
- if (action.state.indexes) {
847
- return newState;
848
- }
849
- console.warn(
850
- "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
851
- );
852
- return walkAppState(newState, appStore.config);
853
- }
854
- return __spreadValues(__spreadValues({}, state), action.state(state));
855
- };
856
488
 
857
489
  // ../core/reducer/actions/insert.ts
858
490
  init_react_import();
859
491
 
860
492
  // ../core/lib/data/insert.ts
861
493
  init_react_import();
862
- var insert = (list, index, item) => {
863
- const result = Array.from(list || []);
864
- result.splice(index, 0, item);
865
- return result;
866
- };
867
494
 
868
495
  // ../core/lib/generate-id.ts
869
496
  init_react_import();
@@ -874,9 +501,6 @@ init_react_import();
874
501
  // ../core/lib/uuid/rng.ts
875
502
  init_react_import();
876
503
  var rnds8 = new Uint8Array(16);
877
- function rng() {
878
- return crypto.getRandomValues(rnds8);
879
- }
880
504
 
881
505
  // ../core/lib/uuid/stringify.ts
882
506
  init_react_import();
@@ -884,291 +508,27 @@ var byteToHex = [];
884
508
  for (let i = 0; i < 256; ++i) {
885
509
  byteToHex.push((i + 256).toString(16).slice(1));
886
510
  }
887
- function unsafeStringify(arr, offset = 0) {
888
- 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]]).toLowerCase();
889
- }
890
-
891
- // ../core/lib/uuid/index.ts
892
- function v4(options, buf, offset) {
893
- if (!buf && !options && crypto.randomUUID) {
894
- return crypto.randomUUID();
895
- }
896
- return _v4(options, buf, offset);
897
- }
898
- function _v4(options, buf, offset) {
899
- var _a, _b, _c;
900
- options = options || {};
901
- const rnds = (_c = (_b = options.random) != null ? _b : (_a = options.rng) == null ? void 0 : _a.call(options)) != null ? _c : rng();
902
- if (rnds.length < 16) {
903
- throw new Error("Random bytes length must be >= 16");
904
- }
905
- rnds[6] = rnds[6] & 15 | 64;
906
- rnds[8] = rnds[8] & 63 | 128;
907
- if (buf) {
908
- offset = offset || 0;
909
- if (offset < 0 || offset + 16 > buf.length) {
910
- throw new RangeError(
911
- `UUID byte range ${offset}:${offset + 15} is out of buffer bounds`
912
- );
913
- }
914
- for (let i = 0; i < 16; ++i) {
915
- buf[offset + i] = rnds[i];
916
- }
917
- return buf;
918
- }
919
- return unsafeStringify(rnds);
920
- }
921
- var uuid_default = v4;
922
-
923
- // ../core/lib/generate-id.ts
924
- var generateId = (type) => type ? `${type}-${uuid_default()}` : uuid_default();
925
511
 
926
512
  // ../core/lib/data/get-ids-for-parent.ts
927
513
  init_react_import();
928
- var getIdsForParent = (zoneCompound, state) => {
929
- const [parentId] = zoneCompound.split(":");
930
- const node = state.indexes.nodes[parentId];
931
- return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
932
- };
933
514
 
934
515
  // ../core/lib/data/populate-ids.ts
935
516
  init_react_import();
936
517
 
937
518
  // ../core/lib/data/walk-tree.ts
938
519
  init_react_import();
939
- function walkTree(data, config, callbackFn) {
940
- var _a, _b;
941
- const walkItem = (item) => {
942
- return mapFields(
943
- item,
944
- {
945
- slot: ({ value, parentId, propName }) => {
946
- var _a2;
947
- const content = value;
948
- return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
949
- }
950
- },
951
- config,
952
- true
953
- );
954
- };
955
- if ("props" in data) {
956
- return walkItem(data);
957
- }
958
- const _data = data;
959
- const zones = (_a = _data.zones) != null ? _a : {};
960
- const mappedContent = _data.content.map(walkItem);
961
- return {
962
- root: walkItem(_data.root),
963
- content: (_b = callbackFn(mappedContent, {
964
- parentId: "root",
965
- propName: "default-zone"
966
- })) != null ? _b : mappedContent,
967
- zones: Object.keys(zones).reduce(
968
- (acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
969
- [zoneCompound]: zones[zoneCompound].map(walkItem)
970
- }),
971
- {}
972
- )
973
- };
974
- }
975
-
976
- // ../core/lib/data/populate-ids.ts
977
- var populateIds = (data, config, override = false) => {
978
- const id = generateId(data.type);
979
- return walkTree(
980
- __spreadProps(__spreadValues({}, data), {
981
- props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({}, data.props)
982
- }),
983
- config,
984
- (contents) => contents.map((item) => {
985
- const id2 = generateId(item.type);
986
- return __spreadProps(__spreadValues({}, item), {
987
- props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
988
- });
989
- })
990
- );
991
- };
992
-
993
- // ../core/reducer/actions/insert.ts
994
- function insertAction(state, action, appStore) {
995
- const id = action.id || generateId(action.componentType);
996
- const emptyComponentData = populateIds(
997
- {
998
- type: action.componentType,
999
- props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
1000
- id
1001
- })
1002
- },
1003
- appStore.config
1004
- );
1005
- const [parentId] = action.destinationZone.split(":");
1006
- const idsInPath = getIdsForParent(action.destinationZone, state);
1007
- return walkAppState(
1008
- state,
1009
- appStore.config,
1010
- (content, zoneCompound) => {
1011
- if (zoneCompound === action.destinationZone) {
1012
- return insert(
1013
- content || [],
1014
- action.destinationIndex,
1015
- emptyComponentData
1016
- );
1017
- }
1018
- return content;
1019
- },
1020
- (childItem, path) => {
1021
- if (childItem.props.id === id || childItem.props.id === parentId) {
1022
- return childItem;
1023
- } else if (idsInPath.includes(childItem.props.id)) {
1024
- return childItem;
1025
- } else if (path.includes(action.destinationZone)) {
1026
- return childItem;
1027
- }
1028
- return null;
1029
- }
1030
- );
1031
- }
1032
520
 
1033
521
  // ../core/reducer/actions/replace.ts
1034
522
  init_react_import();
1035
- var replaceAction = (state, action, appStore) => {
1036
- const [parentId] = action.destinationZone.split(":");
1037
- const idsInPath = getIdsForParent(action.destinationZone, state);
1038
- const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
1039
- const idChanged = originalId !== action.data.props.id;
1040
- if (idChanged) {
1041
- throw new Error(
1042
- `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
1043
- );
1044
- }
1045
- const newSlotIds = [];
1046
- const data = walkTree(action.data, appStore.config, (contents, opts) => {
1047
- newSlotIds.push(`${opts.parentId}:${opts.propName}`);
1048
- return contents.map((item) => {
1049
- const id = generateId(item.type);
1050
- return __spreadProps(__spreadValues({}, item), {
1051
- props: __spreadValues({ id }, item.props)
1052
- });
1053
- });
1054
- });
1055
- const stateWithDeepSlotsRemoved = __spreadProps(__spreadValues({}, state), {
1056
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1057
- });
1058
- Object.keys(state.indexes.zones).forEach((zoneCompound) => {
1059
- const id = zoneCompound.split(":")[0];
1060
- if (id === originalId) {
1061
- if (!newSlotIds.includes(zoneCompound)) {
1062
- delete stateWithDeepSlotsRemoved.indexes.zones[zoneCompound];
1063
- }
1064
- }
1065
- });
1066
- return walkAppState(
1067
- stateWithDeepSlotsRemoved,
1068
- appStore.config,
1069
- (content, zoneCompound) => {
1070
- const newContent = [...content];
1071
- if (zoneCompound === action.destinationZone) {
1072
- newContent[action.destinationIndex] = data;
1073
- }
1074
- return newContent;
1075
- },
1076
- (childItem, path) => {
1077
- const pathIds = path.map((p) => p.split(":")[0]);
1078
- if (childItem.props.id === data.props.id) {
1079
- return data;
1080
- } else if (childItem.props.id === parentId) {
1081
- return childItem;
1082
- } else if (idsInPath.indexOf(childItem.props.id) > -1) {
1083
- return childItem;
1084
- } else if (pathIds.indexOf(data.props.id) > -1) {
1085
- return childItem;
1086
- }
1087
- return null;
1088
- }
1089
- );
1090
- };
1091
523
 
1092
524
  // ../core/reducer/actions/replace-root.ts
1093
525
  init_react_import();
1094
- var replaceRootAction = (state, action, appStore) => {
1095
- return walkAppState(
1096
- state,
1097
- appStore.config,
1098
- (content) => content,
1099
- (childItem) => {
1100
- if (childItem.props.id === "root") {
1101
- return __spreadProps(__spreadValues({}, childItem), {
1102
- props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
1103
- readOnly: action.root.readOnly
1104
- });
1105
- }
1106
- return childItem;
1107
- }
1108
- );
1109
- };
1110
526
 
1111
527
  // ../core/reducer/actions/duplicate.ts
1112
528
  init_react_import();
1113
529
 
1114
530
  // ../core/lib/data/get-item.ts
1115
531
  init_react_import();
1116
- function getItem(selector, state) {
1117
- var _a, _b;
1118
- const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
1119
- return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
1120
- }
1121
-
1122
- // ../core/reducer/actions/duplicate.ts
1123
- function duplicateAction(state, action, appStore) {
1124
- const item = getItem(
1125
- { index: action.sourceIndex, zone: action.sourceZone },
1126
- state
1127
- );
1128
- const idsInPath = getIdsForParent(action.sourceZone, state);
1129
- const newItem = __spreadProps(__spreadValues({}, item), {
1130
- props: __spreadProps(__spreadValues({}, item.props), {
1131
- id: generateId(item.type)
1132
- })
1133
- });
1134
- const modified = walkAppState(
1135
- state,
1136
- appStore.config,
1137
- (content, zoneCompound) => {
1138
- if (zoneCompound === action.sourceZone) {
1139
- return insert(content, action.sourceIndex + 1, item);
1140
- }
1141
- return content;
1142
- },
1143
- (childItem, path, index) => {
1144
- const zoneCompound = path[path.length - 1];
1145
- const parents = path.map((p) => p.split(":")[0]);
1146
- if (parents.indexOf(newItem.props.id) > -1) {
1147
- return __spreadProps(__spreadValues({}, childItem), {
1148
- props: __spreadProps(__spreadValues({}, childItem.props), {
1149
- id: generateId(childItem.type)
1150
- })
1151
- });
1152
- }
1153
- if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
1154
- return newItem;
1155
- }
1156
- const [sourceZoneParent] = action.sourceZone.split(":");
1157
- if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
1158
- return childItem;
1159
- }
1160
- return null;
1161
- }
1162
- );
1163
- return __spreadProps(__spreadValues({}, modified), {
1164
- ui: __spreadProps(__spreadValues({}, modified.ui), {
1165
- itemSelector: {
1166
- index: action.sourceIndex + 1,
1167
- zone: action.sourceZone
1168
- }
1169
- })
1170
- });
1171
- }
1172
532
 
1173
533
  // ../core/reducer/actions/reorder.ts
1174
534
  init_react_import();
@@ -1178,279 +538,28 @@ init_react_import();
1178
538
 
1179
539
  // ../core/lib/data/remove.ts
1180
540
  init_react_import();
1181
- var remove = (list, index) => {
1182
- const result = Array.from(list);
1183
- result.splice(index, 1);
1184
- return result;
1185
- };
1186
-
1187
- // ../core/reducer/actions/move.ts
1188
- var moveAction = (state, action, appStore) => {
1189
- if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
1190
- return state;
1191
- }
1192
- const item = getItem(
1193
- { zone: action.sourceZone, index: action.sourceIndex },
1194
- state
1195
- );
1196
- if (!item) return state;
1197
- const idsInSourcePath = getIdsForParent(action.sourceZone, state);
1198
- const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
1199
- return walkAppState(
1200
- state,
1201
- appStore.config,
1202
- (content, zoneCompound) => {
1203
- if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
1204
- return insert(
1205
- remove(content, action.sourceIndex),
1206
- action.destinationIndex,
1207
- item
1208
- );
1209
- } else if (zoneCompound === action.sourceZone) {
1210
- return remove(content, action.sourceIndex);
1211
- } else if (zoneCompound === action.destinationZone) {
1212
- return insert(content, action.destinationIndex, item);
1213
- }
1214
- return content;
1215
- },
1216
- (childItem, path) => {
1217
- const [sourceZoneParent] = action.sourceZone.split(":");
1218
- const [destinationZoneParent] = action.destinationZone.split(":");
1219
- const childId = childItem.props.id;
1220
- if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
1221
- return childItem;
1222
- }
1223
- return null;
1224
- }
1225
- );
1226
- };
1227
-
1228
- // ../core/reducer/actions/reorder.ts
1229
- var reorderAction = (state, action, appStore) => {
1230
- return moveAction(
1231
- state,
1232
- {
1233
- type: "move",
1234
- sourceIndex: action.sourceIndex,
1235
- sourceZone: action.destinationZone,
1236
- destinationIndex: action.destinationIndex,
1237
- destinationZone: action.destinationZone
1238
- },
1239
- appStore
1240
- );
1241
- };
1242
541
 
1243
542
  // ../core/reducer/actions/remove.ts
1244
543
  init_react_import();
1245
- var removeAction = (state, action, appStore) => {
1246
- const item = getItem({ index: action.index, zone: action.zone }, state);
1247
- const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
1248
- (acc, [nodeId, nodeData]) => {
1249
- const pathIds = nodeData.path.map((p) => p.split(":")[0]);
1250
- if (pathIds.includes(item.props.id)) {
1251
- return [...acc, nodeId];
1252
- }
1253
- return acc;
1254
- },
1255
- [item.props.id]
1256
- );
1257
- const newState = walkAppState(
1258
- state,
1259
- appStore.config,
1260
- (content, zoneCompound) => {
1261
- if (zoneCompound === action.zone) {
1262
- return remove(content, action.index);
1263
- }
1264
- return content;
1265
- }
1266
- );
1267
- Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
1268
- const parentId = zoneCompound.split(":")[0];
1269
- if (nodesToDelete.includes(parentId) && newState.data.zones) {
1270
- delete newState.data.zones[zoneCompound];
1271
- }
1272
- });
1273
- Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
1274
- const parentId = zoneCompound.split(":")[0];
1275
- if (nodesToDelete.includes(parentId)) {
1276
- delete newState.indexes.zones[zoneCompound];
1277
- }
1278
- });
1279
- nodesToDelete.forEach((id) => {
1280
- delete newState.indexes.nodes[id];
1281
- });
1282
- return newState;
1283
- };
1284
544
 
1285
545
  // ../core/reducer/actions/register-zone.ts
1286
546
  init_react_import();
1287
547
 
1288
548
  // ../core/lib/data/setup-zone.ts
1289
549
  init_react_import();
1290
- var setupZone = (data, zoneKey) => {
1291
- if (zoneKey === rootDroppableId) {
1292
- return data;
1293
- }
1294
- const newData = __spreadProps(__spreadValues({}, data), {
1295
- zones: data.zones ? __spreadValues({}, data.zones) : {}
1296
- });
1297
- newData.zones[zoneKey] = newData.zones[zoneKey] || [];
1298
- return newData;
1299
- };
1300
-
1301
- // ../core/reducer/actions/register-zone.ts
1302
- var zoneCache = {};
1303
- function registerZoneAction(state, action) {
1304
- if (zoneCache[action.zone]) {
1305
- return __spreadProps(__spreadValues({}, state), {
1306
- data: __spreadProps(__spreadValues({}, state.data), {
1307
- zones: __spreadProps(__spreadValues({}, state.data.zones), {
1308
- [action.zone]: zoneCache[action.zone]
1309
- })
1310
- }),
1311
- indexes: __spreadProps(__spreadValues({}, state.indexes), {
1312
- zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
1313
- [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
1314
- contentIds: zoneCache[action.zone].map((item) => item.props.id),
1315
- type: "dropzone"
1316
- })
1317
- })
1318
- })
1319
- });
1320
- }
1321
- return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
1322
- }
1323
- function unregisterZoneAction(state, action) {
1324
- const _zones = __spreadValues({}, state.data.zones || {});
1325
- const zoneIndex = __spreadValues({}, state.indexes.zones || {});
1326
- if (_zones[action.zone]) {
1327
- zoneCache[action.zone] = _zones[action.zone];
1328
- delete _zones[action.zone];
1329
- }
1330
- delete zoneIndex[action.zone];
1331
- return __spreadProps(__spreadValues({}, state), {
1332
- data: __spreadProps(__spreadValues({}, state.data), {
1333
- zones: _zones
1334
- }),
1335
- indexes: __spreadProps(__spreadValues({}, state.indexes), {
1336
- zones: zoneIndex
1337
- })
1338
- });
1339
- }
1340
550
 
1341
551
  // ../core/reducer/actions/set-data.ts
1342
552
  init_react_import();
1343
- var setDataAction = (state, action, appStore) => {
1344
- if (typeof action.data === "object") {
1345
- console.warn(
1346
- "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
1347
- );
1348
- return walkAppState(
1349
- __spreadProps(__spreadValues({}, state), {
1350
- data: __spreadValues(__spreadValues({}, state.data), action.data)
1351
- }),
1352
- appStore.config
1353
- );
1354
- }
1355
- return walkAppState(
1356
- __spreadProps(__spreadValues({}, state), {
1357
- data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1358
- }),
1359
- appStore.config
1360
- );
1361
- };
1362
553
 
1363
554
  // ../core/reducer/actions/set-ui.ts
1364
555
  init_react_import();
1365
- var setUiAction = (state, action) => {
1366
- if (typeof action.ui === "object") {
1367
- return __spreadProps(__spreadValues({}, state), {
1368
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1369
- });
1370
- }
1371
- return __spreadProps(__spreadValues({}, state), {
1372
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1373
- });
1374
- };
1375
556
 
1376
557
  // ../core/lib/data/make-state-public.ts
1377
558
  init_react_import();
1378
- var makeStatePublic = (state) => {
1379
- const { data, ui } = state;
1380
- return { data, ui };
1381
- };
1382
559
 
1383
560
  // ../core/reducer/actions.tsx
1384
561
  init_react_import();
1385
562
 
1386
- // ../core/reducer/index.ts
1387
- function storeInterceptor(reducer, record, onAction) {
1388
- return (state, action) => {
1389
- const newAppState = reducer(state, action);
1390
- const isValidType = ![
1391
- "registerZone",
1392
- "unregisterZone",
1393
- "setData",
1394
- "setUi",
1395
- "set"
1396
- ].includes(action.type);
1397
- if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1398
- if (record) record(newAppState);
1399
- }
1400
- onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
1401
- return newAppState;
1402
- };
1403
- }
1404
- function createReducer({
1405
- record,
1406
- onAction,
1407
- appStore
1408
- }) {
1409
- return storeInterceptor(
1410
- (state, action) => {
1411
- if (action.type === "set") {
1412
- return setAction(state, action, appStore);
1413
- }
1414
- if (action.type === "insert") {
1415
- return insertAction(state, action, appStore);
1416
- }
1417
- if (action.type === "replace") {
1418
- return replaceAction(state, action, appStore);
1419
- }
1420
- if (action.type === "replaceRoot") {
1421
- return replaceRootAction(state, action, appStore);
1422
- }
1423
- if (action.type === "duplicate") {
1424
- return duplicateAction(state, action, appStore);
1425
- }
1426
- if (action.type === "reorder") {
1427
- return reorderAction(state, action, appStore);
1428
- }
1429
- if (action.type === "move") {
1430
- return moveAction(state, action, appStore);
1431
- }
1432
- if (action.type === "remove") {
1433
- return removeAction(state, action, appStore);
1434
- }
1435
- if (action.type === "registerZone") {
1436
- return registerZoneAction(state, action);
1437
- }
1438
- if (action.type === "unregisterZone") {
1439
- return unregisterZoneAction(state, action);
1440
- }
1441
- if (action.type === "setData") {
1442
- return setDataAction(state, action, appStore);
1443
- }
1444
- if (action.type === "setUi") {
1445
- return setUiAction(state, action);
1446
- }
1447
- return state;
1448
- },
1449
- record,
1450
- onAction
1451
- );
1452
- }
1453
-
1454
563
  // ../core/components/ViewportControls/default-viewports.ts
1455
564
  init_react_import();
1456
565
  var defaultViewports = [
@@ -1460,7 +569,7 @@ var defaultViewports = [
1460
569
  { width: "100%", height: "auto", icon: "FullWidth", label: "Full-width" }
1461
570
  ];
1462
571
 
1463
- // ../../node_modules/zustand/esm/vanilla.mjs
572
+ // ../../node_modules/.pnpm/zustand@5.0.13_@types+react@19.2.14_react@19.2.6_use-sync-external-store@1.6.0_react@19.2.6_/node_modules/zustand/esm/vanilla.mjs
1464
573
  init_react_import();
1465
574
  var createStoreImpl = (createState) => {
1466
575
  let state;
@@ -1485,7 +594,7 @@ var createStoreImpl = (createState) => {
1485
594
  };
1486
595
  var createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
1487
596
 
1488
- // ../../node_modules/zustand/esm/react.mjs
597
+ // ../../node_modules/.pnpm/zustand@5.0.13_@types+react@19.2.14_react@19.2.6_use-sync-external-store@1.6.0_react@19.2.6_/node_modules/zustand/esm/react.mjs
1489
598
  init_react_import();
1490
599
  import React2 from "react";
1491
600
  var identity = (arg) => arg;
@@ -1506,7 +615,7 @@ var createImpl = (createState) => {
1506
615
  };
1507
616
  var create = ((createState) => createState ? createImpl(createState) : createImpl);
1508
617
 
1509
- // ../../node_modules/zustand/esm/middleware.mjs
618
+ // ../../node_modules/.pnpm/zustand@5.0.13_@types+react@19.2.14_react@19.2.6_use-sync-external-store@1.6.0_react@19.2.6_/node_modules/zustand/esm/middleware.mjs
1510
619
  init_react_import();
1511
620
  var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
1512
621
  const origSubscribe = api.subscribe;
@@ -1553,136 +662,8 @@ var useHotkeyStore = create()(
1553
662
  }))
1554
663
  );
1555
664
 
1556
- // ../core/store/slices/history.ts
1557
- var EMPTY_HISTORY_INDEX = 0;
1558
- function debounce(func, timeout = 300) {
1559
- let timer;
1560
- return (...args) => {
1561
- clearTimeout(timer);
1562
- timer = setTimeout(() => {
1563
- func(...args);
1564
- }, timeout);
1565
- };
1566
- }
1567
- var tidyState = (state) => {
1568
- return __spreadProps(__spreadValues({}, state), {
1569
- ui: __spreadProps(__spreadValues({}, state.ui), {
1570
- field: __spreadProps(__spreadValues({}, state.ui.field), {
1571
- focus: null
1572
- })
1573
- })
1574
- });
1575
- };
1576
- var createHistorySlice = (set, get) => {
1577
- const record = debounce((state) => {
1578
- const { histories, index } = get().history;
1579
- const history = {
1580
- state,
1581
- id: generateId("history")
1582
- };
1583
- const newHistories = [...histories.slice(0, index + 1), history];
1584
- set({
1585
- history: __spreadProps(__spreadValues({}, get().history), {
1586
- histories: newHistories,
1587
- index: newHistories.length - 1
1588
- })
1589
- });
1590
- }, 250);
1591
- return {
1592
- initialAppState: {},
1593
- index: EMPTY_HISTORY_INDEX,
1594
- histories: [],
1595
- hasPast: () => get().history.index > EMPTY_HISTORY_INDEX,
1596
- hasFuture: () => get().history.index < get().history.histories.length - 1,
1597
- prevHistory: () => {
1598
- const { history } = get();
1599
- return history.hasPast() ? history.histories[history.index - 1] : null;
1600
- },
1601
- nextHistory: () => {
1602
- const s = get().history;
1603
- return s.hasFuture() ? s.histories[s.index + 1] : null;
1604
- },
1605
- currentHistory: () => get().history.histories[get().history.index],
1606
- back: () => {
1607
- var _a;
1608
- const { history, dispatch } = get();
1609
- if (history.hasPast()) {
1610
- const state = tidyState(
1611
- ((_a = history.prevHistory()) == null ? void 0 : _a.state) || history.initialAppState
1612
- );
1613
- dispatch({
1614
- type: "set",
1615
- state
1616
- });
1617
- set({ history: __spreadProps(__spreadValues({}, history), { index: history.index - 1 }) });
1618
- }
1619
- },
1620
- forward: () => {
1621
- var _a;
1622
- const { history, dispatch } = get();
1623
- if (history.hasFuture()) {
1624
- const state = (_a = history.nextHistory()) == null ? void 0 : _a.state;
1625
- dispatch({ type: "set", state: state ? tidyState(state) : {} });
1626
- set({ history: __spreadProps(__spreadValues({}, history), { index: history.index + 1 }) });
1627
- }
1628
- },
1629
- setHistories: (histories) => {
1630
- var _a;
1631
- const { dispatch, history } = get();
1632
- dispatch({
1633
- type: "set",
1634
- state: ((_a = histories[histories.length - 1]) == null ? void 0 : _a.state) || history.initialAppState
1635
- });
1636
- set({ history: __spreadProps(__spreadValues({}, history), { histories, index: histories.length - 1 }) });
1637
- },
1638
- setHistoryIndex: (index) => {
1639
- var _a;
1640
- const { dispatch, history } = get();
1641
- dispatch({
1642
- type: "set",
1643
- state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1644
- });
1645
- set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1646
- },
1647
- record
1648
- };
1649
- };
1650
-
1651
665
  // ../core/store/slices/nodes.ts
1652
666
  init_react_import();
1653
- var createNodesSlice = (_set, _get) => {
1654
- const registry = /* @__PURE__ */ new Map();
1655
- return {
1656
- registerNode: (id, handle) => {
1657
- registry.set(id, handle);
1658
- },
1659
- unregisterNode: (id) => {
1660
- registry.delete(id);
1661
- },
1662
- syncNode: (id) => {
1663
- var _a;
1664
- if (!id) return;
1665
- (_a = registry.get(id)) == null ? void 0 : _a.sync();
1666
- },
1667
- syncNodes: (ids) => {
1668
- ids.forEach((id) => {
1669
- var _a;
1670
- if (!id) return;
1671
- (_a = registry.get(id)) == null ? void 0 : _a.sync();
1672
- });
1673
- },
1674
- setOverlayVisible: (id, visible) => {
1675
- if (!id) return;
1676
- const node = registry.get(id);
1677
- if (!node) return;
1678
- if (visible) {
1679
- node.showOverlay();
1680
- return;
1681
- }
1682
- node.hideOverlay();
1683
- }
1684
- };
1685
- };
1686
667
 
1687
668
  // ../core/store/slices/permissions.ts
1688
669
  init_react_import();
@@ -1690,667 +671,19 @@ import { useEffect as useEffect3 } from "react";
1690
671
 
1691
672
  // ../core/lib/data/flatten-data.ts
1692
673
  init_react_import();
1693
- var flattenData = (state, config) => {
1694
- const data = [];
1695
- walkAppState(
1696
- state,
1697
- config,
1698
- (content) => content,
1699
- (item) => {
1700
- data.push(item);
1701
- return item;
1702
- }
1703
- );
1704
- return data;
1705
- };
1706
674
 
1707
675
  // ../core/lib/get-changed.ts
1708
676
  init_react_import();
1709
677
 
1710
- // ../../node_modules/fast-equals/dist/esm/index.mjs
1711
- init_react_import();
1712
- var getOwnPropertyNames = Object.getOwnPropertyNames;
1713
- var getOwnPropertySymbols = Object.getOwnPropertySymbols;
1714
- var hasOwnProperty = Object.prototype.hasOwnProperty;
1715
- function combineComparators(comparatorA, comparatorB) {
1716
- return function isEqual(a, b, state) {
1717
- return comparatorA(a, b, state) && comparatorB(a, b, state);
1718
- };
1719
- }
1720
- function createIsCircular(areItemsEqual) {
1721
- return function isCircular(a, b, state) {
1722
- if (!a || !b || typeof a !== "object" || typeof b !== "object") {
1723
- return areItemsEqual(a, b, state);
1724
- }
1725
- var cache2 = state.cache;
1726
- var cachedA = cache2.get(a);
1727
- var cachedB = cache2.get(b);
1728
- if (cachedA && cachedB) {
1729
- return cachedA === b && cachedB === a;
1730
- }
1731
- cache2.set(a, b);
1732
- cache2.set(b, a);
1733
- var result = areItemsEqual(a, b, state);
1734
- cache2.delete(a);
1735
- cache2.delete(b);
1736
- return result;
1737
- };
1738
- }
1739
- function getStrictProperties(object) {
1740
- return getOwnPropertyNames(object).concat(getOwnPropertySymbols(object));
1741
- }
1742
- var hasOwn = Object.hasOwn || (function(object, property) {
1743
- return hasOwnProperty.call(object, property);
1744
- });
1745
- function sameValueZeroEqual(a, b) {
1746
- return a === b || !a && !b && a !== a && b !== b;
1747
- }
1748
- var PREACT_VNODE = "__v";
1749
- var PREACT_OWNER = "__o";
1750
- var REACT_OWNER = "_owner";
1751
- var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
1752
- var keys = Object.keys;
1753
- function areArraysEqual(a, b, state) {
1754
- var index = a.length;
1755
- if (b.length !== index) {
1756
- return false;
1757
- }
1758
- while (index-- > 0) {
1759
- if (!state.equals(a[index], b[index], index, index, a, b, state)) {
1760
- return false;
1761
- }
1762
- }
1763
- return true;
1764
- }
1765
- function areDatesEqual(a, b) {
1766
- return sameValueZeroEqual(a.getTime(), b.getTime());
1767
- }
1768
- function areErrorsEqual(a, b) {
1769
- return a.name === b.name && a.message === b.message && a.cause === b.cause && a.stack === b.stack;
1770
- }
1771
- function areFunctionsEqual(a, b) {
1772
- return a === b;
1773
- }
1774
- function areMapsEqual(a, b, state) {
1775
- var size = a.size;
1776
- if (size !== b.size) {
1777
- return false;
1778
- }
1779
- if (!size) {
1780
- return true;
1781
- }
1782
- var matchedIndices = new Array(size);
1783
- var aIterable = a.entries();
1784
- var aResult;
1785
- var bResult;
1786
- var index = 0;
1787
- while (aResult = aIterable.next()) {
1788
- if (aResult.done) {
1789
- break;
1790
- }
1791
- var bIterable = b.entries();
1792
- var hasMatch = false;
1793
- var matchIndex = 0;
1794
- while (bResult = bIterable.next()) {
1795
- if (bResult.done) {
1796
- break;
1797
- }
1798
- if (matchedIndices[matchIndex]) {
1799
- matchIndex++;
1800
- continue;
1801
- }
1802
- var aEntry = aResult.value;
1803
- var bEntry = bResult.value;
1804
- if (state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state) && state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)) {
1805
- hasMatch = matchedIndices[matchIndex] = true;
1806
- break;
1807
- }
1808
- matchIndex++;
1809
- }
1810
- if (!hasMatch) {
1811
- return false;
1812
- }
1813
- index++;
1814
- }
1815
- return true;
1816
- }
1817
- var areNumbersEqual = sameValueZeroEqual;
1818
- function areObjectsEqual(a, b, state) {
1819
- var properties = keys(a);
1820
- var index = properties.length;
1821
- if (keys(b).length !== index) {
1822
- return false;
1823
- }
1824
- while (index-- > 0) {
1825
- if (!isPropertyEqual(a, b, state, properties[index])) {
1826
- return false;
1827
- }
1828
- }
1829
- return true;
1830
- }
1831
- function areObjectsEqualStrict(a, b, state) {
1832
- var properties = getStrictProperties(a);
1833
- var index = properties.length;
1834
- if (getStrictProperties(b).length !== index) {
1835
- return false;
1836
- }
1837
- var property;
1838
- var descriptorA;
1839
- var descriptorB;
1840
- while (index-- > 0) {
1841
- property = properties[index];
1842
- if (!isPropertyEqual(a, b, state, property)) {
1843
- return false;
1844
- }
1845
- descriptorA = getOwnPropertyDescriptor(a, property);
1846
- descriptorB = getOwnPropertyDescriptor(b, property);
1847
- if ((descriptorA || descriptorB) && (!descriptorA || !descriptorB || descriptorA.configurable !== descriptorB.configurable || descriptorA.enumerable !== descriptorB.enumerable || descriptorA.writable !== descriptorB.writable)) {
1848
- return false;
1849
- }
1850
- }
1851
- return true;
1852
- }
1853
- function arePrimitiveWrappersEqual(a, b) {
1854
- return sameValueZeroEqual(a.valueOf(), b.valueOf());
1855
- }
1856
- function areRegExpsEqual(a, b) {
1857
- return a.source === b.source && a.flags === b.flags;
1858
- }
1859
- function areSetsEqual(a, b, state) {
1860
- var size = a.size;
1861
- if (size !== b.size) {
1862
- return false;
1863
- }
1864
- if (!size) {
1865
- return true;
1866
- }
1867
- var matchedIndices = new Array(size);
1868
- var aIterable = a.values();
1869
- var aResult;
1870
- var bResult;
1871
- while (aResult = aIterable.next()) {
1872
- if (aResult.done) {
1873
- break;
1874
- }
1875
- var bIterable = b.values();
1876
- var hasMatch = false;
1877
- var matchIndex = 0;
1878
- while (bResult = bIterable.next()) {
1879
- if (bResult.done) {
1880
- break;
1881
- }
1882
- if (!matchedIndices[matchIndex] && state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state)) {
1883
- hasMatch = matchedIndices[matchIndex] = true;
1884
- break;
1885
- }
1886
- matchIndex++;
1887
- }
1888
- if (!hasMatch) {
1889
- return false;
1890
- }
1891
- }
1892
- return true;
1893
- }
1894
- function areTypedArraysEqual(a, b) {
1895
- var index = a.length;
1896
- if (b.length !== index) {
1897
- return false;
1898
- }
1899
- while (index-- > 0) {
1900
- if (a[index] !== b[index]) {
1901
- return false;
1902
- }
1903
- }
1904
- return true;
1905
- }
1906
- function areUrlsEqual(a, b) {
1907
- return a.hostname === b.hostname && a.pathname === b.pathname && a.protocol === b.protocol && a.port === b.port && a.hash === b.hash && a.username === b.username && a.password === b.password;
1908
- }
1909
- function isPropertyEqual(a, b, state, property) {
1910
- if ((property === REACT_OWNER || property === PREACT_OWNER || property === PREACT_VNODE) && (a.$$typeof || b.$$typeof)) {
1911
- return true;
1912
- }
1913
- return hasOwn(b, property) && state.equals(a[property], b[property], property, property, a, b, state);
1914
- }
1915
- var ARGUMENTS_TAG = "[object Arguments]";
1916
- var BOOLEAN_TAG = "[object Boolean]";
1917
- var DATE_TAG = "[object Date]";
1918
- var ERROR_TAG = "[object Error]";
1919
- var MAP_TAG = "[object Map]";
1920
- var NUMBER_TAG = "[object Number]";
1921
- var OBJECT_TAG = "[object Object]";
1922
- var REG_EXP_TAG = "[object RegExp]";
1923
- var SET_TAG = "[object Set]";
1924
- var STRING_TAG = "[object String]";
1925
- var URL_TAG = "[object URL]";
1926
- var isArray = Array.isArray;
1927
- var isTypedArray = typeof ArrayBuffer === "function" && ArrayBuffer.isView ? ArrayBuffer.isView : null;
1928
- var assign = Object.assign;
1929
- var getTag = Object.prototype.toString.call.bind(Object.prototype.toString);
1930
- function createEqualityComparator(_a) {
1931
- var areArraysEqual2 = _a.areArraysEqual, areDatesEqual2 = _a.areDatesEqual, areErrorsEqual2 = _a.areErrorsEqual, areFunctionsEqual2 = _a.areFunctionsEqual, areMapsEqual2 = _a.areMapsEqual, areNumbersEqual2 = _a.areNumbersEqual, areObjectsEqual2 = _a.areObjectsEqual, arePrimitiveWrappersEqual2 = _a.arePrimitiveWrappersEqual, areRegExpsEqual2 = _a.areRegExpsEqual, areSetsEqual2 = _a.areSetsEqual, areTypedArraysEqual2 = _a.areTypedArraysEqual, areUrlsEqual2 = _a.areUrlsEqual;
1932
- return function comparator(a, b, state) {
1933
- if (a === b) {
1934
- return true;
1935
- }
1936
- if (a == null || b == null) {
1937
- return false;
1938
- }
1939
- var type = typeof a;
1940
- if (type !== typeof b) {
1941
- return false;
1942
- }
1943
- if (type !== "object") {
1944
- if (type === "number") {
1945
- return areNumbersEqual2(a, b, state);
1946
- }
1947
- if (type === "function") {
1948
- return areFunctionsEqual2(a, b, state);
1949
- }
1950
- return false;
1951
- }
1952
- var constructor = a.constructor;
1953
- if (constructor !== b.constructor) {
1954
- return false;
1955
- }
1956
- if (constructor === Object) {
1957
- return areObjectsEqual2(a, b, state);
1958
- }
1959
- if (isArray(a)) {
1960
- return areArraysEqual2(a, b, state);
1961
- }
1962
- if (isTypedArray != null && isTypedArray(a)) {
1963
- return areTypedArraysEqual2(a, b, state);
1964
- }
1965
- if (constructor === Date) {
1966
- return areDatesEqual2(a, b, state);
1967
- }
1968
- if (constructor === RegExp) {
1969
- return areRegExpsEqual2(a, b, state);
1970
- }
1971
- if (constructor === Map) {
1972
- return areMapsEqual2(a, b, state);
1973
- }
1974
- if (constructor === Set) {
1975
- return areSetsEqual2(a, b, state);
1976
- }
1977
- var tag = getTag(a);
1978
- if (tag === DATE_TAG) {
1979
- return areDatesEqual2(a, b, state);
1980
- }
1981
- if (tag === REG_EXP_TAG) {
1982
- return areRegExpsEqual2(a, b, state);
1983
- }
1984
- if (tag === MAP_TAG) {
1985
- return areMapsEqual2(a, b, state);
1986
- }
1987
- if (tag === SET_TAG) {
1988
- return areSetsEqual2(a, b, state);
1989
- }
1990
- if (tag === OBJECT_TAG) {
1991
- return typeof a.then !== "function" && typeof b.then !== "function" && areObjectsEqual2(a, b, state);
1992
- }
1993
- if (tag === URL_TAG) {
1994
- return areUrlsEqual2(a, b, state);
1995
- }
1996
- if (tag === ERROR_TAG) {
1997
- return areErrorsEqual2(a, b, state);
1998
- }
1999
- if (tag === ARGUMENTS_TAG) {
2000
- return areObjectsEqual2(a, b, state);
2001
- }
2002
- if (tag === BOOLEAN_TAG || tag === NUMBER_TAG || tag === STRING_TAG) {
2003
- return arePrimitiveWrappersEqual2(a, b, state);
2004
- }
2005
- return false;
2006
- };
2007
- }
2008
- function createEqualityComparatorConfig(_a) {
2009
- var circular = _a.circular, createCustomConfig = _a.createCustomConfig, strict = _a.strict;
2010
- var config = {
2011
- areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual,
2012
- areDatesEqual,
2013
- areErrorsEqual,
2014
- areFunctionsEqual,
2015
- areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual,
2016
- areNumbersEqual,
2017
- areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual,
2018
- arePrimitiveWrappersEqual,
2019
- areRegExpsEqual,
2020
- areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual,
2021
- areTypedArraysEqual: strict ? areObjectsEqualStrict : areTypedArraysEqual,
2022
- areUrlsEqual
2023
- };
2024
- if (createCustomConfig) {
2025
- config = assign({}, config, createCustomConfig(config));
2026
- }
2027
- if (circular) {
2028
- var areArraysEqual$1 = createIsCircular(config.areArraysEqual);
2029
- var areMapsEqual$1 = createIsCircular(config.areMapsEqual);
2030
- var areObjectsEqual$1 = createIsCircular(config.areObjectsEqual);
2031
- var areSetsEqual$1 = createIsCircular(config.areSetsEqual);
2032
- config = assign({}, config, {
2033
- areArraysEqual: areArraysEqual$1,
2034
- areMapsEqual: areMapsEqual$1,
2035
- areObjectsEqual: areObjectsEqual$1,
2036
- areSetsEqual: areSetsEqual$1
2037
- });
2038
- }
2039
- return config;
2040
- }
2041
- function createInternalEqualityComparator(compare) {
2042
- return function(a, b, _indexOrKeyA, _indexOrKeyB, _parentA, _parentB, state) {
2043
- return compare(a, b, state);
2044
- };
2045
- }
2046
- function createIsEqual(_a) {
2047
- var circular = _a.circular, comparator = _a.comparator, createState = _a.createState, equals = _a.equals, strict = _a.strict;
2048
- if (createState) {
2049
- return function isEqual(a, b) {
2050
- var _a2 = createState(), _b = _a2.cache, cache2 = _b === void 0 ? circular ? /* @__PURE__ */ new WeakMap() : void 0 : _b, meta = _a2.meta;
2051
- return comparator(a, b, {
2052
- cache: cache2,
2053
- equals,
2054
- meta,
2055
- strict
2056
- });
2057
- };
2058
- }
2059
- if (circular) {
2060
- return function isEqual(a, b) {
2061
- return comparator(a, b, {
2062
- cache: /* @__PURE__ */ new WeakMap(),
2063
- equals,
2064
- meta: void 0,
2065
- strict
2066
- });
2067
- };
2068
- }
2069
- var state = {
2070
- cache: void 0,
2071
- equals,
2072
- meta: void 0,
2073
- strict
2074
- };
2075
- return function isEqual(a, b) {
2076
- return comparator(a, b, state);
2077
- };
2078
- }
2079
- var deepEqual = createCustomEqual();
2080
- var strictDeepEqual = createCustomEqual({ strict: true });
2081
- var circularDeepEqual = createCustomEqual({ circular: true });
2082
- var strictCircularDeepEqual = createCustomEqual({
2083
- circular: true,
2084
- strict: true
2085
- });
2086
- var shallowEqual = createCustomEqual({
2087
- createInternalComparator: function() {
2088
- return sameValueZeroEqual;
2089
- }
2090
- });
2091
- var strictShallowEqual = createCustomEqual({
2092
- strict: true,
2093
- createInternalComparator: function() {
2094
- return sameValueZeroEqual;
2095
- }
2096
- });
2097
- var circularShallowEqual = createCustomEqual({
2098
- circular: true,
2099
- createInternalComparator: function() {
2100
- return sameValueZeroEqual;
2101
- }
2102
- });
2103
- var strictCircularShallowEqual = createCustomEqual({
2104
- circular: true,
2105
- createInternalComparator: function() {
2106
- return sameValueZeroEqual;
2107
- },
2108
- strict: true
2109
- });
2110
- function createCustomEqual(options) {
2111
- if (options === void 0) {
2112
- options = {};
2113
- }
2114
- var _a = options.circular, circular = _a === void 0 ? false : _a, createCustomInternalComparator = options.createInternalComparator, createState = options.createState, _b = options.strict, strict = _b === void 0 ? false : _b;
2115
- var config = createEqualityComparatorConfig(options);
2116
- var comparator = createEqualityComparator(config);
2117
- var equals = createCustomInternalComparator ? createCustomInternalComparator(comparator) : createInternalEqualityComparator(comparator);
2118
- return createIsEqual({ circular, comparator, createState, equals, strict });
2119
- }
2120
-
2121
- // ../core/lib/get-changed.ts
2122
- var getChanged = (newItem, oldItem) => {
2123
- return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
2124
- const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
2125
- const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
2126
- return __spreadProps(__spreadValues({}, acc), {
2127
- [item]: !deepEqual(oldItemProps[item], newItemProps[item])
2128
- });
2129
- }, {}) : {};
2130
- };
2131
-
2132
- // ../core/store/slices/permissions.ts
2133
- var createPermissionsSlice = (set, get) => {
2134
- const resolvePermissions = (..._0) => __async(null, [..._0], function* (params = {}, force) {
2135
- const { state, permissions, config } = get();
2136
- const { cache: cache2, globalPermissions } = permissions;
2137
- const resolvePermissionsForItem = (item2, force2 = false) => __async(null, null, function* () {
2138
- var _a, _b;
2139
- const { config: config2, state: appState, setComponentLoading } = get();
2140
- const itemCache = cache2[item2.props.id];
2141
- const nodes = appState.indexes.nodes;
2142
- const parentId = (_a = nodes[item2.props.id]) == null ? void 0 : _a.parentId;
2143
- const parentNode = parentId ? nodes[parentId] : null;
2144
- const parentData = (_b = parentNode == null ? void 0 : parentNode.data) != null ? _b : null;
2145
- const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
2146
- if (!componentConfig) {
2147
- return;
2148
- }
2149
- const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
2150
- if (componentConfig.resolvePermissions) {
2151
- const changed = getChanged(item2, itemCache == null ? void 0 : itemCache.lastData);
2152
- const propsChanged = Object.values(changed).some((el) => el === true);
2153
- const parentChanged = (itemCache == null ? void 0 : itemCache.lastParentId) !== parentId;
2154
- if (propsChanged || parentChanged || force2) {
2155
- const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
2156
- const resolvedPermissions = yield componentConfig.resolvePermissions(
2157
- item2,
2158
- {
2159
- changed,
2160
- lastPermissions: (itemCache == null ? void 0 : itemCache.lastPermissions) || null,
2161
- permissions: initialPermissions,
2162
- appState: makeStatePublic(appState),
2163
- lastData: (itemCache == null ? void 0 : itemCache.lastData) || null,
2164
- parent: parentData
2165
- }
2166
- );
2167
- const latest = get().permissions;
2168
- set({
2169
- permissions: __spreadProps(__spreadValues({}, latest), {
2170
- cache: __spreadProps(__spreadValues({}, latest.cache), {
2171
- [item2.props.id]: {
2172
- lastParentId: parentId,
2173
- lastData: item2,
2174
- lastPermissions: resolvedPermissions
2175
- }
2176
- }),
2177
- resolvedPermissions: __spreadProps(__spreadValues({}, latest.resolvedPermissions), {
2178
- [item2.props.id]: resolvedPermissions
2179
- })
2180
- })
2181
- });
2182
- clearTimeout2();
2183
- }
2184
- }
2185
- });
2186
- const resolvePermissionsForRoot = (force2 = false) => {
2187
- const { state: appState } = get();
2188
- resolvePermissionsForItem(
2189
- // Shim the root data in by conforming to component data shape
2190
- {
2191
- type: "root",
2192
- props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
2193
- },
2194
- force2
2195
- );
2196
- };
2197
- const { item, type, root } = params;
2198
- if (item) {
2199
- yield resolvePermissionsForItem(item, force);
2200
- } else if (type) {
2201
- flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(null, null, function* () {
2202
- yield resolvePermissionsForItem(item2, force);
2203
- }));
2204
- } else if (root) {
2205
- resolvePermissionsForRoot(force);
2206
- } else {
2207
- flattenData(state, config).map((item2) => __async(null, null, function* () {
2208
- yield resolvePermissionsForItem(item2, force);
2209
- }));
2210
- }
2211
- });
2212
- const refreshPermissions = (params) => resolvePermissions(params, true);
2213
- return {
2214
- cache: {},
2215
- globalPermissions: {
2216
- drag: true,
2217
- edit: true,
2218
- delete: true,
2219
- duplicate: true,
2220
- insert: true
2221
- },
2222
- resolvedPermissions: {},
2223
- getPermissions: ({ item, type, root } = {}) => {
2224
- const { config, permissions } = get();
2225
- const { globalPermissions, resolvedPermissions } = permissions;
2226
- if (item) {
2227
- const componentConfig = config.components[item.type];
2228
- const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
2229
- const resolvedForItem = resolvedPermissions[item.props.id];
2230
- return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
2231
- } else if (type) {
2232
- const componentConfig = config.components[type];
2233
- return __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
2234
- } else if (root) {
2235
- const rootConfig = config.root;
2236
- const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
2237
- const resolvedForItem = resolvedPermissions["root"];
2238
- return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
2239
- }
2240
- return globalPermissions;
2241
- },
2242
- resolvePermissions,
2243
- refreshPermissions
2244
- };
2245
- };
2246
-
2247
678
  // ../core/store/slices/fields.ts
2248
679
  init_react_import();
2249
680
  import { useCallback, useEffect as useEffect4 } from "react";
2250
- var createFieldsSlice = (_set, _get) => {
2251
- return {
2252
- fields: {},
2253
- loading: false,
2254
- lastResolvedData: {},
2255
- id: void 0
2256
- };
2257
- };
2258
681
 
2259
682
  // ../core/lib/resolve-component-data.ts
2260
683
  init_react_import();
2261
- var cache = { lastChange: {} };
2262
- var resolveComponentData = (_0, _1, ..._2) => __async(null, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", parent = null, root = { props: {} }, cacheStore = cache) {
2263
- const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
2264
- const resolvedItem = __spreadValues({}, item);
2265
- const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
2266
- const id = "id" in item.props ? item.props.id : "root";
2267
- if (shouldRunResolver) {
2268
- const {
2269
- item: oldItem = null,
2270
- resolved = {},
2271
- parentId: oldParentId = null
2272
- } = cacheStore.lastChange[id] || {};
2273
- const isRootOrInserted = oldParentId === null;
2274
- const parentChanged = !isRootOrInserted && (parent == null ? void 0 : parent.props.id) !== oldParentId;
2275
- const dataChanged = item && !deepEqual(item, oldItem);
2276
- const shouldSkip = trigger === "move" && !parentChanged || trigger !== "move" && trigger !== "force" && !dataChanged;
2277
- if (shouldSkip) {
2278
- return { node: resolved, didChange: false };
2279
- }
2280
- const changed = getChanged(item, oldItem);
2281
- if (onResolveStart) {
2282
- onResolveStart(item);
2283
- }
2284
- const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
2285
- changed,
2286
- lastData: oldItem,
2287
- metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
2288
- trigger,
2289
- parent,
2290
- root
2291
- });
2292
- resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
2293
- if (Object.keys(readOnly).length) {
2294
- resolvedItem.readOnly = readOnly;
2295
- }
2296
- }
2297
- const itemAsComponentData = toComponent(resolvedItem);
2298
- let itemWithResolvedChildren = yield mapFields(
2299
- resolvedItem,
2300
- {
2301
- slot: (_02) => __async(null, [_02], function* ({ value }) {
2302
- const content = value;
2303
- return yield Promise.all(
2304
- content.map(
2305
- (childItem) => __async(null, null, function* () {
2306
- return (yield resolveComponentData(
2307
- childItem,
2308
- config,
2309
- metadata,
2310
- onResolveStart,
2311
- onResolveEnd,
2312
- trigger,
2313
- itemAsComponentData,
2314
- root,
2315
- cacheStore
2316
- )).node;
2317
- })
2318
- )
2319
- );
2320
- })
2321
- },
2322
- config
2323
- );
2324
- if (shouldRunResolver && onResolveEnd) {
2325
- onResolveEnd(resolvedItem);
2326
- }
2327
- cacheStore.lastChange[id] = {
2328
- item,
2329
- resolved: itemWithResolvedChildren,
2330
- parentId: parent == null ? void 0 : parent.props.id
2331
- };
2332
- return {
2333
- node: itemWithResolvedChildren,
2334
- didChange: !deepEqual(item, itemWithResolvedChildren)
2335
- };
2336
- });
2337
684
 
2338
685
  // ../core/lib/data/to-root.ts
2339
686
  init_react_import();
2340
- var toRoot = (item) => {
2341
- if ("type" in item && item.type !== "root") {
2342
- throw new Error("Converting non-root item to root.");
2343
- }
2344
- const { readOnly } = item;
2345
- if (item.props) {
2346
- if ("id" in item.props) {
2347
- const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
2348
- return { props, readOnly };
2349
- }
2350
- return { props: item.props, readOnly };
2351
- }
2352
- return { props: {}, readOnly };
2353
- };
2354
687
 
2355
688
  // ../core/store/default-app-state.ts
2356
689
  init_react_import();
@@ -2363,6 +696,7 @@ var defaultAppState = {
2363
696
  itemSelector: null,
2364
697
  componentList: {},
2365
698
  isDragging: false,
699
+ itemExpanded: {},
2366
700
  previewMode: "edit",
2367
701
  viewports: {
2368
702
  current: {
@@ -2372,6 +706,7 @@ var defaultAppState = {
2372
706
  options: [],
2373
707
  controlsVisible: true
2374
708
  },
709
+ expandedFieldGroups: {},
2375
710
  field: { focus: null },
2376
711
  plugin: { current: null }
2377
712
  },
@@ -2382,200 +717,7 @@ var defaultAppState = {
2382
717
  };
2383
718
 
2384
719
  // ../core/store/index.ts
2385
- var defaultPageFields = {
2386
- title: { type: "text" }
2387
- };
2388
- var createAppStore = (initialAppStore) => create()(
2389
- subscribeWithSelector((set, get) => {
2390
- var _a, _b;
2391
- return __spreadProps(__spreadValues({
2392
- instanceId: generateId(),
2393
- state: defaultAppState,
2394
- config: { components: {} },
2395
- componentState: {},
2396
- plugins: [],
2397
- overrides: {},
2398
- viewports: defaultViewports,
2399
- zoomConfig: {
2400
- autoZoom: 1,
2401
- rootHeight: 0,
2402
- zoom: 1
2403
- },
2404
- status: "LOADING",
2405
- iframe: {},
2406
- _experimentalFullScreenCanvas: false,
2407
- _experimentalVirtualization: false,
2408
- metadata: {},
2409
- dictionary: {},
2410
- fieldTransforms: {}
2411
- }, initialAppStore), {
2412
- fields: createFieldsSlice(set, get),
2413
- history: createHistorySlice(set, get),
2414
- nodes: createNodesSlice(set, get),
2415
- permissions: createPermissionsSlice(set, get),
2416
- getCurrentData: () => {
2417
- var _a2;
2418
- const s = get();
2419
- return (_a2 = s.selectedItem) != null ? _a2 : s.state.data.root;
2420
- },
2421
- getComponentConfig: (type) => {
2422
- var _a2;
2423
- const { config, selectedItem } = get();
2424
- const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
2425
- return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
2426
- },
2427
- selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
2428
- (_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
2429
- initialAppStore.state
2430
- ) : null,
2431
- dispatch: (action) => set((s) => {
2432
- var _a2, _b2;
2433
- const { record } = get().history;
2434
- const dispatch = createReducer({
2435
- record,
2436
- appStore: s
2437
- });
2438
- const state = dispatch(s.state, action);
2439
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
2440
- (_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
2441
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
2442
- }),
2443
- setZoomConfig: (zoomConfig) => set({ zoomConfig }),
2444
- setStatus: (status) => set({ status }),
2445
- setComponentState: (componentState) => set({ componentState }),
2446
- pendingLoadTimeouts: {},
2447
- setComponentLoading: (id, loading = true, defer = 0) => {
2448
- const { setComponentState, pendingLoadTimeouts } = get();
2449
- const loadId = generateId();
2450
- const setLoading = () => {
2451
- var _a2;
2452
- const { componentState } = get();
2453
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
2454
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
2455
- loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
2456
- })
2457
- }));
2458
- };
2459
- const unsetLoading = () => {
2460
- var _a2;
2461
- const { componentState } = get();
2462
- clearTimeout(timeout);
2463
- delete pendingLoadTimeouts[loadId];
2464
- set({ pendingLoadTimeouts });
2465
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
2466
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
2467
- loadingCount: Math.max(
2468
- (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
2469
- 0
2470
- )
2471
- })
2472
- }));
2473
- };
2474
- const timeout = setTimeout(() => {
2475
- if (loading) {
2476
- setLoading();
2477
- } else {
2478
- unsetLoading();
2479
- }
2480
- delete pendingLoadTimeouts[loadId];
2481
- set({ pendingLoadTimeouts });
2482
- }, defer);
2483
- set({
2484
- pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
2485
- [id]: timeout
2486
- })
2487
- });
2488
- return unsetLoading;
2489
- },
2490
- unsetComponentLoading: (id) => {
2491
- const { setComponentLoading } = get();
2492
- setComponentLoading(id, false);
2493
- },
2494
- // Helper
2495
- setUi: (ui, recordHistory) => set((s) => {
2496
- const dispatch = createReducer({
2497
- record: () => {
2498
- },
2499
- appStore: s
2500
- });
2501
- const state = dispatch(s.state, {
2502
- type: "setUi",
2503
- ui,
2504
- recordHistory
2505
- });
2506
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
2507
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
2508
- }),
2509
- resolveComponentData: (componentData, trigger) => __async(null, null, function* () {
2510
- var _a2, _b2;
2511
- const { config, metadata, setComponentLoading, permissions, state } = get();
2512
- const componentId = "id" in componentData.props ? componentData.props.id : "root";
2513
- const parentId = (_a2 = state.indexes.nodes[componentId]) == null ? void 0 : _a2.parentId;
2514
- const parentNode = parentId ? state.indexes.nodes[parentId] : null;
2515
- const parentData = (_b2 = parentNode == null ? void 0 : parentNode.data) != null ? _b2 : null;
2516
- const timeouts = {};
2517
- return yield resolveComponentData(
2518
- componentData,
2519
- config,
2520
- metadata,
2521
- (item) => {
2522
- const id = "id" in item.props ? item.props.id : "root";
2523
- timeouts[id] = setComponentLoading(id, true, 50);
2524
- },
2525
- (item) => __async(null, null, function* () {
2526
- const id = "id" in item.props ? item.props.id : "root";
2527
- if ("type" in item) {
2528
- yield permissions.refreshPermissions({ item });
2529
- } else {
2530
- yield permissions.refreshPermissions({ root: true });
2531
- }
2532
- timeouts[id]();
2533
- }),
2534
- trigger,
2535
- parentData,
2536
- state.data.root
2537
- );
2538
- }),
2539
- resolveAndCommitData: () => __async(null, null, function* () {
2540
- const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
2541
- walkAppState(
2542
- state,
2543
- config,
2544
- (content) => content,
2545
- (childItem, path) => {
2546
- if (path.length > 1) return childItem;
2547
- resolveComponentData2(childItem, "load").then((resolved) => {
2548
- const { state: state2 } = get();
2549
- const node = state2.indexes.nodes[resolved.node.props.id];
2550
- if (node && resolved.didChange) {
2551
- if (resolved.node.props.id === "root") {
2552
- dispatch({
2553
- type: "replaceRoot",
2554
- root: toRoot(resolved.node)
2555
- });
2556
- } else {
2557
- const zoneCompound = `${node.parentId}:${node.zone}`;
2558
- const parentZone = state2.indexes.zones[zoneCompound];
2559
- const index = parentZone.contentIds.indexOf(
2560
- resolved.node.props.id
2561
- );
2562
- dispatch({
2563
- type: "replace",
2564
- data: resolved.node,
2565
- destinationIndex: index,
2566
- destinationZone: zoneCompound
2567
- });
2568
- }
2569
- }
2570
- });
2571
- return childItem;
2572
- }
2573
- );
2574
- })
2575
- });
2576
- })
2577
- );
2578
- var appStoreContext = createContext(createAppStore());
720
+ var appStoreContext = createContext(null);
2579
721
 
2580
722
  // ../core/lib/get-zoom-config.ts
2581
723
  init_react_import();