From bdc244e50a35fffc342968811621fac6720ec461 Mon Sep 17 00:00:00 2001 From: Xavier Rutayisire Date: Wed, 28 Aug 2024 20:24:10 +0200 Subject: [PATCH 01/11] feat: support link text --- package-lock.json | 215 ++++------------------------------ package.json | 8 +- src/PrismicNextLink.tsx | 13 +- test/PrismicNextLink.test.tsx | 32 +++++ 4 files changed, 75 insertions(+), 193 deletions(-) diff --git a/package-lock.json b/package-lock.json index be37b54..3286eff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,8 +14,8 @@ "negotiator": "^0.6.3" }, "devDependencies": { - "@prismicio/client": "^7.2.0", - "@prismicio/mock": "^0.3.1", + "@prismicio/client": "7.9.0-alpha.2", + "@prismicio/mock": "0.3.8-alpha.0", "@size-limit/preset-small-lib": "^9.0.0", "@types/negotiator": "^0.6.3", "@types/react-test-renderer": "^18.0.2", @@ -1219,52 +1219,42 @@ } }, "node_modules/@prismicio/client": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@prismicio/client/-/client-7.2.0.tgz", - "integrity": "sha512-bfbs2ZMLd3ba7Bp1qI4qAz+13FIWE/JDT9+h+3hL/MVpK4iDpjz3vmOlYJs25myhryU9HP8Og7qKoaeE9hPzmA==", + "version": "7.9.0-alpha.2", + "resolved": "https://registry.npmjs.org/@prismicio/client/-/client-7.9.0-alpha.2.tgz", + "integrity": "sha512-Y4Ti7XoJ57Rk2AkhI0UBxg3f2+wGr4ZwGfr82bFbmY9CCAUXQ+aN8cl3nUSCUafhRyJTcqWSty52D8RKvseY4g==", "dev": true, + "license": "Apache-2.0", "dependencies": { - "@prismicio/richtext": "^2.1.5", - "imgix-url-builder": "^0.0.4" + "imgix-url-builder": "^0.0.5" }, "engines": { "node": ">=14.15.0" } }, - "node_modules/@prismicio/mock": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@prismicio/mock/-/mock-0.3.1.tgz", - "integrity": "sha512-xwwnQ6kKfHMypjao2Q0sdUFuQsdDlif8qmgKoqYv8KlmNxKHzurgfGh9Zl1wHF1ldEJ8C3NVpI4AqdaHjyCHSA==", + "node_modules/@prismicio/client/node_modules/imgix-url-builder": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/imgix-url-builder/-/imgix-url-builder-0.0.5.tgz", + "integrity": "sha512-dCx3UlXghtsjySoqVCcHQHRikqDummwQEfKlxBUK/wrMzd+1ox/XX+zhqVuXKMVuZvCc84pVLEJyntQB0OOi/w==", "dev": true, - "dependencies": { - "change-case": "^4.1.2" - }, + "license": "Apache-2.0", "engines": { "node": ">=12.7.0" - }, - "peerDependencies": { - "@prismicio/client": "^7" } }, - "node_modules/@prismicio/richtext": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/@prismicio/richtext/-/richtext-2.1.5.tgz", - "integrity": "sha512-Sf6iCsciPmfK3uQeFmeY9RTRSuhrCVzyU39OkiJ1VJn8O0531pKapGoWS+5WGxouJtE5+jGqV8L+L2mKP7NkXQ==", + "node_modules/@prismicio/mock": { + "version": "0.3.8-alpha.0", + "resolved": "https://registry.npmjs.org/@prismicio/mock/-/mock-0.3.8-alpha.0.tgz", + "integrity": "sha512-w8yGiL6cmapktjeb47IS4zdqFArfo+cC81ahdoDBShOjREqQjzTHECihMudcnePav5Ok11IUHXB0F5Il3aaRjA==", "dev": true, + "license": "Apache-2.0", "dependencies": { - "@prismicio/types": "^0.2.7" + "change-case": "^5.4.4" }, "engines": { - "node": ">=12.7.0" - } - }, - "node_modules/@prismicio/types": { - "version": "0.2.8", - "resolved": "https://registry.npmjs.org/@prismicio/types/-/types-0.2.8.tgz", - "integrity": "sha512-EmuYYil56U+UtEifMD/9TmLzpWliV+X6kypwPq47GNXmIXyFK1JsP3z872fUziXwoBjd2YILj28DNdYXlLOpXg==", - "dev": true, - "engines": { - "node": ">=12.7.0" + "node": ">=18" + }, + "peerDependencies": { + "@prismicio/client": "^7" } }, "node_modules/@rollup/plugin-typescript": { @@ -2267,16 +2257,6 @@ "node": ">=6" } }, - "node_modules/camel-case": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/camel-case/-/camel-case-4.1.2.tgz", - "integrity": "sha512-gxGWBrTT1JuMx6R+o5PTXMmUnhnVzLQ9SNutD4YqKtI6ap897t3tKECYla6gCWEkplXnlNybEkZg9GEGxKFCgw==", - "dev": true, - "dependencies": { - "pascal-case": "^3.1.2", - "tslib": "^2.0.3" - } - }, "node_modules/camelcase": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", @@ -2323,17 +2303,6 @@ } ] }, - "node_modules/capital-case": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/capital-case/-/capital-case-1.0.4.tgz", - "integrity": "sha512-ds37W8CytHgwnhGGTi88pcPyR15qoNkOpYwmMMfnWqqWgESapLqvDx6huFjQ5vqWSn2Z06173XNA7LtMOeUh1A==", - "dev": true, - "dependencies": { - "no-case": "^3.0.4", - "tslib": "^2.0.3", - "upper-case-first": "^2.0.2" - } - }, "node_modules/chai": { "version": "4.3.8", "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.8.tgz", @@ -2367,24 +2336,11 @@ } }, "node_modules/change-case": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/change-case/-/change-case-4.1.2.tgz", - "integrity": "sha512-bSxY2ws9OtviILG1EiY5K7NNxkqg/JnRnFxLtKQ96JaviiIxi7djMrSd0ECT9AC+lttClmYwKw53BWpOMblo7A==", + "version": "5.4.4", + "resolved": "https://registry.npmjs.org/change-case/-/change-case-5.4.4.tgz", + "integrity": "sha512-HRQyTk2/YPEkt9TnUPbOpr64Uw3KOicFWPVBb+xiHvd6eBx/qPr9xqfBFDT8P2vWsvvz4jbEkfDe71W3VyNu2w==", "dev": true, - "dependencies": { - "camel-case": "^4.1.2", - "capital-case": "^1.0.4", - "constant-case": "^3.0.4", - "dot-case": "^3.0.4", - "header-case": "^2.0.4", - "no-case": "^3.0.4", - "param-case": "^3.0.4", - "pascal-case": "^3.1.2", - "path-case": "^3.0.4", - "sentence-case": "^3.0.4", - "snake-case": "^3.0.4", - "tslib": "^2.0.3" - } + "license": "MIT" }, "node_modules/character-entities": { "version": "2.0.2", @@ -2516,17 +2472,6 @@ "typedarray": "^0.0.6" } }, - "node_modules/constant-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/constant-case/-/constant-case-3.0.4.tgz", - "integrity": "sha512-I2hSBi7Vvs7BEuJDr5dDHfzb/Ruj3FyvFyh7KLilAjNQw3Be+xgqUBA2W6scVEcL0hL1dwPRtIqEPVUCKkSsyQ==", - "dev": true, - "dependencies": { - "no-case": "^3.0.4", - "tslib": "^2.0.3", - "upper-case": "^2.0.2" - } - }, "node_modules/conventional-changelog": { "version": "3.1.25", "resolved": "https://registry.npmjs.org/conventional-changelog/-/conventional-changelog-3.1.25.tgz", @@ -3087,16 +3032,6 @@ "node": ">=6.0.0" } }, - "node_modules/dot-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/dot-case/-/dot-case-3.0.4.tgz", - "integrity": "sha512-Kv5nKlh6yRrdrGvxeJ2e5y2eRUpkUosIW4A2AS38zwSz27zu7ufDwQPi5Jhs3XAlGNetl3bmnGhQsMtkKJnj3w==", - "dev": true, - "dependencies": { - "no-case": "^3.0.4", - "tslib": "^2.0.3" - } - }, "node_modules/dot-prop": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz", @@ -4457,16 +4392,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/header-case": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/header-case/-/header-case-2.0.4.tgz", - "integrity": "sha512-H/vuk5TEEVZwrR0lp2zed9OCo1uAILMlx0JEMgC26rzyJJ3N1v6XkwHHXJQdR2doSjcGPM6OKPYoJgf0plJ11Q==", - "dev": true, - "dependencies": { - "capital-case": "^1.0.4", - "tslib": "^2.0.3" - } - }, "node_modules/hosted-git-info": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-4.1.0.tgz", @@ -5491,15 +5416,6 @@ "get-func-name": "^2.0.0" } }, - "node_modules/lower-case": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-2.0.2.tgz", - "integrity": "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==", - "dev": true, - "dependencies": { - "tslib": "^2.0.3" - } - }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -6449,16 +6365,6 @@ } } }, - "node_modules/no-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz", - "integrity": "sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==", - "dev": true, - "dependencies": { - "lower-case": "^2.0.2", - "tslib": "^2.0.3" - } - }, "node_modules/node-domexception": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", @@ -6757,16 +6663,6 @@ "node": ">=6" } }, - "node_modules/param-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/param-case/-/param-case-3.0.4.tgz", - "integrity": "sha512-RXlj7zCYokReqWpOPH9oYivUzLYZ5vAPIfEmCTNViosC78F8F0H9y7T7gG2M39ymgutxF5gcFEsyZQSph9Bp3A==", - "dev": true, - "dependencies": { - "dot-case": "^3.0.4", - "tslib": "^2.0.3" - } - }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -6792,26 +6688,6 @@ "node": ">=4" } }, - "node_modules/pascal-case": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/pascal-case/-/pascal-case-3.1.2.tgz", - "integrity": "sha512-uWlGT3YSnK9x3BQJaOdcZwrnV6hPpd8jFH1/ucpiLRPh/2zCVJKS19E4GvYHvaCcACn3foXZ0cLB9Wrx1KGe5g==", - "dev": true, - "dependencies": { - "no-case": "^3.0.4", - "tslib": "^2.0.3" - } - }, - "node_modules/path-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/path-case/-/path-case-3.0.4.tgz", - "integrity": "sha512-qO4qCFjXqVTrcbPt/hQfhTQ+VhFsqNKOPtytgNKkKxSoEp3XPUQ8ObFuePylOIok5gjn69ry8XiULxCwot3Wfg==", - "dev": true, - "dependencies": { - "dot-case": "^3.0.4", - "tslib": "^2.0.3" - } - }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -7745,17 +7621,6 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, - "node_modules/sentence-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/sentence-case/-/sentence-case-3.0.4.tgz", - "integrity": "sha512-8LS0JInaQMCRoQ7YUytAo/xUu5W2XnQxV2HI/6uM6U7CITS1RqPElr30V6uIqyMKM9lJGRVFy5/4CuzcixNYSg==", - "dev": true, - "dependencies": { - "no-case": "^3.0.4", - "tslib": "^2.0.3", - "upper-case-first": "^2.0.2" - } - }, "node_modules/set-function-name": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/set-function-name/-/set-function-name-2.0.1.tgz", @@ -7846,16 +7711,6 @@ "node": ">=8" } }, - "node_modules/snake-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/snake-case/-/snake-case-3.0.4.tgz", - "integrity": "sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg==", - "dev": true, - "dependencies": { - "dot-case": "^3.0.4", - "tslib": "^2.0.3" - } - }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -8561,24 +8416,6 @@ "browserslist": ">= 4.21.0" } }, - "node_modules/upper-case": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/upper-case/-/upper-case-2.0.2.tgz", - "integrity": "sha512-KgdgDGJt2TpuwBUIjgG6lzw2GWFRCW9Qkfkiv0DxqHHLYJHmtmdUIKcZd8rHgFSjopVTlw6ggzCm1b8MFQwikg==", - "dev": true, - "dependencies": { - "tslib": "^2.0.3" - } - }, - "node_modules/upper-case-first": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/upper-case-first/-/upper-case-first-2.0.2.tgz", - "integrity": "sha512-514ppYHBaKwfJRK/pNC6c/OxfGa0obSnAl106u97Ed0I625Nin96KAjttZF6ZL3e1XLtphxnqrOi9iWgm+u+bg==", - "dev": true, - "dependencies": { - "tslib": "^2.0.3" - } - }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/package.json b/package.json index 9efe8bc..b096b47 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,8 @@ "negotiator": "^0.6.3" }, "devDependencies": { - "@prismicio/client": "^7.2.0", - "@prismicio/mock": "^0.3.1", + "@prismicio/client": "7.9.0-alpha.2", + "@prismicio/mock": "0.3.8-alpha.0", "@size-limit/preset-small-lib": "^9.0.0", "@types/negotiator": "^0.6.3", "@types/react-test-renderer": "^18.0.2", @@ -99,5 +99,9 @@ }, "publishConfig": { "access": "public" + }, + "overrides": { + "@prismicio/client": "7.9.0-alpha.2", + "@prismicio/mock": "0.3.8-alpha.0" } } diff --git a/src/PrismicNextLink.tsx b/src/PrismicNextLink.tsx index 9780c1b..e21dfce 100644 --- a/src/PrismicNextLink.tsx +++ b/src/PrismicNextLink.tsx @@ -32,7 +32,7 @@ export const PrismicNextLink = React.forwardRef< HTMLAnchorElement, PrismicNextLinkProps >(function PrismicNextLink( - { field, document, linkResolver, ...restProps }, + { field, document, linkResolver, children, ...restProps }, ref, ): JSX.Element | null { const { @@ -51,5 +51,14 @@ export const PrismicNextLink = React.forwardRef< rel = restProps.rel; } - return ; + let text: string | undefined; + if (field && "text" in field) { + text = field.text; + } + + return ( + + {children || text} + + ); }); diff --git a/test/PrismicNextLink.test.tsx b/test/PrismicNextLink.test.tsx index 371d88d..1e97427 100644 --- a/test/PrismicNextLink.test.tsx +++ b/test/PrismicNextLink.test.tsx @@ -237,3 +237,35 @@ it("forwards ref", (ctx) => { expect(ref).toHaveBeenCalledWith({ tagName: "a" }); }); + +it("renders a next/link with text and without children", (ctx) => { + const field = ctx.mock.value.link({ + type: "Web", + model: { type: "Link", config: { text: { type: "Text" } } }, + }); + + const actual = renderJSON(); + const expected = renderJSON( + + {field.text} + , + ); + + expectLinkToEqual(actual, expected); +}); + +it("renders a next/link with text and children", (ctx) => { + const field = ctx.mock.value.link({ type: "Web" }); + const children = ctx.mock.value.keyText(); + + const actual = renderJSON( + {children}, + ); + const expected = renderJSON( + + {children} + , + ); + + expectLinkToEqual(actual, expected); +}); From 6d83ba292d3c19c142d9799298173f9624bae92f Mon Sep 17 00:00:00 2001 From: Xavier Rutayisire Date: Thu, 29 Aug 2024 10:12:44 +0200 Subject: [PATCH 02/11] review fixes --- src/PrismicNextLink.tsx | 6 +----- test/PrismicNextLink.test.tsx | 13 ++++++------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/PrismicNextLink.tsx b/src/PrismicNextLink.tsx index e21dfce..f1df463 100644 --- a/src/PrismicNextLink.tsx +++ b/src/PrismicNextLink.tsx @@ -45,17 +45,13 @@ export const PrismicNextLink = React.forwardRef< }); const href = ("href" in restProps ? restProps.href : computedHref) || ""; + const text = prismic.isFilled.link(field) ? field.text : undefined; let rel = computedRel; if ("rel" in restProps && typeof restProps.rel !== "function") { rel = restProps.rel; } - let text: string | undefined; - if (field && "text" in field) { - text = field.text; - } - return ( {children || text} diff --git a/test/PrismicNextLink.test.tsx b/test/PrismicNextLink.test.tsx index 1e97427..4ee7915 100644 --- a/test/PrismicNextLink.test.tsx +++ b/test/PrismicNextLink.test.tsx @@ -238,11 +238,9 @@ it("forwards ref", (ctx) => { expect(ref).toHaveBeenCalledWith({ tagName: "a" }); }); -it("renders a next/link with text and without children", (ctx) => { - const field = ctx.mock.value.link({ - type: "Web", - model: { type: "Link", config: { text: { type: "Text" } } }, - }); +it("renders a next/link with text", (ctx) => { + const model = ctx.mock.model.link({ text: true }); + const field = ctx.mock.value.link({ type: "Web", model }); const actual = renderJSON(); const expected = renderJSON( @@ -254,8 +252,9 @@ it("renders a next/link with text and without children", (ctx) => { expectLinkToEqual(actual, expected); }); -it("renders a next/link with text and children", (ctx) => { - const field = ctx.mock.value.link({ type: "Web" }); +it("renders a next/link with the given children, overriding the link's text", (ctx) => { + const model = ctx.mock.model.link({ text: true }); + const field = ctx.mock.value.link({ type: "Web", model }); const children = ctx.mock.value.keyText(); const actual = renderJSON( From decc0d3330515ee6da4bc6635325efede828f9c4 Mon Sep 17 00:00:00 2001 From: Xavier Rutayisire Date: Thu, 29 Aug 2024 10:27:27 +0200 Subject: [PATCH 03/11] prevent random for target blank --- test/PrismicNextLink.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/PrismicNextLink.test.tsx b/test/PrismicNextLink.test.tsx index 4ee7915..005c826 100644 --- a/test/PrismicNextLink.test.tsx +++ b/test/PrismicNextLink.test.tsx @@ -239,7 +239,7 @@ it("forwards ref", (ctx) => { }); it("renders a next/link with text", (ctx) => { - const model = ctx.mock.model.link({ text: true }); + const model = ctx.mock.model.link({ text: true, allowTargetBlank: false }); const field = ctx.mock.value.link({ type: "Web", model }); const actual = renderJSON(); @@ -253,7 +253,7 @@ it("renders a next/link with text", (ctx) => { }); it("renders a next/link with the given children, overriding the link's text", (ctx) => { - const model = ctx.mock.model.link({ text: true }); + const model = ctx.mock.model.link({ text: true, allowTargetBlank: false }); const field = ctx.mock.value.link({ type: "Web", model }); const children = ctx.mock.value.keyText(); From 489428a6967773bb024049e3f4b412dd605a72fd Mon Sep 17 00:00:00 2001 From: Xavier Rutayisire Date: Fri, 30 Aug 2024 14:02:45 +0200 Subject: [PATCH 04/11] review fixes --- src/PrismicNextLink.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PrismicNextLink.tsx b/src/PrismicNextLink.tsx index f1df463..54fc506 100644 --- a/src/PrismicNextLink.tsx +++ b/src/PrismicNextLink.tsx @@ -54,7 +54,7 @@ export const PrismicNextLink = React.forwardRef< return ( - {children || text} + {"children" in restProps ? children : text} ); }); From 205fb87fcaeba6c225f2cb8be1804c88f6593ed3 Mon Sep 17 00:00:00 2001 From: Xavier Rutayisire Date: Fri, 30 Aug 2024 14:04:47 +0200 Subject: [PATCH 05/11] review fixes --- src/PrismicNextLink.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/PrismicNextLink.tsx b/src/PrismicNextLink.tsx index 54fc506..8158b61 100644 --- a/src/PrismicNextLink.tsx +++ b/src/PrismicNextLink.tsx @@ -31,10 +31,8 @@ export type PrismicNextLinkProps = Omit< export const PrismicNextLink = React.forwardRef< HTMLAnchorElement, PrismicNextLinkProps ->(function PrismicNextLink( - { field, document, linkResolver, children, ...restProps }, - ref, -): JSX.Element | null { +>(function PrismicNextLink(props, ref): JSX.Element | null { + const { field, document, linkResolver, children, ...restProps } = props; const { href: computedHref, rel: computedRel, @@ -54,7 +52,7 @@ export const PrismicNextLink = React.forwardRef< return ( - {"children" in restProps ? children : text} + {"children" in props ? children : text} ); }); From 7074630dd6ae5a983b168de3621d678cf9cca045 Mon Sep 17 00:00:00 2001 From: Xavier Rutayisire Date: Sun, 8 Sep 2024 00:19:53 +0200 Subject: [PATCH 06/11] support empty link with text --- src/PrismicNextLink.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/PrismicNextLink.tsx b/src/PrismicNextLink.tsx index 8158b61..fb95733 100644 --- a/src/PrismicNextLink.tsx +++ b/src/PrismicNextLink.tsx @@ -43,7 +43,6 @@ export const PrismicNextLink = React.forwardRef< }); const href = ("href" in restProps ? restProps.href : computedHref) || ""; - const text = prismic.isFilled.link(field) ? field.text : undefined; let rel = computedRel; if ("rel" in restProps && typeof restProps.rel !== "function") { @@ -52,7 +51,7 @@ export const PrismicNextLink = React.forwardRef< return ( - {"children" in props ? children : text} + {"children" in props ? children : field?.text} ); }); From 28a78db9d8a23132dd00557a1e68f3ef18fc8c1c Mon Sep 17 00:00:00 2001 From: Xavier Rutayisire Date: Tue, 10 Sep 2024 23:42:05 +0200 Subject: [PATCH 07/11] update prismic-client & prismic-mock --- package-lock.json | 16 ++++++++-------- package.json | 8 ++++---- test/PrismicNextLink.test.tsx | 10 ++++++++-- test/createLocaleRedirect.test.ts | 16 ++++++++-------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/package-lock.json b/package-lock.json index 40ce627..34c12bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,8 +14,8 @@ "negotiator": "^0.6.3" }, "devDependencies": { - "@prismicio/client": "7.9.0-alpha.2", - "@prismicio/mock": "0.3.8-alpha.0", + "@prismicio/client": "7.9.0-alpha.3", + "@prismicio/mock": "0.3.8-alpha.2", "@size-limit/preset-small-lib": "^9.0.0", "@types/negotiator": "^0.6.3", "@types/react-test-renderer": "^18.0.2", @@ -1219,9 +1219,9 @@ } }, "node_modules/@prismicio/client": { - "version": "7.9.0-alpha.2", - "resolved": "https://registry.npmjs.org/@prismicio/client/-/client-7.9.0-alpha.2.tgz", - "integrity": "sha512-Y4Ti7XoJ57Rk2AkhI0UBxg3f2+wGr4ZwGfr82bFbmY9CCAUXQ+aN8cl3nUSCUafhRyJTcqWSty52D8RKvseY4g==", + "version": "7.9.0-alpha.3", + "resolved": "https://registry.npmjs.org/@prismicio/client/-/client-7.9.0-alpha.3.tgz", + "integrity": "sha512-8u+ot1xTt/wH8BSlnYJ20+fuZRo4TIf4PnkNFMLkgYmNbUTNnsNFsPr0GJC/G9nTZFnn5jV0oTPz48C/ITVnnA==", "dev": true, "license": "Apache-2.0", "dependencies": { @@ -1242,9 +1242,9 @@ } }, "node_modules/@prismicio/mock": { - "version": "0.3.8-alpha.0", - "resolved": "https://registry.npmjs.org/@prismicio/mock/-/mock-0.3.8-alpha.0.tgz", - "integrity": "sha512-w8yGiL6cmapktjeb47IS4zdqFArfo+cC81ahdoDBShOjREqQjzTHECihMudcnePav5Ok11IUHXB0F5Il3aaRjA==", + "version": "0.3.8-alpha.2", + "resolved": "https://registry.npmjs.org/@prismicio/mock/-/mock-0.3.8-alpha.2.tgz", + "integrity": "sha512-LtLeIp88Y1vvQzyWCcK0k0aYdoexh7Yep31WeiUmZXnZ8p91sliw9HXZDEHqnKX2SjZx6sSv+P7oBVcq6IsH+g==", "dev": true, "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index c0c3c58..4309d8c 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,8 @@ "negotiator": "^0.6.3" }, "devDependencies": { - "@prismicio/client": "7.9.0-alpha.2", - "@prismicio/mock": "0.3.8-alpha.0", + "@prismicio/client": "7.9.0-alpha.3", + "@prismicio/mock": "0.3.8-alpha.2", "@size-limit/preset-small-lib": "^9.0.0", "@types/negotiator": "^0.6.3", "@types/react-test-renderer": "^18.0.2", @@ -101,7 +101,7 @@ "access": "public" }, "overrides": { - "@prismicio/client": "7.9.0-alpha.2", - "@prismicio/mock": "0.3.8-alpha.0" + "@prismicio/client": "7.9.0-alpha.3", + "@prismicio/mock": "0.3.8-alpha.2" } } diff --git a/test/PrismicNextLink.test.tsx b/test/PrismicNextLink.test.tsx index 005c826..9226b28 100644 --- a/test/PrismicNextLink.test.tsx +++ b/test/PrismicNextLink.test.tsx @@ -239,7 +239,10 @@ it("forwards ref", (ctx) => { }); it("renders a next/link with text", (ctx) => { - const model = ctx.mock.model.link({ text: true, allowTargetBlank: false }); + const model = ctx.mock.model.link({ + allowText: true, + allowTargetBlank: false, + }); const field = ctx.mock.value.link({ type: "Web", model }); const actual = renderJSON(); @@ -253,7 +256,10 @@ it("renders a next/link with text", (ctx) => { }); it("renders a next/link with the given children, overriding the link's text", (ctx) => { - const model = ctx.mock.model.link({ text: true, allowTargetBlank: false }); + const model = ctx.mock.model.link({ + allowText: true, + allowTargetBlank: false, + }); const field = ctx.mock.value.link({ type: "Web", model }); const children = ctx.mock.value.keyText(); diff --git a/test/createLocaleRedirect.test.ts b/test/createLocaleRedirect.test.ts index 789ac0e..9140ba2 100644 --- a/test/createLocaleRedirect.test.ts +++ b/test/createLocaleRedirect.test.ts @@ -49,7 +49,7 @@ it("creates a redirect with the request's preferred locale", async () => { mockGetRepository({ client, - languages: [{ id: "fr-fr", name: "French (France)" }], + languages: [{ id: "fr-fr", name: "French (France)", is_master: true }], }); const redirect = await createLocaleRedirect(config); @@ -74,8 +74,8 @@ it("returns undefined if the request already contains a locale", async () => { mockGetRepository({ client, languages: [ - { id: "fr-fr", name: "French (France)" }, - { id: "en-us", name: "English (US)" }, + { id: "fr-fr", name: "French (France)", is_master: false }, + { id: "en-us", name: "English (US)", is_master: true }, ], }); @@ -98,8 +98,8 @@ it("uses the default locale if the request's preferred language is unavailable", mockGetRepository({ client, languages: [ - { id: "en-us", name: "English (US)" }, - { id: "en-uk", name: "English (UK)" }, + { id: "en-us", name: "English (US)", is_master: true }, + { id: "en-uk", name: "English (UK)", is_master: false }, ], }); @@ -127,7 +127,7 @@ it("allows for custom locale codes", async () => { mockGetRepository({ client, - languages: [{ id: "fr-fr", name: "French (France)" }], + languages: [{ id: "fr-fr", name: "French (France)", is_master: true }], }); const redirect = await createLocaleRedirect(config); @@ -150,7 +150,7 @@ it("returns undefined when omitDefaultLocale is true and the preferred locale is mockGetRepository({ client, - languages: [{ id: "fr-fr", name: "French (France)" }], + languages: [{ id: "fr-fr", name: "French (France)", is_master: true }], }); const redirect = await createLocaleRedirect(config); @@ -171,7 +171,7 @@ it("uses the default locale when the accept-language header is not set", async ( mockGetRepository({ client, - languages: [{ id: "fr-fr", name: "French (France)" }], + languages: [{ id: "fr-fr", name: "French (France)", is_master: true }], }); const redirect = await createLocaleRedirect(config); From 11cc930c71ee441bee885b821309ca9ca2441f27 Mon Sep 17 00:00:00 2001 From: Xavier Rutayisire Date: Tue, 10 Sep 2024 23:42:55 +0200 Subject: [PATCH 08/11] chore(release): 1.7.0-alpha.0 --- CHANGELOG.md | 13 +++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be691fe..edbb890 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,19 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [1.7.0-alpha.0](https://github.com/prismicio/prismic-next/compare/v1.5.0...v1.7.0-alpha.0) (2024-09-10) + + +### Features + +* support link text ([bdc244e](https://github.com/prismicio/prismic-next/commit/bdc244e50a35fffc342968811621fac6720ec461)) +* Support Next 15 & React 19 ([864bfed](https://github.com/prismicio/prismic-next/commit/864bfedb14a31401ae6ce2e8799767d217e2562d)) + + +### Chore + +* **release:** 1.6.0 ([e97fcca](https://github.com/prismicio/prismic-next/commit/e97fcca55e599131d0945d90dd6bb3f8732092ca)) + ## [1.6.0](https://github.com/prismicio/prismic-next/compare/v1.5.0...v1.6.0) (2024-05-30) diff --git a/package-lock.json b/package-lock.json index 34c12bc..bb873a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@prismicio/next", - "version": "1.6.0", + "version": "1.7.0-alpha.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@prismicio/next", - "version": "1.6.0", + "version": "1.7.0-alpha.0", "license": "Apache-2.0", "dependencies": { "@formatjs/intl-localematcher": "^0.5.2", diff --git a/package.json b/package.json index 4309d8c..7023e0b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@prismicio/next", - "version": "1.6.0", + "version": "1.7.0-alpha.0", "description": "Helpers to integrate Prismic into Next.js apps", "keywords": [ "typescript", From 63c37dbe2500515a1b54d5ea49365c49b46da676 Mon Sep 17 00:00:00 2001 From: Xavier Rutayisire Date: Tue, 10 Sep 2024 23:53:30 +0200 Subject: [PATCH 09/11] update test --- test/PrismicNextLink.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/PrismicNextLink.test.tsx b/test/PrismicNextLink.test.tsx index 9226b28..890b471 100644 --- a/test/PrismicNextLink.test.tsx +++ b/test/PrismicNextLink.test.tsx @@ -243,7 +243,7 @@ it("renders a next/link with text", (ctx) => { allowText: true, allowTargetBlank: false, }); - const field = ctx.mock.value.link({ type: "Web", model }); + const field = ctx.mock.value.link({ type: "Web", model, withText: true }); const actual = renderJSON(); const expected = renderJSON( @@ -260,7 +260,7 @@ it("renders a next/link with the given children, overriding the link's text", (c allowText: true, allowTargetBlank: false, }); - const field = ctx.mock.value.link({ type: "Web", model }); + const field = ctx.mock.value.link({ type: "Web", model, withText: true }); const children = ctx.mock.value.keyText(); const actual = renderJSON( From 9e423c8de232e34d6491779bb16e1a9b4f38d5c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marti=CC=81n?= Date: Fri, 27 Sep 2024 12:58:53 +0200 Subject: [PATCH 10/11] Upgrade prismic deps --- package-lock.json | 16 ++++++++-------- package.json | 8 ++------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index bb873a2..b456d5e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,8 +14,8 @@ "negotiator": "^0.6.3" }, "devDependencies": { - "@prismicio/client": "7.9.0-alpha.3", - "@prismicio/mock": "0.3.8-alpha.2", + "@prismicio/client": "^7.11.0", + "@prismicio/mock": "^0.4.0", "@size-limit/preset-small-lib": "^9.0.0", "@types/negotiator": "^0.6.3", "@types/react-test-renderer": "^18.0.2", @@ -1219,9 +1219,9 @@ } }, "node_modules/@prismicio/client": { - "version": "7.9.0-alpha.3", - "resolved": "https://registry.npmjs.org/@prismicio/client/-/client-7.9.0-alpha.3.tgz", - "integrity": "sha512-8u+ot1xTt/wH8BSlnYJ20+fuZRo4TIf4PnkNFMLkgYmNbUTNnsNFsPr0GJC/G9nTZFnn5jV0oTPz48C/ITVnnA==", + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@prismicio/client/-/client-7.11.0.tgz", + "integrity": "sha512-b5FtER97eFHH435hP4sRchtPYvrwa8v2Ye5IH3MhMp/6aH6kRSrr9fDA4+wkqF/ZK9aiJwJRkjdddgkwDFu9Vg==", "dev": true, "license": "Apache-2.0", "dependencies": { @@ -1242,9 +1242,9 @@ } }, "node_modules/@prismicio/mock": { - "version": "0.3.8-alpha.2", - "resolved": "https://registry.npmjs.org/@prismicio/mock/-/mock-0.3.8-alpha.2.tgz", - "integrity": "sha512-LtLeIp88Y1vvQzyWCcK0k0aYdoexh7Yep31WeiUmZXnZ8p91sliw9HXZDEHqnKX2SjZx6sSv+P7oBVcq6IsH+g==", + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@prismicio/mock/-/mock-0.4.0.tgz", + "integrity": "sha512-CtTEbp/3NOdyP2StC8lGBAE4IwPJOegWEYKSEAQTjp+6BgcGcqUHr1iVBwKd3EFKVoBWA+8tJNP0m0/AFPOuNw==", "dev": true, "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index 7023e0b..cdd0709 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,8 @@ "negotiator": "^0.6.3" }, "devDependencies": { - "@prismicio/client": "7.9.0-alpha.3", - "@prismicio/mock": "0.3.8-alpha.2", + "@prismicio/client": "^7.11.0", + "@prismicio/mock": "^0.4.0", "@size-limit/preset-small-lib": "^9.0.0", "@types/negotiator": "^0.6.3", "@types/react-test-renderer": "^18.0.2", @@ -99,9 +99,5 @@ }, "publishConfig": { "access": "public" - }, - "overrides": { - "@prismicio/client": "7.9.0-alpha.3", - "@prismicio/mock": "0.3.8-alpha.2" } } From fc2581fff21244a0f86cc43c3771af272afd6a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marti=CC=81n?= Date: Fri, 27 Sep 2024 13:09:21 +0200 Subject: [PATCH 11/11] chore(release): 1.7.0 --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edbb890..8a76aa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [1.7.0](https://github.com/prismicio/prismic-next/compare/v1.7.0-alpha.0...v1.7.0) (2024-09-27) + ## [1.7.0-alpha.0](https://github.com/prismicio/prismic-next/compare/v1.5.0...v1.7.0-alpha.0) (2024-09-10) diff --git a/package-lock.json b/package-lock.json index b456d5e..b7b1296 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@prismicio/next", - "version": "1.7.0-alpha.0", + "version": "1.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@prismicio/next", - "version": "1.7.0-alpha.0", + "version": "1.7.0", "license": "Apache-2.0", "dependencies": { "@formatjs/intl-localematcher": "^0.5.2", diff --git a/package.json b/package.json index cdd0709..119c131 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@prismicio/next", - "version": "1.7.0-alpha.0", + "version": "1.7.0", "description": "Helpers to integrate Prismic into Next.js apps", "keywords": [ "typescript",