@prismicio/vue 4.1.0 → 4.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/vue",
3
- "version": "4.1.0",
3
+ "version": "4.2.1",
4
4
  "description": "Vue plugin, components, and composables to fetch and present Prismic content",
5
5
  "keywords": [
6
6
  "typescript",
@@ -57,38 +57,38 @@
57
57
  "test": "npm run lint && npm run types && npm run unit && npm run build && npm run size"
58
58
  },
59
59
  "dependencies": {
60
- "@prismicio/client": "^7.2.0",
60
+ "@prismicio/client": "^7.4.0",
61
61
  "isomorphic-unfetch": "^3.1.0",
62
- "vue-router": "^4.2.5"
62
+ "vue-router": "^4.3.0"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@prismicio/mock": "^0.3.1",
66
66
  "@size-limit/preset-small-lib": "^8.2.6",
67
- "@trivago/prettier-plugin-sort-imports": "^4.2.0",
68
- "@types/jsdom-global": "^3.0.5",
67
+ "@trivago/prettier-plugin-sort-imports": "^4.3.0",
68
+ "@types/jsdom-global": "^3.0.7",
69
69
  "@typescript-eslint/eslint-plugin": "^5.62.0",
70
70
  "@typescript-eslint/parser": "^5.62.0",
71
- "@vitejs/plugin-vue": "^4.3.4",
72
- "@vitest/coverage-v8": "^0.34.5",
73
- "@vue/compiler-sfc": "^3.3.4",
71
+ "@vitejs/plugin-vue": "^4.6.2",
72
+ "@vitest/coverage-v8": "^0.34.6",
73
+ "@vue/compiler-sfc": "^3.4.21",
74
74
  "@vue/eslint-config-typescript": "^11.0.3",
75
- "@vue/test-utils": "^2.4.1",
76
- "eslint": "^8.50.0",
75
+ "@vue/test-utils": "^2.4.5",
76
+ "eslint": "^8.57.0",
77
77
  "eslint-config-prettier": "^8.10.0",
78
78
  "eslint-plugin-prettier": "^4.2.1",
79
79
  "eslint-plugin-tsdoc": "^0.2.17",
80
- "eslint-plugin-vue": "^9.17.0",
81
- "jsdom": "^22.1.0",
80
+ "eslint-plugin-vue": "^9.24.0",
81
+ "jsdom": "^24.0.0",
82
82
  "jsdom-global": "^3.0.2",
83
83
  "prettier": "^2.8.8",
84
84
  "prettier-plugin-jsdoc": "^0.4.2",
85
85
  "size-limit": "^8.2.6",
86
86
  "standard-version": "^9.5.0",
87
- "typescript": "^5.2.2",
88
- "vite": "^4.4.9",
89
- "vite-plugin-sdk": "^0.1.1",
90
- "vitest": "^0.34.3",
91
- "vue": "^3.3.4"
87
+ "typescript": "^5.4.3",
88
+ "vite": "^4.5.3",
89
+ "vite-plugin-sdk": "^0.1.2",
90
+ "vitest": "^0.34.6",
91
+ "vue": "^3.4.21"
92
92
  },
