@lvce-editor/main-area-worker 8.11.0 → 8.13.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.
@@ -273,9 +273,12 @@ const getGroupById = (state, groupId) => {
273
273
  };
274
274
 
275
275
  const closeTabsRight = (state, groupId) => {
276
+ const {
277
+ layout
278
+ } = state;
276
279
  const {
277
280
  groups
278
- } = state.layout;
281
+ } = layout;
279
282
  const group = getGroupById(state, groupId);
280
283
  if (!group) {
281
284
  return state;
@@ -1707,7 +1710,7 @@ const create$2 = (uid, uri, x, y, width, height, platform, assetDir, tabHeight =
1707
1710
  };
1708
1711
 
1709
1712
  const isEqual$1 = (oldState, newState) => {
1710
- return oldState.width === newState.width && oldState.height === newState.height;
1713
+ return false;
1711
1714
  };
1712
1715
 
1713
1716
  const isEqual = (oldState, newState) => {
@@ -2287,10 +2290,13 @@ const closeEditorGroup$1 = (state, groupId) => {
2287
2290
  if (Number.isNaN(groupId)) {
2288
2291
  return state;
2289
2292
  }
2293
+ const {
2294
+ layout
2295
+ } = state;
2290
2296
  const {
2291
2297
  activeGroupId,
2292
2298
  groups
2293
- } = state.layout;
2299
+ } = layout;
2294
2300
  const groupIndex = getGroupIndexById(state, groupId);
2295
2301
  if (groupIndex === -1 || groups.length <= 1) {
2296
2302
  return state;
@@ -2848,6 +2854,19 @@ const retryOpen = async state => {
2848
2854
  return openUri(state, tab.uri);
2849
2855
  };
2850
2856
 
2857
+ const rebalanceGroupSizes = groups => {
2858
+ const groupCount = groups.length;
2859
+ if (groupCount === 0) {
2860
+ return [];
2861
+ }
2862
+ const evenSize = Number((100 / groupCount).toFixed(6));
2863
+ const assignedSize = Number((evenSize * (groupCount - 1)).toFixed(6));
2864
+ const lastSize = Number((100 - assignedSize).toFixed(6));
2865
+ return groups.map((group, index) => ({
2866
+ ...group,
2867
+ size: index === groupCount - 1 ? lastSize : evenSize
2868
+ }));
2869
+ };
2851
2870
  const splitEditorGroup$1 = (state, groupId, direction) => {
2852
2871
  const {
2853
2872
  layout
@@ -2887,24 +2906,32 @@ const splitEditorGroup$1 = (state, groupId, direction) => {
2887
2906
  const sourceIndex = updatedGroups.findIndex(group => group.id === groupId);
2888
2907
  reorderedGroups = [...updatedGroups.slice(0, sourceIndex), newGroup, ...updatedGroups.slice(sourceIndex)];
2889
2908
  }
2909
+ const resizedGroups = rebalanceGroupSizes(reorderedGroups);
2890
2910
  return {
2891
2911
  ...state,
2892
2912
  layout: {
2893
2913
  activeGroupId: newGroupId,
2894
2914
  direction: newLayoutDirection,
2895
- groups: reorderedGroups
2915
+ groups: resizedGroups
2896
2916
  }
2897
2917
  };
2898
2918
  };
2899
2919
 
2900
2920
  const handleClickAction = async (state, action, rawGroupId) => {
2921
+ const {
2922
+ layout
2923
+ } = state;
2924
+ const {
2925
+ activeGroupId,
2926
+ groups
2927
+ } = layout;
2901
2928
  if (!action) {
2902
2929
  return state;
2903
2930
  }
2904
- if (state.layout.activeGroupId === undefined) {
2931
+ if (activeGroupId === undefined) {
2905
2932
  return state;
2906
2933
  }
2907
- const activeGroup = getActiveGroup(state.layout.groups, state.layout.activeGroupId);
2934
+ const activeGroup = getActiveGroup(groups, activeGroupId);
2908
2935
  if (!activeGroup) {
2909
2936
  return state;
2910
2937
  }
@@ -3235,16 +3262,27 @@ const handleSashPointerDown = async (state, sashId, clientX, clientY) => {
3235
3262
  };
3236
3263
  };
3237
3264
 
3238
- const MIN_GROUP_SIZE = 10;
3265
+ const MIN_GROUP_WIDTH_PX = 250;
3239
3266
  const clamp = (value, min, max) => {
3240
3267
  return Math.min(max, Math.max(min, value));
3241
3268
  };
3242
3269
  const round = value => {
3243
3270
  return Math.round(value * 100) / 100;
3244
3271
  };
3272
+ const getMinGroupSizePercent = axisSize => {
3273
+ if (!axisSize) {
3274
+ return 10;
3275
+ }
3276
+ const minPercent = MIN_GROUP_WIDTH_PX / axisSize * 100;
3277
+ // Ensure minimum is at least 10%, matching the CSS 250px constraint on typical widths
3278
+ return Math.max(minPercent, 10);
3279
+ };
3245
3280
  const handleSashPointerMove = async (state, clientX, clientY) => {
3246
3281
  const {
3247
- sashDrag
3282
+ height,
3283
+ layout,
3284
+ sashDrag,
3285
+ width
3248
3286
  } = state;
3249
3287
  if (!sashDrag) {
3250
3288
  return state;
@@ -3252,16 +3290,26 @@ const handleSashPointerMove = async (state, clientX, clientY) => {
3252
3290
  if (!Number.isFinite(clientX) || !Number.isFinite(clientY)) {
3253
3291
  return state;
3254
3292
  }
3255
- const axisSize = state.layout.direction === 'horizontal' ? state.width : state.height;
3293
+ const {
3294
+ direction,
3295
+ groups
3296
+ } = layout;
3297
+ const axisSize = direction === 'horizontal' ? width : height;
3256
3298
  if (!axisSize) {
3257
3299
  return state;
3258
3300
  }
3259
- const deltaPx = state.layout.direction === 'horizontal' ? clientX - sashDrag.startClientX : clientY - sashDrag.startClientY;
3301
+ const deltaPx = direction === 'horizontal' ? clientX - sashDrag.startClientX : clientY - sashDrag.startClientY;
3260
3302
  const deltaPercent = deltaPx / axisSize * 100;
3261
3303
  const totalResizableSize = sashDrag.beforeSize + sashDrag.afterSize;
3262
- const beforeSize = clamp(sashDrag.beforeSize + deltaPercent, MIN_GROUP_SIZE, totalResizableSize - MIN_GROUP_SIZE);
3304
+ let minGroupSize = getMinGroupSizePercent(axisSize);
3305
+
3306
+ // If the minimum size makes it impossible to fit two groups, relax the constraint
3307
+ if (2 * minGroupSize > totalResizableSize) {
3308
+ minGroupSize = totalResizableSize / 2;
3309
+ }
3310
+ const beforeSize = clamp(sashDrag.beforeSize + deltaPercent, minGroupSize, totalResizableSize - minGroupSize);
3263
3311
  const afterSize = totalResizableSize - beforeSize;
3264
- const groups = state.layout.groups.map(group => {
3312
+ const newGroups = groups.map(group => {
3265
3313
  if (group.id === sashDrag.beforeGroupId) {
3266
3314
  return {
3267
3315
  ...group,
@@ -3279,8 +3327,8 @@ const handleSashPointerMove = async (state, clientX, clientY) => {
3279
3327
  return {
3280
3328
  ...state,
3281
3329
  layout: {
3282
- ...state.layout,
3283
- groups
3330
+ ...layout,
3331
+ groups: newGroups
3284
3332
  }
3285
3333
  };
3286
3334
  };
@@ -3500,7 +3548,10 @@ const createViewlets = async (layout, viewletModuleIds, bounds) => {
3500
3548
  const getViewletModuleIds = async layout => {
3501
3549
  const viewletModuleIds = {};
3502
3550
  for (const group of layout.groups) {
3503
- const activeTab = group.tabs.find(tab => tab.id === group.activeTabId);
3551
+ const {
3552
+ tabs
3553
+ } = group;
3554
+ const activeTab = tabs.find(tab => tab.id === group.activeTabId);
3504
3555
  if (activeTab && activeTab.uri) {
3505
3556
  const viewletModuleId = await getViewletModuleId(activeTab.uri);
3506
3557
  if (viewletModuleId) {
@@ -3775,26 +3826,9 @@ const refresh = state => {
3775
3826
  const getCss = () => {
3776
3827
  const rules = [`.MainArea {
3777
3828
  }`, `.editor-groups-container {
3778
- position: relative;
3779
- }`, `.Sash {
3780
- position: absolute;
3781
- z-index: 1;
3782
- }`, `.SashVertical {
3783
- top: 0;
3784
- bottom: 0;
3785
- width: 0;
3786
- cursor: col-resize;
3787
- }`, `.SashVertical:hover {
3788
- width: 4px;
3789
- margin-left: -2px;
3790
- }`, `.SashHorizontal {
3791
- left: 0;
3792
- right: 0;
3793
- height: 0;
3794
- cursor: row-resize;
3795
- }`, `.SashHorizontal:hover {
3796
- height: 4px;
3797
- margin-top: -2px;
3829
+ overflow: auto;
3830
+ }`, `.EditorGroup {
3831
+ min-width: 250px;
3798
3832
  }`];
3799
3833
  const css = rules.join('\n');
3800
3834
  return css;
@@ -4336,13 +4370,25 @@ const renderEmptyGroupCloseButton = (group, groupIndex) => {
4336
4370
  }, text('✕')];
4337
4371
  };
4338
4372
 
4339
- const renderEmptyEditorGroup = (group, groupIndex, style) => {
4373
+ const renderWaterMark = () => {
4340
4374
  return [{
4341
4375
  childCount: 1,
4376
+ className: 'WaterMarkWrapper',
4377
+ type: Div
4378
+ }, {
4379
+ childCount: 0,
4380
+ className: 'WaterMark',
4381
+ type: Div
4382
+ }];
4383
+ };
4384
+
4385
+ const renderEmptyEditorGroup = (group, groupIndex, style) => {
4386
+ return [{
4387
+ childCount: 2,
4342
4388
  className: EditorGroup,
4343
4389
  style,
4344
4390
  type: Div
4345
- }, ...renderEmptyGroupCloseButton(group)];
4391
+ }, ...renderEmptyGroupCloseButton(group), ...renderWaterMark()];
4346
4392
  };
4347
4393
 
4348
4394
  const renderEditorGroup = (group, groupIndex, splitButtonEnabled = false, sizeProperty = 'width') => {
@@ -4365,10 +4411,13 @@ const renderEditorGroup = (group, groupIndex, splitButtonEnabled = false, sizePr
4365
4411
  }, ...renderEditor(activeTab)];
4366
4412
  };
4367
4413
 
4414
+ const getSashClassName = direction => {
4415
+ return direction === 'horizontal' ? 'Sash SashVertical' : 'Sash SashHorizontal';
4416
+ };
4368
4417
  const renderSash = (direction, sashId, style) => {
4369
4418
  return [{
4370
4419
  childCount: 0,
4371
- className: direction === 'horizontal' ? 'Sash SashVertical' : 'Sash SashHorizontal',
4420
+ className: getSashClassName(direction),
4372
4421
  'data-sashId': sashId,
4373
4422
  onPointerDown: HandleSashPointerDown,
4374
4423
  style,
@@ -4398,6 +4447,7 @@ const getMainAreaVirtualDom = (layout, splitButtonEnabled = false) => {
4398
4447
  const directionClassName = isSplit ? direction === 'horizontal' ? EditorGroupsVertical : EditorGroupsHorizontal : '';
4399
4448
  const editorGroupsContainerClassName = directionClassName ? `${EDITOR_GROUPS_CONTAINER} ${directionClassName}` : EDITOR_GROUPS_CONTAINER;
4400
4449
  let sashOffset = 0;
4450
+ let childCount = 0;
4401
4451
  for (let i = 0; i < groups.length; i++) {
4402
4452
  sashOffset += groups[i].size;
4403
4453
  if (i > 0) {
@@ -4407,15 +4457,17 @@ const getMainAreaVirtualDom = (layout, splitButtonEnabled = false) => {
4407
4457
  const sashId = create(beforeGroupId, afterGroupId);
4408
4458
  const style = direction === 'horizontal' ? `left:${sashOffset - groups[i].size}%;` : `top:${sashOffset - groups[i].size}%;`;
4409
4459
  children.push(...renderSash(direction, sashId, style));
4460
+ childCount++;
4410
4461
  }
4411
4462
  children.push(...renderEditorGroup(groups[i], i, splitButtonEnabled, sizeProperty));
4463
+ childCount++;
4412
4464
  }
4413
4465
  return [{
4414
4466
  childCount: 1,
4415
4467
  className: Main,
4416
4468
  type: Div
4417
4469
  }, {
4418
- childCount: children.length,
4470
+ childCount,
4419
4471
  className: editorGroupsContainerClassName,
4420
4472
  role: None$1,
4421
4473
  type: Div
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "8.11.0",
3
+ "version": "8.13.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",