@lvce-editor/main-area-worker 6.3.0 → 6.5.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.
@@ -87,17 +87,6 @@ const terminate = () => {
87
87
  globalThis.close();
88
88
  };
89
89
 
90
- const closeAll$1 = state => {
91
- return {
92
- ...state,
93
- layout: {
94
- ...state.layout,
95
- activeGroupId: undefined,
96
- groups: []
97
- }
98
- };
99
- };
100
-
101
90
  const Button$1 = 1;
102
91
  const Div = 4;
103
92
  const Span = 8;
@@ -1628,6 +1617,37 @@ const closeTab = (state, groupId, tabId) => {
1628
1617
  };
1629
1618
  };
1630
1619
 
1620
+ const closeActiveEditor = state => {
1621
+ const {
1622
+ layout
1623
+ } = state;
1624
+ const {
1625
+ groups
1626
+ } = layout;
1627
+ const focusedGroup = groups.find(group => group.focused);
1628
+ if (!focusedGroup) {
1629
+ return state;
1630
+ }
1631
+ const {
1632
+ activeTabId
1633
+ } = focusedGroup;
1634
+ if (activeTabId === undefined) {
1635
+ return state;
1636
+ }
1637
+ return closeTab(state, focusedGroup.id, activeTabId);
1638
+ };
1639
+
1640
+ const closeAll$1 = state => {
1641
+ return {
1642
+ ...state,
1643
+ layout: {
1644
+ ...state.layout,
1645
+ activeGroupId: undefined,
1646
+ groups: []
1647
+ }
1648
+ };
1649
+ };
1650
+
1631
1651
  const closeFocusedTab = state => {
1632
1652
  const {
1633
1653
  layout
@@ -2129,83 +2149,6 @@ const handleTabContextMenu = async (state, x, y) => {
2129
2149
  return state;
2130
2150
  };
2131
2151
 
2132
- const handleWorkspaceChange = state => {
2133
- return {
2134
- ...state,
2135
- layout: {
2136
- ...state.layout,
2137
- activeGroupId: undefined,
2138
- groups: []
2139
- }
2140
- };
2141
- };
2142
-
2143
- const id = 7201;
2144
- const sendMessagePortToExtensionHostWorker = async port => {
2145
- await sendMessagePortToExtensionHostWorker$1(port, id);
2146
- };
2147
-
2148
- const createExtensionHostRpc = async () => {
2149
- try {
2150
- const rpc = await TransferMessagePortRpcParent.create({
2151
- commandMap: {},
2152
- send: sendMessagePortToExtensionHostWorker
2153
- });
2154
- return rpc;
2155
- } catch (error) {
2156
- throw new VError(error, `Failed to create extension host rpc`);
2157
- }
2158
- };
2159
-
2160
- const initialize = async () => {
2161
- const rpc = await createExtensionHostRpc();
2162
- set$3(rpc);
2163
- };
2164
-
2165
- const isValidTab = tab => {
2166
- return tab && typeof tab.id === 'number' && typeof tab.title === 'string' && typeof tab.isDirty === 'boolean' && typeof tab.editorUid === 'number' && typeof tab.icon === 'string' && (tab.editorType === 'text' || tab.editorType === 'custom');
2167
- };
2168
-
2169
- const isValidEditorGroup = group => {
2170
- return group && typeof group.id === 'number' && Array.isArray(group.tabs) && group.tabs.every(isValidTab) && (group.activeTabId === undefined || typeof group.activeTabId === 'number') && typeof group.focused === 'boolean' && typeof group.size === 'number' && group.size > 0 && typeof group.isEmpty === 'boolean';
2171
- };
2172
-
2173
- const isValidMainAreaLayout = layout => {
2174
- if (!layout || typeof layout !== 'object') {
2175
- return false;
2176
- }
2177
- const layoutObj = layout;
2178
- if (layoutObj.activeGroupId !== undefined && typeof layoutObj.activeGroupId !== 'number') {
2179
- return false;
2180
- }
2181
- if (layoutObj.direction !== 'horizontal' && layoutObj.direction !== 'vertical') {
2182
- return false;
2183
- }
2184
- if (!Array.isArray(layoutObj.groups)) {
2185
- return false;
2186
- }
2187
- if (!layoutObj.groups.every(isValidEditorGroup)) {
2188
- return false;
2189
- }
2190
- return true;
2191
- };
2192
-
2193
- const tryRestoreLayout = savedState => {
2194
- if (savedState === undefined || savedState === null) {
2195
- return undefined;
2196
- }
2197
- if (typeof savedState !== 'object') {
2198
- return undefined;
2199
- }
2200
- const {
2201
- layout
2202
- } = savedState;
2203
- if (!isValidMainAreaLayout(layout)) {
2204
- return undefined;
2205
- }
2206
- return layout;
2207
- };
2208
-
2209
2152
  const getIconsCached = (dirents, fileIconCache) => {
2210
2153
  return dirents.map(dirent => fileIconCache[dirent]);
2211
2154
  };
@@ -2332,6 +2275,140 @@ const loadFileIcons = async state => {
2332
2275
  }
2333
2276
  };
2334
2277
 
2278
+ const getBasename = uri => {
2279
+ const lastSlashIndex = uri.lastIndexOf('/');
2280
+ if (lastSlashIndex === -1) {
2281
+ return uri;
2282
+ }
2283
+ return uri.slice(lastSlashIndex + 1);
2284
+ };
2285
+ const getLabel = uri => {
2286
+ if (uri.startsWith('settings://')) {
2287
+ return 'Settings';
2288
+ }
2289
+ if (uri.startsWith('simple-browser://')) {
2290
+ return 'Simple Browser';
2291
+ }
2292
+ return getBasename(uri);
2293
+ };
2294
+
2295
+ const handleUriChange = async (state, oldUri, newUri) => {
2296
+ const {
2297
+ layout
2298
+ } = state;
2299
+ const {
2300
+ groups
2301
+ } = layout;
2302
+ const newTitle = getLabel(newUri);
2303
+ const updatedGroups = groups.map(group => {
2304
+ return {
2305
+ ...group,
2306
+ tabs: group.tabs.map(tab => {
2307
+ if (tab.uri === oldUri) {
2308
+ return {
2309
+ ...tab,
2310
+ title: newTitle,
2311
+ uri: newUri
2312
+ };
2313
+ }
2314
+ return tab;
2315
+ })
2316
+ };
2317
+ });
2318
+ const stateWithUpdatedUri = {
2319
+ ...state,
2320
+ layout: {
2321
+ ...layout,
2322
+ groups: updatedGroups
2323
+ }
2324
+ };
2325
+
2326
+ // Load icons for the new URI
2327
+ const result = await loadFileIcons(stateWithUpdatedUri);
2328
+ return {
2329
+ ...stateWithUpdatedUri,
2330
+ fileIconCache: result.fileIconCache,
2331
+ layout: result.updatedLayout
2332
+ };
2333
+ };
2334
+
2335
+ const handleWorkspaceChange = state => {
2336
+ return {
2337
+ ...state,
2338
+ layout: {
2339
+ ...state.layout,
2340
+ activeGroupId: undefined,
2341
+ groups: []
2342
+ }
2343
+ };
2344
+ };
2345
+
2346
+ const id = 7201;
2347
+ const sendMessagePortToExtensionHostWorker = async port => {
2348
+ await sendMessagePortToExtensionHostWorker$1(port, id);
2349
+ };
2350
+
2351
+ const createExtensionHostRpc = async () => {
2352
+ try {
2353
+ const rpc = await TransferMessagePortRpcParent.create({
2354
+ commandMap: {},
2355
+ send: sendMessagePortToExtensionHostWorker
2356
+ });
2357
+ return rpc;
2358
+ } catch (error) {
2359
+ throw new VError(error, `Failed to create extension host rpc`);
2360
+ }
2361
+ };
2362
+
2363
+ const initialize = async () => {
2364
+ const rpc = await createExtensionHostRpc();
2365
+ set$3(rpc);
2366
+ };
2367
+
2368
+ const isValidTab = tab => {
2369
+ return tab && typeof tab.id === 'number' && typeof tab.title === 'string' && typeof tab.isDirty === 'boolean' && typeof tab.editorUid === 'number' && typeof tab.icon === 'string' && (tab.editorType === 'text' || tab.editorType === 'custom');
2370
+ };
2371
+
2372
+ const isValidEditorGroup = group => {
2373
+ return group && typeof group.id === 'number' && Array.isArray(group.tabs) && group.tabs.every(isValidTab) && (group.activeTabId === undefined || typeof group.activeTabId === 'number') && typeof group.focused === 'boolean' && typeof group.size === 'number' && group.size > 0 && typeof group.isEmpty === 'boolean';
2374
+ };
2375
+
2376
+ const isValidMainAreaLayout = layout => {
2377
+ if (!layout || typeof layout !== 'object') {
2378
+ return false;
2379
+ }
2380
+ const layoutObj = layout;
2381
+ if (layoutObj.activeGroupId !== undefined && typeof layoutObj.activeGroupId !== 'number') {
2382
+ return false;
2383
+ }
2384
+ if (layoutObj.direction !== 'horizontal' && layoutObj.direction !== 'vertical') {
2385
+ return false;
2386
+ }
2387
+ if (!Array.isArray(layoutObj.groups)) {
2388
+ return false;
2389
+ }
2390
+ if (!layoutObj.groups.every(isValidEditorGroup)) {
2391
+ return false;
2392
+ }
2393
+ return true;
2394
+ };
2395
+
2396
+ const tryRestoreLayout = savedState => {
2397
+ if (savedState === undefined || savedState === null) {
2398
+ return undefined;
2399
+ }
2400
+ if (typeof savedState !== 'object') {
2401
+ return undefined;
2402
+ }
2403
+ const {
2404
+ layout
2405
+ } = savedState;
2406
+ if (!isValidMainAreaLayout(layout)) {
2407
+ return undefined;
2408
+ }
2409
+ return layout;
2410
+ };
2411
+
2335
2412
  const createViewlets = async (layout, viewletModuleIds, bounds) => {
2336
2413
  const editorUids = {};
2337
2414
  for (const group of layout.groups) {
@@ -2583,23 +2660,6 @@ const getMenuEntries = async (state, props) => {
2583
2660
  }
2584
2661
  };
2585
2662
 
2586
- const getBasename = uri => {
2587
- const lastSlashIndex = uri.lastIndexOf('/');
2588
- if (lastSlashIndex === -1) {
2589
- return uri;
2590
- }
2591
- return uri.slice(lastSlashIndex + 1);
2592
- };
2593
- const getLabel = uri => {
2594
- if (uri.startsWith('settings://')) {
2595
- return 'Settings';
2596
- }
2597
- if (uri.startsWith('simple-browser://')) {
2598
- return 'Simple Browser';
2599
- }
2600
- return getBasename(uri);
2601
- };
2602
-
2603
2663
  const createEmptyGroup = (state, uri, requestId) => {
2604
2664
  const {
2605
2665
  layout
@@ -2747,7 +2807,8 @@ const newFile = async state => {
2747
2807
  isDirty: false,
2748
2808
  language: 'plaintext',
2749
2809
  loadingState: 'loading',
2750
- title: 'Untitled'
2810
+ title: 'Untitled',
2811
+ uri: 'untitled:///1'
2751
2812
  };
2752
2813
  const stateWithNewTab = openTab(newState, targetGroupId, newTab);
2753
2814
 
@@ -2779,7 +2840,7 @@ const newFile = async state => {
2779
2840
  if (actualEditorUid === -1) {
2780
2841
  throw new Error(`invalid editorUid`);
2781
2842
  }
2782
- await createViewlet('Editor', actualEditorUid, tabId, bounds, 'untitled:///1');
2843
+ await createViewlet('Editor', actualEditorUid, tabId, bounds, newTab.uri || '');
2783
2844
 
2784
2845
  // After viewlet is created, get the latest state and mark it as ready
2785
2846
  const {
@@ -3702,6 +3763,7 @@ const splitRight = (state, groupId) => {
3702
3763
  };
3703
3764
 
3704
3765
  const commandMap = {
3766
+ 'MainArea.closeActiveEditor': wrapCommand(closeActiveEditor),
3705
3767
  'MainArea.closeAll': wrapCommand(closeAll$1),
3706
3768
  'MainArea.closeFocusedTab': wrapCommand(closeFocusedTab),
3707
3769
  'MainArea.create': create,
@@ -3716,6 +3778,7 @@ const commandMap = {
3716
3778
  'MainArea.handleDoubleClick': wrapCommand(handleDoubleClick),
3717
3779
  'MainArea.handleResize': wrapCommand(handleResize),
3718
3780
  'MainArea.handleTabContextMenu': wrapCommand(handleTabContextMenu),
3781
+ 'MainArea.handleUriChange': wrapCommand(handleUriChange),
3719
3782
  'MainArea.handleWorkspaceChange': wrapCommand(handleWorkspaceChange),
3720
3783
  'MainArea.initialize': initialize,
3721
3784
  'MainArea.loadContent': wrapCommand(loadContent),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "6.3.0",
3
+ "version": "6.5.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",