@rebasepro/admin 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 (780) hide show
  1. package/LICENSE +6 -0
  2. package/dist/CollectionEditorDialog-D509-IMx.js +4731 -0
  3. package/dist/CollectionEditorDialog-D509-IMx.js.map +1 -0
  4. package/dist/CollectionsStudioView-B549BDpU.js +218 -0
  5. package/dist/CollectionsStudioView-B549BDpU.js.map +1 -0
  6. package/dist/ContentHomePage--Bl1FXk7.js +1786 -0
  7. package/dist/ContentHomePage--Bl1FXk7.js.map +1 -0
  8. package/dist/ExportCollectionAction-CttNAdM1.js +439 -0
  9. package/dist/ExportCollectionAction-CttNAdM1.js.map +1 -0
  10. package/dist/ImportCollectionAction-BB33kxAN.js +686 -0
  11. package/dist/ImportCollectionAction-BB33kxAN.js.map +1 -0
  12. package/dist/PropertyEditView-UtDO8g0A.js +8138 -0
  13. package/dist/PropertyEditView-UtDO8g0A.js.map +1 -0
  14. package/dist/RoleChip-QtUFXeTp.js +67 -0
  15. package/dist/RoleChip-QtUFXeTp.js.map +1 -0
  16. package/dist/RolesView-B0E7L0hE.js +426 -0
  17. package/dist/RolesView-B0E7L0hE.js.map +1 -0
  18. package/dist/UsersView-BM2_7VPV.js +494 -0
  19. package/dist/UsersView-BM2_7VPV.js.map +1 -0
  20. package/dist/collection_editor/CollectionEditorDialogsContext.d.ts +19 -0
  21. package/dist/collection_editor/ConfigControllerProvider.d.ts +45 -0
  22. package/dist/collection_editor/_cms_internals.d.ts +29 -0
  23. package/dist/collection_editor/api/generateCollectionApi.d.ts +77 -0
  24. package/dist/collection_editor/api/index.d.ts +1 -0
  25. package/dist/collection_editor/index.d.ts +16 -0
  26. package/dist/collection_editor/pgColumnToProperty.d.ts +6 -0
  27. package/dist/collection_editor/types/collection_editor_controller.d.ts +59 -0
  28. package/dist/collection_editor/types/collection_inference.d.ts +10 -0
  29. package/dist/collection_editor/types/config_controller.d.ts +98 -0
  30. package/dist/collection_editor/types/config_permissions.d.ts +19 -0
  31. package/dist/collection_editor/ui/AddKanbanColumnAction.d.ts +12 -0
  32. package/dist/collection_editor/ui/CollectionViewHeaderAction.d.ts +11 -0
  33. package/dist/collection_editor/ui/EditorCollectionAction.d.ts +2 -0
  34. package/dist/collection_editor/ui/EditorCollectionActionStart.d.ts +2 -0
  35. package/dist/collection_editor/ui/EditorEntityAction.d.ts +2 -0
  36. package/dist/collection_editor/ui/HomePageEditorCollectionAction.d.ts +2 -0
  37. package/dist/collection_editor/ui/KanbanSetupAction.d.ts +11 -0
  38. package/dist/collection_editor/ui/MissingReferenceWidget.d.ts +3 -0
  39. package/dist/collection_editor/ui/NewCollectionButton.d.ts +1 -0
  40. package/dist/collection_editor/ui/NewCollectionCard.d.ts +2 -0
  41. package/dist/collection_editor/ui/PropertyAddColumnComponent.d.ts +8 -0
  42. package/dist/collection_editor/ui/collection_editor/AICollectionGeneratorPopover.d.ts +36 -0
  43. package/dist/collection_editor/ui/collection_editor/AIModifiedPathsContext.d.ts +20 -0
  44. package/dist/collection_editor/ui/collection_editor/CollectionDetailsForm.d.ts +12 -0
  45. package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.d.ts +73 -0
  46. package/dist/collection_editor/ui/collection_editor/CollectionEditorWelcomeView.d.ts +19 -0
  47. package/dist/collection_editor/ui/collection_editor/CollectionJsonImportDialog.d.ts +7 -0
  48. package/dist/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +17 -0
  49. package/dist/collection_editor/ui/collection_editor/CollectionRLSTab.d.ts +12 -0
  50. package/dist/collection_editor/ui/collection_editor/CollectionRelationsTab.d.ts +1 -0
  51. package/dist/collection_editor/ui/collection_editor/CollectionStudioView.d.ts +5 -0
  52. package/dist/collection_editor/ui/collection_editor/CollectionYupValidation.d.ts +14 -0
  53. package/dist/collection_editor/ui/collection_editor/CollectionsStudioView.d.ts +5 -0
  54. package/dist/collection_editor/ui/collection_editor/DisplaySettingsForm.d.ts +3 -0
  55. package/dist/collection_editor/ui/collection_editor/EntityActionsEditTab.d.ts +5 -0
  56. package/dist/collection_editor/ui/collection_editor/EntityActionsSelectDialog.d.ts +4 -0
  57. package/dist/collection_editor/ui/collection_editor/EntityCustomViewsSelectDialog.d.ts +4 -0
  58. package/dist/collection_editor/ui/collection_editor/EnumForm.d.ts +12 -0
  59. package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.d.ts +7 -0
  60. package/dist/collection_editor/ui/collection_editor/GetCodeDialog.d.ts +6 -0
  61. package/dist/collection_editor/ui/collection_editor/KanbanConfigSection.d.ts +4 -0
  62. package/dist/collection_editor/ui/collection_editor/LayoutModeSwitch.d.ts +5 -0
  63. package/dist/collection_editor/ui/collection_editor/PropertyEditView.d.ts +47 -0
  64. package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.d.ts +16 -0
  65. package/dist/collection_editor/ui/collection_editor/PropertyTree.d.ts +31 -0
  66. package/dist/collection_editor/ui/collection_editor/SubcollectionsEditTab.d.ts +12 -0
  67. package/dist/collection_editor/ui/collection_editor/SwitchControl.d.ts +8 -0
  68. package/dist/collection_editor/ui/collection_editor/ViewModeSwitch.d.ts +6 -0
  69. package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.d.ts +7 -0
  70. package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportMapping.d.ts +13 -0
  71. package/dist/collection_editor/ui/collection_editor/import/clean_import_data.d.ts +7 -0
  72. package/dist/collection_editor/ui/collection_editor/properties/BlockPropertyField.d.ts +7 -0
  73. package/dist/collection_editor/ui/collection_editor/properties/BooleanPropertyField.d.ts +3 -0
  74. package/dist/collection_editor/ui/collection_editor/properties/CommonPropertyFields.d.ts +10 -0
  75. package/dist/collection_editor/ui/collection_editor/properties/DateTimePropertyField.d.ts +3 -0
  76. package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.d.ts +9 -0
  77. package/dist/collection_editor/ui/collection_editor/properties/KeyValuePropertyField.d.ts +3 -0
  78. package/dist/collection_editor/ui/collection_editor/properties/MapPropertyField.d.ts +7 -0
  79. package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.d.ts +4 -0
  80. package/dist/collection_editor/ui/collection_editor/properties/NumberPropertyField.d.ts +3 -0
  81. package/dist/collection_editor/ui/collection_editor/properties/ReferencePropertyField.d.ts +14 -0
  82. package/dist/collection_editor/ui/collection_editor/properties/RelationPropertyField.d.ts +15 -0
  83. package/dist/collection_editor/ui/collection_editor/properties/RepeatPropertyField.d.ts +9 -0
  84. package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.d.ts +5 -0
  85. package/dist/collection_editor/ui/collection_editor/properties/StringPropertyField.d.ts +5 -0
  86. package/dist/collection_editor/ui/collection_editor/properties/UrlPropertyField.d.ts +4 -0
  87. package/dist/collection_editor/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.d.ts +3 -0
  88. package/dist/collection_editor/ui/collection_editor/properties/conditions/ConditionsEditor.d.ts +10 -0
  89. package/dist/collection_editor/ui/collection_editor/properties/conditions/ConditionsPanel.d.ts +3 -0
  90. package/dist/collection_editor/ui/collection_editor/properties/conditions/EnumConditionsEditor.d.ts +6 -0
  91. package/dist/collection_editor/ui/collection_editor/properties/conditions/index.d.ts +6 -0
  92. package/dist/collection_editor/ui/collection_editor/properties/conditions/property_paths.d.ts +19 -0
  93. package/dist/collection_editor/ui/collection_editor/properties/validation/ArrayPropertyValidation.d.ts +5 -0
  94. package/dist/collection_editor/ui/collection_editor/properties/validation/GeneralPropertyValidation.d.ts +4 -0
  95. package/dist/collection_editor/ui/collection_editor/properties/validation/NumberPropertyValidation.d.ts +3 -0
  96. package/dist/collection_editor/ui/collection_editor/properties/validation/StringPropertyValidation.d.ts +11 -0
  97. package/dist/collection_editor/ui/collection_editor/properties/validation/ValidationPanel.d.ts +3 -0
  98. package/dist/collection_editor/ui/collection_editor/templates/blog_template.d.ts +2 -0
  99. package/dist/collection_editor/ui/collection_editor/templates/pages_template.d.ts +2 -0
  100. package/dist/collection_editor/ui/collection_editor/templates/products_template.d.ts +2 -0
  101. package/dist/collection_editor/ui/collection_editor/templates/users_template.d.ts +2 -0
  102. package/dist/collection_editor/ui/collection_editor/util.d.ts +5 -0
  103. package/dist/collection_editor/ui/collection_editor/utils/strings.d.ts +1 -0
  104. package/dist/collection_editor/ui/collection_editor/utils/supported_fields.d.ts +3 -0
  105. package/dist/collection_editor/ui/collection_editor/utils/update_property_for_widget.d.ts +2 -0
  106. package/dist/collection_editor/useCollectionEditorController.d.ts +6 -0
  107. package/dist/collection_editor/useCollectionsConfigController.d.ts +6 -0
  108. package/dist/collection_editor/useLocalCollectionsConfigController.d.ts +6 -0
  109. package/dist/collection_editor/validateCollectionJson.d.ts +22 -0
  110. package/dist/collection_editor_ui.d.ts +8 -0
  111. package/dist/collection_editor_ui.js +11 -0
  112. package/dist/collection_editor_ui.js.map +1 -0
  113. package/dist/components/AdminModeSyncer.d.ts +17 -0
  114. package/dist/components/ArrayContainer.d.ts +58 -0
  115. package/dist/components/ClearFilterSortButton.d.ts +5 -0
  116. package/dist/components/CollectionEditorDialogs.d.ts +15 -0
  117. package/dist/components/DefaultAppBar.d.ts +29 -0
  118. package/dist/components/DefaultDrawer.d.ts +29 -0
  119. package/dist/components/DeleteEntityDialog.d.ts +13 -0
  120. package/dist/components/DrawerNavigationGroup.d.ts +49 -0
  121. package/dist/components/DrawerNavigationItem.d.ts +10 -0
  122. package/dist/components/EntityCollectionTable/EntityCollectionRowActions.d.ts +39 -0
  123. package/dist/components/EntityCollectionTable/EntityCollectionTable.d.ts +27 -0
  124. package/dist/components/EntityCollectionTable/EntityCollectionTableProps.d.ts +129 -0
  125. package/dist/components/EntityCollectionTable/PropertyTableCell.d.ts +26 -0
  126. package/dist/components/EntityCollectionTable/column_utils.d.ts +16 -0
  127. package/dist/components/EntityCollectionTable/fields/TableMultipleRelationField.d.ts +21 -0
  128. package/dist/components/EntityCollectionTable/fields/TableReferenceField.d.ts +22 -0
  129. package/dist/components/EntityCollectionTable/fields/TableRelationField.d.ts +22 -0
  130. package/dist/components/EntityCollectionTable/fields/TableRelationSelectorField.d.ts +20 -0
  131. package/dist/components/EntityCollectionTable/fields/TableStorageUpload.d.ts +35 -0
  132. package/dist/components/EntityCollectionTable/fields/VirtualTableDateField.d.ts +12 -0
  133. package/dist/components/EntityCollectionTable/fields/VirtualTableInput.d.ts +9 -0
  134. package/dist/components/EntityCollectionTable/fields/VirtualTableNumberInput.d.ts +8 -0
  135. package/dist/components/EntityCollectionTable/fields/VirtualTableSelect.d.ts +15 -0
  136. package/dist/components/EntityCollectionTable/fields/VirtualTableSwitch.d.ts +7 -0
  137. package/dist/components/EntityCollectionTable/fields/VirtualTableUserSelect.d.ts +12 -0
  138. package/dist/components/EntityCollectionTable/index.d.ts +6 -0
  139. package/dist/components/EntityCollectionTable/internal/CollectionTableToolbar.d.ts +21 -0
  140. package/dist/components/EntityCollectionTable/internal/EntityTableCell.d.ts +32 -0
  141. package/dist/components/EntityCollectionTable/internal/EntityTableCellActions.d.ts +9 -0
  142. package/dist/components/EntityCollectionTable/internal/common.d.ts +5 -0
  143. package/dist/components/EntityCollectionTable/internal/popup_field/PopupFormField.d.ts +27 -0
  144. package/dist/components/EntityCollectionTable/internal/popup_field/useDraggable.d.ts +13 -0
  145. package/dist/components/EntityCollectionTable/internal/popup_field/useWindowSize.d.ts +6 -0
  146. package/dist/components/EntityCollectionTable/table_bindings.d.ts +28 -0
  147. package/dist/components/EntityCollectionView/Board.d.ts +2 -0
  148. package/dist/components/EntityCollectionView/BoardColumn.d.ts +42 -0
  149. package/dist/components/EntityCollectionView/BoardColumnTitle.d.ts +9 -0
  150. package/dist/components/EntityCollectionView/BoardSortableList.d.ts +14 -0
  151. package/dist/components/EntityCollectionView/EntityBoardCard.d.ts +31 -0
  152. package/dist/components/EntityCollectionView/EntityCard.d.ts +20 -0
  153. package/dist/components/EntityCollectionView/EntityCollectionBoardView.d.ts +22 -0
  154. package/dist/components/EntityCollectionView/EntityCollectionCardView.d.ts +32 -0
  155. package/dist/components/EntityCollectionView/EntityCollectionListView.d.ts +34 -0
  156. package/dist/components/EntityCollectionView/EntityCollectionView.d.ts +65 -0
  157. package/dist/components/EntityCollectionView/EntityCollectionViewActions.d.ts +19 -0
  158. package/dist/components/EntityCollectionView/EntityCollectionViewStartActions.d.ts +19 -0
  159. package/dist/components/EntityCollectionView/FiltersDialog.d.ts +15 -0
  160. package/dist/components/EntityCollectionView/SplitListView.d.ts +58 -0
  161. package/dist/components/EntityCollectionView/ViewModeToggle.d.ts +44 -0
  162. package/dist/components/EntityCollectionView/board_types.d.ts +105 -0
  163. package/dist/components/EntityCollectionView/hooks/useCollectionInlineEditor.d.ts +12 -0
  164. package/dist/components/EntityCollectionView/hooks/useKanbanDragAndDrop.d.ts +19 -0
  165. package/dist/components/EntityCollectionView/useBoardDataController.d.ts +61 -0
  166. package/dist/components/EntityCollectionView/useEntityPreviewSlots.d.ts +101 -0
  167. package/dist/components/EntityCollectionView/useSelectionController.d.ts +2 -0
  168. package/dist/components/EntityCollectionView/utils.d.ts +3 -0
  169. package/dist/components/EntityEditView.d.ts +50 -0
  170. package/dist/components/EntityEditViewFormActions.d.ts +2 -0
  171. package/dist/components/EntityJsonPreview.d.ts +3 -0
  172. package/dist/components/EntityPreview.d.ts +56 -0
  173. package/dist/components/EntitySidePanel.d.ts +10 -0
  174. package/dist/components/EntityView.d.ts +12 -0
  175. package/dist/components/FieldCaption.d.ts +5 -0
  176. package/dist/components/HomePage/ContentHomePage.d.ts +11 -0
  177. package/dist/components/HomePage/FavouritesView.d.ts +3 -0
  178. package/dist/components/HomePage/HomePageDnD.d.ts +77 -0
  179. package/dist/components/HomePage/NavigationCard.d.ts +11 -0
  180. package/dist/components/HomePage/NavigationCardBinding.d.ts +18 -0
  181. package/dist/components/HomePage/NavigationGroup.d.ts +11 -0
  182. package/dist/components/HomePage/RenameGroupDialog.d.ts +9 -0
  183. package/dist/components/HomePage/SmallNavigationCard.d.ts +6 -0
  184. package/dist/components/HomePage/index.d.ts +4 -0
  185. package/dist/components/PropertyCollectionView.d.ts +24 -0
  186. package/dist/components/PropertyConfigBadge.d.ts +6 -0
  187. package/dist/components/PropertyIdCopyTooltip.d.ts +8 -0
  188. package/dist/components/RebaseAuthGate.d.ts +21 -0
  189. package/dist/components/RebaseCMS.d.ts +10 -0
  190. package/dist/components/RebaseLayout.d.ts +32 -0
  191. package/dist/components/RebaseNavigation.d.ts +24 -0
  192. package/dist/components/RebaseRouteDefs.d.ts +30 -0
  193. package/dist/components/RebaseShell.d.ts +25 -0
  194. package/dist/components/ReferenceTable/EntitySelectionTable.d.ts +59 -0
  195. package/dist/components/ReferenceWidget.d.ts +30 -0
  196. package/dist/components/RelationSelector.d.ts +32 -0
  197. package/dist/components/SearchIconsView.d.ts +5 -0
  198. package/dist/components/SelectableTable/SelectableTable.d.ts +95 -0
  199. package/dist/components/SelectableTable/SelectableTableContext.d.ts +4 -0
  200. package/dist/components/SelectableTable/SelectionStore.d.ts +26 -0
  201. package/dist/components/SelectableTable/filters/BooleanFilterField.d.ts +9 -0
  202. package/dist/components/SelectableTable/filters/DateTimeFilterField.d.ts +12 -0
  203. package/dist/components/SelectableTable/filters/ReferenceFilterField.d.ts +15 -0
  204. package/dist/components/SelectableTable/filters/RelationFilterField.d.ts +12 -0
  205. package/dist/components/SelectableTable/filters/StringNumberFilterField.d.ts +13 -0
  206. package/dist/components/SideDialogs.d.ts +25 -0
  207. package/dist/components/SideEntityProvider.d.ts +32 -0
  208. package/dist/components/UserSelector.d.ts +18 -0
  209. package/dist/components/admin/RoleChip.d.ts +4 -0
  210. package/dist/components/admin/RolesView.d.ts +4 -0
  211. package/dist/components/admin/UsersView.d.ts +4 -0
  212. package/dist/components/admin/index.d.ts +3 -0
  213. package/dist/components/app/AppBar.d.ts +12 -0
  214. package/dist/components/app/Drawer.d.ts +19 -0
  215. package/dist/components/app/Scaffold.d.ts +34 -0
  216. package/dist/components/app/index.d.ts +4 -0
  217. package/dist/components/app/useApp.d.ts +17 -0
  218. package/dist/components/common/default_entity_actions.d.ts +4 -0
  219. package/dist/components/common/index.d.ts +1 -0
  220. package/dist/components/field_configs.d.ts +7 -0
  221. package/dist/components/history/EntityHistoryEntry.d.ts +17 -0
  222. package/dist/components/history/EntityHistoryView.d.ts +6 -0
  223. package/dist/components/history/LastEditedByFormAction.d.ts +6 -0
  224. package/dist/components/history/LastEditedByIndicator.d.ts +10 -0
  225. package/dist/components/history/UserChip.d.ts +4 -0
  226. package/dist/components/history/index.d.ts +5 -0
  227. package/dist/components/index.d.ts +38 -0
  228. package/dist/contexts/BreacrumbsContext.d.ts +8 -0
  229. package/dist/contexts/SideDialogsControllerContext.d.ts +3 -0
  230. package/dist/contexts/SideEntityControllerContext.d.ts +3 -0
  231. package/dist/data_export/export/BasicExportAction.d.ts +7 -0
  232. package/dist/data_export/export/ExportCollectionAction.d.ts +11 -0
  233. package/dist/data_export/export/export.d.ts +22 -0
  234. package/dist/data_export/export/index.d.ts +3 -0
  235. package/dist/data_export/index.d.ts +1 -0
  236. package/dist/data_import/components/DataNewPropertiesMapping.d.ts +13 -0
  237. package/dist/data_import/components/ImportFileUpload.d.ts +3 -0
  238. package/dist/data_import/components/ImportNewPropertyFieldPreview.d.ts +9 -0
  239. package/dist/data_import/components/ImportSaveInProgress.d.ts +8 -0
  240. package/dist/data_import/components/index.d.ts +4 -0
  241. package/dist/data_import/hooks/index.d.ts +1 -0
  242. package/dist/data_import/hooks/useImportConfig.d.ts +2 -0
  243. package/dist/data_import/import/ImportCollectionAction.d.ts +15 -0
  244. package/dist/data_import/import/index.d.ts +1 -0
  245. package/dist/data_import/index.d.ts +5 -0
  246. package/dist/data_import/types/column_mapping.d.ts +20 -0
  247. package/dist/data_import/types/index.d.ts +1 -0
  248. package/dist/data_import/utils/data.d.ts +4 -0
  249. package/dist/data_import/utils/file_headers.d.ts +1 -0
  250. package/dist/data_import/utils/file_to_json.d.ts +16 -0
  251. package/dist/data_import/utils/get_import_inference_type.d.ts +2 -0
  252. package/dist/data_import/utils/get_properties_mapping.d.ts +1 -0
  253. package/dist/data_import/utils/index.d.ts +3 -0
  254. package/dist/editor/components/SlashCommandMenu.d.ts +6 -0
  255. package/dist/editor/components/editor-bubble-item.d.ts +8 -0
  256. package/dist/editor/components/editor-bubble.d.ts +8 -0
  257. package/dist/editor/components/image-bubble.d.ts +5 -0
  258. package/dist/editor/components/index.d.ts +16 -0
  259. package/dist/editor/components/table-bubble.d.ts +5 -0
  260. package/dist/editor/editor.d.ts +30 -0
  261. package/dist/editor/extensions/HighlightDecorationExtension.d.ts +24 -0
  262. package/dist/editor/extensions/Image/index.d.ts +6 -0
  263. package/dist/editor/extensions/Image.d.ts +6 -0
  264. package/dist/editor/extensions/TextLoadingDecorationExtension.d.ts +16 -0
  265. package/dist/editor/extensions/clipboard.d.ts +7 -0
  266. package/dist/editor/extensions/custom-keymap.d.ts +1 -0
  267. package/dist/editor/extensions/drag-and-drop.d.ts +9 -0
  268. package/dist/editor/hooks/useProseMirror.d.ts +13 -0
  269. package/dist/editor/hooks/useProseMirrorContext.d.ts +9 -0
  270. package/dist/editor/index.d.ts +2 -0
  271. package/dist/editor/markdown.d.ts +5 -0
  272. package/dist/editor/nodeViews/ImageComponent.d.ts +3 -0
  273. package/dist/editor/nodeViews/ReactNodeView.d.ts +29 -0
  274. package/dist/editor/nodeViews/TaskItemComponent.d.ts +3 -0
  275. package/dist/editor/nodeViews/index.d.ts +6 -0
  276. package/dist/editor/plugins/index.d.ts +2 -0
  277. package/dist/editor/plugins/inputrules.d.ts +6 -0
  278. package/dist/editor/plugins/placeholderPlugin.d.ts +3 -0
  279. package/dist/editor/plugins/slashCommandPlugin.d.ts +12 -0
  280. package/dist/editor/schema.d.ts +2 -0
  281. package/dist/editor/selectors/ai-selector.d.ts +0 -0
  282. package/dist/editor/selectors/color-selector.d.ts +10 -0
  283. package/dist/editor/selectors/link-selector.d.ts +8 -0
  284. package/dist/editor/selectors/node-selector.d.ts +15 -0
  285. package/dist/editor/selectors/text-buttons.d.ts +1 -0
  286. package/dist/editor/types.d.ts +5 -0
  287. package/dist/editor/useProseMirror.d.ts +16 -0
  288. package/dist/editor/utils/prosemirror-utils.d.ts +7 -0
  289. package/dist/editor/utils/remove_classes.d.ts +1 -0
  290. package/dist/editor/utils/useDebouncedCallback.d.ts +1 -0
  291. package/dist/editor.js +3834 -0
  292. package/dist/editor.js.map +1 -0
  293. package/dist/form/EntityForm.d.ts +10 -0
  294. package/dist/form/EntityFormActions.d.ts +2 -0
  295. package/dist/form/PropertyFieldBinding.d.ts +30 -0
  296. package/dist/form/components/ErrorFocus.d.ts +4 -0
  297. package/dist/form/components/FieldHelperText.d.ts +12 -0
  298. package/dist/form/components/FormEntry.d.ts +6 -0
  299. package/dist/form/components/FormLayout.d.ts +5 -0
  300. package/dist/form/components/LabelWithIcon.d.ts +14 -0
  301. package/dist/form/components/LabelWithIconAndTooltip.d.ts +15 -0
  302. package/dist/form/components/LocalChangesMenu.d.ts +11 -0
  303. package/dist/form/components/StorageItemPreview.d.ts +14 -0
  304. package/dist/form/components/StorageUploadProgress.d.ts +10 -0
  305. package/dist/form/components/index.d.ts +5 -0
  306. package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.d.ts +10 -0
  307. package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.d.ts +13 -0
  308. package/dist/form/field_bindings/BlockFieldBinding.d.ts +11 -0
  309. package/dist/form/field_bindings/DateTimeFieldBinding.d.ts +12 -0
  310. package/dist/form/field_bindings/KeyValueFieldBinding.d.ts +8 -0
  311. package/dist/form/field_bindings/MapFieldBinding.d.ts +10 -0
  312. package/dist/form/field_bindings/MarkdownEditorFieldBinding.d.ts +12 -0
  313. package/dist/form/field_bindings/MultiSelectFieldBinding.d.ts +10 -0
  314. package/dist/form/field_bindings/MultipleRelationFieldBinding.d.ts +10 -0
  315. package/dist/form/field_bindings/ReadOnlyFieldBinding.d.ts +11 -0
  316. package/dist/form/field_bindings/ReferenceAsStringFieldBinding.d.ts +10 -0
  317. package/dist/form/field_bindings/ReferenceFieldBinding.d.ts +10 -0
  318. package/dist/form/field_bindings/RelationFieldBinding.d.ts +3 -0
  319. package/dist/form/field_bindings/RepeatFieldBinding.d.ts +11 -0
  320. package/dist/form/field_bindings/SelectFieldBinding.d.ts +11 -0
  321. package/dist/form/field_bindings/StorageUploadFieldBinding.d.ts +21 -0
  322. package/dist/form/field_bindings/SwitchFieldBinding.d.ts +10 -0
  323. package/dist/form/field_bindings/TextFieldBinding.d.ts +9 -0
  324. package/dist/form/field_bindings/UserSelectFieldBinding.d.ts +14 -0
  325. package/dist/form/index.d.ts +20 -0
  326. package/dist/form/useClearRestoreValue.d.ts +13 -0
  327. package/dist/form/validation.d.ts +21 -0
  328. package/dist/hooks/index.d.ts +15 -0
  329. package/dist/hooks/navigation/contexts/CollectionRegistryContext.d.ts +5 -0
  330. package/dist/hooks/navigation/contexts/NavigationStateContext.d.ts +4 -0
  331. package/dist/hooks/navigation/contexts/UrlContext.d.ts +4 -0
  332. package/dist/hooks/navigation/contexts/index.d.ts +3 -0
  333. package/dist/hooks/navigation/useBuildCollectionRegistryController.d.ts +7 -0
  334. package/dist/hooks/navigation/useBuildNavigationStateController.d.ts +34 -0
  335. package/dist/hooks/navigation/useBuildUrlController.d.ts +7 -0
  336. package/dist/hooks/navigation/useNavigationRegistry.d.ts +12 -0
  337. package/dist/hooks/navigation/useNavigationResolution.d.ts +7 -0
  338. package/dist/hooks/navigation/useNavigationURLs.d.ts +11 -0
  339. package/dist/hooks/navigation/useResolvedCollections.d.ts +28 -0
  340. package/dist/hooks/navigation/useResolvedViews.d.ts +29 -0
  341. package/dist/hooks/navigation/useTopLevelNavigation.d.ts +27 -0
  342. package/dist/hooks/navigation/utils.d.ts +12 -0
  343. package/dist/hooks/useBreadcrumbsController.d.ts +42 -0
  344. package/dist/hooks/useBuildSideDialogsController.d.ts +2 -0
  345. package/dist/hooks/useBuildSideEntityController.d.ts +6 -0
  346. package/dist/hooks/useCMSContext.d.ts +27 -0
  347. package/dist/hooks/useEntityHistory.d.ts +30 -0
  348. package/dist/hooks/useEntitySelectionDialog.d.ts +18 -0
  349. package/dist/hooks/useResolvedNavigationFrom.d.ts +73 -0
  350. package/dist/hooks/useSideDialogsController.d.ts +19 -0
  351. package/dist/hooks/useSideEntityController.d.ts +11 -0
  352. package/dist/index-C9YDsMC9.js +8 -0
  353. package/dist/index-C9YDsMC9.js.map +1 -0
  354. package/dist/index-CNDetux9.js +463 -0
  355. package/dist/index-CNDetux9.js.map +1 -0
  356. package/dist/index-DO7lMeNB.js +12 -0
  357. package/dist/index-DO7lMeNB.js.map +1 -0
  358. package/dist/index.d.ts +12 -0
  359. package/dist/index.js +811 -0
  360. package/dist/index.js.map +1 -0
  361. package/dist/markdown-z2Ir7Cgo.js +618 -0
  362. package/dist/markdown-z2Ir7Cgo.js.map +1 -0
  363. package/dist/preview/PropertyPreview.d.ts +7 -0
  364. package/dist/preview/components/ArrayEnumPreview.d.ts +11 -0
  365. package/dist/preview/components/BooleanPreview.d.ts +11 -0
  366. package/dist/preview/components/DatePreview.d.ts +17 -0
  367. package/dist/preview/components/EmptyValue.d.ts +6 -0
  368. package/dist/preview/components/EnumValuesChip.d.ts +13 -0
  369. package/dist/preview/components/ImagePreview.d.ts +16 -0
  370. package/dist/preview/components/ReferencePreview.d.ts +17 -0
  371. package/dist/preview/components/RelationPreview.d.ts +17 -0
  372. package/dist/preview/components/StorageThumbnail.d.ts +15 -0
  373. package/dist/preview/components/UrlComponentPreview.d.ts +14 -0
  374. package/dist/preview/components/UserPreview.d.ts +9 -0
  375. package/dist/preview/index.d.ts +23 -0
  376. package/dist/preview/property_previews/ArrayOfMapsPreview.d.ts +6 -0
  377. package/dist/preview/property_previews/ArrayOfReferencesPreview.d.ts +6 -0
  378. package/dist/preview/property_previews/ArrayOfRelationsPreview.d.ts +6 -0
  379. package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.d.ts +6 -0
  380. package/dist/preview/property_previews/ArrayOfStringsPreview.d.ts +6 -0
  381. package/dist/preview/property_previews/ArrayOneOfPreview.d.ts +6 -0
  382. package/dist/preview/property_previews/ArrayPropertyEnumPreview.d.ts +6 -0
  383. package/dist/preview/property_previews/ArrayPropertyPreview.d.ts +6 -0
  384. package/dist/preview/property_previews/MapPropertyPreview.d.ts +9 -0
  385. package/dist/preview/property_previews/NumberPropertyPreview.d.ts +7 -0
  386. package/dist/preview/property_previews/SkeletonPropertyComponent.d.ts +14 -0
  387. package/dist/preview/property_previews/StringPropertyPreview.d.ts +7 -0
  388. package/dist/preview/util.d.ts +7 -0
  389. package/dist/routes/CustomViewRoute.d.ts +4 -0
  390. package/dist/routes/RebaseRoute.d.ts +1 -0
  391. package/dist/routes/index.d.ts +2 -0
  392. package/dist/types/components/EntityFormActionsProps.d.ts +19 -0
  393. package/dist/types/components/EntityFormProps.d.ts +48 -0
  394. package/dist/types/components/PropertyPreviewProps.d.ts +47 -0
  395. package/dist/types/components/formex.d.ts +40 -0
  396. package/dist/types/components/index.d.ts +3 -0
  397. package/dist/types/fields.d.ts +221 -0
  398. package/dist/types/index.d.ts +2 -0
  399. package/dist/useEntityHistory-UVsSclfZ.js +123 -0
  400. package/dist/useEntityHistory-UVsSclfZ.js.map +1 -0
  401. package/dist/util/entity_actions.d.ts +2 -0
  402. package/dist/util/index.d.ts +5 -0
  403. package/dist/util/navigation_utils.d.ts +17 -0
  404. package/dist/util/previews.d.ts +4 -0
  405. package/dist/util/property_utils.d.ts +25 -0
  406. package/dist/util/resolutions.d.ts +9 -0
  407. package/dist/util-DK1O3uM0.js +28006 -0
  408. package/dist/util-DK1O3uM0.js.map +1 -0
  409. package/package.json +163 -0
  410. package/src/collection_editor/CollectionEditorDialogsContext.tsx +25 -0
  411. package/src/collection_editor/ConfigControllerProvider.tsx +407 -0
  412. package/src/collection_editor/_cms_internals.ts +41 -0
  413. package/src/collection_editor/api/generateCollectionApi.ts +125 -0
  414. package/src/collection_editor/api/index.ts +1 -0
  415. package/src/collection_editor/index.ts +63 -0
  416. package/src/collection_editor/pgColumnToProperty.ts +273 -0
  417. package/src/collection_editor/types/collection_editor_controller.tsx +64 -0
  418. package/src/collection_editor/types/collection_inference.ts +17 -0
  419. package/src/collection_editor/types/config_controller.tsx +109 -0
  420. package/src/collection_editor/types/config_permissions.ts +20 -0
  421. package/src/collection_editor/ui/AddKanbanColumnAction.tsx +186 -0
  422. package/src/collection_editor/ui/CollectionViewHeaderAction.tsx +50 -0
  423. package/src/collection_editor/ui/EditorCollectionAction.tsx +58 -0
  424. package/src/collection_editor/ui/EditorCollectionActionStart.tsx +93 -0
  425. package/src/collection_editor/ui/EditorEntityAction.tsx +54 -0
  426. package/src/collection_editor/ui/HomePageEditorCollectionAction.tsx +122 -0
  427. package/src/collection_editor/ui/KanbanSetupAction.tsx +41 -0
  428. package/src/collection_editor/ui/MissingReferenceWidget.tsx +34 -0
  429. package/src/collection_editor/ui/NewCollectionButton.tsx +28 -0
  430. package/src/collection_editor/ui/NewCollectionCard.tsx +54 -0
  431. package/src/collection_editor/ui/PropertyAddColumnComponent.tsx +53 -0
  432. package/src/collection_editor/ui/collection_editor/AICollectionGeneratorPopover.tsx +246 -0
  433. package/src/collection_editor/ui/collection_editor/AIModifiedPathsContext.tsx +90 -0
  434. package/src/collection_editor/ui/collection_editor/CollectionDetailsForm.tsx +416 -0
  435. package/src/collection_editor/ui/collection_editor/CollectionEditorDialog.tsx +977 -0
  436. package/src/collection_editor/ui/collection_editor/CollectionEditorWelcomeView.tsx +286 -0
  437. package/src/collection_editor/ui/collection_editor/CollectionJsonImportDialog.tsx +164 -0
  438. package/src/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.tsx +589 -0
  439. package/src/collection_editor/ui/collection_editor/CollectionRLSTab.tsx +347 -0
  440. package/src/collection_editor/ui/collection_editor/CollectionRelationsTab.tsx +242 -0
  441. package/src/collection_editor/ui/collection_editor/CollectionStudioView.tsx +102 -0
  442. package/src/collection_editor/ui/collection_editor/CollectionYupValidation.tsx +9 -0
  443. package/src/collection_editor/ui/collection_editor/CollectionsStudioView.tsx +139 -0
  444. package/src/collection_editor/ui/collection_editor/DisplaySettingsForm.tsx +301 -0
  445. package/src/collection_editor/ui/collection_editor/EntityActionsEditTab.tsx +151 -0
  446. package/src/collection_editor/ui/collection_editor/EntityActionsSelectDialog.tsx +40 -0
  447. package/src/collection_editor/ui/collection_editor/EntityCustomViewsSelectDialog.tsx +39 -0
  448. package/src/collection_editor/ui/collection_editor/EnumForm.tsx +358 -0
  449. package/src/collection_editor/ui/collection_editor/GeneralSettingsForm.tsx +252 -0
  450. package/src/collection_editor/ui/collection_editor/GetCodeDialog.tsx +142 -0
  451. package/src/collection_editor/ui/collection_editor/KanbanConfigSection.tsx +194 -0
  452. package/src/collection_editor/ui/collection_editor/LayoutModeSwitch.tsx +41 -0
  453. package/src/collection_editor/ui/collection_editor/PropertyEditView.tsx +777 -0
  454. package/src/collection_editor/ui/collection_editor/PropertyFieldPreview.tsx +155 -0
  455. package/src/collection_editor/ui/collection_editor/PropertyTree.tsx +350 -0
  456. package/src/collection_editor/ui/collection_editor/SubcollectionsEditTab.tsx +241 -0
  457. package/src/collection_editor/ui/collection_editor/SwitchControl.tsx +39 -0
  458. package/src/collection_editor/ui/collection_editor/ViewModeSwitch.tsx +47 -0
  459. package/src/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +67 -0
  460. package/src/collection_editor/ui/collection_editor/import/CollectionEditorImportMapping.tsx +295 -0
  461. package/src/collection_editor/ui/collection_editor/import/clean_import_data.ts +57 -0
  462. package/src/collection_editor/ui/collection_editor/properties/BlockPropertyField.tsx +147 -0
  463. package/src/collection_editor/ui/collection_editor/properties/BooleanPropertyField.tsx +41 -0
  464. package/src/collection_editor/ui/collection_editor/properties/CommonPropertyFields.tsx +113 -0
  465. package/src/collection_editor/ui/collection_editor/properties/DateTimePropertyField.tsx +250 -0
  466. package/src/collection_editor/ui/collection_editor/properties/EnumPropertyField.tsx +125 -0
  467. package/src/collection_editor/ui/collection_editor/properties/KeyValuePropertyField.tsx +20 -0
  468. package/src/collection_editor/ui/collection_editor/properties/MapPropertyField.tsx +153 -0
  469. package/src/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.tsx +210 -0
  470. package/src/collection_editor/ui/collection_editor/properties/NumberPropertyField.tsx +117 -0
  471. package/src/collection_editor/ui/collection_editor/properties/ReferencePropertyField.tsx +163 -0
  472. package/src/collection_editor/ui/collection_editor/properties/RelationPropertyField.tsx +346 -0
  473. package/src/collection_editor/ui/collection_editor/properties/RepeatPropertyField.tsx +106 -0
  474. package/src/collection_editor/ui/collection_editor/properties/StoragePropertyField.tsx +360 -0
  475. package/src/collection_editor/ui/collection_editor/properties/StringPropertyField.tsx +148 -0
  476. package/src/collection_editor/ui/collection_editor/properties/UrlPropertyField.tsx +90 -0
  477. package/src/collection_editor/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +47 -0
  478. package/src/collection_editor/ui/collection_editor/properties/conditions/ConditionsEditor.tsx +915 -0
  479. package/src/collection_editor/ui/collection_editor/properties/conditions/ConditionsPanel.tsx +29 -0
  480. package/src/collection_editor/ui/collection_editor/properties/conditions/EnumConditionsEditor.tsx +614 -0
  481. package/src/collection_editor/ui/collection_editor/properties/conditions/index.ts +6 -0
  482. package/src/collection_editor/ui/collection_editor/properties/conditions/property_paths.ts +93 -0
  483. package/src/collection_editor/ui/collection_editor/properties/validation/ArrayPropertyValidation.tsx +52 -0
  484. package/src/collection_editor/ui/collection_editor/properties/validation/GeneralPropertyValidation.tsx +63 -0
  485. package/src/collection_editor/ui/collection_editor/properties/validation/NumberPropertyValidation.tsx +117 -0
  486. package/src/collection_editor/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +154 -0
  487. package/src/collection_editor/ui/collection_editor/properties/validation/ValidationPanel.tsx +29 -0
  488. package/src/collection_editor/ui/collection_editor/templates/blog_template.ts +112 -0
  489. package/src/collection_editor/ui/collection_editor/templates/pages_template.ts +183 -0
  490. package/src/collection_editor/ui/collection_editor/templates/products_template.ts +88 -0
  491. package/src/collection_editor/ui/collection_editor/templates/users_template.ts +42 -0
  492. package/src/collection_editor/ui/collection_editor/util.ts +28 -0
  493. package/src/collection_editor/ui/collection_editor/utils/strings.ts +1 -0
  494. package/src/collection_editor/ui/collection_editor/utils/supported_fields.tsx +34 -0
  495. package/src/collection_editor/ui/collection_editor/utils/update_property_for_widget.ts +281 -0
  496. package/src/collection_editor/useCollectionEditorController.tsx +9 -0
  497. package/src/collection_editor/useCollectionsConfigController.tsx +9 -0
  498. package/src/collection_editor/useLocalCollectionsConfigController.tsx +120 -0
  499. package/src/collection_editor/validateCollectionJson.ts +379 -0
  500. package/src/collection_editor_ui.ts +15 -0
  501. package/src/components/AdminModeSyncer.tsx +56 -0
  502. package/src/components/ArrayContainer.tsx +538 -0
  503. package/src/components/ClearFilterSortButton.tsx +48 -0
  504. package/src/components/CollectionEditorDialogs.tsx +68 -0
  505. package/src/components/DefaultAppBar.tsx +242 -0
  506. package/src/components/DefaultDrawer.tsx +347 -0
  507. package/src/components/DeleteEntityDialog.tsx +182 -0
  508. package/src/components/DrawerNavigationGroup.tsx +130 -0
  509. package/src/components/DrawerNavigationItem.tsx +65 -0
  510. package/src/components/EntityCollectionTable/EntityCollectionRowActions.tsx +233 -0
  511. package/src/components/EntityCollectionTable/EntityCollectionTable.tsx +385 -0
  512. package/src/components/EntityCollectionTable/EntityCollectionTableProps.tsx +171 -0
  513. package/src/components/EntityCollectionTable/PropertyTableCell.tsx +340 -0
  514. package/src/components/EntityCollectionTable/column_utils.tsx +75 -0
  515. package/src/components/EntityCollectionTable/fields/TableMultipleRelationField.tsx +130 -0
  516. package/src/components/EntityCollectionTable/fields/TableReferenceField.tsx +172 -0
  517. package/src/components/EntityCollectionTable/fields/TableRelationField.tsx +181 -0
  518. package/src/components/EntityCollectionTable/fields/TableRelationSelectorField.tsx +42 -0
  519. package/src/components/EntityCollectionTable/fields/TableStorageUpload.tsx +322 -0
  520. package/src/components/EntityCollectionTable/fields/VirtualTableDateField.tsx +39 -0
  521. package/src/components/EntityCollectionTable/fields/VirtualTableInput.tsx +90 -0
  522. package/src/components/EntityCollectionTable/fields/VirtualTableNumberInput.tsx +80 -0
  523. package/src/components/EntityCollectionTable/fields/VirtualTableSelect.tsx +133 -0
  524. package/src/components/EntityCollectionTable/fields/VirtualTableSwitch.tsx +32 -0
  525. package/src/components/EntityCollectionTable/fields/VirtualTableUserSelect.tsx +41 -0
  526. package/src/components/EntityCollectionTable/index.tsx +14 -0
  527. package/src/components/EntityCollectionTable/internal/CollectionTableToolbar.tsx +102 -0
  528. package/src/components/EntityCollectionTable/internal/EntityTableCell.tsx +310 -0
  529. package/src/components/EntityCollectionTable/internal/EntityTableCellActions.tsx +81 -0
  530. package/src/components/EntityCollectionTable/internal/common.tsx +73 -0
  531. package/src/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +418 -0
  532. package/src/components/EntityCollectionTable/internal/popup_field/useDraggable.tsx +96 -0
  533. package/src/components/EntityCollectionTable/internal/popup_field/useWindowSize.tsx +22 -0
  534. package/src/components/EntityCollectionTable/table_bindings.tsx +346 -0
  535. package/src/components/EntityCollectionView/Board.tsx +474 -0
  536. package/src/components/EntityCollectionView/BoardColumn.tsx +158 -0
  537. package/src/components/EntityCollectionView/BoardColumnTitle.tsx +45 -0
  538. package/src/components/EntityCollectionView/BoardSortableList.tsx +177 -0
  539. package/src/components/EntityCollectionView/EntityBoardCard.tsx +263 -0
  540. package/src/components/EntityCollectionView/EntityCard.tsx +224 -0
  541. package/src/components/EntityCollectionView/EntityCollectionBoardView.tsx +642 -0
  542. package/src/components/EntityCollectionView/EntityCollectionCardView.tsx +267 -0
  543. package/src/components/EntityCollectionView/EntityCollectionListView.tsx +918 -0
  544. package/src/components/EntityCollectionView/EntityCollectionView.tsx +1328 -0
  545. package/src/components/EntityCollectionView/EntityCollectionViewActions.tsx +180 -0
  546. package/src/components/EntityCollectionView/EntityCollectionViewStartActions.tsx +153 -0
  547. package/src/components/EntityCollectionView/FiltersDialog.tsx +242 -0
  548. package/src/components/EntityCollectionView/SplitListView.tsx +330 -0
  549. package/src/components/EntityCollectionView/ViewModeToggle.tsx +199 -0
  550. package/src/components/EntityCollectionView/board_types.ts +113 -0
  551. package/src/components/EntityCollectionView/hooks/useCollectionInlineEditor.ts +79 -0
  552. package/src/components/EntityCollectionView/hooks/useKanbanDragAndDrop.ts +140 -0
  553. package/src/components/EntityCollectionView/useBoardDataController.tsx +675 -0
  554. package/src/components/EntityCollectionView/useEntityPreviewSlots.ts +442 -0
  555. package/src/components/EntityCollectionView/useSelectionController.tsx +39 -0
  556. package/src/components/EntityCollectionView/utils.ts +19 -0
  557. package/src/components/EntityEditView.tsx +633 -0
  558. package/src/components/EntityEditViewFormActions.tsx +352 -0
  559. package/src/components/EntityJsonPreview.tsx +66 -0
  560. package/src/components/EntityPreview.tsx +372 -0
  561. package/src/components/EntitySidePanel.tsx +164 -0
  562. package/src/components/EntityView.tsx +69 -0
  563. package/src/components/FieldCaption.tsx +14 -0
  564. package/src/components/HomePage/ContentHomePage.tsx +567 -0
  565. package/src/components/HomePage/FavouritesView.tsx +61 -0
  566. package/src/components/HomePage/HomePageDnD.tsx +703 -0
  567. package/src/components/HomePage/NavigationCard.tsx +88 -0
  568. package/src/components/HomePage/NavigationCardBinding.tsx +108 -0
  569. package/src/components/HomePage/NavigationGroup.tsx +157 -0
  570. package/src/components/HomePage/RenameGroupDialog.tsx +123 -0
  571. package/src/components/HomePage/SmallNavigationCard.tsx +46 -0
  572. package/src/components/HomePage/index.tsx +5 -0
  573. package/src/components/PropertyCollectionView.tsx +335 -0
  574. package/src/components/PropertyConfigBadge.tsx +27 -0
  575. package/src/components/PropertyIdCopyTooltip.tsx +48 -0
  576. package/src/components/RebaseAuthGate.tsx +42 -0
  577. package/src/components/RebaseCMS.tsx +27 -0
  578. package/src/components/RebaseLayout.tsx +73 -0
  579. package/src/components/RebaseNavigation.tsx +230 -0
  580. package/src/components/RebaseRouteDefs.tsx +130 -0
  581. package/src/components/RebaseShell.tsx +70 -0
  582. package/src/components/ReferenceTable/EntitySelectionTable.tsx +363 -0
  583. package/src/components/ReferenceWidget.tsx +155 -0
  584. package/src/components/RelationSelector.tsx +672 -0
  585. package/src/components/SearchIconsView.tsx +96 -0
  586. package/src/components/SelectableTable/SelectableTable.tsx +356 -0
  587. package/src/components/SelectableTable/SelectableTableContext.tsx +6 -0
  588. package/src/components/SelectableTable/SelectionStore.ts +67 -0
  589. package/src/components/SelectableTable/filters/BooleanFilterField.tsx +51 -0
  590. package/src/components/SelectableTable/filters/DateTimeFilterField.tsx +125 -0
  591. package/src/components/SelectableTable/filters/ReferenceFilterField.tsx +208 -0
  592. package/src/components/SelectableTable/filters/RelationFilterField.tsx +138 -0
  593. package/src/components/SelectableTable/filters/StringNumberFilterField.tsx +221 -0
  594. package/src/components/SideDialogs.tsx +208 -0
  595. package/src/components/SideEntityProvider.tsx +76 -0
  596. package/src/components/UserSelector.tsx +339 -0
  597. package/src/components/admin/RoleChip.tsx +23 -0
  598. package/src/components/admin/RolesView.tsx +426 -0
  599. package/src/components/admin/UsersView.tsx +785 -0
  600. package/src/components/admin/index.ts +3 -0
  601. package/src/components/app/AppBar.tsx +17 -0
  602. package/src/components/app/Drawer.tsx +30 -0
  603. package/src/components/app/Scaffold.tsx +242 -0
  604. package/src/components/app/index.ts +4 -0
  605. package/src/components/app/useApp.tsx +36 -0
  606. package/src/components/common/default_entity_actions.tsx +156 -0
  607. package/src/components/common/index.ts +1 -0
  608. package/src/components/field_configs.tsx +420 -0
  609. package/src/components/history/EntityHistoryEntry.tsx +182 -0
  610. package/src/components/history/EntityHistoryView.tsx +202 -0
  611. package/src/components/history/LastEditedByFormAction.tsx +24 -0
  612. package/src/components/history/LastEditedByIndicator.tsx +98 -0
  613. package/src/components/history/UserChip.tsx +15 -0
  614. package/src/components/history/index.tsx +5 -0
  615. package/src/components/index.ts +55 -0
  616. package/src/contexts/BreacrumbsContext.tsx +53 -0
  617. package/src/contexts/SideDialogsControllerContext.tsx +5 -0
  618. package/src/contexts/SideEntityControllerContext.tsx +5 -0
  619. package/src/data_export/export/BasicExportAction.tsx +143 -0
  620. package/src/data_export/export/ExportCollectionAction.tsx +266 -0
  621. package/src/data_export/export/export.ts +248 -0
  622. package/src/data_export/export/index.ts +3 -0
  623. package/src/data_export/index.ts +1 -0
  624. package/src/data_import/components/DataNewPropertiesMapping.tsx +231 -0
  625. package/src/data_import/components/ImportFileUpload.tsx +43 -0
  626. package/src/data_import/components/ImportNewPropertyFieldPreview.tsx +60 -0
  627. package/src/data_import/components/ImportSaveInProgress.tsx +121 -0
  628. package/src/data_import/components/index.ts +4 -0
  629. package/src/data_import/hooks/index.ts +1 -0
  630. package/src/data_import/hooks/useImportConfig.tsx +34 -0
  631. package/src/data_import/import/ImportCollectionAction.tsx +436 -0
  632. package/src/data_import/import/index.ts +1 -0
  633. package/src/data_import/index.ts +5 -0
  634. package/src/data_import/types/column_mapping.ts +32 -0
  635. package/src/data_import/types/index.ts +1 -0
  636. package/src/data_import/utils/data.ts +148 -0
  637. package/src/data_import/utils/file_headers.ts +90 -0
  638. package/src/data_import/utils/file_to_json.ts +106 -0
  639. package/src/data_import/utils/get_import_inference_type.ts +27 -0
  640. package/src/data_import/utils/get_properties_mapping.ts +67 -0
  641. package/src/data_import/utils/index.ts +3 -0
  642. package/src/editor/components/SlashCommandMenu.tsx +517 -0
  643. package/src/editor/components/editor-bubble-item.tsx +32 -0
  644. package/src/editor/components/editor-bubble.tsx +120 -0
  645. package/src/editor/components/image-bubble.tsx +165 -0
  646. package/src/editor/components/index.ts +14 -0
  647. package/src/editor/components/table-bubble.tsx +171 -0
  648. package/src/editor/editor.tsx +510 -0
  649. package/src/editor/extensions/HighlightDecorationExtension.ts +114 -0
  650. package/src/editor/extensions/Image/index.ts +133 -0
  651. package/src/editor/extensions/Image.ts +159 -0
  652. package/src/editor/extensions/TextLoadingDecorationExtension.tsx +107 -0
  653. package/src/editor/extensions/clipboard.ts +72 -0
  654. package/src/editor/extensions/custom-keymap.ts +25 -0
  655. package/src/editor/extensions/drag-and-drop.tsx +508 -0
  656. package/src/editor/hooks/useProseMirror.ts +126 -0
  657. package/src/editor/hooks/useProseMirrorContext.ts +15 -0
  658. package/src/editor/index.ts +2 -0
  659. package/src/editor/markdown.ts +205 -0
  660. package/src/editor/nodeViews/ImageComponent.tsx +20 -0
  661. package/src/editor/nodeViews/ReactNodeView.tsx +89 -0
  662. package/src/editor/nodeViews/TaskItemComponent.tsx +29 -0
  663. package/src/editor/nodeViews/index.ts +35 -0
  664. package/src/editor/plugins/index.ts +58 -0
  665. package/src/editor/plugins/inputrules.ts +82 -0
  666. package/src/editor/plugins/placeholderPlugin.ts +55 -0
  667. package/src/editor/plugins/slashCommandPlugin.ts +65 -0
  668. package/src/editor/schema.ts +263 -0
  669. package/src/editor/selectors/ai-selector.tsx +111 -0
  670. package/src/editor/selectors/color-selector.tsx +200 -0
  671. package/src/editor/selectors/link-selector.tsx +119 -0
  672. package/src/editor/selectors/node-selector.tsx +145 -0
  673. package/src/editor/selectors/text-buttons.tsx +80 -0
  674. package/src/editor/types.ts +6 -0
  675. package/src/editor/useProseMirror.ts +125 -0
  676. package/src/editor/utils/prosemirror-utils.ts +113 -0
  677. package/src/editor/utils/remove_classes.ts +17 -0
  678. package/src/editor/utils/useDebouncedCallback.ts +25 -0
  679. package/src/form/EntityForm.tsx +856 -0
  680. package/src/form/EntityFormActions.tsx +214 -0
  681. package/src/form/PropertyFieldBinding.tsx +344 -0
  682. package/src/form/components/ErrorFocus.tsx +44 -0
  683. package/src/form/components/FieldHelperText.tsx +85 -0
  684. package/src/form/components/FormEntry.tsx +22 -0
  685. package/src/form/components/FormLayout.tsx +16 -0
  686. package/src/form/components/LabelWithIcon.tsx +43 -0
  687. package/src/form/components/LabelWithIconAndTooltip.tsx +28 -0
  688. package/src/form/components/LocalChangesMenu.tsx +132 -0
  689. package/src/form/components/StorageItemPreview.tsx +82 -0
  690. package/src/form/components/StorageUploadProgress.tsx +105 -0
  691. package/src/form/components/index.tsx +5 -0
  692. package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +107 -0
  693. package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +171 -0
  694. package/src/form/field_bindings/BlockFieldBinding.tsx +280 -0
  695. package/src/form/field_bindings/DateTimeFieldBinding.tsx +72 -0
  696. package/src/form/field_bindings/KeyValueFieldBinding.tsx +554 -0
  697. package/src/form/field_bindings/MapFieldBinding.tsx +162 -0
  698. package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +232 -0
  699. package/src/form/field_bindings/MultiSelectFieldBinding.tsx +123 -0
  700. package/src/form/field_bindings/MultipleRelationFieldBinding.tsx +157 -0
  701. package/src/form/field_bindings/ReadOnlyFieldBinding.tsx +66 -0
  702. package/src/form/field_bindings/ReferenceAsStringFieldBinding.tsx +141 -0
  703. package/src/form/field_bindings/ReferenceFieldBinding.tsx +141 -0
  704. package/src/form/field_bindings/RelationFieldBinding.tsx +184 -0
  705. package/src/form/field_bindings/RepeatFieldBinding.tsx +139 -0
  706. package/src/form/field_bindings/SelectFieldBinding.tsx +110 -0
  707. package/src/form/field_bindings/StorageUploadFieldBinding.tsx +493 -0
  708. package/src/form/field_bindings/SwitchFieldBinding.tsx +65 -0
  709. package/src/form/field_bindings/TextFieldBinding.tsx +156 -0
  710. package/src/form/field_bindings/UserSelectFieldBinding.tsx +66 -0
  711. package/src/form/index.tsx +27 -0
  712. package/src/form/useClearRestoreValue.tsx +36 -0
  713. package/src/form/validation.ts +519 -0
  714. package/src/hooks/index.ts +15 -0
  715. package/src/hooks/navigation/contexts/CollectionRegistryContext.tsx +21 -0
  716. package/src/hooks/navigation/contexts/NavigationStateContext.tsx +16 -0
  717. package/src/hooks/navigation/contexts/UrlContext.tsx +25 -0
  718. package/src/hooks/navigation/contexts/index.ts +14 -0
  719. package/src/hooks/navigation/useBuildCollectionRegistryController.tsx +183 -0
  720. package/src/hooks/navigation/useBuildNavigationStateController.tsx +133 -0
  721. package/src/hooks/navigation/useBuildUrlController.tsx +66 -0
  722. package/src/hooks/navigation/useNavigationRegistry.ts +164 -0
  723. package/src/hooks/navigation/useNavigationResolution.ts +91 -0
  724. package/src/hooks/navigation/useNavigationURLs.ts +56 -0
  725. package/src/hooks/navigation/useResolvedCollections.ts +133 -0
  726. package/src/hooks/navigation/useResolvedViews.tsx +216 -0
  727. package/src/hooks/navigation/useTopLevelNavigation.ts +257 -0
  728. package/src/hooks/navigation/utils.ts +176 -0
  729. package/src/hooks/useBreadcrumbsController.tsx +49 -0
  730. package/src/hooks/useBuildSideDialogsController.tsx +145 -0
  731. package/src/hooks/useBuildSideEntityController.tsx +310 -0
  732. package/src/hooks/useCMSContext.tsx +79 -0
  733. package/src/hooks/useEntityHistory.ts +172 -0
  734. package/src/hooks/useEntitySelectionDialog.tsx +57 -0
  735. package/src/hooks/useResolvedNavigationFrom.tsx +160 -0
  736. package/src/hooks/useSideDialogsController.tsx +25 -0
  737. package/src/hooks/useSideEntityController.tsx +13 -0
  738. package/src/index.ts +95 -0
  739. package/src/preview/PropertyPreview.tsx +292 -0
  740. package/src/preview/components/ArrayEnumPreview.tsx +39 -0
  741. package/src/preview/components/BooleanPreview.tsx +25 -0
  742. package/src/preview/components/DatePreview.tsx +93 -0
  743. package/src/preview/components/EmptyValue.tsx +10 -0
  744. package/src/preview/components/EnumValuesChip.tsx +39 -0
  745. package/src/preview/components/ImagePreview.tsx +143 -0
  746. package/src/preview/components/ReferencePreview.tsx +166 -0
  747. package/src/preview/components/RelationPreview.tsx +160 -0
  748. package/src/preview/components/StorageThumbnail.tsx +93 -0
  749. package/src/preview/components/UrlComponentPreview.tsx +115 -0
  750. package/src/preview/components/UserPreview.tsx +30 -0
  751. package/src/preview/index.ts +25 -0
  752. package/src/preview/property_previews/ArrayOfMapsPreview.tsx +73 -0
  753. package/src/preview/property_previews/ArrayOfReferencesPreview.tsx +44 -0
  754. package/src/preview/property_previews/ArrayOfRelationsPreview.tsx +50 -0
  755. package/src/preview/property_previews/ArrayOfStorageComponentsPreview.tsx +49 -0
  756. package/src/preview/property_previews/ArrayOfStringsPreview.tsx +44 -0
  757. package/src/preview/property_previews/ArrayOneOfPreview.tsx +72 -0
  758. package/src/preview/property_previews/ArrayPropertyEnumPreview.tsx +35 -0
  759. package/src/preview/property_previews/ArrayPropertyPreview.tsx +70 -0
  760. package/src/preview/property_previews/MapPropertyPreview.tsx +146 -0
  761. package/src/preview/property_previews/NumberPropertyPreview.tsx +29 -0
  762. package/src/preview/property_previews/SkeletonPropertyComponent.tsx +277 -0
  763. package/src/preview/property_previews/StringPropertyPreview.tsx +59 -0
  764. package/src/preview/util.ts +30 -0
  765. package/src/routes/CustomViewRoute.tsx +24 -0
  766. package/src/routes/RebaseRoute.tsx +365 -0
  767. package/src/routes/index.ts +2 -0
  768. package/src/types/components/EntityFormActionsProps.tsx +20 -0
  769. package/src/types/components/EntityFormProps.tsx +54 -0
  770. package/src/types/components/PropertyPreviewProps.tsx +59 -0
  771. package/src/types/components/formex.tsx +46 -0
  772. package/src/types/components/index.ts +3 -0
  773. package/src/types/fields.tsx +299 -0
  774. package/src/types/index.ts +4 -0
  775. package/src/util/entity_actions.ts +28 -0
  776. package/src/util/index.ts +5 -0
  777. package/src/util/navigation_utils.ts +74 -0
  778. package/src/util/previews.ts +50 -0
  779. package/src/util/property_utils.tsx +215 -0
  780. package/src/util/resolutions.ts +71 -0
