@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,366 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import {withWaitCursor, withoutWaitCursor} from '../busy-cursor.js';
|
|
4
|
+
import {captureProjectLoad, duringProjectLoadApproval, reportProjectAssets, reportProjectFinishing}
|
|
5
|
+
from '../project-load-progress.js';
|
|
6
|
+
import type {createProjectProperties} from './properties.js';
|
|
7
|
+
import {createAuthorHistory} from './history.js';
|
|
8
|
+
import type {createProjectDialogService} from './dialog.js';
|
|
9
|
+
import {editProjectURI, getExtensionAuthoringHost, withProjectSerialization} from '@kubohiroya/turbowarp-extension-loader/scratch-vm';
|
|
10
|
+
import {createProjectDiagnostics} from './diagnostics.js';
|
|
11
|
+
import {flushPendingSurfaceEdits} from '@kubohiroya/turbowarp-plus-editor-windows/surfaces';
|
|
12
|
+
import {isValidSaveName, projectFileDialogTitle, renderExportView, renderExtensionsForm, renderSaveAsForm, saveProjectAs,
|
|
13
|
+
suggestSaveName} from '../project-file-dialogs.js';
|
|
14
|
+
import type {NewProjectChoices, NewProjectRequest, NewProjectResult, ProjectFileStorage, ExtensionStorage}
|
|
15
|
+
from '../project-file-dialogs.js';
|
|
16
|
+
import {createNewProjectHandler} from '../new-project.js';
|
|
17
|
+
import {showNotice} from '../project-notice.js';
|
|
18
|
+
import {renderProjectCommitDialog} from '@kubohiroya/turbowarp-plus-editor-git/project-commit-dialog';
|
|
19
|
+
import {renderProjectPublicationDialog} from '@kubohiroya/turbowarp-plus-editor-git/project-publication-dialog';
|
|
20
|
+
import type {PublicationCommit} from '@kubohiroya/turbowarp-plus-editor-git/project-publication';
|
|
21
|
+
import type {ProjectFolderWorkflows} from '../project-folder-workflows.js';
|
|
22
|
+
import {projectFolderOverwriteWarning} from '@kubohiroya/turbowarp-plus-editor-project-folder';
|
|
23
|
+
import type {ExtensionSpec} from '@kubohiroya/turbowarp-extension-loader';
|
|
24
|
+
import JSZip from '@turbowarp/jszip';
|
|
25
|
+
import {installProjectScreenState} from '../project-screen-state.js';
|
|
26
|
+
import type {ProjectScreenState} from '../project-screen-state.js';
|
|
27
|
+
|
|
28
|
+
export interface ProjectToolsPorts {
|
|
29
|
+
installEditorExtensionHost(vm: any, settings: any): any;
|
|
30
|
+
installProjectProperties: ReturnType<typeof createProjectProperties>;
|
|
31
|
+
createProjectDialogs: ReturnType<typeof createProjectDialogService>['createProjectDialogs'];
|
|
32
|
+
editorProjectArchives: unknown;
|
|
33
|
+
projectToolsEnabled: boolean;
|
|
34
|
+
manualProjectURIEnabled: boolean;
|
|
35
|
+
readStartupFlags(search?: string): {saveWorkspace: boolean};
|
|
36
|
+
projectLoadState(document: Document | undefined): {
|
|
37
|
+
current(): string; isShown(): boolean; subscribe(listener: () => void): () => void;
|
|
38
|
+
} | undefined;
|
|
39
|
+
}
|
|
40
|
+
/** Feature state and workflows are local to one host integration. */
|
|
41
|
+
export function createProjectTools({installEditorExtensionHost, installProjectProperties, createProjectDialogs,
|
|
42
|
+
editorProjectArchives, projectToolsEnabled: PROJECT_TOOLS_ENABLED, manualProjectURIEnabled: MANUAL_PROJECT_URI_ENABLED,
|
|
43
|
+
readStartupFlags: readWebStartupFeatureFlags, projectLoadState}: ProjectToolsPorts) {
|
|
44
|
+
const projects = new WeakMap();
|
|
45
|
+
const screenStates = new WeakMap<object, ProjectScreenState>();
|
|
46
|
+
const storageFor = document => {
|
|
47
|
+
try { return document.defaultView?.localStorage; } catch (error) { return undefined; }
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** Compose this host's project tools with its existing extension host. */
|
|
51
|
+
const installProjectToolsHost = (vm, settings: Parameters<typeof installEditorExtensionHost>[1] & Parameters<typeof installProjectProperties>[1] = {}, enabled = PROJECT_TOOLS_ENABLED) => {
|
|
52
|
+
const diagnostics = createProjectDiagnostics();
|
|
53
|
+
const document = settings.document || globalThis.document;
|
|
54
|
+
const runProjectLoad = document ? <T>(run: () => Promise<T>) => withWaitCursor([document], run) : undefined;
|
|
55
|
+
const host = installEditorExtensionHost(vm, {...settings, showDiagnostics: false, runProjectLoad,
|
|
56
|
+
projectArchives: editorProjectArchives,
|
|
57
|
+
captureProjectProgress: () => captureProjectLoad(vm),
|
|
58
|
+
waitForUser: document ? ask => duringProjectLoadApproval(vm, () => withoutWaitCursor(document, ask)) : undefined,
|
|
59
|
+
diagnostics: event => { diagnostics.record(event); settings.diagnostics?.(event); },
|
|
60
|
+
onProjectManifest: manifest => { diagnostics.describe(manifest); settings.onProjectManifest?.(manifest); }});
|
|
61
|
+
// After the extension loader's bridge, so a save replaces the screen state the loaded file carried.
|
|
62
|
+
const screenState = installProjectScreenState(vm, {Zip: JSZip,
|
|
63
|
+
save: readWebStartupFeatureFlags(settings.search ?? globalThis.location?.search).saveWorkspace});
|
|
64
|
+
screenStates.set(vm, screenState);
|
|
65
|
+
const shareArchives = 'projectIO' in host && 'supportsSharedArchive' in host.projectIO && host.projectIO.supportsSharedArchive === true;
|
|
66
|
+
const properties = installProjectProperties(vm, {...settings, metadataEnabled: enabled, runProjectLoad, shareArchives});
|
|
67
|
+
const reportAssets = (finished: number, total: number) => reportProjectAssets(vm, finished, total);
|
|
68
|
+
const finishProject = () => reportProjectFinishing(vm);
|
|
69
|
+
vm.on?.('ASSET_PROGRESS', reportAssets);
|
|
70
|
+
vm.runtime?.on?.('PROJECT_LOADED', finishProject);
|
|
71
|
+
const history = enabled ? createAuthorHistory(document ? storageFor(document) : undefined) : null;
|
|
72
|
+
const dialogs = document?.body ? createProjectDialogs(document, properties, history, diagnostics,
|
|
73
|
+
{locale: settings.locale, getLocale: settings.getLocale}) : null;
|
|
74
|
+
const tools = {dialogs, payloads: 'payloads' in host ? host.payloads : undefined, propertiesEnabled: enabled,
|
|
75
|
+
projectURIEnabled: MANUAL_PROJECT_URI_ENABLED && host.enabled, properties, projectState: settings.projectState};
|
|
76
|
+
let lastPhase;
|
|
77
|
+
const unsubscribe = properties.subscribe(() => {
|
|
78
|
+
const state = properties.loadState();
|
|
79
|
+
const key = `${state.sequence}:${state.phase}`;
|
|
80
|
+
if (lastPhase === key) return;
|
|
81
|
+
lastPhase = key;
|
|
82
|
+
if (state.phase === 'loading') diagnostics.begin();
|
|
83
|
+
else if (state.phase === 'loaded' || state.phase === 'failed') {
|
|
84
|
+
diagnostics.finish(state, state.phase === 'failed' ? state.title || '' : properties.loadedTitle() || '');
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
projects.set(vm, tools);
|
|
88
|
+
let disposal;
|
|
89
|
+
return {...host, dispose () {
|
|
90
|
+
disposal ??= (async () => {
|
|
91
|
+
vm.off?.('ASSET_PROGRESS', reportAssets);
|
|
92
|
+
vm.runtime?.off?.('PROJECT_LOADED', finishProject);
|
|
93
|
+
unsubscribe(); dialogs?.dispose(); properties.dispose(); diagnostics.dispose(); projects.delete(vm);
|
|
94
|
+
screenStates.delete(vm);
|
|
95
|
+
screenState.dispose();
|
|
96
|
+
await host.dispose();
|
|
97
|
+
})();
|
|
98
|
+
return disposal;
|
|
99
|
+
}};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** The screen state the project files keep for `vm`, once the project tools are installed. */
|
|
103
|
+
const projectScreenState = (vm): ProjectScreenState | undefined => screenStates.get(vm);
|
|
104
|
+
|
|
105
|
+
const loadedProjectTitle = vm => projects.get(vm)?.properties.loadedTitle();
|
|
106
|
+
const restoreProjectTitle = vm => projects.get(vm)?.properties.restoreTitle();
|
|
107
|
+
const isProjectLoading = vm => Boolean(projects.get(vm)?.properties.snapshot().loading);
|
|
108
|
+
const subscribeProjectLoad = (vm, listener: () => void) => projects.get(vm)?.properties.subscribe(listener);
|
|
109
|
+
/** The name the project is saved under as a folder or repository, from Project Properties; `''` when it has none. */
|
|
110
|
+
const projectSaveName = (vm): string => projects.get(vm)?.properties.snapshot().saveName ?? '';
|
|
111
|
+
const setProjectSaveName = (vm, saveName: string) => {
|
|
112
|
+
try {
|
|
113
|
+
projects.get(vm)?.properties.apply({saveName});
|
|
114
|
+
} catch {
|
|
115
|
+
// Properties that cannot be edited (an unsupported version, loading) keep their save name.
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
/** The default name of a folder or repository made from the project: its save name, or a usable title, or a slug of it. */
|
|
119
|
+
const defaultSaveName = (properties): string => {
|
|
120
|
+
const {saveName, title} = properties.snapshot();
|
|
121
|
+
if (saveName) return saveName;
|
|
122
|
+
const trimmed = (title ?? '').trim();
|
|
123
|
+
return isValidSaveName(trimmed) ? trimmed : suggestSaveName(trimmed);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const serializeProjectFolder = (vm, payloads, title?: string) =>
|
|
127
|
+
withProjectSerialization(vm, {title, preview: true}, () => {
|
|
128
|
+
const save = () => vm.saveProjectSb3('uint8array');
|
|
129
|
+
return payloads?.withEmbedded(save) ?? save();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
async function createFolderFromCurrentProject(vm, createFolder: ProjectFolderWorkflows['createFolder']) {
|
|
133
|
+
const tools = projects.get(vm);
|
|
134
|
+
if (!tools || !createFolder || tools.saving || !vm.runtime.getTargetForStage() || isProjectLoading(vm)) return false;
|
|
135
|
+
const sequence = tools.properties.loadState().sequence;
|
|
136
|
+
const current = () => projects.get(vm) === tools && tools.properties.loadState().sequence === sequence;
|
|
137
|
+
tools.saving = true;
|
|
138
|
+
try {
|
|
139
|
+
return await createFolder(() => serializeProjectFolder(vm, tools.payloads), current);
|
|
140
|
+
} finally {
|
|
141
|
+
tools.saving = false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function projectFileActions(vm, locale: string, storage: ProjectFileStorage, detachFolder: () => void, add?: () => void,
|
|
146
|
+
folderWorkflows?: ProjectFolderWorkflows) {
|
|
147
|
+
const tools = projects.get(vm);
|
|
148
|
+
if (!tools?.dialogs) return {};
|
|
149
|
+
const {dialogs, properties, payloads} = tools;
|
|
150
|
+
const ja = locale.startsWith('ja');
|
|
151
|
+
const label = (jp: string, en: string) => ja ? jp : en;
|
|
152
|
+
const publication = folderWorkflows?.publication;
|
|
153
|
+
const showPublication = publication ? (commit: PublicationCommit) =>
|
|
154
|
+
dialogs.showView(label('PR の作成・進捗', 'Pull Request'), locale,
|
|
155
|
+
(document, close) => renderProjectPublicationDialog(document, locale, publication, commit, close, () => showCommit?.())) :
|
|
156
|
+
undefined;
|
|
157
|
+
const showCommit: (() => void) | undefined = storage.canSave && folderWorkflows?.commit ? () =>
|
|
158
|
+
dialogs.showView(label('保存してコミット', 'Save and Commit'), locale,
|
|
159
|
+
(document, close) => renderProjectCommitDialog(document, locale, folderWorkflows.commit, close, showPublication)) : undefined;
|
|
160
|
+
// Save a Copy (`copy`) writes a copy and leaves the project, its file, folder and unsaved changes as they are; Save
|
|
161
|
+
// Project without a save target (`save`) makes the new file, folder or repository the project's target (#679).
|
|
162
|
+
const showSaveForm = (mode: 'copy' | 'save') => dialogs.showView(projectFileDialogTitle(mode === 'copy' ? 'save-as' : 'save', locale),
|
|
163
|
+
locale, (document, close) => {
|
|
164
|
+
const form = renderSaveAsForm(document, locale, storage, async (request, open, signal) => {
|
|
165
|
+
const {name, format} = request;
|
|
166
|
+
if (tools.saving) return false;
|
|
167
|
+
tools.saving = true;
|
|
168
|
+
const sequence = properties.loadState().sequence;
|
|
169
|
+
const current = () => open() && projects.get(vm) === tools && properties.loadState().sequence === sequence;
|
|
170
|
+
let edited = false;
|
|
171
|
+
const changed = () => {edited = true;};
|
|
172
|
+
vm.on?.('PROJECT_CHANGED', changed);
|
|
173
|
+
try {
|
|
174
|
+
if (format === 'folder') {
|
|
175
|
+
const serialize = () => serializeProjectFolder(vm, payloads, name);
|
|
176
|
+
// A new repository is opened only when the person chooses to open it at the end of the setup.
|
|
177
|
+
if (request.git) return await folderWorkflows?.repositoryCreation?.start(request.git, serialize, current, signal);
|
|
178
|
+
return mode === 'copy' ? await folderWorkflows?.copyFolder?.(serialize, current, name) :
|
|
179
|
+
await folderWorkflows?.createFolder?.(serialize, current, name);
|
|
180
|
+
}
|
|
181
|
+
let embed: (() => void) | undefined;
|
|
182
|
+
let commitMetadata: (() => void) | undefined;
|
|
183
|
+
return await saveProjectAs(storage, name, {
|
|
184
|
+
mode,
|
|
185
|
+
current,
|
|
186
|
+
collect: () => flushPendingSurfaceEdits(),
|
|
187
|
+
unchanged: () => !edited,
|
|
188
|
+
serialize(title, run) {
|
|
189
|
+
embed = format === 'embedded' ? payloads?.embedOnSave() : undefined;
|
|
190
|
+
return withProjectSerialization(vm, {title, deferCommit: commit => {commitMetadata = commit;}},
|
|
191
|
+
() => embed ? payloads.withEmbedded(run) : run());
|
|
192
|
+
},
|
|
193
|
+
committed() {
|
|
194
|
+
// A copy is not a save of the project: its properties and data formats stay unsaved.
|
|
195
|
+
if (mode === 'copy') return;
|
|
196
|
+
embed?.();
|
|
197
|
+
commitMetadata?.();
|
|
198
|
+
detachFolder();
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
} finally {
|
|
202
|
+
vm.off?.('PROJECT_CHANGED', changed);
|
|
203
|
+
tools.saving = false;
|
|
204
|
+
}
|
|
205
|
+
}, close, {
|
|
206
|
+
folder: folderWorkflows?.createFolder ? {
|
|
207
|
+
location: folderWorkflows.folderLocation,
|
|
208
|
+
overwriteWarning: projectFolderOverwriteWarning(locale),
|
|
209
|
+
github: folderWorkflows.repositoryCreation && {
|
|
210
|
+
connectForCreation: folderWorkflows.repositoryCreation.connect,
|
|
211
|
+
licenses: folderWorkflows.repositoryCreation.licenses,
|
|
212
|
+
publication: folderWorkflows.repositoryCreation
|
|
213
|
+
}
|
|
214
|
+
} : undefined,
|
|
215
|
+
openCommit: showCommit
|
|
216
|
+
});
|
|
217
|
+
// The repository name starts from the save name, as a new project's does.
|
|
218
|
+
const repository = form.querySelector<HTMLInputElement>('input[name="github-name"]');
|
|
219
|
+
if (repository && !repository.value) repository.value = defaultSaveName(properties);
|
|
220
|
+
return form;
|
|
221
|
+
});
|
|
222
|
+
const openPayloads = () => dialogs.showPayloadFormats(payloads.edit(), locale, payloads.canConvert ? () => {
|
|
223
|
+
const conversion = payloads.convert();
|
|
224
|
+
if (conversion) dialogs.showBundleAssetConversion(conversion, locale);
|
|
225
|
+
} : undefined);
|
|
226
|
+
const authoring = getExtensionAuthoringHost(vm);
|
|
227
|
+
const openExtensions = () => dialogs.showView(label('機能拡張', 'Extensions'), locale, (document, close) => {
|
|
228
|
+
let saved = new Map<string, ExtensionSpec>();
|
|
229
|
+
return renderExtensionsForm(document, locale, close, add, {
|
|
230
|
+
async list() {
|
|
231
|
+
const manifest = await authoring?.inspect();
|
|
232
|
+
saved = new Map((manifest?.extensions || []).map(spec => [spec.id, spec]));
|
|
233
|
+
const ids = new Set<string>([...saved.keys(), ...(vm.extensionManager?._loadedExtensions?.keys() || [])]);
|
|
234
|
+
return [...ids].sort().map(id => {
|
|
235
|
+
const spec = saved.get(id);
|
|
236
|
+
return {id, format: spec?.source.type, editable: Boolean(spec?.source.url)};
|
|
237
|
+
});
|
|
238
|
+
},
|
|
239
|
+
async change(changes: Map<string, ExtensionStorage>) {
|
|
240
|
+
await authoring.configure([...changes].map(([id, distribution]) => {
|
|
241
|
+
const spec = saved.get(id);
|
|
242
|
+
return {id, distribution, url: spec.source.url, execution: spec.execution,
|
|
243
|
+
version: spec.version, dependencies: [...spec.dependencies]};
|
|
244
|
+
}), {});
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
const hasProperties = tools.propertiesEnabled || tools.projectURIEnabled;
|
|
249
|
+
return {
|
|
250
|
+
saveAs: () => showSaveForm('copy'),
|
|
251
|
+
saveNew: () => showSaveForm('save'),
|
|
252
|
+
saveCommit: showCommit,
|
|
253
|
+
properties: hasProperties ?
|
|
254
|
+
() => dialogs.showProperties(locale, tools.projectURIEnabled ? editProjectURI(vm) : undefined) : undefined,
|
|
255
|
+
diagnostics: hasProperties ? undefined : () => dialogs.showDiagnostics(locale),
|
|
256
|
+
payloads: payloads?.canEdit ? openPayloads : undefined,
|
|
257
|
+
extensions: add || authoring ? openExtensions : undefined,
|
|
258
|
+
exportProject: (run: () => void) => dialogs.showView(label('書き出し', 'Export'), locale,
|
|
259
|
+
(document, close) => renderExportView(document, locale, close, run))
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Create New Project… (#679): the new project dialog's choices and its `createIn`, from the workbench's handler. This
|
|
265
|
+
* host supplies only what depends on the GUI and its storage.
|
|
266
|
+
*/
|
|
267
|
+
function projectCreation(vm, locale: string, create: () => void, folderWorkflows?: ProjectFolderWorkflows,
|
|
268
|
+
defaultTitle?: string): {createIn?: (request: NewProjectRequest, signal: AbortSignal) => Promise<NewProjectResult>;
|
|
269
|
+
newProject?: NewProjectChoices} {
|
|
270
|
+
const tools = projects.get(vm);
|
|
271
|
+
const document = globalThis.document;
|
|
272
|
+
const store = tools?.dialogs && projectLoadState(document);
|
|
273
|
+
const createFolder = folderWorkflows?.createFolder;
|
|
274
|
+
if (!tools || !store || !createFolder) return {};
|
|
275
|
+
const {properties, payloads} = tools;
|
|
276
|
+
const locations = folderWorkflows.locations ?? {browser: folderWorkflows.folderLocation === 'browser', device: false};
|
|
277
|
+
// Replaces the project with the GUI's default project, as Create New Project does, and waits until it is shown.
|
|
278
|
+
// `false` when the person kept the current project at the unsaved-changes question.
|
|
279
|
+
const openDefaultProject = async (signal: AbortSignal) => {
|
|
280
|
+
const loadingState = () => store.current();
|
|
281
|
+
const before = loadingState();
|
|
282
|
+
const sequence = properties.loadState().sequence;
|
|
283
|
+
create();
|
|
284
|
+
if (loadingState() === before) return false;
|
|
285
|
+
await new Promise<void>((resolve, reject) => {
|
|
286
|
+
let done = false;
|
|
287
|
+
const check = () => {
|
|
288
|
+
if (done) return;
|
|
289
|
+
const load = properties.loadState();
|
|
290
|
+
const failed = load.sequence > sequence && load.phase === 'failed';
|
|
291
|
+
const shown = load.sequence > sequence && load.phase === 'loaded' && store.isShown();
|
|
292
|
+
if (!signal.aborted && !failed && !shown) return;
|
|
293
|
+
done = true;
|
|
294
|
+
stopStore(); stopLoad?.(); signal.removeEventListener('abort', check);
|
|
295
|
+
if (signal.aborted) reject(signal.reason);
|
|
296
|
+
else if (failed) reject(new Error(locale.startsWith('ja') ? '新しい作品を開けませんでした。' : 'Could not open the new project.'));
|
|
297
|
+
else resolve();
|
|
298
|
+
};
|
|
299
|
+
const stopStore = store.subscribe(check);
|
|
300
|
+
const stopLoad = properties.subscribe(check);
|
|
301
|
+
signal.addEventListener('abort', check);
|
|
302
|
+
check();
|
|
303
|
+
});
|
|
304
|
+
// The GUI resets a new project's title right after showing it; name the project after that.
|
|
305
|
+
await new Promise(resolve => globalThis.setTimeout(resolve, 0));
|
|
306
|
+
return true;
|
|
307
|
+
};
|
|
308
|
+
return createNewProjectHandler({
|
|
309
|
+
locale, defaultTitle, create, openDefaultProject,
|
|
310
|
+
browserFolders: locations.browser,
|
|
311
|
+
deviceFolders: locations.device,
|
|
312
|
+
nameProject(title, saveName) {
|
|
313
|
+
try {
|
|
314
|
+
properties.apply({title, saveName});
|
|
315
|
+
} catch {
|
|
316
|
+
tools.projectState?.setTitle?.(title);
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
pickDeviceFolder: folderWorkflows.pickEmptyFolder && (() => folderWorkflows.pickEmptyFolder(locale)),
|
|
320
|
+
createFolder: (destination, title) => createFolderFromCurrentProject(vm, (serialize, current) =>
|
|
321
|
+
createFolder(serialize, current, title, destination)),
|
|
322
|
+
repositoryCreation: folderWorkflows.repositoryCreation,
|
|
323
|
+
serialize: title => serializeProjectFolder(vm, payloads, title),
|
|
324
|
+
trackProject() {
|
|
325
|
+
const sequence = properties.loadState().sequence;
|
|
326
|
+
return () => projects.get(vm) === tools && properties.loadState().sequence === sequence;
|
|
327
|
+
},
|
|
328
|
+
markSaved: folderWorkflows.markSaved,
|
|
329
|
+
notify: text => showNotice(document, text, {locale})
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** The GUI supplies its native menu components; this host owns the added entries and dialogs. */
|
|
334
|
+
const renderFileMenu = ({vm, locale = 'en', MenuSection, MenuItem, onRequestClose}) => {
|
|
335
|
+
const tools = projects.get(vm);
|
|
336
|
+
if (!tools?.dialogs) return null;
|
|
337
|
+
const open = type => {
|
|
338
|
+
onRequestClose();
|
|
339
|
+
if (type === 'properties') {
|
|
340
|
+
tools.dialogs.showProperties(locale, tools.projectURIEnabled ? editProjectURI(vm) : undefined);
|
|
341
|
+
} else if (type === 'payloads') {
|
|
342
|
+
tools.dialogs.showPayloadFormats(tools.payloads.edit(), locale);
|
|
343
|
+
} else if (type === 'bundle-assets') {
|
|
344
|
+
const conversion = tools.payloads.convert();
|
|
345
|
+
if (conversion) tools.dialogs.showBundleAssetConversion(conversion, locale);
|
|
346
|
+
} else tools.dialogs.showDiagnostics(locale);
|
|
347
|
+
};
|
|
348
|
+
const entries = [
|
|
349
|
+
['properties', '作品のプロパティ…', 'Project Properties…', tools.propertiesEnabled || tools.projectURIEnabled],
|
|
350
|
+
['payloads', '作品データの形式…', 'Project Data Formats…', tools.payloads?.canEdit],
|
|
351
|
+
['bundle-assets', 'バンドル素材を作品に追加…', 'Add Bundle Material to Project…', tools.payloads?.canConvert],
|
|
352
|
+
['diagnostics', '作品の診断…', 'Project Diagnostics…', true]
|
|
353
|
+
].filter(([, , , enabled]) => enabled);
|
|
354
|
+
return React.createElement(MenuSection, null, ...entries.map(([type, ja, en]) =>
|
|
355
|
+
React.createElement(MenuItem, {key: type, command: type, onClick: () => open(type)},
|
|
356
|
+
React.createElement('span', {role: 'button', tabIndex: 0, onKeyDown: event => {
|
|
357
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
358
|
+
event.preventDefault(); event.stopPropagation(); open(type);
|
|
359
|
+
}
|
|
360
|
+
}}, locale.startsWith('ja') ? ja : en))));
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const projectToolsOwnKeyEvent = event => Boolean(event.target?.closest?.('[data-project-tools]'));
|
|
364
|
+
|
|
365
|
+
return {installProjectToolsHost, projectScreenState, loadedProjectTitle, restoreProjectTitle, isProjectLoading, subscribeProjectLoad, projectSaveName, setProjectSaveName, createFolderFromCurrentProject, projectFileActions, projectCreation, renderFileMenu, projectToolsOwnKeyEvent};
|
|
366
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
/** Make links from plain text without interpreting project content as markup. */
|
|
3
|
+
export const contactLink = value => {
|
|
4
|
+
const text = String(value || '').trim();
|
|
5
|
+
if (/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9.-]+\.[a-z0-9-]+$/i.test(text)) return `mailto:${text}`;
|
|
6
|
+
try {
|
|
7
|
+
const url = new URL(text);
|
|
8
|
+
if (url.protocol === 'https:' && !url.username && !url.password) return url.href;
|
|
9
|
+
if (url.protocol === 'mailto:' && url.pathname && !/[\r\n]/.test(text)) return url.href;
|
|
10
|
+
} catch (error) { /* Incomplete input remains plain text. */ }
|
|
11
|
+
return null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const descriptionParts = value => {
|
|
15
|
+
const text = String(value || '');
|
|
16
|
+
const parts = [];
|
|
17
|
+
const pattern = /https:\/\/[^\s<>"'\u3000]+/g;
|
|
18
|
+
let previous = 0;
|
|
19
|
+
for (const match of text.matchAll(pattern)) {
|
|
20
|
+
let url = match[0].replace(/[.,;:!?\u3001\u3002]+$/u, '');
|
|
21
|
+
for (const [open, close] of [['(', ')'], ['[', ']'], ['{', '}'], ['(', ')'], ['「', '」'], ['『', '』']]) {
|
|
22
|
+
while (url.endsWith(close) && url.split(close).length > url.split(open).length) url = url.slice(0, -1);
|
|
23
|
+
}
|
|
24
|
+
const href = contactLink(url);
|
|
25
|
+
if (!href || !href.startsWith('https:')) continue;
|
|
26
|
+
parts.push({text: text.slice(previous, match.index)}, {text: url, href});
|
|
27
|
+
previous = match.index + url.length;
|
|
28
|
+
}
|
|
29
|
+
parts.push({text: text.slice(previous)});
|
|
30
|
+
return parts;
|
|
31
|
+
};
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
import JSZip from '@turbowarp/jszip';
|
|
3
|
+
import {beginProjectLoad} from '../project-load-progress.js';
|
|
4
|
+
import {isValidSaveName} from '../project-file-dialogs.js';
|
|
5
|
+
|
|
6
|
+
export interface ProjectArchive {
|
|
7
|
+
readonly project: Record<string, unknown>;
|
|
8
|
+
readonly projectBytes: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ProjectPropertiesPorts {
|
|
11
|
+
beginProjectArchiveRead(vm: object, input: unknown): {read: {original?: ProjectArchive}; invoke<T>(run: () => T): T} | undefined;
|
|
12
|
+
projectSerializationOptions(vm: object): {preview?: boolean; title?: string; deferCommit?(commit: () => void): void} | undefined;
|
|
13
|
+
}
|
|
14
|
+
export const PROJECT_INFO_KEY = 'turboWarpPlusProject';
|
|
15
|
+
// `saveName` names the project's folder or repository where the title cannot (#679); empty means none yet.
|
|
16
|
+
const fields = ['title', 'description', 'author', 'contact', 'saveName'];
|
|
17
|
+
const empty = () => ({schemaVersion: 1, title: '', description: '', author: '', contact: '', saveName: '',
|
|
18
|
+
createdAt: null, updatedAt: null});
|
|
19
|
+
const clone = value => JSON.parse(JSON.stringify(value));
|
|
20
|
+
const validDate = value => typeof value === 'string' && Number.isFinite(Date.parse(value)) ? value : null;
|
|
21
|
+
const maxInfoBytes = 32 * 1024 * 1024;
|
|
22
|
+
const projectInfo = project => {
|
|
23
|
+
const value = project?.[PROJECT_INFO_KEY];
|
|
24
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? clone(value) : null;
|
|
25
|
+
};
|
|
26
|
+
const archiveInfo = (archive?: ProjectArchive) =>
|
|
27
|
+
archive && archive.projectBytes <= maxInfoBytes ? projectInfo(archive.project) : null;
|
|
28
|
+
const normalize = value => ({...empty(), ...value,
|
|
29
|
+
...Object.fromEntries(fields.map(key => [key, typeof value?.[key] === 'string' ? value[key] : ''])),
|
|
30
|
+
createdAt: validDate(value?.createdAt), updatedAt: validDate(value?.updatedAt)});
|
|
31
|
+
|
|
32
|
+
/** Keep a new repository's chosen title in the saved project, including projects from ordinary SB3s. */
|
|
33
|
+
export function withProjectFolderTitle(files: ReadonlyMap<string, Uint8Array>, title: string) {
|
|
34
|
+
const path = 'project.source.json';
|
|
35
|
+
const project = JSON.parse(new TextDecoder().decode(files.get(path)));
|
|
36
|
+
const existing = projectInfo(project);
|
|
37
|
+
if (existing && existing.schemaVersion !== 1) return files;
|
|
38
|
+
if (existing?.title === title) return files;
|
|
39
|
+
project[PROJECT_INFO_KEY] = {...normalize(existing), title};
|
|
40
|
+
return new Map(files).set(path, new TextEncoder().encode(JSON.stringify(project, null, 2) + '\n'));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Read only this host's metadata. Project validation and extension manifests remain with the VM/Loader. */
|
|
44
|
+
async function readInfo(input) {
|
|
45
|
+
try {
|
|
46
|
+
let project;
|
|
47
|
+
if (typeof input === 'string') project = JSON.parse(input);
|
|
48
|
+
else if (input && typeof input === 'object' && !ArrayBuffer.isView(input) &&
|
|
49
|
+
!(input instanceof ArrayBuffer) && !(typeof Blob !== 'undefined' && input instanceof Blob)) project = input;
|
|
50
|
+
else {
|
|
51
|
+
const bytes = typeof Blob !== 'undefined' && input instanceof Blob ? await input.arrayBuffer() : input;
|
|
52
|
+
const array = bytes instanceof ArrayBuffer ? new Uint8Array(bytes) :
|
|
53
|
+
new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
54
|
+
const prefix = new TextDecoder().decode(array.subarray(0, 64)).trimStart();
|
|
55
|
+
if (prefix.startsWith('{')) return readInfo(JSON.parse(new TextDecoder().decode(array)));
|
|
56
|
+
// Old .sb/.sb2 inputs are left entirely to the VM.
|
|
57
|
+
const zip = await JSZip.loadAsync(bytes);
|
|
58
|
+
const file = zip.file('project.json');
|
|
59
|
+
if (!file || (file as typeof file & {_data?: {uncompressedSize?: number}})._data?.uncompressedSize > maxInfoBytes) return null;
|
|
60
|
+
project = JSON.parse(await file.async('string'));
|
|
61
|
+
}
|
|
62
|
+
return projectInfo(project);
|
|
63
|
+
} catch (error) { return null; }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Install after the extension persistence bridge and release before it. Serialization reads the
|
|
68
|
+
* latest native title; only completed whole-project exports advance the modification date.
|
|
69
|
+
*/
|
|
70
|
+
interface ProjectState {
|
|
71
|
+
isNew?(): boolean;
|
|
72
|
+
getTitle?(): string;
|
|
73
|
+
setTitle?(title: string): void;
|
|
74
|
+
}
|
|
75
|
+
interface LoadState {
|
|
76
|
+
phase: string;
|
|
77
|
+
sequence: number;
|
|
78
|
+
title?: string;
|
|
79
|
+
code?: string;
|
|
80
|
+
message?: string;
|
|
81
|
+
}
|
|
82
|
+
export function createProjectProperties({beginProjectArchiveRead, projectSerializationOptions}: ProjectPropertiesPorts) {
|
|
83
|
+
return function installProjectProperties(vm, {
|
|
84
|
+
projectState = {}, now = () => new Date().toISOString(), metadataEnabled = true, runProjectLoad, shareArchives = false
|
|
85
|
+
}: {projectState?: ProjectState; now?: () => string; metadataEnabled?: boolean;
|
|
86
|
+
runProjectLoad?: <T>(run: () => Promise<T>) => Promise<T>; shareArchives?: boolean} = {}) {
|
|
87
|
+
// Diagnostics observes loads even when metadata editing and serialization are disabled.
|
|
88
|
+
const names = ['loadProject', ...(metadataEnabled ?
|
|
89
|
+
['toJSON', 'saveProjectSb3', 'saveProjectSb3Stream', 'saveProjectSb3DontZip'] : [])];
|
|
90
|
+
const originals = Object.fromEntries(names.filter(name => typeof vm[name] === 'function').map(name => [name, vm[name]]));
|
|
91
|
+
const descriptors = Object.fromEntries(Object.keys(originals).map(name => [name, Object.getOwnPropertyDescriptor(vm, name)]));
|
|
92
|
+
let info = null;
|
|
93
|
+
let baseline = null;
|
|
94
|
+
let loading = 0;
|
|
95
|
+
let generation = 0;
|
|
96
|
+
let transaction = null;
|
|
97
|
+
let saveSerial = 0;
|
|
98
|
+
let lastCommittedSave = 0;
|
|
99
|
+
let disposed = false;
|
|
100
|
+
let loadQueue = Promise.resolve();
|
|
101
|
+
let loadState: LoadState = {phase: 'idle', sequence: 0};
|
|
102
|
+
const listeners = new Set<() => void>();
|
|
103
|
+
const notify = () => {
|
|
104
|
+
// Presentation subscribers cannot change the result of loading or saving a project.
|
|
105
|
+
for (const listener of listeners) { try { listener(); } catch (error) { /* Keep the project lifecycle intact. */ } }
|
|
106
|
+
};
|
|
107
|
+
const current = () => {
|
|
108
|
+
const value = normalize(info);
|
|
109
|
+
value.title = projectSerializationOptions(vm)?.title ?? projectState.getTitle?.() ?? value.title;
|
|
110
|
+
return value;
|
|
111
|
+
};
|
|
112
|
+
const fingerprint = () => {
|
|
113
|
+
const json = JSON.parse(originals.toJSON.call(vm));
|
|
114
|
+
delete json[PROJECT_INFO_KEY];
|
|
115
|
+
delete json.meta;
|
|
116
|
+
const value = current();
|
|
117
|
+
return JSON.stringify([json, fields.map(key => value[key])]);
|
|
118
|
+
};
|
|
119
|
+
const commit = receipt => {
|
|
120
|
+
if (disposed || receipt.generation !== generation || receipt.serial < lastCommittedSave) return;
|
|
121
|
+
lastCommittedSave = receipt.serial;
|
|
122
|
+
// Applying properties or editing blocks during compression must remain unsaved.
|
|
123
|
+
if (JSON.stringify(info) === receipt.previous || receipt.fingerprint === fingerprint()) info = receipt.info;
|
|
124
|
+
baseline = receipt.fingerprint;
|
|
125
|
+
notify();
|
|
126
|
+
};
|
|
127
|
+
const save = (original, args, stream = false) => {
|
|
128
|
+
if (loading) throw new Error('Wait for project loading to finish before saving');
|
|
129
|
+
const options = projectSerializationOptions(vm);
|
|
130
|
+
if (options?.preview) return original.apply(vm, args);
|
|
131
|
+
const print = fingerprint();
|
|
132
|
+
const value = info?.schemaVersion === 1 ? current() : info;
|
|
133
|
+
const receipt = {generation, serial: ++saveSerial, fingerprint: print, previous: JSON.stringify(info),
|
|
134
|
+
info: value ? {...value} : null};
|
|
135
|
+
if (receipt.info?.schemaVersion === 1 && print !== baseline) receipt.info.updatedAt = now();
|
|
136
|
+
transaction = receipt;
|
|
137
|
+
let result;
|
|
138
|
+
try { result = original.apply(vm, args); } finally { transaction = null; }
|
|
139
|
+
if (options?.deferCommit) {
|
|
140
|
+
options.deferCommit(() => commit(receipt));
|
|
141
|
+
} else if (stream) {
|
|
142
|
+
result.on('end', () => commit(receipt));
|
|
143
|
+
} else if (result && typeof result.then === 'function') {
|
|
144
|
+
return result.then(output => { commit(receipt); return output; });
|
|
145
|
+
} else commit(receipt);
|
|
146
|
+
return result;
|
|
147
|
+
};
|
|
148
|
+
const wrappers = {
|
|
149
|
+
loadProject(input, ...args) {
|
|
150
|
+
if (disposed) return Promise.reject(new Error('Project properties were disposed'));
|
|
151
|
+
loading++;
|
|
152
|
+
const progress = beginProjectLoad(vm, input);
|
|
153
|
+
const archive = shareArchives ? beginProjectArchiveRead(vm, input) : undefined;
|
|
154
|
+
const isNew = projectState.isNew?.() === true;
|
|
155
|
+
// The authoring controller identifies its own load in the synchronous start callback.
|
|
156
|
+
// Metadata reading must not defer that callback beyond the caller's ownership scope.
|
|
157
|
+
let nativeLoad;
|
|
158
|
+
const load = () => originals.loadProject.call(vm, input, ...args);
|
|
159
|
+
const invoke = () => archive ? archive.invoke(load) : load();
|
|
160
|
+
try { nativeLoad = progress ? progress.invoke(invoke) : invoke(); }
|
|
161
|
+
catch (error) { nativeLoad = Promise.reject(error); }
|
|
162
|
+
const settled = Promise.resolve(nativeLoad).then(value => ({value}), error => ({error, failed: true}));
|
|
163
|
+
const run = async () => {
|
|
164
|
+
if (disposed) throw new Error('Project properties were disposed');
|
|
165
|
+
const sequence = ++generation;
|
|
166
|
+
loadState = {phase: 'loading', sequence};
|
|
167
|
+
notify();
|
|
168
|
+
let loaded = metadataEnabled && !archive ? await readInfo(input) : null;
|
|
169
|
+
try {
|
|
170
|
+
if (disposed) throw new Error('Project properties were disposed');
|
|
171
|
+
const outcome = await settled;
|
|
172
|
+
if (metadataEnabled && archive) {
|
|
173
|
+
if (archive.read.original) loaded = archiveInfo(archive.read.original);
|
|
174
|
+
else if (!('failed' in outcome)) loaded = await readInfo(input);
|
|
175
|
+
}
|
|
176
|
+
if ('failed' in outcome) throw outcome.error;
|
|
177
|
+
const result = outcome.value;
|
|
178
|
+
if (disposed) return result;
|
|
179
|
+
if (metadataEnabled) {
|
|
180
|
+
info = loaded || (isNew ? {...empty(), createdAt: now()} : null);
|
|
181
|
+
if (info?.schemaVersion === 1 && info.title) projectState.setTitle?.(info.title);
|
|
182
|
+
baseline = fingerprint();
|
|
183
|
+
}
|
|
184
|
+
loadState = {phase: 'loaded', sequence};
|
|
185
|
+
notify();
|
|
186
|
+
return result;
|
|
187
|
+
} catch (error) {
|
|
188
|
+
loadState = {phase: 'failed', sequence, title: loaded?.title,
|
|
189
|
+
code: error.code, message: error.message || String(error)};
|
|
190
|
+
notify();
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
const result = loadQueue.then(() => runProjectLoad ? runProjectLoad(run) : run());
|
|
195
|
+
loadQueue = result.catch(() => {});
|
|
196
|
+
return result.finally(() => {
|
|
197
|
+
loading--;
|
|
198
|
+
progress?.finish();
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
toJSON(...args) {
|
|
202
|
+
const raw = originals.toJSON.apply(vm, args);
|
|
203
|
+
if (args[0]) return raw;
|
|
204
|
+
const value = transaction ? transaction.info : info?.schemaVersion === 1 ? current() : info;
|
|
205
|
+
if (!value) return raw;
|
|
206
|
+
return JSON.stringify({...JSON.parse(raw), [PROJECT_INFO_KEY]: value});
|
|
207
|
+
},
|
|
208
|
+
saveProjectSb3(...args) { return save(originals.saveProjectSb3, args); },
|
|
209
|
+
saveProjectSb3Stream(...args) { return save(originals.saveProjectSb3Stream, args, true); },
|
|
210
|
+
saveProjectSb3DontZip(...args) { return save(originals.saveProjectSb3DontZip, args); }
|
|
211
|
+
};
|
|
212
|
+
for (const name of Object.keys(originals)) vm[name] = wrappers[name];
|
|
213
|
+
return {
|
|
214
|
+
snapshot: () => ({...current(), readOnly: Boolean(info && info.schemaVersion !== 1), loading: loading > 0}),
|
|
215
|
+
loadState: () => ({...loadState}),
|
|
216
|
+
subscribe (listener) { listeners.add(listener); return () => listeners.delete(listener); },
|
|
217
|
+
loadedTitle: () => info?.schemaVersion === 1 && typeof info.title === 'string' && info.title ? info.title : undefined,
|
|
218
|
+
restoreTitle () { const title = this.loadedTitle(); if (title !== undefined) projectState.setTitle?.(title); },
|
|
219
|
+
apply (draft) {
|
|
220
|
+
if (!metadataEnabled || disposed || loading || (info && info.schemaVersion !== 1)) {
|
|
221
|
+
throw new Error('Project properties are not editable');
|
|
222
|
+
}
|
|
223
|
+
const previous = current();
|
|
224
|
+
const next = {...previous, ...Object.fromEntries(fields.map(key =>
|
|
225
|
+
[key, String(draft[key] ?? previous[key])]))};
|
|
226
|
+
next.title = next.title.slice(0, 100);
|
|
227
|
+
next.author = next.author.trim(); next.contact = next.contact.trim(); next.saveName = next.saveName.trim();
|
|
228
|
+
if (next.saveName && !isValidSaveName(next.saveName)) {
|
|
229
|
+
throw Object.assign(new Error('The save name is not valid'), {code: 'INVALID_SAVE_NAME'});
|
|
230
|
+
}
|
|
231
|
+
if (fields.every(key => next[key] === previous[key])) return false;
|
|
232
|
+
info = next;
|
|
233
|
+
projectState.setTitle?.(next.title);
|
|
234
|
+
vm.runtime?.emitProjectChanged?.();
|
|
235
|
+
notify();
|
|
236
|
+
return true;
|
|
237
|
+
},
|
|
238
|
+
dispose () {
|
|
239
|
+
disposed = true;
|
|
240
|
+
generation++;
|
|
241
|
+
listeners.clear();
|
|
242
|
+
for (const [name, original] of Object.entries(originals)) {
|
|
243
|
+
if (vm[name] !== wrappers[name]) continue;
|
|
244
|
+
if (descriptors[name]) Object.defineProperty(vm, name, {...descriptors[name], value: original});
|
|
245
|
+
else delete vm[name];
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
}
|