@uiw/react-codemirror 4.9.4 → 4.10.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.
- package/README.md +38 -7
- package/cjs/index.d.ts +4 -0
- package/cjs/index.js +19 -8
- package/cjs/index.js.map +3 -4
- package/cjs/useCodeMirror.d.ts +2 -2
- package/cjs/useCodeMirror.js +11 -2
- package/cjs/useCodeMirror.js.map +4 -2
- package/cjs/utils.d.ts +20 -0
- package/cjs/utils.js +24 -0
- package/cjs/utils.js.map +31 -0
- package/dist/mdeditor.js +42 -21
- package/dist/mdeditor.min.js +1 -1
- package/esm/index.d.ts +4 -0
- package/esm/index.js +10 -10
- package/esm/index.js.map +4 -4
- package/esm/useCodeMirror.d.ts +2 -2
- package/esm/useCodeMirror.js +8 -2
- package/esm/useCodeMirror.js.map +4 -2
- package/esm/utils.d.ts +20 -0
- package/esm/utils.js +9 -0
- package/esm/utils.js.map +31 -0
- package/package.json +1 -1
- package/src/index.tsx +15 -7
- package/src/useCodeMirror.ts +7 -2
- package/src/utils.ts +29 -0
package/esm/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { EditorState, EditorStateConfig, Extension } from '@codemirror/state';
|
|
3
3
|
import { EditorView, ViewUpdate } from '@codemirror/view';
|
|
4
|
+
import { Statistics } from './utils';
|
|
4
5
|
import { BasicSetupOptions } from './basicSetup';
|
|
5
6
|
export * from './basicSetup';
|
|
6
7
|
export * from './useCodeMirror';
|
|
8
|
+
export * from './utils';
|
|
7
9
|
export interface ReactCodeMirrorProps extends Omit<EditorStateConfig, 'doc' | 'extensions'>, Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'placeholder'> {
|
|
8
10
|
/** value of the auto created model in the editor. */
|
|
9
11
|
value?: string;
|
|
@@ -44,6 +46,8 @@ export interface ReactCodeMirrorProps extends Omit<EditorStateConfig, 'doc' | 'e
|
|
|
44
46
|
indentWithTab?: boolean;
|
|
45
47
|
/** Fired whenever a change occurs to the document. */
|
|
46
48
|
onChange?(value: string, viewUpdate: ViewUpdate): void;
|
|
49
|
+
/** Some data on the statistics editor. */
|
|
50
|
+
onStatistics?(data: Statistics): void;
|
|
47
51
|
/** Fired whenever any state change occurs within the editor, including non-document changes like lint results. */
|
|
48
52
|
onUpdate?(viewUpdate: ViewUpdate): void;
|
|
49
53
|
/**
|
package/esm/index.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
-
var _excluded = ["className", "value", "selection", "extensions", "onChange", "onUpdate", "autoFocus", "theme", "height", "minHeight", "maxHeight", "width", "minWidth", "maxWidth", "basicSetup", "placeholder", "indentWithTab", "editable", "readOnly", "root"];
|
|
4
|
-
import React, {
|
|
3
|
+
var _excluded = ["className", "value", "selection", "extensions", "onChange", "onStatistics", "onUpdate", "autoFocus", "theme", "height", "minHeight", "maxHeight", "width", "minWidth", "maxWidth", "basicSetup", "placeholder", "indentWithTab", "editable", "readOnly", "root"];
|
|
4
|
+
import React, { useRef, forwardRef, useImperativeHandle } from 'react';
|
|
5
5
|
import { useCodeMirror } from './useCodeMirror';
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
7
|
export * from './basicSetup';
|
|
8
8
|
export * from './useCodeMirror';
|
|
9
|
-
|
|
9
|
+
export * from './utils';
|
|
10
|
+
var ReactCodeMirror = /*#__PURE__*/forwardRef((props, ref) => {
|
|
10
11
|
var {
|
|
11
12
|
className,
|
|
12
13
|
value = '',
|
|
13
14
|
selection,
|
|
14
15
|
extensions = [],
|
|
15
16
|
onChange,
|
|
17
|
+
onStatistics,
|
|
16
18
|
onUpdate,
|
|
17
19
|
autoFocus,
|
|
18
20
|
theme = 'light',
|
|
@@ -56,17 +58,15 @@ var ReactCodeMirror = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
56
58
|
readOnly,
|
|
57
59
|
selection,
|
|
58
60
|
onChange,
|
|
61
|
+
onStatistics,
|
|
59
62
|
onUpdate,
|
|
60
63
|
extensions
|
|
61
64
|
});
|
|
62
65
|
useImperativeHandle(ref, () => ({
|
|
63
|
-
editor:
|
|
64
|
-
state,
|
|
65
|
-
view
|
|
66
|
-
}), [container, state, view]);
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
setContainer(editor.current); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
69
|
-
}, []); // check type of value
|
|
66
|
+
editor: editor.current,
|
|
67
|
+
state: state,
|
|
68
|
+
view: view
|
|
69
|
+
}), [editor, container, state, view]); // check type of value
|
|
70
70
|
|
|
71
71
|
if (typeof value !== 'string') {
|
|
72
72
|
throw new Error("value must be typeof string but got " + typeof value);
|
package/esm/index.js.map
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"names": [
|
|
4
4
|
"React",
|
|
5
|
-
"useEffect",
|
|
6
5
|
"useRef",
|
|
6
|
+
"forwardRef",
|
|
7
7
|
"useImperativeHandle",
|
|
8
8
|
"useCodeMirror",
|
|
9
9
|
"ReactCodeMirror",
|
|
10
|
-
"forwardRef",
|
|
11
10
|
"props",
|
|
12
11
|
"ref",
|
|
13
12
|
"className",
|
|
@@ -15,6 +14,7 @@
|
|
|
15
14
|
"selection",
|
|
16
15
|
"extensions",
|
|
17
16
|
"onChange",
|
|
17
|
+
"onStatistics",
|
|
18
18
|
"onUpdate",
|
|
19
19
|
"autoFocus",
|
|
20
20
|
"theme",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"../src/index.tsx"
|
|
46
46
|
],
|
|
47
47
|
"sourcesContent": [
|
|
48
|
-
"import React, {
|
|
48
|
+
"import React, { useRef, forwardRef, useImperativeHandle } from 'react';\nimport { EditorState, EditorStateConfig, Extension } from '@codemirror/state';\nimport { EditorView, ViewUpdate } from '@codemirror/view';\nimport { useCodeMirror } from './useCodeMirror';\nimport { Statistics } from './utils';\nimport { BasicSetupOptions } from './basicSetup';\n\nexport * from './basicSetup';\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 /**\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\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 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 ...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 onUpdate,\n extensions,\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\nexport default ReactCodeMirror;\n"
|
|
49
49
|
],
|
|
50
|
-
"mappings": ";;;AAAA,OAAOA,KAAP,IAAgBC,
|
|
50
|
+
"mappings": ";;;AAAA,OAAOA,KAAP,IAAgBC,MAAhB,EAAwBC,UAAxB,EAAoCC,mBAApC,QAA+D,OAA/D;AAGA,SAASC,aAAT,QAA8B,iBAA9B;;AAIA,cAAc,cAAd;AACA,cAAc,iBAAd;AACA,cAAc,SAAd;AAoEA,IAAMC,eAAe,gBAAGH,UAAU,CAA2C,CAACI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iB,QAArB,EAA+B;IAC7B,MAAM,IAAI2B,KAAJ,0CAAiD,OAAO3B,KAAxD,CAAN;EACD;;EAED,IAAM4B,iBAAiB,GAAG,OAAOrB,KAAP,KAAiB,QAAjB,iBAAwCA,KAAxC,GAAkD,UAA5E;EACA,oBAAO;IAAK,GAAG,EAAEc,MAAV;IAAkB,SAAS,OAAKO,iBAAL,IAAyB7B,SAAS,SAAOA,SAAP,GAAqB,EAAvD;EAA3B,GAA4FqB,KAA5F,EAAP;AACD,CAhEiC,CAAlC;AAkEAxB,eAAe,CAACiC,WAAhB,GAA8B,YAA9B;AAEA,eAAejC,eAAf"
|
|
51
51
|
}
|
package/esm/useCodeMirror.d.ts
CHANGED
|
@@ -9,6 +9,6 @@ export declare function useCodeMirror(props: UseCodeMirror): {
|
|
|
9
9
|
setState: import("react").Dispatch<import("react").SetStateAction<EditorState | undefined>>;
|
|
10
10
|
view: EditorView | undefined;
|
|
11
11
|
setView: import("react").Dispatch<import("react").SetStateAction<EditorView | undefined>>;
|
|
12
|
-
container: HTMLDivElement |
|
|
13
|
-
setContainer: import("react").Dispatch<import("react").SetStateAction<HTMLDivElement |
|
|
12
|
+
container: HTMLDivElement | undefined;
|
|
13
|
+
setContainer: import("react").Dispatch<import("react").SetStateAction<HTMLDivElement | undefined>>;
|
|
14
14
|
};
|
package/esm/useCodeMirror.js
CHANGED
|
@@ -4,11 +4,13 @@ import { indentWithTab } from '@codemirror/commands';
|
|
|
4
4
|
import { EditorView, keymap, placeholder } from '@codemirror/view';
|
|
5
5
|
import { oneDark } from '@codemirror/theme-one-dark';
|
|
6
6
|
import { basicSetup } from './basicSetup';
|
|
7
|
+
import { getStatistics } from './utils';
|
|
7
8
|
export function useCodeMirror(props) {
|
|
8
9
|
var {
|
|
9
10
|
value,
|
|
10
11
|
selection,
|
|
11
12
|
onChange,
|
|
13
|
+
onStatistics,
|
|
12
14
|
onUpdate,
|
|
13
15
|
extensions = [],
|
|
14
16
|
autoFocus,
|
|
@@ -26,7 +28,7 @@ export function useCodeMirror(props) {
|
|
|
26
28
|
basicSetup: defaultBasicSetup = true,
|
|
27
29
|
root
|
|
28
30
|
} = props;
|
|
29
|
-
var [container, setContainer] = useState(
|
|
31
|
+
var [container, setContainer] = useState();
|
|
30
32
|
var [view, setView] = useState();
|
|
31
33
|
var [state, setState] = useState();
|
|
32
34
|
var defaultLightThemeOption = EditorView.theme({
|
|
@@ -54,6 +56,8 @@ export function useCodeMirror(props) {
|
|
|
54
56
|
|
|
55
57
|
onChange(_value, vu);
|
|
56
58
|
}
|
|
59
|
+
|
|
60
|
+
onStatistics && onStatistics(getStatistics(vu));
|
|
57
61
|
});
|
|
58
62
|
var getExtensions = [updateListener, defaultThemeOption];
|
|
59
63
|
|
|
@@ -121,10 +125,12 @@ export function useCodeMirror(props) {
|
|
|
121
125
|
|
|
122
126
|
return () => {
|
|
123
127
|
if (view) {
|
|
128
|
+
setState(undefined);
|
|
124
129
|
setView(undefined);
|
|
125
130
|
}
|
|
126
|
-
};
|
|
131
|
+
};
|
|
127
132
|
}, [container, state]);
|
|
133
|
+
useEffect(() => setContainer(props.container), [props.container]);
|
|
128
134
|
useEffect(() => () => {
|
|
129
135
|
if (view) {
|
|
130
136
|
view.destroy();
|
package/esm/useCodeMirror.js.map
CHANGED
|
@@ -11,11 +11,13 @@
|
|
|
11
11
|
"placeholder",
|
|
12
12
|
"oneDark",
|
|
13
13
|
"basicSetup",
|
|
14
|
+
"getStatistics",
|
|
14
15
|
"useCodeMirror",
|
|
15
16
|
"props",
|
|
16
17
|
"value",
|
|
17
18
|
"selection",
|
|
18
19
|
"onChange",
|
|
20
|
+
"onStatistics",
|
|
19
21
|
"onUpdate",
|
|
20
22
|
"extensions",
|
|
21
23
|
"autoFocus",
|
|
@@ -73,7 +75,7 @@
|
|
|
73
75
|
"../src/useCodeMirror.ts"
|
|
74
76
|
],
|
|
75
77
|
"sourcesContent": [
|
|
76
|
-
"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 { oneDark } from '@codemirror/theme-one-dark';\nimport { basicSetup } from './basicSetup';\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 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 } = props;\n const [container, setContainer] = useState(
|
|
78
|
+
"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 { oneDark } from '@codemirror/theme-one-dark';\nimport { basicSetup } from './basicSetup';\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 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 } = 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 stateCurrent = EditorState.create({\n doc: value,\n selection,\n extensions: getExtensions,\n });\n setState(stateCurrent);\n if (!view) {\n const viewCurrent = new EditorView({\n state: stateCurrent,\n parent: container,\n root,\n });\n setView(viewCurrent);\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"
|
|
77
79
|
],
|
|
78
|
-
"mappings": "AAAA,SAASA,SAAT,EAAoBC,QAApB,QAAoC,OAApC;AACA,SAASC,WAAT,EAAsBC,WAAtB,QAAyC,mBAAzC;AACA,SAASC,aAAT,QAA8B,sBAA9B;AACA,SAASC,UAAT,EAAqBC,MAArB,EAAyCC,WAAzC,QAA4D,kBAA5D;AACA,SAASC,OAAT,QAAwB,4BAAxB;AACA,SAASC,UAAT,QAA2B,cAA3B;AAOA,OAAO,SAASC,aAAT,CAAuBC,KAAvB,EAA6C;EAClD,IAAM;IACJC,KADI;IAEJC,SAFI;IAGJC,QAHI;IAIJC,
|
|
80
|
+
"mappings": "AAAA,SAASA,SAAT,EAAoBC,QAApB,QAAoC,OAApC;AACA,SAASC,WAAT,EAAsBC,WAAtB,QAAyC,mBAAzC;AACA,SAASC,aAAT,QAA8B,sBAA9B;AACA,SAASC,UAAT,EAAqBC,MAArB,EAAyCC,WAAzC,QAA4D,kBAA5D;AACA,SAASC,OAAT,QAAwB,4BAAxB;AACA,SAASC,UAAT,QAA2B,cAA3B;AACA,SAASC,aAAT,QAA8B,SAA9B;AAOA,OAAO,SAASC,aAAT,CAAuBC,KAAvB,EAA6C;EAClD,IAAM;IACJC,KADI;IAEJC,SAFI;IAGJC,QAHI;IAIJC,YAJI;IAKJC,QALI;IAMJC,UAAU,GAAG,EANT;IAOJC,SAPI;IAQJC,KAAK,GAAG,OARJ;IASJC,MAAM,GAAG,EATL;IAUJC,SA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Ha,CAId;;EACD,CALQ,EAKN,CACD7B,KADC,EAEDF,UAFC,EAGDG,MAHC,EAIDC,SAJC,EAKDC,SALC,EAMDE,KANC,EAODC,QAPC,EAQDC,QARC,EASDH,cATC,EAUDI,QAVC,EAWDC,QAXC,EAYDC,oBAZC,EAaDC,iBAbC,EAcDhB,QAdC,EAeDE,QAfC,CALM,CAAT;EAuBAjB,SAAS,CAAC,MAAM;IACd,IAAM+D,YAAY,GAAG5B,IAAI,GAAGA,IAAI,CAACE,KAAL,CAAWU,GAAX,CAAeC,QAAf,EAAH,GAA+B,EAAxD;;IACA,IAAIb,IAAI,IAAItB,KAAK,KAAKkD,YAAtB,EAAoC;MAClC5B,IAAI,CAACyB,QAAL,CAAc;QACZI,OAAO,EAAE;UAAEC,IAAI,EAAE,CAAR;UAAWC,EAAE,EAAEH,YAAY,CAACI,MAA5B;UAAoCC,MAAM,EAAEvD,KAAK,IAAI;QAArD;MADG,CAAd;IAGD;EACF,CAPQ,EAON,CAACA,KAAD,EAAQsB,IAAR,CAPM,CAAT;EASA,OAAO;IAAEE,KAAF;IAASC,QAAT;IAAmBH,IAAnB;IAAyBC,OAAzB;IAAkCH,SAAlC;IAA6CC;EAA7C,CAAP;AACD"
|
|
79
81
|
}
|
package/esm/utils.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EditorSelection, SelectionRange } from '@codemirror/state';
|
|
2
|
+
import { ViewUpdate } from '@codemirror/view';
|
|
3
|
+
export interface Statistics {
|
|
4
|
+
/** Get the number of lines in the editor. */
|
|
5
|
+
lineCount: number;
|
|
6
|
+
/** Cursor Position */
|
|
7
|
+
selection: EditorSelection;
|
|
8
|
+
/** Retrieves a list of all current selections. */
|
|
9
|
+
ranges: readonly SelectionRange[];
|
|
10
|
+
/** Get the currently selected code. */
|
|
11
|
+
selectionCode: string;
|
|
12
|
+
/**
|
|
13
|
+
* The length of the given array should be the same as the number of active selections.
|
|
14
|
+
* Replaces the content of the selections with the strings in the array.
|
|
15
|
+
*/
|
|
16
|
+
selections: string[];
|
|
17
|
+
/** Return true if any text is selected. */
|
|
18
|
+
selectedText: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare const getStatistics: (view: ViewUpdate) => Statistics;
|
package/esm/utils.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export var getStatistics = view => ({
|
|
2
|
+
lineCount: view.state.doc.lines,
|
|
3
|
+
selection: view.state.selection,
|
|
4
|
+
ranges: view.state.selection.ranges,
|
|
5
|
+
selectionCode: view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to),
|
|
6
|
+
selections: view.state.selection.ranges.map(r => view.state.sliceDoc(r.from, r.to)),
|
|
7
|
+
selectedText: view.state.selection.ranges.some(r => !r.empty)
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=utils.js.map
|
package/esm/utils.js.map
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"names": [
|
|
4
|
+
"getStatistics",
|
|
5
|
+
"view",
|
|
6
|
+
"lineCount",
|
|
7
|
+
"state",
|
|
8
|
+
"doc",
|
|
9
|
+
"lines",
|
|
10
|
+
"selection",
|
|
11
|
+
"ranges",
|
|
12
|
+
"selectionCode",
|
|
13
|
+
"sliceDoc",
|
|
14
|
+
"main",
|
|
15
|
+
"from",
|
|
16
|
+
"to",
|
|
17
|
+
"selections",
|
|
18
|
+
"map",
|
|
19
|
+
"r",
|
|
20
|
+
"selectedText",
|
|
21
|
+
"some",
|
|
22
|
+
"empty"
|
|
23
|
+
],
|
|
24
|
+
"sources": [
|
|
25
|
+
"../src/utils.ts"
|
|
26
|
+
],
|
|
27
|
+
"sourcesContent": [
|
|
28
|
+
"import { EditorSelection, SelectionRange } from '@codemirror/state';\nimport { ViewUpdate } from '@codemirror/view';\n\nexport interface Statistics {\n /** Get the number of lines in the editor. */\n lineCount: number;\n /** Cursor Position */\n selection: EditorSelection;\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 lineCount: view.state.doc.lines,\n selection: view.state.selection,\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"
|
|
29
|
+
],
|
|
30
|
+
"mappings": "AAqBA,OAAO,IAAMA,aAAa,GAAIC,IAAD,KAAmC;EAC9DC,SAAS,EAAED,IAAI,CAACE,KAAL,CAAWC,GAAX,CAAeC,KADoC;EAE9DC,SAAS,EAAEL,IAAI,CAACE,KAAL,CAAWG,SAFwC;EAG9DC,MAAM,EAAEN,IAAI,CAACE,KAAL,CAAWG,SAAX,CAAqBC,MAHiC;EAI9DC,aAAa,EAAEP,IAAI,CAACE,KAAL,CAAWM,QAAX,CAAoBR,IAAI,CAACE,KAAL,CAAWG,SAAX,CAAqBI,IAArB,CAA0BC,IAA9C,EAAoDV,IAAI,CAACE,KAAL,CAAWG,SAAX,CAAqBI,IAArB,CAA0BE,EAA9E,CAJ+C;EAK9DC,UAAU,EAAEZ,IAAI,CAACE,KAAL,CAAWG,SAAX,CAAqBC,MAArB,CAA4BO,GAA5B,CAAiCC,CAAD,IAAOd,IAAI,CAACE,KAAL,CAAWM,QAAX,CAAoBM,CAAC,CAACJ,IAAtB,EAA4BI,CAAC,CAACH,EAA9B,CAAvC,CALkD;EAM9DI,YAAY,EAAEf,IAAI,CAACE,KAAL,CAAWG,SAAX,CAAqBC,MAArB,CAA4BU,IAA5B,CAAkCF,CAAD,IAAO,CAACA,CAAC,CAACG,KAA3C;AANgD,CAAnC,CAAtB"
|
|
31
|
+
}
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useRef, forwardRef, useImperativeHandle } from 'react';
|
|
2
2
|
import { EditorState, EditorStateConfig, Extension } from '@codemirror/state';
|
|
3
3
|
import { EditorView, ViewUpdate } from '@codemirror/view';
|
|
4
4
|
import { useCodeMirror } from './useCodeMirror';
|
|
5
|
+
import { Statistics } from './utils';
|
|
5
6
|
import { BasicSetupOptions } from './basicSetup';
|
|
6
7
|
|
|
7
8
|
export * from './basicSetup';
|
|
8
9
|
export * from './useCodeMirror';
|
|
10
|
+
export * from './utils';
|
|
9
11
|
|
|
10
12
|
export interface ReactCodeMirrorProps
|
|
11
13
|
extends Omit<EditorStateConfig, 'doc' | 'extensions'>,
|
|
@@ -49,6 +51,8 @@ export interface ReactCodeMirrorProps
|
|
|
49
51
|
indentWithTab?: boolean;
|
|
50
52
|
/** Fired whenever a change occurs to the document. */
|
|
51
53
|
onChange?(value: string, viewUpdate: ViewUpdate): void;
|
|
54
|
+
/** Some data on the statistics editor. */
|
|
55
|
+
onStatistics?(data: Statistics): void;
|
|
52
56
|
/** Fired whenever any state change occurs within the editor, including non-document changes like lint results. */
|
|
53
57
|
onUpdate?(viewUpdate: ViewUpdate): void;
|
|
54
58
|
/**
|
|
@@ -71,13 +75,14 @@ export interface ReactCodeMirrorRef {
|
|
|
71
75
|
view?: EditorView;
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
const ReactCodeMirror =
|
|
78
|
+
const ReactCodeMirror = forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProps>((props, ref) => {
|
|
75
79
|
const {
|
|
76
80
|
className,
|
|
77
81
|
value = '',
|
|
78
82
|
selection,
|
|
79
83
|
extensions = [],
|
|
80
84
|
onChange,
|
|
85
|
+
onStatistics,
|
|
81
86
|
onUpdate,
|
|
82
87
|
autoFocus,
|
|
83
88
|
theme = 'light',
|
|
@@ -115,14 +120,17 @@ const ReactCodeMirror = React.forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProp
|
|
|
115
120
|
readOnly,
|
|
116
121
|
selection,
|
|
117
122
|
onChange,
|
|
123
|
+
onStatistics,
|
|
118
124
|
onUpdate,
|
|
119
125
|
extensions,
|
|
120
126
|
});
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
|
|
128
|
+
useImperativeHandle(ref, () => ({ editor: editor.current, state: state, view: view }), [
|
|
129
|
+
editor,
|
|
130
|
+
container,
|
|
131
|
+
state,
|
|
132
|
+
view,
|
|
133
|
+
]);
|
|
126
134
|
|
|
127
135
|
// check type of value
|
|
128
136
|
if (typeof value !== 'string') {
|
package/src/useCodeMirror.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { indentWithTab } from '@codemirror/commands';
|
|
|
4
4
|
import { EditorView, keymap, ViewUpdate, placeholder } from '@codemirror/view';
|
|
5
5
|
import { oneDark } from '@codemirror/theme-one-dark';
|
|
6
6
|
import { basicSetup } from './basicSetup';
|
|
7
|
+
import { getStatistics } from './utils';
|
|
7
8
|
import { ReactCodeMirrorProps } from '.';
|
|
8
9
|
|
|
9
10
|
export interface UseCodeMirror extends ReactCodeMirrorProps {
|
|
@@ -15,6 +16,7 @@ export function useCodeMirror(props: UseCodeMirror) {
|
|
|
15
16
|
value,
|
|
16
17
|
selection,
|
|
17
18
|
onChange,
|
|
19
|
+
onStatistics,
|
|
18
20
|
onUpdate,
|
|
19
21
|
extensions = [],
|
|
20
22
|
autoFocus,
|
|
@@ -32,7 +34,7 @@ export function useCodeMirror(props: UseCodeMirror) {
|
|
|
32
34
|
basicSetup: defaultBasicSetup = true,
|
|
33
35
|
root,
|
|
34
36
|
} = props;
|
|
35
|
-
const [container, setContainer] = useState(
|
|
37
|
+
const [container, setContainer] = useState<HTMLDivElement>();
|
|
36
38
|
const [view, setView] = useState<EditorView>();
|
|
37
39
|
const [state, setState] = useState<EditorState>();
|
|
38
40
|
const defaultLightThemeOption = EditorView.theme(
|
|
@@ -61,6 +63,7 @@ export function useCodeMirror(props: UseCodeMirror) {
|
|
|
61
63
|
const value = doc.toString();
|
|
62
64
|
onChange(value, vu);
|
|
63
65
|
}
|
|
66
|
+
onStatistics && onStatistics(getStatistics(vu));
|
|
64
67
|
});
|
|
65
68
|
|
|
66
69
|
let getExtensions = [updateListener, defaultThemeOption];
|
|
@@ -122,12 +125,14 @@ export function useCodeMirror(props: UseCodeMirror) {
|
|
|
122
125
|
}
|
|
123
126
|
return () => {
|
|
124
127
|
if (view) {
|
|
128
|
+
setState(undefined);
|
|
125
129
|
setView(undefined);
|
|
126
130
|
}
|
|
127
131
|
};
|
|
128
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
129
132
|
}, [container, state]);
|
|
130
133
|
|
|
134
|
+
useEffect(() => setContainer(props.container!), [props.container]);
|
|
135
|
+
|
|
131
136
|
useEffect(
|
|
132
137
|
() => () => {
|
|
133
138
|
if (view) {
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { EditorSelection, SelectionRange } from '@codemirror/state';
|
|
2
|
+
import { ViewUpdate } from '@codemirror/view';
|
|
3
|
+
|
|
4
|
+
export interface Statistics {
|
|
5
|
+
/** Get the number of lines in the editor. */
|
|
6
|
+
lineCount: number;
|
|
7
|
+
/** Cursor Position */
|
|
8
|
+
selection: EditorSelection;
|
|
9
|
+
/** Retrieves a list of all current selections. */
|
|
10
|
+
ranges: readonly SelectionRange[];
|
|
11
|
+
/** Get the currently selected code. */
|
|
12
|
+
selectionCode: string;
|
|
13
|
+
/**
|
|
14
|
+
* The length of the given array should be the same as the number of active selections.
|
|
15
|
+
* Replaces the content of the selections with the strings in the array.
|
|
16
|
+
*/
|
|
17
|
+
selections: string[];
|
|
18
|
+
/** Return true if any text is selected. */
|
|
19
|
+
selectedText: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const getStatistics = (view: ViewUpdate): Statistics => ({
|
|
23
|
+
lineCount: view.state.doc.lines,
|
|
24
|
+
selection: view.state.selection,
|
|
25
|
+
ranges: view.state.selection.ranges,
|
|
26
|
+
selectionCode: view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to),
|
|
27
|
+
selections: view.state.selection.ranges.map((r) => view.state.sliceDoc(r.from, r.to)),
|
|
28
|
+
selectedText: view.state.selection.ranges.some((r) => !r.empty),
|
|
29
|
+
});
|