@@ -0,0 +1,4731 @@
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { c } from "react-compiler-runtime";
3
+ import { useAuthController, useCustomizationController, IconForView, useSnackbarController, useLargeLayout, AIIcon, useRebaseContext, ErrorView, ConfirmationDialog, useUnsavedChangesDialog, UnsavedChangesDialog } from "@rebasepro/core";
4
+ import { bk as useCollectionsConfigController, a3 as FieldCaption, ar as SearchIconsView, d as getFieldConfig, P as PropertyConfigBadge, aX as getFullId, b0 as idToPropertiesPath, b4 as namespaceToPropertiesOrderPath, br as validateCollectionJson, e as useCollectionRegistryController, K as CollectionGenerationApiError, s as useCollectionEditorController, I as ImportFileUpload, a as getInferenceType, a8 as ImportNewPropertyFieldPreview, D as DataNewPropertiesMapping, aW as getFieldId, f as useSelectionController, h as convertDataToEntity, E as EntityCollectionTable, m as useNavigationStateController, u as useImportConfig, j as useUrlController, b as ImportSaveInProgress, aY as getFullIdPath } from "./util-DK1O3uM0.js";
5
+ import * as React from "react";
6
+ import React__default, { useState, useRef, useMemo, useEffect } from "react";
7
+ import { Chip, Typography, cls, Tooltip, IconButton, TextField, DebouncedTextField, Dialog, Container, ToggleButtonGroup, Select, SelectItem, iconSize, Button, BooleanSwitchWithLabel, DialogTitle, DialogContent, DialogActions, CircularProgress, ErrorBoundary, defaultBorderMixin, Table, TableHeader, TableCell, TableBody, TableRow, Menu, Card, CircularProgressCenter, Paper, MultiSelect, MultiSelectItem, coolIconKeys, Tabs, Tab, LoadingButton } from "@rebasepro/ui";
8
+ import { ColumnsIcon, SquareIcon, PanelLeftIcon, ListIcon, TableIcon, LayoutGridIcon, KanbanIcon, XIcon, CopyIcon, FileSearchIcon, PlusIcon, Trash2Icon, CodeIcon, ShoppingCartIcon, UserIcon, FileTextIcon, FileIcon, KeyIcon, ArrowLeftIcon, CheckIcon } from "lucide-react";
9
+ import { isPropertyBuilder, getSubcollections, getTableName, removeInitialAndTrailingSlashes } from "@rebasepro/common";
10
+ import "fast-equals";
11
+ import { useFormex, getIn, Field, clone, useCreateFormex, Formex } from "@rebasepro/formex";
12
+ import { z } from "zod";
13
+ import { toSnakeCase, singular, unslugify, camelCase, isEmptyObject, prettifyIdentifier, slugify, randomString, removeUndefined, mergeDeep } from "@rebasepro/utils";
14
+ import "react-dropzone";
15
+ import "@dnd-kit/core";
16
+ import "@dnd-kit/sortable";
17
+ import "@dnd-kit/utilities";
18
+ import { getDataSourceCapabilities } from "@rebasepro/types";
19
+ import "@dnd-kit/modifiers";
20
+ import "react-router";
21
+ import "react-router-dom";
22
+ import "xlsx";
23
+ import { buildPropertyFromData, buildEntityPropertiesFromData } from "@rebasepro/schema-inference";
24
+ import "date-fns";
25
+ import "date-fns/locale";
26
+ import { a as PropertyFormDialog, u as useAIModifiedPaths, b as PropertyTree, P as PropertyForm, s as supportedFields, c as updatePropertyFromWidget, A as AIModifiedPathsProvider } from "./PropertyEditView-UtDO8g0A.js";
27
+ import JSON5 from "json5";
28
+ import { Highlight, themes } from "prism-react-renderer";
29
+ const CollectionEditorSchema = z.object({
30
+ slug: z.string().min(1, "Required"),
31
+ name: z.string().min(1, "Required"),
32
+ table: z.string().min(1, "Required")
33
+ });
34
+ function GeneralSettingsForm(t0) {
35
+ const $ = c(111);
36
+ const {
37
+ isNewCollection,
38
+ parentCollection
39
+ } = t0;
40
+ const {
41
+ values,
42
+ setFieldValue,
43
+ handleChange,
44
+ touched,
45
+ errors,
46
+ setFieldTouched,
47
+ submitCount
48
+ } = useFormex();
49
+ const [iconDialogOpen, setIconDialogOpen] = useState(false);
50
+ useAuthController();
51
+ useCustomizationController();
52
+ const configController = useCollectionsConfigController();
53
+ let t1;
54
+ if ($[0] !== setFieldValue) {
55
+ t1 = (databaseId) => {
56
+ setFieldValue("databaseId", databaseId ?? void 0);
57
+ };
58
+ $[0] = setFieldValue;
59
+ $[1] = t1;
60
+ } else {
61
+ t1 = $[1];
62
+ }
63
+ const updateDatabaseId = t1;
64
+ let t2;
65
+ if ($[2] !== isNewCollection || $[3] !== setFieldValue || $[4] !== touched) {
66
+ t2 = (name) => {
67
+ setFieldValue("name", name);
68
+ const pathTouched = getIn(touched, "table");
69
+ if (!pathTouched && isNewCollection && name) {
70
+ setFieldValue("table", toSnakeCase(name));
71
+ }
72
+ const idTouched = getIn(touched, "slug");
73
+ if (!idTouched && isNewCollection && name) {
74
+ setFieldValue("slug", toSnakeCase(name));
75
+ }
76
+ const singularNameTouched = getIn(touched, "singularName");
77
+ if (!singularNameTouched && isNewCollection && name) {
78
+ setFieldValue("singularName", singular(name));
79
+ }
80
+ };
81
+ $[2] = isNewCollection;
82
+ $[3] = setFieldValue;
83
+ $[4] = touched;
84
+ $[5] = t2;
85
+ } else {
86
+ t2 = $[5];
87
+ }
88
+ const updateName = t2;
89
+ let t3;
90
+ if ($[6] !== values) {
91
+ t3 = /* @__PURE__ */ jsx(IconForView, { collectionOrView: values });
92
+ $[6] = values;
93
+ $[7] = t3;
94
+ } else {
95
+ t3 = $[7];
96
+ }
97
+ const collectionIcon = t3;
98
+ const isSubcollection = !!parentCollection;
99
+ const showErrors = submitCount > 0;
100
+ const t4 = !isNewCollection ? "h5" : "h4";
101
+ const t5 = isNewCollection ? "New collection" : `${values?.name} collection`;
102
+ let t6;
103
+ if ($[8] !== t4 || $[9] !== t5) {
104
+ t6 = /* @__PURE__ */ jsx(Typography, { variant: t4, className: "flex-grow", children: t5 });
105
+ $[8] = t4;
106
+ $[9] = t5;
107
+ $[10] = t6;
108
+ } else {
109
+ t6 = $[10];
110
+ }
111
+ const t7 = configController?.readOnly;
112
+ let t8;
113
+ if ($[11] !== t7 || $[12] !== updateDatabaseId || $[13] !== values.databaseId) {
114
+ t8 = /* @__PURE__ */ jsx(DefaultDatabaseField, { databaseId: values.databaseId, disabled: t7, onDatabaseIdUpdate: updateDatabaseId });
115
+ $[11] = t7;
116
+ $[12] = updateDatabaseId;
117
+ $[13] = values.databaseId;
118
+ $[14] = t8;
119
+ } else {
120
+ t8 = $[14];
121
+ }
122
+ const t9 = configController?.readOnly;
123
+ let t10;
124
+ if ($[15] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
125
+ t10 = () => setIconDialogOpen(true);
126
+ $[15] = t10;
127
+ } else {
128
+ t10 = $[15];
129
+ }
130
+ let t11;
131
+ if ($[16] !== collectionIcon || $[17] !== t9) {
132
+ t11 = /* @__PURE__ */ jsx(Tooltip, { title: "Change icon", asChild: true, children: /* @__PURE__ */ jsx(IconButton, { shape: "square", disabled: t9, onClick: t10, children: collectionIcon }) });
133
+ $[16] = collectionIcon;
134
+ $[17] = t9;
135
+ $[18] = t11;
136
+ } else {
137
+ t11 = $[18];
138
+ }
139
+ let t12;
140
+ if ($[19] !== t11 || $[20] !== t6 || $[21] !== t8) {
141
+ t12 = /* @__PURE__ */ jsxs("div", { className: "flex flex-row gap-2 items-center", children: [
142
+ t6,
143
+ t8,
144
+ t11
145
+ ] });
146
+ $[19] = t11;
147
+ $[20] = t6;
148
+ $[21] = t8;
149
+ $[22] = t12;
150
+ } else {
151
+ t12 = $[22];
152
+ }
153
+ let t13;
154
+ if ($[23] !== parentCollection) {
155
+ t13 = parentCollection && /* @__PURE__ */ jsx(Chip, { colorScheme: "teal", children: /* @__PURE__ */ jsxs(Typography, { variant: "caption", children: [
156
+ "This is a subcollection of ",
157
+ /* @__PURE__ */ jsx("b", { children: parentCollection.name })
158
+ ] }) });
159
+ $[23] = parentCollection;
160
+ $[24] = t13;
161
+ } else {
162
+ t13 = $[24];
163
+ }
164
+ let t14;
165
+ if ($[25] !== t12 || $[26] !== t13) {
166
+ t14 = /* @__PURE__ */ jsxs("div", { children: [
167
+ t12,
168
+ t13
169
+ ] });
170
+ $[25] = t12;
171
+ $[26] = t13;
172
+ $[27] = t14;
173
+ } else {
174
+ t14 = $[27];
175
+ }
176
+ const t15 = configController?.readOnly;
177
+ const t16 = values.name ?? "";
178
+ let t17;
179
+ if ($[28] !== updateName) {
180
+ t17 = (e) => updateName(e.target.value);
181
+ $[28] = updateName;
182
+ $[29] = t17;
183
+ } else {
184
+ t17 = $[29];
185
+ }
186
+ const t18 = showErrors && Boolean(errors.name);
187
+ let t19;
188
+ if ($[30] !== t16 || $[31] !== t17 || $[32] !== t18) {
189
+ t19 = /* @__PURE__ */ jsx(TextField, { value: t16, onChange: t17, label: "Name", autoFocus: true, required: true, error: t18 });
190
+ $[30] = t16;
191
+ $[31] = t17;
192
+ $[32] = t18;
193
+ $[33] = t19;
194
+ } else {
195
+ t19 = $[33];
196
+ }
197
+ const t20 = touched.name && Boolean(errors.name);
198
+ const t21 = touched.name && Boolean(errors.name) ? errors.name : "Name of this collection, usually a plural name (e.g. Products)";
199
+ let t22;
200
+ if ($[34] !== t20 || $[35] !== t21) {
201
+ t22 = /* @__PURE__ */ jsx(FieldCaption, { error: t20, children: t21 });
202
+ $[34] = t20;
203
+ $[35] = t21;
204
+ $[36] = t22;
205
+ } else {
206
+ t22 = $[36];
207
+ }
208
+ let t23;
209
+ if ($[37] !== t19 || $[38] !== t22) {
210
+ t23 = /* @__PURE__ */ jsxs("div", { className: "col-span-12", children: [
211
+ t19,
212
+ t22
213
+ ] });
214
+ $[37] = t19;
215
+ $[38] = t22;
216
+ $[39] = t23;
217
+ } else {
218
+ t23 = $[39];
219
+ }
220
+ let t24;
221
+ if ($[40] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
222
+ t24 = cls("col-span-12");
223
+ $[40] = t24;
224
+ } else {
225
+ t24 = $[40];
226
+ }
227
+ const t25 = showErrors && Boolean(errors.table);
228
+ let t26;
229
+ if ($[41] !== t25) {
230
+ t26 = /* @__PURE__ */ jsx(Field, { name: "table", as: DebouncedTextField, label: "Table name", required: true, error: t25 });
231
+ $[41] = t25;
232
+ $[42] = t26;
233
+ } else {
234
+ t26 = $[42];
235
+ }
236
+ const t27 = touched.table && Boolean(errors.table);
237
+ const t28 = touched.table && Boolean(errors.table) ? errors.table : isSubcollection ? "Relative path to the parent (no need to include the parent path)" : "PostgreSQL table name for this collection";
238
+ let t29;
239
+ if ($[43] !== t27 || $[44] !== t28) {
240
+ t29 = /* @__PURE__ */ jsx(FieldCaption, { error: t27, children: t28 });
241
+ $[43] = t27;
242
+ $[44] = t28;
243
+ $[45] = t29;
244
+ } else {
245
+ t29 = $[45];
246
+ }
247
+ let t30;
248
+ if ($[46] !== t26 || $[47] !== t29) {
249
+ t30 = /* @__PURE__ */ jsxs("div", { className: t24, children: [
250
+ t26,
251
+ t29
252
+ ] });
253
+ $[46] = t26;
254
+ $[47] = t29;
255
+ $[48] = t30;
256
+ } else {
257
+ t30 = $[48];
258
+ }
259
+ const t31 = showErrors && Boolean(errors.singularName);
260
+ let t32;
261
+ if ($[49] !== handleChange || $[50] !== setFieldTouched) {
262
+ t32 = (e_0) => {
263
+ setFieldTouched("singularName", true);
264
+ return handleChange(e_0);
265
+ };
266
+ $[49] = handleChange;
267
+ $[50] = setFieldTouched;
268
+ $[51] = t32;
269
+ } else {
270
+ t32 = $[51];
271
+ }
272
+ const t33 = values.singularName ?? "";
273
+ let t34;
274
+ if ($[52] !== t31 || $[53] !== t32 || $[54] !== t33) {
275
+ t34 = /* @__PURE__ */ jsx(TextField, { error: t31, name: "singularName", "aria-describedby": "singularName-helper", onChange: t32, value: t33, label: "Singular name" });
276
+ $[52] = t31;
277
+ $[53] = t32;
278
+ $[54] = t33;
279
+ $[55] = t34;
280
+ } else {
281
+ t34 = $[55];
282
+ }
283
+ const t35 = showErrors && Boolean(errors.singularName);
284
+ const t36 = showErrors && Boolean(errors.singularName) ? errors.singularName : "Optionally define a singular name for your entities";
285
+ let t37;
286
+ if ($[56] !== t35 || $[57] !== t36) {
287
+ t37 = /* @__PURE__ */ jsx(FieldCaption, { error: t35, children: t36 });
288
+ $[56] = t35;
289
+ $[57] = t36;
290
+ $[58] = t37;
291
+ } else {
292
+ t37 = $[58];
293
+ }
294
+ let t38;
295
+ if ($[59] !== t34 || $[60] !== t37) {
296
+ t38 = /* @__PURE__ */ jsxs("div", { className: "col-span-12", children: [
297
+ t34,
298
+ t37
299
+ ] });
300
+ $[59] = t34;
301
+ $[60] = t37;
302
+ $[61] = t38;
303
+ } else {
304
+ t38 = $[61];
305
+ }
306
+ const t39 = showErrors && Boolean(errors.description);
307
+ const t40 = values.description ?? "";
308
+ let t41;
309
+ if ($[62] !== handleChange || $[63] !== t39 || $[64] !== t40) {
310
+ t41 = /* @__PURE__ */ jsx(TextField, { error: t39, name: "description", value: t40, onChange: handleChange, multiline: true, minRows: 2, "aria-describedby": "description-helper-text", label: "Description" });
311
+ $[62] = handleChange;
312
+ $[63] = t39;
313
+ $[64] = t40;
314
+ $[65] = t41;
315
+ } else {
316
+ t41 = $[65];
317
+ }
318
+ const t42 = showErrors && Boolean(errors.description);
319
+ const t43 = showErrors && Boolean(errors.description) ? errors.description : "Description of the collection, you can use markdown";
320
+ let t44;
321
+ if ($[66] !== t42 || $[67] !== t43) {
322
+ t44 = /* @__PURE__ */ jsx(FieldCaption, { error: t42, children: t43 });
323
+ $[66] = t42;
324
+ $[67] = t43;
325
+ $[68] = t44;
326
+ } else {
327
+ t44 = $[68];
328
+ }
329
+ let t45;
330
+ if ($[69] !== t41 || $[70] !== t44) {
331
+ t45 = /* @__PURE__ */ jsxs("div", { className: "col-span-12", children: [
332
+ t41,
333
+ t44
334
+ ] });
335
+ $[69] = t41;
336
+ $[70] = t44;
337
+ $[71] = t45;
338
+ } else {
339
+ t45 = $[71];
340
+ }
341
+ const t46 = values.slug ?? "";
342
+ let t47;
343
+ if ($[72] !== setFieldValue) {
344
+ t47 = (e_1) => setFieldValue("slug", e_1.target.value);
345
+ $[72] = setFieldValue;
346
+ $[73] = t47;
347
+ } else {
348
+ t47 = $[73];
349
+ }
350
+ const t48 = !isNewCollection;
351
+ const t49 = showErrors && Boolean(errors.slug);
352
+ let t50;
353
+ if ($[74] !== t46 || $[75] !== t47 || $[76] !== t48 || $[77] !== t49) {
354
+ t50 = /* @__PURE__ */ jsx(DebouncedTextField, { name: "slug", value: t46, onChange: t47, disabled: t48, label: "Collection ID", error: t49 });
355
+ $[74] = t46;
356
+ $[75] = t47;
357
+ $[76] = t48;
358
+ $[77] = t49;
359
+ $[78] = t50;
360
+ } else {
361
+ t50 = $[78];
362
+ }
363
+ const t51 = touched.slug && Boolean(errors.slug);
364
+ const t52 = touched.slug && Boolean(errors.slug) ? errors.slug : "This ID identifies this collection. Typically the same as the path.";
365
+ let t53;
366
+ if ($[79] !== t51 || $[80] !== t52) {
367
+ t53 = /* @__PURE__ */ jsx(FieldCaption, { error: t51, children: t52 });
368
+ $[79] = t51;
369
+ $[80] = t52;
370
+ $[81] = t53;
371
+ } else {
372
+ t53 = $[81];
373
+ }
374
+ let t54;
375
+ if ($[82] !== t50 || $[83] !== t53) {
376
+ t54 = /* @__PURE__ */ jsxs("div", { className: "col-span-12", children: [
377
+ t50,
378
+ t53
379
+ ] });
380
+ $[82] = t50;
381
+ $[83] = t53;
382
+ $[84] = t54;
383
+ } else {
384
+ t54 = $[84];
385
+ }
386
+ let t55;
387
+ if ($[85] !== t23 || $[86] !== t30 || $[87] !== t38 || $[88] !== t45 || $[89] !== t54) {
388
+ t55 = /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-12 gap-4", children: [
389
+ t23,
390
+ t30,
391
+ t38,
392
+ t45,
393
+ t54
394
+ ] });
395
+ $[85] = t23;
396
+ $[86] = t30;
397
+ $[87] = t38;
398
+ $[88] = t45;
399
+ $[89] = t54;
400
+ $[90] = t55;
401
+ } else {
402
+ t55 = $[90];
403
+ }
404
+ let t56;
405
+ if ($[91] !== setFieldValue || $[92] !== values.history) {
406
+ t56 = null;
407
+ $[91] = setFieldValue;
408
+ $[92] = values.history;
409
+ $[93] = t56;
410
+ } else {
411
+ t56 = $[93];
412
+ }
413
+ let t57;
414
+ if ($[94] !== t15 || $[95] !== t55 || $[96] !== t56) {
415
+ t57 = /* @__PURE__ */ jsxs("fieldset", { disabled: t15, className: "contents", children: [
416
+ t55,
417
+ t56
418
+ ] });
419
+ $[94] = t15;
420
+ $[95] = t55;
421
+ $[96] = t56;
422
+ $[97] = t57;
423
+ } else {
424
+ t57 = $[97];
425
+ }
426
+ let t58;
427
+ if ($[98] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
428
+ t58 = /* @__PURE__ */ jsx("div", { style: {
429
+ height: "52px"
430
+ } });
431
+ $[98] = t58;
432
+ } else {
433
+ t58 = $[98];
434
+ }
435
+ const t59 = typeof values.icon === "string" ? values.icon : void 0;
436
+ let t60;
437
+ if ($[99] !== setFieldValue) {
438
+ t60 = (icon) => {
439
+ setIconDialogOpen(false);
440
+ setFieldValue("icon", icon);
441
+ };
442
+ $[99] = setFieldValue;
443
+ $[100] = t60;
444
+ } else {
445
+ t60 = $[100];
446
+ }
447
+ let t61;
448
+ if ($[101] !== t59 || $[102] !== t60) {
449
+ t61 = /* @__PURE__ */ jsx("div", { className: "p-4 overflow-auto min-h-[200px]", children: /* @__PURE__ */ jsx(SearchIconsView, { selectedIcon: t59, onIconSelected: t60 }) });
450
+ $[101] = t59;
451
+ $[102] = t60;
452
+ $[103] = t61;
453
+ } else {
454
+ t61 = $[103];
455
+ }
456
+ let t62;
457
+ if ($[104] !== iconDialogOpen || $[105] !== t61) {
458
+ t62 = /* @__PURE__ */ jsx(Dialog, { open: iconDialogOpen, onOpenChange: setIconDialogOpen, maxWidth: "xl", fullWidth: true, children: t61 });
459
+ $[104] = iconDialogOpen;
460
+ $[105] = t61;
461
+ $[106] = t62;
462
+ } else {
463
+ t62 = $[106];
464
+ }
465
+ let t63;
466
+ if ($[107] !== t14 || $[108] !== t57 || $[109] !== t62) {
467
+ t63 = /* @__PURE__ */ jsx("div", { className: "overflow-auto my-auto", children: /* @__PURE__ */ jsxs(Container, { maxWidth: "4xl", className: "flex flex-col gap-4 p-8 m-auto", children: [
468
+ t14,
469
+ t57,
470
+ t58,
471
+ t62
472
+ ] }) });
473
+ $[107] = t14;
474
+ $[108] = t57;
475
+ $[109] = t62;
476
+ $[110] = t63;
477
+ } else {
478
+ t63 = $[110];
479
+ }
480
+ return t63;
481
+ }
482
+ function DefaultDatabaseField(t0) {
483
+ const $ = c(6);
484
+ const {
485
+ databaseId,
486
+ disabled: t1,
487
+ onDatabaseIdUpdate
488
+ } = t0;
489
+ const disabled = t1 === void 0 ? false : t1;
490
+ const t2 = databaseId ?? "";
491
+ let t3;
492
+ if ($[0] !== onDatabaseIdUpdate) {
493
+ t3 = (e) => onDatabaseIdUpdate(e.target.value);
494
+ $[0] = onDatabaseIdUpdate;
495
+ $[1] = t3;
496
+ } else {
497
+ t3 = $[1];
498
+ }
499
+ let t4;
500
+ if ($[2] !== disabled || $[3] !== t2 || $[4] !== t3) {
501
+ t4 = /* @__PURE__ */ jsx(Tooltip, { title: "Database ID", side: "top", align: "start", children: /* @__PURE__ */ jsx(TextField, { size: "small", invisible: true, inputClassName: "text-end", disabled, value: t2, onChange: t3, placeholder: "(default)" }) });
502
+ $[2] = disabled;
503
+ $[3] = t2;
504
+ $[4] = t3;
505
+ $[5] = t4;
506
+ } else {
507
+ t4 = $[5];
508
+ }
509
+ return t4;
510
+ }
511
+ function LayoutModeSwitch(t0) {
512
+ const $ = c(13);
513
+ const {
514
+ value,
515
+ onChange,
516
+ className
517
+ } = t0;
518
+ let t1;
519
+ if ($[0] !== className) {
520
+ t1 = cls(className);
521
+ $[0] = className;
522
+ $[1] = t1;
523
+ } else {
524
+ t1 = $[1];
525
+ }
526
+ let t2;
527
+ if ($[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
528
+ t2 = /* @__PURE__ */ jsx(Typography, { variant: "label", color: "secondary", className: "ml-3.5", children: "Document view" });
529
+ $[2] = t2;
530
+ } else {
531
+ t2 = $[2];
532
+ }
533
+ let t3;
534
+ if ($[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
535
+ t3 = {
536
+ value: "side_panel",
537
+ label: "Side panel",
538
+ icon: /* @__PURE__ */ jsx(ColumnsIcon, {})
539
+ };
540
+ $[3] = t3;
541
+ } else {
542
+ t3 = $[3];
543
+ }
544
+ let t4;
545
+ if ($[4] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
546
+ t4 = {
547
+ value: "full_screen",
548
+ label: "Full screen",
549
+ icon: /* @__PURE__ */ jsx(SquareIcon, {})
550
+ };
551
+ $[4] = t4;
552
+ } else {
553
+ t4 = $[4];
554
+ }
555
+ let t5;
556
+ if ($[5] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
557
+ t5 = [t3, t4, {
558
+ value: "split",
559
+ label: "Split view",
560
+ icon: /* @__PURE__ */ jsx(PanelLeftIcon, {})
561
+ }];
562
+ $[5] = t5;
563
+ } else {
564
+ t5 = $[5];
565
+ }
566
+ let t6;
567
+ if ($[6] !== onChange || $[7] !== value) {
568
+ t6 = /* @__PURE__ */ jsx("div", { className: "my-2", children: /* @__PURE__ */ jsx(ToggleButtonGroup, { value, onValueChange: onChange, options: t5 }) });
569
+ $[6] = onChange;
570
+ $[7] = value;
571
+ $[8] = t6;
572
+ } else {
573
+ t6 = $[8];
574
+ }
575
+ let t7;
576
+ if ($[9] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
577
+ t7 = /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "secondary", className: "ml-3.5", children: "Should documents be opened full screen or in an inline side dialog" });
578
+ $[9] = t7;
579
+ } else {
580
+ t7 = $[9];
581
+ }
582
+ let t8;
583
+ if ($[10] !== t1 || $[11] !== t6) {
584
+ t8 = /* @__PURE__ */ jsxs("div", { className: t1, children: [
585
+ t2,
586
+ t6,
587
+ t7
588
+ ] });
589
+ $[10] = t1;
590
+ $[11] = t6;
591
+ $[12] = t8;
592
+ } else {
593
+ t8 = $[12];
594
+ }
595
+ return t8;
596
+ }
597
+ function ViewModeSwitch(t0) {
598
+ const $ = c(14);
599
+ const {
600
+ value,
601
+ onChange,
602
+ className
603
+ } = t0;
604
+ let t1;
605
+ if ($[0] !== className) {
606
+ t1 = cls(className);
607
+ $[0] = className;
608
+ $[1] = t1;
609
+ } else {
610
+ t1 = $[1];
611
+ }
612
+ let t2;
613
+ if ($[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
614
+ t2 = /* @__PURE__ */ jsx(Typography, { variant: "label", color: "secondary", className: "ml-3.5", children: "Default collection view" });
615
+ $[2] = t2;
616
+ } else {
617
+ t2 = $[2];
618
+ }
619
+ let t3;
620
+ if ($[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
621
+ t3 = {
622
+ value: "list",
623
+ label: "List",
624
+ icon: /* @__PURE__ */ jsx(ListIcon, {})
625
+ };
626
+ $[3] = t3;
627
+ } else {
628
+ t3 = $[3];
629
+ }
630
+ let t4;
631
+ if ($[4] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
632
+ t4 = {
633
+ value: "table",
634
+ label: "Table",
635
+ icon: /* @__PURE__ */ jsx(TableIcon, {})
636
+ };
637
+ $[4] = t4;
638
+ } else {
639
+ t4 = $[4];
640
+ }
641
+ let t5;
642
+ if ($[5] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
643
+ t5 = {
644
+ value: "cards",
645
+ label: "Cards",
646
+ icon: /* @__PURE__ */ jsx(LayoutGridIcon, {})
647
+ };
648
+ $[5] = t5;
649
+ } else {
650
+ t5 = $[5];
651
+ }
652
+ let t6;
653
+ if ($[6] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
654
+ t6 = [t3, t4, t5, {
655
+ value: "kanban",
656
+ label: "Kanban",
657
+ icon: /* @__PURE__ */ jsx(KanbanIcon, {})
658
+ }];
659
+ $[6] = t6;
660
+ } else {
661
+ t6 = $[6];
662
+ }
663
+ let t7;
664
+ if ($[7] !== onChange || $[8] !== value) {
665
+ t7 = /* @__PURE__ */ jsx("div", { className: "my-2", children: /* @__PURE__ */ jsx(ToggleButtonGroup, { value, onValueChange: onChange, options: t6 }) });
666
+ $[7] = onChange;
667
+ $[8] = value;
668
+ $[9] = t7;
669
+ } else {
670
+ t7 = $[9];
671
+ }
672
+ let t8;
673
+ if ($[10] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
674
+ t8 = /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "secondary", className: "ml-3.5", children: "Choose how entities should be displayed by default" });
675
+ $[10] = t8;
676
+ } else {
677
+ t8 = $[10];
678
+ }
679
+ let t9;
680
+ if ($[11] !== t1 || $[12] !== t7) {
681
+ t9 = /* @__PURE__ */ jsxs("div", { className: t1, children: [
682
+ t2,
683
+ t7,
684
+ t8
685
+ ] });
686
+ $[11] = t1;
687
+ $[12] = t7;
688
+ $[13] = t9;
689
+ } else {
690
+ t9 = $[13];
691
+ }
692
+ return t9;
693
+ }
694
+ function KanbanConfigSection({
695
+ className,
696
+ forceExpanded
697
+ }) {
698
+ useAuthController();
699
+ const customizationController = useCustomizationController();
700
+ const {
701
+ values,
702
+ setFieldValue
703
+ } = useFormex();
704
+ const panelRef = useRef(null);
705
+ const [columnPropertyDialogOpen, setColumnPropertyDialogOpen] = useState(false);
706
+ const enumStringProperties = useMemo(() => {
707
+ const result = [];
708
+ if (!values.properties) return result;
709
+ Object.entries(values.properties).forEach(([key, prop]) => {
710
+ if (prop && "type" in prop && prop.type === "string" && prop.enum) {
711
+ result.push({
712
+ key,
713
+ label: prop.name || key,
714
+ property: prop
715
+ });
716
+ }
717
+ });
718
+ return result;
719
+ }, [values.properties]);
720
+ const kanbanConfig = values.kanban;
721
+ const columnPropertyMissing = Boolean(kanbanConfig?.columnProperty) && !enumStringProperties.some((p) => p.key === kanbanConfig?.columnProperty);
722
+ React__default.useEffect(() => {
723
+ if (forceExpanded && panelRef.current) {
724
+ setTimeout(() => {
725
+ panelRef.current?.scrollIntoView({
726
+ behavior: "smooth",
727
+ block: "center"
728
+ });
729
+ }, 100);
730
+ }
731
+ }, [forceExpanded]);
732
+ const showCreateButton = !kanbanConfig?.columnProperty || columnPropertyMissing;
733
+ const dialogPropertyKey = columnPropertyMissing && kanbanConfig?.columnProperty ? kanbanConfig.columnProperty : "status";
734
+ const dialogPropertyName = columnPropertyMissing && kanbanConfig?.columnProperty ? unslugify(kanbanConfig.columnProperty) : "Status";
735
+ return /* @__PURE__ */ jsxs("div", { className, ref: panelRef, children: [
736
+ /* @__PURE__ */ jsx(Select, { name: "kanban.columnProperty", label: "Kanban Column Property", fullWidth: true, position: "item-aligned", disabled: enumStringProperties.length === 0, error: columnPropertyMissing, value: kanbanConfig?.columnProperty ?? "", onValueChange: (v) => {
737
+ if (v) {
738
+ setFieldValue("kanban", {
739
+ ...kanbanConfig,
740
+ columnProperty: v
741
+ });
742
+ } else {
743
+ setFieldValue("kanban", void 0);
744
+ }
745
+ }, renderValue: (value) => {
746
+ if (columnPropertyMissing) {
747
+ return /* @__PURE__ */ jsxs("span", { className: "text-red-500", children: [
748
+ value,
749
+ " (not found)"
750
+ ] });
751
+ }
752
+ const prop_0 = enumStringProperties.find((p_0) => p_0.key === value);
753
+ if (!prop_0) return "Select a property";
754
+ const fieldConfig = getFieldConfig(prop_0.property, customizationController.propertyConfigs);
755
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
756
+ /* @__PURE__ */ jsx(PropertyConfigBadge, { propertyConfig: fieldConfig }),
757
+ /* @__PURE__ */ jsx("span", { children: prop_0.label })
758
+ ] });
759
+ }, endAdornment: kanbanConfig?.columnProperty ? /* @__PURE__ */ jsx(IconButton, { size: "small", onClick: (e) => {
760
+ e.stopPropagation();
761
+ setFieldValue("kanban", void 0);
762
+ }, children: /* @__PURE__ */ jsx(XIcon, { size: iconSize.smallest }) }) : void 0, children: enumStringProperties.map((prop_1) => {
763
+ const fieldConfig_0 = getFieldConfig(prop_1.property, customizationController.propertyConfigs);
764
+ return /* @__PURE__ */ jsx(SelectItem, { value: prop_1.key, children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
765
+ /* @__PURE__ */ jsx(PropertyConfigBadge, { propertyConfig: fieldConfig_0 }),
766
+ /* @__PURE__ */ jsxs("div", { children: [
767
+ /* @__PURE__ */ jsx("div", { children: prop_1.label }),
768
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "secondary", children: fieldConfig_0?.name || "Enum" })
769
+ ] })
770
+ ] }) }, prop_1.key);
771
+ }) }, `column-select-${enumStringProperties.length}`),
772
+ /* @__PURE__ */ jsx(FieldCaption, { error: columnPropertyMissing, children: columnPropertyMissing ? `Property "${kanbanConfig?.columnProperty}" does not exist or is not an enum string property. Please select a valid property or clear the selection.` : enumStringProperties.length === 0 ? "No enum string properties found. Add a string property with enum to use Kanban view." : "Select a string property with enum values to group entities into columns" }),
773
+ showCreateButton && /* @__PURE__ */ jsxs(Fragment, { children: [
774
+ /* @__PURE__ */ jsxs(Button, { variant: "text", size: "small", className: "ml-3.5 mt-2", onClick: () => setColumnPropertyDialogOpen(true), children: [
775
+ '+ Create "',
776
+ dialogPropertyKey,
777
+ '" property'
778
+ ] }),
779
+ /* @__PURE__ */ jsx(PropertyFormDialog, { open: columnPropertyDialogOpen, onCancel: () => setColumnPropertyDialogOpen(false), property: {
780
+ type: "string",
781
+ name: dialogPropertyName,
782
+ enum: [{
783
+ id: "todo",
784
+ label: "To Do"
785
+ }, {
786
+ id: "in_progress",
787
+ label: "In Progress"
788
+ }, {
789
+ id: "done",
790
+ label: "Done"
791
+ }]
792
+ }, propertyKey: dialogPropertyKey, existingProperty: false, autoOpenTypeSelect: false, autoUpdateId: false, inArray: false, allowDataInference: false, propertyConfigs: customizationController.propertyConfigs, existingPropertyKeys: Object.keys(values.properties ?? {}), onPropertyChanged: ({
793
+ id,
794
+ property
795
+ }) => {
796
+ const newProperties = {
797
+ ...values.properties,
798
+ [id]: property
799
+ };
800
+ const newPropertiesOrder = [...values.propertiesOrder ?? Object.keys(values.properties ?? {}), id];
801
+ setFieldValue("properties", newProperties);
802
+ setFieldValue("propertiesOrder", newPropertiesOrder);
803
+ setFieldValue("kanban", {
804
+ ...kanbanConfig,
805
+ columnProperty: id
806
+ });
807
+ setColumnPropertyDialogOpen(false);
808
+ } })
809
+ ] })
810
+ ] });
811
+ }
812
+ function DisplaySettingsForm({
813
+ expandKanban
814
+ }) {
815
+ const {
816
+ values,
817
+ setFieldValue,
818
+ handleChange,
819
+ submitCount
820
+ } = useFormex();
821
+ const [orderPropertyDialogOpen, setOrderPropertyDialogOpen] = useState(false);
822
+ useAuthController();
823
+ const customizationController = useCustomizationController();
824
+ const configController = useCollectionsConfigController();
825
+ const textProperties = useMemo(() => {
826
+ const result = [];
827
+ if (!values.properties) return result;
828
+ Object.entries(values.properties).forEach(([key, prop]) => {
829
+ if (prop && "type" in prop && prop.type === "string") {
830
+ result.push({
831
+ key,
832
+ label: prop.name || key,
833
+ property: prop
834
+ });
835
+ }
836
+ });
837
+ return result;
838
+ }, [values.properties]);
839
+ return /* @__PURE__ */ jsx("div", { className: "overflow-auto my-auto", children: /* @__PURE__ */ jsxs(Container, { maxWidth: "4xl", className: "flex flex-col gap-4 p-8 m-auto", children: [
840
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Typography, { variant: "h5", className: "flex-grow", children: "Display settings" }) }),
841
+ /* @__PURE__ */ jsx("fieldset", { disabled: configController?.readOnly, className: "contents", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-12 gap-4", children: [
842
+ /* @__PURE__ */ jsx(LayoutModeSwitch, { className: "col-span-12", value: values.openEntityMode ?? "side_panel", onChange: (value) => setFieldValue("openEntityMode", value) }),
843
+ /* @__PURE__ */ jsx(ViewModeSwitch, { className: "col-span-12", value: values.defaultViewMode ?? "table", onChange: (value_0) => setFieldValue("defaultViewMode", value_0) }),
844
+ /* @__PURE__ */ jsx(KanbanConfigSection, { className: "col-span-12", forceExpanded: expandKanban }),
845
+ /* @__PURE__ */ jsxs("div", { className: "col-span-12 mt-4", children: [
846
+ (() => {
847
+ const orderPropertyMissing = Boolean(values.orderProperty) && !textProperties.some((p) => p.key === values.orderProperty);
848
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
849
+ /* @__PURE__ */ jsx(Select, { name: "orderProperty", label: "Order Property", fullWidth: true, position: "item-aligned", disabled: textProperties.length === 0, error: orderPropertyMissing, value: values.orderProperty ?? "", onValueChange: (v) => {
850
+ setFieldValue("orderProperty", v || void 0);
851
+ }, renderValue: (value_1) => {
852
+ if (orderPropertyMissing) {
853
+ return /* @__PURE__ */ jsxs("span", { className: "text-red-500", children: [
854
+ value_1,
855
+ " (not found)"
856
+ ] });
857
+ }
858
+ const prop_0 = textProperties.find((p_0) => p_0.key === value_1);
859
+ if (!prop_0) return "Select a property";
860
+ const fieldConfig = getFieldConfig(prop_0.property, customizationController.propertyConfigs);
861
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
862
+ /* @__PURE__ */ jsx(PropertyConfigBadge, { propertyConfig: fieldConfig }),
863
+ /* @__PURE__ */ jsx("span", { children: prop_0.label })
864
+ ] });
865
+ }, endAdornment: values.orderProperty ? /* @__PURE__ */ jsx(IconButton, { size: "small", onClick: (e) => {
866
+ e.stopPropagation();
867
+ setFieldValue("orderProperty", void 0);
868
+ }, children: /* @__PURE__ */ jsx(XIcon, { size: iconSize.smallest }) }) : void 0, children: textProperties.map((prop_1) => {
869
+ const fieldConfig_0 = getFieldConfig(prop_1.property, customizationController.propertyConfigs);
870
+ return /* @__PURE__ */ jsx(SelectItem, { value: prop_1.key, children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
871
+ /* @__PURE__ */ jsx(PropertyConfigBadge, { propertyConfig: fieldConfig_0 }),
872
+ /* @__PURE__ */ jsxs("div", { children: [
873
+ /* @__PURE__ */ jsx("div", { children: prop_1.label }),
874
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "secondary", children: fieldConfig_0?.name || "Text" })
875
+ ] })
876
+ ] }) }, prop_1.key);
877
+ }) }, `order-select-${textProperties.length}`),
878
+ /* @__PURE__ */ jsx(FieldCaption, { error: orderPropertyMissing, children: orderPropertyMissing ? `Property "${values.orderProperty}" does not exist or is not a text property. Please select a valid property or clear the selection.` : textProperties.length === 0 ? "No text properties found. Add a text property to enable ordering." : "Select a text property to persist the order of items" })
879
+ ] });
880
+ })(),
881
+ (() => {
882
+ const orderPropertyMissing_0 = Boolean(values.orderProperty) && !textProperties.some((p_1) => p_1.key === values.orderProperty);
883
+ const showCreateButton = !values.orderProperty || orderPropertyMissing_0;
884
+ const dialogPropertyKey = orderPropertyMissing_0 && values.orderProperty ? values.orderProperty : "__order";
885
+ const dialogPropertyName = orderPropertyMissing_0 && values.orderProperty ? unslugify(values.orderProperty) : "Order";
886
+ if (!showCreateButton) return null;
887
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
888
+ /* @__PURE__ */ jsxs(Button, { variant: "text", size: "small", className: "ml-3.5 mt-2", onClick: () => setOrderPropertyDialogOpen(true), children: [
889
+ '+ Create "',
890
+ dialogPropertyKey,
891
+ '" property'
892
+ ] }),
893
+ /* @__PURE__ */ jsx(PropertyFormDialog, { open: orderPropertyDialogOpen, onCancel: () => setOrderPropertyDialogOpen(false), property: {
894
+ type: "string",
895
+ name: dialogPropertyName,
896
+ ui: {
897
+ disabled: true,
898
+ hideFromCollection: true
899
+ }
900
+ }, propertyKey: dialogPropertyKey, existingProperty: false, autoOpenTypeSelect: false, autoUpdateId: false, inArray: false, allowDataInference: false, propertyConfigs: customizationController.propertyConfigs, existingPropertyKeys: Object.keys(values.properties ?? {}), onPropertyChanged: ({
901
+ id,
902
+ property
903
+ }) => {
904
+ const newProperties = {
905
+ ...values.properties,
906
+ [id]: property
907
+ };
908
+ const newPropertiesOrder = [...values.propertiesOrder ?? Object.keys(values.properties ?? {}), id];
909
+ setFieldValue("properties", newProperties);
910
+ setFieldValue("propertiesOrder", newPropertiesOrder);
911
+ setFieldValue("orderProperty", id);
912
+ setOrderPropertyDialogOpen(false);
913
+ } })
914
+ ] });
915
+ })()
916
+ ] }),
917
+ /* @__PURE__ */ jsx("div", { className: "col-span-12", children: /* @__PURE__ */ jsx(Select, { name: "defaultSize", fullWidth: true, label: "Default row size", position: "item-aligned", onChange: handleChange, value: values.defaultSize ?? "", renderValue: (value_2) => value_2.toUpperCase(), children: ["xs", "s", "m", "l", "xl"].map((value_3) => /* @__PURE__ */ jsx(SelectItem, { value: value_3, children: value_3.toUpperCase() }, `size-select-${value_3}`)) }) }),
918
+ /* @__PURE__ */ jsxs("div", { className: "col-span-12", children: [
919
+ /* @__PURE__ */ jsx(TextField, { name: "sideDialogWidth", type: "number", "aria-describedby": "sideDialogWidth-helper", onChange: (e_0) => {
920
+ const value_4 = e_0.target.value;
921
+ if (!value_4) {
922
+ setFieldValue("sideDialogWidth", null);
923
+ } else if (!isNaN(Number(value_4))) {
924
+ setFieldValue("sideDialogWidth", Number(value_4));
925
+ }
926
+ }, endAdornment: /* @__PURE__ */ jsx(IconButton, { size: "small", onClick: () => {
927
+ setFieldValue("sideDialogWidth", null);
928
+ }, disabled: !values.sideDialogWidth, children: /* @__PURE__ */ jsx(XIcon, { size: iconSize.small }) }), value: values.sideDialogWidth ?? "", label: "Side dialog width" }),
929
+ /* @__PURE__ */ jsx(FieldCaption, { children: "Optionally define the width (in pixels) of entities side dialog. Default is 768px" })
930
+ ] }),
931
+ /* @__PURE__ */ jsxs("div", { className: "col-span-12", children: [
932
+ /* @__PURE__ */ jsx(BooleanSwitchWithLabel, { position: "start", label: values.inlineEditing === void 0 || values.inlineEditing ? "Data can be edited directly in the table view" : "Data can be edited only in the form view", onValueChange: (v_0) => setFieldValue("inlineEditing", v_0), value: values.inlineEditing === void 0 ? true : values.inlineEditing }),
933
+ /* @__PURE__ */ jsx(FieldCaption, { children: "Allow editing data directly in the table view, without opening the form view." })
934
+ ] }),
935
+ /* @__PURE__ */ jsxs("div", { className: "col-span-12", children: [
936
+ /* @__PURE__ */ jsx(BooleanSwitchWithLabel, { position: "start", label: values.includeJsonView === void 0 || values.includeJsonView ? "Include JSON view" : "Do not include JSON view", onValueChange: (v_1) => setFieldValue("includeJsonView", v_1), value: values.includeJsonView === void 0 ? true : values.includeJsonView }),
937
+ /* @__PURE__ */ jsx(FieldCaption, { children: "Allows removing the form view JSON tab if you think it is confusing for your users." })
938
+ ] })
939
+ ] }) }),
940
+ /* @__PURE__ */ jsx("div", { style: {
941
+ height: "52px"
942
+ } })
943
+ ] }) });
944
+ }
945
+ function GetCodeDialog(t0) {
946
+ const $ = c(22);
947
+ const {
948
+ collection,
949
+ onOpenChange,
950
+ open
951
+ } = t0;
952
+ const snackbarController = useSnackbarController();
953
+ const code = collection ? 'import { EntityCollection } from "@rebasepro/core";\n\nconst ' + (collection?.name ? camelCase(collection.name) : "my") + "Collection:EntityCollection = " + JSON5.stringify(collectionToCode({
954
+ ...collection
955
+ }), null, " ") : "No collection selected";
956
+ let t1;
957
+ if ($[0] !== collection.name) {
958
+ t1 = /* @__PURE__ */ jsxs(DialogTitle, { variant: "h6", children: [
959
+ "Code for ",
960
+ collection.name
961
+ ] });
962
+ $[0] = collection.name;
963
+ $[1] = t1;
964
+ } else {
965
+ t1 = $[1];
966
+ }
967
+ let t2;
968
+ if ($[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
969
+ t2 = /* @__PURE__ */ jsxs(Typography, { variant: "body2", className: "my-4 mb-8", children: [
970
+ "If you want to customise the collection in code, you can add this collection code to your CMS app configuration. More info in the ",
971
+ /* @__PURE__ */ jsx("a", { rel: "noopener noreferrer", href: "https://rebase.pro/docs/cloud/quickstart", children: "docs" }),
972
+ "."
973
+ ] });
974
+ $[2] = t2;
975
+ } else {
976
+ t2 = $[2];
977
+ }
978
+ let t3;
979
+ if ($[3] !== code) {
980
+ t3 = /* @__PURE__ */ jsxs(DialogContent, { children: [
981
+ t2,
982
+ /* @__PURE__ */ jsx(Highlight, { theme: themes.vsDark, code, language: "typescript", children: _temp$4 })
983
+ ] });
984
+ $[3] = code;
985
+ $[4] = t3;
986
+ } else {
987
+ t3 = $[4];
988
+ }
989
+ let t4;
990
+ if ($[5] !== code || $[6] !== snackbarController) {
991
+ t4 = (e) => {
992
+ e.stopPropagation();
993
+ e.preventDefault();
994
+ snackbarController.open({
995
+ type: "success",
996
+ message: "Copied"
997
+ });
998
+ return navigator.clipboard.writeText(code);
999
+ };
1000
+ $[5] = code;
1001
+ $[6] = snackbarController;
1002
+ $[7] = t4;
1003
+ } else {
1004
+ t4 = $[7];
1005
+ }
1006
+ let t5;
1007
+ if ($[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
1008
+ t5 = /* @__PURE__ */ jsx(CopyIcon, {});
1009
+ $[8] = t5;
1010
+ } else {
1011
+ t5 = $[8];
1012
+ }
1013
+ let t6;
1014
+ if ($[9] !== t4) {
1015
+ t6 = /* @__PURE__ */ jsxs(Button, { variant: "text", size: "small", onClick: t4, children: [
1016
+ t5,
1017
+ "CopyIcon to clipboard"
1018
+ ] });
1019
+ $[9] = t4;
1020
+ $[10] = t6;
1021
+ } else {
1022
+ t6 = $[10];
1023
+ }
1024
+ let t7;
1025
+ if ($[11] !== onOpenChange) {
1026
+ t7 = /* @__PURE__ */ jsx(Button, { onClick: () => onOpenChange(false), children: "Close" });
1027
+ $[11] = onOpenChange;
1028
+ $[12] = t7;
1029
+ } else {
1030
+ t7 = $[12];
1031
+ }
1032
+ let t8;
1033
+ if ($[13] !== t6 || $[14] !== t7) {
1034
+ t8 = /* @__PURE__ */ jsxs(DialogActions, { children: [
1035
+ t6,
1036
+ t7
1037
+ ] });
1038
+ $[13] = t6;
1039
+ $[14] = t7;
1040
+ $[15] = t8;
1041
+ } else {
1042
+ t8 = $[15];
1043
+ }
1044
+ let t9;
1045
+ if ($[16] !== onOpenChange || $[17] !== open || $[18] !== t1 || $[19] !== t3 || $[20] !== t8) {
1046
+ t9 = /* @__PURE__ */ jsxs(Dialog, { open, onOpenChange, maxWidth: "4xl", children: [
1047
+ t1,
1048
+ t3,
1049
+ t8
1050
+ ] });
1051
+ $[16] = onOpenChange;
1052
+ $[17] = open;
1053
+ $[18] = t1;
1054
+ $[19] = t3;
1055
+ $[20] = t8;
1056
+ $[21] = t9;
1057
+ } else {
1058
+ t9 = $[21];
1059
+ }
1060
+ return t9;
1061
+ }
1062
+ function _temp$4(t0) {
1063
+ const {
1064
+ style,
1065
+ tokens,
1066
+ getLineProps,
1067
+ getTokenProps
1068
+ } = t0;
1069
+ return /* @__PURE__ */ jsx("pre", { style, className: "p-4 rounded-xs text-sm", children: tokens.map((line, i) => /* @__PURE__ */ jsx("div", { ...getLineProps({
1070
+ line
1071
+ }), children: line.map((token, key) => /* @__PURE__ */ jsx("span", { ...getTokenProps({
1072
+ token
1073
+ }) }, key)) }, i)) });
1074
+ }
1075
+ function collectionToCode(collection) {
1076
+ const propertyCleanup = (value) => {
1077
+ if (value === void 0 || value === null) {
1078
+ return value;
1079
+ }
1080
+ const valueCopy = clone(value);
1081
+ if (typeof valueCopy === "function") {
1082
+ return valueCopy;
1083
+ }
1084
+ if (Array.isArray(valueCopy)) {
1085
+ return valueCopy.map((v) => propertyCleanup(v));
1086
+ }
1087
+ if (typeof valueCopy === "object") {
1088
+ if (valueCopy === null) return valueCopy;
1089
+ const obj = valueCopy;
1090
+ Object.keys(obj).forEach((key) => {
1091
+ if (!isEmptyObject(obj)) {
1092
+ const childRes = propertyCleanup(obj[key]);
1093
+ if (childRes !== null && childRes !== void 0 && childRes !== false && !isEmptyObject(childRes)) {
1094
+ obj[key] = childRes;
1095
+ } else {
1096
+ delete obj[key];
1097
+ }
1098
+ }
1099
+ });
1100
+ delete obj.resolved;
1101
+ delete obj.propertiesOrder;
1102
+ delete obj.propertyConfig;
1103
+ }
1104
+ return valueCopy;
1105
+ };
1106
+ return {
1107
+ id: collection.slug,
1108
+ name: collection.name,
1109
+ singularName: collection.singularName,
1110
+ path: collection.slug,
1111
+ description: collection.description,
1112
+ icon: collection.icon,
1113
+ group: collection.group,
1114
+ defaultFilter: collection.defaultFilter,
1115
+ sort: collection.sort,
1116
+ properties: Object.entries({
1117
+ ...collection.properties ?? {}
1118
+ }).map(([key, value]) => ({
1119
+ [key]: propertyCleanup(value)
1120
+ })).reduce((a, b) => ({
1121
+ ...a,
1122
+ ...b
1123
+ }), {})
1124
+ // subcollections: (collection.subcollections ?? []).map(collectionToCode)
1125
+ };
1126
+ }
1127
+ function CollectionPropertiesEditorForm({
1128
+ showErrors,
1129
+ isNewCollection,
1130
+ propertyErrorsRef,
1131
+ onPropertyError,
1132
+ setDirty,
1133
+ reservedGroups,
1134
+ extraIcon,
1135
+ getUser,
1136
+ getData,
1137
+ doCollectionInference,
1138
+ propertyConfigs
1139
+ }) {
1140
+ const {
1141
+ values,
1142
+ setFieldValue,
1143
+ setFieldError,
1144
+ setFieldTouched,
1145
+ errors,
1146
+ dirty
1147
+ } = useFormex();
1148
+ const snackbarController = useSnackbarController();
1149
+ const configController = useCollectionsConfigController();
1150
+ const largeLayout = useLargeLayout();
1151
+ const asDialog = !largeLayout;
1152
+ const [selectedPropertyIndex, setSelectedPropertyIndex] = useState();
1153
+ const [selectedPropertyKey, setSelectedPropertyKey] = useState();
1154
+ const [selectedPropertyNamespace, setSelectedPropertyNamespace] = useState();
1155
+ const selectedPropertyFullId = selectedPropertyKey ? getFullId(selectedPropertyKey, selectedPropertyNamespace) : void 0;
1156
+ const selectedProperty = selectedPropertyFullId ? getIn(values.properties, selectedPropertyFullId.replaceAll(".", ".properties.")) : void 0;
1157
+ const [codeDialogOpen, setCodeDialogOpen] = useState(false);
1158
+ const [inferringProperties, setInferringProperties] = useState(false);
1159
+ const [newPropertyDialogOpen, setNewPropertyDialogOpen] = useState(false);
1160
+ const [inferredPropertyKeys, setInferredPropertyKeys] = useState([]);
1161
+ const currentPropertiesOrderRef = React__default.useRef(values.propertiesOrder ? {
1162
+ "": values.propertiesOrder
1163
+ } : {});
1164
+ useEffect(() => {
1165
+ if (setDirty) setDirty(dirty);
1166
+ }, [dirty]);
1167
+ const inferPropertiesFromData = doCollectionInference ? () => {
1168
+ if (!doCollectionInference || configController?.readOnly) return;
1169
+ setInferringProperties(true);
1170
+ console.debug("CollectionEditor: inferring properties from data", values);
1171
+ doCollectionInference(values).then((newCollection) => {
1172
+ if (!newCollection) {
1173
+ snackbarController.open({
1174
+ type: "error",
1175
+ message: "Could not infer properties from data"
1176
+ });
1177
+ return;
1178
+ }
1179
+ const findNewPropertyKeys = (existingProps, newProps, namespace) => {
1180
+ if (!newProps) return [];
1181
+ const keys = [];
1182
+ for (const key of Object.keys(newProps)) {
1183
+ const fullKey = namespace ? `${namespace}.${key}` : key;
1184
+ const existingProp = existingProps?.[key];
1185
+ const newProp = newProps[key];
1186
+ if (!existingProp) {
1187
+ keys.push(fullKey);
1188
+ } else if (typeof newProp === "object" && "type" in newProp && newProp.dataType === "map" && newProp.properties) {
1189
+ const existingMapProps = typeof existingProp === "object" && "type" in existingProp && existingProp.dataType === "map" ? existingProp.properties : void 0;
1190
+ keys.push(...findNewPropertyKeys(existingMapProps, newProp.properties, fullKey));
1191
+ }
1192
+ }
1193
+ return keys;
1194
+ };
1195
+ const addNewPropertiesOnly = (existingProps_0, newProps_0) => {
1196
+ if (!newProps_0) return existingProps_0 ?? {};
1197
+ if (!existingProps_0) return newProps_0;
1198
+ const result = {
1199
+ ...existingProps_0
1200
+ };
1201
+ for (const key_0 of Object.keys(newProps_0)) {
1202
+ const existingProp_0 = existingProps_0[key_0];
1203
+ const newProp_0 = newProps_0[key_0];
1204
+ if (!existingProp_0) {
1205
+ result[key_0] = newProp_0;
1206
+ } else if (typeof existingProp_0 === "object" && "type" in existingProp_0 && existingProp_0.dataType === "map" && typeof newProp_0 === "object" && "type" in newProp_0 && newProp_0.dataType === "map" && newProp_0.properties) {
1207
+ const existingMapProps_0 = existingProp_0.properties;
1208
+ if (existingMapProps_0) {
1209
+ result[key_0] = {
1210
+ ...existingProp_0,
1211
+ properties: addNewPropertiesOnly(existingMapProps_0, newProp_0.properties)
1212
+ };
1213
+ }
1214
+ }
1215
+ }
1216
+ return result;
1217
+ };
1218
+ const updatedProperties = addNewPropertiesOnly(values.properties ?? {}, newCollection.properties);
1219
+ const allNewPropertyKeys = findNewPropertyKeys(values.properties, newCollection.properties);
1220
+ const newTopLevelPropertyKeys = (newCollection.properties ? Object.keys(newCollection.properties) : []).filter((propertyKey) => !values.properties[propertyKey]);
1221
+ if (allNewPropertyKeys.length === 0) {
1222
+ snackbarController.open({
1223
+ type: "info",
1224
+ message: "No new properties found in existing data"
1225
+ });
1226
+ return;
1227
+ }
1228
+ const allExistingKeys = values.propertiesOrder ?? Object.keys(values.properties ?? {});
1229
+ const updatedPropertiesOrder = [...newTopLevelPropertyKeys, ...allExistingKeys.filter((key_1) => !newTopLevelPropertyKeys.includes(key_1))];
1230
+ setFieldValue("properties", updatedProperties, false);
1231
+ updatePropertiesOrder(updatedPropertiesOrder);
1232
+ setInferredPropertyKeys(allNewPropertyKeys);
1233
+ snackbarController.open({
1234
+ type: "success",
1235
+ message: `Added ${allNewPropertyKeys.length} new ${allNewPropertyKeys.length === 1 ? "property" : "properties"}`
1236
+ });
1237
+ }).finally(() => {
1238
+ setInferringProperties(false);
1239
+ });
1240
+ } : void 0;
1241
+ const getCurrentPropertiesOrder = (namespace_0) => {
1242
+ if (!namespace_0) return currentPropertiesOrderRef.current[""] ?? getIn(values, namespaceToPropertiesOrderPath());
1243
+ return currentPropertiesOrderRef.current[namespace_0] ?? getIn(values, namespaceToPropertiesOrderPath(namespace_0));
1244
+ };
1245
+ const updatePropertiesOrder = (newPropertiesOrder, namespace_1) => {
1246
+ const propertiesOrderPath = namespaceToPropertiesOrderPath(namespace_1);
1247
+ setFieldValue(propertiesOrderPath, newPropertiesOrder, false);
1248
+ currentPropertiesOrderRef.current[namespace_1 ?? ""] = newPropertiesOrder;
1249
+ };
1250
+ const deleteProperty = (propertyKey_0, namespace_2) => {
1251
+ if (configController?.readOnly) return;
1252
+ const fullId = propertyKey_0 ? getFullId(propertyKey_0, namespace_2) : void 0;
1253
+ if (!fullId) throw Error("collection editor miss config");
1254
+ setFieldValue(idToPropertiesPath(fullId), void 0, false);
1255
+ const currentPropertiesOrder = getCurrentPropertiesOrder(namespace_2);
1256
+ if (currentPropertiesOrder) {
1257
+ const newPropertiesOrder_0 = currentPropertiesOrder.filter((p) => p !== propertyKey_0);
1258
+ updatePropertiesOrder(newPropertiesOrder_0, namespace_2);
1259
+ }
1260
+ setNewPropertyDialogOpen(false);
1261
+ setSelectedPropertyIndex(void 0);
1262
+ setSelectedPropertyKey(void 0);
1263
+ setSelectedPropertyNamespace(void 0);
1264
+ };
1265
+ const onPropertyMove = (propertiesOrder, namespace_3) => {
1266
+ if (configController?.readOnly) return;
1267
+ setFieldValue(namespaceToPropertiesOrderPath(namespace_3), propertiesOrder, false);
1268
+ };
1269
+ const onPropertyCreated = ({
1270
+ id,
1271
+ property
1272
+ }) => {
1273
+ if (configController?.readOnly) return;
1274
+ if (!id) {
1275
+ throw Error("Need to include an ID when creating a new property");
1276
+ }
1277
+ setFieldValue("properties", {
1278
+ ...values.properties ?? {},
1279
+ [id]: property
1280
+ }, false);
1281
+ const newPropertiesOrder_1 = [...values.propertiesOrder ?? Object.keys(values.properties), id];
1282
+ updatePropertiesOrder(newPropertiesOrder_1);
1283
+ setNewPropertyDialogOpen(false);
1284
+ if (largeLayout) {
1285
+ setSelectedPropertyIndex(newPropertiesOrder_1.indexOf(id));
1286
+ setSelectedPropertyKey(id);
1287
+ }
1288
+ setSelectedPropertyNamespace(void 0);
1289
+ };
1290
+ const onPropertyChanged = ({
1291
+ id: id_0,
1292
+ property: property_0,
1293
+ previousId,
1294
+ namespace: namespace_4
1295
+ }) => {
1296
+ const fullId_0 = id_0 ? getFullId(id_0, namespace_4) : void 0;
1297
+ const propertyPath = fullId_0 ? idToPropertiesPath(fullId_0) : void 0;
1298
+ if (previousId && previousId !== id_0) {
1299
+ const previousFullId = getFullId(previousId, namespace_4);
1300
+ const previousPropertyPath = idToPropertiesPath(previousFullId);
1301
+ const currentPropertiesOrder_0 = getCurrentPropertiesOrder(namespace_4);
1302
+ const newPropertiesOrder_2 = currentPropertiesOrder_0.map((p_0) => p_0 === previousId ? id_0 : p_0).filter((p_1) => p_1 !== void 0);
1303
+ updatePropertiesOrder(newPropertiesOrder_2, namespace_4);
1304
+ if (id_0) {
1305
+ setSelectedPropertyIndex(newPropertiesOrder_2.indexOf(id_0));
1306
+ setSelectedPropertyKey(id_0);
1307
+ }
1308
+ setFieldValue(previousPropertyPath, void 0, false);
1309
+ setFieldTouched(previousPropertyPath, false, false);
1310
+ }
1311
+ if (propertyPath) {
1312
+ setFieldValue(propertyPath, property_0, false);
1313
+ setFieldTouched(propertyPath, true, false);
1314
+ }
1315
+ };
1316
+ const onPropertyErrorInternal = (id_1, namespace_5, error) => {
1317
+ const propertyPath_0 = id_1 ? getFullId(id_1, namespace_5) : void 0;
1318
+ console.debug("onPropertyErrorInternal", {
1319
+ id: id_1,
1320
+ namespace: namespace_5,
1321
+ error,
1322
+ propertyPath: propertyPath_0
1323
+ });
1324
+ if (propertyPath_0) {
1325
+ const hasError = error && Object.keys(error).length > 0;
1326
+ onPropertyError(id_1, namespace_5, hasError ? error : void 0);
1327
+ setFieldError(idToPropertiesPath(propertyPath_0), hasError ? "Property error" : void 0);
1328
+ }
1329
+ };
1330
+ const closePropertyDialog = () => {
1331
+ setSelectedPropertyIndex(void 0);
1332
+ setSelectedPropertyKey(void 0);
1333
+ };
1334
+ const initialErrors = selectedPropertyKey && propertyErrorsRef?.current?.properties ? propertyErrorsRef.current.properties[selectedPropertyKey] : void 0;
1335
+ const emptyCollection = (values?.propertiesOrder === void 0 || values.propertiesOrder.length === 0) && (!values?.properties || Object.keys(values.properties).length === 0);
1336
+ const usedPropertiesOrder = values.propertiesOrder ? values.propertiesOrder : Object.keys(values.properties);
1337
+ const owner = useMemo(() => values.ownerId && getUser ? getUser(values.ownerId) : null, [getUser, values.ownerId]);
1338
+ const aiModifiedPaths = useAIModifiedPaths();
1339
+ const generationCounter = aiModifiedPaths?.generationCounter ?? 0;
1340
+ const onPropertyClick = (propertyKey_1, namespace_6) => {
1341
+ console.debug("CollectionEditor: onPropertyClick", {
1342
+ propertyKey: propertyKey_1,
1343
+ namespace: namespace_6
1344
+ });
1345
+ setSelectedPropertyIndex(usedPropertiesOrder.indexOf(propertyKey_1));
1346
+ setSelectedPropertyKey(propertyKey_1);
1347
+ setSelectedPropertyNamespace(namespace_6);
1348
+ };
1349
+ const body = /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-12 gap-2 h-full bg-surface dark:bg-surface-dark", children: [
1350
+ /* @__PURE__ */ jsxs("div", { className: cls("bg-surface-50 dark:bg-surface-900", "p-4 md:p-8", "col-span-12 lg:col-span-5 h-full overflow-auto", !asDialog && "border-r " + defaultBorderMixin), children: [
1351
+ /* @__PURE__ */ jsxs("div", { className: "flex my-2", children: [
1352
+ /* @__PURE__ */ jsxs("div", { className: "grow mb-4", children: [
1353
+ /* @__PURE__ */ jsx(Field, { name: "name", as: DebouncedTextField, invisible: true, className: "-ml-1", inputClassName: "text-2xl font-headers", placeholder: "Collection name", size: "small", required: true, error: Boolean(errors?.name) }),
1354
+ owner && /* @__PURE__ */ jsxs(Typography, { variant: "body2", className: "ml-2", color: "secondary", children: [
1355
+ "Created by ",
1356
+ owner.displayName
1357
+ ] })
1358
+ ] }),
1359
+ extraIcon && /* @__PURE__ */ jsx("div", { className: "ml-4", children: extraIcon }),
1360
+ /* @__PURE__ */ jsxs("div", { className: "ml-4 flex flex-row gap-2 items-center flex-shrink-0", children: [
1361
+ inferPropertiesFromData && /* @__PURE__ */ jsx(Tooltip, { title: "Add new properties based on data", asChild: true, children: /* @__PURE__ */ jsx(IconButton, { variant: "filled", disabled: inferringProperties, onClick: inferPropertiesFromData, children: inferringProperties ? /* @__PURE__ */ jsx(CircularProgress, { size: "small" }) : /* @__PURE__ */ jsx(FileSearchIcon, {}) }) }),
1362
+ /* @__PURE__ */ jsx(Tooltip, { title: "Add new property", asChild: true, children: /* @__PURE__ */ jsx(Button, { disabled: configController?.readOnly, onClick: () => setNewPropertyDialogOpen(true), children: /* @__PURE__ */ jsx(PlusIcon, {}) }) })
1363
+ ] })
1364
+ ] }),
1365
+ /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(PropertyTree, { className: "mt-2", inferredPropertyKeys, selectedPropertyKey: selectedPropertyKey ? getFullId(selectedPropertyKey, selectedPropertyNamespace) : void 0, properties: values.properties, additionalFields: values.additionalFields, propertiesOrder: usedPropertiesOrder, onPropertyClick, onPropertyMove, onPropertyRemove: (isNewCollection || inferredPropertyKeys && inferredPropertyKeys.length > 0) && !configController?.readOnly ? deleteProperty : void 0, errors }) }),
1366
+ /* @__PURE__ */ jsx(Button, { className: "mt-4 xl:mt-8 w-full", variant: "filled", color: "neutral", disabled: configController?.readOnly, onClick: () => setNewPropertyDialogOpen(true), startIcon: /* @__PURE__ */ jsx(PlusIcon, {}), children: "Add new property" })
1367
+ ] }),
1368
+ !asDialog && /* @__PURE__ */ jsx("div", { className: "col-span-12 lg:col-span-7 p-4 md:py-8 md:px-4 h-full overflow-auto", children: /* @__PURE__ */ jsxs("div", { className: "sticky top-8 min-h-full w-full flex flex-col justify-center", children: [
1369
+ selectedPropertyFullId && selectedProperty && !isPropertyBuilder(selectedProperty) && /* @__PURE__ */ jsx(PropertyForm, { inArray: false, existingProperty: !isNewCollection, autoUpdateId: false, allowDataInference: !isNewCollection, autoOpenTypeSelect: false, propertyKey: selectedPropertyKey, propertyNamespace: selectedPropertyNamespace, property: selectedProperty, onPropertyChanged, onDelete: deleteProperty, onError: onPropertyErrorInternal, forceShowErrors: showErrors, initialErrors, getData, propertyConfigs }, `edit_view_${selectedPropertyIndex}_${generationCounter}`),
1370
+ !selectedProperty && /* @__PURE__ */ jsxs("div", { className: "w-full flex flex-col items-center justify-center h-full gap-4", children: [
1371
+ /* @__PURE__ */ jsx(Typography, { variant: "label", className: "", children: emptyCollection ? "Now you can add your first property" : "Select a property to edit it" }),
1372
+ /* @__PURE__ */ jsxs(Button, { disabled: configController?.readOnly, onClick: () => setNewPropertyDialogOpen(true), children: [
1373
+ /* @__PURE__ */ jsx(PlusIcon, {}),
1374
+ "Add new property"
1375
+ ] })
1376
+ ] }),
1377
+ selectedProperty && isPropertyBuilder(selectedProperty) && /* @__PURE__ */ jsx(Typography, { variant: "label", className: "flex items-center justify-center", children: "This property is defined as a property builder in code" })
1378
+ ] }) }),
1379
+ asDialog && /* @__PURE__ */ jsx(PropertyFormDialog, { inArray: false, open: selectedPropertyIndex !== void 0, autoUpdateId: !selectedProperty, allowDataInference: !isNewCollection, existingProperty: true, autoOpenTypeSelect: false, propertyKey: selectedPropertyKey, propertyNamespace: selectedPropertyNamespace, property: selectedProperty, onPropertyChanged, onDelete: deleteProperty, onError: onPropertyErrorInternal, forceShowErrors: showErrors, initialErrors, getData, propertyConfigs, onCancel: closePropertyDialog, onOkClicked: asDialog ? closePropertyDialog : void 0 }, `edit_view_${selectedPropertyIndex}_${generationCounter}`)
1380
+ ] });
1381
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1382
+ body,
1383
+ /* @__PURE__ */ jsx(PropertyFormDialog, { inArray: false, existingProperty: false, autoOpenTypeSelect: true, autoUpdateId: true, forceShowErrors: showErrors, open: newPropertyDialogOpen, onCancel: () => setNewPropertyDialogOpen(false), onPropertyChanged: onPropertyCreated, getData, allowDataInference: !isNewCollection, propertyConfigs, existingPropertyKeys: values.propertiesOrder }),
1384
+ /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(GetCodeDialog, { collection: values, open: codeDialogOpen, onOpenChange: setCodeDialogOpen }) })
1385
+ ] });
1386
+ }
1387
+ function CollectionRelationsTab() {
1388
+ const {
1389
+ values,
1390
+ setFieldValue
1391
+ } = useFormex();
1392
+ const {
1393
+ collections
1394
+ } = useCollectionsConfigController();
1395
+ const [editingRelationIndex, setEditingRelationIndex] = useState(null);
1396
+ const [editingRelationState, setEditingRelationState] = useState(null);
1397
+ const getTargetSlug = (target) => {
1398
+ if (typeof target === "string") {
1399
+ const match = target.match(/\(\)\s*=>\s*([a-zA-Z0-9_]+)/);
1400
+ return match ? match[1] : target;
1401
+ }
1402
+ if (typeof target === "function") {
1403
+ try {
1404
+ if (target.slug) return target.slug;
1405
+ const col = target();
1406
+ return col?.slug || col?.name || "";
1407
+ } catch (e) {
1408
+ return "";
1409
+ }
1410
+ }
1411
+ return "";
1412
+ };
1413
+ const relations = values.relations || [];
1414
+ const handleDelete = (index) => {
1415
+ const newRelations = [...relations];
1416
+ newRelations.splice(index, 1);
1417
+ setFieldValue("relations", newRelations);
1418
+ };
1419
+ const handleSave = () => {
1420
+ if (!editingRelationState) return;
1421
+ const newRelations_0 = [...relations];
1422
+ if (editingRelationIndex === -1) {
1423
+ newRelations_0.push(editingRelationState);
1424
+ } else if (editingRelationIndex !== null) {
1425
+ newRelations_0[editingRelationIndex] = editingRelationState;
1426
+ }
1427
+ setFieldValue("relations", newRelations_0);
1428
+ setEditingRelationIndex(null);
1429
+ setEditingRelationState(null);
1430
+ };
1431
+ const handleCancel = () => {
1432
+ setEditingRelationIndex(null);
1433
+ setEditingRelationState(null);
1434
+ };
1435
+ return /* @__PURE__ */ jsx("div", { className: "overflow-auto my-auto h-full w-full", children: /* @__PURE__ */ jsxs(Container, { maxWidth: "4xl", className: "flex flex-col gap-4 p-8 m-auto h-full", children: [
1436
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-8", children: [
1437
+ /* @__PURE__ */ jsx(Typography, { variant: "h5", children: "Relations" }),
1438
+ /* @__PURE__ */ jsx(Button, { variant: "filled", color: "neutral", onClick: () => {
1439
+ setEditingRelationIndex(-1);
1440
+ setEditingRelationState({
1441
+ relationName: "",
1442
+ target: "",
1443
+ cardinality: "many",
1444
+ direction: "owning"
1445
+ });
1446
+ }, children: "ADD RELATION" })
1447
+ ] }),
1448
+ relations.length > 0 ? /* @__PURE__ */ jsx("div", { className: "w-full overflow-auto border dark:border-surface-800 rounded-lg", children: /* @__PURE__ */ jsxs(Table, { className: "w-full", children: [
1449
+ /* @__PURE__ */ jsxs(TableHeader, { children: [
1450
+ /* @__PURE__ */ jsx(TableCell, { header: true, className: "w-16" }),
1451
+ /* @__PURE__ */ jsx(TableCell, { header: true, children: "Name" }),
1452
+ /* @__PURE__ */ jsx(TableCell, { header: true, children: "Target" }),
1453
+ /* @__PURE__ */ jsx(TableCell, { header: true, children: "Cardinality" }),
1454
+ /* @__PURE__ */ jsx(TableCell, { header: true, children: "Direction" })
1455
+ ] }),
1456
+ /* @__PURE__ */ jsx(TableBody, { children: relations.map((relation, index_0) => /* @__PURE__ */ jsxs(TableRow, { className: "cursor-pointer hover:bg-surface-100 dark:hover:bg-surface-800", onClick: () => {
1457
+ setEditingRelationIndex(index_0);
1458
+ setEditingRelationState(relation);
1459
+ }, children: [
1460
+ /* @__PURE__ */ jsx(TableCell, { style: {
1461
+ width: "64px"
1462
+ }, children: /* @__PURE__ */ jsx(IconButton, { size: "small", onClick: (e_0) => {
1463
+ e_0.stopPropagation();
1464
+ handleDelete(index_0);
1465
+ }, children: /* @__PURE__ */ jsx(Trash2Icon, {}) }) }),
1466
+ /* @__PURE__ */ jsx(TableCell, { className: "font-medium", children: relation.relationName }),
1467
+ /* @__PURE__ */ jsx(TableCell, { children: getTargetSlug(relation.target) || "Function" }),
1468
+ /* @__PURE__ */ jsx(TableCell, { children: relation.cardinality }),
1469
+ /* @__PURE__ */ jsx(TableCell, { children: relation.direction || "owning" })
1470
+ ] }, index_0)) })
1471
+ ] }) }) : /* @__PURE__ */ jsxs("div", { className: "flex-grow flex flex-col border border-dashed dark:border-surface-700 rounded-lg items-center justify-center text-text-disabled py-20", children: [
1472
+ /* @__PURE__ */ jsx(Typography, { variant: "body2", className: "mb-4", children: "No relations defined for this collection." }),
1473
+ /* @__PURE__ */ jsx(Button, { variant: "text", onClick: () => {
1474
+ setEditingRelationIndex(-1);
1475
+ setEditingRelationState({
1476
+ relationName: "",
1477
+ target: "",
1478
+ cardinality: "many",
1479
+ direction: "owning"
1480
+ });
1481
+ }, children: "Create your first relation" })
1482
+ ] }),
1483
+ /* @__PURE__ */ jsx(Dialog, { open: !!editingRelationState, onOpenChange: (open) => !open && handleCancel(), maxWidth: "2xl", children: editingRelationState && /* @__PURE__ */ jsxs(Fragment, { children: [
1484
+ /* @__PURE__ */ jsx(DialogTitle, { className: "flex justify-between items-center w-full", variant: "h6", children: editingRelationIndex === -1 ? "New Relation" : "Edit Relation" }),
1485
+ /* @__PURE__ */ jsx(DialogContent, { includeMargin: false, className: "p-4 md:p-6 border-t dark:border-surface-700 bg-surface-50 dark:bg-surface-800", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4 max-w-2xl mx-auto", children: [
1486
+ /* @__PURE__ */ jsx(TextField, { label: "Relation Name", name: "relationName", placeholder: "e.g. posts", value: editingRelationState.relationName || "", onChange: (e_1) => setEditingRelationState((prev) => prev ? {
1487
+ ...prev,
1488
+ relationName: e_1.target.value
1489
+ } : null) }),
1490
+ /* @__PURE__ */ jsx(Select, { fullWidth: true, label: "Target Collection", value: getTargetSlug(editingRelationState.target), onValueChange: (val) => {
1491
+ setEditingRelationState((prev_0) => {
1492
+ if (!prev_0) return null;
1493
+ const targetFn = () => collections?.find((c2) => c2.slug === val) || {
1494
+ slug: val
1495
+ };
1496
+ targetFn.slug = val;
1497
+ return {
1498
+ ...prev_0,
1499
+ target: targetFn
1500
+ };
1501
+ });
1502
+ }, children: collections?.map((col_0) => /* @__PURE__ */ jsx(SelectItem, { value: col_0.slug, children: col_0.name || col_0.slug }, col_0.slug)) }),
1503
+ /* @__PURE__ */ jsxs(Select, { fullWidth: true, label: "Cardinality", value: editingRelationState.cardinality || "many", onValueChange: (val_0) => setEditingRelationState((prev_1) => prev_1 ? {
1504
+ ...prev_1,
1505
+ cardinality: val_0
1506
+ } : null), children: [
1507
+ /* @__PURE__ */ jsx(SelectItem, { value: "many", children: "Many" }),
1508
+ /* @__PURE__ */ jsx(SelectItem, { value: "one", children: "One" })
1509
+ ] }),
1510
+ /* @__PURE__ */ jsxs(Select, { fullWidth: true, label: "Direction", value: editingRelationState.direction || "owning", onValueChange: (val_1) => setEditingRelationState((prev_2) => prev_2 ? {
1511
+ ...prev_2,
1512
+ direction: val_1
1513
+ } : null), children: [
1514
+ /* @__PURE__ */ jsx(SelectItem, { value: "owning", children: "Owning" }),
1515
+ /* @__PURE__ */ jsx(SelectItem, { value: "inverse", children: "Inverse" })
1516
+ ] }),
1517
+ editingRelationState.cardinality === "many" && editingRelationState.direction === "owning" && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4 mt-4 pt-4 border-t dark:border-surface-800", children: [
1518
+ /* @__PURE__ */ jsx(Typography, { variant: "subtitle2", className: "text-text-primary", children: "Intermediate Table" }),
1519
+ /* @__PURE__ */ jsx(Typography, { variant: "body2", className: "text-text-secondary -mt-3", children: "Required for many-to-many relationships. This defines the junction table linking both collections." }),
1520
+ /* @__PURE__ */ jsx(TextField, { label: "Table Name", name: "throughTable", placeholder: "e.g. user_roles", value: editingRelationState.through?.table || "", onChange: (e_2) => setEditingRelationState((prev_3) => prev_3 ? {
1521
+ ...prev_3,
1522
+ through: {
1523
+ ...prev_3.through || {
1524
+ sourceColumn: "",
1525
+ targetColumn: ""
1526
+ },
1527
+ table: e_2.target.value
1528
+ }
1529
+ } : null) }),
1530
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-4", children: [
1531
+ /* @__PURE__ */ jsx(TextField, { className: "flex-1", label: "Source Column", name: "sourceColumn", placeholder: "FK to this collection", value: editingRelationState.through?.sourceColumn || "", onChange: (e_3) => setEditingRelationState((prev_4) => prev_4 ? {
1532
+ ...prev_4,
1533
+ through: {
1534
+ ...prev_4.through || {
1535
+ table: "",
1536
+ targetColumn: ""
1537
+ },
1538
+ sourceColumn: e_3.target.value
1539
+ }
1540
+ } : null) }),
1541
+ /* @__PURE__ */ jsx(TextField, { className: "flex-1", label: "Target Column", name: "targetColumn", placeholder: "FK to target collection", value: editingRelationState.through?.targetColumn || "", onChange: (e_4) => setEditingRelationState((prev_5) => prev_5 ? {
1542
+ ...prev_5,
1543
+ through: {
1544
+ ...prev_5.through || {
1545
+ table: "",
1546
+ sourceColumn: ""
1547
+ },
1548
+ targetColumn: e_4.target.value
1549
+ }
1550
+ } : null) })
1551
+ ] })
1552
+ ] })
1553
+ ] }) }),
1554
+ /* @__PURE__ */ jsxs(DialogActions, { children: [
1555
+ /* @__PURE__ */ jsx(Button, { variant: "text", onClick: handleCancel, children: "Cancel" }),
1556
+ /* @__PURE__ */ jsx(Button, { variant: "filled", color: "primary", onClick: handleSave, disabled: !editingRelationState.relationName || !editingRelationState.target, children: "Save" })
1557
+ ] })
1558
+ ] }) })
1559
+ ] }) });
1560
+ }
1561
+ const EXAMPLE_JSON = `{
1562
+ "id": "products",
1563
+ "name": "Products",
1564
+ "path": "products",
1565
+ "icon": "shopping_cart",
1566
+ "properties": {
1567
+ "name": {
1568
+ "type": "string",
1569
+ "name": "Name",
1570
+ "validation": { "required": true }
1571
+ },
1572
+ "price": {
1573
+ "type": "number",
1574
+ "name": "Price"
1575
+ },
1576
+ "available": {
1577
+ "type": "boolean",
1578
+ "name": "Available"
1579
+ }
1580
+ }
1581
+ }`;
1582
+ function CollectionJsonImportDialog(t0) {
1583
+ const $ = c(46);
1584
+ const {
1585
+ open,
1586
+ onClose,
1587
+ onImport
1588
+ } = t0;
1589
+ const [jsonValue, setJsonValue] = useState("");
1590
+ let t1;
1591
+ if ($[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
1592
+ t1 = [];
1593
+ $[0] = t1;
1594
+ } else {
1595
+ t1 = $[0];
1596
+ }
1597
+ const [errors, setErrors] = useState(t1);
1598
+ const [touched, setTouched] = useState(false);
1599
+ let t2;
1600
+ if ($[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
1601
+ t2 = (e) => {
1602
+ const value = e.target.value;
1603
+ setJsonValue(value);
1604
+ setTouched(true);
1605
+ if (!value.trim()) {
1606
+ setErrors([]);
1607
+ return;
1608
+ }
1609
+ const result = validateCollectionJson(value);
1610
+ setErrors(result.errors);
1611
+ };
1612
+ $[1] = t2;
1613
+ } else {
1614
+ t2 = $[1];
1615
+ }
1616
+ const handleJsonChange = t2;
1617
+ let t3;
1618
+ if ($[2] !== jsonValue || $[3] !== onClose || $[4] !== onImport) {
1619
+ t3 = () => {
1620
+ const result_0 = validateCollectionJson(jsonValue);
1621
+ if (result_0.valid && result_0.collection) {
1622
+ onImport(result_0.collection);
1623
+ setJsonValue("");
1624
+ setErrors([]);
1625
+ setTouched(false);
1626
+ onClose();
1627
+ }
1628
+ };
1629
+ $[2] = jsonValue;
1630
+ $[3] = onClose;
1631
+ $[4] = onImport;
1632
+ $[5] = t3;
1633
+ } else {
1634
+ t3 = $[5];
1635
+ }
1636
+ const handleImport = t3;
1637
+ let t4;
1638
+ if ($[6] !== onClose) {
1639
+ t4 = () => {
1640
+ setJsonValue("");
1641
+ setErrors([]);
1642
+ setTouched(false);
1643
+ onClose();
1644
+ };
1645
+ $[6] = onClose;
1646
+ $[7] = t4;
1647
+ } else {
1648
+ t4 = $[7];
1649
+ }
1650
+ const handleClose = t4;
1651
+ let t5;
1652
+ if ($[8] !== errors.length || $[9] !== jsonValue || $[10] !== touched) {
1653
+ t5 = touched && jsonValue.trim() && errors.length === 0;
1654
+ $[8] = errors.length;
1655
+ $[9] = jsonValue;
1656
+ $[10] = touched;
1657
+ $[11] = t5;
1658
+ } else {
1659
+ t5 = $[11];
1660
+ }
1661
+ const isValid = t5;
1662
+ let t6;
1663
+ if ($[12] !== handleClose) {
1664
+ t6 = (open_0) => !open_0 && handleClose();
1665
+ $[12] = handleClose;
1666
+ $[13] = t6;
1667
+ } else {
1668
+ t6 = $[13];
1669
+ }
1670
+ let t7;
1671
+ if ($[14] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
1672
+ t7 = /* @__PURE__ */ jsxs(DialogTitle, { className: "flex items-center gap-2", children: [
1673
+ /* @__PURE__ */ jsx(CodeIcon, { size: iconSize.smallest }),
1674
+ "Import Collection from JSON"
1675
+ ] });
1676
+ $[14] = t7;
1677
+ } else {
1678
+ t7 = $[14];
1679
+ }
1680
+ let t8;
1681
+ if ($[15] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
1682
+ t8 = /* @__PURE__ */ jsx("code", { className: "bg-surface-200 dark:bg-surface-700 px-1 rounded", children: "id" });
1683
+ $[15] = t8;
1684
+ } else {
1685
+ t8 = $[15];
1686
+ }
1687
+ let t9;
1688
+ if ($[16] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
1689
+ t9 = /* @__PURE__ */ jsx("code", { className: "bg-surface-200 dark:bg-surface-700 px-1 rounded", children: "name" });
1690
+ $[16] = t9;
1691
+ } else {
1692
+ t9 = $[16];
1693
+ }
1694
+ let t10;
1695
+ if ($[17] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
1696
+ t10 = /* @__PURE__ */ jsx("code", { className: "bg-surface-200 dark:bg-surface-700 px-1 rounded", children: "path" });
1697
+ $[17] = t10;
1698
+ } else {
1699
+ t10 = $[17];
1700
+ }
1701
+ let t11;
1702
+ if ($[18] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
1703
+ t11 = /* @__PURE__ */ jsxs(Typography, { variant: "body2", color: "secondary", children: [
1704
+ "Paste a JSON object representing your collection configuration. The JSON must include ",
1705
+ t8,
1706
+ ",",
1707
+ t9,
1708
+ ",",
1709
+ t10,
1710
+ ", and",
1711
+ /* @__PURE__ */ jsx("code", { className: "bg-surface-200 dark:bg-surface-700 px-1 rounded", children: "properties" }),
1712
+ "."
1713
+ ] });
1714
+ $[18] = t11;
1715
+ } else {
1716
+ t11 = $[18];
1717
+ }
1718
+ const t12 = errors.length > 0 && touched ? "border-red-500 dark:border-red-400" : "border-surface-300 dark:border-surface-600";
1719
+ let t13;
1720
+ if ($[19] !== t12) {
1721
+ t13 = cls("w-full p-3 font-mono text-sm rounded-md border resize-none overflow-y-auto", "bg-surface-50 dark:bg-surface-800", "focus:outline-none focus:ring-2 focus:ring-primary", "h-[300px]", t12);
1722
+ $[19] = t12;
1723
+ $[20] = t13;
1724
+ } else {
1725
+ t13 = $[20];
1726
+ }
1727
+ let t14;
1728
+ if ($[21] !== jsonValue || $[22] !== t13) {
1729
+ t14 = /* @__PURE__ */ jsx("textarea", { value: jsonValue, onChange: handleJsonChange, placeholder: EXAMPLE_JSON, rows: 12, className: t13 });
1730
+ $[21] = jsonValue;
1731
+ $[22] = t13;
1732
+ $[23] = t14;
1733
+ } else {
1734
+ t14 = $[23];
1735
+ }
1736
+ let t15;
1737
+ if ($[24] !== errors || $[25] !== touched) {
1738
+ t15 = errors.length > 0 && touched && /* @__PURE__ */ jsxs("div", { className: "p-3 bg-red-50 dark:bg-red-900/20 rounded-md border border-red-200 dark:border-red-800", children: [
1739
+ /* @__PURE__ */ jsx(Typography, { variant: "body2", className: "font-medium text-red-700 dark:text-red-400 mb-2", children: "Validation errors:" }),
1740
+ /* @__PURE__ */ jsx("ul", { className: "list-disc list-inside space-y-1", children: errors.map(_temp$3) })
1741
+ ] });
1742
+ $[24] = errors;
1743
+ $[25] = touched;
1744
+ $[26] = t15;
1745
+ } else {
1746
+ t15 = $[26];
1747
+ }
1748
+ let t16;
1749
+ if ($[27] !== isValid) {
1750
+ t16 = isValid && /* @__PURE__ */ jsx("div", { className: "p-3 bg-green-50 dark:bg-green-900/20 rounded-md border border-green-200 dark:border-green-800", children: /* @__PURE__ */ jsx(Typography, { variant: "body2", className: "text-green-700 dark:text-green-400", children: "✓ JSON is valid and ready to import" }) });
1751
+ $[27] = isValid;
1752
+ $[28] = t16;
1753
+ } else {
1754
+ t16 = $[28];
1755
+ }
1756
+ let t17;
1757
+ if ($[29] !== t14 || $[30] !== t15 || $[31] !== t16) {
1758
+ t17 = /* @__PURE__ */ jsxs(DialogContent, { className: "flex flex-col gap-4", children: [
1759
+ t11,
1760
+ t14,
1761
+ t15,
1762
+ t16
1763
+ ] });
1764
+ $[29] = t14;
1765
+ $[30] = t15;
1766
+ $[31] = t16;
1767
+ $[32] = t17;
1768
+ } else {
1769
+ t17 = $[32];
1770
+ }
1771
+ let t18;
1772
+ if ($[33] !== handleClose) {
1773
+ t18 = /* @__PURE__ */ jsx(Button, { variant: "text", onClick: handleClose, children: "Cancel" });
1774
+ $[33] = handleClose;
1775
+ $[34] = t18;
1776
+ } else {
1777
+ t18 = $[34];
1778
+ }
1779
+ const t19 = !isValid;
1780
+ let t20;
1781
+ if ($[35] !== handleImport || $[36] !== t19) {
1782
+ t20 = /* @__PURE__ */ jsx(Button, { variant: "filled", color: "primary", onClick: handleImport, disabled: t19, children: "Import Collection" });
1783
+ $[35] = handleImport;
1784
+ $[36] = t19;
1785
+ $[37] = t20;
1786
+ } else {
1787
+ t20 = $[37];
1788
+ }
1789
+ let t21;
1790
+ if ($[38] !== t18 || $[39] !== t20) {
1791
+ t21 = /* @__PURE__ */ jsxs(DialogActions, { children: [
1792
+ t18,
1793
+ t20
1794
+ ] });
1795
+ $[38] = t18;
1796
+ $[39] = t20;
1797
+ $[40] = t21;
1798
+ } else {
1799
+ t21 = $[40];
1800
+ }
1801
+ let t22;
1802
+ if ($[41] !== open || $[42] !== t17 || $[43] !== t21 || $[44] !== t6) {
1803
+ t22 = /* @__PURE__ */ jsxs(Dialog, { open, onOpenChange: t6, maxWidth: "2xl", children: [
1804
+ t7,
1805
+ t17,
1806
+ t21
1807
+ ] });
1808
+ $[41] = open;
1809
+ $[42] = t17;
1810
+ $[43] = t21;
1811
+ $[44] = t6;
1812
+ $[45] = t22;
1813
+ } else {
1814
+ t22 = $[45];
1815
+ }
1816
+ return t22;
1817
+ }
1818
+ function _temp$3(error, index) {
1819
+ return /* @__PURE__ */ jsx("li", { className: "text-sm text-red-600 dark:text-red-400", children: error.path ? /* @__PURE__ */ jsxs(Fragment, { children: [
1820
+ /* @__PURE__ */ jsx("code", { className: "bg-red-100 dark:bg-red-900/40 px-1 rounded", children: error.path }),
1821
+ ": ",
1822
+ error.message
1823
+ ] }) : error.message }, index);
1824
+ }
1825
+ const productsCollectionTemplate = {
1826
+ slug: "products",
1827
+ table: "products",
1828
+ name: "Products",
1829
+ singularName: "Product",
1830
+ icon: "ShoppingCart",
1831
+ description: "List of the products currently sold in your shop",
1832
+ properties: {
1833
+ name: {
1834
+ type: "string",
1835
+ name: "Name",
1836
+ description: "Name of this product",
1837
+ validation: {
1838
+ required: true
1839
+ }
1840
+ },
1841
+ brand: {
1842
+ type: "string",
1843
+ name: "Brand",
1844
+ validation: {
1845
+ required: true
1846
+ }
1847
+ },
1848
+ description: {
1849
+ type: "string",
1850
+ name: "Description",
1851
+ description: "Description of this product, supports markdown",
1852
+ markdown: true
1853
+ },
1854
+ main_image: {
1855
+ type: "string",
1856
+ name: "Image",
1857
+ storage: {
1858
+ storagePath: "images",
1859
+ acceptedFiles: ["image/*"]
1860
+ },
1861
+ description: "Upload field for images"
1862
+ },
1863
+ available: {
1864
+ type: "boolean",
1865
+ name: "Available",
1866
+ columnWidth: 100,
1867
+ description: "Is this product available in the website"
1868
+ },
1869
+ price: {
1870
+ type: "number",
1871
+ name: "Price",
1872
+ validation: {
1873
+ requiredMessage: "You must set a positive price",
1874
+ min: 0
1875
+ }
1876
+ },
1877
+ images: {
1878
+ type: "array",
1879
+ name: "Images",
1880
+ hideFromCollection: true,
1881
+ of: {
1882
+ type: "string",
1883
+ storage: {
1884
+ storagePath: "images",
1885
+ acceptedFiles: ["image/*"]
1886
+ }
1887
+ }
1888
+ },
1889
+ related_products: {
1890
+ type: "array",
1891
+ name: "Related products",
1892
+ description: "Products related to this one",
1893
+ of: {
1894
+ type: "reference",
1895
+ path: "products"
1896
+ }
1897
+ },
1898
+ metadata: {
1899
+ name: "Metadata",
1900
+ description: "This is an example of a map property",
1901
+ type: "map",
1902
+ keyValue: true
1903
+ },
1904
+ added_on: {
1905
+ type: "date",
1906
+ name: "Added on",
1907
+ autoValue: "on_create"
1908
+ }
1909
+ }
1910
+ };
1911
+ const blogCollectionTemplate = {
1912
+ slug: "blog",
1913
+ table: "blog",
1914
+ name: "Blog",
1915
+ singularName: "Blog entry",
1916
+ icon: "FileText",
1917
+ description: "A collection of blog entries",
1918
+ defaultSize: "l",
1919
+ properties: {
1920
+ name: {
1921
+ name: "Name",
1922
+ validation: {
1923
+ required: true
1924
+ },
1925
+ type: "string"
1926
+ },
1927
+ header_image: {
1928
+ name: "Header image",
1929
+ type: "string",
1930
+ storage: {
1931
+ storagePath: "images",
1932
+ acceptedFiles: ["image/*"],
1933
+ metadata: {
1934
+ cacheControl: "max-age=1000000"
1935
+ }
1936
+ }
1937
+ },
1938
+ content: {
1939
+ name: "Content",
1940
+ description: "Content blocks for the blog entry",
1941
+ validation: {
1942
+ required: true
1943
+ },
1944
+ type: "array",
1945
+ oneOf: {
1946
+ typeField: "type",
1947
+ valueField: "value",
1948
+ properties: {
1949
+ text: {
1950
+ type: "string",
1951
+ name: "Text",
1952
+ markdown: true
1953
+ },
1954
+ quote: {
1955
+ type: "string",
1956
+ name: "Quote",
1957
+ multiline: true
1958
+ },
1959
+ images: {
1960
+ name: "Images",
1961
+ type: "array",
1962
+ of: {
1963
+ type: "string",
1964
+ storage: {
1965
+ storagePath: "images",
1966
+ acceptedFiles: ["image/*"],
1967
+ metadata: {
1968
+ cacheControl: "max-age=1000000"
1969
+ }
1970
+ }
1971
+ },
1972
+ description: "This fields allows uploading multiple images at once and reordering"
1973
+ },
1974
+ products: {
1975
+ name: "Products",
1976
+ type: "array",
1977
+ of: {
1978
+ type: "reference",
1979
+ path: "products",
1980
+ previewProperties: ["name", "main_image"]
1981
+ }
1982
+ }
1983
+ },
1984
+ propertiesOrder: ["text", "quote", "images", "products"]
1985
+ }
1986
+ },
1987
+ created_on: {
1988
+ name: "Created on",
1989
+ type: "date",
1990
+ autoValue: "on_create"
1991
+ },
1992
+ status: {
1993
+ name: "Status",
1994
+ validation: {
1995
+ required: true
1996
+ },
1997
+ type: "string",
1998
+ enum: {
1999
+ published: {
2000
+ id: "published",
2001
+ label: "Published"
2002
+ },
2003
+ draft: "Draft"
2004
+ },
2005
+ defaultValue: "draft"
2006
+ },
2007
+ publish_date: {
2008
+ name: "Publish date",
2009
+ type: "date",
2010
+ clearable: true
2011
+ },
2012
+ reviewed: {
2013
+ name: "Reviewed",
2014
+ type: "boolean"
2015
+ },
2016
+ tags: {
2017
+ name: "Tags",
2018
+ description: "Example of generic array",
2019
+ type: "array",
2020
+ of: {
2021
+ type: "string",
2022
+ previewAsTag: true
2023
+ }
2024
+ }
2025
+ }
2026
+ };
2027
+ const usersCollectionTemplate = {
2028
+ slug: "users",
2029
+ table: "users",
2030
+ name: "Users",
2031
+ singularName: "User",
2032
+ description: "Registered users in the app/web",
2033
+ icon: "User",
2034
+ properties: {
2035
+ displayName: {
2036
+ name: "Display name",
2037
+ type: "string"
2038
+ },
2039
+ email: {
2040
+ name: "Email",
2041
+ type: "string",
2042
+ email: true
2043
+ },
2044
+ emailVerified: {
2045
+ name: "Email verified",
2046
+ type: "boolean"
2047
+ },
2048
+ phone: {
2049
+ name: "Phone",
2050
+ type: "string"
2051
+ },
2052
+ favourite_products: {
2053
+ name: "Favourite products",
2054
+ type: "array",
2055
+ of: {
2056
+ type: "reference",
2057
+ path: "products"
2058
+ }
2059
+ },
2060
+ photoURL: {
2061
+ name: "Photo URL",
2062
+ type: "string",
2063
+ url: "image"
2064
+ }
2065
+ }
2066
+ };
2067
+ const pagesCollectionTemplate = {
2068
+ slug: "pages",
2069
+ table: "pages",
2070
+ name: "Pages",
2071
+ singularName: "Page",
2072
+ icon: "File",
2073
+ description: "List of website pages that can be edited here",
2074
+ properties: {
2075
+ title: {
2076
+ type: "string",
2077
+ name: "Page Title",
2078
+ validation: {
2079
+ required: true
2080
+ }
2081
+ },
2082
+ slug: {
2083
+ type: "string",
2084
+ name: "URL Slug",
2085
+ validation: {
2086
+ required: true,
2087
+ unique: true,
2088
+ matches: "^[a-z0-9]+(?:-[a-z0-9]+)*$",
2089
+ matchesMessage: "Must be lowercase, alphanumeric, and hyphenated"
2090
+ }
2091
+ },
2092
+ hero_section: {
2093
+ type: "map",
2094
+ name: "Hero Section",
2095
+ properties: {
2096
+ headline: {
2097
+ type: "string",
2098
+ name: "Headline",
2099
+ validation: {
2100
+ required: true
2101
+ }
2102
+ },
2103
+ subhead: {
2104
+ type: "string",
2105
+ name: "Subheadline"
2106
+ },
2107
+ background_image: {
2108
+ type: "string",
2109
+ name: "Background Image",
2110
+ storage: {
2111
+ storagePath: "page_hero/images",
2112
+ acceptedFiles: ["image/*"]
2113
+ }
2114
+ },
2115
+ call_to_action: {
2116
+ type: "string",
2117
+ name: "Call to Action"
2118
+ },
2119
+ call_to_action_link: {
2120
+ type: "string",
2121
+ name: "CTA Link",
2122
+ url: true
2123
+ }
2124
+ }
2125
+ },
2126
+ content: {
2127
+ type: "array",
2128
+ name: "Content",
2129
+ oneOf: {
2130
+ properties: {
2131
+ section: {
2132
+ type: "map",
2133
+ name: "Section",
2134
+ properties: {
2135
+ title: {
2136
+ type: "string",
2137
+ name: "Section Title",
2138
+ validation: {
2139
+ required: true
2140
+ }
2141
+ },
2142
+ content: {
2143
+ type: "string",
2144
+ name: "Section Content",
2145
+ markdown: true
2146
+ },
2147
+ image: {
2148
+ type: "string",
2149
+ name: "Section Image",
2150
+ storage: {
2151
+ storagePath: "page_sections/images",
2152
+ acceptedFiles: ["image/*"]
2153
+ }
2154
+ },
2155
+ link: {
2156
+ type: "string",
2157
+ name: "Section Link",
2158
+ url: true
2159
+ }
2160
+ }
2161
+ },
2162
+ image: {
2163
+ type: "string",
2164
+ name: "Image",
2165
+ storage: {
2166
+ storagePath: "page_sections/images",
2167
+ acceptedFiles: ["image/*"]
2168
+ }
2169
+ },
2170
+ slider: {
2171
+ type: "array",
2172
+ name: "Slider",
2173
+ of: {
2174
+ type: "map",
2175
+ properties: {
2176
+ title: {
2177
+ type: "string",
2178
+ name: "Title",
2179
+ validation: {
2180
+ required: true
2181
+ }
2182
+ },
2183
+ image: {
2184
+ type: "string",
2185
+ storage: {
2186
+ storagePath: "page_sections/images",
2187
+ acceptedFiles: ["image/*"]
2188
+ }
2189
+ }
2190
+ }
2191
+ }
2192
+ }
2193
+ }
2194
+ }
2195
+ },
2196
+ sidebar: {
2197
+ type: "map",
2198
+ name: "Sidebar",
2199
+ properties: {
2200
+ title: {
2201
+ type: "string",
2202
+ name: "Sidebar Title",
2203
+ validation: {
2204
+ required: false
2205
+ }
2206
+ },
2207
+ content: {
2208
+ type: "string",
2209
+ name: "Sidebar Content",
2210
+ markdown: true
2211
+ }
2212
+ }
2213
+ },
2214
+ seo_metadata: {
2215
+ type: "map",
2216
+ name: "SEO Metadata",
2217
+ properties: {
2218
+ meta_title: {
2219
+ type: "string",
2220
+ name: "Meta Title"
2221
+ },
2222
+ meta_description: {
2223
+ type: "string",
2224
+ name: "Meta Description"
2225
+ },
2226
+ focus_keywords: {
2227
+ type: "array",
2228
+ name: "Focus Keywords",
2229
+ of: {
2230
+ type: "string"
2231
+ }
2232
+ }
2233
+ }
2234
+ },
2235
+ footer_override: {
2236
+ type: "string",
2237
+ name: "Footer Override",
2238
+ markdown: true
2239
+ },
2240
+ publish_date: {
2241
+ type: "date",
2242
+ name: "Publish Date",
2243
+ validation: {
2244
+ required: true
2245
+ }
2246
+ },
2247
+ last_updated: {
2248
+ type: "date",
2249
+ name: "Last Updated",
2250
+ autoValue: "on_update"
2251
+ },
2252
+ is_published: {
2253
+ type: "boolean",
2254
+ name: "Is Published",
2255
+ columnWidth: 100,
2256
+ description: "Should this page be live on the site?"
2257
+ }
2258
+ }
2259
+ };
2260
+ function AICollectionGeneratorPopover({
2261
+ existingCollection,
2262
+ onGenerated,
2263
+ generateCollection,
2264
+ trigger,
2265
+ size = "small",
2266
+ showLabel = true,
2267
+ onAnalyticsEvent
2268
+ }) {
2269
+ const [menuOpen, setMenuOpen] = useState(false);
2270
+ const [prompt, setPrompt] = useState("");
2271
+ const [loading, setLoading] = useState(false);
2272
+ const [error, setError] = useState(null);
2273
+ const collectionRegistry = useCollectionRegistryController();
2274
+ const configController = useCollectionsConfigController();
2275
+ const snackbarController = useSnackbarController();
2276
+ const existingCollections = collectionRegistry.collections ?? [];
2277
+ const handleGenerate = async () => {
2278
+ if (!prompt.trim()) return;
2279
+ setLoading(true);
2280
+ setError(null);
2281
+ const mode = existingCollection ? "modify" : "create";
2282
+ onAnalyticsEvent?.("ai_collection_generate_start", {
2283
+ mode
2284
+ });
2285
+ try {
2286
+ const collectionsContext = existingCollections.map((c2) => ({
2287
+ slug: c2.slug,
2288
+ name: c2.name,
2289
+ properties: c2.properties,
2290
+ propertiesOrder: c2.propertiesOrder
2291
+ }));
2292
+ const result = await generateCollection({
2293
+ prompt: prompt.trim(),
2294
+ existingCollections: collectionsContext.slice(0, 30),
2295
+ ...existingCollection && {
2296
+ existingCollection: {
2297
+ slug: existingCollection.slug,
2298
+ name: existingCollection.name,
2299
+ properties: existingCollection.properties,
2300
+ propertiesOrder: existingCollection.propertiesOrder
2301
+ }
2302
+ }
2303
+ });
2304
+ onGenerated(result.collection, result.operations);
2305
+ setMenuOpen(false);
2306
+ setPrompt("");
2307
+ onAnalyticsEvent?.("ai_collection_generate_success", {
2308
+ mode,
2309
+ operationsCount: result.operations?.length
2310
+ });
2311
+ snackbarController.open({
2312
+ type: "success",
2313
+ message: existingCollection ? "Collection updated with AI suggestions" : "Collection generated successfully"
2314
+ });
2315
+ } catch (e) {
2316
+ console.error("Error generating collection:", e);
2317
+ const errorMessage = e instanceof CollectionGenerationApiError ? e.message : "Failed to generate collection. Please try again.";
2318
+ setError(errorMessage);
2319
+ onAnalyticsEvent?.("ai_collection_generate_error", {
2320
+ mode,
2321
+ error: errorMessage
2322
+ });
2323
+ snackbarController.open({
2324
+ type: "error",
2325
+ message: errorMessage
2326
+ });
2327
+ } finally {
2328
+ setLoading(false);
2329
+ }
2330
+ };
2331
+ const handleKeyDown = (e_0) => {
2332
+ if (e_0.key === "Enter" && !e_0.shiftKey) {
2333
+ e_0.preventDefault();
2334
+ handleGenerate();
2335
+ }
2336
+ };
2337
+ const tooltipTitle = configController?.readOnly ? configController.readOnlyReason || "Collection generation is disabled" : void 0;
2338
+ const defaultTrigger = showLabel ? /* @__PURE__ */ jsx(Tooltip, { title: tooltipTitle, asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "text", size, disabled: loading || configController?.readOnly, startIcon: loading ? /* @__PURE__ */ jsx(CircularProgress, { size: "smallest" }) : /* @__PURE__ */ jsx(AIIcon, { size: "small" }), children: "AI Assist" }) }) : /* @__PURE__ */ jsx(Tooltip, { title: tooltipTitle, asChild: true, children: /* @__PURE__ */ jsx(IconButton, { size, disabled: loading || configController?.readOnly, "aria-label": "AI Assist", children: loading ? /* @__PURE__ */ jsx(CircularProgress, { size: "smallest" }) : /* @__PURE__ */ jsx(AIIcon, { size: "small" }) }) });
2339
+ return /* @__PURE__ */ jsx(Menu, { open: menuOpen, onOpenChange: (open) => {
2340
+ setMenuOpen(open);
2341
+ if (!open) {
2342
+ setError(null);
2343
+ }
2344
+ }, trigger: trigger ?? defaultTrigger, children: /* @__PURE__ */ jsxs("div", { className: "p-4 flex flex-col gap-3 min-w-[360px] max-w-[480px]", children: [
2345
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
2346
+ /* @__PURE__ */ jsx(AIIcon, { size: "small" }),
2347
+ /* @__PURE__ */ jsx(Typography, { variant: "subtitle2", children: existingCollection ? "Modify Collection with AI" : "Generate Collection with AI" })
2348
+ ] }),
2349
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "secondary", children: existingCollection ? "Describe the changes you want to make to this collection." : "Describe the collection you want to create." }),
2350
+ /* @__PURE__ */ jsx(TextField, { size: "small", multiline: true, autoFocus: true, className: "w-full text-text-primary dark:text-text-primary-dark", value: prompt, onChange: (e_1) => setPrompt(e_1.target.value), onKeyDown: handleKeyDown, placeholder: existingCollection ? "e.g., Add a thumbnail image field with storage, make price required..." : "e.g., Create a products collection with name, price, description, and category...", disabled: loading }),
2351
+ error && /* @__PURE__ */ jsx(Typography, { variant: "caption", className: "text-red-500", children: error }),
2352
+ /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
2353
+ /* @__PURE__ */ jsx(Button, { variant: "text", size: "small", onClick: () => setMenuOpen(false), disabled: loading, children: "Cancel" }),
2354
+ /* @__PURE__ */ jsx(Button, { variant: "filled", size: "small", onClick: handleGenerate, disabled: !prompt.trim() || loading, startIcon: loading ? /* @__PURE__ */ jsx(CircularProgress, { size: "smallest" }) : void 0, children: loading ? "Generating..." : "Generate" })
2355
+ ] })
2356
+ ] }) });
2357
+ }
2358
+ function CollectionEditorWelcomeView(t0) {
2359
+ const $ = c(90);
2360
+ const {
2361
+ parentCollection,
2362
+ onContinue,
2363
+ existingCollectionPaths,
2364
+ generateCollection,
2365
+ onAnalyticsEvent,
2366
+ unmappedTables,
2367
+ onImportFromTable
2368
+ } = t0;
2369
+ const {
2370
+ pathSuggestions
2371
+ } = useCollectionEditorController();
2372
+ let t1;
2373
+ if ($[0] !== pathSuggestions) {
2374
+ t1 = pathSuggestions ?? [];
2375
+ $[0] = pathSuggestions;
2376
+ $[1] = t1;
2377
+ } else {
2378
+ t1 = $[1];
2379
+ }
2380
+ let t2;
2381
+ if ($[2] !== existingCollectionPaths) {
2382
+ t2 = (s) => !(existingCollectionPaths ?? []).find((c2) => c2.trim().toLowerCase() === s.trim().toLowerCase());
2383
+ $[2] = existingCollectionPaths;
2384
+ $[3] = t2;
2385
+ } else {
2386
+ t2 = $[3];
2387
+ }
2388
+ const filteredSuggestions = t1.filter(t2);
2389
+ const {
2390
+ setFieldValue,
2391
+ setValues
2392
+ } = useFormex();
2393
+ const [jsonImportOpen, setJsonImportOpen] = useState(false);
2394
+ const [importingTable, setImportingTable] = useState(null);
2395
+ let t3;
2396
+ if ($[4] !== unmappedTables) {
2397
+ t3 = unmappedTables ?? [];
2398
+ $[4] = unmappedTables;
2399
+ $[5] = t3;
2400
+ } else {
2401
+ t3 = $[5];
2402
+ }
2403
+ let T0;
2404
+ let t4;
2405
+ let t5;
2406
+ let t6;
2407
+ let t7;
2408
+ let t8;
2409
+ let t9;
2410
+ if ($[6] !== existingCollectionPaths || $[7] !== importingTable || $[8] !== onContinue || $[9] !== onImportFromTable || $[10] !== parentCollection || $[11] !== setFieldValue || $[12] !== t3) {
2411
+ let t102;
2412
+ if ($[20] !== existingCollectionPaths) {
2413
+ t102 = (t) => !(existingCollectionPaths ?? []).find((c_0) => c_0.trim().toLowerCase() === t.trim().toLowerCase());
2414
+ $[20] = existingCollectionPaths;
2415
+ $[21] = t102;
2416
+ } else {
2417
+ t102 = $[21];
2418
+ }
2419
+ const filteredUnmappedTables = t3.filter(t102);
2420
+ t9 = "overflow-auto my-auto";
2421
+ T0 = Container;
2422
+ t4 = "4xl";
2423
+ t5 = "flex flex-col gap-4 p-8 m-auto";
2424
+ if ($[22] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
2425
+ t6 = /* @__PURE__ */ jsx("div", { className: "flex flex-row py-2 pt-3 items-center", children: /* @__PURE__ */ jsx(Typography, { variant: "h4", className: "grow", children: "New collection" }) });
2426
+ $[22] = t6;
2427
+ } else {
2428
+ t6 = $[22];
2429
+ }
2430
+ if ($[23] !== parentCollection) {
2431
+ t7 = parentCollection && /* @__PURE__ */ jsx(Chip, { colorScheme: "teal", children: /* @__PURE__ */ jsxs(Typography, { variant: "caption", children: [
2432
+ "This is a subcollection of ",
2433
+ /* @__PURE__ */ jsx("b", { children: parentCollection.name })
2434
+ ] }) });
2435
+ $[23] = parentCollection;
2436
+ $[24] = t7;
2437
+ } else {
2438
+ t7 = $[24];
2439
+ }
2440
+ t8 = filteredUnmappedTables.length > 0 && /* @__PURE__ */ jsxs("div", { className: "my-2", children: [
2441
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "secondary", children: "● Import from an existing database table:" }),
2442
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-x-2 gap-y-1 items-center my-2 min-h-7", children: filteredUnmappedTables.map((tableName) => /* @__PURE__ */ jsxs(Chip, { colorScheme: "purple", onClick: () => {
2443
+ if (onImportFromTable) {
2444
+ setImportingTable(tableName);
2445
+ onImportFromTable(tableName);
2446
+ } else {
2447
+ setFieldValue("name", prettifyIdentifier(tableName));
2448
+ setFieldValue("id", tableName);
2449
+ setFieldValue("path", tableName);
2450
+ onContinue();
2451
+ }
2452
+ }, size: "small", children: [
2453
+ /* @__PURE__ */ jsx(TableIcon, { size: iconSize.smallest }),
2454
+ importingTable === tableName ? "Loading..." : tableName
2455
+ ] }, tableName)) })
2456
+ ] });
2457
+ $[6] = existingCollectionPaths;
2458
+ $[7] = importingTable;
2459
+ $[8] = onContinue;
2460
+ $[9] = onImportFromTable;
2461
+ $[10] = parentCollection;
2462
+ $[11] = setFieldValue;
2463
+ $[12] = t3;
2464
+ $[13] = T0;
2465
+ $[14] = t4;
2466
+ $[15] = t5;
2467
+ $[16] = t6;
2468
+ $[17] = t7;
2469
+ $[18] = t8;
2470
+ $[19] = t9;
2471
+ } else {
2472
+ T0 = $[13];
2473
+ t4 = $[14];
2474
+ t5 = $[15];
2475
+ t6 = $[16];
2476
+ t7 = $[17];
2477
+ t8 = $[18];
2478
+ t9 = $[19];
2479
+ }
2480
+ const t10 = (filteredSuggestions ?? []).length > 0 && /* @__PURE__ */ jsxs("div", { className: "my-2", children: [
2481
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "secondary", children: "● Use one of the existing paths in your database:" }),
2482
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-x-2 gap-y-1 items-center my-2 min-h-7", children: filteredSuggestions?.map((suggestion, index) => /* @__PURE__ */ jsx(Chip, { colorScheme: "cyan", onClick: () => {
2483
+ setFieldValue("name", prettifyIdentifier(suggestion));
2484
+ setFieldValue("id", suggestion);
2485
+ setFieldValue("path", suggestion);
2486
+ setFieldValue("properties", void 0);
2487
+ onContinue();
2488
+ }, size: "small", children: suggestion }, suggestion)) })
2489
+ ] });
2490
+ let t11;
2491
+ if ($[25] !== generateCollection || $[26] !== onAnalyticsEvent || $[27] !== onContinue || $[28] !== setValues) {
2492
+ t11 = generateCollection && /* @__PURE__ */ jsxs("div", { className: "my-2", children: [
2493
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "secondary", className: "mb-2", children: "● Describe your collection to AI:" }),
2494
+ /* @__PURE__ */ jsx(AICollectionGeneratorPopover, { onGenerated: (generatedCollection) => {
2495
+ setValues(generatedCollection);
2496
+ onContinue();
2497
+ }, generateCollection, onAnalyticsEvent, trigger: /* @__PURE__ */ jsx(Button, { variant: "filled", color: "neutral", startIcon: /* @__PURE__ */ jsx(AIIcon, { size: "small" }), children: "Generate with AI" }) })
2498
+ ] });
2499
+ $[25] = generateCollection;
2500
+ $[26] = onAnalyticsEvent;
2501
+ $[27] = onContinue;
2502
+ $[28] = setValues;
2503
+ $[29] = t11;
2504
+ } else {
2505
+ t11 = $[29];
2506
+ }
2507
+ let t12;
2508
+ if ($[30] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
2509
+ t12 = /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "secondary", className: "mb-2", children: "● Create from JSON configuration:" });
2510
+ $[30] = t12;
2511
+ } else {
2512
+ t12 = $[30];
2513
+ }
2514
+ let t13;
2515
+ if ($[31] !== setJsonImportOpen) {
2516
+ t13 = () => setJsonImportOpen(true);
2517
+ $[31] = setJsonImportOpen;
2518
+ $[32] = t13;
2519
+ } else {
2520
+ t13 = $[32];
2521
+ }
2522
+ let t14;
2523
+ if ($[33] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
2524
+ t14 = /* @__PURE__ */ jsx(CodeIcon, { size: iconSize.small });
2525
+ $[33] = t14;
2526
+ } else {
2527
+ t14 = $[33];
2528
+ }
2529
+ let t15;
2530
+ if ($[34] !== t13) {
2531
+ t15 = /* @__PURE__ */ jsx(Button, { variant: "filled", color: "neutral", onClick: t13, startIcon: t14, children: "Paste JSON Configuration" });
2532
+ $[34] = t13;
2533
+ $[35] = t15;
2534
+ } else {
2535
+ t15 = $[35];
2536
+ }
2537
+ let t16;
2538
+ if ($[36] !== setJsonImportOpen) {
2539
+ t16 = () => setJsonImportOpen(false);
2540
+ $[36] = setJsonImportOpen;
2541
+ $[37] = t16;
2542
+ } else {
2543
+ t16 = $[37];
2544
+ }
2545
+ let t17;
2546
+ if ($[38] !== onContinue || $[39] !== setValues) {
2547
+ t17 = (collection) => {
2548
+ setValues(collection);
2549
+ onContinue();
2550
+ };
2551
+ $[38] = onContinue;
2552
+ $[39] = setValues;
2553
+ $[40] = t17;
2554
+ } else {
2555
+ t17 = $[40];
2556
+ }
2557
+ let t18;
2558
+ if ($[41] !== jsonImportOpen || $[42] !== t16 || $[43] !== t17) {
2559
+ t18 = /* @__PURE__ */ jsx(CollectionJsonImportDialog, { open: jsonImportOpen, onClose: t16, onImport: t17 });
2560
+ $[41] = jsonImportOpen;
2561
+ $[42] = t16;
2562
+ $[43] = t17;
2563
+ $[44] = t18;
2564
+ } else {
2565
+ t18 = $[44];
2566
+ }
2567
+ let t19;
2568
+ if ($[45] !== t15 || $[46] !== t18) {
2569
+ t19 = /* @__PURE__ */ jsxs("div", { className: "my-2", children: [
2570
+ t12,
2571
+ t15,
2572
+ t18
2573
+ ] });
2574
+ $[45] = t15;
2575
+ $[46] = t18;
2576
+ $[47] = t19;
2577
+ } else {
2578
+ t19 = $[47];
2579
+ }
2580
+ let t20;
2581
+ if ($[48] !== t11 || $[49] !== t19) {
2582
+ t20 = /* @__PURE__ */ jsxs("div", { className: "flex flex-row gap-8", children: [
2583
+ t11,
2584
+ t19
2585
+ ] });
2586
+ $[48] = t11;
2587
+ $[49] = t19;
2588
+ $[50] = t20;
2589
+ } else {
2590
+ t20 = $[50];
2591
+ }
2592
+ let t21;
2593
+ if ($[51] !== onContinue || $[52] !== parentCollection) {
2594
+ t21 = !parentCollection && /* @__PURE__ */ jsxs("div", { children: [
2595
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "secondary", className: "mb-2", children: "● Create a collection from a file (csv, json, xls, xslx...)" }),
2596
+ /* @__PURE__ */ jsx(ImportFileUpload, { onDataAdded: (data, propertiesOrder) => onContinue(data, propertiesOrder) })
2597
+ ] });
2598
+ $[51] = onContinue;
2599
+ $[52] = parentCollection;
2600
+ $[53] = t21;
2601
+ } else {
2602
+ t21 = $[53];
2603
+ }
2604
+ let t22;
2605
+ if ($[54] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
2606
+ t22 = /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "secondary", children: "● Select a template:" });
2607
+ $[54] = t22;
2608
+ } else {
2609
+ t22 = $[54];
2610
+ }
2611
+ let t23;
2612
+ if ($[55] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
2613
+ t23 = /* @__PURE__ */ jsx(ShoppingCartIcon, { size: iconSize.small });
2614
+ $[55] = t23;
2615
+ } else {
2616
+ t23 = $[55];
2617
+ }
2618
+ let t24;
2619
+ if ($[56] !== onContinue || $[57] !== setValues) {
2620
+ t24 = /* @__PURE__ */ jsx(TemplateButton, { title: "Products", subtitle: "A collection of products with images, prices and stock", icon: t23, onClick: () => {
2621
+ setValues(productsCollectionTemplate);
2622
+ onContinue();
2623
+ } });
2624
+ $[56] = onContinue;
2625
+ $[57] = setValues;
2626
+ $[58] = t24;
2627
+ } else {
2628
+ t24 = $[58];
2629
+ }
2630
+ let t25;
2631
+ if ($[59] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
2632
+ t25 = /* @__PURE__ */ jsx(UserIcon, { size: iconSize.small });
2633
+ $[59] = t25;
2634
+ } else {
2635
+ t25 = $[59];
2636
+ }
2637
+ let t26;
2638
+ if ($[60] !== onContinue || $[61] !== setValues) {
2639
+ t26 = /* @__PURE__ */ jsx(TemplateButton, { title: "Users", subtitle: "A collection of users with emails, names and roles", icon: t25, onClick: () => {
2640
+ setValues(usersCollectionTemplate);
2641
+ onContinue();
2642
+ } });
2643
+ $[60] = onContinue;
2644
+ $[61] = setValues;
2645
+ $[62] = t26;
2646
+ } else {
2647
+ t26 = $[62];
2648
+ }
2649
+ let t27;
2650
+ if ($[63] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
2651
+ t27 = /* @__PURE__ */ jsx(FileTextIcon, { size: iconSize.small });
2652
+ $[63] = t27;
2653
+ } else {
2654
+ t27 = $[63];
2655
+ }
2656
+ let t28;
2657
+ if ($[64] !== onContinue || $[65] !== setValues) {
2658
+ t28 = /* @__PURE__ */ jsx(TemplateButton, { title: "Blog posts", subtitle: "A collection of blog posts with images, authors and complex content", icon: t27, onClick: () => {
2659
+ setValues(blogCollectionTemplate);
2660
+ onContinue();
2661
+ } });
2662
+ $[64] = onContinue;
2663
+ $[65] = setValues;
2664
+ $[66] = t28;
2665
+ } else {
2666
+ t28 = $[66];
2667
+ }
2668
+ let t29;
2669
+ if ($[67] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
2670
+ t29 = /* @__PURE__ */ jsx(FileIcon, { size: iconSize.small });
2671
+ $[67] = t29;
2672
+ } else {
2673
+ t29 = $[67];
2674
+ }
2675
+ let t30;
2676
+ if ($[68] !== onContinue || $[69] !== setValues) {
2677
+ t30 = /* @__PURE__ */ jsx(TemplateButton, { title: "Pages", subtitle: "A collection of pages with images, authors and complex content", icon: t29, onClick: () => {
2678
+ setValues(pagesCollectionTemplate);
2679
+ onContinue();
2680
+ } });
2681
+ $[68] = onContinue;
2682
+ $[69] = setValues;
2683
+ $[70] = t30;
2684
+ } else {
2685
+ t30 = $[70];
2686
+ }
2687
+ let t31;
2688
+ if ($[71] !== t24 || $[72] !== t26 || $[73] !== t28 || $[74] !== t30) {
2689
+ t31 = /* @__PURE__ */ jsxs("div", { className: "my-2", children: [
2690
+ t22,
2691
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
2692
+ t24,
2693
+ t26,
2694
+ t28,
2695
+ t30
2696
+ ] })
2697
+ ] });
2698
+ $[71] = t24;
2699
+ $[72] = t26;
2700
+ $[73] = t28;
2701
+ $[74] = t30;
2702
+ $[75] = t31;
2703
+ } else {
2704
+ t31 = $[75];
2705
+ }
2706
+ let t32;
2707
+ if ($[76] !== T0 || $[77] !== t10 || $[78] !== t20 || $[79] !== t21 || $[80] !== t31 || $[81] !== t4 || $[82] !== t5 || $[83] !== t6 || $[84] !== t7 || $[85] !== t8) {
2708
+ t32 = /* @__PURE__ */ jsxs(T0, { maxWidth: t4, className: t5, children: [
2709
+ t6,
2710
+ t7,
2711
+ t8,
2712
+ t10,
2713
+ t20,
2714
+ t21,
2715
+ t31
2716
+ ] });
2717
+ $[76] = T0;
2718
+ $[77] = t10;
2719
+ $[78] = t20;
2720
+ $[79] = t21;
2721
+ $[80] = t31;
2722
+ $[81] = t4;
2723
+ $[82] = t5;
2724
+ $[83] = t6;
2725
+ $[84] = t7;
2726
+ $[85] = t8;
2727
+ $[86] = t32;
2728
+ } else {
2729
+ t32 = $[86];
2730
+ }
2731
+ let t33;
2732
+ if ($[87] !== t32 || $[88] !== t9) {
2733
+ t33 = /* @__PURE__ */ jsx("div", { className: t9, children: t32 });
2734
+ $[87] = t32;
2735
+ $[88] = t9;
2736
+ $[89] = t33;
2737
+ } else {
2738
+ t33 = $[89];
2739
+ }
2740
+ return t33;
2741
+ }
2742
+ function TemplateButton(t0) {
2743
+ const $ = c(10);
2744
+ const {
2745
+ title,
2746
+ subtitle,
2747
+ icon,
2748
+ onClick
2749
+ } = t0;
2750
+ let t1;
2751
+ if ($[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
2752
+ t1 = cls("my-2 rounded-md border px-4 py-3 focus:outline-none transition ease-in-out duration-150 flex flex-row gap-4 items-center", "text-text-secondary dark:text-text-secondary-dark", "hover:border-primary-dark hover:text-primary-dark dark:hover:text-primary focus:ring-primary hover:ring-1 hover:ring-primary", "border-surface-400 dark:border-surface-600 ");
2753
+ $[0] = t1;
2754
+ } else {
2755
+ t1 = $[0];
2756
+ }
2757
+ let t2;
2758
+ if ($[1] !== title) {
2759
+ t2 = /* @__PURE__ */ jsx("div", { className: "flex flex-col items-start", children: /* @__PURE__ */ jsx(Typography, { variant: "subtitle2", children: title }) });
2760
+ $[1] = title;
2761
+ $[2] = t2;
2762
+ } else {
2763
+ t2 = $[2];
2764
+ }
2765
+ let t3;
2766
+ if ($[3] !== icon || $[4] !== onClick || $[5] !== t2) {
2767
+ t3 = /* @__PURE__ */ jsxs(Card, { onClick, className: t1, children: [
2768
+ icon,
2769
+ t2
2770
+ ] });
2771
+ $[3] = icon;
2772
+ $[4] = onClick;
2773
+ $[5] = t2;
2774
+ $[6] = t3;
2775
+ } else {
2776
+ t3 = $[6];
2777
+ }
2778
+ let t4;
2779
+ if ($[7] !== subtitle || $[8] !== t3) {
2780
+ t4 = /* @__PURE__ */ jsx(Tooltip, { title: subtitle, asChild: true, children: t3 });
2781
+ $[7] = subtitle;
2782
+ $[8] = t3;
2783
+ $[9] = t4;
2784
+ } else {
2785
+ t4 = $[9];
2786
+ }
2787
+ return t4;
2788
+ }
2789
+ function CollectionEditorImportMapping(t0) {
2790
+ const $ = c(32);
2791
+ const {
2792
+ importConfig,
2793
+ propertyConfigs
2794
+ } = t0;
2795
+ const {
2796
+ setFieldValue,
2797
+ setFieldTouched,
2798
+ values
2799
+ } = useFormex();
2800
+ const [selectedProperty, setSelectedProperty] = useState(void 0);
2801
+ let t1;
2802
+ if ($[0] !== values.propertiesOrder) {
2803
+ t1 = values.propertiesOrder ? {
2804
+ "": values.propertiesOrder
2805
+ } : {};
2806
+ $[0] = values.propertiesOrder;
2807
+ $[1] = t1;
2808
+ } else {
2809
+ t1 = $[1];
2810
+ }
2811
+ const currentPropertiesOrderRef = React__default.useRef(t1);
2812
+ const propertyKey = selectedProperty ? selectedProperty.id : void 0;
2813
+ const property = selectedProperty || void 0;
2814
+ let t2;
2815
+ if ($[2] !== importConfig || $[3] !== setFieldTouched || $[4] !== setFieldValue || $[5] !== values) {
2816
+ t2 = (t32) => {
2817
+ const {
2818
+ id,
2819
+ property: property_0,
2820
+ previousId,
2821
+ namespace
2822
+ } = t32;
2823
+ const fullId = id ? getFullId(id, namespace) : void 0;
2824
+ const propertyPath = fullId ? idToPropertiesPath(fullId) : void 0;
2825
+ const getCurrentPropertiesOrder = (namespace_0) => {
2826
+ if (!namespace_0) {
2827
+ return currentPropertiesOrderRef.current[""];
2828
+ }
2829
+ return currentPropertiesOrderRef.current[namespace_0] ?? getIn(values, namespaceToPropertiesOrderPath(namespace_0));
2830
+ };
2831
+ const updatePropertiesOrder = (newPropertiesOrder, namespace_1) => {
2832
+ const propertiesOrderPath = namespaceToPropertiesOrderPath(namespace_1);
2833
+ setFieldValue(propertiesOrderPath, newPropertiesOrder, false);
2834
+ currentPropertiesOrderRef.current[namespace_1 ?? ""] = newPropertiesOrder;
2835
+ };
2836
+ if (previousId && previousId !== id) {
2837
+ const previousFullId = getFullId(previousId, namespace);
2838
+ const previousPropertyPath = idToPropertiesPath(previousFullId);
2839
+ const currentPropertiesOrder = getCurrentPropertiesOrder(namespace);
2840
+ const newPropertiesOrder_0 = currentPropertiesOrder.map((p) => p === previousId ? id : p).filter(_temp$2);
2841
+ updatePropertiesOrder(newPropertiesOrder_0, namespace);
2842
+ const newHeadersMapping = {
2843
+ ...importConfig.headersMapping
2844
+ };
2845
+ Object.keys(newHeadersMapping).forEach((key) => {
2846
+ if (newHeadersMapping[key] === previousId) {
2847
+ newHeadersMapping[key] = id ?? "";
2848
+ }
2849
+ });
2850
+ importConfig.setHeadersMapping(newHeadersMapping);
2851
+ setFieldValue(previousPropertyPath, void 0, false);
2852
+ setFieldTouched(previousPropertyPath, false, false);
2853
+ }
2854
+ if (propertyPath) {
2855
+ setFieldValue(propertyPath, property_0, false);
2856
+ setFieldTouched(propertyPath, true, false);
2857
+ }
2858
+ };
2859
+ $[2] = importConfig;
2860
+ $[3] = setFieldTouched;
2861
+ $[4] = setFieldValue;
2862
+ $[5] = values;
2863
+ $[6] = t2;
2864
+ } else {
2865
+ t2 = $[6];
2866
+ }
2867
+ const onPropertyChanged = t2;
2868
+ let t3;
2869
+ if ($[7] !== importConfig.importData || $[8] !== setFieldTouched || $[9] !== setFieldValue) {
2870
+ t3 = async (t42) => {
2871
+ const {
2872
+ id: id_0,
2873
+ importKey,
2874
+ property: property_1,
2875
+ namespace: namespace_2
2876
+ } = t42;
2877
+ const fullId_0 = id_0 ? getFullId(id_0, namespace_2) : void 0;
2878
+ const propertyPath_0 = fullId_0 ? idToPropertiesPath(fullId_0) : void 0;
2879
+ const propertyData = importConfig.importData.map((d) => getIn(d, importKey));
2880
+ const inferredNewProperty = {
2881
+ ...buildPropertyFromData(propertyData, property_1, getInferenceType)
2882
+ };
2883
+ if (propertyPath_0) {
2884
+ if (inferredNewProperty) {
2885
+ setFieldValue(propertyPath_0, inferredNewProperty, false);
2886
+ } else {
2887
+ setFieldValue(propertyPath_0, property_1, false);
2888
+ }
2889
+ setFieldTouched(propertyPath_0, true, false);
2890
+ }
2891
+ };
2892
+ $[7] = importConfig.importData;
2893
+ $[8] = setFieldTouched;
2894
+ $[9] = setFieldValue;
2895
+ $[10] = t3;
2896
+ } else {
2897
+ t3 = $[10];
2898
+ }
2899
+ const onPropertyTypeChanged = t3;
2900
+ let t4;
2901
+ if ($[11] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
2902
+ t4 = /* @__PURE__ */ jsx(Typography, { variant: "h6", className: "my-4 ml-3.5", children: "Data property mapping" });
2903
+ $[11] = t4;
2904
+ } else {
2905
+ t4 = $[11];
2906
+ }
2907
+ const t5 = values.properties;
2908
+ let t6;
2909
+ if ($[12] !== onPropertyTypeChanged || $[13] !== propertyConfigs || $[14] !== setFieldValue) {
2910
+ t6 = (t72) => {
2911
+ const {
2912
+ property: property_2,
2913
+ propertyKey: propertyKey_0,
2914
+ importKey: importKey_0,
2915
+ isIdColumn
2916
+ } = t72;
2917
+ if (isIdColumn) {
2918
+ return /* @__PURE__ */ jsx(Typography, { children: " This column will be used as ID" });
2919
+ }
2920
+ return /* @__PURE__ */ jsx(ImportNewPropertyFieldPreview, { property: property_2, propertyKey: propertyKey_0, onPropertyNameChanged: (propertyKey_1, value) => setFieldValue(`properties.${propertyKey_1}.name`, value, false), onEditClick: () => {
2921
+ if (!propertyKey_0 || !property_2) {
2922
+ return;
2923
+ }
2924
+ setSelectedProperty({
2925
+ ...property_2,
2926
+ id: propertyKey_0
2927
+ });
2928
+ }, propertyTypeView: /* @__PURE__ */ jsx(PropertySelect, { property: property_2, disabled: false, onPropertyChanged: (props) => onPropertyTypeChanged({
2929
+ ...props,
2930
+ importKey: importKey_0
2931
+ }), propertyKey: propertyKey_0, propertyConfigs }) });
2932
+ };
2933
+ $[12] = onPropertyTypeChanged;
2934
+ $[13] = propertyConfigs;
2935
+ $[14] = setFieldValue;
2936
+ $[15] = t6;
2937
+ } else {
2938
+ t6 = $[15];
2939
+ }
2940
+ let t7;
2941
+ if ($[16] !== importConfig || $[17] !== t5 || $[18] !== t6) {
2942
+ t7 = /* @__PURE__ */ jsxs(Container, { maxWidth: "6xl", className: "flex flex-col gap-4 p-8 m-auto", children: [
2943
+ t4,
2944
+ /* @__PURE__ */ jsx(DataNewPropertiesMapping, { importConfig, destinationProperties: t5, buildPropertyView: t6 })
2945
+ ] });
2946
+ $[16] = importConfig;
2947
+ $[17] = t5;
2948
+ $[18] = t6;
2949
+ $[19] = t7;
2950
+ } else {
2951
+ t7 = $[19];
2952
+ }
2953
+ const t8 = selectedProperty !== void 0;
2954
+ let t10;
2955
+ let t9;
2956
+ if ($[20] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
2957
+ t9 = () => {
2958
+ setSelectedProperty(void 0);
2959
+ };
2960
+ t10 = () => {
2961
+ setSelectedProperty(void 0);
2962
+ };
2963
+ $[20] = t10;
2964
+ $[21] = t9;
2965
+ } else {
2966
+ t10 = $[20];
2967
+ t9 = $[21];
2968
+ }
2969
+ let t11;
2970
+ if ($[22] !== onPropertyChanged || $[23] !== property || $[24] !== propertyConfigs || $[25] !== propertyKey || $[26] !== t8) {
2971
+ t11 = /* @__PURE__ */ jsx(PropertyFormDialog, { open: t8, propertyKey, property, inArray: false, autoUpdateId: false, onPropertyChanged, allowDataInference: false, onOkClicked: t9, onCancel: t10, autoOpenTypeSelect: false, existingProperty: false, propertyConfigs });
2972
+ $[22] = onPropertyChanged;
2973
+ $[23] = property;
2974
+ $[24] = propertyConfigs;
2975
+ $[25] = propertyKey;
2976
+ $[26] = t8;
2977
+ $[27] = t11;
2978
+ } else {
2979
+ t11 = $[27];
2980
+ }
2981
+ let t12;
2982
+ if ($[28] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
2983
+ t12 = /* @__PURE__ */ jsx("div", { style: {
2984
+ height: "52px"
2985
+ } });
2986
+ $[28] = t12;
2987
+ } else {
2988
+ t12 = $[28];
2989
+ }
2990
+ let t13;
2991
+ if ($[29] !== t11 || $[30] !== t7) {
2992
+ t13 = /* @__PURE__ */ jsxs("div", { className: "overflow-auto my-auto", children: [
2993
+ t7,
2994
+ t11,
2995
+ t12
2996
+ ] });
2997
+ $[29] = t11;
2998
+ $[30] = t7;
2999
+ $[31] = t13;
3000
+ } else {
3001
+ t13 = $[31];
3002
+ }
3003
+ return t13;
3004
+ }
3005
+ function _temp$2(p_0) {
3006
+ return p_0 !== void 0;
3007
+ }
3008
+ function PropertySelect(t0) {
3009
+ const $ = c(24);
3010
+ const {
3011
+ property,
3012
+ onPropertyChanged,
3013
+ propertyKey,
3014
+ propertyConfigs,
3015
+ disabled
3016
+ } = t0;
3017
+ let t1;
3018
+ if ($[0] !== property) {
3019
+ t1 = property ? getFieldId(property) : null;
3020
+ $[0] = property;
3021
+ $[1] = t1;
3022
+ } else {
3023
+ t1 = $[1];
3024
+ }
3025
+ const fieldId = t1;
3026
+ let t2;
3027
+ if ($[2] !== property || $[3] !== propertyConfigs) {
3028
+ t2 = property ? getFieldConfig(property, propertyConfigs) : null;
3029
+ $[2] = property;
3030
+ $[3] = propertyConfigs;
3031
+ $[4] = t2;
3032
+ } else {
3033
+ t2 = $[4];
3034
+ }
3035
+ const widget = t2;
3036
+ const [selectOpen, setSelectOpen] = useState(false);
3037
+ const t3 = property && widget ? `${widget?.name} - ${property.type}` : void 0;
3038
+ const t4 = selectOpen ? false : void 0;
3039
+ const t5 = !widget;
3040
+ const t6 = fieldId ?? "";
3041
+ let t7;
3042
+ if ($[5] !== widget) {
3043
+ t7 = (value) => {
3044
+ if (!widget) {
3045
+ return null;
3046
+ }
3047
+ return /* @__PURE__ */ jsx(PropertyConfigBadge, { propertyConfig: widget });
3048
+ };
3049
+ $[5] = widget;
3050
+ $[6] = t7;
3051
+ } else {
3052
+ t7 = $[6];
3053
+ }
3054
+ let t8;
3055
+ if ($[7] !== onPropertyChanged || $[8] !== property || $[9] !== propertyConfigs || $[10] !== propertyKey) {
3056
+ t8 = (newSelectedWidgetId) => {
3057
+ const newProperty = updatePropertyFromWidget(property, newSelectedWidgetId, propertyConfigs);
3058
+ if (!propertyKey) {
3059
+ return;
3060
+ }
3061
+ onPropertyChanged({
3062
+ id: propertyKey,
3063
+ property: newProperty,
3064
+ previousId: propertyKey,
3065
+ namespace: void 0
3066
+ });
3067
+ };
3068
+ $[7] = onPropertyChanged;
3069
+ $[8] = property;
3070
+ $[9] = propertyConfigs;
3071
+ $[10] = propertyKey;
3072
+ $[11] = t8;
3073
+ } else {
3074
+ t8 = $[11];
3075
+ }
3076
+ let t9;
3077
+ if ($[12] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
3078
+ t9 = Object.entries(supportedFields).map(_temp2);
3079
+ $[12] = t9;
3080
+ } else {
3081
+ t9 = $[12];
3082
+ }
3083
+ let t10;
3084
+ if ($[13] !== disabled || $[14] !== selectOpen || $[15] !== t5 || $[16] !== t6 || $[17] !== t7 || $[18] !== t8) {
3085
+ t10 = /* @__PURE__ */ jsx(Select, { open: selectOpen, onOpenChange: setSelectOpen, invisible: true, className: "w-full", disabled, error: t5, fullWidth: true, value: t6, placeholder: "Select a property widget", position: "item-aligned", renderValue: t7, onValueChange: t8, children: t9 });
3086
+ $[13] = disabled;
3087
+ $[14] = selectOpen;
3088
+ $[15] = t5;
3089
+ $[16] = t6;
3090
+ $[17] = t7;
3091
+ $[18] = t8;
3092
+ $[19] = t10;
3093
+ } else {
3094
+ t10 = $[19];
3095
+ }
3096
+ let t11;
3097
+ if ($[20] !== t10 || $[21] !== t3 || $[22] !== t4) {
3098
+ t11 = /* @__PURE__ */ jsx(Tooltip, { title: t3, open: t4, children: t10 });
3099
+ $[20] = t10;
3100
+ $[21] = t3;
3101
+ $[22] = t4;
3102
+ $[23] = t11;
3103
+ } else {
3104
+ t11 = $[23];
3105
+ }
3106
+ return t11;
3107
+ }
3108
+ function _temp2(t0) {
3109
+ const [key, widget_0] = t0;
3110
+ return /* @__PURE__ */ jsx(ImportPropertySelectItem, { value: key, optionDisabled: false, propertyConfig: widget_0, existing: false }, key);
3111
+ }
3112
+ function ImportPropertySelectItem(t0) {
3113
+ const $ = c(19);
3114
+ const {
3115
+ value,
3116
+ optionDisabled,
3117
+ propertyConfig,
3118
+ existing
3119
+ } = t0;
3120
+ const t1 = optionDisabled ? "w-full" : "";
3121
+ let t2;
3122
+ if ($[0] !== t1) {
3123
+ t2 = cls("flex flex-row items-center text-base min-h-[48px]", t1);
3124
+ $[0] = t1;
3125
+ $[1] = t2;
3126
+ } else {
3127
+ t2 = $[1];
3128
+ }
3129
+ let t3;
3130
+ if ($[2] !== propertyConfig) {
3131
+ t3 = /* @__PURE__ */ jsx("div", { className: "mr-8", children: /* @__PURE__ */ jsx(PropertyConfigBadge, { propertyConfig }) });
3132
+ $[2] = propertyConfig;
3133
+ $[3] = t3;
3134
+ } else {
3135
+ t3 = $[3];
3136
+ }
3137
+ let t4;
3138
+ if ($[4] !== propertyConfig.name) {
3139
+ t4 = /* @__PURE__ */ jsx("div", { children: propertyConfig.name });
3140
+ $[4] = propertyConfig.name;
3141
+ $[5] = t4;
3142
+ } else {
3143
+ t4 = $[5];
3144
+ }
3145
+ const t5 = existing && optionDisabled ? "You can only switch to widgets that use the same data type" : propertyConfig.description;
3146
+ let t6;
3147
+ if ($[6] !== t5) {
3148
+ t6 = /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "disabled", className: "max-w-sm", children: t5 });
3149
+ $[6] = t5;
3150
+ $[7] = t6;
3151
+ } else {
3152
+ t6 = $[7];
3153
+ }
3154
+ let t7;
3155
+ if ($[8] !== t4 || $[9] !== t6) {
3156
+ t7 = /* @__PURE__ */ jsxs("div", { children: [
3157
+ t4,
3158
+ t6
3159
+ ] });
3160
+ $[8] = t4;
3161
+ $[9] = t6;
3162
+ $[10] = t7;
3163
+ } else {
3164
+ t7 = $[10];
3165
+ }
3166
+ let t8;
3167
+ if ($[11] !== t2 || $[12] !== t3 || $[13] !== t7) {
3168
+ t8 = /* @__PURE__ */ jsxs("div", { className: t2, children: [
3169
+ t3,
3170
+ t7
3171
+ ] });
3172
+ $[11] = t2;
3173
+ $[12] = t3;
3174
+ $[13] = t7;
3175
+ $[14] = t8;
3176
+ } else {
3177
+ t8 = $[14];
3178
+ }
3179
+ let t9;
3180
+ if ($[15] !== optionDisabled || $[16] !== t8 || $[17] !== value) {
3181
+ t9 = /* @__PURE__ */ jsx(SelectItem, { value, disabled: optionDisabled, className: "flex flex-row items-center", children: t8 });
3182
+ $[15] = optionDisabled;
3183
+ $[16] = t8;
3184
+ $[17] = value;
3185
+ $[18] = t9;
3186
+ } else {
3187
+ t9 = $[18];
3188
+ }
3189
+ return t9;
3190
+ }
3191
+ function CollectionEditorImportDataPreview(t0) {
3192
+ const $ = c(20);
3193
+ const {
3194
+ importConfig,
3195
+ properties,
3196
+ propertiesOrder
3197
+ } = t0;
3198
+ const authController = useAuthController();
3199
+ const registry = useCollectionRegistryController();
3200
+ const [loading, setLoading] = useState(false);
3201
+ let t1;
3202
+ if ($[0] !== authController || $[1] !== importConfig || $[2] !== properties || $[3] !== registry) {
3203
+ t1 = async function loadEntities2() {
3204
+ const mappedData = importConfig.importData.map((d) => convertDataToEntity(authController, registry, d, importConfig.idColumn, importConfig.headersMapping, properties, "TEMP_PATH", importConfig.defaultValues));
3205
+ importConfig.setEntities(mappedData);
3206
+ };
3207
+ $[0] = authController;
3208
+ $[1] = importConfig;
3209
+ $[2] = properties;
3210
+ $[3] = registry;
3211
+ $[4] = t1;
3212
+ } else {
3213
+ t1 = $[4];
3214
+ }
3215
+ const loadEntities = t1;
3216
+ let t2;
3217
+ if ($[5] !== loadEntities) {
3218
+ t2 = () => {
3219
+ loadEntities().finally(() => setLoading(false));
3220
+ };
3221
+ $[5] = loadEntities;
3222
+ $[6] = t2;
3223
+ } else {
3224
+ t2 = $[6];
3225
+ }
3226
+ let t3;
3227
+ if ($[7] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
3228
+ t3 = [];
3229
+ $[7] = t3;
3230
+ } else {
3231
+ t3 = $[7];
3232
+ }
3233
+ useEffect(t2, t3);
3234
+ const selectionController = useSelectionController();
3235
+ if (loading) {
3236
+ let t42;
3237
+ if ($[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
3238
+ t42 = /* @__PURE__ */ jsx(CircularProgressCenter, {});
3239
+ $[8] = t42;
3240
+ } else {
3241
+ t42 = $[8];
3242
+ }
3243
+ return t42;
3244
+ }
3245
+ let t4;
3246
+ if ($[9] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
3247
+ t4 = /* @__PURE__ */ jsxs("div", { children: [
3248
+ /* @__PURE__ */ jsx(Typography, { variant: "subtitle2", children: "Imported data preview" }),
3249
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", children: "Entities with the same id will be overwritten" })
3250
+ ] });
3251
+ $[9] = t4;
3252
+ } else {
3253
+ t4 = $[9];
3254
+ }
3255
+ let t5;
3256
+ if ($[10] !== importConfig.entities) {
3257
+ t5 = {
3258
+ data: importConfig.entities,
3259
+ dataLoading: false,
3260
+ noMoreToLoad: false
3261
+ };
3262
+ $[10] = importConfig.entities;
3263
+ $[11] = t5;
3264
+ } else {
3265
+ t5 = $[11];
3266
+ }
3267
+ let t6;
3268
+ if ($[12] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
3269
+ t6 = /* @__PURE__ */ jsx("div", { className: "h-12" });
3270
+ $[12] = t6;
3271
+ } else {
3272
+ t6 = $[12];
3273
+ }
3274
+ let t7;
3275
+ if ($[13] !== propertiesOrder) {
3276
+ t7 = propertiesOrder.map(_temp$1);
3277
+ $[13] = propertiesOrder;
3278
+ $[14] = t7;
3279
+ } else {
3280
+ t7 = $[14];
3281
+ }
3282
+ let t8;
3283
+ if ($[15] !== properties || $[16] !== selectionController || $[17] !== t5 || $[18] !== t7) {
3284
+ t8 = /* @__PURE__ */ jsx(EntityCollectionTable, { title: t4, tableController: t5, endAdornment: t6, filterable: false, sortable: false, selectionController, displayedColumnIds: t7, openEntityMode: "side_panel", properties, enablePopupIcon: false });
3285
+ $[15] = properties;
3286
+ $[16] = selectionController;
3287
+ $[17] = t5;
3288
+ $[18] = t7;
3289
+ $[19] = t8;
3290
+ } else {
3291
+ t8 = $[19];
3292
+ }
3293
+ return t8;
3294
+ }
3295
+ function _temp$1(p) {
3296
+ return {
3297
+ key: p,
3298
+ disabled: false
3299
+ };
3300
+ }
3301
+ function cleanPropertiesFromImport(properties, parentSlug = "") {
3302
+ const result = Object.keys(properties).reduce((acc, key) => {
3303
+ const property = properties[key];
3304
+ const slug = slugify(key);
3305
+ const fullSlug = parentSlug ? `${parentSlug}.${slug}` : slug;
3306
+ if (property.type === "map" && property.properties) {
3307
+ const slugifiedResult = cleanPropertiesFromImport(property.properties, fullSlug);
3308
+ return {
3309
+ headersMapping: {
3310
+ ...acc.headersMapping,
3311
+ [key]: fullSlug
3312
+ },
3313
+ properties: {
3314
+ ...acc.properties,
3315
+ [slug]: {
3316
+ ...property,
3317
+ properties: slugifiedResult.properties,
3318
+ propertiesOrder: Object.keys(slugifiedResult.properties)
3319
+ }
3320
+ }
3321
+ };
3322
+ }
3323
+ const updatedProperties = {
3324
+ ...acc.properties,
3325
+ [slug]: property
3326
+ };
3327
+ const headersMapping = {
3328
+ ...acc.headersMapping,
3329
+ [key]: fullSlug
3330
+ };
3331
+ return {
3332
+ headersMapping,
3333
+ properties: updatedProperties
3334
+ };
3335
+ }, {
3336
+ headersMapping: {},
3337
+ properties: {}
3338
+ });
3339
+ const firstKey = Object.keys(result.headersMapping)?.[0];
3340
+ let idColumn;
3341
+ if (firstKey?.includes("id") || firstKey?.includes("key")) {
3342
+ idColumn = firstKey;
3343
+ }
3344
+ return {
3345
+ ...result,
3346
+ idColumn
3347
+ };
3348
+ }
3349
+ function sanitizeSqlIdentifier(name) {
3350
+ if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {
3351
+ throw new Error(`Invalid SQL identifier: "${name}". Only letters, digits, and underscores are allowed.`);
3352
+ }
3353
+ return `"${name}"`;
3354
+ }
3355
+ function CollectionRLSTab() {
3356
+ const {
3357
+ values,
3358
+ setFieldValue
3359
+ } = useFormex();
3360
+ const [editingPolicy, setEditingPolicy] = useState(null);
3361
+ const rules = values.securityRules || [];
3362
+ const {
3363
+ databaseAdmin
3364
+ } = useRebaseContext();
3365
+ const [dbPolicies, setDbPolicies] = useState([]);
3366
+ const [isLoadingDb, setIsLoadingDb] = useState(false);
3367
+ useEffect(() => {
3368
+ const fetchLivePolicies = async () => {
3369
+ const tableName = values.id || values.table || values.alias;
3370
+ if (!tableName || !databaseAdmin?.executeSql) return;
3371
+ setIsLoadingDb(true);
3372
+ try {
3373
+ const safeTableName = sanitizeSqlIdentifier(tableName);
3374
+ const quotedName = safeTableName.slice(1, -1);
3375
+ const sql = `
3376
+ SELECT policyname, permissive, roles, cmd, qual, with_check
3377
+ FROM pg_policies
3378
+ WHERE tablename = '${quotedName}' AND schemaname NOT IN ('information_schema', 'pg_catalog');
3379
+ `;
3380
+ const result = await databaseAdmin.executeSql(sql);
3381
+ const extractRows = (res) => {
3382
+ if (res && typeof res === "object" && "rows" in res && Array.isArray(res.rows)) {
3383
+ return res.rows;
3384
+ }
3385
+ if (Array.isArray(res)) return res;
3386
+ return [];
3387
+ };
3388
+ const pRows = extractRows(result);
3389
+ const policies = pRows.map((p) => {
3390
+ let parsedRoles = [];
3391
+ const r = p.roles || p.ROLES;
3392
+ if (Array.isArray(r)) {
3393
+ parsedRoles = r;
3394
+ } else if (typeof r === "string") {
3395
+ parsedRoles = r.replace(/^{|}$/g, "").split(",").map((s) => s.trim());
3396
+ }
3397
+ return {
3398
+ policyname: p.policyname || p.POLICYNAME || "",
3399
+ tablename: tableName,
3400
+ permissive: p.permissive || p.PERMISSIVE || "PERMISSIVE",
3401
+ roles: parsedRoles,
3402
+ cmd: p.cmd || p.CMD || "ALL",
3403
+ qual: p.qual || p.QUAL || null,
3404
+ with_check: p.with_check || p.WITH_CHECK || null
3405
+ };
3406
+ });
3407
+ setDbPolicies(policies);
3408
+ } catch (e) {
3409
+ console.error("Failed to fetch DB policies", e);
3410
+ } finally {
3411
+ setIsLoadingDb(false);
3412
+ }
3413
+ };
3414
+ fetchLivePolicies();
3415
+ }, [databaseAdmin, values.id, values.table, values.alias]);
3416
+ const unmappedPolicies = dbPolicies.filter((dp) => !rules.some((r_0) => r_0.name === dp.policyname));
3417
+ const handleSave = async (newPolicy) => {
3418
+ const rule = {
3419
+ name: newPolicy.policyname ?? "",
3420
+ operation: newPolicy.cmd?.toLowerCase(),
3421
+ mode: newPolicy.permissive?.toLowerCase(),
3422
+ using: newPolicy.qual || void 0,
3423
+ withCheck: newPolicy.with_check || void 0,
3424
+ roles: newPolicy.roles
3425
+ };
3426
+ let newRules;
3427
+ if (editingPolicy === "new") {
3428
+ newRules = [...rules, rule];
3429
+ } else {
3430
+ newRules = rules.map((r_1) => r_1.name === editingPolicy.policyname ? rule : r_1);
3431
+ }
3432
+ setFieldValue("securityRules", newRules);
3433
+ setEditingPolicy(null);
3434
+ };
3435
+ return /* @__PURE__ */ jsx("div", { className: "overflow-auto my-auto", children: /* @__PURE__ */ jsxs(Container, { maxWidth: "4xl", className: "flex flex-col gap-4 p-8 m-auto", children: [
3436
+ /* @__PURE__ */ jsxs("div", { className: "w-full flex flex-col", children: [
3437
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-8", children: [
3438
+ /* @__PURE__ */ jsx(Typography, { variant: "h5", children: "Row Level Security" }),
3439
+ /* @__PURE__ */ jsx(Button, { variant: "filled", color: "neutral", onClick: () => setEditingPolicy("new"), children: "CREATE POLICY" })
3440
+ ] }),
3441
+ rules.length === 0 ? /* @__PURE__ */ jsx("div", { className: "flex-grow flex items-center justify-center text-text-disabled py-12", children: /* @__PURE__ */ jsx(Typography, { variant: "body2", children: "No RLS policies defined for this collection." }) }) : /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-3", children: rules.map((rule_0) => /* @__PURE__ */ jsxs(Paper, { className: "p-4 border border-transparent hover:border-surface-200 dark:hover:border-surface-700 rounded-lg flex flex-col sm:flex-row sm:items-center justify-between gap-4 transition-colors bg-white dark:bg-surface-800 shadow-sm", children: [
3442
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5 min-w-0", children: [
3443
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
3444
+ /* @__PURE__ */ jsx(KeyIcon, { size: iconSize.smallest, className: "text-text-disabled dark:text-text-disabled-dark shrink-0" }),
3445
+ /* @__PURE__ */ jsx(Typography, { variant: "subtitle2", className: "truncate", children: rule_0.name })
3446
+ ] }),
3447
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-2 text-xs pl-6 overflow-x-auto hide-scrollbar", children: [
3448
+ /* @__PURE__ */ jsxs(Chip, { size: "small", className: "bg-surface-100 dark:bg-surface-900 text-text-secondary border-none", children: [
3449
+ "Action: ",
3450
+ rule_0.operation || "ALL"
3451
+ ] }),
3452
+ /* @__PURE__ */ jsxs(Chip, { size: "small", className: "bg-surface-100 dark:bg-surface-900 text-text-secondary border-none", children: [
3453
+ "Roles: ",
3454
+ Array.isArray(rule_0.roles) ? rule_0.roles.join(", ") : rule_0.roles
3455
+ ] })
3456
+ ] })
3457
+ ] }),
3458
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 sm:gap-2 shrink-0", children: [
3459
+ /* @__PURE__ */ jsx(Button, { size: "small", variant: "text", onClick: () => setEditingPolicy({
3460
+ policyname: rule_0.name,
3461
+ tablename: values.id || values.table || values.alias || "your_table",
3462
+ permissive: (rule_0.mode || "permissive").toUpperCase(),
3463
+ cmd: (rule_0.operation || "ALL").toUpperCase(),
3464
+ roles: rule_0.roles || ["public"],
3465
+ qual: rule_0.using || null,
3466
+ with_check: rule_0.withCheck || null
3467
+ }), children: "EDIT" }),
3468
+ /* @__PURE__ */ jsx(IconButton, { size: "small", onClick: () => {
3469
+ setFieldValue("securityRules", rules.filter((r_2) => r_2.name !== rule_0.name));
3470
+ }, children: /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest, className: "text-text-secondary dark:text-text-secondary-dark hover:text-red-500 dark:hover:text-red-500 transition-colors" }) })
3471
+ ] })
3472
+ ] }, rule_0.name)) }),
3473
+ isLoadingDb && unmappedPolicies.length === 0 && /* @__PURE__ */ jsx("div", { className: "flex justify-center mt-8", children: /* @__PURE__ */ jsx(CircularProgress, { size: "small" }) }),
3474
+ !isLoadingDb && unmappedPolicies.length > 0 && /* @__PURE__ */ jsxs("div", { className: "mt-12 flex flex-col gap-4", children: [
3475
+ /* @__PURE__ */ jsx(Typography, { variant: "h6", className: "text-text-secondary", children: "Unmapped Database Policies" }),
3476
+ /* @__PURE__ */ jsx(Typography, { variant: "body2", className: "text-text-secondary opacity-80 -mt-2", children: "These policies exist in your Postgres database but are not mapped to this collection's codebase configuration." }),
3477
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-3", children: unmappedPolicies.map((dp_0) => /* @__PURE__ */ jsxs(Paper, { className: "p-4 border border-orange-200 dark:border-orange-900/50 bg-orange-50/50 dark:bg-orange-900/10 rounded-lg flex flex-col sm:flex-row sm:items-center justify-between gap-4 transition-colors", children: [
3478
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5 min-w-0", children: [
3479
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
3480
+ /* @__PURE__ */ jsx(KeyIcon, { size: iconSize.smallest, className: "text-orange-500 shrink-0" }),
3481
+ /* @__PURE__ */ jsx(Typography, { variant: "subtitle2", className: "truncate", children: dp_0.policyname }),
3482
+ /* @__PURE__ */ jsx(Tooltip, { title: "This policy is live in the database but missing from your codebase schema.", children: /* @__PURE__ */ jsx("div", { className: "px-1.5 py-0.5 rounded text-[10px] uppercase bg-orange-500/10 text-orange-600 border border-orange-500/20 shrink-0", children: "DB Only" }) })
3483
+ ] }),
3484
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-2 text-xs pl-6 overflow-x-auto hide-scrollbar", children: [
3485
+ /* @__PURE__ */ jsxs(Chip, { size: "small", className: "bg-white dark:bg-surface-900 text-text-secondary border-none", children: [
3486
+ "Action: ",
3487
+ dp_0.cmd || "ALL"
3488
+ ] }),
3489
+ /* @__PURE__ */ jsxs(Chip, { size: "small", className: "bg-white dark:bg-surface-900 text-text-secondary border-none", children: [
3490
+ "Roles: ",
3491
+ Array.isArray(dp_0.roles) ? dp_0.roles.join(", ") : dp_0.roles
3492
+ ] })
3493
+ ] })
3494
+ ] }),
3495
+ /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1 sm:gap-2 shrink-0", children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "outlined", color: "primary", onClick: () => {
3496
+ const rule_1 = {
3497
+ name: dp_0.policyname,
3498
+ operation: dp_0.cmd?.toLowerCase(),
3499
+ mode: dp_0.permissive?.toLowerCase(),
3500
+ using: dp_0.qual || void 0,
3501
+ withCheck: dp_0.with_check || void 0,
3502
+ roles: dp_0.roles
3503
+ };
3504
+ setFieldValue("securityRules", [...rules, rule_1]);
3505
+ }, children: "Import to codebase" }) })
3506
+ ] }, dp_0.policyname)) })
3507
+ ] })
3508
+ ] }),
3509
+ /* @__PURE__ */ jsx(Dialog, { open: !!editingPolicy, onOpenChange: (open) => !open && setEditingPolicy(null), maxWidth: "4xl", children: editingPolicy && /* @__PURE__ */ jsx(InlinePolicyEditor, { policy: editingPolicy === "new" ? void 0 : editingPolicy, table: values.id || values.table || values.alias || "your_table", onSave: handleSave, onCancel: () => setEditingPolicy(null) }) })
3510
+ ] }) });
3511
+ }
3512
+ const COMMAND_OPTIONS = ["ALL", "SELECT", "INSERT", "UPDATE", "DELETE"];
3513
+ const ROLE_OPTIONS = ["public", "authenticated", "anon", "admin"];
3514
+ function InlinePolicyEditor(t0) {
3515
+ const $ = c(63);
3516
+ const {
3517
+ policy,
3518
+ table,
3519
+ onSave,
3520
+ onCancel
3521
+ } = t0;
3522
+ const [name, setName] = useState(policy?.policyname || "");
3523
+ const [behavior, setBehavior] = useState(policy?.permissive || "PERMISSIVE");
3524
+ const [command, setCommand] = useState(policy?.cmd || "ALL");
3525
+ let t1;
3526
+ if ($[0] !== policy) {
3527
+ t1 = policy?.roles ? Array.isArray(policy.roles) ? policy.roles : [policy.roles] : ["public"];
3528
+ $[0] = policy;
3529
+ $[1] = t1;
3530
+ } else {
3531
+ t1 = $[1];
3532
+ }
3533
+ const [roles, setRoles] = useState(t1);
3534
+ const [usingExpr, setUsingExpr] = useState(policy?.qual || "");
3535
+ const [checkExpr, setCheckExpr] = useState(policy?.with_check || "");
3536
+ const showCheck = command === "ALL" || command === "INSERT" || command === "UPDATE";
3537
+ const t2 = policy ? "Edit Policy" : "Create Policy";
3538
+ let t3;
3539
+ if ($[2] !== table) {
3540
+ t3 = /* @__PURE__ */ jsxs("div", { className: "text-sm font-normal text-text-secondary dark:text-text-secondary-dark tracking-wide mt-1", children: [
3541
+ "Define RLS rules for ",
3542
+ /* @__PURE__ */ jsxs("span", { className: "font-mono text-primary bg-primary-bg dark:bg-primary-bg-dark px-1 py-0.5 rounded", children: [
3543
+ "public.",
3544
+ table
3545
+ ] })
3546
+ ] });
3547
+ $[2] = table;
3548
+ $[3] = t3;
3549
+ } else {
3550
+ t3 = $[3];
3551
+ }
3552
+ let t4;
3553
+ if ($[4] !== t2 || $[5] !== t3) {
3554
+ t4 = /* @__PURE__ */ jsxs(DialogTitle, { variant: "h6", children: [
3555
+ t2,
3556
+ t3
3557
+ ] });
3558
+ $[4] = t2;
3559
+ $[5] = t3;
3560
+ $[6] = t4;
3561
+ } else {
3562
+ t4 = $[6];
3563
+ }
3564
+ let t5;
3565
+ if ($[7] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
3566
+ t5 = cls("p-4 md:p-6 flex flex-col gap-6 bg-white dark:bg-surface-800 border-none sm:border-solid rounded-none sm:rounded-xl", defaultBorderMixin);
3567
+ $[7] = t5;
3568
+ } else {
3569
+ t5 = $[7];
3570
+ }
3571
+ let t6;
3572
+ if ($[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
3573
+ t6 = /* @__PURE__ */ jsx(Typography, { variant: "caption", className: "uppercase tracking-wider text-text-secondary", children: "Policy Name" });
3574
+ $[8] = t6;
3575
+ } else {
3576
+ t6 = $[8];
3577
+ }
3578
+ let t7;
3579
+ if ($[9] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
3580
+ t7 = (e) => setName(e.target.value);
3581
+ $[9] = t7;
3582
+ } else {
3583
+ t7 = $[9];
3584
+ }
3585
+ let t8;
3586
+ if ($[10] !== name) {
3587
+ t8 = /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
3588
+ t6,
3589
+ /* @__PURE__ */ jsx(TextField, { value: name, onChange: t7, placeholder: "e.g. allow_read_all" })
3590
+ ] });
3591
+ $[10] = name;
3592
+ $[11] = t8;
3593
+ } else {
3594
+ t8 = $[11];
3595
+ }
3596
+ let t9;
3597
+ if ($[12] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
3598
+ t9 = /* @__PURE__ */ jsx(Typography, { variant: "caption", className: "uppercase tracking-wider text-text-secondary", children: "Behavior" });
3599
+ $[12] = t9;
3600
+ } else {
3601
+ t9 = $[12];
3602
+ }
3603
+ let t10;
3604
+ if ($[13] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
3605
+ t10 = (val) => setBehavior(val);
3606
+ $[13] = t10;
3607
+ } else {
3608
+ t10 = $[13];
3609
+ }
3610
+ let t11;
3611
+ let t12;
3612
+ if ($[14] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
3613
+ t11 = /* @__PURE__ */ jsx(SelectItem, { value: "PERMISSIVE", children: "Permissive" });
3614
+ t12 = /* @__PURE__ */ jsx(SelectItem, { value: "RESTRICTIVE", children: "Restrictive" });
3615
+ $[14] = t11;
3616
+ $[15] = t12;
3617
+ } else {
3618
+ t11 = $[14];
3619
+ t12 = $[15];
3620
+ }
3621
+ let t13;
3622
+ if ($[16] !== behavior) {
3623
+ t13 = /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
3624
+ t9,
3625
+ /* @__PURE__ */ jsxs(Select, { value: behavior, onValueChange: t10, position: "item-aligned", children: [
3626
+ t11,
3627
+ t12
3628
+ ] })
3629
+ ] });
3630
+ $[16] = behavior;
3631
+ $[17] = t13;
3632
+ } else {
3633
+ t13 = $[17];
3634
+ }
3635
+ let t14;
3636
+ if ($[18] !== t13 || $[19] !== t8) {
3637
+ t14 = /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
3638
+ t8,
3639
+ t13
3640
+ ] });
3641
+ $[18] = t13;
3642
+ $[19] = t8;
3643
+ $[20] = t14;
3644
+ } else {
3645
+ t14 = $[20];
3646
+ }
3647
+ let t15;
3648
+ if ($[21] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
3649
+ t15 = /* @__PURE__ */ jsx(Typography, { variant: "caption", className: "uppercase tracking-wider text-text-secondary", children: "Command" });
3650
+ $[21] = t15;
3651
+ } else {
3652
+ t15 = $[21];
3653
+ }
3654
+ let t16;
3655
+ if ($[22] !== command) {
3656
+ t16 = COMMAND_OPTIONS.map((cmd) => /* @__PURE__ */ jsx(Button, { size: "small", variant: command === cmd ? "filled" : "text", color: "neutral", onClick: () => setCommand(cmd), children: cmd }, cmd));
3657
+ $[22] = command;
3658
+ $[23] = t16;
3659
+ } else {
3660
+ t16 = $[23];
3661
+ }
3662
+ let t17;
3663
+ if ($[24] !== t16) {
3664
+ t17 = /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
3665
+ t15,
3666
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5", children: t16 })
3667
+ ] });
3668
+ $[24] = t16;
3669
+ $[25] = t17;
3670
+ } else {
3671
+ t17 = $[25];
3672
+ }
3673
+ let t18;
3674
+ if ($[26] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
3675
+ t18 = /* @__PURE__ */ jsx(Typography, { variant: "caption", className: "uppercase tracking-wider text-text-secondary", children: "Target Roles" });
3676
+ $[26] = t18;
3677
+ } else {
3678
+ t18 = $[26];
3679
+ }
3680
+ let t19;
3681
+ if ($[27] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
3682
+ t19 = ROLE_OPTIONS.map(_temp);
3683
+ $[27] = t19;
3684
+ } else {
3685
+ t19 = $[27];
3686
+ }
3687
+ let t20;
3688
+ if ($[28] !== roles) {
3689
+ t20 = /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
3690
+ t18,
3691
+ /* @__PURE__ */ jsx(MultiSelect, { size: "small", value: roles, onValueChange: setRoles, placeholder: "Select roles", children: t19 })
3692
+ ] });
3693
+ $[28] = roles;
3694
+ $[29] = t20;
3695
+ } else {
3696
+ t20 = $[29];
3697
+ }
3698
+ let t21;
3699
+ if ($[30] !== command || $[31] !== usingExpr) {
3700
+ t21 = command !== "INSERT" && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
3701
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", className: "uppercase tracking-wider text-text-secondary", children: "USING expression" }),
3702
+ /* @__PURE__ */ jsx(TextField, { value: usingExpr, onChange: (e_0) => setUsingExpr(e_0.target.value), placeholder: "e.g. auth.uid() = user_id" })
3703
+ ] });
3704
+ $[30] = command;
3705
+ $[31] = usingExpr;
3706
+ $[32] = t21;
3707
+ } else {
3708
+ t21 = $[32];
3709
+ }
3710
+ let t22;
3711
+ if ($[33] !== checkExpr || $[34] !== showCheck) {
3712
+ t22 = showCheck && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
3713
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", className: "uppercase tracking-wider text-text-secondary", children: "WITH CHECK expression" }),
3714
+ /* @__PURE__ */ jsx(TextField, { value: checkExpr, onChange: (e_1) => setCheckExpr(e_1.target.value), placeholder: "e.g. auth.uid() = user_id" })
3715
+ ] });
3716
+ $[33] = checkExpr;
3717
+ $[34] = showCheck;
3718
+ $[35] = t22;
3719
+ } else {
3720
+ t22 = $[35];
3721
+ }
3722
+ let t23;
3723
+ if ($[36] !== t14 || $[37] !== t17 || $[38] !== t20 || $[39] !== t21 || $[40] !== t22) {
3724
+ t23 = /* @__PURE__ */ jsx(DialogContent, { className: "p-4 md:p-6 border-t dark:border-surface-700 bg-surface-50 dark:bg-surface-800", includeMargin: false, children: /* @__PURE__ */ jsxs(Paper, { className: t5, children: [
3725
+ t14,
3726
+ t17,
3727
+ t20,
3728
+ t21,
3729
+ t22
3730
+ ] }) });
3731
+ $[36] = t14;
3732
+ $[37] = t17;
3733
+ $[38] = t20;
3734
+ $[39] = t21;
3735
+ $[40] = t22;
3736
+ $[41] = t23;
3737
+ } else {
3738
+ t23 = $[41];
3739
+ }
3740
+ let t24;
3741
+ if ($[42] !== onCancel) {
3742
+ t24 = /* @__PURE__ */ jsx(Button, { size: "small", variant: "text", color: "neutral", onClick: onCancel, children: "Cancel" });
3743
+ $[42] = onCancel;
3744
+ $[43] = t24;
3745
+ } else {
3746
+ t24 = $[43];
3747
+ }
3748
+ const t25 = !name;
3749
+ let t26;
3750
+ if ($[44] !== behavior || $[45] !== checkExpr || $[46] !== command || $[47] !== name || $[48] !== onSave || $[49] !== roles || $[50] !== showCheck || $[51] !== usingExpr) {
3751
+ t26 = () => onSave({
3752
+ policyname: name,
3753
+ permissive: behavior,
3754
+ cmd: command,
3755
+ roles,
3756
+ qual: usingExpr,
3757
+ with_check: showCheck ? checkExpr : null
3758
+ });
3759
+ $[44] = behavior;
3760
+ $[45] = checkExpr;
3761
+ $[46] = command;
3762
+ $[47] = name;
3763
+ $[48] = onSave;
3764
+ $[49] = roles;
3765
+ $[50] = showCheck;
3766
+ $[51] = usingExpr;
3767
+ $[52] = t26;
3768
+ } else {
3769
+ t26 = $[52];
3770
+ }
3771
+ let t27;
3772
+ if ($[53] !== t25 || $[54] !== t26) {
3773
+ t27 = /* @__PURE__ */ jsx(Button, { size: "small", variant: "filled", color: "primary", disabled: t25, onClick: t26, children: "Save" });
3774
+ $[53] = t25;
3775
+ $[54] = t26;
3776
+ $[55] = t27;
3777
+ } else {
3778
+ t27 = $[55];
3779
+ }
3780
+ let t28;
3781
+ if ($[56] !== t24 || $[57] !== t27) {
3782
+ t28 = /* @__PURE__ */ jsxs(DialogActions, { children: [
3783
+ t24,
3784
+ t27
3785
+ ] });
3786
+ $[56] = t24;
3787
+ $[57] = t27;
3788
+ $[58] = t28;
3789
+ } else {
3790
+ t28 = $[58];
3791
+ }
3792
+ let t29;
3793
+ if ($[59] !== t23 || $[60] !== t28 || $[61] !== t4) {
3794
+ t29 = /* @__PURE__ */ jsxs(Fragment, { children: [
3795
+ t4,
3796
+ t23,
3797
+ t28
3798
+ ] });
3799
+ $[59] = t23;
3800
+ $[60] = t28;
3801
+ $[61] = t4;
3802
+ $[62] = t29;
3803
+ } else {
3804
+ t29 = $[62];
3805
+ }
3806
+ return t29;
3807
+ }
3808
+ function _temp(r) {
3809
+ return /* @__PURE__ */ jsx(MultiSelectItem, { value: r, children: r }, r);
3810
+ }
3811
+ function pgTypeToRebaseProperty(column) {
3812
+ const {
3813
+ column_name,
3814
+ data_type,
3815
+ udt_name,
3816
+ is_nullable,
3817
+ column_default,
3818
+ enum_values
3819
+ } = column;
3820
+ const required = is_nullable === "NO";
3821
+ const prettifiedName = prettifyIdentifier(column_name);
3822
+ const isAutoId = column_default != null && (column_default.includes("nextval") || column_default.includes("gen_random_uuid") || column_default.includes("uuid_generate") || column_default.includes("identity"));
3823
+ if (data_type === "USER-DEFINED" && enum_values && enum_values.length > 0) {
3824
+ return {
3825
+ type: "string",
3826
+ name: prettifiedName,
3827
+ enum: enum_values.map((v) => ({
3828
+ id: v,
3829
+ label: prettifyIdentifier(v)
3830
+ })),
3831
+ validation: required ? {
3832
+ required: true
3833
+ } : void 0
3834
+ };
3835
+ }
3836
+ const dt = data_type.toLowerCase();
3837
+ switch (dt) {
3838
+ case "character varying":
3839
+ case "varchar":
3840
+ case "text":
3841
+ case "char":
3842
+ case "character":
3843
+ case "citext": {
3844
+ let colType = "varchar";
3845
+ if (dt === "text" || dt === "citext") colType = "text";
3846
+ if (dt === "char" || dt === "character") colType = "char";
3847
+ const prop = {
3848
+ type: "string",
3849
+ name: prettifiedName,
3850
+ columnType: colType,
3851
+ validation: required ? {
3852
+ required: true
3853
+ } : void 0
3854
+ };
3855
+ if (isAutoId) {
3856
+ prop.isId = "manual";
3857
+ }
3858
+ return prop;
3859
+ }
3860
+ case "uuid": {
3861
+ const prop = {
3862
+ type: "string",
3863
+ name: prettifiedName,
3864
+ validation: required ? {
3865
+ required: true
3866
+ } : void 0
3867
+ };
3868
+ if (isAutoId) {
3869
+ prop.isId = "uuid";
3870
+ }
3871
+ return prop;
3872
+ }
3873
+ case "integer":
3874
+ case "bigint":
3875
+ case "smallint": {
3876
+ const colType = dt === "bigint" ? "bigint" : "integer";
3877
+ const prop = {
3878
+ type: "number",
3879
+ name: prettifiedName,
3880
+ columnType: colType,
3881
+ validation: {
3882
+ ...required ? {
3883
+ required: true
3884
+ } : {},
3885
+ integer: true
3886
+ }
3887
+ };
3888
+ if (isAutoId) {
3889
+ prop.isId = "increment";
3890
+ }
3891
+ return prop;
3892
+ }
3893
+ case "serial":
3894
+ case "bigserial":
3895
+ case "smallserial": {
3896
+ const colType = dt === "bigserial" ? "bigserial" : "serial";
3897
+ return {
3898
+ type: "number",
3899
+ name: prettifiedName,
3900
+ columnType: colType,
3901
+ isId: "increment",
3902
+ validation: {
3903
+ ...required ? {
3904
+ required: true
3905
+ } : {},
3906
+ integer: true
3907
+ }
3908
+ };
3909
+ }
3910
+ case "numeric":
3911
+ case "decimal":
3912
+ case "real":
3913
+ case "double precision": {
3914
+ let colType = "numeric";
3915
+ if (dt === "real") colType = "real";
3916
+ if (dt === "double precision") colType = "double precision";
3917
+ return {
3918
+ type: "number",
3919
+ name: prettifiedName,
3920
+ columnType: colType,
3921
+ validation: required ? {
3922
+ required: true
3923
+ } : void 0
3924
+ };
3925
+ }
3926
+ case "boolean":
3927
+ return {
3928
+ type: "boolean",
3929
+ name: prettifiedName,
3930
+ validation: required ? {
3931
+ required: true
3932
+ } : void 0
3933
+ };
3934
+ case "timestamp with time zone":
3935
+ case "timestamp without time zone":
3936
+ case "timestamp":
3937
+ case "timestamptz":
3938
+ case "date":
3939
+ case "time with time zone":
3940
+ case "time without time zone":
3941
+ case "time": {
3942
+ let colType = "timestamp";
3943
+ if (dt.startsWith("date")) colType = "date";
3944
+ if (dt.startsWith("time ") || dt === "time") colType = "time";
3945
+ return {
3946
+ type: "date",
3947
+ name: prettifiedName,
3948
+ columnType: colType,
3949
+ validation: required ? {
3950
+ required: true
3951
+ } : void 0
3952
+ };
3953
+ }
3954
+ case "jsonb":
3955
+ case "json":
3956
+ return {
3957
+ type: "map",
3958
+ name: prettifiedName,
3959
+ columnType: dt === "jsonb" ? "jsonb" : "json",
3960
+ keyValue: true,
3961
+ properties: {}
3962
+ };
3963
+ case "array":
3964
+ case "ARRAY":
3965
+ return {
3966
+ type: "array",
3967
+ name: prettifiedName,
3968
+ of: {
3969
+ type: "string"
3970
+ }
3971
+ };
3972
+ default:
3973
+ return {
3974
+ type: "string",
3975
+ name: prettifiedName,
3976
+ validation: required ? {
3977
+ required: true
3978
+ } : void 0
3979
+ };
3980
+ }
3981
+ }
3982
+ function buildCollectionFromTableMetadata(tableName, metadata) {
3983
+ const properties = {};
3984
+ const propertiesOrder = [];
3985
+ const relations = [];
3986
+ const securityRules = [];
3987
+ for (const column of metadata.columns) {
3988
+ const property = pgTypeToRebaseProperty(column);
3989
+ if (property) {
3990
+ const propRecord = property;
3991
+ Object.keys(propRecord).forEach((key) => propRecord[key] === void 0 && delete propRecord[key]);
3992
+ properties[column.column_name] = property;
3993
+ propertiesOrder.push(column.column_name);
3994
+ }
3995
+ }
3996
+ if (metadata.foreignKeys) {
3997
+ for (const fk of metadata.foreignKeys) {
3998
+ const relName = fk.column_name.endsWith("_id") ? fk.column_name.substring(0, fk.column_name.length - 3) : fk.column_name;
3999
+ relations.push({
4000
+ id: fk.column_name,
4001
+ relationName: relName,
4002
+ target: fk.foreign_table_name,
4003
+ // Will be hydrated later
4004
+ cardinality: "one",
4005
+ direction: "owning",
4006
+ localKey: fk.column_name
4007
+ });
4008
+ }
4009
+ }
4010
+ if (metadata.junctions) {
4011
+ for (const junction of metadata.junctions) {
4012
+ const relName = junction.target_table_name;
4013
+ relations.push({
4014
+ id: junction.target_table_name + "_relation",
4015
+ relationName: relName,
4016
+ target: junction.target_table_name,
4017
+ // Will be hydrated later
4018
+ cardinality: "many",
4019
+ direction: "owning",
4020
+ through: {
4021
+ table: junction.junction_table_name,
4022
+ sourceColumn: junction.source_column_name,
4023
+ targetColumn: junction.target_column_name
4024
+ }
4025
+ });
4026
+ }
4027
+ }
4028
+ if (metadata.policies) {
4029
+ for (const policy of metadata.policies) {
4030
+ let operations = [];
4031
+ switch (policy.cmd) {
4032
+ case "ALL":
4033
+ operations = ["read", "create", "update", "delete"];
4034
+ break;
4035
+ case "SELECT":
4036
+ operations = ["read"];
4037
+ break;
4038
+ case "INSERT":
4039
+ operations = ["create"];
4040
+ break;
4041
+ case "UPDATE":
4042
+ operations = ["update"];
4043
+ break;
4044
+ case "DELETE":
4045
+ operations = ["delete"];
4046
+ break;
4047
+ }
4048
+ securityRules.push({
4049
+ name: policy.policy_name,
4050
+ operations,
4051
+ // roles is string[] e.g., ["public", "authenticated"]
4052
+ roles: policy.roles ?? [],
4053
+ qual: policy.qual,
4054
+ with_check: policy.with_check
4055
+ });
4056
+ }
4057
+ }
4058
+ const prettifiedName = prettifyIdentifier(tableName);
4059
+ return {
4060
+ name: prettifiedName,
4061
+ slug: tableName,
4062
+ table: tableName,
4063
+ properties,
4064
+ propertiesOrder,
4065
+ ...relations.length > 0 ? {
4066
+ relations
4067
+ } : {},
4068
+ ...securityRules.length > 0 ? {
4069
+ securityRules
4070
+ } : {}
4071
+ };
4072
+ }
4073
+ function CollectionEditorDialog(props) {
4074
+ const $ = c(25);
4075
+ const open = props.open;
4076
+ const [formDirty, setFormDirty] = React.useState(false);
4077
+ let t0;
4078
+ if ($[0] !== props) {
4079
+ t0 = () => props.handleClose(void 0);
4080
+ $[0] = props;
4081
+ $[1] = t0;
4082
+ } else {
4083
+ t0 = $[1];
4084
+ }
4085
+ const {
4086
+ dialogProps,
4087
+ triggerDialog
4088
+ } = useUnsavedChangesDialog(open && formDirty, t0);
4089
+ let t1;
4090
+ if ($[2] !== formDirty || $[3] !== props || $[4] !== triggerDialog) {
4091
+ t1 = () => {
4092
+ if (!formDirty) {
4093
+ props.handleClose(void 0);
4094
+ } else {
4095
+ triggerDialog();
4096
+ }
4097
+ };
4098
+ $[2] = formDirty;
4099
+ $[3] = props;
4100
+ $[4] = triggerDialog;
4101
+ $[5] = t1;
4102
+ } else {
4103
+ t1 = $[5];
4104
+ }
4105
+ const handleCancel = t1;
4106
+ let t2;
4107
+ let t3;
4108
+ if ($[6] !== open) {
4109
+ t2 = () => {
4110
+ if (!open) {
4111
+ setFormDirty(false);
4112
+ }
4113
+ };
4114
+ t3 = [open];
4115
+ $[6] = open;
4116
+ $[7] = t2;
4117
+ $[8] = t3;
4118
+ } else {
4119
+ t2 = $[7];
4120
+ t3 = $[8];
4121
+ }
4122
+ useEffect(t2, t3);
4123
+ let t4;
4124
+ if ($[9] !== handleCancel) {
4125
+ t4 = (open_0) => !open_0 ? handleCancel() : void 0;
4126
+ $[9] = handleCancel;
4127
+ $[10] = t4;
4128
+ } else {
4129
+ t4 = $[10];
4130
+ }
4131
+ let t5;
4132
+ if ($[11] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
4133
+ t5 = /* @__PURE__ */ jsx(DialogTitle, { hidden: true, children: "Collection editor" });
4134
+ $[11] = t5;
4135
+ } else {
4136
+ t5 = $[11];
4137
+ }
4138
+ let t6;
4139
+ if ($[12] !== handleCancel || $[13] !== open || $[14] !== props) {
4140
+ t6 = open && /* @__PURE__ */ jsx(CollectionEditor, { ...props, handleCancel, setFormDirty });
4141
+ $[12] = handleCancel;
4142
+ $[13] = open;
4143
+ $[14] = props;
4144
+ $[15] = t6;
4145
+ } else {
4146
+ t6 = $[15];
4147
+ }
4148
+ let t7;
4149
+ if ($[16] !== dialogProps) {
4150
+ t7 = /* @__PURE__ */ jsx(UnsavedChangesDialog, { ...dialogProps });
4151
+ $[16] = dialogProps;
4152
+ $[17] = t7;
4153
+ } else {
4154
+ t7 = $[17];
4155
+ }
4156
+ let t8;
4157
+ if ($[18] !== t6 || $[19] !== t7) {
4158
+ t8 = /* @__PURE__ */ jsxs(AIModifiedPathsProvider, { children: [
4159
+ t6,
4160
+ t7
4161
+ ] });
4162
+ $[18] = t6;
4163
+ $[19] = t7;
4164
+ $[20] = t8;
4165
+ } else {
4166
+ t8 = $[20];
4167
+ }
4168
+ let t9;
4169
+ if ($[21] !== open || $[22] !== t4 || $[23] !== t8) {
4170
+ t9 = /* @__PURE__ */ jsxs(Dialog, { open, fullWidth: true, fullHeight: true, scrollable: false, maxWidth: "7xl", onOpenChange: t4, children: [
4171
+ t5,
4172
+ t8
4173
+ ] });
4174
+ $[21] = open;
4175
+ $[22] = t4;
4176
+ $[23] = t8;
4177
+ $[24] = t9;
4178
+ } else {
4179
+ t9 = $[24];
4180
+ }
4181
+ return t9;
4182
+ }
4183
+ function CollectionEditor(props) {
4184
+ const {
4185
+ propertyConfigs
4186
+ } = useCustomizationController();
4187
+ const navigationState = useNavigationStateController();
4188
+ const collectionRegistry = useCollectionRegistryController();
4189
+ const authController = useAuthController();
4190
+ const {
4191
+ topLevelNavigation
4192
+ } = navigationState;
4193
+ const {
4194
+ collections
4195
+ } = collectionRegistry;
4196
+ const initialValuesProp = props.initialValues;
4197
+ const copyFromProp = props.copyFrom;
4198
+ const includeTemplates = !copyFromProp && !initialValuesProp?.slug && (props.parentCollectionSlugs ?? []).length === 0;
4199
+ const collectionsInThisLevel = (props.parentCollection ? getSubcollections(props.parentCollection) : collections) ?? [];
4200
+ const existingPaths = collectionsInThisLevel.map((col) => getTableName(col)?.trim().toLowerCase()).filter(Boolean);
4201
+ const existingIds = collectionsInThisLevel.map((col_0) => col_0.slug?.trim().toLowerCase()).filter(Boolean);
4202
+ const [collection, setCollection] = React.useState();
4203
+ const [initialLoadingCompleted, setInitialLoadingCompleted] = React.useState(false);
4204
+ useEffect(() => {
4205
+ try {
4206
+ if (collectionRegistry.initialised) {
4207
+ if (props.editedCollectionId) {
4208
+ const collectionPath = [...props.parentCollectionSlugs ?? [], props.editedCollectionId].reduce((acc, segment, i) => i === 0 ? segment : `${acc}/fake_id/${segment}`, "");
4209
+ setCollection(collectionRegistry.getRawCollection(collectionPath));
4210
+ } else {
4211
+ setCollection(void 0);
4212
+ }
4213
+ setInitialLoadingCompleted(true);
4214
+ }
4215
+ } catch (e) {
4216
+ console.error(e);
4217
+ }
4218
+ }, [props.editedCollectionId, props.parentCollectionSlugs, props.parentEntityIds, collectionRegistry.initialised, collectionRegistry.getRawCollection]);
4219
+ const groups = topLevelNavigation?.groups ?? [];
4220
+ const initialCollection = collection ? {
4221
+ ...collection,
4222
+ slug: collection.slug ?? randomString(16)
4223
+ } : void 0;
4224
+ const initialValues = initialCollection ? applyPropertyConfigs(initialCollection, propertyConfigs) : copyFromProp ? (() => {
4225
+ const {
4226
+ subcollections: _sub,
4227
+ ...rest
4228
+ } = copyFromProp;
4229
+ return {
4230
+ ...rest,
4231
+ name: "",
4232
+ ownerId: authController.user?.uid ?? ""
4233
+ };
4234
+ })() : {
4235
+ slug: initialValuesProp?.slug ?? randomString(16),
4236
+ table: initialValuesProp?.slug ?? "",
4237
+ name: initialValuesProp?.name ?? "",
4238
+ group: initialValuesProp?.group ?? "",
4239
+ properties: {},
4240
+ propertiesOrder: [],
4241
+ icon: coolIconKeys[Math.floor(Math.random() * coolIconKeys.length)],
4242
+ ownerId: authController.user?.uid ?? ""
4243
+ };
4244
+ if (!initialLoadingCompleted) {
4245
+ return /* @__PURE__ */ jsx(CircularProgressCenter, {});
4246
+ }
4247
+ if (!props.isNewCollection && (!collectionRegistry.initialised || !initialLoadingCompleted)) {
4248
+ return /* @__PURE__ */ jsx(CircularProgressCenter, {});
4249
+ }
4250
+ return /* @__PURE__ */ jsx(CollectionEditorInternal, { ...props, initialValues, existingPaths, existingIds, includeTemplates, collection, setCollection, groups, propertyConfigs });
4251
+ }
4252
+ function CollectionEditorInternal({
4253
+ isNewCollection,
4254
+ configController,
4255
+ editedCollectionId,
4256
+ parentCollectionSlugs,
4257
+ parentEntityIds,
4258
+ path,
4259
+ collectionInference,
4260
+ handleClose,
4261
+ reservedGroups,
4262
+ extraView,
4263
+ handleCancel,
4264
+ setFormDirty,
4265
+ getUser,
4266
+ parentCollection,
4267
+ getData,
4268
+ existingPaths,
4269
+ existingIds,
4270
+ includeTemplates,
4271
+ collection,
4272
+ setCollection,
4273
+ initialValues,
4274
+ propertyConfigs,
4275
+ groups,
4276
+ existingEntities,
4277
+ initialView: initialViewProp,
4278
+ expandKanban,
4279
+ generateCollection,
4280
+ onAnalyticsEvent,
4281
+ fullScreen,
4282
+ unmappedTables,
4283
+ onFetchTableMetadata
4284
+ }) {
4285
+ const importConfig = useImportConfig();
4286
+ const urlController = useUrlController();
4287
+ const collectionRegistry = useCollectionRegistryController();
4288
+ const snackbarController = useSnackbarController();
4289
+ const propertyErrorsRef = useRef({});
4290
+ const initialView = isNewCollection ? includeTemplates ? "welcome" : "general" : initialViewProp ?? "properties";
4291
+ const [currentView, setCurrentView] = useState(initialView);
4292
+ const [error, setError] = React.useState();
4293
+ const saveCollection = (updatedCollection) => {
4294
+ const id = updatedCollection.slug;
4295
+ return configController.saveCollection({
4296
+ id,
4297
+ collectionData: updatedCollection,
4298
+ previousId: editedCollectionId,
4299
+ parentCollectionSlugs
4300
+ }).then(() => {
4301
+ setError(void 0);
4302
+ return true;
4303
+ }).catch((e) => {
4304
+ setError(e);
4305
+ console.error(e);
4306
+ snackbarController.open({
4307
+ type: "error",
4308
+ message: "Error persisting collection: " + (e.message ?? "Details in the console")
4309
+ });
4310
+ return false;
4311
+ });
4312
+ };
4313
+ const setNextMode = () => {
4314
+ if (currentView === "general") {
4315
+ if (importConfig.inUse) {
4316
+ setCurrentView("import_data_saving");
4317
+ } else if (extraView) {
4318
+ setCurrentView("extra_view");
4319
+ } else {
4320
+ setCurrentView("properties");
4321
+ }
4322
+ } else if (currentView === "welcome") {
4323
+ setCurrentView("general");
4324
+ } else if (currentView === "import_data_mapping") {
4325
+ setCurrentView("import_data_preview");
4326
+ } else if (currentView === "import_data_preview") {
4327
+ setCurrentView("general");
4328
+ } else if (currentView === "extra_view") {
4329
+ setCurrentView("properties");
4330
+ } else {
4331
+ setCurrentView("general");
4332
+ }
4333
+ };
4334
+ const doCollectionInference = collectionInference ? (collection_0) => {
4335
+ if (!collectionInference) return void 0;
4336
+ return collectionInference?.(collection_0.slug, parentPaths ?? [], collection_0.databaseId);
4337
+ } : void 0;
4338
+ const inferCollectionFromData = async (newCollection) => {
4339
+ try {
4340
+ if (!doCollectionInference) {
4341
+ setCollection(newCollection);
4342
+ return Promise.resolve(newCollection);
4343
+ }
4344
+ setCurrentView("loading");
4345
+ const inferredCollection = await doCollectionInference?.(newCollection);
4346
+ if (!inferredCollection) {
4347
+ setCollection(newCollection);
4348
+ return Promise.resolve(newCollection);
4349
+ }
4350
+ const values = {
4351
+ ...newCollection ?? {}
4352
+ };
4353
+ if (Object.keys(inferredCollection.properties ?? {}).length > 0) {
4354
+ values.properties = inferredCollection.properties;
4355
+ values.propertiesOrder = inferredCollection.propertiesOrder;
4356
+ }
4357
+ if (!values.propertiesOrder) {
4358
+ values.propertiesOrder = Object.keys(values.properties);
4359
+ return values;
4360
+ }
4361
+ setCollection(values);
4362
+ console.debug("Inferred collection", {
4363
+ newCollection: newCollection ?? {},
4364
+ values
4365
+ });
4366
+ return values;
4367
+ } catch (e_0) {
4368
+ console.error(e_0);
4369
+ snackbarController.open({
4370
+ type: "error",
4371
+ message: "Error inferring collection: " + (e_0 instanceof Error ? e_0.message : "Details in the console")
4372
+ });
4373
+ return newCollection;
4374
+ }
4375
+ };
4376
+ const onSubmit = async (newCollectionState, formexController) => {
4377
+ console.debug("Submitting collection", newCollectionState);
4378
+ try {
4379
+ if (!isNewCollection) {
4380
+ const success = await saveCollection(newCollectionState);
4381
+ if (success) {
4382
+ aiModifiedPaths?.clearAllPaths();
4383
+ formexController.resetForm({
4384
+ values: newCollectionState
4385
+ });
4386
+ handleClose(newCollectionState);
4387
+ }
4388
+ return;
4389
+ }
4390
+ if (currentView === "welcome") {
4391
+ setNextMode();
4392
+ formexController.resetForm({
4393
+ values: newCollectionState
4394
+ });
4395
+ } else if (currentView === "general") {
4396
+ if (extraView || importConfig.inUse) {
4397
+ formexController.resetForm({
4398
+ values: newCollectionState
4399
+ });
4400
+ setNextMode();
4401
+ } else if (isNewCollection) {
4402
+ const values_0 = await inferCollectionFromData(newCollectionState);
4403
+ formexController.resetForm({
4404
+ values: values_0 ?? newCollectionState,
4405
+ touched: {
4406
+ path: true,
4407
+ name: true
4408
+ }
4409
+ });
4410
+ setNextMode();
4411
+ } else {
4412
+ formexController.resetForm({
4413
+ values: newCollectionState
4414
+ });
4415
+ setNextMode();
4416
+ }
4417
+ } else if (currentView === "extra_view") {
4418
+ setNextMode();
4419
+ formexController.resetForm({
4420
+ values: newCollectionState
4421
+ });
4422
+ } else if (currentView === "import_data_mapping") {
4423
+ setNextMode();
4424
+ } else if (currentView === "import_data_preview") {
4425
+ setNextMode();
4426
+ } else if (currentView === "properties") {
4427
+ const success_0 = await saveCollection(newCollectionState);
4428
+ if (success_0) {
4429
+ formexController.resetForm({
4430
+ values: initialValues
4431
+ });
4432
+ setNextMode();
4433
+ handleClose(newCollectionState);
4434
+ }
4435
+ } else {
4436
+ setNextMode();
4437
+ formexController.resetForm({
4438
+ values: newCollectionState
4439
+ });
4440
+ }
4441
+ } catch (e_1) {
4442
+ snackbarController.open({
4443
+ type: "error",
4444
+ message: "Error persisting collection: " + (e_1 instanceof Error ? e_1.message : "Details in the console")
4445
+ });
4446
+ console.error(e_1);
4447
+ formexController.resetForm({
4448
+ values: newCollectionState
4449
+ });
4450
+ }
4451
+ };
4452
+ const validation = (col) => {
4453
+ let errors = {};
4454
+ const schema = (currentView === "properties" || currentView === "relations" || currentView === "general") && CollectionEditorSchema;
4455
+ if (schema) {
4456
+ const result = schema.safeParse(col);
4457
+ if (!result.success) {
4458
+ result.error.issues.forEach((issue) => {
4459
+ const path_0 = issue.path.join(".");
4460
+ if (path_0) {
4461
+ errors[path_0] = issue.message;
4462
+ }
4463
+ });
4464
+ }
4465
+ }
4466
+ if (currentView === "properties") {
4467
+ errors = {
4468
+ ...errors,
4469
+ ...propertyErrorsRef.current
4470
+ };
4471
+ }
4472
+ if (currentView === "general") {
4473
+ const pathError = validatePath(getTableName(col), isNewCollection, existingPaths, col.slug);
4474
+ if (pathError) {
4475
+ errors.slug = pathError;
4476
+ }
4477
+ const idError = validateId(col.slug, isNewCollection, existingPaths, existingIds);
4478
+ if (idError) {
4479
+ errors.id = idError;
4480
+ }
4481
+ }
4482
+ if (Object.keys(errors).length > 0) {
4483
+ console.error("Formex validation blocked save:", errors, "Current view:", currentView);
4484
+ }
4485
+ return errors;
4486
+ };
4487
+ const formController = useCreateFormex({
4488
+ initialValues,
4489
+ onSubmit,
4490
+ validation,
4491
+ debugId: "COLLECTION_EDITOR"
4492
+ });
4493
+ const {
4494
+ values: values_1,
4495
+ setFieldValue,
4496
+ isSubmitting,
4497
+ dirty,
4498
+ submitCount
4499
+ } = formController;
4500
+ const usedPath = getTableName(values_1);
4501
+ const pathError_0 = validatePath(usedPath, isNewCollection, existingPaths, values_1.slug);
4502
+ const parentPaths = !pathError_0 && parentCollectionSlugs ? collectionRegistry.convertIdsToPaths(parentCollectionSlugs) : void 0;
4503
+ const updatedFullPath = parentPaths && parentPaths.length > 0 ? [...parentPaths, usedPath].join("/fake_id/") : path?.includes("/") ? path.split("/").slice(0, -1).join("/") + "/" + usedPath : usedPath;
4504
+ const resolvedPath = !pathError_0 ? urlController.resolveDatabasePathsFrom(updatedFullPath) : void 0;
4505
+ const getDataWithPath = resolvedPath && getData ? async () => {
4506
+ const data = await getData(resolvedPath, parentPaths ?? []);
4507
+ if (existingEntities) {
4508
+ const existingData = existingEntities.map((e_2) => e_2.values);
4509
+ data.push(...existingData);
4510
+ }
4511
+ return data;
4512
+ } : void 0;
4513
+ useEffect(() => {
4514
+ setFormDirty(dirty);
4515
+ }, [dirty]);
4516
+ function onImportDataSet(data_0, propertiesOrder) {
4517
+ importConfig.setInUse(true);
4518
+ buildEntityPropertiesFromData(data_0, getInferenceType).then((properties) => {
4519
+ const res = cleanPropertiesFromImport(properties);
4520
+ importConfig.setIdColumn(res.idColumn);
4521
+ importConfig.setImportData(data_0);
4522
+ importConfig.setHeadersMapping(res.headersMapping);
4523
+ const filteredHeadingsOrder = (propertiesOrder ?? []).filter((key) => res.headersMapping[key]) ?? Object.keys(res.properties);
4524
+ importConfig.setHeadingsOrder(filteredHeadingsOrder);
4525
+ importConfig.setOriginProperties(res.properties);
4526
+ const mappedHeadings = (propertiesOrder ?? []).map((key_0) => res.headersMapping[key_0]).filter(Boolean) ?? Object.keys(res.properties);
4527
+ setFieldValue("properties", res.properties);
4528
+ setFieldValue("propertiesOrder", mappedHeadings);
4529
+ });
4530
+ }
4531
+ const validValues = Boolean(values_1.name) && Boolean(values_1.slug);
4532
+ const onImportMappingComplete = () => {
4533
+ const updatedProperties = {
4534
+ ...values_1.properties
4535
+ };
4536
+ if (importConfig.idColumn) delete updatedProperties[importConfig.idColumn];
4537
+ setFieldValue("properties", updatedProperties);
4538
+ setNextMode();
4539
+ };
4540
+ const [deleteRequested, setDeleteRequested] = useState(false);
4541
+ const deleteCollection = () => {
4542
+ if (!collection) return;
4543
+ configController?.deleteCollection({
4544
+ id: collection.slug
4545
+ }).then(() => {
4546
+ setDeleteRequested(false);
4547
+ handleCancel();
4548
+ snackbarController.open({
4549
+ message: "Collection deleted",
4550
+ type: "success"
4551
+ });
4552
+ });
4553
+ };
4554
+ const onWelcomeScreenContinue = (importData, propertiesOrder_0) => {
4555
+ if (importData) {
4556
+ onImportDataSet(importData, propertiesOrder_0);
4557
+ setCurrentView("import_data_mapping");
4558
+ } else {
4559
+ setCurrentView("general");
4560
+ }
4561
+ };
4562
+ const aiModifiedPaths = useAIModifiedPaths();
4563
+ const handleAIGenerated = (generatedCollection, operations) => {
4564
+ formController.setValues(generatedCollection);
4565
+ if (operations && aiModifiedPaths) {
4566
+ aiModifiedPaths.addModifiedPaths(operations);
4567
+ }
4568
+ };
4569
+ return /* @__PURE__ */ jsxs("div", { className: "h-full w-full flex flex-col bg-white dark:bg-surface-950", children: [
4570
+ /* @__PURE__ */ jsx(Formex, { value: formController, children: /* @__PURE__ */ jsxs(Fragment, { children: [
4571
+ !isNewCollection && /* @__PURE__ */ jsxs("div", { className: cls("px-4 py-2 w-full flex shrink-0 items-center justify-between gap-4 bg-white dark:bg-surface-950 border-b", defaultBorderMixin), children: [
4572
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end gap-4 min-w-0", children: /* @__PURE__ */ jsxs(Tabs, { value: currentView, className: "bg-transparent !w-fit max-w-full", onValueChange: (v) => setCurrentView(v), children: [
4573
+ /* @__PURE__ */ jsx(Tab, { value: "general", children: "General" }),
4574
+ /* @__PURE__ */ jsx(Tab, { value: "display", children: "Display" }),
4575
+ /* @__PURE__ */ jsx(Tab, { value: "properties", children: "Properties" }),
4576
+ getDataSourceCapabilities(values_1.driver).supportsRLS && /* @__PURE__ */ jsx(Tab, { value: "rls", children: "RLS" }),
4577
+ getDataSourceCapabilities(values_1.driver).supportsRelations && /* @__PURE__ */ jsx(Tab, { value: "relations", children: "Relations" })
4578
+ ] }) }),
4579
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
4580
+ generateCollection && /* @__PURE__ */ jsx(AICollectionGeneratorPopover, { existingCollection: values_1, onGenerated: handleAIGenerated, generateCollection, onAnalyticsEvent }),
4581
+ fullScreen && !isNewCollection && /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx(LoadingButton, { variant: "filled", color: "primary", type: "submit", onClick: () => formController.handleSubmit(), disabled: !dirty || isSubmitting || configController?.readOnly, loading: isSubmitting, children: configController?.readOnly ? "Update (Read-only)" : "Update" }) })
4582
+ ] })
4583
+ ] }),
4584
+ /* @__PURE__ */ jsxs("form", { noValidate: true, onSubmit: formController.handleSubmit, className: "flex-grow flex flex-col min-h-0 relative", children: [
4585
+ /* @__PURE__ */ jsxs("div", { className: "flex-grow flex flex-col min-h-0 overflow-y-auto no-scrollbar relative w-full h-full", children: [
4586
+ currentView === "loading" && /* @__PURE__ */ jsx(CircularProgressCenter, {}),
4587
+ currentView === "extra_view" && usedPath && extraView?.View && /* @__PURE__ */ jsx(extraView.View, { path: usedPath }),
4588
+ currentView === "welcome" && /* @__PURE__ */ jsx(CollectionEditorWelcomeView, { path: usedPath, onContinue: onWelcomeScreenContinue, existingCollectionPaths: existingPaths, parentCollection, generateCollection, onAnalyticsEvent, unmappedTables, onImportFromTable: onFetchTableMetadata ? async (tableName) => {
4589
+ try {
4590
+ const columns = await onFetchTableMetadata(tableName);
4591
+ if (!columns) return;
4592
+ const collectionData = buildCollectionFromTableMetadata(tableName, columns);
4593
+ formController.setValues({
4594
+ ...formController.values,
4595
+ ...collectionData
4596
+ });
4597
+ onWelcomeScreenContinue();
4598
+ } catch (e_3) {
4599
+ console.error("Error importing table:", e_3);
4600
+ snackbarController.open({
4601
+ type: "error",
4602
+ message: "Error importing table: " + (e_3 instanceof Error ? e_3.message : "Unknown error")
4603
+ });
4604
+ }
4605
+ } : void 0 }),
4606
+ currentView === "import_data_mapping" && importConfig && /* @__PURE__ */ jsx(CollectionEditorImportMapping, { importConfig, propertyConfigs }),
4607
+ currentView === "import_data_preview" && importConfig && /* @__PURE__ */ jsx(CollectionEditorImportDataPreview, { importConfig, properties: values_1.properties, propertiesOrder: values_1.propertiesOrder }),
4608
+ currentView === "import_data_saving" && importConfig && /* @__PURE__ */ jsx(ImportSaveInProgress, { importConfig, collection: values_1, path: usedPath, onImportSuccess: async (importedCollection) => {
4609
+ snackbarController.open({
4610
+ type: "info",
4611
+ message: "Data imported successfully"
4612
+ });
4613
+ await saveCollection(values_1);
4614
+ handleClose(importedCollection);
4615
+ } }),
4616
+ currentView === "general" && /* @__PURE__ */ jsx(GeneralSettingsForm, { existingPaths, existingIds, parentCollection, isNewCollection }),
4617
+ currentView === "display" && /* @__PURE__ */ jsx(DisplaySettingsForm, { expandKanban }),
4618
+ currentView === "relations" && getDataSourceCapabilities(values_1.driver).supportsRelations && /* @__PURE__ */ jsx(CollectionRelationsTab, {}),
4619
+ currentView === "rls" && getDataSourceCapabilities(values_1.driver).supportsRLS && /* @__PURE__ */ jsx(CollectionRLSTab, {}),
4620
+ currentView === "properties" && /* @__PURE__ */ jsx(CollectionPropertiesEditorForm, { showErrors: submitCount > 0, isNewCollection, reservedGroups, onPropertyError: (propertyKey, namespace, error_0) => {
4621
+ const current = removeUndefined({
4622
+ ...propertyErrorsRef.current,
4623
+ [getFullIdPath(propertyKey, namespace)]: removeUndefined(error_0, true)
4624
+ }, true);
4625
+ propertyErrorsRef.current = current;
4626
+ formController.validate();
4627
+ }, getUser, getData: getDataWithPath, doCollectionInference, propertyConfigs, extraIcon: extraView?.icon && /* @__PURE__ */ jsx(IconButton, { color: "primary", onClick: () => setCurrentView("extra_view"), children: extraView.icon }) })
4628
+ ] }),
4629
+ (!fullScreen || isNewCollection || !!error) && /* @__PURE__ */ jsxs("div", { className: "shrink-0 w-full p-4 sm:px-6 sm:py-4 border-t border-surface-200 dark:border-surface-900 flex items-center justify-between gap-4 bg-white dark:bg-surface-950", children: [
4630
+ error && /* @__PURE__ */ jsx(ErrorView, { error }),
4631
+ isNewCollection && includeTemplates && currentView === "import_data_mapping" && /* @__PURE__ */ jsx(Button, { variant: "text", type: "button", onClick: () => {
4632
+ importConfig.setInUse(false);
4633
+ return setCurrentView("welcome");
4634
+ }, children: "Back" }),
4635
+ isNewCollection && includeTemplates && currentView === "import_data_preview" && /* @__PURE__ */ jsx(Button, { variant: "text", type: "button", onClick: () => {
4636
+ setCurrentView("import_data_mapping");
4637
+ }, children: "Back" }),
4638
+ isNewCollection && includeTemplates && currentView === "general" && /* @__PURE__ */ jsx(Button, { variant: "text", type: "button", onClick: () => setCurrentView("welcome"), children: "Back" }),
4639
+ isNewCollection && currentView === "properties" && /* @__PURE__ */ jsxs(Button, { variant: "text", type: "button", color: "neutral", onClick: () => setCurrentView("general"), children: [
4640
+ /* @__PURE__ */ jsx(ArrowLeftIcon, {}),
4641
+ "Back"
4642
+ ] }),
4643
+ (!fullScreen || isNewCollection) && /* @__PURE__ */ jsx(Button, { variant: "text", color: "neutral", onClick: () => {
4644
+ handleCancel();
4645
+ }, children: "Cancel" }),
4646
+ currentView === "welcome" && /* @__PURE__ */ jsx(Button, { variant: "text", onClick: () => onWelcomeScreenContinue(), children: "Continue from scratch" }),
4647
+ isNewCollection && currentView === "import_data_mapping" && /* @__PURE__ */ jsx(Button, { variant: "filled", color: "primary", onClick: onImportMappingComplete, children: "Next" }),
4648
+ isNewCollection && currentView === "import_data_preview" && /* @__PURE__ */ jsx(Button, { variant: "filled", color: "primary", onClick: () => {
4649
+ setNextMode();
4650
+ }, children: "Next" }),
4651
+ isNewCollection && (currentView === "general" || currentView === "properties") && /* @__PURE__ */ jsxs(LoadingButton, { variant: "filled", color: "primary", type: "submit", loading: isSubmitting, disabled: isSubmitting || currentView === "general" && !validValues || configController?.readOnly, startIcon: currentView === "properties" ? /* @__PURE__ */ jsx(CheckIcon, {}) : void 0, children: [
4652
+ currentView === "general" && "Next",
4653
+ currentView === "properties" && "Create collection"
4654
+ ] }),
4655
+ !isNewCollection && !fullScreen && /* @__PURE__ */ jsx(LoadingButton, { variant: "filled", color: "primary", type: "submit", disabled: isSubmitting || configController?.readOnly, loading: isSubmitting, children: configController?.readOnly ? "Update collection (Read-only)" : "Update collection" })
4656
+ ] })
4657
+ ] })
4658
+ ] }) }),
4659
+ /* @__PURE__ */ jsx(ConfirmationDialog, { open: deleteRequested, onAccept: deleteCollection, onCancel: () => setDeleteRequested(false), title: /* @__PURE__ */ jsx(Fragment, { children: "Delete the stored config?" }), body: /* @__PURE__ */ jsxs(Fragment, { children: [
4660
+ " This will ",
4661
+ /* @__PURE__ */ jsx("b", { children: "not delete any data" }),
4662
+ ", only the stored config, and reset to the code state."
4663
+ ] }) })
4664
+ ] });
4665
+ }
4666
+ function applyPropertyConfigs(collection, propertyConfigs) {
4667
+ const {
4668
+ properties,
4669
+ ...rest
4670
+ } = collection;
4671
+ const propertiesResult = {};
4672
+ if (properties) {
4673
+ Object.keys(properties).forEach((key) => {
4674
+ const prop = properties[key];
4675
+ if (prop == null) return;
4676
+ propertiesResult[key] = applyPropertiesConfig(prop, propertyConfigs);
4677
+ });
4678
+ }
4679
+ return {
4680
+ ...rest,
4681
+ properties: propertiesResult
4682
+ };
4683
+ }
4684
+ function applyPropertiesConfig(property, propertyConfigs) {
4685
+ let internalProperty = property;
4686
+ if (propertyConfigs && internalProperty && typeof internalProperty === "object" && internalProperty.propertyConfig) {
4687
+ const propertyConfig = propertyConfigs[internalProperty.propertyConfig];
4688
+ if (propertyConfig && isPropertyBuilder(propertyConfig.property)) {
4689
+ internalProperty = propertyConfig.property;
4690
+ } else {
4691
+ if (propertyConfig) {
4692
+ internalProperty = mergeDeep(propertyConfig.property, internalProperty);
4693
+ }
4694
+ if (!isPropertyBuilder(internalProperty) && internalProperty.type === "map" && internalProperty.properties) {
4695
+ const properties = {};
4696
+ Object.keys(internalProperty.properties).forEach((key) => {
4697
+ properties[key] = applyPropertiesConfig(internalProperty.properties[key], propertyConfigs);
4698
+ });
4699
+ internalProperty = {
4700
+ ...internalProperty,
4701
+ properties
4702
+ };
4703
+ }
4704
+ }
4705
+ }
4706
+ return internalProperty;
4707
+ }
4708
+ const validatePath = (value, isNewCollection, existingPaths, idValue) => {
4709
+ let error;
4710
+ if (!value) {
4711
+ error = "You must specify a path in the database for this collection";
4712
+ }
4713
+ if (isNewCollection && existingPaths?.includes(value.trim().toLowerCase()) && !idValue) error = "There is already a collection with the specified path. If you want to have multiple collections referring to the same database path, make sure the have different ids";
4714
+ const subpaths = removeInitialAndTrailingSlashes(value).split("/");
4715
+ if (subpaths.length % 2 === 0) {
4716
+ error = `Collection paths must have an odd number of segments: ${value}`;
4717
+ }
4718
+ return error;
4719
+ };
4720
+ const validateId = (value, isNewCollection, existingPaths, existingIds) => {
4721
+ if (!value) return void 0;
4722
+ let error;
4723
+ if (isNewCollection && existingPaths?.includes(value.trim().toLowerCase())) error = "There is already a collection that uses this value as a path";
4724
+ if (isNewCollection && existingIds?.includes(value.trim().toLowerCase())) error = "There is already a collection which uses this id";
4725
+ return error;
4726
+ };
4727
+ export {
4728
+ CollectionEditor,
4729
+ CollectionEditorDialog
4730
+ };
4731
+ //# sourceMappingURL=CollectionEditorDialog-D509-IMx.js.map