@portabletext/editor 1.12.2 → 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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var types = require("@sanity/types"), schema = require("@sanity/schema"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$m = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), styledComponents = require("styled-components"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"), throttle = require("lodash/throttle.js"), debounce = require("lodash/debounce.js"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), getRandomValues = require("get-random-values-esm"), xstate = require("xstate"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), isHotkeyEsm = require("is-hotkey-esm"), blockTools = require("@sanity/block-tools");
3
+ var types = require("@sanity/types"), schema = require("@sanity/schema"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$m = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), styledComponents = require("styled-components"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"), throttle = require("lodash/throttle.js"), debounce = require("lodash/debounce.js"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), getRandomValues = require("get-random-values-esm"), xstate = require("xstate"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), blockTools = require("@sanity/block-tools");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
@@ -6603,6 +6603,118 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
6603
6603
  return React.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
6604
6604
  };
6605
6605
  Leaf.displayName = "Leaf";
6606
+ const IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
6607
+ alt: "altKey",
6608
+ control: "ctrlKey",
6609
+ meta: "metaKey",
6610
+ shift: "shiftKey"
6611
+ }, aliases = {
6612
+ add: "+",
6613
+ break: "pause",
6614
+ cmd: "meta",
6615
+ command: "meta",
6616
+ ctl: "control",
6617
+ ctrl: "control",
6618
+ del: "delete",
6619
+ down: "arrowdown",
6620
+ esc: "escape",
6621
+ ins: "insert",
6622
+ left: "arrowleft",
6623
+ mod: IS_MAC ? "meta" : "control",
6624
+ opt: "alt",
6625
+ option: "alt",
6626
+ return: "enter",
6627
+ right: "arrowright",
6628
+ space: " ",
6629
+ spacebar: " ",
6630
+ up: "arrowup",
6631
+ win: "meta",
6632
+ windows: "meta"
6633
+ }, keyCodes = {
6634
+ backspace: 8,
6635
+ tab: 9,
6636
+ enter: 13,
6637
+ shift: 16,
6638
+ control: 17,
6639
+ alt: 18,
6640
+ pause: 19,
6641
+ capslock: 20,
6642
+ escape: 27,
6643
+ " ": 32,
6644
+ pageup: 33,
6645
+ pagedown: 34,
6646
+ end: 35,
6647
+ home: 36,
6648
+ arrowleft: 37,
6649
+ arrowup: 38,
6650
+ arrowright: 39,
6651
+ arrowdown: 40,
6652
+ insert: 45,
6653
+ delete: 46,
6654
+ meta: 91,
6655
+ numlock: 144,
6656
+ scrolllock: 145,
6657
+ ";": 186,
6658
+ "=": 187,
6659
+ ",": 188,
6660
+ "-": 189,
6661
+ ".": 190,
6662
+ "/": 191,
6663
+ "`": 192,
6664
+ "[": 219,
6665
+ "\\": 220,
6666
+ "]": 221,
6667
+ "'": 222,
6668
+ f1: 112,
6669
+ f2: 113,
6670
+ f3: 114,
6671
+ f4: 115,
6672
+ f5: 116,
6673
+ f6: 117,
6674
+ f7: 118,
6675
+ f8: 119,
6676
+ f9: 120,
6677
+ f10: 121,
6678
+ f11: 122,
6679
+ f12: 123,
6680
+ f13: 124,
6681
+ f14: 125,
6682
+ f15: 126,
6683
+ f16: 127,
6684
+ f17: 128,
6685
+ f18: 129,
6686
+ f19: 130,
6687
+ f20: 131
6688
+ };
6689
+ function isHotkey(hotkey, event) {
6690
+ return compareHotkey(parseHotkey(hotkey), event);
6691
+ }
6692
+ function parseHotkey(hotkey) {
6693
+ const parsedHotkey = {
6694
+ altKey: !1,
6695
+ ctrlKey: !1,
6696
+ metaKey: !1,
6697
+ shiftKey: !1
6698
+ }, hotkeySegments = hotkey.replace("++", "+add").split("+");
6699
+ for (const rawHotkeySegment of hotkeySegments) {
6700
+ 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];
6701
+ if (hotkeySegment.length > 1 && modifier === void 0 && alias === void 0 && code === void 0)
6702
+ throw new TypeError(`Unknown modifier: "${hotkeySegment}"`);
6703
+ (hotkeySegments.length === 1 || modifier === void 0) && (parsedHotkey.key = keyName, parsedHotkey.keyCode = toKeyCode(hotkeySegment)), modifier !== void 0 && (parsedHotkey[modifier] = optional ? null : !0);
6704
+ }
6705
+ return parsedHotkey;
6706
+ }
6707
+ function compareHotkey(parsedHotkey, event) {
6708
+ 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;
6709
+ }
6710
+ function toKeyCode(name) {
6711
+ const keyName = toKeyName(name);
6712
+ return keyCodes[keyName] ?? keyName.toUpperCase().charCodeAt(0);
6713
+ }
6714
+ function toKeyName(name) {
6715
+ const keyName = name.toLowerCase();
6716
+ return aliases[keyName] ?? keyName;
6717
+ }
6606
6718
  const debug$2 = debugWithName("plugin:withHotKeys"), DEFAULT_HOTKEYS = {
6607
6719
  marks: {
6608
6720
  "mod+b": "strong",
@@ -6621,7 +6733,7 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
6621
6733
  for (const hotkey in activeHotkeys[cat]) {
6622
6734
  if (reservedHotkeys.includes(hotkey))
6623
6735
  throw new Error(`The hotkey ${hotkey} is reserved!`);
6624
- if (isHotkeyEsm.isHotkey(hotkey, event.nativeEvent)) {
6736
+ if (isHotkey(hotkey, event.nativeEvent)) {
6625
6737
  event.preventDefault();
6626
6738
  const possibleMark = activeHotkeys[cat];
6627
6739
  if (possibleMark) {
@@ -6641,7 +6753,7 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
6641
6753
  for (const hotkey in activeHotkeys[cat]) {
6642
6754
  if (reservedHotkeys.includes(hotkey))
6643
6755
  throw new Error(`The hotkey ${hotkey} is reserved!`);
6644
- if (isHotkeyEsm.isHotkey(hotkey, event.nativeEvent)) {
6756
+ if (isHotkey(hotkey, event.nativeEvent)) {
6645
6757
  const possibleCommand = activeHotkeys[cat];
6646
6758
  if (possibleCommand) {
6647
6759
  const command = possibleCommand[hotkey];
@@ -6650,7 +6762,7 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
6650
6762
  }
6651
6763
  }
6652
6764
  });
6653
- const isEnter = isHotkeyEsm.isHotkey("enter", event.nativeEvent), isTab = isHotkeyEsm.isHotkey("tab", event.nativeEvent), isShiftEnter = isHotkeyEsm.isHotkey("shift+enter", event.nativeEvent), isShiftTab = isHotkeyEsm.isHotkey("shift+tab", event.nativeEvent), isArrowDown = isHotkeyEsm.isHotkey("down", event.nativeEvent), isArrowUp = isHotkeyEsm.isHotkey("up", event.nativeEvent);
6765
+ const isEnter = isHotkey("enter", event.nativeEvent), isTab = isHotkey("tab", event.nativeEvent), isShiftEnter = isHotkey("shift+enter", event.nativeEvent), isShiftTab = isHotkey("shift+tab", event.nativeEvent), isArrowDown = isHotkey("down", event.nativeEvent), isArrowUp = isHotkey("up", event.nativeEvent);
6654
6766
  if (isArrowDown && editor.selection) {
6655
6767
  const focusBlock = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1));
6656
6768
  if (focusBlock && slate.Editor.isVoid(editor, focusBlock)) {