@maxal_studio/kratosjs-react 1.0.0
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.
- package/README.md +44 -0
- package/dist/FieldRenderer.d.ts +13 -0
- package/dist/FieldRenderer.js +62 -0
- package/dist/FormRenderer.d.ts +7 -0
- package/dist/FormRenderer.js +78 -0
- package/dist/TableRenderer.d.ts +2 -0
- package/dist/TableRenderer.js +1 -0
- package/dist/api/actionsApi.d.ts +23 -0
- package/dist/api/actionsApi.js +46 -0
- package/dist/api/authenticatedFetch.d.ts +8 -0
- package/dist/api/authenticatedFetch.js +31 -0
- package/dist/api/exportApi.d.ts +18 -0
- package/dist/api/exportApi.js +50 -0
- package/dist/api/http.d.ts +24 -0
- package/dist/api/http.js +52 -0
- package/dist/api/resourceApi.d.ts +37 -0
- package/dist/api/resourceApi.js +52 -0
- package/dist/api/tableApi.d.ts +83 -0
- package/dist/api/tableApi.js +51 -0
- package/dist/api/urls.d.ts +19 -0
- package/dist/api/urls.js +46 -0
- package/dist/app.d.ts +101 -0
- package/dist/app.js +89 -0
- package/dist/auth/AuthContext.d.ts +22 -0
- package/dist/auth/AuthContext.js +147 -0
- package/dist/auth/LoginPage.d.ts +10 -0
- package/dist/auth/LoginPage.js +179 -0
- package/dist/auth/ProtectedRoute.d.ts +12 -0
- package/dist/auth/ProtectedRoute.js +22 -0
- package/dist/auth/authApiClient.d.ts +24 -0
- package/dist/auth/authApiClient.js +95 -0
- package/dist/auth/types.d.ts +103 -0
- package/dist/auth/types.js +1 -0
- package/dist/components/ActionFormModal.d.ts +22 -0
- package/dist/components/ActionFormModal.js +8 -0
- package/dist/components/AdminPanel.d.ts +11 -0
- package/dist/components/AdminPanel.js +194 -0
- package/dist/components/Checkbox.d.ts +10 -0
- package/dist/components/Checkbox.js +8 -0
- package/dist/components/CheckboxField.d.ts +7 -0
- package/dist/components/CheckboxField.js +26 -0
- package/dist/components/ColorPickerField.d.ts +7 -0
- package/dist/components/ColorPickerField.js +26 -0
- package/dist/components/DateTimePickerField.d.ts +7 -0
- package/dist/components/DateTimePickerField.js +64 -0
- package/dist/components/FileUploadField.d.ts +9 -0
- package/dist/components/FileUploadField.js +478 -0
- package/dist/components/GlobalSearch.d.ts +22 -0
- package/dist/components/GlobalSearch.js +181 -0
- package/dist/components/GroupField.d.ts +7 -0
- package/dist/components/GroupField.js +23 -0
- package/dist/components/HiddenField.d.ts +3 -0
- package/dist/components/HiddenField.js +10 -0
- package/dist/components/ModalBreadcrumb.d.ts +5 -0
- package/dist/components/ModalBreadcrumb.js +33 -0
- package/dist/components/ModalDrawer.d.ts +15 -0
- package/dist/components/ModalDrawer.js +40 -0
- package/dist/components/RadioField.d.ts +7 -0
- package/dist/components/RadioField.js +26 -0
- package/dist/components/RepeaterField.d.ts +3 -0
- package/dist/components/RepeaterField.js +191 -0
- package/dist/components/ResourceModalRenderer.d.ts +10 -0
- package/dist/components/ResourceModalRenderer.js +80 -0
- package/dist/components/RichEditorField.d.ts +3 -0
- package/dist/components/RichEditorField.js +655 -0
- package/dist/components/SectionField.d.ts +9 -0
- package/dist/components/SectionField.js +111 -0
- package/dist/components/SelectField.d.ts +8 -0
- package/dist/components/SelectField.js +523 -0
- package/dist/components/TabsField.d.ts +10 -0
- package/dist/components/TabsField.js +214 -0
- package/dist/components/TagsInputField.d.ts +7 -0
- package/dist/components/TagsInputField.js +172 -0
- package/dist/components/TextInputField.d.ts +7 -0
- package/dist/components/TextInputField.js +44 -0
- package/dist/components/TextareaField.d.ts +7 -0
- package/dist/components/TextareaField.js +31 -0
- package/dist/components/ToggleField.d.ts +7 -0
- package/dist/components/ToggleField.js +57 -0
- package/dist/components/ViewModal.d.ts +25 -0
- package/dist/components/ViewModal.js +159 -0
- package/dist/components/blocks/BlockRenderer.d.ts +7 -0
- package/dist/components/blocks/BlockRenderer.js +36 -0
- package/dist/components/blocks/FormBlockRenderer.d.ts +6 -0
- package/dist/components/blocks/FormBlockRenderer.js +110 -0
- package/dist/components/blocks/TableBlockRenderer.d.ts +6 -0
- package/dist/components/blocks/TableBlockRenderer.js +12 -0
- package/dist/components/blocks/TabsBlockRenderer.d.ts +7 -0
- package/dist/components/blocks/TabsBlockRenderer.js +11 -0
- package/dist/components/blocks/WidgetBlockRenderer.d.ts +6 -0
- package/dist/components/blocks/WidgetBlockRenderer.js +11 -0
- package/dist/components/columns/CheckboxColumnComponent.d.ts +6 -0
- package/dist/components/columns/CheckboxColumnComponent.js +21 -0
- package/dist/components/columns/ColorColumnComponent.d.ts +3 -0
- package/dist/components/columns/ColorColumnComponent.js +11 -0
- package/dist/components/columns/DeeplinkWrapper.d.ts +15 -0
- package/dist/components/columns/DeeplinkWrapper.js +85 -0
- package/dist/components/columns/IconColumnComponent.d.ts +3 -0
- package/dist/components/columns/IconColumnComponent.js +52 -0
- package/dist/components/columns/ImageColumnComponent.d.ts +3 -0
- package/dist/components/columns/ImageColumnComponent.js +98 -0
- package/dist/components/columns/MediaColumnComponent.d.ts +3 -0
- package/dist/components/columns/MediaColumnComponent.js +160 -0
- package/dist/components/columns/SelectColumnComponent.d.ts +6 -0
- package/dist/components/columns/SelectColumnComponent.js +26 -0
- package/dist/components/columns/TagsColumnComponent.d.ts +3 -0
- package/dist/components/columns/TagsColumnComponent.js +18 -0
- package/dist/components/columns/TextColumnComponent.d.ts +11 -0
- package/dist/components/columns/TextColumnComponent.js +107 -0
- package/dist/components/columns/TextInputColumnComponent.d.ts +6 -0
- package/dist/components/columns/TextInputColumnComponent.js +18 -0
- package/dist/components/columns/ToggleColumnComponent.d.ts +6 -0
- package/dist/components/columns/ToggleColumnComponent.js +25 -0
- package/dist/components/columns/VideoColumnComponent.d.ts +3 -0
- package/dist/components/columns/VideoColumnComponent.js +125 -0
- package/dist/components/columns/ViewColumnComponent.d.ts +3 -0
- package/dist/components/columns/ViewColumnComponent.js +7 -0
- package/dist/components/errors/ErrorBoundary.d.ts +23 -0
- package/dist/components/errors/ErrorBoundary.js +33 -0
- package/dist/components/filters/CustomFilterComponent.d.ts +10 -0
- package/dist/components/filters/CustomFilterComponent.js +33 -0
- package/dist/components/filters/DateFilterComponent.d.ts +15 -0
- package/dist/components/filters/DateFilterComponent.js +132 -0
- package/dist/components/filters/QueryBuilderFilterComponent.d.ts +11 -0
- package/dist/components/filters/QueryBuilderFilterComponent.js +200 -0
- package/dist/components/layout/Header.d.ts +10 -0
- package/dist/components/layout/Header.js +70 -0
- package/dist/components/layout/PanelBrandMark.d.ts +8 -0
- package/dist/components/layout/PanelBrandMark.js +28 -0
- package/dist/components/layout/Sidebar.d.ts +35 -0
- package/dist/components/layout/Sidebar.js +125 -0
- package/dist/components/modals/RelationCreateModal.d.ts +19 -0
- package/dist/components/modals/RelationCreateModal.js +57 -0
- package/dist/components/modals/ResourceFormModal.d.ts +37 -0
- package/dist/components/modals/ResourceFormModal.js +44 -0
- package/dist/components/modals/useResourceForm.d.ts +40 -0
- package/dist/components/modals/useResourceForm.js +138 -0
- package/dist/components/modals/view/RecordActions.d.ts +17 -0
- package/dist/components/modals/view/RecordActions.js +16 -0
- package/dist/components/modals/view/RecordDetails.d.ts +13 -0
- package/dist/components/modals/view/RecordDetails.js +29 -0
- package/dist/components/modals/view/RelationPanel.d.ts +18 -0
- package/dist/components/modals/view/RelationPanel.js +16 -0
- package/dist/components/modals/view/RelationTabs.d.ts +32 -0
- package/dist/components/modals/view/RelationTabs.js +42 -0
- package/dist/components/modals/view/useRecordView.d.ts +18 -0
- package/dist/components/modals/view/useRecordView.js +114 -0
- package/dist/components/pages/PageRenderer.d.ts +6 -0
- package/dist/components/pages/PageRenderer.js +107 -0
- package/dist/components/table/ColumnTogglePopup.d.ts +11 -0
- package/dist/components/table/ColumnTogglePopup.js +16 -0
- package/dist/components/table/GridCard.d.ts +21 -0
- package/dist/components/table/GridCard.js +30 -0
- package/dist/components/table/GridView.d.ts +23 -0
- package/dist/components/table/GridView.js +49 -0
- package/dist/components/table/LayoutToggle.d.ts +7 -0
- package/dist/components/table/LayoutToggle.js +9 -0
- package/dist/components/table/TableActionsDropdown.d.ts +13 -0
- package/dist/components/table/TableActionsDropdown.js +46 -0
- package/dist/components/table/TableBulkActions.d.ts +11 -0
- package/dist/components/table/TableBulkActions.js +21 -0
- package/dist/components/table/TableHeader.d.ts +14 -0
- package/dist/components/table/TableHeader.js +23 -0
- package/dist/components/table/TablePagination.d.ts +13 -0
- package/dist/components/table/TablePagination.js +55 -0
- package/dist/components/table/TableRow.d.ts +21 -0
- package/dist/components/table/TableRow.js +32 -0
- package/dist/components/table/TableSearchBar.d.ts +11 -0
- package/dist/components/table/TableSearchBar.js +12 -0
- package/dist/components/table/TableTabs.d.ts +14 -0
- package/dist/components/table/TableTabs.js +8 -0
- package/dist/components/ui/Badge.d.ts +6 -0
- package/dist/components/ui/Badge.js +12 -0
- package/dist/components/ui/Button.d.ts +22 -0
- package/dist/components/ui/Button.js +22 -0
- package/dist/components/ui/Card.d.ts +7 -0
- package/dist/components/ui/Card.js +5 -0
- package/dist/components/ui/ConfirmDialog.d.ts +19 -0
- package/dist/components/ui/ConfirmDialog.js +45 -0
- package/dist/components/ui/EmptyState.d.ts +9 -0
- package/dist/components/ui/EmptyState.js +6 -0
- package/dist/components/ui/ErrorAlert.d.ts +7 -0
- package/dist/components/ui/ErrorAlert.js +9 -0
- package/dist/components/ui/Input.d.ts +11 -0
- package/dist/components/ui/Input.js +10 -0
- package/dist/components/ui/Label.d.ts +5 -0
- package/dist/components/ui/Label.js +5 -0
- package/dist/components/ui/PillButton.d.ts +14 -0
- package/dist/components/ui/PillButton.js +19 -0
- package/dist/components/ui/Select.d.ts +7 -0
- package/dist/components/ui/Select.js +7 -0
- package/dist/components/ui/Spinner.d.ts +8 -0
- package/dist/components/ui/Spinner.js +14 -0
- package/dist/components/ui/Toast.d.ts +21 -0
- package/dist/components/ui/Toast.js +47 -0
- package/dist/components/ui/index.d.ts +24 -0
- package/dist/components/ui/index.js +12 -0
- package/dist/components/utils/HintDisplay.d.ts +11 -0
- package/dist/components/utils/HintDisplay.js +12 -0
- package/dist/components/utils/Icon.d.ts +22 -0
- package/dist/components/utils/Icon.js +22 -0
- package/dist/components/utils/MediaPreviewModal.d.ts +14 -0
- package/dist/components/utils/MediaPreviewModal.js +32 -0
- package/dist/components/utils/ViewFieldWrapper.d.ts +11 -0
- package/dist/components/utils/ViewFieldWrapper.js +9 -0
- package/dist/components/utils/layoutHelpers.d.ts +19 -0
- package/dist/components/utils/layoutHelpers.js +257 -0
- package/dist/components/widgets/ChartWidget.d.ts +16 -0
- package/dist/components/widgets/ChartWidget.js +192 -0
- package/dist/components/widgets/StatsWidget.d.ts +16 -0
- package/dist/components/widgets/StatsWidget.js +39 -0
- package/dist/components/widgets/WidgetRenderer.d.ts +10 -0
- package/dist/components/widgets/WidgetRenderer.js +50 -0
- package/dist/components/widgets/WidgetShell.d.ts +9 -0
- package/dist/components/widgets/WidgetShell.js +7 -0
- package/dist/contexts/AuthChallengeRegistryContext.d.ts +15 -0
- package/dist/contexts/AuthChallengeRegistryContext.js +15 -0
- package/dist/contexts/BlockRegistryContext.d.ts +18 -0
- package/dist/contexts/BlockRegistryContext.js +8 -0
- package/dist/contexts/ColumnRegistryContext.d.ts +8 -0
- package/dist/contexts/ColumnRegistryContext.js +30 -0
- package/dist/contexts/FieldRegistryContext.d.ts +13 -0
- package/dist/contexts/FieldRegistryContext.js +46 -0
- package/dist/contexts/PanelMetadataContext.d.ts +26 -0
- package/dist/contexts/PanelMetadataContext.js +26 -0
- package/dist/contexts/PanelProviders.d.ts +27 -0
- package/dist/contexts/PanelProviders.js +24 -0
- package/dist/contexts/ResourceModalContext.d.ts +26 -0
- package/dist/contexts/ResourceModalContext.js +76 -0
- package/dist/contexts/SlotRegistryContext.d.ts +19 -0
- package/dist/contexts/SlotRegistryContext.js +24 -0
- package/dist/contexts/TableRefreshContext.d.ts +10 -0
- package/dist/contexts/TableRefreshContext.js +30 -0
- package/dist/contexts/WidgetRegistryContext.d.ts +17 -0
- package/dist/contexts/WidgetRegistryContext.js +14 -0
- package/dist/contexts/createRegistryContext.d.ts +19 -0
- package/dist/contexts/createRegistryContext.js +20 -0
- package/dist/hooks/useAfterStateUpdated.d.ts +6 -0
- package/dist/hooks/useAfterStateUpdated.js +62 -0
- package/dist/hooks/useValidation.d.ts +26 -0
- package/dist/hooks/useValidation.js +76 -0
- package/dist/i18n/I18nProvider.d.ts +27 -0
- package/dist/i18n/I18nProvider.js +101 -0
- package/dist/i18n/LocaleSwitcher.d.ts +10 -0
- package/dist/i18n/LocaleSwitcher.js +30 -0
- package/dist/i18n/activeLocale.d.ts +11 -0
- package/dist/i18n/activeLocale.js +34 -0
- package/dist/i18n/buildClientI18n.d.ts +28 -0
- package/dist/i18n/buildClientI18n.js +67 -0
- package/dist/i18n/index.d.ts +11 -0
- package/dist/i18n/index.js +9 -0
- package/dist/i18n/locales/core/en.d.ts +225 -0
- package/dist/i18n/locales/core/en.js +252 -0
- package/dist/i18n/locales/core/index.d.ts +2 -0
- package/dist/i18n/locales/core/index.js +4 -0
- package/dist/i18n/locales/core/sq.d.ts +253 -0
- package/dist/i18n/locales/core/sq.js +255 -0
- package/dist/i18n/useFormatter.d.ts +18 -0
- package/dist/i18n/useFormatter.js +37 -0
- package/dist/i18n/useLocale.d.ts +11 -0
- package/dist/i18n/useLocale.js +11 -0
- package/dist/i18n/useTranslation.d.ts +12 -0
- package/dist/i18n/useTranslation.js +12 -0
- package/dist/index.d.ts +106 -0
- package/dist/index.js +101 -0
- package/dist/pages/ResourceListPage.d.ts +8 -0
- package/dist/pages/ResourceListPage.js +139 -0
- package/dist/plugin.d.ts +79 -0
- package/dist/plugin.js +34 -0
- package/dist/runtime/conditions.d.ts +35 -0
- package/dist/runtime/conditions.js +97 -0
- package/dist/runtime/formTraversal.d.ts +25 -0
- package/dist/runtime/formTraversal.js +37 -0
- package/dist/runtime/serializedFunctions.d.ts +41 -0
- package/dist/runtime/serializedFunctions.js +264 -0
- package/dist/slots/Slot.d.ts +24 -0
- package/dist/slots/Slot.js +29 -0
- package/dist/slots/SlotCluster.d.ts +22 -0
- package/dist/slots/SlotCluster.js +49 -0
- package/dist/slots/index.d.ts +7 -0
- package/dist/slots/index.js +4 -0
- package/dist/slots/mergeSlots.d.ts +18 -0
- package/dist/slots/mergeSlots.js +35 -0
- package/dist/slots/types.d.ts +87 -0
- package/dist/slots/types.js +30 -0
- package/dist/styles.css +1 -0
- package/dist/table/TableContext.d.ts +36 -0
- package/dist/table/TableContext.js +13 -0
- package/dist/table/TableRenderer.d.ts +29 -0
- package/dist/table/TableRenderer.js +159 -0
- package/dist/table/components/FiltersPanel.d.ts +11 -0
- package/dist/table/components/FiltersPanel.js +52 -0
- package/dist/table/components/TableToolbar.d.ts +28 -0
- package/dist/table/components/TableToolbar.js +27 -0
- package/dist/table/components/TableToolbarButton.d.ts +6 -0
- package/dist/table/components/TableToolbarButton.js +9 -0
- package/dist/table/components/TableView.d.ts +12 -0
- package/dist/table/components/TableView.js +21 -0
- package/dist/table/defaultRowActions.d.ts +21 -0
- package/dist/table/defaultRowActions.js +37 -0
- package/dist/table/hooks/useColumnVisibility.d.ts +13 -0
- package/dist/table/hooks/useColumnVisibility.js +59 -0
- package/dist/table/hooks/useEditableRows.d.ts +22 -0
- package/dist/table/hooks/useEditableRows.js +63 -0
- package/dist/table/hooks/useTableActions.d.ts +54 -0
- package/dist/table/hooks/useTableActions.js +313 -0
- package/dist/table/hooks/useTableData.d.ts +28 -0
- package/dist/table/hooks/useTableData.js +63 -0
- package/dist/table/hooks/useTableLayout.d.ts +12 -0
- package/dist/table/hooks/useTableLayout.js +31 -0
- package/dist/table/hooks/useTableQuery.d.ts +29 -0
- package/dist/table/hooks/useTableQuery.js +135 -0
- package/dist/types/index.d.ts +224 -0
- package/dist/types/index.js +6 -0
- package/dist/utils/classNames.d.ts +7 -0
- package/dist/utils/classNames.js +9 -0
- package/dist/utils/columnMediaDimensions.d.ts +13 -0
- package/dist/utils/columnMediaDimensions.js +29 -0
- package/dist/utils/columnVisibilityStorage.d.ts +22 -0
- package/dist/utils/columnVisibilityStorage.js +56 -0
- package/dist/utils/fieldErrors.d.ts +13 -0
- package/dist/utils/fieldErrors.js +25 -0
- package/dist/utils/formatValue.d.ts +28 -0
- package/dist/utils/formatValue.js +109 -0
- package/dist/utils/layoutStorage.d.ts +23 -0
- package/dist/utils/layoutStorage.js +53 -0
- package/dist/utils/redirectHandler.d.ts +7 -0
- package/dist/utils/redirectHandler.js +25 -0
- package/dist/utils/tableFormatters.d.ts +14 -0
- package/dist/utils/tableFormatters.js +93 -0
- package/dist/utils/widgetVisibilityStorage.d.ts +11 -0
- package/dist/utils/widgetVisibilityStorage.js +39 -0
- package/package.json +101 -0
- package/src/FieldRenderer.test.tsx +44 -0
- package/src/FieldRenderer.tsx +104 -0
- package/src/FormRenderer.containers.test.tsx +121 -0
- package/src/FormRenderer.test.tsx +174 -0
- package/src/FormRenderer.tsx +140 -0
- package/src/TableRenderer.tsx +2 -0
- package/src/api/actionsApi.ts +76 -0
- package/src/api/authenticatedFetch.ts +40 -0
- package/src/api/exportApi.ts +66 -0
- package/src/api/http.test.ts +58 -0
- package/src/api/http.ts +68 -0
- package/src/api/resourceApi.ts +88 -0
- package/src/api/tableApi.test.ts +108 -0
- package/src/api/tableApi.ts +107 -0
- package/src/api/urls.ts +50 -0
- package/src/app.test.tsx +67 -0
- package/src/app.tsx +181 -0
- package/src/auth/AuthContext.tsx +188 -0
- package/src/auth/LoginPage.tsx +380 -0
- package/src/auth/ProtectedRoute.tsx +39 -0
- package/src/auth/authApiClient.ts +109 -0
- package/src/auth/authFlow.test.tsx +168 -0
- package/src/auth/types.ts +104 -0
- package/src/components/ActionFormModal.tsx +45 -0
- package/src/components/AdminPanel.tsx +368 -0
- package/src/components/Checkbox.tsx +59 -0
- package/src/components/CheckboxField.tsx +88 -0
- package/src/components/ColorPickerField.tsx +93 -0
- package/src/components/DateTimePickerField.tsx +112 -0
- package/src/components/FileUploadField.tsx +841 -0
- package/src/components/GlobalSearch.tsx +436 -0
- package/src/components/GroupField.tsx +85 -0
- package/src/components/HiddenField.tsx +14 -0
- package/src/components/ModalBreadcrumb.tsx +74 -0
- package/src/components/ModalDrawer.tsx +137 -0
- package/src/components/RadioField.tsx +80 -0
- package/src/components/RepeaterField.tsx +546 -0
- package/src/components/ResourceModalRenderer.tsx +144 -0
- package/src/components/RichEditorField.tsx +942 -0
- package/src/components/SectionField.tsx +242 -0
- package/src/components/SelectField.tsx +843 -0
- package/src/components/TabsField.test.tsx +151 -0
- package/src/components/TabsField.tsx +386 -0
- package/src/components/TagsInputField.tsx +411 -0
- package/src/components/TextInputField.tsx +91 -0
- package/src/components/TextareaField.tsx +110 -0
- package/src/components/ToggleField.tsx +126 -0
- package/src/components/ViewModal.tsx +353 -0
- package/src/components/blocks/BlockRenderer.tsx +56 -0
- package/src/components/blocks/FormBlockRenderer.tsx +160 -0
- package/src/components/blocks/TableBlockRenderer.tsx +33 -0
- package/src/components/blocks/TabsBlockRenderer.tsx +49 -0
- package/src/components/blocks/WidgetBlockRenderer.tsx +19 -0
- package/src/components/columns/CheckboxColumnComponent.tsx +38 -0
- package/src/components/columns/ColorColumnComponent.tsx +23 -0
- package/src/components/columns/CustomColumn.test.tsx +55 -0
- package/src/components/columns/DeeplinkWrapper.tsx +103 -0
- package/src/components/columns/IconColumnComponent.tsx +55 -0
- package/src/components/columns/ImageColumnComponent.tsx +220 -0
- package/src/components/columns/MediaColumnComponent.tsx +294 -0
- package/src/components/columns/SelectColumnComponent.tsx +49 -0
- package/src/components/columns/TagsColumnComponent.tsx +46 -0
- package/src/components/columns/TextColumnComponent.tsx +191 -0
- package/src/components/columns/TextInputColumnComponent.tsx +35 -0
- package/src/components/columns/ToggleColumnComponent.tsx +56 -0
- package/src/components/columns/VideoColumnComponent.tsx +236 -0
- package/src/components/columns/ViewColumnComponent.tsx +9 -0
- package/src/components/errors/ErrorBoundary.tsx +58 -0
- package/src/components/filters/CustomFilterComponent.tsx +130 -0
- package/src/components/filters/DateFilterComponent.tsx +272 -0
- package/src/components/filters/QueryBuilderFilterComponent.tsx +502 -0
- package/src/components/layout/Header.tsx +212 -0
- package/src/components/layout/PanelBrandMark.tsx +61 -0
- package/src/components/layout/Sidebar.tsx +283 -0
- package/src/components/modals/RelationCreateModal.tsx +107 -0
- package/src/components/modals/ResourceFormModal.test.tsx +119 -0
- package/src/components/modals/ResourceFormModal.tsx +128 -0
- package/src/components/modals/useResourceForm.ts +207 -0
- package/src/components/modals/view/RecordActions.tsx +69 -0
- package/src/components/modals/view/RecordDetails.tsx +60 -0
- package/src/components/modals/view/RelationPanel.tsx +76 -0
- package/src/components/modals/view/RelationTabs.tsx +145 -0
- package/src/components/modals/view/useRecordView.ts +134 -0
- package/src/components/pages/PageRenderer.tsx +173 -0
- package/src/components/table/ColumnTogglePopup.tsx +85 -0
- package/src/components/table/GridCard.tsx +155 -0
- package/src/components/table/GridView.tsx +138 -0
- package/src/components/table/LayoutToggle.tsx +24 -0
- package/src/components/table/TableActionsDropdown.tsx +114 -0
- package/src/components/table/TableBulkActions.tsx +65 -0
- package/src/components/table/TableHeader.tsx +96 -0
- package/src/components/table/TablePagination.tsx +169 -0
- package/src/components/table/TableRow.tsx +155 -0
- package/src/components/table/TableSearchBar.tsx +66 -0
- package/src/components/table/TableTabs.tsx +49 -0
- package/src/components/ui/Badge.tsx +30 -0
- package/src/components/ui/Button.test.tsx +78 -0
- package/src/components/ui/Button.tsx +102 -0
- package/src/components/ui/Card.tsx +23 -0
- package/src/components/ui/ConfirmDialog.tsx +112 -0
- package/src/components/ui/EmptyState.tsx +24 -0
- package/src/components/ui/ErrorAlert.tsx +37 -0
- package/src/components/ui/Input.tsx +48 -0
- package/src/components/ui/Label.tsx +15 -0
- package/src/components/ui/PillButton.tsx +72 -0
- package/src/components/ui/Select.tsx +33 -0
- package/src/components/ui/Spinner.tsx +39 -0
- package/src/components/ui/Toast.tsx +105 -0
- package/src/components/ui/index.ts +24 -0
- package/src/components/utils/HintDisplay.tsx +26 -0
- package/src/components/utils/Icon.tsx +36 -0
- package/src/components/utils/MediaPreviewModal.tsx +114 -0
- package/src/components/utils/ViewFieldWrapper.tsx +23 -0
- package/src/components/utils/layoutHelpers.ts +267 -0
- package/src/components/widgets/ChartWidget.tsx +247 -0
- package/src/components/widgets/StatsWidget.tsx +72 -0
- package/src/components/widgets/WidgetRenderer.tsx +108 -0
- package/src/components/widgets/WidgetShell.tsx +37 -0
- package/src/contexts/AuthChallengeRegistryContext.tsx +29 -0
- package/src/contexts/BlockRegistryContext.tsx +28 -0
- package/src/contexts/ColumnRegistryContext.tsx +38 -0
- package/src/contexts/FieldRegistryContext.tsx +56 -0
- package/src/contexts/PanelMetadataContext.tsx +60 -0
- package/src/contexts/PanelProviders.tsx +85 -0
- package/src/contexts/ResourceModalContext.tsx +137 -0
- package/src/contexts/SlotRegistryContext.tsx +35 -0
- package/src/contexts/TableRefreshContext.tsx +44 -0
- package/src/contexts/WidgetRegistryContext.tsx +34 -0
- package/src/contexts/createRegistryContext.tsx +29 -0
- package/src/hooks/useAfterStateUpdated.ts +70 -0
- package/src/hooks/useValidation.test.ts +59 -0
- package/src/hooks/useValidation.ts +95 -0
- package/src/i18n/I18nProvider.tsx +128 -0
- package/src/i18n/LocaleSwitcher.tsx +50 -0
- package/src/i18n/activeLocale.ts +39 -0
- package/src/i18n/buildClientI18n.ts +101 -0
- package/src/i18n/i18n.test.tsx +140 -0
- package/src/i18n/index.ts +12 -0
- package/src/i18n/locales/core/en.ts +274 -0
- package/src/i18n/locales/core/index.ts +5 -0
- package/src/i18n/locales/core/sq.ts +275 -0
- package/src/i18n/useFormatter.ts +42 -0
- package/src/i18n/useLocale.ts +16 -0
- package/src/i18n/useTranslation.ts +17 -0
- package/src/index.ts +244 -0
- package/src/pages/ResourceListPage.tsx +205 -0
- package/src/plugin.ts +110 -0
- package/src/runtime/conditions.test.ts +99 -0
- package/src/runtime/conditions.ts +148 -0
- package/src/runtime/formTraversal.ts +41 -0
- package/src/runtime/serializedFunctions.test.ts +59 -0
- package/src/runtime/serializedFunctions.ts +284 -0
- package/src/slots/Slot.test.tsx +89 -0
- package/src/slots/Slot.tsx +47 -0
- package/src/slots/SlotCluster.test.tsx +95 -0
- package/src/slots/SlotCluster.tsx +107 -0
- package/src/slots/index.ts +15 -0
- package/src/slots/mergeSlots.test.ts +71 -0
- package/src/slots/mergeSlots.ts +40 -0
- package/src/slots/slotNames.test.ts +21 -0
- package/src/slots/types.ts +119 -0
- package/src/styles.css +437 -0
- package/src/table/TableContext.tsx +41 -0
- package/src/table/TableRenderer.test.tsx +197 -0
- package/src/table/TableRenderer.tsx +390 -0
- package/src/table/components/FiltersPanel.tsx +193 -0
- package/src/table/components/TableToolbar.tsx +153 -0
- package/src/table/components/TableToolbarButton.tsx +14 -0
- package/src/table/components/TableView.tsx +106 -0
- package/src/table/defaultRowActions.ts +43 -0
- package/src/table/hooks/useColumnVisibility.test.ts +51 -0
- package/src/table/hooks/useColumnVisibility.ts +71 -0
- package/src/table/hooks/useEditableRows.test.ts +69 -0
- package/src/table/hooks/useEditableRows.ts +89 -0
- package/src/table/hooks/useTableActions.ts +393 -0
- package/src/table/hooks/useTableData.ts +89 -0
- package/src/table/hooks/useTableLayout.ts +45 -0
- package/src/table/hooks/useTableQuery.test.ts +116 -0
- package/src/table/hooks/useTableQuery.ts +172 -0
- package/src/test/mockFetch.ts +67 -0
- package/src/test/setup.ts +25 -0
- package/src/types/index.ts +228 -0
- package/src/utils/classNames.ts +10 -0
- package/src/utils/columnMediaDimensions.ts +45 -0
- package/src/utils/columnVisibilityStorage.ts +55 -0
- package/src/utils/fieldErrors.test.ts +35 -0
- package/src/utils/fieldErrors.ts +27 -0
- package/src/utils/formatValue.test.tsx +65 -0
- package/src/utils/formatValue.tsx +117 -0
- package/src/utils/layoutStorage.ts +52 -0
- package/src/utils/redirectHandler.ts +29 -0
- package/src/utils/tableFormatters.test.ts +54 -0
- package/src/utils/tableFormatters.ts +104 -0
- package/src/utils/widgetVisibilityStorage.ts +38 -0
- package/tailwind.config.js +9 -0
- package/vite.config.ts +17 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import React, { createContext, useContext, useState, useEffect, useCallback, useRef } from 'react';
|
|
2
|
+
import { AuthUser, LoginCredentials, PendingChallenge } from './types';
|
|
3
|
+
import { AuthApiClient } from './authApiClient';
|
|
4
|
+
|
|
5
|
+
interface AuthContextValue {
|
|
6
|
+
user: AuthUser | null;
|
|
7
|
+
loading: boolean;
|
|
8
|
+
/** A challenge (e.g. 2FA) awaiting the user's response, or null. */
|
|
9
|
+
pendingChallenge: PendingChallenge | null;
|
|
10
|
+
login: (provider: string, credentials: LoginCredentials) => Promise<void>;
|
|
11
|
+
/** Submit a response to the active `pendingChallenge`. */
|
|
12
|
+
verifyChallenge: (payload: unknown) => Promise<void>;
|
|
13
|
+
/** Abandon the active challenge and return to the login form. */
|
|
14
|
+
cancelChallenge: () => void;
|
|
15
|
+
logout: () => Promise<void>;
|
|
16
|
+
refreshUser: () => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const AuthContext = createContext<AuthContextValue | null>(null);
|
|
20
|
+
|
|
21
|
+
interface AuthProviderProps {
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
apiBaseUrl: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function AuthProvider({ children, apiBaseUrl }: AuthProviderProps) {
|
|
27
|
+
const [user, setUser] = useState<AuthUser | null>(null);
|
|
28
|
+
const [loading, setLoading] = useState(true);
|
|
29
|
+
const [pendingChallenge, setPendingChallenge] = useState<PendingChallenge | null>(null);
|
|
30
|
+
const apiClient = useRef(new AuthApiClient(apiBaseUrl));
|
|
31
|
+
const refreshTimerRef = useRef<NodeJS.Timeout | null>(null);
|
|
32
|
+
|
|
33
|
+
const scheduleTokenRefresh = useCallback((expiresIn: number) => {
|
|
34
|
+
if (refreshTimerRef.current) {
|
|
35
|
+
clearTimeout(refreshTimerRef.current);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Refresh 1 minute before expiry, minimum 1 minute
|
|
39
|
+
const refreshTime = Math.max((expiresIn - 60) * 1000, 60000);
|
|
40
|
+
|
|
41
|
+
refreshTimerRef.current = setTimeout(async () => {
|
|
42
|
+
try {
|
|
43
|
+
const tokens = await apiClient.current.refreshToken();
|
|
44
|
+
if (tokens?.expiresIn) {
|
|
45
|
+
scheduleTokenRefresh(tokens.expiresIn);
|
|
46
|
+
} else {
|
|
47
|
+
setUser(null);
|
|
48
|
+
}
|
|
49
|
+
} catch {
|
|
50
|
+
setUser(null);
|
|
51
|
+
}
|
|
52
|
+
}, refreshTime);
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Fetch the current user from /auth/me.
|
|
57
|
+
* On 401, attempts a silent token refresh via the cookie before giving up.
|
|
58
|
+
* Seeds the proactive refresh timer when a refresh response includes expiresIn.
|
|
59
|
+
*/
|
|
60
|
+
const fetchUser = useCallback(async () => {
|
|
61
|
+
try {
|
|
62
|
+
const currentUser = await apiClient.current.getCurrentUser();
|
|
63
|
+
setUser(currentUser);
|
|
64
|
+
return currentUser;
|
|
65
|
+
} catch (error: any) {
|
|
66
|
+
if (error?.status === 401) {
|
|
67
|
+
try {
|
|
68
|
+
const tokens = await apiClient.current.refreshToken();
|
|
69
|
+
if (tokens) {
|
|
70
|
+
if (tokens.expiresIn) scheduleTokenRefresh(tokens.expiresIn);
|
|
71
|
+
const currentUser = await apiClient.current.getCurrentUser();
|
|
72
|
+
setUser(currentUser);
|
|
73
|
+
return currentUser;
|
|
74
|
+
}
|
|
75
|
+
} catch {
|
|
76
|
+
// refresh failed — fall through to null
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
setUser(null);
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}, [scheduleTokenRefresh]);
|
|
83
|
+
|
|
84
|
+
/** Apply an `authenticated` result: set the user and seed the refresh timer. */
|
|
85
|
+
const applyAuthenticated = useCallback(
|
|
86
|
+
(authUser: AuthUser, expiresIn?: number) => {
|
|
87
|
+
setPendingChallenge(null);
|
|
88
|
+
setUser(authUser);
|
|
89
|
+
if (expiresIn) {
|
|
90
|
+
scheduleTokenRefresh(expiresIn);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
[scheduleTokenRefresh],
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const login = useCallback(
|
|
97
|
+
async (provider: string, credentials: LoginCredentials) => {
|
|
98
|
+
const result = await apiClient.current.login(provider, credentials);
|
|
99
|
+
if (result.status === 'authenticated') {
|
|
100
|
+
applyAuthenticated(result.user, result.tokens?.expiresIn);
|
|
101
|
+
} else {
|
|
102
|
+
// Pause here: a challenge (e.g. 2FA) must be satisfied before tokens are issued.
|
|
103
|
+
setPendingChallenge(result.challenge);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
[applyAuthenticated],
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const verifyChallenge = useCallback(
|
|
110
|
+
async (payload: unknown) => {
|
|
111
|
+
if (!pendingChallenge) {
|
|
112
|
+
throw new Error('No challenge in progress');
|
|
113
|
+
}
|
|
114
|
+
const result = await apiClient.current.verifyChallenge(
|
|
115
|
+
pendingChallenge.challengeToken,
|
|
116
|
+
pendingChallenge.type,
|
|
117
|
+
payload,
|
|
118
|
+
);
|
|
119
|
+
if (result.status === 'authenticated') {
|
|
120
|
+
applyAuthenticated(result.user, result.tokens?.expiresIn);
|
|
121
|
+
} else {
|
|
122
|
+
// Chained step: replace with the next pending challenge.
|
|
123
|
+
setPendingChallenge(result.challenge);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
[pendingChallenge, applyAuthenticated],
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const cancelChallenge = useCallback(() => {
|
|
130
|
+
setPendingChallenge(null);
|
|
131
|
+
}, []);
|
|
132
|
+
|
|
133
|
+
const logout = useCallback(async () => {
|
|
134
|
+
try {
|
|
135
|
+
await apiClient.current.logout();
|
|
136
|
+
} catch {
|
|
137
|
+
// ignore
|
|
138
|
+
} finally {
|
|
139
|
+
setUser(null);
|
|
140
|
+
setPendingChallenge(null);
|
|
141
|
+
if (refreshTimerRef.current) {
|
|
142
|
+
clearTimeout(refreshTimerRef.current);
|
|
143
|
+
refreshTimerRef.current = null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}, []);
|
|
147
|
+
|
|
148
|
+
const refreshUser = useCallback(async () => {
|
|
149
|
+
await fetchUser();
|
|
150
|
+
}, [fetchUser]);
|
|
151
|
+
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
const init = async () => {
|
|
154
|
+
setLoading(true);
|
|
155
|
+
await fetchUser();
|
|
156
|
+
setLoading(false);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
init();
|
|
160
|
+
|
|
161
|
+
return () => {
|
|
162
|
+
if (refreshTimerRef.current) {
|
|
163
|
+
clearTimeout(refreshTimerRef.current);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}, [fetchUser]);
|
|
167
|
+
|
|
168
|
+
const value: AuthContextValue = {
|
|
169
|
+
user,
|
|
170
|
+
loading,
|
|
171
|
+
pendingChallenge,
|
|
172
|
+
login,
|
|
173
|
+
verifyChallenge,
|
|
174
|
+
cancelChallenge,
|
|
175
|
+
logout,
|
|
176
|
+
refreshUser,
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function useAuth(): AuthContextValue {
|
|
183
|
+
const context = useContext(AuthContext);
|
|
184
|
+
if (!context) {
|
|
185
|
+
throw new Error('useAuth must be used within an AuthProvider');
|
|
186
|
+
}
|
|
187
|
+
return context;
|
|
188
|
+
}
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import React, { useState, useEffect, useMemo } from 'react';
|
|
2
|
+
import { AuthProvider, LoginCredentials, PendingChallenge } from './types';
|
|
3
|
+
import { AuthApiClient } from './authApiClient';
|
|
4
|
+
import { useAuth } from './AuthContext';
|
|
5
|
+
import { useAuthChallengeRegistry } from '../contexts/AuthChallengeRegistryContext';
|
|
6
|
+
import { Icon } from '../components/utils/Icon';
|
|
7
|
+
import { cn } from '../utils/classNames';
|
|
8
|
+
import { Button, IconButton, Input, Label, ErrorAlert, Spinner } from '../components/ui';
|
|
9
|
+
import { PanelBrandMark } from '../components/layout/PanelBrandMark';
|
|
10
|
+
import { Moon, Sun, ArrowLeft } from 'lucide-react';
|
|
11
|
+
import { useTranslation } from '../i18n/useTranslation';
|
|
12
|
+
import { LocaleSwitcher } from '../i18n/LocaleSwitcher';
|
|
13
|
+
import { Slot } from '../slots/Slot';
|
|
14
|
+
import { translate } from '../i18n/activeLocale';
|
|
15
|
+
|
|
16
|
+
interface PanelBranding {
|
|
17
|
+
title?: string;
|
|
18
|
+
icon?: string;
|
|
19
|
+
favicon?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface LoginPageProps {
|
|
23
|
+
apiBaseUrl: string;
|
|
24
|
+
onSuccess?: () => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function useDarkMode() {
|
|
28
|
+
const [darkMode, setDarkMode] = useState(() => {
|
|
29
|
+
const stored = localStorage.getItem('darkMode');
|
|
30
|
+
if (stored !== null) {
|
|
31
|
+
return stored === 'true';
|
|
32
|
+
}
|
|
33
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
document.documentElement.classList.toggle('dark', darkMode);
|
|
38
|
+
localStorage.setItem('darkMode', String(darkMode));
|
|
39
|
+
}, [darkMode]);
|
|
40
|
+
|
|
41
|
+
return [darkMode, setDarkMode] as const;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Returns the i18n key for the login subtitle (translated at the call site). */
|
|
45
|
+
function getSubtitleKey(providers: AuthProvider[], selectedProvider: AuthProvider | null): string {
|
|
46
|
+
if (providers.length > 1 && !selectedProvider) {
|
|
47
|
+
return 'core:auth.choose_provider';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const provider = selectedProvider ?? providers[0];
|
|
51
|
+
if (provider?.type === 'oauth') {
|
|
52
|
+
return 'core:auth.continue';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return 'core:auth.enter_credentials';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface ProviderButtonProps {
|
|
59
|
+
provider: AuthProvider;
|
|
60
|
+
onSelect: (provider: AuthProvider) => void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function ProviderButton({ provider, onSelect }: ProviderButtonProps) {
|
|
64
|
+
const hasCustomStyle = Boolean(provider.buttonStyle?.backgroundColor);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Button
|
|
68
|
+
type="button"
|
|
69
|
+
variant={hasCustomStyle ? 'primary' : 'secondary'}
|
|
70
|
+
className={cn('w-full h-11', hasCustomStyle && 'border-transparent')}
|
|
71
|
+
style={
|
|
72
|
+
hasCustomStyle
|
|
73
|
+
? {
|
|
74
|
+
backgroundColor: provider.buttonStyle!.backgroundColor,
|
|
75
|
+
color: provider.buttonStyle!.textColor || '#ffffff',
|
|
76
|
+
borderColor: provider.buttonStyle!.borderColor || provider.buttonStyle!.backgroundColor,
|
|
77
|
+
}
|
|
78
|
+
: undefined
|
|
79
|
+
}
|
|
80
|
+
icon={
|
|
81
|
+
provider.icon ? (
|
|
82
|
+
<Icon name={provider.icon as any} className={cn('h-4 w-4', !hasCustomStyle && 'text-fg')} />
|
|
83
|
+
) : undefined
|
|
84
|
+
}
|
|
85
|
+
onClick={() => onSelect(provider)}>
|
|
86
|
+
{provider.label}
|
|
87
|
+
</Button>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Renders the active login challenge (e.g. 2FA) using the plugin-registered component for
|
|
93
|
+
* its `type`. Owns the per-attempt submitting/error state and wires the challenge UI to
|
|
94
|
+
* `verifyChallenge` / `cancelChallenge` from the auth context.
|
|
95
|
+
*/
|
|
96
|
+
function ChallengeStep({ challenge }: { challenge: PendingChallenge }) {
|
|
97
|
+
const { t } = useTranslation();
|
|
98
|
+
const { verifyChallenge, cancelChallenge } = useAuth();
|
|
99
|
+
const registry = useAuthChallengeRegistry();
|
|
100
|
+
const ChallengeComponent = registry[challenge.type];
|
|
101
|
+
const [error, setError] = useState<string | null>(null);
|
|
102
|
+
const [submitting, setSubmitting] = useState(false);
|
|
103
|
+
|
|
104
|
+
if (!ChallengeComponent) {
|
|
105
|
+
return (
|
|
106
|
+
<div className="space-y-4">
|
|
107
|
+
<ErrorAlert message={`No UI is registered for challenge type "${challenge.type}".`} />
|
|
108
|
+
<Button
|
|
109
|
+
type="button"
|
|
110
|
+
variant="ghost"
|
|
111
|
+
size="sm"
|
|
112
|
+
className="-ml-2 h-8 px-2 text-fg-secondary"
|
|
113
|
+
icon={<ArrowLeft className="h-4 w-4" />}
|
|
114
|
+
onClick={cancelChallenge}>
|
|
115
|
+
{t('core:auth.back_to_signin')}
|
|
116
|
+
</Button>
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const handleSubmit = async (payload: unknown) => {
|
|
122
|
+
setSubmitting(true);
|
|
123
|
+
setError(null);
|
|
124
|
+
try {
|
|
125
|
+
await verifyChallenge(payload);
|
|
126
|
+
} catch (err: any) {
|
|
127
|
+
setError(err.message || t('core:auth.verification_failed'));
|
|
128
|
+
} finally {
|
|
129
|
+
setSubmitting(false);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<ChallengeComponent
|
|
135
|
+
data={challenge.data}
|
|
136
|
+
onSubmit={handleSubmit}
|
|
137
|
+
onCancel={cancelChallenge}
|
|
138
|
+
error={error}
|
|
139
|
+
submitting={submitting}
|
|
140
|
+
/>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* LoginPage - Displays authentication providers and handles login
|
|
146
|
+
*/
|
|
147
|
+
export function LoginPage({ apiBaseUrl, onSuccess }: LoginPageProps) {
|
|
148
|
+
const { t } = useTranslation();
|
|
149
|
+
const { login, pendingChallenge } = useAuth();
|
|
150
|
+
const [providers, setProviders] = useState<AuthProvider[]>([]);
|
|
151
|
+
const [loading, setLoading] = useState(true);
|
|
152
|
+
const [error, setError] = useState<string | null>(null);
|
|
153
|
+
const [selectedProvider, setSelectedProvider] = useState<AuthProvider | null>(null);
|
|
154
|
+
const [credentials, setCredentials] = useState<LoginCredentials>({ email: '', password: '' });
|
|
155
|
+
const [submitting, setSubmitting] = useState(false);
|
|
156
|
+
const [panelBranding, setPanelBranding] = useState<PanelBranding>({});
|
|
157
|
+
const [darkMode, setDarkMode] = useDarkMode();
|
|
158
|
+
|
|
159
|
+
const apiClient = useMemo(() => new AuthApiClient(apiBaseUrl), [apiBaseUrl]);
|
|
160
|
+
|
|
161
|
+
const showProviderPicker = providers.length > 1 && !selectedProvider;
|
|
162
|
+
const activeProvider = selectedProvider ?? (providers.length === 1 ? providers[0] : null);
|
|
163
|
+
const showCredentialsForm = activeProvider?.type === 'credentials';
|
|
164
|
+
const showOAuthPrompt = activeProvider?.type === 'oauth' && !showProviderPicker;
|
|
165
|
+
const showBackLink = providers.length > 1 && selectedProvider?.type === 'credentials';
|
|
166
|
+
|
|
167
|
+
const subtitle = useMemo(() => t(getSubtitleKey(providers, selectedProvider)), [providers, selectedProvider, t]);
|
|
168
|
+
|
|
169
|
+
// Load panel branding for the login screen (meta endpoint allows unauthenticated access)
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
const fetchBranding = async () => {
|
|
172
|
+
try {
|
|
173
|
+
const response = await fetch(`${apiBaseUrl}/meta`);
|
|
174
|
+
if (!response.ok) return;
|
|
175
|
+
const meta = await response.json();
|
|
176
|
+
setPanelBranding({
|
|
177
|
+
title: meta.title,
|
|
178
|
+
icon: meta.icon,
|
|
179
|
+
favicon: meta.favicon,
|
|
180
|
+
});
|
|
181
|
+
} catch {
|
|
182
|
+
// Branding is optional — fall back to defaults
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
fetchBranding();
|
|
187
|
+
}, [apiBaseUrl]);
|
|
188
|
+
|
|
189
|
+
// Fetch available providers
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
const fetchProviders = async () => {
|
|
192
|
+
try {
|
|
193
|
+
const providerList = await apiClient.getProviders();
|
|
194
|
+
setProviders(providerList);
|
|
195
|
+
if (providerList.length === 1) {
|
|
196
|
+
setSelectedProvider(providerList[0]);
|
|
197
|
+
}
|
|
198
|
+
} catch (err: any) {
|
|
199
|
+
setError(err.message || t('core:auth.providers_load_failed'));
|
|
200
|
+
} finally {
|
|
201
|
+
setLoading(false);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
fetchProviders();
|
|
206
|
+
}, [apiClient]);
|
|
207
|
+
|
|
208
|
+
const handleProviderSelect = (provider: AuthProvider) => {
|
|
209
|
+
if (provider.type === 'oauth') {
|
|
210
|
+
const redirectUri = encodeURIComponent(window.location.origin + window.location.pathname);
|
|
211
|
+
const authUrl = `${apiBaseUrl}/auth/oauth/${provider.name}?redirect_uri=${redirectUri}`;
|
|
212
|
+
window.location.href = authUrl;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
setSelectedProvider(provider);
|
|
217
|
+
setError(null);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const handleSubmit = async (e: React.FormEvent) => {
|
|
221
|
+
e.preventDefault();
|
|
222
|
+
if (!activeProvider) return;
|
|
223
|
+
|
|
224
|
+
setSubmitting(true);
|
|
225
|
+
setError(null);
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
await login(activeProvider.name, credentials);
|
|
229
|
+
onSuccess?.();
|
|
230
|
+
} catch (err: any) {
|
|
231
|
+
setError(err.message || t('core:auth.login_failed'));
|
|
232
|
+
} finally {
|
|
233
|
+
setSubmitting(false);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
if (loading) {
|
|
238
|
+
return (
|
|
239
|
+
<div className="flex min-h-screen items-center justify-center bg-base px-6">
|
|
240
|
+
<div className="text-center">
|
|
241
|
+
<Spinner size="lg" className="mx-auto text-accent" />
|
|
242
|
+
<p className="mt-4 text-sm text-fg-secondary">{translate('core:auth.preparing')}</p>
|
|
243
|
+
</div>
|
|
244
|
+
</div>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return (
|
|
249
|
+
<div className="relative flex min-h-screen items-center justify-center bg-base px-6 py-12">
|
|
250
|
+
<div className="pointer-events-none absolute inset-0 overflow-hidden" aria-hidden="true">
|
|
251
|
+
<div className="absolute -top-32 left-1/2 h-80 w-80 -translate-x-1/2 rounded-full bg-accent-soft/50 blur-3xl" />
|
|
252
|
+
<div className="absolute bottom-0 right-0 h-72 w-72 translate-x-1/4 translate-y-1/4 rounded-full bg-accent-soft/25 blur-3xl" />
|
|
253
|
+
</div>
|
|
254
|
+
|
|
255
|
+
<IconButton
|
|
256
|
+
variant="secondary"
|
|
257
|
+
size="sm"
|
|
258
|
+
aria-label={darkMode ? t('core:panel.toggle_light') : t('core:panel.toggle_dark')}
|
|
259
|
+
title={darkMode ? t('core:panel.toggle_light') : t('core:panel.toggle_dark')}
|
|
260
|
+
onClick={() => setDarkMode(!darkMode)}
|
|
261
|
+
className="absolute right-4 top-4 z-10 sm:right-6 sm:top-6">
|
|
262
|
+
{darkMode ? <Sun className="h-4 w-4 text-warning" /> : <Moon className="h-4 w-4" />}
|
|
263
|
+
</IconButton>
|
|
264
|
+
|
|
265
|
+
<div className="relative w-full max-w-[420px]">
|
|
266
|
+
<header className="mb-8 text-center">
|
|
267
|
+
<div className="mx-auto mb-5 flex justify-center">
|
|
268
|
+
<PanelBrandMark icon={panelBranding.icon} favicon={panelBranding.favicon} size="lg" />
|
|
269
|
+
</div>
|
|
270
|
+
<h1 className="text-2xl font-semibold tracking-tight text-fg">
|
|
271
|
+
{pendingChallenge
|
|
272
|
+
? t('core:auth.verify_identity')
|
|
273
|
+
: panelBranding.title
|
|
274
|
+
? t('core:auth.sign_in_to', { title: panelBranding.title })
|
|
275
|
+
: t('core:auth.welcome_back')}
|
|
276
|
+
</h1>
|
|
277
|
+
<p className="mt-2 text-sm text-fg-secondary">
|
|
278
|
+
{pendingChallenge ? 'Complete the additional step to finish signing in' : subtitle}
|
|
279
|
+
</p>
|
|
280
|
+
</header>
|
|
281
|
+
|
|
282
|
+
<Slot name="login.top" as="div" className="mb-6 space-y-4 empty:hidden" />
|
|
283
|
+
|
|
284
|
+
<div className="rounded-xl border border-border bg-surface p-6 shadow-soft sm:p-8">
|
|
285
|
+
{pendingChallenge && <ChallengeStep challenge={pendingChallenge} />}
|
|
286
|
+
|
|
287
|
+
{!pendingChallenge && error && (
|
|
288
|
+
<ErrorAlert message={error} onDismiss={() => setError(null)} className="mb-6" />
|
|
289
|
+
)}
|
|
290
|
+
|
|
291
|
+
{!pendingChallenge && showProviderPicker && (
|
|
292
|
+
<div className="space-y-3">
|
|
293
|
+
{providers.map(provider => (
|
|
294
|
+
<ProviderButton
|
|
295
|
+
key={provider.name}
|
|
296
|
+
provider={provider}
|
|
297
|
+
onSelect={handleProviderSelect}
|
|
298
|
+
/>
|
|
299
|
+
))}
|
|
300
|
+
</div>
|
|
301
|
+
)}
|
|
302
|
+
|
|
303
|
+
{!pendingChallenge && showOAuthPrompt && activeProvider && (
|
|
304
|
+
<div className="space-y-4">
|
|
305
|
+
<ProviderButton provider={activeProvider} onSelect={handleProviderSelect} />
|
|
306
|
+
<p className="text-center text-xs text-fg-muted">
|
|
307
|
+
You will be redirected to {activeProvider.label} to complete sign in.
|
|
308
|
+
</p>
|
|
309
|
+
</div>
|
|
310
|
+
)}
|
|
311
|
+
|
|
312
|
+
{!pendingChallenge && showCredentialsForm && (
|
|
313
|
+
<form onSubmit={handleSubmit} className="space-y-5">
|
|
314
|
+
{showBackLink && (
|
|
315
|
+
<Button
|
|
316
|
+
type="button"
|
|
317
|
+
variant="ghost"
|
|
318
|
+
size="sm"
|
|
319
|
+
className="-ml-2 h-8 px-2 text-fg-secondary"
|
|
320
|
+
icon={<ArrowLeft className="h-4 w-4" />}
|
|
321
|
+
onClick={() => {
|
|
322
|
+
setSelectedProvider(null);
|
|
323
|
+
setError(null);
|
|
324
|
+
setCredentials({ email: '', password: '' });
|
|
325
|
+
}}>
|
|
326
|
+
{t('core:auth.back_to_options')}
|
|
327
|
+
</Button>
|
|
328
|
+
)}
|
|
329
|
+
|
|
330
|
+
<div className="space-y-2">
|
|
331
|
+
<Label htmlFor="email" required>
|
|
332
|
+
{t('core:auth.email')}
|
|
333
|
+
</Label>
|
|
334
|
+
<Input
|
|
335
|
+
id="email"
|
|
336
|
+
type="email"
|
|
337
|
+
required
|
|
338
|
+
value={credentials.email}
|
|
339
|
+
onChange={e => setCredentials({ ...credentials, email: e.target.value })}
|
|
340
|
+
placeholder={t('core:auth.email_placeholder')}
|
|
341
|
+
autoComplete="email"
|
|
342
|
+
autoFocus
|
|
343
|
+
/>
|
|
344
|
+
</div>
|
|
345
|
+
|
|
346
|
+
<div className="space-y-2">
|
|
347
|
+
<Label htmlFor="password" required>
|
|
348
|
+
{t('core:auth.password')}
|
|
349
|
+
</Label>
|
|
350
|
+
<Input
|
|
351
|
+
id="password"
|
|
352
|
+
type="password"
|
|
353
|
+
required
|
|
354
|
+
value={credentials.password}
|
|
355
|
+
onChange={e => setCredentials({ ...credentials, password: e.target.value })}
|
|
356
|
+
placeholder={t('core:auth.password_placeholder')}
|
|
357
|
+
autoComplete="current-password"
|
|
358
|
+
/>
|
|
359
|
+
</div>
|
|
360
|
+
|
|
361
|
+
<Button type="submit" loading={submitting} className="w-full h-11">
|
|
362
|
+
{t('core:auth.sign_in')}
|
|
363
|
+
</Button>
|
|
364
|
+
</form>
|
|
365
|
+
)}
|
|
366
|
+
|
|
367
|
+
{!pendingChallenge && !showProviderPicker && !showOAuthPrompt && !showCredentialsForm && (
|
|
368
|
+
<p className="text-center text-sm text-fg-secondary">{t('core:auth.no_providers')}</p>
|
|
369
|
+
)}
|
|
370
|
+
</div>
|
|
371
|
+
|
|
372
|
+
<Slot name="login.belowForm" as="div" className="mt-6 space-y-4 empty:hidden" />
|
|
373
|
+
|
|
374
|
+
<div className="mt-6 flex justify-center">
|
|
375
|
+
<LocaleSwitcher />
|
|
376
|
+
</div>
|
|
377
|
+
</div>
|
|
378
|
+
</div>
|
|
379
|
+
);
|
|
380
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useAuth } from './AuthContext';
|
|
3
|
+
import { Loader2 } from 'lucide-react';
|
|
4
|
+
import { LoginPage } from './LoginPage';
|
|
5
|
+
import { translate } from '../i18n/activeLocale';
|
|
6
|
+
|
|
7
|
+
interface ProtectedRouteProps {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
apiBaseUrl: string;
|
|
10
|
+
fallback?: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* ProtectedRoute - Wraps content that requires authentication
|
|
15
|
+
* Shows LoginPage if not authenticated, otherwise shows children
|
|
16
|
+
*/
|
|
17
|
+
export function ProtectedRoute({ children, apiBaseUrl, fallback }: ProtectedRouteProps) {
|
|
18
|
+
const { user, loading } = useAuth();
|
|
19
|
+
|
|
20
|
+
if (loading) {
|
|
21
|
+
return (
|
|
22
|
+
<div className="min-h-screen bg-base flex items-center justify-center">
|
|
23
|
+
<div className="text-center">
|
|
24
|
+
<Loader2 className="w-12 h-12 text-accent animate-spin mx-auto" />
|
|
25
|
+
<p className="mt-4 text-fg-secondary">{translate('core:common.loading_ellipsis')}</p>
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!user) {
|
|
32
|
+
if (fallback) {
|
|
33
|
+
return <>{fallback}</>;
|
|
34
|
+
}
|
|
35
|
+
return <LoginPage apiBaseUrl={apiBaseUrl} />;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return <>{children}</>;
|
|
39
|
+
}
|