@sanity/assist 1.2.14 → 1.2.15-lang.10

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 (334) hide show
  1. package/README.md +546 -24
  2. package/dist/index.cjs.mjs +1 -0
  3. package/dist/index.d.ts +253 -11
  4. package/dist/index.esm.js +2367 -393
  5. package/dist/index.esm.js.map +1 -1
  6. package/dist/index.js +2361 -386
  7. package/dist/index.js.map +1 -1
  8. package/package.json +15 -14
  9. package/src/_lib/form/DocumentForm.tsx +3 -2
  10. package/src/_lib/form/constants.ts +1 -0
  11. package/src/assistDocument/AssistDocumentInput.tsx +24 -4
  12. package/src/assistDocument/RequestRunInstructionProvider.tsx +37 -21
  13. package/src/assistDocument/components/instruction/InstructionInput.tsx +5 -4
  14. package/src/assistDocument/components/instruction/InstructionOutputField.tsx +45 -0
  15. package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +205 -0
  16. package/src/assistDocument/hooks/useStudioAssistDocument.ts +5 -32
  17. package/src/assistFormComponents/AssistField.tsx +11 -5
  18. package/src/assistFormComponents/AssistFormBlock.tsx +2 -3
  19. package/src/assistFormComponents/validation/listItem.tsx +2 -2
  20. package/src/assistInspector/AssistInspector.tsx +6 -0
  21. package/src/assistInspector/FieldAutocomplete.tsx +1 -0
  22. package/src/assistInspector/InstructionTaskHistoryButton.tsx +2 -3
  23. package/src/assistInspector/helpers.ts +9 -11
  24. package/src/assistLayout/AssistLayout.tsx +9 -9
  25. package/src/components/ImageContext.tsx +19 -9
  26. package/src/components/SafeValueInput.tsx +4 -1
  27. package/src/coverage/.tmp/coverage-0.json +1 -0
  28. package/src/coverage/base.css +224 -0
  29. package/src/coverage/block-navigation.js +87 -0
  30. package/src/coverage/clover.xml +8613 -0
  31. package/src/coverage/coverage-final.json +107 -0
  32. package/src/coverage/favicon.png +0 -0
  33. package/src/coverage/index.html +461 -0
  34. package/src/coverage/lcov-report/base.css +224 -0
  35. package/src/coverage/lcov-report/block-navigation.js +87 -0
  36. package/src/coverage/lcov-report/favicon.png +0 -0
  37. package/src/coverage/lcov-report/index.html +461 -0
  38. package/src/coverage/lcov-report/prettify.css +1 -0
  39. package/src/coverage/lcov-report/prettify.js +2 -0
  40. package/src/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  41. package/src/coverage/lcov-report/sorter.js +196 -0
  42. package/src/coverage/lcov-report/src/_lib/connector/ConnectFromRegion.tsx.html +157 -0
  43. package/src/coverage/lcov-report/src/_lib/connector/ConnectToRegion.tsx.html +151 -0
  44. package/src/coverage/lcov-report/src/_lib/connector/ConnectorRegion.tsx.html +154 -0
  45. package/src/coverage/lcov-report/src/_lib/connector/ConnectorsProvider.tsx.html +142 -0
  46. package/src/coverage/lcov-report/src/_lib/connector/ConnectorsStore.ts.html +451 -0
  47. package/src/coverage/lcov-report/src/_lib/connector/ConnectorsStoreContext.ts.html +97 -0
  48. package/src/coverage/lcov-report/src/_lib/connector/helpers.ts.html +100 -0
  49. package/src/coverage/lcov-report/src/_lib/connector/index.html +281 -0
  50. package/src/coverage/lcov-report/src/_lib/connector/index.ts.html +112 -0
  51. package/src/coverage/lcov-report/src/_lib/connector/mapConnectorToLine.ts.html +334 -0
  52. package/src/coverage/lcov-report/src/_lib/connector/types.ts.html +253 -0
  53. package/src/coverage/lcov-report/src/_lib/connector/useConnectorsStore.ts.html +124 -0
  54. package/src/coverage/lcov-report/src/_lib/connector/useRegionRects.ts.html +508 -0
  55. package/src/coverage/lcov-report/src/_lib/fixedListenQuery.ts.html +388 -0
  56. package/src/coverage/lcov-report/src/_lib/form/DocumentForm.tsx.html +676 -0
  57. package/src/coverage/lcov-report/src/_lib/form/helpers.ts.html +178 -0
  58. package/src/coverage/lcov-report/src/_lib/form/index.html +146 -0
  59. package/src/coverage/lcov-report/src/_lib/form/index.ts.html +88 -0
  60. package/src/coverage/lcov-report/src/_lib/index.html +161 -0
  61. package/src/coverage/lcov-report/src/_lib/randomKey.ts.html +172 -0
  62. package/src/coverage/lcov-report/src/_lib/useListeningQuery.ts.html +268 -0
  63. package/src/coverage/lcov-report/src/_lib/usePrevious.ts.html +112 -0
  64. package/src/coverage/lcov-report/src/assistConnectors/AssistConnectorsOverlay.tsx.html +481 -0
  65. package/src/coverage/lcov-report/src/assistConnectors/ConnectorPath.tsx.html +271 -0
  66. package/src/coverage/lcov-report/src/assistConnectors/draw/arrowPath.ts.html +112 -0
  67. package/src/coverage/lcov-report/src/assistConnectors/draw/connectorPath.ts.html +511 -0
  68. package/src/coverage/lcov-report/src/assistConnectors/draw/index.html +131 -0
  69. package/src/coverage/lcov-report/src/assistConnectors/index.html +146 -0
  70. package/src/coverage/lcov-report/src/assistConnectors/index.ts.html +88 -0
  71. package/src/coverage/lcov-report/src/assistDocument/AssistDocumentContext.tsx.html +178 -0
  72. package/src/coverage/lcov-report/src/assistDocument/AssistDocumentContextProvider.tsx.html +136 -0
  73. package/src/coverage/lcov-report/src/assistDocument/AssistDocumentInput.tsx.html +280 -0
  74. package/src/coverage/lcov-report/src/assistDocument/RequestRunInstructionProvider.tsx.html +283 -0
  75. package/src/coverage/lcov-report/src/assistDocument/components/AssistDocumentForm.tsx.html +775 -0
  76. package/src/coverage/lcov-report/src/assistDocument/components/FieldRefPreview.tsx.html +166 -0
  77. package/src/coverage/lcov-report/src/assistDocument/components/InstructionsArrayField.tsx.html +109 -0
  78. package/src/coverage/lcov-report/src/assistDocument/components/InstructionsArrayInput.tsx.html +163 -0
  79. package/src/coverage/lcov-report/src/assistDocument/components/SelectedFieldContext.tsx.html +115 -0
  80. package/src/coverage/lcov-report/src/assistDocument/components/generic/HiddenFieldTitle.tsx.html +100 -0
  81. package/src/coverage/lcov-report/src/assistDocument/components/generic/index.html +116 -0
  82. package/src/coverage/lcov-report/src/assistDocument/components/helpers.ts.html +148 -0
  83. package/src/coverage/lcov-report/src/assistDocument/components/index.html +191 -0
  84. package/src/coverage/lcov-report/src/assistDocument/components/instruction/BackToInstructionsLink.tsx.html +178 -0
  85. package/src/coverage/lcov-report/src/assistDocument/components/instruction/FieldRefInput.tsx.html +244 -0
  86. package/src/coverage/lcov-report/src/assistDocument/components/instruction/InstructionInput.tsx.html +349 -0
  87. package/src/coverage/lcov-report/src/assistDocument/components/instruction/InstructionOutputField.tsx.html +220 -0
  88. package/src/coverage/lcov-report/src/assistDocument/components/instruction/InstructionOutputInput.tsx.html +700 -0
  89. package/src/coverage/lcov-report/src/assistDocument/components/instruction/PromptInput.tsx.html +241 -0
  90. package/src/coverage/lcov-report/src/assistDocument/components/instruction/appearance/IconInput.tsx.html +223 -0
  91. package/src/coverage/lcov-report/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx.html +196 -0
  92. package/src/coverage/lcov-report/src/assistDocument/components/instruction/appearance/index.html +131 -0
  93. package/src/coverage/lcov-report/src/assistDocument/components/instruction/index.html +191 -0
  94. package/src/coverage/lcov-report/src/assistDocument/hooks/index.html +161 -0
  95. package/src/coverage/lcov-report/src/assistDocument/hooks/useAssistDocumentContextValue.tsx.html +289 -0
  96. package/src/coverage/lcov-report/src/assistDocument/hooks/useDocumentState.ts.html +103 -0
  97. package/src/coverage/lcov-report/src/assistDocument/hooks/useInstructionToaster.tsx.html +307 -0
  98. package/src/coverage/lcov-report/src/assistDocument/hooks/useStudioAssistDocument.ts.html +379 -0
  99. package/src/coverage/lcov-report/src/assistDocument/index.html +176 -0
  100. package/src/coverage/lcov-report/src/assistDocument/index.ts.html +88 -0
  101. package/src/coverage/lcov-report/src/assistFormComponents/AssistField.tsx.html +301 -0
  102. package/src/coverage/lcov-report/src/assistFormComponents/AssistFormBlock.tsx.html +175 -0
  103. package/src/coverage/lcov-report/src/assistFormComponents/AssistInlineFormBlock.tsx.html +124 -0
  104. package/src/coverage/lcov-report/src/assistFormComponents/AssistItem.tsx.html +145 -0
  105. package/src/coverage/lcov-report/src/assistFormComponents/index.html +161 -0
  106. package/src/coverage/lcov-report/src/assistFormComponents/validation/index.html +131 -0
  107. package/src/coverage/lcov-report/src/assistFormComponents/validation/listItem.tsx.html +274 -0
  108. package/src/coverage/lcov-report/src/assistFormComponents/validation/validationList.tsx.html +352 -0
  109. package/src/coverage/lcov-report/src/assistInspector/AssistInspector.tsx.html +1318 -0
  110. package/src/coverage/lcov-report/src/assistInspector/FieldAutocomplete.tsx.html +505 -0
  111. package/src/coverage/lcov-report/src/assistInspector/InstructionTaskHistoryButton.tsx.html +865 -0
  112. package/src/coverage/lcov-report/src/assistInspector/constants.ts.html +88 -0
  113. package/src/coverage/lcov-report/src/assistInspector/helpers.ts.html +724 -0
  114. package/src/coverage/lcov-report/src/assistInspector/index.html +191 -0
  115. package/src/coverage/lcov-report/src/assistInspector/index.ts.html +163 -0
  116. package/src/coverage/lcov-report/src/assistLayout/AiAssistanceConfigContext.tsx.html +331 -0
  117. package/src/coverage/lcov-report/src/assistLayout/AssistLayout.tsx.html +199 -0
  118. package/src/coverage/lcov-report/src/assistLayout/RunInstructionProvider.tsx.html +751 -0
  119. package/src/coverage/lcov-report/src/assistLayout/index.html +146 -0
  120. package/src/coverage/lcov-report/src/components/AssistFeatureBadge.tsx.html +112 -0
  121. package/src/coverage/lcov-report/src/components/FadeInContent.tsx.html +205 -0
  122. package/src/coverage/lcov-report/src/components/HideReferenceChangedBannerInput.tsx.html +160 -0
  123. package/src/coverage/lcov-report/src/components/ImageContext.tsx.html +229 -0
  124. package/src/coverage/lcov-report/src/components/SafeValueInput.tsx.html +313 -0
  125. package/src/coverage/lcov-report/src/components/TimeAgo.tsx.html +139 -0
  126. package/src/coverage/lcov-report/src/components/index.html +191 -0
  127. package/src/coverage/lcov-report/src/constants.ts.html +145 -0
  128. package/src/coverage/lcov-report/src/fieldActions/PrivateIcon.tsx.html +145 -0
  129. package/src/coverage/lcov-report/src/fieldActions/assistFieldActions.tsx.html +907 -0
  130. package/src/coverage/lcov-report/src/fieldActions/generateCaptionActions.tsx.html +259 -0
  131. package/src/coverage/lcov-report/src/fieldActions/generateImageActions.tsx.html +256 -0
  132. package/src/coverage/lcov-report/src/fieldActions/index.html +161 -0
  133. package/src/coverage/lcov-report/src/helpers/assistSupported.ts.html +226 -0
  134. package/src/coverage/lcov-report/src/helpers/conditionalMembers.ts.html +466 -0
  135. package/src/coverage/lcov-report/src/helpers/ids.ts.html +142 -0
  136. package/src/coverage/lcov-report/src/helpers/index.html +191 -0
  137. package/src/coverage/lcov-report/src/helpers/misc.ts.html +133 -0
  138. package/src/coverage/lcov-report/src/helpers/typeUtils.ts.html +208 -0
  139. package/src/coverage/lcov-report/src/helpers/useAssistSupported.ts.html +106 -0
  140. package/src/coverage/lcov-report/src/index.html +176 -0
  141. package/src/coverage/lcov-report/src/index.ts.html +112 -0
  142. package/src/coverage/lcov-report/src/onboarding/FieldActionsOnboarding.tsx.html +286 -0
  143. package/src/coverage/lcov-report/src/onboarding/FirstAssistedPathProvider.tsx.html +172 -0
  144. package/src/coverage/lcov-report/src/onboarding/InspectorOnboarding.tsx.html +223 -0
  145. package/src/coverage/lcov-report/src/onboarding/index.html +161 -0
  146. package/src/coverage/lcov-report/src/onboarding/onboardingStore.ts.html +184 -0
  147. package/src/coverage/lcov-report/src/plugin.tsx.html +427 -0
  148. package/src/coverage/lcov-report/src/presence/AiFieldPresence.tsx.html +163 -0
  149. package/src/coverage/lcov-report/src/presence/AssistAvatar.tsx.html +373 -0
  150. package/src/coverage/lcov-report/src/presence/AssistDocumentPresence.tsx.html +259 -0
  151. package/src/coverage/lcov-report/src/presence/index.html +161 -0
  152. package/src/coverage/lcov-report/src/presence/useAssistPresence.ts.html +268 -0
  153. package/src/coverage/lcov-report/src/schemas/assistDocumentSchema.tsx.html +1552 -0
  154. package/src/coverage/lcov-report/src/schemas/contextDocumentSchema.tsx.html +253 -0
  155. package/src/coverage/lcov-report/src/schemas/index.html +176 -0
  156. package/src/coverage/lcov-report/src/schemas/index.ts.html +277 -0
  157. package/src/coverage/lcov-report/src/schemas/serialize/SchemTypeTool.tsx.html +391 -0
  158. package/src/coverage/lcov-report/src/schemas/serialize/index.html +146 -0
  159. package/src/coverage/lcov-report/src/schemas/serialize/schemaUtils.ts.html +196 -0
  160. package/src/coverage/lcov-report/src/schemas/serialize/serializeSchema.ts.html +754 -0
  161. package/src/coverage/lcov-report/src/schemas/serializedSchemaTypeSchema.ts.html +262 -0
  162. package/src/coverage/lcov-report/src/schemas/typeDefExtensions.ts.html +397 -0
  163. package/src/coverage/lcov-report/src/translate/FieldTranslationProvider.tsx.html +1003 -0
  164. package/src/coverage/lcov-report/src/translate/getLanguageParams.ts.html +163 -0
  165. package/src/coverage/lcov-report/src/translate/index.html +191 -0
  166. package/src/coverage/lcov-report/src/translate/languageStore.ts.html +139 -0
  167. package/src/coverage/lcov-report/src/translate/paths.ts.html +577 -0
  168. package/src/coverage/lcov-report/src/translate/translateActions.tsx.html +637 -0
  169. package/src/coverage/lcov-report/src/translate/types.ts.html +565 -0
  170. package/src/coverage/lcov-report/src/types.ts.html +649 -0
  171. package/src/coverage/lcov-report/src/useApiClient.ts.html +1015 -0
  172. package/src/coverage/lcov.info +9519 -0
  173. package/src/coverage/prettify.css +1 -0
  174. package/src/coverage/prettify.js +2 -0
  175. package/src/coverage/sort-arrow-sprite.png +0 -0
  176. package/src/coverage/sorter.js +196 -0
  177. package/src/coverage/src/_lib/connector/ConnectFromRegion.tsx.html +157 -0
  178. package/src/coverage/src/_lib/connector/ConnectToRegion.tsx.html +151 -0
  179. package/src/coverage/src/_lib/connector/ConnectorRegion.tsx.html +154 -0
  180. package/src/coverage/src/_lib/connector/ConnectorsProvider.tsx.html +142 -0
  181. package/src/coverage/src/_lib/connector/ConnectorsStore.ts.html +451 -0
  182. package/src/coverage/src/_lib/connector/ConnectorsStoreContext.ts.html +97 -0
  183. package/src/coverage/src/_lib/connector/helpers.ts.html +100 -0
  184. package/src/coverage/src/_lib/connector/index.html +281 -0
  185. package/src/coverage/src/_lib/connector/index.ts.html +112 -0
  186. package/src/coverage/src/_lib/connector/mapConnectorToLine.ts.html +334 -0
  187. package/src/coverage/src/_lib/connector/types.ts.html +253 -0
  188. package/src/coverage/src/_lib/connector/useConnectorsStore.ts.html +124 -0
  189. package/src/coverage/src/_lib/connector/useRegionRects.ts.html +508 -0
  190. package/src/coverage/src/_lib/fixedListenQuery.ts.html +388 -0
  191. package/src/coverage/src/_lib/form/DocumentForm.tsx.html +676 -0
  192. package/src/coverage/src/_lib/form/helpers.ts.html +178 -0
  193. package/src/coverage/src/_lib/form/index.html +146 -0
  194. package/src/coverage/src/_lib/form/index.ts.html +88 -0
  195. package/src/coverage/src/_lib/index.html +161 -0
  196. package/src/coverage/src/_lib/randomKey.ts.html +172 -0
  197. package/src/coverage/src/_lib/useListeningQuery.ts.html +268 -0
  198. package/src/coverage/src/_lib/usePrevious.ts.html +112 -0
  199. package/src/coverage/src/assistConnectors/AssistConnectorsOverlay.tsx.html +481 -0
  200. package/src/coverage/src/assistConnectors/ConnectorPath.tsx.html +271 -0
  201. package/src/coverage/src/assistConnectors/draw/arrowPath.ts.html +112 -0
  202. package/src/coverage/src/assistConnectors/draw/connectorPath.ts.html +511 -0
  203. package/src/coverage/src/assistConnectors/draw/index.html +131 -0
  204. package/src/coverage/src/assistConnectors/index.html +146 -0
  205. package/src/coverage/src/assistConnectors/index.ts.html +88 -0
  206. package/src/coverage/src/assistDocument/AssistDocumentContext.tsx.html +178 -0
  207. package/src/coverage/src/assistDocument/AssistDocumentContextProvider.tsx.html +136 -0
  208. package/src/coverage/src/assistDocument/AssistDocumentInput.tsx.html +280 -0
  209. package/src/coverage/src/assistDocument/RequestRunInstructionProvider.tsx.html +283 -0
  210. package/src/coverage/src/assistDocument/components/AssistDocumentForm.tsx.html +775 -0
  211. package/src/coverage/src/assistDocument/components/FieldRefPreview.tsx.html +166 -0
  212. package/src/coverage/src/assistDocument/components/InstructionsArrayField.tsx.html +109 -0
  213. package/src/coverage/src/assistDocument/components/InstructionsArrayInput.tsx.html +163 -0
  214. package/src/coverage/src/assistDocument/components/SelectedFieldContext.tsx.html +115 -0
  215. package/src/coverage/src/assistDocument/components/generic/HiddenFieldTitle.tsx.html +100 -0
  216. package/src/coverage/src/assistDocument/components/generic/index.html +116 -0
  217. package/src/coverage/src/assistDocument/components/helpers.ts.html +148 -0
  218. package/src/coverage/src/assistDocument/components/index.html +191 -0
  219. package/src/coverage/src/assistDocument/components/instruction/BackToInstructionsLink.tsx.html +178 -0
  220. package/src/coverage/src/assistDocument/components/instruction/FieldRefInput.tsx.html +244 -0
  221. package/src/coverage/src/assistDocument/components/instruction/InstructionInput.tsx.html +349 -0
  222. package/src/coverage/src/assistDocument/components/instruction/InstructionOutputField.tsx.html +220 -0
  223. package/src/coverage/src/assistDocument/components/instruction/InstructionOutputInput.tsx.html +700 -0
  224. package/src/coverage/src/assistDocument/components/instruction/PromptInput.tsx.html +241 -0
  225. package/src/coverage/src/assistDocument/components/instruction/appearance/IconInput.tsx.html +223 -0
  226. package/src/coverage/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx.html +196 -0
  227. package/src/coverage/src/assistDocument/components/instruction/appearance/index.html +131 -0
  228. package/src/coverage/src/assistDocument/components/instruction/index.html +191 -0
  229. package/src/coverage/src/assistDocument/hooks/index.html +161 -0
  230. package/src/coverage/src/assistDocument/hooks/useAssistDocumentContextValue.tsx.html +289 -0
  231. package/src/coverage/src/assistDocument/hooks/useDocumentState.ts.html +103 -0
  232. package/src/coverage/src/assistDocument/hooks/useInstructionToaster.tsx.html +307 -0
  233. package/src/coverage/src/assistDocument/hooks/useStudioAssistDocument.ts.html +379 -0
  234. package/src/coverage/src/assistDocument/index.html +176 -0
  235. package/src/coverage/src/assistDocument/index.ts.html +88 -0
  236. package/src/coverage/src/assistFormComponents/AssistField.tsx.html +301 -0
  237. package/src/coverage/src/assistFormComponents/AssistFormBlock.tsx.html +175 -0
  238. package/src/coverage/src/assistFormComponents/AssistInlineFormBlock.tsx.html +124 -0
  239. package/src/coverage/src/assistFormComponents/AssistItem.tsx.html +145 -0
  240. package/src/coverage/src/assistFormComponents/index.html +161 -0
  241. package/src/coverage/src/assistFormComponents/validation/index.html +131 -0
  242. package/src/coverage/src/assistFormComponents/validation/listItem.tsx.html +274 -0
  243. package/src/coverage/src/assistFormComponents/validation/validationList.tsx.html +352 -0
  244. package/src/coverage/src/assistInspector/AssistInspector.tsx.html +1318 -0
  245. package/src/coverage/src/assistInspector/FieldAutocomplete.tsx.html +505 -0
  246. package/src/coverage/src/assistInspector/InstructionTaskHistoryButton.tsx.html +865 -0
  247. package/src/coverage/src/assistInspector/constants.ts.html +88 -0
  248. package/src/coverage/src/assistInspector/helpers.ts.html +724 -0
  249. package/src/coverage/src/assistInspector/index.html +191 -0
  250. package/src/coverage/src/assistInspector/index.ts.html +163 -0
  251. package/src/coverage/src/assistLayout/AiAssistanceConfigContext.tsx.html +331 -0
  252. package/src/coverage/src/assistLayout/AssistLayout.tsx.html +199 -0
  253. package/src/coverage/src/assistLayout/RunInstructionProvider.tsx.html +751 -0
  254. package/src/coverage/src/assistLayout/index.html +146 -0
  255. package/src/coverage/src/components/AssistFeatureBadge.tsx.html +112 -0
  256. package/src/coverage/src/components/FadeInContent.tsx.html +205 -0
  257. package/src/coverage/src/components/HideReferenceChangedBannerInput.tsx.html +160 -0
  258. package/src/coverage/src/components/ImageContext.tsx.html +229 -0
  259. package/src/coverage/src/components/SafeValueInput.tsx.html +313 -0
  260. package/src/coverage/src/components/TimeAgo.tsx.html +139 -0
  261. package/src/coverage/src/components/index.html +191 -0
  262. package/src/coverage/src/constants.ts.html +145 -0
  263. package/src/coverage/src/fieldActions/PrivateIcon.tsx.html +145 -0
  264. package/src/coverage/src/fieldActions/assistFieldActions.tsx.html +907 -0
  265. package/src/coverage/src/fieldActions/generateCaptionActions.tsx.html +259 -0
  266. package/src/coverage/src/fieldActions/generateImageActions.tsx.html +256 -0
  267. package/src/coverage/src/fieldActions/index.html +161 -0
  268. package/src/coverage/src/helpers/assistSupported.ts.html +226 -0
  269. package/src/coverage/src/helpers/conditionalMembers.ts.html +466 -0
  270. package/src/coverage/src/helpers/ids.ts.html +142 -0
  271. package/src/coverage/src/helpers/index.html +191 -0
  272. package/src/coverage/src/helpers/misc.ts.html +133 -0
  273. package/src/coverage/src/helpers/typeUtils.ts.html +208 -0
  274. package/src/coverage/src/helpers/useAssistSupported.ts.html +106 -0
  275. package/src/coverage/src/index.html +176 -0
  276. package/src/coverage/src/index.ts.html +112 -0
  277. package/src/coverage/src/onboarding/FieldActionsOnboarding.tsx.html +286 -0
  278. package/src/coverage/src/onboarding/FirstAssistedPathProvider.tsx.html +172 -0
  279. package/src/coverage/src/onboarding/InspectorOnboarding.tsx.html +223 -0
  280. package/src/coverage/src/onboarding/index.html +161 -0
  281. package/src/coverage/src/onboarding/onboardingStore.ts.html +184 -0
  282. package/src/coverage/src/plugin.tsx.html +427 -0
  283. package/src/coverage/src/presence/AiFieldPresence.tsx.html +163 -0
  284. package/src/coverage/src/presence/AssistAvatar.tsx.html +373 -0
  285. package/src/coverage/src/presence/AssistDocumentPresence.tsx.html +259 -0
  286. package/src/coverage/src/presence/index.html +161 -0
  287. package/src/coverage/src/presence/useAssistPresence.ts.html +268 -0
  288. package/src/coverage/src/schemas/assistDocumentSchema.tsx.html +1552 -0
  289. package/src/coverage/src/schemas/contextDocumentSchema.tsx.html +253 -0
  290. package/src/coverage/src/schemas/index.html +176 -0
  291. package/src/coverage/src/schemas/index.ts.html +277 -0
  292. package/src/coverage/src/schemas/serialize/SchemTypeTool.tsx.html +391 -0
  293. package/src/coverage/src/schemas/serialize/index.html +146 -0
  294. package/src/coverage/src/schemas/serialize/schemaUtils.ts.html +196 -0
  295. package/src/coverage/src/schemas/serialize/serializeSchema.ts.html +754 -0
  296. package/src/coverage/src/schemas/serializedSchemaTypeSchema.ts.html +262 -0
  297. package/src/coverage/src/schemas/typeDefExtensions.ts.html +397 -0
  298. package/src/coverage/src/translate/FieldTranslationProvider.tsx.html +1003 -0
  299. package/src/coverage/src/translate/getLanguageParams.ts.html +163 -0
  300. package/src/coverage/src/translate/index.html +191 -0
  301. package/src/coverage/src/translate/languageStore.ts.html +139 -0
  302. package/src/coverage/src/translate/paths.ts.html +577 -0
  303. package/src/coverage/src/translate/translateActions.tsx.html +637 -0
  304. package/src/coverage/src/translate/types.ts.html +565 -0
  305. package/src/coverage/src/types.ts.html +649 -0
  306. package/src/coverage/src/useApiClient.ts.html +1015 -0
  307. package/src/fieldActions/assistFieldActions.tsx +42 -13
  308. package/src/fieldActions/generateCaptionActions.tsx +2 -2
  309. package/src/fieldActions/generateImageActions.tsx +57 -0
  310. package/src/helpers/assistSupported.ts +10 -16
  311. package/src/helpers/conditionalMembers.test.ts +200 -0
  312. package/src/helpers/conditionalMembers.ts +127 -0
  313. package/src/helpers/typeUtils.ts +19 -5
  314. package/src/index.ts +3 -0
  315. package/src/node_modules/.vitest/deps/_metadata.json +8 -0
  316. package/src/node_modules/.vitest/deps/package.json +3 -0
  317. package/src/node_modules/.vitest/results.json +1 -0
  318. package/src/plugin.tsx +14 -5
  319. package/src/presence/AssistAvatar.tsx +1 -1
  320. package/src/schemas/assistDocumentSchema.tsx +40 -1
  321. package/src/schemas/serialize/serializeSchema.test.ts +239 -8
  322. package/src/schemas/serialize/serializeSchema.ts +77 -10
  323. package/src/schemas/typeDefExtensions.ts +89 -5
  324. package/src/translate/FieldTranslationProvider.tsx +306 -0
  325. package/src/translate/getLanguageParams.ts +26 -0
  326. package/src/translate/languageStore.ts +18 -0
  327. package/src/translate/paths.test.ts +133 -0
  328. package/src/translate/paths.ts +175 -0
  329. package/src/translate/translateActions.tsx +186 -0
  330. package/src/translate/types.ts +160 -0
  331. package/src/types.ts +33 -12
  332. package/src/useApiClient.ts +130 -2
  333. package/src/assistLayout/AlphaMigration.tsx +0 -310
  334. package/src/legacy-types.ts +0 -72
