slate-react 0.89.0 → 0.90.0-20231122332
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 -0
- package/dist/components/editable.d.ts.map +1 -1
- package/dist/components/leaf.d.ts.map +1 -1
- package/dist/index.es.js +32 -78
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +32 -77
- package/dist/index.js.map +1 -1
- package/dist/slate-react.js +32 -77
- package/dist/slate-react.min.js +1 -1
- package/dist/utils/weak-maps.d.ts +0 -1
- package/dist/utils/weak-maps.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/utils/where-if-supported.d.ts +0 -14
- package/dist/utils/where-if-supported.d.ts.map +0 -1
|
@@ -42,6 +42,7 @@ export declare type EditableProps = {
|
|
|
42
42
|
renderPlaceholder?: (props: RenderPlaceholderProps) => JSX.Element;
|
|
43
43
|
scrollSelectionIntoView?: (editor: ReactEditor, domRange: DOMRange) => void;
|
|
44
44
|
as?: React.ElementType;
|
|
45
|
+
disableDefaultStyles?: boolean;
|
|
45
46
|
} & React.TextareaHTMLAttributes<HTMLDivElement>;
|
|
46
47
|
/**
|
|
47
48
|
* Editable.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editable.d.ts","sourceRoot":"","sources":["../packages/slate-react/src/components/editable.tsx"],"names":[],"mappings":"AAGA,OAAO,KAON,MAAM,OAAO,CAAA;AAEd,OAAO,EAEL,OAAO,EAEP,SAAS,EAET,KAAK,EACL,IAAI,EAEL,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAOpD,OAAO,EAGL,QAAQ,EAMT,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"editable.d.ts","sourceRoot":"","sources":["../packages/slate-react/src/components/editable.tsx"],"names":[],"mappings":"AAGA,OAAO,KAON,MAAM,OAAO,CAAA;AAEd,OAAO,EAEL,OAAO,EAEP,SA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3,"file":"leaf.d.ts","sourceRoot":"","sources":["../packages/slate-react/src/components/leaf.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAQrC,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AA0HpE,QAAA,MAAM,YAAY;YAlHR,OAAO;UACT,IAAI;YACF,OAAO;+BACY,sBAAsB,KAAK,WAAW;0BAC5C,eAAe,KAAK,WAAW;UAC9C,IAAI;kBAuHV,CAAA;AAEF,eAAO,MAAM,WAAW,UAAW,eAAe,gBAGjD,CAAA;AAED,eAAe,YAAY,CAAA"}
|
package/dist/index.es.js
CHANGED
|
@@ -91,7 +91,6 @@ var ELEMENT_TO_NODE = new WeakMap();
|
|
|
91
91
|
var NODE_TO_ELEMENT = new WeakMap();
|
|
92
92
|
var NODE_TO_KEY = new WeakMap();
|
|
93
93
|
var EDITOR_TO_KEY_TO_ELEMENT = new WeakMap();
|
|
94
|
-
var EDITOR_TO_STYLE_ELEMENT = new WeakMap();
|
|
95
94
|
/**
|
|
96
95
|
* Weak maps for storing editor-related state.
|
|
97
96
|
*/
|
|
@@ -1296,22 +1295,6 @@ var useSlateStatic = () => {
|
|
|
1296
1295
|
return editor;
|
|
1297
1296
|
};
|
|
1298
1297
|
|
|
1299
|
-
/**
|
|
1300
|
-
* Returns a set of rules that use the `:where` selector if it is supported,
|
|
1301
|
-
* otherwise it falls back to the provided selector on its own.
|
|
1302
|
-
*
|
|
1303
|
-
* The `:where` selector is used to give a selector a lower specificity,
|
|
1304
|
-
* allowing the rule to be overridden by a user-defined stylesheet.
|
|
1305
|
-
*
|
|
1306
|
-
* Older browsers do not support the `:where` selector.
|
|
1307
|
-
* If it is not supported, the selector will be used without `:where`,
|
|
1308
|
-
* which means that the rule will have a higher specificity and a user-defined
|
|
1309
|
-
* stylesheet will not be able to override it easily.
|
|
1310
|
-
*/
|
|
1311
|
-
function whereIfSupported(selector, styles) {
|
|
1312
|
-
return "@supports (selector(:where(".concat(selector, "))) {") + ":where(".concat(selector, ") { ").concat(styles, " }") + "}" + "@supports not (selector(:where(".concat(selector, "))) {") + "".concat(selector, " { ").concat(styles, " }") + "}";
|
|
1313
|
-
}
|
|
1314
|
-
|
|
1315
1298
|
/**
|
|
1316
1299
|
* Individual leaves in a text node with unique formatting.
|
|
1317
1300
|
*/
|
|
@@ -1325,6 +1308,7 @@ var Leaf = props => {
|
|
|
1325
1308
|
renderPlaceholder,
|
|
1326
1309
|
renderLeaf = props => /*#__PURE__*/React.createElement(DefaultLeaf, Object.assign({}, props))
|
|
1327
1310
|
} = props;
|
|
1311
|
+
var lastPlaceholderRef = useRef(null);
|
|
1328
1312
|
var placeholderRef = useRef(null);
|
|
1329
1313
|
var editor = useSlateStatic();
|
|
1330
1314
|
var placeholderResizeObserver = useRef(null);
|
|
@@ -1351,32 +1335,23 @@ var Leaf = props => {
|
|
|
1351
1335
|
} else if (placeholderEl) {
|
|
1352
1336
|
// Create a new observer and observe the placeholder element.
|
|
1353
1337
|
var ResizeObserver$1 = window.ResizeObserver || ResizeObserver;
|
|
1354
|
-
placeholderResizeObserver.current = new ResizeObserver$1(
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
if (styleElement) {
|
|
1361
|
-
// Make the min-height the height of the placeholder.
|
|
1362
|
-
var selector = "[data-slate-editor-id=\"".concat(editor.id, "\"]");
|
|
1363
|
-
var styles = "min-height: ".concat(target.clientHeight, "px;");
|
|
1364
|
-
styleElement.innerHTML = whereIfSupported(selector, styles);
|
|
1365
|
-
}
|
|
1338
|
+
placeholderResizeObserver.current = new ResizeObserver$1(() => {
|
|
1339
|
+
// Force a re-render of the editor so its min-height can be updated
|
|
1340
|
+
// to the new height of the placeholder.
|
|
1341
|
+
var forceRender = EDITOR_TO_FORCE_RENDER.get(editor);
|
|
1342
|
+
forceRender === null || forceRender === void 0 ? void 0 : forceRender();
|
|
1366
1343
|
});
|
|
1367
1344
|
placeholderResizeObserver.current.observe(placeholderEl);
|
|
1368
1345
|
}
|
|
1369
1346
|
|
|
1370
|
-
if (!placeholderEl) {
|
|
1347
|
+
if (!placeholderEl && lastPlaceholderRef.current) {
|
|
1371
1348
|
// No placeholder element, so no need for a resize observer.
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
// No min-height if there is no placeholder.
|
|
1376
|
-
styleElement.innerHTML = '';
|
|
1377
|
-
}
|
|
1349
|
+
// Force a re-render of the editor so its min-height can be reset.
|
|
1350
|
+
var forceRender = EDITOR_TO_FORCE_RENDER.get(editor);
|
|
1351
|
+
forceRender === null || forceRender === void 0 ? void 0 : forceRender();
|
|
1378
1352
|
}
|
|
1379
1353
|
|
|
1354
|
+
lastPlaceholderRef.current = placeholderRef.current;
|
|
1380
1355
|
return () => {
|
|
1381
1356
|
EDITOR_TO_PLACEHOLDER_ELEMENT.delete(editor);
|
|
1382
1357
|
};
|
|
@@ -3156,22 +3131,22 @@ function useTrackUserInput() {
|
|
|
3156
3131
|
};
|
|
3157
3132
|
}
|
|
3158
3133
|
|
|
3159
|
-
var _excluded$1 = ["autoFocus", "decorate", "onDOMBeforeInput", "placeholder", "readOnly", "renderElement", "renderLeaf", "renderPlaceholder", "scrollSelectionIntoView", "style", "as"],
|
|
3134
|
+
var _excluded$1 = ["autoFocus", "decorate", "onDOMBeforeInput", "placeholder", "readOnly", "renderElement", "renderLeaf", "renderPlaceholder", "scrollSelectionIntoView", "style", "as", "disableDefaultStyles"],
|
|
3160
3135
|
_excluded2 = ["text"];
|
|
3161
3136
|
|
|
3162
3137
|
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
3163
3138
|
|
|
3164
3139
|
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
3165
3140
|
|
|
3166
|
-
var Children = props => /*#__PURE__*/React.createElement(React.Fragment, null, useChildren(props));
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
var mountedCount = 0;
|
|
3141
|
+
var Children = props => /*#__PURE__*/React.createElement(React.Fragment, null, useChildren(props));
|
|
3170
3142
|
/**
|
|
3171
3143
|
* Editable.
|
|
3172
3144
|
*/
|
|
3173
3145
|
|
|
3146
|
+
|
|
3174
3147
|
var Editable = props => {
|
|
3148
|
+
var _EDITOR_TO_PLACEHOLDE, _EDITOR_TO_PLACEHOLDE2;
|
|
3149
|
+
|
|
3175
3150
|
var {
|
|
3176
3151
|
autoFocus,
|
|
3177
3152
|
decorate = defaultDecorate,
|
|
@@ -3182,8 +3157,9 @@ var Editable = props => {
|
|
|
3182
3157
|
renderLeaf,
|
|
3183
3158
|
renderPlaceholder = props => /*#__PURE__*/React.createElement(DefaultPlaceholder, Object.assign({}, props)),
|
|
3184
3159
|
scrollSelectionIntoView = defaultScrollSelectionIntoView,
|
|
3185
|
-
style = {},
|
|
3186
|
-
as: Component = 'div'
|
|
3160
|
+
style: userStyle = {},
|
|
3161
|
+
as: Component = 'div',
|
|
3162
|
+
disableDefaultStyles = false
|
|
3187
3163
|
} = props,
|
|
3188
3164
|
attributes = _objectWithoutProperties(props, _excluded$1);
|
|
3189
3165
|
|
|
@@ -3787,39 +3763,7 @@ var Editable = props => {
|
|
|
3787
3763
|
EDITOR_TO_PENDING_INSERTION_MARKS.delete(editor);
|
|
3788
3764
|
});
|
|
3789
3765
|
});
|
|
3790
|
-
|
|
3791
|
-
mountedCount++;
|
|
3792
|
-
|
|
3793
|
-
if (mountedCount === 1) {
|
|
3794
|
-
// Set global default styles for editors.
|
|
3795
|
-
var defaultStylesElement = document.createElement('style');
|
|
3796
|
-
defaultStylesElement.setAttribute('data-slate-default-styles', 'true');
|
|
3797
|
-
var selector = '[data-slate-editor]';
|
|
3798
|
-
var defaultStyles = // Allow positioning relative to the editable element.
|
|
3799
|
-
"position: relative;" + // Prevent the default outline styles.
|
|
3800
|
-
"outline: none;" + // Preserve adjacent whitespace and new lines.
|
|
3801
|
-
"white-space: pre-wrap;" + // Allow words to break if they are too long.
|
|
3802
|
-
"word-wrap: break-word;";
|
|
3803
|
-
defaultStylesElement.innerHTML = whereIfSupported(selector, defaultStyles);
|
|
3804
|
-
document.head.appendChild(defaultStylesElement);
|
|
3805
|
-
}
|
|
3806
|
-
|
|
3807
|
-
return () => {
|
|
3808
|
-
var _document$querySelect;
|
|
3809
|
-
|
|
3810
|
-
mountedCount--;
|
|
3811
|
-
if (mountedCount <= 0) (_document$querySelect = document.querySelector('style[data-slate-default-styles]')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.remove();
|
|
3812
|
-
};
|
|
3813
|
-
}, []);
|
|
3814
|
-
useEffect(() => {
|
|
3815
|
-
var styleElement = document.createElement('style');
|
|
3816
|
-
document.head.appendChild(styleElement);
|
|
3817
|
-
EDITOR_TO_STYLE_ELEMENT.set(editor, styleElement);
|
|
3818
|
-
return () => {
|
|
3819
|
-
styleElement.remove();
|
|
3820
|
-
EDITOR_TO_STYLE_ELEMENT.delete(editor);
|
|
3821
|
-
};
|
|
3822
|
-
}, []);
|
|
3766
|
+
var placeholderHeight = (_EDITOR_TO_PLACEHOLDE = EDITOR_TO_PLACEHOLDER_ELEMENT.get(editor)) === null || _EDITOR_TO_PLACEHOLDE === void 0 ? void 0 : (_EDITOR_TO_PLACEHOLDE2 = _EDITOR_TO_PLACEHOLDE.getBoundingClientRect()) === null || _EDITOR_TO_PLACEHOLDE2 === void 0 ? void 0 : _EDITOR_TO_PLACEHOLDE2.height;
|
|
3823
3767
|
return /*#__PURE__*/React.createElement(ReadOnlyContext.Provider, {
|
|
3824
3768
|
value: readOnly
|
|
3825
3769
|
}, /*#__PURE__*/React.createElement(DecorateContext.Provider, {
|
|
@@ -3840,7 +3784,6 @@ var Editable = props => {
|
|
|
3840
3784
|
autoCorrect: HAS_BEFORE_INPUT_SUPPORT || !CAN_USE_DOM ? attributes.autoCorrect : 'false',
|
|
3841
3785
|
autoCapitalize: HAS_BEFORE_INPUT_SUPPORT || !CAN_USE_DOM ? attributes.autoCapitalize : 'false',
|
|
3842
3786
|
"data-slate-editor": true,
|
|
3843
|
-
"data-slate-editor-id": editor.id,
|
|
3844
3787
|
"data-slate-node": "value",
|
|
3845
3788
|
// explicitly set this
|
|
3846
3789
|
contentEditable: !readOnly,
|
|
@@ -3850,7 +3793,18 @@ var Editable = props => {
|
|
|
3850
3793
|
zindex: -1,
|
|
3851
3794
|
suppressContentEditableWarning: true,
|
|
3852
3795
|
ref: ref,
|
|
3853
|
-
style:
|
|
3796
|
+
style: _objectSpread$1(_objectSpread$1({}, disableDefaultStyles ? {} : _objectSpread$1({
|
|
3797
|
+
// Allow positioning relative to the editable element.
|
|
3798
|
+
position: 'relative',
|
|
3799
|
+
// Prevent the default outline styles.
|
|
3800
|
+
outline: 'none',
|
|
3801
|
+
// Preserve adjacent whitespace and new lines.
|
|
3802
|
+
whiteSpace: 'pre-wrap',
|
|
3803
|
+
// Allow words to break if they are too long.
|
|
3804
|
+
wordWrap: 'break-word'
|
|
3805
|
+
}, placeholderHeight ? {
|
|
3806
|
+
minHeight: placeholderHeight
|
|
3807
|
+
} : {})), userStyle),
|
|
3854
3808
|
onBeforeInput: useCallback(event => {
|
|
3855
3809
|
// COMPAT: Certain browsers don't support the `beforeinput` event, so we
|
|
3856
3810
|
// fall back to React's leaky polyfill instead just for it. It
|