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