@uiw/react-codemirror 4.19.6 → 4.19.8

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 CHANGED
@@ -16,8 +16,6 @@
16
16
 
17
17
  CodeMirror component for React. Demo Preview: [@uiwjs.github.io/react-codemirror](https://uiwjs.github.io/react-codemirror/)
18
18
 
19
- > ⚠️ The [`v3`](https://raw.githack.com/uiwjs/react-codemirror/doc3/index.html) version document preview is [here](https://raw.githack.com/uiwjs/react-codemirror/doc3/index.html).
20
-
21
19
  <!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;-->
22
20
 
23
21
  **Features:**
@@ -13,6 +13,7 @@ var _view = require("@codemirror/view");
13
13
  var _codemirrorExtensionsBasicSetup = require("@uiw/codemirror-extensions-basic-setup");
14
14
  var _themeOneDark = require("@codemirror/theme-one-dark");
15
15
  var _utils = require("./utils");
16
+ var External = _state.Annotation.define();
16
17
  function useCodeMirror(props) {
17
18
  var value = props.value,
18
19
  selection = props.selection,
@@ -79,7 +80,12 @@ function useCodeMirror(props) {
79
80
  }
80
81
  });
81
82
  var updateListener = _view.EditorView.updateListener.of(function (vu) {
82
- if (vu.docChanged && typeof onChange === 'function') {
83
+ if (vu.docChanged && typeof onChange === 'function' &&
84
+ // Fix echoing of the remote changes:
85
+ // If transaction is market as remote we don't have to call `onChange` handler again
86
+ !vu.transactions.some(function (tr) {
87
+ return tr.annotation(External);
88
+ })) {
83
89
  var doc = vu.state.doc;
84
90
  var _value = doc.toString();
85
91
  onChange(_value, vu);
@@ -184,7 +190,8 @@ function useCodeMirror(props) {
184
190
  from: 0,
185
191
  to: currentValue.length,
186
192
  insert: value || ''
187
- }
193
+ },
194
+ annotations: [External.of(true)]
188
195
  });
189
196
  }
190
197
  }, [value, view]);
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "version": 3,
3
3
  "names": [
4
+ "External",
5
+ "Annotation",
6
+ "define",
4
7
  "useCodeMirror",
5
8
  "props",
6
9
  "value",
@@ -44,6 +47,10 @@
44
47
  "of",
45
48
  "vu",
46
49
  "docChanged",
50
+ "transactions",
51
+ "some",
52
+ "tr",
53
+ "annotation",
47
54
  "doc",
48
55
  "toString",
49
56
  "getStatistics",
@@ -75,13 +82,14 @@
75
82
  "from",
76
83
  "to",
77
84
  "length",
78
- "insert"
85
+ "insert",
86
+ "annotations"
79
87
  ],
80
88
  "sources": [
81
89
  "../src/useCodeMirror.ts"
82
90
  ],
83
91
  "sourcesContent": [
84
- "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 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 (vu.docChanged && typeof onChange === 'function') {\n const doc = vu.state.doc;\n const value = doc.toString();\n onChange(value, vu);\n }\n onStatistics && onStatistics(getStatistics(vu));\n });\n\n let getExtensions = [updateListener, defaultThemeOption];\n if (defaultIndentWithTab) {\n getExtensions.unshift(keymap.of([indentWithTab]));\n }\n if (defaultBasicSetup) {\n if (typeof defaultBasicSetup === 'boolean') {\n getExtensions.unshift(basicSetup());\n } else {\n getExtensions.unshift(basicSetup(defaultBasicSetup));\n }\n }\n\n if (placeholderStr) {\n getExtensions.unshift(placeholder(placeholderStr));\n }\n\n switch (theme) {\n case 'light':\n getExtensions.push(defaultLightThemeOption);\n break;\n case 'dark':\n getExtensions.push(oneDark);\n break;\n 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 });\n }\n }, [value, view]);\n\n return { state, setState, view, setView, container, setContainer };\n}\n"
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"
85
93
  ],
