@flikk/ui 1.0.0-beta.27 → 1.0.0-beta.29
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/dist/bg/1.webp +0 -0
- package/dist/bg/10.webp +0 -0
- package/dist/bg/11.webp +0 -0
- package/dist/bg/12.webp +0 -0
- package/dist/bg/13.webp +0 -0
- package/dist/bg/14.webp +0 -0
- package/dist/bg/15.webp +0 -0
- package/dist/bg/16.webp +0 -0
- package/dist/bg/17.webp +0 -0
- package/dist/bg/18.webp +0 -0
- package/dist/bg/19.webp +0 -0
- package/dist/bg/2.webp +0 -0
- package/dist/bg/20.webp +0 -0
- package/dist/bg/21.webp +0 -0
- package/dist/bg/22.webp +0 -0
- package/dist/bg/3.webp +0 -0
- package/dist/bg/4.webp +0 -0
- package/dist/bg/5.webp +0 -0
- package/dist/bg/6.webp +0 -0
- package/dist/bg/7.webp +0 -0
- package/dist/bg/8.webp +0 -0
- package/dist/bg/9.webp +0 -0
- package/dist/components/ai/CodeBlock/CodeBlock.theme.js +1 -1
- package/dist/components/ai/PromptInput/PromptInput.js +7 -143
- package/dist/components/ai/PromptInput/VoiceRecorder.js +0 -88
- package/dist/components/ai/TokenCounter/TokenCounter.theme.js +1 -1
- package/dist/components/canvas/Background.d.ts +19 -0
- package/dist/components/canvas/Background.js +23 -0
- package/dist/components/canvas/BaseNode.d.ts +15 -0
- package/dist/components/canvas/BaseNode.js +20 -0
- package/dist/components/canvas/CanvasToolbar.d.ts +34 -0
- package/dist/components/canvas/CanvasToolbar.js +34 -0
- package/dist/components/canvas/Edge.d.ts +35 -0
- package/dist/components/canvas/Edge.js +97 -0
- package/dist/components/canvas/EdgeLayer.d.ts +18 -0
- package/dist/components/canvas/EdgeLayer.js +111 -0
- package/dist/components/canvas/Handle.d.ts +11 -0
- package/dist/components/canvas/Handle.js +63 -0
- package/dist/components/canvas/MiniMap.d.ts +22 -0
- package/dist/components/canvas/MiniMap.js +105 -0
- package/dist/components/canvas/NodeCanvas.d.ts +10 -0
- package/dist/components/canvas/NodeCanvas.js +477 -0
- package/dist/components/canvas/NodeCanvas.theme.d.ts +7 -0
- package/dist/components/canvas/NodeCanvas.theme.js +9 -0
- package/dist/components/canvas/NodeCanvas.types.d.ts +187 -0
- package/dist/components/canvas/NodeControls.d.ts +25 -0
- package/dist/components/canvas/NodeControls.js +40 -0
- package/dist/components/canvas/NodeRenderer.d.ts +19 -0
- package/dist/components/canvas/NodeRenderer.js +117 -0
- package/dist/components/canvas/changes.d.ts +11 -0
- package/dist/components/canvas/changes.js +76 -0
- package/dist/components/canvas/context/CanvasContext.d.ts +32 -0
- package/dist/components/canvas/context/CanvasContext.js +14 -0
- package/dist/components/canvas/context/ConnectionContext.d.ts +33 -0
- package/dist/components/canvas/context/ConnectionContext.js +13 -0
- package/dist/components/canvas/context/HandleRegistry.d.ts +24 -0
- package/dist/components/canvas/context/HandleRegistry.js +15 -0
- package/dist/components/canvas/context/InteractionContext.d.ts +18 -0
- package/dist/components/canvas/context/InteractionContext.js +14 -0
- package/dist/components/canvas/context/NodeIdContext.d.ts +3 -0
- package/dist/components/canvas/context/NodeIdContext.js +15 -0
- package/dist/components/canvas/hooks/useConnection.d.ts +17 -0
- package/dist/components/canvas/hooks/useConnection.js +29 -0
- package/dist/components/canvas/hooks/useMarquee.d.ts +25 -0
- package/dist/components/canvas/hooks/useMarquee.js +91 -0
- package/dist/components/canvas/hooks/useNodeDrag.d.ts +23 -0
- package/dist/components/canvas/hooks/useNodeDrag.js +110 -0
- package/dist/components/canvas/hooks/usePanZoom.d.ts +30 -0
- package/dist/components/canvas/hooks/usePanZoom.js +189 -0
- package/dist/components/canvas/hooks/useViewport.d.ts +21 -0
- package/dist/components/canvas/hooks/useViewport.js +35 -0
- package/dist/components/canvas/index.d.ts +14 -0
- package/dist/components/canvas/index.js +12 -0
- package/dist/components/canvas/layout.d.ts +22 -0
- package/dist/components/canvas/layout.js +67 -0
- package/dist/components/canvas/utils.d.ts +4 -0
- package/dist/components/canvas/utils.js +16 -0
- package/dist/components/charts/AreaChart/AreaChart.js +136 -101
- package/dist/components/charts/AreaChart/AreaChart.types.d.ts +5 -5
- package/dist/components/charts/AreaChart/AreaChart.types.js +1 -0
- package/dist/components/charts/BarChart/BarChart.js +207 -143
- package/dist/components/charts/BarChart/BarChart.types.d.ts +4 -4
- package/dist/components/charts/BarChart/BarChart.types.js +1 -0
- package/dist/components/charts/ComboChart/ComboChart.types.d.ts +2 -2
- package/dist/components/charts/LineChart/LineChart.js +88 -72
- package/dist/components/charts/LineChart/LineChart.types.d.ts +3 -3
- package/dist/components/charts/RadarChart/RadarChart.js +1 -1
- package/dist/components/charts/RadarChart/RadarChart.theme.js +5 -2
- package/dist/components/charts/ScatterPlot/ScatterPlot.js +62 -72
- package/dist/components/charts/ScatterPlot/ScatterPlot.theme.js +10 -1
- package/dist/components/charts/ScatterPlot/ScatterPlot.types.d.ts +3 -9
- package/dist/components/charts/StackedBarChart/StackedBarChart.js +33 -33
- package/dist/components/charts/StackedBarChart/StackedBarChart.types.d.ts +2 -2
- package/dist/components/charts/hooks/index.d.ts +2 -0
- package/dist/components/charts/hooks/useChartDimensions.d.ts +29 -0
- package/dist/components/charts/hooks/useChartDimensions.js +42 -0
- package/dist/components/charts/shared/ChartTooltip/ChartTooltip.theme.js +1 -1
- package/dist/components/charts/types/chart.types.d.ts +11 -2
- package/dist/components/charts/types/chart.types.js +10 -3
- package/dist/components/core/Avatar/Avatar.js +5 -1
- package/dist/components/core/AvatarGroup/AvatarGroup.js +5 -1
- package/dist/components/core/AvatarGroup/AvatarGroup.theme.js +4 -2
- package/dist/components/core/Badge/Badge.js +1 -1
- package/dist/components/core/Badge/Badge.theme.js +16 -15
- package/dist/components/core/Button/Button.js +1 -1
- package/dist/components/core/Button/Button.theme.js +2 -2
- package/dist/components/core/Calendar/Calendar.theme.js +1 -1
- package/dist/components/core/Card/Card.js +7 -3
- package/dist/components/core/Card/Card.theme.js +3 -3
- package/dist/components/core/Card/Card.types.d.ts +27 -2
- package/dist/components/core/CommandPalette/CommandPalette.theme.js +2 -2
- package/dist/components/core/ContextMenu/ContextMenu.theme.js +2 -2
- package/dist/components/core/ContextMenu/ContextMenuItem.js +1 -1
- package/dist/components/core/ContextMenu/ContextMenuSubTrigger.js +1 -1
- package/dist/components/core/Dropdown/Dropdown.theme.js +3 -3
- package/dist/components/core/Dropdown/DropdownMenu.js +57 -29
- package/dist/components/core/HeroCard/HeroCard.d.ts +5 -0
- package/dist/components/core/HeroCard/HeroCard.js +99 -0
- package/dist/components/core/HeroCard/HeroCard.theme.d.ts +3 -0
- package/dist/components/core/HeroCard/HeroCard.theme.js +8 -0
- package/dist/components/core/HeroCard/HeroCard.types.d.ts +70 -0
- package/dist/components/core/HeroCard/index.d.ts +4 -0
- package/dist/components/core/Kbd/Kbd.theme.js +1 -1
- package/dist/components/core/Modal/Modal.d.ts +1 -1
- package/dist/components/core/Modal/Modal.js +2 -7
- package/dist/components/core/Modal/Modal.theme.js +4 -8
- package/dist/components/core/Modal/Modal.types.d.ts +0 -10
- package/dist/components/core/Modal/index.d.ts +1 -1
- package/dist/components/core/ModalStack/ModalStack.d.ts +1 -1
- package/dist/components/core/ModalStack/ModalStack.types.d.ts +1 -2
- package/dist/components/core/ModalStack/ModalStackModal.d.ts +1 -1
- package/dist/components/core/ModalStack/ModalStackModal.js +2 -7
- package/dist/components/core/PageHeading/PageHeading.theme.js +2 -2
- package/dist/components/core/Popover/Popover.theme.js +1 -1
- package/dist/components/core/ScrollArea/ScrollArea.js +242 -4
- package/dist/components/core/ScrollArea/ScrollArea.types.d.ts +12 -1
- package/dist/components/core/ScrollArea/smooth/SmoothScrollEngine.d.ts +4 -0
- package/dist/components/core/ScrollArea/smooth/SmoothScrollEngine.js +23 -0
- package/dist/components/core/ScrollArea/smooth/useSmoothScroll.js +4 -0
- package/dist/components/core/ScrollArea/smooth/useSmoothScroll.types.d.ts +5 -0
- package/dist/components/core/Segmented/Segmented.theme.js +2 -2
- package/dist/components/core/Tooltip/Tooltip.theme.js +1 -1
- package/dist/components/core/index.d.ts +1 -0
- package/dist/components/core/index.js +2 -0
- package/dist/components/data-display/DescriptionList/DescriptionList.js +23 -7
- package/dist/components/data-display/DescriptionList/DescriptionList.theme.js +10 -3
- package/dist/components/data-display/DescriptionList/DescriptionList.types.d.ts +49 -10
- package/dist/components/data-display/DescriptionList/index.d.ts +1 -1
- package/dist/components/data-display/Feed/Feed.js +28 -5
- package/dist/components/data-display/Feed/Feed.theme.js +1 -1
- package/dist/components/data-display/Feed/Feed.types.d.ts +32 -1
- package/dist/components/data-display/Feed/index.d.ts +1 -1
- package/dist/components/data-display/Metric/Metric.js +8 -8
- package/dist/components/data-display/Metric/Metric.theme.d.ts +3 -2
- package/dist/components/data-display/Metric/Metric.theme.js +50 -68
- package/dist/components/data-display/Metric/Metric.types.d.ts +19 -21
- package/dist/components/data-display/Table/Table.js +2 -2
- package/dist/components/data-display/Table/Table.theme.js +24 -4
- package/dist/components/data-display/Table/Table.types.d.ts +8 -0
- package/dist/components/data-display/Table/TableBody.js +2 -2
- package/dist/components/data-display/Table/TableCell.js +1 -1
- package/dist/components/data-display/Table/TableRow.d.ts +1 -1
- package/dist/components/data-display/Table/TableRow.js +9 -2
- package/dist/components/data-display/Timeline/Timeline.js +27 -5
- package/dist/components/data-display/Timeline/Timeline.theme.d.ts +10 -2
- package/dist/components/data-display/Timeline/Timeline.theme.js +14 -8
- package/dist/components/data-display/Timeline/Timeline.types.d.ts +48 -16
- package/dist/components/data-display/Timeline/Timeline.utils.d.ts +6 -0
- package/dist/components/data-display/Timeline/Timeline.utils.js +11 -0
- package/dist/components/data-display/Timeline/TimelineItem.js +13 -20
- package/dist/components/data-display/Timeline/TimelineMarker.js +10 -8
- package/dist/components/data-display/Timeline/index.d.ts +2 -2
- package/dist/components/effects/3d/index.d.ts +0 -2
- package/dist/components/effects/3d/index.js +0 -1
- package/dist/components/effects/DotPattern/DotPattern.js +1 -1
- package/dist/components/effects/Overlay/Overlay.theme.js +1 -2
- package/dist/components/effects/Preloader/Preloader.animations.d.ts +23 -0
- package/dist/components/effects/Preloader/Preloader.animations.js +150 -0
- package/dist/components/effects/Preloader/Preloader.d.ts +3 -0
- package/dist/components/effects/Preloader/Preloader.js +119 -0
- package/dist/components/effects/Preloader/Preloader.types.d.ts +63 -0
- package/dist/components/effects/Preloader/index.d.ts +2 -0
- package/dist/components/effects/ProgressiveBlur/ProgressiveBlur.js +25 -14
- package/dist/components/effects/ProgressiveBlur/ProgressiveBlur.types.d.ts +2 -0
- package/dist/components/effects/TiltCard/TiltCard.d.ts +12 -0
- package/dist/components/effects/TiltCard/TiltCard.glow.d.ts +28 -0
- package/dist/components/effects/TiltCard/TiltCard.glow.js +114 -0
- package/dist/components/effects/TiltCard/TiltCard.js +177 -0
- package/dist/components/effects/{SpotlightBorder/SpotlightBorder.shaders.d.ts → TiltCard/TiltCard.shaders.d.ts} +1 -1
- package/dist/components/effects/{SpotlightBorder/SpotlightBorder.shaders.js → TiltCard/TiltCard.shaders.js} +1 -1
- package/dist/components/effects/TiltCard/TiltCard.types.d.ts +88 -0
- package/dist/components/effects/TiltCard/index.d.ts +2 -0
- package/dist/components/effects/index.d.ts +4 -12
- package/dist/components/effects/index.js +2 -6
- package/dist/components/forms/Checkbox/Checkbox.js +7 -1
- package/dist/components/forms/DatePicker/DatePicker.theme.js +2 -2
- package/dist/components/forms/DateRangePicker/DateRangePicker.theme.js +1 -1
- package/dist/components/forms/FileUpload/FileUpload.js +1 -89
- package/dist/components/forms/FormLabel/FormLabel.theme.js +1 -1
- package/dist/components/forms/RichTextEditor/RichTextEditor.theme.js +2 -2
- package/dist/components/forms/Slider/Slider.theme.js +1 -1
- package/dist/components/forms/Switch/Switch.js +27 -15
- package/dist/components/forms/Switch/Switch.theme.d.ts +36 -6
- package/dist/components/forms/Switch/Switch.theme.js +33 -4
- package/dist/components/forms/Switch/Switch.types.d.ts +12 -2
- package/dist/components/forms/TimePicker/TimePicker.theme.js +1 -2
- package/dist/components/forms/TimePicker/TimePickerContent.js +1 -90
- package/dist/components/forms/forms.theme.js +1 -1
- package/dist/components/forms/index.d.ts +0 -4
- package/dist/components/forms/index.js +0 -92
- package/dist/components/generative/GenerativeView.d.ts +21 -0
- package/dist/components/generative/GenerativeView.js +116 -0
- package/dist/components/generative/actions.d.ts +26 -0
- package/dist/components/generative/actions.js +51 -0
- package/dist/components/generative/index.d.ts +11 -0
- package/dist/components/generative/index.js +9 -0
- package/dist/components/generative/registry.d.ts +43 -0
- package/dist/components/generative/registry.js +114 -0
- package/dist/components/generative/resolvers.d.ts +35 -0
- package/dist/components/generative/resolvers.js +93 -0
- package/dist/components/generative/schema.generated.d.ts +2 -0
- package/dist/components/generative/schema.generated.js +1639 -0
- package/dist/components/generative/schemaTypes.d.ts +30 -0
- package/dist/components/generative/streaming.d.ts +39 -0
- package/dist/components/generative/streaming.js +283 -0
- package/dist/components/generative/tools.d.ts +21 -0
- package/dist/components/generative/tools.js +54 -0
- package/dist/components/generative/types.d.ts +41 -0
- package/dist/components/generative/useGenerativeStream.d.ts +37 -0
- package/dist/components/generative/useGenerativeStream.js +36 -0
- package/dist/components/generative/validate.d.ts +24 -0
- package/dist/components/generative/validate.js +259 -0
- package/dist/components/layout/AppShell/AppShell.theme.js +2 -2
- package/dist/components/layout/FormLayout/FormLayout.js +1 -90
- package/dist/components/layout/Grid/Grid.d.ts +3 -0
- package/dist/components/layout/Grid/Grid.js +50 -0
- package/dist/components/layout/Grid/Grid.theme.d.ts +2 -0
- package/dist/components/layout/Grid/Grid.theme.js +35 -0
- package/dist/components/layout/Grid/Grid.types.d.ts +57 -0
- package/dist/components/layout/Grid/index.d.ts +3 -0
- package/dist/components/layout/Section/Section.d.ts +3 -0
- package/dist/components/layout/Section/Section.js +18 -0
- package/dist/components/layout/Section/Section.theme.d.ts +2 -0
- package/dist/components/layout/Section/Section.theme.js +10 -0
- package/dist/components/layout/Section/Section.types.d.ts +34 -0
- package/dist/components/layout/Section/index.d.ts +3 -0
- package/dist/components/layout/Stack/Stack.d.ts +3 -0
- package/dist/components/layout/Stack/Stack.js +19 -0
- package/dist/components/layout/Stack/Stack.theme.d.ts +2 -0
- package/dist/components/layout/Stack/Stack.theme.js +10 -0
- package/dist/components/layout/Stack/Stack.types.d.ts +39 -0
- package/dist/components/layout/Stack/index.d.ts +3 -0
- package/dist/components/layout/index.d.ts +3 -0
- package/dist/components/layout/index.js +6 -0
- package/dist/generative.schema.json +1637 -0
- package/dist/index.js +180 -180
- package/dist/registry.json +648 -464
- package/dist/styles.css +1 -1
- package/dist/tools.json +1731 -0
- package/package.json +17 -4
- package/src/global.scss +53 -101
- package/src/styles/theme.css +687 -493
- package/dist/bg/1.jpg +0 -0
- package/dist/bg/10.jpg +0 -0
- package/dist/bg/11.jpg +0 -0
- package/dist/bg/14.jpg +0 -0
- package/dist/bg/15.jpg +0 -0
- package/dist/bg/16.jpg +0 -0
- package/dist/bg/17.jpg +0 -0
- package/dist/bg/18.jpg +0 -0
- package/dist/bg/19.jpg +0 -0
- package/dist/bg/2.jpg +0 -0
- package/dist/bg/20.jpg +0 -0
- package/dist/bg/21.jpg +0 -0
- package/dist/bg/22.jpg +0 -0
- package/dist/bg/23.jpg +0 -0
- package/dist/bg/24.jpg +0 -0
- package/dist/bg/3.jpg +0 -0
- package/dist/bg/4.jpg +0 -0
- package/dist/bg/5.jpg +0 -0
- package/dist/bg/6.jpg +0 -0
- package/dist/bg/7.jpg +0 -0
- package/dist/bg/8.jpg +0 -0
- package/dist/bg/9.jpg +0 -0
- package/dist/components/effects/MorphingText/MorphingText.d.ts +0 -17
- package/dist/components/effects/MorphingText/MorphingText.js +0 -125
- package/dist/components/effects/MorphingText/MorphingText.types.d.ts +0 -18
- package/dist/components/effects/MorphingText/index.d.ts +0 -2
- package/dist/components/effects/PageTransition/PageTransition.animations.d.ts +0 -8
- package/dist/components/effects/PageTransition/PageTransition.animations.js +0 -53
- package/dist/components/effects/PageTransition/PageTransition.d.ts +0 -3
- package/dist/components/effects/PageTransition/PageTransition.js +0 -82
- package/dist/components/effects/PageTransition/PageTransition.types.d.ts +0 -15
- package/dist/components/effects/PageTransition/index.d.ts +0 -2
- package/dist/components/effects/ParallaxSection/ParallaxSection.d.ts +0 -26
- package/dist/components/effects/ParallaxSection/ParallaxSection.js +0 -71
- package/dist/components/effects/ParallaxSection/ParallaxSection.types.d.ts +0 -11
- package/dist/components/effects/ParallaxSection/index.d.ts +0 -2
- package/dist/components/effects/Spotlight/Spotlight.d.ts +0 -36
- package/dist/components/effects/Spotlight/Spotlight.js +0 -112
- package/dist/components/effects/Spotlight/Spotlight.types.d.ts +0 -29
- package/dist/components/effects/Spotlight/index.d.ts +0 -2
- package/dist/components/effects/SpotlightBorder/SpotlightBorder.d.ts +0 -18
- package/dist/components/effects/SpotlightBorder/SpotlightBorder.js +0 -213
- package/dist/components/effects/SpotlightBorder/SpotlightBorder.types.d.ts +0 -61
- package/dist/components/effects/SpotlightBorder/index.d.ts +0 -2
- package/dist/components/effects/StickyScroll/StickyScroll.d.ts +0 -30
- package/dist/components/effects/StickyScroll/StickyScroll.js +0 -128
- package/dist/components/effects/StickyScroll/StickyScroll.types.d.ts +0 -19
- package/dist/components/effects/StickyScroll/index.d.ts +0 -2
- package/dist/components/forms/CronInput/CronInput.d.ts +0 -3
- package/dist/components/forms/CronInput/CronInput.js +0 -113
- package/dist/components/forms/CronInput/CronInput.theme.d.ts +0 -6
- package/dist/components/forms/CronInput/CronInput.theme.js +0 -75
- package/dist/components/forms/CronInput/CronInput.types.d.ts +0 -109
- package/dist/components/forms/CronInput/CronInput.utils.d.ts +0 -67
- package/dist/components/forms/CronInput/CronInput.utils.js +0 -505
- package/dist/components/forms/CronInput/index.d.ts +0 -4
- /package/dist/components/effects/{SpotlightBorder/SpotlightBorder.types.js → TiltCard/TiltCard.types.js} +0 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
import { Skeleton } from '../core/Skeleton/Skeleton.js';
|
|
4
|
+
import { defaultRegistry, CardShell } from './registry.js';
|
|
5
|
+
import { applyResolvers } from './resolvers.js';
|
|
6
|
+
import { SKELETON_NODE } from './streaming.js';
|
|
7
|
+
import { bindActionProps } from './actions.js';
|
|
8
|
+
|
|
9
|
+
const placeholderStyle = "rounded-lg border border-dashed border-[var(--color-border-secondary)] " +
|
|
10
|
+
"bg-[var(--color-surface-sunken)] p-3 text-xs text-[var(--color-text-muted)]";
|
|
11
|
+
/** The model asked for a component we didn't register — render, don't throw. */
|
|
12
|
+
function UnknownNode({ name }) {
|
|
13
|
+
if (process.env.NODE_ENV !== "production") {
|
|
14
|
+
console.warn(`[GenerativeView]: unknown component "${name}" — rendering placeholder`);
|
|
15
|
+
}
|
|
16
|
+
return (jsxs("div", { role: "note", className: placeholderStyle, children: ["Unknown component \u201C", name, "\u201D"] }));
|
|
17
|
+
}
|
|
18
|
+
/** Streaming placeholder: reserves the target component's footprint until it hydrates. */
|
|
19
|
+
function SkeletonPlaceholder({ props }) {
|
|
20
|
+
var _a;
|
|
21
|
+
const height = (_a = props === null || props === void 0 ? void 0 : props.height) !== null && _a !== void 0 ? _a : 80;
|
|
22
|
+
return jsx(Skeleton, { variant: "rectangle", width: "100%", height: height, className: "rounded-[var(--card-radius)]" });
|
|
23
|
+
}
|
|
24
|
+
/** Per-node error boundary: one bad node never takes down the tree. */
|
|
25
|
+
class NodeBoundary extends React__default.Component {
|
|
26
|
+
constructor() {
|
|
27
|
+
super(...arguments);
|
|
28
|
+
this.state = { failed: false };
|
|
29
|
+
}
|
|
30
|
+
static getDerivedStateFromError() {
|
|
31
|
+
return { failed: true };
|
|
32
|
+
}
|
|
33
|
+
componentDidCatch(error) {
|
|
34
|
+
if (process.env.NODE_ENV !== "production") {
|
|
35
|
+
console.error(`[GenerativeView]: "${this.props.name}" threw while rendering`, error);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
render() {
|
|
39
|
+
if (this.state.failed) {
|
|
40
|
+
return (jsxs("div", { role: "note", className: placeholderStyle, children: ["\u201C", this.props.name, "\u201D failed to render"] }));
|
|
41
|
+
}
|
|
42
|
+
return this.props.children;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function NodeRenderer({ node, registry, inShell, dispatch, }) {
|
|
46
|
+
var _a, _b, _c;
|
|
47
|
+
if (node.component === SKELETON_NODE)
|
|
48
|
+
return jsx(SkeletonPlaceholder, { props: node.props });
|
|
49
|
+
const entry = registry.components[node.component];
|
|
50
|
+
if (!entry)
|
|
51
|
+
return jsx(UnknownNode, { name: node.component });
|
|
52
|
+
const hydrated = applyResolvers(((_a = node.props) !== null && _a !== void 0 ? _a : {}), registry.resolvers, { icons: registry.icons, node });
|
|
53
|
+
const isContainer = entry.kind === "container";
|
|
54
|
+
if (process.env.NODE_ENV !== "production" && !isContainer && ((_b = node.children) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
55
|
+
console.warn(`[GenerativeView]: "${node.component}" is not a container — its children are ignored`);
|
|
56
|
+
}
|
|
57
|
+
const childInShell = entry.providesShell ? true : inShell;
|
|
58
|
+
const children = isContainer && ((_c = node.children) === null || _c === void 0 ? void 0 : _c.length)
|
|
59
|
+
? node.children.map((child, index) => {
|
|
60
|
+
var _a;
|
|
61
|
+
return (jsx(NodeBoundary, { name: child.component, children: jsx(NodeRenderer, { node: child, registry: registry, inShell: childInShell, dispatch: dispatch }) }, (_a = child.id) !== null && _a !== void 0 ? _a : index));
|
|
62
|
+
})
|
|
63
|
+
: undefined;
|
|
64
|
+
// Shell-wrapped leaves: title/subtitle belong to the shell, not the component.
|
|
65
|
+
let componentProps = hydrated;
|
|
66
|
+
let shellTitle;
|
|
67
|
+
let shellSubtitle;
|
|
68
|
+
if (entry.needsShell) {
|
|
69
|
+
const { title, subtitle, ...rest } = hydrated;
|
|
70
|
+
componentProps = rest;
|
|
71
|
+
shellTitle = title;
|
|
72
|
+
shellSubtitle = subtitle;
|
|
73
|
+
}
|
|
74
|
+
let unboundClick;
|
|
75
|
+
if (node.actions && dispatch) {
|
|
76
|
+
const bound = bindActionProps(node, entry.actionProps, componentProps, dispatch);
|
|
77
|
+
componentProps = bound.props;
|
|
78
|
+
unboundClick = bound.unboundClick;
|
|
79
|
+
}
|
|
80
|
+
const Component = entry.component;
|
|
81
|
+
let inner;
|
|
82
|
+
if (entry.render)
|
|
83
|
+
inner = entry.render(componentProps, children);
|
|
84
|
+
else if (isContainer)
|
|
85
|
+
inner = jsx(Component, { ...componentProps, children: children });
|
|
86
|
+
else
|
|
87
|
+
inner = jsx(Component, { ...componentProps });
|
|
88
|
+
const rendered = entry.needsShell && !inShell ? (jsx(CardShell, { title: shellTitle, subtitle: shellSubtitle, children: inner })) : (jsx(Fragment, { children: inner }));
|
|
89
|
+
if (unboundClick && dispatch) {
|
|
90
|
+
const descriptor = unboundClick;
|
|
91
|
+
const fire = () => dispatch(descriptor, {
|
|
92
|
+
component: node.component,
|
|
93
|
+
...(node.id ? { nodeId: node.id } : {}),
|
|
94
|
+
});
|
|
95
|
+
return (jsx("div", { role: "button", tabIndex: 0, className: "cursor-pointer rounded-[var(--card-radius)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-primary)]", onClick: fire, onKeyDown: (e) => {
|
|
96
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
fire();
|
|
99
|
+
}
|
|
100
|
+
}, children: rendered }));
|
|
101
|
+
}
|
|
102
|
+
return rendered;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Render a serializable UINode spec with the given registry.
|
|
106
|
+
* Render-only in P1 — streaming (P3) and action dispatch (P4) layer on top.
|
|
107
|
+
*/
|
|
108
|
+
function GenerativeView({ spec, registry = defaultRegistry, onAction, className, }) {
|
|
109
|
+
const nodes = Array.isArray(spec) ? spec : [spec];
|
|
110
|
+
return (jsx("div", { className: className, children: nodes.map((node, index) => {
|
|
111
|
+
var _a;
|
|
112
|
+
return (jsx(NodeBoundary, { name: node.component, children: jsx(NodeRenderer, { node: node, registry: registry, inShell: false, dispatch: onAction }) }, (_a = node.id) !== null && _a !== void 0 ? _a : index));
|
|
113
|
+
}) }));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { GenerativeView };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ActionDescriptor, JSONValue, UINode } from "./types";
|
|
2
|
+
/** Serializable context delivered alongside the descriptor. */
|
|
3
|
+
export interface ActionContext {
|
|
4
|
+
/** The spec component that fired the action. */
|
|
5
|
+
component: string;
|
|
6
|
+
/** The node's spec id, when present. */
|
|
7
|
+
nodeId?: string;
|
|
8
|
+
/** Serializable callback payload (e.g. the clicked Table row). Never a DOM event. */
|
|
9
|
+
data?: JSONValue;
|
|
10
|
+
}
|
|
11
|
+
/** Consumer handler: first arg is the EXACT descriptor from the spec. */
|
|
12
|
+
export type ActionHandler = (action: ActionDescriptor, context: ActionContext) => void;
|
|
13
|
+
/** Extract a serializable data argument from a component callback — DOM events are dropped. */
|
|
14
|
+
export declare function extractActionData(arg: unknown): JSONValue | undefined;
|
|
15
|
+
export interface BoundActions {
|
|
16
|
+
/** Component props with callback props injected for registry-mapped action keys. */
|
|
17
|
+
props: Record<string, unknown>;
|
|
18
|
+
/** A `click` action with no native callback mapping — caller wraps the output. */
|
|
19
|
+
unboundClick?: ActionDescriptor;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Bind a node's spec actions to component callback props via the registry's
|
|
23
|
+
* actionProps map. Unmapped `click` actions are returned for generic wrapping;
|
|
24
|
+
* other unmapped keys are dropped with a dev warning.
|
|
25
|
+
*/
|
|
26
|
+
export declare function bindActionProps(node: UINode, actionProps: Record<string, string> | undefined, componentProps: Record<string, unknown>, dispatch: ActionHandler): BoundActions;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Extract a serializable data argument from a component callback — DOM events are dropped. */
|
|
2
|
+
function extractActionData(arg) {
|
|
3
|
+
if (arg === null || arg === undefined)
|
|
4
|
+
return undefined;
|
|
5
|
+
const t = typeof arg;
|
|
6
|
+
if (t === "string" || t === "number" || t === "boolean")
|
|
7
|
+
return arg;
|
|
8
|
+
if (t !== "object")
|
|
9
|
+
return undefined;
|
|
10
|
+
const obj = arg;
|
|
11
|
+
if ("nativeEvent" in obj || "preventDefault" in obj || (typeof Event !== "undefined" && arg instanceof Event)) {
|
|
12
|
+
return undefined; // React SyntheticEvent / DOM event — not serializable
|
|
13
|
+
}
|
|
14
|
+
return arg;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Bind a node's spec actions to component callback props via the registry's
|
|
18
|
+
* actionProps map. Unmapped `click` actions are returned for generic wrapping;
|
|
19
|
+
* other unmapped keys are dropped with a dev warning.
|
|
20
|
+
*/
|
|
21
|
+
function bindActionProps(node, actionProps, componentProps, dispatch) {
|
|
22
|
+
const result = { props: componentProps };
|
|
23
|
+
if (!node.actions)
|
|
24
|
+
return result;
|
|
25
|
+
let next = null;
|
|
26
|
+
for (const [key, descriptor] of Object.entries(node.actions)) {
|
|
27
|
+
const propName = actionProps === null || actionProps === void 0 ? void 0 : actionProps[key];
|
|
28
|
+
if (propName) {
|
|
29
|
+
next = next !== null && next !== void 0 ? next : { ...componentProps };
|
|
30
|
+
next[propName] = (...args) => {
|
|
31
|
+
const data = extractActionData(args[0]);
|
|
32
|
+
dispatch(descriptor, {
|
|
33
|
+
component: node.component,
|
|
34
|
+
...(node.id ? { nodeId: node.id } : {}),
|
|
35
|
+
...(data !== undefined ? { data } : {}),
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
else if (key === "click") {
|
|
40
|
+
result.unboundClick = descriptor;
|
|
41
|
+
}
|
|
42
|
+
else if (process.env.NODE_ENV !== "production") {
|
|
43
|
+
console.warn(`[GenerativeView]: action "${key}" is not supported by "${node.component}" — ignored`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (next)
|
|
47
|
+
result.props = next;
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { bindActionProps, extractActionData };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { GenerativeView, type GenerativeViewProps } from "./GenerativeView";
|
|
2
|
+
export { createRegistry, defaultRegistry, CardShell, type GenerativeRegistry, type RegistryEntry, type CreateRegistryOptions, } from "./registry";
|
|
3
|
+
export { DEFAULT_ICONS, DEFAULT_STATUS_COLORS, defaultResolvers, iconPropsResolver, tableColumnsResolver, applyResolvers, resolveIcon, type IconMap, type PropResolver, type ResolverContext, } from "./resolvers";
|
|
4
|
+
export type { UINode, UISpec, ActionDescriptor, JSONValue } from "./types";
|
|
5
|
+
export { validate, type ValidateOptions, type ValidateResult, type ValidationIssue } from "./validate";
|
|
6
|
+
export { parsePartialJSON, parseStreamingSpec, isJSONComplete, SKELETON_NODE, SKELETON_PRESETS, type StreamingSpecResult, type ParseStreamingSpecOptions, } from "./streaming";
|
|
7
|
+
export { useGenerativeStream, type UseGenerativeStreamOptions, type UseGenerativeStreamReturn } from "./useGenerativeStream";
|
|
8
|
+
export { bindActionProps, extractActionData, type ActionContext, type ActionHandler, type BoundActions } from "./actions";
|
|
9
|
+
export { buildToolDefinition, GENERATIVE_TOOL, type GenerativeToolDefinition } from "./tools";
|
|
10
|
+
export { GENERATIVE_SCHEMA } from "./schema.generated";
|
|
11
|
+
export type { GenerativeSchemaDoc, ComponentSchema, SchemaProp, SchemaPropKind } from "./schemaTypes";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { GenerativeView } from './GenerativeView.js';
|
|
2
|
+
export { CardShell, createRegistry, defaultRegistry } from './registry.js';
|
|
3
|
+
export { DEFAULT_ICONS, DEFAULT_STATUS_COLORS, applyResolvers, defaultResolvers, iconPropsResolver, resolveIcon, tableColumnsResolver } from './resolvers.js';
|
|
4
|
+
export { validate } from './validate.js';
|
|
5
|
+
export { SKELETON_NODE, SKELETON_PRESETS, isJSONComplete, parsePartialJSON, parseStreamingSpec } from './streaming.js';
|
|
6
|
+
export { useGenerativeStream } from './useGenerativeStream.js';
|
|
7
|
+
export { bindActionProps, extractActionData } from './actions.js';
|
|
8
|
+
export { GENERATIVE_TOOL, buildToolDefinition } from './tools.js';
|
|
9
|
+
export { GENERATIVE_SCHEMA } from './schema.generated.js';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { IconMap, PropResolver } from "./resolvers";
|
|
3
|
+
export interface RegistryEntry {
|
|
4
|
+
component: React.ComponentType<Record<string, unknown>>;
|
|
5
|
+
/** Containers render `children` recursively; leaves ignore them. @default "leaf" */
|
|
6
|
+
kind?: "leaf" | "container";
|
|
7
|
+
/** Panel-less components get an automatic Card shell when not already inside one. */
|
|
8
|
+
needsShell?: boolean;
|
|
9
|
+
/** Containers that ARE a shell (Card) suppress needsShell in their subtree. */
|
|
10
|
+
providesShell?: boolean;
|
|
11
|
+
/** Escape hatch: fully custom element creation (charts, Table, Card). */
|
|
12
|
+
render?: (props: Record<string, unknown>, children?: React.ReactNode) => React.ReactNode;
|
|
13
|
+
/** Map spec action keys to component callback props, e.g. { click: "onClick" }. */
|
|
14
|
+
actionProps?: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
export interface GenerativeRegistry {
|
|
17
|
+
components: Record<string, RegistryEntry>;
|
|
18
|
+
icons: IconMap;
|
|
19
|
+
resolvers: PropResolver[];
|
|
20
|
+
}
|
|
21
|
+
export interface CreateRegistryOptions {
|
|
22
|
+
/** Merged OVER the default component set; pass `{ Name: null }` to remove one. */
|
|
23
|
+
components?: Record<string, RegistryEntry | null>;
|
|
24
|
+
/** Merged over DEFAULT_ICONS. */
|
|
25
|
+
icons?: IconMap;
|
|
26
|
+
/** REPLACES defaultResolvers when provided (compose manually to extend). */
|
|
27
|
+
resolvers?: PropResolver[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Card shell used by the automatic `needsShell` wrap (KPI, charts).
|
|
31
|
+
* Card now carries `title`/`subtitle` natively (slot-props), so this is a thin
|
|
32
|
+
* adapter over those props — no longer a parallel re-implementation of the
|
|
33
|
+
* Card.Header/Title/Body structure.
|
|
34
|
+
*/
|
|
35
|
+
export declare function CardShell({ title, subtitle, className, children, }: {
|
|
36
|
+
title?: React.ReactNode;
|
|
37
|
+
subtitle?: React.ReactNode;
|
|
38
|
+
className?: string;
|
|
39
|
+
children?: React.ReactNode;
|
|
40
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
41
|
+
export declare function createRegistry(options?: CreateRegistryOptions): GenerativeRegistry;
|
|
42
|
+
/** The default generative-safe registry (curation expands in P5). */
|
|
43
|
+
export declare const defaultRegistry: GenerativeRegistry;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Alert } from '../core/Alert/Alert.js';
|
|
3
|
+
import { Avatar } from '../core/Avatar/Avatar.js';
|
|
4
|
+
import { Badge } from '../core/Badge/Badge.js';
|
|
5
|
+
import { Button } from '../core/Button/Button.js';
|
|
6
|
+
import 'react';
|
|
7
|
+
import { Card } from '../core/Card/Card.js';
|
|
8
|
+
import { Progress } from '../core/Progress/Progress.js';
|
|
9
|
+
import { Separator } from '../core/Separator/Separator.js';
|
|
10
|
+
import { Grid } from '../layout/Grid/Grid.js';
|
|
11
|
+
import { Stack } from '../layout/Stack/Stack.js';
|
|
12
|
+
import { Section } from '../layout/Section/Section.js';
|
|
13
|
+
import { cn } from '../../utils/cn.js';
|
|
14
|
+
import { defaultResolvers, DEFAULT_ICONS } from './resolvers.js';
|
|
15
|
+
import { DonutChart } from '../charts/DonutChart/DonutChart.js';
|
|
16
|
+
import { Feed } from '../data-display/Feed/Feed.js';
|
|
17
|
+
import { DescriptionList } from '../data-display/DescriptionList/DescriptionList.js';
|
|
18
|
+
import { Timeline } from '../data-display/Timeline/Timeline.js';
|
|
19
|
+
import { Table } from '../data-display/Table/index.js';
|
|
20
|
+
import { KPI } from '../data-display/KPI/KPI.js';
|
|
21
|
+
import { Metric } from '../data-display/Metric/Metric.js';
|
|
22
|
+
import { ChartContainer } from '../charts/ChartContainer.js';
|
|
23
|
+
import { ComboChart } from '../charts/ComboChart/ComboChart.js';
|
|
24
|
+
import { StackedBarChart } from '../charts/StackedBarChart/StackedBarChart.js';
|
|
25
|
+
import { LineChart } from '../charts/LineChart/LineChart.js';
|
|
26
|
+
import { BarChart } from '../charts/BarChart/BarChart.js';
|
|
27
|
+
import { AreaChart } from '../charts/AreaChart/AreaChart.js';
|
|
28
|
+
|
|
29
|
+
/** One source of truth for chart height so side-by-side charts always match. */
|
|
30
|
+
const CHART_HEIGHT = 200;
|
|
31
|
+
/** Erase a component's specific prop types at the untyped-JSON spec boundary. */
|
|
32
|
+
const loose = (component) => component;
|
|
33
|
+
const LooseTable = loose(Table);
|
|
34
|
+
const LooseDonutChart = loose(DonutChart);
|
|
35
|
+
const LooseCard = loose(Card);
|
|
36
|
+
/**
|
|
37
|
+
* Card shell used by the automatic `needsShell` wrap (KPI, charts).
|
|
38
|
+
* Card now carries `title`/`subtitle` natively (slot-props), so this is a thin
|
|
39
|
+
* adapter over those props — no longer a parallel re-implementation of the
|
|
40
|
+
* Card.Header/Title/Body structure.
|
|
41
|
+
*/
|
|
42
|
+
function CardShell({ title, subtitle, className, children, }) {
|
|
43
|
+
return (jsx(Card, { title: title, subtitle: subtitle, className: cn("h-full", className), children: children }));
|
|
44
|
+
}
|
|
45
|
+
const chartEntry = (Chart) => ({
|
|
46
|
+
component: Chart,
|
|
47
|
+
needsShell: true,
|
|
48
|
+
render: (props) => (jsx(ChartContainer, { data: props.data, config: props.config, height: typeof props.height === "number" ? props.height : CHART_HEIGHT, className: "w-full", children: jsx(Chart, { ...props }) })),
|
|
49
|
+
});
|
|
50
|
+
const DEFAULT_COMPONENTS = {
|
|
51
|
+
// Layout containers — recursive children
|
|
52
|
+
Grid: { component: Grid, kind: "container" },
|
|
53
|
+
Stack: { component: Stack, kind: "container" },
|
|
54
|
+
Section: { component: Section, kind: "container" },
|
|
55
|
+
Card: {
|
|
56
|
+
component: Card,
|
|
57
|
+
kind: "container",
|
|
58
|
+
providesShell: true,
|
|
59
|
+
// Native title/subtitle slot-props + recursive children. h-full so a Card
|
|
60
|
+
// in a Grid cell fills the row (matching the auto needsShell wrap).
|
|
61
|
+
render: (props, children) => (jsx(LooseCard, { ...props, className: cn("h-full", props.className), children: children })),
|
|
62
|
+
},
|
|
63
|
+
// Self-contained leaves
|
|
64
|
+
Button: { component: Button, actionProps: { click: "onClick" } },
|
|
65
|
+
Metric: { component: Metric },
|
|
66
|
+
Alert: { component: Alert },
|
|
67
|
+
Badge: { component: Badge },
|
|
68
|
+
Avatar: { component: Avatar },
|
|
69
|
+
Progress: { component: Progress },
|
|
70
|
+
Separator: { component: Separator },
|
|
71
|
+
// Panel-less leaves — auto Card shell (lifted from the PoC's NEEDS_SHELL)
|
|
72
|
+
KPI: { component: KPI, needsShell: true },
|
|
73
|
+
// Collections (dual-API data path — items/data arrays are serializable)
|
|
74
|
+
Table: {
|
|
75
|
+
component: Table,
|
|
76
|
+
needsShell: true,
|
|
77
|
+
actionProps: { rowClick: "onRowClick" },
|
|
78
|
+
// Inside a padded Card: flush column edges + drop the last row's border.
|
|
79
|
+
render: (props) => (jsx(LooseTable, { ...props, padding: "flush", className: cn("[&_tbody_tr:last-child_td]:border-b-0", props.className) })),
|
|
80
|
+
},
|
|
81
|
+
Timeline: { component: Timeline },
|
|
82
|
+
DescriptionList: { component: DescriptionList },
|
|
83
|
+
Feed: { component: Feed },
|
|
84
|
+
// Charts — ChartContainer wrap + auto shell
|
|
85
|
+
AreaChart: chartEntry(AreaChart),
|
|
86
|
+
BarChart: chartEntry(BarChart),
|
|
87
|
+
LineChart: chartEntry(LineChart),
|
|
88
|
+
StackedBarChart: chartEntry(StackedBarChart),
|
|
89
|
+
ComboChart: chartEntry(ComboChart),
|
|
90
|
+
DonutChart: {
|
|
91
|
+
component: DonutChart,
|
|
92
|
+
needsShell: true,
|
|
93
|
+
render: (props) => (jsx("div", { className: "flex justify-center py-2", children: jsx(LooseDonutChart, { ...props }) })),
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
function createRegistry(options = {}) {
|
|
97
|
+
var _a, _b;
|
|
98
|
+
const components = { ...DEFAULT_COMPONENTS };
|
|
99
|
+
for (const [name, entry] of Object.entries((_a = options.components) !== null && _a !== void 0 ? _a : {})) {
|
|
100
|
+
if (entry === null)
|
|
101
|
+
delete components[name];
|
|
102
|
+
else
|
|
103
|
+
components[name] = entry;
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
components,
|
|
107
|
+
icons: { ...DEFAULT_ICONS, ...options.icons },
|
|
108
|
+
resolvers: (_b = options.resolvers) !== null && _b !== void 0 ? _b : defaultResolvers,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/** The default generative-safe registry (curation expands in P5). */
|
|
112
|
+
const defaultRegistry = createRegistry();
|
|
113
|
+
|
|
114
|
+
export { CardShell, createRegistry, defaultRegistry };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { UINode } from "./types";
|
|
3
|
+
/** Icon NAME → component map. The spec carries the NAME; we own the element. */
|
|
4
|
+
export type IconMap = Record<string, React.ComponentType<{
|
|
5
|
+
className?: string;
|
|
6
|
+
}>>;
|
|
7
|
+
/** Closed default icon set (P2's schema generation emits these as the enum). */
|
|
8
|
+
export declare const DEFAULT_ICONS: IconMap;
|
|
9
|
+
export interface ResolverContext {
|
|
10
|
+
icons: IconMap;
|
|
11
|
+
node: UINode;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A resolver takes the (partially hydrated) props and returns the next props.
|
|
15
|
+
* Return the SAME object when nothing matched (cheap identity bail).
|
|
16
|
+
*/
|
|
17
|
+
export type PropResolver = (props: Record<string, unknown>, ctx: ResolverContext) => Record<string, unknown>;
|
|
18
|
+
/** Resolve an icon NAME to an element (undefined when unknown — never throws). */
|
|
19
|
+
export declare function resolveIcon(icons: IconMap, name: unknown, className?: string): React.ReactNode;
|
|
20
|
+
/** icon / iconStart / iconEnd string values → Heroicon elements. */
|
|
21
|
+
export declare const iconPropsResolver: PropResolver;
|
|
22
|
+
/**
|
|
23
|
+
* Default status → Badge color map for `cellType: "badge"` columns. A column
|
|
24
|
+
* may override/extend it with a serializable `colors` map of its own.
|
|
25
|
+
*/
|
|
26
|
+
export declare const DEFAULT_STATUS_COLORS: Record<string, string>;
|
|
27
|
+
/**
|
|
28
|
+
* Hydrate serializable Table column hints into real cell renderers.
|
|
29
|
+
* `{ cellType: "badge", colors? }` → a `cell` function rendering a soft Badge.
|
|
30
|
+
* Functions can't be serialized — the spec declares intent, we supply the fn.
|
|
31
|
+
*/
|
|
32
|
+
export declare const tableColumnsResolver: PropResolver;
|
|
33
|
+
export declare const defaultResolvers: PropResolver[];
|
|
34
|
+
/** Run the resolver chain over a node's props. */
|
|
35
|
+
export declare function applyResolvers(props: Record<string, unknown>, resolvers: PropResolver[], ctx: ResolverContext): Record<string, unknown>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
import { ChatBubbleLeftRightIcon, PencilSquareIcon, RocketLaunchIcon, UserPlusIcon, BriefcaseIcon, ExclamationTriangleIcon, CheckCircleIcon, GlobeAltIcon, BoltIcon, ChartBarIcon, ShoppingCartIcon, ArrowTrendingUpIcon, UsersIcon, CurrencyDollarIcon } from '@heroicons/react/24/outline';
|
|
4
|
+
import { Badge } from '../core/Badge/Badge.js';
|
|
5
|
+
|
|
6
|
+
/** Closed default icon set (P2's schema generation emits these as the enum). */
|
|
7
|
+
const DEFAULT_ICONS = {
|
|
8
|
+
CurrencyDollar: CurrencyDollarIcon,
|
|
9
|
+
Users: UsersIcon,
|
|
10
|
+
ArrowTrendingUp: ArrowTrendingUpIcon,
|
|
11
|
+
ShoppingCart: ShoppingCartIcon,
|
|
12
|
+
ChartBar: ChartBarIcon,
|
|
13
|
+
Bolt: BoltIcon,
|
|
14
|
+
Globe: GlobeAltIcon,
|
|
15
|
+
CheckCircle: CheckCircleIcon,
|
|
16
|
+
ExclamationTriangle: ExclamationTriangleIcon,
|
|
17
|
+
Briefcase: BriefcaseIcon,
|
|
18
|
+
UserPlus: UserPlusIcon,
|
|
19
|
+
RocketLaunch: RocketLaunchIcon,
|
|
20
|
+
PencilSquare: PencilSquareIcon,
|
|
21
|
+
ChatBubbleLeftRight: ChatBubbleLeftRightIcon,
|
|
22
|
+
};
|
|
23
|
+
/** Resolve an icon NAME to an element (undefined when unknown — never throws). */
|
|
24
|
+
function resolveIcon(icons, name, className = "size-5") {
|
|
25
|
+
if (typeof name !== "string" || !icons[name])
|
|
26
|
+
return undefined;
|
|
27
|
+
return React__default.createElement(icons[name], { className });
|
|
28
|
+
}
|
|
29
|
+
const ICON_PROPS = ["icon", "iconStart", "iconEnd"];
|
|
30
|
+
/** icon / iconStart / iconEnd string values → Heroicon elements. */
|
|
31
|
+
const iconPropsResolver = (props, { icons }) => {
|
|
32
|
+
let next = null;
|
|
33
|
+
for (const key of ICON_PROPS) {
|
|
34
|
+
const value = props[key];
|
|
35
|
+
if (typeof value === "string") {
|
|
36
|
+
const element = resolveIcon(icons, value);
|
|
37
|
+
next = next !== null && next !== void 0 ? next : { ...props };
|
|
38
|
+
// Unknown name → drop the prop (a string would crash icon slots).
|
|
39
|
+
next[key] = element;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return next !== null && next !== void 0 ? next : props;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Default status → Badge color map for `cellType: "badge"` columns. A column
|
|
46
|
+
* may override/extend it with a serializable `colors` map of its own.
|
|
47
|
+
*/
|
|
48
|
+
const DEFAULT_STATUS_COLORS = {
|
|
49
|
+
Paid: "success",
|
|
50
|
+
Shipped: "primary",
|
|
51
|
+
Pending: "warning",
|
|
52
|
+
Refunded: "danger",
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Hydrate serializable Table column hints into real cell renderers.
|
|
56
|
+
* `{ cellType: "badge", colors? }` → a `cell` function rendering a soft Badge.
|
|
57
|
+
* Functions can't be serialized — the spec declares intent, we supply the fn.
|
|
58
|
+
*/
|
|
59
|
+
const tableColumnsResolver = (props) => {
|
|
60
|
+
const columns = props.columns;
|
|
61
|
+
if (!Array.isArray(columns))
|
|
62
|
+
return props;
|
|
63
|
+
let changed = false;
|
|
64
|
+
const next = columns.map((col) => {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
if (!col || typeof col !== "object" || col.cellType !== "badge") {
|
|
67
|
+
return col;
|
|
68
|
+
}
|
|
69
|
+
changed = true;
|
|
70
|
+
const { cellType: _cellType, colors, ...rest } = col;
|
|
71
|
+
const map = {
|
|
72
|
+
...DEFAULT_STATUS_COLORS,
|
|
73
|
+
...((_a = colors) !== null && _a !== void 0 ? _a : {}),
|
|
74
|
+
};
|
|
75
|
+
const accessor = (_b = col.accessor) !== null && _b !== void 0 ? _b : "";
|
|
76
|
+
return {
|
|
77
|
+
...rest,
|
|
78
|
+
cell: (row) => {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
const value = String((_a = row[accessor]) !== null && _a !== void 0 ? _a : "");
|
|
81
|
+
return (jsx(Badge, { color: ((_b = map[value]) !== null && _b !== void 0 ? _b : "neutral"), variant: "soft", children: value }));
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
return changed ? { ...props, columns: next } : props;
|
|
86
|
+
};
|
|
87
|
+
const defaultResolvers = [iconPropsResolver, tableColumnsResolver];
|
|
88
|
+
/** Run the resolver chain over a node's props. */
|
|
89
|
+
function applyResolvers(props, resolvers, ctx) {
|
|
90
|
+
return resolvers.reduce((acc, resolve) => resolve(acc, ctx), { ...props });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { DEFAULT_ICONS, DEFAULT_STATUS_COLORS, applyResolvers, defaultResolvers, iconPropsResolver, resolveIcon, tableColumnsResolver };
|