@maketribe/ms-app 3.0.35 → 3.0.37

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.
Files changed (93) hide show
  1. package/dist/cjs/dataview/material/material-group/MaterialGroupTree.js +1 -0
  2. package/dist/cjs/dataview/material/material-group/MaterialGroupTree.js.map +1 -1
  3. package/dist/cjs/dataview/member/MemberTable.js +2 -2
  4. package/dist/cjs/dataview/member/MemberTable.js.map +1 -1
  5. package/dist/cjs/dataview/menu/MenuTable.js +33 -0
  6. package/dist/cjs/dataview/menu/MenuTable.js.map +1 -1
  7. package/dist/cjs/layouts/components/header/tools.js +7 -2
  8. package/dist/cjs/layouts/components/header/tools.js.map +1 -1
  9. package/dist/cjs/node_modules/.pnpm/{@codemirror_autocomplete@6.11.1_@codemirror_language@6.9.3_@codemirror_state@6.3.2_@codemirro_dop6xooh6ucho44vivbvrw3b2e → @codemirror_autocomplete@6.15.0_@codemirror_language@6.10.1_@codemirror_state@6.4.1_@codemirr_djjyqdn7bhwopzrz2h2s2bwhzm}/node_modules/@codemirror/autocomplete/dist/index.js +77 -25
  10. package/dist/cjs/node_modules/.pnpm/@codemirror_autocomplete@6.15.0_@codemirror_language@6.10.1_@codemirror_state@6.4.1_@codemirr_djjyqdn7bhwopzrz2h2s2bwhzm/node_modules/@codemirror/autocomplete/dist/index.js.map +1 -0
  11. package/dist/cjs/node_modules/.pnpm/@codemirror_commands@6.3.2/node_modules/@codemirror/commands/dist/index.js +7 -1433
  12. package/dist/cjs/node_modules/.pnpm/@codemirror_commands@6.3.2/node_modules/@codemirror/commands/dist/index.js.map +1 -1
  13. package/dist/cjs/node_modules/.pnpm/@codemirror_commands@6.3.3/node_modules/@codemirror/commands/dist/index.js +1484 -0
  14. package/dist/cjs/node_modules/.pnpm/@codemirror_commands@6.3.3/node_modules/@codemirror/commands/dist/index.js.map +1 -0
  15. package/dist/cjs/node_modules/.pnpm/@codemirror_language@6.10.1/node_modules/@codemirror/language/dist/index.js +1751 -0
  16. package/dist/cjs/node_modules/.pnpm/@codemirror_language@6.10.1/node_modules/@codemirror/language/dist/index.js.map +1 -0
  17. package/dist/cjs/node_modules/.pnpm/@codemirror_language@6.9.3/node_modules/@codemirror/language/dist/index.js +0 -1030
  18. package/dist/cjs/node_modules/.pnpm/@codemirror_language@6.9.3/node_modules/@codemirror/language/dist/index.js.map +1 -1
  19. package/dist/cjs/node_modules/.pnpm/{@codemirror_lint@6.4.2 → @codemirror_lint@6.5.0}/node_modules/@codemirror/lint/dist/index.js +8 -7
  20. package/dist/cjs/node_modules/.pnpm/@codemirror_lint@6.5.0/node_modules/@codemirror/lint/dist/index.js.map +1 -0
  21. package/dist/cjs/node_modules/.pnpm/{@codemirror_search@6.5.5 → @codemirror_search@6.5.6}/node_modules/@codemirror/search/dist/index.js +9 -9
  22. package/dist/cjs/node_modules/.pnpm/@codemirror_search@6.5.6/node_modules/@codemirror/search/dist/index.js.map +1 -0
  23. package/dist/cjs/node_modules/.pnpm/@codemirror_state@6.3.2/node_modules/@codemirror/state/dist/index.js +0 -42
  24. package/dist/cjs/node_modules/.pnpm/@codemirror_state@6.3.2/node_modules/@codemirror/state/dist/index.js.map +1 -1
  25. package/dist/cjs/node_modules/.pnpm/@codemirror_state@6.4.1/node_modules/@codemirror/state/dist/index.js +3958 -0
  26. package/dist/cjs/node_modules/.pnpm/@codemirror_state@6.4.1/node_modules/@codemirror/state/dist/index.js.map +1 -0
  27. package/dist/cjs/node_modules/.pnpm/@codemirror_view@6.22.1/node_modules/@codemirror/view/dist/index.js +3 -2161
  28. package/dist/cjs/node_modules/.pnpm/@codemirror_view@6.22.1/node_modules/@codemirror/view/dist/index.js.map +1 -1
  29. package/dist/cjs/node_modules/.pnpm/@codemirror_view@6.26.1/node_modules/@codemirror/view/dist/index.js +10580 -0
  30. package/dist/cjs/node_modules/.pnpm/@codemirror_view@6.26.1/node_modules/@codemirror/view/dist/index.js.map +1 -0
  31. package/dist/cjs/node_modules/.pnpm/@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js +1668 -0
  32. package/dist/cjs/node_modules/.pnpm/@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js.map +1 -0
  33. package/dist/cjs/node_modules/.pnpm/{codemirror@6.0.1_@lezer_common@1.1.1 → codemirror@6.0.1_@lezer_common@1.2.1}/node_modules/codemirror/dist/index.js +7 -7
  34. package/dist/cjs/node_modules/.pnpm/{codemirror@6.0.1_@lezer_common@1.1.1 → codemirror@6.0.1_@lezer_common@1.2.1}/node_modules/codemirror/dist/index.js.map +1 -1
  35. package/dist/cjs/node_modules/.pnpm/style-mod@4.1.2/node_modules/style-mod/src/style-mod.js +177 -0
  36. package/dist/cjs/node_modules/.pnpm/style-mod@4.1.2/node_modules/style-mod/src/style-mod.js.map +1 -0
  37. package/dist/cjs/node_modules/.pnpm/vue-codemirror@6.1.1_codemirror@6.0.1_vue@3.3.4/node_modules/vue-codemirror/dist/vue-codemirror.esm.js +1 -1
  38. package/dist/esm/dataview/material/material-group/MaterialGroupTree.js +1 -0
  39. package/dist/esm/dataview/material/material-group/MaterialGroupTree.js.map +1 -1
  40. package/dist/esm/dataview/member/MemberTable.js +2 -2
  41. package/dist/esm/dataview/member/MemberTable.js.map +1 -1
  42. package/dist/esm/dataview/menu/MenuTable.js +34 -1
  43. package/dist/esm/dataview/menu/MenuTable.js.map +1 -1
  44. package/dist/esm/layouts/components/header/tools.js +7 -2
  45. package/dist/esm/layouts/components/header/tools.js.map +1 -1
  46. package/dist/esm/node_modules/.pnpm/{@codemirror_autocomplete@6.11.1_@codemirror_language@6.9.3_@codemirror_state@6.3.2_@codemirro_dop6xooh6ucho44vivbvrw3b2e → @codemirror_autocomplete@6.15.0_@codemirror_language@6.10.1_@codemirror_state@6.4.1_@codemirr_djjyqdn7bhwopzrz2h2s2bwhzm}/node_modules/@codemirror/autocomplete/dist/index.js +77 -25
  47. package/dist/esm/node_modules/.pnpm/@codemirror_autocomplete@6.15.0_@codemirror_language@6.10.1_@codemirror_state@6.4.1_@codemirr_djjyqdn7bhwopzrz2h2s2bwhzm/node_modules/@codemirror/autocomplete/dist/index.js.map +1 -0
  48. package/dist/esm/node_modules/.pnpm/@codemirror_commands@6.3.2/node_modules/@codemirror/commands/dist/index.js +4 -1357
  49. package/dist/esm/node_modules/.pnpm/@codemirror_commands@6.3.2/node_modules/@codemirror/commands/dist/index.js.map +1 -1
  50. package/dist/esm/node_modules/.pnpm/@codemirror_commands@6.3.3/node_modules/@codemirror/commands/dist/index.js +1408 -0
  51. package/dist/esm/node_modules/.pnpm/@codemirror_commands@6.3.3/node_modules/@codemirror/commands/dist/index.js.map +1 -0
  52. package/dist/esm/node_modules/.pnpm/@codemirror_language@6.10.1/node_modules/@codemirror/language/dist/index.js +1715 -0
  53. package/dist/esm/node_modules/.pnpm/@codemirror_language@6.10.1/node_modules/@codemirror/language/dist/index.js.map +1 -0
  54. package/dist/esm/node_modules/.pnpm/@codemirror_language@6.9.3/node_modules/@codemirror/language/dist/index.js +4 -1011
  55. package/dist/esm/node_modules/.pnpm/@codemirror_language@6.9.3/node_modules/@codemirror/language/dist/index.js.map +1 -1
  56. package/dist/esm/node_modules/.pnpm/{@codemirror_lint@6.4.2 → @codemirror_lint@6.5.0}/node_modules/@codemirror/lint/dist/index.js +8 -7
  57. package/dist/esm/node_modules/.pnpm/@codemirror_lint@6.5.0/node_modules/@codemirror/lint/dist/index.js.map +1 -0
  58. package/dist/esm/node_modules/.pnpm/{@codemirror_search@6.5.5 → @codemirror_search@6.5.6}/node_modules/@codemirror/search/dist/index.js +9 -9
  59. package/dist/esm/node_modules/.pnpm/@codemirror_search@6.5.6/node_modules/@codemirror/search/dist/index.js.map +1 -0
  60. package/dist/esm/node_modules/.pnpm/@codemirror_state@6.3.2/node_modules/@codemirror/state/dist/index.js +1 -41
  61. package/dist/esm/node_modules/.pnpm/@codemirror_state@6.3.2/node_modules/@codemirror/state/dist/index.js.map +1 -1
  62. package/dist/esm/node_modules/.pnpm/@codemirror_state@6.4.1/node_modules/@codemirror/state/dist/index.js +3930 -0
  63. package/dist/esm/node_modules/.pnpm/@codemirror_state@6.4.1/node_modules/@codemirror/state/dist/index.js.map +1 -0
  64. package/dist/esm/node_modules/.pnpm/@codemirror_view@6.22.1/node_modules/@codemirror/view/dist/index.js +5 -2142
  65. package/dist/esm/node_modules/.pnpm/@codemirror_view@6.22.1/node_modules/@codemirror/view/dist/index.js.map +1 -1
  66. package/dist/esm/node_modules/.pnpm/@codemirror_view@6.26.1/node_modules/@codemirror/view/dist/index.js +10548 -0
  67. package/dist/esm/node_modules/.pnpm/@codemirror_view@6.26.1/node_modules/@codemirror/view/dist/index.js.map +1 -0
  68. package/dist/esm/node_modules/.pnpm/@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js +1658 -0
  69. package/dist/esm/node_modules/.pnpm/@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js.map +1 -0
  70. package/dist/esm/node_modules/.pnpm/{codemirror@6.0.1_@lezer_common@1.1.1 → codemirror@6.0.1_@lezer_common@1.2.1}/node_modules/codemirror/dist/index.js +8 -8
  71. package/dist/esm/node_modules/.pnpm/{codemirror@6.0.1_@lezer_common@1.1.1 → codemirror@6.0.1_@lezer_common@1.2.1}/node_modules/codemirror/dist/index.js.map +1 -1
  72. package/dist/esm/node_modules/.pnpm/style-mod@4.1.2/node_modules/style-mod/src/style-mod.js +175 -0
  73. package/dist/esm/node_modules/.pnpm/style-mod@4.1.2/node_modules/style-mod/src/style-mod.js.map +1 -0
  74. package/dist/esm/node_modules/.pnpm/vue-codemirror@6.1.1_codemirror@6.0.1_vue@3.3.4/node_modules/vue-codemirror/dist/vue-codemirror.esm.js +1 -1
  75. package/dist/style/components/classify-search.css +1 -1
  76. package/dist/style/components/index.css +1 -1
  77. package/dist/style/index.css +2 -2
  78. package/dist/style/layouts/default/header.css +1 -1
  79. package/dist/style/layouts/default/index.css +1 -1
  80. package/dist/style/layouts/index.css +1 -1
  81. package/dist/style/src/components/classify-search.scss +5 -2
  82. package/dist/style/src/layouts/default/header.scss +4 -0
  83. package/package.json +3 -3
  84. package/src/dataview/material/material-group/MaterialGroupTree.ts +1 -0
  85. package/src/dataview/member/MemberTable.tsx +2 -2
  86. package/src/dataview/menu/MenuTable.ts +34 -1
  87. package/src/layouts/components/header/tools.tsx +6 -1
  88. package/dist/cjs/node_modules/.pnpm/@codemirror_autocomplete@6.11.1_@codemirror_language@6.9.3_@codemirror_state@6.3.2_@codemirro_dop6xooh6ucho44vivbvrw3b2e/node_modules/@codemirror/autocomplete/dist/index.js.map +0 -1
  89. package/dist/cjs/node_modules/.pnpm/@codemirror_lint@6.4.2/node_modules/@codemirror/lint/dist/index.js.map +0 -1
  90. package/dist/cjs/node_modules/.pnpm/@codemirror_search@6.5.5/node_modules/@codemirror/search/dist/index.js.map +0 -1
  91. package/dist/esm/node_modules/.pnpm/@codemirror_autocomplete@6.11.1_@codemirror_language@6.9.3_@codemirror_state@6.3.2_@codemirro_dop6xooh6ucho44vivbvrw3b2e/node_modules/@codemirror/autocomplete/dist/index.js.map +0 -1
  92. package/dist/esm/node_modules/.pnpm/@codemirror_lint@6.4.2/node_modules/@codemirror/lint/dist/index.js.map +0 -1
  93. package/dist/esm/node_modules/.pnpm/@codemirror_search@6.5.5/node_modules/@codemirror/search/dist/index.js.map +0 -1
