@sanity/hierarchical-document-list 2.1.0 → 2.1.2
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.mts +240 -0
- package/dist/index.js +6308 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6433 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +13 -11
- package/dist/index.esm.js +0 -151
- package/dist/index.esm.js.map +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import {ArraySchemaType} from 'sanity'
|
|
2
|
+
import type {ConfigContext} from 'sanity'
|
|
3
|
+
import {DocumentDefinition} from 'sanity'
|
|
4
|
+
import {Plugin as Plugin_2} from 'sanity'
|
|
5
|
+
import {PreviewConfig} from 'sanity'
|
|
6
|
+
import * as React_2 from 'react'
|
|
7
|
+
import {StructureBuilder} from 'sanity/desk'
|
|
8
|
+
|
|
9
|
+
export declare function createDeskHierarchy(props: TreeProps): any
|
|
10
|
+
|
|
11
|
+
export declare function createHierarchicalSchemas(options: SchemaOptions): (
|
|
12
|
+
| {
|
|
13
|
+
name: string
|
|
14
|
+
title: string
|
|
15
|
+
type: string
|
|
16
|
+
fields: (
|
|
17
|
+
| {
|
|
18
|
+
name: string
|
|
19
|
+
type: string
|
|
20
|
+
}
|
|
21
|
+
| {
|
|
22
|
+
name: string
|
|
23
|
+
type: string
|
|
24
|
+
title: string
|
|
25
|
+
fields: (
|
|
26
|
+
| {
|
|
27
|
+
name: string
|
|
28
|
+
type: string
|
|
29
|
+
weak?: undefined
|
|
30
|
+
to?: undefined
|
|
31
|
+
options?: undefined
|
|
32
|
+
}
|
|
33
|
+
| {
|
|
34
|
+
name: string
|
|
35
|
+
type: string
|
|
36
|
+
weak: boolean
|
|
37
|
+
to: {
|
|
38
|
+
type: string
|
|
39
|
+
}[]
|
|
40
|
+
options:
|
|
41
|
+
| {
|
|
42
|
+
filter?: string | undefined
|
|
43
|
+
filterParams?: Record<string, unknown> | undefined
|
|
44
|
+
}
|
|
45
|
+
| undefined
|
|
46
|
+
}
|
|
47
|
+
)[]
|
|
48
|
+
}
|
|
49
|
+
)[]
|
|
50
|
+
}
|
|
51
|
+
| {
|
|
52
|
+
name: string
|
|
53
|
+
title: string
|
|
54
|
+
type: string
|
|
55
|
+
of: (
|
|
56
|
+
| {
|
|
57
|
+
name: string
|
|
58
|
+
title: string
|
|
59
|
+
type: string
|
|
60
|
+
fields: (
|
|
61
|
+
| {
|
|
62
|
+
name: string
|
|
63
|
+
type: string
|
|
64
|
+
}
|
|
65
|
+
| {
|
|
66
|
+
name: string
|
|
67
|
+
type: string
|
|
68
|
+
title: string
|
|
69
|
+
fields: (
|
|
70
|
+
| {
|
|
71
|
+
name: string
|
|
72
|
+
type: string
|
|
73
|
+
weak?: undefined
|
|
74
|
+
to?: undefined
|
|
75
|
+
options?: undefined
|
|
76
|
+
}
|
|
77
|
+
| {
|
|
78
|
+
name: string
|
|
79
|
+
type: string
|
|
80
|
+
weak: boolean
|
|
81
|
+
to: {
|
|
82
|
+
type: string
|
|
83
|
+
}[]
|
|
84
|
+
options:
|
|
85
|
+
| {
|
|
86
|
+
filter?: string | undefined
|
|
87
|
+
filterParams?: Record<string, unknown> | undefined
|
|
88
|
+
}
|
|
89
|
+
| undefined
|
|
90
|
+
}
|
|
91
|
+
)[]
|
|
92
|
+
}
|
|
93
|
+
)[]
|
|
94
|
+
}
|
|
95
|
+
| {
|
|
96
|
+
type: string
|
|
97
|
+
}
|
|
98
|
+
)[]
|
|
99
|
+
}
|
|
100
|
+
| {
|
|
101
|
+
name: string | undefined
|
|
102
|
+
title: string
|
|
103
|
+
type: string
|
|
104
|
+
liveEdit: boolean
|
|
105
|
+
fields: (Omit<ArraySchemaType<unknown>, 'type' | 'of' | 'jsonType'> & {
|
|
106
|
+
type: string
|
|
107
|
+
inputComponent: React_2.FC<any>
|
|
108
|
+
of?: any[] | undefined
|
|
109
|
+
})[]
|
|
110
|
+
preview: {
|
|
111
|
+
select: {
|
|
112
|
+
id: string
|
|
113
|
+
tree: string
|
|
114
|
+
}
|
|
115
|
+
prepare({id, tree}: {id: string; tree: unknown[]}): Record<string, string>
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
)[]
|
|
119
|
+
|
|
120
|
+
export declare function flatDataToTree(data: StoredTreeItem[]): TreeItemWithChildren[]
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Usage in `sanity.config.ts` (or .js)
|
|
124
|
+
*
|
|
125
|
+
* ```ts
|
|
126
|
+
* import {defineConfig} from 'sanity'
|
|
127
|
+
* import {hierarchicalDocumentList} from '@sanity/hierarchical-document-list'
|
|
128
|
+
*
|
|
129
|
+
* export default defineConfig({
|
|
130
|
+
* // ...
|
|
131
|
+
* plugins: [hierarchicalDocumentList()],
|
|
132
|
+
* })
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare const hierarchicalDocumentList: Plugin_2<void>
|
|
136
|
+
|
|
137
|
+
export declare const hierarchyTree: {
|
|
138
|
+
type: 'document'
|
|
139
|
+
name: 'hierarchy.tree'
|
|
140
|
+
} & Omit<DocumentDefinition, 'preview'> & {
|
|
141
|
+
preview?: PreviewConfig<Record<string, string>, Record<never, any>> | undefined
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
declare const INTERNAL_NODE_TYPE: string
|
|
145
|
+
|
|
146
|
+
declare const INTERNAL_NODE_VALUE_TYPE: string
|
|
147
|
+
|
|
148
|
+
declare interface SanityReference {
|
|
149
|
+
_type: 'reference'
|
|
150
|
+
_ref: string
|
|
151
|
+
_weak?: boolean
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
declare type SchemaOptions = Omit<TreeDeskStructureProps, 'documentId' | 'maxDepth'>
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Objects saved to tree documents in Sanity's Content Lake
|
|
158
|
+
*/
|
|
159
|
+
declare interface StoredTreeItem {
|
|
160
|
+
_key: string
|
|
161
|
+
_type: typeof INTERNAL_NODE_TYPE | string
|
|
162
|
+
value?: {
|
|
163
|
+
_type: typeof INTERNAL_NODE_VALUE_TYPE | string
|
|
164
|
+
reference?: SanityReference
|
|
165
|
+
docType?: string
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* _key of parent node
|
|
169
|
+
*/
|
|
170
|
+
parent?: string | null
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
declare interface TreeDeskStructureProps extends TreeInputOptions {
|
|
174
|
+
/**
|
|
175
|
+
* _id of the document that will hold the tree data.
|
|
176
|
+
*/
|
|
177
|
+
documentId: string
|
|
178
|
+
/**
|
|
179
|
+
* (Optional)
|
|
180
|
+
* Key for the field representing the hierarchical tree inside the document.
|
|
181
|
+
* `tree` by default.
|
|
182
|
+
*/
|
|
183
|
+
fieldKeyInDocument?: string
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
declare interface TreeInputOptions {
|
|
187
|
+
/**
|
|
188
|
+
* What document types this hierarchy can refer to.
|
|
189
|
+
* Similar to the `to` property of the [reference field](https://www.sanity.io/docs/reference-type).
|
|
190
|
+
*/
|
|
191
|
+
referenceTo: string[]
|
|
192
|
+
/**
|
|
193
|
+
* Used to provide fine-grained filtering for documents.
|
|
194
|
+
*/
|
|
195
|
+
referenceOptions?: {
|
|
196
|
+
/**
|
|
197
|
+
* Static filter to apply to tree document queries.
|
|
198
|
+
*/
|
|
199
|
+
filter?: string
|
|
200
|
+
/**
|
|
201
|
+
* Parameters / variables to pass to the GROQ query ran to fetch documents.
|
|
202
|
+
*/
|
|
203
|
+
filterParams?: Record<string, unknown>
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* How deep should editors be allowed to nest items.
|
|
207
|
+
*/
|
|
208
|
+
maxDepth?: number
|
|
209
|
+
/**
|
|
210
|
+
* Schema type for your hierarchical documents.
|
|
211
|
+
* Refer to documentation on how to provide these schemas in your studio.
|
|
212
|
+
*
|
|
213
|
+
* Defautlt: 'hierarchy.tree' - this schema is bundled with the plugin
|
|
214
|
+
*/
|
|
215
|
+
documentType?: string
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
declare interface TreeItemWithChildren extends StoredTreeItem {
|
|
219
|
+
children?: TreeItemWithChildren[]
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export declare interface TreeProps extends TreeDeskStructureProps {
|
|
223
|
+
/**
|
|
224
|
+
* Visible title above the tree.
|
|
225
|
+
* Also used as the label in the desk list item.
|
|
226
|
+
*/
|
|
227
|
+
title: string
|
|
228
|
+
/**
|
|
229
|
+
* Optional icon for rendering the item in the desk structure.
|
|
230
|
+
*/
|
|
231
|
+
icon?: any
|
|
232
|
+
context?: ConfigContext | any
|
|
233
|
+
S?: StructureBuilder | any
|
|
234
|
+
/**
|
|
235
|
+
* Restrict document types that can be created.
|
|
236
|
+
*/
|
|
237
|
+
creatableTypes?: string[]
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export {}
|