handsontable 0.0.0-next-d7edb4b-20240927 → 0.0.0-next-517ec9c-20240930

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of handsontable might be problematic. Click here for more details.

package/helpers/mixed.js CHANGED
@@ -134,7 +134,7 @@ const domMessages = {
134
134
  function _injectProductInfo(key, element) {
135
135
  const hasValidType = !isEmpty(key);
136
136
  const isNonCommercial = typeof key === 'string' && key.toLowerCase() === 'non-commercial-and-evaluation';
137
- const hotVersion = "0.0.0-next-d7edb4b-20240927";
137
+ const hotVersion = "0.0.0-next-517ec9c-20240930";
138
138
  let keyValidityDate;
139
139
  let consoleMessageState = 'invalid';
140
140
  let domMessageState = 'invalid';
package/helpers/mixed.mjs CHANGED
@@ -124,7 +124,7 @@ const domMessages = {
124
124
  export function _injectProductInfo(key, element) {
125
125
  const hasValidType = !isEmpty(key);
126
126
  const isNonCommercial = typeof key === 'string' && key.toLowerCase() === 'non-commercial-and-evaluation';
127
- const hotVersion = "0.0.0-next-d7edb4b-20240927";
127
+ const hotVersion = "0.0.0-next-517ec9c-20240930";
128
128
  let keyValidityDate;
129
129
  let consoleMessageState = 'invalid';
130
130
  let domMessageState = 'invalid';
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "url": "https://github.com/handsontable/handsontable/issues"
11
11
  },
12
12
  "author": "Handsoncode <hello@handsontable.com>",
13
- "version": "0.0.0-next-d7edb4b-20240927",
13
+ "version": "0.0.0-next-517ec9c-20240930",
14
14
  "main": "index",
15
15
  "module": "index.mjs",
16
16
  "jsnext:main": "index.mjs",
@@ -100,7 +100,7 @@ function createKeyboardShortcutsCtrl(menu) {
100
100
  /**
101
101
  * Makes the specified context active.
102
102
  *
103
- * @param {string} contextName The context name.
103
+ * @param {string} [contextName] The context name.
104
104
  */
105
105
  function listen(contextName) {
106
106
  menu.hotMenu.getShortcutManager().setActiveContextName(_getContextName(contextName));
@@ -96,7 +96,7 @@ export function createKeyboardShortcutsCtrl(menu) {
96
96
  /**
97
97
  * Makes the specified context active.
98
98
  *
99
- * @param {string} contextName The context name.
99
+ * @param {string} [contextName] The context name.
100
100
  */
101
101
  function listen(contextName) {
102
102
  menu.hotMenu.getShortcutManager().setActiveContextName(_getContextName(contextName));
@@ -76,6 +76,7 @@ const SHORTCUTS_GROUP = PLUGIN_KEY;
76
76
  * :::
77
77
  */
78
78
  var _menuFocusNavigator = /*#__PURE__*/new WeakMap();
79
+ var _dropdownMenuTraces = /*#__PURE__*/new WeakMap();
79
80
  var _Filters_brand = /*#__PURE__*/new WeakSet();
80
81
  class Filters extends _base.BasePlugin {
81
82
  static get PLUGIN_KEY() {
@@ -139,6 +140,12 @@ class Filters extends _base.BasePlugin {
139
140
  * @type {MenuFocusNavigator|undefined}
140
141
  */
141
142
  _classPrivateFieldInitSpec(this, _menuFocusNavigator, void 0);
143
+ /**
144
+ * Traces the new menu instances to apply the focus navigation to the latest one.
145
+ *
146
+ * @type {WeakSet<Menu>}
147
+ */
148
+ _classPrivateFieldInitSpec(this, _dropdownMenuTraces, new WeakSet());
142
149
  this.hot.addHook('afterGetColHeader', (col, TH) => _assertClassBrand(_Filters_brand, this, _onAfterGetColHeader).call(this, col, TH));
143
150
  }
144
151
 
@@ -157,6 +164,7 @@ class Filters extends _base.BasePlugin {
157
164
  * Enables the plugin functionality for this Handsontable instance.
158
165
  */
159
166
  enablePlugin() {
167
+ var _this = this;
160
168
  if (this.enabled) {
161
169
  return;
162
170
  }
@@ -218,7 +226,13 @@ class Filters extends _base.BasePlugin {
218
226
  this.conditionUpdateObserver.addLocalHook('update', conditionState => _assertClassBrand(_Filters_brand, this, _updateComponents).call(this, conditionState));
219
227
  }
220
228
  this.components.forEach(component => component.show());
221
- this.addHook('afterDropdownMenuDefaultOptions', defaultOptions => _assertClassBrand(_Filters_brand, this, _onAfterDropdownMenuDefaultOptions).call(this, defaultOptions));
229
+ this.addHook('afterDropdownMenuDefaultOptions', function () {
230
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
231
+ args[_key] = arguments[_key];
232
+ }
233
+ return _assertClassBrand(_Filters_brand, _this, _onAfterDropdownMenuDefaultOptions).call(_this, ...args);
234
+ });
235
+ this.addHook('beforeDropdownMenuShow', () => _assertClassBrand(_Filters_brand, this, _onBeforeDropdownMenuShow).call(this));
222
236
  this.addHook('afterDropdownMenuShow', () => _assertClassBrand(_Filters_brand, this, _onAfterDropdownMenuShow).call(this));
223
237
  this.addHook('afterDropdownMenuHide', () => _assertClassBrand(_Filters_brand, this, _onAfterDropdownMenuHide).call(this));
224
238
  this.addHook('afterChange', changes => _assertClassBrand(_Filters_brand, this, _onAfterChange).call(this, changes));
@@ -229,15 +243,15 @@ class Filters extends _base.BasePlugin {
229
243
  this.dropdownMenuPlugin.enablePlugin();
230
244
  }
231
245
  if (!_classPrivateFieldGet(_menuFocusNavigator, this) && this.dropdownMenuPlugin.enabled) {
232
- const mainMenu = this.dropdownMenuPlugin.menu;
233
246
  const focusableItems = [
234
247
  // A fake menu item that once focused allows escaping from the focus navigation (using Tab keys)
235
248
  // to the menu navigation using arrow keys.
236
249
  {
237
250
  focus: () => {
238
- const menuNavigator = mainMenu.getNavigator();
251
+ const menu = _classPrivateFieldGet(_menuFocusNavigator, this).getMenu();
252
+ const menuNavigator = menu.getNavigator();
239
253
  const lastSelectedMenuItem = _classPrivateFieldGet(_menuFocusNavigator, this).getLastMenuPage();
240
- mainMenu.focus();
254
+ menu.focus();
241
255
  if (lastSelectedMenuItem > 0) {
242
256
  menuNavigator.setCurrentPage(lastSelectedMenuItem);
243
257
  } else {
@@ -248,7 +262,7 @@ class Filters extends _base.BasePlugin {
248
262
  let [, component] = _ref;
249
263
  return component.getElements();
250
264
  }).flat()];
251
- _classPrivateFieldSet(_menuFocusNavigator, this, (0, _focusController.createMenuFocusController)(mainMenu, focusableItems));
265
+ _classPrivateFieldSet(_menuFocusNavigator, this, (0, _focusController.createMenuFocusController)(this.dropdownMenuPlugin.menu, focusableItems));
252
266
  const forwardToFocusNavigation = event => {
253
267
  _classPrivateFieldGet(_menuFocusNavigator, this).listen();
254
268
  event.preventDefault();
@@ -706,8 +720,8 @@ class Filters extends _base.BasePlugin {
706
720
  return indexes;
707
721
  }
708
722
  const menu = this.dropdownMenuPlugin.menu;
709
- for (var _len = arguments.length, components = new Array(_len), _key = 0; _key < _len; _key++) {
710
- components[_key] = arguments[_key];
723
+ for (var _len2 = arguments.length, components = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
724
+ components[_key2] = arguments[_key2];
711
725
  }
712
726
  (0, _array.arrayEach)(components, component => {
713
727
  (0, _array.arrayEach)(menu.menuItems, (item, index) => {
@@ -734,8 +748,8 @@ class Filters extends _base.BasePlugin {
734
748
  const menu = this.dropdownMenuPlugin.menu;
735
749
  const hotMenu = menu.hotMenu;
736
750
  const hiddenRows = hotMenu.getPlugin('hiddenRows');
737
- for (var _len2 = arguments.length, components = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
738
- components[_key2 - 1] = arguments[_key2];
751
+ for (var _len3 = arguments.length, components = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
752
+ components[_key3 - 1] = arguments[_key3];
739
753
  }
740
754
  const indexes = this.getIndexesOfComponents(...components);
741
755
  if (visible) {
@@ -753,8 +767,8 @@ class Filters extends _base.BasePlugin {
753
767
  * @param {...BaseComponent} components List of components.
754
768
  */
755
769
  hideComponents() {
756
- for (var _len3 = arguments.length, components = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
757
- components[_key3] = arguments[_key3];
770
+ for (var _len4 = arguments.length, components = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
771
+ components[_key4] = arguments[_key4];
758
772
  }
759
773
  this.changeComponentsVisibility(false, ...components);
760
774
  }
@@ -766,8 +780,8 @@ class Filters extends _base.BasePlugin {
766
780
  * @param {...BaseComponent} components List of components.
767
781
  */
768
782
  showComponents() {
769
- for (var _len4 = arguments.length, components = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
770
- components[_key4] = arguments[_key4];
783
+ for (var _len5 = arguments.length, components = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
784
+ components[_key5] = arguments[_key5];
771
785
  }
772
786
  this.changeComponentsVisibility(true, ...components);
773
787
  }
@@ -814,6 +828,16 @@ function _onAfterDropdownMenuHide() {
814
828
  this.components.get('filter_by_condition').getSelectElement().closeOptions();
815
829
  this.components.get('filter_by_condition2').getSelectElement().closeOptions();
816
830
  }
831
+ /**
832
+ * Hooks applies the new dropdown menu instance to the focus navigator.
833
+ */
834
+ function _onBeforeDropdownMenuShow() {
835
+ const mainMenu = this.dropdownMenuPlugin.menu;
836
+ if (!_classPrivateFieldGet(_dropdownMenuTraces, this).has(mainMenu)) {
837
+ _classPrivateFieldGet(_menuFocusNavigator, this).setMenu(mainMenu);
838
+ }
839
+ _classPrivateFieldGet(_dropdownMenuTraces, this).add(mainMenu);
840
+ }
817
841
  /**
818
842
  * After dropdown menu default options listener.
819
843
  *
@@ -70,6 +70,7 @@ const SHORTCUTS_GROUP = PLUGIN_KEY;
70
70
  * :::
71
71
  */
72
72
  var _menuFocusNavigator = /*#__PURE__*/new WeakMap();
73
+ var _dropdownMenuTraces = /*#__PURE__*/new WeakMap();
73
74
  var _Filters_brand = /*#__PURE__*/new WeakSet();
74
75
  export class Filters extends BasePlugin {
75
76
  static get PLUGIN_KEY() {
@@ -133,6 +134,12 @@ export class Filters extends BasePlugin {
133
134
  * @type {MenuFocusNavigator|undefined}
134
135
  */
135
136
  _classPrivateFieldInitSpec(this, _menuFocusNavigator, void 0);
137
+ /**
138
+ * Traces the new menu instances to apply the focus navigation to the latest one.
139
+ *
140
+ * @type {WeakSet<Menu>}
141
+ */
142
+ _classPrivateFieldInitSpec(this, _dropdownMenuTraces, new WeakSet());
136
143
  this.hot.addHook('afterGetColHeader', (col, TH) => _assertClassBrand(_Filters_brand, this, _onAfterGetColHeader).call(this, col, TH));
137
144
  }
138
145
 
@@ -151,6 +158,7 @@ export class Filters extends BasePlugin {
151
158
  * Enables the plugin functionality for this Handsontable instance.
152
159
  */
153
160
  enablePlugin() {
161
+ var _this = this;
154
162
  if (this.enabled) {
155
163
  return;
156
164
  }
@@ -212,7 +220,13 @@ export class Filters extends BasePlugin {
212
220
  this.conditionUpdateObserver.addLocalHook('update', conditionState => _assertClassBrand(_Filters_brand, this, _updateComponents).call(this, conditionState));
213
221
  }
214
222
  this.components.forEach(component => component.show());
215
- this.addHook('afterDropdownMenuDefaultOptions', defaultOptions => _assertClassBrand(_Filters_brand, this, _onAfterDropdownMenuDefaultOptions).call(this, defaultOptions));
223
+ this.addHook('afterDropdownMenuDefaultOptions', function () {
224
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
225
+ args[_key] = arguments[_key];
226
+ }
227
+ return _assertClassBrand(_Filters_brand, _this, _onAfterDropdownMenuDefaultOptions).call(_this, ...args);
228
+ });
229
+ this.addHook('beforeDropdownMenuShow', () => _assertClassBrand(_Filters_brand, this, _onBeforeDropdownMenuShow).call(this));
216
230
  this.addHook('afterDropdownMenuShow', () => _assertClassBrand(_Filters_brand, this, _onAfterDropdownMenuShow).call(this));
217
231
  this.addHook('afterDropdownMenuHide', () => _assertClassBrand(_Filters_brand, this, _onAfterDropdownMenuHide).call(this));
218
232
  this.addHook('afterChange', changes => _assertClassBrand(_Filters_brand, this, _onAfterChange).call(this, changes));
@@ -223,15 +237,15 @@ export class Filters extends BasePlugin {
223
237
  this.dropdownMenuPlugin.enablePlugin();
224
238
  }
225
239
  if (!_classPrivateFieldGet(_menuFocusNavigator, this) && this.dropdownMenuPlugin.enabled) {
226
- const mainMenu = this.dropdownMenuPlugin.menu;
227
240
  const focusableItems = [
228
241
  // A fake menu item that once focused allows escaping from the focus navigation (using Tab keys)
229
242
  // to the menu navigation using arrow keys.
230
243
  {
231
244
  focus: () => {
232
- const menuNavigator = mainMenu.getNavigator();
245
+ const menu = _classPrivateFieldGet(_menuFocusNavigator, this).getMenu();
246
+ const menuNavigator = menu.getNavigator();
233
247
  const lastSelectedMenuItem = _classPrivateFieldGet(_menuFocusNavigator, this).getLastMenuPage();
234
- mainMenu.focus();
248
+ menu.focus();
235
249
  if (lastSelectedMenuItem > 0) {
236
250
  menuNavigator.setCurrentPage(lastSelectedMenuItem);
237
251
  } else {
@@ -242,7 +256,7 @@ export class Filters extends BasePlugin {
242
256
  let [, component] = _ref;
243
257
  return component.getElements();
244
258
  }).flat()];
245
- _classPrivateFieldSet(_menuFocusNavigator, this, createMenuFocusController(mainMenu, focusableItems));
259
+ _classPrivateFieldSet(_menuFocusNavigator, this, createMenuFocusController(this.dropdownMenuPlugin.menu, focusableItems));
246
260
  const forwardToFocusNavigation = event => {
247
261
  _classPrivateFieldGet(_menuFocusNavigator, this).listen();
248
262
  event.preventDefault();
@@ -700,8 +714,8 @@ export class Filters extends BasePlugin {
700
714
  return indexes;
701
715
  }
702
716
  const menu = this.dropdownMenuPlugin.menu;
703
- for (var _len = arguments.length, components = new Array(_len), _key = 0; _key < _len; _key++) {
704
- components[_key] = arguments[_key];
717
+ for (var _len2 = arguments.length, components = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
718
+ components[_key2] = arguments[_key2];
705
719
  }
706
720
  arrayEach(components, component => {
707
721
  arrayEach(menu.menuItems, (item, index) => {
@@ -728,8 +742,8 @@ export class Filters extends BasePlugin {
728
742
  const menu = this.dropdownMenuPlugin.menu;
729
743
  const hotMenu = menu.hotMenu;
730
744
  const hiddenRows = hotMenu.getPlugin('hiddenRows');
731
- for (var _len2 = arguments.length, components = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
732
- components[_key2 - 1] = arguments[_key2];
745
+ for (var _len3 = arguments.length, components = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
746
+ components[_key3 - 1] = arguments[_key3];
733
747
  }
734
748
  const indexes = this.getIndexesOfComponents(...components);
735
749
  if (visible) {
@@ -747,8 +761,8 @@ export class Filters extends BasePlugin {
747
761
  * @param {...BaseComponent} components List of components.
748
762
  */
749
763
  hideComponents() {
750
- for (var _len3 = arguments.length, components = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
751
- components[_key3] = arguments[_key3];
764
+ for (var _len4 = arguments.length, components = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
765
+ components[_key4] = arguments[_key4];
752
766
  }
753
767
  this.changeComponentsVisibility(false, ...components);
754
768
  }
@@ -760,8 +774,8 @@ export class Filters extends BasePlugin {
760
774
  * @param {...BaseComponent} components List of components.
761
775
  */
762
776
  showComponents() {
763
- for (var _len4 = arguments.length, components = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
764
- components[_key4] = arguments[_key4];
777
+ for (var _len5 = arguments.length, components = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
778
+ components[_key5] = arguments[_key5];
765
779
  }
766
780
  this.changeComponentsVisibility(true, ...components);
767
781
  }
@@ -807,6 +821,16 @@ function _onAfterDropdownMenuHide() {
807
821
  this.components.get('filter_by_condition').getSelectElement().closeOptions();
808
822
  this.components.get('filter_by_condition2').getSelectElement().closeOptions();
809
823
  }
824
+ /**
825
+ * Hooks applies the new dropdown menu instance to the focus navigator.
826
+ */
827
+ function _onBeforeDropdownMenuShow() {
828
+ const mainMenu = this.dropdownMenuPlugin.menu;
829
+ if (!_classPrivateFieldGet(_dropdownMenuTraces, this).has(mainMenu)) {
830
+ _classPrivateFieldGet(_menuFocusNavigator, this).setMenu(mainMenu);
831
+ }
832
+ _classPrivateFieldGet(_dropdownMenuTraces, this).add(mainMenu);
833
+ }
810
834
  /**
811
835
  * After dropdown menu default options listener.
812
836
  *
@@ -32,10 +32,11 @@ function createMenuFocusController(mainMenu, menuItems) {
32
32
  * into the focus mode triggered by the TAB or SHIFT+TAB keys).
33
33
  */
34
34
  let lastSelectedMenuItem = -1;
35
+ let menuInstance;
35
36
  const focusNavigator = (0, _focusNavigator.createFocusNavigator)(menuItems);
36
37
  const updateNavigatorPosition = element => () => {
37
- if (mainMenu.isOpened()) {
38
- mainMenu.getKeyboardShortcutsCtrl().listen(SHORTCUTS_MENU_CONTEXT);
38
+ if (menuInstance.isOpened()) {
39
+ menuInstance.getKeyboardShortcutsCtrl().listen(SHORTCUTS_MENU_CONTEXT);
39
40
  }
40
41
  focusNavigator.setCurrentPage(menuItems.indexOf(element));
41
42
  };
@@ -48,11 +49,7 @@ function createMenuFocusController(mainMenu, menuItems) {
48
49
  element.addLocalHook('afterClose', updateNavigatorPosition(element));
49
50
  }
50
51
  });
51
- mainMenu.addLocalHook('afterSelectionChange', selectedItem => {
52
- if (!selectedItem.key.startsWith('filter_')) {
53
- focusNavigator.clear();
54
- }
55
- });
52
+ setMenu(mainMenu);
56
53
 
57
54
  /**
58
55
  * Extends the menu and submenus with new keyboard shortcuts.
@@ -60,7 +57,7 @@ function createMenuFocusController(mainMenu, menuItems) {
60
57
  * @param {*} menu The menu (as main menu or submenu) instance.
61
58
  */
62
59
  function addKeyboardShortcuts(menu) {
63
- const mainMenuShortcutsCtrl = mainMenu.getKeyboardShortcutsCtrl();
60
+ const mainMenuShortcutsCtrl = menuInstance.getKeyboardShortcutsCtrl();
64
61
  const currentMenuShortcutsCtrl = menu.getKeyboardShortcutsCtrl();
65
62
  focusNavigator.clear();
66
63
  currentMenuShortcutsCtrl.addCustomShortcuts([{
@@ -79,7 +76,7 @@ function createMenuFocusController(mainMenu, menuItems) {
79
76
  mainMenuShortcutsCtrl.addCustomShortcuts([{
80
77
  keys: [['Tab'], ['Shift', 'Tab']],
81
78
  callback: event => {
82
- const menuNavigator = mainMenu.getNavigator();
79
+ const menuNavigator = menuInstance.getNavigator();
83
80
  if (menuNavigator.getCurrentPage() > -1) {
84
81
  lastSelectedMenuItem = menuNavigator.getCurrentPage();
85
82
  }
@@ -93,7 +90,7 @@ function createMenuFocusController(mainMenu, menuItems) {
93
90
  }, {
94
91
  keys: [['Escape']],
95
92
  callback: () => {
96
- mainMenu.close();
93
+ menuInstance.close();
97
94
  }
98
95
  }, {
99
96
  keys: [['Enter'], ['Space']],
@@ -114,16 +111,39 @@ function createMenuFocusController(mainMenu, menuItems) {
114
111
  }
115
112
  }], SHORTCUTS_MENU_CONTEXT);
116
113
  }
117
- mainMenu.addLocalHook('afterSubmenuOpen', addKeyboardShortcuts);
118
- mainMenu.addLocalHook('afterOpen', addKeyboardShortcuts);
119
114
 
120
115
  /**
121
116
  * Focuses the menu and switches its shortcut context to that one which controls
122
117
  * the focus navigation.
123
118
  */
124
119
  function listen() {
125
- mainMenu.focus();
126
- mainMenu.getKeyboardShortcutsCtrl().listen(SHORTCUTS_MENU_CONTEXT);
120
+ menuInstance.focus();
121
+ menuInstance.getKeyboardShortcutsCtrl().listen(SHORTCUTS_MENU_CONTEXT);
122
+ }
123
+
124
+ /**
125
+ * Applies the focus controller to the new menu instance.
126
+ *
127
+ * @param {Menu} menu The new menu instance.
128
+ */
129
+ function setMenu(menu) {
130
+ menu.addLocalHook('afterSelectionChange', selectedItem => {
131
+ if (!selectedItem.key.startsWith('filter_')) {
132
+ focusNavigator.clear();
133
+ }
134
+ });
135
+ menu.addLocalHook('afterSubmenuOpen', addKeyboardShortcuts);
136
+ menu.addLocalHook('afterOpen', addKeyboardShortcuts);
137
+ menuInstance = menu;
138
+ }
139
+
140
+ /**
141
+ * Retrieves the current menu instance.
142
+ *
143
+ * @returns {Menu} The current menu instance.
144
+ */
145
+ function getMenu() {
146
+ return menuInstance;
127
147
  }
128
148
 
129
149
  /**
@@ -137,6 +157,8 @@ function createMenuFocusController(mainMenu, menuItems) {
137
157
  return {
138
158
  ...focusNavigator,
139
159
  listen,
160
+ setMenu,
161
+ getMenu,
140
162
  getLastMenuPage
141
163
  };
142
164
  }
@@ -28,10 +28,11 @@ export function createMenuFocusController(mainMenu, menuItems) {
28
28
  * into the focus mode triggered by the TAB or SHIFT+TAB keys).
29
29
  */
30
30
  let lastSelectedMenuItem = -1;
31
+ let menuInstance;
31
32
  const focusNavigator = createFocusNavigator(menuItems);
32
33
  const updateNavigatorPosition = element => () => {
33
- if (mainMenu.isOpened()) {
34
- mainMenu.getKeyboardShortcutsCtrl().listen(SHORTCUTS_MENU_CONTEXT);
34
+ if (menuInstance.isOpened()) {
35
+ menuInstance.getKeyboardShortcutsCtrl().listen(SHORTCUTS_MENU_CONTEXT);
35
36
  }
36
37
  focusNavigator.setCurrentPage(menuItems.indexOf(element));
37
38
  };
@@ -44,11 +45,7 @@ export function createMenuFocusController(mainMenu, menuItems) {
44
45
  element.addLocalHook('afterClose', updateNavigatorPosition(element));
45
46
  }
46
47
  });
47
- mainMenu.addLocalHook('afterSelectionChange', selectedItem => {
48
- if (!selectedItem.key.startsWith('filter_')) {
49
- focusNavigator.clear();
50
- }
51
- });
48
+ setMenu(mainMenu);
52
49
 
53
50
  /**
54
51
  * Extends the menu and submenus with new keyboard shortcuts.
@@ -56,7 +53,7 @@ export function createMenuFocusController(mainMenu, menuItems) {
56
53
  * @param {*} menu The menu (as main menu or submenu) instance.
57
54
  */
58
55
  function addKeyboardShortcuts(menu) {
59
- const mainMenuShortcutsCtrl = mainMenu.getKeyboardShortcutsCtrl();
56
+ const mainMenuShortcutsCtrl = menuInstance.getKeyboardShortcutsCtrl();
60
57
  const currentMenuShortcutsCtrl = menu.getKeyboardShortcutsCtrl();
61
58
  focusNavigator.clear();
62
59
  currentMenuShortcutsCtrl.addCustomShortcuts([{
@@ -75,7 +72,7 @@ export function createMenuFocusController(mainMenu, menuItems) {
75
72
  mainMenuShortcutsCtrl.addCustomShortcuts([{
76
73
  keys: [['Tab'], ['Shift', 'Tab']],
77
74
  callback: event => {
78
- const menuNavigator = mainMenu.getNavigator();
75
+ const menuNavigator = menuInstance.getNavigator();
79
76
  if (menuNavigator.getCurrentPage() > -1) {
80
77
  lastSelectedMenuItem = menuNavigator.getCurrentPage();
81
78
  }
@@ -89,7 +86,7 @@ export function createMenuFocusController(mainMenu, menuItems) {
89
86
  }, {
90
87
  keys: [['Escape']],
91
88
  callback: () => {
92
- mainMenu.close();
89
+ menuInstance.close();
93
90
  }
94
91
  }, {
95
92
  keys: [['Enter'], ['Space']],
@@ -110,16 +107,39 @@ export function createMenuFocusController(mainMenu, menuItems) {
110
107
  }
111
108
  }], SHORTCUTS_MENU_CONTEXT);
112
109
  }
113
- mainMenu.addLocalHook('afterSubmenuOpen', addKeyboardShortcuts);
114
- mainMenu.addLocalHook('afterOpen', addKeyboardShortcuts);
115
110
 
116
111
  /**
117
112
  * Focuses the menu and switches its shortcut context to that one which controls
118
113
  * the focus navigation.
119
114
  */
120
115
  function listen() {
121
- mainMenu.focus();
122
- mainMenu.getKeyboardShortcutsCtrl().listen(SHORTCUTS_MENU_CONTEXT);
116
+ menuInstance.focus();
117
+ menuInstance.getKeyboardShortcutsCtrl().listen(SHORTCUTS_MENU_CONTEXT);
118
+ }
119
+
120
+ /**
121
+ * Applies the focus controller to the new menu instance.
122
+ *
123
+ * @param {Menu} menu The new menu instance.
124
+ */
125
+ function setMenu(menu) {
126
+ menu.addLocalHook('afterSelectionChange', selectedItem => {
127
+ if (!selectedItem.key.startsWith('filter_')) {
128
+ focusNavigator.clear();
129
+ }
130
+ });
131
+ menu.addLocalHook('afterSubmenuOpen', addKeyboardShortcuts);
132
+ menu.addLocalHook('afterOpen', addKeyboardShortcuts);
133
+ menuInstance = menu;
134
+ }
135
+
136
+ /**
137
+ * Retrieves the current menu instance.
138
+ *
139
+ * @returns {Menu} The current menu instance.
140
+ */
141
+ function getMenu() {
142
+ return menuInstance;
123
143
  }
124
144
 
125
145
  /**
@@ -133,6 +153,8 @@ export function createMenuFocusController(mainMenu, menuItems) {
133
153
  return {
134
154
  ...focusNavigator,
135
155
  listen,
156
+ setMenu,
157
+ getMenu,
136
158
  getLastMenuPage
137
159
  };
138
160
  }