@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
@@ -3,11 +3,12 @@ import {
3
3
  DocumentFieldActionGroup,
4
4
  DocumentFieldActionItem,
5
5
  ObjectSchemaType,
6
+ typed,
6
7
  useCurrentUser,
7
8
  } from 'sanity'
8
9
  import {ControlsIcon, SparklesIcon} from '@sanity/icons'
9
- import {useCallback, useMemo} from 'react'
10
- import {pluginTitle, pluginTitleShort} from '../constants'
10
+ import {useCallback, useMemo, useRef} from 'react'
11
+ import {pluginTitleShort} from '../constants'
11
12
  import {useAssistSupported} from '../helpers/useAssistSupported'
12
13
  import {useAssistDocumentContext} from '../assistDocument/AssistDocumentContext'
13
14
  import {getInstructionTitle, usePathKey} from '../helpers/misc'
@@ -24,6 +25,9 @@ import {generateCaptionsActions} from './generateCaptionActions'
24
25
  import {useDocumentPane} from 'sanity/desk'
25
26
  import {useSelectedField, useTypePath} from '../assistInspector/helpers'
26
27
  import {isSchemaAssistEnabled} from '../helpers/assistSupported'
28
+ import {translateActions, TranslateProps} from '../translate/translateActions'
29
+ import {generateImagActions} from './generateImageActions'
30
+ import {getConditionalMembers} from '../helpers/conditionalMembers'
27
31
 
28
32
  function node(node: DocumentFieldActionItem | DocumentFieldActionGroup) {
29
33
  return node
@@ -47,6 +51,7 @@ export const assistFieldActions: DocumentFieldAction = {
47
51
  documentSchemaType,
48
52
  documentId,
49
53
  selectedPath,
54
+ assistableDocumentId,
50
55
  } =
51
56
  // document field actions do not have access to the document context
52
57
  // conditional hook _should_ be safe here since the logical path will be stable
@@ -56,7 +61,10 @@ export const assistFieldActions: DocumentFieldAction = {
56
61
  : // eslint-disable-next-line react-hooks/rules-of-hooks
57
62
  useAssistDocumentContext()
58
63
 
59
- const {value: docValue} = useDocumentPane()
64
+ const {value: docValue, formState} = useDocumentPane()
65
+ const formStateRef = useRef(formState)
66
+ formStateRef.current = formState
67
+
60
68
  const currentUser = useCurrentUser()
61
69
  const isHidden = !assistDocument
62
70
  const pathKey = usePathKey(props.path)
@@ -73,7 +81,8 @@ export const assistFieldActions: DocumentFieldAction = {
73
81
  const assistSupported =
74
82
  useAssistSupported(props.path, schemaType) &&
75
83
  isSelectable &&
76
- isSchemaAssistEnabled(documentSchemaType)
84
+ isSchemaAssistEnabled(documentSchemaType) &&
85
+ schemaType.readOnly !== true
77
86
 
78
87
  const fieldAssist = useMemo(
79
88
  () =>
@@ -89,7 +98,15 @@ export const assistFieldActions: DocumentFieldAction = {
89
98
  const isSelected = isInspectorOpen && isPathSelected
90
99
 
91
100
  const imageCaptionAction = generateCaptionsActions.useAction(props)
92
-
101
+ const imageGenAction = generateImagActions.useAction(props)
102
+ const translateAction = translateActions.useAction(
103
+ typed<TranslateProps>({
104
+ ...props,
105
+ documentId: assistableDocumentId,
106
+ documentIsAssistable,
107
+ documentSchemaType,
108
+ })
109
+ )
93
110
  const manageInstructions = useCallback(
94
111
  () =>
95
112
  isSelected
@@ -112,6 +129,9 @@ export const assistFieldActions: DocumentFieldAction = {
112
129
  path: pathKey,
113
130
  typePath,
114
131
  instruction,
132
+ conditionalMembers: formStateRef.current
133
+ ? getConditionalMembers(formStateRef.current)
134
+ : [],
115
135
  })
116
136
  },
117
137
  [requestRunInstruction, assistableDocId, pathKey, typePath, assistDocumentId, fieldAssistKey]
@@ -134,7 +154,7 @@ export const assistFieldActions: DocumentFieldAction = {
134
154
  )
135
155
 
136
156
  const runInstructionsGroup = useMemo(() => {
137
- return instructions?.length || imageCaptionAction
157
+ return instructions?.length || imageCaptionAction || translateAction || imageGenAction
138
158
  ? node({
139
159
  type: 'group',
140
160
  icon: () => null,
@@ -151,7 +171,8 @@ export const assistFieldActions: DocumentFieldAction = {
151
171
  })
152
172
  ),
153
173
  imageCaptionAction,
154
- ].filter(Boolean),
174
+ imageGenAction,
175
+ ].filter((a): a is DocumentFieldActionItem => !!a),
155
176
  expanded: true,
156
177
  })
157
178
  : undefined
@@ -163,6 +184,8 @@ export const assistFieldActions: DocumentFieldAction = {
163
184
  documentIsNew,
164
185
  assistSupported,
165
186
  imageCaptionAction,
187
+ translateAction,
188
+ imageGenAction,
166
189
  ])
167
190
 
168
191
  const instructionsLength = instructions?.length || 0
@@ -185,12 +208,16 @@ export const assistFieldActions: DocumentFieldAction = {
185
208
  type: 'group',
186
209
  icon: SparklesIcon,
187
210
  title: pluginTitleShort,
188
- children: [runInstructionsGroup, assistSupported && manageInstructionsItem].filter(
189
- (c): c is DocumentFieldActionItem | DocumentFieldActionGroup => !!c
190
- ),
211
+ children: [
212
+ runInstructionsGroup,
213
+ translateAction,
214
+ assistSupported && manageInstructionsItem,
215
+ ]
216
+ .filter((c): c is DocumentFieldActionItem | DocumentFieldActionGroup => !!c)
217
+ .filter((c) => (c.type === 'group' ? c.children.length : true)),
191
218
  expanded: false,
192
219
  renderAsButton: true,
193
- hidden: !assistSupported && !imageCaptionAction,
220
+ hidden: !assistSupported && !imageCaptionAction && !translateAction && !imageGenAction,
194
221
  }),
