@deepseek-ai/dsh-experimental-client-ui-forge 0.2.2-alpha.3 → 0.2.2-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +8 -8
- package/README.md +41 -14
- package/README.zh.md +40 -13
- package/lib/client.js +13 -11800
- package/lib/client.js.map +1 -0
- package/lib/index.js +1340 -115
- package/lib/typert.host.js +1715 -212
- package/lib/typert.remote-client.d.ts +42 -5
- package/lib/typert.remote-client.d.ts.map +1 -0
- package/lib/typert.remote-client.js +1523 -244
- package/lib/types/client/ActionToast.d.ts.map +1 -0
- package/lib/types/client/ActionToast.js.map +1 -0
- package/lib/types/client/BaseMenu.d.ts +30 -0
- package/lib/types/client/BaseMenu.d.ts.map +1 -0
- package/lib/types/client/BaseMenu.js.map +1 -0
- package/lib/types/client/ChangeRequestCard.d.ts +9 -5
- package/lib/types/client/ChangeRequestCard.d.ts.map +1 -0
- package/lib/types/client/ChangeRequestCard.js.map +1 -0
- package/lib/types/client/ChangeRequestOverview.d.ts +124 -0
- package/lib/types/client/ChangeRequestOverview.d.ts.map +1 -0
- package/lib/types/client/ChangeRequestOverview.js.map +1 -0
- package/lib/types/client/ChangedFiles.d.ts +2 -0
- package/lib/types/client/ChangedFiles.d.ts.map +1 -0
- package/lib/types/client/ChangedFiles.js.map +1 -0
- package/lib/types/client/ChangesTab.d.ts +30 -5
- package/lib/types/client/ChangesTab.d.ts.map +1 -0
- package/lib/types/client/ChangesTab.js.map +1 -0
- package/lib/types/client/ChangesTabTitle.d.ts.map +1 -0
- package/lib/types/client/ChangesTabTitle.js.map +1 -0
- package/lib/types/client/CommitMenu.d.ts +41 -0
- package/lib/types/client/CommitMenu.d.ts.map +1 -0
- package/lib/types/client/CommitMenu.js.map +1 -0
- package/lib/types/client/DiffFile.d.ts +47 -15
- package/lib/types/client/DiffFile.d.ts.map +1 -0
- package/lib/types/client/DiffFile.js.map +1 -0
- package/lib/types/client/FileLabel.d.ts.map +1 -0
- package/lib/types/client/FileLabel.js.map +1 -0
- package/lib/types/client/FileTreePane.d.ts +4 -2
- package/lib/types/client/FileTreePane.d.ts.map +1 -0
- package/lib/types/client/FileTreePane.js.map +1 -0
- package/lib/types/client/ForgeTab.d.ts +9 -1
- package/lib/types/client/ForgeTab.d.ts.map +1 -0
- package/lib/types/client/ForgeTab.js.map +1 -0
- package/lib/types/client/ForgeTabTitle.d.ts.map +1 -0
- package/lib/types/client/ForgeTabTitle.js.map +1 -0
- package/lib/types/client/HeaderButton.d.ts.map +1 -0
- package/lib/types/client/HeaderButton.js.map +1 -0
- package/lib/types/client/LocalChangesCard.d.ts.map +1 -0
- package/lib/types/client/LocalChangesCard.js.map +1 -0
- package/lib/types/client/RefreshGlyph.d.ts.map +1 -0
- package/lib/types/client/RefreshGlyph.js.map +1 -0
- package/lib/types/client/ReviewComposer.d.ts +20 -6
- package/lib/types/client/ReviewComposer.d.ts.map +1 -0
- package/lib/types/client/ReviewComposer.js.map +1 -0
- package/lib/types/client/ReviewControls.d.ts +79 -0
- package/lib/types/client/ReviewControls.d.ts.map +1 -0
- package/lib/types/client/ReviewControls.js.map +1 -0
- package/lib/types/client/ReviewThread.d.ts +4 -4
- package/lib/types/client/ReviewThread.d.ts.map +1 -0
- package/lib/types/client/ReviewThread.js.map +1 -0
- package/lib/types/client/ReviewThreads.d.ts +108 -0
- package/lib/types/client/ReviewThreads.d.ts.map +1 -0
- package/lib/types/client/ReviewThreads.js.map +1 -0
- package/lib/types/client/SessionHoverForge.d.ts.map +1 -0
- package/lib/types/client/SessionHoverForge.js.map +1 -0
- package/lib/types/client/SessionRowForge.d.ts +1 -1
- package/lib/types/client/SessionRowForge.d.ts.map +1 -0
- package/lib/types/client/SessionRowForge.js.map +1 -0
- package/lib/types/client/SubmitReview.d.ts +12 -4
- package/lib/types/client/SubmitReview.d.ts.map +1 -0
- package/lib/types/client/SubmitReview.js.map +1 -0
- package/lib/types/client/ThreadList.d.ts +43 -0
- package/lib/types/client/ThreadList.d.ts.map +1 -0
- package/lib/types/client/ThreadList.js.map +1 -0
- package/lib/types/client/ViewOptionsMenu.d.ts +31 -0
- package/lib/types/client/ViewOptionsMenu.d.ts.map +1 -0
- package/lib/types/client/ViewOptionsMenu.js.map +1 -0
- package/lib/types/client/WorktreeProgress.d.ts.map +1 -0
- package/lib/types/client/WorktreeProgress.js.map +1 -0
- package/lib/types/client/WorktreeSettings.d.ts +12 -0
- package/lib/types/client/WorktreeSettings.d.ts.map +1 -0
- package/lib/types/client/WorktreeSettings.js.map +1 -0
- package/lib/types/client/WorktreeToggle.d.ts.map +1 -0
- package/lib/types/client/WorktreeToggle.js.map +1 -0
- package/lib/types/client/changes-address.d.ts.map +1 -0
- package/lib/types/client/changes-address.js.map +1 -0
- package/lib/types/client/changes-store.d.ts +20 -5
- package/lib/types/client/changes-store.d.ts.map +1 -0
- package/lib/types/client/changes-store.js.map +1 -0
- package/lib/types/client/checkout.d.ts.map +1 -0
- package/lib/types/client/checkout.js.map +1 -0
- package/lib/types/client/code-selection.d.ts.map +1 -0
- package/lib/types/client/code-selection.js.map +1 -0
- package/lib/types/client/diff-rows.d.ts.map +1 -0
- package/lib/types/client/diff-rows.js.map +1 -0
- package/lib/types/client/file-tree.d.ts.map +1 -0
- package/lib/types/client/file-tree.js.map +1 -0
- package/lib/types/client/format.d.ts.map +1 -0
- package/lib/types/client/format.js.map +1 -0
- package/lib/types/client/glyphs.d.ts +4 -2
- package/lib/types/client/glyphs.d.ts.map +1 -0
- package/lib/types/client/glyphs.js.map +1 -0
- package/lib/types/client/host-viewed.d.ts +84 -0
- package/lib/types/client/host-viewed.d.ts.map +1 -0
- package/lib/types/client/host-viewed.js.map +1 -0
- package/lib/types/client/index.d.ts.map +1 -0
- package/lib/types/client/index.js.map +1 -0
- package/lib/types/client/locales.d.ts +175 -3
- package/lib/types/client/locales.d.ts.map +1 -0
- package/lib/types/client/locales.js.map +1 -0
- package/lib/types/client/menu-search.d.ts +10 -0
- package/lib/types/client/menu-search.d.ts.map +1 -0
- package/lib/types/client/menu-search.js.map +1 -0
- package/lib/types/client/mount.d.ts +4 -0
- package/lib/types/client/mount.d.ts.map +1 -0
- package/lib/types/client/mount.js.map +1 -0
- package/lib/types/client/review-queue.d.ts +5 -8
- package/lib/types/client/review-queue.d.ts.map +1 -0
- package/lib/types/client/review-queue.js.map +1 -0
- package/lib/types/client/review-threads.d.ts +108 -0
- package/lib/types/client/review-threads.d.ts.map +1 -0
- package/lib/types/client/review-threads.js.map +1 -0
- package/lib/types/client/review.d.ts +31 -4
- package/lib/types/client/review.d.ts.map +1 -0
- package/lib/types/client/review.js.map +1 -0
- package/lib/types/client/section-reach.d.ts +26 -0
- package/lib/types/client/section-reach.d.ts.map +1 -0
- package/lib/types/client/section-reach.js.map +1 -0
- package/lib/types/client/session-list.d.ts.map +1 -0
- package/lib/types/client/session-list.js.map +1 -0
- package/lib/types/client/source.d.ts.map +1 -0
- package/lib/types/client/source.js.map +1 -0
- package/lib/types/client/status.d.ts.map +1 -0
- package/lib/types/client/status.js.map +1 -0
- package/lib/types/client/thread-state.d.ts +68 -0
- package/lib/types/client/thread-state.d.ts.map +1 -0
- package/lib/types/client/thread-state.js.map +1 -0
- package/lib/types/client/toolbar-fold.d.ts +19 -0
- package/lib/types/client/toolbar-fold.d.ts.map +1 -0
- package/lib/types/client/toolbar-fold.js.map +1 -0
- package/lib/types/client/viewed-files.d.ts +70 -0
- package/lib/types/client/viewed-files.d.ts.map +1 -0
- package/lib/types/client/viewed-files.js.map +1 -0
- package/lib/types/client/worktree-settings-form.d.ts +32 -0
- package/lib/types/client/worktree-settings-form.d.ts.map +1 -0
- package/lib/types/client/worktree-settings-form.js.map +1 -0
- package/lib/types/commit-range.d.ts +17 -0
- package/lib/types/commit-range.d.ts.map +1 -0
- package/lib/types/commit-range.js.map +1 -0
- package/lib/types/diff.d.ts +10 -2
- package/lib/types/diff.d.ts.map +1 -0
- package/lib/types/diff.js.map +1 -0
- package/lib/types/git.d.ts.map +1 -0
- package/lib/types/git.js.map +1 -0
- package/lib/types/index.d.ts +194 -14
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/layers.d.ts +66 -0
- package/lib/types/layers.d.ts.map +1 -0
- package/lib/types/layers.js.map +1 -0
- package/lib/types/local-diff.d.ts +54 -6
- package/lib/types/local-diff.d.ts.map +1 -0
- package/lib/types/local-diff.js.map +1 -0
- package/lib/types/panel.d.ts.map +1 -0
- package/lib/types/panel.js.map +1 -0
- package/lib/types/parse.d.ts +16 -0
- package/lib/types/parse.d.ts.map +1 -0
- package/lib/types/parse.js.map +1 -0
- package/lib/types/patch-cache.d.ts +12 -7
- package/lib/types/patch-cache.d.ts.map +1 -0
- package/lib/types/patch-cache.js.map +1 -0
- package/lib/types/review-cache.d.ts +54 -0
- package/lib/types/review-cache.d.ts.map +1 -0
- package/lib/types/review-cache.js.map +1 -0
- package/lib/types/states.d.ts.map +1 -0
- package/lib/types/states.js.map +1 -0
- package/lib/types/types.d.ts +113 -11
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js.map +1 -0
- package/lib/types/wildmatch.d.ts +14 -0
- package/lib/types/wildmatch.d.ts.map +1 -0
- package/lib/types/wildmatch.js.map +1 -0
- package/lib/types/worktree.d.ts +8 -6
- package/lib/types/worktree.d.ts.map +1 -0
- package/lib/types/worktree.js.map +1 -0
- package/package.json +59 -49
- package/src/client/ActionToast.tsx +38 -0
- package/src/client/BaseMenu.module.css +153 -0
- package/src/client/BaseMenu.tsx +180 -0
- package/src/client/ChangeRequestCard.tsx +439 -0
- package/src/client/ChangeRequestOverview.module.css +196 -0
- package/src/client/ChangeRequestOverview.tsx +620 -0
- package/src/client/ChangedFiles.module.css +26 -0
- package/src/client/ChangedFiles.tsx +144 -0
- package/src/client/ChangesTab.module.css +984 -0
- package/src/client/ChangesTab.tsx +1288 -0
- package/src/client/ChangesTabTitle.tsx +28 -0
- package/src/client/CommitMenu.module.css +139 -0
- package/src/client/CommitMenu.tsx +186 -0
- package/src/client/DiffFile.tsx +621 -0
- package/src/client/FileLabel.module.css +53 -0
- package/src/client/FileLabel.tsx +66 -0
- package/src/client/FileTreePane.module.css +10 -0
- package/src/client/FileTreePane.tsx +79 -0
- package/src/client/ForgeTab.module.css +627 -0
- package/src/client/ForgeTab.tsx +263 -0
- package/src/client/ForgeTabTitle.tsx +21 -0
- package/src/client/HeaderButton.module.css +29 -0
- package/src/client/HeaderButton.tsx +68 -0
- package/src/client/LocalChangesCard.tsx +83 -0
- package/src/client/RefreshGlyph.module.css +22 -0
- package/src/client/RefreshGlyph.tsx +35 -0
- package/src/client/ReviewComposer.module.css +37 -0
- package/src/client/ReviewComposer.tsx +128 -0
- package/src/client/ReviewControls.module.css +162 -0
- package/src/client/ReviewControls.tsx +191 -0
- package/src/client/ReviewThread.tsx +96 -0
- package/src/client/ReviewThreads.module.css +326 -0
- package/src/client/ReviewThreads.tsx +443 -0
- package/src/client/SessionHoverForge.tsx +72 -0
- package/src/client/SessionList.module.css +85 -0
- package/src/client/SessionRowForge.tsx +86 -0
- package/src/client/SubmitReview.module.css +26 -0
- package/src/client/SubmitReview.tsx +95 -0
- package/src/client/ThreadList.module.css +218 -0
- package/src/client/ThreadList.tsx +165 -0
- package/src/client/ViewOptionsMenu.tsx +79 -0
- package/src/client/WorktreeProgress.module.css +226 -0
- package/src/client/WorktreeProgress.tsx +280 -0
- package/src/client/WorktreeSettings.module.css +29 -0
- package/src/client/WorktreeSettings.tsx +42 -0
- package/src/client/WorktreeToggle.module.css +132 -0
- package/src/client/WorktreeToggle.tsx +165 -0
- package/src/client/changes-address.ts +110 -0
- package/src/client/changes-store.ts +155 -0
- package/src/client/checkout.ts +75 -0
- package/src/client/code-selection.ts +53 -0
- package/src/client/diff-rows.ts +199 -0
- package/src/client/file-tree.ts +86 -0
- package/src/client/format.ts +37 -0
- package/src/client/glyphs.tsx +151 -0
- package/src/client/host-viewed.ts +195 -0
- package/src/client/index.ts +31 -0
- package/src/client/locales.ts +3446 -0
- package/src/client/menu-search.ts +16 -0
- package/src/client/mount.ts +439 -0
- package/src/client/review-queue.ts +256 -0
- package/src/client/review-threads.ts +204 -0
- package/src/client/review.ts +120 -0
- package/src/client/section-reach.ts +61 -0
- package/src/client/session-list.ts +79 -0
- package/src/client/source.ts +274 -0
- package/src/client/status.ts +171 -0
- package/src/client/thread-state.ts +127 -0
- package/src/client/toolbar-fold.ts +70 -0
- package/src/client/viewed-files.ts +178 -0
- package/src/client/worktree-settings-form.ts +43 -0
- package/src/commit-range.ts +27 -0
- package/src/css-modules.d.ts +5 -0
- package/src/diff.ts +162 -0
- package/src/git.ts +293 -0
- package/src/index.ts +1162 -0
- package/src/layers.ts +163 -0
- package/src/local-diff.ts +438 -0
- package/src/panel.ts +422 -0
- package/src/parse.ts +137 -0
- package/src/patch-cache.ts +73 -0
- package/src/review-cache.ts +98 -0
- package/src/states.ts +350 -0
- package/src/types.ts +504 -0
- package/src/wildmatch.ts +121 -0
- package/src/worktree.ts +576 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/** New Session option: start the Session in a new worktree, from a chosen local branch. */
|
|
2
|
+
|
|
3
|
+
import { useState, type ReactNode } from 'react'
|
|
4
|
+
import clsx from 'clsx'
|
|
5
|
+
import { IconBranchOutlineRegular, IconChevronDownOutlineRegular, Menu, Tooltip } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
6
|
+
import type { MenuEntry } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
7
|
+
import type { HostObservable, InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
|
8
|
+
import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
9
|
+
import type { ForgeBranches, ForgePanelState, ForgeWorktreeBlocker } from '../types.ts'
|
|
10
|
+
import type { NS } from './locales.ts'
|
|
11
|
+
import type { PanelSnapshot } from './source.ts'
|
|
12
|
+
import css from './WorktreeToggle.module.css'
|
|
13
|
+
|
|
14
|
+
/** Business face of the New Session option. */
|
|
15
|
+
export interface WorktreeToggleInjected {
|
|
16
|
+
/** Panel snapshot of the Session; the renderer binds it as `usePanel`. */
|
|
17
|
+
readonly hooks: { readonly panel: HostObservable<PanelSnapshot> }
|
|
18
|
+
/**
|
|
19
|
+
* Request a worktree from a base branch, replacing an open request.
|
|
20
|
+
* @param from - base branch, or null for HEAD.
|
|
21
|
+
* @returns whether the Host accepted it.
|
|
22
|
+
*/
|
|
23
|
+
readonly request: (from: string | null) => Promise<boolean>
|
|
24
|
+
/**
|
|
25
|
+
* Withdraw the open request.
|
|
26
|
+
* @returns whether the Host accepted it.
|
|
27
|
+
*/
|
|
28
|
+
readonly cancel: () => Promise<boolean>
|
|
29
|
+
/**
|
|
30
|
+
* List the local branches of the Session's checkout.
|
|
31
|
+
* @returns the branches, or undefined when they could not be read.
|
|
32
|
+
*/
|
|
33
|
+
readonly branches: () => Promise<ForgeBranches | undefined>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Full props of the New Session option. */
|
|
37
|
+
export type WorktreeToggleProps = InjectFace<WorktreeToggleInjected> & PropsLocale<typeof NS>
|
|
38
|
+
|
|
39
|
+
type Translate = WorktreeToggleProps['t']
|
|
40
|
+
|
|
41
|
+
function BaseMenu({ base, held, branches, request, t }: {
|
|
42
|
+
readonly base: string | null
|
|
43
|
+
/** Whether the worktree is being created, which freezes the base. */
|
|
44
|
+
readonly held: boolean
|
|
45
|
+
readonly branches: WorktreeToggleInjected['branches']
|
|
46
|
+
readonly request: WorktreeToggleInjected['request']
|
|
47
|
+
readonly t: Translate
|
|
48
|
+
}): ReactNode {
|
|
49
|
+
const [listed, setListed] = useState<ForgeBranches | null>(null)
|
|
50
|
+
const [open, setOpen] = useState(false)
|
|
51
|
+
const [loading, setLoading] = useState(false)
|
|
52
|
+
const show = (): void => {
|
|
53
|
+
if (open) {
|
|
54
|
+
setOpen(false)
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
setLoading(true)
|
|
58
|
+
void branches().then((result) => {
|
|
59
|
+
setLoading(false)
|
|
60
|
+
if (result === undefined) return
|
|
61
|
+
setListed(result)
|
|
62
|
+
setOpen(true)
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
const items: MenuEntry[] = [
|
|
66
|
+
{ type: 'label', id: 'title', text: t('worktree.baseMenu') },
|
|
67
|
+
...(listed?.branches ?? []).map(name => ({
|
|
68
|
+
id: name,
|
|
69
|
+
label: name === listed?.current
|
|
70
|
+
? <span className={css.option}><span className={css.optionName}>{name}</span><span className={css.optionNote}>{t('worktree.currentBranch')}</span></span>
|
|
71
|
+
: <span className={css.optionName}>{name}</span>,
|
|
72
|
+
})),
|
|
73
|
+
]
|
|
74
|
+
return (
|
|
75
|
+
<Menu
|
|
76
|
+
open={open}
|
|
77
|
+
items={items}
|
|
78
|
+
selectedId={base ?? undefined}
|
|
79
|
+
onSelect={(id) => {
|
|
80
|
+
setOpen(false)
|
|
81
|
+
if (id !== base) void request(id)
|
|
82
|
+
}}
|
|
83
|
+
onClose={() => { setOpen(false) }}
|
|
84
|
+
side="bottom"
|
|
85
|
+
align="end"
|
|
86
|
+
portal
|
|
87
|
+
anchor={
|
|
88
|
+
<button type="button" className={css.base} aria-haspopup="menu" aria-expanded={open} disabled={loading || held} onClick={show}>
|
|
89
|
+
<span className={css.baseLabel}>{base === null ? t('worktree.baseHead') : t('worktree.base', { branch: base })}</span>
|
|
90
|
+
<IconChevronDownOutlineRegular size={12} className={clsx(css.chevron, open && css.chevronOpen)} />
|
|
91
|
+
</button>
|
|
92
|
+
}
|
|
93
|
+
/>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** What the option shows for a panel state, or undefined while it stays hidden. */
|
|
98
|
+
function optionOf(state: ForgePanelState | null): {
|
|
99
|
+
readonly blocker: Exclude<ForgeWorktreeBlocker, 'not-git'> | null
|
|
100
|
+
readonly current: string | null
|
|
101
|
+
readonly commit: string | null
|
|
102
|
+
} | undefined {
|
|
103
|
+
if (state === null || !state.worktree.editable) return undefined
|
|
104
|
+
const blocker = state.worktree.blocker
|
|
105
|
+
if (blocker === 'not-git') return undefined
|
|
106
|
+
const checkout = state.checkout
|
|
107
|
+
if (checkout.state !== 'ready') return undefined
|
|
108
|
+
return { blocker, current: checkout.checkout.branch, commit: checkout.checkout.commit }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Render the worktree option while the Session can still start in a worktree:
|
|
113
|
+
* the current branch, or the base branch menu once requested, then the checkbox.
|
|
114
|
+
* A blocked request keeps its selected base visible without a menu; the checkbox
|
|
115
|
+
* only withdraws it. Branch details support pointer, touch, and keyboard access.
|
|
116
|
+
* The request stays fixed while the worktree is being created.
|
|
117
|
+
* @param props - panel snapshot hook, request actions, and copy.
|
|
118
|
+
* @returns the option, or nothing outside a known Git checkout, once a turn started,
|
|
119
|
+
* the request settled, or no worktree service is mounted.
|
|
120
|
+
*/
|
|
121
|
+
export function WorktreeToggle({ usePanel, request, cancel, branches, t }: WorktreeToggleProps): ReactNode {
|
|
122
|
+
const state = usePanel(snapshot => snapshot.state)
|
|
123
|
+
const [pending, setPending] = useState<boolean | null>(null)
|
|
124
|
+
const option = optionOf(state)
|
|
125
|
+
if (state === null || option === undefined) return null
|
|
126
|
+
const held = state.worktree.creation !== null
|
|
127
|
+
const requested = pending ?? state.worktree.request !== null
|
|
128
|
+
const usable = option.blocker === null
|
|
129
|
+
const disabled = held || pending !== null || (!usable && !requested)
|
|
130
|
+
const current = option.current ?? (option.commit === null ? t('checkout.detached') : t('worktree.detachedTip', { commit: option.commit }))
|
|
131
|
+
const base = state.worktree.request === null ? option.current : state.worktree.request.from
|
|
132
|
+
const branchText = requested ? base === null ? t('worktree.baseHead') : t('worktree.base', { branch: base }) : current
|
|
133
|
+
const branchTip = requested || option.current === null ? branchText : t('worktree.currentBranchTip', { branch: option.current })
|
|
134
|
+
const change = (checked: boolean): void => {
|
|
135
|
+
setPending(checked)
|
|
136
|
+
void (checked ? request(option.current) : cancel()).then(() => { setPending(null) })
|
|
137
|
+
}
|
|
138
|
+
return (
|
|
139
|
+
<span className={css.root} data-forge-worktree="">
|
|
140
|
+
{requested && usable ? (
|
|
141
|
+
<BaseMenu base={state.worktree.request?.from ?? option.current} held={held} branches={branches} request={request} t={t} />
|
|
142
|
+
) : (
|
|
143
|
+
<Tooltip label={branchTip} side="bottom" portal openOnClick>
|
|
144
|
+
<button type="button" className={css.current} aria-label={branchTip}
|
|
145
|
+
data-forge-current-branch={requested ? undefined : ''} data-forge-base-branch={requested ? '' : undefined}>
|
|
146
|
+
<IconBranchOutlineRegular size={14} />
|
|
147
|
+
<span className={css.baseLabel}>{branchText}</span>
|
|
148
|
+
</button>
|
|
149
|
+
</Tooltip>
|
|
150
|
+
)}
|
|
151
|
+
<Tooltip label={option.blocker === null ? t('worktree.hint') : t(`worktree.blocked.${option.blocker}`)} side="bottom" delayMs={500}>
|
|
152
|
+
<label className={css.toggle} data-disabled={disabled ? '' : undefined}>
|
|
153
|
+
<input
|
|
154
|
+
type="checkbox"
|
|
155
|
+
className={css.checkbox}
|
|
156
|
+
checked={requested}
|
|
157
|
+
disabled={disabled}
|
|
158
|
+
onChange={(event) => { change(event.currentTarget.checked) }}
|
|
159
|
+
/>
|
|
160
|
+
{t('worktree.label')}
|
|
161
|
+
</label>
|
|
162
|
+
</Tooltip>
|
|
163
|
+
</span>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The changes view's tab type: the right-Sidebar view of one Session's local
|
|
3
|
+
* changes or of one change request bound to it. Its addresses name the Session
|
|
4
|
+
* and the source, `dsh-resource://forge-changes/<session>/local` or
|
|
5
|
+
* `dsh-resource://forge-changes/<session>/change/<url>`, each part
|
|
6
|
+
* percent-encoded; the source names the tab.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { SidebarRightTabDefinition } from '@deepseek-ai/dsh-client-ui-sidebar-right/client'
|
|
10
|
+
import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots'
|
|
11
|
+
import type { SessionId } from '@deepseek-ai/dsh-session/types'
|
|
12
|
+
import type { NS } from './locales.ts'
|
|
13
|
+
import { numberOf } from './status.ts'
|
|
14
|
+
|
|
15
|
+
/** Kind of the changes tab. */
|
|
16
|
+
export const CHANGES_KIND = 'forge-changes'
|
|
17
|
+
|
|
18
|
+
/** Registry id of the changes tab type, also the key its body and title register under. */
|
|
19
|
+
export const CHANGES_ID = '@deepseek-ai/dsh-experimental-client-ui-forge/changes'
|
|
20
|
+
|
|
21
|
+
const PREFIX = 'dsh-resource://forge-changes/'
|
|
22
|
+
|
|
23
|
+
/** What a changes view shows. */
|
|
24
|
+
export type ChangesSource =
|
|
25
|
+
/** The changes of the Session's checkout. */
|
|
26
|
+
| { readonly kind: 'local' }
|
|
27
|
+
/** The changes of one change request bound to the Session, by its binding URL. */
|
|
28
|
+
| { readonly kind: 'change'; readonly url: string }
|
|
29
|
+
|
|
30
|
+
/** The Session and the source one address names. */
|
|
31
|
+
export interface ChangesTarget {
|
|
32
|
+
/** Session whose checkout or binding the view reads. */
|
|
33
|
+
readonly sessionId: SessionId
|
|
34
|
+
/** What the view shows. */
|
|
35
|
+
readonly source: ChangesSource
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Navigation parameters of a changes tab. */
|
|
39
|
+
export interface ChangesParams {
|
|
40
|
+
/** File to scroll to, by its path in the diff. */
|
|
41
|
+
readonly path?: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare module '@deepseek-ai/dsh-client-ui-sidebar-right/client' {
|
|
45
|
+
interface SidebarRightResourceParamsMap {
|
|
46
|
+
/** The file a changes tab scrolls to. */
|
|
47
|
+
'forge-changes': ChangesParams
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Mint the address of a changes view.
|
|
53
|
+
* @param target - Session and source.
|
|
54
|
+
* @returns the `dsh-resource://forge-changes/…` address.
|
|
55
|
+
*/
|
|
56
|
+
export function changesAddress(target: ChangesTarget): string {
|
|
57
|
+
const session = `${PREFIX}${encodeURIComponent(target.sessionId)}/`
|
|
58
|
+
return target.source.kind === 'local' ? `${session}local` : `${session}change/${encodeURIComponent(target.source.url)}`
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Read the Session and source back out of a changes address.
|
|
63
|
+
* @param address - a resource address.
|
|
64
|
+
* @returns the target, or undefined for an address this package did not mint.
|
|
65
|
+
*/
|
|
66
|
+
export function parseChangesAddress(address: string): ChangesTarget | undefined {
|
|
67
|
+
if (!address.startsWith(PREFIX)) return undefined
|
|
68
|
+
const [session = '', kind, url, ...rest] = address.slice(PREFIX.length).split('/')
|
|
69
|
+
if (session === '' || rest.length > 0) return undefined
|
|
70
|
+
try {
|
|
71
|
+
const sessionId = decodeURIComponent(session) as SessionId
|
|
72
|
+
if (kind === 'local' && url === undefined) return { sessionId, source: { kind: 'local' } }
|
|
73
|
+
if (kind === 'change' && url !== undefined && url !== '') return { sessionId, source: { kind: 'change', url: decodeURIComponent(url) } }
|
|
74
|
+
return undefined
|
|
75
|
+
} catch (error) {
|
|
76
|
+
void error // A malformed percent sequence is not an address this package minted.
|
|
77
|
+
return undefined
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Name a changes view: 本地变更 for the local changes, #N 的变更 for a change request with a number.
|
|
83
|
+
* @param source - what the view shows.
|
|
84
|
+
* @param t - forge panel copy.
|
|
85
|
+
* @returns the title in the current language.
|
|
86
|
+
*/
|
|
87
|
+
export function changesTitle(source: ChangesSource, t: TranslateNS<typeof NS>): string {
|
|
88
|
+
if (source.kind === 'local') return t('changes.local.title')
|
|
89
|
+
const number = numberOf({ ref: null, url: source.url })
|
|
90
|
+
return number === null ? t('diff.tab') : t('diff.tabNumbered', { number })
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The changes type's registry definition.
|
|
95
|
+
* @param t - forge panel copy, read on every title call.
|
|
96
|
+
* @returns the definition to register.
|
|
97
|
+
*/
|
|
98
|
+
export function changesDefinition(t: TranslateNS<typeof NS>): SidebarRightTabDefinition {
|
|
99
|
+
return {
|
|
100
|
+
id: CHANGES_ID,
|
|
101
|
+
kind: CHANGES_KIND,
|
|
102
|
+
keepMounted: true,
|
|
103
|
+
patterns: [`${PREFIX}**`],
|
|
104
|
+
canOpen: address => parseChangesAddress(address) !== undefined,
|
|
105
|
+
title: (address) => {
|
|
106
|
+
const target = parseChangesAddress(address)
|
|
107
|
+
return target === undefined ? address : changesTitle(target.source, t)
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Choices of each changes tab: the local scope, the base branch of the
|
|
3
|
+
* `branch` scope, the commits shown, the review layer, whether test files
|
|
4
|
+
* hide, the side-by-side view, line wrapping, and the navigation it last
|
|
5
|
+
* applied. One bucket per tab, so two views in one Session keep their own
|
|
6
|
+
* choices; the bucket ends with the tab record's signal.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { defineStore, type EngineStoreHandle } from '@deepseek-ai/dsh-client-store'
|
|
10
|
+
import type { ForgeBaseBranch, ForgeCommitRange, ForgeFileLayer, ForgeLocalScope } from '../types.ts'
|
|
11
|
+
|
|
12
|
+
/** Files a changes tab shows: every file, or the files of one review layer. */
|
|
13
|
+
export type ChangesLens = 'all' | ForgeFileLayer
|
|
14
|
+
|
|
15
|
+
/** One changes tab's choices. */
|
|
16
|
+
export interface ChangesTabState {
|
|
17
|
+
/** Local changes shown; a change request view ignores it. */
|
|
18
|
+
scope: ForgeLocalScope['kind']
|
|
19
|
+
/** Branch the `branch` scope compares with, or null for the automatic fork point; other scopes keep it. */
|
|
20
|
+
base: ForgeBaseBranch | null
|
|
21
|
+
/** Commits shown instead of the whole change request or `branch` scope, or null for all of them. */
|
|
22
|
+
commits: ForgeCommitRange | null
|
|
23
|
+
/** Review layer whose files show. */
|
|
24
|
+
lens: ChangesLens
|
|
25
|
+
/** Whether files of the `test` layer hide from the file tree and the diff. */
|
|
26
|
+
hideTests: boolean
|
|
27
|
+
/** Whether deletions and additions show in two columns. */
|
|
28
|
+
split: boolean
|
|
29
|
+
/** Whether long lines wrap instead of being cut at the column edge. */
|
|
30
|
+
wrap: boolean
|
|
31
|
+
/** The navigation revision last applied, whose file the view scrolled to. */
|
|
32
|
+
navigated: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Every changes tab's choices, keyed by tab id. */
|
|
36
|
+
export interface ChangesState {
|
|
37
|
+
byTab: Record<string, ChangesTabState>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function bucket(state: ChangesState, tabId: string): ChangesTabState {
|
|
41
|
+
const tab = state.byTab[tabId]
|
|
42
|
+
if (tab === undefined) throw new Error(`forge-panel: no changes state for tab "${tabId}"`)
|
|
43
|
+
return tab
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The changes store's write set; every action names the tab it writes. */
|
|
47
|
+
type ChangesActions = {
|
|
48
|
+
navigated: (draft: ChangesState, tabId: string, revision: number) => void
|
|
49
|
+
scoped: (draft: ChangesState, tabId: string, scope: ForgeLocalScope['kind']) => void
|
|
50
|
+
based: (draft: ChangesState, tabId: string, base: ForgeBaseBranch | null) => void
|
|
51
|
+
committed: (draft: ChangesState, tabId: string, commits: ForgeCommitRange | null) => void
|
|
52
|
+
lensed: (draft: ChangesState, tabId: string, lens: ChangesLens) => void
|
|
53
|
+
toggledTests: (draft: ChangesState, tabId: string) => void
|
|
54
|
+
toggledSplit: (draft: ChangesState, tabId: string) => void
|
|
55
|
+
toggledWrap: (draft: ChangesState, tabId: string) => void
|
|
56
|
+
forget: (draft: ChangesState, tabId: string) => void
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Declare the changes tab's store; the registration declares it as an
|
|
61
|
+
* exclusive store, so the framework mints one instance per Session.
|
|
62
|
+
* @returns the store handle to declare on the registration.
|
|
63
|
+
*/
|
|
64
|
+
export function createChangesStore(): EngineStoreHandle<ChangesState, ChangesActions> {
|
|
65
|
+
return defineStore({
|
|
66
|
+
init: (): ChangesState => ({ byTab: {} }),
|
|
67
|
+
actions: {
|
|
68
|
+
/**
|
|
69
|
+
* Apply a navigation; the first one seeds the `branch` scope with the automatic fork point, every commit and file,
|
|
70
|
+
* test files shown, two columns, and wrapped lines.
|
|
71
|
+
* @param d - draft state.
|
|
72
|
+
* @param tabId - the tab being drawn.
|
|
73
|
+
* @param revision - the navigation revision being applied.
|
|
74
|
+
*/
|
|
75
|
+
navigated: (d, tabId: string, revision: number) => {
|
|
76
|
+
const tab = d.byTab[tabId]
|
|
77
|
+
if (tab === undefined) {
|
|
78
|
+
d.byTab[tabId] = { scope: 'branch', base: null, commits: null, lens: 'all', hideTests: false, split: true, wrap: true, navigated: revision }
|
|
79
|
+
} else tab.navigated = revision
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* Show another scope of local changes, with all of its commits.
|
|
83
|
+
* @param d - draft state.
|
|
84
|
+
* @param tabId - the tab being drawn.
|
|
85
|
+
* @param scope - the scope to show.
|
|
86
|
+
*/
|
|
87
|
+
scoped: (d, tabId: string, scope: ForgeLocalScope['kind']) => {
|
|
88
|
+
const tab = bucket(d, tabId)
|
|
89
|
+
tab.scope = scope
|
|
90
|
+
tab.commits = null
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* Compare the `branch` scope with another branch, showing all of its commits.
|
|
94
|
+
* @param d - draft state.
|
|
95
|
+
* @param tabId - the tab being drawn.
|
|
96
|
+
* @param base - the branch, or null for the automatic fork point.
|
|
97
|
+
*/
|
|
98
|
+
based: (d, tabId: string, base: ForgeBaseBranch | null) => {
|
|
99
|
+
const tab = bucket(d, tabId)
|
|
100
|
+
tab.base = base
|
|
101
|
+
tab.commits = null
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* Show consecutive commits instead of the whole change request or `branch` scope.
|
|
105
|
+
* @param d - draft state.
|
|
106
|
+
* @param tabId - the tab being drawn.
|
|
107
|
+
* @param commits - the commits, or null for all of them.
|
|
108
|
+
*/
|
|
109
|
+
committed: (d, tabId: string, commits: ForgeCommitRange | null) => { bucket(d, tabId).commits = commits },
|
|
110
|
+
/**
|
|
111
|
+
* Show the files of another review layer.
|
|
112
|
+
* @param d - draft state.
|
|
113
|
+
* @param tabId - the tab being drawn.
|
|
114
|
+
* @param lens - every file, or one layer.
|
|
115
|
+
*/
|
|
116
|
+
lensed: (d, tabId: string, lens: ChangesLens) => { bucket(d, tabId).lens = lens },
|
|
117
|
+
/**
|
|
118
|
+
* Hide or show the files of the `test` layer; hiding them leaves the `test` lens for every file.
|
|
119
|
+
* @param d - draft state.
|
|
120
|
+
* @param tabId - the tab being drawn.
|
|
121
|
+
*/
|
|
122
|
+
toggledTests: (d, tabId: string) => {
|
|
123
|
+
const tab = bucket(d, tabId)
|
|
124
|
+
tab.hideTests = !tab.hideTests
|
|
125
|
+
if (tab.hideTests && tab.lens === 'test') tab.lens = 'all'
|
|
126
|
+
},
|
|
127
|
+
/**
|
|
128
|
+
* Switch between one column and two.
|
|
129
|
+
* @param d - draft state.
|
|
130
|
+
* @param tabId - the tab being drawn.
|
|
131
|
+
*/
|
|
132
|
+
toggledSplit: (d, tabId: string) => {
|
|
133
|
+
const tab = bucket(d, tabId)
|
|
134
|
+
tab.split = !tab.split
|
|
135
|
+
},
|
|
136
|
+
/**
|
|
137
|
+
* Switch line wrapping.
|
|
138
|
+
* @param d - draft state.
|
|
139
|
+
* @param tabId - the tab being drawn.
|
|
140
|
+
*/
|
|
141
|
+
toggledWrap: (d, tabId: string) => {
|
|
142
|
+
const tab = bucket(d, tabId)
|
|
143
|
+
tab.wrap = !tab.wrap
|
|
144
|
+
},
|
|
145
|
+
/**
|
|
146
|
+
* Drop a tab's bucket once its record is gone.
|
|
147
|
+
* @param d - draft state.
|
|
148
|
+
* @param tabId - the tab that ended.
|
|
149
|
+
*/
|
|
150
|
+
forget: (d, tabId: string) => {
|
|
151
|
+
d.byTab = Object.fromEntries(Object.entries(d.byTab).filter(([id]) => id !== tabId))
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
})
|
|
155
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** What the panel's checkout row says about the checkout the Session works in. */
|
|
2
|
+
|
|
3
|
+
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
|
4
|
+
import { abbreviateHomePath } from '@deepseek-ai/dsh-util-workspace-path'
|
|
5
|
+
import type { ForgePanelState } from '../types.ts'
|
|
6
|
+
import type { NS } from './locales.ts'
|
|
7
|
+
|
|
8
|
+
type Translate = PropsLocale<typeof NS>['t']
|
|
9
|
+
|
|
10
|
+
/** Facts the checkout row shows. */
|
|
11
|
+
export interface CheckoutLabel {
|
|
12
|
+
/** Branch name, the abbreviated commit while HEAD is detached, or null when HEAD has no commit. */
|
|
13
|
+
readonly name: string | null
|
|
14
|
+
/** Whether HEAD is detached. */
|
|
15
|
+
readonly detached: boolean
|
|
16
|
+
/** Kind of directory: a worktree with its base, another worktree, the project directory, or a removed worktree. */
|
|
17
|
+
readonly kind: string
|
|
18
|
+
/** The kind with the directory path, home abbreviated to `~`. */
|
|
19
|
+
readonly tooltip: string
|
|
20
|
+
/** Whether the worktree the Session works in is gone. */
|
|
21
|
+
readonly missing: boolean
|
|
22
|
+
/** Full path of the directory, home not abbreviated; a removed worktree keeps the path it was created at. */
|
|
23
|
+
readonly path: string
|
|
24
|
+
/** Whether the directory is a worktree rather than the project directory. */
|
|
25
|
+
readonly worktree: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Describe the checkout of a Session. A worktree this panel created names its
|
|
30
|
+
* base; any other linked worktree is a worktree, and the main checkout is the
|
|
31
|
+
* project directory. A removed worktree keeps its branch name.
|
|
32
|
+
* @param state - panel state.
|
|
33
|
+
* @param home - Host account home, or undefined to show full paths.
|
|
34
|
+
* @param t - forge panel copy.
|
|
35
|
+
* @returns the label, or undefined before a successful inspection.
|
|
36
|
+
*/
|
|
37
|
+
export function checkoutLabel(state: ForgePanelState, home: string | undefined, t: Translate): CheckoutLabel | undefined {
|
|
38
|
+
const created = state.worktree.created
|
|
39
|
+
if (state.worktree.missing !== null && created !== null) {
|
|
40
|
+
const path = abbreviateHomePath(created.path, home)
|
|
41
|
+
return {
|
|
42
|
+
name: created.branch,
|
|
43
|
+
detached: false,
|
|
44
|
+
kind: t('missing.title'),
|
|
45
|
+
tooltip: t('branch.missing', { path }),
|
|
46
|
+
missing: true,
|
|
47
|
+
path: created.path,
|
|
48
|
+
worktree: true,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (state.checkout.state !== 'ready') return undefined
|
|
52
|
+
const { root, branch, linked, commit } = state.checkout.checkout
|
|
53
|
+
const path = abbreviateHomePath(root, home)
|
|
54
|
+
if (created !== null && created.path === root) {
|
|
55
|
+
const base = created.from ?? created.baseCommit.slice(0, 7)
|
|
56
|
+
return {
|
|
57
|
+
name: branch ?? commit,
|
|
58
|
+
detached: branch === null,
|
|
59
|
+
kind: t('checkout.worktreeFrom', { base }),
|
|
60
|
+
tooltip: t('branch.worktree', { base, path }),
|
|
61
|
+
missing: false,
|
|
62
|
+
path: root,
|
|
63
|
+
worktree: true,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
name: branch ?? commit,
|
|
68
|
+
detached: branch === null,
|
|
69
|
+
kind: t(linked ? 'checkout.worktree' : 'checkout.project'),
|
|
70
|
+
tooltip: t(linked ? 'branch.linked' : 'branch.project', { path }),
|
|
71
|
+
missing: false,
|
|
72
|
+
path: root,
|
|
73
|
+
worktree: linked,
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Read browser text selections from one diff side without including the interleaved opposite column. */
|
|
2
|
+
|
|
3
|
+
/** Selected displayed lines and the exact selected text on their side. */
|
|
4
|
+
export interface CodeSelection {
|
|
5
|
+
readonly side: 'L' | 'R'
|
|
6
|
+
readonly from: number
|
|
7
|
+
readonly to: number
|
|
8
|
+
readonly text: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function codeAt(node: Node | null): HTMLElement | null {
|
|
12
|
+
return (node instanceof Element ? node : node?.parentElement)?.closest<HTMLElement>('[data-review-code]') ?? null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Find the side where a text selection begins; unified context belongs to the new side.
|
|
17
|
+
* @param root - this file's diff element.
|
|
18
|
+
* @param node - pointer or selection anchor.
|
|
19
|
+
* @returns the available side, or undefined outside code text.
|
|
20
|
+
*/
|
|
21
|
+
export function codeSideAt(root: HTMLElement, node: Node | null): 'L' | 'R' | undefined {
|
|
22
|
+
const code = codeAt(node)
|
|
23
|
+
if (code === null || !root.contains(code)) return undefined
|
|
24
|
+
return code.dataset.newLine === undefined ? 'L' : 'R'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Read only code fragments from the selected side, retaining partial first and last lines for copy.
|
|
29
|
+
* @param root - this file's diff element.
|
|
30
|
+
* @param side - side captured when the gesture began.
|
|
31
|
+
* @returns the selected range and text, or undefined for collapsed or cross-file selections.
|
|
32
|
+
*/
|
|
33
|
+
export function readCodeSelection(root: HTMLElement, side: 'L' | 'R'): CodeSelection | undefined {
|
|
34
|
+
const selection = root.ownerDocument.getSelection()
|
|
35
|
+
if (selection === null || selection.isCollapsed || selection.rangeCount === 0
|
|
36
|
+
|| !root.contains(selection.anchorNode) || !root.contains(selection.focusNode)) return undefined
|
|
37
|
+
const range = selection.getRangeAt(0)
|
|
38
|
+
const fragments: { line: number; text: string }[] = []
|
|
39
|
+
for (const code of root.querySelectorAll<HTMLElement>('[data-review-code]')) {
|
|
40
|
+
const line = side === 'L' ? code.dataset.oldLine : code.dataset.newLine
|
|
41
|
+
if (line === undefined || !range.intersectsNode(code)) continue
|
|
42
|
+
const part = root.ownerDocument.createRange()
|
|
43
|
+
part.selectNodeContents(code)
|
|
44
|
+
if (code.contains(range.startContainer)) part.setStart(range.startContainer, range.startOffset)
|
|
45
|
+
if (code.contains(range.endContainer)) part.setEnd(range.endContainer, range.endOffset)
|
|
46
|
+
const text = part.toString()
|
|
47
|
+
if (text !== '' || code.textContent === '') fragments.push({ line: Number(line), text })
|
|
48
|
+
}
|
|
49
|
+
const first = fragments[0]
|
|
50
|
+
const last = fragments.at(-1)
|
|
51
|
+
if (first === undefined || last === undefined) return undefined
|
|
52
|
+
return { side, from: first.line, to: last.line, text: fragments.map(item => item.text).join('\n') }
|
|
53
|
+
}
|