openproject-primer_view_components 0.95.0 → 0.97.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.
Files changed (183) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/app/assets/javascripts/primer_view_components.js +11 -1
  4. data/app/assets/javascripts/primer_view_components.js.map +1 -1
  5. data/app/assets/styles/primer_view_components.css +1 -1
  6. data/app/assets/styles/primer_view_components.css.map +1 -1
  7. data/app/components/primer/alpha/action_bar.css +1 -1
  8. data/app/components/primer/alpha/action_bar.css.map +1 -1
  9. data/app/components/primer/alpha/action_list/item.rb +7 -2
  10. data/app/components/primer/alpha/action_list.css +1 -1
  11. data/app/components/primer/alpha/action_list.css.json +16 -27
  12. data/app/components/primer/alpha/action_list.css.map +1 -1
  13. data/app/components/primer/alpha/action_list.html.erb +1 -5
  14. data/app/components/primer/alpha/action_list.pcss +55 -81
  15. data/app/components/primer/alpha/action_list.rb +9 -7
  16. data/app/components/primer/alpha/action_menu/action_menu_element.d.ts +6 -0
  17. data/app/components/primer/alpha/action_menu/action_menu_element.js +239 -84
  18. data/app/components/primer/alpha/action_menu/action_menu_element.ts +261 -81
  19. data/app/components/primer/alpha/action_menu/action_menu_focus_zone_stack.d.ts +4 -1
  20. data/app/components/primer/alpha/action_menu/action_menu_focus_zone_stack.js +38 -14
  21. data/app/components/primer/alpha/action_menu/action_menu_focus_zone_stack.ts +42 -13
  22. data/app/components/primer/alpha/action_menu/menu.html.erb +27 -19
  23. data/app/components/primer/alpha/action_menu/menu.rb +7 -0
  24. data/app/components/primer/alpha/action_menu/menu_loader.d.ts +21 -0
  25. data/app/components/primer/alpha/action_menu/menu_loader.js +221 -0
  26. data/app/components/primer/alpha/action_menu/menu_loader.ts +269 -0
  27. data/app/components/primer/alpha/action_menu/primary_menu.rb +15 -0
  28. data/app/components/primer/alpha/action_menu.rb +55 -0
  29. data/app/components/primer/alpha/auto_complete.css +1 -1
  30. data/app/components/primer/alpha/auto_complete.css.map +1 -1
  31. data/app/components/primer/alpha/banner.css +1 -1
  32. data/app/components/primer/alpha/banner.css.map +1 -1
  33. data/app/components/primer/alpha/button_marketing.css +1 -1
  34. data/app/components/primer/alpha/button_marketing.css.map +1 -1
  35. data/app/components/primer/alpha/dialog.css +1 -1
  36. data/app/components/primer/alpha/dialog.css.map +1 -1
  37. data/app/components/primer/alpha/dropdown/menu.rb +1 -1
  38. data/app/components/primer/alpha/dropdown.css +1 -1
  39. data/app/components/primer/alpha/dropdown.css.json +1 -1
  40. data/app/components/primer/alpha/dropdown.css.map +1 -1
  41. data/app/components/primer/alpha/layout.css +1 -1
  42. data/app/components/primer/alpha/layout.css.json +3 -3
  43. data/app/components/primer/alpha/layout.css.map +1 -1
  44. data/app/components/primer/alpha/menu.css +1 -1
  45. data/app/components/primer/alpha/menu.css.json +3 -3
  46. data/app/components/primer/alpha/menu.css.map +1 -1
  47. data/app/components/primer/alpha/overlay.css +1 -1
  48. data/app/components/primer/alpha/overlay.css.map +1 -1
  49. data/app/components/primer/alpha/segmented_control.css +1 -1
  50. data/app/components/primer/alpha/segmented_control.css.json +1 -1
  51. data/app/components/primer/alpha/segmented_control.css.map +1 -1
  52. data/app/components/primer/alpha/select_panel.css +1 -1
  53. data/app/components/primer/alpha/select_panel.css.map +1 -1
  54. data/app/components/primer/alpha/skeleton_box.css +1 -1
  55. data/app/components/primer/alpha/skeleton_box.css.map +1 -1
  56. data/app/components/primer/alpha/stack.css +1 -1
  57. data/app/components/primer/alpha/stack.css.map +1 -1
  58. data/app/components/primer/alpha/stack_item.css +1 -1
  59. data/app/components/primer/alpha/stack_item.css.map +1 -1
  60. data/app/components/primer/alpha/tab_nav.css +1 -1
  61. data/app/components/primer/alpha/tab_nav.css.map +1 -1
  62. data/app/components/primer/alpha/text_field.css +1 -1
  63. data/app/components/primer/alpha/text_field.css.map +1 -1
  64. data/app/components/primer/alpha/toggle_switch.css +1 -1
  65. data/app/components/primer/alpha/toggle_switch.css.map +1 -1
  66. data/app/components/primer/alpha/tree_view.css +1 -1
  67. data/app/components/primer/alpha/tree_view.css.json +3 -3
  68. data/app/components/primer/alpha/tree_view.css.map +1 -1
  69. data/app/components/primer/alpha/underline_nav.css +1 -1
  70. data/app/components/primer/alpha/underline_nav.css.map +1 -1
  71. data/app/components/primer/beta/border_box.css +1 -1
  72. data/app/components/primer/beta/border_box.css.json +5 -5
  73. data/app/components/primer/beta/border_box.css.map +1 -1
  74. data/app/components/primer/beta/button.css +1 -1
  75. data/app/components/primer/beta/button.css.map +1 -1
  76. data/app/components/primer/beta/button.pcss +97 -0
  77. data/app/components/primer/beta/button.rb +15 -3
  78. data/app/components/primer/beta/counter.css +1 -1
  79. data/app/components/primer/beta/counter.css.map +1 -1
  80. data/app/components/primer/beta/flash.css +1 -1
  81. data/app/components/primer/beta/flash.css.map +1 -1
  82. data/app/components/primer/beta/link.css +1 -1
  83. data/app/components/primer/beta/link.css.json +1 -1
  84. data/app/components/primer/beta/link.css.map +1 -1
  85. data/app/components/primer/beta/popover.css +1 -1
  86. data/app/components/primer/beta/popover.css.map +1 -1
  87. data/app/components/primer/beta/progress_bar.css +1 -1
  88. data/app/components/primer/beta/progress_bar.css.map +1 -1
  89. data/app/components/primer/beta/relative_time.rb +7 -1
  90. data/app/components/primer/beta/state.css +1 -1
  91. data/app/components/primer/beta/state.css.json +2 -2
  92. data/app/components/primer/beta/state.css.map +1 -1
  93. data/app/components/primer/beta/timeline_item.css +1 -1
  94. data/app/components/primer/beta/timeline_item.css.map +1 -1
  95. data/app/components/primer/open_project/border_grid.css +1 -1
  96. data/app/components/primer/open_project/border_grid.css.map +1 -1
  97. data/app/components/primer/open_project/color_field.css +1 -1
  98. data/app/components/primer/open_project/color_field.css.map +1 -1
  99. data/app/components/primer/open_project/inline_message.css +1 -1
  100. data/app/components/primer/open_project/inline_message.css.map +1 -1
  101. data/app/components/primer/open_project/input_group.css +1 -1
  102. data/app/components/primer/open_project/input_group.css.map +1 -1
  103. data/app/components/primer/open_project/keybinding_hint/chords.d.ts +5 -0
  104. data/app/components/primer/open_project/keybinding_hint/chords.js +29 -0
  105. data/app/components/primer/open_project/keybinding_hint/chords.ts +38 -0
  106. data/app/components/primer/open_project/keybinding_hint/key_names.d.ts +16 -0
  107. data/app/components/primer/open_project/keybinding_hint/key_names.js +107 -0
  108. data/app/components/primer/open_project/keybinding_hint/key_names.ts +116 -0
  109. data/app/components/primer/open_project/keybinding_hint/localized_names.d.ts +22 -0
  110. data/app/components/primer/open_project/keybinding_hint/localized_names.js +47 -0
  111. data/app/components/primer/open_project/keybinding_hint/localized_names.ts +71 -0
  112. data/app/components/primer/open_project/keybinding_hint/names.rb +92 -0
  113. data/app/components/primer/open_project/keybinding_hint/names_from_scope.d.ts +21 -0
  114. data/app/components/primer/open_project/keybinding_hint/names_from_scope.js +81 -0
  115. data/app/components/primer/open_project/keybinding_hint/names_from_scope.ts +96 -0
  116. data/app/components/primer/open_project/keybinding_hint/platform.d.ts +10 -0
  117. data/app/components/primer/open_project/keybinding_hint/platform.js +24 -0
  118. data/app/components/primer/open_project/keybinding_hint/platform.ts +34 -0
  119. data/app/components/primer/open_project/keybinding_hint/platform_override.d.ts +2 -0
  120. data/app/components/primer/open_project/keybinding_hint/platform_override.js +4 -0
  121. data/app/components/primer/open_project/keybinding_hint/platform_override.ts +7 -0
  122. data/app/components/primer/open_project/keybinding_hint.css +1 -0
  123. data/app/components/primer/open_project/keybinding_hint.css.json +10 -0
  124. data/app/components/primer/open_project/keybinding_hint.css.map +1 -0
  125. data/app/components/primer/open_project/keybinding_hint.html.erb +4 -0
  126. data/app/components/primer/open_project/keybinding_hint.pcss +65 -0
  127. data/app/components/primer/open_project/keybinding_hint.rb +112 -0
  128. data/app/components/primer/open_project/keybinding_hint_element.d.ts +31 -0
  129. data/app/components/primer/open_project/keybinding_hint_element.js +183 -0
  130. data/app/components/primer/open_project/keybinding_hint_element.ts +152 -0
  131. data/app/components/primer/open_project/page_header.css +1 -1
  132. data/app/components/primer/open_project/page_header.css.json +2 -2
  133. data/app/components/primer/open_project/page_header.css.map +1 -1
  134. data/app/components/primer/open_project/pagination.css +1 -1
  135. data/app/components/primer/open_project/pagination.css.json +1 -1
  136. data/app/components/primer/open_project/pagination.css.map +1 -1
  137. data/app/components/primer/open_project/sub_header.css +1 -1
  138. data/app/components/primer/open_project/sub_header.css.map +1 -1
  139. data/app/components/primer/primer.d.ts +1 -0
  140. data/app/components/primer/primer.js +1 -0
  141. data/app/components/primer/primer.pcss +1 -0
  142. data/app/components/primer/primer.ts +1 -0
  143. data/app/components/primer/truncate.css +1 -1
  144. data/app/components/primer/truncate.css.json +3 -4
  145. data/app/components/primer/truncate.css.map +1 -1
  146. data/app/controllers/primer/view_components/action_menu_controller.rb +35 -0
  147. data/app/views/primer/view_components/action_menu/deferred.html.erb +25 -11
  148. data/app/views/primer/view_components/action_menu/deferred_form.html.erb +10 -0
  149. data/app/views/primer/view_components/action_menu/deferred_preload.html.erb +7 -1
  150. data/config/locales/en.yml +179 -0
  151. data/config/routes.rb +1 -0
  152. data/lib/primer/accessibility.rb +1 -2
  153. data/lib/primer/classify.rb +1 -2
  154. data/lib/primer/view_components/version.rb +1 -1
  155. data/previews/primer/alpha/action_list_preview.rb +46 -1
  156. data/previews/primer/alpha/action_menu_preview/deferred_refresh.html.erb +34 -0
  157. data/previews/primer/alpha/action_menu_preview/deferred_refresh_form.html.erb +9 -0
  158. data/previews/primer/alpha/action_menu_preview/sub_menus.html.erb +1 -1
  159. data/previews/primer/alpha/action_menu_preview.rb +19 -2
  160. data/previews/primer/open_project/keybinding_hint_preview/full_format.html.erb +3 -0
  161. data/previews/primer/open_project/keybinding_hint_preview/in_action_list.html.erb +12 -0
  162. data/previews/primer/open_project/keybinding_hint_preview/in_button.html.erb +24 -0
  163. data/previews/primer/open_project/keybinding_hint_preview/platforms.html.erb +8 -0
  164. data/previews/primer/open_project/keybinding_hint_preview/playground.html.erb +4 -0
  165. data/previews/primer/open_project/keybinding_hint_preview/prose.html.erb +3 -0
  166. data/previews/primer/open_project/keybinding_hint_preview/schemes.html.erb +6 -0
  167. data/previews/primer/open_project/keybinding_hint_preview/sequence.html.erb +1 -0
  168. data/previews/primer/open_project/keybinding_hint_preview/sizes.html.erb +4 -0
  169. data/previews/primer/open_project/keybinding_hint_preview.rb +71 -0
  170. data/static/arguments.json +55 -3
  171. data/static/audited_at.json +1 -0
  172. data/static/classes.json +15 -3
  173. data/static/classnames.cjs +5 -1
  174. data/static/classnames.js +5 -1
  175. data/static/constants.json +35 -0
  176. data/static/info_arch.json +255 -10
  177. data/static/previews.json +177 -0
  178. data/static/statuses.json +1 -0
  179. metadata +45 -5
  180. data/app/components/primer/alpha/text_field.css.json +0 -134
  181. data/app/components/primer/alpha/toggle_switch.css.json +0 -40
  182. data/app/components/primer/alpha/underline_nav.css.json +0 -26
  183. data/app/components/primer/beta/button.css.json +0 -86
