next-sanity 13.3.0 → 13.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +125 -2
- package/dist/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,133 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "./isCorsOriginError.js";
|
|
2
2
|
import { createClient, unstable__adapter, unstable__environment } from "@sanity/client";
|
|
3
|
-
import { ClientReturnStega, StegaBranded, StegaCleaned, StegaString, stegaBrand, stegaClean } from "@sanity/client/stega";
|
|
3
|
+
import { ClientReturnStega, StegaBranded, StegaBranded as StegaBranded$1, StegaCleaned, StegaCleaned as StegaCleaned$1, StegaString, stegaBrand, stegaClean } from "@sanity/client/stega";
|
|
4
4
|
import { CreateDataAttribute, CreateDataAttributeProps, createDataAttribute } from "@sanity/visual-editing/create-data-attribute";
|
|
5
|
+
import { InferComponents as InferComponents$1, InferStrictComponents as InferStrictComponents$1, InferValue as InferValue$1 } from "@portabletext/react";
|
|
5
6
|
import groq, { defineQuery } from "groq";
|
|
6
7
|
export * from "@sanity/client";
|
|
7
8
|
export * from "@portabletext/react";
|
|
9
|
+
/**
|
|
10
|
+
* Widens a query result type to cover both sides of stega branding:
|
|
11
|
+
* the clean TypeGen shape (`sanityFetch` with `stega: false`) and the
|
|
12
|
+
* stega-branded shape (`sanityFetch` when stega may be enabled).
|
|
13
|
+
*
|
|
14
|
+
* This is what lets the `Infer*` types accept `data` from any `sanityFetch`
|
|
15
|
+
* call without requiring a wholesale `stegaClean()`, which would strip the
|
|
16
|
+
* hidden characters Visual Editing needs to make each paragraph clickable.
|
|
17
|
+
*/
|
|
18
|
+
type StegaAware<T> = StegaCleaned$1<T> | StegaBranded$1<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Infer the Portable Text array value type from
|
|
21
|
+
* {@link https://www.sanity.io/docs/apis-and-sdks/sanity-typegen | Sanity TypeGen}
|
|
22
|
+
* generated types.
|
|
23
|
+
*
|
|
24
|
+
* Stega-aware version of `InferValue` from `@portabletext/react`: the inferred
|
|
25
|
+
* value type accepts both clean query results (`sanityFetch` with
|
|
26
|
+
* `stega: false`) and stega-branded results (`sanityFetch` when stega may be
|
|
27
|
+
* enabled). Don't clean the value with `stegaClean()` before rendering it,
|
|
28
|
+
* that strips the hidden characters `@sanity/visual-editing` uses to make each
|
|
29
|
+
* paragraph clickable. Instead, use `stegaClean` on individual strings at the
|
|
30
|
+
* point where they're compared against literals.
|
|
31
|
+
*
|
|
32
|
+
* Useful when building a re-usable wrapper component that only takes `value`
|
|
33
|
+
* as an input prop and sets up `components` internally. Pass a TypeGen-
|
|
34
|
+
* generated query result type that contains Portable Text fields - such as
|
|
35
|
+
* an individual query result like `PostQueryResult`, or the `SanityQueries`
|
|
36
|
+
* interface from `@sanity/client` - and `InferValue<T>` returns an array type
|
|
37
|
+
* containing every Portable Text item shape it can find.
|
|
38
|
+
*
|
|
39
|
+
* Always feed `InferValue<T>` query result types, not Sanity schema types.
|
|
40
|
+
* Schema types describe how content is stored, which can differ from how it
|
|
41
|
+
* is queried (e.g. references resolved with `->`).
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* // Re-usable component typed against every registered query. Relies on
|
|
46
|
+
* // `overloadClientMethods` being enabled in `sanity.cli.ts#typegen` (the default).
|
|
47
|
+
* import {
|
|
48
|
+
* PortableText,
|
|
49
|
+
* type InferStrictComponents,
|
|
50
|
+
* type InferValue,
|
|
51
|
+
* type SanityQueries,
|
|
52
|
+
* } from 'next-sanity'
|
|
53
|
+
*
|
|
54
|
+
* type PortableTextValue = InferValue<SanityQueries[keyof SanityQueries]>
|
|
55
|
+
*
|
|
56
|
+
* export function CustomPortableText(props: {value: PortableTextValue}) {
|
|
57
|
+
* const components = {
|
|
58
|
+
* types: {
|
|
59
|
+
* // custom types are autocompleted and fully typed
|
|
60
|
+
* },
|
|
61
|
+
* } satisfies InferStrictComponents<PortableTextValue>
|
|
62
|
+
*
|
|
63
|
+
* return <PortableText components={components} value={props.value} />
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* // Rendering `sanityFetch` results, with or without stega, type-checks:
|
|
70
|
+
* const {data} = await sanityFetch({query: postQuery, params})
|
|
71
|
+
* return Array.isArray(data?.content) && <CustomPortableText value={data.content} />
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
type InferValue<T> = InferValue$1<StegaAware<T>>;
|
|
75
|
+
/**
|
|
76
|
+
* Infer Portable Text components from a value type. This matches the inference
|
|
77
|
+
* behavior of the `components` prop on `<PortableText>`.
|
|
78
|
+
*
|
|
79
|
+
* Stega-aware version of `InferComponents` from `@portabletext/react`: the
|
|
80
|
+
* inferred component props cover both clean query results (`sanityFetch` with
|
|
81
|
+
* `stega: false`) and stega-branded results (`sanityFetch` when stega may be
|
|
82
|
+
* enabled), so the same `components` object can render both. Strings that may
|
|
83
|
+
* carry stega payloads stay branded inside component props: render them as-is
|
|
84
|
+
* to keep Visual Editing working, and use `stegaClean` on the individual
|
|
85
|
+
* values you compare against string literals.
|
|
86
|
+
*
|
|
87
|
+
* This is useful when working with
|
|
88
|
+
* {@link https://www.sanity.io/docs/apis-and-sdks/sanity-typegen | Sanity TypeGen},
|
|
89
|
+
* where `defineQuery()` and `sanityFetch()` can infer the shape of Portable
|
|
90
|
+
* Text fields.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```tsx
|
|
94
|
+
* import {PortableText, type InferComponents, defineQuery} from 'next-sanity'
|
|
95
|
+
* import {sanityFetch} from '@/sanity/lib/live'
|
|
96
|
+
*
|
|
97
|
+
* export default async function Page({slug}: {slug: string}) {
|
|
98
|
+
* const query = defineQuery(`*[_type == "post" && slug.current == $slug][0]{title,content}`)
|
|
99
|
+
* const {data} = await sanityFetch({query, params: {slug}})
|
|
100
|
+
* const components = {
|
|
101
|
+
* block: {
|
|
102
|
+
* // custom types are autocompleted and fully typed
|
|
103
|
+
* },
|
|
104
|
+
* } satisfies InferComponents<typeof data.content>
|
|
105
|
+
*
|
|
106
|
+
* return (
|
|
107
|
+
* <>
|
|
108
|
+
* ...
|
|
109
|
+
* {Array.isArray(data?.content) && <PortableText components={components} value={data.content} />}
|
|
110
|
+
* </>
|
|
111
|
+
* )
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
type InferComponents<T> = InferComponents$1<StegaAware<T>>;
|
|
116
|
+
/**
|
|
117
|
+
* Infer Portable Text components from a value type, requiring handlers for all
|
|
118
|
+
* custom object types and disallowing extra custom object type handlers.
|
|
119
|
+
*
|
|
120
|
+
* Stega-aware version of `InferStrictComponents` from `@portabletext/react`,
|
|
121
|
+
* see {@link InferComponents} for how stega branding is handled.
|
|
122
|
+
*
|
|
123
|
+
* This is used the same way as {@link InferComponents}, but serves a different
|
|
124
|
+
* purpose: `InferComponents` is forgiving and mirrors the inline
|
|
125
|
+
* `<PortableText components={...} />` experience, allowing custom handlers to
|
|
126
|
+
* be omitted and allowing handlers for types that do not exist in, or could not
|
|
127
|
+
* be inferred from, the value type. `InferStrictComponents` is strict: it
|
|
128
|
+
* requires inferred custom handlers and rejects unknown ones.
|
|
129
|
+
*/
|
|
130
|
+
type InferStrictComponents<T> = InferStrictComponents$1<StegaAware<T>>;
|
|
8
131
|
/**
|
|
9
132
|
* API version required for editing variants queries.
|
|
10
133
|
* Uses the `X` alias while variants are in beta; will move to a dated version when stable.
|
|
@@ -12,5 +135,5 @@ export * from "@portabletext/react";
|
|
|
12
135
|
* @public
|
|
13
136
|
*/
|
|
14
137
|
declare const variantsApiVersion = "X";
|
|
15
|
-
export { type ClientReturnStega, type CreateDataAttribute, type CreateDataAttributeProps, type StegaBranded, type StegaCleaned, type StegaString, createClient, createDataAttribute, defineQuery, groq, isCorsOriginError, stegaBrand, stegaClean, unstable__adapter, unstable__environment, variantsApiVersion };
|
|
138
|
+
export { type ClientReturnStega, type CreateDataAttribute, type CreateDataAttributeProps, type InferComponents, type InferStrictComponents, type InferValue, type StegaBranded, type StegaCleaned, type StegaString, createClient, createDataAttribute, defineQuery, groq, isCorsOriginError, stegaBrand, stegaClean, unstable__adapter, unstable__environment, variantsApiVersion };
|
|
16
139
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/variants/constants.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/portable-text.ts","../src/variants/constants.ts"],"mappings":";;;;;;;;;;;;;;;;;KAgBK,WAAW,KAAK,eAAa,KAAK,eAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAyDxC,WAAW,KAAK,aAAuB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA0ClD,gBAAgB,KAAK,kBAA4B,WAAW;;;;;;;;;;;;;;;KAgB5D,sBAAsB,KAAK,wBAAkC,WAAW;;;;;;;cC7HvE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-sanity",
|
|
3
|
-
"version": "13.3.
|
|
3
|
+
"version": "13.3.1",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"live",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@portabletext/react": "^7.0.1",
|
|
62
|
-
"@sanity/client": "^7.26.
|
|
62
|
+
"@sanity/client": "^7.26.1",
|
|
63
63
|
"@sanity/generate-help-url": "^4.0.0",
|
|
64
64
|
"@sanity/preview-url-secret": "^4.1.2",
|
|
65
65
|
"@sanity/visual-editing": "^5.7.3",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"vitest-package-exports": "^1.2.0"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
|
-
"@sanity/client": "^7.26.
|
|
94
|
+
"@sanity/client": "^7.26.1",
|
|
95
95
|
"next": "^16.0.0-0",
|
|
96
96
|
"react": "^19.2.3",
|
|
97
97
|
"react-dom": "^19.2.3",
|