93
93
  "peerDependencies": {
94
94
  "vue": "^3.0.0"
@@ -41,10 +41,10 @@ type ExtractSliceType<TSlice extends SliceLike> = TSlice extends SliceLikeRestV2
41
41
  *
42
42
  * @typeParam TSliceType - Type name of the Slice.
43
43
  */
44
- export type SliceLikeRestV2<TSliceType extends string = string> = {
45
- slice_type: Slice<TSliceType>["slice_type"];
46
- id?: string;
47
- };
44
+ export type SliceLikeRestV2<TSliceType extends string = string> = Pick<
45
+ Slice<TSliceType>,
46
+ "id" | "slice_type"
47
+ >;
48
48
 
49
49
  /**
50
50
  * The minimum required properties to represent a Prismic Slice from the Prismic
@@ -60,14 +60,23 @@ export type SliceLikeGraphQL<TSliceType extends string = string> = {
60
60
  * The minimum required properties to represent a Prismic Slice for the
61
61
  * `<SliceZone />` component.
62
62
  *
63
- * If using Prismic's REST API, use the `Slice` export from `@prismicio/client`
64
- * for a full interface.
63
+ * If using Prismic's Rest API V2, use the `Slice` export from
64
+ * `@prismicio/client` for a full interface.
65
65
  *
66
66
  * @typeParam TSliceType - Type name of the Slice
67
67
  */
68
- export type SliceLike<TSliceType extends string = string> =
68
+ export type SliceLike<TSliceType extends string = string> = (
69
69
  | SliceLikeRestV2<TSliceType>
70
- | SliceLikeGraphQL<TSliceType>;
70
+ | SliceLikeGraphQL<TSliceType>
71
+ ) & {
72
+ /**
73
+ * If `true`, this Slice has been modified from its original value using a
74
+ * mapper and `@prismicio/client`'s `mapSliceZone()`.
75
+ *
76
+ * @internal
77
+ */
78
+ __mapped?: true;
79
+ };
71
80
 
72
81
  /**
73
82
  * A looser version of the `SliceZone` type from `@prismicio/client` using
@@ -78,8 +87,9 @@ export type SliceLike<TSliceType extends string = string> =
78
87
  *
79
88
  * @typeParam TSlice - The type(s) of slices in the Slice Zone
80
89
  */
81
- export type SliceZoneLike<TSlice extends SliceLike = SliceLike> =
82
- readonly TSlice[];
90
+ export type SliceZoneLike<
91
+ TSlice extends SliceLike = SliceLike & Record<string, unknown>,
92
+ > = readonly TSlice[];
83
93
 
84
94
  /**
85
95
  * Vue props for a component rendering content from a Prismic Slice using the
@@ -90,8 +100,7 @@ export type SliceZoneLike<TSlice extends SliceLike = SliceLike> =
90
100
  * available to all Slice components
91
101
  */
92
102
  export type SliceComponentProps<
93
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
- TSlice extends SliceLike = any,
103
+ TSlice extends SliceLike = SliceLike,
95
104
  TContext = unknown,
96
105
  > = {
97
106
  /**
@@ -111,7 +120,9 @@ export type SliceComponentProps<
111
120
  // reference limtiations. If we had another generic to determine the full
112
121
  // union of Slice types, it would include TSlice. This causes TypeScript to
113
122
  // throw a compilation error.
114
- slices: SliceZoneLike<SliceLike>;
123
+ slices: SliceZoneLike<
124
+ TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2
125
+ >;
115
126
 
116
127
  /**
117
128
  * Arbitrary data passed to `<SliceZone />` and made available to all Slice
@@ -243,16 +254,23 @@ export type SliceComponentType<
243
254
  * cannot be found in `<SliceZone />`.
244
255
  */
245
256
  export const TODOSliceComponent = __PRODUCTION__
246
- ? ((() => null) as FunctionalComponent<SliceComponentProps>)
257
+ ? ((() => null) as FunctionalComponent<{
258
+ slice: SliceLike;
259
+ }>)
247
260
  : /*#__PURE__*/ (defineComponent({
248
261
  name: "TODOSliceComponent",
249
- props: getSliceComponentProps(),
262
+ props: {
263
+ slice: {
264
+ type: Object as PropType<SliceLike>,
265
+ required: true,
266
+ },
267
+ },
250
268
  setup(props) {
251
- const type = computed(() =>
252
- "slice_type" in props.slice
269
+ const type = computed(() => {
270
+ return "slice_type" in props.slice
253
271
  ? props.slice.slice_type
254
- : props.slice.type,
255
- );
272
+ : props.slice.type;
273
+ });
256
274
 
257
275
  watchEffect(() => {
258
276
  console.warn(
@@ -426,6 +444,7 @@ export type SliceZoneProps<TContext = unknown> = {
426
444
  *
427
445
  * @returns The Vue component to render for a Slice.
428
446
  */
447
+ // TODO: Remove in v5 when the `resolver` prop is removed.
429
448
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
430
449
  resolver?: SliceZoneResolver<any, TContext>;
431
450
 
@@ -499,20 +518,29 @@ export const SliceZoneImpl = /*#__PURE__*/ defineComponent({
499
518
  return () => null;
500
519
  }
501
520
 
521
+ // TODO: Remove in v3 when the `resolver` prop is removed.
522
+ if (!__PRODUCTION__) {
523
+ if (props.resolver) {
524
+ console.warn(
525
+ "The `resolver` prop is deprecated. Please replace it with a components map using the `components` prop.",
526
+ );
527
+ }
528
+ }
529
+
502
530
  const { options } = usePrismic();
503
531
 
504
532
  const renderedSlices = computed(() => {
505
533
  return props.slices.map((slice, index) => {
506
- const type = "slice_type" in slice ? slice.slice_type : slice.type;
534
+ const type =
535
+ "slice_type" in slice ? (slice.slice_type as string) : slice.type;
507
536
 
508
537
  let component =
509
538
  props.components && type in props.components
510
539
  ? props.components[type]
511
540
  : props.defaultComponent ||
512
- options.components?.sliceZoneDefaultComponent ||
513
- TODOSliceComponent;
541
+ options.components?.sliceZoneDefaultComponent;
514
542
 
515
- // TODO: Remove `resolver` in v3 in favor of `components`.
543
+ // TODO: Remove `resolver` in v5 in favor of `components`.
516
544
  if (props.resolver) {
517
545
  const resolvedComponent = props.resolver({
518
546
  slice,
@@ -526,19 +554,33 @@ export const SliceZoneImpl = /*#__PURE__*/ defineComponent({
526
554
  }
527
555
 
528
556
  const key =
529
- "id" in slice && slice.id
557
+ "id" in slice && typeof slice.id === "string"
530
558
  ? slice.id
531
559
  : `${index}-${JSON.stringify(slice)}`;
532
560
 
533
- const p = {
534
- key,
535
- slice,
536
- index,
537
- context: props.context,
538
- slices: props.slices,
539
- };
561
+ if (component) {
562
+ if (slice.__mapped) {
563
+ const { __mapped, ...mappedProps } = slice;
564
+
565
+ return h(simplyResolveComponent(component as ConcreteComponent), {
566
+ key,
567
+ ...mappedProps,
568
+ });
569
+ }
540
570
 
541
- return h(simplyResolveComponent(component as ConcreteComponent), p);
571
+ return h(simplyResolveComponent(component as ConcreteComponent), {
572
+ key,
573
+ slice,
574
+ index,
575
+ context: props.context,
576
+ slices: props.slices,
577
+ });
578
+ } else {
579
+ return h(
580
+ simplyResolveComponent(TODOSliceComponent as ConcreteComponent),
581
+ { key, slice },
582
+ );
583
+ }
542
584
  });
543
585
  });
544
586