slate-react 0.134.1 → 0.136.0

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.
@@ -1068,6 +1068,41 @@
1068
1068
  lib.toKeyCode;
1069
1069
  lib.toKeyName;
1070
1070
 
1071
+ function _typeof(o) {
1072
+ "@babel/helpers - typeof";
1073
+
1074
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
1075
+ return typeof o;
1076
+ } : function (o) {
1077
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
1078
+ }, _typeof(o);
1079
+ }
1080
+
1081
+ function toPrimitive(t, r) {
1082
+ if ("object" != _typeof(t) || !t) return t;
1083
+ var e = t[Symbol.toPrimitive];
1084
+ if (void 0 !== e) {
1085
+ var i = e.call(t, r);
1086
+ if ("object" != _typeof(i)) return i;
1087
+ throw new TypeError("@@toPrimitive must return a primitive value.");
1088
+ }
1089
+ return ("string" === r ? String : Number)(t);
1090
+ }
1091
+
1092
+ function toPropertyKey(t) {
1093
+ var i = toPrimitive(t, "string");
1094
+ return "symbol" == _typeof(i) ? i : i + "";
1095
+ }
1096
+
1097
+ function _defineProperty(e, r, t) {
1098
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
1099
+ value: t,
1100
+ enumerable: true,
1101
+ configurable: true,
1102
+ writable: true
1103
+ }) : e[r] = t, e;
1104
+ }
1105
+
1071
1106
  /**
1072
1107
  * Types.
1073
1108
  */
@@ -1398,41 +1433,6 @@
1398
1433
  // @ts-ignore The `getTargetRanges` property isn't recognized.
1399
1434
  typeof globalThis.InputEvent.prototype.getTargetRanges === 'function';
1400
1435
 
1401
- function _typeof(o) {
1402
- "@babel/helpers - typeof";
1403
-
1404
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
1405
- return typeof o;
1406
- } : function (o) {
1407
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
1408
- }, _typeof(o);
1409
- }
1410
-
1411
- function toPrimitive(t, r) {
1412
- if ("object" != _typeof(t) || !t) return t;
1413
- var e = t[Symbol.toPrimitive];
1414
- if (void 0 !== e) {
1415
- var i = e.call(t, r);
1416
- if ("object" != _typeof(i)) return i;
1417
- throw new TypeError("@@toPrimitive must return a primitive value.");
1418
- }
1419
- return ("string" === r ? String : Number)(t);
1420
- }
1421
-
1422
- function toPropertyKey(t) {
1423
- var i = toPrimitive(t, "string");
1424
- return "symbol" == _typeof(i) ? i : i + "";
1425
- }
1426
-
1427
- function _defineProperty(e, r, t) {
1428
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
1429
- value: t,
1430
- enumerable: true,
1431
- configurable: true,
1432
- writable: true
1433
- }) : e[r] = t, e;
1434
- }
1435
-
1436
1436
  /**
1437
1437
  * An auto-incrementing identifier for keys.
1438
1438
  */
@@ -1496,6 +1496,8 @@
1496
1496
  const PLACEHOLDER_SYMBOL = Symbol('placeholder');
1497
1497
  const MARK_PLACEHOLDER_SYMBOL = Symbol('mark-placeholder');
1498
1498
 
1499
+ function ownKeys$3$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1500
+ function _objectSpread$3$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1499
1501
  // eslint-disable-next-line no-redeclare
1500
1502
  const DOMEditor = {
1501
1503
  androidPendingDiffs: editor => EDITOR_TO_PENDING_DIFFS.get(editor),
@@ -1746,6 +1748,21 @@
1746
1748
  isComposing: editor => {
1747
1749
  return !!IS_COMPOSING.get(editor);
1748
1750
  },
1751
+ getWord: (editor, options = {}) => {
1752
+ var _composing$view, _options$at;
1753
+ if (typeof slate.Editor.word !== 'function') {
1754
+ throw new Error('DOMEditor.getWord needs slate 0.136.0 or later');
1755
+ }
1756
+ const composing = DOMEditor.isComposing(editor) ? getComposingView(editor) : undefined;
1757
+ const view = (_composing$view = composing === null || composing === void 0 ? void 0 : composing.view) !== null && _composing$view !== void 0 ? _composing$view : editor;
1758
+ const range = slate.Editor.word(view, _objectSpread$3$1(_objectSpread$3$1({}, options), {}, {
1759
+ at: (_options$at = options.at) !== null && _options$at !== void 0 ? _options$at : composing === null || composing === void 0 ? void 0 : composing.point
1760
+ }));
1761
+ return range && {
1762
+ range,
1763
+ text: slate.Editor.string(view, range)
1764
+ };
1765
+ },
1749
1766
  isFocused: editor => !!IS_FOCUSED.get(editor),
1750
1767
  isMounted: editor => !!EDITOR_TO_ELEMENT.get(editor),
1751
1768
  isReadOnly: editor => !!IS_READ_ONLY.get(editor),
@@ -2180,6 +2197,43 @@
2180
2197
  return range;
2181
2198
  }
2182
2199
  };
2200
+ const replaceText = (nodes, path, text) => nodes.map((node, index) => {
2201
+ if (index !== path[0]) {
2202
+ return node;
2203
+ }
2204
+ if (path.length === 1) {
2205
+ return _objectSpread$3$1(_objectSpread$3$1({}, node), {}, {
2206
+ text
2207
+ });
2208
+ }
2209
+ return _objectSpread$3$1(_objectSpread$3$1({}, node), {}, {
2210
+ children: replaceText(node.children, path.slice(1), text)
2211
+ });
2212
+ });
2213
+ const getComposingView = editor => {
2214
+ var _textElement$textCont;
2215
+ const domSelection = DOMEditor.getWindow(editor).getSelection();
2216
+ if (!(domSelection !== null && domSelection !== void 0 && domSelection.focusNode)) {
2217
+ return undefined;
2218
+ }
2219
+ const point = DOMEditor.toSlatePoint(editor, [domSelection.focusNode, domSelection.focusOffset], {
2220
+ exactMatch: false,
2221
+ suppressThrow: true
2222
+ });
2223
+ if (!point) {
2224
+ return undefined;
2225
+ }
2226
+ const textElement = DOMEditor.toDOMNode(editor, slate.Node.get(editor, point.path));
2227
+ const text = ((_textElement$textCont = textElement.textContent) !== null && _textElement$textCont !== void 0 ? _textElement$textCont : '').replace(/\uFEFF/g, '');
2228
+ const view = slate.createEditor();
2229
+ view.isInline = editor.isInline;
2230
+ view.isVoid = editor.isVoid;
2231
+ view.children = replaceText(editor.children, point.path, text);
2232
+ return {
2233
+ view,
2234
+ point
2235
+ };
2236
+ };
2183
2237
 
2184
2238
  /**
2185
2239
  * Check whether a text diff was applied in a way we can perform the pending action on /