@jsenv/navi 0.10.1 → 0.11.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.
- package/dist/jsenv_navi.js +13858 -23295
- package/dist/jsenv_navi.js.map +1281 -0
- package/package.json +5 -7
- package/index.js +0 -122
- package/src/action_private_properties.js +0 -11
- package/src/action_proxy_test.html +0 -353
- package/src/action_run_states.js +0 -5
- package/src/actions.js +0 -1401
- package/src/browser_integration/browser_integration.js +0 -216
- package/src/browser_integration/document_back_and_forward.js +0 -17
- package/src/browser_integration/document_loading_signal.js +0 -100
- package/src/browser_integration/document_state_signal.js +0 -9
- package/src/browser_integration/document_url_signal.js +0 -9
- package/src/browser_integration/use_is_visited.js +0 -19
- package/src/browser_integration/via_history.js +0 -232
- package/src/browser_integration/via_navigation.js +0 -168
- package/src/components/action_execution/form_context.js +0 -5
- package/src/components/action_execution/render_actionable_component.jsx +0 -29
- package/src/components/action_execution/use_action.js +0 -99
- package/src/components/action_execution/use_execute_action.js +0 -177
- package/src/components/action_execution/use_run_on_mount.js +0 -9
- package/src/components/action_renderer.jsx +0 -125
- package/src/components/callout/callout.js +0 -990
- package/src/components/callout/callout_demo.html +0 -201
- package/src/components/callout/test_dynamic_positioning.html +0 -161
- package/src/components/callout/test_html_document_iframe.html +0 -182
- package/src/components/demos/0_button_demo.html +0 -707
- package/src/components/demos/10_column_reordering_debug.html +0 -277
- package/src/components/demos/11_table_selection_debug.html +0 -432
- package/src/components/demos/1_checkbox_demo.html +0 -754
- package/src/components/demos/2_input_textual_demo.html +0 -286
- package/src/components/demos/3_radio_demo.html +0 -874
- package/src/components/demos/4_select_demo.html +0 -100
- package/src/components/demos/5_list_scrollable_demo.html +0 -153
- package/src/components/demos/6_tablist_demo.html +0 -77
- package/src/components/demos/7_table_selection_demo.html +0 -176
- package/src/components/demos/8_table_fixed_headers_demo.html +0 -584
- package/src/components/demos/9_table_column_drag_demo.html +0 -325
- package/src/components/demos/action/0_button_demo.html +0 -204
- package/src/components/demos/action/10_shortcuts_demo.html +0 -189
- package/src/components/demos/action/11_nested_shortcuts_demo.xhtml +0 -401
- package/src/components/demos/action/1_input_text_demo.html +0 -876
- package/src/components/demos/action/2_form_multiple.html +0 -303
- package/src/components/demos/action/3_details_demo.html +0 -203
- package/src/components/demos/action/4_input_checkbox_demo.html +0 -731
- package/src/components/demos/action/5_input_checkbox_state_demo.html +0 -270
- package/src/components/demos/action/6_checkbox_list_demo.html +0 -341
- package/src/components/demos/action/7_radio_list_demo.html +0 -357
- package/src/components/demos/action/8_editable_demo.html +0 -431
- package/src/components/demos/action/9_link_demo.html +0 -194
- package/src/components/demos/demo.md +0 -0
- package/src/components/demos/route/basic/basic.html +0 -14
- package/src/components/demos/route/basic/basic_route_demo.jsx +0 -224
- package/src/components/demos/route/multi/multi.html +0 -14
- package/src/components/demos/route/multi/multi_route_demo.jsx +0 -277
- package/src/components/demos/ui_transition/0_action_renderer_ui_transition_demo.html +0 -695
- package/src/components/demos/ui_transition/1_nested_ui_transition_demo.html +0 -429
- package/src/components/demos/ui_transition/2_height_transition_test.html +0 -295
- package/src/components/details/details.jsx +0 -245
- package/src/components/details/summary_marker.jsx +0 -141
- package/src/components/edition/editable.jsx +0 -186
- package/src/components/error_boundary_context.js +0 -9
- package/src/components/field/README.md +0 -247
- package/src/components/field/button.jsx +0 -429
- package/src/components/field/checkbox_list.jsx +0 -185
- package/src/components/field/collect_form_element_values.js +0 -82
- package/src/components/field/custom_field.js +0 -106
- package/src/components/field/form.jsx +0 -209
- package/src/components/field/input.jsx +0 -16
- package/src/components/field/input_checkbox.jsx +0 -434
- package/src/components/field/input_radio.jsx +0 -432
- package/src/components/field/input_textual.jsx +0 -389
- package/src/components/field/label.jsx +0 -46
- package/src/components/field/radio_list.jsx +0 -183
- package/src/components/field/select.jsx +0 -256
- package/src/components/field/use_action_events.js +0 -132
- package/src/components/field/use_form_events.js +0 -59
- package/src/components/field/use_ui_state_controller.js +0 -506
- package/src/components/item_tracker/README.md +0 -461
- package/src/components/item_tracker/use_isolated_item_tracker.jsx +0 -209
- package/src/components/item_tracker/use_isolated_item_tracker_demo.html +0 -148
- package/src/components/item_tracker/use_isolated_item_tracker_demo.jsx +0 -460
- package/src/components/item_tracker/use_item_tracker.jsx +0 -143
- package/src/components/item_tracker/use_item_tracker_demo.html +0 -207
- package/src/components/item_tracker/use_item_tracker_demo.jsx +0 -216
- package/src/components/keyboard_shortcuts/active_keyboard_shortcuts.jsx +0 -87
- package/src/components/keyboard_shortcuts/aria_key_shortcuts.js +0 -61
- package/src/components/keyboard_shortcuts/keyboard_key_meta.js +0 -17
- package/src/components/keyboard_shortcuts/keyboard_shortcuts.js +0 -371
- package/src/components/keyboard_shortcuts/os.js +0 -9
- package/src/components/layout/demos/demo_flex.html +0 -638
- package/src/components/layout/demos/demo_layout_style_buttons.html +0 -351
- package/src/components/layout/demos/demo_layout_style_input.html +0 -226
- package/src/components/layout/demos/demo_layout_style_text.html +0 -514
- package/src/components/layout/flex.jsx +0 -109
- package/src/components/layout/layout_context.jsx +0 -3
- package/src/components/layout/spacing.jsx +0 -20
- package/src/components/layout/use_layout_style.js +0 -249
- package/src/components/link/link.jsx +0 -267
- package/src/components/link/link_with_icon.jsx +0 -52
- package/src/components/loader/loader_background.jsx +0 -372
- package/src/components/loader/loading_spinner.jsx +0 -68
- package/src/components/loader/network_speed.js +0 -83
- package/src/components/loader/rectangle_loading.jsx +0 -244
- package/src/components/props_composition/demos/demo_with_props_style.html +0 -81
- package/src/components/props_composition/with_props_class_name.js +0 -37
- package/src/components/props_composition/with_props_style.js +0 -26
- package/src/components/route.jsx +0 -19
- package/src/components/selection/selection.jsx +0 -1583
- package/src/components/svg/font_sized_svg.jsx +0 -59
- package/src/components/svg/icon_and_text.jsx +0 -21
- package/src/components/svg/svg_mask_overlay.jsx +0 -105
- package/src/components/table/drag/table_drag.jsx +0 -506
- package/src/components/table/resize/table_resize.jsx +0 -650
- package/src/components/table/resize/table_size.js +0 -43
- package/src/components/table/selection/table_selection.js +0 -106
- package/src/components/table/selection/table_selection.jsx +0 -203
- package/src/components/table/sticky/sticky_group.js +0 -354
- package/src/components/table/sticky/table_sticky.js +0 -25
- package/src/components/table/sticky/table_sticky.jsx +0 -501
- package/src/components/table/table.jsx +0 -721
- package/src/components/table/table_css.js +0 -211
- package/src/components/table/table_ui.jsx +0 -49
- package/src/components/table/use_cells_and_columns.js +0 -90
- package/src/components/table/use_object_array_to_cells.js +0 -46
- package/src/components/table/z_indexes.js +0 -23
- package/src/components/tablist/tablist.jsx +0 -99
- package/src/components/text/demos/demo_text_and_icon.html +0 -421
- package/src/components/text/overflow.jsx +0 -15
- package/src/components/text/text.jsx +0 -83
- package/src/components/text/text_and_count.jsx +0 -28
- package/src/components/ui_transition.jsx +0 -128
- package/src/components/use_auto_focus.js +0 -94
- package/src/components/use_batch_during_render.js +0 -33
- package/src/components/use_debounce_true.js +0 -31
- package/src/components/use_dependencies_diff.js +0 -35
- package/src/components/use_focus_group.js +0 -20
- package/src/components/use_initial_value.js +0 -78
- package/src/components/use_is_visited.js +0 -19
- package/src/components/use_ref_array.js +0 -38
- package/src/components/use_signal_sync.js +0 -50
- package/src/components/use_stable_callback.js +0 -68
- package/src/components/use_state_array.js +0 -47
- package/src/docs/actions.md +0 -250
- package/src/docs/demos/resource/action_status.jsx +0 -42
- package/src/docs/demos/resource/demo.md +0 -1
- package/src/docs/demos/resource/resource_demo_0.html +0 -84
- package/src/docs/demos/resource/resource_demo_10_post_gc.html +0 -364
- package/src/docs/demos/resource/resource_demo_11_describe_many.html +0 -362
- package/src/docs/demos/resource/resource_demo_2.html +0 -173
- package/src/docs/demos/resource/resource_demo_3_filtered_users.html +0 -415
- package/src/docs/demos/resource/resource_demo_4_details.html +0 -284
- package/src/docs/demos/resource/resource_demo_5_renderer_lazy.html +0 -115
- package/src/docs/demos/resource/resource_demo_6_gc.html +0 -217
- package/src/docs/demos/resource/resource_demo_7_child_gc.html +0 -240
- package/src/docs/demos/resource/resource_demo_8_proxy_gc.html +0 -319
- package/src/docs/demos/resource/resource_demo_9_describe_one.html +0 -472
- package/src/docs/demos/resource/tata.jsx +0 -3
- package/src/docs/demos/resource/toto.jsx +0 -3
- package/src/docs/demos/user_nav/user_nav.html +0 -12
- package/src/docs/demos/user_nav/user_nav.jsx +0 -330
- package/src/docs/resource_dependencies.md +0 -103
- package/src/docs/resource_with_params.md +0 -80
- package/src/navi_css_vars.js +0 -14
- package/src/notes.md +0 -34
- package/src/route/route.js +0 -596
- package/src/route/route.xtest.html +0 -228
- package/src/store/array_signal_store.js +0 -537
- package/src/store/local_storage_signal.js +0 -17
- package/src/store/resource_graph.js +0 -1304
- package/src/store/tests/resource_graph_autoreload_demo.html +0 -12
- package/src/store/tests/resource_graph_autoreload_demo.jsx +0 -964
- package/src/store/tests/resource_graph_dependencies.test_manual.js +0 -95
- package/src/store/value_in_local_storage.js +0 -187
- package/src/symbol_object_signal.js +0 -1
- package/src/use_action_data.js +0 -10
- package/src/use_action_status.js +0 -47
- package/src/utils/add_many_event_listeners.js +0 -15
- package/src/utils/array_add_remove.js +0 -61
- package/src/utils/array_signal.js +0 -15
- package/src/utils/compare_two_js_values.js +0 -172
- package/src/utils/execute_with_cleanup.js +0 -21
- package/src/utils/get_caller_info.js +0 -85
- package/src/utils/is_signal.js +0 -20
- package/src/utils/js_value_weak_map.js +0 -162
- package/src/utils/js_value_weak_map_demo.html +0 -690
- package/src/utils/merge_two_js_values.js +0 -53
- package/src/utils/stringify_for_display.js +0 -131
- package/src/utils/weak_effect.js +0 -48
- package/src/validation/constraints/confirm_constraint.js +0 -14
- package/src/validation/constraints/create_unique_value_constraint.js +0 -27
- package/src/validation/constraints/native_constraints.js +0 -338
- package/src/validation/constraints/readonly_constraint.js +0 -41
- package/src/validation/constraints/same_as_constraint.js +0 -42
- package/src/validation/constraints/single_space_constraint.js +0 -13
- package/src/validation/custom_constraint_validation.js +0 -793
- package/src/validation/custom_message.js +0 -18
- package/src/validation/demos/browser_style.png +0 -0
- package/src/validation/demos/demo_same_as_constraint.html +0 -259
- package/src/validation/demos/form_validation_demo.html +0 -142
- package/src/validation/demos/form_validation_demo_preact.html +0 -87
- package/src/validation/demos/form_validation_native_popover_demo.html +0 -168
- package/src/validation/demos/form_validation_vs_native_demo.html +0 -172
- package/src/validation/hooks/use_constraints.js +0 -23
- package/src/validation/hooks/use_custom_validation_ref.js +0 -73
- package/src/validation/hooks/use_validation_message.js +0 -19
- package/src/validation/input_change_effect.js +0 -106
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { isMac } from "./os.js";
|
|
2
|
-
|
|
3
|
-
// Maps canonical browser key names to their user-friendly aliases.
|
|
4
|
-
// Used for both event matching and ARIA normalization.
|
|
5
|
-
export const keyMapping = {
|
|
6
|
-
" ": { alias: ["space"] },
|
|
7
|
-
"escape": { alias: ["esc"] },
|
|
8
|
-
"arrowup": { alias: ["up"] },
|
|
9
|
-
"arrowdown": { alias: ["down"] },
|
|
10
|
-
"arrowleft": { alias: ["left"] },
|
|
11
|
-
"arrowright": { alias: ["right"] },
|
|
12
|
-
"delete": { alias: ["del"] },
|
|
13
|
-
// Platform-specific mappings
|
|
14
|
-
...(isMac
|
|
15
|
-
? { delete: { alias: ["backspace"] } }
|
|
16
|
-
: { backspace: { alias: ["delete"] } }),
|
|
17
|
-
};
|
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
import { activeElementSignal, canInterceptKeys } from "@jsenv/dom";
|
|
2
|
-
import { effect, signal } from "@preact/signals";
|
|
3
|
-
import { useEffect, useRef } from "preact/hooks";
|
|
4
|
-
|
|
5
|
-
import { requestAction } from "../../validation/custom_constraint_validation.js";
|
|
6
|
-
import { useAction } from "../action_execution/use_action.js";
|
|
7
|
-
import { useExecuteAction } from "../action_execution/use_execute_action.js";
|
|
8
|
-
import { useActionEvents } from "../field/use_action_events.js";
|
|
9
|
-
import { keyMapping } from "./keyboard_key_meta.js";
|
|
10
|
-
import { isMac } from "./os.js";
|
|
11
|
-
|
|
12
|
-
export const activeShortcutsSignal = signal([]);
|
|
13
|
-
const shortcutsMap = new Map();
|
|
14
|
-
|
|
15
|
-
const areShortcutsEqual = (shortcutA, shortcutB) => {
|
|
16
|
-
return (
|
|
17
|
-
shortcutA.key === shortcutB.key &&
|
|
18
|
-
shortcutA.description === shortcutB.description &&
|
|
19
|
-
shortcutA.enabled === shortcutB.enabled
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const areShortcutArraysEqual = (arrayA, arrayB) => {
|
|
24
|
-
if (arrayA.length !== arrayB.length) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
for (let i = 0; i < arrayA.length; i++) {
|
|
29
|
-
if (!areShortcutsEqual(arrayA[i], arrayB[i])) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return true;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const updateActiveShortcuts = () => {
|
|
38
|
-
const activeElement = activeElementSignal.peek();
|
|
39
|
-
const currentActiveShortcuts = activeShortcutsSignal.peek();
|
|
40
|
-
const activeShortcuts = [];
|
|
41
|
-
for (const [element, { shortcuts }] of shortcutsMap) {
|
|
42
|
-
if (element === activeElement || element.contains(activeElement)) {
|
|
43
|
-
activeShortcuts.push(...shortcuts);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Only update if shortcuts have actually changed
|
|
48
|
-
if (!areShortcutArraysEqual(currentActiveShortcuts, activeShortcuts)) {
|
|
49
|
-
activeShortcutsSignal.value = activeShortcuts;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
effect(() => {
|
|
53
|
-
// eslint-disable-next-line no-unused-expressions
|
|
54
|
-
activeElementSignal.value;
|
|
55
|
-
updateActiveShortcuts();
|
|
56
|
-
});
|
|
57
|
-
const addShortcuts = (element, shortcuts) => {
|
|
58
|
-
shortcutsMap.set(element, { shortcuts });
|
|
59
|
-
updateActiveShortcuts();
|
|
60
|
-
};
|
|
61
|
-
const removeShortcuts = (element) => {
|
|
62
|
-
shortcutsMap.delete(element);
|
|
63
|
-
updateActiveShortcuts();
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export const useKeyboardShortcuts = (
|
|
67
|
-
elementRef,
|
|
68
|
-
shortcuts,
|
|
69
|
-
{
|
|
70
|
-
onActionPrevented,
|
|
71
|
-
onActionStart,
|
|
72
|
-
onActionAbort,
|
|
73
|
-
onActionError,
|
|
74
|
-
onActionEnd,
|
|
75
|
-
allowConcurrentActions,
|
|
76
|
-
} = {},
|
|
77
|
-
) => {
|
|
78
|
-
if (!elementRef) {
|
|
79
|
-
throw new Error(
|
|
80
|
-
"useKeyboardShortcuts requires an elementRef to attach shortcuts to.",
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const executeAction = useExecuteAction(elementRef);
|
|
85
|
-
const shortcutActionIsBusyRef = useRef(false);
|
|
86
|
-
useActionEvents(elementRef, {
|
|
87
|
-
actionOrigin: "keyboard_shortcut",
|
|
88
|
-
onPrevented: onActionPrevented,
|
|
89
|
-
onAction: (actionEvent) => {
|
|
90
|
-
const { shortcut } = actionEvent.detail.meta || {};
|
|
91
|
-
if (!shortcut) {
|
|
92
|
-
// not a shortcut (an other interaction triggered the action, don't request it again)
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
// action can be a function or an action object, whem a function we must "wrap" it in a function returning that function
|
|
96
|
-
// otherwise setState would call that action immediately
|
|
97
|
-
// setAction(() => actionEvent.detail.action);
|
|
98
|
-
executeAction(actionEvent, {
|
|
99
|
-
requester: document.activeElement,
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
onStart: (e) => {
|
|
103
|
-
const { shortcut } = e.detail.meta || {};
|
|
104
|
-
if (!shortcut) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (!allowConcurrentActions) {
|
|
108
|
-
shortcutActionIsBusyRef.current = true;
|
|
109
|
-
}
|
|
110
|
-
shortcut.onStart?.(e);
|
|
111
|
-
onActionStart?.(e);
|
|
112
|
-
},
|
|
113
|
-
onAbort: (e) => {
|
|
114
|
-
const { shortcut } = e.detail.meta || {};
|
|
115
|
-
if (!shortcut) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
shortcutActionIsBusyRef.current = false;
|
|
119
|
-
shortcut.onAbort?.(e);
|
|
120
|
-
onActionAbort?.(e);
|
|
121
|
-
},
|
|
122
|
-
onError: (error, e) => {
|
|
123
|
-
const { shortcut } = e.detail.meta || {};
|
|
124
|
-
if (!shortcut) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
shortcutActionIsBusyRef.current = false;
|
|
128
|
-
shortcut.onError?.(error, e);
|
|
129
|
-
onActionError?.(error, e);
|
|
130
|
-
},
|
|
131
|
-
onEnd: (e) => {
|
|
132
|
-
const { shortcut } = e.detail.meta || {};
|
|
133
|
-
if (!shortcut) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
shortcutActionIsBusyRef.current = false;
|
|
137
|
-
shortcut.onEnd?.(e);
|
|
138
|
-
onActionEnd?.(e);
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
const shortcutDeps = [];
|
|
143
|
-
for (const shortcut of shortcuts) {
|
|
144
|
-
shortcutDeps.push(
|
|
145
|
-
shortcut.key,
|
|
146
|
-
shortcut.description,
|
|
147
|
-
shortcut.enabled,
|
|
148
|
-
shortcut.confirmMessage,
|
|
149
|
-
);
|
|
150
|
-
shortcut.action = useAction(shortcut.action);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
useEffect(() => {
|
|
154
|
-
const element = elementRef.current;
|
|
155
|
-
const shortcutsCopy = [];
|
|
156
|
-
for (const shortcutCandidate of shortcuts) {
|
|
157
|
-
shortcutsCopy.push({
|
|
158
|
-
...shortcutCandidate,
|
|
159
|
-
handler: (keyboardEvent) => {
|
|
160
|
-
if (shortcutCandidate.handler) {
|
|
161
|
-
return shortcutCandidate.handler(keyboardEvent);
|
|
162
|
-
}
|
|
163
|
-
if (shortcutActionIsBusyRef.current) {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
const { action } = shortcutCandidate;
|
|
167
|
-
return requestAction(element, action, {
|
|
168
|
-
actionOrigin: "keyboard_shortcut",
|
|
169
|
-
event: keyboardEvent,
|
|
170
|
-
requester: document.activeElement,
|
|
171
|
-
confirmMessage: shortcutCandidate.confirmMessage,
|
|
172
|
-
meta: {
|
|
173
|
-
shortcut: shortcutCandidate,
|
|
174
|
-
},
|
|
175
|
-
});
|
|
176
|
-
},
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
addShortcuts(element, shortcuts);
|
|
181
|
-
|
|
182
|
-
const onKeydown = (event) => {
|
|
183
|
-
applyKeyboardShortcuts(shortcutsCopy, event);
|
|
184
|
-
};
|
|
185
|
-
element.addEventListener("keydown", onKeydown);
|
|
186
|
-
return () => {
|
|
187
|
-
element.removeEventListener("keydown", onKeydown);
|
|
188
|
-
removeShortcuts(element);
|
|
189
|
-
};
|
|
190
|
-
}, [shortcutDeps]);
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const applyKeyboardShortcuts = (shortcuts, keyboardEvent) => {
|
|
194
|
-
if (!canInterceptKeys(keyboardEvent)) {
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
for (const shortcutCandidate of shortcuts) {
|
|
198
|
-
let { enabled = true, key } = shortcutCandidate;
|
|
199
|
-
if (!enabled) {
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (typeof key === "function") {
|
|
204
|
-
const keyReturnValue = key(keyboardEvent);
|
|
205
|
-
if (!keyReturnValue) {
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
key = keyReturnValue;
|
|
209
|
-
}
|
|
210
|
-
if (!key) {
|
|
211
|
-
console.error(shortcutCandidate);
|
|
212
|
-
throw new TypeError(`key is required in keyboard shortcut, got ${key}`);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Handle platform-specific combination objects
|
|
216
|
-
let actualCombination;
|
|
217
|
-
let crossPlatformCombination;
|
|
218
|
-
if (typeof key === "object" && key !== null) {
|
|
219
|
-
actualCombination = isMac ? key.mac : key.other;
|
|
220
|
-
} else {
|
|
221
|
-
actualCombination = key;
|
|
222
|
-
if (containsPlatformSpecificKeys(key)) {
|
|
223
|
-
crossPlatformCombination = generateCrossPlatformCombination(key);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Check both the actual combination and cross-platform combination
|
|
228
|
-
const matchesActual =
|
|
229
|
-
actualCombination &&
|
|
230
|
-
keyboardEventIsMatchingKeyCombination(keyboardEvent, actualCombination);
|
|
231
|
-
const matchesCrossPlatform =
|
|
232
|
-
crossPlatformCombination &&
|
|
233
|
-
crossPlatformCombination !== actualCombination &&
|
|
234
|
-
keyboardEventIsMatchingKeyCombination(
|
|
235
|
-
keyboardEvent,
|
|
236
|
-
crossPlatformCombination,
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
if (!matchesActual && !matchesCrossPlatform) {
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
if (typeof enabled === "function" && !enabled(keyboardEvent)) {
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
const returnValue = shortcutCandidate.handler(keyboardEvent);
|
|
246
|
-
if (returnValue) {
|
|
247
|
-
keyboardEvent.preventDefault();
|
|
248
|
-
}
|
|
249
|
-
return shortcutCandidate;
|
|
250
|
-
}
|
|
251
|
-
return null;
|
|
252
|
-
};
|
|
253
|
-
const containsPlatformSpecificKeys = (combination) => {
|
|
254
|
-
const lowerCombination = combination.toLowerCase();
|
|
255
|
-
const macSpecificKeys = ["command", "cmd"];
|
|
256
|
-
|
|
257
|
-
return macSpecificKeys.some((key) => lowerCombination.includes(key));
|
|
258
|
-
};
|
|
259
|
-
const generateCrossPlatformCombination = (combination) => {
|
|
260
|
-
let crossPlatform = combination;
|
|
261
|
-
|
|
262
|
-
if (isMac) {
|
|
263
|
-
// No need to convert anything TO Windows/Linux-specific format since we're on Mac
|
|
264
|
-
return null;
|
|
265
|
-
}
|
|
266
|
-
// If not on Mac but combination contains Mac-specific keys, generate Windows equivalent
|
|
267
|
-
crossPlatform = crossPlatform.replace(/\bcommand\b/gi, "control");
|
|
268
|
-
crossPlatform = crossPlatform.replace(/\bcmd\b/gi, "control");
|
|
269
|
-
|
|
270
|
-
return crossPlatform;
|
|
271
|
-
};
|
|
272
|
-
const keyboardEventIsMatchingKeyCombination = (event, keyCombination) => {
|
|
273
|
-
const keys = keyCombination.toLowerCase().split("+");
|
|
274
|
-
|
|
275
|
-
for (const key of keys) {
|
|
276
|
-
let modifierFound = false;
|
|
277
|
-
|
|
278
|
-
// Check if this key is a modifier
|
|
279
|
-
for (const [eventProperty, config] of Object.entries(modifierKeyMapping)) {
|
|
280
|
-
const allNames = [...config.names];
|
|
281
|
-
|
|
282
|
-
// Add Mac-specific names only if we're on Mac and they exist
|
|
283
|
-
if (isMac && config.macNames) {
|
|
284
|
-
allNames.push(...config.macNames);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (allNames.includes(key)) {
|
|
288
|
-
// Check if the corresponding event property is pressed
|
|
289
|
-
if (!event[eventProperty]) {
|
|
290
|
-
return false;
|
|
291
|
-
}
|
|
292
|
-
modifierFound = true;
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
if (modifierFound) {
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// Check if it's a range pattern like "a-z" or "0-9"
|
|
301
|
-
if (key.includes("-") && key.length === 3) {
|
|
302
|
-
const [startChar, dash, endChar] = key;
|
|
303
|
-
if (dash === "-") {
|
|
304
|
-
// Only check ranges for single alphanumeric characters
|
|
305
|
-
const eventKey = event.key.toLowerCase();
|
|
306
|
-
if (eventKey.length !== 1) {
|
|
307
|
-
return false; // Not a single character key
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// Only allow a-z and 0-9 ranges
|
|
311
|
-
const isValidRange =
|
|
312
|
-
(startChar >= "a" && endChar <= "z") ||
|
|
313
|
-
(startChar >= "0" && endChar <= "9");
|
|
314
|
-
|
|
315
|
-
if (!isValidRange) {
|
|
316
|
-
return false; // Invalid range pattern
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const eventKeyCode = eventKey.charCodeAt(0);
|
|
320
|
-
const startCode = startChar.charCodeAt(0);
|
|
321
|
-
const endCode = endChar.charCodeAt(0);
|
|
322
|
-
|
|
323
|
-
if (eventKeyCode >= startCode && eventKeyCode <= endCode) {
|
|
324
|
-
continue; // Range matched
|
|
325
|
-
}
|
|
326
|
-
return false; // Range not matched
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// If it's not a modifier or range, check if it matches the actual key
|
|
331
|
-
if (!isSameKey(event.key, key)) {
|
|
332
|
-
return false;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return true;
|
|
336
|
-
};
|
|
337
|
-
// Configuration for mapping shortcut key names to browser event properties
|
|
338
|
-
const modifierKeyMapping = {
|
|
339
|
-
metaKey: {
|
|
340
|
-
names: ["meta"],
|
|
341
|
-
macNames: ["command", "cmd"],
|
|
342
|
-
},
|
|
343
|
-
ctrlKey: {
|
|
344
|
-
names: ["control", "ctrl"],
|
|
345
|
-
},
|
|
346
|
-
shiftKey: {
|
|
347
|
-
names: ["shift"],
|
|
348
|
-
},
|
|
349
|
-
altKey: {
|
|
350
|
-
names: ["alt"],
|
|
351
|
-
macNames: ["option"],
|
|
352
|
-
},
|
|
353
|
-
};
|
|
354
|
-
const isSameKey = (browserEventKey, key) => {
|
|
355
|
-
browserEventKey = browserEventKey.toLowerCase();
|
|
356
|
-
key = key.toLowerCase();
|
|
357
|
-
|
|
358
|
-
if (browserEventKey === key) {
|
|
359
|
-
return true;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// Check if either key is an alias for the other
|
|
363
|
-
for (const [canonicalKey, config] of Object.entries(keyMapping)) {
|
|
364
|
-
const allKeys = [canonicalKey, ...config.alias];
|
|
365
|
-
if (allKeys.includes(browserEventKey) && allKeys.includes(key)) {
|
|
366
|
-
return true;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
return false;
|
|
371
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const detectMac = () => {
|
|
2
|
-
// Modern way using User-Agent Client Hints API
|
|
3
|
-
if (window.navigator.userAgentData) {
|
|
4
|
-
return window.navigator.userAgentData.platform === "macOS";
|
|
5
|
-
}
|
|
6
|
-
// Fallback to userAgent string parsing
|
|
7
|
-
return /Mac|iPhone|iPad|iPod/.test(window.navigator.userAgent);
|
|
8
|
-
};
|
|
9
|
-
export const isMac = detectMac();
|