openproject-primer_view_components 0.95.0 → 0.96.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 (176) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -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 +5 -1
  10. data/app/components/primer/alpha/action_list.css +1 -1
  11. data/app/components/primer/alpha/action_list.css.json +13 -11
  12. data/app/components/primer/alpha/action_list.css.map +1 -1
  13. data/app/components/primer/alpha/action_list.pcss +12 -0
  14. data/app/components/primer/alpha/action_menu/action_menu_element.d.ts +6 -0
  15. data/app/components/primer/alpha/action_menu/action_menu_element.js +389 -84
  16. data/app/components/primer/alpha/action_menu/action_menu_element.ts +439 -78
  17. data/app/components/primer/alpha/action_menu/action_menu_focus_zone_stack.d.ts +4 -1
  18. data/app/components/primer/alpha/action_menu/action_menu_focus_zone_stack.js +37 -13
  19. data/app/components/primer/alpha/action_menu/action_menu_focus_zone_stack.ts +41 -12
  20. data/app/components/primer/alpha/action_menu/menu.html.erb +27 -19
  21. data/app/components/primer/alpha/action_menu/menu.rb +7 -0
  22. data/app/components/primer/alpha/action_menu/primary_menu.rb +15 -0
  23. data/app/components/primer/alpha/action_menu.rb +55 -0
  24. data/app/components/primer/alpha/auto_complete.css +1 -1
  25. data/app/components/primer/alpha/auto_complete.css.map +1 -1
  26. data/app/components/primer/alpha/banner.css +1 -1
  27. data/app/components/primer/alpha/banner.css.map +1 -1
  28. data/app/components/primer/alpha/button_marketing.css +1 -1
  29. data/app/components/primer/alpha/button_marketing.css.map +1 -1
  30. data/app/components/primer/alpha/dialog.css +1 -1
  31. data/app/components/primer/alpha/dialog.css.map +1 -1
  32. data/app/components/primer/alpha/dropdown/menu.rb +1 -1
  33. data/app/components/primer/alpha/dropdown.css +1 -1
  34. data/app/components/primer/alpha/dropdown.css.json +1 -1
  35. data/app/components/primer/alpha/dropdown.css.map +1 -1
  36. data/app/components/primer/alpha/layout.css +1 -1
  37. data/app/components/primer/alpha/layout.css.json +3 -3
  38. data/app/components/primer/alpha/layout.css.map +1 -1
  39. data/app/components/primer/alpha/menu.css +1 -1
  40. data/app/components/primer/alpha/menu.css.json +3 -3
  41. data/app/components/primer/alpha/menu.css.map +1 -1
  42. data/app/components/primer/alpha/overlay.css +1 -1
  43. data/app/components/primer/alpha/overlay.css.map +1 -1
  44. data/app/components/primer/alpha/segmented_control.css +1 -1
  45. data/app/components/primer/alpha/segmented_control.css.json +1 -1
  46. data/app/components/primer/alpha/segmented_control.css.map +1 -1
  47. data/app/components/primer/alpha/select_panel.css +1 -1
  48. data/app/components/primer/alpha/select_panel.css.map +1 -1
  49. data/app/components/primer/alpha/skeleton_box.css +1 -1
  50. data/app/components/primer/alpha/skeleton_box.css.map +1 -1
  51. data/app/components/primer/alpha/stack.css +1 -1
  52. data/app/components/primer/alpha/stack.css.map +1 -1
  53. data/app/components/primer/alpha/stack_item.css +1 -1
  54. data/app/components/primer/alpha/stack_item.css.map +1 -1
  55. data/app/components/primer/alpha/tab_nav.css +1 -1
  56. data/app/components/primer/alpha/tab_nav.css.map +1 -1
  57. data/app/components/primer/alpha/text_field.css +1 -1
  58. data/app/components/primer/alpha/text_field.css.map +1 -1
  59. data/app/components/primer/alpha/toggle_switch.css +1 -1
  60. data/app/components/primer/alpha/toggle_switch.css.map +1 -1
  61. data/app/components/primer/alpha/tree_view.css +1 -1
  62. data/app/components/primer/alpha/tree_view.css.json +3 -3
  63. data/app/components/primer/alpha/tree_view.css.map +1 -1
  64. data/app/components/primer/alpha/underline_nav.css +1 -1
  65. data/app/components/primer/alpha/underline_nav.css.map +1 -1
  66. data/app/components/primer/beta/border_box.css +1 -1
  67. data/app/components/primer/beta/border_box.css.json +5 -5
  68. data/app/components/primer/beta/border_box.css.map +1 -1
  69. data/app/components/primer/beta/button.css +1 -1
  70. data/app/components/primer/beta/button.css.map +1 -1
  71. data/app/components/primer/beta/button.pcss +97 -0
  72. data/app/components/primer/beta/button.rb +15 -3
  73. data/app/components/primer/beta/counter.css +1 -1
  74. data/app/components/primer/beta/counter.css.map +1 -1
  75. data/app/components/primer/beta/flash.css +1 -1
  76. data/app/components/primer/beta/flash.css.map +1 -1
  77. data/app/components/primer/beta/link.css +1 -1
  78. data/app/components/primer/beta/link.css.json +1 -1
  79. data/app/components/primer/beta/link.css.map +1 -1
  80. data/app/components/primer/beta/popover.css +1 -1
  81. data/app/components/primer/beta/popover.css.map +1 -1
  82. data/app/components/primer/beta/progress_bar.css +1 -1
  83. data/app/components/primer/beta/progress_bar.css.map +1 -1
  84. data/app/components/primer/beta/relative_time.rb +7 -1
  85. data/app/components/primer/beta/state.css +1 -1
  86. data/app/components/primer/beta/state.css.json +2 -2
  87. data/app/components/primer/beta/state.css.map +1 -1
  88. data/app/components/primer/beta/timeline_item.css +1 -1
  89. data/app/components/primer/beta/timeline_item.css.map +1 -1
  90. data/app/components/primer/open_project/border_grid.css +1 -1
  91. data/app/components/primer/open_project/border_grid.css.map +1 -1
  92. data/app/components/primer/open_project/color_field.css +1 -1
  93. data/app/components/primer/open_project/color_field.css.map +1 -1
  94. data/app/components/primer/open_project/inline_message.css +1 -1
  95. data/app/components/primer/open_project/inline_message.css.map +1 -1
  96. data/app/components/primer/open_project/input_group.css +1 -1
  97. data/app/components/primer/open_project/input_group.css.map +1 -1
  98. data/app/components/primer/open_project/keybinding_hint/chords.d.ts +5 -0
  99. data/app/components/primer/open_project/keybinding_hint/chords.js +29 -0
  100. data/app/components/primer/open_project/keybinding_hint/chords.ts +38 -0
  101. data/app/components/primer/open_project/keybinding_hint/key_names.d.ts +16 -0
  102. data/app/components/primer/open_project/keybinding_hint/key_names.js +107 -0
  103. data/app/components/primer/open_project/keybinding_hint/key_names.ts +116 -0
  104. data/app/components/primer/open_project/keybinding_hint/localized_names.d.ts +22 -0
  105. data/app/components/primer/open_project/keybinding_hint/localized_names.js +47 -0
  106. data/app/components/primer/open_project/keybinding_hint/localized_names.ts +71 -0
  107. data/app/components/primer/open_project/keybinding_hint/names.rb +92 -0
  108. data/app/components/primer/open_project/keybinding_hint/names_from_scope.d.ts +21 -0
  109. data/app/components/primer/open_project/keybinding_hint/names_from_scope.js +81 -0
  110. data/app/components/primer/open_project/keybinding_hint/names_from_scope.ts +96 -0
  111. data/app/components/primer/open_project/keybinding_hint/platform.d.ts +10 -0
  112. data/app/components/primer/open_project/keybinding_hint/platform.js +24 -0
  113. data/app/components/primer/open_project/keybinding_hint/platform.ts +34 -0
  114. data/app/components/primer/open_project/keybinding_hint/platform_override.d.ts +2 -0
  115. data/app/components/primer/open_project/keybinding_hint/platform_override.js +4 -0
  116. data/app/components/primer/open_project/keybinding_hint/platform_override.ts +7 -0
  117. data/app/components/primer/open_project/keybinding_hint.css +1 -0
  118. data/app/components/primer/open_project/keybinding_hint.css.json +10 -0
  119. data/app/components/primer/open_project/keybinding_hint.css.map +1 -0
  120. data/app/components/primer/open_project/keybinding_hint.html.erb +4 -0
  121. data/app/components/primer/open_project/keybinding_hint.pcss +65 -0
  122. data/app/components/primer/open_project/keybinding_hint.rb +112 -0
  123. data/app/components/primer/open_project/keybinding_hint_element.d.ts +31 -0
  124. data/app/components/primer/open_project/keybinding_hint_element.js +183 -0
  125. data/app/components/primer/open_project/keybinding_hint_element.ts +152 -0
  126. data/app/components/primer/open_project/page_header.css +1 -1
  127. data/app/components/primer/open_project/page_header.css.json +2 -2
  128. data/app/components/primer/open_project/page_header.css.map +1 -1
  129. data/app/components/primer/open_project/pagination.css +1 -1
  130. data/app/components/primer/open_project/pagination.css.json +1 -1
  131. data/app/components/primer/open_project/pagination.css.map +1 -1
  132. data/app/components/primer/open_project/sub_header.css +1 -1
  133. data/app/components/primer/open_project/sub_header.css.map +1 -1
  134. data/app/components/primer/primer.d.ts +1 -0
  135. data/app/components/primer/primer.js +1 -0
  136. data/app/components/primer/primer.pcss +1 -0
  137. data/app/components/primer/primer.ts +1 -0
  138. data/app/components/primer/truncate.css +1 -1
  139. data/app/components/primer/truncate.css.json +3 -4
  140. data/app/components/primer/truncate.css.map +1 -1
  141. data/app/controllers/primer/view_components/action_menu_controller.rb +35 -0
  142. data/app/views/primer/view_components/action_menu/deferred.html.erb +25 -11
  143. data/app/views/primer/view_components/action_menu/deferred_form.html.erb +10 -0
  144. data/app/views/primer/view_components/action_menu/deferred_preload.html.erb +7 -1
  145. data/config/locales/en.yml +179 -0
  146. data/config/routes.rb +1 -0
  147. data/lib/primer/accessibility.rb +1 -2
  148. data/lib/primer/classify.rb +1 -2
  149. data/lib/primer/view_components/version.rb +1 -1
  150. data/previews/primer/alpha/action_menu_preview/deferred_refresh.html.erb +34 -0
  151. data/previews/primer/alpha/action_menu_preview/deferred_refresh_form.html.erb +9 -0
  152. data/previews/primer/alpha/action_menu_preview.rb +14 -0
  153. data/previews/primer/open_project/keybinding_hint_preview/full_format.html.erb +3 -0
  154. data/previews/primer/open_project/keybinding_hint_preview/in_action_list.html.erb +12 -0
  155. data/previews/primer/open_project/keybinding_hint_preview/in_button.html.erb +24 -0
  156. data/previews/primer/open_project/keybinding_hint_preview/platforms.html.erb +8 -0
  157. data/previews/primer/open_project/keybinding_hint_preview/playground.html.erb +4 -0
  158. data/previews/primer/open_project/keybinding_hint_preview/prose.html.erb +3 -0
  159. data/previews/primer/open_project/keybinding_hint_preview/schemes.html.erb +6 -0
  160. data/previews/primer/open_project/keybinding_hint_preview/sequence.html.erb +1 -0
  161. data/previews/primer/open_project/keybinding_hint_preview/sizes.html.erb +4 -0
  162. data/previews/primer/open_project/keybinding_hint_preview.rb +71 -0
  163. data/static/arguments.json +53 -1
  164. data/static/audited_at.json +1 -0
  165. data/static/classes.json +12 -0
  166. data/static/classnames.cjs +4 -0
  167. data/static/classnames.js +4 -0
  168. data/static/constants.json +35 -0
  169. data/static/info_arch.json +234 -8
  170. data/static/previews.json +164 -0
  171. data/static/statuses.json +1 -0
  172. metadata +42 -5
  173. data/app/components/primer/alpha/text_field.css.json +0 -134
  174. data/app/components/primer/alpha/toggle_switch.css.json +0 -40
  175. data/app/components/primer/alpha/underline_nav.css.json +0 -26
  176. data/app/components/primer/beta/button.css.json +0 -86
