@lvce-editor/main-area-worker 8.20.0 → 8.21.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.
@@ -245,6 +245,36 @@ const closeAll$1 = state => {
245
245
  return withEmptyGroups(state);
246
246
  };
247
247
 
248
+ const redistributeSizesWithRemainder = groups => {
249
+ const baseSize = Math.floor(100 / groups.length);
250
+ const remainder = 100 % groups.length;
251
+ return groups.map((group, index) => ({
252
+ ...group,
253
+ size: baseSize + (index === groups.length - 1 ? remainder : 0)
254
+ }));
255
+ };
256
+
257
+ const closeEditorGroup$1 = (state, groupId) => {
258
+ if (Number.isNaN(groupId)) {
259
+ return state;
260
+ }
261
+ const {
262
+ layout
263
+ } = state;
264
+ const {
265
+ activeGroupId,
266
+ groups
267
+ } = layout;
268
+ const groupIndex = getGroupIndexById(state, groupId);
269
+ if (groupIndex === -1 || groups.length <= 1) {
270
+ return state;
271
+ }
272
+ const remainingGroups = groups.filter(group => group.id !== groupId);
273
+ const redistributedGroups = redistributeSizesWithRemainder(remainingGroups);
274
+ const newActiveGroupId = activeGroupId === groupId ? remainingGroups[0].id : activeGroupId;
275
+ return withGroupsAndActiveGroup(state, redistributedGroups, newActiveGroupId);
276
+ };
277
+
248
278
  const isFocused = group => {
249
279
  return group.focused;
250
280
  };
@@ -610,6 +640,7 @@ const EventTargetClassName = 'event.target.className';
610
640
  const TargetName = 'event.target.name';
611
641
 
612
642
  const Tab = 13;
643
+ const Main$1 = 24;
613
644
 
614
645
  const Separator = 1;
615
646
  const None = 0;
@@ -1278,7 +1309,7 @@ const focusPreviousTab = async state => {
1278
1309
  };
1279
1310
 
1280
1311
  const getMenuIds = () => {
1281
- return [Tab];
1312
+ return [Main$1, Tab];
1282
1313
  };
1283
1314
 
1284
1315
  const handleClick = async (state, name) => {
@@ -1288,36 +1319,6 @@ const handleClick = async (state, name) => {
1288
1319
  return state;
1289
1320
  };
1290
1321
 
1291
- const redistributeSizesWithRemainder = groups => {
1292
- const baseSize = Math.floor(100 / groups.length);
1293
- const remainder = 100 % groups.length;
1294
- return groups.map((group, index) => ({
1295
- ...group,
1296
- size: baseSize + (index === groups.length - 1 ? remainder : 0)
1297
- }));
1298
- };
1299
-
1300
- const closeEditorGroup$1 = (state, groupId) => {
1301
- if (Number.isNaN(groupId)) {
1302
- return state;
1303
- }
1304
- const {
1305
- layout
1306
- } = state;
1307
- const {
1308
- activeGroupId,
1309
- groups
1310
- } = layout;
1311
- const groupIndex = getGroupIndexById(state, groupId);
1312
- if (groupIndex === -1 || groups.length <= 1) {
1313
- return state;
1314
- }
1315
- const remainingGroups = groups.filter(group => group.id !== groupId);
1316
- const redistributedGroups = redistributeSizesWithRemainder(remainingGroups);
1317
- const newActiveGroupId = activeGroupId === groupId ? remainingGroups[0].id : activeGroupId;
1318
- return withGroupsAndActiveGroup(state, redistributedGroups, newActiveGroupId);
1319
- };
1320
-
1321
1322
  const getActiveGroup = (groups, activeGroupId) => {
1322
1323
  return groups.find(g => g.id === activeGroupId);
1323
1324
  };
@@ -2047,12 +2048,34 @@ const handleClickTab = async (state, groupIndexRaw, indexRaw) => {
2047
2048
  return selectTab(state, groupIndex, index);
2048
2049
  };
2049
2050
 
2051
+ const show2 = async (uid, menuId, x, y, args) => {
2052
+ await showContextMenu2(uid, menuId, x, y, args);
2053
+ };
2054
+
2055
+ const handleContextMenu = async (state, rawGroupId, x, y) => {
2056
+ number(x);
2057
+ number(y);
2058
+ if (!rawGroupId) {
2059
+ return state;
2060
+ }
2061
+ const groupId = Number.parseInt(rawGroupId, 10);
2062
+ if (Number.isNaN(groupId)) {
2063
+ return state;
2064
+ }
2065
+ await show2(state.uid, Main$1, x, y, {
2066
+ groupId,
2067
+ menuId: Main$1
2068
+ });
2069
+ return state;
2070
+ };
2071
+
2050
2072
  const handleDoubleClick = async state => {
2051
2073
  // TODO: implement handleDoubleClick
2052
2074
  return state;
2053
2075
  };
2054
2076
 
2055
2077
  const EditorGroupHeader = 'EditorGroupHeader';
2078
+ const EmptyGroupHeader = 'EmptyGroupHeader';
2056
2079
  const EmptyGroupCloseButton = 'EmptyGroupCloseButton';
2057
2080
  const EditorGroup = 'EditorGroup';
2058
2081
  const EditorGroupsHorizontal = 'EditorGroupsHorizontal';
@@ -2406,10 +2429,6 @@ const handleSashPointerUp = async state => {
2406
2429
  };
2407
2430
  };
