@uiw/react-codemirror 4.25.8 → 4.25.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.
@@ -10,14 +10,19 @@ export var getDefaultExtensions = function getDefaultExtensions(optios) {
10
10
  if (optios === void 0) {
11
11
  optios = {};
12
12
  }
13
- var {
14
- indentWithTab: defaultIndentWithTab = true,
15
- editable = true,
16
- readOnly = false,
17
- theme = 'light',
18
- placeholder: placeholderStr = '',
19
- basicSetup: defaultBasicSetup = true
20
- } = optios;
13
+ var _optios = optios,
14
+ _optios$indentWithTab = _optios.indentWithTab,
15
+ defaultIndentWithTab = _optios$indentWithTab === void 0 ? true : _optios$indentWithTab,
16
+ _optios$editable = _optios.editable,
17
+ editable = _optios$editable === void 0 ? true : _optios$editable,
18
+ _optios$readOnly = _optios.readOnly,
19
+ readOnly = _optios$readOnly === void 0 ? false : _optios$readOnly,
20
+ _optios$theme = _optios.theme,
21
+ theme = _optios$theme === void 0 ? 'light' : _optios$theme,
22
+ _optios$placeholder = _optios.placeholder,
23
+ placeholderStr = _optios$placeholder === void 0 ? '' : _optios$placeholder,
24
+ _optios$basicSetup = _optios.basicSetup,
25
+ defaultBasicSetup = _optios$basicSetup === void 0 ? true : _optios$basicSetup;
21
26
  var getExtensions = [];
22
27
  if (defaultIndentWithTab) {
23
28
  getExtensions.unshift(keymap.of([indentWithTab]));
package/esm/index.js CHANGED
@@ -11,17 +11,39 @@ export * from "./useCodeMirror.js";
11
11
  export * from "./getDefaultExtensions.js";
12
12
  export * from "./utils.js";
13
13
  var ReactCodeMirror = /*#__PURE__*/forwardRef((props, ref) => {
14
- var {
15
- className,
16
- value = '',
17
- selection,
18
- extensions = [],
19
- onChange,
20
- onStatistics,
21
- onCreateEditor,
22
- onUpdate,
14
+ var className = props.className,
15
+ _props$value = props.value,
16
+ value = _props$value === void 0 ? '' : _props$value,
17
+ selection = props.selection,
18
+ _props$extensions = props.extensions,
19
+ extensions = _props$extensions === void 0 ? [] : _props$extensions,
20
+ onChange = props.onChange,
21
+ onStatistics = props.onStatistics,
22
+ onCreateEditor = props.onCreateEditor,
23
+ onUpdate = props.onUpdate,
24
+ autoFocus = props.autoFocus,
25
+ _props$theme = props.theme,
26
+ theme = _props$theme === void 0 ? 'light' : _props$theme,
27
+ height = props.height,
28
+ minHeight = props.minHeight,
29
+ maxHeight = props.maxHeight,
30
+ width = props.width,
31
+ minWidth = props.minWidth,
32
+ maxWidth = props.maxWidth,
33
+ basicSetup = props.basicSetup,
34
+ placeholder = props.placeholder,
35
+ indentWithTab = props.indentWithTab,
36
+ editable = props.editable,
37
+ readOnly = props.readOnly,
38
+ root = props.root,
39
+ initialState = props.initialState,
40
+ other = _objectWithoutPropertiesLoose(props, _excluded);
41
+ var editor = useRef(null);
42
+ var _useCodeMirror = useCodeMirror({
43
+ root,
44
+ value,
23
45
  autoFocus,
24
- theme = 'light',
46
+ theme,
25
47
  height,
26
48
  minHeight,
27
49
  maxHeight,
@@ -33,40 +55,18 @@ var ReactCodeMirror = /*#__PURE__*/forwardRef((props, ref) => {
33
55
  indentWithTab,
34
56
  editable,
35
57
  readOnly,
36
- root,
58
+ selection,
59
+ onChange,
60
+ onStatistics,
61
+ onCreateEditor,
62
+ onUpdate,
63
+ extensions,
37
64
  initialState
38
- } = props,
39
- other = _objectWithoutPropertiesLoose(props, _excluded);
40
- var editor = useRef(null);
41
- var {
42
- state,
43
- view,
44
- container,
45
- setContainer
46
- } = useCodeMirror({
47
- root,
48
- value,
49
- autoFocus,
50
- theme,
51
- height,
52
- minHeight,
53
- maxHeight,
54
- width,
55
- minWidth,
56
- maxWidth,
57
- basicSetup,
58
- placeholder,
59
- indentWithTab,
60
- editable,
61
- readOnly,
62
- selection,
63
- onChange,
64
- onStatistics,
65
- onCreateEditor,
66
- onUpdate,
67
- extensions,
68
- initialState
69
- });
65
+ }),
66
+ state = _useCodeMirror.state,
67
+ view = _useCodeMirror.view,
68
+ container = _useCodeMirror.container,
69
+ setContainer = _useCodeMirror.setContainer;
70
70
  useImperativeHandle(ref, () => ({
71
71
  editor: editor.current,
72
72
  state: state,
@@ -9,33 +9,50 @@ var TYPING_TIMOUT = 200; // ms
9
9
 
10
10
  var emptyExtensions = [];
11
11
  export function useCodeMirror(props) {
12
- var {
13
- value,
14
- selection,
15
- onChange,
16
- onStatistics,
17
- onCreateEditor,
18
- onUpdate,
19
- extensions = emptyExtensions,
20
- autoFocus,
21
- theme = 'light',
22
- height = null,
23
- minHeight = null,
24
- maxHeight = null,
25
- width = null,
26
- minWidth = null,
27
- maxWidth = null,
28
- placeholder: placeholderStr = '',
29
- editable = true,
30
- readOnly = false,
31
- indentWithTab: defaultIndentWithTab = true,
32
- basicSetup: defaultBasicSetup = true,
33
- root,
34
- initialState
35
- } = props;
36
- var [container, setContainer] = useState();
37
- var [view, setView] = useState();
38
- var [state, setState] = useState();
12
+ var value = props.value,
13
+ selection = props.selection,
14
+ onChange = props.onChange,
15
+ onStatistics = props.onStatistics,
16
+ onCreateEditor = props.onCreateEditor,
17
+ onUpdate = props.onUpdate,
18
+ _props$extensions = props.extensions,
19
+ extensions = _props$extensions === void 0 ? emptyExtensions : _props$extensions,
20
+ autoFocus = props.autoFocus,
21
+ _props$theme = props.theme,
22
+ theme = _props$theme === void 0 ? 'light' : _props$theme,
23
+ _props$height = props.height,
24
+ height = _props$height === void 0 ? null : _props$height,
25
+ _props$minHeight = props.minHeight,
26
+ minHeight = _props$minHeight === void 0 ? null : _props$minHeight,
27
+ _props$maxHeight = props.maxHeight,
28
+ maxHeight = _props$maxHeight === void 0 ? null : _props$maxHeight,
29
+ _props$width = props.width,
30
+ width = _props$width === void 0 ? null : _props$width,
31
+ _props$minWidth = props.minWidth,
32
+ minWidth = _props$minWidth === void 0 ? null : _props$minWidth,
33
+ _props$maxWidth = props.maxWidth,
34
+ maxWidth = _props$maxWidth === void 0 ? null : _props$maxWidth,
35
+ _props$placeholder = props.placeholder,
36
+ placeholderStr = _props$placeholder === void 0 ? '' : _props$placeholder,
37
+ _props$editable = props.editable,
38
+ editable = _props$editable === void 0 ? true : _props$editable,
39
+ _props$readOnly = props.readOnly,
40
+ readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
41
+ _props$indentWithTab = props.indentWithTab,
42
+ defaultIndentWithTab = _props$indentWithTab === void 0 ? true : _props$indentWithTab,
43
+ _props$basicSetup = props.basicSetup,
44
+ defaultBasicSetup = _props$basicSetup === void 0 ? true : _props$basicSetup,
45
+ root = props.root,
46
+ initialState = props.initialState;
47
+ var _useState = useState(),
48
+ container = _useState[0],
49
+ setContainer = _useState[1];
50
+ var _useState2 = useState(),
51
+ view = _useState2[0],
52
+ setView = _useState2[1];
53
+ var _useState3 = useState(),
54
+ state = _useState3[0],
55
+ setState = _useState3[1];
39
56
  var typingLatch = useState(() => ({
40
57
  current: null
41
58
  }))[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-codemirror",
3
- "version": "4.25.8",
3
+ "version": "4.25.10",
4
4
  "description": "CodeMirror component for React.",
5
5
  "homepage": "https://uiwjs.github.io/react-codemirror",
6
6
  "funding": "https://jaywcjlove.github.io/#/sponsor",
@@ -47,7 +47,7 @@
47
47
  "@codemirror/commands": "^6.1.0",
48
48
  "@codemirror/state": "^6.1.1",
49
49
  "@codemirror/theme-one-dark": "^6.0.0",
50
- "@uiw/codemirror-extensions-basic-setup": "4.25.8",
50
+ "@uiw/codemirror-extensions-basic-setup": "4.25.10",
51
51
  "codemirror": "^6.0.0"
52
52
  },
53
53
  "keywords": [
@@ -6,6 +6,65 @@ import { render, fireEvent, screen } from '@testing-library/react';
6
6
  // import '@testing-library/jest-dom';
7
7
  import CodeMirror, { ReactCodeMirrorRef } from '..';
8
8
 
9
+ // Setup JSDOM mocks for CodeMirror
10
+ beforeAll(() => {
11
+ // Mock Range.getClientRects
12
+ Object.defineProperty(global.Range.prototype, 'getClientRects', {
13
+ writable: true,
14
+ value: jest.fn(() => ({
15
+ length: 1,
16
+ item: () => ({ bottom: 16, height: 16, left: 0, right: 100, top: 0, width: 100 }),
17
+ [Symbol.iterator]: function* () {
18
+ yield { bottom: 16, height: 16, left: 0, right: 100, top: 0, width: 100 };
19
+ },
20
+ })),
21
+ });
22
+
23
+ Object.defineProperty(global.Range.prototype, 'getBoundingClientRect', {
24
+ writable: true,
25
+ value: jest.fn(() => ({ bottom: 16, height: 16, left: 0, right: 100, top: 0, width: 100 })),
26
+ });
27
+
28
+ // Mock observers used by CodeMirror internals in JSDOM.
29
+ class MockIntersectionObserver {
30
+ observe = jest.fn();
31
+ unobserve = jest.fn();
32
+ disconnect = jest.fn();
33
+ takeRecords = jest.fn(() => []);
34
+ }
35
+ class MockResizeObserver {
36
+ observe = jest.fn();
37
+ unobserve = jest.fn();
38
+ disconnect = jest.fn();
39
+ }
40
+ class MockMutationObserver {
41
+ observe = jest.fn();
42
+ disconnect = jest.fn();
43
+ takeRecords = jest.fn(() => []);
44
+ }
45
+ global.IntersectionObserver = MockIntersectionObserver as unknown as typeof IntersectionObserver;
46
+ global.ResizeObserver = MockResizeObserver as unknown as typeof ResizeObserver;
47
+ global.MutationObserver = MockMutationObserver as unknown as typeof MutationObserver;
48
+ window.IntersectionObserver = global.IntersectionObserver;
49
+ window.ResizeObserver = global.ResizeObserver;
50
+ window.MutationObserver = global.MutationObserver;
51
+
52
+ // Mock element properties
53
+ Object.defineProperty(global.HTMLElement.prototype, 'clientHeight', { get: () => 100 });
54
+ Object.defineProperty(global.HTMLElement.prototype, 'clientWidth', { get: () => 500 });
55
+ Object.defineProperty(global.HTMLElement.prototype, 'offsetHeight', { get: () => 100 });
56
+ Object.defineProperty(global.HTMLElement.prototype, 'offsetWidth', { get: () => 500 });
57
+ Object.defineProperty(global.Element.prototype, 'scrollIntoView', { writable: true, value: jest.fn() });
58
+
59
+ // Suppress CodeMirror JSDOM warnings
60
+ const originalError = console.error;
61
+ console.error = (...args) => {
62
+ if (args[0]?.toString?.().includes('getClientRects') || args[0]?.toString?.().includes('observe is not a function'))
63
+ return;
64
+ originalError.apply(console, args);
65
+ };
66
+ });
67
+
9
68
  it('CodeMirror', async () => {
10
69
  const component = renderer.create(<CodeMirror />);
11
70
  let tree = component.toJSON();