@uiw/react-codemirror 4.7.0 → 4.8.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 +8 -5
- package/cjs/index.d.ts +0 -3
- package/cjs/index.js +0 -41
- package/cjs/index.js.map +10 -6
- package/cjs/theme/light.js.map +5 -5
- package/cjs/useCodeMirror.js +2 -2
- package/cjs/useCodeMirror.js.map +8 -6
- package/dist/codemirror.js +4009 -324
- package/dist/codemirror.min.js +1 -1
- package/esm/index.d.ts +0 -3
- package/esm/index.js +0 -3
- package/esm/index.js.map +6 -6
- package/esm/theme/light.js.map +5 -5
- package/esm/useCodeMirror.js +1 -1
- package/esm/useCodeMirror.js.map +6 -6
- package/package.json +23 -24
- package/src/index.tsx +0 -3
- package/src/useCodeMirror.ts +1 -1
package/esm/useCodeMirror.js.map
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
4
|
-
"../src/useCodeMirror.ts"
|
|
5
|
-
],
|
|
6
3
|
"names": [
|
|
7
4
|
"useEffect",
|
|
8
5
|
"useState",
|
|
@@ -70,8 +67,11 @@
|
|
|
70
67
|
"effects",
|
|
71
68
|
"reconfigure"
|
|
72
69
|
],
|
|
73
|
-
"
|
|
70
|
+
"sources": [
|
|
71
|
+
"../src/useCodeMirror.ts"
|
|
72
|
+
],
|
|
74
73
|
"sourcesContent": [
|
|
75
|
-
"import { useEffect, useState } from 'react';\nimport { basicSetup } from '
|
|
76
|
-
]
|
|
74
|
+
"import { useEffect, useState } from 'react';\nimport { basicSetup } from 'codemirror';\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 { ReactCodeMirrorProps } from './';\nimport { defaultLightThemeOption } from './theme/light';\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(props.container);\n const [view, setView] = useState<EditorView>();\n const [state, setState] = useState<EditorState>();\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 });\n let getExtensions = [updateListener, defaultThemeOption];\n if (defaultIndentWithTab) {\n getExtensions.unshift(keymap.of([indentWithTab]));\n }\n if (defaultBasicSetup) {\n getExtensions.unshift(basicSetup);\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 setView(undefined);\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [container, state]);\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 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 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 placeholderStr,\n minWidth,\n maxWidth,\n editable,\n defaultIndentWithTab,\n defaultBasicSetup,\n ]);\n\n return { state, setState, view, setView, container, setContainer };\n}\n"
|
|
75
|
+
],
|
|
76
|
+
"mappings": "AAAA,SAASA,SAAT,EAAoBC,QAApB,QAAoC,OAApC;AACA,SAASC,UAAT,QAA2B,YAA3B;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;AAEA,SAASC,uBAAT,QAAwC,eAAxC;AAMA,OAAO,SAASC,aAAT,CAAuBC,KAAvB,EAA6C;EAClD,IAAM;IACJC,KADI;IAEJC,SAFI;IAGJC,QAHI;IAIJC,QAJI;IAKJC,UAAU,GAAG,EALT;IAMJC,SANI;IAOJC,KAAK,GAAG,OAPJ;IAQJC,MAAM,GAAG,EARL;IASJC,SAAS,GAAG,EATR;IAUJC,SAAS,GAAG,EAVR;IAWJd,WAAW,EAAEe,cAAc,GAAG,EAX1B;IAYJC,KAAK,GAAG,EAZJ;IAaJC,QAAQ,GAAG,EAbP;IAcJC,QAA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EAoBA,OAAO;IAAEM,KAAF;IAASC,QAAT;IAAmBH,IAAnB;IAAyBC,OAAzB;IAAkCH,SAAlC;IAA6CC;EAA7C,CAAP;AACD"
|
|
77
77
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-codemirror",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.0",
|
|
4
4
|
"description": "CodeMirror component for React.",
|
|
5
5
|
"homepage": "https://uiwjs.github.io/react-codemirror",
|
|
6
6
|
"main": "cjs/index.js",
|
|
@@ -62,26 +62,23 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@babel/runtime": ">=7.11.0",
|
|
65
|
-
"@codemirror/
|
|
66
|
-
"
|
|
67
|
-
"@codemirror/theme-one-dark": "^0.20.0",
|
|
68
|
-
"@codemirror/view": "^0.20.0"
|
|
65
|
+
"@codemirror/theme-one-dark": "^6.0.0",
|
|
66
|
+
"codemirror": "^6.0.0"
|
|
69
67
|
},
|
|
70
68
|
"devDependencies": {
|
|
71
|
-
"@codemirror/lang-cpp": "~0.
|
|
72
|
-
"@codemirror/lang-html": "~0.
|
|
73
|
-
"@codemirror/lang-java": "~0.
|
|
74
|
-
"@codemirror/lang-javascript": "~0.
|
|
75
|
-
"@codemirror/lang-json": "~0.
|
|
76
|
-
"@codemirror/lang-lezer": "~0.
|
|
77
|
-
"@codemirror/lang-markdown": "~0.
|
|
78
|
-
"@codemirror/lang-php": "~0.
|
|
79
|
-
"@codemirror/lang-python": "~0.
|
|
80
|
-
"@codemirror/lang-rust": "~0.
|
|
81
|
-
"@codemirror/lang-sql": "~0.
|
|
82
|
-
"@codemirror/lang-xml": "~0.
|
|
83
|
-
"@codemirror/legacy-modes": "~0.
|
|
84
|
-
"@codemirror/stream-parser": "~0.19.6",
|
|
69
|
+
"@codemirror/lang-cpp": "~6.0.0",
|
|
70
|
+
"@codemirror/lang-html": "~6.0.0",
|
|
71
|
+
"@codemirror/lang-java": "~6.0.0",
|
|
72
|
+
"@codemirror/lang-javascript": "~6.0.0",
|
|
73
|
+
"@codemirror/lang-json": "~6.0.0",
|
|
74
|
+
"@codemirror/lang-lezer": "~6.0.0",
|
|
75
|
+
"@codemirror/lang-markdown": "~6.0.0",
|
|
76
|
+
"@codemirror/lang-php": "~6.0.0",
|
|
77
|
+
"@codemirror/lang-python": "~6.0.0",
|
|
78
|
+
"@codemirror/lang-rust": "~6.0.0",
|
|
79
|
+
"@codemirror/lang-sql": "~6.0.0",
|
|
80
|
+
"@codemirror/lang-xml": "~6.0.0",
|
|
81
|
+
"@codemirror/legacy-modes": "~6.0.0",
|
|
85
82
|
"@kkt/less-modules": "~7.1.1",
|
|
86
83
|
"@kkt/ncc": "~1.0.8",
|
|
87
84
|
"@kkt/raw-modules": "~7.1.1",
|
|
@@ -96,13 +93,15 @@
|
|
|
96
93
|
"@uiw/reset.css": "~1.0.5",
|
|
97
94
|
"@wcj/dark-mode": "~1.0.12",
|
|
98
95
|
"code-example": "~3.3.1",
|
|
99
|
-
"husky": "~
|
|
96
|
+
"husky": "~8.0.0",
|
|
100
97
|
"kkt": "~7.1.5",
|
|
101
|
-
"lint-staged": "~
|
|
98
|
+
"lint-staged": "~13.0.0",
|
|
99
|
+
"markdown-react-code-preview-loader": "^2.1.2",
|
|
102
100
|
"prettier": "~2.6.0",
|
|
103
|
-
"react": "~18.
|
|
104
|
-
"react-
|
|
105
|
-
"react-
|
|
101
|
+
"react": "~18.1.0",
|
|
102
|
+
"react-code-preview-layout": "^2.0.2",
|
|
103
|
+
"react-dom": "~18.1.0",
|
|
104
|
+
"react-test-renderer": "~18.1.0",
|
|
106
105
|
"tsbb": "~3.7.0"
|
|
107
106
|
},
|
|
108
107
|
"browserslist": {
|
package/src/index.tsx
CHANGED
|
@@ -3,9 +3,6 @@ import { EditorState, EditorStateConfig, Extension } from '@codemirror/state';
|
|
|
3
3
|
import { EditorView, ViewUpdate } from '@codemirror/view';
|
|
4
4
|
import { useCodeMirror } from './useCodeMirror';
|
|
5
5
|
|
|
6
|
-
export * from '@codemirror/view';
|
|
7
|
-
export * from '@codemirror/basic-setup';
|
|
8
|
-
export * from '@codemirror/state';
|
|
9
6
|
export * from './useCodeMirror';
|
|
10
7
|
|
|
11
8
|
export interface ReactCodeMirrorProps
|
package/src/useCodeMirror.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
import { basicSetup } from '
|
|
2
|
+
import { basicSetup } from 'codemirror';
|
|
3
3
|
import { EditorState, StateEffect } from '@codemirror/state';
|
|
4
4
|
import { indentWithTab } from '@codemirror/commands';
|
|
5
5
|
import { EditorView, keymap, ViewUpdate, placeholder } from '@codemirror/view';
|