@sanity/assist 1.2.6 → 1.2.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/assist",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "sanity",
@@ -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 = useAssistSupported(props.path, schemaType) && isSelectable
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
@@ -50,7 +50,10 @@ export const assist = definePlugin<AssistPluginConfig | void>((config) => {
50
50
  },
51
51
  unstable_languageFilter: (prev, {documentId, schema, schemaType}) => {
52
52
  const docSchema = schema.get(schemaType) as ObjectSchemaType
53
- return [...prev, createAssistDocumentPresence(documentId, docSchema)]
53
+ if (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',
@@ -422,6 +444,33 @@ describe('serializeSchema', () => {
422
444
  ])
423
445
  })
424
446
 
447
+ test('should not try to serialize list values if list values are not an array', () => {
448
+ const schema = Schema.compile({
449
+ name: 'test',
450
+ types: [
451
+ defineType({
452
+ type: 'array',
453
+ name: 'list',
454
+ of: [{type: 'string'}],
455
+ options: {
456
+ list: new Promise(() => {}) as any, // Type usually only accepts array, but some plugins might use other types
457
+ },
458
+ }),
459
+ ],
460
+ })
461
+
462
+ const serializedTypes = serializeSchema(schema, {leanFormat: true})
463
+
464
+ expect(serializedTypes).toEqual([
465
+ {
466
+ name: 'list',
467
+ type: 'array',
468
+ of: [{type: 'string', name: 'string', title: 'String'}],
469
+ values: undefined,
470
+ },
471
+ ])
472
+ })
473
+
425
474
  test('should exclude truthy hidden and readonly', () => {
426
475
  const schema = Schema.compile({
427
476
  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) => {
@@ -83,7 +84,7 @@ function getBaseFields(
83
84
  imagePromptField: imagePromptField,
84
85
  }
85
86
  : undefined,
86
- values: type?.options?.list
87
+ values: Array.isArray(type?.options?.list)
87
88
  ? type?.options?.list.map((v: string | {value: string; title: string}) =>
88
89
  typeof v === 'string' ? v : v.value ?? `${v.title}`
89
90
  )