@measured/puck-plugin-heading-analyzer 0.10.0-canary.2a12826 → 0.10.0-canary.6a9145c
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 +174 -24
- 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
|
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 =
|
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
|
1080
|
+
var import_react6 = require("react");
|
1078
1081
|
|
1079
1082
|
// ../core/components/SidebarSection/index.tsx
|
1080
1083
|
init_react_import();
|
@@ -1211,24 +1214,171 @@ 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 defaultAppData = {
|
1272
|
+
data: { content: [], root: { title: "" } },
|
1273
|
+
state: {
|
1274
|
+
leftSideBarVisible: true,
|
1275
|
+
arrayState: {}
|
1276
|
+
}
|
1277
|
+
};
|
1278
|
+
var appContext = (0, import_react4.createContext)({
|
1279
|
+
appData: defaultAppData,
|
1280
|
+
dispatch: () => null
|
1281
|
+
});
|
1282
|
+
var AppProvider = appContext.Provider;
|
1283
|
+
var useAppContext = () => {
|
1284
|
+
const mainContext = (0, import_react4.useContext)(appContext);
|
1285
|
+
const selectedItem = mainContext.appData.state.itemSelector ? getItem(mainContext.appData.state.itemSelector, mainContext.appData.data) : void 0;
|
1286
|
+
return __spreadProps(__spreadValues({}, mainContext), {
|
1287
|
+
// Helpers
|
1288
|
+
selectedItem,
|
1289
|
+
setState: (state, recordHistory) => {
|
1290
|
+
return mainContext.dispatch({
|
1291
|
+
type: "setState",
|
1292
|
+
state,
|
1293
|
+
recordHistory
|
1294
|
+
});
|
1295
|
+
}
|
1296
|
+
});
|
1297
|
+
};
|
1298
|
+
|
1299
|
+
// ../core/lib/use-breadcrumbs.ts
|
1300
|
+
var convertPathDataToBreadcrumbs = (selectedItem, pathData, data) => {
|
1301
|
+
const id = selectedItem ? selectedItem == null ? void 0 : selectedItem.props.id : "";
|
1302
|
+
const currentPathData = pathData && id && pathData[id] ? __spreadValues({}, pathData[id]) : { label: "Page", path: [] };
|
1303
|
+
if (!id) {
|
1304
|
+
return [];
|
1305
|
+
}
|
1306
|
+
return currentPathData == null ? void 0 : currentPathData.path.reduce((acc, zoneCompound) => {
|
1307
|
+
const [area] = getZoneId(zoneCompound);
|
1308
|
+
if (area === rootDroppableId) {
|
1309
|
+
return [
|
1310
|
+
{
|
1311
|
+
label: "Page",
|
1312
|
+
selector: null
|
1313
|
+
}
|
1314
|
+
];
|
1315
|
+
}
|
1316
|
+
const parentZoneCompound = acc.length > 0 ? acc[acc.length - 1].zoneCompound : rootDroppableId;
|
1317
|
+
let parentZone = data.content;
|
1318
|
+
if (parentZoneCompound && parentZoneCompound !== rootDroppableId) {
|
1319
|
+
parentZone = data.zones[parentZoneCompound];
|
1320
|
+
}
|
1321
|
+
if (!parentZone) {
|
1322
|
+
return acc;
|
1323
|
+
}
|
1324
|
+
const itemIndex = parentZone.findIndex(
|
1325
|
+
(queryItem) => queryItem.props.id === area
|
1326
|
+
);
|
1327
|
+
const item = parentZone[itemIndex];
|
1328
|
+
if (!item) {
|
1329
|
+
return acc;
|
1330
|
+
}
|
1331
|
+
return [
|
1332
|
+
...acc,
|
1333
|
+
{
|
1334
|
+
label: item.type.toString(),
|
1335
|
+
selector: {
|
1336
|
+
index: itemIndex,
|
1337
|
+
zone: parentZoneCompound
|
1338
|
+
},
|
1339
|
+
zoneCompound
|
1340
|
+
}
|
1341
|
+
];
|
1342
|
+
}, []);
|
1343
|
+
};
|
1344
|
+
var useBreadcrumbs = (renderCount) => {
|
1345
|
+
const {
|
1346
|
+
appData: { data },
|
1347
|
+
selectedItem
|
1348
|
+
} = useAppContext();
|
1349
|
+
const dzContext = (0, import_react5.useContext)(dropZoneContext);
|
1350
|
+
return (0, import_react5.useMemo)(() => {
|
1351
|
+
const breadcrumbs = convertPathDataToBreadcrumbs(
|
1352
|
+
selectedItem,
|
1353
|
+
dzContext == null ? void 0 : dzContext.pathData,
|
1354
|
+
data
|
1355
|
+
);
|
1356
|
+
if (renderCount) {
|
1357
|
+
return breadcrumbs.slice(breadcrumbs.length - renderCount);
|
1358
|
+
}
|
1359
|
+
return breadcrumbs;
|
1360
|
+
}, [selectedItem, dzContext == null ? void 0 : dzContext.pathData, renderCount]);
|
1361
|
+
};
|
1362
|
+
|
1214
1363
|
// ../core/components/SidebarSection/index.tsx
|
1215
1364
|
var getClassName2 = get_class_name_factory_default("SidebarSection", styles_module_default);
|
1216
1365
|
var SidebarSection = ({
|
1217
1366
|
children,
|
1218
1367
|
title,
|
1219
1368
|
background,
|
1220
|
-
|
1221
|
-
breadcrumbClick,
|
1369
|
+
showBreadcrumbs,
|
1222
1370
|
noPadding
|
1223
1371
|
}) => {
|
1224
|
-
|
1372
|
+
const { setState } = useAppContext();
|
1373
|
+
const breadcrumbs = useBreadcrumbs(1);
|
1374
|
+
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
1375
|
"div",
|
1226
1376
|
{
|
1227
1377
|
className: getClassName2("breadcrumbLabel"),
|
1228
|
-
onClick: () =>
|
1378
|
+
onClick: () => setState({ itemSelector: breadcrumb.selector })
|
1229
1379
|
},
|
1230
1380
|
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));
|
1381
|
+
), /* @__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
1382
|
};
|
1233
1383
|
|
1234
1384
|
// ../core/components/OutlineList/index.tsx
|
@@ -1272,7 +1422,7 @@ var scrollIntoView = (el) => {
|
|
1272
1422
|
|
1273
1423
|
// src/HeadingAnalyzer.tsx
|
1274
1424
|
var import_react_from_json = __toESM(require("react-from-json"));
|
1275
|
-
var
|
1425
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
1276
1426
|
var dataAttr = "data-puck-heading-analyzer-id";
|
1277
1427
|
var getOutline = ({
|
1278
1428
|
addDataAttr = false
|
@@ -1329,9 +1479,9 @@ var HeadingOutlineAnalyer = ({
|
|
1329
1479
|
children,
|
1330
1480
|
data
|
1331
1481
|
}) => {
|
1332
|
-
const [hierarchy, setHierarchy] = (0,
|
1333
|
-
const [firstRender, setFirstRender] = (0,
|
1334
|
-
(0,
|
1482
|
+
const [hierarchy, setHierarchy] = (0, import_react6.useState)([]);
|
1483
|
+
const [firstRender, setFirstRender] = (0, import_react6.useState)(true);
|
1484
|
+
(0, import_react6.useEffect)(() => {
|
1335
1485
|
if (firstRender) {
|
1336
1486
|
setTimeout(() => {
|
1337
1487
|
setHierarchy(buildHierarchy());
|
@@ -1341,17 +1491,17 @@ var HeadingOutlineAnalyer = ({
|
|
1341
1491
|
setHierarchy(buildHierarchy());
|
1342
1492
|
}
|
1343
1493
|
}, [data.content]);
|
1344
|
-
return /* @__PURE__ */ (0,
|
1494
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
1345
1495
|
children,
|
1346
|
-
/* @__PURE__ */ (0,
|
1347
|
-
hierarchy.length === 0 && /* @__PURE__ */ (0,
|
1348
|
-
/* @__PURE__ */ (0,
|
1496
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(SidebarSection, { title: "Heading Outline", children: [
|
1497
|
+
hierarchy.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: "No headings." }),
|
1498
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(OutlineList, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
1349
1499
|
import_react_from_json.default,
|
1350
1500
|
{
|
1351
1501
|
mapping: {
|
1352
|
-
Root: (props) => /* @__PURE__ */ (0,
|
1353
|
-
OutlineListItem: (props) => /* @__PURE__ */ (0,
|
1354
|
-
/* @__PURE__ */ (0,
|
1502
|
+
Root: (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: props.children }),
|
1503
|
+
OutlineListItem: (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(OutlineList.Item, { children: [
|
1504
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(OutlineList.Clickable, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
1355
1505
|
"small",
|
1356
1506
|
{
|
1357
1507
|
onClick: typeof props.analyzeId == "undefined" ? void 0 : (e) => {
|
@@ -1370,14 +1520,14 @@ var HeadingOutlineAnalyer = ({
|
|
1370
1520
|
}, 2e3);
|
1371
1521
|
}
|
1372
1522
|
},
|
1373
|
-
children: props.missing ? /* @__PURE__ */ (0,
|
1374
|
-
/* @__PURE__ */ (0,
|
1523
|
+
children: props.missing ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { color: "var(--puck-color-red)" }, children: [
|
1524
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("b", { children: [
|
1375
1525
|
"H",
|
1376
1526
|
props.rank
|
1377
1527
|
] }),
|
1378
1528
|
": Missing"
|
1379
|
-
] }) : /* @__PURE__ */ (0,
|
1380
|
-
/* @__PURE__ */ (0,
|
1529
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
|
1530
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("b", { children: [
|
1381
1531
|
"H",
|
1382
1532
|
props.rank
|
1383
1533
|
] }),
|
@@ -1386,7 +1536,7 @@ var HeadingOutlineAnalyer = ({
|
|
1386
1536
|
] })
|
1387
1537
|
}
|
1388
1538
|
) }),
|
1389
|
-
/* @__PURE__ */ (0,
|
1539
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(OutlineList, { children: props.children })
|
1390
1540
|
] })
|
1391
1541
|
},
|
1392
1542
|
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.
|
3
|
+
"version": "0.10.0-canary.6a9145c",
|
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.
|
17
|
+
"@measured/puck": "^0.10.0-canary.6a9145c",
|
18
18
|
"@types/react": "^18.2.0",
|
19
19
|
"@types/react-dom": "^18.2.0",
|
20
20
|
"eslint": "^7.32.0",
|