@kubohiroya/turbowarp-plus-editor-project-folder 0.7.0 → 0.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.ja.md +5 -1
- package/README.md +4 -0
- package/dist/THIRD_PARTY_NOTICES.md +716 -0
- package/dist/create-folder.d.ts +8 -0
- package/dist/explorer-files.d.ts +15 -0
- package/dist/explorer-menu.d.ts +49 -0
- package/dist/explorer.d.ts +46 -1
- package/dist/explorer.js +1911 -672
- package/dist/file-preview.d.ts +24 -0
- package/dist/folder-registry.d.ts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +1028 -541
- package/dist/session.d.ts +10 -1
- package/dist/shared-JdaDvk2R.js +588 -0
- package/dist/shared-kI7qYraF.js +30130 -0
- package/dist/source.d.ts +4 -2
- package/dist/text-file-editor.d.ts +17 -0
- package/package.json +16 -1
- package/src/create-folder.ts +99 -0
- package/src/explorer-files.ts +167 -0
- package/src/explorer-menu.tsx +125 -0
- package/src/explorer.tsx +351 -16
- package/src/file-preview.ts +134 -0
- package/src/folder-registry.ts +50 -0
- package/src/index.ts +42 -2
- package/src/session.ts +105 -20
- package/src/source.ts +42 -38
- package/src/text-file-editor.ts +356 -0
- package/vite.config.ts +2 -0
- package/dist/shared-DLcytVOx.js +0 -445
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import {defaultKeymap, history, historyKeymap} from '@codemirror/commands';
|
|
2
|
+
import {css} from '@codemirror/lang-css';
|
|
3
|
+
import {html} from '@codemirror/lang-html';
|
|
4
|
+
import {javascript} from '@codemirror/lang-javascript';
|
|
5
|
+
import {json} from '@codemirror/lang-json';
|
|
6
|
+
import {markdown} from '@codemirror/lang-markdown';
|
|
7
|
+
import {python} from '@codemirror/lang-python';
|
|
8
|
+
import {xml} from '@codemirror/lang-xml';
|
|
9
|
+
import {yaml} from '@codemirror/lang-yaml';
|
|
10
|
+
import {HighlightStyle, StreamLanguage, syntaxHighlighting} from '@codemirror/language';
|
|
11
|
+
import {shell} from '@codemirror/legacy-modes/mode/shell';
|
|
12
|
+
import {MergeView} from '@codemirror/merge';
|
|
13
|
+
import {EditorState} from '@codemirror/state';
|
|
14
|
+
import {drawSelection, EditorView, highlightActiveLine, highlightSpecialChars, keymap, lineNumbers} from '@codemirror/view';
|
|
15
|
+
import {tags} from '@lezer/highlight';
|
|
16
|
+
import type {FileBaseline} from './file-preview.js';
|
|
17
|
+
|
|
18
|
+
const decoder = new TextDecoder('utf-8', {fatal: true, ignoreBOM: true});
|
|
19
|
+
const encoder = new TextEncoder();
|
|
20
|
+
|
|
21
|
+
export function decodeText(bytes: ArrayBuffer | Uint8Array): string | null {
|
|
22
|
+
try {
|
|
23
|
+
const content = decoder.decode(bytes as ArrayBuffer | Uint8Array<ArrayBuffer>);
|
|
24
|
+
return /[\u0000-\u0008\u000b\u000e-\u001f\u007f]/u.test(content) ? null : content;
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const languageFor = (extension: string) => {
|
|
31
|
+
switch (extension) {
|
|
32
|
+
case 'js': case 'mjs': case 'cjs': return javascript();
|
|
33
|
+
case 'jsx': return javascript({jsx: true});
|
|
34
|
+
case 'ts': case 'mts': case 'cts': return javascript({typescript: true});
|
|
35
|
+
case 'tsx': return javascript({typescript: true, jsx: true});
|
|
36
|
+
case 'json': case 'jsonc': return json();
|
|
37
|
+
case 'yaml': case 'yml': return yaml();
|
|
38
|
+
case 'md': case 'markdown': return markdown();
|
|
39
|
+
case 'html': case 'htm': return html();
|
|
40
|
+
case 'css': return css();
|
|
41
|
+
case 'xml': return xml();
|
|
42
|
+
case 'py': return python();
|
|
43
|
+
case 'sh': case 'bash': return StreamLanguage.define(shell);
|
|
44
|
+
default: return [];
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const highlighting = syntaxHighlighting(HighlightStyle.define([
|
|
49
|
+
{tag: [tags.comment, tags.quote], class: 'twpf-syntax-comment'},
|
|
50
|
+
{tag: [tags.keyword, tags.bool, tags.null, tags.meta], class: 'twpf-syntax-keyword'},
|
|
51
|
+
{tag: [tags.string, tags.regexp], class: 'twpf-syntax-string'},
|
|
52
|
+
{tag: [tags.propertyName, tags.attributeName, tags.tagName, tags.heading], class: 'twpf-syntax-name'},
|
|
53
|
+
{tag: [tags.number, tags.atom, tags.literal], class: 'twpf-syntax-number'}
|
|
54
|
+
]));
|
|
55
|
+
|
|
56
|
+
const styles = `
|
|
57
|
+
.twpf-text-file{display:flex;flex-direction:column;height:100%;min-height:0;font:inherit}
|
|
58
|
+
.twpf-file-toolbar,.twpf-diff-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:.4rem;padding:.5rem .7rem;
|
|
59
|
+
border-bottom:1px solid var(--ui-black-transparent,rgba(128,128,128,.25))}
|
|
60
|
+
.twpf-file-path{font-size:.83em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-inline-end:auto;min-width:0}
|
|
61
|
+
.twpf-file-actions{display:flex;gap:.25rem}
|
|
62
|
+
.twpf-text-file button{font:inherit;font-size:.85em;color:inherit;background:transparent;border:1px solid
|
|
63
|
+
var(--ui-black-transparent,rgba(128,128,128,.45));border-radius:.3rem;padding:.25rem .55rem;cursor:pointer}
|
|
64
|
+
.twpf-text-file button[aria-pressed=true]{background:var(--motion-primary,#2468b7);border-color:transparent;color:#fff}
|
|
65
|
+
.twpf-text-file button:disabled{opacity:.55;cursor:default}
|
|
66
|
+
.twpf-file-status,.twpf-diff-status{margin:0;padding:.35rem .7rem;font-size:.82em}
|
|
67
|
+
.twpf-file-edit,.twpf-file-diff{flex:1;min-height:0}
|
|
68
|
+
.twpf-file-edit>.cm-editor{height:100%}
|
|
69
|
+
.twpf-file-diff{display:flex;flex-direction:column}
|
|
70
|
+
.twpf-text-file [hidden]{display:none}
|
|
71
|
+
.twpf-diff-headings{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));font-size:.83em;
|
|
72
|
+
border-bottom:1px solid var(--ui-black-transparent,rgba(128,128,128,.25))}
|
|
73
|
+
.twpf-diff-headings span{padding:.4rem .7rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
74
|
+
.twpf-diff-content{flex:1;min-height:0;overflow:auto}
|
|
75
|
+
.twpf-diff-content .cm-mergeViewEditor+.cm-mergeViewEditor{border-inline-start:1px solid var(--ui-black-transparent,rgba(128,128,128,.25))}
|
|
76
|
+
.twpf-text-file .cm-content{font:.875rem/1.55 monospace}
|
|
77
|
+
.twpf-text-file .cm-gutters{background:transparent;color:inherit;border-color:rgba(128,128,128,.25);font:.78rem/1.74 monospace}
|
|
78
|
+
.twpf-text-file .cm-activeLine,.twpf-text-file .cm-activeLineGutter{background:rgba(128,128,128,.12)}
|
|
79
|
+
.twpf-text-file .cm-collapsedLines{color:inherit;background:rgba(128,128,128,.12);border-color:rgba(128,128,128,.24)}
|
|
80
|
+
.twpf-syntax-comment{color:light-dark(#586576,#a6b0bc)}
|
|
81
|
+
.twpf-syntax-keyword{color:light-dark(#80359b,#dda7ef)}
|
|
82
|
+
.twpf-syntax-string{color:light-dark(#1b6c45,#9ddaac)}
|
|
83
|
+
.twpf-syntax-name{color:light-dark(#145e97,#99cfff)}
|
|
84
|
+
.twpf-syntax-number{color:light-dark(#8d440e,#f0b28a)}
|
|
85
|
+
`;
|
|
86
|
+
|
|
87
|
+
const messages = {
|
|
88
|
+
en: {
|
|
89
|
+
edit: 'Edit', diff: 'Diff', changes: 'Changes only', whole: 'Full file', refresh: 'Reload latest commit',
|
|
90
|
+
save: 'Save file', unsaved: 'Unsaved changes', saving: 'Saving…', saved: 'File saved.',
|
|
91
|
+
conflict: 'The file changed outside this tab. Your edits are still here. Reopen the file to load the current version.',
|
|
92
|
+
saveFailed: 'The file could not be saved.', tooLarge: 'The text file exceeds the 4 MiB limit.',
|
|
93
|
+
close: 'Discard the unsaved edits to this file?', loading: 'Reading the latest commit…',
|
|
94
|
+
noGit: 'No accessible Git repository for this file. Select its repository in Local Git to compare.',
|
|
95
|
+
readFailed: 'The committed version could not be read.', unsupported: 'The committed version is not a UTF-8 text file.',
|
|
96
|
+
missing: 'This file is not in the latest commit.', unborn: 'This branch has no commits yet.',
|
|
97
|
+
same: 'No differences.', formatting: 'The line endings or UTF-8 BOM differ.',
|
|
98
|
+
before: 'Latest commit', after: 'Current content', collapsed: '$ unchanged lines'
|
|
99
|
+
},
|
|
100
|
+
ja: {
|
|
101
|
+
edit: '編集', diff: '差分', changes: '変更箇所のみ', whole: '全体', refresh: '最新コミットを読み直す',
|
|
102
|
+
save: 'ファイルを保存', unsaved: '未保存の変更があります', saving: '保存中…', saved: 'ファイルを保存しました。',
|
|
103
|
+
conflict: 'ファイルがこのタブの外で変更されました。編集内容はタブに残っています。現在の内容を読むにはファイルを開き直してください。',
|
|
104
|
+
saveFailed: 'ファイルを保存できませんでした。', tooLarge: 'テキストファイルの上限(4 MiB)を超えています。',
|
|
105
|
+
close: 'このファイルの未保存の編集を破棄しますか?', loading: '最新コミットを読み込んでいます…',
|
|
106
|
+
noGit: 'このファイルの Git リポジトリを参照できません。比較するにはローカル Git でリポジトリを選んでください。',
|
|
107
|
+
readFailed: 'コミット済みの内容を読み込めませんでした。', unsupported: 'コミット済みの内容は UTF-8 テキストとして表示できません。',
|
|
108
|
+
missing: '最新コミットにこのファイルはありません。', unborn: 'このブランチにはまだコミットがありません。',
|
|
109
|
+
same: '差分はありません。', formatting: '改行コードまたは UTF-8 BOM が異なります。',
|
|
110
|
+
before: '最新コミット', after: '現在の内容', collapsed: '変更のない $ 行'
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
type TextFileOptions = {
|
|
115
|
+
path: string;
|
|
116
|
+
extension: string;
|
|
117
|
+
content: string;
|
|
118
|
+
locale: string;
|
|
119
|
+
limit: number;
|
|
120
|
+
readHandle(): Promise<FileSystemFileHandle>;
|
|
121
|
+
readBaseline?(): Promise<FileBaseline | null>;
|
|
122
|
+
close(): void;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export function mountTextFile(parent: HTMLElement, options: TextFileOptions) {
|
|
126
|
+
const {ownerDocument: document} = parent;
|
|
127
|
+
const browser = document.defaultView;
|
|
128
|
+
const message = options.locale.toLowerCase().startsWith('ja') ? messages.ja : messages.en;
|
|
129
|
+
const element = <Tag extends 'div' | 'span' | 'p'>(tag: Tag, className: string) => {
|
|
130
|
+
const node = document.createElement(tag);
|
|
131
|
+
node.className = className;
|
|
132
|
+
return node;
|
|
133
|
+
};
|
|
134
|
+
const button = (label: string, action: () => void) => {
|
|
135
|
+
const node = document.createElement('button');
|
|
136
|
+
node.type = 'button';
|
|
137
|
+
node.textContent = label;
|
|
138
|
+
node.addEventListener('click', action);
|
|
139
|
+
return node;
|
|
140
|
+
};
|
|
141
|
+
const press = (node: HTMLButtonElement, active: boolean) => node.setAttribute('aria-pressed', String(active));
|
|
142
|
+
const setStatus = (node: HTMLElement, text: string) => {node.textContent = text; node.hidden = !text;};
|
|
143
|
+
const panel = element('div', 'twpf-text-file');
|
|
144
|
+
const style = document.createElement('style');
|
|
145
|
+
style.textContent = styles;
|
|
146
|
+
const toolbar = element('div', 'twpf-file-toolbar');
|
|
147
|
+
const path = element('span', 'twpf-file-path');
|
|
148
|
+
path.textContent = path.title = options.path;
|
|
149
|
+
const status = element('p', 'twpf-file-status');
|
|
150
|
+
status.setAttribute('role', 'status');
|
|
151
|
+
const editPane = element('div', 'twpf-file-edit');
|
|
152
|
+
const diffPane = element('div', 'twpf-file-diff');
|
|
153
|
+
const diffToolbar = element('div', 'twpf-diff-toolbar');
|
|
154
|
+
const headings = element('div', 'twpf-diff-headings');
|
|
155
|
+
const left = element('span', '');
|
|
156
|
+
const right = element('span', '');
|
|
157
|
+
right.textContent = message.after;
|
|
158
|
+
headings.append(left, right);
|
|
159
|
+
const diffStatus = element('p', 'twpf-diff-status');
|
|
160
|
+
diffStatus.setAttribute('role', 'status');
|
|
161
|
+
const diffContent = element('div', 'twpf-diff-content');
|
|
162
|
+
diffPane.append(diffToolbar, diffStatus, headings, diffContent);
|
|
163
|
+
|
|
164
|
+
let saved = options.content;
|
|
165
|
+
const bom = saved.startsWith('\uFEFF') ? '\uFEFF' : '';
|
|
166
|
+
const initial = saved.slice(bom.length);
|
|
167
|
+
const hasLF = initial.includes('\n');
|
|
168
|
+
const hasCR = initial.includes('\r');
|
|
169
|
+
const mixed = hasLF && hasCR && /(^|[^\r])\n|\r(?!\n)/u.test(initial);
|
|
170
|
+
// When LF and CRLF are mixed, keep CRs in existing lines and use LF for new lines.
|
|
171
|
+
const newline = hasCR && !mixed ? hasLF ? '\r\n' : '\r' : '\n';
|
|
172
|
+
const common = [lineNumbers(), languageFor(options.extension), highlighting];
|
|
173
|
+
let savedDoc = EditorState.create({doc: initial, extensions: mixed ? EditorState.lineSeparator.of('\n') : []}).doc;
|
|
174
|
+
let merge: MergeView | undefined;
|
|
175
|
+
let saving = false;
|
|
176
|
+
let disposed = false;
|
|
177
|
+
let comparison: boolean | undefined;
|
|
178
|
+
let changesOnly = true;
|
|
179
|
+
let readVersion = 0;
|
|
180
|
+
const collapseUnchanged = {margin: 0, minSize: 1};
|
|
181
|
+
const edit = button(message.edit, () => showDiff(false));
|
|
182
|
+
const diff = button(message.diff, () => showDiff(true));
|
|
183
|
+
const saveButton = button(message.save, () => void save());
|
|
184
|
+
const changes = button(message.changes, () => changeVisibility(true));
|
|
185
|
+
const whole = button(message.whole, () => changeVisibility(false));
|
|
186
|
+
const refresh = button(message.refresh, () => void loadBaseline());
|
|
187
|
+
const modes = element('div', 'twpf-file-actions');
|
|
188
|
+
modes.append(edit, diff);
|
|
189
|
+
toolbar.append(path, modes, saveButton);
|
|
190
|
+
const ranges = element('div', 'twpf-file-actions');
|
|
191
|
+
ranges.append(changes, whole);
|
|
192
|
+
diffToolbar.append(ranges, refresh);
|
|
193
|
+
panel.append(style, toolbar, status, editPane, diffPane);
|
|
194
|
+
parent.append(panel);
|
|
195
|
+
|
|
196
|
+
const view = new EditorView({
|
|
197
|
+
parent: editPane, doc: savedDoc,
|
|
198
|
+
extensions: [
|
|
199
|
+
common, mixed ? EditorState.lineSeparator.of('\n') : [], history(), drawSelection(), highlightSpecialChars(),
|
|
200
|
+
highlightActiveLine(), EditorView.contentAttributes.of({'aria-label': options.path}),
|
|
201
|
+
keymap.of([...defaultKeymap, ...historyKeymap]),
|
|
202
|
+
EditorView.updateListener.of(update => {if (update.docChanged) updateSaveState();})
|
|
203
|
+
]
|
|
204
|
+
});
|
|
205
|
+
const dirty = () => !view.state.doc.eq(savedDoc);
|
|
206
|
+
const serialize = () => bom + (newline === '\n' ? view.state.doc.toString() : view.state.doc.toString().replace(/\n/gu, newline));
|
|
207
|
+
|
|
208
|
+
function updateSaveState(text = saving ? message.saving : dirty() ? message.unsaved : '') {
|
|
209
|
+
saveButton.disabled = saving || !dirty();
|
|
210
|
+
setStatus(status, text);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async function unchanged(handle: FileSystemFileHandle) {
|
|
214
|
+
try {
|
|
215
|
+
const file = await handle.getFile();
|
|
216
|
+
return file.size <= options.limit && decodeText(await file.arrayBuffer()) === saved;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (['NotFoundError', 'TypeMismatchError'].includes((error as DOMException).name)) return false;
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async function save() {
|
|
224
|
+
if (saving || disposed || !dirty()) return;
|
|
225
|
+
const doc = view.state.doc;
|
|
226
|
+
const content = serialize();
|
|
227
|
+
const bytes = encoder.encode(content);
|
|
228
|
+
if (bytes.byteLength > options.limit) return updateSaveState(message.tooLarge);
|
|
229
|
+
saving = true;
|
|
230
|
+
updateSaveState();
|
|
231
|
+
let result = message.saveFailed;
|
|
232
|
+
let writable: FileSystemWritableFileStream | undefined;
|
|
233
|
+
try {
|
|
234
|
+
const handle = await options.readHandle();
|
|
235
|
+
if (!await unchanged(handle)) {
|
|
236
|
+
result = message.conflict;
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (disposed) return;
|
|
240
|
+
writable = await handle.createWritable({mode: 'exclusive'} as FileSystemCreateWritableOptions);
|
|
241
|
+
await writable.write(bytes);
|
|
242
|
+
const current = await options.readHandle();
|
|
243
|
+
if (!await current.isSameEntry(handle) || !await unchanged(current)) {
|
|
244
|
+
result = message.conflict;
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (disposed) return;
|
|
248
|
+
await writable.close();
|
|
249
|
+
writable = undefined;
|
|
250
|
+
saved = content;
|
|
251
|
+
savedDoc = doc;
|
|
252
|
+
result = dirty() ? message.unsaved : message.saved;
|
|
253
|
+
} catch (error) {
|
|
254
|
+
if (['NotFoundError', 'TypeMismatchError'].includes((error as DOMException).name)) result = message.conflict;
|
|
255
|
+
} finally {
|
|
256
|
+
await writable?.abort().catch(() => {});
|
|
257
|
+
saving = false;
|
|
258
|
+
if (!disposed) updateSaveState(result);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function destroyDiff() {
|
|
263
|
+
merge?.destroy();
|
|
264
|
+
merge = undefined;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function changeVisibility(onlyChanges: boolean) {
|
|
268
|
+
changesOnly = onlyChanges;
|
|
269
|
+
press(changes, onlyChanges);
|
|
270
|
+
press(whole, !onlyChanges);
|
|
271
|
+
merge?.reconfigure({collapseUnchanged: onlyChanges ? collapseUnchanged : undefined});
|
|
272
|
+
diffContent.hidden = !merge || (onlyChanges && merge.chunks.length === 0);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function showDiff(active: boolean) {
|
|
276
|
+
if (comparison === active) return;
|
|
277
|
+
comparison = active;
|
|
278
|
+
editPane.hidden = active;
|
|
279
|
+
diffPane.hidden = !active;
|
|
280
|
+
press(edit, !active);
|
|
281
|
+
press(diff, active);
|
|
282
|
+
if (active) void loadBaseline();
|
|
283
|
+
else {
|
|
284
|
+
++readVersion;
|
|
285
|
+
destroyDiff();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async function loadBaseline() {
|
|
290
|
+
const version = ++readVersion;
|
|
291
|
+
destroyDiff();
|
|
292
|
+
headings.hidden = true;
|
|
293
|
+
changes.disabled = whole.disabled = true;
|
|
294
|
+
refresh.disabled = true;
|
|
295
|
+
changeVisibility(changesOnly);
|
|
296
|
+
setStatus(diffStatus, message.loading);
|
|
297
|
+
const current = () => !disposed && comparison && version === readVersion;
|
|
298
|
+
try {
|
|
299
|
+
const base = await options.readBaseline?.();
|
|
300
|
+
if (!current()) return;
|
|
301
|
+
if (!base) return setStatus(diffStatus, message.noGit);
|
|
302
|
+
const text = base.bytes ? decodeText(base.bytes) : '';
|
|
303
|
+
if (text === null) return setStatus(diffStatus, message.unsupported);
|
|
304
|
+
const edited = serialize();
|
|
305
|
+
if (encoder.encode(edited).byteLength > options.limit) return setStatus(diffStatus, message.tooLarge);
|
|
306
|
+
left.textContent = [message.before, base.branch, base.head?.slice(0, 8)].filter(Boolean).join(' · ');
|
|
307
|
+
left.title = base.head ?? left.textContent;
|
|
308
|
+
const readOnly = (label: string) => [common, EditorState.readOnly.of(true), EditorView.editable.of(false),
|
|
309
|
+
EditorView.contentAttributes.of({'aria-label': label, tabindex: '0'}),
|
|
310
|
+
EditorState.phrases.of({'$ unchanged lines': message.collapsed})];
|
|
311
|
+
merge = new MergeView({
|
|
312
|
+
parent: diffContent,
|
|
313
|
+
a: {doc: text.replace(/^\uFEFF/u, ''), extensions: readOnly(left.textContent)},
|
|
314
|
+
b: {doc: edited.replace(/^\uFEFF/u, ''), extensions: readOnly(message.after)},
|
|
315
|
+
diffConfig: {scanLimit: 500, timeout: 100}
|
|
316
|
+
});
|
|
317
|
+
headings.hidden = false;
|
|
318
|
+
changes.disabled = whole.disabled = false;
|
|
319
|
+
changeVisibility(changesOnly);
|
|
320
|
+
const notice = !base.head ? message.unborn : !base.bytes ? message.missing :
|
|
321
|
+
merge.chunks.length ? '' : text === edited ? message.same : message.formatting;
|
|
322
|
+
setStatus(diffStatus, notice);
|
|
323
|
+
} catch (error) {
|
|
324
|
+
if (current()) setStatus(diffStatus, (error as {code?: string})?.code === 'large' ? message.tooLarge : message.readFailed);
|
|
325
|
+
} finally {
|
|
326
|
+
if (current()) refresh.disabled = !options.readBaseline;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const beforeUnload = (event: BeforeUnloadEvent) => {
|
|
331
|
+
if (!dirty()) return;
|
|
332
|
+
event.preventDefault();
|
|
333
|
+
event.returnValue = '';
|
|
334
|
+
};
|
|
335
|
+
panel.addEventListener('keydown', event => {
|
|
336
|
+
if (!(event.metaKey || event.ctrlKey) || event.key.toLowerCase() !== 's') return;
|
|
337
|
+
event.preventDefault();
|
|
338
|
+
event.stopPropagation();
|
|
339
|
+
void save();
|
|
340
|
+
});
|
|
341
|
+
browser?.addEventListener('beforeunload', beforeUnload);
|
|
342
|
+
showDiff(false);
|
|
343
|
+
updateSaveState();
|
|
344
|
+
return {
|
|
345
|
+
requestClose() {
|
|
346
|
+
if (!saving && (!dirty() || browser?.confirm(message.close))) options.close();
|
|
347
|
+
},
|
|
348
|
+
dispose() {
|
|
349
|
+
disposed = true;
|
|
350
|
+
browser?.removeEventListener('beforeunload', beforeUnload);
|
|
351
|
+
destroyDiff();
|
|
352
|
+
view.destroy();
|
|
353
|
+
panel.remove();
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
}
|
package/vite.config.ts
CHANGED
|
@@ -4,6 +4,8 @@ export default defineConfig({
|
|
|
4
4
|
build: {
|
|
5
5
|
// The pinned Scratch GUI still parses the library with Webpack 4.
|
|
6
6
|
target: 'es2017',
|
|
7
|
+
// Leave class bindings intact for Webpack 4's scope hoisting and final minification.
|
|
8
|
+
minify: false,
|
|
7
9
|
license: {fileName: 'THIRD_PARTY_NOTICES.md'},
|
|
8
10
|
lib: {
|
|
9
11
|
entry: {index: 'src/index.ts', explorer: 'src/explorer.tsx'},
|