@prismicio/vue 3.0.0-alpha.5 → 3.0.0-alpha.6
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/dist/index.cjs +40 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +312 -264
- package/dist/index.mjs +40 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/PrismicLink.ts +27 -15
- package/src/components/SliceZone.ts +75 -7
- package/src/components/index.ts +3 -1
- package/src/index.ts +2 -1
- package/src/types.ts +2 -1
|
@@ -254,11 +254,11 @@ export type SliceZoneComponents<
|
|
|
254
254
|
* @example Defining a slice components:
|
|
255
255
|
*
|
|
256
256
|
* ```javascript
|
|
257
|
-
* import {
|
|
257
|
+
* import { defineSliceZoneComponents } from "@prismicio/vue";
|
|
258
258
|
*
|
|
259
259
|
* export default {
|
|
260
260
|
* data() {
|
|
261
|
-
* components:
|
|
261
|
+
* components: defineSliceZoneComponents({
|
|
262
262
|
* foo: Foo,
|
|
263
263
|
* bar: defineAsyncComponent(
|
|
264
264
|
* () => new Promise((res) => res(Bar)),
|
|
@@ -275,7 +275,7 @@ export type SliceZoneComponents<
|
|
|
275
275
|
*
|
|
276
276
|
* @returns A new optimized record of {@link SliceZoneComponents}
|
|
277
277
|
*/
|
|
278
|
-
export const
|
|
278
|
+
export const defineSliceZoneComponents = <
|
|
279
279
|
TSlice extends SliceLike = SliceLike,
|
|
280
280
|
TContext = unknown,
|
|
281
281
|
>(
|
|
@@ -300,6 +300,43 @@ export const getSliceZoneComponents = <
|
|
|
300
300
|
return result;
|
|
301
301
|
};
|
|
302
302
|
|
|
303
|
+
/**
|
|
304
|
+
* Arguments for a `<SliceZone>` `resolver` function.
|
|
305
|
+
*/
|
|
306
|
+
export type SliceZoneResolverArgs<TSlice extends SliceLike = SliceLike> = {
|
|
307
|
+
/**
|
|
308
|
+
* The Slice to resolve to a Vue component..
|
|
309
|
+
*/
|
|
310
|
+
slice: TSlice;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* The name of the Slice.
|
|
314
|
+
*/
|
|
315
|
+
sliceName: TSlice["slice_type"];
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* The index of the Slice in the Slice Zone.
|
|
319
|
+
*/
|
|
320
|
+
i: number;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* A function that determines the rendered Vue component for each Slice in the
|
|
325
|
+
* Slice Zone. If a nullish value is returned, the component will fallback to
|
|
326
|
+
* the `components` or `defaultComponent` props to determine the rendered component.
|
|
327
|
+
*
|
|
328
|
+
* @deprecated Use the `components` prop instead.
|
|
329
|
+
* @param args - Arguments for the resolver function.
|
|
330
|
+
*
|
|
331
|
+
* @returns The Vue component to render for a Slice.
|
|
332
|
+
*/
|
|
333
|
+
export type SliceZoneResolver<
|
|
334
|
+
TSlice extends SliceLike = SliceLike,
|
|
335
|
+
TContext = unknown,
|
|
336
|
+
> = (
|
|
337
|
+
args: SliceZoneResolverArgs<TSlice>,
|
|
338
|
+
) => SliceComponentType<TSlice, TContext> | string | undefined | null;
|
|
339
|
+
|
|
303
340
|
/**
|
|
304
341
|
* Props for `<SliceZone />`.
|
|
305
342
|
*
|
|
@@ -318,7 +355,18 @@ export type SliceZoneProps<
|
|
|
318
355
|
/**
|
|
319
356
|
* A record mapping Slice types to Vue components.
|
|
320
357
|
*/
|
|
321
|
-
components
|
|
358
|
+
components?: SliceZoneComponents;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* A function that determines the rendered Vue component for each Slice in the
|
|
362
|
+
* Slice Zone.
|
|
363
|
+
*
|
|
364
|
+
* @deprecated Use the `components` prop instead.
|
|
365
|
+
* @param args - Arguments for the resolver function.
|
|
366
|
+
*
|
|
367
|
+
* @returns The Vue component to render for a Slice.
|
|
368
|
+
*/
|
|
369
|
+
resolver?: SliceZoneResolver<TSlice, TContext>;
|
|
322
370
|
|
|
323
371
|
/**
|
|
324
372
|
* Arbitrary data made available to all Slice components.
|
|
@@ -356,7 +404,13 @@ export const SliceZoneImpl = /*#__PURE__*/ defineComponent({
|
|
|
356
404
|
},
|
|
357
405
|
components: {
|
|
358
406
|
type: Object as PropType<SliceZoneComponents>,
|
|
359
|
-
|
|
407
|
+
default: undefined,
|
|
408
|
+
required: false,
|
|
409
|
+
},
|
|
410
|
+
resolver: {
|
|
411
|
+
type: Function as PropType<SliceZoneResolver>,
|
|
412
|
+
default: undefined,
|
|
413
|
+
required: false,
|
|
360
414
|
},
|
|
361
415
|
context: {
|
|
362
416
|
type: null,
|
|
@@ -384,14 +438,28 @@ export const SliceZoneImpl = /*#__PURE__*/ defineComponent({
|
|
|
384
438
|
|
|
385
439
|
const renderedSlices = computed(() => {
|
|
386
440
|
return props.slices.map((slice, index) => {
|
|
387
|
-
|
|
388
|
-
slice.slice_type in props.components
|
|
441
|
+
let component =
|
|
442
|
+
props.components && slice.slice_type in props.components
|
|
389
443
|
? props.components[slice.slice_type]
|
|
390
444
|
: props.defaultComponent ||
|
|
391
445
|
options.components?.sliceZoneDefaultComponent ||
|
|
392
446
|
TODOSliceComponent;
|
|
393
447
|
|
|
448
|
+
// TODO: Remove `resolver` in v3 in favor of `components`.
|
|
449
|
+
if (props.resolver) {
|
|
450
|
+
const resolvedComponent = props.resolver({
|
|
451
|
+
slice,
|
|
452
|
+
sliceName: slice.slice_type,
|
|
453
|
+
i: index,
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
if (resolvedComponent) {
|
|
457
|
+
component = resolvedComponent;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
394
461
|
const p = {
|
|
462
|
+
key: `${slice.slice_type}-${index}`,
|
|
395
463
|
slice,
|
|
396
464
|
index,
|
|
397
465
|
context: props.context,
|
package/src/components/index.ts
CHANGED
|
@@ -23,7 +23,7 @@ export type {
|
|
|
23
23
|
export {
|
|
24
24
|
getSliceComponentProps,
|
|
25
25
|
TODOSliceComponent,
|
|
26
|
-
|
|
26
|
+
defineSliceZoneComponents,
|
|
27
27
|
SliceZoneImpl,
|
|
28
28
|
SliceZone,
|
|
29
29
|
} from "./SliceZone";
|
|
@@ -33,6 +33,8 @@ export type {
|
|
|
33
33
|
SliceComponentType,
|
|
34
34
|
SliceLike,
|
|
35
35
|
SliceZoneComponents,
|
|
36
|
+
SliceZoneResolverArgs,
|
|
37
|
+
SliceZoneResolver,
|
|
36
38
|
SliceZoneLike,
|
|
37
39
|
SliceZoneProps,
|
|
38
40
|
} from "./SliceZone";
|
package/src/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ export {
|
|
|
15
15
|
// Slice Zone
|
|
16
16
|
getSliceComponentProps,
|
|
17
17
|
TODOSliceComponent,
|
|
18
|
-
|
|
18
|
+
defineSliceZoneComponents,
|
|
19
19
|
SliceZoneImpl,
|
|
20
20
|
SliceZone,
|
|
21
21
|
} from "./components";
|
|
@@ -36,6 +36,7 @@ export type {
|
|
|
36
36
|
SliceComponentType,
|
|
37
37
|
SliceLike,
|
|
38
38
|
SliceZoneComponents,
|
|
39
|
+
SliceZoneResolver,
|
|
39
40
|
SliceZoneLike,
|
|
40
41
|
SliceZoneProps,
|
|
41
42
|
} from "./components";
|
package/src/types.ts
CHANGED
|
@@ -25,6 +25,7 @@ import type { RouterLink } from "vue-router";
|
|
|
25
25
|
|
|
26
26
|
import type {
|
|
27
27
|
SliceComponentProps,
|
|
28
|
+
SliceComponentType,
|
|
28
29
|
TODOSliceComponent,
|
|
29
30
|
} from "./components/SliceZone";
|
|
30
31
|
|
|
@@ -90,7 +91,7 @@ type PrismicPluginComponentsOptions = {
|
|
|
90
91
|
* Components will be rendered using the {@link SliceComponentProps} interface.
|
|
91
92
|
* @defaultValue `null` when `process.env.NODE_ENV === "production"` else {@link TODOSliceComponent}
|
|
92
93
|
*/
|
|
93
|
-
sliceZoneDefaultComponent?:
|
|
94
|
+
sliceZoneDefaultComponent?: SliceComponentType;
|
|
94
95
|
};
|
|
95
96
|
|
|
96
97
|
/**
|