sanity-plugin-taxonomy-manager 4.7.0 → 4.7.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/lib/index.d.ts CHANGED
@@ -8,14 +8,142 @@ import type {SanityDocument} from 'sanity'
8
8
  import type {useClient} from 'sanity'
9
9
 
10
10
  /**
11
- * #### Hierarchy View Input Component
12
- * Allows Studio users to browse and select taxonomy
13
- * terms from a hierarchical tree structure. It is designed to be
14
- * used as an input for taxonomy array fields in Sanity Studio.
11
+ * Input component that replaces Sanity's default array field input with a
12
+ * hierarchical taxonomy tree browser. Studio users can browse taxonomy terms
13
+ * organized in their scheme hierarchy and select terms to add to the array field.
15
14
  *
16
- * Hierarchy view must be used in conjunction with the Taxonomy Manager
17
- * plugin `schemeFilter` or `branchFilter` options.
15
+ * @remarks
16
+ * - Must be used with a `schemeFilter` or `branchFilter` helper in the field's
17
+ * `options.filter`. Rendering without a filter will display a configuration warning.
18
+ * - Supports only **single-schema arrays** (i.e., `of: [{type: 'reference'}]`). Arrays
19
+ * with multiple schema types will render a warning and fall back to the default input.
20
+ * - Taxonomy selection is disabled when viewing the published perspective.
21
+ * - When `browseOnly` is set in the filter configuration, Sanity's default search input
22
+ * is suppressed and only the tree browser is available for term selection.
23
+ * - When `expanded` is set in the filter configuration, the hierarchy tree loads open
24
+ * by default instead of collapsed.
18
25
  *
26
+ * @param props - Standard Sanity `ArrayFieldProps` extended with an optional
27
+ * `embeddingsIndex` configuration object.
28
+ * @param props.embeddingsIndex - Optional configuration for AI-assisted term
29
+ * recommendations via a Sanity Embeddings Index. When provided, opening the tree
30
+ * browser queries the specified index and annotates matching taxonomy terms with
31
+ * a relevance score to help authors identify the most appropriate terms.
32
+ * @param props.embeddingsIndex.indexName - The name of the Sanity Embeddings Index
33
+ * to query. Must be an index that includes `skosConcept` documents.
34
+ * @param props.embeddingsIndex.fieldReferences - An array of field names from the
35
+ * current document whose values are concatenated and sent as the embeddings search
36
+ * query. All listed fields must contain values when the tree browser is opened;
37
+ * empty fields will display an error message in the tree view rather than scores.
38
+ * @param props.embeddingsIndex.maxResults - Maximum number of semantically matching
39
+ * terms to return from the embeddings index. Defaults to `3`.
40
+ *
41
+ * @example
42
+ * Basic usage with a scheme filter:
43
+ * ```js
44
+ * import {ArrayHierarchyInput, schemeFilter} from 'sanity-plugin-taxonomy-manager'
45
+ *
46
+ * defineField({
47
+ * name: 'categories',
48
+ * title: 'Categories',
49
+ * type: 'array',
50
+ * of: [
51
+ * {
52
+ * type: 'reference',
53
+ * to: {type: 'skosConcept'},
54
+ * options: {
55
+ * filter: schemeFilter({schemeId: 'f3deba'}),
56
+ * disableNew: true,
57
+ * },
58
+ * },
59
+ * ],
60
+ * components: {field: ArrayHierarchyInput},
61
+ * })
62
+ * ```
63
+ *
64
+ * @example
65
+ * Branch filter with tree expanded by default:
66
+ * ```js
67
+ * import {ArrayHierarchyInput, branchFilter} from 'sanity-plugin-taxonomy-manager'
68
+ *
69
+ * defineField({
70
+ * name: 'habitats',
71
+ * title: 'Habitats',
72
+ * type: 'array',
73
+ * of: [
74
+ * {
75
+ * type: 'reference',
76
+ * to: {type: 'skosConcept'},
77
+ * options: {
78
+ * filter: branchFilter({schemeId: 'cf76c1', branchId: '1e5e6c', expanded: true}),
79
+ * disableNew: true,
80
+ * },
81
+ * },
82
+ * ],
83
+ * components: {field: ArrayHierarchyInput},
84
+ * })
85
+ * ```
86
+ *
87
+ * @example
88
+ * Browse-only mode (suppresses the default Sanity search input):
89
+ * ```js
90
+ * import {ArrayHierarchyInput, branchFilter} from 'sanity-plugin-taxonomy-manager'
91
+ *
92
+ * defineField({
93
+ * name: 'habitats',
94
+ * title: 'Habitats',
95
+ * type: 'array',
96
+ * of: [
97
+ * {
98
+ * type: 'reference',
99
+ * to: {type: 'skosConcept'},
100
+ * options: {
101
+ * filter: branchFilter({schemeId: 'cf76c1', branchId: '1e5e6c', browseOnly: true}),
102
+ * disableNew: true,
103
+ * },
104
+ * },
105
+ * ],
106
+ * components: {field: ArrayHierarchyInput},
107
+ * })
108
+ * ```
109
+ *
110
+ * @example
111
+ * AI-assisted recommendations via an embeddings index:
112
+ * ```jsx
113
+ * import {ArrayHierarchyInput, branchFilter} from 'sanity-plugin-taxonomy-manager'
114
+ *
115
+ * defineField({
116
+ * name: 'categories',
117
+ * title: 'Categories',
118
+ * type: 'array',
119
+ * of: [
120
+ * {
121
+ * type: 'reference',
122
+ * to: [{type: 'skosConcept'}],
123
+ * options: {
124
+ * filter: branchFilter({schemeId: 'f3deba', branchId: '25f826'}),
125
+ * disableNew: true,
126
+ * },
127
+ * },
128
+ * ],
129
+ * components: {
130
+ * field: (props) => (
131
+ * <ArrayHierarchyInput
132
+ * {...props}
133
+ * embeddingsIndex={{
134
+ * indexName: 'my-taxonomy-index',
135
+ * fieldReferences: ['title', 'description'],
136
+ * maxResults: 4,
137
+ * }}
138
+ * />
139
+ * ),
140
+ * },
141
+ * })
142
+ * ```
143
+ *
144
+ * @see {@link ReferenceHierarchyInput} for single-value `reference` fields
145
+ * @see {@link schemeFilter} for filtering by a full concept scheme
146
+ * @see {@link branchFilter} for filtering by a branch within a concept scheme
19
147
  */
