@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,384 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CardGridBlock — contract-driven card grid with variant support.
|
|
3
|
+
*
|
|
4
|
+
* Renders rows as clickable cards in a responsive grid.
|
|
5
|
+
* When an InspectorContext is available, clicking a card opens the inspector.
|
|
6
|
+
*
|
|
7
|
+
* Variants control visual layout:
|
|
8
|
+
* - 'default': generic key-value card
|
|
9
|
+
* - 'store': ecommerce store card with logo, stats, status badge
|
|
10
|
+
* - 'connector': connector card with type icon and health indicator
|
|
11
|
+
*
|
|
12
|
+
* @see ADR-807
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
"use client";
|
|
16
|
+
|
|
17
|
+
import { useCallback, useMemo, useState, type ReactElement } from "react";
|
|
18
|
+
import { HugeiconsIcon, type IconSvgElement } from "@hugeicons/react";
|
|
19
|
+
import { router } from "@inertiajs/core";
|
|
20
|
+
import { Link } from "@inertiajs/react";
|
|
21
|
+
|
|
22
|
+
import { ConfirmationDialog } from "@/base/partials/ConfirmationDialog";
|
|
23
|
+
import { useInspector } from "@/base/shell/partials/InspectorContext";
|
|
24
|
+
import { getIcon } from "@/base/utils/icons";
|
|
25
|
+
import { interpolate } from "@/base/utils/interpolate";
|
|
26
|
+
import type {
|
|
27
|
+
ActionConfirmation,
|
|
28
|
+
CardGridBlockData,
|
|
29
|
+
CardGridColumnDef,
|
|
30
|
+
} from "@/contracts/block-data";
|
|
31
|
+
import type { BlockProps } from "@/engine/registries";
|
|
32
|
+
import { renderLabel } from "@/i18n/render-label";
|
|
33
|
+
import { useTranslation } from "@/i18n/useTranslation";
|
|
34
|
+
import { resolveActionTarget } from "@/lib/actions/resolve-action-target";
|
|
35
|
+
import { cn } from "@/lib/utils";
|
|
36
|
+
import { Button } from "@/primitives/reui/button";
|
|
37
|
+
|
|
38
|
+
export function CardGridBlock({ block }: BlockProps<CardGridBlockData>): ReactElement {
|
|
39
|
+
const { t } = useTranslation();
|
|
40
|
+
const { data } = block;
|
|
41
|
+
const { select, selectedId, enabled } = useInspector();
|
|
42
|
+
const variant = data.variant ?? "default";
|
|
43
|
+
const reloadKey = block.key;
|
|
44
|
+
|
|
45
|
+
const [confirmDialog, setConfirmDialog] = useState<{
|
|
46
|
+
open: boolean;
|
|
47
|
+
confirmation: ActionConfirmation;
|
|
48
|
+
row: Record<string, unknown>;
|
|
49
|
+
href?: string;
|
|
50
|
+
method?: string;
|
|
51
|
+
isNavigation?: boolean;
|
|
52
|
+
} | null>(null);
|
|
53
|
+
|
|
54
|
+
const handleConfirm = useCallback(() => {
|
|
55
|
+
if (!confirmDialog) return;
|
|
56
|
+
const { href, method, isNavigation } = confirmDialog;
|
|
57
|
+
setConfirmDialog(null);
|
|
58
|
+
|
|
59
|
+
if (!href) return;
|
|
60
|
+
if (isNavigation) {
|
|
61
|
+
router.visit(href);
|
|
62
|
+
} else if (method === "delete") {
|
|
63
|
+
router.delete(href, { preserveState: true, only: [reloadKey] });
|
|
64
|
+
} else {
|
|
65
|
+
const reqMethod = (method ?? "post") as "post" | "put" | "patch";
|
|
66
|
+
router[reqMethod](href, {} as never, { preserveState: true, only: [reloadKey] });
|
|
67
|
+
}
|
|
68
|
+
}, [confirmDialog, reloadKey]);
|
|
69
|
+
|
|
70
|
+
const handleCloseConfirm = useCallback(() => setConfirmDialog(null), []);
|
|
71
|
+
|
|
72
|
+
const runRowAction = useCallback(
|
|
73
|
+
(
|
|
74
|
+
action: NonNullable<CardGridBlockData["rowActions"]>[number],
|
|
75
|
+
row: Record<string, unknown>,
|
|
76
|
+
) => {
|
|
77
|
+
const target = resolveActionTarget(action);
|
|
78
|
+
const resolvedHref = interpolate(target.url, row);
|
|
79
|
+
|
|
80
|
+
if (action.confirmation) {
|
|
81
|
+
setConfirmDialog({
|
|
82
|
+
open: true,
|
|
83
|
+
confirmation: action.confirmation,
|
|
84
|
+
row,
|
|
85
|
+
href: resolvedHref,
|
|
86
|
+
method: target.method,
|
|
87
|
+
isNavigation: target.kind === "link",
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (target.kind === "link") {
|
|
93
|
+
router.visit(resolvedHref);
|
|
94
|
+
} else if (target.method === "delete") {
|
|
95
|
+
router.delete(resolvedHref, { preserveState: true, only: [reloadKey] });
|
|
96
|
+
} else {
|
|
97
|
+
const method = target.method as "post" | "put" | "patch";
|
|
98
|
+
router[method](resolvedHref, {} as never, { preserveState: true, only: [reloadKey] });
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
[reloadKey],
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
if (data.rows.length === 0 && data.emptyState) {
|
|
105
|
+
return (
|
|
106
|
+
<div className="flex flex-col items-center justify-center rounded-lg border border-dashed p-12 text-center">
|
|
107
|
+
{data.emptyState.title && (
|
|
108
|
+
<h3 className="text-lg font-semibold">{data.emptyState.title}</h3>
|
|
109
|
+
)}
|
|
110
|
+
{data.emptyState.description && (
|
|
111
|
+
<p className="text-muted-foreground mt-1 text-sm">{data.emptyState.description}</p>
|
|
112
|
+
)}
|
|
113
|
+
{data.emptyState.cta && (
|
|
114
|
+
<Link
|
|
115
|
+
href={data.emptyState.cta.href}
|
|
116
|
+
className="bg-primary text-primary-foreground mt-4 inline-flex items-center rounded-md px-4 py-2 text-sm font-medium"
|
|
117
|
+
>
|
|
118
|
+
{data.emptyState.cta.label}
|
|
119
|
+
</Link>
|
|
120
|
+
)}
|
|
121
|
+
</div>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<div className="grid grid-cols-[repeat(auto-fill,minmax(300px,1fr))] gap-4">
|
|
127
|
+
{data.rows.map((row, index) => {
|
|
128
|
+
// Preserve the row id verbatim — it may be a string/UUID, not just a
|
|
129
|
+
// number — so selection works for non-numeric ids. Rows without an id
|
|
130
|
+
// fall back to the index for a stable, unique React key and are not
|
|
131
|
+
// selectable.
|
|
132
|
+
const id = row.id as string | number | undefined;
|
|
133
|
+
const key = id != null ? String(id) : `row-${index}`;
|
|
134
|
+
const isSelected = enabled && id != null && selectedId === id;
|
|
135
|
+
|
|
136
|
+
const canSelect = enabled && id != null;
|
|
137
|
+
const editHref = data.editHref ? interpolate(data.editHref, row) : undefined;
|
|
138
|
+
const hasActions = editHref != null || (data.rowActions?.length ?? 0) > 0;
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<div
|
|
142
|
+
key={key}
|
|
143
|
+
role="button"
|
|
144
|
+
tabIndex={0}
|
|
145
|
+
onClick={() => canSelect && select(id as string | number)}
|
|
146
|
+
onKeyDown={(e) => {
|
|
147
|
+
if (canSelect && (e.key === "Enter" || e.key === " ")) {
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
select(id as string | number);
|
|
150
|
+
}
|
|
151
|
+
}}
|
|
152
|
+
className={cn(
|
|
153
|
+
"bg-card text-card-foreground relative rounded-lg border p-5 text-left transition-all",
|
|
154
|
+
"cursor-pointer",
|
|
155
|
+
"hover:border-primary/50 hover:shadow-sm",
|
|
156
|
+
isSelected && "border-primary ring-primary/20 ring-2",
|
|
157
|
+
)}
|
|
158
|
+
>
|
|
159
|
+
{hasActions && (
|
|
160
|
+
<div
|
|
161
|
+
className="absolute top-3 right-3 flex items-center gap-1"
|
|
162
|
+
onClick={(e) => e.stopPropagation()}
|
|
163
|
+
>
|
|
164
|
+
{editHref && (
|
|
165
|
+
<Button
|
|
166
|
+
variant="ghost"
|
|
167
|
+
size="icon-xs"
|
|
168
|
+
asChild
|
|
169
|
+
aria-label={t("middag.ui.card.edit")}
|
|
170
|
+
>
|
|
171
|
+
<Link href={editHref}>
|
|
172
|
+
<HugeiconsIcon
|
|
173
|
+
icon={getIcon("edit") as unknown as IconSvgElement}
|
|
174
|
+
className="size-3.5"
|
|
175
|
+
/>
|
|
176
|
+
</Link>
|
|
177
|
+
</Button>
|
|
178
|
+
)}
|
|
179
|
+
{data.rowActions?.map((action) => (
|
|
180
|
+
<Button
|
|
181
|
+
key={action.id}
|
|
182
|
+
variant="ghost"
|
|
183
|
+
size="icon-xs"
|
|
184
|
+
className={cn(
|
|
185
|
+
action.intent === "danger" && "text-destructive hover:text-destructive",
|
|
186
|
+
)}
|
|
187
|
+
title={renderLabel(action.label, t)}
|
|
188
|
+
onClick={() => runRowAction(action, row)}
|
|
189
|
+
>
|
|
190
|
+
{action.icon && (
|
|
191
|
+
<HugeiconsIcon
|
|
192
|
+
icon={getIcon(action.icon) as unknown as IconSvgElement}
|
|
193
|
+
className="size-3.5"
|
|
194
|
+
/>
|
|
195
|
+
)}
|
|
196
|
+
</Button>
|
|
197
|
+
))}
|
|
198
|
+
</div>
|
|
199
|
+
)}
|
|
200
|
+
<CardContent row={row} columns={data.columns} variant={variant} />
|
|
201
|
+
</div>
|
|
202
|
+
);
|
|
203
|
+
})}
|
|
204
|
+
{confirmDialog && (
|
|
205
|
+
<ConfirmationDialog
|
|
206
|
+
open={confirmDialog.open}
|
|
207
|
+
onClose={handleCloseConfirm}
|
|
208
|
+
onConfirm={handleConfirm}
|
|
209
|
+
title={renderLabel(confirmDialog.confirmation.title, t)}
|
|
210
|
+
message={interpolate(
|
|
211
|
+
renderLabel(confirmDialog.confirmation.message, t),
|
|
212
|
+
confirmDialog.row,
|
|
213
|
+
)}
|
|
214
|
+
intent={confirmDialog.confirmation.intent}
|
|
215
|
+
confirmLabel={renderLabel(confirmDialog.confirmation.confirmLabel, t) || undefined}
|
|
216
|
+
cancelLabel={renderLabel(confirmDialog.confirmation.cancelLabel, t) || undefined}
|
|
217
|
+
/>
|
|
218
|
+
)}
|
|
219
|
+
</div>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ── Card variants ────────────────────────────────────────────────────────────
|
|
224
|
+
|
|
225
|
+
function CardContent({
|
|
226
|
+
row,
|
|
227
|
+
columns,
|
|
228
|
+
variant,
|
|
229
|
+
}: {
|
|
230
|
+
row: Record<string, unknown>;
|
|
231
|
+
columns: CardGridColumnDef[];
|
|
232
|
+
variant: string;
|
|
233
|
+
}): ReactElement {
|
|
234
|
+
if (variant === "store") {
|
|
235
|
+
return <StoreCard row={row} />;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (variant === "connector") {
|
|
239
|
+
return <ConnectorCard row={row} />;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Default variant: render columns as key-value pairs
|
|
243
|
+
return (
|
|
244
|
+
<div className="space-y-2">
|
|
245
|
+
<h3 className="font-semibold">{String(row.fullname ?? row.name ?? row.title ?? "")}</h3>
|
|
246
|
+
{columns
|
|
247
|
+
.filter((col) => col.key !== "id" && col.key !== "fullname")
|
|
248
|
+
.map((col) => (
|
|
249
|
+
<div key={col.key} className="flex items-center justify-between text-sm">
|
|
250
|
+
<span className="text-muted-foreground">{col.label}</span>
|
|
251
|
+
<span className="font-medium">{formatValue(row[col.key], col.kind)}</span>
|
|
252
|
+
</div>
|
|
253
|
+
))}
|
|
254
|
+
</div>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function StoreCard({ row }: { row: Record<string, unknown> }): ReactElement {
|
|
259
|
+
const { t } = useTranslation();
|
|
260
|
+
const provider = String(row.provider_type ?? row.idnumber ?? "");
|
|
261
|
+
const status = String(row.status ?? "inactive");
|
|
262
|
+
const initial = provider.charAt(0).toUpperCase() || "S";
|
|
263
|
+
|
|
264
|
+
const logoColor = useMemo(() => {
|
|
265
|
+
const colors: Record<string, string> = {
|
|
266
|
+
woocommerce: "bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",
|
|
267
|
+
eduzz: "bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400",
|
|
268
|
+
digitalmanagerguru: "bg-teal-100 text-teal-700 dark:bg-teal-900/30 dark:text-teal-400",
|
|
269
|
+
};
|
|
270
|
+
return (
|
|
271
|
+
colors[provider.toLowerCase()] ??
|
|
272
|
+
"bg-zinc-100 text-zinc-700 dark:bg-zinc-800 dark:text-zinc-300"
|
|
273
|
+
);
|
|
274
|
+
}, [provider]);
|
|
275
|
+
|
|
276
|
+
const statusColor =
|
|
277
|
+
status === "active"
|
|
278
|
+
? "bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-400"
|
|
279
|
+
: status === "error"
|
|
280
|
+
? "bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400"
|
|
281
|
+
: "bg-zinc-100 text-zinc-700 dark:bg-zinc-800 dark:text-zinc-300";
|
|
282
|
+
|
|
283
|
+
return (
|
|
284
|
+
<>
|
|
285
|
+
<div className="mb-3 flex items-center gap-3">
|
|
286
|
+
<div
|
|
287
|
+
className={cn(
|
|
288
|
+
"flex h-10 w-10 items-center justify-center rounded-md text-sm font-bold",
|
|
289
|
+
logoColor,
|
|
290
|
+
)}
|
|
291
|
+
>
|
|
292
|
+
{initial}
|
|
293
|
+
</div>
|
|
294
|
+
<div className="min-w-0 flex-1">
|
|
295
|
+
<div className="truncate font-semibold">{String(row.fullname ?? "")}</div>
|
|
296
|
+
<div className="text-muted-foreground text-xs tracking-wider uppercase">{provider}</div>
|
|
297
|
+
</div>
|
|
298
|
+
</div>
|
|
299
|
+
<div className="flex items-center justify-between border-t pt-3">
|
|
300
|
+
<span
|
|
301
|
+
className={cn(
|
|
302
|
+
"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium",
|
|
303
|
+
statusColor,
|
|
304
|
+
)}
|
|
305
|
+
>
|
|
306
|
+
<span className="h-1.5 w-1.5 rounded-full bg-current" />
|
|
307
|
+
{t(`middag.ui.card.status.${status}`, { defaultValue: status })}
|
|
308
|
+
</span>
|
|
309
|
+
</div>
|
|
310
|
+
</>
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function ConnectorCard({ row }: { row: Record<string, unknown> }): ReactElement {
|
|
315
|
+
const { t } = useTranslation();
|
|
316
|
+
const type = String(row.connector_type ?? "");
|
|
317
|
+
const extension = String(row.extension ?? "");
|
|
318
|
+
const status = String(row.status ?? "unconfigured");
|
|
319
|
+
const latency = row.latency_ms != null ? `${row.latency_ms}ms` : "—";
|
|
320
|
+
const initial = type.charAt(0).toUpperCase() || "C";
|
|
321
|
+
|
|
322
|
+
const typeColor = useMemo(() => {
|
|
323
|
+
const colors: Record<string, string> = {
|
|
324
|
+
http_api: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
|
|
325
|
+
oauth2: "bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",
|
|
326
|
+
webhook: "bg-violet-100 text-violet-700 dark:bg-violet-900/30 dark:text-violet-400",
|
|
327
|
+
sdk: "bg-cyan-100 text-cyan-700 dark:bg-cyan-900/30 dark:text-cyan-400",
|
|
328
|
+
};
|
|
329
|
+
return (
|
|
330
|
+
colors[type.toLowerCase()] ?? "bg-zinc-100 text-zinc-700 dark:bg-zinc-800 dark:text-zinc-300"
|
|
331
|
+
);
|
|
332
|
+
}, [type]);
|
|
333
|
+
|
|
334
|
+
const statusColor =
|
|
335
|
+
status === "connected"
|
|
336
|
+
? "bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-400"
|
|
337
|
+
: status === "degraded"
|
|
338
|
+
? "bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-400"
|
|
339
|
+
: status === "disconnected" || status === "error"
|
|
340
|
+
? "bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400"
|
|
341
|
+
: "bg-zinc-100 text-zinc-700 dark:bg-zinc-800 dark:text-zinc-300";
|
|
342
|
+
|
|
343
|
+
return (
|
|
344
|
+
<>
|
|
345
|
+
<div className="mb-3 flex items-center gap-3">
|
|
346
|
+
<div
|
|
347
|
+
className={cn(
|
|
348
|
+
"flex h-10 w-10 items-center justify-center rounded-md text-sm font-bold",
|
|
349
|
+
typeColor,
|
|
350
|
+
)}
|
|
351
|
+
>
|
|
352
|
+
{initial}
|
|
353
|
+
</div>
|
|
354
|
+
<div className="min-w-0 flex-1">
|
|
355
|
+
<div className="truncate font-semibold">{String(row.fullname ?? "")}</div>
|
|
356
|
+
<div className="text-muted-foreground text-xs">
|
|
357
|
+
{type} · {extension}
|
|
358
|
+
</div>
|
|
359
|
+
</div>
|
|
360
|
+
</div>
|
|
361
|
+
<div className="flex items-center justify-between border-t pt-3">
|
|
362
|
+
<span
|
|
363
|
+
className={cn(
|
|
364
|
+
"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium",
|
|
365
|
+
statusColor,
|
|
366
|
+
)}
|
|
367
|
+
>
|
|
368
|
+
<span className="h-1.5 w-1.5 rounded-full bg-current" />
|
|
369
|
+
{t(`middag.ui.card.status.${status}`, { defaultValue: status })}
|
|
370
|
+
</span>
|
|
371
|
+
<span className="text-muted-foreground text-xs">{latency}</span>
|
|
372
|
+
</div>
|
|
373
|
+
</>
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function formatValue(value: unknown, kind?: string): string {
|
|
378
|
+
if (value === null || value === undefined) return "—";
|
|
379
|
+
if (kind === "boolean") return value ? "✓" : "✗";
|
|
380
|
+
if (kind === "timestamp" && typeof value === "number") {
|
|
381
|
+
return new Date(value * 1000).toLocaleDateString();
|
|
382
|
+
}
|
|
383
|
+
return String(value);
|
|
384
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChartBlock — free-tier chart renderer (line / bar / area). Reads the
|
|
3
|
+
* middag-php-ui `chart` wire shape: { chartType, categoryKey, series, data }.
|
|
4
|
+
* The premium `chart_panel` (pie, playground, richer config) lives in
|
|
5
|
+
* @middag-io/react-pro.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ReactElement } from "react";
|
|
9
|
+
import { Area, AreaChart, Bar, BarChart, CartesianGrid, Line, LineChart, XAxis } from "recharts";
|
|
10
|
+
|
|
11
|
+
import type { ChartBlockData } from "@/contracts/block-data";
|
|
12
|
+
import type { BlockProps } from "@/engine/registries";
|
|
13
|
+
import {
|
|
14
|
+
ChartContainer,
|
|
15
|
+
ChartLegend,
|
|
16
|
+
ChartLegendContent,
|
|
17
|
+
ChartTooltip,
|
|
18
|
+
ChartTooltipContent,
|
|
19
|
+
type ChartConfig,
|
|
20
|
+
} from "@/primitives/reui/chart";
|
|
21
|
+
|
|
22
|
+
export function ChartBlock({ block }: BlockProps<ChartBlockData>): ReactElement {
|
|
23
|
+
const { chartType, categoryKey, series, data, options } = block.data;
|
|
24
|
+
|
|
25
|
+
const config: ChartConfig = Object.fromEntries(
|
|
26
|
+
series.map((s, i) => [
|
|
27
|
+
s.key,
|
|
28
|
+
{ label: s.label, color: s.color ?? `var(--chart-${(i % 5) + 1})` },
|
|
29
|
+
]),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const showGrid = options?.showGrid ?? true;
|
|
33
|
+
const showLegend = options?.showLegend ?? series.length > 1;
|
|
34
|
+
|
|
35
|
+
const grid = showGrid ? <CartesianGrid vertical={false} /> : null;
|
|
36
|
+
const axis = <XAxis dataKey={categoryKey} tickLine={false} axisLine={false} tickMargin={8} />;
|
|
37
|
+
const tooltip = <ChartTooltip content={<ChartTooltipContent />} />;
|
|
38
|
+
const legend = showLegend ? <ChartLegend content={<ChartLegendContent />} /> : null;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<ChartContainer config={config}>
|
|
42
|
+
{chartType === "bar" ? (
|
|
43
|
+
<BarChart data={data}>
|
|
44
|
+
{grid}
|
|
45
|
+
{axis}
|
|
46
|
+
{tooltip}
|
|
47
|
+
{legend}
|
|
48
|
+
{series.map((s) => (
|
|
49
|
+
<Bar key={s.key} dataKey={s.key} fill={`var(--color-${s.key})`} radius={4} />
|
|
50
|
+
))}
|
|
51
|
+
</BarChart>
|
|
52
|
+
) : chartType === "area" ? (
|
|
53
|
+
<AreaChart data={data}>
|
|
54
|
+
{grid}
|
|
55
|
+
{axis}
|
|
56
|
+
{tooltip}
|
|
57
|
+
{legend}
|
|
58
|
+
{series.map((s) => (
|
|
59
|
+
<Area
|
|
60
|
+
key={s.key}
|
|
61
|
+
dataKey={s.key}
|
|
62
|
+
stroke={`var(--color-${s.key})`}
|
|
63
|
+
fill={`var(--color-${s.key})`}
|
|
64
|
+
fillOpacity={0.2}
|
|
65
|
+
/>
|
|
66
|
+
))}
|
|
67
|
+
</AreaChart>
|
|
68
|
+
) : (
|
|
69
|
+
<LineChart data={data}>
|
|
70
|
+
{grid}
|
|
71
|
+
{axis}
|
|
72
|
+
{tooltip}
|
|
73
|
+
{legend}
|
|
74
|
+
{series.map((s) => (
|
|
75
|
+
<Line key={s.key} dataKey={s.key} stroke={`var(--color-${s.key})`} dot={false} />
|
|
76
|
+
))}
|
|
77
|
+
</LineChart>
|
|
78
|
+
)}
|
|
79
|
+
</ChartContainer>
|
|
80
|
+
);
|
|
81
|
+
}
|