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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/app/assets/javascripts/primer_view_components.js +11 -1
- data/app/assets/javascripts/primer_view_components.js.map +1 -1
- data/app/assets/styles/primer_view_components.css +1 -1
- data/app/assets/styles/primer_view_components.css.map +1 -1
- data/app/components/primer/alpha/action_bar.css +1 -1
- data/app/components/primer/alpha/action_bar.css.map +1 -1
- data/app/components/primer/alpha/action_list/item.rb +5 -1
- data/app/components/primer/alpha/action_list.css +1 -1
- data/app/components/primer/alpha/action_list.css.json +13 -11
- data/app/components/primer/alpha/action_list.css.map +1 -1
- data/app/components/primer/alpha/action_list.pcss +12 -0
- data/app/components/primer/alpha/action_menu/action_menu_element.d.ts +6 -0
- data/app/components/primer/alpha/action_menu/action_menu_element.js +389 -84
- data/app/components/primer/alpha/action_menu/action_menu_element.ts +439 -78
- data/app/components/primer/alpha/action_menu/action_menu_focus_zone_stack.d.ts +4 -1
- data/app/components/primer/alpha/action_menu/action_menu_focus_zone_stack.js +37 -13
- data/app/components/primer/alpha/action_menu/action_menu_focus_zone_stack.ts +41 -12
- data/app/components/primer/alpha/action_menu/menu.html.erb +27 -19
- data/app/components/primer/alpha/action_menu/menu.rb +7 -0
- data/app/components/primer/alpha/action_menu/primary_menu.rb +15 -0
- data/app/components/primer/alpha/action_menu.rb +55 -0
- data/app/components/primer/alpha/auto_complete.css +1 -1
- data/app/components/primer/alpha/auto_complete.css.map +1 -1
- data/app/components/primer/alpha/banner.css +1 -1
- data/app/components/primer/alpha/banner.css.map +1 -1
- data/app/components/primer/alpha/button_marketing.css +1 -1
- data/app/components/primer/alpha/button_marketing.css.map +1 -1
- data/app/components/primer/alpha/dialog.css +1 -1
- data/app/components/primer/alpha/dialog.css.map +1 -1
- data/app/components/primer/alpha/dropdown/menu.rb +1 -1
- data/app/components/primer/alpha/dropdown.css +1 -1
- data/app/components/primer/alpha/dropdown.css.json +1 -1
- data/app/components/primer/alpha/dropdown.css.map +1 -1
- data/app/components/primer/alpha/layout.css +1 -1
- data/app/components/primer/alpha/layout.css.json +3 -3
- data/app/components/primer/alpha/layout.css.map +1 -1
- data/app/components/primer/alpha/menu.css +1 -1
- data/app/components/primer/alpha/menu.css.json +3 -3
- data/app/components/primer/alpha/menu.css.map +1 -1
- data/app/components/primer/alpha/overlay.css +1 -1
- data/app/components/primer/alpha/overlay.css.map +1 -1
- data/app/components/primer/alpha/segmented_control.css +1 -1
- data/app/components/primer/alpha/segmented_control.css.json +1 -1
- data/app/components/primer/alpha/segmented_control.css.map +1 -1
- data/app/components/primer/alpha/select_panel.css +1 -1
- data/app/components/primer/alpha/select_panel.css.map +1 -1
- data/app/components/primer/alpha/skeleton_box.css +1 -1
- data/app/components/primer/alpha/skeleton_box.css.map +1 -1
- data/app/components/primer/alpha/stack.css +1 -1
- data/app/components/primer/alpha/stack.css.map +1 -1
- data/app/components/primer/alpha/stack_item.css +1 -1
- data/app/components/primer/alpha/stack_item.css.map +1 -1
- data/app/components/primer/alpha/tab_nav.css +1 -1
- data/app/components/primer/alpha/tab_nav.css.map +1 -1
- data/app/components/primer/alpha/text_field.css +1 -1
- data/app/components/primer/alpha/text_field.css.map +1 -1
- data/app/components/primer/alpha/toggle_switch.css +1 -1
- data/app/components/primer/alpha/toggle_switch.css.map +1 -1
- data/app/components/primer/alpha/tree_view.css +1 -1
- data/app/components/primer/alpha/tree_view.css.json +3 -3
- data/app/components/primer/alpha/tree_view.css.map +1 -1
- data/app/components/primer/alpha/underline_nav.css +1 -1
- data/app/components/primer/alpha/underline_nav.css.map +1 -1
- data/app/components/primer/beta/border_box.css +1 -1
- data/app/components/primer/beta/border_box.css.json +5 -5
- data/app/components/primer/beta/border_box.css.map +1 -1
- data/app/components/primer/beta/button.css +1 -1
- data/app/components/primer/beta/button.css.map +1 -1
- data/app/components/primer/beta/button.pcss +97 -0
- data/app/components/primer/beta/button.rb +15 -3
- data/app/components/primer/beta/counter.css +1 -1
- data/app/components/primer/beta/counter.css.map +1 -1
- data/app/components/primer/beta/flash.css +1 -1
- data/app/components/primer/beta/flash.css.map +1 -1
- data/app/components/primer/beta/link.css +1 -1
- data/app/components/primer/beta/link.css.json +1 -1
- data/app/components/primer/beta/link.css.map +1 -1
- data/app/components/primer/beta/popover.css +1 -1
- data/app/components/primer/beta/popover.css.map +1 -1
- data/app/components/primer/beta/progress_bar.css +1 -1
- data/app/components/primer/beta/progress_bar.css.map +1 -1
- data/app/components/primer/beta/relative_time.rb +7 -1
- data/app/components/primer/beta/state.css +1 -1
- data/app/components/primer/beta/state.css.json +2 -2
- data/app/components/primer/beta/state.css.map +1 -1
- data/app/components/primer/beta/timeline_item.css +1 -1
- data/app/components/primer/beta/timeline_item.css.map +1 -1
- data/app/components/primer/open_project/border_grid.css +1 -1
- data/app/components/primer/open_project/border_grid.css.map +1 -1
- data/app/components/primer/open_project/color_field.css +1 -1
- data/app/components/primer/open_project/color_field.css.map +1 -1
- data/app/components/primer/open_project/inline_message.css +1 -1
- data/app/components/primer/open_project/inline_message.css.map +1 -1
- data/app/components/primer/open_project/input_group.css +1 -1
- data/app/components/primer/open_project/input_group.css.map +1 -1
- data/app/components/primer/open_project/keybinding_hint/chords.d.ts +5 -0
- data/app/components/primer/open_project/keybinding_hint/chords.js +29 -0
- data/app/components/primer/open_project/keybinding_hint/chords.ts +38 -0
- data/app/components/primer/open_project/keybinding_hint/key_names.d.ts +16 -0
- data/app/components/primer/open_project/keybinding_hint/key_names.js +107 -0
- data/app/components/primer/open_project/keybinding_hint/key_names.ts +116 -0
- data/app/components/primer/open_project/keybinding_hint/localized_names.d.ts +22 -0
- data/app/components/primer/open_project/keybinding_hint/localized_names.js +47 -0
- data/app/components/primer/open_project/keybinding_hint/localized_names.ts +71 -0
- data/app/components/primer/open_project/keybinding_hint/names.rb +92 -0
- data/app/components/primer/open_project/keybinding_hint/names_from_scope.d.ts +21 -0
- data/app/components/primer/open_project/keybinding_hint/names_from_scope.js +81 -0
- data/app/components/primer/open_project/keybinding_hint/names_from_scope.ts +96 -0
- data/app/components/primer/open_project/keybinding_hint/platform.d.ts +10 -0
- data/app/components/primer/open_project/keybinding_hint/platform.js +24 -0
- data/app/components/primer/open_project/keybinding_hint/platform.ts +34 -0
- data/app/components/primer/open_project/keybinding_hint/platform_override.d.ts +2 -0
- data/app/components/primer/open_project/keybinding_hint/platform_override.js +4 -0
- data/app/components/primer/open_project/keybinding_hint/platform_override.ts +7 -0
- data/app/components/primer/open_project/keybinding_hint.css +1 -0
- data/app/components/primer/open_project/keybinding_hint.css.json +10 -0
- data/app/components/primer/open_project/keybinding_hint.css.map +1 -0
- data/app/components/primer/open_project/keybinding_hint.html.erb +4 -0
- data/app/components/primer/open_project/keybinding_hint.pcss +65 -0
- data/app/components/primer/open_project/keybinding_hint.rb +112 -0
- data/app/components/primer/open_project/keybinding_hint_element.d.ts +31 -0
- data/app/components/primer/open_project/keybinding_hint_element.js +183 -0
- data/app/components/primer/open_project/keybinding_hint_element.ts +152 -0
- data/app/components/primer/open_project/page_header.css +1 -1
- data/app/components/primer/open_project/page_header.css.json +2 -2
- data/app/components/primer/open_project/page_header.css.map +1 -1
- data/app/components/primer/open_project/pagination.css +1 -1
- data/app/components/primer/open_project/pagination.css.json +1 -1
- data/app/components/primer/open_project/pagination.css.map +1 -1
- data/app/components/primer/open_project/sub_header.css +1 -1
- data/app/components/primer/open_project/sub_header.css.map +1 -1
- data/app/components/primer/primer.d.ts +1 -0
- data/app/components/primer/primer.js +1 -0
- data/app/components/primer/primer.pcss +1 -0
- data/app/components/primer/primer.ts +1 -0
- data/app/components/primer/truncate.css +1 -1
- data/app/components/primer/truncate.css.json +3 -4
- data/app/components/primer/truncate.css.map +1 -1
- data/app/controllers/primer/view_components/action_menu_controller.rb +35 -0
- data/app/views/primer/view_components/action_menu/deferred.html.erb +25 -11
- data/app/views/primer/view_components/action_menu/deferred_form.html.erb +10 -0
- data/app/views/primer/view_components/action_menu/deferred_preload.html.erb +7 -1
- data/config/locales/en.yml +179 -0
- data/config/routes.rb +1 -0
- data/lib/primer/accessibility.rb +1 -2
- data/lib/primer/classify.rb +1 -2
- data/lib/primer/view_components/version.rb +1 -1
- data/previews/primer/alpha/action_menu_preview/deferred_refresh.html.erb +34 -0
- data/previews/primer/alpha/action_menu_preview/deferred_refresh_form.html.erb +9 -0
- data/previews/primer/alpha/action_menu_preview.rb +14 -0
- data/previews/primer/open_project/keybinding_hint_preview/full_format.html.erb +3 -0
- data/previews/primer/open_project/keybinding_hint_preview/in_action_list.html.erb +12 -0
- data/previews/primer/open_project/keybinding_hint_preview/in_button.html.erb +24 -0
- data/previews/primer/open_project/keybinding_hint_preview/platforms.html.erb +8 -0
- data/previews/primer/open_project/keybinding_hint_preview/playground.html.erb +4 -0
- data/previews/primer/open_project/keybinding_hint_preview/prose.html.erb +3 -0
- data/previews/primer/open_project/keybinding_hint_preview/schemes.html.erb +6 -0
- data/previews/primer/open_project/keybinding_hint_preview/sequence.html.erb +1 -0
- data/previews/primer/open_project/keybinding_hint_preview/sizes.html.erb +4 -0
- data/previews/primer/open_project/keybinding_hint_preview.rb +71 -0
- data/static/arguments.json +53 -1
- data/static/audited_at.json +1 -0
- data/static/classes.json +12 -0
- data/static/classnames.cjs +4 -0
- data/static/classnames.js +4 -0
- data/static/constants.json +35 -0
- data/static/info_arch.json +234 -8
- data/static/previews.json +164 -0
- data/static/statuses.json +1 -0
- metadata +42 -5
- data/app/components/primer/alpha/text_field.css.json +0 -134
- data/app/components/primer/alpha/toggle_switch.css.json +0 -40
- data/app/components/primer/alpha/underline_nav.css.json +0 -26
- 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 @@
|
|
|
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 @@
|
|
|
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
|
+
}
|