@lvce-editor/main-area-worker 9.19.0 → 9.20.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.
@@ -1896,6 +1896,38 @@ const closeTabsRight = (state, groupId) => {
1896
1896
  return withGroups(addClosedTabs(state, closedTabs), newGroups);
1897
1897
  };
1898
1898
 
1899
+ const findGroupById = (state, groupId) => {
1900
+ const {
1901
+ layout
1902
+ } = state;
1903
+ const {
1904
+ groups
1905
+ } = layout;
1906
+ return groups.find(group => group.id === groupId);
1907
+ };
1908
+
1909
+ const copyIntoNewWindow$1 = async state => {
1910
+ const {
1911
+ activeGroupId
1912
+ } = state.layout;
1913
+ const group = findGroupById(state, activeGroupId ?? 0);
1914
+ if (!group) {
1915
+ return state;
1916
+ }
1917
+ const {
1918
+ activeTabId
1919
+ } = group;
1920
+ if (activeTabId === undefined) {
1921
+ return state;
1922
+ }
1923
+ const tab = group.tabs.find(tab => tab.id === activeTabId);
1924
+ if (!tab?.uri) {
1925
+ return state;
1926
+ }
1927
+ await invoke('ElectronWindow.openNewWithUri', tab.uri);
1928
+ return state;
1929
+ };
1930
+
1899
1931
  const copyPath$1 = async (state, path) => {
1900
1932
  string(path);
1901
1933
  await writeClipBoardText(path);
@@ -1944,6 +1976,7 @@ const create$2 = (uid, uri, x, y, width, height, platform, assetDir, tabHeight =
1944
1976
  closedTabs: [],
1945
1977
  fileIconCache: {},
1946
1978
  height,
1979
+ homeDirUri: '',
1947
1980
  iframes: [],
1948
1981
  initial: true,
1949
1982
  layout: {
@@ -3018,6 +3051,16 @@ const getCurrentState = state => {
3018
3051
  return state;
3019
3052
  };
3020
3053
 
3054
+ const getTitle = (uri, homeDir) => {
3055
+ if (!uri) {
3056
+ return '';
3057
+ }
3058
+ const normalizedHomeDir = homeDir.endsWith('/') ? homeDir.slice(0, -1) : homeDir;
3059
+ if (uri.startsWith('file://') && normalizedHomeDir.startsWith('file://') && (uri === normalizedHomeDir || uri.startsWith(`${normalizedHomeDir}/`))) {
3060
+ return `~${uri.slice(normalizedHomeDir.length)}`;
3061
+ }
3062
+ return uri;
3063
+ };
3021
3064
  const getBasename$1 = uri => {
3022
3065
  const lastSlashIndex = uri.lastIndexOf('/');
3023
3066
  if (lastSlashIndex === -1) {
@@ -3034,6 +3077,9 @@ const getInlineDiffLabel = uri => {
3034
3077
  return `${getBasename$1(workingTreeUri)} (Working Tree)`;
3035
3078
  };
3036
3079
  const getLabel = uri => {
3080
+ if (uri === 'app://keybindings') {
3081
+ return 'Keyboard Shortcuts';
3082
+ }
3037
3083
  if (uri.startsWith('settings://')) {
3038
3084
  return 'Settings';
3039
3085
  }
@@ -3072,7 +3118,41 @@ const getEditorInputTitle = editorInput => {
3072
3118
  }
3073
3119
  };
3074
3120
 
3075
- const createEmptyGroup = (state, uri, requestId, preview = false, title = getLabel(uri), editorType = 'text', editorInput) => {
3121
+ const getUriTitle = (uri, homeDirUri) => {
3122
+ if (!uri) {
3123
+ return undefined;
3124
+ }
3125
+ const title = getTitle(uri, homeDirUri);
3126
+ return title === uri ? undefined : title;
3127
+ };
3128
+ const updateTabUriTitle = (tab, homeDirUri) => {
3129
+ const uriTitle = getUriTitle(tab.uri, homeDirUri);
3130
+ if (tab.uriTitle === uriTitle) {
3131
+ return tab;
3132
+ }
3133
+ return {
3134
+ ...tab,
3135
+ uriTitle
3136
+ };
3137
+ };
3138
+ const updateTabUriTitles = state => {
3139
+ const {
3140
+ layout
3141
+ } = state;
3142
+ const homeDirUri = state.homeDirUri || '';
3143
+ return {
3144
+ ...state,
3145
+ layout: {
3146
+ ...layout,
3147
+ groups: layout.groups.map(group => ({
3148
+ ...group,
3149
+ tabs: group.tabs.map(tab => updateTabUriTitle(tab, homeDirUri))
3150
+ }))
3151
+ }
3152
+ };
3153
+ };
3154
+
3155
+ const createEmptyGroup$1 = (state, uri, requestId, preview = false, title = getLabel(uri), editorType = 'text', editorInput) => {
3076
3156
  const {
3077
3157
  layout
3078
3158
  } = state;
@@ -3094,7 +3174,8 @@ const createEmptyGroup = (state, uri, requestId, preview = false, title = getLab
3094
3174
  language: '',
3095
3175
  loadingState: 'loading',
3096
3176
  title,
3097
- uri
3177
+ uri,
3178
+ uriTitle: getUriTitle(uri, state.homeDirUri || '')
3098
3179
  };
3099
3180
  const newGroup = {
3100
3181
  activeTabId: newTab.id,
@@ -3188,7 +3269,8 @@ const ensureActiveGroup = (state, uri, preview = false, title = getLabel(uri), e
3188
3269
  language: '',
3189
3270
  loadingState: 'loading',
3190
3271
  title,
3191
- uri
3272
+ uri,
3273
+ uriTitle: getUriTitle(uri, state.homeDirUri || '')
3192
3274
  };
3193
3275
  });
3194
3276
  return {
@@ -3221,11 +3303,12 @@ const ensureActiveGroup = (state, uri, preview = false, title = getLabel(uri), e
3221
3303
  language: '',
3222
3304
  loadingState: 'loading',
3223
3305
  title,
3224
- uri: uri
3306
+ uri: uri,
3307
+ uriTitle: getUriTitle(uri, state.homeDirUri || '')
3225
3308
  };
3226
3309
  newState = openTab(state, activeGroup.id, newTab);
3227
3310
  } else {
3228
- newState = createEmptyGroup(state, uri, requestId, preview, title, editorType, editorInput);
3311
+ newState = createEmptyGroup$1(state, uri, requestId, preview, title, editorType, editorInput);
3229
3312
  }
3230
3313
  return newState;
3231
3314
  };
@@ -3239,7 +3322,8 @@ const getStateWithTab = (currentState, editorInput, existingTab, shouldRetryExis
3239
3322
  errorMessage: '',
3240
3323
  loadingState: 'loading',
3241
3324
  title,
3242
- uri
3325
+ uri,
3326
+ uriTitle: getUriTitle(uri, currentState.homeDirUri || '')
3243
3327
  }),
3244
3328
  tabId: existingTab.tab.id
3245
3329
  };
@@ -3921,7 +4005,7 @@ const newFile = async state => {
3921
4005
  targetGroupId = activeGroup.id;
3922
4006
  } else {
3923
4007
  // No active group, create an empty one
3924
- newState = createEmptyGroup(state, '');
4008
+ newState = createEmptyGroup$1(state, '');
3925
4009
  const updatedActiveGroupId = newState.layout.activeGroupId;
3926
4010
  if (!updatedActiveGroupId) {
3927
4011
  return state;
@@ -4306,7 +4390,8 @@ const handleUriChange = async (state, oldUri, newUri) => {
4306
4390
  return {
4307
4391
  ...tab,
4308
4392
  title: newTitle,
4309
- uri: newUri
4393
+ uri: newUri,
4394
+ uriTitle: getUriTitle(newUri, state.homeDirUri || '')
4310
4395
  };
4311
4396
  }
4312
4397
  return tab;
@@ -4371,6 +4456,27 @@ const initialize = async () => {
4371
4456
  set$3(rpc);
4372
4457
  };
4373
4458
 
4459
+ const toFileUri = path => {
4460
+ if (!path) {
4461
+ return '';
4462
+ }
4463
+ if (path.startsWith('file://')) {
4464
+ return path;
4465
+ }
4466
+ if (path.startsWith('/')) {
4467
+ return `file://${path}`;
4468
+ }
4469
+ return path;
4470
+ };
4471
+ const loadHomeDirUri = async () => {
4472
+ try {
4473
+ const homeDir = await invoke('Workspace.getHomeDir');
4474
+ return typeof homeDir === 'string' ? toFileUri(homeDir) : '';
4475
+ } catch {
4476
+ return '';
4477
+ }
4478
+ };
4479
+
4374
4480
  const isValidTab = tab => {
4375
4481
  return tab && typeof tab.id === 'number' && typeof tab.title === 'string' && typeof tab.isDirty === 'boolean' && typeof tab.isPreview === 'boolean' && typeof tab.editorUid === 'number' && typeof tab.icon === 'string' && (tab.editorType === 'text' || tab.editorType === 'custom');
4376
4482
  };
@@ -4562,10 +4668,15 @@ const restoreAndCreateEditors = async (state, restoredLayout) => {
4562
4668
  };
4563
4669
 
4564
4670
  const loadContent = async (state, savedState) => {
4671
+ const homeDirUri = await loadHomeDirUri();
4672
+ const stateWithHomeDir = {
4673
+ ...state,
4674
+ homeDirUri
4675
+ };
4565
4676
  const restoredLayout = tryRestoreLayout(savedState);
4566
4677
  if (restoredLayout) {
4567
4678
  // Restore and create editors
4568
- const editorState = await restoreAndCreateEditors(state, restoredLayout);
4679
+ const editorState = await restoreAndCreateEditors(stateWithHomeDir, restoredLayout);
4569
4680
 
4570
4681
  // Load file icons with the updated editor state
4571
4682
  const {
@@ -4574,16 +4685,16 @@ const loadContent = async (state, savedState) => {
4574
4685
  } = await loadFileIcons(editorState);
4575
4686
 
4576
4687
  // Merge the results
4577
- const finalState = {
4688
+ const finalState = updateTabUriTitles({
4578
4689
  ...editorState,
4579
4690
  fileIconCache,
4580
4691
  initial: false,
4581
4692
  layout: updatedLayout
4582
- };
4693
+ });
4583
4694
  return finalState;
4584
4695
  }
4585
4696
  return {
4586
- ...state,
4697
+ ...stateWithHomeDir,
4587
4698
  initial: false,
4588
4699
  layout: {
4589
4700
  activeGroupId: undefined,
@@ -4721,7 +4832,7 @@ const pin = () => {
4721
4832
  const splitAndMove = () => {
4722
4833
  return i18nString(SplitAndMove);
4723
4834
  };
4724
- const moveIntoNewWindow = () => {
4835
+ const moveIntoNewWindow$1 = () => {
4725
4836
  return i18nString(MoveIntoNewWindow);
4726
4837
  };
4727
4838
  const copyIntoNewWindow = () => {
@@ -4803,16 +4914,6 @@ const getMenuEntries$2 = (state, groupId) => {
4803
4914
  }];
4804
4915
  };
4805
4916
 
4806
- const findGroupById = (state, groupId) => {
4807
- const {
4808
- layout
4809
- } = state;
4810
- const {
4811
- groups
4812
- } = layout;
4813
- return groups.find(group => group.id === groupId);
4814
- };
4815
-
4816
4917
  // TODO should pass tab uri as argument or tab index
4817
4918
  const getMenuEntries$1 = state => {
4818
4919
  const {
@@ -4920,12 +5021,12 @@ const getMenuEntries$1 = state => {
4920
5021
  id: 'splitAndMove',
4921
5022
  label: splitAndMove()
4922
5023
  }, {
4923
- command: '',
5024
+ command: 'MainArea.moveIntoNewWindow',
4924
5025
  flags: None,
4925
5026
  id: 'moveIntoNewWindow',
4926
- label: moveIntoNewWindow()
5027
+ label: moveIntoNewWindow$1()
4927
5028
  }, {
4928
- command: '',
5029
+ command: 'MainArea.copyIntoNewWindow',
4929
5030
  flags: None,
4930
5031
  id: 'copyIntoNewWindow',
4931
5032
  label: copyIntoNewWindow()
@@ -4949,8 +5050,30 @@ const getMenuEntries = async (state, props) => {
4949
5050
  }
4950
5051
  };
4951
5052
 
5053
+ const moveIntoNewWindow = async state => {
5054
+ const {
5055
+ activeGroupId
5056
+ } = state.layout;
5057
+ const group = findGroupById(state, activeGroupId ?? 0);
5058
+ if (!group) {
5059
+ return state;
5060
+ }
5061
+ const {
5062
+ activeTabId
5063
+ } = group;
5064
+ if (activeTabId === undefined) {
5065
+ return state;
5066
+ }
5067
+ const tab = group.tabs.find(tab => tab.id === activeTabId);
5068
+ if (!tab?.uri) {
5069
+ return state;
5070
+ }
5071
+ await invoke('ElectronWindow.openNewWithUri', tab.uri);
5072
+ return closeTabAndSave(state, group.id, activeTabId);
5073
+ };
5074
+
4952
5075
  const newWindow = async state => {
4953
- await invoke('Main.newWindow');
5076
+ await invoke('ElectronWindow.openNew');
4954
5077
  return state;
4955
5078
  };
4956
5079
 
@@ -5518,7 +5641,7 @@ const renderTab = (tab, isActive, tabIndex, groupIndex) => {
5518
5641
  onContextMenu: HandleTabContextMenu,
5519
5642
  onMouseDown: HandleClickTab,
5520
5643
  role: 'tab',
5521
- title: tab.uri || tab.title,
5644
+ title: tab.uriTitle || tab.uri || tab.title,
5522
5645
  type: Div
5523
5646
  }, {
5524
5647
  childCount: 0,
@@ -5995,6 +6118,178 @@ const saveState = state => {
5995
6118
  };
5996
6119
  };
5997
6120
 
6121
+ const flipDirection = direction => {
6122
+ return direction === Horizontal ? Vertical : Horizontal;
6123
+ };
6124
+ const createEmptyGroup = () => {
6125
+ return {
6126
+ activeTabId: undefined,
6127
+ focused: false,
6128
+ id: create$1(),
6129
+ isEmpty: true,
6130
+ size: 100,
6131
+ tabs: []
6132
+ };
6133
+ };
6134
+ const getActiveGroupIndex = (groups, activeGroupId) => {
6135
+ const activeIndex = groups.findIndex(group => group.id === activeGroupId);
6136
+ if (activeIndex !== -1) {
6137
+ return activeIndex;
6138
+ }
6139
+ const focusedIndex = groups.findIndex(group => group.focused);
6140
+ if (focusedIndex !== -1) {
6141
+ return focusedIndex;
6142
+ }
6143
+ return 0;
6144
+ };
6145
+ const mergeGroups = (target, groups, activeGroupId) => {
6146
+ const allGroups = [target, ...groups];
6147
+ const tabs = allGroups.flatMap(group => group.tabs);
6148
+ const activeGroup = allGroups.find(group => group.id === activeGroupId) ?? groups.findLast(group => group.activeTabId !== undefined) ?? target;
6149
+ const activeTabId = activeGroup.activeTabId ?? tabs[0]?.id;
6150
+ return {
6151
+ ...target,
6152
+ activeTabId,
6153
+ isEmpty: tabs.length === 0,
6154
+ tabs
6155
+ };
6156
+ };
6157
+ const getGroupsForSlotCount = (groups, slotCount, activeGroupId) => {
6158
+ if (slotCount === 1) {
6159
+ const firstGroup = groups[0] ?? createEmptyGroup();
6160
+ return [mergeGroups(firstGroup, groups.slice(1), activeGroupId)];
6161
+ }
6162
+ if (groups.length === slotCount) {
6163
+ return groups;
6164
+ }
6165
+ if (groups.length < slotCount) {
6166
+ const missingGroups = Array.from({
6167
+ length: slotCount - groups.length
6168
+ }, createEmptyGroup);
6169
+ return [...groups, ...missingGroups];
6170
+ }
6171
+ const retainedGroups = groups.slice(0, slotCount);
6172
+ const extraGroups = groups.slice(slotCount);
6173
+ const lastGroup = retainedGroups.at(-1);
6174
+ if (!lastGroup) {
6175
+ return retainedGroups;
6176
+ }
6177
+ return [...retainedGroups.slice(0, -1), mergeGroups(lastGroup, extraGroups, activeGroupId)];
6178
+ };
6179
+ const setEditorLayout = (state, direction, slots) => {
6180
+ const {
6181
+ layout
6182
+ } = state;
6183
+ const groups = getGroupsForSlotCount(layout.groups, slots.length, layout.activeGroupId);
6184
+ const originalActiveIndex = layout.groups.findIndex(group => group.id === layout.activeGroupId);
6185
+ const activeIndex = originalActiveIndex >= slots.length ? slots.length - 1 : getActiveGroupIndex(groups, layout.activeGroupId);
6186
+ const nextGroups = groups.map((group, index) => {
6187
+ const slot = slots[index];
6188
+ const focused = index === activeIndex;
6189
+ return {
6190
+ ...group,
6191
+ direction: slot.direction,
6192
+ focused,
6193
+ size: slot.size
6194
+ };
6195
+ });
6196
+ return {
6197
+ ...state,
6198
+ layout: {
6199
+ activeGroupId: nextGroups[activeIndex]?.id,
6200
+ direction,
6201
+ groups: nextGroups
6202
+ }
6203
+ };
6204
+ };
6205
+ const flipLayout = state => {
6206
+ return {
6207
+ ...state,
6208
+ layout: {
6209
+ ...state.layout,
6210
+ direction: flipDirection(state.layout.direction),
6211
+ groups: state.layout.groups.map(group => ({
6212
+ ...group,
6213
+ direction: group.direction === undefined ? undefined : flipDirection(group.direction)
6214
+ }))
6215
+ }
6216
+ };
6217
+ };
6218
+ const setEditorLayoutSingle = state => {
6219
+ return setEditorLayout(state, Horizontal, [{
6220
+ size: 100
6221
+ }]);
6222
+ };
6223
+ const setEditorLayoutTwoColumns = state => {
6224
+ return setEditorLayout(state, Horizontal, [{
6225
+ size: 50
6226
+ }, {
6227
+ size: 50
6228
+ }]);
6229
+ };
6230
+ const setEditorLayoutThreeColumns = state => {
6231
+ return setEditorLayout(state, Horizontal, [{
6232
+ size: 33.333333
6233
+ }, {
6234
+ size: 33.333333
6235
+ }, {
6236
+ size: 33.333334
6237
+ }]);
6238
+ };
6239
+ const setEditorLayoutTwoRows = state => {
6240
+ return setEditorLayout(state, Vertical, [{
6241
+ size: 50
6242
+ }, {
6243
+ size: 50
6244
+ }]);
6245
+ };
6246
+ const setEditorLayoutThreeRows = state => {
6247
+ return setEditorLayout(state, Vertical, [{
6248
+ size: 33.333333
6249
+ }, {
6250
+ size: 33.333333
6251
+ }, {
6252
+ size: 33.333334
6253
+ }]);
6254
+ };
6255
+ const setEditorLayoutGrid = state => {
6256
+ return setEditorLayout(state, Horizontal, [{
6257
+ direction: Vertical,
6258
+ size: 25
6259
+ }, {
6260
+ direction: Vertical,
6261
+ size: 25
6262
+ }, {
6263
+ direction: Vertical,
6264
+ size: 25
6265
+ }, {
6266
+ direction: Vertical,
6267
+ size: 25
6268
+ }]);
6269
+ };
6270
+ const setEditorLayoutTwoRowsRight = state => {
6271
+ return setEditorLayout(state, Horizontal, [{
6272
+ size: 50
6273
+ }, {
6274
+ direction: Vertical,
6275
+ size: 25
6276
+ }, {
6277
+ direction: Vertical,
6278
+ size: 25
6279
+ }]);
6280
+ };
6281
+ const setEditorLayoutTwoColumnsBottom = state => {
6282
+ return setEditorLayout(state, Vertical, [{
6283
+ size: 50
6284
+ }, {
6285
+ direction: Horizontal,
6286
+ size: 25
6287
+ }, {
6288
+ direction: Horizontal,
6289
+ size: 25
6290
+ }]);
6291
+ };
6292
+
5998
6293
  const splitDown = (state, groupId) => {
5999
6294
  const {
6000
6295
  layout
@@ -6165,10 +6460,12 @@ const commandMap = {
6165
6460
  'MainArea.closeSaved': wrapCommand(closeSaved$1),
6166
6461
  'MainArea.closeTabsByUris': wrapCommand(closeTabsByUris),
6167
6462
  'MainArea.closeTabsRight': wrapCommand(closeTabsRight),
6463
+ 'MainArea.copyIntoNewWindow': wrapCommand(copyIntoNewWindow$1),
6168
6464
  'MainArea.copyPath': wrapCommand(copyPath$1),
6169
6465
  'MainArea.copyRelativePath': wrapCommand(copyRelativePath$1),
6170
6466
  'MainArea.create': create$2,
6171
6467
  'MainArea.diff2': diff2,
6468
+ 'MainArea.flipEditorLayout': wrapCommand(flipLayout),
6172
6469
  'MainArea.focusNext': wrapCommand(focusNextTab),
6173
6470
  'MainArea.focusNextTab': wrapCommand(focusNextTab),
6174
6471
  'MainArea.focusPrevious': wrapCommand(focusPreviousTab),
@@ -6196,6 +6493,7 @@ const commandMap = {
6196
6493
  'MainArea.handleWorkspaceChange': wrapCommand(handleWorkspaceChange),
6197
6494
  'MainArea.initialize': initialize,
6198
6495
  'MainArea.loadContent': wrapCommand(loadContent),
6496
+ 'MainArea.moveIntoNewWindow': wrapCommand(moveIntoNewWindow),
6199
6497
  'MainArea.newFile': wrapCommand(newFile),
6200
6498
  'MainArea.newWindow': wrapCommand(newWindow),
6201
6499
  'MainArea.openInput': wrapCommand(openInput),
@@ -6209,6 +6507,14 @@ const commandMap = {
6209
6507
  'MainArea.save': wrapCommand(save),
6210
6508
  'MainArea.saveState': wrapGetter(saveState),
6211
6509
  'MainArea.selectTab': wrapCommand(selectTab),
6510
+ 'MainArea.setEditorLayoutGrid': wrapCommand(setEditorLayoutGrid),
6511
+ 'MainArea.setEditorLayoutSingle': wrapCommand(setEditorLayoutSingle),
6512
+ 'MainArea.setEditorLayoutThreeColumns': wrapCommand(setEditorLayoutThreeColumns),
6513
+ 'MainArea.setEditorLayoutThreeRows': wrapCommand(setEditorLayoutThreeRows),
6514
+ 'MainArea.setEditorLayoutTwoColumns': wrapCommand(setEditorLayoutTwoColumns),
6515
+ 'MainArea.setEditorLayoutTwoColumnsBottom': wrapCommand(setEditorLayoutTwoColumnsBottom),
6516
+ 'MainArea.setEditorLayoutTwoRows': wrapCommand(setEditorLayoutTwoRows),
6517
+ 'MainArea.setEditorLayoutTwoRowsRight': wrapCommand(setEditorLayoutTwoRowsRight),
6212
6518
  'MainArea.splitDown': wrapCommand(splitDown),
6213
6519
  'MainArea.splitLeft': wrapCommand(splitLeft),
6214
6520
  'MainArea.splitRight': wrapCommand(splitRight),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.19.0",
3
+ "version": "9.20.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",