@lvce-editor/main-area-worker 9.67.10 → 9.68.1

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.
@@ -1926,7 +1926,15 @@ const wrapSerialCommand = fn => {
1926
1926
  const state$1 = {
1927
1927
  configured: false,
1928
1928
  lastId: -1,
1929
- nextId: 0
1929
+ nextId: 0,
1930
+ reservedIds: new Set()
1931
+ };
1932
+ const reserve = ids => {
1933
+ for (const id of ids) {
1934
+ if (id >= state$1.nextId && id <= state$1.lastId) {
1935
+ state$1.reservedIds.add(id);
1936
+ }
1937
+ }
1930
1938
  };
1931
1939
  const configure = (start, end) => {
1932
1940
  const {
@@ -1946,13 +1954,16 @@ const create$2 = () => {
1946
1954
  const {
1947
1955
  configured,
1948
1956
  lastId,
1949
- nextId
1957
+ reservedIds
1950
1958
  } = state$1;
1951
1959
  if (!configured) {
1952
1960
  // Compatibility with renderer versions that do not assign worker id ranges.
1953
1961
  return Math.random();
1954
1962
  }
1955
- if (nextId > lastId) {
1963
+ while (reservedIds.delete(state$1.nextId)) {
1964
+ state$1.nextId++;
1965
+ }
1966
+ if (state$1.nextId > lastId) {
1956
1967
  throw new Error('Component id range exhausted');
1957
1968
  }
1958
1969
  return state$1.nextId++;
@@ -2310,11 +2321,23 @@ const closeTabWithViewlet = async (state, groupId, tabId) => {
2310
2321
  return newState;
2311
2322
  };
2312
2323
 
2324
+ const legacyRenderers = new WeakSet();
2313
2325
  const saveEditor = async (editorUid, skipFormatting = false) => {
2314
- if (skipFormatting) {
2315
- return invoke$2('Editor.save', editorUid, true);
2326
+ const args = skipFormatting ? [editorUid, true] : [editorUid];
2327
+ const rpc = get$2(RendererWorker);
2328
+ if (legacyRenderers.has(rpc)) {
2329
+ return invoke$2('Editor.save', ...args);
2330
+ }
2331
+ try {
2332
+ return await invoke$2('Viewlet.save', ...args);
2333
+ } catch (error) {
2334
+ // Older renderers support only text editors. Never retry an actual save failure.
2335
+ if (!(error instanceof Error) || !['Command not found Viewlet.save', 'Command "Viewlet.save" not found (renderer worker)'].includes(error.message)) {
2336
+ throw error;
2337
+ }
2338
+ legacyRenderers.add(rpc);
2339
+ return invoke$2('Editor.save', ...args);
2316
2340
  }
2317
- return invoke$2('Editor.save', editorUid);
2318
2341
  };
2319
2342
 
2320
2343
  const promptLegacy = async (message, discardPrompt) => {
@@ -7852,6 +7875,9 @@ const updateTabs = (state, editorUids) => {
7852
7875
  };
7853
7876
 
7854
7877
  const restoreAndCreateEditors = async (state, restoredLayout) => {
7878
+ // Saved tab/group IDs can overlap the range assigned to a fresh renderer.
7879
+ // Reserve them before creating editors or opening any additional tabs.
7880
+ reserve(restoredLayout.groups.flatMap(group => [group.id, ...group.tabs.map(tab => tab.id)]));
7855
7881
  let newState = {
7856
7882
  ...state,
7857
7883
  layout: restoredLayout
@@ -8850,6 +8876,23 @@ const save = async state => {
8850
8876
  const saveWithoutFormatting = async state => {
8851
8877
  return saveInternal(state, true);
8852
8878
  };
8879
+ const saveAll = async context => {
8880
+ const initialState = context.getState();
8881
+ const tabs = initialState.layout.groups.flatMap(group => group.tabs).filter(tab => tab.isDirty && tab.loadingState !== 'loading');
8882
+ for (const tab of tabs) {
8883
+ const current = context.getState().layout.groups.flatMap(group => group.tabs).find(item => item.id === tab.id);
8884
+ if (!current?.isDirty || current.editorUid !== tab.editorUid) {
8885
+ continue;
8886
+ }
8887
+ const result = await saveEditorAndHandleSettingsChange(current, initialState.applicationId);
8888
+ if (result?.modified) {
8889
+ continue;
8890
+ }
8891
+ await context.updateState(state => updateTab(state, tab.id, {
8892
+ isDirty: false
8893
+ }));
8894
+ }
8895
+ };
8853
8896
 
8854
8897
  const getSavedTab = tab => {
8855
8898
  const normalizedTab = normalizeTabEditorInput(tab);
@@ -9206,6 +9249,7 @@ const commandMap = {
9206
9249
  'Main.openUris': wrapSerialAsyncCommand(openUrisWithContext),
9207
9250
  'Main.restoreClosedTab': wrapSerialCommand(restoreClosedTab),
9208
9251
  'Main.save': wrapSerialCommand(save),
9252
+ 'Main.saveAll': wrapAsyncCommand(saveAll),
9209
9253
  'Main.saveState': wrapGetter(saveState),
9210
9254
  'Main.splitRight': splitRightAndResize,
9211
9255
  'MainArea.closeActiveEditor': wrapSerialCommand(closeActiveEditor),
@@ -9287,6 +9331,7 @@ const commandMap = {
9287
9331
  'MainArea.resize': resize,
9288
9332
  'MainArea.restoreClosedTab': wrapSerialCommand(restoreClosedTab),
9289
9333
  'MainArea.save': wrapSerialCommand(save),
9334
+ 'MainArea.saveAll': wrapAsyncCommand(saveAll),
9290
9335
  'MainArea.saveState': wrapGetter(saveState),
9291
9336
  'MainArea.saveWithoutFormatting': wrapSerialCommand(saveWithoutFormatting),
9292
9337
  'MainArea.selectTab': wrapSerialCommand(selectTab),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.67.10",
3
+ "version": "9.68.1",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",