@@ -0,0 +1,1715 @@
1
+ import { NodeType, Tree, NodeProp, IterMode, TreeFragment, Parser } from '../../../../../@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js';
2
+ import { EditorState, RangeSet, Prec, StateField, Facet, countColumn, StateEffect, combineConfig, RangeSetBuilder } from '../../../../../@codemirror_state@6.4.1/node_modules/@codemirror/state/dist/index.js';
3
+ import { ViewPlugin, gutter, EditorView, Decoration, Direction, WidgetType, GutterMarker, logException } from '../../../../../@codemirror_view@6.26.1/node_modules/@codemirror/view/dist/index.js';
4
+ import { tags, styleTags, tagHighlighter, highlightTree } from '../../../../../@lezer_highlight@1.2.0/node_modules/@lezer/highlight/dist/index.js';
5
+ import { StyleModule } from '../../../../../style-mod@4.1.2/node_modules/style-mod/src/style-mod.js';
6
+
7
+ var _a;
8
+ /**
9
+ Node prop stored in a parser's top syntax node to provide the
10
+ facet that stores language-specific data for that language.
11
+ */
12
+ const languageDataProp = /*@__PURE__*/new NodeProp();
13
+ /**
14
+ Syntax node prop used to register sublanguages. Should be added to
15
+ the top level node type for the language.
16
+ */
17
+ const sublanguageProp = /*@__PURE__*/new NodeProp();
18
+ /**
19
+ A language object manages parsing and per-language
20
+ [metadata](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt). Parse data is
21
+ managed as a [Lezer](https://lezer.codemirror.net) tree. The class
22
+ can be used directly, via the [`LRLanguage`](https://codemirror.net/6/docs/ref/#language.LRLanguage)
23
+ subclass for [Lezer](https://lezer.codemirror.net/) LR parsers, or
24
+ via the [`StreamLanguage`](https://codemirror.net/6/docs/ref/#language.StreamLanguage) subclass
25
+ for stream parsers.
26
+ */
27
+ class Language {
28
+ /**
29
+ Construct a language object. If you need to invoke this
30
+ directly, first define a data facet with
31
+ [`defineLanguageFacet`](https://codemirror.net/6/docs/ref/#language.defineLanguageFacet), and then
32
+ configure your parser to [attach](https://codemirror.net/6/docs/ref/#language.languageDataProp) it
33
+ to the language's outer syntax node.
34
+ */
35
+ constructor(
36
+ /**
37
+ The [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) facet
38
+ used for this language.
39
+ */
40
+ data, parser, extraExtensions = [],
41
+ /**
42
+ A language name.
43
+ */
44
+ name = "") {
45
+ this.data = data;
46
+ this.name = name;
47
+ // Kludge to define EditorState.tree as a debugging helper,
48
+ // without the EditorState package actually knowing about
49
+ // languages and lezer trees.
50
+ if (!EditorState.prototype.hasOwnProperty("tree"))
51
+ Object.defineProperty(EditorState.prototype, "tree", { get() { return syntaxTree(this); } });
52
+ this.parser = parser;
53
+ this.extension = [
54
+ language.of(this),
55
+ EditorState.languageData.of((state, pos, side) => {
56
+ let top = topNodeAt(state, pos, side), data = top.type.prop(languageDataProp);
57
+ if (!data)
58
+ return [];
59
+ let base = state.facet(data), sub = top.type.prop(sublanguageProp);
60
+ if (sub) {
61
+ let innerNode = top.resolve(pos - top.from, side);
62
+ for (let sublang of sub)
63
+ if (sublang.test(innerNode, state)) {
64
+ let data = state.facet(sublang.facet);
65
+ return sublang.type == "replace" ? data : data.concat(base);
66
+ }
67
+ }
68
+ return base;
69
+ })
70
+ ].concat(extraExtensions);
71
+ }
72
+ /**
73
+ Query whether this language is active at the given position.
74
+ */
75
+ isActiveAt(state, pos, side = -1) {
76
+ return topNodeAt(state, pos, side).type.prop(languageDataProp) == this.data;
77
+ }
78
+ /**
79
+ Find the document regions that were parsed using this language.
80
+ The returned regions will _include_ any nested languages rooted
81
+ in this language, when those exist.
82
+ */
83
+ findRegions(state) {
84
+ let lang = state.facet(language);
85
+ if ((lang === null || lang === void 0 ? void 0 : lang.data) == this.data)
86
+ return [{ from: 0, to: state.doc.length }];
87
+ if (!lang || !lang.allowsNesting)
88
+ return [];
89
+ let result = [];
90
+ let explore = (tree, from) => {
91
+ if (tree.prop(languageDataProp) == this.data) {
92
+ result.push({ from, to: from + tree.length });
93
+ return;
94
+ }
95
+ let mount = tree.prop(NodeProp.mounted);
96
+ if (mount) {
97
+ if (mount.tree.prop(languageDataProp) == this.data) {
98
+ if (mount.overlay)
99
+ for (let r of mount.overlay)
100
+ result.push({ from: r.from + from, to: r.to + from });
101
+ else
102
+ result.push({ from: from, to: from + tree.length });
103
+ return;
104
+ }
105
+ else if (mount.overlay) {
106
+ let size = result.length;
107
+ explore(mount.tree, mount.overlay[0].from + from);
108
+ if (result.length > size)
109
+ return;
110
+ }
111
+ }
112
+ for (let i = 0; i < tree.children.length; i++) {
113
+ let ch = tree.children[i];
114
+ if (ch instanceof Tree)
115
+ explore(ch, tree.positions[i] + from);
116
+ }
117
+ };
118
+ explore(syntaxTree(state), 0);
119
+ return result;
120
+ }
121
+ /**
122
+ Indicates whether this language allows nested languages. The
123
+ default implementation returns true.
124
+ */
125
+ get allowsNesting() { return true; }
126
+ }
127
+ /**
128
+ @internal
129
+ */
130
+ Language.setState = /*@__PURE__*/StateEffect.define();
131
+ function topNodeAt(state, pos, side) {
132
+ let topLang = state.facet(language), tree = syntaxTree(state).topNode;
133
+ if (!topLang || topLang.allowsNesting) {
134
+ for (let node = tree; node; node = node.enter(pos, side, IterMode.ExcludeBuffers))
135
+ if (node.type.isTop)
136
+ tree = node;
137
+ }
138
+ return tree;
139
+ }
140
+ /**
141
+ Get the syntax tree for a state, which is the current (possibly
142
+ incomplete) parse tree of the active
143
+ [language](https://codemirror.net/6/docs/ref/#language.Language), or the empty tree if there is no
144
+ language available.
145
+ */
146
+ function syntaxTree(state) {
147
+ let field = state.field(Language.state, false);
148
+ return field ? field.tree : Tree.empty;
149
+ }
150
+ /**
151
+ Lezer-style
152
+ [`Input`](https://lezer.codemirror.net/docs/ref#common.Input)
153
+ object for a [`Text`](https://codemirror.net/6/docs/ref/#state.Text) object.
154
+ */
155
+ class DocInput {
156
+ /**
157
+ Create an input object for the given document.
158
+ */
159
+ constructor(doc) {
160
+ this.doc = doc;
161
+ this.cursorPos = 0;
162
+ this.string = "";
163
+ this.cursor = doc.iter();
164
+ }
165
+ get length() { return this.doc.length; }
166
+ syncTo(pos) {
167
+ this.string = this.cursor.next(pos - this.cursorPos).value;
168
+ this.cursorPos = pos + this.string.length;
169
+ return this.cursorPos - this.string.length;
170
+ }
171
+ chunk(pos) {
172
+ this.syncTo(pos);
173
+ return this.string;
174
+ }
175
+ get lineChunks() { return true; }
176
+ read(from, to) {
177
+ let stringStart = this.cursorPos - this.string.length;
178
+ if (from < stringStart || to >= this.cursorPos)
179
+ return this.doc.sliceString(from, to);
180
+ else
181
+ return this.string.slice(from - stringStart, to - stringStart);
182
+ }
183
+ }
184
+ let currentContext = null;
185
+ /**
186
+ A parse context provided to parsers working on the editor content.
187
+ */
188
+ class ParseContext {
189
+ constructor(parser,
190
+ /**
191
+ The current editor state.
192
+ */
193
+ state,
194
+ /**
195
+ Tree fragments that can be reused by incremental re-parses.
196
+ */
197
+ fragments = [],
198
+ /**
199
+ @internal
200
+ */
201
+ tree,
202
+ /**
203
+ @internal
204
+ */
205
+ treeLen,
206
+ /**
207
+ The current editor viewport (or some overapproximation
208
+ thereof). Intended to be used for opportunistically avoiding
209
+ work (in which case
210
+ [`skipUntilInView`](https://codemirror.net/6/docs/ref/#language.ParseContext.skipUntilInView)
211
+ should be called to make sure the parser is restarted when the
212
+ skipped region becomes visible).
213
+ */
214
+ viewport,
215
+ /**
216
+ @internal
217
+ */
218
+ skipped,
219
+ /**
220
+ This is where skipping parsers can register a promise that,
221
+ when resolved, will schedule a new parse. It is cleared when
222
+ the parse worker picks up the promise. @internal
223
+ */
224
+ scheduleOn) {
225
+ this.parser = parser;
226
+ this.state = state;
227
+ this.fragments = fragments;
228
+ this.tree = tree;
229
+ this.treeLen = treeLen;
230
+ this.viewport = viewport;
231
+ this.skipped = skipped;
232
+ this.scheduleOn = scheduleOn;
233
+ this.parse = null;
234
+ /**
235
+ @internal
236
+ */
237
+ this.tempSkipped = [];
238
+ }
239
+ /**
240
+ @internal
241
+ */
242
+ static create(parser, state, viewport) {
243
+ return new ParseContext(parser, state, [], Tree.empty, 0, viewport, [], null);
244
+ }
245
+ startParse() {
246
+ return this.parser.startParse(new DocInput(this.state.doc), this.fragments);
247
+ }
248
+ /**
249
+ @internal
250
+ */
251
+ work(until, upto) {
252
+ if (upto != null && upto >= this.state.doc.length)
253
+ upto = undefined;
254
+ if (this.tree != Tree.empty && this.isDone(upto !== null && upto !== void 0 ? upto : this.state.doc.length)) {
255
+ this.takeTree();
256
+ return true;
257
+ }
258
+ return this.withContext(() => {
259
+ var _a;
260
+ if (typeof until == "number") {
261
+ let endTime = Date.now() + until;
262
+ until = () => Date.now() > endTime;
263
+ }
264
+ if (!this.parse)
265
+ this.parse = this.startParse();
266
+ if (upto != null && (this.parse.stoppedAt == null || this.parse.stoppedAt > upto) &&
267
+ upto < this.state.doc.length)
268
+ this.parse.stopAt(upto);
269
+ for (;;) {
270
+ let done = this.parse.advance();
271
+ if (done) {
272
+ this.fragments = this.withoutTempSkipped(TreeFragment.addTree(done, this.fragments, this.parse.stoppedAt != null));
273
+ this.treeLen = (_a = this.parse.stoppedAt) !== null && _a !== void 0 ? _a : this.state.doc.length;
274
+ this.tree = done;
275
+ this.parse = null;
276
+ if (this.treeLen < (upto !== null && upto !== void 0 ? upto : this.state.doc.length))
277
+ this.parse = this.startParse();
278
+ else
279
+ return true;
280
+ }
281
+ if (until())
282
+ return false;
283
+ }
284
+ });
285
+ }
286
+ /**
287
+ @internal
288
+ */
289
+ takeTree() {
290
+ let pos, tree;
291
+ if (this.parse && (pos = this.parse.parsedPos) >= this.treeLen) {
292
+ if (this.parse.stoppedAt == null || this.parse.stoppedAt > pos)
293
+ this.parse.stopAt(pos);
294
+ this.withContext(() => { while (!(tree = this.parse.advance())) { } });
295
+ this.treeLen = pos;
296
+ this.tree = tree;
297
+ this.fragments = this.withoutTempSkipped(TreeFragment.addTree(this.tree, this.fragments, true));
298
+ this.parse = null;
299
+ }
300
+ }
301
+ withContext(f) {
302
+ let prev = currentContext;
303
+ currentContext = this;
304
+ try {
305
+ return f();
306
+ }
307
+ finally {
308
+ currentContext = prev;
309
+ }
310
+ }
311
+ withoutTempSkipped(fragments) {
312
+ for (let r; r = this.tempSkipped.pop();)
313
+ fragments = cutFragments(fragments, r.from, r.to);
314
+ return fragments;
315
+ }
316
+ /**
317
+ @internal
318
+ */
319
+ changes(changes, newState) {
320
+ let { fragments, tree, treeLen, viewport, skipped } = this;
321
+ this.takeTree();
322
+ if (!changes.empty) {
323
+ let ranges = [];
324
+ changes.iterChangedRanges((fromA, toA, fromB, toB) => ranges.push({ fromA, toA, fromB, toB }));
325
+ fragments = TreeFragment.applyChanges(fragments, ranges);
326
+ tree = Tree.empty;
327
+ treeLen = 0;
328
+ viewport = { from: changes.mapPos(viewport.from, -1), to: changes.mapPos(viewport.to, 1) };
329
+ if (this.skipped.length) {
330
+ skipped = [];
331
+ for (let r of this.skipped) {
332
+ let from = changes.mapPos(r.from, 1), to = changes.mapPos(r.to, -1);
333
+ if (from < to)
334
+ skipped.push({ from, to });
335
+ }
336
+ }
337
+ }
338
+ return new ParseContext(this.parser, newState, fragments, tree, treeLen, viewport, skipped, this.scheduleOn);
339
+ }
340
+ /**
341
+ @internal
342
+ */
343
+ updateViewport(viewport) {
344
+ if (this.viewport.from == viewport.from && this.viewport.to == viewport.to)
345
+ return false;
346
+ this.viewport = viewport;
347
+ let startLen = this.skipped.length;
348
+ for (let i = 0; i < this.skipped.length; i++) {
349
+ let { from, to } = this.skipped[i];
350
+ if (from < viewport.to && to > viewport.from) {
351
+ this.fragments = cutFragments(this.fragments, from, to);
352
+ this.skipped.splice(i--, 1);
353
+ }
354
+ }
355
+ if (this.skipped.length >= startLen)
356
+ return false;
357
+ this.reset();
358
+ return true;
359
+ }
360
+ /**
361
+ @internal
362
+ */
363
+ reset() {
364
+ if (this.parse) {
365
+ this.takeTree();
366
+ this.parse = null;
367
+ }
368
+ }
369
+ /**
370
+ Notify the parse scheduler that the given region was skipped
371
+ because it wasn't in view, and the parse should be restarted
372
+ when it comes into view.
373
+ */
374
+ skipUntilInView(from, to) {
375
+ this.skipped.push({ from, to });
376
+ }
377
+ /**
378
+ Returns a parser intended to be used as placeholder when
379
+ asynchronously loading a nested parser. It'll skip its input and
380
+ mark it as not-really-parsed, so that the next update will parse
381
+ it again.
382
+
383
+ When `until` is given, a reparse will be scheduled when that
384
+ promise resolves.
385
+ */
386
+ static getSkippingParser(until) {
387
+ return new class extends Parser {
388
+ createParse(input, fragments, ranges) {
389
+ let from = ranges[0].from, to = ranges[ranges.length - 1].to;
390
+ let parser = {
391
+ parsedPos: from,
392
+ advance() {
393
+ let cx = currentContext;
394
+ if (cx) {
395
+ for (let r of ranges)
396
+ cx.tempSkipped.push(r);
397
+ if (until)
398
+ cx.scheduleOn = cx.scheduleOn ? Promise.all([cx.scheduleOn, until]) : until;
399
+ }
400
+ this.parsedPos = to;
401
+ return new Tree(NodeType.none, [], [], to - from);
402
+ },
403
+ stoppedAt: null,
404
+ stopAt() { }
405
+ };
406
+ return parser;
407
+ }
408
+ };
409
+ }
410
+ /**
411
+ @internal
412
+ */
413
+ isDone(upto) {
414
+ upto = Math.min(upto, this.state.doc.length);
415
+ let frags = this.fragments;
416
+ return this.treeLen >= upto && frags.length && frags[0].from == 0 && frags[0].to >= upto;
417
+ }
418
+ /**
419
+ Get the context for the current parse, or `null` if no editor
420
+ parse is in progress.
421
+ */
422
+ static get() { return currentContext; }
423
+ }
424
+ function cutFragments(fragments, from, to) {
425
+ return TreeFragment.applyChanges(fragments, [{ fromA: from, toA: to, fromB: from, toB: to }]);
426
+ }
427
+ class LanguageState {
428
+ constructor(
429
+ // A mutable parse state that is used to preserve work done during
430
+ // the lifetime of a state when moving to the next state.
431
+ context) {
432
+ this.context = context;
433
+ this.tree = context.tree;
434
+ }
435
+ apply(tr) {
436
+ if (!tr.docChanged && this.tree == this.context.tree)
437
+ return this;
438
+ let newCx = this.context.changes(tr.changes, tr.state);
439
+ // If the previous parse wasn't done, go forward only up to its
440
+ // end position or the end of the viewport, to avoid slowing down
441
+ // state updates with parse work beyond the viewport.
442
+ let upto = this.context.treeLen == tr.startState.doc.length ? undefined
443
+ : Math.max(tr.changes.mapPos(this.context.treeLen), newCx.viewport.to);
444
+ if (!newCx.work(20 /* Work.Apply */, upto))
445
+ newCx.takeTree();
446
+ return new LanguageState(newCx);
447
+ }
448
+ static init(state) {
449
+ let vpTo = Math.min(3000 /* Work.InitViewport */, state.doc.length);
450
+ let parseState = ParseContext.create(state.facet(language).parser, state, { from: 0, to: vpTo });
451
+ if (!parseState.work(20 /* Work.Apply */, vpTo))
452
+ parseState.takeTree();
453
+ return new LanguageState(parseState);
454
+ }
455
+ }
456
+ Language.state = /*@__PURE__*/StateField.define({
457
+ create: LanguageState.init,
458
+ update(value, tr) {
459
+ for (let e of tr.effects)
460
+ if (e.is(Language.setState))
461
+ return e.value;
462
+ if (tr.startState.facet(language) != tr.state.facet(language))
463
+ return LanguageState.init(tr.state);
464
+ return value.apply(tr);
465
+ }
466
+ });
467
+ let requestIdle = (callback) => {
468
+ let timeout = setTimeout(() => callback(), 500 /* Work.MaxPause */);
469
+ return () => clearTimeout(timeout);
470
+ };
471
+ if (typeof requestIdleCallback != "undefined")
472
+ requestIdle = (callback) => {
473
+ let idle = -1, timeout = setTimeout(() => {
474
+ idle = requestIdleCallback(callback, { timeout: 500 /* Work.MaxPause */ - 100 /* Work.MinPause */ });
475
+ }, 100 /* Work.MinPause */);
476
+ return () => idle < 0 ? clearTimeout(timeout) : cancelIdleCallback(idle);
477
+ };
478
+ const isInputPending = typeof navigator != "undefined" && ((_a = navigator.scheduling) === null || _a === void 0 ? void 0 : _a.isInputPending)
479
+ ? () => navigator.scheduling.isInputPending() : null;
480
+ const parseWorker = /*@__PURE__*/ViewPlugin.fromClass(class ParseWorker {
481
+ constructor(view) {
482
+ this.view = view;
483
+ this.working = null;
484
+ this.workScheduled = 0;
485
+ // End of the current time chunk
486
+ this.chunkEnd = -1;
487
+ // Milliseconds of budget left for this chunk
488
+ this.chunkBudget = -1;
489
+ this.work = this.work.bind(this);
490
+ this.scheduleWork();
491
+ }
492
+ update(update) {
493
+ let cx = this.view.state.field(Language.state).context;
494
+ if (cx.updateViewport(update.view.viewport) || this.view.viewport.to > cx.treeLen)
495
+ this.scheduleWork();
496
+ if (update.docChanged || update.selectionSet) {
497
+ if (this.view.hasFocus)
498
+ this.chunkBudget += 50 /* Work.ChangeBonus */;
499
+ this.scheduleWork();
500
+ }
501
+ this.checkAsyncSchedule(cx);
502
+ }
503
+ scheduleWork() {
504
+ if (this.working)
505
+ return;
506
+ let { state } = this.view, field = state.field(Language.state);
507
+ if (field.tree != field.context.tree || !field.context.isDone(state.doc.length))
508
+ this.working = requestIdle(this.work);
509
+ }
510
+ work(deadline) {
511
+ this.working = null;
512
+ let now = Date.now();
513
+ if (this.chunkEnd < now && (this.chunkEnd < 0 || this.view.hasFocus)) { // Start a new chunk
514
+ this.chunkEnd = now + 30000 /* Work.ChunkTime */;
515
+ this.chunkBudget = 3000 /* Work.ChunkBudget */;
516
+ }
517
+ if (this.chunkBudget <= 0)
518
+ return; // No more budget
519
+ let { state, viewport: { to: vpTo } } = this.view, field = state.field(Language.state);
520
+ if (field.tree == field.context.tree && field.context.isDone(vpTo + 100000 /* Work.MaxParseAhead */))
521
+ return;
522
+ let endTime = Date.now() + Math.min(this.chunkBudget, 100 /* Work.Slice */, deadline && !isInputPending ? Math.max(25 /* Work.MinSlice */, deadline.timeRemaining() - 5) : 1e9);
523
+ let viewportFirst = field.context.treeLen < vpTo && state.doc.length > vpTo + 1000;
524
+ let done = field.context.work(() => {
525
+ return isInputPending && isInputPending() || Date.now() > endTime;
526
+ }, vpTo + (viewportFirst ? 0 : 100000 /* Work.MaxParseAhead */));
527
+ this.chunkBudget -= Date.now() - now;
528
+ if (done || this.chunkBudget <= 0) {
529
+ field.context.takeTree();
530
+ this.view.dispatch({ effects: Language.setState.of(new LanguageState(field.context)) });
531
+ }
532
+ if (this.chunkBudget > 0 && !(done && !viewportFirst))
533
+ this.scheduleWork();
534
+ this.checkAsyncSchedule(field.context);
535
+ }
536
+ checkAsyncSchedule(cx) {
537
+ if (cx.scheduleOn) {
538
+ this.workScheduled++;
539
+ cx.scheduleOn
540
+ .then(() => this.scheduleWork())
541
+ .catch(err => logException(this.view.state, err))
542
+ .then(() => this.workScheduled--);
543
+ cx.scheduleOn = null;
544
+ }
545
+ }
546
+ destroy() {
547
+ if (this.working)
548
+ this.working();
549
+ }
550
+ isWorking() {
551
+ return !!(this.working || this.workScheduled > 0);
552
+ }
553
+ }, {
554
+ eventHandlers: { focus() { this.scheduleWork(); } }
555
+ });
556
+ /**
557
+ The facet used to associate a language with an editor state. Used
558
+ by `Language` object's `extension` property (so you don't need to
559
+ manually wrap your languages in this). Can be used to access the
560
+ current language on a state.
561
+ */
562
+ const language = /*@__PURE__*/Facet.define({
563
+ combine(languages) { return languages.length ? languages[0] : null; },
564
+ enables: language => [
565
+ Language.state,
566
+ parseWorker,
567
+ EditorView.contentAttributes.compute([language], state => {
568
+ let lang = state.facet(language);
569
+ return lang && lang.name ? { "data-language": lang.name } : {};
570
+ })
571
+ ]
572
+ });
573
+
574
+ /**
575
+ Facet that defines a way to provide a function that computes the
576
+ appropriate indentation depth, as a column number (see
577
+ [`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)), at the start of a given
578
+ line. A return value of `null` indicates no indentation can be
579
+ determined, and the line should inherit the indentation of the one
580
+ above it. A return value of `undefined` defers to the next indent
581
+ service.
582
+ */
583
+ const indentService = /*@__PURE__*/Facet.define();
584
+ /**
585
+ Facet for overriding the unit by which indentation happens. Should
586
+ be a string consisting either entirely of the same whitespace
587
+ character. When not set, this defaults to 2 spaces.
588
+ */
589
+ const indentUnit = /*@__PURE__*/Facet.define({
590
+ combine: values => {
591
+ if (!values.length)
592
+ return " ";
593
+ let unit = values[0];
594
+ if (!unit || /\S/.test(unit) || Array.from(unit).some(e => e != unit[0]))
595
+ throw new Error("Invalid indent unit: " + JSON.stringify(values[0]));
596
+ return unit;
597
+ }
598
+ });
599
+ /**
600
+ Return the _column width_ of an indent unit in the state.
601
+ Determined by the [`indentUnit`](https://codemirror.net/6/docs/ref/#language.indentUnit)
602
+ facet, and [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) when that
603
+ contains tabs.
604
+ */
605
+ function getIndentUnit(state) {
606
+ let unit = state.facet(indentUnit);
607
+ return unit.charCodeAt(0) == 9 ? state.tabSize * unit.length : unit.length;
608
+ }
609
+ /**
610
+ Create an indentation string that covers columns 0 to `cols`.
611
+ Will use tabs for as much of the columns as possible when the
612
+ [`indentUnit`](https://codemirror.net/6/docs/ref/#language.indentUnit) facet contains
613
+ tabs.
614
+ */
615
+ function indentString(state, cols) {
616
+ let result = "", ts = state.tabSize, ch = state.facet(indentUnit)[0];
617
+ if (ch == "\t") {
618
+ while (cols >= ts) {
619
+ result += "\t";
620
+ cols -= ts;
621
+ }
622
+ ch = " ";
623
+ }
624
+ for (let i = 0; i < cols; i++)
625
+ result += ch;
626
+ return result;
627
+ }
628
+ /**
629
+ Get the indentation, as a column number, at the given position.
630
+ Will first consult any [indent services](https://codemirror.net/6/docs/ref/#language.indentService)
631
+ that are registered, and if none of those return an indentation,
632
+ this will check the syntax tree for the [indent node
633
+ prop](https://codemirror.net/6/docs/ref/#language.indentNodeProp) and use that if found. Returns a
634
+ number when an indentation could be determined, and null
635
+ otherwise.
636
+ */
637
+ function getIndentation(context, pos) {
638
+ if (context instanceof EditorState)
639
+ context = new IndentContext(context);
640
+ for (let service of context.state.facet(indentService)) {
641
+ let result = service(context, pos);
642
+ if (result !== undefined)
643
+ return result;
644
+ }
645
+ let tree = syntaxTree(context.state);
646
+ return tree.length >= pos ? syntaxIndentation(context, tree, pos) : null;
647
+ }
648
+ /**
649
+ Indentation contexts are used when calling [indentation
650
+ services](https://codemirror.net/6/docs/ref/#language.indentService). They provide helper utilities
651
+ useful in indentation logic, and can selectively override the
652
+ indentation reported for some lines.
653
+ */
654
+ class IndentContext {
655
+ /**
656
+ Create an indent context.
657
+ */
658
+ constructor(
659
+ /**
660
+ The editor state.
661
+ */
662
+ state,
663
+ /**
664
+ @internal
665
+ */
666
+ options = {}) {
667
+ this.state = state;
668
+ this.options = options;
669
+ this.unit = getIndentUnit(state);
670
+ }
671
+ /**
672
+ Get a description of the line at the given position, taking
673
+ [simulated line
674
+ breaks](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
675
+ into account. If there is such a break at `pos`, the `bias`
676
+ argument determines whether the part of the line line before or
677
+ after the break is used.
678
+ */
679
+ lineAt(pos, bias = 1) {
680
+ let line = this.state.doc.lineAt(pos);
681
+ let { simulateBreak, simulateDoubleBreak } = this.options;
682
+ if (simulateBreak != null && simulateBreak >= line.from && simulateBreak <= line.to) {
683
+ if (simulateDoubleBreak && simulateBreak == pos)
684
+ return { text: "", from: pos };
685
+ else if (bias < 0 ? simulateBreak < pos : simulateBreak <= pos)
686
+ return { text: line.text.slice(simulateBreak - line.from), from: simulateBreak };
687
+ else
688
+ return { text: line.text.slice(0, simulateBreak - line.from), from: line.from };
689
+ }
690
+ return line;
691
+ }
692
+ /**
693
+ Get the text directly after `pos`, either the entire line
694
+ or the next 100 characters, whichever is shorter.
695
+ */
696
+ textAfterPos(pos, bias = 1) {
697
+ if (this.options.simulateDoubleBreak && pos == this.options.simulateBreak)
698
+ return "";
699
+ let { text, from } = this.lineAt(pos, bias);
700
+ return text.slice(pos - from, Math.min(text.length, pos + 100 - from));
701
+ }
702
+ /**
703
+ Find the column for the given position.
704
+ */
705
+ column(pos, bias = 1) {
706
+ let { text, from } = this.lineAt(pos, bias);
707
+ let result = this.countColumn(text, pos - from);
708
+ let override = this.options.overrideIndentation ? this.options.overrideIndentation(from) : -1;
709
+ if (override > -1)
710
+ result += override - this.countColumn(text, text.search(/\S|$/));
711
+ return result;
712
+ }
713
+ /**
714
+ Find the column position (taking tabs into account) of the given
715
+ position in the given string.
716
+ */
717
+ countColumn(line, pos = line.length) {
718
+ return countColumn(line, this.state.tabSize, pos);
719
+ }
720
+ /**
721
+ Find the indentation column of the line at the given point.
722
+ */
723
+ lineIndent(pos, bias = 1) {
724
+ let { text, from } = this.lineAt(pos, bias);
725
+ let override = this.options.overrideIndentation;
726
+ if (override) {
727
+ let overriden = override(from);
728
+ if (overriden > -1)
729
+ return overriden;
730
+ }
731
+ return this.countColumn(text, text.search(/\S|$/));
732
+ }
733
+ /**
734
+ Returns the [simulated line
735
+ break](https://codemirror.net/6/docs/ref/#language.IndentContext.constructor^options.simulateBreak)
736
+ for this context, if any.
737
+ */
738
+ get simulatedBreak() {
739
+ return this.options.simulateBreak || null;
740
+ }
741
+ }
742
+ /**
743
+ A syntax tree node prop used to associate indentation strategies
744
+ with node types. Such a strategy is a function from an indentation
745
+ context to a column number (see also
746
+ [`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)) or null, where null
747
+ indicates that no definitive indentation can be determined.
748
+ */
749
+ const indentNodeProp = /*@__PURE__*/new NodeProp();
750
+ // Compute the indentation for a given position from the syntax tree.
751
+ function syntaxIndentation(cx, ast, pos) {
752
+ let stack = ast.resolveStack(pos);
753
+ let inner = stack.node.enterUnfinishedNodesBefore(pos);
754
+ if (inner != stack.node) {
755
+ let add = [];
756
+ for (let cur = inner; cur != stack.node; cur = cur.parent)
757
+ add.push(cur);
758
+ for (let i = add.length - 1; i >= 0; i--)
759
+ stack = { node: add[i], next: stack };
760
+ }
761
+ return indentFor(stack, cx, pos);
762
+ }
763
+ function indentFor(stack, cx, pos) {
764
+ for (let cur = stack; cur; cur = cur.next) {
765
+ let strategy = indentStrategy(cur.node);
766
+ if (strategy)
767
+ return strategy(TreeIndentContext.create(cx, pos, cur));
768
+ }
769
+ return 0;
770
+ }
771
+ function ignoreClosed(cx) {
772
+ return cx.pos == cx.options.simulateBreak && cx.options.simulateDoubleBreak;
773
+ }
774
+ function indentStrategy(tree) {
775
+ let strategy = tree.type.prop(indentNodeProp);
776
+ if (strategy)
777
+ return strategy;
778
+ let first = tree.firstChild, close;
779
+ if (first && (close = first.type.prop(NodeProp.closedBy))) {
780
+ let last = tree.lastChild, closed = last && close.indexOf(last.name) > -1;
781
+ return cx => delimitedStrategy(cx, true, 1, undefined, closed && !ignoreClosed(cx) ? last.from : undefined);
782
+ }
783
+ return tree.parent == null ? topIndent : null;
784
+ }
785
+ function topIndent() { return 0; }
786
+ /**
787
+ Objects of this type provide context information and helper
788
+ methods to indentation functions registered on syntax nodes.
789
+ */
790
+ class TreeIndentContext extends IndentContext {
791
+ constructor(base,
792
+ /**
793
+ The position at which indentation is being computed.
794
+ */
795
+ pos,
796
+ /**
797
+ @internal
798
+ */
799
+ context) {
800
+ super(base.state, base.options);
801
+ this.base = base;
802
+ this.pos = pos;
803
+ this.context = context;
804
+ }
805
+ /**
806
+ The syntax tree node to which the indentation strategy
807
+ applies.
808
+ */
809
+ get node() { return this.context.node; }
810
+ /**
811
+ @internal
812
+ */
813
+ static create(base, pos, context) {
814
+ return new TreeIndentContext(base, pos, context);
815
+ }
816
+ /**
817
+ Get the text directly after `this.pos`, either the entire line
818
+ or the next 100 characters, whichever is shorter.
819
+ */
820
+ get textAfter() {
821
+ return this.textAfterPos(this.pos);
822
+ }
823
+ /**
824
+ Get the indentation at the reference line for `this.node`, which
825
+ is the line on which it starts, unless there is a node that is
826
+ _not_ a parent of this node covering the start of that line. If
827
+ so, the line at the start of that node is tried, again skipping
828
+ on if it is covered by another such node.
829
+ */
830
+ get baseIndent() {
831
+ return this.baseIndentFor(this.node);
832
+ }
833
+ /**
834
+ Get the indentation for the reference line of the given node
835
+ (see [`baseIndent`](https://codemirror.net/6/docs/ref/#language.TreeIndentContext.baseIndent)).
836
+ */
837
+ baseIndentFor(node) {
838
+ let line = this.state.doc.lineAt(node.from);
839
+ // Skip line starts that are covered by a sibling (or cousin, etc)
840
+ for (;;) {
841
+ let atBreak = node.resolve(line.from);
842
+ while (atBreak.parent && atBreak.parent.from == atBreak.from)
843
+ atBreak = atBreak.parent;
844
+ if (isParent(atBreak, node))
845
+ break;
846
+ line = this.state.doc.lineAt(atBreak.from);
847
+ }
848
+ return this.lineIndent(line.from);
849
+ }
850
+ /**
851
+ Continue looking for indentations in the node's parent nodes,
852
+ and return the result of that.
853
+ */
854
+ continue() {
855
+ return indentFor(this.context.next, this.base, this.pos);
856
+ }
857
+ }
858
+ function isParent(parent, of) {
859
+ for (let cur = of; cur; cur = cur.parent)
860
+ if (parent == cur)
861
+ return true;
862
+ return false;
863
+ }
864
+ // Check whether a delimited node is aligned (meaning there are
865
+ // non-skipped nodes on the same line as the opening delimiter). And
866
+ // if so, return the opening token.
867
+ function bracketedAligned(context) {
868
+ let tree = context.node;
869
+ let openToken = tree.childAfter(tree.from), last = tree.lastChild;
870
+ if (!openToken)
871
+ return null;
872
+ let sim = context.options.simulateBreak;
873
+ let openLine = context.state.doc.lineAt(openToken.from);
874
+ let lineEnd = sim == null || sim <= openLine.from ? openLine.to : Math.min(openLine.to, sim);
875
+ for (let pos = openToken.to;;) {
876
+ let next = tree.childAfter(pos);
877
+ if (!next || next == last)
878
+ return null;
879
+ if (!next.type.isSkipped)
880
+ return next.from < lineEnd ? openToken : null;
881
+ pos = next.to;
882
+ }
883
+ }
884
+ function delimitedStrategy(context, align, units, closing, closedAt) {
885
+ let after = context.textAfter, space = after.match(/^\s*/)[0].length;
886
+ let closed = closing && after.slice(space, space + closing.length) == closing || closedAt == context.pos + space;
887
+ let aligned = align ? bracketedAligned(context) : null;
888
+ if (aligned)
889
+ return closed ? context.column(aligned.from) : context.column(aligned.to);
890
+ return context.baseIndent + (closed ? 0 : context.unit * units);
891
+ }
892
+ const DontIndentBeyond = 200;
893
+ /**
894
+ Enables reindentation on input. When a language defines an
895
+ `indentOnInput` field in its [language
896
+ data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt), which must hold a regular
897
+ expression, the line at the cursor will be reindented whenever new
898
+ text is typed and the input from the start of the line up to the
899
+ cursor matches that regexp.
900
+
901
+ To avoid unneccesary reindents, it is recommended to start the
902
+ regexp with `^` (usually followed by `\s*`), and end it with `$`.
903
+ For example, `/^\s*\}$/` will reindent when a closing brace is
904
+ added at the start of a line.
905
+ */
906
+ function indentOnInput() {
907
+ return EditorState.transactionFilter.of(tr => {
908
+ if (!tr.docChanged || !tr.isUserEvent("input.type") && !tr.isUserEvent("input.complete"))
909
+ return tr;
910
+ let rules = tr.startState.languageDataAt("indentOnInput", tr.startState.selection.main.head);
911
+ if (!rules.length)
912
+ return tr;
913
+ let doc = tr.newDoc, { head } = tr.newSelection.main, line = doc.lineAt(head);
914
+ if (head > line.from + DontIndentBeyond)
915
+ return tr;
916
+ let lineStart = doc.sliceString(line.from, head);
917
+ if (!rules.some(r => r.test(lineStart)))
918
+ return tr;
919
+ let { state } = tr, last = -1, changes = [];
920
+ for (let { head } of state.selection.ranges) {
921
+ let line = state.doc.lineAt(head);
922
+ if (line.from == last)
923
+ continue;
924
+ last = line.from;
925
+ let indent = getIndentation(state, line.from);
926
+ if (indent == null)
927
+ continue;
928
+ let cur = /^\s*/.exec(line.text)[0];
929
+ let norm = indentString(state, indent);
930
+ if (cur != norm)
931
+ changes.push({ from: line.from, to: line.from + cur.length, insert: norm });
932
+ }
933
+ return changes.length ? [tr, { changes, sequential: true }] : tr;
934
+ });
935
+ }
936
+
937
+ /**
938
+ A facet that registers a code folding service. When called with
939
+ the extent of a line, such a function should return a foldable
940
+ range that starts on that line (but continues beyond it), if one
941
+ can be found.
942
+ */
943
+ const foldService = /*@__PURE__*/Facet.define();
944
+ /**
945
+ This node prop is used to associate folding information with
946
+ syntax node types. Given a syntax node, it should check whether
947
+ that tree is foldable and return the range that can be collapsed
948
+ when it is.
949
+ */
950
+ const foldNodeProp = /*@__PURE__*/new NodeProp();
951
+ function syntaxFolding(state, start, end) {
952
+ let tree = syntaxTree(state);
953
+ if (tree.length < end)
954
+ return null;
955
+ let stack = tree.resolveStack(end, 1);
956
+ let found = null;
957
+ for (let iter = stack; iter; iter = iter.next) {
958
+ let cur = iter.node;
959
+ if (cur.to <= end || cur.from > end)
960
+ continue;
961
+ if (found && cur.from < start)
962
+ break;
963
+ let prop = cur.type.prop(foldNodeProp);
964
+ if (prop && (cur.to < tree.length - 50 || tree.length == state.doc.length || !isUnfinished(cur))) {
965
+ let value = prop(cur, state);
966
+ if (value && value.from <= end && value.from >= start && value.to > end)
967
+ found = value;
968
+ }
969
+ }
970
+ return found;
971
+ }
972
+ function isUnfinished(node) {
973
+ let ch = node.lastChild;
974
+ return ch && ch.to == node.to && ch.type.isError;
975
+ }
976
+ /**
977
+ Check whether the given line is foldable. First asks any fold
978
+ services registered through
979
+ [`foldService`](https://codemirror.net/6/docs/ref/#language.foldService), and if none of them return
980
+ a result, tries to query the [fold node
981
+ prop](https://codemirror.net/6/docs/ref/#language.foldNodeProp) of syntax nodes that cover the end
982
+ of the line.
983
+ */
984
+ function foldable(state, lineStart, lineEnd) {
985
+ for (let service of state.facet(foldService)) {
986
+ let result = service(state, lineStart, lineEnd);
987
+ if (result)
988
+ return result;
989
+ }
990
+ return syntaxFolding(state, lineStart, lineEnd);
991
+ }
992
+ function mapRange(range, mapping) {
993
+ let from = mapping.mapPos(range.from, 1), to = mapping.mapPos(range.to, -1);
994
+ return from >= to ? undefined : { from, to };
995
+ }
996
+ /**
997
+ State effect that can be attached to a transaction to fold the
998
+ given range. (You probably only need this in exceptional
999
+ circumstances—usually you'll just want to let
1000
+ [`foldCode`](https://codemirror.net/6/docs/ref/#language.foldCode) and the [fold
1001
+ gutter](https://codemirror.net/6/docs/ref/#language.foldGutter) create the transactions.)
1002
+ */
1003
+ const foldEffect = /*@__PURE__*/StateEffect.define({ map: mapRange });
1004
+ /**
1005
+ State effect that unfolds the given range (if it was folded).
1006
+ */
1007
+ const unfoldEffect = /*@__PURE__*/StateEffect.define({ map: mapRange });
1008
+ function selectedLines(view) {
1009
+ let lines = [];
1010
+ for (let { head } of view.state.selection.ranges) {
1011
+ if (lines.some(l => l.from <= head && l.to >= head))
1012
+ continue;
1013
+ lines.push(view.lineBlockAt(head));
1014
+ }
1015
+ return lines;
1016
+ }
1017
+ /**
1018
+ The state field that stores the folded ranges (as a [decoration
1019
+ set](https://codemirror.net/6/docs/ref/#view.DecorationSet)). Can be passed to
1020
+ [`EditorState.toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) and
1021
+ [`fromJSON`](https://codemirror.net/6/docs/ref/#state.EditorState^fromJSON) to serialize the fold
1022
+ state.
1023
+ */
1024
+ const foldState = /*@__PURE__*/StateField.define({
1025
+ create() {
1026
+ return Decoration.none;
1027
+ },
1028
+ update(folded, tr) {
1029
+ folded = folded.map(tr.changes);
1030
+ for (let e of tr.effects) {
1031
+ if (e.is(foldEffect) && !foldExists(folded, e.value.from, e.value.to)) {
1032
+ let { preparePlaceholder } = tr.state.facet(foldConfig);
1033
+ let widget = !preparePlaceholder ? foldWidget :
1034
+ Decoration.replace({ widget: new PreparedFoldWidget(preparePlaceholder(tr.state, e.value)) });
1035
+ folded = folded.update({ add: [widget.range(e.value.from, e.value.to)] });
1036
+ }
1037
+ else if (e.is(unfoldEffect)) {
1038
+ folded = folded.update({ filter: (from, to) => e.value.from != from || e.value.to != to,
1039
+ filterFrom: e.value.from, filterTo: e.value.to });
1040
+ }
1041
+ }
1042
+ // Clear folded ranges that cover the selection head
1043
+ if (tr.selection) {
1044
+ let onSelection = false, { head } = tr.selection.main;
1045
+ folded.between(head, head, (a, b) => { if (a < head && b > head)
1046
+ onSelection = true; });
1047
+ if (onSelection)
1048
+ folded = folded.update({
1049
+ filterFrom: head,
1050
+ filterTo: head,
1051
+ filter: (a, b) => b <= head || a >= head
1052
+ });
1053
+ }
1054
+ return folded;
1055
+ },
1056
+ provide: f => EditorView.decorations.from(f),
1057
+ toJSON(folded, state) {
1058
+ let ranges = [];
1059
+ folded.between(0, state.doc.length, (from, to) => { ranges.push(from, to); });
1060
+ return ranges;
1061
+ },
1062
+ fromJSON(value) {
1063
+ if (!Array.isArray(value) || value.length % 2)
1064
+ throw new RangeError("Invalid JSON for fold state");
1065
+ let ranges = [];
1066
+ for (let i = 0; i < value.length;) {
1067
+ let from = value[i++], to = value[i++];
1068
+ if (typeof from != "number" || typeof to != "number")
1069
+ throw new RangeError("Invalid JSON for fold state");
1070
+ ranges.push(foldWidget.range(from, to));
1071
+ }
1072
+ return Decoration.set(ranges, true);
1073
+ }
1074
+ });
1075
+ function findFold(state, from, to) {
1076
+ var _a;
1077
+ let found = null;
1078
+ (_a = state.field(foldState, false)) === null || _a === void 0 ? void 0 : _a.between(from, to, (from, to) => {
1079
+ if (!found || found.from > from)
1080
+ found = { from, to };
1081
+ });
1082
+ return found;
1083
+ }
1084
+ function foldExists(folded, from, to) {
1085
+ let found = false;
1086
+ folded.between(from, from, (a, b) => { if (a == from && b == to)
1087
+ found = true; });
1088
+ return found;
1089
+ }
1090
+ function maybeEnable(state, other) {
1091
+ return state.field(foldState, false) ? other : other.concat(StateEffect.appendConfig.of(codeFolding()));
1092
+ }
1093
+ /**
1094
+ Fold the lines that are selected, if possible.
1095
+ */
1096
+ const foldCode = view => {
1097
+ for (let line of selectedLines(view)) {
1098
+ let range = foldable(view.state, line.from, line.to);
1099
+ if (range) {
1100
+ view.dispatch({ effects: maybeEnable(view.state, [foldEffect.of(range), announceFold(view, range)]) });
1101
+ return true;
1102
+ }
1103
+ }
1104
+ return false;
1105
+ };
1106
+ /**
1107
+ Unfold folded ranges on selected lines.
1108
+ */
1109
+ const unfoldCode = view => {
1110
+ if (!view.state.field(foldState, false))
1111
+ return false;
1112
+ let effects = [];
1113
+ for (let line of selectedLines(view)) {
1114
+ let folded = findFold(view.state, line.from, line.to);
1115
+ if (folded)
1116
+ effects.push(unfoldEffect.of(folded), announceFold(view, folded, false));
1117
+ }
1118
+ if (effects.length)
1119
+ view.dispatch({ effects });
1120
+ return effects.length > 0;
1121
+ };
1122
+ function announceFold(view, range, fold = true) {
1123
+ let lineFrom = view.state.doc.lineAt(range.from).number, lineTo = view.state.doc.lineAt(range.to).number;
1124
+ return EditorView.announce.of(`${view.state.phrase(fold ? "Folded lines" : "Unfolded lines")} ${lineFrom} ${view.state.phrase("to")} ${lineTo}.`);
1125
+ }
1126
+ /**
1127
+ Fold all top-level foldable ranges. Note that, in most cases,
1128
+ folding information will depend on the [syntax
1129
+ tree](https://codemirror.net/6/docs/ref/#language.syntaxTree), and folding everything may not work
1130
+ reliably when the document hasn't been fully parsed (either
1131
+ because the editor state was only just initialized, or because the
1132
+ document is so big that the parser decided not to parse it
1133
+ entirely).
1134
+ */
1135
+ const foldAll = view => {
1136
+ let { state } = view, effects = [];
1137
+ for (let pos = 0; pos < state.doc.length;) {
1138
+ let line = view.lineBlockAt(pos), range = foldable(state, line.from, line.to);
1139
+ if (range)
1140
+ effects.push(foldEffect.of(range));
1141
+ pos = (range ? view.lineBlockAt(range.to) : line).to + 1;
1142
+ }
1143
+ if (effects.length)
1144
+ view.dispatch({ effects: maybeEnable(view.state, effects) });
1145
+ return !!effects.length;
1146
+ };
1147
+ /**
1148
+ Unfold all folded code.
1149
+ */
1150
+ const unfoldAll = view => {
1151
+ let field = view.state.field(foldState, false);
1152
+ if (!field || !field.size)
1153
+ return false;
1154
+ let effects = [];
1155
+ field.between(0, view.state.doc.length, (from, to) => { effects.push(unfoldEffect.of({ from, to })); });
1156
+ view.dispatch({ effects });
1157
+ return true;
1158
+ };
1159
+ /**
1160
+ Default fold-related key bindings.
1161
+
1162
+ - Ctrl-Shift-[ (Cmd-Alt-[ on macOS): [`foldCode`](https://codemirror.net/6/docs/ref/#language.foldCode).
1163
+ - Ctrl-Shift-] (Cmd-Alt-] on macOS): [`unfoldCode`](https://codemirror.net/6/docs/ref/#language.unfoldCode).
1164
+ - Ctrl-Alt-[: [`foldAll`](https://codemirror.net/6/docs/ref/#language.foldAll).
1165
+ - Ctrl-Alt-]: [`unfoldAll`](https://codemirror.net/6/docs/ref/#language.unfoldAll).
1166
+ */
1167
+ const foldKeymap = [
1168
+ { key: "Ctrl-Shift-[", mac: "Cmd-Alt-[", run: foldCode },
1169
+ { key: "Ctrl-Shift-]", mac: "Cmd-Alt-]", run: unfoldCode },
1170
+ { key: "Ctrl-Alt-[", run: foldAll },
1171
+ { key: "Ctrl-Alt-]", run: unfoldAll }
1172
+ ];
1173
+ const defaultConfig = {
1174
+ placeholderDOM: null,
1175
+ preparePlaceholder: null,
1176
+ placeholderText: "…"
1177
+ };
1178
+ const foldConfig = /*@__PURE__*/Facet.define({
1179
+ combine(values) { return combineConfig(values, defaultConfig); }
1180
+ });
1181
+ /**
1182
+ Create an extension that configures code folding.
1183
+ */
1184
+ function codeFolding(config) {
1185
+ let result = [foldState, baseTheme$1];
1186
+ if (config)
1187
+ result.push(foldConfig.of(config));
1188
+ return result;
1189
+ }
1190
+ function widgetToDOM(view, prepared) {
1191
+ let { state } = view, conf = state.facet(foldConfig);
1192
+ let onclick = (event) => {
1193
+ let line = view.lineBlockAt(view.posAtDOM(event.target));
1194
+ let folded = findFold(view.state, line.from, line.to);
1195
+ if (folded)
1196
+ view.dispatch({ effects: unfoldEffect.of(folded) });
1197
+ event.preventDefault();
1198
+ };
1199
+ if (conf.placeholderDOM)
1200
+ return conf.placeholderDOM(view, onclick, prepared);
1201
+ let element = document.createElement("span");
1202
+ element.textContent = conf.placeholderText;
1203
+ element.setAttribute("aria-label", state.phrase("folded code"));
1204
+ element.title = state.phrase("unfold");
1205
+ element.className = "cm-foldPlaceholder";
1206
+ element.onclick = onclick;
1207
+ return element;
1208
+ }
1209
+ const foldWidget = /*@__PURE__*/Decoration.replace({ widget: /*@__PURE__*/new class extends WidgetType {
1210
+ toDOM(view) { return widgetToDOM(view, null); }
1211
+ } });
1212
+ class PreparedFoldWidget extends WidgetType {
1213
+ constructor(value) {
1214
+ super();
1215
+ this.value = value;
1216
+ }
1217
+ eq(other) { return this.value == other.value; }
1218
+ toDOM(view) { return widgetToDOM(view, this.value); }
1219
+ }
1220
+ const foldGutterDefaults = {
1221
+ openText: "⌄",
1222
+ closedText: "›",
1223
+ markerDOM: null,
1224
+ domEventHandlers: {},
1225
+ foldingChanged: () => false
1226
+ };
1227
+ class FoldMarker extends GutterMarker {
1228
+ constructor(config, open) {
1229
+ super();
1230
+ this.config = config;
1231
+ this.open = open;
1232
+ }
1233
+ eq(other) { return this.config == other.config && this.open == other.open; }
1234
+ toDOM(view) {
1235
+ if (this.config.markerDOM)
1236
+ return this.config.markerDOM(this.open);
1237
+ let span = document.createElement("span");
1238
+ span.textContent = this.open ? this.config.openText : this.config.closedText;
1239
+ span.title = view.state.phrase(this.open ? "Fold line" : "Unfold line");
1240
+ return span;
1241
+ }
1242
+ }
1243
+ /**
1244
+ Create an extension that registers a fold gutter, which shows a
1245
+ fold status indicator before foldable lines (which can be clicked
1246
+ to fold or unfold the line).
1247
+ */
1248
+ function foldGutter(config = {}) {
1249
+ let fullConfig = Object.assign(Object.assign({}, foldGutterDefaults), config);
1250
+ let canFold = new FoldMarker(fullConfig, true), canUnfold = new FoldMarker(fullConfig, false);
1251
+ let markers = ViewPlugin.fromClass(class {
1252
+ constructor(view) {
1253
+ this.from = view.viewport.from;
1254
+ this.markers = this.buildMarkers(view);
1255
+ }
1256
+ update(update) {
1257
+ if (update.docChanged || update.viewportChanged ||
1258
+ update.startState.facet(language) != update.state.facet(language) ||
1259
+ update.startState.field(foldState, false) != update.state.field(foldState, false) ||
1260
+ syntaxTree(update.startState) != syntaxTree(update.state) ||
1261
+ fullConfig.foldingChanged(update))
1262
+ this.markers = this.buildMarkers(update.view);
1263
+ }
1264
+ buildMarkers(view) {
1265
+ let builder = new RangeSetBuilder();
1266
+ for (let line of view.viewportLineBlocks) {
1267
+ let mark = findFold(view.state, line.from, line.to) ? canUnfold
1268
+ : foldable(view.state, line.from, line.to) ? canFold : null;
1269
+ if (mark)
1270
+ builder.add(line.from, line.from, mark);
1271
+ }
1272
+ return builder.finish();
1273
+ }
1274
+ });
1275
+ let { domEventHandlers } = fullConfig;
1276
+ return [
1277
+ markers,
1278
+ gutter({
1279
+ class: "cm-foldGutter",
1280
+ markers(view) { var _a; return ((_a = view.plugin(markers)) === null || _a === void 0 ? void 0 : _a.markers) || RangeSet.empty; },
1281
+ initialSpacer() {
1282
+ return new FoldMarker(fullConfig, false);
1283
+ },
1284
+ domEventHandlers: Object.assign(Object.assign({}, domEventHandlers), { click: (view, line, event) => {
1285
+ if (domEventHandlers.click && domEventHandlers.click(view, line, event))
1286
+ return true;
1287
+ let folded = findFold(view.state, line.from, line.to);
1288
+ if (folded) {
1289
+ view.dispatch({ effects: unfoldEffect.of(folded) });
1290
+ return true;
1291
+ }
1292
+ let range = foldable(view.state, line.from, line.to);
1293
+ if (range) {
1294
+ view.dispatch({ effects: foldEffect.of(range) });
1295
+ return true;
1296
+ }
1297
+ return false;
1298
+ } })
1299
+ }),
1300
+ codeFolding()
1301
+ ];
1302
+ }
1303
+ const baseTheme$1 = /*@__PURE__*/EditorView.baseTheme({
1304
+ ".cm-foldPlaceholder": {
1305
+ backgroundColor: "#eee",
1306
+ border: "1px solid #ddd",
1307
+ color: "#888",
1308
+ borderRadius: ".2em",
1309
+ margin: "0 1px",
1310
+ padding: "0 1px",
1311
+ cursor: "pointer"
1312
+ },
1313
+ ".cm-foldGutter span": {
1314
+ padding: "0 1px",
1315
+ cursor: "pointer"
1316
+ }
1317
+ });
1318
+
1319
+ /**
1320
+ A highlight style associates CSS styles with higlighting
1321
+ [tags](https://lezer.codemirror.net/docs/ref#highlight.Tag).
1322
+ */
1323
+ class HighlightStyle {
1324
+ constructor(
1325
+ /**
1326
+ The tag styles used to create this highlight style.
1327
+ */
1328
+ specs, options) {
1329
+ this.specs = specs;
1330
+ let modSpec;
1331
+ function def(spec) {
1332
+ let cls = StyleModule.newName();
1333
+ (modSpec || (modSpec = Object.create(null)))["." + cls] = spec;
1334
+ return cls;
1335
+ }
1336
+ const all = typeof options.all == "string" ? options.all : options.all ? def(options.all) : undefined;
1337
+ const scopeOpt = options.scope;
1338
+ this.scope = scopeOpt instanceof Language ? (type) => type.prop(languageDataProp) == scopeOpt.data
1339
+ : scopeOpt ? (type) => type == scopeOpt : undefined;
1340
+ this.style = tagHighlighter(specs.map(style => ({
1341
+ tag: style.tag,
1342
+ class: style.class || def(Object.assign({}, style, { tag: null }))
1343
+ })), {
1344
+ all,
1345
+ }).style;
1346
+ this.module = modSpec ? new StyleModule(modSpec) : null;
1347
+ this.themeType = options.themeType;
1348
+ }
1349
+ /**
1350
+ Create a highlighter style that associates the given styles to
1351
+ the given tags. The specs must be objects that hold a style tag
1352
+ or array of tags in their `tag` property, and either a single
1353
+ `class` property providing a static CSS class (for highlighter
1354
+ that rely on external styling), or a
1355
+ [`style-mod`](https://github.com/marijnh/style-mod#documentation)-style
1356
+ set of CSS properties (which define the styling for those tags).
1357
+
1358
+ The CSS rules created for a highlighter will be emitted in the
1359
+ order of the spec's properties. That means that for elements that
1360
+ have multiple tags associated with them, styles defined further
1361
+ down in the list will have a higher CSS precedence than styles
1362
+ defined earlier.
1363
+ */
1364
+ static define(specs, options) {
1365
+ return new HighlightStyle(specs, options || {});
1366
+ }
1367
+ }
1368
+ const highlighterFacet = /*@__PURE__*/Facet.define();
1369
+ const fallbackHighlighter = /*@__PURE__*/Facet.define({
1370
+ combine(values) { return values.length ? [values[0]] : null; }
1371
+ });
1372
+ function getHighlighters(state) {
1373
+ let main = state.facet(highlighterFacet);
1374
+ return main.length ? main : state.facet(fallbackHighlighter);
1375
+ }
1376
+ /**
1377
+ Wrap a highlighter in an editor extension that uses it to apply
1378
+ syntax highlighting to the editor content.
1379
+
1380
+ When multiple (non-fallback) styles are provided, the styling
1381
+ applied is the union of the classes they emit.
1382
+ */
1383
+ function syntaxHighlighting(highlighter, options) {
1384
+ let ext = [treeHighlighter], themeType;
1385
+ if (highlighter instanceof HighlightStyle) {
1386
+ if (highlighter.module)
1387
+ ext.push(EditorView.styleModule.of(highlighter.module));
1388
+ themeType = highlighter.themeType;
1389
+ }
1390
+ if (options === null || options === void 0 ? void 0 : options.fallback)
1391
+ ext.push(fallbackHighlighter.of(highlighter));
1392
+ else if (themeType)
1393
+ ext.push(highlighterFacet.computeN([EditorView.darkTheme], state => {
1394
+ return state.facet(EditorView.darkTheme) == (themeType == "dark") ? [highlighter] : [];
1395
+ }));
1396
+ else
1397
+ ext.push(highlighterFacet.of(highlighter));
1398
+ return ext;
1399
+ }
1400
+ class TreeHighlighter {
1401
+ constructor(view) {
1402
+ this.markCache = Object.create(null);
1403
+ this.tree = syntaxTree(view.state);
1404
+ this.decorations = this.buildDeco(view, getHighlighters(view.state));
1405
+ this.decoratedTo = view.viewport.to;
1406
+ }
1407
+ update(update) {
1408
+ let tree = syntaxTree(update.state), highlighters = getHighlighters(update.state);
1409
+ let styleChange = highlighters != getHighlighters(update.startState);
1410
+ let { viewport } = update.view, decoratedToMapped = update.changes.mapPos(this.decoratedTo, 1);
1411
+ if (tree.length < viewport.to && !styleChange && tree.type == this.tree.type && decoratedToMapped >= viewport.to) {
1412
+ this.decorations = this.decorations.map(update.changes);
1413
+ this.decoratedTo = decoratedToMapped;
1414
+ }
1415
+ else if (tree != this.tree || update.viewportChanged || styleChange) {
1416
+ this.tree = tree;
1417
+ this.decorations = this.buildDeco(update.view, highlighters);
1418
+ this.decoratedTo = viewport.to;
1419
+ }
1420
+ }
1421
+ buildDeco(view, highlighters) {
1422
+ if (!highlighters || !this.tree.length)
1423
+ return Decoration.none;
1424
+ let builder = new RangeSetBuilder();
1425
+ for (let { from, to } of view.visibleRanges) {
1426
+ highlightTree(this.tree, highlighters, (from, to, style) => {
1427
+ builder.add(from, to, this.markCache[style] || (this.markCache[style] = Decoration.mark({ class: style })));
1428
+ }, from, to);
1429
+ }
1430
+ return builder.finish();
1431
+ }
1432
+ }
1433
+ const treeHighlighter = /*@__PURE__*/Prec.high(/*@__PURE__*/ViewPlugin.fromClass(TreeHighlighter, {
1434
+ decorations: v => v.decorations
1435
+ }));
1436
+ /**
1437
+ A default highlight style (works well with light themes).
1438
+ */
1439
+ const defaultHighlightStyle = /*@__PURE__*/HighlightStyle.define([
1440
+ { tag: tags.meta,
1441
+ color: "#404740" },
1442
+ { tag: tags.link,
1443
+ textDecoration: "underline" },
1444
+ { tag: tags.heading,
1445
+ textDecoration: "underline",
1446
+ fontWeight: "bold" },
1447
+ { tag: tags.emphasis,
1448
+ fontStyle: "italic" },
1449
+ { tag: tags.strong,
1450
+ fontWeight: "bold" },
1451
+ { tag: tags.strikethrough,
1452
+ textDecoration: "line-through" },
1453
+ { tag: tags.keyword,
1454
+ color: "#708" },
1455
+ { tag: [tags.atom, tags.bool, tags.url, tags.contentSeparator, tags.labelName],
1456
+ color: "#219" },
1457
+ { tag: [tags.literal, tags.inserted],
1458
+ color: "#164" },
1459
+ { tag: [tags.string, tags.deleted],
1460
+ color: "#a11" },
1461
+ { tag: [tags.regexp, tags.escape, /*@__PURE__*/tags.special(tags.string)],
1462
+ color: "#e40" },
1463
+ { tag: /*@__PURE__*/tags.definition(tags.variableName),
1464
+ color: "#00f" },
1465
+ { tag: /*@__PURE__*/tags.local(tags.variableName),
1466
+ color: "#30a" },
1467
+ { tag: [tags.typeName, tags.namespace],
1468
+ color: "#085" },
1469
+ { tag: tags.className,
1470
+ color: "#167" },
1471
+ { tag: [/*@__PURE__*/tags.special(tags.variableName), tags.macroName],
1472
+ color: "#256" },
1473
+ { tag: /*@__PURE__*/tags.definition(tags.propertyName),
1474
+ color: "#00c" },
1475
+ { tag: tags.comment,
1476
+ color: "#940" },
1477
+ { tag: tags.invalid,
1478
+ color: "#f00" }
1479
+ ]);
1480
+
1481
+ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
1482
+ "&.cm-focused .cm-matchingBracket": { backgroundColor: "#328c8252" },
1483
+ "&.cm-focused .cm-nonmatchingBracket": { backgroundColor: "#bb555544" }
1484
+ });
1485
+ const DefaultScanDist = 10000, DefaultBrackets = "()[]{}";
1486
+ const bracketMatchingConfig = /*@__PURE__*/Facet.define({
1487
+ combine(configs) {
1488
+ return combineConfig(configs, {
1489
+ afterCursor: true,
1490
+ brackets: DefaultBrackets,
1491
+ maxScanDistance: DefaultScanDist,
1492
+ renderMatch: defaultRenderMatch
1493
+ });
1494
+ }
1495
+ });
1496
+ const matchingMark = /*@__PURE__*/Decoration.mark({ class: "cm-matchingBracket" }), nonmatchingMark = /*@__PURE__*/Decoration.mark({ class: "cm-nonmatchingBracket" });
1497
+ function defaultRenderMatch(match) {
1498
+ let decorations = [];
1499
+ let mark = match.matched ? matchingMark : nonmatchingMark;
1500
+ decorations.push(mark.range(match.start.from, match.start.to));
1501
+ if (match.end)
1502
+ decorations.push(mark.range(match.end.from, match.end.to));
1503
+ return decorations;
1504
+ }
1505
+ const bracketMatchingState = /*@__PURE__*/StateField.define({
1506
+ create() { return Decoration.none; },
1507
+ update(deco, tr) {
1508
+ if (!tr.docChanged && !tr.selection)
1509
+ return deco;
1510
+ let decorations = [];
1511
+ let config = tr.state.facet(bracketMatchingConfig);
1512
+ for (let range of tr.state.selection.ranges) {
1513
+ if (!range.empty)
1514
+ continue;
1515
+ let match = matchBrackets(tr.state, range.head, -1, config)
1516
+ || (range.head > 0 && matchBrackets(tr.state, range.head - 1, 1, config))
1517
+ || (config.afterCursor &&
1518
+ (matchBrackets(tr.state, range.head, 1, config) ||
1519
+ (range.head < tr.state.doc.length && matchBrackets(tr.state, range.head + 1, -1, config))));
1520
+ if (match)
1521
+ decorations = decorations.concat(config.renderMatch(match, tr.state));
1522
+ }
1523
+ return Decoration.set(decorations, true);
1524
+ },
1525
+ provide: f => EditorView.decorations.from(f)
1526
+ });
1527
+ const bracketMatchingUnique = [
1528
+ bracketMatchingState,
1529
+ baseTheme
1530
+ ];
1531
+ /**
1532
+ Create an extension that enables bracket matching. Whenever the
1533
+ cursor is next to a bracket, that bracket and the one it matches
1534
+ are highlighted. Or, when no matching bracket is found, another
1535
+ highlighting style is used to indicate this.
1536
+ */
1537
+ function bracketMatching(config = {}) {
1538
+ return [bracketMatchingConfig.of(config), bracketMatchingUnique];
1539
+ }
1540
+ /**
1541
+ When larger syntax nodes, such as HTML tags, are marked as
1542
+ opening/closing, it can be a bit messy to treat the whole node as
1543
+ a matchable bracket. This node prop allows you to define, for such
1544
+ a node, a ‘handle’—the part of the node that is highlighted, and
1545
+ that the cursor must be on to activate highlighting in the first
1546
+ place.
1547
+ */
1548
+ const bracketMatchingHandle = /*@__PURE__*/new NodeProp();
1549
+ function matchingNodes(node, dir, brackets) {
1550
+ let byProp = node.prop(dir < 0 ? NodeProp.openedBy : NodeProp.closedBy);
1551
+ if (byProp)
1552
+ return byProp;
1553
+ if (node.name.length == 1) {
1554
+ let index = brackets.indexOf(node.name);
1555
+ if (index > -1 && index % 2 == (dir < 0 ? 1 : 0))
1556
+ return [brackets[index + dir]];
1557
+ }
1558
+ return null;
1559
+ }
1560
+ function findHandle(node) {
1561
+ let hasHandle = node.type.prop(bracketMatchingHandle);
1562
+ return hasHandle ? hasHandle(node.node) : node;
1563
+ }
1564
+ /**
1565
+ Find the matching bracket for the token at `pos`, scanning
1566
+ direction `dir`. Only the `brackets` and `maxScanDistance`
1567
+ properties are used from `config`, if given. Returns null if no
1568
+ bracket was found at `pos`, or a match result otherwise.
1569
+ */
1570
+ function matchBrackets(state, pos, dir, config = {}) {
1571
+ let maxScanDistance = config.maxScanDistance || DefaultScanDist, brackets = config.brackets || DefaultBrackets;
1572
+ let tree = syntaxTree(state), node = tree.resolveInner(pos, dir);
1573
+ for (let cur = node; cur; cur = cur.parent) {
1574
+ let matches = matchingNodes(cur.type, dir, brackets);
1575
+ if (matches && cur.from < cur.to) {
1576
+ let handle = findHandle(cur);
1577
+ if (handle && (dir > 0 ? pos >= handle.from && pos < handle.to : pos > handle.from && pos <= handle.to))
1578
+ return matchMarkedBrackets(state, pos, dir, cur, handle, matches, brackets);
1579
+ }
1580
+ }
1581
+ return matchPlainBrackets(state, pos, dir, tree, node.type, maxScanDistance, brackets);
1582
+ }
1583
+ function matchMarkedBrackets(_state, _pos, dir, token, handle, matching, brackets) {
1584
+ let parent = token.parent, firstToken = { from: handle.from, to: handle.to };
1585
+ let depth = 0, cursor = parent === null || parent === void 0 ? void 0 : parent.cursor();
1586
+ if (cursor && (dir < 0 ? cursor.childBefore(token.from) : cursor.childAfter(token.to)))
1587
+ do {
1588
+ if (dir < 0 ? cursor.to <= token.from : cursor.from >= token.to) {
1589
+ if (depth == 0 && matching.indexOf(cursor.type.name) > -1 && cursor.from < cursor.to) {
1590
+ let endHandle = findHandle(cursor);
1591
+ return { start: firstToken, end: endHandle ? { from: endHandle.from, to: endHandle.to } : undefined, matched: true };
1592
+ }
1593
+ else if (matchingNodes(cursor.type, dir, brackets)) {
1594
+ depth++;
1595
+ }
1596
+ else if (matchingNodes(cursor.type, -dir, brackets)) {
1597
+ if (depth == 0) {
1598
+ let endHandle = findHandle(cursor);
1599
+ return {
1600
+ start: firstToken,
1601
+ end: endHandle && endHandle.from < endHandle.to ? { from: endHandle.from, to: endHandle.to } : undefined,
1602
+ matched: false
1603
+ };
1604
+ }
1605
+ depth--;
1606
+ }
1607
+ }
1608
+ } while (dir < 0 ? cursor.prevSibling() : cursor.nextSibling());
1609
+ return { start: firstToken, matched: false };
1610
+ }
1611
+ function matchPlainBrackets(state, pos, dir, tree, tokenType, maxScanDistance, brackets) {
1612
+ let startCh = dir < 0 ? state.sliceDoc(pos - 1, pos) : state.sliceDoc(pos, pos + 1);
1613
+ let bracket = brackets.indexOf(startCh);
1614
+ if (bracket < 0 || (bracket % 2 == 0) != (dir > 0))
1615
+ return null;
1616
+ let startToken = { from: dir < 0 ? pos - 1 : pos, to: dir > 0 ? pos + 1 : pos };
1617
+ let iter = state.doc.iterRange(pos, dir > 0 ? state.doc.length : 0), depth = 0;
1618
+ for (let distance = 0; !(iter.next()).done && distance <= maxScanDistance;) {
1619
+ let text = iter.value;
1620
+ if (dir < 0)
1621
+ distance += text.length;
1622
+ let basePos = pos + distance * dir;
1623
+ for (let pos = dir > 0 ? 0 : text.length - 1, end = dir > 0 ? text.length : -1; pos != end; pos += dir) {
1624
+ let found = brackets.indexOf(text[pos]);
1625
+ if (found < 0 || tree.resolveInner(basePos + pos, 1).type != tokenType)
1626
+ continue;
1627
+ if ((found % 2 == 0) == (dir > 0)) {
1628
+ depth++;
1629
+ }
1630
+ else if (depth == 1) { // Closing
1631
+ return { start: startToken, end: { from: basePos + pos, to: basePos + pos + 1 }, matched: (found >> 1) == (bracket >> 1) };
1632
+ }
1633
+ else {
1634
+ depth--;
1635
+ }
1636
+ }
1637
+ if (dir > 0)
1638
+ distance += text.length;
1639
+ }
1640
+ return iter.done ? { start: startToken, matched: false } : null;
1641
+ }
1642
+ const noTokens = /*@__PURE__*/Object.create(null);
1643
+ const typeArray = [NodeType.none];
1644
+ const warned = [];
1645
+ // Cache of node types by name and tags
1646
+ const byTag = /*@__PURE__*/Object.create(null);
1647
+ const defaultTable = /*@__PURE__*/Object.create(null);
1648
+ for (let [legacyName, name] of [
1649
+ ["variable", "variableName"],
1650
+ ["variable-2", "variableName.special"],
1651
+ ["string-2", "string.special"],
1652
+ ["def", "variableName.definition"],
1653
+ ["tag", "tagName"],
1654
+ ["attribute", "attributeName"],
1655
+ ["type", "typeName"],
1656
+ ["builtin", "variableName.standard"],
1657
+ ["qualifier", "modifier"],
1658
+ ["error", "invalid"],
1659
+ ["header", "heading"],
1660
+ ["property", "propertyName"]
1661
+ ])
1662
+ defaultTable[legacyName] = /*@__PURE__*/createTokenType(noTokens, name);
1663
+ function warnForPart(part, msg) {
1664
+ if (warned.indexOf(part) > -1)
1665
+ return;
1666
+ warned.push(part);
1667
+ console.warn(msg);
1668
+ }
1669
+ function createTokenType(extra, tagStr) {
1670
+ let tags$1 = [];
1671
+ for (let name of tagStr.split(" ")) {
1672
+ let found = [];
1673
+ for (let part of name.split(".")) {
1674
+ let value = (extra[part] || tags[part]);
1675
+ if (!value) {
1676
+ warnForPart(part, `Unknown highlighting tag ${part}`);
1677
+ }
1678
+ else if (typeof value == "function") {
1679
+ if (!found.length)
1680
+ warnForPart(part, `Modifier ${part} used at start of tag`);
1681
+ else
1682
+ found = found.map(value);
1683
+ }
1684
+ else {
1685
+ if (found.length)
1686
+ warnForPart(part, `Tag ${part} used as modifier`);
1687
+ else
1688
+ found = Array.isArray(value) ? value : [value];
1689
+ }
1690
+ }
1691
+ for (let tag of found)
1692
+ tags$1.push(tag);
1693
+ }
1694
+ if (!tags$1.length)
1695
+ return 0;
1696
+ let name = tagStr.replace(/ /g, "_"), key = name + " " + tags$1.map(t => t.id);
1697
+ let known = byTag[key];
1698
+ if (known)
1699
+ return known.id;
1700
+ let type = byTag[key] = NodeType.define({
1701
+ id: typeArray.length,
1702
+ name,
1703
+ props: [styleTags({ [name]: tags$1 })]
1704
+ });
1705
+ typeArray.push(type);
1706
+ return type.id;
1707
+ }
1708
+ ({
1709
+ rtl: /*@__PURE__*/Decoration.mark({ class: "cm-iso", inclusive: true, attributes: { dir: "rtl" }, bidiIsolate: Direction.RTL }),
1710
+ ltr: /*@__PURE__*/Decoration.mark({ class: "cm-iso", inclusive: true, attributes: { dir: "ltr" }, bidiIsolate: Direction.LTR }),
1711
+ auto: /*@__PURE__*/Decoration.mark({ class: "cm-iso", inclusive: true, attributes: { dir: "auto" }, bidiIsolate: null })
1712
+ });
1713
+
1714
+ export { DocInput, HighlightStyle, IndentContext, Language, ParseContext, TreeIndentContext, bracketMatching, bracketMatchingHandle, codeFolding, defaultHighlightStyle, foldAll, foldCode, foldEffect, foldGutter, foldKeymap, foldNodeProp, foldService, foldState, foldable, getIndentUnit, getIndentation, indentNodeProp, indentOnInput, indentService, indentString, indentUnit, language, languageDataProp, matchBrackets, sublanguageProp, syntaxHighlighting, syntaxTree, unfoldAll, unfoldCode, unfoldEffect };
1715
+ //# sourceMappingURL=index.js.map