@lvce-editor/main-area-worker 5.2.0 → 5.3.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.
@@ -2,7 +2,7 @@ const toCommandId = key => {
2
2
  const dotIndex = key.indexOf('.');
3
3
  return key.slice(dotIndex + 1);
4
4
  };
5
- const create$7 = () => {
5
+ const create$6 = () => {
6
6
  const states = Object.create(null);
7
7
  const commandMapRef = {};
8
8
  return {
@@ -98,87 +98,6 @@ const closeAll$1 = state => {
98
98
  };
99
99
  };
100
100
 
101
- const {
102
- get: get$2,
103
- getCommandIds,
104
- registerCommands,
105
- set: set$4,
106
- wrapCommand,
107
- wrapGetter
108
- } = create$7();
109
-
110
- const create$6 = (uid, uri, x, y, width, height, platform, assetDir, tabHeight = 35) => {
111
- const state = {
112
- assetDir,
113
- fileIconCache: {},
114
- height,
115
- layout: {
116
- activeGroupId: undefined,
117
- direction: 'horizontal',
118
- groups: []
119
- },
120
- platform,
121
- tabHeight,
122
- uid,
123
- width,
124
- x,
125
- y
126
- };
127
- set$4(uid, state, state);
128
- };
129
-
130
- const isEqual = (oldState, newState) => {
131
- return oldState.layout === newState.layout;
132
- };
133
-
134
- const RenderItems = 4;
135
-
136
- const modules = [isEqual];
137
- const numbers = [RenderItems];
138
-
139
- const diff = (oldState, newState) => {
140
- const diffResult = [];
141
- for (let i = 0; i < modules.length; i++) {
142
- const fn = modules[i];
143
- if (!fn(oldState, newState)) {
144
- diffResult.push(numbers[i]);
145
- }
146
- }
147
- return diffResult;
148
- };
149
-
150
- const diff2 = uid => {
151
- const {
152
- newState,
153
- oldState
154
- } = get$2(uid);
155
- const result = diff(oldState, newState);
156
- return result;
157
- };
158
-
159
- const Button$1 = 'event.button';
160
- const ClientX = 'event.clientX';
161
- const ClientY = 'event.clientY';
162
- const TargetName = 'event.target.name';
163
-
164
- const Tab = 13;
165
-
166
- const Separator = 1;
167
- const None = 0;
168
-
169
- const SetDom2 = 'Viewlet.setDom2';
170
-
171
- const getMenuIds = () => {
172
- return [Tab];
173
- };
174
-
175
- const handleClick = async (state, name) => {
176
- if (!name) {
177
- return state;
178
- }
179
- return state;
180
- };
181
-
182
101
  const ExtensionHostWorker = 44;
183
102
  const IconThemeWorker = 7009;
184
103
  const RendererWorker = 1;
@@ -699,7 +618,7 @@ const IpcParentWithMessagePort$1 = {
699
618
 
700
619
  const Two$1 = '2.0';
701
620
  const callbacks = Object.create(null);
702
- const get$1 = id => {
621
+ const get$2 = id => {
703
622
  return callbacks[id];
704
623
  };
705
624
  const remove$1 = id => {
@@ -848,7 +767,7 @@ const warn = (...args) => {
848
767
  console.warn(...args);
849
768
  };
850
769
  const resolve = (id, response) => {
851
- const fn = get$1(id);
770
+ const fn = get$2(id);
852
771
  if (!fn) {
853
772
  console.log(response);
854
773
  warn(`callback ${id} may already be disposed`);
@@ -1232,7 +1151,7 @@ const TransferMessagePortRpcParent = {
1232
1151
  __proto__: null,
1233
1152
  create: create$3
1234
1153
  };
1235
- const create$2 = async ({
1154
+ const create$2$1 = async ({
1236
1155
  commandMap
1237
1156
  }) => {
1238
1157
  // TODO create a commandMap per rpc instance
@@ -1244,7 +1163,7 @@ const create$2 = async ({
1244
1163
  };
1245
1164
  const WebWorkerRpcClient = {
1246
1165
  __proto__: null,
1247
- create: create$2
1166
+ create: create$2$1
1248
1167
  };
1249
1168
  const createMockRpc = ({
1250
1169
  commandMap
@@ -1267,10 +1186,10 @@ const createMockRpc = ({
1267
1186
  };
1268
1187
 
1269
1188
  const rpcs = Object.create(null);
1270
- const set$3 = (id, rpc) => {
1189
+ const set$4 = (id, rpc) => {
1271
1190
  rpcs[id] = rpc;
1272
1191
  };
1273
- const get = id => {
1192
+ const get$1 = id => {
1274
1193
  return rpcs[id];
1275
1194
  };
1276
1195
  const remove = id => {
@@ -1278,21 +1197,21 @@ const remove = id => {
1278
1197
  };
1279
1198
 
1280
1199
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
1281
- const create$1 = rpcId => {
1200
+ const create$2 = rpcId => {
1282
1201
  return {
1283
1202
  async dispose() {
1284
- const rpc = get(rpcId);
1203
+ const rpc = get$1(rpcId);
1285
1204
  await rpc.dispose();
1286
1205
  },
1287
1206
  // @ts-ignore
1288
1207
  invoke(method, ...params) {
1289
- const rpc = get(rpcId);
1208
+ const rpc = get$1(rpcId);
1290
1209
  // @ts-ignore
1291
1210
  return rpc.invoke(method, ...params);
1292
1211
  },
1293
1212
  // @ts-ignore
1294
1213
  invokeAndTransfer(method, ...params) {
1295
- const rpc = get(rpcId);
1214
+ const rpc = get$1(rpcId);
1296
1215
  // @ts-ignore
1297
1216
  return rpc.invokeAndTransfer(method, ...params);
1298
1217
  },
@@ -1300,7 +1219,7 @@ const create$1 = rpcId => {
1300
1219
  const mockRpc = createMockRpc({
1301
1220
  commandMap
1302
1221
  });
1303
- set$3(rpcId, mockRpc);
1222
+ set$4(rpcId, mockRpc);
1304
1223
  // @ts-ignore
1305
1224
  mockRpc[Symbol.dispose] = () => {
1306
1225
  remove(rpcId);
@@ -1309,19 +1228,19 @@ const create$1 = rpcId => {
1309
1228
  return mockRpc;
1310
1229
  },
1311
1230
  set(rpc) {
1312
- set$3(rpcId, rpc);
1231
+ set$4(rpcId, rpc);
1313
1232
  }
1314
1233
  };
1315
1234
  };
1316
1235
 
1317
1236
  const {
1318
- set: set$2
1319
- } = create$1(ExtensionHostWorker);
1237
+ set: set$3
1238
+ } = create$2(ExtensionHostWorker);
1320
1239
 
1321
1240
  const {
1322
1241
  invoke: invoke$1,
1323
- set: set$1
1324
- } = create$1(IconThemeWorker);
1242
+ set: set$2
1243
+ } = create$2(IconThemeWorker);
1325
1244
  const getIcons = async iconRequests => {
1326
1245
  // @ts-ignore
1327
1246
  return invoke$1('IconTheme.getIcons', iconRequests);
@@ -1330,8 +1249,8 @@ const getIcons = async iconRequests => {
1330
1249
  const {
1331
1250
  invoke,
1332
1251
  invokeAndTransfer,
1333
- set
1334
- } = create$1(RendererWorker);
1252
+ set: set$1
1253
+ } = create$2(RendererWorker);
1335
1254
  const showContextMenu2 = async (uid, menuId, x, y, args) => {
1336
1255
  number(uid);
1337
1256
  number(menuId);
@@ -1357,7 +1276,16 @@ const handleAttach = async command => {
1357
1276
  await invoke('Layout.attachViewlet', parentNodeSelector, command.instanceId);
1358
1277
  };
1359
1278
 
1360
- const create = () => {
1279
+ const {
1280
+ get,
1281
+ getCommandIds,
1282
+ registerCommands,
1283
+ set,
1284
+ wrapCommand,
1285
+ wrapGetter
1286
+ } = create$6();
1287
+
1288
+ const create$1 = () => {
1361
1289
  return Math.random();
1362
1290
  };
1363
1291
 
@@ -1430,7 +1358,7 @@ const loadTabContentAsync = async (tabId, path, requestId, getLatestState) => {
1430
1358
  }
1431
1359
 
1432
1360
  // Assign editorUid if tab doesn't have one yet
1433
- const editorUid = latestTab.editorUid === -1 ? create() : latestTab.editorUid;
1361
+ const editorUid = latestTab.editorUid === -1 ? create$1() : latestTab.editorUid;
1434
1362
  return updateTab(latestState, tabId, {
1435
1363
  content,
1436
1364
  editorUid,
@@ -1467,7 +1395,7 @@ const createViewletForTab = (state, tabId, viewletModuleId, bounds) => {
1467
1395
  if (tab.editorUid !== -1 || tab.loadingState === 'loading' || tab.loadingState === 'loaded') {
1468
1396
  return state;
1469
1397
  }
1470
- const editorUid = create();
1398
+ const editorUid = create$1();
1471
1399
  const newState = updateTab(state, tabId, {
1472
1400
  editorUid
1473
1401
  });
@@ -1547,9 +1475,9 @@ const handleCreate = async command => {
1547
1475
  const {
1548
1476
  newState: state,
1549
1477
  oldState
1550
- } = get$2(command.uid);
1478
+ } = get(command.uid);
1551
1479
  const readyState = handleViewletReady(state, command.editorUid);
1552
- set$4(command.uid, oldState, readyState);
1480
+ set(command.uid, oldState, readyState);
1553
1481
  return readyState;
1554
1482
  };
1555
1483
 
@@ -1648,6 +1576,98 @@ const closeTab = (state, groupId, tabId) => {
1648
1576
  };
1649
1577
  };
1650
1578
 
1579
+ const closeFocusedTab = state => {
1580
+ const {
1581
+ layout
1582
+ } = state;
1583
+ const {
1584
+ groups
1585
+ } = layout;
1586
+ const focusedGroup = groups.find(group => group.focused);
1587
+ if (!focusedGroup) {
1588
+ return state;
1589
+ }
1590
+ const {
1591
+ activeTabId
1592
+ } = focusedGroup;
1593
+ if (activeTabId === undefined) {
1594
+ return state;
1595
+ }
1596
+ return closeTab(state, focusedGroup.id, activeTabId);
1597
+ };
1598
+
1599
+ const create = (uid, uri, x, y, width, height, platform, assetDir, tabHeight = 35) => {
1600
+ const state = {
1601
+ assetDir,
1602
+ fileIconCache: {},
1603
+ height,
1604
+ layout: {
1605
+ activeGroupId: undefined,
1606
+ direction: 'horizontal',
1607
+ groups: []
1608
+ },
1609
+ platform,
1610
+ tabHeight,
1611
+ uid,
1612
+ width,
1613
+ x,
1614
+ y
1615
+ };
1616
+ set(uid, state, state);
1617
+ };
1618
+
1619
+ const isEqual = (oldState, newState) => {
1620
+ return oldState.layout === newState.layout;
1621
+ };
1622
+
1623
+ const RenderItems = 4;
1624
+
1625
+ const modules = [isEqual];
1626
+ const numbers = [RenderItems];
1627
+
1628
+ const diff = (oldState, newState) => {
1629
+ const diffResult = [];
1630
+ for (let i = 0; i < modules.length; i++) {
1631
+ const fn = modules[i];
1632
+ if (!fn(oldState, newState)) {
1633
+ diffResult.push(numbers[i]);
1634
+ }
1635
+ }
1636
+ return diffResult;
1637
+ };
1638
+
1639
+ const diff2 = uid => {
1640
+ const {
1641
+ newState,
1642
+ oldState
1643
+ } = get(uid);
1644
+ const result = diff(oldState, newState);
1645
+ return result;
1646
+ };
1647
+
1648
+ const Button$1 = 'event.button';
1649
+ const ClientX = 'event.clientX';
1650
+ const ClientY = 'event.clientY';
1651
+ const TargetName = 'event.target.name';
1652
+
1653
+ const Tab = 13;
1654
+
1655
+ const Separator = 1;
1656
+ const None = 0;
1657
+
1658
+ const SetDom2 = 'Viewlet.setDom2';
1659
+
1660
+ const getMenuIds = () => {
1661
+ return [Tab];
1662
+ };
1663
+
1664
+ const handleClick = async (state, name) => {
1665
+ if (!name) {
1666
+ return state;
1667
+ }
1668
+ return state;
1669
+ };
1670
+
1651
1671
  const handleClickCloseTab = (state, rawGroupIndex, rawIndex) => {
1652
1672
  if (!rawGroupIndex || !rawIndex) {
1653
1673
  return state;
@@ -1708,9 +1728,9 @@ const getNextRequestId = () => {
1708
1728
  const startContentLoading = async (oldState, state, tabId, path, requestId) => {
1709
1729
  try {
1710
1730
  const getLatestState = () => {
1711
- return get$2(state.uid).newState;
1731
+ return get(state.uid).newState;
1712
1732
  };
1713
- set$4(state.uid, oldState, state);
1733
+ set(state.uid, oldState, state);
1714
1734
  const newState = await loadTabContentAsync(tabId, path, requestId, getLatestState);
1715
1735
  return newState;
1716
1736
  } catch {
@@ -1842,7 +1862,7 @@ const selectTab = async (state, groupIndex, index) => {
1842
1862
  newState = createdState;
1843
1863
 
1844
1864
  // Store updated state before creating viewlet
1845
- set$4(uid, state, newState);
1865
+ set(uid, state, newState);
1846
1866
 
1847
1867
  // Execute viewlet commands if any
1848
1868
  if (switchCommands.length > 0) {
@@ -1861,7 +1881,7 @@ const selectTab = async (state, groupIndex, index) => {
1861
1881
 
1862
1882
  // Mark viewlet as ready
1863
1883
  newState = handleViewletReady(newState, editorUid);
1864
- set$4(uid, state, newState);
1884
+ set(uid, state, newState);
1865
1885
  }
1866
1886
  }
1867
1887
 
@@ -1876,7 +1896,7 @@ const selectTab = async (state, groupIndex, index) => {
1876
1896
  // Viewlet creation is optional - silently ignore if RendererWorker isn't available
1877
1897
  }
1878
1898
  }
1879
- set$4(uid, state, newState);
1899
+ set(uid, state, newState);
1880
1900
 
1881
1901
  // Execute viewlet commands if any
1882
1902
  if (switchCommands.length > 0) {
@@ -1935,7 +1955,7 @@ const createExtensionHostRpc = async () => {
1935
1955
 
1936
1956
  const initialize = async () => {
1937
1957
  const rpc = await createExtensionHostRpc();
1938
- set$2(rpc);
1958
+ set$3(rpc);
1939
1959
  };
1940
1960
 
1941
1961
  const isValidTab = tab => {
@@ -2113,7 +2133,7 @@ const createViewlets = async (layout, viewletModuleIds, bounds) => {
2113
2133
  for (const group of layout.groups) {
2114
2134
  const activeTab = group.tabs.find(tab => tab.id === group.activeTabId);
2115
2135
  if (activeTab && viewletModuleIds[activeTab.id]) {
2116
- const editorUid = activeTab.editorUid === -1 ? create() : activeTab.editorUid;
2136
+ const editorUid = activeTab.editorUid === -1 ? create$1() : activeTab.editorUid;
2117
2137
  editorUids[activeTab.id] = editorUid;
2118
2138
  await createViewlet(viewletModuleIds[activeTab.id], editorUid, activeTab.id, bounds, activeTab.uri);
2119
2139
  }
@@ -2235,6 +2255,16 @@ const loadContent = async (state, savedState) => {
2235
2255
  };
2236
2256
  };
2237
2257
 
2258
+ const findGroupById = (state, groupId) => {
2259
+ const {
2260
+ layout
2261
+ } = state;
2262
+ const {
2263
+ groups
2264
+ } = layout;
2265
+ return groups.find(group => group.id === groupId);
2266
+ };
2267
+
2238
2268
  const emptyObject = {};
2239
2269
  const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
2240
2270
  const i18nString = (key, placeholders = emptyObject) => {
@@ -2286,16 +2316,20 @@ const getMenuEntries$1 = state => {
2286
2316
  layout
2287
2317
  } = state;
2288
2318
  const {
2289
- activeGroupId,
2290
- groups
2319
+ activeGroupId
2291
2320
  } = layout;
2292
- const group = groups[activeGroupId || 0];
2321
+ const group = findGroupById(state, activeGroupId || 0);
2322
+ if (!group) {
2323
+ return [];
2324
+ }
2293
2325
  const {
2294
2326
  activeTabId,
2295
2327
  tabs
2296
2328
  } = group;
2297
- const tab = tabs[activeTabId || 0];
2298
- object(tab);
2329
+ const tab = tabs.find(t => t.id === activeTabId);
2330
+ if (!tab) {
2331
+ return [];
2332
+ }
2299
2333
  const {
2300
2334
  uri: path
2301
2335
  } = tab;
@@ -2367,10 +2401,10 @@ const createEmptyGroup = (state, uri, requestId) => {
2367
2401
  const {
2368
2402
  groups
2369
2403
  } = layout;
2370
- const groupId = create();
2404
+ const groupId = create$1();
2371
2405
  const title = getLabel(uri);
2372
- const tabId = create();
2373
- const editorUid = create();
2406
+ const tabId = create$1();
2407
+ const editorUid = create$1();
2374
2408
  const newTab = {
2375
2409
  content: '',
2376
2410
  editorType: 'text',
@@ -2404,7 +2438,7 @@ const createEmptyGroup = (state, uri, requestId) => {
2404
2438
  const openTab = (state, groupId, tab) => {
2405
2439
  const newTab = 'id' in tab && tab.id !== undefined ? tab : {
2406
2440
  ...tab,
2407
- id: create()
2441
+ id: create$1()
2408
2442
  };
2409
2443
  const {
2410
2444
  layout
@@ -2450,8 +2484,8 @@ const ensureActiveGroup = (state, uri) => {
2450
2484
  if (activeGroup) {
2451
2485
  // Create a new tab with the URI in the active group
2452
2486
  const title = getLabel(uri);
2453
- const tabId = create();
2454
- const editorUid = create();
2487
+ const tabId = create$1();
2488
+ const editorUid = create$1();
2455
2489
  const newTab = {
2456
2490
  content: '',
2457
2491
  editorType: 'text',
@@ -2606,7 +2640,7 @@ const openUri = async (state, options) => {
2606
2640
  newState: switchedState
2607
2641
  } = switchViewlet(intermediateState1);
2608
2642
  intermediateState1 = switchedState;
2609
- set$4(uid, state, intermediateState1);
2643
+ set(uid, state, intermediateState1);
2610
2644
 
2611
2645
  // @ts-ignore
2612
2646
 
@@ -2627,7 +2661,7 @@ const openUri = async (state, options) => {
2627
2661
  // This ensures we have any state updates that occurred during viewlet creation
2628
2662
  const {
2629
2663
  newState: latestState
2630
- } = get$2(uid);
2664
+ } = get(uid);
2631
2665
 
2632
2666
  // Attachment is handled automatically by virtual DOM reference nodes
2633
2667
  const readyState = handleViewletReady(latestState, editorUid);
@@ -2866,8 +2900,8 @@ const render2 = (uid, diffResult) => {
2866
2900
  const {
2867
2901
  newState,
2868
2902
  oldState
2869
- } = get$2(uid);
2870
- set$4(uid, newState, newState);
2903
+ } = get(uid);
2904
+ set(uid, newState, newState);
2871
2905
  const commands = applyRender(oldState, newState, diffResult);
2872
2906
  return commands;
2873
2907
  };
@@ -2907,7 +2941,8 @@ const saveState = state => {
2907
2941
 
2908
2942
  const commandMap = {
2909
2943
  'MainArea.closeAll': wrapCommand(closeAll$1),
2910
- 'MainArea.create': create$6,
2944
+ 'MainArea.closeFocusedTab': wrapCommand(closeFocusedTab),
2945
+ 'MainArea.create': create,
2911
2946
  'MainArea.diff2': diff2,
2912
2947
  'MainArea.getCommandIds': getCommandIds,
2913
2948
  'MainArea.getMenuEntries': wrapGetter(getMenuEntries),
@@ -2945,14 +2980,14 @@ const createIconThemeWorkerRpc = async () => {
2945
2980
 
2946
2981
  const initializeIconThemeWorker = async () => {
2947
2982
  const rpc = await createIconThemeWorkerRpc();
2948
- set$1(rpc);
2983
+ set$2(rpc);
2949
2984
  };
2950
2985
 
2951
2986
  const initializeRendererWorker = async () => {
2952
2987
  const rpc = await WebWorkerRpcClient.create({
2953
2988
  commandMap: commandMap
2954
2989
  });
2955
- set(rpc);
2990
+ set$1(rpc);
2956
2991
  };
2957
2992
 
2958
2993
  const listen = async () => {
@@ -2969,7 +3004,7 @@ const main$1 = async () => {
2969
3004
  const rpc = await WebWorkerRpcClient.create({
2970
3005
  commandMap: commandMap
2971
3006
  });
2972
- set(rpc);
3007
+ set$1(rpc);
2973
3008
  };
2974
3009
 
2975
3010
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "5.2.0",
3
+ "version": "5.3.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",