@kubohiroya/turbowarp-plus-editor-workbench 0.27.0 → 0.28.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/EDITOR-MIGRATION.md +5 -0
- package/README.ja.md +9 -0
- package/dist/basic-panel.d.ts +52 -0
- package/dist/basic-panel.js +153 -0
- package/dist/editor-tabs.d.ts +37 -0
- package/dist/editor-tabs.js +550 -0
- package/dist/popup-layout.d.ts +20 -0
- package/dist/popup-layout.js +59 -0
- package/dist/project-folder-workflows.d.ts +31 -0
- package/dist/project-folder-workflows.js +1 -0
- package/dist/project-payload-forms.d.ts +8 -0
- package/dist/project-payload-forms.js +184 -0
- package/dist/project-tools/diagnostics.d.ts +13 -0
- package/dist/project-tools/diagnostics.js +65 -0
- package/dist/project-tools/dialog.d.ts +21 -0
- package/dist/project-tools/dialog.js +363 -0
- package/dist/project-tools/history.d.ts +8 -0
- package/dist/project-tools/history.js +22 -0
- package/dist/project-tools/integration.d.ts +65 -0
- package/dist/project-tools/integration.js +356 -0
- package/dist/project-tools/links.d.ts +3 -0
- package/dist/project-tools/links.js +36 -0
- package/dist/project-tools/properties.d.ts +51 -0
- package/dist/project-tools/properties.js +268 -0
- package/dist/sprite-tabs.d.ts +1 -0
- package/dist/sprite-tabs.js +1 -0
- package/dist/stage-display-menu.d.ts +21 -0
- package/dist/stage-display-menu.js +156 -0
- package/dist/stage-panel.d.ts +29 -0
- package/dist/stage-panel.js +105 -0
- package/package.json +78 -9
- package/src/basic-panel.tsx +207 -0
- package/src/editor-tabs.tsx +591 -0
- package/src/popup-layout.css +4 -0
- package/src/popup-layout.tsx +81 -0
- package/src/project-dialog.css +39 -0
- package/src/project-folder-workflows.ts +32 -0
- package/src/project-payload-forms.ts +179 -0
- package/src/project-snackbar.css +85 -0
- package/src/project-tools/diagnostics.ts +51 -0
- package/src/project-tools/dialog.ts +341 -0
- package/src/project-tools/history.ts +20 -0
- package/src/project-tools/integration.ts +366 -0
- package/src/project-tools/links.ts +31 -0
- package/src/project-tools/properties.ts +251 -0
- package/src/sprite-tabs.ts +2 -1
- package/src/stage-display-menu.css +28 -0
- package/src/stage-display-menu.tsx +177 -0
- package/src/stage-panel.tsx +127 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
import {dialogAction, dialogActions} from '@kubohiroya/turbowarp-plus-editor-windows';
|
|
3
|
+
import {contactLink, descriptionParts} from './links.js';
|
|
4
|
+
import {diagnosticText} from './diagnostics.js';
|
|
5
|
+
import {renderBundleAssetForm, renderPayloadForm} from '../project-payload-forms.js';
|
|
6
|
+
import {isValidSaveName} from '../project-file-dialogs.js';
|
|
7
|
+
|
|
8
|
+
/** Presentation is supplied by the host's CSS Modules build. */
|
|
9
|
+
export function createProjectDialogService({styles, snackbarStyles}: {
|
|
10
|
+
styles: Record<string, string>; snackbarStyles: Record<string, string>;
|
|
11
|
+
}) {
|
|
12
|
+
const element = <Tag extends keyof HTMLElementTagNameMap>(document: Document, tag: Tag, text?: string, attributes: Record<string, string> = {}) => {
|
|
13
|
+
const node = document.createElement(tag);
|
|
14
|
+
if (text !== undefined) node.textContent = text;
|
|
15
|
+
for (const [key, value] of Object.entries(attributes)) node.setAttribute(key, value);
|
|
16
|
+
return node;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Native modal dialogs keep focus and Escape handling in the browser, outside the stage. */
|
|
20
|
+
const createProjectDialogs = (document, properties, history, diagnostics, {
|
|
21
|
+
locale: hostLocale, getLocale
|
|
22
|
+
}: {locale?: string; getLocale?: () => string | undefined} = {}) => {
|
|
23
|
+
let active = null;
|
|
24
|
+
let returnFocus = null;
|
|
25
|
+
let identity = 0;
|
|
26
|
+
let disposeView = null;
|
|
27
|
+
let notice = null;
|
|
28
|
+
let noticeReturnFocus = null;
|
|
29
|
+
let notifiedError = '';
|
|
30
|
+
const close = () => {
|
|
31
|
+
if (!active) return;
|
|
32
|
+
disposeView?.(); disposeView = null;
|
|
33
|
+
active.remove(); active = null;
|
|
34
|
+
if (returnFocus?.isConnected) returnFocus.focus();
|
|
35
|
+
};
|
|
36
|
+
const open = (title, locale) => {
|
|
37
|
+
close();
|
|
38
|
+
returnFocus = document.activeElement;
|
|
39
|
+
const dialog = element(document, 'dialog', undefined, {class: styles.dialog,
|
|
40
|
+
'data-project-tools': '', 'aria-labelledby': `project-tools-title-${++identity}`});
|
|
41
|
+
dialog.appendChild(element(document, 'h2', title, {id: `project-tools-title-${identity}`}));
|
|
42
|
+
dialog.addEventListener('cancel', event => { event.preventDefault(); close(); });
|
|
43
|
+
dialog.addEventListener('close', close);
|
|
44
|
+
document.body.appendChild(dialog);
|
|
45
|
+
active = dialog;
|
|
46
|
+
return {dialog, label: (ja, en) => locale.startsWith('ja') ? ja : en};
|
|
47
|
+
};
|
|
48
|
+
const unsubscribe = properties.subscribe(() => {
|
|
49
|
+
// A form must never apply an old project's draft to the newly opened project.
|
|
50
|
+
if (properties.loadState().phase === 'loading') close();
|
|
51
|
+
});
|
|
52
|
+
const stopNotice = diagnostics?.subscribe(() => {
|
|
53
|
+
const sessions = diagnostics.snapshot();
|
|
54
|
+
const error = sessions[0]?.events.filter(event => ['error', 'project-error'].includes(event.type)).at(-1);
|
|
55
|
+
const key = error ? `${sessions[0].id}:${error.time}:${error.code}:${error.type}` : '';
|
|
56
|
+
if (!key || key === notifiedError) return;
|
|
57
|
+
notifiedError = key;
|
|
58
|
+
if (!notice?.contains(document.activeElement)) noticeReturnFocus = document.activeElement;
|
|
59
|
+
notice?.remove();
|
|
60
|
+
const locale = getLocale?.() || hostLocale || document.documentElement.lang || 'en';
|
|
61
|
+
const ja = locale.startsWith('ja');
|
|
62
|
+
notice = element(document, 'aside', undefined, {class: snackbarStyles.snackbar, 'data-project-tools': '',
|
|
63
|
+
'data-testid': 'project-diagnostics-snackbar'});
|
|
64
|
+
const message = error.type === 'project-error' ?
|
|
65
|
+
(ja ? '作品を開けませんでした。' : 'Could not open the project.') :
|
|
66
|
+
(ja ? '拡張機能を読み込めませんでした。' : 'Could not load the extension.');
|
|
67
|
+
notice.appendChild(element(document, 'span', message, {role: 'status', 'aria-atomic': 'true'}));
|
|
68
|
+
const show = element(document, 'button', ja ? '詳細ログを表示' : 'View detailed log', {type: 'button'});
|
|
69
|
+
show.addEventListener('click', () => {
|
|
70
|
+
api.showDiagnostics(locale, sessions[0].id);
|
|
71
|
+
returnFocus = noticeReturnFocus;
|
|
72
|
+
notice.remove();
|
|
73
|
+
});
|
|
74
|
+
const dismiss = element(document, 'button', ja ? '閉じる' : 'Dismiss', {type: 'button'});
|
|
75
|
+
dismiss.addEventListener('click', () => {
|
|
76
|
+
const restore = notice.contains(document.activeElement);
|
|
77
|
+
notice.remove();
|
|
78
|
+
if (restore && noticeReturnFocus?.isConnected) noticeReturnFocus.focus();
|
|
79
|
+
});
|
|
80
|
+
notice.append(show, dismiss); document.body.appendChild(notice);
|
|
81
|
+
});
|
|
82
|
+
const api = {
|
|
83
|
+
showView(title: string, locale: string, render: (document: Document, close: () => void) =>
|
|
84
|
+
HTMLElement | {element: HTMLElement; dispose(): void}) {
|
|
85
|
+
const {dialog} = open(title, locale);
|
|
86
|
+
const view = render(document, () => {if (active === dialog) close();});
|
|
87
|
+
if ('element' in view) {
|
|
88
|
+
dialog.append(view.element);
|
|
89
|
+
disposeView = view.dispose;
|
|
90
|
+
} else dialog.append(view);
|
|
91
|
+
dialog.showModal();
|
|
92
|
+
},
|
|
93
|
+
showProperties(locale = 'en', editURI) {
|
|
94
|
+
const {dialog, label} = open(locale.startsWith('ja') ? '作品のプロパティ' : 'Project Properties', locale);
|
|
95
|
+
dialog.setAttribute('data-testid', 'project-properties');
|
|
96
|
+
const value = properties.snapshot();
|
|
97
|
+
const inputs: Record<string, HTMLInputElement | HTMLTextAreaElement> = {};
|
|
98
|
+
const form = element(document, 'form');
|
|
99
|
+
const field = (key: string, title: string, list?: string[]) => {
|
|
100
|
+
const id = `project-properties-${key}-${identity}`;
|
|
101
|
+
const row = element(document, 'label', title, {for: id});
|
|
102
|
+
const input = element(document, key === 'description' ? 'textarea' : 'input', undefined,
|
|
103
|
+
{id, name: key});
|
|
104
|
+
input.value = value[key] ?? '';
|
|
105
|
+
input.disabled = value.readOnly || value.loading;
|
|
106
|
+
if (key === 'title') input.maxLength = 100;
|
|
107
|
+
if (key === 'description') (input as HTMLTextAreaElement).rows = 5;
|
|
108
|
+
if (list) {
|
|
109
|
+
input.setAttribute('list', `${id}-history`);
|
|
110
|
+
const datalist = element(document, 'datalist', undefined, {id: `${id}-history`});
|
|
111
|
+
for (const text of list) datalist.appendChild(element(document, 'option', undefined, {value: text}));
|
|
112
|
+
form.appendChild(datalist);
|
|
113
|
+
}
|
|
114
|
+
row.appendChild(input); form.appendChild(row); inputs[key] = input;
|
|
115
|
+
return input;
|
|
116
|
+
};
|
|
117
|
+
if (history) field('title', label('作品タイトル', 'Project title'));
|
|
118
|
+
let saveNameInput: HTMLInputElement | undefined;
|
|
119
|
+
const saveNameError = element(document, 'p', '', {'aria-live': 'polite'});
|
|
120
|
+
const checkSaveName = () => {
|
|
121
|
+
const name = saveNameInput.value.trim();
|
|
122
|
+
const valid = !name || isValidSaveName(name);
|
|
123
|
+
if (valid) saveNameInput.removeAttribute('aria-invalid');
|
|
124
|
+
else saveNameInput.setAttribute('aria-invalid', 'true');
|
|
125
|
+
saveNameError.textContent = valid ? '' : label('この名前は使えません。使える文字を確かめてください。',
|
|
126
|
+
'This name cannot be used. Check the allowed characters.');
|
|
127
|
+
return valid;
|
|
128
|
+
};
|
|
129
|
+
if (history) {
|
|
130
|
+
// The name of the project's folder or GitHub repository, where the title cannot be used (#679).
|
|
131
|
+
saveNameInput = field('saveName', label('保存用の名前', 'Save name')) as HTMLInputElement;
|
|
132
|
+
saveNameInput.maxLength = 100;
|
|
133
|
+
saveNameInput.spellcheck = false;
|
|
134
|
+
saveNameInput.setAttribute('autocomplete', 'off');
|
|
135
|
+
const help = element(document, 'p', label(
|
|
136
|
+
'フォルダや GitHub のリポジトリの名前に使います。使える文字は英数字と「-」「_」「.」で、100 文字までです(「.」「..」と、末尾の「.git」は使えません)。空のままにすると、作品名が使えるときは作品名を使います。',
|
|
137
|
+
'Used as the name of the project\'s folder or GitHub repository. Use letters, digits, "-", "_" and ".", up to 100 characters (not "." or "..", and not ending in ".git"). When it is empty, the project title is used if it can be.'),
|
|
138
|
+
{id: `${saveNameInput.id}-help`});
|
|
139
|
+
saveNameInput.setAttribute('aria-describedby', `${help.id} ${saveNameInput.id}-error`);
|
|
140
|
+
saveNameError.id = `${saveNameInput.id}-error`;
|
|
141
|
+
saveNameInput.addEventListener('input', checkSaveName);
|
|
142
|
+
form.append(help, saveNameError);
|
|
143
|
+
}
|
|
144
|
+
let uriInput;
|
|
145
|
+
if (editURI) {
|
|
146
|
+
const id = `project-uri-${identity}`;
|
|
147
|
+
const row = element(document, 'label', label('作品の URI', 'Project URI'), {for: id});
|
|
148
|
+
uriInput = element(document, 'input', undefined, {
|
|
149
|
+
id, name: 'uri', inputmode: 'url', 'aria-describedby': `${id}-help`
|
|
150
|
+
});
|
|
151
|
+
uriInput.value = editURI.uri;
|
|
152
|
+
uriInput.disabled = value.loading;
|
|
153
|
+
row.appendChild(uriInput);
|
|
154
|
+
const help = element(document, 'p', label(
|
|
155
|
+
'適用した URI は、次に作品を保存したときに SB3 に記録されます。',
|
|
156
|
+
'The URI will be recorded in the SB3 the next time you save the project.'), {id: `${id}-help`});
|
|
157
|
+
form.append(row, help);
|
|
158
|
+
}
|
|
159
|
+
if (history) {
|
|
160
|
+
const recent = history.snapshot();
|
|
161
|
+
const description = field('description', label('作品概要', 'Description'));
|
|
162
|
+
const preview = element(document, 'div', undefined, {class: styles.preview,
|
|
163
|
+
'aria-label': label('作品概要のプレビュー', 'Description preview')});
|
|
164
|
+
const renderPreview = () => {
|
|
165
|
+
preview.replaceChildren();
|
|
166
|
+
for (const part of descriptionParts(description.value)) {
|
|
167
|
+
preview.appendChild(part.href ? element(document, 'a', part.text,
|
|
168
|
+
{href: part.href, target: '_blank', rel: 'noopener noreferrer'}) : document.createTextNode(part.text));
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
description.addEventListener('input', renderPreview); renderPreview(); form.appendChild(preview);
|
|
172
|
+
field('author', label('作者名', 'Author name'), recent.names);
|
|
173
|
+
const contact = field('contact', label('連絡先', 'Contact'), recent.contacts);
|
|
174
|
+
const contactView = element(document, 'div', undefined, {class: styles.preview});
|
|
175
|
+
const renderContact = () => {
|
|
176
|
+
const href = contactLink(contact.value);
|
|
177
|
+
contactView.replaceChildren();
|
|
178
|
+
if (!href) return;
|
|
179
|
+
contactView.appendChild(element(document, 'a', contact.value, {href,
|
|
180
|
+
...(href.startsWith('https:') ? {target: '_blank', rel: 'noopener noreferrer'} : {})}));
|
|
181
|
+
};
|
|
182
|
+
contact.addEventListener('input', renderContact); renderContact(); form.appendChild(contactView);
|
|
183
|
+
const dates = element(document, 'dl');
|
|
184
|
+
for (const [key, title] of [['createdAt', label('作成日時', 'Created')],
|
|
185
|
+
['updatedAt', label('最終更新日時', 'Last updated')]]) {
|
|
186
|
+
dates.appendChild(element(document, 'dt', title));
|
|
187
|
+
const row = element(document, 'dd');
|
|
188
|
+
row.appendChild(value[key] ? element(document, 'time', new Date(value[key]).toLocaleString(locale),
|
|
189
|
+
{datetime: value[key]}) : document.createTextNode(label('未記録', 'Not recorded')));
|
|
190
|
+
dates.appendChild(row);
|
|
191
|
+
}
|
|
192
|
+
form.appendChild(dates);
|
|
193
|
+
form.appendChild(element(document, 'p', label(
|
|
194
|
+
'作者名・連絡先の候補はこのブラウザに各5件保持します。作品ファイルには今回の入力値を保存します。',
|
|
195
|
+
'This browser remembers five recent names and contacts. Only the current values are saved in the project.')));
|
|
196
|
+
if (value.readOnly) form.appendChild(element(document, 'p', label(
|
|
197
|
+
'この作品情報の形式は未対応です。元の情報を保持し、編集はできません。',
|
|
198
|
+
'This metadata version is unsupported. The original data is preserved and cannot be edited.')));
|
|
199
|
+
}
|
|
200
|
+
const canApplyMetadata = Boolean(history) && !value.readOnly;
|
|
201
|
+
const error = element(document, 'p', '', {role: 'alert'});
|
|
202
|
+
form.appendChild(error);
|
|
203
|
+
const cancel = element(document, 'button', label('キャンセル', 'Cancel'), {type: 'button'});
|
|
204
|
+
cancel.addEventListener('click', close);
|
|
205
|
+
const apply = element(document, 'button', label('適用', 'Apply'), {type: 'submit'});
|
|
206
|
+
apply.disabled = value.loading || (!canApplyMetadata && !uriInput);
|
|
207
|
+
const diagnosticsButton = element(document, 'button', label('作品の診断…', 'Project Diagnostics…'), {type: 'button'});
|
|
208
|
+
diagnosticsButton.addEventListener('click', () => api.showDiagnostics(locale));
|
|
209
|
+
form.append(dialogActions(document, diagnosticsButton, dialogAction(cancel, 'cancel'),
|
|
210
|
+
dialogAction(apply, 'confirm')));
|
|
211
|
+
form.addEventListener('submit', async event => {
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
if (apply.disabled) return;
|
|
214
|
+
if (saveNameInput && !checkSaveName()) {
|
|
215
|
+
saveNameInput.focus();
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
apply.disabled = true;
|
|
219
|
+
error.textContent = '';
|
|
220
|
+
const draft = Object.fromEntries(Object.entries(inputs).map(([key, input]) => [key, input.value]));
|
|
221
|
+
try {
|
|
222
|
+
// Validate and apply the URI first so a rejected URI cannot commit the metadata draft.
|
|
223
|
+
if (uriInput && uriInput.value.trim() !== editURI.uri) await editURI.apply(uriInput.value);
|
|
224
|
+
if (active !== dialog) return;
|
|
225
|
+
if (canApplyMetadata) {
|
|
226
|
+
properties.apply(draft);
|
|
227
|
+
history.remember(draft.author, draft.contact);
|
|
228
|
+
}
|
|
229
|
+
close();
|
|
230
|
+
} catch (failure) {
|
|
231
|
+
error.textContent = failure.code === 'INVALID_SAVE_NAME' ?
|
|
232
|
+
label('保存用の名前に使えない文字があります。', 'The save name has characters that cannot be used.') :
|
|
233
|
+
failure.code === 'INVALID_PROJECT_URI' ?
|
|
234
|
+
label('認証情報やフラグメントを含まない HTTPS URI を入力してください。',
|
|
235
|
+
'Enter an HTTPS URI without credentials or a fragment.') :
|
|
236
|
+
label('作品情報を適用できませんでした。読み込み完了後に開き直してください。',
|
|
237
|
+
'Could not apply properties. Reopen this dialog after loading has finished.');
|
|
238
|
+
apply.disabled = false;
|
|
239
|
+
if (failure.code === 'INVALID_PROJECT_URI' && active === dialog) uriInput.focus();
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
dialog.appendChild(form);
|
|
243
|
+
dialog.showModal(); (inputs.title || uriInput)?.focus();
|
|
244
|
+
},
|
|
245
|
+
showPayloadFormats(edit, locale = 'en', addAssets?: () => void) {
|
|
246
|
+
const {dialog} = open(locale.startsWith('ja') ? '作品データの形式' : 'Project Data Formats', locale);
|
|
247
|
+
const {form, dispose} = renderPayloadForm(document, edit, locale, close);
|
|
248
|
+
disposeView = dispose;
|
|
249
|
+
if (addAssets) {
|
|
250
|
+
const button = element(document, 'button', locale.startsWith('ja') ?
|
|
251
|
+
'バンドル素材を作品に追加…' : 'Add Bundle Material to Project…', {type: 'button'});
|
|
252
|
+
button.onclick = addAssets;
|
|
253
|
+
form.prepend(button);
|
|
254
|
+
}
|
|
255
|
+
dialog.append(form);
|
|
256
|
+
dialog.showModal();
|
|
257
|
+
},
|
|
258
|
+
showBundleAssetConversion(conversion, locale = 'en') {
|
|
259
|
+
const {dialog} = open(locale.startsWith('ja') ? 'バンドル素材を作品に追加' : 'Add Bundle Material to Project', locale);
|
|
260
|
+
const {form, dispose} = renderBundleAssetForm(document, conversion, locale, close);
|
|
261
|
+
disposeView = dispose;
|
|
262
|
+
dialog.append(form);
|
|
263
|
+
dialog.showModal();
|
|
264
|
+
},
|
|
265
|
+
showDiagnostics(locale = 'en', initialSession?: number) {
|
|
266
|
+
const {dialog, label} = open(locale.startsWith('ja') ? '作品の診断' : 'Project Diagnostics', locale);
|
|
267
|
+
dialog.setAttribute('data-testid', 'project-diagnostics');
|
|
268
|
+
const selectorLabel = element(document, 'label', label('読み込みの記録', 'Load attempt'));
|
|
269
|
+
const selector = element(document, 'select', undefined, {'aria-label': label('読み込みの記録', 'Load attempt')});
|
|
270
|
+
selectorLabel.appendChild(selector); dialog.appendChild(selectorLabel);
|
|
271
|
+
const content = element(document, 'div'); dialog.appendChild(content);
|
|
272
|
+
const status = element(document, 'p', '', {role: 'status'}); dialog.appendChild(status);
|
|
273
|
+
const copy = element(document, 'button', label('診断をコピー', 'Copy diagnostics'), {type: 'button'});
|
|
274
|
+
const done = element(document, 'button', label('閉じる', 'Close'), {type: 'button'});
|
|
275
|
+
done.addEventListener('click', close);
|
|
276
|
+
dialog.append(dialogActions(document, copy, dialogAction(done, 'close')));
|
|
277
|
+
let selected = initialSession;
|
|
278
|
+
let exported = '';
|
|
279
|
+
const states = {
|
|
280
|
+
loading: label('読み込み中', 'Loading'), loaded: label('読み込み完了', 'Loaded'),
|
|
281
|
+
failed: label('読み込み失敗・キャンセル', 'Failed or cancelled'),
|
|
282
|
+
verified: label('内容を検証済み', 'Content verified'), authorized: label('実行を許可済み', 'Execution approved'),
|
|
283
|
+
review: label('実行許可を確認中', 'Reviewing execution permission'),
|
|
284
|
+
retry: label('接続を再試行中', 'Retrying connection'), error: label('読み込みを拒否', 'Loading rejected'),
|
|
285
|
+
'project-error': label('作品を開けませんでした', 'Could not open project')
|
|
286
|
+
};
|
|
287
|
+
const render = () => {
|
|
288
|
+
const sessions = diagnostics?.snapshot() || [];
|
|
289
|
+
const session = sessions.find(value => value.id === selected) || sessions[0];
|
|
290
|
+
selected = session?.id;
|
|
291
|
+
selector.replaceChildren(...sessions.map(value => element(document, 'option',
|
|
292
|
+
`${new Date(value.startedAt).toLocaleString(locale)} · ${value.title || label('タイトル未設定', 'Untitled')} · ${states[value.phase] || value.phase}`,
|
|
293
|
+
{value: value.id})));
|
|
294
|
+
if (session) selector.value = String(session.id);
|
|
295
|
+
selector.disabled = sessions.length < 2; copy.disabled = !session;
|
|
296
|
+
exported = diagnosticText(session); content.replaceChildren();
|
|
297
|
+
if (!session || !session.events.length) {
|
|
298
|
+
content.appendChild(element(document, 'p', label('診断イベントはまだありません。', 'No diagnostic events have been recorded.')));
|
|
299
|
+
}
|
|
300
|
+
if (!session) return;
|
|
301
|
+
for (const extension of session.extensions) {
|
|
302
|
+
const details = element(document, 'details');
|
|
303
|
+
details.appendChild(element(document, 'summary', extension.id));
|
|
304
|
+
details.appendChild(element(document, 'pre', [extension.source, extension.execution,
|
|
305
|
+
`SHA-256: ${extension.sha256}`].filter(Boolean).join('\n')));
|
|
306
|
+
content.appendChild(details);
|
|
307
|
+
}
|
|
308
|
+
const list = element(document, 'ol');
|
|
309
|
+
for (const event of session.events) {
|
|
310
|
+
const details = element(document, 'details');
|
|
311
|
+
details.appendChild(element(document, 'summary',
|
|
312
|
+
[states[event.type] || event.type, event.id, event.ids?.join(', '), event.code].filter(Boolean).join(' · ')));
|
|
313
|
+
details.appendChild(element(document, 'pre', JSON.stringify(event, null, 2)));
|
|
314
|
+
const item = element(document, 'li'); item.appendChild(details); list.appendChild(item);
|
|
315
|
+
}
|
|
316
|
+
content.appendChild(list);
|
|
317
|
+
};
|
|
318
|
+
selector.addEventListener('change', () => { selected = Number(selector.value); render(); });
|
|
319
|
+
copy.addEventListener('click', async () => {
|
|
320
|
+
try {
|
|
321
|
+
await document.defaultView.navigator.clipboard.writeText(exported);
|
|
322
|
+
status.textContent = label('コピーしました。', 'Copied.');
|
|
323
|
+
} catch (error) {
|
|
324
|
+
// Clipboard permissions differ by browser; offer selectable text without opening a new window.
|
|
325
|
+
const text = element(document, 'textarea', undefined, {readonly: '',
|
|
326
|
+
'aria-label': label('コピーする診断内容', 'Diagnostics to copy')});
|
|
327
|
+
text.value = exported; content.replaceChildren(text); text.focus(); text.select();
|
|
328
|
+
status.textContent = label('選択した内容をコピーしてください。', 'Copy the selected text.');
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
disposeView = diagnostics?.subscribe(render);
|
|
332
|
+
render(); dialog.showModal(); done.focus();
|
|
333
|
+
},
|
|
334
|
+
ownsKeyEvent: event => Boolean(event.target?.closest?.('[data-project-tools]')),
|
|
335
|
+
dispose () { unsubscribe(); stopNotice?.(); notice?.remove(); close(); }
|
|
336
|
+
};
|
|
337
|
+
return api;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
return {createProjectDialogs};
|
|
341
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
const KEY = 'tw-plus-project-author-history-v1';
|
|
3
|
+
const clean = values => Array.isArray(values) ? [...new Set(values.filter(value =>
|
|
4
|
+
typeof value === 'string' && value.trim()).map(value => value.trim()))].slice(0, 5) : [];
|
|
5
|
+
|
|
6
|
+
/** A browser-local history; storage denial must not prevent applying project properties. */
|
|
7
|
+
export const createAuthorHistory = storage => {
|
|
8
|
+
let value = {names: [], contacts: []};
|
|
9
|
+
try {
|
|
10
|
+
const saved = JSON.parse(storage?.getItem(KEY) || '{}');
|
|
11
|
+
value = {names: clean(saved.names), contacts: clean(saved.contacts)};
|
|
12
|
+
} catch (error) { /* Storage can be unavailable or contain obsolete data. */ }
|
|
13
|
+
return {
|
|
14
|
+
snapshot: () => ({names: [...value.names], contacts: [...value.contacts]}),
|
|
15
|
+
remember (name, contact) {
|
|
16
|
+
value = {names: clean([name, ...value.names]), contacts: clean([contact, ...value.contacts])};
|
|
17
|
+
try { storage?.setItem(KEY, JSON.stringify(value)); } catch (error) { /* Keep an in-memory history. */ }
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|