@lvce-editor/main-area-worker 9.33.2 → 9.34.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.
@@ -1503,6 +1503,10 @@ const Main$1 = 24;
1503
1503
  const Separator = 1;
1504
1504
  const None$1 = 0;
1505
1505
 
1506
+ const Add$1 = 6;
1507
+ const NavigateChild$1 = 7;
1508
+ const NavigateParent$1 = 8;
1509
+
1506
1510
  const Electron = 2;
1507
1511
 
1508
1512
  const ClipBoardWorker = 3400;
@@ -2012,10 +2016,38 @@ const notifyActiveEditorChange = async (oldState, newState) => {
2012
2016
  }
2013
2017
  };
2014
2018
 
2019
+ const getMountedViewletUids = state => {
2020
+ const mountedViewletUids = [];
2021
+ for (const group of state.layout.groups) {
2022
+ const activeTab = group.tabs.find(tab => tab.id === group.activeTabId);
2023
+ if (activeTab?.loadingState === 'loaded' && activeTab.editorUid !== -1) {
2024
+ mountedViewletUids.push(activeTab.editorUid);
2025
+ }
2026
+ }
2027
+ return mountedViewletUids;
2028
+ };
2029
+
2030
+ const arraysEqual = (a, b) => {
2031
+ return a.length === b.length && a.every((value, index) => value === b[index]);
2032
+ };
2033
+ const notifyMountedViewlets = async (oldState, newState) => {
2034
+ const oldViewletUids = getMountedViewletUids(oldState);
2035
+ const newViewletUids = getMountedViewletUids(newState);
2036
+ if (oldState.uid === newState.uid && arraysEqual(oldViewletUids, newViewletUids)) {
2037
+ return;
2038
+ }
2039
+ try {
2040
+ await invoke('Layout.setMountedViewlets', newState.uid, newViewletUids);
2041
+ } catch (error) {
2042
+ console.warn('Failed to publish mounted viewlets', error);
2043
+ }
2044
+ };
2045
+
2015
2046
  const withActiveEditorChange = fn => {
2016
2047
  return async (state, ...args) => {
2017
2048
  const newState = await fn(state, ...args);
2018
2049
  await notifyActiveEditorChange(state, newState);
2050
+ await notifyMountedViewlets(state, newState);
2019
2051
  return newState;
2020
2052
  };
2021
2053
  };
@@ -2025,6 +2057,7 @@ const withActiveEditorChangeAsync = fn => {
2025
2057
  await fn(context, ...args);
2026
2058
  const newState = context.getState();
2027
2059
  await notifyActiveEditorChange(oldState, newState);
2060
+ await notifyMountedViewlets(oldState, newState);
2028
2061
  };
2029
2062
  };
2030
2063
 
@@ -3801,6 +3834,7 @@ const createEmptyGroup$1 = (state, uri, requestId, preview = false, title = getL
3801
3834
  layout
3802
3835
  } = state;
3803
3836
  const {
3837
+ direction,
3804
3838
  groups
3805
3839
  } = layout;
3806
3840
  const groupId = create$2();
@@ -3823,6 +3857,7 @@ const createEmptyGroup$1 = (state, uri, requestId, preview = false, title = getL
3823
3857
  };
