@measured/puck-plugin-heading-analyzer 0.10.0-canary.ca4f4be → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/dist/index.js +177 -25
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
8
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
9
  var __getProtoOf = Object.getPrototypeOf;
@@ -19,6 +21,7 @@ var __spreadValues = (a, b) => {
19
21
  }
20
22
  return a;
21
23
  };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
25
  var __esm = (fn, res) => function __init() {
23
26
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
24
27
  };
@@ -292,7 +295,7 @@ var require_react_is_development = __commonJS({
292
295
  var ContextProvider = REACT_PROVIDER_TYPE;
293
296
  var Element = REACT_ELEMENT_TYPE;
294
297
  var ForwardRef = REACT_FORWARD_REF_TYPE;
295
- var Fragment2 = REACT_FRAGMENT_TYPE;
298
+ var Fragment3 = REACT_FRAGMENT_TYPE;
296
299
  var Lazy = REACT_LAZY_TYPE;
297
300
  var Memo = REACT_MEMO_TYPE;
298
301
  var Portal = REACT_PORTAL_TYPE;
@@ -351,7 +354,7 @@ var require_react_is_development = __commonJS({
351
354
  exports.ContextProvider = ContextProvider;
352
355
  exports.Element = Element;
353
356
  exports.ForwardRef = ForwardRef;
354
- exports.Fragment = Fragment2;
357
+ exports.Fragment = Fragment3;
355
358
  exports.Lazy = Lazy;
356
359
  exports.Memo = Memo;
357
360
  exports.Portal = Portal;
@@ -1074,7 +1077,7 @@ init_react_import();
1074
1077
 
1075
1078
  // src/HeadingAnalyzer.tsx
1076
1079
  init_react_import();
1077
- var import_react3 = require("react");
1080
+ var import_react6 = require("react");
1078
1081
 
1079
1082
  // ../core/components/SidebarSection/index.tsx
1080
1083
  init_react_import();
@@ -1211,24 +1214,172 @@ ChevronRight.propTypes = {
1211
1214
  ChevronRight.displayName = "ChevronRight";
1212
1215
  var chevron_right_default = ChevronRight;
1213
1216
 
1217
+ // ../core/lib/use-breadcrumbs.ts
1218
+ init_react_import();
1219
+ var import_react5 = require("react");
1220
+
1221
+ // ../core/components/DropZone/context.tsx
1222
+ init_react_import();
1223
+ var import_react3 = require("react");
1224
+
1225
+ // ../core/lib/get-item.ts
1226
+ init_react_import();
1227
+
1228
+ // ../core/lib/root-droppable-id.ts
1229
+ init_react_import();
1230
+ var rootDroppableId = "default-zone";
1231
+
1232
+ // ../core/lib/setup-zone.ts
1233
+ init_react_import();
1234
+ var setupZone = (data, zoneKey) => {
1235
+ if (zoneKey === rootDroppableId) {
1236
+ return data;
1237
+ }
1238
+ const newData = __spreadValues({}, data);
1239
+ newData.zones = data.zones || {};
1240
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
1241
+ return newData;
1242
+ };
1243
+
1244
+ // ../core/lib/get-item.ts
1245
+ var getItem = (selector, data) => {
1246
+ if (!selector.zone || selector.zone === rootDroppableId) {
1247
+ return data.content[selector.index];
1248
+ }
1249
+ return setupZone(data, selector.zone).zones[selector.zone][selector.index];
1250
+ };
1251
+
1252
+ // ../core/lib/get-zone-id.ts
1253
+ init_react_import();
1254
+ var getZoneId = (zoneCompound) => {
1255
+ if (!zoneCompound) {
1256
+ return [];
1257
+ }
1258
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
1259
+ return zoneCompound.split(":");
1260
+ }
1261
+ return [rootDroppableId, zoneCompound];
1262
+ };
1263
+
1264
+ // ../core/components/DropZone/context.tsx
1265
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1266
+ var dropZoneContext = (0, import_react3.createContext)(null);
1267
+
1268
+ // ../core/components/Puck/context.tsx
1269
+ init_react_import();
1270
+ var import_react4 = require("react");
1271
+ var defaultAppState = {
1272
+ data: { content: [], root: { title: "" } },
1273
+ ui: {
1274
+ leftSideBarVisible: true,
1275
+ arrayState: {},
1276
+ itemSelector: null
1277
+ }
1278
+ };
1279
+ var appContext = (0, import_react4.createContext)({
1280
+ state: defaultAppState,
1281
+ dispatch: () => null
1282
+ });
1283
+ var AppProvider = appContext.Provider;
1284
+ var useAppContext = () => {
1285
+ const mainContext = (0, import_react4.useContext)(appContext);
1286
+ const selectedItem = mainContext.state.ui.itemSelector ? getItem(mainContext.state.ui.itemSelector, mainContext.state.data) : void 0;
1287
+ return __spreadProps(__spreadValues({}, mainContext), {
1288
+ // Helpers
1289
+ selectedItem,
1290
+ setUi: (ui, recordHistory) => {
1291
+ return mainContext.dispatch({
1292
+ type: "setUi",
1293
+ ui,
1294
+ recordHistory
1295
+ });
1296
+ }
1297
+ });
1298
+ };
1299
+
1300
+ // ../core/lib/use-breadcrumbs.ts
1301
+ var convertPathDataToBreadcrumbs = (selectedItem, pathData, data) => {
1302
+ const id = selectedItem ? selectedItem == null ? void 0 : selectedItem.props.id : "";
1303
+ const currentPathData = pathData && id && pathData[id] ? __spreadValues({}, pathData[id]) : { label: "Page", path: [] };
1304
+ if (!id) {
1305
+ return [];
1306
+ }
1307
+ return currentPathData == null ? void 0 : currentPathData.path.reduce((acc, zoneCompound) => {
1308
+ const [area] = getZoneId(zoneCompound);
1309
+ if (area === rootDroppableId) {
1310
+ return [
1311
+ {
1312
+ label: "Page",
1313
+ selector: null
1314
+ }
1315
+ ];
1316
+ }
1317
+ const parentZoneCompound = acc.length > 0 ? acc[acc.length - 1].zoneCompound : rootDroppableId;
1318
+ let parentZone = data.content;
1319
+ if (parentZoneCompound && parentZoneCompound !== rootDroppableId) {
1320
+ parentZone = data.zones[parentZoneCompound];
1321
+ }
1322
+ if (!parentZone) {
1323
+ return acc;
1324
+ }
1325
+ const itemIndex = parentZone.findIndex(
1326
+ (queryItem) => queryItem.props.id === area
1327
+ );
1328
+ const item = parentZone[itemIndex];
1329
+ if (!item) {
1330
+ return acc;
1331
+ }
1332
+ return [
1333
+ ...acc,
1334
+ {
1335
+ label: item.type.toString(),
1336
+ selector: {
1337
+ index: itemIndex,
1338
+ zone: parentZoneCompound
1339
+ },
1340
+ zoneCompound
1341
+ }
1342
+ ];
1343
+ }, []);
1344
+ };
1345
+ var useBreadcrumbs = (renderCount) => {
1346
+ const {
1347
+ state: { data },
1348
+ selectedItem
1349
+ } = useAppContext();
1350
+ const dzContext = (0, import_react5.useContext)(dropZoneContext);
1351
+ return (0, import_react5.useMemo)(() => {
1352
+ const breadcrumbs = convertPathDataToBreadcrumbs(
1353
+ selectedItem,
1354
+ dzContext == null ? void 0 : dzContext.pathData,
1355
+ data
1356
+ );
1357
+ if (renderCount) {
1358
+ return breadcrumbs.slice(breadcrumbs.length - renderCount);
1359
+ }
1360
+ return breadcrumbs;
1361
+ }, [selectedItem, dzContext == null ? void 0 : dzContext.pathData, renderCount]);
1362
+ };
1363
+
1214
1364
  // ../core/components/SidebarSection/index.tsx
1215
1365
  var getClassName2 = get_class_name_factory_default("SidebarSection", styles_module_default);
1216
1366
  var SidebarSection = ({
1217
1367
  children,
1218
1368
  title,
1219
1369
  background,
1220
- breadcrumbs = [],
1221
- breadcrumbClick,
1370
+ showBreadcrumbs,
1222
1371
  noPadding
1223
1372
  }) => {
1224
- return /* @__PURE__ */ import_react.default.createElement("div", { className: getClassName2({ noPadding }), style: { background } }, /* @__PURE__ */ import_react.default.createElement("div", { className: getClassName2("title") }, /* @__PURE__ */ import_react.default.createElement("div", { className: getClassName2("breadcrumbs") }, breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ import_react.default.createElement("div", { key: i, className: getClassName2("breadcrumb") }, /* @__PURE__ */ import_react.default.createElement(
1373
+ const { setUi } = useAppContext();
1374
+ const breadcrumbs = useBreadcrumbs(1);
1375
+ return /* @__PURE__ */ import_react.default.createElement("div", { className: getClassName2({ noPadding }), style: { background } }, /* @__PURE__ */ import_react.default.createElement("div", { className: getClassName2("title") }, /* @__PURE__ */ import_react.default.createElement("div", { className: getClassName2("breadcrumbs") }, showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ import_react.default.createElement("div", { key: i, className: getClassName2("breadcrumb") }, /* @__PURE__ */ import_react.default.createElement(
1225
1376
  "div",
1226
1377
  {
1227
1378
  className: getClassName2("breadcrumbLabel"),
1228
- onClick: () => breadcrumbClick && breadcrumbClick(breadcrumb)
1379
+ onClick: () => setUi({ itemSelector: breadcrumb.selector })
1229
1380
  },
1230
1381
  breadcrumb.label
1231
- ), /* @__PURE__ */ import_react.default.createElement(chevron_right_default, { size: 16 }))), /* @__PURE__ */ import_react.default.createElement("div", { className: getClassName2("heading") }, /* @__PURE__ */ import_react.default.createElement(Heading, { rank: 2, size: "xs" }, title)))), /* @__PURE__ */ import_react.default.createElement("div", { className: getClassName2("content") }, children));
1382
+ ), /* @__PURE__ */ import_react.default.createElement(chevron_right_default, { size: 16 }))) : null, /* @__PURE__ */ import_react.default.createElement("div", { className: getClassName2("heading") }, /* @__PURE__ */ import_react.default.createElement(Heading, { rank: 2, size: "xs" }, title)))), /* @__PURE__ */ import_react.default.createElement("div", { className: getClassName2("content") }, children));
1232
1383
  };
1233
1384
 
1234
1385
  // ../core/components/OutlineList/index.tsx
@@ -1272,7 +1423,7 @@ var scrollIntoView = (el) => {
1272
1423
 
1273
1424
  // src/HeadingAnalyzer.tsx
1274
1425
  var import_react_from_json = __toESM(require("react-from-json"));
1275
- var import_jsx_runtime2 = require("react/jsx-runtime");
1426
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1276
1427
  var dataAttr = "data-puck-heading-analyzer-id";
1277
1428
  var getOutline = ({
1278
1429
  addDataAttr = false
@@ -1327,11 +1478,12 @@ function buildHierarchy() {
1327
1478
  }
1328
1479
  var HeadingOutlineAnalyer = ({
1329
1480
  children,
1330
- data
1481
+ state
1331
1482
  }) => {
1332
- const [hierarchy, setHierarchy] = (0, import_react3.useState)([]);
1333
- const [firstRender, setFirstRender] = (0, import_react3.useState)(true);
1334
- (0, import_react3.useEffect)(() => {
1483
+ const { data } = state;
1484
+ const [hierarchy, setHierarchy] = (0, import_react6.useState)([]);
1485
+ const [firstRender, setFirstRender] = (0, import_react6.useState)(true);
1486
+ (0, import_react6.useEffect)(() => {
1335
1487
  if (firstRender) {
1336
1488
  setTimeout(() => {
1337
1489
  setHierarchy(buildHierarchy());
@@ -1341,17 +1493,17 @@ var HeadingOutlineAnalyer = ({
1341
1493
  setHierarchy(buildHierarchy());
1342
1494
  }
1343
1495
  }, [data.content]);
1344
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1496
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1345
1497
  children,
1346
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(SidebarSection, { title: "Heading Outline", children: [
1347
- hierarchy.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: "No headings." }),
1348
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OutlineList, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1498
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(SidebarSection, { title: "Heading Outline", children: [
1499
+ hierarchy.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: "No headings." }),
1500
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(OutlineList, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1349
1501
  import_react_from_json.default,
1350
1502
  {
1351
1503
  mapping: {
1352
- Root: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: props.children }),
1353
- OutlineListItem: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(OutlineList.Item, { children: [
1354
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OutlineList.Clickable, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1504
+ Root: (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: props.children }),
1505
+ OutlineListItem: (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(OutlineList.Item, { children: [
1506
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(OutlineList.Clickable, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1355
1507
  "small",
1356
1508
  {
1357
1509
  onClick: typeof props.analyzeId == "undefined" ? void 0 : (e) => {
@@ -1370,14 +1522,14 @@ var HeadingOutlineAnalyer = ({
1370
1522
  }, 2e3);
1371
1523
  }
1372
1524
  },
1373
- children: props.missing ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: { color: "var(--puck-color-red)" }, children: [
1374
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("b", { children: [
1525
+ children: props.missing ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { color: "var(--puck-color-red)" }, children: [
1526
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("b", { children: [
1375
1527
  "H",
1376
1528
  props.rank
1377
1529
  ] }),
1378
1530
  ": Missing"
1379
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
1380
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("b", { children: [
1531
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
1532
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("b", { children: [
1381
1533
  "H",
1382
1534
  props.rank
1383
1535
  ] }),
@@ -1386,7 +1538,7 @@ var HeadingOutlineAnalyer = ({
1386
1538
  ] })
1387
1539
  }
1388
1540
  ) }),
1389
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OutlineList, { children: props.children })
1541
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(OutlineList, { children: props.children })
1390
1542
  ] })
1391
1543
  },
1392
1544
  entry: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck-plugin-heading-analyzer",
3
- "version": "0.10.0-canary.ca4f4be",
3
+ "version": "0.10.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "dist"
15
15
  ],
16
16
  "devDependencies": {
17
- "@measured/puck": "^0.10.0-canary.ca4f4be",
17
+ "@measured/puck": "^0.10.0",
18
18
  "@types/react": "^18.2.0",
19
19
  "@types/react-dom": "^18.2.0",
20
20
  "eslint": "^7.32.0",