@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.
- package/README.md +2 -0
- package/dist/agent/pulse/gradient-label.js +36 -15
- package/dist/agent/pulse/marks/bars-mark.js +24 -10
- package/dist/agent/pulse/marks/glyph-mark.js +17 -11
- package/dist/agent/pulse/marks/locus-mark.js +39 -28
- package/dist/agent/pulse/marks/orb-mark.js +21 -8
- package/dist/agent/pulse/marks/spinner-mark.js +20 -1
- package/dist/agent/pulse/pulse.js +63 -35
- package/dist/agent/pulse/use-loop-animation.js +14 -16
- package/dist/agent/steps/step-icon.js +40 -24
- package/dist/agent/steps/steps.js +72 -25
- package/dist/agent/thinking/thinking.js +203 -23
- package/dist/agent/thinking/thought-duration.js +7 -9
- package/dist/agent/tool/json-block.js +18 -11
- package/dist/agent/tool/tool-status.js +28 -18
- package/dist/agent/tool/tool.js +184 -6
- package/dist/approval/inbox/inbox-row.d.ts +3 -2
- package/dist/approval/inbox/inbox-row.js +96 -7
- package/dist/approval/inbox/inbox-selection.js +7 -13
- package/dist/approval/inbox/inbox.d.ts +2 -1
- package/dist/approval/inbox/inbox.js +99 -18
- package/dist/approval/inbox/virtual-inbox-list.d.ts +13 -0
- package/dist/approval/inbox/virtual-inbox-list.js +53 -0
- package/dist/approval/memory/memory-choices.js +27 -22
- package/dist/approval/memory/memory-review.js +108 -17
- package/dist/approval/memory/memory-row.js +80 -19
- package/dist/approval/plan/plan-review.js +129 -28
- package/dist/approval/plan/plan-step-row.js +91 -44
- package/dist/approval/plan/plan-steps.js +24 -23
- package/dist/approval/plan/question-choices.js +73 -40
- package/dist/approval/plan/question.d.ts +1 -1
- package/dist/approval/plan/question.js +108 -27
- package/dist/approval/run/run-bar.js +94 -22
- package/dist/approval/shared/decision-line.js +1 -1
- package/dist/approval/shared/risk-badge.js +32 -16
- package/dist/approval/shared/time.js +5 -8
- package/dist/approval/shared/use-focus-on-mount.js +7 -6
- package/dist/approval/spend/raise-cap-form.js +64 -19
- package/dist/approval/spend/spend-gate.js +124 -21
- package/dist/approval/spend/spend-math.js +7 -8
- package/dist/approval/spend/spend-meter.js +136 -35
- package/dist/approval/tool/approval.js +113 -27
- package/dist/approval/tool/args/args-editor.js +104 -26
- package/dist/approval/tool/args/args-field.js +79 -22
- package/dist/approval/tool/args/args-validation.js +38 -47
- package/dist/approval/tool/deny-form.js +43 -10
- package/dist/approval/tool/tool-inputs.js +62 -38
- package/dist/chat/chat/chat-item-spacing.d.ts +3 -0
- package/dist/chat/chat/chat-item-spacing.js +19 -0
- package/dist/chat/chat/chat.d.ts +2 -1
- package/dist/chat/chat/chat.js +181 -5
- package/dist/chat/chat/use-stick-to-bottom.js +71 -48
- package/dist/chat/chat/virtual-chat-items.d.ts +8 -0
- package/dist/chat/chat/virtual-chat-items.js +60 -0
- package/dist/chat/composer/composer-actions.js +69 -17
- package/dist/chat/composer/composer.js +330 -32
- package/dist/chat/composer/use-auto-grow.js +9 -9
- package/dist/chat/files/file-meta.js +19 -19
- package/dist/chat/files/files.js +92 -29
- package/dist/chat/reply/fenced-code.js +23 -21
- package/dist/chat/reply/markdown-components.js +137 -17
- package/dist/chat/reply/reply.js +30 -10
- package/dist/chat/turn/group-parts.js +43 -29
- package/dist/chat/turn/turn.js +87 -30
- package/dist/cost/context.js +104 -23
- package/dist/cost/cost-steps.js +67 -14
- package/dist/cost/cost.js +128 -23
- package/dist/cost/model-picker.js +51 -6
- package/dist/cost/shared/context-breakdown.js +83 -10
- package/dist/cost/shared/meter-marks.js +49 -9
- package/dist/cost/shared/model-option-row.js +56 -22
- package/dist/cost/shared/step-cost-row.js +65 -22
- package/dist/cost/shared/usage-totals.js +22 -18
- package/dist/memory/cite.js +62 -12
- package/dist/memory/memorized.js +65 -11
- package/dist/memory/recall.js +101 -17
- package/dist/memory/shared/host-label.js +19 -22
- package/dist/memory/shared/source-mark.js +11 -3
- package/dist/memory/sources.js +78 -14
- package/dist/shared/decision-summary.js +51 -14
- package/dist/shared/panel-empty.js +20 -3
- package/dist/shared/panel.js +69 -13
- package/dist/shared/status-dot.js +16 -8
- package/dist/shared/virtual/use-list-virtualizer.d.ts +24 -0
- package/dist/shared/virtual/use-list-virtualizer.js +68 -0
- package/dist/thread/actions/action-button.js +22 -3
- package/dist/thread/actions/actions.js +184 -13
- package/dist/thread/actions/branch-switcher.js +28 -5
- package/dist/thread/canvas/canvas.js +205 -5
- package/dist/thread/canvas/version-switcher.js +54 -8
- package/dist/thread/code/code.js +186 -24
- package/dist/thread/code/copy-code-button.js +30 -14
- package/dist/thread/code/highlight.js +30 -29
- package/dist/thread/history/history-rows.d.ts +16 -0
- package/dist/thread/history/history-rows.js +23 -0
- package/dist/thread/history/history.d.ts +3 -2
- package/dist/thread/history/history.js +174 -5
- package/dist/thread/history/{history-row.d.ts → row/history-row.d.ts} +3 -2
- package/dist/thread/history/row/history-row.js +58 -0
- package/dist/thread/history/row/thread-item-menu.js +31 -0
- package/dist/thread/history/row/thread-title-editor.js +38 -0
- package/dist/thread/history/thread-groups.d.ts +1 -1
- package/dist/thread/history/thread-groups.js +40 -34
- package/dist/thread/history/virtual-history-list.d.ts +11 -0
- package/dist/thread/history/virtual-history-list.js +71 -0
- package/dist/thread/index.d.ts +1 -1
- package/dist/thread/starters/starters.js +33 -8
- package/dist/thread/use-copied.js +18 -16
- package/dist/types.js +1 -1
- package/package.json +6 -4
- package/dist/thread/history/history-row.js +0 -17
- package/dist/thread/history/thread-item-menu.js +0 -6
- package/dist/thread/history/thread-title-editor.js +0 -25
- /package/dist/thread/history/{thread-item-menu.d.ts → row/thread-item-menu.d.ts} +0 -0
- /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
|
|
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
|
-
|
|
12
|
-
|
|
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({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 {
|
|
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
|
-
|
|
5
|
+
return `${idPrefix}-${stepId}-${action}`;
|
|
6
6
|
}
|
|
7
7
|
function selectInputById(id) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
13
|
+
const digit = Number(key);
|
|
14
|
+
return Number.isInteger(digit) && digit >= 1 && digit <= count ? digit - 1 : undefined;
|
|
15
15
|
}
|
|
16
|
-
export function QuestionChoices({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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;
|