20
148
  export declare function ArrayHierarchyInput(props: ArrayHierarchyInputProps): JSX.Element
21
149
 
@@ -138,13 +266,120 @@ declare interface Options {
138
266
  }
139
267
 
140
268
  /**
141
- * #### Hierarchy View Input Component for Reference Fields
142
- * Allows Studio users to browse and select taxonomy
143
- * terms from a hierarchical tree structure. It is designed to be
144
- * used as an input for taxonomy reference fields in Sanity Studio.
269
+ * Input component that replaces Sanity's default reference field input with a
270
+ * hierarchical taxonomy tree browser. Studio users can browse taxonomy terms
271
+ * organized in their scheme hierarchy and select a single term for the field.
272
+ *
273
+ * @remarks
274
+ * - Must be used with a `schemeFilter` or `branchFilter` helper in the field's
275
+ * `options.filter`. Rendering without a filter will display a configuration warning.
276
+ * - Taxonomy selection is disabled when viewing the published perspective.
277
+ * - When `browseOnly` is set in the filter configuration, Sanity's default search input
278
+ * is suppressed and only the tree browser is available for term selection.
279
+ * - When `expanded` is set in the filter configuration, the hierarchy tree loads open
280
+ * by default instead of collapsed.
281
+ *
282
+ * @param props - Standard Sanity `ObjectFieldProps<Reference>` extended with an optional
283
+ * `embeddingsIndex` configuration object.
284
+ * @param props.embeddingsIndex - Optional configuration for AI-assisted term
285
+ * recommendations via a Sanity Embeddings Index. When provided, opening the tree
286
+ * browser queries the specified index and annotates matching taxonomy terms with
287
+ * a relevance score to help authors identify the most appropriate term.
288
+ * @param props.embeddingsIndex.indexName - The name of the Sanity Embeddings Index
289
+ * to query. Must be an index that includes `skosConcept` documents.
290
+ * @param props.embeddingsIndex.fieldReferences - An array of field names from the
291
+ * current document whose values are concatenated and sent as the embeddings search
292
+ * query. All listed fields must contain values when the tree browser is opened;
293
+ * empty fields will display an error message in the tree view rather than scores.
294
+ * @param props.embeddingsIndex.maxResults - Maximum number of semantically matching
295
+ * terms to return from the embeddings index. Defaults to `3`.
296
+ *
297
+ * @example
298
+ * Basic usage with a scheme filter:
299
+ * ```js
300
+ * import {ReferenceHierarchyInput, schemeFilter} from 'sanity-plugin-taxonomy-manager'
301
+ *
302
+ * defineField({
303
+ * name: 'gradeLevel',
304
+ * title: 'Grade Level',
305
+ * type: 'reference',
306
+ * to: {type: 'skosConcept'},
307
+ * options: {
308
+ * filter: schemeFilter({schemeId: 'f3deba'}),
309
+ * disableNew: true,
310
+ * },
311
+ * components: {field: ReferenceHierarchyInput},
312
+ * })
313
+ * ```
314
+ *
315
+ * @example
316
+ * Branch filter with tree expanded by default:
317
+ * ```js
318
+ * import {ReferenceHierarchyInput, branchFilter} from 'sanity-plugin-taxonomy-manager'
319
+ *
320
+ * defineField({
321
+ * name: 'topics',
322
+ * title: 'Topics',
323
+ * type: 'reference',
324
+ * to: {type: 'skosConcept'},
325
+ * options: {
326
+ * filter: branchFilter({schemeId: 'cf76c1', branchId: '1e5e6c', expanded: true}),
327
+ * disableNew: true,
328
+ * },
329
+ * components: {field: ReferenceHierarchyInput},
330
+ * })
331
+ * ```
332
+ *
333
+ * @example
334
+ * Browse-only mode (suppresses the default Sanity search input):
335
+ * ```js
336
+ * import {ReferenceHierarchyInput, branchFilter} from 'sanity-plugin-taxonomy-manager'
337
+ *
338
+ * defineField({
339
+ * name: 'topics',
340
+ * title: 'Topics',
341
+ * type: 'reference',
342
+ * to: {type: 'skosConcept'},
343
+ * options: {
344
+ * filter: branchFilter({schemeId: 'cf76c1', branchId: '1e5e6c', browseOnly: true}),
345
+ * disableNew: true,
346
+ * },
347
+ * components: {field: ReferenceHierarchyInput},
348
+ * })
349
+ * ```
350
+ *
351
+ * @example
352
+ * AI-assisted recommendations via an embeddings index:
353
+ * ```jsx
354
+ * import {ReferenceHierarchyInput, schemeFilter} from 'sanity-plugin-taxonomy-manager'
355
+ *
356
+ * defineField({
357
+ * name: 'topics',
358
+ * title: 'Topics',
359
+ * type: 'reference',
360
+ * to: [{type: 'skosConcept'}],
361
+ * options: {
362
+ * filter: schemeFilter({schemeId: 'f3deba'}),
363
+ * disableNew: true,
364
+ * },
365
+ * components: {
366
+ * field: (props) => (
367
+ * <ReferenceHierarchyInput
368
+ * {...props}
369
+ * embeddingsIndex={{
370
+ * indexName: 'my-taxonomy-index',
371
+ * fieldReferences: ['title', 'metaDescription'],
372
+ * maxResults: 4,
373
+ * }}
374
+ * />
375
+ * ),
376
+ * },
377
+ * })
378
+ * ```
145
379
  *
146
- * Hierarchy view must be used in conjunction with the Taxonomy Manager
147
- * plugin `schemeFilter` or `branchFilter` options.
380
+ * @see {@link ArrayHierarchyInput} for multi-value `array` fields
381
+ * @see {@link schemeFilter} for filtering by a full concept scheme
382
+ * @see {@link branchFilter} for filtering by a branch within a concept scheme
148
383
  */
