@lvce-editor/title-bar-worker 3.4.0 → 3.6.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.
@@ -1629,23 +1629,42 @@ const diff3 = uid => {
1629
1629
  return diffResult;
1630
1630
  };
1631
1631
 
1632
- const getEntryMap = async modules => {
1633
- const map = Object.create(null);
1634
- for (const module of modules) {
1635
- const {
1636
- id
1637
- } = module;
1638
- const entries = await module.getMenuEntries();
1639
- map[id] = entries;
1640
- }
1641
- return map;
1642
- };
1632
+ const Separator$2 = 1;
1633
+ const None$1 = 0;
1634
+ const SubMenu$1 = 4;
1635
+ const Checked = 2;
1636
+ const Unchecked = 3;
1637
+ const Disabled = 5;
1638
+ const RestoreFocus = 6;
1639
+ const Ignore = 7;
1643
1640
 
1644
- // TODO cache window id
1641
+ const getMenuEntriesTitleBarContextMenu = async state => {
1642
+ const {
1643
+ commandCenterEnabled,
1644
+ titleBarMenuBarEnabled
1645
+ } = state;
1646
+ // TODO checked state should be depending on whether or not that feature is currently visible or not
1647
+ return [{
1648
+ command: titleBarMenuBarEnabled ? 'TitleBar.hideMenuBar' : 'TitleBar.showMenuBar',
1649
+ flags: titleBarMenuBarEnabled ? Checked : Unchecked,
1650
+ id: 'MenuBar',
1651
+ label: menuBar()
1652
+ }, {
1653
+ command: commandCenterEnabled ? 'TitleBar.hideCommandCenter' : 'TitleBar.showCommandCenter',
1654
+ flags: commandCenterEnabled ? Checked : Unchecked,
1655
+ id: 'Command center',
1656
+ label: commandCenter()
1657
+ }, {
1658
+ command: '',
1659
+ flags: Checked,
1660
+ id: 'layout controls',
1661
+ label: 'layout controls'
1662
+ }];
1663
+ };
1645
1664
 
