@zyro-sec/session-ui 0.0.0-stage → 1.0.4
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/AGENTS.md +25 -0
- package/bunfig.toml +2 -0
- package/component-tests/basic-tool.fixture.tsx +46 -0
- package/component-tests/basic-tool.spec.ts +63 -0
- package/component-tests/file-media.fixture.tsx +39 -0
- package/component-tests/file-media.spec.ts +13 -0
- package/component-tests/file-tool.spec.ts +62 -0
- package/component-tests/file-viewer.fixture.tsx +109 -0
- package/component-tests/file-viewer.spec.ts +134 -0
- package/component-tests/file.spec.ts +33 -0
- package/component-tests/line-comment-v2.spec.ts +15 -0
- package/component-tests/markdown-code-wrap.spec.ts +94 -0
- package/component-tests/markdown-readiness.spec.ts +95 -0
- package/component-tests/markdown.fixture.tsx +104 -0
- package/component-tests/markdown.spec.ts +1564 -0
- package/component-tests/mermaid-preview.spec.ts +43 -0
- package/component-tests/patch-group.spec.ts +79 -0
- package/component-tests/read-group.spec.ts +72 -0
- package/component-tests/read-image.fixture.tsx +66 -0
- package/component-tests/read-image.spec.ts +154 -0
- package/component-tests/session-compaction.spec.ts +254 -0
- package/component-tests/session-lifecycle.spec.ts +190 -0
- package/component-tests/session-message-projection.spec.ts +639 -0
- package/component-tests/session-notice-projection.spec.ts +20 -0
- package/component-tests/session-review-comments.spec.ts +179 -0
- package/component-tests/session-shell.spec.ts +93 -0
- package/component-tests/session-timeline-mobile.spec.ts +201 -0
- package/component-tests/session-timeline-notices.spec.ts +38 -0
- package/component-tests/session-timeline-reasoning.spec.ts +107 -0
- package/component-tests/session-timeline.spec.ts +157 -0
- package/component-tests/session-tool-projection.spec.ts +323 -0
- package/component-tests/text-lifecycle.fixture.tsx +26 -0
- package/component-tests/text-lifecycle.spec.ts +42 -0
- package/component-tests/timeline-subagent-rows.spec.ts +33 -0
- package/component-tests/tool-disclosure.spec.ts +48 -0
- package/component-tests/tool-group-sticky.spec.ts +37 -0
- package/component-tests/tool-group.spec.ts +290 -0
- package/component-tests/tool-status-title.fixture.tsx +22 -0
- package/component-tests/tool-status-title.spec.ts +30 -0
- package/component-tests/user-message-quotes.spec.ts +111 -0
- package/package.json +91 -4
- package/playwright.components.config.ts +4 -0
- package/playwright.local.config.ts +2 -0
- package/src/actions.ts +54 -0
- package/src/components/apply-patch-file.ts +122 -0
- package/src/components/basic-tool.css +487 -0
- package/src/components/basic-tool.tsx +258 -0
- package/src/components/copy-machine.ts +78 -0
- package/src/components/copy.ts +85 -0
- package/src/components/diagram-preview.tsx +28 -0
- package/src/components/disclosure-machine.ts +188 -0
- package/src/components/disclosure.ts +129 -0
- package/src/components/dock-prompt.stories.tsx +73 -0
- package/src/components/dock-prompt.tsx +29 -0
- package/src/components/file-comment-selection.tsx +146 -0
- package/src/components/file-media-machine.ts +165 -0
- package/src/components/file-media.stories.tsx +112 -0
- package/src/components/file-media.tsx +323 -0
- package/src/components/file-search.tsx +73 -0
- package/src/components/file.css +59 -0
- package/src/components/file.tsx +1300 -0
- package/src/components/image-preview.tsx +35 -0
- package/src/components/line-comment-annotations.tsx +580 -0
- package/src/components/line-comment-machine.ts +262 -0
- package/src/components/line-comment-styles.ts +293 -0
- package/src/components/line-comment.stories.tsx +152 -0
- package/src/components/line-comment.tsx +448 -0
- package/src/components/link-segments.ts +20 -0
- package/src/components/linked-text.tsx +21 -0
- package/src/components/markdown-cache-machine.ts +257 -0
- package/src/components/markdown-cache.tsx +556 -0
- package/src/components/markdown-clipboard.ts +101 -0
- package/src/components/markdown-code-machine.ts +200 -0
- package/src/components/markdown-code-state.ts +22 -0
- package/src/components/markdown-fragment-links.ts +74 -0
- package/src/components/markdown-github.svg +3 -0
- package/src/components/markdown-globe.svg +5 -0
- package/src/components/markdown-image-machine.ts +170 -0
- package/src/components/markdown-image.ts +156 -0
- package/src/components/markdown-inline-code-kind.ts +39 -0
- package/src/components/markdown-mermaid.ts +18 -0
- package/src/components/markdown-phase-machine.ts +102 -0
- package/src/components/markdown-projection.ts +13 -0
- package/src/components/markdown-session-links.ts +183 -0
- package/src/components/markdown-solid.test.tsx +92 -0
- package/src/components/markdown-solid.tsx +113 -0
- package/src/components/markdown-stream.ts +95 -0
- package/src/components/markdown-worker-machine.ts +516 -0
- package/src/components/markdown-worker-protocol.ts +73 -0
- package/src/components/markdown-worker.ts +250 -0
- package/src/components/markdown.css +672 -0
- package/src/components/markdown.stories.tsx +199 -0
- package/src/components/markdown.tsx +1612 -0
- package/src/components/markdown.worker.ts +188 -0
- package/src/components/message-file.ts +102 -0
- package/src/components/message-nav.css +134 -0
- package/src/components/message-nav.tsx +159 -0
- package/src/components/message-part.css +2109 -0
- package/src/components/message-part.tsx +3 -0
- package/src/components/question-prompt-experimental.css +576 -0
- package/src/components/question-prompt.css +527 -0
- package/src/components/quote-highlight.css +59 -0
- package/src/components/review-focus-driver.ts +142 -0
- package/src/components/review-focus-machine.ts +95 -0
- package/src/components/session-compaction.css +270 -0
- package/src/components/session-diff.ts +358 -0
- package/src/components/session-error.tsx +41 -0
- package/src/components/session-retry.tsx +92 -0
- package/src/components/session-review-machine.ts +241 -0
- package/src/components/session-review.css +264 -0
- package/src/components/session-review.stories.tsx +232 -0
- package/src/components/session-review.tsx +733 -0
- package/src/components/session-turn.css +282 -0
- package/src/components/shell-submessage.css +24 -0
- package/src/components/timeline-separator.tsx +69 -0
- package/src/components/tool-count-label.css +57 -0
- package/src/components/tool-count-label.tsx +76 -0
- package/src/components/tool-count-summary.css +102 -0
- package/src/components/tool-count-summary.stories.tsx +99 -0
- package/src/components/tool-count-summary.tsx +44 -0
- package/src/components/tool-error-card.css +178 -0
- package/src/components/tool-error-card.stories.tsx +113 -0
- package/src/components/tool-error-card.tsx +202 -0
- package/src/components/tool-status-title-machine.ts +128 -0
- package/src/components/tool-status-title.css +89 -0
- package/src/components/tool-status-title.tsx +163 -0
- package/src/context/data.tsx +107 -0
- package/src/context/index.ts +1 -0
- package/src/context/markdown.tsx +129 -0
- package/src/context/sources.tsx +34 -0
- package/src/document.ts +8 -0
- package/src/file-presentation.ts +34 -0
- package/src/message/action-machine.ts +72 -0
- package/src/message/agent-label.ts +3 -0
- package/src/message/attachment-card.css +119 -0
- package/src/message/attachment-card.tsx +40 -0
- package/src/message/attachment-media-machine.ts +213 -0
- package/src/message/comment-card.tsx +155 -0
- package/src/message/compaction-entrance-machine.ts +93 -0
- package/src/message/current-message.tsx +157 -0
- package/src/message/current-tool-state.ts +161 -0
- package/src/message/message-content.tsx +1391 -0
- package/src/message/paced-text-machine.ts +73 -0
- package/src/message/prompt-message.stories.tsx +149 -0
- package/src/message/relative-time.ts +45 -0
- package/src/message/user-message-quote-parts.ts +16 -0
- package/src/message/user-message-quotes.stories.tsx +797 -0
- package/src/message/user-message-quotes.tsx +135 -0
- package/src/pierre/comment-hover-machine.ts +53 -0
- package/src/pierre/comment-hover.ts +131 -0
- package/src/pierre/comment-selection-machine.ts +257 -0
- package/src/pierre/commented-lines.ts +106 -0
- package/src/pierre/diff-selection.ts +91 -0
- package/src/pierre/file-find-machine.ts +323 -0
- package/src/pierre/file-find.ts +537 -0
- package/src/pierre/file-runtime.ts +42 -0
- package/src/pierre/file-selection.ts +140 -0
- package/src/pierre/index.ts +344 -0
- package/src/pierre/media.ts +140 -0
- package/src/pierre/render-machine.ts +381 -0
- package/src/pierre/selection-bridge.ts +82 -0
- package/src/pierre/selection-machine.ts +198 -0
- package/src/pierre/virtualizer.ts +114 -0
- package/src/pierre/worker.ts +46 -0
- package/src/sources/experiment.ts +59 -0
- package/src/sources/site-icon.tsx +53 -0
- package/src/sources/sources-chip.tsx +57 -0
- package/src/sources/sources-expand-machine.ts +101 -0
- package/src/sources/sources-panel.tsx +249 -0
- package/src/sources/sources-title.tsx +21 -0
- package/src/sources/sources.css +266 -0
- package/src/sources/sources.ts +141 -0
- package/src/storybook/current-session-fixtures.ts +1492 -0
- package/src/storybook/current-session-scenarios.ts +76 -0
- package/src/storybook/current-session-story.tsx +154 -0
- package/src/storybook/index.ts +43 -0
- package/src/styles/index.css +19 -0
- package/src/timeline/__snapshots__/group-labels.test.ts.snap +110 -0
- package/src/timeline/__snapshots__/placement.test.ts.snap +1041 -0
- package/src/timeline/code-blocks.stories.tsx +105 -0
- package/src/timeline/commentary.stories.tsx +70 -0
- package/src/timeline/commentary.ts +38 -0
- package/src/timeline/detail.ts +111 -0
- package/src/timeline/error-card.stories.tsx +134 -0
- package/src/timeline/error-spacing.stories.tsx +71 -0
- package/src/timeline/facts.ts +493 -0
- package/src/timeline/file-changes.stories.tsx +436 -0
- package/src/timeline/group-label-fixtures.ts +97 -0
- package/src/timeline/mermaid.stories.tsx +131 -0
- package/src/timeline/place.ts +280 -0
- package/src/timeline/placement-fixtures.ts +365 -0
- package/src/timeline/placement-reactivity.ts +133 -0
- package/src/timeline/projection.ts +1261 -0
- package/src/timeline/research-and-agents.stories.tsx +461 -0
- package/src/timeline/session-timeline-row.tsx +1675 -0
- package/src/timeline/session-timeline.tsx +68 -0
- package/src/timeline/steer-arrival-machine.ts +134 -0
- package/src/timeline/terminal-work.stories.tsx +464 -0
- package/src/timeline/timeline-row.stories.tsx +1069 -0
- package/src/timeline/timeline-row.ts +238 -0
- package/src/timeline/turn-phase-machine.ts +112 -0
- package/src/timeline/user-message-fold.stories.tsx +194 -0
- package/src/timeline/user-runs.ts +87 -0
- package/src/timeline-next/__snapshots__/placement.test.ts.snap +990 -0
- package/src/timeline-next/compaction.tsx +236 -0
- package/src/timeline-next/errors.ts +101 -0
- package/src/timeline-next/event-row.tsx +168 -0
- package/src/timeline-next/events.ts +103 -0
- package/src/timeline-next/index.ts +10 -0
- package/src/timeline-next/nested-rail.ts +125 -0
- package/src/timeline-next/projection.ts +1028 -0
- package/src/timeline-next/row.tsx +1728 -0
- package/src/timeline-next/rules.ts +89 -0
- package/src/timeline-next/separator.tsx +73 -0
- package/src/timeline-next/spacing.ts +127 -0
- package/src/timeline-next/status-line.tsx +41 -0
- package/src/timeline-next/status.ts +33 -0
- package/src/timeline-next/stories/compare-renderer.stories.tsx +190 -0
- package/src/timeline-next/stories/compare-sessions/.gitignore +3 -0
- package/src/timeline-next/stories/compare.stories.tsx +486 -0
- package/src/timeline-next/stories/playground.stories.tsx +297 -0
- package/src/timeline-next/stories/session-replay.ts +1156 -0
- package/src/timeline-next/stories/session-timeline.tsx +50 -0
- package/src/timeline-next/stories/subagent-status.stories.tsx +132 -0
- package/src/timeline-next/timeline-next.css +649 -0
- package/src/timeline-next/tools/__snapshots__/activity-label.test.ts.snap +39 -0
- package/src/timeline-next/tools/activity-label.ts +166 -0
- package/src/timeline-next/tools/assistant-content.tsx +84 -0
- package/src/timeline-next/tools/context-group.tsx +619 -0
- package/src/timeline-next/tools/error-card.tsx +147 -0
- package/src/timeline-next/tools/explore.tsx +119 -0
- package/src/timeline-next/tools/file-group.tsx +128 -0
- package/src/timeline-next/tools/patch.tsx +174 -0
- package/src/timeline-next/tools/shell.tsx +186 -0
- package/src/timeline-next/tools/thought.tsx +87 -0
- package/src/timeline-next/tools/tool-display.tsx +119 -0
- package/src/tools/ansi.ts +8 -0
- package/src/tools/context-group-label.ts +123 -0
- package/src/tools/file-runs.ts +35 -0
- package/src/tools/project-path.ts +18 -0
- package/src/tools/read-group.stories.tsx +159 -0
- package/src/tools/run-machine.ts +185 -0
- package/src/tools/shell-output-machine.ts +233 -0
- package/src/tools/shell-output.ts +91 -0
- package/src/tools/subagent-row-variants.stories.tsx +129 -0
- package/src/tools/tool-group.stories.tsx +345 -0
- package/src/tools/tool-renderer.tsx +2876 -0
- package/src/v2/components/line-comment-annotations-v2.tsx +215 -0
- package/src/v2/components/session-file-panel-v2.tsx +149 -0
- package/src/v2/components/session-progress-indicator-v2.css +5 -0
- package/src/v2/components/session-progress-indicator-v2.stories.tsx +86 -0
- package/src/v2/components/session-progress-indicator-v2.tsx +16 -0
- package/src/v2/components/session-review-empty-changes-v2.tsx +17 -0
- package/src/v2/components/session-review-empty-no-git-v2.tsx +28 -0
- package/src/v2/components/session-review-file-preview-v2-virtualize.ts +5 -0
- package/src/v2/components/session-review-file-preview-v2.tsx +266 -0
- package/src/v2/components/session-review-v2.css +653 -0
- package/src/v2/components/session-review-v2.tsx +422 -0
- package/src/v2/components/sidebar-presence-machine.ts +69 -0
- package/tsconfig.json +20 -0
- package/README.md +0 -3
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { createMemo, For, Match, Show, Switch, type Accessor, type JSX } from "solid-js"
|
|
2
|
+
import { Option, Schema } from "effect"
|
|
3
|
+
import { useI18n } from "@zyro-sec/ui/context/i18n"
|
|
4
|
+
import { Collapsible } from "@zyro-sec/ui/collapsible"
|
|
5
|
+
import type { IconProps } from "@zyro-sec/ui/icon"
|
|
6
|
+
import { TextShimmer } from "@zyro-sec/ui/text-shimmer"
|
|
7
|
+
import { createDisclosure } from "./disclosure"
|
|
8
|
+
|
|
9
|
+
export type TriggerTitle = {
|
|
10
|
+
title: string
|
|
11
|
+
titleClass?: string
|
|
12
|
+
subtitle?: string
|
|
13
|
+
subtitleClass?: string
|
|
14
|
+
args?: string[]
|
|
15
|
+
argsClass?: string
|
|
16
|
+
action?: JSX.Element
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const isTriggerTitle = (value: TriggerTitle | JSX.Element): value is TriggerTitle =>
|
|
20
|
+
value instanceof Object && !("nodeType" in value) && "title" in value
|
|
21
|
+
|
|
22
|
+
export interface BasicToolProps {
|
|
23
|
+
icon: IconProps["name"]
|
|
24
|
+
trigger: TriggerTitle | JSX.Element | ((open: Accessor<boolean>) => JSX.Element)
|
|
25
|
+
children?: JSX.Element
|
|
26
|
+
/** Declare known content without constructing lazy JSX to test its presence. */
|
|
27
|
+
hasContent?: boolean
|
|
28
|
+
status?: string
|
|
29
|
+
hideDetails?: boolean
|
|
30
|
+
defaultOpen?: boolean
|
|
31
|
+
open?: boolean
|
|
32
|
+
onOpenChange?: (open: boolean) => void
|
|
33
|
+
forceOpen?: boolean
|
|
34
|
+
allowOpenWhilePending?: boolean
|
|
35
|
+
defer?: boolean
|
|
36
|
+
locked?: boolean
|
|
37
|
+
rail?: boolean
|
|
38
|
+
onSubtitleClick?: () => void
|
|
39
|
+
onTriggerClick?: JSX.EventHandlerUnion<HTMLElement, MouseEvent>
|
|
40
|
+
onTriggerKeyDown?: JSX.EventHandlerUnion<HTMLElement, KeyboardEvent>
|
|
41
|
+
triggerHref?: string
|
|
42
|
+
triggerAsLink?: boolean
|
|
43
|
+
clickable?: boolean
|
|
44
|
+
compact?: boolean
|
|
45
|
+
/** Rendered beside the trigger rather than inside it, so it can be its own button. Shown on hover or focus. */
|
|
46
|
+
action?: JSX.Element
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function BasicTool(props: BasicToolProps) {
|
|
50
|
+
const pending = () => props.status === "streaming" || props.status === "running"
|
|
51
|
+
const hasChildren = () => props.hasContent ?? (props.defer ? "children" in props : props.children)
|
|
52
|
+
|
|
53
|
+
const disclosure = createDisclosure({
|
|
54
|
+
open: () => props.open,
|
|
55
|
+
defaultOpen: () => props.defaultOpen ?? false,
|
|
56
|
+
forceOpen: () => props.forceOpen ?? false,
|
|
57
|
+
defer: () => props.defer ?? false,
|
|
58
|
+
queue: "deferred",
|
|
59
|
+
locked: () => props.locked ?? false,
|
|
60
|
+
pending,
|
|
61
|
+
allowOpenWhilePending: () => props.allowOpenWhilePending ?? false,
|
|
62
|
+
onOpenChange: (open) => props.onOpenChange?.(open),
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const open = disclosure.open
|
|
66
|
+
|
|
67
|
+
const triggerContent = createMemo(() => {
|
|
68
|
+
const value = props.trigger
|
|
69
|
+
|
|
70
|
+
return value instanceof Function ? value(open) : value
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
const triggerTitle = createMemo(() => {
|
|
74
|
+
const value = triggerContent()
|
|
75
|
+
|
|
76
|
+
return isTriggerTitle(value) ? value : undefined
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const triggerElement = () => {
|
|
80
|
+
const value = triggerContent()
|
|
81
|
+
|
|
82
|
+
return isTriggerTitle(value) ? undefined : value
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const trigger = () => (
|
|
86
|
+
<div
|
|
87
|
+
data-component="tool-trigger"
|
|
88
|
+
data-clickable={props.clickable ? "true" : undefined}
|
|
89
|
+
data-hide-details={props.hideDetails ? "true" : undefined}
|
|
90
|
+
>
|
|
91
|
+
<div data-slot="basic-tool-tool-trigger-content">
|
|
92
|
+
<div data-slot="basic-tool-tool-info">
|
|
93
|
+
<Switch>
|
|
94
|
+
<Match when={triggerTitle()}>
|
|
95
|
+
{(title) => (
|
|
96
|
+
<div data-slot="basic-tool-tool-info-structured">
|
|
97
|
+
<div data-slot="basic-tool-tool-info-main">
|
|
98
|
+
<span
|
|
99
|
+
data-slot="basic-tool-tool-title"
|
|
100
|
+
classList={{
|
|
101
|
+
[title().titleClass ?? ""]: !!title().titleClass,
|
|
102
|
+
}}
|
|
103
|
+
>
|
|
104
|
+
<TextShimmer text={title().title} active={pending()} />
|
|
105
|
+
</span>
|
|
106
|
+
<Show when={!pending() || title().subtitle || title().args?.length}>
|
|
107
|
+
<Show when={title().subtitle}>
|
|
108
|
+
<span
|
|
109
|
+
data-slot="basic-tool-tool-subtitle"
|
|
110
|
+
classList={{
|
|
111
|
+
[title().subtitleClass ?? ""]: !!title().subtitleClass,
|
|
112
|
+
clickable: !!props.onSubtitleClick,
|
|
113
|
+
}}
|
|
114
|
+
onClick={(e) => {
|
|
115
|
+
if (props.onSubtitleClick) {
|
|
116
|
+
e.stopPropagation()
|
|
117
|
+
props.onSubtitleClick()
|
|
118
|
+
}
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
{title().subtitle}
|
|
122
|
+
</span>
|
|
123
|
+
</Show>
|
|
124
|
+
<Show when={title().args?.length}>
|
|
125
|
+
<For each={title().args}>
|
|
126
|
+
{(arg) => (
|
|
127
|
+
<span
|
|
128
|
+
data-slot="basic-tool-tool-arg"
|
|
129
|
+
classList={{
|
|
130
|
+
[title().argsClass ?? ""]: !!title().argsClass,
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
{arg}
|
|
134
|
+
</span>
|
|
135
|
+
)}
|
|
136
|
+
</For>
|
|
137
|
+
</Show>
|
|
138
|
+
</Show>
|
|
139
|
+
</div>
|
|
140
|
+
<Show when={!pending() && title().action}>
|
|
141
|
+
<span data-slot="basic-tool-tool-action">{title().action}</span>
|
|
142
|
+
</Show>
|
|
143
|
+
</div>
|
|
144
|
+
)}
|
|
145
|
+
</Match>
|
|
146
|
+
<Match when={true}>{triggerElement()}</Match>
|
|
147
|
+
</Switch>
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
<Show when={hasChildren() && !props.hideDetails && disclosure.canToggle()}>
|
|
151
|
+
<Collapsible.Arrow />
|
|
152
|
+
</Show>
|
|
153
|
+
</div>
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<Collapsible
|
|
158
|
+
open={open()}
|
|
159
|
+
onOpenChange={props.locked ? undefined : disclosure.setOpen}
|
|
160
|
+
class="tool-collapsible"
|
|
161
|
+
data-compact={props.compact ? "true" : undefined}
|
|
162
|
+
data-rail={props.rail === false ? "false" : undefined}
|
|
163
|
+
data-has-action={props.action ? "true" : undefined}
|
|
164
|
+
>
|
|
165
|
+
<Show
|
|
166
|
+
when={!props.locked && (props.triggerAsLink || props.triggerHref)}
|
|
167
|
+
fallback={
|
|
168
|
+
<Show
|
|
169
|
+
when={!props.locked}
|
|
170
|
+
fallback={
|
|
171
|
+
<div
|
|
172
|
+
data-slot="collapsible-trigger"
|
|
173
|
+
data-locked
|
|
174
|
+
data-hide-details={props.hideDetails ? "true" : undefined}
|
|
175
|
+
>
|
|
176
|
+
{trigger()}
|
|
177
|
+
</div>
|
|
178
|
+
}
|
|
179
|
+
>
|
|
180
|
+
<Collapsible.Trigger
|
|
181
|
+
data-hide-details={props.hideDetails ? "true" : undefined}
|
|
182
|
+
onClick={props.onTriggerClick}
|
|
183
|
+
>
|
|
184
|
+
{trigger()}
|
|
185
|
+
</Collapsible.Trigger>
|
|
186
|
+
</Show>
|
|
187
|
+
}
|
|
188
|
+
>
|
|
189
|
+
<Collapsible.Trigger
|
|
190
|
+
as="a"
|
|
191
|
+
href={props.triggerHref}
|
|
192
|
+
role={!props.triggerHref && props.clickable ? "button" : undefined}
|
|
193
|
+
tabIndex={!props.triggerHref && props.clickable ? 0 : undefined}
|
|
194
|
+
data-hide-details={props.hideDetails ? "true" : undefined}
|
|
195
|
+
onClick={props.onTriggerClick}
|
|
196
|
+
onKeyDown={props.onTriggerKeyDown}
|
|
197
|
+
>
|
|
198
|
+
{trigger()}
|
|
199
|
+
</Collapsible.Trigger>
|
|
200
|
+
</Show>
|
|
201
|
+
<Show when={props.action}>{(action) => <span data-slot="basic-tool-action">{action()}</span>}</Show>
|
|
202
|
+
<Show when={hasChildren() && !props.hideDetails}>
|
|
203
|
+
<Show
|
|
204
|
+
when={props.locked && open() && !props.defer}
|
|
205
|
+
fallback={
|
|
206
|
+
<Collapsible.Content>
|
|
207
|
+
<Show when={!props.defer || disclosure.mounted()}>{props.children}</Show>
|
|
208
|
+
</Collapsible.Content>
|
|
209
|
+
}
|
|
210
|
+
>
|
|
211
|
+
<div data-slot="collapsible-content" data-expanded="">
|
|
212
|
+
{props.children}
|
|
213
|
+
</div>
|
|
214
|
+
</Show>
|
|
215
|
+
</Show>
|
|
216
|
+
</Collapsible>
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// SAFETY: tool input is an open per-tool record. GenericTool shows arbitrary keys and decodes each value it reads.
|
|
221
|
+
// oxlint-disable-next-line anti-slop/no-unsafe-dictionary-type -- see SAFETY above
|
|
222
|
+
type GenericToolInput = Record<string, unknown>
|
|
223
|
+
|
|
224
|
+
const labelKeys = ["description", "query", "url", "path", "pattern", "name"]
|
|
225
|
+
|
|
226
|
+
const labelValue = Schema.decodeUnknownOption(Schema.NonEmptyString)
|
|
227
|
+
|
|
228
|
+
const argValue = Schema.decodeUnknownOption(Schema.Union([Schema.String, Schema.Number, Schema.Boolean]))
|
|
229
|
+
|
|
230
|
+
function label(input: GenericToolInput | undefined) {
|
|
231
|
+
return labelKeys.flatMap((key) => Option.toArray(labelValue(input?.[key])))[0]
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function args(input: GenericToolInput | undefined) {
|
|
235
|
+
if (!input) return []
|
|
236
|
+
|
|
237
|
+
return Object.entries(input)
|
|
238
|
+
.filter(([key]) => !labelKeys.includes(key))
|
|
239
|
+
.flatMap(([key, value]) => Option.toArray(argValue(value)).map((arg) => `${key}=${arg}`))
|
|
240
|
+
.slice(0, 3)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function GenericTool(props: { tool: string; status?: string; hideDetails?: boolean; input?: GenericToolInput }) {
|
|
244
|
+
const i18n = useI18n()
|
|
245
|
+
|
|
246
|
+
return (
|
|
247
|
+
<BasicTool
|
|
248
|
+
icon="mcp"
|
|
249
|
+
status={props.status}
|
|
250
|
+
trigger={{
|
|
251
|
+
title: i18n.t("ui.basicTool.called", { tool: props.tool }),
|
|
252
|
+
subtitle: label(props.input),
|
|
253
|
+
args: args(props.input),
|
|
254
|
+
}}
|
|
255
|
+
hideDetails={props.hideDetails}
|
|
256
|
+
/>
|
|
257
|
+
)
|
|
258
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export const COPY_FEEDBACK_MS = 2_000
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A copy button's feedback. `copying` keeps the checkmark of a click inside the feedback window while the next write
|
|
5
|
+
* settles, and `attempt` lets only the latest write and its own reset timer move the button.
|
|
6
|
+
*/
|
|
7
|
+
export type CopyFeedbackState =
|
|
8
|
+
| { readonly status: "idle"; readonly attempts: number }
|
|
9
|
+
| { readonly status: "copying"; readonly attempt: number; readonly copied: boolean }
|
|
10
|
+
| { readonly status: "copied"; readonly attempt: number }
|
|
11
|
+
|
|
12
|
+
export type CopyFeedbackEvent =
|
|
13
|
+
| { readonly type: "copy.requested"; readonly text: string }
|
|
14
|
+
| { readonly type: "copy.succeeded"; readonly attempt: number }
|
|
15
|
+
| { readonly type: "copy.failed"; readonly attempt: number }
|
|
16
|
+
| { readonly type: "reset.due"; readonly attempt: number }
|
|
17
|
+
| { readonly type: "disposed" }
|
|
18
|
+
|
|
19
|
+
export type CopyFeedbackEffect =
|
|
20
|
+
| { readonly type: "write"; readonly attempt: number; readonly text: string }
|
|
21
|
+
| { readonly type: "schedule-reset"; readonly attempt: number; readonly delayMs: number }
|
|
22
|
+
| { readonly type: "clear-reset" }
|
|
23
|
+
|
|
24
|
+
export type CopyFeedbackTransition = {
|
|
25
|
+
readonly state: CopyFeedbackState
|
|
26
|
+
readonly effects: readonly CopyFeedbackEffect[]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const INITIAL_COPY_FEEDBACK_STATE: CopyFeedbackState = Object.freeze({ status: "idle", attempts: 0 })
|
|
30
|
+
|
|
31
|
+
const NO_EFFECTS: readonly CopyFeedbackEffect[] = Object.freeze([])
|
|
32
|
+
|
|
33
|
+
const CLEAR_RESET: CopyFeedbackEffect = Object.freeze({ type: "clear-reset" })
|
|
34
|
+
|
|
35
|
+
export function transitionCopyFeedback(state: CopyFeedbackState, event: CopyFeedbackEvent): CopyFeedbackTransition {
|
|
36
|
+
if (event.type === "copy.requested") {
|
|
37
|
+
if (!event.text) return { state, effects: NO_EFFECTS }
|
|
38
|
+
const attempt = (state.status === "idle" ? state.attempts : state.attempt) + 1
|
|
39
|
+
const write = { type: "write", attempt, text: event.text } as const
|
|
40
|
+
|
|
41
|
+
if (state.status === "copied")
|
|
42
|
+
return { state: { status: "copying", attempt, copied: true }, effects: [CLEAR_RESET, write] }
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
state: { status: "copying", attempt, copied: state.status === "copying" && state.copied },
|
|
46
|
+
effects: [write],
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (state.status === "idle") return { state, effects: NO_EFFECTS }
|
|
51
|
+
|
|
52
|
+
if (event.type === "disposed")
|
|
53
|
+
return {
|
|
54
|
+
state: { status: "idle", attempts: state.attempt },
|
|
55
|
+
effects: state.status === "copied" ? [CLEAR_RESET] : NO_EFFECTS,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (event.attempt !== state.attempt) return { state, effects: NO_EFFECTS }
|
|
59
|
+
|
|
60
|
+
if (event.type === "copy.succeeded") {
|
|
61
|
+
if (state.status !== "copying") return { state, effects: NO_EFFECTS }
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
state: { status: "copied", attempt: state.attempt },
|
|
65
|
+
effects: [{ type: "schedule-reset", attempt: state.attempt, delayMs: COPY_FEEDBACK_MS }],
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (event.type === "copy.failed" && state.status !== "copying") return { state, effects: NO_EFFECTS }
|
|
70
|
+
|
|
71
|
+
if (event.type === "reset.due" && state.status !== "copied") return { state, effects: NO_EFFECTS }
|
|
72
|
+
|
|
73
|
+
return { state: { status: "idle", attempts: state.attempt }, effects: NO_EFFECTS }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function viewCopyFeedback(state: CopyFeedbackState) {
|
|
77
|
+
return { copied: state.status === "copied" || (state.status === "copying" && state.copied) }
|
|
78
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { createMemo, createSignal, onCleanup, untrack } from "solid-js"
|
|
2
|
+
import {
|
|
3
|
+
INITIAL_COPY_FEEDBACK_STATE,
|
|
4
|
+
transitionCopyFeedback,
|
|
5
|
+
viewCopyFeedback,
|
|
6
|
+
type CopyFeedbackEffect,
|
|
7
|
+
type CopyFeedbackEvent,
|
|
8
|
+
} from "./copy-machine"
|
|
9
|
+
|
|
10
|
+
// `navigator.clipboard` exists only in secure contexts, so plain-HTTP LAN origins copy through a selected textarea.
|
|
11
|
+
export async function writeClipboard(text: string): Promise<boolean> {
|
|
12
|
+
const written = await navigator.clipboard?.writeText(text).then(
|
|
13
|
+
() => true,
|
|
14
|
+
() => false,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
if (written) return true
|
|
18
|
+
// The textarea sits beside the focused element so a focus trap, such as an open menu's, keeps its selection.
|
|
19
|
+
const active = document.activeElement instanceof HTMLElement ? document.activeElement : undefined
|
|
20
|
+
const host = active && active !== document.body ? (active.parentElement ?? document.body) : document.body
|
|
21
|
+
const textarea = document.createElement("textarea")
|
|
22
|
+
textarea.value = text
|
|
23
|
+
textarea.setAttribute("readonly", "")
|
|
24
|
+
textarea.setAttribute("aria-hidden", "true")
|
|
25
|
+
textarea.tabIndex = -1
|
|
26
|
+
textarea.style.position = "fixed"
|
|
27
|
+
textarea.style.opacity = "0"
|
|
28
|
+
textarea.style.pointerEvents = "none"
|
|
29
|
+
host.appendChild(textarea)
|
|
30
|
+
textarea.select()
|
|
31
|
+
const copied = document.execCommand("copy")
|
|
32
|
+
textarea.remove()
|
|
33
|
+
active?.focus({ preventScroll: true })
|
|
34
|
+
|
|
35
|
+
return copied
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** "Copied" feedback for one copy button. Owner cleanup clears the timer and ignores a write still in flight. */
|
|
39
|
+
export function createCopyFeedback(options?: {
|
|
40
|
+
write: (text: string) => Promise<boolean | void>
|
|
41
|
+
onError: () => void
|
|
42
|
+
}) {
|
|
43
|
+
const write = options?.write ?? writeClipboard
|
|
44
|
+
|
|
45
|
+
const [state, setState] = createSignal(INITIAL_COPY_FEEDBACK_STATE)
|
|
46
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
47
|
+
|
|
48
|
+
const dispatch = (event: CopyFeedbackEvent) => {
|
|
49
|
+
const next = transitionCopyFeedback(untrack(state), event)
|
|
50
|
+
|
|
51
|
+
if (next.state === untrack(state)) return
|
|
52
|
+
setState(next.state)
|
|
53
|
+
|
|
54
|
+
if (event.type === "copy.failed") options?.onError()
|
|
55
|
+
next.effects.forEach(run)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const run = (effect: CopyFeedbackEffect) => {
|
|
59
|
+
if (effect.type === "clear-reset") {
|
|
60
|
+
clearTimeout(timer)
|
|
61
|
+
timer = undefined
|
|
62
|
+
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (effect.type === "schedule-reset") {
|
|
67
|
+
timer = setTimeout(() => dispatch({ type: "reset.due", attempt: effect.attempt }), effect.delayMs)
|
|
68
|
+
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
void Promise.try(() => write(effect.text)).then(
|
|
73
|
+
(written) => dispatch({ type: written === false ? "copy.failed" : "copy.succeeded", attempt: effect.attempt }),
|
|
74
|
+
() => dispatch({ type: "copy.failed", attempt: effect.attempt }),
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
onCleanup(() => dispatch({ type: "disposed" }))
|
|
79
|
+
const view = createMemo(() => viewCopyFeedback(state()))
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
copied: () => view().copied,
|
|
83
|
+
copy: (text: string) => dispatch({ type: "copy.requested", text }),
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useDialog } from "@zyro-sec/ui/context/dialog"
|
|
2
|
+
import { DiagramPreview } from "@zyro-sec/ui/diagram-preview"
|
|
3
|
+
|
|
4
|
+
// Opens a rendered Mermaid diagram maximized when its button is pressed. The preview gets its own copy, so the diagram
|
|
5
|
+
// in the message stays where it is, and keeps updating while it streams.
|
|
6
|
+
export function createDiagramPreview() {
|
|
7
|
+
const dialog = useDialog()
|
|
8
|
+
|
|
9
|
+
return (root: HTMLElement) => {
|
|
10
|
+
const open = (event: MouseEvent) => {
|
|
11
|
+
const button = event.target instanceof Element && event.target.closest('[data-slot="markdown-mermaid-maximize"]')
|
|
12
|
+
|
|
13
|
+
if (!button) return
|
|
14
|
+
|
|
15
|
+
const svg = button.parentElement
|
|
16
|
+
?.querySelector(':scope > [data-component="markdown-mermaid"] > svg')
|
|
17
|
+
?.cloneNode(true)
|
|
18
|
+
|
|
19
|
+
if (!(svg instanceof SVGSVGElement)) return
|
|
20
|
+
event.preventDefault()
|
|
21
|
+
dialog.show(() => <DiagramPreview svg={svg} />)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
root.addEventListener("click", open)
|
|
25
|
+
|
|
26
|
+
return () => root.removeEventListener("click", open)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/** Where an open disclosure's body is: shown at once, waiting for a frame, or mounted after one. */
|
|
2
|
+
export type DisclosureMount =
|
|
3
|
+
| { readonly phase: "immediate" }
|
|
4
|
+
| { readonly phase: "scheduled"; readonly attempt: number }
|
|
5
|
+
| { readonly phase: "mounted" }
|
|
6
|
+
|
|
7
|
+
/** `deferred` shares one frame-spaced queue across the timeline; `frame` waits a single frame. */
|
|
8
|
+
export type DisclosureQueue = "deferred" | "frame"
|
|
9
|
+
|
|
10
|
+
export type DisclosureProps = {
|
|
11
|
+
readonly open: boolean | undefined
|
|
12
|
+
readonly defaultOpen: boolean
|
|
13
|
+
readonly forceOpen: boolean
|
|
14
|
+
readonly defer: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type DisclosureCapabilities = {
|
|
18
|
+
readonly locked: boolean
|
|
19
|
+
readonly pending: boolean
|
|
20
|
+
readonly allowOpenWhilePending: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type Shared = {
|
|
24
|
+
/** `controlled` while the owner passes `open`; a toggle then only asks the owner. */
|
|
25
|
+
readonly control: "controlled" | "uncontrolled"
|
|
26
|
+
/** The user toggled an uncontrolled disclosure, so it no longer follows `defaultOpen`. */
|
|
27
|
+
readonly touched: boolean
|
|
28
|
+
/** `forceOpen` was on at the last sync, so only its next rising edge opens again. */
|
|
29
|
+
readonly forced: boolean
|
|
30
|
+
/** Scheduled body mounts; a frame whose attempt is not the current one is stale. */
|
|
31
|
+
readonly attempts: number
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type DisclosureState =
|
|
35
|
+
| (Shared & { readonly status: "closed" })
|
|
36
|
+
| (Shared & { readonly status: "open"; readonly mount: DisclosureMount })
|
|
37
|
+
|
|
38
|
+
export type DisclosureEvent =
|
|
39
|
+
| { readonly type: "props.sync"; readonly props: DisclosureProps }
|
|
40
|
+
| {
|
|
41
|
+
readonly type: "toggle.requested"
|
|
42
|
+
readonly open: boolean
|
|
43
|
+
readonly defer: boolean
|
|
44
|
+
readonly capabilities: DisclosureCapabilities
|
|
45
|
+
}
|
|
46
|
+
| { readonly type: "mount.ready"; readonly attempt: number }
|
|
47
|
+
| { readonly type: "disposed" }
|
|
48
|
+
|
|
49
|
+
export type DisclosureEffect =
|
|
50
|
+
| { readonly type: "notify"; readonly open: boolean }
|
|
51
|
+
| { readonly type: "schedule-mount"; readonly attempt: number; readonly queue: DisclosureQueue }
|
|
52
|
+
| { readonly type: "cancel-mount"; readonly attempt: number }
|
|
53
|
+
|
|
54
|
+
export type DisclosureTransition = {
|
|
55
|
+
readonly state: DisclosureState
|
|
56
|
+
readonly effects: readonly DisclosureEffect[]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const NO_EFFECTS: readonly DisclosureEffect[] = Object.freeze([])
|
|
60
|
+
|
|
61
|
+
/** The first open state. `queue` is how a body that starts open and deferred waits for its first frame. */
|
|
62
|
+
export function createDisclosureState(props: DisclosureProps, queue: DisclosureQueue): DisclosureTransition {
|
|
63
|
+
const control = props.open === undefined ? "uncontrolled" : "controlled"
|
|
64
|
+
const open = props.open ?? (props.forceOpen || props.defaultOpen)
|
|
65
|
+
const shared = { control, touched: props.forceOpen && control === "uncontrolled", forced: props.forceOpen } as const
|
|
66
|
+
const notify = props.forceOpen && props.open === false ? [{ type: "notify" as const, open: true }] : []
|
|
67
|
+
|
|
68
|
+
if (!open) return { state: { ...shared, status: "closed", attempts: 0 }, effects: notify }
|
|
69
|
+
|
|
70
|
+
if (!props.defer)
|
|
71
|
+
return { state: { ...shared, status: "open", attempts: 0, mount: { phase: "immediate" } }, effects: notify }
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
state: { ...shared, status: "open", attempts: 1, mount: { phase: "scheduled", attempt: 1 } },
|
|
75
|
+
effects: [...notify, { type: "schedule-mount", attempt: 1, queue }],
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function transitionDisclosure(state: DisclosureState, event: DisclosureEvent): DisclosureTransition {
|
|
80
|
+
if (event.type === "props.sync") return sync(state, event.props)
|
|
81
|
+
|
|
82
|
+
if (event.type === "mount.ready") {
|
|
83
|
+
if (state.status !== "open" || state.mount.phase !== "scheduled" || state.mount.attempt !== event.attempt)
|
|
84
|
+
return { state, effects: NO_EFFECTS }
|
|
85
|
+
|
|
86
|
+
return { state: { ...state, mount: { phase: "mounted" } }, effects: NO_EFFECTS }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (event.type === "disposed") {
|
|
90
|
+
const closed = {
|
|
91
|
+
status: "closed",
|
|
92
|
+
control: state.control,
|
|
93
|
+
touched: false,
|
|
94
|
+
forced: false,
|
|
95
|
+
attempts: state.attempts,
|
|
96
|
+
} as const
|
|
97
|
+
|
|
98
|
+
return { state: closed, effects: cancel(state) }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const open = state.status === "open"
|
|
102
|
+
|
|
103
|
+
if (event.capabilities.locked || (event.capabilities.pending && !event.capabilities.allowOpenWhilePending))
|
|
104
|
+
return { state, effects: NO_EFFECTS }
|
|
105
|
+
|
|
106
|
+
if (event.open === open) {
|
|
107
|
+
if (state.control === "controlled" || state.touched) return { state, effects: NO_EFFECTS }
|
|
108
|
+
|
|
109
|
+
return { state: { ...state, touched: true }, effects: NO_EFFECTS }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// The owner of a controlled disclosure decides; it answers with a new `open` prop.
|
|
113
|
+
if (state.control === "controlled") return { state, effects: [{ type: "notify", open: event.open }] }
|
|
114
|
+
|
|
115
|
+
const next = move(state, event.open, event.defer)
|
|
116
|
+
|
|
117
|
+
return { state: { ...next.state, touched: true }, effects: [...next.effects, { type: "notify", open: event.open }] }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function viewDisclosure(state: DisclosureState, capabilities: DisclosureCapabilities) {
|
|
121
|
+
const open = state.status === "open"
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
open,
|
|
125
|
+
mounted: open && state.mount.phase !== "scheduled",
|
|
126
|
+
canToggle: !capabilities.locked && (!capabilities.pending || capabilities.allowOpenWhilePending),
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function sync(state: DisclosureState, props: DisclosureProps): DisclosureTransition {
|
|
131
|
+
const control = props.open === undefined ? "uncontrolled" : "controlled"
|
|
132
|
+
const rising = props.forceOpen && !state.forced
|
|
133
|
+
// A forced open counts as the user's: it stays open once `forceOpen` drops.
|
|
134
|
+
const touched = control === "uncontrolled" && state.control === "uncontrolled" && (state.touched || rising)
|
|
135
|
+
const open = props.open ?? (touched ? rising || state.status === "open" : props.defaultOpen)
|
|
136
|
+
const notify = rising && state.status === "closed" ? [{ type: "notify" as const, open: true }] : []
|
|
137
|
+
const next = move(state, open, props.defer)
|
|
138
|
+
|
|
139
|
+
if (
|
|
140
|
+
next.state === state &&
|
|
141
|
+
state.control === control &&
|
|
142
|
+
state.touched === touched &&
|
|
143
|
+
state.forced === props.forceOpen &&
|
|
144
|
+
notify.length === 0
|
|
145
|
+
)
|
|
146
|
+
return { state, effects: NO_EFFECTS }
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
state: { ...next.state, control, touched, forced: props.forceOpen },
|
|
150
|
+
effects: [...next.effects, ...notify],
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function move(state: DisclosureState, open: boolean, defer: boolean): DisclosureTransition {
|
|
155
|
+
if (!open) {
|
|
156
|
+
if (state.status === "closed") return { state, effects: NO_EFFECTS }
|
|
157
|
+
|
|
158
|
+
const closed = {
|
|
159
|
+
status: "closed",
|
|
160
|
+
control: state.control,
|
|
161
|
+
touched: state.touched,
|
|
162
|
+
forced: state.forced,
|
|
163
|
+
attempts: state.attempts,
|
|
164
|
+
} as const
|
|
165
|
+
|
|
166
|
+
return { state: closed, effects: cancel(state) }
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (state.status === "open") {
|
|
170
|
+
if (defer || state.mount.phase !== "scheduled") return { state, effects: NO_EFFECTS }
|
|
171
|
+
|
|
172
|
+
return { state: { ...state, mount: { phase: "immediate" } }, effects: cancel(state) }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!defer) return { state: { ...state, status: "open", mount: { phase: "immediate" } }, effects: NO_EFFECTS }
|
|
176
|
+
const attempt = state.attempts + 1
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
state: { ...state, status: "open", attempts: attempt, mount: { phase: "scheduled", attempt } },
|
|
180
|
+
effects: [{ type: "schedule-mount", attempt, queue: "frame" }],
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function cancel(state: DisclosureState): readonly DisclosureEffect[] {
|
|
185
|
+
if (state.status !== "open" || state.mount.phase !== "scheduled") return NO_EFFECTS
|
|
186
|
+
|
|
187
|
+
return [{ type: "cancel-mount", attempt: state.mount.attempt }]
|
|
188
|
+
}
|