149
384
  export declare function ReferenceHierarchyInput(props: HierarchyInput): JSX.Element
150
385
 
@@ -8,14 +8,142 @@ import type {SanityDocument} from 'sanity'
8
8
  import type {useClient} from 'sanity'
9
9
 
10
10
  /**
11
- * #### Hierarchy View Input Component
12
- * Allows Studio users to browse and select taxonomy
13
- * terms from a hierarchical tree structure. It is designed to be
14
- * used as an input for taxonomy array fields in Sanity Studio.
11
+ * Input component that replaces Sanity's default array field input with a
12
+ * hierarchical taxonomy tree browser. Studio users can browse taxonomy terms
13
+ * organized in their scheme hierarchy and select terms to add to the array field.
15
14
  *
16
- * Hierarchy view must be used in conjunction with the Taxonomy Manager
17
- * plugin `schemeFilter` or `branchFilter` options.
15
+ * @remarks
16
+ * - Must be used with a `schemeFilter` or `branchFilter` helper in the field's
17
+ * `options.filter`. Rendering without a filter will display a configuration warning.
18
+ * - Supports only **single-schema arrays** (i.e., `of: [{type: 'reference'}]`). Arrays
19
+ * with multiple schema types will render a warning and fall back to the default input.
20
+ * - Taxonomy selection is disabled when viewing the published perspective.
21
+ * - When `browseOnly` is set in the filter configuration, Sanity's default search input
22
+ * is suppressed and only the tree browser is available for term selection.
23
+ * - When `expanded` is set in the filter configuration, the hierarchy tree loads open
24
+ * by default instead of collapsed.
18
25
  *
26
+ * @param props - Standard Sanity `ArrayFieldProps` extended with an optional
27
+ * `embeddingsIndex` configuration object.
28
+ * @param props.embeddingsIndex - Optional configuration for AI-assisted term
29
+ * recommendations via a Sanity Embeddings Index. When provided, opening the tree
30
+ * browser queries the specified index and annotates matching taxonomy terms with
31
+ * a relevance score to help authors identify the most appropriate terms.
32
+ * @param props.embeddingsIndex.indexName - The name of the Sanity Embeddings Index
33
+ * to query. Must be an index that includes `skosConcept` documents.
34
+ * @param props.embeddingsIndex.fieldReferences - An array of field names from the
35
+ * current document whose values are concatenated and sent as the embeddings search
36
+ * query. All listed fields must contain values when the tree browser is opened;
37
+ * empty fields will display an error message in the tree view rather than scores.
38
+ * @param props.embeddingsIndex.maxResults - Maximum number of semantically matching
39
+ * terms to return from the embeddings index. Defaults to `3`.
40
+ *
41
+ * @example
42
+ * Basic usage with a scheme filter:
43
+ * ```js
44
+ * import {ArrayHierarchyInput, schemeFilter} from 'sanity-plugin-taxonomy-manager'
45
+ *
46
+ * defineField({
47
+ * name: 'categories',
48
+ * title: 'Categories',
49
+ * type: 'array',
50
+ * of: [
51
+ * {
52
+ * type: 'reference',
53
+ * to: {type: 'skosConcept'},
54
+ * options: {
55
+ * filter: schemeFilter({schemeId: 'f3deba'}),
56
+ * disableNew: true,
57
+ * },
58
+ * },
59
+ * ],
60
+ * components: {field: ArrayHierarchyInput},
61
+ * })
62
+ * ```
63
+ *
64
+ * @example
65
+ * Branch filter with tree expanded by default:
66
+ * ```js
67
+ * import {ArrayHierarchyInput, branchFilter} from 'sanity-plugin-taxonomy-manager'
68
+ *
69
+ * defineField({
70
+ * name: 'habitats',
71
+ * title: 'Habitats',
72
+ * type: 'array',
73
+ * of: [
74
+ * {
75
+ * type: 'reference',
76
+ * to: {type: 'skosConcept'},
77
+ * options: {
78
+ * filter: branchFilter({schemeId: 'cf76c1', branchId: '1e5e6c', expanded: true}),
79
+ * disableNew: true,
80
+ * },
81
+ * },
82
+ * ],
83
+ * components: {field: ArrayHierarchyInput},
84
+ * })
85
+ * ```
86
+ *
87
+ * @example
88
+ * Browse-only mode (suppresses the default Sanity search input):
89
+ * ```js
90
+ * import {ArrayHierarchyInput, branchFilter} from 'sanity-plugin-taxonomy-manager'
91
+ *
92
+ * defineField({
93
+ * name: 'habitats',
94
+ * title: 'Habitats',
95
+ * type: 'array',
96
+ * of: [
97
+ * {
98
+ * type: 'reference',
99
+ * to: {type: 'skosConcept'},
100
+ * options: {
101
+ * filter: branchFilter({schemeId: 'cf76c1', branchId: '1e5e6c', browseOnly: true}),
102
+ * disableNew: true,
103
+ * },
104
+ * },
105
+ * ],
106
+ * components: {field: ArrayHierarchyInput},
107
+ * })
108
+ * ```
109
+ *
110
+ * @example
111
+ * AI-assisted recommendations via an embeddings index:
112
+ * ```jsx
113
+ * import {ArrayHierarchyInput, branchFilter} from 'sanity-plugin-taxonomy-manager'
114
+ *
115
+ * defineField({
116
+ * name: 'categories',
117
+ * title: 'Categories',
118
+ * type: 'array',
119
+ * of: [
120
+ * {
121
+ * type: 'reference',
122
+ * to: [{type: 'skosConcept'}],
123
+ * options: {
124
+ * filter: branchFilter({schemeId: 'f3deba', branchId: '25f826'}),
125
+ * disableNew: true,
126
+ * },
127
+ * },
128
+ * ],
129
+ * components: {
130
+ * field: (props) => (
131
+ * <ArrayHierarchyInput
132
+ * {...props}
133
+ * embeddingsIndex={{
134
+ * indexName: 'my-taxonomy-index',
135
+ * fieldReferences: ['title', 'description'],
136
+ * maxResults: 4,
137
+ * }}
138
+ * />
139
+ * ),
140
+ * },
141
+ * })
142
+ * ```
143
+ *
144
+ * @see {@link ReferenceHierarchyInput} for single-value `reference` fields
145
+ * @see {@link schemeFilter} for filtering by a full concept scheme
146
+ * @see {@link branchFilter} for filtering by a branch within a concept scheme
19
147
  */
