@lvce-editor/main-area-worker 9.31.0 → 9.32.1

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.
@@ -1546,6 +1546,9 @@ const create$3 = rpcId => {
1546
1546
  };
1547
1547
 
1548
1548
  const None$1 = 'none';
1549
+ const Tab$1 = 'tab';
1550
+ const TabList = 'tablist';
1551
+ const ToolBar = 'toolbar';
1549
1552
 
1550
1553
  const Audio = 0;
1551
1554
  const Button$2 = 1;
@@ -1930,17 +1933,72 @@ const createViewlet = async (viewletModuleId, editorUid, tabId, bounds, uri) =>
1930
1933
  return getTitle$1(editorUid);
1931
1934
  };
1932
1935
 
1936
+ const getActiveFileUri = state => {
1937
+ const {
1938
+ activeGroupId,
1939
+ groups
1940
+ } = state.layout;
1941
+ const activeGroup = groups.find(group => group.id === activeGroupId);
1942
+ const activeTab = activeGroup?.tabs.find(tab => tab.id === activeGroup.activeTabId);
1943
+ if (!activeTab) {
1944
+ return '';
1945
+ }
1946
+ if (typeof activeTab.uri === 'string') {
1947
+ return activeTab.uri;
1948
+ }
1949
+ const {
1950
+ editorInput
1951
+ } = activeTab;
1952
+ return editorInput && 'uri' in editorInput ? editorInput.uri : '';
1953
+ };
1954
+
1955
+ const notifyActiveEditorChange = async (oldState, newState) => {
1956
+ const oldUri = getActiveFileUri(oldState);
1957
+ const newUri = getActiveFileUri(newState);
1958
+ if (oldUri === newUri) {
1959
+ return;
1960
+ }
1961
+ try {
1962
+ await invoke('Viewlet.executeViewletCommand', 'Problems', 'handleActiveEditorChange', newUri);
1963
+ } catch (error) {
1964
+ console.warn('Failed to notify Problems view about active editor change', error);
1965
+ }
1966
+ };
1967
+
1968
+ const withActiveEditorChange = fn => {
1969
+ return async (state, ...args) => {
1970
+ const newState = await fn(state, ...args);
1971
+ await notifyActiveEditorChange(state, newState);
1972
+ return newState;
1973
+ };
1974
+ };
1975
+ const withActiveEditorChangeAsync = fn => {
1976
+ return async (context, ...args) => {
1977
+ const oldState = context.getState();
1978
+ await fn(context, ...args);
1979
+ const newState = context.getState();
1980
+ await notifyActiveEditorChange(oldState, newState);
1981
+ };
1982
+ };
1983
+
1984
+ const registry = create$f();
1933
1985
  const {
1934
1986
  get,
1935
1987
  getCommandIds,
1936
1988
  getKeys: getKeys$1,
1937
1989
  registerCommands,
1938
1990
  set,
1939
- wrapAsyncCommand,
1940
- wrapGetter,
1941
- wrapSerialAsyncCommand,
1942
- wrapSerialCommand
1943
- } = create$f();
1991
+ wrapGetter
1992
+ } = registry;
1993
+ const wrapAsyncCommand = fn => {
1994
+ return registry.wrapAsyncCommand(withActiveEditorChangeAsync(fn));
1995
+ };
1996
+ const wrapSerialAsyncCommand = fn => {
1997
+ return registry.wrapSerialAsyncCommand(withActiveEditorChangeAsync(fn));
1998
+ };
1999
+ const wrapSerialCommand = fn => {
2000
+ return registry.wrapSerialCommand(withActiveEditorChange(fn));
2001
+ };
1944
2002
 
