@lvce-editor/menu-worker 1.5.0 → 1.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.
@@ -1231,7 +1231,7 @@ const invoke = async (method, ...params) => {
1231
1231
  // TODO
1232
1232
  };
1233
1233
 
1234
- const state$2 = {
1234
+ const state$1 = {
1235
1235
  /**
1236
1236
  * @type {any}
1237
1237
  */
@@ -1829,7 +1829,7 @@ const getMenuEntries2 = async (uid, menuId, ...args) => {
1829
1829
  };
1830
1830
 
1831
1831
  const addKeyBindings = menuEntries => {
1832
- const keyBindings = state$2.matchingKeyBindings;
1832
+ const keyBindings = state$1.matchingKeyBindings;
1833
1833
  const newMenuEntries = [];
1834
1834
  for (const menuEntry of menuEntries) {
1835
1835
  const keyBinding = getCommandKeyBinding(keyBindings, menuEntry.command, menuEntry.args);
@@ -2085,17 +2085,36 @@ const getVisible = (items, focusedIndex, expanded, level) => {
2085
2085
  return visibleItems;
2086
2086
  };
2087
2087
 
2088
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
2088
2089
  // TODO lazyload menuEntries and use Command.execute (maybe)
2089
- const CONTEXT_MENU_WIDTH$1 = 250;
2090
- const state$1 = {
2090
+
2091
+ // TODO difference between focusing with mouse or keyboard
2092
+ // with mouse -> open submenu
2093
+ // with keyboard -> don't open submenu, only focus
2094
+
2095
+ // TODO this code seems a bit too complicated, maybe it can be simplified
2096
+
2097
+ const state = {
2091
2098
  menus: []};
2092
- const addMenuInternal$1 = menu => {
2093
- if (state$1.menus.length > 5) {
2099
+ const addMenuInternal = menu => {
2100
+ if (state.menus.length > 5) {
2094
2101
  throw new Error('too many menus');
2095
2102
  }
2096
- state$1.menus.push(menu);
2103
+ state.menus.push(menu);
2097
2104
  return menu;
2098
2105
  };
2106
+ const getCount = () => {
2107
+ return state.menus.length;
2108
+ };
2109
+ const reset = () => {
2110
+ state.menus = [];
2111
+ };
2112
+ const getAll = () => {
2113
+ return state.menus;
2114
+ };
2115
+
2116
+ // TODO lazyload menuEntries and use Command.execute (maybe)
2117
+ const CONTEXT_MENU_WIDTH$1 = 250;
2099
2118
 
2100
2119
  // TODO handle printable letter and focus item that starts with that letter
2101
2120
 
@@ -2147,11 +2166,11 @@ const getMenuBounds$1 = (x, y, items) => {
2147
2166
  const show$2 = async (x, y, id, mouseBlocking = false, ...args) => {
2148
2167
  const items = await getMenuEntriesWithKeyBindings(id, ...args);
2149
2168
  const bounds = getMenuBounds$1(x, y, items);
2150
- const menu = addMenuInternal$1({
2169
+ const menu = addMenuInternal({
2151
2170
  id,
2152
2171
  items,
2153
2172
  focusedIndex: -1,
2154
- level: state$1.menus.length,
2173
+ level: getCount(),
2155
2174
  x: bounds.x,
2156
2175
  y: bounds.y
2157
2176
  });
@@ -2162,11 +2181,11 @@ const show$2 = async (x, y, id, mouseBlocking = false, ...args) => {
2162
2181
  const show2$2 = async (uid, menuId, x, y, mouseBlocking = false, ...args) => {
2163
2182
  const items = await getMenuEntriesWithKeyBindings2(uid, menuId, ...args);
2164
2183
  const bounds = getMenuBounds$1(x, y, items);
2165
- const menu = addMenuInternal$1({
2184
+ const menu = addMenuInternal({
2166
2185
  id: menuId,
2167
2186
  items,
2168
2187
  focusedIndex: -1,
2169
- level: state$1.menus.length,
2188
+ level: getCount(),
2170
2189
  x: bounds.x,
2171
2190
  y: bounds.y
2172
2191
  });
@@ -2175,10 +2194,10 @@ const show2$2 = async (uid, menuId, x, y, mouseBlocking = false, ...args) => {
2175
2194
  await invoke(/* Menu.show */'Menu.showMenu', /* x */bounds.x, /* y */bounds.y, /* width */bounds.width, /* height */bounds.height, /* items */menu.items, /* level */menu.level, /* parentIndex */-1, /* dom */dom, /* mouseBlocking */mouseBlocking);
2176
2195
  };
2177
2196
  const hide = async (restoreFocus = true) => {
2178
- if (state$1.menus.length === 0) {
2197
+ if (getCount() === 0) {
2179
2198
  return;
2180
2199
  }
2181
- state$1.menus = [];
2200
+ reset();
2182
2201
  await invoke(/* Menu.hide */'Menu.hide', /* restoreFocus */restoreFocus);
2183
2202
  };
2184
2203
 
@@ -2332,6 +2351,33 @@ const getKeyBindings = () => {
2332
2351
  }];
2333
2352
  };
2334
2353
 
2354
+ const getMenuHideCommands = async (restoreFocus = true) => {
2355
+ if (getCount() === 0) {
2356
+ return {
2357
+ newMenus: [],
2358
+ commands: []
2359
+ };
2360
+ }
2361
+ reset();
2362
+ return {
2363
+ commands: [/* Menu.hide */'Menu.hide', /* restoreFocus */restoreFocus],
2364
+ newMenus: []
2365
+ };
2366
+ };
2367
+
2368
+ const menus = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
2369
+
2370
+ const getMenuIds = () => {
2371
+ return menus.map(menu => menu.id);
2372
+ };
2373
+ const getMenuEntries = (id, platform) => {
2374
+ const menu = menus.find(item => item.id === id);
2375
+ if (!menu) {
2376
+ return [];
2377
+ }
2378
+ return menu.getMenuEntries(platform);
2379
+ };
2380
+
2335
2381
  // TODO lazyload menuEntries and use Command.execute (maybe)
2336
2382
  const CONTEXT_MENU_WIDTH = 250;
2337
2383
 
@@ -2341,16 +2387,6 @@ const CONTEXT_MENU_WIDTH = 250;
2341
2387
 
2342
2388
  // TODO this code seems a bit too complicated, maybe it can be simplified
2343
2389
 
2344
- const state = {
2345
- menus: []};
2346
- const addMenuInternal = menu => {
2347
- if (state.menus.length > 5) {
2348
- throw new Error('too many menus');
2349
- }
2350
- state.menus.push(menu);
2351
- return menu;
2352
- };
2353
-
2354
2390
  // TODO handle printable letter and focus item that starts with that letter
2355
2391
 
2356
2392
  // TODO pageup / pagedown keys
@@ -2404,45 +2440,19 @@ const getMenuShowCommands = async (items, menuId, x, y, mouseBlocking = false) =
2404
2440
  id: menuId,
2405
2441
  items,
2406
2442
  focusedIndex: -1,
2407
- level: state.menus.length,
2443
+ level: getCount(),
2408
2444
  x: bounds.x,
2409
2445
  y: bounds.y
2410
2446
  });
2411
2447
  const visible = getVisible(menu.items, -1, false, menu.level);
2412
2448
  const dom = getMenuVirtualDom(visible).slice(1);
2413
2449
  return {
2450
+ menus: getAll(),
2414
2451
  menu,
2415
2452
  commands: [/* Menu.show */'Menu.showMenu', /* x */bounds.x, /* y */bounds.y, /* width */bounds.width, /* height */bounds.height, /* items */menu.items, /* level */menu.level, /* parentIndex */-1, /* dom */dom, /* mouseBlocking */mouseBlocking]
2416
2453
  };
2417
2454
  };
2418
2455
 
2419
- const getMenuHideCommands = async (restoreFocus = true) => {
2420
- if (state.menus.length === 0) {
2421
- return {
2422
- newMenus: [],
2423
- commands: []
2424
- };
2425
- }
2426
- state.menus = [];
2427
- return {
2428
- commands: [/* Menu.hide */'Menu.hide', /* restoreFocus */restoreFocus],
2429
- newMenus: []
2430
- };
2431
- };
2432
-
2433
- const menus = [MenuEntriesEdit, MenuEntriesFile, MenuEntriesGo, MenuEntriesHelp, MenuEntriesRun, MenuEntriesSelection, MenuEntriesTerminal, MenuEntriesTitleBar, MenuEntriesView, MenuEntriesOpenRecent];
2434
-
2435
- const getMenuIds = () => {
2436
- return menus.map(menu => menu.id);
2437
- };
2438
- const getMenuEntries = (id, platform) => {
2439
- const menu = menus.find(item => item.id === id);
2440
- if (!menu) {
2441
- return [];
2442
- }
2443
- return menu.getMenuEntries(platform);
2444
- };
2445
-
2446
2456
  const handleContextMenu = state => {
2447
2457
  return state;
2448
2458
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/menu-worker",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Menu Worker",
5
5
  "repository": {
6
6
  "type": "git",