@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/cjs/useCodeMirror.js.map
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"names": [
|
|
4
|
-
"_react",
|
|
5
|
-
"require",
|
|
6
|
-
"_state",
|
|
7
|
-
"_commands",
|
|
8
|
-
"_view",
|
|
9
|
-
"_codemirrorExtensionsBasicSetup",
|
|
10
|
-
"_themeOneDark",
|
|
11
|
-
"_utils",
|
|
12
|
-
"External",
|
|
13
|
-
"Annotation",
|
|
14
|
-
"define",
|
|
15
|
-
"useCodeMirror",
|
|
16
|
-
"props",
|
|
17
|
-
"value",
|
|
18
|
-
"selection",
|
|
19
|
-
"onChange",
|
|
20
|
-
"onStatistics",
|
|
21
|
-
"onCreateEditor",
|
|
22
|
-
"onUpdate",
|
|
23
|
-
"_props$extensions",
|
|
24
|
-
"extensions",
|
|
25
|
-
"autoFocus",
|
|
26
|
-
"_props$theme",
|
|
27
|
-
"theme",
|
|
28
|
-
"_props$height",
|
|
29
|
-
"height",
|
|
30
|
-
"_props$minHeight",
|
|
31
|
-
"minHeight",
|
|
32
|
-
"_props$maxHeight",
|
|
33
|
-
"maxHeight",
|
|
34
|
-
"_props$placeholder",
|
|
35
|
-
"placeholder",
|
|
36
|
-
"placeholderStr",
|
|
37
|
-
"_props$width",
|
|
38
|
-
"width",
|
|
39
|
-
"_props$minWidth",
|
|
40
|
-
"minWidth",
|
|
41
|
-
"_props$maxWidth",
|
|
42
|
-
"maxWidth",
|
|
43
|
-
"_props$editable",
|
|
44
|
-
"editable",
|
|
45
|
-
"_props$readOnly",
|
|
46
|
-
"readOnly",
|
|
47
|
-
"_props$indentWithTab",
|
|
48
|
-
"indentWithTab",
|
|
49
|
-
"defaultIndentWithTab",
|
|
50
|
-
"_props$basicSetup",
|
|
51
|
-
"basicSetup",
|
|
52
|
-
"defaultBasicSetup",
|
|
53
|
-
"root",
|
|
54
|
-
"initialState",
|
|
55
|
-
"_useState",
|
|
56
|
-
"useState",
|
|
57
|
-
"_useState2",
|
|
58
|
-
"_slicedToArray2",
|
|
59
|
-
"container",
|
|
60
|
-
"setContainer",
|
|
61
|
-
"_useState3",
|
|
62
|
-
"_useState4",
|
|
63
|
-
"view",
|
|
64
|
-
"setView",
|
|
65
|
-
"_useState5",
|
|
66
|
-
"_useState6",
|
|
67
|
-
"state",
|
|
68
|
-
"setState",
|
|
69
|
-
"defaultLightThemeOption",
|
|
70
|
-
"EditorView",
|
|
71
|
-
"backgroundColor",
|
|
72
|
-
"dark",
|
|
73
|
-
"defaultThemeOption",
|
|
74
|
-
"updateListener",
|
|
75
|
-
"of",
|
|
76
|
-
"vu",
|
|
77
|
-
"docChanged",
|
|
78
|
-
"transactions",
|
|
79
|
-
"some",
|
|
80
|
-
"tr",
|
|
81
|
-
"annotation",
|
|
82
|
-
"doc",
|
|
83
|
-
"toString",
|
|
84
|
-
"getStatistics",
|
|
85
|
-
"getExtensions",
|
|
86
|
-
"unshift",
|
|
87
|
-
"keymap",
|
|
88
|
-
"push",
|
|
89
|
-
"oneDark",
|
|
90
|
-
"EditorState",
|
|
91
|
-
"concat",
|
|
92
|
-
"useEffect",
|
|
93
|
-
"config",
|
|
94
|
-
"stateCurrent",
|
|
95
|
-
"fromJSON",
|
|
96
|
-
"json",
|
|
97
|
-
"fields",
|
|
98
|
-
"create",
|
|
99
|
-
"viewCurrent",
|
|
100
|
-
"parent",
|
|
101
|
-
"undefined",
|
|
102
|
-
"destroy",
|
|
103
|
-
"focus",
|
|
104
|
-
"dispatch",
|
|
105
|
-
"effects",
|
|
106
|
-
"StateEffect",
|
|
107
|
-
"reconfigure",
|
|
108
|
-
"currentValue",
|
|
109
|
-
"changes",
|
|
110
|
-
"from",
|
|
111
|
-
"to",
|
|
112
|
-
"length",
|
|
113
|
-
"insert",
|
|
114
|
-
"annotations"
|
|
115
|
-
],
|
|
116
|
-
"sources": [
|
|
117
|
-
"../src/useCodeMirror.ts"
|
|
118
|
-
],
|
|
119
|
-
"sourcesContent": [
|
|
120
|
-
"import { useEffect, useState } from 'react';\nimport { Annotation, EditorState, StateEffect } from '@codemirror/state';\nimport { indentWithTab } from '@codemirror/commands';\nimport { EditorView, keymap, ViewUpdate, placeholder } from '@codemirror/view';\nimport { basicSetup } from '@uiw/codemirror-extensions-basic-setup';\nimport { oneDark } from '@codemirror/theme-one-dark';\nimport { getStatistics } from './utils';\nimport { ReactCodeMirrorProps } from '.';\n\nconst External = Annotation.define<boolean>();\n\nexport interface UseCodeMirror extends ReactCodeMirrorProps {\n container?: HTMLDivElement | null;\n}\n\nexport function useCodeMirror(props: UseCodeMirror) {\n const {\n value,\n selection,\n onChange,\n onStatistics,\n onCreateEditor,\n onUpdate,\n extensions = [],\n autoFocus,\n theme = 'light',\n height = '',\n minHeight = '',\n maxHeight = '',\n placeholder: placeholderStr = '',\n width = '',\n minWidth = '',\n maxWidth = '',\n editable = true,\n readOnly = false,\n indentWithTab: defaultIndentWithTab = true,\n basicSetup: defaultBasicSetup = true,\n root,\n initialState,\n } = props;\n const [container, setContainer] = useState<HTMLDivElement>();\n const [view, setView] = useState<EditorView>();\n const [state, setState] = useState<EditorState>();\n const defaultLightThemeOption = EditorView.theme(\n {\n '&': {\n backgroundColor: '#fff',\n },\n },\n {\n dark: false,\n },\n );\n const defaultThemeOption = EditorView.theme({\n '&': {\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n },\n });\n const updateListener = EditorView.updateListener.of((vu: ViewUpdate) => {\n if (\n vu.docChanged &&\n typeof onChange === 'function' &&\n // Fix echoing of the remote changes:\n // If transaction is market as remote we don't have to call `onChange` handler again\n !vu.transactions.some((tr) => tr.annotation(External))\n ) {\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 case 'none':\n break;\n default:\n getExtensions.push(theme);\n break;\n }\n\n if (editable === false) {\n getExtensions.push(EditorView.editable.of(false));\n }\n if (readOnly) {\n getExtensions.push(EditorState.readOnly.of(true));\n }\n\n if (onUpdate && typeof onUpdate === 'function') {\n getExtensions.push(EditorView.updateListener.of(onUpdate));\n }\n getExtensions = getExtensions.concat(extensions);\n\n useEffect(() => {\n if (container && !state) {\n const config = {\n doc: value,\n selection,\n extensions: getExtensions,\n };\n const stateCurrent = initialState\n ? EditorState.fromJSON(initialState.json, config, initialState.fields)\n : EditorState.create(config);\n setState(stateCurrent);\n if (!view) {\n const viewCurrent = new EditorView({\n state: stateCurrent,\n parent: container,\n root,\n });\n setView(viewCurrent);\n onCreateEditor && onCreateEditor(viewCurrent, stateCurrent);\n }\n }\n return () => {\n if (view) {\n setState(undefined);\n setView(undefined);\n }\n };\n }, [container, state]);\n\n useEffect(() => setContainer(props.container!), [props.container]);\n\n useEffect(\n () => () => {\n if (view) {\n view.destroy();\n setView(undefined);\n }\n },\n [view],\n );\n\n useEffect(() => {\n if (autoFocus && view) {\n view.focus();\n }\n }, [autoFocus, view]);\n\n useEffect(() => {\n if (view) {\n view.dispatch({ effects: StateEffect.reconfigure.of(getExtensions) });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n theme,\n extensions,\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n placeholderStr,\n editable,\n readOnly,\n defaultIndentWithTab,\n defaultBasicSetup,\n onChange,\n onUpdate,\n ]);\n\n useEffect(() => {\n if (value === undefined) {\n return;\n }\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 annotations: [External.of(true)],\n });\n }\n }, [value, view]);\n\n return { state, setState, view, setView, container, setContainer };\n}\n"
|
|
121
|
-
],
|
|
122
|
-
"mappings": ";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,+BAAA,GAAAJ,OAAA;AACA,I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AAM;IACd,IAAI3E,KAAK,KAAKoF,SAAS,EAAE;MACvB;IACF;IACA,IAAMO,YAAY,GAAG7C,IAAI,GAAGA,IAAI,CAACI,KAAK,CAACe,GAAG,CAACC,QAAQ,EAAE,GAAG,EAAE;IAC1D,IAAIpB,IAAI,IAAI9C,KAAK,KAAK2F,YAAY,EAAE;MAClC7C,IAAI,CAACyC,QAAQ,CAAC;QACZK,OAAO,EAAE;UAAEC,IAAI,EAAE,CAAC;UAAEC,EAAE,EAAEH,YAAY,CAACI,MAAM;UAAEC,MAAM,EAAEhG,KAAK,IAAI;QAAG,CAAC;QAClEiG,WAAW,EAAE,CAACtG,QAAQ,CAAC+D,EAAE,CAAC,IAAI,CAAC;MACjC,CAAC,CAAC;IACJ;EACF,CAAC,EAAE,CAAC1D,KAAK,EAAE8C,IAAI,CAAC,CAAC;EAEjB,OAAO;IAAEI,KAAK,EAALA,KAAK;IAAEC,QAAQ,EAARA,QAAQ;IAAEL,IAAI,EAAJA,IAAI;IAAEC,OAAO,EAAPA,OAAO;IAAEL,SAAS,EAATA,SAAS;IAAEC,YAAY,EAAZA;EAAa,CAAC;AACpE"
|
|
123
|
-
}
|
package/cjs/utils.js.map
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"names": [
|
|
4
|
-
"getStatistics",
|
|
5
|
-
"view",
|
|
6
|
-
"line",
|
|
7
|
-
"state",
|
|
8
|
-
"doc",
|
|
9
|
-
"lineAt",
|
|
10
|
-
"selection",
|
|
11
|
-
"main",
|
|
12
|
-
"from",
|
|
13
|
-
"lineCount",
|
|
14
|
-
"lines",
|
|
15
|
-
"lineBreak",
|
|
16
|
-
"length",
|
|
17
|
-
"readOnly",
|
|
18
|
-
"tabSize",
|
|
19
|
-
"selectionAsSingle",
|
|
20
|
-
"asSingle",
|
|
21
|
-
"ranges",
|
|
22
|
-
"selectionCode",
|
|
23
|
-
"sliceDoc",
|
|
24
|
-
"to",
|
|
25
|
-
"selections",
|
|
26
|
-
"map",
|
|
27
|
-
"r",
|
|
28
|
-
"selectedText",
|
|
29
|
-
"some",
|
|
30
|
-
"empty",
|
|
31
|
-
"exports"
|
|
32
|
-
],
|
|
33
|
-
"sources": [
|
|
34
|
-
"../src/utils.ts"
|
|
35
|
-
],
|
|
36
|
-
"sourcesContent": [
|
|
37
|
-
"import { EditorSelection, SelectionRange, Line } from '@codemirror/state';\nimport { ViewUpdate } from '@codemirror/view';\n\nexport interface Statistics {\n /** total length of the document */\n length: number;\n /** Get the number of lines in the editor. */\n lineCount: number;\n /** Get the currently line description around the given position. */\n line: Line;\n /** Get the proper [line-break](https://codemirror.net/docs/ref/#state.EditorState^lineSeparator) string for this state. */\n lineBreak: string;\n /** Returns true when the editor is [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. */\n readOnly: boolean;\n /** The size (in columns) of a tab in the document, determined by the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. */\n tabSize: number;\n /** Cursor Position */\n selection: EditorSelection;\n /** Make sure the selection only has one range. */\n selectionAsSingle: SelectionRange;\n /** Retrieves a list of all current selections. */\n ranges: readonly SelectionRange[];\n /** Get the currently selected code. */\n selectionCode: string;\n /**\n * The length of the given array should be the same as the number of active selections.\n * Replaces the content of the selections with the strings in the array.\n */\n selections: string[];\n /** Return true if any text is selected. */\n selectedText: boolean;\n}\n\nexport const getStatistics = (view: ViewUpdate): Statistics => {\n return {\n line: view.state.doc.lineAt(view.state.selection.main.from),\n lineCount: view.state.doc.lines,\n lineBreak: view.state.lineBreak,\n length: view.state.doc.length,\n readOnly: view.state.readOnly,\n tabSize: view.state.tabSize,\n selection: view.state.selection,\n selectionAsSingle: view.state.selection.asSingle().main,\n ranges: view.state.selection.ranges,\n selectionCode: view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to),\n selections: view.state.selection.ranges.map((r) => view.state.sliceDoc(r.from, r.to)),\n selectedText: view.state.selection.ranges.some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UAACF,CAAC;MAAA,OAAK,CAACA,CAAC,CAACG,KAAK;IAAA;EAChE,CAAC;AACH,CAAC;AAACC,OAAA,CAAA3B,aAAA,GAAAA,aAAA"
|
|
40
|
-
}
|
package/esm/index.js.map
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"names": [
|
|
4
|
-
"React",
|
|
5
|
-
"useRef",
|
|
6
|
-
"forwardRef",
|
|
7
|
-
"useImperativeHandle",
|
|
8
|
-
"useCodeMirror",
|
|
9
|
-
"jsx",
|
|
10
|
-
"_jsx",
|
|
11
|
-
"ReactCodeMirror",
|
|
12
|
-
"props",
|
|
13
|
-
"ref",
|
|
14
|
-
"className",
|
|
15
|
-
"value",
|
|
16
|
-
"selection",
|
|
17
|
-
"extensions",
|
|
18
|
-
"onChange",
|
|
19
|
-
"onStatistics",
|
|
20
|
-
"onCreateEditor",
|
|
21
|
-
"onUpdate",
|
|
22
|
-
"autoFocus",
|
|
23
|
-
"theme",
|
|
24
|
-
"height",
|
|
25
|
-
"minHeight",
|
|
26
|
-
"maxHeight",
|
|
27
|
-
"width",
|
|
28
|
-
"minWidth",
|
|
29
|
-
"maxWidth",
|
|
30
|
-
"basicSetup",
|
|
31
|
-
"placeholder",
|
|
32
|
-
"indentWithTab",
|
|
33
|
-
"editable",
|
|
34
|
-
"readOnly",
|
|
35
|
-
"root",
|
|
36
|
-
"initialState",
|
|
37
|
-
"other",
|
|
38
|
-
"_objectWithoutPropertiesLoose",
|
|
39
|
-
"_excluded",
|
|
40
|
-
"editor",
|
|
41
|
-
"state",
|
|
42
|
-
"view",
|
|
43
|
-
"container",
|
|
44
|
-
"current",
|
|
45
|
-
"Error",
|
|
46
|
-
"defaultClassNames",
|
|
47
|
-
"_extends",
|
|
48
|
-
"displayName"
|
|
49
|
-
],
|
|
50
|
-
"sources": [
|
|
51
|
-
"../src/index.tsx"
|
|
52
|
-
],
|
|
53
|
-
"sourcesContent": [
|
|
54
|
-
"import React, { useRef, forwardRef, useImperativeHandle } from 'react';\nimport { EditorState, EditorStateConfig, Extension, StateField } from '@codemirror/state';\nimport { EditorView, ViewUpdate } from '@codemirror/view';\nimport { BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';\nimport { useCodeMirror } from './useCodeMirror';\nimport { Statistics } from './utils';\n\nexport * from '@uiw/codemirror-extensions-basic-setup';\nexport * from './useCodeMirror';\nexport * from './utils';\n\nexport interface ReactCodeMirrorProps\n extends Omit<EditorStateConfig, 'doc' | 'extensions'>,\n Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'placeholder'> {\n /** value of the auto created model in the editor. */\n value?: string;\n height?: string;\n minHeight?: string;\n maxHeight?: string;\n width?: string;\n minWidth?: string;\n maxWidth?: string;\n /** focus on the editor. */\n autoFocus?: boolean;\n /** Enables a placeholder—a piece of example content to show when the editor is empty. */\n placeholder?: string | HTMLElement;\n /**\n * `light` / `dark` / `Extension` Defaults to `light`.\n * @default light\n */\n theme?: 'light' | 'dark' | 'none' | Extension;\n /**\n * Whether to optional basicSetup by default\n * @default true\n */\n basicSetup?: boolean | BasicSetupOptions;\n /**\n * This disables editing of the editor content by the user.\n * @default true\n */\n editable?: boolean;\n /**\n * This disables editing of the editor content by the user.\n * @default false\n */\n readOnly?: boolean;\n /**\n * Whether to optional basicSetup by default\n * @default true\n */\n indentWithTab?: boolean;\n /** Fired whenever a change occurs to the document. */\n onChange?(value: string, viewUpdate: ViewUpdate): void;\n /** Some data on the statistics editor. */\n onStatistics?(data: Statistics): void;\n /** Fired whenever any state change occurs within the editor, including non-document changes like lint results. */\n onUpdate?(viewUpdate: ViewUpdate): void;\n /** The first time the editor executes the event. */\n onCreateEditor?(view: EditorView, state: EditorState): void;\n /**\n * Extension values can be [provided](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions) when creating a state to attach various kinds of configuration and behavior information.\n * They can either be built-in extension-providing objects,\n * such as [state fields](https://codemirror.net/6/docs/ref/#state.StateField) or [facet providers](https://codemirror.net/6/docs/ref/#state.Facet.of),\n * or objects with an extension in its `extension` property. Extensions can be nested in arrays arbitrarily deep—they will be flattened when processed.\n */\n extensions?: Extension[];\n /**\n * If the view is going to be mounted in a shadow root or document other than the one held by the global variable document (the default), you should pass it here.\n * Originally from the [config of EditorView](https://codemirror.net/6/docs/ref/#view.EditorView.constructor%5Econfig.root)\n */\n root?: ShadowRoot | Document;\n /**\n * Create a state from its JSON representation serialized with [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) function\n */\n initialState?: {\n json: any;\n fields?: Record<string, StateField<any>>;\n };\n}\n\nexport interface ReactCodeMirrorRef {\n editor?: HTMLDivElement | null;\n state?: EditorState;\n view?: EditorView;\n}\n\nconst ReactCodeMirror = forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProps>((props, ref) => {\n const {\n className,\n value = '',\n selection,\n extensions = [],\n onChange,\n onStatistics,\n onCreateEditor,\n onUpdate,\n autoFocus,\n theme = 'light',\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n basicSetup,\n placeholder,\n indentWithTab,\n editable,\n readOnly,\n root,\n initialState,\n ...other\n } = props;\n const editor = useRef<HTMLDivElement>(null);\n const { state, view, container } = useCodeMirror({\n container: editor.current,\n root,\n value,\n autoFocus,\n theme,\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n basicSetup,\n placeholder,\n indentWithTab,\n editable,\n readOnly,\n selection,\n onChange,\n onStatistics,\n onCreateEditor,\n onUpdate,\n extensions,\n initialState,\n });\n\n useImperativeHandle(ref, () => ({ editor: editor.current, state: state, view: view }), [\n editor,\n container,\n state,\n view,\n ]);\n\n // check type of value\n if (typeof value !== 'string') {\n throw new Error(`value must be typeof string but got ${typeof value}`);\n }\n\n const defaultClassNames = typeof theme === 'string' ? `cm-theme-${theme}` : 'cm-theme';\n return <div ref={editor} className={`${defaultClassNames}${className ? ` ${className}` : ''}`} {...other}></div>;\n});\n\nReactCodeM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EF7B,mBAAmB,CAACM,GAAG,EAAE,OAAO;IAAE2B,MAAM,EAAEA,MAAM,CAACI,OAAO;IAAEH,KAAK,EAAEA,KAAK;IAAEC,IAAI,EAAEA;EAAK,CAAC,CAAC,EAAE,CACrFF,MAAM,EACNG,SAAS,EACTF,KAAK,EACLC,IAAI,CACL,CAAC;;EAEF;EACA,IAAI,OAAO3B,KAAK,KAAK,QAAQ,EAAE;IAC7B,MAAM,IAAI8B,KAAK,0CAAwC,OAAO9B,KAAK,CAAG;EACxE;EAEA,IAAM+B,iBAAiB,GAAG,OAAOvB,KAAK,KAAK,QAAQ,iBAAeA,KAAK,GAAK,UAAU;EACtF,oBAAOb,IAAA,QAAAqC,QAAA;IAAKlC,GAAG,EAAE2B,MAAO;IAAC1B,SAAS,OAAKgC,iBAAiB,IAAGhC,SAAS,SAAOA,SAAS,GAAK,EAAE;EAAG,GAAKuB,KAAK,EAAQ;AAClH,CAAC,CAAC;AAEF1B,eAAe,CAACqC,WAAW,GAAG,YAAY;AAE1C,eAAerC,eAAe"
|
|
57
|
-
}
|
package/esm/theme/light.js.map
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"names": [
|
|
4
|
-
"EditorView",
|
|
5
|
-
"defaultLightThemeOption",
|
|
6
|
-
"theme",
|
|
7
|
-
"backgroundColor",
|
|
8
|
-
"dark"
|
|
9
|
-
],
|
|
10
|
-
"sources": [
|
|
11
|
-
"../../src/theme/light.ts"
|
|
12
|
-
],
|
|
13
|
-
"sourcesContent": [
|
|
14
|
-
"import { EditorView } from '@codemirror/view';\n\nexport const defaultLightThemeOption = EditorView.theme(\n {\n '&': {\n backgroundColor: '#fff',\n },\n },\n {\n dark: false,\n },\n);\n"
|
|
15
|
-
],
|
|
16
|
-
"mappings": "AAAA,SAASA,UAAU,QAAQ,kBAAkB;AAE7C,OAAO,IAAMC,uBAAuB,GAAGD,UAAU,CAACE,KAAK,CACrD;EACE,GAAG,EAAE;IACHC,eAAe,EAAE;EACnB;AACF,CAAC,EACD;EACEC,IAAI,EAAE;AACR,CAAC,CACF"
|
|
17
|
-
}
|
package/esm/useCodeMirror.js.map
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"names": [
|
|
4
|
-
"useEffect",
|
|
5
|
-
"useState",
|
|
6
|
-
"Annotation",
|
|
7
|
-
"EditorState",
|
|
8
|
-
"StateEffect",
|
|
9
|
-
"indentWithTab",
|
|
10
|
-
"EditorView",
|
|
11
|
-
"keymap",
|
|
12
|
-
"placeholder",
|
|
13
|
-
"basicSetup",
|
|
14
|
-
"oneDark",
|
|
15
|
-
"getStatistics",
|
|
16
|
-
"External",
|
|
17
|
-
"define",
|
|
18
|
-
"useCodeMirror",
|
|
19
|
-
"props",
|
|
20
|
-
"value",
|
|
21
|
-
"selection",
|
|
22
|
-
"onChange",
|
|
23
|
-
"onStatistics",
|
|
24
|
-
"onCreateEditor",
|
|
25
|
-
"onUpdate",
|
|
26
|
-
"extensions",
|
|
27
|
-
"autoFocus",
|
|
28
|
-
"theme",
|
|
29
|
-
"height",
|
|
30
|
-
"minHeight",
|
|
31
|
-
"maxHeight",
|
|
32
|
-
"placeholderStr",
|
|
33
|
-
"width",
|
|
34
|
-
"minWidth",
|
|
35
|
-
"maxWidth",
|
|
36
|
-
"editable",
|
|
37
|
-
"readOnly",
|
|
38
|
-
"defaultIndentWithTab",
|
|
39
|
-
"defaultBasicSetup",
|
|
40
|
-
"root",
|
|
41
|
-
"initialState",
|
|
42
|
-
"container",
|
|
43
|
-
"setContainer",
|
|
44
|
-
"view",
|
|
45
|
-
"setView",
|
|
46
|
-
"state",
|
|
47
|
-
"setState",
|
|
48
|
-
"defaultLightThemeOption",
|
|
49
|
-
"backgroundColor",
|
|
50
|
-
"dark",
|
|
51
|
-
"defaultThemeOption",
|
|
52
|
-
"updateListener",
|
|
53
|
-
"of",
|
|
54
|
-
"vu",
|
|
55
|
-
"docChanged",
|
|
56
|
-
"transactions",
|
|
57
|
-
"some",
|
|
58
|
-
"tr",
|
|
59
|
-
"annotation",
|
|
60
|
-
"doc",
|
|
61
|
-
"toString",
|
|
62
|
-
"getExtensions",
|
|
63
|
-
"unshift",
|
|
64
|
-
"push",
|
|
65
|
-
"concat",
|
|
66
|
-
"config",
|
|
67
|
-
"stateCurrent",
|
|
68
|
-
"fromJSON",
|
|
69
|
-
"json",
|
|
70
|
-
"fields",
|
|
71
|
-
"create",
|
|
72
|
-
"viewCurrent",
|
|
73
|
-
"parent",
|
|
74
|
-
"undefined",
|
|
75
|
-
"destroy",
|
|
76
|
-
"focus",
|
|
77
|
-
"dispatch",
|
|
78
|
-
"effects",
|
|
79
|
-
"reconfigure",
|
|
80
|
-
"currentValue",
|
|
81
|
-
"changes",
|
|
82
|
-
"from",
|
|
83
|
-
"to",
|
|
84
|
-
"length",
|
|
85
|
-
"insert",
|
|
86
|
-
"annotations"
|
|
87
|
-
],
|
|
88
|
-
"sources": [
|
|
89
|
-
"../src/useCodeMirror.ts"
|
|
90
|
-
],
|
|
91
|
-
"sourcesContent": [
|
|
92
|
-
"import { useEffect, useState } from 'react';\nimport { Annotation, EditorState, StateEffect } from '@codemirror/state';\nimport { indentWithTab } from '@codemirror/commands';\nimport { EditorView, keymap, ViewUpdate, placeholder } from '@codemirror/view';\nimport { basicSetup } from '@uiw/codemirror-extensions-basic-setup';\nimport { oneDark } from '@codemirror/theme-one-dark';\nimport { getStatistics } from './utils';\nimport { ReactCodeMirrorProps } from '.';\n\nconst External = Annotation.define<boolean>();\n\nexport interface UseCodeMirror extends ReactCodeMirrorProps {\n container?: HTMLDivElement | null;\n}\n\nexport function useCodeMirror(props: UseCodeMirror) {\n const {\n value,\n selection,\n onChange,\n onStatistics,\n onCreateEditor,\n onUpdate,\n extensions = [],\n autoFocus,\n theme = 'light',\n height = '',\n minHeight = '',\n maxHeight = '',\n placeholder: placeholderStr = '',\n width = '',\n minWidth = '',\n maxWidth = '',\n editable = true,\n readOnly = false,\n indentWithTab: defaultIndentWithTab = true,\n basicSetup: defaultBasicSetup = true,\n root,\n initialState,\n } = props;\n const [container, setContainer] = useState<HTMLDivElement>();\n const [view, setView] = useState<EditorView>();\n const [state, setState] = useState<EditorState>();\n const defaultLightThemeOption = EditorView.theme(\n {\n '&': {\n backgroundColor: '#fff',\n },\n },\n {\n dark: false,\n },\n );\n const defaultThemeOption = EditorView.theme({\n '&': {\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n },\n });\n const updateListener = EditorView.updateListener.of((vu: ViewUpdate) => {\n if (\n vu.docChanged &&\n typeof onChange === 'function' &&\n // Fix echoing of the remote changes:\n // If transaction is market as remote we don't have to call `onChange` handler again\n !vu.transactions.some((tr) => tr.annotation(External))\n ) {\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 case 'none':\n break;\n default:\n getExtensions.push(theme);\n break;\n }\n\n if (editable === false) {\n getExtensions.push(EditorView.editable.of(false));\n }\n if (readOnly) {\n getExtensions.push(EditorState.readOnly.of(true));\n }\n\n if (onUpdate && typeof onUpdate === 'function') {\n getExtensions.push(EditorView.updateListener.of(onUpdate));\n }\n getExtensions = getExtensions.concat(extensions);\n\n useEffect(() => {\n if (container && !state) {\n const config = {\n doc: value,\n selection,\n extensions: getExtensions,\n };\n const stateCurrent = initialState\n ? EditorState.fromJSON(initialState.json, config, initialState.fields)\n : EditorState.create(config);\n setState(stateCurrent);\n if (!view) {\n const viewCurrent = new EditorView({\n state: stateCurrent,\n parent: container,\n root,\n });\n setView(viewCurrent);\n onCreateEditor && onCreateEditor(viewCurrent, stateCurrent);\n }\n }\n return () => {\n if (view) {\n setState(undefined);\n setView(undefined);\n }\n };\n }, [container, state]);\n\n useEffect(() => setContainer(props.container!), [props.container]);\n\n useEffect(\n () => () => {\n if (view) {\n view.destroy();\n setView(undefined);\n }\n },\n [view],\n );\n\n useEffect(() => {\n if (autoFocus && view) {\n view.focus();\n }\n }, [autoFocus, view]);\n\n useEffect(() => {\n if (view) {\n view.dispatch({ effects: StateEffect.reconfigure.of(getExtensions) });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n theme,\n extensions,\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n placeholderStr,\n editable,\n readOnly,\n defaultIndentWithTab,\n defaultBasicSetup,\n onChange,\n onUpdate,\n ]);\n\n useEffect(() => {\n if (value === undefined) {\n return;\n }\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 annotations: [External.of(true)],\n });\n }\n }, [value, view]);\n\n return { state, setState, view, setView, container, setContainer };\n}\n"
|
|
93
|
-
],
|
|
94
|
-
"mappings": "AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAASC,UAAU,EAAEC,WAAW,EAAEC,WAAW,QAAQ,mBAAmB;AACxE,SAASC,aAAa,QAAQ,sBAAsB;AACpD,SAASC,UAAU,EAAEC,MAAM,EAAcC,WAAW,QAAQ,kBAAkB;AAC9E,SAASC,UAAU,QAAQ,wCAAwC;AACnE,SAASC,OAAO,QAAQ,4BAA4B;AACpD,SAASC,aAAa,QAAQ,SAAS;AAGvC,IAAMC,QAAQ,GAAGV,UAAU,CAACW,MAAM,EAAW;AAM7C,OAAO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C,EAAE,CAAC,IAAI,CAAC;MACjC,CAAC,CAAC;IACJ;EACF,CAAC,EAAE,CAACjC,KAAK,EAAEwB,IAAI,CAAC,CAAC;EAEjB,OAAO;IAAEE,KAAK;IAAEC,QAAQ;IAAEH,IAAI;IAAEC,OAAO;IAAEH,SAAS;IAAEC;EAAa,CAAC;AACpE"
|
|
95
|
-
}
|
package/esm/utils.js.map
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"names": [
|
|
4
|
-
"getStatistics",
|
|
5
|
-
"view",
|
|
6
|
-
"line",
|
|
7
|
-
"state",
|
|
8
|
-
"doc",
|
|
9
|
-
"lineAt",
|
|
10
|
-
"selection",
|
|
11
|
-
"main",
|
|
12
|
-
"from",
|
|
13
|
-
"lineCount",
|
|
14
|
-
"lines",
|
|
15
|
-
"lineBreak",
|
|
16
|
-
"length",
|
|
17
|
-
"readOnly",
|
|
18
|
-
"tabSize",
|
|
19
|
-
"selectionAsSingle",
|
|
20
|
-
"asSingle",
|
|
21
|
-
"ranges",
|
|
22
|
-
"selectionCode",
|
|
23
|
-
"sliceDoc",
|
|
24
|
-
"to",
|
|
25
|
-
"selections",
|
|
26
|
-
"map",
|
|
27
|
-
"r",
|
|
28
|
-
"selectedText",
|
|
29
|
-
"some",
|
|
30
|
-
"empty"
|
|
31
|
-
],
|
|
32
|
-
"sources": [
|
|
33
|
-
"../src/utils.ts"
|
|
34
|
-
],
|
|
35
|
-
"sourcesContent": [
|
|
36
|
-
"import { EditorSelection, SelectionRange, Line } from '@codemirror/state';\nimport { ViewUpdate } from '@codemirror/view';\n\nexport interface Statistics {\n /** total length of the document */\n length: number;\n /** Get the number of lines in the editor. */\n lineCount: number;\n /** Get the currently line description around the given position. */\n line: Line;\n /** Get the proper [line-break](https://codemirror.net/docs/ref/#state.EditorState^lineSeparator) string for this state. */\n lineBreak: string;\n /** Returns true when the editor is [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. */\n readOnly: boolean;\n /** The size (in columns) of a tab in the document, determined by the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. */\n tabSize: number;\n /** Cursor Position */\n selection: EditorSelection;\n /** Make sure the selection only has one range. */\n selectionAsSingle: SelectionRange;\n /** Retrieves a list of all current selections. */\n ranges: readonly SelectionRange[];\n /** Get the currently selected code. */\n selectionCode: string;\n /**\n * The length of the given array should be the same as the number of active selections.\n * Replaces the content of the selections with the strings in the array.\n */\n selections: string[];\n /** Return true if any text is selected. */\n selectedText: boolean;\n}\n\nexport const getStatistics = (view: ViewUpdate): Statistics => {\n return {\n line: view.state.doc.lineAt(view.state.selection.main.from),\n lineCount: view.state.doc.lines,\n lineBreak: view.state.lineBreak,\n length: view.state.doc.length,\n readOnly: view.state.readOnly,\n tabSize: view.state.tabSize,\n selection: view.state.selection,\n selectionAsSingle: view.state.selection.asSingle().main,\n ranges: view.state.selection.ranges,\n selectionCode: view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to),\n selections: view.state.selection.ranges.map((r) => view.state.sliceDoc(r.from, r.to)),\n selectedText: view.state.selection.ranges.some((r) => !r.empty),\n };\n};\n"
|
|
37
|
-
],
|
|
38
|
-
"mappings": "AAiCA,OAAO,IAAMA,aAAa,GAAIC,IAAgB,IAAiB;EAC7D,OAAO;IACLC,IAAI,EAAED,IAAI,CAACE,KAAK,CAACC,GAAG,CAACC,MAAM,CAACJ,IAAI,CAACE,KAAK,CAACG,SAAS,CAACC,IAAI,CAACC,IAAI,CAAC;IAC3DC,SAAS,EAAER,IAAI,CAACE,KAAK,CAACC,GAAG,CAACM,KAAK;IAC/BC,SAAS,EAAEV,IAAI,CAACE,KAAK,CAACQ,SAAS;IAC/BC,MAAM,EAAEX,IAAI,CAACE,KAAK,CAACC,GAAG,CAACQ,MAAM;IAC7BC,QAAQ,EAAEZ,IAAI,CAACE,KAAK,CAACU,QAAQ;IAC7BC,OAAO,EAAEb,IAAI,CAAC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