@kubohiroya/turbowarp-plus-editor-workbench 0.28.0 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.ja.md CHANGED
@@ -4,6 +4,18 @@ TurboWarp Plus Editor の作業画面。分割レイアウト、Plus 標準配
4
4
 
5
5
  このパッケージは 0.3.0 まで `@kubohiroya/turbowarp-plus-editor-layout` として公開していた。
6
6
 
7
+ ## プロジェクト一覧
8
+
9
+ `project-catalog` は SB3、手元のフォルダ、ブラウザー保存、リモート Git と作業コピーを共通の登録として扱う。`project-catalog-dialog` と `project-catalog.css` が一覧・並び替え・開く・除外・保存データ削除・2種類の改名を提供する。`project-catalog-host` が既存のファイル保存、作品情報、project-folder と Git の接続口へつなぐ。Editor は `createProjectTools` の `catalogEnvironment` にファイルハンドルの読み取りと変更購読を渡し、`bindProjectCatalogFolder` でフォルダとリモート操作を渡す。`projectFileOpened` は読み込み成功後だけ呼ぶ。
10
+
11
+ カタログは IndexedDB の `twPlusProjectCatalog` に保存する。作品名を識別子に使わず、ファイルハンドル・OPFS の ID で照合する。同じリモートの別作業コピーは別登録のまま保持する。以前の画面配置に残ったハンドルと既存 OPFS 作品を取り込み、「一覧から除外」した作品は再取り込みで戻さない。最終利用日時は正常に開いた場合だけ更新する。
12
+
13
+ 作品名変更は作品を開き、作品情報を変更して既存の保存経路で書き戻す。保存先名は別操作で、両方を同名に揃える選択もできる。非対応の操作は理由を表示する。ファイル名の変更では `.sb3` を保持し、改名後もハンドルで画面配置を照合する。途中まで成功した場合は、成功した変更を個別に記録する。
14
+
15
+ 一覧からの除外は保存データを消さない。保存データ削除には確認を求め、開いている作品の保存先は先に別作品を開くまで削除しない。GitHub 上のリポジトリ削除は提供しない。GitHub の改名は #681 の対応を必要とする。切り戻す場合は一覧の接続と依存更新を戻し、カタログ・保存データを残す。
16
+
17
+ 対象検証: `npm run build`、`node --test test/project-catalog.test.ts test/workspace-layout-store.test.ts test/project-file-menu.test.ts`、`node --test test/project-catalog.browser.ts`(ヘッドレス)。
18
+
7
19
  ## 分割レイアウト
8
20
 
9
21
  同じ document 内で「編集領域/ステージ列」と「ステージ/対象領域」の境界を調整する。ホストは `createLayout(React)` に既存の React を渡し、`render` に渡される境界・スタイル・表示サイズを既存コンポーネントに接続する。ホストがストレージとキーを指定し、このパッケージが設定を保存・復元する。
package/README.md CHANGED
@@ -6,6 +6,16 @@ The workbench of TurboWarp Plus Editor: the resizable layout, the Plus standard
6
6
 
7
7
  This package was published as `@kubohiroya/turbowarp-plus-editor-layout` up to 0.3.0.
8
8
 
9
+ ## Project catalog
10
+
11
+ The `project-catalog`, `project-catalog-dialog`, `project-catalog-host` exports and `project-catalog.css` provide one catalog for SB3 files, device folders, browser storage and remote Git worktrees. The Editor supplies file handles, location subscriptions, folder operations and the remote opener through `createProjectTools`, `bindProjectCatalogFolder` and the successful-upload callback `projectFileOpened`.
12
+
13
+ The catalog uses the `twPlusProjectCatalog` IndexedDB database and matches resources by handle or browser ID. Names never identify resources, and different worktrees of one remote remain separate. Existing browser projects and handles from workspace history are imported without restoring forgotten entries. Sorting persists; only successful opens update usage times. Forgetting an entry never deletes its data.
14
+
15
+ Project-title changes open and save the project through its existing metadata and save services. Storage renaming is separate, with an optional shared name; native file renames retain `.sb3`. Unsupported operations explain why they are unavailable. Each completed rename is recorded independently, including when a later step fails. Deleting saved data requires confirmation and refuses the currently open resource. Deleting a repository on GitHub is not offered; repository renaming depends on Editor issue #681.
16
+
17
+ Run `npm run build`, the catalog/workspace/file-menu unit tests, and `node --test test/project-catalog.browser.ts` for focused validation. Roll back the host connection and dependency updates to restore the individual menus, keeping the catalog and saved data intact.
18
+
9
19
  ## Resizable layout
