@lvce-editor/main-area-worker 8.6.0 → 8.7.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.
@@ -335,6 +335,7 @@ const ExtensionHostWorker = 44;
335
335
  const IconThemeWorker = 7009;
336
336
  const RendererWorker = 1;
337
337
 
338
+ const SetCss = 'Viewlet.setCss';
338
339
  const SetDom2 = 'Viewlet.setDom2';
339
340
  const SetPatches = 'Viewlet.setPatches';
340
341
 
@@ -1486,7 +1487,7 @@ const create$j = async ({
1486
1487
  send
1487
1488
  }) => {
1488
1489
  return createSharedLazyRpc(() => {
1489
- return create$3({
1490
+ return create$3$1({
1490
1491
  commandMap,
1491
1492
  isMessagePortOpen,
1492
1493
  send
@@ -1514,7 +1515,7 @@ const create$5 = async ({
1514
1515
  messagePort.start();
1515
1516
  return rpc;
1516
1517
  };
1517
- const create$3 = async ({
1518
+ const create$3$1 = async ({
1518
1519
  commandMap,
1519
1520
  isMessagePortOpen,
1520
1521
  send
@@ -1532,7 +1533,7 @@ const create$3 = async ({
1532
1533
  };
1533
1534
  const TransferMessagePortRpcParent = {
1534
1535
  __proto__: null,
1535
- create: create$3
1536
+ create: create$3$1
1536
1537
  };
1537
1538
  const create$2$1 = async ({
1538
1539
  commandMap
@@ -1580,7 +1581,7 @@ const remove = id => {
1580
1581
  };
1581
1582
 
1582
1583
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
1583
- const create$2 = rpcId => {
1584
+ const create$3 = rpcId => {
1584
1585
  return {
1585
1586
  async dispose() {
1586
1587
  const rpc = get$1(rpcId);
@@ -1618,16 +1619,16 @@ const create$2 = rpcId => {
1618
1619
 
1619
1620
  const {
1620
1621
  set: set$4
1621
- } = create$2(ClipBoardWorker);
1622
+ } = create$3(ClipBoardWorker);
1622
1623
 
1623
1624
  const {
1624
1625
  set: set$3
1625
- } = create$2(ExtensionHostWorker);
1626
+ } = create$3(ExtensionHostWorker);
1626
1627
 
1627
1628
  const {
1628
1629
  invoke: invoke$1,
1629
1630
  set: set$2
1630
- } = create$2(IconThemeWorker);
1631
+ } = create$3(IconThemeWorker);
1631
1632
  const getIcons = async iconRequests => {
1632
1633
  // @ts-ignore
1633
1634
  return invoke$1('IconTheme.getIcons', iconRequests);
@@ -1637,7 +1638,7 @@ const {
1637
1638
  invoke,
1638
1639
  invokeAndTransfer,
1639
1640
  set: set$1
1640
- } = create$2(RendererWorker);
1641
+ } = create$3(RendererWorker);
1641
1642
  const showContextMenu2 = async (uid, menuId, x, y, args) => {
1642
1643
  number(uid);
1643
1644
  number(menuId);
@@ -1680,7 +1681,7 @@ const {
1680
1681
  wrapGetter
1681
1682
  } = create$6();
1682
1683
 
1683
- const create$1 = (uid, uri, x, y, width, height, platform, assetDir, tabHeight = 35) => {
1684
+ const create$2 = (uid, uri, x, y, width, height, platform, assetDir, tabHeight = 35) => {
1684
1685
  const state = {
1685
1686
  assetDir,
1686
1687
  fileIconCache: {},
@@ -1704,15 +1705,20 @@ const create$1 = (uid, uri, x, y, width, height, platform, assetDir, tabHeight =
1704
1705
  set(uid, state, state);
1705
1706
  };
1706
1707
 
1708
+ const isEqual$1 = (oldState, newState) => {
1709
+ return oldState.width === newState.width && oldState.height === newState.height;
1710
+ };
1711
+
1707
1712
  const isEqual = (oldState, newState) => {
1708
1713
  return oldState.layout === newState.layout;
1709
1714
  };
1710
1715
 
1711
1716
  const RenderItems = 4;
1717
+ const RenderCss = 10;
1712
1718
  const RenderIncremental = 11;
1713
1719
 
1714
- const modules = [isEqual];
1715
- const numbers = [RenderIncremental];
1720
+ const modules = [isEqual, isEqual$1];
1721
+ const numbers = [RenderIncremental, RenderCss];
1716
1722
 
1717
1723
  const diff = (oldState, newState) => {
1718
1724
  const diffResult = [];
@@ -1744,7 +1750,7 @@ const handleAttach = async command => {
1744
1750
  await invoke('Layout.attachViewlet', parentNodeSelector, command.instanceId);
1745
1751
  };
1746
1752
 
1747
- const create = () => {
1753
+ const create$1 = () => {
1748
1754
  return Math.random();
1749
1755
  };
1750
1756
 
@@ -1821,7 +1827,7 @@ const loadTabContentAsync = async (tabId, path, requestId, getLatestState) => {
1821
1827
  }
1822
1828
 
1823
1829
  // Assign editorUid if tab doesn't have one yet
1824
- const editorUid = latestTab.editorUid === -1 ? create() : latestTab.editorUid;
1830
+ const editorUid = latestTab.editorUid === -1 ? create$1() : latestTab.editorUid;
1825
1831
  return updateTab(latestState, tabId, {
1826
1832
  editorUid,
1827
1833
  errorMessage: undefined,
@@ -1861,7 +1867,7 @@ const createViewletForTab = (state, tabId, viewletModuleId, bounds) => {
1861
1867
  if (tab.editorUid !== -1 || tab.loadingState === 'loading' || tab.loadingState === 'loaded') {
1862
1868
  return state;
1863
1869
  }
1864
- const editorUid = create();
1870
+ const editorUid = create$1();
1865
1871
  const newState = updateTab(state, tabId, {
1866
1872
  editorUid
1867
1873
  });
@@ -2361,10 +2367,10 @@ const createEmptyGroup = (state, uri, requestId) => {
2361
2367
  const {
2362
2368
  groups
2363
2369
  } = layout;
2364
- const groupId = create();
2370
+ const groupId = create$1();
2365
2371
  const title = getLabel(uri);
2366
- const tabId = create();
2367
- const editorUid = create();
2372
+ const tabId = create$1();
2373
+ const editorUid = create$1();
2368
2374
  const newTab = {
2369
2375
  editorType: 'text',
2370
2376
  editorUid,
@@ -2398,7 +2404,7 @@ const createEmptyGroup = (state, uri, requestId) => {
2398
2404
  const openTab = (state, groupId, tab) => {
2399
2405
  const newTab = 'id' in tab && tab.id !== undefined ? tab : {
2400
2406
  ...tab,
2401
- id: create()
2407
+ id: create$1()
2402
2408
  };
2403
2409
  const {
2404
2410
  layout
@@ -2446,8 +2452,8 @@ const ensureActiveGroup = (state, uri) => {
2446
2452
  if (activeGroup) {
2447
2453
  // Create a new tab with the URI in the active group
2448
2454
  const title = getLabel(uri);
2449
- const tabId = create();
2450
- const editorUid = create();
2455
+ const tabId = create$1();
2456
+ const editorUid = create$1();
2451
2457
  const newTab = {
2452
2458
  editorType: 'text',
2453
2459
  editorUid,
@@ -2855,7 +2861,7 @@ const splitEditorGroup$1 = (state, groupId, direction) => {
2855
2861
  if (!sourceGroup) {
2856
2862
  return state;
2857
2863
  }
2858
- const newGroupId = create();
2864
+ const newGroupId = create$1();
2859
2865
  const isHorizontalSplit = direction === Left || direction === Right;
2860
2866
  const newLayoutDirection = isHorizontalSplit ? 'horizontal' : 'vertical';
2861
2867
  const updatedGroups = groups.map(group => {
@@ -3044,8 +3050,8 @@ const newFile = async state => {
3044
3050
  getActiveTabId(newState);
3045
3051
 
3046
3052
  // Create a new empty tab
3047
- const tabId = create();
3048
- const editorUid = create();
3053
+ const tabId = create$1();
3054
+ const editorUid = create$1();
3049
3055
  const newTab = {
3050
3056
  editorType: 'text',
3051
3057
  editorUid,
@@ -3175,6 +3181,119 @@ const handleResize = async (state, dimensions) => {
3175
3181
  return allResizeCommands;
3176
3182
  };
3177
3183
 
3184
+ const create = (beforeGroupId, afterGroupId) => {
3185
+ return `${beforeGroupId}:${afterGroupId}`;
3186
+ };
3187
+ const parse = sashId => {
3188
+ if (!sashId) {
3189
+ return undefined;
3190
+ }
3191
+ const [beforeRaw, afterRaw] = sashId.split(':');
3192
+ if (!beforeRaw || !afterRaw) {
3193
+ return undefined;
3194
+ }
3195
+ const beforeGroupId = Number.parseInt(beforeRaw, 10);
3196
+ const afterGroupId = Number.parseInt(afterRaw, 10);
3197
+ if (!Number.isFinite(beforeGroupId) || !Number.isFinite(afterGroupId)) {
3198
+ return undefined;
3199
+ }
3200
+ return {
3201
+ afterGroupId,
3202
+ beforeGroupId
3203
+ };
3204
+ };
3205
+
3206
+ const handleSashPointerDown = async (state, sashId, clientXRaw, clientYRaw) => {
3207
+ const parsed = parse(sashId);
3208
+ if (!parsed) {
3209
+ return state;
3210
+ }
3211
+ const beforeGroup = state.layout.groups.find(group => group.id === parsed.beforeGroupId);
3212
+ const afterGroup = state.layout.groups.find(group => group.id === parsed.afterGroupId);
3213
+ if (!beforeGroup || !afterGroup) {
3214
+ return state;
3215
+ }
3216
+ const clientX = Number.parseFloat(clientXRaw);
3217
+ const clientY = Number.parseFloat(clientYRaw);
3218
+ if (!Number.isFinite(clientX) || !Number.isFinite(clientY)) {
3219
+ return state;
3220
+ }
3221
+ return {
3222
+ ...state,
3223
+ sashDrag: {
3224
+ afterGroupId: parsed.afterGroupId,
3225
+ afterSize: afterGroup.size,
3226
+ beforeGroupId: parsed.beforeGroupId,
3227
+ beforeSize: beforeGroup.size,
3228
+ sashId,
3229
+ startClientX: clientX,
3230
+ startClientY: clientY
3231
+ }
3232
+ };
3233
+ };
3234
+
3235
+ const MIN_GROUP_SIZE = 10;
3236
+ const clamp = (value, min, max) => {
3237
+ return Math.min(max, Math.max(min, value));
3238
+ };
3239
+ const round = value => {
3240
+ return Math.round(value * 100) / 100;
3241
+ };
3242
+ const handleSashPointerMove = async (state, clientXRaw, clientYRaw) => {
3243
+ const {
3244
+ sashDrag
3245
+ } = state;
3246
+ if (!sashDrag) {
3247
+ return state;
3248
+ }
3249
+ const clientX = Number.parseFloat(clientXRaw);
3250
+ const clientY = Number.parseFloat(clientYRaw);
3251
+ if (!Number.isFinite(clientX) || !Number.isFinite(clientY)) {
3252
+ return state;
3253
+ }
3254
+ const axisSize = state.layout.direction === 'horizontal' ? state.width : state.height;
3255
+ if (!axisSize) {
3256
+ return state;
3257
+ }
3258
+ const deltaPx = state.layout.direction === 'horizontal' ? clientX - sashDrag.startClientX : clientY - sashDrag.startClientY;
3259
+ const deltaPercent = deltaPx / axisSize * 100;
3260
+ const totalResizableSize = sashDrag.beforeSize + sashDrag.afterSize;
3261
+ const beforeSize = clamp(sashDrag.beforeSize + deltaPercent, MIN_GROUP_SIZE, totalResizableSize - MIN_GROUP_SIZE);
3262
+ const afterSize = totalResizableSize - beforeSize;
3263
+ const groups = state.layout.groups.map(group => {
3264
+ if (group.id === sashDrag.beforeGroupId) {
3265
+ return {
3266
+ ...group,
3267
+ size: round(beforeSize)
3268
+ };
3269
+ }
3270
+ if (group.id === sashDrag.afterGroupId) {
3271
+ return {
3272
+ ...group,
3273
+ size: round(afterSize)
3274
+ };
3275
+ }
3276
+ return group;
3277
+ });
3278
+ return {
3279
+ ...state,
3280
+ layout: {
3281
+ ...state.layout,
3282
+ groups
3283
+ }
3284
+ };
3285
+ };
3286
+
3287
+ const handleSashPointerUp = async state => {
3288
+ if (!state.sashDrag) {
3289
+ return state;
3290
+ }
3291
+ return {
3292
+ ...state,
3293
+ sashDrag: undefined
3294
+ };
3295
+ };
3296
+
3178
3297
  const show2 = async (uid, menuId, x, y, args) => {
3179
3298
  await showContextMenu2(uid, menuId, x, y, args);
3180
3299
  };
@@ -3366,7 +3485,7 @@ const createViewlets = async (layout, viewletModuleIds, bounds) => {
3366
3485
  for (const group of layout.groups) {
3367
3486
  const activeTab = group.tabs.find(tab => tab.id === group.activeTabId);
3368
3487
  if (activeTab && viewletModuleIds[activeTab.id]) {
3369
- const editorUid = activeTab.editorUid === -1 ? create() : activeTab.editorUid;
3488
+ const editorUid = activeTab.editorUid === -1 ? create$1() : activeTab.editorUid;
3370
3489
  editorUids[activeTab.id] = editorUid;
3371
3490
  await createViewlet(viewletModuleIds[activeTab.id], editorUid, activeTab.id, bounds, activeTab.uri);
3372
3491
  }
@@ -3633,6 +3752,18 @@ const refresh = state => {
3633
3752
  };
3634
3753
  };
3635
3754
 
3755
+ const getCss = () => {
3756
+ const rules = [`.MainArea {
3757
+ }`];
3758
+ const css = rules.join('\n');
3759
+ return css;
3760
+ };
3761
+
3762
+ const renderCss = (oldState, newState) => {
3763
+ const css = getCss();
3764
+ return [SetCss, newState.uid, css];
3765
+ };
3766
+
3636
3767
  const text = data => {
3637
3768
  return {
3638
3769
  childCount: 0,
@@ -3947,6 +4078,9 @@ const HandleClickClose = 12;
3947
4078
  const HandleClickTab = 13;
3948
4079
  const HandleTabContextMenu = 14;
3949
4080
  const HandleHeaderDoubleClick = 15;
4081
+ const HandleSashPointerDown = 16;
4082
+ const HandleSashPointerMove = 17;
4083
+ const HandleSashPointerUp = 18;
3950
4084
 
3951
4085
  const renderError = errorMessage => {
3952
4086
  return [{
@@ -4149,11 +4283,13 @@ const renderEditorGroupHeader = (group, groupIndex, splitButtonEnabled) => {
4149
4283
  }, ...getTabsVirtualDom(group, groupIndex, tabsChildCount), ...actions];
4150
4284
  };
4151
4285
 
4152
- const renderEditorGroup = (group, groupIndex, splitButtonEnabled = false) => {
4286
+ const renderEditorGroup = (group, groupIndex, splitButtonEnabled = false, direction = 'horizontal') => {
4153
4287
  const activeTab = group.tabs.find(tab => tab.id === group.activeTabId);
4288
+ const style = direction === 'horizontal' ? `width:${group.size}%;` : `height:${group.size}%;`;
4154
4289
  return [{
4155
4290
  childCount: 2,
4156
4291
  className: EditorGroup,
4292
+ style,
4157
4293
  type: Div
4158
4294
  }, ...renderEditorGroupHeader(group, groupIndex, splitButtonEnabled), {
4159
4295
  childCount: 1,
@@ -4162,10 +4298,14 @@ const renderEditorGroup = (group, groupIndex, splitButtonEnabled = false) => {
4162
4298
  }, ...renderEditor(activeTab)];
4163
4299
  };
4164
4300
 
4165
- const renderSash = direction => {
4301
+ const renderSash = (direction, sashId) => {
4166
4302
  return {
4167
4303
  childCount: 0,
4168
4304
  className: direction === 'vertical' ? 'SashVertical' : 'SashHorizontal',
4305
+ 'data-sashId': sashId,
4306
+ onPointerDown: HandleSashPointerDown,
4307
+ onPointerMove: HandleSashPointerMove,
4308
+ onPointerUp: HandleSashPointerUp,
4169
4309
  type: Div
4170
4310
  };
4171
4311
  };
@@ -4175,9 +4315,12 @@ const getMainAreaVirtualDom = (layout, splitButtonEnabled = false) => {
4175
4315
  for (let i = 0; i < layout.groups.length; i++) {
4176
4316
  if (i > 0) {
4177
4317
  // Insert sash between groups
4178
- children.push(renderSash(layout.direction));
4318
+ const beforeGroupId = layout.groups[i - 1].id;
4319
+ const afterGroupId = layout.groups[i].id;
4320
+ const sashId = create(beforeGroupId, afterGroupId);
4321
+ children.push(renderSash(layout.direction, sashId));
4179
4322
  }
4180
- children.push(...renderEditorGroup(layout.groups[i], i, splitButtonEnabled));
4323
+ children.push(...renderEditorGroup(layout.groups[i], i, splitButtonEnabled, layout.direction));
4181
4324
  }
4182
4325
  return [{
4183
4326
  childCount: 1,
@@ -4214,6 +4357,8 @@ const renderIncremental = (oldState, newState) => {
4214
4357
 
4215
4358
  const getRenderer = diffType => {
4216
4359
  switch (diffType) {
4360
+ case RenderCss:
4361
+ return renderCss;
4217
4362
  case RenderIncremental:
4218
4363
  return renderIncremental;
4219
4364
  case RenderItems:
@@ -4265,6 +4410,15 @@ const renderEventListeners = () => {
4265
4410
  }, {
4266
4411
  name: HandleHeaderDoubleClick,
4267
4412
  params: ['handleHeaderDoubleClick', EventTargetClassName, 'event.target.dataset.groupId']
4413
+ }, {
4414
+ name: HandleSashPointerDown,
4415
+ params: ['handleSashPointerDown', 'event.target.dataset.sashId', ClientX, ClientY]
4416
+ }, {
4417
+ name: HandleSashPointerMove,
4418
+ params: ['handleSashPointerMove', ClientX, ClientY]
4419
+ }, {
4420
+ name: HandleSashPointerUp,
4421
+ params: ['handleSashPointerUp', ClientX, ClientY]
4268
4422
  }];
4269
4423
  };
4270
4424
 
@@ -4329,7 +4483,7 @@ const splitDown = (state, groupId) => {
4329
4483
 
4330
4484
  // If there are no groups, create an initial empty group first
4331
4485
  if (groups.length === 0) {
4332
- const initialGroupId = create();
4486
+ const initialGroupId = create$1();
4333
4487
  const initialGroup = {
4334
4488
  activeTabId: undefined,
4335
4489
  focused: true,
@@ -4366,7 +4520,7 @@ const splitRight = (state, groupId) => {
4366
4520
 
4367
4521
  // If there are no groups, create an initial empty group first
4368
4522
  if (groups.length === 0) {
4369
- const initialGroupId = create();
4523
+ const initialGroupId = create$1();
4370
4524
  const initialGroup = {
4371
4525
  activeTabId: undefined,
4372
4526
  focused: true,
@@ -4398,7 +4552,7 @@ const commandMap = {
4398
4552
  'MainArea.closeTabsRight': wrapCommand(closeTabsRight),
4399
4553
  'MainArea.copyPath': wrapCommand(copyPath$1),
4400
4554
  'MainArea.copyRelativePath': wrapCommand(copyRelativePath$1),
4401
- 'MainArea.create': create$1,
4555
+ 'MainArea.create': create$2,
4402
4556
  'MainArea.diff2': diff2,
4403
4557
  'MainArea.focusNext': wrapCommand(focusNextTab),
4404
4558
  'MainArea.focusNextTab': wrapCommand(focusNextTab),
@@ -4417,6 +4571,9 @@ const commandMap = {
4417
4571
  'MainArea.handleModifiedStatusChange': wrapCommand(handleModifiedStatusChange),
4418
4572
  'MainArea.handleResize': wrapGetter(handleResize),
4419
4573
  // TODO would need to have a function that returns newstate as well as commands
4574
+ 'MainArea.handleSashPointerDown': wrapCommand(handleSashPointerDown),
4575
+ 'MainArea.handleSashPointerMove': wrapCommand(handleSashPointerMove),
4576
+ 'MainArea.handleSashPointerUp': wrapCommand(handleSashPointerUp),
4420
4577
  'MainArea.handleTabContextMenu': wrapCommand(handleTabContextMenu),
4421
4578
  'MainArea.handleUriChange': wrapCommand(handleUriChange),
4422
4579
  'MainArea.handleWorkspaceChange': wrapCommand(handleWorkspaceChange),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "8.6.0",
3
+ "version": "8.7.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",