slate 0.91.4 → 0.93.0-20233318843

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.
@@ -1 +1 @@
1
- {"version":3,"file":"create-editor.d.ts","sourceRoot":"","sources":["packages/slate/src/create-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EAWP,MAAM,IAAI,CAAA;AAIX;;GAEG;AAEH,eAAO,MAAM,YAAY,QAAO,MAyZ/B,CAAA"}
1
+ {"version":3,"file":"create-editor.d.ts","sourceRoot":"","sources":["packages/slate/src/create-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EAWP,MAAM,IAAI,CAAA;AAIX;;GAEG;AAEH,eAAO,MAAM,YAAY,QAAO,MA2Z/B,CAAA"}
package/dist/index.es.js CHANGED
@@ -37,7 +37,9 @@ var createEditor = () => {
37
37
  operations: [],
38
38
  selection: null,
39
39
  marks: null,
40
+ isElementReadOnly: () => false,
40
41
  isInline: () => false,
42
+ isSelectable: () => true,
41
43
  isVoid: () => false,
42
44
  markableVoid: () => false,
43
45
  onChange: () => {},
@@ -1065,6 +1067,16 @@ var Editor = {
1065
1067
  return [Editor.start(editor, at), Editor.end(editor, at)];
1066
1068
  },
1067
1069
 
1070
+ /**
1071
+ * Match a read-only element in the current branch of the editor.
1072
+ */
1073
+ elementReadOnly(editor) {
1074
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1075
+ return Editor.above(editor, _objectSpread$8(_objectSpread$8({}, options), {}, {
1076
+ match: n => Element.isElement(n) && Editor.isElementReadOnly(editor, n)
1077
+ }));
1078
+ },
1079
+
1068
1080
  /**
1069
1081
  * Get the end point of a location.
1070
1082
  */
@@ -1180,7 +1192,7 @@ var Editor = {
1180
1192
  return false;
1181
1193
  }
1182
1194
 
1183
- var isEditor = typeof value.addMark === 'function' && typeof value.apply === 'function' && typeof value.deleteBackward === 'function' && typeof value.deleteForward === 'function' && typeof value.deleteFragment === 'function' && typeof value.insertBreak === 'function' && typeof value.insertSoftBreak === 'function' && typeof value.insertFragment === 'function' && typeof value.insertNode === 'function' && typeof value.insertText === 'function' && typeof value.isInline === 'function' && typeof value.isVoid === 'function' && typeof value.normalizeNode === 'function' && typeof value.onChange === 'function' && typeof value.removeMark === 'function' && typeof value.getDirtyPaths === 'function' && (value.marks === null || isPlainObject(value.marks)) && (value.selection === null || Range.isRange(value.selection)) && Node.isNodeList(value.children) && Operation.isOperationList(value.operations);
1195
+ var isEditor = typeof value.addMark === 'function' && typeof value.apply === 'function' && typeof value.deleteBackward === 'function' && typeof value.deleteForward === 'function' && typeof value.deleteFragment === 'function' && typeof value.insertBreak === 'function' && typeof value.insertSoftBreak === 'function' && typeof value.insertFragment === 'function' && typeof value.insertNode === 'function' && typeof value.insertText === 'function' && typeof value.isElementReadOnly === 'function' && typeof value.isInline === 'function' && typeof value.isSelectable === 'function' && typeof value.isVoid === 'function' && typeof value.normalizeNode === 'function' && typeof value.onChange === 'function' && typeof value.removeMark === 'function' && typeof value.getDirtyPaths === 'function' && (value.marks === null || isPlainObject(value.marks)) && (value.selection === null || Range.isRange(value.selection)) && Node.isNodeList(value.children) && Operation.isOperationList(value.operations);
1184
1196
  IS_EDITOR_CACHE.set(value, isEditor);
1185
1197
  return isEditor;
1186
1198
  },
@@ -1218,6 +1230,13 @@ var Editor = {
1218
1230
  return editor.isInline(value);
1219
1231
  },
1220
1232
 
1233
+ /**
1234
+ * Check if a value is a read-only `Element` object.
1235
+ */
1236
+ isElementReadOnly(editor, value) {
1237
+ return editor.isElementReadOnly(value);
1238
+ },
1239
+
1221
1240
  /**
1222
1241
  * Check if the editor is currently normalizing after each operation.
1223
1242
  */
@@ -1226,6 +1245,13 @@ var Editor = {
1226
1245
  return isNormalizing === undefined ? true : isNormalizing;
1227
1246
  },
1228
1247
 
1248
+ /**
1249
+ * Check if a value is a selectable `Element` object.
1250
+ */
1251
+ isSelectable(editor, value) {
1252
+ return editor.isSelectable(value);
1253
+ },
1254
+
1229
1255
  /**
1230
1256
  * Check if a point is the start point of a location.
1231
1257
  */
@@ -1449,7 +1475,8 @@ var Editor = {
1449
1475
  mode = 'all',
1450
1476
  universal = false,
1451
1477
  reverse = false,
1452
- voids = false
1478
+ voids = false,
1479
+ ignoreNonSelectable = false
1453
1480
  } = options;
1454
1481
  var {
1455
1482
  match
@@ -1485,14 +1512,21 @@ var Editor = {
1485
1512
  from,
1486
1513
  to,
1487
1514
  pass: _ref => {
1488
- var [n] = _ref;
1489
- return voids ? false : Element.isElement(n) && Editor.isVoid(editor, n);
1515
+ var [node] = _ref;
1516
+ if (!Element.isElement(node)) return false;
1517
+ if (!voids && (Editor.isVoid(editor, node) || Editor.isElementReadOnly(editor, node))) return true;
1518
+ if (ignoreNonSelectable && !Editor.isSelectable(editor, node)) return true;
1519
+ return false;
1490
1520
  }
1491
1521
  });
1492
1522
  var matches = [];
1493
1523
  var hit;
1494
1524
 
1495
1525
  for (var [node, path] of nodeEntries) {
1526
+ if (ignoreNonSelectable && Element.isElement(node) && !Editor.isSelectable(editor, node)) {
1527
+ continue;
1528
+ }
1529
+
1496
1530
  var isLower = hit && Path.compare(path, hit[1]) === 0; // In highest mode any node lower than the last hit is not a match.
1497
1531
 
1498
1532
  if (mode === 'highest' && isLower) {
@@ -1845,7 +1879,8 @@ var Editor = {
1845
1879
  at = editor.selection,
1846
1880
  unit = 'offset',
1847
1881
  reverse = false,
1848
- voids = false
1882
+ voids = false,
1883
+ ignoreNonSelectable = false
1849
1884
  } = options;
1850
1885
 
1851
1886
  if (!at) {
@@ -1888,7 +1923,8 @@ var Editor = {
1888
1923
  for (var [node, path] of Editor.nodes(editor, {
1889
1924
  at,
1890
1925
  reverse,
1891
- voids
1926
+ voids,
1927
+ ignoreNonSelectable
1892
1928
  })) {
1893
1929
  /*
1894
1930
  * ELEMENT NODE - Yield position(s) for voids, collect blockText for blocks
@@ -1897,7 +1933,7 @@ var Editor = {
1897
1933
  // Void nodes are a special case, so by default we will always
1898
1934
  // yield their first point. If the `voids` option is set to true,
1899
1935
  // then we will iterate over their content.
1900
- if (!voids && editor.isVoid(node)) {
1936
+ if (!voids && (editor.isVoid(node) || editor.isElementReadOnly(node))) {
1901
1937
  yield Editor.start(editor, path);
1902
1938
  continue;
1903
1939
  } // Inline element nodes are ignored as they don't themselves
@@ -5459,7 +5495,8 @@ var SelectionTransforms = {
5459
5495
  } = selection;
5460
5496
  var opts = {
5461
5497
  distance,
5462
- unit
5498
+ unit,
5499
+ ignoreNonSelectable: true
5463
5500
  };
5464
5501
  var props = {};
5465
5502
 
@@ -5580,6 +5617,8 @@ var TextTransforms = {
5580
5617
  delete(editor) {
5581
5618
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5582
5619
  Editor.withoutNormalizing(editor, () => {
5620
+ var _Editor$void, _Editor$void2;
5621
+
5583
5622
  var {
5584
5623
  reverse = false,
5585
5624
  unit = 'character',
@@ -5661,16 +5700,22 @@ var TextTransforms = {
5661
5700
  });
5662
5701
  var isAcrossBlocks = startBlock && endBlock && !Path.equals(startBlock[1], endBlock[1]);
5663
5702
  var isSingleText = Path.equals(start.path, end.path);
5664
- var startVoid = voids ? null : Editor.void(editor, {
5703
+ var startNonEditable = voids ? null : (_Editor$void = Editor.void(editor, {
5704
+ at: start,
5705
+ mode: 'highest'
5706
+ })) !== null && _Editor$void !== void 0 ? _Editor$void : Editor.elementReadOnly(editor, {
5665
5707
  at: start,
5666
5708
  mode: 'highest'
5667
5709
  });
5668
- var endVoid = voids ? null : Editor.void(editor, {
5710
+ var endNonEditable = voids ? null : (_Editor$void2 = Editor.void(editor, {
5711
+ at: end,
5712
+ mode: 'highest'
5713
+ })) !== null && _Editor$void2 !== void 0 ? _Editor$void2 : Editor.elementReadOnly(editor, {
5669
5714
  at: end,
5670
5715
  mode: 'highest'
5671
5716
  }); // If the start or end points are inside an inline void, nudge them out.
5672
5717
 
5673
- if (startVoid) {
5718
+ if (startNonEditable) {
5674
5719
  var before = Editor.before(editor, start);
5675
5720
 
5676
5721
  if (before && startBlock && Path.isAncestor(startBlock[1], before.path)) {
@@ -5678,7 +5723,7 @@ var TextTransforms = {
5678
5723
  }
5679
5724
  }
5680
5725
 
5681
- if (endVoid) {
5726
+ if (endNonEditable) {
5682
5727
  var after = Editor.after(editor, end);
5683
5728
 
5684
5729
  if (after && endBlock && Path.isAncestor(endBlock[1], after.path)) {
@@ -5701,7 +5746,7 @@ var TextTransforms = {
5701
5746
  continue;
5702
5747
  }
5703
5748
 
5704
- if (!voids && Element.isElement(node) && Editor.isVoid(editor, node) || !Path.isCommon(path, start.path) && !Path.isCommon(path, end.path)) {
5749
+ if (!voids && Element.isElement(node) && (Editor.isVoid(editor, node) || Editor.isElementReadOnly(editor, node)) || !Path.isCommon(path, start.path) && !Path.isCommon(path, end.path)) {
5705
5750
  matches.push(entry);
5706
5751
  lastPath = path;
5707
5752
  }
@@ -5715,7 +5760,7 @@ var TextTransforms = {
5715
5760
  var endRef = Editor.pointRef(editor, end);
5716
5761
  var removedText = '';
5717
5762
 
5718
- if (!isSingleText && !startVoid) {
5763
+ if (!isSingleText && !startNonEditable) {
5719
5764
  var _point = startRef.current;
5720
5765
  var [_node] = Editor.leaf(editor, _point);
5721
5766
  var {
@@ -5743,7 +5788,7 @@ var TextTransforms = {
5743
5788
  voids
5744
5789
  }));
5745
5790
 
5746
- if (!endVoid) {
5791
+ if (!endNonEditable) {
5747
5792
  var _point2 = endRef.current;
5748
5793
  var [_node2] = Editor.leaf(editor, _point2);
5749
5794
  var {
@@ -6057,6 +6102,8 @@ var TextTransforms = {
6057
6102
 
6058
6103
  if (!voids && Editor.void(editor, {
6059
6104
  at
6105
+ }) || Editor.elementReadOnly(editor, {
6106
+ at
6060
6107
  })) {
6061
6108
  return;
6062
6109
  }