@rebasepro/plugin-data-enhancement 0.0.1-canary.000dc36

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 (318) hide show
  1. package/LICENSE +114 -0
  2. package/README.md +89 -0
  3. package/dist/common/src/collections/CollectionRegistry.d.ts +56 -0
  4. package/dist/common/src/collections/index.d.ts +1 -0
  5. package/dist/common/src/data/buildRebaseData.d.ts +14 -0
  6. package/dist/common/src/index.d.ts +3 -0
  7. package/dist/common/src/util/builders.d.ts +57 -0
  8. package/dist/common/src/util/callbacks.d.ts +6 -0
  9. package/dist/common/src/util/collections.d.ts +11 -0
  10. package/dist/common/src/util/common.d.ts +2 -0
  11. package/dist/common/src/util/conditions.d.ts +26 -0
  12. package/dist/common/src/util/entities.d.ts +58 -0
  13. package/dist/common/src/util/enums.d.ts +3 -0
  14. package/dist/common/src/util/index.d.ts +16 -0
  15. package/dist/common/src/util/navigation_from_path.d.ts +34 -0
  16. package/dist/common/src/util/navigation_utils.d.ts +20 -0
  17. package/dist/common/src/util/parent_references_from_path.d.ts +6 -0
  18. package/dist/common/src/util/paths.d.ts +14 -0
  19. package/dist/common/src/util/permissions.d.ts +5 -0
  20. package/dist/common/src/util/references.d.ts +2 -0
  21. package/dist/common/src/util/relations.d.ts +22 -0
  22. package/dist/common/src/util/resolutions.d.ts +72 -0
  23. package/dist/common/src/util/storage.d.ts +24 -0
  24. package/dist/core/src/components/AIIcon.d.ts +16 -0
  25. package/dist/core/src/components/ConfirmationDialog.d.ts +9 -0
  26. package/dist/core/src/components/Debug/UIReferenceView.d.ts +1 -0
  27. package/dist/core/src/components/Debug/UIStyleGuide.d.ts +1 -0
  28. package/dist/core/src/components/ErrorTooltip.d.ts +2 -0
  29. package/dist/core/src/components/ErrorView.d.ts +21 -0
  30. package/dist/core/src/components/LanguageToggle.d.ts +1 -0
  31. package/dist/core/src/components/LoginView/LoginView.d.ts +68 -0
  32. package/dist/core/src/components/LoginView/index.d.ts +2 -0
  33. package/dist/core/src/components/NotFoundPage.d.ts +1 -0
  34. package/dist/core/src/components/RebaseAuth.d.ts +10 -0
  35. package/dist/core/src/components/RebaseLogo.d.ts +7 -0
  36. package/dist/core/src/components/UnsavedChangesDialog.d.ts +9 -0
  37. package/dist/core/src/components/UserDisplay.d.ts +7 -0
  38. package/dist/core/src/components/UserSelectPopover.d.ts +62 -0
  39. package/dist/core/src/components/UserSettingsView.d.ts +1 -0
  40. package/dist/core/src/components/common/index.d.ts +6 -0
  41. package/dist/core/src/components/common/table_height.d.ts +5 -0
  42. package/dist/core/src/components/common/types.d.ts +63 -0
  43. package/dist/core/src/components/common/useColumnsIds.d.ts +9 -0
  44. package/dist/core/src/components/common/useDataTableController.d.ts +45 -0
  45. package/dist/core/src/components/common/useDebouncedData.d.ts +9 -0
  46. package/dist/core/src/components/common/useScrollRestoration.d.ts +14 -0
  47. package/dist/core/src/components/index.d.ts +16 -0
  48. package/dist/core/src/contexts/AdminModeController.d.ts +4 -0
  49. package/dist/core/src/contexts/AnalyticsContext.d.ts +3 -0
  50. package/dist/core/src/contexts/AuthControllerContext.d.ts +3 -0
  51. package/dist/core/src/contexts/CustomizationControllerContext.d.ts +3 -0
  52. package/dist/core/src/contexts/DataDriverContext.d.ts +3 -0
  53. package/dist/core/src/contexts/DatabaseAdminContext.d.ts +3 -0
  54. package/dist/core/src/contexts/DialogsProvider.d.ts +4 -0
  55. package/dist/core/src/contexts/EffectiveRoleController.d.ts +4 -0
  56. package/dist/core/src/contexts/InternalUserManagementContext.d.ts +3 -0
  57. package/dist/core/src/contexts/ModeController.d.ts +4 -0
  58. package/dist/core/src/contexts/RebaseClientInstanceContext.d.ts +6 -0
  59. package/dist/core/src/contexts/RebaseDataContext.d.ts +3 -0
  60. package/dist/core/src/contexts/SnackbarProvider.d.ts +2 -0
  61. package/dist/core/src/contexts/StorageSourceContext.d.ts +3 -0
  62. package/dist/core/src/contexts/UserConfigurationPersistenceContext.d.ts +3 -0
  63. package/dist/core/src/contexts/index.d.ts +13 -0
  64. package/dist/core/src/core/PluginLifecycleManager.d.ts +17 -0
  65. package/dist/core/src/core/PluginProviderStack.d.ts +21 -0
  66. package/dist/core/src/core/Rebase.d.ts +14 -0
  67. package/dist/core/src/core/RebaseProps.d.ts +136 -0
  68. package/dist/core/src/core/RebaseRouter.d.ts +4 -0
  69. package/dist/core/src/core/RebaseRoutes.d.ts +17 -0
  70. package/dist/core/src/core/index.d.ts +4 -0
  71. package/dist/core/src/hooks/ApiConfigContext.d.ts +24 -0
  72. package/dist/core/src/hooks/data/delete.d.ts +31 -0
  73. package/dist/core/src/hooks/data/save.d.ts +34 -0
  74. package/dist/core/src/hooks/data/useCollectionFetch.d.ts +51 -0
  75. package/dist/core/src/hooks/data/useData.d.ts +13 -0
  76. package/dist/core/src/hooks/data/useDataOrder.d.ts +12 -0
  77. package/dist/core/src/hooks/data/useEntityFetch.d.ts +38 -0
  78. package/dist/core/src/hooks/data/useRelationSelector.d.ts +52 -0
  79. package/dist/core/src/hooks/data/useUserSelector.d.ts +31 -0
  80. package/dist/core/src/hooks/index.d.ts +37 -0
  81. package/dist/core/src/hooks/useAdminModeController.d.ts +19 -0
  82. package/dist/core/src/hooks/useAnalyticsController.d.ts +5 -0
  83. package/dist/core/src/hooks/useAuthController.d.ts +11 -0
  84. package/dist/core/src/hooks/useAuthSubscription.d.ts +2 -0
  85. package/dist/core/src/hooks/useBackendStorageSource.d.ts +30 -0
  86. package/dist/core/src/hooks/useBridgeRegistration.d.ts +18 -0
  87. package/dist/core/src/hooks/useBrowserTitleAndIcon.d.ts +6 -0
  88. package/dist/core/src/hooks/useBuildAdminModeController.d.ts +6 -0
  89. package/dist/core/src/hooks/useBuildEffectiveRoleController.d.ts +8 -0
  90. package/dist/core/src/hooks/useBuildLocalConfigurationPersistence.d.ts +2 -0
  91. package/dist/core/src/hooks/useBuildModeController.d.ts +6 -0
  92. package/dist/core/src/hooks/useClipboard.d.ts +57 -0
  93. package/dist/core/src/hooks/useCollapsedGroups.d.ts +12 -0
  94. package/dist/core/src/hooks/useCustomizationController.d.ts +11 -0
  95. package/dist/core/src/hooks/useDialogsController.d.ts +11 -0
  96. package/dist/core/src/hooks/useEffectiveRoleController.d.ts +7 -0
  97. package/dist/core/src/hooks/useInternalUserManagementController.d.ts +12 -0
  98. package/dist/core/src/hooks/useLargeLayout.d.ts +1 -0
  99. package/dist/core/src/hooks/useModeController.d.ts +19 -0
  100. package/dist/core/src/hooks/usePermissions.d.ts +12 -0
  101. package/dist/core/src/hooks/useRebaseClient.d.ts +5 -0
  102. package/dist/core/src/hooks/useRebaseContext.d.ts +11 -0
  103. package/dist/core/src/hooks/useRebaseRegistry.d.ts +34 -0
  104. package/dist/core/src/hooks/useSlot.d.ts +18 -0
  105. package/dist/core/src/hooks/useSnackbarController.d.ts +20 -0
  106. package/dist/core/src/hooks/useStorageSource.d.ts +7 -0
  107. package/dist/core/src/hooks/useStudioBridge.d.ts +91 -0
  108. package/dist/core/src/hooks/useTranslation.d.ts +17 -0
  109. package/dist/core/src/hooks/useUnsavedChangesDialog.d.ts +12 -0
  110. package/dist/core/src/hooks/useUserConfigurationPersistence.d.ts +8 -0
  111. package/dist/core/src/hooks/useValidateAuthenticator.d.ts +21 -0
  112. package/dist/core/src/i18n/RebaseI18nProvider.d.ts +33 -0
  113. package/dist/core/src/index.d.ts +15 -0
  114. package/dist/core/src/internal/common.d.ts +3 -0
  115. package/dist/core/src/internal/useRestoreScroll.d.ts +6 -0
  116. package/dist/core/src/locales/de.d.ts +2 -0
  117. package/dist/core/src/locales/en.d.ts +10 -0
  118. package/dist/core/src/locales/es.d.ts +10 -0
  119. package/dist/core/src/locales/fr.d.ts +2 -0
  120. package/dist/core/src/locales/hi.d.ts +2 -0
  121. package/dist/core/src/locales/it.d.ts +2 -0
  122. package/dist/core/src/locales/pt.d.ts +7 -0
  123. package/dist/core/src/util/constants.d.ts +1 -0
  124. package/dist/core/src/util/createFormexStub.d.ts +2 -0
  125. package/dist/core/src/util/entity_cache.d.ts +27 -0
  126. package/dist/core/src/util/enums.d.ts +5 -0
  127. package/dist/core/src/util/icon_list.d.ts +5 -0
  128. package/dist/core/src/util/icon_synonyms.d.ts +1 -0
  129. package/dist/core/src/util/icons.d.ts +20 -0
  130. package/dist/core/src/util/index.d.ts +10 -0
  131. package/dist/core/src/util/previews.d.ts +4 -0
  132. package/dist/core/src/util/useStorageUploadController.d.ts +38 -0
  133. package/dist/core/src/util/useTraceUpdate.d.ts +2 -0
  134. package/dist/formex/src/Field.d.ts +52 -0
  135. package/dist/formex/src/Formex.d.ts +7 -0
  136. package/dist/formex/src/index.d.ts +5 -0
  137. package/dist/formex/src/types.d.ts +40 -0
  138. package/dist/formex/src/useCreateFormex.d.ts +14 -0
  139. package/dist/formex/src/utils.d.ts +16 -0
  140. package/dist/index.es.js +751 -0
  141. package/dist/index.es.js.map +1 -0
  142. package/dist/index.umd.js +746 -0
  143. package/dist/index.umd.js.map +1 -0
  144. package/dist/plugin-data-enhancement/src/api.d.ts +34 -0
  145. package/dist/plugin-data-enhancement/src/components/DataEnhancementControllerProvider.d.ts +14 -0
  146. package/dist/plugin-data-enhancement/src/components/FormEnhanceAction.d.ts +10 -0
  147. package/dist/plugin-data-enhancement/src/editor/useEditorAIController.d.ts +4 -0
  148. package/dist/plugin-data-enhancement/src/index.d.ts +4 -0
  149. package/dist/plugin-data-enhancement/src/locales/de.d.ts +21 -0
  150. package/dist/plugin-data-enhancement/src/locales/en.d.ts +21 -0
  151. package/dist/plugin-data-enhancement/src/locales/es.d.ts +21 -0
  152. package/dist/plugin-data-enhancement/src/locales/fr.d.ts +21 -0
  153. package/dist/plugin-data-enhancement/src/locales/hi.d.ts +21 -0
  154. package/dist/plugin-data-enhancement/src/locales/it.d.ts +21 -0
  155. package/dist/plugin-data-enhancement/src/locales/pt.d.ts +21 -0
  156. package/dist/plugin-data-enhancement/src/types/data_enhancement_controller.d.ts +71 -0
  157. package/dist/plugin-data-enhancement/src/types/subscriptions_message_props.d.ts +3 -0
  158. package/dist/plugin-data-enhancement/src/useDataEnhancementPlugin.d.ts +29 -0
  159. package/dist/plugin-data-enhancement/src/utils/diffStrings.d.ts +7 -0
  160. package/dist/plugin-data-enhancement/src/utils/properties.d.ts +3 -0
  161. package/dist/plugin-data-enhancement/src/utils/strings_counter.d.ts +2 -0
  162. package/dist/plugin-data-enhancement/src/utils/suggestions.d.ts +1 -0
  163. package/dist/plugin-data-enhancement/src/utils/values.d.ts +1 -0
  164. package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
  165. package/dist/types/src/controllers/auth.d.ts +119 -0
  166. package/dist/types/src/controllers/client.d.ts +170 -0
  167. package/dist/types/src/controllers/collection_registry.d.ts +46 -0
  168. package/dist/types/src/controllers/customization_controller.d.ts +60 -0
  169. package/dist/types/src/controllers/data.d.ts +168 -0
  170. package/dist/types/src/controllers/data_driver.d.ts +195 -0
  171. package/dist/types/src/controllers/database_admin.d.ts +11 -0
  172. package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
  173. package/dist/types/src/controllers/effective_role.d.ts +4 -0
  174. package/dist/types/src/controllers/email.d.ts +34 -0
  175. package/dist/types/src/controllers/index.d.ts +18 -0
  176. package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
  177. package/dist/types/src/controllers/navigation.d.ts +213 -0
  178. package/dist/types/src/controllers/registry.d.ts +54 -0
  179. package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
  180. package/dist/types/src/controllers/side_entity_controller.d.ts +90 -0
  181. package/dist/types/src/controllers/snackbar.d.ts +24 -0
  182. package/dist/types/src/controllers/storage.d.ts +171 -0
  183. package/dist/types/src/index.d.ts +4 -0
  184. package/dist/types/src/rebase_context.d.ts +105 -0
  185. package/dist/types/src/types/backend.d.ts +536 -0
  186. package/dist/types/src/types/backend_hooks.d.ts +187 -0
  187. package/dist/types/src/types/builders.d.ts +15 -0
  188. package/dist/types/src/types/chips.d.ts +5 -0
  189. package/dist/types/src/types/collections.d.ts +857 -0
  190. package/dist/types/src/types/cron.d.ts +102 -0
  191. package/dist/types/src/types/data_source.d.ts +64 -0
  192. package/dist/types/src/types/entities.d.ts +145 -0
  193. package/dist/types/src/types/entity_actions.d.ts +98 -0
  194. package/dist/types/src/types/entity_callbacks.d.ts +173 -0
  195. package/dist/types/src/types/entity_link_builder.d.ts +7 -0
  196. package/dist/types/src/types/entity_overrides.d.ts +10 -0
  197. package/dist/types/src/types/entity_views.d.ts +59 -0
  198. package/dist/types/src/types/export_import.d.ts +21 -0
  199. package/dist/types/src/types/formex.d.ts +40 -0
  200. package/dist/types/src/types/index.d.ts +25 -0
  201. package/dist/types/src/types/locales.d.ts +4 -0
  202. package/dist/types/src/types/modify_collections.d.ts +5 -0
  203. package/dist/types/src/types/plugins.d.ts +282 -0
  204. package/dist/types/src/types/properties.d.ts +1148 -0
  205. package/dist/types/src/types/property_config.d.ts +70 -0
  206. package/dist/types/src/types/relations.d.ts +336 -0
  207. package/dist/types/src/types/slots.d.ts +262 -0
  208. package/dist/types/src/types/translations.d.ts +874 -0
  209. package/dist/types/src/types/user_management_delegate.d.ts +121 -0
  210. package/dist/types/src/types/websockets.d.ts +78 -0
  211. package/dist/types/src/users/index.d.ts +2 -0
  212. package/dist/types/src/users/roles.d.ts +22 -0
  213. package/dist/types/src/users/user.d.ts +46 -0
  214. package/dist/ui/src/components/Alert.d.ts +12 -0
  215. package/dist/ui/src/components/Autocomplete.d.ts +21 -0
  216. package/dist/ui/src/components/Avatar.d.ts +11 -0
  217. package/dist/ui/src/components/Badge.d.ts +8 -0
  218. package/dist/ui/src/components/BooleanSwitch.d.ts +14 -0
  219. package/dist/ui/src/components/BooleanSwitchWithLabel.d.ts +17 -0
  220. package/dist/ui/src/components/Button.d.ts +14 -0
  221. package/dist/ui/src/components/Card.d.ts +9 -0
  222. package/dist/ui/src/components/CenteredView.d.ts +9 -0
  223. package/dist/ui/src/components/Checkbox.d.ts +13 -0
  224. package/dist/ui/src/components/Chip.d.ts +26 -0
  225. package/dist/ui/src/components/CircularProgress.d.ts +5 -0
  226. package/dist/ui/src/components/CircularProgressCenter.d.ts +11 -0
  227. package/dist/ui/src/components/Collapse.d.ts +9 -0
  228. package/dist/ui/src/components/ColorPicker.d.ts +30 -0
  229. package/dist/ui/src/components/Container.d.ts +8 -0
  230. package/dist/ui/src/components/DateTimeField.d.ts +24 -0
  231. package/dist/ui/src/components/DebouncedTextField.d.ts +2 -0
  232. package/dist/ui/src/components/Dialog.d.ts +39 -0
  233. package/dist/ui/src/components/DialogActions.d.ts +7 -0
  234. package/dist/ui/src/components/DialogContent.d.ts +7 -0
  235. package/dist/ui/src/components/DialogTitle.d.ts +10 -0
  236. package/dist/ui/src/components/ErrorBoundary.d.ts +11 -0
  237. package/dist/ui/src/components/ExpandablePanel.d.ts +12 -0
  238. package/dist/ui/src/components/FileUpload.d.ts +23 -0
  239. package/dist/ui/src/components/IconButton.d.ts +12 -0
  240. package/dist/ui/src/components/InfoLabel.d.ts +5 -0
  241. package/dist/ui/src/components/InputLabel.d.ts +11 -0
  242. package/dist/ui/src/components/Label.d.ts +7 -0
  243. package/dist/ui/src/components/LoadingButton.d.ts +7 -0
  244. package/dist/ui/src/components/Markdown.d.ts +10 -0
  245. package/dist/ui/src/components/Menu.d.ts +23 -0
  246. package/dist/ui/src/components/Menubar.d.ts +80 -0
  247. package/dist/ui/src/components/MultiSelect.d.ts +48 -0
  248. package/dist/ui/src/components/Paper.d.ts +6 -0
  249. package/dist/ui/src/components/Popover.d.ts +24 -0
  250. package/dist/ui/src/components/RadioGroup.d.ts +28 -0
  251. package/dist/ui/src/components/ResizablePanels.d.ts +18 -0
  252. package/dist/ui/src/components/SearchBar.d.ts +22 -0
  253. package/dist/ui/src/components/Select.d.ts +43 -0
  254. package/dist/ui/src/components/Separator.d.ts +5 -0
  255. package/dist/ui/src/components/Sheet.d.ts +22 -0
  256. package/dist/ui/src/components/Skeleton.d.ts +6 -0
  257. package/dist/ui/src/components/Slider.d.ts +21 -0
  258. package/dist/ui/src/components/Table.d.ts +34 -0
  259. package/dist/ui/src/components/Tabs.d.ts +19 -0
  260. package/dist/ui/src/components/TextField.d.ts +58 -0
  261. package/dist/ui/src/components/TextareaAutosize.d.ts +43 -0
  262. package/dist/ui/src/components/ToggleButtonGroup.d.ts +30 -0
  263. package/dist/ui/src/components/Tooltip.d.ts +19 -0
  264. package/dist/ui/src/components/Typography.d.ts +36 -0
  265. package/dist/ui/src/components/VirtualTable/VirtualTable.d.ts +11 -0
  266. package/dist/ui/src/components/VirtualTable/VirtualTableCell.d.ts +21 -0
  267. package/dist/ui/src/components/VirtualTable/VirtualTableHeader.d.ts +29 -0
  268. package/dist/ui/src/components/VirtualTable/VirtualTableHeaderRow.d.ts +2 -0
  269. package/dist/ui/src/components/VirtualTable/VirtualTableProps.d.ts +243 -0
  270. package/dist/ui/src/components/VirtualTable/VirtualTableRow.d.ts +3 -0
  271. package/dist/ui/src/components/VirtualTable/index.d.ts +3 -0
  272. package/dist/ui/src/components/VirtualTable/types.d.ts +38 -0
  273. package/dist/ui/src/components/common/SelectInputLabel.d.ts +5 -0
  274. package/dist/ui/src/components/index.d.ts +53 -0
  275. package/dist/ui/src/hooks/PortalContainerContext.d.ts +31 -0
  276. package/dist/ui/src/hooks/index.d.ts +6 -0
  277. package/dist/ui/src/hooks/useDebounceCallback.d.ts +1 -0
  278. package/dist/ui/src/hooks/useDebounceValue.d.ts +1 -0
  279. package/dist/ui/src/hooks/useDebouncedCallback.d.ts +1 -0
  280. package/dist/ui/src/hooks/useInjectStyles.d.ts +7 -0
  281. package/dist/ui/src/hooks/useOutsideAlerter.d.ts +5 -0
  282. package/dist/ui/src/icons/GitHubIcon.d.ts +2 -0
  283. package/dist/ui/src/icons/HandleIcon.d.ts +1 -0
  284. package/dist/ui/src/icons/Icon.d.ts +20 -0
  285. package/dist/ui/src/icons/cool_icon_keys.d.ts +1 -0
  286. package/dist/ui/src/icons/icon_keys.d.ts +1 -0
  287. package/dist/ui/src/icons/index.d.ts +6 -0
  288. package/dist/ui/src/index.d.ts +5 -0
  289. package/dist/ui/src/styles.d.ts +12 -0
  290. package/dist/ui/src/util/chip_colors.d.ts +4 -0
  291. package/dist/ui/src/util/cls.d.ts +2 -0
  292. package/dist/ui/src/util/debounce.d.ts +10 -0
  293. package/dist/ui/src/util/hash.d.ts +1 -0
  294. package/dist/ui/src/util/index.d.ts +4 -0
  295. package/dist/ui/src/util/key_to_icon_component.d.ts +1 -0
  296. package/package.json +86 -0
  297. package/src/api.ts +198 -0
  298. package/src/components/DataEnhancementControllerProvider.tsx +339 -0
  299. package/src/components/FormEnhanceAction.tsx +273 -0
  300. package/src/editor/useEditorAIController.tsx +37 -0
  301. package/src/index.ts +10 -0
  302. package/src/locales/de.ts +21 -0
  303. package/src/locales/en.ts +21 -0
  304. package/src/locales/es.ts +21 -0
  305. package/src/locales/fr.ts +21 -0
  306. package/src/locales/hi.ts +21 -0
  307. package/src/locales/it.ts +21 -0
  308. package/src/locales/pt.ts +21 -0
  309. package/src/tests/diffStrings.test.ts +128 -0
  310. package/src/types/data_enhancement_controller.tsx +75 -0
  311. package/src/types/subscriptions_message_props.tsx +1 -0
  312. package/src/useDataEnhancementPlugin.tsx +66 -0
  313. package/src/utils/diffStrings.ts +70 -0
  314. package/src/utils/properties.ts +168 -0
  315. package/src/utils/strings_counter.ts +22 -0
  316. package/src/utils/suggestions.ts +6 -0
  317. package/src/utils/values.ts +12 -0
  318. package/src/vite-env.d.ts +1 -0
