@lvce-editor/main-area-worker 9.67.4 → 9.67.6

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.
@@ -1531,7 +1531,7 @@ const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
1531
1531
  const readFile = async uri => {
1532
1532
  return invoke$2('FileSystem.readFile', uri);
1533
1533
  };
1534
- const confirm$1 = async (message, options) => {
1534
+ const confirm = async (message, options) => {
1535
1535
  const result = await invoke$2('ConfirmPrompt.prompt', message, options);
1536
1536
  return result;
1537
1537
  };
@@ -2088,18 +2088,31 @@ const createViewletForTab = (state, tabId, viewletModuleId, bounds) => {
2088
2088
  return newState;
2089
2089
  };
2090
2090
 
2091
- /**
2092
- * Called when switching tabs.
2093
- * With reference nodes, attachment/detachment is handled automatically by virtual DOM rendering.
2094
- * No attach/detach commands needed - virtual DOM will render the correct reference at each position.
2095
- */
2096
- const switchViewlet = (state, fromTabId, toTabId) => {
2097
- // No commands needed - virtual DOM reference nodes handle attachment automatically
2098
- // Virtual DOM will:
2099
- // 1. Remove the old reference node from the previous active tab
2100
- // 2. Add the new reference node for the now-active tab
2101
- // This achieves the same effect as detach/attach without explicit commands
2091
+ const findTabById = (state, tabId) => {
2092
+ const {
2093
+ layout
2094
+ } = state;
2095
+ const {
2096
+ groups
2097
+ } = layout;
2098
+ for (const group of groups) {
2099
+ const tab = group.tabs.find(t => t.id === tabId);
2100
+ if (tab) {
2101
+ return {
2102
+ groupId: group.id,
2103
+ tab
2104
+ };
2105
+ }
2106
+ }
2107
+ return undefined;
2108
+ };
2102
2109
 
2110
+ const switchViewlet = async (state, fromTabId, toTabId) => {
2111
+ const previous = fromTabId === undefined ? undefined : findTabById(state, fromTabId)?.tab;
2112
+ if (fromTabId !== toTabId && previous && previous.editorUid >= 0 && previous.loadingState === 'loaded' && previous.editorInput?.type === 'editor') {
2113
+ // Browsers do not consistently emit blur when a focused editor reference is detached.
2114
+ await invoke$1(state.applicationId, 'Viewlet.executeViewletCommand', previous.editorUid, 'handleBlur');
2115
+ }
2103
2116
  return {
2104
2117
  commands: [],
2105
2118
  newState: state
@@ -2295,19 +2308,8 @@ const saveEditor = async (editorUid, skipFormatting = false) => {
2295
2308
  return invoke$2('Editor.save', editorUid);
2296
2309
  };
2297
2310
 
2298
- const confirm = async (message, options) => {
2299
- try {
2300
- return await confirm$1(message, options);
2301
- } catch (error) {
2302
- const errorMessage = String(error);
2303
- if (!errorMessage.includes('ConfirmPrompt.prompt') || !errorMessage.includes('not found')) {
2304
- throw error;
2305
- }
2306
- return invoke$6('ConfirmPrompt.prompt', message, options);
2307
- }
2308
- };
2309
- const promptSave = async title => {
2310
- const shouldSave = await confirm(`Do you want to save the changes you made to ${title}?`, {
2311
+ const promptLegacy = async (message, discardPrompt) => {
2312
+ const shouldSave = await confirm(message, {
2311
2313
  cancelMessage: 'More Options',
2312
2314
  confirmMessage: 'Save',
2313
2315
  title: 'Save Changes'
@@ -2315,13 +2317,47 @@ const promptSave = async title => {
2315
2317
  if (shouldSave) {
2316
2318
  return 'save';
2317
2319
  }
2318
- const shouldDiscard = await confirm(`Discard the changes you made to ${title}?`, {
2320
+ const shouldDiscard = await confirm(discardPrompt, {
2319
2321
  cancelMessage: 'Cancel',
2320
2322
  confirmMessage: "Don't Save",
2321
2323
  title: 'Save Changes'
2322
2324
  });
2323
2325
  return shouldDiscard ? 'discard' : 'cancel';
2324
2326
  };
2327
+ const promptSave = async title => {
2328
+ const message = `Do you want to save the changes you made to ${title}?`;
2329
+ const discardPrompt = `Discard the changes you made to ${title}?`;
2330
+ const options = {
2331
+ cancelMessage: 'Cancel',
2332
+ confirmMessage: 'Save',
2333
+ discardMessage: "Don't Save",
2334
+ discardPrompt,
2335
+ title: 'Save Changes'
2336
+ };
2337
+ try {
2338
+ const result = await invoke$2('ConfirmPrompt.prompt3', message, options);
2339
+ if (['cancel', 'discard', 'save'].includes(result)) {
2340
+ return result;
2341
+ }
2342
+ } catch (error) {
2343
+ const errorMessage = String(error);
2344
+ if (!errorMessage.includes('ConfirmPrompt.prompt3') || !errorMessage.includes('not found')) {
2345
+ throw error;
2346
+ }
2347
+ }
2348
+ try {
2349
+ const result = await invoke$6('ConfirmPrompt.prompt3', message, options);
2350
+ if (['cancel', 'discard', 'save'].includes(result)) {
2351
+ return result;
2352
+ }
2353
+ } catch (error) {
2354
+ const errorMessage = String(error);
2355
+ if (!errorMessage.includes('ConfirmPrompt.prompt3') || !errorMessage.includes('not found')) {
2356
+ throw error;
2357
+ }
2358
+ }
2359
+ return promptLegacy(message, discardPrompt);
2360
+ };
2325
2361
  const canCloseTab = async tab => {
2326
2362
  if (tab.editorUid === -1 || !tab.isDirty) {
2327
2363
  return true;
@@ -3098,25 +3134,6 @@ const getUpdatedGroups = (groups, groupIndex, needsLoading, tabId) => {
3098
3134
  });
3099
3135
  };
3100
3136
 
3101
- const findTabById = (state, tabId) => {
3102
- const {
3103
- layout
3104
- } = state;
3105
- const {
3106
- groups
3107
- } = layout;
3108
- for (const group of groups) {
3109
- const tab = group.tabs.find(t => t.id === tabId);
3110
- if (tab) {
3111
- return {
3112
- groupId: group.id,
3113
- tab
3114
- };
3115
- }
3116
- }
3117
- return undefined;
3118
- };
3119
-
3120
3137
  const getSegmentSize = segment => {
3121
3138
  return segment.groups.reduce((total, group) => total + group.size, 0);
3122
3139
  };
@@ -3383,7 +3400,7 @@ const selectTab = async (state, groupIndex, index) => {
3383
3400
  if (isAlreadyActive && !shouldLoadContentForTab(normalizedTab)) {
3384
3401
  return state;
3385
3402
  }
3386
- getActiveTabId$1(state);
3403
+ const previousTabId = getActiveTabId$1(state);
3387
3404
  const needsLoading = shouldLoadContentForTab(normalizedTab);
3388
3405
  const requestId = needsLoading ? getNextRequestId() : 0;
3389
3406
  const updatedGroups = getUpdatedGroups(groups, groupIndex, needsLoading, tabId);
@@ -3398,7 +3415,7 @@ const selectTab = async (state, groupIndex, index) => {
3398
3415
  const {
3399
3416
  commands: switchCommands,
3400
3417
  newState: stateWithViewlet
3401
- } = switchViewlet(newState);
3418
+ } = await switchViewlet(newState, previousTabId, tabId);
3402
3419
  newState = stateWithViewlet;
3403
3420
  const maybeCreatedState = await maybeCreateViewletForSelectedTab(state, newState, groupIndex, index, tabId, normalizedTab, uid, needsLoading, requestId, switchCommands);
3404
3421
  if (maybeCreatedState) {
@@ -3408,6 +3425,9 @@ const selectTab = async (state, groupIndex, index) => {
3408
3425
  if (switchCommands.length > 0) {
3409
3426
  await executeViewletCommands(switchCommands);
3410
3427
  }
3428
+ if (!needsLoading) {
3429
+ await focus(newState);
3430
+ }
3411
3431
  return maybeStartLoading(state, newState, tabId, normalizedTab, needsLoading, requestId);
3412
3432
  };
3413
3433
 
@@ -5582,7 +5602,7 @@ const openInputWithContext = async (context, options) => {
5582
5602
  let intermediateState = stateWithViewlet;
5583
5603
  const {
5584
5604
  newState: switchedState
5585
- } = switchViewlet(intermediateState, previousTabId, tabId);
5605
+ } = await switchViewlet(intermediateState, previousTabId, tabId);
5586
5606
  intermediateState = switchedState;
5587
5607
  await context.updateState(() => intermediateState);
5588
5608
  const tabWithViewlet = findTabById(intermediateState, tabId);
@@ -6959,7 +6979,7 @@ const newFile = async state => {
6959
6979
  }
6960
6980
 
6961
6981
  // Get previous active tab ID for viewlet switching
6962
- getActiveTabId(newState);
6982
+ const previousTabId = getActiveTabId(newState);
6963
6983
 
6964
6984
  // Create a new empty tab
6965
6985
  const tabId = create$2();
@@ -6989,7 +7009,7 @@ const newFile = async state => {
6989
7009
  // Switch viewlet (detach old, attach new if ready)
6990
7010
  const {
6991
7011
  newState: switchedState
6992
- } = switchViewlet(intermediateState);
7012
+ } = await switchViewlet(intermediateState, previousTabId, tabId);
6993
7013
  intermediateState = switchedState;
6994
7014
  set$1(uid, state, intermediateState);
6995
7015
 
@@ -9103,8 +9123,25 @@ const setEditorLayoutTwoColumnsBottom = state => {
9103
9123
  }]);
9104
9124
  };
9105
9125
 
9126
+ const splitEditorGroupAndResize = async (state, split, ...args) => {
9127
+ const newState = split(state, ...args);
9128
+ if (newState === state) {
9129
+ return state;
9130
+ }
9131
+ await handleResize(newState, newState);
9132
+ const editorUids = newState.layout.groups.flatMap(group => group.tabs.map(tab => tab.editorUid).filter(editorUid => editorUid !== -1));
9133
+ for (const editorUid of editorUids) {
9134
+ await invoke$2('Viewlet.requestRender', editorUid);
9135
+ }
9136
+ return newState;
9137
+ };
9138
+
9106
9139
  const pendingLoads = new Map();
9107
9140
  const loadContent = wrapSerialCommand(loadContent$1);
9141
+ const splitDownAndResize = wrapSerialCommand((state, ...args) => splitEditorGroupAndResize(state, splitDown, ...args));
9142
+ const splitLeftAndResize = wrapSerialCommand((state, ...args) => splitEditorGroupAndResize(state, splitLeft, ...args));
9143
+ const splitRightAndResize = wrapSerialCommand((state, ...args) => splitEditorGroupAndResize(state, splitRight, ...args));
9144
+ const splitUpAndResize = wrapSerialCommand((state, ...args) => splitEditorGroupAndResize(state, splitUp, ...args));
9108
9145
  const loadContentTracked = async (uid, ...args) => {
9109
9146
  const loading = loadContent(uid, ...args);
9110
9147
  pendingLoads.set(uid, loading);
@@ -9159,7 +9196,7 @@ const commandMap = {
9159
9196
  'Main.restoreClosedTab': wrapSerialCommand(restoreClosedTab),
9160
9197
  'Main.save': wrapSerialCommand(save),
9161
9198
  'Main.saveState': wrapGetter(saveState),
9162
- 'Main.splitRight': wrapSerialCommand(splitRight),
9199
+ 'Main.splitRight': splitRightAndResize,
9163
9200
  'MainArea.closeActiveEditor': wrapSerialCommand(closeActiveEditor),
9164
9201
  'MainArea.closeAll': wrapSerialCommand(closeAll$1),
9165
9202
  'MainArea.closeAllEditors': wrapSerialCommand(closeAll$1),
@@ -9251,10 +9288,10 @@ const commandMap = {
9251
9288
  'MainArea.setEditorLayoutTwoColumnsBottom': wrapSerialCommand(setEditorLayoutTwoColumnsBottom),
9252
9289
  'MainArea.setEditorLayoutTwoRows': wrapSerialCommand(setEditorLayoutTwoRows),
9253
9290
  'MainArea.setEditorLayoutTwoRowsRight': wrapSerialCommand(setEditorLayoutTwoRowsRight),
9254
- 'MainArea.splitDown': wrapSerialCommand(splitDown),
9255
- 'MainArea.splitLeft': wrapSerialCommand(splitLeft),
9256
- 'MainArea.splitRight': wrapSerialCommand(splitRight),
9257
- 'MainArea.splitUp': wrapSerialCommand(splitUp),
9291
+ 'MainArea.splitDown': splitDownAndResize,
9292
+ 'MainArea.splitLeft': splitLeftAndResize,
9293
+ 'MainArea.splitRight': splitRightAndResize,
9294
+ 'MainArea.splitUp': splitUpAndResize,
9258
9295
  'MainArea.terminate': terminate
9259
9296
  };
9260
9297
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.67.4",
3
+ "version": "9.67.6",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",