@@ -4,18 +4,18 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
7
12
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
13
  if (kind === "m") throw new TypeError("Private method is not writable");
9
14
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
15
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
16
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
17
  };
13
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
14
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
15
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
16
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
17
- };
18
- var _ActionMenuElement_instances, _a, _ActionMenuElement_abortController, _ActionMenuElement_originalLabel, _ActionMenuElement_inputName, _ActionMenuElement_invokerBeingClicked, _ActionMenuElement_intersectionObserver, _ActionMenuElement_focusZoneStack, _ActionMenuElement_updateLevels, _ActionMenuElement_softDisableItems, _ActionMenuElement_potentiallyDisallowActivation, _ActionMenuElement_isAnchorActivationViaSpace, _ActionMenuElement_isClipboardActivationViaKeyboard, _ActionMenuElement_isActivation, _ActionMenuElement_handleItemKeyboardEvent, _ActionMenuElement_handleToggleEvent, _ActionMenuElement_handleInvokerActivated, _ActionMenuElement_handleDialogItemActivated, _ActionMenuElement_handleItemActivated, _ActionMenuElement_handleIncludeFragmentReplaced, _ActionMenuElement_handleFocusOut, _ActionMenuElement_show, _ActionMenuElement_hide, _ActionMenuElement_isOpen, _ActionMenuElement_setDynamicLabel, _ActionMenuElement_updateInput, _ActionMenuElement_firstItem_get, _ActionMenuElement_subMenuForItem, _ActionMenuElement_itemForSubMenu;
18
+ var _ActionMenuElement_instances, _a, _ActionMenuElement_abortController, _ActionMenuElement_originalLabel, _ActionMenuElement_inputName, _ActionMenuElement_invokerBeingClicked, _ActionMenuElement_intersectionObserver, _ActionMenuElement_focusZoneStack, _ActionMenuElement_loader, _ActionMenuElement_scrollUpdater, _ActionMenuElement_bindHostListeners, _ActionMenuElement_setupSubMenuLoading, _ActionMenuElement_observeInvokerPosition, _ActionMenuElement_updateLevels, _ActionMenuElement_keepOpenWhileLoading, _ActionMenuElement_pruneFocusZones, _ActionMenuElement_softDisableItems, _ActionMenuElement_potentiallyDisallowActivation, _ActionMenuElement_isAnchorActivationViaSpace, _ActionMenuElement_isClipboardActivationViaKeyboard, _ActionMenuElement_isActivation, _ActionMenuElement_handleItemKeyboardEvent, _ActionMenuElement_handleBeforeToggleEvent, _ActionMenuElement_handleToggleEvent, _ActionMenuElement_focusLostTo, _ActionMenuElement_toggledMenu, _ActionMenuElement_handleInvokerActivated, _ActionMenuElement_handleDialogItemActivated, _ActionMenuElement_handleItemActivated, _ActionMenuElement_handleIncludeFragmentReplaced, _ActionMenuElement_focusLoadedMenu, _ActionMenuElement_restoreTabStop, _ActionMenuElement_handleFocusOut, _ActionMenuElement_show, _ActionMenuElement_hide, _ActionMenuElement_isOpen, _ActionMenuElement_setDynamicLabel, _ActionMenuElement_updateInput, _ActionMenuElement_firstItem_get, _ActionMenuElement_subMenuForItem, _ActionMenuElement_itemForSubMenu;
19
19
  var ActionMenuElement_1;
