@lvce-editor/main-area-worker 9.67.3 → 9.67.5

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.
@@ -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
@@ -3098,25 +3111,6 @@ const getUpdatedGroups = (groups, groupIndex, needsLoading, tabId) => {
3098
3111
  });
3099
3112
  };
3100
3113
 
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
3114
  const getSegmentSize = segment => {
3121
3115
  return segment.groups.reduce((total, group) => total + group.size, 0);
3122
3116
  };
@@ -3383,7 +3377,7 @@ const selectTab = async (state, groupIndex, index) => {
3383
3377
  if (isAlreadyActive && !shouldLoadContentForTab(normalizedTab)) {
3384
3378
  return state;
3385
3379
  }
3386
- getActiveTabId$1(state);
3380
+ const previousTabId = getActiveTabId$1(state);
3387
3381
  const needsLoading = shouldLoadContentForTab(normalizedTab);
3388
3382
  const requestId = needsLoading ? getNextRequestId() : 0;
3389
3383
  const updatedGroups = getUpdatedGroups(groups, groupIndex, needsLoading, tabId);
@@ -3398,7 +3392,7 @@ const selectTab = async (state, groupIndex, index) => {
3398
3392
  const {
3399
3393
  commands: switchCommands,
3400
3394
  newState: stateWithViewlet
3401
- } = switchViewlet(newState);
3395
+ } = await switchViewlet(newState, previousTabId, tabId);
3402
3396
  newState = stateWithViewlet;
3403
3397
  const maybeCreatedState = await maybeCreateViewletForSelectedTab(state, newState, groupIndex, index, tabId, normalizedTab, uid, needsLoading, requestId, switchCommands);
3404
3398
  if (maybeCreatedState) {
@@ -3408,6 +3402,9 @@ const selectTab = async (state, groupIndex, index) => {
3408
3402
  if (switchCommands.length > 0) {
3409
3403
  await executeViewletCommands(switchCommands);
3410
3404
  }
3405
+ if (!needsLoading) {
3406
+ await focus(newState);
3407
+ }
3411
3408
  return maybeStartLoading(state, newState, tabId, normalizedTab, needsLoading, requestId);
3412
3409
  };
3413
3410
 
@@ -5582,7 +5579,7 @@ const openInputWithContext = async (context, options) => {
5582
5579
  let intermediateState = stateWithViewlet;
5583
5580
  const {
5584
5581
  newState: switchedState
5585
- } = switchViewlet(intermediateState, previousTabId, tabId);
5582
+ } = await switchViewlet(intermediateState, previousTabId, tabId);
5586
5583
  intermediateState = switchedState;
5587
5584
  await context.updateState(() => intermediateState);
5588
5585
  const tabWithViewlet = findTabById(intermediateState, tabId);
@@ -6959,7 +6956,7 @@ const newFile = async state => {
6959
6956
  }
6960
6957
 
6961
6958
  // Get previous active tab ID for viewlet switching
6962
- getActiveTabId(newState);
6959
+ const previousTabId = getActiveTabId(newState);
6963
6960
 
6964
6961
  // Create a new empty tab
6965
6962
  const tabId = create$2();
@@ -6989,7 +6986,7 @@ const newFile = async state => {
6989
6986
  // Switch viewlet (detach old, attach new if ready)
6990
6987
  const {
6991
6988
  newState: switchedState
6992
- } = switchViewlet(intermediateState);
6989
+ } = await switchViewlet(intermediateState, previousTabId, tabId);
6993
6990
  intermediateState = switchedState;
6994
6991
  set$1(uid, state, intermediateState);
6995
6992
 
@@ -8411,8 +8408,10 @@ const getSashCornerCss = (left, top) => {
8411
8408
  top: ${top}%;
8412
8409
  }`;
8413
8410
  };
8414
- const getCss = (layout, width = 0, dragOverlay) => {
8415
- const rules = [];
8411
+ const getCss = (layout, width = 0, dragOverlay, tabHeight = 35) => {
8412
+ const rules = [`.EditorGroupHeader {
8413
+ --EditorGroupHeight: ${tabHeight}px;
8414
+ }`];
8416
8415
  if (layout) {
8417
8416
  rules.push(...getEditorGroupCss(layout), ...getDragOverlayCss(dragOverlay), ...getSashCss(layout, width));
8418
8417
  const sashCorner = getSashCorner(layout);
@@ -8425,7 +8424,7 @@ const getCss = (layout, width = 0, dragOverlay) => {
8425
8424
  };
8426
8425
 
8427
8426
  const renderCss = (oldState, newState) => {
8428
- const css = getCss(newState.layout, newState.width, newState.dragOverlay);
8427
+ const css = getCss(newState.layout, newState.width, newState.dragOverlay, newState.tabHeight);
8429
8428
  return [SetCss, newState.uid, css];
8430
8429
  };
8431
8430
 
@@ -9101,8 +9100,25 @@ const setEditorLayoutTwoColumnsBottom = state => {
9101
9100
  }]);
9102
9101
  };
9103
9102
 
9103
+ const splitEditorGroupAndResize = async (state, split, ...args) => {
9104
+ const newState = split(state, ...args);
9105
+ if (newState === state) {
9106
+ return state;
9107
+ }
9108
+ await handleResize(newState, newState);
9109
+ const editorUids = newState.layout.groups.flatMap(group => group.tabs.map(tab => tab.editorUid).filter(editorUid => editorUid !== -1));
9110
+ for (const editorUid of editorUids) {
9111
+ await invoke$2('Viewlet.requestRender', editorUid);
9112
+ }
9113
+ return newState;
9114
+ };
9115
+
9104
9116
  const pendingLoads = new Map();
9105
9117
  const loadContent = wrapSerialCommand(loadContent$1);
9118
+ const splitDownAndResize = wrapSerialCommand((state, ...args) => splitEditorGroupAndResize(state, splitDown, ...args));
9119
+ const splitLeftAndResize = wrapSerialCommand((state, ...args) => splitEditorGroupAndResize(state, splitLeft, ...args));
9120
+ const splitRightAndResize = wrapSerialCommand((state, ...args) => splitEditorGroupAndResize(state, splitRight, ...args));
9121
+ const splitUpAndResize = wrapSerialCommand((state, ...args) => splitEditorGroupAndResize(state, splitUp, ...args));
9106
9122
  const loadContentTracked = async (uid, ...args) => {
9107
9123
  const loading = loadContent(uid, ...args);
9108
9124
  pendingLoads.set(uid, loading);
@@ -9157,7 +9173,7 @@ const commandMap = {
9157
9173
  'Main.restoreClosedTab': wrapSerialCommand(restoreClosedTab),
9158
9174
  'Main.save': wrapSerialCommand(save),
9159
9175
  'Main.saveState': wrapGetter(saveState),
9160
- 'Main.splitRight': wrapSerialCommand(splitRight),
9176
+ 'Main.splitRight': splitRightAndResize,
9161
9177
  'MainArea.closeActiveEditor': wrapSerialCommand(closeActiveEditor),
9162
9178
  'MainArea.closeAll': wrapSerialCommand(closeAll$1),
9163
9179
  'MainArea.closeAllEditors': wrapSerialCommand(closeAll$1),
@@ -9249,10 +9265,10 @@ const commandMap = {
9249
9265
  'MainArea.setEditorLayoutTwoColumnsBottom': wrapSerialCommand(setEditorLayoutTwoColumnsBottom),
9250
9266
  'MainArea.setEditorLayoutTwoRows': wrapSerialCommand(setEditorLayoutTwoRows),
9251
9267
  'MainArea.setEditorLayoutTwoRowsRight': wrapSerialCommand(setEditorLayoutTwoRowsRight),
9252
- 'MainArea.splitDown': wrapSerialCommand(splitDown),
9253
- 'MainArea.splitLeft': wrapSerialCommand(splitLeft),
9254
- 'MainArea.splitRight': wrapSerialCommand(splitRight),
9255
- 'MainArea.splitUp': wrapSerialCommand(splitUp),
9268
+ 'MainArea.splitDown': splitDownAndResize,
9269
+ 'MainArea.splitLeft': splitLeftAndResize,
9270
+ 'MainArea.splitRight': splitRightAndResize,
9271
+ 'MainArea.splitUp': splitUpAndResize,
9256
9272
  'MainArea.terminate': terminate
9257
9273
  };
9258
9274
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.67.3",
3
+ "version": "9.67.5",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",