@middag-io/react 0.45.0 → 0.45.3
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 +4 -3
- 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
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BasicShell — Community app shell with a simple sidebar + header.
|
|
3
|
+
*
|
|
4
|
+
* The Community counterpart to the Pro ProductShell: a persistent sidebar
|
|
5
|
+
* with flat navigation (no drilldown, quick-find, or command palette) plus a
|
|
6
|
+
* header with title + breadcrumbs and a light/dark toggle. Built entirely from
|
|
7
|
+
* the ReUI sidebar primitives, so any Community consumer gets a usable
|
|
8
|
+
* dashboard frame without @middag-io/react-pro.
|
|
9
|
+
*
|
|
10
|
+
* Reads navigation from shared props (NavigationTreePayload, rendered flat —
|
|
11
|
+
* top-level groups with one level of children) and page meta from the contract.
|
|
12
|
+
* For rich navigation (drilldown, search, chrome panels), use the Pro
|
|
13
|
+
* ProductShell via @middag-io/react-pro's registerProDefaults().
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { type ReactElement } from "react";
|
|
17
|
+
import { router } from "@inertiajs/core";
|
|
18
|
+
import { Link, usePage } from "@inertiajs/react";
|
|
19
|
+
|
|
20
|
+
import { useIsDark } from "@/base/hooks/useIsDark";
|
|
21
|
+
import { PageActionButton } from "@/base/shell/partials/PageActionButton";
|
|
22
|
+
import { setAppearance } from "@/base/theme/appearance";
|
|
23
|
+
import type { NavigationNode, NavigationTreePayload } from "@/contracts/navigation";
|
|
24
|
+
import type { PageMeta } from "@/contracts/page-contract";
|
|
25
|
+
import type { SharedProps, SharedPropsAuth } from "@/contracts/shared-props";
|
|
26
|
+
import type { ShellProps } from "@/engine/registries";
|
|
27
|
+
import { renderLabel } from "@/i18n/render-label";
|
|
28
|
+
import { useTranslation } from "@/i18n/useTranslation";
|
|
29
|
+
import { Avatar, AvatarFallback, AvatarImage } from "@/primitives/reui/avatar";
|
|
30
|
+
import {
|
|
31
|
+
DropdownMenu,
|
|
32
|
+
DropdownMenuContent,
|
|
33
|
+
DropdownMenuItem,
|
|
34
|
+
DropdownMenuLabel,
|
|
35
|
+
DropdownMenuSeparator,
|
|
36
|
+
DropdownMenuTrigger,
|
|
37
|
+
} from "@/primitives/reui/dropdown-menu";
|
|
38
|
+
import {
|
|
39
|
+
Sidebar,
|
|
40
|
+
SidebarContent,
|
|
41
|
+
SidebarFooter,
|
|
42
|
+
SidebarGroup,
|
|
43
|
+
SidebarGroupLabel,
|
|
44
|
+
SidebarHeader,
|
|
45
|
+
SidebarInset,
|
|
46
|
+
SidebarMenu,
|
|
47
|
+
SidebarMenuButton,
|
|
48
|
+
SidebarMenuItem,
|
|
49
|
+
SidebarProvider,
|
|
50
|
+
SidebarTrigger,
|
|
51
|
+
} from "@/primitives/reui/sidebar";
|
|
52
|
+
import { Toaster } from "@/primitives/reui/sonner";
|
|
53
|
+
|
|
54
|
+
const EMPTY_NAV: NavigationTreePayload = { tree: [], footer: [], activeKey: "" };
|
|
55
|
+
|
|
56
|
+
/** A single navigation leaf — a link (or label-only node) inside the menu. */
|
|
57
|
+
function NavLeaf({ node, activeKey }: { node: NavigationNode; activeKey: string }): ReactElement {
|
|
58
|
+
const { t } = useTranslation();
|
|
59
|
+
const isActive = node.key === activeKey;
|
|
60
|
+
const label = renderLabel(node.label, t);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<SidebarMenuItem>
|
|
64
|
+
<SidebarMenuButton asChild={!!node.href} isActive={isActive}>
|
|
65
|
+
{node.href ? (
|
|
66
|
+
<Link href={node.href} prefetch="hover" aria-current={isActive ? "page" : undefined}>
|
|
67
|
+
<span className="truncate">{label}</span>
|
|
68
|
+
</Link>
|
|
69
|
+
) : (
|
|
70
|
+
<span className="truncate">{label}</span>
|
|
71
|
+
)}
|
|
72
|
+
</SidebarMenuButton>
|
|
73
|
+
</SidebarMenuItem>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* HeaderUserMenu — account avatar + dropdown (identity, logout).
|
|
79
|
+
*
|
|
80
|
+
* The Community shell previously exposed no signed-in identity and no logout
|
|
81
|
+
* affordance (only the sidebar-footer theme toggle). Logout is intentionally
|
|
82
|
+
* data-driven: it POSTs to `logoutUrl` (canonically `auth.logoutUrl`; a
|
|
83
|
+
* top-level `logoutUrl` shared prop is accepted as a fallback) so consumers
|
|
84
|
+
* with different auth backends (Moodle, WordPress) set their own endpoint and
|
|
85
|
+
* the generic shell never hard-codes an app route. The item is hidden entirely
|
|
86
|
+
* when no `logoutUrl` is provided.
|
|
87
|
+
*/
|
|
88
|
+
function HeaderUserMenu({
|
|
89
|
+
auth,
|
|
90
|
+
logoutUrl,
|
|
91
|
+
csrfToken,
|
|
92
|
+
}: {
|
|
93
|
+
auth: SharedPropsAuth;
|
|
94
|
+
logoutUrl?: string;
|
|
95
|
+
csrfToken?: string;
|
|
96
|
+
}): ReactElement {
|
|
97
|
+
const { t } = useTranslation();
|
|
98
|
+
const initials =
|
|
99
|
+
auth.name
|
|
100
|
+
.split(/\s+/)
|
|
101
|
+
.filter(Boolean)
|
|
102
|
+
.slice(0, 2)
|
|
103
|
+
.map((word) => word[0]?.toUpperCase() ?? "")
|
|
104
|
+
.join("") || "?";
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<DropdownMenu>
|
|
108
|
+
<DropdownMenuTrigger asChild>
|
|
109
|
+
<button
|
|
110
|
+
type="button"
|
|
111
|
+
className="focus-visible:ring-ring rounded-full transition-opacity hover:opacity-80 focus-visible:ring-2 focus-visible:outline-none"
|
|
112
|
+
aria-label={auth.name}
|
|
113
|
+
>
|
|
114
|
+
<Avatar className="size-8">
|
|
115
|
+
{auth.avatarUrl ? <AvatarImage src={auth.avatarUrl} alt={auth.name} /> : null}
|
|
116
|
+
<AvatarFallback className="text-xs">{initials}</AvatarFallback>
|
|
117
|
+
</Avatar>
|
|
118
|
+
</button>
|
|
119
|
+
</DropdownMenuTrigger>
|
|
120
|
+
<DropdownMenuContent align="end" className="w-56">
|
|
121
|
+
<DropdownMenuLabel>
|
|
122
|
+
<div className="flex min-w-0 flex-col">
|
|
123
|
+
<span className="truncate text-sm font-medium">{auth.name}</span>
|
|
124
|
+
{auth.email ? (
|
|
125
|
+
<span className="text-muted-foreground truncate text-xs font-normal">
|
|
126
|
+
{auth.email}
|
|
127
|
+
</span>
|
|
128
|
+
) : null}
|
|
129
|
+
</div>
|
|
130
|
+
</DropdownMenuLabel>
|
|
131
|
+
{logoutUrl ? (
|
|
132
|
+
<>
|
|
133
|
+
<DropdownMenuSeparator />
|
|
134
|
+
<DropdownMenuItem
|
|
135
|
+
className="text-destructive focus:text-destructive"
|
|
136
|
+
onSelect={() => router.post(logoutUrl, csrfToken ? { _token: csrfToken } : {})}
|
|
137
|
+
>
|
|
138
|
+
{t("middag.ui.auth.sign_out")}
|
|
139
|
+
</DropdownMenuItem>
|
|
140
|
+
</>
|
|
141
|
+
) : null}
|
|
142
|
+
</DropdownMenuContent>
|
|
143
|
+
</DropdownMenu>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function BasicShell({ children }: ShellProps): ReactElement {
|
|
148
|
+
const { t } = useTranslation();
|
|
149
|
+
const { props } = usePage<SharedProps>();
|
|
150
|
+
const isDark = useIsDark();
|
|
151
|
+
|
|
152
|
+
const nav: NavigationTreePayload = (props as SharedProps).navigation ?? EMPTY_NAV;
|
|
153
|
+
const page: PageMeta = (props as SharedProps & { contract?: { page?: PageMeta } }).contract
|
|
154
|
+
?.page ?? { key: "unknown", title: "", breadcrumbs: [], actions: [] };
|
|
155
|
+
|
|
156
|
+
// Header-right chrome inputs. `actions` are the contract's page-level actions
|
|
157
|
+
// (Edit, back, etc.) — previously destructured into `page` but never rendered.
|
|
158
|
+
// `logoutUrl`/`csrf_token` are optional shared props the app supplies.
|
|
159
|
+
const auth: SharedPropsAuth | null | undefined = (props as SharedProps).auth;
|
|
160
|
+
const actions = page.actions ?? [];
|
|
161
|
+
// Canonical source is `auth.logoutUrl`; a top-level `logoutUrl` shared prop
|
|
162
|
+
// is accepted as a fallback for hosts that inject it outside the auth object.
|
|
163
|
+
const logoutUrl =
|
|
164
|
+
auth?.logoutUrl ?? ((props as Record<string, unknown>).logoutUrl as string | undefined);
|
|
165
|
+
const csrfToken = (props as Record<string, unknown>).csrf_token as string | undefined;
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<SidebarProvider>
|
|
169
|
+
<Sidebar collapsible="offcanvas" className="border-sidebar-border bg-sidebar border-r">
|
|
170
|
+
<SidebarHeader className="border-sidebar-border border-b px-4 py-3">
|
|
171
|
+
<span className="text-sidebar-foreground text-sm font-semibold">MIDDAG</span>
|
|
172
|
+
</SidebarHeader>
|
|
173
|
+
|
|
174
|
+
<SidebarContent>
|
|
175
|
+
{(nav.tree ?? []).map((node) =>
|
|
176
|
+
node.children?.length ? (
|
|
177
|
+
<SidebarGroup key={node.key}>
|
|
178
|
+
<SidebarGroupLabel>{renderLabel(node.label, t)}</SidebarGroupLabel>
|
|
179
|
+
<SidebarMenu>
|
|
180
|
+
{node.children.map((child) => (
|
|
181
|
+
<NavLeaf key={child.key} node={child} activeKey={nav.activeKey} />
|
|
182
|
+
))}
|
|
183
|
+
</SidebarMenu>
|
|
184
|
+
</SidebarGroup>
|
|
185
|
+
) : (
|
|
186
|
+
<SidebarGroup key={node.key}>
|
|
187
|
+
<SidebarMenu>
|
|
188
|
+
<NavLeaf node={node} activeKey={nav.activeKey} />
|
|
189
|
+
</SidebarMenu>
|
|
190
|
+
</SidebarGroup>
|
|
191
|
+
),
|
|
192
|
+
)}
|
|
193
|
+
|
|
194
|
+
{(nav.footer ?? []).length > 0 && (
|
|
195
|
+
<SidebarGroup className="mt-auto">
|
|
196
|
+
<SidebarMenu>
|
|
197
|
+
{(nav.footer ?? []).map((node) => (
|
|
198
|
+
<NavLeaf key={node.key} node={node} activeKey={nav.activeKey} />
|
|
199
|
+
))}
|
|
200
|
+
</SidebarMenu>
|
|
201
|
+
</SidebarGroup>
|
|
202
|
+
)}
|
|
203
|
+
</SidebarContent>
|
|
204
|
+
|
|
205
|
+
<SidebarFooter className="border-sidebar-border border-t px-3 py-2">
|
|
206
|
+
<button
|
|
207
|
+
type="button"
|
|
208
|
+
onClick={() => setAppearance(isDark ? "light" : "dark")}
|
|
209
|
+
className="text-muted-foreground hover:bg-sidebar-hover hover:text-sidebar-foreground flex items-center gap-2 rounded-md px-2 py-1.5 text-xs transition-colors"
|
|
210
|
+
aria-label={t("middag.ui.appearance.toggle")}
|
|
211
|
+
>
|
|
212
|
+
<svg
|
|
213
|
+
viewBox="0 0 24 24"
|
|
214
|
+
fill="none"
|
|
215
|
+
stroke="currentColor"
|
|
216
|
+
strokeWidth={2}
|
|
217
|
+
className="h-4 w-4"
|
|
218
|
+
>
|
|
219
|
+
{isDark ? (
|
|
220
|
+
<circle cx="12" cy="12" r="5" />
|
|
221
|
+
) : (
|
|
222
|
+
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79Z" />
|
|
223
|
+
)}
|
|
224
|
+
</svg>
|
|
225
|
+
<span>{isDark ? t("middag.ui.appearance.light") : t("middag.ui.appearance.dark")}</span>
|
|
226
|
+
</button>
|
|
227
|
+
</SidebarFooter>
|
|
228
|
+
</Sidebar>
|
|
229
|
+
|
|
230
|
+
<SidebarInset>
|
|
231
|
+
<header className="border-border flex h-14 shrink-0 items-center gap-3 border-b px-4">
|
|
232
|
+
<SidebarTrigger className="text-muted-foreground hover:text-foreground" />
|
|
233
|
+
<div className="flex min-w-0 flex-col">
|
|
234
|
+
{page.breadcrumbs && page.breadcrumbs.length > 0 && (
|
|
235
|
+
<nav
|
|
236
|
+
aria-label="Breadcrumb"
|
|
237
|
+
className="text-muted-foreground flex items-center gap-1 text-xs"
|
|
238
|
+
>
|
|
239
|
+
{page.breadcrumbs.map((crumb, i) => (
|
|
240
|
+
<span key={`${crumb.label}-${i}`} className="flex items-center gap-1">
|
|
241
|
+
{i > 0 && <span aria-hidden="true">/</span>}
|
|
242
|
+
{crumb.href ? (
|
|
243
|
+
<Link href={crumb.href} className="hover:text-foreground truncate">
|
|
244
|
+
{renderLabel(crumb.label, t)}
|
|
245
|
+
</Link>
|
|
246
|
+
) : (
|
|
247
|
+
<span className="truncate">{renderLabel(crumb.label, t)}</span>
|
|
248
|
+
)}
|
|
249
|
+
</span>
|
|
250
|
+
))}
|
|
251
|
+
</nav>
|
|
252
|
+
)}
|
|
253
|
+
{page.title && (
|
|
254
|
+
<span className="text-foreground truncate text-sm font-medium">
|
|
255
|
+
{renderLabel(page.title, t)}
|
|
256
|
+
</span>
|
|
257
|
+
)}
|
|
258
|
+
</div>
|
|
259
|
+
|
|
260
|
+
{/* Contract-declared page actions (Edit, back, …) + account menu. */}
|
|
261
|
+
{(actions.length > 0 || auth?.name) && (
|
|
262
|
+
<div className="ml-auto flex shrink-0 items-center gap-2">
|
|
263
|
+
{actions.map((action, i) => (
|
|
264
|
+
<PageActionButton key={action.id ?? i} action={action} />
|
|
265
|
+
))}
|
|
266
|
+
{auth?.name ? (
|
|
267
|
+
<HeaderUserMenu auth={auth} logoutUrl={logoutUrl} csrfToken={csrfToken} />
|
|
268
|
+
) : null}
|
|
269
|
+
</div>
|
|
270
|
+
)}
|
|
271
|
+
</header>
|
|
272
|
+
|
|
273
|
+
<main
|
|
274
|
+
id="middag-main-content"
|
|
275
|
+
className="flex min-h-0 flex-1 flex-col overflow-auto"
|
|
276
|
+
aria-live="polite"
|
|
277
|
+
aria-busy="false"
|
|
278
|
+
>
|
|
279
|
+
{children}
|
|
280
|
+
</main>
|
|
281
|
+
</SidebarInset>
|
|
282
|
+
|
|
283
|
+
<Toaster position="bottom-right" richColors />
|
|
284
|
+
</SidebarProvider>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ImmersiveShell — full-screen shell with minimal chrome.
|
|
3
|
+
*
|
|
4
|
+
* No sidebar, no persistent navigation. Only a slim top bar with
|
|
5
|
+
* a back/close button and optional title. Designed for focused
|
|
6
|
+
* experiences: wizards, flow editors, onboarding, presentations.
|
|
7
|
+
*
|
|
8
|
+
* The host can provide a `backHref` in the page contract to control
|
|
9
|
+
* where the close button navigates (defaults to browser history back).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { useCallback, type ReactElement } from "react";
|
|
13
|
+
import { router, usePage } from "@inertiajs/react";
|
|
14
|
+
|
|
15
|
+
import type { PageMeta } from "@/contracts/page-contract";
|
|
16
|
+
import type { SharedProps } from "@/contracts/shared-props";
|
|
17
|
+
import type { ShellProps } from "@/engine/registries";
|
|
18
|
+
import { renderLabel } from "@/i18n/render-label";
|
|
19
|
+
import { useTranslation } from "@/i18n/useTranslation";
|
|
20
|
+
import { Toaster } from "@/primitives/reui/sonner";
|
|
21
|
+
|
|
22
|
+
export function ImmersiveShell({ children }: ShellProps): ReactElement {
|
|
23
|
+
const { t } = useTranslation();
|
|
24
|
+
const { props } = usePage<SharedProps>();
|
|
25
|
+
|
|
26
|
+
const page: PageMeta = (props as SharedProps & { contract?: { page?: PageMeta } }).contract
|
|
27
|
+
?.page ?? {
|
|
28
|
+
key: "unknown",
|
|
29
|
+
title: "",
|
|
30
|
+
breadcrumbs: [],
|
|
31
|
+
actions: [],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const backHref = page.breadcrumbs?.[page.breadcrumbs.length - 1]?.href;
|
|
35
|
+
|
|
36
|
+
const handleClose = useCallback(() => {
|
|
37
|
+
if (backHref) {
|
|
38
|
+
router.visit(backHref);
|
|
39
|
+
} else {
|
|
40
|
+
window.history.back();
|
|
41
|
+
}
|
|
42
|
+
}, [backHref]);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className="bg-background text-foreground flex min-h-screen flex-col">
|
|
46
|
+
{/* Slim top bar */}
|
|
47
|
+
<header className="border-border flex h-12 shrink-0 items-center gap-3 border-b px-4">
|
|
48
|
+
<button
|
|
49
|
+
type="button"
|
|
50
|
+
onClick={handleClose}
|
|
51
|
+
className="text-muted-foreground hover:text-foreground flex h-8 w-8 items-center justify-center rounded-md transition-colors"
|
|
52
|
+
aria-label={t("middag.ui.close")}
|
|
53
|
+
>
|
|
54
|
+
<svg
|
|
55
|
+
viewBox="0 0 24 24"
|
|
56
|
+
fill="none"
|
|
57
|
+
stroke="currentColor"
|
|
58
|
+
strokeWidth={2}
|
|
59
|
+
className="h-5 w-5"
|
|
60
|
+
>
|
|
61
|
+
<path d="M18 6 6 18M6 6l12 12" />
|
|
62
|
+
</svg>
|
|
63
|
+
</button>
|
|
64
|
+
|
|
65
|
+
{page.title && (
|
|
66
|
+
<span className="text-foreground truncate text-sm font-medium">
|
|
67
|
+
{renderLabel(page.title, t)}
|
|
68
|
+
</span>
|
|
69
|
+
)}
|
|
70
|
+
</header>
|
|
71
|
+
|
|
72
|
+
{/* Full-bleed content */}
|
|
73
|
+
<main
|
|
74
|
+
id="middag-main-content"
|
|
75
|
+
className="flex min-h-0 flex-1 flex-col"
|
|
76
|
+
aria-live="polite"
|
|
77
|
+
aria-busy="false"
|
|
78
|
+
>
|
|
79
|
+
{children}
|
|
80
|
+
</main>
|
|
81
|
+
|
|
82
|
+
<Toaster position="bottom-right" richColors />
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext } from "react";
|
|
4
|
+
|
|
5
|
+
import type { FormSchemaNode } from "@/contracts/block-data";
|
|
6
|
+
|
|
7
|
+
// ── Types ────────────────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* EditablePanelDescriptor — the form a panel edits. Mirrors the FormPanel block
|
|
11
|
+
* payload (schema + values + submit metadata) so the panel reuses the same
|
|
12
|
+
* FormField router and Zod schema builder the form_panel block uses.
|
|
13
|
+
*/
|
|
14
|
+
export interface EditablePanelDescriptor {
|
|
15
|
+
title: string;
|
|
16
|
+
/** Small label above the title (e.g. "Formulário · matricula-2026"). */
|
|
17
|
+
subtitle?: string;
|
|
18
|
+
/** Form schema tree — fields, sections, groups, headers (FormPanel shape). */
|
|
19
|
+
schema: FormSchemaNode[];
|
|
20
|
+
/** Initial field values, keyed by field key. */
|
|
21
|
+
values?: Record<string, unknown>;
|
|
22
|
+
/** Save button label; falls back to the engine default. */
|
|
23
|
+
submitLabel?: string;
|
|
24
|
+
/** Cancel button label; falls back to the engine default. */
|
|
25
|
+
cancelLabel?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* EditablePanelConfig — page-level config delivered as a shared prop (like the
|
|
30
|
+
* inspector). Hybrid source (D-02): the descriptor may ship inline OR be fetched
|
|
31
|
+
* from `endpoint` per selected id.
|
|
32
|
+
*/
|
|
33
|
+
export interface EditablePanelConfig {
|
|
34
|
+
/**
|
|
35
|
+
* GET endpoint returning an EditablePanelDescriptor; `{id}` is interpolated
|
|
36
|
+
* with the opened row id. Omit when `descriptor` is supplied inline.
|
|
37
|
+
*/
|
|
38
|
+
endpoint?: string;
|
|
39
|
+
/** Inline descriptor — skips the GET (contract-embedded source). */
|
|
40
|
+
descriptor?: EditablePanelDescriptor;
|
|
41
|
+
/** Save endpoint; `{id}` interpolated. Defaults to `endpoint`. */
|
|
42
|
+
submitEndpoint?: string;
|
|
43
|
+
/** Save HTTP method. Default "post". */
|
|
44
|
+
submitMethod?: "post" | "put" | "patch";
|
|
45
|
+
/** Panel width in px. Default 420. */
|
|
46
|
+
width?: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface EditablePanelContextValue {
|
|
50
|
+
selectedId: string | number | null;
|
|
51
|
+
open: (id: string | number) => void;
|
|
52
|
+
close: () => void;
|
|
53
|
+
enabled: boolean;
|
|
54
|
+
descriptor: EditablePanelDescriptor | null;
|
|
55
|
+
loading: boolean;
|
|
56
|
+
saving: boolean;
|
|
57
|
+
submit: (values: Record<string, unknown>) => void;
|
|
58
|
+
width: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ── Context ──────────────────────────────────────────────────────────────────
|
|
62
|
+
//
|
|
63
|
+
// The Community engine owns the editable-panel CONTEXT and PROVIDER (unlike the
|
|
64
|
+
// inspector, whose provider is Pro — D-03: this primitive is fully free). Blocks
|
|
65
|
+
// (DenseTable) call useEditablePanel() and degrade gracefully to the disabled
|
|
66
|
+
// no-op default when a page ships no `editablePanel` config.
|
|
67
|
+
|
|
68
|
+
export const EditablePanelContext = createContext<EditablePanelContextValue>({
|
|
69
|
+
selectedId: null,
|
|
70
|
+
open: () => {},
|
|
71
|
+
close: () => {},
|
|
72
|
+
enabled: false,
|
|
73
|
+
descriptor: null,
|
|
74
|
+
loading: false,
|
|
75
|
+
saving: false,
|
|
76
|
+
submit: () => {},
|
|
77
|
+
width: 420,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export function useEditablePanel(): EditablePanelContextValue {
|
|
81
|
+
return useContext(EditablePanelContext);
|
|
82
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState, type ReactNode } from "react";
|
|
4
|
+
import { router } from "@inertiajs/core";
|
|
5
|
+
|
|
6
|
+
import { trackedFetch } from "@/lib/host-pending";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
EditablePanelContext,
|
|
10
|
+
type EditablePanelConfig,
|
|
11
|
+
type EditablePanelContextValue,
|
|
12
|
+
type EditablePanelDescriptor,
|
|
13
|
+
} from "./EditablePanelContext";
|
|
14
|
+
|
|
15
|
+
interface EditablePanelProviderProps {
|
|
16
|
+
config: EditablePanelConfig;
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Interpolate the `{id}` token in an endpoint template. */
|
|
21
|
+
function withId(endpoint: string, id: string | number): string {
|
|
22
|
+
return endpoint.replace("{id}", String(id));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* EditablePanelProvider — free provider that fills EditablePanelContext with real
|
|
27
|
+
* data fetching + submission. Mounted by the shell when the page ships an
|
|
28
|
+
* `editablePanel` config. Does NOT render the panel — InlineEditablePanel renders
|
|
29
|
+
* as a flex sibling and reads the same context via useEditablePanel().
|
|
30
|
+
*
|
|
31
|
+
* Source is hybrid (D-02): an inline `descriptor` is used verbatim; otherwise the
|
|
32
|
+
* descriptor is fetched per-id from `endpoint`. Submission goes through the
|
|
33
|
+
* Inertia router (same transport as the form_panel block), so hosts get
|
|
34
|
+
* server-driven refresh + validation errors for free.
|
|
35
|
+
*/
|
|
36
|
+
export function EditablePanelProvider({ config, children }: EditablePanelProviderProps) {
|
|
37
|
+
const [selectedId, setSelectedId] = useState<string | number | null>(null);
|
|
38
|
+
const [descriptor, setDescriptor] = useState<EditablePanelDescriptor | null>(
|
|
39
|
+
config.descriptor ?? null,
|
|
40
|
+
);
|
|
41
|
+
const [loading, setLoading] = useState(false);
|
|
42
|
+
const [saving, setSaving] = useState(false);
|
|
43
|
+
|
|
44
|
+
const open = useCallback(
|
|
45
|
+
(id: string | number) => {
|
|
46
|
+
setSelectedId(id);
|
|
47
|
+
// Inline descriptor (contract-embedded) — no round-trip.
|
|
48
|
+
if (config.descriptor) {
|
|
49
|
+
setDescriptor(config.descriptor);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (config.endpoint) setLoading(true);
|
|
53
|
+
},
|
|
54
|
+
[config.descriptor, config.endpoint],
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const close = useCallback(() => {
|
|
58
|
+
setSelectedId(null);
|
|
59
|
+
if (!config.descriptor) setDescriptor(null);
|
|
60
|
+
}, [config.descriptor]);
|
|
61
|
+
|
|
62
|
+
// Fetch the descriptor for the selected id (endpoint source only).
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (selectedId === null || config.descriptor || !config.endpoint) return;
|
|
65
|
+
|
|
66
|
+
const url = withId(config.endpoint, selectedId);
|
|
67
|
+
let cancelled = false;
|
|
68
|
+
|
|
69
|
+
trackedFetch(url, {
|
|
70
|
+
headers: { Accept: "application/json", "X-Requested-With": "XMLHttpRequest" },
|
|
71
|
+
})
|
|
72
|
+
.then((r) => r.json())
|
|
73
|
+
.then((json: EditablePanelDescriptor) => {
|
|
74
|
+
if (!cancelled) setDescriptor(json);
|
|
75
|
+
})
|
|
76
|
+
.catch(() => {
|
|
77
|
+
if (!cancelled) setDescriptor(null);
|
|
78
|
+
})
|
|
79
|
+
.finally(() => {
|
|
80
|
+
if (!cancelled) setLoading(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return () => {
|
|
84
|
+
cancelled = true;
|
|
85
|
+
};
|
|
86
|
+
}, [selectedId, config.descriptor, config.endpoint]);
|
|
87
|
+
|
|
88
|
+
const submit = useCallback(
|
|
89
|
+
(values: Record<string, unknown>) => {
|
|
90
|
+
if (selectedId === null) return;
|
|
91
|
+
const base = config.submitEndpoint ?? config.endpoint;
|
|
92
|
+
if (!base) return;
|
|
93
|
+
const url = withId(base, selectedId);
|
|
94
|
+
const method = config.submitMethod ?? "post";
|
|
95
|
+
setSaving(true);
|
|
96
|
+
router[method](url, values as Record<string, string>, {
|
|
97
|
+
preserveScroll: true,
|
|
98
|
+
preserveState: true,
|
|
99
|
+
onSuccess: () => close(),
|
|
100
|
+
onFinish: () => setSaving(false),
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
[selectedId, config.submitEndpoint, config.endpoint, config.submitMethod, close],
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const ctx = useMemo<EditablePanelContextValue>(
|
|
107
|
+
() => ({
|
|
108
|
+
selectedId,
|
|
109
|
+
open,
|
|
110
|
+
close,
|
|
111
|
+
enabled: true,
|
|
112
|
+
descriptor,
|
|
113
|
+
loading,
|
|
114
|
+
saving,
|
|
115
|
+
submit,
|
|
116
|
+
width: config.width ?? 420,
|
|
117
|
+
}),
|
|
118
|
+
[selectedId, open, close, descriptor, loading, saving, submit, config.width],
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
return <EditablePanelContext.Provider value={ctx}>{children}</EditablePanelContext.Provider>;
|
|
122
|
+
}
|