20
20
  import { controller, target } from '@github/catalyst';
21
21
  import '@oddbird/popover-polyfill';
@@ -23,9 +23,10 @@ import AnchoredPositionElement from '../../anchored_position';
23
23
  import { observeMutationsUntilConditionMet } from '../../utils';
24
24
  import { ActionMenuFocusZoneStack } from './action_menu_focus_zone_stack';
25
25
  import { ClipboardCopyElement } from '@github/clipboard-copy-element';
26
+ import { MenuLoader } from './menu_loader';
26
27
  let ActionMenuElement = ActionMenuElement_1 = _a = class ActionMenuElement extends HTMLElement {
27
28
  constructor() {
28
- super(...arguments);
29
+ super();
29
30
  _ActionMenuElement_instances.add(this);
30
31
  _ActionMenuElement_abortController.set(this, void 0);
31
32
  _ActionMenuElement_originalLabel.set(this, '');
@@ -33,6 +34,55 @@ let ActionMenuElement = ActionMenuElement_1 = _a = class ActionMenuElement exten
33
34
  _ActionMenuElement_invokerBeingClicked.set(this, false);
34
35
  _ActionMenuElement_intersectionObserver.set(this, void 0);
35
36
  _ActionMenuElement_focusZoneStack.set(this, void 0);
37
+ // Loads a deferred primary menu's items; see MenuLoader
38
+ _ActionMenuElement_loader.set(this, void 0);
39
+ _ActionMenuElement_scrollUpdater.set(this, () => {
40
+ if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isOpen).call(this)) {
41
+ this.overlay?.update();
42
+ }
43
+ });
44
+ // Never disconnected: it observes the element's own subtree, so it keeps
45
+ // working while the element is detached. A local, not a field: the
46
+ // registration keeps it alive as long as the element is.
47
+ __classPrivateFieldSet(this, _ActionMenuElement_loader, new MenuLoader({
48
+ element: this,
49
+ body: () => this.overlayBody,
50
+ template: () => this.loaderTemplate,
51
+ itemSelector: ActionMenuElement_1.menuItemSelectors.join(','),
52
+ isOpen: () => __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isOpen).call(this),
53
+ onLoadStart: (fragment, keepOpen) => {
54
+ // The response decides the form field name
55
+ __classPrivateFieldSet(this, _ActionMenuElement_inputName, '', "f");
56
+ if (keepOpen)
57
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_keepOpenWhileLoading).call(this, fragment);
58
+ },
59
+ onLoaded: () => __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_handleIncludeFragmentReplaced).call(this),
60
+ }), "f");
61
+ const observer = new MutationObserver(records => {
62
+ // A replaced overlay may have taken open sub-menus with it
63
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_pruneFocusZones).call(this);
64
+ __classPrivateFieldGet(this, _ActionMenuElement_loader, "f").mutated(records);
65
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_updateLevels).call(this);
66
+ });
67
+ observer.observe(this, { childList: true, subtree: true });
68
+ __classPrivateFieldSet(this, _ActionMenuElement_focusZoneStack, new ActionMenuFocusZoneStack(), "f");
69
+ // The code below updates the menu (i.e. overlay) position whenever the invoker button
70
+ // changes position within its scroll container.
71
+ //
72
+ // See: https://github.com/primer/view_components/issues/3175
73
+ __classPrivateFieldSet(this, _ActionMenuElement_intersectionObserver, new IntersectionObserver(entries => {
74
+ for (const entry of entries) {
75
+ if (entry.target !== this.invokerElement)
76
+ continue;
77
+ if (entry.isIntersecting) {
78
+ // eslint-disable-next-line github/prefer-observers
79
+ window.addEventListener('scroll', __classPrivateFieldGet(this, _ActionMenuElement_scrollUpdater, "f"), { capture: true });
80
+ }
81
+ else {
82
+ window.removeEventListener('scroll', __classPrivateFieldGet(this, _ActionMenuElement_scrollUpdater, "f"), { capture: true });
83
+ }
84
+ }
85
+ }), "f");
36
86
  }
