@lvce-editor/main-area-worker 9.7.0 → 9.9.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.
@@ -2479,6 +2479,14 @@ const RetryOpen = 'retry-open';
2479
2479
  const SplitRight$1 = 'split-right';
2480
2480
  const TogglePreview$1 = 'toggle-preview';
2481
2481
 
2482
+ const parseRawGroupId = rawGroupId => {
2483
+ if (!rawGroupId) {
2484
+ return undefined;
2485
+ }
2486
+ const groupId = Number.parseFloat(rawGroupId);
2487
+ return Number.isNaN(groupId) ? undefined : groupId;
2488
+ };
2489
+
2482
2490
  const getBasename$1 = uri => {
2483
2491
  const lastSlashIndex = uri.lastIndexOf('/');
2484
2492
  if (lastSlashIndex === -1) {
@@ -3128,6 +3136,39 @@ const retryOpen = async state => {
3128
3136
  return openUri(state, tab.uri);
3129
3137
  };
3130
3138
 
3139
+ const getSegmentSize = segment => {
3140
+ return segment.groups.reduce((total, group) => total + group.size, 0);
3141
+ };
3142
+ const getGroupSegments = (groups, parentDirection) => {
3143
+ const segments = [];
3144
+ let index = 0;
3145
+ while (index < groups.length) {
3146
+ const group = groups[index];
3147
+ if (group.direction !== undefined && group.direction !== parentDirection) {
3148
+ const startIndex = index;
3149
+ const nestedGroups = [group];
3150
+ index++;
3151
+ while (index < groups.length && groups[index].direction === group.direction) {
3152
+ nestedGroups.push(groups[index]);
3153
+ index++;
3154
+ }
3155
+ segments.push({
3156
+ direction: group.direction,
3157
+ groups: nestedGroups,
3158
+ startIndex
3159
+ });
3160
+ continue;
3161
+ }
3162
+ segments.push({
3163
+ direction: undefined,
3164
+ groups: [group],
3165
+ startIndex: index
3166
+ });
3167
+ index++;
3168
+ }
3169
+ return segments;
3170
+ };
3171
+
3131
3172
  const rebalanceGroupSizes = groups => {
3132
3173
  const groupCount = groups.length;
3133
3174
  if (groupCount === 0) {
@@ -3141,6 +3182,111 @@ const rebalanceGroupSizes = groups => {
3141
3182
  size: index === groupCount - 1 ? lastSize : evenSize
3142
3183
  }));
3143
3184
  };
3185
+ const isTrailingSplit = direction => {
3186
+ return direction === Right || direction === 'down';
3187
+ };
3188
+ const getSplitLayoutDirection = direction => {
3189
+ return direction === Left || direction === Right ? Horizontal : Vertical;
3190
+ };
3191
+ const createNextState = (state, activeGroupId, groups) => {
3192
+ return {
3193
+ ...state,
3194
+ layout: {
3195
+ activeGroupId,
3196
+ direction: state.layout.direction,
3197
+ groups
3198
+ }
3199
+ };
3200
+ };
3201
+ const splitOnlyGroup = (state, groups, groupId, newGroupId, direction, splitLayoutDirection, baseNewGroup) => {
3202
+ const updatedGroups = groups.map(group => {
3203
+ if (group.id === groupId) {
3204
+ return {
3205
+ ...group,
3206
+ direction: undefined,
3207
+ focused: false,
3208
+ size: 50
3209
+ };
3210
+ }
3211
+ return group;
3212
+ });
3213
+ const newGroup = {
3214
+ ...baseNewGroup,
3215
+ direction: undefined,
3216
+ size: 50
3217
+ };
3218
+ const reorderedGroups = isTrailingSplit(direction) ? [...updatedGroups, newGroup] : [newGroup, ...updatedGroups];
3219
+ return {
3220
+ ...state,
3221
+ layout: {
3222
+ activeGroupId: newGroupId,
3223
+ direction: splitLayoutDirection,
3224
+ groups: reorderedGroups
3225
+ }
3226
+ };
3227
+ };
3228
+ const splitWithinMatchingNestedDirection = (state, groups, sourceGroup, groupId, newGroupId, direction, splitLayoutDirection, baseNewGroup) => {
3229
+ const sourceIndex = groups.findIndex(group => group.id === groupId);
3230
+ const updatedGroups = groups.map(group => {
3231
+ if (group.id === groupId) {
3232
+ return {
3233
+ ...group,
3234
+ focused: false,
3235
+ size: Number((group.size / 2).toFixed(6))
3236
+ };
3237
+ }
3238
+ return group;
3239
+ });
3240
+ const newGroup = {
3241
+ ...baseNewGroup,
3242
+ direction: splitLayoutDirection,
3243
+ size: Number((sourceGroup.size / 2).toFixed(6))
3244
+ };
3245
+ const insertIndex = isTrailingSplit(direction) ? sourceIndex + 1 : sourceIndex;
3246
+ const reorderedGroups = [...updatedGroups.slice(0, insertIndex), newGroup, ...updatedGroups.slice(insertIndex)];
3247
+ return createNextState(state, newGroupId, reorderedGroups);
3248
+ };
3249
+ const splitStandaloneSourceIntoNestedDirection = (state, groups, sourceGroup, groupId, newGroupId, direction, splitLayoutDirection, baseNewGroup) => {
3250
+ const sourceIndex = groups.findIndex(group => group.id === groupId);
3251
+ const halfSize = Number((sourceGroup.size / 2).toFixed(6));
3252
+ const updatedSourceGroup = {
3253
+ ...sourceGroup,
3254
+ direction: splitLayoutDirection,
3255
+ focused: false,
3256
+ size: halfSize
3257
+ };
3258
+ const newGroup = {
3259
+ ...baseNewGroup,
3260
+ direction: splitLayoutDirection,
3261
+ size: Number((sourceGroup.size - halfSize).toFixed(6))
3262
+ };
3263
+ const replacementGroups = isTrailingSplit(direction) ? [updatedSourceGroup, newGroup] : [newGroup, updatedSourceGroup];
3264
+ const reorderedGroups = [...groups.slice(0, sourceIndex), ...replacementGroups, ...groups.slice(sourceIndex + 1)];
3265
+ return createNextState(state, newGroupId, reorderedGroups);
3266
+ };
3267
+ const splitAtRootLevel = (state, groups, groupId, newGroupId, direction, baseNewGroup) => {
3268
+ const updatedGroups = groups.map(group => {
3269
+ if (group.id === groupId) {
3270
+ return {
3271
+ ...group,
3272
+ direction: undefined,
3273
+ focused: false,
3274
+ size: 50
3275
+ };
3276
+ }
3277
+ return group;
3278
+ });
3279
+ const newGroup = {
3280
+ ...baseNewGroup,
3281
+ direction: undefined,
3282
+ size: 50
3283
+ };
3284
+ const reorderedGroups = isTrailingSplit(direction) ? [...updatedGroups, newGroup] : (() => {
3285
+ const sourceIndex = updatedGroups.findIndex(group => group.id === groupId);
3286
+ return [...updatedGroups.slice(0, sourceIndex), newGroup, ...updatedGroups.slice(sourceIndex)];
3287
+ })();
3288
+ return createNextState(state, newGroupId, rebalanceGroupSizes(reorderedGroups));
3289
+ };
3144
3290
  const splitEditorGroup$1 = (state, groupId, direction) => {
3145
3291
  const {
3146
3292
  layout
@@ -3153,42 +3299,30 @@ const splitEditorGroup$1 = (state, groupId, direction) => {
3153
3299
  return state;
3154
3300
  }
3155
3301
  const newGroupId = create$1();
3156
- const isHorizontalSplit = direction === Left || direction === Right;
3157
- const newLayoutDirection = isHorizontalSplit ? Horizontal : Vertical;
3158
- const updatedGroups = groups.map(group => {
3159
- if (group.id === groupId) {
3160
- return {
3161
- ...group,
3162
- focused: false,
3163
- size: 50
3164
- };
3165
- }
3166
- return group;
3167
- });
3168
- const newGroup = {
3302
+ const splitLayoutDirection = getSplitLayoutDirection(direction);
3303
+ const baseNewGroup = {
3169
3304
  activeTabId: undefined,
3170
3305
  focused: true,
3171
3306
  id: newGroupId,
3172
3307
  isEmpty: true,
3173
- size: 50,
3308
+ size: sourceGroup.size / 2,
3174
3309
  tabs: []
3175
3310
  };
3176
- let reorderedGroups;
3177
- if (direction === Right || direction === 'down') {
3178
- reorderedGroups = [...updatedGroups, newGroup];
3179
- } else {
3180
- const sourceIndex = updatedGroups.findIndex(group => group.id === groupId);
3181
- reorderedGroups = [...updatedGroups.slice(0, sourceIndex), newGroup, ...updatedGroups.slice(sourceIndex)];
3311
+ if (groups.length === 1) {
3312
+ return splitOnlyGroup(state, groups, groupId, newGroupId, direction, splitLayoutDirection, baseNewGroup);
3182
3313
  }
3183
- const resizedGroups = rebalanceGroupSizes(reorderedGroups);
3184
- return {
3185
- ...state,
3186
- layout: {
3187
- activeGroupId: newGroupId,
3188
- direction: newLayoutDirection,
3189
- groups: resizedGroups
3190
- }
3191
- };
3314
+ if (sourceGroup.direction === splitLayoutDirection) {
3315
+ return splitWithinMatchingNestedDirection(state, groups, sourceGroup, groupId, newGroupId, direction, splitLayoutDirection, baseNewGroup);
3316
+ }
3317
+ if (splitLayoutDirection !== layout.direction && sourceGroup.direction === undefined) {
3318
+ return splitStandaloneSourceIntoNestedDirection(state, groups, sourceGroup, groupId, newGroupId, direction, splitLayoutDirection, baseNewGroup);
3319
+ }
3320
+ const segments = getGroupSegments(groups, layout.direction);
3321
+ const hasNestedSegments = segments.some(segment => segment.direction !== undefined);
3322
+ if (splitLayoutDirection === layout.direction && !hasNestedSegments) {
3323
+ return splitAtRootLevel(state, groups, groupId, newGroupId, direction, baseNewGroup);
3324
+ }
3325
+ return createNextState(state, newGroupId, groups);
3192
3326
  };
3193
3327
 
3194
3328
  const handleClickAction = async (state, action, rawGroupId) => {
@@ -3211,11 +3345,13 @@ const handleClickAction = async (state, action, rawGroupId) => {
3211
3345
  }
3212
3346
  switch (action) {
3213
3347
  case CloseGroup:
3214
- if (rawGroupId) {
3215
- const groupId = Number.parseInt(rawGroupId, 10);
3348
+ {
3349
+ const groupId = parseRawGroupId(rawGroupId);
3350
+ if (groupId === undefined) {
3351
+ return state;
3352
+ }
3216
3353
  return closeEditorGroup$1(state, groupId);
3217
3354
  }
3218
- return state;
3219
3355
  case RetryOpen:
3220
3356
  return retryOpen(state);
3221
3357
  case SplitRight$1:
@@ -4005,6 +4141,17 @@ const loadContent = async (state, savedState) => {
4005
4141
  };
4006
4142
  };
4007
4143
 
4144
+ const hasTargetGroup = groupId => {
4145
+ return groupId !== undefined && groupId >= 0;
4146
+ };
4147
+
4148
+ const getMenuEntryArgs = groupId => {
4149
+ if (!hasTargetGroup(groupId)) {
4150
+ return undefined;
4151
+ }
4152
+ return [groupId];
4153
+ };
4154
+
4008
4155
  const emptyObject = {};
4009
4156
  const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
4010
4157
  const i18nString = (key, placeholders = emptyObject) => {
@@ -4138,15 +4285,6 @@ const menuEntrySeparator = {
4138
4285
  label: ''
4139
4286
  };
4140
4287
 
4141
- const hasTargetGroup = groupId => {
4142
- return groupId !== undefined && groupId >= 0;
4143
- };
4144
- const getArgs = groupId => {
4145
- if (!hasTargetGroup(groupId)) {
4146
- return undefined;
4147
- }
4148
- return [groupId];
4149
- };
4150
4288
  const getNewWindowMenuEntries = state => {
4151
4289
  if (state.platform !== Electron) {
4152
4290
  return [];
@@ -4158,8 +4296,9 @@ const getNewWindowMenuEntries = state => {
4158
4296
  label: newWindow$1()
4159
4297
  }];
4160
4298
  };
4299
+
4161
4300
  const getMenuEntries$2 = (state, groupId) => {
4162
- const groupArgs = getArgs(groupId);
4301
+ const groupArgs = getMenuEntryArgs(groupId);
4163
4302
  const entries = [{
4164
4303
  args: [QuickPick, 'file'],
4165
4304
  command: 'Viewlet.openWidget',
@@ -4391,26 +4530,70 @@ const getEditorGroupCss = layout => {
4391
4530
  });
4392
4531
  };
4393
4532
 
4394
- const getSashCss = layout => {
4533
+ const MIN_GROUP_WIDTH_PX = 250;
4534
+ const getSashOffset = (layout, groupIndex, width) => {
4535
+ const {
4536
+ direction,
4537
+ groups
4538
+ } = layout;
4539
+ const percentOffset = groups.slice(0, groupIndex).reduce((total, group) => total + group.size, 0);
4540
+ if (direction !== Horizontal || !width || !Number.isFinite(width)) {
4541
+ return `${percentOffset}%`;
4542
+ }
4543
+ const effectiveGroupSizes = groups.map(group => Math.max(group.size / 100 * width, MIN_GROUP_WIDTH_PX));
4544
+ const hasOverflowingGroups = effectiveGroupSizes.some((size, index) => size !== groups[index].size / 100 * width);
4545
+ if (!hasOverflowingGroups) {
4546
+ return `${percentOffset}%`;
4547
+ }
4548
+ const pixelOffset = effectiveGroupSizes.slice(0, groupIndex).reduce((total, size) => total + size, 0);
4549
+ return `${pixelOffset}px`;
4550
+ };
4551
+
4552
+ const escapeCssAttributeValue = value => {
4553
+ return value.replaceAll('\\', '\\\\').replaceAll('"', '\\"');
4554
+ };
4555
+ const getSashCss = (layout, width = 0) => {
4395
4556
  if (layout.groups.length <= 1) {
4396
4557
  return [];
4397
4558
  }
4398
- const sashPositionVariable = layout.direction === Horizontal ? '--SashLeft' : '--SashTop';
4399
4559
  const rules = [];
4400
- let sashOffset = 0;
4401
- for (let i = 1; i < layout.groups.length; i++) {
4402
- sashOffset += layout.groups[i - 1].size;
4403
- const beforeGroupId = layout.groups[i - 1].id;
4404
- const afterGroupId = layout.groups[i].id;
4560
+ const segments = getGroupSegments(layout.groups, layout.direction);
4561
+ const sashPositionProperty = layout.direction === Horizontal ? 'left' : 'top';
4562
+ let segmentOffset = 0;
4563
+ for (let i = 1; i < segments.length; i++) {
4564
+ segmentOffset += getSegmentSize(segments[i - 1]);
4565
+ const beforeGroupId = segments[i - 1].groups.at(-1)?.id || 0;
4566
+ const afterGroupId = segments[i].groups[0].id;
4405
4567
  const sashId = create(beforeGroupId, afterGroupId);
4406
- rules.push(`.Sash[data-sashId="${sashId}"] {
4407
- ${sashPositionVariable}: ${sashOffset}%;
4568
+ const escapedSashId = escapeCssAttributeValue(sashId);
4569
+ const sashOffset = segments.some(segment => segment.direction !== undefined) || layout.direction !== Horizontal || !width ? `${segmentOffset}%` : getSashOffset(layout, i, width);
4570
+ rules.push(`[data-sashId="${escapedSashId}"] {
4571
+ ${sashPositionProperty}: ${sashOffset};
4408
4572
  }`);
4409
4573
  }
4574
+ for (const segment of segments) {
4575
+ if (segment.direction === undefined || segment.groups.length <= 1) {
4576
+ continue;
4577
+ }
4578
+ const nestedProperty = segment.direction === Horizontal ? 'left' : 'top';
4579
+ const segmentSize = getSegmentSize(segment);
4580
+ let nestedOffset = 0;
4581
+ for (let i = 1; i < segment.groups.length; i++) {
4582
+ nestedOffset += segment.groups[i - 1].size;
4583
+ const beforeGroupId = segment.groups[i - 1].id;
4584
+ const afterGroupId = segment.groups[i].id;
4585
+ const sashId = create(beforeGroupId, afterGroupId);
4586
+ const escapedSashId = escapeCssAttributeValue(sashId);
4587
+ const relativeOffset = Number((nestedOffset / segmentSize * 100).toFixed(6));
4588
+ rules.push(`[data-sashId="${escapedSashId}"] {
4589
+ ${nestedProperty}: ${relativeOffset}%;
4590
+ }`);
4591
+ }
4592
+ }
4410
4593
  return rules;
4411
4594
  };
4412
4595
 
4413
- const getCss = layout => {
4596
+ const getCss = (layout, width = 0) => {
4414
4597
  const rules = [`.MainArea {
4415
4598
  }`, `.editor-groups-container {
4416
4599
  overflow: auto;
@@ -4418,20 +4601,16 @@ const getCss = layout => {
4418
4601
  min-width: 250px;
4419
4602
  width: var(--EditorGroupWidth, auto);
4420
4603
  /*height: var(--EditorGroupHeight, auto);*/
4421
- }`, `.MainArea .SashVertical {
4422
- left: var(--SashLeft);
4423
- }`, `.MainArea .SashHorizontal {
4424
- top: var(--SashTop);
4425
4604
  }`];
4426
4605
  if (layout) {
4427
- rules.push(...getEditorGroupCss(layout), ...getSashCss(layout));
4606
+ rules.push(...getEditorGroupCss(layout), ...getSashCss(layout, width));
4428
4607
  }
4429
4608
  const css = rules.join('\n');
4430
4609
  return css;
4431
4610
  };
4432
4611
 
4433
4612
  const renderCss = (oldState, newState) => {
4434
- const css = getCss(newState.layout);
4613
+ const css = getCss(newState.layout, newState.width);
4435
4614
  return [SetCss, newState.uid, css];
4436
4615
  };
4437
4616
 
@@ -4745,25 +4924,6 @@ const HandleSashPointerDown = 16;
4745
4924
  const HandleSashPointerMove = 17;
4746
4925
  const HandleSashPointerUp = 18;
4747
4926
 
4748
- const MIN_GROUP_WIDTH_PX = 250;
4749
- const getSashOffset = (layout, groupIndex, width) => {
4750
- const {
4751
- direction,
4752
- groups
4753
- } = layout;
4754
- const percentOffset = groups.slice(0, groupIndex).reduce((total, group) => total + group.size, 0);
4755
- if (direction !== Horizontal || !width || !Number.isFinite(width)) {
4756
- return `${percentOffset}%`;
4757
- }
4758
- const effectiveGroupSizes = groups.map(group => Math.max(group.size / 100 * width, MIN_GROUP_WIDTH_PX));
4759
- const hasOverflowingGroups = effectiveGroupSizes.some((size, index) => size !== groups[index].size / 100 * width);
4760
- if (!hasOverflowingGroups) {
4761
- return `${percentOffset}%`;
4762
- }
4763
- const pixelOffset = effectiveGroupSizes.slice(0, groupIndex).reduce((total, size) => total + size, 0);
4764
- return `${pixelOffset}px`;
4765
- };
4766
-
4767
4927
  const renderContent = content => {
4768
4928
  return [{
4769
4929
  childCount: 1,
@@ -4985,12 +5145,13 @@ const renderEditorGroupHeader = (group, groupIndex, splitButtonEnabled) => {
4985
5145
  }, ...getTabsVirtualDom(group, groupIndex, tabsChildCount), ...actions];
4986
5146
  };
4987
5147
 
5148
+ const emptyHeader = {
5149
+ childCount: 1,
5150
+ className: EmptyGroupHeader,
5151
+ type: Div
5152
+ };
4988
5153
  const renderEmptyGroupCloseButton = (group, groupIndex) => {
4989
- return [{
4990
- childCount: 1,
4991
- className: EmptyGroupHeader,
4992
- type: Div
4993
- }, {
5154
+ return [emptyHeader, {
4994
5155
  childCount: 1,
4995
5156
  className: EmptyGroupCloseButton,
4996
5157
  'data-groupId': String(group.id),
@@ -4998,7 +5159,11 @@ const renderEmptyGroupCloseButton = (group, groupIndex) => {
4998
5159
  onClick: HandleClickAction,
4999
5160
  title: closeEditorGroup(),
5000
5161
  type: Button$2
5001
- }, text('✕')];
5162
+ }, {
5163
+ childCount: 0,
5164
+ className: MaskIconClose,
5165
+ type: Div
5166
+ }];
5002
5167
  };
5003
5168
 
5004
5169
  const renderWaterMark = groupId => {
@@ -5052,14 +5217,13 @@ const getSashClassName = direction => {
5052
5217
  return direction === Horizontal ? 'Sash SashVertical' : 'Sash SashHorizontal';
5053
5218
  };
5054
5219
 
5055
- const renderSash = (direction, sashId, style) => {
5220
+ const renderSash = (direction, sashId) => {
5056
5221
  return [{
5057
5222
  childCount: 1,
5058
5223
  className: getSashClassName(direction),
5059
5224
  'data-sashId': sashId,
5060
5225
  onPointerDown: HandleSashPointerDown,
5061
5226
  role: 'none',
5062
- style,
5063
5227
  type: Button$2
5064
5228
  }, {
5065
5229
  childCount: 0,
@@ -5082,19 +5246,81 @@ const getDirectionClassName = (direction, isSplit) => {
5082
5246
  }
5083
5247
  return direction === Horizontal ? EditorGroupsVertical : EditorGroupsHorizontal;
5084
5248
  };
5085
- const getMainAreaVirtualDom = (layout, splitButtonEnabled = false, width = 0) => {
5249
+ const getContainerClassName = (direction, childCount) => {
5250
+ const directionClassName = getDirectionClassName(direction, childCount > 1);
5251
+ return directionClassName ? `${EDITOR_GROUPS_CONTAINER} ${directionClassName}` : EDITOR_GROUPS_CONTAINER;
5252
+ };
5253
+ const getSizeProperty = direction => {
5254
+ return direction === Vertical ? 'height' : 'width';
5255
+ };
5256
+ const renderSegmentChildren = (direction, groups, splitButtonEnabled) => {
5257
+ const segments = getGroupSegments(groups, direction);
5258
+ const children = [];
5259
+ let childCount = 0;
5260
+ const sizeProperty = getSizeProperty(direction);
5261
+ for (let i = 0; i < segments.length; i++) {
5262
+ const segment = segments[i];
5263
+ if (i > 0) {
5264
+ const previousSegment = segments[i - 1];
5265
+ const beforeGroupId = previousSegment.groups.at(-1)?.id || 0;
5266
+ const afterGroupId = segment.groups[0].id;
5267
+ const sashId = create(beforeGroupId, afterGroupId);
5268
+ children.push(...renderSash(direction, sashId));
5269
+ childCount++;
5270
+ }
5271
+ if (segment.direction === undefined) {
5272
+ children.push(...renderEditorGroup(segment.groups[0], segment.startIndex, splitButtonEnabled, sizeProperty));
5273
+ childCount++;
5274
+ continue;
5275
+ }
5276
+ const nestedDirection = segment.direction;
5277
+ const nestedSizeProperty = getSizeProperty(nestedDirection);
5278
+ const nestedChildCount = segment.groups.length + segment.groups.length - 1;
5279
+ const nestedChildren = [];
5280
+ let nestedCount = 0;
5281
+ const segmentSize = getSegmentSize(segment);
5282
+ for (let j = 0; j < segment.groups.length; j++) {
5283
+ if (j > 0) {
5284
+ const beforeGroupId = segment.groups[j - 1].id;
5285
+ const afterGroupId = segment.groups[j].id;
5286
+ const sashId = create(beforeGroupId, afterGroupId);
5287
+ nestedChildren.push(...renderSash(nestedDirection, sashId));
5288
+ nestedCount++;
5289
+ }
5290
+ const group = segment.groups[j];
5291
+ const normalizedSize = Number((group.size / segmentSize * 100).toFixed(6));
5292
+ nestedChildren.push(...renderEditorGroup({
5293
+ ...group,
5294
+ size: normalizedSize
5295
+ }, segment.startIndex + j, splitButtonEnabled, nestedSizeProperty));
5296
+ nestedCount++;
5297
+ }
5298
+ children.push({
5299
+ childCount: nestedChildCount,
5300
+ className: getContainerClassName(nestedDirection, segment.groups.length),
5301
+ role: None$1,
5302
+ style: `${sizeProperty}:${segmentSize}%;`,
5303
+ type: Div
5304
+ });
5305
+ children.push(...nestedChildren);
5306
+ childCount++;
5307
+ childCount += nestedCount;
5308
+ }
5309
+ return {
5310
+ childCount,
5311
+ children
5312
+ };
5313
+ };
5314
+ const getMainAreaVirtualDom = (layout, splitButtonEnabled = false) => {
5086
5315
  const {
5087
5316
  direction,
5088
5317
  groups
5089
5318
  } = layout;
5090
- const sizeProperty = direction === Vertical ? 'height' : 'width';
5319
+ const sizeProperty = getSizeProperty(direction);
5091
5320
  if (groups.length === 1) {
5092
5321
  return renderSingleEditorGroup(layout, splitButtonEnabled, sizeProperty);
5093
5322
  }
5094
- const children = [];
5095
- const isSplit = groups.length > 1;
5096
- const directionClassName = getDirectionClassName(direction, isSplit);
5097
- const editorGroupsContainerClassName = directionClassName ? `${EDITOR_GROUPS_CONTAINER} ${directionClassName}` : EDITOR_GROUPS_CONTAINER;
5323
+ const editorGroupsContainerClassName = getContainerClassName(direction, groups.length);
5098
5324
  if (groups.length === 0) {
5099
5325
  return [{
5100
5326
  childCount: 1,
@@ -5109,22 +5335,10 @@ const getMainAreaVirtualDom = (layout, splitButtonEnabled = false, width = 0) =>
5109
5335
  type: Div
5110
5336
  }];
5111
5337
  }
5112
- let childCount = 0;
5113
- for (let i = 0; i < groups.length; i++) {
5114
- if (i > 0) {
5115
- // Insert sash between groups
5116
- const beforeGroupId = groups[i - 1].id;
5117
- const afterGroupId = groups[i].id;
5118
- const sashId = create(beforeGroupId, afterGroupId);
5119
- const offset = getSashOffset(layout, i, width);
5120
- const style = direction === Horizontal ? `left:${offset};` : `top:${offset};`;
5121
- children.push(...renderSash(direction, sashId, style));
5122
- childCount++;
5123
- }
5124
- const editorGroupDom = renderEditorGroup(groups[i], i, splitButtonEnabled, sizeProperty);
5125
- children.push(...editorGroupDom);
5126
- childCount++;
5127
- }
5338
+ const {
5339
+ childCount,
5340
+ children
5341
+ } = renderSegmentChildren(direction, groups, splitButtonEnabled);
5128
5342
  return [{
5129
5343
  childCount: 1,
5130
5344
  className: Main,
@@ -5142,13 +5356,12 @@ const renderItems = (oldState, newState) => {
5142
5356
  initial,
5143
5357
  layout,
5144
5358
  splitButtonEnabled,
5145
- uid,
5146
- width
5359
+ uid
5147
5360
  } = newState;
5148
5361
  if (initial) {
5149
5362
  return [SetDom2, uid, []];
5150
5363
  }
5151
- const dom = getMainAreaVirtualDom(layout, splitButtonEnabled, width);
5364
+ const dom = getMainAreaVirtualDom(layout, splitButtonEnabled);
5152
5365
  return [SetDom2, uid, dom];
5153
5366
  };
5154
5367
 
@@ -5235,6 +5448,9 @@ const renderEventListeners = () => {
5235
5448
  const saveEditor = async editorUid => {
5236
5449
  await invoke('Editor.save', editorUid);
5237
5450
  };
5451
+ const getEditorSaveState = async editorUid => {
5452
+ return invoke('Editor.saveState', editorUid);
5453
+ };
5238
5454
 
5239
5455
  const save = async state => {
5240
5456
  const activeTabData = getActiveTab(state);
@@ -5251,6 +5467,10 @@ const save = async state => {
5251
5467
  if (!tab.isDirty) {
5252
5468
  return state;
5253
5469
  }
5470
+ const editorState = await getEditorSaveState(tab.editorUid);
5471
+ if (editorState.modified) {
5472
+ return state;
5473
+ }
5254
5474
  return updateTab(state, tab.id, {
5255
5475
  isDirty: false
5256
5476
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.7.0",
3
+ "version": "9.9.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",