@lvce-editor/main-area-worker 9.2.0 → 9.4.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.
@@ -1716,6 +1716,8 @@ const Main$1 = 24;
1716
1716
  const Separator = 1;
1717
1717
  const None = 0;
1718
1718
 
1719
+ const Electron = 2;
1720
+
1719
1721
  const ClipBoardWorker = 3400;
1720
1722
  const ExtensionHostWorker = 44;
1721
1723
  const IconThemeWorker = 7009;
@@ -3194,13 +3196,14 @@ const show2 = async (uid, menuId, x, y, args) => {
3194
3196
  await showContextMenu2(uid, menuId, x, y, args);
3195
3197
  };
3196
3198
 
3199
+ const NoGroupId = -1;
3197
3200
  const handleContextMenu = async (state, rawGroupId, x, y) => {
3198
3201
  number(x);
3199
3202
  number(y);
3200
- if (!rawGroupId) {
3203
+ if (rawGroupId === undefined) {
3201
3204
  return state;
3202
3205
  }
3203
- const groupId = Number.parseInt(rawGroupId, 10);
3206
+ const groupId = rawGroupId === '' ? NoGroupId : Number.parseInt(rawGroupId, 10);
3204
3207
  if (Number.isNaN(groupId)) {
3205
3208
  return state;
3206
3209
  }
@@ -3458,8 +3461,7 @@ const handleResize = async (state, dimensions) => {
3458
3461
  // Resize all editor children to their new bounds
3459
3462
  const {
3460
3463
  layout,
3461
- tabHeight,
3462
- uid
3464
+ tabHeight
3463
3465
  } = state;
3464
3466
  const {
3465
3467
  groups
@@ -3483,7 +3485,6 @@ const handleResize = async (state, dimensions) => {
3483
3485
  }
3484
3486
  }
3485
3487
  }
3486
- allResizeCommands.push(['Viewlet.setBounds', uid, x, y, width, height]);
3487
3488
  return allResizeCommands;
3488
3489
  };
3489
3490
 
@@ -3991,7 +3992,7 @@ const splitRight$1 = () => {
3991
3992
  const splitEditorGroup = () => {
3992
3993
  return i18nString(SplitEditorGroup);
3993
3994
  };
3994
- const newWindow = () => {
3995
+ const newWindow$1 = () => {
3995
3996
  return i18nString(NewWindow);
3996
3997
  };
3997
3998
  const close = () => {
@@ -4065,13 +4066,27 @@ const menuEntrySeparator = {
4065
4066
  label: ''
4066
4067
  };
4067
4068
 
4069
+ const hasTargetGroup = groupId => {
4070
+ return groupId !== undefined && groupId >= 0;
4071
+ };
4068
4072
  const getArgs = groupId => {
4069
- if (groupId === undefined) {
4073
+ if (!hasTargetGroup(groupId)) {
4070
4074
  return undefined;
4071
4075
  }
4072
4076
  return [groupId];
4073
4077
  };
4074
- const getMenuEntries$2 = groupId => {
4078
+ const getNewWindowMenuEntries = state => {
4079
+ if (state.platform !== Electron) {
4080
+ return [];
4081
+ }
4082
+ return [menuEntrySeparator, {
4083
+ command: 'MainArea.newWindow',
4084
+ flags: None,
4085
+ id: 'newWindow',
4086
+ label: newWindow$1()
4087
+ }];
4088
+ };
4089
+ const getMenuEntries$2 = (state, groupId) => {
4075
4090
  const groupArgs = getArgs(groupId);
4076
4091
  const entries = [{
4077
4092
  args: [QuickPick, 'file'],
@@ -4103,13 +4118,8 @@ const getMenuEntries$2 = groupId => {
4103
4118
  flags: None,
4104
4119
  id: 'splitRight',
4105
4120
  label: splitRight$1()
4106
- }, menuEntrySeparator, {
4107
- command: 'Main.newWindow',
4108
- flags: None,
4109
- id: 'newWindow',
4110
- label: newWindow()
4111
- }];
4112
- if (groupId === undefined) {
4121
+ }, ...getNewWindowMenuEntries(state)];
4122
+ if (!hasTargetGroup(groupId)) {
4113
4123
  return entries;
4114
4124
  }
4115
4125
  return [...entries, menuEntrySeparator, {
@@ -4259,7 +4269,7 @@ const getMenuEntries$1 = state => {
4259
4269
  const getMenuEntries = async (state, props) => {
4260
4270
  switch (props.menuId) {
4261
4271
  case Main$1:
4262
- return getMenuEntries$2(props.groupId);
4272
+ return getMenuEntries$2(state, props.groupId);
4263
4273
  case Tab:
4264
4274
  return getMenuEntries$1(state);
4265
4275
  default:
@@ -4267,6 +4277,11 @@ const getMenuEntries = async (state, props) => {
4267
4277
  }
4268
4278
  };
4269
4279
 
4280
+ const newWindow = async state => {
4281
+ await invoke('Main.newWindow');
4282
+ return state;
4283
+ };
4284
+
4270
4285
  const openUris = async (state, uris) => {
4271
4286
  if (uris.length === 0) {
4272
4287
  return state;
@@ -4295,19 +4310,54 @@ const refresh = state => {
4295
4310
  };
4296
4311
  };
4297
4312
 
4298
- const getCss = () => {
4313
+ const getEditorGroupCss = layout => {
4314
+ const groupSizeVariable = layout.direction === Vertical ? '--EditorGroupHeight' : '--EditorGroupWidth';
4315
+ return layout.groups.map(group => {
4316
+ return `.EditorGroup[data-groupId="${group.id}"] {
4317
+ ${groupSizeVariable}: ${group.size}%;
4318
+ }`;
4319
+ });
4320
+ };
4321
+ const getSashCss = layout => {
4322
+ if (layout.groups.length <= 1) {
4323
+ return [];
4324
+ }
4325
+ const sashPositionVariable = layout.direction === Horizontal ? '--SashLeft' : '--SashTop';
4326
+ const rules = [];
4327
+ let sashOffset = 0;
4328
+ for (let i = 1; i < layout.groups.length; i++) {
4329
+ sashOffset += layout.groups[i - 1].size;
4330
+ const beforeGroupId = layout.groups[i - 1].id;
4331
+ const afterGroupId = layout.groups[i].id;
4332
+ const sashId = create(beforeGroupId, afterGroupId);
4333
+ rules.push(`.Sash[data-sashId="${sashId}"] {
4334
+ ${sashPositionVariable}: ${sashOffset}%;
4335
+ }`);
4336
+ }
4337
+ return rules;
4338
+ };
4339
+ const getCss = layout => {
4299
4340
  const rules = [`.MainArea {
4300
4341
  }`, `.editor-groups-container {
4301
4342
  overflow: auto;
4302
4343
  }`, `.EditorGroup {
4303
4344
  min-width: 250px;
4345
+ width: var(--EditorGroupWidth, auto);
4346
+ height: var(--EditorGroupHeight, auto);
4347
+ }`, `.SashVertical {
4348
+ left: var(--SashLeft);
4349
+ }`, `.SashHorizontal {
4350
+ top: var(--SashTop);
4304
4351
  }`];
4352
+ if (layout) {
4353
+ rules.push(...getEditorGroupCss(layout), ...getSashCss(layout));
4354
+ }
4305
4355
  const css = rules.join('\n');
4306
4356
  return css;
4307
4357
  };
4308
4358
 
4309
4359
  const renderCss = (oldState, newState) => {
4310
- const css = getCss();
4360
+ const css = getCss(newState.layout);
4311
4361
  return [SetCss, newState.uid, css];
4312
4362
  };
4313
4363
 
@@ -4610,6 +4660,36 @@ const diffTree = (oldNodes, newNodes) => {
4610
4660
  return removeTrailingNavigationPatches(patches);
4611
4661
  };
4612
4662
 
4663
+ const HandleContextMenu = 2;
4664
+ const HandleClickAction = 10;
4665
+ const HandleClick = 11;
4666
+ const HandleClickClose = 12;
4667
+ const HandleClickTab = 13;
4668
+ const HandleTabContextMenu = 14;
4669
+ const HandleHeaderDoubleClick = 15;
4670
+ const HandleSashPointerDown = 16;
4671
+ const HandleSashPointerMove = 17;
4672
+ const HandleSashPointerUp = 18;
4673
+
4674
+ const MIN_GROUP_WIDTH_PX = 250;
4675
+ const getSashOffset = (layout, groupIndex, width) => {
4676
+ const {
4677
+ direction,
4678
+ groups
4679
+ } = layout;
4680
+ const percentOffset = groups.slice(0, groupIndex).reduce((total, group) => total + group.size, 0);
4681
+ if (direction !== Horizontal || !width || !Number.isFinite(width)) {
4682
+ return `${percentOffset}%`;
4683
+ }
4684
+ const effectiveGroupSizes = groups.map(group => Math.max(group.size / 100 * width, MIN_GROUP_WIDTH_PX));
4685
+ const hasOverflowingGroups = effectiveGroupSizes.some((size, index) => size !== groups[index].size / 100 * width);
4686
+ if (!hasOverflowingGroups) {
4687
+ return `${percentOffset}%`;
4688
+ }
4689
+ const pixelOffset = effectiveGroupSizes.slice(0, groupIndex).reduce((total, size) => total + size, 0);
4690
+ return `${pixelOffset}px`;
4691
+ };
4692
+
4613
4693
  const renderContent = content => {
4614
4694
  return [{
4615
4695
  childCount: 1,
@@ -4622,17 +4702,6 @@ const renderContent = content => {
4622
4702
  }, text(content)];
4623
4703
  };
4624
4704
 
4625
- const HandleContextMenu = 2;
4626
- const HandleClickAction = 10;
4627
- const HandleClick = 11;
4628
- const HandleClickClose = 12;
4629
- const HandleClickTab = 13;
4630
- const HandleTabContextMenu = 14;
4631
- const HandleHeaderDoubleClick = 15;
4632
- const HandleSashPointerDown = 16;
4633
- const HandleSashPointerMove = 17;
4634
- const HandleSashPointerUp = 18;
4635
-
4636
4705
  const renderError = errorMessage => {
4637
4706
  return [{
4638
4707
  childCount: 2,
@@ -4895,6 +4964,7 @@ const renderEditorGroup = (group, groupIndex, splitButtonEnabled = false, sizePr
4895
4964
  return [{
4896
4965
  childCount: 2,
4897
4966
  className: EditorGroup,
4967
+ 'data-groupId': String(group.id),
4898
4968
  style,
4899
4969
  type: Div
4900
4970
  }, ...renderEditorGroupHeader(group, groupIndex, splitButtonEnabled), {
@@ -4924,7 +4994,7 @@ const renderSash = (direction, sashId, style) => {
4924
4994
  }];
4925
4995
  };
4926
4996
 
4927
- const renderSingleEditorGroup = (layout, splitButtonEnabled, sizeProperty) => {
4997
+ const renderSingleEditorGroup = (layout, splitButtonEnabled, sizeProperty = 'width') => {
4928
4998
  return [{
4929
4999
  childCount: 1,
4930
5000
  className: Main,
@@ -4932,24 +5002,6 @@ const renderSingleEditorGroup = (layout, splitButtonEnabled, sizeProperty) => {
4932
5002
  }, ...renderEditorGroup(layout.groups[0], 0, splitButtonEnabled, sizeProperty)];
4933
5003
  };
4934
5004
 
4935
- const MIN_GROUP_WIDTH_PX = 250;
4936
- const getSashOffset = (layout, groupIndex, width) => {
4937
- const {
4938
- direction,
4939
- groups
4940
- } = layout;
4941
- const percentOffset = groups.slice(0, groupIndex).reduce((total, group) => total + group.size, 0);
4942
- if (direction !== Horizontal || !width || !Number.isFinite(width)) {
4943
- return `${percentOffset}%`;
4944
- }
4945
- const effectiveGroupSizes = groups.map(group => Math.max(group.size / 100 * width, MIN_GROUP_WIDTH_PX));
4946
- const hasOverflowingGroups = effectiveGroupSizes.some((size, index) => size !== groups[index].size / 100 * width);
4947
- if (!hasOverflowingGroups) {
4948
- return `${percentOffset}%`;
4949
- }
4950
- const pixelOffset = effectiveGroupSizes.slice(0, groupIndex).reduce((total, size) => total + size, 0);
4951
- return `${pixelOffset}px`;
4952
- };
4953
5005
  const getMainAreaVirtualDom = (layout, splitButtonEnabled = false, width = 0) => {
4954
5006
  const {
4955
5007
  direction,
@@ -4963,6 +5015,20 @@ const getMainAreaVirtualDom = (layout, splitButtonEnabled = false, width = 0) =>
4963
5015
  const isSplit = groups.length > 1;
4964
5016
  const directionClassName = isSplit ? direction === Horizontal ? EditorGroupsVertical : EditorGroupsHorizontal : '';
4965
5017
  const editorGroupsContainerClassName = directionClassName ? `${EDITOR_GROUPS_CONTAINER} ${directionClassName}` : EDITOR_GROUPS_CONTAINER;
5018
+ if (groups.length === 0) {
5019
+ return [{
5020
+ childCount: 1,
5021
+ className: Main,
5022
+ type: Div
5023
+ }, {
5024
+ childCount: 0,
5025
+ className: editorGroupsContainerClassName,
5026
+ 'data-groupId': '',
5027
+ onContextMenu: HandleContextMenu,
5028
+ role: None$1,
5029
+ type: Div
5030
+ }];
5031
+ }
4966
5032
  let childCount = 0;
4967
5033
  for (let i = 0; i < groups.length; i++) {
4968
5034
  if (i > 0) {
@@ -5110,18 +5176,18 @@ const save = async state => {
5110
5176
  });
5111
5177
  };
5112
5178
 
5179
+ const getFilteredGroups = groups => {
5180
+ return groups.map(group => ({
5181
+ ...group,
5182
+ tabs: group.tabs.filter(tab => !tab.uri?.startsWith('untitled://'))
5183
+ })).filter(group => group.tabs.length > 0);
5184
+ };
5185
+
5113
5186
  const saveState = state => {
5114
5187
  const {
5115
5188
  layout
5116
5189
  } = state;
5117
-
5118
- // Filter out untitled editors from tabs
5119
- const filteredGroups = layout.groups.map(group => ({
5120
- ...group,
5121
- tabs: group.tabs.filter(tab => !tab.uri?.startsWith('untitled://'))
5122
- }))
5123
- // Remove groups that become empty after filtering
5124
- .filter(group => group.tabs.length > 0);
5190
+ const filteredGroups = getFilteredGroups(layout.groups);
5125
5191
 
5126
5192
  // Update activeGroupId if it points to a removed group
5127
5193
  const {
@@ -5314,6 +5380,7 @@ const commandMap = {
5314
5380
  'MainArea.initialize': initialize,
5315
5381
  'MainArea.loadContent': wrapCommand(loadContent),
5316
5382
  'MainArea.newFile': wrapCommand(newFile),
5383
+ 'MainArea.newWindow': wrapCommand(newWindow),
5317
5384
  'MainArea.openInput': wrapCommand(openInput),
5318
5385
  'MainArea.openUri': wrapCommand(openUri),
5319
5386
  'MainArea.openUris': wrapCommand(openUris),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.2.0",
3
+ "version": "9.4.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",