vue-datocms 2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-datocms",
3
- "version": "2.0.0",
3
+ "version": "3.0.0-0",
4
4
  "description": "A set of components and utilities to work faster with DatoCMS in Vue.js environments",
5
5
  "keywords": [
6
6
  "datocms",
@@ -8,52 +8,62 @@
8
8
  "vue",
9
9
  "vuejs"
10
10
  ],
11
- "main": "./dist/index.umd.js",
12
- "module": "./dist/index.esm.js",
13
- "unpkg": "./dist/index.min.js",
11
+ "main": "./dist/index.cjs.js",
12
+ "module": "./dist/index.esm.mjs",
14
13
  "types": "./dist/index.d.ts",
15
14
  "license": "MIT",
16
15
  "exports": {
17
16
  ".": {
18
- "import": "./dist/index.esm.js",
19
- "require": "./dist/index.umd.js"
17
+ "import": "./dist/index.esm.mjs",
18
+ "require": "./dist/index.cjs.js"
20
19
  }
21
20
  },
22
21
  "files": [
23
22
  "dist/*"
24
23
  ],
25
24
  "scripts": {
26
- "build": "rimraf dist && rollup -c",
27
- "prepublishOnly": "npm run test && npm run build",
28
- "test": "jest src"
25
+ "build": "rimraf dist && rollup --config",
26
+ "dev": "rollup --config --watch",
27
+ "prepublishOnly": "npm run test",
28
+ "pretest": "npm run build",
29
+ "test": "jest --coverage"
29
30
  },
30
31
  "dependencies": {
32
+ "datocms-listen": "^0.1.10",
31
33
  "datocms-structured-text-generic-html-renderer": "^2.0.4",
32
34
  "datocms-structured-text-utils": "^2.0.4",
33
- "hyphenate-style-name": "^1.0.4"
35
+ "hyphenate-style-name": "^1.0.4",
36
+ "vue-demi": "^0.13.11"
34
37
  },
35
38
  "peerDependencies": {
36
- "vue": "3"
39
+ "@vue/composition-api": "^1.7.1",
40
+ "vue": "^2.0.0 || >=3.0.0"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "@vue/composition-api": {
44
+ "optional": true
45
+ }
37
46
  },
38
47
  "devDependencies": {
39
48
  "@types/hyphenate-style-name": "^1.0.0",
40
- "@types/jest": "^28.1.1",
49
+ "@types/jest": "^29.1.1",
41
50
  "@types/node": "^14.14.41",
42
- "@vue/test-utils": "^2.0.0-rc.6",
43
- "@vue/vue3-jest": "^28.0.0",
51
+ "@vue/test-utils": "^2.1.0",
44
52
  "@vuedx/typescript-plugin-vue": "^0.6.3",
45
- "jest": "^28.1.1",
46
- "jest-environment-jsdom": "^28.1.1",
53
+ "esbuild": "^0.15.10",
54
+ "jest": "^29.1.2",
55
+ "jest-environment-jsdom": "^29.1.2",
47
56
  "jest-serializer-vue": "^2.0.2",
48
57
  "jsdom": "^19.0.0",
49
58
  "np": "^7.6.1",
50
59
  "rimraf": "^2.7.1",
51
60
  "rollup": "^2.45.2",
52
- "rollup-plugin-dts": "^3.0.1",
53
- "rollup-plugin-esbuild": "^4.1.0",
54
- "ts-jest": "^28.0.5",
55
- "typescript": "^4.7.3",
56
- "vue": "^3.2.25",
61
+ "rollup-plugin-dts": "^4.2.2",
62
+ "rollup-plugin-esbuild": "^4.10.1",
63
+ "ts-jest": "^29.0.3",
64
+ "tslib": "^2.4.0",
65
+ "typescript": "^4.8.4",
66
+ "vue": "^3.2.40",
57
67
  "vue-tsc": "^0.37.9"
58
68
  }
59
69
  }
