vue-datocms 1.0.5 → 2.0.0
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/README.md +67 -57
- package/dist/index.d.ts +111 -37
- package/dist/index.esm.js +157 -214
- package/dist/index.min.js +165 -220
- package/dist/index.umd.js +165 -220
- package/package.json +16 -20
package/dist/index.esm.js
CHANGED
|
@@ -1,68 +1,29 @@
|
|
|
1
1
|
import hypenateStyleName from 'hyphenate-style-name';
|
|
2
|
-
import {
|
|
3
|
-
import { render,
|
|
4
|
-
export { renderRule } from 'datocms-structured-text-generic-html-renderer';
|
|
5
|
-
import { isInlineItem, RenderError, isStructuredText, isItemLink, isBlock } from 'datocms-structured-text-utils';
|
|
2
|
+
import { defineComponent, ref, h, onMounted, onBeforeUnmount, isVNode, cloneVNode } from 'vue';
|
|
3
|
+
import { render, renderNodeRule, defaultMetaTransformer } from 'datocms-structured-text-generic-html-renderer';
|
|
4
|
+
export { renderMarkRule, renderNodeRule, renderNodeRule as renderRule } from 'datocms-structured-text-generic-html-renderer';
|
|
5
|
+
import { isRoot, isInlineItem, RenderError, isStructuredText, isItemLink, isBlock } from 'datocms-structured-text-utils';
|
|
6
6
|
export { RenderError } from 'datocms-structured-text-utils';
|
|
7
7
|
|
|
8
|
-
var __defProp$2 = Object.defineProperty;
|
|
9
|
-
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
11
|
-
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
13
|
-
var __objSpread$2 = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp$3.call(b, prop))
|
|
16
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols$3)
|
|
18
|
-
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
19
|
-
if (__propIsEnum$3.call(b, prop))
|
|
20
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __objRest$1 = (source, exclude) => {
|
|
25
|
-
var target = {};
|
|
26
|
-
for (var prop in source)
|
|
27
|
-
if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
if (source != null && __getOwnPropSymbols$3)
|
|
30
|
-
for (var prop of __getOwnPropSymbols$3(source)) {
|
|
31
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
|
|
32
|
-
target[prop] = source[prop];
|
|
33
|
-
}
|
|
34
|
-
return target;
|
|
35
|
-
};
|
|
36
|
-
function crossH(tag, data, ...rest) {
|
|
37
|
-
if (isVue3) {
|
|
38
|
-
let vue3Data = null;
|
|
39
|
-
if (data) {
|
|
40
|
-
const _a = data, {domProps, attrs, props, on} = _a, other = __objRest$1(_a, ["domProps", "attrs", "props", "on"]);
|
|
41
|
-
vue3Data = __objSpread$2(__objSpread$2(__objSpread$2(__objSpread$2(__objSpread$2({}, other), attrs), props), domProps), Object.entries(on || {}).reduce((acc, [key, value]) => __objSpread$2(__objSpread$2({}, acc), {
|
|
42
|
-
[`on${key.charAt(0).toUpperCase() + key.slice(1)}`]: value
|
|
43
|
-
}), {}));
|
|
44
|
-
}
|
|
45
|
-
return h(tag, vue3Data, ...rest);
|
|
46
|
-
}
|
|
47
|
-
return h(tag, data, ...rest);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
8
|
var __defProp$1 = Object.defineProperty;
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
var
|
|
9
|
+
var __defProps$1 = Object.defineProperties;
|
|
10
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
11
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
12
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
14
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15
|
+
var __spreadValues$1 = (a, b) => {
|
|
56
16
|
for (var prop in b || (b = {}))
|
|
57
|
-
if (__hasOwnProp$
|
|
17
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
58
18
|
__defNormalProp$1(a, prop, b[prop]);
|
|
59
|
-
if (__getOwnPropSymbols$
|
|
60
|
-
for (var prop of __getOwnPropSymbols$
|
|
61
|
-
if (__propIsEnum$
|
|
19
|
+
if (__getOwnPropSymbols$1)
|
|
20
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
21
|
+
if (__propIsEnum$1.call(b, prop))
|
|
62
22
|
__defNormalProp$1(a, prop, b[prop]);
|
|
63
23
|
}
|
|
64
24
|
return a;
|
|
65
25
|
};
|
|
26
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
66
27
|
const escape = (s) => {
|
|
67
28
|
s = "" + s;
|
|
68
29
|
s = s.replace(/&/g, "&");
|
|
@@ -99,9 +60,11 @@ const tag = (tagName, attrs, content) => {
|
|
|
99
60
|
const attrsString = serializedAttrs.length > 0 ? ` ${serializedAttrs.join(" ")}` : "";
|
|
100
61
|
return content ? `<${tagName}${attrsString}>${content.join("")}</${tagName}>` : `<${tagName}${attrsString} />`;
|
|
101
62
|
};
|
|
102
|
-
const isSsr = typeof window === "undefined";
|
|
103
|
-
const isIntersectionObserverAvailable =
|
|
104
|
-
|
|
63
|
+
const isSsr = () => typeof window === "undefined";
|
|
64
|
+
const isIntersectionObserverAvailable = () => {
|
|
65
|
+
return isSsr() ? false : !!window.IntersectionObserver;
|
|
66
|
+
};
|
|
67
|
+
const universalBtoa = (str) => isSsr() ? Buffer.from(str.toString(), "binary").toString("base64") : window.btoa(str);
|
|
105
68
|
const absolutePositioning = {
|
|
106
69
|
position: "absolute",
|
|
107
70
|
left: "0px",
|
|
@@ -109,12 +72,12 @@ const absolutePositioning = {
|
|
|
109
72
|
width: "100%",
|
|
110
73
|
height: "100%"
|
|
111
74
|
};
|
|
112
|
-
const useInView = ({threshold, rootMargin}) => {
|
|
75
|
+
const useInView = ({ threshold, rootMargin }) => {
|
|
113
76
|
const observer = ref(null);
|
|
114
77
|
const elRef = ref(null);
|
|
115
78
|
const inView = ref(false);
|
|
116
79
|
onMounted(() => {
|
|
117
|
-
if (isIntersectionObserverAvailable) {
|
|
80
|
+
if (isIntersectionObserverAvailable()) {
|
|
118
81
|
observer.value = new IntersectionObserver((entries) => {
|
|
119
82
|
const image = entries[0];
|
|
120
83
|
if (image.isIntersecting && observer.value) {
|
|
@@ -131,32 +94,32 @@ const useInView = ({threshold, rootMargin}) => {
|
|
|
131
94
|
}
|
|
132
95
|
});
|
|
133
96
|
onBeforeUnmount(() => {
|
|
134
|
-
if (isIntersectionObserverAvailable && observer.value) {
|
|
97
|
+
if (isIntersectionObserverAvailable() && observer.value) {
|
|
135
98
|
observer.value.disconnect();
|
|
136
99
|
}
|
|
137
100
|
});
|
|
138
|
-
return {inView, elRef};
|
|
101
|
+
return { inView, elRef };
|
|
139
102
|
};
|
|
140
|
-
const imageAddStrategy = ({lazyLoad, inView, loaded}) => {
|
|
103
|
+
const imageAddStrategy = ({ lazyLoad, inView, loaded }) => {
|
|
141
104
|
if (!lazyLoad) {
|
|
142
105
|
return true;
|
|
143
106
|
}
|
|
144
|
-
if (isSsr) {
|
|
107
|
+
if (isSsr()) {
|
|
145
108
|
return false;
|
|
146
109
|
}
|
|
147
|
-
if (isIntersectionObserverAvailable) {
|
|
110
|
+
if (isIntersectionObserverAvailable()) {
|
|
148
111
|
return inView || loaded;
|
|
149
112
|
}
|
|
150
113
|
return true;
|
|
151
114
|
};
|
|
152
|
-
const imageShowStrategy = ({lazyLoad, loaded}) => {
|
|
115
|
+
const imageShowStrategy = ({ lazyLoad, loaded }) => {
|
|
153
116
|
if (!lazyLoad) {
|
|
154
117
|
return true;
|
|
155
118
|
}
|
|
156
|
-
if (isSsr) {
|
|
119
|
+
if (isSsr()) {
|
|
157
120
|
return false;
|
|
158
121
|
}
|
|
159
|
-
if (isIntersectionObserverAvailable) {
|
|
122
|
+
if (isIntersectionObserverAvailable()) {
|
|
160
123
|
return loaded;
|
|
161
124
|
}
|
|
162
125
|
return true;
|
|
@@ -202,7 +165,7 @@ const Image = defineComponent({
|
|
|
202
165
|
function handleLoad() {
|
|
203
166
|
loaded.value = true;
|
|
204
167
|
}
|
|
205
|
-
const {inView, elRef} = useInView({
|
|
168
|
+
const { inView, elRef } = useInView({
|
|
206
169
|
threshold: props.intersectionThreshold || props.intersectionTreshold || 0,
|
|
207
170
|
rootMargin: props.intersectionMargin || "0px 0px 0px 0px"
|
|
208
171
|
});
|
|
@@ -224,22 +187,18 @@ const Image = defineComponent({
|
|
|
224
187
|
inView: this.inView,
|
|
225
188
|
loaded: this.loaded
|
|
226
189
|
});
|
|
227
|
-
const webpSource = this.data.webpSrcSet &&
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
type: "image/webp"
|
|
232
|
-
}
|
|
190
|
+
const webpSource = this.data.webpSrcSet && h("source", {
|
|
191
|
+
srcset: this.data.webpSrcSet,
|
|
192
|
+
sizes: this.data.sizes,
|
|
193
|
+
type: "image/webp"
|
|
233
194
|
});
|
|
234
|
-
const regularSource = this.data.srcSet &&
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
sizes: this.data.sizes
|
|
238
|
-
}
|
|
195
|
+
const regularSource = this.data.srcSet && h("source", {
|
|
196
|
+
srcset: this.data.srcSet,
|
|
197
|
+
sizes: this.data.sizes
|
|
239
198
|
});
|
|
240
199
|
const transition = typeof this.fadeInDuration === "undefined" || this.fadeInDuration > 0 ? `opacity ${this.fadeInDuration || 500}ms ${this.fadeInDuration || 500}ms` : void 0;
|
|
241
|
-
const placeholder =
|
|
242
|
-
style:
|
|
200
|
+
const placeholder = h("div", {
|
|
201
|
+
style: __spreadValues$1({
|
|
243
202
|
backgroundImage: this.data.base64 ? `url(${this.data.base64})` : null,
|
|
244
203
|
backgroundColor: this.data.bgColor,
|
|
245
204
|
backgroundSize: "cover",
|
|
@@ -247,21 +206,19 @@ const Image = defineComponent({
|
|
|
247
206
|
transition
|
|
248
207
|
}, absolutePositioning)
|
|
249
208
|
});
|
|
250
|
-
const {width, aspectRatio} = this.data;
|
|
209
|
+
const { width, aspectRatio } = this.data;
|
|
251
210
|
const height = this.data.height || width / aspectRatio;
|
|
252
211
|
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}"></svg>`;
|
|
253
|
-
const sizer =
|
|
212
|
+
const sizer = h("img", {
|
|
254
213
|
class: this.pictureClass,
|
|
255
|
-
style:
|
|
214
|
+
style: __spreadValues$1({
|
|
256
215
|
display: "block",
|
|
257
216
|
width: this.explicitWidth ? `${width}px` : "100%"
|
|
258
217
|
}, this.pictureStyle),
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
role: "presentation"
|
|
262
|
-
}
|
|
218
|
+
src: `data:image/svg+xml;base64,${universalBtoa(svg)}`,
|
|
219
|
+
role: "presentation"
|
|
263
220
|
});
|
|
264
|
-
return
|
|
221
|
+
return h("div", {
|
|
265
222
|
style: {
|
|
266
223
|
display: this.explicitWidth ? "inline-block" : "block",
|
|
267
224
|
overflow: "hidden",
|
|
@@ -271,47 +228,41 @@ const Image = defineComponent({
|
|
|
271
228
|
}, [
|
|
272
229
|
sizer,
|
|
273
230
|
placeholder,
|
|
274
|
-
addImage &&
|
|
231
|
+
addImage && h("picture", null, [
|
|
275
232
|
webpSource,
|
|
276
233
|
regularSource,
|
|
277
|
-
this.data.src &&
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
},
|
|
283
|
-
on: {
|
|
284
|
-
load: this.handleLoad
|
|
285
|
-
},
|
|
234
|
+
this.data.src && h("img", {
|
|
235
|
+
src: this.data.src,
|
|
236
|
+
alt: this.data.alt,
|
|
237
|
+
title: this.data.title,
|
|
238
|
+
onLoad: this.handleLoad,
|
|
286
239
|
class: this.pictureClass,
|
|
287
|
-
style:
|
|
240
|
+
style: __spreadProps$1(__spreadValues$1(__spreadValues$1({}, absolutePositioning), this.pictureStyle), {
|
|
288
241
|
opacity: showImage ? 1 : 0,
|
|
289
242
|
transition
|
|
290
243
|
})
|
|
291
244
|
})
|
|
292
245
|
]),
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
this.data.webpSrcSet
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
this.data.srcSet
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
])
|
|
314
|
-
}
|
|
246
|
+
h("noscript", {
|
|
247
|
+
innerHTML: tag("picture", {}, [
|
|
248
|
+
this.data.webpSrcSet && tag("source", {
|
|
249
|
+
srcset: this.data.webpSrcSet,
|
|
250
|
+
sizes: this.data.sizes,
|
|
251
|
+
type: "image/webp"
|
|
252
|
+
}),
|
|
253
|
+
this.data.srcSet && tag("source", {
|
|
254
|
+
srcset: this.data.srcSet,
|
|
255
|
+
sizes: this.data.sizes
|
|
256
|
+
}),
|
|
257
|
+
tag("img", {
|
|
258
|
+
src: this.data.src,
|
|
259
|
+
alt: this.data.alt,
|
|
260
|
+
title: this.data.title,
|
|
261
|
+
class: this.pictureClass,
|
|
262
|
+
style: toCss(__spreadValues$1(__spreadValues$1({}, this.pictureStyle), absolutePositioning)),
|
|
263
|
+
loading: "lazy"
|
|
264
|
+
})
|
|
265
|
+
])
|
|
315
266
|
})
|
|
316
267
|
]);
|
|
317
268
|
}
|
|
@@ -322,44 +273,18 @@ const DatocmsImagePlugin = {
|
|
|
322
273
|
}
|
|
323
274
|
};
|
|
324
275
|
|
|
325
|
-
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
326
|
-
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
327
|
-
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
328
|
-
var __objRest = (source, exclude) => {
|
|
329
|
-
var target = {};
|
|
330
|
-
for (var prop in source)
|
|
331
|
-
if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
332
|
-
target[prop] = source[prop];
|
|
333
|
-
if (source != null && __getOwnPropSymbols$1)
|
|
334
|
-
for (var prop of __getOwnPropSymbols$1(source)) {
|
|
335
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
|
|
336
|
-
target[prop] = source[prop];
|
|
337
|
-
}
|
|
338
|
-
return target;
|
|
339
|
-
};
|
|
340
276
|
const hAdapter = (tagName, props, childOrChildren) => {
|
|
341
|
-
|
|
342
|
-
if (props) {
|
|
343
|
-
const _a = props, {key} = _a, attrs = __objRest(_a, ["key"]);
|
|
344
|
-
data = {key, attrs};
|
|
345
|
-
}
|
|
346
|
-
return crossH(tagName, data, Array.isArray(childOrChildren) ? childOrChildren : [childOrChildren]);
|
|
277
|
+
return h(tagName, props, Array.isArray(childOrChildren) ? childOrChildren : [childOrChildren]);
|
|
347
278
|
};
|
|
348
279
|
const defaultAdapter = {
|
|
349
280
|
renderNode: hAdapter,
|
|
350
281
|
renderMark: hAdapter,
|
|
351
|
-
renderFragment: (children, key) =>
|
|
282
|
+
renderFragment: (children, key) => children,
|
|
352
283
|
renderText: (text, key) => text
|
|
353
284
|
};
|
|
354
285
|
function appendKeyToValidElement(element, key) {
|
|
355
|
-
if (
|
|
356
|
-
|
|
357
|
-
if (isVNode(element) && element.key === null) {
|
|
358
|
-
return cloneVNode(element, {key});
|
|
359
|
-
}
|
|
360
|
-
} else if (element && typeof element === "object" && (element.key === null || element.key === void 0)) {
|
|
361
|
-
element.key = key;
|
|
362
|
-
return element;
|
|
286
|
+
if (isVNode(element) && element.key === null) {
|
|
287
|
+
return cloneVNode(element, { key });
|
|
363
288
|
}
|
|
364
289
|
return element;
|
|
365
290
|
}
|
|
@@ -372,6 +297,12 @@ const StructuredText = defineComponent({
|
|
|
372
297
|
customRules: {
|
|
373
298
|
type: Array
|
|
374
299
|
},
|
|
300
|
+
customNodeRules: {
|
|
301
|
+
type: Array
|
|
302
|
+
},
|
|
303
|
+
customMarkRules: {
|
|
304
|
+
type: Array
|
|
305
|
+
},
|
|
375
306
|
renderInlineRecord: {
|
|
376
307
|
type: Function
|
|
377
308
|
},
|
|
@@ -381,65 +312,74 @@ const StructuredText = defineComponent({
|
|
|
381
312
|
renderBlock: {
|
|
382
313
|
type: Function
|
|
383
314
|
},
|
|
384
|
-
metaTransformer: {type: Function},
|
|
385
|
-
renderText: {type: Function},
|
|
386
|
-
renderNode: {type: Function},
|
|
387
|
-
renderFragment: {type: Function}
|
|
315
|
+
metaTransformer: { type: Function },
|
|
316
|
+
renderText: { type: Function },
|
|
317
|
+
renderNode: { type: Function },
|
|
318
|
+
renderFragment: { type: Function }
|
|
388
319
|
},
|
|
389
320
|
setup(props) {
|
|
390
321
|
return () => {
|
|
391
|
-
return render({
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
322
|
+
return render(props.data, {
|
|
323
|
+
adapter: {
|
|
324
|
+
renderText: props.renderText || defaultAdapter.renderText,
|
|
325
|
+
renderNode: props.renderNode || defaultAdapter.renderNode,
|
|
326
|
+
renderFragment: props.renderFragment || defaultAdapter.renderFragment
|
|
327
|
+
},
|
|
328
|
+
metaTransformer: props.metaTransformer,
|
|
329
|
+
customMarkRules: props.customMarkRules,
|
|
330
|
+
customNodeRules: [
|
|
331
|
+
renderNodeRule(isRoot, ({ adapter: { renderNode }, key, children }) => {
|
|
332
|
+
return renderNode("div", { key }, children);
|
|
333
|
+
}),
|
|
334
|
+
renderNodeRule(isInlineItem, ({ node, key }) => {
|
|
335
|
+
if (!props.renderInlineRecord) {
|
|
336
|
+
throw new RenderError(`The Structured Text document contains an 'inlineItem' node, but no 'renderInlineRecord' prop is specified!`, node);
|
|
337
|
+
}
|
|
338
|
+
if (!isStructuredText(props.data) || !props.data.links) {
|
|
339
|
+
throw new RenderError(`The Structured Text document contains an 'inlineItem' node, but .links is not present!`, node);
|
|
340
|
+
}
|
|
341
|
+
const item = props.data.links.find((item2) => item2.id === node.item);
|
|
342
|
+
if (!item) {
|
|
343
|
+
throw new RenderError(`The Structured Text document contains an 'inlineItem' node, but cannot find a record with ID ${node.item} inside .links!`, node);
|
|
344
|
+
}
|
|
345
|
+
return appendKeyToValidElement(props.renderInlineRecord({ record: item }), key);
|
|
346
|
+
}),
|
|
347
|
+
renderNodeRule(isItemLink, ({ node, key, children }) => {
|
|
348
|
+
if (!props.renderLinkToRecord) {
|
|
349
|
+
throw new RenderError(`The Structured Text document contains an 'itemLink' node, but no 'renderLinkToRecord' prop is specified!`, node);
|
|
350
|
+
}
|
|
351
|
+
if (!isStructuredText(props.data) || !props.data.links) {
|
|
352
|
+
throw new RenderError(`The Structured Text document contains an 'itemLink' node, but .links is not present!`, node);
|
|
353
|
+
}
|
|
354
|
+
const item = props.data.links.find((item2) => item2.id === node.item);
|
|
355
|
+
if (!item) {
|
|
356
|
+
throw new RenderError(`The Structured Text document contains an 'itemLink' node, but cannot find a record with ID ${node.item} inside .links!`, node);
|
|
357
|
+
}
|
|
358
|
+
return appendKeyToValidElement(props.renderLinkToRecord({
|
|
359
|
+
record: item,
|
|
360
|
+
children,
|
|
361
|
+
transformedMeta: node.meta ? (props.metaTransformer || defaultMetaTransformer)({
|
|
362
|
+
node,
|
|
363
|
+
meta: node.meta
|
|
364
|
+
}) : null
|
|
365
|
+
}), key);
|
|
366
|
+
}),
|
|
367
|
+
renderNodeRule(isBlock, ({ node, key }) => {
|
|
368
|
+
if (!props.renderBlock) {
|
|
369
|
+
throw new RenderError(`The Structured Text document contains a 'block' node, but no 'renderBlock' prop is specified!`, node);
|
|
370
|
+
}
|
|
371
|
+
if (!isStructuredText(props.data) || !props.data.blocks) {
|
|
372
|
+
throw new RenderError(`The Structured Text document contains a 'block' node, but .blocks is not present!`, node);
|
|
373
|
+
}
|
|
374
|
+
const item = props.data.blocks.find((item2) => item2.id === node.item);
|
|
375
|
+
if (!item) {
|
|
376
|
+
throw new RenderError(`The Structured Text document contains a 'block' node, but cannot find a record with ID ${node.item} inside .blocks!`, node);
|
|
377
|
+
}
|
|
378
|
+
return appendKeyToValidElement(props.renderBlock({ record: item }), key);
|
|
379
|
+
}),
|
|
380
|
+
...props.customNodeRules || props.customRules || []
|
|
381
|
+
]
|
|
382
|
+
});
|
|
443
383
|
};
|
|
444
384
|
}
|
|
445
385
|
});
|
|
@@ -450,11 +390,13 @@ const DatocmsStructuredTextPlugin = {
|
|
|
450
390
|
};
|
|
451
391
|
|
|
452
392
|
var __defProp = Object.defineProperty;
|
|
453
|
-
var
|
|
393
|
+
var __defProps = Object.defineProperties;
|
|
394
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
454
395
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
396
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
455
397
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
456
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
457
|
-
var
|
|
398
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
399
|
+
var __spreadValues = (a, b) => {
|
|
458
400
|
for (var prop in b || (b = {}))
|
|
459
401
|
if (__hasOwnProp.call(b, prop))
|
|
460
402
|
__defNormalProp(a, prop, b[prop]);
|
|
@@ -465,6 +407,7 @@ var __objSpread = (a, b) => {
|
|
|
465
407
|
}
|
|
466
408
|
return a;
|
|
467
409
|
};
|
|
410
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
468
411
|
const toHead = (...args) => {
|
|
469
412
|
const tags = [].concat(...args);
|
|
470
413
|
const titleTag = tags && tags.find((t) => t.tag === "title");
|
|
@@ -474,14 +417,14 @@ const toHead = (...args) => {
|
|
|
474
417
|
title: titleTag && titleTag.content,
|
|
475
418
|
meta: metaTags.map((tag) => {
|
|
476
419
|
var _a, _b, _c, _d;
|
|
477
|
-
return
|
|
420
|
+
return __spreadProps(__spreadValues({}, tag.attributes), {
|
|
478
421
|
hid: ((_a = tag.attributes) == null ? void 0 : _a.name) || ((_b = tag.attributes) == null ? void 0 : _b.property),
|
|
479
422
|
vmid: ((_c = tag.attributes) == null ? void 0 : _c.name) || ((_d = tag.attributes) == null ? void 0 : _d.property)
|
|
480
423
|
});
|
|
481
424
|
}),
|
|
482
425
|
link: linkTags.map((tag) => {
|
|
483
426
|
var _a, _b, _c, _d, _e, _f;
|
|
484
|
-
return
|
|
427
|
+
return __spreadProps(__spreadValues({}, tag.attributes), {
|
|
485
428
|
hid: ((_a = tag.attributes) == null ? void 0 : _a.name) || `${(_b = tag.attributes) == null ? void 0 : _b.rel}-${(_c = tag.attributes) == null ? void 0 : _c.sizes}`,
|
|
486
429
|
vmid: ((_d = tag.attributes) == null ? void 0 : _d.name) || `${(_e = tag.attributes) == null ? void 0 : _e.rel}-${(_f = tag.attributes) == null ? void 0 : _f.sizes}`
|
|
487
430
|
});
|