@lvce-editor/main-area-worker 9.33.3 → 9.34.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.
@@ -2016,10 +2016,38 @@ const notifyActiveEditorChange = async (oldState, newState) => {
2016
2016
  }
2017
2017
  };
2018
2018
 
2019
+ const getMountedViewletUids = state => {
2020
+ const mountedViewletUids = [];
2021
+ for (const group of state.layout.groups) {
2022
+ const activeTab = group.tabs.find(tab => tab.id === group.activeTabId);
2023
+ if (activeTab?.loadingState === 'loaded' && activeTab.editorUid !== -1) {
2024
+ mountedViewletUids.push(activeTab.editorUid);
2025
+ }
2026
+ }
2027
+ return mountedViewletUids;
2028
+ };
2029
+
2030
+ const arraysEqual = (a, b) => {
2031
+ return a.length === b.length && a.every((value, index) => value === b[index]);
2032
+ };
2033
+ const notifyMountedViewlets = async (oldState, newState) => {
2034
+ const oldViewletUids = getMountedViewletUids(oldState);
2035
+ const newViewletUids = getMountedViewletUids(newState);
2036
+ if (oldState.uid === newState.uid && arraysEqual(oldViewletUids, newViewletUids)) {
2037
+ return;
2038
+ }
2039
+ try {
2040
+ await invoke('Layout.setMountedViewlets', newState.uid, newViewletUids);
2041
+ } catch (error) {
2042
+ console.warn('Failed to publish mounted viewlets', error);
2043
+ }
2044
+ };
2045
+
2019
2046
  const withActiveEditorChange = fn => {
2020
2047
  return async (state, ...args) => {
2021
2048
  const newState = await fn(state, ...args);
2022
2049
  await notifyActiveEditorChange(state, newState);
2050
+ await notifyMountedViewlets(state, newState);
2023
2051
  return newState;
2024
2052
  };
2025
2053
  };
@@ -2029,6 +2057,7 @@ const withActiveEditorChangeAsync = fn => {
2029
2057
  await fn(context, ...args);
2030
2058
  const newState = context.getState();
2031
2059
  await notifyActiveEditorChange(oldState, newState);
2060
+ await notifyMountedViewlets(oldState, newState);
2032
2061
  };
2033
2062
  };
2034
2063
 
@@ -4747,6 +4776,9 @@ const getSplitDirection = (x, y, width, height) => {
4747
4776
  return None;
4748
4777
  };
4749
4778
 