37
87
  get selectVariant() {
38
88
  return this.getAttribute('data-select-variant');
@@ -69,14 +119,13 @@ let ActionMenuElement = ActionMenuElement_1 = _a = class ActionMenuElement exten
69
119
  }
70
120
  get invokerElement() {
71
121
  const id = this.querySelector('[role=menu]')?.id;
72
- if (!id)
73
- return null;
74
- for (const el of this.querySelectorAll(`[aria-controls]`)) {
75
- if (el.getAttribute('aria-controls') === id) {
122
+ if (id) {
123
+ const el = this.querySelector(`[aria-controls="${CSS.escape(id)}"]`);
124
+ if (el)
76
125
  return el;
77
- }
78
126
  }
79
- return null;
127
+ const overlayId = this.overlay?.id;
128
+ return overlayId ? this.querySelector(`[popovertarget="${CSS.escape(overlayId)}"]`) : null;
80
129
  }
81
130
  get invokerLabel() {
82
131
  if (!this.invokerElement)
@@ -97,61 +146,47 @@ let ActionMenuElement = ActionMenuElement_1 = _a = class ActionMenuElement exten
97
146
  return results;
98
147
  }
99
148
  connectedCallback() {
100
- const { signal } = (__classPrivateFieldSet(this, _ActionMenuElement_abortController, new AbortController(), "f"));
101
- this.addEventListener('keydown', this, { signal });
102
- this.addEventListener('click', this, { signal });
103
- this.addEventListener('mouseover', this, { signal });
104
- this.addEventListener('focusout', this, { signal });
105
- this.addEventListener('mousedown', this, { signal });
106
- this.addEventListener('toggle', this, { signal, capture: true });
107
- __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_setDynamicLabel).call(this);
108
- __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_updateInput).call(this);
149
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_bindHostListeners).call(this);
150
+ // Kept inputs stand for the selection until a response replaces them;
151
+ // the body holds no items to sync from meanwhile
152
+ if (!__classPrivateFieldGet(this, _ActionMenuElement_loader, "f").keepingInputs) {
153
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_setDynamicLabel).call(this);
154
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_updateInput).call(this);
155
+ }
109
156
  __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_softDisableItems).call(this);
