sanity-plugin-recursive-hierarchy 1.0.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/LICENSE +21 -0
- package/README.md +676 -0
- package/dist/index.d.mts +336 -0
- package/dist/index.d.ts +336 -0
- package/dist/index.js +3494 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3502 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +100 -0
- package/sanity.json +8 -0
- package/src/actions/helpers.ts +55 -0
- package/src/actions/wrapDuplicateAction.ts +92 -0
- package/src/components/MapUpdater.tsx +447 -0
- package/src/components/RecursiveListWrapper.tsx +180 -0
- package/src/index.ts +95 -0
- package/src/initialValueTemplates.ts +72 -0
- package/src/lib/apiVersion.ts +18 -0
- package/src/lib/defaultStructureFilter.ts +47 -0
- package/src/lib/helpers.ts +23 -0
- package/src/lib/hooks.ts +10 -0
- package/src/recursiveNestedList/ListLoading.tsx +10 -0
- package/src/recursiveNestedList/createDraftMenuItems.ts +67 -0
- package/src/recursiveNestedList/fields.ts +155 -0
- package/src/recursiveNestedList/index.ts +7 -0
- package/src/recursiveNestedList/parentChildMap.ts +564 -0
- package/src/recursiveNestedList/recursiveMapStore.tsx +60 -0
- package/src/recursiveNestedList/recursiveNestedStructureDescendentList.tsx +315 -0
- package/src/recursiveNestedList/recursiveNestedStructureParentList.ts +413 -0
- package/src/recursiveNestedList/routing.ts +259 -0
- package/src/types.ts +216 -0
- package/src/urlSlug/components/AsyncUrlSlugInput.tsx +167 -0
- package/src/urlSlug/components/PrefixErrorBoundary.tsx +43 -0
- package/src/urlSlug/components/useAsyncUrlSlugLogic.ts +132 -0
- package/src/urlSlug/index.ts +15 -0
- package/src/urlSlug/lib/slugGeneration.ts +86 -0
- package/src/urlSlug/lib/slugValidationPerspective.ts +13 -0
- package/src/urlSlug/lib/slugify.ts +22 -0
- package/src/urlSlug/urlSlugObject.ts +43 -0
- package/v2-incompatible.js +11 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import {BooleanDefinition} from 'sanity'
|
|
2
|
+
import type {ComponentType} from 'react'
|
|
3
|
+
import type {CurrentUser} from 'sanity'
|
|
4
|
+
import type {FieldDefinition} from 'sanity'
|
|
5
|
+
import {FieldDefinitionBase} from 'sanity'
|
|
6
|
+
import {ListItemBuilder} from 'sanity/structure'
|
|
7
|
+
import {ObjectDefinition} from 'sanity'
|
|
8
|
+
import type {ObjectInputProps} from 'sanity'
|
|
9
|
+
import {Plugin as Plugin_2} from 'sanity'
|
|
10
|
+
import {PreviewConfig} from 'sanity'
|
|
11
|
+
import {ReactNode} from 'react'
|
|
12
|
+
import type {SanityDocument} from 'sanity'
|
|
13
|
+
import type {Slug} from 'sanity'
|
|
14
|
+
import {StringDefinition} from 'sanity'
|
|
15
|
+
import {StructureBuilder} from 'sanity/structure'
|
|
16
|
+
import {StructureResolverContext} from 'sanity/structure'
|
|
17
|
+
import type {Template} from 'sanity'
|
|
18
|
+
import {WidenInitialValue} from 'sanity'
|
|
19
|
+
import {WidenValidation} from 'sanity'
|
|
20
|
+
|
|
21
|
+
/** @public */
|
|
22
|
+
export declare const ACTION_GROUP_ADD: 'ADD'
|
|
23
|
+
|
|
24
|
+
/** @public */
|
|
25
|
+
export declare const ACTION_GROUP_DELETE: 'DELETE'
|
|
26
|
+
|
|
27
|
+
/** @public */
|
|
28
|
+
export declare const ACTION_GROUP_EDIT: 'EDIT'
|
|
29
|
+
|
|
30
|
+
declare type BaseRecursiveStructureParentOptions = {
|
|
31
|
+
S: StructureBuilder
|
|
32
|
+
context: StructureResolverContext
|
|
33
|
+
treeId: string
|
|
34
|
+
locale: Locale
|
|
35
|
+
parentNodeDocumentType: string
|
|
36
|
+
parentNodeIcon: ComponentType
|
|
37
|
+
parentNodeTemplate: string
|
|
38
|
+
topLevelNodeListTitle: string
|
|
39
|
+
descendentNodeTemplate: string
|
|
40
|
+
descendentListTitleSuffix: string
|
|
41
|
+
leafMenuSortByParentsItemTitle: string
|
|
42
|
+
descendentAdditionalParamsFromParent: {
|
|
43
|
+
key: string
|
|
44
|
+
default: unknown
|
|
45
|
+
}[]
|
|
46
|
+
parentMenuCreateItemLabel: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @public */
|
|
50
|
+
export declare type CreateDraftParams = {
|
|
51
|
+
timestamp: number
|
|
52
|
+
type: string
|
|
53
|
+
template: string
|
|
54
|
+
parentId: string
|
|
55
|
+
parentSummary: SanityDocumentWithDraftInfo | undefined
|
|
56
|
+
parentPaneId: string
|
|
57
|
+
additionalAttributes?: {
|
|
58
|
+
title?: string
|
|
59
|
+
language?: string
|
|
60
|
+
filters?: string[]
|
|
61
|
+
topLevelNode?: boolean
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** @public */
|
|
66
|
+
export declare function createTreeTemplates(trees: TreeConfig[]): Template[]
|
|
67
|
+
|
|
68
|
+
/** @public */
|
|
69
|
+
export declare const DEFAULT_LOCALE_KEY = 'default'
|
|
70
|
+
|
|
71
|
+
/** @public */
|
|
72
|
+
export declare interface FilterBuilder {
|
|
73
|
+
type: (type: string) => FilterBuilder
|
|
74
|
+
language: (lang: string, langFieldName?: string) => FilterBuilder
|
|
75
|
+
userScope: (user: CurrentUser | null) => FilterBuilder
|
|
76
|
+
excludeSingletons: (ids: string[]) => FilterBuilder
|
|
77
|
+
custom: (filter: string) => FilterBuilder
|
|
78
|
+
build: () => string
|
|
79
|
+
getParams: () => Record<string, unknown>
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** @public */
|
|
83
|
+
export declare const generateLanguageField: (params: {languageFieldName: string}) => FieldDefinition
|
|
84
|
+
|
|
85
|
+
/** @public */
|
|
86
|
+
export declare const generateLeafParentNodesField: (params: {
|
|
87
|
+
nodeType: string
|
|
88
|
+
title?: string
|
|
89
|
+
description?: string
|
|
90
|
+
languageFieldName?: string
|
|
91
|
+
}) => FieldDefinition
|
|
92
|
+
|
|
93
|
+
/** @public */
|
|
94
|
+
export declare const generateNodeParentField: (params: {
|
|
95
|
+
nodeType: string
|
|
96
|
+
title?: string
|
|
97
|
+
description?: string
|
|
98
|
+
languageFieldName?: string
|
|
99
|
+
}) => FieldDefinition
|
|
100
|
+
|
|
101
|
+
/** @public */
|
|
102
|
+
export declare const generateSlugField: (params: {
|
|
103
|
+
treeId: string
|
|
104
|
+
basePath?: string
|
|
105
|
+
languageFieldName?: string
|
|
106
|
+
}) => FieldDefinition
|
|
107
|
+
|
|
108
|
+
/** @public */
|
|
109
|
+
export declare function getAllTrees(): TreeConfig[]
|
|
110
|
+
|
|
111
|
+
/** @public */
|
|
112
|
+
export declare function getPluginOptions(): PluginOptions
|
|
113
|
+
|
|
114
|
+
/** @public */
|
|
115
|
+
export declare function getStructureApiVersion(): string
|
|
116
|
+
|
|
117
|
+
/** @public */
|
|
118
|
+
export declare function getTreeConfig(treeId: string): TreeConfig
|
|
119
|
+
|
|
120
|
+
/** @public */
|
|
121
|
+
export declare function getTreeForDocumentType(docType: string): TreeConfig | undefined
|
|
122
|
+
|
|
123
|
+
/** @public */
|
|
124
|
+
export declare function getTreeTemplateIds(tree: TreeConfig): TreeTemplateIds
|
|
125
|
+
|
|
126
|
+
/** @public */
|
|
127
|
+
export declare const leafParentTitlesField: {
|
|
128
|
+
type: 'string'
|
|
129
|
+
name: 'parentTitles'
|
|
130
|
+
} & Omit<StringDefinition, 'preview'> &
|
|
131
|
+
FieldDefinitionBase &
|
|
132
|
+
WidenValidation &
|
|
133
|
+
WidenInitialValue
|
|
134
|
+
|
|
135
|
+
/** @public */
|
|
136
|
+
export declare type Locale = {
|
|
137
|
+
fallbackLocale?: null | string
|
|
138
|
+
flag: string
|
|
139
|
+
id: string
|
|
140
|
+
releaseId?: string
|
|
141
|
+
status?: 'draft' | 'in_release' | 'published'
|
|
142
|
+
title: string
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** @public */
|
|
146
|
+
export declare type LocaleOption = {
|
|
147
|
+
id: string
|
|
148
|
+
title: string
|
|
149
|
+
flag?: string
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** @public */
|
|
153
|
+
export declare type MapUpdatePayload = {
|
|
154
|
+
timestamp: number
|
|
155
|
+
treeId: string
|
|
156
|
+
documentType: string
|
|
157
|
+
nodeDocumentType: string
|
|
158
|
+
leafDocumentType: string
|
|
159
|
+
documentId: string
|
|
160
|
+
oldParentIds: Array<string>
|
|
161
|
+
newParentIds: Array<string>
|
|
162
|
+
language: string
|
|
163
|
+
suppressRouting: boolean
|
|
164
|
+
rebuildFromRoot: boolean
|
|
165
|
+
patchFields?: {
|
|
166
|
+
title?: string
|
|
167
|
+
slug?: {
|
|
168
|
+
current?: string
|
|
169
|
+
fullUrl?: string
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
actionGroup: typeof ACTION_GROUP_ADD | typeof ACTION_GROUP_DELETE | typeof ACTION_GROUP_EDIT | ''
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* WARNING: Must be rendered as a React component (`<MapUpdater {...props} />`)
|
|
177
|
+
* and NOT called as a function (`MapUpdater(props)`). Calling it as a function
|
|
178
|
+
* breaks React's hook lifecycle — hooks inside will be associated with the
|
|
179
|
+
* parent component's fiber instead of their own, causing stale state, skipped
|
|
180
|
+
* effects, and unpredictable behavior.
|
|
181
|
+
*
|
|
182
|
+
* @public
|
|
183
|
+
*/
|
|
184
|
+
export declare function MapUpdater(
|
|
185
|
+
props: {
|
|
186
|
+
treeId: string
|
|
187
|
+
documentType: string
|
|
188
|
+
nodeOrLeaf: 'leaf' | 'node'
|
|
189
|
+
} & ObjectInputProps,
|
|
190
|
+
): ReactNode
|
|
191
|
+
|
|
192
|
+
declare type MultiLocaleRecursiveNestedStructureOptions = Omit<
|
|
193
|
+
BaseRecursiveStructureParentOptions,
|
|
194
|
+
'locale'
|
|
195
|
+
> & {
|
|
196
|
+
mode: 'browse' | 'manage'
|
|
197
|
+
rootListRecursiveListItemTitle: string
|
|
198
|
+
rootListRecursiveListItemIcon: ComponentType | ReactNode
|
|
199
|
+
locales: Locale[]
|
|
200
|
+
noLocalesError: string
|
|
201
|
+
parentMenuCreateItemLabel: string
|
|
202
|
+
parentNodeIcon?: ComponentType
|
|
203
|
+
parentAdditionalParams: {
|
|
204
|
+
title?: string
|
|
205
|
+
}
|
|
206
|
+
leafDocumentType: string
|
|
207
|
+
leafTemplate: string
|
|
208
|
+
leafDocumentTypeLabel?: string
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Outer key = treeId, inner key = localeKey
|
|
213
|
+
* @public
|
|
214
|
+
*/
|
|
215
|
+
export declare type NodeAndLeafMap = Record<string, Record<string, StructureMapAndNodesDict>>
|
|
216
|
+
|
|
217
|
+
declare type NodeInfo = {
|
|
218
|
+
leaves: SanityDocumentWithDraftInfo[]
|
|
219
|
+
node: SanityDocumentWithDraftInfo | undefined
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
declare type NodesDictionary = Record<string, NodeInfo>
|
|
223
|
+
|
|
224
|
+
/** @public */
|
|
225
|
+
export declare type PluginOptions = {
|
|
226
|
+
trees: TreeConfig[]
|
|
227
|
+
t?: (key: string, language?: string, params?: Record<string, unknown>) => string
|
|
228
|
+
createStructureFilter?: () => FilterBuilder
|
|
229
|
+
icons?: {
|
|
230
|
+
plus?: ComponentType
|
|
231
|
+
folderTree?: ComponentType
|
|
232
|
+
}
|
|
233
|
+
apiVersion?: string
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Sanity plugin for recursive nested list structure.
|
|
238
|
+
* Configure trees (each with documentTypes, languageFieldName, getLocales), t, createStructureFilter, and icons via options.
|
|
239
|
+
*
|
|
240
|
+
* @public
|
|
241
|
+
*/
|
|
242
|
+
export declare const recursiveListPlugin: Plugin_2<PluginOptions | undefined>
|
|
243
|
+
|
|
244
|
+
/** @public */
|
|
245
|
+
export declare const recursiveListSingleOrMultiLocale: (
|
|
246
|
+
options: MultiLocaleRecursiveNestedStructureOptions,
|
|
247
|
+
) => ListItemBuilder
|
|
248
|
+
|
|
249
|
+
/** @public */
|
|
250
|
+
export declare type SanityDocumentWithDraftInfo = Omit<
|
|
251
|
+
SanityDocument,
|
|
252
|
+
'_rev' | 'createdAt' | 'updatedAt'
|
|
253
|
+
> & {
|
|
254
|
+
_id: string
|
|
255
|
+
_type: string
|
|
256
|
+
_originalId: string
|
|
257
|
+
language?: string
|
|
258
|
+
title: string
|
|
259
|
+
slug: Slug & {
|
|
260
|
+
fullUrl?: string
|
|
261
|
+
}
|
|
262
|
+
parentIds?: Array<string>
|
|
263
|
+
topLevelNode?: boolean
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** @public */
|
|
267
|
+
export declare function setPluginOptions(options: PluginOptions): void
|
|
268
|
+
|
|
269
|
+
declare type StructureMap = Record<
|
|
270
|
+
string,
|
|
271
|
+
{
|
|
272
|
+
children: Array<SanityDocumentWithDraftInfo>
|
|
273
|
+
title: string
|
|
274
|
+
}
|
|
275
|
+
>
|
|
276
|
+
|
|
277
|
+
/** @public */
|
|
278
|
+
export declare type StructureMapAndNodesDict = {
|
|
279
|
+
nodesDictionary: NodesDictionary
|
|
280
|
+
structureMap: StructureMap
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** @public */
|
|
284
|
+
export declare const titleField: {
|
|
285
|
+
type: 'string'
|
|
286
|
+
name: 'title'
|
|
287
|
+
} & Omit<StringDefinition, 'preview'> &
|
|
288
|
+
FieldDefinitionBase &
|
|
289
|
+
WidenValidation &
|
|
290
|
+
WidenInitialValue
|
|
291
|
+
|
|
292
|
+
/** @public */
|
|
293
|
+
export declare const topLevelNodeField: {
|
|
294
|
+
type: 'boolean'
|
|
295
|
+
name: 'topLevelNode'
|
|
296
|
+
} & Omit<BooleanDefinition, 'preview'> &
|
|
297
|
+
FieldDefinitionBase &
|
|
298
|
+
WidenValidation &
|
|
299
|
+
WidenInitialValue
|
|
300
|
+
|
|
301
|
+
/** @public */
|
|
302
|
+
export declare type TreeConfig = {
|
|
303
|
+
id: string
|
|
304
|
+
documentTypes: {
|
|
305
|
+
node: string
|
|
306
|
+
leaf: string
|
|
307
|
+
}
|
|
308
|
+
languageFieldName?: string
|
|
309
|
+
getLocales?: (client: unknown) => LocaleOption[]
|
|
310
|
+
leafParentReferenceField?: string
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** @public */
|
|
314
|
+
export declare type TreeTemplateIds = {
|
|
315
|
+
parentNode: string
|
|
316
|
+
descendentNode: string
|
|
317
|
+
leaf: string
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** @public */
|
|
321
|
+
export declare const urlSlugObject: {
|
|
322
|
+
type: 'object'
|
|
323
|
+
name: 'urlSlug'
|
|
324
|
+
} & Omit<ObjectDefinition, 'preview'> & {
|
|
325
|
+
preview?:
|
|
326
|
+
| PreviewConfig<
|
|
327
|
+
{
|
|
328
|
+
current: string
|
|
329
|
+
fullUrl: string
|
|
330
|
+
},
|
|
331
|
+
Record<'current' | 'fullUrl', any>
|
|
332
|
+
>
|
|
333
|
+
| undefined
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export {}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import {BooleanDefinition} from 'sanity'
|
|
2
|
+
import type {ComponentType} from 'react'
|
|
3
|
+
import type {CurrentUser} from 'sanity'
|
|
4
|
+
import type {FieldDefinition} from 'sanity'
|
|
5
|
+
import {FieldDefinitionBase} from 'sanity'
|
|
6
|
+
import {ListItemBuilder} from 'sanity/structure'
|
|
7
|
+
import {ObjectDefinition} from 'sanity'
|
|
8
|
+
import type {ObjectInputProps} from 'sanity'
|
|
9
|
+
import {Plugin as Plugin_2} from 'sanity'
|
|
10
|
+
import {PreviewConfig} from 'sanity'
|
|
11
|
+
import {ReactNode} from 'react'
|
|
12
|
+
import type {SanityDocument} from 'sanity'
|
|
13
|
+
import type {Slug} from 'sanity'
|
|
14
|
+
import {StringDefinition} from 'sanity'
|
|
15
|
+
import {StructureBuilder} from 'sanity/structure'
|
|
16
|
+
import {StructureResolverContext} from 'sanity/structure'
|
|
17
|
+
import type {Template} from 'sanity'
|
|
18
|
+
import {WidenInitialValue} from 'sanity'
|
|
19
|
+
import {WidenValidation} from 'sanity'
|
|
20
|
+
|
|
21
|
+
/** @public */
|
|
22
|
+
export declare const ACTION_GROUP_ADD: 'ADD'
|
|
23
|
+
|
|
24
|
+
/** @public */
|
|
25
|
+
export declare const ACTION_GROUP_DELETE: 'DELETE'
|
|
26
|
+
|
|
27
|
+
/** @public */
|
|
28
|
+
export declare const ACTION_GROUP_EDIT: 'EDIT'
|
|
29
|
+
|
|
30
|
+
declare type BaseRecursiveStructureParentOptions = {
|
|
31
|
+
S: StructureBuilder
|
|
32
|
+
context: StructureResolverContext
|
|
33
|
+
treeId: string
|
|
34
|
+
locale: Locale
|
|
35
|
+
parentNodeDocumentType: string
|
|
36
|
+
parentNodeIcon: ComponentType
|
|
37
|
+
parentNodeTemplate: string
|
|
38
|
+
topLevelNodeListTitle: string
|
|
39
|
+
descendentNodeTemplate: string
|
|
40
|
+
descendentListTitleSuffix: string
|
|
41
|
+
leafMenuSortByParentsItemTitle: string
|
|
42
|
+
descendentAdditionalParamsFromParent: {
|
|
43
|
+
key: string
|
|
44
|
+
default: unknown
|
|
45
|
+
}[]
|
|
46
|
+
parentMenuCreateItemLabel: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @public */
|
|
50
|
+
export declare type CreateDraftParams = {
|
|
51
|
+
timestamp: number
|
|
52
|
+
type: string
|
|
53
|
+
template: string
|
|
54
|
+
parentId: string
|
|
55
|
+
parentSummary: SanityDocumentWithDraftInfo | undefined
|
|
56
|
+
parentPaneId: string
|
|
57
|
+
additionalAttributes?: {
|
|
58
|
+
title?: string
|
|
59
|
+
language?: string
|
|
60
|
+
filters?: string[]
|
|
61
|
+
topLevelNode?: boolean
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** @public */
|
|
66
|
+
export declare function createTreeTemplates(trees: TreeConfig[]): Template[]
|
|
67
|
+
|
|
68
|
+
/** @public */
|
|
69
|
+
export declare const DEFAULT_LOCALE_KEY = 'default'
|
|
70
|
+
|
|
71
|
+
/** @public */
|
|
72
|
+
export declare interface FilterBuilder {
|
|
73
|
+
type: (type: string) => FilterBuilder
|
|
74
|
+
language: (lang: string, langFieldName?: string) => FilterBuilder
|
|
75
|
+
userScope: (user: CurrentUser | null) => FilterBuilder
|
|
76
|
+
excludeSingletons: (ids: string[]) => FilterBuilder
|
|
77
|
+
custom: (filter: string) => FilterBuilder
|
|
78
|
+
build: () => string
|
|
79
|
+
getParams: () => Record<string, unknown>
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** @public */
|
|
83
|
+
export declare const generateLanguageField: (params: {languageFieldName: string}) => FieldDefinition
|
|
84
|
+
|
|
85
|
+
/** @public */
|
|
86
|
+
export declare const generateLeafParentNodesField: (params: {
|
|
87
|
+
nodeType: string
|
|
88
|
+
title?: string
|
|
89
|
+
description?: string
|
|
90
|
+
languageFieldName?: string
|
|
91
|
+
}) => FieldDefinition
|
|
92
|
+
|
|
93
|
+
/** @public */
|
|
94
|
+
export declare const generateNodeParentField: (params: {
|
|
95
|
+
nodeType: string
|
|
96
|
+
title?: string
|
|
97
|
+
description?: string
|
|
98
|
+
languageFieldName?: string
|
|
99
|
+
}) => FieldDefinition
|
|
100
|
+
|
|
101
|
+
/** @public */
|
|
102
|
+
export declare const generateSlugField: (params: {
|
|
103
|
+
treeId: string
|
|
104
|
+
basePath?: string
|
|
105
|
+
languageFieldName?: string
|
|
106
|
+
}) => FieldDefinition
|
|
107
|
+
|
|
108
|
+
/** @public */
|
|
109
|
+
export declare function getAllTrees(): TreeConfig[]
|
|
110
|
+
|
|
111
|
+
/** @public */
|
|
112
|
+
export declare function getPluginOptions(): PluginOptions
|
|
113
|
+
|
|
114
|
+
/** @public */
|
|
115
|
+
export declare function getStructureApiVersion(): string
|
|
116
|
+
|
|
117
|
+
/** @public */
|
|
118
|
+
export declare function getTreeConfig(treeId: string): TreeConfig
|
|
119
|
+
|
|
120
|
+
/** @public */
|
|
121
|
+
export declare function getTreeForDocumentType(docType: string): TreeConfig | undefined
|
|
122
|
+
|
|
123
|
+
/** @public */
|
|
124
|
+
export declare function getTreeTemplateIds(tree: TreeConfig): TreeTemplateIds
|
|
125
|
+
|
|
126
|
+
/** @public */
|
|
127
|
+
export declare const leafParentTitlesField: {
|
|
128
|
+
type: 'string'
|
|
129
|
+
name: 'parentTitles'
|
|
130
|
+
} & Omit<StringDefinition, 'preview'> &
|
|
131
|
+
FieldDefinitionBase &
|
|
132
|
+
WidenValidation &
|
|
133
|
+
WidenInitialValue
|
|
134
|
+
|
|
135
|
+
/** @public */
|
|
136
|
+
export declare type Locale = {
|
|
137
|
+
fallbackLocale?: null | string
|
|
138
|
+
flag: string
|
|
139
|
+
id: string
|
|
140
|
+
releaseId?: string
|
|
141
|
+
status?: 'draft' | 'in_release' | 'published'
|
|
142
|
+
title: string
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** @public */
|
|
146
|
+
export declare type LocaleOption = {
|
|
147
|
+
id: string
|
|
148
|
+
title: string
|
|
149
|
+
flag?: string
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** @public */
|
|
153
|
+
export declare type MapUpdatePayload = {
|
|
154
|
+
timestamp: number
|
|
155
|
+
treeId: string
|
|
156
|
+
documentType: string
|
|
157
|
+
nodeDocumentType: string
|
|
158
|
+
leafDocumentType: string
|
|
159
|
+
documentId: string
|
|
160
|
+
oldParentIds: Array<string>
|
|
161
|
+
newParentIds: Array<string>
|
|
162
|
+
language: string
|
|
163
|
+
suppressRouting: boolean
|
|
164
|
+
rebuildFromRoot: boolean
|
|
165
|
+
patchFields?: {
|
|
166
|
+
title?: string
|
|
167
|
+
slug?: {
|
|
168
|
+
current?: string
|
|
169
|
+
fullUrl?: string
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
actionGroup: typeof ACTION_GROUP_ADD | typeof ACTION_GROUP_DELETE | typeof ACTION_GROUP_EDIT | ''
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* WARNING: Must be rendered as a React component (`<MapUpdater {...props} />`)
|
|
177
|
+
* and NOT called as a function (`MapUpdater(props)`). Calling it as a function
|
|
178
|
+
* breaks React's hook lifecycle — hooks inside will be associated with the
|
|
179
|
+
* parent component's fiber instead of their own, causing stale state, skipped
|
|
180
|
+
* effects, and unpredictable behavior.
|
|
181
|
+
*
|
|
182
|
+
* @public
|
|
183
|
+
*/
|
|
184
|
+
export declare function MapUpdater(
|
|
185
|
+
props: {
|
|
186
|
+
treeId: string
|
|
187
|
+
documentType: string
|
|
188
|
+
nodeOrLeaf: 'leaf' | 'node'
|
|
189
|
+
} & ObjectInputProps,
|
|
190
|
+
): ReactNode
|
|
191
|
+
|
|
192
|
+
declare type MultiLocaleRecursiveNestedStructureOptions = Omit<
|
|
193
|
+
BaseRecursiveStructureParentOptions,
|
|
194
|
+
'locale'
|
|
195
|
+
> & {
|
|
196
|
+
mode: 'browse' | 'manage'
|
|
197
|
+
rootListRecursiveListItemTitle: string
|
|
198
|
+
rootListRecursiveListItemIcon: ComponentType | ReactNode
|
|
199
|
+
locales: Locale[]
|
|
200
|
+
noLocalesError: string
|
|
201
|
+
parentMenuCreateItemLabel: string
|
|
202
|
+
parentNodeIcon?: ComponentType
|
|
203
|
+
parentAdditionalParams: {
|
|
204
|
+
title?: string
|
|
205
|
+
}
|
|
206
|
+
leafDocumentType: string
|
|
207
|
+
leafTemplate: string
|
|
208
|
+
leafDocumentTypeLabel?: string
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Outer key = treeId, inner key = localeKey
|
|
213
|
+
* @public
|
|
214
|
+
*/
|
|
215
|
+
export declare type NodeAndLeafMap = Record<string, Record<string, StructureMapAndNodesDict>>
|
|
216
|
+
|
|
217
|
+
declare type NodeInfo = {
|
|
218
|
+
leaves: SanityDocumentWithDraftInfo[]
|
|
219
|
+
node: SanityDocumentWithDraftInfo | undefined
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
declare type NodesDictionary = Record<string, NodeInfo>
|
|
223
|
+
|
|
224
|
+
/** @public */
|
|
225
|
+
export declare type PluginOptions = {
|
|
226
|
+
trees: TreeConfig[]
|
|
227
|
+
t?: (key: string, language?: string, params?: Record<string, unknown>) => string
|
|
228
|
+
createStructureFilter?: () => FilterBuilder
|
|
229
|
+
icons?: {
|
|
230
|
+
plus?: ComponentType
|
|
231
|
+
folderTree?: ComponentType
|
|
232
|
+
}
|
|
233
|
+
apiVersion?: string
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Sanity plugin for recursive nested list structure.
|
|
238
|
+
* Configure trees (each with documentTypes, languageFieldName, getLocales), t, createStructureFilter, and icons via options.
|
|
239
|
+
*
|
|
240
|
+
* @public
|
|
241
|
+
*/
|
|
242
|
+
export declare const recursiveListPlugin: Plugin_2<PluginOptions | undefined>
|
|
243
|
+
|
|
244
|
+
/** @public */
|
|
245
|
+
export declare const recursiveListSingleOrMultiLocale: (
|
|
246
|
+
options: MultiLocaleRecursiveNestedStructureOptions,
|
|
247
|
+
) => ListItemBuilder
|
|
248
|
+
|
|
249
|
+
/** @public */
|
|
250
|
+
export declare type SanityDocumentWithDraftInfo = Omit<
|
|
251
|
+
SanityDocument,
|
|
252
|
+
'_rev' | 'createdAt' | 'updatedAt'
|
|
253
|
+
> & {
|
|
254
|
+
_id: string
|
|
255
|
+
_type: string
|
|
256
|
+
_originalId: string
|
|
257
|
+
language?: string
|
|
258
|
+
title: string
|
|
259
|
+
slug: Slug & {
|
|
260
|
+
fullUrl?: string
|
|
261
|
+
}
|
|
262
|
+
parentIds?: Array<string>
|
|
263
|
+
topLevelNode?: boolean
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** @public */
|
|
267
|
+
export declare function setPluginOptions(options: PluginOptions): void
|
|
268
|
+
|
|
269
|
+
declare type StructureMap = Record<
|
|
270
|
+
string,
|
|
271
|
+
{
|
|
272
|
+
children: Array<SanityDocumentWithDraftInfo>
|
|
273
|
+
title: string
|
|
274
|
+
}
|
|
275
|
+
>
|
|
276
|
+
|
|
277
|
+
/** @public */
|
|
278
|
+
export declare type StructureMapAndNodesDict = {
|
|
279
|
+
nodesDictionary: NodesDictionary
|
|
280
|
+
structureMap: StructureMap
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** @public */
|
|
284
|
+
export declare const titleField: {
|
|
285
|
+
type: 'string'
|
|
286
|
+
name: 'title'
|
|
287
|
+
} & Omit<StringDefinition, 'preview'> &
|
|
288
|
+
FieldDefinitionBase &
|
|
289
|
+
WidenValidation &
|
|
290
|
+
WidenInitialValue
|
|
291
|
+
|
|
292
|
+
/** @public */
|
|
293
|
+
export declare const topLevelNodeField: {
|
|
294
|
+
type: 'boolean'
|
|
295
|
+
name: 'topLevelNode'
|
|
296
|
+
} & Omit<BooleanDefinition, 'preview'> &
|
|
297
|
+
FieldDefinitionBase &
|
|
298
|
+
WidenValidation &
|
|
299
|
+
WidenInitialValue
|
|
300
|
+
|
|
301
|
+
/** @public */
|
|
302
|
+
export declare type TreeConfig = {
|
|
303
|
+
id: string
|
|
304
|
+
documentTypes: {
|
|
305
|
+
node: string
|
|
306
|
+
leaf: string
|
|
307
|
+
}
|
|
308
|
+
languageFieldName?: string
|
|
309
|
+
getLocales?: (client: unknown) => LocaleOption[]
|
|
310
|
+
leafParentReferenceField?: string
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** @public */
|
|
314
|
+
export declare type TreeTemplateIds = {
|
|
315
|
+
parentNode: string
|
|
316
|
+
descendentNode: string
|
|
317
|
+
leaf: string
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** @public */
|
|
321
|
+
export declare const urlSlugObject: {
|
|
322
|
+
type: 'object'
|
|
323
|
+
name: 'urlSlug'
|
|
324
|
+
} & Omit<ObjectDefinition, 'preview'> & {
|
|
325
|
+
preview?:
|
|
326
|
+
| PreviewConfig<
|
|
327
|
+
{
|
|
328
|
+
current: string
|
|
329
|
+
fullUrl: string
|
|
330
|
+
},
|
|
331
|
+
Record<'current' | 'fullUrl', any>
|
|
332
|
+
>
|
|
333
|
+
| undefined
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export {}
|