sanity-plugin-taxonomy-manager 4.7.2 → 5.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.
Files changed (83) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +13 -108
  3. package/{lib → dist}/index.d.ts +66 -48
  4. package/dist/index.js +106 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +40 -46
  7. package/src/components/Children.tsx +4 -3
  8. package/src/components/Concepts.tsx +2 -2
  9. package/src/components/Hierarchy.test.tsx +92 -0
  10. package/src/components/Hierarchy.tsx +65 -30
  11. package/src/components/TopConcepts.tsx +2 -2
  12. package/src/components/TreeStructure.tsx +3 -3
  13. package/src/components/inputs/ArrayHierarchyInput.test.tsx +102 -0
  14. package/src/components/inputs/ArrayHierarchyInput.tsx +23 -24
  15. package/src/components/inputs/Identifier.tsx +1 -1
  16. package/src/components/inputs/InputHierarchy.test.tsx +38 -0
  17. package/src/components/inputs/InputHierarchy.tsx +20 -68
  18. package/src/components/inputs/ReferenceHierarchyInput.test.tsx +109 -0
  19. package/src/components/inputs/ReferenceHierarchyInput.tsx +24 -25
  20. package/src/components/interactions/ConceptDetailLink.tsx +0 -1
  21. package/src/components/interactions/ConceptEditAction.tsx +1 -1
  22. package/src/components/interactions/ConceptSelectLink.test.tsx +49 -0
  23. package/src/components/interactions/ConceptSelectLink.tsx +10 -6
  24. package/src/context.ts +34 -14
  25. package/src/core/__snapshots__/queries.test.ts.snap +386 -0
  26. package/src/core/__snapshots__/semanticRecommendations.test.ts.snap +10 -0
  27. package/src/core/createId.test.ts +35 -0
  28. package/src/core/filters.test.ts +64 -0
  29. package/src/core/filters.ts +68 -0
  30. package/src/core/ids.test.ts +68 -0
  31. package/src/core/ids.ts +61 -0
  32. package/src/core/mutations.test.ts +114 -0
  33. package/src/core/mutations.ts +105 -0
  34. package/src/core/ports.ts +59 -0
  35. package/src/core/queries.test.ts +50 -0
  36. package/src/{queries.ts → core/queries.ts} +7 -6
  37. package/src/core/semanticRecommendations.test.ts +160 -0
  38. package/src/core/semanticRecommendations.ts +127 -0
  39. package/src/core/tree/annotateRecommendations.test.ts +43 -0
  40. package/src/core/tree/annotateRecommendations.ts +30 -0
  41. package/src/core/tree/pruneConcepts.test.ts +77 -0
  42. package/src/core/tree/pruneConcepts.ts +72 -0
  43. package/src/core/validation.test.ts +42 -0
  44. package/src/core/validation.ts +42 -0
  45. package/src/helpers/baseIriField.ts +22 -0
  46. package/src/helpers/branchFilter.test.ts +48 -0
  47. package/src/helpers/branchFilter.ts +17 -26
  48. package/src/helpers/schemeFilter.test.ts +51 -0
  49. package/src/helpers/schemeFilter.ts +11 -23
  50. package/src/hooks/index.ts +1 -1
  51. package/src/hooks/useCreateConcept.tsx +33 -110
  52. package/src/hooks/useRemoveConcept.tsx +24 -36
  53. package/src/hooks/useSemanticRecommendations.tsx +75 -0
  54. package/src/index.test.ts +31 -0
  55. package/src/index.ts +2 -6
  56. package/src/seams/StudioDataAdapter.ts +81 -0
  57. package/src/seams/TaxonomyPortContext.tsx +33 -0
  58. package/src/skosConcept.tsx +23 -234
  59. package/src/skosConceptScheme.tsx +2 -4
  60. package/src/structure.tsx +60 -0
  61. package/src/test/FakeDataPort.test.ts +62 -0
  62. package/src/test/FakeDataPort.ts +69 -0
  63. package/src/test/inputHarness.tsx +71 -0
  64. package/src/test/renderWithUi.test.tsx +14 -0
  65. package/src/test/renderWithUi.tsx +24 -0
  66. package/src/test-setup.ts +35 -0
  67. package/src/types.tsx +30 -11
  68. package/src/views/ConceptUseView.tsx +4 -10
  69. package/lib/index.esm.d.mts +0 -492
  70. package/lib/index.esm.esm.js +0 -182
  71. package/lib/index.esm.esm.js.map +0 -1
  72. package/lib/index.esm.mjs +0 -182
  73. package/lib/index.esm.mjs.map +0 -1
  74. package/lib/index.js +0 -182
  75. package/lib/index.js.map +0 -1
  76. package/sanity.json +0 -8
  77. package/src/config.ts +0 -16
  78. package/src/helpers/baseIriField.tsx +0 -42
  79. package/src/hooks/useEmbeddingsRecs.tsx +0 -75
  80. package/src/skosConcept.module.css +0 -10
  81. package/src/structure.ts +0 -40
  82. package/v2-incompatible.js +0 -11
  83. /package/src/{helpers → core}/createId.ts +0 -0
