@locusgraph/loop 0.1.0 → 0.2.1

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.
Files changed (115) hide show
  1. package/README.md +2 -0
  2. package/dist/agent/pulse/gradient-label.js +36 -15
  3. package/dist/agent/pulse/marks/bars-mark.js +24 -10
  4. package/dist/agent/pulse/marks/glyph-mark.js +17 -11
  5. package/dist/agent/pulse/marks/locus-mark.js +39 -28
  6. package/dist/agent/pulse/marks/orb-mark.js +21 -8
  7. package/dist/agent/pulse/marks/spinner-mark.js +20 -1
  8. package/dist/agent/pulse/pulse.js +63 -35
  9. package/dist/agent/pulse/use-loop-animation.js +14 -16
  10. package/dist/agent/steps/step-icon.js +40 -24
  11. package/dist/agent/steps/steps.js +72 -25
  12. package/dist/agent/thinking/thinking.js +203 -23
  13. package/dist/agent/thinking/thought-duration.js +7 -9
  14. package/dist/agent/tool/json-block.js +18 -11
  15. package/dist/agent/tool/tool-status.js +28 -18
  16. package/dist/agent/tool/tool.js +184 -6
  17. package/dist/approval/inbox/inbox-row.d.ts +3 -2
  18. package/dist/approval/inbox/inbox-row.js +96 -7
  19. package/dist/approval/inbox/inbox-selection.js +7 -13
  20. package/dist/approval/inbox/inbox.d.ts +2 -1
  21. package/dist/approval/inbox/inbox.js +99 -18
  22. package/dist/approval/inbox/virtual-inbox-list.d.ts +13 -0
  23. package/dist/approval/inbox/virtual-inbox-list.js +53 -0
  24. package/dist/approval/memory/memory-choices.js +27 -22
  25. package/dist/approval/memory/memory-review.js +108 -17
  26. package/dist/approval/memory/memory-row.js +80 -19
  27. package/dist/approval/plan/plan-review.js +129 -28
  28. package/dist/approval/plan/plan-step-row.js +91 -44
  29. package/dist/approval/plan/plan-steps.js +24 -23
  30. package/dist/approval/plan/question-choices.js +73 -40
  31. package/dist/approval/plan/question.d.ts +1 -1
  32. package/dist/approval/plan/question.js +108 -27
  33. package/dist/approval/run/run-bar.js +94 -22
  34. package/dist/approval/shared/decision-line.js +1 -1
  35. package/dist/approval/shared/risk-badge.js +32 -16
  36. package/dist/approval/shared/time.js +5 -8
  37. package/dist/approval/shared/use-focus-on-mount.js +7 -6
  38. package/dist/approval/spend/raise-cap-form.js +64 -19
  39. package/dist/approval/spend/spend-gate.js +124 -21
  40. package/dist/approval/spend/spend-math.js +7 -8
  41. package/dist/approval/spend/spend-meter.js +136 -35
  42. package/dist/approval/tool/approval.js +113 -27
  43. package/dist/approval/tool/args/args-editor.js +104 -26
  44. package/dist/approval/tool/args/args-field.js +79 -22
  45. package/dist/approval/tool/args/args-validation.js +38 -47
  46. package/dist/approval/tool/deny-form.js +43 -10
  47. package/dist/approval/tool/tool-inputs.js +62 -38
  48. package/dist/chat/chat/chat-item-spacing.d.ts +3 -0
  49. package/dist/chat/chat/chat-item-spacing.js +19 -0
  50. package/dist/chat/chat/chat.d.ts +2 -1
  51. package/dist/chat/chat/chat.js +181 -5
  52. package/dist/chat/chat/use-stick-to-bottom.js +71 -48
  53. package/dist/chat/chat/virtual-chat-items.d.ts +8 -0
  54. package/dist/chat/chat/virtual-chat-items.js +60 -0
  55. package/dist/chat/composer/composer-actions.js +69 -17
  56. package/dist/chat/composer/composer.js +330 -32
  57. package/dist/chat/composer/use-auto-grow.js +9 -9
  58. package/dist/chat/files/file-meta.js +19 -19
  59. package/dist/chat/files/files.js +92 -29
  60. package/dist/chat/reply/fenced-code.js +23 -21
  61. package/dist/chat/reply/markdown-components.js +137 -17
  62. package/dist/chat/reply/reply.js +30 -10
  63. package/dist/chat/turn/group-parts.js +43 -29
  64. package/dist/chat/turn/turn.js +87 -30
  65. package/dist/cost/context.js +104 -23
  66. package/dist/cost/cost-steps.js +67 -14
  67. package/dist/cost/cost.js +128 -23
  68. package/dist/cost/model-picker.js +51 -6
  69. package/dist/cost/shared/context-breakdown.js +83 -10
  70. package/dist/cost/shared/meter-marks.js +49 -9
  71. package/dist/cost/shared/model-option-row.js +56 -22
  72. package/dist/cost/shared/step-cost-row.js +65 -22
  73. package/dist/cost/shared/usage-totals.js +22 -18
  74. package/dist/memory/cite.js +62 -12
  75. package/dist/memory/memorized.js +65 -11
  76. package/dist/memory/recall.js +101 -17
  77. package/dist/memory/shared/host-label.js +19 -22
  78. package/dist/memory/shared/source-mark.js +11 -3
  79. package/dist/memory/sources.js +78 -14
  80. package/dist/shared/decision-summary.js +51 -14
  81. package/dist/shared/panel-empty.js +20 -3
  82. package/dist/shared/panel.js +69 -13
  83. package/dist/shared/status-dot.js +16 -8
  84. package/dist/shared/virtual/use-list-virtualizer.d.ts +24 -0
  85. package/dist/shared/virtual/use-list-virtualizer.js +68 -0
  86. package/dist/thread/actions/action-button.js +22 -3
  87. package/dist/thread/actions/actions.js +184 -13
  88. package/dist/thread/actions/branch-switcher.js +28 -5
  89. package/dist/thread/canvas/canvas.js +205 -5
  90. package/dist/thread/canvas/version-switcher.js +54 -8
  91. package/dist/thread/code/code.js +186 -24
  92. package/dist/thread/code/copy-code-button.js +30 -14
  93. package/dist/thread/code/highlight.js +30 -29
  94. package/dist/thread/history/history-rows.d.ts +16 -0
  95. package/dist/thread/history/history-rows.js +23 -0
  96. package/dist/thread/history/history.d.ts +3 -2
  97. package/dist/thread/history/history.js +174 -5
  98. package/dist/thread/history/{history-row.d.ts → row/history-row.d.ts} +3 -2
  99. package/dist/thread/history/row/history-row.js +58 -0
  100. package/dist/thread/history/row/thread-item-menu.js +31 -0
  101. package/dist/thread/history/row/thread-title-editor.js +38 -0
  102. package/dist/thread/history/thread-groups.d.ts +1 -1
  103. package/dist/thread/history/thread-groups.js +40 -34
  104. package/dist/thread/history/virtual-history-list.d.ts +11 -0
  105. package/dist/thread/history/virtual-history-list.js +71 -0
  106. package/dist/thread/index.d.ts +1 -1
  107. package/dist/thread/starters/starters.js +33 -8
  108. package/dist/thread/use-copied.js +18 -16
  109. package/dist/types.js +1 -1
  110. package/package.json +6 -4
  111. package/dist/thread/history/history-row.js +0 -17
  112. package/dist/thread/history/thread-item-menu.js +0 -6
  113. package/dist/thread/history/thread-title-editor.js +0 -25
  114. /package/dist/thread/history/{thread-item-menu.d.ts → row/thread-item-menu.d.ts} +0 -0
  115. /package/dist/thread/history/{thread-title-editor.d.ts → row/thread-title-editor.d.ts} +0 -0
