@tc96/cli 0.0.0-stage → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +213 -2
- package/cli.js +1450 -0
- package/package.json +35 -4
- package/registry/agenda-1.json +1297 -0
- package/registry/aggregate.json +4 -0
- package/registry/ai-chat-1.json +91 -0
- package/registry/app-shell-1.json +81 -0
- package/registry/app-shell-2.json +89 -0
- package/registry/app-shell-3.json +109 -0
- package/registry/app-shell-4.json +104 -0
- package/registry/card-1.json +104 -0
- package/registry/card-2.json +97 -0
- package/registry/card-3.json +104 -0
- package/registry/card-4.json +98 -0
- package/registry/card-5.json +85 -0
- package/registry/card-6.json +98 -0
- package/registry/card-7.json +104 -0
- package/registry/card-8.json +106 -0
- package/registry/card-9.json +92 -0
- package/registry/charts.json +30 -0
- package/registry/chat-assistant.json +110 -0
- package/registry/chats-panel.json +97 -0
- package/registry/checklist.json +321 -0
- package/registry/collection.json +1104 -0
- package/registry/crm-1.json +1317 -0
- package/registry/crm-2.json +1400 -0
- package/registry/dashboard-1.json +160 -0
- package/registry/dashboard-2.json +153 -0
- package/registry/dashboard-3.json +154 -0
- package/registry/dashboard-4.json +168 -0
- package/registry/dashboard-5.json +167 -0
- package/registry/dashboard-6.json +143 -0
- package/registry/dashboard-7.json +188 -0
- package/registry/documents-1.json +1322 -0
- package/registry/editable.json +36 -0
- package/registry/empty-state-1.json +40 -0
- package/registry/empty-state-2.json +39 -0
- package/registry/empty-state-3.json +61 -0
- package/registry/empty-state-4.json +39 -0
- package/registry/empty-state-5.json +47 -0
- package/registry/empty-state-6.json +40 -0
- package/registry/finance-1.json +845 -0
- package/registry/finance-2.json +973 -0
- package/registry/finance-3.json +1436 -0
- package/registry/flow-1.json +460 -0
- package/registry/flow-2.json +503 -0
- package/registry/flow-3.json +198 -0
- package/registry/flow-4.json +75 -0
- package/registry/flow-canvas.json +198 -0
- package/registry/flow-inspector.json +151 -0
- package/registry/flow-step-library.json +112 -0
- package/registry/forgot-password-1.json +73 -0
- package/registry/forgot-password-2.json +73 -0
- package/registry/inbox-1.json +1184 -0
- package/registry/inventory-1.json +828 -0
- package/registry/inventory-2.json +956 -0
- package/registry/legal-1.json +1345 -0
- package/registry/legal-2.json +1279 -0
- package/registry/legal-3.json +1273 -0
- package/registry/legal-4.json +1273 -0
- package/registry/legal-5.json +1393 -0
- package/registry/legal-6.json +1309 -0
- package/registry/legal-7.json +1315 -0
- package/registry/legal-8.json +1358 -0
- package/registry/legal-9.json +1381 -0
- package/registry/list-1.json +129 -0
- package/registry/list-2.json +117 -0
- package/registry/list-3.json +129 -0
- package/registry/list-4.json +105 -0
- package/registry/list-5.json +98 -0
- package/registry/list-6.json +92 -0
- package/registry/list.json +52 -0
- package/registry/login-1.json +89 -0
- package/registry/login-10.json +88 -0
- package/registry/login-2.json +81 -0
- package/registry/login-3.json +90 -0
- package/registry/login-4.json +81 -0
- package/registry/login-5.json +82 -0
- package/registry/login-6.json +88 -0
- package/registry/login-7.json +83 -0
- package/registry/login-8.json +81 -0
- package/registry/login-9.json +88 -0
- package/registry/magic-link-6.json +79 -0
- package/registry/marketing-1.json +833 -0
- package/registry/marketing-2.json +961 -0
- package/registry/navbar-1.json +66 -0
- package/registry/navbar-10.json +50 -0
- package/registry/navbar-11.json +48 -0
- package/registry/navbar-12.json +48 -0
- package/registry/navbar-2.json +48 -0
- package/registry/navbar-3.json +50 -0
- package/registry/navbar-4.json +39 -0
- package/registry/navbar-5.json +50 -0
- package/registry/navbar-6.json +48 -0
- package/registry/navbar-7.json +72 -0
- package/registry/navbar-8.json +50 -0
- package/registry/navbar-9.json +54 -0
- package/registry/onboarding-1.json +114 -0
- package/registry/onboarding-2.json +78 -0
- package/registry/onboarding-3.json +71 -0
- package/registry/otp-1.json +73 -0
- package/registry/projects-1.json +865 -0
- package/registry/projects-2.json +993 -0
- package/registry/projects-3.json +1346 -0
- package/registry/properties.json +530 -0
- package/registry/record-dialog.json +88 -0
- package/registry/record-group.json +194 -0
- package/registry/record-preview.json +70 -0
- package/registry/record-status-list.json +70 -0
- package/registry/reset-password-1.json +92 -0
- package/registry/reset-password-2.json +98 -0
- package/registry/reset-password-6.json +91 -0
- package/registry/revenue-1.json +834 -0
- package/registry/revenue-2.json +968 -0
- package/registry/revenue-3.json +821 -0
- package/registry/revenue-4.json +949 -0
- package/registry/rich-text-editor-1.json +172 -0
- package/registry/rich-text-editor-2.json +158 -0
- package/registry/rich-text-editor-3.json +198 -0
- package/registry/rich-text-editor-4.json +200 -0
- package/registry/rich-text-editor-5.json +237 -0
- package/registry/rich-text-editor.json +113 -0
- package/registry/settings-account-1.json +119 -0
- package/registry/settings-account-2.json +118 -0
- package/registry/settings-catalog-1.json +128 -0
- package/registry/settings-catalog-10.json +129 -0
- package/registry/settings-catalog-2.json +116 -0
- package/registry/settings-catalog-3.json +118 -0
- package/registry/settings-catalog-4.json +227 -0
- package/registry/settings-catalog-5.json +129 -0
- package/registry/settings-catalog-6.json +130 -0
- package/registry/settings-catalog-7.json +130 -0
- package/registry/settings-catalog-8.json +183 -0
- package/registry/settings-catalog-9.json +159 -0
- package/registry/settings-integration-1.json +125 -0
- package/registry/settings-integration-2.json +122 -0
- package/registry/settings-integration-3.json +118 -0
- package/registry/settings-integration-4.json +129 -0
- package/registry/settings-integration-5.json +122 -0
- package/registry/settings-integration-6.json +92 -0
- package/registry/settings-integration-7.json +122 -0
- package/registry/settings-integration-8.json +593 -0
- package/registry/settings-notification-channel-1.json +112 -0
- package/registry/settings-preference-1.json +123 -0
- package/registry/settings-preference-2.json +123 -0
- package/registry/settings-preference-3.json +116 -0
- package/registry/settings-role-permission-1.json +117 -0
- package/registry/settings-security-1.json +117 -0
- package/registry/settings-workspace-1.json +119 -0
- package/registry/settings-workspace-2.json +125 -0
- package/registry/settings.json +82 -0
- package/registry/signup-1.json +100 -0
- package/registry/signup-2.json +93 -0
- package/registry/signup-3.json +83 -0
- package/registry/signup-6.json +99 -0
- package/registry/state-surface.json +58 -0
- package/registry/stats-1.json +116 -0
- package/registry/stats-2.json +115 -0
- package/registry/stats-3.json +97 -0
- package/registry/stats-4.json +92 -0
- package/registry/stats-5.json +103 -0
- package/registry/stats-6.json +105 -0
- package/registry/stats-7.json +103 -0
- package/registry/stats.json +64 -0
- package/registry/support-1.json +853 -0
- package/registry/support-2.json +981 -0
- package/registry/support-3.json +762 -0
- package/registry/support-4.json +538 -0
- package/registry/team-1.json +829 -0
- package/registry/team-2.json +957 -0
- package/registry/timeline-1.json +97 -0
- package/registry/timeline-2.json +102 -0
- package/registry/timeline-3.json +68 -0
- package/registry/timeline-4.json +86 -0
- package/registry/ui/accordion.json +15 -0
- package/registry/ui/alert-dialog.json +14 -0
- package/registry/ui/alert.json +50 -0
- package/registry/ui/autocomplete.json +18 -0
- package/registry/ui/avatar.json +14 -0
- package/registry/ui/badge.json +51 -0
- package/registry/ui/breadcrumb.json +15 -0
- package/registry/ui/button.json +25 -0
- package/registry/ui/calendar.json +15 -0
- package/registry/ui/card.json +14 -0
- package/registry/ui/chat.json +115 -0
- package/registry/ui/checkbox-group.json +14 -0
- package/registry/ui/checkbox.json +14 -0
- package/registry/ui/collapsible.json +14 -0
- package/registry/ui/combobox.json +18 -0
- package/registry/ui/command.json +17 -0
- package/registry/ui/composer-clipboard.json +14 -0
- package/registry/ui/composer-document.json +14 -0
- package/registry/ui/composer-editor.json +16 -0
- package/registry/ui/composer-query.json +12 -0
- package/registry/ui/composer.json +17 -0
- package/registry/ui/context-menu.json +23 -0
- package/registry/ui/dialog.json +18 -0
- package/registry/ui/drawer.json +18 -0
- package/registry/ui/empty.json +14 -0
- package/registry/ui/field.json +22 -0
- package/registry/ui/fieldset.json +14 -0
- package/registry/ui/form.json +14 -0
- package/registry/ui/frame.json +12 -0
- package/registry/ui/gauge.json +31 -0
- package/registry/ui/group.json +17 -0
- package/registry/ui/icon-frame.json +31 -0
- package/registry/ui/input-group.json +17 -0
- package/registry/ui/input.json +14 -0
- package/registry/ui/kbd.json +12 -0
- package/registry/ui/label.json +14 -0
- package/registry/ui/menu.json +39 -0
- package/registry/ui/meter.json +14 -0
- package/registry/ui/number-field.json +17 -0
- package/registry/ui/otp-field.json +31 -0
- package/registry/ui/pagination.json +17 -0
- package/registry/ui/popover.json +14 -0
- package/registry/ui/preview-card.json +14 -0
- package/registry/ui/progress.json +14 -0
- package/registry/ui/property-meta.json +16 -0
- package/registry/ui/property-tone.json +12 -0
- package/registry/ui/radio-group.json +14 -0
- package/registry/ui/render-anchor.json +12 -0
- package/registry/ui/scroll-area.json +14 -0
- package/registry/ui/segmented-control.json +14 -0
- package/registry/ui/select.json +16 -0
- package/registry/ui/separator.json +14 -0
- package/registry/ui/sheet.json +18 -0
- package/registry/ui/sidebar.json +25 -0
- package/registry/ui/skeleton.json +24 -0
- package/registry/ui/slider.json +14 -0
- package/registry/ui/spinner.json +14 -0
- package/registry/ui/switch.json +14 -0
- package/registry/ui/table.json +14 -0
- package/registry/ui/tabs.json +16 -0
- package/registry/ui/text.json +31 -0
- package/registry/ui/textarea.json +14 -0
- package/registry/ui/toast.json +89 -0
- package/registry/ui/toggle-group.json +18 -0
- package/registry/ui/toggle.json +15 -0
- package/registry/ui/toolbar.json +14 -0
- package/registry/ui/tooltip.json +14 -0
- package/registry/ui/use-composer-editor.json +17 -0
- package/registry/ui/use-copy-to-clipboard.json +12 -0
- package/registry/ui/use-media-query.json +12 -0
- package/registry/view.json +1104 -0
- package/registry/widgets.json +319 -0
- package/registry/wizard.json +89 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "flow-canvas",
|
|
3
|
+
"type": "registry:block",
|
|
4
|
+
"files": [
|
|
5
|
+
{
|
|
6
|
+
"path": "patterns/flow/canvas/components/flow-canvas-empty.tsx",
|
|
7
|
+
"type": "registry:file",
|
|
8
|
+
"content": "import {\n Empty,\n EmptyDescription,\n EmptyHeader,\n EmptyTitle,\n} from '@tc96/ui/empty'\nimport type { ReactElement } from 'react'\nimport { flowCanvasEmptyClassName } from '../lib/variants'\nimport { useFlowCanvasContext } from '../store/flow-canvas-context'\n\nexport function FlowCanvasEmpty(): ReactElement {\n const { labels } = useFlowCanvasContext('FlowCanvasEmpty')\n return (\n <div className={flowCanvasEmptyClassName} data-slot=\"flow-canvas-empty\">\n <Empty>\n <EmptyHeader>\n <EmptyTitle>{labels.emptyTitle}</EmptyTitle>\n <EmptyDescription>{labels.emptyDescription}</EmptyDescription>\n </EmptyHeader>\n </Empty>\n </div>\n )\n}\n",
|
|
9
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/components/flow-canvas-empty.tsx"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "patterns/flow/canvas/components/flow-control-button.tsx",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"content": "import { Button, type ButtonProps } from '@tc96/ui/button'\nimport { Tooltip, TooltipPopup, TooltipTrigger } from '@tc96/ui/tooltip'\nimport type { ReactElement } from 'react'\n\nexport interface FlowControlButtonProps\n extends Omit<ButtonProps, 'aria-label' | 'render'> {\n label: string\n tooltip?: string\n}\n\nexport function FlowControlButton({\n children,\n label,\n tooltip = label,\n ...props\n}: Readonly<FlowControlButtonProps>): ReactElement {\n return (\n <Tooltip>\n <TooltipTrigger\n render={\n <Button aria-label={label} {...props}>\n {children}\n </Button>\n }\n />\n <TooltipPopup>{tooltip}</TooltipPopup>\n </Tooltip>\n )\n}\n",
|
|
15
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/components/flow-control-button.tsx"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "patterns/flow/canvas/components/flow-edge-controls.tsx",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"content": "import { PlusIcon, XIcon } from '@phosphor-icons/react'\nimport type { ReactElement } from 'react'\nimport type { FlowConnection } from '../core'\nimport { flowEdgeControlsClassName } from '../lib/variants'\nimport { useFlowCanvasContext } from '../store/flow-canvas-context'\nimport { FlowControlButton } from './flow-control-button'\n\nexport function FlowEdgeControls({\n connection,\n}: Readonly<{ connection: FlowConnection }>): ReactElement {\n const { connections, labels, locked, onConnectionsChange, onStepAction } =\n useFlowCanvasContext('FlowEdgeControls')\n return (\n <div className={flowEdgeControlsClassName} data-slot=\"flow-edge-controls\">\n <FlowControlButton\n disabled={locked}\n label={labels.edgeAdd(connection.label)}\n onClick={() =>\n onStepAction?.('add-after', connection.source, connection)\n }\n size=\"icon-xs\"\n variant=\"outline\"\n >\n <PlusIcon aria-hidden=\"true\" />\n </FlowControlButton>\n <FlowControlButton\n disabled={locked}\n label={labels.edgeRemove(connection.label)}\n onClick={() =>\n onConnectionsChange?.(\n connections.filter((item) => item.id !== connection.id),\n )\n }\n size=\"icon-xs\"\n variant=\"outline\"\n >\n <XIcon aria-hidden=\"true\" />\n </FlowControlButton>\n </div>\n )\n}\n",
|
|
21
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/components/flow-edge-controls.tsx"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "patterns/flow/canvas/components/flow-shortcuts-popover.tsx",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"content": "import { KeyboardIcon } from '@phosphor-icons/react'\nimport { Button } from '@tc96/ui/button'\nimport { Kbd, KbdGroup } from '@tc96/ui/kbd'\nimport {\n Popover,\n PopoverPopup,\n PopoverTitle,\n PopoverTrigger,\n} from '@tc96/ui/popover'\nimport type { ReactElement } from 'react'\nimport { defaultFlowShortcutsLabels } from '../lib/labels'\nimport { flowShortcutRowClassName } from '../lib/variants'\nimport type { FlowShortcutsLabels } from '../types'\n\nexport interface FlowShortcutsPopoverProps {\n labels?: Partial<FlowShortcutsLabels>\n}\n\nexport function FlowShortcutsPopover({\n labels: labelsProp,\n}: Readonly<FlowShortcutsPopoverProps>): ReactElement {\n const labels = { ...defaultFlowShortcutsLabels, ...labelsProp }\n const shortcuts: readonly (readonly [string, readonly string[]])[] = [\n [labels.select, ['V']],\n [labels.pan, ['H']],\n [labels.zoomIn, ['+']],\n [labels.zoomOut, ['-']],\n [labels.fit, ['Shift', '1']],\n [labels.actualSize, ['Shift', '0']],\n [labels.remove, ['Backspace']],\n ]\n return (\n <Popover>\n <PopoverTrigger\n render={\n <Button aria-label={labels.trigger} size=\"icon\" variant=\"outline\" />\n }\n >\n <KeyboardIcon aria-hidden=\"true\" />\n </PopoverTrigger>\n <PopoverPopup align=\"end\">\n <PopoverTitle className=\"mb-3\">{labels.title}</PopoverTitle>\n <ul className=\"m-0 flex list-none flex-col gap-2 p-0\">\n {shortcuts.map(([name, keys]) => (\n <li className={flowShortcutRowClassName} key={name}>\n <span>{name}</span>\n <KbdGroup>\n {keys.map((key) => (\n <Kbd key={key}>{key}</Kbd>\n ))}\n </KbdGroup>\n </li>\n ))}\n </ul>\n </PopoverPopup>\n </Popover>\n )\n}\n",
|
|
27
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/components/flow-shortcuts-popover.tsx"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "patterns/flow/canvas/components/flow-status-icon.tsx",
|
|
31
|
+
"type": "registry:file",
|
|
32
|
+
"content": "import { Spinner } from '@tc96/ui/spinner'\nimport type { ReactElement } from 'react'\nimport type { FlowRunStatus } from '../core'\nimport { flowStatusIcons } from '../lib/steps'\n\nexport function FlowStatusIcon({\n status,\n}: Readonly<{ status: FlowRunStatus }>): ReactElement {\n if (status === 'running')\n return <Spinner aria-hidden=\"true\" className=\"size-3.5\" />\n const Icon = flowStatusIcons[status]\n return <Icon aria-hidden=\"true\" className=\"size-3.5 shrink-0\" />\n}\n",
|
|
33
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/components/flow-status-icon.tsx"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "patterns/flow/canvas/components/flow-step-context-menu.tsx",
|
|
37
|
+
"type": "registry:file",
|
|
38
|
+
"content": "import {\n ContextMenu,\n ContextMenuItem,\n ContextMenuPopup,\n ContextMenuTrigger,\n} from '@tc96/ui/context-menu'\nimport type { ComponentProps, ReactElement } from 'react'\nimport type { FlowStep } from '../core'\nimport {\n flowActionIcons,\n isMutatingAction,\n resolveStepKind,\n stepActionsFor,\n} from '../lib/steps'\nimport { useFlowCanvasContext } from '../store/flow-canvas-context'\n\nexport interface FlowStepContextMenuProps extends ComponentProps<'div'> {\n step: FlowStep\n}\n\nexport function FlowStepContextMenu({\n children,\n step,\n ...props\n}: Readonly<FlowStepContextMenuProps>): ReactElement {\n const { labels, locked, onStepAction, stepTypes } = useFlowCanvasContext(\n 'FlowStepContextMenu',\n )\n const kind = resolveStepKind(step, stepTypes)\n return (\n <ContextMenu>\n <ContextMenuTrigger {...props}>{children}</ContextMenuTrigger>\n <ContextMenuPopup>\n {stepActionsFor(kind, 'toolbar').map((action) => {\n const Icon = flowActionIcons[action]\n return (\n <ContextMenuItem\n disabled={locked && isMutatingAction(action)}\n key={action}\n onClick={() => onStepAction?.(action, step.id)}\n variant={action === 'delete' ? 'destructive' : 'default'}\n >\n <Icon aria-hidden=\"true\" />\n {labels.menuActions[action]}\n </ContextMenuItem>\n )\n })}\n </ContextMenuPopup>\n </ContextMenu>\n )\n}\n",
|
|
39
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/components/flow-step-context-menu.tsx"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "patterns/flow/canvas/components/flow-step-edge.tsx",
|
|
43
|
+
"type": "registry:file",
|
|
44
|
+
"content": "import { Badge } from '@tc96/ui/badge'\nimport {\n BaseEdge,\n EdgeLabelRenderer,\n type EdgeProps,\n getSmoothStepPath,\n} from '@xyflow/react'\nimport type { ReactElement } from 'react'\nimport { flowEdgeLabelClassName, flowEdgePathVariants } from '../lib/variants'\nimport { useFlowCanvasContext } from '../store/flow-canvas-context'\nimport type { FlowEdgeType } from '../types'\nimport { FlowEdgeControls } from './flow-edge-controls'\n\nexport function FlowStepEdge({\n data,\n id,\n markerEnd,\n sourcePosition,\n sourceX,\n sourceY,\n targetPosition,\n targetX,\n targetY,\n}: Readonly<EdgeProps<FlowEdgeType>>): ReactElement {\n const { edgeControls } = useFlowCanvasContext('FlowStepEdge')\n const connection = data?.connection\n const [path, labelX, labelY] = getSmoothStepPath({\n borderRadius: 12,\n sourcePosition,\n sourceX,\n sourceY,\n targetPosition,\n targetX,\n targetY,\n })\n const label = connection?.label\n return (\n <>\n <BaseEdge\n className={flowEdgePathVariants({ taken: connection?.taken === true })}\n id={id}\n interactionWidth={20}\n markerEnd={markerEnd}\n path={path}\n />\n {connection && (label || edgeControls) ? (\n <EdgeLabelRenderer>\n <div\n className={flowEdgeLabelClassName}\n data-slot=\"flow-step-edge-label\"\n style={{\n transform: `translate(-50%, -50%) translate(${labelX}px, ${labelY}px)`,\n }}\n >\n {label ? (\n <Badge className=\"max-w-32 truncate\" variant=\"outline\">\n {label}\n </Badge>\n ) : null}\n {edgeControls ? <FlowEdgeControls connection={connection} /> : null}\n </div>\n </EdgeLabelRenderer>\n ) : null}\n </>\n )\n}\n",
|
|
45
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/components/flow-step-edge.tsx"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "patterns/flow/canvas/components/flow-step-icon.tsx",
|
|
49
|
+
"type": "registry:file",
|
|
50
|
+
"content": "import { IconFrame } from '@tc96/ui/icon-frame'\nimport { cn } from '@tc96/utils'\nimport type { ReactElement } from 'react'\nimport type { FlowStep, FlowStepKind } from '../core'\nimport { flowFallbackIcon, flowKindIcons } from '../lib/steps'\nimport { flowStepNodeIconVariants } from '../lib/variants'\nimport { useFlowCanvasContext } from '../store/flow-canvas-context'\n\nexport function FlowStepIcon({\n kind,\n step,\n}: Readonly<{ kind: FlowStepKind; step: FlowStep }>): ReactElement {\n const { icons } = useFlowCanvasContext('FlowStepIcon')\n const Fallback = flowKindIcons[kind] ?? flowFallbackIcon\n return (\n <IconFrame\n className={cn(flowStepNodeIconVariants({ kind }))}\n data-kind={kind}\n shape=\"rounded\"\n variant=\"plain\"\n >\n {icons[step.type] ?? <Fallback />}\n </IconFrame>\n )\n}\n",
|
|
51
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/components/flow-step-icon.tsx"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "patterns/flow/canvas/components/flow-step-menu.tsx",
|
|
55
|
+
"type": "registry:file",
|
|
56
|
+
"content": "import { DotsThreeIcon } from '@phosphor-icons/react'\nimport { Button } from '@tc96/ui/button'\nimport { Menu, MenuItem, MenuPopup, MenuTrigger } from '@tc96/ui/menu'\nimport type { ReactElement } from 'react'\nimport type { FlowStep } from '../core'\nimport {\n flowActionIcons,\n isMutatingAction,\n resolveStepKind,\n stepActionsFor,\n} from '../lib/steps'\nimport { useFlowCanvasContext } from '../store/flow-canvas-context'\n\nexport function FlowStepMenu({\n step,\n}: Readonly<{ step: FlowStep }>): ReactElement {\n const { labels, locked, onStepAction, stepTypes } =\n useFlowCanvasContext('FlowStepMenu')\n const kind = resolveStepKind(step, stepTypes)\n return (\n <Menu>\n <MenuTrigger\n render={\n <Button\n aria-label={labels.stepMenu(step.name)}\n className=\"nodrag nopan\"\n size=\"icon-xs\"\n variant=\"ghost\"\n />\n }\n >\n <DotsThreeIcon aria-hidden=\"true\" />\n </MenuTrigger>\n <MenuPopup align=\"end\">\n {stepActionsFor(kind, 'menu').map((action) => {\n const Icon = flowActionIcons[action]\n return (\n <MenuItem\n disabled={locked && isMutatingAction(action)}\n key={action}\n onClick={() => onStepAction?.(action, step.id)}\n variant={action === 'delete' ? 'destructive' : 'default'}\n >\n <Icon aria-hidden=\"true\" />\n {labels.menuActions[action]}\n </MenuItem>\n )\n })}\n </MenuPopup>\n </Menu>\n )\n}\n",
|
|
57
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/components/flow-step-menu.tsx"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"path": "patterns/flow/canvas/components/flow-step-node.tsx",
|
|
61
|
+
"type": "registry:file",
|
|
62
|
+
"content": "import { PlusIcon } from '@phosphor-icons/react'\nimport { Avatar, AvatarFallback, AvatarImage } from '@tc96/ui/avatar'\nimport { Badge, type BadgeProps } from '@tc96/ui/badge'\nimport { Card } from '@tc96/ui/card'\nimport { cn } from '@tc96/utils'\nimport { Handle, type NodeProps } from '@xyflow/react'\nimport { memo, type ReactElement } from 'react'\nimport type { FlowRunStatus } from '../core'\nimport { formatStepDuration, resolveStepKind } from '../lib/steps'\nimport { handlePositions } from '../lib/to-react-flow'\nimport {\n flowHandleClassName,\n flowNodeAddLeafClassName,\n flowStatusTextVariants,\n flowStepNodeDescriptionClassName,\n flowStepNodeFooterClassName,\n flowStepNodeHeaderClassName,\n flowStepNodeTextClassName,\n flowStepNodeTitleClassName,\n flowStepNodeVariants,\n} from '../lib/variants'\nimport { useFlowCanvasContext } from '../store/flow-canvas-context'\nimport type { FlowNodeType } from '../types'\nimport { FlowControlButton } from './flow-control-button'\nimport { FlowStatusIcon } from './flow-status-icon'\nimport { FlowStepContextMenu } from './flow-step-context-menu'\nimport { FlowStepIcon } from './flow-step-icon'\nimport { FlowStepMenu } from './flow-step-menu'\nimport { FlowStepToolbar } from './flow-step-toolbar'\n\nconst statusBadgeVariants: Record<FlowRunStatus, BadgeProps['variant']> = {\n failed: 'destructive',\n idle: 'outline',\n 'not-run': 'outline',\n running: 'outline',\n skipped: 'secondary',\n success: 'outline',\n}\n\nfunction initials(name: string): string {\n return name\n .split(/\\s+/)\n .slice(0, 2)\n .map((part) => part.charAt(0).toUpperCase())\n .join('')\n}\n\nfunction FlowStepNodeView({\n data,\n selected,\n}: Readonly<NodeProps<FlowNodeType>>): ReactElement {\n const { step, leaf } = data\n const { direction, labels, locked, onStepAction, stepMenu, stepTypes } =\n useFlowCanvasContext('FlowStepNode')\n const kind = resolveStepKind(step, stepTypes)\n const status: FlowRunStatus = step.run?.status ?? 'not-run'\n const positions = handlePositions(direction)\n const vertical = direction === 'vertical'\n const metrics = step.run?.metrics?.join(' · ')\n const duration =\n step.run?.durationMs === undefined\n ? undefined\n : formatStepDuration(step.run.durationMs)\n const showFooter = vertical\n ? Boolean(step.run)\n : Boolean(step.owner) || duration !== undefined\n\n return (\n <>\n <FlowStepToolbar step={step} visible={selected} />\n <FlowStepContextMenu\n className=\"w-64\"\n data-kind={kind}\n data-slot=\"flow-step-node\"\n data-status={status}\n step={step}\n >\n <Card className={cn(flowStepNodeVariants({ selected }))}>\n <div className={flowStepNodeHeaderClassName}>\n <FlowStepIcon aria-hidden=\"true\" kind={kind} step={step} />\n <div className={flowStepNodeTextClassName}>\n <span className={flowStepNodeTitleClassName}>{step.name}</span>\n {step.description ? (\n <span className={flowStepNodeDescriptionClassName}>\n {step.description}\n </span>\n ) : null}\n </div>\n {stepMenu ? (\n <FlowStepMenu step={step} />\n ) : (\n <Badge variant={statusBadgeVariants[status]}>\n {labels.statuses[status]}\n </Badge>\n )}\n </div>\n {showFooter ? (\n <div className={flowStepNodeFooterClassName}>\n {vertical ? (\n <>\n <span className={flowStatusTextVariants({ status })}>\n <FlowStatusIcon aria-hidden=\"true\" status={status} />\n <span className=\"truncate\">\n {metrics ?? labels.statuses[status]}\n </span>\n </span>\n <Badge\n className=\"ms-auto\"\n variant={statusBadgeVariants[status]}\n >\n {labels.statuses[status]}\n </Badge>\n </>\n ) : (\n <>\n {step.owner ? (\n <Avatar className=\"[--avatar-size:--spacing(4)] text-[0.625rem]\">\n {step.owner.avatarUrl ? (\n <AvatarImage alt=\"\" src={step.owner.avatarUrl} />\n ) : null}\n <AvatarFallback className=\"text-foreground\">\n {initials(step.owner.name)}\n </AvatarFallback>\n </Avatar>\n ) : null}\n {duration ? (\n <span className=\"ms-auto tabular-nums\">{duration}</span>\n ) : null}\n </>\n )}\n </div>\n ) : null}\n </Card>\n </FlowStepContextMenu>\n {kind === 'trigger' ? null : (\n <Handle\n role=\"button\"\n aria-label={labels.targetHandle(step.name)}\n className={flowHandleClassName}\n position={positions.target}\n type=\"target\"\n />\n )}\n <Handle\n role=\"button\"\n aria-label={labels.sourceHandle(step.name)}\n className={flowHandleClassName}\n position={positions.source}\n type=\"source\"\n />\n {vertical && leaf ? (\n <div className={flowNodeAddLeafClassName}>\n <FlowControlButton\n disabled={locked}\n label={labels.addAfterLeaf(step.name)}\n onClick={() => onStepAction?.('add-after', step.id)}\n size=\"icon-xs\"\n tooltip={labels.menuActions['add-after']}\n variant=\"outline\"\n >\n <PlusIcon aria-hidden=\"true\" />\n </FlowControlButton>\n </div>\n ) : null}\n </>\n )\n}\n\nexport const FlowStepNode = memo(FlowStepNodeView)\n",
|
|
63
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/components/flow-step-node.tsx"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "patterns/flow/canvas/components/flow-step-toolbar.tsx",
|
|
67
|
+
"type": "registry:file",
|
|
68
|
+
"content": "import { Group } from '@tc96/ui/group'\nimport { NodeToolbar, Position } from '@xyflow/react'\nimport type { ReactElement } from 'react'\nimport type { FlowStep } from '../core'\nimport {\n flowActionIcons,\n isMutatingAction,\n resolveStepKind,\n stepActionsFor,\n} from '../lib/steps'\nimport { useFlowCanvasContext } from '../store/flow-canvas-context'\nimport { FlowControlButton } from './flow-control-button'\n\nexport function FlowStepToolbar({\n step,\n visible,\n}: Readonly<{ step: FlowStep; visible: boolean }>): ReactElement {\n const { labels, locked, onStepAction, stepTypes } =\n useFlowCanvasContext('FlowStepToolbar')\n const kind = resolveStepKind(step, stepTypes)\n return (\n <NodeToolbar isVisible={visible} offset={12} position={Position.Top}>\n <Group\n aria-label={labels.stepToolbar(step.name)}\n className=\"nodrag nopan\"\n data-slot=\"flow-step-toolbar\"\n >\n {stepActionsFor(kind, 'toolbar').map((action) => {\n const Icon = flowActionIcons[action]\n return (\n <FlowControlButton\n disabled={locked && isMutatingAction(action)}\n key={action}\n label={labels.actions[action](step.name)}\n onClick={() => onStepAction?.(action, step.id)}\n size=\"icon-sm\"\n tooltip={labels.menuActions[action]}\n variant={action === 'delete' ? 'destructive-outline' : 'outline'}\n >\n <Icon aria-hidden=\"true\" />\n </FlowControlButton>\n )\n })}\n </Group>\n </NodeToolbar>\n )\n}\n",
|
|
69
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/components/flow-step-toolbar.tsx"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "patterns/flow/canvas/composition/flow-canvas-controls/flow-canvas-controls.tsx",
|
|
73
|
+
"type": "registry:file",
|
|
74
|
+
"content": "'use client'\n\nimport {\n CursorIcon,\n HandIcon,\n MinusIcon,\n PlusIcon,\n} from '@phosphor-icons/react'\nimport { Button } from '@tc96/ui/button'\nimport { Group } from '@tc96/ui/group'\nimport { ToggleGroup, ToggleGroupItem } from '@tc96/ui/toggle-group'\nimport { cn } from '@tc96/utils'\nimport { Panel, useReactFlow, useStore } from '@xyflow/react'\nimport type { ReactElement, ReactNode } from 'react'\nimport { FlowControlButton } from '../../components/flow-control-button'\nimport { flowControlsPanelClassName } from '../../lib/variants'\nimport { useFlowCanvasContext } from '../../store/flow-canvas-context'\n\nexport interface FlowCanvasControlsProps {\n children?: ReactNode\n className?: string\n}\n\nexport function FlowCanvasControls({\n children,\n className,\n}: Readonly<FlowCanvasControlsProps>): ReactElement {\n const { labels, mode, setMode } = useFlowCanvasContext('FlowCanvasControls')\n const { fitView, zoomIn, zoomOut } = useReactFlow()\n const zoom = useStore((state) => state.transform[2])\n const percent = Math.round(zoom * 100)\n\n return (\n <Panel\n aria-label={labels.controls}\n className={cn(flowControlsPanelClassName, className)}\n data-slot=\"flow-canvas-controls\"\n position=\"bottom-left\"\n role=\"group\"\n >\n <ToggleGroup\n aria-label={labels.mode}\n onValueChange={(value) => {\n const next = value[0]\n if (next === 'select' || next === 'pan') setMode(next)\n }}\n size=\"sm\"\n value={[mode]}\n variant=\"outline\"\n >\n <ToggleGroupItem aria-label={labels.select} value=\"select\">\n <CursorIcon aria-hidden=\"true\" />\n </ToggleGroupItem>\n <ToggleGroupItem aria-label={labels.pan} value=\"pan\">\n <HandIcon aria-hidden=\"true\" />\n </ToggleGroupItem>\n </ToggleGroup>\n <Group>\n <FlowControlButton\n label={labels.zoomOut}\n onClick={() => void zoomOut({ duration: 200 })}\n size=\"icon-sm\"\n variant=\"outline\"\n >\n <MinusIcon aria-hidden=\"true\" />\n </FlowControlButton>\n <Button\n aria-label={labels.zoomLevel(percent)}\n className=\"tabular-nums\"\n onClick={() => void fitView({ duration: 200 })}\n size=\"sm\"\n variant=\"outline\"\n >\n {percent}%\n </Button>\n <FlowControlButton\n label={labels.zoomIn}\n onClick={() => void zoomIn({ duration: 200 })}\n size=\"icon-sm\"\n variant=\"outline\"\n >\n <PlusIcon aria-hidden=\"true\" />\n </FlowControlButton>\n </Group>\n {children}\n </Panel>\n )\n}\n",
|
|
75
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/composition/flow-canvas-controls/flow-canvas-controls.tsx"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"path": "patterns/flow/canvas/composition/flow-canvas-controls/index.ts",
|
|
79
|
+
"type": "registry:file",
|
|
80
|
+
"content": "export * from './flow-canvas-controls'\n",
|
|
81
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/composition/flow-canvas-controls/index.ts"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"path": "patterns/flow/canvas/composition/flow-canvas-minimap/flow-canvas-minimap.tsx",
|
|
85
|
+
"type": "registry:file",
|
|
86
|
+
"content": "'use client'\n\nimport { cn } from '@tc96/utils'\nimport { MiniMap } from '@xyflow/react'\nimport type { ReactElement } from 'react'\nimport { flowMinimapClassName } from '../../lib/variants'\nimport { useFlowCanvasContext } from '../../store/flow-canvas-context'\n\nexport interface FlowCanvasMinimapProps {\n className?: string\n}\n\nexport function FlowCanvasMinimap({\n className,\n}: Readonly<FlowCanvasMinimapProps>): ReactElement {\n const { labels } = useFlowCanvasContext('FlowCanvasMinimap')\n return (\n <MiniMap\n ariaLabel={labels.minimap}\n className={cn(flowMinimapClassName, className)}\n pannable\n position=\"bottom-right\"\n zoomable\n />\n )\n}\n",
|
|
87
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/composition/flow-canvas-minimap/flow-canvas-minimap.tsx"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"path": "patterns/flow/canvas/composition/flow-canvas-minimap/index.ts",
|
|
91
|
+
"type": "registry:file",
|
|
92
|
+
"content": "export * from './flow-canvas-minimap'\n",
|
|
93
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/composition/flow-canvas-minimap/index.ts"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"path": "patterns/flow/canvas/composition/flow-canvas/flow-canvas.tsx",
|
|
97
|
+
"type": "registry:file",
|
|
98
|
+
"content": "'use client'\n\nimport { cn } from '@tc96/utils'\nimport {\n Background,\n BackgroundVariant,\n type NodeChange,\n ReactFlow,\n ReactFlowProvider,\n} from '@xyflow/react'\nimport {\n type ReactElement,\n type ReactNode,\n useCallback,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react'\nimport { FlowCanvasEmpty } from '../../components/flow-canvas-empty'\nimport { FlowStepEdge } from '../../components/flow-step-edge'\nimport { FlowStepNode } from '../../components/flow-step-node'\nimport type { FlowConnection, FlowStepAction, FlowStepType } from '../../core'\nimport { useFlowDrop } from '../../hooks/use-flow-drop'\nimport { useFlowShortcuts } from '../../hooks/use-flow-shortcuts'\nimport { resolveFlowCanvasLabels } from '../../lib/labels'\nimport { resolveStepKind, resolveStepTypeLabel } from '../../lib/steps'\nimport {\n connectionFromReactFlow,\n endsDrag,\n type MeasuredSizes,\n measuredFromChanges,\n moveSteps,\n selectionFromChanges,\n toEdges,\n toNodes,\n} from '../../lib/to-react-flow'\nimport {\n flowCanvasClassName,\n flowCanvasFlowClassName,\n} from '../../lib/variants'\nimport {\n FlowCanvasContext,\n type FlowCanvasContextValue,\n} from '../../store/flow-canvas-context'\nimport type {\n FlowCanvasMode,\n FlowCanvasProps,\n FlowNodeType,\n FlowPosition,\n} from '../../types'\n\nconst nodeTypes = { step: FlowStepNode }\nconst edgeTypes = { step: FlowStepEdge }\nconst gridSize: [number, number] = [16, 16]\nconst fitViewOptions = { padding: 0.2 }\nconst panOnDragButtons = [1, 2]\nconst emptyStepTypes: readonly FlowStepType[] = []\nconst emptyIcons: Record<string, ReactNode> = {}\n\nfunction FlowCanvasContent({\n children,\n className,\n connections,\n direction = 'horizontal',\n edgeControls,\n icons,\n labels: labelsProp,\n loading = false,\n locked = false,\n onConnect,\n onConnectionsChange,\n onSelect,\n onStepAction,\n onStepDrop,\n onStepsChange,\n onStepsChangeEnd,\n selectedStepId = null,\n snapToGrid = false,\n stepMenu,\n stepTypes,\n steps,\n}: Readonly<FlowCanvasProps>): ReactElement {\n const [modeState, setMode] = useState<FlowCanvasMode>('select')\n const mode: FlowCanvasMode = locked ? 'select' : modeState\n const [measured, setMeasured] = useState<MeasuredSizes>({})\n const labels = useMemo(\n () => resolveFlowCanvasLabels(labelsProp),\n [labelsProp],\n )\n const types = stepTypes ?? emptyStepTypes\n const vertical = direction === 'vertical'\n const selected = useRef<string | null>(selectedStepId)\n const latest = useRef({\n onConnect,\n onConnectionsChange,\n onSelect,\n onStepAction,\n onStepDrop,\n onStepsChange,\n onStepsChangeEnd,\n })\n\n useLayoutEffect(() => {\n selected.current = selectedStepId\n latest.current = {\n onConnect,\n onConnectionsChange,\n onSelect,\n onStepAction,\n onStepDrop,\n onStepsChange,\n onStepsChangeEnd,\n }\n })\n\n const handleConnectionsChange = useCallback(\n (next: FlowConnection[]) => latest.current.onConnectionsChange?.(next),\n [],\n )\n const handleStepAction = useCallback(\n (action: FlowStepAction, stepId: string, connection?: FlowConnection) => {\n const { onStepAction: act } = latest.current\n if (connection) act?.(action, stepId, connection)\n else act?.(action, stepId)\n },\n [],\n )\n const handleStepDrop = useCallback(\n (type: FlowStepType, position: FlowPosition) =>\n latest.current.onStepDrop?.(type, position),\n [],\n )\n const emitSelect = useCallback((id: string | null) => {\n if (id === selected.current) return\n selected.current = id\n latest.current.onSelect?.(id)\n }, [])\n\n const nodes = useMemo(\n () =>\n loading\n ? []\n : toNodes(steps, {\n connections,\n describe: (step) =>\n labels.stepName(\n step.name,\n resolveStepTypeLabel(step, types),\n labels.statuses[step.run?.status ?? 'not-run'],\n ),\n direction,\n measured,\n roleDescription: labels.stepRoleDescription,\n selectedStepId,\n }),\n [\n connections,\n direction,\n labels,\n loading,\n measured,\n selectedStepId,\n steps,\n types,\n ],\n )\n const edges = useMemo(\n () => (loading ? [] : toEdges(connections)),\n [connections, loading],\n )\n\n const onNodesChange = useCallback(\n (changes: NodeChange<FlowNodeType>[]) => {\n setMeasured((current) => measuredFromChanges(current, changes))\n const moved = moveSteps(steps, changes)\n if (moved) latest.current.onStepsChange?.(moved)\n if (moved && endsDrag(changes)) latest.current.onStepsChangeEnd?.(moved)\n const selection = selectionFromChanges(changes, selected.current)\n if (selection.changed) emitSelect(selection.id)\n },\n [emitSelect, steps],\n )\n\n const selectedStep = steps.find((step) => step.id === selectedStepId)\n const onDelete = useCallback(() => {\n if (!selectedStep || locked) return\n if (resolveStepKind(selectedStep, types) === 'trigger') return\n handleStepAction('delete', selectedStep.id)\n }, [handleStepAction, locked, selectedStep, types])\n\n const onKeyDown = useFlowShortcuts({ onDelete, onMode: setMode })\n const drop = useFlowDrop({\n disabled: locked || loading,\n onStepDrop: handleStepDrop,\n snapToGrid,\n })\n\n const context = useMemo<FlowCanvasContextValue>(\n () => ({\n connections,\n direction,\n edgeControls: edgeControls ?? vertical,\n icons: icons ?? emptyIcons,\n labels,\n locked,\n mode,\n onConnectionsChange: handleConnectionsChange,\n onStepAction: handleStepAction,\n setMode,\n stepMenu: stepMenu ?? vertical,\n stepTypes: types,\n }),\n [\n connections,\n direction,\n edgeControls,\n icons,\n labels,\n locked,\n mode,\n handleConnectionsChange,\n handleStepAction,\n stepMenu,\n types,\n vertical,\n ],\n )\n\n return (\n <FlowCanvasContext.Provider value={context}>\n <section\n aria-busy={loading || undefined}\n aria-label={labels.canvas}\n className={cn(flowCanvasClassName, className)}\n data-direction={direction}\n data-locked={locked || undefined}\n data-mode={mode}\n data-slot=\"flow-canvas\"\n onKeyDown={onKeyDown}\n tabIndex={-1}\n >\n <ReactFlow<FlowNodeType>\n attributionPosition=\"bottom-center\"\n className={flowCanvasFlowClassName}\n deleteKeyCode={null}\n edges={edges}\n edgeTypes={edgeTypes}\n fitView\n fitViewOptions={fitViewOptions}\n isValidConnection={(connection) =>\n connection.source !== connection.target\n }\n maxZoom={2}\n minZoom={0.25}\n multiSelectionKeyCode={null}\n nodes={nodes}\n nodesConnectable={!locked}\n nodesDraggable={!locked && mode === 'select'}\n nodeTypes={nodeTypes}\n onConnect={(connection) =>\n latest.current.onConnect?.(connectionFromReactFlow(connection))\n }\n onDragOver={drop.onDragOver}\n onDrop={drop.onDrop}\n onNodeClick={(_, node) => emitSelect(node.id)}\n onNodesChange={onNodesChange}\n onPaneClick={() => emitSelect(null)}\n panOnDrag={mode === 'pan' ? true : panOnDragButtons}\n selectionOnDrag={mode === 'select'}\n snapGrid={gridSize}\n snapToGrid={snapToGrid}\n zoomOnDoubleClick={false}\n >\n <Background gap={16} size={1.5} variant={BackgroundVariant.Dots} />\n {children}\n </ReactFlow>\n {!loading && steps.length === 0 ? <FlowCanvasEmpty /> : null}\n </section>\n </FlowCanvasContext.Provider>\n )\n}\n\nexport function FlowCanvas(props: Readonly<FlowCanvasProps>): ReactElement {\n return (\n <ReactFlowProvider>\n <FlowCanvasContent {...props} />\n </ReactFlowProvider>\n )\n}\n",
|
|
99
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/composition/flow-canvas/flow-canvas.tsx"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"path": "patterns/flow/canvas/composition/flow-canvas/index.ts",
|
|
103
|
+
"type": "registry:file",
|
|
104
|
+
"content": "export * from './flow-canvas'\n",
|
|
105
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/composition/flow-canvas/index.ts"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"path": "patterns/flow/canvas/composition/index.ts",
|
|
109
|
+
"type": "registry:file",
|
|
110
|
+
"content": "export * from './flow-canvas/index'\nexport * from './flow-canvas-controls/index'\nexport * from './flow-canvas-minimap/index'\n",
|
|
111
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/composition/index.ts"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"path": "patterns/flow/canvas/core.ts",
|
|
115
|
+
"type": "registry:file",
|
|
116
|
+
"content": "import { hierarchy, tree } from 'd3-hierarchy'\n\nexport type FlowDirection = 'horizontal' | 'vertical'\nexport type FlowRunStatus =\n | 'idle'\n | 'running'\n | 'success'\n | 'failed'\n | 'skipped'\n | 'not-run'\nexport type FlowStepKind = 'trigger' | 'action' | 'condition'\n\nexport interface FlowStepType {\n id: string\n label: string\n group: string\n kind?: FlowStepKind\n description?: string\n}\n\nexport interface FlowStepRun {\n status: FlowRunStatus\n durationMs?: number\n metrics?: readonly string[]\n note?: string\n}\n\nexport interface FlowStep {\n id: string\n type: string\n name: string\n description?: string\n kind?: FlowStepKind\n owner?: { name: string; avatarUrl?: string }\n position: { x: number; y: number }\n run?: FlowStepRun\n}\n\nexport interface FlowConnection {\n id: string\n source: string\n target: string\n label?: string\n sourceHandle?: string\n taken?: boolean\n}\n\nexport interface FlowRunSummary {\n status: FlowRunStatus\n id?: string\n note?: string\n completed: number\n total: number\n}\n\nexport type FlowStepAction =\n | 'add-after'\n | 'add-branch'\n | 'view'\n | 'edit'\n | 'duplicate'\n | 'delete'\n\nexport interface TidyTreeOptions {\n direction: FlowDirection\n nodeSize: readonly [number, number]\n gap: readonly [number, number]\n}\n\nexport const flowStepNodeSize = [256, 100] as const\n\nexport const FLOW_STEP_TRANSFER_TYPE = 'application/x-tc96-flow-step'\n\nconst stepKinds: readonly string[] = ['trigger', 'action', 'condition']\n\nexport function serializeStepTransfer(type: FlowStepType) {\n return JSON.stringify(type)\n}\n\nexport function parseStepTransfer(\n raw: string | null | undefined,\n): FlowStepType | null {\n if (!raw) return null\n let value: unknown\n try {\n value = JSON.parse(raw)\n } catch {\n return null\n }\n if (typeof value !== 'object' || value === null) return null\n const { id, label, group, kind, description } = value as Record<\n string,\n unknown\n >\n if (\n typeof id !== 'string' ||\n typeof label !== 'string' ||\n typeof group !== 'string'\n )\n return null\n if (\n kind !== undefined &&\n !(typeof kind === 'string' && stepKinds.includes(kind))\n )\n return null\n if (description !== undefined && typeof description !== 'string') return null\n return {\n id,\n label,\n group,\n ...(kind !== undefined && { kind: kind as FlowStepKind }),\n ...(description !== undefined && { description }),\n }\n}\n\nexport function incomingOf(\n stepId: string,\n connections: readonly FlowConnection[],\n) {\n return connections.filter((connection) => connection.target === stepId)\n}\n\nexport function outgoingOf(\n stepId: string,\n connections: readonly FlowConnection[],\n) {\n return connections.filter((connection) => connection.source === stepId)\n}\n\ninterface TreeNode {\n id: string | null\n children: TreeNode[]\n}\n\nexport function tidyTree(\n steps: readonly FlowStep[],\n connections: readonly FlowConnection[],\n options: TidyTreeOptions,\n): FlowStep[] {\n const { direction, nodeSize, gap } = options\n const ids = new Set(steps.map((step) => step.id))\n const nodes = new Map<string, TreeNode>(\n steps.map((step) => [step.id, { id: step.id, children: [] }]),\n )\n const placed = new Set<string>()\n const roots = steps.filter(\n (step) =>\n !connections.some(\n (connection) =>\n connection.target === step.id &&\n connection.source !== step.id &&\n ids.has(connection.source),\n ),\n )\n const rootNodes: TreeNode[] = []\n const stack: TreeNode[] = []\n const expand = (pending: TreeNode[]) => {\n while (pending.length) {\n const current = pending.pop()\n if (!current?.id) continue\n for (const connection of outgoingOf(current.id, connections)) {\n const child = nodes.get(connection.target)\n if (!child || placed.has(connection.target)) continue\n placed.add(connection.target)\n current.children.push(child)\n pending.push(child)\n }\n }\n }\n for (const root of roots) {\n const node = nodes.get(root.id)\n if (!node) continue\n rootNodes.push(node)\n placed.add(root.id)\n stack.push(node)\n expand(stack)\n }\n for (const step of steps) {\n if (placed.has(step.id)) continue\n const node = nodes.get(step.id)\n if (!node) continue\n rootNodes.push(node)\n placed.add(step.id)\n stack.push(node)\n expand(stack)\n }\n if (!rootNodes.length) return steps.map((step) => ({ ...step }))\n\n const virtualRoot: TreeNode = { id: null, children: rootNodes }\n const [width, height] = nodeSize\n const [gapX, gapY] = gap\n const horizontal = direction === 'horizontal'\n const breadth = horizontal ? height + gapY : width + gapX\n const depth = horizontal ? width + gapX : height + gapY\n const layout = tree<TreeNode>()\n .nodeSize([breadth, depth])\n .separation(() => 1)(hierarchy(virtualRoot, (node) => node.children))\n\n const positions = new Map<string, { x: number; y: number }>()\n for (const node of layout.descendants()) {\n if (node.data.id === null) continue\n const across = node.x - (horizontal ? height : width) / 2\n const along = node.y - depth\n positions.set(\n node.data.id,\n horizontal ? { x: along, y: across } : { x: across, y: along },\n )\n }\n const values = [...positions.values()]\n const minX = Math.min(...values.map((position) => position.x))\n const minY = Math.min(...values.map((position) => position.y))\n\n return steps.map((step) => {\n const position = positions.get(step.id)\n if (!position) return { ...step }\n return {\n ...step,\n position: { x: position.x - minX, y: position.y - minY },\n }\n })\n}\n\nexport function flowRunSummary(\n steps: readonly FlowStep[],\n options: { id?: string } = {},\n): FlowRunSummary {\n const total = steps.length\n const completed = steps.filter(\n (step) => step.run?.status === 'success',\n ).length\n const failed = steps.find((step) => step.run?.status === 'failed')\n const summary = { id: options.id, completed, total }\n if (failed) return { ...summary, status: 'failed', note: failed.run?.note }\n if (steps.some((step) => step.run?.status === 'running'))\n return { ...summary, status: 'running' }\n if (total > 0 && steps.every((step) => step.run?.status === 'skipped'))\n return { ...summary, status: 'skipped' }\n if (\n completed > 0 &&\n steps.every(\n (step) =>\n step.run?.status === 'success' || step.run?.status === 'skipped',\n )\n )\n return { ...summary, status: 'success' }\n if (\n steps.every(\n (step) =>\n !step.run ||\n step.run.status === 'not-run' ||\n step.run.status === 'idle',\n )\n )\n return { ...summary, status: 'not-run' }\n return { ...summary, status: 'idle' }\n}\n",
|
|
117
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/core.ts"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"path": "patterns/flow/canvas/hooks/use-flow-drop.ts",
|
|
121
|
+
"type": "registry:file",
|
|
122
|
+
"content": "import { useReactFlow } from '@xyflow/react'\nimport { type DragEvent, useCallback } from 'react'\nimport {\n FLOW_STEP_TRANSFER_TYPE,\n type FlowStepType,\n parseStepTransfer,\n} from '../core'\nimport type { FlowPosition } from '../types'\n\nexport interface UseFlowDropOptions {\n disabled?: boolean\n onStepDrop?: (type: FlowStepType, position: FlowPosition) => void\n snapToGrid?: boolean\n}\n\nexport function useFlowDrop({\n disabled,\n onStepDrop,\n snapToGrid,\n}: UseFlowDropOptions) {\n const { screenToFlowPosition } = useReactFlow()\n\n const onDragOver = useCallback(\n (event: DragEvent) => {\n if (disabled) return\n if (!event.dataTransfer.types.includes(FLOW_STEP_TRANSFER_TYPE)) return\n event.preventDefault()\n event.dataTransfer.dropEffect = 'move'\n },\n [disabled],\n )\n\n const onDrop = useCallback(\n (event: DragEvent) => {\n if (disabled) return\n const type = parseStepTransfer(\n event.dataTransfer.getData(FLOW_STEP_TRANSFER_TYPE),\n )\n if (!type) return\n event.preventDefault()\n const position = screenToFlowPosition(\n { x: event.clientX, y: event.clientY },\n { snapToGrid },\n )\n onStepDrop?.(type, position)\n },\n [disabled, onStepDrop, screenToFlowPosition, snapToGrid],\n )\n\n return { onDragOver, onDrop }\n}\n",
|
|
123
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/hooks/use-flow-drop.ts"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"path": "patterns/flow/canvas/hooks/use-flow-shortcuts.ts",
|
|
127
|
+
"type": "registry:file",
|
|
128
|
+
"content": "import { useReactFlow } from '@xyflow/react'\nimport { type KeyboardEvent, useCallback } from 'react'\nimport type { FlowCanvasMode } from '../types'\n\nexport interface UseFlowShortcutsOptions {\n onDelete?: () => void\n onMode: (mode: FlowCanvasMode) => void\n}\n\nexport function isTextEntry(target: EventTarget | null): boolean {\n if (!(target instanceof HTMLElement)) return false\n if (target.isContentEditable) return true\n const tag = target.tagName\n return (\n tag === 'INPUT' ||\n tag === 'TEXTAREA' ||\n tag === 'SELECT' ||\n target.getAttribute('role') === 'textbox'\n )\n}\n\nexport function useFlowShortcuts({\n onDelete,\n onMode,\n}: UseFlowShortcutsOptions) {\n const { fitView, zoomIn, zoomOut, zoomTo } = useReactFlow()\n\n return useCallback(\n (event: KeyboardEvent) => {\n if (event.defaultPrevented || isTextEntry(event.target)) return\n if (\n !(event.target instanceof Node) ||\n !event.currentTarget.contains(event.target)\n )\n return\n if (event.ctrlKey || event.metaKey || event.altKey) return\n if (event.shiftKey && event.code === 'Digit1') {\n event.preventDefault()\n void fitView({ duration: 200 })\n return\n }\n if (event.shiftKey && event.code === 'Digit0') {\n event.preventDefault()\n void zoomTo(1, { duration: 200 })\n return\n }\n if (event.shiftKey) return\n switch (event.key) {\n case 'v':\n case 'V':\n onMode('select')\n return\n case 'h':\n case 'H':\n onMode('pan')\n return\n case '+':\n case '=':\n event.preventDefault()\n void zoomIn({ duration: 200 })\n return\n case '-':\n event.preventDefault()\n void zoomOut({ duration: 200 })\n return\n case 'Backspace':\n case 'Delete':\n if (!onDelete) return\n event.preventDefault()\n onDelete()\n return\n default:\n }\n },\n [fitView, onDelete, onMode, zoomIn, zoomOut, zoomTo],\n )\n}\n",
|
|
129
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/hooks/use-flow-shortcuts.ts"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"path": "patterns/flow/canvas/index.ts",
|
|
133
|
+
"type": "registry:file",
|
|
134
|
+
"content": "export type { FlowShortcutsPopoverProps } from './components/flow-shortcuts-popover'\nexport { FlowShortcutsPopover } from './components/flow-shortcuts-popover'\nexport * from './composition/index'\nexport type {\n FlowConnection,\n FlowDirection,\n FlowRunStatus,\n FlowRunSummary,\n FlowStep,\n FlowStepAction,\n FlowStepKind,\n FlowStepRun,\n FlowStepType,\n TidyTreeOptions,\n} from './core'\nexport {\n FLOW_STEP_TRANSFER_TYPE,\n flowRunSummary,\n flowStepNodeSize,\n incomingOf,\n outgoingOf,\n parseStepTransfer,\n serializeStepTransfer,\n tidyTree,\n} from './core'\nexport type {\n FlowCanvasLabels,\n FlowCanvasMode,\n FlowCanvasProps,\n FlowConnectInput,\n FlowPosition,\n FlowShortcutsLabels,\n} from './types'\n",
|
|
135
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/index.ts"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"path": "patterns/flow/canvas/lib/labels.ts",
|
|
139
|
+
"type": "registry:file",
|
|
140
|
+
"content": "import type { FlowCanvasLabels, FlowShortcutsLabels } from '../types'\n\nexport const defaultFlowCanvasLabels: FlowCanvasLabels = {\n actions: {\n 'add-after': (name) => `Adicionar um passo depois de ${name}`,\n 'add-branch': (name) => `Adicionar ramo em ${name}`,\n delete: (name) => `Excluir ${name}`,\n duplicate: (name) => `Duplicar ${name}`,\n edit: (name) => `Editar ${name}`,\n view: (name) => `Ver ${name}`,\n },\n addAfterLeaf: (name) => `Adicionar um passo depois de ${name}`,\n canvas: 'Canvas do fluxo',\n controls: 'Controles do canvas',\n edgeAdd: (label) =>\n label\n ? `Adicionar um passo no caminho ${label}`\n : 'Adicionar um passo aqui',\n edgeRemove: (label) =>\n label ? `Remover a conexão do caminho ${label}` : 'Remover esta conexão',\n emptyDescription:\n 'Arraste um passo da biblioteca ou clique em Adicionar passo.',\n emptyTitle: 'Nenhum passo ainda',\n menuActions: {\n 'add-after': 'Adicionar passo depois',\n 'add-branch': 'Adicionar ramo',\n delete: 'Excluir',\n duplicate: 'Duplicar',\n edit: 'Editar',\n view: 'Ver',\n },\n minimap: 'Minimapa',\n mode: 'Modo do cursor',\n pan: 'Mover',\n select: 'Selecionar',\n sourceHandle: (name) => `Conectar a partir de ${name}`,\n statuses: {\n failed: 'Falhou',\n idle: 'Parado',\n 'not-run': 'Não executado',\n running: 'Executando',\n skipped: 'Ignorado',\n success: 'Sucesso',\n },\n stepMenu: (name) => `Ações de ${name}`,\n stepName: (name, type, status) => `${name}, ${type}, ${status}`,\n stepRoleDescription: 'passo',\n stepToolbar: (name) => `Ações de ${name}`,\n targetHandle: (name) => `Conectar em ${name}`,\n zoomIn: 'Aumentar zoom',\n zoomLevel: (percent) => `Nível de zoom ${percent}%`,\n zoomOut: 'Diminuir zoom',\n}\n\nexport const defaultFlowShortcutsLabels: FlowShortcutsLabels = {\n actualSize: 'Tamanho real',\n fit: 'Ajustar à tela',\n pan: 'Mover',\n remove: 'Excluir passo',\n select: 'Selecionar',\n title: 'Atalhos de teclado',\n trigger: 'Atalhos de teclado',\n zoomIn: 'Aumentar zoom',\n zoomOut: 'Diminuir zoom',\n}\n\nexport function resolveFlowCanvasLabels(\n labels: Partial<FlowCanvasLabels> | undefined,\n): FlowCanvasLabels {\n return { ...defaultFlowCanvasLabels, ...labels }\n}\n",
|
|
141
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/lib/labels.ts"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"path": "patterns/flow/canvas/lib/steps.ts",
|
|
145
|
+
"type": "registry:file",
|
|
146
|
+
"content": "import {\n CheckCircleIcon,\n CircleDashedIcon,\n CopyIcon,\n CubeIcon,\n EyeIcon,\n GitBranchIcon,\n GitDiffIcon,\n LightningIcon,\n MinusCircleIcon,\n PencilSimpleIcon,\n type Icon as PhosphorIcon,\n PlayIcon,\n PlusIcon,\n TrashIcon,\n XCircleIcon,\n} from '@phosphor-icons/react'\nimport type {\n FlowRunStatus,\n FlowStep,\n FlowStepAction,\n FlowStepKind,\n FlowStepType,\n} from '../core'\n\nexport const flowKindIcons: Record<FlowStepKind, PhosphorIcon> = {\n action: PlayIcon,\n condition: GitBranchIcon,\n trigger: LightningIcon,\n}\n\nexport const flowFallbackIcon: PhosphorIcon = CubeIcon\n\nexport const flowStatusIcons: Record<FlowRunStatus, PhosphorIcon> = {\n failed: XCircleIcon,\n idle: CircleDashedIcon,\n 'not-run': CircleDashedIcon,\n running: PlayIcon,\n skipped: MinusCircleIcon,\n success: CheckCircleIcon,\n}\n\nexport const flowActionIcons: Record<FlowStepAction, PhosphorIcon> = {\n 'add-after': PlusIcon,\n 'add-branch': GitDiffIcon,\n delete: TrashIcon,\n duplicate: CopyIcon,\n edit: PencilSimpleIcon,\n view: EyeIcon,\n}\n\nconst toolbarActions: readonly FlowStepAction[] = [\n 'add-after',\n 'view',\n 'edit',\n 'duplicate',\n 'delete',\n]\nconst menuActions: readonly FlowStepAction[] = [\n 'view',\n 'edit',\n 'add-branch',\n 'delete',\n]\nconst mutatingActions: readonly FlowStepAction[] = [\n 'add-after',\n 'add-branch',\n 'duplicate',\n 'delete',\n]\nconst triggerHidden: readonly FlowStepAction[] = ['duplicate', 'delete']\n\nexport function isMutatingAction(action: FlowStepAction): boolean {\n return mutatingActions.includes(action)\n}\n\nexport function resolveStepKind(\n step: FlowStep,\n stepTypes: readonly FlowStepType[] | undefined,\n): FlowStepKind {\n return (\n step.kind ??\n stepTypes?.find((type) => type.id === step.type)?.kind ??\n 'action'\n )\n}\n\nexport function resolveStepTypeLabel(\n step: FlowStep,\n stepTypes: readonly FlowStepType[] | undefined,\n): string {\n return stepTypes?.find((type) => type.id === step.type)?.label ?? step.type\n}\n\nexport function stepActionsFor(\n kind: FlowStepKind,\n variant: 'toolbar' | 'menu',\n): FlowStepAction[] {\n const actions = variant === 'toolbar' ? toolbarActions : menuActions\n return actions.filter(\n (action) => kind !== 'trigger' || !triggerHidden.includes(action),\n )\n}\n\nexport function formatStepDuration(durationMs: number): string {\n if (durationMs < 1000) return `${Math.round(durationMs)}ms`\n return `${(durationMs / 1000).toFixed(1)}s`\n}\n",
|
|
147
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/lib/steps.ts"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"path": "patterns/flow/canvas/lib/to-react-flow.ts",
|
|
151
|
+
"type": "registry:file",
|
|
152
|
+
"content": "import { MarkerType, type NodeChange, Position } from '@xyflow/react'\nimport type { FlowConnection, FlowDirection, FlowStep } from '../core'\nimport type { FlowConnectInput, FlowEdgeType, FlowNodeType } from '../types'\n\nexport type MeasuredSizes = Readonly<\n Record<string, { width: number; height: number }>\n>\n\nexport interface ToNodesOptions {\n connections: readonly FlowConnection[]\n describe: (step: FlowStep) => string\n direction: FlowDirection\n measured?: MeasuredSizes\n roleDescription: string\n selectedStepId?: string | null\n}\n\nexport function handlePositions(direction: FlowDirection) {\n return direction === 'vertical'\n ? { source: Position.Bottom, target: Position.Top }\n : { source: Position.Right, target: Position.Left }\n}\n\nexport function toNodes(\n steps: readonly FlowStep[],\n options: ToNodesOptions,\n): FlowNodeType[] {\n const {\n connections,\n describe,\n direction,\n measured,\n roleDescription,\n selectedStepId,\n } = options\n const { source, target } = handlePositions(direction)\n const parents = new Set(connections.map((connection) => connection.source))\n return steps.map((step) => ({\n ariaLabel: describe(step),\n ariaRole: 'group',\n className: 'group/step outline-none',\n data: { leaf: !parents.has(step.id), step },\n deletable: false,\n domAttributes: { 'aria-roledescription': roleDescription },\n id: step.id,\n measured: measured?.[step.id],\n position: { x: step.position.x, y: step.position.y },\n selected: step.id === selectedStepId,\n sourcePosition: source,\n targetPosition: target,\n type: 'step',\n }))\n}\n\nexport function toEdges(\n connections: readonly FlowConnection[],\n): FlowEdgeType[] {\n return connections.map((connection) => ({\n animated: connection.taken === true,\n data: { connection },\n focusable: false,\n id: connection.id,\n markerEnd: { height: 16, type: MarkerType.ArrowClosed, width: 16 },\n selectable: false,\n source: connection.source,\n target: connection.target,\n type: 'step',\n }))\n}\n\nexport function connectionFromReactFlow(connection: {\n source: string\n target: string\n sourceHandle?: string | null\n}): FlowConnectInput {\n return {\n source: connection.source,\n target: connection.target,\n ...(connection.sourceHandle\n ? { sourceHandle: connection.sourceHandle }\n : {}),\n }\n}\n\nexport function moveSteps(\n steps: readonly FlowStep[],\n changes: readonly NodeChange<FlowNodeType>[],\n): FlowStep[] | null {\n const moves = new Map<string, { x: number; y: number }>()\n for (const change of changes) {\n if (change.type === 'position' && change.position)\n moves.set(change.id, change.position)\n }\n if (!moves.size) return null\n return steps.map((step) => {\n const position = moves.get(step.id)\n return position ? { ...step, position: { ...position } } : { ...step }\n })\n}\n\nexport function endsDrag(\n changes: readonly NodeChange<FlowNodeType>[],\n): boolean {\n return changes.some(\n (change) => change.type === 'position' && change.dragging === false,\n )\n}\n\nexport function measuredFromChanges(\n current: MeasuredSizes,\n changes: readonly NodeChange<FlowNodeType>[],\n): MeasuredSizes {\n let next: Record<string, { width: number; height: number }> | undefined\n for (const change of changes) {\n if (change.type !== 'dimensions' || !change.dimensions) continue\n const { width, height } = change.dimensions\n const known = current[change.id]\n if (known?.width === width && known.height === height) continue\n next ??= { ...current }\n next[change.id] = { height, width }\n }\n return next ?? current\n}\n\nexport function selectionFromChanges(\n changes: readonly NodeChange<FlowNodeType>[],\n current: string | null,\n): { changed: boolean; id: string | null } {\n const selected = changes.find(\n (change) => change.type === 'select' && change.selected,\n )\n if (selected && 'id' in selected)\n return { changed: selected.id !== current, id: selected.id }\n const deselected = changes.some(\n (change) =>\n change.type === 'select' && !change.selected && change.id === current,\n )\n return deselected\n ? { changed: true, id: null }\n : { changed: false, id: current }\n}\n",
|
|
153
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/lib/to-react-flow.ts"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"path": "patterns/flow/canvas/lib/variants.ts",
|
|
157
|
+
"type": "registry:file",
|
|
158
|
+
"content": "import { cva } from 'class-variance-authority'\nimport type { FlowRunStatus } from '../core'\n\nexport const flowCanvasClassName =\n 'relative isolate flex size-full min-h-80 min-w-0 flex-col overflow-hidden bg-background outline-none'\n\nexport const flowCanvasFlowClassName =\n '[--xy-attribution-background-color:transparent] [--xy-background-pattern-dots-color:var(--color-border)] [--xy-connectionline-stroke:var(--color-primary)] [--xy-edge-stroke:var(--color-muted-foreground)] [--xy-minimap-background-color:var(--color-card)] [--xy-minimap-mask-background-color:color-mix(in_oklab,var(--color-background)_72%,transparent)] [--xy-minimap-node-background-color:var(--color-muted-foreground)]' +\n String.raw` [&_.react-flow\\_\\_attribution_a]:text-muted-foreground!`\n\nexport const flowCanvasEmptyClassName =\n 'pointer-events-none absolute inset-0 z-10 flex items-center justify-center'\n\nexport const flowStepNodeVariants = cva(\n 'gap-0 transition-shadow group-focus-visible/step:ring-2 group-focus-visible/step:ring-ring',\n {\n defaultVariants: { selected: false },\n variants: {\n selected: {\n false: '',\n true: 'ring-2 ring-primary',\n },\n },\n },\n)\n\nexport const flowStepNodeHeaderClassName = 'flex min-w-0 items-center gap-3 p-3'\n\nexport const flowStepNodeTextClassName = 'flex min-w-0 flex-1 flex-col'\n\nexport const flowStepNodeTitleClassName = 'truncate font-medium text-sm'\n\nexport const flowStepNodeDescriptionClassName =\n 'truncate text-muted-foreground text-xs'\n\nexport const flowStepNodeFooterClassName =\n 'flex min-w-0 items-center gap-2 border-t px-3 py-2 text-muted-foreground text-xs'\n\nexport const flowStepNodeIconVariants = cva('', {\n defaultVariants: { kind: 'action' },\n variants: {\n kind: {\n action: 'border border-border bg-transparent text-foreground',\n condition: 'border border-border bg-transparent text-foreground',\n trigger: 'bg-primary text-primary-foreground',\n },\n },\n})\n\nexport const flowStatusTextVariants = cva('flex min-w-0 items-center gap-1', {\n defaultVariants: { status: 'not-run' },\n variants: {\n status: {\n failed: 'text-destructive-foreground',\n idle: 'text-muted-foreground',\n 'not-run': 'text-muted-foreground',\n running: 'text-muted-foreground',\n skipped: 'text-muted-foreground',\n success: 'text-muted-foreground',\n } satisfies Record<FlowRunStatus, string>,\n },\n})\n\nexport const flowHandleClassName =\n 'size-2.5! border-2! border-background! bg-muted-foreground!'\n\nexport const flowNodeAddLeafClassName =\n 'nodrag nopan absolute start-1/2 top-full mt-2 -translate-x-1/2'\n\nexport const flowEdgePathVariants = cva(\n 'stroke-2! motion-reduce:animate-none!',\n {\n defaultVariants: { taken: false },\n variants: {\n taken: {\n false: 'stroke-muted-foreground!',\n true: 'stroke-primary!',\n },\n },\n },\n)\n\nexport const flowEdgeLabelClassName =\n 'nodrag nopan pointer-events-auto absolute flex items-center gap-1'\n\nexport const flowEdgeControlsClassName =\n 'flex items-center gap-1 opacity-0 transition-opacity focus-within:opacity-100 hover:opacity-100 pointer-coarse:opacity-100'\n\nexport const flowControlsPanelClassName =\n 'm-4 flex items-center gap-2 rounded-xl border bg-card p-1 text-card-foreground shadow-xs/5'\n\nexport const flowMinimapClassName =\n 'm-4 hidden overflow-hidden rounded-xl border! shadow-sm/5 md:block'\n\nexport const flowShortcutRowClassName =\n 'flex items-center justify-between gap-6 text-sm'\n",
|
|
159
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/lib/variants.ts"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"path": "patterns/flow/canvas/store/flow-canvas-context.ts",
|
|
163
|
+
"type": "registry:file",
|
|
164
|
+
"content": "import { createContext, type ReactNode, useContext } from 'react'\nimport type {\n FlowConnection,\n FlowDirection,\n FlowStepAction,\n FlowStepType,\n} from '../core'\nimport type { FlowCanvasLabels, FlowCanvasMode } from '../types'\n\nexport interface FlowCanvasContextValue {\n connections: readonly FlowConnection[]\n direction: FlowDirection\n edgeControls: boolean\n icons: Record<string, ReactNode>\n labels: FlowCanvasLabels\n locked: boolean\n mode: FlowCanvasMode\n onConnectionsChange?: (connections: FlowConnection[]) => void\n onStepAction?: (\n action: FlowStepAction,\n stepId: string,\n connection?: FlowConnection,\n ) => void\n setMode: (mode: FlowCanvasMode) => void\n stepMenu: boolean\n stepTypes: readonly FlowStepType[]\n}\n\nexport const FlowCanvasContext = createContext<\n FlowCanvasContextValue | undefined\n>(undefined)\n\nexport function useFlowCanvasContext(\n component: string,\n): FlowCanvasContextValue {\n const context = useContext(FlowCanvasContext)\n if (!context)\n throw new Error(`${component} must be used inside a FlowCanvas.`)\n return context\n}\n",
|
|
165
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/store/flow-canvas-context.ts"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"path": "patterns/flow/canvas/types/index.ts",
|
|
169
|
+
"type": "registry:file",
|
|
170
|
+
"content": "import type { Edge, Node } from '@xyflow/react'\nimport type { ReactNode } from 'react'\nimport type {\n FlowConnection,\n FlowDirection,\n FlowRunStatus,\n FlowStep,\n FlowStepAction,\n FlowStepType,\n} from '../core'\n\nexport type FlowCanvasMode = 'select' | 'pan'\n\nexport interface FlowPosition {\n x: number\n y: number\n}\n\nexport interface FlowConnectInput {\n source: string\n target: string\n sourceHandle?: string\n}\n\nexport interface FlowCanvasLabels {\n canvas: string\n stepRoleDescription: string\n statuses: Record<FlowRunStatus, string>\n stepName: (name: string, type: string, status: string) => string\n stepToolbar: (name: string) => string\n stepMenu: (name: string) => string\n actions: Record<FlowStepAction, (name: string) => string>\n menuActions: Record<FlowStepAction, string>\n addAfterLeaf: (name: string) => string\n sourceHandle: (name: string) => string\n targetHandle: (name: string) => string\n edgeAdd: (label?: string) => string\n edgeRemove: (label?: string) => string\n controls: string\n mode: string\n select: string\n pan: string\n zoomOut: string\n zoomIn: string\n zoomLevel: (percent: number) => string\n minimap: string\n emptyTitle: string\n emptyDescription: string\n}\n\nexport interface FlowCanvasProps {\n steps: readonly FlowStep[]\n connections: readonly FlowConnection[]\n stepTypes?: readonly FlowStepType[]\n direction?: FlowDirection\n selectedStepId?: string | null\n locked?: boolean\n snapToGrid?: boolean\n loading?: boolean\n edgeControls?: boolean\n stepMenu?: boolean\n icons?: Record<string, ReactNode>\n labels?: Partial<FlowCanvasLabels>\n className?: string\n children?: ReactNode\n onStepsChange?: (steps: FlowStep[]) => void\n onStepsChangeEnd?: (steps: FlowStep[]) => void\n onConnectionsChange?: (connections: FlowConnection[]) => void\n onConnect?: (connection: FlowConnectInput) => void\n onSelect?: (stepId: string | null) => void\n onStepDrop?: (type: FlowStepType, position: FlowPosition) => void\n onStepAction?: (\n action: FlowStepAction,\n stepId: string,\n connection?: FlowConnection,\n ) => void\n}\n\nexport interface FlowNodeData extends Record<string, unknown> {\n step: FlowStep\n leaf: boolean\n}\n\nexport interface FlowEdgeData extends Record<string, unknown> {\n connection: FlowConnection\n}\n\nexport type FlowNodeType = Node<FlowNodeData, 'step'>\nexport type FlowEdgeType = Edge<FlowEdgeData, 'step'>\n\nexport interface FlowShortcutsLabels {\n trigger: string\n title: string\n select: string\n pan: string\n zoomIn: string\n zoomOut: string\n fit: string\n actualSize: string\n remove: string\n}\n",
|
|
171
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/types/index.ts"
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
"dependencies": [
|
|
175
|
+
"@phosphor-icons/react@2.1.10",
|
|
176
|
+
"@xyflow/react@12.12.0",
|
|
177
|
+
"class-variance-authority@0.7.1",
|
|
178
|
+
"d3-hierarchy@3.1.2",
|
|
179
|
+
"react@19.1.1"
|
|
180
|
+
],
|
|
181
|
+
"registryDependencies": [
|
|
182
|
+
"@ui/avatar",
|
|
183
|
+
"@ui/badge",
|
|
184
|
+
"@ui/button",
|
|
185
|
+
"@ui/card",
|
|
186
|
+
"@ui/context-menu",
|
|
187
|
+
"@ui/empty",
|
|
188
|
+
"@ui/group",
|
|
189
|
+
"@ui/icon-frame",
|
|
190
|
+
"@ui/kbd",
|
|
191
|
+
"@ui/menu",
|
|
192
|
+
"@ui/popover",
|
|
193
|
+
"@ui/spinner",
|
|
194
|
+
"@ui/toggle-group",
|
|
195
|
+
"@ui/tooltip"
|
|
196
|
+
],
|
|
197
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
198
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "flow-inspector",
|
|
3
|
+
"type": "registry:block",
|
|
4
|
+
"files": [
|
|
5
|
+
{
|
|
6
|
+
"path": "patterns/flow/canvas/core.ts",
|
|
7
|
+
"type": "registry:file",
|
|
8
|
+
"content": "import { hierarchy, tree } from 'd3-hierarchy'\n\nexport type FlowDirection = 'horizontal' | 'vertical'\nexport type FlowRunStatus =\n | 'idle'\n | 'running'\n | 'success'\n | 'failed'\n | 'skipped'\n | 'not-run'\nexport type FlowStepKind = 'trigger' | 'action' | 'condition'\n\nexport interface FlowStepType {\n id: string\n label: string\n group: string\n kind?: FlowStepKind\n description?: string\n}\n\nexport interface FlowStepRun {\n status: FlowRunStatus\n durationMs?: number\n metrics?: readonly string[]\n note?: string\n}\n\nexport interface FlowStep {\n id: string\n type: string\n name: string\n description?: string\n kind?: FlowStepKind\n owner?: { name: string; avatarUrl?: string }\n position: { x: number; y: number }\n run?: FlowStepRun\n}\n\nexport interface FlowConnection {\n id: string\n source: string\n target: string\n label?: string\n sourceHandle?: string\n taken?: boolean\n}\n\nexport interface FlowRunSummary {\n status: FlowRunStatus\n id?: string\n note?: string\n completed: number\n total: number\n}\n\nexport type FlowStepAction =\n | 'add-after'\n | 'add-branch'\n | 'view'\n | 'edit'\n | 'duplicate'\n | 'delete'\n\nexport interface TidyTreeOptions {\n direction: FlowDirection\n nodeSize: readonly [number, number]\n gap: readonly [number, number]\n}\n\nexport const flowStepNodeSize = [256, 100] as const\n\nexport const FLOW_STEP_TRANSFER_TYPE = 'application/x-tc96-flow-step'\n\nconst stepKinds: readonly string[] = ['trigger', 'action', 'condition']\n\nexport function serializeStepTransfer(type: FlowStepType) {\n return JSON.stringify(type)\n}\n\nexport function parseStepTransfer(\n raw: string | null | undefined,\n): FlowStepType | null {\n if (!raw) return null\n let value: unknown\n try {\n value = JSON.parse(raw)\n } catch {\n return null\n }\n if (typeof value !== 'object' || value === null) return null\n const { id, label, group, kind, description } = value as Record<\n string,\n unknown\n >\n if (\n typeof id !== 'string' ||\n typeof label !== 'string' ||\n typeof group !== 'string'\n )\n return null\n if (\n kind !== undefined &&\n !(typeof kind === 'string' && stepKinds.includes(kind))\n )\n return null\n if (description !== undefined && typeof description !== 'string') return null\n return {\n id,\n label,\n group,\n ...(kind !== undefined && { kind: kind as FlowStepKind }),\n ...(description !== undefined && { description }),\n }\n}\n\nexport function incomingOf(\n stepId: string,\n connections: readonly FlowConnection[],\n) {\n return connections.filter((connection) => connection.target === stepId)\n}\n\nexport function outgoingOf(\n stepId: string,\n connections: readonly FlowConnection[],\n) {\n return connections.filter((connection) => connection.source === stepId)\n}\n\ninterface TreeNode {\n id: string | null\n children: TreeNode[]\n}\n\nexport function tidyTree(\n steps: readonly FlowStep[],\n connections: readonly FlowConnection[],\n options: TidyTreeOptions,\n): FlowStep[] {\n const { direction, nodeSize, gap } = options\n const ids = new Set(steps.map((step) => step.id))\n const nodes = new Map<string, TreeNode>(\n steps.map((step) => [step.id, { id: step.id, children: [] }]),\n )\n const placed = new Set<string>()\n const roots = steps.filter(\n (step) =>\n !connections.some(\n (connection) =>\n connection.target === step.id &&\n connection.source !== step.id &&\n ids.has(connection.source),\n ),\n )\n const rootNodes: TreeNode[] = []\n const stack: TreeNode[] = []\n const expand = (pending: TreeNode[]) => {\n while (pending.length) {\n const current = pending.pop()\n if (!current?.id) continue\n for (const connection of outgoingOf(current.id, connections)) {\n const child = nodes.get(connection.target)\n if (!child || placed.has(connection.target)) continue\n placed.add(connection.target)\n current.children.push(child)\n pending.push(child)\n }\n }\n }\n for (const root of roots) {\n const node = nodes.get(root.id)\n if (!node) continue\n rootNodes.push(node)\n placed.add(root.id)\n stack.push(node)\n expand(stack)\n }\n for (const step of steps) {\n if (placed.has(step.id)) continue\n const node = nodes.get(step.id)\n if (!node) continue\n rootNodes.push(node)\n placed.add(step.id)\n stack.push(node)\n expand(stack)\n }\n if (!rootNodes.length) return steps.map((step) => ({ ...step }))\n\n const virtualRoot: TreeNode = { id: null, children: rootNodes }\n const [width, height] = nodeSize\n const [gapX, gapY] = gap\n const horizontal = direction === 'horizontal'\n const breadth = horizontal ? height + gapY : width + gapX\n const depth = horizontal ? width + gapX : height + gapY\n const layout = tree<TreeNode>()\n .nodeSize([breadth, depth])\n .separation(() => 1)(hierarchy(virtualRoot, (node) => node.children))\n\n const positions = new Map<string, { x: number; y: number }>()\n for (const node of layout.descendants()) {\n if (node.data.id === null) continue\n const across = node.x - (horizontal ? height : width) / 2\n const along = node.y - depth\n positions.set(\n node.data.id,\n horizontal ? { x: along, y: across } : { x: across, y: along },\n )\n }\n const values = [...positions.values()]\n const minX = Math.min(...values.map((position) => position.x))\n const minY = Math.min(...values.map((position) => position.y))\n\n return steps.map((step) => {\n const position = positions.get(step.id)\n if (!position) return { ...step }\n return {\n ...step,\n position: { x: position.x - minX, y: position.y - minY },\n }\n })\n}\n\nexport function flowRunSummary(\n steps: readonly FlowStep[],\n options: { id?: string } = {},\n): FlowRunSummary {\n const total = steps.length\n const completed = steps.filter(\n (step) => step.run?.status === 'success',\n ).length\n const failed = steps.find((step) => step.run?.status === 'failed')\n const summary = { id: options.id, completed, total }\n if (failed) return { ...summary, status: 'failed', note: failed.run?.note }\n if (steps.some((step) => step.run?.status === 'running'))\n return { ...summary, status: 'running' }\n if (total > 0 && steps.every((step) => step.run?.status === 'skipped'))\n return { ...summary, status: 'skipped' }\n if (\n completed > 0 &&\n steps.every(\n (step) =>\n step.run?.status === 'success' || step.run?.status === 'skipped',\n )\n )\n return { ...summary, status: 'success' }\n if (\n steps.every(\n (step) =>\n !step.run ||\n step.run.status === 'not-run' ||\n step.run.status === 'idle',\n )\n )\n return { ...summary, status: 'not-run' }\n return { ...summary, status: 'idle' }\n}\n",
|
|
9
|
+
"target": "~/packages/ui/src/patterns/flow/canvas/core.ts"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "patterns/flow/inspector/components/inspector-header.tsx",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"content": "import { XIcon } from '@phosphor-icons/react'\nimport { Badge } from '@tc96/ui/badge'\nimport { Button } from '@tc96/ui/button'\nimport { IconFrame } from '@tc96/ui/icon-frame'\nimport type { ReactNode } from 'react'\nimport { useFlowInspectorContext } from '../store/flow-inspector-context'\n\nexport function InspectorHeader({\n actions,\n badge,\n icon,\n title,\n}: Readonly<{\n actions?: ReactNode\n badge?: ReactNode\n icon?: ReactNode\n title: ReactNode\n}>) {\n const { labels, onClose } = useFlowInspectorContext('InspectorHeader')\n return (\n <header\n className=\"flex items-start gap-3 p-4\"\n data-slot=\"flow-inspector-header\"\n >\n {icon ? (\n <IconFrame className=\"mt-0.5\" shape=\"rounded\">\n {icon}\n </IconFrame>\n ) : null}\n <div className=\"flex min-w-0 flex-1 flex-col items-start gap-1\">\n <h2 className=\"max-w-full truncate font-semibold text-base\">{title}</h2>\n {badge ? <Badge variant=\"outline\">{badge}</Badge> : null}\n </div>\n <div className=\"flex shrink-0 items-center gap-1\">\n {actions}\n <Button\n aria-label={labels.close}\n onClick={onClose}\n size=\"icon-sm\"\n variant=\"ghost\"\n >\n <XIcon aria-hidden=\"true\" />\n </Button>\n </div>\n </header>\n )\n}\n",
|
|
15
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/components/inspector-header.tsx"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "patterns/flow/inspector/components/log-entry.tsx",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"content": "import type { FlowLogEntry } from '../core'\nimport { useFlowInspectorLabels } from '../store/flow-inspector-context'\nimport { StatusIcon } from './status-icon'\n\nexport function LogEntry({ entry }: Readonly<{ entry: FlowLogEntry }>) {\n const labels = useFlowInspectorLabels()\n return (\n <li\n className=\"flex gap-2.5 px-4 py-3\"\n data-slot=\"flow-inspector-log-entry\"\n data-status={entry.status}\n >\n <span\n className=\"mt-0.5 inline-flex\"\n role=\"img\"\n aria-label={labels.statuses[entry.status]}\n >\n <StatusIcon status={entry.status} />\n </span>\n <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n <p className=\"flex items-baseline gap-1.5 text-sm\">\n <span className=\"min-w-0 truncate font-medium\">{entry.stepName}</span>\n <span className=\"shrink-0 text-muted-foreground text-xs\">\n #{entry.sequence}\n </span>\n </p>\n {entry.description ? (\n <p className=\"break-words text-muted-foreground text-xs\">\n {entry.description}\n </p>\n ) : null}\n </div>\n </li>\n )\n}\n",
|
|
21
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/components/log-entry.tsx"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "patterns/flow/inspector/components/stat-grid.tsx",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"content": "import { cn } from '@tc96/utils'\nimport type { ReactNode } from 'react'\n\nexport interface StatGridItem {\n label: string\n value: ReactNode\n}\n\nexport function StatGrid({\n className,\n items,\n label,\n}: Readonly<{\n className?: string\n items: readonly StatGridItem[]\n label: string\n}>) {\n return (\n <section\n aria-label={label}\n className={cn('flex flex-col gap-3', className)}\n data-slot=\"flow-inspector-stat-grid\"\n >\n <h3 className=\"font-medium text-sm\">{label}</h3>\n <dl className=\"grid grid-cols-[repeat(auto-fit,minmax(6rem,1fr))] gap-x-4 gap-y-3\">\n {items.map((item) => (\n <div className=\"flex min-w-0 flex-col gap-1\" key={item.label}>\n <dt className=\"text-muted-foreground text-xs\">{item.label}</dt>\n <dd className=\"min-w-0 break-words font-medium text-sm\">\n {item.value}\n </dd>\n </div>\n ))}\n </dl>\n </section>\n )\n}\n",
|
|
27
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/components/stat-grid.tsx"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "patterns/flow/inspector/components/status-icon.tsx",
|
|
31
|
+
"type": "registry:file",
|
|
32
|
+
"content": "import {\n CheckCircleIcon,\n CircleDashedIcon,\n CircleNotchIcon,\n SkipForwardIcon,\n XCircleIcon,\n} from '@phosphor-icons/react'\nimport { cn } from '@tc96/utils'\nimport type { FlowRunStatus } from '../../canvas/core'\nimport { flowStatusIconClassName } from '../lib/variants'\n\nconst icons = {\n failed: XCircleIcon,\n idle: CircleDashedIcon,\n 'not-run': CircleDashedIcon,\n running: CircleNotchIcon,\n skipped: SkipForwardIcon,\n success: CheckCircleIcon,\n} as const\n\nexport function StatusIcon({ status }: Readonly<{ status: FlowRunStatus }>) {\n const Icon = icons[status]\n return (\n <Icon\n aria-hidden=\"true\"\n className={cn('size-4 shrink-0', flowStatusIconClassName[status])}\n data-slot=\"flow-status-icon\"\n data-status={status}\n />\n )\n}\n",
|
|
33
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/components/status-icon.tsx"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "patterns/flow/inspector/composition/flow-inspector-details/flow-inspector-details.tsx",
|
|
37
|
+
"type": "registry:file",
|
|
38
|
+
"content": "'use client'\n\nimport { Avatar, AvatarFallback, AvatarImage } from '@tc96/ui/avatar'\nimport { cn } from '@tc96/utils'\nimport type { ReactNode } from 'react'\nimport { useFlowInspectorLabels } from '../../store/flow-inspector-context'\nimport type { FlowInspectorLabels } from '../../types'\n\nexport interface FlowInspectorDetail {\n id: string\n label: string\n value?: ReactNode\n owner?: { name: string; avatarUrl?: string }\n}\n\nexport interface FlowInspectorDetailsProps {\n className?: string\n items: readonly FlowInspectorDetail[]\n labels?: Partial<FlowInspectorLabels>\n}\n\nfunction initialsOf(name: string) {\n return name\n .split(/\\s+/)\n .filter(Boolean)\n .slice(0, 2)\n .map((part) => part[0]?.toUpperCase())\n .join('')\n}\n\nexport function FlowInspectorDetails({\n className,\n items,\n labels: labelOverrides,\n}: FlowInspectorDetailsProps) {\n const labels = useFlowInspectorLabels(labelOverrides)\n const visible = items.filter(\n (item) => item.owner || (item.value !== undefined && item.value !== null),\n )\n\n return (\n <section\n aria-label={labels.details}\n className={cn('flex flex-col gap-3', className)}\n data-slot=\"flow-inspector-details\"\n >\n <h3 className=\"font-medium text-sm\">{labels.details}</h3>\n <dl className=\"flex flex-col gap-3\">\n {visible.map((item) => (\n <div\n className=\"grid grid-cols-[6.5rem_1fr] items-start gap-3 text-sm\"\n data-slot=\"flow-inspector-detail\"\n key={item.id}\n >\n <dt className=\"text-muted-foreground\">{item.label}</dt>\n <dd className=\"min-w-0 break-words\">\n {item.owner ? (\n <span className=\"flex items-center gap-2\">\n <Avatar className=\"[--avatar-size:--spacing(4)] text-[0.625rem]\">\n {item.owner.avatarUrl ? (\n <AvatarImage alt=\"\" src={item.owner.avatarUrl} />\n ) : null}\n <AvatarFallback className=\"text-foreground\">\n {initialsOf(item.owner.name)}\n </AvatarFallback>\n </Avatar>\n <span className=\"min-w-0 truncate\">{item.owner.name}</span>\n </span>\n ) : (\n item.value\n )}\n </dd>\n </div>\n ))}\n </dl>\n </section>\n )\n}\n",
|
|
39
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/composition/flow-inspector-details/flow-inspector-details.tsx"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "patterns/flow/inspector/composition/flow-inspector-details/index.ts",
|
|
43
|
+
"type": "registry:file",
|
|
44
|
+
"content": "export {\n type FlowInspectorDetail,\n FlowInspectorDetails,\n type FlowInspectorDetailsProps,\n} from './flow-inspector-details'\n",
|
|
45
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/composition/flow-inspector-details/index.ts"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "patterns/flow/inspector/composition/flow-inspector-logs/flow-inspector-logs.tsx",
|
|
49
|
+
"type": "registry:file",
|
|
50
|
+
"content": "'use client'\n\nimport { Button } from '@tc96/ui/button'\nimport {\n Empty,\n EmptyContent,\n EmptyDescription,\n EmptyHeader,\n EmptyTitle,\n} from '@tc96/ui/empty'\nimport { ToggleGroup, ToggleGroupItem } from '@tc96/ui/toggle-group'\nimport { cn } from '@tc96/utils'\nimport { LogEntry } from '../../components/log-entry'\nimport type { FlowLogEntry, FlowLogFilter } from '../../core'\nimport { useFlowInspectorLabels } from '../../store/flow-inspector-context'\nimport type { FlowInspectorLabels } from '../../types'\n\nexport interface FlowInspectorLogsProps {\n className?: string\n emptyActionLabel?: string\n entries: readonly FlowLogEntry[]\n filter: FlowLogFilter\n labels?: Partial<FlowInspectorLabels>\n onEmptyAction?: () => void\n onFilterChange: (filter: FlowLogFilter) => void\n}\n\nexport function FlowInspectorLogs({\n className,\n emptyActionLabel,\n entries,\n filter,\n labels: labelOverrides,\n onEmptyAction,\n onFilterChange,\n}: FlowInspectorLogsProps) {\n const labels = useFlowInspectorLabels(labelOverrides)\n\n return (\n <div\n className={cn('flex flex-col gap-3', className)}\n data-slot=\"flow-inspector-logs\"\n >\n <div className=\"flex flex-wrap items-center justify-between gap-2\">\n <ToggleGroup\n aria-label={labels.logFilter}\n onValueChange={(value) => {\n const next = value[0]\n if (next === 'step' || next === 'all') onFilterChange(next)\n }}\n size=\"sm\"\n value={[filter]}\n variant=\"outline\"\n >\n <ToggleGroupItem value=\"step\">{labels.logThisStep}</ToggleGroupItem>\n <ToggleGroupItem value=\"all\">{labels.logAllSteps}</ToggleGroupItem>\n </ToggleGroup>\n <p className=\"text-muted-foreground text-xs\">\n {labels.logCount(entries.length)}\n </p>\n </div>\n {entries.length ? (\n <ul\n className=\"-mx-4 flex flex-col divide-y border-y\"\n data-slot=\"flow-inspector-log-list\"\n >\n {entries.map((entry) => (\n <LogEntry entry={entry} key={entry.id} />\n ))}\n </ul>\n ) : (\n <Empty className=\"py-8 md:py-10\" data-slot=\"flow-inspector-logs-empty\">\n <EmptyHeader>\n <EmptyTitle className=\"text-base\">\n {labels.logsEmptyTitle}\n </EmptyTitle>\n <EmptyDescription>{labels.logsEmptyDescription}</EmptyDescription>\n </EmptyHeader>\n {onEmptyAction && emptyActionLabel ? (\n <EmptyContent>\n <Button onClick={onEmptyAction} size=\"sm\" variant=\"outline\">\n {emptyActionLabel}\n </Button>\n </EmptyContent>\n ) : null}\n </Empty>\n )}\n </div>\n )\n}\n",
|
|
51
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/composition/flow-inspector-logs/flow-inspector-logs.tsx"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "patterns/flow/inspector/composition/flow-inspector-logs/index.ts",
|
|
55
|
+
"type": "registry:file",
|
|
56
|
+
"content": "export {\n FlowInspectorLogs,\n type FlowInspectorLogsProps,\n} from './flow-inspector-logs'\n",
|
|
57
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/composition/flow-inspector-logs/index.ts"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"path": "patterns/flow/inspector/composition/flow-inspector-status/flow-inspector-status.tsx",
|
|
61
|
+
"type": "registry:file",
|
|
62
|
+
"content": "'use client'\n\nimport { Badge } from '@tc96/ui/badge'\nimport { cn } from '@tc96/utils'\nimport type { FlowRunStatus } from '../../../canvas/core'\nimport { StatGrid, type StatGridItem } from '../../components/stat-grid'\nimport { StatusIcon } from '../../components/status-icon'\nimport {\n type FlowStepStats,\n flowStepAbandonment,\n formatFlowDuration,\n} from '../../core'\nimport { flowStatusBadgeVariant } from '../../lib/variants'\nimport { useFlowInspectorLabels } from '../../store/flow-inspector-context'\nimport type { FlowInspectorLabels } from '../../types'\n\nexport interface FlowInspectorStatusProps {\n className?: string\n durationMs?: number\n labels?: Partial<FlowInspectorLabels>\n runId?: string\n stats?: FlowStepStats\n status?: FlowRunStatus\n}\n\nexport function FlowInspectorStatus({\n className,\n durationMs,\n labels: labelOverrides,\n runId,\n stats,\n status,\n}: FlowInspectorStatusProps) {\n const labels = useFlowInspectorLabels(labelOverrides)\n const duration = formatFlowDuration(durationMs)\n const abandonment = stats ? flowStepAbandonment(stats) : null\n const reached = Boolean(status && status !== 'not-run' && status !== 'idle')\n\n const lastRun: StatGridItem[] = []\n if (status)\n lastRun.push({\n label: labels.state,\n value: (\n <Badge variant={flowStatusBadgeVariant[status]}>\n <StatusIcon status={status} />\n {labels.statuses[status]}\n </Badge>\n ),\n })\n if (duration) lastRun.push({ label: labels.duration, value: duration })\n if (runId) lastRun.push({ label: labels.run, value: runId })\n\n const testRuns: StatGridItem[] = []\n if (stats) {\n testRuns.push(\n { label: labels.entered, value: stats.entered },\n { label: labels.completed, value: stats.completed },\n {\n label: labels.abandonment,\n value: abandonment === null ? labels.empty : `${abandonment}%`,\n },\n )\n }\n\n return (\n <div\n className={cn('flex flex-col gap-6', className)}\n data-slot=\"flow-inspector-status\"\n >\n {lastRun.length ? (\n <StatGrid items={lastRun} label={labels.lastRun} />\n ) : null}\n {testRuns.length ? (\n <StatGrid items={testRuns} label={labels.testRuns} />\n ) : null}\n {!reached && !stats?.entered ? (\n <p\n className=\"text-muted-foreground text-sm\"\n data-slot=\"flow-inspector-status-note\"\n >\n {labels.noRunNote}\n </p>\n ) : null}\n </div>\n )\n}\n",
|
|
63
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/composition/flow-inspector-status/flow-inspector-status.tsx"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "patterns/flow/inspector/composition/flow-inspector-status/index.ts",
|
|
67
|
+
"type": "registry:file",
|
|
68
|
+
"content": "export {\n FlowInspectorStatus,\n type FlowInspectorStatusProps,\n} from './flow-inspector-status'\n",
|
|
69
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/composition/flow-inspector-status/index.ts"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "patterns/flow/inspector/composition/flow-inspector/flow-inspector.tsx",
|
|
73
|
+
"type": "registry:file",
|
|
74
|
+
"content": "'use client'\n\nimport { WarningIcon } from '@phosphor-icons/react'\nimport { Alert, AlertDescription, AlertTitle } from '@tc96/ui/alert'\nimport { ScrollArea } from '@tc96/ui/scroll-area'\nimport { Sheet, SheetPopup } from '@tc96/ui/sheet'\nimport { Tabs, TabsList, TabsPanel, TabsTab } from '@tc96/ui/tabs'\nimport { cn } from '@tc96/utils'\nimport { type CSSProperties, type ReactNode, useMemo } from 'react'\nimport { InspectorHeader } from '../../components/inspector-header'\nimport { type FlowInspectorTab, flowInspectorTabs } from '../../core'\nimport { useInspectorDock } from '../../hooks/use-inspector-dock'\nimport { defaultFlowInspectorLabels } from '../../lib/labels'\nimport { FlowInspectorContext } from '../../store/flow-inspector-context'\nimport type { FlowInspectorLabels } from '../../types'\n\nexport interface FlowInspectorProps {\n badge?: ReactNode\n build?: ReactNode\n children?: ReactNode\n className?: string\n disabledTabs?: readonly FlowInspectorTab[]\n headerActions?: ReactNode\n icon?: ReactNode\n labels?: Partial<FlowInspectorLabels>\n logs?: ReactNode\n onClose: () => void\n onTabChange: (tab: FlowInspectorTab) => void\n open: boolean\n status?: ReactNode\n tab: FlowInspectorTab\n title: ReactNode\n unconnected?: boolean\n width?: string\n}\n\nfunction isTab(value: unknown): value is FlowInspectorTab {\n return flowInspectorTabs.some((tab) => tab === value)\n}\n\nexport function FlowInspector({\n badge,\n build,\n children,\n className,\n disabledTabs = [],\n headerActions,\n icon,\n labels: labelOverrides,\n logs,\n onClose,\n onTabChange,\n open,\n status,\n tab,\n title,\n unconnected = false,\n width = '24rem',\n}: FlowInspectorProps) {\n const docked = useInspectorDock()\n const labels = useMemo(\n () => ({ ...defaultFlowInspectorLabels, ...labelOverrides }),\n [labelOverrides],\n )\n const context = useMemo(() => ({ labels, onClose }), [labels, onClose])\n const panels: Record<FlowInspectorTab, ReactNode> = { build, logs, status }\n\n const body = (\n <div\n className=\"flex h-full min-h-0 w-full flex-col\"\n data-slot=\"flow-inspector-body\"\n >\n <InspectorHeader\n actions={headerActions}\n badge={badge}\n icon={icon}\n title={title}\n />\n <Tabs\n className=\"min-h-0 flex-1 gap-0\"\n onValueChange={(value) => {\n if (isTab(value)) onTabChange(value)\n }}\n value={tab}\n >\n <div className=\"border-b px-4\">\n <TabsList\n aria-label={labels.tabsLabel}\n className=\"w-full justify-start py-0\"\n variant=\"underline\"\n >\n {flowInspectorTabs.map((item) => (\n <TabsTab\n className=\"grow-0\"\n disabled={disabledTabs.includes(item)}\n key={item}\n value={item}\n >\n {labels.tabs[item]}\n </TabsTab>\n ))}\n </TabsList>\n </div>\n <ScrollArea className=\"flex-1\" scrollFade>\n {flowInspectorTabs.map((item) => (\n <TabsPanel\n className=\"flex flex-col gap-4 p-4\"\n key={item}\n value={item}\n >\n {item === 'build' && unconnected ? (\n <Alert\n className=\"[&>svg]:text-warning-foreground\"\n variant=\"warning\"\n >\n <WarningIcon aria-hidden=\"true\" />\n <AlertTitle>{labels.unconnectedTitle}</AlertTitle>\n <AlertDescription>\n {labels.unconnectedDescription}\n </AlertDescription>\n </Alert>\n ) : null}\n {panels[item]}\n </TabsPanel>\n ))}\n </ScrollArea>\n </Tabs>\n {children ? (\n <footer\n className=\"flex shrink-0 flex-wrap items-center justify-end gap-2 border-t p-4\"\n data-slot=\"flow-inspector-footer\"\n >\n {children}\n </footer>\n ) : null}\n </div>\n )\n\n if (!docked) {\n return (\n <FlowInspectorContext.Provider value={context}>\n <Sheet\n onOpenChange={(next) => {\n if (!next) onClose()\n }}\n open={open}\n >\n <SheetPopup\n aria-label={labels.title}\n className=\"p-0\"\n data-slot=\"flow-inspector\"\n showCloseButton={false}\n >\n {body}\n </SheetPopup>\n </Sheet>\n </FlowInspectorContext.Provider>\n )\n }\n\n return (\n <FlowInspectorContext.Provider value={context}>\n <aside\n aria-label={labels.title}\n className={cn(\n 'relative h-full shrink-0 overflow-hidden border-s bg-background transition-[width] duration-200 ease-in-out motion-reduce:transition-none',\n open ? 'w-(--flow-inspector-width)' : 'w-0 border-s-0',\n className,\n )}\n data-docked={open ? 'true' : 'false'}\n data-slot=\"flow-inspector\"\n inert={!open}\n style={{ '--flow-inspector-width': width } as CSSProperties}\n >\n <div className=\"h-full w-(--flow-inspector-width)\">{body}</div>\n </aside>\n </FlowInspectorContext.Provider>\n )\n}\n",
|
|
75
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/composition/flow-inspector/flow-inspector.tsx"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"path": "patterns/flow/inspector/composition/flow-inspector/index.ts",
|
|
79
|
+
"type": "registry:file",
|
|
80
|
+
"content": "export { FlowInspector, type FlowInspectorProps } from './flow-inspector'\n",
|
|
81
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/composition/flow-inspector/index.ts"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"path": "patterns/flow/inspector/composition/index.ts",
|
|
85
|
+
"type": "registry:file",
|
|
86
|
+
"content": "export * from './flow-inspector/index'\nexport * from './flow-inspector-details/index'\nexport * from './flow-inspector-logs/index'\nexport * from './flow-inspector-status/index'\n",
|
|
87
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/composition/index.ts"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"path": "patterns/flow/inspector/core.ts",
|
|
91
|
+
"type": "registry:file",
|
|
92
|
+
"content": "import type { FlowRunStatus } from '../canvas/core'\n\nexport type FlowInspectorTab = 'build' | 'status' | 'logs'\nexport type FlowLogFilter = 'step' | 'all'\n\nexport const flowInspectorTabs: readonly FlowInspectorTab[] = [\n 'build',\n 'status',\n 'logs',\n]\n\nexport interface FlowLogEntry {\n id: string\n stepId: string\n stepName: string\n status: FlowRunStatus\n sequence: number\n description?: string\n}\n\nexport interface FlowStepStats {\n entered: number\n completed: number\n}\n\nexport function flowStepAbandonment(stats: FlowStepStats): number | null {\n if (stats.entered <= 0) return null\n const abandoned = Math.max(stats.entered - stats.completed, 0)\n return Math.round((abandoned / stats.entered) * 100)\n}\n\nexport function formatFlowDuration(durationMs: number | undefined) {\n if (durationMs === undefined || durationMs < 0) return null\n if (durationMs < 1000) return `${Math.round(durationMs)} ms`\n const seconds = durationMs / 1000\n if (seconds < 60)\n return `${seconds.toFixed(seconds < 10 ? 1 : 0).replace('.', ',')} s`\n const minutes = Math.floor(seconds / 60)\n return `${minutes} min ${Math.round(seconds - minutes * 60)} s`\n}\n",
|
|
93
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/core.ts"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"path": "patterns/flow/inspector/hooks/use-inspector-dock.ts",
|
|
97
|
+
"type": "registry:file",
|
|
98
|
+
"content": "import { useMediaQuery } from '@tc96/ui/hooks/use-media-query'\n\nexport function useInspectorDock() {\n return useMediaQuery('md')\n}\n",
|
|
99
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/hooks/use-inspector-dock.ts"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"path": "patterns/flow/inspector/index.ts",
|
|
103
|
+
"type": "registry:file",
|
|
104
|
+
"content": "export * from './composition/index'\nexport type {\n FlowInspectorTab,\n FlowLogEntry,\n FlowLogFilter,\n FlowStepStats,\n} from './core'\nexport {\n flowInspectorTabs,\n flowStepAbandonment,\n formatFlowDuration,\n} from './core'\nexport { defaultFlowInspectorLabels } from './lib/labels'\nexport type { FlowInspectorLabels } from './types'\n",
|
|
105
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/index.ts"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"path": "patterns/flow/inspector/lib/labels.ts",
|
|
109
|
+
"type": "registry:file",
|
|
110
|
+
"content": "import type { FlowInspectorLabels } from '../types'\n\nexport const defaultFlowInspectorLabels: FlowInspectorLabels = {\n abandonment: 'Abandono',\n close: 'Fechar detalhes do passo',\n completed: 'Concluídas',\n details: 'Detalhes',\n duration: 'Duração',\n empty: '—',\n entered: 'Entradas',\n lastRun: 'Última execução',\n logAllSteps: 'Todos os passos',\n logCount: (count) => (count === 1 ? '1 entrada' : `${count} entradas`),\n logFilter: 'Filtrar logs',\n logThisStep: 'Este passo',\n logsEmptyDescription: 'Execute o fluxo para ver o que cada passo registra.',\n logsEmptyTitle: 'Sem logs ainda',\n noRunNote: 'Nenhuma execução chegou a este passo.',\n run: 'Execução',\n state: 'Estado',\n statuses: {\n failed: 'Falhou',\n idle: 'Ocioso',\n 'not-run': 'Não executado',\n running: 'Executando',\n skipped: 'Ignorado',\n success: 'Sucesso',\n },\n tabs: { build: 'Build', logs: 'Logs', status: 'Status' },\n tabsLabel: 'Seções do passo',\n testRuns: 'Execuções de teste',\n title: 'Detalhes do passo',\n unconnectedDescription: 'Conecte um passo a este.',\n unconnectedTitle: 'Nada chega a este passo.',\n}\n",
|
|
111
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/lib/labels.ts"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"path": "patterns/flow/inspector/lib/variants.ts",
|
|
115
|
+
"type": "registry:file",
|
|
116
|
+
"content": "import type { FlowRunStatus } from '../../canvas/core'\n\nexport const flowStatusBadgeVariant = {\n failed: 'destructive',\n idle: 'outline',\n 'not-run': 'outline',\n running: 'outline',\n skipped: 'secondary',\n success: 'outline',\n} as const satisfies Record<FlowRunStatus, string>\n\nexport const flowStatusIconClassName = {\n failed: 'text-destructive-foreground',\n idle: 'text-muted-foreground',\n 'not-run': 'text-muted-foreground',\n running: 'text-muted-foreground motion-safe:animate-spin',\n skipped: 'text-muted-foreground',\n success: 'text-muted-foreground',\n} as const satisfies Record<FlowRunStatus, string>\n",
|
|
117
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/lib/variants.ts"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"path": "patterns/flow/inspector/store/flow-inspector-context.ts",
|
|
121
|
+
"type": "registry:file",
|
|
122
|
+
"content": "import { createContext, useContext } from 'react'\nimport { defaultFlowInspectorLabels } from '../lib/labels'\nimport type { FlowInspectorLabels } from '../types'\n\nexport interface FlowInspectorContextValue {\n labels: FlowInspectorLabels\n onClose: () => void\n}\n\nexport const FlowInspectorContext = createContext<\n FlowInspectorContextValue | undefined\n>(undefined)\n\nexport function useFlowInspectorLabels(\n labels?: Partial<FlowInspectorLabels>,\n): FlowInspectorLabels {\n const context = useContext(FlowInspectorContext)\n return { ...(context?.labels ?? defaultFlowInspectorLabels), ...labels }\n}\n\nexport function useFlowInspectorContext(\n component: string,\n): FlowInspectorContextValue {\n const context = useContext(FlowInspectorContext)\n if (!context)\n throw new Error(`${component} must be used inside a FlowInspector.`)\n return context\n}\n",
|
|
123
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/store/flow-inspector-context.ts"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"path": "patterns/flow/inspector/types/index.ts",
|
|
127
|
+
"type": "registry:file",
|
|
128
|
+
"content": "import type { FlowRunStatus } from '../../canvas/core'\nimport type { FlowInspectorTab } from '../core'\n\nexport interface FlowInspectorLabels {\n title: string\n close: string\n tabsLabel: string\n tabs: Record<FlowInspectorTab, string>\n details: string\n lastRun: string\n state: string\n duration: string\n run: string\n testRuns: string\n entered: string\n completed: string\n abandonment: string\n noRunNote: string\n statuses: Record<FlowRunStatus, string>\n logFilter: string\n logThisStep: string\n logAllSteps: string\n logCount: (count: number) => string\n logsEmptyTitle: string\n logsEmptyDescription: string\n unconnectedTitle: string\n unconnectedDescription: string\n empty: string\n}\n",
|
|
129
|
+
"target": "~/packages/ui/src/patterns/flow/inspector/types/index.ts"
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
"dependencies": [
|
|
133
|
+
"@phosphor-icons/react@2.1.10",
|
|
134
|
+
"d3-hierarchy@3.1.2",
|
|
135
|
+
"react@19.1.1"
|
|
136
|
+
],
|
|
137
|
+
"registryDependencies": [
|
|
138
|
+
"@ui/alert",
|
|
139
|
+
"@ui/avatar",
|
|
140
|
+
"@ui/badge",
|
|
141
|
+
"@ui/button",
|
|
142
|
+
"@ui/empty",
|
|
143
|
+
"@ui/icon-frame",
|
|
144
|
+
"@ui/scroll-area",
|
|
145
|
+
"@ui/sheet",
|
|
146
|
+
"@ui/tabs",
|
|
147
|
+
"@ui/toggle-group",
|
|
148
|
+
"@ui/use-media-query"
|
|
149
|
+
],
|
|
150
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
151
|
+
}
|