slate-react 0.83.2 → 0.86.0-20221017162431
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/components/editable.d.ts +1 -13
- package/dist/components/editable.d.ts.map +1 -1
- package/dist/index.es.js +53 -46
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +53 -46
- package/dist/index.js.map +1 -1
- package/dist/plugin/react-editor.d.ts +20 -0
- package/dist/plugin/react-editor.d.ts.map +1 -1
- package/dist/slate-react.js +53 -46
- package/dist/slate-react.min.js +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1249,6 +1249,38 @@ var ReactEditor = {
|
|
|
1249
1249
|
return slate.Editor.hasPath(editor, anchor.path) && slate.Editor.hasPath(editor, focus.path);
|
|
1250
1250
|
},
|
|
1251
1251
|
|
|
1252
|
+
/**
|
|
1253
|
+
* Check if the target is in the editor.
|
|
1254
|
+
*/
|
|
1255
|
+
hasTarget: function hasTarget(editor, target) {
|
|
1256
|
+
return isDOMNode(target) && ReactEditor.hasDOMNode(editor, target);
|
|
1257
|
+
},
|
|
1258
|
+
|
|
1259
|
+
/**
|
|
1260
|
+
* Check if the target is editable and in the editor.
|
|
1261
|
+
*/
|
|
1262
|
+
hasEditableTarget: function hasEditableTarget(editor, target) {
|
|
1263
|
+
return isDOMNode(target) && ReactEditor.hasDOMNode(editor, target, {
|
|
1264
|
+
editable: true
|
|
1265
|
+
});
|
|
1266
|
+
},
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* Check if the target can be selectable
|
|
1270
|
+
*/
|
|
1271
|
+
hasSelectableTarget: function hasSelectableTarget(editor, target) {
|
|
1272
|
+
return ReactEditor.hasEditableTarget(editor, target) || ReactEditor.isTargetInsideNonReadonlyVoid(editor, target);
|
|
1273
|
+
},
|
|
1274
|
+
|
|
1275
|
+
/**
|
|
1276
|
+
* Check if the target is inside void and in an non-readonly editor.
|
|
1277
|
+
*/
|
|
1278
|
+
isTargetInsideNonReadonlyVoid: function isTargetInsideNonReadonlyVoid(editor, target) {
|
|
1279
|
+
if (IS_READ_ONLY.get(editor)) return false;
|
|
1280
|
+
var slateNode = ReactEditor.hasTarget(editor, target) && ReactEditor.toSlateNode(editor, target);
|
|
1281
|
+
return slate.Editor.isVoid(editor, slateNode);
|
|
1282
|
+
},
|
|
1283
|
+
|
|
1252
1284
|
/**
|
|
1253
1285
|
* Experimental and android specific: Flush all pending diffs and cancel composition at the next possible time.
|
|
1254
1286
|
*/
|
|
@@ -3585,8 +3617,8 @@ var Editable = function Editable(props) {
|
|
|
3585
3617
|
|
|
3586
3618
|
var anchorNode = domSelection.anchorNode,
|
|
3587
3619
|
focusNode = domSelection.focusNode;
|
|
3588
|
-
var anchorNodeSelectable = hasEditableTarget(editor, anchorNode) || isTargetInsideNonReadonlyVoid(editor, anchorNode);
|
|
3589
|
-
var focusNodeSelectable = hasEditableTarget(editor, focusNode) || isTargetInsideNonReadonlyVoid(editor, focusNode);
|
|
3620
|
+
var anchorNodeSelectable = ReactEditor.hasEditableTarget(editor, anchorNode) || ReactEditor.isTargetInsideNonReadonlyVoid(editor, anchorNode);
|
|
3621
|
+
var focusNodeSelectable = ReactEditor.hasEditableTarget(editor, focusNode) || ReactEditor.isTargetInsideNonReadonlyVoid(editor, focusNode);
|
|
3590
3622
|
|
|
3591
3623
|
if (anchorNodeSelectable && focusNodeSelectable) {
|
|
3592
3624
|
var range = ReactEditor.toSlateRange(editor, domSelection, {
|
|
@@ -3768,7 +3800,7 @@ var Editable = function Editable(props) {
|
|
|
3768
3800
|
var onDOMBeforeInput = React.useCallback(function (event) {
|
|
3769
3801
|
onUserInput();
|
|
3770
3802
|
|
|
3771
|
-
if (!readOnly && hasEditableTarget(editor, event.target) && !isDOMEventHandled(event, propsOnDOMBeforeInput)) {
|
|
3803
|
+
if (!readOnly && ReactEditor.hasEditableTarget(editor, event.target) && !isDOMEventHandled(event, propsOnDOMBeforeInput)) {
|
|
3772
3804
|
var _EDITOR_TO_USER_SELEC;
|
|
3773
3805
|
|
|
3774
3806
|
// COMPAT: BeforeInput events aren't cancelable on android, so we have to handle them differently using the android input manager.
|
|
@@ -4165,7 +4197,7 @@ var Editable = function Editable(props) {
|
|
|
4165
4197
|
// COMPAT: Certain browsers don't support the `beforeinput` event, so we
|
|
4166
4198
|
// fall back to React's leaky polyfill instead just for it. It
|
|
4167
4199
|
// only works for the `insertText` input type.
|
|
4168
|
-
if (!HAS_BEFORE_INPUT_SUPPORT && !readOnly && !isEventHandled(event, attributes.onBeforeInput) &&
|
|
4200
|
+
if (!HAS_BEFORE_INPUT_SUPPORT && !readOnly && !isEventHandled(event, attributes.onBeforeInput) && ReactEditor.hasSelectableTarget(editor, event.target)) {
|
|
4169
4201
|
event.preventDefault();
|
|
4170
4202
|
|
|
4171
4203
|
if (!ReactEditor.isComposing(editor)) {
|
|
@@ -4201,7 +4233,7 @@ var Editable = function Editable(props) {
|
|
|
4201
4233
|
deferredOperations.current = [];
|
|
4202
4234
|
}, []),
|
|
4203
4235
|
onBlur: React.useCallback(function (event) {
|
|
4204
|
-
if (readOnly || state.isUpdatingSelection || !
|
|
4236
|
+
if (readOnly || state.isUpdatingSelection || !ReactEditor.hasSelectableTarget(editor, event.target) || isEventHandled(event, attributes.onBlur)) {
|
|
4205
4237
|
return;
|
|
4206
4238
|
} // COMPAT: If the current `activeElement` is still the previous
|
|
4207
4239
|
// one, this is due to the window being blurred when the tab
|
|
@@ -4252,7 +4284,7 @@ var Editable = function Editable(props) {
|
|
|
4252
4284
|
IS_FOCUSED["delete"](editor);
|
|
4253
4285
|
}, [readOnly, attributes.onBlur]),
|
|
4254
4286
|
onClick: React.useCallback(function (event) {
|
|
4255
|
-
if (hasTarget(editor, event.target) && !isEventHandled(event, attributes.onClick) && isDOMNode(event.target)) {
|
|
4287
|
+
if (ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onClick) && isDOMNode(event.target)) {
|
|
4256
4288
|
var node = ReactEditor.toSlateNode(editor, event.target);
|
|
4257
4289
|
var path = ReactEditor.findPath(editor, node); // At this time, the Slate document may be arbitrarily different,
|
|
4258
4290
|
// because onClick handlers can change the document before we get here.
|
|
@@ -4305,7 +4337,7 @@ var Editable = function Editable(props) {
|
|
|
4305
4337
|
}
|
|
4306
4338
|
}, [readOnly, attributes.onClick]),
|
|
4307
4339
|
onCompositionEnd: React.useCallback(function (event) {
|
|
4308
|
-
if (
|
|
4340
|
+
if (ReactEditor.hasSelectableTarget(editor, event.target)) {
|
|
4309
4341
|
if (ReactEditor.isComposing(editor)) {
|
|
4310
4342
|
setIsComposing(false);
|
|
4311
4343
|
IS_COMPOSING.set(editor, false);
|
|
@@ -4341,7 +4373,7 @@ var Editable = function Editable(props) {
|
|
|
4341
4373
|
}
|
|
4342
4374
|
}, [attributes.onCompositionEnd]),
|
|
4343
4375
|
onCompositionUpdate: React.useCallback(function (event) {
|
|
4344
|
-
if (
|
|
4376
|
+
if (ReactEditor.hasSelectableTarget(editor, event.target) && !isEventHandled(event, attributes.onCompositionUpdate)) {
|
|
4345
4377
|
if (!ReactEditor.isComposing(editor)) {
|
|
4346
4378
|
setIsComposing(true);
|
|
4347
4379
|
IS_COMPOSING.set(editor, true);
|
|
@@ -4349,7 +4381,7 @@ var Editable = function Editable(props) {
|
|
|
4349
4381
|
}
|
|
4350
4382
|
}, [attributes.onCompositionUpdate]),
|
|
4351
4383
|
onCompositionStart: React.useCallback(function (event) {
|
|
4352
|
-
if (
|
|
4384
|
+
if (ReactEditor.hasSelectableTarget(editor, event.target)) {
|
|
4353
4385
|
androidInputManager === null || androidInputManager === void 0 ? void 0 : androidInputManager.handleCompositionStart(event);
|
|
4354
4386
|
|
|
4355
4387
|
if (isEventHandled(event, attributes.onCompositionStart) || IS_ANDROID) {
|
|
@@ -4388,13 +4420,13 @@ var Editable = function Editable(props) {
|
|
|
4388
4420
|
}
|
|
4389
4421
|
}, [attributes.onCompositionStart]),
|
|
4390
4422
|
onCopy: React.useCallback(function (event) {
|
|
4391
|
-
if (
|
|
4423
|
+
if (ReactEditor.hasSelectableTarget(editor, event.target) && !isEventHandled(event, attributes.onCopy)) {
|
|
4392
4424
|
event.preventDefault();
|
|
4393
4425
|
ReactEditor.setFragmentData(editor, event.clipboardData, 'copy');
|
|
4394
4426
|
}
|
|
4395
4427
|
}, [attributes.onCopy]),
|
|
4396
4428
|
onCut: React.useCallback(function (event) {
|
|
4397
|
-
if (!readOnly &&
|
|
4429
|
+
if (!readOnly && ReactEditor.hasSelectableTarget(editor, event.target) && !isEventHandled(event, attributes.onCut)) {
|
|
4398
4430
|
event.preventDefault();
|
|
4399
4431
|
ReactEditor.setFragmentData(editor, event.clipboardData, 'cut');
|
|
4400
4432
|
var selection = editor.selection;
|
|
@@ -4413,7 +4445,7 @@ var Editable = function Editable(props) {
|
|
|
4413
4445
|
}
|
|
4414
4446
|
}, [readOnly, attributes.onCut]),
|
|
4415
4447
|
onDragOver: React.useCallback(function (event) {
|
|
4416
|
-
if (hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDragOver)) {
|
|
4448
|
+
if (ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDragOver)) {
|
|
4417
4449
|
// Only when the target is void, call `preventDefault` to signal
|
|
4418
4450
|
// that drops are allowed. Editable content is droppable by
|
|
4419
4451
|
// default, and calling `preventDefault` hides the cursor.
|
|
@@ -4425,7 +4457,7 @@ var Editable = function Editable(props) {
|
|
|
4425
4457
|
}
|
|
4426
4458
|
}, [attributes.onDragOver]),
|
|
4427
4459
|
onDragStart: React.useCallback(function (event) {
|
|
4428
|
-
if (!readOnly && hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDragStart)) {
|
|
4460
|
+
if (!readOnly && ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDragStart)) {
|
|
4429
4461
|
var node = ReactEditor.toSlateNode(editor, event.target);
|
|
4430
4462
|
var path = ReactEditor.findPath(editor, node);
|
|
4431
4463
|
var voidMatch = slate.Editor.isVoid(editor, node) || slate.Editor["void"](editor, {
|
|
@@ -4444,7 +4476,7 @@ var Editable = function Editable(props) {
|
|
|
4444
4476
|
}
|
|
4445
4477
|
}, [readOnly, attributes.onDragStart]),
|
|
4446
4478
|
onDrop: React.useCallback(function (event) {
|
|
4447
|
-
if (!readOnly && hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDrop)) {
|
|
4479
|
+
if (!readOnly && ReactEditor.hasTarget(editor, event.target) && !isEventHandled(event, attributes.onDrop)) {
|
|
4448
4480
|
event.preventDefault(); // Keep a reference to the dragged range before updating selection
|
|
4449
4481
|
|
|
4450
4482
|
var draggedRange = editor.selection; // Find the range where the drop happened
|
|
@@ -4475,7 +4507,7 @@ var Editable = function Editable(props) {
|
|
|
4475
4507
|
state.isDraggingInternally = false;
|
|
4476
4508
|
}, [readOnly, attributes.onDrop]),
|
|
4477
4509
|
onDragEnd: React.useCallback(function (event) {
|
|
4478
|
-
if (!readOnly && state.isDraggingInternally && attributes.onDragEnd && hasTarget(editor, event.target)) {
|
|
4510
|
+
if (!readOnly && state.isDraggingInternally && attributes.onDragEnd && ReactEditor.hasTarget(editor, event.target)) {
|
|
4479
4511
|
attributes.onDragEnd(event);
|
|
4480
4512
|
} // When dropping on a different droppable element than the current editor,
|
|
4481
4513
|
// `onDrop` is not called. So we need to clean up in `onDragEnd` instead.
|
|
@@ -4485,7 +4517,7 @@ var Editable = function Editable(props) {
|
|
|
4485
4517
|
state.isDraggingInternally = false;
|
|
4486
4518
|
}, [readOnly, attributes.onDragEnd]),
|
|
4487
4519
|
onFocus: React.useCallback(function (event) {
|
|
4488
|
-
if (!readOnly && !state.isUpdatingSelection &&
|
|
4520
|
+
if (!readOnly && !state.isUpdatingSelection && ReactEditor.hasSelectableTarget(editor, event.target) && !isEventHandled(event, attributes.onFocus)) {
|
|
4489
4521
|
var el = ReactEditor.toDOMNode(editor, editor);
|
|
4490
4522
|
var root = ReactEditor.findDocumentOrShadowRoot(editor);
|
|
4491
4523
|
state.latestElement = root.activeElement; // COMPAT: If the editor has nested editable elements, the focus
|
|
@@ -4501,7 +4533,7 @@ var Editable = function Editable(props) {
|
|
|
4501
4533
|
}
|
|
4502
4534
|
}, [readOnly, attributes.onFocus]),
|
|
4503
4535
|
onKeyDown: React.useCallback(function (event) {
|
|
4504
|
-
if (!readOnly && hasEditableTarget(editor, event.target)) {
|
|
4536
|
+
if (!readOnly && ReactEditor.hasEditableTarget(editor, event.target)) {
|
|
4505
4537
|
androidInputManager === null || androidInputManager === void 0 ? void 0 : androidInputManager.handleKeyDown(event);
|
|
4506
4538
|
var nativeEvent = event.nativeEvent; // COMPAT: The composition end event isn't fired reliably in all browsers,
|
|
4507
4539
|
// so we sometimes might end up stuck in a composition state even though we
|
|
@@ -4788,7 +4820,7 @@ var Editable = function Editable(props) {
|
|
|
4788
4820
|
}
|
|
4789
4821
|
}, [readOnly, attributes.onKeyDown]),
|
|
4790
4822
|
onPaste: React.useCallback(function (event) {
|
|
4791
|
-
if (!readOnly &&
|
|
4823
|
+
if (!readOnly && ReactEditor.hasSelectableTarget(editor, event.target) && !isEventHandled(event, attributes.onPaste)) {
|
|
4792
4824
|
// COMPAT: Certain browsers don't support the `beforeinput` event, so we
|
|
4793
4825
|
// fall back to React's `onPaste` here instead.
|
|
4794
4826
|
// COMPAT: Firefox, Chrome and Safari don't emit `beforeinput` events
|
|
@@ -4846,36 +4878,11 @@ var defaultScrollSelectionIntoView = function defaultScrollSelectionIntoView(edi
|
|
|
4846
4878
|
delete leafEl.getBoundingClientRect;
|
|
4847
4879
|
}
|
|
4848
4880
|
};
|
|
4849
|
-
/**
|
|
4850
|
-
* Check if the target is in the editor.
|
|
4851
|
-
*/
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
var hasTarget = function hasTarget(editor, target) {
|
|
4855
|
-
return isDOMNode(target) && ReactEditor.hasDOMNode(editor, target);
|
|
4856
|
-
};
|
|
4857
|
-
/**
|
|
4858
|
-
* Check if the target is editable and in the editor.
|
|
4859
|
-
*/
|
|
4860
|
-
|
|
4861
|
-
var hasEditableTarget = function hasEditableTarget(editor, target) {
|
|
4862
|
-
return isDOMNode(target) && ReactEditor.hasDOMNode(editor, target, {
|
|
4863
|
-
editable: true
|
|
4864
|
-
});
|
|
4865
|
-
};
|
|
4866
|
-
/**
|
|
4867
|
-
* Check if the target is inside void and in an non-readonly editor.
|
|
4868
|
-
*/
|
|
4869
|
-
|
|
4870
|
-
var isTargetInsideNonReadonlyVoid = function isTargetInsideNonReadonlyVoid(editor, target) {
|
|
4871
|
-
if (IS_READ_ONLY.get(editor)) return false;
|
|
4872
|
-
var slateNode = hasTarget(editor, target) && ReactEditor.toSlateNode(editor, target);
|
|
4873
|
-
return slate.Editor.isVoid(editor, slateNode);
|
|
4874
|
-
};
|
|
4875
4881
|
/**
|
|
4876
4882
|
* Check if an event is overrided by a handler.
|
|
4877
4883
|
*/
|
|
4878
4884
|
|
|
4885
|
+
|
|
4879
4886
|
var isEventHandled = function isEventHandled(event, handler) {
|
|
4880
4887
|
if (!handler) {
|
|
4881
4888
|
return false;
|
|
@@ -5072,11 +5079,11 @@ var Slate = function Slate(props) {
|
|
|
5072
5079
|
|
|
5073
5080
|
var _React$useState = React__default['default'].useState(function () {
|
|
5074
5081
|
if (!slate.Node.isNodeList(value)) {
|
|
5075
|
-
throw new Error("[Slate] value is invalid! Expected a list of elements
|
|
5082
|
+
throw new Error("[Slate] value is invalid! Expected a list of elements but got: ".concat(slate.Scrubber.stringify(value)));
|
|
5076
5083
|
}
|
|
5077
5084
|
|
|
5078
5085
|
if (!slate.Editor.isEditor(editor)) {
|
|
5079
|
-
throw new Error("[Slate] editor is invalid!
|
|
5086
|
+
throw new Error("[Slate] editor is invalid! You passed: ".concat(slate.Scrubber.stringify(editor)));
|
|
5080
5087
|
}
|
|
5081
5088
|
|
|
5082
5089
|
editor.children = value;
|