@@ -0,0 +1,306 @@
1
+ import {
2
+ createContext,
3
+ PropsWithChildren,
4
+ useCallback,
5
+ useContext,
6
+ useId,
7
+ useMemo,
8
+ useState,
9
+ } from 'react'
10
+ import {ObjectSchemaType, Path, pathToString, SanityDocumentLike, useClient} from 'sanity'
11
+ import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
12
+ import {useApiClient, useTranslate} from '../useApiClient'
13
+ import {Box, Button, Checkbox, Dialog, Flex, Radio, Spinner, Stack, Text, Tooltip} from '@sanity/ui'
14
+ import {
15
+ defaultLanguageOutputs,
16
+ FieldLanguageMap,
17
+ getDocumentMembersFlat,
18
+ getFieldLanguageMap,
19
+ } 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'
25
+
26
+ interface FieldTranslationParams {
27
+ document: SanityDocumentLike
28
+ documentSchema: ObjectSchemaType
29
+ translatePath: Path
30
+ conditionalMembers: ConditionalMemberState[]
31
+ }
32
+
33
+ export interface FieldTranslationContextValue {
34
+ openFieldTranslation: (args: FieldTranslationParams) => void
35
+ translationLoading: boolean
36
+ }
37
+
38
+ export const FieldTranslationContext = createContext<FieldTranslationContextValue>({
39
+ openFieldTranslation: () => {},
40
+ translationLoading: false,
41
+ })
42
+
43
+ export function useFieldTranslation() {
44
+ return useContext(FieldTranslationContext)
45
+ }
46
+
47
+ function hasValuesToTranslate(
48
+ fieldLanguageMaps: FieldLanguageMap[] | undefined,
49
+ fromLanguage: Language | undefined,
50
+ basePath: Path
51
+ ) {
52
+ return fieldLanguageMaps?.some(
53
+ (map) =>
54
+ map.inputLanguageId === fromLanguage?.id &&
55
+ map.inputPath &&
56
+ pathToString(map.inputPath).startsWith(pathToString(basePath))
57
+ )
58
+ }
59
+
60
+ export function FieldTranslationProvider(props: PropsWithChildren<{}>) {
61
+ const {config: assistConfig} = useAiAssistanceConfig()
62
+ const apiClient = useApiClient(assistConfig.__customApiClient)
63
+ const config = assistConfig.translate?.field
64
+ const {translate: runTranslate} = useTranslate(apiClient)
65
+
66
+ const [dialogOpen, setDialogOpen] = useState(false)
67
+
68
+ const [fieldTranslationParams, setFieldTranslationParams] = useState<
69
+ FieldTranslationParams | undefined
70
+ >()
71
+ const [languages, setLanguages] = useState<Language[] | undefined>()
72
+ const [fromLanguage, setFromLanguage] = useState<Language | undefined>(undefined)
73
+ const [toLanguages, setToLanguages] = useState<Language[] | undefined>(undefined)
74
+ const [fieldLanguageMaps, setFieldLanguageMaps] = useState<FieldLanguageMap[] | undefined>()
75
+
76
+ const close = useCallback(() => {
77
+ setDialogOpen(false)
78
+ setLanguages(undefined)
79
+ setFieldTranslationParams(undefined)
80
+ }, [])
81
+ const languageClient = useClient({apiVersion: config?.apiVersion ?? '2022-11-27'})
82
+ const documentId = fieldTranslationParams?.document?._id
83
+ const id = useId()
84
+
85
+ const selectFromLanguage = useCallback(
86
+ (
87
+ from: Language,
88
+ languages: Language[] | undefined,
89
+ params: FieldTranslationParams | undefined
90
+ ) => {
91
+ const {document, documentSchema} = params ?? {}
92
+ setFromLanguage(from)
93
+ if (!document || !documentSchema || !params || !languages) {
94
+ setFieldLanguageMaps(undefined)
95
+ return
96
+ }
97
+
98
+ const preferred = getPreferredToFieldLanguages(from.id)
99
+ const allToLanguages = languages.filter((l) => l.id !== from?.id)
100
+ const filteredToLanguages = allToLanguages.filter(
101
+ (l) => !preferred.length || preferred.includes(l.id)
102
+ )
103
+
104
+ setToLanguages(filteredToLanguages)
105
+ const fromId = from?.id
106
+ const allToIds = allToLanguages?.map((l) => l.id) ?? []
107
+ const docMembers = getDocumentMembersFlat(document, documentSchema)
108
+ if (fromId && allToIds?.length) {
109
+ const transMap = getFieldLanguageMap(
110
+ documentSchema,
111
+ docMembers,
112
+ fromId,
113
+ allToIds.filter((toId) => fromId !== toId),
114
+ config?.translationOutputs ?? defaultLanguageOutputs
115
+ )
116
+ setFieldLanguageMaps(transMap)
117
+ } else {
118
+ setFieldLanguageMaps(undefined)
119
+ }
120
+ },
121
+ [config]
122
+ )
123
+
124
+ const toggleToLanguage = useCallback(
125
+ (
126
+ toggledLang: Language,
127
+ toLanguages: Language[] | undefined,
128
+ languages: Language[] | undefined
129
+ ) => {
130
+ if (!languages || !fromLanguage) {
131
+ return
132
+ }
133
+ const wasSelected = !!toLanguages?.find((l) => l.id === toggledLang.id)
134
+ const newToLangs = languages.filter(
135
+ (anyLang) =>
136
+ !!toLanguages?.find(
137
+ (selectedLang) => toggledLang.id !== selectedLang.id && selectedLang.id === anyLang.id
138
+ ) ||
139
+ (toggledLang.id === anyLang.id && !wasSelected)
140
+ )
141
+ setToLanguages(newToLangs)
142
+ setPreferredToFieldLanguages(
143
+ fromLanguage.id,
144
+ newToLangs.map((l) => l.id)
145
+ )
146
+ },
147
+ [fromLanguage]
148
+ )
149
+
150
+ const openFieldTranslation = useCallback(
151
+ async (params: FieldTranslationParams) => {
152
+ setDialogOpen(true)
153
+ const languageParams = getLanguageParams(config?.selectLanguageParams, params.document)
154
+ const languages: Language[] | undefined = await (typeof config?.languages === 'function'
155
+ ? config?.languages(languageClient, languageParams)
156
+ : Promise.resolve(config?.languages))
157
+ setLanguages(languages)
158
+ setFieldTranslationParams(params)
159
+ const fromLanguage = languages?.[0]
160
+ if (fromLanguage) {
161
+ selectFromLanguage(fromLanguage, languages, params)
162
+ } else {
163
+ console.error('No languages available for selected language params', languageParams)
164
+ }
165
+ },
166
+ [selectFromLanguage, config, languageClient]
167
+ )
168
+
169
+ const contextValue: FieldTranslationContextValue = useMemo(() => {
170
+ return {
171
+ openFieldTranslation,
172
+ translationLoading: false,
173
+ }
174
+ }, [openFieldTranslation])
175
+
176
+ const runDisabled =
177
+ !fromLanguage ||
178
+ !toLanguages?.length ||
179
+ !fieldLanguageMaps?.length ||
180
+ !documentId ||
181
+ !hasValuesToTranslate(fieldLanguageMaps, fromLanguage, fieldTranslationParams.translatePath)
182
+
183
+ const onRunTranslation = useCallback(() => {
184
+ const translatePath = fieldTranslationParams?.translatePath
185
+ if (fieldLanguageMaps && documentId && translatePath) {
186
+ runTranslate({
187
+ documentId,
188
+ translatePath: translatePath,
189
+ fieldLanguageMap: fieldLanguageMaps.map((map) => ({
190
+ ...map,
191
+ // eslint-disable-next-line max-nested-callbacks
192
+ outputs: map.outputs.filter((out) => !!toLanguages?.find((l) => l.id === out.id)),
193
+ })),
194
+ conditionalMembers: fieldTranslationParams?.conditionalMembers,
195
+ })
196
+ }
197
+ close()
198
+ }, [
199
+ fieldLanguageMaps,
200
+ documentId,
201
+ runTranslate,
202
+ close,
203
+ toLanguages,
204
+ fieldTranslationParams?.translatePath,
205
+ ])
206
+
207
+ const runButton = (
208
+ <Button
209
+ text={`Translate`}
210
+ tone="primary"
211
+ icon={PlayIcon}
212
+ style={{width: '100%'}}
213
+ disabled={runDisabled}
214
+ onClick={onRunTranslation}
215
+ />
216
+ )
217
+
218
+ return (
219
+ <FieldTranslationContext.Provider value={contextValue}>
220
+ {dialogOpen ? (
221
+ <Dialog
222
+ id={id}
223
+ width={1}
224
+ open={dialogOpen}
225
+ onClose={close}
226
+ header="Translate fields"
227
+ footer={
228
+ <Flex justify="space-between" padding={2} flex={1}>
229
+ {runDisabled ? (
230
+ <Tooltip
231
+ content={
232
+ <Flex padding={2}>
233
+ <Text>There is nothing to translate in the selected from-language.</Text>
234
+ </Flex>
235
+ }
236
+ placement="top"
237
+ >
238
+ <Flex flex={1}>{runButton}</Flex>
239
+ </Tooltip>
240
+ ) : (
241
+ runButton
242
+ )}
243
+ </Flex>
244
+ }
245
+ >
246
+ {languages ? (
247
+ <Flex padding={4} gap={5} align="flex-start" justify="center">
248
+ <Stack space={2}>
249
+ <Box marginBottom={2}>
250
+ <Text weight="semibold">From</Text>
251
+ </Box>
252
+ {languages?.map((l) => {
253
+ return (
254
+ <Flex key={l.id} gap={3} align="center" as={'label'}>
255
+ <Radio
256
+ name="fromLang"
257
+ value={l.id}
258
+ checked={l.id === fromLanguage?.id}
259
+ onChange={() => selectFromLanguage(l, languages, fieldTranslationParams)}
260
+ />
261
+ <Text>{l.title ?? l.id}</Text>
262
+ </Flex>
263
+ )
264
+ })}
265
+ </Stack>
266
+
267
+ <Stack space={2}>
268
+ <Box marginBottom={2}>
269
+ <Text weight="semibold">To</Text>
270
+ </Box>
271
+ {languages.map((l) => (
272
+ <Flex
273
+ key={l.id}
274
+ gap={3}
275
+ align="center"
276
+ as={'label'}
277
+ style={l.id === fromLanguage?.id ? {opacity: 0.5} : undefined}
278
+ >
279
+ <Checkbox
280
+ name="toLang"
281
+ value={l.id}
282
+ checked={
283
+ l.id !== fromLanguage?.id && !!toLanguages?.find((tl) => tl.id === l.id)
284
+ }
285
+ onChange={() => toggleToLanguage(l, toLanguages, languages)}
286
+ disabled={l.id === fromLanguage?.id}
287
+ />
288
+ <Text muted={l.id === fromLanguage?.id}>{l.title ?? l.id}</Text>
289
+ </Flex>
290
+ ))}
291
+ </Stack>
292
+ </Flex>
293
+ ) : (
294
+ <Flex padding={4} gap={2} align="flex-start" justify="center">
295
+ <Box>
296
+ <Spinner />
297
+ </Box>
298
+ <Text>Loading languages...</Text>
299
+ </Flex>
300
+ )}
301
+ </Dialog>
302
+ ) : null}
303
+ {props.children}
304
+ </FieldTranslationContext.Provider>
305
+ )
306
+ }
@@ -0,0 +1,26 @@
1
+ import {SanityDocumentLike} from 'sanity'
2
+ import get from 'lodash/get'
3
+
4
+ export const getLanguageParams = (
5
+ select: Record<string, string> | undefined,
6
+ document: SanityDocumentLike | undefined
7
+ ): Record<string, unknown> => {
8
+ if (!select || !document) {
9
+ return {}
10
+ }
11
+
12
+ const selection: Record<string, string> = select || {}
13
+ const selectedValue: Record<string, unknown> = {}
14
+ for (const [key, path] of Object.entries(selection)) {
15
+ let value = get(document, path)
16
+ if (Array.isArray(value)) {
17
+ // If there are references in the array, ensure they have `_ref` set, otherwise they are considered empty and can safely be ignored
18
+ value = value.filter((item) =>
19
+ typeof item === 'object' ? item?._type !== 'reference' || '_ref' in item : true
20
+ )
21
+ }
22
+ selectedValue[key] = value
23
+ }
24
+
25
+ return selectedValue
26
+ }
@@ -0,0 +1,18 @@
1
+ export const toFieldLanguagesKeyPrefix = 'sanityStudio:assist:field-languages:from:'
2
+
3
+ export function getPreferredToFieldLanguages(fromLanguageId: string): string[] {
4
+ if (typeof localStorage === 'undefined') {
5
+ return []
6
+ }
7
+
8
+ const value = localStorage.getItem(`${toFieldLanguagesKeyPrefix}${fromLanguageId}`)
9
+ return value ? (JSON.parse(value) as string[]) : []
10
+ }
11
+
12
+ export function setPreferredToFieldLanguages(fromLanguageId: string, languageIds: string[]) {
13
+ if (typeof localStorage === 'undefined') {
14
+ return
15
+ }
16
+
17
+ localStorage.setItem(`${toFieldLanguagesKeyPrefix}${fromLanguageId}`, JSON.stringify(languageIds))
18
+ }
@@ -0,0 +1,133 @@
1
+ import {describe, expect, test} from 'vitest'
2
+ import {Schema} from '@sanity/schema'
3
+ import {defineType, ObjectSchemaType, pathToString, SanityDocumentLike, typed} from 'sanity'
4
+ import {
5
+ defaultLanguageOutputs,
6
+ FieldLanguageMap,
7
+ getDocumentMembersFlat,
8
+ getFieldLanguageMap,
9
+ } from './paths'
10
+
11
+ describe('paths', () => {
12
+ test('should return internationalizedArrayString paths and find translation mappings', () => {
13
+ const docSchema: ObjectSchemaType = Schema.compile({
14
+ name: 'test',
15
+ types: [
16
+ defineType({
17
+ type: 'document',
18
+ name: 'article',
19
+ fields: [
20
+ {type: 'string', name: 'title'},
21
+ {
22
+ type: 'object',
23
+ name: 'localeTitle',
24
+ fields: [
25
+ {type: 'string', name: 'en'},
26
+ {type: 'string', name: 'no'},
27
+ ],
28
+ },
29
+ {
30
+ type: 'array',
31
+ name: 'translations',
32
+ of: [
33
+ {
34
+ type: 'object',
35
+ name: 'internationalizedArrayString',
36
+ fields: [{type: 'string', name: 'value'}],
37
+ },
38
+ ],
39
+ },
40
+ ],
41
+ }),
42
+ ],
43
+ }).get('article')
44
+
45
+ const doc: SanityDocumentLike = {
46
+ _id: 'na',
47
+ _type: 'article',
48
+ title: 'some title',
49
+ localeTitle: {
50
+ en: 'en string',
51
+ },
52
+ translations: [
53
+ {
54
+ _type: 'internationalizedArrayString',
55
+ _key: 'en',
56
+ value: 'some string',
57
+ },
58
+ ],
59
+ }
60
+
61
+ const members = getDocumentMembersFlat(doc, docSchema)
62
+ expect(members.map((p) => pathToString(p.path))).toEqual([
63
+ 'title',
64
+ 'localeTitle',
65
+ 'localeTitle.en',
66
+ // this path has no value in the document, so are not included
67
+ //'localeTitle.no',
68
+ 'translations',
69
+ 'translations[_key=="en"]',
70
+ 'translations[_key=="en"].value',
71
+ // these path has no value in the document, so are not included
72
+ //'translations[_key=="nb"]',
73
+ //'translations[_key=="nb"].value',
74
+ ])
75
+
76
+ const transMap = getFieldLanguageMap(docSchema, members, 'en', ['nb'], defaultLanguageOutputs)
77
+
78
+ expect(transMap).toEqual(
79
+ typed<FieldLanguageMap[]>([
80
+ {
81
+ inputLanguageId: 'en',
82
+ inputPath: ['translations', {_key: 'en'}],
83
+ outputs: [{id: 'nb', outputPath: ['translations', {_key: 'nb'}]}],
84
+ },
85
+ ])
86
+ )
87
+ })
88
+
89
+ test('should use first type in array when array item is missing _type', () => {
90
+ const docSchema: ObjectSchemaType = Schema.compile({
91
+ name: 'test',
92
+ types: [
93
+ defineType({
94
+ type: 'document',
95
+ name: 'article',
96
+ fields: [
97
+ {
98
+ type: 'array',
99
+ name: 'translations',
100
+ of: [
101
+ {
102
+ type: 'object',
103
+ name: 'internationalizedArrayString',
104
+ fields: [{type: 'string', name: 'value'}],
105
+ },
106
+ ],
107
+ },
108
+ ],
109
+ }),
110
+ ],
111
+ }).get('article')
112
+
113
+ const doc: SanityDocumentLike = {
114
+ _id: 'na',
115
+ _type: 'article',
116
+ translations: [
117
+ {
118
+ //assume type is missing in the data for some reason
119
+ //_type: 'internationalizedArrayString',
120
+ _key: 'en',
121
+ value: 'some string',
122
+ },
123
+ ],
124
+ }
125
+
126
+ const members = getDocumentMembersFlat(doc, docSchema)
127
+ expect(members.map((p) => pathToString(p.path))).toEqual([
128
+ 'translations',
129
+ 'translations[_key=="en"]',
130
+ 'translations[_key=="en"].value',
131
+ ])
132
+ })
133
+ })
@@ -0,0 +1,175 @@
1
+ import {
2
+ isDocumentSchemaType,
3
+ isKeySegment,
4
+ ObjectSchemaType,
5
+ Path,
6
+ pathToString,
7
+ SanityDocumentLike,
8
+ } from 'sanity'
9
+ import {extractWithPath} from '@sanity/mutator'
10
+ import {DocumentMember, TranslationOutput, TranslationOutputsFunction} from './types'
11
+
12
+ export interface FieldLanguageMap {
13
+ inputLanguageId: string
14
+ inputPath: Path
15
+ outputs: TranslationOutput[]
16
+ }
17
+
18
+ const MAX_DEPTH = 6
19
+
20
+ export function getDocumentMembersFlat(doc: SanityDocumentLike, schemaType: ObjectSchemaType) {
21
+ if (!isDocumentSchemaType(schemaType)) {
22
+ console.error(`Schema type is not a document`)
23
+ return []
24
+ }
25
+
26
+ return extractPaths(doc, schemaType, [], MAX_DEPTH)
27
+ }
28
+
29
+ function extractPaths(
30
+ doc: SanityDocumentLike,
31
+ schemaType: ObjectSchemaType,
32
+ path: Path,
33
+ maxDepth: number
34
+ ): DocumentMember[] {
35
+ if (path.length >= maxDepth) {
36
+ return []
37
+ }
38
+
39
+ return schemaType.fields.reduce<DocumentMember[]>((acc, field) => {
40
+ const fieldPath = [...path, field.name]
41
+ const fieldSchema = field.type
42
+ const {value} = extractWithPath(pathToString(fieldPath), doc)[0] ?? {}
43
+ if (!value) {
44
+ return acc
45
+ }
46
+
47
+ const thisFieldWithPath: DocumentMember = {
48
+ path: fieldPath,
49
+ name: field.name,
50
+ schemaType: fieldSchema,
51
+ value,
52
+ }
53
+
54
+ if (fieldSchema.jsonType === 'object') {
55
+ const innerFields = extractPaths(doc, fieldSchema, fieldPath, maxDepth)
56
+
57
+ return [...acc, thisFieldWithPath, ...innerFields]
58
+ } else if (
59
+ fieldSchema.jsonType === 'array' &&
60
+ fieldSchema.of.length &&
61
+ fieldSchema.of.some((item) => 'fields' in item)
62
+ ) {
63
+ const {value: arrayValue} = extractWithPath(pathToString(fieldPath), doc)[0] ?? {}
64
+
65
+ let arrayPaths: DocumentMember[] = []
66
+ if ((arrayValue as any)?.length) {
67
+ for (const item of arrayValue as any[]) {
68
+ const itemPath = [...fieldPath, {_key: item._key}]
69
+ let itemSchema = fieldSchema.of.find((t) => t.name === item._type)
70
+ if (!item._type) {
71
+ itemSchema = fieldSchema.of[0]
72
+ console.warn(
73
+ 'Array item is missing _type - using the first defined type in the array.of schema',
74
+ {
75
+ itemPath,
76
+ item,
77
+ itemSchema,
78
+ }
79
+ )
80
+ }
81
+ if (item._key && itemSchema) {
82
+ const innerFields = extractPaths(
83
+ doc,
84
+ itemSchema as ObjectSchemaType,
85
+ itemPath,
86
+ maxDepth
87
+ )
88
+ const arrayMember = {
89
+ path: itemPath,
90
+ name: item._key,
91
+ schemaType: itemSchema,
92
+ value: item,
93
+ }
94
+ arrayPaths = [...arrayPaths, arrayMember, ...innerFields]
95
+ }
96
+ }
97
+ }
98
+
99
+ return [...acc, thisFieldWithPath, ...arrayPaths]
100
+ }
101
+
102
+ return [...acc, thisFieldWithPath]
103
+ }, [])
104
+ }
105
+
106
+ /**
107
+ * Default implementation for plugin config `translate.field.translationOutputs`
108
+ *
109
+ * @see FieldTranslationConfig#translationOutputs
110
+ */
111
+ export const defaultLanguageOutputs: TranslationOutputsFunction = function (
112
+ member,
113
+ enclosingType,
114
+ translateFromLanguageId,
115
+ translateToLanguageIds
116
+ ) {
117
+ if (
118
+ member.schemaType.jsonType === 'object' &&
119
+ member.schemaType.name.startsWith('internationalizedArray')
120
+ ) {
121
+ const pathEnd = member.path.slice(-1)
122
+
123
+ const language = isKeySegment(pathEnd[0]) ? pathEnd[0]._key : null
124
+ return language === translateFromLanguageId
125
+ ? translateToLanguageIds.map((translateToId) => ({
126
+ id: translateToId,
127
+ outputPath: [...member.path.slice(0, -1), {_key: translateToId}],
128
+ }))
129
+ : undefined
130
+ }
131
+
132
+ if (enclosingType.jsonType === 'object' && enclosingType.name.startsWith('locale')) {
133
+ return translateFromLanguageId === member.name
134
+ ? translateToLanguageIds.map((translateToId) => ({
135
+ id: translateToId,
136
+ outputPath: [...member.path.slice(0, -1), translateToId],
137
+ }))
138
+ : undefined
139
+ }
140
+
141
+ return undefined
142
+ }
143
+
144
+ export function getFieldLanguageMap(
145
+ documentSchema: ObjectSchemaType,
146
+ documentMembers: DocumentMember[],
147
+ translateFromLanguageId: string,
148
+ outputLanguageIds: string[],
149
+ langFn: TranslationOutputsFunction
150
+ ): FieldLanguageMap[] {
151
+ const translationMaps: FieldLanguageMap[] = []
152
+ for (const member of documentMembers) {
153
+ const parentPath = member.path.slice(0, -1)
154
+ const enclosingType =
155
+ documentMembers.find((m) => pathToString(m.path) === pathToString(parentPath))?.schemaType ??
156
+ documentSchema
157
+
158
+ const translations = langFn(
159
+ member,
160
+ enclosingType,
161
+ translateFromLanguageId,
162
+ outputLanguageIds
163
+ )?.filter((translation) => translation.id !== translateFromLanguageId)
164
+
165
+ if (translations) {
166
+ translationMaps.push({
167
+ inputLanguageId: translateFromLanguageId,
168
+ inputPath: member.path,
169
+ outputs: translations,
170
+ })
171
+ }
172
+ }
173
+
174
+ return translationMaps
175
+ }