package/dist/index.esm.js DELETED
@@ -1,435 +0,0 @@
1
- import hypenateStyleName from 'hyphenate-style-name';
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
- export { RenderError } from 'datocms-structured-text-utils';
7
-
8
- var __defProp$1 = Object.defineProperty;
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) => {
16
- for (var prop in b || (b = {}))
17
- if (__hasOwnProp$1.call(b, prop))
18
- __defNormalProp$1(a, prop, b[prop]);
19
- if (__getOwnPropSymbols$1)
20
- for (var prop of __getOwnPropSymbols$1(b)) {
21
- if (__propIsEnum$1.call(b, prop))
22
- __defNormalProp$1(a, prop, b[prop]);
23
- }
24
- return a;
25
- };
26
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
27
- const escape = (s) => {
28
- s = "" + s;
29
- s = s.replace(/&/g, "&");
30
- s = s.replace(/</g, "&lt;");
31
- s = s.replace(/>/g, "&gt;");
32
- s = s.replace(/"/g, "&quot;");
33
- s = s.replace(/'/g, "&#39;");
34
- return s;
35
- };
36
- const toCss = (object) => {
37
- if (!object) {
38
- return null;
39
- }
40
- let result = "";
41
- for (var styleName in object) {
42
- if (Object.prototype.hasOwnProperty.call(object, styleName) && object[styleName]) {
43
- result += `${hypenateStyleName(styleName)}: ${object[styleName]}; `;
44
- }
45
- }
46
- return result.length > 0 ? result : null;
47
- };
48
- const tag = (tagName, attrs, content) => {
49
- const serializedAttrs = [];
50
- if (attrs) {
51
- for (var attrName in attrs) {
52
- if (Object.prototype.hasOwnProperty.call(attrs, attrName)) {
53
- const value = attrs[attrName];
54
- if (value) {
55
- serializedAttrs.push(`${escape(attrName)}="${escape(value)}"`);
56
- }
57
- }
58
- }
59
- }
60
- const attrsString = serializedAttrs.length > 0 ? ` ${serializedAttrs.join(" ")}` : "";
61
- return content ? `<${tagName}${attrsString}>${content.join("")}</${tagName}>` : `<${tagName}${attrsString} />`;
62
- };
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);
68
- const absolutePositioning = {
69
- position: "absolute",
70
- left: "0px",
71
- top: "0px",
72
- width: "100%",
73
- height: "100%"
74
- };
75
- const useInView = ({ threshold, rootMargin }) => {
76
- const observer = ref(null);
77
- const elRef = ref(null);
78
- const inView = ref(false);
79
- onMounted(() => {
80
- if (isIntersectionObserverAvailable()) {
81
- observer.value = new IntersectionObserver((entries) => {
82
- const image = entries[0];
83
- if (image.isIntersecting && observer.value) {
84
- inView.value = true;
85
- observer.value.disconnect();
86
- }
87
- }, {
88
- threshold,
89
- rootMargin
90
- });
91
- if (elRef.value) {
92
- observer.value.observe(elRef.value);
93
- }
94
- }
95
- });
96
- onBeforeUnmount(() => {
97
- if (isIntersectionObserverAvailable() && observer.value) {
98
- observer.value.disconnect();
99
- }
100
- });
101
- return { inView, elRef };
102
- };
103
- const imageAddStrategy = ({ lazyLoad, inView, loaded }) => {
104
- if (!lazyLoad) {
105
- return true;
106
- }
107
- if (isSsr()) {
108
- return false;
109
- }
110
- if (isIntersectionObserverAvailable()) {
111
- return inView || loaded;
112
- }
113
- return true;
114
- };
115
- const imageShowStrategy = ({ lazyLoad, loaded }) => {
116
- if (!lazyLoad) {
117
- return true;
118
- }
119
- if (isSsr()) {
120
- return false;
121
- }
122
- if (isIntersectionObserverAvailable()) {
123
- return loaded;
124
- }
125
- return true;
126
- };
127
- const Image = defineComponent({
128
- name: "DatocmsImage",
129
- props: {
130
- data: {
131
- type: Object,
132
- required: true
133
- },
134
- pictureClass: {
135
- type: String
136
- },
137
- fadeInDuration: {
138
- type: Number
139
- },
140
- intersectionTreshold: {
141
- type: Number,
142
- default: 0
143
- },
144
- intersectionThreshold: {
145
- type: Number
146
- },
147
- intersectionMargin: {
148
- type: String,
149
- default: "0px 0px 0px 0px"
150
- },
151
- lazyLoad: {
152
- type: Boolean,
153
- default: true
154
- },
155
- pictureStyle: {
156
- type: Object,
157
- default: () => ({})
158
- },
159
- explicitWidth: {
160
- type: Boolean
161
- }
162
- },
163
- setup(props) {
164
- const loaded = ref(false);
165
- function handleLoad() {
166
- loaded.value = true;
167
- }
168
- const { inView, elRef } = useInView({
169
- threshold: props.intersectionThreshold || props.intersectionTreshold || 0,
170
- rootMargin: props.intersectionMargin || "0px 0px 0px 0px"
171
- });
172
- return {
173
- inView,
174
- elRef,
175
- loaded,
176
- handleLoad
177
- };
178
- },
179
- render() {
180
- const addImage = imageAddStrategy({
181
- lazyLoad: this.lazyLoad,
182
- inView: this.inView,
183
- loaded: this.loaded
184
- });
185
- const showImage = imageShowStrategy({
186
- lazyLoad: this.lazyLoad,
187
- inView: this.inView,
188
- loaded: this.loaded
189
- });
190
- const webpSource = this.data.webpSrcSet && h("source", {
191
- srcset: this.data.webpSrcSet,
192
- sizes: this.data.sizes,
193
- type: "image/webp"
194
- });
195
- const regularSource = this.data.srcSet && h("source", {
196
- srcset: this.data.srcSet,
197
- sizes: this.data.sizes
198
- });
199
- const transition = typeof this.fadeInDuration === "undefined" || this.fadeInDuration > 0 ? `opacity ${this.fadeInDuration || 500}ms ${this.fadeInDuration || 500}ms` : void 0;
200
- const placeholder = h("div", {
201
- style: __spreadValues$1({
202
- backgroundImage: this.data.base64 ? `url(${this.data.base64})` : null,
203
- backgroundColor: this.data.bgColor,
204
- backgroundSize: "cover",
205
- opacity: showImage ? 0 : 1,
206
- transition
207
- }, absolutePositioning)
208
- });
209
- const { width, aspectRatio } = this.data;
210
- const height = this.data.height || width / aspectRatio;
211
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}"></svg>`;
212
- const sizer = h("img", {
213
- class: this.pictureClass,
214
- style: __spreadValues$1({
215
- display: "block",
216
- width: this.explicitWidth ? `${width}px` : "100%"
217
- }, this.pictureStyle),
218
- src: `data:image/svg+xml;base64,${universalBtoa(svg)}`,
219
- role: "presentation"
220
- });
221
- return h("div", {
222
- style: {
223
- display: this.explicitWidth ? "inline-block" : "block",
224
- overflow: "hidden",
225
- position: "relative"
226
- },
227
- ref: "elRef"
228
- }, [
229
- sizer,
230
- placeholder,
231
- addImage && h("picture", null, [
232
- webpSource,
233
- regularSource,
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,
239
- class: this.pictureClass,
240
- style: __spreadProps$1(__spreadValues$1(__spreadValues$1({}, absolutePositioning), this.pictureStyle), {
241
- opacity: showImage ? 1 : 0,
242
- transition
243
- })
244
- })
245
- ]),
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
- ])
266
- })
267
- ]);
268
- }
269
- });
270
- const DatocmsImagePlugin = {
271
- install: (Vue) => {
272
- Vue.component("DatocmsImage", Image);
273
- }
274
- };
275
-
276
- const hAdapter = (tagName, props, childOrChildren) => {
277
- return h(tagName, props, Array.isArray(childOrChildren) ? childOrChildren : [childOrChildren]);
278
- };
279
- const defaultAdapter = {
280
- renderNode: hAdapter,
281
- renderMark: hAdapter,
282
- renderFragment: (children, key) => children,
283
- renderText: (text, key) => text
284
- };
285
- function appendKeyToValidElement(element, key) {
286
- if (isVNode(element) && element.key === null) {
287
- return cloneVNode(element, { key });
288
- }
289
- return element;
290
- }
291
- const StructuredText = defineComponent({
292
- name: "DatocmsStructuredText",
293
- props: {
294
- data: {
295
- type: Object
296
- },
297
- customRules: {
298
- type: Array
299
- },
300
- customNodeRules: {
301
- type: Array
302
- },
303
- customMarkRules: {
304
- type: Array
305
- },
306
- renderInlineRecord: {
307
- type: Function
308
- },
309
- renderLinkToRecord: {
310
- type: Function
311
- },
312
- renderBlock: {
313
- type: Function
314
- },
315
- metaTransformer: { type: Function },
316
- renderText: { type: Function },
317
- renderNode: { type: Function },
318
- renderFragment: { type: Function }
319
- },
320
- setup(props) {
321
- return () => {
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
- });
383
- };
384
- }
385
- });
386
- const DatocmsStructuredTextPlugin = {
387
- install: (Vue) => {
388
- Vue.component("DatocmsStructuredText", StructuredText);
389
- }
390
- };
391
-
392
- var __defProp = Object.defineProperty;
393
- var __defProps = Object.defineProperties;
394
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
395
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
396
- var __hasOwnProp = Object.prototype.hasOwnProperty;
397
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
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) => {
400
- for (var prop in b || (b = {}))
401
- if (__hasOwnProp.call(b, prop))
402
- __defNormalProp(a, prop, b[prop]);
403
- if (__getOwnPropSymbols)
404
- for (var prop of __getOwnPropSymbols(b)) {
405
- if (__propIsEnum.call(b, prop))
406
- __defNormalProp(a, prop, b[prop]);
407
- }
408
- return a;
409
- };
410
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
411
- const toHead = (...args) => {
412
- const tags = [].concat(...args);
413
- const titleTag = tags && tags.find((t) => t.tag === "title");
414
- const metaTags = tags ? tags.filter((t) => t.tag === "meta") : [];
415
- const linkTags = tags ? tags.filter((t) => t.tag === "link") : [];
416
- return {
417
- title: titleTag && titleTag.content,
418
- meta: metaTags.map((tag) => {
419
- var _a, _b, _c, _d;
420
- return __spreadProps(__spreadValues({}, tag.attributes), {
421
- hid: ((_a = tag.attributes) == null ? void 0 : _a.name) || ((_b = tag.attributes) == null ? void 0 : _b.property),
422
- vmid: ((_c = tag.attributes) == null ? void 0 : _c.name) || ((_d = tag.attributes) == null ? void 0 : _d.property)
423
- });
424
- }),
425
- link: linkTags.map((tag) => {
426
- var _a, _b, _c, _d, _e, _f;
427
- return __spreadProps(__spreadValues({}, tag.attributes), {
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}`,
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}`
430
- });
431
- })
432
- };
433
- };
434
-
435
- export { DatocmsImagePlugin, DatocmsStructuredTextPlugin, Image, StructuredText, appendKeyToValidElement, defaultAdapter, toHead };