@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/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,
@@ -127,11 +133,24 @@
127
133
  }
128
134
  };
129
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
+
130
149
  var Link = (function (_ref) {
131
150
  var _ref$component = _ref.component,
132
- component = _ref$component === void 0 ? 'a' : _ref$component;
151
+ component = _ref$component === void 0 ? "a" : _ref$component;
133
152
  return {
134
- name: 'PrismicLink',
153
+ name: "PrismicLink",
135
154
  functional: true,
136
155
  props: {
137
156
  field: {
@@ -141,6 +160,21 @@
141
160
  linkResolver: {
142
161
  type: Function,
143
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
144
178
  }
145
179
  },
146
180
  render: function render(h, _ref2) {
@@ -155,11 +189,11 @@
155
189
  return null;
156
190
  }
157
191
 
158
- 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 () {
159
193
  return null;
160
194
  });
161
195
 
162
- if (url.indexOf('/') === 0) {
196
+ if (isInternalURL(url) && !props.target) {
163
197
  data.props = data.props || {};
164
198
  data.props.to = url;
165
199
  return h(component, data, children);
@@ -167,23 +201,33 @@
167
201
 
168
202
  data.attrs = _objectSpread2(_objectSpread2({}, data.attrs), {}, {
169
203
  href: url
170
- }, field.target && {
171
- target: field.target,
172
- rel: 'noopener'
173
204
  });
174
- return h('a', data, children);
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);
175
215
  }
176
216
  };
177
217
  });
178
218
 
179
219
  var RichText = {
180
- name: 'PrismicRichText',
220
+ name: "PrismicRichText",
181
221
  functional: true,
182
222
  props: {
183
223
  field: {
184
224
  type: Array,
185
225
  required: true
186
226
  },
227
+ linkResolver: {
228
+ type: Function,
229
+ required: false
230
+ },
187
231
  htmlSerializer: {
188
232
  type: Function,
189
233
  required: false
@@ -191,15 +235,15 @@
191
235
  wrapper: {
192
236
  type: String,
193
237
  required: false,
194
- "default": 'div'
238
+ "default": "div"
195
239
  }
196
240
  },
197
241
  render: function render(h, _ref) {
198
242
  var props = _ref.props,
199
243
  data = _ref.data,
200
- children = _ref.children,
201
244
  parent = _ref.parent;
202
245
  var field = props.field,
246
+ linkResolver = props.linkResolver,
203
247
  htmlSerializer = props.htmlSerializer,
204
248
  wrapper = props.wrapper;
205
249
 
@@ -207,7 +251,7 @@
207
251
  return null;
208
252
  }
209
253
 
210
- 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);
211
255
  return h(wrapper, _objectSpread2(_objectSpread2({}, data), {}, {
212
256
  domProps: {
213
257
  innerHTML: innerHTML
@@ -216,17 +260,203 @@
216
260
  }
217
261
  };
218
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
+
219
447
  var NuxtLink = Link({
220
- component: 'nuxt-link'
448
+ component: "nuxt-link"
221
449
  });
222
450
  var VueRouterLink = Link({
223
- component: 'router-link'
451
+ component: "router-link"
224
452
  });
225
453
  var exp = {
226
454
  common: {
227
455
  Embed: Embed,
228
456
  Image: Image,
229
- RichText: RichText
457
+ RichText: RichText,
458
+ Text: Text,
459
+ SliceZone: SliceZone
230
460
  },
231
461
  nuxt: {
232
462
  Link: NuxtLink
@@ -235,16 +465,21 @@
235
465
  Link: VueRouterLink
236
466
  }
237
467
  };
468
+ exp.common;
469
+ exp.nuxt;
470
+ exp.vueRouter;
238
471
 
239
- var common$1 = exp.common;
240
- var nuxt$1 = exp.nuxt;
241
- var vueRouter$1 = exp.vueRouter;
472
+ var common = exp.common;
473
+ var nuxt = exp.nuxt;
474
+ var vueRouter = exp.vueRouter;
242
475
 
243
- exports.common = common$1;
244
- exports.nuxt = nuxt$1;
245
- exports.vueRouter = vueRouter$1;
246
- exports.default = exp;
476
+ exports.common = common;
477
+ exports["default"] = exp;
478
+ exports.defineSliceZoneComponents = defineSliceZoneComponents;
479
+ exports.getSliceComponentProps = getSliceComponentProps;
480
+ exports.nuxt = nuxt;
481
+ exports.vueRouter = vueRouter;
247
482
 
248
483
  Object.defineProperty(exports, '__esModule', { value: true });
249
484
 
250
- })));
485
+ }));