@prismicio/vue 2.0.11 → 2.1.0-alpha.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/LICENSE +202 -0
- package/README.md +81 -149
- package/components/common.js +275 -41
- package/components/index.js +269 -39
- package/components/umd.js +278 -43
- package/dist/prismic-vue.common.js +278 -48
- package/dist/prismic-vue.esm.js +270 -42
- package/dist/prismic-vue.js +282 -52
- package/dist/prismic-vue.min.js +1 -1
- package/package.json +51 -47
- package/src/components/Link.js +87 -51
- package/src/components/RichText.js +40 -41
- package/src/components/SliceZone.js +144 -0
- package/src/components/Text.js +37 -0
- package/src/components/index.js +26 -22
- package/src/components-bundler.js +10 -5
- package/src/index.js +46 -39
package/components/common.js
CHANGED
|
@@ -2,34 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
-
|
|
7
5
|
var PrismicDom = require('prismic-dom');
|
|
8
|
-
var PrismicDom__default = _interopDefault(PrismicDom);
|
|
9
6
|
|
|
10
|
-
function
|
|
11
|
-
if (key in obj) {
|
|
12
|
-
Object.defineProperty(obj, key, {
|
|
13
|
-
value: value,
|
|
14
|
-
enumerable: true,
|
|
15
|
-
configurable: true,
|
|
16
|
-
writable: true
|
|
17
|
-
});
|
|
18
|
-
} else {
|
|
19
|
-
obj[key] = value;
|
|
20
|
-
}
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
21
8
|
|
|
22
|
-
|
|
23
|
-
}
|
|
9
|
+
var PrismicDom__default = /*#__PURE__*/_interopDefaultLegacy(PrismicDom);
|
|
24
10
|
|
|
25
11
|
function ownKeys(object, enumerableOnly) {
|
|
26
12
|
var keys = Object.keys(object);
|
|
27
13
|
|
|
28
14
|
if (Object.getOwnPropertySymbols) {
|
|
29
15
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
|
|
17
|
+
if (enumerableOnly) {
|
|
18
|
+
symbols = symbols.filter(function (sym) {
|
|
19
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
33
23
|
keys.push.apply(keys, symbols);
|
|
34
24
|
}
|
|
35
25
|
|
|
@@ -56,6 +46,21 @@ function _objectSpread2(target) {
|
|
|
56
46
|
return target;
|
|
57
47
|
}
|
|
58
48
|
|
|
49
|
+
function _defineProperty(obj, key, value) {
|
|
50
|
+
if (key in obj) {
|
|
51
|
+
Object.defineProperty(obj, key, {
|
|
52
|
+
value: value,
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
obj[key] = value;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return obj;
|
|
62
|
+
}
|
|
63
|
+
|
|
59
64
|
var Embed = {
|
|
60
65
|
name: 'PrismicEmbed',
|
|
61
66
|
functional: true,
|
|
@@ -128,11 +133,24 @@ var Image = {
|
|
|
128
133
|
}
|
|
129
134
|
};
|
|
130
135
|
|
|
136
|
+
var isInternalURL = function isInternalURL(url) {
|
|
137
|
+
/**
|
|
138
|
+
* @see Regex101 expression: {@link https://regex101.com/r/1y7iod/1}
|
|
139
|
+
*/
|
|
140
|
+
var isInternal = /^\/(?!\/)/.test(url);
|
|
141
|
+
/**
|
|
142
|
+
* @see Regex101 expression: {@link https://regex101.com/r/RnUseS/1}
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
var isSpecialLink = !isInternal && !/^https?:\/\//i.test(url);
|
|
146
|
+
return isInternal && !isSpecialLink;
|
|
147
|
+
};
|
|
148
|
+
|
|
131
149
|
var Link = (function (_ref) {
|
|
132
150
|
var _ref$component = _ref.component,
|
|
133
|
-
component = _ref$component === void 0 ?
|
|
151
|
+
component = _ref$component === void 0 ? "a" : _ref$component;
|
|
134
152
|
return {
|
|
135
|
-
name:
|
|
153
|
+
name: "PrismicLink",
|
|
136
154
|
functional: true,
|
|
137
155
|
props: {
|
|
138
156
|
field: {
|
|
@@ -142,6 +160,21 @@ var Link = (function (_ref) {
|
|
|
142
160
|
linkResolver: {
|
|
143
161
|
type: Function,
|
|
144
162
|
required: false
|
|
163
|
+
},
|
|
164
|
+
target: {
|
|
165
|
+
type: String,
|
|
166
|
+
"default": undefined,
|
|
167
|
+
required: false
|
|
168
|
+
},
|
|
169
|
+
rel: {
|
|
170
|
+
type: String,
|
|
171
|
+
"default": undefined,
|
|
172
|
+
required: false
|
|
173
|
+
},
|
|
174
|
+
blankTargetRelAttribute: {
|
|
175
|
+
type: String,
|
|
176
|
+
"default": "noopener",
|
|
177
|
+
required: false
|
|
145
178
|
}
|
|
146
179
|
},
|
|
147
180
|
render: function render(h, _ref2) {
|
|
@@ -156,11 +189,11 @@ var Link = (function (_ref) {
|
|
|
156
189
|
return null;
|
|
157
190
|
}
|
|
158
191
|
|
|
159
|
-
var url = parent.$prismic ? parent.$prismic.asLink(field, linkResolver) : PrismicDom__default.Link.url(field, linkResolver || function () {
|
|
192
|
+
var url = parent.$prismic ? parent.$prismic.asLink(field, linkResolver) : PrismicDom__default["default"].Link.url(field, linkResolver || function () {
|
|
160
193
|
return null;
|
|
161
194
|
});
|
|
162
195
|
|
|
163
|
-
if (url
|
|
196
|
+
if (isInternalURL(url) && !props.target) {
|
|
164
197
|
data.props = data.props || {};
|
|
165
198
|
data.props.to = url;
|
|
166
199
|
return h(component, data, children);
|
|
@@ -168,23 +201,33 @@ var Link = (function (_ref) {
|
|
|
168
201
|
|
|
169
202
|
data.attrs = _objectSpread2(_objectSpread2({}, data.attrs), {}, {
|
|
170
203
|
href: url
|
|
171
|
-
}, field.target && {
|
|
172
|
-
target: field.target,
|
|
173
|
-
rel: 'noopener'
|
|
174
204
|
});
|
|
175
|
-
|
|
205
|
+
|
|
206
|
+
if (typeof props.target !== "undefined" || field.target) {
|
|
207
|
+
data.attrs.target = typeof props.target !== "undefined" ? props.target : field.target;
|
|
208
|
+
|
|
209
|
+
if (data.attrs.target === "_blank") {
|
|
210
|
+
data.attrs.rel = typeof props.rel !== "undefined" ? props.rel : props.blankTargetRelAttribute;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return h("a", data, children);
|
|
176
215
|
}
|
|
177
216
|
};
|
|
178
217
|
});
|
|
179
218
|
|
|
180
219
|
var RichText = {
|
|
181
|
-
name:
|
|
220
|
+
name: "PrismicRichText",
|
|
182
221
|
functional: true,
|
|
183
222
|
props: {
|
|
184
223
|
field: {
|
|
185
224
|
type: Array,
|
|
186
225
|
required: true
|
|
187
226
|
},
|
|
227
|
+
linkResolver: {
|
|
228
|
+
type: Function,
|
|
229
|
+
required: false
|
|
230
|
+
},
|
|
188
231
|
htmlSerializer: {
|
|
189
232
|
type: Function,
|
|
190
233
|
required: false
|
|
@@ -192,15 +235,15 @@ var RichText = {
|
|
|
192
235
|
wrapper: {
|
|
193
236
|
type: String,
|
|
194
237
|
required: false,
|
|
195
|
-
"default":
|
|
238
|
+
"default": "div"
|
|
196
239
|
}
|
|
197
240
|
},
|
|
198
241
|
render: function render(h, _ref) {
|
|
199
242
|
var props = _ref.props,
|
|
200
243
|
data = _ref.data,
|
|
201
|
-
children = _ref.children,
|
|
202
244
|
parent = _ref.parent;
|
|
203
245
|
var field = props.field,
|
|
246
|
+
linkResolver = props.linkResolver,
|
|
204
247
|
htmlSerializer = props.htmlSerializer,
|
|
205
248
|
wrapper = props.wrapper;
|
|
206
249
|
|
|
@@ -208,7 +251,7 @@ var RichText = {
|
|
|
208
251
|
return null;
|
|
209
252
|
}
|
|
210
253
|
|
|
211
|
-
var innerHTML = PrismicDom.RichText.asHtml(field, parent.$prismic.linkResolver, htmlSerializer || parent.$prismic.htmlSerializer);
|
|
254
|
+
var innerHTML = PrismicDom.RichText.asHtml(field, linkResolver || parent.$prismic.linkResolver, htmlSerializer || parent.$prismic.htmlSerializer);
|
|
212
255
|
return h(wrapper, _objectSpread2(_objectSpread2({}, data), {}, {
|
|
213
256
|
domProps: {
|
|
214
257
|
innerHTML: innerHTML
|
|
@@ -217,17 +260,203 @@ var RichText = {
|
|
|
217
260
|
}
|
|
218
261
|
};
|
|
219
262
|
|
|
263
|
+
var Text = {
|
|
264
|
+
name: "PrismicText",
|
|
265
|
+
functional: true,
|
|
266
|
+
props: {
|
|
267
|
+
field: {
|
|
268
|
+
type: Array,
|
|
269
|
+
required: true
|
|
270
|
+
},
|
|
271
|
+
separator: {
|
|
272
|
+
type: String,
|
|
273
|
+
"default": undefined,
|
|
274
|
+
required: false
|
|
275
|
+
},
|
|
276
|
+
wrapper: {
|
|
277
|
+
type: String,
|
|
278
|
+
required: false,
|
|
279
|
+
"default": "div"
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
render: function render(h, _ref) {
|
|
283
|
+
var props = _ref.props,
|
|
284
|
+
data = _ref.data;
|
|
285
|
+
_ref.children;
|
|
286
|
+
_ref.parent;
|
|
287
|
+
var field = props.field,
|
|
288
|
+
separator = props.separator,
|
|
289
|
+
wrapper = props.wrapper;
|
|
290
|
+
|
|
291
|
+
if (!field) {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
var innerHTML = PrismicDom.RichText.asText(field, separator);
|
|
296
|
+
return h(wrapper, _objectSpread2(_objectSpread2({}, data), {}, {
|
|
297
|
+
domProps: {
|
|
298
|
+
innerHTML: innerHTML
|
|
299
|
+
}
|
|
300
|
+
}));
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
// We need to polyfill process if it doesn't exist, such as in the browser.
|
|
305
|
+
if (typeof process === "undefined") {
|
|
306
|
+
globalThis.process = {
|
|
307
|
+
env: {}
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* `true` if in the production environment, `false` otherwise.
|
|
312
|
+
*
|
|
313
|
+
* This boolean can be used to perform actions only in development environments,
|
|
314
|
+
* such as logging.
|
|
315
|
+
*/
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
var __PRODUCTION__ = process.env.NODE_ENV === "production";
|
|
319
|
+
|
|
320
|
+
var getSliceComponentProps = function getSliceComponentProps(propsHint) {
|
|
321
|
+
return {
|
|
322
|
+
slice: {
|
|
323
|
+
type: Object,
|
|
324
|
+
required: true
|
|
325
|
+
},
|
|
326
|
+
index: {
|
|
327
|
+
type: Number,
|
|
328
|
+
required: true
|
|
329
|
+
},
|
|
330
|
+
slices: {
|
|
331
|
+
type: Array,
|
|
332
|
+
required: true
|
|
333
|
+
},
|
|
334
|
+
context: {
|
|
335
|
+
type: null,
|
|
336
|
+
required: true
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
var TODOSliceComponent = __PRODUCTION__ ? function () {
|
|
341
|
+
return null;
|
|
342
|
+
} : {
|
|
343
|
+
name: "TODOSliceCOmponent",
|
|
344
|
+
functional: true,
|
|
345
|
+
props: getSliceComponentProps(),
|
|
346
|
+
renfer: function renfer(h, _ref) {
|
|
347
|
+
var props = _ref.props,
|
|
348
|
+
data = _ref.data;
|
|
349
|
+
console.warn("[SliceZone] Could not find a component for Slice type \"".concat(props.slice.slice_type, "\""), props.slice);
|
|
350
|
+
return function () {
|
|
351
|
+
return h("section", _objectSpread2(_objectSpread2({}, data), {}, {
|
|
352
|
+
"data-slice-zone-todo-component": "",
|
|
353
|
+
"data-slice-type": props.slice.slice_type
|
|
354
|
+
}), ["Could not find a component for Slice type \"".concat(props.slice.slice_type, "\"")]);
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
}; // Just mimiced to prevent confusion but doesn't provide any value with version 2 of this kit
|
|
358
|
+
|
|
359
|
+
var defineSliceZoneComponents = function defineSliceZoneComponents(components) {
|
|
360
|
+
return components;
|
|
361
|
+
};
|
|
362
|
+
var SliceZone = {
|
|
363
|
+
name: "SliceZone",
|
|
364
|
+
functional: true,
|
|
365
|
+
props: {
|
|
366
|
+
slices: {
|
|
367
|
+
type: Array,
|
|
368
|
+
required: true
|
|
369
|
+
},
|
|
370
|
+
components: {
|
|
371
|
+
type: Object,
|
|
372
|
+
"default": undefined,
|
|
373
|
+
required: false
|
|
374
|
+
},
|
|
375
|
+
resolver: {
|
|
376
|
+
type: Function,
|
|
377
|
+
"default": undefined,
|
|
378
|
+
required: false
|
|
379
|
+
},
|
|
380
|
+
context: {
|
|
381
|
+
type: null,
|
|
382
|
+
"default": undefined,
|
|
383
|
+
required: false
|
|
384
|
+
},
|
|
385
|
+
defaultComponent: {
|
|
386
|
+
type: Object,
|
|
387
|
+
"default": undefined,
|
|
388
|
+
required: false
|
|
389
|
+
},
|
|
390
|
+
wrapper: {
|
|
391
|
+
type: [String, Object, Function],
|
|
392
|
+
"default": "div",
|
|
393
|
+
required: false
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
render: function render(h, _ref2) {
|
|
397
|
+
var props = _ref2.props,
|
|
398
|
+
data = _ref2.data;
|
|
399
|
+
|
|
400
|
+
// Prevent fatal if user didn't check for field, throws `Invalid prop` warn
|
|
401
|
+
if (!props.slices) {
|
|
402
|
+
return function () {
|
|
403
|
+
return null;
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
var renderedSlices = computed(function () {
|
|
408
|
+
return props.slices.map(function (slice, index) {
|
|
409
|
+
var component = props.components && slice.slice_type in props.components ? props.components[slice.slice_type] : props.defaultComponent || TODOSliceComponent; // TODO: Remove `resolver` in v3 in favor of `components`.
|
|
410
|
+
|
|
411
|
+
if (props.resolver) {
|
|
412
|
+
var resolvedComponent = props.resolver({
|
|
413
|
+
slice: slice,
|
|
414
|
+
sliceName: slice.slice_type,
|
|
415
|
+
i: index
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
if (resolvedComponent) {
|
|
419
|
+
component = resolvedComponent;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
var p = {
|
|
424
|
+
key: "".concat(slice.slice_type, "-").concat(index),
|
|
425
|
+
slice: slice,
|
|
426
|
+
index: index,
|
|
427
|
+
context: props.context,
|
|
428
|
+
slices: props.slices
|
|
429
|
+
};
|
|
430
|
+
return h(component, p);
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
var parent = props.wrapper;
|
|
434
|
+
|
|
435
|
+
if (typeof parent === "string") {
|
|
436
|
+
return h(parent, data, renderedSlices.value);
|
|
437
|
+
} else {
|
|
438
|
+
return h(parent, data, {
|
|
439
|
+
"default": function _default() {
|
|
440
|
+
return renderedSlices.value;
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
|
|
220
447
|
var NuxtLink = Link({
|
|
221
|
-
component:
|
|
448
|
+
component: "nuxt-link"
|
|
222
449
|
});
|
|
223
450
|
var VueRouterLink = Link({
|
|
224
|
-
component:
|
|
451
|
+
component: "router-link"
|
|
225
452
|
});
|
|
226
453
|
var exp = {
|
|
227
454
|
common: {
|
|
228
455
|
Embed: Embed,
|
|
229
456
|
Image: Image,
|
|
230
|
-
RichText: RichText
|
|
457
|
+
RichText: RichText,
|
|
458
|
+
Text: Text,
|
|
459
|
+
SliceZone: SliceZone
|
|
231
460
|
},
|
|
232
461
|
nuxt: {
|
|
233
462
|
Link: NuxtLink
|
|
@@ -236,12 +465,17 @@ var exp = {
|
|
|
236
465
|
Link: VueRouterLink
|
|
237
466
|
}
|
|
238
467
|
};
|
|
468
|
+
exp.common;
|
|
469
|
+
exp.nuxt;
|
|
470
|
+
exp.vueRouter;
|
|
239
471
|
|
|
240
|
-
var common
|
|
241
|
-
var nuxt
|
|
242
|
-
var vueRouter
|
|
472
|
+
var common = exp.common;
|
|
473
|
+
var nuxt = exp.nuxt;
|
|
474
|
+
var vueRouter = exp.vueRouter;
|
|
243
475
|
|
|
244
|
-
exports.common = common
|
|
245
|
-
exports
|
|
246
|
-
exports.
|
|
247
|
-
exports.
|
|
476
|
+
exports.common = common;
|
|
477
|
+
exports["default"] = exp;
|
|
478
|
+
exports.defineSliceZoneComponents = defineSliceZoneComponents;
|
|
479
|
+
exports.getSliceComponentProps = getSliceComponentProps;
|
|
480
|
+
exports.nuxt = nuxt;
|
|
481
|
+
exports.vueRouter = vueRouter;
|