@webmaster-droid/web 0.1.0 → 0.1.1
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 +42 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -197,7 +197,7 @@ function parseSelectedEditableFromTarget(target, pagePath) {
|
|
|
197
197
|
}
|
|
198
198
|
return selected;
|
|
199
199
|
}
|
|
200
|
-
function pickStringValue(document2, path, fallback, componentName, fallbackPropName) {
|
|
200
|
+
function pickStringValue(document2, path, fallback, componentName, fallbackPropName, missingBehavior = "throw") {
|
|
201
201
|
const value = readByPath(document2, path);
|
|
202
202
|
if (typeof value === "string" && value.trim()) {
|
|
203
203
|
return value;
|
|
@@ -205,9 +205,12 @@ function pickStringValue(document2, path, fallback, componentName, fallbackPropN
|
|
|
205
205
|
if (typeof fallback === "string") {
|
|
206
206
|
return fallback;
|
|
207
207
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
const message = `${componentName} missing content for "${path}". Provide a CMS value or set \`${fallbackPropName}\`.`;
|
|
209
|
+
if (missingBehavior === "empty") {
|
|
210
|
+
console.error(message);
|
|
211
|
+
return "";
|
|
212
|
+
}
|
|
213
|
+
throw new Error(message);
|
|
211
214
|
}
|
|
212
215
|
function sanitizeRichTextHtml(html) {
|
|
213
216
|
return sanitizeHtml(html, {
|
|
@@ -229,7 +232,7 @@ function EditableText({
|
|
|
229
232
|
...rest
|
|
230
233
|
}) {
|
|
231
234
|
const { document: document2, enabled } = useEditableDocument();
|
|
232
|
-
const value = pickStringValue(document2, path, fallback, "EditableText", "fallback");
|
|
235
|
+
const value = pickStringValue(document2, path, fallback, "EditableText", "fallback", "empty");
|
|
233
236
|
const attrs = enabled ? editableMeta({
|
|
234
237
|
path,
|
|
235
238
|
label: label ?? path,
|
|
@@ -247,7 +250,14 @@ function EditableRichText({
|
|
|
247
250
|
...rest
|
|
248
251
|
}) {
|
|
249
252
|
const { document: document2, enabled } = useEditableDocument();
|
|
250
|
-
const value = pickStringValue(
|
|
253
|
+
const value = pickStringValue(
|
|
254
|
+
document2,
|
|
255
|
+
path,
|
|
256
|
+
fallback,
|
|
257
|
+
"EditableRichText",
|
|
258
|
+
"fallback",
|
|
259
|
+
"empty"
|
|
260
|
+
);
|
|
251
261
|
const sanitizedHtml = sanitizeRichTextHtml(value);
|
|
252
262
|
const attrs = enabled ? editableMeta({
|
|
253
263
|
path,
|
|
@@ -270,8 +280,22 @@ function EditableImage({
|
|
|
270
280
|
...rest
|
|
271
281
|
}) {
|
|
272
282
|
const { document: document2, enabled } = useEditableDocument();
|
|
273
|
-
const src = pickStringValue(
|
|
274
|
-
|
|
283
|
+
const src = pickStringValue(
|
|
284
|
+
document2,
|
|
285
|
+
path,
|
|
286
|
+
fallbackSrc,
|
|
287
|
+
"EditableImage",
|
|
288
|
+
"fallbackSrc",
|
|
289
|
+
"empty"
|
|
290
|
+
);
|
|
291
|
+
const alt = altPath ? pickStringValue(
|
|
292
|
+
document2,
|
|
293
|
+
altPath,
|
|
294
|
+
fallbackAlt,
|
|
295
|
+
"EditableImage",
|
|
296
|
+
"fallbackAlt",
|
|
297
|
+
"empty"
|
|
298
|
+
) : fallbackAlt ?? "";
|
|
275
299
|
const attrs = enabled ? editableMeta({
|
|
276
300
|
path,
|
|
277
301
|
label: label ?? path,
|
|
@@ -290,13 +314,21 @@ function EditableLink({
|
|
|
290
314
|
...rest
|
|
291
315
|
}) {
|
|
292
316
|
const { document: document2, enabled } = useEditableDocument();
|
|
293
|
-
const href = pickStringValue(
|
|
317
|
+
const href = pickStringValue(
|
|
318
|
+
document2,
|
|
319
|
+
hrefPath,
|
|
320
|
+
fallbackHref,
|
|
321
|
+
"EditableLink",
|
|
322
|
+
"fallbackHref",
|
|
323
|
+
"empty"
|
|
324
|
+
);
|
|
294
325
|
const text = pickStringValue(
|
|
295
326
|
document2,
|
|
296
327
|
labelPath,
|
|
297
328
|
fallbackLabel,
|
|
298
329
|
"EditableLink",
|
|
299
|
-
"fallbackLabel"
|
|
330
|
+
"fallbackLabel",
|
|
331
|
+
"empty"
|
|
300
332
|
);
|
|
301
333
|
const attrs = enabled ? editableMeta({
|
|
302
334
|
path: labelPath,
|