@zyro-sec/session-ui 0.0.0-stage → 1.0.3
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,448 @@
|
|
|
1
|
+
import { getDirectory, getFilename } from "@zyro-sec/util/path"
|
|
2
|
+
import {
|
|
3
|
+
createComputed,
|
|
4
|
+
createEffect,
|
|
5
|
+
createMemo,
|
|
6
|
+
createSignal,
|
|
7
|
+
For,
|
|
8
|
+
on,
|
|
9
|
+
onCleanup,
|
|
10
|
+
onMount,
|
|
11
|
+
Show,
|
|
12
|
+
splitProps,
|
|
13
|
+
untrack,
|
|
14
|
+
type JSX,
|
|
15
|
+
} from "solid-js"
|
|
16
|
+
import {
|
|
17
|
+
createLineCommentEditorState,
|
|
18
|
+
MENTION_TIMEOUT_MS,
|
|
19
|
+
parseMentionToken,
|
|
20
|
+
transitionLineCommentEditor,
|
|
21
|
+
viewLineCommentEditor,
|
|
22
|
+
type LineCommentEditorConfig,
|
|
23
|
+
type LineCommentEditorEffect,
|
|
24
|
+
type LineCommentEditorEvent,
|
|
25
|
+
} from "@zyro-sec/ui/line-comment/machine"
|
|
26
|
+
import { Button } from "@zyro-sec/ui/button"
|
|
27
|
+
import { FileIcon } from "@zyro-sec/ui/file-icon"
|
|
28
|
+
import { Icon } from "@zyro-sec/ui/icon"
|
|
29
|
+
import { installLineCommentStyles } from "./line-comment-styles"
|
|
30
|
+
import { useI18n } from "@zyro-sec/ui/context/i18n"
|
|
31
|
+
|
|
32
|
+
installLineCommentStyles()
|
|
33
|
+
|
|
34
|
+
export type LineCommentVariant = "default" | "editor"
|
|
35
|
+
|
|
36
|
+
function InlineGlyph(props: { icon: "comment" | "plus" }) {
|
|
37
|
+
return (
|
|
38
|
+
<svg data-slot="line-comment-icon" viewBox="0 0 20 20" fill="none" aria-hidden="true">
|
|
39
|
+
<Show
|
|
40
|
+
when={props.icon === "comment"}
|
|
41
|
+
fallback={
|
|
42
|
+
<path
|
|
43
|
+
d="M10 5.41699V10.0003M10 10.0003V14.5837M10 10.0003H5.4165M10 10.0003H14.5832"
|
|
44
|
+
stroke="currentColor"
|
|
45
|
+
stroke-linecap="square"
|
|
46
|
+
/>
|
|
47
|
+
}
|
|
48
|
+
>
|
|
49
|
+
<path d="M16.25 3.75H3.75V16.25L6.875 14.4643H16.25V3.75Z" stroke="currentColor" stroke-linecap="square" />
|
|
50
|
+
</Show>
|
|
51
|
+
</svg>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type LineCommentAnchorProps = {
|
|
56
|
+
id?: string
|
|
57
|
+
top?: number
|
|
58
|
+
inline?: boolean
|
|
59
|
+
hideButton?: boolean
|
|
60
|
+
open: boolean
|
|
61
|
+
variant?: LineCommentVariant
|
|
62
|
+
icon?: "comment" | "plus"
|
|
63
|
+
buttonLabel?: string
|
|
64
|
+
onClick?: (event: MouseEvent) => void
|
|
65
|
+
onMouseEnter?: (event: MouseEvent) => void
|
|
66
|
+
onPopoverFocusOut?: (event: FocusEvent) => void
|
|
67
|
+
class?: string
|
|
68
|
+
popoverClass?: string
|
|
69
|
+
children?: JSX.Element
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const LineCommentAnchor = (props: LineCommentAnchorProps) => {
|
|
73
|
+
const hidden = () => !props.inline && props.top === undefined
|
|
74
|
+
const variant = () => props.variant ?? "default"
|
|
75
|
+
const icon = () => props.icon ?? "comment"
|
|
76
|
+
const inlineBody = () => props.inline && props.hideButton
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div
|
|
80
|
+
data-component="line-comment"
|
|
81
|
+
data-prevent-autofocus=""
|
|
82
|
+
data-variant={variant()}
|
|
83
|
+
data-comment-id={props.id}
|
|
84
|
+
data-open={props.open ? "" : undefined}
|
|
85
|
+
data-inline={props.inline ? "" : undefined}
|
|
86
|
+
classList={{
|
|
87
|
+
[props.class ?? ""]: !!props.class,
|
|
88
|
+
}}
|
|
89
|
+
style={
|
|
90
|
+
props.inline
|
|
91
|
+
? undefined
|
|
92
|
+
: {
|
|
93
|
+
top: `${props.top ?? 0}px`,
|
|
94
|
+
opacity: hidden() ? 0 : 1,
|
|
95
|
+
"pointer-events": hidden() ? "none" : "auto",
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
>
|
|
99
|
+
<Show
|
|
100
|
+
when={inlineBody()}
|
|
101
|
+
fallback={
|
|
102
|
+
<>
|
|
103
|
+
<button
|
|
104
|
+
type="button"
|
|
105
|
+
aria-label={props.buttonLabel}
|
|
106
|
+
data-slot="line-comment-button"
|
|
107
|
+
onMouseDown={(event) => event.stopPropagation()}
|
|
108
|
+
onMouseUp={(event) => event.stopPropagation()}
|
|
109
|
+
onClick={props.onClick}
|
|
110
|
+
onMouseEnter={props.onMouseEnter}
|
|
111
|
+
>
|
|
112
|
+
<Show
|
|
113
|
+
when={props.inline}
|
|
114
|
+
fallback={<Icon name={icon()} />}
|
|
115
|
+
>
|
|
116
|
+
<InlineGlyph icon={icon()} />
|
|
117
|
+
</Show>
|
|
118
|
+
</button>
|
|
119
|
+
<Show when={props.open}>
|
|
120
|
+
<div
|
|
121
|
+
data-slot="line-comment-popover"
|
|
122
|
+
classList={{
|
|
123
|
+
[props.popoverClass ?? ""]: !!props.popoverClass,
|
|
124
|
+
}}
|
|
125
|
+
onMouseDown={(event) => event.stopPropagation()}
|
|
126
|
+
onFocusOut={props.onPopoverFocusOut}
|
|
127
|
+
>
|
|
128
|
+
{props.children}
|
|
129
|
+
</div>
|
|
130
|
+
</Show>
|
|
131
|
+
</>
|
|
132
|
+
}
|
|
133
|
+
>
|
|
134
|
+
<div
|
|
135
|
+
data-slot="line-comment-popover"
|
|
136
|
+
data-inline-body=""
|
|
137
|
+
classList={{
|
|
138
|
+
[props.popoverClass ?? ""]: !!props.popoverClass,
|
|
139
|
+
}}
|
|
140
|
+
onMouseDown={(event) => event.stopPropagation()}
|
|
141
|
+
onClick={props.onClick}
|
|
142
|
+
onMouseEnter={props.onMouseEnter}
|
|
143
|
+
onFocusOut={props.onPopoverFocusOut}
|
|
144
|
+
>
|
|
145
|
+
{props.children}
|
|
146
|
+
</div>
|
|
147
|
+
</Show>
|
|
148
|
+
</div>
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export type LineCommentProps = Omit<LineCommentAnchorProps, "children" | "variant"> & {
|
|
153
|
+
comment: JSX.Element
|
|
154
|
+
selection: JSX.Element
|
|
155
|
+
actions?: JSX.Element
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export const LineComment = (props: LineCommentProps) => {
|
|
159
|
+
const i18n = useI18n()
|
|
160
|
+
const [split, rest] = splitProps(props, ["comment", "selection", "actions"])
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<LineCommentAnchor {...rest} variant="default" hideButton={props.inline}>
|
|
164
|
+
<div data-slot="line-comment-content">
|
|
165
|
+
<div data-slot="line-comment-head">
|
|
166
|
+
<div data-slot="line-comment-text">{split.comment}</div>
|
|
167
|
+
<Show when={split.actions}>
|
|
168
|
+
<div data-slot="line-comment-tools">{split.actions}</div>
|
|
169
|
+
</Show>
|
|
170
|
+
</div>
|
|
171
|
+
<div data-slot="line-comment-label">
|
|
172
|
+
{i18n.t("ui.lineComment.label.prefix")}
|
|
173
|
+
{split.selection}
|
|
174
|
+
{i18n.t("ui.lineComment.label.suffix")}
|
|
175
|
+
</div>
|
|
176
|
+
</div>
|
|
177
|
+
</LineCommentAnchor>
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export type LineCommentEditorProps = Omit<LineCommentAnchorProps, "children" | "open" | "variant" | "onClick"> & {
|
|
182
|
+
value: string
|
|
183
|
+
selection: JSX.Element
|
|
184
|
+
onInput: (value: string) => void
|
|
185
|
+
onCancel: VoidFunction
|
|
186
|
+
onSubmit: (value: string) => void
|
|
187
|
+
placeholder?: string
|
|
188
|
+
rows?: number
|
|
189
|
+
autofocus?: boolean
|
|
190
|
+
cancelLabel?: string
|
|
191
|
+
submitLabel?: string
|
|
192
|
+
mention?: {
|
|
193
|
+
items: (query: string) => string[] | Promise<string[]>
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export const LineCommentEditor = (props: LineCommentEditorProps) => {
|
|
198
|
+
const i18n = useI18n()
|
|
199
|
+
|
|
200
|
+
const [split, rest] = splitProps(props, [
|
|
201
|
+
"value",
|
|
202
|
+
"selection",
|
|
203
|
+
"onInput",
|
|
204
|
+
"onCancel",
|
|
205
|
+
"onSubmit",
|
|
206
|
+
"placeholder",
|
|
207
|
+
"rows",
|
|
208
|
+
"autofocus",
|
|
209
|
+
"cancelLabel",
|
|
210
|
+
"submitLabel",
|
|
211
|
+
"mention",
|
|
212
|
+
])
|
|
213
|
+
|
|
214
|
+
let textareaRef: HTMLTextAreaElement | undefined
|
|
215
|
+
|
|
216
|
+
let mentionTimer: ReturnType<typeof setTimeout> | undefined
|
|
217
|
+
let focusFrame: number | undefined
|
|
218
|
+
const [editorState, setEditorState] = createSignal(createLineCommentEditorState())
|
|
219
|
+
|
|
220
|
+
const readConfig = (): LineCommentEditorConfig => ({
|
|
221
|
+
value: split.value,
|
|
222
|
+
allowEmpty: false,
|
|
223
|
+
variant: "default",
|
|
224
|
+
alternateSubmit: null,
|
|
225
|
+
submitting: false,
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
const view = createMemo(() => viewLineCommentEditor(editorState(), readConfig()))
|
|
229
|
+
|
|
230
|
+
const currentToken = () =>
|
|
231
|
+
split.mention && textareaRef
|
|
232
|
+
? parseMentionToken(textareaRef.value, textareaRef.selectionStart, textareaRef.selectionEnd)
|
|
233
|
+
: null
|
|
234
|
+
|
|
235
|
+
const dispatch = (event: LineCommentEditorEvent) => {
|
|
236
|
+
const transition = transitionLineCommentEditor(untrack(editorState), event)
|
|
237
|
+
setEditorState(transition.state)
|
|
238
|
+
|
|
239
|
+
if (transition.state.status !== "mention-loading") clearTimeout(mentionTimer)
|
|
240
|
+
transition.effects.forEach(run)
|
|
241
|
+
|
|
242
|
+
return transition.handled
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const run = (effect: LineCommentEditorEffect) => {
|
|
246
|
+
if (effect.type === "mention.load") {
|
|
247
|
+
const attempt = effect.attempt
|
|
248
|
+
clearTimeout(mentionTimer)
|
|
249
|
+
mentionTimer = setTimeout(() => dispatch({ type: "mention.timeout", attempt }), MENTION_TIMEOUT_MS)
|
|
250
|
+
// A search that returns, rejects or throws settles its attempt.
|
|
251
|
+
void Promise.resolve()
|
|
252
|
+
.then(() => untrack(() => split.mention?.items(effect.query) ?? []))
|
|
253
|
+
.then(
|
|
254
|
+
(items) => dispatch({ type: "mention.loaded", attempt, items }),
|
|
255
|
+
() => dispatch({ type: "mention.failed", attempt }),
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
return
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (effect.type === "mention.insert") {
|
|
262
|
+
const textarea = textareaRef
|
|
263
|
+
|
|
264
|
+
if (!textarea) return
|
|
265
|
+
const value = `${textarea.value.slice(0, effect.token.start)}@${effect.path} ${textarea.value.slice(effect.token.end)}`
|
|
266
|
+
split.onInput(value)
|
|
267
|
+
scheduleFocus(effect.token.start + effect.path.length + 2)
|
|
268
|
+
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (effect.type === "submit") return split.onSubmit(effect.value)
|
|
273
|
+
|
|
274
|
+
if (effect.blur) textareaRef?.blur()
|
|
275
|
+
split.onCancel()
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const scheduleFocus = (cursor?: number) => {
|
|
279
|
+
if (focusFrame !== undefined) cancelAnimationFrame(focusFrame)
|
|
280
|
+
focusFrame = requestAnimationFrame(() => {
|
|
281
|
+
focusFrame = undefined
|
|
282
|
+
|
|
283
|
+
if (untrack(editorState).status === "disposed") return
|
|
284
|
+
textareaRef?.focus()
|
|
285
|
+
|
|
286
|
+
if (cursor !== undefined) textareaRef?.setSelectionRange(cursor, cursor)
|
|
287
|
+
})
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const syncMention = () => dispatch({ type: "mention.synced", token: currentToken() })
|
|
291
|
+
|
|
292
|
+
const focus = () => textareaRef?.focus()
|
|
293
|
+
|
|
294
|
+
const hold: JSX.EventHandlerUnion<HTMLButtonElement, MouseEvent> = (e) => {
|
|
295
|
+
e.preventDefault()
|
|
296
|
+
e.stopPropagation()
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const click =
|
|
300
|
+
(fn: VoidFunction): JSX.EventHandlerUnion<HTMLButtonElement, MouseEvent> =>
|
|
301
|
+
(e) => {
|
|
302
|
+
e.stopPropagation()
|
|
303
|
+
fn()
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const cancel = () => dispatch({ type: "cancel.requested" })
|
|
307
|
+
const submit = () => dispatch({ type: "submit.requested", config: readConfig() })
|
|
308
|
+
|
|
309
|
+
createComputed(
|
|
310
|
+
on(
|
|
311
|
+
() => !!split.mention,
|
|
312
|
+
() => dispatch({ type: "props.synced", config: readConfig(), token: currentToken() }),
|
|
313
|
+
),
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
// An owner that resets or rewrites the value closes a mention list the new text no longer has.
|
|
317
|
+
createEffect(
|
|
318
|
+
on(
|
|
319
|
+
() => split.value,
|
|
320
|
+
() => dispatch({ type: "props.synced", config: readConfig(), token: currentToken() }),
|
|
321
|
+
{ defer: true },
|
|
322
|
+
),
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
onMount(() => {
|
|
326
|
+
if (split.autofocus === false) return
|
|
327
|
+
scheduleFocus()
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
onCleanup(() => {
|
|
331
|
+
if (focusFrame !== undefined) cancelAnimationFrame(focusFrame)
|
|
332
|
+
clearTimeout(mentionTimer)
|
|
333
|
+
dispatch({ type: "disposed" })
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
return (
|
|
337
|
+
<LineCommentAnchor {...rest} open={true} variant="editor" hideButton={props.inline} onClick={() => focus()}>
|
|
338
|
+
<div data-slot="line-comment-editor">
|
|
339
|
+
<textarea
|
|
340
|
+
ref={(el) => {
|
|
341
|
+
textareaRef = el
|
|
342
|
+
}}
|
|
343
|
+
data-slot="line-comment-textarea"
|
|
344
|
+
// Escape here closes the mention list or cancels the comment, not a dialog or popover around the editor.
|
|
345
|
+
data-owns-escape
|
|
346
|
+
dir="auto"
|
|
347
|
+
rows={split.rows ?? 3}
|
|
348
|
+
placeholder={split.placeholder ?? i18n.t("ui.lineComment.placeholder")}
|
|
349
|
+
value={split.value}
|
|
350
|
+
style={{ "unicode-bidi": "plaintext", "text-align": "start" }}
|
|
351
|
+
on:input={(event) => {
|
|
352
|
+
split.onInput(event.currentTarget.value)
|
|
353
|
+
syncMention()
|
|
354
|
+
}}
|
|
355
|
+
on:click={() => syncMention()}
|
|
356
|
+
on:select={() => syncMention()}
|
|
357
|
+
on:keydown={(event) => {
|
|
358
|
+
if (event.isComposing || event.keyCode === 229) return
|
|
359
|
+
event.stopPropagation()
|
|
360
|
+
|
|
361
|
+
const handled = dispatch({
|
|
362
|
+
type: "key.down",
|
|
363
|
+
target: "textarea",
|
|
364
|
+
key: event.key,
|
|
365
|
+
ctrl: event.ctrlKey,
|
|
366
|
+
meta: event.metaKey,
|
|
367
|
+
alt: event.altKey,
|
|
368
|
+
shift: event.shiftKey,
|
|
369
|
+
repeat: event.repeat,
|
|
370
|
+
config: readConfig(),
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
if (handled) event.preventDefault()
|
|
374
|
+
}}
|
|
375
|
+
/>
|
|
376
|
+
<Show when={view().mentionItems.length > 0}>
|
|
377
|
+
<div data-slot="line-comment-mention-list">
|
|
378
|
+
<For each={view().mentionItems}>
|
|
379
|
+
{(path, index) => {
|
|
380
|
+
const directory = path.endsWith("/") ? path : getDirectory(path)
|
|
381
|
+
const name = path.endsWith("/") ? "" : getFilename(path)
|
|
382
|
+
|
|
383
|
+
return (
|
|
384
|
+
<button
|
|
385
|
+
type="button"
|
|
386
|
+
data-slot="line-comment-mention-item"
|
|
387
|
+
data-active={view().activeMentionPath === path ? "" : undefined}
|
|
388
|
+
on:mousedown={(event) => event.preventDefault()}
|
|
389
|
+
on:mouseenter={() => dispatch({ type: "mention.hovered", index: index() })}
|
|
390
|
+
on:click={() => dispatch({ type: "mention.selected", index: index() })}
|
|
391
|
+
>
|
|
392
|
+
<FileIcon node={{ path, type: "file" }} class="shrink-0 size-4" />
|
|
393
|
+
<div data-slot="line-comment-mention-path">
|
|
394
|
+
<span data-slot="line-comment-mention-dir">{directory}</span>
|
|
395
|
+
<Show when={name}>
|
|
396
|
+
<span data-slot="line-comment-mention-file">{name}</span>
|
|
397
|
+
</Show>
|
|
398
|
+
</div>
|
|
399
|
+
</button>
|
|
400
|
+
)
|
|
401
|
+
}}
|
|
402
|
+
</For>
|
|
403
|
+
</div>
|
|
404
|
+
</Show>
|
|
405
|
+
<div data-slot="line-comment-actions">
|
|
406
|
+
<div data-slot="line-comment-editor-label">
|
|
407
|
+
{i18n.t("ui.lineComment.editorLabel.prefix")}
|
|
408
|
+
{split.selection}
|
|
409
|
+
{i18n.t("ui.lineComment.editorLabel.suffix")}
|
|
410
|
+
</div>
|
|
411
|
+
<Show
|
|
412
|
+
when={!props.inline}
|
|
413
|
+
fallback={
|
|
414
|
+
<>
|
|
415
|
+
<button
|
|
416
|
+
type="button"
|
|
417
|
+
data-slot="line-comment-action"
|
|
418
|
+
data-variant="ghost"
|
|
419
|
+
onMouseDown={hold}
|
|
420
|
+
onClick={click(cancel)}
|
|
421
|
+
>
|
|
422
|
+
{split.cancelLabel ?? i18n.t("ui.common.cancel")}
|
|
423
|
+
</button>
|
|
424
|
+
<button
|
|
425
|
+
type="button"
|
|
426
|
+
data-slot="line-comment-action"
|
|
427
|
+
data-variant="primary"
|
|
428
|
+
disabled={!view().canSubmit}
|
|
429
|
+
onMouseDown={hold}
|
|
430
|
+
onClick={click(submit)}
|
|
431
|
+
>
|
|
432
|
+
{split.submitLabel ?? i18n.t("ui.lineComment.submit")}
|
|
433
|
+
</button>
|
|
434
|
+
</>
|
|
435
|
+
}
|
|
436
|
+
>
|
|
437
|
+
<Button size="small" variant="ghost" onClick={cancel}>
|
|
438
|
+
{split.cancelLabel ?? i18n.t("ui.common.cancel")}
|
|
439
|
+
</Button>
|
|
440
|
+
<Button size="small" variant="contrast" disabled={!view().canSubmit} onClick={submit}>
|
|
441
|
+
{split.submitLabel ?? i18n.t("ui.lineComment.submit")}
|
|
442
|
+
</Button>
|
|
443
|
+
</Show>
|
|
444
|
+
</div>
|
|
445
|
+
</div>
|
|
446
|
+
</LineCommentAnchor>
|
|
447
|
+
)
|
|
448
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Splits plain text into runs, marking each http(s) URL with its link target. */
|
|
2
|
+
export function linkSegments(text: string) {
|
|
3
|
+
const result: { text: string; href?: string }[] = []
|
|
4
|
+
let last = 0
|
|
5
|
+
|
|
6
|
+
for (const match of text.matchAll(/https?:\/\/[^\s<>"'`]+/g)) {
|
|
7
|
+
// Sentence punctuation and closing brackets after a URL are almost never part of it.
|
|
8
|
+
const href = match[0].replace(/[),.;:!?\]]+$/, "")
|
|
9
|
+
|
|
10
|
+
if (!URL.canParse(href)) continue
|
|
11
|
+
|
|
12
|
+
if (match.index > last) result.push({ text: text.slice(last, match.index) })
|
|
13
|
+
result.push({ text: href, href })
|
|
14
|
+
last = match.index + href.length
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (last < text.length) result.push({ text: text.slice(last) })
|
|
18
|
+
|
|
19
|
+
return result
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Index, Show, createMemo } from "solid-js"
|
|
2
|
+
import { linkSegments } from "./link-segments"
|
|
3
|
+
|
|
4
|
+
/** Plain text with every http(s) URL rendered as a link that opens outside the app. */
|
|
5
|
+
export function LinkedText(props: { text: string }) {
|
|
6
|
+
const segments = createMemo(() => linkSegments(props.text))
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<Index each={segments()}>
|
|
10
|
+
{(segment) => (
|
|
11
|
+
<Show when={segment().href} fallback={segment().text}>
|
|
12
|
+
{(href) => (
|
|
13
|
+
<a data-slot="linked-text-link" href={href()} target="_blank" rel="noopener noreferrer">
|
|
14
|
+
{segment().text}
|
|
15
|
+
</a>
|
|
16
|
+
)}
|
|
17
|
+
</Show>
|
|
18
|
+
)}
|
|
19
|
+
</Index>
|
|
20
|
+
)
|
|
21
|
+
}
|