@portabletext/editor 1.12.1 → 1.12.3
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/lib/index.esm.js +114 -3
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +118 -6
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +114 -3
- package/lib/index.mjs.map +1 -1
- package/package.json +6 -3
- package/src/editor/behavior/behavior.markdown.ts +2 -2
- package/src/editor/plugins/createWithHotKeys.ts +1 -1
- package/src/utils/is-hotkey.test.ts +61 -0
- package/src/utils/is-hotkey.ts +209 -0
package/lib/index.esm.js
CHANGED
|
@@ -24,7 +24,6 @@ import { setup, assign, assertEvent, emit, enqueueActions, createActor } from "x
|
|
|
24
24
|
import get from "lodash/get.js";
|
|
25
25
|
import isUndefined from "lodash/isUndefined.js";
|
|
26
26
|
import omitBy from "lodash/omitBy.js";
|
|
27
|
-
import { isHotkey } from "is-hotkey-esm";
|
|
28
27
|
import { htmlToBlocks, normalizeBlock } from "@sanity/block-tools";
|
|
29
28
|
function defineBehavior(behavior) {
|
|
30
29
|
return behavior;
|
|
@@ -769,9 +768,9 @@ function createMarkdownBehaviors(config) {
|
|
|
769
768
|
listItemLength: 1,
|
|
770
769
|
style: defaultStyle
|
|
771
770
|
};
|
|
772
|
-
const looksLikeOrderedList = /^1
|
|
771
|
+
const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle = config.orderedListStyle?.({
|
|
773
772
|
schema: context.schema
|
|
774
|
-
}), caretAtTheEndOfOrderedList =
|
|
773
|
+
}), caretAtTheEndOfOrderedList = blockOffset.offset === 2;
|
|
775
774
|
return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
|
|
776
775
|
focusTextBlock,
|
|
777
776
|
listItem: orderedListStyle,
|
|
@@ -6624,6 +6623,118 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6624
6623
|
return useMemo(() => /* @__PURE__ */ jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
|
|
6625
6624
|
};
|
|
6626
6625
|
Leaf.displayName = "Leaf";
|
|
6626
|
+
const IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
|
|
6627
|
+
alt: "altKey",
|
|
6628
|
+
control: "ctrlKey",
|
|
6629
|
+
meta: "metaKey",
|
|
6630
|
+
shift: "shiftKey"
|
|
6631
|
+
}, aliases = {
|
|
6632
|
+
add: "+",
|
|
6633
|
+
break: "pause",
|
|
6634
|
+
cmd: "meta",
|
|
6635
|
+
command: "meta",
|
|
6636
|
+
ctl: "control",
|
|
6637
|
+
ctrl: "control",
|
|
6638
|
+
del: "delete",
|
|
6639
|
+
down: "arrowdown",
|
|
6640
|
+
esc: "escape",
|
|
6641
|
+
ins: "insert",
|
|
6642
|
+
left: "arrowleft",
|
|
6643
|
+
mod: IS_MAC ? "meta" : "control",
|
|
6644
|
+
opt: "alt",
|
|
6645
|
+
option: "alt",
|
|
6646
|
+
return: "enter",
|
|
6647
|
+
right: "arrowright",
|
|
6648
|
+
space: " ",
|
|
6649
|
+
spacebar: " ",
|
|
6650
|
+
up: "arrowup",
|
|
6651
|
+
win: "meta",
|
|
6652
|
+
windows: "meta"
|
|
6653
|
+
}, keyCodes = {
|
|
6654
|
+
backspace: 8,
|
|
6655
|
+
tab: 9,
|
|
6656
|
+
enter: 13,
|
|
6657
|
+
shift: 16,
|
|
6658
|
+
control: 17,
|
|
6659
|
+
alt: 18,
|
|
6660
|
+
pause: 19,
|
|
6661
|
+
capslock: 20,
|
|
6662
|
+
escape: 27,
|
|
6663
|
+
" ": 32,
|
|
6664
|
+
pageup: 33,
|
|
6665
|
+
pagedown: 34,
|
|
6666
|
+
end: 35,
|
|
6667
|
+
home: 36,
|
|
6668
|
+
arrowleft: 37,
|
|
6669
|
+
arrowup: 38,
|
|
6670
|
+
arrowright: 39,
|
|
6671
|
+
arrowdown: 40,
|
|
6672
|
+
insert: 45,
|
|
6673
|
+
delete: 46,
|
|
6674
|
+
meta: 91,
|
|
6675
|
+
numlock: 144,
|
|
6676
|
+
scrolllock: 145,
|
|
6677
|
+
";": 186,
|
|
6678
|
+
"=": 187,
|
|
6679
|
+
",": 188,
|
|
6680
|
+
"-": 189,
|
|
6681
|
+
".": 190,
|
|
6682
|
+
"/": 191,
|
|
6683
|
+
"`": 192,
|
|
6684
|
+
"[": 219,
|
|
6685
|
+
"\\": 220,
|
|
6686
|
+
"]": 221,
|
|
6687
|
+
"'": 222,
|
|
6688
|
+
f1: 112,
|
|
6689
|
+
f2: 113,
|
|
6690
|
+
f3: 114,
|
|
6691
|
+
f4: 115,
|
|
6692
|
+
f5: 116,
|
|
6693
|
+
f6: 117,
|
|
6694
|
+
f7: 118,
|
|
6695
|
+
f8: 119,
|
|
6696
|
+
f9: 120,
|
|
6697
|
+
f10: 121,
|
|
6698
|
+
f11: 122,
|
|
6699
|
+
f12: 123,
|
|
6700
|
+
f13: 124,
|
|
6701
|
+
f14: 125,
|
|
6702
|
+
f15: 126,
|
|
6703
|
+
f16: 127,
|
|
6704
|
+
f17: 128,
|
|
6705
|
+
f18: 129,
|
|
6706
|
+
f19: 130,
|
|
6707
|
+
f20: 131
|
|
6708
|
+
};
|
|
6709
|
+
function isHotkey(hotkey, event) {
|
|
6710
|
+
return compareHotkey(parseHotkey(hotkey), event);
|
|
6711
|
+
}
|
|
6712
|
+
function parseHotkey(hotkey) {
|
|
6713
|
+
const parsedHotkey = {
|
|
6714
|
+
altKey: !1,
|
|
6715
|
+
ctrlKey: !1,
|
|
6716
|
+
metaKey: !1,
|
|
6717
|
+
shiftKey: !1
|
|
6718
|
+
}, hotkeySegments = hotkey.replace("++", "+add").split("+");
|
|
6719
|
+
for (const rawHotkeySegment of hotkeySegments) {
|
|
6720
|
+
const optional = rawHotkeySegment.endsWith("?") && rawHotkeySegment.length > 1, hotkeySegment = optional ? rawHotkeySegment.slice(0, -1) : rawHotkeySegment, keyName = toKeyName(hotkeySegment), modifier = modifiers[keyName], alias = aliases[hotkeySegment], code = keyCodes[keyName];
|
|
6721
|
+
if (hotkeySegment.length > 1 && modifier === void 0 && alias === void 0 && code === void 0)
|
|
6722
|
+
throw new TypeError(`Unknown modifier: "${hotkeySegment}"`);
|
|
6723
|
+
(hotkeySegments.length === 1 || modifier === void 0) && (parsedHotkey.key = keyName, parsedHotkey.keyCode = toKeyCode(hotkeySegment)), modifier !== void 0 && (parsedHotkey[modifier] = optional ? null : !0);
|
|
6724
|
+
}
|
|
6725
|
+
return parsedHotkey;
|
|
6726
|
+
}
|
|
6727
|
+
function compareHotkey(parsedHotkey, event) {
|
|
6728
|
+
return (parsedHotkey.altKey == null || parsedHotkey.altKey === event.altKey) && (parsedHotkey.ctrlKey == null || parsedHotkey.ctrlKey === event.ctrlKey) && (parsedHotkey.metaKey == null || parsedHotkey.metaKey === event.metaKey) && (parsedHotkey.shiftKey == null || parsedHotkey.shiftKey === event.shiftKey) ? parsedHotkey.keyCode !== void 0 && event.keyCode !== void 0 ? parsedHotkey.keyCode === 91 && event.keyCode === 93 ? !0 : parsedHotkey.keyCode === event.keyCode : parsedHotkey.keyCode === event.keyCode || parsedHotkey.key === event.key.toLowerCase() : !1;
|
|
6729
|
+
}
|
|
6730
|
+
function toKeyCode(name) {
|
|
6731
|
+
const keyName = toKeyName(name);
|
|
6732
|
+
return keyCodes[keyName] ?? keyName.toUpperCase().charCodeAt(0);
|
|
6733
|
+
}
|
|
6734
|
+
function toKeyName(name) {
|
|
6735
|
+
const keyName = name.toLowerCase();
|
|
6736
|
+
return aliases[keyName] ?? keyName;
|
|
6737
|
+
}
|
|
6627
6738
|
const debug$2 = debugWithName("plugin:withHotKeys"), DEFAULT_HOTKEYS = {
|
|
6628
6739
|
marks: {
|
|
6629
6740
|
"mod+b": "strong",
|