@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,537 @@
|
|
|
1
|
+
import { createEffect, createMemo, createSignal, onCleanup, onMount } from "solid-js"
|
|
2
|
+
import { makeEventListener } from "@solid-primitives/event-listener"
|
|
3
|
+
import { createResizeObserver } from "@solid-primitives/resize-observer"
|
|
4
|
+
import {
|
|
5
|
+
createFindHostRegistryState,
|
|
6
|
+
INITIAL_FILE_FIND_STATE,
|
|
7
|
+
selectShortcutHost,
|
|
8
|
+
transitionFileFind,
|
|
9
|
+
transitionFindHostRegistry,
|
|
10
|
+
viewFileFind,
|
|
11
|
+
type FileFindEffect,
|
|
12
|
+
type FileFindEvent,
|
|
13
|
+
type FileFindState,
|
|
14
|
+
type FindHostRegistryEffect,
|
|
15
|
+
type FindHostRegistryEvent,
|
|
16
|
+
} from "./file-find-machine"
|
|
17
|
+
|
|
18
|
+
export type FindHost = {
|
|
19
|
+
element: () => HTMLElement | undefined
|
|
20
|
+
open: () => void
|
|
21
|
+
close: () => void
|
|
22
|
+
next: (dir: 1 | -1) => void
|
|
23
|
+
isOpen: () => boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let registry = createFindHostRegistryState<FindHost>()
|
|
27
|
+
|
|
28
|
+
let installed = false
|
|
29
|
+
|
|
30
|
+
function dispatchRegistry(event: FindHostRegistryEvent<FindHost>) {
|
|
31
|
+
const next = transitionFindHostRegistry(registry, event)
|
|
32
|
+
registry = next.state
|
|
33
|
+
next.effects.forEach(runRegistry)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function runRegistry(effect: FindHostRegistryEffect<FindHost>) {
|
|
37
|
+
if (effect.type === "close-host") return effect.host.close()
|
|
38
|
+
|
|
39
|
+
clearHighlightFind()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isEditable(node: EventTarget | null): boolean {
|
|
43
|
+
if (!(node instanceof HTMLElement)) return false
|
|
44
|
+
|
|
45
|
+
if (node.closest("[data-prevent-autofocus]")) return true
|
|
46
|
+
|
|
47
|
+
if (node.isContentEditable) return true
|
|
48
|
+
|
|
49
|
+
return /^(INPUT|TEXTAREA|SELECT|BUTTON)$/.test(node.tagName)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function hostForNode(node: EventTarget | null) {
|
|
53
|
+
if (!(node instanceof Node)) return
|
|
54
|
+
|
|
55
|
+
for (const host of registry.hosts) {
|
|
56
|
+
const el = host.element()
|
|
57
|
+
|
|
58
|
+
if (el && el.isConnected && el.contains(node)) return host
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function installShortcuts() {
|
|
63
|
+
if (installed) return
|
|
64
|
+
|
|
65
|
+
if (typeof window === "undefined") return
|
|
66
|
+
installed = true
|
|
67
|
+
|
|
68
|
+
window.addEventListener(
|
|
69
|
+
"keydown",
|
|
70
|
+
(event) => {
|
|
71
|
+
if (event.defaultPrevented) return
|
|
72
|
+
|
|
73
|
+
if (isEditable(event.target)) return
|
|
74
|
+
|
|
75
|
+
const mod = event.metaKey || event.ctrlKey
|
|
76
|
+
|
|
77
|
+
if (!mod) return
|
|
78
|
+
|
|
79
|
+
const key = event.key.toLowerCase()
|
|
80
|
+
|
|
81
|
+
if (key !== "f" && key !== "g") return
|
|
82
|
+
|
|
83
|
+
const host = selectShortcutHost(
|
|
84
|
+
registry,
|
|
85
|
+
key,
|
|
86
|
+
() => hostForNode(document.activeElement) ?? hostForNode(event.target),
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
if (!host) return
|
|
90
|
+
event.preventDefault()
|
|
91
|
+
event.stopPropagation()
|
|
92
|
+
|
|
93
|
+
if (key === "g") return host.next(event.shiftKey ? -1 : 1)
|
|
94
|
+
host.open()
|
|
95
|
+
},
|
|
96
|
+
{ capture: true },
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function clearHighlightFind() {
|
|
101
|
+
const api = globalThis.CSS?.highlights
|
|
102
|
+
|
|
103
|
+
if (!api) return
|
|
104
|
+
api.delete("opencode-find")
|
|
105
|
+
api.delete("opencode-find-current")
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function supportsHighlights() {
|
|
109
|
+
return "Highlight" in globalThis && !!globalThis.CSS?.highlights
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function scrollParent(el: HTMLElement): HTMLElement | undefined {
|
|
113
|
+
let parent = el.parentElement
|
|
114
|
+
|
|
115
|
+
while (parent) {
|
|
116
|
+
const style = getComputedStyle(parent)
|
|
117
|
+
|
|
118
|
+
if (style.overflowY === "auto" || style.overflowY === "scroll") return parent
|
|
119
|
+
parent = parent.parentElement
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
type CreateFileFindOptions = {
|
|
124
|
+
wrapper: () => HTMLElement | undefined
|
|
125
|
+
overlay: () => HTMLDivElement | undefined
|
|
126
|
+
getRoot: () => ShadowRoot | undefined
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function createFileFind(opts: CreateFileFindOptions) {
|
|
130
|
+
let input: HTMLInputElement | undefined
|
|
131
|
+
let focusFrame: number | undefined
|
|
132
|
+
let overlayFrame: number | undefined
|
|
133
|
+
let posFrame: number | undefined
|
|
134
|
+
let current: FileFindState = INITIAL_FILE_FIND_STATE
|
|
135
|
+
const queue: FileFindEvent[] = []
|
|
136
|
+
const [state, setState] = createSignal(current)
|
|
137
|
+
const [overlayScroll, setOverlayScroll] = createSignal<HTMLElement[]>([])
|
|
138
|
+
|
|
139
|
+
const view = createMemo(() => viewFileFind(state()))
|
|
140
|
+
const open = createMemo(() => view().open)
|
|
141
|
+
const query = createMemo(() => view().query)
|
|
142
|
+
const index = createMemo(() => view().index)
|
|
143
|
+
const count = createMemo(() => view().count)
|
|
144
|
+
const pos = createMemo(() => view().pos)
|
|
145
|
+
|
|
146
|
+
const dispatch = (event: FileFindEvent) => {
|
|
147
|
+
queue.push(event)
|
|
148
|
+
|
|
149
|
+
// Effects dispatch scan results and highlight fallbacks while they run; the outer loop drains them next.
|
|
150
|
+
if (queue.length > 1) return
|
|
151
|
+
|
|
152
|
+
while (queue.length > 0) {
|
|
153
|
+
try {
|
|
154
|
+
const next = transitionFileFind(current, queue[0]!)
|
|
155
|
+
|
|
156
|
+
if (next.state !== current) {
|
|
157
|
+
current = next.state
|
|
158
|
+
setState(current)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
next.effects.forEach(run)
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.error("File find transition failed", error)
|
|
164
|
+
} finally {
|
|
165
|
+
queue.shift()
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const run = (effect: FileFindEffect) => {
|
|
171
|
+
try {
|
|
172
|
+
perform(effect)
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error("File find effect failed", error)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const perform = (effect: FileFindEffect) => {
|
|
179
|
+
if (effect.type === "activate-host") return dispatchRegistry({ type: "host.activated", host })
|
|
180
|
+
|
|
181
|
+
if (effect.type === "deactivate-host") return dispatchRegistry({ type: "host.deactivated", host })
|
|
182
|
+
|
|
183
|
+
if (effect.type === "unregister-host") return dispatchRegistry({ type: "host.unregistered", host })
|
|
184
|
+
|
|
185
|
+
if (effect.type === "schedule-focus") {
|
|
186
|
+
focusFrame = requestAnimationFrame(() => {
|
|
187
|
+
focusFrame = undefined
|
|
188
|
+
dispatch({ type: "focus.frame", attempt: effect.attempt })
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (effect.type === "cancel-focus") return cancelFocus()
|
|
195
|
+
|
|
196
|
+
if (effect.type === "cancel-frames") {
|
|
197
|
+
cancelFocus()
|
|
198
|
+
cancelOverlay()
|
|
199
|
+
|
|
200
|
+
if (posFrame !== undefined) cancelAnimationFrame(posFrame)
|
|
201
|
+
posFrame = undefined
|
|
202
|
+
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (effect.type === "focus-input") {
|
|
207
|
+
input?.focus()
|
|
208
|
+
input?.select()
|
|
209
|
+
|
|
210
|
+
return
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (effect.type === "scan") {
|
|
214
|
+
const root = opts.getRoot()
|
|
215
|
+
|
|
216
|
+
// Without drawn rows there is nothing to search; the viewer refreshes find once its rows mount.
|
|
217
|
+
if (!root) return
|
|
218
|
+
|
|
219
|
+
dispatch({
|
|
220
|
+
type: "matches.measured",
|
|
221
|
+
attempt: effect.attempt,
|
|
222
|
+
matches: scan(root, effect.query),
|
|
223
|
+
cursor: effect.cursor,
|
|
224
|
+
scroll: effect.scroll,
|
|
225
|
+
preferredRenderer: supportsHighlights() ? "highlights" : "overlay",
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (effect.type === "render-marks") {
|
|
232
|
+
if (effect.renderer === "highlights") {
|
|
233
|
+
clearOverlay()
|
|
234
|
+
setOverlayScroll([])
|
|
235
|
+
|
|
236
|
+
if (!setHighlights(effect.matches, effect.index))
|
|
237
|
+
dispatch({ type: "highlights.failed", attempt: effect.attempt })
|
|
238
|
+
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
clearHighlightFind()
|
|
243
|
+
syncOverlayScroll()
|
|
244
|
+
scheduleOverlay()
|
|
245
|
+
|
|
246
|
+
return
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (effect.type === "clear-marks") {
|
|
250
|
+
clearHighlightFind()
|
|
251
|
+
clearOverlay()
|
|
252
|
+
setOverlayScroll([])
|
|
253
|
+
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
scrollToRange(effect.match)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const cancelFocus = () => {
|
|
261
|
+
if (focusFrame !== undefined) cancelAnimationFrame(focusFrame)
|
|
262
|
+
focusFrame = undefined
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const cancelOverlay = () => {
|
|
266
|
+
if (overlayFrame !== undefined) cancelAnimationFrame(overlayFrame)
|
|
267
|
+
overlayFrame = undefined
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const clearOverlay = () => {
|
|
271
|
+
// Cancel first: the overlay element is gone once the viewer unmounts, but its frame is not.
|
|
272
|
+
cancelOverlay()
|
|
273
|
+
const el = opts.overlay()
|
|
274
|
+
|
|
275
|
+
if (!el) return
|
|
276
|
+
el.innerHTML = ""
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const renderOverlay = () => {
|
|
280
|
+
const wrapper = opts.wrapper()
|
|
281
|
+
const overlay = opts.overlay()
|
|
282
|
+
|
|
283
|
+
if (!wrapper || !overlay) return
|
|
284
|
+
|
|
285
|
+
clearOverlay()
|
|
286
|
+
|
|
287
|
+
if (current.status !== "open" || current.renderer !== "overlay" || current.matches.length === 0) return
|
|
288
|
+
|
|
289
|
+
const base = wrapper.getBoundingClientRect()
|
|
290
|
+
const frag = document.createDocumentFragment()
|
|
291
|
+
|
|
292
|
+
for (let i = 0; i < current.matches.length; i++) {
|
|
293
|
+
const range = current.matches[i]
|
|
294
|
+
const active = i === current.index
|
|
295
|
+
|
|
296
|
+
for (const rect of Array.from(range.getClientRects())) {
|
|
297
|
+
if (!rect.width || !rect.height) continue
|
|
298
|
+
|
|
299
|
+
const mark = document.createElement("div")
|
|
300
|
+
mark.style.position = "absolute"
|
|
301
|
+
mark.style.left = `${Math.round(rect.left - base.left)}px`
|
|
302
|
+
mark.style.top = `${Math.round(rect.top - base.top)}px`
|
|
303
|
+
mark.style.width = `${Math.round(rect.width)}px`
|
|
304
|
+
mark.style.height = `${Math.round(rect.height)}px`
|
|
305
|
+
mark.style.borderRadius = "2px"
|
|
306
|
+
mark.style.backgroundColor = active ? "var(--surface-warning-strong)" : "var(--surface-warning-base)"
|
|
307
|
+
mark.style.opacity = active ? "0.55" : "0.35"
|
|
308
|
+
|
|
309
|
+
if (active) mark.style.boxShadow = "inset 0 0 0 1px var(--v2-state-border-warning)"
|
|
310
|
+
frag.appendChild(mark)
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
overlay.appendChild(frag)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function scheduleOverlay() {
|
|
318
|
+
if (current.status !== "open" || current.renderer !== "overlay") return
|
|
319
|
+
|
|
320
|
+
if (overlayFrame !== undefined) return
|
|
321
|
+
|
|
322
|
+
overlayFrame = requestAnimationFrame(() => {
|
|
323
|
+
overlayFrame = undefined
|
|
324
|
+
renderOverlay()
|
|
325
|
+
})
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const syncOverlayScroll = () => {
|
|
329
|
+
const root = opts.getRoot()
|
|
330
|
+
|
|
331
|
+
const next = root
|
|
332
|
+
? Array.from(root.querySelectorAll("[data-code]")).filter(
|
|
333
|
+
(node): node is HTMLElement => node instanceof HTMLElement,
|
|
334
|
+
)
|
|
335
|
+
: []
|
|
336
|
+
|
|
337
|
+
const previous = overlayScroll()
|
|
338
|
+
|
|
339
|
+
if (next.length === previous.length && next.every((el, i) => el === previous[i])) return
|
|
340
|
+
|
|
341
|
+
setOverlayScroll(next)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const positionBar = () => {
|
|
345
|
+
if (typeof window === "undefined") return
|
|
346
|
+
const wrapper = opts.wrapper()
|
|
347
|
+
|
|
348
|
+
if (!wrapper) return
|
|
349
|
+
|
|
350
|
+
const root = scrollParent(wrapper) ?? wrapper
|
|
351
|
+
const rect = root.getBoundingClientRect()
|
|
352
|
+
const title = parseFloat(getComputedStyle(root).getPropertyValue("--session-title-height"))
|
|
353
|
+
const header = Number.isNaN(title) ? 0 : title
|
|
354
|
+
|
|
355
|
+
dispatch({
|
|
356
|
+
type: "position.updated",
|
|
357
|
+
pos: {
|
|
358
|
+
top: Math.round(rect.top) + header - 4,
|
|
359
|
+
right: Math.round(window.innerWidth - rect.right) + 8,
|
|
360
|
+
},
|
|
361
|
+
})
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const scan = (root: ShadowRoot, value: string) => {
|
|
365
|
+
const needle = value.toLowerCase()
|
|
366
|
+
const ranges: Range[] = []
|
|
367
|
+
|
|
368
|
+
const cols = Array.from(root.querySelectorAll("[data-content] [data-line], [data-column-content]")).filter(
|
|
369
|
+
(node): node is HTMLElement => node instanceof HTMLElement,
|
|
370
|
+
)
|
|
371
|
+
|
|
372
|
+
for (const col of cols) {
|
|
373
|
+
const text = col.textContent
|
|
374
|
+
|
|
375
|
+
if (!text) continue
|
|
376
|
+
|
|
377
|
+
const hay = text.toLowerCase()
|
|
378
|
+
let at = hay.indexOf(needle)
|
|
379
|
+
|
|
380
|
+
if (at === -1) continue
|
|
381
|
+
|
|
382
|
+
const nodes: Text[] = []
|
|
383
|
+
const ends: number[] = []
|
|
384
|
+
const walker = document.createTreeWalker(col, NodeFilter.SHOW_TEXT)
|
|
385
|
+
let node = walker.nextNode()
|
|
386
|
+
let pos = 0
|
|
387
|
+
|
|
388
|
+
while (node) {
|
|
389
|
+
if (node instanceof Text) {
|
|
390
|
+
pos += node.data.length
|
|
391
|
+
nodes.push(node)
|
|
392
|
+
ends.push(pos)
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
node = walker.nextNode()
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (nodes.length === 0) continue
|
|
399
|
+
|
|
400
|
+
const locate = (offset: number) => {
|
|
401
|
+
let lo = 0
|
|
402
|
+
let hi = ends.length - 1
|
|
403
|
+
|
|
404
|
+
while (lo < hi) {
|
|
405
|
+
const mid = (lo + hi) >> 1
|
|
406
|
+
|
|
407
|
+
if (ends[mid] >= offset) hi = mid
|
|
408
|
+
else lo = mid + 1
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const prev = lo === 0 ? 0 : ends[lo - 1]
|
|
412
|
+
|
|
413
|
+
return { node: nodes[lo], offset: offset - prev }
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
while (at !== -1) {
|
|
417
|
+
const start = locate(at)
|
|
418
|
+
const end = locate(at + value.length)
|
|
419
|
+
const range = document.createRange()
|
|
420
|
+
range.setStart(start.node, start.offset)
|
|
421
|
+
range.setEnd(end.node, end.offset)
|
|
422
|
+
ranges.push(range)
|
|
423
|
+
at = hay.indexOf(needle, at + value.length)
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return ranges
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const scrollToRange = (range: Range) => {
|
|
431
|
+
const start = range.startContainer
|
|
432
|
+
const el = start instanceof Element ? start : start.parentElement
|
|
433
|
+
el?.scrollIntoView({ block: "center", inline: "center" })
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const setHighlights = (ranges: readonly Range[], currentIndex: number) => {
|
|
437
|
+
const api = globalThis.CSS?.highlights
|
|
438
|
+
|
|
439
|
+
if (!api || !("Highlight" in globalThis)) return false
|
|
440
|
+
|
|
441
|
+
api.delete("opencode-find")
|
|
442
|
+
api.delete("opencode-find-current")
|
|
443
|
+
|
|
444
|
+
const active = ranges[currentIndex]
|
|
445
|
+
|
|
446
|
+
if (active) api.set("opencode-find-current", new Highlight(active))
|
|
447
|
+
|
|
448
|
+
const rest = ranges.filter((_, i) => i !== currentIndex)
|
|
449
|
+
|
|
450
|
+
if (rest.length > 0) api.set("opencode-find", new Highlight(...rest))
|
|
451
|
+
|
|
452
|
+
return true
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const focus = () =>
|
|
456
|
+
dispatch({ type: "open.requested", preferredRenderer: supportsHighlights() ? "highlights" : "overlay" })
|
|
457
|
+
|
|
458
|
+
const close = () => dispatch({ type: "close.requested" })
|
|
459
|
+
|
|
460
|
+
const next = (dir: 1 | -1) =>
|
|
461
|
+
dispatch({
|
|
462
|
+
type: "next.requested",
|
|
463
|
+
dir,
|
|
464
|
+
stale: current.status === "open" && current.matches.some((range) => !range.startContainer.isConnected),
|
|
465
|
+
})
|
|
466
|
+
|
|
467
|
+
const host: FindHost = {
|
|
468
|
+
element: opts.wrapper,
|
|
469
|
+
isOpen: () => current.status === "open",
|
|
470
|
+
next,
|
|
471
|
+
open: focus,
|
|
472
|
+
close,
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
createEffect(() => {
|
|
476
|
+
for (const el of overlayScroll()) makeEventListener(el, "scroll", scheduleOverlay, { passive: true })
|
|
477
|
+
})
|
|
478
|
+
|
|
479
|
+
onMount(() => {
|
|
480
|
+
installShortcuts()
|
|
481
|
+
dispatchRegistry({ type: "host.registered", host })
|
|
482
|
+
})
|
|
483
|
+
|
|
484
|
+
createEffect(() => {
|
|
485
|
+
if (!open()) return
|
|
486
|
+
|
|
487
|
+
const update = () => {
|
|
488
|
+
posFrame = undefined
|
|
489
|
+
positionBar()
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
posFrame = requestAnimationFrame(update)
|
|
493
|
+
makeEventListener(window, "resize", positionBar, { passive: true })
|
|
494
|
+
|
|
495
|
+
const wrapper = opts.wrapper()
|
|
496
|
+
|
|
497
|
+
if (!wrapper) return
|
|
498
|
+
const root = scrollParent(wrapper) ?? wrapper
|
|
499
|
+
createResizeObserver(root, positionBar)
|
|
500
|
+
})
|
|
501
|
+
|
|
502
|
+
onCleanup(() => dispatch({ type: "disposed" }))
|
|
503
|
+
|
|
504
|
+
return {
|
|
505
|
+
open,
|
|
506
|
+
query,
|
|
507
|
+
count,
|
|
508
|
+
index,
|
|
509
|
+
pos,
|
|
510
|
+
setInput: (el: HTMLInputElement) => {
|
|
511
|
+
input = el
|
|
512
|
+
},
|
|
513
|
+
setQuery: (value: string) => dispatch({ type: "query.changed", query: value }),
|
|
514
|
+
focus,
|
|
515
|
+
close,
|
|
516
|
+
next,
|
|
517
|
+
refresh: (args?: { reset?: boolean; scroll?: boolean }) =>
|
|
518
|
+
dispatch({ type: "refresh.requested", reset: !!args?.reset, scroll: !!args?.scroll }),
|
|
519
|
+
onPointerDown: () => {
|
|
520
|
+
dispatchRegistry({ type: "host.preferred", host })
|
|
521
|
+
opts.wrapper()?.focus({ preventScroll: true })
|
|
522
|
+
},
|
|
523
|
+
onFocus: () => dispatchRegistry({ type: "host.preferred", host }),
|
|
524
|
+
onInputKeyDown: (event: KeyboardEvent) => {
|
|
525
|
+
if (event.key === "Escape") {
|
|
526
|
+
event.preventDefault()
|
|
527
|
+
close()
|
|
528
|
+
|
|
529
|
+
return
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
if (event.key !== "Enter") return
|
|
533
|
+
event.preventDefault()
|
|
534
|
+
next(event.shiftKey ? -1 : 1)
|
|
535
|
+
},
|
|
536
|
+
}
|
|
537
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function getViewerHost(container: HTMLElement | undefined) {
|
|
2
|
+
if (!container) return
|
|
3
|
+
const host = container.querySelector("diffs-container")
|
|
4
|
+
|
|
5
|
+
if (!(host instanceof HTMLElement)) return
|
|
6
|
+
|
|
7
|
+
return host
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function getViewerRoot(container: HTMLElement | undefined) {
|
|
11
|
+
return getViewerHost(container)?.shadowRoot ?? undefined
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function applyViewerScheme(host: HTMLElement | undefined) {
|
|
15
|
+
if (!host) return
|
|
16
|
+
|
|
17
|
+
if (typeof document === "undefined") return
|
|
18
|
+
|
|
19
|
+
const scheme = document.documentElement.dataset.colorScheme
|
|
20
|
+
|
|
21
|
+
if (scheme === "dark" || scheme === "light") {
|
|
22
|
+
host.dataset.colorScheme = scheme
|
|
23
|
+
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
host.removeAttribute("data-color-scheme")
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function observeViewerScheme(getHost: () => HTMLElement | undefined) {
|
|
31
|
+
if (typeof document === "undefined") return () => {}
|
|
32
|
+
|
|
33
|
+
applyViewerScheme(getHost())
|
|
34
|
+
|
|
35
|
+
if (typeof MutationObserver === "undefined") return () => {}
|
|
36
|
+
|
|
37
|
+
const root = document.documentElement
|
|
38
|
+
const monitor = new MutationObserver(() => applyViewerScheme(getHost()))
|
|
39
|
+
monitor.observe(root, { attributes: true, attributeFilter: ["data-color-scheme"] })
|
|
40
|
+
|
|
41
|
+
return () => monitor.disconnect()
|
|
42
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { type SelectedLineRange } from "@pierre/diffs"
|
|
2
|
+
import { toRange } from "./selection-bridge"
|
|
3
|
+
|
|
4
|
+
export function findElement(node: Node | null): HTMLElement | undefined {
|
|
5
|
+
if (!node) return
|
|
6
|
+
|
|
7
|
+
if (node instanceof HTMLElement) return node
|
|
8
|
+
|
|
9
|
+
return node.parentElement ?? undefined
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function findFileLineNumber(node: Node | null): number | undefined {
|
|
13
|
+
const el = findElement(node)
|
|
14
|
+
|
|
15
|
+
if (!el) return
|
|
16
|
+
|
|
17
|
+
const line = el.closest("[data-line]")
|
|
18
|
+
|
|
19
|
+
if (!(line instanceof HTMLElement)) return
|
|
20
|
+
|
|
21
|
+
const value = parseInt(line.dataset.line ?? "", 10)
|
|
22
|
+
|
|
23
|
+
if (Number.isNaN(value)) return
|
|
24
|
+
|
|
25
|
+
return value
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function findDiffLineNumber(node: Node | null): number | undefined {
|
|
29
|
+
const el = findElement(node)
|
|
30
|
+
|
|
31
|
+
if (!el) return
|
|
32
|
+
|
|
33
|
+
const line = el.closest("[data-line], [data-alt-line]")
|
|
34
|
+
|
|
35
|
+
if (!(line instanceof HTMLElement)) return
|
|
36
|
+
|
|
37
|
+
const primary = parseInt(line.dataset.line ?? "", 10)
|
|
38
|
+
|
|
39
|
+
if (!Number.isNaN(primary)) return primary
|
|
40
|
+
|
|
41
|
+
const alt = parseInt(line.dataset.altLine ?? "", 10)
|
|
42
|
+
|
|
43
|
+
if (!Number.isNaN(alt)) return alt
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function findCodeSelectionSide(node: Node | null): SelectedLineRange["side"] {
|
|
47
|
+
const el = findElement(node)
|
|
48
|
+
|
|
49
|
+
if (!el) return
|
|
50
|
+
|
|
51
|
+
const code = el.closest("[data-code]")
|
|
52
|
+
|
|
53
|
+
if (!(code instanceof HTMLElement)) return
|
|
54
|
+
|
|
55
|
+
if (code.hasAttribute("data-deletions")) return "deletions"
|
|
56
|
+
|
|
57
|
+
return "additions"
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
type ComposedSelection = {
|
|
61
|
+
getComposedRanges?: (options?: { shadowRoots?: ShadowRoot[] }) => StaticRange[]
|
|
62
|
+
direction?: string
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The lines under the browser's text selection in a viewer's shadow root, with the selected text's DOM range. */
|
|
66
|
+
export function readShadowLineSelection(opts: {
|
|
67
|
+
root: ShadowRoot
|
|
68
|
+
lineForNode: (node: Node | null) => number | undefined
|
|
69
|
+
sideForNode?: (node: Node | null) => SelectedLineRange["side"]
|
|
70
|
+
}) {
|
|
71
|
+
// Chromium exposes `getSelection` on shadow roots and `getComposedRanges` on selections; the DOM types do not list them.
|
|
72
|
+
const root: ShadowRoot & { getSelection?: () => Selection | null } = opts.root
|
|
73
|
+
const selection: (Selection & ComposedSelection) | null = root.getSelection?.() ?? window.getSelection()
|
|
74
|
+
|
|
75
|
+
if (!selection || selection.isCollapsed) return
|
|
76
|
+
|
|
77
|
+
const domRange =
|
|
78
|
+
selection.getComposedRanges?.({ shadowRoots: [opts.root] })?.[0] ??
|
|
79
|
+
(selection.rangeCount > 0 ? selection.getRangeAt(0) : undefined)
|
|
80
|
+
|
|
81
|
+
if (!domRange) return
|
|
82
|
+
|
|
83
|
+
if (!opts.root.contains(domRange.startContainer) || !opts.root.contains(domRange.endContainer)) return
|
|
84
|
+
|
|
85
|
+
// A triple click, or a drag that stops at the start of the next line, ends on a line with nothing selected in it.
|
|
86
|
+
const startLine = selectedLine(domRange.startContainer, domRange.startOffset, false)
|
|
87
|
+
const endLine = selectedLine(domRange.endContainer, domRange.endOffset, true)
|
|
88
|
+
const span = startLine?.row !== endLine?.row
|
|
89
|
+
const startNode = (span && startLine?.empty) || domRange.startContainer
|
|
90
|
+
const endNode = (span && endLine?.empty) || domRange.endContainer
|
|
91
|
+
|
|
92
|
+
const start = opts.lineForNode(startNode)
|
|
93
|
+
const end = opts.lineForNode(endNode)
|
|
94
|
+
|
|
95
|
+
if (start === undefined || end === undefined) return
|
|
96
|
+
|
|
97
|
+
const startSide = opts.sideForNode?.(startNode)
|
|
98
|
+
const endSide = opts.sideForNode?.(endNode)
|
|
99
|
+
const side = startSide ?? endSide
|
|
100
|
+
|
|
101
|
+
const range: SelectedLineRange = { start, end }
|
|
102
|
+
|
|
103
|
+
if (side) range.side = side
|
|
104
|
+
|
|
105
|
+
if (endSide && side && endSide !== side) range.endSide = endSide
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
range,
|
|
109
|
+
text: toRange(domRange),
|
|
110
|
+
backward: selection.direction === "backward",
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The line row holding one end of a selection. `empty` is the neighbouring row to read instead when no character of
|
|
116
|
+
* this row is selected: the previous row for the end, the next one for the start.
|
|
117
|
+
*/
|
|
118
|
+
function selectedLine(node: Node, offset: number, end: boolean) {
|
|
119
|
+
const row = findElement(node)?.closest("[data-line], [data-alt-line]")
|
|
120
|
+
|
|
121
|
+
if (!row) return
|
|
122
|
+
const part = new Range()
|
|
123
|
+
|
|
124
|
+
if (end) {
|
|
125
|
+
part.setStart(row, 0)
|
|
126
|
+
part.setEnd(node, offset)
|
|
127
|
+
} else {
|
|
128
|
+
part.setStart(node, offset)
|
|
129
|
+
part.setEnd(row, row.childNodes.length)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (part.toString() !== "") return { row }
|
|
133
|
+
|
|
134
|
+
let next = end ? row.previousElementSibling : row.nextElementSibling
|
|
135
|
+
|
|
136
|
+
while (next && !next.matches("[data-line], [data-alt-line]"))
|
|
137
|
+
next = end ? next.previousElementSibling : next.nextElementSibling
|
|
138
|
+
|
|
139
|
+
return { row, empty: next ?? undefined }
|
|
140
|
+
}
|