20
148
  export declare function ArrayHierarchyInput(props: ArrayHierarchyInputProps): JSX.Element
21
149
 
@@ -138,13 +266,120 @@ declare interface Options {
138
266
  }
139
267
 
140
268
  /**
141
- * #### Hierarchy View Input Component for Reference Fields
142
- * Allows Studio users to browse and select taxonomy
143
- * terms from a hierarchical tree structure. It is designed to be
144
- * used as an input for taxonomy reference fields in Sanity Studio.
269
+ * Input component that replaces Sanity's default reference field input with a
270
+ * hierarchical taxonomy tree browser. Studio users can browse taxonomy terms
271
+ * organized in their scheme hierarchy and select a single term for the field.
272
+ *
273
+ * @remarks
274
+ * - Must be used with a `schemeFilter` or `branchFilter` helper in the field's
275
+ * `options.filter`. Rendering without a filter will display a configuration warning.
276
+ * - Taxonomy selection is disabled when viewing the published perspective.
277
+ * - When `browseOnly` is set in the filter configuration, Sanity's default search input
278
+ * is suppressed and only the tree browser is available for term selection.
279
+ * - When `expanded` is set in the filter configuration, the hierarchy tree loads open
280
+ * by default instead of collapsed.
281
+ *
282
+ * @param props - Standard Sanity `ObjectFieldProps<Reference>` extended with an optional
283
+ * `embeddingsIndex` configuration object.
284
+ * @param props.embeddingsIndex - Optional configuration for AI-assisted term
285
+ * recommendations via a Sanity Embeddings Index. When provided, opening the tree
286
+ * browser queries the specified index and annotates matching taxonomy terms with
287
+ * a relevance score to help authors identify the most appropriate term.
288
+ * @param props.embeddingsIndex.indexName - The name of the Sanity Embeddings Index
289
+ * to query. Must be an index that includes `skosConcept` documents.
290
+ * @param props.embeddingsIndex.fieldReferences - An array of field names from the
291
+ * current document whose values are concatenated and sent as the embeddings search
292
+ * query. All listed fields must contain values when the tree browser is opened;
293
+ * empty fields will display an error message in the tree view rather than scores.
294
+ * @param props.embeddingsIndex.maxResults - Maximum number of semantically matching
295
+ * terms to return from the embeddings index. Defaults to `3`.
296
+ *
297
+ * @example
298
+ * Basic usage with a scheme filter:
299
+ * ```js
300
+ * import {ReferenceHierarchyInput, schemeFilter} from 'sanity-plugin-taxonomy-manager'
301
+ *
302
+ * defineField({
303
+ * name: 'gradeLevel',
304
+ * title: 'Grade Level',
305
+ * type: 'reference',
306
+ * to: {type: 'skosConcept'},
307
+ * options: {
308
+ * filter: schemeFilter({schemeId: 'f3deba'}),
309
+ * disableNew: true,
310
+ * },
311
+ * components: {field: ReferenceHierarchyInput},
312
+ * })
313
+ * ```
314
+ *
315
+ * @example
316
+ * Branch filter with tree expanded by default:
317
+ * ```js
318
+ * import {ReferenceHierarchyInput, branchFilter} from 'sanity-plugin-taxonomy-manager'
319
+ *
320
+ * defineField({
321
+ * name: 'topics',
322
+ * title: 'Topics',
323
+ * type: 'reference',
324
+ * to: {type: 'skosConcept'},
325
+ * options: {
326
+ * filter: branchFilter({schemeId: 'cf76c1', branchId: '1e5e6c', expanded: true}),
327
+ * disableNew: true,
328
+ * },
329
+ * components: {field: ReferenceHierarchyInput},
330
+ * })
331
+ * ```
332
+ *
333
+ * @example
334
+ * Browse-only mode (suppresses the default Sanity search input):
335
+ * ```js
336
+ * import {ReferenceHierarchyInput, branchFilter} from 'sanity-plugin-taxonomy-manager'
337
+ *
338
+ * defineField({
339
+ * name: 'topics',
340
+ * title: 'Topics',
341
+ * type: 'reference',
342
+ * to: {type: 'skosConcept'},
343
+ * options: {
344
+ * filter: branchFilter({schemeId: 'cf76c1', branchId: '1e5e6c', browseOnly: true}),
345
+ * disableNew: true,
346
+ * },
347
+ * components: {field: ReferenceHierarchyInput},
348
+ * })
349
+ * ```
350
+ *
351
+ * @example
352
+ * AI-assisted recommendations via an embeddings index:
353
+ * ```jsx
354
+ * import {ReferenceHierarchyInput, schemeFilter} from 'sanity-plugin-taxonomy-manager'
355
+ *
356
+ * defineField({
357
+ * name: 'topics',
358
+ * title: 'Topics',
359
+ * type: 'reference',
360
+ * to: [{type: 'skosConcept'}],
361
+ * options: {
362
+ * filter: schemeFilter({schemeId: 'f3deba'}),
363
+ * disableNew: true,
364
+ * },
365
+ * components: {
366
+ * field: (props) => (
367
+ * <ReferenceHierarchyInput
368
+ * {...props}
369
+ * embeddingsIndex={{
370
+ * indexName: 'my-taxonomy-index',
371
+ * fieldReferences: ['title', 'metaDescription'],
372
+ * maxResults: 4,
373
+ * }}
374
+ * />
375
+ * ),
376
+ * },
377
+ * })
378
+ * ```
145
379
  *
146
- * Hierarchy view must be used in conjunction with the Taxonomy Manager
147
- * plugin `schemeFilter` or `branchFilter` options.
380
+ * @see {@link ArrayHierarchyInput} for multi-value `array` fields
381
+ * @see {@link schemeFilter} for filtering by a full concept scheme
382
+ * @see {@link branchFilter} for filtering by a branch within a concept scheme
148
383
  */
149
384
  export declare function ReferenceHierarchyInput(props: HierarchyInput): JSX.Element
150
385