@rebasepro/admin 0.0.1-canary.eae7889 → 0.0.1-canary.eb08332

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