1945
2003
  const create$2 = () => {
1946
2004
  return Math.random();
@@ -4718,6 +4776,155 @@ const handleResize = async (state, dimensions) => {
4718
4776
  return allResizeCommands;
4719
4777
  };
4720
4778
 
4779
+ const offsetsMatch = (first, second) => {
4780
+ return Math.abs(first - second) < 1e-6;
4781
+ };
4782
+ const getSashCorner = layout => {
4783
+ const segments = getGroupSegments(layout.groups, layout.direction);
4784
+ if (segments.length !== 2) {
4785
+ return undefined;
4786
+ }
4787
+ const [firstSegment, secondSegment] = segments;
4788
+ if (firstSegment.direction === undefined || secondSegment.direction !== firstSegment.direction || firstSegment.groups.length !== 2 || secondSegment.groups.length !== 2) {
4789
+ return undefined;
4790
+ }
4791
+ const firstSegmentSize = getSegmentSize(firstSegment);
4792
+ const secondSegmentSize = getSegmentSize(secondSegment);
4793
+ const totalSize = firstSegmentSize + secondSegmentSize;
4794
+ if (!firstSegmentSize || !secondSegmentSize || !totalSize) {
4795
+ return undefined;
4796
+ }
4797
+ const firstNestedOffset = firstSegment.groups[0].size / firstSegmentSize * 100;
4798
+ const secondNestedOffset = secondSegment.groups[0].size / secondSegmentSize * 100;
4799
+ if (!offsetsMatch(firstNestedOffset, secondNestedOffset)) {
4800
+ return undefined;
4801
+ }
4802
+ const rootOffset = firstSegmentSize / totalSize * 100;
4803
+ if (layout.direction === Horizontal) {
4804
+ return {
4805
+ leftOffset: rootOffset,
4806
+ topOffset: firstNestedOffset,
4807
+ xAfterGroupIds: secondSegment.groups.map(group => group.id),
4808
+ xBeforeGroupIds: firstSegment.groups.map(group => group.id),
4809
+ yAfterGroupIds: [firstSegment.groups[1].id, secondSegment.groups[1].id],
4810
+ yBeforeGroupIds: [firstSegment.groups[0].id, secondSegment.groups[0].id]
4811
+ };
4812
+ }
4813
+ return {
4814
+ leftOffset: firstNestedOffset,
4815
+ topOffset: rootOffset,
4816
+ xAfterGroupIds: [firstSegment.groups[1].id, secondSegment.groups[1].id],
4817
+ xBeforeGroupIds: [firstSegment.groups[0].id, secondSegment.groups[0].id],
4818
+ yAfterGroupIds: secondSegment.groups.map(group => group.id),
4819
+ yBeforeGroupIds: firstSegment.groups.map(group => group.id)
4820
+ };
4821
+ };
4822
+
4823
+ const handleSashCornerPointerDown = async (state, clientX, clientY) => {
4824
+ if (!Number.isFinite(clientX) || !Number.isFinite(clientY)) {
4825
+ return state;
4826
+ }
4827
+ const sashCorner = getSashCorner(state.layout);
4828
+ if (!sashCorner) {
4829
+ return state;
4830
+ }
4831
+ return {
4832
+ ...state,
4833
+ sashCornerDrag: {
4834
+ groupSizes: state.layout.groups.map(group => ({
4835
+ id: group.id,
4836
+ size: group.size
4837
+ })),
4838
+ startClientX: clientX,
4839
+ startClientY: clientY,
4840
+ xAfterGroupIds: sashCorner.xAfterGroupIds,
4841
+ xBeforeGroupIds: sashCorner.xBeforeGroupIds,
4842
+ yAfterGroupIds: sashCorner.yAfterGroupIds,
4843
+ yBeforeGroupIds: sashCorner.yBeforeGroupIds
4844
+ }
4845
+ };
4846
+ };
4847
+
4848
+ const clamp = (value, min, max) => {
4849
+ return Math.min(max, Math.max(min, value));
4850
+ };
4851
+
4852
+ const getMinGroupSizePercent = (axisSize, minGroupSizePx) => {
4853
+ if (!axisSize) {
4854
+ return 0;
4855
+ }
4856
+ return minGroupSizePx / axisSize * 100;
4857
+ };
4858
+
4859
+ const round = value => {
4860
+ return Math.round(value * 100) / 100;
4861
+ };
4862
+
4863
+ const sumGroupSizes = (groupSizes, groupIds) => {
4864
+ return groupSizes.reduce((total, group) => total + (groupIds.includes(group.id) ? group.size : 0), 0);
4865
+ };
4866
+ const getBeforeSize = (startSize, deltaPx, axisSize, minSizePx, totalSize) => {
4867
+ let minSize = getMinGroupSizePercent(axisSize, minSizePx);
4868
+ if (2 * minSize > totalSize) {
4869
+ minSize = totalSize / 2;
4870
+ }
4871
+ const deltaSize = deltaPx / axisSize * totalSize;
4872
+ return clamp(startSize + deltaSize, minSize, totalSize - minSize);
4873
+ };
4874
+ const handleSashCornerPointerMove = async (state, clientX, clientY) => {
4875
+ const {
4876
+ height,
4877
+ sashCornerDrag,
4878
+ width
4879
+ } = state;
4880
+ if (!sashCornerDrag || !width || !height || !Number.isFinite(clientX) || !Number.isFinite(clientY)) {
4881
+ return state;
4882
+ }
4883
+ const {
4884
+ groupSizes,
4885
+ startClientX,
4886
+ startClientY,
4887
+ xBeforeGroupIds,
4888
+ yBeforeGroupIds
4889
+ } = sashCornerDrag;
4890
+ const totalSize = groupSizes.reduce((total, group) => total + group.size, 0);
4891
+ if (!totalSize) {
4892
+ return state;
4893
+ }
4894
+ const xBeforeStartSize = sumGroupSizes(groupSizes, xBeforeGroupIds);
4895
+ const yBeforeStartSize = sumGroupSizes(groupSizes, yBeforeGroupIds);
4896
+ const xBeforeSize = getBeforeSize(xBeforeStartSize, clientX - startClientX, width, state.minGroupWidthPx, totalSize);
4897
+ const yBeforeSize = getBeforeSize(yBeforeStartSize, clientY - startClientY, height, state.minGroupHeightPx, totalSize);
4898
+ const xAfterSize = totalSize - xBeforeSize;
4899
+ const yAfterSize = totalSize - yBeforeSize;
4900
+ const xBeforeGroupIdSet = new Set(xBeforeGroupIds);
4901
+ const yBeforeGroupIdSet = new Set(yBeforeGroupIds);
4902
+ return {
4903
+ ...state,
4904
+ layout: {
4905
+ ...state.layout,
4906
+ groups: state.layout.groups.map(group => {
4907
+ const xSize = xBeforeGroupIdSet.has(group.id) ? xBeforeSize : xAfterSize;
4908
+ const ySize = yBeforeGroupIdSet.has(group.id) ? yBeforeSize : yAfterSize;
4909
+ return {
4910
+ ...group,
4911
+ size: round(xSize * ySize / totalSize)
4912
+ };
4913
+ })
4914
+ }
4915
+ };
4916
+ };
4917
+
4918
+ const handleSashCornerPointerUp = async state => {
4919
+ if (!state.sashCornerDrag) {
4920
+ return state;
4921
+ }
4922
+ return {
4923
+ ...state,
4924
+ sashCornerDrag: undefined
4925
+ };
4926
+ };
4927
+
4721
4928
  const create = (beforeGroupId, afterGroupId) => {
4722
4929
  return `${beforeGroupId}:${afterGroupId}`;
4723
4930
  };
@@ -4773,21 +4980,6 @@ const handleSashPointerDown = async (state, sashId, clientX, clientY) => {
4773
4980
  };
4774
4981
  };