110
- if (this.includeFragment) {
111
- this.includeFragment.addEventListener('include-fragment-replaced', this, {
112
- signal,
113
- });
157
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_setupSubMenuLoading).call(this);
158
+ __classPrivateFieldGet(this, _ActionMenuElement_loader, "f").sync();
159
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_observeInvokerPosition).call(this);
160
+ if (__classPrivateFieldGet(this, _ActionMenuElement_loader, "f").deferred) {
161
+ __classPrivateFieldGet(this, _ActionMenuElement_loader, "f").updateReady();
114
162
  }
115
- // The code below updates the menu (i.e. overlay) position whenever the invoker button
116
- // changes position within its scroll container.
117
- //
118
- // See: https://github.com/primer/view_components/issues/3175
119
- const scrollUpdater = () => {
120
- if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isOpen).call(this)) {
121
- this.overlay?.update();
122
- }
123
- };
124
- __classPrivateFieldSet(this, _ActionMenuElement_intersectionObserver, new IntersectionObserver(entries => {
125
- for (const entry of entries) {
126
- const elem = entry.target;
127
- if (elem === this.invokerElement) {
128
- if (entry.isIntersecting) {
129
- // eslint-disable-next-line github/prefer-observers
130
- window.addEventListener('scroll', scrollUpdater, { capture: true });
131
- }
132
- else {
133
- window.removeEventListener('scroll', scrollUpdater, { capture: true });
134
- }
135
- }
136
- }
137
- }), "f");
138
- observeMutationsUntilConditionMet(this, () => Boolean(this.invokerElement), () => __classPrivateFieldGet(this, _ActionMenuElement_intersectionObserver, "f").observe(this.invokerElement));
139
- // If there's no include fragment, then no async fetching will occur and we can
140
- // mark the component as ready.
141
- if (!this.includeFragment) {
163
+ else if (!this.includeFragment?.isConnected) {
142
164
  this.setAttribute('data-ready', 'true');
143
165
  }
144
- const levelObserver = new MutationObserver(() => __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_updateLevels).call(this));
145
- levelObserver.observe(this, { childList: true, subtree: true });
146
166
  __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_updateLevels).call(this);
147
- __classPrivateFieldSet(this, _ActionMenuElement_focusZoneStack, new ActionMenuFocusZoneStack(), "f");
148
167
  }
149
168
  disconnectedCallback() {
150
169
  __classPrivateFieldGet(this, _ActionMenuElement_abortController, "f").abort();
170
+ __classPrivateFieldGet(this, _ActionMenuElement_focusZoneStack, "f").clear();
171
+ __classPrivateFieldGet(this, _ActionMenuElement_intersectionObserver, "f").disconnect();
172
+ window.removeEventListener('scroll', __classPrivateFieldGet(this, _ActionMenuElement_scrollUpdater, "f"), { capture: true });
173
+ }
174
+ attributeChangedCallback(name) {
175
+ if (name === 'src')
176
+ __classPrivateFieldGet(this, _ActionMenuElement_loader, "f").sync();
177
+ }
178
+ // Forgets the current request so the menu loads again at the current src:
179
+ // at once when open or preloaded, otherwise when it next opens.
180
+ refresh() {
181
+ __classPrivateFieldGet(this, _ActionMenuElement_loader, "f").refresh();
151
182
  }
152
183
  handleEvent(event) {
153
184
  const targetIsInvoker = this.invokerElement?.contains(event.target);
154
185
  const eventIsActivation = __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isActivation).call(this, event);
186
+ if (event.type === 'beforetoggle' && event instanceof ToggleEvent) {
187
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_handleBeforeToggleEvent).call(this, event);
188
+ return;
189
+ }
155
190
  if (event.type === 'toggle' && event instanceof ToggleEvent) {
156
191
  __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_handleToggleEvent).call(this, event);
