@uiw/react-codemirror 4.19.10 → 4.19.12
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 +30 -1
- package/cjs/.kktrc.d.ts +3 -0
- package/cjs/getDefaultExtensions.d.ts +11 -0
- package/cjs/getDefaultExtensions.js +68 -0
- package/cjs/index.d.ts +3 -1
- package/cjs/index.js +13 -2
- package/cjs/theme/light.d.ts +1 -0
- package/cjs/theme/light.js +1 -2
- package/cjs/useCodeMirror.js +12 -45
- package/cjs/utils.js +1 -2
- package/dist/mdeditor.js +42 -19
- package/dist/mdeditor.min.js +1 -1
- package/esm/.kktrc.d.ts +3 -0
- package/esm/getDefaultExtensions.d.ts +11 -0
- package/esm/getDefaultExtensions.js +59 -0
- package/esm/index.d.ts +3 -1
- package/esm/index.js +2 -2
- package/esm/theme/light.d.ts +1 -0
- package/esm/theme/light.js +1 -2
- package/esm/useCodeMirror.js +12 -46
- package/esm/utils.js +1 -2
- package/package.json +4 -4
- package/src/getDefaultExtensions.ts +71 -0
- package/src/index.tsx +3 -1
- package/src/useCodeMirror.ts +11 -49
- package/cjs/index.js.map +0 -81
- package/cjs/theme/light.js.map +0 -20
- package/cjs/useCodeMirror.js.map +0 -123
- package/cjs/utils.js.map +0 -40
- package/esm/index.js.map +0 -57
- package/esm/theme/light.js.map +0 -17
- package/esm/useCodeMirror.js.map +0 -95
- package/esm/utils.js.map +0 -39
package/README.md
CHANGED
|
@@ -183,6 +183,34 @@ export default function App() {
|
|
|
183
183
|
}
|
|
184
184
|
```
|
|
185
185
|
|
|
186
|
+
## Codemirror Merge
|
|
187
|
+
|
|
188
|
+
```jsx
|
|
189
|
+
import CodeMirrorMerge from 'react-codemirror-merge';
|
|
190
|
+
import { EditorView } from 'codemirror';
|
|
191
|
+
import { EditorState } from '@codemirror/state';
|
|
192
|
+
|
|
193
|
+
const Original = CodeMirrorMerge.Original;
|
|
194
|
+
const Modified = CodeMirrorMerge.Modified;
|
|
195
|
+
let doc = `one
|
|
196
|
+
two
|
|
197
|
+
three
|
|
198
|
+
four
|
|
199
|
+
five`;
|
|
200
|
+
|
|
201
|
+
export const Example = () => {
|
|
202
|
+
return (
|
|
203
|
+
<CodeMirrorMerge>
|
|
204
|
+
<Original value={doc} />
|
|
205
|
+
<Modified
|
|
206
|
+
value={doc.replace(/t/g, 'T') + 'Six'}
|
|
207
|
+
extensions={[EditorView.editable.of(false), EditorState.readOnly.of(true)]}
|
|
208
|
+
/>
|
|
209
|
+
</CodeMirrorMerge>
|
|
210
|
+
);
|
|
211
|
+
};
|
|
212
|
+
```
|
|
213
|
+
|
|
186
214
|
## Support Hook
|
|
187
215
|
|
|
188
216
|
[](https://codesandbox.io/embed/react-codemirror-example-codemirror-6-hook-yr4vg?fontsize=14&hidenavigation=1&theme=dark)
|
|
@@ -397,7 +425,8 @@ export interface ReactCodeMirrorProps
|
|
|
397
425
|
*/
|
|
398
426
|
readOnly?: boolean;
|
|
399
427
|
/**
|
|
400
|
-
*
|
|
428
|
+
* Controls whether pressing the `Tab` key inserts a tab character and indents the text (`true`)
|
|
429
|
+
* or behaves according to the browser's default behavior (`false`).
|
|
401
430
|
* @default true
|
|
402
431
|
*/
|
|
403
432
|
indentWithTab?: boolean;
|
package/cjs/.kktrc.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Extension } from '@codemirror/state';
|
|
2
|
+
import { BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
|
|
3
|
+
export type DefaultExtensionsOptions = {
|
|
4
|
+
indentWithTab?: boolean;
|
|
5
|
+
basicSetup?: boolean | BasicSetupOptions;
|
|
6
|
+
placeholder?: string | HTMLElement;
|
|
7
|
+
theme?: 'light' | 'dark' | 'none' | Extension;
|
|
8
|
+
readOnly?: boolean;
|
|
9
|
+
editable?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const getDefaultExtensions: (optios?: DefaultExtensionsOptions) => Extension[];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDefaultExtensions = void 0;
|
|
7
|
+
var _commands = require("@codemirror/commands");
|
|
8
|
+
var _codemirrorExtensionsBasicSetup = require("@uiw/codemirror-extensions-basic-setup");
|
|
9
|
+
var _view = require("@codemirror/view");
|
|
10
|
+
var _themeOneDark = require("@codemirror/theme-one-dark");
|
|
11
|
+
var _state = require("@codemirror/state");
|
|
12
|
+
var getDefaultExtensions = function getDefaultExtensions() {
|
|
13
|
+
var optios = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
14
|
+
var _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;
|
|
26
|
+
var getExtensions = [];
|
|
27
|
+
var defaultLightThemeOption = _view.EditorView.theme({
|
|
28
|
+
'&': {
|
|
29
|
+
backgroundColor: '#fff'
|
|
30
|
+
}
|
|
31
|
+
}, {
|
|
32
|
+
dark: false
|
|
33
|
+
});
|
|
34
|
+
if (defaultIndentWithTab) {
|
|
35
|
+
getExtensions.unshift(_view.keymap.of([_commands.indentWithTab]));
|
|
36
|
+
}
|
|
37
|
+
if (defaultBasicSetup) {
|
|
38
|
+
if (typeof defaultBasicSetup === 'boolean') {
|
|
39
|
+
getExtensions.unshift((0, _codemirrorExtensionsBasicSetup.basicSetup)());
|
|
40
|
+
} else {
|
|
41
|
+
getExtensions.unshift((0, _codemirrorExtensionsBasicSetup.basicSetup)(defaultBasicSetup));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (placeholderStr) {
|
|
45
|
+
getExtensions.unshift((0, _view.placeholder)(placeholderStr));
|
|
46
|
+
}
|
|
47
|
+
switch (theme) {
|
|
48
|
+
case 'light':
|
|
49
|
+
getExtensions.push(defaultLightThemeOption);
|
|
50
|
+
break;
|
|
51
|
+
case 'dark':
|
|
52
|
+
getExtensions.push(_themeOneDark.oneDark);
|
|
53
|
+
break;
|
|
54
|
+
case 'none':
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
getExtensions.push(theme);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
if (editable === false) {
|
|
61
|
+
getExtensions.push(_view.EditorView.editable.of(false));
|
|
62
|
+
}
|
|
63
|
+
if (readOnly) {
|
|
64
|
+
getExtensions.push(_state.EditorState.readOnly.of(true));
|
|
65
|
+
}
|
|
66
|
+
return [].concat(getExtensions);
|
|
67
|
+
};
|
|
68
|
+
exports.getDefaultExtensions = getDefaultExtensions;
|
package/cjs/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
|
|
|
5
5
|
import { Statistics } from './utils';
|
|
6
6
|
export * from '@uiw/codemirror-extensions-basic-setup';
|
|
7
7
|
export * from './useCodeMirror';
|
|
8
|
+
export * from './getDefaultExtensions';
|
|
8
9
|
export * from './utils';
|
|
9
10
|
export interface ReactCodeMirrorProps extends Omit<EditorStateConfig, 'doc' | 'extensions'>, Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'placeholder'> {
|
|
10
11
|
/** value of the auto created model in the editor. */
|
|
@@ -40,7 +41,8 @@ export interface ReactCodeMirrorProps extends Omit<EditorStateConfig, 'doc' | 'e
|
|
|
40
41
|
*/
|
|
41
42
|
readOnly?: boolean;
|
|
42
43
|
/**
|
|
43
|
-
*
|
|
44
|
+
* Controls whether pressing the `Tab` key inserts a tab character and indents the text (`true`)
|
|
45
|
+
* or behaves according to the browser's default behavior (`false`).
|
|
44
46
|
* @default true
|
|
45
47
|
*/
|
|
46
48
|
indentWithTab?: boolean;
|
package/cjs/index.js
CHANGED
|
@@ -36,6 +36,18 @@ Object.keys(_codemirrorExtensionsBasicSetup).forEach(function (key) {
|
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
|
+
var _getDefaultExtensions = require("./getDefaultExtensions");
|
|
40
|
+
Object.keys(_getDefaultExtensions).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
43
|
+
if (key in exports && exports[key] === _getDefaultExtensions[key]) return;
|
|
44
|
+
Object.defineProperty(exports, key, {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function get() {
|
|
47
|
+
return _getDefaultExtensions[key];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
39
51
|
var _utils = require("./utils");
|
|
40
52
|
Object.keys(_utils).forEach(function (key) {
|
|
41
53
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -126,5 +138,4 @@ var ReactCodeMirror = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
|
126
138
|
});
|
|
127
139
|
ReactCodeMirror.displayName = 'CodeMirror';
|
|
128
140
|
var _default = ReactCodeMirror;
|
|
129
|
-
exports["default"] = _default;
|
|
130
|
-
//# sourceMappingURL=index.js.map
|
|
141
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const defaultLightThemeOption: import("@codemirror/state").Extension;
|
package/cjs/theme/light.js
CHANGED
package/cjs/useCodeMirror.js
CHANGED
|
@@ -5,13 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.useCodeMirror = useCodeMirror;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
8
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
10
|
var _react = require("react");
|
|
10
11
|
var _state = require("@codemirror/state");
|
|
11
|
-
var _commands = require("@codemirror/commands");
|
|
12
12
|
var _view = require("@codemirror/view");
|
|
13
|
-
var
|
|
14
|
-
var _themeOneDark = require("@codemirror/theme-one-dark");
|
|
13
|
+
var _getDefaultExtensions = require("./getDefaultExtensions");
|
|
15
14
|
var _utils = require("./utils");
|
|
16
15
|
var External = _state.Annotation.define();
|
|
17
16
|
function useCodeMirror(props) {
|
|
@@ -62,13 +61,6 @@ function useCodeMirror(props) {
|
|
|
62
61
|
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
|
63
62
|
state = _useState6[0],
|
|
64
63
|
setState = _useState6[1];
|
|
65
|
-
var defaultLightThemeOption = _view.EditorView.theme({
|
|
66
|
-
'&': {
|
|
67
|
-
backgroundColor: '#fff'
|
|
68
|
-
}
|
|
69
|
-
}, {
|
|
70
|
-
dark: false
|
|
71
|
-
});
|
|
72
64
|
var defaultThemeOption = _view.EditorView.theme({
|
|
73
65
|
'&': {
|
|
74
66
|
height: height,
|
|
@@ -92,39 +84,15 @@ function useCodeMirror(props) {
|
|
|
92
84
|
}
|
|
93
85
|
onStatistics && onStatistics((0, _utils.getStatistics)(vu));
|
|
94
86
|
});
|
|
95
|
-
var
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (placeholderStr) {
|
|
107
|
-
getExtensions.unshift((0, _view.placeholder)(placeholderStr));
|
|
108
|
-
}
|
|
109
|
-
switch (theme) {
|
|
110
|
-
case 'light':
|
|
111
|
-
getExtensions.push(defaultLightThemeOption);
|
|
112
|
-
break;
|
|
113
|
-
case 'dark':
|
|
114
|
-
getExtensions.push(_themeOneDark.oneDark);
|
|
115
|
-
break;
|
|
116
|
-
case 'none':
|
|
117
|
-
break;
|
|
118
|
-
default:
|
|
119
|
-
getExtensions.push(theme);
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
if (editable === false) {
|
|
123
|
-
getExtensions.push(_view.EditorView.editable.of(false));
|
|
124
|
-
}
|
|
125
|
-
if (readOnly) {
|
|
126
|
-
getExtensions.push(_state.EditorState.readOnly.of(true));
|
|
127
|
-
}
|
|
87
|
+
var defaultExtensions = (0, _getDefaultExtensions.getDefaultExtensions)({
|
|
88
|
+
theme: theme,
|
|
89
|
+
editable: true,
|
|
90
|
+
readOnly: false,
|
|
91
|
+
placeholder: placeholderStr,
|
|
92
|
+
indentWithTab: defaultIndentWithTab,
|
|
93
|
+
basicSetup: defaultBasicSetup
|
|
94
|
+
});
|
|
95
|
+
var getExtensions = [updateListener, defaultThemeOption].concat((0, _toConsumableArray2["default"])(defaultExtensions));
|
|
128
96
|
if (onUpdate && typeof onUpdate === 'function') {
|
|
129
97
|
getExtensions.push(_view.EditorView.updateListener.of(onUpdate));
|
|
130
98
|
}
|
|
@@ -203,5 +171,4 @@ function useCodeMirror(props) {
|
|
|
203
171
|
container: container,
|
|
204
172
|
setContainer: setContainer
|
|
205
173
|
};
|
|
206
|
-
}
|
|
207
|
-
//# sourceMappingURL=useCodeMirror.js.map
|
|
174
|
+
}
|
package/cjs/utils.js
CHANGED
package/dist/mdeditor.js
CHANGED
|
@@ -137,6 +137,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
137
137
|
__webpack_require__.d(__webpack_exports__, {
|
|
138
138
|
"basicSetup": () => (/* reexport */ basicSetup),
|
|
139
139
|
"default": () => (/* binding */ src),
|
|
140
|
+
"getDefaultExtensions": () => (/* reexport */ getDefaultExtensions),
|
|
140
141
|
"getStatistics": () => (/* reexport */ getStatistics),
|
|
141
142
|
"minimalSetup": () => (/* reexport */ minimalSetup),
|
|
142
143
|
"useCodeMirror": () => (/* reexport */ useCodeMirror)
|
|
@@ -242,6 +243,43 @@ function _objectWithoutProperties(source, excluded) {
|
|
|
242
243
|
}
|
|
243
244
|
// EXTERNAL MODULE: external {"root":"React","commonjs2":"react","commonjs":"react","amd":"react"}
|
|
244
245
|
var external_root_React_commonjs2_react_commonjs_react_amd_react_ = __webpack_require__(787);
|
|
246
|
+
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js
|
|
247
|
+
function _arrayLikeToArray(arr, len) {
|
|
248
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
249
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
250
|
+
return arr2;
|
|
251
|
+
}
|
|
252
|
+
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js
|
|
253
|
+
|
|
254
|
+
function _arrayWithoutHoles(arr) {
|
|
255
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
256
|
+
}
|
|
257
|
+
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/iterableToArray.js
|
|
258
|
+
function _iterableToArray(iter) {
|
|
259
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
260
|
+
}
|
|
261
|
+
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js
|
|
262
|
+
|
|
263
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
264
|
+
if (!o) return;
|
|
265
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
266
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
267
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
268
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
269
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
270
|
+
}
|
|
271
|
+
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js
|
|
272
|
+
function _nonIterableSpread() {
|
|
273
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
274
|
+
}
|
|
275
|
+
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/toConsumableArray.js
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
function _toConsumableArray(arr) {
|
|
281
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
282
|
+
}
|
|
245
283
|
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js
|
|
246
284
|
function _arrayWithHoles(arr) {
|
|
247
285
|
if (Array.isArray(arr)) return arr;
|
|
@@ -274,22 +312,6 @@ function _iterableToArrayLimit(arr, i) {
|
|
|
274
312
|
return _arr;
|
|
275
313
|
}
|
|
276
314
|
}
|
|
277
|
-
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js
|
|
278
|
-
function _arrayLikeToArray(arr, len) {
|
|
279
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
280
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
281
|
-
return arr2;
|
|
282
|
-
}
|
|
283
|
-
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js
|
|
284
|
-
|
|
285
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
286
|
-
if (!o) return;
|
|
287
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
288
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
289
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
290
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
291
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
292
|
-
}
|
|
293
315
|
;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/nonIterableRest.js
|
|
294
316
|
function _nonIterableRest() {
|
|
295
317
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
@@ -11205,15 +11227,16 @@ var minimalSetup = function minimalSetup(options) {
|
|
|
11205
11227
|
}));
|
|
11206
11228
|
return extensions.concat([view_.keymap.of(keymaps.flat())]).filter(Boolean);
|
|
11207
11229
|
};
|
|
11208
|
-
|
|
11209
11230
|
// EXTERNAL MODULE: external {"root":["CM","@codemirror/theme-one-dark"],"commonjs":"@codemirror/theme-one-dark","commonjs2":"@codemirror/theme-one-dark"}
|
|
11210
11231
|
var theme_one_dark_ = __webpack_require__(362);
|
|
11232
|
+
;// CONCATENATED MODULE: ./src/getDefaultExtensions.ts
|
|
11233
|
+
var getDefaultExtensions=function getDefaultExtensions(){var optios=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _optios$indentWithTab=optios.indentWithTab,defaultIndentWithTab=_optios$indentWithTab===void 0?true:_optios$indentWithTab,_optios$editable=optios.editable,editable=_optios$editable===void 0?true:_optios$editable,_optios$readOnly=optios.readOnly,readOnly=_optios$readOnly===void 0?false:_optios$readOnly,_optios$theme=optios.theme,theme=_optios$theme===void 0?'light':_optios$theme,_optios$placeholder=optios.placeholder,placeholderStr=_optios$placeholder===void 0?'':_optios$placeholder,_optios$basicSetup=optios.basicSetup,defaultBasicSetup=_optios$basicSetup===void 0?true:_optios$basicSetup;var getExtensions=[];var defaultLightThemeOption=view_.EditorView.theme({'&':{backgroundColor:'#fff'}},{dark:false});if(defaultIndentWithTab){getExtensions.unshift(view_.keymap.of([indentWithTab]));}if(defaultBasicSetup){if(typeof defaultBasicSetup==='boolean'){getExtensions.unshift(basicSetup());}else{getExtensions.unshift(basicSetup(defaultBasicSetup));}}if(placeholderStr){getExtensions.unshift((0,view_.placeholder)(placeholderStr));}switch(theme){case'light':getExtensions.push(defaultLightThemeOption);break;case'dark':getExtensions.push(theme_one_dark_.oneDark);break;case'none':break;default:getExtensions.push(theme);break;}if(editable===false){getExtensions.push(view_.EditorView.editable.of(false));}if(readOnly){getExtensions.push(state_.EditorState.readOnly.of(true));}return[].concat(getExtensions);};
|
|
11211
11234
|
;// CONCATENATED MODULE: ./src/utils.ts
|
|
11212
11235
|
var getStatistics=function getStatistics(view){return{line:view.state.doc.lineAt(view.state.selection.main.from),lineCount:view.state.doc.lines,lineBreak:view.state.lineBreak,length:view.state.doc.length,readOnly:view.state.readOnly,tabSize:view.state.tabSize,selection:view.state.selection,selectionAsSingle:view.state.selection.asSingle().main,ranges:view.state.selection.ranges,selectionCode:view.state.sliceDoc(view.state.selection.main.from,view.state.selection.main.to),selections:view.state.selection.ranges.map(function(r){return view.state.sliceDoc(r.from,r.to);}),selectedText:view.state.selection.ranges.some(function(r){return!r.empty;})};};
|
|
11213
11236
|
;// CONCATENATED MODULE: ./src/useCodeMirror.ts
|
|
11214
|
-
var External=state_.Annotation.define();function useCodeMirror(props){var value=props.value,selection=props.selection,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,_props$height=props.height,height=_props$height===void 0?'':_props$height,_props$minHeight=props.minHeight,minHeight=_props$minHeight===void 0?'':_props$minHeight,_props$maxHeight=props.maxHeight,maxHeight=_props$maxHeight===void 0?'':_props$maxHeight,_props$placeholder=props.placeholder,placeholderStr=_props$placeholder===void 0?'':_props$placeholder,_props$width=props.width,width=_props$width===void 0?'':_props$width,_props$minWidth=props.minWidth,minWidth=_props$minWidth===void 0?'':_props$minWidth,_props$maxWidth=props.maxWidth,maxWidth=_props$maxWidth===void 0?'':_props$maxWidth,_props$editable=props.editable,editable=_props$editable===void 0?true:_props$editable,_props$readOnly=props.readOnly,readOnly=_props$readOnly===void 0?false:_props$readOnly,_props$indentWithTab=props.indentWithTab,defaultIndentWithTab=_props$indentWithTab===void 0?true:_props$indentWithTab,_props$basicSetup=props.basicSetup,defaultBasicSetup=_props$basicSetup===void 0?true:_props$basicSetup,root=props.root,initialState=props.initialState;var _useState=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState2=_slicedToArray(_useState,2),container=_useState2[0],setContainer=_useState2[1];var _useState3=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState4=_slicedToArray(_useState3,2),view=_useState4[0],setView=_useState4[1];var _useState5=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState6=_slicedToArray(_useState5,2),state=_useState6[0],setState=_useState6[1];var
|
|
11237
|
+
var External=state_.Annotation.define();function useCodeMirror(props){var value=props.value,selection=props.selection,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,_props$height=props.height,height=_props$height===void 0?'':_props$height,_props$minHeight=props.minHeight,minHeight=_props$minHeight===void 0?'':_props$minHeight,_props$maxHeight=props.maxHeight,maxHeight=_props$maxHeight===void 0?'':_props$maxHeight,_props$placeholder=props.placeholder,placeholderStr=_props$placeholder===void 0?'':_props$placeholder,_props$width=props.width,width=_props$width===void 0?'':_props$width,_props$minWidth=props.minWidth,minWidth=_props$minWidth===void 0?'':_props$minWidth,_props$maxWidth=props.maxWidth,maxWidth=_props$maxWidth===void 0?'':_props$maxWidth,_props$editable=props.editable,editable=_props$editable===void 0?true:_props$editable,_props$readOnly=props.readOnly,readOnly=_props$readOnly===void 0?false:_props$readOnly,_props$indentWithTab=props.indentWithTab,defaultIndentWithTab=_props$indentWithTab===void 0?true:_props$indentWithTab,_props$basicSetup=props.basicSetup,defaultBasicSetup=_props$basicSetup===void 0?true:_props$basicSetup,root=props.root,initialState=props.initialState;var _useState=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState2=_slicedToArray(_useState,2),container=_useState2[0],setContainer=_useState2[1];var _useState3=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState4=_slicedToArray(_useState3,2),view=_useState4[0],setView=_useState4[1];var _useState5=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState6=_slicedToArray(_useState5,2),state=_useState6[0],setState=_useState6[1];var defaultThemeOption=view_.EditorView.theme({'&':{height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth}});var updateListener=view_.EditorView.updateListener.of(function(vu){if(vu.docChanged&&typeof onChange==='function'&&// Fix echoing of the remote changes:
|
|
11215
11238
|
// If transaction is market as remote we don't have to call `onChange` handler again
|
|
11216
|
-
!vu.transactions.some(function(tr){return tr.annotation(External);})){var doc=vu.state.doc;var _value=doc.toString();onChange(_value,vu);}onStatistics&&onStatistics(getStatistics(vu));});var
|
|
11239
|
+
!vu.transactions.some(function(tr){return tr.annotation(External);})){var doc=vu.state.doc;var _value=doc.toString();onChange(_value,vu);}onStatistics&&onStatistics(getStatistics(vu));});var defaultExtensions=getDefaultExtensions({theme:theme,editable:true,readOnly:false,placeholder:placeholderStr,indentWithTab:defaultIndentWithTab,basicSetup:defaultBasicSetup});var getExtensions=[updateListener,defaultThemeOption].concat(_toConsumableArray(defaultExtensions));if(onUpdate&&typeof onUpdate==='function'){getExtensions.push(view_.EditorView.updateListener.of(onUpdate));}getExtensions=getExtensions.concat(extensions);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(container&&!state){var config={doc:value,selection:selection,extensions:getExtensions};var stateCurrent=initialState?state_.EditorState.fromJSON(initialState.json,config,initialState.fields):state_.EditorState.create(config);setState(stateCurrent);if(!view){var viewCurrent=new view_.EditorView({state:stateCurrent,parent:container,root:root});setView(viewCurrent);onCreateEditor&&onCreateEditor(viewCurrent,stateCurrent);}}return function(){if(view){setState(undefined);setView(undefined);}};},[container,state]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){return setContainer(props.container);},[props.container]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){return function(){if(view){view.destroy();setView(undefined);}};},[view]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(autoFocus&&view){view.focus();}},[autoFocus,view]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(view){view.dispatch({effects:state_.StateEffect.reconfigure.of(getExtensions)});}// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
11217
11240
|
},[theme,extensions,height,minHeight,maxHeight,width,minWidth,maxWidth,placeholderStr,editable,readOnly,defaultIndentWithTab,defaultBasicSetup,onChange,onUpdate]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(value===undefined){return;}var currentValue=view?view.state.doc.toString():'';if(view&&value!==currentValue){view.dispatch({changes:{from:0,to:currentValue.length,insert:value||''},annotations:[External.of(true)]});}},[value,view]);return{state:state,setState:setState,view:view,setView:setView,container:container,setContainer:setContainer};}
|
|
11218
11241
|
// EXTERNAL MODULE: ../node_modules/react/jsx-runtime.js
|
|
11219
11242
|
var jsx_runtime = __webpack_require__(605);
|