@kubohiroya/turbowarp-plus-editor-workbench 0.28.1 → 0.29.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/README.ja.md +14 -0
- package/README.md +10 -0
- package/dist/extension-file-menu.d.ts +1 -0
- package/dist/extension-file-menu.js +1 -0
- package/dist/project-catalog-dialog.d.ts +3 -0
- package/dist/project-catalog-dialog.js +247 -0
- package/dist/project-catalog-host.d.ts +50 -0
- package/dist/project-catalog-host.js +330 -0
- package/dist/project-catalog-migration.d.ts +3 -0
- package/dist/project-catalog-migration.js +47 -0
- package/dist/project-catalog.d.ts +58 -0
- package/dist/project-catalog.js +150 -0
- package/dist/project-file-menu.d.ts +2 -0
- package/dist/project-file-menu.js +7 -6
- package/dist/project-tools/integration.d.ts +10 -1
- package/dist/project-tools/integration.js +15 -3
- package/dist/workspace-layout-store.js +2 -1
- package/package.json +17 -3
- package/src/extension-file-menu.ts +1 -0
- package/src/project-catalog-dialog.ts +206 -0
- package/src/project-catalog-host.ts +298 -0
- package/src/project-catalog-migration.ts +38 -0
- package/src/project-catalog.css +27 -0
- package/src/project-catalog.ts +172 -0
- package/src/project-file-menu.tsx +6 -3
- package/src/project-tools/integration.ts +22 -3
- package/src/workspace-layout-store.ts +2 -1
|
@@ -14,8 +14,9 @@ import { renderProjectPublicationDialog } from '@kubohiroya/turbowarp-plus-edito
|
|
|
14
14
|
import { projectFolderOverwriteWarning } from '@kubohiroya/turbowarp-plus-editor-project-folder';
|
|
15
15
|
import JSZip from '@turbowarp/jszip';
|
|
16
16
|
import { installProjectScreenState } from '../project-screen-state.js';
|
|
17
|
+
import { createProjectCatalogRuntime } from '../project-catalog-host.js';
|
|
17
18
|
/** Feature state and workflows are local to one host integration. */
|
|
18
|
-
export function createProjectTools({ installEditorExtensionHost, installProjectProperties, createProjectDialogs, editorProjectArchives, projectToolsEnabled: PROJECT_TOOLS_ENABLED, manualProjectURIEnabled: MANUAL_PROJECT_URI_ENABLED, readStartupFlags: readWebStartupFeatureFlags, projectLoadState }) {
|
|
19
|
+
export function createProjectTools({ installEditorExtensionHost, installProjectProperties, createProjectDialogs, editorProjectArchives, projectToolsEnabled: PROJECT_TOOLS_ENABLED, manualProjectURIEnabled: MANUAL_PROJECT_URI_ENABLED, readStartupFlags: readWebStartupFeatureFlags, projectLoadState, catalogEnvironment }) {
|
|
19
20
|
const projects = new WeakMap();
|
|
20
21
|
const screenStates = new WeakMap();
|
|
21
22
|
const storageFor = document => {
|
|
@@ -50,7 +51,13 @@ export function createProjectTools({ installEditorExtensionHost, installProjectP
|
|
|
50
51
|
const history = enabled ? createAuthorHistory(document ? storageFor(document) : undefined) : null;
|
|
51
52
|
const dialogs = document?.body ? createProjectDialogs(document, properties, history, diagnostics, { locale: settings.locale, getLocale: settings.getLocale }) : null;
|
|
52
53
|
const tools = { dialogs, payloads: 'payloads' in host ? host.payloads : undefined, propertiesEnabled: enabled,
|
|
53
|
-
projectURIEnabled: MANUAL_PROJECT_URI_ENABLED && host.enabled, properties, projectState: settings.projectState
|
|
54
|
+
projectURIEnabled: MANUAL_PROJECT_URI_ENABLED && host.enabled, properties, projectState: settings.projectState,
|
|
55
|
+
catalog: undefined };
|
|
56
|
+
const environment = document && catalogEnvironment?.(document);
|
|
57
|
+
if (environment)
|
|
58
|
+
tools.catalog = createProjectCatalogRuntime({ document, vm, properties, ...environment,
|
|
59
|
+
report: error => showNotice(document, (settings.getLocale?.() ?? settings.locale ?? 'en').startsWith('ja') ?
|
|
60
|
+
'プロジェクト履歴を保存できませんでした。' : 'The project history could not be saved.', { locale: settings.getLocale?.() ?? settings.locale ?? 'en' }) });
|
|
54
61
|
let lastPhase;
|
|
55
62
|
const unsubscribe = properties.subscribe(() => {
|
|
56
63
|
const state = properties.loadState();
|
|
@@ -70,6 +77,7 @@ export function createProjectTools({ installEditorExtensionHost, installProjectP
|
|
|
70
77
|
disposal ??= (async () => {
|
|
71
78
|
vm.off?.('ASSET_PROGRESS', reportAssets);
|
|
72
79
|
vm.runtime?.off?.('PROJECT_LOADED', finishProject);
|
|
80
|
+
tools.catalog?.dispose();
|
|
73
81
|
unsubscribe();
|
|
74
82
|
dialogs?.dispose();
|
|
75
83
|
properties.dispose();
|
|
@@ -352,5 +360,9 @@ export function createProjectTools({ installEditorExtensionHost, installProjectP
|
|
|
352
360
|
} }, locale.startsWith('ja') ? ja : en))));
|
|
353
361
|
};
|
|
354
362
|
const projectToolsOwnKeyEvent = event => Boolean(event.target?.closest?.('[data-project-tools]'));
|
|
355
|
-
|
|
363
|
+
const bindProjectCatalogFolder = (vm, ports) => projects.get(vm)?.catalog?.bindFolder(ports);
|
|
364
|
+
const projectCatalog = (vm, locale, storage, createProject) => projects.get(vm)?.catalog?.show(locale, storage, createProject);
|
|
365
|
+
const projectFileOpened = (vm, file) => projects.get(vm)?.catalog?.fileOpened(file);
|
|
366
|
+
return { installProjectToolsHost, projectScreenState, loadedProjectTitle, restoreProjectTitle, isProjectLoading, subscribeProjectLoad, projectSaveName, setProjectSaveName, createFolderFromCurrentProject, projectFileActions, projectCreation, renderFileMenu, projectToolsOwnKeyEvent,
|
|
367
|
+
bindProjectCatalogFolder, projectCatalog, projectFileOpened };
|
|
356
368
|
}
|
|
@@ -43,7 +43,8 @@ async function find(database, identity, signature) {
|
|
|
43
43
|
const store = transaction.objectStore(layoutsStore);
|
|
44
44
|
const records = identity.kind === 'desktop' ?
|
|
45
45
|
await result(store.index('desktopKey').getAll(identity.key)) :
|
|
46
|
-
await result(store.index('name').getAll(identity.name))
|
|
46
|
+
identity.kind === 'anonymous' ? await result(store.index('name').getAll(identity.name)) :
|
|
47
|
+
await result(store.getAll());
|
|
47
48
|
await finished;
|
|
48
49
|
const candidates = recent(records.filter(record => record.kind === identity.kind));
|
|
49
50
|
if (identity.kind === 'desktop')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-plus-editor-workbench",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.1",
|
|
4
4
|
"description": "The TurboWarp Plus Editor workbench: layout, dockable sprite tabs, stage, debugger tab and file menu",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -179,7 +179,20 @@
|
|
|
179
179
|
"./editor-tabs": {
|
|
180
180
|
"types": "./dist/editor-tabs.d.ts",
|
|
181
181
|
"default": "./dist/editor-tabs.js"
|
|
182
|
-
}
|
|
182
|
+
},
|
|
183
|
+
"./project-catalog": {
|
|
184
|
+
"types": "./dist/project-catalog.d.ts",
|
|
185
|
+
"default": "./dist/project-catalog.js"
|
|
186
|
+
},
|
|
187
|
+
"./project-catalog-dialog": {
|
|
188
|
+
"types": "./dist/project-catalog-dialog.d.ts",
|
|
189
|
+
"default": "./dist/project-catalog-dialog.js"
|
|
190
|
+
},
|
|
191
|
+
"./project-catalog-host": {
|
|
192
|
+
"types": "./dist/project-catalog-host.d.ts",
|
|
193
|
+
"default": "./dist/project-catalog-host.js"
|
|
194
|
+
},
|
|
195
|
+
"./project-catalog.css": "./src/project-catalog.css"
|
|
183
196
|
},
|
|
184
197
|
"files": [
|
|
185
198
|
"dist",
|
|
@@ -213,7 +226,8 @@
|
|
|
213
226
|
"@kubohiroya/turbowarp-extension-loader": "0.11.1",
|
|
214
227
|
"@kubohiroya/turbowarp-plus-editor-project-folder": "0.20.1",
|
|
215
228
|
"@kubohiroya/turbowarp-plus-editor-code-views": "0.22.1",
|
|
216
|
-
"@kubohiroya/turbowarp-extension-security-dialog": "0.9.0"
|
|
229
|
+
"@kubohiroya/turbowarp-extension-security-dialog": "0.9.0",
|
|
230
|
+
"esbuild": "0.25.12"
|
|
217
231
|
},
|
|
218
232
|
"repository": {
|
|
219
233
|
"type": "git",
|
|
@@ -36,6 +36,7 @@ const glyphs = {
|
|
|
36
36
|
remix: 'M18 8a7 7 0 1 0 0 8 M18 3v5h-5 M18 8l2-2',
|
|
37
37
|
// An SB3 file is one file: a page with an arrow, set apart from the folder of Open Folder….
|
|
38
38
|
open: 'M5 3h9l5 5v13H5z M14 3v5h5 M12 18v-7 M9 14l3-3 3 3',
|
|
39
|
+
projects: 'M4 4h16v16H4z M4 9h16 M9 9v11 M12 13h5 M12 17h5',
|
|
39
40
|
'project-folder-open': 'M3 6h7l2 2h9l-2 11H3z M3 11h16',
|
|
40
41
|
'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',
|
|
41
42
|
// A remote Git repository: a cloud with an arrow down, fetched onto the device.
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
import {renameCatalogProject, sortCatalog} from './project-catalog.js';
|
|
3
|
+
import type {CatalogHost, CatalogProject, CatalogSort} from './project-catalog.js';
|
|
4
|
+
|
|
5
|
+
/** One set of commands for every resource. Availability comes from the saved resource's adapter. */
|
|
6
|
+
export function openProjectCatalog(document: Document, host: CatalogHost, locale = 'en'): () => void {
|
|
7
|
+
const ja = locale.startsWith('ja');
|
|
8
|
+
const label = (jp: string, en: string) => ja ? jp : en;
|
|
9
|
+
const view = document.defaultView!;
|
|
10
|
+
const returnFocus = document.activeElement as HTMLElement | null;
|
|
11
|
+
const dialog = document.createElement('dialog');
|
|
12
|
+
dialog.className = 'tw-project-catalog';
|
|
13
|
+
dialog.dataset.projectCatalog = '';
|
|
14
|
+
dialog.dataset.projectTools = '';
|
|
15
|
+
dialog.setAttribute('aria-label', label('プロジェクト一覧', 'Projects'));
|
|
16
|
+
const heading = document.createElement('h2');
|
|
17
|
+
heading.textContent = label('プロジェクト一覧', 'Projects');
|
|
18
|
+
const removalNote = document.createElement('p');
|
|
19
|
+
removalNote.textContent = label('「一覧から除外」は参照だけを消し、保存データを残します。「保存データを削除」は保存先のファイルやフォルダを消します。',
|
|
20
|
+
'Remove from List only forgets the reference and keeps the data. Delete Saved Data removes the saved file or folder.');
|
|
21
|
+
const orderLabel = document.createElement('label');
|
|
22
|
+
orderLabel.textContent = label('並び順 ', 'Sort by ');
|
|
23
|
+
const order = document.createElement('select');
|
|
24
|
+
order.name = 'sort';
|
|
25
|
+
const options: [CatalogSort['by'], string][] = [
|
|
26
|
+
['lastOpenedAt', label('最終利用日時', 'Last opened')], ['title', label('名前', 'Name')],
|
|
27
|
+
['location', label('保存場所', 'Location')]
|
|
28
|
+
];
|
|
29
|
+
for (const [key, name] of options) for (const direction of ['desc', 'asc'] as const) {
|
|
30
|
+
const option = document.createElement('option');
|
|
31
|
+
option.value = `${key}:${direction}`;
|
|
32
|
+
option.textContent = `${name} · ${direction === 'asc' ? label('昇順', 'Ascending') : label('降順', 'Descending')}`;
|
|
33
|
+
order.append(option);
|
|
34
|
+
}
|
|
35
|
+
orderLabel.append(order);
|
|
36
|
+
const status = document.createElement('p');
|
|
37
|
+
status.setAttribute('role', 'status');
|
|
38
|
+
const error = document.createElement('p');
|
|
39
|
+
error.setAttribute('role', 'alert');
|
|
40
|
+
error.hidden = true;
|
|
41
|
+
const list = document.createElement('ul');
|
|
42
|
+
list.dataset.projectCatalogList = '';
|
|
43
|
+
const editor = document.createElement('form');
|
|
44
|
+
editor.hidden = true;
|
|
45
|
+
editor.className = 'tw-project-catalog__rename';
|
|
46
|
+
const close = document.createElement('button');
|
|
47
|
+
close.type = 'button';
|
|
48
|
+
close.textContent = label('閉じる', 'Close');
|
|
49
|
+
close.dataset.catalogAction = 'close';
|
|
50
|
+
let alive = true;
|
|
51
|
+
let busy = false;
|
|
52
|
+
let sort: CatalogSort = {by: 'lastOpenedAt', direction: 'desc'};
|
|
53
|
+
let records: CatalogProject[] = [];
|
|
54
|
+
const report = (failure: unknown) => {
|
|
55
|
+
if ((failure as {name?: string})?.name === 'AbortError') return;
|
|
56
|
+
error.textContent = label('操作を完了できませんでした。一部の変更が完了している場合があります。一覧を確認してください。',
|
|
57
|
+
'The operation could not be completed. Some changes may have completed. Check the list.') +
|
|
58
|
+
(failure instanceof Error ? ` ${failure.message}` : '');
|
|
59
|
+
error.hidden = false;
|
|
60
|
+
};
|
|
61
|
+
const dispose = () => {
|
|
62
|
+
if (!alive) return;
|
|
63
|
+
alive = false;
|
|
64
|
+
dialog.remove();
|
|
65
|
+
if (returnFocus?.isConnected) returnFocus.focus();
|
|
66
|
+
};
|
|
67
|
+
close.addEventListener('click', () => {if (!busy) dialog.close();});
|
|
68
|
+
dialog.addEventListener('close', dispose);
|
|
69
|
+
dialog.addEventListener('cancel', event => {if (busy) event.preventDefault();});
|
|
70
|
+
const setBusy = (value: boolean) => {
|
|
71
|
+
busy = value;
|
|
72
|
+
dialog.setAttribute('aria-busy', String(value));
|
|
73
|
+
order.disabled = value;
|
|
74
|
+
for (const control of dialog.querySelectorAll<HTMLButtonElement | HTMLInputElement>('button, input')) {
|
|
75
|
+
if (value) {control.dataset.wasDisabled = String(control.disabled); control.disabled = true;}
|
|
76
|
+
else if (control.dataset.wasDisabled !== undefined) {
|
|
77
|
+
control.disabled = control.dataset.wasDisabled === 'true'; delete control.dataset.wasDisabled;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
status.textContent = value ? label('処理中…', 'Working…') : '';
|
|
81
|
+
};
|
|
82
|
+
const run = async (action: () => Promise<void>) => {
|
|
83
|
+
if (busy || !alive) return;
|
|
84
|
+
error.hidden = true;
|
|
85
|
+
setBusy(true);
|
|
86
|
+
try {await action();} catch (failure) {if (alive) report(failure);}
|
|
87
|
+
finally {
|
|
88
|
+
if (alive) {
|
|
89
|
+
try {records = await host.store.list(); draw();} catch (failure) {report(failure);}
|
|
90
|
+
setBusy(false);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const button = (text: string, command: string, action?: () => void, unavailable?: string) => {
|
|
95
|
+
const element = document.createElement('button');
|
|
96
|
+
element.type = 'button'; element.textContent = text; element.dataset.catalogAction = command;
|
|
97
|
+
element.disabled = !action;
|
|
98
|
+
if (unavailable) element.title = unavailable;
|
|
99
|
+
if (action) element.addEventListener('click', action);
|
|
100
|
+
return element;
|
|
101
|
+
};
|
|
102
|
+
const header = document.createElement('div');
|
|
103
|
+
header.className = 'tw-project-catalog__header';
|
|
104
|
+
header.append(heading);
|
|
105
|
+
if (host.createProject) header.append(button(label('新しいプロジェクトを作成…', 'Create New Project…'), 'create', () => {
|
|
106
|
+
if (busy || !alive) return;
|
|
107
|
+
dialog.close();
|
|
108
|
+
// Dispose before opening the next dialog so the queued close event cannot steal its focus.
|
|
109
|
+
dispose();
|
|
110
|
+
host.createProject!();
|
|
111
|
+
}));
|
|
112
|
+
const rename = (project: CatalogProject, target: 'title' | 'storageName') => {
|
|
113
|
+
editor.replaceChildren(); editor.hidden = false;
|
|
114
|
+
const operations = host.operations(project);
|
|
115
|
+
const nameLabel = document.createElement('label');
|
|
116
|
+
nameLabel.textContent = target === 'title' ? label('新しいプロジェクト名 ', 'New project name ') :
|
|
117
|
+
label('保存先での新しい名前 ', 'New storage name ');
|
|
118
|
+
const input = document.createElement('input');
|
|
119
|
+
input.name = target; input.required = true; input.maxLength = target === 'title' ? 100 : 200;
|
|
120
|
+
input.value = project[target]; nameLabel.append(input);
|
|
121
|
+
const current = document.createElement('p');
|
|
122
|
+
current.textContent = label('現在の名前: ', 'Current name: ') + project[target];
|
|
123
|
+
const bothLabel = document.createElement('label');
|
|
124
|
+
const both = document.createElement('input'); both.type = 'checkbox'; both.name = 'both';
|
|
125
|
+
both.disabled = !operations.renameProject || !operations.renameStorage;
|
|
126
|
+
bothLabel.append(both, label('プロジェクト名と保存先の名前を揃える', 'Use this name for both project and storage'));
|
|
127
|
+
const save = document.createElement('button');
|
|
128
|
+
save.type = 'submit'; save.textContent = label('変更', 'Rename');
|
|
129
|
+
const cancel = button(label('キャンセル', 'Cancel'), 'cancel-rename', () => {editor.hidden = true;});
|
|
130
|
+
const targetNote = document.createElement('p');
|
|
131
|
+
targetNote.textContent = target === 'title' ? label('作品を開いて作品情報を変更し、保存します。',
|
|
132
|
+
'Opens the project, changes its project information, and saves it.') :
|
|
133
|
+
label('保存先での名前を変更します。作品名はチェックした場合に変更します。',
|
|
134
|
+
'Renames the saved resource. The project title changes only when checked.');
|
|
135
|
+
editor.append(current, targetNote, nameLabel, bothLabel, save, cancel);
|
|
136
|
+
editor.onsubmit = event => {
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
const value = input.value.trim();
|
|
139
|
+
if (!value || !editor.reportValidity()) return;
|
|
140
|
+
void run(async () => {
|
|
141
|
+
const projectName = project.location === 'file' && target === 'storageName' ? value.replace(/\.sb3$/i, '') : value;
|
|
142
|
+
await renameCatalogProject(host, project, both.checked ? {title: projectName, storageName: value} : {[target]: value});
|
|
143
|
+
editor.hidden = true;
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
input.focus(); input.select();
|
|
147
|
+
};
|
|
148
|
+
const draw = () => {
|
|
149
|
+
list.replaceChildren();
|
|
150
|
+
if (!records.length) {
|
|
151
|
+
const empty = document.createElement('li');
|
|
152
|
+
empty.textContent = label('登録されたプロジェクトはありません。', 'No projects are registered.');
|
|
153
|
+
list.append(empty);
|
|
154
|
+
}
|
|
155
|
+
for (const project of sortCatalog(records, sort, locale)) {
|
|
156
|
+
const row = document.createElement('li'); row.dataset.projectId = project.id;
|
|
157
|
+
const name = document.createElement('strong'); name.textContent = project.title;
|
|
158
|
+
const detail = document.createElement('p');
|
|
159
|
+
const place = {file: label('SB3ファイル', 'SB3 file'), folder: label('手元のフォルダ', 'Device folder'),
|
|
160
|
+
browser: label('ブラウザー内', 'In this browser'), remote: label('リモートGit', 'Remote Git')}[project.location];
|
|
161
|
+
const time = project.lastOpenedAt === null ? label('未利用', 'Not opened yet') :
|
|
162
|
+
new Intl.DateTimeFormat(locale, {dateStyle: 'medium', timeStyle: 'short'}).format(project.lastOpenedAt);
|
|
163
|
+
detail.textContent = `${place} · ${project.storageName} · ${time}`;
|
|
164
|
+
const actions = host.operations(project);
|
|
165
|
+
const controls = document.createElement('div'); controls.className = 'tw-project-catalog__actions';
|
|
166
|
+
controls.append(
|
|
167
|
+
button(label('開く', 'Open'), 'open', () => void run(async () => {
|
|
168
|
+
const source = await actions.open();
|
|
169
|
+
if (source) {await host.store.register(source, true, project.id); dialog.close();}
|
|
170
|
+
})),
|
|
171
|
+
button(label('プロジェクト名を変更…', 'Rename Project…'), 'rename-title',
|
|
172
|
+
actions.renameProject ? () => rename(project, 'title') : undefined, actions.unavailable?.renameProject),
|
|
173
|
+
button(label('保存先の名前を変更…', 'Rename Storage…'), 'rename-storage',
|
|
174
|
+
actions.renameStorage ? () => rename(project, 'storageName') : undefined, actions.unavailable?.renameStorage),
|
|
175
|
+
button(label('一覧から除外', 'Remove from List'), 'forget', () => void run(async () => {
|
|
176
|
+
await host.store.forget(project.id);
|
|
177
|
+
})),
|
|
178
|
+
button(label('保存データを削除…', 'Delete Saved Data…'), 'delete', actions.deleteData ? () => void run(async () => {
|
|
179
|
+
const text = label('次の保存データを削除します。元に戻せません。GitHub上のリポジトリは削除しません。',
|
|
180
|
+
'Delete the following saved data? This cannot be undone. The repository on GitHub is kept.');
|
|
181
|
+
if (!view.confirm(`${text}\n\n${project.title}\n${place}: ${project.storageName}`)) return;
|
|
182
|
+
// Keep the import tombstone so legacy workspace history cannot restore a deleted resource.
|
|
183
|
+
await actions.deleteData!(); await host.store.forget(project.id);
|
|
184
|
+
}) : undefined, actions.unavailable?.deleteData)
|
|
185
|
+
);
|
|
186
|
+
row.append(name, detail);
|
|
187
|
+
if (project.remote) {const remote = document.createElement('p'); remote.textContent = project.remote; row.append(remote);}
|
|
188
|
+
row.append(controls);
|
|
189
|
+
const reasons = [...new Set(Object.values(actions.unavailable ?? {}).filter(Boolean))];
|
|
190
|
+
if (reasons.length) {
|
|
191
|
+
const note = document.createElement('small'); note.textContent = reasons.join(' '); row.append(note);
|
|
192
|
+
}
|
|
193
|
+
list.append(row);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
order.addEventListener('change', () => void run(async () => {
|
|
197
|
+
const [by, direction] = order.value.split(':') as [CatalogSort['by'], CatalogSort['direction']];
|
|
198
|
+
sort = await host.store.sort({by, direction});
|
|
199
|
+
}));
|
|
200
|
+
dialog.append(header, removalNote, orderLabel, status, error, list, editor, close);
|
|
201
|
+
document.body.append(dialog); dialog.showModal(); close.focus();
|
|
202
|
+
void run(async () => {
|
|
203
|
+
await host.refresh(); sort = await host.store.sort(); order.value = `${sort.by}:${sort.direction}`;
|
|
204
|
+
});
|
|
205
|
+
return dispose;
|
|
206
|
+
}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
import type {BrowserProjects} from '@kubohiroya/turbowarp-plus-editor-project-folder';
|
|
3
|
+
import {flushPendingSurfaceEdits} from '@kubohiroya/turbowarp-plus-editor-windows/surfaces';
|
|
4
|
+
import {createProjectCatalogStore} from './project-catalog.js';
|
|
5
|
+
import type {CatalogHost, CatalogOperations, CatalogProject, CatalogSource, ProjectCatalogStore} from './project-catalog.js';
|
|
6
|
+
import {openProjectCatalog} from './project-catalog-dialog.js';
|
|
7
|
+
import {importWorkspaceProjectHistory} from './project-catalog-migration.js';
|
|
8
|
+
import type {ProjectFileStorage} from './project-file-dialogs.js';
|
|
9
|
+
import {withProjectSerialization} from '@kubohiroya/turbowarp-extension-loader/scratch-vm';
|
|
10
|
+
import {PROJECT_INFO_KEY} from './project-tools/properties.js';
|
|
11
|
+
|
|
12
|
+
export interface CatalogFolder {
|
|
13
|
+
readonly directory: FileSystemDirectoryHandle | null;
|
|
14
|
+
readonly root: FileSystemDirectoryHandle | null;
|
|
15
|
+
browserProjects: BrowserProjects | null;
|
|
16
|
+
openDirectory(directory: FileSystemDirectoryHandle, confirm: () => boolean,
|
|
17
|
+
root?: FileSystemDirectoryHandle): Promise<string>;
|
|
18
|
+
save(): Promise<unknown>;
|
|
19
|
+
detach(): void;
|
|
20
|
+
}
|
|
21
|
+
export interface CatalogFolderPorts {
|
|
22
|
+
folder: CatalogFolder;
|
|
23
|
+
readRemote?(root: FileSystemDirectoryHandle): Promise<string | undefined>;
|
|
24
|
+
openRemote?(locale: string, remote?: string): Promise<boolean>;
|
|
25
|
+
}
|
|
26
|
+
export interface CatalogRuntimePorts {
|
|
27
|
+
document: Document;
|
|
28
|
+
vm: any;
|
|
29
|
+
readFile(): FileSystemFileHandle | null;
|
|
30
|
+
isDirty(): boolean;
|
|
31
|
+
properties: {snapshot(): {title: string; loading?: boolean; readOnly?: boolean};
|
|
32
|
+
loadedTitle?(): string | undefined;
|
|
33
|
+
apply(draft: {title: string}): unknown; subscribe(listener: () => void): () => void;
|
|
34
|
+
loadState(): {phase: string; sequence: number}};
|
|
35
|
+
subscribeLocation?(listener: () => void): () => void;
|
|
36
|
+
report?(error: unknown): void;
|
|
37
|
+
store?: ProjectCatalogStore;
|
|
38
|
+
}
|
|
39
|
+
type PermissionHandle = FileSystemHandle & {queryPermission?(options: {mode: string}): Promise<string>;
|
|
40
|
+
requestPermission?(options: {mode: string}): Promise<string>};
|
|
41
|
+
type MutableHandle = (FileSystemFileHandle | FileSystemDirectoryHandle) & {
|
|
42
|
+
move?(name: string): Promise<void>;
|
|
43
|
+
remove?(options?: {recursive?: boolean}): Promise<void>;
|
|
44
|
+
};
|
|
45
|
+
async function permission(handle: FileSystemHandle, mode: 'read' | 'readwrite') {
|
|
46
|
+
const access = handle as PermissionHandle;
|
|
47
|
+
if (!access.queryPermission || await access.queryPermission({mode}) === 'granted') return;
|
|
48
|
+
if (!access.requestPermission || await access.requestPermission({mode}) !== 'granted') {
|
|
49
|
+
throw new DOMException('Permission was not granted', 'NotAllowedError');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const same = async (a?: FileSystemHandle | null, b?: FileSystemHandle | null) => {
|
|
53
|
+
try {return Boolean(a && b && await a.isSameEntry(b));} catch {return false;}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** Connects native resources to the catalog without importing GUI code or changing the saved project format. */
|
|
57
|
+
export function createProjectCatalogRuntime(ports: CatalogRuntimePorts) {
|
|
58
|
+
const {document, vm, properties} = ports;
|
|
59
|
+
const view = document.defaultView!;
|
|
60
|
+
const store = ports.store ?? createProjectCatalogStore({indexedDB: view.indexedDB, locks: view.navigator.locks});
|
|
61
|
+
let folders: CatalogFolderPorts | undefined;
|
|
62
|
+
let storage: ProjectFileStorage | undefined;
|
|
63
|
+
let activeId: string | undefined;
|
|
64
|
+
let alive = true;
|
|
65
|
+
let performing = false;
|
|
66
|
+
let selectedFile: {file: File; sequence: number} | undefined;
|
|
67
|
+
let observedSequence = -1;
|
|
68
|
+
let observedFile: FileSystemFileHandle | null = null;
|
|
69
|
+
let timer: number | undefined;
|
|
70
|
+
let dialog: (() => void) | undefined;
|
|
71
|
+
let tracking = Promise.resolve();
|
|
72
|
+
const report = (error: unknown) => ports.report?.(error);
|
|
73
|
+
const title = () => properties.snapshot().title;
|
|
74
|
+
const askReplace = (locale: string) => !ports.isDirty() || view.confirm(locale.startsWith('ja') ?
|
|
75
|
+
'現在の作品に未保存の変更があります。選んだ作品を開きますか?' :
|
|
76
|
+
'The current project has unsaved changes. Open the selected project?');
|
|
77
|
+
const source = async (fallback?: CatalogProject): Promise<CatalogSource | null> => {
|
|
78
|
+
const folder = folders?.folder;
|
|
79
|
+
const handle = folder?.directory ?? ports.readFile();
|
|
80
|
+
if (!handle) return fallback?.location === 'file' ? {...fallback, title: title() || fallback.title} : null;
|
|
81
|
+
const browser = handle.kind === 'directory' && folder?.browserProjects ? await folder.browserProjects.find(handle) : null;
|
|
82
|
+
const remote = handle.kind === 'directory' ? await folders?.readRemote?.(folder?.root ?? handle).catch(() => undefined) : undefined;
|
|
83
|
+
return {location: browser ? 'browser' : handle.kind === 'file' ? 'file' : 'folder',
|
|
84
|
+
title: title() || browser?.title || handle.name, storageName: browser?.title ?? handle.name,
|
|
85
|
+
handle, repositoryRoot: handle.kind === 'directory' ? folder?.root ?? undefined : undefined,
|
|
86
|
+
browserId: browser?.id, remote};
|
|
87
|
+
};
|
|
88
|
+
const capture = () => {
|
|
89
|
+
const load = properties.loadState();
|
|
90
|
+
const file = ports.readFile();
|
|
91
|
+
if (!alive || performing || properties.snapshot().loading || load.phase === 'failed') return;
|
|
92
|
+
if (load.sequence === observedSequence && file === observedFile) return;
|
|
93
|
+
observedSequence = load.sequence; observedFile = file;
|
|
94
|
+
if (load.phase !== 'loaded') return;
|
|
95
|
+
const selection = selectedFile?.sequence === load.sequence ? selectedFile.file : undefined;
|
|
96
|
+
tracking = tracking.catch(() => {}).then(async () => {
|
|
97
|
+
if (!alive || performing) return;
|
|
98
|
+
const input = await source() ?? (selection ? {location: 'file' as const, title: title() || selection.name,
|
|
99
|
+
storageName: selection.name} : null);
|
|
100
|
+
if (input) activeId = (await store.register(input)).id;
|
|
101
|
+
else activeId = undefined;
|
|
102
|
+
}).catch(report);
|
|
103
|
+
};
|
|
104
|
+
const schedule = () => {
|
|
105
|
+
if (!alive) return;
|
|
106
|
+
view.clearTimeout(timer);
|
|
107
|
+
// Folder onOpened and the GUI's upload completion publish their location after loadProject resolves.
|
|
108
|
+
timer = view.setTimeout(capture, 0);
|
|
109
|
+
};
|
|
110
|
+
const stopLoad = properties.subscribe(schedule);
|
|
111
|
+
const stopLocation = ports.subscribeLocation?.(schedule);
|
|
112
|
+
const withAction = async <T>(run: () => Promise<T>): Promise<T> => {
|
|
113
|
+
if (performing) throw new Error('Another project operation is in progress');
|
|
114
|
+
performing = true;
|
|
115
|
+
try {await tracking; return await run();}
|
|
116
|
+
finally {
|
|
117
|
+
performing = false; observedSequence = properties.loadState().sequence; observedFile = ports.readFile();
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const chooseFile = (project: CatalogProject): Promise<{file: File; handle?: FileSystemFileHandle} | null> => {
|
|
121
|
+
const picker = (view as Window & {showOpenFilePicker?: (options: unknown) => Promise<FileSystemFileHandle[]>}).showOpenFilePicker;
|
|
122
|
+
if (picker) return picker({multiple: false, types: [{description: project.storageName, accept: {'*/*': ['.sb3']}}]})
|
|
123
|
+
.then(async ([handle]) => ({handle, file: await handle.getFile()}));
|
|
124
|
+
return new Promise(resolve => {
|
|
125
|
+
const input = document.createElement('input'); input.type = 'file'; input.accept = '.sb3'; input.hidden = true;
|
|
126
|
+
const finish = (value: {file: File} | null) => {input.remove(); resolve(value);};
|
|
127
|
+
input.addEventListener('change', () => finish(input.files?.[0] ? {file: input.files[0]} : null), {once: true});
|
|
128
|
+
input.addEventListener('cancel', () => finish(null), {once: true});
|
|
129
|
+
document.body.append(input); input.click();
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
const open = async (project: CatalogProject, locale: string): Promise<CatalogSource | null> => {
|
|
133
|
+
await flushPendingSurfaceEdits();
|
|
134
|
+
const folder = folders?.folder;
|
|
135
|
+
if (project.location === 'remote' || (!project.handle && project.remote && project.location !== 'browser')) {
|
|
136
|
+
if (!folders?.openRemote || !await folders.openRemote(locale, project.remote)) return null;
|
|
137
|
+
} else if (project.location === 'browser' || project.handle?.kind === 'directory') {
|
|
138
|
+
if (!folder) throw new Error('Project folders are unavailable');
|
|
139
|
+
const directory = project.browserId ? await folder.browserProjects?.root(project.browserId) : project.handle;
|
|
140
|
+
if (!directory) {
|
|
141
|
+
if (project.remote && folders?.openRemote && await folders.openRemote(locale, project.remote)) return source(project);
|
|
142
|
+
throw new DOMException('The saved folder no longer exists', 'NotFoundError');
|
|
143
|
+
}
|
|
144
|
+
await permission(directory, 'read');
|
|
145
|
+
if (project.browserId) await folder.browserProjects!.moveProjectToRoot(project.browserId);
|
|
146
|
+
if (await folder.openDirectory(directory as FileSystemDirectoryHandle, () => askReplace(locale),
|
|
147
|
+
project.repositoryRoot) !== 'opened') return null;
|
|
148
|
+
} else {
|
|
149
|
+
if (!askReplace(locale)) return null;
|
|
150
|
+
let handle = project.handle as FileSystemFileHandle | undefined;
|
|
151
|
+
let file: File;
|
|
152
|
+
if (handle) {
|
|
153
|
+
await permission(handle, 'read');
|
|
154
|
+
try {file = await handle.getFile();}
|
|
155
|
+
catch (error) {
|
|
156
|
+
if ((error as {name?: string}).name !== 'NotFoundError') throw error;
|
|
157
|
+
const chosen = await chooseFile(project);
|
|
158
|
+
if (!chosen) return null;
|
|
159
|
+
file = chosen.file; handle = chosen.handle;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
const chosen = await chooseFile(project);
|
|
164
|
+
if (!chosen) return null;
|
|
165
|
+
file = chosen.file; handle = chosen.handle;
|
|
166
|
+
}
|
|
167
|
+
if (!storage) throw new Error('File loading is unavailable');
|
|
168
|
+
vm.quit();
|
|
169
|
+
await vm.loadProject(await file.arrayBuffer(), {replaceLegacyExtensions: true});
|
|
170
|
+
folder?.detach();
|
|
171
|
+
storage.finish(handle ?? null, properties.loadedTitle?.() || file.name.replace(/\.sb3$/i, ''), true);
|
|
172
|
+
vm.renderer?.draw();
|
|
173
|
+
activeId = project.id;
|
|
174
|
+
return {location: 'file', title: title() || project.title, storageName: file.name, handle};
|
|
175
|
+
}
|
|
176
|
+
activeId = project.id;
|
|
177
|
+
return source(project);
|
|
178
|
+
};
|
|
179
|
+
const ensureOpen = async (project: CatalogProject, locale: string) => {
|
|
180
|
+
if (activeId === project.id && (await same(project.handle, folders?.folder.directory ?? ports.readFile()) ||
|
|
181
|
+
project.location === 'file' && !project.handle)) return true;
|
|
182
|
+
const opened = await open(project, locale);
|
|
183
|
+
if (!opened) return false;
|
|
184
|
+
await store.register(opened, true, project.id);
|
|
185
|
+
return true;
|
|
186
|
+
};
|
|
187
|
+
const operations = (project: CatalogProject, locale: string): CatalogOperations => {
|
|
188
|
+
const ja = locale.startsWith('ja');
|
|
189
|
+
const handle = project.handle as MutableHandle | undefined;
|
|
190
|
+
const browser = project.browserId && folders?.folder.browserProjects;
|
|
191
|
+
const noStorage = ja ? 'この保存先では名前変更・削除を実行できません。' :
|
|
192
|
+
'This storage does not support renaming or deleting the saved resource.';
|
|
193
|
+
const remoteNote = ja ? 'GitHubのリポジトリ名変更は別途対応が必要です(#681)。' :
|
|
194
|
+
'Renaming the repository on GitHub requires the rename support tracked in #681.';
|
|
195
|
+
const unsupported: CatalogOperations['unavailable'] = {renameStorage: project.location === 'remote' ? remoteNote : noStorage,
|
|
196
|
+
deleteData: project.location === 'remote' ? (ja ? 'リモートの登録は「一覧から除外」で解除できます。' :
|
|
197
|
+
'Use Remove from List to forget a remote repository.') : noStorage};
|
|
198
|
+
if (browser || handle?.move) delete unsupported.renameStorage;
|
|
199
|
+
const canDelete = Boolean((browser || handle?.remove) && activeId !== project.id);
|
|
200
|
+
if (canDelete) delete unsupported.deleteData;
|
|
201
|
+
else if (activeId === project.id) unsupported.deleteData = ja ?
|
|
202
|
+
'別の作品を開いてから、この保存データを削除してください。' : 'Open another project before deleting this saved project.';
|
|
203
|
+
let canRenameProject = project.location !== 'file' || Boolean(handle ||
|
|
204
|
+
(view as Window & {showOpenFilePicker?: unknown}).showOpenFilePicker);
|
|
205
|
+
if (!canRenameProject) unsupported.renameProject = ja ?
|
|
206
|
+
'このブラウザーでは元のSB3ファイルへ書き戻せません。開いてからコピーを保存できます。' :
|
|
207
|
+
'This browser cannot overwrite the original SB3 file. Open it and save a copy instead.';
|
|
208
|
+
if (activeId === project.id && properties.snapshot().readOnly) {
|
|
209
|
+
canRenameProject = false;
|
|
210
|
+
unsupported.renameProject = ja ? 'この作品の情報は読み取り専用です。' : 'This project information is read-only.';
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
unavailable: {...unsupported},
|
|
214
|
+
open: () => withAction(() => open(project, locale)),
|
|
215
|
+
...canRenameProject && {renameProject: (nextTitle: string) => withAction(async () => {
|
|
216
|
+
if (!await ensureOpen(project, locale)) throw new DOMException('Cancelled', 'AbortError');
|
|
217
|
+
await flushPendingSurfaceEdits();
|
|
218
|
+
const stage = vm.runtime.getTargetForStage();
|
|
219
|
+
const current = () => stage === vm.runtime.getTargetForStage();
|
|
220
|
+
properties.apply({title: nextTitle});
|
|
221
|
+
if (folders?.folder.directory) await folders.folder.save();
|
|
222
|
+
else {
|
|
223
|
+
const file = ports.readFile();
|
|
224
|
+
if (!storage || !file) throw new Error(ja ? '名前を保存するにはSB3ファイルの保存先を選択してください。' :
|
|
225
|
+
'Select a writable SB3 file to save the project title.');
|
|
226
|
+
await permission(file, 'readwrite');
|
|
227
|
+
let commit: (() => void) | undefined;
|
|
228
|
+
let edited = false;
|
|
229
|
+
const changed = () => {edited = true;};
|
|
230
|
+
vm.on?.('PROJECT_CHANGED', changed);
|
|
231
|
+
try {
|
|
232
|
+
await storage.write(file, run => withProjectSerialization(vm, {deferCommit: action => {commit = action;}}, run), current);
|
|
233
|
+
if (!current()) throw new DOMException('The project changed', 'AbortError');
|
|
234
|
+
commit?.();
|
|
235
|
+
storage.finish(file, nextTitle, !edited);
|
|
236
|
+
} finally {vm.off?.('PROJECT_CHANGED', changed);}
|
|
237
|
+
}
|
|
238
|
+
})},
|
|
239
|
+
...(browser || handle?.move ? {renameStorage: (name: string) => withAction(async () => {
|
|
240
|
+
if (!name.trim() || /[\\/\u0000-\u001f]/u.test(name) || name === '.' || name === '..') {
|
|
241
|
+
throw new Error(ja ? '保存先の名前に使えない文字が含まれています。' : 'The storage name is invalid.');
|
|
242
|
+
}
|
|
243
|
+
if (handle?.kind === 'file' && !/\.sb3$/i.test(name)) name += '.sb3';
|
|
244
|
+
if (browser) await browser.exclusive(project.browserId!, () => browser.rename(project.browserId!, name));
|
|
245
|
+
else {await permission(handle!, 'readwrite'); await handle!.move!(name);}
|
|
246
|
+
return {storageName: name, handle};
|
|
247
|
+
})} : {}),
|
|
248
|
+
...(canDelete ? {deleteData: () => withAction(async () => {
|
|
249
|
+
const currentHandle = folders?.folder.directory ?? ports.readFile();
|
|
250
|
+
if (activeId === project.id || await same(handle, currentHandle)) {
|
|
251
|
+
throw new Error(ja ? '別の作品を開いてから、この保存データを削除してください。' :
|
|
252
|
+
'Open another project before deleting this saved project.');
|
|
253
|
+
}
|
|
254
|
+
if (browser) await browser.remove(project.browserId!);
|
|
255
|
+
else {await permission(handle!, 'readwrite'); await handle!.remove!({recursive: handle!.kind === 'directory'});}
|
|
256
|
+
})} : {})
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
const host = (locale: string): CatalogHost => ({store, operations: project => operations(project, locale), async refresh() {
|
|
260
|
+
await tracking;
|
|
261
|
+
await importWorkspaceProjectHistory(store, view.indexedDB);
|
|
262
|
+
for (const entry of await folders?.folder.browserProjects?.list() ?? []) {
|
|
263
|
+
const handle = await folders!.folder.browserProjects!.root(entry.id);
|
|
264
|
+
if (!handle) continue;
|
|
265
|
+
const existing = (await store.list(true)).find(project => project.browserId === entry.id);
|
|
266
|
+
let savedTitle: string | undefined;
|
|
267
|
+
if (!existing) {
|
|
268
|
+
try {
|
|
269
|
+
const file = await (await handle.getFileHandle('project.source.json')).getFile();
|
|
270
|
+
const info = file.size <= 32 * 1024 * 1024 ? JSON.parse(await file.text())[PROJECT_INFO_KEY] : null;
|
|
271
|
+
if (info?.schemaVersion === 1 && typeof info.title === 'string') savedTitle = info.title;
|
|
272
|
+
} catch { /* A newly created or incomplete folder has no project metadata yet. */ }
|
|
273
|
+
}
|
|
274
|
+
await store.register({location: 'browser', browserId: entry.id, handle, storageName: entry.title,
|
|
275
|
+
title: existing?.title ?? savedTitle ?? entry.title,
|
|
276
|
+
remote: existing?.remote ?? await folders?.readRemote?.(handle).catch(() => undefined)}, false);
|
|
277
|
+
}
|
|
278
|
+
}});
|
|
279
|
+
schedule();
|
|
280
|
+
return {
|
|
281
|
+
store,
|
|
282
|
+
bindFolder(value: CatalogFolderPorts) {folders = value; schedule();},
|
|
283
|
+
fileOpened(file: File | null) {
|
|
284
|
+
if (!file || !/\.sb3$/i.test(file.name)) return;
|
|
285
|
+
selectedFile = {file, sequence: properties.loadState().sequence};
|
|
286
|
+
schedule();
|
|
287
|
+
},
|
|
288
|
+
capture: schedule,
|
|
289
|
+
show(locale: string, fileStorage: ProjectFileStorage, createProject?: () => void) {
|
|
290
|
+
storage = fileStorage;
|
|
291
|
+
dialog?.(); dialog = openProjectCatalog(document, {...host(locale), createProject}, locale);
|
|
292
|
+
},
|
|
293
|
+
dispose() {
|
|
294
|
+
alive = false; view.clearTimeout(timer); stopLoad(); stopLocation?.();
|
|
295
|
+
dialog?.();
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
import type {ProjectCatalogStore} from './project-catalog.js';
|
|
3
|
+
import {workspaceLayoutDatabase} from './workspace-layout-store.js';
|
|
4
|
+
|
|
5
|
+
/** Import existing handle history once per legacy record, without changing or creating a layout database. */
|
|
6
|
+
export async function importWorkspaceProjectHistory(store: ProjectCatalogStore, factory?: IDBFactory) {
|
|
7
|
+
if (!factory) return;
|
|
8
|
+
const records = await new Promise<any[]>((resolve, reject) => {
|
|
9
|
+
const request = factory.open(workspaceLayoutDatabase);
|
|
10
|
+
let missing = false;
|
|
11
|
+
request.onupgradeneeded = () => {missing = true; request.transaction!.abort();};
|
|
12
|
+
request.onerror = () => missing ? resolve([]) : reject(request.error);
|
|
13
|
+
request.onsuccess = () => {
|
|
14
|
+
const db = request.result;
|
|
15
|
+
if (!db.objectStoreNames.contains('layouts')) {db.close(); resolve([]); return;}
|
|
16
|
+
const transaction = db.transaction('layouts');
|
|
17
|
+
const read = transaction.objectStore('layouts').getAll();
|
|
18
|
+
transaction.oncomplete = () => {db.close(); resolve(read.result);};
|
|
19
|
+
transaction.onerror = transaction.onabort = () => {db.close(); reject(transaction.error);};
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
const known = await store.list(true);
|
|
23
|
+
for (const record of records) {
|
|
24
|
+
if (!Number.isSafeInteger(record.id) || !['file', 'directory'].includes(record.kind) || !record.handle ||
|
|
25
|
+
typeof record.name !== 'string' || known.some(project => project.legacyLayoutId === record.id)) continue;
|
|
26
|
+
let matched = false;
|
|
27
|
+
for (const project of known) {
|
|
28
|
+
try {if (project.handle && await record.handle.isSameEntry(project.handle)) {matched = true; break;}}
|
|
29
|
+
catch { /* A missing resource can still have a legacy record, identified by its database id. */ }
|
|
30
|
+
}
|
|
31
|
+
if (matched) continue;
|
|
32
|
+
const imported = await store.register({location: record.kind === 'file' ? 'file' : 'folder',
|
|
33
|
+
title: record.kind === 'file' ? record.name.replace(/\.sb3$/i, '') : record.name,
|
|
34
|
+
storageName: record.name, handle: record.handle, legacyLayoutId: record.id,
|
|
35
|
+
lastOpenedAt: Number.isFinite(record.lastUsedAt) ? record.lastUsedAt : null}, false);
|
|
36
|
+
known.push(imported);
|
|
37
|
+
}
|
|
38
|
+
}
|