@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.mjs CHANGED
@@ -532,32 +532,27 @@ var walkField = ({
532
532
  config,
533
533
  recurseSlots = false
534
534
  }) => {
535
- var _a, _b, _c, _d, _e;
535
+ var _a, _b, _c;
536
536
  const fieldType = (_a = fields[propKey]) == null ? void 0 : _a.type;
537
537
  const map = mappers[fieldType];
538
538
  if (map && fieldType === "slot") {
539
539
  const content = value || [];
540
- let mappedContent = content;
541
- if (recurseSlots) {
542
- for (let i = 0; i < content.length; i++) {
543
- const el = content[i];
544
- const componentConfig = config.components[el.type];
545
- if (!componentConfig || !((_b = el.props) == null ? void 0 : _b.id)) {
546
- continue;
547
- }
548
- const fields2 = (_c = componentConfig.fields) != null ? _c : {};
549
- mappedContent.push(
550
- walkField({
551
- value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
552
- fields: fields2,
553
- mappers,
554
- id: el.props.id,
555
- config,
556
- recurseSlots
557
- })
558
- );
540
+ const mappedContent = recurseSlots ? content.map((el) => {
541
+ var _a2;
542
+ const componentConfig = config.components[el.type];
543
+ if (!componentConfig) {
544
+ throw new Error(`Could not find component config for ${el.type}`);
559
545
  }
560
- }
546
+ const fields2 = (_a2 = componentConfig.fields) != null ? _a2 : {};
547
+ return walkField({
548
+ value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
549
+ fields: fields2,
550
+ mappers,
551
+ id: el.props.id,
552
+ config,
553
+ recurseSlots
554
+ });
555
+ }) : content;
561
556
  if (containsPromise(mappedContent)) {
562
557
  return Promise.all(mappedContent);
563
558
  }
@@ -579,7 +574,7 @@ var walkField = ({
579
574
  }
580
575
  if (value && typeof value === "object") {
581
576
  if (Array.isArray(value)) {
582
- const arrayFields = ((_d = fields[propKey]) == null ? void 0 : _d.type) === "array" ? fields[propKey].arrayFields : null;
577
+ const arrayFields = ((_b = fields[propKey]) == null ? void 0 : _b.type) === "array" ? fields[propKey].arrayFields : null;
583
578
  if (!arrayFields) return value;
584
579
  const newValue = value.map(
585
580
  (el, idx) => walkField({
@@ -600,7 +595,7 @@ var walkField = ({
600
595
  } else if ("$$typeof" in value) {
601
596
  return value;
602
597
  } else {
603
- const objectFields = ((_e = fields[propKey]) == null ? void 0 : _e.type) === "object" ? fields[propKey].objectFields : fields;
598
+ const objectFields = ((_c = fields[propKey]) == null ? void 0 : _c.type) === "object" ? fields[propKey].objectFields : fields;
604
599
  return walkObject({
605
600
  value,
606
601
  fields: objectFields,
@@ -684,9 +679,28 @@ var stripSlots = (data, config) => {
684
679
 
685
680
  // ../core/lib/data/flatten-node.ts
686
681
  var { flatten: flatten2, unflatten } = import_flat.default;
682
+ function isEmptyArrayOrObject(val) {
683
+ if (Array.isArray(val)) {
684
+ return val.length === 0;
685
+ }
686
+ if (val != null && Object.prototype.toString.call(val) === "[object Object]") {
687
+ return Object.keys(val).length === 0;
688
+ }
689
+ return false;
690
+ }
691
+ function stripEmptyObjects(props) {
692
+ const result = {};
693
+ for (const key in props) {
694
+ if (!Object.prototype.hasOwnProperty.call(props, key)) continue;
695
+ const val = props[key];
696
+ if (isEmptyArrayOrObject(val)) continue;
697
+ result[key] = val;
698
+ }
699
+ return result;
700
+ }
687
701
  var flattenNode = (node, config) => {
688
702
  return __spreadProps(__spreadValues({}, node), {
689
- props: flatten2(stripSlots(node, config).props)
703
+ props: stripEmptyObjects(flatten2(stripSlots(node, config).props))
690
704
  });
691
705
  };
692
706
 
@@ -846,10 +860,10 @@ var insert = (list, index, item) => {
846
860
  // ../core/lib/generate-id.ts
847
861
  init_react_import();
848
862
 
849
- // ../../node_modules/uuid/dist/esm-node/index.js
863
+ // ../core/node_modules/uuid/dist/esm-node/index.js
850
864
  init_react_import();
851
865
 
852
- // ../../node_modules/uuid/dist/esm-node/rng.js
866
+ // ../core/node_modules/uuid/dist/esm-node/rng.js
853
867
  init_react_import();
854
868
  import crypto from "crypto";
855
869
  var rnds8Pool = new Uint8Array(256);
@@ -862,7 +876,7 @@ function rng() {
862
876
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
863
877
  }
864
878
 
865
- // ../../node_modules/uuid/dist/esm-node/stringify.js
879
+ // ../core/node_modules/uuid/dist/esm-node/stringify.js
866
880
  init_react_import();
867
881
  var byteToHex = [];
868
882
  for (let i = 0; i < 256; ++i) {
@@ -872,17 +886,17 @@ function unsafeStringify(arr, offset = 0) {
872
886
  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]];
873
887
  }
874
888
 
875
- // ../../node_modules/uuid/dist/esm-node/v4.js
889
+ // ../core/node_modules/uuid/dist/esm-node/v4.js
876
890
  init_react_import();
877
891
 
878
- // ../../node_modules/uuid/dist/esm-node/native.js
892
+ // ../core/node_modules/uuid/dist/esm-node/native.js
879
893
  init_react_import();
880
894
  import crypto2 from "crypto";
881
895
  var native_default = {
882
896
  randomUUID: crypto2.randomUUID
883
897
  };
884
898
 
885
- // ../../node_modules/uuid/dist/esm-node/v4.js
899
+ // ../core/node_modules/uuid/dist/esm-node/v4.js
886
900
  function v4(options, buf, offset) {
887
901
  if (native_default.randomUUID && !buf && !options) {
888
902
  return native_default.randomUUID();
@@ -1034,7 +1048,9 @@ var replaceAction = (state, action, appStore) => {
1034
1048
  });
1035
1049
  });
1036
1050
  });
1037
- const stateWithDeepSlotsRemoved = __spreadValues({}, state);
1051
+ const stateWithDeepSlotsRemoved = __spreadProps(__spreadValues({}, state), {
1052
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1053
+ });
1038
1054
  Object.keys(state.indexes.zones).forEach((zoneCompound) => {
1039
1055
  const id = zoneCompound.split(":")[0];
1040
1056
  if (id === originalId) {
@@ -1463,7 +1479,7 @@ var createStoreImpl = (createState) => {
1463
1479
  const initialState = state = createState(setState, getState, api);
1464
1480
  return api;
1465
1481
  };
1466
- var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
1482
+ var createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
1467
1483
 
1468
1484
  // ../../node_modules/zustand/esm/react.mjs
1469
1485
  init_react_import();
@@ -1472,8 +1488,8 @@ var identity = (arg) => arg;
1472
1488
  function useStore(api, selector = identity) {
1473
1489
  const slice = React2.useSyncExternalStore(
1474
1490
  api.subscribe,
1475
- () => selector(api.getState()),
1476
- () => selector(api.getInitialState())
1491
+ React2.useCallback(() => selector(api.getState()), [api, selector]),
1492
+ React2.useCallback(() => selector(api.getInitialState()), [api, selector])
1477
1493
  );
1478
1494
  React2.useDebugValue(slice);
1479
1495
  return slice;
@@ -1484,13 +1500,13 @@ var createImpl = (createState) => {
1484
1500
  Object.assign(useBoundStore, api);
1485
1501
  return useBoundStore;
1486
1502
  };
1487
- var create = (createState) => createState ? createImpl(createState) : createImpl;
1503
+ var create = ((createState) => createState ? createImpl(createState) : createImpl);
1488
1504
 
1489
1505
  // ../../node_modules/zustand/esm/middleware.mjs
1490
1506
  init_react_import();
1491
1507
  var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
1492
1508
  const origSubscribe = api.subscribe;
1493
- api.subscribe = (selector, optListener, options) => {
1509
+ api.subscribe = ((selector, optListener, options) => {
1494
1510
  let listener = selector;
1495
1511
  if (optListener) {
1496
1512
  const equalityFn = (options == null ? void 0 : options.equalityFn) || Object.is;
@@ -1507,7 +1523,7 @@ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
1507
1523
  }
1508
1524
  }
1509
1525
  return origSubscribe(listener);
1510
- };
1526
+ });
1511
1527
  const initialState = fn(set, get, api);
1512
1528
  return initialState;
1513
1529
  };
@@ -1547,9 +1563,9 @@ function debounce(func, timeout = 300) {
1547
1563
  var tidyState = (state) => {
1548
1564
  return __spreadProps(__spreadValues({}, state), {
1549
1565
  ui: __spreadProps(__spreadValues({}, state.ui), {
1550
- field: {
1566
+ field: __spreadProps(__spreadValues({}, state.ui.field), {
1551
1567
  focus: null
1552
- }
1568
+ })
1553
1569
  })
1554
1570
  });
1555
1571
  };
@@ -1724,9 +1740,9 @@ function createIsCircular(areItemsEqual) {
1724
1740
  function getStrictProperties(object) {
1725
1741
  return getOwnPropertyNames(object).concat(getOwnPropertySymbols(object));
1726
1742
  }
1727
- var hasOwn = Object.hasOwn || function(object, property) {
1743
+ var hasOwn = Object.hasOwn || (function(object, property) {
1728
1744
  return hasOwnProperty.call(object, property);
1729
- };
1745
+ });
1730
1746
  function sameValueZeroEqual(a, b) {
1731
1747
  return a === b || !a && !b && a !== a && b !== b;
1732
1748
  }
@@ -2116,29 +2132,37 @@ var getChanged = (newItem, oldItem) => {
2116
2132
 
2117
2133
  // ../core/store/slices/permissions.ts
2118
2134
  var createPermissionsSlice = (set, get) => {
2119
- const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
2135
+ const resolvePermissions = (..._0) => __async(null, [..._0], function* (params = {}, force) {
2120
2136
  const { state, permissions, config } = get();
2121
2137
  const { cache: cache2, globalPermissions } = permissions;
2122
- const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
2123
- var _a, _b, _c;
2138
+ const resolvePermissionsForItem = (item2, force2 = false) => __async(null, null, function* () {
2139
+ var _a, _b;
2124
2140
  const { config: config2, state: appState, setComponentLoading } = get();
2141
+ const itemCache = cache2[item2.props.id];
2142
+ const nodes = appState.indexes.nodes;
2143
+ const parentId = (_a = nodes[item2.props.id]) == null ? void 0 : _a.parentId;
2144
+ const parentNode = parentId ? nodes[parentId] : null;
2145
+ const parentData = (_b = parentNode == null ? void 0 : parentNode.data) != null ? _b : null;
2125
2146
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
2126
2147
  if (!componentConfig) {
2127
2148
  return;
2128
2149
  }
2129
2150
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
2130
2151
  if (componentConfig.resolvePermissions) {
2131
- const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
2132
- if (Object.values(changed).some((el) => el === true) || force2) {
2152
+ const changed = getChanged(item2, itemCache == null ? void 0 : itemCache.lastData);
2153
+ const propsChanged = Object.values(changed).some((el) => el === true);
2154
+ const parentChanged = (itemCache == null ? void 0 : itemCache.lastParentId) !== parentId;
2155
+ if (propsChanged || parentChanged || force2) {
2133
2156
  const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
2134
2157
  const resolvedPermissions = yield componentConfig.resolvePermissions(
2135
2158
  item2,
2136
2159
  {
2137
2160
  changed,
2138
- lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
2161
+ lastPermissions: (itemCache == null ? void 0 : itemCache.lastPermissions) || null,
2139
2162
  permissions: initialPermissions,
2140
2163
  appState: makeStatePublic(appState),
2141
- lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
2164
+ lastData: (itemCache == null ? void 0 : itemCache.lastData) || null,
2165
+ parent: parentData
2142
2166
  }
2143
2167
  );
2144
2168
  const latest = get().permissions;
@@ -2146,6 +2170,7 @@ var createPermissionsSlice = (set, get) => {
2146
2170
  permissions: __spreadProps(__spreadValues({}, latest), {
2147
2171
  cache: __spreadProps(__spreadValues({}, latest.cache), {
2148
2172
  [item2.props.id]: {
2173
+ lastParentId: parentId,
2149
2174
  lastData: item2,
2150
2175
  lastPermissions: resolvedPermissions
2151
2176
  }
@@ -2159,9 +2184,9 @@ var createPermissionsSlice = (set, get) => {
2159
2184
  }
2160
2185
  }
2161
2186
  });
2162
- const resolveDataForRoot = (force2 = false) => {
2187
+ const resolvePermissionsForRoot = (force2 = false) => {
2163
2188
  const { state: appState } = get();
2164
- resolveDataForItem(
2189
+ resolvePermissionsForItem(
2165
2190
  // Shim the root data in by conforming to component data shape
2166
2191
  {
2167
2192
  type: "root",
@@ -2172,16 +2197,16 @@ var createPermissionsSlice = (set, get) => {
2172
2197
  };
2173
2198
  const { item, type, root } = params;
2174
2199
  if (item) {
2175
- yield resolveDataForItem(item, force);
2200
+ yield resolvePermissionsForItem(item, force);
2176
2201
  } else if (type) {
2177
- flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
2178
- yield resolveDataForItem(item2, force);
2202
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(null, null, function* () {
2203
+ yield resolvePermissionsForItem(item2, force);
2179
2204
  }));
2180
2205
  } else if (root) {
2181
- resolveDataForRoot(force);
2206
+ resolvePermissionsForRoot(force);
2182
2207
  } else {
2183
- flattenData(state, config).map((item2) => __async(void 0, null, function* () {
2184
- yield resolveDataForItem(item2, force);
2208
+ flattenData(state, config).map((item2) => __async(null, null, function* () {
2209
+ yield resolvePermissionsForItem(item2, force);
2185
2210
  }));
2186
2211
  }
2187
2212
  });
@@ -2235,7 +2260,7 @@ var createFieldsSlice = (_set, _get) => {
2235
2260
  // ../core/lib/resolve-component-data.ts
2236
2261
  init_react_import();
2237
2262
  var cache = { lastChange: {} };
2238
- var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
2263
+ var resolveComponentData = (_0, _1, ..._2) => __async(null, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
2239
2264
  const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
2240
2265
  const resolvedItem = __spreadValues({}, item);
2241
2266
  const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
@@ -2263,11 +2288,11 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
2263
2288
  let itemWithResolvedChildren = yield mapFields(
2264
2289
  resolvedItem,
2265
2290
  {
2266
- slot: (_02) => __async(void 0, [_02], function* ({ value }) {
2291
+ slot: (_02) => __async(null, [_02], function* ({ value }) {
2267
2292
  const content = value;
2268
2293
  return yield Promise.all(
2269
2294
  content.map(
2270
- (childItem) => __async(void 0, null, function* () {
2295
+ (childItem) => __async(null, null, function* () {
2271
2296
  return (yield resolveComponentData(
2272
2297
  childItem,
2273
2298
  config,
@@ -2371,6 +2396,11 @@ var createAppStore = (initialAppStore) => create()(
2371
2396
  history: createHistorySlice(set, get),
2372
2397
  nodes: createNodesSlice(set, get),
2373
2398
  permissions: createPermissionsSlice(set, get),
2399
+ getCurrentData: () => {
2400
+ var _a2;
2401
+ const s = get();
2402
+ return (_a2 = s.selectedItem) != null ? _a2 : s.state.data.root;
2403
+ },
2374
2404
  getComponentConfig: (type) => {
2375
2405
  var _a2;
2376
2406
  const { config, selectedItem } = get();
@@ -2459,7 +2489,7 @@ var createAppStore = (initialAppStore) => create()(
2459
2489
  const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
2460
2490
  return __spreadProps(__spreadValues({}, s), { state, selectedItem });
2461
2491
  }),
2462
- resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
2492
+ resolveComponentData: (componentData, trigger) => __async(null, null, function* () {
2463
2493
  const { config, metadata, setComponentLoading, permissions } = get();
2464
2494
  const timeouts = {};
2465
2495
  return yield resolveComponentData(
@@ -2470,7 +2500,7 @@ var createAppStore = (initialAppStore) => create()(
2470
2500
  const id = "id" in item.props ? item.props.id : "root";
2471
2501
  timeouts[id] = setComponentLoading(id, true, 50);
2472
2502
  },
2473
- (item) => __async(void 0, null, function* () {
2503
+ (item) => __async(null, null, function* () {
2474
2504
  const id = "id" in item.props ? item.props.id : "root";
2475
2505
  if ("type" in item) {
2476
2506
  yield permissions.refreshPermissions({ item });
@@ -2482,7 +2512,7 @@ var createAppStore = (initialAppStore) => create()(
2482
2512
  trigger
2483
2513
  );
2484
2514
  }),
2485
- resolveAndCommitData: () => __async(void 0, null, function* () {
2515
+ resolveAndCommitData: () => __async(null, null, function* () {
2486
2516
  const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
2487
2517
  walkAppState(
2488
2518
  state,
@@ -2718,45 +2748,10 @@ classnames/index.js:
2718
2748
  *)
2719
2749
 
2720
2750
  lucide-react/dist/esm/shared/src/utils.js:
2721
- (**
2722
- * @license lucide-react v0.468.0 - ISC
2723
- *
2724
- * This source code is licensed under the ISC license.
2725
- * See the LICENSE file in the root directory of this source tree.
2726
- *)
2727
-
2728
2751
  lucide-react/dist/esm/defaultAttributes.js:
2729
- (**
2730
- * @license lucide-react v0.468.0 - ISC
2731
- *
2732
- * This source code is licensed under the ISC license.
2733
- * See the LICENSE file in the root directory of this source tree.
2734
- *)
2735
-
2736
2752
  lucide-react/dist/esm/Icon.js:
2737
- (**
2738
- * @license lucide-react v0.468.0 - ISC
2739
- *
2740
- * This source code is licensed under the ISC license.
2741
- * See the LICENSE file in the root directory of this source tree.
2742
- *)
2743
-
2744
2753
  lucide-react/dist/esm/createLucideIcon.js:
2745
- (**
2746
- * @license lucide-react v0.468.0 - ISC
2747
- *
2748
- * This source code is licensed under the ISC license.
2749
- * See the LICENSE file in the root directory of this source tree.
2750
- *)
2751
-
2752
2754
  lucide-react/dist/esm/icons/heading-1.js:
2753
- (**
2754
- * @license lucide-react v0.468.0 - ISC
2755
- *
2756
- * This source code is licensed under the ISC license.
2757
- * See the LICENSE file in the root directory of this source tree.
2758
- *)
2759
-
2760
2755
  lucide-react/dist/esm/lucide-react.js:
2761
2756
  (**
2762
2757
  * @license lucide-react v0.468.0 - ISC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck-plugin-heading-analyzer",
3
- "version": "0.21.0-canary.a3dabae1",
3
+ "version": "0.21.0-canary.a4bfae4f",
4
4
  "author": "Chris Villa <chris@puckeditor.com>",
5
5
  "repository": "measuredco/puck",
6
6
  "bugs": "https://github.com/measuredco/puck/issues",
@@ -25,7 +25,8 @@
25
25
  "dist"
26
26
  ],
27
27
  "devDependencies": {
28
- "@measured/puck": "^0.21.0-canary.a3dabae1",
28
+ "@measured/puck": "^0.21.0-canary.a4bfae4f",
29
+ "@types/minimatch": "3.0.5",
29
30
  "@types/react": "^19.0.1",
30
31
  "@types/react-dom": "^19.0.2",
31
32
  "eslint": "^7.32.0",