@sanity/assist 5.0.4 → 6.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.
- package/LICENSE +1 -1
- package/README.md +28 -254
- package/dist/index.d.ts +322 -410
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3181 -2649
- package/dist/index.js.map +1 -1
- package/package.json +38 -78
- package/dist/index.cjs +0 -4239
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -791
- package/sanity.json +0 -8
- package/src/_lib/connector/ConnectFromRegion.tsx +0 -25
- package/src/_lib/connector/ConnectToRegion.tsx +0 -23
- package/src/_lib/connector/ConnectorRegion.tsx +0 -24
- package/src/_lib/connector/ConnectorsProvider.tsx +0 -20
- package/src/_lib/connector/ConnectorsStore.ts +0 -122
- package/src/_lib/connector/ConnectorsStoreContext.ts +0 -5
- package/src/_lib/connector/helpers.ts +0 -5
- package/src/_lib/connector/index.ts +0 -9
- package/src/_lib/connector/mapConnectorToLine.ts +0 -83
- package/src/_lib/connector/types.ts +0 -56
- package/src/_lib/connector/useConnectorsStore.ts +0 -14
- package/src/_lib/connector/useRegionRects.ts +0 -142
- package/src/_lib/fixedListenQuery.ts +0 -101
- package/src/_lib/form/DocumentForm.tsx +0 -201
- package/src/_lib/form/constants.ts +0 -1
- package/src/_lib/form/helpers.ts +0 -32
- package/src/_lib/form/index.ts +0 -1
- package/src/_lib/randomKey.ts +0 -29
- package/src/_lib/useListeningQuery.ts +0 -62
- package/src/_lib/usePrevious.ts +0 -9
- package/src/assistConnectors/AssistConnectorsOverlay.tsx +0 -133
- package/src/assistConnectors/ConnectorPath.tsx +0 -63
- package/src/assistConnectors/draw/arrowPath.ts +0 -9
- package/src/assistConnectors/draw/connectorPath.ts +0 -142
- package/src/assistConnectors/index.ts +0 -1
- package/src/assistDocument/AssistDocumentContext.tsx +0 -51
- package/src/assistDocument/AssistDocumentContextProvider.tsx +0 -17
- package/src/assistDocument/AssistDocumentInput.tsx +0 -61
- package/src/assistDocument/AssistDocumentLayout.tsx +0 -12
- package/src/assistDocument/RequestRunInstructionProvider.tsx +0 -61
- package/src/assistDocument/components/AssistDocumentForm.tsx +0 -287
- package/src/assistDocument/components/AssistTypeContext.tsx +0 -7
- package/src/assistDocument/components/FieldRefPreview.tsx +0 -26
- package/src/assistDocument/components/InstructionsArrayField.tsx +0 -8
- package/src/assistDocument/components/InstructionsArrayInput.tsx +0 -27
- package/src/assistDocument/components/SelectedFieldContext.tsx +0 -10
- package/src/assistDocument/components/generic/HiddenFieldTitle.tsx +0 -5
- package/src/assistDocument/components/helpers.ts +0 -21
- package/src/assistDocument/components/instruction/BackToInstructionsLink.tsx +0 -32
- package/src/assistDocument/components/instruction/FieldRefInput.tsx +0 -54
- package/src/assistDocument/components/instruction/InstructionInput.tsx +0 -89
- package/src/assistDocument/components/instruction/InstructionOutputField.tsx +0 -46
- package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +0 -206
- package/src/assistDocument/components/instruction/PromptInput.tsx +0 -59
- package/src/assistDocument/components/instruction/appearance/IconInput.tsx +0 -46
- package/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx +0 -37
- package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +0 -127
- package/src/assistDocument/hooks/useDocumentState.ts +0 -6
- package/src/assistDocument/hooks/useInstructionToaster.tsx +0 -75
- package/src/assistDocument/hooks/useStudioAssistDocument.ts +0 -99
- package/src/assistDocument/index.ts +0 -1
- package/src/assistFormComponents/AssistField.tsx +0 -63
- package/src/assistFormComponents/AssistFormBlock.tsx +0 -31
- package/src/assistFormComponents/AssistInlineFormBlock.tsx +0 -13
- package/src/assistFormComponents/AssistItem.tsx +0 -21
- package/src/assistFormComponents/validation/listItem.tsx +0 -63
- package/src/assistFormComponents/validation/validationList.tsx +0 -90
- package/src/assistInspector/AssistInspector.tsx +0 -419
- package/src/assistInspector/FieldAutocomplete.tsx +0 -146
- package/src/assistInspector/InstructionTaskHistoryButton.tsx +0 -262
- package/src/assistInspector/constants.ts +0 -1
- package/src/assistInspector/helpers.ts +0 -211
- package/src/assistInspector/index.ts +0 -27
- package/src/assistLayout/AiAssistanceConfigContext.tsx +0 -32
- package/src/assistLayout/AiAssistanceConfigProvider.tsx +0 -98
- package/src/assistLayout/AssistLayout.tsx +0 -39
- package/src/assistLayout/RunInstructionProvider.tsx +0 -278
- package/src/assistLayout/fieldRefCache.tsx +0 -34
- package/src/assistTypes.ts +0 -83
- package/src/components/AssistFeatureBadge.tsx +0 -9
- package/src/components/FadeInContent.tsx +0 -40
- package/src/components/HideReferenceChangedBannerInput.tsx +0 -25
- package/src/components/ImageContext.tsx +0 -85
- package/src/components/SafeValueInput.tsx +0 -74
- package/src/components/TimeAgo.tsx +0 -18
- package/src/constants.ts +0 -20
- package/src/fieldActions/PrivateIcon.tsx +0 -20
- package/src/fieldActions/assistFieldActions.tsx +0 -320
- package/src/fieldActions/customFieldActions.tsx +0 -333
- package/src/fieldActions/generateCaptionActions.tsx +0 -77
- package/src/fieldActions/generateImageActions.tsx +0 -58
- package/src/fieldActions/useUserInput.ts +0 -107
- package/src/globals.d.ts +0 -4
- package/src/helpers/assistSupported.ts +0 -49
- package/src/helpers/conditionalMembers.test.ts +0 -319
- package/src/helpers/conditionalMembers.ts +0 -134
- package/src/helpers/ids.test.ts +0 -28
- package/src/helpers/ids.ts +0 -23
- package/src/helpers/misc.ts +0 -25
- package/src/helpers/styleguide.ts +0 -24
- package/src/helpers/typeUtils.ts +0 -60
- package/src/helpers/useAssistSupported.ts +0 -8
- package/src/index.ts +0 -26
- package/src/onboarding/FirstAssistedPathProvider.tsx +0 -30
- package/src/onboarding/InspectorOnboarding.tsx +0 -47
- package/src/onboarding/onboardingStore.ts +0 -32
- package/src/plugin.tsx +0 -162
- package/src/presence/AiFieldPresence.tsx +0 -28
- package/src/presence/AssistAvatar.tsx +0 -96
- package/src/presence/AssistDocumentPresence.tsx +0 -50
- package/src/presence/useAssistPresence.ts +0 -64
- package/src/schemas/assistDocumentSchema.tsx +0 -497
- package/src/schemas/contextDocumentSchema.tsx +0 -57
- package/src/schemas/index.ts +0 -69
- package/src/schemas/serialize/SchemTypeTool.tsx +0 -103
- package/src/schemas/serialize/schemaUtils.ts +0 -38
- package/src/schemas/serialize/serializeSchema.test.ts +0 -819
- package/src/schemas/serialize/serializeSchema.ts +0 -224
- package/src/schemas/serializedSchemaTypeSchema.ts +0 -60
- package/src/schemas/typeDefExtensions.ts +0 -127
- package/src/translate/FieldTranslationProvider.tsx +0 -382
- package/src/translate/getLanguageParams.ts +0 -26
- package/src/translate/languageStore.ts +0 -18
- package/src/translate/paths.test.ts +0 -181
- package/src/translate/paths.ts +0 -183
- package/src/translate/translateActions.tsx +0 -205
- package/src/translate/types.ts +0 -197
- package/src/types.ts +0 -220
- package/src/useApiClient.ts +0 -338
- package/v2-incompatible.js +0 -11
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import {ImageIcon} from '@sanity/icons'
|
|
2
|
-
import {Box, Spinner} from '@sanity/ui'
|
|
3
|
-
import {useContext, useMemo} from 'react'
|
|
4
|
-
import type {DocumentFieldAction, DocumentFieldActionGroup, DocumentFieldActionItem} from 'sanity'
|
|
5
|
-
import {useDocumentPane} from 'sanity/structure'
|
|
6
|
-
|
|
7
|
-
import {useAssistDocumentContext} from '../assistDocument/AssistDocumentContext'
|
|
8
|
-
import {aiInspectorId} from '../assistInspector/constants'
|
|
9
|
-
import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
|
|
10
|
-
import {ImageContext} from '../components/ImageContext'
|
|
11
|
-
import {usePathKey} from '../helpers/misc'
|
|
12
|
-
import {fieldPathParam, instructionParam} from '../types'
|
|
13
|
-
import {canUseAssist, useApiClient, useGenerateCaption} from '../useApiClient'
|
|
14
|
-
|
|
15
|
-
function node(node: DocumentFieldActionItem | DocumentFieldActionGroup) {
|
|
16
|
-
return node
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const generateCaptionsActions: DocumentFieldAction = {
|
|
20
|
-
name: 'sanity-assist-generate-captions',
|
|
21
|
-
useAction(props) {
|
|
22
|
-
const pathKey = usePathKey(props.path)
|
|
23
|
-
const {openInspector} = useDocumentPane()
|
|
24
|
-
|
|
25
|
-
const {config, status} = useAiAssistanceConfig()
|
|
26
|
-
const apiClient = useApiClient(config?.__customApiClient)
|
|
27
|
-
const {generateCaption, loading} = useGenerateCaption(apiClient)
|
|
28
|
-
const imageContext = useContext(ImageContext)
|
|
29
|
-
|
|
30
|
-
if (imageContext && pathKey === imageContext?.imageDescriptionPath) {
|
|
31
|
-
//if this is true, it is stable, and not breaking rules of hooks
|
|
32
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
33
|
-
const {assistableDocumentId} = useAssistDocumentContext()
|
|
34
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
35
|
-
return useMemo(() => {
|
|
36
|
-
return node({
|
|
37
|
-
type: 'action',
|
|
38
|
-
icon: loading
|
|
39
|
-
? () => (
|
|
40
|
-
<Box style={{height: 17}}>
|
|
41
|
-
<Spinner style={{transform: 'translateY(6px)'}} />
|
|
42
|
-
</Box>
|
|
43
|
-
)
|
|
44
|
-
: ImageIcon,
|
|
45
|
-
title: 'Generate image description',
|
|
46
|
-
onAction: () => {
|
|
47
|
-
if (loading) {
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
if (!canUseAssist(status)) {
|
|
51
|
-
openInspector(aiInspectorId, {
|
|
52
|
-
[fieldPathParam]: pathKey,
|
|
53
|
-
[instructionParam]: undefined as any,
|
|
54
|
-
})
|
|
55
|
-
return
|
|
56
|
-
}
|
|
57
|
-
generateCaption({path: pathKey, documentId: assistableDocumentId})
|
|
58
|
-
},
|
|
59
|
-
renderAsButton: true,
|
|
60
|
-
disabled: loading,
|
|
61
|
-
hidden: !imageContext.assetRef,
|
|
62
|
-
})
|
|
63
|
-
}, [
|
|
64
|
-
generateCaption,
|
|
65
|
-
pathKey,
|
|
66
|
-
assistableDocumentId,
|
|
67
|
-
loading,
|
|
68
|
-
imageContext,
|
|
69
|
-
status,
|
|
70
|
-
openInspector,
|
|
71
|
-
])
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// works but not supported by types
|
|
75
|
-
return undefined as unknown as DocumentFieldActionItem
|
|
76
|
-
},
|
|
77
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {ImageIcon} from '@sanity/icons'
|
|
2
|
-
import {Box, Spinner} from '@sanity/ui'
|
|
3
|
-
import {useContext, useMemo} from 'react'
|
|
4
|
-
import {DocumentFieldAction, DocumentFieldActionGroup, DocumentFieldActionItem} from 'sanity'
|
|
5
|
-
|
|
6
|
-
import {useAssistDocumentContext} from '../assistDocument/AssistDocumentContext'
|
|
7
|
-
import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
|
|
8
|
-
import {ImageContext} from '../components/ImageContext'
|
|
9
|
-
import {usePathKey} from '../helpers/misc'
|
|
10
|
-
import {useApiClient, useGenerateImage} from '../useApiClient'
|
|
11
|
-
|
|
12
|
-
function node(node: DocumentFieldActionItem | DocumentFieldActionGroup) {
|
|
13
|
-
return node
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const generateImagActions: DocumentFieldAction = {
|
|
17
|
-
name: 'sanity-assist-generate-image',
|
|
18
|
-
useAction(props) {
|
|
19
|
-
const pathKey = usePathKey(props.path)
|
|
20
|
-
|
|
21
|
-
const {config} = useAiAssistanceConfig()
|
|
22
|
-
const apiClient = useApiClient(config?.__customApiClient)
|
|
23
|
-
const {generateImage, loading} = useGenerateImage(apiClient)
|
|
24
|
-
|
|
25
|
-
const imageContext = useContext(ImageContext)
|
|
26
|
-
|
|
27
|
-
if (imageContext && pathKey === imageContext?.imageInstructionPath) {
|
|
28
|
-
//if this is true, it is stable, and not breaking rules of hooks
|
|
29
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
30
|
-
const {assistableDocumentId} = useAssistDocumentContext()
|
|
31
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
32
|
-
return useMemo(() => {
|
|
33
|
-
return node({
|
|
34
|
-
type: 'action',
|
|
35
|
-
icon: loading
|
|
36
|
-
? () => (
|
|
37
|
-
<Box style={{height: 17}}>
|
|
38
|
-
<Spinner style={{transform: 'translateY(6px)'}} />
|
|
39
|
-
</Box>
|
|
40
|
-
)
|
|
41
|
-
: ImageIcon,
|
|
42
|
-
title: 'Generate image from prompt',
|
|
43
|
-
onAction: () => {
|
|
44
|
-
if (loading) {
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
generateImage({path: pathKey, documentId: assistableDocumentId})
|
|
48
|
-
},
|
|
49
|
-
renderAsButton: true,
|
|
50
|
-
disabled: loading,
|
|
51
|
-
})
|
|
52
|
-
}, [generateImage, pathKey, assistableDocumentId, loading])
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// works but not supported by types
|
|
56
|
-
return undefined as unknown as DocumentFieldActionItem
|
|
57
|
-
},
|
|
58
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import {useRunInstruction} from '../assistLayout/RunInstructionProvider'
|
|
2
|
-
|
|
3
|
-
export type GetUserInput = (args: {
|
|
4
|
-
/**
|
|
5
|
-
* Dialog title
|
|
6
|
-
*/
|
|
7
|
-
title: string
|
|
8
|
-
/**
|
|
9
|
-
* One titled input per array item
|
|
10
|
-
*/
|
|
11
|
-
inputs: CustomInput[]
|
|
12
|
-
}) => Promise<CustomInputResult[] | undefined>
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
export interface CustomInput {
|
|
18
|
-
/**
|
|
19
|
-
* Id for the input
|
|
20
|
-
*/
|
|
21
|
-
id: string
|
|
22
|
-
/**
|
|
23
|
-
* Title of the input field
|
|
24
|
-
*/
|
|
25
|
-
title: string
|
|
26
|
-
/**
|
|
27
|
-
* Additional info that will be displayed over the input
|
|
28
|
-
*/
|
|
29
|
-
description?: string
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type CustomInputResult = {
|
|
33
|
-
/**
|
|
34
|
-
* Identifies which custom input the `result`belongs to
|
|
35
|
-
*/
|
|
36
|
-
input: CustomInput
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The text provided by the user in the input
|
|
40
|
-
*/
|
|
41
|
-
result: string
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* `useUserInput` returns a function that can be used to await user input.
|
|
46
|
-
*
|
|
47
|
-
* Useful for custom `fieldActions` to get user input for populating Agent Action requests,.
|
|
48
|
-
*
|
|
49
|
-
* ```ts
|
|
50
|
-
* fieldActions: {
|
|
51
|
-
* useFieldActions: (props) => {
|
|
52
|
-
* const {
|
|
53
|
-
* documentSchemaType,
|
|
54
|
-
* schemaId,
|
|
55
|
-
* getDocumentValue,
|
|
56
|
-
* getConditionalPaths,
|
|
57
|
-
* documentIdForAction,
|
|
58
|
-
* } = props
|
|
59
|
-
* const client = useClient({apiVersion: 'vX'})
|
|
60
|
-
* const getUserInput = useUserInput()
|
|
61
|
-
* return useMemo(() => {
|
|
62
|
-
* return [
|
|
63
|
-
* defineAssistFieldAction({
|
|
64
|
-
* title: 'Log user input',
|
|
65
|
-
* icon: UserIcon,
|
|
66
|
-
* onAction: async () => {
|
|
67
|
-
* const input = await getUserInput({
|
|
68
|
-
* title: 'Topic',
|
|
69
|
-
* inputs: [{id: 'about', title: 'What should the article be about?'}],
|
|
70
|
-
* })
|
|
71
|
-
* if (!input) return // user canceled input
|
|
72
|
-
* await client.agent.action.generate({
|
|
73
|
-
* schemaId,
|
|
74
|
-
* targetDocument: {
|
|
75
|
-
* operation: 'createIfNotExists',
|
|
76
|
-
* _id: documentIdForAction,
|
|
77
|
-
* _type: documentSchemaType.name,
|
|
78
|
-
* initialValues: getDocumentValue(),
|
|
79
|
-
* },
|
|
80
|
-
* instruction: `
|
|
81
|
-
* Create a document about the following topic:
|
|
82
|
-
* $about
|
|
83
|
-
* ---
|
|
84
|
-
* `,
|
|
85
|
-
* instructionParams: {about: input[0].result},
|
|
86
|
-
* conditionalPaths: {paths: getConditionalPaths()},
|
|
87
|
-
* })
|
|
88
|
-
* },
|
|
89
|
-
* }),
|
|
90
|
-
* ]
|
|
91
|
-
* }, [
|
|
92
|
-
* client,
|
|
93
|
-
* documentSchemaType,
|
|
94
|
-
* schemaId,
|
|
95
|
-
* getDocumentValue,
|
|
96
|
-
* getConditionalPaths,
|
|
97
|
-
* documentIdForAction,
|
|
98
|
-
* getUserInput,
|
|
99
|
-
* ])
|
|
100
|
-
* },
|
|
101
|
-
* }
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
export function useUserInput(): GetUserInput {
|
|
105
|
-
const {getUserInput} = useRunInstruction()
|
|
106
|
-
return getUserInput
|
|
107
|
-
}
|
package/src/globals.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {ReferenceOptions, SchemaType} from 'sanity'
|
|
2
|
-
|
|
3
|
-
import {AssistOptions} from '../schemas/typeDefExtensions'
|
|
4
|
-
import {isType} from './typeUtils'
|
|
5
|
-
|
|
6
|
-
export function isSchemaAssistEnabled(type: SchemaType) {
|
|
7
|
-
return !(type.options as AssistOptions | undefined)?.aiAssist?.exclude
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function isAssistSupported(type: SchemaType) {
|
|
11
|
-
if (!isSchemaAssistEnabled(type)) {
|
|
12
|
-
return false
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (isDisabled(type)) {
|
|
16
|
-
return false
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (type.jsonType === 'array') {
|
|
20
|
-
const unsupportedArray = type.of.every((t) => isDisabled(t))
|
|
21
|
-
return !unsupportedArray
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (type.jsonType === 'object') {
|
|
25
|
-
const unsupportedObject = type.fields.every((field) => isDisabled(field.type))
|
|
26
|
-
return (
|
|
27
|
-
!unsupportedObject ||
|
|
28
|
-
/* to allow attaching custom actions on fieldless images */
|
|
29
|
-
isType(type, 'image')
|
|
30
|
-
)
|
|
31
|
-
}
|
|
32
|
-
return true
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function isDisabled(type: SchemaType) {
|
|
36
|
-
return !isSchemaAssistEnabled(type) || isUnsupportedType(type)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function isUnsupportedType(type: SchemaType) {
|
|
40
|
-
return (
|
|
41
|
-
type.name === 'sanity.imageCrop' ||
|
|
42
|
-
type.name === 'sanity.imageHotspot' ||
|
|
43
|
-
isType(type, 'globalDocumentReference') ||
|
|
44
|
-
(isType(type, 'reference') &&
|
|
45
|
-
!(type?.options as ReferenceOptions)?.aiAssist?.embeddingsIndex) ||
|
|
46
|
-
isType(type, 'crossDatasetReference') ||
|
|
47
|
-
isType(type, 'file')
|
|
48
|
-
)
|
|
49
|
-
}
|
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
import {Schema} from '@sanity/schema'
|
|
2
|
-
import {ArraySchemaType, defineField, defineType, ObjectSchemaType} from 'sanity'
|
|
3
|
-
import {describe, expect, test} from 'vitest'
|
|
4
|
-
|
|
5
|
-
import {getConditionalMembers} from './conditionalMembers'
|
|
6
|
-
|
|
7
|
-
describe('conditionalMembers', () => {
|
|
8
|
-
test('should not include paths without conditional hidden/readonly', () => {
|
|
9
|
-
const docSchema: ObjectSchemaType = Schema.compile({
|
|
10
|
-
name: 'test',
|
|
11
|
-
types: [
|
|
12
|
-
defineType({
|
|
13
|
-
type: 'document',
|
|
14
|
-
name: 'article',
|
|
15
|
-
fields: [{type: 'string', name: 'title'}],
|
|
16
|
-
}),
|
|
17
|
-
],
|
|
18
|
-
}).get('article')
|
|
19
|
-
|
|
20
|
-
const docState = {
|
|
21
|
-
path: [],
|
|
22
|
-
schemaType: docSchema,
|
|
23
|
-
members: [
|
|
24
|
-
{
|
|
25
|
-
kind: 'field',
|
|
26
|
-
field: {path: [docSchema.fields[0].name], schemaType: docSchema.fields[0].type},
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
} as any
|
|
30
|
-
const conditionalMembers = getConditionalMembers(docState)
|
|
31
|
-
|
|
32
|
-
expect(conditionalMembers).toEqual([])
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
test('should include path with conditional readonly', () => {
|
|
36
|
-
const docSchema: ObjectSchemaType = Schema.compile({
|
|
37
|
-
name: 'test',
|
|
38
|
-
types: [
|
|
39
|
-
defineType({
|
|
40
|
-
type: 'document',
|
|
41
|
-
name: 'article',
|
|
42
|
-
fields: [{type: 'string', name: 'title', readOnly: () => false}],
|
|
43
|
-
}),
|
|
44
|
-
],
|
|
45
|
-
}).get('article')
|
|
46
|
-
|
|
47
|
-
const docState = {
|
|
48
|
-
path: [],
|
|
49
|
-
schemaType: docSchema,
|
|
50
|
-
members: [
|
|
51
|
-
{
|
|
52
|
-
kind: 'field',
|
|
53
|
-
field: {path: [docSchema.fields[0].name], schemaType: docSchema.fields[0].type},
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
} as any
|
|
57
|
-
const conditionalMembers = getConditionalMembers(docState)
|
|
58
|
-
|
|
59
|
-
expect(conditionalMembers).toEqual([{path: 'title', hidden: false, readOnly: false}])
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
test('regression test: should include document path with conditional readonly and no hidden', () => {
|
|
63
|
-
const docSchema: ObjectSchemaType = Schema.compile({
|
|
64
|
-
name: 'test',
|
|
65
|
-
types: [
|
|
66
|
-
defineType({
|
|
67
|
-
type: 'document',
|
|
68
|
-
name: 'article',
|
|
69
|
-
readOnly: () => false,
|
|
70
|
-
fields: [{type: 'string', name: 'title'}],
|
|
71
|
-
}),
|
|
72
|
-
],
|
|
73
|
-
}).get('article')
|
|
74
|
-
|
|
75
|
-
const docState = {
|
|
76
|
-
path: [],
|
|
77
|
-
schemaType: docSchema,
|
|
78
|
-
members: [
|
|
79
|
-
{
|
|
80
|
-
kind: 'field',
|
|
81
|
-
field: {path: [docSchema.fields[0].name], schemaType: docSchema.fields[0].type},
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
} as any
|
|
85
|
-
const conditionalMembers = getConditionalMembers(docState)
|
|
86
|
-
|
|
87
|
-
expect(conditionalMembers).toEqual([{path: '', hidden: false, readOnly: false}])
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
test('should include array item path with conditional readonly', () => {
|
|
91
|
-
const docSchema: ObjectSchemaType = Schema.compile({
|
|
92
|
-
name: 'test',
|
|
93
|
-
types: [
|
|
94
|
-
defineType({
|
|
95
|
-
type: 'document',
|
|
96
|
-
name: 'article',
|
|
97
|
-
fields: [{type: 'array', name: 'array', of: [{type: 'string', readOnly: () => true}]}],
|
|
98
|
-
}),
|
|
99
|
-
],
|
|
100
|
-
}).get('article')
|
|
101
|
-
|
|
102
|
-
const docState = {
|
|
103
|
-
path: [],
|
|
104
|
-
schemaType: docSchema,
|
|
105
|
-
members: [
|
|
106
|
-
{
|
|
107
|
-
kind: 'field',
|
|
108
|
-
field: {
|
|
109
|
-
path: [docSchema.fields[0].name],
|
|
110
|
-
schemaType: docSchema.fields[0].type,
|
|
111
|
-
members: [
|
|
112
|
-
{
|
|
113
|
-
kind: 'item',
|
|
114
|
-
item: {
|
|
115
|
-
path: [docSchema.fields[0].name, 0],
|
|
116
|
-
schemaType: (docSchema.fields[0].type as ArraySchemaType).of[0],
|
|
117
|
-
readOnly: true,
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
],
|
|
124
|
-
} as any
|
|
125
|
-
const conditionalMembers = getConditionalMembers(docState)
|
|
126
|
-
|
|
127
|
-
expect(conditionalMembers).toEqual([
|
|
128
|
-
{
|
|
129
|
-
path: 'array[0]',
|
|
130
|
-
hidden: false,
|
|
131
|
-
readOnly: true,
|
|
132
|
-
},
|
|
133
|
-
])
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
test('should include object path with conditional hidden', () => {
|
|
137
|
-
const docSchema: ObjectSchemaType = Schema.compile({
|
|
138
|
-
name: 'test',
|
|
139
|
-
types: [
|
|
140
|
-
defineType({
|
|
141
|
-
type: 'document',
|
|
142
|
-
name: 'article',
|
|
143
|
-
fields: [
|
|
144
|
-
defineField({
|
|
145
|
-
type: 'object',
|
|
146
|
-
name: 'object',
|
|
147
|
-
fields: [{type: 'string', name: 'title', hidden: () => false}],
|
|
148
|
-
}),
|
|
149
|
-
],
|
|
150
|
-
}),
|
|
151
|
-
],
|
|
152
|
-
}).get('article')
|
|
153
|
-
|
|
154
|
-
const docState = {
|
|
155
|
-
path: [],
|
|
156
|
-
schemaType: docSchema,
|
|
157
|
-
members: [
|
|
158
|
-
{
|
|
159
|
-
kind: 'field',
|
|
160
|
-
field: {
|
|
161
|
-
path: [docSchema.fields[0].name],
|
|
162
|
-
schemaType: docSchema.fields[0].type,
|
|
163
|
-
members: [
|
|
164
|
-
{
|
|
165
|
-
kind: 'field',
|
|
166
|
-
field: {
|
|
167
|
-
path: [docSchema.fields[0].name, 'title'],
|
|
168
|
-
schemaType: (docSchema.fields[0].type as ObjectSchemaType).fields[0].type,
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
],
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
} as any
|
|
176
|
-
const conditionalMembers = getConditionalMembers(docState)
|
|
177
|
-
|
|
178
|
-
expect(conditionalMembers).toEqual([
|
|
179
|
-
{
|
|
180
|
-
path: 'object.title',
|
|
181
|
-
hidden: false,
|
|
182
|
-
readOnly: false,
|
|
183
|
-
},
|
|
184
|
-
])
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
test('should include path with fieldset with conditional state', () => {
|
|
188
|
-
const docSchema: ObjectSchemaType = Schema.compile({
|
|
189
|
-
name: 'test',
|
|
190
|
-
types: [
|
|
191
|
-
defineType({
|
|
192
|
-
type: 'document',
|
|
193
|
-
name: 'article',
|
|
194
|
-
fieldsets: [{name: 'set', hidden: () => false}],
|
|
195
|
-
fields: [{type: 'string', fieldset: 'set', name: 'title'}],
|
|
196
|
-
}),
|
|
197
|
-
],
|
|
198
|
-
}).get('article')
|
|
199
|
-
|
|
200
|
-
const docState = {
|
|
201
|
-
path: [],
|
|
202
|
-
schemaType: docSchema,
|
|
203
|
-
members: [
|
|
204
|
-
{
|
|
205
|
-
kind: 'fieldSet',
|
|
206
|
-
fieldSet: {
|
|
207
|
-
name: 'set',
|
|
208
|
-
path: ['set'],
|
|
209
|
-
members: [
|
|
210
|
-
{
|
|
211
|
-
kind: 'field',
|
|
212
|
-
field: {path: [docSchema.fields[0].name], schemaType: docSchema.fields[0].type},
|
|
213
|
-
},
|
|
214
|
-
],
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
],
|
|
218
|
-
} as any
|
|
219
|
-
const conditionalMembers = getConditionalMembers(docState)
|
|
220
|
-
|
|
221
|
-
expect(conditionalMembers).toEqual([
|
|
222
|
-
{
|
|
223
|
-
path: 'title',
|
|
224
|
-
hidden: false,
|
|
225
|
-
readOnly: false,
|
|
226
|
-
},
|
|
227
|
-
])
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
test('should include field with conditional state inside fieldset', () => {
|
|
231
|
-
const docSchema: ObjectSchemaType = Schema.compile({
|
|
232
|
-
name: 'test',
|
|
233
|
-
types: [
|
|
234
|
-
defineType({
|
|
235
|
-
type: 'document',
|
|
236
|
-
name: 'article',
|
|
237
|
-
fieldsets: [{name: 'set'}],
|
|
238
|
-
fields: [{type: 'string', fieldset: 'set', name: 'title', hidden: () => false}],
|
|
239
|
-
}),
|
|
240
|
-
],
|
|
241
|
-
}).get('article')
|
|
242
|
-
|
|
243
|
-
const docState = {
|
|
244
|
-
path: [],
|
|
245
|
-
schemaType: docSchema,
|
|
246
|
-
members: [
|
|
247
|
-
{
|
|
248
|
-
kind: 'fieldSet',
|
|
249
|
-
fieldSet: {
|
|
250
|
-
name: 'set',
|
|
251
|
-
path: ['set'],
|
|
252
|
-
members: [
|
|
253
|
-
{
|
|
254
|
-
kind: 'field',
|
|
255
|
-
field: {path: [docSchema.fields[0].name], schemaType: docSchema.fields[0].type},
|
|
256
|
-
},
|
|
257
|
-
],
|
|
258
|
-
},
|
|
259
|
-
},
|
|
260
|
-
],
|
|
261
|
-
} as any
|
|
262
|
-
const conditionalMembers = getConditionalMembers(docState)
|
|
263
|
-
|
|
264
|
-
expect(conditionalMembers).toEqual([
|
|
265
|
-
{
|
|
266
|
-
path: 'title',
|
|
267
|
-
hidden: false,
|
|
268
|
-
readOnly: false,
|
|
269
|
-
},
|
|
270
|
-
])
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
test('should respect max-depth', () => {
|
|
274
|
-
const docSchema: ObjectSchemaType = Schema.compile({
|
|
275
|
-
name: 'test',
|
|
276
|
-
types: [
|
|
277
|
-
defineType({
|
|
278
|
-
type: 'document',
|
|
279
|
-
name: 'article',
|
|
280
|
-
fields: [
|
|
281
|
-
{type: 'string', name: 'title', readOnly: () => false},
|
|
282
|
-
{
|
|
283
|
-
type: 'object',
|
|
284
|
-
name: 'object',
|
|
285
|
-
fields: [{type: 'string', name: 'title', readOnly: () => false}],
|
|
286
|
-
},
|
|
287
|
-
],
|
|
288
|
-
}),
|
|
289
|
-
],
|
|
290
|
-
}).get('article')
|
|
291
|
-
|
|
292
|
-
const docState = {
|
|
293
|
-
path: [],
|
|
294
|
-
schemaType: docSchema,
|
|
295
|
-
members: [
|
|
296
|
-
{
|
|
297
|
-
kind: 'field',
|
|
298
|
-
field: {path: [docSchema.fields[0].name], schemaType: docSchema.fields[0].type},
|
|
299
|
-
},
|
|
300
|
-
{
|
|
301
|
-
kind: 'field',
|
|
302
|
-
field: {
|
|
303
|
-
path: [docSchema.fields[1].name],
|
|
304
|
-
schemaType: docSchema.fields[1].type,
|
|
305
|
-
members: [
|
|
306
|
-
{
|
|
307
|
-
kind: 'field',
|
|
308
|
-
field: {path: ['object', 'title'], schemaType: docSchema.fields[0].type},
|
|
309
|
-
},
|
|
310
|
-
],
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
],
|
|
314
|
-
} as any
|
|
315
|
-
const conditionalMembers = getConditionalMembers(docState, 1)
|
|
316
|
-
|
|
317
|
-
expect(conditionalMembers).toEqual([{path: 'title', hidden: false, readOnly: false}])
|
|
318
|
-
})
|
|
319
|
-
})
|