vue-datocms 1.0.4 → 2.0.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 -55
- package/dist/index.d.ts +111 -37
- package/dist/index.esm.js +157 -214
- package/dist/index.min.js +165 -219
- package/dist/index.umd.js +165 -219
- package/package.json +16 -20
package/dist/index.esm.js
CHANGED
|
@@ -1,69 +1,29 @@
|
|
|
1
1
|
import hypenateStyleName from 'hyphenate-style-name';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
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';
|
|
7
6
|
export { RenderError } from 'datocms-structured-text-utils';
|
|
8
7
|
|
|
9
|
-
var __defProp$2 = Object.defineProperty;
|
|
10
|
-
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
12
|
-
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
13
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
14
|
-
var __objSpread$2 = (a, b) => {
|
|
15
|
-
for (var prop in b || (b = {}))
|
|
16
|
-
if (__hasOwnProp$3.call(b, prop))
|
|
17
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
18
|
-
if (__getOwnPropSymbols$3)
|
|
19
|
-
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
20
|
-
if (__propIsEnum$3.call(b, prop))
|
|
21
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
22
|
-
}
|
|
23
|
-
return a;
|
|
24
|
-
};
|
|
25
|
-
var __objRest$1 = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols$3)
|
|
31
|
-
for (var prop of __getOwnPropSymbols$3(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
|
-
function crossH(tag, data, ...rest) {
|
|
38
|
-
if (isVue3) {
|
|
39
|
-
let vue3Data = null;
|
|
40
|
-
if (data) {
|
|
41
|
-
const _a = data, {domProps, attrs, props, on} = _a, other = __objRest$1(_a, ["domProps", "attrs", "props", "on"]);
|
|
42
|
-
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), {
|
|
43
|
-
[`on${key.charAt(0).toUpperCase() + key.slice(1)}`]: value
|
|
44
|
-
}), {}));
|
|
45
|
-
}
|
|
46
|
-
return h(tag, vue3Data, ...rest);
|
|
47
|
-
}
|
|
48
|
-
return h(tag, data, ...rest);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
8
|
var __defProp$1 = Object.defineProperty;
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
var
|
|
56
|
-
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) => {
|
|
57
16
|
for (var prop in b || (b = {}))
|
|
58
|
-
if (__hasOwnProp$
|
|
17
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
59
18
|
__defNormalProp$1(a, prop, b[prop]);
|
|
60
|
-
if (__getOwnPropSymbols$
|
|
61
|
-
for (var prop of __getOwnPropSymbols$
|
|
62
|
-
if (__propIsEnum$
|
|
19
|
+
if (__getOwnPropSymbols$1)
|
|
20
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
21
|
+
if (__propIsEnum$1.call(b, prop))
|
|
63
22
|
__defNormalProp$1(a, prop, b[prop]);
|
|
64
23
|
}
|
|
65
24
|
return a;
|
|
66
25
|
};
|
|
26
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
67
27
|
const escape = (s) => {
|
|
68
28
|
s = "" + s;
|
|
69
29
|
s = s.replace(/&/g, "&");
|
|
@@ -100,9 +60,11 @@ const tag = (tagName, attrs, content) => {
|
|
|
100
60
|
const attrsString = serializedAttrs.length > 0 ? ` ${serializedAttrs.join(" ")}` : "";
|
|
101
61
|
return content ? `<${tagName}${attrsString}>${content.join("")}</${tagName}>` : `<${tagName}${attrsString} />`;
|
|
102
62
|
};
|
|
103
|
-
const isSsr = typeof window === "undefined";
|
|
104
|
-
const isIntersectionObserverAvailable =
|
|
105
|
-
|
|
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);
|
|
106
68
|
const absolutePositioning = {
|
|
107
69
|
position: "absolute",
|
|
108
70
|
left: "0px",
|
|
@@ -110,12 +72,12 @@ const absolutePositioning = {
|
|
|
110
72
|
width: "100%",
|
|
111
73
|
height: "100%"
|
|
112
74
|
};
|
|
113
|
-
const useInView = ({threshold, rootMargin}) => {
|
|
75
|
+
const useInView = ({ threshold, rootMargin }) => {
|
|
114
76
|
const observer = ref(null);
|
|
115
77
|
const elRef = ref(null);
|
|
116
78
|
const inView = ref(false);
|
|
117
79
|
onMounted(() => {
|
|
118
|
-
if (isIntersectionObserverAvailable) {
|
|
80
|
+
if (isIntersectionObserverAvailable()) {
|
|
119
81
|
observer.value = new IntersectionObserver((entries) => {
|
|
120
82
|
const image = entries[0];
|
|
121
83
|
if (image.isIntersecting && observer.value) {
|
|
@@ -132,32 +94,32 @@ const useInView = ({threshold, rootMargin}) => {
|
|
|
132
94
|
}
|
|
133
95
|
});
|
|
134
96
|
onBeforeUnmount(() => {
|
|
135
|
-
if (isIntersectionObserverAvailable && observer.value) {
|
|
97
|
+
if (isIntersectionObserverAvailable() && observer.value) {
|
|
136
98
|
observer.value.disconnect();
|
|
137
99
|
}
|
|
138
100
|
});
|
|
139
|
-
return {inView, elRef};
|
|
101
|
+
return { inView, elRef };
|
|
140
102
|
};
|
|
141
|
-
const imageAddStrategy = ({lazyLoad, inView, loaded}) => {
|
|
103
|
+
const imageAddStrategy = ({ lazyLoad, inView, loaded }) => {
|
|
142
104
|
if (!lazyLoad) {
|
|
143
105
|
return true;
|
|
144
106
|
}
|
|
145
|
-
if (isSsr) {
|
|
107
|
+
if (isSsr()) {
|
|
146
108
|
return false;
|
|
147
109
|
}
|
|
148
|
-
if (isIntersectionObserverAvailable) {
|
|
110
|
+
if (isIntersectionObserverAvailable()) {
|
|
149
111
|
return inView || loaded;
|
|
150
112
|
}
|
|
151
113
|
return true;
|
|
152
114
|
};
|
|
153
|
-
const imageShowStrategy = ({lazyLoad, loaded}) => {
|
|
115
|
+
const imageShowStrategy = ({ lazyLoad, loaded }) => {
|
|
154
116
|
if (!lazyLoad) {
|
|
155
117
|
return true;
|
|
156
118
|
}
|
|
157
|
-
if (isSsr) {
|
|
119
|
+
if (isSsr()) {
|
|
158
120
|
return false;
|
|
159
121
|
}
|
|
160
|
-
if (isIntersectionObserverAvailable) {
|
|
122
|
+
if (isIntersectionObserverAvailable()) {
|
|
161
123
|
return loaded;
|
|
162
124
|
}
|
|
163
125
|
return true;
|
|
@@ -203,7 +165,7 @@ const Image = defineComponent({
|
|
|
203
165
|
function handleLoad() {
|
|
204
166
|
loaded.value = true;
|
|
205
167
|
}
|
|
206
|
-
const {inView, elRef} = useInView({
|
|
168
|
+
const { inView, elRef } = useInView({
|
|
207
169
|
threshold: props.intersectionThreshold || props.intersectionTreshold || 0,
|
|
208
170
|
rootMargin: props.intersectionMargin || "0px 0px 0px 0px"
|
|
209
171
|
});
|
|
@@ -225,22 +187,18 @@ const Image = defineComponent({
|
|
|
225
187
|
inView: this.inView,
|
|
226
188
|
loaded: this.loaded
|
|
227
189
|
});
|
|
228
|
-
const webpSource = this.data.webpSrcSet &&
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
type: "image/webp"
|
|
233
|
-
}
|
|
190
|
+
const webpSource = this.data.webpSrcSet && h("source", {
|
|
191
|
+
srcset: this.data.webpSrcSet,
|
|
192
|
+
sizes: this.data.sizes,
|
|
193
|
+
type: "image/webp"
|
|
234
194
|
});
|
|
235
|
-
const regularSource = this.data.srcSet &&
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
sizes: this.data.sizes
|
|
239
|
-
}
|
|
195
|
+
const regularSource = this.data.srcSet && h("source", {
|
|
196
|
+
srcset: this.data.srcSet,
|
|
197
|
+
sizes: this.data.sizes
|
|
240
198
|
});
|
|
241
199
|
const transition = typeof this.fadeInDuration === "undefined" || this.fadeInDuration > 0 ? `opacity ${this.fadeInDuration || 500}ms ${this.fadeInDuration || 500}ms` : void 0;
|
|
242
|
-
const placeholder =
|
|
243
|
-
style:
|
|
200
|
+
const placeholder = h("div", {
|
|
201
|
+
style: __spreadValues$1({
|
|
244
202
|
backgroundImage: this.data.base64 ? `url(${this.data.base64})` : null,
|
|
245
203
|
backgroundColor: this.data.bgColor,
|
|
246
204
|
backgroundSize: "cover",
|
|
@@ -248,21 +206,19 @@ const Image = defineComponent({
|
|
|
248
206
|
transition
|
|
249
207
|
}, absolutePositioning)
|
|
250
208
|
});
|
|
251
|
-
const {width, aspectRatio} = this.data;
|
|
209
|
+
const { width, aspectRatio } = this.data;
|
|
252
210
|
const height = this.data.height || width / aspectRatio;
|
|
253
211
|
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}"></svg>`;
|
|
254
|
-
const sizer =
|
|
212
|
+
const sizer = h("img", {
|
|
255
213
|
class: this.pictureClass,
|
|
256
|
-
style:
|
|
214
|
+
style: __spreadValues$1({
|
|
257
215
|
display: "block",
|
|
258
216
|
width: this.explicitWidth ? `${width}px` : "100%"
|
|
259
217
|
}, this.pictureStyle),
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
role: "presentation"
|
|
263
|
-
}
|
|
218
|
+
src: `data:image/svg+xml;base64,${universalBtoa(svg)}`,
|
|
219
|
+
role: "presentation"
|
|
264
220
|
});
|
|
265
|
-
return
|
|
221
|
+
return h("div", {
|
|
266
222
|
style: {
|
|
267
223
|
display: this.explicitWidth ? "inline-block" : "block",
|
|
268
224
|
overflow: "hidden",
|
|
@@ -272,47 +228,41 @@ const Image = defineComponent({
|
|
|
272
228
|
}, [
|
|
273
229
|
sizer,
|
|
274
230
|
placeholder,
|
|
275
|
-
addImage &&
|
|
231
|
+
addImage && h("picture", null, [
|
|
276
232
|
webpSource,
|
|
277
233
|
regularSource,
|
|
278
|
-
this.data.src &&
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
},
|
|
284
|
-
on: {
|
|
285
|
-
load: this.handleLoad
|
|
286
|
-
},
|
|
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,
|
|
287
239
|
class: this.pictureClass,
|
|
288
|
-
style:
|
|
240
|
+
style: __spreadProps$1(__spreadValues$1(__spreadValues$1({}, absolutePositioning), this.pictureStyle), {
|
|
289
241
|
opacity: showImage ? 1 : 0,
|
|
290
242
|
transition
|
|
291
243
|
})
|
|
292
244
|
})
|
|
293
245
|
]),
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
this.data.webpSrcSet
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
this.data.srcSet
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
])
|
|
315
|
-
}
|
|
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
|
+
])
|
|
316
266
|
})
|
|
317
267
|
]);
|
|
318
268
|
}
|
|
@@ -323,43 +273,18 @@ const DatocmsImagePlugin = {
|
|
|
323
273
|
}
|
|
324
274
|
};
|
|
325
275
|
|
|
326
|
-
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
327
|
-
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
328
|
-
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
329
|
-
var __objRest = (source, exclude) => {
|
|
330
|
-
var target = {};
|
|
331
|
-
for (var prop in source)
|
|
332
|
-
if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
333
|
-
target[prop] = source[prop];
|
|
334
|
-
if (source != null && __getOwnPropSymbols$1)
|
|
335
|
-
for (var prop of __getOwnPropSymbols$1(source)) {
|
|
336
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
|
|
337
|
-
target[prop] = source[prop];
|
|
338
|
-
}
|
|
339
|
-
return target;
|
|
340
|
-
};
|
|
341
276
|
const hAdapter = (tagName, props, childOrChildren) => {
|
|
342
|
-
|
|
343
|
-
if (props) {
|
|
344
|
-
const _a = props, {key} = _a, attrs = __objRest(_a, ["key"]);
|
|
345
|
-
data = {key, attrs};
|
|
346
|
-
}
|
|
347
|
-
return crossH(tagName, data, Array.isArray(childOrChildren) ? childOrChildren : [childOrChildren]);
|
|
277
|
+
return h(tagName, props, Array.isArray(childOrChildren) ? childOrChildren : [childOrChildren]);
|
|
348
278
|
};
|
|
349
279
|
const defaultAdapter = {
|
|
350
280
|
renderNode: hAdapter,
|
|
351
281
|
renderMark: hAdapter,
|
|
352
|
-
renderFragment: (children, key) =>
|
|
282
|
+
renderFragment: (children, key) => children,
|
|
353
283
|
renderText: (text, key) => text
|
|
354
284
|
};
|
|
355
285
|
function appendKeyToValidElement(element, key) {
|
|
356
|
-
if (
|
|
357
|
-
|
|
358
|
-
return vueDemi.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
|
});
|