@measured/puck-plugin-heading-analyzer 0.19.0-canary.896a6279 → 0.19.0-canary.91cb9cee
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/README.md +1 -1
- package/dist/index.d.mts +17 -9
- package/dist/index.d.ts +17 -9
- package/dist/index.js +141 -67
- package/dist/index.mjs +141 -67
- package/package.json +3 -3
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
@@ -13,6 +13,7 @@ type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
|
|
13
13
|
type BaseField = {
|
14
14
|
label?: string;
|
15
15
|
labelIcon?: ReactElement;
|
16
|
+
metadata?: Metadata;
|
16
17
|
};
|
17
18
|
type TextField = BaseField & {
|
18
19
|
type: "text";
|
@@ -99,19 +100,22 @@ type ExternalField<Props extends {
|
|
99
100
|
filterFields?: Record<string, Field>;
|
100
101
|
initialFilters?: Record<string, any>;
|
101
102
|
};
|
102
|
-
type
|
103
|
+
type CustomFieldRender<Value extends any> = (props: {
|
104
|
+
field: CustomField<Value>;
|
105
|
+
name: string;
|
106
|
+
id: string;
|
107
|
+
value: Value;
|
108
|
+
onChange: (value: Value) => void;
|
109
|
+
readOnly?: boolean;
|
110
|
+
}) => ReactElement;
|
111
|
+
type CustomField<Value extends any> = BaseField & {
|
103
112
|
type: "custom";
|
104
|
-
render:
|
105
|
-
field: CustomField<Props>;
|
106
|
-
name: string;
|
107
|
-
id: string;
|
108
|
-
value: Props;
|
109
|
-
onChange: (value: Props) => void;
|
110
|
-
readOnly?: boolean;
|
111
|
-
}) => ReactElement;
|
113
|
+
render: CustomFieldRender<Value>;
|
112
114
|
};
|
113
115
|
type SlotField = BaseField & {
|
114
116
|
type: "slot";
|
117
|
+
allow?: string[];
|
118
|
+
disallow?: string[];
|
115
119
|
};
|
116
120
|
type Field<Props extends any = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props extends {
|
117
121
|
[key: string]: any;
|
@@ -130,6 +134,10 @@ type FieldProps<F = Field<any>, ValueType = any> = {
|
|
130
134
|
readOnly?: boolean;
|
131
135
|
};
|
132
136
|
|
137
|
+
type Metadata = {
|
138
|
+
[key: string]: any;
|
139
|
+
};
|
140
|
+
|
133
141
|
type ItemWithId = {
|
134
142
|
_arrayId: string;
|
135
143
|
_originalIndex: number;
|
package/dist/index.d.ts
CHANGED
@@ -13,6 +13,7 @@ type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
|
|
13
13
|
type BaseField = {
|
14
14
|
label?: string;
|
15
15
|
labelIcon?: ReactElement;
|
16
|
+
metadata?: Metadata;
|
16
17
|
};
|
17
18
|
type TextField = BaseField & {
|
18
19
|
type: "text";
|
@@ -99,19 +100,22 @@ type ExternalField<Props extends {
|
|
99
100
|
filterFields?: Record<string, Field>;
|
100
101
|
initialFilters?: Record<string, any>;
|
101
102
|
};
|
102
|
-
type
|
103
|
+
type CustomFieldRender<Value extends any> = (props: {
|
104
|
+
field: CustomField<Value>;
|
105
|
+
name: string;
|
106
|
+
id: string;
|
107
|
+
value: Value;
|
108
|
+
onChange: (value: Value) => void;
|
109
|
+
readOnly?: boolean;
|
110
|
+
}) => ReactElement;
|
111
|
+
type CustomField<Value extends any> = BaseField & {
|
103
112
|
type: "custom";
|
104
|
-
render:
|
105
|
-
field: CustomField<Props>;
|
106
|
-
name: string;
|
107
|
-
id: string;
|
108
|
-
value: Props;
|
109
|
-
onChange: (value: Props) => void;
|
110
|
-
readOnly?: boolean;
|
111
|
-
}) => ReactElement;
|
113
|
+
render: CustomFieldRender<Value>;
|
112
114
|
};
|
113
115
|
type SlotField = BaseField & {
|
114
116
|
type: "slot";
|
117
|
+
allow?: string[];
|
118
|
+
disallow?: string[];
|
115
119
|
};
|
116
120
|
type Field<Props extends any = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props extends {
|
117
121
|
[key: string]: any;
|
@@ -130,6 +134,10 @@ type FieldProps<F = Field<any>, ValueType = any> = {
|
|
130
134
|
readOnly?: boolean;
|
131
135
|
};
|
132
136
|
|
137
|
+
type Metadata = {
|
138
|
+
[key: string]: any;
|
139
|
+
};
|
140
|
+
|
133
141
|
type ItemWithId = {
|
134
142
|
_arrayId: string;
|
135
143
|
_originalIndex: number;
|
package/dist/index.js
CHANGED
@@ -371,7 +371,7 @@ init_react_import();
|
|
371
371
|
// ../core/reducer/actions/set.ts
|
372
372
|
init_react_import();
|
373
373
|
|
374
|
-
// ../core/lib/data/walk-
|
374
|
+
// ../core/lib/data/walk-app-state.ts
|
375
375
|
init_react_import();
|
376
376
|
|
377
377
|
// ../core/lib/data/for-each-slot.ts
|
@@ -460,8 +460,8 @@ var stripSlots = (data) => {
|
|
460
460
|
});
|
461
461
|
};
|
462
462
|
|
463
|
-
// ../core/lib/data/walk-
|
464
|
-
function
|
463
|
+
// ../core/lib/data/walk-app-state.ts
|
464
|
+
function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
465
465
|
var _a;
|
466
466
|
let newZones = {};
|
467
467
|
const newZoneIndex = {};
|
@@ -594,7 +594,7 @@ var setAction = (state, action, appStore) => {
|
|
594
594
|
console.warn(
|
595
595
|
"`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
596
596
|
);
|
597
|
-
return
|
597
|
+
return walkAppState(newState, appStore.config);
|
598
598
|
}
|
599
599
|
return __spreadValues(__spreadValues({}, state), action.state(state));
|
600
600
|
};
|
@@ -680,18 +680,116 @@ var getIdsForParent = (zoneCompound, state) => {
|
|
680
680
|
return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
|
681
681
|
};
|
682
682
|
|
683
|
+
// ../core/lib/data/populate-ids.ts
|
684
|
+
init_react_import();
|
685
|
+
|
686
|
+
// ../core/lib/data/walk-tree.ts
|
687
|
+
init_react_import();
|
688
|
+
|
689
|
+
// ../core/lib/data/map-slots.ts
|
690
|
+
init_react_import();
|
691
|
+
function mapSlotsAsync(_0, _1) {
|
692
|
+
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
693
|
+
const props = __spreadValues({}, item.props);
|
694
|
+
const propKeys = Object.keys(props);
|
695
|
+
for (let i = 0; i < propKeys.length; i++) {
|
696
|
+
const propKey = propKeys[i];
|
697
|
+
const itemType = "type" in item ? item.type : "root";
|
698
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
699
|
+
const content = props[propKey];
|
700
|
+
const mappedContent = recursive ? yield Promise.all(
|
701
|
+
content.map((item2) => __async(this, null, function* () {
|
702
|
+
return yield mapSlotsAsync(item2, map, recursive, isSlot2);
|
703
|
+
}))
|
704
|
+
) : content;
|
705
|
+
props[propKey] = yield map(mappedContent, propKey);
|
706
|
+
}
|
707
|
+
}
|
708
|
+
return __spreadProps(__spreadValues({}, item), { props });
|
709
|
+
});
|
710
|
+
}
|
711
|
+
function mapSlotsSync(item, map, isSlot2 = isSlot) {
|
712
|
+
var _a, _b;
|
713
|
+
const props = __spreadValues({}, item.props);
|
714
|
+
const propKeys = Object.keys(props);
|
715
|
+
for (let i = 0; i < propKeys.length; i++) {
|
716
|
+
const propKey = propKeys[i];
|
717
|
+
const itemType = "type" in item ? item.type : "root";
|
718
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
719
|
+
const content = props[propKey];
|
720
|
+
const mappedContent = content.map((item2) => {
|
721
|
+
return mapSlotsSync(item2, map, isSlot2);
|
722
|
+
});
|
723
|
+
props[propKey] = (_b = map(mappedContent, (_a = props.id) != null ? _a : "root", propKey)) != null ? _b : mappedContent;
|
724
|
+
}
|
725
|
+
}
|
726
|
+
return __spreadProps(__spreadValues({}, item), { props });
|
727
|
+
}
|
728
|
+
|
729
|
+
// ../core/lib/data/walk-tree.ts
|
730
|
+
function walkTree(data, config, callbackFn) {
|
731
|
+
var _a, _b;
|
732
|
+
const isSlot2 = createIsSlotConfig(config);
|
733
|
+
const walkItem = (item) => {
|
734
|
+
return mapSlotsSync(
|
735
|
+
item,
|
736
|
+
(content, parentId, propName) => callbackFn(content, { parentId, propName }),
|
737
|
+
isSlot2
|
738
|
+
);
|
739
|
+
};
|
740
|
+
if ("props" in data) {
|
741
|
+
return walkItem(data);
|
742
|
+
}
|
743
|
+
const _data = data;
|
744
|
+
const zones = (_a = _data.zones) != null ? _a : {};
|
745
|
+
const mappedContent = _data.content.map(walkItem);
|
746
|
+
return {
|
747
|
+
root: walkItem(_data.root),
|
748
|
+
content: (_b = callbackFn(mappedContent, {
|
749
|
+
parentId: "root",
|
750
|
+
propName: "default-zone"
|
751
|
+
})) != null ? _b : mappedContent,
|
752
|
+
zones: Object.keys(zones).reduce(
|
753
|
+
(acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
|
754
|
+
[zoneCompound]: zones[zoneCompound].map(walkItem)
|
755
|
+
}),
|
756
|
+
{}
|
757
|
+
)
|
758
|
+
};
|
759
|
+
}
|
760
|
+
|
761
|
+
// ../core/lib/data/populate-ids.ts
|
762
|
+
var populateIds = (data, config, override = false) => {
|
763
|
+
const id = generateId(data.type);
|
764
|
+
return walkTree(
|
765
|
+
__spreadProps(__spreadValues({}, data), {
|
766
|
+
props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({ id }, data.props)
|
767
|
+
}),
|
768
|
+
config,
|
769
|
+
(contents) => contents.map((item) => {
|
770
|
+
const id2 = generateId(item.type);
|
771
|
+
return __spreadProps(__spreadValues({}, item), {
|
772
|
+
props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
|
773
|
+
});
|
774
|
+
})
|
775
|
+
);
|
776
|
+
};
|
777
|
+
|
683
778
|
// ../core/reducer/actions/insert.ts
|
684
779
|
function insertAction(state, action, appStore) {
|
685
780
|
const id = action.id || generateId(action.componentType);
|
686
|
-
const emptyComponentData =
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
781
|
+
const emptyComponentData = populateIds(
|
782
|
+
{
|
783
|
+
type: action.componentType,
|
784
|
+
props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
|
785
|
+
id
|
786
|
+
})
|
787
|
+
},
|
788
|
+
appStore.config
|
789
|
+
);
|
692
790
|
const [parentId] = action.destinationZone.split(":");
|
693
791
|
const idsInPath = getIdsForParent(action.destinationZone, state);
|
694
|
-
return
|
792
|
+
return walkAppState(
|
695
793
|
state,
|
696
794
|
appStore.config,
|
697
795
|
(content, zoneCompound) => {
|
@@ -729,25 +827,26 @@ var replaceAction = (state, action, appStore) => {
|
|
729
827
|
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
730
828
|
);
|
731
829
|
}
|
732
|
-
|
830
|
+
const data = populateIds(action.data, appStore.config);
|
831
|
+
return walkAppState(
|
733
832
|
state,
|
734
833
|
appStore.config,
|
735
834
|
(content, zoneCompound) => {
|
736
835
|
const newContent = [...content];
|
737
836
|
if (zoneCompound === action.destinationZone) {
|
738
|
-
newContent[action.destinationIndex] =
|
837
|
+
newContent[action.destinationIndex] = data;
|
739
838
|
}
|
740
839
|
return newContent;
|
741
840
|
},
|
742
841
|
(childItem, path) => {
|
743
842
|
const pathIds = path.map((p) => p.split(":")[0]);
|
744
|
-
if (childItem.props.id ===
|
745
|
-
return
|
843
|
+
if (childItem.props.id === data.props.id) {
|
844
|
+
return data;
|
746
845
|
} else if (childItem.props.id === parentId) {
|
747
846
|
return childItem;
|
748
847
|
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
|
749
848
|
return childItem;
|
750
|
-
} else if (pathIds.indexOf(
|
849
|
+
} else if (pathIds.indexOf(data.props.id) > -1) {
|
751
850
|
return childItem;
|
752
851
|
}
|
753
852
|
return null;
|
@@ -758,7 +857,7 @@ var replaceAction = (state, action, appStore) => {
|
|
758
857
|
// ../core/reducer/actions/replace-root.ts
|
759
858
|
init_react_import();
|
760
859
|
var replaceRootAction = (state, action, appStore) => {
|
761
|
-
return
|
860
|
+
return walkAppState(
|
762
861
|
state,
|
763
862
|
appStore.config,
|
764
863
|
(content) => content,
|
@@ -797,7 +896,7 @@ function duplicateAction(state, action, appStore) {
|
|
797
896
|
id: generateId(item.type)
|
798
897
|
})
|
799
898
|
});
|
800
|
-
const modified =
|
899
|
+
const modified = walkAppState(
|
801
900
|
state,
|
802
901
|
appStore.config,
|
803
902
|
(content, zoneCompound) => {
|
@@ -862,7 +961,7 @@ var moveAction = (state, action, appStore) => {
|
|
862
961
|
if (!item) return state;
|
863
962
|
const idsInSourcePath = getIdsForParent(action.sourceZone, state);
|
864
963
|
const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
|
865
|
-
return
|
964
|
+
return walkAppState(
|
866
965
|
state,
|
867
966
|
appStore.config,
|
868
967
|
(content, zoneCompound) => {
|
@@ -910,7 +1009,6 @@ var reorderAction = (state, action, appStore) => {
|
|
910
1009
|
init_react_import();
|
911
1010
|
var removeAction = (state, action, appStore) => {
|
912
1011
|
const item = getItem({ index: action.index, zone: action.zone }, state);
|
913
|
-
const [parentId] = action.zone.split(":");
|
914
1012
|
const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
|
915
1013
|
(acc, [nodeId, nodeData]) => {
|
916
1014
|
const pathIds = nodeData.path.map((p) => p.split(":")[0]);
|
@@ -921,7 +1019,7 @@ var removeAction = (state, action, appStore) => {
|
|
921
1019
|
},
|
922
1020
|
[item.props.id]
|
923
1021
|
);
|
924
|
-
const newState =
|
1022
|
+
const newState = walkAppState(
|
925
1023
|
state,
|
926
1024
|
appStore.config,
|
927
1025
|
(content, zoneCompound) => {
|
@@ -929,24 +1027,17 @@ var removeAction = (state, action, appStore) => {
|
|
929
1027
|
return remove(content, action.index);
|
930
1028
|
}
|
931
1029
|
return content;
|
932
|
-
},
|
933
|
-
(childItem, path) => {
|
934
|
-
const parentIds = path.map((p) => p.split(":")[0]);
|
935
|
-
if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
|
936
|
-
return childItem;
|
937
|
-
}
|
938
|
-
return null;
|
939
1030
|
}
|
940
1031
|
);
|
941
1032
|
Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
|
942
|
-
const
|
943
|
-
if (nodesToDelete.includes(
|
1033
|
+
const parentId = zoneCompound.split(":")[0];
|
1034
|
+
if (nodesToDelete.includes(parentId) && newState.data.zones) {
|
944
1035
|
delete newState.data.zones[zoneCompound];
|
945
1036
|
}
|
946
1037
|
});
|
947
1038
|
Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
|
948
|
-
const
|
949
|
-
if (nodesToDelete.includes(
|
1039
|
+
const parentId = zoneCompound.split(":")[0];
|
1040
|
+
if (nodesToDelete.includes(parentId)) {
|
950
1041
|
delete newState.indexes.zones[zoneCompound];
|
951
1042
|
}
|
952
1043
|
});
|
@@ -1019,14 +1110,14 @@ var setDataAction = (state, action, appStore) => {
|
|
1019
1110
|
console.warn(
|
1020
1111
|
"`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
1021
1112
|
);
|
1022
|
-
return
|
1113
|
+
return walkAppState(
|
1023
1114
|
__spreadProps(__spreadValues({}, state), {
|
1024
1115
|
data: __spreadValues(__spreadValues({}, state.data), action.data)
|
1025
1116
|
}),
|
1026
1117
|
appStore.config
|
1027
1118
|
);
|
1028
1119
|
}
|
1029
|
-
return
|
1120
|
+
return walkAppState(
|
1030
1121
|
__spreadProps(__spreadValues({}, state), {
|
1031
1122
|
data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
|
1032
1123
|
}),
|
@@ -1313,7 +1404,7 @@ var createHistorySlice = (set, get) => {
|
|
1313
1404
|
const { dispatch, history } = get();
|
1314
1405
|
dispatch({
|
1315
1406
|
type: "set",
|
1316
|
-
state: ((_a = history.histories[
|
1407
|
+
state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
|
1317
1408
|
});
|
1318
1409
|
set({ history: __spreadProps(__spreadValues({}, history), { index }) });
|
1319
1410
|
},
|
@@ -1329,7 +1420,11 @@ var createNodesSlice = (set, get) => ({
|
|
1329
1420
|
const s = get().nodes;
|
1330
1421
|
const emptyNode = {
|
1331
1422
|
id,
|
1332
|
-
methods: {
|
1423
|
+
methods: {
|
1424
|
+
sync: () => null,
|
1425
|
+
hideOverlay: () => null,
|
1426
|
+
showOverlay: () => null
|
1427
|
+
},
|
1333
1428
|
element: null
|
1334
1429
|
};
|
1335
1430
|
const existingNode = s.nodes[id];
|
@@ -1366,7 +1461,7 @@ var import_react7 = require("react");
|
|
1366
1461
|
init_react_import();
|
1367
1462
|
var flattenData = (state, config) => {
|
1368
1463
|
const data = [];
|
1369
|
-
|
1464
|
+
walkAppState(
|
1370
1465
|
state,
|
1371
1466
|
config,
|
1372
1467
|
(content) => content,
|
@@ -1503,37 +1598,13 @@ var createFieldsSlice = (_set, _get) => {
|
|
1503
1598
|
return {
|
1504
1599
|
fields: {},
|
1505
1600
|
loading: false,
|
1506
|
-
lastResolvedData: {}
|
1601
|
+
lastResolvedData: {},
|
1602
|
+
id: void 0
|
1507
1603
|
};
|
1508
1604
|
};
|
1509
1605
|
|
1510
1606
|
// ../core/lib/resolve-component-data.ts
|
1511
1607
|
init_react_import();
|
1512
|
-
|
1513
|
-
// ../core/lib/data/map-slots.ts
|
1514
|
-
init_react_import();
|
1515
|
-
function mapSlots(_0, _1) {
|
1516
|
-
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
1517
|
-
const props = __spreadValues({}, item.props);
|
1518
|
-
const propKeys = Object.keys(props);
|
1519
|
-
for (let i = 0; i < propKeys.length; i++) {
|
1520
|
-
const propKey = propKeys[i];
|
1521
|
-
const itemType = "type" in item ? item.type : "root";
|
1522
|
-
if (isSlot2(itemType, propKey, props[propKey])) {
|
1523
|
-
const content = props[propKey];
|
1524
|
-
const mappedContent = recursive ? yield Promise.all(
|
1525
|
-
content.map((item2) => __async(this, null, function* () {
|
1526
|
-
return yield mapSlots(item2, map, recursive, isSlot2);
|
1527
|
-
}))
|
1528
|
-
) : content;
|
1529
|
-
props[propKey] = yield map(mappedContent, propKey);
|
1530
|
-
}
|
1531
|
-
}
|
1532
|
-
return __spreadProps(__spreadValues({}, item), { props });
|
1533
|
-
});
|
1534
|
-
}
|
1535
|
-
|
1536
|
-
// ../core/lib/resolve-component-data.ts
|
1537
1608
|
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1538
1609
|
var cache = { lastChange: {} };
|
1539
1610
|
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
|
@@ -1551,14 +1622,14 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1551
1622
|
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
1552
1623
|
changed,
|
1553
1624
|
lastData: oldItem,
|
1554
|
-
metadata,
|
1625
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
1555
1626
|
trigger
|
1556
1627
|
});
|
1557
1628
|
let resolvedItem = __spreadProps(__spreadValues({}, item), {
|
1558
1629
|
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
1559
1630
|
});
|
1560
1631
|
if (recursive) {
|
1561
|
-
resolvedItem = yield
|
1632
|
+
resolvedItem = yield mapSlotsAsync(
|
1562
1633
|
resolvedItem,
|
1563
1634
|
(content) => __async(void 0, null, function* () {
|
1564
1635
|
return Promise.all(
|
@@ -1613,7 +1684,8 @@ var toRoot = (item) => {
|
|
1613
1684
|
return { props: {}, readOnly };
|
1614
1685
|
};
|
1615
1686
|
|
1616
|
-
// ../core/store/
|
1687
|
+
// ../core/store/default-app-state.ts
|
1688
|
+
init_react_import();
|
1617
1689
|
var defaultAppState = {
|
1618
1690
|
data: { content: [], root: {}, zones: {} },
|
1619
1691
|
ui: {
|
@@ -1639,6 +1711,8 @@ var defaultAppState = {
|
|
1639
1711
|
zones: {}
|
1640
1712
|
}
|
1641
1713
|
};
|
1714
|
+
|
1715
|
+
// ../core/store/index.ts
|
1642
1716
|
var defaultPageFields = {
|
1643
1717
|
title: { type: "text" }
|
1644
1718
|
};
|
@@ -1778,7 +1852,7 @@ var createAppStore = (initialAppStore) => create()(
|
|
1778
1852
|
}),
|
1779
1853
|
resolveAndCommitData: () => __async(void 0, null, function* () {
|
1780
1854
|
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
1781
|
-
|
1855
|
+
walkAppState(
|
1782
1856
|
state,
|
1783
1857
|
config,
|
1784
1858
|
(content) => content,
|
package/dist/index.mjs
CHANGED
@@ -359,7 +359,7 @@ init_react_import();
|
|
359
359
|
// ../core/reducer/actions/set.ts
|
360
360
|
init_react_import();
|
361
361
|
|
362
|
-
// ../core/lib/data/walk-
|
362
|
+
// ../core/lib/data/walk-app-state.ts
|
363
363
|
init_react_import();
|
364
364
|
|
365
365
|
// ../core/lib/data/for-each-slot.ts
|
@@ -448,8 +448,8 @@ var stripSlots = (data) => {
|
|
448
448
|
});
|
449
449
|
};
|
450
450
|
|
451
|
-
// ../core/lib/data/walk-
|
452
|
-
function
|
451
|
+
// ../core/lib/data/walk-app-state.ts
|
452
|
+
function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
453
453
|
var _a;
|
454
454
|
let newZones = {};
|
455
455
|
const newZoneIndex = {};
|
@@ -582,7 +582,7 @@ var setAction = (state, action, appStore) => {
|
|
582
582
|
console.warn(
|
583
583
|
"`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
584
584
|
);
|
585
|
-
return
|
585
|
+
return walkAppState(newState, appStore.config);
|
586
586
|
}
|
587
587
|
return __spreadValues(__spreadValues({}, state), action.state(state));
|
588
588
|
};
|
@@ -668,18 +668,116 @@ var getIdsForParent = (zoneCompound, state) => {
|
|
668
668
|
return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
|
669
669
|
};
|
670
670
|
|
671
|
+
// ../core/lib/data/populate-ids.ts
|
672
|
+
init_react_import();
|
673
|
+
|
674
|
+
// ../core/lib/data/walk-tree.ts
|
675
|
+
init_react_import();
|
676
|
+
|
677
|
+
// ../core/lib/data/map-slots.ts
|
678
|
+
init_react_import();
|
679
|
+
function mapSlotsAsync(_0, _1) {
|
680
|
+
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
681
|
+
const props = __spreadValues({}, item.props);
|
682
|
+
const propKeys = Object.keys(props);
|
683
|
+
for (let i = 0; i < propKeys.length; i++) {
|
684
|
+
const propKey = propKeys[i];
|
685
|
+
const itemType = "type" in item ? item.type : "root";
|
686
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
687
|
+
const content = props[propKey];
|
688
|
+
const mappedContent = recursive ? yield Promise.all(
|
689
|
+
content.map((item2) => __async(this, null, function* () {
|
690
|
+
return yield mapSlotsAsync(item2, map, recursive, isSlot2);
|
691
|
+
}))
|
692
|
+
) : content;
|
693
|
+
props[propKey] = yield map(mappedContent, propKey);
|
694
|
+
}
|
695
|
+
}
|
696
|
+
return __spreadProps(__spreadValues({}, item), { props });
|
697
|
+
});
|
698
|
+
}
|
699
|
+
function mapSlotsSync(item, map, isSlot2 = isSlot) {
|
700
|
+
var _a, _b;
|
701
|
+
const props = __spreadValues({}, item.props);
|
702
|
+
const propKeys = Object.keys(props);
|
703
|
+
for (let i = 0; i < propKeys.length; i++) {
|
704
|
+
const propKey = propKeys[i];
|
705
|
+
const itemType = "type" in item ? item.type : "root";
|
706
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
707
|
+
const content = props[propKey];
|
708
|
+
const mappedContent = content.map((item2) => {
|
709
|
+
return mapSlotsSync(item2, map, isSlot2);
|
710
|
+
});
|
711
|
+
props[propKey] = (_b = map(mappedContent, (_a = props.id) != null ? _a : "root", propKey)) != null ? _b : mappedContent;
|
712
|
+
}
|
713
|
+
}
|
714
|
+
return __spreadProps(__spreadValues({}, item), { props });
|
715
|
+
}
|
716
|
+
|
717
|
+
// ../core/lib/data/walk-tree.ts
|
718
|
+
function walkTree(data, config, callbackFn) {
|
719
|
+
var _a, _b;
|
720
|
+
const isSlot2 = createIsSlotConfig(config);
|
721
|
+
const walkItem = (item) => {
|
722
|
+
return mapSlotsSync(
|
723
|
+
item,
|
724
|
+
(content, parentId, propName) => callbackFn(content, { parentId, propName }),
|
725
|
+
isSlot2
|
726
|
+
);
|
727
|
+
};
|
728
|
+
if ("props" in data) {
|
729
|
+
return walkItem(data);
|
730
|
+
}
|
731
|
+
const _data = data;
|
732
|
+
const zones = (_a = _data.zones) != null ? _a : {};
|
733
|
+
const mappedContent = _data.content.map(walkItem);
|
734
|
+
return {
|
735
|
+
root: walkItem(_data.root),
|
736
|
+
content: (_b = callbackFn(mappedContent, {
|
737
|
+
parentId: "root",
|
738
|
+
propName: "default-zone"
|
739
|
+
})) != null ? _b : mappedContent,
|
740
|
+
zones: Object.keys(zones).reduce(
|
741
|
+
(acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
|
742
|
+
[zoneCompound]: zones[zoneCompound].map(walkItem)
|
743
|
+
}),
|
744
|
+
{}
|
745
|
+
)
|
746
|
+
};
|
747
|
+
}
|
748
|
+
|
749
|
+
// ../core/lib/data/populate-ids.ts
|
750
|
+
var populateIds = (data, config, override = false) => {
|
751
|
+
const id = generateId(data.type);
|
752
|
+
return walkTree(
|
753
|
+
__spreadProps(__spreadValues({}, data), {
|
754
|
+
props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({ id }, data.props)
|
755
|
+
}),
|
756
|
+
config,
|
757
|
+
(contents) => contents.map((item) => {
|
758
|
+
const id2 = generateId(item.type);
|
759
|
+
return __spreadProps(__spreadValues({}, item), {
|
760
|
+
props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
|
761
|
+
});
|
762
|
+
})
|
763
|
+
);
|
764
|
+
};
|
765
|
+
|
671
766
|
// ../core/reducer/actions/insert.ts
|
672
767
|
function insertAction(state, action, appStore) {
|
673
768
|
const id = action.id || generateId(action.componentType);
|
674
|
-
const emptyComponentData =
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
769
|
+
const emptyComponentData = populateIds(
|
770
|
+
{
|
771
|
+
type: action.componentType,
|
772
|
+
props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
|
773
|
+
id
|
774
|
+
})
|
775
|
+
},
|
776
|
+
appStore.config
|
777
|
+
);
|
680
778
|
const [parentId] = action.destinationZone.split(":");
|
681
779
|
const idsInPath = getIdsForParent(action.destinationZone, state);
|
682
|
-
return
|
780
|
+
return walkAppState(
|
683
781
|
state,
|
684
782
|
appStore.config,
|
685
783
|
(content, zoneCompound) => {
|
@@ -717,25 +815,26 @@ var replaceAction = (state, action, appStore) => {
|
|
717
815
|
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
718
816
|
);
|
719
817
|
}
|
720
|
-
|
818
|
+
const data = populateIds(action.data, appStore.config);
|
819
|
+
return walkAppState(
|
721
820
|
state,
|
722
821
|
appStore.config,
|
723
822
|
(content, zoneCompound) => {
|
724
823
|
const newContent = [...content];
|
725
824
|
if (zoneCompound === action.destinationZone) {
|
726
|
-
newContent[action.destinationIndex] =
|
825
|
+
newContent[action.destinationIndex] = data;
|
727
826
|
}
|
728
827
|
return newContent;
|
729
828
|
},
|
730
829
|
(childItem, path) => {
|
731
830
|
const pathIds = path.map((p) => p.split(":")[0]);
|
732
|
-
if (childItem.props.id ===
|
733
|
-
return
|
831
|
+
if (childItem.props.id === data.props.id) {
|
832
|
+
return data;
|
734
833
|
} else if (childItem.props.id === parentId) {
|
735
834
|
return childItem;
|
736
835
|
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
|
737
836
|
return childItem;
|
738
|
-
} else if (pathIds.indexOf(
|
837
|
+
} else if (pathIds.indexOf(data.props.id) > -1) {
|
739
838
|
return childItem;
|
740
839
|
}
|
741
840
|
return null;
|
@@ -746,7 +845,7 @@ var replaceAction = (state, action, appStore) => {
|
|
746
845
|
// ../core/reducer/actions/replace-root.ts
|
747
846
|
init_react_import();
|
748
847
|
var replaceRootAction = (state, action, appStore) => {
|
749
|
-
return
|
848
|
+
return walkAppState(
|
750
849
|
state,
|
751
850
|
appStore.config,
|
752
851
|
(content) => content,
|
@@ -785,7 +884,7 @@ function duplicateAction(state, action, appStore) {
|
|
785
884
|
id: generateId(item.type)
|
786
885
|
})
|
787
886
|
});
|
788
|
-
const modified =
|
887
|
+
const modified = walkAppState(
|
789
888
|
state,
|
790
889
|
appStore.config,
|
791
890
|
(content, zoneCompound) => {
|
@@ -850,7 +949,7 @@ var moveAction = (state, action, appStore) => {
|
|
850
949
|
if (!item) return state;
|
851
950
|
const idsInSourcePath = getIdsForParent(action.sourceZone, state);
|
852
951
|
const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
|
853
|
-
return
|
952
|
+
return walkAppState(
|
854
953
|
state,
|
855
954
|
appStore.config,
|
856
955
|
(content, zoneCompound) => {
|
@@ -898,7 +997,6 @@ var reorderAction = (state, action, appStore) => {
|
|
898
997
|
init_react_import();
|
899
998
|
var removeAction = (state, action, appStore) => {
|
900
999
|
const item = getItem({ index: action.index, zone: action.zone }, state);
|
901
|
-
const [parentId] = action.zone.split(":");
|
902
1000
|
const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
|
903
1001
|
(acc, [nodeId, nodeData]) => {
|
904
1002
|
const pathIds = nodeData.path.map((p) => p.split(":")[0]);
|
@@ -909,7 +1007,7 @@ var removeAction = (state, action, appStore) => {
|
|
909
1007
|
},
|
910
1008
|
[item.props.id]
|
911
1009
|
);
|
912
|
-
const newState =
|
1010
|
+
const newState = walkAppState(
|
913
1011
|
state,
|
914
1012
|
appStore.config,
|
915
1013
|
(content, zoneCompound) => {
|
@@ -917,24 +1015,17 @@ var removeAction = (state, action, appStore) => {
|
|
917
1015
|
return remove(content, action.index);
|
918
1016
|
}
|
919
1017
|
return content;
|
920
|
-
},
|
921
|
-
(childItem, path) => {
|
922
|
-
const parentIds = path.map((p) => p.split(":")[0]);
|
923
|
-
if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
|
924
|
-
return childItem;
|
925
|
-
}
|
926
|
-
return null;
|
927
1018
|
}
|
928
1019
|
);
|
929
1020
|
Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
|
930
|
-
const
|
931
|
-
if (nodesToDelete.includes(
|
1021
|
+
const parentId = zoneCompound.split(":")[0];
|
1022
|
+
if (nodesToDelete.includes(parentId) && newState.data.zones) {
|
932
1023
|
delete newState.data.zones[zoneCompound];
|
933
1024
|
}
|
934
1025
|
});
|
935
1026
|
Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
|
936
|
-
const
|
937
|
-
if (nodesToDelete.includes(
|
1027
|
+
const parentId = zoneCompound.split(":")[0];
|
1028
|
+
if (nodesToDelete.includes(parentId)) {
|
938
1029
|
delete newState.indexes.zones[zoneCompound];
|
939
1030
|
}
|
940
1031
|
});
|
@@ -1007,14 +1098,14 @@ var setDataAction = (state, action, appStore) => {
|
|
1007
1098
|
console.warn(
|
1008
1099
|
"`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
1009
1100
|
);
|
1010
|
-
return
|
1101
|
+
return walkAppState(
|
1011
1102
|
__spreadProps(__spreadValues({}, state), {
|
1012
1103
|
data: __spreadValues(__spreadValues({}, state.data), action.data)
|
1013
1104
|
}),
|
1014
1105
|
appStore.config
|
1015
1106
|
);
|
1016
1107
|
}
|
1017
|
-
return
|
1108
|
+
return walkAppState(
|
1018
1109
|
__spreadProps(__spreadValues({}, state), {
|
1019
1110
|
data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
|
1020
1111
|
}),
|
@@ -1301,7 +1392,7 @@ var createHistorySlice = (set, get) => {
|
|
1301
1392
|
const { dispatch, history } = get();
|
1302
1393
|
dispatch({
|
1303
1394
|
type: "set",
|
1304
|
-
state: ((_a = history.histories[
|
1395
|
+
state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
|
1305
1396
|
});
|
1306
1397
|
set({ history: __spreadProps(__spreadValues({}, history), { index }) });
|
1307
1398
|
},
|
@@ -1317,7 +1408,11 @@ var createNodesSlice = (set, get) => ({
|
|
1317
1408
|
const s = get().nodes;
|
1318
1409
|
const emptyNode = {
|
1319
1410
|
id,
|
1320
|
-
methods: {
|
1411
|
+
methods: {
|
1412
|
+
sync: () => null,
|
1413
|
+
hideOverlay: () => null,
|
1414
|
+
showOverlay: () => null
|
1415
|
+
},
|
1321
1416
|
element: null
|
1322
1417
|
};
|
1323
1418
|
const existingNode = s.nodes[id];
|
@@ -1354,7 +1449,7 @@ import { useEffect as useEffect3 } from "react";
|
|
1354
1449
|
init_react_import();
|
1355
1450
|
var flattenData = (state, config) => {
|
1356
1451
|
const data = [];
|
1357
|
-
|
1452
|
+
walkAppState(
|
1358
1453
|
state,
|
1359
1454
|
config,
|
1360
1455
|
(content) => content,
|
@@ -1491,37 +1586,13 @@ var createFieldsSlice = (_set, _get) => {
|
|
1491
1586
|
return {
|
1492
1587
|
fields: {},
|
1493
1588
|
loading: false,
|
1494
|
-
lastResolvedData: {}
|
1589
|
+
lastResolvedData: {},
|
1590
|
+
id: void 0
|
1495
1591
|
};
|
1496
1592
|
};
|
1497
1593
|
|
1498
1594
|
// ../core/lib/resolve-component-data.ts
|
1499
1595
|
init_react_import();
|
1500
|
-
|
1501
|
-
// ../core/lib/data/map-slots.ts
|
1502
|
-
init_react_import();
|
1503
|
-
function mapSlots(_0, _1) {
|
1504
|
-
return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
|
1505
|
-
const props = __spreadValues({}, item.props);
|
1506
|
-
const propKeys = Object.keys(props);
|
1507
|
-
for (let i = 0; i < propKeys.length; i++) {
|
1508
|
-
const propKey = propKeys[i];
|
1509
|
-
const itemType = "type" in item ? item.type : "root";
|
1510
|
-
if (isSlot2(itemType, propKey, props[propKey])) {
|
1511
|
-
const content = props[propKey];
|
1512
|
-
const mappedContent = recursive ? yield Promise.all(
|
1513
|
-
content.map((item2) => __async(this, null, function* () {
|
1514
|
-
return yield mapSlots(item2, map, recursive, isSlot2);
|
1515
|
-
}))
|
1516
|
-
) : content;
|
1517
|
-
props[propKey] = yield map(mappedContent, propKey);
|
1518
|
-
}
|
1519
|
-
}
|
1520
|
-
return __spreadProps(__spreadValues({}, item), { props });
|
1521
|
-
});
|
1522
|
-
}
|
1523
|
-
|
1524
|
-
// ../core/lib/resolve-component-data.ts
|
1525
1596
|
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
1526
1597
|
var cache = { lastChange: {} };
|
1527
1598
|
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
|
@@ -1539,14 +1610,14 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
1539
1610
|
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
1540
1611
|
changed,
|
1541
1612
|
lastData: oldItem,
|
1542
|
-
metadata,
|
1613
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
1543
1614
|
trigger
|
1544
1615
|
});
|
1545
1616
|
let resolvedItem = __spreadProps(__spreadValues({}, item), {
|
1546
1617
|
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
1547
1618
|
});
|
1548
1619
|
if (recursive) {
|
1549
|
-
resolvedItem = yield
|
1620
|
+
resolvedItem = yield mapSlotsAsync(
|
1550
1621
|
resolvedItem,
|
1551
1622
|
(content) => __async(void 0, null, function* () {
|
1552
1623
|
return Promise.all(
|
@@ -1601,7 +1672,8 @@ var toRoot = (item) => {
|
|
1601
1672
|
return { props: {}, readOnly };
|
1602
1673
|
};
|
1603
1674
|
|
1604
|
-
// ../core/store/
|
1675
|
+
// ../core/store/default-app-state.ts
|
1676
|
+
init_react_import();
|
1605
1677
|
var defaultAppState = {
|
1606
1678
|
data: { content: [], root: {}, zones: {} },
|
1607
1679
|
ui: {
|
@@ -1627,6 +1699,8 @@ var defaultAppState = {
|
|
1627
1699
|
zones: {}
|
1628
1700
|
}
|
1629
1701
|
};
|
1702
|
+
|
1703
|
+
// ../core/store/index.ts
|
1630
1704
|
var defaultPageFields = {
|
1631
1705
|
title: { type: "text" }
|
1632
1706
|
};
|
@@ -1766,7 +1840,7 @@ var createAppStore = (initialAppStore) => create()(
|
|
1766
1840
|
}),
|
1767
1841
|
resolveAndCommitData: () => __async(void 0, null, function* () {
|
1768
1842
|
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
1769
|
-
|
1843
|
+
walkAppState(
|
1770
1844
|
state,
|
1771
1845
|
config,
|
1772
1846
|
(content) => content,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@measured/puck-plugin-heading-analyzer",
|
3
|
-
"version": "0.19.0-canary.
|
4
|
-
"author": "
|
3
|
+
"version": "0.19.0-canary.91cb9cee",
|
4
|
+
"author": "Chris Villa <chris@puckeditor.com>",
|
5
5
|
"repository": "measuredco/puck",
|
6
6
|
"bugs": "https://github.com/measuredco/puck/issues",
|
7
7
|
"homepage": "https://puckeditor.com",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"dist"
|
26
26
|
],
|
27
27
|
"devDependencies": {
|
28
|
-
"@measured/puck": "^0.19.0-canary.
|
28
|
+
"@measured/puck": "^0.19.0-canary.91cb9cee",
|
29
29
|
"@types/react": "^19.0.1",
|
30
30
|
"@types/react-dom": "^19.0.2",
|
31
31
|
"eslint": "^7.32.0",
|