cms-renderer 0.6.12 → 0.6.13
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/lib/block-renderer.d.ts +16 -12
- package/dist/lib/block-renderer.js +64 -1
- package/dist/lib/block-renderer.js.map +1 -1
- package/dist/lib/custom-schemas.js.map +1 -1
- package/dist/lib/docs-markdown.d.ts +2 -2
- package/dist/lib/parametric-route.d.ts +15 -2
- package/dist/lib/parametric-route.js +94 -6
- package/dist/lib/parametric-route.js.map +1 -1
- package/dist/lib/renderer.d.ts +12 -3
- package/dist/lib/renderer.js +105 -6
- package/dist/lib/renderer.js.map +1 -1
- package/package.json +4 -4
package/dist/lib/renderer.js
CHANGED
|
@@ -486,7 +486,7 @@ function generateCmsOverlayScript(cmsParentOrigin) {
|
|
|
486
486
|
pointer-events: none;
|
|
487
487
|
z-index: 99998;
|
|
488
488
|
}
|
|
489
|
-
#cms-overlay-root >
|
|
489
|
+
#cms-overlay-root > *:not(.cms-block-toolbar) {
|
|
490
490
|
pointer-events: none;
|
|
491
491
|
}
|
|
492
492
|
.cms-block-outline {
|
|
@@ -583,9 +583,69 @@ function generateCmsOverlayScript(cmsParentOrigin) {
|
|
|
583
583
|
blockEl.setAttribute('data-cms-block', '');
|
|
584
584
|
blockEl.setAttribute('data-block-id', blockId);
|
|
585
585
|
blockEl.setAttribute('data-block-type', blockType);
|
|
586
|
+
|
|
587
|
+
injectEditableSpans(
|
|
588
|
+
blockEl,
|
|
589
|
+
blockId,
|
|
590
|
+
blockType,
|
|
591
|
+
sentinel.getAttribute('data-content-entries')
|
|
592
|
+
);
|
|
586
593
|
});
|
|
587
594
|
}
|
|
588
595
|
|
|
596
|
+
function injectEditableSpans(blockEl, blockId, blockType, rawEntries) {
|
|
597
|
+
if (!rawEntries || blockEl.querySelector('[data-cms-editable][data-content-path]')) return;
|
|
598
|
+
|
|
599
|
+
var entries;
|
|
600
|
+
try {
|
|
601
|
+
entries = JSON.parse(rawEntries);
|
|
602
|
+
} catch (_) {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
if (!Array.isArray(entries) || entries.length === 0) return;
|
|
606
|
+
|
|
607
|
+
var used = {};
|
|
608
|
+
var walker = document.createTreeWalker(blockEl, NodeFilter.SHOW_TEXT, null);
|
|
609
|
+
var textNodes = [];
|
|
610
|
+
var node = walker.nextNode();
|
|
611
|
+
while (node !== null) {
|
|
612
|
+
if (node.nodeValue && node.nodeValue.trim()) {
|
|
613
|
+
textNodes.push(node);
|
|
614
|
+
}
|
|
615
|
+
node = walker.nextNode();
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
for (var i = 0; i < textNodes.length; i++) {
|
|
619
|
+
var textNode = textNodes[i];
|
|
620
|
+
var parentEl = textNode.parentElement;
|
|
621
|
+
if (!parentEl || parentEl.closest('svg') || parentEl.closest('[data-cms-editable]')) {
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
var text = textNode.nodeValue;
|
|
626
|
+
if (!text) continue;
|
|
627
|
+
|
|
628
|
+
for (var j = 0; j < entries.length; j++) {
|
|
629
|
+
var entry = entries[j];
|
|
630
|
+
if (!entry || typeof entry.v !== 'string' || typeof entry.p !== 'string' || used[entry.p]) {
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
if (text.trim() !== entry.v.trim()) continue;
|
|
634
|
+
|
|
635
|
+
used[entry.p] = true;
|
|
636
|
+
var span = document.createElement('span');
|
|
637
|
+
span.setAttribute('data-cms-editable', '');
|
|
638
|
+
span.setAttribute('data-block-id', blockId);
|
|
639
|
+
span.setAttribute('data-block-type', blockType);
|
|
640
|
+
span.setAttribute('data-content-path', entry.p);
|
|
641
|
+
span.setAttribute('contenteditable', 'true');
|
|
642
|
+
parentEl.insertBefore(span, textNode);
|
|
643
|
+
span.appendChild(textNode);
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
589
649
|
stampBlockElements();
|
|
590
650
|
|
|
591
651
|
var stampObserver = new MutationObserver(function(mutations) {
|
|
@@ -931,6 +991,27 @@ function getCmsParentTargetOrigin(preferredCmsUrl, explicitParentOrigin) {
|
|
|
931
991
|
|
|
932
992
|
// lib/block-renderer.tsx
|
|
933
993
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
994
|
+
function extractContentValues(content, basePath = []) {
|
|
995
|
+
const map = /* @__PURE__ */ new Map();
|
|
996
|
+
function walk(obj, path) {
|
|
997
|
+
if (typeof obj === "string" && obj.trim() !== "") {
|
|
998
|
+
const contentPath = path.join(".");
|
|
999
|
+
const existing = map.get(obj) || [];
|
|
1000
|
+
existing.push({ contentPath, value: obj });
|
|
1001
|
+
map.set(obj, existing);
|
|
1002
|
+
} else if (Array.isArray(obj)) {
|
|
1003
|
+
for (let index = 0; index < obj.length; index++) {
|
|
1004
|
+
walk(obj[index], [...path, String(index)]);
|
|
1005
|
+
}
|
|
1006
|
+
} else if (obj && typeof obj === "object") {
|
|
1007
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1008
|
+
walk(value, [...path, key]);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
walk(content, basePath);
|
|
1013
|
+
return map;
|
|
1014
|
+
}
|
|
934
1015
|
function CmsEditableInit({
|
|
935
1016
|
cmsUrl,
|
|
936
1017
|
cmsParentOrigin
|
|
@@ -979,6 +1060,7 @@ function BlockRenderer({
|
|
|
979
1060
|
block,
|
|
980
1061
|
registry,
|
|
981
1062
|
disableEditable,
|
|
1063
|
+
enableContentEditable,
|
|
982
1064
|
routeParams,
|
|
983
1065
|
path
|
|
984
1066
|
}) {
|
|
@@ -994,6 +1076,7 @@ function BlockRenderer({
|
|
|
994
1076
|
if (disableEditable) {
|
|
995
1077
|
return component;
|
|
996
1078
|
}
|
|
1079
|
+
const contentEntries = enableContentEditable ? [...extractContentValues(block.content).values()].flat().map(({ value, contentPath }) => ({ v: value, p: contentPath })) : void 0;
|
|
997
1080
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
998
1081
|
/* @__PURE__ */ jsx(
|
|
999
1082
|
"span",
|
|
@@ -1001,6 +1084,7 @@ function BlockRenderer({
|
|
|
1001
1084
|
"data-cms-sentinel": "",
|
|
1002
1085
|
"data-block-id": block.id,
|
|
1003
1086
|
"data-block-type": block.type,
|
|
1087
|
+
"data-content-entries": contentEntries ? JSON.stringify(contentEntries) : void 0,
|
|
1004
1088
|
style: { display: "none" },
|
|
1005
1089
|
"aria-hidden": "true"
|
|
1006
1090
|
}
|
|
@@ -1034,7 +1118,7 @@ async function renderParametricRoute({
|
|
|
1034
1118
|
apiKey,
|
|
1035
1119
|
cmsUrl,
|
|
1036
1120
|
websiteId: providedWebsiteId
|
|
1037
|
-
}) {
|
|
1121
|
+
}, { preview = false } = {}) {
|
|
1038
1122
|
const websiteId = getWebsiteId(providedWebsiteId);
|
|
1039
1123
|
const { slug } = "then" in params ? await params : params;
|
|
1040
1124
|
const resolvedSearchParams = searchParams && "then" in searchParams ? await searchParams : searchParams;
|
|
@@ -1049,10 +1133,11 @@ async function renderParametricRoute({
|
|
|
1049
1133
|
}
|
|
1050
1134
|
}
|
|
1051
1135
|
}
|
|
1052
|
-
const editModeParam = resolvedSearchParams?.edit_mode;
|
|
1053
|
-
const editMode = editModeParam === true || editModeParam === "true" || editModeParam === "1";
|
|
1054
1136
|
const cmsParentOriginParam = resolvedSearchParams?.cms_parent_origin;
|
|
1055
1137
|
const cmsParentOrigin = typeof cmsParentOriginParam === "boolean" ? void 0 : Array.isArray(cmsParentOriginParam) ? cmsParentOriginParam[0] : cmsParentOriginParam;
|
|
1138
|
+
const previewMode = preview === true;
|
|
1139
|
+
const editModeParam = resolvedSearchParams?.edit_mode;
|
|
1140
|
+
const editMode = previewMode || editModeParam === true || editModeParam === "true" || editModeParam === "1";
|
|
1056
1141
|
const rawPath = `/${slug.join("/")}`;
|
|
1057
1142
|
const path = normalizePath(rawPath);
|
|
1058
1143
|
if (/\.[a-zA-Z0-9]+$/.test(path)) {
|
|
@@ -1092,7 +1177,9 @@ async function renderParametricRoute({
|
|
|
1092
1177
|
]);
|
|
1093
1178
|
const blocks = [];
|
|
1094
1179
|
for (const block of blockResults) {
|
|
1095
|
-
if (!block
|
|
1180
|
+
if (!block) continue;
|
|
1181
|
+
const blockContent = previewMode ? block.draft_content : block.published_content;
|
|
1182
|
+
if (blockContent == null) continue;
|
|
1096
1183
|
let content = null;
|
|
1097
1184
|
if (aiPreviewIndex !== null) {
|
|
1098
1185
|
const generatedBlock = generatedBlocks[block.id];
|
|
@@ -1102,7 +1189,7 @@ async function renderParametricRoute({
|
|
|
1102
1189
|
content = variants[variantIndex].content;
|
|
1103
1190
|
}
|
|
1104
1191
|
}
|
|
1105
|
-
content = content ??
|
|
1192
|
+
content = content ?? blockContent;
|
|
1106
1193
|
if (!content) continue;
|
|
1107
1194
|
if (block.schema_name === "article") {
|
|
1108
1195
|
const article = normalizeArticleContent(content);
|
|
@@ -1150,6 +1237,7 @@ async function renderParametricRoute({
|
|
|
1150
1237
|
block,
|
|
1151
1238
|
registry: registry ?? {},
|
|
1152
1239
|
disableEditable: !editMode,
|
|
1240
|
+
enableContentEditable: previewMode,
|
|
1153
1241
|
routeParams,
|
|
1154
1242
|
path
|
|
1155
1243
|
},
|
|
@@ -1178,6 +1266,16 @@ async function ParametricRoutePage(props) {
|
|
|
1178
1266
|
}
|
|
1179
1267
|
return result.node;
|
|
1180
1268
|
}
|
|
1269
|
+
async function ParametricRoutePreviewPage(props) {
|
|
1270
|
+
const result = await renderParametricRoute(props, { preview: true });
|
|
1271
|
+
if (result.status === "not_found") {
|
|
1272
|
+
notFound();
|
|
1273
|
+
}
|
|
1274
|
+
if (result.status === "error") {
|
|
1275
|
+
throw result.error;
|
|
1276
|
+
}
|
|
1277
|
+
return result.node;
|
|
1278
|
+
}
|
|
1181
1279
|
async function generateMetadata({
|
|
1182
1280
|
params,
|
|
1183
1281
|
apiKey,
|
|
@@ -1204,6 +1302,7 @@ async function generateMetadata({
|
|
|
1204
1302
|
}
|
|
1205
1303
|
}
|
|
1206
1304
|
export {
|
|
1305
|
+
ParametricRoutePreviewPage,
|
|
1207
1306
|
ParametricRoutePage as default,
|
|
1208
1307
|
generateMetadata
|
|
1209
1308
|
};
|