86
- "mappings": ";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAOO,SAASA,aAAa,CAACC,KAAoB,EAAE;EAClD,IACEC,KAAK,GAsBHD,KAAK,CAtBPC,KAAK;IACLC,SAAS,GAqBPF,KAAK,CArBPE,SAAS;IACTC,QAAQ,GAoBNH,KAAK,CApBPG,QAAQ;IACRC,YAAY,GAmBVJ,KAAK,CAnBPI,YAAY;IACZC,cAAc,GAkBZL,KAAK,CAlBPK,cAAc;IACdC,QAAQ,GAiBNN,KAAK,CAjBPM,QAAQ;IAAA,oBAiBNN,KAAK,CAhBPO,UAAU;IAAVA,UAAU,kCAAG,EAAE;IACfC,SAAS,GAePR,KAAK,CAfPQ,SAAS;IAAA,eAePR,KAAK,CAdPS,KAAK;IAALA,KAAK,6BAAG,OAAO;IAAA,gBAcbT,KAAK,CAbPU,MAAM;IAANA,MAAM,8BAAG,EAAE;IAAA,mBAaTV,KAAK,CAZPW,SAAS;IAATA,SAAS,iCAAG,EAAE;IAAA,mBAYZX,KAAK,CAXPY,SAAS;IAATA,SAAS,iCAAG,EAAE;IAAA,qBAWZZ,KAAK,CAVPa,WAAW;IAAEC,cAAc,mCAAG,EAAE;IAAA,eAU9Bd,KAAK,CATPe,KAAK;IAALA,KAAK,6BAAG,EA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F,CAAC,EAAE,CAACtC,KAAK,EAAE4B,IAAI,CAAC,CAAC;EAEjB,OAAO;IAAEE,KAAK,EAALA,KAAK;IAAEC,QAAQ,EAARA,QAAQ;IAAEH,IAAI,EAAJA,IAAI;IAAEC,OAAO,EAAPA,OAAO;IAAEH,SAAS,EAATA,SAAS;IAAEC,YAAY,EAAZA;EAAa,CAAC;AACpE"
87
95
  }
package/dist/mdeditor.js CHANGED
@@ -3173,13 +3173,13 @@ function syntaxParserRunning(view) {
3173
3173
  }
3174
3174
  // Lezer-style Input object for a Text document.
