slate-react 0.86.0 → 0.87.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.
- package/dist/components/editable.d.ts.map +1 -1
- package/dist/components/leaf.d.ts.map +1 -1
- package/dist/index.es.js +82 -18
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +82 -18
- package/dist/index.js.map +1 -1
- package/dist/slate-react.js +82 -18
- package/dist/slate-react.min.js +1 -1
- package/dist/utils/weak-maps.d.ts +1 -0
- package/dist/utils/weak-maps.d.ts.map +1 -1
- package/package.json +3 -2
package/dist/slate-react.js
CHANGED
|
@@ -945,6 +945,7 @@
|
|
|
945
945
|
var NODE_TO_ELEMENT = new WeakMap();
|
|
946
946
|
var NODE_TO_KEY = new WeakMap();
|
|
947
947
|
var EDITOR_TO_KEY_TO_ELEMENT = new WeakMap();
|
|
948
|
+
var EDITOR_TO_STYLE_ELEMENT = new WeakMap();
|
|
948
949
|
/**
|
|
949
950
|
* Weak maps for storing editor-related state.
|
|
950
951
|
*/
|
|
@@ -2158,18 +2159,55 @@
|
|
|
2158
2159
|
} : _props$renderLeaf;
|
|
2159
2160
|
var placeholderRef = React.useRef(null);
|
|
2160
2161
|
var editor = useSlateStatic();
|
|
2162
|
+
var placeholderResizeObserver = React.useRef(null);
|
|
2163
|
+
React.useEffect(function () {
|
|
2164
|
+
return function () {
|
|
2165
|
+
if (placeholderResizeObserver.current) {
|
|
2166
|
+
placeholderResizeObserver.current.disconnect();
|
|
2167
|
+
}
|
|
2168
|
+
};
|
|
2169
|
+
}, []);
|
|
2161
2170
|
React.useEffect(function () {
|
|
2162
2171
|
var placeholderEl = placeholderRef === null || placeholderRef === void 0 ? void 0 : placeholderRef.current;
|
|
2163
|
-
var editorEl = ReactEditor.toDOMNode(editor, editor);
|
|
2164
2172
|
|
|
2165
|
-
if (
|
|
2166
|
-
|
|
2173
|
+
if (placeholderEl) {
|
|
2174
|
+
EDITOR_TO_PLACEHOLDER_ELEMENT.set(editor, placeholderEl);
|
|
2175
|
+
} else {
|
|
2176
|
+
EDITOR_TO_PLACEHOLDER_ELEMENT["delete"](editor);
|
|
2177
|
+
}
|
|
2178
|
+
|
|
2179
|
+
if (placeholderResizeObserver.current) {
|
|
2180
|
+
// Update existing observer.
|
|
2181
|
+
placeholderResizeObserver.current.disconnect();
|
|
2182
|
+
if (placeholderEl) placeholderResizeObserver.current.observe(placeholderEl);
|
|
2183
|
+
} else if (placeholderEl) {
|
|
2184
|
+
// Create a new observer and observe the placeholder element.
|
|
2185
|
+
placeholderResizeObserver.current = new ResizeObserver(function (_ref) {
|
|
2186
|
+
var _ref2 = _slicedToArray(_ref, 1),
|
|
2187
|
+
target = _ref2[0].target;
|
|
2188
|
+
|
|
2189
|
+
var styleElement = EDITOR_TO_STYLE_ELEMENT.get(editor);
|
|
2190
|
+
|
|
2191
|
+
if (styleElement) {
|
|
2192
|
+
// Make the min-height the height of the placeholder.
|
|
2193
|
+
var minHeight = "".concat(target.clientHeight, "px");
|
|
2194
|
+
styleElement.innerHTML = ":where([data-slate-editor-id=\"".concat(editor.id, "\"]) { min-height: ").concat(minHeight, "; }");
|
|
2195
|
+
}
|
|
2196
|
+
});
|
|
2197
|
+
placeholderResizeObserver.current.observe(placeholderEl);
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
if (!placeholderEl) {
|
|
2201
|
+
// No placeholder element, so no need for a resize observer.
|
|
2202
|
+
var styleElement = EDITOR_TO_STYLE_ELEMENT.get(editor);
|
|
2203
|
+
|
|
2204
|
+
if (styleElement) {
|
|
2205
|
+
// No min-height if there is no placeholder.
|
|
2206
|
+
styleElement.innerHTML = '';
|
|
2207
|
+
}
|
|
2167
2208
|
}
|
|
2168
2209
|
|
|
2169
|
-
editorEl.style.minHeight = "".concat(placeholderEl.clientHeight, "px");
|
|
2170
|
-
EDITOR_TO_PLACEHOLDER_ELEMENT.set(editor, placeholderEl);
|
|
2171
2210
|
return function () {
|
|
2172
|
-
editorEl.style.minHeight = 'auto';
|
|
2173
2211
|
EDITOR_TO_PLACEHOLDER_ELEMENT["delete"](editor);
|
|
2174
2212
|
};
|
|
2175
2213
|
}, [placeholderRef, leaf]);
|
|
@@ -4435,12 +4473,14 @@
|
|
|
4435
4473
|
|
|
4436
4474
|
var Children = function Children(props) {
|
|
4437
4475
|
return /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, useChildren(props));
|
|
4438
|
-
};
|
|
4476
|
+
}; // The number of Editable components currently mounted.
|
|
4477
|
+
|
|
4478
|
+
|
|
4479
|
+
var mountedCount = 0;
|
|
4439
4480
|
/**
|
|
4440
4481
|
* Editable.
|
|
4441
4482
|
*/
|
|
4442
4483
|
|
|
4443
|
-
|
|
4444
4484
|
var Editable = function Editable(props) {
|
|
4445
4485
|
var autoFocus = props.autoFocus,
|
|
4446
4486
|
_props$decorate = props.decorate,
|
|
@@ -5064,6 +5104,38 @@
|
|
|
5064
5104
|
EDITOR_TO_PENDING_INSERTION_MARKS["delete"](editor);
|
|
5065
5105
|
});
|
|
5066
5106
|
});
|
|
5107
|
+
React.useEffect(function () {
|
|
5108
|
+
mountedCount++;
|
|
5109
|
+
|
|
5110
|
+
if (mountedCount === 1) {
|
|
5111
|
+
// Set global default styles for editors.
|
|
5112
|
+
var defaultStylesElement = document.createElement('style');
|
|
5113
|
+
defaultStylesElement.setAttribute('data-slate-default-styles', 'true');
|
|
5114
|
+
defaultStylesElement.innerHTML = // :where is used to give these rules lower specificity so user stylesheets can override them.
|
|
5115
|
+
":where([data-slate-editor]) {" + // Allow positioning relative to the editable element.
|
|
5116
|
+
"position: relative;" + // Prevent the default outline styles.
|
|
5117
|
+
"outline: none;" + // Preserve adjacent whitespace and new lines.
|
|
5118
|
+
"white-space: pre-wrap;" + // Allow words to break if they are too long.
|
|
5119
|
+
"word-wrap: break-word;" + "}";
|
|
5120
|
+
document.head.appendChild(defaultStylesElement);
|
|
5121
|
+
}
|
|
5122
|
+
|
|
5123
|
+
return function () {
|
|
5124
|
+
var _document$querySelect;
|
|
5125
|
+
|
|
5126
|
+
mountedCount--;
|
|
5127
|
+
if (mountedCount <= 0) (_document$querySelect = document.querySelector('style[data-slate-default-styles]')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.remove();
|
|
5128
|
+
};
|
|
5129
|
+
}, []);
|
|
5130
|
+
React.useEffect(function () {
|
|
5131
|
+
var styleElement = document.createElement('style');
|
|
5132
|
+
document.head.appendChild(styleElement);
|
|
5133
|
+
EDITOR_TO_STYLE_ELEMENT.set(editor, styleElement);
|
|
5134
|
+
return function () {
|
|
5135
|
+
styleElement.remove();
|
|
5136
|
+
EDITOR_TO_STYLE_ELEMENT["delete"](editor);
|
|
5137
|
+
};
|
|
5138
|
+
}, []);
|
|
5067
5139
|
return /*#__PURE__*/React__default['default'].createElement(ReadOnlyContext.Provider, {
|
|
5068
5140
|
value: readOnly
|
|
5069
5141
|
}, /*#__PURE__*/React__default['default'].createElement(DecorateContext.Provider, {
|
|
@@ -5084,6 +5156,7 @@
|
|
|
5084
5156
|
autoCorrect: HAS_BEFORE_INPUT_SUPPORT || !CAN_USE_DOM ? attributes.autoCorrect : 'false',
|
|
5085
5157
|
autoCapitalize: HAS_BEFORE_INPUT_SUPPORT || !CAN_USE_DOM ? attributes.autoCapitalize : 'false',
|
|
5086
5158
|
"data-slate-editor": true,
|
|
5159
|
+
"data-slate-editor-id": editor.id,
|
|
5087
5160
|
"data-slate-node": "value",
|
|
5088
5161
|
// explicitly set this
|
|
5089
5162
|
contentEditable: !readOnly,
|
|
@@ -5093,16 +5166,7 @@
|
|
|
5093
5166
|
zindex: -1,
|
|
5094
5167
|
suppressContentEditableWarning: true,
|
|
5095
5168
|
ref: ref,
|
|
5096
|
-
style:
|
|
5097
|
-
// Allow positioning relative to the editable element.
|
|
5098
|
-
position: 'relative',
|
|
5099
|
-
// Prevent the default outline styles.
|
|
5100
|
-
outline: 'none',
|
|
5101
|
-
// Preserve adjacent whitespace and new lines.
|
|
5102
|
-
whiteSpace: 'pre-wrap',
|
|
5103
|
-
// Allow words to break if they are too long.
|
|
5104
|
-
wordWrap: 'break-word'
|
|
5105
|
-
}, style),
|
|
5169
|
+
style: style,
|
|
5106
5170
|
onBeforeInput: React.useCallback(function (event) {
|
|
5107
5171
|
// COMPAT: Certain browsers don't support the `beforeinput` event, so we
|
|
5108
5172
|
// fall back to React's leaky polyfill instead just for it. It
|