@codemirror/language 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/dispatch.yml +1 -1
- package/CHANGELOG.md +6 -0
- package/README.md +5 -5
- package/dist/index.cjs +32 -4
- package/dist/index.d.ts +14 -3
- package/dist/index.js +32 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# @codemirror/language [](https://www.npmjs.org/package/@codemirror/language)
|
|
2
2
|
|
|
3
|
-
[ [**WEBSITE**](https://codemirror.net/
|
|
3
|
+
[ [**WEBSITE**](https://codemirror.net/) | [**DOCS**](https://codemirror.net/docs/ref/#language) | [**ISSUES**](https://github.com/codemirror/dev/issues) | [**FORUM**](https://discuss.codemirror.net/c/next/) | [**CHANGELOG**](https://github.com/codemirror/language/blob/main/CHANGELOG.md) ]
|
|
4
4
|
|
|
5
5
|
This package implements the language support infrastructure for the
|
|
6
|
-
[CodeMirror](https://codemirror.net/
|
|
6
|
+
[CodeMirror](https://codemirror.net/) code editor.
|
|
7
7
|
|
|
8
|
-
The [project page](https://codemirror.net/
|
|
9
|
-
number of [examples](https://codemirror.net/
|
|
10
|
-
[documentation](https://codemirror.net/
|
|
8
|
+
The [project page](https://codemirror.net/) has more information, a
|
|
9
|
+
number of [examples](https://codemirror.net/examples/) and the
|
|
10
|
+
[documentation](https://codemirror.net/docs/).
|
|
11
11
|
|
|
12
12
|
This code is released under an
|
|
13
13
|
[MIT license](https://github.com/codemirror/language/tree/main/LICENSE).
|
package/dist/index.cjs
CHANGED
|
@@ -616,7 +616,10 @@ const parseWorker = view.ViewPlugin.fromClass(class ParseWorker {
|
|
|
616
616
|
eventHandlers: { focus() { this.scheduleWork(); } }
|
|
617
617
|
});
|
|
618
618
|
/**
|
|
619
|
-
The facet used to associate a language with an editor state.
|
|
619
|
+
The facet used to associate a language with an editor state. Used
|
|
620
|
+
by `Language` object's `extension` property (so you don't need to
|
|
621
|
+
manually wrap your languages in this). Can be used to access the
|
|
622
|
+
current language on a state.
|
|
620
623
|
*/
|
|
621
624
|
const language = state.Facet.define({
|
|
622
625
|
combine(languages) { return languages.length ? languages[0] : null; },
|
|
@@ -1204,6 +1207,13 @@ function selectedLines(view) {
|
|
|
1204
1207
|
}
|
|
1205
1208
|
return lines;
|
|
1206
1209
|
}
|
|
1210
|
+
/**
|
|
1211
|
+
The state field that stores the folded ranges (as a [decoration
|
|
1212
|
+
set](https://codemirror.net/6/docs/ref/#view.DecorationSet)). Can be passed to
|
|
1213
|
+
[`EditorState.toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) and
|
|
1214
|
+
[`fromJSON`](https://codemirror.net/6/docs/ref/#state.EditorState^fromJSON) to serialize the fold
|
|
1215
|
+
state.
|
|
1216
|
+
*/
|
|
1207
1217
|
const foldState = state.StateField.define({
|
|
1208
1218
|
create() {
|
|
1209
1219
|
return view.Decoration.none;
|
|
@@ -1231,7 +1241,24 @@ const foldState = state.StateField.define({
|
|
|
1231
1241
|
}
|
|
1232
1242
|
return folded;
|
|
1233
1243
|
},
|
|
1234
|
-
provide: f => view.EditorView.decorations.from(f)
|
|
1244
|
+
provide: f => view.EditorView.decorations.from(f),
|
|
1245
|
+
toJSON(folded, state) {
|
|
1246
|
+
let ranges = [];
|
|
1247
|
+
folded.between(0, state.doc.length, (from, to) => { ranges.push(from, to); });
|
|
1248
|
+
return ranges;
|
|
1249
|
+
},
|
|
1250
|
+
fromJSON(value) {
|
|
1251
|
+
if (!Array.isArray(value) || value.length % 2)
|
|
1252
|
+
throw new RangeError("Invalid JSON for fold state");
|
|
1253
|
+
let ranges = [];
|
|
1254
|
+
for (let i = 0; i < value.length;) {
|
|
1255
|
+
let from = value[i++], to = value[i++];
|
|
1256
|
+
if (typeof from != "number" || typeof to != "number")
|
|
1257
|
+
throw new RangeError("Invalid JSON for fold state");
|
|
1258
|
+
ranges.push(foldWidget.range(from, to));
|
|
1259
|
+
}
|
|
1260
|
+
return view.Decoration.set(ranges, true);
|
|
1261
|
+
}
|
|
1235
1262
|
});
|
|
1236
1263
|
/**
|
|
1237
1264
|
Get a [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) containing the folded ranges
|
|
@@ -2249,8 +2276,8 @@ for (let [legacyName, name] of [
|
|
|
2249
2276
|
["variable-2", "variableName.special"],
|
|
2250
2277
|
["string-2", "string.special"],
|
|
2251
2278
|
["def", "variableName.definition"],
|
|
2252
|
-
["tag", "
|
|
2253
|
-
["attribute", "
|
|
2279
|
+
["tag", "tagName"],
|
|
2280
|
+
["attribute", "attributeName"],
|
|
2254
2281
|
["type", "typeName"],
|
|
2255
2282
|
["builtin", "variableName.standard"],
|
|
2256
2283
|
["qualifier", "modifier"],
|
|
@@ -2337,6 +2364,7 @@ exports.foldInside = foldInside;
|
|
|
2337
2364
|
exports.foldKeymap = foldKeymap;
|
|
2338
2365
|
exports.foldNodeProp = foldNodeProp;
|
|
2339
2366
|
exports.foldService = foldService;
|
|
2367
|
+
exports.foldState = foldState;
|
|
2340
2368
|
exports.foldable = foldable;
|
|
2341
2369
|
exports.foldedRanges = foldedRanges;
|
|
2342
2370
|
exports.forceParsing = forceParsing;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NodeProp, Parser, Tree, TreeFragment, SyntaxNode, NodeType } from '@lezer/common';
|
|
2
2
|
import { LRParser, ParserConfig } from '@lezer/lr';
|
|
3
3
|
import * as _codemirror_state from '@codemirror/state';
|
|
4
|
-
import { Facet, Extension, EditorState, Range } from '@codemirror/state';
|
|
4
|
+
import { Facet, Extension, EditorState, StateField, Range } from '@codemirror/state';
|
|
5
5
|
import { EditorView, DecorationSet, Command, KeyBinding, ViewUpdate, BlockInfo, Decoration } from '@codemirror/view';
|
|
6
6
|
import { Highlighter, Tag } from '@lezer/highlight';
|
|
7
7
|
import { StyleModule, StyleSpec } from 'style-mod';
|
|
@@ -214,7 +214,10 @@ declare class ParseContext {
|
|
|
214
214
|
static get(): ParseContext | null;
|
|
215
215
|
}
|
|
216
216
|
/**
|
|
217
|
-
The facet used to associate a language with an editor state.
|
|
217
|
+
The facet used to associate a language with an editor state. Used
|
|
218
|
+
by `Language` object's `extension` property (so you don't need to
|
|
219
|
+
manually wrap your languages in this). Can be used to access the
|
|
220
|
+
current language on a state.
|
|
218
221
|
*/
|
|
219
222
|
declare const language: Facet<Language, Language | null>;
|
|
220
223
|
/**
|
|
@@ -617,6 +620,14 @@ State effect that unfolds the given range (if it was folded).
|
|
|
617
620
|
*/
|
|
618
621
|
declare const unfoldEffect: _codemirror_state.StateEffectType<DocRange>;
|
|
619
622
|
/**
|
|
623
|
+
The state field that stores the folded ranges (as a [decoration
|
|
624
|
+
set](https://codemirror.net/6/docs/ref/#view.DecorationSet)). Can be passed to
|
|
625
|
+
[`EditorState.toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) and
|
|
626
|
+
[`fromJSON`](https://codemirror.net/6/docs/ref/#state.EditorState^fromJSON) to serialize the fold
|
|
627
|
+
state.
|
|
628
|
+
*/
|
|
629
|
+
declare const foldState: StateField<DecorationSet>;
|
|
630
|
+
/**
|
|
620
631
|
Get a [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) containing the folded ranges
|
|
621
632
|
in the given state.
|
|
622
633
|
*/
|
|
@@ -1061,4 +1072,4 @@ declare class StreamLanguage<State> extends Language {
|
|
|
1061
1072
|
get allowsNesting(): boolean;
|
|
1062
1073
|
}
|
|
1063
1074
|
|
|
1064
|
-
export { Config, HighlightStyle, IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, MatchResult, ParseContext, StreamLanguage, StreamParser, StringStream, TagStyle, TreeIndentContext, bracketMatching, codeFolding, continuedIndent, defaultHighlightStyle, defineLanguageFacet, delimitedIndent, ensureSyntaxTree, flatIndent, foldAll, foldCode, foldEffect, foldGutter, foldInside, foldKeymap, foldNodeProp, foldService, foldable, foldedRanges, forceParsing, getIndentUnit, getIndentation, highlightingFor, indentNodeProp, indentOnInput, indentService, indentString, indentUnit, language, languageDataProp, matchBrackets, syntaxHighlighting, syntaxParserRunning, syntaxTree, syntaxTreeAvailable, unfoldAll, unfoldCode, unfoldEffect };
|
|
1075
|
+
export { Config, HighlightStyle, IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, MatchResult, ParseContext, StreamLanguage, StreamParser, StringStream, TagStyle, TreeIndentContext, bracketMatching, codeFolding, continuedIndent, defaultHighlightStyle, defineLanguageFacet, delimitedIndent, ensureSyntaxTree, flatIndent, foldAll, foldCode, foldEffect, foldGutter, foldInside, foldKeymap, foldNodeProp, foldService, foldState, foldable, foldedRanges, forceParsing, getIndentUnit, getIndentation, highlightingFor, indentNodeProp, indentOnInput, indentService, indentString, indentUnit, language, languageDataProp, matchBrackets, syntaxHighlighting, syntaxParserRunning, syntaxTree, syntaxTreeAvailable, unfoldAll, unfoldCode, unfoldEffect };
|
package/dist/index.js
CHANGED
|
@@ -612,7 +612,10 @@ const parseWorker = /*@__PURE__*/ViewPlugin.fromClass(class ParseWorker {
|
|
|
612
612
|
eventHandlers: { focus() { this.scheduleWork(); } }
|
|
613
613
|
});
|
|
614
614
|
/**
|
|
615
|
-
The facet used to associate a language with an editor state.
|
|
615
|
+
The facet used to associate a language with an editor state. Used
|
|
616
|
+
by `Language` object's `extension` property (so you don't need to
|
|
617
|
+
manually wrap your languages in this). Can be used to access the
|
|
618
|
+
current language on a state.
|
|
616
619
|
*/
|
|
617
620
|
const language = /*@__PURE__*/Facet.define({
|
|
618
621
|
combine(languages) { return languages.length ? languages[0] : null; },
|
|
@@ -1200,6 +1203,13 @@ function selectedLines(view) {
|
|
|
1200
1203
|
}
|
|
1201
1204
|
return lines;
|
|
1202
1205
|
}
|
|
1206
|
+
/**
|
|
1207
|
+
The state field that stores the folded ranges (as a [decoration
|
|
1208
|
+
set](https://codemirror.net/6/docs/ref/#view.DecorationSet)). Can be passed to
|
|
1209
|
+
[`EditorState.toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) and
|
|
1210
|
+
[`fromJSON`](https://codemirror.net/6/docs/ref/#state.EditorState^fromJSON) to serialize the fold
|
|
1211
|
+
state.
|
|
1212
|
+
*/
|
|
1203
1213
|
const foldState = /*@__PURE__*/StateField.define({
|
|
1204
1214
|
create() {
|
|
1205
1215
|
return Decoration.none;
|
|
@@ -1227,7 +1237,24 @@ const foldState = /*@__PURE__*/StateField.define({
|
|
|
1227
1237
|
}
|
|
1228
1238
|
return folded;
|
|
1229
1239
|
},
|
|
1230
|
-
provide: f => EditorView.decorations.from(f)
|
|
1240
|
+
provide: f => EditorView.decorations.from(f),
|
|
1241
|
+
toJSON(folded, state) {
|
|
1242
|
+
let ranges = [];
|
|
1243
|
+
folded.between(0, state.doc.length, (from, to) => { ranges.push(from, to); });
|
|
1244
|
+
return ranges;
|
|
1245
|
+
},
|
|
1246
|
+
fromJSON(value) {
|
|
1247
|
+
if (!Array.isArray(value) || value.length % 2)
|
|
1248
|
+
throw new RangeError("Invalid JSON for fold state");
|
|
1249
|
+
let ranges = [];
|
|
1250
|
+
for (let i = 0; i < value.length;) {
|
|
1251
|
+
let from = value[i++], to = value[i++];
|
|
1252
|
+
if (typeof from != "number" || typeof to != "number")
|
|
1253
|
+
throw new RangeError("Invalid JSON for fold state");
|
|
1254
|
+
ranges.push(foldWidget.range(from, to));
|
|
1255
|
+
}
|
|
1256
|
+
return Decoration.set(ranges, true);
|
|
1257
|
+
}
|
|
1231
1258
|
});
|
|
1232
1259
|
/**
|
|
1233
1260
|
Get a [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) containing the folded ranges
|
|
@@ -2245,8 +2272,8 @@ for (let [legacyName, name] of [
|
|
|
2245
2272
|
["variable-2", "variableName.special"],
|
|
2246
2273
|
["string-2", "string.special"],
|
|
2247
2274
|
["def", "variableName.definition"],
|
|
2248
|
-
["tag", "
|
|
2249
|
-
["attribute", "
|
|
2275
|
+
["tag", "tagName"],
|
|
2276
|
+
["attribute", "attributeName"],
|
|
2250
2277
|
["type", "typeName"],
|
|
2251
2278
|
["builtin", "variableName.standard"],
|
|
2252
2279
|
["qualifier", "modifier"],
|
|
@@ -2307,4 +2334,4 @@ function docID(data) {
|
|
|
2307
2334
|
return type;
|
|
2308
2335
|
}
|
|
2309
2336
|
|
|
2310
|
-
export { HighlightStyle, IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, ParseContext, StreamLanguage, StringStream, TreeIndentContext, bracketMatching, codeFolding, continuedIndent, defaultHighlightStyle, defineLanguageFacet, delimitedIndent, ensureSyntaxTree, flatIndent, foldAll, foldCode, foldEffect, foldGutter, foldInside, foldKeymap, foldNodeProp, foldService, foldable, foldedRanges, forceParsing, getIndentUnit, getIndentation, highlightingFor, indentNodeProp, indentOnInput, indentService, indentString, indentUnit, language, languageDataProp, matchBrackets, syntaxHighlighting, syntaxParserRunning, syntaxTree, syntaxTreeAvailable, unfoldAll, unfoldCode, unfoldEffect };
|
|
2337
|
+
export { HighlightStyle, IndentContext, LRLanguage, Language, LanguageDescription, LanguageSupport, ParseContext, StreamLanguage, StringStream, TreeIndentContext, bracketMatching, codeFolding, continuedIndent, defaultHighlightStyle, defineLanguageFacet, delimitedIndent, ensureSyntaxTree, flatIndent, foldAll, foldCode, foldEffect, foldGutter, foldInside, foldKeymap, foldNodeProp, foldService, foldState, foldable, foldedRanges, forceParsing, getIndentUnit, getIndentation, highlightingFor, indentNodeProp, indentOnInput, indentService, indentString, indentUnit, language, languageDataProp, matchBrackets, syntaxHighlighting, syntaxParserRunning, syntaxTree, syntaxTreeAvailable, unfoldAll, unfoldCode, unfoldEffect };
|