@sanity/assist 2.0.4 → 3.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.
Files changed (96) hide show
  1. package/README.md +2 -2
  2. package/dist/index.d.mts +377 -0
  3. package/dist/index.esm.js +3132 -5883
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +3109 -5886
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +4159 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +32 -37
  10. package/src/_lib/connector/ConnectFromRegion.tsx +4 -3
  11. package/src/_lib/connector/ConnectToRegion.tsx +1 -0
  12. package/src/_lib/connector/ConnectorRegion.tsx +2 -1
  13. package/src/_lib/connector/ConnectorsProvider.tsx +2 -1
  14. package/src/_lib/connector/ConnectorsStoreContext.ts +1 -0
  15. package/src/_lib/connector/index.ts +1 -1
  16. package/src/_lib/connector/mapConnectorToLine.ts +2 -2
  17. package/src/_lib/connector/useConnectorsStore.ts +2 -1
  18. package/src/_lib/connector/useRegionRects.ts +4 -3
  19. package/src/_lib/fixedListenQuery.ts +11 -11
  20. package/src/_lib/form/DocumentForm.tsx +11 -9
  21. package/src/_lib/form/helpers.ts +2 -1
  22. package/src/_lib/useListeningQuery.ts +4 -3
  23. package/src/assistConnectors/AssistConnectorsOverlay.tsx +1 -0
  24. package/src/assistConnectors/ConnectorPath.tsx +3 -2
  25. package/src/assistConnectors/draw/connectorPath.ts +13 -13
  26. package/src/assistDocument/AssistDocumentContext.tsx +3 -2
  27. package/src/assistDocument/AssistDocumentContextProvider.tsx +2 -1
  28. package/src/assistDocument/AssistDocumentInput.tsx +10 -9
  29. package/src/assistDocument/RequestRunInstructionProvider.tsx +4 -3
  30. package/src/assistDocument/components/AssistDocumentForm.tsx +25 -24
  31. package/src/assistDocument/components/FieldRefPreview.tsx +4 -3
  32. package/src/assistDocument/components/InstructionsArrayInput.tsx +4 -3
  33. package/src/assistDocument/components/SelectedFieldContext.tsx +1 -1
  34. package/src/assistDocument/components/helpers.ts +4 -4
  35. package/src/assistDocument/components/instruction/BackToInstructionsLink.tsx +4 -3
  36. package/src/assistDocument/components/instruction/FieldRefInput.tsx +5 -4
  37. package/src/assistDocument/components/instruction/InstructionInput.tsx +3 -2
  38. package/src/assistDocument/components/instruction/InstructionOutputField.tsx +2 -1
  39. package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +14 -13
  40. package/src/assistDocument/components/instruction/PromptInput.tsx +10 -3
  41. package/src/assistDocument/components/instruction/appearance/IconInput.tsx +2 -2
  42. package/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx +1 -1
  43. package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +8 -7
  44. package/src/assistDocument/hooks/useInstructionToaster.tsx +6 -5
  45. package/src/assistDocument/hooks/useStudioAssistDocument.ts +14 -13
  46. package/src/assistFormComponents/AssistField.tsx +9 -8
  47. package/src/assistFormComponents/AssistFormBlock.tsx +5 -4
  48. package/src/assistFormComponents/AssistInlineFormBlock.tsx +1 -1
  49. package/src/assistFormComponents/AssistItem.tsx +3 -2
  50. package/src/assistFormComponents/validation/listItem.tsx +3 -3
  51. package/src/assistFormComponents/validation/validationList.tsx +3 -2
  52. package/src/assistInspector/AssistInspector.tsx +25 -18
  53. package/src/assistInspector/FieldAutocomplete.tsx +4 -3
  54. package/src/assistInspector/InstructionTaskHistoryButton.tsx +20 -19
  55. package/src/assistInspector/helpers.ts +16 -15
  56. package/src/assistInspector/index.ts +4 -3
  57. package/src/assistLayout/AiAssistanceConfigContext.tsx +1 -0
  58. package/src/assistLayout/AssistLayout.tsx +5 -4
  59. package/src/assistLayout/RunInstructionProvider.tsx +18 -15
  60. package/src/components/FadeInContent.tsx +3 -3
  61. package/src/components/HideReferenceChangedBannerInput.tsx +1 -1
  62. package/src/components/ImageContext.tsx +5 -4
  63. package/src/components/SafeValueInput.tsx +9 -11
  64. package/src/components/TimeAgo.tsx +1 -1
  65. package/src/fieldActions/assistFieldActions.tsx +31 -30
  66. package/src/fieldActions/generateCaptionActions.tsx +8 -7
  67. package/src/fieldActions/generateImageActions.tsx +6 -5
  68. package/src/helpers/assistSupported.ts +1 -0
  69. package/src/helpers/conditionalMembers.test.ts +2 -1
  70. package/src/helpers/conditionalMembers.ts +17 -14
  71. package/src/helpers/misc.ts +3 -2
  72. package/src/helpers/typeUtils.ts +1 -1
  73. package/src/helpers/useAssistSupported.ts +2 -1
  74. package/src/onboarding/FieldActionsOnboarding.tsx +2 -1
  75. package/src/onboarding/FirstAssistedPathProvider.tsx +4 -3
  76. package/src/onboarding/InspectorOnboarding.tsx +3 -2
  77. package/src/onboarding/onboardingStore.ts +1 -1
  78. package/src/presence/AiFieldPresence.tsx +3 -1
  79. package/src/presence/AssistAvatar.tsx +2 -2
  80. package/src/presence/AssistDocumentPresence.tsx +7 -6
  81. package/src/presence/useAssistPresence.ts +6 -3
  82. package/src/schemas/assistDocumentSchema.tsx +21 -20
  83. package/src/schemas/contextDocumentSchema.tsx +3 -2
  84. package/src/schemas/index.ts +2 -1
  85. package/src/schemas/serialize/SchemTypeTool.tsx +4 -3
  86. package/src/schemas/serialize/serializeSchema.test.ts +3 -2
  87. package/src/schemas/serialize/serializeSchema.ts +15 -14
  88. package/src/schemas/serializedSchemaTypeSchema.ts +2 -1
  89. package/src/translate/FieldTranslationProvider.tsx +33 -25
  90. package/src/translate/getLanguageParams.ts +4 -4
  91. package/src/translate/paths.test.ts +11 -4
  92. package/src/translate/paths.ts +12 -11
  93. package/src/translate/translateActions.tsx +12 -11
  94. package/src/translate/types.ts +2 -2
  95. package/src/useApiClient.ts +9 -9
  96. package/dist/index.cjs.mjs +0 -7
