sanity-plugin-utils 1.4.0 → 1.5.0
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/README.md +48 -18
- package/lib/index.d.ts +12 -0
- package/lib/index.esm.js +661 -4
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +661 -2
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Table.tsx +2 -1
- package/src/hooks/useImageUrlBuilder.tsx +13 -0
- package/src/hooks/useImageUrlBuilderImage.tsx +18 -0
- package/src/index.ts +2 -0
package/README.md
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
> This is a **Sanity Studio v3** plugin.
|
|
2
|
-
|
|
3
|
-
## Installation
|
|
4
|
-
|
|
5
|
-
```sh
|
|
6
|
-
npm install sanity-plugin-utils
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
> This is exclusively a **Sanity Studio v3** plugin.
|
|
10
|
-
|
|
11
1
|
# sanity-plugin-utils
|
|
12
2
|
|
|
3
|
+
Handy hooks and clever components for Sanity Studio v3.
|
|
4
|
+
|
|
13
5
|
## Installation
|
|
14
6
|
|
|
15
7
|
```
|
|
@@ -24,19 +16,17 @@ yarn add sanity-plugin-utils
|
|
|
24
16
|
|
|
25
17
|
## Usage
|
|
26
18
|
|
|
27
|
-
Handy hooks and clever components for Sanity Studio v3
|
|
28
|
-
|
|
29
19
|
### `useListeningQuery()`
|
|
30
20
|
|
|
31
21
|
Sanity's real-time APIs power excellent editorial experiences. Your plugins should respond to other users collaborating on documents in real time. This hook is a convenient way to perform a GROQ query that responds to changes, along with built-in `loading` and `error` states.
|
|
32
22
|
|
|
33
23
|
The `data` variable will be constantly updated as changes are made to the data returned by your query. You can also pass in initial data so that it is set in the first render.
|
|
34
24
|
|
|
35
|
-
```
|
|
25
|
+
```tsx
|
|
36
26
|
import {useListeningQuery} from 'sanity-plugin-utils'
|
|
37
27
|
|
|
38
28
|
export default function DocumentList() {
|
|
39
|
-
const {data, loading, error} = useListeningQuery(`*[_type == $type]`, {
|
|
29
|
+
const {data, loading, error} = useListeningQuery<SanityDocument[]>(`*[_type == $type]`, {
|
|
40
30
|
params: {type: 'pet'},
|
|
41
31
|
initialValue: [],
|
|
42
32
|
})
|
|
@@ -65,7 +55,7 @@ export default function DocumentList() {
|
|
|
65
55
|
|
|
66
56
|
Hook for getting extended details on all Users in the project. Such as name.
|
|
67
57
|
|
|
68
|
-
```
|
|
58
|
+
```tsx
|
|
69
59
|
import {useProjectUsers} from 'sanity-plugin-utils'
|
|
70
60
|
|
|
71
61
|
export default function DocumentList() {
|
|
@@ -103,11 +93,51 @@ export default function SidePetOpener(pet: SanityDocument) {
|
|
|
103
93
|
}
|
|
104
94
|
```
|
|
105
95
|
|
|
96
|
+
### useImageUrlBuilder()
|
|
97
|
+
|
|
98
|
+
Returns an [image URL builder](https://www.sanity.io/docs/image-url) configured with the current workspace's Project ID and Dataset.
|
|
99
|
+
|
|
100
|
+
Useful if you have many images in the one component.
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
import {useImageUrlBuilder} from 'sanity-plugin-utils'
|
|
104
|
+
|
|
105
|
+
export default function PetPics(pet: SanityDocument) {
|
|
106
|
+
const builder = useImageUrlBuilder({apiVersion: `2023-01-01`})
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<ul>
|
|
110
|
+
{pet.pics.map((pic) => (
|
|
111
|
+
<li key={pic._key}>
|
|
112
|
+
<img src={builder.source(pic).width(200).height(200).url()} alt={pic.altText} />
|
|
113
|
+
</li>
|
|
114
|
+
))}
|
|
115
|
+
</ul>
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### useImageUrlBuilderImage()
|
|
121
|
+
|
|
122
|
+
As above, but pre-configured with an image source.
|
|
123
|
+
|
|
124
|
+
Useful if you only have one image in your component.
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
import {useImageUrlBuilderImage} from 'sanity-plugin-utils'
|
|
128
|
+
|
|
129
|
+
export default function PetPic(pet: SanityDocument) {
|
|
130
|
+
const image = useImageUrlBuilderImage(pet.image, {apiVersion: `2023-01-01`})
|
|
131
|
+
|
|
132
|
+
return <img src={image.width(200).height(200).url()} alt={pet.name} />
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
106
136
|
### Feedback
|
|
107
137
|
|
|
108
138
|
Component for consistently displaying feedback in a card with a title, text and an icon.
|
|
109
139
|
|
|
110
|
-
```
|
|
140
|
+
```tsx
|
|
111
141
|
import {Feedback, useListeningQuery} from 'sanity-plugin-utils'
|
|
112
142
|
|
|
113
143
|
export default function DocumentList() {
|
|
@@ -135,7 +165,7 @@ export default function DocumentList() {
|
|
|
135
165
|
|
|
136
166
|
These components are all `@sanity/ui` `Card`'s but with their HTML DOM elements and CSS updated to output and behave like tables.
|
|
137
167
|
|
|
138
|
-
```
|
|
168
|
+
```tsx
|
|
139
169
|
import {Table, Row, Cell} from 'sanity-plugin-utils'
|
|
140
170
|
|
|
141
171
|
export default function Report(documents) {
|
|
@@ -172,7 +202,7 @@ export default function Report(documents) {
|
|
|
172
202
|
|
|
173
203
|
A Menu component for searching and interacting with users. Requires Users to be passed into the component.
|
|
174
204
|
|
|
175
|
-
```
|
|
205
|
+
```tsx
|
|
176
206
|
import {UserSelectMenu} from 'sanity-plugin-utils'
|
|
177
207
|
|
|
178
208
|
export default function Report() {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import {CardProps} from '@sanity/ui'
|
|
2
2
|
import {CardTone} from '@sanity/ui'
|
|
3
|
+
import type {ImageUrlBuilder} from 'sanity'
|
|
3
4
|
import {PropsWithChildren} from 'react'
|
|
4
5
|
import {default as React_2} from 'react'
|
|
6
|
+
import type {SanityImageSource} from '@sanity/asset-utils'
|
|
7
|
+
import type {SourceClientOptions} from 'sanity'
|
|
5
8
|
|
|
6
9
|
export declare function Cell(props: TableCellProps): JSX.Element
|
|
7
10
|
|
|
@@ -71,6 +74,15 @@ declare type TableProps = PropsWithChildren<CardProps>
|
|
|
71
74
|
|
|
72
75
|
declare type TableRowProps = PropsWithChildren<CardProps>
|
|
73
76
|
|
|
77
|
+
export declare function useImageUrlBuilder(
|
|
78
|
+
clientOptions?: SourceClientOptions
|
|
79
|
+
): ImageUrlBuilder | null
|
|
80
|
+
|
|
81
|
+
export declare function useImageUrlBuilderImage(
|
|
82
|
+
source: SanityImageSource,
|
|
83
|
+
clientOptions?: SourceClientOptions
|
|
84
|
+
): ImageUrlBuilder | null
|
|
85
|
+
|
|
74
86
|
export declare function useListeningQuery<V>(
|
|
75
87
|
query:
|
|
76
88
|
| string
|