@measured/puck-plugin-heading-analyzer 0.21.0-canary.a3dabae1 → 0.21.0-canary.a4bfae4f

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
@@ -268,11 +268,11 @@ var require_flat = __commonJS({
268
268
  });
269
269
 
270
270
  // index.ts
271
- var plugin_heading_analyzer_exports = {};
272
- __export(plugin_heading_analyzer_exports, {
271
+ var index_exports = {};
272
+ __export(index_exports, {
273
273
  default: () => HeadingAnalyzer_default
274
274
  });
275
- module.exports = __toCommonJS(plugin_heading_analyzer_exports);
275
+ module.exports = __toCommonJS(index_exports);
276
276
  init_react_import();
277
277
 
278
278
  // src/HeadingAnalyzer.tsx
@@ -544,32 +544,27 @@ var walkField = ({
544
544
  config,
545
545
  recurseSlots = false
546
546
  }) => {
547
- var _a, _b, _c, _d, _e;
547
+ var _a, _b, _c;
548
548
  const fieldType = (_a = fields[propKey]) == null ? void 0 : _a.type;
549
549
  const map = mappers[fieldType];
550
550
  if (map && fieldType === "slot") {
551
551
  const content = value || [];
552
- let mappedContent = content;
553
- if (recurseSlots) {
554
- for (let i = 0; i < content.length; i++) {
555
- const el = content[i];
556
- const componentConfig = config.components[el.type];
557
- if (!componentConfig || !((_b = el.props) == null ? void 0 : _b.id)) {
558
- continue;
559
- }
560
- const fields2 = (_c = componentConfig.fields) != null ? _c : {};
561
- mappedContent.push(
562
- walkField({
563
- value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
564
- fields: fields2,
565
- mappers,
566
- id: el.props.id,
567
- config,
568
- recurseSlots
569
- })
570
- );
552
+ const mappedContent = recurseSlots ? content.map((el) => {
553
+ var _a2;
554
+ const componentConfig = config.components[el.type];
555
+ if (!componentConfig) {
556
+ throw new Error(`Could not find component config for ${el.type}`);
571
557
  }
572
- }
558
+ const fields2 = (_a2 = componentConfig.fields) != null ? _a2 : {};
559
+ return walkField({
560
+ value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
561
+ fields: fields2,
562
+ mappers,
563
+ id: el.props.id,
564
+ config,
565
+ recurseSlots
566
+ });
567
+ }) : content;
573
568
  if (containsPromise(mappedContent)) {
574
569
  return Promise.all(mappedContent);
575
570
  }
@@ -591,7 +586,7 @@ var walkField = ({
591
586
  }
592
587
  if (value && typeof value === "object") {
593
588
  if (Array.isArray(value)) {
594
- const arrayFields = ((_d = fields[propKey]) == null ? void 0 : _d.type) === "array" ? fields[propKey].arrayFields : null;
589
+ const arrayFields = ((_b = fields[propKey]) == null ? void 0 : _b.type) === "array" ? fields[propKey].arrayFields : null;
595
590
  if (!arrayFields) return value;
596
591
  const newValue = value.map(
597
592
  (el, idx) => walkField({
@@ -612,7 +607,7 @@ var walkField = ({
612
607
  } else if ("$$typeof" in value) {
613
608
  return value;
614
609
  } else {
615
- const objectFields = ((_e = fields[propKey]) == null ? void 0 : _e.type) === "object" ? fields[propKey].objectFields : fields;
610
+ const objectFields = ((_c = fields[propKey]) == null ? void 0 : _c.type) === "object" ? fields[propKey].objectFields : fields;
616
611
  return walkObject({
617
612
  value,
618
613
  fields: objectFields,
@@ -696,9 +691,28 @@ var stripSlots = (data, config) => {
696
691
 
697
692
  // ../core/lib/data/flatten-node.ts
698
693
  var { flatten: flatten2, unflatten } = import_flat.default;
694
+ function isEmptyArrayOrObject(val) {
695
+ if (Array.isArray(val)) {
696
+ return val.length === 0;
697
+ }
698
+ if (val != null && Object.prototype.toString.call(val) === "[object Object]") {
699
+ return Object.keys(val).length === 0;
700
+ }
701
+ return false;
702
+ }
703
+ function stripEmptyObjects(props) {
704
+ const result = {};
705
+ for (const key in props) {
706
+ if (!Object.prototype.hasOwnProperty.call(props, key)) continue;
707
+ const val = props[key];
708
+ if (isEmptyArrayOrObject(val)) continue;
709
+ result[key] = val;
710
+ }
711
+ return result;
712
+ }
699
713
  var flattenNode = (node, config) => {
700
714
  return __spreadProps(__spreadValues({}, node), {
701
- props: flatten2(stripSlots(node, config).props)
715
+ props: stripEmptyObjects(flatten2(stripSlots(node, config).props))
702
716
  });
703
717
  };
704
718
 
@@ -858,10 +872,10 @@ var insert = (list, index, item) => {
858
872
  // ../core/lib/generate-id.ts
859
873
  init_react_import();
860
874
 
861
- // ../../node_modules/uuid/dist/esm-node/index.js
875
+ // ../core/node_modules/uuid/dist/esm-node/index.js
862
876
  init_react_import();
863
877
 
864
- // ../../node_modules/uuid/dist/esm-node/rng.js
878
+ // ../core/node_modules/uuid/dist/esm-node/rng.js
865
879
  init_react_import();
866
880
  var import_crypto = __toESM(require("crypto"));
867
881
  var rnds8Pool = new Uint8Array(256);
@@ -874,7 +888,7 @@ function rng() {
874
888
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
875
889
  }
876
890
 
877
- // ../../node_modules/uuid/dist/esm-node/stringify.js
891
+ // ../core/node_modules/uuid/dist/esm-node/stringify.js
878
892
  init_react_import();
879
893
  var byteToHex = [];
880
894
  for (let i = 0; i < 256; ++i) {
@@ -884,17 +898,17 @@ function unsafeStringify(arr, offset = 0) {
884
898
  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]];
885
899
  }
886
900
 
887
- // ../../node_modules/uuid/dist/esm-node/v4.js
901
+ // ../core/node_modules/uuid/dist/esm-node/v4.js
888
902
  init_react_import();
889
903
 
890
- // ../../node_modules/uuid/dist/esm-node/native.js
904
+ // ../core/node_modules/uuid/dist/esm-node/native.js
891
905
  init_react_import();
892
906
  var import_crypto2 = __toESM(require("crypto"));
893
907
  var native_default = {
894
908
  randomUUID: import_crypto2.default.randomUUID
895
909
  };
896
910
 
897
- // ../../node_modules/uuid/dist/esm-node/v4.js
911
+ // ../core/node_modules/uuid/dist/esm-node/v4.js
898
912
  function v4(options, buf, offset) {
899
913
  if (native_default.randomUUID && !buf && !options) {
900
914
  return native_default.randomUUID();
@@ -1046,7 +1060,9 @@ var replaceAction = (state, action, appStore) => {
1046
1060
  });
1047
1061
  });
1048
1062
  });
1049
- const stateWithDeepSlotsRemoved = __spreadValues({}, state);
1063
+ const stateWithDeepSlotsRemoved = __spreadProps(__spreadValues({}, state), {
1064
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1065
+ });
1050
1066
  Object.keys(state.indexes.zones).forEach((zoneCompound) => {
1051
1067
  const id = zoneCompound.split(":")[0];
1052
1068
  if (id === originalId) {
@@ -1475,7 +1491,7 @@ var createStoreImpl = (createState) => {
1475
1491
  const initialState = state = createState(setState, getState, api);
1476
1492
  return api;
1477
1493
  };
1478
- var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
1494
+ var createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
1479
1495
 
1480
1496
  // ../../node_modules/zustand/esm/react.mjs
1481
1497
  init_react_import();
@@ -1484,8 +1500,8 @@ var identity = (arg) => arg;
1484
1500
  function useStore(api, selector = identity) {
1485
1501
  const slice = import_react4.default.useSyncExternalStore(
1486
1502
  api.subscribe,
1487
- () => selector(api.getState()),
1488
- () => selector(api.getInitialState())
1503
+ import_react4.default.useCallback(() => selector(api.getState()), [api, selector]),
1504
+ import_react4.default.useCallback(() => selector(api.getInitialState()), [api, selector])
1489
1505
  );
1490
1506
  import_react4.default.useDebugValue(slice);
1491
1507
  return slice;
@@ -1496,13 +1512,13 @@ var createImpl = (createState) => {
1496
1512
  Object.assign(useBoundStore, api);
1497
1513
  return useBoundStore;
1498
1514
  };
1499
- var create = (createState) => createState ? createImpl(createState) : createImpl;
1515
+ var create = ((createState) => createState ? createImpl(createState) : createImpl);
1500
1516
 
1501
1517
  // ../../node_modules/zustand/esm/middleware.mjs
1502
1518
  init_react_import();
1503
1519
  var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
1504
1520
  const origSubscribe = api.subscribe;
1505
- api.subscribe = (selector, optListener, options) => {
1521
+ api.subscribe = ((selector, optListener, options) => {
1506
1522
  let listener = selector;
1507
1523
  if (optListener) {
1508
1524
  const equalityFn = (options == null ? void 0 : options.equalityFn) || Object.is;
@@ -1519,7 +1535,7 @@ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
1519
1535
  }
1520
1536
  }
1521
1537
  return origSubscribe(listener);
1522
- };
1538
+ });
1523
1539
  const initialState = fn(set, get, api);
1524
1540
  return initialState;
1525
1541
  };
@@ -1559,9 +1575,9 @@ function debounce(func, timeout = 300) {
1559
1575
  var tidyState = (state) => {
1560
1576
  return __spreadProps(__spreadValues({}, state), {
1561
1577
  ui: __spreadProps(__spreadValues({}, state.ui), {
1562
- field: {
1578
+ field: __spreadProps(__spreadValues({}, state.ui.field), {
1563
1579
  focus: null
1564
- }
1580
+ })
1565
1581
  })
1566
1582
  });
1567
1583
  };
@@ -1736,9 +1752,9 @@ function createIsCircular(areItemsEqual) {
1736
1752
  function getStrictProperties(object) {
1737
1753
  return getOwnPropertyNames(object).concat(getOwnPropertySymbols(object));
1738
1754
  }
1739
- var hasOwn = Object.hasOwn || function(object, property) {
1755
+ var hasOwn = Object.hasOwn || (function(object, property) {
1740
1756
  return hasOwnProperty.call(object, property);
1741
- };
1757
+ });
1742
1758
  function sameValueZeroEqual(a, b) {
1743
1759
  return a === b || !a && !b && a !== a && b !== b;
1744
1760
  }
@@ -2128,29 +2144,37 @@ var getChanged = (newItem, oldItem) => {
2128
2144
 
2129
2145
  // ../core/store/slices/permissions.ts
2130
2146
  var createPermissionsSlice = (set, get) => {
2131
- const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
2147
+ const resolvePermissions = (..._0) => __async(null, [..._0], function* (params = {}, force) {
2132
2148
  const { state, permissions, config } = get();
2133
2149
  const { cache: cache2, globalPermissions } = permissions;
2134
- const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
2135
- var _a, _b, _c;
2150
+ const resolvePermissionsForItem = (item2, force2 = false) => __async(null, null, function* () {
2151
+ var _a, _b;
2136
2152
  const { config: config2, state: appState, setComponentLoading } = get();
2153
+ const itemCache = cache2[item2.props.id];
2154
+ const nodes = appState.indexes.nodes;
2155
+ const parentId = (_a = nodes[item2.props.id]) == null ? void 0 : _a.parentId;
2156
+ const parentNode = parentId ? nodes[parentId] : null;
2157
+ const parentData = (_b = parentNode == null ? void 0 : parentNode.data) != null ? _b : null;
2137
2158
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
2138
2159
  if (!componentConfig) {
2139
2160
  return;
2140
2161
  }
2141
2162
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
2142
2163
  if (componentConfig.resolvePermissions) {
2143
- const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
2144
- if (Object.values(changed).some((el) => el === true) || force2) {
2164
+ const changed = getChanged(item2, itemCache == null ? void 0 : itemCache.lastData);
2165
+ const propsChanged = Object.values(changed).some((el) => el === true);
2166
+ const parentChanged = (itemCache == null ? void 0 : itemCache.lastParentId) !== parentId;
2167
+ if (propsChanged || parentChanged || force2) {
2145
2168
  const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
2146
2169
  const resolvedPermissions = yield componentConfig.resolvePermissions(
2147
2170
  item2,
2148
2171
  {
2149
2172
  changed,
2150
- lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
2173
+ lastPermissions: (itemCache == null ? void 0 : itemCache.lastPermissions) || null,
2151
2174
  permissions: initialPermissions,
2152
2175
  appState: makeStatePublic(appState),
2153
- lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
2176
+ lastData: (itemCache == null ? void 0 : itemCache.lastData) || null,
2177
+ parent: parentData
2154
2178
  }
2155
2179
  );
2156
2180
  const latest = get().permissions;
@@ -2158,6 +2182,7 @@ var createPermissionsSlice = (set, get) => {
2158
2182
  permissions: __spreadProps(__spreadValues({}, latest), {
2159
2183
  cache: __spreadProps(__spreadValues({}, latest.cache), {
2160
2184
  [item2.props.id]: {
2185
+ lastParentId: parentId,
2161
2186
  lastData: item2,
2162
2187
  lastPermissions: resolvedPermissions
2163
2188
  }
@@ -2171,9 +2196,9 @@ var createPermissionsSlice = (set, get) => {
2171
2196
  }
2172
2197
  }
2173
2198
  });
2174
- const resolveDataForRoot = (force2 = false) => {
2199
+ const resolvePermissionsForRoot = (force2 = false) => {
2175
2200
  const { state: appState } = get();
2176
- resolveDataForItem(
2201
+ resolvePermissionsForItem(
2177
2202
  // Shim the root data in by conforming to component data shape
2178
2203
  {
2179
2204
  type: "root",
@@ -2184,16 +2209,16 @@ var createPermissionsSlice = (set, get) => {
2184
2209
  };
2185
2210
  const { item, type, root } = params;
2186
2211
  if (item) {
2187
- yield resolveDataForItem(item, force);
2212
+ yield resolvePermissionsForItem(item, force);
2188
2213
  } else if (type) {
2189
- flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
2190
- yield resolveDataForItem(item2, force);
2214
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(null, null, function* () {
2215
+ yield resolvePermissionsForItem(item2, force);
2191
2216
  }));
2192
2217
  } else if (root) {
2193
- resolveDataForRoot(force);
2218
+ resolvePermissionsForRoot(force);
2194
2219
  } else {
2195
- flattenData(state, config).map((item2) => __async(void 0, null, function* () {
2196
- yield resolveDataForItem(item2, force);
2220
+ flattenData(state, config).map((item2) => __async(null, null, function* () {
2221
+ yield resolvePermissionsForItem(item2, force);
2197
2222
  }));
2198
2223
  }
2199
2224
  });
@@ -2247,7 +2272,7 @@ var createFieldsSlice = (_set, _get) => {
2247
2272
  // ../core/lib/resolve-component-data.ts
2248
2273
  init_react_import();
2249
2274
  var cache = { lastChange: {} };
2250
- var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
2275
+ var resolveComponentData = (_0, _1, ..._2) => __async(null, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
2251
2276
  const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
2252
2277
  const resolvedItem = __spreadValues({}, item);
2253
2278
  const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
@@ -2275,11 +2300,11 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
2275
2300
  let itemWithResolvedChildren = yield mapFields(
2276
2301
  resolvedItem,
2277
2302
  {
2278
- slot: (_02) => __async(void 0, [_02], function* ({ value }) {
2303
+ slot: (_02) => __async(null, [_02], function* ({ value }) {
2279
2304
  const content = value;
2280
2305
  return yield Promise.all(
2281
2306
  content.map(
2282
- (childItem) => __async(void 0, null, function* () {
2307
+ (childItem) => __async(null, null, function* () {
2283
2308
  return (yield resolveComponentData(
2284
2309
  childItem,
2285
2310
  config,
@@ -2383,6 +2408,11 @@ var createAppStore = (initialAppStore) => create()(
2383
2408
  history: createHistorySlice(set, get),
2384
2409
  nodes: createNodesSlice(set, get),
2385
2410
  permissions: createPermissionsSlice(set, get),
2411
+ getCurrentData: () => {
2412
+ var _a2;
2413
+ const s = get();
2414
+ return (_a2 = s.selectedItem) != null ? _a2 : s.state.data.root;
2415
+ },
2386
2416
  getComponentConfig: (type) => {
2387
2417
  var _a2;
2388
2418
  const { config, selectedItem } = get();
@@ -2471,7 +2501,7 @@ var createAppStore = (initialAppStore) => create()(
2471
2501
  const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
2472
2502
  return __spreadProps(__spreadValues({}, s), { state, selectedItem });
2473
2503
  }),
2474
- resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
2504
+ resolveComponentData: (componentData, trigger) => __async(null, null, function* () {
2475
2505
  const { config, metadata, setComponentLoading, permissions } = get();
2476
2506
  const timeouts = {};
2477
2507
  return yield resolveComponentData(
@@ -2482,7 +2512,7 @@ var createAppStore = (initialAppStore) => create()(
2482
2512
  const id = "id" in item.props ? item.props.id : "root";
2483
2513
  timeouts[id] = setComponentLoading(id, true, 50);
2484
2514
  },
2485
- (item) => __async(void 0, null, function* () {
2515
+ (item) => __async(null, null, function* () {
2486
2516
  const id = "id" in item.props ? item.props.id : "root";
2487
2517
  if ("type" in item) {
2488
2518
  yield permissions.refreshPermissions({ item });
@@ -2494,7 +2524,7 @@ var createAppStore = (initialAppStore) => create()(
2494
2524
  trigger
2495
2525
  );
2496
2526
  }),
2497
- resolveAndCommitData: () => __async(void 0, null, function* () {
2527
+ resolveAndCommitData: () => __async(null, null, function* () {
2498
2528
  const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
2499
2529
  walkAppState(
2500
2530
  state,
@@ -2727,45 +2757,10 @@ classnames/index.js:
2727
2757
  *)
2728
2758
 
2729
2759
  lucide-react/dist/esm/shared/src/utils.js:
2730
- (**
2731
- * @license lucide-react v0.468.0 - ISC
2732
- *
2733
- * This source code is licensed under the ISC license.
2734
- * See the LICENSE file in the root directory of this source tree.
2735
- *)
2736
-
2737
2760
  lucide-react/dist/esm/defaultAttributes.js:
2738
- (**
2739
- * @license lucide-react v0.468.0 - ISC
2740
- *
2741
- * This source code is licensed under the ISC license.
2742
- * See the LICENSE file in the root directory of this source tree.
2743
- *)
2744
-
2745
2761
  lucide-react/dist/esm/Icon.js:
2746
- (**
2747
- * @license lucide-react v0.468.0 - ISC
2748
- *
2749
- * This source code is licensed under the ISC license.
2750
- * See the LICENSE file in the root directory of this source tree.
2751
- *)
2752
-
2753
2762
  lucide-react/dist/esm/createLucideIcon.js:
2754
- (**
2755
- * @license lucide-react v0.468.0 - ISC
2756
- *
2757
- * This source code is licensed under the ISC license.
2758
- * See the LICENSE file in the root directory of this source tree.
2759
- *)
2760
-
2761
2763
  lucide-react/dist/esm/icons/heading-1.js:
2762
- (**
2763
- * @license lucide-react v0.468.0 - ISC
2764
- *
2765
- * This source code is licensed under the ISC license.
2766
- * See the LICENSE file in the root directory of this source tree.
2767
- *)
2768
-
2769
2764
  lucide-react/dist/esm/lucide-react.js:
2770
2765
  (**
2771
2766
  * @license lucide-react v0.468.0 - ISC