@lvce-editor/main-area-worker 9.51.0 → 9.52.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.
@@ -2404,27 +2404,32 @@ const promptSave = async title => {
2404
2404
  });
2405
2405
  return shouldDiscard ? 'discard' : 'cancel';
2406
2406
  };
2407
+ const canCloseTab = async tab => {
2408
+ if (tab.editorUid === -1 || !tab.isDirty) {
2409
+ return true;
2410
+ }
2411
+ const savePromptResult = await promptSave(tab.title);
2412
+ if (savePromptResult === 'cancel') {
2413
+ return false;
2414
+ }
2415
+ if (savePromptResult === 'save') {
2416
+ const editorState = await saveEditor(tab.editorUid);
2417
+ if (editorState?.modified !== false) {
2418
+ return false;
2419
+ }
2420
+ if (tab.uri) {
2421
+ await handleModifiedStatusChange$1(tab.uri, false);
2422
+ }
2423
+ }
2424
+ return savePromptResult === 'save' || savePromptResult === 'discard';
2425
+ };
2407
2426
  const closeTabAndSave = async (state, groupId, tabId) => {
2408
2427
  const tab = findTabInState(state, groupId, tabId);
2409
2428
  if (!tab) {
2410
2429
  return state;
2411
2430
  }
2412
- if (tab.editorUid !== -1 && tab.isDirty) {
2413
- const savePromptResult = await promptSave(tab.title);
2414
- if (savePromptResult === 'cancel') {
2415
- return state;
2416
- }
2417
- if (savePromptResult === 'save') {
2418
- const editorState = await saveEditor(tab.editorUid);
2419
- if (editorState?.modified !== false) {
2420
- return state;
2421
- }
2422
- if (tab.uri) {
2423
- await handleModifiedStatusChange$1(tab.uri, false);
2424
- }
2425
- } else if (savePromptResult !== 'discard') {
2426
- return state;
2427
- }
2431
+ if (!(await canCloseTab(tab))) {
2432
+ return state;
2428
2433
  }
2429
2434
  return closeTabWithViewlet(state, groupId, tabId);
2430
2435
  };
@@ -2488,6 +2493,16 @@ const closeAll$1 = async state => {
2488
2493
  return withEmptyGroups(addClosedTabs(state, entries));
2489
2494
  };
2490
2495
 
2496
+ const closeAllAndSave = async state => {
2497
+ const tabs = state.layout.groups.flatMap(group => group.tabs);
2498
+ for (const tab of tabs) {
2499
+ if (!(await canCloseTab(tab))) {
2500
+ return state;
2501
+ }
2502
+ }
2503
+ return closeAll$1(state);
2504
+ };
2505
+
2491
2506
  const redistributeSizesWithRemainder = groups => {
2492
2507
  const baseSize = Math.floor(100 / groups.length);
2493
2508
  const remainder = 100 % groups.length;
@@ -3214,6 +3229,9 @@ const findTabById = (state, tabId) => {
3214
3229
  const getSegmentSize = segment => {
3215
3230
  return segment.groups.reduce((total, group) => total + group.size, 0);
3216
3231
  };
3232
+ const getGroupSegment = (segments, groupId) => {
3233
+ return segments.find(segment => segment.groups.some(group => group.id === groupId));
3234
+ };
3217
3235
  const getGroupSegments = (groups, parentDirection) => {
3218
3236
  const segments = [];
3219
3237
  let index = 0;
@@ -5433,7 +5451,7 @@ const handleHeaderDoubleClick = async (state, className, groupIndexRaw) => {
5433
5451
  return newFile(state);
5434
5452
  };
5435
5453
 
5436
- const getAllTabs = layout => {
5454
+ const getAllTabs$1 = layout => {
5437
5455
  const {
5438
5456
  groups
5439
5457
  } = layout;
@@ -5453,7 +5471,7 @@ const loadFileIcons = async state => {
5453
5471
  groups
5454
5472
  } = layout;
5455
5473
  try {
5456
- const allTabs = getAllTabs(layout);
5474
+ const allTabs = getAllTabs$1(layout);
5457
5475
  const {
5458
5476
  newFileIconCache
5459
5477
  } = await getFileIconsForTabs(allTabs, fileIconCache);
@@ -5790,6 +5808,7 @@ const handleSashPointerDown = async (state, sashId, clientX, clientY) => {
5790
5808
  layout
5791
5809
  } = state;
5792
5810
  const {
5811
+ direction,
5793
5812
  groups
5794
5813
  } = layout;
5795
5814
  const beforeGroup = groups.find(group => group.id === parsed.beforeGroupId);
@@ -5800,13 +5819,20 @@ const handleSashPointerDown = async (state, sashId, clientX, clientY) => {
5800
5819
  if (!Number.isFinite(clientX) || !Number.isFinite(clientY)) {
5801
5820
  return state;
5802
5821
  }
5822
+ const segments = getGroupSegments(groups, direction);
5823
+ const beforeSegment = getGroupSegment(segments, parsed.beforeGroupId);
5824
+ const afterSegment = getGroupSegment(segments, parsed.afterGroupId);
5825
+ if (!beforeSegment || !afterSegment) {
5826
+ return state;
5827
+ }
5828
+ const isNestedSash = beforeSegment === afterSegment;
5803
5829
  return {
5804
5830
  ...state,
5805
5831
  sashDrag: {
5806
5832
  afterGroupId: parsed.afterGroupId,
5807
- afterSize: afterGroup.size,
5833
+ afterSize: isNestedSash ? afterGroup.size : getSegmentSize(afterSegment),
5808
5834
  beforeGroupId: parsed.beforeGroupId,
5809
- beforeSize: beforeGroup.size,
5835
+ beforeSize: isNestedSash ? beforeGroup.size : getSegmentSize(beforeSegment),
5810
5836
  sashId,
5811
5837
  startClientX: clientX,
5812
5838
  startClientY: clientY
@@ -5814,6 +5840,14 @@ const handleSashPointerDown = async (state, sashId, clientX, clientY) => {
5814
5840
  };
5815
5841
  };
5816
5842
 
5843
+ const resizeGroupInSegment = (segment, groupId, segmentSize) => {
5844
+ const group = segment.groups.find(group => group.id === groupId);
5845
+ if (!group) {
5846
+ return undefined;
5847
+ }
5848
+ const previousSegmentSize = getSegmentSize(segment);
5849
+ return round(group.size / previousSegmentSize * segmentSize);
5850
+ };
5817
5851
  const handleSashPointerMove = async (state, clientX, clientY) => {
5818
5852
  const {
5819
5853
  height,
@@ -5833,6 +5867,13 @@ const handleSashPointerMove = async (state, clientX, clientY) => {
5833
5867
  direction,
5834
5868
  groups
5835
5869
  } = layout;
5870
+ const segments = getGroupSegments(groups, direction);
5871
+ const beforeSegment = getGroupSegment(segments, sashDrag.beforeGroupId);
5872
+ const afterSegment = getGroupSegment(segments, sashDrag.afterGroupId);
5873
+ if (!beforeSegment || !afterSegment) {
5874
+ return state;
5875
+ }
5876
+ const isNestedSash = beforeSegment === afterSegment;
5836
5877
  const axisSize = direction === Horizontal ? width : height;
5837
5878
  if (!axisSize) {
5838
5879
  return state;
@@ -5850,6 +5891,23 @@ const handleSashPointerMove = async (state, clientX, clientY) => {
5850
5891
  const beforeSize = clamp(sashDrag.beforeSize + deltaPercent, minGroupSize, totalResizableSize - minGroupSize);
5851
5892
  const afterSize = totalResizableSize - beforeSize;
5852
5893
  const newGroups = groups.map(group => {
5894
+ if (!isNestedSash) {
5895
+ const resizedBeforeGroupSize = resizeGroupInSegment(beforeSegment, group.id, beforeSize);
5896
+ if (resizedBeforeGroupSize !== undefined) {
5897
+ return {
5898
+ ...group,
5899
+ size: resizedBeforeGroupSize
5900
+ };
5901
+ }
5902
+ const resizedAfterGroupSize = resizeGroupInSegment(afterSegment, group.id, afterSize);
5903
+ if (resizedAfterGroupSize !== undefined) {
5904
+ return {
5905
+ ...group,
5906
+ size: resizedAfterGroupSize
5907
+ };
5908
+ }
5909
+ return group;
5910
+ }
5853
5911
  if (group.id === sashDrag.beforeGroupId) {
5854
5912
  return {
5855
5913
  ...group,
@@ -6387,6 +6445,30 @@ const hasActiveTextEditor = state => {
6387
6445
  return activeTab?.tab.editorInput?.type === 'editor';
6388
6446
  };
6389
6447
 
6448
+ const getTabs = group => {
6449
+ return group.tabs;
6450
+ };
6451
+ const getAllTabs = state => {
6452
+ const {
6453
+ layout
6454
+ } = state;
6455
+ const {
6456
+ groups
6457
+ } = layout;
6458
+ return groups.flatMap(getTabs);
6459
+ };
6460
+
6461
+ const isDirty = tab => {
6462
+ return tab.isDirty;
6463
+ };
6464
+ const getDirtyTabs = state => {
6465
+ return getAllTabs(state).filter(isDirty);
6466
+ };
6467
+
6468
+ const hasDirtyTabs = state => {
6469
+ return getDirtyTabs(state).length > 0;
6470
+ };
6471
+
6390
6472
  const initialize$1 = async () => {
6391
6473
  // Kept as a compatibility command for existing renderer startup code.
6392
6474
  };
@@ -8475,6 +8557,7 @@ const commandMap = {
8475
8557
  'Main.closeActiveEditor': wrapSerialCommand(closeActiveEditor),
8476
8558
  'Main.closeAll': wrapSerialCommand(closeAll$1),
8477
8559
  'Main.closeAllEditors': wrapSerialCommand(closeAll$1),
8560
+ 'Main.closeAllEditorsAndSave': wrapSerialCommand(closeAllAndSave),
8478
8561
  'Main.closeFocusedTab': wrapSerialCommand(closeFocusedTab),
8479
8562
  'Main.closeOthers': wrapSerialCommand(closeOtherTabs),
8480
8563
  'Main.closeSaved': wrapSerialCommand(closeSaved$1),
@@ -8490,6 +8573,7 @@ const commandMap = {
8490
8573
  'Main.handleModifiedStatusChange': wrapAsyncCommand(handleModifiedStatusChangeWithContext),
8491
8574
  'Main.handleTabContextMenu': wrapSerialCommand(handleTabContextMenu),
8492
8575
  'Main.hasActiveTextEditor': wrapGetter(hasActiveTextEditor),
8576
+ 'Main.hasDirtyTabs': wrapGetter(hasDirtyTabs),
8493
8577
  'Main.openInput': wrapSerialAsyncCommand(openInputWithContext),
8494
8578
  'Main.openUri': wrapSerialAsyncCommand(openUriWithContext),
8495
8579
  'Main.openUris': wrapSerialAsyncCommand(openUrisWithContext),
@@ -8500,6 +8584,7 @@ const commandMap = {
8500
8584
  'MainArea.closeActiveEditor': wrapSerialCommand(closeActiveEditor),
8501
8585
  'MainArea.closeAll': wrapSerialCommand(closeAll$1),
8502
8586
  'MainArea.closeAllEditors': wrapSerialCommand(closeAll$1),
8587
+ 'MainArea.closeAllEditorsAndSave': wrapSerialCommand(closeAllAndSave),
8503
8588
  'MainArea.closeEditorGroup': wrapSerialCommand(closeEditorGroup$1),
8504
8589
  'MainArea.closeFocusedTab': wrapSerialCommand(closeFocusedTab),
8505
8590
  'MainArea.closeOthers': wrapSerialCommand(closeOtherTabs),
@@ -8553,6 +8638,7 @@ const commandMap = {
8553
8638
  'MainArea.handleWorkspaceChange': wrapSerialCommand(handleWorkspaceChange),
8554
8639
  'MainArea.handleWorkspaceRefresh': wrapAsyncCommand(handleWorkspaceRefreshWithContext),
8555
8640
  'MainArea.hasActiveTextEditor': wrapGetter(hasActiveTextEditor),
8641
+ 'MainArea.hasDirtyTabs': wrapGetter(hasDirtyTabs),
8556
8642
  'MainArea.initialize': initialize$1,
8557
8643
  'MainArea.loadContent': loadContentTracked,
8558
8644
  'MainArea.moveIntoNewWindow': wrapSerialCommand(moveIntoNewWindow),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.51.0",
3
+ "version": "9.52.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",