157
192
  return;
@@ -212,6 +247,7 @@ let ActionMenuElement = ActionMenuElement_1 = _a = class ActionMenuElement exten
212
247
  return;
213
248
  }
214
249
  if (event.type === 'include-fragment-replaced') {
250
+ // A static menu's deferred sub-menu
215
251
  __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_handleIncludeFragmentReplaced).call(this);
216
252
  return;
217
253
  }
@@ -296,14 +332,46 @@ _ActionMenuElement_inputName = new WeakMap();
296
332
  _ActionMenuElement_invokerBeingClicked = new WeakMap();
297
333
  _ActionMenuElement_intersectionObserver = new WeakMap();
298
334
  _ActionMenuElement_focusZoneStack = new WeakMap();
335
+ _ActionMenuElement_loader = new WeakMap();
336
+ _ActionMenuElement_scrollUpdater = new WeakMap();
299
337
  _ActionMenuElement_instances = new WeakSet();
338
+ _ActionMenuElement_bindHostListeners = function _ActionMenuElement_bindHostListeners() {
339
+ const { signal } = (__classPrivateFieldSet(this, _ActionMenuElement_abortController, new AbortController(), "f"));
340
+ this.addEventListener('keydown', this, { signal });
341
+ this.addEventListener('click', this, { signal });
342
+ this.addEventListener('mouseover', this, { signal });
343
+ this.addEventListener('focusout', this, { signal });
344
+ this.addEventListener('mousedown', this, { signal });
345
+ this.addEventListener('beforetoggle', this, { signal, capture: true });
346
+ this.addEventListener('toggle', this, { signal, capture: true });
347
+ };
348
+ _ActionMenuElement_setupSubMenuLoading = function _ActionMenuElement_setupSubMenuLoading() {
349
+ if (__classPrivateFieldGet(this, _ActionMenuElement_loader, "f").deferred || !this.includeFragment)
350
+ return;
351
+ this.includeFragment.addEventListener('include-fragment-replaced', this, {
352
+ signal: __classPrivateFieldGet(this, _ActionMenuElement_abortController, "f").signal,
353
+ });
354
+ };
355
+ _ActionMenuElement_observeInvokerPosition = function _ActionMenuElement_observeInvokerPosition() {
356
+ observeMutationsUntilConditionMet(this, () => Boolean(this.invokerElement), () => __classPrivateFieldGet(this, _ActionMenuElement_intersectionObserver, "f").observe(this.invokerElement));
357
+ };
300
358
  _ActionMenuElement_updateLevels = function _ActionMenuElement_updateLevels() {
301
- let idx = 1;
302
- for (const menu of this.querySelectorAll('[role=menu]')) {
303
- menu.setAttribute('data-level', idx.toString());
304
- idx++;
359
+ for (const [index, menu] of this.querySelectorAll('[role=menu]').entries()) {
360
+ menu.setAttribute('data-level', String(index + 1));
305
361
  }
306
362
  };
363
+ _ActionMenuElement_keepOpenWhileLoading = function _ActionMenuElement_keepOpenWhileLoading(fragment) {
364
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_pruneFocusZones).call(this);
365
+ __classPrivateFieldGet(this, _ActionMenuElement_focusZoneStack, "f").popAbove(this.overlay);
366
+ for (const child of this.childPopoverElements) {
367
+ if (child.matches(':popover-open'))
368
+ child.hidePopover();
369
+ }
370
+ fragment.querySelector('[role=menuitem]')?.focus();
371
+ };
372
+ _ActionMenuElement_pruneFocusZones = function _ActionMenuElement_pruneFocusZones() {
373
+ __classPrivateFieldGet(this, _ActionMenuElement_focusZoneStack, "f").prune(element => element.isConnected && this.contains(element));
374
+ };
307
375
  _ActionMenuElement_softDisableItems = function _ActionMenuElement_softDisableItems() {
308
376
  const { signal } = __classPrivateFieldGet(this, _ActionMenuElement_abortController, "f");
309
377
  for (const item of this.querySelectorAll(ActionMenuElement_1.validSelectors.join(','))) {
@@ -352,43 +420,75 @@ _ActionMenuElement_isActivation = function _ActionMenuElement_isActivation(event
352
420
  _ActionMenuElement_handleItemKeyboardEvent = function _ActionMenuElement_handleItemKeyboardEvent(event, item) {
353
421
  switch (event.key) {
354
422
  case 'ArrowRight': {
423
+ if (item.getAttribute('aria-disabled'))
424
+ break;
355
425
  const subMenu = __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_subMenuForItem).call(this, item);
356
426
  subMenu?.showPopover();
357
427
  break;
358
428
  }
359
- case 'ArrowLeft':
360
- if (item.closest('role[menu]') !== this.list) {
361
- const overlay = item.closest('anchored-position');
362
- overlay?.hidePopover();
429
+ case 'ArrowLeft': {
430
+ const overlay = item.closest('anchored-position');
431
+ if (overlay && overlay !== this.overlay) {
432
+ overlay.hidePopover();
363
433
  }
364
434
  break;
435
+ }
365
436
  }
366
437
  };
438
+ _ActionMenuElement_handleBeforeToggleEvent = function _ActionMenuElement_handleBeforeToggleEvent(event) {
439
+ if (event.newState === 'open') {
440
+ // A closed lazy menu catches up, and a failed load retries, as it opens
441
+ if (event.target === this.overlay)
442
+ __classPrivateFieldGet(this, _ActionMenuElement_loader, "f").sync(true);
443
+ return;
444
+ }
445
+ if (event.newState !== 'closed')
446
+ return;
447
+ const menu = __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_toggledMenu).call(this, event);
448
+ if (!menu)
449
+ return;
450
+ __classPrivateFieldGet(this, _ActionMenuElement_focusZoneStack, "f").pop(menu);
451
+ // The primary menu's popover hands focus back to the invoker itself
452
+ if (menu === this.overlay)
453
+ return;
454
+ // A nested popover does not hand focus back when it closes, so a sub-menu closed
455
+ // with ArrowLeft or Escape would leave focus on the body and the focusout handler
456
+ // would then close the whole menu. Move focus to the sub-menu's item before the
457
+ // sub-menu hides, while focus is still inside it. Doing this synchronously, rather
458
+ // than in the async toggle event, keeps focus from ever reaching the body.
459
+ if (!menu.contains(document.activeElement))
460
+ return;
461
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_itemForSubMenu).call(this, menu)?.focus();
462
+ };
367
463
  _ActionMenuElement_handleToggleEvent = function _ActionMenuElement_handleToggleEvent(event) {
368
- const subMenu = event.target;
369
- // Ignore toggle events from non-anchored-position elements (e.g. tooltips inside the menu)
370
- if (!(event.target instanceof AnchoredPositionElement))
464
+ const menu = __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_toggledMenu).call(this, event);
465
+ if (!menu)
371
466
  return;
372
467
  if (event.newState === 'open') {
373
468
  // allow tabbing away from primary menu, but trap focus in sub-menus
374
- const isPrimaryMenu = subMenu === this.overlay;
375
- __classPrivateFieldGet(this, _ActionMenuElement_focusZoneStack, "f").push(subMenu, { trapFocus: !isPrimaryMenu });
469
+ const isPrimaryMenu = menu === this.overlay;
470
+ __classPrivateFieldGet(this, _ActionMenuElement_focusZoneStack, "f").push(menu, { trapFocus: !isPrimaryMenu });
471
+ // Picks up a src set by a beforetoggle listener that ran after ours
472
+ if (isPrimaryMenu)
473
+ __classPrivateFieldGet(this, _ActionMenuElement_loader, "f").sync(true);
376
474
  window.requestAnimationFrame(() => {
377
- const firstItem = subMenu.querySelector(ActionMenuElement_1.menuItemSelectors.join(','));
475
+ const firstItem = menu.querySelector(ActionMenuElement_1.menuItemSelectors.join(','));
378
476
  firstItem?.focus();
379
477
  });
380
478
  }
381
- else {
382
- // Note that this will also cause focus to return to the invoker button, which is
383
- // desirable
384
- __classPrivateFieldGet(this, _ActionMenuElement_focusZoneStack, "f").pop(subMenu);
385
- const item = __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_itemForSubMenu).call(this, subMenu);
386
- const openPopover = document.querySelector(':popover-open');
387
- if (item && !openPopover) {
388
- item.focus();
389
- }
479
+ else if (menu === this.overlay && !document.querySelector(':popover-open') && __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_focusLostTo).call(this, menu)) {
480
+ // A light-dismissed menu (e.g. a click outside it) leaves focus on the body;
481
+ // hand it back to the invoker so the menu stays reachable from the keyboard.
482
+ this.invokerElement?.focus();
390
483
  }
