datocms-react-ui 3.1.0-next.0 → 3.1.0-next.1
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/Actions.d.ts +1 -0
- package/dist/Actions.js +4 -0
- package/dist/IconAvatar.d.ts +2 -0
- package/dist/IconAvatar.js +2 -0
- package/dist/ListDetail.js +2 -2
- package/dist/Pane.js +2 -1
- package/dist/SplitPane.js +2 -2
- package/dist/react-ui/src/Canvas.d.ts +2 -1
- package/dist/react-ui/src/Canvas.js +8 -6
- package/dist/react-ui/src/ContextInspector.js +2 -2
- package/dist/react-ui/src/messageText.js +1 -1
- package/dist/styles.css +330 -195
- package/dist/ui/icons/brands/gitlab.js +15 -0
- package/dist/ui/icons/custom/netlify.js +7 -29
- package/dist/ui/icons/custom/vercel.js +1 -4
- package/dist/ui/icons/index.js +206 -195
- package/dist/ui/icons/regular/command.js +16 -0
- package/dist/ui/icons/regular/keyboard.js +16 -0
- package/dist/ui/icons/regular/list-tree.js +2 -1
- package/dist/ui/icons/regular/list.js +2 -1
- package/dist/ui/icons/regular/memo.js +2 -1
- package/dist/ui/locales/en.js +10 -3
- package/dist/ui/src/BundledTexts.js +2 -2
- package/dist/ui/src/UiTextKey.d.ts +1 -1
- package/dist/ui/src/actions/Actions/ActionTooltip.js +24 -0
- package/dist/ui/src/actions/Actions/Shortcut.d.ts +23 -0
- package/dist/ui/src/actions/Actions/Shortcut.js +45 -0
- package/dist/ui/src/actions/Actions/index.d.ts +3 -0
- package/dist/ui/src/actions/Actions/index.js +3 -0
- package/dist/ui/src/actions/Actions/registry.d.ts +211 -0
- package/dist/ui/src/actions/Actions/registry.js +580 -0
- package/dist/ui/src/actions/Actions/shortcuts.d.ts +85 -0
- package/dist/ui/src/actions/Actions/shortcuts.js +284 -0
- package/dist/ui/src/actions/Button.d.ts +13 -12
- package/dist/ui/src/actions/Button.js +8 -7
- package/dist/ui/src/actions/Dropdown/DropdownContext.js +2 -1
- package/dist/ui/src/actions/Dropdown/Footer.js +1 -1
- package/dist/ui/src/actions/Dropdown/Menu.d.ts +2 -1
- package/dist/ui/src/actions/Dropdown/Menu.js +43 -37
- package/dist/ui/src/actions/Dropdown/MenuContent.js +22 -12
- package/dist/ui/src/actions/Dropdown/MenuParts.js +3 -3
- package/dist/ui/src/actions/Dropdown/Option.d.ts +20 -3
- package/dist/ui/src/actions/Dropdown/Option.js +48 -9
- package/dist/ui/src/actions/Dropdown/OptionAction.js +1 -1
- package/dist/ui/src/actions/Dropdown/Submenu.js +2 -2
- package/dist/ui/src/actions/Dropdown/index.d.ts +4 -1
- package/dist/ui/src/actions/Dropdown/index.js +6 -4
- package/dist/ui/src/actions/Dropdown/triggers/ButtonTrigger.d.ts +4 -4
- package/dist/ui/src/actions/Dropdown/triggers/ButtonTrigger.js +7 -6
- package/dist/ui/src/actions/Dropdown/triggers/PillTrigger.js +1 -1
- package/dist/ui/src/actions/Dropdown/triggers/TextualTrigger.js +1 -1
- package/dist/ui/src/actions/EditorToolbar/Button.js +2 -2
- package/dist/ui/src/actions/EditorToolbar/Buttons.js +2 -2
- package/dist/ui/src/actions/EditorToolbar/index.js +1 -1
- package/dist/ui/src/actions/MultipleSelectionActionBar.d.ts +20 -3
- package/dist/ui/src/actions/MultipleSelectionActionBar.js +25 -7
- package/dist/ui/src/actions/SplitButton/Caret.js +1 -1
- package/dist/ui/src/actions/SplitButton/index.js +1 -1
- package/dist/ui/src/actions/disabledReason.js +1 -1
- package/dist/ui/src/content/Avatar.d.ts +5 -3
- package/dist/ui/src/content/Avatar.js +4 -3
- package/dist/ui/src/content/CodeSnippet.js +1 -1
- package/dist/ui/src/content/CopyButton.js +1 -1
- package/dist/ui/src/content/CopyableId.d.ts +6 -1
- package/dist/ui/src/content/CopyableId.js +5 -2
- package/dist/ui/src/content/CopyableValue.js +2 -2
- package/dist/ui/src/content/FeedbackDot.js +1 -1
- package/dist/ui/src/content/IconAvatar.d.ts +42 -0
- package/dist/ui/src/content/IconAvatar.js +36 -0
- package/dist/ui/src/content/InitialsAvatar.js +1 -2
- package/dist/ui/src/content/Pill.js +3 -3
- package/dist/ui/src/content/SmartDate.js +1 -1
- package/dist/ui/src/content/UploadThreatTriangle.js +1 -1
- package/dist/ui/src/content/UsageMeter.d.ts +2 -1
- package/dist/ui/src/content/UsageMeter.js +3 -2
- package/dist/ui/src/content/ValidityTriangles.js +3 -3
- package/dist/ui/src/feedback/BlankSlate.js +2 -2
- package/dist/ui/src/feedback/Callout.js +2 -2
- package/dist/ui/src/feedback/ProgressBar.js +1 -1
- package/dist/ui/src/form/AutosizeInput.js +1 -1
- package/dist/ui/src/form/FieldHint.js +1 -1
- package/dist/ui/src/form/FieldWrapper.js +1 -1
- package/dist/ui/src/form/InputGroup.js +1 -1
- package/dist/ui/src/form/Label.js +2 -2
- package/dist/ui/src/form/PasswordInput.js +1 -1
- package/dist/ui/src/form/RadioGroupInput.js +1 -1
- package/dist/ui/src/form/SelectInput/SelectMenu.js +3 -3
- package/dist/ui/src/form/SelectInput/SelectMultiValueRemove.js +7 -0
- package/dist/ui/src/form/SelectInput/SelectOption.js +1 -1
- package/dist/ui/src/form/SelectInput/SortableMultiValue.js +1 -1
- package/dist/ui/src/form/StringInput.js +1 -1
- package/dist/ui/src/form/SwitchInput.d.ts +2 -0
- package/dist/ui/src/form/SwitchInput.js +4 -3
- package/dist/ui/src/form/SwitchList.js +1 -1
- package/dist/ui/src/form/TableList.js +2 -2
- package/dist/ui/src/form/TextareaInput.js +1 -1
- package/dist/ui/src/i18n.js +6 -6
- package/dist/ui/src/layout/ListOrOverview.js +3 -3
- package/dist/ui/src/layout/Page/Page.js +1 -1
- package/dist/ui/src/layout/Page/PageContent.js +1 -1
- package/dist/ui/src/layout/Page/PageGroup.js +2 -2
- package/dist/ui/src/layout/Page/PageSection.js +1 -1
- package/dist/ui/src/layout/Pane/ListFilter.js +6 -12
- package/dist/ui/src/layout/Pane/PaneHeader.js +3 -3
- package/dist/ui/src/layout/Pane/PaneRegion.d.ts +14 -0
- package/dist/ui/src/layout/Pane/PaneRegion.js +23 -0
- package/dist/ui/src/layout/Pane/index.d.ts +1 -0
- package/dist/ui/src/layout/Pane/index.js +36 -32
- package/dist/ui/src/layout/SidebarPanel.js +1 -1
- package/dist/ui/src/layout/SplitPane.d.ts +2 -0
- package/dist/ui/src/layout/SplitPane.js +79 -37
- package/dist/ui/src/layout/SplitView/SashActionButton.js +17 -9
- package/dist/ui/src/layout/SplitView/SplitView.js +1 -1
- package/dist/ui/src/layout/SplitView/SplitViewSash.js +2 -1
- package/dist/ui/src/layout/Toolbar/AddNewButton.d.ts +10 -6
- package/dist/ui/src/layout/Toolbar/AddNewButton.js +10 -23
- package/dist/ui/src/layout/Toolbar/Divider.d.ts +8 -0
- package/dist/ui/src/layout/Toolbar/Divider.js +16 -0
- package/dist/ui/src/layout/Toolbar/DotsDropdown.d.ts +8 -1
- package/dist/ui/src/layout/Toolbar/DotsDropdown.js +3 -2
- package/dist/ui/src/layout/Toolbar/Fill.js +1 -1
- package/dist/ui/src/layout/Toolbar/FilterInput.d.ts +7 -3
- package/dist/ui/src/layout/Toolbar/FilterInput.js +62 -49
- package/dist/ui/src/layout/Toolbar/FilterToggle.d.ts +6 -4
- package/dist/ui/src/layout/Toolbar/FilterToggle.js +42 -7
- package/dist/ui/src/layout/Toolbar/GoBack.d.ts +6 -1
- package/dist/ui/src/layout/Toolbar/GoBack.js +12 -5
- package/dist/ui/src/layout/Toolbar/Group.js +1 -1
- package/dist/ui/src/layout/Toolbar/Help.js +3 -3
- package/dist/ui/src/layout/Toolbar/Pagination.js +2 -2
- package/dist/ui/src/layout/Toolbar/PresetsTitle.js +3 -3
- package/dist/ui/src/layout/Toolbar/PrimaryButton.d.ts +3 -3
- package/dist/ui/src/layout/Toolbar/PrimaryButton.js +2 -2
- package/dist/ui/src/layout/Toolbar/Root.d.ts +6 -1
- package/dist/ui/src/layout/Toolbar/Root.js +13 -2
- package/dist/ui/src/layout/Toolbar/Search.d.ts +2 -1
- package/dist/ui/src/layout/Toolbar/Search.js +8 -3
- package/dist/ui/src/layout/Toolbar/context.js +2 -1
- package/dist/ui/src/layout/Toolbar/index.d.ts +5 -3
- package/dist/ui/src/layout/Toolbar/index.js +2 -0
- package/dist/ui/src/lists/CardList.d.ts +7 -2
- package/dist/ui/src/lists/CardList.js +7 -6
- package/dist/ui/src/lists/EmptySlot.js +2 -2
- package/dist/ui/src/lists/EntityRow.js +1 -1
- package/dist/ui/src/lists/InfoList.js +8 -3
- package/dist/ui/src/lists/InsertGap.js +4 -4
- package/dist/ui/src/lists/MediaCard.d.ts +10 -0
- package/dist/ui/src/lists/MediaCard.js +9 -4
- package/dist/ui/src/lists/RowList.js +2 -2
- package/dist/ui/src/lists/SettingsList.js +1 -1
- package/dist/ui/src/lists/Table/Body.js +1 -1
- package/dist/ui/src/lists/Table/Cell.js +1 -1
- package/dist/ui/src/lists/Table/ColumnsMenu.js +1 -1
- package/dist/ui/src/lists/Table/Header.js +8 -10
- package/dist/ui/src/lists/Table/HeaderCell.js +2 -2
- package/dist/ui/src/lists/Table/Row.d.ts +7 -1
- package/dist/ui/src/lists/Table/Row.js +6 -2
- package/dist/ui/src/lists/Table/Table.js +1 -1
- package/dist/ui/src/lists/Table/TreeToggle.js +1 -1
- package/dist/ui/src/lists/Table/index.d.ts +1 -1
- package/dist/ui/src/lists/Table/layout.d.ts +3 -2
- package/dist/ui/src/lists/Table/layout.js +26 -13
- package/dist/ui/src/lists/dnd/DragHandle.js +1 -1
- package/dist/ui/src/lists/dnd/DropIndicator.js +1 -1
- package/dist/ui/src/lists/dnd/SortableList.js +2 -2
- package/dist/ui/src/lists/dnd/tree/SortableTree.js +1 -1
- package/dist/ui/src/navigation/Chevron.js +2 -2
- package/dist/ui/src/navigation/SegmentedControl.d.ts +23 -4
- package/dist/ui/src/navigation/SegmentedControl.js +23 -5
- package/dist/ui/src/navigation/SettingsMenu.js +3 -3
- package/dist/ui/src/navigation/SidebarTree/SidebarTreeNode.js +3 -3
- package/dist/ui/src/navigation/SidebarTree/SidebarTreeNodeActions.js +1 -1
- package/dist/ui/src/navigation/Tabs.js +1 -1
- package/dist/ui/src/overlays/FullscreenModal.js +48 -53
- package/dist/ui/src/overlays/HoverCard.js +4 -4
- package/dist/ui/src/overlays/Modal.d.ts +7 -0
- package/dist/ui/src/overlays/Modal.js +53 -55
- package/dist/ui/src/overlays/Popover.d.ts +6 -3
- package/dist/ui/src/overlays/Popover.js +13 -8
- package/dist/ui/src/overlays/Portal.js +1 -1
- package/dist/ui/src/overlays/Tooltip.d.ts +6 -3
- package/dist/ui/src/overlays/Tooltip.js +29 -13
- package/dist/ui/src/overlays/useModalClose.js +17 -12
- package/dist/ui/src/patterns/ListDetail/Page.d.ts +9 -0
- package/dist/ui/src/patterns/ListDetail/Page.js +33 -26
- package/dist/ui/src/patterns/ListDetail/Panel.js +4 -2
- package/dist/ui/src/patterns/ListDetail/Split.d.ts +5 -0
- package/dist/ui/src/patterns/ListDetail/Split.js +75 -56
- package/dist/ui/src/patterns/ListDetail/index.d.ts +2 -2
- package/dist/ui/src/patterns/ListDetail/index.js +2 -2
- package/dist/ui/src/patterns/ListFormPage.js +2 -2
- package/dist/ui/src/semantic/Main.d.ts +4 -1
- package/dist/ui/src/semantic/Main.js +53 -3
- package/dist/ui/src/semantic/NavigationFocusProvider.js +9 -0
- package/package.json +1 -1
- package/dist/HotKey.d.ts +0 -1
- package/dist/HotKey.js +0 -2
- package/dist/ui/src/actions/HotKey.d.ts +0 -98
- package/dist/ui/src/actions/HotKey.js +0 -270
- package/dist/ui/src/actions/hotKeyContext.d.ts +0 -32
- package/dist/ui/src/actions/hotKeyContext.js +0 -15
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import { useClickOutside } from "../hooks/useClickOutside.js";
|
|
2
|
-
import { useTranslation } from "../i18n.js";
|
|
3
|
-
import NewZIndex from "../overlays/NewZIndex.js";
|
|
4
|
-
import Tooltip from "../overlays/Tooltip.js";
|
|
5
|
-
import Portal from "../overlays/Portal.js";
|
|
6
|
-
import randomKey from "../utils/randomKey.js";
|
|
7
|
-
import { HotKeyContext, HotKeyManagerContext } from "./hotKeyContext.js";
|
|
8
|
-
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
9
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
-
import { isHotkey } from "is-hotkey-esm";
|
|
11
|
-
import { groupBy, isEqual } from "lodash-es";
|
|
12
|
-
//#region ../ui/src/actions/HotKey.tsx
|
|
13
|
-
var IsRootCoveredContext = React.createContext(false);
|
|
14
|
-
var useIsRootCovered = () => useContext(IsRootCoveredContext);
|
|
15
|
-
/**
|
|
16
|
-
* A layer of keys. While it is mounted, only its own HotKeyListener
|
|
17
|
-
* elements work, and the ones of the layers below do not. A dialog is a
|
|
18
|
-
* stack.
|
|
19
|
-
*/
|
|
20
|
-
function HotKeyStack({ children, forceStackPriority }) {
|
|
21
|
-
const { pushStack } = useContext(HotKeyManagerContext);
|
|
22
|
-
const id = useMemo(() => randomKey(), []);
|
|
23
|
-
const contextValue = useContext(HotKeyContext);
|
|
24
|
-
const newContextValue = useMemo(() => ({
|
|
25
|
-
currentStackId: id,
|
|
26
|
-
currentStackPriority: forceStackPriority !== void 0 ? forceStackPriority : contextValue.currentStackPriority + 1,
|
|
27
|
-
currentListenerPriority: 0,
|
|
28
|
-
currentListenerDeets: void 0
|
|
29
|
-
}), [
|
|
30
|
-
contextValue.currentStackId,
|
|
31
|
-
contextValue.currentStackPriority,
|
|
32
|
-
forceStackPriority
|
|
33
|
-
]);
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
return pushStack({
|
|
36
|
-
id,
|
|
37
|
-
priority: newContextValue.currentStackPriority
|
|
38
|
-
});
|
|
39
|
-
}, [id, newContextValue.currentStackPriority]);
|
|
40
|
-
return /* @__PURE__ */ jsx(HotKeyContext.Provider, {
|
|
41
|
-
value: newContextValue,
|
|
42
|
-
children
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function findHighestStack(definitions) {
|
|
46
|
-
const winner = definitions.reduce((currentWinner, stack) => currentWinner ? currentWinner.priority < stack.priority ? stack : currentWinner : stack, null);
|
|
47
|
-
if (!winner) throw new Error("This cannot happen!");
|
|
48
|
-
return winner;
|
|
49
|
-
}
|
|
50
|
-
function findHighestDefinition(definitions) {
|
|
51
|
-
return definitions.reduce((currentWinner, stack) => currentWinner ? currentWinner.priority < stack.priority ? stack : currentWinner : stack, null);
|
|
52
|
-
}
|
|
53
|
-
var GLOBAL_PRIORITY = 1e5;
|
|
54
|
-
/**
|
|
55
|
-
* Listens to the keys of the whole page. Put it once near the root of the
|
|
56
|
-
* app, above every HotKeyListener.
|
|
57
|
-
*/
|
|
58
|
-
function HotKeyManager({ children }) {
|
|
59
|
-
const [state, setState] = useState({
|
|
60
|
-
stacks: [{
|
|
61
|
-
id: "root",
|
|
62
|
-
priority: 0
|
|
63
|
-
}],
|
|
64
|
-
hotKeys: []
|
|
65
|
-
});
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
const handler = (event) => {
|
|
68
|
-
const highestStackId = findHighestStack(state.stacks).id;
|
|
69
|
-
const winnerDefinition = findHighestDefinition(state.hotKeys.filter((d) => (!d.stackId || d.stackId === highestStackId) && isHotkey(d.hotKey, event)));
|
|
70
|
-
if (winnerDefinition) {
|
|
71
|
-
event.stopImmediatePropagation();
|
|
72
|
-
event.preventDefault();
|
|
73
|
-
winnerDefinition.trigger(event);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
document.addEventListener("keydown", handler);
|
|
77
|
-
return () => {
|
|
78
|
-
document.removeEventListener("keydown", handler);
|
|
79
|
-
};
|
|
80
|
-
}, [state]);
|
|
81
|
-
const addHotKey = (definition) => {
|
|
82
|
-
setState((oldState) => {
|
|
83
|
-
return {
|
|
84
|
-
...oldState,
|
|
85
|
-
hotKeys: [...oldState.hotKeys, definition]
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
return () => {
|
|
89
|
-
setState((oldState) => {
|
|
90
|
-
return {
|
|
91
|
-
...oldState,
|
|
92
|
-
hotKeys: oldState.hotKeys.filter((d) => d.trigger !== definition.trigger)
|
|
93
|
-
};
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
const pushStack = (definition) => {
|
|
98
|
-
setState((oldState) => {
|
|
99
|
-
return {
|
|
100
|
-
...oldState,
|
|
101
|
-
stacks: [...oldState.stacks, definition]
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
return () => {
|
|
105
|
-
setState((oldState) => {
|
|
106
|
-
return {
|
|
107
|
-
...oldState,
|
|
108
|
-
stacks: oldState.stacks.filter((d) => d.id !== definition.id)
|
|
109
|
-
};
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
const highestStackId = useMemo(() => findHighestStack(state.stacks).id, [state.stacks]);
|
|
114
|
-
const activeHotKeys = useMemo(() => {
|
|
115
|
-
const matchingHotKeys = state.hotKeys.filter((d) => !d.stackId || d.stackId === highestStackId);
|
|
116
|
-
const byHotKey = groupBy(matchingHotKeys, (d) => d.hotKey);
|
|
117
|
-
return Object.entries(byHotKey).reduce((acc, [key, definitions]) => {
|
|
118
|
-
if (definitions.length > 0) acc[key] = findHighestDefinition(definitions).description;
|
|
119
|
-
return acc;
|
|
120
|
-
}, {});
|
|
121
|
-
}, [state]);
|
|
122
|
-
return /* @__PURE__ */ jsx(HotKeyManagerContext.Provider, {
|
|
123
|
-
value: {
|
|
124
|
-
addHotKey,
|
|
125
|
-
pushStack,
|
|
126
|
-
activeHotKeys
|
|
127
|
-
},
|
|
128
|
-
children: /* @__PURE__ */ jsx(IsRootCoveredContext.Provider, {
|
|
129
|
-
value: highestStackId !== "root",
|
|
130
|
-
children
|
|
131
|
-
})
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Runs `trigger` when the user presses `hotKey`. Of two listeners with the
|
|
136
|
-
* same keys, the one that is nested deeper in the tree wins.
|
|
137
|
-
*/
|
|
138
|
-
function HotKeyListener({ children, hotKey, enabled = true, trigger, description: descriptionProp }) {
|
|
139
|
-
const { addHotKey } = useContext(HotKeyManagerContext);
|
|
140
|
-
const contextValue = useContext(HotKeyContext);
|
|
141
|
-
const descriptionRef = useRef(descriptionProp);
|
|
142
|
-
if (!isEqual(descriptionRef.current, descriptionProp)) descriptionRef.current = descriptionProp;
|
|
143
|
-
const description = descriptionRef.current;
|
|
144
|
-
const newContextValue = useMemo(() => ({
|
|
145
|
-
currentStackId: contextValue.currentStackId,
|
|
146
|
-
currentStackPriority: contextValue.currentStackPriority,
|
|
147
|
-
currentListenerPriority: contextValue.currentListenerPriority + 1,
|
|
148
|
-
currentListenerDeets: {
|
|
149
|
-
hotKey,
|
|
150
|
-
description,
|
|
151
|
-
enabled
|
|
152
|
-
}
|
|
153
|
-
}), [
|
|
154
|
-
hotKey,
|
|
155
|
-
description,
|
|
156
|
-
enabled,
|
|
157
|
-
contextValue.currentStackId,
|
|
158
|
-
contextValue.currentStackPriority,
|
|
159
|
-
contextValue.currentListenerPriority
|
|
160
|
-
]);
|
|
161
|
-
const [isTriggerPending, setTriggerPending] = useState(false);
|
|
162
|
-
const isMountedRef = useRef(true);
|
|
163
|
-
useEffect(() => {
|
|
164
|
-
isMountedRef.current = true;
|
|
165
|
-
return () => {
|
|
166
|
-
isMountedRef.current = false;
|
|
167
|
-
};
|
|
168
|
-
}, []);
|
|
169
|
-
const triggerWrapper = useCallback(async (event) => {
|
|
170
|
-
try {
|
|
171
|
-
setTriggerPending(true);
|
|
172
|
-
return await trigger(event);
|
|
173
|
-
} finally {
|
|
174
|
-
if (isMountedRef.current) setTriggerPending(false);
|
|
175
|
-
}
|
|
176
|
-
}, [trigger]);
|
|
177
|
-
useEffect(() => {
|
|
178
|
-
if (enabled) return addHotKey({
|
|
179
|
-
stackId: newContextValue.currentStackId,
|
|
180
|
-
priority: newContextValue.currentListenerPriority,
|
|
181
|
-
hotKey,
|
|
182
|
-
description,
|
|
183
|
-
trigger: triggerWrapper
|
|
184
|
-
});
|
|
185
|
-
}, [
|
|
186
|
-
newContextValue.currentStackId,
|
|
187
|
-
newContextValue.currentListenerPriority,
|
|
188
|
-
hotKey,
|
|
189
|
-
triggerWrapper,
|
|
190
|
-
enabled
|
|
191
|
-
]);
|
|
192
|
-
return /* @__PURE__ */ jsx(HotKeyContext.Provider, {
|
|
193
|
-
value: newContextValue,
|
|
194
|
-
children: typeof children === "function" ? children(isTriggerPending) : children
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
var modifierKey = typeof window !== "undefined" && /Mac|iPod|iPhone|iPad/.test(window.navigator.platform) ? "⌘" : "Ctrl";
|
|
198
|
-
var keySymbols = {
|
|
199
|
-
enter: "↵",
|
|
200
|
-
esc: "Esc",
|
|
201
|
-
escape: "Esc",
|
|
202
|
-
arrowup: "↑",
|
|
203
|
-
arrowdown: "↓",
|
|
204
|
-
arrowleft: "←",
|
|
205
|
-
arrowright: "→"
|
|
206
|
-
};
|
|
207
|
-
/** The keys of a shortcut, drawn as small keycaps. */
|
|
208
|
-
function HotKey({ hotkey }) {
|
|
209
|
-
const keys = hotkey.replace(/\bmod\b/g, modifierKey).split(/\+/).map((e) => keySymbols[e.toLowerCase()] || e.charAt(0).toUpperCase() + e.slice(1));
|
|
210
|
-
return /* @__PURE__ */ jsx("kbd", {
|
|
211
|
-
className: "HotKey",
|
|
212
|
-
children: keys.map((key, index) => /* @__PURE__ */ jsx("kbd", {
|
|
213
|
-
className: "HotKey__key",
|
|
214
|
-
children: key
|
|
215
|
-
}, `${index}-${key}`))
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* A tooltip with the keys of the HotKeyListener of the trigger. Put the
|
|
220
|
-
* HotKeyListener around it. When there is no listener, or the listener is
|
|
221
|
-
* disabled, the tooltip has no keys, and without `label` it does not show.
|
|
222
|
-
*/
|
|
223
|
-
function HotKeyTooltip({ label, hidden, ...props }) {
|
|
224
|
-
const { currentListenerDeets } = useContext(HotKeyContext);
|
|
225
|
-
const { tm } = useTranslation();
|
|
226
|
-
const active = currentListenerDeets?.enabled ? currentListenerDeets : null;
|
|
227
|
-
return /* @__PURE__ */ jsx(Tooltip, {
|
|
228
|
-
...props,
|
|
229
|
-
label: !hidden && (label ?? (active && tm(active.description))),
|
|
230
|
-
shortcut: active?.hotKey
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* A panel at the top of the page with the active keys. Cmd or Ctrl + \\
|
|
235
|
-
* opens and closes it. Put it once, inside HotKeyManager.
|
|
236
|
-
*/
|
|
237
|
-
function HotKeyManagerInfo() {
|
|
238
|
-
const { t, tm } = useTranslation();
|
|
239
|
-
const { activeHotKeys, addHotKey } = useContext(HotKeyManagerContext);
|
|
240
|
-
const [visible, setVisible] = useState(false);
|
|
241
|
-
const clickOutsideRef = useClickOutside(() => setVisible(false));
|
|
242
|
-
const handleToggleVisibility = useCallback(() => setVisible((x) => {
|
|
243
|
-
return !x;
|
|
244
|
-
}), [setVisible]);
|
|
245
|
-
useEffect(() => addHotKey({
|
|
246
|
-
priority: GLOBAL_PRIORITY,
|
|
247
|
-
hotKey: "mod+\\",
|
|
248
|
-
description: { id: "hotkeys.toggleKeyboardShortcuts" },
|
|
249
|
-
trigger: handleToggleVisibility
|
|
250
|
-
}), [handleToggleVisibility]);
|
|
251
|
-
return /* @__PURE__ */ jsx(Fragment, { children: visible && /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(NewZIndex, { children: (zIndex) => /* @__PURE__ */ jsx("div", {
|
|
252
|
-
ref: clickOutsideRef,
|
|
253
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
254
|
-
className: "HotKeyManagerInfo",
|
|
255
|
-
style: { zIndex },
|
|
256
|
-
children: [/* @__PURE__ */ jsx("p", {
|
|
257
|
-
className: "HotKeyManagerInfo__title",
|
|
258
|
-
children: t("hotkeys.info.title")
|
|
259
|
-
}), Object.keys(activeHotKeys).length > 0 ? Object.entries(activeHotKeys).map(([hotKey, description]) => /* @__PURE__ */ jsxs("div", {
|
|
260
|
-
className: "HotKeyManagerInfo__hotkey",
|
|
261
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
262
|
-
className: "HotKeyManagerInfo__hotkey__description",
|
|
263
|
-
children: tm(description)
|
|
264
|
-
}), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(HotKey, { hotkey: hotKey }), " "] })]
|
|
265
|
-
}, hotKey)) : /* @__PURE__ */ jsx("p", { children: t("hotkeys.info.empty") })]
|
|
266
|
-
})
|
|
267
|
-
}) }) }) });
|
|
268
|
-
}
|
|
269
|
-
//#endregion
|
|
270
|
-
export { HotKey, HotKeyListener, HotKeyManager, HotKeyManagerInfo, HotKeyStack, HotKeyTooltip, useIsRootCovered };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { type TextMessage } from '../Message.js';
|
|
3
|
-
export type Callback = (event: Event) => void;
|
|
4
|
-
export type ActiveHotKeysType = Record<string, TextMessage>;
|
|
5
|
-
export type HotKeyDefinition = {
|
|
6
|
-
stackId?: string;
|
|
7
|
-
priority: number;
|
|
8
|
-
hotKey: string;
|
|
9
|
-
description: TextMessage;
|
|
10
|
-
trigger: Callback;
|
|
11
|
-
};
|
|
12
|
-
export type StackDefinition = {
|
|
13
|
-
id: string;
|
|
14
|
-
priority: number;
|
|
15
|
-
};
|
|
16
|
-
export type HotKeyManagerContextValue = {
|
|
17
|
-
addHotKey(definition: HotKeyDefinition): (() => void) | undefined;
|
|
18
|
-
pushStack(stack: StackDefinition): (() => void) | undefined;
|
|
19
|
-
activeHotKeys: ActiveHotKeysType;
|
|
20
|
-
};
|
|
21
|
-
export type HotKeyContextType = {
|
|
22
|
-
currentListenerPriority: number;
|
|
23
|
-
currentListenerDeets?: {
|
|
24
|
-
hotKey: string;
|
|
25
|
-
description: TextMessage;
|
|
26
|
-
enabled: boolean;
|
|
27
|
-
};
|
|
28
|
-
currentStackId: string;
|
|
29
|
-
currentStackPriority: number;
|
|
30
|
-
};
|
|
31
|
-
export declare const HotKeyContext: React.Context<HotKeyContextType>;
|
|
32
|
-
export declare const HotKeyManagerContext: React.Context<HotKeyManagerContextValue>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
//#region ../ui/src/actions/hotKeyContext.ts
|
|
3
|
-
var HotKeyContext = React.createContext({
|
|
4
|
-
currentListenerPriority: 0,
|
|
5
|
-
currentListenerDeets: void 0,
|
|
6
|
-
currentStackPriority: 0,
|
|
7
|
-
currentStackId: "root"
|
|
8
|
-
});
|
|
9
|
-
var HotKeyManagerContext = React.createContext({
|
|
10
|
-
addHotKey: () => void 0,
|
|
11
|
-
pushStack: () => void 0,
|
|
12
|
-
activeHotKeys: {}
|
|
13
|
-
});
|
|
14
|
-
//#endregion
|
|
15
|
-
export { HotKeyContext, HotKeyManagerContext };
|