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
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
import { Editor } from "../../../icons/index.js";
|
|
2
|
+
import { useHostServices } from "../../HostServicesProvider.js";
|
|
3
|
+
import randomKey from "../../utils/randomKey.js";
|
|
4
|
+
import { isMac, isModifierOnly, isPlain, isSequence, sequenceStartsWith, shortcutMatches, shortcutProblem, strokeOf, toList } from "./shortcuts.js";
|
|
5
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
6
|
+
import { isEqual } from "lodash-es";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
//#region ../ui/src/actions/Actions/registry.tsx
|
|
9
|
+
/** The group of an action that gives no group */
|
|
10
|
+
var GENERAL_ACTION_GROUP = {
|
|
11
|
+
id: "general",
|
|
12
|
+
name: { id: "actionGroups.general" }
|
|
13
|
+
};
|
|
14
|
+
/** The group of the actions of a list: the filter, the selection */
|
|
15
|
+
var LIST_ACTION_GROUP = {
|
|
16
|
+
id: "list",
|
|
17
|
+
name: { id: "actionGroups.list" },
|
|
18
|
+
icon: Editor.RecordListIcon
|
|
19
|
+
};
|
|
20
|
+
var ROOT_LAYER = {
|
|
21
|
+
id: "root",
|
|
22
|
+
kind: "root",
|
|
23
|
+
priority: 0,
|
|
24
|
+
order: -1
|
|
25
|
+
};
|
|
26
|
+
var SEQUENCE_TIMEOUT_MS = 1200;
|
|
27
|
+
var LEVEL_RANK = {
|
|
28
|
+
app: 0,
|
|
29
|
+
page: 1,
|
|
30
|
+
region: 2
|
|
31
|
+
};
|
|
32
|
+
var NOT_TEXT_INPUTS = /* @__PURE__ */ new Set([
|
|
33
|
+
"button",
|
|
34
|
+
"checkbox",
|
|
35
|
+
"color",
|
|
36
|
+
"file",
|
|
37
|
+
"image",
|
|
38
|
+
"radio",
|
|
39
|
+
"range",
|
|
40
|
+
"reset",
|
|
41
|
+
"submit"
|
|
42
|
+
]);
|
|
43
|
+
function isTextField(target) {
|
|
44
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
45
|
+
if (target.isContentEditable) return true;
|
|
46
|
+
if (target instanceof HTMLInputElement) return !NOT_TEXT_INPUTS.has(target.type);
|
|
47
|
+
return target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A key that an embedded app (the frame of a plugin) did not handle. The
|
|
51
|
+
* host dispatches it on the frame with `data-actions-frame`, and gives
|
|
52
|
+
* `text-field` when the key comes from a text field of the frame.
|
|
53
|
+
*/
|
|
54
|
+
function frameOf(target) {
|
|
55
|
+
const value = target?.getAttribute("data-actions-frame");
|
|
56
|
+
return value === null || value === void 0 ? void 0 : { inField: value === "text-field" };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The code of the frame can send any key. Thus a key from a frame runs only
|
|
60
|
+
* the actions of the app (the palette, the chords) and the Escape that
|
|
61
|
+
* closes a layer, never an action on the content of the page.
|
|
62
|
+
*/
|
|
63
|
+
function frameMayRun(entry, stroke) {
|
|
64
|
+
return entry.registration.level === "app" || stroke.code === "Escape" && isPlain(stroke);
|
|
65
|
+
}
|
|
66
|
+
function isAbove(a, b) {
|
|
67
|
+
return a.priority > b.priority || a.priority === b.priority && a.order > b.order;
|
|
68
|
+
}
|
|
69
|
+
function contains(outer, inner) {
|
|
70
|
+
const outerElement = outer.element();
|
|
71
|
+
const innerElement = inner.element();
|
|
72
|
+
return outerElement !== null && innerElement !== null && outerElement !== innerElement && outerElement.contains(innerElement);
|
|
73
|
+
}
|
|
74
|
+
/** `a` wins over `b` when both have the same keys or the same id */
|
|
75
|
+
function beats(a, b) {
|
|
76
|
+
if (a.layer !== b.layer) return isAbove(a.layer, b.layer);
|
|
77
|
+
if (a.level !== b.level) return LEVEL_RANK[a.level] > LEVEL_RANK[b.level];
|
|
78
|
+
if (a.region && b.region) {
|
|
79
|
+
if (contains(a.region, b.region)) return false;
|
|
80
|
+
if (contains(b.region, a.region)) return true;
|
|
81
|
+
if (a.region.focused !== b.region.focused) return a.region.focused;
|
|
82
|
+
}
|
|
83
|
+
return a.order > b.order;
|
|
84
|
+
}
|
|
85
|
+
function byPrecedence(a, b) {
|
|
86
|
+
if (beats(a.registration, b.registration)) return -1;
|
|
87
|
+
if (beats(b.registration, a.registration)) return 1;
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
function validShortcuts(action) {
|
|
91
|
+
return toList(action.shortcut).filter((shortcut) => shortcutProblem(shortcut) === void 0);
|
|
92
|
+
}
|
|
93
|
+
var ActionsRegistry = class {
|
|
94
|
+
constructor() {
|
|
95
|
+
this.registrations = /* @__PURE__ */ new Set();
|
|
96
|
+
this.layers = [];
|
|
97
|
+
this.coveringLayerIds = /* @__PURE__ */ new Set();
|
|
98
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
99
|
+
this.nextOrder = 0;
|
|
100
|
+
this.warn = () => void 0;
|
|
101
|
+
}
|
|
102
|
+
takeOrder() {
|
|
103
|
+
this.nextOrder += 1;
|
|
104
|
+
return this.nextOrder;
|
|
105
|
+
}
|
|
106
|
+
subscribe(listener) {
|
|
107
|
+
this.listeners.add(listener);
|
|
108
|
+
return () => {
|
|
109
|
+
this.listeners.delete(listener);
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
notify() {
|
|
113
|
+
for (const listener of Array.from(this.listeners)) listener();
|
|
114
|
+
}
|
|
115
|
+
add(registration) {
|
|
116
|
+
this.registrations.add(registration);
|
|
117
|
+
this.notify();
|
|
118
|
+
return () => {
|
|
119
|
+
this.registrations.delete(registration);
|
|
120
|
+
this.notify();
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
newLayer(kind, parent) {
|
|
124
|
+
const base = kind === "dialog" ? Math.max(parent.priority, ...this.layers.map((l) => l.priority)) : parent.priority;
|
|
125
|
+
return {
|
|
126
|
+
id: randomKey(),
|
|
127
|
+
kind,
|
|
128
|
+
priority: base + 1,
|
|
129
|
+
order: 0
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
pushLayer(layer) {
|
|
133
|
+
layer.order = this.takeOrder();
|
|
134
|
+
this.layers.push(layer);
|
|
135
|
+
this.notify();
|
|
136
|
+
return () => {
|
|
137
|
+
this.layers = this.layers.filter((l) => l !== layer);
|
|
138
|
+
this.notify();
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
coverPage(layer) {
|
|
142
|
+
this.coveringLayerIds.add(layer.id);
|
|
143
|
+
this.notify();
|
|
144
|
+
return () => {
|
|
145
|
+
this.coveringLayerIds.delete(layer.id);
|
|
146
|
+
this.notify();
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
isPageCovered() {
|
|
150
|
+
return this.layers.some((layer) => this.coveringLayerIds.has(layer.id));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* A popover keeps the actions of the app on. A dialog with its own `Main`
|
|
154
|
+
* also does: it is a page in a dialog, for example the project settings.
|
|
155
|
+
*/
|
|
156
|
+
keepsAppActions(layer) {
|
|
157
|
+
return layer.kind === "popover" || this.coveringLayerIds.has(layer.id);
|
|
158
|
+
}
|
|
159
|
+
isActive(entry) {
|
|
160
|
+
const { action, registration } = entry;
|
|
161
|
+
const { region, layer, level } = registration;
|
|
162
|
+
if (region && !region.hovered && !region.focused) return false;
|
|
163
|
+
if (action.applicable && !action.applicable()) return false;
|
|
164
|
+
if (layer !== ROOT_LAYER && !this.layers.includes(layer)) return false;
|
|
165
|
+
const above = this.layers.filter((l) => isAbove(l, layer));
|
|
166
|
+
if (above.length === 0 || action.layerSafe) return true;
|
|
167
|
+
return level === "app" && above.every((l) => this.keepsAppActions(l));
|
|
168
|
+
}
|
|
169
|
+
entries(keep = () => true) {
|
|
170
|
+
const entries = [];
|
|
171
|
+
for (const registration of Array.from(this.registrations)) for (const action of registration.actions()) {
|
|
172
|
+
const entry = {
|
|
173
|
+
action,
|
|
174
|
+
registration
|
|
175
|
+
};
|
|
176
|
+
if (keep(entry)) entries.push(entry);
|
|
177
|
+
}
|
|
178
|
+
return entries.sort(byPrecedence);
|
|
179
|
+
}
|
|
180
|
+
/** The active actions, the winner first. A winner hides its id below. */
|
|
181
|
+
activeEntries() {
|
|
182
|
+
const seen = /* @__PURE__ */ new Set();
|
|
183
|
+
const inActiveRegion = ({ registration: { region } }) => !region || region.hovered || region.focused;
|
|
184
|
+
return this.entries(inActiveRegion).filter((entry) => {
|
|
185
|
+
if (seen.has(entry.action.id) || !this.isActive(entry)) return false;
|
|
186
|
+
seen.add(entry.action.id);
|
|
187
|
+
return true;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* One action for each id, the active one first: the winner among the
|
|
192
|
+
* active actions, else the action that would win. The actions that do not
|
|
193
|
+
* apply now are out.
|
|
194
|
+
*/
|
|
195
|
+
listedEntries() {
|
|
196
|
+
const active = this.activeEntries();
|
|
197
|
+
const activeIds = new Set(active.map((entry) => entry.action.id));
|
|
198
|
+
const seen = /* @__PURE__ */ new Set();
|
|
199
|
+
const inactive = this.entries().filter((entry) => {
|
|
200
|
+
const { id, applicable } = entry.action;
|
|
201
|
+
if (activeIds.has(id) || seen.has(id)) return false;
|
|
202
|
+
if (applicable && !applicable()) return false;
|
|
203
|
+
seen.add(id);
|
|
204
|
+
return true;
|
|
205
|
+
});
|
|
206
|
+
return [...active.map((entry) => ({
|
|
207
|
+
entry,
|
|
208
|
+
active: true
|
|
209
|
+
})), ...inactive.map((entry) => ({
|
|
210
|
+
entry,
|
|
211
|
+
active: false
|
|
212
|
+
}))];
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The action with this id: the active one, else the one that would win.
|
|
216
|
+
* A menu runs an action of a region also when the pointer is in the menu.
|
|
217
|
+
* With an `origin` (the dropdown of the menu), only the regions that hold
|
|
218
|
+
* the origin count: each row of a list registers the same ids, and the
|
|
219
|
+
* menu of a row must not run the action of another row, nor a menu out of
|
|
220
|
+
* the rows (the panel of the open row) the action of a row.
|
|
221
|
+
*/
|
|
222
|
+
find(id, origin) {
|
|
223
|
+
const inScope = ({ registration: { region } }) => !origin || !region || Boolean(region.element()?.contains(origin));
|
|
224
|
+
const candidates = this.entries((e) => e.action.id === id && inScope(e));
|
|
225
|
+
if (origin) {
|
|
226
|
+
const own = candidates.find((e) => e.registration.region);
|
|
227
|
+
if (own) return !own.action.applicable || own.action.applicable() ? {
|
|
228
|
+
entry: own,
|
|
229
|
+
active: this.isActive(own)
|
|
230
|
+
} : void 0;
|
|
231
|
+
}
|
|
232
|
+
const active = candidates.find((e) => this.isActive(e));
|
|
233
|
+
if (active) return {
|
|
234
|
+
entry: active,
|
|
235
|
+
active: true
|
|
236
|
+
};
|
|
237
|
+
const entry = candidates.find((e) => !e.action.applicable || e.action.applicable());
|
|
238
|
+
return entry && {
|
|
239
|
+
entry,
|
|
240
|
+
active: false
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
run(entry, source) {
|
|
244
|
+
const reason = entry.action.disabledReason?.();
|
|
245
|
+
if (reason !== void 0) {
|
|
246
|
+
this.warn(reason);
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
entry.action.run({ source });
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Runs the action of an entry that the registry gave before. The action
|
|
254
|
+
* comes again from its registration, because the component can render
|
|
255
|
+
* again with a new `run` after the read.
|
|
256
|
+
*/
|
|
257
|
+
rerun(entry, source) {
|
|
258
|
+
const { registration } = entry;
|
|
259
|
+
if (!this.registrations.has(registration)) return false;
|
|
260
|
+
const action = registration.actions().find((a) => a.id === entry.action.id);
|
|
261
|
+
if (!action || action.applicable && !action.applicable()) return false;
|
|
262
|
+
return this.run({
|
|
263
|
+
action,
|
|
264
|
+
registration
|
|
265
|
+
}, source);
|
|
266
|
+
}
|
|
267
|
+
handleKeyDown(event, mac) {
|
|
268
|
+
if (event.defaultPrevented || event.isComposing || event.keyCode === 229) return;
|
|
269
|
+
const stroke = strokeOf(event, mac);
|
|
270
|
+
if (isModifierOnly(stroke)) return;
|
|
271
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
272
|
+
if (target?.closest("[data-actions-ignore]")) return;
|
|
273
|
+
const frame = frameOf(target);
|
|
274
|
+
const inField = frame ? frame.inField : isTextField(target);
|
|
275
|
+
const now = Date.now();
|
|
276
|
+
const buffer = this.buffer;
|
|
277
|
+
const previous = !inField && buffer && buffer.target === event.target && now - buffer.time <= SEQUENCE_TIMEOUT_MS ? buffer.stroke : void 0;
|
|
278
|
+
this.buffer = void 0;
|
|
279
|
+
const entries = frame ? this.activeEntries().filter((entry) => frameMayRun(entry, stroke)) : this.activeEntries();
|
|
280
|
+
const shortcutsOf = (entry, inside) => validShortcuts(entry.action).filter((shortcut) => !inside || shortcut.runWithInputFocus);
|
|
281
|
+
const findMatch = (inside) => previous && entries.find((entry) => shortcutsOf(entry, inside).some((s) => isSequence(s) && shortcutMatches(s, stroke, previous))) || entries.find((entry) => shortcutsOf(entry, inside).some((s) => !isSequence(s) && shortcutMatches(s, stroke, void 0)));
|
|
282
|
+
const winner = findMatch(inField);
|
|
283
|
+
if (winner) {
|
|
284
|
+
event.preventDefault();
|
|
285
|
+
if (!event.repeat) this.run(winner, "key");
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (inField && stroke.code === "Escape" && isPlain(stroke)) {
|
|
289
|
+
if (findMatch(false)) {
|
|
290
|
+
event.preventDefault();
|
|
291
|
+
target.blur();
|
|
292
|
+
}
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
if (!inField && isPlain(stroke) && entries.some((entry) => shortcutsOf(entry, false).some((s) => sequenceStartsWith(s, stroke)))) this.buffer = {
|
|
296
|
+
stroke,
|
|
297
|
+
time: now,
|
|
298
|
+
target: event.target
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
var RegistryContext = createContext(null);
|
|
303
|
+
var LayerContext = createContext(ROOT_LAYER);
|
|
304
|
+
var PageCoveredContext = createContext(false);
|
|
305
|
+
/**
|
|
306
|
+
* Holds the actions and listens to the keys of the whole page. Put it once
|
|
307
|
+
* near the root, inside the host services: a disabled action shows its
|
|
308
|
+
* reason with them. A second provider inside the first does nothing.
|
|
309
|
+
*/
|
|
310
|
+
function ActionsProvider({ children }) {
|
|
311
|
+
const parent = useContext(RegistryContext);
|
|
312
|
+
return parent ? /* @__PURE__ */ jsx(RegistryContext.Provider, {
|
|
313
|
+
value: parent,
|
|
314
|
+
children
|
|
315
|
+
}) : /* @__PURE__ */ jsx(RootActionsProvider, { children });
|
|
316
|
+
}
|
|
317
|
+
function RootActionsProvider({ children }) {
|
|
318
|
+
const [registry] = useState(() => new ActionsRegistry());
|
|
319
|
+
const { warn } = useHostServices();
|
|
320
|
+
const [pageCovered, setPageCovered] = useState(false);
|
|
321
|
+
useEffect(() => {
|
|
322
|
+
registry.warn = warn;
|
|
323
|
+
}, [registry, warn]);
|
|
324
|
+
useEffect(() => {
|
|
325
|
+
const mac = isMac();
|
|
326
|
+
const handleKeyDown = (event) => registry.handleKeyDown(event, mac);
|
|
327
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
328
|
+
const updatePageCovered = () => setPageCovered(registry.isPageCovered());
|
|
329
|
+
const unsubscribe = registry.subscribe(updatePageCovered);
|
|
330
|
+
updatePageCovered();
|
|
331
|
+
return () => {
|
|
332
|
+
window.removeEventListener("keydown", handleKeyDown);
|
|
333
|
+
unsubscribe();
|
|
334
|
+
};
|
|
335
|
+
}, [registry]);
|
|
336
|
+
return /* @__PURE__ */ jsx(RegistryContext.Provider, {
|
|
337
|
+
value: registry,
|
|
338
|
+
children: /* @__PURE__ */ jsx(PageCoveredContext.Provider, {
|
|
339
|
+
value: pageCovered,
|
|
340
|
+
children
|
|
341
|
+
})
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* A layer of actions, for example a dialog. While it is open, the actions
|
|
346
|
+
* under it are off: all of them under a dialog, the page and the regions
|
|
347
|
+
* under a popover. An action with `layerSafe` stays on. A dialog that opens
|
|
348
|
+
* later is on top, also when it is not inside the other dialogs in the tree.
|
|
349
|
+
*/
|
|
350
|
+
function ActionLayer({ kind, actions, active = true, children }) {
|
|
351
|
+
const registry = useContext(RegistryContext);
|
|
352
|
+
const parent = useContext(LayerContext);
|
|
353
|
+
const [layer] = useState(() => registry ? registry.newLayer(kind, parent) : {
|
|
354
|
+
id: randomKey(),
|
|
355
|
+
kind,
|
|
356
|
+
priority: parent.priority + 1,
|
|
357
|
+
order: 0
|
|
358
|
+
});
|
|
359
|
+
useLayoutEffect(() => active ? registry?.pushLayer(layer) : void 0, [
|
|
360
|
+
registry,
|
|
361
|
+
layer,
|
|
362
|
+
active
|
|
363
|
+
]);
|
|
364
|
+
return /* @__PURE__ */ jsxs(LayerContext.Provider, {
|
|
365
|
+
value: layer,
|
|
366
|
+
children: [actions && /* @__PURE__ */ jsx(LayerActions, { actions }), children]
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
function LayerActions({ actions }) {
|
|
370
|
+
useRegisterActions(actions);
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
/** The layer covers the page. Main calls it when it is in a layer. */
|
|
374
|
+
function useLayerCoversPage() {
|
|
375
|
+
const registry = useContext(RegistryContext);
|
|
376
|
+
const layer = useContext(LayerContext);
|
|
377
|
+
useEffect(() => {
|
|
378
|
+
if (!registry || layer === ROOT_LAYER) return;
|
|
379
|
+
return registry.coverPage(layer);
|
|
380
|
+
}, [registry, layer]);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Whether a layer with its own `Main` covers the page. The host makes the
|
|
384
|
+
* page inert while it does.
|
|
385
|
+
*/
|
|
386
|
+
function useIsPageCovered() {
|
|
387
|
+
return useContext(PageCoveredContext);
|
|
388
|
+
}
|
|
389
|
+
function reportProblem(message) {
|
|
390
|
+
if (process.env.NODE_ENV !== "production") throw new Error(message);
|
|
391
|
+
console.warn(message);
|
|
392
|
+
}
|
|
393
|
+
/** The props of the actions that the read hooks show */
|
|
394
|
+
function signatureOf(actions) {
|
|
395
|
+
return JSON.stringify(actions.map((action) => [
|
|
396
|
+
action.id,
|
|
397
|
+
action.name,
|
|
398
|
+
action.group,
|
|
399
|
+
action.shortcut,
|
|
400
|
+
action.layerSafe,
|
|
401
|
+
action.keywords,
|
|
402
|
+
action.palette,
|
|
403
|
+
action.applicable ? action.applicable() : true,
|
|
404
|
+
action.disabledReason ? action.disabledReason() : void 0
|
|
405
|
+
]));
|
|
406
|
+
}
|
|
407
|
+
function useRegisterActions(first, second) {
|
|
408
|
+
const withRegion = !Array.isArray(first);
|
|
409
|
+
const region = withRegion ? first : void 0;
|
|
410
|
+
const actions = withRegion ? second : first;
|
|
411
|
+
const level = region ? "region" : (withRegion ? void 0 : second)?.level ?? "page";
|
|
412
|
+
const registry = useContext(RegistryContext);
|
|
413
|
+
const layer = useContext(LayerContext);
|
|
414
|
+
const actionsRef = useRef(actions);
|
|
415
|
+
actionsRef.current = actions;
|
|
416
|
+
const [order] = useState(() => registry?.takeOrder() ?? 0);
|
|
417
|
+
const signature = signatureOf(actions);
|
|
418
|
+
const isEmpty = actions.length === 0;
|
|
419
|
+
useEffect(() => {
|
|
420
|
+
if (!registry || isEmpty) return;
|
|
421
|
+
const element = region?.current ?? null;
|
|
422
|
+
const regionState = region && {
|
|
423
|
+
element: () => region.current,
|
|
424
|
+
hovered: element?.matches(":hover") ?? false,
|
|
425
|
+
focused: element?.contains(document.activeElement) ?? false
|
|
426
|
+
};
|
|
427
|
+
const remove = registry.add({
|
|
428
|
+
order,
|
|
429
|
+
level,
|
|
430
|
+
layer,
|
|
431
|
+
actions: () => actionsRef.current,
|
|
432
|
+
region: regionState
|
|
433
|
+
});
|
|
434
|
+
if (!regionState || !element) return remove;
|
|
435
|
+
const update = (change) => {
|
|
436
|
+
const next = {
|
|
437
|
+
...regionState,
|
|
438
|
+
...change
|
|
439
|
+
};
|
|
440
|
+
if (next.hovered === regionState.hovered && next.focused === regionState.focused) return;
|
|
441
|
+
Object.assign(regionState, change);
|
|
442
|
+
registry.notify();
|
|
443
|
+
};
|
|
444
|
+
const handleEnter = () => update({ hovered: true });
|
|
445
|
+
const handleLeave = () => update({ hovered: false });
|
|
446
|
+
const handleFocusIn = () => update({ focused: true });
|
|
447
|
+
const handleFocusOut = (event) => update({ focused: element.contains(event.relatedTarget) });
|
|
448
|
+
element.addEventListener("mouseenter", handleEnter);
|
|
449
|
+
element.addEventListener("mouseleave", handleLeave);
|
|
450
|
+
element.addEventListener("focusin", handleFocusIn);
|
|
451
|
+
element.addEventListener("focusout", handleFocusOut);
|
|
452
|
+
return () => {
|
|
453
|
+
element.removeEventListener("mouseenter", handleEnter);
|
|
454
|
+
element.removeEventListener("mouseleave", handleLeave);
|
|
455
|
+
element.removeEventListener("focusin", handleFocusIn);
|
|
456
|
+
element.removeEventListener("focusout", handleFocusOut);
|
|
457
|
+
remove();
|
|
458
|
+
};
|
|
459
|
+
}, [
|
|
460
|
+
registry,
|
|
461
|
+
layer,
|
|
462
|
+
level,
|
|
463
|
+
region,
|
|
464
|
+
order,
|
|
465
|
+
isEmpty
|
|
466
|
+
]);
|
|
467
|
+
useEffect(() => {
|
|
468
|
+
for (const action of actionsRef.current) for (const shortcut of toList(action.shortcut)) {
|
|
469
|
+
const problem = shortcutProblem(shortcut);
|
|
470
|
+
if (problem) reportProblem(`The shortcut ${JSON.stringify(shortcut)} of the action "${action.id}" is refused: ${problem}.`);
|
|
471
|
+
}
|
|
472
|
+
if (!isEmpty) registry?.notify();
|
|
473
|
+
}, [
|
|
474
|
+
registry,
|
|
475
|
+
signature,
|
|
476
|
+
isEmpty
|
|
477
|
+
]);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* A value that the registry gives. The component renders again only when
|
|
481
|
+
* the value changes.
|
|
482
|
+
*/
|
|
483
|
+
function useRegistryValue(select, fallback, key) {
|
|
484
|
+
const registry = useContext(RegistryContext);
|
|
485
|
+
const selectRef = useRef(select);
|
|
486
|
+
selectRef.current = select;
|
|
487
|
+
const [value, setValue] = useState(() => registry ? select(registry) : fallback);
|
|
488
|
+
useEffect(() => {
|
|
489
|
+
if (!registry) return;
|
|
490
|
+
const update = () => {
|
|
491
|
+
const next = selectRef.current(registry);
|
|
492
|
+
setValue((current) => isEqual(current, next) ? current : next);
|
|
493
|
+
};
|
|
494
|
+
update();
|
|
495
|
+
return registry.subscribe(update);
|
|
496
|
+
}, [registry, key]);
|
|
497
|
+
return value;
|
|
498
|
+
}
|
|
499
|
+
function infoOf(entry, active) {
|
|
500
|
+
return {
|
|
501
|
+
id: entry.action.id,
|
|
502
|
+
name: entry.action.name,
|
|
503
|
+
parent: entry.action.parent,
|
|
504
|
+
icon: entry.action.icon,
|
|
505
|
+
group: entry.action.group,
|
|
506
|
+
shortcuts: validShortcuts(entry.action),
|
|
507
|
+
level: entry.registration.level,
|
|
508
|
+
active,
|
|
509
|
+
disabledReason: entry.action.disabledReason?.()
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* The action with this id: the active one, else the one that would win
|
|
514
|
+
* when its region or its page is on. `Button` and `Dropdown.Option` read
|
|
515
|
+
* the name, the keys and the reason with it. With an `origin` in a region
|
|
516
|
+
* that has the id, it gives the action of that region (see `find`).
|
|
517
|
+
*/
|
|
518
|
+
function useAction(id, origin) {
|
|
519
|
+
return useRegistryValue((registry) => {
|
|
520
|
+
const found = id === void 0 ? void 0 : registry.find(id, origin);
|
|
521
|
+
return found && infoOf(found.entry, found.active);
|
|
522
|
+
}, void 0, id);
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Gives a function that runs an action by its id. A disabled action shows
|
|
526
|
+
* its reason. The function gives `false` when the action did not run. The
|
|
527
|
+
* `source` is `menu` by default. A menu gives the element of its dropdown
|
|
528
|
+
* as `origin` (see `find`).
|
|
529
|
+
*/
|
|
530
|
+
function useRunAction() {
|
|
531
|
+
const registry = useContext(RegistryContext);
|
|
532
|
+
return useCallback((id, { source = "menu", origin } = {}) => {
|
|
533
|
+
const found = registry?.find(id, origin);
|
|
534
|
+
return registry && found ? registry.run(found.entry, source) : false;
|
|
535
|
+
}, [registry]);
|
|
536
|
+
}
|
|
537
|
+
/** The actions that work now, grouped by level, the winner first */
|
|
538
|
+
function useActiveActions() {
|
|
539
|
+
return useRegistryValue((registry) => {
|
|
540
|
+
const groups = {
|
|
541
|
+
app: [],
|
|
542
|
+
page: [],
|
|
543
|
+
region: []
|
|
544
|
+
};
|
|
545
|
+
for (const entry of registry.activeEntries()) groups[entry.registration.level].push(infoOf(entry, true));
|
|
546
|
+
return groups;
|
|
547
|
+
}, {
|
|
548
|
+
app: [],
|
|
549
|
+
page: [],
|
|
550
|
+
region: []
|
|
551
|
+
}, null);
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* One action for each id, the active ones first: the actions that work
|
|
555
|
+
* now, and the actions that work when their region, their page or their
|
|
556
|
+
* layer is on. The list of the shortcuts reads it.
|
|
557
|
+
*/
|
|
558
|
+
function useRegisteredActions() {
|
|
559
|
+
return useRegistryValue((registry) => registry.listedEntries().map(({ entry, active }) => infoOf(entry, active)), [], null);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Gives a function that reads the actions for the command palette: the
|
|
563
|
+
* active actions, the winner first, without the hidden ones. Read them
|
|
564
|
+
* before the palette opens: its dialog turns off the actions under it.
|
|
565
|
+
*/
|
|
566
|
+
function useReadPaletteActions() {
|
|
567
|
+
const registry = useContext(RegistryContext);
|
|
568
|
+
return useCallback(() => registry ? registry.activeEntries().flatMap((entry) => {
|
|
569
|
+
const palette = entry.action.palette ?? "listed";
|
|
570
|
+
if (palette === "hidden") return [];
|
|
571
|
+
return [{
|
|
572
|
+
...infoOf(entry, true),
|
|
573
|
+
keywords: entry.action.keywords ?? [],
|
|
574
|
+
palette,
|
|
575
|
+
run: () => registry.rerun(entry, "palette")
|
|
576
|
+
}];
|
|
577
|
+
}) : [], [registry]);
|
|
578
|
+
}
|
|
579
|
+
//#endregion
|
|
580
|
+
export { ActionLayer, ActionsProvider, GENERAL_ACTION_GROUP, LIST_ACTION_GROUP, useAction, useActiveActions, useIsPageCovered, useLayerCoversPage, useReadPaletteActions, useRegisterActions, useRegisteredActions, useRunAction };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
declare const LETTERS: readonly ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
|
|
2
|
+
declare const DIGITS: readonly ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
|
|
3
|
+
declare const FUNCTION_KEYS: readonly ["f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12"];
|
|
4
|
+
type Letter = (typeof LETTERS)[number];
|
|
5
|
+
type Digit = (typeof DIGITS)[number];
|
|
6
|
+
type FunctionKey = (typeof FUNCTION_KEYS)[number];
|
|
7
|
+
/**
|
|
8
|
+
* A key. A letter, a digit or a sign matches the character that the layout of
|
|
9
|
+
* the user types. When the layout types a character that is not ASCII
|
|
10
|
+
* (Cyrillic, Greek), it matches the key at that place on a US keyboard.
|
|
11
|
+
*/
|
|
12
|
+
export type ShortcutKey = Letter | Digit | FunctionKey | 'enter' | 'escape' | 'space' | 'tab' | 'backspace' | 'delete' | 'arrowup' | 'arrowdown' | 'arrowleft' | 'arrowright' | 'home' | 'end' | 'pageup' | 'pagedown' | '/' | '.' | ',' | ';' | "'" | '[' | ']' | '\\' | '-' | '=' | '`' | '?';
|
|
13
|
+
/** One key, with its modifiers */
|
|
14
|
+
export type KeyShortcut = {
|
|
15
|
+
/** The key */
|
|
16
|
+
key: ShortcutKey;
|
|
17
|
+
/** Cmd on a Mac, Ctrl on the other systems */
|
|
18
|
+
mod?: boolean;
|
|
19
|
+
shift?: boolean;
|
|
20
|
+
/** Option on a Mac */
|
|
21
|
+
alt?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The shortcut also works while the focus is in a text field. It must
|
|
24
|
+
* have `mod`: a key without it types a character.
|
|
25
|
+
*/
|
|
26
|
+
runWithInputFocus?: boolean;
|
|
27
|
+
};
|
|
28
|
+
/** Two keys, one after the other, with no modifier (`G` then `S`) */
|
|
29
|
+
export type SequenceShortcut = {
|
|
30
|
+
/** The first key and the second key */
|
|
31
|
+
key: readonly [ShortcutKey, ShortcutKey];
|
|
32
|
+
mod?: never;
|
|
33
|
+
shift?: never;
|
|
34
|
+
alt?: never;
|
|
35
|
+
runWithInputFocus?: never;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The keys of an action: `{ key: 'p' }`, `{ key: 's', mod: true }` or
|
|
39
|
+
* `{ key: ['g', 's'] }`.
|
|
40
|
+
*/
|
|
41
|
+
export type ActionShortcut = KeyShortcut | SequenceShortcut;
|
|
42
|
+
export declare function isSequence(shortcut: ActionShortcut): shortcut is SequenceShortcut;
|
|
43
|
+
export declare function toList(shortcut: ActionShortcut | ActionShortcut[] | undefined): ActionShortcut[];
|
|
44
|
+
/**
|
|
45
|
+
* The reason why the registry refuses a shortcut, or undefined. The browser
|
|
46
|
+
* does not let a page cancel some keys on some systems, thus they never
|
|
47
|
+
* reach the page.
|
|
48
|
+
*/
|
|
49
|
+
export declare function shortcutProblem(shortcut: ActionShortcut): string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* The keys of a string in the format of `is-hotkey` ("mod+shift+s"), or
|
|
52
|
+
* undefined when the string has a key that a shortcut does not know. The
|
|
53
|
+
* text editors give their keys in this format.
|
|
54
|
+
*/
|
|
55
|
+
export declare function parseShortcut(hotKey: string): KeyShortcut | undefined;
|
|
56
|
+
/** A key press, without the event: the buffer of a sequence keeps it */
|
|
57
|
+
export type Stroke = {
|
|
58
|
+
code: string;
|
|
59
|
+
key: string;
|
|
60
|
+
mod: boolean;
|
|
61
|
+
shift: boolean;
|
|
62
|
+
alt: boolean;
|
|
63
|
+
/** The modifier that is not `mod`: Ctrl on a Mac, Cmd elsewhere */
|
|
64
|
+
other: boolean;
|
|
65
|
+
};
|
|
66
|
+
export declare function strokeOf(event: KeyboardEvent, mac: boolean): Stroke;
|
|
67
|
+
export declare function isModifierOnly(stroke: Stroke): boolean;
|
|
68
|
+
/** The stroke is a key with no modifier: it can start a sequence */
|
|
69
|
+
export declare function isPlain(stroke: Stroke): boolean;
|
|
70
|
+
/** The shortcut matches the last stroke, or the last two for a sequence */
|
|
71
|
+
export declare function shortcutMatches(shortcut: ActionShortcut, stroke: Stroke, previous: Stroke | undefined): boolean;
|
|
72
|
+
/** The stroke is the first key of the sequence */
|
|
73
|
+
export declare function sequenceStartsWith(shortcut: ActionShortcut, stroke: Stroke): boolean;
|
|
74
|
+
export declare function isMac(): boolean;
|
|
75
|
+
/** A key as the keycap and as a screen reader says it */
|
|
76
|
+
export type KeyLabel = {
|
|
77
|
+
visible: string;
|
|
78
|
+
spoken: string;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* The keys of each stroke of a shortcut, in the order of the system:
|
|
82
|
+
* ⌥ ⇧ ⌘ on a Mac, Ctrl Alt Shift elsewhere.
|
|
83
|
+
*/
|
|
84
|
+
export declare function strokeLabels(shortcut: ActionShortcut, mac: boolean): KeyLabel[][];
|
|
85
|
+
export {};
|