@lvce-editor/main-area-worker 9.70.0 → 9.71.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.
@@ -1934,6 +1934,7 @@ const withActiveEditorChangeAsync = fn => {
1934
1934
 
1935
1935
  const registry = create$4();
1936
1936
  const {
1937
+ dispose: dispose$1,
1937
1938
  get: get$1,
1938
1939
  getCommandIds,
1939
1940
  getKeys: getKeys$1,
@@ -2911,6 +2912,16 @@ const diff2 = uid => {
2911
2912
  return result;
2912
2913
  };
2913
2914
 
2915
+ const dispose = async uid => {
2916
+ const instance = get$1(uid);
2917
+ if (!instance) {
2918
+ return;
2919
+ }
2920
+ const editorUids = instance.newState.layout.groups.flatMap(group => group.tabs.map(tab => tab.editorUid).filter(id => id !== -1));
2921
+ dispose$1(uid);
2922
+ await disposeEditors(editorUids);
2923
+ };
2924
+
2914
2925
  const state = {
2915
2926
  connected: false
2916
2927
  };
@@ -8091,6 +8102,163 @@ const initialize$1 = async () => {
8091
8102
  // Kept as a compatibility command for existing renderer startup code.
8092
8103
  };
8093
8104
 
8105
+ const isCurrent = context => {
8106
+ const state = context.getState();
8107
+ return !state.disposed && get$1(state.uid)?.newState === state;
8108
+ };
8109
+ const renderPending = async context => {
8110
+ if (!isCurrent(context)) {
8111
+ return;
8112
+ }
8113
+ const {
8114
+ applicationId,
8115
+ uid
8116
+ } = context.getState();
8117
+ await invoke$1(applicationId, 'Layout.renderMainAreaPending', uid);
8118
+ };
8119
+ const loadRestoredTab = async (context, tab) => {
8120
+ const isPending = () => {
8121
+ const latestTab = findTabById(context.getState(), tab.id)?.tab;
8122
+ return isCurrent(context) && latestTab?.editorUid === tab.editorUid && latestTab.loadingState === 'loading';
8123
+ };
8124
+ try {
8125
+ const state = context.getState();
8126
+ const moduleId = await getViewletModuleIdForEditorInput(tab.editorInput, state.applicationId);
8127
+ if (!isPending()) {
8128
+ return;
8129
+ }
8130
+ if (!moduleId) {
8131
+ throw new Error('Could not determine editor type for this URI');
8132
+ }
8133
+ const latestState = context.getState();
8134
+ const location = findTabById(latestState, tab.id);
8135
+ const bounds = getSelectedTabBounds(latestState, location.groupId);
8136
+ await createViewletContent(moduleId, tab.editorUid, tab.id, bounds, tab.uri, [{
8137
+ focus: false
8138
+ }], state.applicationId);
8139
+ if (!isPending()) {
8140
+ await disposeEditors([tab.editorUid]);
8141
+ return;
8142
+ }
8143
+ const beforeReady = context.getState();
8144
+ const readyState = await context.updateState(current => handleViewletReady(current, tab.editorUid));
8145
+ await notifyActiveEditorChange(beforeReady, readyState);
8146
+ await notifyMountedViewlets(beforeReady, readyState);
8147
+ await renderPending(context);
8148
+ // Optional metadata must never hold up editor readiness or another group.
8149
+ const title = await getViewletTitle(tab.editorUid);
8150
+ if (!isCurrent(context) || findTabById(context.getState(), tab.id)?.tab.editorUid !== tab.editorUid) {
8151
+ return;
8152
+ }
8153
+ if (title) {
8154
+ await context.updateState(current => handleViewletReady(current, tab.editorUid, title));
8155
+ }
8156
+ await renderPending(context);
8157
+ } catch (error) {
8158
+ if (!isPending()) {
8159
+ return;
8160
+ }
8161
+ await disposeEditors([tab.editorUid]);
8162
+ await context.updateState(current => updateTab(current, tab.id, {
8163
+ editorUid: -1,
8164
+ errorMessage: error instanceof Error ? error.message : 'Failed to restore editor',
8165
+ loadingState: 'error'
8166
+ }));
8167
+ await renderPending(context);
8168
+ }
8169
+ };
8170
+ const loadHomeDir = async context => {
8171
+ const homeDirUri = await loadHomeDirUri(context.getState().applicationId);
8172
+ if (!isCurrent(context)) {
8173
+ return;
8174
+ }
8175
+ await context.updateState(state => updateTabUriTitles({
8176
+ ...state,
8177
+ homeDirUri
8178
+ }));
8179
+ await renderPending(context);
8180
+ };
8181
+ const loadIcons = async context => {
8182
+ const {
8183
+ fileIconCache,
8184
+ updatedLayout
8185
+ } = await loadFileIcons(context.getState());
8186
+ if (!isCurrent(context)) {
8187
+ return;
8188
+ }
8189
+ const icons = new Map(updatedLayout.groups.flatMap(group => group.tabs.map(tab => [tab.id, tab])));
8190
+ // Metadata completion must not restore an obsolete layout or tab selection.
8191
+ await context.updateState(state => ({
8192
+ ...state,
8193
+ fileIconCache: {
8194
+ ...state.fileIconCache,
8195
+ ...fileIconCache
8196
+ },
8197
+ layout: {
8198
+ ...state.layout,
8199
+ groups: state.layout.groups.map(group => ({
8200
+ ...group,
8201
+ tabs: group.tabs.map(tab => {
8202
+ const restored = icons.get(tab.id);
8203
+ return restored && restored.uri === tab.uri ? {
8204
+ ...tab,
8205
+ icon: restored.icon
8206
+ } : tab;
8207
+ })
8208
+ }))
8209
+ }
8210
+ }));
8211
+ await renderPending(context);
8212
+ };
8213
+ const loadContentLater = async context => {
8214
+ const state = context.getState();
8215
+ // Older renderers discover this lifecycle hook but still use loadContent.
8216
+ if (state.pendingRestoreTabIds === undefined) {
8217
+ return;
8218
+ }
8219
+ const pendingIds = new Set(state.pendingRestoreTabIds);
8220
+ const tabs = state.layout.groups.flatMap(group => group.tabs.filter(tab => pendingIds.has(tab.id) && tab.loadingState === 'loading'));
8221
+ await context.updateState(current => ({
8222
+ ...current,
8223
+ pendingRestoreTabIds: []
8224
+ }));
8225
+ await Promise.all([loadHomeDir(context), loadIcons(context), ...tabs.map(tab => loadRestoredTab(context, tab))]);
8226
+ };
8227
+
8228
+ // Restore the shell without depending on any editor, workspace, or icon RPC.
8229
+ const loadContentShell = (state, savedState) => {
8230
+ const layout = tryRestoreLayout(savedState) ?? {
8231
+ activeGroupId: -1,
8232
+ direction: Horizontal,
8233
+ groups: []
8234
+ };
8235
+ const {
8236
+ groups
8237
+ } = layout;
8238
+ reserve(groups.flatMap(group => [group.id, ...group.tabs.map(tab => tab.id)]));
8239
+ return updateTabUriTitles({
8240
+ ...state,
8241
+ initial: false,
8242
+ layout: {
8243
+ ...layout,
8244
+ groups: groups.map(group => ({
8245
+ ...group,
8246
+ tabs: group.tabs.map(tab => {
8247
+ if (tab.id !== group.activeTabId || !tab.uri || tab.loadingState === 'binary') {
8248
+ return tab;
8249
+ }
8250
+ return {
8251
+ ...tab,
8252
+ editorUid: create$2(),
8253
+ loadingState: 'loading'
8254
+ };
8255
+ })
8256
+ }))
8257
+ },
8258
+ pendingRestoreTabIds: groups.flatMap(group => group.tabs.filter(tab => tab.id === group.activeTabId && tab.uri && tab.loadingState !== 'binary').map(tab => tab.id))
8259
+ });
8260
+ };
8261
+
8094
8262
  const hasTargetGroup = groupId => {
8095
8263
  return groupId !== undefined && groupId >= 0;
8096
8264
  };
@@ -9305,6 +9473,7 @@ const commandMap = {
9305
9473
  'MainArea.copyRelativePath': wrapSerialCommand(copyRelativePath$1),
9306
9474
  'MainArea.create': create$1,
9307
9475
  'MainArea.diff2': diff2,
9476
+ 'MainArea.dispose': dispose,
9308
9477
  'MainArea.flipEditorLayout': wrapSerialCommand(flipLayout),
9309
9478
  'MainArea.focus': wrapSerialCommand(focus),
9310
9479
  'MainArea.focusNext': wrapSerialCommand(focusNextTab),
@@ -9312,7 +9481,8 @@ const commandMap = {
9312
9481
  'MainArea.focusPrevious': wrapSerialCommand(focusPreviousTab),
9313
9482
  'MainArea.focusPreviousTab': wrapSerialCommand(focusPreviousTab),
9314
9483
  'MainArea.getActiveEditorUid': wrapGetter(getActiveEditorUid),
9315
- 'MainArea.getCommandIds': getCommandIds,
9484
+ // Lifecycle hooks require an explicit renderer adapter, not command discovery.
9485
+ 'MainArea.getCommandIds': () => getCommandIds().filter(id => id !== 'loadContentLater'),
9316
9486
  'MainArea.getComponentDom': getComponentDom,
9317
9487
  'MainArea.getComponentState': getComponentState,
9318
9488
  'MainArea.getMenuEntries': wrapGetter(getMenuEntries),
@@ -9356,6 +9526,11 @@ const commandMap = {
9356
9526
  'MainArea.hasDirtyTabs': wrapGetter(hasDirtyTabs),
9357
9527
  'MainArea.initialize': initialize$1,
9358
9528
  'MainArea.loadContent': loadContentTracked,
9529
+ 'MainArea.loadContentLater': wrapAsyncCommand(loadContentLater),
9530
+ 'MainArea.loadContentShell': (uid, savedState) => {
9531
+ const instance = get$1(uid);
9532
+ set$1(uid, instance.oldState, loadContentShell(instance.newState, savedState));
9533
+ },
9359
9534
  'MainArea.moveIntoNewWindow': wrapSerialCommand(moveIntoNewWindow),
9360
9535
  'MainArea.newFile': wrapSerialCommand(newFile),
9361
9536
  'MainArea.newWindow': wrapSerialCommand(newWindow),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.70.0",
3
+ "version": "9.71.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",