@lvce-editor/main-area-worker 9.24.0 → 9.27.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.
@@ -3,10 +3,67 @@ const toCommandId = key => {
3
3
  return key.slice(dotIndex + 1);
4
4
  };
5
5
  const create$f = () => {
6
+ const commandQueues = new Map();
7
+ const generations = Object.create(null);
6
8
  const states = Object.create(null);
7
9
  const commandMapRef = {};
10
+ const getGeneration = uid => generations[uid] || 0;
11
+ const isCurrentGeneration = (uid, generation) => {
12
+ return states[uid] !== undefined && getGeneration(uid) === generation;
13
+ };
14
+ const updateState = (uid, generation, fallbackState, updater) => {
15
+ if (!isCurrentGeneration(uid, generation)) {
16
+ return Promise.resolve(fallbackState);
17
+ }
18
+ const current = states[uid];
19
+ const updatedState = updater(current.newState);
20
+ if (updatedState !== current.newState) {
21
+ states[uid] = {
22
+ newState: updatedState,
23
+ oldState: current.oldState,
24
+ scheduledState: updatedState
25
+ };
26
+ }
27
+ return Promise.resolve(updatedState);
28
+ };
29
+ const createAsyncCommandContext = (uid, generation) => {
30
+ let latestState = states[uid].newState;
31
+ return {
32
+ getState: () => {
33
+ if (isCurrentGeneration(uid, generation)) {
34
+ latestState = states[uid].newState;
35
+ }
36
+ return latestState;
37
+ },
38
+ updateState: async updater => {
39
+ latestState = await updateState(uid, generation, latestState, updater);
40
+ return latestState;
41
+ }
42
+ };
43
+ };
44
+ const enqueueCommand = async (uid, command) => {
45
+ const previous = commandQueues.get(uid) || Promise.resolve();
46
+ const run = async () => {
47
+ try {
48
+ await previous;
49
+ } catch {
50
+ // The previous caller receives its error; later commands must still run.
51
+ }
52
+ await command();
53
+ };
54
+ const current = run();
55
+ commandQueues.set(uid, current);
56
+ try {
57
+ await current;
58
+ } finally {
59
+ if (commandQueues.get(uid) === current) {
60
+ commandQueues.delete(uid);
61
+ }
62
+ }
63
+ };
8
64
  return {
9
65
  clear() {
66
+ commandQueues.clear();
10
67
  for (const key of Object.keys(states)) {
11
68
  delete states[key];
12
69
  }
@@ -26,6 +83,7 @@ const create$f = () => {
26
83
  return diffResult;
27
84
  },
28
85
  dispose(uid) {
86
+ commandQueues.delete(uid);
29
87
  delete states[uid];
30
88
  },
31
89
  get(uid) {
@@ -43,14 +101,27 @@ const create$f = () => {
43
101
  Object.assign(commandMapRef, commandMap);
44
102
  },
45
103
  set(uid, oldState, newState, scheduledState) {
104
+ const current = states[uid];
105
+ if (!current || oldState === newState && newState !== current.newState) {
106
+ generations[uid] = getGeneration(uid) + 1;
107
+ }
46
108
  states[uid] = {
47
109
  newState,
48
110
  oldState,
49
111
  scheduledState: scheduledState ?? newState
50
112
  };
51
113
  },
114
+ wrapAsyncCommand(fn) {
115
+ const wrapped = async (uid, ...args) => {
116
+ const generation = getGeneration(uid);
117
+ const context = createAsyncCommandContext(uid, generation);
118
+ await fn(context, ...args);
119
+ };
120
+ return wrapped;
121
+ },
52
122
  wrapCommand(fn) {
53
123
  const wrapped = async (uid, ...args) => {
124
+ const generation = getGeneration(uid);
54
125
  const {
55
126
  newState,
56
127
  oldState
@@ -59,6 +130,9 @@ const create$f = () => {
59
130
  if (oldState === newerState || newState === newerState) {
60
131
  return;
61
132
  }
133
+ if (!isCurrentGeneration(uid, generation)) {
134
+ return;
135
+ }
62
136
  const latestOld = states[uid];
63
137
  const latestNew = {
64
138
  ...latestOld.newState,
@@ -83,6 +157,7 @@ const create$f = () => {
83
157
  },
84
158
  wrapLoadContent(fn) {
85
159
  const wrapped = async (uid, ...args) => {
160
+ const generation = getGeneration(uid);
86
161
  const {
87
162
  newState,
88
163
  oldState
@@ -97,6 +172,11 @@ const create$f = () => {
97
172
  error
98
173
  };
99
174
  }
175
+ if (!isCurrentGeneration(uid, generation)) {
176
+ return {
177
+ error
178
+ };
179
+ }
100
180
  const latestOld = states[uid];
101
181
  const latestNew = {
102
182
  ...latestOld.newState,
@@ -112,6 +192,51 @@ const create$f = () => {
112
192
  };
113
193
  };
114
194
  return wrapped;
195
+ },
196
+ wrapSerialAsyncCommand(fn) {
197
+ const wrapped = async (uid, ...args) => {
198
+ await enqueueCommand(uid, async () => {
199
+ if (!states[uid]) {
200
+ return;
201
+ }
202
+ const generation = getGeneration(uid);
203
+ const context = createAsyncCommandContext(uid, generation);
204
+ await fn(context, ...args);
205
+ });
206
+ };
207
+ return wrapped;
208
+ },
209
+ wrapSerialCommand(fn) {
210
+ const wrapped = async (uid, ...args) => {
211
+ await enqueueCommand(uid, async () => {
212
+ if (!states[uid]) {
213
+ return;
214
+ }
215
+ const generation = getGeneration(uid);
216
+ const {
217
+ newState,
218
+ oldState
219
+ } = states[uid];
220
+ const newerState = await fn(newState, ...args);
221
+ if (oldState === newerState || newState === newerState) {
222
+ return;
223
+ }
224
+ if (!isCurrentGeneration(uid, generation)) {
225
+ return;
226
+ }
227
+ const latestOld = states[uid];
228
+ const latestNew = {
229
+ ...latestOld.newState,
230
+ ...newerState
231
+ };
232
+ states[uid] = {
233
+ newState: latestNew,
234
+ oldState: latestOld.oldState,
235
+ scheduledState: latestNew
236
+ };
237
+ });
238
+ };
239
+ return wrapped;
115
240
  }
116
241
  };
117
242
  };
@@ -2125,8 +2250,10 @@ const {
2125
2250
  getKeys: getKeys$1,
2126
2251
  registerCommands,
2127
2252
  set,
2128
- wrapCommand,
2129
- wrapGetter
2253
+ wrapAsyncCommand,
2254
+ wrapGetter,
2255
+ wrapSerialAsyncCommand,
2256
+ wrapSerialCommand
2130
2257
  } = create$f();
2131
2258
 
2132
2259
  const create$2 = (uid, uri, x, y, width, height, platform, assetDir, tabHeight = 35) => {
@@ -2200,6 +2327,19 @@ const handleAttach = async command => {
2200
2327
  await invoke('Layout.attachViewlet', parentNodeSelector, command.instanceId);
2201
2328
  };
2202
2329
 
2330
+ const getTitle$1 = async editorUid => {
2331
+ try {
2332
+ const title = await invoke('Viewlet.getTitle', editorUid);
2333
+ return typeof title === 'string' && title ? title : undefined;
2334
+ } catch {
2335
+ return undefined;
2336
+ }
2337
+ };
2338
+ const createViewlet = async (viewletModuleId, editorUid, tabId, bounds, uri) => {
2339
+ await invoke('Layout.createViewlet', viewletModuleId, editorUid, tabId, bounds, uri);
2340
+ return getTitle$1(editorUid);
2341
+ };
2342
+
2203
2343
  const create$1 = () => {
2204
2344
  return Math.random();
2205
2345
  };
@@ -2372,7 +2512,7 @@ const findTabByEditorUid = (state, editorUid) => {
2372
2512
  * With reference nodes, attachment is handled automatically by virtual DOM rendering.
2373
2513
  * No commands needed - state update is sufficient.
2374
2514
  */
2375
- const handleViewletReady = (state, editorUid) => {
2515
+ const handleViewletReady = (state, editorUid, title) => {
2376
2516
  if (editorUid === -1) {
2377
2517
  throw new Error('Invalid editorUid -1');
2378
2518
  }
@@ -2387,7 +2527,10 @@ const handleViewletReady = (state, editorUid) => {
2387
2527
  // Reference nodes will handle rendering at the correct position automatically
2388
2528
  const newState = updateTab(state, tab.id, {
2389
2529
  editorUid,
2390
- loadingState: 'loaded'
2530
+ loadingState: 'loaded',
2531
+ ...(title && {
2532
+ title
2533
+ })
2391
2534
  });
2392
2535
 
2393
2536
  // No attach commands needed - virtual DOM reference nodes handle positioning
@@ -2397,9 +2540,7 @@ const handleViewletReady = (state, editorUid) => {
2397
2540
  const handleCreate = async command => {
2398
2541
  // Safe to call - no visible side effects
2399
2542
 
2400
- const instanceId = Math.random(); // TODO try to find a better way to get consistent integer ids (thread safe)
2401
-
2402
- await invoke('Layout.createViewlet', command.viewletModuleId, command.tabId, command.bounds, command.uri, instanceId);
2543
+ const title = await createViewlet(command.viewletModuleId, command.editorUid, command.tabId, command.bounds, command.uri || '');
2403
2544
 
2404
2545
  // After viewlet is created, mark it as ready
2405
2546
  // Attachment is handled automatically by virtual DOM reference nodes
@@ -2407,7 +2548,7 @@ const handleCreate = async command => {
2407
2548
  newState: state,
2408
2549
  oldState
2409
2550
  } = get(command.uid);
2410
- const readyState = handleViewletReady(state, command.editorUid);
2551
+ const readyState = handleViewletReady(state, command.editorUid, title);
2411
2552
  set(command.uid, oldState, readyState);
2412
2553
  return readyState;
2413
2554
  };
@@ -2685,10 +2826,6 @@ const getUpdatedGroups = (groups, groupIndex, needsLoading, tabId) => {
2685
2826
  });
2686
2827
  };
2687
2828
 
2688
- const createViewlet = async (viewletModuleId, editorUid, tabId, bounds, uri) => {
2689
- await invoke('Layout.createViewlet', viewletModuleId, editorUid, tabId, bounds, uri);
2690
- };
2691
-
2692
2829
  const findTabById = (state, tabId) => {
2693
2830
  const {
2694
2831
  layout
@@ -2803,8 +2940,8 @@ const maybeCreateViewletForSelectedTab = async (state, newState, groupIndex, ind
2803
2940
  editorUid
2804
2941
  } = tabWithViewlet.tab;
2805
2942
  if (editorUid !== -1 && selectedTab.uri) {
2806
- await createViewlet(viewletModuleId, editorUid, tabId, bounds, selectedTab.uri);
2807
- stateWithViewlet = handleViewletReady(stateWithViewlet, editorUid);
2943
+ const title = await createViewlet(viewletModuleId, editorUid, tabId, bounds, selectedTab.uri);
2944
+ stateWithViewlet = handleViewletReady(stateWithViewlet, editorUid, title);
2808
2945
  set(uid, state, stateWithViewlet);
2809
2946
  }
2810
2947
  }
@@ -3669,7 +3806,7 @@ const getFileIconsForTabs = async (tabs, fileIconCache) => {
3669
3806
  };
3670
3807
  };
3671
3808
 
3672
- const updateTabIcon = async (uid, state, readyState, tabId) => {
3809
+ const updateTabIcon = async (context, readyState, tabId) => {
3673
3810
  const newTab = findTabById(readyState, tabId);
3674
3811
  if (!newTab || !newTab.tab.uri) {
3675
3812
  return undefined;
@@ -3678,9 +3815,7 @@ const updateTabIcon = async (uid, state, readyState, tabId) => {
3678
3815
  const {
3679
3816
  newFileIconCache
3680
3817
  } = await getFileIconsForTabs([newTab.tab], readyState.fileIconCache);
3681
- const {
3682
- newState: stateBeforeIconUpdate
3683
- } = get(uid);
3818
+ const stateBeforeIconUpdate = context.getState();
3684
3819
  const icon = newFileIconCache[newTab.tab.uri] || '';
3685
3820
  const stateWithIcon = {
3686
3821
  ...stateBeforeIconUpdate,
@@ -3696,19 +3831,16 @@ const updateTabIcon = async (uid, state, readyState, tabId) => {
3696
3831
  }))
3697
3832
  }
3698
3833
  };
3699
- set(uid, state, stateWithIcon);
3700
- return stateWithIcon;
3834
+ return context.updateState(() => stateWithIcon);
3701
3835
  } catch {
3702
3836
  return undefined;
3703
3837
  }
3704
3838
  };
3705
3839
 
3706
- const openInput = async (state, options) => {
3840
+ const openInputWithContext = async (context, options) => {
3841
+ const state = context.getState();
3707
3842
  object(state);
3708
3843
  object(options);
3709
- const {
3710
- uid
3711
- } = state;
3712
3844
  const {
3713
3845
  editorInput
3714
3846
  } = options;
@@ -3716,40 +3848,40 @@ const openInput = async (state, options) => {
3716
3848
  const uri = getEditorInputUri(editorInput);
3717
3849
  const title = getEditorInputTitle(editorInput);
3718
3850
  const editorType = getEditorInputEditorType(editorInput);
3719
- const currentState = getCurrentState(state);
3851
+ const currentState = state;
3720
3852
  const existingTab = findTabByUri(currentState, uri);
3721
3853
  const shouldRetryExistingTab = !!existingTab && existingTab.tab.loadingState === 'error';
3722
3854
  if (existingTab && !shouldRetryExistingTab) {
3723
3855
  const focusedState = focusEditorGroup(currentState, existingTab.groupId);
3724
- return switchTab(focusedState, existingTab.groupId, existingTab.tab.id);
3856
+ const switchedState = switchTab(focusedState, existingTab.groupId, existingTab.tab.id);
3857
+ await context.updateState(() => switchedState);
3858
+ return;
3725
3859
  }
3726
3860
  const previousTabId = getActiveTabId(currentState);
3727
3861
  const {
3728
3862
  stateWithTab,
3729
3863
  tabId
3730
3864
  } = getStateWithTab(currentState, editorInput, existingTab, shouldRetryExistingTab, uri, preview, title, editorType);
3731
- set(uid, state, stateWithTab);
3865
+ await context.updateState(() => stateWithTab);
3732
3866
  if (await isDirectoryEditorInput(editorInput)) {
3733
- const {
3734
- newState: latestState
3735
- } = get(uid);
3867
+ const latestState = context.getState();
3736
3868
  const errorState = updateTab(latestState, tabId, {
3737
3869
  errorMessage: 'Expected a file but received a folder',
3738
3870
  loadingState: 'error'
3739
3871
  });
3740
- set(uid, state, errorState);
3741
- return errorState;
3872
+ await context.updateState(() => errorState);
3873
+ return;
3742
3874
  }
3743
3875
  try {
3744
3876
  const viewletModuleId = await getViewletModuleIdForEditorInput(editorInput);
3745
- const {
3746
- newState: stateAfterModuleId
3747
- } = get(uid);
3877
+ const stateAfterModuleId = context.getState();
3748
3878
  if (!viewletModuleId) {
3749
- return updateTab(stateAfterModuleId, tabId, {
3879
+ const unsupportedState = updateTab(stateAfterModuleId, tabId, {
3750
3880
  errorMessage: 'Could not determine editor type for this URI',
3751
3881
  loadingState: 'error'
3752
3882
  });
3883
+ await context.updateState(() => unsupportedState);
3884
+ return;
3753
3885
  }
3754
3886
  const bounds = {
3755
3887
  height: stateAfterModuleId.height - stateAfterModuleId.tabHeight,
@@ -3763,10 +3895,10 @@ const openInput = async (state, options) => {
3763
3895
  newState: switchedState
3764
3896
  } = switchViewlet(intermediateState, previousTabId, tabId);
3765
3897
  intermediateState = switchedState;
3766
- set(uid, state, intermediateState);
3898
+ await context.updateState(() => intermediateState);
3767
3899
  const tabWithViewlet = findTabById(intermediateState, tabId);
3768
3900
  if (!tabWithViewlet) {
3769
- return intermediateState;
3901
+ return;
3770
3902
  }
3771
3903
  const {
3772
3904
  editorUid
@@ -3774,33 +3906,42 @@ const openInput = async (state, options) => {
3774
3906
  if (editorUid === -1) {
3775
3907
  throw new Error('invalid editorUid');
3776
3908
  }
3777
- await createViewlet(viewletModuleId, editorUid, tabId, bounds, uri);
3778
- const {
3779
- newState: latestState
3780
- } = get(uid);
3781
- const readyState = handleViewletReady(latestState, editorUid);
3782
- set(uid, state, readyState);
3783
- const stateWithIcon = await updateTabIcon(uid, state, readyState, tabId);
3909
+ const renderedTitle = await createViewlet(viewletModuleId, editorUid, tabId, bounds, uri);
3910
+ const latestState = context.getState();
3911
+ const readyState = handleViewletReady(latestState, editorUid, renderedTitle);
3912
+ await context.updateState(() => readyState);
3913
+ const stateWithIcon = await updateTabIcon(context, readyState, tabId);
3784
3914
  if (stateWithIcon) {
3785
- return stateWithIcon;
3915
+ return;
3786
3916
  }
3787
- const {
3788
- newState: finalState
3789
- } = get(uid);
3790
- return finalState;
3791
3917
  } catch (error) {
3792
- const {
3793
- newState: latestState
3794
- } = get(uid);
3918
+ const latestState = context.getState();
3795
3919
  const errorMessage = error instanceof Error ? error.message : 'Failed to open URI';
3796
3920
  const errorState = updateTab(latestState, tabId, {
3797
3921
  errorMessage,
3798
3922
  loadingState: 'error'
3799
3923
  });
3800
- set(uid, state, errorState);
3801
- return errorState;
3924
+ await context.updateState(() => errorState);
3802
3925
  }
3803
3926
  };
3927
+ const openInput = async (state, options) => {
3928
+ const {
3929
+ uid
3930
+ } = state;
3931
+ let currentState = getCurrentState(state);
3932
+ const context = {
3933
+ getState: () => get(uid)?.newState ?? currentState,
3934
+ updateState: updater => {
3935
+ const storedState = get(uid);
3936
+ const latestState = storedState?.newState ?? currentState;
3937
+ currentState = updater(latestState);
3938
+ set(uid, storedState?.oldState ?? state, currentState);
3939
+ return Promise.resolve(currentState);
3940
+ }
3941
+ };
3942
+ await openInputWithContext(context, options);
3943
+ return context.getState();
3944
+ };
3804
3945
 
3805
3946
  const getOptionUriOptions = options => {
3806
3947
  if (typeof options === 'string') {
@@ -3809,14 +3950,20 @@ const getOptionUriOptions = options => {
3809
3950
  return options.uri;
3810
3951
  };
3811
3952
 
3812
- const openUri = async (state, options) => {
3953
+ const getOpenInputOptions = options => {
3813
3954
  const uri = getOptionUriOptions(options);
3814
3955
  const preview = typeof options === 'string' ? false : options.preview ?? false;
3815
- return openInput(state, {
3956
+ return {
3816
3957
  editorInput: getNormalizedOpenEditorInput(uri),
3817
3958
  focus: typeof options === 'string' ? false : options.focus,
3818
3959
  preview
3819
- });
3960
+ };
3961
+ };
3962
+ const openUri = async (state, options) => {
3963
+ return openInput(state, getOpenInputOptions(options));
3964
+ };
3965
+ const openUriWithContext = async (context, options) => {
3966
+ await openInputWithContext(context, getOpenInputOptions(options));
3820
3967
  };
3821
3968
 
3822
3969
  const retryOpen = async state => {
@@ -4265,13 +4412,13 @@ const newFile = async state => {
4265
4412
  if (actualEditorUid === -1) {
4266
4413
  throw new Error(`invalid editorUid`);
4267
4414
  }
4268
- await createViewlet(viewletModuleId, actualEditorUid, tabId, bounds, newTab.uri || '');
4415
+ const title = await createViewlet(viewletModuleId, actualEditorUid, tabId, bounds, newTab.uri || '');
4269
4416
 
4270
4417
  // After viewlet is created, get the latest state and mark it as ready
4271
4418
  const {
4272
4419
  newState: latestState
4273
4420
  } = get(uid);
4274
- const readyState = handleViewletReady(latestState, actualEditorUid);
4421
+ const readyState = handleViewletReady(latestState, actualEditorUid, title);
4275
4422
  return readyState;
4276
4423
  };
4277
4424
 
@@ -4366,6 +4513,9 @@ const handleModifiedStatusChange = (state, uri, newStatus) => {
4366
4513
  }
4367
4514
  };
4368
4515
  };
4516
+ const handleModifiedStatusChangeWithContext = async (context, uri, newStatus) => {
4517
+ await context.updateState(state => handleModifiedStatusChange(state, uri, newStatus));
4518
+ };
4369
4519
 
4370
4520
  const handleResize = async (state, dimensions) => {
4371
4521
  const {
@@ -4598,47 +4748,6 @@ const handleUriChange = async (state, oldUri, newUri) => {
4598
4748
  };
4599
4749
  };
4600
4750
 
4601
- const handleWorkspaceChange = state => {
4602
- const {
4603
- layout
4604
- } = state;
4605
- return {
4606
- ...state,
4607
- layout: {
4608
- ...layout,
4609
- activeGroupId: undefined,
4610
- groups: []
4611
- }
4612
- };
4613
- };
4614
-
4615
- const hasActiveTextEditor = state => {
4616
- const activeTab = getActiveTab(state);
4617
- return activeTab?.tab.editorInput?.type === 'editor';
4618
- };
4619
-
4620
- const id = 7201;
4621
- const sendMessagePortToExtensionHostWorker = async port => {
4622
- await sendMessagePortToExtensionHostWorker$1(port, id);
4623
- };
4624
-
4625
- const createExtensionHostRpc = async () => {
4626
- try {
4627
- const rpc = await create$8({
4628
- commandMap: {},
4629
- send: sendMessagePortToExtensionHostWorker
4630
- });
4631
- return rpc;
4632
- } catch (error) {
4633
- throw new VError(error, `Failed to create extension host rpc`);
4634
- }
4635
- };
4636
-
4637
- const initialize = async () => {
4638
- const rpc = await createExtensionHostRpc();
4639
- set$3(rpc);
4640
- };
4641
-
4642
4751
  const toFileUri = path => {
4643
4752
  if (!path) {
4644
4753
  return '';
@@ -4748,15 +4857,22 @@ const tryRestoreLayout = savedState => {
4748
4857
 
4749
4858
  const createViewlets = async (layout, viewletModuleIds, bounds) => {
4750
4859
  const editorUids = {};
4860
+ const titles = {};
4751
4861
  for (const group of layout.groups) {
4752
4862
  const activeTab = group.tabs.find(tab => tab.id === group.activeTabId);
4753
4863
  if (activeTab && viewletModuleIds[activeTab.id]) {
4754
4864
  const editorUid = activeTab.editorUid === -1 ? create$1() : activeTab.editorUid;
4755
4865
  editorUids[activeTab.id] = editorUid;
4756
- await createViewlet(viewletModuleIds[activeTab.id], editorUid, activeTab.id, bounds, activeTab.uri);
4866
+ const title = await createViewlet(viewletModuleIds[activeTab.id], editorUid, activeTab.id, bounds, activeTab.uri);
4867
+ if (title) {
4868
+ titles[activeTab.id] = title;
4869
+ }
4757
4870
  }
4758
4871
  }
4759
- return editorUids;
4872
+ return {
4873
+ editorUids,
4874
+ titles
4875
+ };
4760
4876
  };
4761
4877
 
4762
4878
  const getViewletModuleIds = async layout => {
@@ -4833,7 +4949,10 @@ const restoreAndCreateEditors = async (state, restoredLayout) => {
4833
4949
  const viewletModuleIds = await getViewletModuleIds(newState.layout);
4834
4950
 
4835
4951
  // Create viewlets and get editor UIDs
4836
- const editorUids = await createViewlets(newState.layout, viewletModuleIds, bounds);
4952
+ const {
4953
+ editorUids,
4954
+ titles
4955
+ } = await createViewlets(newState.layout, viewletModuleIds, bounds);
4837
4956
 
4838
4957
  // Update tabs with editor UIDs
4839
4958
  newState = updateTabs(newState, editorUids);
@@ -4844,7 +4963,7 @@ const restoreAndCreateEditors = async (state, restoredLayout) => {
4844
4963
  if (activeTab && viewletModuleIds[activeTab.id]) {
4845
4964
  const editorUid = editorUids[activeTab.id];
4846
4965
  newState = createViewletForTab(newState, activeTab.id);
4847
- newState = handleViewletReady(newState, editorUid);
4966
+ newState = handleViewletReady(newState, editorUid, titles[activeTab.id]);
4848
4967
  }
4849
4968
  }
4850
4969
  return newState;
@@ -4887,6 +5006,37 @@ const loadContent = async (state, savedState) => {
4887
5006
  };
4888
5007
  };
4889
5008
 
5009
+ const handleWorkspaceChange = async (state, _workspacePath, savedState) => {
5010
+ return loadContent(state, savedState);
5011
+ };
5012
+
5013
+ const hasActiveTextEditor = state => {
5014
+ const activeTab = getActiveTab(state);
5015
+ return activeTab?.tab.editorInput?.type === 'editor';
5016
+ };
5017
+
5018
+ const id = 7201;
5019
+ const sendMessagePortToExtensionHostWorker = async port => {
5020
+ await sendMessagePortToExtensionHostWorker$1(port, id);
5021
+ };
5022
+
5023
+ const createExtensionHostRpc = async () => {
5024
+ try {
5025
+ const rpc = await create$8({
5026
+ commandMap: {},
5027
+ send: sendMessagePortToExtensionHostWorker
5028
+ });
5029
+ return rpc;
5030
+ } catch (error) {
5031
+ throw new VError(error, `Failed to create extension host rpc`);
5032
+ }
5033
+ };
5034
+
5035
+ const initialize = async () => {
5036
+ const rpc = await createExtensionHostRpc();
5037
+ set$3(rpc);
5038
+ };
5039
+
4890
5040
  const hasTargetGroup = groupId => {
4891
5041
  return groupId !== undefined && groupId >= 0;
4892
5042
  };
@@ -5260,26 +5410,26 @@ const newWindow = async state => {
5260
5410
  return state;
5261
5411
  };
5262
5412
 
5263
- const openUris = async (state, uris) => {
5413
+ const openUrisWithContext = async (context, uris) => {
5264
5414
  if (uris.length === 0) {
5265
- return state;
5415
+ return;
5266
5416
  }
5417
+ await openUriWithContext(context, uris[0]);
5267
5418
  if (uris.length === 1) {
5268
- return openUri(state, uris[0]);
5419
+ return;
5269
5420
  }
5270
- let currentState = await openUri(state, uris[0]);
5421
+ let currentState = context.getState();
5271
5422
  const firstTab = findTabByUri(currentState, uris[0]);
5272
5423
  for (const uri of uris.slice(1)) {
5273
5424
  const existingTab = findTabByUri(currentState, uri);
5274
- if (existingTab) {
5275
- continue;
5425
+ if (!existingTab) {
5426
+ currentState = ensureActiveGroup(currentState, uri);
5276
5427
  }
5277
- currentState = ensureActiveGroup(currentState, uri);
5278
5428
  }
5279
- if (!firstTab) {
5280
- return currentState;
5429
+ if (firstTab) {
5430
+ currentState = switchTab(currentState, firstTab.groupId, firstTab.tab.id);
5281
5431
  }
5282
- return switchTab(currentState, firstTab.groupId, firstTab.tab.id);
5432
+ await context.updateState(() => currentState);
5283
5433
  };
5284
5434
 
5285
5435
  const refresh = state => {
@@ -6652,99 +6802,99 @@ const splitUp = (state, groupId) => {
6652
6802
  };
6653
6803
 
6654
6804
  const commandMap = {
6655
- 'Main.closeActiveEditor': wrapCommand(closeActiveEditor),
6656
- 'Main.closeAll': wrapCommand(closeAll$1),
6657
- 'Main.closeAllEditors': wrapCommand(closeAll$1),
6658
- 'Main.closeFocusedTab': wrapCommand(closeFocusedTab),
6659
- 'Main.closeOthers': wrapCommand(closeOtherTabs),
6660
- 'Main.closeSaved': wrapCommand(closeSaved$1),
6661
- 'Main.closeTabsByUris': wrapCommand(closeTabsByUris),
6662
- 'Main.closeTabsRight': wrapCommand(closeTabsRight),
6663
- 'Main.copyPath': wrapCommand(copyPath$1),
6664
- 'Main.copyRelativePath': wrapCommand(copyRelativePath$1),
6665
- 'Main.focusNext': wrapCommand(focusNextTab),
6666
- 'Main.focusNextTab': wrapCommand(focusNextTab),
6667
- 'Main.focusPrevious': wrapCommand(focusPreviousTab),
6668
- 'Main.focusPreviousTab': wrapCommand(focusPreviousTab),
6669
- 'Main.handleModifiedStatusChange': wrapCommand(handleModifiedStatusChange),
6670
- 'Main.handleTabContextMenu': wrapCommand(handleTabContextMenu),
6805
+ 'Main.closeActiveEditor': wrapSerialCommand(closeActiveEditor),
6806
+ 'Main.closeAll': wrapSerialCommand(closeAll$1),
6807
+ 'Main.closeAllEditors': wrapSerialCommand(closeAll$1),
6808
+ 'Main.closeFocusedTab': wrapSerialCommand(closeFocusedTab),
6809
+ 'Main.closeOthers': wrapSerialCommand(closeOtherTabs),
6810
+ 'Main.closeSaved': wrapSerialCommand(closeSaved$1),
6811
+ 'Main.closeTabsByUris': wrapSerialCommand(closeTabsByUris),
6812
+ 'Main.closeTabsRight': wrapSerialCommand(closeTabsRight),
6813
+ 'Main.copyPath': wrapSerialCommand(copyPath$1),
6814
+ 'Main.copyRelativePath': wrapSerialCommand(copyRelativePath$1),
6815
+ 'Main.focusNext': wrapSerialCommand(focusNextTab),
6816
+ 'Main.focusNextTab': wrapSerialCommand(focusNextTab),
6817
+ 'Main.focusPrevious': wrapSerialCommand(focusPreviousTab),
6818
+ 'Main.focusPreviousTab': wrapSerialCommand(focusPreviousTab),
6819
+ 'Main.handleModifiedStatusChange': wrapAsyncCommand(handleModifiedStatusChangeWithContext),
6820
+ 'Main.handleTabContextMenu': wrapSerialCommand(handleTabContextMenu),
6671
6821
  'Main.hasActiveTextEditor': wrapGetter(hasActiveTextEditor),
6672
- 'Main.openInput': wrapCommand(openInput),
6673
- 'Main.openUri': wrapCommand(openUri),
6674
- 'Main.openUris': wrapCommand(openUris),
6675
- 'Main.restoreClosedTab': wrapCommand(restoreClosedTab),
6676
- 'Main.save': wrapCommand(save),
6822
+ 'Main.openInput': wrapSerialAsyncCommand(openInputWithContext),
6823
+ 'Main.openUri': wrapSerialAsyncCommand(openUriWithContext),
6824
+ 'Main.openUris': wrapSerialAsyncCommand(openUrisWithContext),
6825
+ 'Main.restoreClosedTab': wrapSerialCommand(restoreClosedTab),
6826
+ 'Main.save': wrapSerialCommand(save),
6677
6827
  'Main.saveState': wrapGetter(saveState),
6678
- 'Main.splitRight': wrapCommand(splitRight),
6679
- 'MainArea.closeActiveEditor': wrapCommand(closeActiveEditor),
6680
- 'MainArea.closeAll': wrapCommand(closeAll$1),
6681
- 'MainArea.closeAllEditors': wrapCommand(closeAll$1),
6682
- 'MainArea.closeEditorGroup': wrapCommand(closeEditorGroup$1),
6683
- 'MainArea.closeFocusedTab': wrapCommand(closeFocusedTab),
6684
- 'MainArea.closeOthers': wrapCommand(closeOtherTabs),
6685
- 'MainArea.closeSaved': wrapCommand(closeSaved$1),
6686
- 'MainArea.closeTabsByUris': wrapCommand(closeTabsByUris),
6687
- 'MainArea.closeTabsRight': wrapCommand(closeTabsRight),
6688
- 'MainArea.copyIntoNewWindow': wrapCommand(copyIntoNewWindow$1),
6689
- 'MainArea.copyPath': wrapCommand(copyPath$1),
6690
- 'MainArea.copyRelativePath': wrapCommand(copyRelativePath$1),
6828
+ 'Main.splitRight': wrapSerialCommand(splitRight),
6829
+ 'MainArea.closeActiveEditor': wrapSerialCommand(closeActiveEditor),
6830
+ 'MainArea.closeAll': wrapSerialCommand(closeAll$1),
6831
+ 'MainArea.closeAllEditors': wrapSerialCommand(closeAll$1),
6832
+ 'MainArea.closeEditorGroup': wrapSerialCommand(closeEditorGroup$1),
6833
+ 'MainArea.closeFocusedTab': wrapSerialCommand(closeFocusedTab),
6834
+ 'MainArea.closeOthers': wrapSerialCommand(closeOtherTabs),
6835
+ 'MainArea.closeSaved': wrapSerialCommand(closeSaved$1),
6836
+ 'MainArea.closeTabsByUris': wrapSerialCommand(closeTabsByUris),
6837
+ 'MainArea.closeTabsRight': wrapSerialCommand(closeTabsRight),
6838
+ 'MainArea.copyIntoNewWindow': wrapSerialCommand(copyIntoNewWindow$1),
6839
+ 'MainArea.copyPath': wrapSerialCommand(copyPath$1),
6840
+ 'MainArea.copyRelativePath': wrapSerialCommand(copyRelativePath$1),
6691
6841
  'MainArea.create': create$2,
6692
6842
  'MainArea.diff2': diff2,
6693
- 'MainArea.flipEditorLayout': wrapCommand(flipLayout),
6694
- 'MainArea.focusNext': wrapCommand(focusNextTab),
6695
- 'MainArea.focusNextTab': wrapCommand(focusNextTab),
6696
- 'MainArea.focusPrevious': wrapCommand(focusPreviousTab),
6697
- 'MainArea.focusPreviousTab': wrapCommand(focusPreviousTab),
6843
+ 'MainArea.flipEditorLayout': wrapSerialCommand(flipLayout),
6844
+ 'MainArea.focusNext': wrapSerialCommand(focusNextTab),
6845
+ 'MainArea.focusNextTab': wrapSerialCommand(focusNextTab),
6846
+ 'MainArea.focusPrevious': wrapSerialCommand(focusPreviousTab),
6847
+ 'MainArea.focusPreviousTab': wrapSerialCommand(focusPreviousTab),
6698
6848
  'MainArea.getCommandIds': getCommandIds,
6699
6849
  'MainArea.getMenuEntries': wrapGetter(getMenuEntries),
6700
6850
  'MainArea.getMenuIds': getMenuIds,
6701
- 'MainArea.handleClick': wrapCommand(handleClick),
6702
- 'MainArea.handleClickAction': wrapCommand(handleClickAction),
6703
- 'MainArea.handleClickCloseTab': wrapCommand(handleClickCloseTab),
6704
- 'MainArea.handleClickTab': wrapCommand(handleClickTab),
6705
- 'MainArea.handleClickTogglePreview': wrapCommand(handleClickTogglePreview),
6706
- 'MainArea.handleContextMenu': wrapCommand(handleContextMenu),
6707
- 'MainArea.handleDoubleClick': wrapCommand(handleDoubleClick),
6708
- 'MainArea.handleHeaderDoubleClick': wrapCommand(handleHeaderDoubleClick),
6709
- 'MainArea.handleIconThemeChange': wrapCommand(handleIconThemeChange),
6710
- 'MainArea.handleModifiedStatusChange': wrapCommand(handleModifiedStatusChange),
6851
+ 'MainArea.handleClick': wrapSerialCommand(handleClick),
6852
+ 'MainArea.handleClickAction': wrapSerialCommand(handleClickAction),
6853
+ 'MainArea.handleClickCloseTab': wrapSerialCommand(handleClickCloseTab),
6854
+ 'MainArea.handleClickTab': wrapSerialCommand(handleClickTab),
6855
+ 'MainArea.handleClickTogglePreview': wrapSerialCommand(handleClickTogglePreview),
6856
+ 'MainArea.handleContextMenu': wrapSerialCommand(handleContextMenu),
6857
+ 'MainArea.handleDoubleClick': wrapSerialCommand(handleDoubleClick),
6858
+ 'MainArea.handleHeaderDoubleClick': wrapSerialCommand(handleHeaderDoubleClick),
6859
+ 'MainArea.handleIconThemeChange': wrapSerialCommand(handleIconThemeChange),
6860
+ 'MainArea.handleModifiedStatusChange': wrapAsyncCommand(handleModifiedStatusChangeWithContext),
6711
6861
  'MainArea.handleResize': wrapGetter(handleResize),
6712
6862
  // TODO would need to have a function that returns newstate as well as commands
6713
- 'MainArea.handleSashPointerDown': wrapCommand(handleSashPointerDown),
6714
- 'MainArea.handleSashPointerMove': wrapCommand(handleSashPointerMove),
6715
- 'MainArea.handleSashPointerUp': wrapCommand(handleSashPointerUp),
6716
- 'MainArea.handleTabContextMenu': wrapCommand(handleTabContextMenu),
6717
- 'MainArea.handleUriChange': wrapCommand(handleUriChange),
6718
- 'MainArea.handleWorkspaceChange': wrapCommand(handleWorkspaceChange),
6863
+ 'MainArea.handleSashPointerDown': wrapSerialCommand(handleSashPointerDown),
6864
+ 'MainArea.handleSashPointerMove': wrapSerialCommand(handleSashPointerMove),
6865
+ 'MainArea.handleSashPointerUp': wrapSerialCommand(handleSashPointerUp),
6866
+ 'MainArea.handleTabContextMenu': wrapSerialCommand(handleTabContextMenu),
6867
+ 'MainArea.handleUriChange': wrapSerialCommand(handleUriChange),
6868
+ 'MainArea.handleWorkspaceChange': wrapSerialCommand(handleWorkspaceChange),
6719
6869
  'MainArea.hasActiveTextEditor': wrapGetter(hasActiveTextEditor),
6720
6870
  'MainArea.initialize': initialize,
6721
- 'MainArea.loadContent': wrapCommand(loadContent),
6722
- 'MainArea.moveIntoNewWindow': wrapCommand(moveIntoNewWindow),
6723
- 'MainArea.newFile': wrapCommand(newFile),
6724
- 'MainArea.newWindow': wrapCommand(newWindow),
6725
- 'MainArea.openInput': wrapCommand(openInput),
6726
- 'MainArea.openUri': wrapCommand(openUri),
6727
- 'MainArea.openUris': wrapCommand(openUris),
6728
- 'MainArea.refresh': wrapCommand(refresh),
6871
+ 'MainArea.loadContent': wrapSerialCommand(loadContent),
6872
+ 'MainArea.moveIntoNewWindow': wrapSerialCommand(moveIntoNewWindow),
6873
+ 'MainArea.newFile': wrapSerialCommand(newFile),
6874
+ 'MainArea.newWindow': wrapSerialCommand(newWindow),
6875
+ 'MainArea.openInput': wrapSerialAsyncCommand(openInputWithContext),
6876
+ 'MainArea.openUri': wrapSerialAsyncCommand(openUriWithContext),
6877
+ 'MainArea.openUris': wrapSerialAsyncCommand(openUrisWithContext),
6878
+ 'MainArea.refresh': wrapSerialCommand(refresh),
6729
6879
  'MainArea.render2': render2,
6730
6880
  'MainArea.renderEventListeners': renderEventListeners,
6731
6881
  'MainArea.resize': wrapGetter(handleResize),
6732
- 'MainArea.restoreClosedTab': wrapCommand(restoreClosedTab),
6733
- 'MainArea.save': wrapCommand(save),
6882
+ 'MainArea.restoreClosedTab': wrapSerialCommand(restoreClosedTab),
6883
+ 'MainArea.save': wrapSerialCommand(save),
6734
6884
  'MainArea.saveState': wrapGetter(saveState),
6735
- 'MainArea.selectTab': wrapCommand(selectTab),
6736
- 'MainArea.setEditorLayoutGrid': wrapCommand(setEditorLayoutGrid),
6737
- 'MainArea.setEditorLayoutSingle': wrapCommand(setEditorLayoutSingle),
6738
- 'MainArea.setEditorLayoutThreeColumns': wrapCommand(setEditorLayoutThreeColumns),
6739
- 'MainArea.setEditorLayoutThreeRows': wrapCommand(setEditorLayoutThreeRows),
6740
- 'MainArea.setEditorLayoutTwoColumns': wrapCommand(setEditorLayoutTwoColumns),
6741
- 'MainArea.setEditorLayoutTwoColumnsBottom': wrapCommand(setEditorLayoutTwoColumnsBottom),
6742
- 'MainArea.setEditorLayoutTwoRows': wrapCommand(setEditorLayoutTwoRows),
6743
- 'MainArea.setEditorLayoutTwoRowsRight': wrapCommand(setEditorLayoutTwoRowsRight),
6744
- 'MainArea.splitDown': wrapCommand(splitDown),
6745
- 'MainArea.splitLeft': wrapCommand(splitLeft),
6746
- 'MainArea.splitRight': wrapCommand(splitRight),
6747
- 'MainArea.splitUp': wrapCommand(splitUp),
6885
+ 'MainArea.selectTab': wrapSerialCommand(selectTab),
6886
+ 'MainArea.setEditorLayoutGrid': wrapSerialCommand(setEditorLayoutGrid),
6887
+ 'MainArea.setEditorLayoutSingle': wrapSerialCommand(setEditorLayoutSingle),
6888
+ 'MainArea.setEditorLayoutThreeColumns': wrapSerialCommand(setEditorLayoutThreeColumns),
6889
+ 'MainArea.setEditorLayoutThreeRows': wrapSerialCommand(setEditorLayoutThreeRows),
6890
+ 'MainArea.setEditorLayoutTwoColumns': wrapSerialCommand(setEditorLayoutTwoColumns),
6891
+ 'MainArea.setEditorLayoutTwoColumnsBottom': wrapSerialCommand(setEditorLayoutTwoColumnsBottom),
6892
+ 'MainArea.setEditorLayoutTwoRows': wrapSerialCommand(setEditorLayoutTwoRows),
6893
+ 'MainArea.setEditorLayoutTwoRowsRight': wrapSerialCommand(setEditorLayoutTwoRowsRight),
6894
+ 'MainArea.splitDown': wrapSerialCommand(splitDown),
6895
+ 'MainArea.splitLeft': wrapSerialCommand(splitLeft),
6896
+ 'MainArea.splitRight': wrapSerialCommand(splitRight),
6897
+ 'MainArea.splitUp': wrapSerialCommand(splitUp),
6748
6898
  'MainArea.terminate': terminate
6749
6899
  };
6750
6900
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.24.0",
3
+ "version": "9.27.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",