@lvce-editor/main-area-worker 3.1.0 → 4.0.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.
@@ -1832,6 +1832,11 @@ const initialize = async () => {
1832
1832
  set$1(rpc);
1833
1833
  };
1834
1834
 
1835
+ const createViewlet = async (viewletModuleId, editorUid, tabId, bounds, uri) => {
1836
+ // @ts-ignore
1837
+ await invoke('Layout.createViewlet', viewletModuleId, editorUid, tabId, bounds, uri);
1838
+ };
1839
+
1835
1840
  const getMaxIdFromLayout = layout => {
1836
1841
  let maxId = 0;
1837
1842
  for (const group of layout.groups) {
@@ -1847,6 +1852,18 @@ const getMaxIdFromLayout = layout => {
1847
1852
  return maxId;
1848
1853
  };
1849
1854
 
1855
+ const getViewletModuleId = async uri => {
1856
+ // Query RendererWorker for viewlet module ID (optional, may fail in tests)
1857
+ let viewletModuleId;
1858
+ try {
1859
+ // @ts-ignore
1860
+ viewletModuleId = await invoke('Layout.getModuleId', uri);
1861
+ } catch {
1862
+ // Viewlet creation is optional - silently ignore if RendererWorker isn't available
1863
+ }
1864
+ return viewletModuleId;
1865
+ };
1866
+
1850
1867
  const isValidTab = tab => {
1851
1868
  return tab && typeof tab.id === 'number' && typeof tab.title === 'string' && typeof tab.content === 'string' && typeof tab.isDirty === 'boolean' && (tab.editorType === 'text' || tab.editorType === 'custom') && (tab.editorType !== 'custom' || typeof tab.customEditorId === 'string');
1852
1869
  };
@@ -1896,10 +1913,66 @@ const loadContent = async (state, savedState) => {
1896
1913
  if (restoredLayout) {
1897
1914
  const maxId = getMaxIdFromLayout(restoredLayout);
1898
1915
  setMinId(maxId);
1899
- return {
1916
+ let newState = {
1900
1917
  ...state,
1901
1918
  layout: restoredLayout
1902
1919
  };
1920
+
1921
+ // Create viewlets only for active tabs in each group
1922
+ const TAB_HEIGHT = 35;
1923
+ const bounds = {
1924
+ height: newState.height - TAB_HEIGHT,
1925
+ width: newState.width,
1926
+ x: newState.x,
1927
+ y: newState.y + TAB_HEIGHT
1928
+ };
1929
+ for (const group of restoredLayout.groups) {
1930
+ // Find the active tab in this group
1931
+ const activeTab = group.tabs.find(tab => tab.id === group.activeTabId);
1932
+ if (activeTab && activeTab.uri) {
1933
+ const viewletModuleId = await getViewletModuleId(activeTab.uri);
1934
+ if (viewletModuleId) {
1935
+ // Ensure the tab has an editorUid
1936
+ const editorUid = activeTab.editorUid === -1 ? create() : activeTab.editorUid;
1937
+
1938
+ // Create viewlet for the tab
1939
+ newState = createViewletForTab(newState, activeTab.id);
1940
+
1941
+ // Update the tab with the editorUid in the state
1942
+ const updatedGroups = newState.layout.groups.map(g => {
1943
+ if (g.id !== group.id) {
1944
+ return g;
1945
+ }
1946
+ return {
1947
+ ...g,
1948
+ tabs: g.tabs.map(t => {
1949
+ if (t.id !== activeTab.id) {
1950
+ return t;
1951
+ }
1952
+ return {
1953
+ ...t,
1954
+ editorUid
1955
+ };
1956
+ })
1957
+ };
1958
+ });
1959
+ newState = {
1960
+ ...newState,
1961
+ layout: {
1962
+ ...newState.layout,
1963
+ groups: updatedGroups
1964
+ }
1965
+ };
1966
+
1967
+ // Create the actual viewlet instance
1968
+ await createViewlet(viewletModuleId, editorUid, activeTab.id, bounds, activeTab.uri);
1969
+
1970
+ // Mark the viewlet as ready
1971
+ newState = handleViewletReady(newState, editorUid);
1972
+ }
1973
+ }
1974
+ }
1975
+ return newState;
1903
1976
  }
1904
1977
  return {
1905
1978
  ...state,
@@ -2019,11 +2092,6 @@ const getMenuEntries = async (state, props) => {
2019
2092
  }
2020
2093
  };
2021
2094
 
2022
- const createViewlet = async (viewletModuleId, editorUid, tabId, bounds, uri) => {
2023
- // @ts-ignore
2024
- await invoke('Layout.createViewlet', viewletModuleId, editorUid, tabId, bounds, uri);
2025
- };
2026
-
2027
2095
  const getBasename = uri => {
2028
2096
  const lastSlashIndex = uri.lastIndexOf('/');
2029
2097
  if (lastSlashIndex === -1) {
@@ -2051,10 +2119,11 @@ const createEmptyGroup = (state, uri, requestId) => {
2051
2119
  const groupId = create();
2052
2120
  const title = getLabel(uri);
2053
2121
  const tabId = create();
2122
+ const editorUid = create();
2054
2123
  const newTab = {
2055
2124
  content: '',
2056
2125
  editorType: 'text',
2057
- editorUid: -1,
2126
+ editorUid,
2058
2127
  errorMessage: '',
2059
2128
  id: tabId,
2060
2129
  isDirty: false,
@@ -2130,10 +2199,11 @@ const ensureActiveGroup = (state, uri) => {
2130
2199
  // Create a new tab with the URI in the active group
2131
2200
  const title = getLabel(uri);
2132
2201
  const tabId = create();
2202
+ const editorUid = create();
2133
2203
  const newTab = {
2134
2204
  content: '',
2135
2205
  editorType: 'text',
2136
- editorUid: -1,
2206
+ editorUid,
2137
2207
  errorMessage: '',
2138
2208
  id: tabId,
2139
2209
  isDirty: false,
@@ -2233,18 +2303,6 @@ const getOptionUriOptions = options => {
2233
2303
  return uri;
2234
2304
  };
2235
2305
 
2236
- const getViewletModuleId = async uri => {
2237
- // Query RendererWorker for viewlet module ID (optional, may fail in tests)
2238
- let viewletModuleId;
2239
- try {
2240
- // @ts-ignore
2241
- viewletModuleId = await invoke('Layout.getModuleId', uri);
2242
- } catch {
2243
- // Viewlet creation is optional - silently ignore if RendererWorker isn't available
2244
- }
2245
- return viewletModuleId;
2246
- };
2247
-
2248
2306
  const switchTab = (state, groupId, tabId) => {
2249
2307
  const {
2250
2308
  layout
@@ -2586,7 +2644,7 @@ const commandMap = {
2586
2644
  'MainArea.render2': render2,
2587
2645
  'MainArea.renderEventListeners': renderEventListeners,
2588
2646
  'MainArea.resize': wrapCommand(resize),
2589
- 'MainArea.saveState': saveState,
2647
+ 'MainArea.saveState': wrapGetter(saveState),
2590
2648
  'MainArea.selectTab': wrapCommand(selectTab),
2591
2649
  'MainArea.terminate': terminate
2592
2650
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "3.1.0",
3
+ "version": "4.0.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",