@lvce-editor/main-area-worker 9.30.0 → 9.30.2

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.
@@ -1739,6 +1739,8 @@ const SetCss = 'Viewlet.setCss';
1739
1739
  const SetDom2 = 'Viewlet.setDom2';
1740
1740
  const SetPatches = 'Viewlet.setPatches';
1741
1741
 
1742
+ const FocusEditorText = 12;
1743
+
1742
1744
  const {
1743
1745
  set: set$4
1744
1746
  } = create$3(ClipBoardWorker);
@@ -1786,6 +1788,10 @@ const sendMessagePortToExtensionHostWorker$1 = async (port, rpcId = 0) => {
1786
1788
  const command = 'HandleMessagePort.handleMessagePort2';
1787
1789
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1788
1790
  };
1791
+ const confirm = async (message, options) => {
1792
+ const result = await invoke('ConfirmPrompt.prompt', message, options);
1793
+ return result;
1794
+ };
1789
1795
  const writeClipBoardText = async text => {
1790
1796
  await invoke('ClipBoard.writeText', /* text */text);
1791
1797
  };
@@ -2231,18 +2237,25 @@ const closeTabWithViewlet = async (state, groupId, tabId) => {
2231
2237
  const newState = closeTab(state, groupId, tabId);
2232
2238
  const group = state.layout.groups.find(g => g.id === groupId);
2233
2239
  const wasActiveTab = group?.activeTabId === tabId;
2234
- if (wasActiveTab) {
2235
- const newGroup = newState.layout.groups.find(g => g.id === groupId);
2236
- const newActiveTabId = newGroup?.activeTabId;
2237
- if (newActiveTabId !== undefined) {
2238
- const {
2239
- commands: switchCommands,
2240
- newState: switchedState
2241
- } = switchViewlet(newState);
2242
- commands.push(...switchCommands);
2243
- await executeViewletCommands(commands);
2244
- return switchedState;
2240
+ const newGroup = wasActiveTab ? newState.layout.groups.find(candidate => candidate.id === groupId) : undefined;
2241
+ const newActiveTabId = newGroup?.activeTabId;
2242
+ if (wasActiveTab && commands.length > 0) {
2243
+ if (newActiveTabId === undefined) {
2244
+ return {
2245
+ ...newState,
2246
+ pendingViewletUpdate: {
2247
+ disposal: tab.editorUid
2248
+ }
2249
+ };
2245
2250
  }
2251
+ const newActiveTab = newGroup?.tabs.find(candidate => candidate.id === newActiveTabId);
2252
+ return {
2253
+ ...newState,
2254
+ pendingViewletUpdate: {
2255
+ disposal: tab.editorUid,
2256
+ focus: newActiveTab?.editorUid === -1 ? undefined : newActiveTab?.editorUid
2257
+ }
2258
+ };
2246
2259
  }
2247
2260
  if (commands.length > 0) {
2248
2261
  await executeViewletCommands(commands);
@@ -2254,24 +2267,45 @@ const saveEditor = async editorUid => {
2254
2267
  return invoke('Editor.save', editorUid);
2255
2268
  };
2256
2269
 
2270
+ const promptSave = async title => {
2271
+ const shouldSave = await confirm(`Do you want to save the changes you made to ${title}?`, {
2272
+ cancelMessage: 'More Options',
2273
+ confirmMessage: 'Save',
2274
+ title: 'Save Changes'
2275
+ });
2276
+ if (shouldSave) {
2277
+ return 'save';
2278
+ }
2279
+ const shouldDiscard = await confirm(`Discard the changes you made to ${title}?`, {
2280
+ cancelMessage: 'Cancel',
2281
+ confirmMessage: "Don't Save",
2282
+ title: 'Save Changes'
2283
+ });
2284
+ return shouldDiscard ? 'discard' : 'cancel';
2285
+ };
2257
2286
  const closeTabAndSave = async (state, groupId, tabId) => {
2258
2287
  const tab = findTabInState(state, groupId, tabId);
2259
2288
  if (!tab) {
2260
2289
  return state;
2261
2290
  }
2262
2291
  if (tab.editorUid !== -1 && tab.isDirty) {
2263
- const editorState = await saveEditor(tab.editorUid);
2264
- if (editorState?.modified !== false) {
2292
+ const savePromptResult = await promptSave(tab.title);
2293
+ if (savePromptResult === 'cancel') {
2265
2294
  return state;
2266
2295
  }
2267
- if (tab.uri) {
2268
- await handleModifiedStatusChange$1(tab.uri, false);
2296
+ if (savePromptResult === 'save') {
2297
+ const editorState = await saveEditor(tab.editorUid);
2298
+ if (editorState?.modified !== false) {
2299
+ return state;
2300
+ }
2301
+ if (tab.uri) {
2302
+ await handleModifiedStatusChange$1(tab.uri, false);
2303
+ }
2304
+ } else if (savePromptResult !== 'discard') {
2305
+ return state;
2269
2306
  }
2270
2307
  }
2271
- if (tab.uri?.startsWith('simple-browser://')) {
2272
- return closeTabWithViewlet(state, groupId, tabId);
2273
- }
2274
- return closeTab(state, groupId, tabId);
2308
+ return closeTabWithViewlet(state, groupId, tabId);
2275
2309
  };
2276
2310
 
2277
2311
  const getFocusedGroup = state => {
@@ -2649,9 +2683,13 @@ const isEqual = (oldState, newState) => {
2649
2683
  const RenderItems = 4;
2650
2684
  const RenderCss = 10;
2651
2685
  const RenderIncremental = 11;
2686
+ const RenderPendingViewletUpdate = 12;
2652
2687
 
2653
- const modules = [isEqual, isEqual$1];
2654
- const numbers = [RenderIncremental, RenderCss];
2688
+ const isPendingViewletUpdateEqual = (oldState, newState) => {
2689
+ return newState.pendingViewletUpdate === undefined;
2690
+ };
2691
+ const modules = [isEqual, isEqual$1, isPendingViewletUpdateEqual];
2692
+ const numbers = [RenderIncremental, RenderCss, RenderPendingViewletUpdate];
2655
2693
 
2656
2694
  const diff = (oldState, newState) => {
2657
2695
  const diffResult = [];
@@ -6494,6 +6532,15 @@ const renderIncremental = (oldState, newState) => {
6494
6532
  return [SetPatches, newState.uid, patches];
6495
6533
  };
6496
6534
 
6535
+ const renderPendingViewletUpdate = (oldState, newState) => {
6536
+ const update = newState.pendingViewletUpdate;
6537
+ newState.pendingViewletUpdate = undefined;
6538
+ setTimeout(() => {
6539
+ void invoke('Viewlet.dispose', update.disposal).catch(() => {});
6540
+ }, 50);
6541
+ return update.focus === undefined ? [] : ['Viewlet.setFocusContext', update.focus, FocusEditorText, 0, update.focus, 'Editor'];
6542
+ };
6543
+
6497
6544
  const getRenderer = diffType => {
6498
6545
  switch (diffType) {
6499
6546
  case RenderCss:
@@ -6502,6 +6549,8 @@ const getRenderer = diffType => {
6502
6549
  return renderIncremental;
6503
6550
  case RenderItems:
6504
6551
  return renderItems;
6552
+ case RenderPendingViewletUpdate:
6553
+ return renderPendingViewletUpdate;
6505
6554
  default:
6506
6555
  throw new Error('unknown renderer');
6507
6556
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.30.0",
3
+ "version": "9.30.2",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",