@uiw/react-codemirror 4.19.7 → 4.19.9

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.
@@ -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,EAAE;IAAA,kBASRf,KAAK,CARPgB,QAAQ;IAARA,QAAQ,gCAAG,EAAE;IAAA,kBAQXhB,KAAK,CAPPiB,QAAQ;IAARA,QAAQ,gCAAG,EAAE;IAAA,kBAOXjB,KAAK,CANPkB,QAAQ;IAARA,QAAQ,gCAAG,IAAI;IAAA,kBAMblB,KAAK,CALPmB,QAAQ;IAARA,QAAQ,gCAAG,KAAK;IAAA,uBAKdnB,KAAK,CAJPoB,aAAa;IAAEC,oBAAoB,qCAAG,IAAI;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}
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
 
@@ -4867,10 +4905,11 @@ class StringStream {
4867
4905
  /**
4868
4906
  The current indent unit size.
4869
4907
  */
4870
- indentUnit) {
4908
+ indentUnit, overrideIndent) {
4871
4909
  this.string = string;
4872
4910
  this.tabSize = tabSize;
4873
4911
  this.indentUnit = indentUnit;
4912
+ this.overrideIndent = overrideIndent;
4874
4913
  /**
4875
4914
  The current position on the line.
4876
4915
  */
@@ -4971,7 +5010,8 @@ class StringStream {
4971
5010
  Get the indentation column of the current line.
4972
5011
  */
4973
5012
  indentation() {
4974
- 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);
4975
5015
  }
4976
5016
  /**
4977
5017
  Match the input against the given string or regular expression
@@ -5033,6 +5073,7 @@ function defaultCopyState(state) {
5033
5073
  }
5034
5074
  return newState;
5035
5075
  }
5076
+ const IndentedFrom = /*@__PURE__*/new WeakMap();
5036
5077
  /**
5037
5078
  A [language](https://codemirror.net/6/docs/ref/#language.Language) class based on a CodeMirror
5038
5079
  5-style [streaming parser](https://codemirror.net/6/docs/ref/#language.StreamParser).
@@ -5063,7 +5104,14 @@ class StreamLanguage extends (/* unused pure expression or super */ null && (Lan
5063
5104
  at = at.parent;
5064
5105
  if (!at)
5065
5106
  return null;
5066
- 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;
5067
5115
  if (start) {
5068
5116
  state = start.state;
5069
5117
  statePos = start.pos + 1;
@@ -5077,7 +5125,8 @@ class StreamLanguage extends (/* unused pure expression or super */ null && (Lan
5077
5125
  while (statePos < pos) {
5078
5126
  let line = cx.state.doc.lineAt(statePos), end = Math.min(pos, line.to);
5079
5127
  if (line.length) {
5080
- 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);
5081
5130
  while (stream.pos < end - line.from)
5082
5131
  readToken(this.streamParser.token, stream, state);
5083
5132
  }
@@ -5088,8 +5137,10 @@ class StreamLanguage extends (/* unused pure expression or super */ null && (Lan
5088
5137
  break;
5089
5138
  statePos = line.to + 1;
5090
5139
  }
5091
- let { text } = cx.lineAt(pos);
5092
- 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);
5093
5144
  }
5094
5145
  get allowsNesting() { return false; }
5095
5146
  }
@@ -5566,8 +5617,13 @@ const historyConfig = /*@__PURE__*/state_.Facet.define({
5566
5617
  combine(configs) {
5567
5618
  return (0,state_.combineConfig)(configs, {
5568
5619
  minDepth: 100,
5569
- newGroupDelay: 500
5570
- }, { 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
+ });
5571
5627
  }
5572
5628
  });
5573
5629
  function changeEnd(changes) {
@@ -5600,7 +5656,7 @@ const historyField_ = /*@__PURE__*/state_.StateField.define({
5600
5656
  let event = HistEvent.fromTransaction(tr);
5601
5657
  let time = tr.annotation(state_.Transaction.time), userEvent = tr.annotation(state_.Transaction.userEvent);
5602
5658
  if (event)
5603
- state = state.addChanges(event, time, userEvent, config.newGroupDelay, config.minDepth);
5659
+ state = state.addChanges(event, time, userEvent, config, tr);
5604
5660
  else if (tr.selection)
5605
5661
  state = state.addSelection(tr.startState.selection, time, userEvent, config.newGroupDelay);
5606
5662
  if (isolate == "full" || isolate == "after")
@@ -5837,19 +5893,19 @@ class HistoryState {
5837
5893
  isolate() {
5838
5894
  return this.prevTime ? new HistoryState(this.done, this.undone) : this;
5839
5895
  }
5840
- addChanges(event, time, userEvent, newGroupDelay, maxLen) {
5896
+ addChanges(event, time, userEvent, config, tr) {
5841
5897
  let done = this.done, lastEvent = done[done.length - 1];
5842
5898
  if (lastEvent && lastEvent.changes && !lastEvent.changes.empty && event.changes &&
5843
5899
  (!userEvent || joinableUserEvent.test(userEvent)) &&
5844
5900
  ((!lastEvent.selectionsAfter.length &&
5845
- time - this.prevTime < newGroupDelay &&
5846
- isAdjacent(lastEvent.changes, event.changes)) ||
5901
+ time - this.prevTime < config.newGroupDelay &&
5902
+ config.joinToEvent(tr, isAdjacent(lastEvent.changes, event.changes))) ||
5847
5903
  // For compose (but not compose.start) events, always join with previous event
5848
5904
  userEvent == "input.type.compose")) {
5849
- 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));
5850
5906
  }
5851
5907
  else {
5852
- done = updateBranch(done, done.length, maxLen, event);
5908
+ done = updateBranch(done, done.length, config.minDepth, event);
5853
5909
  }
5854
5910
  return new HistoryState(done, none, time, userEvent);
5855
5911
  }
@@ -10897,8 +10953,10 @@ var theme_one_dark_ = __webpack_require__(362);
10897
10953
  ;// CONCATENATED MODULE: ./src/utils.ts
10898
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;})};};
10899
10955
  ;// CONCATENATED MODULE: ./src/useCodeMirror.ts
10900
- 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
10901
- },[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};}
10902
10960
  // EXTERNAL MODULE: ../node_modules/react/jsx-runtime.js
10903
10961
  var jsx_runtime = __webpack_require__(605);
10904
10962
  ;// CONCATENATED MODULE: ./src/index.tsx