@prismicio/vue 3.0.0-alpha.1 → 3.0.0-alpha.5

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.
@@ -20,9 +20,11 @@ import { __PRODUCTION__ } from "../lib/__PRODUCTION__";
20
20
  import { usePrismic } from "../usePrismic";
21
21
 
22
22
  /**
23
- * The minimum required properties to represent a Prismic Slice for the `<SliceZone />` component.
23
+ * The minimum required properties to represent a Prismic Slice for the
24
+ * `<SliceZone />` component.
24
25
  *
25
- * If using Prismic's REST API, use the `Slice` export from `@prismicio/types` for a full interface.
26
+ * If using Prismic's REST API, use the `Slice` export from `@prismicio/types`
27
+ * for a full interface.
26
28
  *
27
29
  * @typeParam TSliceType - Type name of the Slice
28
30
  */
@@ -34,44 +36,57 @@ export type SliceLike<TSliceType extends string = string> = Pick<
34
36
  /**
35
37
  * A looser version of the `SliceZone` type from `@prismicio/types` using `SliceLike`.
36
38
  *
37
- * If using Prismic's REST API, use the `SliceZone` export from `@prismicio/types` for the full type.
39
+ * If using Prismic's REST API, use the `SliceZone` export from
40
+ * `@prismicio/types` for the full type.
38
41
  *
39
42
  * @typeParam TSlice - The type(s) of slices in the Slice Zone
40
43
  */
41
44
  export type SliceZoneLike<TSlice extends SliceLike> = readonly TSlice[];
42
45
 
43
46
  /**
44
- * Vue props for a component rendering content from a Prismic Slice using the `<SliceZone />` component.
47
+ * Vue props for a component rendering content from a Prismic Slice using the
48
+ * `<SliceZone />` component.
45
49
  *
46
50
  * @typeParam TSlice - The type(s) of slices in the Slice Zone
47
- * @typeParam TContext - Arbitrary data passed to `<SliceZone />` and made available to all Slice components
51
+ * @typeParam TContext - Arbitrary data passed to `<SliceZone />` and made
52
+ * available to all Slice components
48
53
  */
49
54
  export type SliceComponentProps<
50
55
  TSlice extends SliceLike = SliceLike,
51
56
  TContext = unknown,
52
57
  > = {
53
- /** Slice data for this component. */
58
+ /**
59
+ * Slice data for this component.
60
+ */
54
61
  slice: TSlice;
55
62
 
56
- /** The index of the Slice in the Slice Zone. */
63
+ /**
64
+ * The index of the Slice in the Slice Zone.
65
+ */
57
66
  index: number;
58
67
 
59
- /** All Slices from the Slice Zone to which the Slice belongs. */
68
+ /**
69
+ * All Slices from the Slice Zone to which the Slice belongs.
70
+ */
60
71
  // TODO: We have to keep this list of Slices general due to circular
61
72
  // reference limtiations. If we had another generic to determine the full
62
73
  // union of Slice types, it would include TSlice. This causes TypeScript to
63
74
  // throw a compilation error.
64
75
  slices: SliceZoneLike<SliceLike>;
65
76
 
66
- /** Arbitrary data passed to `<SliceZone />` and made available to all Slice components. */
77
+ /**
78
+ * Arbitrary data passed to `<SliceZone />` and made available to all Slice components.
79
+ */
67
80
  context: TContext;
68
81
  };
69
82
 
70
83
  /**
71
- * Native Vue props for a component rendering content from a Prismic Slice using the `<SliceZone />` component.
84
+ * Native Vue props for a component rendering content from a Prismic Slice using
85
+ * the `<SliceZone />` component.
72
86
  *
73
87
  * @typeParam TSlice - The type(s) of slices in the Slice Zone
74
- * @typeParam TContext - Arbitrary data passed to `<SliceZone />` and made available to all Slice components
88
+ * @typeParam TContext - Arbitrary data passed to `<SliceZone />` and made
89
+ * available to all Slice components
75
90
  */