@@ -0,0 +1,21 @@
1
+ import type { Platform } from './platform';
2
+ import type { NameFormat } from './localized_names';
3
+ type PlatformNames = Partial<Record<Platform, string>>;
4
+ type EntryNames = Partial<Record<NameFormat, PlatformNames>>;
5
+ /** The `data-names` JSON shape; identical to Ruby's `KeybindingHint::Names.for`. */
6
+ export type KeyNamesData = {
7
+ then: string | undefined;
8
+ keys: Record<string, EntryNames>;
9
+ };
10
+ /**
11
+ * Keys as Ruby tokenises them: the server cannot know the platform, so `mod`
12
+ * contributes both `control` and `meta`. Whitespace matches Ruby's `\s`.
13
+ */
14
+ export declare const tokens: (keys: string) => string[];
15
+ /**
16
+ * Builds `data-names` for `keys` from the `keybinding_hint` locale scopes, as
17
+ * i18n-js returns them. Translator data is untrusted: only non-blank strings in
18
+ * the expected place are used, and symbols such as ⌘ cannot be replaced.
19
+ */
20
+ export declare function buildKeyNames(keys: string, localeScope: unknown, englishScope: unknown): KeyNamesData;
21
+ export {};
@@ -0,0 +1,81 @@
1
+ import { nonBlank } from './localized_names';
2
+ const FORMATS = ['condensed', 'full', 'accessible'];
3
+ const PLATFORMS = ['apple', 'windows', 'other'];
4
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
5
+ const own = (value, key) => isRecord(value) && Object.hasOwn(value, key) ? value[key] : undefined;
6
+ const isSymbol = (name) => name !== undefined && !/\p{L}/u.test(name);
7
+ /**
8
+ * Keys as Ruby tokenises them: the server cannot know the platform, so `mod`
9
+ * contributes both `control` and `meta`. Whitespace matches Ruby's `\s`.
10
+ */
11
+ export const tokens = (keys) => [
12
+ ...new Set(keys
13
+ .split(/[ \t\r\n\f\v]+/)
14
+ .flatMap(chord => chord.split('+'))
15
+ .filter(token => token !== '')
16
+ .map(token => token.toLowerCase())
17
+ .flatMap(token => (token === 'mod' ? ['control', 'meta'] : [token]))),
18
+ ];
19
+ /** I18n keys cannot contain `.`, so punctuation entries carry their key in `key`. */
20
+ const tokenIndex = (entries) => {
21
+ const index = new Map();
22
+ if (!isRecord(entries))
23
+ return index;
24
+ for (const [name, entry] of Object.entries(entries)) {
25
+ if (!isRecord(entry))
26
+ continue;
27
+ const key = own(entry, 'key');
28
+ index.set(typeof key === 'string' ? key : name, name);
29
+ }
30
+ return index;
31
+ };
32
+ const platformNames = (value) => {
33
+ const names = {};
34
+ for (const platform of PLATFORMS) {
35
+ const name = nonBlank(own(value, platform));
36
+ if (name !== undefined)
37
+ names[platform] = name;
38
+ }
39
+ return names;
40
+ };
41
+ const entryNames = (englishEntry, localeEntry) => {
42
+ const names = {};
43
+ for (const format of FORMATS) {
44
+ const english = platformNames(own(englishEntry, format));
45
+ const translated = platformNames(own(localeEntry, format));
46
+ for (const platform of PLATFORMS) {
47
+ if (isSymbol(english[platform]))
48
+ delete translated[platform];
49
+ }
50
+ const merged = { ...english, ...translated };
51
+ if (Object.keys(merged).length > 0)
52
+ names[format] = merged;
53
+ }
54
+ return names;
55
+ };
56
+ /**
57
+ * Builds `data-names` for `keys` from the `keybinding_hint` locale scopes, as
58
+ * i18n-js returns them. Translator data is untrusted: only non-blank strings in
59
+ * the expected place are used, and symbols such as ⌘ cannot be replaced.
60
+ */
61
+ export function buildKeyNames(keys, localeScope, englishScope) {
62
+ const englishKeys = own(englishScope, 'keys');
63
+ const index = tokenIndex(englishKeys);
64
+ const result = {
65
+ then: nonBlank(own(localeScope, 'then')) ?? nonBlank(own(englishScope, 'then')),
66
+ keys: {},
67
+ };
68
+ for (const token of tokens(keys)) {
69
+ const entry = index.get(token);
70
+ if (entry === undefined)
71
+ continue;
72
+ // defineProperty, not assignment: a `__proto__` token must stay an own key.
73
+ Object.defineProperty(result.keys, token, {
74
+ value: entryNames(own(englishKeys, entry), own(own(localeScope, 'keys'), entry)),
75
+ enumerable: true,
76
+ writable: true,
77
+ configurable: true,
78
+ });
79
+ }
80
+ return result;
81
+ }
@@ -0,0 +1,96 @@
1
+ import type {Platform} from './platform'
2
+ import {nonBlank} from './localized_names'
3
+ import type {NameFormat} from './localized_names'
4
+
5
+ type PlatformNames = Partial<Record<Platform, string>>
6
+ type EntryNames = Partial<Record<NameFormat, PlatformNames>>
7
+
8
+ /** The `data-names` JSON shape; identical to Ruby's `KeybindingHint::Names.for`. */
9
+ export type KeyNamesData = {then: string | undefined; keys: Record<string, EntryNames>}
10
+
11
+ const FORMATS: readonly NameFormat[] = ['condensed', 'full', 'accessible']
12
+ const PLATFORMS: readonly Platform[] = ['apple', 'windows', 'other']
13
+
14
+ const isRecord = (value: unknown): value is Record<string, unknown> =>
15
+ typeof value === 'object' && value !== null && !Array.isArray(value)
16
+
17
+ const own = (value: unknown, key: string): unknown =>
18
+ isRecord(value) && Object.hasOwn(value, key) ? value[key] : undefined
19
+
20
+ const isSymbol = (name: string | undefined) => name !== undefined && !/\p{L}/u.test(name)
21
+
22
+ /**
23
+ * Keys as Ruby tokenises them: the server cannot know the platform, so `mod`
24
+ * contributes both `control` and `meta`. Whitespace matches Ruby's `\s`.
25
+ */
26
+ export const tokens = (keys: string): string[] => [
27
+ ...new Set(
28
+ keys
29
+ .split(/[ \t\r\n\f\v]+/)
30
+ .flatMap(chord => chord.split('+'))
31
+ .filter(token => token !== '')
32
+ .map(token => token.toLowerCase())
33
+ .flatMap(token => (token === 'mod' ? ['control', 'meta'] : [token])),
34
+ ),
35
+ ]
36
+
37
+ /** I18n keys cannot contain `.`, so punctuation entries carry their key in `key`. */
38
+ const tokenIndex = (entries: unknown): Map<string, string> => {
39
+ const index = new Map<string, string>()
40
+ if (!isRecord(entries)) return index
41
+ for (const [name, entry] of Object.entries(entries)) {
42
+ if (!isRecord(entry)) continue
43
+ const key = own(entry, 'key')
44
+ index.set(typeof key === 'string' ? key : name, name)
45
+ }
46
+ return index
47
+ }
48
+
49
+ const platformNames = (value: unknown): PlatformNames => {
50
+ const names: PlatformNames = {}
51
+ for (const platform of PLATFORMS) {
52
+ const name = nonBlank(own(value, platform))
53
+ if (name !== undefined) names[platform] = name
54
+ }
55
+ return names
56
+ }
57
+
58
+ const entryNames = (englishEntry: unknown, localeEntry: unknown): EntryNames => {
59
+ const names: EntryNames = {}
60
+ for (const format of FORMATS) {
61
+ const english = platformNames(own(englishEntry, format))
62
+ const translated = platformNames(own(localeEntry, format))
63
+ for (const platform of PLATFORMS) {
64
+ if (isSymbol(english[platform])) delete translated[platform]
65
+ }
66
+ const merged = {...english, ...translated}
67
+ if (Object.keys(merged).length > 0) names[format] = merged
68
+ }
69
+ return names
70
+ }
71
+
72
+ /**
73
+ * Builds `data-names` for `keys` from the `keybinding_hint` locale scopes, as
74
+ * i18n-js returns them. Translator data is untrusted: only non-blank strings in
75
+ * the expected place are used, and symbols such as ⌘ cannot be replaced.
76
+ */
77
+ export function buildKeyNames(keys: string, localeScope: unknown, englishScope: unknown): KeyNamesData {
78
+ const englishKeys = own(englishScope, 'keys')
79
+ const index = tokenIndex(englishKeys)
80
+ const result: KeyNamesData = {
81
+ then: nonBlank(own(localeScope, 'then')) ?? nonBlank(own(englishScope, 'then')),
82
+ keys: {},
83
+ }
84
+ for (const token of tokens(keys)) {
85
+ const entry = index.get(token)
86
+ if (entry === undefined) continue
87
+ // defineProperty, not assignment: a `__proto__` token must stay an own key.
88
+ Object.defineProperty(result.keys, token, {
89
+ value: entryNames(own(englishKeys, entry), own(own(localeScope, 'keys'), entry)),
90
+ enumerable: true,
91
+ writable: true,
92
+ configurable: true,
93
+ })
94
+ }
95
+ return result
96
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The platform categories that affect how keyboard shortcut keys are displayed.
3
+ *
4
+ * - `apple`: Apple platforms (macOS and iOS/iPadOS), which use the Command and Option keys.
5
+ * - `windows`: Windows, which uses the Windows (Meta) key.
6
+ * - `other`: Any other platform (e.g. Linux, Android), where the Meta key does not map to a
7
+ * consistent label.
8
+ */
9
+ export type Platform = 'apple' | 'windows' | 'other';
10
+ export declare const detectPlatform: () => Platform;
@@ -0,0 +1,24 @@
1
+ // Mirrors primer-react `KeybindingHint/platform.ts`. The React-only parts are
2
+ // replaced: `getSnapshot` is exported as `detectPlatform`, and the element's
3
+ // `data-platform` attribute takes the place of `PlatformOverrideProvider`.
4
+ import { isMacOS as ssrUnsafeIsMacOS } from '@primer/behaviors/utils';
5
+ /** SSR-unsafe detection of iOS/iPadOS (in addition to macOS, which is detected separately). */
6
+ const ssrUnsafeIsIOS = () => {
7
+ if (typeof navigator === 'undefined')
8
+ return false;
9
+ return /iphone|ipad|ipod/i.test(navigator.platform) || /iphone|ipad|ipod/i.test(navigator.userAgent);
10
+ };
11
+ /** SSR-unsafe detection of Windows. */
12
+ const ssrUnsafeIsWindows = () => {
13
+ if (typeof navigator === 'undefined')
14
+ return false;
15
+ return /^win/i.test(navigator.platform);
16
+ };
17
+ const getSnapshot = () => {
18
+ if (ssrUnsafeIsMacOS() || ssrUnsafeIsIOS())
19
+ return 'apple';
20
+ if (ssrUnsafeIsWindows())
21
+ return 'windows';
22
+ return 'other';
23
+ };
24
+ export const detectPlatform = getSnapshot;
@@ -0,0 +1,34 @@
1
+ // Mirrors primer-react `KeybindingHint/platform.ts`. The React-only parts are
2
+ // replaced: `getSnapshot` is exported as `detectPlatform`, and the element's
3
+ // `data-platform` attribute takes the place of `PlatformOverrideProvider`.
4
+ import {isMacOS as ssrUnsafeIsMacOS} from '@primer/behaviors/utils'
5
+
6
+ /**
7
+ * The platform categories that affect how keyboard shortcut keys are displayed.
8
+ *
9
+ * - `apple`: Apple platforms (macOS and iOS/iPadOS), which use the Command and Option keys.
10
+ * - `windows`: Windows, which uses the Windows (Meta) key.
11
+ * - `other`: Any other platform (e.g. Linux, Android), where the Meta key does not map to a
12
+ * consistent label.
13
+ */
14
+ export type Platform = 'apple' | 'windows' | 'other'
15
+
16
+ /** SSR-unsafe detection of iOS/iPadOS (in addition to macOS, which is detected separately). */
17
+ const ssrUnsafeIsIOS = () => {
18
+ if (typeof navigator === 'undefined') return false
19
+ return /iphone|ipad|ipod/i.test(navigator.platform) || /iphone|ipad|ipod/i.test(navigator.userAgent)
20
+ }
21
+
22
+ /** SSR-unsafe detection of Windows. */
23
+ const ssrUnsafeIsWindows = () => {
24
+ if (typeof navigator === 'undefined') return false
25
+ return /^win/i.test(navigator.platform)
26
+ }
27
+
28
+ const getSnapshot = (): Platform => {
29
+ if (ssrUnsafeIsMacOS() || ssrUnsafeIsIOS()) return 'apple'
30
+ if (ssrUnsafeIsWindows()) return 'windows'
31
+ return 'other'
32
+ }
33
+
34
+ export const detectPlatform = getSnapshot
@@ -0,0 +1,2 @@
1
+ import type { Platform } from './platform';
2
+ export declare function isPlatform(value: string): value is Platform;
@@ -0,0 +1,4 @@
1
+ const PLATFORMS = ['apple', 'windows', 'other'];
2
+ export function isPlatform(value) {
3
+ return PLATFORMS.includes(value);
4
+ }
@@ -0,0 +1,7 @@
1
+ import type {Platform} from './platform'
2
+
3
+ const PLATFORMS: readonly string[] = ['apple', 'windows', 'other']
4
+
5
+ export function isPlatform(value: string): value is Platform {
6
+ return PLATFORMS.includes(value)
7
+ }
@@ -0,0 +1 @@
1
+ keybinding-hint{display:contents}.KeybindingHint-kbd{position:relative;padding:0;overflow:visible;font-family:inherit;font-size:inherit;line-height:unset;color:inherit;white-space:nowrap;vertical-align:initial;background:none;border:none;box-shadow:none}.KeybindingHint-chord{display:inline-flex;justify-content:center;min-width:var(--base-size-20);padding:var(--base-size-4);overflow:hidden;font-size:var(--text-body-size-small);font-weight:var(--base-text-weight-normal);line-height:10px;color:var(--fgColor-muted);vertical-align:initial;background:var(--bgColor-transparent);border:var(--borderWidth-thin) solid var(--borderColor-default);border-radius:var(--borderRadius-medium);box-shadow:none;gap:.5ch;transition:80ms ease-in;transition-property:color,background-color,border-color}.KeybindingHint-chord--emphasis{color:var(--fgColor-onEmphasis);background:var(--counter-bgColor-emphasis);border-color:#0000;border-radius:var(--borderRadius-default);min-width:auto}.KeybindingHint-chord--small{min-width:var(--base-size-16);padding:var(--base-size-2);font-size:11px;line-height:var(--base-size-8);border-radius:var(--borderRadius-small)}
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "open_project/keybinding_hint",
3
+ "selectors": [
4
+ "keybinding-hint",
5
+ ".KeybindingHint-kbd",
6
+ ".KeybindingHint-chord",
7
+ ".KeybindingHint-chord--emphasis",
8
+ ".KeybindingHint-chord--small"
9
+ ]
10
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["keybinding_hint.pcss"],"names":[],"mappings":"AAIA,gBACE,gBACF,CAGA,oBACE,iBAAkB,CAClB,SAAU,CACV,gBAAiB,CACjB,mBAAoB,CACpB,iBAAkB,CAElB,iBAAkB,CAClB,aAAc,CACd,kBAAmB,CACnB,sBAAwB,CACxB,eAAgB,CAChB,WAAY,CACZ,eACF,CAGA,sBACE,mBAAoB,CACpB,sBAAuB,CACvB,6BAA8B,CAC9B,0BAA2B,CAC3B,eAAgB,CAChB,qCAAsC,CACtC,0CAA2C,CAE3C,gBAAiB,CACjB,0BAA2B,CAC3B,sBAAwB,CACxB,qCAAsC,CACtC,+DAAgE,CAChE,wCAAyC,CACzC,eAAgB,CAChB,QAAU,CACV,uBAAwB,CACxB,uDACF,CAEA,gCACE,+BAAgC,CAChC,0CAA2C,CAC3C,kBAAyB,CAEzB,yCAA0C,CAC1C,cACF,CAEA,6BACE,6BAA8B,CAC9B,0BAA2B,CAE3B,cAAe,CAEf,8BAA+B,CAC/B,uCACF","file":"keybinding_hint.css","sourcesContent":["/* KeybindingHint (port of Primer React KeybindingHint at 6794582843) */\n\n/* The host carries no semantics; let the <kbd> be the flex/grid item, as in React. */\n/* stylelint-disable-next-line selector-max-type */\nkeybinding-hint {\n display: contents;\n}\n\n/* Reset user-agent <kbd> styling; matches KeybindingHint.module.css */\n.KeybindingHint-kbd {\n position: relative;\n padding: 0;\n overflow: visible;\n font-family: inherit;\n font-size: inherit;\n /* stylelint-disable-next-line primer/typography */\n line-height: unset;\n color: inherit;\n white-space: nowrap;\n vertical-align: baseline;\n background: none;\n border: none;\n box-shadow: none;\n}\n\n/* One bordered box per chord; matches Chord.module.css */\n.KeybindingHint-chord {\n display: inline-flex;\n justify-content: center;\n min-width: var(--base-size-20);\n padding: var(--base-size-4);\n overflow: hidden;\n font-size: var(--text-body-size-small);\n font-weight: var(--base-text-weight-normal);\n /* stylelint-disable-next-line primer/typography */\n line-height: 10px;\n color: var(--fgColor-muted);\n vertical-align: baseline;\n background: var(--bgColor-transparent);\n border: var(--borderWidth-thin) solid var(--borderColor-default);\n border-radius: var(--borderRadius-medium);\n box-shadow: none;\n gap: 0.5ch;\n transition: 80ms ease-in;\n transition-property: color, background-color, border-color;\n}\n\n.KeybindingHint-chord--emphasis {\n color: var(--fgColor-onEmphasis);\n background: var(--counter-bgColor-emphasis);\n border-color: transparent;\n /* React applies the medium radius and the 20px floor only to the default scheme */\n border-radius: var(--borderRadius-default);\n min-width: auto;\n}\n\n.KeybindingHint-chord--small {\n min-width: var(--base-size-16);\n padding: var(--base-size-2);\n /* stylelint-disable-next-line primer/typography */\n font-size: 11px;\n /* stylelint-disable-next-line primer/typography */\n line-height: var(--base-size-8);\n border-radius: var(--borderRadius-small);\n}\n"]}
@@ -0,0 +1,4 @@
1
+ <%= render(Primer::BaseComponent.new(**@system_arguments)) do %>
2
+ <%# Keep the <kbd> on one line: the only whitespace text node allowed is the single space between chord spans (visible separator and screen-reader word boundary). %>
3
+ <kbd class="KeybindingHint-kbd"><% fallback_chords.each_with_index do |chord, index| %><%= " " if index.positive? %><span class="<%= @chord_classes %>" data-kbd-chord><%= chord %></span><% end %></kbd>
4
+ <% end %>
@@ -0,0 +1,65 @@
1
+ /* KeybindingHint (port of Primer React KeybindingHint at 6794582843) */
2
+
3
+ /* The host carries no semantics; let the <kbd> be the flex/grid item, as in React. */
4
+ /* stylelint-disable-next-line selector-max-type */
5
+ keybinding-hint {
6
+ display: contents;
7
+ }
8
+
9
+ /* Reset user-agent <kbd> styling; matches KeybindingHint.module.css */
10
+ .KeybindingHint-kbd {
11
+ position: relative;
12
+ padding: 0;
13
+ overflow: visible;
14
+ font-family: inherit;
15
+ font-size: inherit;
16
+ /* stylelint-disable-next-line primer/typography */
17
+ line-height: unset;
18
+ color: inherit;
19
+ white-space: nowrap;
20
+ vertical-align: baseline;
21
+ background: none;
22
+ border: none;
23
+ box-shadow: none;
24
+ }
25
+
26
+ /* One bordered box per chord; matches Chord.module.css */
27
+ .KeybindingHint-chord {
28
+ display: inline-flex;
29
+ justify-content: center;
30
+ min-width: var(--base-size-20);
31
+ padding: var(--base-size-4);
32
+ overflow: hidden;
33
+ font-size: var(--text-body-size-small);
34
+ font-weight: var(--base-text-weight-normal);
35
+ /* stylelint-disable-next-line primer/typography */
36
+ line-height: 10px;
37
+ color: var(--fgColor-muted);
38
+ vertical-align: baseline;
39
+ background: var(--bgColor-transparent);
40
+ border: var(--borderWidth-thin) solid var(--borderColor-default);
41
+ border-radius: var(--borderRadius-medium);
42
+ box-shadow: none;
43
+ gap: 0.5ch;
44
+ transition: 80ms ease-in;
45
+ transition-property: color, background-color, border-color;
46
+ }
47
+
48
+ .KeybindingHint-chord--emphasis {
49
+ color: var(--fgColor-onEmphasis);
50
+ background: var(--counter-bgColor-emphasis);
51
+ border-color: transparent;
52
+ /* React applies the medium radius and the 20px floor only to the default scheme */
53
+ border-radius: var(--borderRadius-default);
54
+ min-width: auto;
55
+ }
56
+
57
+ .KeybindingHint-chord--small {
58
+ min-width: var(--base-size-16);
59
+ padding: var(--base-size-2);
60
+ /* stylelint-disable-next-line primer/typography */
61
+ font-size: 11px;
62
+ /* stylelint-disable-next-line primer/typography */
63
+ line-height: var(--base-size-8);
64
+ border-radius: var(--borderRadius-small);
65
+ }
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module OpenProject
5
+ # Displays a keyboard shortcut as a visible, screen-reader-friendly hint.
6
+ # Port of Primer React's `KeybindingHint`.
7
+ #
8
+ # The server renders a plain-text fallback inside the styled chord box.
9
+ # The `<keybinding-hint>` custom element replaces it with platform-specific
10
+ # names (for example ⌘ on Apple platforms, Ctrl elsewhere) and visually
11
+ # hidden accessible key names ("command", "shift", …).
12
+ #
13
+ # ## Translation
14
+ #
15
+ # Key names follow the current locale: visible condensed and full names,
16
+ # accessible names and the "then" spoken between chords of a sequence.
17
+ # The component looks them up in the `keybinding_hint` locale scope
18
+ # (English defaults in PVC's `config/locales/en.yml`) and passes the names
19
+ # for its keys to the element as JSON in `data-names`. Each name is looked
20
+ # up for the exact platform, then `other`, then Primer React's English
21
+ # tables. Glyphs such as ↑, ⇧ and ⏎ are not translated.
22
+ #
23
+ # ## Key syntax
24
+ #
25
+ # Use the key names `KeyboardEvent.key` reports ("Control", "Shift",
26
+ # "ArrowUp", "a", …), matching the github/hotkey format:
27
+ #
28
+ # - Join keys with `+` to form a chord pressed together: `"Mod+Shift+p"`.
29
+ # - Join chords with a space to form a sequence pressed one after the
30
+ # other: `"g i"` (g, then i).
31
+ # - Use `Plus` for the `+` key and `Space` for the space bar.
32
+ # - `Mod` means Command on Apple platforms and Control everywhere else.
33
+ #
34
+ # Comma-separated alternatives (`"s,/"`) are not supported. The component only
35
+ # displays hints; it does not register the shortcut.
36
+ #
37
+ # ## Terminology
38
+ #
39
+ # Primer React's `variant` is `scheme:` here (`normal` → `:default`,
40
+ # `onEmphasis` → `:emphasis`) and its `size="normal"` is `size: :medium`.
41
+ class KeybindingHint < Primer::Component
42
+ status :open_project
43
+
44
+ DEFAULT_FORMAT = :condensed
45
+ FORMAT_OPTIONS = [DEFAULT_FORMAT, :full].freeze
46
+
47
+ DEFAULT_SCHEME = :default
48
+ SCHEME_MAPPINGS = {
49
+ DEFAULT_SCHEME => "",
50
+ :emphasis => "KeybindingHint-chord--emphasis"
51
+ }.freeze
52
+ SCHEME_OPTIONS = SCHEME_MAPPINGS.keys.freeze
53
+
54
+ DEFAULT_SIZE = :medium
55
+ SIZE_MAPPINGS = {
56
+ DEFAULT_SIZE => "",
57
+ :small => "KeybindingHint-chord--small"
58
+ }.freeze
59
+ SIZE_OPTIONS = SIZE_MAPPINGS.keys.freeze
60
+
61
+ # @param keys [String] The keys of the shortcut, e.g. `"Mod+Shift+p"` or `"g i"`. See the class documentation for the syntax.
62
+ # @param format [Symbol] <%= one_of(Primer::OpenProject::KeybindingHint::FORMAT_OPTIONS) %> `:condensed` shows symbols (⌘⇧P) and suits menus and buttons; `:full` spells keys out (Command + Shift + P) and suits prose.
63
+ # @param scheme [Symbol] <%= one_of(Primer::OpenProject::KeybindingHint::SCHEME_OPTIONS) %> Use `:emphasis` on emphasis-coloured backgrounds.
64
+ # @param size [Symbol] <%= one_of(Primer::OpenProject::KeybindingHint::SIZE_OPTIONS) %>
65
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
66
+ def initialize(keys:, format: DEFAULT_FORMAT, scheme: DEFAULT_SCHEME, size: DEFAULT_SIZE, **system_arguments)
67
+ @keys = keys.to_s.strip
68
+ @format = fetch_or_fallback(FORMAT_OPTIONS, format, DEFAULT_FORMAT)
69
+ @scheme = fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)
70
+ @size = fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)
71
+
72
+ @system_arguments = deny_tag_argument(**system_arguments)
73
+ @system_arguments[:tag] = "keybinding-hint"
74
+ @system_arguments[:classes] = class_names(@system_arguments[:classes], "KeybindingHint")
75
+ @system_arguments[:data] = merge_data(
76
+ @system_arguments,
77
+ { data: { keys: @keys, format: @format, scheme: @scheme, size: @size } }
78
+ )
79
+
80
+ @chord_classes = class_names("KeybindingHint-chord", SCHEME_MAPPINGS[@scheme], SIZE_MAPPINGS[@size])
81
+ end
82
+
83
+ def render?
84
+ @keys.present?
85
+ end
86
+
87
+ # Translations depend on the locale at render time, not at construction.
88
+ def before_render
89
+ @names = Names.for(@keys)
90
+ @system_arguments[:data][:names] = @names.to_json
91
+ end
92
+
93
+ private
94
+
95
+ # Readable degraded output for no-JS and the pre-upgrade frame. Uses the
96
+ # translated condensed name for non-Apple platforms where one exists
97
+ # (`Mod` as Control); other keys keep their spelling with the first
98
+ # letter upcased, so `ArrowUp` stays `ArrowUp` and `p` becomes `P`.
99
+ def fallback_chords
100
+ @keys.split(/\s+/).compact_blank.map do |chord|
101
+ chord.split("+").compact_blank.map { |key| fallback_key_name(key) }.join("+")
102
+ end
103
+ end
104
+
105
+ def fallback_key_name(key)
106
+ token = key.downcase
107
+ token = "control" if token == "mod"
108
+ @names.dig("keys", token, "condensed", "other") || key.upcase_first
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,31 @@
1
+ import { buildKeyNames } from './keybinding_hint/names_from_scope';
2
+ /**
3
+ * Renders keyboard shortcut hints client-side, because only the browser knows
4
+ * the platform (⌘ vs ⌃). The server renders a plain-text fallback inside the
5
+ * chord box; this element replaces it once, then owns a <kbd> mount that
6
+ * lit-html renders into.
7
+ *
8
+ * Attributes (Catalyst `@attr`, so `data-*`): keys, format, scheme, size,
9
+ * platform ('' = detect; 'apple' | 'windows' | 'other' overrides, used by
10
+ * previews and tests), names (JSON of translated key names; see
11
+ * localized_names.ts).
12
+ */
13
+ export declare class KeybindingHintElement extends HTMLElement {
14
+ #private;
15
+ /** Builds `data-names` from i18n-js scopes, for hosts that render hints client-side. */
16
+ static buildNames: typeof buildKeyNames;
17
+ keys: string;
18
+ format: string;
19
+ scheme: string;
20
+ size: string;
21
+ platform: string;
22
+ names: string;
23
+ connectedCallback(): void;
24
+ disconnectedCallback(): void;
25
+ attributeChangedCallback(): void;
26
+ }
27
+ declare global {
28
+ interface Window {
29
+ KeybindingHintElement: typeof KeybindingHintElement;
30
+ }
31
+ }