@middag-io/react 0.44.1 → 0.45.2
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 +7 -0
- package/dist-lib/{FormField-Bj43PjHH.js → FormField-Csx8hGAW.js} +1956 -1936
- package/dist-lib/{FormPanelBlock-C6eDfGoI.js → FormPanelBlock-Bmd0DpiX.js} +337 -337
- package/dist-lib/base/blocks/DenseTableBlock.d.ts.map +1 -1
- package/dist-lib/base/blocks/LinkListBlock.d.ts +2 -1
- package/dist-lib/base/blocks/LinkListBlock.d.ts.map +1 -1
- package/dist-lib/base/form/FormField.d.ts.map +1 -1
- package/dist-lib/base/layout/DashboardLayout.d.ts.map +1 -1
- package/dist-lib/base/partials/ConfirmationDialog/index.d.ts.map +1 -1
- package/dist-lib/base/partials/DataTable/cell-renderers.d.ts +1 -1
- package/dist-lib/base/partials/DataTable/cell-renderers.d.ts.map +1 -1
- package/dist-lib/base/partials/DataTable/index.d.ts +1 -1
- package/dist-lib/base/partials/DataTable/index.d.ts.map +1 -1
- package/dist-lib/base/partials/DataTable/sanitize-html.d.ts +17 -0
- package/dist-lib/base/partials/DataTable/sanitize-html.d.ts.map +1 -0
- package/dist-lib/base/partials/DataTable/types.d.ts +15 -0
- package/dist-lib/base/partials/DataTable/types.d.ts.map +1 -1
- package/dist-lib/base/partials/FilterBar/index.d.ts.map +1 -1
- package/dist-lib/base/shell/BasicShell.js +1 -1
- package/dist-lib/base/shell/partials/InlineEditablePanel.js +38 -24
- package/dist-lib/base/shell/partials/PageActionButton.d.ts.map +1 -1
- package/dist-lib/base/shell/partials/PageActionButton.js +1 -1
- package/dist-lib/chunks/subpath-Bh1MAmBT.js +165 -0
- package/dist-lib/chunks/{subpath-AeMdleNB.js → subpath-fEhy6n_U.js} +10 -6
- package/dist-lib/contracts/block-data/data-display.d.ts +51 -2
- package/dist-lib/contracts/block-data/data-display.d.ts.map +1 -1
- package/dist-lib/contracts/generated/contract-schema.d.ts +1 -1
- package/dist-lib/contracts/generated/contract-types.d.ts +4 -2
- package/dist-lib/contracts/generated/contract-types.d.ts.map +1 -1
- package/dist-lib/contracts/generated/index.d.ts +1 -1
- package/dist-lib/i18n/I18nProvider.js +1 -1
- package/dist-lib/i18n/instance.js +1 -1
- package/dist-lib/i18n/locales/en/ui.json +5 -3
- package/dist-lib/i18n/locales/pt-BR/ui.json +5 -3
- package/dist-lib/i18n/register-strings.js +1 -1
- package/dist-lib/index.d.ts +1 -1
- package/dist-lib/index.d.ts.map +1 -1
- package/dist-lib/middag-react.css +1 -1
- package/dist-lib/middag-react.js +18641 -13317
- package/dist-lib/primitives/reui/chart.d.ts.map +1 -1
- package/dist-lib/primitives/reui/chart.js +35 -31
- package/docs/public/schemas/ai-contract-manifest.json +1820 -0
- package/docs/public/schemas/blocks.json +445 -0
- package/docs/public/schemas/components.json +166 -0
- package/docs/public/schemas/connectors.json +97 -0
- package/docs/public/schemas/fragment.json +2329 -0
- package/docs/public/schemas/manifest.json +119 -0
- package/docs/public/schemas/navigation.json +72 -0
- package/docs/public/schemas/page-contract.json +2329 -0
- package/docs/public/schemas/shared-props.json +118 -0
- package/docs/public/schemas/theme-defaults.json +253 -0
- package/docs/public/schemas/theme.json +401 -0
- package/package.json +109 -3
- package/src/assets/lottie/calendar/schedule-1.json +1 -0
- package/src/assets/lottie/calendar/schedule-2.json +1 -0
- package/src/assets/lottie/celebration/confetti-1.json +1 -0
- package/src/assets/lottie/celebration/confetti-2.json +1 -0
- package/src/assets/lottie/celebration/confetti-3.json +1 -0
- package/src/assets/lottie/cloud/cloud-1.json +1 -0
- package/src/assets/lottie/cloud/cloud-2.json +1 -0
- package/src/assets/lottie/connection/network-1.json +1 -0
- package/src/assets/lottie/connection/network-2.json +1 -0
- package/src/assets/lottie/connection/network-3.json +1 -0
- package/src/assets/lottie/dashboard/analytics-1.json +1 -0
- package/src/assets/lottie/dashboard/analytics-2.json +1 -0
- package/src/assets/lottie/dashboard/analytics-3.json +1 -0
- package/src/assets/lottie/email/mail-1.json +1 -0
- package/src/assets/lottie/email/mail-2.json +1 -0
- package/src/assets/lottie/email/mail-3.json +1 -0
- package/src/assets/lottie/empty-state/empty-1.json +1 -0
- package/src/assets/lottie/empty-state/empty-2.json +1 -0
- package/src/assets/lottie/empty-state/empty-3.json +1 -0
- package/src/assets/lottie/error/warning-1.json +1 -0
- package/src/assets/lottie/error/warning-2.json +1 -0
- package/src/assets/lottie/error/warning-3.json +1 -0
- package/src/assets/lottie/index.ts +49 -0
- package/src/assets/lottie/loading/spinner-1.json +1 -0
- package/src/assets/lottie/loading/spinner-2.json +1 -0
- package/src/assets/lottie/loading/spinner-3.json +1 -0
- package/src/assets/lottie/maintenance/construction-1.json +1 -0
- package/src/assets/lottie/maintenance/construction-2.json +1 -0
- package/src/assets/lottie/maintenance/construction-3.json +1 -0
- package/src/assets/lottie/not-found/404-1.json +1 -0
- package/src/assets/lottie/not-found/404-2.json +1 -0
- package/src/assets/lottie/not-found/404-3.json +1 -0
- package/src/assets/lottie/notification/bell-1.json +1 -0
- package/src/assets/lottie/notification/bell-2.json +1 -0
- package/src/assets/lottie/notification/bell-3.json +1 -0
- package/src/assets/lottie/onboarding/welcome-1.json +1 -0
- package/src/assets/lottie/onboarding/welcome-2.json +1 -0
- package/src/assets/lottie/onboarding/welcome-3.json +1 -0
- package/src/assets/lottie/payment/wallet-1.json +1 -0
- package/src/assets/lottie/payment/wallet-2.json +1 -0
- package/src/assets/lottie/payment/wallet-3.json +1 -0
- package/src/assets/lottie/search/search-1.json +1 -0
- package/src/assets/lottie/search/search-2.json +1 -0
- package/src/assets/lottie/search/search-3.json +1 -0
- package/src/assets/lottie/security/lock-1.json +1 -0
- package/src/assets/lottie/security/lock-2.json +1 -0
- package/src/assets/lottie/security/lock-3.json +1 -0
- package/src/assets/lottie/settings/gear-1.json +1 -0
- package/src/assets/lottie/settings/gear-2.json +1 -0
- package/src/assets/lottie/settings/gear-3.json +1 -0
- package/src/assets/lottie/success/check-1.json +1 -0
- package/src/assets/lottie/success/check-2.json +1 -0
- package/src/assets/lottie/success/check-3.json +1 -0
- package/src/assets/lottie/upload/upload-1.json +1 -0
- package/src/assets/lottie/upload/upload-2.json +1 -0
- package/src/assets/lottie/upload/upload-3.json +1 -0
- package/src/assets/lottie/user/profile-1.json +1 -0
- package/src/assets/lottie/user/profile-2.json +1 -0
- package/src/assets/lottie/user/profile-3.json +1 -0
- package/src/base/blocks/ActionGridBlock.tsx +151 -0
- package/src/base/blocks/ActivityTimelineBlock.tsx +180 -0
- package/src/base/blocks/CardGridBlock.tsx +384 -0
- package/src/base/blocks/ChartBlock.tsx +81 -0
- package/src/base/blocks/DenseTableBlock.tsx +403 -0
- package/src/base/blocks/DetailPanelBlock.tsx +189 -0
- package/src/base/blocks/EmptyStateBlock.tsx +46 -0
- package/src/base/blocks/FormPanelBlock.lazy.tsx +38 -0
- package/src/base/blocks/FormPanelBlock.tsx +480 -0
- package/src/base/blocks/LinkListBlock.tsx +94 -0
- package/src/base/blocks/MarkdownPanelBlock.tsx +60 -0
- package/src/base/blocks/MetricCardBlock.tsx +128 -0
- package/src/base/blocks/StatusStripBlock.tsx +43 -0
- package/src/base/blocks/TabsBlock.tsx +94 -0
- package/src/base/form/FormField.tsx +607 -0
- package/src/base/form/fields/CheckboxField.tsx +56 -0
- package/src/base/form/fields/ColorField.tsx +76 -0
- package/src/base/form/fields/CurrencyField.tsx +126 -0
- package/src/base/form/fields/DateField.tsx +168 -0
- package/src/base/form/fields/DateRangeField.tsx +66 -0
- package/src/base/form/fields/DocumentField.tsx +222 -0
- package/src/base/form/fields/EntityPickerField.tsx +244 -0
- package/src/base/form/fields/FileUploadField.tsx +253 -0
- package/src/base/form/fields/MultiSelectField.tsx +286 -0
- package/src/base/form/fields/NativeSelectField.tsx +67 -0
- package/src/base/form/fields/NumberField.tsx +67 -0
- package/src/base/form/fields/OtpField.tsx +88 -0
- package/src/base/form/fields/PasswordField.tsx +69 -0
- package/src/base/form/fields/PhoneField.tsx +64 -0
- package/src/base/form/fields/RadioField.tsx +66 -0
- package/src/base/form/fields/RatingField.tsx +52 -0
- package/src/base/form/fields/SelectField.tsx +76 -0
- package/src/base/form/fields/SliderField.tsx +77 -0
- package/src/base/form/fields/SlugField.tsx +114 -0
- package/src/base/form/fields/StaticField.tsx +25 -0
- package/src/base/form/fields/SwitchField.tsx +56 -0
- package/src/base/form/fields/TagsField.tsx +128 -0
- package/src/base/form/fields/TextField.tsx +55 -0
- package/src/base/form/fields/TextareaField.tsx +55 -0
- package/src/base/form/fields/document-validation.ts +126 -0
- package/src/base/form/fields/field-registry.ts +53 -0
- package/src/base/form/fields/register-default-fields.ts +86 -0
- package/src/base/form/form-schema-builder.ts +192 -0
- package/src/base/form/form-utils.ts +71 -0
- package/src/base/hooks/useIsDark.ts +50 -0
- package/src/base/hooks/useLazyTabs.ts +98 -0
- package/src/base/hooks/usePolling.ts +43 -0
- package/src/base/hooks/useRemember.ts +58 -0
- package/src/base/hooks/useToast.ts +27 -0
- package/src/base/layout/BlockRegion.tsx +39 -0
- package/src/base/layout/DashboardLayout.tsx +110 -0
- package/src/base/layout/SidebarLayout.tsx +38 -0
- package/src/base/layout/StackLayout.tsx +32 -0
- package/src/base/layout/WizardLayout.tsx +49 -0
- package/src/base/partials/ActionBar/index.tsx +115 -0
- package/src/base/partials/ConfirmationDialog/index.tsx +128 -0
- package/src/base/partials/DataTable/cell-registry.ts +50 -0
- package/src/base/partials/DataTable/cell-renderers.tsx +372 -0
- package/src/base/partials/DataTable/index.tsx +1282 -0
- package/src/base/partials/DataTable/register-default-cells.ts +37 -0
- package/src/base/partials/DataTable/sanitize-html.ts +45 -0
- package/src/base/partials/DataTable/types.ts +229 -0
- package/src/base/partials/DetailSection/index.tsx +316 -0
- package/src/base/partials/EmptyPlaceholder/index.tsx +162 -0
- package/src/base/partials/EntityItem/index.tsx +154 -0
- package/src/base/partials/FilterBar/index.tsx +256 -0
- package/src/base/partials/FormSection/index.tsx +87 -0
- package/src/base/partials/LogViewer/JsonBlock.tsx +39 -0
- package/src/base/partials/LogViewer/LogEntry.tsx +68 -0
- package/src/base/partials/LogViewer/LogViewerToolbar.tsx +71 -0
- package/src/base/partials/LogViewer/index.tsx +110 -0
- package/src/base/partials/LogViewer/types.ts +28 -0
- package/src/base/partials/MarkdownContent/index.tsx +307 -0
- package/src/base/partials/MenuBar/index.tsx +80 -0
- package/src/base/partials/QuickRecordSheet/index.tsx +59 -0
- package/src/base/partials/ResizableSidebar/index.tsx +70 -0
- package/src/base/partials/StatRow/index.tsx +28 -0
- package/src/base/partials/StatusBar/index.tsx +126 -0
- package/src/base/partials/StatusIndicator/index.tsx +61 -0
- package/src/base/partials/StepIndicator/index.tsx +63 -0
- package/src/base/partials/TableOfContents/index.tsx +78 -0
- package/src/base/partials/TimelineList/index.tsx +273 -0
- package/src/base/partials/ToggleGroupControl/index.tsx +100 -0
- package/src/base/partials/TreeView/index.tsx +75 -0
- package/src/base/partials/index.ts +23 -0
- package/src/base/shell/AuthShell.tsx +54 -0
- package/src/base/shell/BasicShell.tsx +286 -0
- package/src/base/shell/ImmersiveShell.tsx +85 -0
- package/src/base/shell/partials/EditablePanelContext.tsx +82 -0
- package/src/base/shell/partials/EditablePanelProvider.tsx +122 -0
- package/src/base/shell/partials/InlineEditablePanel.tsx +239 -0
- package/src/base/shell/partials/InspectorContext.tsx +173 -0
- package/src/base/shell/partials/InspectorPanel.tsx +65 -0
- package/src/base/shell/partials/NavErrorBoundary.tsx +82 -0
- package/src/base/shell/partials/OverlayScreen.tsx +67 -0
- package/src/base/shell/partials/PageActionButton.tsx +203 -0
- package/src/base/theme/appearance.ts +133 -0
- package/src/base/theme/host-layout-detector.ts +119 -0
- package/src/base/theme/host-theme-detector.ts +146 -0
- package/src/base/theme/sidebar-safelist.txt +20 -0
- package/src/base/theme/tailwind-theme.css +136 -0
- package/src/base/theme/theme-bridge.css +164 -0
- package/src/base/theme/theme-context.tsx +142 -0
- package/src/base/theme/themes/classic.css +174 -0
- package/src/base/theme/tokens.css +290 -0
- package/src/base/theme/useHostTheme.ts +95 -0
- package/src/base/utils/clipboard.ts +39 -0
- package/src/base/utils/conditions.ts +27 -0
- package/src/base/utils/icon-registry.ts +78 -0
- package/src/base/utils/icons.ts +31 -0
- package/src/base/utils/interpolate.ts +9 -0
- package/src/base/utils/register-default-icons.ts +163 -0
- package/src/base/utils/storage.ts +65 -0
- package/src/base/utils/time.ts +139 -0
- package/src/contracts/block-data/actions.ts +73 -0
- package/src/contracts/block-data/data-display.ts +343 -0
- package/src/contracts/block-data/form.ts +164 -0
- package/src/contracts/block-data/index.ts +15 -0
- package/src/contracts/block-data/interactive.ts +34 -0
- package/src/contracts/block-data/shared.ts +44 -0
- package/src/contracts/connectors.ts +60 -0
- package/src/contracts/generated/contract-schema.ts +1237 -0
- package/src/contracts/generated/contract-types.ts +675 -0
- package/src/contracts/generated/index.ts +15 -0
- package/src/contracts/navigation.ts +59 -0
- package/src/contracts/page-contract-schema.ts +40 -0
- package/src/contracts/page-contract.ts +79 -0
- package/src/contracts/shared-props.ts +92 -0
- package/src/engine/ContractPage.tsx +178 -0
- package/src/engine/EntityRoutes.tsx +72 -0
- package/src/engine/HostSlot.tsx +126 -0
- package/src/engine/LazyBlock.tsx +92 -0
- package/src/engine/bootstrap.tsx +20 -0
- package/src/engine/providers/auth.tsx +87 -0
- package/src/engine/providers/error-reporter.tsx +89 -0
- package/src/engine/providers/flash.tsx +44 -0
- package/src/engine/providers/index.ts +18 -0
- package/src/engine/providers/inertia-error-reporter.tsx +61 -0
- package/src/engine/providers/progress.tsx +56 -0
- package/src/engine/providers/scope.tsx +51 -0
- package/src/engine/register-defaults.ts +88 -0
- package/src/engine/registries.ts +96 -0
- package/src/i18n/I18nProvider.tsx +53 -0
- package/src/i18n/MANIFEST.md +101 -0
- package/src/i18n/host-resolver.ts +18 -0
- package/src/i18n/instance.ts +69 -0
- package/src/i18n/locales/en/ui.json +277 -0
- package/src/i18n/locales/en/validators.json +13 -0
- package/src/i18n/locales/pt-BR/ui.json +277 -0
- package/src/i18n/locales/pt-BR/validators.json +13 -0
- package/src/i18n/register-strings.ts +10 -0
- package/src/i18n/render-label.ts +33 -0
- package/src/i18n/resolve-field-error.ts +29 -0
- package/src/i18n/useHostString.ts +50 -0
- package/src/i18n/useTranslation.ts +83 -0
- package/src/lib/actions/resolve-action-target.ts +151 -0
- package/src/lib/hooks/use-copy-to-clipboard.ts +37 -0
- package/src/lib/hooks/use-file-upload.ts +406 -0
- package/src/lib/hooks/use-mobile.ts +21 -0
- package/src/lib/host-pending.ts +76 -0
- package/src/lib/portal-container.ts +16 -0
- package/src/lib/test-ids.ts +40 -0
- package/src/lib/utils.ts +6 -0
- package/src/primitives/reui/MANIFEST.md +97 -0
- package/src/primitives/reui/accordion.tsx +64 -0
- package/src/primitives/reui/alert-dialog.tsx +196 -0
- package/src/primitives/reui/alert.tsx +92 -0
- package/src/primitives/reui/aspect-ratio.tsx +9 -0
- package/src/primitives/reui/autocomplete.tsx +343 -0
- package/src/primitives/reui/avatar.tsx +109 -0
- package/src/primitives/reui/badge.tsx +94 -0
- package/src/primitives/reui/breadcrumb.tsx +109 -0
- package/src/primitives/reui/button-group.tsx +83 -0
- package/src/primitives/reui/button.tsx +64 -0
- package/src/primitives/reui/calendar.tsx +220 -0
- package/src/primitives/reui/card.tsx +92 -0
- package/src/primitives/reui/carousel.tsx +239 -0
- package/src/primitives/reui/chart.tsx +388 -0
- package/src/primitives/reui/checkbox.tsx +30 -0
- package/src/primitives/reui/collapsible.tsx +31 -0
- package/src/primitives/reui/combobox.tsx +308 -0
- package/src/primitives/reui/command.tsx +182 -0
- package/src/primitives/reui/context-menu.tsx +250 -0
- package/src/primitives/reui/data-grid/data-grid-column-filter.tsx +172 -0
- package/src/primitives/reui/data-grid/data-grid-column-header.tsx +420 -0
- package/src/primitives/reui/data-grid/data-grid-column-visibility.tsx +51 -0
- package/src/primitives/reui/data-grid/data-grid-pagination.tsx +235 -0
- package/src/primitives/reui/data-grid/data-grid-scroll-area.tsx +427 -0
- package/src/primitives/reui/data-grid/data-grid-table-dnd-rows.tsx +308 -0
- package/src/primitives/reui/data-grid/data-grid-table-dnd.tsx +318 -0
- package/src/primitives/reui/data-grid/data-grid-table-virtual.tsx +491 -0
- package/src/primitives/reui/data-grid/data-grid-table.tsx +1430 -0
- package/src/primitives/reui/data-grid/data-grid.tsx +269 -0
- package/src/primitives/reui/data-grid-pagination.tsx +235 -0
- package/src/primitives/reui/date-selector.tsx +1353 -0
- package/src/primitives/reui/dialog.tsx +158 -0
- package/src/primitives/reui/drawer.tsx +133 -0
- package/src/primitives/reui/dropdown-menu.tsx +257 -0
- package/src/primitives/reui/empty.tsx +104 -0
- package/src/primitives/reui/field.tsx +246 -0
- package/src/primitives/reui/filters.tsx +1891 -0
- package/src/primitives/reui/frame.tsx +170 -0
- package/src/primitives/reui/hover-card.tsx +42 -0
- package/src/primitives/reui/icon-placeholder.tsx +39 -0
- package/src/primitives/reui/index.ts +98 -0
- package/src/primitives/reui/input-group.tsx +170 -0
- package/src/primitives/reui/input-otp.tsx +75 -0
- package/src/primitives/reui/input.tsx +21 -0
- package/src/primitives/reui/item.tsx +193 -0
- package/src/primitives/reui/kanban.tsx +743 -0
- package/src/primitives/reui/kbd.tsx +28 -0
- package/src/primitives/reui/label.tsx +22 -0
- package/src/primitives/reui/menubar.tsx +274 -0
- package/src/primitives/reui/native-select.tsx +62 -0
- package/src/primitives/reui/navigation-menu.tsx +168 -0
- package/src/primitives/reui/number-field.tsx +250 -0
- package/src/primitives/reui/pagination.tsx +127 -0
- package/src/primitives/reui/phone-input.tsx +231 -0
- package/src/primitives/reui/popover.tsx +87 -0
- package/src/primitives/reui/progress.tsx +31 -0
- package/src/primitives/reui/radio-group.tsx +43 -0
- package/src/primitives/reui/rating.tsx +177 -0
- package/src/primitives/reui/resizable.tsx +51 -0
- package/src/primitives/reui/scroll-area.tsx +58 -0
- package/src/primitives/reui/scrollspy.tsx +240 -0
- package/src/primitives/reui/select.tsx +188 -0
- package/src/primitives/reui/separator.tsx +28 -0
- package/src/primitives/reui/sheet.tsx +141 -0
- package/src/primitives/reui/sidebar.tsx +732 -0
- package/src/primitives/reui/skeleton.tsx +13 -0
- package/src/primitives/reui/slider.tsx +61 -0
- package/src/primitives/reui/sonner.tsx +47 -0
- package/src/primitives/reui/sortable.tsx +414 -0
- package/src/primitives/reui/spinner.tsx +16 -0
- package/src/primitives/reui/stepper.tsx +484 -0
- package/src/primitives/reui/svgs/claudeAiIcon.tsx +12 -0
- package/src/primitives/reui/svgs/gemini.tsx +171 -0
- package/src/primitives/reui/svgs/openai.tsx +9 -0
- package/src/primitives/reui/svgs/openaiDark.tsx +12 -0
- package/src/primitives/reui/switch.tsx +33 -0
- package/src/primitives/reui/table.tsx +114 -0
- package/src/primitives/reui/tabs.tsx +91 -0
- package/src/primitives/reui/textarea.tsx +18 -0
- package/src/primitives/reui/timeline.tsx +219 -0
- package/src/primitives/reui/toggle-group.tsx +83 -0
- package/src/primitives/reui/toggle.tsx +45 -0
- package/src/primitives/reui/tooltip.tsx +55 -0
- package/src/primitives/reui/tree.tsx +247 -0
- package/src/theme.css +71 -0
- package/dist-lib/chunks/subpath-q4Q2zg_p.js +0 -153
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* usePolling — Inertia v3 contract-driven polling for blocks.
|
|
3
|
+
*
|
|
4
|
+
* Consumes the canonical `PollConfig` (`BlockDescriptor.poll`, generated from
|
|
5
|
+
* `Middag\Ui`): the server owns whether and how a block polls.
|
|
6
|
+
*
|
|
7
|
+
* - intervalMs → poll interval in ms (0 / absent ⇒ no polling)
|
|
8
|
+
* - pauseWhenHidden → throttle while the tab is hidden (maps to keepAlive: false)
|
|
9
|
+
* - stopAfterMs → stop polling after this elapsed time (optional)
|
|
10
|
+
* - endpoint → server-side hint; the same-page reload refreshes the contract
|
|
11
|
+
*
|
|
12
|
+
* Uses Inertia v3 `router.poll` (mode "cancel" for overlap-guard, visibility-aware
|
|
13
|
+
* via keepAlive) instead of a hand-rolled setInterval: automatic cleanup,
|
|
14
|
+
* pause-on-hidden, and overlap protection come for free. The effect re-arms when
|
|
15
|
+
* the poll config changes, so the server can start/stop/retune polling by sending
|
|
16
|
+
* a new contract.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { useEffect } from "react";
|
|
20
|
+
import { router } from "@inertiajs/core";
|
|
21
|
+
|
|
22
|
+
import type { PollConfig } from "@/contracts/generated";
|
|
23
|
+
|
|
24
|
+
export function usePolling(poll: PollConfig | undefined): void {
|
|
25
|
+
const intervalMs = poll?.intervalMs ?? 0;
|
|
26
|
+
const enabled = intervalMs > 0;
|
|
27
|
+
// pauseWhenHidden=true ⇒ throttle while hidden ⇒ keepAlive must be false.
|
|
28
|
+
const keepAlive = poll?.pauseWhenHidden === false;
|
|
29
|
+
const stopAfterMs = poll?.stopAfterMs ?? 0;
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (!enabled) return;
|
|
33
|
+
|
|
34
|
+
const handle = router.poll(intervalMs, { only: ["contract"] }, { keepAlive, mode: "cancel" });
|
|
35
|
+
|
|
36
|
+
const stopTimer = stopAfterMs > 0 ? setTimeout(() => handle.stop(), stopAfterMs) : null;
|
|
37
|
+
|
|
38
|
+
return () => {
|
|
39
|
+
if (stopTimer !== null) clearTimeout(stopTimer);
|
|
40
|
+
handle.destroy();
|
|
41
|
+
};
|
|
42
|
+
}, [enabled, intervalMs, keepAlive, stopAfterMs]);
|
|
43
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useRemember — useState that survives Inertia history navigation when opted in.
|
|
3
|
+
*
|
|
4
|
+
* Wraps Inertia v3's `useRemember` so a block's client-only UI state (column
|
|
5
|
+
* visibility, density, draft selections — state that is NOT round-tripped to
|
|
6
|
+
* the server) is restored on browser back/forward within the SPA. Gated by the
|
|
7
|
+
* `remember` flag the backend sets on `BlockDescriptor`: when off, it behaves
|
|
8
|
+
* as a plain `useState`, so non-opted-in blocks pay nothing and keep the same
|
|
9
|
+
* wire shape.
|
|
10
|
+
*
|
|
11
|
+
* Drop-in for `useState`: same `[state, setState]` tuple, same lazy-initializer
|
|
12
|
+
* support. The `key` scopes Inertia's history slot — keep it stable and unique
|
|
13
|
+
* per block (use `block.key`).
|
|
14
|
+
*
|
|
15
|
+
* IMPORTANT: `enabled` must be stable for the lifetime of the component. It is
|
|
16
|
+
* derived from the contract (`block.remember`), which does not change across
|
|
17
|
+
* renders of a mounted block. A flipping `enabled` would swap which underlying
|
|
18
|
+
* state backs the tuple and desync the value.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* const [visibility, setVisibility] = useRemember(
|
|
23
|
+
* () => buildInitialVisibility(columns),
|
|
24
|
+
* `${block.key}:columns`,
|
|
25
|
+
* block.remember ?? false,
|
|
26
|
+
* );
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { useState, type Dispatch, type SetStateAction } from "react";
|
|
31
|
+
import { useRemember as useInertiaRemember } from "@inertiajs/react";
|
|
32
|
+
|
|
33
|
+
export function useRemember<T>(
|
|
34
|
+
initialState: T | (() => T),
|
|
35
|
+
key: string,
|
|
36
|
+
enabled: boolean,
|
|
37
|
+
): [T, Dispatch<SetStateAction<T>>] {
|
|
38
|
+
// Freeze `enabled` for the component's lifetime. The branch below calls a
|
|
39
|
+
// different hook per path, which Rules of Hooks forbids *if the branch can
|
|
40
|
+
// change between renders*. Freezing makes the branch constant for this mount,
|
|
41
|
+
// so hook order is stable at runtime; the static linter cannot prove that, so
|
|
42
|
+
// the calls are explicitly exempted. A block's `remember` flag is
|
|
43
|
+
// contract-stable; a flip would only take effect on remount.
|
|
44
|
+
const [persist] = useState(enabled);
|
|
45
|
+
// Resolve the (possibly lazy) initial value exactly once, before the branch.
|
|
46
|
+
const [initial] = useState<T>(initialState);
|
|
47
|
+
|
|
48
|
+
if (persist) {
|
|
49
|
+
// Inertia's useRemember reaches into the router's history layer, which only
|
|
50
|
+
// exists once a host bootstraps `createInertiaApp`. Calling it ONLY on the
|
|
51
|
+
// opted-in path keeps mock/SSR/unit environments (remember=false) free of
|
|
52
|
+
// that dependency.
|
|
53
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks -- `persist` is frozen; branch is constant per mount
|
|
54
|
+
return useInertiaRemember<T>(initial, key);
|
|
55
|
+
}
|
|
56
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks -- see above
|
|
57
|
+
return useState<T>(initial);
|
|
58
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useToast — typed wrapper around Sonner toast API.
|
|
3
|
+
*
|
|
4
|
+
* Provides a consistent imperative toast interface for block components
|
|
5
|
+
* and system partials. Sonner's Toaster is already mounted in ProductShell.
|
|
6
|
+
*
|
|
7
|
+
* @see Page Builder v2 spec §Gap 4
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { toast as sonnerToast } from "sonner";
|
|
11
|
+
|
|
12
|
+
export interface ToastData {
|
|
13
|
+
severity: "success" | "error" | "warning" | "info";
|
|
14
|
+
message: string;
|
|
15
|
+
duration?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const DEFAULT_DURATION = 5000;
|
|
19
|
+
|
|
20
|
+
export function useToast() {
|
|
21
|
+
const toast = (data: ToastData) => {
|
|
22
|
+
const duration = data.duration ?? DEFAULT_DURATION;
|
|
23
|
+
sonnerToast[data.severity](data.message, { duration });
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return { toast };
|
|
27
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BlockRegion — shared utility for rendering a list of blocks
|
|
3
|
+
* with consistent per-block horizontal padding.
|
|
4
|
+
*
|
|
5
|
+
* Skips padding for blocks with `meta.fullBleed: true` (edge-to-edge).
|
|
6
|
+
* Used by all built-in layouts as a composition primitive.
|
|
7
|
+
* Custom layouts can use BlockRegion directly or handle padding manually.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ReactElement } from "react";
|
|
11
|
+
|
|
12
|
+
import type { BlockDescriptor } from "@/contracts/page-contract";
|
|
13
|
+
import { blockTestId } from "@/lib/test-ids";
|
|
14
|
+
import { cn } from "@/lib/utils";
|
|
15
|
+
|
|
16
|
+
interface BlockRegionProps {
|
|
17
|
+
blocks: BlockDescriptor[];
|
|
18
|
+
renderBlock: (block: BlockDescriptor) => ReactElement | null;
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function BlockRegion({ blocks, renderBlock, className }: BlockRegionProps): ReactElement {
|
|
23
|
+
return (
|
|
24
|
+
<div className={cn("space-y-4", className)}>
|
|
25
|
+
{blocks.map((block) => {
|
|
26
|
+
const fullBleed = (block.meta as Record<string, unknown> | undefined)?.fullBleed === true;
|
|
27
|
+
return (
|
|
28
|
+
<div
|
|
29
|
+
key={block.key}
|
|
30
|
+
data-testid={blockTestId(block.key)}
|
|
31
|
+
className={cn(!fullBleed && "px-6")}
|
|
32
|
+
>
|
|
33
|
+
{renderBlock(block)}
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
})}
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DashboardLayout — renders the `dashboard` template from page-contract.
|
|
3
|
+
*
|
|
4
|
+
* Regions: metrics (full-width grid row), header?, content, aside? (optional).
|
|
5
|
+
*
|
|
6
|
+
* Metrics renders blocks in a grid (no per-block padding).
|
|
7
|
+
* Content and aside render blocks directly — blocks are self-describing.
|
|
8
|
+
*
|
|
9
|
+
* @see NV-05-ux-screens-core.md T-01
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { ReactElement } from "react";
|
|
13
|
+
|
|
14
|
+
import { StatRow } from "@/base/partials/StatRow";
|
|
15
|
+
import type { BlockDescriptor } from "@/contracts/page-contract";
|
|
16
|
+
import type { LayoutProps } from "@/engine/registries";
|
|
17
|
+
import { renderLabel } from "@/i18n/render-label";
|
|
18
|
+
import { useTranslation } from "@/i18n/useTranslation";
|
|
19
|
+
import { blockTestId } from "@/lib/test-ids";
|
|
20
|
+
import { Card, CardContent, CardHeader, CardTitle } from "@/primitives/reui/card";
|
|
21
|
+
|
|
22
|
+
function BlockCard({
|
|
23
|
+
block,
|
|
24
|
+
renderBlock,
|
|
25
|
+
}: {
|
|
26
|
+
block: BlockDescriptor;
|
|
27
|
+
renderBlock: (b: BlockDescriptor) => ReactElement | null;
|
|
28
|
+
}): ReactElement {
|
|
29
|
+
const { t } = useTranslation();
|
|
30
|
+
return (
|
|
31
|
+
<Card data-testid={blockTestId(block.key)}>
|
|
32
|
+
{block.title && (
|
|
33
|
+
<CardHeader>
|
|
34
|
+
<CardTitle className="text-sm">{renderLabel(block.title, t)}</CardTitle>
|
|
35
|
+
</CardHeader>
|
|
36
|
+
)}
|
|
37
|
+
<CardContent>{renderBlock(block)}</CardContent>
|
|
38
|
+
</Card>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Content-to-aside ratio, by name.
|
|
44
|
+
*
|
|
45
|
+
* Both tracks are wrapped in `minmax(0, …)`. Without it a grid track refuses to
|
|
46
|
+
* shrink below the intrinsic minimum of its content, so one wide child — a table
|
|
47
|
+
* with many columns is the usual one — takes more than its share and pushes the
|
|
48
|
+
* aside past the right edge of the window, with no horizontal scrollbar to reach
|
|
49
|
+
* it. `minmax(0, …)` lets the content column shrink and scroll internally
|
|
50
|
+
* instead, which keeps the aside on screen at every width.
|
|
51
|
+
*/
|
|
52
|
+
const ASIDE_RATIO = {
|
|
53
|
+
default: "lg:grid-cols-[minmax(0,3fr)_minmax(0,1fr)]",
|
|
54
|
+
narrow: "lg:grid-cols-[minmax(0,4fr)_minmax(0,1fr)]",
|
|
55
|
+
wide: "lg:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]",
|
|
56
|
+
} as const;
|
|
57
|
+
|
|
58
|
+
type AsideWidth = keyof typeof ASIDE_RATIO;
|
|
59
|
+
|
|
60
|
+
export function DashboardLayout({ layout, renderBlock }: LayoutProps): ReactElement {
|
|
61
|
+
const { regions } = layout;
|
|
62
|
+
const metricsBlocks = regions.metrics ?? [];
|
|
63
|
+
const headerBlocks = regions.header ?? [];
|
|
64
|
+
const contentBlocks = regions.content ?? [];
|
|
65
|
+
const asideBlocks = regions.aside ?? [];
|
|
66
|
+
const hasAside = asideBlocks.length > 0;
|
|
67
|
+
|
|
68
|
+
// A page whose aside holds a short list of facets wants less room than one
|
|
69
|
+
// holding a chart. The contract carries a name rather than a length so the
|
|
70
|
+
// scale stays the layout's to decide, and an unknown value falls back instead
|
|
71
|
+
// of producing a class Tailwind never generated.
|
|
72
|
+
const asideWidth = (layout.meta as { asideWidth?: string } | undefined)?.asideWidth;
|
|
73
|
+
const ratio = ASIDE_RATIO[asideWidth as AsideWidth] ?? ASIDE_RATIO.default;
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div className="bg-muted/50 -mx-[var(--content-padding,0px)] mt-2 -mb-6 flex flex-col gap-6 px-[var(--content-padding,1.5rem)] py-6">
|
|
77
|
+
{/* Header */}
|
|
78
|
+
{headerBlocks.length > 0 && (
|
|
79
|
+
<div className="space-y-4">
|
|
80
|
+
{headerBlocks.map((block) => (
|
|
81
|
+
<div key={block.key} data-testid={blockTestId(block.key)}>
|
|
82
|
+
{renderBlock(block)}
|
|
83
|
+
</div>
|
|
84
|
+
))}
|
|
85
|
+
</div>
|
|
86
|
+
)}
|
|
87
|
+
|
|
88
|
+
{/* Unified grid — metrics inside content column, aside aligned from top */}
|
|
89
|
+
<div className={hasAside ? `grid grid-cols-1 gap-6 ${ratio}` : "grid grid-cols-1 gap-6"}>
|
|
90
|
+
<div className="space-y-6">
|
|
91
|
+
{metricsBlocks.length > 0 && (
|
|
92
|
+
<StatRow columns={metricsBlocks.length <= 3 ? 3 : 4}>
|
|
93
|
+
{metricsBlocks.map(renderBlock)}
|
|
94
|
+
</StatRow>
|
|
95
|
+
)}
|
|
96
|
+
{contentBlocks.map((block) => (
|
|
97
|
+
<BlockCard key={block.key} block={block} renderBlock={renderBlock} />
|
|
98
|
+
))}
|
|
99
|
+
</div>
|
|
100
|
+
{hasAside && (
|
|
101
|
+
<aside className="space-y-6">
|
|
102
|
+
{asideBlocks.map((block) => (
|
|
103
|
+
<BlockCard key={block.key} block={block} renderBlock={renderBlock} />
|
|
104
|
+
))}
|
|
105
|
+
</aside>
|
|
106
|
+
)}
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SidebarLayout — renders the `sidebar` template from page-contract.
|
|
3
|
+
*
|
|
4
|
+
* Two-column layout with main content area and aside panel (320px).
|
|
5
|
+
* Regions: main (required), aside (required), header? (optional).
|
|
6
|
+
*
|
|
7
|
+
* When the header region is present, it renders as a full-width row
|
|
8
|
+
* above the two columns.
|
|
9
|
+
*
|
|
10
|
+
* The aside panel has a left border and subtle background, styled
|
|
11
|
+
* via semantic tokens so themes can override it.
|
|
12
|
+
*/
|
|
13
|
+
import type { ReactElement } from "react";
|
|
14
|
+
|
|
15
|
+
import type { LayoutProps } from "@/engine/registries";
|
|
16
|
+
|
|
17
|
+
import { BlockRegion } from "./BlockRegion";
|
|
18
|
+
|
|
19
|
+
export function SidebarLayout({ layout, renderBlock }: LayoutProps): ReactElement {
|
|
20
|
+
const { regions } = layout;
|
|
21
|
+
const headerBlocks = regions.header ?? [];
|
|
22
|
+
const mainBlocks = regions.main ?? [];
|
|
23
|
+
const asideBlocks = regions.aside ?? [];
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div className="flex flex-col gap-5 py-6">
|
|
27
|
+
{headerBlocks.length > 0 && <BlockRegion blocks={headerBlocks} renderBlock={renderBlock} />}
|
|
28
|
+
<div className="grid grid-cols-1 gap-5 lg:grid-cols-[1fr_320px]">
|
|
29
|
+
<BlockRegion blocks={mainBlocks} renderBlock={renderBlock} className="min-w-0" />
|
|
30
|
+
{asideBlocks.length > 0 && (
|
|
31
|
+
<aside className="border-border bg-muted/30 border-l">
|
|
32
|
+
<BlockRegion blocks={asideBlocks} renderBlock={renderBlock} className="py-4" />
|
|
33
|
+
</aside>
|
|
34
|
+
)}
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StackLayout — renders the `stack` template from page-contract.
|
|
3
|
+
*
|
|
4
|
+
* Regions: content (required), header? (optional), footer? (optional).
|
|
5
|
+
* Single column, blocks stacked vertically.
|
|
6
|
+
*
|
|
7
|
+
* Uses BlockRegion for per-block horizontal padding with fullBleed support.
|
|
8
|
+
*/
|
|
9
|
+
import type { ReactElement } from "react";
|
|
10
|
+
|
|
11
|
+
import type { LayoutProps } from "@/engine/registries";
|
|
12
|
+
|
|
13
|
+
import { BlockRegion } from "./BlockRegion";
|
|
14
|
+
|
|
15
|
+
export function StackLayout({ layout, renderBlock }: LayoutProps): ReactElement {
|
|
16
|
+
const { regions } = layout;
|
|
17
|
+
const headerBlocks = regions.header ?? [];
|
|
18
|
+
const contentBlocks = regions.content ?? [];
|
|
19
|
+
const footerBlocks = regions.footer ?? [];
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div className="flex flex-col gap-5 py-6">
|
|
23
|
+
{headerBlocks.length > 0 && <BlockRegion blocks={headerBlocks} renderBlock={renderBlock} />}
|
|
24
|
+
<BlockRegion blocks={contentBlocks} renderBlock={renderBlock} />
|
|
25
|
+
{footerBlocks.length > 0 && (
|
|
26
|
+
<div className="border-border border-t pt-5">
|
|
27
|
+
<BlockRegion blocks={footerBlocks} renderBlock={renderBlock} />
|
|
28
|
+
</div>
|
|
29
|
+
)}
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WizardLayout — renders the `wizard` template from page-contract.
|
|
3
|
+
*
|
|
4
|
+
* Server-driven: steps come from layout.meta.steps, actions from layout.meta.actions.
|
|
5
|
+
* Content region renders standard blocks via BlockRegion.
|
|
6
|
+
*
|
|
7
|
+
* @see UI Layer Completion spec §1
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ReactElement } from "react";
|
|
11
|
+
|
|
12
|
+
import { StepIndicator, type StepItem } from "@/base/partials/StepIndicator";
|
|
13
|
+
import { PageActionButton } from "@/base/shell/partials/PageActionButton";
|
|
14
|
+
import type { PageAction } from "@/contracts/page-contract";
|
|
15
|
+
import type { LayoutProps } from "@/engine/registries";
|
|
16
|
+
|
|
17
|
+
import { BlockRegion } from "./BlockRegion";
|
|
18
|
+
|
|
19
|
+
export function WizardLayout({ layout, renderBlock }: LayoutProps): ReactElement {
|
|
20
|
+
const { regions, meta } = layout;
|
|
21
|
+
const contentBlocks = regions.content ?? [];
|
|
22
|
+
const steps = (meta?.steps ?? []) as StepItem[];
|
|
23
|
+
const actions = (meta?.actions ?? []) as PageAction[];
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div className="flex min-h-0 flex-col">
|
|
27
|
+
{/* Step indicator bar */}
|
|
28
|
+
{steps.length > 0 && (
|
|
29
|
+
<div className="border-border border-b px-6 py-4">
|
|
30
|
+
<StepIndicator steps={steps} />
|
|
31
|
+
</div>
|
|
32
|
+
)}
|
|
33
|
+
|
|
34
|
+
{/* Content region */}
|
|
35
|
+
<div className="flex-1 overflow-y-auto py-6">
|
|
36
|
+
<BlockRegion blocks={contentBlocks} renderBlock={renderBlock} />
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
{/* Actions footer */}
|
|
40
|
+
{actions.length > 0 && (
|
|
41
|
+
<div className="border-border flex justify-end gap-2 border-t px-6 py-4">
|
|
42
|
+
{actions.map((action) => (
|
|
43
|
+
<PageActionButton key={action.id} action={action} />
|
|
44
|
+
))}
|
|
45
|
+
</div>
|
|
46
|
+
)}
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ActionBar — bulk action toolbar for selected rows.
|
|
3
|
+
*
|
|
4
|
+
* Shows selected count + bulk action buttons. Dangerous actions require confirmation
|
|
5
|
+
* via the unified ConfirmationDialog.
|
|
6
|
+
*
|
|
7
|
+
* @see NV-05-ux-blocks.md §1.2 toolbar anatomy
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { useState, type ReactElement } from "react";
|
|
11
|
+
|
|
12
|
+
import { ConfirmationDialog } from "@/base/partials/ConfirmationDialog";
|
|
13
|
+
import type { ExecutableAction } from "@/contracts/block-data";
|
|
14
|
+
import { renderLabel } from "@/i18n/render-label";
|
|
15
|
+
import { useTranslation } from "@/i18n/useTranslation";
|
|
16
|
+
import { actionTestId } from "@/lib/test-ids";
|
|
17
|
+
import { Button } from "@/primitives/reui/button";
|
|
18
|
+
|
|
19
|
+
export interface ActionBarProps {
|
|
20
|
+
selectedCount: number;
|
|
21
|
+
totalCount: number;
|
|
22
|
+
actions: ExecutableAction[];
|
|
23
|
+
onAction: (actionId: string) => void;
|
|
24
|
+
onSelectAll?: () => void;
|
|
25
|
+
isLoading?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function ActionBar({
|
|
29
|
+
selectedCount,
|
|
30
|
+
totalCount,
|
|
31
|
+
actions,
|
|
32
|
+
onAction,
|
|
33
|
+
onSelectAll,
|
|
34
|
+
isLoading,
|
|
35
|
+
}: ActionBarProps): ReactElement {
|
|
36
|
+
const { t } = useTranslation();
|
|
37
|
+
const [confirmAction, setConfirmAction] = useState<ExecutableAction | null>(null);
|
|
38
|
+
|
|
39
|
+
const handleAction = (action: ExecutableAction) => {
|
|
40
|
+
if (action.confirmation) {
|
|
41
|
+
setConfirmAction(action);
|
|
42
|
+
} else {
|
|
43
|
+
onAction(action.id);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const bulkMessage = confirmAction
|
|
48
|
+
? renderLabel(confirmAction.confirmation?.message, t) ||
|
|
49
|
+
t("middag.ui.actionbar.confirm_bulk", {
|
|
50
|
+
label: renderLabel(confirmAction.label, t),
|
|
51
|
+
total: selectedCount,
|
|
52
|
+
items: t("middag.ui.actionbar.item", { count: selectedCount }),
|
|
53
|
+
})
|
|
54
|
+
: "";
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
<div
|
|
59
|
+
className="flex items-center gap-3"
|
|
60
|
+
role="toolbar"
|
|
61
|
+
aria-label={t("middag.ui.actionbar.label")}
|
|
62
|
+
>
|
|
63
|
+
<span className="text-sm font-semibold" role="status" aria-live="polite">
|
|
64
|
+
{t("middag.ui.actionbar.selected", { count: selectedCount })}
|
|
65
|
+
</span>
|
|
66
|
+
|
|
67
|
+
{totalCount > selectedCount && onSelectAll && (
|
|
68
|
+
<button onClick={onSelectAll} className="text-primary text-xs hover:underline">
|
|
69
|
+
{t("middag.ui.actionbar.select_all", { total: totalCount })}
|
|
70
|
+
</button>
|
|
71
|
+
)}
|
|
72
|
+
|
|
73
|
+
{actions.map((action) => (
|
|
74
|
+
<Button
|
|
75
|
+
key={action.id}
|
|
76
|
+
data-testid={actionTestId(action.id)}
|
|
77
|
+
variant={action.intent === "danger" ? "destructive" : "outline"}
|
|
78
|
+
size="sm"
|
|
79
|
+
onClick={() => handleAction(action)}
|
|
80
|
+
disabled={isLoading}
|
|
81
|
+
>
|
|
82
|
+
{renderLabel(action.label, t)}
|
|
83
|
+
</Button>
|
|
84
|
+
))}
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
{confirmAction && (
|
|
88
|
+
<ConfirmationDialog
|
|
89
|
+
open={!!confirmAction}
|
|
90
|
+
onClose={() => setConfirmAction(null)}
|
|
91
|
+
onConfirm={() => {
|
|
92
|
+
onAction(confirmAction.id);
|
|
93
|
+
setConfirmAction(null);
|
|
94
|
+
}}
|
|
95
|
+
title={renderLabel(confirmAction.confirmation?.title ?? confirmAction.label, t)}
|
|
96
|
+
message={bulkMessage}
|
|
97
|
+
intent={
|
|
98
|
+
confirmAction.confirmation?.intent ??
|
|
99
|
+
(confirmAction.intent === "danger" ? "danger" : undefined)
|
|
100
|
+
}
|
|
101
|
+
confirmLabel={
|
|
102
|
+
confirmAction.confirmation?.confirmLabel
|
|
103
|
+
? renderLabel(confirmAction.confirmation.confirmLabel, t)
|
|
104
|
+
: undefined
|
|
105
|
+
}
|
|
106
|
+
cancelLabel={
|
|
107
|
+
confirmAction.confirmation?.cancelLabel
|
|
108
|
+
? renderLabel(confirmAction.confirmation.cancelLabel, t)
|
|
109
|
+
: undefined
|
|
110
|
+
}
|
|
111
|
+
/>
|
|
112
|
+
)}
|
|
113
|
+
</>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConfirmationDialog — generic confirmation modal for actions.
|
|
3
|
+
*
|
|
4
|
+
* Supports two patterns:
|
|
5
|
+
* 1. Confirm & Execute: simple confirmation, closes after confirm click.
|
|
6
|
+
* 2. Confirm & Wait: stays open with spinner until polling resolves.
|
|
7
|
+
*
|
|
8
|
+
* Used by DenseTableBlock (row actions) and PageHeader (page actions).
|
|
9
|
+
*
|
|
10
|
+
* @see Page Builder v2 spec §Confirmation Dialogs
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { type ReactElement } from "react";
|
|
14
|
+
|
|
15
|
+
import { useTranslation } from "@/i18n/useTranslation";
|
|
16
|
+
import { TEST_IDS } from "@/lib/test-ids";
|
|
17
|
+
import { Button } from "@/primitives/reui/button";
|
|
18
|
+
import {
|
|
19
|
+
Dialog,
|
|
20
|
+
DialogContent,
|
|
21
|
+
DialogDescription,
|
|
22
|
+
DialogFooter,
|
|
23
|
+
DialogHeader,
|
|
24
|
+
DialogTitle,
|
|
25
|
+
} from "@/primitives/reui/dialog";
|
|
26
|
+
|
|
27
|
+
function Spinner({ className }: { className?: string }): ReactElement {
|
|
28
|
+
return (
|
|
29
|
+
<svg
|
|
30
|
+
className={`animate-spin ${className ?? ""}`}
|
|
31
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
32
|
+
fill="none"
|
|
33
|
+
viewBox="0 0 24 24"
|
|
34
|
+
>
|
|
35
|
+
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
|
36
|
+
<path
|
|
37
|
+
className="opacity-75"
|
|
38
|
+
fill="currentColor"
|
|
39
|
+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
|
|
40
|
+
/>
|
|
41
|
+
</svg>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ConfirmationDialogProps {
|
|
46
|
+
open: boolean;
|
|
47
|
+
onClose: () => void;
|
|
48
|
+
onConfirm: () => void;
|
|
49
|
+
title: string;
|
|
50
|
+
message: string;
|
|
51
|
+
intent?: "danger" | "warning" | "default";
|
|
52
|
+
confirmLabel?: string;
|
|
53
|
+
cancelLabel?: string;
|
|
54
|
+
waiting?: boolean;
|
|
55
|
+
waitingMessage?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function ConfirmationDialog({
|
|
59
|
+
open,
|
|
60
|
+
onClose,
|
|
61
|
+
onConfirm,
|
|
62
|
+
title,
|
|
63
|
+
message,
|
|
64
|
+
intent = "default",
|
|
65
|
+
confirmLabel,
|
|
66
|
+
cancelLabel,
|
|
67
|
+
waiting = false,
|
|
68
|
+
waitingMessage,
|
|
69
|
+
}: ConfirmationDialogProps): ReactElement {
|
|
70
|
+
const { t } = useTranslation();
|
|
71
|
+
const confirmVariant = intent === "danger" ? "destructive" : "default";
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Dialog
|
|
75
|
+
open={open}
|
|
76
|
+
onOpenChange={(isOpen) => {
|
|
77
|
+
if (!isOpen && !waiting) onClose();
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
<DialogContent data-testid={TEST_IDS.confirmDialog}>
|
|
81
|
+
<DialogHeader>
|
|
82
|
+
<DialogTitle>{title}</DialogTitle>
|
|
83
|
+
{/*
|
|
84
|
+
Rendered as text, never as HTML.
|
|
85
|
+
|
|
86
|
+
The message is interpolated with row data before it gets here (see
|
|
87
|
+
DenseTableBlock), so it carries values this component does not
|
|
88
|
+
control. Injecting it as HTML turned a row field — a saved view's
|
|
89
|
+
name, a course title, anything a user can type — into live DOM.
|
|
90
|
+
|
|
91
|
+
`whitespace-pre-line` keeps the one formatting need this actually
|
|
92
|
+
had: a newline in the message still breaks the line.
|
|
93
|
+
*/}
|
|
94
|
+
<DialogDescription className="whitespace-pre-line">{message}</DialogDescription>
|
|
95
|
+
</DialogHeader>
|
|
96
|
+
|
|
97
|
+
{waiting && waitingMessage && (
|
|
98
|
+
<div className="text-muted-foreground flex items-center gap-2 py-2">
|
|
99
|
+
<Spinner className="size-4" />
|
|
100
|
+
<span className="text-sm">{waitingMessage}</span>
|
|
101
|
+
</div>
|
|
102
|
+
)}
|
|
103
|
+
|
|
104
|
+
<DialogFooter>
|
|
105
|
+
<Button
|
|
106
|
+
type="button"
|
|
107
|
+
variant="outline"
|
|
108
|
+
onClick={onClose}
|
|
109
|
+
disabled={waiting}
|
|
110
|
+
data-testid={TEST_IDS.confirmDialogCancel}
|
|
111
|
+
>
|
|
112
|
+
{cancelLabel ?? t("middag.ui.cancel")}
|
|
113
|
+
</Button>
|
|
114
|
+
<Button
|
|
115
|
+
type="button"
|
|
116
|
+
variant={confirmVariant}
|
|
117
|
+
onClick={onConfirm}
|
|
118
|
+
disabled={waiting}
|
|
119
|
+
data-testid={TEST_IDS.confirmDialogConfirm}
|
|
120
|
+
>
|
|
121
|
+
{waiting && <Spinner className="mr-2 size-4" />}
|
|
122
|
+
{confirmLabel ?? t("middag.ui.confirm")}
|
|
123
|
+
</Button>
|
|
124
|
+
</DialogFooter>
|
|
125
|
+
</DialogContent>
|
|
126
|
+
</Dialog>
|
|
127
|
+
);
|
|
128
|
+
}
|