391
484
  };
485
+ _ActionMenuElement_focusLostTo = function _ActionMenuElement_focusLostTo(menu) {
486
+ const active = document.activeElement;
487
+ return !active || active === document.body || menu.contains(active);
488
+ };
489
+ _ActionMenuElement_toggledMenu = function _ActionMenuElement_toggledMenu(event) {
490
+ return event.target instanceof AnchoredPositionElement ? event.target : null;
491
+ };
392
492
  _ActionMenuElement_handleInvokerActivated = function _ActionMenuElement_handleInvokerActivated(event) {
393
493
  event.preventDefault();
394
494
  /* eslint-disable-next-line no-restricted-syntax */
@@ -478,11 +578,49 @@ _ActionMenuElement_handleItemActivated = function _ActionMenuElement_handleItemA
478
578
  }));
479
579
  };
480
580
  _ActionMenuElement_handleIncludeFragmentReplaced = function _ActionMenuElement_handleIncludeFragmentReplaced() {
481
- __classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get)?.focus();
581
+ // Selection first: focusing afterwards can run a consumer handler that
582
+ // starts another load
583
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_setDynamicLabel).call(this);
584
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_updateInput).call(this);
482
585
  __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_softDisableItems).call(this);
586
+ // Focus moves in a microtask: after the list's focus zone has processed
587
+ // the new items (its observer would otherwise drop the focused item's
588
+ // tab stop), and before the focusout frame would close the menu
589
+ const activeOnLoad = document.activeElement;
590
+ queueMicrotask(() => __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_focusLoadedMenu).call(this, activeOnLoad));
591
+ // A deferred menu's loader decides readiness
592
+ if (!__classPrivateFieldGet(this, _ActionMenuElement_loader, "f").deferred)
593
+ this.setAttribute('data-ready', 'true');
594
+ };
595
+ _ActionMenuElement_focusLoadedMenu = function _ActionMenuElement_focusLoadedMenu(activeOnLoad) {
596
+ // Content can finish loading while the menu is detached
597
+ if (!this.isConnected)
598
+ return;
599
+ // A consumer's completion listener, or a load it started, moved focus
600
+ // meanwhile: keep it there
601
+ const active = document.activeElement;
602
+ if (active !== activeOnLoad) {
603
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_restoreTabStop).call(this, active);
604
+ return;
605
+ }
606
+ const firstItem = __classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get);
607
+ if (firstItem) {
608
+ firstItem.focus();
609
+ }
610
+ else if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isOpen).call(this)) {
611
+ // Nothing to focus in an empty response: close and return to the
612
+ // button.
613
+ this.overlay.hidePopover();
614
+ this.invokerElement?.focus();
615
+ }
483
616
  this.overlay?.update();