3175
3175
  class DocInput {
3176
- constructor(doc, length = doc.length) {
3176
+ constructor(doc) {
3177
3177
  this.doc = doc;
3178
- this.length = length;
3179
3178
  this.cursorPos = 0;
3180
3179
  this.string = "";
3181
3180
  this.cursor = doc.iter();
3182
3181
  }
3182
+ get length() { return this.doc.length; }
3183
3183
  syncTo(pos) {
3184
3184
  this.string = this.cursor.next(pos - this.cursorPos).value;
3185
3185
  this.cursorPos = pos + this.string.length;
@@ -3724,17 +3724,18 @@ service.
3724
3724
  */
3725
3725
  const indentService = /*@__PURE__*/state_.Facet.define();
3726
3726
  /**
3727
- Facet for overriding the unit by which indentation happens.
3728
- Should be a string consisting either entirely of spaces or
3729
- entirely of tabs. When not set, this defaults to 2 spaces.
3727
+ Facet for overriding the unit by which indentation happens. Should
3728
+ be a string consisting either entirely of the same whitespace
3729
+ character. When not set, this defaults to 2 spaces.
3730
3730
  */
3731
3731
  const dist_indentUnit = /*@__PURE__*/state_.Facet.define({
3732
3732
  combine: values => {
3733
3733
  if (!values.length)
3734
3734
  return " ";
3735
- if (!/^(?: +|\t+)$/.test(values[0]))
3735
+ let unit = values[0];
3736
+ if (!unit || /\S/.test(unit) || Array.from(unit).some(e => e != unit[0]))
3736
3737
  throw new Error("Invalid indent unit: " + JSON.stringify(values[0]));
3737
- return values[0];
3738
+ return unit;
3738
3739
  }
3739
3740
  });
3740
3741
  /**
@@ -3754,14 +3755,16 @@ Will use tabs for as much of the columns as possible when the
3754
3755
  tabs.
3755
3756
  */
3756
3757
  function indentString(state, cols) {
3757
- let result = "", ts = state.tabSize;
3758
- if (state.facet(dist_indentUnit).charCodeAt(0) == 9)
3758
+ let result = "", ts = state.tabSize, ch = state.facet(dist_indentUnit)[0];
3759
+ if (ch == "\t") {
3759
3760
  while (cols >= ts) {
3760
3761
  result += "\t";
3761
3762
  cols -= ts;
3762
3763
  }
3764
+ ch = " ";
3765
+ }
3763
3766
  for (let i = 0; i < cols; i++)
3764
- result += " ";
3767
+ result += ch;
3765
3768
  return result;
3766
3769
  }
3767
3770
  /**
@@ -4344,6 +4347,41 @@ const unfoldAll = view => {
4344
4347
  view.dispatch({ effects });
4345
4348
  return true;
4346
4349
  };
4350
+ // Find the foldable region containing the given line, if one exists
4351
+ function foldableContainer(view, lineBlock) {
4352
+ // Look backwards through line blocks until we find a foldable region that
4353
+ // intersects with the line
4354
+ for (let line = lineBlock;;) {
4355
+ let foldableRegion = foldable(view.state, line.from, line.to);
4356
+ if (foldableRegion && foldableRegion.to > lineBlock.from)
4357
+ return foldableRegion;
4358
+ if (!line.from)
4359
+ return null;
4360
+ line = view.lineBlockAt(line.from - 1);
4361
+ }
4362
+ }
4363
+ /**
4364
+ Toggle folding at cursors. Unfolds if there is an existing fold
4365
+ starting in that line, tries to find a foldable range around it
4366
+ otherwise.
4367
+ */
4368
+ const toggleFold = (view) => {
4369
+ let effects = [];
4370
+ for (let line of selectedLines(view)) {
4371
+ let folded = findFold(view.state, line.from, line.to);
4372
+ if (folded) {
4373
+ effects.push(unfoldEffect.of(folded), announceFold(view, folded, false));
4374
+ }
4375
+ else {
4376
+ let foldRange = foldableContainer(view, line);
4377
+ if (foldRange)
4378
+ effects.push(foldEffect.of(foldRange), announceFold(view, foldRange));
4379
+ }
4380
+ }
4381
+ if (effects.length > 0)
4382
+ view.dispatch({ effects: maybeEnable(view.state, effects) });
4383
+ return !!effects.length;
4384
+ };
4347
4385
  /**
4348
4386
  Default fold-related key bindings.
4349
4387
 
@@ -4731,6 +4769,15 @@ highlighting style is used to indicate this.
4731
4769
  function bracketMatching(config = {}) {
4732
4770
  return [bracketMatchingConfig.of(config), bracketMatchingUnique];
4733
4771
  }
4772
+ /**
4773
+ When larger syntax nodes, such as HTML tags, are marked as
4774
+ opening/closing, it can be a bit messy to treat the whole node as
4775
+ a matchable bracket. This node prop allows you to define, for such
4776
+ a node, a ‘handle’—the part of the node that is highlighted, and
4777
+ that the cursor must be on to activate highlighting in the first
4778
+ place.
4779
+ */
4780
+ const bracketMatchingHandle = /*@__PURE__*/new dist_NodeProp();
4734
4781
  function matchingNodes(node, dir, brackets) {
4735
4782
  let byProp = node.prop(dir < 0 ? dist_NodeProp.openedBy : dist_NodeProp.closedBy);
4736
4783
  if (byProp)
@@ -4742,6 +4789,10 @@ function matchingNodes(node, dir, brackets) {
4742
4789
  }
4743
4790
  return null;
4744
4791
  }
4792
+ function findHandle(node) {
4793
+ let hasHandle = node.type.prop(bracketMatchingHandle);
4794
+ return hasHandle ? hasHandle(node.node) : node;
4795
+ }
4745
4796
  /**
4746
4797
  Find the matching bracket for the token at `pos`, scanning
4747
4798
  direction `dir`. Only the `brackets` and `maxScanDistance`
@@ -4753,30 +4804,36 @@ function matchBrackets(state, pos, dir, config = {}) {
4753
4804
  let tree = dist_syntaxTree(state), node = tree.resolveInner(pos, dir);
4754
4805
  for (let cur = node; cur; cur = cur.parent) {
4755
4806
  let matches = matchingNodes(cur.type, dir, brackets);
4756
- if (matches && cur.from < cur.to)
4757
- return matchMarkedBrackets(state, pos, dir, cur, matches, brackets);
4807
+ if (matches && cur.from < cur.to) {
4808
+ let handle = findHandle(cur);
4809
+ if (handle && (dir > 0 ? pos >= handle.from && pos < handle.to : pos > handle.from && pos <= handle.to))
4810
+ return matchMarkedBrackets(state, pos, dir, cur, handle, matches, brackets);
4811
+ }
4758
4812
  }
4759
4813
  return matchPlainBrackets(state, pos, dir, tree, node.type, maxScanDistance, brackets);
4760
4814
  }
4761
- function matchMarkedBrackets(_state, _pos, dir, token, matching, brackets) {
4762
- let parent = token.parent, firstToken = { from: token.from, to: token.to };
4815
+ function matchMarkedBrackets(_state, _pos, dir, token, handle, matching, brackets) {
4816
+ let parent = token.parent, firstToken = { from: handle.from, to: handle.to };
4763
4817
  let depth = 0, cursor = parent === null || parent === void 0 ? void 0 : parent.cursor();
4764
4818
  if (cursor && (dir < 0 ? cursor.childBefore(token.from) : cursor.childAfter(token.to)))
4765
4819
  do {
4766
4820
  if (dir < 0 ? cursor.to <= token.from : cursor.from >= token.to) {
4767
4821
  if (depth == 0 && matching.indexOf(cursor.type.name) > -1 && cursor.from < cursor.to) {
4768
- return { start: firstToken, end: { from: cursor.from, to: cursor.to }, matched: true };
4822
+ let endHandle = findHandle(cursor);
4823
+ return { start: firstToken, end: endHandle ? { from: endHandle.from, to: endHandle.to } : undefined, matched: true };
4769
4824
  }
4770
4825
  else if (matchingNodes(cursor.type, dir, brackets)) {
4771
4826
  depth++;
4772
4827
  }
4773
4828
  else if (matchingNodes(cursor.type, -dir, brackets)) {
4774
- if (depth == 0)
4829
+ if (depth == 0) {
4830
+ let endHandle = findHandle(cursor);
4775
4831
  return {
4776
4832
  start: firstToken,
4777
- end: cursor.from == cursor.to ? undefined : { from: cursor.from, to: cursor.to },
4833
+ end: endHandle && endHandle.from < endHandle.to ? { from: endHandle.from, to: endHandle.to } : undefined,
4778
4834
  matched: false
4779
4835
  };
4836
+ }
4780
4837
  depth--;
4781
4838
  }
4782
4839
  }
@@ -4848,10 +4905,11 @@ class StringStream {
4848
4905
  /**
4849
4906
  The current indent unit size.
4850
4907
  */
4851
- indentUnit) {
4908
+ indentUnit, overrideIndent) {
4852
4909
  this.string = string;
4853
4910
  this.tabSize = tabSize;
4854
4911
  this.indentUnit = indentUnit;
4912
+ this.overrideIndent = overrideIndent;
4855
4913
  /**
4856
4914
  The current position on the line.
4857
4915
  */
@@ -4952,7 +5010,8 @@ class StringStream {
4952
5010
  Get the indentation column of the current line.
4953
5011
  */
4954
5012
  indentation() {
4955
- return countCol(this.string, null, this.tabSize);
5013
+ var _a;
5014
+ return (_a = this.overrideIndent) !== null && _a !== void 0 ? _a : countCol(this.string, null, this.tabSize);
4956
5015
  }
4957
5016
  /**
4958
5017
  Match the input against the given string or regular expression
@@ -5014,6 +5073,7 @@ function defaultCopyState(state) {
5014
5073
  }
5015
5074
  return newState;
5016
5075
  }
5076
+ const IndentedFrom = /*@__PURE__*/new WeakMap();
5017
5077
  /**
5018
5078
  A [language](https://codemirror.net/6/docs/ref/#language.Language) class based on a CodeMirror
5019
5079
  5-style [streaming parser](https://codemirror.net/6/docs/ref/#language.StreamParser).
@@ -5044,7 +5104,14 @@ class StreamLanguage extends (/* unused pure expression or super */ null && (Lan
5044
5104
  at = at.parent;
5045
5105
  if (!at)
5046
5106
  return null;
5047
- let start = findState(this, tree, 0, at.from, pos), statePos, state;
5107
+ let from = undefined;
5108
+ let { overrideIndentation } = cx.options;
5109
+ if (overrideIndentation) {
5110
+ from = IndentedFrom.get(cx.state);
5111
+ if (from != null && from < pos - 1e4)
5112
+ from = undefined;
5113
+ }
5114
+ let start = findState(this, tree, 0, at.from, from !== null && from !== void 0 ? from : pos), statePos, state;
5048
5115
  if (start) {
5049
5116
  state = start.state;
5050
5117
  statePos = start.pos + 1;
@@ -5058,7 +5125,8 @@ class StreamLanguage extends (/* unused pure expression or super */ null && (Lan
5058
5125
  while (statePos < pos) {
5059
5126
  let line = cx.state.doc.lineAt(statePos), end = Math.min(pos, line.to);
5060
5127
  if (line.length) {
5061
- let stream = new StringStream(line.text, cx.state.tabSize, cx.unit);
5128
+ let indentation = overrideIndentation ? overrideIndentation(line.from) : -1;
5129
+ let stream = new StringStream(line.text, cx.state.tabSize, cx.unit, indentation < 0 ? undefined : indentation);
5062
5130
  while (stream.pos < end - line.from)
5063
5131
  readToken(this.streamParser.token, stream, state);
5064
5132
  }
@@ -5069,8 +5137,10 @@ class StreamLanguage extends (/* unused pure expression or super */ null && (Lan
5069
5137
  break;
5070
5138
  statePos = line.to + 1;
5071
5139
  }
5072
- let { text } = cx.lineAt(pos);
5073
- return this.streamParser.indent(state, /^\s*(.*)/.exec(text)[1], cx);
5140
+ let line = cx.lineAt(pos);
5141
+ if (overrideIndentation && from == null)
5142
+ IndentedFrom.set(cx.state, line.from);
5143
+ return this.streamParser.indent(state, /^\s*(.*)/.exec(line.text)[1], cx);
5074
5144
  }
5075
5145
  get allowsNesting() { return false; }
5076
5146
  }
@@ -5547,8 +5617,13 @@ const historyConfig = /*@__PURE__*/state_.Facet.define({
5547
5617
  combine(configs) {
5548
5618
  return (0,state_.combineConfig)(configs, {
5549
5619
  minDepth: 100,
5550
- newGroupDelay: 500
5551
- }, { minDepth: Math.max, newGroupDelay: Math.min });
5620
+ newGroupDelay: 500,
5621
+ joinToEvent: (_t, isAdjacent) => isAdjacent,
5622
+ }, {
5623
+ minDepth: Math.max,
5624
+ newGroupDelay: Math.min,
5625
+ joinToEvent: (a, b) => (tr, adj) => a(tr, adj) || b(tr, adj)
5626
+ });
5552
5627
  }
5553
5628
  });
5554
5629
  function changeEnd(changes) {
@@ -5581,7 +5656,7 @@ const historyField_ = /*@__PURE__*/state_.StateField.define({
5581
5656
  let event = HistEvent.fromTransaction(tr);
5582
5657
  let time = tr.annotation(state_.Transaction.time), userEvent = tr.annotation(state_.Transaction.userEvent);
5583
5658
  if (event)
5584
- state = state.addChanges(event, time, userEvent, config.newGroupDelay, config.minDepth);
5659
+ state = state.addChanges(event, time, userEvent, config, tr);
5585
5660
  else if (tr.selection)
5586
5661
  state = state.addSelection(tr.startState.selection, time, userEvent, config.newGroupDelay);
5587
5662
  if (isolate == "full" || isolate == "after")
@@ -5818,19 +5893,19 @@ class HistoryState {
5818
5893
  isolate() {
5819
5894
  return this.prevTime ? new HistoryState(this.done, this.undone) : this;
5820
5895
  }
5821
- addChanges(event, time, userEvent, newGroupDelay, maxLen) {
5896
+ addChanges(event, time, userEvent, config, tr) {
5822
5897
  let done = this.done, lastEvent = done[done.length - 1];
5823
5898
  if (lastEvent && lastEvent.changes && !lastEvent.changes.empty && event.changes &&
5824
5899
  (!userEvent || joinableUserEvent.test(userEvent)) &&
5825
5900
  ((!lastEvent.selectionsAfter.length &&
5826
- time - this.prevTime < newGroupDelay &&
5827
- isAdjacent(lastEvent.changes, event.changes)) ||
5901
+ time - this.prevTime < config.newGroupDelay &&
5902
+ config.joinToEvent(tr, isAdjacent(lastEvent.changes, event.changes))) ||
5828
5903
  // For compose (but not compose.start) events, always join with previous event
5829
5904
  userEvent == "input.type.compose")) {
5830
- done = updateBranch(done, done.length - 1, maxLen, new HistEvent(event.changes.compose(lastEvent.changes), conc(event.effects, lastEvent.effects), lastEvent.mapped, lastEvent.startSelection, none));
5905
+ done = updateBranch(done, done.length - 1, config.minDepth, new HistEvent(event.changes.compose(lastEvent.changes), conc(event.effects, lastEvent.effects), lastEvent.mapped, lastEvent.startSelection, none));
5831
5906
  }
5832
5907
  else {
5833
- done = updateBranch(done, done.length, maxLen, event);
5908
+ done = updateBranch(done, done.length, config.minDepth, event);
5834
5909
  }
5835
5910
  return new HistoryState(done, none, time, userEvent);
5836
5911
  }
@@ -10878,8 +10953,10 @@ var theme_one_dark_ = __webpack_require__(362);
10878
10953
  ;// CONCATENATED MODULE: ./src/utils.ts
10879
10954
  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;})};};
10880
10955
  ;// CONCATENATED MODULE: ./src/useCodeMirror.ts
10881
- 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,initialState=props.initialState;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();onChange(_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;case'none':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 config={doc:value,selection:selection,extensions:getExtensions};var stateCurrent=initialState?state_.EditorState.fromJSON(initialState.json,config,initialState.fields):state_.EditorState.create(config);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
10882
- },[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(){if(value===undefined){return;}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};}
10956
+ var External=state_.Annotation.define();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,initialState=props.initialState;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'&&// Fix echoing of the remote changes:
10957
+ // If transaction is market as remote we don't have to call `onChange` handler again
10958
+ !vu.transactions.some(function(tr){return tr.annotation(External);})){var doc=vu.state.doc;var _value=doc.toString();onChange(_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;case'none':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 config={doc:value,selection:selection,extensions:getExtensions};var stateCurrent=initialState?state_.EditorState.fromJSON(initialState.json,config,initialState.fields):state_.EditorState.create(config);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
10959
+ },[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(){if(value===undefined){return;}var currentValue=view?view.state.doc.toString():'';if(view&&value!==currentValue){view.dispatch({changes:{from:0,to:currentValue.length,insert:value||''},annotations:[External.of(true)]});}},[value,view]);return{state:state,setState:setState,view:view,setView:setView,container:container,setContainer:setContainer};}
10883
10960
  // EXTERNAL MODULE: ../node_modules/react/jsx-runtime.js
10884
10961
  var jsx_runtime = __webpack_require__(605);
10885
10962
  ;// CONCATENATED MODULE: ./src/index.tsx