@uiw/react-codemirror 4.8.1 → 4.9.2

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/esm/index.js CHANGED
@@ -4,6 +4,7 @@ var _excluded = ["className", "value", "selection", "extensions", "onChange", "o
4
4
  import React, { useEffect, useRef, useImperativeHandle } from 'react';
5
5
  import { useCodeMirror } from './useCodeMirror';
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
7
+ export * from './basicSetup';
7
8
  export * from './useCodeMirror';
8
9
  var ReactCodeMirror = /*#__PURE__*/React.forwardRef((props, ref) => {
9
10
  var {
package/esm/index.js.map CHANGED
@@ -45,7 +45,7 @@
45
45
  "../src/index.tsx"
46
46
  ],
47
47
  "sourcesContent": [
48
- "import React, { useEffect, useRef, useImperativeHandle } from 'react';\nimport { EditorState, EditorStateConfig, Extension } from '@codemirror/state';\nimport { EditorView, ViewUpdate } from '@codemirror/view';\nimport { useCodeMirror } from './useCodeMirror';\n\nexport * from './useCodeMirror';\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;\n /**\n * This disables editing of the editor content by the user.\n * @default true\n */\n editable?: boolean;\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 /** Fired whenever a change occurs to the document. There is a certain difference with `onChange`. */\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 = React.forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProps>((props, ref) => {\n const {\n className,\n value = '',\n selection,\n extensions = [],\n onChange,\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 onUpdate,\n extensions,\n });\n useImperativeHandle(ref, () => ({ editor: container, state, view }), [container, state, view]);\n useEffect(() => {\n setContainer(editor.current);\n // eslint-disable-next-line react-hooks/exhaustive-deps\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"
48
+ "import React, { useEffect, useRef, useImperativeHandle } from 'react';\nimport { EditorState, EditorStateConfig, Extension } from '@codemirror/state';\nimport { EditorView, ViewUpdate } from '@codemirror/view';\nimport { useCodeMirror } from './useCodeMirror';\nimport { BasicSetupOptions } from './basicSetup';\n\nexport * from './basicSetup';\nexport * from './useCodeMirror';\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 /** Fired whenever a change occurs to the document. There is a certain difference with `onChange`. */\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 = React.forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProps>((props, ref) => {\n const {\n className,\n value = '',\n selection,\n extensions = [],\n onChange,\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 onUpdate,\n extensions,\n });\n useImperativeHandle(ref, () => ({ editor: container, state, view }), [container, state, view]);\n useEffect(() => {\n setContainer(editor.current);\n // eslint-disable-next-line react-hooks/exhaustive-deps\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,SAAhB,EAA2BC,MAA3B,EAAmCC,mBAAnC,QAA8D,OAA9D;AAGA,SAASC,aAAT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orView } from '@codemirror/view';
4
- import { ReactCodeMirrorProps } from './';
3
+ import { ReactCodeMirrorProps } from '.';
5
4
  export interface UseCodeMirror extends ReactCodeMirrorProps {
6
5
  container?: HTMLDivElement | null;
7
6
  }
@@ -1,9 +1,9 @@
1
1
  import { useEffect, useState } from 'react';
2
- import { basicSetup } from 'codemirror';
3
2
  import { EditorState, StateEffect } from '@codemirror/state';
4
3
  import { indentWithTab } from '@codemirror/commands';
5
4
  import { EditorView, keymap, placeholder } from '@codemirror/view';
6
5
  import { oneDark } from '@codemirror/theme-one-dark';
6
+ import { basicSetup } from './basicSetup';
7
7
  export function useCodeMirror(props) {
8
8
  var {
9
9
  value,
@@ -62,7 +62,11 @@ export function useCodeMirror(props) {
62
62
  }
63
63
 
64
64
  if (defaultBasicSetup) {
65
- getExtensions.unshift(basicSetup);
65
+ if (typeof defaultBasicSetup === 'boolean') {
66
+ getExtensions.unshift(basicSetup());
67
+ } else {
68
+ getExtensions.unshift(basicSetup(defaultBasicSetup));
69
+ }
66
70
  }
67
71
 
68
72
  if (placeholderStr) {
@@ -3,7 +3,6 @@
3
3
  "names": [
4
4
  "useEffect",
5
5
  "useState",
6
- "basicSetup",
7
6
  "EditorState",
8
7
  "StateEffect",
9
8
  "indentWithTab",
@@ -11,6 +10,7 @@
11
10
  "keymap",
12
11
  "placeholder",
13
12
  "oneDark",
13
+ "basicSetup",
14
14
  "useCodeMirror",
15
15
  "props",
16
16
  "value",
@@ -73,7 +73,7 @@
73
73
  "../src/useCodeMirror.ts"
74
74
  ],
75
75
  "sourcesContent": [
76
- "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 './';\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 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 });\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"
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(props.container);\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 });\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 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"
77
77
  ],
78
- "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;AAOA,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;IAWJb,WAAW,EAAEc,cAAc,GAAG,EAX1B;IAYJC,KAAK,GAAG,EAZJ;IAaJC,QAAQ,GAAG,EAbP;IAcJC,QAAQ,GAAG,EAdP;IAeJC,QAAQ,GAAG,IAfP;IAgBJC,QAAQ,GAAG,KAhBP;IAiBJtB,aAAa,EAAEuB,oBAAoB,GAAG,IAjBlC;IAkBJ1B,UAAU,EAAE2B,iBAAiB,GAAG,IAlB5B;IAmBJC;EAnBI,IAoBFnB,KApBJ;EAqBA,IAAM,CAACoB,SAAD,EAAYC,YAAZ,IAA4B/B,QAAQ,CAACU,KAAK,CAACoB,SAAP,CAA1C;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;MACrBA,IAAI,CAACwB,KAAL;IACD;EACF,CAJQ,EAIN,CAACxC,SAAD,EAAYgB,IAAZ,CAJM,CAAT;EAMAjC,SAAS,CAAC,MAAM;IACd,IAAM0D,YAAY,GAAGzB,IAAI,GAAGA,IAAI,CAACE,KAAL,CAAWU,GAAX,CAAeC,QAAf,EAAH,GAA+B,EAAxD;;IACA,IAAIb,IAAI,IAAIrB,KAAK,KAAK8C,YAAtB,EAAoC;MAClCzB,IAAI,CAAC0B,QAAL,CAAc;QACZC,OAAO,EAAE;UAAEC,IAAI,EAAE,CAAR;UAAWC,EAAE,EAAEJ,YAAY,CAACK,MAA5B;UAAoCC,MAAM,EAAEpD,KAAK,IAAI;QAArD;MADG,CAAd;IAGD;EACF,CAPQ,EAON,CAACA,KAAD,EAAQqB,IAAR,CAPM,CAAT;EASAjC,SAAS,CAAC,MAAM;IACd,IAAIiC,IAAJ,EAAU;MACRA,IAAI,CAAC0B,QAAL,CAAc;QAAEM,OAAO,EAAE9D,WAAW,CAAC+D,WAAZ,CAAwBxB,EAAxB,CAA2BK,aAA3B;MAAX,CAAd;IACD,CAHa,CAId;;EACD,CALQ,EAKN,CACD7B,KADC,EAEDF,UAFC,EAGDG,MAHC,EAIDC,SAJC,EAKDC,SALC,EAMDE,KANC,EAODD,cAPC,EAQDE,QARC,EASDC,QATC,EAUDC,QAVC,EAWDE,oBAXC,EAYDC,iBAZC,CALM,CAAT;EAoBA,OAAO;IAAEM,KAAF;IAASC,QAAT;IAAmBH,IAAnB;IAAyBC,OAAzB;IAAkCH,SAAlC;IAA6CC;EAA7C,CAAP;AACD"
79
79
  }
package/package.json CHANGED
@@ -1,60 +1,31 @@
1
1
  {
2
2
  "name": "@uiw/react-codemirror",
3
- "version": "4.8.1",
3
+ "version": "4.9.2",
4
4
  "description": "CodeMirror component for React.",
5
5
  "homepage": "https://uiwjs.github.io/react-codemirror",
6
- "main": "cjs/index.js",
7
- "module": "esm/index.js",
8
- "exports": {
9
- "import": "./esm/index.js",
10
- "require": "./cjs/index.js"
11
- },
6
+ "author": "kenny wong <wowohoo@qq.com>",
7
+ "license": "MIT",
8
+ "main": "./cjs/index.js",
9
+ "module": "./esm/index.js",
12
10
  "scripts": {
13
- "prepare": "husky install && npm run build",
11
+ "bundle": "ncc build src/index.tsx --target web --filename mdeditor && npm run bundle:min",
12
+ "bundle:watch": "ncc watch src/index.tsx --target web --filename mdeditor",
13
+ "bundle:min": "ncc build src/index.tsx --target web --filename mdeditor --minify",
14
14
  "watch": "tsbb watch",
15
15
  "build": "tsbb build",
16
- "bundle": "ncc build src/index.tsx --target web --filename codemirror",
17
- "bundle:min": "ncc build src/index.tsx --target web --filename codemirror --minify",
18
16
  "test": "tsbb test --env=jsdom",
19
- "coverage": "tsbb test --coverage --bail",
20
- "doc": "kkt build --app-src ./website",
21
- "start": "kkt start --app-src ./website",
22
- "prettier": "prettier --write '**/*.{js,jsx,tsx,ts,html,less,md,json}'"
17
+ "coverage": "tsbb test --env=jsdom --coverage --bail"
23
18
  },
24
19
  "repository": {
25
20
  "type": "git",
26
21
  "url": "https://github.com/uiwjs/react-codemirror.git"
27
22
  },
28
- "keywords": [
29
- "react",
30
- "codemirror",
31
- "codemirror6",
32
- "react-codemirror",
33
- "editor",
34
- "syntax",
35
- "ide",
36
- "code"
37
- ],
38
23
  "files": [
39
24
  "dist",
40
25
  "src",
41
26
  "esm",
42
27
  "cjs"
43
28
  ],
44
- "author": "kenny wong <wowohoo@qq.com>",
45
- "license": "MIT",
46
- "jest": {
47
- "coverageReporters": [
48
- "lcov",
49
- "json-summary"
50
- ]
51
- },
52
- "eslintConfig": {
53
- "extends": [
54
- "react-app",
55
- "react-app/jest"
56
- ]
57
- },
58
29
  "peerDependencies": {
59
30
  "@babel/runtime": ">=7.11.0",
60
31
  "react": ">=16.8.0",
@@ -65,55 +36,20 @@
65
36
  "@codemirror/theme-one-dark": "^6.0.0",
66
37
  "codemirror": "^6.0.0"
67
38
  },
68
- "devDependencies": {
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",
82
- "@kkt/less-modules": "~7.1.1",
83
- "@kkt/ncc": "~1.0.8",
84
- "@kkt/raw-modules": "~7.1.1",
85
- "@kkt/scope-plugin-options": "~7.1.1",
86
- "@testing-library/react": "^13.0.0",
87
- "@types/react": "~18.0.1",
88
- "@types/react-dom": "~18.0.0",
89
- "@types/react-test-renderer": "~18.0.0",
90
- "@uiw/react-github-corners": "~1.5.14",
91
- "@uiw/react-markdown-preview": "~4.0.5",
92
- "@uiw/react-shields": "~1.1.3",
93
- "@uiw/reset.css": "~1.0.5",
94
- "@wcj/dark-mode": "~1.0.12",
95
- "code-example": "~3.3.1",
96
- "husky": "~8.0.0",
97
- "kkt": "~7.1.5",
98
- "lint-staged": "~13.0.0",
99
- "markdown-react-code-preview-loader": "^2.1.2",
100
- "prettier": "~2.6.0",
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",
105
- "tsbb": "~3.7.0"
106
- },
107
- "browserslist": {
108
- "production": [
109
- ">0.2%",
110
- "not dead",
111
- "not op_mini all"
112
- ],
113
- "development": [
114
- "last 1 chrome version",
115
- "last 1 firefox version",
116
- "last 1 safari version"
39
+ "keywords": [
40
+ "react",
41
+ "codemirror",
42
+ "codemirror6",
43
+ "react-codemirror",
44
+ "editor",
45
+ "syntax",
46
+ "ide",
47
+ "code"
48
+ ],
49
+ "jest": {
50
+ "coverageReporters": [
51
+ "lcov",
52
+ "json-summary"
117
53
  ]
118
54
  }
119
55
  }
@@ -0,0 +1,136 @@
1
+ import {
2
+ KeyBinding,
3
+ lineNumbers,
4
+ highlightActiveLineGutter,
5
+ highlightSpecialChars,
6
+ drawSelection,
7
+ dropCursor,
8
+ rectangularSelection,
9
+ crosshairCursor,
10
+ highlightActiveLine,
11
+ keymap,
12
+ } from '@codemirror/view';
13
+ import { EditorState, Extension } from '@codemirror/state';
14
+ import { history, defaultKeymap, historyKeymap } from '@codemirror/commands';
15
+ import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';
16
+ import { closeBrackets, autocompletion, closeBracketsKeymap, completionKeymap } from '@codemirror/autocomplete';
17
+ import {
18
+ foldGutter,
19
+ indentOnInput,
20
+ syntaxHighlighting,
21
+ defaultHighlightStyle,
22
+ bracketMatching,
23
+ foldKeymap,
24
+ } from '@codemirror/language';
25
+ import { lintKeymap } from '@codemirror/lint';
26
+
27
+ export interface BasicSetupOptions {
28
+ lineNumbers?: boolean;
29
+ highlightActiveLineGutter?: boolean;
30
+ highlightSpecialChars?: boolean;
31
+ history?: boolean;
32
+ foldGutter?: boolean;
33
+ drawSelection?: boolean;
34
+ dropCursor?: boolean;
35
+ allowMultipleSelections?: boolean;
36
+ indentOnInput?: boolean;
37
+ syntaxHighlighting?: boolean;
38
+ bracketMatching?: boolean;
39
+ closeBrackets?: boolean;
40
+ autocompletion?: boolean;
41
+ rectangularSelection?: boolean;
42
+ crosshairCursor?: boolean;
43
+ highlightActiveLine?: boolean;
44
+ highlightSelectionMatches?: boolean;
45
+
46
+ closeBracketsKeymap?: boolean;
47
+ defaultKeymap?: boolean;
48
+ searchKeymap?: boolean;
49
+ historyKeymap?: boolean;
50
+ foldKeymap?: boolean;
51
+ completionKeymap?: boolean;
52
+ lintKeymap?: boolean;
53
+ }
54
+
55
+ /**
56
+ This is an extension value that just pulls together a number of
57
+ extensions that you might want in a basic editor. It is meant as a
58
+ convenient helper to quickly set up CodeMirror without installing
59
+ and importing a lot of separate packages.
60
+
61
+ Specifically, it includes...
62
+
63
+ - [the default command bindings](https://codemirror.net/6/docs/ref/#commands.defaultKeymap)
64
+ - [line numbers](https://codemirror.net/6/docs/ref/#view.lineNumbers)
65
+ - [special character highlighting](https://codemirror.net/6/docs/ref/#view.highlightSpecialChars)
66
+ - [the undo history](https://codemirror.net/6/docs/ref/#commands.history)
67
+ - [a fold gutter](https://codemirror.net/6/docs/ref/#language.foldGutter)
68
+ - [custom selection drawing](https://codemirror.net/6/docs/ref/#view.drawSelection)
69
+ - [drop cursor](https://codemirror.net/6/docs/ref/#view.dropCursor)
70
+ - [multiple selections](https://codemirror.net/6/docs/ref/#state.EditorState^allowMultipleSelections)
71
+ - [reindentation on input](https://codemirror.net/6/docs/ref/#language.indentOnInput)
72
+ - [the default highlight style](https://codemirror.net/6/docs/ref/#language.defaultHighlightStyle) (as fallback)
73
+ - [bracket matching](https://codemirror.net/6/docs/ref/#language.bracketMatching)
74
+ - [bracket closing](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets)
75
+ - [autocompletion](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion)
76
+ - [rectangular selection](https://codemirror.net/6/docs/ref/#view.rectangularSelection) and [crosshair cursor](https://codemirror.net/6/docs/ref/#view.crosshairCursor)
77
+ - [active line highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLine)
78
+ - [active line gutter highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLineGutter)
79
+ - [selection match highlighting](https://codemirror.net/6/docs/ref/#search.highlightSelectionMatches)
80
+ - [search](https://codemirror.net/6/docs/ref/#search.searchKeymap)
81
+ - [linting](https://codemirror.net/6/docs/ref/#lint.lintKeymap)
82
+
83
+ (You'll probably want to add some language package to your setup
84
+ too.)
85
+
86
+ This extension does not allow customization. The idea is that,
87
+ once you decide you want to configure your editor more precisely,
88
+ you take this package's source (which is just a bunch of imports
89
+ and an array literal), copy it into your own code, and adjust it
90
+ as desired.
91
+ */
92
+ export const basicSetup = (options: BasicSetupOptions = {}): Extension[] => {
93
+ const keymaps: KeyBinding[][] = [];
94
+ if (options.closeBracketsKeymap !== false) {
95
+ keymaps.push([...closeBracketsKeymap]);
96
+ }
97
+ if (options.defaultKeymap !== false) {
98
+ keymaps.push([...defaultKeymap]);
99
+ }
100
+ if (options.searchKeymap !== false) {
101
+ keymaps.push([...searchKeymap]);
102
+ }
103
+ if (options.historyKeymap !== false) {
104
+ keymaps.push([...historyKeymap]);
105
+ }
106
+ if (options.foldKeymap !== false) {
107
+ keymaps.push([...foldKeymap]);
108
+ }
109
+ if (options.completionKeymap !== false) {
110
+ keymaps.push([...completionKeymap]);
111
+ }
112
+ if (options.lintKeymap !== false) {
113
+ keymaps.push([...lintKeymap]);
114
+ }
115
+ const extensions: Extension[] = [];
116
+ if (options.lineNumbers !== false) extensions.push(lineNumbers());
117
+ if (options.highlightActiveLineGutter !== false) extensions.push(highlightActiveLineGutter());
118
+ if (options.highlightSpecialChars !== false) extensions.push(highlightSpecialChars());
119
+ if (options.history !== false) extensions.push(history());
120
+ if (options.foldGutter !== false) extensions.push(foldGutter());
121
+ if (options.drawSelection !== false) extensions.push(drawSelection());
122
+ if (options.dropCursor !== false) extensions.push(dropCursor());
123
+ if (options.allowMultipleSelections !== false) extensions.push(EditorState.allowMultipleSelections.of(true));
124
+ if (options.indentOnInput !== false) extensions.push(indentOnInput());
125
+ if (options.syntaxHighlighting !== false)
126
+ extensions.push(syntaxHighlighting(defaultHighlightStyle, { fallback: true }));
127
+ if (options.bracketMatching !== false) extensions.push(bracketMatching());
128
+ if (options.closeBrackets !== false) extensions.push(closeBrackets());
129
+ if (options.autocompletion !== false) extensions.push(autocompletion());
130
+ if (options.rectangularSelection !== false) extensions.push(rectangularSelection());
131
+ if (options.crosshairCursor !== false) extensions.push(crosshairCursor());
132
+ if (options.highlightActiveLine !== false) extensions.push(highlightActiveLine());
133
+ if (options.highlightSelectionMatches !== false) extensions.push(highlightSelectionMatches());
134
+
135
+ return [...extensions, keymap.of(keymaps.flat())].filter(Boolean);
136
+ };
package/src/index.tsx CHANGED
@@ -2,7 +2,9 @@ import React, { useEffect, useRef, 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 { BasicSetupOptions } from './basicSetup';
5
6
 
7
+ export * from './basicSetup';
6
8
  export * from './useCodeMirror';
7
9
 
8
10
  export interface ReactCodeMirrorProps
@@ -29,12 +31,16 @@ export interface ReactCodeMirrorProps
29
31
  * Whether to optional basicSetup by default
30
32
  * @default true
31
33
  */
32
- basicSetup?: boolean;
34
+ basicSetup?: boolean | BasicSetupOptions;
33
35
  /**
34
36
  * This disables editing of the editor content by the user.
35
37
  * @default true
36
38
  */
37
39
  editable?: boolean;
40
+ /**
41
+ * This disables editing of the editor content by the user.
42
+ * @default false
43
+ */
38
44
  readOnly?: boolean;
39
45
  /**
40
46
  * Whether to optional basicSetup by default
@@ -1,10 +1,10 @@
1
1
  import { useEffect, useState } from 'react';
2
- import { basicSetup } from 'codemirror';
3
2
  import { EditorState, StateEffect } from '@codemirror/state';
4
3
  import { indentWithTab } from '@codemirror/commands';
5
4
  import { EditorView, keymap, ViewUpdate, placeholder } from '@codemirror/view';
6
5
  import { oneDark } from '@codemirror/theme-one-dark';
7
- import { ReactCodeMirrorProps } from './';
6
+ import { basicSetup } from './basicSetup';
7
+ import { ReactCodeMirrorProps } from '.';
8
8
 
9
9
  export interface UseCodeMirror extends ReactCodeMirrorProps {
10
10
  container?: HTMLDivElement | null;
@@ -62,12 +62,17 @@ export function useCodeMirror(props: UseCodeMirror) {
62
62
  onChange(value, vu);
63
63
  }
64
64
  });
65
+
65
66
  let getExtensions = [updateListener, defaultThemeOption];
66
67
  if (defaultIndentWithTab) {
67
68
  getExtensions.unshift(keymap.of([indentWithTab]));
68
69
  }
69
70
  if (defaultBasicSetup) {
70
- getExtensions.unshift(basicSetup);
71
+ if (typeof defaultBasicSetup === 'boolean') {
72
+ getExtensions.unshift(basicSetup());
73
+ } else {
74
+ getExtensions.unshift(basicSetup(defaultBasicSetup));
75
+ }
71
76
  }
72
77
 
73
78
  if (placeholderStr) {
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 uiw
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.