2408
2431
 
2409
- const show2 = async (uid, menuId, x, y, args) => {
2410
- await showContextMenu2(uid, menuId, x, y, args);
2411
- };
2412
-
2413
2432
  const handleTabContextMenu = async (state, button, x, y) => {
2414
2433
  number(x);
2415
2434
  number(y);
@@ -3805,16 +3824,6 @@ const loadContent = async (state, savedState) => {
3805
3824
  };
3806
3825
  };
3807
3826
 
3808
- const findGroupById = (state, groupId) => {
3809
- const {
3810
- layout
3811
- } = state;
3812
- const {
3813
- groups
3814
- } = layout;
3815
- return groups.find(group => group.id === groupId);
3816
- };
3817
-
3818
3827
  const emptyObject = {};
3819
3828
  const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
3820
3829
  const i18nString = (key, placeholders = emptyObject) => {
@@ -3846,17 +3855,37 @@ const Pin = 'Pin';
3846
3855
  const SplitAndMove = 'Split & Move';
3847
3856
  const MoveIntoNewWindow = 'Move into New Window';
3848
3857
  const CopyIntoNewWindow = 'Copy into New Window';
3858
+ const NewWindow = 'New Window';
3859
+ const OpenFile = 'Open File';
3860
+ const SplitDown = 'Split Down';
3849
3861
  const SplitEditorGroup = 'Split Editor Group';
3862
+ const SplitLeft = 'Split Left';
3850
3863
  const SplitRight = 'Split Right';
3864
+ const SplitUp = 'Split Up';
3851
3865
  const TogglePreview = 'Toggle Preview';
3852
3866
  const Retry = 'Retry';
3853
3867
 
3868
+ const openFile = () => {
3869
+ return i18nString(OpenFile);
3870
+ };
3871
+ const splitUp$1 = () => {
3872
+ return i18nString(SplitUp);
3873
+ };
3874
+ const splitDown$1 = () => {
3875
+ return i18nString(SplitDown);
3876
+ };
3877
+ const splitLeft$1 = () => {
3878
+ return i18nString(SplitLeft);
3879
+ };
3854
3880
  const splitRight$1 = () => {
3855
3881
  return i18nString(SplitRight);
3856
3882
  };
3857
3883
  const splitEditorGroup = () => {
3858
3884
  return i18nString(SplitEditorGroup);
3859
3885
  };
3886
+ const newWindow = () => {
3887
+ return i18nString(NewWindow);
3888
+ };
3860
3889
  const close = () => {
3861
3890
  return i18nString(Close);
3862
3891
  };
@@ -3928,6 +3957,74 @@ const menuEntrySeparator = {
3928
3957
  label: ''
3929
3958
  };
3930
3959
 
3960
+ const QuickPick = 'QuickPick';
3961
+
3962
+ const getArgs = groupId => {
3963
+ if (groupId === undefined) {
3964
+ return undefined;
3965
+ }
3966
+ return [groupId];
3967
+ };
3968
+ const getMenuEntries$2 = groupId => {
3969
+ const groupArgs = getArgs(groupId);
3970
+ const entries = [{
3971
+ args: [QuickPick, 'file'],
3972
+ command: 'Viewlet.openWidget',
3973
+ flags: None,
3974
+ id: 'openFile',
3975
+ label: openFile()
3976
+ }, menuEntrySeparator, {
3977
+ args: groupArgs,
3978
+ command: 'MainArea.splitUp',
3979
+ flags: None,
3980
+ id: 'splitUp',
3981
+ label: splitUp$1()
3982
+ }, {
3983
+ args: groupArgs,
3984
+ command: 'MainArea.splitDown',
3985
+ flags: None,
3986
+ id: 'splitDown',
3987
+ label: splitDown$1()
3988
+ }, {
3989
+ args: groupArgs,
3990
+ command: 'MainArea.splitLeft',
3991
+ flags: None,
3992
+ id: 'splitLeft',
3993
+ label: splitLeft$1()
3994
+ }, {
3995
+ args: groupArgs,
3996
+ command: 'MainArea.splitRight',
3997
+ flags: None,
3998
+ id: 'splitRight',
3999
+ label: splitRight$1()
4000
+ }, menuEntrySeparator, {
4001
+ command: 'Main.newWindow',
4002
+ flags: None,
4003
+ id: 'newWindow',
4004
+ label: newWindow()
4005
+ }];
4006
+ if (groupId === undefined) {
4007
+ return entries;
4008
+ }
4009
+ return [...entries, menuEntrySeparator, {
4010
+ args: [groupId],
4011
+ command: 'MainArea.closeEditorGroup',
4012
+ flags: None,
4013
+ id: 'closeGroup',
4014
+ label: closeEditorGroup()
4015
+ }];
4016
+ };
4017
+
4018
+ const findGroupById = (state, groupId) => {
4019
+ const {
4020
+ layout
4021
+ } = state;
4022
+ const {
4023
+ groups
4024
+ } = layout;
4025
+ return groups.find(group => group.id === groupId);
4026
+ };
4027
+
3931
4028
  // TODO should pass tab uri as argument or tab index
3932
4029
  const getMenuEntries$1 = state => {
3933
4030
  const {
@@ -4055,6 +4152,8 @@ const getMenuEntries$1 = state => {
4055
4152
 
4056
4153
  const getMenuEntries = async (state, props) => {
4057
4154
  switch (props.menuId) {
4155
+ case Main$1:
4156
+ return getMenuEntries$2(props.groupId);
4058
4157
  case Tab:
4059
4158
  return getMenuEntries$1(state);
4060
4159
  default:
@@ -4418,6 +4517,7 @@ const renderContent = content => {
4418
4517
  }, text(content)];
4419
4518
  };
4420
4519
 
4520
+ const HandleContextMenu = 2;
4421
4521
  const HandleClickAction = 10;
4422
4522
  const HandleClick = 11;
4423
4523
  const HandleClickClose = 12;
@@ -4639,6 +4739,10 @@ const renderEditorGroupHeader = (group, groupIndex, splitButtonEnabled) => {
4639
4739
 
4640
4740
  const renderEmptyGroupCloseButton = (group, groupIndex) => {
4641
4741
  return [{
4742
+ childCount: 1,
4743
+ className: EmptyGroupHeader,
4744
+ type: Div
4745
+ }, {
4642
4746
  childCount: 1,
4643
4747
  className: EmptyGroupCloseButton,
4644
4748
  'data-groupId': String(group.id),
@@ -4649,14 +4753,16 @@ const renderEmptyGroupCloseButton = (group, groupIndex) => {
4649
4753
  }, text('✕')];
4650
4754
  };
4651
4755
 
4652
- const renderWaterMark = () => {
4756
+ const renderWaterMark = groupId => {
4653
4757
  return [{
4654
4758
  childCount: 1,
4655
4759
  className: 'WaterMarkWrapper',
4760
+ 'data-groupId': String(groupId),
4656
4761
  type: Div
4657
4762
  }, {
4658
4763
  childCount: 0,
4659
4764
  className: 'WaterMark',
4765
+ 'data-groupId': String(groupId),
4660
4766
  type: Div
4661
4767
  }];
4662
4768
  };
@@ -4665,10 +4771,12 @@ const renderEmptyEditorGroup = (group, groupIndex, style) => {
4665
4771
  return [{
4666
4772
  childCount: 2,
4667
4773
  className: EditorGroup,
4774
+ 'data-groupId': String(group.id),
4775
+ onContextMenu: HandleContextMenu,
4668
4776
  style,
4669
4777
  tabIndex: 0,
4670
4778
  type: Div
4671
- }, ...renderEmptyGroupCloseButton(group), ...renderWaterMark()];
4779
+ }, ...renderEmptyGroupCloseButton(group), ...renderWaterMark(group.id)];
4672
4780
  };
4673
4781
 
4674
4782
  const renderEditorGroup = (group, groupIndex, splitButtonEnabled = false, sizeProperty = 'width') => {
@@ -4701,8 +4809,9 @@ const renderSash = (direction, sashId, style) => {
4701
4809
  className: getSashClassName(direction),
4702
4810
  'data-sashId': sashId,
4703
4811
  onPointerDown: HandleSashPointerDown,
4812
+ role: 'none',
4704
4813
  style,
4705
- type: Div
4814
+ type: Button$2
4706
4815
  }, {
4707
4816
  childCount: 0,
4708
4817
  className: 'SashBorder',
@@ -4826,6 +4935,10 @@ const renderEventListeners = () => {
4826
4935
  }, {
4827
4936
  name: HandleClickTab,
4828
4937
  params: ['handleClickTab', 'event.target.dataset.groupIndex', 'event.target.dataset.index']
4938
+ }, {
4939
+ name: HandleContextMenu,
4940
+ params: ['handleContextMenu', 'event.target.dataset.groupId', ClientX, ClientY],
4941
+ preventDefault: true
4829
4942
  }, {
4830
4943
  name: HandleTabContextMenu,
4831
4944
  params: ['handleTabContextMenu', Button$1, ClientX, ClientY],
@@ -4937,6 +5050,38 @@ const splitDown = (state, groupId) => {
4937
5050
  return splitEditorGroup$1(state, resolvedGroupId, 'down');
4938
5051
  };
4939
5052
 
5053
+ const splitLeft = (state, groupId) => {
5054
+ const {
5055
+ layout
5056
+ } = state;
5057
+ const {
5058
+ activeGroupId,
5059
+ groups
5060
+ } = layout;
5061
+ if (groups.length === 0) {
5062
+ const initialGroupId = create$c();
5063
+ const initialGroup = {
5064
+ activeTabId: undefined,
5065
+ focused: true,
5066
+ id: initialGroupId,
5067
+ isEmpty: true,
5068
+ size: 100,
5069
+ tabs: []
5070
+ };
5071
+ const stateWithInitialGroup = {
5072
+ ...state,
5073
+ layout: {
5074
+ ...layout,
5075
+ activeGroupId: initialGroupId,
5076
+ groups: [initialGroup]
5077
+ }
5078
+ };
5079
+ return splitEditorGroup$1(stateWithInitialGroup, initialGroupId, Left);
5080
+ }
5081
+ const targetGroupId = groupId ?? activeGroupId ?? groups[0]?.id ?? 0;
5082
+ return splitEditorGroup$1(state, targetGroupId, Left);
5083
+ };
5084
+
4940
5085
  const splitRight = (state, groupId) => {
4941
5086
  const {
4942
5087
  layout
@@ -4971,10 +5116,45 @@ const splitRight = (state, groupId) => {
4971
5116
  return splitEditorGroup$1(state, targetGroupId, Right);
4972
5117
  };
4973
5118
 
5119
+ const splitUp = (state, groupId) => {
5120
+ const {
5121
+ layout
5122
+ } = state;
5123
+ const {
5124
+ groups
5125
+ } = layout;
5126
+ if (groups.length === 0) {
5127
+ const initialGroupId = create$c();
5128
+ const initialGroup = {
5129
+ activeTabId: undefined,
5130
+ focused: true,
5131
+ id: initialGroupId,
5132
+ isEmpty: true,
5133
+ size: 100,
5134
+ tabs: []
5135
+ };
5136
+ const stateWithInitialGroup = {
5137
+ ...state,
5138
+ layout: {
5139
+ ...layout,
5140
+ activeGroupId: initialGroupId,
5141
+ groups: [initialGroup]
5142
+ }
5143
+ };
5144
+ return splitEditorGroup$1(stateWithInitialGroup, initialGroupId, 'up');
5145
+ }
5146
+ const resolvedGroupId = groupId ?? state.layout.activeGroupId;
5147
+ if (!resolvedGroupId) {
5148
+ return state;
5149
+ }
5150
+ return splitEditorGroup$1(state, resolvedGroupId, 'up');
5151
+ };
5152
+
4974
5153
  const commandMap = {
4975
5154
  'MainArea.closeActiveEditor': wrapCommand(closeActiveEditor),
4976
5155
  'MainArea.closeAll': wrapCommand(closeAll$1),
4977
5156
  'MainArea.closeAllEditors': wrapCommand(closeAll$1),
5157
+ 'MainArea.closeEditorGroup': wrapCommand(closeEditorGroup$1),
4978
5158
  'MainArea.closeFocusedTab': wrapCommand(closeFocusedTab),
4979
5159
  'MainArea.closeOthers': wrapCommand(closeOtherTabs),
4980
5160
  'MainArea.closeSaved': wrapCommand(closeSaved$1),
@@ -4995,6 +5175,7 @@ const commandMap = {
4995
5175
  'MainArea.handleClickCloseTab': wrapCommand(handleClickCloseTab),
4996
5176
  'MainArea.handleClickTab': wrapCommand(handleClickTab),
4997
5177
  'MainArea.handleClickTogglePreview': wrapCommand(handleClickTogglePreview),
5178
+ 'MainArea.handleContextMenu': wrapCommand(handleContextMenu),
4998
5179
  'MainArea.handleDoubleClick': wrapCommand(handleDoubleClick),
4999
5180
  'MainArea.handleHeaderDoubleClick': wrapCommand(handleHeaderDoubleClick),
5000
5181
  'MainArea.handleModifiedStatusChange': wrapCommand(handleModifiedStatusChange),
@@ -5019,7 +5200,9 @@ const commandMap = {
5019
5200
  'MainArea.saveState': wrapGetter(saveState),
5020
5201
  'MainArea.selectTab': wrapCommand(selectTab),
5021
5202
  'MainArea.splitDown': wrapCommand(splitDown),
5203
+ 'MainArea.splitLeft': wrapCommand(splitLeft),
5022
5204
  'MainArea.splitRight': wrapCommand(splitRight),
5205
+ 'MainArea.splitUp': wrapCommand(splitUp),
5023
5206
  'MainArea.terminate': terminate
5024
5207
  };
5025
5208
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "8.20.0",
3
+ "version": "8.21.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",