76
91
  export type DefineComponentSliceComponentProps<
77
92
  TSlice extends SliceLike = SliceLike,
@@ -96,28 +111,46 @@ export type DefineComponentSliceComponentProps<
96
111
  };
97
112
 
98
113
  /**
99
- * Gets native Vue props for a component rendering content from a Prismic Slice using the `<SliceZone />` component.
114
+ * Gets native Vue props for a component rendering content from a Prismic Slice
115
+ * using the `<SliceZone />` component. Props are: `["slice", "index", "slices",
116
+ * "context"]`
100
117
  *
101
- * @returns Props object to use with {@link defineComponent}
102
- *
103
- * @typeParam TSlice - The type(s) of slices in the Slice Zone
104
- * @typeParam TContext - Arbitrary data passed to `<SliceZone />` and made available to all Slice components
118
+ * @example Defining a new slice component:
105
119
  *
106
- * @example
107
- * Defining a new slice component:
120
+ * ```javascript
121
+ * import { getSliceComponentProps } from "@prismicio/vue";
108
122
  *
123
+ * export default {
124
+ * props: getSliceComponentProps(),
125
+ * };
109
126
  * ```
127
+ *
128
+ * @example Defining a new slice component with visual hint:
129
+ *
130
+ * ```javascript
110
131
  * import { getSliceComponentProps } from "@prismicio/vue";
111
132
  *
112
133
  * export default {
113
- * props: getSliceComponentProps(),
134
+ * props: getSliceComponentProps(["slice", "index", "slices", "context"]),
114
135
  * };
115
136
  * ```
137
+ *
138
+ * @typeParam TSlice - The type(s) of slices in the Slice Zone
139
+ * @typeParam TContext - Arbitrary data passed to `<SliceZone />` and made
140
+ * available to all Slice components
141
+ * @param propsHint - An optional array of prop names used for the sole purpose
142
+ * of having a visual hint of which props are made available to the slice,
143
+ * this parameters doesn't have any effect
144
+ *
145
+ * @returns Props object to use with {@link defineComponent}
116
146
  */
117
147
  export const getSliceComponentProps = <
118
148
  TSlice extends SliceLike = SliceLike,
119
149
  TContext = unknown,
