slate-react 0.72.5 → 0.72.7-202202714199

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # slate-react
2
2
 
3
+ ## 0.72.7-202202714199
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4798](https://github.com/ianstormtaylor/slate/pull/4798) [`3796c514`](https://github.com/ianstormtaylor/slate/commit/3796c514d6da0db8656486151147d92e73a2350a) Thanks [@hueyhe](https://github.com/hueyhe)! - Fix text not rendered on ssr
8
+
9
+ ## 0.72.6
10
+
11
+ ### Patch Changes
12
+
13
+ - [#4796](https://github.com/ianstormtaylor/slate/pull/4796) [`5d8a1606`](https://github.com/ianstormtaylor/slate/commit/5d8a16066949981ead34466af26bcb8e4ffa994b) Thanks [@hueyhe](https://github.com/hueyhe)! - Fix text not rendered on server-side rendering
14
+
3
15
  ## 0.72.5
4
16
 
5
17
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../packages/slate-react/src/components/string.tsx"],"names":[],"mappings":";AACA,OAAO,EAAU,IAAI,EAAQ,OAAO,EAAQ,MAAM,OAAO,CAAA;AAIzD;;GAEG;AAEH,QAAA,MAAM,MAAM,UAAW;IACrB,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,IAAI,CAAA;CACX,gBAsCA,CAAA;AAoDD,eAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../packages/slate-react/src/components/string.tsx"],"names":[],"mappings":";AACA,OAAO,EAAU,IAAI,EAAQ,OAAO,EAAQ,MAAM,OAAO,CAAA;AAKzD;;GAEG;AAEH,QAAA,MAAM,MAAM,UAAW;IACrB,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,IAAI,CAAA;CACX,gBAsCA,CAAA;AAkED,eAAe,MAAM,CAAA"}
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useRef, useLayoutEffect, useEffect, useState, Fragment, useContext, createContext, useMemo, useCallback } from 'react';
1
+ import React, { useLayoutEffect, useEffect, useRef, useState, Fragment, useContext, createContext, 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
4
  import debounce from 'lodash/debounce';
@@ -56,6 +56,40 @@ function _objectWithoutProperties(source, excluded) {
56
56
  return target;
57
57
  }
58
58
 
59
+ var IS_IOS = typeof navigator !== 'undefined' && typeof window !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
60
+ var IS_APPLE = typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent);
61
+ var IS_ANDROID = typeof navigator !== 'undefined' && /Android/.test(navigator.userAgent);
62
+ var IS_FIREFOX = typeof navigator !== 'undefined' && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
63
+ var IS_SAFARI = typeof navigator !== 'undefined' && /Version\/[\d\.]+.*Safari/.test(navigator.userAgent); // "modern" Edge was released at 79.x
64
+
65
+ var IS_EDGE_LEGACY = typeof navigator !== 'undefined' && /Edge?\/(?:[0-6][0-9]|[0-7][0-8])/i.test(navigator.userAgent);
66
+ var IS_CHROME = typeof navigator !== 'undefined' && /Chrome/i.test(navigator.userAgent); // Native `beforeInput` events don't work well with react on Chrome 75
67
+ // and older, Chrome 76+ can use `beforeInput` though.
68
+
69
+ var IS_CHROME_LEGACY = typeof navigator !== 'undefined' && /Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent); // Firefox did not support `beforeInput` until `v87`.
70
+
71
+ var IS_FIREFOX_LEGACY = typeof navigator !== 'undefined' && /^(?!.*Seamonkey)(?=.*Firefox\/(?:[0-7][0-9]|[0-8][0-6])).*/i.test(navigator.userAgent); // qq browser
72
+
73
+ var IS_QQBROWSER = typeof navigator !== 'undefined' && /.*QQBrowser/.test(navigator.userAgent); // UC mobile browser
74
+
75
+ var IS_UC_MOBILE = typeof navigator !== 'undefined' && /.*UCBrowser/.test(navigator.userAgent); // Wechat browser
76
+
77
+ var IS_WECHATBROWSER = typeof navigator !== 'undefined' && /.*Wechat/.test(navigator.userAgent); // Check if DOM is available as React does internally.
78
+ // https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
79
+
80
+ var CAN_USE_DOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined'); // COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event
81
+ // Chrome Legacy doesn't support `beforeinput` correctly
82
+
83
+ var HAS_BEFORE_INPUT_SUPPORT = !IS_CHROME_LEGACY && !IS_EDGE_LEGACY && // globalThis is undefined in older browsers
84
+ typeof globalThis !== 'undefined' && globalThis.InputEvent && // @ts-ignore The `getTargetRanges` property isn't recognized.
85
+ typeof globalThis.InputEvent.prototype.getTargetRanges === 'function';
86
+
87
+ /**
88
+ * Prevent warning on SSR by falling back to useEffect when DOM isn't available
89
+ */
90
+
91
+ var useIsomorphicLayoutEffect = CAN_USE_DOM ? useLayoutEffect : useEffect;
92
+
59
93
  /**
60
94
  * Leaf content strings.
61
95
  */
@@ -117,7 +151,11 @@ var TextString = props => {
117
151
  text,
118
152
  isTrailing = false
119
153
  } = props;
