From 2898e5582d4d50d528328b636e85018c0312358c Mon Sep 17 00:00:00 2001 From: lihbr Date: Mon, 27 Jul 2026 15:03:15 +0900 Subject: [PATCH] chore: align tooling with typescript-template Consolidate release CI into publish.yml, align oxlint/oxfmt with the template, and refresh formatting and the e2e Next.js dependency. Co-authored-by: Cursor --- .github/workflows/prerelease-canary.yml | 40 --- .github/workflows/prerelease-pr-cleanup.yml | 31 -- .github/workflows/prerelease-pr.yml | 39 -- .github/workflows/publish.yml | 114 ++++++ .github/workflows/release.yml | 34 -- .github/workflows/validate.yml | 2 + .oxfmtrc.json | 5 +- .oxlintrc.json | 2 + .versionrc | 24 -- CHANGELOG.md | 3 +- CONTRIBUTING.md | 51 +-- .../app/PrismicImage/client/ClientTest.tsx | 16 +- .../nextjs/app/PrismicImage/client/page.tsx | 18 +- e2e-projects/nextjs/app/PrismicImage/page.tsx | 28 +- .../nextjs/app/PrismicLink/client/page.tsx | 12 +- e2e-projects/nextjs/app/PrismicLink/page.tsx | 32 +- .../nextjs/app/PrismicRichText/page.tsx | 20 +- e2e-projects/nextjs/app/PrismicTable/page.tsx | 20 +- e2e-projects/nextjs/app/PrismicText/page.tsx | 24 +- .../nextjs/app/PrismicToolbar/page.tsx | 10 +- .../PrismicToolbarPreviewEvents.tsx | 18 +- .../PrismicToolbar/preview-events/page.tsx | 10 +- e2e-projects/nextjs/app/SliceZone/page.tsx | 34 +- e2e-projects/nextjs/app/layout.tsx | 4 +- e2e-projects/nextjs/next.config.ts | 8 +- e2e-projects/nextjs/package.json | 2 +- e2e-projects/nextjs/prismic-types.d.ts | 122 +++---- e2e-projects/nextjs/prismicio.ts | 16 +- e2e-projects/nextjs/tsconfig.json | 70 ++-- examples/custom-slicezone-props/index.tsx | 22 +- examples/custom-slicezone-props/types.ts | 22 +- examples/router-link/index.tsx | 18 +- examples/with-typescript/index.tsx | 50 +-- package-lock.json | 93 ++--- package.json | 4 +- playwright.config.ts | 28 +- src/PrismicImage.tsx | 66 ++-- src/PrismicLink.tsx | 86 ++--- src/PrismicRichText.tsx | 86 ++--- src/PrismicTable.tsx | 58 +-- src/PrismicText.tsx | 32 +- src/PrismicToolbar.tsx | 60 ++-- src/SliceZone.tsx | 82 ++--- src/index.ts | 30 +- src/lib/devMsg.ts | 6 +- tests/PrismicImage.spec.ts | 122 +++---- tests/PrismicLink.spec.ts | 174 ++++----- tests/PrismicRichText.spec.ts | 332 +++++++++--------- tests/PrismicTable.spec.ts | 36 +- tests/PrismicText.spec.ts | 40 +-- tests/PrismicToolbar.spec.ts | 60 ++-- tests/SliceZone.spec.ts | 56 +-- tests/infra/client.ts | 274 +++++++-------- tests/infra/content/image.ts | 4 +- tests/infra/content/index.ts | 10 +- tests/infra/content/link.ts | 6 +- tests/infra/content/page.ts | 6 +- tests/infra/content/richtext.ts | 4 +- tests/infra/content/table.ts | 4 +- tests/infra/index.ts | 4 +- tests/infra/setup.ts | 54 +-- tests/infra/teardown.ts | 20 +- tests/infra/test.ts | 102 +++--- tsdown.config.ts | 4 +- 64 files changed, 1401 insertions(+), 1463 deletions(-) delete mode 100644 .github/workflows/prerelease-canary.yml delete mode 100644 .github/workflows/prerelease-pr-cleanup.yml delete mode 100644 .github/workflows/prerelease-pr.yml create mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/release.yml delete mode 100644 .versionrc diff --git a/.github/workflows/prerelease-canary.yml b/.github/workflows/prerelease-canary.yml deleted file mode 100644 index 3590d34..0000000 --- a/.github/workflows/prerelease-canary.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: prerelease-canary - -permissions: - contents: read - id-token: write - -on: - push: - branches: - - master - -jobs: - publish: - if: github.repository_owner == 'prismicio' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - uses: actions/setup-node@v6 - with: - node-version: 24 - registry-url: "https://registry.npmjs.org" - - name: "Deprecate previous canary" - run: | - PACKAGE_NAME=$(jq -r ".name" package.json) - PREVIOUS_VERSION=$(npm view "$PACKAGE_NAME" dist-tags.canary 2>/dev/null) - if [ -n "$PREVIOUS_VERSION" ]; then - npm deprecate "$PACKAGE_NAME@$PREVIOUS_VERSION" "Replaced by newer canary version" - fi - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - run: npm ci - - name: "Generate new version" - run: | - SHORT_SHA=$(git rev-parse --short HEAD) - CURRENT_VERSION=$(jq -r '.version' package.json) - VERSION="${CURRENT_VERSION}-canary.${SHORT_SHA}" - npm version $VERSION --no-git-tag-version - - run: npm publish --provenance --tag canary - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/prerelease-pr-cleanup.yml b/.github/workflows/prerelease-pr-cleanup.yml deleted file mode 100644 index 42ab764..0000000 --- a/.github/workflows/prerelease-pr-cleanup.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: prerelease-pr-cleanup - -permissions: - contents: read - id-token: write - -on: - pull_request: - types: [closed] - -jobs: - cleanup: - if: github.repository_owner == 'prismicio' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - uses: actions/setup-node@v6 - with: - node-version: 24 - registry-url: "https://registry.npmjs.org" - - name: "Deprecate PR prerelease" - run: | - PACKAGE_NAME=$(jq -r ".name" package.json) - TAG="pr-${{ github.event.number }}" - VERSION=$(npm view "$PACKAGE_NAME" dist-tags."$TAG" 2>/dev/null || echo "") - if [ -n "$VERSION" ]; then - npm deprecate "$PACKAGE_NAME@$VERSION" "PR ${{ github.event.number }} was closed" - npm dist-tag rm "$PACKAGE_NAME" "$TAG" - fi - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/prerelease-pr.yml b/.github/workflows/prerelease-pr.yml deleted file mode 100644 index 8d5b13c..0000000 --- a/.github/workflows/prerelease-pr.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: prerelease-pr - -permissions: - contents: read - id-token: write - -on: - pull_request: - -jobs: - publish: - if: github.repository_owner == 'prismicio' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - uses: actions/setup-node@v6 - with: - node-version: 24 - registry-url: "https://registry.npmjs.org" - - name: "Deprecate previous PR prerelease" - run: | - PACKAGE_NAME=$(jq -r ".name" package.json) - TAG="pr-${{ github.event.number }}" - PREVIOUS_VERSION=$(npm view "$PACKAGE_NAME" dist-tags."$TAG" 2>/dev/null) - if [ -n "$PREVIOUS_VERSION" ]; then - npm deprecate "$PACKAGE_NAME@$PREVIOUS_VERSION" "Replaced by newer prerelease version" - fi - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - run: npm ci - - name: "Generate new version" - run: | - SHORT_SHA=$(git rev-parse --short HEAD) - CURRENT_VERSION=$(jq -r '.version' package.json) - VERSION="${CURRENT_VERSION}-pr.${{ github.event.number }}.${SHORT_SHA}" - npm version $VERSION --no-git-tag-version - - run: npm publish --provenance --tag pr-${{ github.event.number }} - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..483d69f --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,114 @@ +name: publish + +on: + push: + branches: [master] + pull_request: + types: [opened, synchronize, reopened, closed] + +jobs: + release: + if: github.event_name == 'push' && github.repository_owner == 'prismicio' + runs-on: ubuntu-latest + permissions: + contents: write + issues: write + pull-requests: write + id-token: write + env: + MODE: production + outputs: + release_created: ${{ steps.release.outputs.release_created }} + steps: + - uses: googleapis/release-please-action@v4 + id: release + continue-on-error: true + with: + release-type: node + - uses: actions/checkout@v6 + if: steps.release.outputs.release_created == 'true' + - uses: actions/setup-node@v6 + if: steps.release.outputs.release_created == 'true' + with: + node-version: 24 + registry-url: "https://registry.npmjs.org" + - if: steps.release.outputs.release_created == 'true' + run: npm ci + - name: "Publish release" + if: steps.release.outputs.release_created == 'true' + run: npm publish + + prerelease: + if: "!cancelled() && github.repository_owner == 'prismicio'" + needs: [release] + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + env: + MODE: production + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-node@v6 + with: + node-version: 24 + registry-url: "https://registry.npmjs.org" + + # Canary + - name: "Deprecate previous canary" + if: github.event_name == 'push' && needs.release.outputs.release_created != 'true' + continue-on-error: true + run: | + PACKAGE_NAME=$(jq -r ".name" package.json) + PREVIOUS_VERSION=$(npm view "$PACKAGE_NAME" dist-tags.canary 2>/dev/null || true) + if [ -n "$PREVIOUS_VERSION" ]; then + npm deprecate "$PACKAGE_NAME@$PREVIOUS_VERSION" "Replaced by newer canary version" + fi + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: "Publish canary" + if: github.event_name == 'push' && needs.release.outputs.release_created != 'true' + run: | + SHORT_SHA=$(git rev-parse --short HEAD) + CURRENT_VERSION=$(jq -r '.version' package.json) + npm ci + npm version "${CURRENT_VERSION}-canary.${SHORT_SHA}" --no-git-tag-version + npm publish --tag canary + + # Pull request + - name: "Deprecate previous PR prerelease" + if: github.event_name == 'pull_request' && github.event.action != 'closed' + continue-on-error: true + run: | + PACKAGE_NAME=$(jq -r ".name" package.json) + TAG="pr-${{ github.event.number }}" + PREVIOUS_VERSION=$(npm view "$PACKAGE_NAME" dist-tags."$TAG" 2>/dev/null || true) + if [ -n "$PREVIOUS_VERSION" ]; then + npm deprecate "$PACKAGE_NAME@$PREVIOUS_VERSION" "Replaced by newer prerelease version" + fi + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: "Publish PR prerelease" + if: github.event_name == 'pull_request' && github.event.action != 'closed' + run: | + SHORT_SHA=$(git rev-parse --short HEAD) + CURRENT_VERSION=$(jq -r '.version' package.json) + npm ci + npm version "${CURRENT_VERSION}-pr.${{ github.event.number }}.${SHORT_SHA}" --no-git-tag-version + npm publish --tag pr-${{ github.event.number }} + + - name: "Clean up PR prerelease" + if: github.event_name == 'pull_request' && github.event.action == 'closed' + continue-on-error: true + run: | + PACKAGE_NAME=$(jq -r ".name" package.json) + TAG="pr-${{ github.event.number }}" + VERSION=$(npm view "$PACKAGE_NAME" dist-tags."$TAG" 2>/dev/null || echo "") + if [ -n "$VERSION" ]; then + npm deprecate "$PACKAGE_NAME@$VERSION" "PR ${{ github.event.number }} was closed" + npm dist-tag rm "$PACKAGE_NAME" "$TAG" + fi + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index c16e753..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: release - -permissions: - contents: write - issues: write - pull-requests: write - id-token: write - -on: - push: - branches: - - master - -jobs: - release-please: - runs-on: ubuntu-latest - steps: - - uses: googleapis/release-please-action@v4 - id: release - with: - release-type: node - - uses: actions/checkout@v6 - if: ${{ steps.release.outputs.release_created }} - - uses: actions/setup-node@v6 - if: ${{ steps.release.outputs.release_created }} - with: - node-version: 24 - registry-url: "https://registry.npmjs.org" - - run: npm ci - if: ${{ steps.release.outputs.release_created }} - - run: npm publish --provenance - if: ${{ steps.release.outputs.release_created }} - env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index c965cc4..6060f6c 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -16,6 +16,8 @@ jobs: build: runs-on: ubuntu-latest + env: + MODE: production steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 diff --git a/.oxfmtrc.json b/.oxfmtrc.json index ec6d335..eca1254 100644 --- a/.oxfmtrc.json +++ b/.oxfmtrc.json @@ -1,5 +1,6 @@ { "$schema": "./node_modules/oxfmt/configuration_schema.json", - "sortImports": {}, - "jsdoc": {} + "semi": false, + "sortImports": true, + "jsdoc": true } diff --git a/.oxlintrc.json b/.oxlintrc.json index 47166cc..983ce1f 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -1,8 +1,10 @@ { + "$schema": "./node_modules/oxlint/configuration_schema.json", "plugins": ["unicorn", "typescript", "oxc", "jsdoc", "react"], "rules": { "no-console": ["warn", { "allow": ["info", "warn", "error"] }], "no-debugger": "warn", + "prefer-const": "error", "no-unused-vars": [ "error", { diff --git a/.versionrc b/.versionrc deleted file mode 100644 index 2807c44..0000000 --- a/.versionrc +++ /dev/null @@ -1,24 +0,0 @@ -{ - "types": [ - { - "type": "feat", - "section": "Features" - }, - { - "type": "fix", - "section": "Bug Fixes" - }, - { - "type": "refactor", - "section": "Refactor" - }, - { - "type": "docs", - "section": "Documentation" - }, - { - "type": "chore", - "section": "Chore" - } - ] -} diff --git a/CHANGELOG.md b/CHANGELOG.md index 150c223..0a2e27a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,9 @@ All notable changes to this project will be documented in this file. See [standa ## [3.4.1](https://github.com/prismicio/prismic-react/compare/v3.4.0...v3.4.1) (2026-04-03) - ### Chore -* upgrade dependencies ([#257](https://github.com/prismicio/prismic-react/issues/257)) ([32a2a11](https://github.com/prismicio/prismic-react/commit/32a2a11)) +- upgrade dependencies ([#257](https://github.com/prismicio/prismic-react/issues/257)) ([32a2a11](https://github.com/prismicio/prismic-react/commit/32a2a11)) ## [3.4.0](https://github.com/prismicio/prismic-react/compare/v3.3.0...v3.4.0) (2026-02-21) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f7d2c5c..0faa20e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing -This package is primarily maintained by [Prismic](https://prismic.io)[^1]. External contributions are welcome. Ask for help by [opening an issue](https://github.com/prismicio/prismic-client/issues/new/choose), or request a review by opening a pull request. +This package is primarily maintained by [Prismic](https://prismic.io)[^1]. External contributions are welcome. Ask for help by [opening an issue](https://github.com/prismicio/prismic-react/issues/new/choose), or request a review by opening a pull request. ## :gear: Setup @@ -8,7 +8,7 @@ This package is primarily maintained by [Prismic](https://prismic.io)[^1]. Exter The following setup is required to work on this project: -- Node.js +- Node.js 24 or later - npm CLI ## :memo: Project-specific notes @@ -28,7 +28,7 @@ The following setup is required to work on this project: ## :construction_worker: Develop > [!NOTE] -> It's highly recommended to discuss your changes with the Prismic team before starting by [opening an issue](https://github.com/prismicio/prismic-client/issues/new/choose).[^2] +> It's highly recommended to discuss your changes with the Prismic team before starting by [opening an issue](https://github.com/prismicio/prismic-react/issues/new/choose).[^2] > > A short discussion can accellerate your work and ship it faster. @@ -43,19 +43,19 @@ git checkout -b / # Start the development watcher. # Run this command while you are working on your changes. -npm run dev +node --run dev # Build the project for production. # Run this command when you want to see the production version. -npm run build +node --run build # Lint your changes before requesting a review. No errors are allowed. -npm run lint +node --run lint # Some errors can be fixed automatically: -npm run lint -- --fix +node --run lint -- --fix # Format your changes before requesting a review. No errors are allowed. -npm run format +node --run format # Create a .env.test.local file and provide a Prismic username and password. # They will be used to run E2E tests. @@ -64,12 +64,12 @@ cp .env.test.example .env.test.local # Test your changes before requesting a review. # All changes should be tested. No failing tests are allowed. -npm run test +node --run test # Run only E2E tests (optionally in UI mode): -npm run e2e -npm run e2e:ui +node --run e2e +node --run e2e:ui # Run only type tests -npm run types +node --run types ``` ## :building_construction: Submit a pull request @@ -86,6 +86,10 @@ gh pr create # Someone from the Prismic team will review your work. This review will at # least consider the PR's general direction, code style, and test coverage. +# Prereleases are published to npm automatically to upon pushing commits. +# Install the prerelease using the `pr-${number}` tag. +npm install @prismicio/react@pr-101 + # When ready, PRs should be merged using the "Squash and merge" option. ``` @@ -94,28 +98,9 @@ gh pr create > [!CAUTION] > Publishing is restricted to the Prismic team.[^4] -```sh -# Checkout the main branch and pull the latest changes. -git checkout main -git pull - -# Perform a dry-run and verify the output. -# If it looks good, release a new version. -npm run release:dry -npm run release - -# Or release an alpha. -# Perform a dry-run and verify the output. -# If it looks good, release a new alpha version. -npm run release:alpha:dry -npm run release:alpha -``` - -After publishing a new release, publish the tags as releases. This will show the latest release on the repository's homepage. +This repository uses [Release Please](https://github.com/googleapis/release-please). To publish changes in `master`, merge [the pending Release Please PR](https://github.com/prismicio/prismic-react/pulls?q=is%3Apr+is%3Aopen+label%3A%22autorelease%3A+pending%22). -1. Go to the repository's [Tags page](https://github.com/prismicio/prismic-react/tags). -2. Open the options for the tag you just published to NPM and select "Create release." -3. Ensure that the "Set as the latest release" box is checked, then publish the release. +If you don't see a pending PR, there are no changes to publish from `master`. [^1]: This package is maintained by the DevX team. Prismic employees can ask for help or a review in the [#team-devx](https://prismic-team.slack.com/archives/C014VAACCQL) Slack channel. diff --git a/e2e-projects/nextjs/app/PrismicImage/client/ClientTest.tsx b/e2e-projects/nextjs/app/PrismicImage/client/ClientTest.tsx index b9ea40f..d334352 100644 --- a/e2e-projects/nextjs/app/PrismicImage/client/ClientTest.tsx +++ b/e2e-projects/nextjs/app/PrismicImage/client/ClientTest.tsx @@ -1,19 +1,19 @@ -"use client"; +"use client" -import type { ImageField } from "@prismicio/client"; -import { PrismicImage } from "@prismicio/react"; -import type { ReactNode } from "react"; -import { useState } from "react"; +import type { ImageField } from "@prismicio/client" +import { PrismicImage } from "@prismicio/react" +import type { ReactNode } from "react" +import { useState } from "react" export function ClientTest(props: { field: ImageField }): ReactNode { - const { field } = props; + const { field } = props - const [ref, setRef] = useState(null); + const [ref, setRef] = useState(null) return (