120
- >(): DefineComponentSliceComponentProps<TSlice, TContext> => ({
150
+ >(
151
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
152
+ propsHint?: string[],
153
+ ): DefineComponentSliceComponentProps<TSlice, TContext> => ({
121
154
  slice: {
122
155
  type: Object as PropType<SliceComponentProps<TSlice, TContext>["slice"]>,
123
156
  required: true,
@@ -154,11 +187,12 @@ export type SliceComponentType<
154
187
  /**
155
188
  * This Slice component can be used as a reminder to provide a proper implementation.
156
189
  *
157
- * This is also the default Vue component rendered when a component mapping cannot be found in `<SliceZone />`.
190
+ * This is also the default Vue component rendered when a component mapping
191
+ * cannot be found in `<SliceZone />`.
158
192
  */
159
193
  export const TODOSliceComponent = __PRODUCTION__
160
194
  ? ((() => null) as FunctionalComponent<SliceComponentProps>)
161
- : (defineComponent({
195
+ : /*#__PURE__*/ (defineComponent({
162
196
  name: "TODOSliceCOmponent",
163
197
  props: getSliceComponentProps(),
164
198
  setup(props) {
@@ -185,7 +219,8 @@ export const TODOSliceComponent = __PRODUCTION__
185
219
  }) as SliceComponentType);
186
220
 
187
221
  /**
188
- * A record of Slice types mapped to Vue components. Each components will be rendered for each instance of their Slice type.
222
+ * A record of Slice types mapped to Vue components. Each components will be
223
+ * rendered for each instance of their Slice type.
189
224
  *
190
225
  * @typeParam TSlice - The type(s) of slices in the Slice Zone
191
226
  * @typeParam TContext - Arbitrary data made available to all Slice components
@@ -210,21 +245,15 @@ export type SliceZoneComponents<
210
245
  };
211
246
 
212
247
  /**
213
- * Gets an optimized record of Slice types mapped to Vue components. Each components will be rendered for each instance of their Slice type.
248
+ * Gets an optimized record of Slice types mapped to Vue components. Each
249
+ * components will be rendered for each instance of their Slice type.
214
250
  *
215
- * @param components - {@link SliceZoneComponents}
251
+ * @remarks
252
+ * This is essentially an helper function to ensure {@link markRaw} is correctly
253
+ * applied on each components, improving performances.
254
+ * @example Defining a slice components:
216
255
  *
217
- * @returns A new optimized record of {@link SliceZoneComponents}
218
- *
219
- * @typeParam TSlice - The type(s) of slices in the Slice Zone
220
- * @typeParam TContext - Arbitrary data made available to all Slice components
221
- *
222
- * @remarks This is essentially an helper function to ensure {@link markRaw} is correctly applied on each components, improving performances.
223
- *
224
- * @example
225
- * Defining a slice components:
226
- *
227
- * ```
256
+ * ```javascript
228
257
  * import { getSliceZoneComponents } from "@prismicio/vue";
229
258
  *
230
259
  * export default {
@@ -239,6 +268,12 @@ export type SliceZoneComponents<
239
268
  * }
240
269
  * };
241
270
  * ```
271
+ *
272
+ * @typeParam TSlice - The type(s) of slices in the Slice Zone
273
+ * @typeParam TContext - Arbitrary data made available to all Slice components
274
+ * @param components - {@link SliceZoneComponents}
275
+ *
276
+ * @returns A new optimized record of {@link SliceZoneComponents}
242
277
  */
243
278
  export const getSliceZoneComponents = <
244
279
  TSlice extends SliceLike = SliceLike,
@@ -275,26 +310,34 @@ export type SliceZoneProps<
275
310
  TSlice extends SliceLike = SliceLike,
276
311
  TContext = unknown,
277
312
  > = {
278
- /** List of Slice data from the Slice Zone. */
313
+ /**
314
+ * List of Slice data from the Slice Zone.
315
+ */
279
316
  slices: SliceZoneLike<TSlice>;
280
317
 
281
- /** A record mapping Slice types to Vue components. */
318
+ /**
319
+ * A record mapping Slice types to Vue components.
320
+ */
282
321
  components: SliceZoneComponents;
283
322
 
284
- /** Arbitrary data made available to all Slice components. */
323
+ /**
324
+ * Arbitrary data made available to all Slice components.
325
+ */
285
326
  context?: TContext;
286
327
 
287
328
  /**
288
- * A component or a functional component rendered if a component mapping from the `components` prop cannot be found.
289
- *
290
- * @remarks Components will be rendered using the {@link SliceComponentProps} interface.
329
+ * A component or a functional component rendered if a component mapping from
330
+ * the `components` prop cannot be found.
291
331
  *
332
+ * @remarks
333
+ * Components will be rendered using the {@link SliceComponentProps} interface.
292
334
  * @defaultValue The Slice Zone default component provided to `@prismicio/vue` plugin if configured, otherwise `null` when `process.env.NODE_ENV === "production"` else {@link TODOSliceComponent}.
293
335
  */
294
336
  defaultComponent?: SliceComponentType<TSlice, TContext>;
295
337
 
296
338
  /**
297
- * An HTML tag name, a component, or a functional component used to wrap the output. The Slice Zone is not wrapped by default.
339
+ * An HTML tag name, a component, or a functional component used to wrap the
340
+ * output. The Slice Zone is not wrapped by default.
298
341
  */
299
342
  wrapper?: string | ConcreteComponent;
300
343
  };
@@ -304,7 +347,7 @@ export type SliceZoneProps<
304
347
  *
305
348
  * @internal
306
349
  */
307
- export const SliceZoneImpl = defineComponent({
350
+ export const SliceZoneImpl = /*#__PURE__*/ defineComponent({
308
351
  name: "SliceZone",
309
352
  props: {
310
353
  slices: {