484
- // async items have loaded, so component is ready
485
- this.setAttribute('data-ready', 'true');
617
+ };
618
+ _ActionMenuElement_restoreTabStop = function _ActionMenuElement_restoreTabStop(element) {
619
+ if (element instanceof HTMLElement &&
620
+ this.overlay?.contains(element) &&
621
+ element.matches(ActionMenuElement_1.validSelectors.join(','))) {
622
+ element.setAttribute('tabindex', '0');
623
+ }
486
624
  };
487
625
  _ActionMenuElement_handleFocusOut = function _ActionMenuElement_handleFocusOut() {
488
626
  __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_hide).call(this);
@@ -497,7 +635,7 @@ _ActionMenuElement_hide = function _ActionMenuElement_hide() {
497
635
  }
498
636
  };
499
637
  _ActionMenuElement_isOpen = function _ActionMenuElement_isOpen() {
500
- return this.popoverElement?.matches(':popover-open');
638
+ return this.overlay?.matches(':popover-open') ?? false;
501
639
  };
502
640
  _ActionMenuElement_setDynamicLabel = function _ActionMenuElement_setDynamicLabel() {
503
641
  if (!this.dynamicLabel)
@@ -505,7 +643,12 @@ _ActionMenuElement_setDynamicLabel = function _ActionMenuElement_setDynamicLabel
505
643
  const invokerLabel = this.invokerLabel;
506
644
  if (!invokerLabel)
507
645
  return;
508
- __classPrivateFieldSet(this, _ActionMenuElement_originalLabel, __classPrivateFieldGet(this, _ActionMenuElement_originalLabel, "f") || (invokerLabel.textContent || ''), "f");
646
+ // Kept on the host, since the button of a cloned or restored menu
647
+ // already shows a selection
648
+ if (!__classPrivateFieldGet(this, _ActionMenuElement_originalLabel, "f")) {
649
+ __classPrivateFieldSet(this, _ActionMenuElement_originalLabel, this.getAttribute('data-original-label') ?? (invokerLabel.textContent || ''), "f");
650
+ this.setAttribute('data-original-label', __classPrivateFieldGet(this, _ActionMenuElement_originalLabel, "f"));
651
+ }
509
652
  let itemLabel;
510
653
  if (this.selectVariant === 'single') {
511
654
  itemLabel = this.querySelector('[aria-checked=true] .ActionListItem-label')?.textContent?.trim();
@@ -552,6 +695,11 @@ _ActionMenuElement_updateInput = function _ActionMenuElement_updateInput() {
552
695
  if (inputs.length > 0) {
553
696
  __classPrivateFieldSet(this, _ActionMenuElement_inputName, __classPrivateFieldGet(this, _ActionMenuElement_inputName, "f") || inputs[0].name, "f");
554
697
  }
698
+ // Kept on the container too, so a cloned or restored menu with nothing
699
+ // selected still names the inputs it creates
700
+ __classPrivateFieldSet(this, _ActionMenuElement_inputName, __classPrivateFieldGet(this, _ActionMenuElement_inputName, "f") || (inputList.getAttribute('data-input-name') ?? ''), "f");
701
+ if (__classPrivateFieldGet(this, _ActionMenuElement_inputName, "f"))
702
+ inputList.setAttribute('data-input-name', __classPrivateFieldGet(this, _ActionMenuElement_inputName, "f"));
555
703
  for (const selectedItem of this.selectedItems) {
556
704
  const newInput = document.createElement('input');
557
705
  newInput.setAttribute('data-list-input', 'true');
@@ -583,6 +731,7 @@ _ActionMenuElement_itemForSubMenu = function _ActionMenuElement_itemForSubMenu(s
583
731
  }
584
732
  return null;
585
733
  };
734
+ ActionMenuElement.observedAttributes = ['src'];
586
735
  ActionMenuElement.validItemRoles = ['menuitem', 'menuitemcheckbox', 'menuitemradio'];
587
736
  ActionMenuElement.validSelectors = ActionMenuElement_1.validItemRoles.map(role => `[role="${role}"]`);
588
737
  ActionMenuElement.menuItemSelectors = ActionMenuElement_1.validSelectors.map(selector => `:not([hidden]) > ${selector}`);
@@ -595,6 +744,12 @@ __decorate([
595
744
  __decorate([
596
745
  target
597
746
  ], ActionMenuElement.prototype, "list", void 0);
747
+ __decorate([
748
+ target
749
+ ], ActionMenuElement.prototype, "overlayBody", void 0);
750
+ __decorate([
751
+ target
752
+ ], ActionMenuElement.prototype, "loaderTemplate", void 0);
598
753
  ActionMenuElement = ActionMenuElement_1 = __decorate([
599
754
  controller('action-menu')
600
755
  ], ActionMenuElement);