tagname: {ref?.tagName}

- ); + ) } diff --git a/e2e-projects/nextjs/app/PrismicImage/client/page.tsx b/e2e-projects/nextjs/app/PrismicImage/client/page.tsx index 1791ada..8530e61 100644 --- a/e2e-projects/nextjs/app/PrismicImage/client/page.tsx +++ b/e2e-projects/nextjs/app/PrismicImage/client/page.tsx @@ -1,17 +1,17 @@ -import assert from "assert"; +import assert from "assert" -import { isFilled } from "@prismicio/client"; -import type { ReactNode } from "react"; +import { isFilled } from "@prismicio/client" +import type { ReactNode } from "react" -import { createClient } from "@/prismicio"; +import { createClient } from "@/prismicio" -import { ClientTest } from "./ClientTest"; +import { ClientTest } from "./ClientTest" export default async function Page(): Promise { - const client = await createClient(); - const { data: tests } = await client.getSingle("image_test"); + const client = await createClient() + const { data: tests } = await client.getSingle("image_test") - assert(isFilled.image(tests.filled)); + assert(isFilled.image(tests.filled)) - return ; + return } diff --git a/e2e-projects/nextjs/app/PrismicImage/page.tsx b/e2e-projects/nextjs/app/PrismicImage/page.tsx index 6a6b331..8dcdb73 100644 --- a/e2e-projects/nextjs/app/PrismicImage/page.tsx +++ b/e2e-projects/nextjs/app/PrismicImage/page.tsx @@ -1,28 +1,28 @@ -import assert from "assert"; +import assert from "assert" -import { isFilled } from "@prismicio/client"; -import { PrismicImage } from "@prismicio/react"; -import type { ReactNode } from "react"; +import { isFilled } from "@prismicio/client" +import { PrismicImage } from "@prismicio/react" +import type { ReactNode } from "react" -import { createClient } from "@/prismicio"; +import { createClient } from "@/prismicio" export default async function Page(): Promise { - const client = await createClient(); - const { data: tests } = await client.getSingle("image_test"); + const client = await createClient() + const { data: tests } = await client.getSingle("image_test") - assert(isFilled.image(tests.with_alt_text) && tests.with_alt_text.alt !== null); - assert(isFilled.image(tests.without_alt_text) && tests.without_alt_text.alt === null); - assert(isFilled.image(tests.filled)); - assert(!isFilled.image(tests.empty)); + assert(isFilled.image(tests.with_alt_text) && tests.with_alt_text.alt !== null) + assert(isFilled.image(tests.without_alt_text) && tests.without_alt_text.alt === null) + assert(isFilled.image(tests.filled)) + assert(!isFilled.image(tests.empty)) assert( isFilled.image(tests.with_crop) && new URL(tests.with_crop.url).searchParams.get("rect") !== null, - ); + ) assert( isFilled.image(tests.with_thumbnails) && isFilled.imageThumbnail(tests.with_thumbnails.foo) && isFilled.imageThumbnail(tests.with_thumbnails.bar), - ); + ) return ( <> @@ -72,5 +72,5 @@ export default async function Page(): Promise { imgixParams={{ rect: [0, 0, 100, 100] }} /> - ); + ) } diff --git a/e2e-projects/nextjs/app/PrismicLink/client/page.tsx b/e2e-projects/nextjs/app/PrismicLink/client/page.tsx index 5ba5634..f320465 100644 --- a/e2e-projects/nextjs/app/PrismicLink/client/page.tsx +++ b/e2e-projects/nextjs/app/PrismicLink/client/page.tsx @@ -1,15 +1,15 @@ -"use client"; +"use client" -import { PrismicLink } from "@prismicio/react"; -import type { ReactNode } from "react"; -import { useState } from "react"; +import { PrismicLink } from "@prismicio/react" +import type { ReactNode } from "react" +import { useState } from "react" export default function Page(): ReactNode { - const [ref, setRef] = useState(null); + const [ref, setRef] = useState(null) return ( tagname: {ref?.tagName} - ); + ) } diff --git a/e2e-projects/nextjs/app/PrismicLink/page.tsx b/e2e-projects/nextjs/app/PrismicLink/page.tsx index 55b2f46..99d5960 100644 --- a/e2e-projects/nextjs/app/PrismicLink/page.tsx +++ b/e2e-projects/nextjs/app/PrismicLink/page.tsx @@ -1,38 +1,38 @@ -import assert from "assert"; +import assert from "assert" -import { isFilled } from "@prismicio/client"; -import { PrismicLink } from "@prismicio/react"; -import Link from "next/link"; -import type { ReactNode } from "react"; +import { isFilled } from "@prismicio/client" +import { PrismicLink } from "@prismicio/react" +import Link from "next/link" +import type { ReactNode } from "react" -import { createClient } from "@/prismicio"; +import { createClient } from "@/prismicio" export default async function Page(): Promise { - const client = await createClient(); - const { data: tests } = await client.getSingle("link_test"); + const client = await createClient() + const { data: tests } = await client.getSingle("link_test") assert( isFilled.link(tests.document) && tests.document.link_type === "Document" && tests.document.url, - ); - const doc = await client.getByID(tests.document.id); + ) + const doc = await client.getByID(tests.document.id) - assert(isFilled.link(tests.media) && tests.media.link_type === "Media"); + assert(isFilled.link(tests.media) && tests.media.link_type === "Media") assert( isFilled.link(tests.internal_web) && tests.internal_web.link_type === "Web" && !tests.internal_web.url.startsWith("http"), - ); + ) assert( isFilled.link(tests.external_web) && tests.external_web.link_type === "Web" && tests.external_web.url.startsWith("http"), - ); + ) assert( isFilled.link(tests.external_web_with_target) && tests.external_web_with_target.link_type === "Web" && tests.external_web_with_target.url.startsWith("http") && tests.external_web_with_target.target, - ); - assert(isFilled.link(tests.with_text) && tests.with_text.text); + ) + assert(isFilled.link(tests.with_text) && tests.with_text.text) return ( <> @@ -83,5 +83,5 @@ export default async function Page(): Promise { override - ); + ) } diff --git a/e2e-projects/nextjs/app/PrismicRichText/page.tsx b/e2e-projects/nextjs/app/PrismicRichText/page.tsx index 17514fc..5e2b3f4 100644 --- a/e2e-projects/nextjs/app/PrismicRichText/page.tsx +++ b/e2e-projects/nextjs/app/PrismicRichText/page.tsx @@ -1,17 +1,17 @@ -import assert from "assert"; +import assert from "assert" -import { isFilled } from "@prismicio/client"; -import { PrismicRichText } from "@prismicio/react"; -import type { ReactNode } from "react"; +import { isFilled } from "@prismicio/client" +import { PrismicRichText } from "@prismicio/react" +import type { ReactNode } from "react" -import { createClient } from "@/prismicio"; +import { createClient } from "@/prismicio" export default async function Page(): Promise { - const client = await createClient(); - const { data: tests } = await client.getSingle("rich_text_test"); + const client = await createClient() + const { data: tests } = await client.getSingle("rich_text_test") - assert(isFilled.richText(tests.filled)); - assert(!isFilled.richText(tests.empty)); + assert(isFilled.richText(tests.filled)) + assert(!isFilled.richText(tests.empty)) return ( <> @@ -280,5 +280,5 @@ export default async function Page(): Promise { - ); + ) } diff --git a/e2e-projects/nextjs/app/PrismicTable/page.tsx b/e2e-projects/nextjs/app/PrismicTable/page.tsx index 9af9805..afbe80f 100644 --- a/e2e-projects/nextjs/app/PrismicTable/page.tsx +++ b/e2e-projects/nextjs/app/PrismicTable/page.tsx @@ -1,17 +1,17 @@ -import assert from "assert"; +import assert from "assert" -import { isFilled } from "@prismicio/client"; -import { PrismicTable } from "@prismicio/react"; -import type { ReactNode } from "react"; +import { isFilled } from "@prismicio/client" +import { PrismicTable } from "@prismicio/react" +import type { ReactNode } from "react" -import { createClient } from "@/prismicio"; +import { createClient } from "@/prismicio" export default async function Page(): Promise { - const client = await createClient(); - const { data: tests } = await client.getSingle("table_test"); + const client = await createClient() + const { data: tests } = await client.getSingle("table_test") - assert(isFilled.table(tests.filled)); - assert(!isFilled.table(tests.empty)); + assert(isFilled.table(tests.filled)) + assert(!isFilled.table(tests.empty)) return ( <> @@ -53,5 +53,5 @@ export default async function Page(): Promise { /> - ); + ) } diff --git a/e2e-projects/nextjs/app/PrismicText/page.tsx b/e2e-projects/nextjs/app/PrismicText/page.tsx index 05ca3db..c0967e6 100644 --- a/e2e-projects/nextjs/app/PrismicText/page.tsx +++ b/e2e-projects/nextjs/app/PrismicText/page.tsx @@ -1,19 +1,19 @@ -import assert from "assert"; +import assert from "assert" -import { isFilled } from "@prismicio/client"; -import { PrismicText } from "@prismicio/react"; -import type { ReactNode } from "react"; +import { isFilled } from "@prismicio/client" +import { PrismicText } from "@prismicio/react" +import type { ReactNode } from "react" -import { createClient } from "@/prismicio"; +import { createClient } from "@/prismicio" export default async function Page(): Promise { - const client = await createClient(); - const { data: tests } = await client.getSingle("rich_text_test"); + const client = await createClient() + const { data: tests } = await client.getSingle("rich_text_test") - assert(isFilled.richText(tests.filled)); - assert(!isFilled.richText(tests.empty)); - assert(isFilled.keyText(tests.keytext)); - assert(isFilled.select(tests.select)); + assert(isFilled.richText(tests.filled)) + assert(!isFilled.richText(tests.empty)) + assert(isFilled.keyText(tests.keytext)) + assert(isFilled.select(tests.select)) return ( <> @@ -42,5 +42,5 @@ export default async function Page(): Promise { - ); + ) } diff --git a/e2e-projects/nextjs/app/PrismicToolbar/page.tsx b/e2e-projects/nextjs/app/PrismicToolbar/page.tsx index 4cc70fe..9a228f6 100644 --- a/e2e-projects/nextjs/app/PrismicToolbar/page.tsx +++ b/e2e-projects/nextjs/app/PrismicToolbar/page.tsx @@ -1,10 +1,10 @@ -import { PrismicToolbar } from "@prismicio/react"; -import type { ReactNode } from "react"; +import { PrismicToolbar } from "@prismicio/react" +import type { ReactNode } from "react" -import { createClient } from "@/prismicio"; +import { createClient } from "@/prismicio" export default async function Page(): Promise { - const client = await createClient(); + const client = await createClient() - return ; + return } diff --git a/e2e-projects/nextjs/app/PrismicToolbar/preview-events/PrismicToolbarPreviewEvents.tsx b/e2e-projects/nextjs/app/PrismicToolbar/preview-events/PrismicToolbarPreviewEvents.tsx index e19b476..eb3f3e9 100644 --- a/e2e-projects/nextjs/app/PrismicToolbar/preview-events/PrismicToolbarPreviewEvents.tsx +++ b/e2e-projects/nextjs/app/PrismicToolbar/preview-events/PrismicToolbarPreviewEvents.tsx @@ -1,20 +1,20 @@ -"use client"; +"use client" -import { PrismicToolbar } from "@prismicio/react"; -import { type ReactNode, useState } from "react"; +import { PrismicToolbar } from "@prismicio/react" +import { type ReactNode, useState } from "react" export function PrismicToolbarPreviewEvents(props: { repositoryName: string }): ReactNode { - const [updateCount, setUpdateCount] = useState(0); - const [endCount, setEndCount] = useState(0); - const [updateRef, setUpdateRef] = useState(""); + const [updateCount, setUpdateCount] = useState(0) + const [endCount, setEndCount] = useState(0) + const [updateRef, setUpdateRef] = useState("") return ( <> { - setUpdateCount((c) => c + 1); - setUpdateRef(event.detail.ref); + setUpdateCount((c) => c + 1) + setUpdateRef(event.detail.ref) }} onPreviewEnd={() => setEndCount((c) => c + 1)} /> @@ -22,5 +22,5 @@ export function PrismicToolbarPreviewEvents(props: { repositoryName: string }): {endCount} {updateRef} - ); + ) } diff --git a/e2e-projects/nextjs/app/PrismicToolbar/preview-events/page.tsx b/e2e-projects/nextjs/app/PrismicToolbar/preview-events/page.tsx index 26e1409..2617d07 100644 --- a/e2e-projects/nextjs/app/PrismicToolbar/preview-events/page.tsx +++ b/e2e-projects/nextjs/app/PrismicToolbar/preview-events/page.tsx @@ -1,11 +1,11 @@ -import type { ReactNode } from "react"; +import type { ReactNode } from "react" -import { createClient } from "@/prismicio"; +import { createClient } from "@/prismicio" -import { PrismicToolbarPreviewEvents } from "./PrismicToolbarPreviewEvents"; +import { PrismicToolbarPreviewEvents } from "./PrismicToolbarPreviewEvents" export default async function Page(): Promise { - const client = await createClient(); + const client = await createClient() - return ; + return } diff --git a/e2e-projects/nextjs/app/SliceZone/page.tsx b/e2e-projects/nextjs/app/SliceZone/page.tsx index fab83d7..f866bf3 100644 --- a/e2e-projects/nextjs/app/SliceZone/page.tsx +++ b/e2e-projects/nextjs/app/SliceZone/page.tsx @@ -1,27 +1,27 @@ -import assert from "assert"; +import assert from "assert" -import { isFilled, mapSliceZone } from "@prismicio/client"; -import { type SliceComponentProps, SliceZone } from "@prismicio/react"; -import type { ReactNode } from "react"; +import { isFilled, mapSliceZone } from "@prismicio/client" +import { type SliceComponentProps, SliceZone } from "@prismicio/react" +import type { ReactNode } from "react" -import { createClient } from "@/prismicio"; +import { createClient } from "@/prismicio" export default async function Page(): Promise { - const client = await createClient(); - const { data: tests } = await client.getSingle("page"); + const client = await createClient() + const { data: tests } = await client.getSingle("page") - assert(isFilled.sliceZone(tests.filled)); - assert(!isFilled.sliceZone(tests.empty)); + assert(isFilled.sliceZone(tests.filled)) + assert(!isFilled.sliceZone(tests.empty)) - const graphQLURL = new URL("/graphql", client.documentAPIEndpoint); - graphQLURL.searchParams.set("query", graphQLQuery); - const graphQLRes = await client.graphQLFetch(graphQLURL.toString()); - const graphQL = await graphQLRes.json(); + const graphQLURL = new URL("/graphql", client.documentAPIEndpoint) + graphQLURL.searchParams.set("query", graphQLQuery) + const graphQLRes = await client.graphQLFetch(graphQLURL.toString()) + const graphQL = await graphQLRes.json() const mapped = await mapSliceZone(tests.filled, { text: () => ({ foo: "bar" }), image: () => ({ bar: "baz" }), - }); + }) return ( <> @@ -45,13 +45,13 @@ export default async function Page(): Promise { - ); + ) } const components = { text: (props: SliceComponentProps) =>
{JSON.stringify(props)}
, image: (props: SliceComponentProps) =>
{JSON.stringify(props)}
, -}; +} const graphQLQuery = /* GraphQL */ ` query Foo { @@ -88,4 +88,4 @@ const graphQLQuery = /* GraphQL */ ` } } } -`; +` diff --git a/e2e-projects/nextjs/app/layout.tsx b/e2e-projects/nextjs/app/layout.tsx index be8abc9..84edb8c 100644 --- a/e2e-projects/nextjs/app/layout.tsx +++ b/e2e-projects/nextjs/app/layout.tsx @@ -1,9 +1,9 @@ -import type { ReactNode } from "react"; +import type { ReactNode } from "react" export default function RootLayout({ children }: { children: ReactNode }): ReactNode { return ( {children} - ); + ) } diff --git a/e2e-projects/nextjs/next.config.ts b/e2e-projects/nextjs/next.config.ts index 41cf08a..94013a4 100644 --- a/e2e-projects/nextjs/next.config.ts +++ b/e2e-projects/nextjs/next.config.ts @@ -1,12 +1,12 @@ -import { fileURLToPath } from "node:url"; +import { fileURLToPath } from "node:url" -import type { NextConfig } from "next"; +import type { NextConfig } from "next" const nextConfig: NextConfig = { outputFileTracingRoot: fileURLToPath(new URL("../..", import.meta.url)), images: { remotePatterns: [{ hostname: "images.prismic.io" }], }, -}; +} -export default nextConfig; +export default nextConfig diff --git a/e2e-projects/nextjs/package.json b/e2e-projects/nextjs/package.json index 8ec15df..6c67ebf 100644 --- a/e2e-projects/nextjs/package.json +++ b/e2e-projects/nextjs/package.json @@ -9,7 +9,7 @@ "dependencies": { "@prismicio/client": "^7.21.7", "@prismicio/react": "*", - "next": "16.2.2", + "next": "16.2.12", "react": "19.2.4", "react-dom": "19.2.4" }, diff --git a/e2e-projects/nextjs/prismic-types.d.ts b/e2e-projects/nextjs/prismic-types.d.ts index e429148..3238375 100644 --- a/e2e-projects/nextjs/prismic-types.d.ts +++ b/e2e-projects/nextjs/prismic-types.d.ts @@ -1,8 +1,8 @@ // Code generated by prismic-ts-codegen. DO NOT EDIT. -import type * as prismic from "@prismicio/client"; +import type * as prismic from "@prismicio/client" -type Simplify = { [KeyType in keyof T]: T[KeyType] }; +type Simplify = { [KeyType in keyof T]: T[KeyType] } /** Content for Image Test documents */ interface ImageTestDocumentData { @@ -15,7 +15,7 @@ interface ImageTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#image */ - empty: prismic.ImageField; + empty: prismic.ImageField /** * Filled field in _Image Test_ @@ -26,7 +26,7 @@ interface ImageTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#image */ - filled: prismic.ImageField; + filled: prismic.ImageField /** * With Alt Text field in _Image Test_ @@ -37,7 +37,7 @@ interface ImageTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#image */ - with_alt_text: prismic.ImageField; + with_alt_text: prismic.ImageField /** * Without Alt Text field in _Image Test_ @@ -48,7 +48,7 @@ interface ImageTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#image */ - without_alt_text: prismic.ImageField; + without_alt_text: prismic.ImageField /** * With Crop field in _Image Test_ @@ -59,7 +59,7 @@ interface ImageTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#image */ - with_crop: prismic.ImageField; + with_crop: prismic.ImageField /** * With Thumbnails field in _Image Test_ @@ -70,7 +70,7 @@ interface ImageTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#image */ - with_thumbnails: prismic.ImageField<"foo" | "bar">; + with_thumbnails: prismic.ImageField<"foo" | "bar"> } /** @@ -86,7 +86,7 @@ export type ImageTestDocument = prismic.PrismicDoc Simplify, "image_test", Lang ->; +> /** Content for Link Test documents */ interface LinkTestDocumentData { @@ -99,7 +99,7 @@ interface LinkTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#link-content-relationship */ - empty: prismic.LinkField; + empty: prismic.LinkField /** * Internal Web field in _Link Test_ @@ -110,7 +110,7 @@ interface LinkTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#link-content-relationship */ - internal_web: prismic.LinkField; + internal_web: prismic.LinkField /** * External Web field in _Link Test_ @@ -121,7 +121,7 @@ interface LinkTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#link-content-relationship */ - external_web: prismic.LinkField; + external_web: prismic.LinkField /** * External Web With Target field in _Link Test_ @@ -132,7 +132,7 @@ interface LinkTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#link-content-relationship */ - external_web_with_target: prismic.LinkField; + external_web_with_target: prismic.LinkField /** * Document field in _Link Test_ @@ -143,7 +143,7 @@ interface LinkTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#link-content-relationship */ - document: prismic.LinkField; + document: prismic.LinkField /** * Media field in _Link Test_ @@ -154,7 +154,7 @@ interface LinkTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#link-content-relationship */ - media: prismic.LinkField; + media: prismic.LinkField /** * With Text field in _Link Test_ @@ -165,7 +165,7 @@ interface LinkTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#link-content-relationship */ - with_text: prismic.LinkField; + with_text: prismic.LinkField } /** @@ -181,11 +181,11 @@ export type LinkTestDocument = prismic.PrismicDocu Simplify, "link_test", Lang ->; +> -type PageDocumentDataFilledSlice = TextSlice | ImageSlice; +type PageDocumentDataFilledSlice = TextSlice | ImageSlice -type PageDocumentDataEmptySlice = TextSlice | ImageSlice; +type PageDocumentDataEmptySlice = TextSlice | ImageSlice /** Content for Page documents */ interface PageDocumentData { @@ -206,8 +206,8 @@ interface PageDocumentData { * - **API ID Path**: page.empty[] * - **Tab**: Empty * - **Documentation**: https://prismic.io/docs/field#slices - */; - empty: prismic.SliceZone; + */ + empty: prismic.SliceZone } /** @@ -223,7 +223,7 @@ export type PageDocument = prismic.PrismicDocument Simplify, "page", Lang ->; +> /** Content for Rich Text Test documents */ interface RichTextTestDocumentData { @@ -236,7 +236,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - empty: prismic.RichTextField; + empty: prismic.RichTextField /** * Filled field in _Rich Text Test_ @@ -247,7 +247,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - filled: prismic.RichTextField; + filled: prismic.RichTextField /** * Key Text field in _Rich Text Test_ @@ -258,7 +258,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#key-text */ - keytext: prismic.KeyTextField; + keytext: prismic.KeyTextField /** * Select field in _Rich Text Test_ @@ -269,7 +269,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#select */ - select: prismic.SelectField<"foo">; + select: prismic.SelectField<"foo"> /** * Heading 1 field in _Rich Text Test_ @@ -280,7 +280,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - heading1: prismic.RichTextField; + heading1: prismic.RichTextField /** * Heading 2 field in _Rich Text Test_ @@ -291,7 +291,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - heading2: prismic.RichTextField; + heading2: prismic.RichTextField /** * Heading 3 field in _Rich Text Test_ @@ -302,7 +302,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - heading3: prismic.RichTextField; + heading3: prismic.RichTextField /** * Heading 4 field in _Rich Text Test_ @@ -313,7 +313,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - heading4: prismic.RichTextField; + heading4: prismic.RichTextField /** * Heading 5 field in _Rich Text Test_ @@ -324,7 +324,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - heading5: prismic.RichTextField; + heading5: prismic.RichTextField /** * Heading 6 field in _Rich Text Test_ @@ -335,7 +335,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - heading6: prismic.RichTextField; + heading6: prismic.RichTextField /** * Paragraph field in _Rich Text Test_ @@ -346,7 +346,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - paragraph: prismic.RichTextField; + paragraph: prismic.RichTextField /** * Preformatted field in _Rich Text Test_ @@ -357,7 +357,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - preformatted: prismic.RichTextField; + preformatted: prismic.RichTextField /** * Strong field in _Rich Text Test_ @@ -368,7 +368,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - strong: prismic.RichTextField; + strong: prismic.RichTextField /** * Em field in _Rich Text Test_ @@ -379,7 +379,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - em: prismic.RichTextField; + em: prismic.RichTextField /** * List field in _Rich Text Test_ @@ -390,7 +390,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - list: prismic.RichTextField; + list: prismic.RichTextField /** * Ordered List field in _Rich Text Test_ @@ -401,7 +401,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - ordered_list: prismic.RichTextField; + ordered_list: prismic.RichTextField /** * Image field in _Rich Text Test_ @@ -412,7 +412,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - image: prismic.RichTextField; + image: prismic.RichTextField /** * Embed field in _Rich Text Test_ @@ -423,7 +423,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - embed: prismic.RichTextField; + embed: prismic.RichTextField /** * Hyperlink Internal field in _Rich Text Test_ @@ -434,7 +434,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - hyperlink_internal: prismic.RichTextField; + hyperlink_internal: prismic.RichTextField /** * Hyperlink External field in _Rich Text Test_ @@ -445,7 +445,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - hyperlink_external: prismic.RichTextField; + hyperlink_external: prismic.RichTextField /** * Label field in _Rich Text Test_ @@ -456,7 +456,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - label: prismic.RichTextField; + label: prismic.RichTextField /** * RTL field in _Rich Text Test_ @@ -467,7 +467,7 @@ interface RichTextTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - rtl: prismic.RichTextField; + rtl: prismic.RichTextField } /** @@ -483,7 +483,7 @@ export type RichTextTestDocument = prismic.Prismic Simplify, "rich_text_test", Lang ->; +> /** Content for Table Test documents */ interface TableTestDocumentData { @@ -496,7 +496,7 @@ interface TableTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#table */ - empty: prismic.TableField; + empty: prismic.TableField /** * Filled field in _Table Test_ @@ -507,7 +507,7 @@ interface TableTestDocumentData { * - **Tab**: Main * - **Documentation**: https://prismic.io/docs/field#table */ - filled: prismic.TableField; + filled: prismic.TableField } /** @@ -523,14 +523,14 @@ export type TableTestDocument = prismic.PrismicDoc Simplify, "table_test", Lang ->; +> export type AllDocumentTypes = | ImageTestDocument | LinkTestDocument | PageDocument | RichTextTestDocument - | TableTestDocument; + | TableTestDocument /** Primary content in _Image → Default → Primary_ */ export interface ImageSliceDefaultPrimary { @@ -542,7 +542,7 @@ export interface ImageSliceDefaultPrimary { * - **API ID Path**: image.default.primary.content * - **Documentation**: https://prismic.io/docs/field#image */ - content: prismic.ImageField; + content: prismic.ImageField } /** @@ -556,10 +556,10 @@ export type ImageSliceDefault = prismic.SharedSliceVariation< "default", Simplify, never ->; +> /** Slice variation for _Image_ */ -type ImageSliceVariation = ImageSliceDefault; +type ImageSliceVariation = ImageSliceDefault /** * Image Shared Slice @@ -568,7 +568,7 @@ type ImageSliceVariation = ImageSliceDefault; * - **Description**: Image * - **Documentation**: https://prismic.io/docs/slice */ -export type ImageSlice = prismic.SharedSlice<"image", ImageSliceVariation>; +export type ImageSlice = prismic.SharedSlice<"image", ImageSliceVariation> /** Primary content in _Text → Default → Primary_ */ export interface TextSliceDefaultPrimary { @@ -580,7 +580,7 @@ export interface TextSliceDefaultPrimary { * - **API ID Path**: text.default.primary.content * - **Documentation**: https://prismic.io/docs/field#rich-text-title */ - content: prismic.RichTextField; + content: prismic.RichTextField } /** @@ -594,10 +594,10 @@ export type TextSliceDefault = prismic.SharedSliceVariation< "default", Simplify, never ->; +> /** Slice variation for _Text_ */ -type TextSliceVariation = TextSliceDefault; +type TextSliceVariation = TextSliceDefault /** * Text Shared Slice @@ -606,25 +606,25 @@ type TextSliceVariation = TextSliceDefault; * - **Description**: Text * - **Documentation**: https://prismic.io/docs/slice */ -export type TextSlice = prismic.SharedSlice<"text", TextSliceVariation>; +export type TextSlice = prismic.SharedSlice<"text", TextSliceVariation> declare module "@prismicio/client" { interface CreateClient { ( repositoryNameOrEndpoint: string, options?: prismic.ClientConfig, - ): prismic.Client; + ): prismic.Client } interface CreateWriteClient { ( repositoryNameOrEndpoint: string, options: prismic.WriteClientConfig, - ): prismic.WriteClient; + ): prismic.WriteClient } interface CreateMigration { - (): prismic.Migration; + (): prismic.Migration } namespace Content { @@ -648,6 +648,6 @@ declare module "@prismicio/client" { TextSliceDefaultPrimary, TextSliceVariation, TextSliceDefault, - }; + } } } diff --git a/e2e-projects/nextjs/prismicio.ts b/e2e-projects/nextjs/prismicio.ts index 9bb5cae..79cd3df 100644 --- a/e2e-projects/nextjs/prismicio.ts +++ b/e2e-projects/nextjs/prismicio.ts @@ -1,18 +1,18 @@ -import assert from "node:assert"; +import assert from "node:assert" -import * as prismic from "@prismicio/client"; -import { cookies } from "next/headers"; +import * as prismic from "@prismicio/client" +import { cookies } from "next/headers" export async function createClient(config: prismic.ClientConfig = {}): Promise { - const cookieJar = await cookies(); - const repositoryName = cookieJar.get("repository-name")?.value; - assert(repositoryName, "A repository-name cookie is required."); + const cookieJar = await cookies() + const repositoryName = cookieJar.get("repository-name")?.value + assert(repositoryName, "A repository-name cookie is required.") const client = prismic.createClient(repositoryName, { routes: [{ type: "page", path: "/page" }], fetchOptions: { cache: "no-store" }, ...config, - }); + }) - return client; + return client } diff --git a/e2e-projects/nextjs/tsconfig.json b/e2e-projects/nextjs/tsconfig.json index e7ff3a2..fd75fd2 100644 --- a/e2e-projects/nextjs/tsconfig.json +++ b/e2e-projects/nextjs/tsconfig.json @@ -1,41 +1,33 @@ { - "compilerOptions": { - "target": "ES2017", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], - "allowJs": true, - "skipLibCheck": true, - "strict": true, - "noEmit": true, - "esModuleInterop": true, - "module": "esnext", - "moduleResolution": "bundler", - "resolveJsonModule": true, - "isolatedModules": true, - "jsx": "react-jsx", - "incremental": true, - "plugins": [ - { - "name": "next" - } - ], - "paths": { - "@/*": [ - "./*" - ] - } - }, - "include": [ - "next-env.d.ts", - "**/*.ts", - "**/*.tsx", - ".next/types/**/*.ts", - ".next/dev/types/**/*.ts" - ], - "exclude": [ - "node_modules" - ] + "compilerOptions": { + "target": "ES2017", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "strict": true, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "bundler", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "react-jsx", + "incremental": true, + "plugins": [ + { + "name": "next" + } + ], + "paths": { + "@/*": ["./*"] + } + }, + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx", + ".next/types/**/*.ts", + ".next/dev/types/**/*.ts" + ], + "exclude": ["node_modules"] } diff --git a/examples/custom-slicezone-props/index.tsx b/examples/custom-slicezone-props/index.tsx index d1d6289..6e36aee 100644 --- a/examples/custom-slicezone-props/index.tsx +++ b/examples/custom-slicezone-props/index.tsx @@ -1,7 +1,7 @@ -import { SliceZone, type SliceComponentProps, type SliceComponentType } from "@prismicio/react"; -import type { ReactNode } from "react"; +import { SliceZone, type SliceComponentProps, type SliceComponentType } from "@prismicio/react" +import type { ReactNode } from "react" -import type { HeroSlice, ExampleSliceZone } from "./types"; +import type { HeroSlice, ExampleSliceZone } from "./types" // This is the contents of a Slice Zone field. // Normally, this would be accessed at `document.data.body`, where `document` @@ -40,7 +40,7 @@ const slices: ExampleSliceZone = [ items: [], version: "2", }, -]; +] // This React component is rendered for Hero Slices. // It accepts a Slice object as a prop. @@ -56,8 +56,8 @@ const HeroSlice = ({ slice }: SliceComponentProps) => { ))} - ); -}; + ) +} // This React component is rendered for Call To Action Slices. // @@ -71,8 +71,8 @@ const CallToActionSlice = ({ text, disclaimer }: { text: string; disclaimer: str