120
- var ref = useRef(null); // This is the actual text rendering boundary where we interface with the DOM
154
+ var ref = useRef(null);
155
+
156
+ var getTextContent = () => {
157
+ return "".concat(text !== null && text !== void 0 ? text : '').concat(isTrailing ? '\n' : '');
158
+ }; // This is the actual text rendering boundary where we interface with the DOM
121
159
  // The text is not rendered as part of the virtual DOM, as since we handle basic character insertions natively,
122
160
  // updating the DOM is not a one way dataflow anymore. What we need here is not reconciliation and diffing
123
161
  // with previous version of the virtual DOM, but rather diffing with the actual DOM element, and replace the DOM <span> content
@@ -126,16 +164,26 @@ var TextString = props => {
126
164
  // eg makes native spellcheck opt out from checking the text node.
127
165
  // useLayoutEffect: updating our span before browser paint
128
166
 
129
- useLayoutEffect(() => {
167
+
168
+ useIsomorphicLayoutEffect(() => {
130
169
  // null coalescing text to make sure we're not outputing "null" as a string in the extreme case it is nullish at runtime
131
- var textWithTrailing = "".concat(text !== null && text !== void 0 ? text : '').concat(isTrailing ? '\n' : '');
170
+ var textWithTrailing = getTextContent();
132
171
 
133
172
  if (ref.current && ref.current.textContent !== textWithTrailing) {
134
173
  ref.current.textContent = textWithTrailing;
135
174
  } // intentionally not specifying dependencies, so that this effect runs on every render
136
175
  // as this effectively replaces "specifying the text in the virtual DOM under the <span> below" on each render
137
176
 
138
- }); // the span is intentionally same on every render in virtual DOM, actual rendering happens in the layout effect above
177
+ }); // Render text content immediately if it's the first-time render
178
+ // Ensure that text content is rendered on server-side rendering
179
+
180
+ if (!ref.current) {
181
+ return /*#__PURE__*/React.createElement("span", {
182
+ "data-slate-string": true,
183
+ ref: ref
184
+ }, getTextContent());
185
+ } // the span is intentionally same on every render in virtual DOM, actual rendering happens in the layout effect above
186
+
139
187
 
140
188
  return /*#__PURE__*/React.createElement("span", {
141
189
  "data-slate-string": true,
@@ -281,40 +329,6 @@ var DefaultLeaf = props => {
281
329
  return /*#__PURE__*/React.createElement("span", Object.assign({}, attributes), children);
282
330
  };
283
331
 
284
- var IS_IOS = typeof navigator !== 'undefined' && typeof window !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
285
- var IS_APPLE = typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent);
286
- var IS_ANDROID = typeof navigator !== 'undefined' && /Android/.test(navigator.userAgent);
287
- var IS_FIREFOX = typeof navigator !== 'undefined' && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
288
- var IS_SAFARI = typeof navigator !== 'undefined' && /Version\/[\d\.]+.*Safari/.test(navigator.userAgent); // "modern" Edge was released at 79.x
289
-
290
- var IS_EDGE_LEGACY = typeof navigator !== 'undefined' && /Edge?\/(?:[0-6][0-9]|[0-7][0-8])/i.test(navigator.userAgent);
291
- var IS_CHROME = typeof navigator !== 'undefined' && /Chrome/i.test(navigator.userAgent); // Native `beforeInput` events don't work well with react on Chrome 75
292
- // and older, Chrome 76+ can use `beforeInput` though.
293
-
294
- var IS_CHROME_LEGACY = typeof navigator !== 'undefined' && /Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent); // Firefox did not support `beforeInput` until `v87`.
295
-
296
- var IS_FIREFOX_LEGACY = typeof navigator !== 'undefined' && /^(?!.*Seamonkey)(?=.*Firefox\/(?:[0-7][0-9]|[0-8][0-6])).*/i.test(navigator.userAgent); // qq browser
297
-
298
- var IS_QQBROWSER = typeof navigator !== 'undefined' && /.*QQBrowser/.test(navigator.userAgent); // UC mobile browser
299
-
300
- var IS_UC_MOBILE = typeof navigator !== 'undefined' && /.*UCBrowser/.test(navigator.userAgent); // Wechat browser
301
-
302
- var IS_WECHATBROWSER = typeof navigator !== 'undefined' && /.*Wechat/.test(navigator.userAgent); // Check if DOM is available as React does internally.
303
- // https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
304
-
305
- var CAN_USE_DOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined'); // COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event
306
- // Chrome Legacy doesn't support `beforeinput` correctly
307
-
308
- var HAS_BEFORE_INPUT_SUPPORT = !IS_CHROME_LEGACY && !IS_EDGE_LEGACY && // globalThis is undefined in older browsers
309
- typeof globalThis !== 'undefined' && globalThis.InputEvent && // @ts-ignore The `getTargetRanges` property isn't recognized.
310
- typeof globalThis.InputEvent.prototype.getTargetRanges === 'function';
311
-
312
- /**
313
- * Prevent warning on SSR by falling back to useEffect when DOM isn't available
314
- */
315
-
316
- var useIsomorphicLayoutEffect = CAN_USE_DOM ? useLayoutEffect : useEffect;
317
-
318
332
  var _excluded$3 = ["anchor", "focus"],
319
333
  _excluded2 = ["anchor", "focus"];
320
334
  var shallowCompare = (obj1, obj2) => Object.keys(obj1).length === Object.keys(obj2).length && Object.keys(obj1).every(key => obj2.hasOwnProperty(key) && obj1[key] === obj2[key]);