@prismicio/vue 2.0.9 → 2.1.0-alpha.1

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