@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,134 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-depth */
|
|
2
|
-
import {
|
|
3
|
-
type ArrayOfObjectsFormNode,
|
|
4
|
-
type ArrayOfObjectsItemMember,
|
|
5
|
-
type ArrayOfPrimitivesFormNode,
|
|
6
|
-
type DocumentFormNode,
|
|
7
|
-
type FieldsetState,
|
|
8
|
-
isObjectSchemaType,
|
|
9
|
-
type ObjectFormNode,
|
|
10
|
-
type Path,
|
|
11
|
-
pathToString,
|
|
12
|
-
type SchemaType,
|
|
13
|
-
} from 'sanity'
|
|
14
|
-
|
|
15
|
-
const DEFAULT_MAX_DEPTH = 8
|
|
16
|
-
const ABSOLUTE_MAX_DEPTH = 50
|
|
17
|
-
|
|
18
|
-
export interface ConditionalMemberState {
|
|
19
|
-
path: string
|
|
20
|
-
hidden: boolean
|
|
21
|
-
readOnly: boolean
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface ConditionalMemberInnerState extends ConditionalMemberState {
|
|
25
|
-
conditional: boolean
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* This is used to statically determine the state of the functions on the server-side.
|
|
30
|
-
* Paths which has a schema with conditional config should be considered hidden: true and/or readOnly: true
|
|
31
|
-
* Only conditional paths are included, as static props can be determined from schema.
|
|
32
|
-
*
|
|
33
|
-
* Returns paths that has conditional hidden or readOnly schema config (function) and that.
|
|
34
|
-
* Form-state does not contain hidden members.
|
|
35
|
-
*
|
|
36
|
-
* Note:
|
|
37
|
-
* * If a parent path is hidden, no child paths are included
|
|
38
|
-
* * If a parent path is readOnly, no child paths are included
|
|
39
|
-
* * If a path is hidden, it is not included; only conditionally visible paths will be returned, with hidden: false
|
|
40
|
-
*/
|
|
41
|
-
export function getConditionalMembers(
|
|
42
|
-
docState: DocumentFormNode,
|
|
43
|
-
maxDepth = DEFAULT_MAX_DEPTH,
|
|
44
|
-
): ConditionalMemberState[] {
|
|
45
|
-
const doc: ConditionalMemberInnerState = {
|
|
46
|
-
path: '',
|
|
47
|
-
hidden: false,
|
|
48
|
-
readOnly: !!docState.readOnly,
|
|
49
|
-
conditional: isConditional(docState.schemaType),
|
|
50
|
-
}
|
|
51
|
-
return (
|
|
52
|
-
[doc, ...extractConditionalPaths(docState, Math.min(maxDepth, ABSOLUTE_MAX_DEPTH))]
|
|
53
|
-
.filter((v) => v.conditional)
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
55
|
-
.map(({conditional, ...state}) => ({...state}))
|
|
56
|
-
)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function isConditional(schemaType: SchemaType) {
|
|
60
|
-
return typeof schemaType.hidden === 'function' || typeof schemaType.readOnly === 'function'
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function conditionalState(memberState: {
|
|
64
|
-
path: Path
|
|
65
|
-
schemaType: SchemaType
|
|
66
|
-
readOnly?: boolean
|
|
67
|
-
}): ConditionalMemberInnerState {
|
|
68
|
-
return {
|
|
69
|
-
path: pathToString(memberState.path),
|
|
70
|
-
readOnly: !!memberState.readOnly, // Use actual form state readOnly value
|
|
71
|
-
hidden: false, // If it's in form state members, it's not hidden
|
|
72
|
-
conditional: isConditional(memberState.schemaType),
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function extractConditionalPaths(
|
|
77
|
-
node: ObjectFormNode | FieldsetState,
|
|
78
|
-
maxDepth: number,
|
|
79
|
-
): ConditionalMemberInnerState[] {
|
|
80
|
-
if (node.path.length >= maxDepth) {
|
|
81
|
-
return []
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return node.members.reduce<ConditionalMemberInnerState[]>((acc, member) => {
|
|
85
|
-
if (member.kind === 'error') {
|
|
86
|
-
return acc
|
|
87
|
-
}
|
|
88
|
-
if (member.kind === 'field') {
|
|
89
|
-
const schemaType = member.field.schemaType
|
|
90
|
-
if (schemaType.jsonType === 'object') {
|
|
91
|
-
const innerFields = member.field.readOnly
|
|
92
|
-
? []
|
|
93
|
-
: extractConditionalPaths(member.field as ObjectFormNode, maxDepth)
|
|
94
|
-
return [...acc, conditionalState(member.field), ...innerFields]
|
|
95
|
-
} else if (schemaType.jsonType === 'array') {
|
|
96
|
-
const array = member.field as ArrayOfObjectsFormNode | ArrayOfPrimitivesFormNode
|
|
97
|
-
|
|
98
|
-
let arrayPaths: ConditionalMemberInnerState[] = []
|
|
99
|
-
const isObjectsArray = array.members.some(
|
|
100
|
-
(m) => m.kind === 'item' && isObjectSchemaType(m.item.schemaType),
|
|
101
|
-
)
|
|
102
|
-
if (!array.readOnly) {
|
|
103
|
-
for (const arrayMember of array.members) {
|
|
104
|
-
if (arrayMember.kind === 'error') {
|
|
105
|
-
continue
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const innerFields =
|
|
109
|
-
isObjectsArray && !arrayMember.item.readOnly
|
|
110
|
-
? extractConditionalPaths((arrayMember as ArrayOfObjectsItemMember).item, maxDepth)
|
|
111
|
-
: []
|
|
112
|
-
|
|
113
|
-
arrayPaths = [...arrayPaths, conditionalState(arrayMember.item), ...innerFields]
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return [...acc, conditionalState(array), ...arrayPaths]
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return [...acc, conditionalState(member.field)]
|
|
120
|
-
} else if (member.kind === 'fieldSet') {
|
|
121
|
-
const conditionalFieldset = !!(node as ObjectFormNode).schemaType?.fieldsets?.some(
|
|
122
|
-
(f) => !f.single && f.name === member.fieldSet.name && typeof f.hidden === 'function',
|
|
123
|
-
)
|
|
124
|
-
const innerFields = extractConditionalPaths(member.fieldSet, maxDepth).map((f) => ({
|
|
125
|
-
...f,
|
|
126
|
-
// if fieldset is conditional, visible fields must also be considered conditional
|
|
127
|
-
conditional: conditionalFieldset || f.conditional,
|
|
128
|
-
}))
|
|
129
|
-
return [...acc, ...innerFields]
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return acc
|
|
133
|
-
}, [])
|
|
134
|
-
}
|
package/src/helpers/ids.test.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {describe, expect, test} from 'vitest'
|
|
2
|
-
|
|
3
|
-
import {assistDocumentId, assistTasksStatusId} from './ids'
|
|
4
|
-
|
|
5
|
-
describe('ids', () => {
|
|
6
|
-
test('assistDocumentId should replace illegal id chars with _', () => {
|
|
7
|
-
const testCases = [
|
|
8
|
-
{schemaType: 'test', assistId: 'sanity.assist.schemaType.test'},
|
|
9
|
-
{schemaType: 'test-type', assistId: 'sanity.assist.schemaType.test-type'},
|
|
10
|
-
{schemaType: 'test/type', assistId: 'sanity.assist.schemaType.test_type'},
|
|
11
|
-
{schemaType: '%broken©™£€∞', assistId: 'sanity.assist.schemaType._broken_____'},
|
|
12
|
-
]
|
|
13
|
-
const outputs = testCases.map((testCase) => assistDocumentId(testCase.schemaType))
|
|
14
|
-
const expected = testCases.map((testCase) => testCase.assistId)
|
|
15
|
-
expect(outputs).toEqual(expected)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
test.each([
|
|
19
|
-
{documentId: 'foo', assistId: 'sanity.assist.status.foo'},
|
|
20
|
-
{documentId: 'drafts.foo', assistId: 'sanity.assist.status.foo'},
|
|
21
|
-
{documentId: 'versions.r12332.foo', assistId: 'sanity.assist.status.r12332.foo'},
|
|
22
|
-
])(
|
|
23
|
-
"assistTasksStatusId should return the documentId with 'sanity.assist.status' prefix for $documentId",
|
|
24
|
-
({documentId, assistId}) => {
|
|
25
|
-
expect(assistTasksStatusId(documentId)).toEqual(assistId)
|
|
26
|
-
},
|
|
27
|
-
)
|
|
28
|
-
})
|
package/src/helpers/ids.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {getPublishedId, getVersionFromId, isVersionId} from 'sanity'
|
|
2
|
-
|
|
3
|
-
import {assistDocumentIdPrefix, assistDocumentStatusIdPrefix} from '../types'
|
|
4
|
-
|
|
5
|
-
const illegalIdChars = /[^a-zA-Z0-9._-]/g
|
|
6
|
-
|
|
7
|
-
export function publicId(id: string) {
|
|
8
|
-
return id.replace('drafts.', '')
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function assistDocumentId(documentType: string) {
|
|
12
|
-
return `${assistDocumentIdPrefix}${documentType}`.replace(illegalIdChars, '_')
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function assistTasksStatusId(documentId: string) {
|
|
16
|
-
if (isVersionId(documentId)) {
|
|
17
|
-
// Creates an id: sanity.assist.status.<versionName>.<documentId>
|
|
18
|
-
return `${assistDocumentStatusIdPrefix}${getVersionFromId(documentId)}.${getPublishedId(documentId)}`
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Creates an id: sanity.assist.status<documentId>
|
|
22
|
-
return `${assistDocumentStatusIdPrefix}${getPublishedId(documentId)}`
|
|
23
|
-
}
|
package/src/helpers/misc.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {useMemo} from 'react'
|
|
2
|
-
import {Path, pathToString} from 'sanity'
|
|
3
|
-
|
|
4
|
-
import {documentRootKey, StudioInstruction} from '../types'
|
|
5
|
-
|
|
6
|
-
export function usePathKey(path: Path | string) {
|
|
7
|
-
return useMemo(() => {
|
|
8
|
-
return getPathKey(path)
|
|
9
|
-
}, [path])
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function getPathKey(path: Path | string) {
|
|
13
|
-
if (path.length) {
|
|
14
|
-
return Array.isArray(path) ? pathToString(path) : path
|
|
15
|
-
}
|
|
16
|
-
return documentRootKey
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function getInstructionTitle(instruction?: StudioInstruction) {
|
|
20
|
-
return instruction?.title ?? 'Untitled'
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function isDefined<T>(t: T | undefined | null): t is T {
|
|
24
|
-
return t !== undefined && t !== null
|
|
25
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {packageName} from '../constants'
|
|
2
|
-
import {TranslateStyleguide, TranslateStyleguideContext} from '../translate/types'
|
|
3
|
-
|
|
4
|
-
export function validateStyleguide(styleguide: string | undefined) {
|
|
5
|
-
if (styleguide && styleguide.length > 2000) {
|
|
6
|
-
throw new Error(
|
|
7
|
-
`[${packageName}]: \`translate.styleguide\` value is too long. It must be 2000 characters or less, but was ${styleguide.length} characters`,
|
|
8
|
-
)
|
|
9
|
-
}
|
|
10
|
-
return styleguide
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function createStyleGuideResolver(
|
|
14
|
-
styleguide: TranslateStyleguide | undefined,
|
|
15
|
-
context: TranslateStyleguideContext,
|
|
16
|
-
) {
|
|
17
|
-
return async () => {
|
|
18
|
-
if (typeof styleguide !== 'function') {
|
|
19
|
-
return styleguide
|
|
20
|
-
}
|
|
21
|
-
const styleguideResult = await styleguide(context)
|
|
22
|
-
return validateStyleguide(styleguideResult)
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/helpers/typeUtils.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {ArraySchemaType, ImageOptions, SchemaType} from 'sanity'
|
|
2
|
-
|
|
3
|
-
export function isPortableTextArray(type: ArraySchemaType) {
|
|
4
|
-
return type.of.find((t) => isType(t, 'block'))
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns true if the `schemaType` or any of its parent types (`schemaType.type`)` has `name` equal
|
|
9
|
-
* to `typeName`.
|
|
10
|
-
*
|
|
11
|
-
* Useful for checking if `schemaType` is a type alias of `ìmage`, `code` or similar.
|
|
12
|
-
*/
|
|
13
|
-
export function isType(schemaType: SchemaType, typeName: string): boolean {
|
|
14
|
-
if (schemaType.name === typeName) {
|
|
15
|
-
return true
|
|
16
|
-
}
|
|
17
|
-
if (!schemaType.type) {
|
|
18
|
-
return false
|
|
19
|
-
}
|
|
20
|
-
return isType(schemaType.type, typeName)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function isImage(schemaType: SchemaType) {
|
|
24
|
-
return isType(schemaType, 'image')
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function getDescriptionFieldOption(
|
|
28
|
-
schemaType: SchemaType | undefined,
|
|
29
|
-
): {path: string; updateOnImageChange: boolean} | undefined {
|
|
30
|
-
if (!schemaType) {
|
|
31
|
-
return undefined
|
|
32
|
-
}
|
|
33
|
-
const descriptionField = (schemaType.options as ImageOptions)?.aiAssist?.imageDescriptionField
|
|
34
|
-
if (typeof descriptionField === 'string') {
|
|
35
|
-
return {
|
|
36
|
-
path: descriptionField,
|
|
37
|
-
updateOnImageChange: true,
|
|
38
|
-
}
|
|
39
|
-
} else if (descriptionField) {
|
|
40
|
-
return {
|
|
41
|
-
path: descriptionField.path,
|
|
42
|
-
updateOnImageChange: descriptionField.updateOnImageChange ?? true,
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return getDescriptionFieldOption(schemaType.type)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function getImageInstructionFieldOption(
|
|
49
|
-
schemaType: SchemaType | undefined,
|
|
50
|
-
): string | undefined {
|
|
51
|
-
if (!schemaType) {
|
|
52
|
-
return undefined
|
|
53
|
-
}
|
|
54
|
-
const imageInstructionField = (schemaType.options as ImageOptions)?.aiAssist
|
|
55
|
-
?.imageInstructionField
|
|
56
|
-
if (imageInstructionField) {
|
|
57
|
-
return imageInstructionField
|
|
58
|
-
}
|
|
59
|
-
return getImageInstructionFieldOption(schemaType.type)
|
|
60
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import {useMemo} from 'react'
|
|
2
|
-
import {Path, SchemaType} from 'sanity'
|
|
3
|
-
|
|
4
|
-
import {isAssistSupported} from './assistSupported'
|
|
5
|
-
|
|
6
|
-
export function useAssistSupported(path: Path, schemaType: SchemaType) {
|
|
7
|
-
return useMemo(() => isAssistSupported(schemaType), [schemaType])
|
|
8
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export {assist} from './plugin'
|
|
2
|
-
export * from './schemas/serialize/SchemTypeTool'
|
|
3
|
-
export * from './schemas/typeDefExtensions'
|
|
4
|
-
export {defaultLanguageOutputs} from './translate/paths'
|
|
5
|
-
export * from './translate/types'
|
|
6
|
-
export {contextDocumentTypeName} from './types'
|
|
7
|
-
export * from './assistTypes'
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
type AssistFieldActionProps,
|
|
11
|
-
type AssistFieldActionGroup,
|
|
12
|
-
type AssistFieldActionItem,
|
|
13
|
-
type AssistFieldActionNode,
|
|
14
|
-
defineAssistFieldAction,
|
|
15
|
-
defineFieldActionDivider,
|
|
16
|
-
defineAssistFieldActionGroup,
|
|
17
|
-
} from './fieldActions/customFieldActions'
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
type GetUserInput,
|
|
21
|
-
type CustomInput,
|
|
22
|
-
type CustomInputResult,
|
|
23
|
-
useUserInput,
|
|
24
|
-
} from './fieldActions/useUserInput'
|
|
25
|
-
|
|
26
|
-
export {isType} from './helpers/typeUtils'
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {createContext, PropsWithChildren, useMemo} from 'react'
|
|
2
|
-
import {FieldMember, ObjectInputProps, pathToString} from 'sanity'
|
|
3
|
-
|
|
4
|
-
import {isAssistSupported} from '../helpers/assistSupported'
|
|
5
|
-
|
|
6
|
-
export const FirstAssistedPathContext = createContext<string | undefined>(undefined)
|
|
7
|
-
|
|
8
|
-
export interface FirstAssistedPathProviderProps {
|
|
9
|
-
members: ObjectInputProps['members']
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function FirstAssistedPathProvider(
|
|
13
|
-
props: PropsWithChildren<FirstAssistedPathProviderProps>,
|
|
14
|
-
) {
|
|
15
|
-
const {members} = props
|
|
16
|
-
|
|
17
|
-
const firstAssistedPath = useMemo(() => {
|
|
18
|
-
const firstAssisted = members.find(
|
|
19
|
-
(member): member is FieldMember =>
|
|
20
|
-
member.kind === 'field' && isAssistSupported(member.field.schemaType),
|
|
21
|
-
)
|
|
22
|
-
return firstAssisted?.field.path ? pathToString(firstAssisted?.field.path) : undefined
|
|
23
|
-
}, [members])
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<FirstAssistedPathContext.Provider value={firstAssistedPath}>
|
|
27
|
-
{props.children}
|
|
28
|
-
</FirstAssistedPathContext.Provider>
|
|
29
|
-
)
|
|
30
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {SparklesIcon} from '@sanity/icons'
|
|
2
|
-
import {Box, Button, Container, Flex, Stack, Text} from '@sanity/ui'
|
|
3
|
-
import {styled} from 'styled-components'
|
|
4
|
-
|
|
5
|
-
import {releaseAnnouncementUrl} from '../constants'
|
|
6
|
-
|
|
7
|
-
const SparklesIllustration = styled(SparklesIcon)({
|
|
8
|
-
fontSize: '3.125em',
|
|
9
|
-
'& path': {
|
|
10
|
-
strokeWidth: `0.6px !important`,
|
|
11
|
-
},
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
export function InspectorOnboarding(props: {onDismiss: () => void}) {
|
|
15
|
-
const {onDismiss} = props
|
|
16
|
-
return (
|
|
17
|
-
<Box padding={4}>
|
|
18
|
-
<Container width={0}>
|
|
19
|
-
<Stack space={4}>
|
|
20
|
-
<div style={{textAlign: 'center'}}>
|
|
21
|
-
<SparklesIllustration />
|
|
22
|
-
</div>
|
|
23
|
-
<Text align="center" size={1}>
|
|
24
|
-
Create reusable AI instructions that can be applied across all documents of a certain
|
|
25
|
-
type.
|
|
26
|
-
</Text>
|
|
27
|
-
|
|
28
|
-
<Flex align="center" gap={2} justify="center">
|
|
29
|
-
<Button
|
|
30
|
-
as="a"
|
|
31
|
-
href={releaseAnnouncementUrl}
|
|
32
|
-
rel="noreferrer"
|
|
33
|
-
target="_blank"
|
|
34
|
-
fontSize={1}
|
|
35
|
-
mode="default"
|
|
36
|
-
onClick={onDismiss}
|
|
37
|
-
padding={2}
|
|
38
|
-
text="Learn more"
|
|
39
|
-
tone="primary"
|
|
40
|
-
/>
|
|
41
|
-
<Button fontSize={1} mode="bleed" onClick={onDismiss} padding={2} text="Dismiss" />
|
|
42
|
-
</Flex>
|
|
43
|
-
</Stack>
|
|
44
|
-
</Container>
|
|
45
|
-
</Box>
|
|
46
|
-
)
|
|
47
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {useCallback, useState} from 'react'
|
|
2
|
-
|
|
3
|
-
export const inspectorOnboardingKey = 'sanityStudio:assist:inspector:onboarding:dismissed'
|
|
4
|
-
|
|
5
|
-
export function isFeatureOnboardingDismissed(featureKey: string): boolean {
|
|
6
|
-
if (typeof localStorage === 'undefined') {
|
|
7
|
-
return false
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const value = localStorage.getItem(featureKey)
|
|
11
|
-
return value === 'true'
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function dismissFeatureOnboarding(featureKey: string) {
|
|
15
|
-
if (typeof localStorage === 'undefined') {
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
localStorage.setItem(featureKey, 'true')
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function useOnboardingFeature(featureKey: string) {
|
|
23
|
-
const [showOnboarding, setShowOnboarding] = useState(
|
|
24
|
-
() => !isFeatureOnboardingDismissed(featureKey),
|
|
25
|
-
)
|
|
26
|
-
const dismissOnboarding = useCallback(() => {
|
|
27
|
-
setShowOnboarding(false)
|
|
28
|
-
dismissFeatureOnboarding(featureKey)
|
|
29
|
-
}, [setShowOnboarding, featureKey])
|
|
30
|
-
|
|
31
|
-
return {showOnboarding, dismissOnboarding}
|
|
32
|
-
}
|
package/src/plugin.tsx
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import type {SanityClient} from '@sanity/client'
|
|
2
|
-
import {definePlugin, isObjectSchemaType} from 'sanity'
|
|
3
|
-
|
|
4
|
-
import {AssistDocumentInputWrapper} from './assistDocument/AssistDocumentInput'
|
|
5
|
-
import {AssistDocumentLayout} from './assistDocument/AssistDocumentLayout'
|
|
6
|
-
import {AssistFieldWrapper} from './assistFormComponents/AssistField'
|
|
7
|
-
import {AssistFormBlock} from './assistFormComponents/AssistFormBlock'
|
|
8
|
-
import {AssistInlineFormBlock} from './assistFormComponents/AssistInlineFormBlock'
|
|
9
|
-
import {AssistItem} from './assistFormComponents/AssistItem'
|
|
10
|
-
import {assistInspector} from './assistInspector'
|
|
11
|
-
import {AssistLayout} from './assistLayout/AssistLayout'
|
|
12
|
-
import {AssistConfig} from './assistTypes'
|
|
13
|
-
import {ImageContextProvider} from './components/ImageContext'
|
|
14
|
-
import {SafeValueInput} from './components/SafeValueInput'
|
|
15
|
-
import {packageName} from './constants'
|
|
16
|
-
import {assistFieldActions} from './fieldActions/assistFieldActions'
|
|
17
|
-
import {isSchemaAssistEnabled} from './helpers/assistSupported'
|
|
18
|
-
import {validateStyleguide} from './helpers/styleguide'
|
|
19
|
-
import {isImage} from './helpers/typeUtils'
|
|
20
|
-
import {createAssistDocumentPresence} from './presence/AssistDocumentPresence'
|
|
21
|
-
import {schemaTypes} from './schemas'
|
|
22
|
-
import {TranslationConfig} from './translate/types'
|
|
23
|
-
import {assistDocumentTypeName, AssistPreset} from './types'
|
|
24
|
-
import {AssistFieldActionNode, AssistFieldActionProps} from './fieldActions/customFieldActions'
|
|
25
|
-
|
|
26
|
-
export interface AssistPluginConfig {
|
|
27
|
-
translate?: TranslationConfig
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Config that affects all instructions
|
|
31
|
-
*/
|
|
32
|
-
assist?: AssistConfig
|
|
33
|
-
|
|
34
|
-
fieldActions?: {
|
|
35
|
-
title?: string
|
|
36
|
-
/**
|
|
37
|
-
* The returned array can include `undefined` entries in the action array. These will be filtered out.
|
|
38
|
-
*/
|
|
39
|
-
useFieldActions?: (props: AssistFieldActionProps) => (AssistFieldActionNode | undefined)[]
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @internal
|
|
44
|
-
*/
|
|
45
|
-
__customApiClient?: (defaultClient: SanityClient) => SanityClient
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @internal
|
|
49
|
-
*/
|
|
50
|
-
__presets?: Record<string, AssistPreset>
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const assist = definePlugin<AssistPluginConfig | void>((config) => {
|
|
54
|
-
const configWithDefaults = config ?? {}
|
|
55
|
-
const styleguide = configWithDefaults.translate?.styleguide || ''
|
|
56
|
-
const maxPathDepth = configWithDefaults.assist?.maxPathDepth
|
|
57
|
-
const temperature = configWithDefaults.assist?.temperature
|
|
58
|
-
|
|
59
|
-
if (typeof styleguide === 'string') {
|
|
60
|
-
validateStyleguide(styleguide)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (maxPathDepth !== undefined && (maxPathDepth < 1 || maxPathDepth > 12)) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
`[${packageName}]: \`assist.maxPathDepth\` must be be in the range [1,12] inclusive, but was ${maxPathDepth}`,
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (temperature !== undefined && (temperature < 0 || temperature > 1)) {
|
|
70
|
-
throw new Error(
|
|
71
|
-
`[${packageName}]: \`assist.maxPathDepth\` must be be in the range [0,1] inclusive, but was ${temperature}`,
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
name: packageName,
|
|
77
|
-
// the addition of global references broke auto updating studios
|
|
78
|
-
// new versions of studio know to look for this prop on assist plugin, and filter + console.warn if it is missing
|
|
79
|
-
...({handlesGDR: true} as any),
|
|
80
|
-
schema: {
|
|
81
|
-
types: schemaTypes,
|
|
82
|
-
},
|
|
83
|
-
i18n: {
|
|
84
|
-
bundles: [{}],
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
document: {
|
|
88
|
-
inspectors: (prev, context) => {
|
|
89
|
-
const documentType = context.documentType
|
|
90
|
-
const docSchema = context.schema.get(documentType)
|
|
91
|
-
if (docSchema && isSchemaAssistEnabled(docSchema)) {
|
|
92
|
-
return [...prev, assistInspector]
|
|
93
|
-
}
|
|
94
|
-
return prev
|
|
95
|
-
},
|
|
96
|
-
unstable_fieldActions: (prev, {documentType, schema}) => {
|
|
97
|
-
if (documentType === assistDocumentTypeName) {
|
|
98
|
-
return []
|
|
99
|
-
}
|
|
100
|
-
const docSchema = schema.get(documentType)
|
|
101
|
-
if (docSchema && isSchemaAssistEnabled(docSchema)) {
|
|
102
|
-
return [...prev, assistFieldActions]
|
|
103
|
-
}
|
|
104
|
-
return prev
|
|
105
|
-
},
|
|
106
|
-
unstable_languageFilter: (prev, {documentId, schema, schemaType}) => {
|
|
107
|
-
if (schemaType === assistDocumentTypeName) {
|
|
108
|
-
return []
|
|
109
|
-
}
|
|
110
|
-
const docSchema = schema.get(schemaType)
|
|
111
|
-
if (docSchema && isObjectSchemaType(docSchema) && isSchemaAssistEnabled(docSchema)) {
|
|
112
|
-
return [...prev, createAssistDocumentPresence(documentId)]
|
|
113
|
-
}
|
|
114
|
-
return prev
|
|
115
|
-
},
|
|
116
|
-
components: {
|
|
117
|
-
unstable_layout: AssistDocumentLayout,
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
studio: {
|
|
122
|
-
components: {
|
|
123
|
-
layout: function Layout(props) {
|
|
124
|
-
return <AssistLayout {...props} config={configWithDefaults} />
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
form: {
|
|
130
|
-
components: {
|
|
131
|
-
input: AssistDocumentInputWrapper,
|
|
132
|
-
field: AssistFieldWrapper,
|
|
133
|
-
item: AssistItem,
|
|
134
|
-
block: AssistFormBlock,
|
|
135
|
-
inlineBlock: AssistInlineFormBlock,
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
plugins: [
|
|
140
|
-
definePlugin({
|
|
141
|
-
name: `${packageName}/safe-value-input`,
|
|
142
|
-
form: {components: {input: SafeValueInput}},
|
|
143
|
-
})(),
|
|
144
|
-
|
|
145
|
-
definePlugin({
|
|
146
|
-
name: `${packageName}/generate-caption`,
|
|
147
|
-
form: {
|
|
148
|
-
components: {
|
|
149
|
-
input: (props) => {
|
|
150
|
-
const {schemaType} = props
|
|
151
|
-
|
|
152
|
-
if (isImage(schemaType)) {
|
|
153
|
-
return <ImageContextProvider {...props} />
|
|
154
|
-
}
|
|
155
|
-
return props.renderDefault(props)
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
})(),
|
|
160
|
-
],
|
|
161
|
-
}
|
|
162
|
-
})
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line react/no-unused-prop-types
|
|
2
|
-
import {Card, Flex, Text, Tooltip} from '@sanity/ui'
|
|
3
|
-
import type {FormNodePresence} from 'sanity'
|
|
4
|
-
|
|
5
|
-
import {FadeInContent} from '../components/FadeInContent'
|
|
6
|
-
import {AssistAvatar} from './AssistAvatar'
|
|
7
|
-
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
-
export function AiFieldPresence(props: {presence: FormNodePresence}) {
|
|
10
|
-
return (
|
|
11
|
-
<Card style={{position: 'relative', background: 'transparent'}} contentEditable={false}>
|
|
12
|
-
<Tooltip
|
|
13
|
-
placement="left"
|
|
14
|
-
content={
|
|
15
|
-
<Card padding={3} border>
|
|
16
|
-
<Flex align="center">
|
|
17
|
-
<Text size={1}>Running instruction...</Text>
|
|
18
|
-
</Flex>
|
|
19
|
-
</Card>
|
|
20
|
-
}
|
|
21
|
-
>
|
|
22
|
-
<FadeInContent durationMs={300}>
|
|
23
|
-
<AssistAvatar state="active" />
|
|
24
|
-
</FadeInContent>
|
|
25
|
-
</Tooltip>
|
|
26
|
-
</Card>
|
|
27
|
-
)
|
|
28
|
-
}
|