@rebasepro/cms 0.0.1-canary.4d4fb3e

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