@celljs/ta-workspace 4.8.0 → 4.9.0
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 +913 -294
- 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/browser.tsx
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { BrowserBar, Home, openOutside, Recent, ShowPage, useForwarded } from './browser-common';
|
|
2
|
-
import { WebviewBrowser } from './browser-webview';
|
|
3
|
-
import { pi } from './host';
|
|
4
|
-
import { t } from './i18n';
|
|
5
|
-
import { React } from './react';
|
|
6
|
-
import { WorkspaceUtil } from './util/workspace';
|
|
7
|
-
|
|
8
|
-
interface History {
|
|
9
|
-
/** The addresses opened here, '' for the start page. */
|
|
10
|
-
list: string[];
|
|
11
|
-
index: number;
|
|
12
|
-
reloads: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The browser of a browser tab: the page in a frame. Back and forward go through the addresses opened
|
|
17
|
-
* here, as a frame of another site hides its own history; some sites refuse to be in a frame.
|
|
18
|
-
*/
|
|
19
|
-
function FrameBrowser() {
|
|
20
|
-
const [history, setHistory] = React.useState<History>({ list: [''], index: 0, reloads: 0 });
|
|
21
|
-
const [loading, setLoading] = React.useState(false);
|
|
22
|
-
const url = history.list[history.index];
|
|
23
|
-
const shown = useForwarded(url, pi.ui.useCwd());
|
|
24
|
-
const go = (next: string) => {
|
|
25
|
-
if (next) {
|
|
26
|
-
Recent.add(next);
|
|
27
|
-
}
|
|
28
|
-
setLoading(Boolean(next));
|
|
29
|
-
setHistory(previous => ({ list: [...previous.list.slice(0, previous.index + 1), next], index: previous.index + 1, reloads: 0 }));
|
|
30
|
-
};
|
|
31
|
-
const step = (delta: number) => {
|
|
32
|
-
const index = Math.min(history.list.length - 1, Math.max(0, history.index + delta));
|
|
33
|
-
if (index !== history.index) {
|
|
34
|
-
setLoading(Boolean(history.list[index]));
|
|
35
|
-
setHistory({ ...history, index });
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
ShowPage.useReceive(go);
|
|
39
|
-
const reload = () => {
|
|
40
|
-
setLoading(true);
|
|
41
|
-
setHistory(previous => ({ ...previous, reloads: previous.reloads + 1 }));
|
|
42
|
-
};
|
|
43
|
-
return (
|
|
44
|
-
<div className="taw-browser">
|
|
45
|
-
<BrowserBar
|
|
46
|
-
url={url}
|
|
47
|
-
loading={loading}
|
|
48
|
-
canGoBack={history.index > 0}
|
|
49
|
-
canGoForward={history.index < history.list.length - 1}
|
|
50
|
-
onBack={() => step(-1)}
|
|
51
|
-
onForward={() => step(1)}
|
|
52
|
-
onReload={reload}
|
|
53
|
-
onOpen={go}
|
|
54
|
-
onHome={() => go('')}
|
|
55
|
-
onOpenOutside={shown ? () => openOutside(shown) : undefined}
|
|
56
|
-
outsideLabel={t('openExternal')}
|
|
57
|
-
/>
|
|
58
|
-
{url ? (
|
|
59
|
-
shown && (
|
|
60
|
-
<iframe
|
|
61
|
-
key={`${history.index}:${history.reloads}`}
|
|
62
|
-
className="taw-frame"
|
|
63
|
-
title={shown === url ? url : `${url} → ${shown}`}
|
|
64
|
-
src={shown}
|
|
65
|
-
referrerPolicy="no-referrer"
|
|
66
|
-
sandbox={WorkspaceUtil.frameSandbox(shown, location.origin)}
|
|
67
|
-
onLoad={() => setLoading(false)}
|
|
68
|
-
/>
|
|
69
|
-
)
|
|
70
|
-
) : (
|
|
71
|
-
<Home onOpen={go} foot={t('frameHint')} />
|
|
72
|
-
)}
|
|
73
|
-
</div>
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** A browser in one tab of the workbench: a webview in Ta Desktop, a frame elsewhere. */
|
|
78
|
-
export function BrowserView() {
|
|
79
|
-
return pi.ui.supportsWebview ? <WebviewBrowser /> : <FrameBrowser />;
|
|
80
|
-
}
|
package/web-src/common.tsx
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import type { WebIcon } from '@celljs/ta-web/lib/browser/extension/web-extension-api';
|
|
2
|
-
import { Host, pi } from './host';
|
|
3
|
-
import { React } from './react';
|
|
4
|
-
|
|
5
|
-
/** The row under the title the page gives a view: what it is about (`hint` on hover, else the title), and its actions. */
|
|
6
|
-
export function ViewHeader({ title, hint, children }: { title?: React.ReactNode; hint?: string; children?: React.ReactNode }) {
|
|
7
|
-
if (!title && !children) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
return (
|
|
11
|
-
<header className="taw-view-head">
|
|
12
|
-
<span className="taw-view-title" title={hint ?? (typeof title === 'string' ? title : undefined)}>
|
|
13
|
-
{title}
|
|
14
|
-
</span>
|
|
15
|
-
<div className="taw-actions">{children}</div>
|
|
16
|
-
</header>
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function Action({
|
|
21
|
-
icon,
|
|
22
|
-
label,
|
|
23
|
-
onClick,
|
|
24
|
-
active,
|
|
25
|
-
disabled,
|
|
26
|
-
}: {
|
|
27
|
-
icon: string;
|
|
28
|
-
label: string;
|
|
29
|
-
onClick(event: React.MouseEvent): void;
|
|
30
|
-
active?: boolean;
|
|
31
|
-
disabled?: boolean;
|
|
32
|
-
}) {
|
|
33
|
-
const Glyph: WebIcon = Host.icon(icon);
|
|
34
|
-
return (
|
|
35
|
-
<button
|
|
36
|
-
type="button"
|
|
37
|
-
className={`taw-action ${active ? 'taw-on' : ''}`}
|
|
38
|
-
title={label}
|
|
39
|
-
aria-label={label}
|
|
40
|
-
aria-pressed={active === undefined ? undefined : active}
|
|
41
|
-
disabled={disabled}
|
|
42
|
-
onClick={event => {
|
|
43
|
-
event.stopPropagation();
|
|
44
|
-
onClick(event);
|
|
45
|
-
}}
|
|
46
|
-
onDoubleClick={event => event.stopPropagation()}
|
|
47
|
-
>
|
|
48
|
-
<Glyph size={15} strokeWidth={1.7} />
|
|
49
|
-
</button>
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function Empty({ children, tone }: { children: React.ReactNode; tone?: 'error' }) {
|
|
54
|
-
return <div className={`taw-empty ${tone === 'error' ? 'taw-error' : ''}`}>{children}</div>;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function Glyph({ name, size = 15 }: { name: string; size?: number }) {
|
|
58
|
-
const Icon = Host.icon(name);
|
|
59
|
-
return <Icon size={size} strokeWidth={1.7} />;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** The value kept for one directory while the view comes and goes. */
|
|
63
|
-
export function useKept<T>(store: Map<string, T>, key: string, initial: () => T): [T, (value: T | ((previous: T) => T)) => void] {
|
|
64
|
-
const [value, setValue] = React.useState<T>(() => store.get(key) ?? initial());
|
|
65
|
-
const keyRef = React.useRef(key);
|
|
66
|
-
if (keyRef.current !== key) {
|
|
67
|
-
keyRef.current = key;
|
|
68
|
-
const next = store.get(key) ?? initial();
|
|
69
|
-
setValue(next);
|
|
70
|
-
}
|
|
71
|
-
const set = React.useCallback(
|
|
72
|
-
(next: T | ((previous: T) => T)) =>
|
|
73
|
-
setValue(previous => {
|
|
74
|
-
const value = typeof next === 'function' ? (next as (previous: T) => T)(previous) : next;
|
|
75
|
-
store.set(keyRef.current, value);
|
|
76
|
-
return value;
|
|
77
|
-
}),
|
|
78
|
-
[store],
|
|
79
|
-
);
|
|
80
|
-
return [value, set];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** An entry of a context menu; `'-'` is a line between groups. */
|
|
84
|
-
export type MenuItem =
|
|
85
|
-
| '-'
|
|
86
|
-
| {
|
|
87
|
-
label: string;
|
|
88
|
-
run(): void;
|
|
89
|
-
/** Shown on the right, as the keys of an IDE. */
|
|
90
|
-
keys?: string;
|
|
91
|
-
disabled?: boolean;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
interface MenuState {
|
|
95
|
-
x: number;
|
|
96
|
-
y: number;
|
|
97
|
-
items: MenuItem[];
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* A context menu at the pointer, as an IDE's: arrows move, Enter runs, Escape or a click elsewhere
|
|
102
|
-
* closes. `open` takes the event of a right click (or of a button that opens it) and the entries.
|
|
103
|
-
*/
|
|
104
|
-
export function useContextMenu(): [React.ReactNode, (event: React.MouseEvent | React.KeyboardEvent, items: MenuItem[]) => void] {
|
|
105
|
-
const [menu, setMenu] = React.useState<MenuState>();
|
|
106
|
-
const open = React.useCallback((event: React.MouseEvent | React.KeyboardEvent, items: MenuItem[]) => {
|
|
107
|
-
event.preventDefault();
|
|
108
|
-
event.stopPropagation();
|
|
109
|
-
const target = event.currentTarget as HTMLElement;
|
|
110
|
-
const box = target.getBoundingClientRect();
|
|
111
|
-
const pointer = 'clientX' in event && (event.clientX || event.clientY);
|
|
112
|
-
setMenu({ x: pointer ? event.clientX : box.left + 16, y: pointer ? event.clientY : box.bottom, items });
|
|
113
|
-
}, []);
|
|
114
|
-
const element = menu ? <ContextMenu {...menu} onClose={() => setMenu(undefined)} /> : null;
|
|
115
|
-
return [element, open];
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function ContextMenu({ x, y, items, onClose }: MenuState & { onClose(): void }) {
|
|
119
|
-
const root = React.useRef<HTMLDivElement>(null);
|
|
120
|
-
const [place, setPlace] = React.useState({ left: x, top: y, ready: false });
|
|
121
|
-
React.useLayoutEffect(() => {
|
|
122
|
-
const box = root.current?.getBoundingClientRect();
|
|
123
|
-
if (box) {
|
|
124
|
-
const left = Math.max(4, Math.min(x, window.innerWidth - box.width - 4));
|
|
125
|
-
const top = y + box.height > window.innerHeight - 4 ? Math.max(4, y - box.height) : y;
|
|
126
|
-
setPlace({ left, top, ready: true });
|
|
127
|
-
}
|
|
128
|
-
root.current?.querySelector<HTMLButtonElement>('button:not(:disabled)')?.focus();
|
|
129
|
-
}, [x, y]);
|
|
130
|
-
React.useEffect(() => {
|
|
131
|
-
const close = (event: Event) => {
|
|
132
|
-
if (!root.current?.contains(event.target as Node)) {
|
|
133
|
-
onClose();
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
const onKey = (event: KeyboardEvent) => event.key === 'Escape' && onClose();
|
|
137
|
-
document.addEventListener('pointerdown', close, true);
|
|
138
|
-
document.addEventListener('keydown', onKey);
|
|
139
|
-
window.addEventListener('blur', onClose);
|
|
140
|
-
window.addEventListener('resize', onClose);
|
|
141
|
-
return () => {
|
|
142
|
-
document.removeEventListener('pointerdown', close, true);
|
|
143
|
-
document.removeEventListener('keydown', onKey);
|
|
144
|
-
window.removeEventListener('blur', onClose);
|
|
145
|
-
window.removeEventListener('resize', onClose);
|
|
146
|
-
};
|
|
147
|
-
}, [onClose]);
|
|
148
|
-
const onKeyDown = (event: React.KeyboardEvent) => {
|
|
149
|
-
if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp') {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
event.preventDefault();
|
|
153
|
-
const buttons = [...(root.current?.querySelectorAll<HTMLButtonElement>('button:not(:disabled)') ?? [])];
|
|
154
|
-
const at = buttons.indexOf(document.activeElement as HTMLButtonElement);
|
|
155
|
-
buttons[(at + (event.key === 'ArrowDown' ? 1 : buttons.length - 1)) % buttons.length]?.focus();
|
|
156
|
-
};
|
|
157
|
-
return (
|
|
158
|
-
<div
|
|
159
|
-
ref={root}
|
|
160
|
-
className="taw-menu"
|
|
161
|
-
role="menu"
|
|
162
|
-
style={{ left: place.left, top: place.top, visibility: place.ready ? 'visible' : 'hidden' }}
|
|
163
|
-
onKeyDown={onKeyDown}
|
|
164
|
-
onContextMenu={event => event.preventDefault()}
|
|
165
|
-
>
|
|
166
|
-
{items.map((item, index) =>
|
|
167
|
-
item === '-' ? (
|
|
168
|
-
<hr key={`-${index}`} className="taw-menu-line" />
|
|
169
|
-
) : (
|
|
170
|
-
<button
|
|
171
|
-
key={item.label}
|
|
172
|
-
type="button"
|
|
173
|
-
role="menuitem"
|
|
174
|
-
className="taw-menu-item"
|
|
175
|
-
disabled={item.disabled}
|
|
176
|
-
onClick={() => {
|
|
177
|
-
onClose();
|
|
178
|
-
item.run();
|
|
179
|
-
}}
|
|
180
|
-
>
|
|
181
|
-
<span>{item.label}</span>
|
|
182
|
-
{item.keys && <kbd>{item.keys}</kbd>}
|
|
183
|
-
</button>
|
|
184
|
-
),
|
|
185
|
-
)}
|
|
186
|
-
</div>
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* A name typed in place, as the explorer of an IDE asks for one: Enter or leaving it accepts, Escape
|
|
192
|
-
* cancels. `validate` tells what is wrong (an error) or odd (a warning) while it is typed.
|
|
193
|
-
*/
|
|
194
|
-
export function NameInput({
|
|
195
|
-
initial,
|
|
196
|
-
validate,
|
|
197
|
-
onDone,
|
|
198
|
-
selectBase,
|
|
199
|
-
}: {
|
|
200
|
-
initial: string;
|
|
201
|
-
validate(name: string): { message: string; severity: 'error' | 'warning' } | undefined;
|
|
202
|
-
/** undefined: cancelled. */
|
|
203
|
-
onDone(name: string | undefined): void;
|
|
204
|
-
/** Selects the name without its extension, as a rename does. */
|
|
205
|
-
selectBase?: boolean;
|
|
206
|
-
}) {
|
|
207
|
-
const [value, setValue] = React.useState(initial);
|
|
208
|
-
const input = React.useRef<HTMLInputElement>(null);
|
|
209
|
-
const done = React.useRef(false);
|
|
210
|
-
React.useEffect(() => {
|
|
211
|
-
const element = input.current;
|
|
212
|
-
if (element) {
|
|
213
|
-
element.focus();
|
|
214
|
-
const dot = initial.lastIndexOf('.');
|
|
215
|
-
element.setSelectionRange(0, selectBase && dot > 0 ? dot : initial.length);
|
|
216
|
-
}
|
|
217
|
-
}, [initial, selectBase]);
|
|
218
|
-
// Nothing typed yet is not a mistake: the box only says what is wrong once there is a name.
|
|
219
|
-
const problem = value ? validate(value) : undefined;
|
|
220
|
-
const finish = (accept: boolean) => {
|
|
221
|
-
if (done.current) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
if (accept && problem?.severity === 'error' && value.trim()) {
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
done.current = true;
|
|
228
|
-
onDone(accept && value.trim() && value !== initial ? value : undefined);
|
|
229
|
-
};
|
|
230
|
-
return (
|
|
231
|
-
<span className="taw-name-input">
|
|
232
|
-
<input
|
|
233
|
-
ref={input}
|
|
234
|
-
className={`taw-input taw-inline ${problem ? `taw-${problem.severity}` : ''}`}
|
|
235
|
-
value={value}
|
|
236
|
-
spellCheck={false}
|
|
237
|
-
aria-invalid={problem?.severity === 'error'}
|
|
238
|
-
onChange={event => setValue(event.target.value)}
|
|
239
|
-
onClick={event => event.stopPropagation()}
|
|
240
|
-
onKeyDown={event => {
|
|
241
|
-
event.stopPropagation();
|
|
242
|
-
if (event.key === 'Enter') {
|
|
243
|
-
event.preventDefault();
|
|
244
|
-
finish(true);
|
|
245
|
-
} else if (event.key === 'Escape') {
|
|
246
|
-
event.preventDefault();
|
|
247
|
-
finish(false);
|
|
248
|
-
}
|
|
249
|
-
}}
|
|
250
|
-
onBlur={() => finish(problem?.severity !== 'error')}
|
|
251
|
-
/>
|
|
252
|
-
{problem && <span className={`taw-input-message taw-${problem.severity}`}>{problem.message}</span>}
|
|
253
|
-
</span>
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/** A part of a view with a header that folds it, as the groups of source control: a title, a count, actions on hover. */
|
|
258
|
-
export function Section({
|
|
259
|
-
title,
|
|
260
|
-
count,
|
|
261
|
-
open,
|
|
262
|
-
onToggle,
|
|
263
|
-
actions,
|
|
264
|
-
children,
|
|
265
|
-
}: {
|
|
266
|
-
title: string;
|
|
267
|
-
count?: number;
|
|
268
|
-
open: boolean;
|
|
269
|
-
onToggle(): void;
|
|
270
|
-
actions?: React.ReactNode;
|
|
271
|
-
children?: React.ReactNode;
|
|
272
|
-
}) {
|
|
273
|
-
return (
|
|
274
|
-
<section className="taw-section">
|
|
275
|
-
<div className="taw-section-head">
|
|
276
|
-
<button type="button" className="taw-section-toggle" aria-expanded={open} onClick={onToggle}>
|
|
277
|
-
<span className="taw-twisty">
|
|
278
|
-
<Glyph name={open ? 'ChevronDown' : 'ChevronRight'} size={14} />
|
|
279
|
-
</span>
|
|
280
|
-
<span className="taw-section-title">{title}</span>
|
|
281
|
-
</button>
|
|
282
|
-
<div className="taw-row-actions">{actions}</div>
|
|
283
|
-
{count !== undefined && <span className="taw-badge">{count}</span>}
|
|
284
|
-
</div>
|
|
285
|
-
{open && children}
|
|
286
|
-
</section>
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/** Writes to the clipboard, and says so. */
|
|
291
|
-
export function copyText(text: string, done: string): void {
|
|
292
|
-
navigator.clipboard.writeText(text).then(
|
|
293
|
-
() => pi.ui.notify(done),
|
|
294
|
-
error => pi.ui.notify(Host.message(error), 'error'),
|
|
295
|
-
);
|
|
296
|
-
}
|