@@ -0,0 +1,751 @@
1
+ import { c } from "react-compiler-runtime";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import React, { useState, useRef, useMemo, useEffect, useCallback, useContext, useDeferredValue } from "react";
4
+ import { useAuthController, useSnackbarController, useLargeLayout, AIIcon } from "@rebasepro/core";
5
+ import { getFieldId, useUrlController } from "@rebasepro/admin";
6
+ import { isPropertyBuilder, stripCollectionPath } from "@rebasepro/common";
7
+ import { getValueInPath } from "@rebasepro/utils";
8
+ import { Menu, MenuItem, Separator, IconButton, iconSize, TextareaAutosize, cls, focusedDisabled, CircularProgress, Button } from "@rebasepro/ui";
9
+ import { XIcon, SendIcon } from "lucide-react";
10
+ function flatMapEntityValues(values, path = "") {
11
+ if (!values) return {};
12
+ return Object.entries(values).flatMap(([key, value]) => {
13
+ const currentPath = path ? `${path}.${key}` : key;
14
+ if (typeof value === "object") {
15
+ return flatMapEntityValues(value, currentPath);
16
+ } else {
17
+ return {
18
+ [currentPath]: value
19
+ };
20
+ }
21
+ }).reduce((acc, curr) => ({
22
+ ...acc,
23
+ ...curr
24
+ }), {});
25
+ }
26
+ const DEFAULT_SERVER = "https://api.rebase.pro";
27
+ async function enhanceDataAPIStream(props) {
28
+ const flatValues = flatMapEntityValues(props.values);
29
+ const properties = props.properties;
30
+ const inputEntity = {
31
+ entityId: props.entityId,
32
+ values: flatValues
33
+ };
34
+ const request = {
35
+ inputEntity,
36
+ properties,
37
+ entityName: props.entityName,
38
+ entityDescription: props.entityDescription,
39
+ propertyKey: props.propertyKey,
40
+ propertyInstructions: props.propertyInstructions,
41
+ instructions: props.instructions
42
+ };
43
+ console.debug("enhanceDataAPIStream", request);
44
+ return fetch((props.host ?? DEFAULT_SERVER) + "/data/enhance_stream/", {
45
+ // mode: "no-cors",
46
+ method: "POST",
47
+ headers: {
48
+ "Content-Type": "application/json",
49
+ Authorization: `Basic ${props.firebaseToken}`,
50
+ "x-de-api-key": `Basic ${props.apiKey}`
51
+ // "x-de-version": version
52
+ },
53
+ body: JSON.stringify(request)
54
+ }).then(async (res) => {
55
+ if (!res.ok) {
56
+ console.error("enhanceDataAPIStream error", res);
57
+ throw await res.json();
58
+ }
59
+ const reader = res.body?.getReader();
60
+ if (!reader) {
61
+ throw new Error("No reader");
62
+ }
63
+ for await (const chunk of readChunks(reader)) {
64
+ const str = new TextDecoder().decode(chunk);
65
+ try {
66
+ str.split("&$# ").forEach((s) => {
67
+ if (s && s.length > 0) {
68
+ const data = JSON.parse(s.trim());
69
+ if (data.type === "suggestion_delta") props.onUpdateDelta(data.data.propertyKey, data.data.partialValue);
70
+ else if (data.type === "suggestion") props.onUpdate(data.data);
71
+ else if (data.type === "result") props.onEnd(data.data);
72
+ }
73
+ });
74
+ } catch (e) {
75
+ console.error("str", str);
76
+ console.error("Error parsing stream", e);
77
+ props.onError(e);
78
+ }
79
+ }
80
+ });
81
+ }
82
+ function readChunks(reader) {
83
+ return {
84
+ async *[Symbol.asyncIterator]() {
85
+ let readResult = await reader.read();
86
+ while (!readResult.done) {
87
+ yield readResult.value;
88
+ readResult = await reader.read();
89
+ }
90
+ }
91
+ };
92
+ }
93
+ async function fetchEntityPromptSuggestion(props) {
94
+ return fetch((props.host ?? DEFAULT_SERVER) + "/data/prompt_autocomplete/", {
95
+ // mode: "no-cors",
96
+ method: "POST",
97
+ headers: {
98
+ "Content-Type": "application/json",
99
+ Authorization: `Basic ${props.firebaseToken}`,
100
+ "x-de-api-key": `Basic ${props.apiKey}`
101
+ },
102
+ body: JSON.stringify({
103
+ entityName: props.entityName,
104
+ input: props.input ?? null
105
+ })
106
+ }).then(async (res) => {
107
+ const data = await res.json();
108
+ if (!res.ok) {
109
+ console.error("fetchEntityPromptSuggestion", data);
110
+ throw Error(data.message);
111
+ }
112
+ return {
113
+ prompts: data.data.prompts.map((e) => ({
114
+ prompt: e,
115
+ type: "sample"
116
+ }))
117
+ };
118
+ });
119
+ }
120
+ async function autocompleteStream(props) {
121
+ let result = "";
122
+ return fetch((props.host ?? DEFAULT_SERVER) + "/data/autocomplete/", {
123
+ // mode: "no-cors",
124
+ method: "POST",
125
+ headers: {
126
+ "Content-Type": "application/json",
127
+ Authorization: `Basic ${props.firebaseToken}`
128
+ // "x-de-version": version
129
+ },
130
+ body: JSON.stringify({
131
+ textBefore: props.textBefore,
132
+ textAfter: props.textAfter
133
+ })
134
+ }).then(async (res) => {
135
+ if (!res.ok) {
136
+ console.error("enhanceDataAPIStream error", res);
137
+ throw await res.json();
138
+ }
139
+ const reader = res.body?.getReader();
140
+ if (!reader) {
141
+ throw new Error("No reader");
142
+ }
143
+ for await (const chunk of readChunks(reader)) {
144
+ const str = new TextDecoder().decode(chunk);
145
+ result += str;
146
+ console.debug("Autocomplete update:", str);
147
+ props.onUpdate(str);
148
+ }
149
+ }).then(() => {
150
+ console.debug("Autocomplete result:", result);
151
+ return result;
152
+ });
153
+ }
154
+ function getAppendableSuggestion(suggestion, value) {
155
+ const suggestionIncludesValue = typeof suggestion === "string" && typeof value === "string" && suggestion.toLowerCase().trim().startsWith(value.toLowerCase().trim());
156
+ return typeof value === "string" && suggestionIncludesValue ? suggestion.substring(suggestion.toLowerCase().trim().indexOf(value.toLowerCase().trim()) + value.trim().length) : void 0;
157
+ }
158
+ function getSimplifiedProperties(properties, values, path = "") {
159
+ if (!properties) return {};
160
+ return Object.entries(properties).map(([key, property]) => {
161
+ if (isPropertyBuilder(property)) return {};
162
+ const fullKey = path ? `${path}.${key}` : key;
163
+ const valueInPath = getValueInPath(values, fullKey);
164
+ return getSimplifiedProperty(property, fullKey, valueInPath);
165
+ }).reduce((a, b) => ({
166
+ ...a,
167
+ ...b
168
+ }), {});
169
+ }
170
+ function getSimpleProperty(property) {
171
+ const fieldId = getFieldId(property);
172
+ if (!fieldId) {
173
+ console.error("No fieldId found for property", property);
174
+ throw new Error("Field id not found");
175
+ }
176
+ return {
177
+ name: property.name,
178
+ description: property.description,
179
+ type: property.type,
180
+ fieldConfigId: fieldId,
181
+ enum: "enum" in property && property.enum ? getSimpleEnumValues(property.enum) : void 0,
182
+ disabled: Boolean(property.ui?.disabled || property.ui?.readOnly)
183
+ };
184
+ }
185
+ function getSimplifiedProperty(property, path, value) {
186
+ if (isPropertyBuilder(property)) return {};
187
+ if (property.type === "array") {
188
+ if (property.of && !Array.isArray(property.of) && !isPropertyBuilder(property.of)) {
189
+ const arrayParentProperty = {
190
+ name: property.name,
191
+ description: property.description,
192
+ type: property.type,
193
+ fieldConfigId: "repeat",
194
+ disabled: Boolean(property.ui?.disabled || property.ui?.readOnly),
195
+ of: getSimpleProperty(property.of)
196
+ };
197
+ const result = {
198
+ [path]: arrayParentProperty
199
+ };
200
+ return result;
201
+ } else if (property.oneOf) {
202
+ const arrayParentProperty = {
203
+ name: property.name,
204
+ description: property.description,
205
+ type: property.type,
206
+ fieldConfigId: "block",
207
+ disabled: Boolean(property.ui?.disabled || property.ui?.readOnly),
208
+ oneOf: {
209
+ typeField: property.oneOf.typeField,
210
+ valueField: property.oneOf.valueField,
211
+ properties: Object.entries(property.oneOf.properties).map(([key, prop]) => ({
212
+ [key]: getSimpleProperty(prop)
213
+ })).reduce((a, b) => ({
214
+ ...a,
215
+ ...b
216
+ }), {})
217
+ }
218
+ };
219
+ if (!Array.isArray(value)) {
220
+ return {
221
+ [path]: arrayParentProperty
222
+ };
223
+ }
224
+ return value.map((v, i) => {
225
+ if (v == null) return {};
226
+ const typeKey = property.oneOf.typeField ?? "type";
227
+ const oneOfType = v[typeKey];
228
+ const valueKey = property.oneOf.valueField ?? "value";
229
+ const oneOfValue = v[valueKey];
230
+ const childProperty = property.oneOf.properties[oneOfType];
231
+ if (childProperty === void 0) {
232
+ console.error(`No property found for type ${oneOfType}`, property.oneOf.properties);
233
+ return {};
234
+ }
235
+ const simplifiedProperty = getSimplifiedProperty(childProperty, `${path}.${i}.${valueKey}`, oneOfValue);
236
+ return {
237
+ [`${path}.${i}.${typeKey}`]: oneOfType,
238
+ ...simplifiedProperty
239
+ };
240
+ }).reduce((a, b) => ({
241
+ ...a,
242
+ ...b
243
+ }), {
244
+ [path]: arrayParentProperty
245
+ });
246
+ }
247
+ } else if (property.type === "map") {
248
+ if (property.properties) {
249
+ const mapProperties = Object.entries(property.properties).map(([key, childProperty]) => {
250
+ const childValue = value?.[key];
251
+ return getSimplifiedProperty(childProperty, key, childValue);
252
+ }).map((o) => attachPathToKeys(o, path)).reduce((a, b) => ({
253
+ ...a,
254
+ ...b
255
+ }), {});
256
+ if (Object.keys(mapProperties).length === 0) return {};
257
+ const mapParentProperty = {
258
+ name: property.name,
259
+ description: property.description,
260
+ type: property.type,
261
+ fieldConfigId: "group",
262
+ disabled: Boolean(property.ui?.disabled || property.ui?.readOnly)
263
+ };
264
+ return {
265
+ [path]: mapParentProperty,
266
+ ...mapProperties
267
+ };
268
+ }
269
+ } else {
270
+ const fieldId = getFieldId(property);
271
+ if (!fieldId) {
272
+ console.warn(`No fieldId found for property ${path} with type ${property.type}`);
273
+ return {};
274
+ }
275
+ return {
276
+ [path]: getSimpleProperty(property)
277
+ };
278
+ }
279
+ return {};
280
+ }
281
+ function attachPathToKeys(obj, path = "") {
282
+ return Object.entries(obj).map(([key, value]) => {
283
+ const fullKey = path ? `${path}.${key}` : key;
284
+ return {
285
+ [fullKey]: value
286
+ };
287
+ }).reduce((a, b) => ({
288
+ ...a,
289
+ ...b
290
+ }), {});
291
+ }
292
+ function getSimpleEnumValues(enumValues) {
293
+ if (Array.isArray(enumValues)) return enumValues.map((v) => String(v.id));
294
+ if (typeof enumValues === "object") return Object.keys(enumValues);
295
+ throw Error("getSimpleEnumValues: Invalid enumValues");
296
+ }
297
+ function useEditorAIController({
298
+ getAuthToken
299
+ }) {
300
+ const autocomplete = async (textBefore, textAfter, onUpdate) => {
301
+ if (!getAuthToken) {
302
+ throw new Error("Firebase token is required");
303
+ }
304
+ const firebaseToken = await getAuthToken();
305
+ return autocompleteStream({
306
+ firebaseToken,
307
+ textBefore,
308
+ textAfter,
309
+ onUpdate
310
+ });
311
+ };
312
+ return {
313
+ autocomplete
314
+ };
315
+ }
316
+ const DataEnhancementControllerContext = React.createContext(null);
317
+ const useDataEnhancementController = () => {
318
+ return useContext(DataEnhancementControllerContext);
319
+ };
320
+ function getPropertyFromKey(properties, propertyKey) {
321
+ if (propertyKey in properties) {
322
+ return properties[propertyKey];
323
+ } else {
324
+ const split = propertyKey.split(".");
325
+ if (split.length === 1) {
326
+ return void 0;
327
+ }
328
+ const parentKey = split.slice(0, split.length - 1).join(".");
329
+ return getPropertyFromKey(properties, parentKey);
330
+ }
331
+ }
332
+ function DataEnhancementControllerProvider({
333
+ apiKey,
334
+ getConfigForPath,
335
+ children,
336
+ host,
337
+ path,
338
+ collection,
339
+ formContext
340
+ }) {
341
+ const [enabled, setEnabled] = useState(false);
342
+ const [suggestions, setSuggestions] = useState({});
343
+ const [loadingSuggestions, setLoadingSuggestions] = useState([]);
344
+ const enhancingInProgress = useRef(false);
345
+ const authController = useAuthController();
346
+ const snackbarController = useSnackbarController();
347
+ const properties = useMemo(() => getSimplifiedProperties(collection.properties, formContext?.values ?? {}), [formContext?.values]);
348
+ const valuesRef = React.useRef(formContext?.values ?? {});
349
+ useEffect(() => {
350
+ if (!enhancingInProgress.current) valuesRef.current = formContext?.values ?? {};
351
+ }, [formContext?.values]);
352
+ const allowReferenceDataSelection = false;
353
+ const updateConfig = useCallback(async () => {
354
+ if (!getConfigForPath) return;
355
+ const config = getConfigForPath({
356
+ path,
357
+ collection
358
+ });
359
+ if (config) {
360
+ setEnabled(true);
361
+ }
362
+ }, [collection, getConfigForPath, path]);
363
+ useEffect(() => {
364
+ if (!getConfigForPath) {
365
+ setEnabled(true);
366
+ } else {
367
+ updateConfig();
368
+ }
369
+ }, [getConfigForPath, updateConfig]);
370
+ const urlController = useUrlController();
371
+ const clearSuggestion = useCallback((propertyKey) => {
372
+ setSuggestions((prev) => {
373
+ const {
374
+ [propertyKey]: _,
375
+ ...rest
376
+ } = prev;
377
+ return rest;
378
+ });
379
+ }, []);
380
+ const appendValueDelta = useCallback((propertyKey_0, delta) => {
381
+ const property = getPropertyFromKey(properties, propertyKey_0);
382
+ if (delta === null || property?.disabled) {
383
+ return;
384
+ }
385
+ const value = getValueInPath(valuesRef.current, propertyKey_0);
386
+ const currentValue = value ? value + "" : "";
387
+ const updatedValue = currentValue + delta;
388
+ valuesRef.current = {
389
+ ...valuesRef.current,
390
+ [propertyKey_0]: updatedValue
391
+ };
392
+ formContext?.setFieldValue(propertyKey_0, updatedValue, false);
393
+ setSuggestions((prev_0) => ({
394
+ ...prev_0,
395
+ [propertyKey_0]: (prev_0[propertyKey_0] ?? "") + delta
396
+ }));
397
+ }, [properties, formContext]);
398
+ const updateSuggestedValues = useCallback((currentValues, updatedValues, replaceValues) => {
399
+ setLoadingSuggestions((prev_1) => {
400
+ return prev_1.filter((p) => !Object.keys(updatedValues).includes(p));
401
+ });
402
+ Object.entries(updatedValues).forEach(([propertyKey_1, suggestion]) => {
403
+ const value_0 = getValueInPath(currentValues, propertyKey_1);
404
+ const property_0 = getPropertyFromKey(properties, propertyKey_1);
405
+ if (!property_0 || suggestion === null || property_0?.disabled) {
406
+ return;
407
+ }
408
+ if (typeof suggestion === "number") {
409
+ formContext?.setFieldValue(propertyKey_1, suggestion);
410
+ return;
411
+ }
412
+ if (replaceValues) {
413
+ formContext?.setFieldValue(propertyKey_1, suggestion);
414
+ return;
415
+ }
416
+ const appendableValue = getAppendableSuggestion(suggestion, value_0);
417
+ const currentValue_0 = value_0 ? value_0 + "" : "";
418
+ if (appendableValue) {
419
+ formContext?.setFieldValue(propertyKey_1, suggestion);
420
+ } else {
421
+ const multiline = property_0?.fieldConfigId === "multiline" || property_0?.fieldConfigId === "markdown";
422
+ const trimmedValue = currentValue_0.trimEnd();
423
+ if (multiline && (trimmedValue.endsWith(".") || trimmedValue.endsWith("?") || trimmedValue.endsWith("!") || trimmedValue.endsWith(":"))) {
424
+ formContext?.setFieldValue(propertyKey_1, trimmedValue + "\n\n" + suggestion.trimStart());
425
+ } else {
426
+ formContext?.setFieldValue(propertyKey_1, trimmedValue + (trimmedValue.length > 0 ? " " : "") + suggestion);
427
+ }
428
+ }
429
+ });
430
+ setSuggestions((prev_2) => ({
431
+ ...prev_2,
432
+ ...Object.keys(updatedValues).reduce((acc, key) => {
433
+ const value_1 = getValueInPath(formContext?.values, key);
434
+ const suggestion_0 = updatedValues[key];
435
+ return {
436
+ ...acc,
437
+ [key]: getAppendableSuggestion(suggestion_0, value_1) ?? suggestion_0
438
+ };
439
+ }, {})
440
+ }));
441
+ }, [properties, formContext]);
442
+ const displayNeededSubscriptionSnackbar = useCallback((projectId) => {
443
+ snackbarController.open({
444
+ type: "warning",
445
+ message: "A valid subscription is needed in order to use this function.",
446
+ autoHideDuration: 4e3
447
+ });
448
+ }, [snackbarController]);
449
+ const editorAIController = useEditorAIController({
450
+ getAuthToken: authController.getAuthToken
451
+ });
452
+ const clearAllSuggestions = useCallback(() => {
453
+ setSuggestions({});
454
+ }, []);
455
+ const enhance = useCallback(async (props) => {
456
+ if (!authController.user) {
457
+ snackbarController.open({
458
+ type: "warning",
459
+ message: "You need to be logged in to enhance data"
460
+ });
461
+ return Promise.reject(new Error("Not logged in"));
462
+ }
463
+ const resolvedPath = urlController.resolveDatabasePathsFrom(path);
464
+ const firebaseToken = await authController.getAuthToken();
465
+ if (props.propertyKey) {
466
+ clearSuggestion(props.propertyKey);
467
+ } else {
468
+ clearAllSuggestions();
469
+ }
470
+ setLoadingSuggestions((prev_3) => [...prev_3, ...props.propertyKey ? [props.propertyKey] : Object.keys(properties)]);
471
+ enhancingInProgress.current = true;
472
+ const currentValues_0 = valuesRef.current ?? {};
473
+ return new Promise((resolve, reject) => {
474
+ function onError(e) {
475
+ setLoadingSuggestions([]);
476
+ if (e.code === "payment-required") {
477
+ const projectId_0 = e.data.projectId;
478
+ displayNeededSubscriptionSnackbar(projectId_0);
479
+ } else {
480
+ console.error("Enhance error", e);
481
+ }
482
+ reject(e);
483
+ enhancingInProgress.current = false;
484
+ }
485
+ try {
486
+ enhanceDataAPIStream({
487
+ ...props,
488
+ host,
489
+ apiKey,
490
+ properties,
491
+ path: resolvedPath,
492
+ entityName: collection.singularName ?? collection.name,
493
+ entityDescription: collection.description,
494
+ firebaseToken,
495
+ onUpdate: (suggestions_0) => {
496
+ console.debug("de onUpdate", suggestions_0);
497
+ updateSuggestedValues(currentValues_0, suggestions_0, props.replaceValues ?? false);
498
+ },
499
+ onUpdateDelta: (propertyKey_2, partialValue) => {
500
+ appendValueDelta(propertyKey_2, partialValue);
501
+ },
502
+ onError,
503
+ onEnd: (result) => {
504
+ console.debug("de onEnd", result);
505
+ if (result.errors) {
506
+ result.errors.forEach((error) => {
507
+ snackbarController.open({
508
+ type: "warning",
509
+ message: error
510
+ });
511
+ });
512
+ }
513
+ if (Object.keys(result.suggestions).length === 0) {
514
+ snackbarController.open({
515
+ type: "info",
516
+ autoHideDuration: 1800,
517
+ message: "No fields were updated"
518
+ });
519
+ }
520
+ setLoadingSuggestions([]);
521
+ resolve(result);
522
+ enhancingInProgress.current = false;
523
+ }
524
+ }).catch(onError);
525
+ } catch (e_0) {
526
+ onError(e_0);
527
+ }
528
+ });
529
+ }, [authController, urlController, path, clearSuggestion, clearAllSuggestions, properties, host, apiKey, collection, updateSuggestedValues, appendValueDelta, displayNeededSubscriptionSnackbar, snackbarController]);
530
+ const getSamplePrompts = useCallback(async (entityName, input) => {
531
+ const firebaseToken_0 = await authController.getAuthToken();
532
+ return fetchEntityPromptSuggestion({
533
+ host,
534
+ entityName,
535
+ firebaseToken: firebaseToken_0,
536
+ apiKey,
537
+ input
538
+ });
539
+ }, [apiKey, authController.getAuthToken, host]);
540
+ const dataEnhancementController = useMemo(() => ({
541
+ enabled,
542
+ suggestions,
543
+ clearSuggestion,
544
+ enhance,
545
+ allowReferenceDataSelection,
546
+ clearAllSuggestions,
547
+ getSamplePrompts,
548
+ loadingSuggestions,
549
+ editorAIController
550
+ }), [enabled, suggestions, clearSuggestion, enhance, allowReferenceDataSelection, clearAllSuggestions, getSamplePrompts, loadingSuggestions, editorAIController]);
551
+ return /* @__PURE__ */ jsx(DataEnhancementControllerContext.Provider, { value: dataEnhancementController, children });
552
+ }
553
+ function FormEnhanceAction({
554
+ entityId,
555
+ path,
556
+ status,
557
+ collection,
558
+ formContext,
559
+ openEntityMode
560
+ }) {
561
+ const largeLayout = useLargeLayout();
562
+ const storageKey = createLocalStorageKey(path, status);
563
+ const [loading, setLoading] = React.useState(false);
564
+ const dataEnhancementController = useDataEnhancementController();
565
+ const [samplePrompts, setSamplePrompts] = React.useState(void 0);
566
+ const [instructions, setInstructions] = React.useState("");
567
+ const {
568
+ suggestions,
569
+ getSamplePrompts
570
+ } = dataEnhancementController;
571
+ const loadingPrompts = useRef(false);
572
+ const updateSuggestedPrompts = useCallback(async function updateSuggestedPrompts2(instructions_0) {
573
+ if (loadingPrompts.current) return;
574
+ loadingPrompts.current = true;
575
+ const prompts = status === "new" ? (await getSamplePrompts(collection.singularName ?? collection.name, instructions_0)).prompts : getPromptsForExistingEntities(collection.properties);
576
+ const recentPromptsFromStorage = getRecentPromptsFromStorage(storageKey);
577
+ const recentPrompts = recentPromptsFromStorage.map((prompt) => prompt.prompt);
578
+ setSamplePrompts([...recentPromptsFromStorage, ...prompts.filter((p) => !recentPrompts.includes(p.prompt))].slice(0, 5));
579
+ loadingPrompts.current = false;
580
+ }, [collection.name, collection.singularName, getSamplePrompts, status]);
581
+ useDeferredValue(formContext?.values);
582
+ useEffect(() => {
583
+ if (!samplePrompts) {
584
+ setSamplePrompts(getRecentPromptsFromStorage(storageKey));
585
+ updateSuggestedPrompts().then();
586
+ }
587
+ }, [samplePrompts, storageKey, updateSuggestedPrompts, instructions, status]);
588
+ useEffect(() => {
589
+ updateSuggestedPrompts().then();
590
+ }, [status]);
591
+ const enhance = (prompt_0) => {
592
+ if (!formContext?.values) return;
593
+ setLoading(true);
594
+ if (prompt_0) {
595
+ addRecentPrompt(storageKey, prompt_0);
596
+ setSamplePrompts([{
597
+ prompt: prompt_0,
598
+ type: "recent"
599
+ }, ...(samplePrompts ?? []).slice(0, 5)]);
600
+ }
601
+ return dataEnhancementController.enhance({
602
+ entityId,
603
+ values: formContext.values,
604
+ instructions: prompt_0,
605
+ replaceValues: true
606
+ }).finally(() => {
607
+ setLoading(false);
608
+ });
609
+ };
610
+ if (!dataEnhancementController?.enabled) return null;
611
+ Object.values(suggestions).filter(Boolean).length > 0;
612
+ (samplePrompts ?? []).length > 0 && instructions.length === 0;
613
+ function submit() {
614
+ enhance(instructions);
615
+ }
616
+ return /* @__PURE__ */ jsxs(Menu, { align: "end", sideOffset: 8, className: "max-w-[100vw]", trigger: /* @__PURE__ */ jsxs(Button, { variant: "filled", color: "neutral", fullWidth: largeLayout && openEntityMode === "full_screen", size: "small", disabled: loading, children: [
617
+ !loading && /* @__PURE__ */ jsx(AIIcon, { size: "small" }),
618
+ loading && /* @__PURE__ */ jsx(CircularProgress, { size: "small" }),
619
+ "Autofill"
620
+ ] }), children: [
621
+ /* @__PURE__ */ jsxs(MenuItem, { className: "py-4", onClick: () => {
622
+ enhance();
623
+ }, children: [
624
+ /* @__PURE__ */ jsx(AIIcon, { size: "small" }),
625
+ "Autofill based on the current content"
626
+ ] }),
627
+ /* @__PURE__ */ jsx(Separator, { orientation: "horizontal", className: "mt-2" }),
628
+ samplePrompts?.map((samplePrompt, index) => {
629
+ return /* @__PURE__ */ jsxs(MenuItem, { onClick: () => {
630
+ setInstructions(samplePrompt.prompt);
631
+ enhance(samplePrompt.prompt);
632
+ }, children: [
633
+ /* @__PURE__ */ jsx("div", { className: "pl-9 grow text-text-secondary dark:text-text-secondary-dark", children: samplePrompt.prompt }),
634
+ samplePrompt.type === "recent" && /* @__PURE__ */ jsx(IconButton, { onClick: (e) => {
635
+ e.preventDefault();
636
+ e.stopPropagation();
637
+ removeRecentPrompt(storageKey, samplePrompt.prompt);
638
+ setSamplePrompts((samplePrompts ?? []).filter((p_0) => p_0.prompt !== samplePrompt.prompt));
639
+ }, size: "smallest", children: /* @__PURE__ */ jsx(XIcon, { size: iconSize.smallest }) })
640
+ ] }, index + "_" + samplePrompt.prompt);
641
+ }),
642
+ /* @__PURE__ */ jsx(Separator, { orientation: "horizontal" }),
643
+ /* @__PURE__ */ jsxs("div", { className: cls("my-2 w-[500px] max-w-full flex items-start text-surface-700 dark:text-surface-200"), children: [
644
+ /* @__PURE__ */ jsx(TextareaAutosize, { className: cls("p-4 rounded-lg resize-none bg-surface-100 dark:bg-surface-950 mx-2 w-full grow outline-hidden max-h-[300px] overflow-auto", focusedDisabled), value: instructions, autoFocus: status === "new", disabled: loading, onFocus: (event) => {
645
+ event.stopPropagation();
646
+ }, placeholder: "...or provide instructions", onKeyDown: (e_0) => {
647
+ e_0.stopPropagation();
648
+ if (e_0.key === "Enter" && !e_0.shiftKey) {
649
+ e_0.preventDefault();
650
+ submit();
651
+ }
652
+ }, onChange: (e_1) => {
653
+ setInstructions(e_1.target.value);
654
+ } }),
655
+ /* @__PURE__ */ jsx(IconButton, { size: "small", onClick: () => {
656
+ setInstructions("");
657
+ }, color: !instructions ? "primary" : void 0, disabled: loading || !instructions, children: /* @__PURE__ */ jsx(XIcon, { size: iconSize.small }) }),
658
+ /* @__PURE__ */ jsxs(IconButton, { onClick: () => enhance(instructions), size: "small", color: !instructions ? "primary" : void 0, disabled: loading || !instructions, children: [
659
+ loading && /* @__PURE__ */ jsx(CircularProgress, { size: "smallest" }),
660
+ !loading && /* @__PURE__ */ jsx(SendIcon, { color: "primary" })
661
+ ] })
662
+ ] })
663
+ ] });
664
+ }
665
+ function getPromptsForExistingEntities(properties) {
666
+ const multilineProperties = Object.values(properties).filter((p) => {
667
+ if (isPropertyBuilder(p)) {
668
+ return false;
669
+ }
670
+ return p.type === "string" && (p.ui?.markdown || p.ui?.multiline);
671
+ });
672
+ const multilinePrompt = multilineProperties.length > 0 ? multilineProperties[Math.floor(Math.random() * multilineProperties.length)] : void 0;
673
+ const prompts = ["Fill the missing fields", "Translate the missing content"];
674
+ if (multilinePrompt) {
675
+ prompts.push(`Add 2 paragraphs to '${multilinePrompt.name}'`);
676
+ }
677
+ return prompts.map((p) => ({
678
+ prompt: p,
679
+ type: "sample"
680
+ }));
681
+ }
682
+ const createLocalStorageKey = (path, status) => {
683
+ const statusString = status === "new" ? "new" : "existing";
684
+ return `data_enhancement::${statusString}::${stripCollectionPath(path)}`;
685
+ };
686
+ const getRecentPromptsFromStorage = (storageKey) => {
687
+ const item = localStorage.getItem(storageKey);
688
+ return item ? JSON.parse(item).map((e) => ({
689
+ prompt: e,
690
+ type: "recent"
691
+ })) : [];
692
+ };
693
+ const addRecentPrompt = (storageKey, prompt) => {
694
+ if (!prompt || prompt.trim().length === 0) {
695
+ return;
696
+ }
697
+ const recentPrompts = getRecentPromptsFromStorage(storageKey);
698
+ localStorage.setItem(storageKey, JSON.stringify([prompt, ...recentPrompts.map((e) => e.prompt).filter((e) => e !== prompt).slice(0, 5)]));
699
+ };
700
+ const removeRecentPrompt = (storageKey, prompt) => {
701
+ localStorage.setItem(storageKey, JSON.stringify(getRecentPromptsFromStorage(storageKey).map((e) => e.prompt).filter((e) => e !== prompt)));
702
+ };
703
+ const DEFAULT_API_KEY = "fcms-U9jdDii0xXWSDC34asfrf54lbkFJBfKfRWcEDEwdc4V5wDWEDF";
704
+ function useDataEnhancementPlugin(props) {
705
+ const $ = c(5);
706
+ const apiKey = props?.apiKey ?? DEFAULT_API_KEY;
707
+ const getConfigForPath = props?.getConfigForPath;
708
+ props?.host;
709
+ let t0;
710
+ let t1;
711
+ if ($[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
712
+ t1 = [{
713
+ slot: "form.actions",
714
+ Component: FormEnhanceAction,
715
+ order: 40
716
+ }];
717
+ $[0] = t1;
718
+ } else {
719
+ t1 = $[0];
720
+ }
721
+ const t2 = props?.host;
722
+ let t3;
723
+ if ($[1] !== apiKey || $[2] !== getConfigForPath || $[3] !== t2) {
724
+ t3 = {
725
+ key: "data_enhancement",
726
+ slots: t1,
727
+ providers: [{
728
+ scope: "form",
729
+ Component: DataEnhancementControllerProvider,
730
+ props: {
731
+ apiKey,
732
+ getConfigForPath,
733
+ host: t2
734
+ }
735
+ }]
736
+ };
737
+ $[1] = apiKey;
738
+ $[2] = getConfigForPath;
739
+ $[3] = t2;
740
+ $[4] = t3;
741
+ } else {
742
+ t3 = $[4];
743
+ }
744
+ t0 = t3;
745
+ return t0;
746
+ }
747
+ export {
748
+ useDataEnhancementPlugin,
749
+ useEditorAIController
750
+ };
751
+ //# sourceMappingURL=index.es.js.map