3824
3858
  const newGroup = {
3825
3859
  activeTabId: newTab.id,
3860
+ direction,
3826
3861
  focused: true,
3827
3862
  id: groupId,
3828
3863
  isEmpty: false,
@@ -4340,7 +4375,7 @@ const getGroupSegments = (groups, parentDirection) => {
4340
4375
  let index = 0;
4341
4376
  while (index < groups.length) {
4342
4377
  const group = groups[index];
4343
- if (group.direction !== undefined && group.direction !== parentDirection) {
4378
+ if (group.direction !== parentDirection) {
4344
4379
  const startIndex = index;
4345
4380
  const nestedGroups = [group];
4346
4381
  const {
@@ -4408,7 +4443,7 @@ const splitOnlyGroup = (state, groups, groupId, newGroupId, direction, splitLayo
4408
4443
  if (group.id === groupId) {
4409
4444
  return {
4410
4445
  ...group,
4411
- direction: undefined,
4446
+ direction: splitLayoutDirection,
4412
4447
  focused: false,
4413
4448
  size: 50
4414
4449
  };
@@ -4417,7 +4452,7 @@ const splitOnlyGroup = (state, groups, groupId, newGroupId, direction, splitLayo
4417
4452
  });
4418
4453
  const newGroup = {
4419
4454
  ...baseNewGroup,
4420
- direction: undefined,
4455
+ direction: splitLayoutDirection,
4421
4456
  size: 50
4422
4457
  };
4423
4458
  const reorderedGroups = isTrailingSplit(direction) ? [...updatedGroups, newGroup] : [newGroup, ...updatedGroups];
@@ -4478,7 +4513,7 @@ const splitAtRootLevel = (state, groups, groupId, newGroupId, direction, baseNew
4478
4513
  if (group.id === groupId) {
4479
4514
  return {
4480
4515
  ...group,
4481
- direction: undefined,
4516
+ direction: state.layout.direction,
4482
4517
  focused: false,
4483
4518
  size: 50
4484
4519
  };
@@ -4487,7 +4522,7 @@ const splitAtRootLevel = (state, groups, groupId, newGroupId, direction, baseNew
4487
4522
  });
4488
4523
  const newGroup = {
4489
4524
  ...baseNewGroup,
4490
- direction: undefined,
4525
+ direction: state.layout.direction,
4491
4526
  size: 50
4492
4527
  };
4493
4528
  const reorderedGroups = isTrailingSplit(direction) ? [...updatedGroups, newGroup] : (() => {
@@ -4512,6 +4547,7 @@ const splitEditorGroup$1 = (state, groupId, direction) => {
4512
4547
  const splitLayoutDirection = getSplitLayoutDirection(direction);
4513
4548
  const baseNewGroup = {
4514
4549
  activeTabId: undefined,
4550
+ direction: sourceGroup.direction,
4515
4551
  focused: true,
4516
4552
  id: newGroupId,
4517
4553
  isEmpty: true,
@@ -4521,10 +4557,10 @@ const splitEditorGroup$1 = (state, groupId, direction) => {
4521
4557
  if (groups.length === 1) {
4522
4558
  return splitOnlyGroup(state, groups, groupId, newGroupId, direction, splitLayoutDirection, baseNewGroup);
4523
4559
  }
4524
- if (sourceGroup.direction === splitLayoutDirection) {
4560
+ if (sourceGroup.direction !== layoutDirection && sourceGroup.direction === splitLayoutDirection) {
4525
4561
  return splitWithinMatchingNestedDirection(state, groups, sourceGroup, groupId, newGroupId, direction, splitLayoutDirection, baseNewGroup);
4526
4562
  }
4527
- if (splitLayoutDirection !== layoutDirection && sourceGroup.direction === undefined) {
4563
+ if (splitLayoutDirection !== layoutDirection && sourceGroup.direction === layoutDirection) {
4528
4564
  return splitStandaloneSourceIntoNestedDirection(state, groups, sourceGroup, groupId, newGroupId, direction, splitLayoutDirection, baseNewGroup);
4529
4565
  }
4530
4566
  const segments = getGroupSegments(groups, layoutDirection);
@@ -5489,7 +5525,7 @@ const isValidTab = tab => {
5489
5525
  };
5490
5526
 
5491
5527
  const isValidEditorGroup = group => {
5492
- return group && typeof group.id === 'number' && Array.isArray(group.tabs) && group.tabs.every(isValidTab) && (group.activeTabId === undefined || typeof group.activeTabId === 'number') && (group.direction === undefined || isLayoutDirection(group.direction)) && typeof group.focused === 'boolean' && (group.segmentId === undefined || typeof group.segmentId === 'number') && typeof group.size === 'number' && group.size > 0 && typeof group.isEmpty === 'boolean';
5528
+ return group && typeof group.id === 'number' && Array.isArray(group.tabs) && group.tabs.every(isValidTab) && (group.activeTabId === undefined || typeof group.activeTabId === 'number') && isLayoutDirection(group.direction) && typeof group.focused === 'boolean' && (group.segmentId === undefined || typeof group.segmentId === 'number') && typeof group.size === 'number' && group.size > 0 && typeof group.isEmpty === 'boolean';
5493
5529
  };
5494
5530
 
5495
5531
  const isValidMainAreaLayout = layout => {
@@ -5523,6 +5559,12 @@ const normalizeRestoredTab = tab => {
5523
5559
  isPreview: typeof tab?.isPreview === 'boolean' ? tab.isPreview : false
5524
5560
  };
5525
5561
  };
5562
+ const normalizeGroupDirection = (group, layoutDirection) => {
5563
+ if (!group || typeof group !== 'object' || !Object.hasOwn(group, 'direction')) {
5564
+ return layoutDirection;
5565
+ }
5566
+ return normalizeLayoutDirection(group.direction);
5567
+ };
5526
5568
  const tryRestoreLayout = savedState => {
5527
5569
  if (savedState === undefined || savedState === null) {
5528
5570
  return undefined;
@@ -5554,12 +5596,10 @@ const tryRestoreLayout = savedState => {
5554
5596
  ...rawLayout,
5555
5597
  direction: layoutDirection,
5556
5598
  groups: rawLayout.groups.map(group => {
5557
- const groupDirection = normalizeLayoutDirection(group?.direction);
5599
+ const groupDirection = normalizeGroupDirection(group, layoutDirection);
5558
5600
  return {
5559
5601
  ...group,
5560
- ...(groupDirection !== undefined && {
5561
- direction: groupDirection
5562
- }),
5602
+ direction: groupDirection,
5563
5603
  tabs: Array.isArray(group?.tabs) ? group.tabs.map(normalizeRestoredTab) : []
5564
5604
  };
5565
5605
  })
@@ -6185,13 +6225,17 @@ const getDragOverlayCss = dragOverlay => {
6185
6225
  y
6186
6226
  } = dragOverlay;
6187
6227
  return [`.DragOverlay {
6188
- left: ${x}px;
6189
- top: ${y}px;
6190
- width: ${width}px;
6191
- height: ${height}px;
6228
+ --DragOverlayLeft: ${x}px;
6229
+ --DragOverlayTop: ${y}px;
6230
+ --DragOverlayWidth: ${width}px;
6231
+ --DragOverlayHeight: ${height}px;
6192
6232
  }`];
6193
6233
  };
6194
6234
 
6235
+ const getEditorGroupClassName = groupId => {
6236
+ return `EditorGroup-${groupId}`;
6237
+ };
6238
+
6195
6239
  const getEditorGroupCss = layout => {
6196
6240
  const {
6197
6241
  direction,
@@ -6199,7 +6243,7 @@ const getEditorGroupCss = layout => {
6199
6243
  } = layout;
6200
6244
  const groupSizeVariable = direction === Vertical ? '--EditorGroupHeight' : '--EditorGroupWidth';
6201
6245
  return groups.map(group => {
6202
- return `.EditorGroup[data-groupId="${group.id}"] {
6246
+ return `.${getEditorGroupClassName(group.id)} {
6203
6247
  ${groupSizeVariable}: ${group.size}%;
6204
6248
  }`;
6205
6249
  });
@@ -6924,7 +6968,7 @@ const renderEmptyEditorGroup = (group, groupIndex, style, closeButtonEnabled = t
6924
6968
  const closeButtonDom = closeButtonEnabled ? renderEmptyGroupCloseButton(group) : [];
6925
6969
  return [{
6926
6970
  childCount: closeButtonEnabled ? 2 : 1,
6927
- className: EditorGroupEmpty,
6971
+ className: mergeClassNames(EditorGroupEmpty, getEditorGroupClassName(group.id)),
6928
6972
  'data-groupId': String(group.id),
6929
6973
  onContextMenu: HandleContextMenu,
6930
6974
  style,
@@ -6948,7 +6992,7 @@ const renderEditorGroup = (group, groupIndex, splitButtonEnabled = false, sizePr
6948
6992
  }
6949
6993
  return [{
6950
6994
  childCount: 2,
6951
- className: EditorGroup,
6995
+ className: mergeClassNames(EditorGroup, getEditorGroupClassName(group.id)),
6952
6996
  'data-groupId': String(group.id),
6953
6997
  style,
6954
6998
  type: Div
@@ -7025,10 +7069,10 @@ const addDragOverlay = (dom, dragOverlay) => {
7025
7069
  if (!dragOverlay) {
7026
7070
  return dom;
7027
7071
  }
7028
- return [dom[0], {
7029
- ...dom[1],
7030
- childCount: dom[1].childCount + 1
7031
- }, ...dom.slice(2), getDragOverlayVirtualDom()];
7072
+ return [{
7073
+ ...dom[0],
7074
+ childCount: dom[0].childCount + 1
7075
+ }, dom[1], ...dom.slice(2), getDragOverlayVirtualDom()];
7032
7076
  };
7033
7077
  const getSizeProperty = direction => {
7034
7078
  return direction === Vertical ? 'height' : 'width';
@@ -7140,10 +7184,21 @@ const renderItems = (oldState, newState) => {
7140
7184
  return [SetDom2, uid, dom];
7141
7185
  };
7142
7186
 
7187
+ const avoidRootReplacement = patches => {
7188
+ if (patches.length !== 1 || patches[0].type !== Add$1 || patches[0].nodes?.length !== 1 || patches[0].nodes[0].className !== DragOverlay) {
7189
+ return patches;
7190
+ }
7191
+ return [{
7192
+ index: 0,
7193
+ type: NavigateChild$1
7194
+ }, {
7195
+ type: NavigateParent$1
7196
+ }, ...patches];
7197
+ };
7143
7198
  const renderIncremental = (oldState, newState) => {
7144
7199
  const oldDom = renderItems(oldState, oldState)[2];
7145
7200
  const newDom = renderItems(newState, newState)[2];
7146
- const patches = diffTree(oldDom, newDom);
7201
+ const patches = avoidRootReplacement(diffTree(oldDom, newDom));
7147
7202
  return [SetPatches, newState.uid, patches];
7148
7203
  };
7149
7204
 
@@ -7472,9 +7527,10 @@ const saveState = state => {
7472
7527
  const flipDirection = direction => {
7473
7528
  return direction === Horizontal ? Vertical : Horizontal;
7474
7529
  };
7475
- const createEmptyGroup = () => {
7530
+ const createEmptyGroup = direction => {
7476
7531
  return {
7477
7532
  activeTabId: undefined,
7533
+ direction,
7478
7534
  focused: false,
7479
7535
  id: create$2(),
7480
7536
  isEmpty: true,
@@ -7505,9 +7561,9 @@ const mergeGroups = (target, groups, activeGroupId) => {
7505
7561
  tabs
7506
7562
  };
7507
7563
  };
7508
- const getGroupsForSlotCount = (groups, slotCount, activeGroupId) => {
7564
+ const getGroupsForSlotCount = (groups, slotCount, activeGroupId, direction) => {
7509
7565
  if (slotCount === 1) {
7510
- const firstGroup = groups[0] ?? createEmptyGroup();
7566
+ const firstGroup = groups[0] ?? createEmptyGroup(direction);
7511
7567
  return [mergeGroups(firstGroup, groups.slice(1), activeGroupId)];
7512
7568
  }
7513
7569
  if (groups.length === slotCount) {
@@ -7516,7 +7572,7 @@ const getGroupsForSlotCount = (groups, slotCount, activeGroupId) => {
7516
7572
  if (groups.length < slotCount) {
7517
7573
  const missingGroups = Array.from({
7518
7574
  length: slotCount - groups.length
7519
- }, createEmptyGroup);
7575
+ }, () => createEmptyGroup(direction));
7520
7576
  return [...groups, ...missingGroups];
7521
7577
  }
7522
7578
  const retainedGroups = groups.slice(0, slotCount);
@@ -7535,7 +7591,7 @@ const setEditorLayout = (state, direction, slots) => {
7535
7591
  activeGroupId,
7536
7592
  groups: currentGroups
7537
7593
  } = layout;
7538
- const groups = getGroupsForSlotCount(currentGroups, slots.length, activeGroupId);
7594
+ const groups = getGroupsForSlotCount(currentGroups, slots.length, activeGroupId, direction);
7539
7595
  const originalActiveIndex = currentGroups.findIndex(group => group.id === activeGroupId);
7540
7596
  const activeIndex = originalActiveIndex >= slots.length ? slots.length - 1 : getActiveGroupIndex(groups, activeGroupId);
7541
7597
  const nextGroups = groups.map((group, index) => {
@@ -7573,45 +7629,56 @@ const flipLayout = state => {
7573
7629
  direction: flipDirection(direction),
7574
7630
  groups: groups.map(group => ({
7575
7631
  ...group,
7576
- direction: group.direction === undefined ? undefined : flipDirection(group.direction)
7632
+ direction: flipDirection(group.direction)
7577
7633
  }))
7578
7634
  }
7579
7635
  };
7580
7636
  };
7581
7637
  const setEditorLayoutSingle = state => {
7582
7638
  return setEditorLayout(state, Horizontal, [{
7639
+ direction: Horizontal,
7583
7640
  size: 100
7584
7641
  }]);
7585
7642
  };
7586
7643
  const setEditorLayoutTwoColumns = state => {
7587
7644
  return setEditorLayout(state, Horizontal, [{
7645
+ direction: Horizontal,
7588
7646
  size: 50
7589
7647
  }, {
7648
+ direction: Horizontal,
7590
7649
  size: 50
7591
7650
  }]);
7592
7651
  };
7593
7652
  const setEditorLayoutThreeColumns = state => {
7594
7653
  return setEditorLayout(state, Horizontal, [{
7654
+ direction: Horizontal,
7595
7655
  size: 33.333333
7596
7656
  }, {
7657
+ direction: Horizontal,
7597
7658
  size: 33.333333
7598
7659
  }, {
7660
+ direction: Horizontal,
7599
7661
  size: 33.333334
7600
7662
  }]);
7601
7663
  };
7602
7664
  const setEditorLayoutTwoRows = state => {
7603
7665
  return setEditorLayout(state, Vertical, [{
7666
+ direction: Vertical,
7604
7667
  size: 50
7605
7668
  }, {
7669
+ direction: Vertical,
7606
7670
  size: 50
7607
7671
  }]);
7608
7672
  };
7609
7673
  const setEditorLayoutThreeRows = state => {
7610
7674
  return setEditorLayout(state, Vertical, [{
7675
+ direction: Vertical,
7611
7676
  size: 33.333333
7612
7677
  }, {
7678
+ direction: Vertical,
7613
7679
  size: 33.333333
7614
7680
  }, {
7681
+ direction: Vertical,
7615
7682
  size: 33.333334
7616
7683
  }]);
7617
7684
  };
@@ -7639,6 +7706,7 @@ const setEditorLayoutGrid = state => {
7639
7706
  const setEditorLayoutTwoRowsRight = state => {
7640
7707
  const segmentId = create$2();
7641
7708
  return setEditorLayout(state, Horizontal, [{
7709
+ direction: Horizontal,
7642
7710
  size: 50
7643
7711
  }, {
7644
7712
  direction: Vertical,
@@ -7653,6 +7721,7 @@ const setEditorLayoutTwoRowsRight = state => {
7653
7721
  const setEditorLayoutTwoColumnsBottom = state => {
7654
7722
  const segmentId = create$2();
7655
7723
  return setEditorLayout(state, Vertical, [{
7724
+ direction: Vertical,
7656
7725
  size: 50
7657
7726
  }, {
7658
7727
  direction: Horizontal,
@@ -7671,6 +7740,7 @@ const splitDown = (state, groupId) => {
7671
7740
  } = state;
7672
7741
  const {
7673
7742
  activeGroupId,
7743
+ direction,
7674
7744
  groups
7675
7745
  } = layout;
7676
7746
 
@@ -7679,6 +7749,7 @@ const splitDown = (state, groupId) => {
7679
7749
  const initialGroupId = create$2();
7680
7750
  const initialGroup = {
7681
7751
  activeTabId: undefined,
7752
+ direction,
7682
7753
  focused: true,
7683
7754
  id: initialGroupId,
7684
7755
  isEmpty: true,
@@ -7708,12 +7779,14 @@ const splitLeft = (state, groupId) => {
7708
7779
  } = state;
7709
7780
  const {
7710
7781
  activeGroupId,
7782
+ direction,
7711
7783
  groups
7712
7784
  } = layout;
7713
7785
  if (groups.length === 0) {
7714
7786
  const initialGroupId = create$2();
7715
7787
  const initialGroup = {
7716
7788
  activeTabId: undefined,
7789
+ direction,
7717
7790
  focused: true,
7718
7791
  id: initialGroupId,
7719
7792
  isEmpty: true,
@@ -7740,6 +7813,7 @@ const splitRight = (state, groupId) => {
7740
7813
  } = state;
7741
7814
  const {
7742
7815
  activeGroupId,
7816
+ direction,
7743
7817
  groups
7744
7818
  } = layout;
7745
7819
 
@@ -7748,6 +7822,7 @@ const splitRight = (state, groupId) => {
7748
7822
  const initialGroupId = create$2();
7749
7823
  const initialGroup = {
7750
7824
  activeTabId: undefined,
7825
+ direction,
7751
7826
  focused: true,
7752
7827
  id: initialGroupId,
7753
7828
  isEmpty: true,
@@ -7774,12 +7849,14 @@ const splitUp = (state, groupId) => {
7774
7849
  } = state;
7775
7850
  const {
7776
7851
  activeGroupId,
7852
+ direction,
7777
7853
  groups
7778
7854
  } = layout;
7779
7855
  if (groups.length === 0) {
7780
7856
  const initialGroupId = create$2();
7781
7857
  const initialGroup = {
7782
7858
  activeTabId: undefined,
7859
+ direction,
7783
7860
  focused: true,
7784
7861
  id: initialGroupId,
7785
7862
  isEmpty: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.33.2",
3
+ "version": "9.34.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",