vitest-prosemirror 1.0.0 → 1.1.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/index.js
CHANGED
|
@@ -629,27 +629,29 @@ function tokenizeKeyboardInput(input) {
|
|
|
629
629
|
const output = [];
|
|
630
630
|
let currentGroupOpener = null;
|
|
631
631
|
let group = "";
|
|
632
|
+
let escaped = false;
|
|
632
633
|
for (const char of input) if (currentGroupOpener !== null) {
|
|
633
|
-
if (
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
634
|
+
if (escaped) {
|
|
635
|
+
group += char === matchingBrace(currentGroupOpener) || char === "\\" ? char : `\\${char}`;
|
|
636
|
+
escaped = false;
|
|
637
|
+
} else if (char === "\\") escaped = true;
|
|
638
|
+
else if (char === matchingBrace(currentGroupOpener)) {
|
|
639
|
+
assertSupported(group);
|
|
640
|
+
if (group.length === 4 && group.startsWith("Key")) output.push(group.slice(3).toLowerCase());
|
|
641
|
+
else output.push(group);
|
|
642
|
+
currentGroupOpener = null;
|
|
643
|
+
group = "";
|
|
641
644
|
} else if (group === "" && currentGroupOpener === char) {
|
|
642
645
|
output.push(char);
|
|
643
646
|
currentGroupOpener = null;
|
|
644
|
-
group = "";
|
|
645
647
|
} else group += char;
|
|
646
648
|
} else if (["[", "{"].includes(char)) currentGroupOpener = char;
|
|
647
649
|
else output.push(char);
|
|
648
|
-
|
|
650
|
+
if (currentGroupOpener !== null) throw new Error("Unterminated group in keyboard input");
|
|
649
651
|
return output;
|
|
650
652
|
}
|
|
651
|
-
function assertSupported(
|
|
652
|
-
if (/^\/.+/u.exec(
|
|
653
|
+
function assertSupported(group) {
|
|
654
|
+
if (/^\/.+/u.exec(group) || /.*[^-]>[\d]*\/?$/u.exec(group)) throw new Error("Unsupported keyboard input");
|
|
653
655
|
}
|
|
654
656
|
function matchingBrace(opener) {
|
|
655
657
|
return opener === "{" ? "}" : "]";
|
|
@@ -702,14 +704,14 @@ function type(view, text) {
|
|
|
702
704
|
...modifiers,
|
|
703
705
|
shiftKey
|
|
704
706
|
};
|
|
705
|
-
const keydownEvent =
|
|
707
|
+
const keydownEvent = keyboardEvent("keydown", eventInit);
|
|
706
708
|
view.dispatchEvent(keydownEvent);
|
|
707
709
|
if (!keydownEvent.defaultPrevented) {
|
|
708
710
|
const action = keyAction(character, modifiers);
|
|
709
711
|
if (action.type === "delete") deleteText(view, action.direction);
|
|
710
712
|
else if (action.type === "moveCaret") moveCaret(view, action.direction, action.extend);
|
|
711
713
|
else if (action.type === "type") {
|
|
712
|
-
view.dispatchEvent(
|
|
714
|
+
view.dispatchEvent(keyboardEvent("keypress", {
|
|
713
715
|
...eventInit,
|
|
714
716
|
charCode: identity.charCode,
|
|
715
717
|
keyCode: identity.charCode
|
|
@@ -717,7 +719,7 @@ function type(view, text) {
|
|
|
717
719
|
typeCharacter(view, action.character);
|
|
718
720
|
}
|
|
719
721
|
}
|
|
720
|
-
view.dispatchEvent(
|
|
722
|
+
view.dispatchEvent(keyboardEvent("keyup", eventInit));
|
|
721
723
|
}
|
|
722
724
|
}
|
|
723
725
|
function keyAction(key, modifiers) {
|
|
@@ -752,6 +754,14 @@ function keyAction(key, modifiers) {
|
|
|
752
754
|
}
|
|
753
755
|
throw new Error(`Cannot simulate the "${key}" key`);
|
|
754
756
|
}
|
|
757
|
+
function keyboardEvent(eventType, init) {
|
|
758
|
+
const event = new KeyboardEvent(eventType, { ...init });
|
|
759
|
+
if (!Object.hasOwn(event, "charCode")) Object.defineProperty(event, "charCode", {
|
|
760
|
+
configurable: true,
|
|
761
|
+
value: init.charCode
|
|
762
|
+
});
|
|
763
|
+
return event;
|
|
764
|
+
}
|
|
755
765
|
//#endregion
|
|
756
766
|
//#region src/renderProseMirror.ts
|
|
757
767
|
var originalMutationObserver = global.MutationObserver;
|
package/dist/setup.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as resolveSelection, i as containsRTL, n as cleanupEditors, t as ProseMirrorEditorImpl } from "./renderProseMirror-
|
|
1
|
+
import { a as resolveSelection, i as containsRTL, n as cleanupEditors, t as ProseMirrorEditorImpl } from "./renderProseMirror-BdkGkoiJ.js";
|
|
2
2
|
import { afterEach, expect } from "vitest";
|
|
3
3
|
import stringifyObject from "stringify-object";
|
|
4
4
|
//#region src/isProseMirrorNode.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-prosemirror",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A plugin for Vitest that enables you to write tests using the ProseMirror editor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vitest",
|
|
@@ -52,7 +52,9 @@
|
|
|
52
52
|
"lint:ts:typecheck": "tsc --noEmit",
|
|
53
53
|
"prepack": "npm run build",
|
|
54
54
|
"start": "vite build --watch",
|
|
55
|
-
"test": "
|
|
55
|
+
"test": "run-s test:*",
|
|
56
|
+
"test:happy-dom": "VITEST_ENVIRONMENT=happy-dom vitest run",
|
|
57
|
+
"test:jsdom": "vitest run --coverage",
|
|
56
58
|
"test-watch": "vitest"
|
|
57
59
|
},
|
|
58
60
|
"dependencies": {
|
|
@@ -80,6 +82,7 @@
|
|
|
80
82
|
"eslint-plugin-perfectionist": "^5.0.0",
|
|
81
83
|
"eslint-plugin-prefer-arrow-functions": "^3.9.1",
|
|
82
84
|
"eslint-plugin-prettier": "^5.1.3",
|
|
85
|
+
"happy-dom": "^20.14.3",
|
|
83
86
|
"jiti": "^2.7.0",
|
|
84
87
|
"jsdom": "^30.0.0",
|
|
85
88
|
"npm-run-all2": "^9.0.3",
|