fix: resolve TypeScript errors in frontend build

This commit is contained in:
Hiro
2026-03-30 23:16:07 +00:00
parent b733306773
commit 24925e1acb
2941 changed files with 418042 additions and 49 deletions

8
node_modules/prosemirror-keymap/.tern-project generated vendored Normal file
View File

@@ -0,0 +1,8 @@
{
"libs": ["browser"],
"plugins": {
"node": {},
"complete_strings": {},
"es_modules": {}
}
}

104
node_modules/prosemirror-keymap/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,104 @@
## 1.2.3 (2025-05-04)
### Bug fixes
Fix an issue where the library was too eager to dispatch keys by key code when the character produced isn't ASCII.
## 1.2.2 (2023-05-17)
### Bug fixes
Include CommonJS type declarations in the package to please new TypeScript resolution settings.
## 1.2.1 (2023-02-14)
### Bug fixes
Work around macOS putting the unmodified character in `KeyboardEvent.key` when Cmd is held down, fixing shift-cmd-letter bindings.
## 1.2.0 (2022-05-30)
### New features
Include TypeScript type declarations.
## 1.1.5 (2021-10-29)
### Bug fixes
Fix issue where iPhones and iPads with a hardware keyboard didn't have Mod converted to Cmd.
## 1.1.4 (2020-05-18)
### Bug fixes
Fall through to the name associated with a key's `keyCode` when the character produced isn't ASCII and isn't directly bound.
## 1.1.3 (2019-11-20)
### Bug fixes
Rename ES module files to use a .js extension, since Webpack gets confused by .mjs
## 1.1.2 (2019-11-19)
### Bug fixes
The file referred to in the package's `module` field now is compiled down to ES5.
## 1.1.1 (2019-11-15)
### Bug fixes
Fix an issue where keyboards layouts that use shift to produce characters that are created without shift on a US keyboard would fail to fire bindings for those keys that include the Shift- modifier.
## 1.1.0 (2019-11-08)
### New features
Add a `module` field to package json file.
## 1.0.2 (2019-10-16)
### Bug fixes
Upgrade w3c-keyname package dependency.
## 1.0.1 (2018-02-23)
### Bug fixes
Upgrade `w3c-keyname` dependency to version 1.1.8 to prevent users getting stuck with a buggy version.
## 0.22.1 (2017-07-14)
### Bug fixes
Bindings like Alt-3 should now fire even if your keyboard produces a special character for that combination.
## 0.18.0 (2017-02-24)
### New features
Add a [`keydownHandler`](https://prosemirror.net/docs/ref/version/0.18.0.html#keymap.keydownHandler) function, which takes a keymap and produces a [`handleKeydown` prop](https://prosemirror.net/docs/ref/version/0.18.0.html#view.EditorProps.handleKeydown)-style function.
## 0.12.0 (2016-10-21)
### Breaking changes
Key names are now based on
[`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
instead of
[`.code`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code).
This means that, for character-producing keys, you'll want to use the
character typed, not the key name. So `Ctrl-Z` now means uppercase Z,
and you'll usually want `Ctrl-z` instead. Single-quoted key names are
no longer supported.
## 0.11.0 (2016-09-21)
### Breaking changes
New module, takes the same role as the old built-in keymap support in
the `ProseMirror` class.

104
node_modules/prosemirror-keymap/CONTRIBUTING.md generated vendored Normal file
View File

@@ -0,0 +1,104 @@
# How to contribute
- [Getting help](#getting-help)
- [Submitting bug reports](#submitting-bug-reports)
- [Contributing code](#contributing-code)
## Getting help
Community discussion, questions, and informal bug reporting is done on the
[discuss.ProseMirror forum](http://discuss.prosemirror.net).
## Submitting bug reports
Report bugs on the
[GitHub issue tracker](http://github.com/prosemirror/prosemirror/issues).
Before reporting a bug, please read these pointers.
- The issue tracker is for *bugs*, not requests for help. Questions
should be asked on the [forum](http://discuss.prosemirror.net).
- Include information about the version of the code that exhibits the
problem. For browser-related issues, include the browser and browser
version on which the problem occurred.
- Mention very precisely what went wrong. "X is broken" is not a good
bug report. What did you expect to happen? What happened instead?
Describe the exact steps a maintainer has to take to make the
problem occur. A screencast can be useful, but is no substitute for
a textual description.
- A great way to make it easy to reproduce your problem, if it can not
be trivially reproduced on the website demos, is to submit a script
that triggers the issue.
## Contributing code
If you want to make a change that involves a significant overhaul of
the code or introduces a user-visible new feature, create an
[RFC](https://github.com/ProseMirror/rfcs/) first with your proposal.
- Make sure you have a [GitHub Account](https://github.com/signup/free)
- Fork the relevant repository
([how to fork a repo](https://help.github.com/articles/fork-a-repo))
- Create a local checkout of the code. You can use the
[main repository](https://github.com/prosemirror/prosemirror) to
easily check out all core modules.
- Make your changes, and commit them
- Follow the code style of the rest of the project (see below). Run
`npm run lint` (in the main repository checkout) to make sure that
the linter is happy.
- If your changes are easy to test or likely to regress, add tests in
the relevant `test/` directory. Either put them in an existing
`test-*.js` file, if they fit there, or add a new file.
- Make sure all tests pass. Run `npm run test` to verify tests pass
(you will need Node.js v6+).
- Submit a pull request ([how to create a pull request](https://help.github.com/articles/fork-a-repo)).
Don't put more than one feature/fix in a single pull request.
By contributing code to ProseMirror you
- Agree to license the contributed code under the project's [MIT
license](https://github.com/ProseMirror/prosemirror/blob/master/LICENSE).
- Confirm that you have the right to contribute and license the code
in question. (Either you hold all rights on the code, or the rights
holder has explicitly granted the right to use it like this,
through a compatible open source license or through a direct
agreement with you.)
### Coding standards
- ES6 syntax, targeting an ES5 runtime (i.e. don't use library
elements added by ES6, don't use ES7/ES.next syntax).
- 2 spaces per indentation level, no tabs.
- No semicolons except when necessary.
- Follow the surrounding code when it comes to spacing, brace
placement, etc.
- Brace-less single-statement bodies are encouraged (whenever they
don't impact readability).
- [getdocs](https://github.com/marijnh/getdocs)-style doc comments
above items that are part of the public API.
- When documenting non-public items, you can put the type after a
single colon, so that getdocs doesn't pick it up and add it to the
API reference.
- The linter (`npm run lint`) complains about unused variables and
functions. Prefix their names with an underscore to muffle it.
- ProseMirror does *not* follow JSHint or JSLint prescribed style.
Patches that try to 'fix' code to pass one of these linters will not
be accepted.

19
node_modules/prosemirror-keymap/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,19 @@
Copyright (C) 2015-2017 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

27
node_modules/prosemirror-keymap/README.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# prosemirror-keymap
[ [**WEBSITE**](https://prosemirror.net) | [**ISSUES**](https://github.com/prosemirror/prosemirror/issues) | [**FORUM**](https://discuss.prosemirror.net) | [**CHANGELOG**](https://github.com/ProseMirror/prosemirror-keymap/blob/master/CHANGELOG.md) ]
This is a [core module](https://prosemirror.net/docs/ref/#keymap) of [ProseMirror](https://prosemirror.net).
ProseMirror is a well-behaved rich semantic content editor based on
contentEditable, with support for collaborative editing and custom
document schemas.
This [module](https://prosemirror.net/docs/ref/#keymap) implements a
plugin for conveniently defining key bindings.
The [project page](https://prosemirror.net) has more information, a
number of [examples](https://prosemirror.net/examples/) and the
[documentation](https://prosemirror.net/docs/).
This code is released under an
[MIT license](https://github.com/prosemirror/prosemirror/tree/master/LICENSE).
There's a [forum](http://discuss.prosemirror.net) for general
discussion and support requests, and the
[Github bug tracker](https://github.com/prosemirror/prosemirror/issues)
is the place to report issues.
We aim to be an inclusive, welcoming community. To make that explicit,
we have a [code of
conduct](http://contributor-covenant.org/version/1/1/0/) that applies
to communication around the project.

65
node_modules/prosemirror-keymap/dist/index.cjs generated vendored Normal file
View File

@@ -0,0 +1,65 @@
'use strict';
var w3cKeyname = require('w3c-keyname');
var prosemirrorState = require('prosemirror-state');
var mac = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
var windows = typeof navigator != "undefined" && /Win/.test(navigator.platform);
function normalizeKeyName(name) {
var parts = name.split(/-(?!$)/),
result = parts[parts.length - 1];
if (result == "Space") result = " ";
var alt, ctrl, shift, meta;
for (var i = 0; i < parts.length - 1; i++) {
var mod = parts[i];
if (/^(cmd|meta|m)$/i.test(mod)) meta = true;else if (/^a(lt)?$/i.test(mod)) alt = true;else if (/^(c|ctrl|control)$/i.test(mod)) ctrl = true;else if (/^s(hift)?$/i.test(mod)) shift = true;else if (/^mod$/i.test(mod)) {
if (mac) meta = true;else ctrl = true;
} else throw new Error("Unrecognized modifier name: " + mod);
}
if (alt) result = "Alt-" + result;
if (ctrl) result = "Ctrl-" + result;
if (meta) result = "Meta-" + result;
if (shift) result = "Shift-" + result;
return result;
}
function normalize(map) {
var copy = Object.create(null);
for (var prop in map) copy[normalizeKeyName(prop)] = map[prop];
return copy;
}
function modifiers(name, event) {
var shift = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
if (event.altKey) name = "Alt-" + name;
if (event.ctrlKey) name = "Ctrl-" + name;
if (event.metaKey) name = "Meta-" + name;
if (shift && event.shiftKey) name = "Shift-" + name;
return name;
}
function keymap(bindings) {
return new prosemirrorState.Plugin({
props: {
handleKeyDown: keydownHandler(bindings)
}
});
}
function keydownHandler(bindings) {
var map = normalize(bindings);
return function (view, event) {
var name = w3cKeyname.keyName(event),
baseName,
direct = map[modifiers(name, event)];
if (direct && direct(view.state, view.dispatch, view)) return true;
if (name.length == 1 && name != " ") {
if (event.shiftKey) {
var noShift = map[modifiers(name, event, false)];
if (noShift && noShift(view.state, view.dispatch, view)) return true;
}
if ((event.altKey || event.metaKey || event.ctrlKey) && !(windows && event.ctrlKey && event.altKey) && (baseName = w3cKeyname.base[event.keyCode]) && baseName != name) {
var fromCode = map[modifiers(baseName, event)];
if (fromCode && fromCode(view.state, view.dispatch, view)) return true;
}
}
return false;
};
}
exports.keydownHandler = keydownHandler;
exports.keymap = keymap;

47
node_modules/prosemirror-keymap/dist/index.d.cts generated vendored Normal file
View File

@@ -0,0 +1,47 @@
import { Command, Plugin } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view';
/**
Create a keymap plugin for the given set of bindings.
Bindings should map key names to [command](https://prosemirror.net/docs/ref/#commands)-style
functions, which will be called with `(EditorState, dispatch,
EditorView)` arguments, and should return true when they've handled
the key. Note that the view argument isn't part of the command
protocol, but can be used as an escape hatch if a binding needs to
directly interact with the UI.
Key names may be strings like `"Shift-Ctrl-Enter"`—a key
identifier prefixed with zero or more modifiers. Key identifiers
are based on the strings that can appear in
[`KeyEvent.key`](https:developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key).
Use lowercase letters to refer to letter keys (or uppercase letters
if you want shift to be held). You may use `"Space"` as an alias
for the `" "` name.
Modifiers can be given in any order. `Shift-` (or `s-`), `Alt-` (or
`a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or
`Meta-`) are recognized. For characters that are created by holding
shift, the `Shift-` prefix is implied, and should not be added
explicitly.
You can use `Mod-` as a shorthand for `Cmd-` on Mac and `Ctrl-` on
other platforms.
You can add multiple keymap plugins to an editor. The order in
which they appear determines their precedence (the ones early in
the array get to dispatch first).
*/
declare function keymap(bindings: {
[key: string]: Command;
}): Plugin;
/**
Given a set of bindings (using the same format as
[`keymap`](https://prosemirror.net/docs/ref/#keymap.keymap)), return a [keydown
handler](https://prosemirror.net/docs/ref/#view.EditorProps.handleKeyDown) that handles them.
*/
declare function keydownHandler(bindings: {
[key: string]: Command;
}): (view: EditorView, event: KeyboardEvent) => boolean;
export { keydownHandler, keymap };

47
node_modules/prosemirror-keymap/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,47 @@
import { Command, Plugin } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view';
/**
Create a keymap plugin for the given set of bindings.
Bindings should map key names to [command](https://prosemirror.net/docs/ref/#commands)-style
functions, which will be called with `(EditorState, dispatch,
EditorView)` arguments, and should return true when they've handled
the key. Note that the view argument isn't part of the command
protocol, but can be used as an escape hatch if a binding needs to
directly interact with the UI.
Key names may be strings like `"Shift-Ctrl-Enter"`—a key
identifier prefixed with zero or more modifiers. Key identifiers
are based on the strings that can appear in
[`KeyEvent.key`](https:developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key).
Use lowercase letters to refer to letter keys (or uppercase letters
if you want shift to be held). You may use `"Space"` as an alias
for the `" "` name.
Modifiers can be given in any order. `Shift-` (or `s-`), `Alt-` (or
`a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or
`Meta-`) are recognized. For characters that are created by holding
shift, the `Shift-` prefix is implied, and should not be added
explicitly.
You can use `Mod-` as a shorthand for `Cmd-` on Mac and `Ctrl-` on
other platforms.
You can add multiple keymap plugins to an editor. The order in
which they appear determines their precedence (the ones early in
the array get to dispatch first).
*/
declare function keymap(bindings: {
[key: string]: Command;
}): Plugin;
/**
Given a set of bindings (using the same format as
[`keymap`](https://prosemirror.net/docs/ref/#keymap.keymap)), return a [keydown
handler](https://prosemirror.net/docs/ref/#view.EditorProps.handleKeyDown) that handles them.
*/
declare function keydownHandler(bindings: {
[key: string]: Command;
}): (view: EditorView, event: KeyboardEvent) => boolean;
export { keydownHandler, keymap };

128
node_modules/prosemirror-keymap/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,128 @@
import { keyName, base } from 'w3c-keyname';
import { Plugin } from 'prosemirror-state';
const mac = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
const windows = typeof navigator != "undefined" && /Win/.test(navigator.platform);
function normalizeKeyName(name) {
let parts = name.split(/-(?!$)/), result = parts[parts.length - 1];
if (result == "Space")
result = " ";
let alt, ctrl, shift, meta;
for (let i = 0; i < parts.length - 1; i++) {
let mod = parts[i];
if (/^(cmd|meta|m)$/i.test(mod))
meta = true;
else if (/^a(lt)?$/i.test(mod))
alt = true;
else if (/^(c|ctrl|control)$/i.test(mod))
ctrl = true;
else if (/^s(hift)?$/i.test(mod))
shift = true;
else if (/^mod$/i.test(mod)) {
if (mac)
meta = true;
else
ctrl = true;
}
else
throw new Error("Unrecognized modifier name: " + mod);
}
if (alt)
result = "Alt-" + result;
if (ctrl)
result = "Ctrl-" + result;
if (meta)
result = "Meta-" + result;
if (shift)
result = "Shift-" + result;
return result;
}
function normalize(map) {
let copy = Object.create(null);
for (let prop in map)
copy[normalizeKeyName(prop)] = map[prop];
return copy;
}
function modifiers(name, event, shift = true) {
if (event.altKey)
name = "Alt-" + name;
if (event.ctrlKey)
name = "Ctrl-" + name;
if (event.metaKey)
name = "Meta-" + name;
if (shift && event.shiftKey)
name = "Shift-" + name;
return name;
}
/**
Create a keymap plugin for the given set of bindings.
Bindings should map key names to [command](https://prosemirror.net/docs/ref/#commands)-style
functions, which will be called with `(EditorState, dispatch,
EditorView)` arguments, and should return true when they've handled
the key. Note that the view argument isn't part of the command
protocol, but can be used as an escape hatch if a binding needs to
directly interact with the UI.
Key names may be strings like `"Shift-Ctrl-Enter"`—a key
identifier prefixed with zero or more modifiers. Key identifiers
are based on the strings that can appear in
[`KeyEvent.key`](https:developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key).
Use lowercase letters to refer to letter keys (or uppercase letters
if you want shift to be held). You may use `"Space"` as an alias
for the `" "` name.
Modifiers can be given in any order. `Shift-` (or `s-`), `Alt-` (or
`a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or
`Meta-`) are recognized. For characters that are created by holding
shift, the `Shift-` prefix is implied, and should not be added
explicitly.
You can use `Mod-` as a shorthand for `Cmd-` on Mac and `Ctrl-` on
other platforms.
You can add multiple keymap plugins to an editor. The order in
which they appear determines their precedence (the ones early in
the array get to dispatch first).
*/
function keymap(bindings) {
return new Plugin({ props: { handleKeyDown: keydownHandler(bindings) } });
}
/**
Given a set of bindings (using the same format as
[`keymap`](https://prosemirror.net/docs/ref/#keymap.keymap)), return a [keydown
handler](https://prosemirror.net/docs/ref/#view.EditorProps.handleKeyDown) that handles them.
*/
function keydownHandler(bindings) {
let map = normalize(bindings);
return function (view, event) {
let name = keyName(event), baseName, direct = map[modifiers(name, event)];
if (direct && direct(view.state, view.dispatch, view))
return true;
// A character key
if (name.length == 1 && name != " ") {
if (event.shiftKey) {
// In case the name was already modified by shift, try looking
// it up without its shift modifier
let noShift = map[modifiers(name, event, false)];
if (noShift && noShift(view.state, view.dispatch, view))
return true;
}
if ((event.altKey || event.metaKey || event.ctrlKey) &&
// Ctrl-Alt may be used for AltGr on Windows
!(windows && event.ctrlKey && event.altKey) &&
(baseName = base[event.keyCode]) && baseName != name) {
// Try falling back to the keyCode when there's a modifier
// active or the character produced isn't ASCII, and our table
// produces a different name from the the keyCode. See #668,
// #1060, #1529.
let fromCode = map[modifiers(baseName, event)];
if (fromCode && fromCode(view.state, view.dispatch, view))
return true;
}
}
return false;
};
}
export { keydownHandler, keymap };

38
node_modules/prosemirror-keymap/package.json generated vendored Normal file
View File

@@ -0,0 +1,38 @@
{
"name": "prosemirror-keymap",
"version": "1.2.3",
"description": "Keymap plugin for ProseMirror",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"sideEffects": false,
"license": "MIT",
"maintainers": [
{
"name": "Marijn Haverbeke",
"email": "marijn@haverbeke.berlin",
"web": "http://marijnhaverbeke.nl"
}
],
"repository": {
"type": "git",
"url": "git://github.com/prosemirror/prosemirror-keymap.git"
},
"dependencies": {
"w3c-keyname": "^2.2.0",
"prosemirror-state": "^1.0.0"
},
"devDependencies": {
"@prosemirror/buildhelper": "^0.1.5",
"prosemirror-test-builder": "^1.0.0"
},
"scripts": {
"test": "pm-runtests",
"prepare": "pm-buildhelper src/keymap.ts"
}
}

5
node_modules/prosemirror-keymap/src/README.md generated vendored Normal file
View File

@@ -0,0 +1,5 @@
A plugin for conveniently defining key bindings.
@keymap
@keydownHandler

105
node_modules/prosemirror-keymap/src/keymap.ts generated vendored Normal file
View File

@@ -0,0 +1,105 @@
import {base, keyName} from "w3c-keyname"
import {Plugin, Command} from "prosemirror-state"
import {EditorView} from "prosemirror-view"
const mac = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform)
const windows = typeof navigator != "undefined" && /Win/.test(navigator.platform)
function normalizeKeyName(name: string) {
let parts = name.split(/-(?!$)/), result = parts[parts.length - 1]
if (result == "Space") result = " "
let alt, ctrl, shift, meta
for (let i = 0; i < parts.length - 1; i++) {
let mod = parts[i]
if (/^(cmd|meta|m)$/i.test(mod)) meta = true
else if (/^a(lt)?$/i.test(mod)) alt = true
else if (/^(c|ctrl|control)$/i.test(mod)) ctrl = true
else if (/^s(hift)?$/i.test(mod)) shift = true
else if (/^mod$/i.test(mod)) { if (mac) meta = true; else ctrl = true }
else throw new Error("Unrecognized modifier name: " + mod)
}
if (alt) result = "Alt-" + result
if (ctrl) result = "Ctrl-" + result
if (meta) result = "Meta-" + result
if (shift) result = "Shift-" + result
return result
}
function normalize(map: {[key: string]: Command}) {
let copy: {[key: string]: Command} = Object.create(null)
for (let prop in map) copy[normalizeKeyName(prop)] = map[prop]
return copy
}
function modifiers(name: string, event: KeyboardEvent, shift = true) {
if (event.altKey) name = "Alt-" + name
if (event.ctrlKey) name = "Ctrl-" + name
if (event.metaKey) name = "Meta-" + name
if (shift && event.shiftKey) name = "Shift-" + name
return name
}
/// Create a keymap plugin for the given set of bindings.
///
/// Bindings should map key names to [command](#commands)-style
/// functions, which will be called with `(EditorState, dispatch,
/// EditorView)` arguments, and should return true when they've handled
/// the key. Note that the view argument isn't part of the command
/// protocol, but can be used as an escape hatch if a binding needs to
/// directly interact with the UI.
///
/// Key names may be strings like `"Shift-Ctrl-Enter"`—a key
/// identifier prefixed with zero or more modifiers. Key identifiers
/// are based on the strings that can appear in
/// [`KeyEvent.key`](https:///developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key).
/// Use lowercase letters to refer to letter keys (or uppercase letters
/// if you want shift to be held). You may use `"Space"` as an alias
/// for the `" "` name.
///
/// Modifiers can be given in any order. `Shift-` (or `s-`), `Alt-` (or
/// `a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or
/// `Meta-`) are recognized. For characters that are created by holding
/// shift, the `Shift-` prefix is implied, and should not be added
/// explicitly.
///
/// You can use `Mod-` as a shorthand for `Cmd-` on Mac and `Ctrl-` on
/// other platforms.
///
/// You can add multiple keymap plugins to an editor. The order in
/// which they appear determines their precedence (the ones early in
/// the array get to dispatch first).
export function keymap(bindings: {[key: string]: Command}): Plugin {
return new Plugin({props: {handleKeyDown: keydownHandler(bindings)}})
}
/// Given a set of bindings (using the same format as
/// [`keymap`](#keymap.keymap)), return a [keydown
/// handler](#view.EditorProps.handleKeyDown) that handles them.
export function keydownHandler(bindings: {[key: string]: Command}): (view: EditorView, event: KeyboardEvent) => boolean {
let map = normalize(bindings)
return function(view, event) {
let name = keyName(event), baseName, direct = map[modifiers(name, event)]
if (direct && direct(view.state, view.dispatch, view)) return true
// A character key
if (name.length == 1 && name != " ") {
if (event.shiftKey) {
// In case the name was already modified by shift, try looking
// it up without its shift modifier
let noShift = map[modifiers(name, event, false)]
if (noShift && noShift(view.state, view.dispatch, view)) return true
}
if ((event.altKey || event.metaKey || event.ctrlKey) &&
// Ctrl-Alt may be used for AltGr on Windows
!(windows && event.ctrlKey && event.altKey) &&
(baseName = base[event.keyCode]) && baseName != name) {
// Try falling back to the keyCode when there's a modifier
// active or the character produced isn't ASCII, and our table
// produces a different name from the the keyCode. See #668,
// #1060, #1529.
let fromCode = map[modifiers(baseName, event)]
if (fromCode && fromCode(view.state, view.dispatch, view)) return true
}
}
return false
}
}