@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.
Files changed (49) hide show
  1. package/EDITOR-MIGRATION.md +5 -0
  2. package/README.ja.md +9 -0
  3. package/dist/basic-panel.d.ts +52 -0
  4. package/dist/basic-panel.js +153 -0
  5. package/dist/editor-tabs.d.ts +37 -0
  6. package/dist/editor-tabs.js +550 -0
  7. package/dist/popup-layout.d.ts +20 -0
  8. package/dist/popup-layout.js +59 -0
  9. package/dist/project-folder-workflows.d.ts +31 -0
  10. package/dist/project-folder-workflows.js +1 -0
  11. package/dist/project-payload-forms.d.ts +8 -0
  12. package/dist/project-payload-forms.js +184 -0
  13. package/dist/project-tools/diagnostics.d.ts +13 -0
  14. package/dist/project-tools/diagnostics.js +65 -0
  15. package/dist/project-tools/dialog.d.ts +21 -0
  16. package/dist/project-tools/dialog.js +363 -0
  17. package/dist/project-tools/history.d.ts +8 -0
  18. package/dist/project-tools/history.js +22 -0
  19. package/dist/project-tools/integration.d.ts +65 -0
  20. package/dist/project-tools/integration.js +356 -0
  21. package/dist/project-tools/links.d.ts +3 -0
  22. package/dist/project-tools/links.js +36 -0
  23. package/dist/project-tools/properties.d.ts +51 -0
  24. package/dist/project-tools/properties.js +268 -0
  25. package/dist/sprite-tabs.d.ts +1 -0
  26. package/dist/sprite-tabs.js +1 -0
  27. package/dist/stage-display-menu.d.ts +21 -0
  28. package/dist/stage-display-menu.js +156 -0
  29. package/dist/stage-panel.d.ts +29 -0
  30. package/dist/stage-panel.js +105 -0
  31. package/package.json +78 -9
  32. package/src/basic-panel.tsx +207 -0
  33. package/src/editor-tabs.tsx +591 -0
  34. package/src/popup-layout.css +4 -0
  35. package/src/popup-layout.tsx +81 -0
  36. package/src/project-dialog.css +39 -0
  37. package/src/project-folder-workflows.ts +32 -0
  38. package/src/project-payload-forms.ts +179 -0
  39. package/src/project-snackbar.css +85 -0
  40. package/src/project-tools/diagnostics.ts +51 -0
  41. package/src/project-tools/dialog.ts +341 -0
  42. package/src/project-tools/history.ts +20 -0
  43. package/src/project-tools/integration.ts +366 -0
  44. package/src/project-tools/links.ts +31 -0
  45. package/src/project-tools/properties.ts +251 -0
  46. package/src/sprite-tabs.ts +2 -1
  47. package/src/stage-display-menu.css +28 -0
  48. package/src/stage-display-menu.tsx +177 -0
  49. package/src/stage-panel.tsx +127 -0
@@ -0,0 +1,31 @@
1
+ import type { NewProjectRepositoryCreation } from './new-project.ts';
2
+ import type { ProjectCommitPort } from '@kubohiroya/turbowarp-plus-editor-git/project-commit-dialog';
3
+ import type { ProjectPublicationPort } from '@kubohiroya/turbowarp-plus-editor-git/project-publication';
4
+ import type { RepositoryCreationControls } from '@kubohiroya/turbowarp-plus-editor-git/project-repository-creation';
5
+ export type ProjectRepositoryCreation = Omit<NewProjectRepositoryCreation, 'start'> & RepositoryCreationControls & {
6
+ start(draft: Parameters<NewProjectRepositoryCreation['start']>[0], serialize: () => Promise<Uint8Array>, current: () => boolean, signal: AbortSignal, target?: Parameters<NewProjectRepositoryCreation['start']>[4]): ReturnType<NewProjectRepositoryCreation['start']>;
7
+ };
8
+ export interface ProjectFolderWorkflows {
9
+ /**
10
+ * Creates a project folder from the current project and opens it. `title` names a folder made in the browser, where
11
+ * the user names a new folder instead of picking one. `destination` is `browser` for a new folder in the browser's
12
+ * storage, or an empty folder already picked on the device; without it the folder follows `folderLocation`.
13
+ */
14
+ createFolder?(serialize: () => Promise<Uint8Array>, current: () => boolean, title?: string, destination?: 'browser' | FileSystemDirectoryHandle): Promise<boolean>;
15
+ /** Writes the current project into a new folder and leaves the open project as it is (Save a Copy, #679). */
16
+ copyFolder?(serialize: () => Promise<Uint8Array>, current: () => boolean, title?: string): Promise<boolean>;
17
+ /** Picks an empty folder on the device for a new project; `null` when the person cancelled or it was not empty. */
18
+ pickEmptyFolder?(language: string): Promise<FileSystemDirectoryHandle | null>;
19
+ /** Where new project folders can be made: the browser's own storage, and folders picked on the device. */
20
+ locations?: {
21
+ browser: boolean;
22
+ device: boolean;
23
+ };
24
+ /** Marks the open project as saved, for a new default project that is about to be replaced by its folder. */
25
+ markSaved?(): void;
26
+ /** `browser` when new project folders go to the browser's own storage, where there is no folder picker. */
27
+ folderLocation?: 'device' | 'browser';
28
+ repositoryCreation?: ProjectRepositoryCreation;
29
+ commit?: ProjectCommitPort;
30
+ publication?: ProjectPublicationPort;
31
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -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
+ };