@uiw/react-codemirror 4.19.9 → 4.19.10

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/dist/mdeditor.js CHANGED
@@ -2132,45 +2132,59 @@ function enterFragments(mounts, ranges) {
2132
2132
 
2133
2133
 
2134
2134
  let nextTagID = 0;
2135
- /// Highlighting tags are markers that denote a highlighting category.
2136
- /// They are [associated](#highlight.styleTags) with parts of a syntax
2137
- /// tree by a language mode, and then mapped to an actual CSS style by
2138
- /// a [highlighter](#highlight.Highlighter).
2139
- ///
2140
- /// Because syntax tree node types and highlight styles have to be
2141
- /// able to talk the same language, CodeMirror uses a mostly _closed_
2142
- /// [vocabulary](#highlight.tags) of syntax tags (as opposed to
2143
- /// traditional open string-based systems, which make it hard for
2144
- /// highlighting themes to cover all the tokens produced by the
2145
- /// various languages).
2146
- ///
2147
- /// It _is_ possible to [define](#highlight.Tag^define) your own
2148
- /// highlighting tags for system-internal use (where you control both
2149
- /// the language package and the highlighter), but such tags will not
2150
- /// be picked up by regular highlighters (though you can derive them
2151
- /// from standard tags to allow highlighters to fall back to those).
2135
+ /**
2136
+ Highlighting tags are markers that denote a highlighting category.
2137
+ They are [associated](#highlight.styleTags) with parts of a syntax
2138
+ tree by a language mode, and then mapped to an actual CSS style by
2139
+ a [highlighter](#highlight.Highlighter).
2140
+
2141
+ Because syntax tree node types and highlight styles have to be
2142
+ able to talk the same language, CodeMirror uses a mostly _closed_
2143
+ [vocabulary](#highlight.tags) of syntax tags (as opposed to
2144
+ traditional open string-based systems, which make it hard for
2145
+ highlighting themes to cover all the tokens produced by the
2146
+ various languages).
2147
+
2148
+ It _is_ possible to [define](#highlight.Tag^define) your own
2149
+ highlighting tags for system-internal use (where you control both
2150
+ the language package and the highlighter), but such tags will not
2151
+ be picked up by regular highlighters (though you can derive them
2152
+ from standard tags to allow highlighters to fall back to those).
2153
+ */
2152
2154
  class Tag {
2153
- /// @internal
2155
+ /**
2156
+ @internal
2157
+ */
2154
2158
  constructor(
2155
- /// The set of this tag and all its parent tags, starting with
2156
- /// this one itself and sorted in order of decreasing specificity.
2159
+ /**
2160
+ The set of this tag and all its parent tags, starting with
2161
+ this one itself and sorted in order of decreasing specificity.
2162
+ */
2157
2163
  set,
2158
- /// The base unmodified tag that this one is based on, if it's
2159
- /// modified @internal
2164
+ /**
2165
+ The base unmodified tag that this one is based on, if it's
2166
+ modified @internal
2167
+ */
2160
2168
  base,
2161
- /// The modifiers applied to this.base @internal
2169
+ /**
2170
+ The modifiers applied to this.base @internal
2171
+ */
2162
2172
  modified) {
2163
2173
  this.set = set;
2164
2174
  this.base = base;
2165
2175
  this.modified = modified;
2166
- /// @internal
2176
+ /**
2177
+ @internal
2178
+ */
2167
2179
  this.id = nextTagID++;
2168
2180
  }
2169
- /// Define a new tag. If `parent` is given, the tag is treated as a
2170
- /// sub-tag of that parent, and
2171
- /// [highlighters](#highlight.tagHighlighter) that don't mention
2172
- /// this tag will try to fall back to the parent tag (or grandparent
2173
- /// tag, etc).
2181
+ /**
2182
+ Define a new tag. If `parent` is given, the tag is treated as a
2183
+ sub-tag of that parent, and
2184
+ [highlighters](#highlight.tagHighlighter) that don't mention
2185
+ this tag will try to fall back to the parent tag (or grandparent
2186
+ tag, etc).
2187
+ */
2174
2188
  static define(parent) {
2175
2189
  if (parent === null || parent === void 0 ? void 0 : parent.base)
2176
2190
  throw new Error("Can not derive from a modified tag");
@@ -2181,16 +2195,18 @@ class Tag {
2181
2195
  tag.set.push(t);
2182
2196
  return tag;
2183
2197
  }
2184
- /// Define a tag _modifier_, which is a function that, given a tag,
2185
- /// will return a tag that is a subtag of the original. Applying the
2186
- /// same modifier to a twice tag will return the same value (`m1(t1)
2187
- /// == m1(t1)`) and applying multiple modifiers will, regardless or
2188
- /// order, produce the same tag (`m1(m2(t1)) == m2(m1(t1))`).
2189
- ///
2190
- /// When multiple modifiers are applied to a given base tag, each
2191
- /// smaller set of modifiers is registered as a parent, so that for
2192
- /// example `m1(m2(m3(t1)))` is a subtype of `m1(m2(t1))`,
2193
- /// `m1(m3(t1)`, and so on.
2198
+ /**
2199
+ Define a tag _modifier_, which is a function that, given a tag,
2200
+ will return a tag that is a subtag of the original. Applying the
2201
+ same modifier to a twice tag will return the same value (`m1(t1)
2202
+ == m1(t1)`) and applying multiple modifiers will, regardless or
2203
+ order, produce the same tag (`m1(m2(t1)) == m2(m1(t1))`).
2204
+
2205
+ When multiple modifiers are applied to a given base tag, each
2206
+ smaller set of modifiers is registered as a parent, so that for
2207
+ example `m1(m2(m3(t1)))` is a subtype of `m1(m2(t1))`,
2208
+ `m1(m3(t1)`, and so on.
2209
+ */
2194
2210
  static defineModifier() {
2195
2211
  let mod = new Modifier;
2196
2212
  return (tag) => {
@@ -2235,55 +2251,57 @@ function powerSet(array) {
2235
2251
  }
2236
2252
  return sets.sort((a, b) => b.length - a.length);
2237
2253
  }
2238
- /// This function is used to add a set of tags to a language syntax
2239
- /// via [`NodeSet.extend`](#common.NodeSet.extend) or
2240
- /// [`LRParser.configure`](#lr.LRParser.configure).
2241
- ///
2242
- /// The argument object maps node selectors to [highlighting
2243
- /// tags](#highlight.Tag) or arrays of tags.
2244
- ///
2245
- /// Node selectors may hold one or more (space-separated) node paths.
2246
- /// Such a path can be a [node name](#common.NodeType.name), or
2247
- /// multiple node names (or `*` wildcards) separated by slash
2248
- /// characters, as in `"Block/Declaration/VariableName"`. Such a path
2249
- /// matches the final node but only if its direct parent nodes are the
2250
- /// other nodes mentioned. A `*` in such a path matches any parent,
2251
- /// but only a single level—wildcards that match multiple parents
2252
- /// aren't supported, both for efficiency reasons and because Lezer
2253
- /// trees make it rather hard to reason about what they would match.)
2254
- ///
2255
- /// A path can be ended with `/...` to indicate that the tag assigned
2256
- /// to the node should also apply to all child nodes, even if they
2257
- /// match their own style (by default, only the innermost style is
2258
- /// used).
2259
- ///
2260
- /// When a path ends in `!`, as in `Attribute!`, no further matching
2261
- /// happens for the node's child nodes, and the entire node gets the
2262
- /// given style.
2263
- ///
2264
- /// In this notation, node names that contain `/`, `!`, `*`, or `...`
2265
- /// must be quoted as JSON strings.
2266
- ///
2267
- /// For example:
2268
- ///
2269
- /// ```javascript
2270
- /// parser.withProps(
2271
- /// styleTags({
2272
- /// // Style Number and BigNumber nodes
2273
- /// "Number BigNumber": tags.number,
2274
- /// // Style Escape nodes whose parent is String
2275
- /// "String/Escape": tags.escape,
2276
- /// // Style anything inside Attributes nodes
2277
- /// "Attributes!": tags.meta,
2278
- /// // Add a style to all content inside Italic nodes
2279
- /// "Italic/...": tags.emphasis,
2280
- /// // Style InvalidString nodes as both `string` and `invalid`
2281
- /// "InvalidString": [tags.string, tags.invalid],
2282
- /// // Style the node named "/" as punctuation
2283
- /// '"/"': tags.punctuation
2284
- /// })
2285
- /// )
2286
- /// ```
2254
+ /**
2255
+ This function is used to add a set of tags to a language syntax
2256
+ via [`NodeSet.extend`](#common.NodeSet.extend) or
2257
+ [`LRParser.configure`](#lr.LRParser.configure).
2258
+
2259
+ The argument object maps node selectors to [highlighting
2260
+ tags](#highlight.Tag) or arrays of tags.
2261
+
2262
+ Node selectors may hold one or more (space-separated) node paths.
2263
+ Such a path can be a [node name](#common.NodeType.name), or
2264
+ multiple node names (or `*` wildcards) separated by slash
2265
+ characters, as in `"Block/Declaration/VariableName"`. Such a path
2266
+ matches the final node but only if its direct parent nodes are the
2267
+ other nodes mentioned. A `*` in such a path matches any parent,
2268
+ but only a single level—wildcards that match multiple parents
2269
+ aren't supported, both for efficiency reasons and because Lezer
2270
+ trees make it rather hard to reason about what they would match.)
2271
+
2272
+ A path can be ended with `/...` to indicate that the tag assigned
2273
+ to the node should also apply to all child nodes, even if they
2274
+ match their own style (by default, only the innermost style is
2275
+ used).
2276
+
2277
+ When a path ends in `!`, as in `Attribute!`, no further matching
2278
+ happens for the node's child nodes, and the entire node gets the
2279
+ given style.
2280
+
2281
+ In this notation, node names that contain `/`, `!`, `*`, or `...`
2282
+ must be quoted as JSON strings.
2283
+
2284
+ For example:
2285
+
2286
+ ```javascript
2287
+ parser.withProps(
2288
+ styleTags({
2289
+ // Style Number and BigNumber nodes
2290
+ "Number BigNumber": tags.number,
2291
+ // Style Escape nodes whose parent is String
2292
+ "String/Escape": tags.escape,
2293
+ // Style anything inside Attributes nodes
2294
+ "Attributes!": tags.meta,
2295
+ // Add a style to all content inside Italic nodes
2296
+ "Italic/...": tags.emphasis,
2297
+ // Style InvalidString nodes as both `string` and `invalid`
2298
+ "InvalidString": [tags.string, tags.invalid],
2299
+ // Style the node named "/" as punctuation
2300
+ '"/"': tags.punctuation
2301
+ })
2302
+ )
2303
+ ```
2304
+ */
2287
2305
  function styleTags(spec) {
2288
2306
  let byName = Object.create(null);
2289
2307
  for (let prop in spec) {
@@ -2292,10 +2310,10 @@ function styleTags(spec) {
2292
2310
  tags = [tags];
2293
2311
  for (let part of prop.split(" "))
2294
2312
  if (part) {
2295
- let pieces = [], mode = 2 /* Mode.Normal */, rest = part;
2313
+ let pieces = [], mode = 2 /* Normal */, rest = part;
2296
2314
  for (let pos = 0;;) {
2297
2315
  if (rest == "..." && pos > 0 && pos + 3 == part.length) {
2298
- mode = 1 /* Mode.Inherit */;
2316
+ mode = 1 /* Inherit */;
2299
2317
  break;
2300
2318
  }
2301
2319
  let m = /^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(rest);
@@ -2307,7 +2325,7 @@ function styleTags(spec) {
2307
2325
  break;
2308
2326
  let next = part[pos++];
2309
2327
  if (pos == part.length && next == "!") {
2310
- mode = 0 /* Mode.Opaque */;
2328
+ mode = 0 /* Opaque */;
2311
2329
  break;
2312
2330
  }
2313
2331
  if (next != "/")
@@ -2331,8 +2349,8 @@ class Rule {
2331
2349
  this.context = context;
2332
2350
  this.next = next;
2333
2351
  }
2334
- get opaque() { return this.mode == 0 /* Mode.Opaque */; }
2335
- get inherit() { return this.mode == 1 /* Mode.Inherit */; }
2352
+ get opaque() { return this.mode == 0 /* Opaque */; }
2353
+ get inherit() { return this.mode == 1 /* Inherit */; }
2336
2354
  sort(other) {
2337
2355
  if (!other || other.depth < this.depth) {
2338
2356
  this.next = other;
@@ -2343,10 +2361,12 @@ class Rule {
2343
2361
  }
2344
2362
  get depth() { return this.context ? this.context.length : 0; }
2345
2363
  }
2346
- Rule.empty = new Rule([], 2 /* Mode.Normal */, null);
2347
- /// Define a [highlighter](#highlight.Highlighter) from an array of
2348
- /// tag/class pairs. Classes associated with more specific tags will
2349
- /// take precedence.
2364
+ Rule.empty = new Rule([], 2 /* Normal */, null);
2365
+ /**
2366
+ Define a [highlighter](#highlight.Highlighter) from an array of
2367
+ tag/class pairs. Classes associated with more specific tags will
2368
+ take precedence.
2369
+ */
2350
2370
  function tagHighlighter(tags, options) {
2351
2371
  let map = Object.create(null);
2352
2372
  for (let style of tags) {
@@ -2383,16 +2403,24 @@ function highlightTags(highlighters, tags) {
2383
2403
  }
2384
2404
  return result;
2385
2405
  }
2386
- /// Highlight the given [tree](#common.Tree) with the given
2387
- /// [highlighter](#highlight.Highlighter).
2406
+ /**
2407
+ Highlight the given [tree](#common.Tree) with the given
2408
+ [highlighter](#highlight.Highlighter).
2409
+ */
2388
2410
  function highlightTree(tree, highlighter,
2389
- /// Assign styling to a region of the text. Will be called, in order
2390
- /// of position, for any ranges where more than zero classes apply.
2391
- /// `classes` is a space separated string of CSS classes.
2411
+ /**
2412
+ Assign styling to a region of the text. Will be called, in order
2413
+ of position, for any ranges where more than zero classes apply.
2414
+ `classes` is a space separated string of CSS classes.
2415
+ */
2392
2416
  putStyle,
2393
- /// The start of the range to highlight.
2417
+ /**
2418
+ The start of the range to highlight.
2419
+ */
2394
2420
  from = 0,
2395
- /// The end of the range.
2421
+ /**
2422
+ The end of the range.
2423
+ */
2396
2424
  to = tree.length) {
2397
2425
  let builder = new HighlightBuilder(from, Array.isArray(highlighter) ? highlighter : [highlighter], putStyle);
2398
2426
  builder.highlightRange(tree.cursor(), from, to, "", builder.highlighters);
@@ -2430,7 +2458,7 @@ class HighlightBuilder {
2430
2458
  if (cls)
2431
2459
  cls += " ";
2432
2460
  cls += tagCls;
2433
- if (rule.mode == 1 /* Mode.Inherit */)
2461
+ if (rule.mode == 1 /* Inherit */)
2434
2462
  inheritedClass += (inheritedClass ? " " : "") + tagCls;
2435
2463
  }
2436
2464
  this.startSpan(cursor.from, cls);
@@ -2477,9 +2505,11 @@ class HighlightBuilder {
2477
2505
  }
2478
2506
  }
2479
2507
  }
2480
- /// Match a syntax node's [highlight rules](#highlight.styleTags). If
2481
- /// there's a match, return its set of tags, and whether it is
2482
- /// opaque (uses a `!`) or applies to all child nodes (`/...`).
2508
+ /**
2509
+ Match a syntax node's [highlight rules](#highlight.styleTags). If
2510
+ there's a match, return its set of tags, and whether it is
2511
+ opaque (uses a `!`) or applies to all child nodes (`/...`).
2512
+ */
2483
2513
  function getStyleTags(node) {
2484
2514
  let rule = node.type.prop(ruleNodeProp);
2485
2515
  while (rule && rule.context && !node.matchContext(rule.context))
@@ -2488,268 +2518,440 @@ function getStyleTags(node) {
2488
2518
  }
2489
2519
  const t = Tag.define;
2490
2520
  const comment = t(), dist_name = t(), typeName = t(dist_name), propertyName = t(dist_name), literal = t(), string = t(literal), number = t(literal), content = t(), heading = t(content), keyword = t(), operator = t(), punctuation = t(), bracket = t(punctuation), meta = t();
2491
- /// The default set of highlighting [tags](#highlight.Tag).
2492
- ///
2493
- /// This collection is heavily biased towards programming languages,
2494
- /// and necessarily incomplete. A full ontology of syntactic
2495
- /// constructs would fill a stack of books, and be impractical to
2496
- /// write themes for. So try to make do with this set. If all else
2497
- /// fails, [open an
2498
- /// issue](https://github.com/codemirror/codemirror.next) to propose a
2499
- /// new tag, or [define](#highlight.Tag^define) a local custom tag for
2500
- /// your use case.
2501
- ///
2502
- /// Note that it is not obligatory to always attach the most specific
2503
- /// tag possible to an element—if your grammar can't easily
2504
- /// distinguish a certain type of element (such as a local variable),
2505
- /// it is okay to style it as its more general variant (a variable).
2506
- ///
2507
- /// For tags that extend some parent tag, the documentation links to
2508
- /// the parent.
2521
+ /**
2522
+ The default set of highlighting [tags](#highlight.Tag).
2523
+
2524
+ This collection is heavily biased towards programming languages,
2525
+ and necessarily incomplete. A full ontology of syntactic
2526
+ constructs would fill a stack of books, and be impractical to
2527
+ write themes for. So try to make do with this set. If all else
2528
+ fails, [open an
2529
+ issue](https://github.com/codemirror/codemirror.next) to propose a
2530
+ new tag, or [define](#highlight.Tag^define) a local custom tag for
2531
+ your use case.
2532
+
2533
+ Note that it is not obligatory to always attach the most specific
2534
+ tag possible to an element—if your grammar can't easily
2535
+ distinguish a certain type of element (such as a local variable),
2536
+ it is okay to style it as its more general variant (a variable).
2537
+
2538
+ For tags that extend some parent tag, the documentation links to
2539
+ the parent.
2540
+ */
2509
2541
  const tags = {
2510
- /// A comment.
2542
+ /**
2543
+ A comment.
2544
+ */
2511
2545
  comment,
2512
- /// A line [comment](#highlight.tags.comment).
2546
+ /**
2547
+ A line [comment](#highlight.tags.comment).
2548
+ */
2513
2549
  lineComment: t(comment),
2514
- /// A block [comment](#highlight.tags.comment).
2550
+ /**
2551
+ A block [comment](#highlight.tags.comment).
2552
+ */
2515
2553
  blockComment: t(comment),
2516
- /// A documentation [comment](#highlight.tags.comment).
2554
+ /**
2555
+ A documentation [comment](#highlight.tags.comment).
2556
+ */
2517
2557
  docComment: t(comment),
2518
- /// Any kind of identifier.
2558
+ /**
2559
+ Any kind of identifier.
2560
+ */
2519
2561
  name: dist_name,
2520
- /// The [name](#highlight.tags.name) of a variable.
2562
+ /**
2563
+ The [name](#highlight.tags.name) of a variable.
2564
+ */
2521
2565
  variableName: t(dist_name),
2522
- /// A type [name](#highlight.tags.name).
2566
+ /**
2567
+ A type [name](#highlight.tags.name).
2568
+ */
2523
2569
  typeName: typeName,
2524
- /// A tag name (subtag of [`typeName`](#highlight.tags.typeName)).
2570
+ /**
2571
+ A tag name (subtag of [`typeName`](#highlight.tags.typeName)).
2572
+ */
2525
2573
  tagName: t(typeName),
2526
- /// A property or field [name](#highlight.tags.name).
2574
+ /**
2575
+ A property or field [name](#highlight.tags.name).
2576
+ */
2527
2577
  propertyName: propertyName,
2528
- /// An attribute name (subtag of [`propertyName`](#highlight.tags.propertyName)).
2578
+ /**
2579
+ An attribute name (subtag of [`propertyName`](#highlight.tags.propertyName)).
2580
+ */
2529
2581
  attributeName: t(propertyName),
2530
- /// The [name](#highlight.tags.name) of a class.
2582
+ /**
2583
+ The [name](#highlight.tags.name) of a class.
2584
+ */
2531
2585
  className: t(dist_name),
2532
- /// A label [name](#highlight.tags.name).
2586
+ /**
2587
+ A label [name](#highlight.tags.name).
2588
+ */
2533
2589
  labelName: t(dist_name),
2534
- /// A namespace [name](#highlight.tags.name).
2590
+ /**
2591
+ A namespace [name](#highlight.tags.name).
2592
+ */
2535
2593
  namespace: t(dist_name),
2536
- /// The [name](#highlight.tags.name) of a macro.
2594
+ /**
2595
+ The [name](#highlight.tags.name) of a macro.
2596
+ */
2537
2597
  macroName: t(dist_name),
2538
- /// A literal value.
2598
+ /**
2599
+ A literal value.
2600
+ */
2539
2601
  literal,
2540
- /// A string [literal](#highlight.tags.literal).
2602
+ /**
2603
+ A string [literal](#highlight.tags.literal).
2604
+ */
2541
2605
  string,
2542
- /// A documentation [string](#highlight.tags.string).
2606
+ /**
2607
+ A documentation [string](#highlight.tags.string).
2608
+ */
2543
2609
  docString: t(string),
2544
- /// A character literal (subtag of [string](#highlight.tags.string)).
2610
+ /**
2611
+ A character literal (subtag of [string](#highlight.tags.string)).
2612
+ */
2545
2613
  character: t(string),
2546
- /// An attribute value (subtag of [string](#highlight.tags.string)).
2614
+ /**
2615
+ An attribute value (subtag of [string](#highlight.tags.string)).
2616
+ */
2547
2617
  attributeValue: t(string),
2548
- /// A number [literal](#highlight.tags.literal).
2618
+ /**
2619
+ A number [literal](#highlight.tags.literal).
2620
+ */
2549
2621
  number,
2550
- /// An integer [number](#highlight.tags.number) literal.
2622
+ /**
2623
+ An integer [number](#highlight.tags.number) literal.
2624
+ */
2551
2625
  integer: t(number),
2552
- /// A floating-point [number](#highlight.tags.number) literal.
2626
+ /**
2627
+ A floating-point [number](#highlight.tags.number) literal.
2628
+ */
2553
2629
  float: t(number),
2554
- /// A boolean [literal](#highlight.tags.literal).
2630
+ /**
2631
+ A boolean [literal](#highlight.tags.literal).
2632
+ */
2555
2633
  bool: t(literal),
2556
- /// Regular expression [literal](#highlight.tags.literal).
2634
+ /**
2635
+ Regular expression [literal](#highlight.tags.literal).
2636
+ */
2557
2637
  regexp: t(literal),
2558
- /// An escape [literal](#highlight.tags.literal), for example a
2559
- /// backslash escape in a string.
2638
+ /**
2639
+ An escape [literal](#highlight.tags.literal), for example a
2640
+ backslash escape in a string.
2641
+ */
2560
2642
  escape: t(literal),
2561
- /// A color [literal](#highlight.tags.literal).
2643
+ /**
2644
+ A color [literal](#highlight.tags.literal).
2645
+ */
2562
2646
  color: t(literal),
2563
- /// A URL [literal](#highlight.tags.literal).
2647
+ /**
2648
+ A URL [literal](#highlight.tags.literal).
2649
+ */
2564
2650
  url: t(literal),
2565
- /// A language keyword.
2651
+ /**
2652
+ A language keyword.
2653
+ */
2566
2654
  keyword,
2567
- /// The [keyword](#highlight.tags.keyword) for the self or this
2568
- /// object.
2655
+ /**
2656
+ The [keyword](#highlight.tags.keyword) for the self or this
2657
+ object.
2658
+ */
2569
2659
  self: t(keyword),
2570
- /// The [keyword](#highlight.tags.keyword) for null.
2660
+ /**
2661
+ The [keyword](#highlight.tags.keyword) for null.
2662
+ */
2571
2663
  null: t(keyword),
2572
- /// A [keyword](#highlight.tags.keyword) denoting some atomic value.
2664
+ /**
2665
+ A [keyword](#highlight.tags.keyword) denoting some atomic value.
2666
+ */
2573
2667
  atom: t(keyword),
2574
- /// A [keyword](#highlight.tags.keyword) that represents a unit.
2668
+ /**
2669
+ A [keyword](#highlight.tags.keyword) that represents a unit.
2670
+ */
2575
2671
  unit: t(keyword),
2576
- /// A modifier [keyword](#highlight.tags.keyword).
2672
+ /**
2673
+ A modifier [keyword](#highlight.tags.keyword).
2674
+ */
2577
2675
  modifier: t(keyword),
2578
- /// A [keyword](#highlight.tags.keyword) that acts as an operator.
2676
+ /**
2677
+ A [keyword](#highlight.tags.keyword) that acts as an operator.
2678
+ */
2579
2679
  operatorKeyword: t(keyword),
2580
- /// A control-flow related [keyword](#highlight.tags.keyword).
2680
+ /**
2681
+ A control-flow related [keyword](#highlight.tags.keyword).
2682
+ */
2581
2683
  controlKeyword: t(keyword),
2582
- /// A [keyword](#highlight.tags.keyword) that defines something.
2684
+ /**
2685
+ A [keyword](#highlight.tags.keyword) that defines something.
2686
+ */
2583
2687
  definitionKeyword: t(keyword),
2584
- /// A [keyword](#highlight.tags.keyword) related to defining or
2585
- /// interfacing with modules.
2688
+ /**
2689
+ A [keyword](#highlight.tags.keyword) related to defining or
2690
+ interfacing with modules.
2691
+ */
2586
2692
  moduleKeyword: t(keyword),
2587
- /// An operator.
2693
+ /**
2694
+ An operator.
2695
+ */
2588
2696
  operator,
2589
- /// An [operator](#highlight.tags.operator) that dereferences something.
2697
+ /**
2698
+ An [operator](#highlight.tags.operator) that dereferences something.
2699
+ */
2590
2700
  derefOperator: t(operator),
2591
- /// Arithmetic-related [operator](#highlight.tags.operator).
2701
+ /**
2702
+ Arithmetic-related [operator](#highlight.tags.operator).
2703
+ */
2592
2704
  arithmeticOperator: t(operator),
2593
- /// Logical [operator](#highlight.tags.operator).
2705
+ /**
2706
+ Logical [operator](#highlight.tags.operator).
2707
+ */
2594
2708
  logicOperator: t(operator),
2595
- /// Bit [operator](#highlight.tags.operator).
2709
+ /**
2710
+ Bit [operator](#highlight.tags.operator).
2711
+ */
2596
2712
  bitwiseOperator: t(operator),
2597
- /// Comparison [operator](#highlight.tags.operator).
2713
+ /**
2714
+ Comparison [operator](#highlight.tags.operator).
2715
+ */
2598
2716
  compareOperator: t(operator),
2599
- /// [Operator](#highlight.tags.operator) that updates its operand.
2717
+ /**
2718
+ [Operator](#highlight.tags.operator) that updates its operand.
2719
+ */
2600
2720
  updateOperator: t(operator),
2601
- /// [Operator](#highlight.tags.operator) that defines something.
2721
+ /**
2722
+ [Operator](#highlight.tags.operator) that defines something.
2723
+ */
2602
2724
  definitionOperator: t(operator),
2603
- /// Type-related [operator](#highlight.tags.operator).
2725
+ /**
2726
+ Type-related [operator](#highlight.tags.operator).
2727
+ */
2604
2728
  typeOperator: t(operator),
2605
- /// Control-flow [operator](#highlight.tags.operator).
2729
+ /**
2730
+ Control-flow [operator](#highlight.tags.operator).
2731
+ */
2606
2732
  controlOperator: t(operator),
2607
- /// Program or markup punctuation.
2733
+ /**
2734
+ Program or markup punctuation.
2735
+ */
2608
2736
  punctuation,
2609
- /// [Punctuation](#highlight.tags.punctuation) that separates
2610
- /// things.
2737
+ /**
2738
+ [Punctuation](#highlight.tags.punctuation) that separates
2739
+ things.
2740
+ */
2611
2741
  separator: t(punctuation),
2612
- /// Bracket-style [punctuation](#highlight.tags.punctuation).
2742
+ /**
2743
+ Bracket-style [punctuation](#highlight.tags.punctuation).
2744
+ */
2613
2745
  bracket,
2614
- /// Angle [brackets](#highlight.tags.bracket) (usually `<` and `>`
2615
- /// tokens).
2746
+ /**
2747
+ Angle [brackets](#highlight.tags.bracket) (usually `<` and `>`
2748
+ tokens).
2749
+ */
2616
2750
  angleBracket: t(bracket),
2617
- /// Square [brackets](#highlight.tags.bracket) (usually `[` and `]`
2618
- /// tokens).
2751
+ /**
2752
+ Square [brackets](#highlight.tags.bracket) (usually `[` and `]`
2753
+ tokens).
2754
+ */
2619
2755
  squareBracket: t(bracket),
2620
- /// Parentheses (usually `(` and `)` tokens). Subtag of
2621
- /// [bracket](#highlight.tags.bracket).
2756
+ /**
2757
+ Parentheses (usually `(` and `)` tokens). Subtag of
2758
+ [bracket](#highlight.tags.bracket).
2759
+ */
2622
2760
  paren: t(bracket),
2623
- /// Braces (usually `{` and `}` tokens). Subtag of
2624
- /// [bracket](#highlight.tags.bracket).
2761
+ /**
2762
+ Braces (usually `{` and `}` tokens). Subtag of
2763
+ [bracket](#highlight.tags.bracket).
2764
+ */
2625
2765
  brace: t(bracket),
2626
- /// Content, for example plain text in XML or markup documents.
2766
+ /**
2767
+ Content, for example plain text in XML or markup documents.
2768
+ */
2627
2769
  content,
2628
- /// [Content](#highlight.tags.content) that represents a heading.
2770
+ /**
2771
+ [Content](#highlight.tags.content) that represents a heading.
2772
+ */
2629
2773
  heading,
2630
- /// A level 1 [heading](#highlight.tags.heading).
2774
+ /**
2775
+ A level 1 [heading](#highlight.tags.heading).
2776
+ */
2631
2777
  heading1: t(heading),
2632
- /// A level 2 [heading](#highlight.tags.heading).
2778
+ /**
2779
+ A level 2 [heading](#highlight.tags.heading).
2780
+ */
2633
2781
  heading2: t(heading),
2634
- /// A level 3 [heading](#highlight.tags.heading).
2782
+ /**
2783
+ A level 3 [heading](#highlight.tags.heading).
2784
+ */
2635
2785
  heading3: t(heading),
2636
- /// A level 4 [heading](#highlight.tags.heading).
2786
+ /**
2787
+ A level 4 [heading](#highlight.tags.heading).
2788
+ */
2637
2789
  heading4: t(heading),
2638
- /// A level 5 [heading](#highlight.tags.heading).
2790
+ /**
2791
+ A level 5 [heading](#highlight.tags.heading).
2792
+ */
2639
2793
  heading5: t(heading),
2640
- /// A level 6 [heading](#highlight.tags.heading).
2794
+ /**
2795
+ A level 6 [heading](#highlight.tags.heading).
2796
+ */
2641
2797
  heading6: t(heading),
2642
- /// A prose separator (such as a horizontal rule).
2798
+ /**
2799
+ A prose separator (such as a horizontal rule).
2800
+ */
2643
2801
  contentSeparator: t(content),
2644
- /// [Content](#highlight.tags.content) that represents a list.
2802
+ /**
2803
+ [Content](#highlight.tags.content) that represents a list.
2804
+ */
2645
2805
  list: t(content),
2646
- /// [Content](#highlight.tags.content) that represents a quote.
2806
+ /**
2807
+ [Content](#highlight.tags.content) that represents a quote.
2808
+ */
2647
2809
  quote: t(content),
2648
- /// [Content](#highlight.tags.content) that is emphasized.
2810
+ /**
2811
+ [Content](#highlight.tags.content) that is emphasized.
2812
+ */
2649
2813
  emphasis: t(content),
2650
- /// [Content](#highlight.tags.content) that is styled strong.
2814
+ /**
2815
+ [Content](#highlight.tags.content) that is styled strong.
2816
+ */
2651
2817
  strong: t(content),
2652
- /// [Content](#highlight.tags.content) that is part of a link.
2818
+ /**
2819
+ [Content](#highlight.tags.content) that is part of a link.
2820
+ */
2653
2821
  link: t(content),
2654
- /// [Content](#highlight.tags.content) that is styled as code or
2655
- /// monospace.
2822
+ /**
2823
+ [Content](#highlight.tags.content) that is styled as code or
2824
+ monospace.
2825
+ */
2656
2826
  monospace: t(content),
2657
- /// [Content](#highlight.tags.content) that has a strike-through
2658
- /// style.
2827
+ /**
2828
+ [Content](#highlight.tags.content) that has a strike-through
2829
+ style.
2830
+ */
2659
2831
  strikethrough: t(content),
2660
- /// Inserted text in a change-tracking format.
2832
+ /**
2833
+ Inserted text in a change-tracking format.
2834
+ */
2661
2835
  inserted: t(),
2662
- /// Deleted text.
2836
+ /**
2837
+ Deleted text.
2838
+ */
2663
2839
  deleted: t(),
2664
- /// Changed text.
2840
+ /**
2841
+ Changed text.
2842
+ */
2665
2843
  changed: t(),
2666
- /// An invalid or unsyntactic element.
2844
+ /**
2845
+ An invalid or unsyntactic element.
2846
+ */
2667
2847
  invalid: t(),
2668
- /// Metadata or meta-instruction.
2848
+ /**
2849
+ Metadata or meta-instruction.
2850
+ */
2669
2851
  meta,
2670
- /// [Metadata](#highlight.tags.meta) that applies to the entire
2671
- /// document.
2852
+ /**
2853
+ [Metadata](#highlight.tags.meta) that applies to the entire
2854
+ document.
2855
+ */
2672
2856
  documentMeta: t(meta),
2673
- /// [Metadata](#highlight.tags.meta) that annotates or adds
2674
- /// attributes to a given syntactic element.
2857
+ /**
2858
+ [Metadata](#highlight.tags.meta) that annotates or adds
2859
+ attributes to a given syntactic element.
2860
+ */
2675
2861
  annotation: t(meta),
2676
- /// Processing instruction or preprocessor directive. Subtag of
2677
- /// [meta](#highlight.tags.meta).
2862
+ /**
2863
+ Processing instruction or preprocessor directive. Subtag of
2864
+ [meta](#highlight.tags.meta).
2865
+ */
2678
2866
  processingInstruction: t(meta),
2679
- /// [Modifier](#highlight.Tag^defineModifier) that indicates that a
2680
- /// given element is being defined. Expected to be used with the
2681
- /// various [name](#highlight.tags.name) tags.
2867
+ /**
2868
+ [Modifier](#highlight.Tag^defineModifier) that indicates that a
2869
+ given element is being defined. Expected to be used with the
2870
+ various [name](#highlight.tags.name) tags.
2871
+ */
2682
2872
  definition: Tag.defineModifier(),
2683
- /// [Modifier](#highlight.Tag^defineModifier) that indicates that
2684
- /// something is constant. Mostly expected to be used with
2685
- /// [variable names](#highlight.tags.variableName).
2873
+ /**
2874
+ [Modifier](#highlight.Tag^defineModifier) that indicates that
2875
+ something is constant. Mostly expected to be used with
2876
+ [variable names](#highlight.tags.variableName).
2877
+ */
2686
2878
  constant: Tag.defineModifier(),
2687
- /// [Modifier](#highlight.Tag^defineModifier) used to indicate that
2688
- /// a [variable](#highlight.tags.variableName) or [property
2689
- /// name](#highlight.tags.propertyName) is being called or defined
2690
- /// as a function.
2879
+ /**
2880
+ [Modifier](#highlight.Tag^defineModifier) used to indicate that
2881
+ a [variable](#highlight.tags.variableName) or [property
2882
+ name](#highlight.tags.propertyName) is being called or defined
2883
+ as a function.
2884
+ */
2691
2885
  function: Tag.defineModifier(),
2692
- /// [Modifier](#highlight.Tag^defineModifier) that can be applied to
2693
- /// [names](#highlight.tags.name) to indicate that they belong to
2694
- /// the language's standard environment.
2886
+ /**
2887
+ [Modifier](#highlight.Tag^defineModifier) that can be applied to
2888
+ [names](#highlight.tags.name) to indicate that they belong to
2889
+ the language's standard environment.
2890
+ */
2695
2891
  standard: Tag.defineModifier(),
2696
- /// [Modifier](#highlight.Tag^defineModifier) that indicates a given
2697
- /// [names](#highlight.tags.name) is local to some scope.
2892
+ /**
2893
+ [Modifier](#highlight.Tag^defineModifier) that indicates a given
2894
+ [names](#highlight.tags.name) is local to some scope.
2895
+ */
2698
2896
  local: Tag.defineModifier(),
2699
- /// A generic variant [modifier](#highlight.Tag^defineModifier) that
2700
- /// can be used to tag language-specific alternative variants of
2701
- /// some common tag. It is recommended for themes to define special
2702
- /// forms of at least the [string](#highlight.tags.string) and
2703
- /// [variable name](#highlight.tags.variableName) tags, since those
2704
- /// come up a lot.
2897
+ /**
2898
+ A generic variant [modifier](#highlight.Tag^defineModifier) that
2899
+ can be used to tag language-specific alternative variants of
2900
+ some common tag. It is recommended for themes to define special
2901
+ forms of at least the [string](#highlight.tags.string) and
2902
+ [variable name](#highlight.tags.variableName) tags, since those
2903
+ come up a lot.
2904
+ */
2705
2905
  special: Tag.defineModifier()
2706
2906
  };
2707
- /// This is a highlighter that adds stable, predictable classes to
2708
- /// tokens, for styling with external CSS.
2709
- ///
2710
- /// The following tags are mapped to their name prefixed with `"tok-"`
2711
- /// (for example `"tok-comment"`):
2712
- ///
2713
- /// * [`link`](#highlight.tags.link)
2714
- /// * [`heading`](#highlight.tags.heading)
2715
- /// * [`emphasis`](#highlight.tags.emphasis)
2716
- /// * [`strong`](#highlight.tags.strong)
2717
- /// * [`keyword`](#highlight.tags.keyword)
2718
- /// * [`atom`](#highlight.tags.atom)
2719
- /// * [`bool`](#highlight.tags.bool)
2720
- /// * [`url`](#highlight.tags.url)
2721
- /// * [`labelName`](#highlight.tags.labelName)
2722
- /// * [`inserted`](#highlight.tags.inserted)
2723
- /// * [`deleted`](#highlight.tags.deleted)
2724
- /// * [`literal`](#highlight.tags.literal)
2725
- /// * [`string`](#highlight.tags.string)
2726
- /// * [`number`](#highlight.tags.number)
2727
- /// * [`variableName`](#highlight.tags.variableName)
2728
- /// * [`typeName`](#highlight.tags.typeName)
2729
- /// * [`namespace`](#highlight.tags.namespace)
2730
- /// * [`className`](#highlight.tags.className)
2731
- /// * [`macroName`](#highlight.tags.macroName)
2732
- /// * [`propertyName`](#highlight.tags.propertyName)
2733
- /// * [`operator`](#highlight.tags.operator)
2734
- /// * [`comment`](#highlight.tags.comment)
2735
- /// * [`meta`](#highlight.tags.meta)
2736
- /// * [`punctuation`](#highlight.tags.punctuation)
2737
- /// * [`invalid`](#highlight.tags.invalid)
2738
- ///
2739
- /// In addition, these mappings are provided:
2740
- ///
2741
- /// * [`regexp`](#highlight.tags.regexp),
2742
- /// [`escape`](#highlight.tags.escape), and
2743
- /// [`special`](#highlight.tags.special)[`(string)`](#highlight.tags.string)
2744
- /// are mapped to `"tok-string2"`
2745
- /// * [`special`](#highlight.tags.special)[`(variableName)`](#highlight.tags.variableName)
2746
- /// to `"tok-variableName2"`
2747
- /// * [`local`](#highlight.tags.local)[`(variableName)`](#highlight.tags.variableName)
2748
- /// to `"tok-variableName tok-local"`
2749
- /// * [`definition`](#highlight.tags.definition)[`(variableName)`](#highlight.tags.variableName)
2750
- /// to `"tok-variableName tok-definition"`
2751
- /// * [`definition`](#highlight.tags.definition)[`(propertyName)`](#highlight.tags.propertyName)
2752
- /// to `"tok-propertyName tok-definition"`
2907
+ /**
2908
+ This is a highlighter that adds stable, predictable classes to
2909
+ tokens, for styling with external CSS.
2910
+
2911
+ The following tags are mapped to their name prefixed with `"tok-"`
2912
+ (for example `"tok-comment"`):
2913
+
2914
+ * [`link`](#highlight.tags.link)
2915
+ * [`heading`](#highlight.tags.heading)
2916
+ * [`emphasis`](#highlight.tags.emphasis)
2917
+ * [`strong`](#highlight.tags.strong)
2918
+ * [`keyword`](#highlight.tags.keyword)
2919
+ * [`atom`](#highlight.tags.atom)
2920
+ * [`bool`](#highlight.tags.bool)
2921
+ * [`url`](#highlight.tags.url)
2922
+ * [`labelName`](#highlight.tags.labelName)
2923
+ * [`inserted`](#highlight.tags.inserted)
2924
+ * [`deleted`](#highlight.tags.deleted)
2925
+ * [`literal`](#highlight.tags.literal)
2926
+ * [`string`](#highlight.tags.string)
2927
+ * [`number`](#highlight.tags.number)
2928
+ * [`variableName`](#highlight.tags.variableName)
2929
+ * [`typeName`](#highlight.tags.typeName)
2930
+ * [`namespace`](#highlight.tags.namespace)
2931
+ * [`className`](#highlight.tags.className)
2932
+ * [`macroName`](#highlight.tags.macroName)
2933
+ * [`propertyName`](#highlight.tags.propertyName)
2934
+ * [`operator`](#highlight.tags.operator)
2935
+ * [`comment`](#highlight.tags.comment)
2936
+ * [`meta`](#highlight.tags.meta)
2937
+ * [`punctuation`](#highlight.tags.punctuation)
2938
+ * [`invalid`](#highlight.tags.invalid)
2939
+
2940
+ In addition, these mappings are provided:
2941
+
2942
+ * [`regexp`](#highlight.tags.regexp),
2943
+ [`escape`](#highlight.tags.escape), and
2944
+ [`special`](#highlight.tags.special)[`(string)`](#highlight.tags.string)
2945
+ are mapped to `"tok-string2"`
2946
+ * [`special`](#highlight.tags.special)[`(variableName)`](#highlight.tags.variableName)
2947
+ to `"tok-variableName2"`
2948
+ * [`local`](#highlight.tags.local)[`(variableName)`](#highlight.tags.variableName)
2949
+ to `"tok-variableName tok-local"`
2950
+ * [`definition`](#highlight.tags.definition)[`(variableName)`](#highlight.tags.variableName)
2951
+ to `"tok-variableName tok-definition"`
2952
+ * [`definition`](#highlight.tags.definition)[`(propertyName)`](#highlight.tags.propertyName)
2953
+ to `"tok-propertyName tok-definition"`
2954
+ */
2753
2955
  const classHighlighter = tagHighlighter([
2754
2956
  { tag: tags.link, class: "tok-link" },
2755
2957
  { tag: tags.heading, class: "tok-heading" },
@@ -2874,11 +3076,11 @@ class StyleSet {
2874
3076
  constructor(root) {
2875
3077
  if (!root.head && root.adoptedStyleSheets && typeof CSSStyleSheet != "undefined") {
2876
3078
  if (adoptedSet) {
2877
- root.adoptedStyleSheets = [adoptedSet.sheet].concat(root.adoptedStyleSheets)
3079
+ root.adoptedStyleSheets = [adoptedSet.sheet, ...root.adoptedStyleSheets]
2878
3080
  return root[SET] = adoptedSet
2879
3081
  }
2880
3082
  this.sheet = new CSSStyleSheet
2881
- root.adoptedStyleSheets = [this.sheet].concat(root.adoptedStyleSheets)
3083
+ root.adoptedStyleSheets = [this.sheet, ...root.adoptedStyleSheets]
2882
3084
  adoptedSet = this
2883
3085
  } else {
2884
3086
  this.styleTag = (root.ownerDocument || root).createElement("style")
@@ -2972,6 +3174,11 @@ function defineLanguageFacet(baseData) {
2972
3174
  });
2973
3175
  }
2974
3176
  /**
3177
+ Syntax node prop used to register sublangauges. Should be added to
3178
+ the top level node type for the language.
3179
+ */
3180
+ const sublanguageProp = /*@__PURE__*/new dist_NodeProp();
3181
+ /**
2975
3182
  A language object manages parsing and per-language
2976
3183
  [metadata](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt). Parse data is
2977
3184
  managed as a [Lezer](https://lezer.codemirror.net) tree. The class
@@ -3008,14 +3215,28 @@ class Language {
3008
3215
  this.parser = parser;
3009
3216
  this.extension = [
3010
3217
  language.of(this),
3011
- state_.EditorState.languageData.of((state, pos, side) => state.facet(languageDataFacetAt(state, pos, side)))
3218
+ state_.EditorState.languageData.of((state, pos, side) => {
3219
+ let top = topNodeAt(state, pos, side), data = top.type.prop(languageDataProp);
3220
+ if (!data)
3221
+ return [];
3222
+ let base = state.facet(data), sub = top.type.prop(sublanguageProp);
3223
+ if (sub) {
3224
+ let innerNode = top.resolve(pos - top.from, side);
3225
+ for (let sublang of sub)
3226
+ if (sublang.test(innerNode, state)) {
3227
+ let data = state.facet(sublang.facet);
3228
+ return sublang.type == "replace" ? data : data.concat(base);
3229
+ }
3230
+ }
3231
+ return base;
3232
+ })
3012
3233
  ].concat(extraExtensions);
3013
3234
  }
3014
3235
  /**
3015
3236
  Query whether this language is active at the given position.
3016
3237
  */
3017
3238
  isActiveAt(state, pos, side = -1) {
3018
- return languageDataFacetAt(state, pos, side) == this.data;
3239
+ return topNodeAt(state, pos, side).type.prop(languageDataProp) == this.data;
3019
3240
  }
3020
3241
  /**
3021
3242
  Find the document regions that were parsed using this language.
@@ -3070,16 +3291,14 @@ class Language {
3070
3291
  @internal
3071
3292
  */
3072
3293
  Language.setState = /*@__PURE__*/state_.StateEffect.define();
3073
- function languageDataFacetAt(state, pos, side) {
3074
- let topLang = state.facet(language);
3075
- if (!topLang)
3076
- return null;
3077
- let facet = topLang.data;
3078
- if (topLang.allowsNesting) {
3079
- for (let node = dist_syntaxTree(state).topNode; node; node = node.enter(pos, side, IterMode.ExcludeBuffers))
3080
- facet = node.type.prop(languageDataProp) || facet;
3294
+ function topNodeAt(state, pos, side) {
3295
+ let topLang = state.facet(language), tree = dist_syntaxTree(state).topNode;
3296
+ if (!topLang || topLang.allowsNesting) {
3297
+ for (let node = tree; node; node = node.enter(pos, side, IterMode.ExcludeBuffers))
3298
+ if (node.type.isTop)
3299
+ tree = node;
3081
3300
  }
3082
- return facet;
3301
+ return tree;
3083
3302
  }
3084
3303
  /**
3085
3304
  A subclass of [`Language`](https://codemirror.net/6/docs/ref/#language.Language) for use with Lezer
@@ -5420,7 +5639,7 @@ Comment or uncomment the current selection. Will use line comments
5420
5639
  if available, otherwise falling back to block comments.
5421
5640
  */
5422
5641
  const toggleComment = target => {
5423
- let config = getConfig(target.state);
5642
+ let { state } = target, line = state.doc.lineAt(state.selection.main.from), config = getConfig(target.state, line.from);
5424
5643
  return config.line ? toggleLineComment(target) : config.block ? toggleBlockCommentByLine(target) : false;
5425
5644
  };
5426
5645
  function command(f, option) {
@@ -5469,7 +5688,7 @@ Comment or uncomment the lines around the current selection using
5469
5688
  block comments.
5470
5689
  */
5471
5690
  const toggleBlockCommentByLine = /*@__PURE__*/command((o, s) => changeBlockComment(o, s, selectedLineRanges(s)), 0 /* CommentOption.Toggle */);
5472
- function getConfig(state, pos = state.selection.main.head) {
5691
+ function getConfig(state, pos) {
5473
5692
  let data = state.languageDataAt("commentTokens", pos);
5474
5693
  return data.length ? data[0] : {};
5475
5694
  }
@@ -5551,13 +5770,13 @@ function changeLineComment(option, state, ranges = state.selection.ranges) {
5551
5770
  let prevLine = -1;
5552
5771
  for (let { from, to } of ranges) {
5553
5772
  let startI = lines.length, minIndent = 1e9;
5773
+ let token = getConfig(state, from).line;
5774
+ if (!token)
5775
+ continue;
5554
5776
  for (let pos = from; pos <= to;) {
5555
5777
  let line = state.doc.lineAt(pos);
5556
5778
  if (line.from > prevLine && (from == to || to > line.from)) {
5557
5779
  prevLine = line.from;
5558
- let token = getConfig(state, pos).line;
5559
- if (!token)
5560
- continue;
5561
5780
  let indent = /^\s*/.exec(line.text)[0].length;
5562
5781
  let empty = indent == line.length;
5563
5782
  let comment = line.text.slice(indent, indent + token.length) == token ? indent : -1;
@@ -6129,21 +6348,41 @@ const cursorLineUp = view => cursorByLine(view, false);
6129
6348
  Move the selection one line down.
6130
6349
  */
6131
6350
  const cursorLineDown = view => cursorByLine(view, true);
6132
- function pageHeight(view) {
6133
- return Math.max(view.defaultLineHeight, Math.min(view.dom.clientHeight, innerHeight) - 5);
6351
+ function pageInfo(view) {
6352
+ let selfScroll = view.scrollDOM.clientHeight < view.scrollDOM.scrollHeight - 2;
6353
+ let marginTop = 0, marginBottom = 0, height;
6354
+ if (selfScroll) {
6355
+ for (let source of view.state.facet(view_.EditorView.scrollMargins)) {
6356
+ let margins = source(view);
6357
+ if (margins === null || margins === void 0 ? void 0 : margins.top)
6358
+ marginTop = Math.max(margins === null || margins === void 0 ? void 0 : margins.top, marginTop);
6359
+ if (margins === null || margins === void 0 ? void 0 : margins.bottom)
6360
+ marginBottom = Math.max(margins === null || margins === void 0 ? void 0 : margins.bottom, marginBottom);
6361
+ }
6362
+ height = view.scrollDOM.clientHeight - marginTop - marginBottom;
6363
+ }
6364
+ else {
6365
+ height = (view.dom.ownerDocument.defaultView || window).innerHeight;
6366
+ }
6367
+ return { marginTop, marginBottom, selfScroll,
6368
+ height: Math.max(view.defaultLineHeight, height - 5) };
6134
6369
  }
6135
6370
  function cursorByPage(view, forward) {
6371
+ let page = pageInfo(view);
6136
6372
  let { state } = view, selection = updateSel(state.selection, range => {
6137
- return range.empty ? view.moveVertically(range, forward, pageHeight(view)) : rangeEnd(range, forward);
6373
+ return range.empty ? view.moveVertically(range, forward, page.height)
6374
+ : rangeEnd(range, forward);
6138
6375
  });
6139
6376
  if (selection.eq(state.selection))
6140
6377
  return false;
6141
- let startPos = view.coordsAtPos(state.selection.main.head);
6142
- let scrollRect = view.scrollDOM.getBoundingClientRect();
6143
6378
  let effect;
6144
- if (startPos && startPos.top > scrollRect.top && startPos.bottom < scrollRect.bottom &&
6145
- startPos.top - scrollRect.top <= view.scrollDOM.scrollHeight - view.scrollDOM.scrollTop - view.scrollDOM.clientHeight)
6146
- effect = view_.EditorView.scrollIntoView(selection.main.head, { y: "start", yMargin: startPos.top - scrollRect.top });
6379
+ if (page.selfScroll) {
6380
+ let startPos = view.coordsAtPos(state.selection.main.head);
6381
+ let scrollRect = view.scrollDOM.getBoundingClientRect();
6382
+ let scrollTop = scrollRect.top + page.marginTop, scrollBottom = scrollRect.bottom - page.marginBottom;
6383
+ if (startPos && startPos.top > scrollTop && startPos.bottom < scrollBottom)
6384
+ effect = view_.EditorView.scrollIntoView(selection.main.head, { y: "start", yMargin: startPos.top - scrollTop });
6385
+ }
6147
6386
  view.dispatch(setSel(state, selection), { effects: effect });
6148
6387
  return true;
6149
6388
  }
@@ -6302,7 +6541,7 @@ Move the selection head one line down.
6302
6541
  */
6303
6542
  const selectLineDown = view => selectByLine(view, true);
6304
6543
  function selectByPage(view, forward) {
6305
- return extendSel(view, range => view.moveVertically(range, forward, pageHeight(view)));
6544
+ return extendSel(view, range => view.moveVertically(range, forward, pageInfo(view).height));
6306
6545
  }
6307
6546
  /**
6308
6547
  Move the selection head one page up.
@@ -7385,9 +7624,6 @@ Supports line numbers, relative line offsets prefixed with `+` or
7385
7624
  `-`, document percentages suffixed with `%`, and an optional
7386
7625
  column position by adding `:` and a second number after the line
7387
7626
  number.
7388
-
7389
- The dialog can be styled with the `panel.gotoLine` theme
7390
- selector.
7391
7627
  */
7392
7628
  const gotoLine = view => {
7393
7629
  let panel = (0,view_.getPanel)(view, createLineDialog);
@@ -7574,7 +7810,8 @@ const searchConfigFacet = /*@__PURE__*/state_.Facet.define({
7574
7810
  caseSensitive: false,
7575
7811
  literal: false,
7576
7812
  wholeWord: false,
7577
- createPanel: view => new SearchPanel(view)
7813
+ createPanel: view => new SearchPanel(view),
7814
+ scrollToMatch: range => view_.EditorView.scrollIntoView(range)
7578
7815
  });
7579
7816
  }
7580
7817
  });
@@ -7855,10 +8092,11 @@ const findNext = /*@__PURE__*/searchCommand((view, { query }) => {
7855
8092
  let next = query.nextMatch(view.state, to, to);
7856
8093
  if (!next)
7857
8094
  return false;
8095
+ let selection = state_.EditorSelection.single(next.from, next.to);
8096
+ let config = view.state.facet(searchConfigFacet);
7858
8097
  view.dispatch({
7859
- selection: { anchor: next.from, head: next.to },
7860
- scrollIntoView: true,
7861
- effects: announceMatch(view, next),
8098
+ selection,
8099
+ effects: [announceMatch(view, next), config.scrollToMatch(selection.main)],
7862
8100
  userEvent: "select.search"
7863
8101
  });
7864
8102
  return true;
@@ -7870,13 +8108,14 @@ of the document to start searching at the end again.
7870
8108
  */
7871
8109
  const findPrevious = /*@__PURE__*/searchCommand((view, { query }) => {
7872
8110
  let { state } = view, { from } = state.selection.main;
7873
- let range = query.prevMatch(state, from, from);
7874
- if (!range)
8111
+ let prev = query.prevMatch(state, from, from);
8112
+ if (!prev)
7875
8113
  return false;
8114
+ let selection = state_.EditorSelection.single(prev.from, prev.to);
8115
+ let config = view.state.facet(searchConfigFacet);
7876
8116
  view.dispatch({
7877
- selection: { anchor: range.from, head: range.to },
7878
- scrollIntoView: true,
7879
- effects: announceMatch(view, range),
8117
+ selection,
8118
+ effects: [announceMatch(view, prev), config.scrollToMatch(selection.main)],
7880
8119
  userEvent: "select.search"
7881
8120
  });
7882
8121
  return true;
@@ -7927,22 +8166,21 @@ const replaceNext = /*@__PURE__*/searchCommand((view, { query }) => {
7927
8166
  if (!next)
7928
8167
  return false;
7929
8168
  let changes = [], selection, replacement;
7930
- let announce = [];
8169
+ let effects = [];
7931
8170
  if (next.from == from && next.to == to) {
7932
8171
  replacement = state.toText(query.getReplacement(next));
7933
8172
  changes.push({ from: next.from, to: next.to, insert: replacement });
7934
8173
  next = query.nextMatch(state, next.from, next.to);
7935
- announce.push(view_.EditorView.announce.of(state.phrase("replaced match on line $", state.doc.lineAt(from).number) + "."));
8174
+ effects.push(view_.EditorView.announce.of(state.phrase("replaced match on line $", state.doc.lineAt(from).number) + "."));
7936
8175
  }
7937
8176
  if (next) {
7938
8177
  let off = changes.length == 0 || changes[0].from >= next.to ? 0 : next.to - next.from - replacement.length;
7939
- selection = { anchor: next.from - off, head: next.to - off };
7940
- announce.push(announceMatch(view, next));
8178
+ selection = state_.EditorSelection.single(next.from - off, next.to - off);
8179
+ effects.push(announceMatch(view, next));
8180
+ effects.push(state.facet(searchConfigFacet).scrollToMatch(selection.main));
7941
8181
  }
7942
8182
  view.dispatch({
7943
- changes, selection,
7944
- scrollIntoView: !!selection,
7945
- effects: announce,
8183
+ changes, selection, effects,
7946
8184
  userEvent: "input.replace"
7947
8185
  });
7948
8186
  return true;
@@ -8333,9 +8571,12 @@ cursor is in a syntax node with one of the given names.
8333
8571
  */
8334
8572
  function ifIn(nodes, source) {
8335
8573
  return (context) => {
8336
- for (let pos = syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent)
8574
+ for (let pos = syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent) {
8337
8575
  if (nodes.indexOf(pos.name) > -1)
8338
8576
  return source(context);
8577
+ if (pos.type.isTop)
8578
+ break;
8579
+ }
8339
8580
  return null;
8340
8581
  };
8341
8582
  }
@@ -8345,9 +8586,12 @@ cursor is in a syntax node with one of the given names.
8345
8586
  */
8346
8587
  function ifNotIn(nodes, source) {
8347
8588
  return (context) => {
8348
- for (let pos = syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent)
8589
+ for (let pos = syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent) {
8349
8590
  if (nodes.indexOf(pos.name) > -1)
8350
8591
  return null;
8592
+ if (pos.type.isTop)
8593
+ break;
8594
+ }
8351
8595
  return source(context);
8352
8596
  };
8353
8597
  }
@@ -8452,13 +8696,18 @@ class FuzzyMatcher {
8452
8696
  // For single-character queries, only match when they occur right
8453
8697
  // at the start
8454
8698
  if (chars.length == 1) {
8455
- let first = (0,state_.codePointAt)(word, 0);
8456
- return first == chars[0] ? [0, 0, (0,state_.codePointSize)(first)]
8457
- : first == folded[0] ? [-200 /* Penalty.CaseFold */, 0, (0,state_.codePointSize)(first)] : null;
8699
+ let first = (0,state_.codePointAt)(word, 0), firstSize = (0,state_.codePointSize)(first);
8700
+ let score = firstSize == word.length ? 0 : -100 /* Penalty.NotFull */;
8701
+ if (first == chars[0]) ;
8702
+ else if (first == folded[0])
8703
+ score += -200 /* Penalty.CaseFold */;
8704
+ else
8705
+ return null;
8706
+ return [score, 0, firstSize];
8458
8707
  }
8459
8708
  let direct = word.indexOf(this.pattern);
8460
8709
  if (direct == 0)
8461
- return [0, 0, this.pattern.length];
8710
+ return [word.length == this.pattern.length ? 0 : -100 /* Penalty.NotFull */, 0, this.pattern.length];
8462
8711
  let len = chars.length, anyTo = 0;
8463
8712
  if (direct < 0) {
8464
8713
  for (let i = 0, e = Math.min(word.length, 200); i < e && anyTo < len;) {
@@ -8514,7 +8763,7 @@ class FuzzyMatcher {
8514
8763
  if (byWordTo == len && byWord[0] == 0 && wordAdjacent)
8515
8764
  return this.result(-100 /* Penalty.ByWord */ + (byWordFolded ? -200 /* Penalty.CaseFold */ : 0), byWord, word);
8516
8765
  if (adjacentTo == len && adjacentStart == 0)
8517
- return [-200 /* Penalty.CaseFold */ - word.length, 0, adjacentEnd];
8766
+ return [-200 /* Penalty.CaseFold */ - word.length + (adjacentEnd == word.length ? 0 : -100 /* Penalty.NotFull */), 0, adjacentEnd];
8518
8767
  if (direct > -1)
8519
8768
  return [-700 /* Penalty.NotStart */ - word.length, direct, direct + this.pattern.length];
8520
8769
  if (adjacentTo == len)
@@ -9577,11 +9826,12 @@ interpreted as indicating a placeholder.
9577
9826
  */
9578
9827
  function snippet(template) {
9579
9828
  let snippet = Snippet.parse(template);
9580
- return (editor, _completion, from, to) => {
9829
+ return (editor, completion, from, to) => {
9581
9830
  let { text, ranges } = snippet.instantiate(editor.state, from);
9582
9831
  let spec = {
9583
9832
  changes: { from, to, insert: Text.of(text) },
9584
- scrollIntoView: true
9833
+ scrollIntoView: true,
9834
+ annotations: pickedCompletion.of(completion)
9585
9835
  };
9586
9836
  if (ranges.length)
9587
9837
  spec.selection = fieldSelection(ranges, 0);
@@ -10300,7 +10550,8 @@ const lintPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
10300
10550
  }
10301
10551
  update(update) {
10302
10552
  let config = update.state.facet(lintConfig);
10303
- if (update.docChanged || config != update.startState.facet(lintConfig)) {
10553
+ if (update.docChanged || config != update.startState.facet(lintConfig) ||
10554
+ config.needsRefresh && config.needsRefresh(update)) {
10304
10555
  this.lintTime = Date.now() + config.delay;
10305
10556
  if (!this.set) {
10306
10557
  this.set = true;
@@ -10323,7 +10574,10 @@ const lintConfig = /*@__PURE__*/state_.Facet.define({
10323
10574
  return Object.assign({ sources: input.map(i => i.source) }, (0,state_.combineConfig)(input.map(i => i.config), {
10324
10575
  delay: 750,
10325
10576
  markerFilter: null,
10326
- tooltipFilter: null
10577
+ tooltipFilter: null,
10578
+ needsRefresh: null
10579
+ }, {
10580
+ needsRefresh: (a, b) => !a ? b : !b ? a : u => a(u) || b(u)
10327
10581
  }));
10328
10582
  },
10329
10583
  enables: lintPlugin
@@ -10364,8 +10618,11 @@ function renderDiagnostic(view, diagnostic, inPanel) {
10364
10618
  var _a;
10365
10619
  let keys = inPanel ? assignKeys(diagnostic.actions) : [];
10366
10620
  return crelt("li", { class: "cm-diagnostic cm-diagnostic-" + diagnostic.severity }, crelt("span", { class: "cm-diagnosticText" }, diagnostic.renderMessage ? diagnostic.renderMessage() : diagnostic.message), (_a = diagnostic.actions) === null || _a === void 0 ? void 0 : _a.map((action, i) => {
10367
- let click = (e) => {
10621
+ let fired = false, click = (e) => {
10368
10622
  e.preventDefault();
10623
+ if (fired)
10624
+ return;
10625
+ fired = true;
10369
10626
  let found = findDiagnostic(view.state.field(lintState).diagnostics, diagnostic);
10370
10627
  if (found)
10371
10628
  action.apply(view, found.from, found.to);
@@ -10592,7 +10849,8 @@ const lint_dist_baseTheme = /*@__PURE__*/view_.EditorView.baseTheme({
10592
10849
  backgroundColor: "#444",
10593
10850
  color: "white",
10594
10851
  borderRadius: "3px",
10595
- marginLeft: "8px"
10852
+ marginLeft: "8px",
10853
+ cursor: "pointer"
10596
10854
  },
10597
10855
  ".cm-diagnosticSource": {
10598
10856
  fontSize: "70%",
@@ -10812,7 +11070,7 @@ function lintGutter(config = {}) {
10812
11070
  /**
10813
11071
  Iterate over the marked diagnostics for the given editor state,
10814
11072
  calling `f` for each of them. Note that, if the document changed
10815
- since the diagnostics werecreated, the `Diagnostic` object will
11073
+ since the diagnostics were created, the `Diagnostic` object will
10816
11074
  hold the original outdated position, whereas the `to` and `from`
10817
11075
  arguments hold the diagnostic's current position.
10818
11076
  */
@@ -10960,7 +11218,7 @@ var External=state_.Annotation.define();function useCodeMirror(props){var value=
10960
11218
  // EXTERNAL MODULE: ../node_modules/react/jsx-runtime.js
10961
11219
  var jsx_runtime = __webpack_require__(605);
10962
11220
  ;// CONCATENATED MODULE: ./src/index.tsx
10963
- var _excluded=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"];var ReactCodeMirror=/*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.forwardRef)(function(props,ref){var className=props.className,_props$value=props.value,value=_props$value===void 0?'':_props$value,selection=props.selection,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,height=props.height,minHeight=props.minHeight,maxHeight=props.maxHeight,width=props.width,minWidth=props.minWidth,maxWidth=props.maxWidth,basicSetup=props.basicSetup,placeholder=props.placeholder,indentWithTab=props.indentWithTab,editable=props.editable,readOnly=props.readOnly,root=props.root,initialState=props.initialState,other=_objectWithoutProperties(props,_excluded);var editor=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);var _useCodeMirror=useCodeMirror({container:editor.current,root:root,value:value,autoFocus:autoFocus,theme:theme,height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth,basicSetup:basicSetup,placeholder:placeholder,indentWithTab:indentWithTab,editable:editable,readOnly:readOnly,selection:selection,onChange:onChange,onStatistics:onStatistics,onCreateEditor:onCreateEditor,onUpdate:onUpdate,extensions:extensions,initialState:initialState}),state=_useCodeMirror.state,view=_useCodeMirror.view,container=_useCodeMirror.container,setContainer=_useCodeMirror.setContainer;(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useImperativeHandle)(ref,function(){return{editor:editor.current,state:state,view:view};},[editor,container,state,view]);// check type of value
11221
+ var _excluded=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"];var ReactCodeMirror=/*#__PURE__*/(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.forwardRef)(function(props,ref){var className=props.className,_props$value=props.value,value=_props$value===void 0?'':_props$value,selection=props.selection,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,height=props.height,minHeight=props.minHeight,maxHeight=props.maxHeight,width=props.width,minWidth=props.minWidth,maxWidth=props.maxWidth,basicSetup=props.basicSetup,placeholder=props.placeholder,indentWithTab=props.indentWithTab,editable=props.editable,readOnly=props.readOnly,root=props.root,initialState=props.initialState,other=_objectWithoutProperties(props,_excluded);var editor=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);var _useCodeMirror=useCodeMirror({container:editor.current,root:root,value:value,autoFocus:autoFocus,theme:theme,height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth,basicSetup:basicSetup,placeholder:placeholder,indentWithTab:indentWithTab,editable:editable,readOnly:readOnly,selection:selection,onChange:onChange,onStatistics:onStatistics,onCreateEditor:onCreateEditor,onUpdate:onUpdate,extensions:extensions,initialState:initialState}),state=_useCodeMirror.state,view=_useCodeMirror.view,container=_useCodeMirror.container;(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useImperativeHandle)(ref,function(){return{editor:editor.current,state:state,view:view};},[editor,container,state,view]);// check type of value
10964
11222
  if(typeof value!=='string'){throw new Error("value must be typeof string but got ".concat(typeof value));}var defaultClassNames=typeof theme==='string'?"cm-theme-".concat(theme):'cm-theme';return/*#__PURE__*/(0,jsx_runtime.jsx)("div",_objectSpread2({ref:editor,className:"".concat(defaultClassNames).concat(className?" ".concat(className):'')},other));});ReactCodeMirror.displayName='CodeMirror';/* harmony default export */ const src = (ReactCodeMirror);
10965
11223
  })();
10966
11224