4779
+ const isNotEmpty = group => {
4780
+ return !group.isEmpty;
4781
+ };
4750
4782
  const getDragOverlay = (state, eventX, eventY) => {
4751
4783
  const {
4752
4784
  height,
@@ -4759,7 +4791,7 @@ const getDragOverlay = (state, eventX, eventY) => {
4759
4791
  const {
4760
4792
  groups
4761
4793
  } = layout;
4762
- const hasOpenEditor = groups.some(group => !group.isEmpty);
4794
+ const hasOpenEditor = groups.some(isNotEmpty);
4763
4795
  const contentY = hasOpenEditor ? tabHeight : 0;
4764
4796
  const contentHeight = Math.max(0, height - contentY);
4765
4797
  const relativeX = eventX - x;
@@ -4786,6 +4818,7 @@ const handleDragOver = (state, eventX, eventY) => {
4786
4818
  };
4787
4819
 
4788
4820
  const lineSeparatorRegex = /\r?\n/;
4821
+ const chromiumDragIdRegex = /^[A-F\d]{32}$/i;
4789
4822
  const isUriList = item => {
4790
4823
  if (!item || typeof item !== 'object') {
4791
4824
  return false;
@@ -4796,12 +4829,37 @@ const isUriList = item => {
4796
4829
  const parseUriList = value => {
4797
4830
  return value.split(lineSeparatorRegex).map(uri => uri.trim()).filter(uri => uri && !uri.startsWith('#'));
4798
4831
  };
4832
+ const isChromiumDragId = item => {
4833
+ if (!item || typeof item !== 'object') {
4834
+ return false;
4835
+ }
4836
+ const candidate = item;
4837
+ return candidate.kind === 'string' && (candidate.type === '' || candidate.type === 'chromium/x-drag-id') && typeof candidate.value === 'string' && chromiumDragIdRegex.test(candidate.value);
4838
+ };
4839
+ const isDragInfoItem = item => {
4840
+ if (!item || typeof item !== 'object') {
4841
+ return false;
4842
+ }
4843
+ const candidate = item;
4844
+ return candidate.type === 'text/uri-list' && typeof candidate.data === 'string';
4845
+ };
4846
+ const getUrisFromDragInfo = dragInfo => {
4847
+ if (!dragInfo || typeof dragInfo !== 'object' || !Array.isArray(dragInfo.items)) {
4848
+ return [];
4849
+ }
4850
+ return dragInfo.items.filter(isDragInfoItem).flatMap(item => parseUriList(item.data));
4851
+ };
4799
4852
  const getDroppedUris = async itemIds => {
4800
4853
  if (itemIds.length === 0) {
4801
4854
  return [];
4802
4855
  }
4803
4856
  const items = await getFileHandles(itemIds);
4804
- return items.filter(isUriList).flatMap(item => parseUriList(item.value));
4857
+ const uris = items.filter(isUriList).flatMap(item => parseUriList(item.value));
4858
+ if (uris.length > 0 || !items.some(isChromiumDragId)) {
4859
+ return uris;
4860
+ }
4861
+ const dragInfo = await invoke('Viewlet.getDragData');
4862
+ return getUrisFromDragInfo(dragInfo);
4805
4863
  };
4806
4864
 
4807
4865
  const openUrisWithContext = async (context, uris) => {
@@ -5067,6 +5125,13 @@ const handleModifiedStatusChangeWithContext = async (context, uri, newStatus) =>
5067
5125
  await context.updateState(state => handleModifiedStatusChange(state, uri, newStatus));
5068
5126
  };
5069
5127
 
5128
+ const resizeChild = async (editorUid, dimensions) => {
5129
+ try {
5130
+ return await invoke('Viewlet.resize', editorUid, dimensions);
5131
+ } catch {
5132
+ return [];
5133
+ }
5134
+ };
5070
5135
  const handleResize = async (state, dimensions) => {
5071
5136
  const {
5072
5137
  height,
@@ -5084,25 +5149,22 @@ const handleResize = async (state, dimensions) => {
5084
5149
  groups
5085
5150
  } = layout;
5086
5151
  const contentHeight = height - tabHeight;
5087
- const allResizeCommands = [];
5088
- for (const group of groups) {
5089
- for (const tab of group.tabs) {
5090
- if (tab.editorUid !== -1) {
5091
- try {
5092
- const resizeCommands = await invoke('Viewlet.resize', tab.editorUid, {
5093
- height: contentHeight,
5094
- width,
5095
- x,
5096
- y: y + tabHeight
5097
- });
5098
- allResizeCommands.push(...resizeCommands);
5099
- } catch {
5100
- // ignore
5101
- }
5102
- }
5152
+ const resizePromises = [];
5153
+ const tabs = groups.flatMap(group => group.tabs);
5154
+ for (const tab of tabs) {
5155
+ if (tab.editorUid === -1) {
5156
+ continue;
5103
5157
  }
5158
+ const resizePromise = resizeChild(tab.editorUid, {
5159
+ height: contentHeight,
5160
+ width,
5161
+ x,
5162
+ y: y + tabHeight
5163
+ });
5164
+ resizePromises.push(resizePromise);
5104
5165
  }
5105
- return allResizeCommands;
5166
+ const resizeCommands = await Promise.all(resizePromises);
5167
+ return resizeCommands.flat();
5106
5168
  };
5107
5169
 
5108
5170
  const offsetsMatch = (first, second) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.33.3",
3
+ "version": "9.34.1",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",