10
20
 
11
21
  Resize the divider between the editor and the stage column, or the divider between the stage and the target pane, within a single document. The host passes its React instance to `createLayout(React)` and connects the dividers, styles, and display dimensions provided by the `render` callback to its existing components. The host supplies a storage provider and key, and this package saves and restores the layout settings.
@@ -1,5 +1,7 @@
1
1
  /** Give the browser a frame before starting work that may block its main thread. */
2
- export declare function withWaitCursor<T>(documents: Iterable<Document>, run: () => T): Promise<Awaited<T>>;
2
+ export declare function withWaitCursor<T>(documents: Iterable<Document>, run: () => T, { releaseAfterPaint }?: {
3
+ releaseAfterPaint?: boolean;
4
+ }): Promise<Awaited<T>>;
3
5
  /** Temporarily restore the normal cursor while an operation needs an answer. */
4
6
  export declare function withoutWaitCursor<T>(document: Document | undefined, ask: () => T): Promise<Awaited<T>>;
5
7
  interface Target {
@@ -38,7 +38,7 @@ function afterPaint(document) {
38
38
  });
39
39
  }
40
40
  /** Give the browser a frame before starting work that may block its main thread. */
41
- export async function withWaitCursor(documents, run) {
41
+ export async function withWaitCursor(documents, run, { releaseAfterPaint = false } = {}) {
42
42
  const visible = [...new Set(documents)].filter(document => document?.head && document.defaultView && !document.defaultView.closed);
43
43
  const release = visible.map(holdCursor);
44
44
  try {
@@ -46,7 +46,13 @@ export async function withWaitCursor(documents, run) {
46
46
  return await run();
47
47
  }
48
48
  finally {
49
- release.forEach(done => done());
49
+ const finish = () => release.forEach(done => done());
50
+ // Resolving the project load lets the host mount its initial code view. Keep the already-painted
51
+ // wait cursor through that synchronous work without delaying the host's load continuation.
52
+ if (releaseAfterPaint)
53
+ void Promise.all(visible.map(afterPaint)).then(finish, finish);
54
+ else
55
+ finish();
50
56
  }
51
57
  }
52
58
  /** Temporarily restore the normal cursor while an operation needs an answer. */
@@ -14,6 +14,7 @@ declare const glyphs: {
14
14
  copy: string;
15
15
  remix: string;
16
16
  open: string;
17
+ projects: string;
17
18
  'project-folder-open': string;
18
19
  'project-folder-open-browser': string;
19
20
  'git-open-remote': string;
@@ -26,6 +26,7 @@ const glyphs = {
26
26
  remix: 'M18 8a7 7 0 1 0 0 8 M18 3v5h-5 M18 8l2-2',
27
27
  // An SB3 file is one file: a page with an arrow, set apart from the folder of Open Folder….
28
28
  open: 'M5 3h9l5 5v13H5z M14 3v5h5 M12 18v-7 M9 14l3-3 3 3',
29
+ projects: 'M4 4h16v16H4z M4 9h16 M9 9v11 M12 13h5 M12 17h5',
29
30
  'project-folder-open': 'M3 6h7l2 2h9l-2 11H3z M3 11h16',
30
31
  'project-folder-open-browser': 'M4 4h16a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1z M3 9h18 M6 6.5h.01 M8.5 6.5h.01 M11 6.5h.01',
31
32
  // A remote Git repository: a cloud with an arrow down, fetched onto the device.
@@ -0,0 +1,3 @@
1
+ import type { CatalogHost } from './project-catalog.js';
2
+ /** One set of commands for every resource. Availability comes from the saved resource's adapter. */
3
+ export declare function openProjectCatalog(document: Document, host: CatalogHost, locale?: string): () => void;
@@ -0,0 +1,235 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ import { renameCatalogProject, sortCatalog } from './project-catalog.js';
3
+ /** One set of commands for every resource. Availability comes from the saved resource's adapter. */
4
+ export function openProjectCatalog(document, host, locale = 'en') {
5
+ const ja = locale.startsWith('ja');
6
+ const label = (jp, en) => ja ? jp : en;
7
+ const view = document.defaultView;
8
+ const returnFocus = document.activeElement;
9
+ const dialog = document.createElement('dialog');
10
+ dialog.className = 'tw-project-catalog';
11
+ dialog.dataset.projectCatalog = '';
12
+ dialog.dataset.projectTools = '';
13
+ dialog.setAttribute('aria-label', label('プロジェクト一覧', 'Projects'));
14
+ const heading = document.createElement('h2');
15
+ heading.textContent = label('プロジェクト一覧', 'Projects');
16
+ const removalNote = document.createElement('p');
17
+ removalNote.textContent = label('「一覧から除外」は参照だけを消し、保存データを残します。「保存データを削除」は保存先のファイルやフォルダを消します。', 'Remove from List only forgets the reference and keeps the data. Delete Saved Data removes the saved file or folder.');
18
+ const orderLabel = document.createElement('label');
19
+ orderLabel.textContent = label('並び順 ', 'Sort by ');
20
+ const order = document.createElement('select');
21
+ order.name = 'sort';
22
+ const options = [
23
+ ['lastOpenedAt', label('最終利用日時', 'Last opened')], ['title', label('名前', 'Name')],
24
+ ['location', label('保存場所', 'Location')]
25
+ ];
26
+ for (const [key, name] of options)
27
+ for (const direction of ['desc', 'asc']) {
28
+ const option = document.createElement('option');
29
+ option.value = `${key}:${direction}`;
30
+ option.textContent = `${name} · ${direction === 'asc' ? label('昇順', 'Ascending') : label('降順', 'Descending')}`;
31
+ order.append(option);
32
+ }
33
+ orderLabel.append(order);
34
+ const status = document.createElement('p');
35
+ status.setAttribute('role', 'status');
36
+ const error = document.createElement('p');
37
+ error.setAttribute('role', 'alert');
38
+ error.hidden = true;
39
+ const list = document.createElement('ul');
40
+ list.dataset.projectCatalogList = '';
41
+ const editor = document.createElement('form');
42
+ editor.hidden = true;
43
+ editor.className = 'tw-project-catalog__rename';
44
+ const close = document.createElement('button');
45
+ close.type = 'button';
46
+ close.textContent = label('閉じる', 'Close');
47
+ close.dataset.catalogAction = 'close';
48
+ let alive = true;
49
+ let busy = false;
50
+ let sort = { by: 'lastOpenedAt', direction: 'desc' };
51
+ let records = [];
52
+ const report = (failure) => {
53
+ if (failure?.name === 'AbortError')
54
+ return;
55
+ error.textContent = label('操作を完了できませんでした。一部の変更が完了している場合があります。一覧を確認してください。', 'The operation could not be completed. Some changes may have completed. Check the list.') +
56
+ (failure instanceof Error ? ` ${failure.message}` : '');
57
+ error.hidden = false;
58
+ };
59
+ const dispose = () => {
60
+ if (!alive)
61
+ return;
62
+ alive = false;
63
+ dialog.remove();
64
+ if (returnFocus?.isConnected)
65
+ returnFocus.focus();
66
+ };
67
+ close.addEventListener('click', () => { if (!busy)
68
+ dialog.close(); });
69
+ dialog.addEventListener('close', dispose);
70
+ dialog.addEventListener('cancel', event => { if (busy)
71
+ event.preventDefault(); });
72
+ const setBusy = (value) => {
73
+ busy = value;
74
+ dialog.setAttribute('aria-busy', String(value));
75
+ order.disabled = value;
76
+ for (const control of dialog.querySelectorAll('button, input')) {
77
+ if (value) {
78
+ control.dataset.wasDisabled = String(control.disabled);
79
+ control.disabled = true;
80
+ }
81
+ else if (control.dataset.wasDisabled !== undefined) {
82
+ control.disabled = control.dataset.wasDisabled === 'true';
83
+ delete control.dataset.wasDisabled;
84
+ }
85
+ }
86
+ status.textContent = value ? label('処理中…', 'Working…') : '';
87
+ };
88
+ const run = async (action) => {
89
+ if (busy || !alive)
90
+ return;
91
+ error.hidden = true;
92
+ setBusy(true);
93
+ try {
94
+ await action();
95
+ }
96
+ catch (failure) {
97
+ if (alive)
98
+ report(failure);
99
+ }
100
+ finally {
101
+ if (alive) {
102
+ try {
103
+ records = await host.store.list();
104
+ draw();
105
+ }
106
+ catch (failure) {
107
+ report(failure);
108
+ }
109
+ setBusy(false);
110
+ }
111
+ }
112
+ };
113
+ const button = (text, command, action, unavailable) => {
114
+ const element = document.createElement('button');
115
+ element.type = 'button';
116
+ element.textContent = text;
117
+ element.dataset.catalogAction = command;
118
+ element.disabled = !action;
119
+ if (unavailable)
120
+ element.title = unavailable;
121
+ if (action)
122
+ element.addEventListener('click', action);
123
+ return element;
124
+ };
125
+ const rename = (project, target) => {
126
+ editor.replaceChildren();
127
+ editor.hidden = false;
128
+ const operations = host.operations(project);
129
+ const nameLabel = document.createElement('label');
130
+ nameLabel.textContent = target === 'title' ? label('新しいプロジェクト名 ', 'New project name ') :
131
+ label('保存先での新しい名前 ', 'New storage name ');
132
+ const input = document.createElement('input');
133
+ input.name = target;
134
+ input.required = true;
135
+ input.maxLength = target === 'title' ? 100 : 200;
136
+ input.value = project[target];
137
+ nameLabel.append(input);
138
+ const current = document.createElement('p');
139
+ current.textContent = label('現在の名前: ', 'Current name: ') + project[target];
140
+ const bothLabel = document.createElement('label');
141
+ const both = document.createElement('input');
142
+ both.type = 'checkbox';
143
+ both.name = 'both';
144
+ both.disabled = !operations.renameProject || !operations.renameStorage;
145
+ bothLabel.append(both, label('プロジェクト名と保存先の名前を揃える', 'Use this name for both project and storage'));
146
+ const save = document.createElement('button');
147
+ save.type = 'submit';
148
+ save.textContent = label('変更', 'Rename');
149
+ const cancel = button(label('キャンセル', 'Cancel'), 'cancel-rename', () => { editor.hidden = true; });
150
+ const targetNote = document.createElement('p');
151
+ targetNote.textContent = target === 'title' ? label('作品を開いて作品情報を変更し、保存します。', 'Opens the project, changes its project information, and saves it.') :
152
+ label('保存先での名前を変更します。作品名はチェックした場合に変更します。', 'Renames the saved resource. The project title changes only when checked.');
153
+ editor.append(current, targetNote, nameLabel, bothLabel, save, cancel);
154
+ editor.onsubmit = event => {
155
+ event.preventDefault();
156
+ const value = input.value.trim();
157
+ if (!value || !editor.reportValidity())
158
+ return;
159
+ void run(async () => {
160
+ const projectName = project.location === 'file' && target === 'storageName' ? value.replace(/\.sb3$/i, '') : value;
161
+ await renameCatalogProject(host, project, both.checked ? { title: projectName, storageName: value } : { [target]: value });
162
+ editor.hidden = true;
163
+ });
164
+ };
165
+ input.focus();
166
+ input.select();
167
+ };
168
+ const draw = () => {
169
+ list.replaceChildren();
170
+ if (!records.length) {
171
+ const empty = document.createElement('li');
172
+ empty.textContent = label('登録されたプロジェクトはありません。', 'No projects are registered.');
173
+ list.append(empty);
174
+ }
175
+ for (const project of sortCatalog(records, sort, locale)) {
176
+ const row = document.createElement('li');
177
+ row.dataset.projectId = project.id;
178
+ const name = document.createElement('strong');
179
+ name.textContent = project.title;
180
+ const detail = document.createElement('p');
181
+ const place = { file: label('SB3ファイル', 'SB3 file'), folder: label('手元のフォルダ', 'Device folder'),
182
+ browser: label('ブラウザー内', 'In this browser'), remote: label('リモートGit', 'Remote Git') }[project.location];
183
+ const time = project.lastOpenedAt === null ? label('未利用', 'Not opened yet') :
184
+ new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeStyle: 'short' }).format(project.lastOpenedAt);
185
+ detail.textContent = `${place} · ${project.storageName} · ${time}`;
186
+ const actions = host.operations(project);
187
+ const controls = document.createElement('div');
188
+ controls.className = 'tw-project-catalog__actions';
189
+ controls.append(button(label('開く', 'Open'), 'open', () => void run(async () => {
190
+ const source = await actions.open();
191
+ if (source) {
192
+ await host.store.register(source, true, project.id);
193
+ dialog.close();
194
+ }
195
+ })), button(label('プロジェクト名を変更…', 'Rename Project…'), 'rename-title', actions.renameProject ? () => rename(project, 'title') : undefined, actions.unavailable?.renameProject), button(label('保存先の名前を変更…', 'Rename Storage…'), 'rename-storage', actions.renameStorage ? () => rename(project, 'storageName') : undefined, actions.unavailable?.renameStorage), button(label('一覧から除外', 'Remove from List'), 'forget', () => void run(async () => {
196
+ await host.store.forget(project.id);
197
+ })), button(label('保存データを削除…', 'Delete Saved Data…'), 'delete', actions.deleteData ? () => void run(async () => {
198
+ const text = label('次の保存データを削除します。元に戻せません。GitHub上のリポジトリは削除しません。', 'Delete the following saved data? This cannot be undone. The repository on GitHub is kept.');
199
+ if (!view.confirm(`${text}\n\n${project.title}\n${place}: ${project.storageName}`))
200
+ return;
201
+ // Keep the import tombstone so legacy workspace history cannot restore a deleted resource.
202
+ await actions.deleteData();
203
+ await host.store.forget(project.id);
204
+ }) : undefined, actions.unavailable?.deleteData));
205
+ row.append(name, detail);
206
+ if (project.remote) {
207
+ const remote = document.createElement('p');
208
+ remote.textContent = project.remote;
209
+ row.append(remote);
210
+ }
211
+ row.append(controls);
212
+ const reasons = [...new Set(Object.values(actions.unavailable ?? {}).filter(Boolean))];
213
+ if (reasons.length) {
214
+ const note = document.createElement('small');
215
+ note.textContent = reasons.join(' ');
216
+ row.append(note);
217
+ }
218
+ list.append(row);
219
+ }
220
+ };
221
+ order.addEventListener('change', () => void run(async () => {
222
+ const [by, direction] = order.value.split(':');
223
+ sort = await host.store.sort({ by, direction });
224
+ }));
225
+ dialog.append(heading, removalNote, orderLabel, status, error, list, editor, close);
226
+ document.body.append(dialog);
227
+ dialog.showModal();
228
+ close.focus();
229
+ void run(async () => {
230
+ await host.refresh();
231
+ sort = await host.store.sort();
232
+ order.value = `${sort.by}:${sort.direction}`;
233
+ });
234
+ return dispose;
235
+ }
@@ -0,0 +1,50 @@
1
+ import type { BrowserProjects } from '@kubohiroya/turbowarp-plus-editor-project-folder';
2
+ import type { ProjectCatalogStore } from './project-catalog.js';
3
+ import type { ProjectFileStorage } from './project-file-dialogs.js';
4
+ export interface CatalogFolder {
5
+ readonly directory: FileSystemDirectoryHandle | null;
6
+ readonly root: FileSystemDirectoryHandle | null;
7
+ browserProjects: BrowserProjects | null;
8
+ openDirectory(directory: FileSystemDirectoryHandle, confirm: () => boolean, root?: FileSystemDirectoryHandle): Promise<string>;
9
+ save(): Promise<unknown>;
10
+ detach(): void;
11
+ }
12
+ export interface CatalogFolderPorts {
13
+ folder: CatalogFolder;
14
+ readRemote?(root: FileSystemDirectoryHandle): Promise<string | undefined>;
15
+ openRemote?(locale: string, remote?: string): Promise<boolean>;
16
+ }
17
+ export interface CatalogRuntimePorts {
18
+ document: Document;
19
+ vm: any;
20
+ readFile(): FileSystemFileHandle | null;
21
+ isDirty(): boolean;
22
+ properties: {
23
+ snapshot(): {
24
+ title: string;
25
+ loading?: boolean;
26
+ readOnly?: boolean;
27
+ };
28
+ loadedTitle?(): string | undefined;
29
+ apply(draft: {
30
+ title: string;
31
+ }): unknown;
32
+ subscribe(listener: () => void): () => void;
33
+ loadState(): {
34
+ phase: string;
35
+ sequence: number;
36
+ };
37
+ };
38
+ subscribeLocation?(listener: () => void): () => void;
39
+ report?(error: unknown): void;
40
+ store?: ProjectCatalogStore;
41
+ }
42
+ /** Connects native resources to the catalog without importing GUI code or changing the saved project format. */
43
+ export declare function createProjectCatalogRuntime(ports: CatalogRuntimePorts): {
44
+ store: ProjectCatalogStore;
45
+ bindFolder(value: CatalogFolderPorts): void;
46
+ fileOpened(file: File | null): void;
47
+ capture: () => void;
48
+ show(locale: string, fileStorage: ProjectFileStorage): void;
49
+ dispose(): void;
50
+ };