{text}

{disclaimer} - ); -}; + ) +} // This object contains a component for each type of Slice that can be rendered // by ``. @@ -89,10 +89,10 @@ const components: Record = { // // We can also pass arbitrary data as well, such as the `disclaimer` prop. call_to_action: ({ slice }) => , -}; +} // We render the Slice Zone using the `` component by passing the // list of Slices and component map. export const App = (): ReactNode => { - return ; -}; + return +} diff --git a/examples/custom-slicezone-props/types.ts b/examples/custom-slicezone-props/types.ts index 89d35b5..360db12 100644 --- a/examples/custom-slicezone-props/types.ts +++ b/examples/custom-slicezone-props/types.ts @@ -1,30 +1,30 @@ -import type * as prismic from "@prismicio/client"; +import type * as prismic from "@prismicio/client" export type HeroSlice = prismic.SharedSlice< "hero", prismic.SharedSliceVariation< "default", { - heading: prismic.KeyTextField; - buttonText: prismic.KeyTextField; + heading: prismic.KeyTextField + buttonText: prismic.KeyTextField cards: prismic.GroupField<{ - title: prismic.KeyTextField; - content: prismic.KeyTextField; - }>; + title: prismic.KeyTextField + content: prismic.KeyTextField + }> } > ->; +> export type CallToActionSlice = prismic.SharedSlice< "call_to_action", prismic.SharedSliceVariation< "default", { - text: prismic.KeyTextField; + text: prismic.KeyTextField } > ->; +> -export type Slices = HeroSlice | CallToActionSlice; +export type Slices = HeroSlice | CallToActionSlice -export type ExampleSliceZone = prismic.SliceZone; +export type ExampleSliceZone = prismic.SliceZone diff --git a/examples/router-link/index.tsx b/examples/router-link/index.tsx index 43540e4..45ebf63 100644 --- a/examples/router-link/index.tsx +++ b/examples/router-link/index.tsx @@ -1,19 +1,19 @@ -import type * as prismic from "@prismicio/client"; -import { PrismicLink, type LinkProps } from "@prismicio/react"; -import type { ReactNode } from "react"; -import { Link } from "react-router"; +import type * as prismic from "@prismicio/client" +import { PrismicLink, type LinkProps } from "@prismicio/react" +import type { ReactNode } from "react" +import { Link } from "react-router" // This is an example Link field value. It contains a URL internal to the app. const field: prismic.LinkField = { link_type: "Web", url: "/internal-url", -}; +} // This React component acts as a "shim" to convert the `href` prop provided by // `` to the `to` prop required by react-router-dom's ``. const LinkShim = ({ href, ...props }: LinkProps): ReactNode => { - return ; -}; + return +} // We render the Link field using ``. Since the field contains an // internal URL, react-router-dom's `` component will render. @@ -22,5 +22,5 @@ export const App = (): ReactNode => {
- ); -}; + ) +} diff --git a/examples/with-typescript/index.tsx b/examples/with-typescript/index.tsx index 0d04f50..666d694 100644 --- a/examples/with-typescript/index.tsx +++ b/examples/with-typescript/index.tsx @@ -1,14 +1,14 @@ -import * as prismic from "@prismicio/client"; -import { SliceZone, PrismicRichText, PrismicLink } from "@prismicio/react"; -import type { ReactNode } from "react"; +import * as prismic from "@prismicio/client" +import { SliceZone, PrismicRichText, PrismicLink } from "@prismicio/react" +import type { ReactNode } from "react" // Documents can be typed using `@prismicio/client` type PageDocument = prismic.PrismicDocumentWithUID<{ - title: prismic.TitleField; - meta_description: prismic.RichTextField; + title: prismic.TitleField + meta_description: prismic.RichTextField related_links: prismic.GroupField<{ - link: prismic.LinkField; - }>; + link: prismic.LinkField + }> // Each Slice in a Slice Zone can be typed using `prismic.SharedSlice` slices: prismic.SliceZone< @@ -19,11 +19,11 @@ type PageDocument = prismic.PrismicDocumentWithUID<{ "default", // Fields { - heading: prismic.KeyTextField; - body: prismic.RichTextField; + heading: prismic.KeyTextField + body: prismic.RichTextField buttons: prismic.GroupField<{ - link: prismic.LinkField; - }>; + link: prismic.LinkField + }> } > > @@ -34,15 +34,15 @@ type PageDocument = prismic.PrismicDocumentWithUID<{ "default", // Fields { - text: prismic.RichTextField; + text: prismic.RichTextField buttons: prismic.GroupField<{ - link: prismic.LinkField; - }>; + link: prismic.LinkField + }> } > > - >; -}>; + > +}> // Let's assume we have a full document from the Prismic Rest API V2. // @@ -50,20 +50,20 @@ type PageDocument = prismic.PrismicDocumentWithUID<{ // without needing to type it out for this example. // // In your real project, this would come from the API via `@prismicio/client`. -declare const page: PageDocument; +declare const page: PageDocument // Components from `@prismicio/react` will work with this type to ensure the // correct fields are passed. // Rendering a Rich Text or Title looks like this. export const WithRichText = (): ReactNode => { - return ; -}; + return +} // Rendering a link to a document looks like this. export const WithDocumentLink = (): ReactNode => { - return ; -}; + return +} // Rendering a group looks like this. // Using `isFilled.group()` and `isFilled.link()` from `@prismicio/helpers` @@ -85,8 +85,8 @@ export const WithGroupFieldLink = (): ReactNode => { ), )} - ); -}; + ) +} // Rendering a Slice Zone looks like this. // Note that the `components` object is typed to ensure a component is given @@ -100,5 +100,5 @@ export const WithSliceZone = (): ReactNode => { call_to_action: () =>
Call to Action Slice
, }} /> - ); -}; + ) +} diff --git a/package-lock.json b/package-lock.json index ca5a9cd..27ec6d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,7 +41,7 @@ "dependencies": { "@prismicio/client": "^7.21.7", "@prismicio/react": "*", - "next": "16.2.2", + "next": "16.2.12", "react": "19.2.4", "react-dom": "19.2.4" }, @@ -613,15 +613,15 @@ } }, "node_modules/@next/env": { - "version": "16.2.2", - "resolved": "https://registry.npmjs.org/@next/env/-/env-16.2.2.tgz", - "integrity": "sha512-LqSGz5+xGk9EL/iBDr2yo/CgNQV6cFsNhRR2xhSXYh7B/hb4nePCxlmDvGEKG30NMHDFf0raqSyOZiQrO7BkHQ==", + "version": "16.2.12", + "resolved": "https://registry.npmjs.org/@next/env/-/env-16.2.12.tgz", + "integrity": "sha512-d0Z5Bc13Fa4nR8pFAKx2jay2yhJM16vlfHbTzYnUQAxlNb6B6lmn4hjt69lYNt4kRtyYP6gEM49lPRHNbIyneg==", "license": "MIT" }, "node_modules/@next/swc-darwin-arm64": { - "version": "16.2.2", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-16.2.2.tgz", - "integrity": "sha512-B92G3ulrwmkDSEJEp9+XzGLex5wC1knrmCSIylyVeiAtCIfvEJYiN3v5kXPlYt5R4RFlsfO/v++aKV63Acrugg==", + "version": "16.2.12", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-16.2.12.tgz", + "integrity": "sha512-0W1R0teHWJrqKX0FH20IzzIWAOuGtBxPGuObrxy1lE8hQvCFj49KE8a3WUg0D7sq6rn6zkM4c7YGUnhudBS6oA==", "cpu": [ "arm64" ], @@ -635,9 +635,9 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "16.2.2", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-16.2.2.tgz", - "integrity": "sha512-7ZwSgNKJNQiwW0CKhNm9B1WS2L1Olc4B2XY0hPYCAL3epFnugMhuw5TMWzMilQ3QCZcCHoYm9NGWTHbr5REFxw==", + "version": "16.2.12", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-16.2.12.tgz", + "integrity": "sha512-Hy5Ls099+aFUmOLmIgPfLqNi6iCwhL3uQCssz5rWk+5Nkc6TUKCE83DY5BbNylfm3+mfwcSFnLRfrZDJhVxdtw==", "cpu": [ "x64" ], @@ -651,12 +651,15 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "16.2.2", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-16.2.2.tgz", - "integrity": "sha512-c3m8kBHMziMgo2fICOP/cd/5YlrxDU5YYjAJeQLyFsCqVF8xjOTH/QYG4a2u48CvvZZSj1eHQfBCbyh7kBr30Q==", + "version": "16.2.12", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-16.2.12.tgz", + "integrity": "sha512-+YqU2h1cQkHsGfvjAsrSmst8UIFBibBGm5x3Xgel8NLMiDQtNOM4sM2GOEMvG5YiOBNeN/Ykk8cQC2S0Xrqljg==", "cpu": [ "arm64" ], + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -667,12 +670,15 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "16.2.2", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-16.2.2.tgz", - "integrity": "sha512-VKLuscm0P/mIfzt+SDdn2+8TNNJ7f0qfEkA+az7OqQbjzKdBxAHs0UvuiVoCtbwX+dqMEL9U54b5wQ/aN3dHeg==", + "version": "16.2.12", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-16.2.12.tgz", + "integrity": "sha512-0qjhiYBaKAqF63LA1ZWAAnKTzFUguAaZiRa5etMLGGPj/B6uEVjtIZldIzFEp3wHlB0koK6aTzqPtSdplTCjoA==", "cpu": [ "arm64" ], + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -683,12 +689,15 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "16.2.2", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-16.2.2.tgz", - "integrity": "sha512-kU3OPHJq6sBUjOk7wc5zJ7/lipn8yGldMoAv4z67j6ov6Xo/JvzA7L7LCsyzzsXmgLEhk3Qkpwqaq/1+XpNR3g==", + "version": "16.2.12", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-16.2.12.tgz", + "integrity": "sha512-7A3q26W+h7gnA15uqBToNuDqBEFZZcqh0mW2mn4AJh/G5pdg2RVE3n4slzLEliASZFG3NmsbEzng/x2Sh09mBg==", "cpu": [ "x64" ], + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -699,12 +708,15 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "16.2.2", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-16.2.2.tgz", - "integrity": "sha512-CKXRILyErMtUftp+coGcZ38ZwE/Aqq45VMCcRLr2I4OXKrgxIBDXHnBgeX/UMil0S09i2JXaDL3Q+TN8D/cKmg==", + "version": "16.2.12", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-16.2.12.tgz", + "integrity": "sha512-qSjL/uppm+cbh21s72Ss8gkiOhQ4dExWHNGOWy6eZV7STj5WsKehgxT61beSsOj+YYQuTplL376lOCdMQU5T8w==", "cpu": [ "x64" ], + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -715,9 +727,9 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "16.2.2", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-16.2.2.tgz", - "integrity": "sha512-sS/jSk5VUoShUqINJFvNjVT7JfR5ORYj/+/ZpOYbbIohv/lQfduWnGAycq2wlknbOql2xOR0DoV0s6Xfcy49+g==", + "version": "16.2.12", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-16.2.12.tgz", + "integrity": "sha512-X6hzsOUJac/e7AWSbn9gQ9nzHld1xWP5iyjHpYWvud8pufB679O1xg4JDyKr8Xd69Jvd+kM2Der6uftiZCmjYA==", "cpu": [ "arm64" ], @@ -731,9 +743,9 @@ } }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "16.2.2", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-16.2.2.tgz", - "integrity": "sha512-aHaKceJgdySReT7qeck5oShucxWRiiEuwCGK8HHALe6yZga8uyFpLkPgaRw3kkF04U7ROogL/suYCNt/+CuXGA==", + "version": "16.2.12", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-16.2.12.tgz", + "integrity": "sha512-F6fakeHuFTLOPt0bslQJdf+xtT+WIP9DVn/m4y1w1mRnVPyh3D/cNvzlRkxM444xfm+IvvYNSOrKiA2CDJ0Uxw==", "cpu": [ "x64" ], @@ -2044,7 +2056,6 @@ "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, "hasInstallScript": true, "license": "MIT", "optional": true, @@ -2175,12 +2186,12 @@ } }, "node_modules/next": { - "version": "16.2.2", - "resolved": "https://registry.npmjs.org/next/-/next-16.2.2.tgz", - "integrity": "sha512-i6AJdyVa4oQjyvX/6GeER8dpY/xlIV+4NMv/svykcLtURJSy/WzDnnUk/TM4d0uewFHK7xSQz4TbIwPgjky+3A==", + "version": "16.2.12", + "resolved": "https://registry.npmjs.org/next/-/next-16.2.12.tgz", + "integrity": "sha512-iD59eYQWmbFcEbX7v/acG5DRym9iw1DdaPoD0WTA920naWsE25wShzJW4+UvAs8MK9EC2kBfIH6vtto1H1PHGw==", "license": "MIT", "dependencies": { - "@next/env": "16.2.2", + "@next/env": "16.2.12", "@swc/helpers": "0.5.15", "baseline-browser-mapping": "^2.9.19", "caniuse-lite": "^1.0.30001579", @@ -2194,14 +2205,14 @@ "node": ">=20.9.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "16.2.2", - "@next/swc-darwin-x64": "16.2.2", - "@next/swc-linux-arm64-gnu": "16.2.2", - "@next/swc-linux-arm64-musl": "16.2.2", - "@next/swc-linux-x64-gnu": "16.2.2", - "@next/swc-linux-x64-musl": "16.2.2", - "@next/swc-win32-arm64-msvc": "16.2.2", - "@next/swc-win32-x64-msvc": "16.2.2", + "@next/swc-darwin-arm64": "16.2.12", + "@next/swc-darwin-x64": "16.2.12", + "@next/swc-linux-arm64-gnu": "16.2.12", + "@next/swc-linux-arm64-musl": "16.2.12", + "@next/swc-linux-x64-gnu": "16.2.12", + "@next/swc-linux-x64-musl": "16.2.12", + "@next/swc-win32-arm64-msvc": "16.2.12", + "@next/swc-win32-x64-msvc": "16.2.12", "sharp": "^0.34.5" }, "peerDependencies": { diff --git a/package.json b/package.json index 3e38897..82713fb 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,8 @@ "e2e-projects/*" ], "files": [ - "dist", - "src" + "./dist", + "./src" ], "type": "module", "sideEffects": false, diff --git a/playwright.config.ts b/playwright.config.ts index d35994c..06bf56b 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,16 +1,16 @@ -import assert from "node:assert"; -import { existsSync, writeFileSync } from "node:fs"; -import { fileURLToPath } from "node:url"; +import assert from "node:assert" +import { existsSync, writeFileSync } from "node:fs" +import { fileURLToPath } from "node:url" -import { defineConfig, devices } from "@playwright/test"; -import dotenv from "dotenv"; +import { defineConfig, devices } from "@playwright/test" +import dotenv from "dotenv" -dotenv.config({ path: ".env.test.local" }); +dotenv.config({ path: ".env.test.local" }) export const STORAGE_STATE = fileURLToPath( new URL("./tests/infra/.storage-state.json", import.meta.url), -); -if (!existsSync(STORAGE_STATE)) writeFileSync(STORAGE_STATE, JSON.stringify({})); +) +if (!existsSync(STORAGE_STATE)) writeFileSync(STORAGE_STATE, JSON.stringify({})) // https://playwright.dev/docs/test-configuration export default defineConfig({ @@ -57,18 +57,18 @@ export default defineConfig({ reuseExistingServer: !process.env.CI, }, ], -}); +}) declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace NodeJS { interface ProcessEnv { - CI: boolean; - E2E_PRISMIC_EMAIL: string; - E2E_PRISMIC_PASSWORD: string; + CI: boolean + E2E_PRISMIC_EMAIL: string + E2E_PRISMIC_PASSWORD: string } } } -assert.ok(process.env.E2E_PRISMIC_EMAIL, "Missing E2E_PRISMIC_EMAIL env variable."); -assert.ok(process.env.E2E_PRISMIC_PASSWORD, "Missing E2E_PRISMIC_PASSWORD env variable."); +assert.ok(process.env.E2E_PRISMIC_EMAIL, "Missing E2E_PRISMIC_EMAIL env variable.") +assert.ok(process.env.E2E_PRISMIC_PASSWORD, "Missing E2E_PRISMIC_PASSWORD env variable.") diff --git a/src/PrismicImage.tsx b/src/PrismicImage.tsx index fc5337d..620b417 100644 --- a/src/PrismicImage.tsx +++ b/src/PrismicImage.tsx @@ -3,33 +3,33 @@ import { asImagePixelDensitySrcSet, asImageWidthSrcSet, isFilled, -} from "@prismicio/client"; -import { DEV } from "esm-env"; -import { type ForwardedRef, forwardRef, type ComponentProps, type FC, type ReactNode } from "react"; +} from "@prismicio/client" +import { DEV } from "esm-env" +import { type ForwardedRef, forwardRef, type ComponentProps, type FC, type ReactNode } from "react" -import { devMsg } from "./lib/devMsg.js"; +import { devMsg } from "./lib/devMsg.js" type ImgixURLParams = Omit[1]>, "widths"> & - Omit[1]>, "pixelDensities">; + Omit[1]>, "pixelDensities"> /** Props for ``. */ export type PrismicImageProps = Omit, "src" | "srcset" | "alt"> & { /** The Prismic image field or thumbnail to render. */ - field: ImageFieldImage | null | undefined; + field: ImageFieldImage | null | undefined /** * An object of Imgix URL API parameters to transform the image. * * See: https://docs.imgix.com/apis/rendering */ - imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null }; + imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null } /** * Declare an image as decorative by providing `alt=""`. * * See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images */ - alt?: ""; + alt?: "" /** * Declare an image as decorative only if the image field does not have alternative text by @@ -37,13 +37,13 @@ export type PrismicImageProps = Omit, "src" | "srcset" | " * * See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images */ - fallbackAlt?: ""; + fallbackAlt?: "" /** * The value to be rendered when the field is empty. If a fallback is not given, `null` will be * rendered. */ - fallback?: ReactNode; + fallback?: ReactNode } & ( | { /** @@ -55,13 +55,13 @@ export type PrismicImageProps = Omit, "src" | "srcset" | " * If the image field contains responsive views, each responsive view can be used as a width * in the resulting `srcset` by passing `"thumbnails"` as the `widths` prop. */ - widths?: NonNullable[1]>["widths"] | "defaults"; + widths?: NonNullable[1]>["widths"] | "defaults" /** Not used when the `widths` prop is used. */ - pixelDensities?: never; + pixelDensities?: never } | { /** Not used when the `widths` prop is used. */ - widths?: never; + widths?: never /** * Pixel densities used to build a `srcset` value for the image field. * @@ -70,15 +70,15 @@ export type PrismicImageProps = Omit, "src" | "srcset" | " */ pixelDensities: | NonNullable[1]>["pixelDensities"] - | "defaults"; + | "defaults" } - ); + ) /** * Renders an optimized image from a Prismic image field. * * @example - * ```tsx + * ;```tsx * ; * ``` * @@ -97,7 +97,7 @@ export const PrismicImage: FC = forwardRef(function PrismicIm pixelDensities, fallback, ...restProps - } = props; + } = props if (DEV) { if (typeof alt === "string" && alt !== "") { @@ -105,7 +105,7 @@ export const PrismicImage: FC = forwardRef(function PrismicIm `[PrismicImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="". For more details, see ${devMsg( "alt-must-be-an-empty-string", )}`, - ); + ) } if (typeof fallbackAlt === "string" && fallbackAlt !== "") { @@ -113,46 +113,46 @@ export const PrismicImage: FC = forwardRef(function PrismicIm `[PrismicImage] The "fallbackAlt" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt="") but was provided a non-empty string. You can resolve this warning by removing the "fallbackAlt" prop or changing it to fallbackAlt="". For more details, see ${devMsg( "alt-must-be-an-empty-string", )}`, - ); + ) } if (widths && pixelDensities) { console.warn( `[PrismicImage] Only one of "widths" or "pixelDensities" props can be provided. You can resolve this warning by removing either the "widths" or "pixelDensities" prop. "widths" will be used in this case.`, - ); + ) } } if (!isFilled.imageThumbnail(field)) { - return <>{fallback}; + return <>{fallback} } - const resolvedImgixParams = imgixParams; + const resolvedImgixParams = imgixParams for (const x in imgixParams) { if (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) { - resolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined; + resolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined } } - let src: string | undefined; - let srcSet: string | undefined; + let src: string | undefined + let srcSet: string | undefined if (widths || !pixelDensities) { const res = asImageWidthSrcSet(field, { ...resolvedImgixParams, widths: widths === "defaults" ? undefined : widths, - } as ImgixURLParams); + } as ImgixURLParams) - src = res.src; - srcSet = res.srcset; + src = res.src + srcSet = res.srcset } else if (pixelDensities) { const res = asImagePixelDensitySrcSet(field, { ...resolvedImgixParams, pixelDensities: pixelDensities === "defaults" ? undefined : pixelDensities, - } as ImgixURLParams); + } as ImgixURLParams) - src = res.src; - srcSet = res.srcset; + src = res.src + srcSet = res.srcset } return ( @@ -163,5 +163,5 @@ export const PrismicImage: FC = forwardRef(function PrismicIm alt={alt ?? (field.alt || fallbackAlt)} {...restProps} /> - ); -}); + ) +}) diff --git a/src/PrismicLink.tsx b/src/PrismicLink.tsx index 808fa80..06e5782 100644 --- a/src/PrismicLink.tsx +++ b/src/PrismicLink.tsx @@ -4,8 +4,8 @@ import { type PrismicDocument, asLinkAttrs, type AsLinkAttrsConfig, -} from "@prismicio/client"; -import { DEV } from "esm-env"; +} from "@prismicio/client" +import { DEV } from "esm-env" import { type ComponentProps, type ComponentType, @@ -13,32 +13,32 @@ import { type HTMLAttributeAnchorTarget, type ReactNode, forwardRef, -} from "react"; +} from "react" -import { devMsg } from "./lib/devMsg.js"; +import { devMsg } from "./lib/devMsg.js" /** The default component rendered for internal and external links. */ -const defaultComponent = "a"; +const defaultComponent = "a" /** Props provided to a component when rendered with ``. */ export interface LinkProps { /** The URL to link. */ - href: string; + href: string /** * The `target` attribute for anchor elements. If the Prismic field is configured to open in a new * window, this prop defaults to `_blank`. */ - target?: HTMLAttributeAnchorTarget; + target?: HTMLAttributeAnchorTarget /** * The `rel` attribute for anchor elements. If the `target` prop is set to `"_blank"`, this prop * defaults to `"noopener noreferrer"`. */ - rel?: string; + rel?: string /** Children for the component. */ - children?: ReactNode; + children?: ReactNode } export type PrismicLinkProps< @@ -50,7 +50,7 @@ export type PrismicLinkProps< * external. This prop can be provided a function to use the link's metadata to determine the * `rel` value. */ - rel?: string | AsLinkAttrsConfig["rel"]; + rel?: string | AsLinkAttrsConfig["rel"] /** * The link resolver used to resolve links. @@ -60,7 +60,7 @@ export type PrismicLinkProps< * resolver does not need to be provided. * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes} */ - linkResolver?: LinkResolverFunction; + linkResolver?: LinkResolverFunction /** * The component rendered for internal URLs. Defaults to ``. @@ -68,39 +68,39 @@ export type PrismicLinkProps< * If your app uses a client-side router that requires a special Link component, provide the Link * component to this prop. */ - internalComponent?: ComponentType; + internalComponent?: ComponentType /** The component rendered for external URLs. Defaults to ``. */ - externalComponent?: ComponentType; + externalComponent?: ComponentType /** * The children to render for the link. If no children are provided, the link's `text` property * will be used. */ - children?: ReactNode; + children?: ReactNode } & ( | { - document: PrismicDocument | null | undefined; - href?: never; - field?: never; + document: PrismicDocument | null | undefined + href?: never + field?: never } | { - field: LinkField | null | undefined; - href?: never; - document?: never; + field: LinkField | null | undefined + href?: never + document?: never } | { - href: LinkProps["href"]; - field?: LinkField | null | undefined; - document?: never; + href: LinkProps["href"] + field?: LinkField | null | undefined + document?: never } - ); + ) /** * Renders a link from a Prismic link field or page. * * @example - * ```tsx + * ;```tsx * Click here; * ``` * @@ -121,7 +121,7 @@ export const PrismicLink = forwardRef(function PrismicLink< externalComponent, children, ...restProps - } = props; + } = props if (DEV) { if (field) { @@ -129,12 +129,12 @@ export const PrismicLink = forwardRef(function PrismicLink< console.error( `[PrismicLink] This "field" prop value caused an error to be thrown.\n`, field, - ); + ) throw new Error( `[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg( "missing-link-properties", )}`, - ); + ) } else if ( ("text" in field ? Object.keys(field).length > 2 : Object.keys(field).length > 1) && !("url" in field || "uid" in field || "id" in field) @@ -144,7 +144,7 @@ export const PrismicLink = forwardRef(function PrismicLink< "missing-link-properties", )}`, field, - ); + ) } } else if (doc) { if (!("url" in doc || "id" in doc)) { @@ -153,7 +153,7 @@ export const PrismicLink = forwardRef(function PrismicLink< "missing-link-properties", )}`, doc, - ); + ) } } } @@ -165,36 +165,36 @@ export const PrismicLink = forwardRef(function PrismicLink< } = asLinkAttrs(field ?? doc, { linkResolver, rel: typeof restProps.rel === "function" ? restProps.rel : undefined, - }); + }) - let rel: string | undefined = computedRel; + let rel: string | undefined = computedRel if ("rel" in restProps && typeof restProps.rel !== "function") { - rel = restProps.rel; + rel = restProps.rel } - const href = ("href" in restProps ? restProps.href : computedHref) || ""; + const href = ("href" in restProps ? restProps.href : computedHref) || "" - const InternalComponent = (internalComponent || defaultComponent) as ComponentType; - const ExternalComponent = (externalComponent || defaultComponent) as ComponentType; + const InternalComponent = (internalComponent || defaultComponent) as ComponentType + const ExternalComponent = (externalComponent || defaultComponent) as ComponentType const Component = href ? isInternalURL(href) ? InternalComponent : ExternalComponent - : InternalComponent; + : InternalComponent return ( {"children" in props ? children : field?.text} - ); + ) }) as < InternalComponentProps = ComponentProps, ExternalComponentProps = ComponentProps, >( props: PrismicLinkProps & { - ref?: ForwardedRef; + ref?: ForwardedRef }, -) => ReactNode; +) => ReactNode /** * Determines if a URL is internal or external. @@ -204,8 +204,8 @@ export const PrismicLink = forwardRef(function PrismicLink< */ // TODO: This does not detect all relative URLs as internal such as `about` or `./about`. This function assumes relative URLs start with a "/" or "#"`. export function isInternalURL(url: string): boolean { - const isInternal = /^(\/(?!\/)|#)/.test(url); - const isSpecialLink = !isInternal && !/^https?:\/\//.test(url); + const isInternal = /^(\/(?!\/)|#)/.test(url) + const isSpecialLink = !isInternal && !/^https?:\/\//.test(url) - return isInternal && !isSpecialLink; + return isInternal && !isSpecialLink } diff --git a/src/PrismicRichText.tsx b/src/PrismicRichText.tsx index c28e4e9..18f3796 100644 --- a/src/PrismicRichText.tsx +++ b/src/PrismicRichText.tsx @@ -3,15 +3,15 @@ import { type LinkResolverFunction, type RichTextField, type RTAnyNode, -} from "@prismicio/client"; +} from "@prismicio/client" import { composeSerializers, serialize, wrapMapSerializer, type RichTextFunctionSerializer, type RichTextMapSerializer, -} from "@prismicio/client/richtext"; -import { DEV } from "esm-env"; +} from "@prismicio/client/richtext" +import { DEV } from "esm-env" import { cloneElement, type ComponentType, @@ -19,10 +19,10 @@ import { Fragment, isValidElement, type ReactNode, -} from "react"; +} from "react" -import { devMsg } from "./lib/devMsg.js"; -import { type LinkProps, PrismicLink } from "./PrismicLink.js"; +import { devMsg } from "./lib/devMsg.js" +import { type LinkProps, PrismicLink } from "./PrismicLink.js" /** * A function mapping rich text block types to React Components. It is used to render rich text @@ -30,22 +30,22 @@ import { type LinkProps, PrismicLink } from "./PrismicLink.js"; * * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text} */ -export type JSXFunctionSerializer = RichTextFunctionSerializer; +export type JSXFunctionSerializer = RichTextFunctionSerializer /** * A map of rich text block types to React Components. It is used to render rich text fields. * * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text} */ -export type RichTextComponents = RichTextMapSerializer; +export type RichTextComponents = RichTextMapSerializer /** @deprecated Use `RichTextComponents` instead. */ -export type JSXMapSerializer = RichTextComponents; +export type JSXMapSerializer = RichTextComponents /** Props for ``. */ export type PrismicRichTextProps = { /** The Prismic rich text field to render. */ - field: RichTextField | null | undefined; + field: RichTextField | null | undefined /** * The link resolver used to resolve links. @@ -55,7 +55,7 @@ export type PrismicRichTextProps = { * resolver does not need to be provided. * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes} */ - linkResolver?: LinkResolverFunction; + linkResolver?: LinkResolverFunction /** * A map or function that maps a rich text block to a React component. @@ -85,40 +85,40 @@ export type PrismicRichTextProps = { * }; * ``` */ - components?: RichTextComponents | JSXFunctionSerializer; + components?: RichTextComponents | JSXFunctionSerializer /** * The React component rendered for links when the URL is internal. * * @defaultValue `` */ - internalLinkComponent?: ComponentType; + internalLinkComponent?: ComponentType /** * The React component rendered for links when the URL is external. * * @defaultValue `` */ - externalLinkComponent?: ComponentType; + externalLinkComponent?: ComponentType /** * The value to be rendered when the field is empty. If a fallback is not given, `null` will be * rendered. */ - fallback?: ReactNode; -}; + fallback?: ReactNode +} type CreateDefaultSerializerArgs = { - linkResolver: LinkResolverFunction | undefined; - internalLinkComponent?: ComponentType; - externalLinkComponent?: ComponentType; -}; + linkResolver: LinkResolverFunction | undefined + internalLinkComponent?: ComponentType + externalLinkComponent?: ComponentType +} const getDir = (node: RTAnyNode): "rtl" | undefined => { if ("direction" in node && node.direction === "rtl") { - return "rtl"; + return "rtl" } -}; +} const createDefaultSerializer = (args: CreateDefaultSerializerArgs): JSXFunctionSerializer => wrapMapSerializer({ @@ -179,7 +179,7 @@ const createDefaultSerializer = (args: CreateDefaultSerializerArgs): JSXFunction alt={node.alt ?? undefined} data-copyright={node.copyright ? node.copyright : undefined} /> - ); + ) return (

