@sanity/assist 1.2.7 → 1.2.9
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.esm.js +6 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/fieldActions/assistFieldActions.tsx +5 -1
- package/src/plugin.tsx +6 -3
- package/src/schemas/serialize/serializeSchema.test.ts +22 -0
- package/src/schemas/serialize/serializeSchema.ts +1 -0
package/package.json
CHANGED
|
@@ -23,6 +23,7 @@ import {PrivateIcon} from './PrivateIcon'
|
|
|
23
23
|
import {generateCaptionsActions} from './generateCaptionActions'
|
|
24
24
|
import {useDocumentPane} from 'sanity/desk'
|
|
25
25
|
import {useSelectedField, useTypePath} from '../assistInspector/helpers'
|
|
26
|
+
import {isSchemaAssistEnabled} from '../helpers/assistSupported'
|
|
26
27
|
|
|
27
28
|
function node(node: DocumentFieldActionItem | DocumentFieldActionGroup) {
|
|
28
29
|
return node
|
|
@@ -69,7 +70,10 @@ export const assistFieldActions: DocumentFieldAction = {
|
|
|
69
70
|
})
|
|
70
71
|
|
|
71
72
|
const isSelectable = !!useSelectedField(documentSchemaType, typePath)
|
|
72
|
-
const assistSupported =
|
|
73
|
+
const assistSupported =
|
|
74
|
+
useAssistSupported(props.path, schemaType) &&
|
|
75
|
+
isSelectable &&
|
|
76
|
+
isSchemaAssistEnabled(documentSchemaType)
|
|
73
77
|
|
|
74
78
|
const fieldAssist = useMemo(
|
|
75
79
|
() =>
|
package/src/plugin.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {definePlugin,
|
|
1
|
+
import {definePlugin, isObjectSchemaType} from 'sanity'
|
|
2
2
|
import {assistInspector} from './assistInspector'
|
|
3
3
|
import {AssistFieldWrapper} from './assistFormComponents/AssistField'
|
|
4
4
|
import {AssistLayout} from './assistLayout/AssistLayout'
|
|
@@ -49,8 +49,11 @@ export const assist = definePlugin<AssistPluginConfig | void>((config) => {
|
|
|
49
49
|
return [...prev, assistFieldActions]
|
|
50
50
|
},
|
|
51
51
|
unstable_languageFilter: (prev, {documentId, schema, schemaType}) => {
|
|
52
|
-
const docSchema = schema.get(schemaType)
|
|
53
|
-
|
|
52
|
+
const docSchema = schema.get(schemaType)
|
|
53
|
+
if (docSchema && isObjectSchemaType(docSchema) && isSchemaAssistEnabled(docSchema)) {
|
|
54
|
+
return [...prev, createAssistDocumentPresence(documentId, docSchema)]
|
|
55
|
+
}
|
|
56
|
+
return prev
|
|
54
57
|
},
|
|
55
58
|
},
|
|
56
59
|
|
|
@@ -23,6 +23,28 @@ const mockStudioTypes = [
|
|
|
23
23
|
]
|
|
24
24
|
|
|
25
25
|
describe('serializeSchema', () => {
|
|
26
|
+
test('should not serialize excluded document schema', () => {
|
|
27
|
+
const schema = Schema.compile({
|
|
28
|
+
name: 'test',
|
|
29
|
+
types: [
|
|
30
|
+
defineType({
|
|
31
|
+
type: 'document',
|
|
32
|
+
name: 'article',
|
|
33
|
+
fields: [{type: 'string', name: 'title'}],
|
|
34
|
+
options: {
|
|
35
|
+
aiWritingAssistance: {
|
|
36
|
+
exclude: true,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const serializedTypes = serializeSchema(schema, {leanFormat: true})
|
|
44
|
+
|
|
45
|
+
expect(serializedTypes).toEqual([])
|
|
46
|
+
})
|
|
47
|
+
|
|
26
48
|
test('should serialize simple schema', () => {
|
|
27
49
|
const schema = Schema.compile({
|
|
28
50
|
name: 'test',
|
|
@@ -29,6 +29,7 @@ export function serializeSchema(schema: Schema, options?: Options): SerializedSc
|
|
|
29
29
|
.filter((t) => !(hiddenTypes.includes(t) || t.startsWith('sanity.')))
|
|
30
30
|
.map((t) => schema.get(t))
|
|
31
31
|
.filter((t): t is SchemaType => !!t)
|
|
32
|
+
.filter((t) => isAssistSupported(t))
|
|
32
33
|
.filter((t) => !t.hidden && !t.readOnly)
|
|
33
34
|
.map((t) => getSchemaStub(t, schema, options))
|
|
34
35
|
.filter((t) => {
|