@uiw/react-codemirror 4.23.8 → 4.23.10

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/cjs/index.js CHANGED
@@ -115,7 +115,6 @@ var ReactCodeMirror = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
115
115
  other = (0, _objectWithoutProperties2["default"])(props, _excluded);
116
116
  var editor = (0, _react.useRef)(null);
117
117
  var _useCodeMirror = (0, _useCodeMirror2.useCodeMirror)({
118
- container: editor.current,
119
118
  root: root,
120
119
  value: value,
121
120
  autoFocus: autoFocus,
@@ -141,7 +140,8 @@ var ReactCodeMirror = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
141
140
  }),
142
141
  state = _useCodeMirror.state,
143
142
  view = _useCodeMirror.view,
144
- container = _useCodeMirror.container;
143
+ container = _useCodeMirror.container,
144
+ setContainer = _useCodeMirror.setContainer;
145
145
  (0, _react.useImperativeHandle)(ref, function () {
146
146
  return {
147
147
  editor: editor.current,
@@ -149,6 +149,10 @@ var ReactCodeMirror = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
149
149
  view: view
150
150
  };
151
151
  }, [editor, container, state, view]);
152
+ var setEditorRef = (0, _react.useCallback)(function (el) {
153
+ editor.current = el;
154
+ setContainer(el);
155
+ }, [setContainer]);
152
156
 
153
157
  // check type of value
154
158
  if (typeof value !== 'string') {
@@ -156,7 +160,7 @@ var ReactCodeMirror = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
156
160
  }
157
161
  var defaultClassNames = typeof theme === 'string' ? "cm-theme-".concat(theme) : 'cm-theme';
158
162
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({
159
- ref: editor,
163
+ ref: setEditorRef,
160
164
  className: "".concat(defaultClassNames).concat(className ? " ".concat(className) : '')
161
165
  }, other));
162
166
  });
@@ -101,7 +101,7 @@ function useCodeMirror(props) {
101
101
  getExtensions.push(_view.EditorView.updateListener.of(onUpdate));
102
102
  }
103
103
  getExtensions = getExtensions.concat(extensions);
104
- (0, _react.useEffect)(function () {
104
+ (0, _react.useLayoutEffect)(function () {
105
105
  if (container && !state) {
106
106
  var config = {
107
107
  doc: value,
@@ -128,7 +128,9 @@ function useCodeMirror(props) {
128
128
  };
129
129
  }, [container, state]);
130
130
  (0, _react.useEffect)(function () {
131
- return setContainer(props.container);
131
+ if (props.container) {
132
+ setContainer(props.container);
133
+ }
132
134
  }, [props.container]);
133
135
  (0, _react.useEffect)(function () {
134
136
  return function () {