4775
4982
 
4776
- const clamp = (value, min, max) => {
4777
- return Math.min(max, Math.max(min, value));
4778
- };
4779
-
4780
- const getMinGroupSizePercent = (axisSize, minGroupSizePx) => {
4781
- if (!axisSize) {
4782
- return 0;
4783
- }
4784
- return minGroupSizePx / axisSize * 100;
4785
- };
4786
-
4787
- const round = value => {
4788
- return Math.round(value * 100) / 100;
4789
- };
4790
-
4791
4983
  const handleSashPointerMove = async (state, clientX, clientY) => {
4792
4984
  const {
4793
4985
  height,
@@ -5746,6 +5938,27 @@ const getCss = (layout, width = 0) => {
5746
5938
  }`, `.SashBorderVertical {
5747
5939
  width: 1px;
5748
5940
  height: 100%;
5941
+ }`, `.SashCorner {
5942
+ position: absolute;
5943
+ z-index: 2;
5944
+ display: flex;
5945
+ align-items: center;
5946
+ justify-content: center;
5947
+ width: 12px;
5948
+ height: 12px;
5949
+ padding: 0;
5950
+ border: 0;
5951
+ background: transparent;
5952
+ cursor: all-scroll;
5953
+ transform: translate(-50%, -50%);
5954
+ }`, `.SashCorner::after {
5955
+ content: '';
5956
+ width: 4px;
5957
+ height: 4px;
5958
+ background: var(--SashBorder, gray);
5959
+ }`, `.SashCorner:hover::after,
5960
+ .SashCorner:active::after {
5961
+ background: var(--SashHoverBorder, #3d5252);
5749
5962
  }`, `.EditorGroup {
5750
5963
  min-width: 250px;
5751
5964
  width: var(--EditorGroupWidth, auto);
@@ -5753,6 +5966,13 @@ const getCss = (layout, width = 0) => {
5753
5966
  }`];
5754
5967
  if (layout) {
5755
5968
  rules.push(...getEditorGroupCss(layout), ...getSashCss(layout, width));
5969
+ const sashCorner = getSashCorner(layout);
5970
+ if (sashCorner) {
5971
+ rules.push(`.SashCorner {
5972
+ left: ${sashCorner.leftOffset}%;
5973
+ top: ${sashCorner.topOffset}%;
5974
+ }`);
5975
+ }
5756
5976
  }
5757
5977
  const css = rules.join('\n');
5758
5978
  return css;
@@ -6049,6 +6269,9 @@ const HandleSashPointerDown = 16;
6049
6269
  const HandleSashPointerMove = 17;
6050
6270
  const HandleSashPointerUp = 18;
6051
6271
  const HandleDoubleClick = 19;
6272
+ const HandleSashCornerPointerDown = 20;
6273
+ const HandleSashCornerPointerMove = 21;
6274
+ const HandleSashCornerPointerUp = 22;
6052
6275
 
6053
6276
  const renderContent = content => {
6054
6277
  return [{
@@ -6064,7 +6287,7 @@ const renderContent = content => {
6064
6287
 
6065
6288
  const renderError = errorMessage => {
6066
6289
  return [{
6067
- childCount: 2,
6290
+ childCount: 1,
6068
6291
  className: TextEditorError,
6069
6292
  type: Div
6070
6293
  }, {
@@ -6099,7 +6322,7 @@ const renderLoading = () => {
6099
6322
  const renderViewletReference = tab => {
6100
6323
  return [{
6101
6324
  childCount: 0,
6102
- type: 100,
6325
+ type: Reference,
6103
6326
  // Reference node type - frontend will append the component at this position
6104
6327
  uid: tab.editorUid
6105
6328
  }];
@@ -6217,7 +6440,7 @@ const renderTab = (tab, isActive, tabIndex, groupIndex) => {
6217
6440
  onContextMenu: HandleTabContextMenu,
6218
6441
  onDblClick: HandleDoubleClick,
6219
6442
  onMouseDown: HandleClickTab,
6220
- role: 'tab',
6443
+ role: Tab$1,
6221
6444
  title: tab.uriTitle || tab.uri || tab.title,
6222
6445
  type: Div
6223
6446
  }, ...renderTabIcon(tab), {
@@ -6231,7 +6454,7 @@ const getTabsVirtualDom = (group, groupIndex, tabsChildCount) => {
6231
6454
  return [{
6232
6455
  childCount: tabsChildCount,
6233
6456
  className: MainTabs,
6234
- role: 'tablist',
6457
+ role: TabList,
6235
6458
  type: Div
6236
6459
  }, ...group.tabs.flatMap((tab, tabIndex) => renderTab(tab, tab.id === group.activeTabId, tabIndex, groupIndex))];
6237
6460
  };
@@ -6270,7 +6493,7 @@ const renderEditorGroupActions = (group, groupIndex, splitButtonEnabled) => {
6270
6493
  if (splitButtonEnabled) {
6271
6494
  buttons.push({
6272
6495
  childCount: 1,
6273
- className: EditorGroupActionButton + ' ' + SplitEditorGroupButton,
6496
+ className: mergeClassNames(EditorGroupActionButton, SplitEditorGroupButton),
6274
6497
  'data-action': SplitRight$1,
6275
6498
  'data-groupId': String(group.id),
6276
6499
  name: SplitRight$1,
@@ -6283,7 +6506,7 @@ const renderEditorGroupActions = (group, groupIndex, splitButtonEnabled) => {
6283
6506
  childCount: buttons.length / 2,
6284
6507
  // Each button has 2 nodes (button + text)
6285
6508
  className: EditorGroupActions,
6286
- role: 'toolbar',
6509
+ role: ToolBar,
6287
6510
  type: Div
6288
6511
  }, ...buttons];
6289
6512
  };
@@ -6336,6 +6559,8 @@ const renderWaterMark = groupId => {
6336
6559
  }];
6337
6560
  };
6338
6561
 
6562
+ const Focusable = 0;
6563
+
6339
6564
  const renderEmptyEditorGroup = (group, groupIndex, style, closeButtonEnabled = true) => {
6340
6565
  const closeButtonDom = closeButtonEnabled ? renderEmptyGroupCloseButton(group) : [];
6341
6566
  return [{
@@ -6344,7 +6569,7 @@ const renderEmptyEditorGroup = (group, groupIndex, style, closeButtonEnabled = t
6344
6569
  'data-groupId': String(group.id),
6345
6570
  onContextMenu: HandleContextMenu,
6346
6571
  style,
6347
- tabIndex: 0,
6572
+ tabIndex: Focusable,
6348
6573
  type: Div
6349
6574
  }, ...closeButtonDom, ...renderWaterMark(group.id)];
6350
6575
  };
@@ -6383,7 +6608,7 @@ const renderSash = (direction, sashId) => {
6383
6608
  className: getSashClassName(direction),
6384
6609
  'data-sashId': sashId,
6385
6610
  onPointerDown: HandleSashPointerDown,
6386
- role: 'none',
6611
+ role: None$1,
6387
6612
  type: Button$2
6388
6613
  }, {
6389
6614
  childCount: 0,
@@ -6392,6 +6617,16 @@ const renderSash = (direction, sashId) => {
6392
6617
  }];
6393
6618
  };
6394
6619
 
6620
+ const renderSashCorner = () => {
6621
+ return {
6622
+ childCount: 0,
6623
+ className: 'SashCorner',
6624
+ onPointerDown: HandleSashCornerPointerDown,
6625
+ role: None$1,
6626
+ type: Button$2
6627
+ };
6628
+ };
6629
+
6395
6630
  const renderSingleEditorGroup = (layout, splitButtonEnabled, sizeProperty = 'width') => {
6396
6631
  return [{
6397
6632
  childCount: 1,
@@ -6499,16 +6734,18 @@ const getMainAreaVirtualDom = (layout, splitButtonEnabled = false) => {
6499
6734
  childCount,
6500
6735
  children
6501
6736
  } = renderSegmentChildren(direction, groups, splitButtonEnabled);
6737
+ const sashCorner = getSashCorner(layout);
6738
+ const sashCornerChildren = sashCorner ? [renderSashCorner()] : [];
6502
6739
  return [{
6503
6740
  childCount: 1,
6504
6741
  className: Main,
6505
6742
  type: Div
6506
6743
  }, {
6507
- childCount,
6744
+ childCount: childCount + sashCornerChildren.length,
6508
6745
  className: editorGroupsContainerClassName,
6509
6746
  role: None$1,
6510
6747
  type: Div
6511
- }, ...children];
6748
+ }, ...children, ...sashCornerChildren];
6512
6749
  };
6513
6750
 
6514
6751
  const renderItems = (oldState, newState) => {
@@ -6616,6 +6853,17 @@ const renderEventListeners = () => {
6616
6853
  }, {
6617
6854
  name: HandleSashPointerUp,
6618
6855
  params: ['handleSashPointerUp', ClientX, ClientY]
6856
+ }, {
6857
+ name: HandleSashCornerPointerDown,
6858
+ params: ['handleSashCornerPointerDown', ClientX, ClientY],
6859
+ preventDefault: true,
6860
+ trackPointerEvents: [HandleSashCornerPointerMove, HandleSashCornerPointerUp]
6861
+ }, {
6862
+ name: HandleSashCornerPointerMove,
6863
+ params: ['handleSashCornerPointerMove', ClientX, ClientY]
6864
+ }, {
6865
+ name: HandleSashCornerPointerUp,
6866
+ params: ['handleSashCornerPointerUp', ClientX, ClientY]
6619
6867
  }];
6620
6868
  };
6621
6869
 
@@ -7199,6 +7447,9 @@ const commandMap = {
7199
7447
  'MainArea.handleModifiedStatusChange': wrapAsyncCommand(handleModifiedStatusChangeWithContext),
7200
7448
  'MainArea.handleResize': wrapGetter(handleResize),
7201
7449
  // TODO would need to have a function that returns newstate as well as commands
7450
+ 'MainArea.handleSashCornerPointerDown': wrapSerialCommand(handleSashCornerPointerDown),
7451
+ 'MainArea.handleSashCornerPointerMove': wrapSerialCommand(handleSashCornerPointerMove),
7452
+ 'MainArea.handleSashCornerPointerUp': wrapSerialCommand(handleSashCornerPointerUp),
7202
7453
  'MainArea.handleSashPointerDown': wrapSerialCommand(handleSashPointerDown),
7203
7454
  'MainArea.handleSashPointerMove': wrapSerialCommand(handleSashPointerMove),
7204
7455
  'MainArea.handleSashPointerUp': wrapSerialCommand(handleSashPointerUp),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.31.0",
3
+ "version": "9.32.1",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",