195
222
  [
196
223
  //documentIsNew,
@@ -198,6 +225,8 @@ export const assistFieldActions: DocumentFieldAction = {
198
225
  manageInstructionsItem,
199
226
  assistSupported,
200
227
  imageCaptionAction,
228
+ translateAction,
229
+ imageGenAction,
201
230
  ]
202
231
  )
203
232
 
@@ -216,7 +245,7 @@ export const assistFieldActions: DocumentFieldAction = {
216
245
  )
217
246
 
218
247
  // If there are no instructions, we don't want to render the group
219
- if (instructionsLength === 0 && !imageCaptionAction) {
248
+ if (instructionsLength === 0 && !imageCaptionAction && !translateAction && !imageGenAction) {
220
249
  return emptyAction
221
250
  }
222
251
 
@@ -239,7 +268,7 @@ function instructionItem(props: {
239
268
  iconRight: isPrivate ? PrivateIcon : undefined,
240
269
  title: getInstructionTitle(instruction),
241
270
  onAction: () => onInstructionAction(instruction),
242
- disabled: assistSupported ? false : {reason: `${pluginTitle} is not supported for this field`},
271
+ disabled: !assistSupported,
243
272
  hidden,
244
273
  })
245
274
  }
@@ -23,7 +23,7 @@ export const generateCaptionsActions: DocumentFieldAction = {
23
23
 
24
24
  const imageContext = useContext(ImageContext)
25
25
 
26
- if (imageContext && pathKey === imageContext?.captionPath) {
26
+ if (imageContext && pathKey === imageContext?.imageDescriptionPath) {
27
27
  //if this is true, it is stable, and not breaking rules of hooks
28
28
  // eslint-disable-next-line react-hooks/rules-of-hooks
29
29
  const {documentId} = useAssistDocumentContext()
@@ -38,7 +38,7 @@ export const generateCaptionsActions: DocumentFieldAction = {
38
38
  </Box>
39
39
  )
40
40
  : ImageIcon,
41
- title: 'Generate caption',
41
+ title: 'Generate image description',
42
42
  onAction: () => {
43
43
  if (loading) {
44
44
  return
@@ -0,0 +1,57 @@
1
+ import {DocumentFieldAction, DocumentFieldActionGroup, DocumentFieldActionItem} from 'sanity'
2
+ import {ImageIcon} from '@sanity/icons'
3
+ import {useContext, useMemo} from 'react'
4
+ import {usePathKey} from '../helpers/misc'
5
+ import {useApiClient, useGenerateImage} from '../useApiClient'
6
+ import {useAiAssistanceConfig} from '../assistLayout/AiAssistanceConfigContext'
7
+ import {useAssistDocumentContext} from '../assistDocument/AssistDocumentContext'
8
+ import {ImageContext} from '../components/ImageContext'
9
+ import {Box, Spinner} from '@sanity/ui'
10
+
11
+ function node(node: DocumentFieldActionItem | DocumentFieldActionGroup) {
12
+ return node
13
+ }
14
+
15
+ export const generateImagActions: DocumentFieldAction = {
16
+ name: 'sanity-assist-generate-image',
17
+ useAction(props) {
18
+ const pathKey = usePathKey(props.path)
19
+
20
+ const {config} = useAiAssistanceConfig()
21
+ const apiClient = useApiClient(config?.__customApiClient)
22
+ const {generateImage, loading} = useGenerateImage(apiClient)
23
+
24
+ const imageContext = useContext(ImageContext)
25
+
26
+ if (imageContext && pathKey === imageContext?.imageInstructionPath) {
27
+ //if this is true, it is stable, and not breaking rules of hooks
28
+ // eslint-disable-next-line react-hooks/rules-of-hooks
29
+ const {documentId} = useAssistDocumentContext()
30
+ // eslint-disable-next-line react-hooks/rules-of-hooks
31
+ return useMemo(() => {
32
+ return node({
33
+ type: 'action',
34
+ icon: loading
35
+ ? () => (
36
+ <Box style={{height: 17}}>
37
+ <Spinner style={{transform: 'translateY(6px)'}} />
38
+ </Box>
39
+ )
40
+ : ImageIcon,
41
+ title: 'Generate image from prompt',
42
+ onAction: () => {
43
+ if (loading) {
44
+ return
45
+ }
46
+ generateImage({path: pathKey, documentId: documentId ?? ''})
47
+ },
48
+ renderAsButton: true,
49
+ disabled: loading,
50
+ })
51
+ }, [generateImage, pathKey, documentId, loading])
52
+ }
53
+
54
+ // works but not supported by types
55
+ return undefined as unknown as DocumentFieldActionItem
56
+ },
57
+ }
@@ -1,41 +1,34 @@
1
- import {SchemaType} from 'sanity'
1
+ import {ReferenceOptions, SchemaType} from 'sanity'
2
2
  import {AssistOptions} from '../schemas/typeDefExtensions'
3
3
  import {isType} from './typeUtils'
4
4
 
5
5
  export function isSchemaAssistEnabled(type: SchemaType) {
6
- return !(type.options as AssistOptions | undefined)?.aiWritingAssistance?.exclude
6
+ return !(type.options as AssistOptions | undefined)?.aiAssist?.exclude
7
7
  }
8
8
 
9
- export function isAssistSupported(type: SchemaType, allowReadonlyHidden = false) {
9
+ export function isAssistSupported(type: SchemaType) {
10
10
  if (!isSchemaAssistEnabled(type)) {
11
11
  return false
12
12
  }
13
13
 
14
- if (isDisabled(type, allowReadonlyHidden)) {
14
+ if (isDisabled(type)) {
15
15
  return false
16
16
  }
17
17
 
18
18
  if (type.jsonType === 'array') {
19
- const unsupportedArray = type.of.every((t) => isDisabled(t, allowReadonlyHidden))
19
+ const unsupportedArray = type.of.every((t) => isDisabled(t))
20
20
  return !unsupportedArray
21
21
  }
22
22
 
23
23
  if (type.jsonType === 'object') {
24
- const unsupportedObject = type.fields.every((field) =>
25
- isDisabled(field.type, allowReadonlyHidden)
26
- )
24
+ const unsupportedObject = type.fields.every((field) => isDisabled(field.type))
27
25
  return !unsupportedObject
28
26
  }
29
27
  return true
30
28
  }
31
29
 
32
- function isDisabled(type: SchemaType, allowReadonlyHidden: boolean) {
33
- const readonlyHidden = !!type.readOnly || !!type.hidden
34
- return (
35
- !isSchemaAssistEnabled(type) ||
36
- isUnsupportedType(type) ||
37
- (!allowReadonlyHidden && readonlyHidden)
38
- )
30
+ function isDisabled(type: SchemaType) {
31
+ return !isSchemaAssistEnabled(type) || isUnsupportedType(type)
39
32
  }
40
33
 
41
34
  function isUnsupportedType(type: SchemaType) {
@@ -43,7 +36,8 @@ function isUnsupportedType(type: SchemaType) {
43
36
  type.jsonType === 'number' ||
44
37
  type.name === 'sanity.imageCrop' ||
45
38
  type.name === 'sanity.imageHotspot' ||
46
- isType(type, 'reference') ||
39
+ (isType(type, 'reference') &&
40
+ !(type?.options as ReferenceOptions)?.aiAssist?.embeddingsIndex) ||
47
41
  isType(type, 'crossDatasetReference') ||
48
42
  isType(type, 'slug') ||
49
43
  isType(type, 'url') ||
@@ -0,0 +1,200 @@
1
+ import {describe, expect, test} from 'vitest'
2
+ import {Schema} from '@sanity/schema'
3
+ import {ArraySchemaType, defineField, defineType, ObjectSchemaType} from 'sanity'
4
+ import {getConditionalMembers} from './conditionalMembers'
5
+
6
+ describe('conditionalMembers', () => {
7
+ test('should not include paths without conditional hidden/readonly', () => {
8
+ const docSchema: ObjectSchemaType = Schema.compile({
9
+ name: 'test',
10
+ types: [
11
+ defineType({
12
+ type: 'document',
13
+ name: 'article',
14
+ fields: [{type: 'string', name: 'title'}],
15
+ }),
16
+ ],
17
+ }).get('article')
18
+
19
+ const docState = {
20
+ path: [],
21
+ schemaType: docSchema,
22
+ members: [
23
+ {
24
+ kind: 'field',
25
+ field: {path: [docSchema.fields[0].name], schemaType: docSchema.fields[0].type},
26
+ },
27
+ ],
28
+ } as any
29
+ const conditionalMembers = getConditionalMembers(docState)
30
+
31
+ expect(conditionalMembers).toEqual([])
32
+ })
33
+
34
+ test('should include path with conditional readonly', () => {
35
+ const docSchema: ObjectSchemaType = Schema.compile({
36
+ name: 'test',
37
+ types: [
38
+ defineType({
39
+ type: 'document',
40
+ name: 'article',
41
+ fields: [{type: 'string', name: 'title', readOnly: () => false}],
42
+ }),
43
+ ],
44
+ }).get('article')
45
+
46
+ const docState = {
47
+ path: [],
48
+ schemaType: docSchema,
49
+ members: [
50
+ {
51
+ kind: 'field',
52
+ field: {path: [docSchema.fields[0].name], schemaType: docSchema.fields[0].type},
53
+ },
54
+ ],
55
+ } as any
56
+ const conditionalMembers = getConditionalMembers(docState)
57
+
58
+ expect(conditionalMembers).toEqual([{path: 'title', hidden: false, readOnly: false}])
59
+ })
60
+
61
+ test('should include array item path with conditional readonly', () => {
62
+ const docSchema: ObjectSchemaType = Schema.compile({
63
+ name: 'test',
64
+ types: [
65
+ defineType({
66
+ type: 'document',
67
+ name: 'article',
68
+ fields: [{type: 'array', name: 'array', of: [{type: 'string', readOnly: () => true}]}],
69
+ }),
70
+ ],
71
+ }).get('article')
72
+
73
+ const docState = {
74
+ path: [],
75
+ schemaType: docSchema,
76
+ members: [
77
+ {
78
+ kind: 'field',
79
+ field: {
80
+ path: [docSchema.fields[0].name],
81
+ schemaType: docSchema.fields[0].type,
82
+ members: [
83
+ {
84
+ kind: 'item',
85
+ item: {
86
+ path: [docSchema.fields[0].name, 0],
87
+ schemaType: (docSchema.fields[0].type as ArraySchemaType).of[0],
88
+ readOnly: true,
89
+ },
90
+ },
91
+ ],
92
+ },
93
+ },
94
+ ],
95
+ } as any
96
+ const conditionalMembers = getConditionalMembers(docState)
97
+
98
+ expect(conditionalMembers).toEqual([
99
+ {
100
+ path: 'array[0]',
101
+ hidden: false,
102
+ readOnly: true,
103
+ },
104
+ ])
105
+ })
106
+
107
+ test('should include object path with conditional hidden', () => {
108
+ const docSchema: ObjectSchemaType = Schema.compile({
109
+ name: 'test',
110
+ types: [
111
+ defineType({
112
+ type: 'document',
113
+ name: 'article',
114
+ fields: [
115
+ defineField({
116
+ type: 'object',
117
+ name: 'object',
118
+ fields: [{type: 'string', name: 'title', hidden: () => false}],
119
+ }),
120
+ ],
121
+ }),
122
+ ],
123
+ }).get('article')
124
+
125
+ const docState = {
126
+ path: [],
127
+ schemaType: docSchema,
128
+ members: [
129
+ {
130
+ kind: 'field',
131
+ field: {
132
+ path: [docSchema.fields[0].name],
133
+ schemaType: docSchema.fields[0].type,
134
+ members: [
135
+ {
136
+ kind: 'field',
137
+ field: {
138
+ path: [docSchema.fields[0].name, 'title'],
139
+ schemaType: (docSchema.fields[0].type as ObjectSchemaType).fields[0].type,
140
+ },
141
+ },
142
+ ],
143
+ },
144
+ },
145
+ ],
146
+ } as any
147
+ const conditionalMembers = getConditionalMembers(docState)
148
+
149
+ expect(conditionalMembers).toEqual([
150
+ {
151
+ path: 'object.title',
152
+ hidden: false,
153
+ readOnly: false,
154
+ },
155
+ ])
156
+ })
157
+
158
+ test('should include path with fieldset with conditional state', () => {
159
+ const docSchema: ObjectSchemaType = Schema.compile({
160
+ name: 'test',
161
+ types: [
162
+ defineType({
163
+ type: 'document',
164
+ name: 'article',
165
+ fieldsets: [{name: 'set', hidden: () => false}],
166
+ fields: [{type: 'string', fieldset: 'set', name: 'title'}],
167
+ }),
168
+ ],
169
+ }).get('article')
170
+
171
+ const docState = {
172
+ path: [],
173
+ schemaType: docSchema,
174
+ members: [
175
+ {
176
+ kind: 'fieldSet',
177
+ fieldSet: {
178
+ name: 'set',
179
+ path: ['set'],
180
+ members: [
181
+ {
182
+ kind: 'field',
183
+ field: {path: [docSchema.fields[0].name], schemaType: docSchema.fields[0].type},
184
+ },
185
+ ],
186
+ },
187
+ },
188
+ ],
189
+ } as any
190
+ const conditionalMembers = getConditionalMembers(docState)
191
+
192
+ expect(conditionalMembers).toEqual([
193
+ {
194
+ path: 'title',
195
+ hidden: false,
196
+ readOnly: false,
197
+ },
198
+ ])
199
+ })
200
+ })
@@ -0,0 +1,127 @@
1
+ /* eslint-disable max-depth */
2
+ import {
3
+ ArrayOfObjectsFormNode,
4
+ ArrayOfObjectsItemMember,
5
+ ArrayOfPrimitivesFormNode,
6
+ DocumentFormNode,
7
+ FieldsetState,
8
+ isObjectSchemaType,
9
+ ObjectFormNode,
10
+ Path,
11
+ pathToString,
12
+ SchemaType,
13
+ } from 'sanity'
14
+
15
+ const MAX_DEPTH = 8
16
+
17
+ export interface ConditionalMemberState {
18
+ path: string
19
+ hidden: boolean
20
+ readOnly: boolean
21
+ }
22
+
23
+ interface ConditionalMemberInnerState extends ConditionalMemberState {
24
+ conditional: boolean
25
+ }
26
+
27
+ /**
28
+ * This is used to statically determine the state of the functions on the server-side.
29
+ * Paths which has a schema with conditional config should be considered hidden: true and/or readOnly: true
30
+ * Only conditional paths are included, as static props can be determined from schema.
31
+ *
32
+ * Returns paths that has conditional hidden or readOnly schema config (function) and that.
33
+ * Form-state does not contain hidden members.
34
+ *
35
+ * Note:
36
+ * * If a parent path is hidden, no child paths are included
37
+ * * If a parent path is readOnly, no child paths are included
38
+ * * If a path is hidden, it is not included; only conditionally visible paths will be returned, with hidden: false
39
+ */
40
+ export function getConditionalMembers(docState: DocumentFormNode): ConditionalMemberState[] {
41
+ const doc: ConditionalMemberInnerState = {
42
+ path: '',
43
+ hidden: false,
44
+ readOnly: !!docState.readOnly,
45
+ conditional: typeof docState.schemaType.hidden === 'function',
46
+ }
47
+ return [doc, ...extractConditionalPaths(docState, MAX_DEPTH)]
48
+ .filter((v) => v.conditional)
49
+ .map(({conditional, ...state}) => ({...state}))
50
+ }
51
+
52
+ function isConditional(schemaType: SchemaType) {
53
+ return typeof schemaType.hidden === 'function' || typeof schemaType.readOnly === 'function'
54
+ }
55
+
56
+ function conditionalState(memberState: {
57
+ path: Path
58
+ schemaType: SchemaType
59
+ readOnly?: boolean
60
+ }): ConditionalMemberInnerState {
61
+ return {
62
+ path: pathToString(memberState.path),
63
+ readOnly: !!memberState.readOnly,
64
+ hidden: false, // if its in members, its not hidden
65
+ conditional: isConditional(memberState.schemaType),
66
+ }
67
+ }
68
+
69
+ function extractConditionalPaths(
70
+ node: ObjectFormNode | FieldsetState,
71
+ maxDepth: number
72
+ ): ConditionalMemberInnerState[] {
73
+ if (node.path.length >= maxDepth) {
74
+ return []
75
+ }
76
+
77
+ return node.members.reduce<ConditionalMemberInnerState[]>((acc, member) => {
78
+ if (member.kind === 'error') {
79
+ return acc
80
+ }
81
+ if (member.kind === 'field') {
82
+ const schemaType = member.field.schemaType
83
+ if (schemaType.jsonType === 'object') {
84
+ const innerFields = member.field.readOnly
85
+ ? []
86
+ : extractConditionalPaths(member.field as ObjectFormNode, maxDepth)
87
+ return [...acc, conditionalState(member.field), ...innerFields]
88
+ } else if (schemaType.jsonType === 'array') {
89
+ const array = member.field as ArrayOfObjectsFormNode | ArrayOfPrimitivesFormNode
90
+
91
+ let arrayPaths: ConditionalMemberInnerState[] = []
92
+ const isObjectsArray = array.members.some(
93
+ (m) => m.kind === 'item' && isObjectSchemaType(m.item.schemaType)
94
+ )
95
+ if (!array.readOnly) {
96
+ for (const arrayMember of array.members) {
97
+ if (arrayMember.kind === 'error') {
98
+ continue
99
+ }
100
+
101
+ const innerFields =
102
+ isObjectsArray && !arrayMember.item.readOnly
103
+ ? extractConditionalPaths((arrayMember as ArrayOfObjectsItemMember).item, maxDepth)
104
+ : []
105
+
106
+ arrayPaths = [...arrayPaths, conditionalState(arrayMember.item), ...innerFields]
107
+ }
108
+ }
109
+ return [...acc, conditionalState(array), ...arrayPaths]
110
+ }
111
+
112
+ return [...acc, conditionalState(member.field)]
113
+ } else if (member.kind === 'fieldSet') {
114
+ const conditionalFieldset = !!(node as ObjectFormNode).schemaType?.fieldsets?.some(
115
+ (f) => !f.single && f.name === member.fieldSet.name && typeof f.hidden === 'function'
116
+ )
117
+ const innerFields = extractConditionalPaths(member.fieldSet, maxDepth).map((f) => ({
118
+ ...f,
119
+ // if fieldset is conditional, visible fields must also be considered conditional
120
+ conditional: conditionalFieldset ?? f.conditional,
121
+ }))
122
+ return [...acc, ...innerFields]
123
+ }
124
+
125
+ return acc
126
+ }, [])
127
+ }
@@ -18,13 +18,27 @@ export function isImage(schemaType: SchemaType) {
18
18
  return isType(schemaType, 'image')
19
19
  }
20
20
 
21
- export function getCaptionFieldOption(schemaType: SchemaType | undefined): string | undefined {
21
+ export function getDescriptionFieldOption(schemaType: SchemaType | undefined): string | undefined {
22
22
  if (!schemaType) {
23
23
  return undefined
24
24
  }
25
- const captionField = (schemaType.options as ImageOptions)?.captionField
26
- if (captionField) {
27
- return captionField
25
+ const descriptionField = (schemaType.options as ImageOptions)?.aiAssist?.imageDescriptionField
26
+ if (descriptionField) {
27
+ return descriptionField
28
28
  }
29
- return getCaptionFieldOption(schemaType.type)
29
+ return getDescriptionFieldOption(schemaType.type)
30
+ }
31
+
32
+ export function getImageInstructionFieldOption(
33
+ schemaType: SchemaType | undefined
34
+ ): string | undefined {
35
+ if (!schemaType) {
36
+ return undefined
37
+ }
38
+ const imageInstructionField = (schemaType.options as ImageOptions)?.aiAssist
39
+ ?.imageInstructionField
40
+ if (imageInstructionField) {
41
+ return imageInstructionField
42
+ }
43
+ return getImageInstructionFieldOption(schemaType.type)
30
44
  }
package/src/index.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export * from './schemas/typeDefExtensions'
2
2
  export * from './schemas/serialize/SchemTypeTool'
3
3
 
4
+ export {defaultLanguageOutputs} from './translate/paths'
5
+ export * from './translate/types'
6
+
4
7
  export {contextDocumentTypeName} from './types'
5
8
 
6
9
  export {assist} from './plugin'
@@ -0,0 +1,8 @@
1
+ {
2
+ "hash": "6b9f27e8",
3
+ "configHash": "36395290",
4
+ "lockfileHash": "8eb2d291",
5
+ "browserHash": "2b6c636b",
6
+ "optimized": {},
7
+ "chunks": {}
8
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1 @@
1
+ {"version":"0.32.2","results":[[":schemas/serialize/serializeSchema.test.ts",{"duration":13,"failed":false}],[":translate/paths.test.ts",{"duration":6,"failed":false}],[":helpers/conditionalMembers.test.ts",{"duration":4,"failed":false}]]}