@uiw/react-codemirror 4.3.3 → 4.4.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.
@@ -0,0 +1,14 @@
1
+ /*
2
+ object-assign
3
+ (c) Sindre Sorhus
4
+ @license MIT
5
+ */
6
+
7
+ /** @license React v17.0.2
8
+ * react-jsx-runtime.production.min.js
9
+ *
10
+ * Copyright (c) Facebook, Inc. and its affiliates.
11
+ *
12
+ * This source code is licensed under the MIT license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-codemirror",
3
- "version": "4.3.3",
3
+ "version": "4.4.0",
4
4
  "description": "CodeMirror component for React.",
5
5
  "homepage": "https://uiwjs.github.io/react-codemirror",
6
6
  "main": "cjs/index.js",
@@ -13,6 +13,8 @@
13
13
  "prepare": "husky install && npm run build",
14
14
  "watch": "tsbb watch",
15
15
  "build": "tsbb build",
16
+ "bundle": "kkt build --bundle",
17
+ "bundle:min": "kkt build --bundle --mini --no-emptyDir",
16
18
  "test": "tsbb test --env=jsdom",
17
19
  "coverage": "tsbb test --coverage --bail",
18
20
  "doc": "kkt build --app-src ./website",
@@ -34,6 +36,7 @@
34
36
  "code"
35
37
  ],
36
38
  "files": [
39
+ "dist",
37
40
  "src",
38
41
  "esm",
39
42
  "cjs"
@@ -52,11 +55,6 @@
52
55
  "react-app/jest"
53
56
  ]
54
57
  },
55
- "lint-staged": {
56
- "*.{js,jsx,ts,tsx,html,less,md,json}": [
57
- "prettier --write"
58
- ]
59
- },
60
58
  "peerDependencies": {
61
59
  "@babel/runtime": ">=7.11.0",
62
60
  "react": ">=16.8.0",
@@ -73,20 +71,21 @@
73
71
  "@codemirror/lang-cpp": "0.19.1",
74
72
  "@codemirror/lang-html": "0.19.4",
75
73
  "@codemirror/lang-java": "0.19.1",
76
- "@codemirror/lang-javascript": "0.19.4",
74
+ "@codemirror/lang-javascript": "0.19.7",
77
75
  "@codemirror/lang-json": "0.19.1",
78
76
  "@codemirror/lang-lezer": "0.19.1",
79
- "@codemirror/lang-markdown": "0.19.4",
77
+ "@codemirror/lang-markdown": "0.19.6",
80
78
  "@codemirror/lang-php": "0.19.1",
81
- "@codemirror/lang-python": "0.19.2",
79
+ "@codemirror/lang-python": "0.19.4",
82
80
  "@codemirror/lang-rust": "0.19.1",
83
81
  "@codemirror/lang-sql": "0.19.4",
84
82
  "@codemirror/lang-xml": "0.19.2",
85
83
  "@codemirror/legacy-modes": "0.19.0",
86
- "@codemirror/stream-parser": "0.19.3",
87
- "@kkt/less-modules": "7.0.5",
88
- "@kkt/raw-modules": "7.0.5",
89
- "@kkt/scope-plugin-options": "7.0.5",
84
+ "@codemirror/stream-parser": "0.19.5",
85
+ "@kkt/less-modules": "7.1.0",
86
+ "@kkt/raw-modules": "7.1.0",
87
+ "@kkt/react-library": "7.1.0",
88
+ "@kkt/scope-plugin-options": "7.1.0",
90
89
  "@types/react": "17.0.38",
91
90
  "@types/react-dom": "17.0.11",
92
91
  "@types/react-test-renderer": "17.0.1",
@@ -96,13 +95,13 @@
96
95
  "@uiw/reset.css": "1.0.5",
97
96
  "code-example": "3.3.1",
98
97
  "husky": "7.0.4",
99
- "kkt": "7.0.5",
100
- "lint-staged": "12.1.7",
98
+ "kkt": "7.1.0",
99
+ "lint-staged": "12.3.4",
101
100
  "prettier": "2.5.1",
102
101
  "react": "17.0.2",
103
102
  "react-dom": "17.0.2",
104
103
  "react-test-renderer": "17.0.2",
105
- "tsbb": "3.5.4"
104
+ "tsbb": "3.5.6"
106
105
  },
107
106
  "browserslist": {
108
107
  "production": [
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ /* eslint-disable jest/no-conditional-expect */
5
+ import React, { useEffect, useRef } from 'react';
6
+ import renderer from 'react-test-renderer';
7
+ import { render, fireEvent, screen } from '@testing-library/react';
8
+ // import userEvent from '@testing-library/user-event';
9
+ // import '@testing-library/jest-dom';
10
+ import CodeMirror, { ReactCodeMirrorRef } from '..';
11
+
12
+ it('CodeMirror', async () => {
13
+ const component = renderer.create(<CodeMirror />);
14
+ let tree = component.toJSON();
15
+ if (tree && !Array.isArray(tree)) {
16
+ expect(tree.type).toEqual('div');
17
+ expect(tree.props.className).toEqual('cm-theme-light');
18
+ }
19
+ });
20
+
21
+ it('CodeMirror onChange', async () => {
22
+ const handleChange = jest.fn((value) => {
23
+ expect(value).toEqual('# title');
24
+ return Array.isArray(value) ? value.join() : value;
25
+ });
26
+ render(<CodeMirror autoFocus value="console.log('Hello world!')" onChange={handleChange} />);
27
+ const input = await screen.findByRole<HTMLInputElement>('textbox'); // findByRole('textbox');
28
+ fireEvent.change(input, { target: { textContent: '# title' } });
29
+ const elm = screen.queryByText('# title');
30
+ expect((elm as any).cmView.dom.innerHTML).toEqual('# title');
31
+ });
32
+
33
+ it('CodeMirror onUpdate', async () => {
34
+ render(
35
+ <CodeMirror
36
+ value="console.log('Hello world!')"
37
+ autoFocus
38
+ onUpdate={(viewUpdate) => {
39
+ expect(viewUpdate.state.doc.length).toEqual(27);
40
+ }}
41
+ />,
42
+ );
43
+ });
44
+
45
+ it('CodeMirror ref', async () => {
46
+ function Demo() {
47
+ const ref = useRef<ReactCodeMirrorRef>(null);
48
+ useEffect(() => {
49
+ expect(Object.keys(ref.current!)).toEqual(['editor', 'state', 'view']);
50
+ }, [ref]);
51
+
52
+ return <CodeMirror ref={ref} value="console.log('Hello world!')" />;
53
+ }
54
+ render(<Demo />);
55
+ });
56
+
57
+ it('CodeMirror theme', async () => {
58
+ const component = renderer.create(<CodeMirror theme="dark" />);
59
+ let tree = component.toJSON();
60
+ if (tree && !Array.isArray(tree)) {
61
+ expect(tree.type).toEqual('div');
62
+ expect(tree.props.className).toEqual('cm-theme-dark');
63
+ }
64
+ });
65
+
66
+ it('CodeMirror className', async () => {
67
+ const component = renderer.create(<CodeMirror className="test" />);
68
+ let tree = component.toJSON();
69
+ if (tree && !Array.isArray(tree)) {
70
+ expect(tree.type).toEqual('div');
71
+ expect(tree.props.className).toEqual('cm-theme-light test');
72
+ }
73
+ });
74
+
75
+ it('CodeMirror placeholder', async () => {
76
+ render(<CodeMirror placeholder="Hello World" className="test" />);
77
+ const elm = screen.queryByText('Hello World');
78
+ expect(elm!.style['pointerEvents']).toEqual('none');
79
+ expect(elm!.className).toEqual('cm-placeholder');
80
+ });
81
+
82
+ it('CodeMirror editable', async () => {
83
+ render(<CodeMirror editable={false} className="test" />);
84
+ const text = screen.getByRole('textbox');
85
+ expect(text.className).toEqual('cm-content');
86
+ expect(text.tagName).toEqual('DIV');
87
+ });