slate-react 0.70.1-2021109235946 → 0.70.2
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/CHANGELOG.md +13 -1
- package/dist/components/editable.d.ts.map +1 -1
- package/dist/index.es.js +67 -57
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +66 -55
- package/dist/index.js.map +1 -1
- package/dist/slate-react.js +64 -55
- package/dist/slate-react.min.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
# slate-react
|
|
2
2
|
|
|
3
|
-
## 0.70.
|
|
3
|
+
## 0.70.2
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
+
- [#4669](https://github.com/ianstormtaylor/slate/pull/4669) [`807716d7`](https://github.com/ianstormtaylor/slate/commit/807716d7dfb0fa5791cdcdfeaf4ac027a003127b) Thanks [@BitPhinix](https://github.com/BitPhinix)! - Flush scheduleOnDOMSelectionChange on beforeinput
|
|
8
|
+
|
|
9
|
+
* [#4661](https://github.com/ianstormtaylor/slate/pull/4661) [`0f194a86`](https://github.com/ianstormtaylor/slate/commit/0f194a86a08d5de07e58e20fb95c9dc760e9d52d) Thanks [@leoc4e](https://github.com/leoc4e)! - use ownerDocument to create element
|
|
10
|
+
|
|
11
|
+
## 0.70.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#4654](https://github.com/ianstormtaylor/slate/pull/4654) [`2c7750ca`](https://github.com/ianstormtaylor/slate/commit/2c7750cac5949a935a570a9590a82187673b9a44) Thanks [@anho](https://github.com/anho)! - weak guard on DataTransfer to not rely on current window
|
|
16
|
+
|
|
17
|
+
* [#4652](https://github.com/ianstormtaylor/slate/pull/4652) [`95389ed7`](https://github.com/ianstormtaylor/slate/commit/95389ed7b03487aa066af277afcccba440c32f24) Thanks [@karthikcodes6](https://github.com/karthikcodes6)! - Disabled the auto scroll behaviour when the editor has any active selection
|
|
18
|
+
|
|
7
19
|
- [#4650](https://github.com/ianstormtaylor/slate/pull/4650) [`b6643132`](https://github.com/ianstormtaylor/slate/commit/b6643132f1f3b64f019a601ee2f44a521c122ad3) Thanks [@e1himself](https://github.com/e1himself)! - Do not disable Grammarly extension in Slate editors
|
|
8
20
|
|
|
9
21
|
## 0.70.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editable.d.ts","sourceRoot":"","sources":["../packages/slate-react/src/components/editable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAA;AAChF,OAAO,EAEL,OAAO,EACP,SAAS,EAET,KAAK,EACL,IAAI,EAGL,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"editable.d.ts","sourceRoot":"","sources":["../packages/slate-react/src/components/editable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAA;AAChF,OAAO,EAEL,OAAO,EACP,SAAS,EAET,KAAK,EACL,IAAI,EAGL,MAAM,OAAO,CAAA;AAiBd,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AAKhC,OAAO,EAEL,OAAO,EACP,QAAQ,EAKT,MAAM,cAAc,CAAA;AAkBrB;;GAEG;AAEH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,GAAG,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE;QACV,iBAAiB,EAAE,SAAS,CAAA;QAC5B,mBAAmB,CAAC,EAAE,IAAI,CAAA;QAC1B,iBAAiB,CAAC,EAAE,IAAI,CAAA;QACxB,GAAG,CAAC,EAAE,KAAK,CAAA;QACX,GAAG,EAAE,GAAG,CAAA;KACT,CAAA;CACF;AAED;;GAEG;AAEH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,GAAG,CAAA;IACb,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,IAAI,CAAA;IACV,UAAU,E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eAAO,MAAM,kBAAkB,8BAG5B,sBAAsB,gBAA4C,CAAA;AAErE;;GAEG;AAEH,eAAO,MAAM,eAAe,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,KAAK,EAAa,CAAA;AAyBtE;;GAEG;AAEH,eAAO,MAAM,YAAY,MAAO,QAAQ,KAAK,QAAQ,YAWpD,CAAA;AAED;;GAEG;AAEH,eAAO,MAAM,SAAS,WACZ,WAAW,UACX,WAAW,GAAG,IAAI,sBAG3B,CAAA;AAED;;GAEG;AAEH,eAAO,MAAM,iBAAiB,WACpB,WAAW,UACX,WAAW,GAAG,IAAI,sBAM3B,CAAA;AAED;;GAEG;AAEH,eAAO,MAAM,kBAAkB,WACrB,WAAW,UACX,WAAW,GAAG,IAAI,KACzB,OAIF,CAAA;AAED;;GAEG;AAEH,eAAO,MAAM,cAAc,gHAIO,IAAI,GAAG,OAAO,yBAc/C,CAAA;AAED;;GAEG;AAEH,eAAO,MAAM,iBAAiB,uDAEJ,IAAI,GAAG,OAAO,yBAevC,CAAA"}
|
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useRef, useEffect, useLayoutEffect, useContext, createContext, useState, useMemo, useCallback } from 'react';
|
|
2
2
|
import { Path, Node, Editor, Text as Text$1, Range, Element as Element$1, Transforms } from 'slate';
|
|
3
3
|
import getDirection from 'direction';
|
|
4
|
+
import debounce from 'lodash/debounce';
|
|
4
5
|
import throttle from 'lodash/throttle';
|
|
5
6
|
import scrollIntoView from 'scroll-into-view-if-needed';
|
|
6
7
|
import { isKeyHotkey } from 'is-hotkey';
|
|
@@ -1075,13 +1076,59 @@ var Editable$1 = props => {
|
|
|
1075
1076
|
if (ref.current && autoFocus) {
|
|
1076
1077
|
ref.current.focus();
|
|
1077
1078
|
}
|
|
1078
|
-
}, [autoFocus]); // Listen on the native `
|
|
1079
|
+
}, [autoFocus]); // Listen on the native `selectionchange` event to be able to update any time
|
|
1080
|
+
// the selection changes. This is required because React's `onSelect` is leaky
|
|
1081
|
+
// and non-standard so it doesn't fire until after a selection has been
|
|
1082
|
+
// released. This causes issues in situations where another change happens
|
|
1083
|
+
// while a selection is being dragged.
|
|
1084
|
+
|
|
1085
|
+
var onDOMSelectionChange = useCallback(throttle(() => {
|
|
1086
|
+
if (!state.isComposing && !state.isUpdatingSelection && !state.isDraggingInternally) {
|
|
1087
|
+
var root = ReactEditor.findDocumentOrShadowRoot(editor);
|
|
1088
|
+
var {
|
|
1089
|
+
activeElement
|
|
1090
|
+
} = root;
|
|
1091
|
+
var el = ReactEditor.toDOMNode(editor, editor);
|
|
1092
|
+
var domSelection = root.getSelection();
|
|
1093
|
+
|
|
1094
|
+
if (activeElement === el) {
|
|
1095
|
+
state.latestElement = activeElement;
|
|
1096
|
+
IS_FOCUSED.set(editor, true);
|
|
1097
|
+
} else {
|
|
1098
|
+
IS_FOCUSED.delete(editor);
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
if (!domSelection) {
|
|
1102
|
+
return Transforms.deselect(editor);
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
var {
|
|
1106
|
+
anchorNode,
|
|
1107
|
+
focusNode
|
|
1108
|
+
} = domSelection;
|
|
1109
|
+
var anchorNodeSelectable = hasEditableTarget(editor, anchorNode) || isTargetInsideVoid(editor, anchorNode);
|
|
1110
|
+
var focusNodeSelectable = hasEditableTarget(editor, focusNode) || isTargetInsideVoid(editor, focusNode);
|
|
1111
|
+
|
|
1112
|
+
if (anchorNodeSelectable && focusNodeSelectable) {
|
|
1113
|
+
var range = ReactEditor.toSlateRange(editor, domSelection, {
|
|
1114
|
+
exactMatch: false,
|
|
1115
|
+
suppressThrow: false
|
|
1116
|
+
});
|
|
1117
|
+
Transforms.select(editor, range);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
}, 100), [readOnly]);
|
|
1121
|
+
var scheduleOnDOMSelectionChange = useMemo(() => debounce(onDOMSelectionChange, 0), [onDOMSelectionChange]); // Listen on the native `beforeinput` event to get real "Level 2" events. This
|
|
1079
1122
|
// is required because React's `beforeinput` is fake and never really attaches
|
|
1080
1123
|
// to the real event sadly. (2019/11/01)
|
|
1081
1124
|
// https://github.com/facebook/react/issues/11211
|
|
1082
1125
|
|
|
1083
1126
|
var onDOMBeforeInput = useCallback(event => {
|
|
1084
1127
|
if (!readOnly && hasEditableTarget(editor, event.target) && !isDOMEventHandled(event, propsOnDOMBeforeInput)) {
|
|
1128
|
+
// Some IMEs/Chrome extensions like e.g. Grammarly set the selection immediately before
|
|
1129
|
+
// triggering a `beforeinput` expecting the change to be applied to the immediately before
|
|
1130
|
+
// set selection.
|
|
1131
|
+
scheduleOnDOMSelectionChange.flush();
|
|
1085
1132
|
var {
|
|
1086
1133
|
selection
|
|
1087
1134
|
} = editor;
|
|
@@ -1266,11 +1313,12 @@ var Editable$1 = props => {
|
|
|
1266
1313
|
// https://www.w3.org/TR/input-events-2/
|
|
1267
1314
|
state.isComposing && setIsComposing(false);
|
|
1268
1315
|
state.isComposing = false;
|
|
1269
|
-
}
|
|
1316
|
+
} // use a weak comparison instead of 'instanceof' to allow
|
|
1317
|
+
// programmatic access of paste events coming from external windows
|
|
1318
|
+
// like cypress where cy.window does not work realibly
|
|
1270
1319
|
|
|
1271
|
-
var window = ReactEditor.getWindow(editor);
|
|
1272
1320
|
|
|
1273
|
-
if (data
|
|
1321
|
+
if ((data === null || data === void 0 ? void 0 : data.constructor.name) === 'DataTransfer') {
|
|
1274
1322
|
ReactEditor.insertData(editor, data);
|
|
1275
1323
|
} else if (typeof data === 'string') {
|
|
1276
1324
|
// Only insertText operations use the native functionality, for now.
|
|
@@ -1303,49 +1351,7 @@ var Editable$1 = props => {
|
|
|
1303
1351
|
ref.current.removeEventListener('beforeinput', onDOMBeforeInput);
|
|
1304
1352
|
}
|
|
1305
1353
|
};
|
|
1306
|
-
}, [onDOMBeforeInput]); //
|
|
1307
|
-
// the selection changes. This is required because React's `onSelect` is leaky
|
|
1308
|
-
// and non-standard so it doesn't fire until after a selection has been
|
|
1309
|
-
// released. This causes issues in situations where another change happens
|
|
1310
|
-
// while a selection is being dragged.
|
|
1311
|
-
|
|
1312
|
-
var onDOMSelectionChange = useCallback(throttle(() => {
|
|
1313
|
-
if (!state.isComposing && !state.isUpdatingSelection && !state.isDraggingInternally) {
|
|
1314
|
-
var root = ReactEditor.findDocumentOrShadowRoot(editor);
|
|
1315
|
-
var {
|
|
1316
|
-
activeElement
|
|
1317
|
-
} = root;
|
|
1318
|
-
var el = ReactEditor.toDOMNode(editor, editor);
|
|
1319
|
-
var domSelection = root.getSelection();
|
|
1320
|
-
|
|
1321
|
-
if (activeElement === el) {
|
|
1322
|
-
state.latestElement = activeElement;
|
|
1323
|
-
IS_FOCUSED.set(editor, true);
|
|
1324
|
-
} else {
|
|
1325
|
-
IS_FOCUSED.delete(editor);
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
if (!domSelection) {
|
|
1329
|
-
return Transforms.deselect(editor);
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
var {
|
|
1333
|
-
anchorNode,
|
|
1334
|
-
focusNode
|
|
1335
|
-
} = domSelection;
|
|
1336
|
-
var anchorNodeSelectable = hasEditableTarget(editor, anchorNode) || isTargetInsideVoid(editor, anchorNode);
|
|
1337
|
-
var focusNodeSelectable = hasEditableTarget(editor, focusNode) || isTargetInsideVoid(editor, focusNode);
|
|
1338
|
-
|
|
1339
|
-
if (anchorNodeSelectable && focusNodeSelectable) {
|
|
1340
|
-
var range = ReactEditor.toSlateRange(editor, domSelection, {
|
|
1341
|
-
exactMatch: false,
|
|
1342
|
-
suppressThrow: false
|
|
1343
|
-
});
|
|
1344
|
-
Transforms.select(editor, range);
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
}, 100), [readOnly]);
|
|
1348
|
-
var scheduleOnDOMSelectionChange = useCallback(() => setTimeout(onDOMSelectionChange), [onDOMSelectionChange]); // Attach a native DOM event handler for `selectionchange`, because React's
|
|
1354
|
+
}, [onDOMBeforeInput]); // Attach a native DOM event handler for `selectionchange`, because React's
|
|
1349
1355
|
// built-in `onSelect` handler doesn't fire for all selection changes. It's a
|
|
1350
1356
|
// leaky polyfill that only fires on keypresses or clicks. Instead, we want to
|
|
1351
1357
|
// fire for any change to the selection inside the editor. (2019/11/04)
|
|
@@ -2017,12 +2023,16 @@ var defaultDecorate = () => [];
|
|
|
2017
2023
|
*/
|
|
2018
2024
|
|
|
2019
2025
|
var defaultScrollSelectionIntoView = (editor, domRange) => {
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
+
// This was affecting the selection of multiple blocks and dragging behavior,
|
|
2027
|
+
// so enabled only if the selection has been collapsed.
|
|
2028
|
+
if (!editor.selection || editor.selection && Range.isCollapsed(editor.selection)) {
|
|
2029
|
+
var leafEl = domRange.startContainer.parentElement;
|
|
2030
|
+
leafEl.getBoundingClientRect = domRange.getBoundingClientRect.bind(domRange);
|
|
2031
|
+
scrollIntoView(leafEl, {
|
|
2032
|
+
scrollMode: 'if-needed'
|
|
2033
|
+
});
|
|
2034
|
+
delete leafEl.getBoundingClientRect;
|
|
2035
|
+
}
|
|
2026
2036
|
};
|
|
2027
2037
|
/**
|
|
2028
2038
|
* Check if the target is in the editor.
|
|
@@ -3963,7 +3973,7 @@ var withReact = editor => {
|
|
|
3963
3973
|
// node, wrap it in a `<span>` so we have something to set an attribute on.
|
|
3964
3974
|
|
|
3965
3975
|
if (isDOMText(attach)) {
|
|
3966
|
-
var span =
|
|
3976
|
+
var span = attach.ownerDocument.createElement('span'); // COMPAT: In Chrome and Safari, if we don't add the `white-space` style
|
|
3967
3977
|
// then leading and trailing spaces will be ignored. (2017/09/21)
|
|
3968
3978
|
|
|
3969
3979
|
span.style.whiteSpace = 'pre';
|
|
@@ -3978,13 +3988,13 @@ var withReact = editor => {
|
|
|
3978
3988
|
attach.setAttribute('data-slate-fragment', encoded);
|
|
3979
3989
|
data.setData('application/x-slate-fragment', encoded); // Add the content to a <div> so that we can get its inner HTML.
|
|
3980
3990
|
|
|
3981
|
-
var div =
|
|
3991
|
+
var div = contents.ownerDocument.createElement('div');
|
|
3982
3992
|
div.appendChild(contents);
|
|
3983
3993
|
div.setAttribute('hidden', 'true');
|
|
3984
|
-
|
|
3994
|
+
contents.ownerDocument.body.appendChild(div);
|
|
3985
3995
|
data.setData('text/html', div.innerHTML);
|
|
3986
3996
|
data.setData('text/plain', getPlainText(div));
|
|
3987
|
-
|
|
3997
|
+
contents.ownerDocument.body.removeChild(div);
|
|
3988
3998
|
return data;
|
|
3989
3999
|
};
|
|
3990
4000
|
|