@kubohiroya/turbowarp-plus-editor-workbench 0.14.0 → 0.16.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/NOTICE +26 -0
- package/README.ja.md +22 -0
- package/README.md +22 -0
- package/dist/backpack-script.d.ts +2 -0
- package/dist/backpack-script.js +23 -0
- package/dist/backpack.d.ts +60 -0
- package/dist/backpack.js +226 -0
- package/dist/browser-tab-title.d.ts +2 -0
- package/dist/browser-tab-title.js +5 -0
- package/dist/busy-cursor.d.ts +22 -0
- package/dist/busy-cursor.js +107 -0
- package/dist/edit-menu.d.ts +57 -0
- package/dist/edit-menu.js +99 -0
- package/dist/info-menu.d.ts +39 -0
- package/dist/info-menu.js +157 -0
- package/dist/project-file-dialogs.d.ts +70 -0
- package/dist/project-file-dialogs.js +625 -0
- package/dist/project-file-menu.d.ts +43 -0
- package/dist/project-file-menu.js +90 -0
- package/dist/project-load-progress-view.d.ts +6 -0
- package/dist/project-load-progress-view.js +66 -0
- package/dist/project-load-progress.d.ts +26 -0
- package/dist/project-load-progress.js +104 -0
- package/dist/project-search-box.d.ts +43 -0
- package/dist/project-search-box.js +437 -0
- package/dist/project-size-approval.d.ts +10 -0
- package/dist/project-size-approval.js +64 -0
- package/dist/stage-controls-view.d.ts +45 -0
- package/dist/stage-controls-view.js +127 -0
- package/dist/stage-controls.d.ts +98 -0
- package/dist/stage-controls.js +110 -0
- package/package.json +97 -28
- package/src/backpack-script.ts +21 -0
- package/src/backpack.tsx +260 -0
- package/src/browser-tab-title.ts +6 -0
- package/src/busy-cursor.ts +108 -0
- package/src/edit-menu.css +42 -0
- package/src/edit-menu.tsx +139 -0
- package/src/info-menu.css +172 -0
- package/src/info-menu.tsx +221 -0
- package/src/project-file-dialogs.ts +654 -0
- package/src/project-file-menu.css +94 -0
- package/src/project-file-menu.tsx +137 -0
- package/src/project-load-progress-view.tsx +75 -0
- package/src/project-load-progress.css +57 -0
- package/src/project-load-progress.ts +118 -0
- package/src/project-search-box.tsx +469 -0
- package/src/project-search.css +116 -0
- package/src/project-size-approval.ts +74 -0
- package/src/sprite-layout-menu.css +2 -1
- package/src/stage-controls-view.tsx +178 -0
- package/src/stage-controls.css +192 -0
- package/src/stage-controls.ts +124 -0
|
@@ -0,0 +1,654 @@
|
|
|
1
|
+
import {dialogAction, dialogActions} from '@kubohiroya/turbowarp-plus-editor-windows';
|
|
2
|
+
import type {CreationInteraction, GitHubCreationAccount, GitHubRepositoryDraft, RepositoryCreationControls,
|
|
3
|
+
RepositoryCreationProgress, RepositoryReceipt} from '@kubohiroya/turbowarp-plus-editor-git/project-repository-creation';
|
|
4
|
+
|
|
5
|
+
export type Action = () => void;
|
|
6
|
+
export type FolderActions = {open: Action; save?: Action; detach: Action};
|
|
7
|
+
export type SaveFormat = 'current' | 'embedded' | 'folder';
|
|
8
|
+
type Serialize = <T>(run: () => T) => T;
|
|
9
|
+
|
|
10
|
+
export type SaveAsRequest =
|
|
11
|
+
| {name: string; format: 'current' | 'embedded'}
|
|
12
|
+
| {name: string; format: 'folder'; git?: GitHubRepositoryDraft};
|
|
13
|
+
|
|
14
|
+
export interface SaveAsFormOptions {
|
|
15
|
+
openCommit?: Action;
|
|
16
|
+
folder?: {
|
|
17
|
+
overwriteWarning?: string;
|
|
18
|
+
github?: {
|
|
19
|
+
// The host can reuse a current session or open sign-in. The form retains its draft either way.
|
|
20
|
+
connectForCreation(interaction: CreationInteraction): Promise<GitHubCreationAccount | null>;
|
|
21
|
+
licenses?: readonly {id: string; label: string}[];
|
|
22
|
+
publication?: RepositoryCreationControls;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ProjectFileStorage {
|
|
28
|
+
canSave: boolean;
|
|
29
|
+
filename: string;
|
|
30
|
+
overwrite?: Action;
|
|
31
|
+
pick?: (filename: string) => Promise<FileSystemFileHandle>;
|
|
32
|
+
write(handle: FileSystemFileHandle, serialize: Serialize, current: () => boolean): Promise<void>;
|
|
33
|
+
download(filename: string, serialize: Serialize, current: () => boolean): Promise<void>;
|
|
34
|
+
finish(handle: FileSystemFileHandle | null, title: string, unchanged: boolean): void;
|
|
35
|
+
fail(error: unknown): void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Saving over the last file or into the project folder first collects edits held by other windows,
|
|
40
|
+
* as Save As does, so a save that does not move the focus to the editor misses nothing. A failed
|
|
41
|
+
* collection reports the failure, does not save, and leaves those edits for a retry.
|
|
42
|
+
*/
|
|
43
|
+
export function collectBeforeSaving(storage: ProjectFileStorage, folder: FolderActions | undefined,
|
|
44
|
+
collect: () => Promise<void>) {
|
|
45
|
+
const first = (action?: Action) => action && (async () => {
|
|
46
|
+
try {
|
|
47
|
+
await collect();
|
|
48
|
+
} catch (error) {
|
|
49
|
+
storage.fail(error);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
action();
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
storage: storage.overwrite ? {...storage, overwrite: first(storage.overwrite)} : storage,
|
|
56
|
+
folder: folder?.save ? {...folder, save: first(folder.save)} : folder
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function projectSaveShortcut(storage: ProjectFileStorage, folder?: FolderActions, saveAs?: Action) {
|
|
61
|
+
if (storage.canSave) (storage.overwrite || folder?.save || saveAs)?.();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function saveProjectAs(storage: ProjectFileStorage, name: string, {
|
|
65
|
+
current, unchanged, serialize, committed, collect
|
|
66
|
+
}: {
|
|
67
|
+
current(): boolean;
|
|
68
|
+
unchanged(): boolean;
|
|
69
|
+
serialize<T>(title: string, run: () => T): T;
|
|
70
|
+
committed(): void;
|
|
71
|
+
// Collects edits still held by other windows. A failure leaves them there for a retry.
|
|
72
|
+
collect?(): Promise<void>;
|
|
73
|
+
}) {
|
|
74
|
+
if (!storage.canSave || !current()) return false;
|
|
75
|
+
const filename = name + '.sb3';
|
|
76
|
+
try {
|
|
77
|
+
const handle = storage.pick ? await storage.pick(filename) : null;
|
|
78
|
+
if (!current()) return false;
|
|
79
|
+
await collect?.();
|
|
80
|
+
if (!current()) return false;
|
|
81
|
+
const title = handle ? handle.name.replace(/\.sb3$/i, '').slice(0, 100) : name;
|
|
82
|
+
const output: Serialize = run => {
|
|
83
|
+
if (!current()) throw new DOMException('The project changed', 'AbortError');
|
|
84
|
+
return serialize(title, run);
|
|
85
|
+
};
|
|
86
|
+
if (handle) await storage.write(handle, output, current);
|
|
87
|
+
else await storage.download(filename, output, current);
|
|
88
|
+
if (!current()) return false;
|
|
89
|
+
committed();
|
|
90
|
+
storage.finish(handle, title, unchanged());
|
|
91
|
+
return true;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
storage.fail(error);
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const validRepositoryName = (name: string) => /^[A-Za-z0-9_.-]{1,100}$/.test(name) &&
|
|
99
|
+
name !== '.' && name !== '..' && !/\.git$/i.test(name);
|
|
100
|
+
|
|
101
|
+
function parseGitHubRepositoryUrl(url: string) {
|
|
102
|
+
const match = /^https:\/\/github\.com\/([A-Za-z0-9][A-Za-z0-9-]{0,38})\/([A-Za-z0-9_.-]{1,104})\/?$/i.exec(url.trim());
|
|
103
|
+
const name = match?.[2].replace(/\.git$/iu, '');
|
|
104
|
+
return name && validRepositoryName(name) ? {owner: match[1], name} : null;
|
|
105
|
+
}
|
|
106
|
+
const invalidDraft = (message: string) => Object.assign(new Error(message), {code: 'invalidDraft'});
|
|
107
|
+
|
|
108
|
+
const readTopics = (value: string) => value.split(',').map(topic => topic.trim()).filter(Boolean);
|
|
109
|
+
const validTopics = (topics: readonly string[]) => topics.length <= 20 &&
|
|
110
|
+
topics.every(topic => /^[a-z0-9][a-z0-9-]{0,49}$/.test(topic));
|
|
111
|
+
|
|
112
|
+
function appendOption(select: HTMLSelectElement, title: string, value: string) {
|
|
113
|
+
const option = select.ownerDocument.createElement('option');
|
|
114
|
+
option.textContent = title;
|
|
115
|
+
option.value = value;
|
|
116
|
+
select.append(option);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function appendField(parent: HTMLElement, title: string, input: HTMLElement) {
|
|
120
|
+
const label = parent.ownerDocument.createElement('label');
|
|
121
|
+
label.append(title, input);
|
|
122
|
+
parent.append(label);
|
|
123
|
+
return label;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
type GitHubCreationProvider = NonNullable<NonNullable<SaveAsFormOptions['folder']>['github']>;
|
|
127
|
+
|
|
128
|
+
function createGitHubFields(document: Document, label: (ja: string, en: string) => string,
|
|
129
|
+
provider: GitHubCreationProvider, report: (message: string) => void) {
|
|
130
|
+
const panel = document.createElement('fieldset');
|
|
131
|
+
const legend = document.createElement('legend');
|
|
132
|
+
legend.textContent = label('GitHub リポジトリ', 'GitHub repository');
|
|
133
|
+
const identity = document.createElement('p');
|
|
134
|
+
identity.hidden = true;
|
|
135
|
+
panel.append(legend, identity);
|
|
136
|
+
|
|
137
|
+
const owner = document.createElement('select');
|
|
138
|
+
owner.name = 'github-owner';
|
|
139
|
+
owner.disabled = true;
|
|
140
|
+
appendField(panel, label('作成先', 'Repository owner'), owner);
|
|
141
|
+
const name = document.createElement('input');
|
|
142
|
+
name.name = 'github-name';
|
|
143
|
+
name.maxLength = 100;
|
|
144
|
+
appendField(panel, label('リポジトリ名', 'Repository name'), name);
|
|
145
|
+
const url = document.createElement('input');
|
|
146
|
+
url.name = 'github-url';
|
|
147
|
+
url.inputMode = 'url';
|
|
148
|
+
url.placeholder = 'https://github.com/owner/repository';
|
|
149
|
+
appendField(panel, label('GitHub URL(任意)', 'GitHub URL (optional)'), url);
|
|
150
|
+
const description = document.createElement('input');
|
|
151
|
+
description.name = 'github-description';
|
|
152
|
+
description.maxLength = 350;
|
|
153
|
+
appendField(panel, label('概要', 'Description'), description);
|
|
154
|
+
const topics = document.createElement('input');
|
|
155
|
+
topics.name = 'github-topics';
|
|
156
|
+
appendField(panel, label('トピック(カンマ区切り)', 'Topics (comma separated)'), topics);
|
|
157
|
+
const topicError = label('トピックは小文字・数字・ハイフンで、1件50文字以内、20件以内です。',
|
|
158
|
+
'Use at most 20 topics, each up to 50 characters, with lowercase letters, digits, and hyphens.');
|
|
159
|
+
topics.oninput = () => {
|
|
160
|
+
const valid = validTopics(readTopics(topics.value));
|
|
161
|
+
topics.setAttribute('aria-invalid', String(!valid));
|
|
162
|
+
report(valid ? '' : topicError);
|
|
163
|
+
};
|
|
164
|
+
const license = document.createElement('select');
|
|
165
|
+
license.name = 'github-license';
|
|
166
|
+
appendOption(license, label('なし', 'None'), '');
|
|
167
|
+
for (const choice of provider.licenses ?? []) appendOption(license, choice.label, choice.id);
|
|
168
|
+
appendField(panel, label('ライセンス', 'License'), license);
|
|
169
|
+
const visibility = document.createElement('select');
|
|
170
|
+
visibility.name = 'github-visibility';
|
|
171
|
+
appendOption(visibility, label('非公開', 'Private'), 'private');
|
|
172
|
+
appendOption(visibility, label('公開', 'Public'), 'public');
|
|
173
|
+
appendField(panel, label('公開範囲', 'Visibility'), visibility);
|
|
174
|
+
|
|
175
|
+
let account: GitHubCreationAccount | null = null;
|
|
176
|
+
let requestedOwner: string | null = null;
|
|
177
|
+
const fillOwners = (current: GitHubCreationAccount) => {
|
|
178
|
+
const expected = requestedOwner ?? owner.value;
|
|
179
|
+
owner.replaceChildren();
|
|
180
|
+
for (const choice of current.owners) appendOption(owner, choice.login, choice.login);
|
|
181
|
+
const selected = [...owner.options].find(choice => choice.value.toLowerCase() === expected.toLowerCase());
|
|
182
|
+
if (selected) owner.value = selected.value;
|
|
183
|
+
else if (expected) {
|
|
184
|
+
appendOption(owner, label(`${expected}(選択不可)`, `${expected} (unavailable)`), expected);
|
|
185
|
+
owner.value = expected;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
owner.onchange = () => { requestedOwner = null; };
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
panel,
|
|
192
|
+
get connected() {return account !== null;},
|
|
193
|
+
async connect(open: () => boolean, interaction: CreationInteraction) {
|
|
194
|
+
const result = await provider.connectForCreation(interaction);
|
|
195
|
+
if (!open() || !result) return false;
|
|
196
|
+
account = result;
|
|
197
|
+
identity.hidden = false;
|
|
198
|
+
identity.textContent = label(`GitHub アカウント ${result.account.login}`, `GitHub account ${result.account.login}`);
|
|
199
|
+
fillOwners(result);
|
|
200
|
+
owner.disabled = false;
|
|
201
|
+
return true;
|
|
202
|
+
},
|
|
203
|
+
applyUrl() {
|
|
204
|
+
if (!url.value.trim()) return;
|
|
205
|
+
const parsed = parseGitHubRepositoryUrl(url.value);
|
|
206
|
+
if (!parsed) throw invalidDraft(label('https://github.com/所有者/リポジトリ名 の形式で入力してください。',
|
|
207
|
+
'Enter a URL in the form https://github.com/owner/repository.'));
|
|
208
|
+
requestedOwner = parsed.owner;
|
|
209
|
+
name.value = parsed.name;
|
|
210
|
+
url.value = '';
|
|
211
|
+
if (account) fillOwners(account);
|
|
212
|
+
},
|
|
213
|
+
draft(title: string): GitHubRepositoryDraft {
|
|
214
|
+
if (!validRepositoryName(name.value.trim())) throw invalidDraft(label('有効なリポジトリ名を入力してください。',
|
|
215
|
+
'Enter a valid repository name.'));
|
|
216
|
+
const topicValues = readTopics(topics.value);
|
|
217
|
+
if (!validTopics(topicValues)) throw invalidDraft(topicError);
|
|
218
|
+
const selectedVisibility = visibility.value === 'public' ? 'public' : 'private';
|
|
219
|
+
const destination = account?.owners.find(choice => choice.login === owner.value);
|
|
220
|
+
if (!account || !destination) throw invalidDraft(label('リポジトリを作成できる作成先を選んでください。',
|
|
221
|
+
'Choose an owner where you can create a repository.'));
|
|
222
|
+
if (!destination.canCreate[selectedVisibility]) throw invalidDraft(label('この作成先では選んだ公開範囲を使えません。',
|
|
223
|
+
'The selected visibility is unavailable for this owner.'));
|
|
224
|
+
return {account: account.account.login, owner: destination.login, name: name.value.trim(), title,
|
|
225
|
+
description: description.value.trim(), topics: [...new Set(topicValues)], license: license.value || null,
|
|
226
|
+
visibility: selectedVisibility};
|
|
227
|
+
},
|
|
228
|
+
review(draft: GitHubRepositoryDraft, container: HTMLElement) {
|
|
229
|
+
const heading = document.createElement('h3');
|
|
230
|
+
heading.textContent = label('GitHub リポジトリ作成の確認', 'Review GitHub repository creation');
|
|
231
|
+
heading.tabIndex = -1;
|
|
232
|
+
const details = document.createElement('dl');
|
|
233
|
+
const empty = label('なし', 'None');
|
|
234
|
+
for (const [title, value] of [
|
|
235
|
+
[label('GitHub アカウント', 'GitHub account'), draft.account],
|
|
236
|
+
[label('リポジトリ', 'Repository'), `https://github.com/${draft.owner}/${draft.name}`],
|
|
237
|
+
[label('タイトル', 'Title'), draft.title],
|
|
238
|
+
[label('概要', 'Description'), draft.description || empty],
|
|
239
|
+
[label('トピック', 'Topics'), draft.topics.join(', ') || empty],
|
|
240
|
+
[label('ライセンス', 'License'), license.selectedOptions[0]?.textContent || empty],
|
|
241
|
+
[label('公開範囲', 'Visibility'), draft.visibility === 'private' ? label('非公開', 'Private') : label('公開', 'Public')]
|
|
242
|
+
]) {
|
|
243
|
+
const term = document.createElement('dt');
|
|
244
|
+
term.textContent = title;
|
|
245
|
+
const definition = document.createElement('dd');
|
|
246
|
+
definition.textContent = value;
|
|
247
|
+
details.append(term, definition);
|
|
248
|
+
}
|
|
249
|
+
container.replaceChildren(heading, details);
|
|
250
|
+
return heading;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function renderSaveAsForm(document: Document, locale: string, storage: ProjectFileStorage,
|
|
256
|
+
save: (request: SaveAsRequest, open: () => boolean, signal: AbortSignal) =>
|
|
257
|
+
Promise<boolean | RepositoryCreationProgress | null>, close: Action,
|
|
258
|
+
{folder, openCommit}: SaveAsFormOptions = {}) {
|
|
259
|
+
const label = (ja: string, en: string) => locale.startsWith('ja') ? ja : en;
|
|
260
|
+
const form = document.createElement('form');
|
|
261
|
+
const fields = document.createElement('div');
|
|
262
|
+
const name = document.createElement('input');
|
|
263
|
+
name.name = 'title';
|
|
264
|
+
name.required = true;
|
|
265
|
+
name.maxLength = 100;
|
|
266
|
+
name.value = storage.filename.replace(/\.sb3$/i, '');
|
|
267
|
+
const nameField = appendField(fields, label('名前', 'Name'), name);
|
|
268
|
+
const format = document.createElement('select');
|
|
269
|
+
format.name = 'format';
|
|
270
|
+
appendOption(format, label('SB3(現在の格納方式)', 'SB3 (current storage settings)'), 'current');
|
|
271
|
+
appendOption(format, label('SB3(設定対象の台本・素材を同梱)', 'SB3 (embed configured scripts and assets)'), 'embedded');
|
|
272
|
+
const picker = (document.defaultView as (Window & {showDirectoryPicker?: unknown}) | null)?.showDirectoryPicker;
|
|
273
|
+
const folderAvailable = folder && typeof picker === 'function';
|
|
274
|
+
if (folderAvailable) appendOption(format, label('プロジェクトフォルダ', 'Project folder'), 'folder');
|
|
275
|
+
appendField(fields, label('保存形式', 'Save format'), format);
|
|
276
|
+
|
|
277
|
+
const status = document.createElement('p');
|
|
278
|
+
status.setAttribute('role', 'alert');
|
|
279
|
+
const report = (message: string) => {status.textContent = message;};
|
|
280
|
+
const git = document.createElement('input');
|
|
281
|
+
git.type = 'checkbox';
|
|
282
|
+
git.name = 'git';
|
|
283
|
+
const gitChoice = document.createElement('div');
|
|
284
|
+
appendField(gitChoice, label('Git でバージョン管理する', 'Use Git version control'), git);
|
|
285
|
+
const github = folderAvailable && folder.github ? createGitHubFields(document, label, folder.github, report) : null;
|
|
286
|
+
if (github) fields.append(gitChoice, github.panel);
|
|
287
|
+
const overwriteWarning = document.createElement('p');
|
|
288
|
+
if (folder?.overwriteWarning) {
|
|
289
|
+
overwriteWarning.textContent = folder.overwriteWarning;
|
|
290
|
+
fields.append(overwriteWarning);
|
|
291
|
+
}
|
|
292
|
+
const publication = github ? folder.github.publication : undefined;
|
|
293
|
+
const pending = document.createElement('ul');
|
|
294
|
+
pending.setAttribute('aria-label', label('未完了のリポジトリ作成', 'Pending repository setup'));
|
|
295
|
+
const device = document.createElement('div');
|
|
296
|
+
const controller = new AbortController();
|
|
297
|
+
const interaction: CreationInteraction = {
|
|
298
|
+
signal: controller.signal,
|
|
299
|
+
deviceCode({userCode, verificationUri}) {
|
|
300
|
+
if (!open()) return;
|
|
301
|
+
const link = document.createElement('a');
|
|
302
|
+
link.href = verificationUri;
|
|
303
|
+
link.target = '_blank';
|
|
304
|
+
link.rel = 'noopener noreferrer';
|
|
305
|
+
link.textContent = label('GitHub で認証する', 'Authorize on GitHub');
|
|
306
|
+
const code = document.createElement('strong');
|
|
307
|
+
code.textContent = userCode;
|
|
308
|
+
device.replaceChildren(link, ' ', code);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
const review = document.createElement('div');
|
|
313
|
+
const cancel = document.createElement('button');
|
|
314
|
+
cancel.type = 'button';
|
|
315
|
+
cancel.textContent = label('キャンセル', 'Cancel');
|
|
316
|
+
let dismissed = false;
|
|
317
|
+
const dismiss = () => {dismissed = true; controller.abort(); close();};
|
|
318
|
+
cancel.onclick = dismiss;
|
|
319
|
+
const back = document.createElement('button');
|
|
320
|
+
back.type = 'button';
|
|
321
|
+
back.textContent = label('戻る', 'Back');
|
|
322
|
+
const submit = document.createElement('button');
|
|
323
|
+
submit.type = 'submit';
|
|
324
|
+
const recoverAccess = document.createElement('button');
|
|
325
|
+
recoverAccess.type = 'button';
|
|
326
|
+
recoverAccess.textContent = label('ローカルフォルダへのアクセスを許可…', 'Grant Local Folder Access…');
|
|
327
|
+
const actions = dialogActions(document, back, recoverAccess, dialogAction(cancel, 'cancel'),
|
|
328
|
+
dialogAction(submit, 'confirm'));
|
|
329
|
+
form.append(fields, pending, review, device, status, actions);
|
|
330
|
+
const commit = document.createElement('button');
|
|
331
|
+
if (openCommit) {
|
|
332
|
+
commit.type = 'button';
|
|
333
|
+
commit.textContent = label('保存してコミット…', 'Save and Commit…');
|
|
334
|
+
commit.onclick = openCommit;
|
|
335
|
+
actions.prepend(commit);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
type FolderReview = {name: string; format: 'folder'; git: GitHubRepositoryDraft};
|
|
339
|
+
let confirmedDraft: FolderReview | null = null;
|
|
340
|
+
let task: RepositoryCreationProgress | null = null;
|
|
341
|
+
let candidate: RepositoryReceipt | null = null;
|
|
342
|
+
let needsAccess = false;
|
|
343
|
+
let busy = false;
|
|
344
|
+
const open = () => !dismissed && form.isConnected;
|
|
345
|
+
const savingFolder = () => folderAvailable && format.value === 'folder';
|
|
346
|
+
const selectedGitHub = () => savingFolder() && git.checked ? github : null;
|
|
347
|
+
const phaseText = (phase: RepositoryCreationProgress['phase']) => ({
|
|
348
|
+
create: label('GitHub リポジトリ作成待ち', 'Waiting to create the repository'),
|
|
349
|
+
unknown: label('GitHub での作成結果を確認してください。', 'Check whether GitHub created the repository.'),
|
|
350
|
+
prepare: label('GitHub リポジトリを作成しました。ローカルの初回コミットを準備します。',
|
|
351
|
+
'GitHub repository created. The local initial commit is still being prepared.'),
|
|
352
|
+
topics: label('ローカルの初回コミットを保存しました。GitHub のトピック設定を再試行できます。',
|
|
353
|
+
'The local initial commit was saved. You can retry setting GitHub topics.'),
|
|
354
|
+
push: label('ローカルの初回コミットを保存しました。GitHub への初回 push を承認してください。',
|
|
355
|
+
'The local initial commit was saved. Authorize the initial push to GitHub.'),
|
|
356
|
+
open: label('初回 push が完了しました。', 'The initial push is complete.')
|
|
357
|
+
})[phase];
|
|
358
|
+
const actionText = (phase: RepositoryCreationProgress['phase']) => ({
|
|
359
|
+
create: label('リポジトリ作成を再開', 'Resume Repository Creation'),
|
|
360
|
+
unknown: candidate ? label('確認したリポジトリで再開', 'Continue with This Repository') :
|
|
361
|
+
label('作成結果を確認', 'Check Creation Result'),
|
|
362
|
+
prepare: label('ローカルの準備を再開', 'Resume Local Setup'),
|
|
363
|
+
topics: label('トピック設定を再試行', 'Retry Setting Topics'),
|
|
364
|
+
push: label('初回 push を承認…', 'Authorize and Push…'),
|
|
365
|
+
open: label('ローカルの作品を開く', 'Open the Local Project')
|
|
366
|
+
})[phase];
|
|
367
|
+
const refreshTask = () => {
|
|
368
|
+
if (!task) return;
|
|
369
|
+
const heading = document.createElement('h3');
|
|
370
|
+
const link = document.createElement('a');
|
|
371
|
+
link.href = `https://github.com/${task.owner}/${task.name}`;
|
|
372
|
+
link.target = '_blank';
|
|
373
|
+
link.rel = 'noopener noreferrer';
|
|
374
|
+
link.textContent = task.owner + '/' + task.name;
|
|
375
|
+
heading.append(link);
|
|
376
|
+
const state = document.createElement('p');
|
|
377
|
+
state.textContent = phaseText(task.phase);
|
|
378
|
+
review.replaceChildren(heading, state);
|
|
379
|
+
if (candidate) {
|
|
380
|
+
const detail = document.createElement('p');
|
|
381
|
+
detail.textContent = label(`空のリポジトリ ID ${candidate.id} を確認しました。表示されたリポジトリで初回設定を続けます。`,
|
|
382
|
+
`An empty repository with ID ${candidate.id} was found. Continue setup with the displayed repository.`);
|
|
383
|
+
review.append(detail);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
const refresh = () => {
|
|
387
|
+
const reviewing = confirmedDraft !== null || task !== null;
|
|
388
|
+
const creation = selectedGitHub();
|
|
389
|
+
const localFolder = savingFolder() && !creation;
|
|
390
|
+
overwriteWarning.hidden = !localFolder;
|
|
391
|
+
fields.hidden = reviewing;
|
|
392
|
+
review.hidden = !reviewing;
|
|
393
|
+
back.hidden = !confirmedDraft || task !== null;
|
|
394
|
+
back.disabled = busy;
|
|
395
|
+
nameField.hidden = localFolder;
|
|
396
|
+
name.disabled = busy || reviewing || localFolder;
|
|
397
|
+
format.disabled = busy || reviewing;
|
|
398
|
+
git.disabled = busy || reviewing;
|
|
399
|
+
gitChoice.hidden = !savingFolder();
|
|
400
|
+
if (github) {
|
|
401
|
+
github.panel.hidden = !selectedGitHub();
|
|
402
|
+
github.panel.disabled = busy || reviewing || github.panel.hidden;
|
|
403
|
+
}
|
|
404
|
+
submit.disabled = busy;
|
|
405
|
+
recoverAccess.hidden = !task || !needsAccess;
|
|
406
|
+
recoverAccess.disabled = busy;
|
|
407
|
+
commit.disabled = busy || reviewing;
|
|
408
|
+
pending.hidden = reviewing || !pending.childElementCount;
|
|
409
|
+
submit.textContent = task ? actionText(task.phase) : reviewing ? label('リポジトリを作成', 'Create Repository') : creation ?
|
|
410
|
+
(creation.connected ? label('作成内容を確認', 'Review Repository') : label('GitHub へ接続…', 'Connect to GitHub…')) :
|
|
411
|
+
(savingFolder() || storage.pick ? label('保存先を選ぶ…', 'Choose Where to Save…') : label('保存', 'Save'));
|
|
412
|
+
};
|
|
413
|
+
const loadPending = async () => {
|
|
414
|
+
if (!publication) return [];
|
|
415
|
+
const entries = await publication.list();
|
|
416
|
+
if (!open()) return entries;
|
|
417
|
+
const rows = entries.map(entry => {
|
|
418
|
+
const row = document.createElement('li');
|
|
419
|
+
const button = document.createElement('button');
|
|
420
|
+
button.type = 'button';
|
|
421
|
+
button.textContent = label(`${entry.owner}/${entry.name} の作成を再開`, `Resume setup for ${entry.owner}/${entry.name}`);
|
|
422
|
+
button.onclick = () => {
|
|
423
|
+
if (busy) return;
|
|
424
|
+
task = entry;
|
|
425
|
+
candidate = null;
|
|
426
|
+
needsAccess = false;
|
|
427
|
+
confirmedDraft = null;
|
|
428
|
+
report('');
|
|
429
|
+
refreshTask();
|
|
430
|
+
refresh();
|
|
431
|
+
submit.focus();
|
|
432
|
+
};
|
|
433
|
+
row.append(button);
|
|
434
|
+
return row;
|
|
435
|
+
});
|
|
436
|
+
pending.replaceChildren(...rows);
|
|
437
|
+
refresh();
|
|
438
|
+
return entries;
|
|
439
|
+
};
|
|
440
|
+
const advance = async () => {
|
|
441
|
+
if (task.phase === 'open') {
|
|
442
|
+
if (await publication.open(task) && open()) dismiss();
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const updated = await publication.advance(task, interaction, candidate?.id);
|
|
446
|
+
if (!open()) return;
|
|
447
|
+
task = updated.progress;
|
|
448
|
+
candidate = updated.candidate ?? null;
|
|
449
|
+
refreshTask();
|
|
450
|
+
if (updated.candidate === null) report(label('再開できる空のリポジトリを確認できませんでした。',
|
|
451
|
+
'No empty repository was verified for resuming this setup.'));
|
|
452
|
+
};
|
|
453
|
+
const showError = (error: unknown) => {
|
|
454
|
+
const code = (error as {code?: string})?.code;
|
|
455
|
+
switch (code) {
|
|
456
|
+
case 'invalidDraft': return (error as Error).message;
|
|
457
|
+
case 'directoryNotEmpty': return label('空のフォルダを選んでください。', 'Choose an empty directory.');
|
|
458
|
+
case 'directoryPermission': return label('同じローカルフォルダへのアクセスを許可してから再開してください。',
|
|
459
|
+
'Grant access to the same local folder before resuming.');
|
|
460
|
+
case 'differentDirectory': return label('最初に選んだローカルフォルダを選び直してください。',
|
|
461
|
+
'Choose the same local folder you selected initially.');
|
|
462
|
+
case 'popupBlocked': return label('GitHub 認証のポップアップを許可して再試行してください。',
|
|
463
|
+
'Allow the GitHub authorization popup and try again.');
|
|
464
|
+
case 'unknown': return label('GitHub の作成結果を確認できませんでした。作成結果を照会してください。',
|
|
465
|
+
'GitHub did not confirm the creation result. Check the recorded result.');
|
|
466
|
+
case 'nameConflict': return label('同名のリポジトリがすでにあります。', 'A repository with this name already exists.');
|
|
467
|
+
case 'pendingRepository': return label('同じリポジトリの設定を再開してください。', 'Resume the existing setup for this repository.');
|
|
468
|
+
case 'insufficientPermission': case 'forbidden': case 'denied': case 'session':
|
|
469
|
+
return label('GitHub のアカウントと権限を確認して再試行してください。', 'Check the GitHub account and permissions, then retry.');
|
|
470
|
+
case 'rateLimited': return label('GitHub の利用上限に達しました。しばらくしてから再試行してください。',
|
|
471
|
+
'GitHub rate limited this request. Try again later.');
|
|
472
|
+
case 'diverged': return label('GitHub に異なる履歴があるため、初回 push を停止しました。',
|
|
473
|
+
'The initial push stopped because the GitHub repository has different history.');
|
|
474
|
+
case 'pushUnknown': return label('初回 push の結果を確認できません。再試行して GitHub の状態を確認してください。',
|
|
475
|
+
'The initial push result could not be confirmed. Retry to check the GitHub repository.');
|
|
476
|
+
default: return label('リポジトリの設定を完了できませんでした。', 'Could not complete repository setup.');
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
recoverAccess.onclick = () => {
|
|
480
|
+
if (!task || busy) return;
|
|
481
|
+
busy = true;
|
|
482
|
+
refresh();
|
|
483
|
+
void publication.grantAccess(task).then(granted => {
|
|
484
|
+
if (!granted || !open()) return;
|
|
485
|
+
needsAccess = false;
|
|
486
|
+
report('');
|
|
487
|
+
}, error => {if (open()) report(showError(error));}).finally(() => {
|
|
488
|
+
busy = false;
|
|
489
|
+
if (open()) refresh();
|
|
490
|
+
});
|
|
491
|
+
};
|
|
492
|
+
format.onchange = git.onchange = () => {report(''); refresh();};
|
|
493
|
+
back.onclick = () => {
|
|
494
|
+
confirmedDraft = null;
|
|
495
|
+
report('');
|
|
496
|
+
refresh();
|
|
497
|
+
submit.focus();
|
|
498
|
+
};
|
|
499
|
+
refresh();
|
|
500
|
+
if (publication) queueMicrotask(() => {if (open()) void loadPending().catch(error => report(showError(error)));});
|
|
501
|
+
if (github && document.defaultView?.MutationObserver) {
|
|
502
|
+
const observer = new document.defaultView.MutationObserver(() => {
|
|
503
|
+
if (!open()) {observer.disconnect(); controller.abort();}
|
|
504
|
+
});
|
|
505
|
+
observer.observe(document.body, {childList: true, subtree: true});
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
form.onsubmit = async event => {
|
|
509
|
+
event.preventDefault();
|
|
510
|
+
const value = name.value.trim();
|
|
511
|
+
const title = savingFolder() ? value : value.replace(/\.sb3$/i, '');
|
|
512
|
+
if (!open() || busy || (!task && !confirmedDraft && !title && !name.disabled)) return;
|
|
513
|
+
report('');
|
|
514
|
+
busy = true;
|
|
515
|
+
refresh();
|
|
516
|
+
let focus: HTMLElement | null = null;
|
|
517
|
+
try {
|
|
518
|
+
if (task) {await advance(); return;}
|
|
519
|
+
const creation = selectedGitHub();
|
|
520
|
+
if (creation && !confirmedDraft) {
|
|
521
|
+
creation.applyUrl();
|
|
522
|
+
if (!creation.connected) {
|
|
523
|
+
report(label('GitHub に接続しています…', 'Connecting to GitHub…'));
|
|
524
|
+
if (await creation.connect(open, interaction)) focus = submit;
|
|
525
|
+
if (open()) report('');
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
confirmedDraft = {name: title, format: 'folder', git: creation.draft(title)};
|
|
529
|
+
focus = creation.review(confirmedDraft.git, review);
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const request: SaveAsRequest = confirmedDraft ?? (savingFolder() ? {name: title, format: 'folder'} :
|
|
533
|
+
{name: title, format: format.value === 'embedded' ? 'embedded' : 'current'});
|
|
534
|
+
const result = await save(request, open, controller.signal);
|
|
535
|
+
if (!open()) return;
|
|
536
|
+
if (result === true) dismiss();
|
|
537
|
+
else if (result && publication) {
|
|
538
|
+
task = result;
|
|
539
|
+
confirmedDraft = null;
|
|
540
|
+
refreshTask();
|
|
541
|
+
refresh();
|
|
542
|
+
await advance();
|
|
543
|
+
}
|
|
544
|
+
} catch (error) {
|
|
545
|
+
if (open() && publication && (task || confirmedDraft || selectedGitHub())) {
|
|
546
|
+
const entries = await loadPending().catch(() => []);
|
|
547
|
+
if (!open()) return;
|
|
548
|
+
if (task) {
|
|
549
|
+
task = entries.find(entry => entry.operationId === task.operationId) ?? null;
|
|
550
|
+
candidate = null;
|
|
551
|
+
if ((error as {code?: string})?.code === 'directoryPermission') needsAccess = true;
|
|
552
|
+
refreshTask();
|
|
553
|
+
}
|
|
554
|
+
report(showError(error));
|
|
555
|
+
} else if (open()) report(error instanceof Error ? error.message : String(error));
|
|
556
|
+
} finally {
|
|
557
|
+
device.replaceChildren();
|
|
558
|
+
busy = false;
|
|
559
|
+
if (open()) {refresh(); focus?.focus();}
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
return form;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export function renderExportView(document: Document, locale: string, close: Action, run: Action) {
|
|
566
|
+
const ja = locale.startsWith('ja');
|
|
567
|
+
const view = document.createElement('div');
|
|
568
|
+
const explanation = document.createElement('p');
|
|
569
|
+
explanation.textContent = ja ?
|
|
570
|
+
'実行・配布用のファイルを作成します。書き出しに必要な作品データは出力に同梱されます。' :
|
|
571
|
+
'Create a file for running or sharing the project. Project data needed for export is included in the output.';
|
|
572
|
+
const button = document.createElement('button');
|
|
573
|
+
button.type = 'button';
|
|
574
|
+
button.textContent = ja ? 'プロジェクトをパッケージ化する' : 'Package Project';
|
|
575
|
+
button.onclick = () => {close(); run();};
|
|
576
|
+
view.append(explanation, dialogActions(document, dialogAction(button, 'confirm')));
|
|
577
|
+
return view;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
export type ExtensionStorage = 'remote-non-cacheable' | 'remote-cacheable' | 'embedded-file' | 'embedded-data';
|
|
581
|
+
|
|
582
|
+
export function renderExtensionsForm(document: Document, locale: string, close: Action, add: Action | undefined, {
|
|
583
|
+
list, change
|
|
584
|
+
}: {
|
|
585
|
+
list(): Promise<{id: string; format?: ExtensionStorage; editable?: boolean}[]>;
|
|
586
|
+
change(changes: Map<string, ExtensionStorage>): Promise<void>;
|
|
587
|
+
}) {
|
|
588
|
+
const ja = locale.startsWith('ja');
|
|
589
|
+
const form = document.createElement('form');
|
|
590
|
+
const entries = document.createElement('ul');
|
|
591
|
+
const status = document.createElement('p');
|
|
592
|
+
status.setAttribute('role', 'status');
|
|
593
|
+
status.textContent = ja ? '確認中…' : 'Inspecting…';
|
|
594
|
+
const done = document.createElement('button');
|
|
595
|
+
done.type = 'button';
|
|
596
|
+
done.textContent = ja ? '閉じる' : 'Close';
|
|
597
|
+
done.onclick = close;
|
|
598
|
+
const apply = document.createElement('button');
|
|
599
|
+
apply.textContent = ja ? '格納方式を適用' : 'Apply Storage Settings';
|
|
600
|
+
apply.disabled = true;
|
|
601
|
+
const actions = dialogActions(document, dialogAction(done, 'close'), dialogAction(apply, 'confirm'));
|
|
602
|
+
form.append(entries, status, actions);
|
|
603
|
+
if (add) {
|
|
604
|
+
const button = document.createElement('button');
|
|
605
|
+
button.type = 'button';
|
|
606
|
+
button.textContent = ja ? '機能拡張の追加' : 'Add Extension';
|
|
607
|
+
button.onclick = () => {close(); add();};
|
|
608
|
+
actions.prepend(button);
|
|
609
|
+
}
|
|
610
|
+
const labels = {
|
|
611
|
+
'remote-non-cacheable': ja ? 'HTTPSから毎回取得' : 'Fetch from HTTPS each time',
|
|
612
|
+
'remote-cacheable': ja ? 'HTTPSから取得・キャッシュ可' : 'Fetch from HTTPS, caching allowed',
|
|
613
|
+
'embedded-file': ja ? 'SB3内のファイル' : 'File in the SB3',
|
|
614
|
+
'embedded-data': ja ? '作品JSON内のデータ' : 'Data in the project JSON'
|
|
615
|
+
};
|
|
616
|
+
const choices = new Map<string, {original: ExtensionStorage; input: HTMLSelectElement}>();
|
|
617
|
+
const changed = () => new Map([...choices].filter(([, choice]) => choice.input.value !== choice.original)
|
|
618
|
+
.map(([id, choice]) => [id, choice.input.value as ExtensionStorage]));
|
|
619
|
+
void list().then(items => {
|
|
620
|
+
status.textContent = items.length ? '' : (ja ? '使用中の機能拡張はありません。' : 'No extensions in use.');
|
|
621
|
+
for (const item of items) {
|
|
622
|
+
const li = document.createElement('li');
|
|
623
|
+
if (!item.editable) {
|
|
624
|
+
li.textContent = item.format ? `${item.id} — ${labels[item.format]}` : item.id;
|
|
625
|
+
} else {
|
|
626
|
+
const label = document.createElement('label');
|
|
627
|
+
const input = document.createElement('select');
|
|
628
|
+
for (const [value, title] of Object.entries(labels)) input.add(new Option(title, value));
|
|
629
|
+
input.value = item.format;
|
|
630
|
+
input.onchange = () => {apply.disabled = !changed().size;};
|
|
631
|
+
choices.set(item.id, {original: item.format, input});
|
|
632
|
+
label.append(item.id, input);
|
|
633
|
+
li.append(label);
|
|
634
|
+
}
|
|
635
|
+
entries.append(li);
|
|
636
|
+
}
|
|
637
|
+
}, error => {status.textContent = error.message;});
|
|
638
|
+
form.onsubmit = async event => {
|
|
639
|
+
event.preventDefault();
|
|
640
|
+
if (apply.disabled) return;
|
|
641
|
+
apply.disabled = true;
|
|
642
|
+
status.textContent = ja ? '適用中…' : 'Applying…';
|
|
643
|
+
for (const {input} of choices.values()) input.disabled = true;
|
|
644
|
+
try {
|
|
645
|
+
await change(changed());
|
|
646
|
+
if (form.isConnected) close();
|
|
647
|
+
} catch (error) {
|
|
648
|
+
status.textContent = error.message;
|
|
649
|
+
for (const {input} of choices.values()) input.disabled = false;
|
|
650
|
+
apply.disabled = false;
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
return form;
|
|
654
|
+
}
|