1646
- const getWindowId = async () => {
1647
- const windowId = await invoke('GetWindowId.getWindowId');
1648
- return windowId;
1665
+ const MenuIdTitleBarContextMenu = 50;
1666
+ const getMenuIds = () => {
1667
+ return [Edit$2, File$3, Go$2, Help$3, OpenRecent$1, Run$2, Selection$2, Terminal$2, TitleBar$1, View$2, MenuIdTitleBarContextMenu, TitleBarContextMenu];
1649
1668
  };
1650
1669
 
1651
1670
  const cut = () => {
@@ -1712,15 +1731,6 @@ const selectAllOccurrences = () => {
1712
1731
  return i18nString(SelectAllOccurrences);
1713
1732
  };
1714
1733
 
1715
- const Separator$2 = 1;
1716
- const None$1 = 0;
1717
- const SubMenu$1 = 4;
1718
- const Checked = 2;
1719
- const Unchecked = 3;
1720
- const Disabled = 5;
1721
- const RestoreFocus = 6;
1722
- const Ignore = 7;
1723
-
1724
1734
  const menuEntrySeparator = {
1725
1735
  command: '',
1726
1736
  flags: Separator$2,
@@ -1767,11 +1777,6 @@ const getMenuEntries$c = () => {
1767
1777
  }];
1768
1778
  };
1769
1779
 
1770
- const MenuEntriesEdit = {
1771
- __proto__: null,
1772
- getMenuEntries: getMenuEntries$c
1773
- };
1774
-
1775
1780
  /**
1776
1781
  * @enum {string}
1777
1782
  */
@@ -1868,20 +1873,10 @@ const getMenuEntries$b = platform => {
1868
1873
  return entries;
1869
1874
  };
1870
1875
 
1871
- const MenuEntriesFile = {
1872
- __proto__: null,
1873
- getMenuEntries: getMenuEntries$b
1874
- };
1875
-
1876
1876
  const getMenuEntries$a = () => {
1877
1877
  return [];
1878
1878
  };
1879
1879
 
1880
- const MenuEntriesGo = {
1881
- __proto__: null,
1882
- getMenuEntries: getMenuEntries$a
1883
- };
1884
-
1885
1880
  const toggleDeveloperTools = () => {
1886
1881
  return i18nString(ToggleDeveloperTools);
1887
1882
  };
@@ -1938,21 +1933,70 @@ const getMenuEntries$9 = async platform => {
1938
1933
  return entries;
1939
1934
  };
1940
1935
 
1941
- const MenuEntriesHelp = {
1942
- __proto__: null,
1943
- getMenuEntries: getMenuEntries$9
1936
+ const getRecentlyOpened = () => {
1937
+ return invoke(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
1944
1938
  };
1945
1939
 
1946
- const getMenuEntries$8 = () => {
1947
- return [];
1940
+ const File = 'file://';
1941
+
1942
+ const getTitle$1 = (homeDir, uri) => {
1943
+ if (!uri) {
1944
+ return '';
1945
+ }
1946
+ if (uri.startsWith(File)) {
1947
+ return uri.slice(File.length);
1948
+ }
1949
+ return uri;
1948
1950
  };
1949
1951
 
1950
- const MenuEntriesRun = {
1951
- __proto__: null,
1952
- getMenuEntries: getMenuEntries$8
1952
+ const moreDot = () => {
1953
+ return i18nString(MoreDot);
1954
+ };
1955
+ const clearRecentlyOpened = () => {
1956
+ return i18nString(ClearRecentlyOpened);
1957
+ };
1958
+
1959
+ const getHomeDir = () => {
1960
+ return '';
1961
+ };
1962
+
1963
+ const MAX_MENU_RECENT_ENTRIES = 10;
1964
+ const toMenuItem = folder => {
1965
+ const homeDir = getHomeDir();
1966
+ const label = getTitle$1(homeDir, folder);
1967
+ return {
1968
+ args: [folder],
1969
+ command: 'Workspace.setPath',
1970
+ flags: None$1,
1971
+ label
1972
+ };
1973
+ };
1974
+ const getMenuEntries$8 = async () => {
1975
+ const allItems = await getRecentlyOpened();
1976
+ const itemsToShow = allItems.slice(0, MAX_MENU_RECENT_ENTRIES);
1977
+ const items = [];
1978
+ if (itemsToShow.length > 0) {
1979
+ items.push(...itemsToShow.map(toMenuItem), menuEntrySeparator);
1980
+ }
1981
+ items.push({
1982
+ command: 'QuickPick.showRecent',
1983
+ flags: None$1,
1984
+ id: 'more',
1985
+ label: moreDot()
1986
+ }, menuEntrySeparator, {
1987
+ command: 'RecentlyOpened.clearRecentlyOpened',
1988
+ flags: None$1,
1989
+ id: 'clearRecentlyOpened',
1990
+ label: clearRecentlyOpened()
1991
+ });
1992
+ return items;
1953
1993
  };
1954
1994
 
1955
1995
  const getMenuEntries$7 = () => {
1996
+ return [];
1997
+ };
1998
+
1999
+ const getMenuEntries$6 = () => {
1956
2000
  return [{
1957
2001
  command: 'Editor.selectAll',
1958
2002
  flags: None$1,
@@ -2026,12 +2070,7 @@ const getMenuEntries$7 = () => {
2026
2070
  }];
2027
2071
  };
2028
2072
 
2029
- const MenuEntriesSelection = {
2030
- __proto__: null,
2031
- getMenuEntries: getMenuEntries$7
2032
- };
2033
-
2034
- const getMenuEntries$6 = () => {
2073
+ const getMenuEntries$5 = () => {
2035
2074
  return [{
2036
2075
  args: ['Terminal'],
2037
2076
  command: 'Layout.togglePanel',
@@ -2041,18 +2080,151 @@ const getMenuEntries$6 = () => {
2041
2080
  }];
2042
2081
  };
2043
2082
 
2044
- const MenuEntriesTerminal = {
2045
- __proto__: null,
2046
- getMenuEntries: getMenuEntries$6
2083
+ const getMenuEntries$4 = () => {
2084
+ return [{
2085
+ command: '',
2086
+ flags: SubMenu$1,
2087
+ id: File$1,
2088
+ label: file()
2089
+ }, {
2090
+ command: '',
2091
+ flags: SubMenu$1,
2092
+ id: Edit,
2093
+ label: edit()
2094
+ }, {
2095
+ command: '',
2096
+ flags: SubMenu$1,
2097
+ id: Selection,
2098
+ label: selection()
2099
+ }, {
2100
+ command: '',
2101
+ flags: SubMenu$1,
2102
+ id: View,
2103
+ label: view()
2104
+ }, {
2105
+ command: '',
2106
+ flags: SubMenu$1,
2107
+ id: Go,
2108
+ label: go()
2109
+ }, {
2110
+ command: '',
2111
+ flags: SubMenu$1,
2112
+ id: Run,
2113
+ keyboardShortCut: 'Alt+r',
2114
+ label: run()
2115
+ }, {
2116
+ command: '',
2117
+ flags: SubMenu$1,
2118
+ id: Terminal,
2119
+ keyboardShortCut: 'Alt+t',
2120
+ label: terminal()
2121
+ }, {
2122
+ command: '',
2123
+ flags: SubMenu$1,
2124
+ id: Help$1,
2125
+ keyboardShortCut: 'Alt+h',
2126
+ label: help()
2127
+ }];
2047
2128
  };
2048
2129
 
2049
- const getMenuEntries$5 = () => {
2130
+ const getMenuEntries$3 = () => {
2131
+ return [{
2132
+ command: '',
2133
+ flags: None$1,
2134
+ id: File$1,
2135
+ label: file()
2136
+ }, {
2137
+ command: '',
2138
+ flags: None$1,
2139
+ id: Edit,
2140
+ label: edit()
2141
+ }, {
2142
+ command: '',
2143
+ flags: None$1,
2144
+ id: Selection,
2145
+ label: selection()
2146
+ }, {
2147
+ command: '',
2148
+ flags: None$1,
2149
+ id: View,
2150
+ label: view()
2151
+ }, {
2152
+ command: '',
2153
+ flags: None$1,
2154
+ id: Go,
2155
+ label: go()
2156
+ }, {
2157
+ command: '',
2158
+ flags: None$1,
2159
+ id: Help$1,
2160
+ label: help()
2161
+ }];
2162
+ };
2163
+
2164
+ const getFn$1 = platform => {
2165
+ switch (platform) {
2166
+ case Web:
2167
+ return getMenuEntries$3;
2168
+ default:
2169
+ return getMenuEntries$4;
2170
+ }
2171
+ };
2172
+ const getMenuEntries$2 = async platform => {
2173
+ const fn = getFn$1(platform);
2174
+ return fn();
2175
+ };
2176
+
2177
+ const getMenuEntries$1 = () => {
2050
2178
  return [];
2051
2179
  };
2052
2180
 
2053
- const MenuEntriesView = {
2054
- __proto__: null,
2055
- getMenuEntries: getMenuEntries$5
2181
+ const getMenuEntries2 = async (state, props) => {
2182
+ switch (props.menuId) {
2183
+ case Edit$2:
2184
+ return getMenuEntries$c();
2185
+ case File$3:
2186
+ return getMenuEntries$b(props.platform);
2187
+ case Go$2:
2188
+ return getMenuEntries$a();
2189
+ case Help$3:
2190
+ return getMenuEntries$9(props.platform);
2191
+ case OpenRecent$1:
2192
+ return getMenuEntries$8();
2193
+ case Run$2:
2194
+ return getMenuEntries$7();
2195
+ case Selection$2:
2196
+ return getMenuEntries$6();
2197
+ case Terminal$2:
2198
+ return getMenuEntries$5();
2199
+ case TitleBar$1:
2200
+ return getMenuEntries$2(props.platform);
2201
+ case TitleBarContextMenu:
2202
+ case MenuIdTitleBarContextMenu:
2203
+ return getMenuEntriesTitleBarContextMenu(state);
2204
+ case View$2:
2205
+ return getMenuEntries$1();
2206
+ default:
2207
+ return [];
2208
+ }
2209
+ };
2210
+
2211
+ const getEntryMap = async (state, menuIds) => {
2212
+ const map = Object.create(null);
2213
+ for (const id of menuIds) {
2214
+ const entries = await getMenuEntries2(state, {
2215
+ // @ts-ignore
2216
+ menuId: id
2217
+ });
2218
+ map[id] = entries;
2219
+ }
2220
+ return map;
2221
+ };
2222
+
2223
+ // TODO cache window id
2224
+
2225
+ const getWindowId = async () => {
2226
+ const windowId = await invoke('GetWindowId.getWindowId');
2227
+ return windowId;
2056
2228
  };
2057
2229
 
2058
2230
  // based on https://www.electronjs.org/docs/latest/api/menu-item#new-menuitemoptions
@@ -2188,15 +2360,13 @@ const toElectronMenu = (map, rootId) => {
2188
2360
  };
2189
2361
  };
2190
2362
 
2191
- const menuEntries = [MenuEntriesFile, MenuEntriesEdit, MenuEntriesSelection, MenuEntriesView, MenuEntriesGo, MenuEntriesRun, MenuEntriesTerminal, MenuEntriesHelp
2192
- // MenuEntriesTitleBar,
2193
- ];
2194
2363
  const setItems = async items => {
2195
2364
  const windowId = await getWindowId();
2196
- return invoke('ElectronApplicationMenu.setItems', windowId, items);
2365
+ return invoke('WebView.compatSharedProcessInvoke', 'ElectronApplicationMenu.setItems', windowId, items);
2197
2366
  };
2198
2367
  const hydrate = async state => {
2199
- const map = await getEntryMap(menuEntries);
2368
+ const ids = getMenuIds();
2369
+ const map = await getEntryMap(state, ids);
2200
2370
  const {
2201
2371
  commandMap,
2202
2372
  electronMenu
@@ -2286,122 +2456,6 @@ const getKeyBindings = () => {
2286
2456
  }];
2287
2457
  };
2288
2458
 
2289
- const getMenuEntriesTitleBarContextMenu = async state => {
2290
- const {
2291
- commandCenterEnabled,
2292
- titleBarMenuBarEnabled
2293
- } = state;
2294
- // TODO checked state should be depending on whether or not that feature is currently visible or not
2295
- return [{
2296
- command: titleBarMenuBarEnabled ? 'TitleBar.hideMenuBar' : 'TitleBar.showMenuBar',
2297
- flags: titleBarMenuBarEnabled ? Checked : Unchecked,
2298
- id: 'MenuBar',
2299
- label: menuBar()
2300
- }, {
2301
- command: commandCenterEnabled ? 'TitleBar.hideCommandCenter' : 'TitleBar.showCommandCenter',
2302
- flags: commandCenterEnabled ? Checked : Unchecked,
2303
- id: 'Command center',
2304
- label: commandCenter()
2305
- }, {
2306
- command: '',
2307
- flags: Checked,
2308
- id: 'layout controls',
2309
- label: 'layout controls'
2310
- }];
2311
- };
2312
-
2313
- const MenuIdTitleBarContextMenu = 50;
2314
- const getMenuIds = () => {
2315
- return [Edit$2, File$3, Go$2, Help$3, OpenRecent$1, Run$2, Selection$2, Terminal$2, TitleBar$1, View$2, MenuIdTitleBarContextMenu, TitleBarContextMenu];
2316
- };
2317
-
2318
- const getRecentlyOpened = () => {
2319
- return invoke(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
2320
- };
2321
-
2322
- const File = 'file://';
2323
-
2324
- const getTitle$1 = (homeDir, uri) => {
2325
- if (!uri) {
2326
- return '';
2327
- }
2328
- if (uri.startsWith(File)) {
2329
- return uri.slice(File.length);
2330
- }
2331
- return uri;
2332
- };
2333
-
2334
- const moreDot = () => {
2335
- return i18nString(MoreDot);
2336
- };
2337
- const clearRecentlyOpened = () => {
2338
- return i18nString(ClearRecentlyOpened);
2339
- };
2340
-
2341
- const getHomeDir = () => {
2342
- return '';
2343
- };
2344
-
2345
- const MAX_MENU_RECENT_ENTRIES = 10;
2346
- const toMenuItem = folder => {
2347
- const homeDir = getHomeDir();
2348
- const label = getTitle$1(homeDir, folder);
2349
- return {
2350
- args: [folder],
2351
- command: 'Workspace.setPath',
2352
- flags: None$1,
2353
- label
2354
- };
2355
- };
2356
- const getMenuEntries$4 = async () => {
2357
- const allItems = await getRecentlyOpened();
2358
- const itemsToShow = allItems.slice(0, MAX_MENU_RECENT_ENTRIES);
2359
- const items = [];
2360
- if (itemsToShow.length > 0) {
2361
- items.push(...itemsToShow.map(toMenuItem), menuEntrySeparator);
2362
- }
2363
- items.push({
2364
- command: 'QuickPick.showRecent',
2365
- flags: None$1,
2366
- id: 'more',
2367
- label: moreDot()
2368
- }, menuEntrySeparator, {
2369
- command: 'RecentlyOpened.clearRecentlyOpened',
2370
- flags: None$1,
2371
- id: 'clearRecentlyOpened',
2372
- label: clearRecentlyOpened()
2373
- });
2374
- return items;
2375
- };
2376
-
2377
- const getMenuEntries2 = async (state, props) => {
2378
- switch (props.menuId) {
2379
- case Edit$2:
2380
- return getMenuEntries$c();
2381
- case File$3:
2382
- return getMenuEntries$b(props.platform);
2383
- case Go$2:
2384
- return getMenuEntries$a();
2385
- case Help$3:
2386
- return getMenuEntries$9(props.platform);
2387
- case OpenRecent$1:
2388
- return getMenuEntries$4();
2389
- case Run$2:
2390
- return getMenuEntries$8();
2391
- case Selection$2:
2392
- return getMenuEntries$7();
2393
- case Terminal$2:
2394
- return getMenuEntries$6();
2395
- case TitleBarContextMenu:
2396
- case MenuIdTitleBarContextMenu:
2397
- return getMenuEntriesTitleBarContextMenu(state);
2398
- case View$2:
2399
- return getMenuEntries$5();
2400
- default:
2401
- return [];
2402
- }
2403
- };
2404
-
2405
2459
  const maximize = async () => {
2406
2460
  await invoke('ElectronWindow.maximize');
2407
2461
  };
@@ -2788,100 +2842,6 @@ const getTitle = workspaceUri => {
2788
2842
  return baseName;
2789
2843
  };
2790
2844
 
2791
- const getMenuEntries$3 = () => {
2792
- return [{
2793
- command: '',
2794
- flags: SubMenu$1,
2795
- id: File$1,
2796
- label: file()
2797
- }, {
2798
- command: '',
2799
- flags: SubMenu$1,
2800
- id: Edit,
2801
- label: edit()
2802
- }, {
2803
- command: '',
2804
- flags: SubMenu$1,
2805
- id: Selection,
2806
- label: selection()
2807
- }, {
2808
- command: '',
2809
- flags: SubMenu$1,
2810
- id: View,
2811
- label: view()
2812
- }, {
2813
- command: '',
2814
- flags: SubMenu$1,
2815
- id: Go,
2816
- label: go()
2817
- }, {
2818
- command: '',
2819
- flags: SubMenu$1,
2820
- id: Run,
2821
- keyboardShortCut: 'Alt+r',
2822
- label: run()
2823
- }, {
2824
- command: '',
2825
- flags: SubMenu$1,
2826
- id: Terminal,
2827
- keyboardShortCut: 'Alt+t',
2828
- label: terminal()
2829
- }, {
2830
- command: '',
2831
- flags: SubMenu$1,
2832
- id: Help$1,
2833
- keyboardShortCut: 'Alt+h',
2834
- label: help()
2835
- }];
2836
- };
2837
-
2838
- const getMenuEntries$2 = () => {
2839
- return [{
2840
- command: '',
2841
- flags: None$1,
2842
- id: File$1,
2843
- label: file()
2844
- }, {
2845
- command: '',
2846
- flags: None$1,
2847
- id: Edit,
2848
- label: edit()
2849
- }, {
2850
- command: '',
2851
- flags: None$1,
2852
- id: Selection,
2853
- label: selection()
2854
- }, {
2855
- command: '',
2856
- flags: None$1,
2857
- id: View,
2858
- label: view()
2859
- }, {
2860
- command: '',
2861
- flags: None$1,
2862
- id: Go,
2863
- label: go()
2864
- }, {
2865
- command: '',
2866
- flags: None$1,
2867
- id: Help$1,
2868
- label: help()
2869
- }];
2870
- };
2871
-
2872
- const getFn$1 = platform => {
2873
- switch (platform) {
2874
- case Web:
2875
- return getMenuEntries$2;
2876
- default:
2877
- return getMenuEntries$3;
2878
- }
2879
- };
2880
- const getMenuEntries$1 = async platform => {
2881
- const fn = getFn$1(platform);
2882
- return fn();
2883
- };
2884
-
2885
2845
  const loadContent2 = async state => {
2886
2846
  const {
2887
2847
  controlsOverlayEnabled,
@@ -2893,12 +2853,15 @@ const loadContent2 = async state => {
2893
2853
  platform,
2894
2854
  titleBarStyleCustom
2895
2855
  } = state;
2896
- const titleBarEntries = await getMenuEntries$1(platform);
2856
+ const titleBarEntries = await getMenuEntries$2(platform);
2897
2857
  const withWidths = addWidths(titleBarEntries, labelPadding, labelFontWeight, labelFontSize, labelFontFamily, labelLetterSpacing);
2898
2858
  const buttons = getTitleBarButtons(platform, controlsOverlayEnabled, titleBarStyleCustom);
2899
2859
  const workspaceUri = await invoke('Workspace.getUri');
2900
2860
  const title = getTitle(workspaceUri);
2901
2861
  const iconWidth = 30;
2862
+ if (titleBarStyleCustom === false) {
2863
+ return hydrate(state);
2864
+ }
2902
2865
  return {
2903
2866
  ...state,
2904
2867
  buttons,
@@ -3363,9 +3326,16 @@ const getTitleBarVirtualDom = state => {
3363
3326
  titleBarEntries,
3364
3327
  titleBarIconEnabled,
3365
3328
  titleBarMenuBarEnabled,
3329
+ titleBarStyleCustom,
3366
3330
  titleBarTitleEnabled,
3367
3331
  width
3368
3332
  } = state;
3333
+ if (titleBarStyleCustom) {
3334
+ return [{
3335
+ childCount: 0,
3336
+ type: Div$1
3337
+ }];
3338
+ }
3369
3339
  const iconSrc = getIcon(assetDir);
3370
3340
  const visibleEntries = getVisibleTitleBarEntries(titleBarEntries, width, focusedIndex, isMenuOpen);
3371
3341
  return [{
@@ -3723,17 +3693,17 @@ const getFn = id => {
3723
3693
  case Help$3:
3724
3694
  return getMenuEntries$9;
3725
3695
  case OpenRecent$1:
3726
- return getMenuEntries$4;
3727
- case Run$2:
3728
3696
  return getMenuEntries$8;
3729
- case Selection$2:
3697
+ case Run$2:
3730
3698
  return getMenuEntries$7;
3731
- case Terminal$2:
3699
+ case Selection$2:
3732
3700
  return getMenuEntries$6;
3701
+ case Terminal$2:
3702
+ return getMenuEntries$5;
3733
3703
  case TitleBar$1:
3734
- return getMenuEntries$1;
3704
+ return getMenuEntries$2;
3735
3705
  case View$2:
3736
- return getMenuEntries$5;
3706
+ return getMenuEntries$1;
3737
3707
  default:
3738
3708
  return undefined;
3739
3709
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/title-bar-worker",
3
- "version": "3.4.0",
3
+ "version": "3.6.0",
4
4
  "description": "Title Bar Worker",
5
5
  "repository": {
6
6
  "type": "git",