@lvce-editor/main-area-worker 6.3.0 → 6.4.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.
@@ -2129,83 +2129,6 @@ const handleTabContextMenu = async (state, x, y) => {
2129
2129
  return state;
2130
2130
  };
2131
2131
 
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
2132
  const getIconsCached = (dirents, fileIconCache) => {
2210
2133
  return dirents.map(dirent => fileIconCache[dirent]);
2211
2134
  };
@@ -2332,6 +2255,140 @@ const loadFileIcons = async state => {
2332
2255
  }
2333
2256
  };
2334
2257
 
2258
+ const getBasename = uri => {
2259
+ const lastSlashIndex = uri.lastIndexOf('/');
2260
+ if (lastSlashIndex === -1) {
2261
+ return uri;
2262
+ }
2263
+ return uri.slice(lastSlashIndex + 1);
2264
+ };
2265
+ const getLabel = uri => {
2266
+ if (uri.startsWith('settings://')) {
2267
+ return 'Settings';
2268
+ }
2269
+ if (uri.startsWith('simple-browser://')) {
2270
+ return 'Simple Browser';
2271
+ }
2272
+ return getBasename(uri);
2273
+ };
2274
+
2275
+ const handleUriChange = async (state, oldUri, newUri) => {
2276
+ const {
2277
+ layout
2278
+ } = state;
2279
+ const {
2280
+ groups
2281
+ } = layout;
2282
+ const newTitle = getLabel(newUri);
2283
+ const updatedGroups = groups.map(group => {
2284
+ return {
2285
+ ...group,
2286
+ tabs: group.tabs.map(tab => {
2287
+ if (tab.uri === oldUri) {
2288
+ return {
2289
+ ...tab,
2290
+ title: newTitle,
2291
+ uri: newUri
2292
+ };
2293
+ }
2294
+ return tab;
2295
+ })
2296
+ };
2297
+ });
2298
+ const stateWithUpdatedUri = {
2299
+ ...state,
2300
+ layout: {
2301
+ ...layout,
2302
+ groups: updatedGroups
2303
+ }
2304
+ };
2305
+
2306
+ // Load icons for the new URI
2307
+ const result = await loadFileIcons(stateWithUpdatedUri);
2308
+ return {
2309
+ ...stateWithUpdatedUri,
2310
+ fileIconCache: result.fileIconCache,
2311
+ layout: result.updatedLayout
2312
+ };
2313
+ };
2314
+
2315
+ const handleWorkspaceChange = state => {
2316
+ return {
2317
+ ...state,
2318
+ layout: {
2319
+ ...state.layout,
2320
+ activeGroupId: undefined,
2321
+ groups: []
2322
+ }
2323
+ };
2324
+ };
2325
+
2326
+ const id = 7201;
2327
+ const sendMessagePortToExtensionHostWorker = async port => {
2328
+ await sendMessagePortToExtensionHostWorker$1(port, id);
2329
+ };
2330
+
2331
+ const createExtensionHostRpc = async () => {
2332
+ try {
2333
+ const rpc = await TransferMessagePortRpcParent.create({
2334
+ commandMap: {},
2335
+ send: sendMessagePortToExtensionHostWorker
2336
+ });
2337
+ return rpc;
2338
+ } catch (error) {
2339
+ throw new VError(error, `Failed to create extension host rpc`);
2340
+ }
2341
+ };
2342
+
2343
+ const initialize = async () => {
2344
+ const rpc = await createExtensionHostRpc();
2345
+ set$3(rpc);
2346
+ };
2347
+
2348
+ const isValidTab = tab => {
2349
+ 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');
2350
+ };
2351
+
2352
+ const isValidEditorGroup = group => {
2353
+ 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';
2354
+ };
2355
+
2356
+ const isValidMainAreaLayout = layout => {
2357
+ if (!layout || typeof layout !== 'object') {
2358
+ return false;
2359
+ }
2360
+ const layoutObj = layout;
2361
+ if (layoutObj.activeGroupId !== undefined && typeof layoutObj.activeGroupId !== 'number') {
2362
+ return false;
2363
+ }
2364
+ if (layoutObj.direction !== 'horizontal' && layoutObj.direction !== 'vertical') {
2365
+ return false;
2366
+ }
2367
+ if (!Array.isArray(layoutObj.groups)) {
2368
+ return false;
2369
+ }
2370
+ if (!layoutObj.groups.every(isValidEditorGroup)) {
2371
+ return false;
2372
+ }
2373
+ return true;
2374
+ };
2375
+
2376
+ const tryRestoreLayout = savedState => {
2377
+ if (savedState === undefined || savedState === null) {
2378
+ return undefined;
2379
+ }
2380
+ if (typeof savedState !== 'object') {
2381
+ return undefined;
2382
+ }
2383
+ const {
2384
+ layout
2385
+ } = savedState;
2386
+ if (!isValidMainAreaLayout(layout)) {
2387
+ return undefined;
2388
+ }
2389
+ return layout;
2390
+ };
2391
+
2335
2392
  const createViewlets = async (layout, viewletModuleIds, bounds) => {
2336
2393
  const editorUids = {};
2337
2394
  for (const group of layout.groups) {
@@ -2583,23 +2640,6 @@ const getMenuEntries = async (state, props) => {
2583
2640
  }
2584
2641
  };
2585
2642
 
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
2643
  const createEmptyGroup = (state, uri, requestId) => {
2604
2644
  const {
2605
2645
  layout
@@ -2747,7 +2787,8 @@ const newFile = async state => {
2747
2787
  isDirty: false,
2748
2788
  language: 'plaintext',
2749
2789
  loadingState: 'loading',
2750
- title: 'Untitled'
2790
+ title: 'Untitled',
2791
+ uri: 'untitled:///1'
2751
2792
  };
2752
2793
  const stateWithNewTab = openTab(newState, targetGroupId, newTab);
2753
2794
 
@@ -2779,7 +2820,7 @@ const newFile = async state => {
2779
2820
  if (actualEditorUid === -1) {
2780
2821
  throw new Error(`invalid editorUid`);
2781
2822
  }
2782
- await createViewlet('Editor', actualEditorUid, tabId, bounds, 'untitled:///1');
2823
+ await createViewlet('Editor', actualEditorUid, tabId, bounds, newTab.uri || '');
2783
2824
 
2784
2825
  // After viewlet is created, get the latest state and mark it as ready
2785
2826
  const {
@@ -3716,6 +3757,7 @@ const commandMap = {
3716
3757
  'MainArea.handleDoubleClick': wrapCommand(handleDoubleClick),
3717
3758
  'MainArea.handleResize': wrapCommand(handleResize),
3718
3759
  'MainArea.handleTabContextMenu': wrapCommand(handleTabContextMenu),
3760
+ 'MainArea.handleUriChange': wrapCommand(handleUriChange),
3719
3761
  'MainArea.handleWorkspaceChange': wrapCommand(handleWorkspaceChange),
3720
3762
  'MainArea.initialize': initialize,
3721
3763
  '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.4.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",