@uiw/react-codemirror 4.12.4 → 4.13.1
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/README.md +1 -0
- package/cjs/index.js +56 -71
- package/cjs/index.js.map +1 -1
- package/cjs/theme/light.js +0 -3
- package/cjs/theme/light.js.map +1 -1
- package/cjs/useCodeMirror.js +45 -78
- package/cjs/useCodeMirror.js.map +1 -1
- package/cjs/utils.js +0 -2
- package/cjs/utils.js.map +1 -1
- package/dist/mdeditor.js +89 -85
- package/dist/mdeditor.min.js +1 -1
- package/esm/index.js +27 -28
- package/esm/index.js.map +1 -1
- package/esm/theme/light.js.map +1 -1
- package/esm/useCodeMirror.js +2 -18
- package/esm/useCodeMirror.js.map +1 -1
- package/esm/utils.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ npm install @uiw/react-codemirror --save
|
|
|
62
62
|
| `@uiw/codemirror-theme-darcula` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-darcula) [](https://www.npmjs.com/package/@uiw/codemirror-theme-darcula) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/darcula) |
|
|
63
63
|
| `@uiw/codemirror-theme-eclipse` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-eclipse) [](https://www.npmjs.com/package/@uiw/codemirror-theme-eclipse) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/eclipse) |
|
|
64
64
|
| `@uiw/codemirror-theme-github` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-github) [](https://www.npmjs.com/package/@uiw/codemirror-theme-github) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/github) |
|
|
65
|
+
| `@uiw/codemirror-theme-gruvbox-dark` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-gruvbox-dark) [](https://www.npmjs.com/package/@uiw/codemirror-theme-gruvbox-dark) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/gruvbox/dark) |
|
|
65
66
|
| `@uiw/codemirror-theme-okaidia` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-okaidia) [](https://www.npmjs.com/package/@uiw/codemirror-theme-okaidia) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/okaidia) |
|
|
66
67
|
| `@uiw/codemirror-theme-sublime` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-sublime) [](https://www.npmjs.com/package/@uiw/codemirror-theme-sublime) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/sublime) |
|
|
67
68
|
|
package/cjs/index.js
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
-
|
|
5
4
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
var _exportNames = {};
|
|
11
9
|
exports["default"] = void 0;
|
|
12
|
-
|
|
13
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
14
|
-
|
|
15
11
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
16
|
-
|
|
17
12
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
18
|
-
|
|
19
13
|
var _react = _interopRequireWildcard(require("react"));
|
|
20
|
-
|
|
21
14
|
var _useCodeMirror2 = require("./useCodeMirror");
|
|
22
|
-
|
|
23
15
|
Object.keys(_useCodeMirror2).forEach(function (key) {
|
|
24
16
|
if (key === "default" || key === "__esModule") return;
|
|
25
17
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -31,11 +23,8 @@ Object.keys(_useCodeMirror2).forEach(function (key) {
|
|
|
31
23
|
}
|
|
32
24
|
});
|
|
33
25
|
});
|
|
34
|
-
|
|
35
26
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
36
|
-
|
|
37
27
|
var _codemirrorExtensionsBasicSetup = require("@uiw/codemirror-extensions-basic-setup");
|
|
38
|
-
|
|
39
28
|
Object.keys(_codemirrorExtensionsBasicSetup).forEach(function (key) {
|
|
40
29
|
if (key === "default" || key === "__esModule") return;
|
|
41
30
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -47,9 +36,7 @@ Object.keys(_codemirrorExtensionsBasicSetup).forEach(function (key) {
|
|
|
47
36
|
}
|
|
48
37
|
});
|
|
49
38
|
});
|
|
50
|
-
|
|
51
39
|
var _utils = require("./utils");
|
|
52
|
-
|
|
53
40
|
Object.keys(_utils).forEach(function (key) {
|
|
54
41
|
if (key === "default" || key === "__esModule") return;
|
|
55
42
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -64,76 +51,74 @@ Object.keys(_utils).forEach(function (key) {
|
|
|
64
51
|
var _excluded = ["className", "value", "selection", "extensions", "onChange", "onStatistics", "onCreateEditor", "onUpdate", "autoFocus", "theme", "height", "minHeight", "maxHeight", "width", "minWidth", "maxWidth", "basicSetup", "placeholder", "indentWithTab", "editable", "readOnly", "root", "initialState"];
|
|
65
52
|
var ReactCodeMirror = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
66
53
|
var className = props.className,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
54
|
+
_props$value = props.value,
|
|
55
|
+
value = _props$value === void 0 ? '' : _props$value,
|
|
56
|
+
selection = props.selection,
|
|
57
|
+
_props$extensions = props.extensions,
|
|
58
|
+
extensions = _props$extensions === void 0 ? [] : _props$extensions,
|
|
59
|
+
onChange = props.onChange,
|
|
60
|
+
onStatistics = props.onStatistics,
|
|
61
|
+
onCreateEditor = props.onCreateEditor,
|
|
62
|
+
onUpdate = props.onUpdate,
|
|
63
|
+
autoFocus = props.autoFocus,
|
|
64
|
+
_props$theme = props.theme,
|
|
65
|
+
theme = _props$theme === void 0 ? 'light' : _props$theme,
|
|
66
|
+
height = props.height,
|
|
67
|
+
minHeight = props.minHeight,
|
|
68
|
+
maxHeight = props.maxHeight,
|
|
69
|
+
width = props.width,
|
|
70
|
+
minWidth = props.minWidth,
|
|
71
|
+
maxWidth = props.maxWidth,
|
|
72
|
+
basicSetup = props.basicSetup,
|
|
73
|
+
placeholder = props.placeholder,
|
|
74
|
+
indentWithTab = props.indentWithTab,
|
|
75
|
+
editable = props.editable,
|
|
76
|
+
readOnly = props.readOnly,
|
|
77
|
+
root = props.root,
|
|
78
|
+
initialState = props.initialState,
|
|
79
|
+
other = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
93
80
|
var editor = (0, _react.useRef)(null);
|
|
94
|
-
|
|
95
81
|
var _useCodeMirror = (0, _useCodeMirror2.useCodeMirror)({
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
82
|
+
container: editor.current,
|
|
83
|
+
root: root,
|
|
84
|
+
value: value,
|
|
85
|
+
autoFocus: autoFocus,
|
|
86
|
+
theme: theme,
|
|
87
|
+
height: height,
|
|
88
|
+
minHeight: minHeight,
|
|
89
|
+
maxHeight: maxHeight,
|
|
90
|
+
width: width,
|
|
91
|
+
minWidth: minWidth,
|
|
92
|
+
maxWidth: maxWidth,
|
|
93
|
+
basicSetup: basicSetup,
|
|
94
|
+
placeholder: placeholder,
|
|
95
|
+
indentWithTab: indentWithTab,
|
|
96
|
+
editable: editable,
|
|
97
|
+
readOnly: readOnly,
|
|
98
|
+
selection: selection,
|
|
99
|
+
onChange: onChange,
|
|
100
|
+
onStatistics: onStatistics,
|
|
101
|
+
onCreateEditor: onCreateEditor,
|
|
102
|
+
onUpdate: onUpdate,
|
|
103
|
+
extensions: extensions,
|
|
104
|
+
initialState: initialState
|
|
105
|
+
}),
|
|
106
|
+
state = _useCodeMirror.state,
|
|
107
|
+
view = _useCodeMirror.view,
|
|
108
|
+
container = _useCodeMirror.container,
|
|
109
|
+
setContainer = _useCodeMirror.setContainer;
|
|
125
110
|
(0, _react.useImperativeHandle)(ref, function () {
|
|
126
111
|
return {
|
|
127
112
|
editor: editor.current,
|
|
128
113
|
state: state,
|
|
129
114
|
view: view
|
|
130
115
|
};
|
|
131
|
-
}, [editor, container, state, view]);
|
|
116
|
+
}, [editor, container, state, view]);
|
|
132
117
|
|
|
118
|
+
// check type of value
|
|
133
119
|
if (typeof value !== 'string') {
|
|
134
120
|
throw new Error("value must be typeof string but got ".concat((0, _typeof2["default"])(value)));
|
|
135
121
|
}
|
|
136
|
-
|
|
137
122
|
var defaultClassNames = typeof theme === 'string' ? "cm-theme-".concat(theme) : 'cm-theme';
|
|
138
123
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({
|
|
139
124
|
ref: editor,
|
package/cjs/index.js.map
CHANGED
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"sourcesContent": [
|
|
49
49
|
"import React, { useRef, forwardRef, useImperativeHandle } from 'react';\nimport { EditorState, EditorStateConfig, Extension, StateField } from '@codemirror/state';\nimport { EditorView, ViewUpdate } from '@codemirror/view';\nimport { BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';\nimport { useCodeMirror } from './useCodeMirror';\nimport { Statistics } from './utils';\n\nexport * from '@uiw/codemirror-extensions-basic-setup';\nexport * from './useCodeMirror';\nexport * from './utils';\n\nexport interface ReactCodeMirrorProps\n extends Omit<EditorStateConfig, 'doc' | 'extensions'>,\n Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'placeholder'> {\n /** value of the auto created model in the editor. */\n value?: string;\n height?: string;\n minHeight?: string;\n maxHeight?: string;\n width?: string;\n minWidth?: string;\n maxWidth?: string;\n /** focus on the editor. */\n autoFocus?: boolean;\n /** Enables a placeholder—a piece of example content to show when the editor is empty. */\n placeholder?: string | HTMLElement;\n /**\n * `light` / `dark` / `Extension` Defaults to `light`.\n * @default light\n */\n theme?: 'light' | 'dark' | Extension;\n /**\n * Whether to optional basicSetup by default\n * @default true\n */\n basicSetup?: boolean | BasicSetupOptions;\n /**\n * This disables editing of the editor content by the user.\n * @default true\n */\n editable?: boolean;\n /**\n * This disables editing of the editor content by the user.\n * @default false\n */\n readOnly?: boolean;\n /**\n * Whether to optional basicSetup by default\n * @default true\n */\n indentWithTab?: boolean;\n /** Fired whenever a change occurs to the document. */\n onChange?(value: string, viewUpdate: ViewUpdate): void;\n /** Some data on the statistics editor. */\n onStatistics?(data: Statistics): void;\n /** Fired whenever any state change occurs within the editor, including non-document changes like lint results. */\n onUpdate?(viewUpdate: ViewUpdate): void;\n /** The first time the editor executes the event. */\n onCreateEditor?(view: EditorView, state: EditorState): void;\n /**\n * Extension values can be [provided](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions) when creating a state to attach various kinds of configuration and behavior information.\n * They can either be built-in extension-providing objects,\n * such as [state fields](https://codemirror.net/6/docs/ref/#state.StateField) or [facet providers](https://codemirror.net/6/docs/ref/#state.Facet.of),\n * or objects with an extension in its `extension` property. Extensions can be nested in arrays arbitrarily deep—they will be flattened when processed.\n */\n extensions?: Extension[];\n /**\n * If the view is going to be mounted in a shadow root or document other than the one held by the global variable document (the default), you should pass it here.\n * Originally from the [config of EditorView](https://codemirror.net/6/docs/ref/#view.EditorView.constructor%5Econfig.root)\n */\n root?: ShadowRoot | Document;\n /**\n * Create a state from its JSON representation serialized with [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) function\n */\n initialState?: {\n json: any;\n fields?: Record<string, StateField<any>>;\n };\n}\n\nexport interface ReactCodeMirrorRef {\n editor?: HTMLDivElement | null;\n state?: EditorState;\n view?: EditorView;\n}\n\nconst ReactCodeMirror = forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProps>((props, ref) => {\n const {\n className,\n value = '',\n selection,\n extensions = [],\n onChange,\n onStatistics,\n onCreateEditor,\n onUpdate,\n autoFocus,\n theme = 'light',\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n basicSetup,\n placeholder,\n indentWithTab,\n editable,\n readOnly,\n root,\n initialState,\n ...other\n } = props;\n const editor = useRef<HTMLDivElement>(null);\n const { state, view, container, setContainer } = useCodeMirror({\n container: editor.current,\n root,\n value,\n autoFocus,\n theme,\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n basicSetup,\n placeholder,\n indentWithTab,\n editable,\n readOnly,\n selection,\n onChange,\n onStatistics,\n onCreateEditor,\n onUpdate,\n extensions,\n initialState,\n });\n\n useImperativeHandle(ref, () => ({ editor: editor.current, state: state, view: view }), [\n editor,\n container,\n state,\n view,\n ]);\n\n // check type of value\n if (typeof value !== 'string') {\n throw new Error(`value must be typeof string but got ${typeof value}`);\n }\n\n const defaultClassNames = typeof theme === 'string' ? `cm-theme-${theme}` : 'cm-theme';\n return <div ref={editor} className={`${defaultClassNames}${className ? ` ${className}` : ''}`} {...other}></div>;\n});\n\nReactCodeMirror.displayName = 'CodeMirror';\n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K,EACLC,IAAI,CACL,CAAC;;EAEF;EACA,IAAI,OAAO7B,KAAK,KAAK,QAAQ,EAAE;IAC7B,MAAM,IAAIgC,KAAK,wEAA+ChC,KAAK,GAAG;EACxE;EAEA,IAAMiC,iBAAiB,GAAG,OAAOzB,KAAK,KAAK,QAAQ,sBAAeA,KAAK,IAAK,UAAU;EACtF,oBAAO;IAAK,GAAG,EAAEe,MAAO;IAAC,SAAS,YAAKU,iBAAiB,SAAGlC,SAAS,cAAOA,SAAS,IAAK,EAAE;EAAG,GAAKuB,KAAK,EAAQ;AAClH,CAAC,CAAC;AAEF3B,eAAe,CAACuC,WAAW,GAAG,YAAY;AAAC,eAE5BvC,eAAe;AAAA"
|
|
52
52
|
}
|
package/cjs/theme/light.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.defaultLightThemeOption = void 0;
|
|
7
|
-
|
|
8
7
|
var _view = require("@codemirror/view");
|
|
9
|
-
|
|
10
8
|
var defaultLightThemeOption = _view.EditorView.theme({
|
|
11
9
|
'&': {
|
|
12
10
|
backgroundColor: '#fff'
|
|
@@ -14,6 +12,5 @@ var defaultLightThemeOption = _view.EditorView.theme({
|
|
|
14
12
|
}, {
|
|
15
13
|
dark: false
|
|
16
14
|
});
|
|
17
|
-
|
|
18
15
|
exports.defaultLightThemeOption = defaultLightThemeOption;
|
|
19
16
|
//# sourceMappingURL=light.js.map
|
package/cjs/theme/light.js.map
CHANGED
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
"sourcesContent": [
|
|
14
14
|
"import { EditorView } from '@codemirror/view';\n\nexport const defaultLightThemeOption = EditorView.theme(\n {\n '&': {\n backgroundColor: '#fff',\n },\n },\n {\n dark: false,\n },\n);\n"
|
|
15
15
|
],
|
|
16
|
-
"mappings": "
|
|
16
|
+
"mappings": ";;;;;;AAAA;AAEO,IAAMA,uBAAuB,GAAGC,gBAAU,CAACC,KAAK,CACrD;EACE,GAAG,EAAE;IACHC,eAAe,EAAE;EACnB;AACF,CAAC,EACD;EACEC,IAAI,EAAE;AACR,CAAC,CACF;AAAC"
|
|
17
17
|
}
|
package/cjs/useCodeMirror.js
CHANGED
|
@@ -1,80 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.useCodeMirror = useCodeMirror;
|
|
9
|
-
|
|
10
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
-
|
|
12
9
|
var _react = require("react");
|
|
13
|
-
|
|
14
10
|
var _state = require("@codemirror/state");
|
|
15
|
-
|
|
16
11
|
var _commands = require("@codemirror/commands");
|
|
17
|
-
|
|
18
12
|
var _view = require("@codemirror/view");
|
|
19
|
-
|
|
20
13
|
var _codemirrorExtensionsBasicSetup = require("@uiw/codemirror-extensions-basic-setup");
|
|
21
|
-
|
|
22
14
|
var _themeOneDark = require("@codemirror/theme-one-dark");
|
|
23
|
-
|
|
24
15
|
var _utils = require("./utils");
|
|
25
|
-
|
|
26
16
|
function useCodeMirror(props) {
|
|
27
17
|
var value = props.value,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
18
|
+
selection = props.selection,
|
|
19
|
+
onChange = props.onChange,
|
|
20
|
+
onStatistics = props.onStatistics,
|
|
21
|
+
onCreateEditor = props.onCreateEditor,
|
|
22
|
+
onUpdate = props.onUpdate,
|
|
23
|
+
_props$extensions = props.extensions,
|
|
24
|
+
extensions = _props$extensions === void 0 ? [] : _props$extensions,
|
|
25
|
+
autoFocus = props.autoFocus,
|
|
26
|
+
_props$theme = props.theme,
|
|
27
|
+
theme = _props$theme === void 0 ? 'light' : _props$theme,
|
|
28
|
+
_props$height = props.height,
|
|
29
|
+
height = _props$height === void 0 ? '' : _props$height,
|
|
30
|
+
_props$minHeight = props.minHeight,
|
|
31
|
+
minHeight = _props$minHeight === void 0 ? '' : _props$minHeight,
|
|
32
|
+
_props$maxHeight = props.maxHeight,
|
|
33
|
+
maxHeight = _props$maxHeight === void 0 ? '' : _props$maxHeight,
|
|
34
|
+
_props$placeholder = props.placeholder,
|
|
35
|
+
placeholderStr = _props$placeholder === void 0 ? '' : _props$placeholder,
|
|
36
|
+
_props$width = props.width,
|
|
37
|
+
width = _props$width === void 0 ? '' : _props$width,
|
|
38
|
+
_props$minWidth = props.minWidth,
|
|
39
|
+
minWidth = _props$minWidth === void 0 ? '' : _props$minWidth,
|
|
40
|
+
_props$maxWidth = props.maxWidth,
|
|
41
|
+
maxWidth = _props$maxWidth === void 0 ? '' : _props$maxWidth,
|
|
42
|
+
_props$editable = props.editable,
|
|
43
|
+
editable = _props$editable === void 0 ? true : _props$editable,
|
|
44
|
+
_props$readOnly = props.readOnly,
|
|
45
|
+
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
|
|
46
|
+
_props$indentWithTab = props.indentWithTab,
|
|
47
|
+
defaultIndentWithTab = _props$indentWithTab === void 0 ? true : _props$indentWithTab,
|
|
48
|
+
_props$basicSetup = props.basicSetup,
|
|
49
|
+
defaultBasicSetup = _props$basicSetup === void 0 ? true : _props$basicSetup,
|
|
50
|
+
root = props.root,
|
|
51
|
+
initialState = props.initialState;
|
|
63
52
|
var _useState = (0, _react.useState)(),
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
53
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
54
|
+
container = _useState2[0],
|
|
55
|
+
setContainer = _useState2[1];
|
|
68
56
|
var _useState3 = (0, _react.useState)(),
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
57
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
58
|
+
view = _useState4[0],
|
|
59
|
+
setView = _useState4[1];
|
|
73
60
|
var _useState5 = (0, _react.useState)(),
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
61
|
+
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
|
62
|
+
state = _useState6[0],
|
|
63
|
+
setState = _useState6[1];
|
|
78
64
|
var defaultLightThemeOption = _view.EditorView.theme({
|
|
79
65
|
'&': {
|
|
80
66
|
backgroundColor: '#fff'
|
|
@@ -82,7 +68,6 @@ function useCodeMirror(props) {
|
|
|
82
68
|
}, {
|
|
83
69
|
dark: false
|
|
84
70
|
});
|
|
85
|
-
|
|
86
71
|
var defaultThemeOption = _view.EditorView.theme({
|
|
87
72
|
'&': {
|
|
88
73
|
height: height,
|
|
@@ -93,25 +78,18 @@ function useCodeMirror(props) {
|
|
|
93
78
|
maxWidth: maxWidth
|
|
94
79
|
}
|
|
95
80
|
});
|
|
96
|
-
|
|
97
81
|
var updateListener = _view.EditorView.updateListener.of(function (vu) {
|
|
98
82
|
if (vu.docChanged && typeof onChange === 'function') {
|
|
99
83
|
var doc = vu.state.doc;
|
|
100
|
-
|
|
101
84
|
var _value = doc.toString();
|
|
102
|
-
|
|
103
85
|
onChange(_value, vu);
|
|
104
86
|
}
|
|
105
|
-
|
|
106
87
|
onStatistics && onStatistics((0, _utils.getStatistics)(vu));
|
|
107
88
|
});
|
|
108
|
-
|
|
109
89
|
var getExtensions = [updateListener, defaultThemeOption];
|
|
110
|
-
|
|
111
90
|
if (defaultIndentWithTab) {
|
|
112
91
|
getExtensions.unshift(_view.keymap.of([_commands.indentWithTab]));
|
|
113
92
|
}
|
|
114
|
-
|
|
115
93
|
if (defaultBasicSetup) {
|
|
116
94
|
if (typeof defaultBasicSetup === 'boolean') {
|
|
117
95
|
getExtensions.unshift((0, _codemirrorExtensionsBasicSetup.basicSetup)());
|
|
@@ -119,37 +97,29 @@ function useCodeMirror(props) {
|
|
|
119
97
|
getExtensions.unshift((0, _codemirrorExtensionsBasicSetup.basicSetup)(defaultBasicSetup));
|
|
120
98
|
}
|
|
121
99
|
}
|
|
122
|
-
|
|
123
100
|
if (placeholderStr) {
|
|
124
101
|
getExtensions.unshift((0, _view.placeholder)(placeholderStr));
|
|
125
102
|
}
|
|
126
|
-
|
|
127
103
|
switch (theme) {
|
|
128
104
|
case 'light':
|
|
129
105
|
getExtensions.push(defaultLightThemeOption);
|
|
130
106
|
break;
|
|
131
|
-
|
|
132
107
|
case 'dark':
|
|
133
108
|
getExtensions.push(_themeOneDark.oneDark);
|
|
134
109
|
break;
|
|
135
|
-
|
|
136
110
|
default:
|
|
137
111
|
getExtensions.push(theme);
|
|
138
112
|
break;
|
|
139
113
|
}
|
|
140
|
-
|
|
141
114
|
if (editable === false) {
|
|
142
115
|
getExtensions.push(_view.EditorView.editable.of(false));
|
|
143
116
|
}
|
|
144
|
-
|
|
145
117
|
if (readOnly) {
|
|
146
118
|
getExtensions.push(_state.EditorState.readOnly.of(true));
|
|
147
119
|
}
|
|
148
|
-
|
|
149
120
|
if (onUpdate && typeof onUpdate === 'function') {
|
|
150
121
|
getExtensions.push(_view.EditorView.updateListener.of(onUpdate));
|
|
151
122
|
}
|
|
152
|
-
|
|
153
123
|
getExtensions = getExtensions.concat(extensions);
|
|
154
124
|
(0, _react.useEffect)(function () {
|
|
155
125
|
if (container && !state) {
|
|
@@ -160,7 +130,6 @@ function useCodeMirror(props) {
|
|
|
160
130
|
};
|
|
161
131
|
var stateCurrent = initialState ? _state.EditorState.fromJSON(initialState.json, config, initialState.fields) : _state.EditorState.create(config);
|
|
162
132
|
setState(stateCurrent);
|
|
163
|
-
|
|
164
133
|
if (!view) {
|
|
165
134
|
var viewCurrent = new _view.EditorView({
|
|
166
135
|
state: stateCurrent,
|
|
@@ -171,7 +140,6 @@ function useCodeMirror(props) {
|
|
|
171
140
|
onCreateEditor && onCreateEditor(viewCurrent, stateCurrent);
|
|
172
141
|
}
|
|
173
142
|
}
|
|
174
|
-
|
|
175
143
|
return function () {
|
|
176
144
|
if (view) {
|
|
177
145
|
setState(undefined);
|
|
@@ -200,12 +168,11 @@ function useCodeMirror(props) {
|
|
|
200
168
|
view.dispatch({
|
|
201
169
|
effects: _state.StateEffect.reconfigure.of(getExtensions)
|
|
202
170
|
});
|
|
203
|
-
}
|
|
204
|
-
|
|
171
|
+
}
|
|
172
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
205
173
|
}, [theme, extensions, height, minHeight, maxHeight, width, minWidth, maxWidth, placeholderStr, editable, readOnly, defaultIndentWithTab, defaultBasicSetup, onChange, onUpdate]);
|
|
206
174
|
(0, _react.useEffect)(function () {
|
|
207
175
|
var currentValue = view ? view.state.doc.toString() : '';
|
|
208
|
-
|
|
209
176
|
if (view && value !== currentValue) {
|
|
210
177
|
view.dispatch({
|
|
211
178
|
changes: {
|
package/cjs/useCodeMirror.js.map
CHANGED
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"sourcesContent": [
|
|
84
84
|
"import { useEffect, useState } from 'react';\nimport { EditorState, StateEffect } from '@codemirror/state';\nimport { indentWithTab } from '@codemirror/commands';\nimport { EditorView, keymap, ViewUpdate, placeholder } from '@codemirror/view';\nimport { basicSetup } from '@uiw/codemirror-extensions-basic-setup';\nimport { oneDark } from '@codemirror/theme-one-dark';\nimport { getStatistics } from './utils';\nimport { ReactCodeMirrorProps } from '.';\n\nexport interface UseCodeMirror extends ReactCodeMirrorProps {\n container?: HTMLDivElement | null;\n}\n\nexport function useCodeMirror(props: UseCodeMirror) {\n const {\n value,\n selection,\n onChange,\n onStatistics,\n onCreateEditor,\n onUpdate,\n extensions = [],\n autoFocus,\n theme = 'light',\n height = '',\n minHeight = '',\n maxHeight = '',\n placeholder: placeholderStr = '',\n width = '',\n minWidth = '',\n maxWidth = '',\n editable = true,\n readOnly = false,\n indentWithTab: defaultIndentWithTab = true,\n basicSetup: defaultBasicSetup = true,\n root,\n initialState,\n } = props;\n const [container, setContainer] = useState<HTMLDivElement>();\n const [view, setView] = useState<EditorView>();\n const [state, setState] = useState<EditorState>();\n const defaultLightThemeOption = EditorView.theme(\n {\n '&': {\n backgroundColor: '#fff',\n },\n },\n {\n dark: false,\n },\n );\n const defaultThemeOption = EditorView.theme({\n '&': {\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n },\n });\n const updateListener = EditorView.updateListener.of((vu: ViewUpdate) => {\n if (vu.docChanged && typeof onChange === 'function') {\n const doc = vu.state.doc;\n const value = doc.toString();\n onChange(value, vu);\n }\n onStatistics && onStatistics(getStatistics(vu));\n });\n\n let getExtensions = [updateListener, defaultThemeOption];\n if (defaultIndentWithTab) {\n getExtensions.unshift(keymap.of([indentWithTab]));\n }\n if (defaultBasicSetup) {\n if (typeof defaultBasicSetup === 'boolean') {\n getExtensions.unshift(basicSetup());\n } else {\n getExtensions.unshift(basicSetup(defaultBasicSetup));\n }\n }\n\n if (placeholderStr) {\n getExtensions.unshift(placeholder(placeholderStr));\n }\n\n switch (theme) {\n case 'light':\n getExtensions.push(defaultLightThemeOption);\n break;\n case 'dark':\n getExtensions.push(oneDark);\n break;\n default:\n getExtensions.push(theme);\n break;\n }\n\n if (editable === false) {\n getExtensions.push(EditorView.editable.of(false));\n }\n if (readOnly) {\n getExtensions.push(EditorState.readOnly.of(true));\n }\n\n if (onUpdate && typeof onUpdate === 'function') {\n getExtensions.push(EditorView.updateListener.of(onUpdate));\n }\n getExtensions = getExtensions.concat(extensions);\n\n useEffect(() => {\n if (container && !state) {\n const config = {\n doc: value,\n selection,\n extensions: getExtensions,\n };\n const stateCurrent = initialState\n ? EditorState.fromJSON(initialState.json, config, initialState.fields)\n : EditorState.create(config);\n setState(stateCurrent);\n if (!view) {\n const viewCurrent = new EditorView({\n state: stateCurrent,\n parent: container,\n root,\n });\n setView(viewCurrent);\n onCreateEditor && onCreateEditor(viewCurrent, stateCurrent);\n }\n }\n return () => {\n if (view) {\n setState(undefined);\n setView(undefined);\n }\n };\n }, [container, state]);\n\n useEffect(() => setContainer(props.container!), [props.container]);\n\n useEffect(\n () => () => {\n if (view) {\n view.destroy();\n setView(undefined);\n }\n },\n [view],\n );\n\n useEffect(() => {\n if (autoFocus && view) {\n view.focus();\n }\n }, [autoFocus, view]);\n\n useEffect(() => {\n if (view) {\n view.dispatch({ effects: StateEffect.reconfigure.of(getExtensions) });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n theme,\n extensions,\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n placeholderStr,\n editable,\n readOnly,\n defaultIndentWithTab,\n defaultBasicSetup,\n onChange,\n onUpdate,\n ]);\n\n useEffect(() => {\n const currentValue = view ? view.state.doc.toString() : '';\n if (view && value !== currentValue) {\n view.dispatch({\n changes: { from: 0, to: currentValue.length, insert: value || '' },\n });\n }\n }, [value, view]);\n\n return { state, setState, view, setView, container, setContainer };\n}\n"
|
|
85
85
|
],
|
|
86
|
-
"mappings": "
|
|
86
|
+
"mappings": ";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAOO,SAASA,aAAa,CAACC,KAAoB,EAAE;EAClD,IACEC,KAAK,GAsBHD,KAAK,CAtBPC,KAAK;IACLC,SAAS,GAqBPF,KAAK,CArBPE,SAAS;IACTC,QAAQ,GAoBNH,KAAK,CApBPG,QAAQ;IACRC,YAAY,GAmBVJ,KAAK,CAn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,EACRE,oBAAoB,EACpBE,iBAAiB,EACjBpB,QAAQ,EACRG,QAAQ,CACT,CAAC;EAEF,IAAA8C,gBAAS,EAAC,YAAM;IACd,IAAMgB,YAAY,GAAGvC,IAAI,GAAGA,IAAI,CAACE,KAAK,CAACW,GAAG,CAACC,QAAQ,EAAE,GAAG,EAAE;IAC1D,IAAId,IAAI,IAAI5B,KAAK,KAAKmE,YAAY,EAAE;MAClCvC,IAAI,CAACmC,QAAQ,CAAC;QACZK,OAAO,EAAE;UAAEC,IAAI,EAAE,CAAC;UAAEC,EAAE,EAAEH,YAAY,CAACI,MAAM;UAAEC,MAAM,EAAExE,KAAK,IAAI;QAAG;MACnE,CAAC,CAAC;IACJ;EACF,CAAC,EAAE,CAACA,KAAK,EAAE4B,IAAI,CAAC,CAAC;EAEjB,OAAO;IAAEE,KAAK,EAALA,KAAK;IAAEC,QAAQ,EAARA,QAAQ;IAAEH,IAAI,EAAJA,IAAI;IAAEC,OAAO,EAAPA,OAAO;IAAEH,SAAS,EAATA,SAAS;IAAEC,YAAY,EAAZA;EAAa,CAAC;AACpE"
|
|
87
87
|
}
|
package/cjs/utils.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getStatistics = void 0;
|
|
7
|
-
|
|
8
7
|
var getStatistics = function getStatistics(view) {
|
|
9
8
|
return {
|
|
10
9
|
line: view.state.doc.lineAt(view.state.selection.main.from),
|
|
@@ -25,6 +24,5 @@ var getStatistics = function getStatistics(view) {
|
|
|
25
24
|
})
|
|
26
25
|
};
|
|
27
26
|
};
|
|
28
|
-
|
|
29
27
|
exports.getStatistics = getStatistics;
|
|
30
28
|
//# sourceMappingURL=utils.js.map
|
package/cjs/utils.js.map
CHANGED
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"sourcesContent": [
|
|
36
36
|
"import { EditorSelection, SelectionRange, Line } from '@codemirror/state';\nimport { ViewUpdate } from '@codemirror/view';\n\nexport interface Statistics {\n /** total length of the document */\n length: number;\n /** Get the number of lines in the editor. */\n lineCount: number;\n /** Get the currently line description around the given position. */\n line: Line;\n /** Get the proper [line-break](https://codemirror.net/docs/ref/#state.EditorState^lineSeparator) string for this state. */\n lineBreak: string;\n /** Returns true when the editor is [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. */\n readOnly: boolean;\n /** The size (in columns) of a tab in the document, determined by the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. */\n tabSize: number;\n /** Cursor Position */\n selection: EditorSelection;\n /** Make sure the selection only has one range. */\n selectionAsSingle: SelectionRange;\n /** Retrieves a list of all current selections. */\n ranges: readonly SelectionRange[];\n /** Get the currently selected code. */\n selectionCode: string;\n /**\n * The length of the given array should be the same as the number of active selections.\n * Replaces the content of the selections with the strings in the array.\n */\n selections: string[];\n /** Return true if any text is selected. */\n selectedText: boolean;\n}\n\nexport const getStatistics = (view: ViewUpdate): Statistics => {\n return {\n line: view.state.doc.lineAt(view.state.selection.main.from),\n lineCount: view.state.doc.lines,\n lineBreak: view.state.lineBreak,\n length: view.state.doc.length,\n readOnly: view.state.readOnly,\n tabSize: view.state.tabSize,\n selection: view.state.selection,\n selectionAsSingle: view.state.selection.asSingle().main,\n ranges: view.state.selection.ranges,\n selectionCode: view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to),\n selections: view.state.selection.ranges.map((r) => view.state.sliceDoc(r.from, r.to)),\n selectedText: view.state.selection.ranges.some((r) => !r.empty),\n };\n};\n"
|
|
37
37
|
],
|
|
38
|
-
"mappings": "
|
|
38
|
+
"mappings": ";;;;;;AAiCO,IAAMA,aAAa,GAAG,SAAhBA,aAAa,CAAIC,IAAgB,EAAiB;EAC7D,OAAO;IACLC,IAAI,EAAED,IAAI,CAACE,KAAK,CAACC,GAAG,CAACC,MAAM,CAACJ,IAAI,CAACE,KAAK,CAACG,SAAS,CAACC,IAAI,CAACC,IAAI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