@@ -196,7 +196,7 @@ const createDefaultSerializer = (args: CreateDefaultSerializerArgs): JSXFunction img )}

- ); + ) }, embed: ({ node, key }) => (
), span: ({ text, key }) => { - const result: ReactNode[] = []; + const result: ReactNode[] = [] - let i = 0; + let i = 0 for (const line of text.split("\n")) { if (i > 0) { - result.push(
); + result.push(
) } - result.push({line}); + result.push({line}) - i++; + i++ } - return {result}; + return {result} }, - }); + }) /** * Renders content from a Prismic rich text field as React components. * * @example - * ```tsx + * ;```tsx * ; * ``` * @@ -260,7 +260,7 @@ export const PrismicRichText: FC = (props) => { externalLinkComponent, internalLinkComponent, ...restProps - } = props; + } = props if (DEV) { if ("className" in restProps) { @@ -269,12 +269,12 @@ export const PrismicRichText: FC = (props) => { "classname-is-not-a-valid-prop", )}.`, field, - ); + ) } } if (!isFilled.richText(field)) { - return fallback != null ? <>{fallback} : null; + return fallback != null ? <>{fallback} : null } const serializer = composeSerializers( @@ -284,24 +284,24 @@ export const PrismicRichText: FC = (props) => { internalLinkComponent, externalLinkComponent, }), - ); + ) // The serializer is wrapped in a higher-order function that // automatically applies a key to React Elements if one is not already // given. const serialized = serialize(field, (type, node, text, children, key) => { - const result = serializer(type, node, text, children, key); + const result = serializer(type, node, text, children, key) if (isValidElement(result) && result.key == null) { - return cloneElement(result, { key }); + return cloneElement(result, { key }) } else { - return result; + return result } - }); + }) if (!serialized) { - return fallback != null ? <>{fallback} : null; + return fallback != null ? <>{fallback} : null } - return <>{serialized}; -}; + return <>{serialized} +} diff --git a/src/PrismicTable.tsx b/src/PrismicTable.tsx index 362b0db..ff7bf34 100644 --- a/src/PrismicTable.tsx +++ b/src/PrismicTable.tsx @@ -7,22 +7,22 @@ import { type TableFieldBodyRow, type TableFieldHeaderCell, type TableFieldDataCell, -} from "@prismicio/client"; -import type { ComponentType, FC, ReactNode } from "react"; +} from "@prismicio/client" +import type { ComponentType, FC, ReactNode } from "react" -import { type JSXMapSerializer, PrismicRichText } from "./PrismicRichText.js"; +import { type JSXMapSerializer, PrismicRichText } from "./PrismicRichText.js" type TableComponents = { - table?: ComponentType<{ table: TableField<"filled">; children: ReactNode }>; - thead?: ComponentType<{ head: TableFieldHead; children: ReactNode }>; - tbody?: ComponentType<{ body: TableFieldBody; children: ReactNode }>; + table?: ComponentType<{ table: TableField<"filled">; children: ReactNode }> + thead?: ComponentType<{ head: TableFieldHead; children: ReactNode }> + tbody?: ComponentType<{ body: TableFieldBody; children: ReactNode }> tr?: ComponentType<{ - row: TableFieldHeadRow | TableFieldBodyRow; - children: ReactNode; - }>; - th?: ComponentType<{ cell: TableFieldHeaderCell; children: ReactNode }>; - td?: ComponentType<{ cell: TableFieldDataCell; children: ReactNode }>; -}; + row: TableFieldHeadRow | TableFieldBodyRow + children: ReactNode + }> + th?: ComponentType<{ cell: TableFieldHeaderCell; children: ReactNode }> + td?: ComponentType<{ cell: TableFieldDataCell; children: ReactNode }> +} const defaultComponents: Required = { table: ({ children }) => {children}
, @@ -31,12 +31,12 @@ const defaultComponents: Required = { tr: ({ children }) => {children}, th: ({ children }) => {children}, td: ({ children }) => {children}, -}; +} /** Props for ``. */ export type PrismicTableProps = { /** The Prismic table field to render. */ - field: TableField; + field: TableField /** * An object that maps a table block to a React component. @@ -51,33 +51,33 @@ export type PrismicTableProps = { * } * ``` */ - components?: JSXMapSerializer & TableComponents; + components?: JSXMapSerializer & TableComponents /** * The value to be rendered when the field is empty. If a fallback is not given, `null` will be * rendered. */ - fallback?: ReactNode; -}; + fallback?: ReactNode +} /** * Renders content from a Prismic table field as React components. * * @example - * ```tsx + * ;```tsx * ; * ``` * * @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table} */ export const PrismicTable: FC = (props) => { - const { field, components, fallback = null } = props; + const { field, components, fallback = null } = props if (!isFilled.table(field)) { - return fallback; + return fallback } - const { table: Table, thead: Thead, tbody: Tbody } = { ...defaultComponents, ...components }; + const { table: Table, thead: Thead, tbody: Tbody } = { ...defaultComponents, ...components } return ( @@ -94,18 +94,18 @@ export const PrismicTable: FC = (props) => { ))}
- ); -}; + ) +} type TableRowProps = { - row: TableFieldHeadRow | TableFieldBodyRow; - components?: JSXMapSerializer & TableComponents; -}; + row: TableFieldHeadRow | TableFieldBodyRow + components?: JSXMapSerializer & TableComponents +} function TableRow(props: TableRowProps) { - const { row, components } = props; + const { row, components } = props - const { tr: Tr, th: Th, td: Td } = { ...defaultComponents, ...components }; + const { tr: Tr, th: Th, td: Td } = { ...defaultComponents, ...components } return ( @@ -121,5 +121,5 @@ function TableRow(props: TableRowProps) { ), )} - ); + ) } diff --git a/src/PrismicText.tsx b/src/PrismicText.tsx index 38000f9..dfcd2c7 100644 --- a/src/PrismicText.tsx +++ b/src/PrismicText.tsx @@ -1,36 +1,36 @@ -import { asText, isFilled, type RichTextField } from "@prismicio/client"; -import { DEV } from "esm-env"; -import type { FC } from "react"; +import { asText, isFilled, type RichTextField } from "@prismicio/client" +import { DEV } from "esm-env" +import type { FC } from "react" -import { devMsg } from "./lib/devMsg.js"; +import { devMsg } from "./lib/devMsg.js" /** Props for ``. */ export type PrismicTextProps = { /** The Prismic rich text field to render. */ - field: RichTextField | null | undefined; + field: RichTextField | null | undefined /** * The string rendered when the field is empty. If a fallback is not given, `null` will be * rendered. */ - fallback?: string; + fallback?: string /** The separator used between blocks. Defaults to `\n`. */ - separator?: string; -}; + separator?: string +} /** * Renders content from a Prismic rich text field as plain text (no HTML). * * @example - * ```tsx + * ;```tsx * ; * ``` * * @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text} */ export const PrismicText: FC = (props) => { - const { field, fallback, separator } = props; + const { field, fallback, separator } = props if (DEV) { if ("className" in props) { @@ -39,7 +39,7 @@ export const PrismicText: FC = (props) => { "classname-is-not-a-valid-prop", )}.`, props.field, - ); + ) } } @@ -50,15 +50,15 @@ export const PrismicText: FC = (props) => { "prismictext-works-only-with-rich-text-and-title-fields", )}`, props.field, - ); + ) } - return null; + return null } if (!isFilled.richText(field)) { - return fallback != null ? <>{fallback} : null; + return fallback != null ? <>{fallback} : null } - return <>{asText(field, { separator })}; -}; + return <>{asText(field, { separator })} +} diff --git a/src/PrismicToolbar.tsx b/src/PrismicToolbar.tsx index a0d8312..2ce8542 100644 --- a/src/PrismicToolbar.tsx +++ b/src/PrismicToolbar.tsx @@ -1,7 +1,7 @@ -"use client"; +"use client" -import { getToolbarSrc } from "@prismicio/client"; -import { type FC, useEffect, useRef } from "react"; +import { getToolbarSrc } from "@prismicio/client" +import { type FC, useEffect, useRef } from "react" /** Props for ``. */ export type PrismicToolbarProps = { @@ -9,7 +9,7 @@ export type PrismicToolbarProps = { * The name of the Prismic repository. For example, `"my-repo"` if the repository URL is * `my-repo.prismic.io`. */ - repositoryName: string; + repositoryName: string /** * Called when the Prismic toolbar triggers a preview update. This happens when the previewed @@ -19,7 +19,7 @@ export type PrismicToolbarProps = { * * The default page reload behavior can be cancelled with `event.preventDefault()`. */ - onPreviewUpdate?: (event: CustomEvent<{ ref: string }>) => void; + onPreviewUpdate?: (event: CustomEvent<{ ref: string }>) => void /** * Called when the Prismic toolbar triggers a preview end. This happens when a preview session is @@ -27,67 +27,67 @@ export type PrismicToolbarProps = { * * The default page reload behavior can be cancelled with `event.preventDefault()`. */ - onPreviewEnd?: (event: CustomEvent) => void; -}; + onPreviewEnd?: (event: CustomEvent) => void +} /** * Renders the Prismic Toolbar script to support draft previews. * * @example - * ```tsx + * ;```tsx * ; * ``` * * @see Learn how to set up preview functionality and the toolbar's role in preview sessions: {@link https://prismic.io/docs/previews} */ export const PrismicToolbar: FC = (props) => { - const { repositoryName, onPreviewUpdate, onPreviewEnd } = props; + const { repositoryName, onPreviewUpdate, onPreviewEnd } = props - const src = getToolbarSrc(repositoryName); + const src = getToolbarSrc(repositoryName) - const onPreviewUpdateRef = useRef(onPreviewUpdate); - onPreviewUpdateRef.current = onPreviewUpdate; + const onPreviewUpdateRef = useRef(onPreviewUpdate) + onPreviewUpdateRef.current = onPreviewUpdate - const onPreviewEndRef = useRef(onPreviewEnd); - onPreviewEndRef.current = onPreviewEnd; + const onPreviewEndRef = useRef(onPreviewEnd) + onPreviewEndRef.current = onPreviewEnd useEffect(() => { - const existingScript = document.querySelector(`script[src="${src}"]`); + const existingScript = document.querySelector(`script[src="${src}"]`) if (!existingScript) { - const script = document.createElement("script"); - script.src = src; - script.defer = true; + const script = document.createElement("script") + script.src = src + script.defer = true // Used to distinguish the toolbar element from other elements. - script.dataset.prismicToolbar = ""; - script.dataset.repositoryName = repositoryName; + script.dataset.prismicToolbar = "" + script.dataset.repositoryName = repositoryName // Disable Happy DOM `