@@ -1,38 +1,139 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
1
  import { ArrowRight as ArrowRightIcon, ListChecked as ListChecksIcon } from "@carbon/icons-react";
3
2
  import { Button } from "@locusgraph/components";
4
3
  import { pluralize } from "@locusgraph/utils";
5
4
  import { useEffect, useId, useState } from "react";
6
- import { ApprovalPanel, LiveStatus, PanelBody, PanelFooter, PanelHeader, PanelTitle, } from "../../shared/panel.js";
5
+ import { ApprovalPanel, LiveStatus, PanelBody, PanelFooter, PanelHeader, PanelTitle } from "../../shared/panel.js";
7
6
  import { DecisionSummary } from "../shared/decision-line.js";
8
7
  import { useFocusOnMount } from "../shared/use-focus-on-mount.js";
9
8
  import { PlanStepRow, stepControlId } from "./plan-step-row.js";
10
9
  import { applyStepAction, describeStepAction, focusAfterAction } from "./plan-steps.js";
11
- function DecidedSteps({ steps }) {
12
- return (_jsx("ol", { className: "flex flex-col gap-1 pl-6.5 text-sm text-muted-foreground", children: steps.map((step, position) => (_jsxs("li", { className: "flex gap-3", children: [_jsx("span", { className: "w-4 shrink-0 font-mono text-xs leading-5 tabular-nums", children: position + 1 }), _jsx("span", { className: "min-w-0", children: step.title })] }, step.id))) }));
10
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
+ function DecidedSteps({
12
+ steps
13
+ }) {
14
+ return /*#__PURE__*/_jsx("ol", {
15
+ className: "flex flex-col gap-1 pl-6.5 text-sm text-muted-foreground",
16
+ children: steps.map((step, position) => /*#__PURE__*/_jsxs("li", {
17
+ className: "flex gap-3",
18
+ children: [/*#__PURE__*/_jsx("span", {
19
+ className: "w-4 shrink-0 font-mono text-xs leading-5 tabular-nums",
20
+ children: position + 1
21
+ }), /*#__PURE__*/_jsx("span", {
22
+ className: "min-w-0",
23
+ children: step.title
24
+ })]
25
+ }, step.id))
26
+ });
13
27
  }
14
- export function PlanReview({ steps: initialSteps, title = "Review the plan", description = "The agent will run these steps in order. Edit, reorder or remove steps before it starts.", actionLabel, decision, onApprove, onCancel, autoFocus = true, className, }) {
15
- const idPrefix = useId();
16
- const [steps, setSteps] = useState(initialSteps);
17
- const [announcement, setAnnouncement] = useState("");
18
- const [pendingFocus, setPendingFocus] = useState(null);
19
- const approveRef = useFocusOnMount(autoFocus && !decision);
20
- const hasBlankTitle = steps.some((step) => step.title.trim() === "");
21
- useEffect(() => {
22
- if (pendingFocus)
23
- document.getElementById(pendingFocus.id)?.focus();
24
- }, [pendingFocus]);
25
- function handleAction(stepId, position, action) {
26
- const next = applyStepAction(steps, stepId, action);
27
- const focus = focusAfterAction(next, stepId, action);
28
- setSteps(next);
29
- setAnnouncement(describeStepAction(position, action));
30
- setPendingFocus(focus ? { id: stepControlId(idPrefix, focus.stepId, focus.control) } : null);
31
- }
32
- function renameStep(stepId, nextTitle) {
33
- setSteps((current) => current.map((item) => (item.id === stepId ? { ...item, title: nextTitle } : item)));
34
- }
35
- return (_jsxs(ApprovalPanel, { "data-slot": "plan-review", "data-decided": decision ? true : undefined, "aria-label": title, className: className, children: [_jsx(PanelHeader, { icon: _jsx(ListChecksIcon, { "aria-hidden": true }), eyebrow: "Plan", status: decision ? (decision.approved ? "Approved" : "Cancelled") : "Waiting for you", tone: decision ? (decision.approved ? "done" : "danger") : "waiting", aside: pluralize(steps.length, "step") }), _jsx(PanelTitle, { className: decision ? "text-muted-foreground" : undefined, children: title }), decision ? (_jsxs(PanelBody, { children: [_jsx(DecisionSummary, { decision: decision, deniedVerb: "Cancelled", result: decision.approved
36
- ? `${pluralize(initialSteps.length, "step")} approved`
37
- : "Plan cancelled" }), _jsx(DecidedSteps, { steps: initialSteps })] })) : (_jsxs(_Fragment, { children: [_jsx("p", { className: "px-5 pt-1 text-sm text-muted-foreground", children: description }), _jsx(PanelBody, { className: "pb-0", children: _jsx("ol", { className: "-mx-5 flex flex-col divide-y border-t", children: steps.map((step, position) => (_jsx(PlanStepRow, { idPrefix: idPrefix, step: step, position: position, count: steps.length, onRename: (nextTitle) => renameStep(step.id, nextTitle), onAction: (action) => handleAction(step.id, position, action) }, step.id))) }) }), _jsxs(PanelFooter, { className: "justify-between", children: [hasBlankTitle ? (_jsx("span", { className: "text-xs text-destructive", children: "Every step needs a title." })) : (_jsx("span", { className: "hidden font-mono text-[11px] text-muted-foreground sm:inline", children: "The run starts when you approve" })), _jsxs("span", { className: "ml-auto flex gap-2", children: [_jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: onCancel, children: "Cancel" }), _jsxs(Button, { ref: approveRef, type: "button", size: "sm", disabled: hasBlankTitle || steps.length === 0, onClick: () => onApprove(steps.map((step) => ({ ...step, title: step.title.trim() }))), children: [actionLabel ?? `Run ${pluralize(steps.length, "step")}`, _jsx(ArrowRightIcon, { "aria-hidden": true })] })] })] })] })), _jsx(LiveStatus, { message: decision ? (decision.approved ? "Plan approved" : "Plan cancelled") : announcement })] }));
28
+ export function PlanReview({
29
+ steps: initialSteps,
30
+ title = "Review the plan",
31
+ description = "The agent will run these steps in order. Edit, reorder or remove steps before it starts.",
32
+ actionLabel,
33
+ decision,
34
+ onApprove,
35
+ onCancel,
36
+ autoFocus = true,
37
+ className
38
+ }) {
39
+ const idPrefix = useId();
40
+ const [steps, setSteps] = useState(initialSteps);
41
+ const [announcement, setAnnouncement] = useState("");
42
+ const [pendingFocus, setPendingFocus] = useState(null);
43
+ const approveRef = useFocusOnMount(autoFocus && !decision);
44
+ const hasBlankTitle = steps.some(step => step.title.trim() === "");
45
+ useEffect(() => {
46
+ if (pendingFocus) document.getElementById(pendingFocus.id)?.focus();
47
+ }, [pendingFocus]);
48
+ function handleAction(stepId, position, action) {
49
+ const next = applyStepAction(steps, stepId, action);
50
+ const focus = focusAfterAction(next, stepId, action);
51
+ setSteps(next);
52
+ setAnnouncement(describeStepAction(position, action));
53
+ setPendingFocus(focus ? {
54
+ id: stepControlId(idPrefix, focus.stepId, focus.control)
55
+ } : null);
56
+ }
57
+ function renameStep(stepId, nextTitle) {
58
+ setSteps(current => current.map(item => item.id === stepId ? {
59
+ ...item,
60
+ title: nextTitle
61
+ } : item));
62
+ }
63
+ return /*#__PURE__*/_jsxs(ApprovalPanel, {
64
+ "data-slot": "plan-review",
65
+ "data-decided": decision ? true : undefined,
66
+ "aria-label": title,
67
+ className: className,
68
+ children: [/*#__PURE__*/_jsx(PanelHeader, {
69
+ icon: /*#__PURE__*/_jsx(ListChecksIcon, {
70
+ "aria-hidden": true
71
+ }),
72
+ eyebrow: "Plan",
73
+ status: decision ? decision.approved ? "Approved" : "Cancelled" : "Waiting for you",
74
+ tone: decision ? decision.approved ? "done" : "danger" : "waiting",
75
+ aside: pluralize(steps.length, "step")
76
+ }), /*#__PURE__*/_jsx(PanelTitle, {
77
+ className: decision ? "text-muted-foreground" : undefined,
78
+ children: title
79
+ }), decision ? /*#__PURE__*/_jsxs(PanelBody, {
80
+ children: [/*#__PURE__*/_jsx(DecisionSummary, {
81
+ decision: decision,
82
+ deniedVerb: "Cancelled",
83
+ result: decision.approved ? `${pluralize(initialSteps.length, "step")} approved` : "Plan cancelled"
84
+ }), /*#__PURE__*/_jsx(DecidedSteps, {
85
+ steps: initialSteps
86
+ })]
87
+ }) : /*#__PURE__*/_jsxs(_Fragment, {
88
+ children: [/*#__PURE__*/_jsx("p", {
89
+ className: "px-5 pt-1 text-sm text-muted-foreground",
90
+ children: description
91
+ }), /*#__PURE__*/_jsx(PanelBody, {
92
+ className: "pb-0",
93
+ children: /*#__PURE__*/_jsx("ol", {
94
+ className: "-mx-5 flex flex-col divide-y border-t",
95
+ children: steps.map((step, position) => /*#__PURE__*/_jsx(PlanStepRow, {
96
+ idPrefix: idPrefix,
97
+ step: step,
98
+ position: position,
99
+ count: steps.length,
100
+ onRename: nextTitle => renameStep(step.id, nextTitle),
101
+ onAction: action => handleAction(step.id, position, action)
102
+ }, step.id))
103
+ })
104
+ }), /*#__PURE__*/_jsxs(PanelFooter, {
105
+ className: "justify-between",
106
+ children: [hasBlankTitle ? /*#__PURE__*/_jsx("span", {
107
+ className: "text-xs text-destructive",
108
+ children: "Every step needs a title."
109
+ }) : /*#__PURE__*/_jsx("span", {
110
+ className: "hidden font-mono text-[11px] text-muted-foreground sm:inline",
111
+ children: "The run starts when you approve"
112
+ }), /*#__PURE__*/_jsxs("span", {
113
+ className: "ml-auto flex gap-2",
114
+ children: [/*#__PURE__*/_jsx(Button, {
115
+ type: "button",
116
+ size: "sm",
117
+ variant: "ghost",
118
+ onClick: onCancel,
119
+ children: "Cancel"
120
+ }), /*#__PURE__*/_jsxs(Button, {
121
+ ref: approveRef,
122
+ type: "button",
123
+ size: "sm",
124
+ disabled: hasBlankTitle || steps.length === 0,
125
+ onClick: () => onApprove(steps.map(step => ({
126
+ ...step,
127
+ title: step.title.trim()
128
+ }))),
129
+ children: [actionLabel ?? `Run ${pluralize(steps.length, "step")}`, /*#__PURE__*/_jsx(ArrowRightIcon, {
130
+ "aria-hidden": true
131
+ })]
132
+ })]
133
+ })]
134
+ })]
135
+ }), /*#__PURE__*/_jsx(LiveStatus, {
136
+ message: decision ? decision.approved ? "Plan approved" : "Plan cancelled" : announcement
137
+ })]
138
+ });
38
139
  }
