@uiw/react-codemirror 4.11.2 → 4.11.5
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 +5 -0
- package/cjs/useCodeMirror.js +5 -1
- package/cjs/useCodeMirror.js.map +5 -3
- package/dist/mdeditor.js +79 -36
- package/dist/mdeditor.min.js +1 -1
- package/esm/useCodeMirror.js +3 -2
- package/esm/useCodeMirror.js.map +5 -3
- package/package.json +2 -2
- package/src/useCodeMirror.ts +3 -2
package/README.md
CHANGED
|
@@ -43,13 +43,18 @@ npm install @uiw/react-codemirror --save
|
|
|
43
43
|
| Name | NPM Version | Website |
|
|
44
44
|
| -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
45
45
|
| `@uiw/react-codemirror` | [](https://www.npmjs.com/package/@uiw/react-codemirror) [](https://www.npmjs.com/package/@uiw/react-codemirror) | [`#preview`](https://uiwjs.github.io/react-codemirror/) |
|
|
46
|
+
| `@uiw/codemirror-extensions-basic-setup` | [](https://www.npmjs.com/package/@uiw/codemirror-extensions-basic-setup) [](https://www.npmjs.com/package/@uiw/codemirror-extensions-basic-setup) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/extensions/basic-setup) |
|
|
46
47
|
| `@uiw/codemirror-extensions-color` | [](https://www.npmjs.com/package/@uiw/codemirror-extensions-color) [](https://www.npmjs.com/package/@uiw/codemirror-extensions-color) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/extensions/color) |
|
|
47
48
|
| `@uiw/codemirror-extensions-events` | [](https://www.npmjs.com/package/@uiw/codemirror-extensions-events) [](https://www.npmjs.com/package/@uiw/codemirror-extensions-events) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/extensions/events) |
|
|
48
49
|
| `@uiw/codemirror-extensions-hyper-link` | [](https://www.npmjs.com/package/@uiw/codemirror-extensions-hyper-link) [](https://www.npmjs.com/package/@uiw/codemirror-extensions-hyper-link) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/extensions/hyper-link) |
|
|
50
|
+
| `@uiw/codemirror-extensions-langs` | [](https://www.npmjs.com/package/@uiw/codemirror-extensions-langs) [](https://www.npmjs.com/package/@uiw/codemirror-extensions-langs) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/extensions/languages) |
|
|
49
51
|
| `@uiw/codemirror-extensions-line-numbers-relative` | [](https://www.npmjs.com/package/@uiw/codemirror-extensions-line-numbers-relative) [](https://www.npmjs.com/package/@uiw/codemirror-extensions-line-numbers-relative) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/extensions/line-numbers-relative) |
|
|
52
|
+
| `@uiw/codemirror-extensions-mentions` | [](https://www.npmjs.com/package/@uiw/codemirror-extensions-mentions) [](https://www.npmjs.com/package/@uiw/codemirror-extensions-mentions) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/extensions/mentions) |
|
|
50
53
|
| `@uiw/codemirror-themes` | [](https://www.npmjs.com/package/@uiw/codemirror-themes) [](https://www.npmjs.com/package/@uiw/codemirror-themes) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/doc) |
|
|
51
54
|
| `@uiw/codemirror-theme-abcdef` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-abcdef) [](https://www.npmjs.com/package/@uiw/codemirror-theme-abcdef) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/abcdef) |
|
|
52
55
|
| `@uiw/codemirror-theme-androidstudio` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-androidstudio) [](https://www.npmjs.com/package/@uiw/codemirror-theme-androidstudio) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/androidstudio) |
|
|
56
|
+
| `@uiw/codemirror-theme-atomone` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-atomone) [](https://www.npmjs.com/package/@uiw/codemirror-theme-atomone) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/atomone) |
|
|
57
|
+
| `@uiw/codemirror-theme-bbedit` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-bbedit) [](https://www.npmjs.com/package/@uiw/codemirror-theme-bbedit) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/bbedit) |
|
|
53
58
|
| `@uiw/codemirror-theme-bespin` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-bespin) [](https://www.npmjs.com/package/@uiw/codemirror-theme-bespin) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/bespin) |
|
|
54
59
|
| `@uiw/codemirror-theme-duotone` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-duotone) [](https://www.npmjs.com/package/@uiw/codemirror-theme-duotone) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/duotone/light) |
|
|
55
60
|
| `@uiw/codemirror-theme-dracula` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-dracula) [](https://www.npmjs.com/package/@uiw/codemirror-theme-dracula) | [`#preview`](https://uiwjs.github.io/react-codemirror/#/theme/data/dracula) |
|
package/cjs/useCodeMirror.js
CHANGED
|
@@ -93,13 +93,17 @@ function useCodeMirror(props) {
|
|
|
93
93
|
}
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
+
var handleChange = (0, _react.useCallback)(function (value, vu) {
|
|
97
|
+
return onChange && onChange(value, vu);
|
|
98
|
+
}, []);
|
|
99
|
+
|
|
96
100
|
var updateListener = _view.EditorView.updateListener.of(function (vu) {
|
|
97
101
|
if (vu.docChanged && typeof onChange === 'function') {
|
|
98
102
|
var doc = vu.state.doc;
|
|
99
103
|
|
|
100
104
|
var _value = doc.toString();
|
|
101
105
|
|
|
102
|
-
|
|
106
|
+
handleChange(_value, vu);
|
|
103
107
|
}
|
|
104
108
|
|
|
105
109
|
onStatistics && onStatistics((0, _utils.getStatistics)(vu));
|
package/cjs/useCodeMirror.js.map
CHANGED
|
@@ -39,9 +39,11 @@
|
|
|
39
39
|
"backgroundColor",
|
|
40
40
|
"dark",
|
|
41
41
|
"defaultThemeOption",
|
|
42
|
+
"handleChange",
|
|
43
|
+
"useCallback",
|
|
44
|
+
"vu",
|
|
42
45
|
"updateListener",
|
|
43
46
|
"of",
|
|
44
|
-
"vu",
|
|
45
47
|
"docChanged",
|
|
46
48
|
"doc",
|
|
47
49
|
"toString",
|
|
@@ -76,7 +78,7 @@
|
|
|
76
78
|
"../src/useCodeMirror.ts"
|
|
77
79
|
],
|
|
78
80
|
"sourcesContent": [
|
|
79
|
-
"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 { basicSetup } from '@uiw/codemirror-extensions-basic-setup';\nimport { oneDark } from '@codemirror/theme-one-dark';\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 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 } = 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
|
|
81
|
+
"import { useCallback, useEffect, useState } from 'react';\nimport { 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\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 } = 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 handleChange = useCallback((value: string, vu: ViewUpdate) => onChange && onChange(value, vu), []);\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 handleChange(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 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 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"
|
|
80
82
|
],
|
|
81
|
-
"mappings": ";;;;;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MAAX,CAAd;IACD,CAHa,CAId;;EACD,CALD,EAKG,CACDrC,KADC,EAEDF,UAFC,EAGDG,MAHC,EAIDC,SAJC,EAKDC,SALC,EAMDG,KANC,EAODC,QAPC,EAQDC,QARC,EASDH,cATC,EAUDI,QAVC,EAWDC,QAXC,EAYDE,oBAZC,EAaDE,iBAbC,EAcDpB,QAdC,EAeDG,QAfC,CALH;EAuBA,IAAA+C,gBAAA,EAAU,YAAM;IACd,IAAMY,YAAY,GAAGrC,IAAI,GAAGA,IAAI,CAACE,KAAL,CAAWa,GAAX,CAAeC,QAAf,EAAH,GAA+B,EAAxD;;IACA,IAAIhB,IAAI,IAAI3B,KAAK,KAAKgE,YAAtB,EAAoC;MAClCrC,IAAI,CAACiC,QAAL,CAAc;QACZK,OAAO,EAAE;UAAEC,IAAI,EAAE,CAAR;UAAWC,EAAE,EAAEH,YAAY,CAACI,MAA5B;UAAoCC,MAAM,EAAErE,KAAK,IAAI;QAArD;MADG,CAAd;IAGD;EACF,CAPD,EAOG,CAACA,KAAD,EAAQ2B,IAAR,CAPH;EASA,OAAO;IAAEE,KAAK,EAALA,KAAF;IAASC,QAAQ,EAARA,QAAT;IAAmBH,IAAI,EAAJA,IAAnB;IAAyBC,OAAO,EAAPA,OAAzB;IAAkCH,SAAS,EAATA,SAAlC;IAA6CC,YAAY,EAAZA;EAA7C,CAAP;AACD"
|
|
82
84
|
}
|
package/dist/mdeditor.js
CHANGED
|
@@ -3746,6 +3746,7 @@ function indentRange(state, from, to) {
|
|
|
3746
3746
|
let changes = [];
|
|
3747
3747
|
for (let pos = from; pos <= to;) {
|
|
3748
3748
|
let line = state.doc.lineAt(pos);
|
|
3749
|
+
pos = line.to + 1;
|
|
3749
3750
|
let indent = getIndentation(context, line.from);
|
|
3750
3751
|
if (indent == null)
|
|
3751
3752
|
continue;
|
|
@@ -3757,7 +3758,6 @@ function indentRange(state, from, to) {
|
|
|
3757
3758
|
updated[line.from] = indent;
|
|
3758
3759
|
changes.push({ from: line.from, to: line.from + cur.length, insert: norm });
|
|
3759
3760
|
}
|
|
3760
|
-
pos = line.to + 1;
|
|
3761
3761
|
}
|
|
3762
3762
|
return state.changes(changes);
|
|
3763
3763
|
}
|
|
@@ -4717,13 +4717,13 @@ function matchMarkedBrackets(_state, _pos, dir, token, matching, brackets) {
|
|
|
4717
4717
|
depth++;
|
|
4718
4718
|
}
|
|
4719
4719
|
else if (matchingNodes(cursor.type, -dir, brackets)) {
|
|
4720
|
-
depth--;
|
|
4721
4720
|
if (depth == 0)
|
|
4722
4721
|
return {
|
|
4723
4722
|
start: firstToken,
|
|
4724
4723
|
end: cursor.from == cursor.to ? undefined : { from: cursor.from, to: cursor.to },
|
|
4725
4724
|
matched: false
|
|
4726
4725
|
};
|
|
4726
|
+
depth--;
|
|
4727
4727
|
}
|
|
4728
4728
|
}
|
|
4729
4729
|
} while (dir < 0 ? cursor.prevSibling() : cursor.nextSibling());
|
|
@@ -6049,6 +6049,14 @@ end of the indentation instead of the start of the line.
|
|
|
6049
6049
|
*/
|
|
6050
6050
|
const cursorLineBoundaryBackward = view => moveSel(view, range => moveByLineBoundary(view, range, false));
|
|
6051
6051
|
/**
|
|
6052
|
+
Move the selection one line wrap point to the left.
|
|
6053
|
+
*/
|
|
6054
|
+
const cursorLineBoundaryLeft = view => moveSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view)));
|
|
6055
|
+
/**
|
|
6056
|
+
Move the selection one line wrap point to the right.
|
|
6057
|
+
*/
|
|
6058
|
+
const cursorLineBoundaryRight = view => moveSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view)));
|
|
6059
|
+
/**
|
|
6052
6060
|
Move the selection to the start of the line.
|
|
6053
6061
|
*/
|
|
6054
6062
|
const cursorLineStart = view => moveSel(view, range => state_.EditorSelection.cursor(view.lineBlockAt(range.head).from, 1));
|
|
@@ -6183,6 +6191,14 @@ Move the selection head to the previous line boundary.
|
|
|
6183
6191
|
*/
|
|
6184
6192
|
const selectLineBoundaryBackward = view => extendSel(view, range => moveByLineBoundary(view, range, false));
|
|
6185
6193
|
/**
|
|
6194
|
+
Move the selection head one line boundary to the left.
|
|
6195
|
+
*/
|
|
6196
|
+
const selectLineBoundaryLeft = view => extendSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view)));
|
|
6197
|
+
/**
|
|
6198
|
+
Move the selection head one line boundary to the right.
|
|
6199
|
+
*/
|
|
6200
|
+
const selectLineBoundaryRight = view => extendSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view)));
|
|
6201
|
+
/**
|
|
6186
6202
|
Move the selection head to the start of the line.
|
|
6187
6203
|
*/
|
|
6188
6204
|
const selectLineStart = view => extendSel(view, range => state_.EditorSelection.cursor(view.lineBlockAt(range.head).from));
|
|
@@ -6751,11 +6767,11 @@ property changed to `mac`.)
|
|
|
6751
6767
|
*/
|
|
6752
6768
|
const standardKeymap = /*@__PURE__*/[
|
|
6753
6769
|
{ key: "ArrowLeft", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true },
|
|
6754
|
-
{ key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: cursorGroupLeft, shift: selectGroupLeft },
|
|
6755
|
-
{ mac: "Cmd-ArrowLeft", run:
|
|
6770
|
+
{ key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: cursorGroupLeft, shift: selectGroupLeft, preventDefault: true },
|
|
6771
|
+
{ mac: "Cmd-ArrowLeft", run: cursorLineBoundaryLeft, shift: selectLineBoundaryLeft, preventDefault: true },
|
|
6756
6772
|
{ key: "ArrowRight", run: cursorCharRight, shift: selectCharRight, preventDefault: true },
|
|
6757
|
-
{ key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: cursorGroupRight, shift: selectGroupRight },
|
|
6758
|
-
{ mac: "Cmd-ArrowRight", run:
|
|
6773
|
+
{ key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: cursorGroupRight, shift: selectGroupRight, preventDefault: true },
|
|
6774
|
+
{ mac: "Cmd-ArrowRight", run: cursorLineBoundaryRight, shift: selectLineBoundaryRight, preventDefault: true },
|
|
6759
6775
|
{ key: "ArrowUp", run: cursorLineUp, shift: selectLineUp, preventDefault: true },
|
|
6760
6776
|
{ mac: "Cmd-ArrowUp", run: cursorDocStart, shift: selectDocStart },
|
|
6761
6777
|
{ mac: "Ctrl-ArrowUp", run: cursorPageUp, shift: selectPageUp },
|
|
@@ -6997,6 +7013,7 @@ class RegExpCursor {
|
|
|
6997
7013
|
`new RegExp`).
|
|
6998
7014
|
*/
|
|
6999
7015
|
constructor(text, query, options, from = 0, to = text.length) {
|
|
7016
|
+
this.text = text;
|
|
7000
7017
|
this.to = to;
|
|
7001
7018
|
this.curLine = "";
|
|
7002
7019
|
/**
|
|
@@ -7016,7 +7033,7 @@ class RegExpCursor {
|
|
|
7016
7033
|
this.iter = text.iter();
|
|
7017
7034
|
let startLine = text.lineAt(from);
|
|
7018
7035
|
this.curLineStart = startLine.from;
|
|
7019
|
-
this.matchPos = from;
|
|
7036
|
+
this.matchPos = toCharEnd(text, from);
|
|
7020
7037
|
this.getLine(this.curLineStart);
|
|
7021
7038
|
}
|
|
7022
7039
|
getLine(skip) {
|
|
@@ -7047,7 +7064,7 @@ class RegExpCursor {
|
|
|
7047
7064
|
let match = this.matchPos <= this.to && this.re.exec(this.curLine);
|
|
7048
7065
|
if (match) {
|
|
7049
7066
|
let from = this.curLineStart + match.index, to = from + match[0].length;
|
|
7050
|
-
this.matchPos = to + (from == to ? 1 : 0);
|
|
7067
|
+
this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0));
|
|
7051
7068
|
if (from == this.curLine.length)
|
|
7052
7069
|
this.nextLine();
|
|
7053
7070
|
if (from < to || from > this.value.to) {
|
|
@@ -7101,7 +7118,7 @@ class MultilineRegExpCursor {
|
|
|
7101
7118
|
this.to = to;
|
|
7102
7119
|
this.done = false;
|
|
7103
7120
|
this.value = empty;
|
|
7104
|
-
this.matchPos = from;
|
|
7121
|
+
this.matchPos = toCharEnd(text, from);
|
|
7105
7122
|
this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : ""));
|
|
7106
7123
|
this.flat = FlattenedDoc.get(text, from, this.chunkEnd(from + 5000 /* Base */));
|
|
7107
7124
|
}
|
|
@@ -7124,7 +7141,7 @@ class MultilineRegExpCursor {
|
|
|
7124
7141
|
if (match) {
|
|
7125
7142
|
let from = this.flat.from + match.index, to = from + match[0].length;
|
|
7126
7143
|
this.value = { from, to, match };
|
|
7127
|
-
this.matchPos = to + (from == to ? 1 : 0);
|
|
7144
|
+
this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0));
|
|
7128
7145
|
return this;
|
|
7129
7146
|
}
|
|
7130
7147
|
else {
|
|
@@ -7151,6 +7168,14 @@ function validRegExp(source) {
|
|
|
7151
7168
|
return false;
|
|
7152
7169
|
}
|
|
7153
7170
|
}
|
|
7171
|
+
function toCharEnd(text, pos) {
|
|
7172
|
+
if (pos >= text.length)
|
|
7173
|
+
return pos;
|
|
7174
|
+
let line = text.lineAt(pos), next;
|
|
7175
|
+
while (pos < line.to && (next = line.text.charCodeAt(pos - line.from)) >= 0xDC00 && next < 0xE000)
|
|
7176
|
+
pos++;
|
|
7177
|
+
return pos;
|
|
7178
|
+
}
|
|
7154
7179
|
|
|
7155
7180
|
function createLineDialog(view) {
|
|
7156
7181
|
let input = crelt("input", { class: "cm-textfield", name: "line" });
|
|
@@ -7406,6 +7431,7 @@ const searchConfigFacet = /*@__PURE__*/state_.Facet.define({
|
|
|
7406
7431
|
return {
|
|
7407
7432
|
top: configs.reduce((val, conf) => val !== null && val !== void 0 ? val : conf.top, undefined) || false,
|
|
7408
7433
|
caseSensitive: configs.reduce((val, conf) => val !== null && val !== void 0 ? val : conf.caseSensitive, undefined) || false,
|
|
7434
|
+
literal: configs.reduce((val, conf) => val !== null && val !== void 0 ? val : conf.literal, undefined) || false,
|
|
7409
7435
|
createPanel: ((_a = configs.find(c => c.createPanel)) === null || _a === void 0 ? void 0 : _a.createPanel) || (view => new SearchPanel(view))
|
|
7410
7436
|
};
|
|
7411
7437
|
}
|
|
@@ -7429,10 +7455,11 @@ class SearchQuery {
|
|
|
7429
7455
|
constructor(config) {
|
|
7430
7456
|
this.search = config.search;
|
|
7431
7457
|
this.caseSensitive = !!config.caseSensitive;
|
|
7458
|
+
this.literal = !!config.literal;
|
|
7432
7459
|
this.regexp = !!config.regexp;
|
|
7433
7460
|
this.replace = config.replace || "";
|
|
7434
7461
|
this.valid = !!this.search && (!this.regexp || validRegExp(this.search));
|
|
7435
|
-
this.unquoted =
|
|
7462
|
+
this.unquoted = this.literal ? this.search : this.search.replace(/\\([nrt\\])/g, (_, ch) => ch == "n" ? "\n" : ch == "r" ? "\r" : ch == "t" ? "\t" : "\\");
|
|
7436
7463
|
}
|
|
7437
7464
|
/**
|
|
7438
7465
|
Compare this query to another query.
|
|
@@ -7586,6 +7613,13 @@ function getSearchQuery(state) {
|
|
|
7586
7613
|
let curState = state.field(searchState, false);
|
|
7587
7614
|
return curState ? curState.query.spec : defaultQuery(state);
|
|
7588
7615
|
}
|
|
7616
|
+
/**
|
|
7617
|
+
Query whether the search panel is open in the given editor state.
|
|
7618
|
+
*/
|
|
7619
|
+
function searchPanelOpen(state) {
|
|
7620
|
+
var _a;
|
|
7621
|
+
return ((_a = state.field(searchState, false)) === null || _a === void 0 ? void 0 : _a.panel) != null;
|
|
7622
|
+
}
|
|
7589
7623
|
class SearchState {
|
|
7590
7624
|
constructor(query, panel) {
|
|
7591
7625
|
this.query = query;
|
|
@@ -7635,9 +7669,9 @@ Will wrap around to the start of the document when it reaches the
|
|
|
7635
7669
|
end.
|
|
7636
7670
|
*/
|
|
7637
7671
|
const findNext = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
7638
|
-
let {
|
|
7639
|
-
let next = query.nextMatch(view.state.doc,
|
|
7640
|
-
if (!next
|
|
7672
|
+
let { to } = view.state.selection.main;
|
|
7673
|
+
let next = query.nextMatch(view.state.doc, to, to);
|
|
7674
|
+
if (!next)
|
|
7641
7675
|
return false;
|
|
7642
7676
|
view.dispatch({
|
|
7643
7677
|
selection: { anchor: next.from, head: next.to },
|
|
@@ -7653,8 +7687,8 @@ before the current main selection. Will wrap past the start
|
|
|
7653
7687
|
of the document to start searching at the end again.
|
|
7654
7688
|
*/
|
|
7655
7689
|
const findPrevious = /*@__PURE__*/searchCommand((view, { query }) => {
|
|
7656
|
-
let { state } = view, { from
|
|
7657
|
-
let range = query.prevMatch(state.doc, from,
|
|
7690
|
+
let { state } = view, { from } = state.selection.main;
|
|
7691
|
+
let range = query.prevMatch(state.doc, from, from);
|
|
7658
7692
|
if (!range)
|
|
7659
7693
|
return false;
|
|
7660
7694
|
view.dispatch({
|
|
@@ -7756,11 +7790,17 @@ function createSearchPanel(view) {
|
|
|
7756
7790
|
return view.state.facet(searchConfigFacet).createPanel(view);
|
|
7757
7791
|
}
|
|
7758
7792
|
function defaultQuery(state, fallback) {
|
|
7759
|
-
var _a;
|
|
7793
|
+
var _a, _b, _c;
|
|
7760
7794
|
let sel = state.selection.main;
|
|
7761
7795
|
let selText = sel.empty || sel.to > sel.from + 100 ? "" : state.sliceDoc(sel.from, sel.to);
|
|
7762
|
-
|
|
7763
|
-
|
|
7796
|
+
if (fallback && !selText)
|
|
7797
|
+
return fallback;
|
|
7798
|
+
let config = state.facet(searchConfigFacet);
|
|
7799
|
+
return new SearchQuery({
|
|
7800
|
+
search: ((_a = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _a !== void 0 ? _a : config.literal) ? selText : selText.replace(/\n/g, "\\n"),
|
|
7801
|
+
caseSensitive: (_b = fallback === null || fallback === void 0 ? void 0 : fallback.caseSensitive) !== null && _b !== void 0 ? _b : config.caseSensitive,
|
|
7802
|
+
literal: (_c = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _c !== void 0 ? _c : config.literal,
|
|
7803
|
+
});
|
|
7764
7804
|
}
|
|
7765
7805
|
/**
|
|
7766
7806
|
Make sure the search panel is open and focused.
|
|
@@ -8306,6 +8346,7 @@ const completionConfig = /*@__PURE__*/state_.Facet.define({
|
|
|
8306
8346
|
combine(configs) {
|
|
8307
8347
|
return (0,state_.combineConfig)(configs, {
|
|
8308
8348
|
activateOnTyping: true,
|
|
8349
|
+
selectOnOpen: true,
|
|
8309
8350
|
override: null,
|
|
8310
8351
|
closeOnBlur: true,
|
|
8311
8352
|
maxRenderedOptions: 100,
|
|
@@ -8313,7 +8354,8 @@ const completionConfig = /*@__PURE__*/state_.Facet.define({
|
|
|
8313
8354
|
optionClass: () => "",
|
|
8314
8355
|
aboveCursor: false,
|
|
8315
8356
|
icons: true,
|
|
8316
|
-
addToOptions: []
|
|
8357
|
+
addToOptions: [],
|
|
8358
|
+
compareCompletions: (a, b) => a.label.localeCompare(b.label)
|
|
8317
8359
|
}, {
|
|
8318
8360
|
defaultKeymap: (a, b) => a && b,
|
|
8319
8361
|
closeOnBlur: (a, b) => a && b,
|
|
@@ -8376,6 +8418,8 @@ function optionContent(config) {
|
|
|
8376
8418
|
function rangeAroundSelected(total, selected, max) {
|
|
8377
8419
|
if (total <= max)
|
|
8378
8420
|
return { from: 0, to: total };
|
|
8421
|
+
if (selected < 0)
|
|
8422
|
+
selected = 0;
|
|
8379
8423
|
if (selected <= (total >> 1)) {
|
|
8380
8424
|
let off = Math.floor(selected / max);
|
|
8381
8425
|
return { from: off * max, to: (off + 1) * max };
|
|
@@ -8583,7 +8627,8 @@ function sortOptions(active, state) {
|
|
|
8583
8627
|
}
|
|
8584
8628
|
}
|
|
8585
8629
|
let result = [], prev = null;
|
|
8586
|
-
|
|
8630
|
+
let compare = state.facet(completionConfig).compareCompletions;
|
|
8631
|
+
for (let opt of options.sort((a, b) => (b.match[0] - a.match[0]) || compare(a.completion, b.completion))) {
|
|
8587
8632
|
if (!prev || prev.label != opt.completion.label || prev.detail != opt.completion.detail ||
|
|
8588
8633
|
(prev.type != null && opt.completion.type != null && prev.type != opt.completion.type) ||
|
|
8589
8634
|
prev.apply != opt.completion.apply)
|
|
@@ -8610,8 +8655,8 @@ class CompletionDialog {
|
|
|
8610
8655
|
let options = sortOptions(active, state);
|
|
8611
8656
|
if (!options.length)
|
|
8612
8657
|
return null;
|
|
8613
|
-
let selected = 0;
|
|
8614
|
-
if (prev && prev.selected) {
|
|
8658
|
+
let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
|
|
8659
|
+
if (prev && prev.selected != selected && prev.selected != -1) {
|
|
8615
8660
|
let selectedValue = prev.options[prev.selected].completion;
|
|
8616
8661
|
for (let i = 0; i < options.length; i++)
|
|
8617
8662
|
if (options[i].completion == selectedValue) {
|
|
@@ -8681,20 +8726,16 @@ const baseAttrs = {
|
|
|
8681
8726
|
"aria-autocomplete": "list"
|
|
8682
8727
|
};
|
|
8683
8728
|
function makeAttrs(id, selected) {
|
|
8684
|
-
|
|
8729
|
+
let result = {
|
|
8685
8730
|
"aria-autocomplete": "list",
|
|
8686
8731
|
"aria-haspopup": "listbox",
|
|
8687
|
-
"aria-activedescendant": id + "-" + selected,
|
|
8688
8732
|
"aria-controls": id
|
|
8689
8733
|
};
|
|
8734
|
+
if (selected > -1)
|
|
8735
|
+
result["aria-activedescendant"] = id + "-" + selected;
|
|
8736
|
+
return result;
|
|
8690
8737
|
}
|
|
8691
8738
|
const dist_none = [];
|
|
8692
|
-
function cmpOption(a, b) {
|
|
8693
|
-
let dScore = b.match[0] - a.match[0];
|
|
8694
|
-
if (dScore)
|
|
8695
|
-
return dScore;
|
|
8696
|
-
return a.completion.label.localeCompare(b.completion.label);
|
|
8697
|
-
}
|
|
8698
8739
|
function getUserEvent(tr) {
|
|
8699
8740
|
return tr.isUserEvent("input.type") ? "input" : tr.isUserEvent("delete.backward") ? "delete" : null;
|
|
8700
8741
|
}
|
|
@@ -8802,7 +8843,8 @@ function moveCompletionSelection(forward, by = "option") {
|
|
|
8802
8843
|
if (by == "page" && (tooltip = (0,view_.getTooltip)(view, cState.open.tooltip)))
|
|
8803
8844
|
step = Math.max(2, Math.floor(tooltip.dom.offsetHeight /
|
|
8804
8845
|
tooltip.dom.querySelector("li").offsetHeight) - 1);
|
|
8805
|
-
let
|
|
8846
|
+
let { length } = cState.open.options;
|
|
8847
|
+
let selected = cState.open.selected > -1 ? cState.open.selected + step * (forward ? 1 : -1) : forward ? 0 : length - 1;
|
|
8806
8848
|
if (selected < 0)
|
|
8807
8849
|
selected = by == "page" ? 0 : length - 1;
|
|
8808
8850
|
else if (selected >= length)
|
|
@@ -8816,7 +8858,8 @@ Accept the current completion.
|
|
|
8816
8858
|
*/
|
|
8817
8859
|
const acceptCompletion = (view) => {
|
|
8818
8860
|
let cState = view.state.field(completionState, false);
|
|
8819
|
-
if (view.state.readOnly || !cState || !cState.open || Date.now() - cState.open.timestamp < CompletionInteractMargin
|
|
8861
|
+
if (view.state.readOnly || !cState || !cState.open || Date.now() - cState.open.timestamp < CompletionInteractMargin ||
|
|
8862
|
+
cState.open.selected < 0)
|
|
8820
8863
|
return false;
|
|
8821
8864
|
applyCompletion(view, cState.open.options[cState.open.selected]);
|
|
8822
8865
|
return true;
|
|
@@ -9729,7 +9772,7 @@ Return the currently selected completion, if any.
|
|
|
9729
9772
|
function selectedCompletion(state) {
|
|
9730
9773
|
var _a;
|
|
9731
9774
|
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
|
|
9732
|
-
return open ? open.options[open.selected].completion : null;
|
|
9775
|
+
return open && open.selected >= 0 ? open.options[open.selected].completion : null;
|
|
9733
9776
|
}
|
|
9734
9777
|
/**
|
|
9735
9778
|
Returns the currently selected position in the active completion
|
|
@@ -9738,7 +9781,7 @@ list, or null if no completions are active.
|
|
|
9738
9781
|
function selectedCompletionIndex(state) {
|
|
9739
9782
|
var _a;
|
|
9740
9783
|
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
|
|
9741
|
-
return open ? open.selected : null;
|
|
9784
|
+
return open && open.selected >= 0 ? open.selected : null;
|
|
9742
9785
|
}
|
|
9743
9786
|
/**
|
|
9744
9787
|
Create an effect that can be attached to a transaction to change
|
|
@@ -10626,7 +10669,7 @@ var theme_one_dark_ = __webpack_require__(362);
|
|
|
10626
10669
|
;// CONCATENATED MODULE: ./src/utils.ts
|
|
10627
10670
|
var getStatistics=function getStatistics(view){return{line:view.state.doc.lineAt(view.state.selection.main.from),lineCount:view.state.doc.lines,lineBreak:view.state.lineBreak,length:view.state.doc.length,readOnly:view.state.readOnly,tabSize:view.state.tabSize,selection:view.state.selection,selectionAsSingle:view.state.selection.asSingle().main,ranges:view.state.selection.ranges,selectionCode:view.state.sliceDoc(view.state.selection.main.from,view.state.selection.main.to),selections:view.state.selection.ranges.map(function(r){return view.state.sliceDoc(r.from,r.to);}),selectedText:view.state.selection.ranges.some(function(r){return!r.empty;})};};
|
|
10628
10671
|
;// CONCATENATED MODULE: ./src/useCodeMirror.ts
|
|
10629
|
-
function useCodeMirror(props){var value=props.value,selection=props.selection,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,_props$height=props.height,height=_props$height===void 0?'':_props$height,_props$minHeight=props.minHeight,minHeight=_props$minHeight===void 0?'':_props$minHeight,_props$maxHeight=props.maxHeight,maxHeight=_props$maxHeight===void 0?'':_props$maxHeight,_props$placeholder=props.placeholder,placeholderStr=_props$placeholder===void 0?'':_props$placeholder,_props$width=props.width,width=_props$width===void 0?'':_props$width,_props$minWidth=props.minWidth,minWidth=_props$minWidth===void 0?'':_props$minWidth,_props$maxWidth=props.maxWidth,maxWidth=_props$maxWidth===void 0?'':_props$maxWidth,_props$editable=props.editable,editable=_props$editable===void 0?true:_props$editable,_props$readOnly=props.readOnly,readOnly=_props$readOnly===void 0?false:_props$readOnly,_props$indentWithTab=props.indentWithTab,defaultIndentWithTab=_props$indentWithTab===void 0?true:_props$indentWithTab,_props$basicSetup=props.basicSetup,defaultBasicSetup=_props$basicSetup===void 0?true:_props$basicSetup,root=props.root;var _useState=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState2=_slicedToArray(_useState,2),container=_useState2[0],setContainer=_useState2[1];var _useState3=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState4=_slicedToArray(_useState3,2),view=_useState4[0],setView=_useState4[1];var _useState5=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState6=_slicedToArray(_useState5,2),state=_useState6[0],setState=_useState6[1];var defaultLightThemeOption=view_.EditorView.theme({'&':{backgroundColor:'#fff'}},{dark:false});var defaultThemeOption=view_.EditorView.theme({'&':{height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth}});var updateListener=view_.EditorView.updateListener.of(function(vu){if(vu.docChanged&&typeof onChange==='function'){var doc=vu.state.doc;var _value=doc.toString();
|
|
10672
|
+
function useCodeMirror(props){var value=props.value,selection=props.selection,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,_props$height=props.height,height=_props$height===void 0?'':_props$height,_props$minHeight=props.minHeight,minHeight=_props$minHeight===void 0?'':_props$minHeight,_props$maxHeight=props.maxHeight,maxHeight=_props$maxHeight===void 0?'':_props$maxHeight,_props$placeholder=props.placeholder,placeholderStr=_props$placeholder===void 0?'':_props$placeholder,_props$width=props.width,width=_props$width===void 0?'':_props$width,_props$minWidth=props.minWidth,minWidth=_props$minWidth===void 0?'':_props$minWidth,_props$maxWidth=props.maxWidth,maxWidth=_props$maxWidth===void 0?'':_props$maxWidth,_props$editable=props.editable,editable=_props$editable===void 0?true:_props$editable,_props$readOnly=props.readOnly,readOnly=_props$readOnly===void 0?false:_props$readOnly,_props$indentWithTab=props.indentWithTab,defaultIndentWithTab=_props$indentWithTab===void 0?true:_props$indentWithTab,_props$basicSetup=props.basicSetup,defaultBasicSetup=_props$basicSetup===void 0?true:_props$basicSetup,root=props.root;var _useState=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState2=_slicedToArray(_useState,2),container=_useState2[0],setContainer=_useState2[1];var _useState3=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState4=_slicedToArray(_useState3,2),view=_useState4[0],setView=_useState4[1];var _useState5=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)(),_useState6=_slicedToArray(_useState5,2),state=_useState6[0],setState=_useState6[1];var defaultLightThemeOption=view_.EditorView.theme({'&':{backgroundColor:'#fff'}},{dark:false});var defaultThemeOption=view_.EditorView.theme({'&':{height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth}});var handleChange=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function(value,vu){return onChange&&onChange(value,vu);},[]);var updateListener=view_.EditorView.updateListener.of(function(vu){if(vu.docChanged&&typeof onChange==='function'){var doc=vu.state.doc;var _value=doc.toString();handleChange(_value,vu);}onStatistics&&onStatistics(getStatistics(vu));});var getExtensions=[updateListener,defaultThemeOption];if(defaultIndentWithTab){getExtensions.unshift(view_.keymap.of([indentWithTab]));}if(defaultBasicSetup){if(typeof defaultBasicSetup==='boolean'){getExtensions.unshift(basicSetup());}else{getExtensions.unshift(basicSetup(defaultBasicSetup));}}if(placeholderStr){getExtensions.unshift((0,view_.placeholder)(placeholderStr));}switch(theme){case'light':getExtensions.push(defaultLightThemeOption);break;case'dark':getExtensions.push(theme_one_dark_.oneDark);break;default:getExtensions.push(theme);break;}if(editable===false){getExtensions.push(view_.EditorView.editable.of(false));}if(readOnly){getExtensions.push(state_.EditorState.readOnly.of(true));}if(onUpdate&&typeof onUpdate==='function'){getExtensions.push(view_.EditorView.updateListener.of(onUpdate));}getExtensions=getExtensions.concat(extensions);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(container&&!state){var stateCurrent=state_.EditorState.create({doc:value,selection:selection,extensions:getExtensions});setState(stateCurrent);if(!view){var viewCurrent=new view_.EditorView({state:stateCurrent,parent:container,root:root});setView(viewCurrent);onCreateEditor&&onCreateEditor(viewCurrent,stateCurrent);}}return function(){if(view){setState(undefined);setView(undefined);}};},[container,state]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){return setContainer(props.container);},[props.container]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){return function(){if(view){view.destroy();setView(undefined);}};},[view]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(autoFocus&&view){view.focus();}},[autoFocus,view]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(view){view.dispatch({effects:state_.StateEffect.reconfigure.of(getExtensions)});}// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
10630
10673
|
},[theme,extensions,height,minHeight,maxHeight,width,minWidth,maxWidth,placeholderStr,editable,readOnly,defaultIndentWithTab,defaultBasicSetup,onChange,onUpdate]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){var currentValue=view?view.state.doc.toString():'';if(view&&value!==currentValue){view.dispatch({changes:{from:0,to:currentValue.length,insert:value||''}});}},[value,view]);return{state:state,setState:setState,view:view,setView:setView,container:container,setContainer:setContainer};}
|
|
10631
10674
|
// EXTERNAL MODULE: ../node_modules/react/jsx-runtime.js
|
|
10632
10675
|
var jsx_runtime = __webpack_require__(605);
|