@sanity/assist 1.2.12 → 1.2.14
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 +47 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +47 -6
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/plugin.tsx +6 -2
- package/src/schemas/index.ts +45 -6
- package/src/schemas/serialize/serializeSchema.test.ts +15 -2
- package/src/schemas/serialize/serializeSchema.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/assist",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -64,18 +64,18 @@
|
|
|
64
64
|
"rxjs-exhaustmap-with-trailing": "^2.1.1"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@commitlint/cli": "^17.
|
|
68
|
-
"@commitlint/config-conventional": "^17.
|
|
67
|
+
"@commitlint/cli": "^17.8.1",
|
|
68
|
+
"@commitlint/config-conventional": "^17.8.1",
|
|
69
69
|
"@rollup/plugin-image": "^3.0.3",
|
|
70
70
|
"@sanity/pkg-utils": "^2.4.10",
|
|
71
71
|
"@sanity/plugin-kit": "^3.1.10",
|
|
72
|
-
"@sanity/semantic-release-preset": "^4.1.
|
|
73
|
-
"@types/react": "^18.2.
|
|
74
|
-
"@types/styled-components": "^5.1.
|
|
72
|
+
"@sanity/semantic-release-preset": "^4.1.6",
|
|
73
|
+
"@types/react": "^18.2.37",
|
|
74
|
+
"@types/styled-components": "^5.1.30",
|
|
75
75
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
76
76
|
"@typescript-eslint/parser": "^5.62.0",
|
|
77
77
|
"date-fns": "^2.30.0",
|
|
78
|
-
"eslint": "^8.
|
|
78
|
+
"eslint": "^8.53.0",
|
|
79
79
|
"eslint-config-prettier": "^8.10.0",
|
|
80
80
|
"eslint-config-sanity": "^6.0.0",
|
|
81
81
|
"eslint-plugin-prettier": "^4.2.1",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"react": "^18.2.0",
|
|
86
86
|
"react-dom": "^18.2.0",
|
|
87
87
|
"rimraf": "^4.4.0",
|
|
88
|
-
"sanity": "^3.
|
|
88
|
+
"sanity": "^3.19.3",
|
|
89
89
|
"semantic-release": "^21.1.2",
|
|
90
90
|
"styled-components": "^5.3.11",
|
|
91
91
|
"typescript": "^5.2.2",
|
package/src/plugin.tsx
CHANGED
|
@@ -45,8 +45,12 @@ export const assist = definePlugin<AssistPluginConfig | void>((config) => {
|
|
|
45
45
|
}
|
|
46
46
|
return prev
|
|
47
47
|
},
|
|
48
|
-
unstable_fieldActions: (prev) => {
|
|
49
|
-
|
|
48
|
+
unstable_fieldActions: (prev, {documentType, schema}) => {
|
|
49
|
+
const docSchema = schema.get(documentType)
|
|
50
|
+
if (docSchema && isSchemaAssistEnabled(docSchema)) {
|
|
51
|
+
return [...prev, assistFieldActions]
|
|
52
|
+
}
|
|
53
|
+
return prev
|
|
50
54
|
},
|
|
51
55
|
unstable_languageFilter: (prev, {documentId, schema, schemaType}) => {
|
|
52
56
|
const docSchema = schema.get(schemaType)
|
package/src/schemas/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
1
2
|
import {
|
|
2
3
|
assistDocumentSchema,
|
|
3
4
|
documentInstructionStatus,
|
|
@@ -10,16 +11,54 @@ import {
|
|
|
10
11
|
userInput,
|
|
11
12
|
} from './assistDocumentSchema'
|
|
12
13
|
import {contextDocumentSchema} from './contextDocumentSchema'
|
|
14
|
+
import {FieldProps, SchemaTypeDefinition, ArrayOfType} from 'sanity'
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
function excludeComments<T extends SchemaTypeDefinition | ArrayOfType>(type: T): T {
|
|
17
|
+
const existingRender = (type as any)?.components?.field
|
|
18
|
+
return {
|
|
19
|
+
...type,
|
|
20
|
+
...('components' in type
|
|
21
|
+
? {
|
|
22
|
+
components: {
|
|
23
|
+
...type.components,
|
|
24
|
+
field: (props: FieldProps) => {
|
|
25
|
+
const newProps = {...props, ...{__internal_comments: undefined}}
|
|
26
|
+
if (typeof existingRender === 'function') {
|
|
27
|
+
return existingRender(newProps)
|
|
28
|
+
}
|
|
29
|
+
return props.renderDefault(newProps)
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
: {}),
|
|
34
|
+
...('fields' in type
|
|
35
|
+
? {
|
|
36
|
+
// recursively disable comments in fields
|
|
37
|
+
fields: type.fields?.map((field) => excludeComments(field)),
|
|
38
|
+
}
|
|
39
|
+
: {}),
|
|
40
|
+
...('of' in type
|
|
41
|
+
? {
|
|
42
|
+
// recursively disable comments in array items
|
|
43
|
+
of: type.of?.map((arrayItemType) => excludeComments(arrayItemType)),
|
|
44
|
+
}
|
|
45
|
+
: {}),
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const instructionForm = [
|
|
15
50
|
fieldInstructions,
|
|
16
|
-
assistDocumentSchema,
|
|
17
|
-
prompt,
|
|
18
|
-
fieldReference,
|
|
19
51
|
instruction,
|
|
52
|
+
fieldReference,
|
|
53
|
+
prompt,
|
|
54
|
+
userInput,
|
|
55
|
+
promptContext,
|
|
56
|
+
].map(excludeComments)
|
|
57
|
+
|
|
58
|
+
export const schemaTypes = [
|
|
59
|
+
...instructionForm,
|
|
60
|
+
assistDocumentSchema,
|
|
20
61
|
documentInstructionStatus,
|
|
21
62
|
instructionTask,
|
|
22
63
|
contextDocumentSchema,
|
|
23
|
-
userInput,
|
|
24
|
-
promptContext,
|
|
25
64
|
]
|
|
@@ -23,7 +23,7 @@ const mockStudioTypes = [
|
|
|
23
23
|
]
|
|
24
24
|
|
|
25
25
|
describe('serializeSchema', () => {
|
|
26
|
-
test('should
|
|
26
|
+
test('should serialize excluded document schema to support exclude: false overrides at the field level', () => {
|
|
27
27
|
const schema = Schema.compile({
|
|
28
28
|
name: 'test',
|
|
29
29
|
types: [
|
|
@@ -42,7 +42,20 @@ describe('serializeSchema', () => {
|
|
|
42
42
|
|
|
43
43
|
const serializedTypes = serializeSchema(schema, {leanFormat: true})
|
|
44
44
|
|
|
45
|
-
expect(serializedTypes).toEqual([
|
|
45
|
+
expect(serializedTypes).toEqual([
|
|
46
|
+
{
|
|
47
|
+
fields: [
|
|
48
|
+
{
|
|
49
|
+
name: 'title',
|
|
50
|
+
title: 'Title',
|
|
51
|
+
type: 'string',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
name: 'article',
|
|
55
|
+
title: 'Article',
|
|
56
|
+
type: 'document',
|
|
57
|
+
},
|
|
58
|
+
])
|
|
46
59
|
})
|
|
47
60
|
|
|
48
61
|
test('should serialize simple schema', () => {
|
|
@@ -29,7 +29,8 @@ 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
|
-
|
|
32
|
+
// because a field can override exclude at the type level, we have to also serialize excluded types
|
|
33
|
+
// so don't do this: .filter((t) => isAssistSupported(t))
|
|
33
34
|
.filter((t) => !t.hidden && !t.readOnly)
|
|
34
35
|
.map((t) => getSchemaStub(t, schema, options))
|
|
35
36
|
.filter((t) => {
|