@@ -9,6 +9,9 @@ import {
9
9
  SchemaType,
10
10
  typed,
11
11
  } from 'sanity'
12
+
13
+ import {isAssistSupported} from '../../helpers/assistSupported'
14
+ import {isType} from '../../helpers/typeUtils'
12
15
  import {
13
16
  assistSchemaIdPrefix,
14
17
  assistSerializedFieldTypeName,
@@ -17,8 +20,6 @@ import {
17
20
  SerializedSchemaType,
18
21
  } from '../../types'
19
22
  import {hiddenTypes} from './schemaUtils'
20
- import {isAssistSupported} from '../../helpers/assistSupported'
21
- import {isType} from '../../helpers/typeUtils'
22
23
 
23
24
  interface Options {
24
25
  leanFormat?: boolean
@@ -54,7 +55,7 @@ export function serializeSchema(schema: Schema, options?: Options): SerializedSc
54
55
  function getSchemaStub(
55
56
  schemaType: SchemaType,
56
57
  schema: Schema,
57
- options?: Options
58
+ options?: Options,
58
59
  ): SerializedSchemaType {
59
60
  if (!schemaType.type?.name) {
60
61
  console.error('Missing type name', schemaType.type)
@@ -78,7 +79,7 @@ function getBaseFields(
78
79
  schema: Schema,
79
80
  type: SchemaType,
80
81
  typeName: string,
81
- options: Options | undefined
82
+ options: Options | undefined,
82
83
  ) {
83
84
  const schemaOptions: SerializedSchemaType['options'] = removeUndef({
84
85
  imagePromptField: (type.options as ImageOptions)?.aiAssist?.imageInstructionField,
@@ -88,7 +89,7 @@ function getBaseFields(
88
89
  options: Object.keys(schemaOptions).length ? schemaOptions : undefined,
89
90
  values: Array.isArray(type?.options?.list)
90
91
  ? type?.options?.list.map((v: string | {value: string; title: string}) =>
91
- typeof v === 'string' ? v : v.value ?? `${v.title}`
92
+ typeof v === 'string' ? v : v.value ?? `${v.title}`,
92
93
  )
93
94
  : undefined,
94
95
  of: 'of' in type && typeName === 'array' ? arrayOf(type, schema, options) : undefined,
@@ -114,15 +115,15 @@ function getBaseFields(
114
115
  typeof type.readOnly === 'function'
115
116
  ? ('function' as const)
116
117
  : type.readOnly
117
- ? true
118
- : undefined,
118
+ ? true
119
+ : undefined,
119
120
  })
120
121
  }
121
122
 
122
123
  function serializeFields(
123
124
  schema: Schema,
124
125
  schemaType: ObjectSchemaType,
125
- options: Options | undefined
126
+ options: Options | undefined,
126
127
  ) {
127
128
  const fields = schemaType.fieldsets
128
129
  ? schemaType.fieldsets.flatMap((fs) =>
@@ -138,7 +139,7 @@ function serializeFields(
138
139
  hidden:
139
140
  typeof fs.hidden === 'function' ? fs.hidden : fs.hidden ? true : f.type.hidden,
140
141
  },
141
- }))
142
+ })),
142
143
  )
143
144
  : schemaType.fields
144
145
 
@@ -152,7 +153,7 @@ function serializeMember(
152
153
  schema: Schema,
153
154
  type: SchemaType,
154
155
  name: string,
155
- options: Options | undefined
156
+ options: Options | undefined,
156
157
  ): SerializedSchemaMember {
157
158
  const typeNameExists = !!schema.get(type?.name)
158
159
  const typeName = typeNameExists ? type.name : type.type?.name ?? ''
@@ -168,7 +169,7 @@ function serializeMember(
168
169
  function serializeInlineOf(
169
170
  blockSchemaType: ObjectSchemaType,
170
171
  schema: Schema,
171
- options: Options | undefined
172
+ options: Options | undefined,
172
173
  ): SerializedSchemaMember[] | undefined {
173
174
  const childrenField = blockSchemaType.fields.find((f) => f.name === 'children')
174
175
  const childrenType = childrenField?.type
@@ -181,14 +182,14 @@ function serializeInlineOf(
181
182
  of: childrenType.of.filter((t) => !isType(t, 'span')),
182
183
  },
183
184
  schema,
184
- options
185
+ options,
185
186
  )
186
187
  }
187
188
 
188
189
  function serializeAnnotations(
189
190
  blockSchemaType: ObjectSchemaType,
190
191
  schema: Schema,
191
- options: Options | undefined
192
+ options: Options | undefined,
192
193
  ): SerializedSchemaMember[] | undefined {
193
194
  const markDefs = blockSchemaType.fields.find((f) => f.name === 'markDefs')
194
195
  const marksType = markDefs?.type
@@ -201,7 +202,7 @@ function serializeAnnotations(
201
202
  function arrayOf(
202
203
  arrayType: ArraySchemaType,
203
204
  schema: Schema,
204
- options: Options | undefined
205
+ options: Options | undefined,
205
206
  ): SerializedSchemaMember[] {
206
207
  return arrayType.of
207
208
  .filter((type) => isAssistSupported(type))
@@ -1,6 +1,7 @@
1
+ import {CodeIcon, StarIcon} from '@sanity/icons'
1
2
  import {defineField, defineType} from 'sanity'
3
+
2
4
  import {assistSerializedFieldTypeName, assistSerializedTypeName} from '../types'
3
- import {CodeIcon, StarIcon} from '@sanity/icons'
4
5
 
5
6
  export const serializedSchemaField = defineType({
6
7
  type: 'object',
@@ -1,27 +1,34 @@
1
+ import {PlayIcon} from '@sanity/icons'
2
+ import {Box, Button, Checkbox, Dialog, Flex, Radio, Spinner, Stack, Text, Tooltip} from '@sanity/ui'
1
3
  import {
2
4
  createContext,
3
- PropsWithChildren,
5
+ type PropsWithChildren,
4
6
  useCallback,
5
7
  useContext,
6
8
  useId,
7
9
  useMemo,
8
10
  useState,
9
11
  } from 'react'
10
- import {ObjectSchemaType, Path, pathToString, SanityDocumentLike, useClient} from 'sanity'
12
+ import {
13
+ type ObjectSchemaType,
14
+ type Path,
15
+ pathToString,
16
+ type SanityDocumentLike,
17
+ useClient,
18
+ } from 'sanity'
19
+
11
20
  import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
21
+ import type {ConditionalMemberState} from '../helpers/conditionalMembers'
12
22
  import {useApiClient, useTranslate} from '../useApiClient'
13
- import {Box, Button, Checkbox, Dialog, Flex, Radio, Spinner, Stack, Text, Tooltip} from '@sanity/ui'
23
+ import {getLanguageParams} from './getLanguageParams'
24
+ import {getPreferredToFieldLanguages, setPreferredToFieldLanguages} from './languageStore'
14
25
  import {
15
26
  defaultLanguageOutputs,
16
- FieldLanguageMap,
27
+ type FieldLanguageMap,
17
28
  getDocumentMembersFlat,
18
29
  getFieldLanguageMap,
19
30
  } from './paths'
20
- import {PlayIcon} from '@sanity/icons'
21
- import {Language} from './types'
22
- import {getLanguageParams} from './getLanguageParams'
23
- import {getPreferredToFieldLanguages, setPreferredToFieldLanguages} from './languageStore'
24
- import {ConditionalMemberState} from '../helpers/conditionalMembers'
31
+ import type {Language} from './types'
25
32
 
26
33
  interface FieldTranslationParams {
27
34
  document: SanityDocumentLike
@@ -47,16 +54,17 @@ export function useFieldTranslation() {
47
54
  function hasValuesToTranslate(
48
55
  fieldLanguageMaps: FieldLanguageMap[] | undefined,
49
56
  fromLanguage: Language | undefined,
50
- basePath: Path
57
+ basePath: Path,
51
58
  ) {
52
59
  return fieldLanguageMaps?.some(
53
60
  (map) =>
54
61
  map.inputLanguageId === fromLanguage?.id &&
55
62
  map.inputPath &&
56
- pathToString(map.inputPath).startsWith(pathToString(basePath))
63
+ pathToString(map.inputPath).startsWith(pathToString(basePath)),
57
64
  )
58
65
  }
59
66
 
67
+ // eslint-disable-next-line @typescript-eslint/ban-types
60
68
  export function FieldTranslationProvider(props: PropsWithChildren<{}>) {
61
69
  const {config: assistConfig} = useAiAssistanceConfig()
62
70
  const apiClient = useApiClient(assistConfig.__customApiClient)
@@ -86,7 +94,7 @@ export function FieldTranslationProvider(props: PropsWithChildren<{}>) {
86
94
  (
87
95
  from: Language,
88
96
  languages: Language[] | undefined,
89
- params: FieldTranslationParams | undefined
97
+ params: FieldTranslationParams | undefined,
90
98
  ) => {
91
99
  const {document, documentSchema} = params ?? {}
92
100
  setFromLanguage(from)
@@ -98,7 +106,7 @@ export function FieldTranslationProvider(props: PropsWithChildren<{}>) {
98
106
  const preferred = getPreferredToFieldLanguages(from.id)
99
107
  const allToLanguages = languages.filter((l) => l.id !== from?.id)
100
108
  const filteredToLanguages = allToLanguages.filter(
101
- (l) => !preferred.length || preferred.includes(l.id)
109
+ (l) => !preferred.length || preferred.includes(l.id),
102
110
  )
103
111
 
104
112
  setToLanguages(filteredToLanguages)
@@ -111,21 +119,21 @@ export function FieldTranslationProvider(props: PropsWithChildren<{}>) {
111
119
  docMembers,
112
120
  fromId,
113
121
  allToIds.filter((toId) => fromId !== toId),
114
- config?.translationOutputs ?? defaultLanguageOutputs
122
+ config?.translationOutputs ?? defaultLanguageOutputs,
115
123
  )
116
124
  setFieldLanguageMaps(transMap)
117
125
  } else {
118
126
  setFieldLanguageMaps(undefined)
119
127
  }
120
128
  },
121
- [config]
129
+ [config],
122
130
  )
123
131
 
124
132
  const toggleToLanguage = useCallback(
125
133
  (
126
134
  toggledLang: Language,
127
135
  toLanguages: Language[] | undefined,
128
- languages: Language[] | undefined
136
+ languages: Language[] | undefined,
129
137
  ) => {
130
138
  if (!languages || !fromLanguage) {
131
139
  return
@@ -134,17 +142,17 @@ export function FieldTranslationProvider(props: PropsWithChildren<{}>) {
134
142
  const newToLangs = languages.filter(
135
143
  (anyLang) =>
136
144
  !!toLanguages?.find(
137
- (selectedLang) => toggledLang.id !== selectedLang.id && selectedLang.id === anyLang.id
145
+ (selectedLang) => toggledLang.id !== selectedLang.id && selectedLang.id === anyLang.id,
138
146
  ) ||
139
- (toggledLang.id === anyLang.id && !wasSelected)
147
+ (toggledLang.id === anyLang.id && !wasSelected),
140
148
  )
141
149
  setToLanguages(newToLangs)
142
150
  setPreferredToFieldLanguages(
143
151
  fromLanguage.id,
144
- newToLangs.map((l) => l.id)
152
+ newToLangs.map((l) => l.id),
145
153
  )
146
154
  },
147
- [fromLanguage]
155
+ [fromLanguage],
148
156
  )
149
157
 
150
158
  const openFieldTranslation = useCallback(
@@ -163,7 +171,7 @@ export function FieldTranslationProvider(props: PropsWithChildren<{}>) {
163
171
  console.error('No languages available for selected language params', languageParams)
164
172
  }
165
173
  },
166
- [selectFromLanguage, config, languageClient]
174
+ [selectFromLanguage, config, languageClient],
167
175
  )
168
176
 
169
177
  const contextValue: FieldTranslationContextValue = useMemo(() => {
@@ -298,7 +306,7 @@ function ToLanguageCheckbox(props: {
298
306
  toggleToLanguage: (
299
307
  toggledLang: Language,
300
308
  toLanguages: Language[] | undefined,
301
- languages: Language[] | undefined
309
+ languages: Language[] | undefined,
302
310
  ) => void
303
311
  languages: Language[]
304
312
  }) {
@@ -306,7 +314,7 @@ function ToLanguageCheckbox(props: {
306
314
  const langId = checkboxLanguage.id
307
315
  const onChange = useCallback(
308
316
  () => toggleToLanguage(checkboxLanguage, toLanguages, languages),
309
- [toggleToLanguage, checkboxLanguage, toLanguages, languages]
317
+ [toggleToLanguage, checkboxLanguage, toLanguages, languages],
310
318
  )
311
319
  return (
312
320
  <Flex
@@ -334,7 +342,7 @@ function FromLanguageRadio(props: {
334
342
  selectFromLanguage: (
335
343
  from: Language,
336
344
  languages: Language[] | undefined,
337
- params: FieldTranslationParams | undefined
345
+ params: FieldTranslationParams | undefined,
338
346
  ) => void
339
347
  languages: Language[] | undefined
340
348
  fieldTranslationParams: FieldTranslationParams | undefined
@@ -344,7 +352,7 @@ function FromLanguageRadio(props: {
344
352
 
345
353
  const onChange = useCallback(
346
354
  () => selectFromLanguage(radioLanguage, languages, fieldTranslationParams),
347
- [selectFromLanguage, radioLanguage, languages, fieldTranslationParams]
355
+ [selectFromLanguage, radioLanguage, languages, fieldTranslationParams],
348
356
  )
349
357
  return (
350
358
  <Flex key={langId} gap={3} align="center" as={'label'}>
@@ -1,9 +1,9 @@
1
- import {SanityDocumentLike} from 'sanity'
2
- import get from 'lodash/get'
1
+ import {get} from 'lodash'
2
+ import type {SanityDocumentLike} from 'sanity'
3
3
 
4
4
  export const getLanguageParams = (
5
5
  select: Record<string, string> | undefined,
6
- document: SanityDocumentLike | undefined
6
+ document: SanityDocumentLike | undefined,
7
7
  ): Record<string, unknown> => {
8
8
  if (!select || !document) {
9
9
  return {}
@@ -16,7 +16,7 @@ export const getLanguageParams = (
16
16
  if (Array.isArray(value)) {
17
17
  // If there are references in the array, ensure they have `_ref` set, otherwise they are considered empty and can safely be ignored
18
18
  value = value.filter((item) =>
19
- typeof item === 'object' ? item?._type !== 'reference' || '_ref' in item : true
19
+ typeof item === 'object' ? item?._type !== 'reference' || '_ref' in item : true,
20
20
  )
21
21
  }
22
22
  selectedValue[key] = value
@@ -1,9 +1,16 @@
1
- import {describe, expect, test} from 'vitest'
2
1
  import {Schema} from '@sanity/schema'
3
- import {defineType, ObjectSchemaType, pathToString, SanityDocumentLike, typed} from 'sanity'
2
+ import {
3
+ defineType,
4
+ type ObjectSchemaType,
5
+ pathToString,
6
+ type SanityDocumentLike,
7
+ typed,
8
+ } from 'sanity'
9
+ import {describe, expect, test} from 'vitest'
10
+
4
11
  import {
5
12
  defaultLanguageOutputs,
6
- FieldLanguageMap,
13
+ type FieldLanguageMap,
7
14
  getDocumentMembersFlat,
8
15
  getFieldLanguageMap,
9
16
  } from './paths'
@@ -82,7 +89,7 @@ describe('paths', () => {
82
89
  inputPath: ['translations', {_key: 'en'}],
83
90
  outputs: [{id: 'nb', outputPath: ['translations', {_key: 'nb'}]}],
84
91
  },
85
- ])
92
+ ]),
86
93
  )
87
94
  })
88
95
 
@@ -1,13 +1,14 @@
1
+ import {extractWithPath} from '@sanity/mutator'
1
2
  import {
2
3
  isDocumentSchemaType,
3
4
  isKeySegment,
4
- ObjectSchemaType,
5
- Path,
5
+ type ObjectSchemaType,
6
+ type Path,
6
7
  pathToString,
7
- SanityDocumentLike,
8
+ type SanityDocumentLike,
8
9
  } from 'sanity'
9
- import {extractWithPath} from '@sanity/mutator'
10
- import {DocumentMember, TranslationOutput, TranslationOutputsFunction} from './types'
10
+
11
+ import type {DocumentMember, TranslationOutput, TranslationOutputsFunction} from './types'
11
12
 
12
13
  export interface FieldLanguageMap {
13
14
  inputLanguageId: string
@@ -30,7 +31,7 @@ function extractPaths(
30
31
  doc: SanityDocumentLike,
31
32
  schemaType: ObjectSchemaType,
32
33
  path: Path,
33
- maxDepth: number
34
+ maxDepth: number,
34
35
  ): DocumentMember[] {
35
36
  if (path.length >= maxDepth) {
36
37
  return []
@@ -75,7 +76,7 @@ function extractPaths(
75
76
  itemPath,
76
77
  item,
77
78
  itemSchema,
78
- }
79
+ },
79
80
  )
80
81
  }
81
82
  if (item._key && itemSchema) {
@@ -83,7 +84,7 @@ function extractPaths(
83
84
  doc,
84
85
  itemSchema as ObjectSchemaType,
85
86
  itemPath,
86
- maxDepth
87
+ maxDepth,
87
88
  )
88
89
  const arrayMember = {
89
90
  path: itemPath,
@@ -112,7 +113,7 @@ export const defaultLanguageOutputs: TranslationOutputsFunction = function (
112
113
  member,
113
114
  enclosingType,
114
115
  translateFromLanguageId,
115
- translateToLanguageIds
116
+ translateToLanguageIds,
116
117
  ) {
117
118
  if (
118
119
  member.schemaType.jsonType === 'object' &&
@@ -146,7 +147,7 @@ export function getFieldLanguageMap(
146
147
  documentMembers: DocumentMember[],
147
148
  translateFromLanguageId: string,
148
149
  outputLanguageIds: string[],
149
- langFn: TranslationOutputsFunction
150
+ langFn: TranslationOutputsFunction,
150
151
  ): FieldLanguageMap[] {
151
152
  const translationMaps: FieldLanguageMap[] = []
152
153
  for (const member of documentMembers) {
@@ -159,7 +160,7 @@ export function getFieldLanguageMap(
159
160
  member,
160
161
  enclosingType,
161
162
  translateFromLanguageId,
162
- outputLanguageIds
163
+ outputLanguageIds,
163
164
  )?.filter((translation) => translation.id !== translateFromLanguageId)
164
165
 
165
166
  if (translations) {
@@ -1,22 +1,23 @@
1
1
  /* eslint-disable react-hooks/rules-of-hooks */
2
- import {
2
+ import {TranslateIcon} from '@sanity/icons'
3
+ import {Box, Spinner} from '@sanity/ui'
4
+ import {useMemo, useRef} from 'react'
5
+ import type {
3
6
  DocumentFieldAction,
4
7
  DocumentFieldActionGroup,
5
8
  DocumentFieldActionItem,
6
9
  DocumentFieldActionProps,
7
10
  ObjectSchemaType,
8
11
  } from 'sanity'
9
- import {TranslateIcon} from '@sanity/icons'
10
- import {useMemo, useRef} from 'react'
11
- import {useApiClient, useTranslate} from '../useApiClient'
12
+ import {useDocumentPane} from 'sanity/structure'
13
+
14
+ import {useDraftDelayedTask} from '../assistDocument/RequestRunInstructionProvider'
12
15
  import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
13
- import {Box, Spinner} from '@sanity/ui'
14
16
  import {isAssistSupported} from '../helpers/assistSupported'
15
- import {useDocumentPane} from 'sanity/desk'
16
- import {useFieldTranslation} from './FieldTranslationProvider'
17
- import {useDraftDelayedTask} from '../assistDocument/RequestRunInstructionProvider'
18
- import {AssistOptions} from '../schemas/typeDefExtensions'
19
17
  import {getConditionalMembers} from '../helpers/conditionalMembers'
18
+ import type {AssistOptions} from '../schemas/typeDefExtensions'
19
+ import {useApiClient, useTranslate} from '../useApiClient'
20
+ import {useFieldTranslation} from './FieldTranslationProvider'
20
21
 
21
22
  function node(node: DocumentFieldActionItem | DocumentFieldActionGroup) {
22
23
  return node
@@ -163,7 +164,7 @@ export const translateActions: DocumentFieldAction = {
163
164
  fieldTransEnabled,
164
165
  path,
165
166
  readOnly,
166
- ]
167
+ ],
167
168
  )
168
169
 
169
170
  // eslint-disable-next-line react-hooks/rules-of-hooks
@@ -176,7 +177,7 @@ export const translateActions: DocumentFieldAction = {
176
177
  icon: () => null,
177
178
  title: 'Translation',
178
179
  children: [translateDocumentAction, translateFieldsAction].filter(
179
- (c): c is DocumentFieldActionItem => !!c
180
+ (c): c is DocumentFieldActionItem => !!c,
180
181
  ),
181
182
  expanded: true,
182
183
  })
@@ -22,12 +22,12 @@ export type TranslationOutputsFunction = (
22
22
  documentMember: DocumentMember,
23
23
  enclosingType: SchemaType,
24
24
  translateFromLanguageId: string,
25
- translateToLanguageIds: string[]
25
+ translateToLanguageIds: string[],
26
26
  ) => TranslationOutput[] | undefined
27
27
 
28
28
  export type LanguageCallback = (
29
29
  client: SanityClient,
30
- selectedLanguageParams: Record<string, unknown>
30
+ selectedLanguageParams: Record<string, unknown>,
31
31
  ) => Promise<Language[]>
32
32
 
33
33
  export interface FieldTranslationConfig {
@@ -47,7 +47,7 @@ export function useApiClient(customApiClient?: (defaultClient: SanityClient) =>
47
47
  const client = useClient({apiVersion: '2023-06-05'})
48
48
  return useMemo(
49
49
  () => (customApiClient ? customApiClient(client) : client),
50
- [client, customApiClient]
50
+ [client, customApiClient],
51
51
  )
52
52
  }
53
53
 
@@ -102,7 +102,7 @@ export function useTranslate(apiClient: SanityClient) {
102
102
  }, 2000)
103
103
  })
104
104
  },
105
- [setLoading, apiClient, toast, user, types]
105
+ [setLoading, apiClient, toast, user, types],
106
106
  )
107
107
 
108
108
  return useMemo(
@@ -110,7 +110,7 @@ export function useTranslate(apiClient: SanityClient) {
110
110
  translate,
111
111
  loading,
112
112
  }),
113
- [translate, loading]
113
+ [translate, loading],
114
114
  )
115
115
  }
116
116
 
@@ -155,7 +155,7 @@ export function useGenerateCaption(apiClient: SanityClient) {
155
155
  }, 2000)
156
156
  })
157
157
  },
158
- [setLoading, apiClient, toast, user, types]
158
+ [setLoading, apiClient, toast, user, types],
159
159
  )
160
160
 
161
161
  return useMemo(
@@ -163,7 +163,7 @@ export function useGenerateCaption(apiClient: SanityClient) {
163
163
  generateCaption,
164
164
  loading,
165
165
  }),
166
- [generateCaption, loading]
166
+ [generateCaption, loading],
167
167
  )
168
168
  }
169
169
 
@@ -208,7 +208,7 @@ export function useGenerateImage(apiClient: SanityClient) {
208
208
  }, 2000)
209
209
  })
210
210
  },
211
- [setLoading, apiClient, toast, user, types]
211
+ [setLoading, apiClient, toast, user, types],
212
212
  )
213
213
 
214
214
  return useMemo(
@@ -216,7 +216,7 @@ export function useGenerateImage(apiClient: SanityClient) {
216
216
  generateImage,
217
217
  loading,
218
218
  }),
219
- [generateImage, loading]
219
+ [generateImage, loading],
220
220
  )
221
221
  }
222
222
 
@@ -301,7 +301,7 @@ export function useRunInstructionApi(apiClient: SanityClient) {
301
301
  setLoading(false)
302
302
  })
303
303
  },
304
- [apiClient, types, user, toast]
304
+ [apiClient, types, user, toast],
305
305
  )
306
306
 
307
307
  return useMemo(
@@ -309,6 +309,6 @@ export function useRunInstructionApi(apiClient: SanityClient) {
309
309
  runInstruction,
310
310
  loading,
311
311
  }),
312
- [runInstruction, loading]
312
+ [runInstruction, loading],
313
313
  )
314
314
  }
@@ -1,7 +0,0 @@
1
- import cjs from './index.js';
2
-
3
- export const SchemaTypeTool = cjs.SchemaTypeTool;
4
- export const assist = cjs.assist;
5
- export const contextDocumentTypeName = cjs.contextDocumentTypeName;
6
- export const defaultLanguageOutputs = cjs.defaultLanguageOutputs;
7
-