@celljs/ta-workspace 4.8.0 → 4.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/README.zh-cn.md +2 -2
- package/package.json +13 -4
- package/web/index.js +916 -295
- package/web-src/browser-agent.ts +0 -440
- package/web-src/browser-common.tsx +0 -278
- package/web-src/browser-import.tsx +0 -126
- package/web-src/browser-webview.tsx +0 -270
- package/web-src/browser.tsx +0 -80
- package/web-src/common.tsx +0 -296
- package/web-src/editors.tsx +0 -471
- package/web-src/explorer.tsx +0 -717
- package/web-src/file-icon.tsx +0 -21
- package/web-src/host.ts +0 -121
- package/web-src/i18n.ts +0 -395
- package/web-src/index.tsx +0 -71
- package/web-src/open-files.tsx +0 -80
- package/web-src/preview.tsx +0 -132
- package/web-src/react.ts +0 -8
- package/web-src/scm.tsx +0 -388
- package/web-src/search.tsx +0 -485
- package/web-src/style.ts +0 -254
- package/web-src/terminal.tsx +0 -269
- package/web-src/util/browser-snapshot.spec.ts +0 -96
- package/web-src/util/browser-snapshot.ts +0 -225
- package/web-src/util/file-icon.spec.ts +0 -35
- package/web-src/util/file-icon.ts +0 -23
- package/web-src/util/git.ts +0 -203
- package/web-src/util/preview.spec.ts +0 -48
- package/web-src/util/preview.ts +0 -90
- package/web-src/util/search.spec.ts +0 -164
- package/web-src/util/search.ts +0 -274
- package/web-src/util/seti-font.ts +0 -6
- package/web-src/util/seti.ts +0 -761
- package/web-src/util/upload.spec.ts +0 -66
- package/web-src/util/upload.ts +0 -123
- package/web-src/util/workspace.spec.ts +0 -220
- package/web-src/util/workspace.ts +0 -396
- package/web-src/util/zip.spec.ts +0 -60
- package/web-src/util/zip.ts +0 -137
- package/web-src/workspace-client.ts +0 -221
package/web-src/open-files.tsx
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Action, copyText, Empty, type MenuItem, useContextMenu, ViewHeader } from './common';
|
|
2
|
-
import { closeEditor, type OpenFile, OpenFiles, useOpenFiles } from './editors';
|
|
3
|
-
import { RevealRequests } from './explorer';
|
|
4
|
-
import { FileIcon } from './file-icon';
|
|
5
|
-
import { PACKAGE, pi } from './host';
|
|
6
|
-
import { t } from './i18n';
|
|
7
|
-
// biome-ignore lint/correctness/noUnusedImports: the JSX below is React.createElement
|
|
8
|
-
import { React } from './react';
|
|
9
|
-
import { WorkspaceUtil } from './util/workspace';
|
|
10
|
-
|
|
11
|
-
function close(files: readonly OpenFile[]): void {
|
|
12
|
-
for (const file of files) {
|
|
13
|
-
closeEditor(file.id);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** The tabs of files and changes this package opened, as the open editors of an IDE; a click shows one again. */
|
|
18
|
-
export function OpenFilesView() {
|
|
19
|
-
const files = useOpenFiles();
|
|
20
|
-
const active = pi.ui.useActiveEditor();
|
|
21
|
-
const [menu, openMenu] = useContextMenu();
|
|
22
|
-
|
|
23
|
-
const reveal = (file: OpenFile) => {
|
|
24
|
-
RevealRequests.send({ cwd: file.cwd, path: file.detail });
|
|
25
|
-
pi.ui.showView(`${PACKAGE}/explorer`);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const menuFor = (file: OpenFile): MenuItem[] => {
|
|
29
|
-
const others = files.filter(other => other.id !== file.id);
|
|
30
|
-
const below = files.slice(files.indexOf(file) + 1);
|
|
31
|
-
return [
|
|
32
|
-
{ label: t('close'), run: () => closeEditor(file.id) },
|
|
33
|
-
{ label: t('closeOthers'), run: () => close(others), disabled: others.length === 0 },
|
|
34
|
-
{ label: t('closeToTheRight'), run: () => close(below), disabled: below.length === 0 },
|
|
35
|
-
{ label: t('closeAll'), run: () => close(OpenFiles.list()) },
|
|
36
|
-
'-',
|
|
37
|
-
{ label: t('copyRelativePath'), run: () => copyText(file.detail, t('copied')) },
|
|
38
|
-
{ label: t('revealInExplorer'), run: () => reveal(file) },
|
|
39
|
-
];
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<div className="taw-view">
|
|
44
|
-
<ViewHeader title={files.length > 0 ? t('openCount', { count: files.length }) : undefined}>
|
|
45
|
-
{files.length > 0 && <Action icon="CopyMinus" label={t('closeAll')} onClick={() => close(OpenFiles.list())} />}
|
|
46
|
-
</ViewHeader>
|
|
47
|
-
<div className="taw-list" role="listbox" aria-label={t('openFiles')}>
|
|
48
|
-
{files.length === 0 && <Empty>{t('noOpenFiles')}</Empty>}
|
|
49
|
-
{files.map(file => (
|
|
50
|
-
<div
|
|
51
|
-
key={file.id}
|
|
52
|
-
role="option"
|
|
53
|
-
tabIndex={0}
|
|
54
|
-
aria-selected={file.id === active}
|
|
55
|
-
className={`taw-row ${file.id === active ? 'taw-selected' : ''}`}
|
|
56
|
-
title={`${file.cwd}/${file.detail}`}
|
|
57
|
-
onClick={() => file.reopen()}
|
|
58
|
-
onKeyDown={event => {
|
|
59
|
-
if (event.key === 'Enter') {
|
|
60
|
-
file.reopen();
|
|
61
|
-
} else if (event.key === 'Delete' || event.key === 'Backspace') {
|
|
62
|
-
closeEditor(file.id);
|
|
63
|
-
}
|
|
64
|
-
}}
|
|
65
|
-
onAuxClick={event => event.button === 1 && closeEditor(file.id)}
|
|
66
|
-
onContextMenu={event => openMenu(event, menuFor(file))}
|
|
67
|
-
>
|
|
68
|
-
<FileIcon path={file.detail} />
|
|
69
|
-
<span className="taw-name">{file.title}</span>
|
|
70
|
-
<span className="taw-detail">{WorkspaceUtil.dirname(file.detail)}</span>
|
|
71
|
-
<span className="taw-row-actions taw-keep">
|
|
72
|
-
<Action icon="X" label={t('close')} onClick={() => closeEditor(file.id)} />
|
|
73
|
-
</span>
|
|
74
|
-
</div>
|
|
75
|
-
))}
|
|
76
|
-
</div>
|
|
77
|
-
{menu}
|
|
78
|
-
</div>
|
|
79
|
-
);
|
|
80
|
-
}
|
package/web-src/preview.tsx
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { marked } from 'marked';
|
|
2
|
-
import { pi, useTheme } from './host';
|
|
3
|
-
import { t } from './i18n';
|
|
4
|
-
import { React } from './react';
|
|
5
|
-
import { type PreviewKind, PreviewUtil } from './util/preview';
|
|
6
|
-
import { WorkspaceUtil } from './util/workspace';
|
|
7
|
-
|
|
8
|
-
/** What a page may do in the preview of an HTML file; the server answers it sandboxed as well. */
|
|
9
|
-
const PAGE_SANDBOX = 'allow-scripts allow-forms allow-popups allow-modals allow-downloads';
|
|
10
|
-
/** Rendered Markdown runs no scripts; its links open in a tab of their own. */
|
|
11
|
-
const MARKDOWN_SANDBOX = 'allow-popups allow-popups-to-escape-sandbox';
|
|
12
|
-
/** Elements of rendered Markdown whose URLs point beside the file. */
|
|
13
|
-
const LINKED = [
|
|
14
|
-
['img', 'src'],
|
|
15
|
-
['source', 'src'],
|
|
16
|
-
['video', 'src'],
|
|
17
|
-
['video', 'poster'],
|
|
18
|
-
['audio', 'src'],
|
|
19
|
-
['a', 'href'],
|
|
20
|
-
] as const;
|
|
21
|
-
|
|
22
|
-
/** The value of a variable of the page's theme, for a document that cannot read the page's styles. */
|
|
23
|
-
function themeValue(name: string): string {
|
|
24
|
-
return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function markdownStyle(): string {
|
|
28
|
-
const v = (name: string) => themeValue(`--ta-${name}`);
|
|
29
|
-
return `
|
|
30
|
-
:root { color-scheme: ${pi.ui.theme}; }
|
|
31
|
-
html, body { margin: 0; overscroll-behavior: none; background: ${v('main')}; color: ${v('body')}; font: 14px/1.7 ${v('sans')}; -webkit-font-smoothing: antialiased; }
|
|
32
|
-
.markdown { max-width: 860px; margin: 0 auto; padding: 24px 32px 48px; overflow-wrap: break-word; }
|
|
33
|
-
.markdown > :first-child { margin-top: 0; }
|
|
34
|
-
h1, h2, h3, h4, h5, h6 { margin: 1.5em 0 0.6em; color: ${v('text')}; font-weight: 600; line-height: 1.3; }
|
|
35
|
-
h1 { font-size: 1.85em; padding-bottom: 0.3em; border-bottom: 1px solid ${v('border-muted')}; }
|
|
36
|
-
h2 { font-size: 1.45em; padding-bottom: 0.3em; border-bottom: 1px solid ${v('border-muted')}; }
|
|
37
|
-
h3 { font-size: 1.2em; } h4 { font-size: 1em; } h5, h6 { font-size: 0.9em; color: ${v('secondary')}; }
|
|
38
|
-
p, ul, ol, pre, table, blockquote, details { margin: 0 0 1em; }
|
|
39
|
-
a { color: ${v('link')}; text-decoration: none; } a:hover { text-decoration: underline; }
|
|
40
|
-
strong { color: ${v('text')}; }
|
|
41
|
-
ul, ol { padding-left: 1.6em; } li + li { margin-top: 0.25em; } li > ul, li > ol { margin: 0.25em 0 0; }
|
|
42
|
-
ul:has(> li > input[type='checkbox']) { padding-left: 0.3em; } li:has(> input[type='checkbox']) { list-style: none; } li:has(> input[type='checkbox']) > :is(ul, ol) { padding-left: 2.8em; } input[type='checkbox'] { margin: 0 0.45em 0 0; vertical-align: -1px; }
|
|
43
|
-
code { padding: 0.15em 0.4em; border-radius: 5px; background: ${v('chip')}; font-family: ${v('mono')}; font-size: 0.86em; }
|
|
44
|
-
pre { padding: 12px 14px; overflow: auto; border: 1px solid ${v('border')}; border-radius: 10px; background: ${v('code')}; line-height: 1.55; }
|
|
45
|
-
pre code { padding: 0; background: none; font-size: 12.5px; }
|
|
46
|
-
blockquote { padding: 0 1em; border-left: 3px solid ${v('border-field')}; color: ${v('secondary')}; }
|
|
47
|
-
table { display: block; max-width: 100%; overflow: auto; border-collapse: collapse; }
|
|
48
|
-
th, td { padding: 6px 12px; border: 1px solid ${v('border')}; } th { background: ${v('raised')}; font-weight: 600; }
|
|
49
|
-
img, video { max-width: 100%; } img { border-radius: 4px; }
|
|
50
|
-
hr { height: 0; margin: 1.6em 0; border: 0; border-top: 1px solid ${v('border')}; }
|
|
51
|
-
@media (max-width: 600px) { .markdown { padding: 16px 18px 32px; } }
|
|
52
|
-
kbd { padding: 1px 5px; border: 1px solid ${v('border')}; border-bottom-width: 2px; border-radius: 4px; font-family: ${v('mono')}; font-size: 0.85em; }
|
|
53
|
-
`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Markdown as GitHub shows it: relative images and links point beside the file, links open in a tab of
|
|
58
|
-
* their own, headings get ids for links to them. Parsed by the browser without running anything.
|
|
59
|
-
*/
|
|
60
|
-
function renderMarkdown(text: string, directory: string): string {
|
|
61
|
-
const html = marked.parse(text, { async: false, gfm: true }) as string;
|
|
62
|
-
const body = new DOMParser().parseFromString(html, 'text/html').body;
|
|
63
|
-
for (const [tag, attribute] of LINKED) {
|
|
64
|
-
for (const element of body.querySelectorAll(`${tag}[${attribute}]`)) {
|
|
65
|
-
element.setAttribute(attribute, PreviewUtil.resolve(element.getAttribute(attribute) ?? '', directory));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
for (const link of body.querySelectorAll('a[href]')) {
|
|
69
|
-
if (!link.getAttribute('href')?.startsWith('#')) {
|
|
70
|
-
link.setAttribute('target', '_blank');
|
|
71
|
-
link.setAttribute('rel', 'noopener noreferrer');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const taken = new Map<string, number>();
|
|
75
|
-
for (const heading of body.querySelectorAll('h1, h2, h3, h4, h5, h6')) {
|
|
76
|
-
heading.id ||= PreviewUtil.slug(heading.textContent ?? '', taken);
|
|
77
|
-
}
|
|
78
|
-
return PreviewUtil.markdownDocument(body.innerHTML, markdownStyle());
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function MarkdownPreview({ text, url }: { text: string; url: string }) {
|
|
82
|
-
const theme = useTheme();
|
|
83
|
-
const document = React.useMemo(() => renderMarkdown(text, PreviewUtil.directoryUrl(new URL(url, location.href).href)), [text, url, theme]);
|
|
84
|
-
return <iframe className="taw-preview-frame" title="Markdown" sandbox={MARKDOWN_SANDBOX} srcDoc={document} />;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function ImagePreview({ url, size, onInfo }: { url: string; size: number; onInfo(info: string): void }) {
|
|
88
|
-
const [actual, setActual] = React.useState(false);
|
|
89
|
-
return (
|
|
90
|
-
<div className={`taw-preview-media taw-preview-image ${actual ? 'taw-actual' : ''}`}>
|
|
91
|
-
<button type="button" className="taw-image-toggle" title={t(actual ? 'fit' : 'actualSize')} onClick={() => setActual(value => !value)}>
|
|
92
|
-
<img
|
|
93
|
-
src={url}
|
|
94
|
-
alt=""
|
|
95
|
-
onLoad={event => {
|
|
96
|
-
const image = event.currentTarget;
|
|
97
|
-
onInfo(`${image.naturalWidth} × ${image.naturalHeight} · ${WorkspaceUtil.size(size)}`);
|
|
98
|
-
}}
|
|
99
|
-
/>
|
|
100
|
-
</button>
|
|
101
|
-
</div>
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* A file as it is: a page, an image, a video, a sound or a PDF, loaded from ta serve (TaWorkspaceServer.fileUrl).
|
|
107
|
-
* It loads again when the file changed (its ETag), not on every run of a tool.
|
|
108
|
-
*/
|
|
109
|
-
export function MediaPreview({ kind, url, size, onInfo }: { kind: Exclude<PreviewKind, 'markdown'>; url: string; size: number; onInfo(info: string): void }) {
|
|
110
|
-
switch (kind) {
|
|
111
|
-
case 'html':
|
|
112
|
-
return <iframe className="taw-preview-frame taw-preview-page" title="HTML" sandbox={PAGE_SANDBOX} src={url} />;
|
|
113
|
-
case 'pdf':
|
|
114
|
-
return <iframe className="taw-preview-frame" title="PDF" src={url} />;
|
|
115
|
-
case 'image':
|
|
116
|
-
return <ImagePreview url={url} size={size} onInfo={onInfo} />;
|
|
117
|
-
case 'video':
|
|
118
|
-
return (
|
|
119
|
-
<div className="taw-preview-media">
|
|
120
|
-
{/* biome-ignore lint/a11y/useMediaCaption: a file of the workspace, which has no captions to give */}
|
|
121
|
-
<video src={url} controls preload="metadata" />
|
|
122
|
-
</div>
|
|
123
|
-
);
|
|
124
|
-
case 'audio':
|
|
125
|
-
return (
|
|
126
|
-
<div className="taw-preview-media">
|
|
127
|
-
{/* biome-ignore lint/a11y/useMediaCaption: a file of the workspace, which has no captions to give */}
|
|
128
|
-
<audio src={url} controls preload="metadata" />
|
|
129
|
-
</div>
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
}
|
package/web-src/react.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type * as ReactModule from 'react';
|
|
2
|
-
|
|
3
|
-
/** The React of the page; a web extension brings none of its own, and gets it only when it starts. */
|
|
4
|
-
export let React: typeof ReactModule;
|
|
5
|
-
|
|
6
|
-
export function bind(react: typeof ReactModule): void {
|
|
7
|
-
React = react;
|
|
8
|
-
}
|
package/web-src/scm.tsx
DELETED
|
@@ -1,388 +0,0 @@
|
|
|
1
|
-
import { Action, copyText, Empty, Glyph, type MenuItem, Section, useContextMenu, ViewHeader } from './common';
|
|
2
|
-
import { openDiff, openFile } from './editors';
|
|
3
|
-
import { RevealRequests } from './explorer';
|
|
4
|
-
import { FileIcon } from './file-icon';
|
|
5
|
-
import { FilesChanged, Host, MAC, PACKAGE, pi, useFilesChanged, useLoad } from './host';
|
|
6
|
-
import { gitLabel, t } from './i18n';
|
|
7
|
-
import { React } from './react';
|
|
8
|
-
import { type GitStatus, GitUtil } from './util/git';
|
|
9
|
-
import { type GitGroup, type GitRow, WorkspaceUtil } from './util/workspace';
|
|
10
|
-
import { WorkspaceClient } from './workspace-client';
|
|
11
|
-
|
|
12
|
-
const REFRESH_MS = 10000;
|
|
13
|
-
const GROUPS: GitGroup[] = ['merge', 'staged', 'changes'];
|
|
14
|
-
|
|
15
|
-
/** What is typed for the next commit, by directory, while the view comes and goes. */
|
|
16
|
-
const messages = new Map<string, string>();
|
|
17
|
-
|
|
18
|
-
/** The changes of git in the conversation's directory, as source control in an IDE: stage, unstage, discard, commit, pull and push. */
|
|
19
|
-
export function ScmView() {
|
|
20
|
-
const cwd = pi.ui.useCwd();
|
|
21
|
-
const changed = useFilesChanged();
|
|
22
|
-
const status = useLoad<GitStatus>(() => WorkspaceClient.status(cwd), [cwd, changed]);
|
|
23
|
-
const { reload } = status;
|
|
24
|
-
const [message, setMessageState] = React.useState(() => messages.get(cwd) ?? '');
|
|
25
|
-
const [busy, setBusy] = React.useState<string>();
|
|
26
|
-
const [closed, setClosed] = React.useState<GitGroup[]>([]);
|
|
27
|
-
const [tree, setTree] = React.useState(false);
|
|
28
|
-
const [menu, openMenu] = useContextMenu();
|
|
29
|
-
const box = React.useRef<HTMLTextAreaElement>(null);
|
|
30
|
-
React.useEffect(() => setMessageState(messages.get(cwd) ?? ''), [cwd]);
|
|
31
|
-
const setMessage = (value: string) => {
|
|
32
|
-
messages.set(cwd, value);
|
|
33
|
-
setMessageState(value);
|
|
34
|
-
};
|
|
35
|
-
React.useEffect(() => {
|
|
36
|
-
const timer = setInterval(() => document.visibilityState === 'visible' && reload(), REFRESH_MS);
|
|
37
|
-
return () => clearInterval(timer);
|
|
38
|
-
}, [reload]);
|
|
39
|
-
// The box grows with the message, as the one of an IDE, up to a few lines.
|
|
40
|
-
React.useLayoutEffect(() => {
|
|
41
|
-
const element = box.current;
|
|
42
|
-
if (element) {
|
|
43
|
-
element.style.height = 'auto';
|
|
44
|
-
element.style.height = `${Math.min(element.scrollHeight, 200)}px`;
|
|
45
|
-
}
|
|
46
|
-
}, [message]);
|
|
47
|
-
|
|
48
|
-
const value = status.value;
|
|
49
|
-
const rows = React.useMemo(() => (value ? WorkspaceUtil.gitRows(value) : []), [value]);
|
|
50
|
-
const groups = GROUPS.map(group => [group, rows.filter(row => row.group === group)] as const);
|
|
51
|
-
const staged = rows.filter(row => row.group === 'staged');
|
|
52
|
-
const initial = !!value?.initial;
|
|
53
|
-
|
|
54
|
-
/** Runs git, then reads the status again; a failure is a notice. */
|
|
55
|
-
const run = async (label: string, work: () => Promise<unknown>) => {
|
|
56
|
-
setBusy(label);
|
|
57
|
-
try {
|
|
58
|
-
await work();
|
|
59
|
-
} catch (error) {
|
|
60
|
-
pi.ui.notify(Host.message(error), 'error');
|
|
61
|
-
} finally {
|
|
62
|
-
setBusy(undefined);
|
|
63
|
-
FilesChanged.notify();
|
|
64
|
-
reload();
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const stage = (paths: string[]) => run('stage', () => WorkspaceClient.git(cwd, GitUtil.stage(paths)));
|
|
69
|
-
const unstage = (paths: string[]) => run('unstage', () => WorkspaceClient.git(cwd, GitUtil.unstage(paths, initial)));
|
|
70
|
-
|
|
71
|
-
/** Back to the index for tracked files; untracked ones are deleted, which says so. */
|
|
72
|
-
const discard = async (list: GitRow[]) => {
|
|
73
|
-
const untracked = list.filter(row => row.file.unstaged === '?').map(row => row.file.path);
|
|
74
|
-
const tracked = list.filter(row => row.file.unstaged !== '?').map(row => row.file.path);
|
|
75
|
-
const single = list.length === 1 ? WorkspaceUtil.basename(list[0].file.path) : undefined;
|
|
76
|
-
const title =
|
|
77
|
-
untracked.length && !tracked.length
|
|
78
|
-
? single
|
|
79
|
-
? t('deleteUntracked', { name: single })
|
|
80
|
-
: t('deleteUntrackedMany', { count: untracked.length })
|
|
81
|
-
: single
|
|
82
|
-
? t('discardOne', { name: single })
|
|
83
|
-
: t('discardMany', { count: list.length });
|
|
84
|
-
const confirmed = await pi.ui.confirm(title, t('irreversible'), {
|
|
85
|
-
confirmLabel: untracked.length && !tracked.length ? t('delete') : t('discard'),
|
|
86
|
-
danger: true,
|
|
87
|
-
});
|
|
88
|
-
if (confirmed) {
|
|
89
|
-
await run('discard', async () => {
|
|
90
|
-
if (tracked.length) {
|
|
91
|
-
await WorkspaceClient.git(cwd, GitUtil.discard(tracked));
|
|
92
|
-
}
|
|
93
|
-
if (untracked.length) {
|
|
94
|
-
await WorkspaceClient.git(cwd, GitUtil.clean(untracked));
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const commit = async () => {
|
|
101
|
-
if (!message.trim()) {
|
|
102
|
-
box.current?.focus();
|
|
103
|
-
pi.ui.notify(t('commitMessageMissing'), 'warning');
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
// As VS Code with nothing staged: commit all the changes (after asking once).
|
|
107
|
-
if (staged.length === 0) {
|
|
108
|
-
if (rows.length === 0) {
|
|
109
|
-
pi.ui.notify(t('nothingToCommit'), 'info');
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
const confirmed = await pi.ui.confirm(t('stageAllTitle'), t('stageAllMessage'), { confirmLabel: t('stageAllCommit') });
|
|
113
|
-
if (!confirmed) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
await run('commit', async () => {
|
|
118
|
-
if (staged.length === 0) {
|
|
119
|
-
await WorkspaceClient.git(cwd, GitUtil.stage(['.']));
|
|
120
|
-
}
|
|
121
|
-
await WorkspaceClient.commit(cwd, message);
|
|
122
|
-
setMessage('');
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const remote = (command: 'pull' | 'push' | 'fetch') =>
|
|
127
|
-
run(command, async () => {
|
|
128
|
-
await WorkspaceClient.remote(cwd, command);
|
|
129
|
-
pi.ui.notify(t(`${command}Done`));
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
const open = (row: GitRow, pin: boolean) => {
|
|
133
|
-
if (row.letter === 'D' && row.group === 'changes') {
|
|
134
|
-
openDiff(cwd, row.file.path, false, { preview: !pin });
|
|
135
|
-
} else {
|
|
136
|
-
openDiff(cwd, row.file.path, row.group === 'staged', { preview: !pin });
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const reveal = (path: string) => {
|
|
141
|
-
RevealRequests.send({ cwd, path });
|
|
142
|
-
pi.ui.showView(`${PACKAGE}/explorer`);
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const rowMenu = (row: GitRow): MenuItem[] => [
|
|
146
|
-
{ label: t('openChanges'), run: () => open(row, true) },
|
|
147
|
-
...(row.letter !== 'D' ? [{ label: t('openFile'), run: () => openFile(cwd, row.file.path) }] : []),
|
|
148
|
-
'-',
|
|
149
|
-
...(row.group === 'staged'
|
|
150
|
-
? [{ label: t('unstage'), run: () => void unstage([row.file.path]) }]
|
|
151
|
-
: [
|
|
152
|
-
{ label: t('stage'), run: () => void stage([row.file.path]) },
|
|
153
|
-
...(row.group === 'changes' ? [{ label: t(row.letter === 'U' ? 'delete' : 'discard'), run: () => void discard([row]) }] : []),
|
|
154
|
-
]),
|
|
155
|
-
'-',
|
|
156
|
-
...(row.letter !== 'D' ? [{ label: t('revealInExplorer'), run: () => reveal(row.file.path) }] : []),
|
|
157
|
-
{ label: t('copyRelativePath'), run: () => copyText(row.file.path, t('copied')) },
|
|
158
|
-
];
|
|
159
|
-
|
|
160
|
-
const commitKeys = MAC ? '⌘↵' : 'Ctrl+Enter';
|
|
161
|
-
const branch = value?.branch;
|
|
162
|
-
const placeholder = branch ? t('commitPlaceholderBranch', { keys: commitKeys, branch }) : t('commitPlaceholder', { keys: commitKeys });
|
|
163
|
-
|
|
164
|
-
return (
|
|
165
|
-
<div className="taw-view">
|
|
166
|
-
<ViewHeader
|
|
167
|
-
title={
|
|
168
|
-
<span className="taw-scm-title">
|
|
169
|
-
<span>{WorkspaceUtil.basename(cwd) || t('scm')}</span>
|
|
170
|
-
{branch && (
|
|
171
|
-
<span className="taw-branch-title">
|
|
172
|
-
<Glyph name="GitBranch" size={12} />
|
|
173
|
-
{branch}
|
|
174
|
-
{!!value?.ahead && <span className="taw-sync">{value.ahead}↑</span>}
|
|
175
|
-
{!!value?.behind && <span className="taw-sync">{value.behind}↓</span>}
|
|
176
|
-
</span>
|
|
177
|
-
)}
|
|
178
|
-
</span>
|
|
179
|
-
}
|
|
180
|
-
hint={[cwd, branch, value?.ahead || value?.behind ? t('aheadBehind', { ahead: value.ahead ?? 0, behind: value.behind ?? 0 }) : '']
|
|
181
|
-
.filter(Boolean)
|
|
182
|
-
.join(' · ')}
|
|
183
|
-
>
|
|
184
|
-
{value?.repository && (
|
|
185
|
-
<React.Fragment>
|
|
186
|
-
<Action icon={tree ? 'List' : 'ListTree'} label={t(tree ? 'viewAsList' : 'viewAsTree')} onClick={() => setTree(!tree)} />
|
|
187
|
-
<Action icon="ArrowDown" label={t('pull')} disabled={!!busy} onClick={() => void remote('pull')} />
|
|
188
|
-
<Action icon="ArrowUp" label={t('push')} disabled={!!busy} onClick={() => void remote('push')} />
|
|
189
|
-
</React.Fragment>
|
|
190
|
-
)}
|
|
191
|
-
<Action icon="RefreshCw" label={t('refresh')} onClick={reload} />
|
|
192
|
-
{value?.repository && (
|
|
193
|
-
<Action
|
|
194
|
-
icon="Ellipsis"
|
|
195
|
-
label={t('moreActions')}
|
|
196
|
-
onClick={event =>
|
|
197
|
-
openMenu(event, [
|
|
198
|
-
{ label: t('pull'), run: () => void remote('pull') },
|
|
199
|
-
{ label: t('push'), run: () => void remote('push') },
|
|
200
|
-
{ label: t('fetch'), run: () => void remote('fetch') },
|
|
201
|
-
'-',
|
|
202
|
-
{ label: t('stageAll'), run: () => void stage(['.']), disabled: rows.every(row => row.group === 'staged') },
|
|
203
|
-
{ label: t('unstageAll'), run: () => void unstage(staged.map(row => row.file.path)), disabled: staged.length === 0 },
|
|
204
|
-
{
|
|
205
|
-
label: t('discardAll'),
|
|
206
|
-
run: () => void discard(rows.filter(row => row.group === 'changes')),
|
|
207
|
-
disabled: !rows.some(row => row.group === 'changes'),
|
|
208
|
-
},
|
|
209
|
-
])
|
|
210
|
-
}
|
|
211
|
-
/>
|
|
212
|
-
)}
|
|
213
|
-
</ViewHeader>
|
|
214
|
-
{busy && <div className="taw-progress-bar" role="progressbar" aria-label={t('loading')} />}
|
|
215
|
-
{value?.repository && (
|
|
216
|
-
<div className="taw-commit">
|
|
217
|
-
<textarea
|
|
218
|
-
ref={box}
|
|
219
|
-
rows={1}
|
|
220
|
-
className="taw-input taw-commit-input"
|
|
221
|
-
value={message}
|
|
222
|
-
placeholder={placeholder}
|
|
223
|
-
aria-label={t('commitMessage')}
|
|
224
|
-
spellCheck={false}
|
|
225
|
-
onChange={event => setMessage(event.target.value)}
|
|
226
|
-
onKeyDown={event => {
|
|
227
|
-
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
|
|
228
|
-
event.preventDefault();
|
|
229
|
-
void commit();
|
|
230
|
-
}
|
|
231
|
-
}}
|
|
232
|
-
/>
|
|
233
|
-
<button
|
|
234
|
-
type="button"
|
|
235
|
-
className={`taw-button taw-commit-button ${message.trim() ? 'taw-ready' : ''}`}
|
|
236
|
-
disabled={!!busy}
|
|
237
|
-
onClick={() => void commit()}
|
|
238
|
-
>
|
|
239
|
-
<Glyph name="Check" size={14} />
|
|
240
|
-
{t('commit')}
|
|
241
|
-
</button>
|
|
242
|
-
</div>
|
|
243
|
-
)}
|
|
244
|
-
<div className="taw-list taw-scm-list">
|
|
245
|
-
{status.error && <Empty tone="error">{t('failed', { message: status.error })}</Empty>}
|
|
246
|
-
{!status.error && !value && <Empty>{t('loading')}</Empty>}
|
|
247
|
-
{value && !value.repository && <Empty>{t('notRepository')}</Empty>}
|
|
248
|
-
{value?.repository && rows.length === 0 && <Empty>{t('noChanges')}</Empty>}
|
|
249
|
-
{groups.map(([group, list]) => {
|
|
250
|
-
if (list.length === 0) {
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
const expanded = !closed.includes(group);
|
|
254
|
-
const paths = list.map(row => row.file.path);
|
|
255
|
-
const actions =
|
|
256
|
-
group === 'staged' ? (
|
|
257
|
-
<Action icon="Minus" label={t('unstageAll')} onClick={() => void unstage(paths)} />
|
|
258
|
-
) : (
|
|
259
|
-
<React.Fragment>
|
|
260
|
-
{group === 'changes' && <Action icon="Undo2" label={t('discardAll')} onClick={() => void discard(list)} />}
|
|
261
|
-
<Action icon="Plus" label={t('stageAll')} onClick={() => void stage(paths)} />
|
|
262
|
-
</React.Fragment>
|
|
263
|
-
);
|
|
264
|
-
return (
|
|
265
|
-
<Section
|
|
266
|
-
key={group}
|
|
267
|
-
title={t(group === 'merge' ? 'mergeChanges' : group)}
|
|
268
|
-
count={list.length}
|
|
269
|
-
open={expanded}
|
|
270
|
-
onToggle={() => setClosed(expanded ? [...closed, group] : closed.filter(other => other !== group))}
|
|
271
|
-
actions={actions}
|
|
272
|
-
>
|
|
273
|
-
{(tree ? treeRows(list) : list.map(row => ({ row, depth: 0 }))).map(item =>
|
|
274
|
-
'folder' in item ? (
|
|
275
|
-
<div key={`${group}:dir:${item.folder}`} className="taw-row taw-scm-row" style={{ paddingLeft: 20 + item.depth * 12 }}>
|
|
276
|
-
<Glyph name="Folder" />
|
|
277
|
-
<span className="taw-name">{WorkspaceUtil.basename(item.folder)}</span>
|
|
278
|
-
</div>
|
|
279
|
-
) : (
|
|
280
|
-
<ScmRow
|
|
281
|
-
key={`${group}:${item.row.file.path}`}
|
|
282
|
-
row={item.row}
|
|
283
|
-
depth={item.depth}
|
|
284
|
-
tree={tree}
|
|
285
|
-
onOpen={pin => open(item.row, pin)}
|
|
286
|
-
onMenu={event => openMenu(event, rowMenu(item.row))}
|
|
287
|
-
actions={
|
|
288
|
-
<React.Fragment>
|
|
289
|
-
{item.row.letter !== 'D' && (
|
|
290
|
-
<Action icon="File" label={t('openFile')} onClick={() => openFile(cwd, item.row.file.path)} />
|
|
291
|
-
)}
|
|
292
|
-
{item.row.group === 'changes' && (
|
|
293
|
-
<Action
|
|
294
|
-
icon="Undo2"
|
|
295
|
-
label={t(item.row.letter === 'U' ? 'delete' : 'discard')}
|
|
296
|
-
onClick={() => void discard([item.row])}
|
|
297
|
-
/>
|
|
298
|
-
)}
|
|
299
|
-
{item.row.group === 'staged' ? (
|
|
300
|
-
<Action icon="Minus" label={t('unstage')} onClick={() => void unstage([item.row.file.path])} />
|
|
301
|
-
) : (
|
|
302
|
-
<Action icon="Plus" label={t('stage')} onClick={() => void stage([item.row.file.path])} />
|
|
303
|
-
)}
|
|
304
|
-
</React.Fragment>
|
|
305
|
-
}
|
|
306
|
-
/>
|
|
307
|
-
),
|
|
308
|
-
)}
|
|
309
|
-
</Section>
|
|
310
|
-
);
|
|
311
|
-
})}
|
|
312
|
-
</div>
|
|
313
|
-
{menu}
|
|
314
|
-
</div>
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/** The rows of a group as a tree: each folder once, before its files. */
|
|
319
|
-
function treeRows(list: readonly GitRow[]): ({ row: GitRow; depth: number } | { folder: string; depth: number })[] {
|
|
320
|
-
const out: ({ row: GitRow; depth: number } | { folder: string; depth: number })[] = [];
|
|
321
|
-
const seen = new Set<string>();
|
|
322
|
-
const sorted = [...list].sort((a, b) => {
|
|
323
|
-
const [da, db] = [WorkspaceUtil.dirname(a.file.path), WorkspaceUtil.dirname(b.file.path)];
|
|
324
|
-
return da === db ? WorkspaceUtil.compareNames(a.file.path, b.file.path) : WorkspaceUtil.compareNames(da, db);
|
|
325
|
-
});
|
|
326
|
-
for (const row of sorted) {
|
|
327
|
-
const parts = row.file.path.split('/');
|
|
328
|
-
for (let depth = 0; depth < parts.length - 1; depth++) {
|
|
329
|
-
const folder = parts.slice(0, depth + 1).join('/');
|
|
330
|
-
if (!seen.has(folder)) {
|
|
331
|
-
seen.add(folder);
|
|
332
|
-
out.push({ folder, depth });
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
out.push({ row, depth: parts.length - 1 });
|
|
336
|
-
}
|
|
337
|
-
return out;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
function ScmRow({
|
|
341
|
-
row,
|
|
342
|
-
depth,
|
|
343
|
-
tree,
|
|
344
|
-
onOpen,
|
|
345
|
-
onMenu,
|
|
346
|
-
actions,
|
|
347
|
-
}: {
|
|
348
|
-
row: GitRow;
|
|
349
|
-
depth: number;
|
|
350
|
-
tree: boolean;
|
|
351
|
-
onOpen(pin: boolean): void;
|
|
352
|
-
onMenu(event: React.MouseEvent | React.KeyboardEvent): void;
|
|
353
|
-
actions: React.ReactNode;
|
|
354
|
-
}) {
|
|
355
|
-
const color = WorkspaceUtil.gitColor(row.letter);
|
|
356
|
-
const path = row.file.path;
|
|
357
|
-
const from = row.file.from && row.group === 'staged' ? row.file.from : undefined;
|
|
358
|
-
return (
|
|
359
|
-
<div
|
|
360
|
-
role="treeitem"
|
|
361
|
-
tabIndex={0}
|
|
362
|
-
className={`taw-row taw-scm-row ${row.letter === 'D' ? 'taw-deleted' : ''}`}
|
|
363
|
-
style={{ paddingLeft: 20 + depth * 12 }}
|
|
364
|
-
title={`${from ? `${from} → ` : ''}${path} • ${gitLabel(row.letter)}`}
|
|
365
|
-
onClick={() => onOpen(false)}
|
|
366
|
-
onDoubleClick={() => onOpen(true)}
|
|
367
|
-
onKeyDown={event => {
|
|
368
|
-
if (event.key === 'Enter') {
|
|
369
|
-
onOpen(true);
|
|
370
|
-
} else if (event.key === 'ContextMenu' || (event.key === 'F10' && event.shiftKey)) {
|
|
371
|
-
onMenu(event);
|
|
372
|
-
}
|
|
373
|
-
}}
|
|
374
|
-
onContextMenu={onMenu}
|
|
375
|
-
>
|
|
376
|
-
<FileIcon path={path} />
|
|
377
|
-
<span className="taw-name" style={{ color }}>
|
|
378
|
-
{WorkspaceUtil.basename(path)}
|
|
379
|
-
</span>
|
|
380
|
-
{!tree && <span className="taw-detail">{from ? `${from} → ${WorkspaceUtil.dirname(path)}` : WorkspaceUtil.dirname(path)}</span>}
|
|
381
|
-
{tree && <span className="taw-detail" />}
|
|
382
|
-
<span className="taw-row-actions">{actions}</span>
|
|
383
|
-
<span className="taw-letter" style={{ color }}>
|
|
384
|
-
{row.letter}
|
|
385
|
-
</span>
|
|
386
|
-
</div>
|
|
387
|
-
);
|
|
388
|
-
}
|