Skip to content

Commit

Permalink
feat!: update to client v7 (#64)
Browse files Browse the repository at this point in the history
Co-authored-by: lihbr <[email protected]>
  • Loading branch information
lihbr and lihbr authored Jun 2, 2023
1 parent 5ced89b commit 00a71ca
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 117 deletions.
59 changes: 17 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
"playground:dev": "vite playground",
"prepare": "npm run build",
"release": "npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
"release:dry": "standard-version --dry-run",
"release:beta": "npm run test && standard-version --release-as major --prerelease beta && git push --follow-tags && npm run build && npm publish --tag beta",
"release:beta:dry": "standard-version --release-as major --prerelease beta --dry-run",
"release:dry": "standard-version --dry-run",
"lint": "eslint --ext .js,.ts .",
"types": "vitest typecheck --run && tsc --noEmit",
"types:watch": "vitest typecheck",
Expand All @@ -57,9 +57,7 @@
"test": "npm run lint && npm run types && npm run unit && npm run build && npm run size"
},
"dependencies": {
"@prismicio/client": "^6.7.3",
"@prismicio/helpers": "^2.3.9",
"@prismicio/types": "^0.2.7",
"@prismicio/client": "^7.0.1",
"isomorphic-unfetch": "^3.1.0",
"vue-router": "^4.2.1"
},
Expand Down Expand Up @@ -96,7 +94,7 @@
"vue": "^3.0.0"
},
"engines": {
"node": ">=14.15.0"
"node": ">=16.10.0"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions src/components/PrismicEmbed.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EmbedField } from "@prismicio/client";
import {
AllowedComponentProps,
ComponentCustomProps,
Expand All @@ -12,8 +13,6 @@ import {

import { simplyResolveComponent } from "../lib/simplyResolveComponent";

import { EmbedField } from "@prismicio/types";

/**
* The default component rendered to wrap the embed.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/components/PrismicImage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
ImageField,
asImagePixelDensitySrcSet,
asImageSrc,
asImageWidthSrcSet,
isFilled,
} from "@prismicio/helpers";
} from "@prismicio/client";
import {
AllowedComponentProps,
ComponentCustomProps,
Expand All @@ -23,7 +24,6 @@ import { __PRODUCTION__ } from "../lib/__PRODUCTION__";
import { simplyResolveComponent } from "../lib/simplyResolveComponent";

import { VueUseOptions } from "../types";
import { ImageField } from "@prismicio/types";

import { usePrismic } from "../usePrismic";

Expand Down
8 changes: 6 additions & 2 deletions src/components/PrismicLink.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { LinkResolverFunction, asLink } from "@prismicio/helpers";
import {
LinkField,
LinkResolverFunction,
PrismicDocument,
asLink,
} from "@prismicio/client";
import {
AllowedComponentProps,
ComponentCustomProps,
Expand All @@ -20,7 +25,6 @@ import { isInternalURL } from "../lib/isInternalURL";
import { simplyResolveComponent } from "../lib/simplyResolveComponent";

import { VueUseOptions } from "../types";
import { LinkField, PrismicDocument } from "@prismicio/types";

import { usePrismic } from "../usePrismic";

Expand Down
4 changes: 2 additions & 2 deletions src/components/PrismicRichText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import {
HTMLFunctionSerializer,
HTMLMapSerializer,
LinkResolverFunction,
RichTextField,
asHTML,
isFilled,
} from "@prismicio/helpers";
} from "@prismicio/client";
import {
AllowedComponentProps,
Component,
Expand All @@ -31,7 +32,6 @@ import { isInternalURL } from "../lib/isInternalURL";
import { simplyResolveComponent } from "../lib/simplyResolveComponent";

import { VueUseOptions } from "../types";
import { RichTextField } from "@prismicio/types";

import { usePrismic } from "../usePrismic";

Expand Down
3 changes: 1 addition & 2 deletions src/components/PrismicText.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { asText, isFilled } from "@prismicio/helpers";
import { RichTextField, asText, isFilled } from "@prismicio/client";
import {
AllowedComponentProps,
ComponentCustomProps,
Expand All @@ -18,7 +18,6 @@ import {
import { simplyResolveComponent } from "../lib/simplyResolveComponent";

import { VueUseOptions } from "../types";
import { RichTextField } from "@prismicio/types";

/**
* The default component rendered to wrap the text output.
Expand Down
16 changes: 8 additions & 8 deletions src/components/SliceZone.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Slice } from "@prismicio/client";
import {
AllowedComponentProps,
ComponentCustomProps,
Expand All @@ -17,8 +18,6 @@ import {
import { __PRODUCTION__ } from "../lib/__PRODUCTION__";
import { simplyResolveComponent } from "../lib/simplyResolveComponent";

import { Slice } from "@prismicio/types";

import { usePrismic } from "../usePrismic";

/**
Expand All @@ -37,7 +36,7 @@ type ExtractSliceType<TSlice extends SliceLike> = TSlice extends SliceLikeRestV2
* Rest API V2 for the `<SliceZone>` component.
*
* If using Prismic's Rest API V2, use the `Slice` export from
* `@prismicio/types` for a full interface.
* `@prismicio/client` for a full interface.
*
* @typeParam TSliceType - Type name of the Slice.
*/
Expand All @@ -60,7 +59,7 @@ export type SliceLikeGraphQL<TSliceType extends string = string> = {
* The minimum required properties to represent a Prismic Slice for the
* `<SliceZone />` component.
*
* If using Prismic's REST API, use the `Slice` export from `@prismicio/types`
* If using Prismic's REST API, use the `Slice` export from `@prismicio/client`
* for a full interface.
*
* @typeParam TSliceType - Type name of the Slice
Expand All @@ -70,11 +69,11 @@ export type SliceLike<TSliceType extends string = string> =
| SliceLikeGraphQL<TSliceType>;

/**
* A looser version of the `SliceZone` type from `@prismicio/types` using
* A looser version of the `SliceZone` type from `@prismicio/client` using
* `SliceLike`.
*
* If using Prismic's REST API, use the `SliceZone` export from
* `@prismicio/types` for the full type.
* `@prismicio/client` for the full type.
*
* @typeParam TSlice - The type(s) of slices in the Slice Zone
*/
Expand Down Expand Up @@ -153,8 +152,9 @@ export type DefineComponentSliceComponentProps<

/**
* Gets native Vue props for a component rendering content from a Prismic Slice
* using the `<SliceZone />` component. Props are: `["slice", "index", "slices",
* "context"]`
* using the `<SliceZone />` component.
*
* Props are: `["slice", "index", "slices", "context"]`
*
* @example Defining a new slice component:
*
Expand Down
2 changes: 1 addition & 1 deletion src/composables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { Client } from "@prismicio/client";

/* eslint-enable @typescript-eslint/no-unused-vars */
import { PrismicDocument, Query } from "@prismicio/types";
import { PrismicDocument, Query } from "@prismicio/client";

import {
ClientComposableReturnType,
Expand Down
56 changes: 44 additions & 12 deletions src/createPrismic.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import {
Client,
FetchLike,
cookie,
createClient,
predicate,
} from "@prismicio/client";
import {
LinkResolverFunction,
asDate,
asHTML,
asImagePixelDensitySrcSet,
asImageSrc,
asImageWidthSrcSet,
asLink,
asLinkAttrs,
asText,
cookie,
createClient,
documentToLinkField,
} from "@prismicio/helpers";
filter,
} from "@prismicio/client";
import { App } from "vue";

import type {
Expand Down Expand Up @@ -67,22 +67,54 @@ export const createPrismic = (options: PrismicPluginOptions): PrismicPlugin => {

const prismicClient: PrismicPluginClient = {
client,
predicate,
filter,
cookie,
};

// Create plugin helpers
const prismicHelpers: PrismicPluginHelpers = {
asText,
asHTML: (richTextField, linkResolver, htmlSerializer) => {
asHTML: (richTextField, ...config) => {
const [configOrLinkResolver, maybeHTMLSerializer] = config;

return asHTML(
richTextField,
linkResolver || options.linkResolver,
htmlSerializer || options.richTextSerializer || options.htmlSerializer,
typeof configOrLinkResolver === "function" ||
configOrLinkResolver == null
? {
linkResolver: configOrLinkResolver || options.linkResolver,
serializer:
maybeHTMLSerializer ||
options.richTextSerializer ||
options.htmlSerializer,
}
: {
linkResolver: options.linkResolver,
serializer: options.richTextSerializer || options.htmlSerializer,
...config,
},
);
},
asLink: (linkField, config) => {
return asLink(
linkField,
typeof config === "function"
? { linkResolver: config }
: {
linkResolver: options.linkResolver,
// TODO: For some reasons, TypeScript narrows the type to "unknown" where it's supposed to be a union
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...(config as any),
},
);
},
asLink: (linkField, linkResolver) => {
return asLink(linkField, linkResolver || options.linkResolver);
asLinkAttrs: (linkField, config) => {
return asLinkAttrs(linkField, {
// TODO: We can't really retrieve the generic type here, this might cause some unexpected type error in some edge-case scenario
// eslint-disable-next-line @typescript-eslint/no-explicit-any
linkResolver: options.linkResolver as LinkResolverFunction<any>,
...config,
});
},
asDate,
asImageSrc,
Expand Down
Loading

0 comments on commit 00a71ca

Please sign in to comment.