@measured/puck-plugin-heading-analyzer 0.19.0-canary.896a6279 → 0.19.0-canary.8d459e4e

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 CHANGED
@@ -31,4 +31,4 @@ export function Page() {
31
31
 
32
32
  ## License
33
33
 
34
- MIT © [Measured Corporation Ltd](https://measured.co)
34
+ MIT © [The Puck Contributors](https://github.com/measuredco/puck/graphs/contributors)
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 CustomField<Props extends any = {}> = BaseField & {
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: (props: {
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 CustomField<Props extends any = {}> = BaseField & {
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: (props: {
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-tree.ts
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-tree.ts
464
- function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
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 walkTree(newState, appStore.config);
597
+ return walkAppState(newState, appStore.config);
598
598
  }
599
599
  return __spreadValues(__spreadValues({}, state), action.state(state));
600
600
  };
@@ -691,7 +691,7 @@ function insertAction(state, action, appStore) {
691
691
  };
692
692
  const [parentId] = action.destinationZone.split(":");
693
693
  const idsInPath = getIdsForParent(action.destinationZone, state);
694
- return walkTree(
694
+ return walkAppState(
695
695
  state,
696
696
  appStore.config,
697
697
  (content, zoneCompound) => {
@@ -729,7 +729,7 @@ var replaceAction = (state, action, appStore) => {
729
729
  `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
730
730
  );
731
731
  }
732
- return walkTree(
732
+ return walkAppState(
733
733
  state,
734
734
  appStore.config,
735
735
  (content, zoneCompound) => {
@@ -758,7 +758,7 @@ var replaceAction = (state, action, appStore) => {
758
758
  // ../core/reducer/actions/replace-root.ts
759
759
  init_react_import();
760
760
  var replaceRootAction = (state, action, appStore) => {
761
- return walkTree(
761
+ return walkAppState(
762
762
  state,
763
763
  appStore.config,
764
764
  (content) => content,
@@ -797,7 +797,7 @@ function duplicateAction(state, action, appStore) {
797
797
  id: generateId(item.type)
798
798
  })
799
799
  });
800
- const modified = walkTree(
800
+ const modified = walkAppState(
801
801
  state,
802
802
  appStore.config,
803
803
  (content, zoneCompound) => {
@@ -862,7 +862,7 @@ var moveAction = (state, action, appStore) => {
862
862
  if (!item) return state;
863
863
  const idsInSourcePath = getIdsForParent(action.sourceZone, state);
864
864
  const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
865
- return walkTree(
865
+ return walkAppState(
866
866
  state,
867
867
  appStore.config,
868
868
  (content, zoneCompound) => {
@@ -910,7 +910,6 @@ var reorderAction = (state, action, appStore) => {
910
910
  init_react_import();
911
911
  var removeAction = (state, action, appStore) => {
912
912
  const item = getItem({ index: action.index, zone: action.zone }, state);
913
- const [parentId] = action.zone.split(":");
914
913
  const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
915
914
  (acc, [nodeId, nodeData]) => {
916
915
  const pathIds = nodeData.path.map((p) => p.split(":")[0]);
@@ -921,7 +920,7 @@ var removeAction = (state, action, appStore) => {
921
920
  },
922
921
  [item.props.id]
923
922
  );
924
- const newState = walkTree(
923
+ const newState = walkAppState(
925
924
  state,
926
925
  appStore.config,
927
926
  (content, zoneCompound) => {
@@ -929,24 +928,17 @@ var removeAction = (state, action, appStore) => {
929
928
  return remove(content, action.index);
930
929
  }
931
930
  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
931
  }
940
932
  );
941
933
  Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
942
- const parentId2 = zoneCompound.split(":")[0];
943
- if (nodesToDelete.includes(parentId2) && newState.data.zones) {
934
+ const parentId = zoneCompound.split(":")[0];
935
+ if (nodesToDelete.includes(parentId) && newState.data.zones) {
944
936
  delete newState.data.zones[zoneCompound];
945
937
  }
946
938
  });
947
939
  Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
948
- const parentId2 = zoneCompound.split(":")[0];
949
- if (nodesToDelete.includes(parentId2)) {
940
+ const parentId = zoneCompound.split(":")[0];
941
+ if (nodesToDelete.includes(parentId)) {
950
942
  delete newState.indexes.zones[zoneCompound];
951
943
  }
952
944
  });
@@ -1019,14 +1011,14 @@ var setDataAction = (state, action, appStore) => {
1019
1011
  console.warn(
1020
1012
  "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
1021
1013
  );
1022
- return walkTree(
1014
+ return walkAppState(
1023
1015
  __spreadProps(__spreadValues({}, state), {
1024
1016
  data: __spreadValues(__spreadValues({}, state.data), action.data)
1025
1017
  }),
1026
1018
  appStore.config
1027
1019
  );
1028
1020
  }
1029
- return walkTree(
1021
+ return walkAppState(
1030
1022
  __spreadProps(__spreadValues({}, state), {
1031
1023
  data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1032
1024
  }),
@@ -1313,7 +1305,7 @@ var createHistorySlice = (set, get) => {
1313
1305
  const { dispatch, history } = get();
1314
1306
  dispatch({
1315
1307
  type: "set",
1316
- state: ((_a = history.histories[history.index]) == null ? void 0 : _a.state) || history.initialAppState
1308
+ state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1317
1309
  });
1318
1310
  set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1319
1311
  },
@@ -1366,7 +1358,7 @@ var import_react7 = require("react");
1366
1358
  init_react_import();
1367
1359
  var flattenData = (state, config) => {
1368
1360
  const data = [];
1369
- walkTree(
1361
+ walkAppState(
1370
1362
  state,
1371
1363
  config,
1372
1364
  (content) => content,
@@ -1512,7 +1504,7 @@ init_react_import();
1512
1504
 
1513
1505
  // ../core/lib/data/map-slots.ts
1514
1506
  init_react_import();
1515
- function mapSlots(_0, _1) {
1507
+ function mapSlotsAsync(_0, _1) {
1516
1508
  return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
1517
1509
  const props = __spreadValues({}, item.props);
1518
1510
  const propKeys = Object.keys(props);
@@ -1523,7 +1515,7 @@ function mapSlots(_0, _1) {
1523
1515
  const content = props[propKey];
1524
1516
  const mappedContent = recursive ? yield Promise.all(
1525
1517
  content.map((item2) => __async(this, null, function* () {
1526
- return yield mapSlots(item2, map, recursive, isSlot2);
1518
+ return yield mapSlotsAsync(item2, map, recursive, isSlot2);
1527
1519
  }))
1528
1520
  ) : content;
1529
1521
  props[propKey] = yield map(mappedContent, propKey);
@@ -1551,14 +1543,14 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
1551
1543
  const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1552
1544
  changed,
1553
1545
  lastData: oldItem,
1554
- metadata,
1546
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1555
1547
  trigger
1556
1548
  });
1557
1549
  let resolvedItem = __spreadProps(__spreadValues({}, item), {
1558
1550
  props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1559
1551
  });
1560
1552
  if (recursive) {
1561
- resolvedItem = yield mapSlots(
1553
+ resolvedItem = yield mapSlotsAsync(
1562
1554
  resolvedItem,
1563
1555
  (content) => __async(void 0, null, function* () {
1564
1556
  return Promise.all(
@@ -1778,7 +1770,7 @@ var createAppStore = (initialAppStore) => create()(
1778
1770
  }),
1779
1771
  resolveAndCommitData: () => __async(void 0, null, function* () {
1780
1772
  const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1781
- walkTree(
1773
+ walkAppState(
1782
1774
  state,
1783
1775
  config,
1784
1776
  (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-tree.ts
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-tree.ts
452
- function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
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 walkTree(newState, appStore.config);
585
+ return walkAppState(newState, appStore.config);
586
586
  }
587
587
  return __spreadValues(__spreadValues({}, state), action.state(state));
588
588
  };
@@ -679,7 +679,7 @@ function insertAction(state, action, appStore) {
679
679
  };
680
680
  const [parentId] = action.destinationZone.split(":");
681
681
  const idsInPath = getIdsForParent(action.destinationZone, state);
682
- return walkTree(
682
+ return walkAppState(
683
683
  state,
684
684
  appStore.config,
685
685
  (content, zoneCompound) => {
@@ -717,7 +717,7 @@ var replaceAction = (state, action, appStore) => {
717
717
  `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
718
718
  );
719
719
  }
720
- return walkTree(
720
+ return walkAppState(
721
721
  state,
722
722
  appStore.config,
723
723
  (content, zoneCompound) => {
@@ -746,7 +746,7 @@ var replaceAction = (state, action, appStore) => {
746
746
  // ../core/reducer/actions/replace-root.ts
747
747
  init_react_import();
748
748
  var replaceRootAction = (state, action, appStore) => {
749
- return walkTree(
749
+ return walkAppState(
750
750
  state,
751
751
  appStore.config,
752
752
  (content) => content,
@@ -785,7 +785,7 @@ function duplicateAction(state, action, appStore) {
785
785
  id: generateId(item.type)
786
786
  })
787
787
  });
788
- const modified = walkTree(
788
+ const modified = walkAppState(
789
789
  state,
790
790
  appStore.config,
791
791
  (content, zoneCompound) => {
@@ -850,7 +850,7 @@ var moveAction = (state, action, appStore) => {
850
850
  if (!item) return state;
851
851
  const idsInSourcePath = getIdsForParent(action.sourceZone, state);
852
852
  const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
853
- return walkTree(
853
+ return walkAppState(
854
854
  state,
855
855
  appStore.config,
856
856
  (content, zoneCompound) => {
@@ -898,7 +898,6 @@ var reorderAction = (state, action, appStore) => {
898
898
  init_react_import();
899
899
  var removeAction = (state, action, appStore) => {
900
900
  const item = getItem({ index: action.index, zone: action.zone }, state);
901
- const [parentId] = action.zone.split(":");
902
901
  const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
903
902
  (acc, [nodeId, nodeData]) => {
904
903
  const pathIds = nodeData.path.map((p) => p.split(":")[0]);
@@ -909,7 +908,7 @@ var removeAction = (state, action, appStore) => {
909
908
  },
910
909
  [item.props.id]
911
910
  );
912
- const newState = walkTree(
911
+ const newState = walkAppState(
913
912
  state,
914
913
  appStore.config,
915
914
  (content, zoneCompound) => {
@@ -917,24 +916,17 @@ var removeAction = (state, action, appStore) => {
917
916
  return remove(content, action.index);
918
917
  }
919
918
  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
919
  }
928
920
  );
929
921
  Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
930
- const parentId2 = zoneCompound.split(":")[0];
931
- if (nodesToDelete.includes(parentId2) && newState.data.zones) {
922
+ const parentId = zoneCompound.split(":")[0];
923
+ if (nodesToDelete.includes(parentId) && newState.data.zones) {
932
924
  delete newState.data.zones[zoneCompound];
933
925
  }
934
926
  });
935
927
  Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
936
- const parentId2 = zoneCompound.split(":")[0];
937
- if (nodesToDelete.includes(parentId2)) {
928
+ const parentId = zoneCompound.split(":")[0];
929
+ if (nodesToDelete.includes(parentId)) {
938
930
  delete newState.indexes.zones[zoneCompound];
939
931
  }
940
932
  });
@@ -1007,14 +999,14 @@ var setDataAction = (state, action, appStore) => {
1007
999
  console.warn(
1008
1000
  "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
1009
1001
  );
1010
- return walkTree(
1002
+ return walkAppState(
1011
1003
  __spreadProps(__spreadValues({}, state), {
1012
1004
  data: __spreadValues(__spreadValues({}, state.data), action.data)
1013
1005
  }),
1014
1006
  appStore.config
1015
1007
  );
1016
1008
  }
1017
- return walkTree(
1009
+ return walkAppState(
1018
1010
  __spreadProps(__spreadValues({}, state), {
1019
1011
  data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1020
1012
  }),
@@ -1301,7 +1293,7 @@ var createHistorySlice = (set, get) => {
1301
1293
  const { dispatch, history } = get();
1302
1294
  dispatch({
1303
1295
  type: "set",
1304
- state: ((_a = history.histories[history.index]) == null ? void 0 : _a.state) || history.initialAppState
1296
+ state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1305
1297
  });
1306
1298
  set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1307
1299
  },
@@ -1354,7 +1346,7 @@ import { useEffect as useEffect3 } from "react";
1354
1346
  init_react_import();
1355
1347
  var flattenData = (state, config) => {
1356
1348
  const data = [];
1357
- walkTree(
1349
+ walkAppState(
1358
1350
  state,
1359
1351
  config,
1360
1352
  (content) => content,
@@ -1500,7 +1492,7 @@ init_react_import();
1500
1492
 
1501
1493
  // ../core/lib/data/map-slots.ts
1502
1494
  init_react_import();
1503
- function mapSlots(_0, _1) {
1495
+ function mapSlotsAsync(_0, _1) {
1504
1496
  return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
1505
1497
  const props = __spreadValues({}, item.props);
1506
1498
  const propKeys = Object.keys(props);
@@ -1511,7 +1503,7 @@ function mapSlots(_0, _1) {
1511
1503
  const content = props[propKey];
1512
1504
  const mappedContent = recursive ? yield Promise.all(
1513
1505
  content.map((item2) => __async(this, null, function* () {
1514
- return yield mapSlots(item2, map, recursive, isSlot2);
1506
+ return yield mapSlotsAsync(item2, map, recursive, isSlot2);
1515
1507
  }))
1516
1508
  ) : content;
1517
1509
  props[propKey] = yield map(mappedContent, propKey);
@@ -1539,14 +1531,14 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
1539
1531
  const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1540
1532
  changed,
1541
1533
  lastData: oldItem,
1542
- metadata,
1534
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1543
1535
  trigger
1544
1536
  });
1545
1537
  let resolvedItem = __spreadProps(__spreadValues({}, item), {
1546
1538
  props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1547
1539
  });
1548
1540
  if (recursive) {
1549
- resolvedItem = yield mapSlots(
1541
+ resolvedItem = yield mapSlotsAsync(
1550
1542
  resolvedItem,
1551
1543
  (content) => __async(void 0, null, function* () {
1552
1544
  return Promise.all(
@@ -1766,7 +1758,7 @@ var createAppStore = (initialAppStore) => create()(
1766
1758
  }),
1767
1759
  resolveAndCommitData: () => __async(void 0, null, function* () {
1768
1760
  const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1769
- walkTree(
1761
+ walkAppState(
1770
1762
  state,
1771
1763
  config,
1772
1764
  (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.896a6279",
4
- "author": "Measured Corporation Ltd <hello@measured.co>",
3
+ "version": "0.19.0-canary.8d459e4e",
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.896a6279",
28
+ "@measured/puck": "^0.19.0-canary.8d459e4e",
29
29
  "@types/react": "^19.0.1",
30
30
  "@types/react-dom": "^19.0.2",
31
31
  "eslint": "^7.32.0",