@sanity/hierarchical-document-list 2.1.3 → 3.0.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/LICENSE +1 -1
- package/README.md +30 -28
- package/dist/index.d.ts +170 -195
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +835 -6031
- package/dist/index.js.map +1 -1
- package/package.json +38 -77
- package/dist/index.d.mts +0 -240
- package/dist/index.mjs +0 -6433
- package/dist/index.mjs.map +0 -1
- package/sanity.json +0 -8
- package/src/TreeDeskStructure.tsx +0 -80
- package/src/TreeInputComponent.tsx +0 -41
- package/src/components/DeskWarning.tsx +0 -40
- package/src/components/DocumentInNode.tsx +0 -133
- package/src/components/DocumentPreviewStatus.tsx +0 -70
- package/src/components/NodeActions.tsx +0 -85
- package/src/components/NodeContentRenderer.tsx +0 -141
- package/src/components/PlaceholderDropzone.tsx +0 -45
- package/src/components/TreeEditor.tsx +0 -184
- package/src/components/TreeEditorErrorBoundary.tsx +0 -14
- package/src/components/TreeNodeRenderer.tsx +0 -37
- package/src/components/TreeNodeRendererScaffold.tsx +0 -193
- package/src/createDeskHierarchy.tsx +0 -110
- package/src/createHierarchicalSchemas.tsx +0 -151
- package/src/hooks/useAllItems.ts +0 -119
- package/src/hooks/useLocalTree.ts +0 -40
- package/src/hooks/useTreeOperations.ts +0 -25
- package/src/hooks/useTreeOperationsProvider.ts +0 -86
- package/src/index.ts +0 -25
- package/src/schemas/hierarchy.tree.ts +0 -19
- package/src/types.ts +0 -148
- package/src/utils/flatDataToTree.ts +0 -20
- package/src/utils/getAdjescentNodes.ts +0 -30
- package/src/utils/getCommonTreeProps.tsx +0 -28
- package/src/utils/getTreeHeight.ts +0 -8
- package/src/utils/gradientPatchAdapter.ts +0 -43
- package/src/utils/idUtils.ts +0 -7
- package/src/utils/injectNodeTypeInPatches.ts +0 -60
- package/src/utils/moveItemInArray.ts +0 -26
- package/src/utils/throwError.ts +0 -9
- package/src/utils/treeData.tsx +0 -119
- package/src/utils/treePatches.ts +0 -171
- package/v2-incompatible.js +0 -11
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -12,10 +12,8 @@ Plugin for visually organizing documents as hierarchies in the [Sanity studio](h
|
|
|
12
12
|
|
|
13
13
|
If you're looking for a way to order documents on a flat list, refer to [@sanity/orderable-document-list](https://github.com/sanity-io/orderable-document-list).
|
|
14
14
|
|
|
15
|
-
|
|
16
15
|
## Installation
|
|
17
16
|
|
|
18
|
-
|
|
19
17
|
```bash
|
|
20
18
|
# From the root of your sanity project
|
|
21
19
|
npm i @sanity/hierarchical-document-list
|
|
@@ -29,17 +27,16 @@ npm i @sanity/hierarchical-document-list
|
|
|
29
27
|
// sanity.config.js
|
|
30
28
|
import {defineConfig} from 'sanity'
|
|
31
29
|
import {hierarchicalDocumentList, hierarchyTree} from '@sanity/hierarchical-document-list'
|
|
32
|
-
|
|
30
|
+
|
|
33
31
|
export default defineConfig({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
// ...
|
|
33
|
+
plugins: [hierarchicalDocumentList()],
|
|
34
|
+
schema: {
|
|
37
35
|
types: [
|
|
38
36
|
//...,
|
|
39
|
-
hierarchyTree
|
|
40
|
-
]
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
hierarchyTree,
|
|
38
|
+
],
|
|
39
|
+
},
|
|
43
40
|
})
|
|
44
41
|
```
|
|
45
42
|
|
|
@@ -51,14 +48,19 @@ export default defineConfig({
|
|
|
51
48
|
// sanity.config.ts
|
|
52
49
|
import {defineConfig} from 'sanity'
|
|
53
50
|
import {deskTool} from 'sanity/desk'
|
|
54
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
createDeskHierarchy,
|
|
53
|
+
hierarchicalDocumentList,
|
|
54
|
+
hierarchyTree,
|
|
55
|
+
} from '@sanity/hierarchical-document-list'
|
|
55
56
|
|
|
56
57
|
export default defineConfig({
|
|
57
58
|
// ...
|
|
58
59
|
plugins: [
|
|
59
60
|
deskTool({
|
|
60
61
|
// NOTE: I'n V3 you MUST pass S and Context along to createDeskHierarchy as props
|
|
61
|
-
structure: (S, context) =>
|
|
62
|
+
structure: (S, context) =>
|
|
63
|
+
S.list()
|
|
62
64
|
.title('Content')
|
|
63
65
|
.items([
|
|
64
66
|
...S.documentTypeListItems(), // or whatever other structure you have
|
|
@@ -81,26 +83,26 @@ export default defineConfig({
|
|
|
81
83
|
referenceOptions: {
|
|
82
84
|
filter: 'status in $acceptedStatuses',
|
|
83
85
|
filterParams: {
|
|
84
|
-
acceptedStatuses: ['published', 'approved']
|
|
85
|
-
}
|
|
86
|
+
acceptedStatuses: ['published', 'approved'],
|
|
87
|
+
},
|
|
86
88
|
},
|
|
87
89
|
|
|
88
90
|
// ❓ Optional: limit the depth of your hierarachies
|
|
89
91
|
maxDepth: 3,
|
|
90
92
|
|
|
91
93
|
// ❓ Optional: subarray of referenceTo, when it should not be possible to create new types from all referenceTo types
|
|
92
|
-
creatableTypes: ['site.page']
|
|
93
|
-
})
|
|
94
|
-
])
|
|
94
|
+
creatableTypes: ['site.page'],
|
|
95
|
+
}),
|
|
96
|
+
]),
|
|
95
97
|
}),
|
|
96
|
-
hierarchicalDocumentList()
|
|
98
|
+
hierarchicalDocumentList(),
|
|
97
99
|
],
|
|
98
100
|
schema: {
|
|
99
101
|
types: [
|
|
100
102
|
//...,
|
|
101
|
-
hierarchyTree
|
|
102
|
-
]
|
|
103
|
-
}
|
|
103
|
+
hierarchyTree,
|
|
104
|
+
],
|
|
105
|
+
},
|
|
104
106
|
})
|
|
105
107
|
```
|
|
106
108
|
|
|
@@ -285,12 +287,12 @@ export const hierarchicalOptions = {
|
|
|
285
287
|
referenceOptions: {
|
|
286
288
|
filter: 'status in $acceptedStatuses',
|
|
287
289
|
filterParams: {
|
|
288
|
-
acceptedStatuses: ['published', 'approved']
|
|
289
|
-
}
|
|
290
|
+
acceptedStatuses: ['published', 'approved'],
|
|
291
|
+
},
|
|
290
292
|
},
|
|
291
293
|
|
|
292
294
|
// ❓ Optional: limit the depth of your hierarachies
|
|
293
|
-
maxDept: 3
|
|
295
|
+
maxDept: 3,
|
|
294
296
|
}
|
|
295
297
|
|
|
296
298
|
export default createHierarchicalSchemas(hierarchicalOptions)
|
|
@@ -307,8 +309,8 @@ export default createSchema({
|
|
|
307
309
|
name: 'default',
|
|
308
310
|
types: schemaTypes.concat([
|
|
309
311
|
// ...Other schemas
|
|
310
|
-
...hierarchicalSchemas // add all items in the array of hierarchical schemas
|
|
311
|
-
])
|
|
312
|
+
...hierarchicalSchemas, // add all items in the array of hierarchical schemas
|
|
313
|
+
]),
|
|
312
314
|
})
|
|
313
315
|
```
|
|
314
316
|
|
|
@@ -318,7 +320,7 @@ Then, in your desk structure where you added the hierarchical document(s), inclu
|
|
|
318
320
|
createDeskHierarchy({
|
|
319
321
|
// Include whatever values you defined in your schema in the step above
|
|
320
322
|
documentType: 'myCustomHierarchicalType', // the name of your document type
|
|
321
|
-
fieldKeyInDocument: 'customTreeDataKey' // the name of the hierarchical field
|
|
323
|
+
fieldKeyInDocument: 'customTreeDataKey', // the name of the hierarchical field
|
|
322
324
|
// ...
|
|
323
325
|
})
|
|
324
326
|
|
|
@@ -326,7 +328,7 @@ createDeskHierarchy({
|
|
|
326
328
|
import {hierarchicalOptions} from './hierarchicalSchemas'
|
|
327
329
|
|
|
328
330
|
createDeskHierarchy({
|
|
329
|
-
...hierarchicalOptions
|
|
331
|
+
...hierarchicalOptions,
|
|
330
332
|
// ...
|
|
331
333
|
})
|
|
332
334
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,194 +1,34 @@
|
|
|
1
|
-
import {ArraySchemaType} from
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
1
|
+
import { ArraySchemaType } from "sanity";
|
|
2
|
+
import { FC } from "react";
|
|
3
|
+
declare const INTERNAL_NODE_TYPE: string;
|
|
4
|
+
declare const INTERNAL_NODE_VALUE_TYPE: string;
|
|
5
|
+
interface SanityReference {
|
|
6
|
+
_type: 'reference';
|
|
7
|
+
_ref: string;
|
|
8
|
+
_weak?: boolean;
|
|
152
9
|
}
|
|
153
|
-
|
|
154
|
-
declare type SchemaOptions = Omit<TreeDeskStructureProps, 'documentId' | 'maxDepth'>
|
|
155
|
-
|
|
156
10
|
/**
|
|
157
11
|
* Objects saved to tree documents in Sanity's Content Lake
|
|
158
12
|
*/
|
|
159
|
-
|
|
160
|
-
_key: string
|
|
161
|
-
_type: typeof INTERNAL_NODE_TYPE
|
|
13
|
+
interface StoredTreeItem {
|
|
14
|
+
_key: string;
|
|
15
|
+
_type: typeof INTERNAL_NODE_TYPE;
|
|
162
16
|
value?: {
|
|
163
|
-
_type: typeof INTERNAL_NODE_VALUE_TYPE
|
|
164
|
-
reference?: SanityReference
|
|
165
|
-
docType?: string
|
|
166
|
-
}
|
|
17
|
+
_type: typeof INTERNAL_NODE_VALUE_TYPE;
|
|
18
|
+
reference?: SanityReference;
|
|
19
|
+
docType?: string;
|
|
20
|
+
};
|
|
167
21
|
/**
|
|
168
22
|
* _key of parent node
|
|
169
23
|
*/
|
|
170
|
-
parent?: string | null
|
|
24
|
+
parent?: string | null;
|
|
171
25
|
}
|
|
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 {
|
|
26
|
+
interface TreeInputOptions {
|
|
187
27
|
/**
|
|
188
28
|
* What document types this hierarchy can refer to.
|
|
189
29
|
* Similar to the `to` property of the [reference field](https://www.sanity.io/docs/reference-type).
|
|
190
30
|
*/
|
|
191
|
-
referenceTo: string[]
|
|
31
|
+
referenceTo: string[];
|
|
192
32
|
/**
|
|
193
33
|
* Used to provide fine-grained filtering for documents.
|
|
194
34
|
*/
|
|
@@ -196,45 +36,180 @@ declare interface TreeInputOptions {
|
|
|
196
36
|
/**
|
|
197
37
|
* Static filter to apply to tree document queries.
|
|
198
38
|
*/
|
|
199
|
-
filter?: string
|
|
39
|
+
filter?: string;
|
|
200
40
|
/**
|
|
201
41
|
* Parameters / variables to pass to the GROQ query ran to fetch documents.
|
|
202
42
|
*/
|
|
203
|
-
filterParams?: Record<string, unknown
|
|
204
|
-
}
|
|
43
|
+
filterParams?: Record<string, unknown>;
|
|
44
|
+
};
|
|
205
45
|
/**
|
|
206
46
|
* How deep should editors be allowed to nest items.
|
|
207
47
|
*/
|
|
208
|
-
maxDepth?: number
|
|
48
|
+
maxDepth?: number;
|
|
209
49
|
/**
|
|
210
50
|
* Schema type for your hierarchical documents.
|
|
211
51
|
* Refer to documentation on how to provide these schemas in your studio.
|
|
212
52
|
*
|
|
213
53
|
* Defautlt: 'hierarchy.tree' - this schema is bundled with the plugin
|
|
214
54
|
*/
|
|
215
|
-
documentType?: string
|
|
55
|
+
documentType?: string;
|
|
216
56
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
57
|
+
interface TreeDeskStructureProps extends TreeInputOptions {
|
|
58
|
+
/**
|
|
59
|
+
* _id of the document that will hold the tree data.
|
|
60
|
+
*/
|
|
61
|
+
documentId: string;
|
|
62
|
+
/**
|
|
63
|
+
* (Optional)
|
|
64
|
+
* Key for the field representing the hierarchical tree inside the document.
|
|
65
|
+
* `tree` by default.
|
|
66
|
+
*/
|
|
67
|
+
fieldKeyInDocument?: string;
|
|
220
68
|
}
|
|
221
|
-
|
|
222
|
-
export declare interface TreeProps extends TreeDeskStructureProps {
|
|
69
|
+
interface TreeProps extends TreeDeskStructureProps {
|
|
223
70
|
/**
|
|
224
71
|
* Visible title above the tree.
|
|
225
72
|
* Also used as the label in the desk list item.
|
|
226
73
|
*/
|
|
227
|
-
title: string
|
|
74
|
+
title: string;
|
|
228
75
|
/**
|
|
229
76
|
* Optional icon for rendering the item in the desk structure.
|
|
230
77
|
*/
|
|
231
|
-
icon?: any
|
|
232
|
-
|
|
233
|
-
|
|
78
|
+
icon?: any;
|
|
79
|
+
/**
|
|
80
|
+
* The `ConfigContext` available as the second parameter of the structure resolver.
|
|
81
|
+
*/
|
|
82
|
+
context?: any;
|
|
83
|
+
/**
|
|
84
|
+
* The `StructureBuilder` (`S`) available as the first parameter of the structure resolver.
|
|
85
|
+
*/
|
|
86
|
+
S?: any;
|
|
234
87
|
/**
|
|
235
88
|
* Restrict document types that can be created.
|
|
236
89
|
*/
|
|
237
|
-
creatableTypes?: string[]
|
|
90
|
+
creatableTypes?: string[];
|
|
91
|
+
}
|
|
92
|
+
declare function createDeskHierarchy(props: TreeProps): any;
|
|
93
|
+
type SchemaOptions = Omit<TreeDeskStructureProps, 'documentId' | 'maxDepth'>;
|
|
94
|
+
declare function createHierarchicalSchemas(options: SchemaOptions): ({
|
|
95
|
+
name: string | undefined;
|
|
96
|
+
title: string;
|
|
97
|
+
type: string;
|
|
98
|
+
liveEdit: boolean;
|
|
99
|
+
fields: (Omit<ArraySchemaType<unknown>, "type" | "of" | "jsonType"> & {
|
|
100
|
+
type: string;
|
|
101
|
+
inputComponent: FC<any>;
|
|
102
|
+
of?: any[];
|
|
103
|
+
})[];
|
|
104
|
+
preview: {
|
|
105
|
+
select: {
|
|
106
|
+
id: string;
|
|
107
|
+
tree: string;
|
|
108
|
+
};
|
|
109
|
+
prepare({
|
|
110
|
+
id,
|
|
111
|
+
tree
|
|
112
|
+
}: {
|
|
113
|
+
id: string;
|
|
114
|
+
tree: unknown[];
|
|
115
|
+
}): Record<string, string>;
|
|
116
|
+
};
|
|
117
|
+
} | {
|
|
118
|
+
name: string;
|
|
119
|
+
title: string;
|
|
120
|
+
type: string;
|
|
121
|
+
fields: ({
|
|
122
|
+
name: string;
|
|
123
|
+
type: string;
|
|
124
|
+
} | {
|
|
125
|
+
name: string;
|
|
126
|
+
type: string;
|
|
127
|
+
title: string;
|
|
128
|
+
fields: ({
|
|
129
|
+
name: string;
|
|
130
|
+
type: string;
|
|
131
|
+
weak?: undefined;
|
|
132
|
+
to?: undefined;
|
|
133
|
+
options?: undefined;
|
|
134
|
+
} | {
|
|
135
|
+
name: string;
|
|
136
|
+
type: string;
|
|
137
|
+
weak: boolean;
|
|
138
|
+
to: {
|
|
139
|
+
type: string;
|
|
140
|
+
}[];
|
|
141
|
+
options: {
|
|
142
|
+
filter?: string;
|
|
143
|
+
filterParams?: Record<string, unknown>;
|
|
144
|
+
} | undefined;
|
|
145
|
+
})[];
|
|
146
|
+
})[];
|
|
147
|
+
} | {
|
|
148
|
+
name: string;
|
|
149
|
+
title: string;
|
|
150
|
+
type: string;
|
|
151
|
+
of: ({
|
|
152
|
+
name: string;
|
|
153
|
+
title: string;
|
|
154
|
+
type: string;
|
|
155
|
+
fields: ({
|
|
156
|
+
name: string;
|
|
157
|
+
type: string;
|
|
158
|
+
} | {
|
|
159
|
+
name: string;
|
|
160
|
+
type: string;
|
|
161
|
+
title: string;
|
|
162
|
+
fields: ({
|
|
163
|
+
name: string;
|
|
164
|
+
type: string;
|
|
165
|
+
weak?: undefined;
|
|
166
|
+
to?: undefined;
|
|
167
|
+
options?: undefined;
|
|
168
|
+
} | {
|
|
169
|
+
name: string;
|
|
170
|
+
type: string;
|
|
171
|
+
weak: boolean;
|
|
172
|
+
to: {
|
|
173
|
+
type: string;
|
|
174
|
+
}[];
|
|
175
|
+
options: {
|
|
176
|
+
filter?: string;
|
|
177
|
+
filterParams?: Record<string, unknown>;
|
|
178
|
+
} | undefined;
|
|
179
|
+
})[];
|
|
180
|
+
})[];
|
|
181
|
+
} | {
|
|
182
|
+
type: string;
|
|
183
|
+
})[];
|
|
184
|
+
})[];
|
|
185
|
+
declare const _default: {
|
|
186
|
+
type: "document";
|
|
187
|
+
name: "hierarchy.tree";
|
|
188
|
+
} & Omit<import("sanity").DocumentDefinition, "preview"> & {
|
|
189
|
+
preview?: import("sanity").PreviewConfig<Record<string, string>, Record<never, any>> | undefined;
|
|
190
|
+
};
|
|
191
|
+
interface TreeItemWithChildren extends StoredTreeItem {
|
|
192
|
+
[key: string]: unknown;
|
|
193
|
+
children?: TreeItemWithChildren[];
|
|
238
194
|
}
|
|
239
|
-
|
|
240
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Converts the flat array stored in the Sanity document into a nested tree,
|
|
197
|
+
* nesting items under their `parent` _key. Items without a `parent` are roots.
|
|
198
|
+
*/
|
|
199
|
+
declare function flatDataToTree(data: StoredTreeItem[]): TreeItemWithChildren[];
|
|
200
|
+
/**
|
|
201
|
+
* Usage in `sanity.config.ts` (or .js)
|
|
202
|
+
*
|
|
203
|
+
* ```ts
|
|
204
|
+
* import {defineConfig} from 'sanity'
|
|
205
|
+
* import {hierarchicalDocumentList} from '@sanity/hierarchical-document-list'
|
|
206
|
+
*
|
|
207
|
+
* export default defineConfig({
|
|
208
|
+
* // ...
|
|
209
|
+
* plugins: [hierarchicalDocumentList()],
|
|
210
|
+
* })
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
declare const hierarchicalDocumentList: import("sanity").Plugin<void>;
|
|
214
|
+
export { type TreeProps, createDeskHierarchy, createHierarchicalSchemas, flatDataToTree, hierarchicalDocumentList, _default as hierarchyTree };
|
|
215
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/utils/injectNodeTypeInPatches.ts","../src/types.ts","../src/createDeskHierarchy.tsx","../src/createHierarchicalSchemas.tsx","../src/schemas/hierarchy.tree.ts","../src/utils/flatDataToTree.ts","../src/index.ts"],"mappings":";;cAsBa,kBAAA;AAAA,cACA,wBAAA;AAAA,UClBH,eAAA;EACR,KAAA;EACA,IAAA;EACA,KAAA;AAAA;ADeF;;;AAAA,UCTiB,cAAA;EACf,IAAA;EACA,KAAA,SAAc,kBAAA;EACd,KAAA;IACE,KAAA,SAAc,wBAAA;IACd,SAAA,GAAY,eAAA;IACZ,OAAA;EAAA;EAbF;;;EAkBA,MAAA;AAAA;AAAA,UAgCe,gBAAA;EAkBE;;;;EAbjB,WAAA;EAqCe;;;EAhCf,gBAAA;IAgC8C;;;IA5B5C,MAAA;IAuCgB;;ACvGpB;IDoEI,YAAA,GAAe,MAAM;EAAA;ECpEgC;;;ED0EvD,QAAA;EC3DA;;;;AAQc;AACf;ED0DC,YAAA;AAAA;AAAA,UAUe,sBAAA,SAA+B,gBAAgB;EErF9C;;;EFyFhB,UAAA;EEkCsB;;;;;EF3BtB,kBAAA;AAAA;AAAA,UCvGe,SAAA,SAAkB,sBAAsB;;AFezD;;;EEVE,KAAA;EFU2E;AAC7E;;EENE,IAAA;EFMsF;AAAA;;EEDtF,OAAA;EDjBuB;;;ECqBvB,CAAA;EDnBA;;;ECuBA,cAAA;AAAA;AAAA,iBAesB,mBAAA,CAAoB,KAAgB,EAAT,SAAS;AAAA,KC/BvD,aAAA,GAAgB,IAAI,CAAC,sBAAA;AAAA,iBA2HF,yBAAA,CAA0B,OAAA,EAAS,aAAA;;;;;;;oBApDzC,EAAA;;;;;;;;;;;;MA0CS,EAAA;MAAY,IAAA;IAAA,IAAmB,MAAA;EAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UE7HhD,oBAAA,SAA6B,cAAc;EAAA,CAElD,GAAA;EACD,QAAA,GAAW,oBAAA;AAAA;;;ALiBgE;AAC7E;iBKXwB,cAAA,CAAe,IAAA,EAAM,cAAA,KAAmB,oBAAoB;;ALUP;AAC7E;;;;AAAwF;;ACpBS;;;;;cKqBpF,wBAAA,mBAAwB,MAAA"}
|