@kubohiroya/turbowarp-plus-editor-workbench 0.26.0 → 0.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EDITOR-MIGRATION.md +5 -0
- package/README.ja.md +7 -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 +538 -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 +7 -1
- package/dist/sprite-tabs.js +11 -1
- 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 +580 -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 +17 -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,8 @@
|
|
|
1
|
+
export declare function renderPayloadForm(document: any, edit: any, locale: any, close: any): {
|
|
2
|
+
form: any;
|
|
3
|
+
dispose: () => void;
|
|
4
|
+
};
|
|
5
|
+
export declare function renderBundleAssetForm(document: any, conversion: any, locale: any, close: any): {
|
|
6
|
+
form: any;
|
|
7
|
+
dispose: () => void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
import { dialogAction, dialogActions } from '@kubohiroya/turbowarp-plus-editor-windows';
|
|
3
|
+
import { sb3SaveFormats } from '@kubohiroya/turbowarp-sb3-save-format';
|
|
4
|
+
const formatLabels = {
|
|
5
|
+
'': ['標準の格納方式を使う', 'Use default storage'],
|
|
6
|
+
'remote-non-cacheable': ['HTTPS から毎回取得', 'Fetch from HTTPS each time'],
|
|
7
|
+
'remote-cacheable': ['HTTPS から取得・キャッシュ可', 'Fetch from HTTPS, caching allowed'],
|
|
8
|
+
'embedded-file': ['SB3 内のファイル', 'File in the SB3'],
|
|
9
|
+
'embedded-data': ['作品 JSON 内のデータ', 'Data in the project JSON']
|
|
10
|
+
};
|
|
11
|
+
export function renderPayloadForm(document, edit, locale, close) {
|
|
12
|
+
const ja = locale.startsWith('ja');
|
|
13
|
+
const label = (jp, en) => ja ? jp : en;
|
|
14
|
+
const make = (tag, text) => {
|
|
15
|
+
const node = document.createElement(tag);
|
|
16
|
+
if (text)
|
|
17
|
+
node.textContent = text;
|
|
18
|
+
return node;
|
|
19
|
+
};
|
|
20
|
+
const controller = new AbortController();
|
|
21
|
+
const form = make('form');
|
|
22
|
+
const inputs = new Map();
|
|
23
|
+
const intro = make('p', label('設定した形式は次の SB3 保存に使われます。リモート形式の URL は現在の内容と一致する必要があります。', 'These formats are used the next time you save an SB3. Remote URLs must serve the current bytes.'));
|
|
24
|
+
form.append(intro);
|
|
25
|
+
for (const [kind, heading] of [
|
|
26
|
+
['source', label('ソースデータ', 'Source Data')], ['assets', label('アセット', 'Assets')]
|
|
27
|
+
]) {
|
|
28
|
+
const group = make('fieldset');
|
|
29
|
+
group.append(make('legend', heading));
|
|
30
|
+
const items = edit.items.filter(item => item.kind === kind);
|
|
31
|
+
if (!items.length)
|
|
32
|
+
group.append(make('p', label('設定できる項目がありません。', 'No items are available.')));
|
|
33
|
+
for (const item of items) {
|
|
34
|
+
const row = make('label', item.label);
|
|
35
|
+
const format = make('select');
|
|
36
|
+
format.setAttribute('aria-label', `${heading} – ${item.label}`);
|
|
37
|
+
for (const id of ['', ...sb3SaveFormats]) {
|
|
38
|
+
const option = make('option', label(formatLabels[id][0], formatLabels[id][1]));
|
|
39
|
+
option.value = id;
|
|
40
|
+
format.append(option);
|
|
41
|
+
}
|
|
42
|
+
format.value = item.format || '';
|
|
43
|
+
row.append(format);
|
|
44
|
+
const urlRow = make('label', `${item.label} HTTPS URL`);
|
|
45
|
+
const url = make('input');
|
|
46
|
+
url.inputMode = 'url';
|
|
47
|
+
url.value = item.url || '';
|
|
48
|
+
urlRow.append(url);
|
|
49
|
+
const update = () => {
|
|
50
|
+
const needed = format.value.startsWith('remote-');
|
|
51
|
+
urlRow.hidden = !needed;
|
|
52
|
+
url.required = needed;
|
|
53
|
+
url.disabled = !needed;
|
|
54
|
+
};
|
|
55
|
+
format.addEventListener('change', update);
|
|
56
|
+
update();
|
|
57
|
+
group.append(row, urlRow);
|
|
58
|
+
inputs.set(item.id, { format, url });
|
|
59
|
+
}
|
|
60
|
+
form.append(group);
|
|
61
|
+
}
|
|
62
|
+
const error = make('p');
|
|
63
|
+
error.setAttribute('role', 'alert');
|
|
64
|
+
const cancel = make('button', label('キャンセル', 'Cancel'));
|
|
65
|
+
cancel.type = 'button';
|
|
66
|
+
cancel.addEventListener('click', close);
|
|
67
|
+
const apply = make('button', label('適用', 'Apply'));
|
|
68
|
+
apply.type = 'submit';
|
|
69
|
+
apply.disabled = !inputs.size;
|
|
70
|
+
form.append(error, dialogActions(document, dialogAction(cancel, 'cancel'), dialogAction(apply, 'confirm')));
|
|
71
|
+
form.addEventListener('submit', async (event) => {
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
if (apply.disabled)
|
|
74
|
+
return;
|
|
75
|
+
apply.disabled = true;
|
|
76
|
+
error.textContent = '';
|
|
77
|
+
const choices = new Map([...inputs].filter(([, { format }]) => format.value)
|
|
78
|
+
.map(([id, { format, url }]) => [id, { format: format.value, url: url.value.trim() }]));
|
|
79
|
+
try {
|
|
80
|
+
await edit.apply(choices, controller.signal);
|
|
81
|
+
if (!controller.signal.aborted)
|
|
82
|
+
close();
|
|
83
|
+
}
|
|
84
|
+
catch (failure) {
|
|
85
|
+
if (controller.signal.aborted)
|
|
86
|
+
return;
|
|
87
|
+
error.textContent = failure.message;
|
|
88
|
+
apply.disabled = false;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return { form, dispose: () => controller.abort() };
|
|
92
|
+
}
|
|
93
|
+
export function renderBundleAssetForm(document, conversion, locale, close) {
|
|
94
|
+
const ja = locale.startsWith('ja');
|
|
95
|
+
const label = (jp, en) => ja ? jp : en;
|
|
96
|
+
const make = (tag, text) => {
|
|
97
|
+
const node = document.createElement(tag);
|
|
98
|
+
if (text)
|
|
99
|
+
node.textContent = text;
|
|
100
|
+
return node;
|
|
101
|
+
};
|
|
102
|
+
const controller = new AbortController();
|
|
103
|
+
const form = make('form');
|
|
104
|
+
const select = title => {
|
|
105
|
+
const row = make('label', title);
|
|
106
|
+
const input = make('select');
|
|
107
|
+
row.append(input);
|
|
108
|
+
form.append(row);
|
|
109
|
+
return input;
|
|
110
|
+
};
|
|
111
|
+
const fill = (input, choices) => {
|
|
112
|
+
input.replaceChildren(...choices.map(([value, text]) => {
|
|
113
|
+
const option = make('option', text);
|
|
114
|
+
option.value = value;
|
|
115
|
+
return option;
|
|
116
|
+
}));
|
|
117
|
+
};
|
|
118
|
+
const intro = make('p', label('選んだ素材を作品に追加します。紙芝居から使う元の素材はバンドル内に保持します。', 'Add the selected material to the project. The original stays in the bundle for Kamishibai.'));
|
|
119
|
+
form.append(intro);
|
|
120
|
+
const material = select(label('バンドル素材', 'Bundle material'));
|
|
121
|
+
const kind = select(label('追加する種類', 'Add as'));
|
|
122
|
+
const target = select(label('追加先', 'Target'));
|
|
123
|
+
const kinds = {
|
|
124
|
+
costume: label('コスチューム', 'Costume'),
|
|
125
|
+
backdrop: label('背景', 'Backdrop'),
|
|
126
|
+
sound: label('音', 'Sound')
|
|
127
|
+
};
|
|
128
|
+
const targetsFor = type => type ? conversion.targets.filter(item => type === 'sound' ||
|
|
129
|
+
(type === 'backdrop' ? item.stage : !item.stage)) : [];
|
|
130
|
+
const status = make('p');
|
|
131
|
+
status.setAttribute('role', 'status');
|
|
132
|
+
const error = make('p');
|
|
133
|
+
error.setAttribute('role', 'alert');
|
|
134
|
+
const cancel = make('button', label('閉じる', 'Close'));
|
|
135
|
+
cancel.type = 'button';
|
|
136
|
+
cancel.addEventListener('click', close);
|
|
137
|
+
const add = make('button', label('作品に追加', 'Add to project'));
|
|
138
|
+
add.type = 'submit';
|
|
139
|
+
form.append(status, error, dialogActions(document, dialogAction(cancel, 'close'), dialogAction(add, 'confirm')));
|
|
140
|
+
const showTargets = () => {
|
|
141
|
+
fill(target, targetsFor(kind.value).map(item => [item.id, item.stage ? label('ステージ', 'Stage') : item.name]));
|
|
142
|
+
add.disabled = !target.value;
|
|
143
|
+
};
|
|
144
|
+
const showKinds = () => {
|
|
145
|
+
const selected = conversion.materials.find(item => item.key === material.value);
|
|
146
|
+
fill(kind, (selected?.kinds || []).filter(type => targetsFor(type).length).map(type => [type, kinds[type]]));
|
|
147
|
+
showTargets();
|
|
148
|
+
};
|
|
149
|
+
fill(material, conversion.materials.map(item => [item.key, item.label]));
|
|
150
|
+
if (!conversion.materials.length) {
|
|
151
|
+
status.textContent = label('追加できる画像や音がありません。', 'There are no supported images or sounds.');
|
|
152
|
+
}
|
|
153
|
+
material.addEventListener('change', showKinds);
|
|
154
|
+
kind.addEventListener('change', showTargets);
|
|
155
|
+
showKinds();
|
|
156
|
+
form.addEventListener('submit', async (event) => {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
if (add.disabled)
|
|
159
|
+
return;
|
|
160
|
+
const choice = { key: material.value, kind: kind.value, targetId: target.value };
|
|
161
|
+
for (const control of [material, kind, target, add])
|
|
162
|
+
control.disabled = true;
|
|
163
|
+
status.textContent = '';
|
|
164
|
+
error.textContent = '';
|
|
165
|
+
try {
|
|
166
|
+
const name = await conversion.add(choice, controller.signal);
|
|
167
|
+
if (controller.signal.aborted)
|
|
168
|
+
return;
|
|
169
|
+
status.textContent = label(`「${name}」を追加しました。作品を SB3 に保存できます。`, `Added “${name}”. You can save the project as an SB3.`);
|
|
170
|
+
}
|
|
171
|
+
catch (failure) {
|
|
172
|
+
if (controller.signal.aborted)
|
|
173
|
+
return;
|
|
174
|
+
error.textContent = label(`素材を追加できませんでした。${failure.message}`, `Could not add the material. ${failure.message}`);
|
|
175
|
+
}
|
|
176
|
+
finally {
|
|
177
|
+
if (!controller.signal.aborted) {
|
|
178
|
+
for (const control of [material, kind, target, add])
|
|
179
|
+
control.disabled = false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
return { form, dispose: () => controller.abort() };
|
|
184
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Bounded, in-memory load attempts. A failed attempt remains available after the editor returns to a new project. */
|
|
2
|
+
export declare const createProjectDiagnostics: ({ now }?: {
|
|
3
|
+
now?: () => string;
|
|
4
|
+
}) => {
|
|
5
|
+
begin: (title?: string) => void;
|
|
6
|
+
record(event: any): void;
|
|
7
|
+
describe(manifest: any): void;
|
|
8
|
+
finish(state: any, title?: string): void;
|
|
9
|
+
snapshot: () => any;
|
|
10
|
+
subscribe(listener: () => void): () => boolean;
|
|
11
|
+
dispose(): void;
|
|
12
|
+
};
|
|
13
|
+
export declare const diagnosticText: (session: any) => string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
const text = (value) => value === undefined || value === null ? undefined : String(value).slice(0, 16384);
|
|
3
|
+
/** Bounded, in-memory load attempts. A failed attempt remains available after the editor returns to a new project. */
|
|
4
|
+
export const createProjectDiagnostics = ({ now = () => new Date().toISOString() } = {}) => {
|
|
5
|
+
const sessions = [];
|
|
6
|
+
const listeners = new Set();
|
|
7
|
+
let serial = 0;
|
|
8
|
+
const notify = () => {
|
|
9
|
+
for (const listener of listeners) {
|
|
10
|
+
try {
|
|
11
|
+
listener();
|
|
12
|
+
}
|
|
13
|
+
catch (error) { /* Diagnostics must not affect execution. */ }
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const begin = (title = '') => {
|
|
17
|
+
sessions.unshift({ id: ++serial, title: text(title), startedAt: now(), phase: 'loading', events: [], extensions: [] });
|
|
18
|
+
sessions.splice(5);
|
|
19
|
+
notify();
|
|
20
|
+
};
|
|
21
|
+
const current = () => { if (!sessions.length)
|
|
22
|
+
begin(); return sessions[0]; };
|
|
23
|
+
const api = {
|
|
24
|
+
begin,
|
|
25
|
+
record(event) {
|
|
26
|
+
const session = current();
|
|
27
|
+
const safe = { time: now() };
|
|
28
|
+
for (const field of ['type', 'id', 'sha256', 'code', 'message', 'execution', 'attempt', 'attempts']) {
|
|
29
|
+
const value = text(event[field]);
|
|
30
|
+
if (value !== undefined)
|
|
31
|
+
safe[field] = value;
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(event.ids))
|
|
34
|
+
safe.ids = event.ids.map(text).slice(0, 200);
|
|
35
|
+
if (event.source)
|
|
36
|
+
safe.source = text(event.source.url || event.source.path);
|
|
37
|
+
if (typeof event.cached === 'boolean')
|
|
38
|
+
safe.cached = event.cached;
|
|
39
|
+
session.events.push(safe);
|
|
40
|
+
session.events.splice(0, Math.max(0, session.events.length - 50));
|
|
41
|
+
notify();
|
|
42
|
+
},
|
|
43
|
+
describe(manifest) {
|
|
44
|
+
current().extensions = (manifest?.extensions || []).slice(0, 200).map(spec => ({
|
|
45
|
+
id: text(spec.id), source: text(spec.source?.url || spec.source?.path), execution: text(spec.execution),
|
|
46
|
+
sha256: text(spec.sha256)
|
|
47
|
+
}));
|
|
48
|
+
notify();
|
|
49
|
+
},
|
|
50
|
+
finish(state, title = '') {
|
|
51
|
+
const session = current();
|
|
52
|
+
session.phase = state.phase;
|
|
53
|
+
session.title = text(title);
|
|
54
|
+
if (state.phase === 'failed' && !session.events.some(event => event.type === 'project-error')) {
|
|
55
|
+
api.record({ type: 'project-error', code: state.code || 'LOAD_FAILED', message: state.message });
|
|
56
|
+
}
|
|
57
|
+
notify();
|
|
58
|
+
},
|
|
59
|
+
snapshot: () => JSON.parse(JSON.stringify(sessions)),
|
|
60
|
+
subscribe(listener) { listeners.add(listener); return () => listeners.delete(listener); },
|
|
61
|
+
dispose() { listeners.clear(); sessions.length = 0; }
|
|
62
|
+
};
|
|
63
|
+
return api;
|
|
64
|
+
};
|
|
65
|
+
export const diagnosticText = session => session ? JSON.stringify(session, null, 2) : '';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Presentation is supplied by the host's CSS Modules build. */
|
|
2
|
+
export declare function createProjectDialogService({ styles, snackbarStyles }: {
|
|
3
|
+
styles: Record<string, string>;
|
|
4
|
+
snackbarStyles: Record<string, string>;
|
|
5
|
+
}): {
|
|
6
|
+
createProjectDialogs: (document: any, properties: any, history: any, diagnostics: any, { locale: hostLocale, getLocale }?: {
|
|
7
|
+
locale?: string;
|
|
8
|
+
getLocale?: () => string | undefined;
|
|
9
|
+
}) => {
|
|
10
|
+
showView(title: string, locale: string, render: (document: Document, close: () => void) => HTMLElement | {
|
|
11
|
+
element: HTMLElement;
|
|
12
|
+
dispose(): void;
|
|
13
|
+
}): void;
|
|
14
|
+
showProperties(locale: string, editURI: any): void;
|
|
15
|
+
showPayloadFormats(edit: any, locale?: string, addAssets?: () => void): void;
|
|
16
|
+
showBundleAssetConversion(conversion: any, locale?: string): void;
|
|
17
|
+
showDiagnostics(locale?: string, initialSession?: number): void;
|
|
18
|
+
ownsKeyEvent: (event: any) => boolean;
|
|
19
|
+
dispose(): void;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1,363 @@
|
|
|
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
|
+
/** Presentation is supplied by the host's CSS Modules build. */
|
|
8
|
+
export function createProjectDialogService({ styles, snackbarStyles }) {
|
|
9
|
+
const element = (document, tag, text, attributes = {}) => {
|
|
10
|
+
const node = document.createElement(tag);
|
|
11
|
+
if (text !== undefined)
|
|
12
|
+
node.textContent = text;
|
|
13
|
+
for (const [key, value] of Object.entries(attributes))
|
|
14
|
+
node.setAttribute(key, value);
|
|
15
|
+
return node;
|
|
16
|
+
};
|
|
17
|
+
/** Native modal dialogs keep focus and Escape handling in the browser, outside the stage. */
|
|
18
|
+
const createProjectDialogs = (document, properties, history, diagnostics, { locale: hostLocale, getLocale } = {}) => {
|
|
19
|
+
let active = null;
|
|
20
|
+
let returnFocus = null;
|
|
21
|
+
let identity = 0;
|
|
22
|
+
let disposeView = null;
|
|
23
|
+
let notice = null;
|
|
24
|
+
let noticeReturnFocus = null;
|
|
25
|
+
let notifiedError = '';
|
|
26
|
+
const close = () => {
|
|
27
|
+
if (!active)
|
|
28
|
+
return;
|
|
29
|
+
disposeView?.();
|
|
30
|
+
disposeView = null;
|
|
31
|
+
active.remove();
|
|
32
|
+
active = null;
|
|
33
|
+
if (returnFocus?.isConnected)
|
|
34
|
+
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')
|
|
51
|
+
close();
|
|
52
|
+
});
|
|
53
|
+
const stopNotice = diagnostics?.subscribe(() => {
|
|
54
|
+
const sessions = diagnostics.snapshot();
|
|
55
|
+
const error = sessions[0]?.events.filter(event => ['error', 'project-error'].includes(event.type)).at(-1);
|
|
56
|
+
const key = error ? `${sessions[0].id}:${error.time}:${error.code}:${error.type}` : '';
|
|
57
|
+
if (!key || key === notifiedError)
|
|
58
|
+
return;
|
|
59
|
+
notifiedError = key;
|
|
60
|
+
if (!notice?.contains(document.activeElement))
|
|
61
|
+
noticeReturnFocus = document.activeElement;
|
|
62
|
+
notice?.remove();
|
|
63
|
+
const locale = getLocale?.() || hostLocale || document.documentElement.lang || 'en';
|
|
64
|
+
const ja = locale.startsWith('ja');
|
|
65
|
+
notice = element(document, 'aside', undefined, { class: snackbarStyles.snackbar, 'data-project-tools': '',
|
|
66
|
+
'data-testid': 'project-diagnostics-snackbar' });
|
|
67
|
+
const message = error.type === 'project-error' ?
|
|
68
|
+
(ja ? '作品を開けませんでした。' : 'Could not open the project.') :
|
|
69
|
+
(ja ? '拡張機能を読み込めませんでした。' : 'Could not load the extension.');
|
|
70
|
+
notice.appendChild(element(document, 'span', message, { role: 'status', 'aria-atomic': 'true' }));
|
|
71
|
+
const show = element(document, 'button', ja ? '詳細ログを表示' : 'View detailed log', { type: 'button' });
|
|
72
|
+
show.addEventListener('click', () => {
|
|
73
|
+
api.showDiagnostics(locale, sessions[0].id);
|
|
74
|
+
returnFocus = noticeReturnFocus;
|
|
75
|
+
notice.remove();
|
|
76
|
+
});
|
|
77
|
+
const dismiss = element(document, 'button', ja ? '閉じる' : 'Dismiss', { type: 'button' });
|
|
78
|
+
dismiss.addEventListener('click', () => {
|
|
79
|
+
const restore = notice.contains(document.activeElement);
|
|
80
|
+
notice.remove();
|
|
81
|
+
if (restore && noticeReturnFocus?.isConnected)
|
|
82
|
+
noticeReturnFocus.focus();
|
|
83
|
+
});
|
|
84
|
+
notice.append(show, dismiss);
|
|
85
|
+
document.body.appendChild(notice);
|
|
86
|
+
});
|
|
87
|
+
const api = {
|
|
88
|
+
showView(title, locale, render) {
|
|
89
|
+
const { dialog } = open(title, locale);
|
|
90
|
+
const view = render(document, () => { if (active === dialog)
|
|
91
|
+
close(); });
|
|
92
|
+
if ('element' in view) {
|
|
93
|
+
dialog.append(view.element);
|
|
94
|
+
disposeView = view.dispose;
|
|
95
|
+
}
|
|
96
|
+
else
|
|
97
|
+
dialog.append(view);
|
|
98
|
+
dialog.showModal();
|
|
99
|
+
},
|
|
100
|
+
showProperties(locale = 'en', editURI) {
|
|
101
|
+
const { dialog, label } = open(locale.startsWith('ja') ? '作品のプロパティ' : 'Project Properties', locale);
|
|
102
|
+
dialog.setAttribute('data-testid', 'project-properties');
|
|
103
|
+
const value = properties.snapshot();
|
|
104
|
+
const inputs = {};
|
|
105
|
+
const form = element(document, 'form');
|
|
106
|
+
const field = (key, title, list) => {
|
|
107
|
+
const id = `project-properties-${key}-${identity}`;
|
|
108
|
+
const row = element(document, 'label', title, { for: id });
|
|
109
|
+
const input = element(document, key === 'description' ? 'textarea' : 'input', undefined, { id, name: key });
|
|
110
|
+
input.value = value[key] ?? '';
|
|
111
|
+
input.disabled = value.readOnly || value.loading;
|
|
112
|
+
if (key === 'title')
|
|
113
|
+
input.maxLength = 100;
|
|
114
|
+
if (key === 'description')
|
|
115
|
+
input.rows = 5;
|
|
116
|
+
if (list) {
|
|
117
|
+
input.setAttribute('list', `${id}-history`);
|
|
118
|
+
const datalist = element(document, 'datalist', undefined, { id: `${id}-history` });
|
|
119
|
+
for (const text of list)
|
|
120
|
+
datalist.appendChild(element(document, 'option', undefined, { value: text }));
|
|
121
|
+
form.appendChild(datalist);
|
|
122
|
+
}
|
|
123
|
+
row.appendChild(input);
|
|
124
|
+
form.appendChild(row);
|
|
125
|
+
inputs[key] = input;
|
|
126
|
+
return input;
|
|
127
|
+
};
|
|
128
|
+
if (history)
|
|
129
|
+
field('title', label('作品タイトル', 'Project title'));
|
|
130
|
+
let saveNameInput;
|
|
131
|
+
const saveNameError = element(document, 'p', '', { 'aria-live': 'polite' });
|
|
132
|
+
const checkSaveName = () => {
|
|
133
|
+
const name = saveNameInput.value.trim();
|
|
134
|
+
const valid = !name || isValidSaveName(name);
|
|
135
|
+
if (valid)
|
|
136
|
+
saveNameInput.removeAttribute('aria-invalid');
|
|
137
|
+
else
|
|
138
|
+
saveNameInput.setAttribute('aria-invalid', 'true');
|
|
139
|
+
saveNameError.textContent = valid ? '' : label('この名前は使えません。使える文字を確かめてください。', 'This name cannot be used. Check the allowed characters.');
|
|
140
|
+
return valid;
|
|
141
|
+
};
|
|
142
|
+
if (history) {
|
|
143
|
+
// The name of the project's folder or GitHub repository, where the title cannot be used (#679).
|
|
144
|
+
saveNameInput = field('saveName', label('保存用の名前', 'Save name'));
|
|
145
|
+
saveNameInput.maxLength = 100;
|
|
146
|
+
saveNameInput.spellcheck = false;
|
|
147
|
+
saveNameInput.setAttribute('autocomplete', 'off');
|
|
148
|
+
const help = element(document, 'p', label('フォルダや GitHub のリポジトリの名前に使います。使える文字は英数字と「-」「_」「.」で、100 文字までです(「.」「..」と、末尾の「.git」は使えません)。空のままにすると、作品名が使えるときは作品名を使います。', '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.'), { id: `${saveNameInput.id}-help` });
|
|
149
|
+
saveNameInput.setAttribute('aria-describedby', `${help.id} ${saveNameInput.id}-error`);
|
|
150
|
+
saveNameError.id = `${saveNameInput.id}-error`;
|
|
151
|
+
saveNameInput.addEventListener('input', checkSaveName);
|
|
152
|
+
form.append(help, saveNameError);
|
|
153
|
+
}
|
|
154
|
+
let uriInput;
|
|
155
|
+
if (editURI) {
|
|
156
|
+
const id = `project-uri-${identity}`;
|
|
157
|
+
const row = element(document, 'label', label('作品の URI', 'Project URI'), { for: id });
|
|
158
|
+
uriInput = element(document, 'input', undefined, {
|
|
159
|
+
id, name: 'uri', inputmode: 'url', 'aria-describedby': `${id}-help`
|
|
160
|
+
});
|
|
161
|
+
uriInput.value = editURI.uri;
|
|
162
|
+
uriInput.disabled = value.loading;
|
|
163
|
+
row.appendChild(uriInput);
|
|
164
|
+
const help = element(document, 'p', label('適用した URI は、次に作品を保存したときに SB3 に記録されます。', 'The URI will be recorded in the SB3 the next time you save the project.'), { id: `${id}-help` });
|
|
165
|
+
form.append(row, help);
|
|
166
|
+
}
|
|
167
|
+
if (history) {
|
|
168
|
+
const recent = history.snapshot();
|
|
169
|
+
const description = field('description', label('作品概要', 'Description'));
|
|
170
|
+
const preview = element(document, 'div', undefined, { class: styles.preview,
|
|
171
|
+
'aria-label': label('作品概要のプレビュー', 'Description preview') });
|
|
172
|
+
const renderPreview = () => {
|
|
173
|
+
preview.replaceChildren();
|
|
174
|
+
for (const part of descriptionParts(description.value)) {
|
|
175
|
+
preview.appendChild(part.href ? element(document, 'a', part.text, { href: part.href, target: '_blank', rel: 'noopener noreferrer' }) : document.createTextNode(part.text));
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
description.addEventListener('input', renderPreview);
|
|
179
|
+
renderPreview();
|
|
180
|
+
form.appendChild(preview);
|
|
181
|
+
field('author', label('作者名', 'Author name'), recent.names);
|
|
182
|
+
const contact = field('contact', label('連絡先', 'Contact'), recent.contacts);
|
|
183
|
+
const contactView = element(document, 'div', undefined, { class: styles.preview });
|
|
184
|
+
const renderContact = () => {
|
|
185
|
+
const href = contactLink(contact.value);
|
|
186
|
+
contactView.replaceChildren();
|
|
187
|
+
if (!href)
|
|
188
|
+
return;
|
|
189
|
+
contactView.appendChild(element(document, 'a', contact.value, { href,
|
|
190
|
+
...(href.startsWith('https:') ? { target: '_blank', rel: 'noopener noreferrer' } : {}) }));
|
|
191
|
+
};
|
|
192
|
+
contact.addEventListener('input', renderContact);
|
|
193
|
+
renderContact();
|
|
194
|
+
form.appendChild(contactView);
|
|
195
|
+
const dates = element(document, 'dl');
|
|
196
|
+
for (const [key, title] of [['createdAt', label('作成日時', 'Created')],
|
|
197
|
+
['updatedAt', label('最終更新日時', 'Last updated')]]) {
|
|
198
|
+
dates.appendChild(element(document, 'dt', title));
|
|
199
|
+
const row = element(document, 'dd');
|
|
200
|
+
row.appendChild(value[key] ? element(document, 'time', new Date(value[key]).toLocaleString(locale), { datetime: value[key] }) : document.createTextNode(label('未記録', 'Not recorded')));
|
|
201
|
+
dates.appendChild(row);
|
|
202
|
+
}
|
|
203
|
+
form.appendChild(dates);
|
|
204
|
+
form.appendChild(element(document, 'p', label('作者名・連絡先の候補はこのブラウザに各5件保持します。作品ファイルには今回の入力値を保存します。', 'This browser remembers five recent names and contacts. Only the current values are saved in the project.')));
|
|
205
|
+
if (value.readOnly)
|
|
206
|
+
form.appendChild(element(document, 'p', label('この作品情報の形式は未対応です。元の情報を保持し、編集はできません。', 'This metadata version is unsupported. The original data is preserved and cannot be edited.')));
|
|
207
|
+
}
|
|
208
|
+
const canApplyMetadata = Boolean(history) && !value.readOnly;
|
|
209
|
+
const error = element(document, 'p', '', { role: 'alert' });
|
|
210
|
+
form.appendChild(error);
|
|
211
|
+
const cancel = element(document, 'button', label('キャンセル', 'Cancel'), { type: 'button' });
|
|
212
|
+
cancel.addEventListener('click', close);
|
|
213
|
+
const apply = element(document, 'button', label('適用', 'Apply'), { type: 'submit' });
|
|
214
|
+
apply.disabled = value.loading || (!canApplyMetadata && !uriInput);
|
|
215
|
+
const diagnosticsButton = element(document, 'button', label('作品の診断…', 'Project Diagnostics…'), { type: 'button' });
|
|
216
|
+
diagnosticsButton.addEventListener('click', () => api.showDiagnostics(locale));
|
|
217
|
+
form.append(dialogActions(document, diagnosticsButton, dialogAction(cancel, 'cancel'), dialogAction(apply, 'confirm')));
|
|
218
|
+
form.addEventListener('submit', async (event) => {
|
|
219
|
+
event.preventDefault();
|
|
220
|
+
if (apply.disabled)
|
|
221
|
+
return;
|
|
222
|
+
if (saveNameInput && !checkSaveName()) {
|
|
223
|
+
saveNameInput.focus();
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
apply.disabled = true;
|
|
227
|
+
error.textContent = '';
|
|
228
|
+
const draft = Object.fromEntries(Object.entries(inputs).map(([key, input]) => [key, input.value]));
|
|
229
|
+
try {
|
|
230
|
+
// Validate and apply the URI first so a rejected URI cannot commit the metadata draft.
|
|
231
|
+
if (uriInput && uriInput.value.trim() !== editURI.uri)
|
|
232
|
+
await editURI.apply(uriInput.value);
|
|
233
|
+
if (active !== dialog)
|
|
234
|
+
return;
|
|
235
|
+
if (canApplyMetadata) {
|
|
236
|
+
properties.apply(draft);
|
|
237
|
+
history.remember(draft.author, draft.contact);
|
|
238
|
+
}
|
|
239
|
+
close();
|
|
240
|
+
}
|
|
241
|
+
catch (failure) {
|
|
242
|
+
error.textContent = failure.code === 'INVALID_SAVE_NAME' ?
|
|
243
|
+
label('保存用の名前に使えない文字があります。', 'The save name has characters that cannot be used.') :
|
|
244
|
+
failure.code === 'INVALID_PROJECT_URI' ?
|
|
245
|
+
label('認証情報やフラグメントを含まない HTTPS URI を入力してください。', 'Enter an HTTPS URI without credentials or a fragment.') :
|
|
246
|
+
label('作品情報を適用できませんでした。読み込み完了後に開き直してください。', 'Could not apply properties. Reopen this dialog after loading has finished.');
|
|
247
|
+
apply.disabled = false;
|
|
248
|
+
if (failure.code === 'INVALID_PROJECT_URI' && active === dialog)
|
|
249
|
+
uriInput.focus();
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
dialog.appendChild(form);
|
|
253
|
+
dialog.showModal();
|
|
254
|
+
(inputs.title || uriInput)?.focus();
|
|
255
|
+
},
|
|
256
|
+
showPayloadFormats(edit, locale = 'en', addAssets) {
|
|
257
|
+
const { dialog } = open(locale.startsWith('ja') ? '作品データの形式' : 'Project Data Formats', locale);
|
|
258
|
+
const { form, dispose } = renderPayloadForm(document, edit, locale, close);
|
|
259
|
+
disposeView = dispose;
|
|
260
|
+
if (addAssets) {
|
|
261
|
+
const button = element(document, 'button', locale.startsWith('ja') ?
|
|
262
|
+
'バンドル素材を作品に追加…' : 'Add Bundle Material to Project…', { type: 'button' });
|
|
263
|
+
button.onclick = addAssets;
|
|
264
|
+
form.prepend(button);
|
|
265
|
+
}
|
|
266
|
+
dialog.append(form);
|
|
267
|
+
dialog.showModal();
|
|
268
|
+
},
|
|
269
|
+
showBundleAssetConversion(conversion, locale = 'en') {
|
|
270
|
+
const { dialog } = open(locale.startsWith('ja') ? 'バンドル素材を作品に追加' : 'Add Bundle Material to Project', locale);
|
|
271
|
+
const { form, dispose } = renderBundleAssetForm(document, conversion, locale, close);
|
|
272
|
+
disposeView = dispose;
|
|
273
|
+
dialog.append(form);
|
|
274
|
+
dialog.showModal();
|
|
275
|
+
},
|
|
276
|
+
showDiagnostics(locale = 'en', initialSession) {
|
|
277
|
+
const { dialog, label } = open(locale.startsWith('ja') ? '作品の診断' : 'Project Diagnostics', locale);
|
|
278
|
+
dialog.setAttribute('data-testid', 'project-diagnostics');
|
|
279
|
+
const selectorLabel = element(document, 'label', label('読み込みの記録', 'Load attempt'));
|
|
280
|
+
const selector = element(document, 'select', undefined, { 'aria-label': label('読み込みの記録', 'Load attempt') });
|
|
281
|
+
selectorLabel.appendChild(selector);
|
|
282
|
+
dialog.appendChild(selectorLabel);
|
|
283
|
+
const content = element(document, 'div');
|
|
284
|
+
dialog.appendChild(content);
|
|
285
|
+
const status = element(document, 'p', '', { role: 'status' });
|
|
286
|
+
dialog.appendChild(status);
|
|
287
|
+
const copy = element(document, 'button', label('診断をコピー', 'Copy diagnostics'), { type: 'button' });
|
|
288
|
+
const done = element(document, 'button', label('閉じる', 'Close'), { type: 'button' });
|
|
289
|
+
done.addEventListener('click', close);
|
|
290
|
+
dialog.append(dialogActions(document, copy, dialogAction(done, 'close')));
|
|
291
|
+
let selected = initialSession;
|
|
292
|
+
let exported = '';
|
|
293
|
+
const states = {
|
|
294
|
+
loading: label('読み込み中', 'Loading'), loaded: label('読み込み完了', 'Loaded'),
|
|
295
|
+
failed: label('読み込み失敗・キャンセル', 'Failed or cancelled'),
|
|
296
|
+
verified: label('内容を検証済み', 'Content verified'), authorized: label('実行を許可済み', 'Execution approved'),
|
|
297
|
+
review: label('実行許可を確認中', 'Reviewing execution permission'),
|
|
298
|
+
retry: label('接続を再試行中', 'Retrying connection'), error: label('読み込みを拒否', 'Loading rejected'),
|
|
299
|
+
'project-error': label('作品を開けませんでした', 'Could not open project')
|
|
300
|
+
};
|
|
301
|
+
const render = () => {
|
|
302
|
+
const sessions = diagnostics?.snapshot() || [];
|
|
303
|
+
const session = sessions.find(value => value.id === selected) || sessions[0];
|
|
304
|
+
selected = session?.id;
|
|
305
|
+
selector.replaceChildren(...sessions.map(value => element(document, 'option', `${new Date(value.startedAt).toLocaleString(locale)} · ${value.title || label('タイトル未設定', 'Untitled')} · ${states[value.phase] || value.phase}`, { value: value.id })));
|
|
306
|
+
if (session)
|
|
307
|
+
selector.value = String(session.id);
|
|
308
|
+
selector.disabled = sessions.length < 2;
|
|
309
|
+
copy.disabled = !session;
|
|
310
|
+
exported = diagnosticText(session);
|
|
311
|
+
content.replaceChildren();
|
|
312
|
+
if (!session || !session.events.length) {
|
|
313
|
+
content.appendChild(element(document, 'p', label('診断イベントはまだありません。', 'No diagnostic events have been recorded.')));
|
|
314
|
+
}
|
|
315
|
+
if (!session)
|
|
316
|
+
return;
|
|
317
|
+
for (const extension of session.extensions) {
|
|
318
|
+
const details = element(document, 'details');
|
|
319
|
+
details.appendChild(element(document, 'summary', extension.id));
|
|
320
|
+
details.appendChild(element(document, 'pre', [extension.source, extension.execution,
|
|
321
|
+
`SHA-256: ${extension.sha256}`].filter(Boolean).join('\n')));
|
|
322
|
+
content.appendChild(details);
|
|
323
|
+
}
|
|
324
|
+
const list = element(document, 'ol');
|
|
325
|
+
for (const event of session.events) {
|
|
326
|
+
const details = element(document, 'details');
|
|
327
|
+
details.appendChild(element(document, 'summary', [states[event.type] || event.type, event.id, event.ids?.join(', '), event.code].filter(Boolean).join(' · ')));
|
|
328
|
+
details.appendChild(element(document, 'pre', JSON.stringify(event, null, 2)));
|
|
329
|
+
const item = element(document, 'li');
|
|
330
|
+
item.appendChild(details);
|
|
331
|
+
list.appendChild(item);
|
|
332
|
+
}
|
|
333
|
+
content.appendChild(list);
|
|
334
|
+
};
|
|
335
|
+
selector.addEventListener('change', () => { selected = Number(selector.value); render(); });
|
|
336
|
+
copy.addEventListener('click', async () => {
|
|
337
|
+
try {
|
|
338
|
+
await document.defaultView.navigator.clipboard.writeText(exported);
|
|
339
|
+
status.textContent = label('コピーしました。', 'Copied.');
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
// Clipboard permissions differ by browser; offer selectable text without opening a new window.
|
|
343
|
+
const text = element(document, 'textarea', undefined, { readonly: '',
|
|
344
|
+
'aria-label': label('コピーする診断内容', 'Diagnostics to copy') });
|
|
345
|
+
text.value = exported;
|
|
346
|
+
content.replaceChildren(text);
|
|
347
|
+
text.focus();
|
|
348
|
+
text.select();
|
|
349
|
+
status.textContent = label('選択した内容をコピーしてください。', 'Copy the selected text.');
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
disposeView = diagnostics?.subscribe(render);
|
|
353
|
+
render();
|
|
354
|
+
dialog.showModal();
|
|
355
|
+
done.focus();
|
|
356
|
+
},
|
|
357
|
+
ownsKeyEvent: event => Boolean(event.target?.closest?.('[data-project-tools]')),
|
|
358
|
+
dispose() { unsubscribe(); stopNotice?.(); notice?.remove(); close(); }
|
|
359
|
+
};
|
|
360
|
+
return api;
|
|
361
|
+
};
|
|
362
|
+
return { createProjectDialogs };
|
|
363
|
+
}
|