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

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