package/sanity.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "parts": [
3
- {
4
- "implements": "part:@sanity/base/sanity-root",
5
- "path": "./v2-incompatible.js"
6
- }
7
- ]
8
- }
package/src/config.ts DELETED
@@ -1,16 +0,0 @@
1
- import type {Options} from './types'
2
-
3
- let taxonomyManagerConfig: Options | undefined
4
-
5
- /**
6
- * #### Manage Plugin Config
7
- * Store the user preferences config in a module-level
8
- * variable when the plugin initializes
9
- */
10
- export function setPluginConfig(config: Options | undefined): void {
11
- taxonomyManagerConfig = config
12
- }
13
-
14
- export function getPluginConfig(): Options | undefined {
15
- return taxonomyManagerConfig
16
- }
@@ -1,42 +0,0 @@
1
- import {defineField} from 'sanity'
2
-
3
- import {RdfUri} from '../components/inputs'
4
-
5
- import styles from './baseIriField.module.css'
6
-
7
- /**
8
- * #### Base Universal Resource Identifier object for Sanity Taxonomy Manager
9
- * Used for Concept and Concept Scheme URI fields
10
- */
11
- export default [
12
- defineField({
13
- name: 'baseIri',
14
- title: 'Base URI',
15
- type: 'url',
16
- validation: (Rule) =>
17
- Rule.required().error(`Please supply a base URI in the format 'http://example.com/'`),
18
- description: (
19
- <details className={styles.description}>
20
- <summary>
21
- The root URI (Uniform Resource Identifier) used to create unique concept identifiers.
22
- </summary>
23
- <div>
24
- Unique identifiers allow for the clear an unambiguous identification of concepts across
25
- namespaces, for example between <code>https://shipparts.com/vocab#Bow</code> and {}
26
- <code>https://wrappingsupplies.com/vocab#Bow</code>.
27
- </div>
28
- <div>
29
- In most cases, it makes sense for your base URI to be the root or a subdirectory of your
30
- website. In all cases, the URI you choose should be in a domain that you control.
31
- </div>
32
- <div>
33
- For new Concepts and Concept Schemes, the Base URI field is pre-populated based on the
34
- most recently used Base URI value.
35
- </div>
36
- </details>
37
- ),
38
- components: {
39
- input: RdfUri as any,
40
- },
41
- }),
42
- ]
@@ -1,75 +0,0 @@
1
- import {useState, useCallback} from 'react'
2
- import {useClient, useDataset, useGetFormValue} from 'sanity'
3
-
4
- import type {EmbeddingsIndexConfig, EmbeddingsResult} from '../types'
5
-
6
- /**
7
- * Queries a Sanity embeddings index using values from specified form fields.
8
- * Returns matching concept scores and any validation errors.
9
- */
10
- export function useEmbeddingsRecs(embeddingsIndex?: EmbeddingsIndexConfig) {
11
- const client = useClient({apiVersion: 'vX'})
12
- const dataset = useDataset()
13
- const getFormValue = useGetFormValue()
14
-
15
- const [conceptRecs, setConceptRecs] = useState<EmbeddingsResult[]>([])
16
- const [recsError, setRecsError] = useState<string | null>(null)
17
-
18
- const buildQueryString = useCallback(
19
- (fieldReferences: string[]): string => {
20
- const emptyFields: string[] = []
21
- const values = fieldReferences.map((fieldName) => {
22
- const val = getFormValue([fieldName])
23
- if (typeof val === 'string' && val.trim() !== '') {
24
- return val
25
- }
26
- emptyFields.push(fieldName)
27
- return ''
28
- })
29
- if (emptyFields.length === 1) {
30
- throw new Error(`Please fill out the ${emptyFields[0]} field to enable match scores.`)
31
- } else if (emptyFields.length > 1) {
32
- throw new Error(
33
- `The following fields must be filled out to enable match scores: ${emptyFields.join(
34
- ', '
35
- )}`
36
- )
37
- }
38
- return values.filter(Boolean).join(' ')
39
- },
40
- [getFormValue]
41
- )
42
-
43
- const fetchConceptRecs = useCallback(
44
- async (query: string, indexName: string, maxResults: number) => {
45
- const returnedRecs: EmbeddingsResult[] = await client.request({
46
- url: `/embeddings-index/query/${dataset}/${indexName}`,
47
- method: 'POST',
48
- body: {
49
- query,
50
- maxResults,
51
- },
52
- })
53
- setConceptRecs(returnedRecs)
54
- },
55
- [client, dataset]
56
- )
57
-
58
- const triggerEmbeddingsSearch = useCallback(() => {
59
- setRecsError(null)
60
- if (!embeddingsIndex) return
61
- const {indexName, fieldReferences, maxResults = 3} = embeddingsIndex
62
- try {
63
- const query = buildQueryString(fieldReferences)
64
- fetchConceptRecs(query, indexName, maxResults).catch((error) =>
65
- console.error('Error with embeddings index fetch: ', error)
66
- )
67
- } catch (error) {
68
- const errorMessage =
69
- error instanceof Error ? error.message : 'One or more required fields are empty'
70
- setRecsError(errorMessage)
71
- }
72
- }, [buildQueryString, embeddingsIndex, fetchConceptRecs])
73
-
74
- return {conceptRecs, recsError, triggerEmbeddingsSearch}
75
- }
@@ -1,10 +0,0 @@
1
- details.description summary {
2
- cursor: pointer;
3
- }
4
- details.description div {
5
- margin-top: 0.5rem;
6
- margin-left: 0.75rem;
7
- }
8
- details.description div svg {
9
- padding-right: 0.25rem;
10
- }
package/src/structure.ts DELETED
@@ -1,40 +0,0 @@
1
- import {EditIcon, DocumentsIcon} from '@sanity/icons'
2
- import type {StructureBuilder, ListBuilder, DefaultDocumentNodeResolver} from 'sanity/structure'
3
-
4
- import {TreeView} from './components/TreeView'
5
- import NodeTree from './static/NodeTree'
6
- import {ConceptUseView} from './views/ConceptUseView'
7
-
8
- /**
9
- * #### Default Desk Structure for Concept and Concept Scheme
10
- * Sets defaultDocumentNode. Consider exporting in the future,
11
- * if there is a use case for mixing taxonomy views in the main
12
- * desk structure.
13
- */
14
- export const structure = (S: StructureBuilder): ListBuilder =>
15
- S.list()
16
- .title('Taxonomy Manager')
17
- .items([
18
- S.documentTypeListItem('skosConceptScheme').title('Concept Schemes'),
19
- S.documentTypeListItem('skosConcept').title('Concepts'),
20
- ])
21
-
22
- // set default document node here — so that if users want concepts
23
- // and schemes elsewhere in desk, they'll get the right views.
24
- export const defaultDocumentNode: DefaultDocumentNodeResolver = (S, {schemaType}) => {
25
- // Conditionally return a different configuration based on the schema type
26
- switch (schemaType) {
27
- case 'skosConceptScheme':
28
- return S.document().views([
29
- S.view.component(TreeView).title('Tree View').icon(NodeTree),
30
- S.view.form().icon(EditIcon),
31
- ])
32
- case 'skosConcept':
33
- return S.document().views([
34
- S.view.form().icon(EditIcon),
35
- S.view.component(ConceptUseView).title('Tagged Resources').icon(DocumentsIcon),
36
- ])
37
- default:
38
- return S.document().views([S.view.form().icon(EditIcon)])
39
- }
40
- }
@@ -1,11 +0,0 @@
1
- const {showIncompatiblePluginDialog} = require('@sanity/incompatible-plugin')
2
- const {name, version, sanityExchangeUrl} = require('./package.json')
3
-
4
- export default showIncompatiblePluginDialog({
5
- name: name,
6
- versions: {
7
- v3: version,
8
- v2: '^1.0.5',
9
- },
10
- sanityExchangeUrl,
11
- })
File without changes