@@ -1,50 +1,97 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { ArrowDown as ArrowDownIcon, ArrowUp as ArrowUpIcon, Edit as PencilIcon, TrashCan as Trash2Icon, } from "@carbon/icons-react";
1
+ import { ArrowDown as ArrowDownIcon, ArrowUp as ArrowUpIcon, Edit as PencilIcon, TrashCan as Trash2Icon } from "@carbon/icons-react";
3
2
  import { Button, cn } from "@locusgraph/components";
3
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
4
  export function stepControlId(idPrefix, stepId, action) {
5
- return `${idPrefix}-${stepId}-${action}`;
5
+ return `${idPrefix}-${stepId}-${action}`;
6
6
  }
7
7
  function selectInputById(id) {
8
- const element = document.getElementById(id);
9
- if (element instanceof HTMLInputElement) {
10
- element.focus();
11
- element.select();
12
- }
8
+ const element = document.getElementById(id);
9
+ if (element instanceof HTMLInputElement) {
10
+ element.focus();
11
+ element.select();
12
+ }
13
13
  }
14
- export function PlanStepRow({ idPrefix, step, position, count, onRename, onAction, }) {
15
- const number = position + 1;
16
- const titleId = stepControlId(idPrefix, step.id, "title");
17
- const blank = step.title.trim() === "";
18
- const controls = [
19
- {
20
- id: `${idPrefix}-${step.id}-edit`,
21
- label: `Edit step ${number}`,
22
- icon: PencilIcon,
23
- disabled: false,
24
- onClick: () => selectInputById(titleId),
25
- },
26
- {
27
- id: stepControlId(idPrefix, step.id, "up"),
28
- label: `Move step ${number} up`,
29
- icon: ArrowUpIcon,
30
- disabled: position === 0,
31
- onClick: () => onAction("up"),
32
- },
33
- {
34
- id: stepControlId(idPrefix, step.id, "down"),
35
- label: `Move step ${number} down`,
36
- icon: ArrowDownIcon,
37
- disabled: position === count - 1,
38
- onClick: () => onAction("down"),
39
- },
40
- {
41
- id: stepControlId(idPrefix, step.id, "remove"),
42
- label: `Remove step ${number}`,
43
- icon: Trash2Icon,
44
- disabled: count === 1,
45
- onClick: () => onAction("remove"),
46
- danger: true,
47
- },
48
- ];
49
- return (_jsxs("li", { "data-slot": "plan-step", className: "group flex items-start gap-3 px-5 py-2.5 focus-within:bg-accent/50 hover:bg-accent/50 motion-safe:transition-colors", children: [_jsx("span", { "aria-hidden": true, className: "mt-0.5 flex size-5 shrink-0 items-center justify-center font-mono text-[11px] text-muted-foreground tabular-nums ring-1 ring-input", children: number }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5", children: [_jsx("input", { id: titleId, "aria-label": `Step ${number} title`, value: step.title, placeholder: "Name this step", "aria-invalid": blank || undefined, onChange: (event) => onRename(event.target.value), className: cn("-mx-1.5 h-6 min-w-0 bg-transparent px-1.5 text-sm font-medium outline-none placeholder:font-normal placeholder:text-muted-foreground focus-visible:bg-background focus-visible:ring-1 focus-visible:ring-ring", blank && "ring-1 ring-destructive/70") }), step.detail && _jsx("p", { className: "text-xs text-muted-foreground", children: step.detail })] }), _jsx("div", { className: "flex shrink-0 gap-0.5 sm:opacity-0 sm:group-focus-within:opacity-100 sm:group-hover:opacity-100 sm:motion-safe:transition-opacity", children: controls.map(({ id, label, icon: Icon, disabled, onClick, danger }) => (_jsx(Button, { id: id, type: "button", variant: "ghost", size: "icon-xs", "aria-label": label, title: label, disabled: disabled, onClick: onClick, className: cn("text-muted-foreground hover:text-foreground", danger && "hover:text-destructive"), children: _jsx(Icon, { "aria-hidden": true }) }, id))) })] }));
14
+ export function PlanStepRow({
15
+ idPrefix,
16
+ step,
17
+ position,
18
+ count,
19
+ onRename,
20
+ onAction
21
+ }) {
22
+ const number = position + 1;
23
+ const titleId = stepControlId(idPrefix, step.id, "title");
24
+ const blank = step.title.trim() === "";
25
+ const controls = [{
26
+ id: `${idPrefix}-${step.id}-edit`,
27
+ label: `Edit step ${number}`,
28
+ icon: PencilIcon,
29
+ disabled: false,
30
+ onClick: () => selectInputById(titleId)
31
+ }, {
32
+ id: stepControlId(idPrefix, step.id, "up"),
33
+ label: `Move step ${number} up`,
34
+ icon: ArrowUpIcon,
35
+ disabled: position === 0,
36
+ onClick: () => onAction("up")
37
+ }, {
38
+ id: stepControlId(idPrefix, step.id, "down"),
39
+ label: `Move step ${number} down`,
40
+ icon: ArrowDownIcon,
41
+ disabled: position === count - 1,
42
+ onClick: () => onAction("down")
43
+ }, {
44
+ id: stepControlId(idPrefix, step.id, "remove"),
45
+ label: `Remove step ${number}`,
46
+ icon: Trash2Icon,
47
+ disabled: count === 1,
48
+ onClick: () => onAction("remove"),
49
+ danger: true
50
+ }];
51
+ return /*#__PURE__*/_jsxs("li", {
52
+ "data-slot": "plan-step",
53
+ className: "group flex items-start gap-3 px-5 py-2.5 focus-within:bg-accent/50 hover:bg-accent/50 motion-safe:transition-colors",
54
+ children: [/*#__PURE__*/_jsx("span", {
55
+ "aria-hidden": true,
56
+ className: "mt-0.5 flex size-5 shrink-0 items-center justify-center font-mono text-[11px] text-muted-foreground tabular-nums ring-1 ring-input",
57
+ children: number
58
+ }), /*#__PURE__*/_jsxs("div", {
59
+ className: "flex min-w-0 flex-1 flex-col gap-0.5",
60
+ children: [/*#__PURE__*/_jsx("input", {
61
+ id: titleId,
62
+ "aria-label": `Step ${number} title`,
63
+ value: step.title,
64
+ placeholder: "Name this step",
65
+ "aria-invalid": blank || undefined,
66
+ onChange: event => onRename(event.target.value),
67
+ className: cn("-mx-1.5 h-6 min-w-0 bg-transparent px-1.5 text-sm font-medium outline-none placeholder:font-normal placeholder:text-muted-foreground focus-visible:bg-background focus-visible:ring-1 focus-visible:ring-ring", blank && "ring-1 ring-destructive/70")
68
+ }), step.detail && /*#__PURE__*/_jsx("p", {
69
+ className: "text-xs text-muted-foreground",
70
+ children: step.detail
71
+ })]
72
+ }), /*#__PURE__*/_jsx("div", {
73
+ className: "flex shrink-0 gap-0.5 sm:opacity-0 sm:group-focus-within:opacity-100 sm:group-hover:opacity-100 sm:motion-safe:transition-opacity",
74
+ children: controls.map(({
75
+ id,
76
+ label,
77
+ icon: Icon,
78
+ disabled,
79
+ onClick,
80
+ danger
81
+ }) => /*#__PURE__*/_jsx(Button, {
82
+ id: id,
83
+ type: "button",
84
+ variant: "ghost",
85
+ size: "icon-xs",
86
+ "aria-label": label,
87
+ title: label,
88
+ disabled: disabled,
89
+ onClick: onClick,
90
+ className: cn("text-muted-foreground hover:text-foreground", danger && "hover:text-destructive"),
91
+ children: /*#__PURE__*/_jsx(Icon, {
92
+ "aria-hidden": true
93
+ })
94
+ }, id))
95
+ })]
96
+ });
50
97
  }
@@ -1,29 +1,30 @@
1
1
  export function applyStepAction(steps, stepId, action) {
2
- const index = steps.findIndex((step) => step.id === stepId);
3
- if (index === -1)
4
- return steps;
5
- if (action === "remove")
6
- return steps.filter((step) => step.id !== stepId);
7
- const target = action === "up" ? index - 1 : index + 1;
8
- if (target < 0 || target >= steps.length)
9
- return steps;
10
- const reordered = [...steps];
11
- const [moved] = reordered.splice(index, 1);
12
- if (moved)
13
- reordered.splice(target, 0, moved);
14
- return reordered;
2
+ const index = steps.findIndex(step => step.id === stepId);
3
+ if (index === -1) return steps;
4
+ if (action === "remove") return steps.filter(step => step.id !== stepId);
5
+ const target = action === "up" ? index - 1 : index + 1;
6
+ if (target < 0 || target >= steps.length) return steps;
7
+ const reordered = [...steps];
8
+ const [moved] = reordered.splice(index, 1);
9
+ if (moved) reordered.splice(target, 0, moved);
10
+ return reordered;
15
11
  }
16
12
  export function focusAfterAction(steps, stepId, action) {
17
- if (action !== "remove") {
18
- const index = steps.findIndex((step) => step.id === stepId);
19
- const atEdge = action === "up" ? index === 0 : index === steps.length - 1;
20
- return { stepId, control: atEdge ? "title" : action };
21
- }
22
- const neighbor = steps[0];
23
- return neighbor ? { stepId: neighbor.id, control: "title" } : null;
13
+ if (action !== "remove") {
14
+ const index = steps.findIndex(step => step.id === stepId);
15
+ const atEdge = action === "up" ? index === 0 : index === steps.length - 1;
16
+ return {
17
+ stepId,
18
+ control: atEdge ? "title" : action
19
+ };
20
+ }
21
+ const neighbor = steps[0];
22
+ return neighbor ? {
23
+ stepId: neighbor.id,
24
+ control: "title"
25
+ } : null;
24
26
  }
25
27
  export function describeStepAction(position, action) {
26
- if (action === "remove")
27
- return `Step ${position + 1} removed.`;
28
- return `Step moved ${action}.`;
28
+ if (action === "remove") return `Step ${position + 1} removed.`;
29
+ return `Step moved ${action}.`;
29
30
  }
@@ -1,47 +1,80 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
1
  import { cn } from "@locusgraph/components";
3
2
  import { useEffect, useRef } from "react";
3
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
4
  const nextIndexByKey = {
5
- ArrowRight: (index, count) => (index + 1) % count,
6
- ArrowDown: (index, count) => (index + 1) % count,
7
- ArrowLeft: (index, count) => (index - 1 + count) % count,
8
- ArrowUp: (index, count) => (index - 1 + count) % count,
9
- Home: () => 0,
10
- End: (_index, count) => count - 1,
5
+ ArrowRight: (index, count) => (index + 1) % count,
6
+ ArrowDown: (index, count) => (index + 1) % count,
7
+ ArrowLeft: (index, count) => (index - 1 + count) % count,
8
+ ArrowUp: (index, count) => (index - 1 + count) % count,
9
+ Home: () => 0,
10
+ End: (_index, count) => count - 1
11
11
  };
12
12
  function indexFromDigitKey(key, count) {
13
- const digit = Number(key);
14
- return Number.isInteger(digit) && digit >= 1 && digit <= count ? digit - 1 : undefined;
13
+ const digit = Number(key);
14
+ return Number.isInteger(digit) && digit >= 1 && digit <= count ? digit - 1 : undefined;
15
15
  }
16
- export function QuestionChoices({ label, options, selectedId, onSelect, autoFocus = false, }) {
17
- const buttons = useRef([]);
18
- useEffect(() => {
19
- if (autoFocus)
20
- buttons.current[0]?.focus({ preventScroll: true });
21
- }, [autoFocus]);
22
- const selectedIndex = options.findIndex((option) => option.id === selectedId);
23
- const tabStop = selectedIndex === -1 ? 0 : selectedIndex;
24
- function selectIndex(next) {
25
- const option = options[next];
26
- if (!option)
27
- return;
28
- onSelect(option.id);
29
- buttons.current[next]?.focus();
30
- }
31
- function handleKeyDown(event, index) {
32
- const byDigit = indexFromDigitKey(event.key, options.length);
33
- const move = nextIndexByKey[event.key];
34
- if (byDigit === undefined && !move)
35
- return;
36
- event.preventDefault();
37
- selectIndex(byDigit ?? move?.(index, options.length) ?? index);
38
- }
39
- return (_jsx("div", { role: "radiogroup", "aria-label": label, "data-slot": "question-choices", className: "-mx-5 flex flex-col divide-y border-y", children: options.map((option, index) => {
40
- const checked = option.id === selectedId;
41
- return (_jsxs("button", { ref: (element) => {
42
- buttons.current[index] = element;
43
- }, type: "button", role: "radio", "aria-checked": checked, tabIndex: index === tabStop ? 0 : -1, "data-state": checked ? "checked" : "unchecked", onClick: () => onSelect(option.id), onKeyDown: (event) => handleKeyDown(event, index), className: cn("group relative flex items-center gap-3 px-5 py-2.5 text-left text-sm outline-none motion-safe:transition-colors focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-ring/70 focus-visible:ring-inset", checked ? "bg-accent" : "hover:bg-accent/50"), children: [_jsx("span", { "aria-hidden": true, className: cn("flex size-5 shrink-0 items-center justify-center font-mono text-[11px] ring-1", checked
44
- ? "bg-primary text-primary-foreground ring-primary"
45
- : "text-muted-foreground ring-input"), children: index + 1 }), _jsxs("span", { className: "flex min-w-0 flex-1 flex-col", children: [_jsx("span", { className: "font-medium", children: option.label }), option.description && (_jsx("span", { className: "text-xs text-muted-foreground", children: option.description }))] })] }, option.id));
46
- }) }));
16
+ export function QuestionChoices({
17
+ label,
18
+ options,
19
+ selectedId,
20
+ onSelect,
21
+ autoFocus = false
22
+ }) {
23
+ const buttons = useRef([]);
24
+ useEffect(() => {
25
+ if (autoFocus) buttons.current[0]?.focus({
26
+ preventScroll: true
27
+ });
28
+ }, [autoFocus]);
29
+ const selectedIndex = options.findIndex(option => option.id === selectedId);
30
+ const tabStop = selectedIndex === -1 ? 0 : selectedIndex;
31
+ function selectIndex(next) {
32
+ const option = options[next];
33
+ if (!option) return;
34
+ onSelect(option.id);
35
+ buttons.current[next]?.focus();
36
+ }
37
+ function handleKeyDown(event, index) {
38
+ const byDigit = indexFromDigitKey(event.key, options.length);
39
+ const move = nextIndexByKey[event.key];
40
+ if (byDigit === undefined && !move) return;
41
+ event.preventDefault();
42
+ selectIndex(byDigit ?? move?.(index, options.length) ?? index);
43
+ }
44
+ return /*#__PURE__*/_jsx("div", {
45
+ role: "radiogroup",
46
+ "aria-label": label,
47
+ "data-slot": "question-choices",
48
+ className: "-mx-5 flex flex-col divide-y border-y",
49
+ children: options.map((option, index) => {
50
+ const checked = option.id === selectedId;
51
+ return /*#__PURE__*/_jsxs("button", {
52
+ ref: element => {
53
+ buttons.current[index] = element;
54
+ },
55
+ type: "button",
56
+ role: "radio",
57
+ "aria-checked": checked,
58
+ tabIndex: index === tabStop ? 0 : -1,
59
+ "data-state": checked ? "checked" : "unchecked",
60
+ onClick: () => onSelect(option.id),
61
+ onKeyDown: event => handleKeyDown(event, index),
62
+ className: cn("group relative flex items-center gap-3 px-5 py-2.5 text-left text-sm outline-none motion-safe:transition-colors focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-ring/70 focus-visible:ring-inset", checked ? "bg-accent" : "hover:bg-accent/50"),
63
+ children: [/*#__PURE__*/_jsx("span", {
64
+ "aria-hidden": true,
65
+ className: cn("flex size-5 shrink-0 items-center justify-center font-mono text-[11px] ring-1", checked ? "bg-primary text-primary-foreground ring-primary" : "text-muted-foreground ring-input"),
66
+ children: index + 1
67
+ }), /*#__PURE__*/_jsxs("span", {
68
+ className: "flex min-w-0 flex-1 flex-col",
69
+ children: [/*#__PURE__*/_jsx("span", {
70
+ className: "font-medium",
71
+ children: option.label
72
+ }), option.description && /*#__PURE__*/_jsx("span", {
73
+ className: "text-xs text-muted-foreground",
74
+ children: option.description
75
+ })]
76
+ })]
77
+ }, option.id);
78
+ })
79
+ });
47
80
  }
@@ -15,4 +15,4 @@ export type QuestionProps = {
15
15
  autoFocus?: boolean;
16
16
  className?: string;
17
17
  };
18
- export declare function Question({ question, options, allowText, textLabel, textPlaceholder, submitLabel, answer, onAnswer, autoFocus, className, }: QuestionProps): import("react").JSX.Element;
18
+ export declare function Question({ question, options, allowText: allowTextProp, textLabel: textLabelProp, textPlaceholder: textPlaceholderProp, submitLabel, answer, onAnswer, autoFocus, className, }: QuestionProps): import("react").JSX.Element;