@codemirror/state 6.2.0 → 6.3.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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 6.3.0 (2023-10-12)
2
+
3
+ ### New features
4
+
5
+ The new `FacetReader` type provides a way to export a read-only handle to a `Facet`.
6
+
7
+ ## 6.2.1 (2023-05-23)
8
+
9
+ ### Bug fixes
10
+
11
+ Fix an issue that could cause `RangeSet.compare` to miss changes in the set of active ranges around a point range.
12
+
1
13
  ## 6.2.0 (2022-12-26)
2
14
 
3
15
  ### New features
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (C) 2018-2021 by Marijn Haverbeke <marijnh@gmail.com> and others
3
+ Copyright (C) 2018-2021 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.cjs CHANGED
@@ -1,15 +1,9 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  /**
6
4
  The data structure for documents. @nonabstract
7
5
  */
8
6
  class Text {
9
- /**
10
- @internal
11
- */
12
- constructor() { }
13
7
  /**
14
8
  Get the line description around the given position.
15
9
  */
@@ -104,7 +98,8 @@ class Text {
104
98
  return new LineCursor(inner);
105
99
  }
106
100
  /**
107
- @internal
101
+ Return the document as a string, using newline characters to
102
+ separate lines.
108
103
  */
109
104
  toString() { return this.sliceString(0); }
110
105
  /**
@@ -117,6 +112,10 @@ class Text {
117
112
  return lines;
118
113
  }
119
114
  /**
115
+ @internal
116
+ */
117
+ constructor() { }
118
+ /**
120
119
  Create a `Text` instance for the given array of lines.
121
120
  */
122
121
  static of(text) {
@@ -1316,12 +1315,12 @@ class SelectionRange {
1316
1315
  The anchor of the range—the side that doesn't move when you
1317
1316
  extend it.
1318
1317
  */
1319
- get anchor() { return this.flags & 16 /* RangeFlag.Inverted */ ? this.to : this.from; }
1318
+ get anchor() { return this.flags & 32 /* RangeFlag.Inverted */ ? this.to : this.from; }
1320
1319
  /**
1321
1320
  The head of the range, which is moved when the range is
1322
1321
  [extended](https://codemirror.net/6/docs/ref/#state.SelectionRange.extend).
1323
1322
  */
1324
- get head() { return this.flags & 16 /* RangeFlag.Inverted */ ? this.from : this.to; }
1323
+ get head() { return this.flags & 32 /* RangeFlag.Inverted */ ? this.from : this.to; }
1325
1324
  /**
1326
1325
  True when `anchor` and `head` are at the same position.
1327
1326
  */
@@ -1332,14 +1331,14 @@ class SelectionRange {
1332
1331
  the character before its position, 1 the character after, and 0
1333
1332
  means no association.
1334
1333
  */
1335
- get assoc() { return this.flags & 4 /* RangeFlag.AssocBefore */ ? -1 : this.flags & 8 /* RangeFlag.AssocAfter */ ? 1 : 0; }
1334
+ get assoc() { return this.flags & 8 /* RangeFlag.AssocBefore */ ? -1 : this.flags & 16 /* RangeFlag.AssocAfter */ ? 1 : 0; }
1336
1335
  /**
1337
1336
  The bidirectional text level associated with this cursor, if
1338
1337
  any.
1339
1338
  */
1340
1339
  get bidiLevel() {
1341
- let level = this.flags & 3 /* RangeFlag.BidiLevelMask */;
1342
- return level == 3 ? null : level;
1340
+ let level = this.flags & 7 /* RangeFlag.BidiLevelMask */;
1341
+ return level == 7 ? null : level;
1343
1342
  }
1344
1343
  /**
1345
1344
  The goal column (stored vertical offset) associated with a
@@ -1348,8 +1347,8 @@ class SelectionRange {
1348
1347
  lines of different length.
1349
1348
  */
1350
1349
  get goalColumn() {
1351
- let value = this.flags >> 5 /* RangeFlag.GoalColumnOffset */;
1352
- return value == 33554431 /* RangeFlag.NoGoalColumn */ ? undefined : value;
1350
+ let value = this.flags >> 6 /* RangeFlag.GoalColumnOffset */;
1351
+ return value == 16777215 /* RangeFlag.NoGoalColumn */ ? undefined : value;
1353
1352
  }
1354
1353
  /**
1355
1354
  Map this range through a change, producing a valid range in the
@@ -1509,18 +1508,18 @@ class EditorSelection {
1509
1508
  safely ignore the optional arguments in most situations.
1510
1509
  */
1511
1510
  static cursor(pos, assoc = 0, bidiLevel, goalColumn) {
1512
- return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 4 /* RangeFlag.AssocBefore */ : 8 /* RangeFlag.AssocAfter */) |
1513
- (bidiLevel == null ? 3 : Math.min(2, bidiLevel)) |
1514
- ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* RangeFlag.NoGoalColumn */) << 5 /* RangeFlag.GoalColumnOffset */));
1511
+ return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 8 /* RangeFlag.AssocBefore */ : 16 /* RangeFlag.AssocAfter */) |
1512
+ (bidiLevel == null ? 7 : Math.min(6, bidiLevel)) |
1513
+ ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215 /* RangeFlag.NoGoalColumn */) << 6 /* RangeFlag.GoalColumnOffset */));
1515
1514
  }
1516
1515
  /**
1517
1516
  Create a selection range.
1518
1517
  */
1519
1518
  static range(anchor, head, goalColumn, bidiLevel) {
1520
- let flags = ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* RangeFlag.NoGoalColumn */) << 5 /* RangeFlag.GoalColumnOffset */) |
1521
- (bidiLevel == null ? 3 : Math.min(2, bidiLevel));
1522
- return head < anchor ? SelectionRange.create(head, anchor, 16 /* RangeFlag.Inverted */ | 8 /* RangeFlag.AssocAfter */ | flags)
1523
- : SelectionRange.create(anchor, head, (head > anchor ? 4 /* RangeFlag.AssocBefore */ : 0) | flags);
1519
+ let flags = ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215 /* RangeFlag.NoGoalColumn */) << 6 /* RangeFlag.GoalColumnOffset */) |
1520
+ (bidiLevel == null ? 7 : Math.min(6, bidiLevel));
1521
+ return head < anchor ? SelectionRange.create(head, anchor, 32 /* RangeFlag.Inverted */ | 16 /* RangeFlag.AssocAfter */ | flags)
1522
+ : SelectionRange.create(anchor, head, (head > anchor ? 8 /* RangeFlag.AssocBefore */ : 0) | flags);
1524
1523
  }
1525
1524
  /**
1526
1525
  @internal
@@ -1557,6 +1556,9 @@ Examples of uses of facets are the [tab
1557
1556
  size](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize), [editor
1558
1557
  attributes](https://codemirror.net/6/docs/ref/#view.EditorView^editorAttributes), and [update
1559
1558
  listeners](https://codemirror.net/6/docs/ref/#view.EditorView^updateListener).
1559
+
1560
+ Note that `Facet` instances can be used anywhere where
1561
+ [`FacetReader`](https://codemirror.net/6/docs/ref/#state.FacetReader) is expected.
1560
1562
  */
1561
1563
  class Facet {
1562
1564
  constructor(
@@ -1584,6 +1586,11 @@ class Facet {
1584
1586
  this.extensions = typeof enables == "function" ? enables(this) : enables;
1585
1587
  }
1586
1588
  /**
1589
+ Returns a facet reader for this facet, which can be used to
1590
+ [read](https://codemirror.net/6/docs/ref/#state.EditorState.facet) it but not to define values for it.
1591
+ */
1592
+ get reader() { return this; }
1593
+ /**
1587
1594
  Define a new facet.
1588
1595
  */
1589
1596
  static define(config = {}) {
@@ -2161,7 +2168,10 @@ class StateEffect {
2161
2168
  is(type) { return this.type == type; }
2162
2169
  /**
2163
2170
  Define a new effect type. The type parameter indicates the type
2164
- of values that his effect holds.
2171
+ of values that his effect holds. It should be a type that
2172
+ doesn't include `undefined`, since that is used in
2173
+ [mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is
2174
+ removed.
2165
2175
  */
2166
2176
  static define(spec = {}) {
2167
2177
  return new StateEffectType(spec.map || (v => v));
@@ -3305,8 +3315,7 @@ class RangeSet {
3305
3315
  static compare(oldSets, newSets,
3306
3316
  /**
3307
3317
  This indicates how the underlying data changed between these
3308
- ranges, and is needed to synchronize the iteration. `from` and
3309
- `to` are coordinates in the _new_ space, after these changes.
3318
+ ranges, and is needed to synchronize the iteration.
3310
3319
  */
3311
3320
  textDiff, comparator,
3312
3321
  /**
@@ -3417,6 +3426,18 @@ A range set builder is a data structure that helps build up a
3417
3426
  an array of [`Range`](https://codemirror.net/6/docs/ref/#state.Range) objects.
3418
3427
  */
3419
3428
  class RangeSetBuilder {
3429
+ finishChunk(newArrays) {
3430
+ this.chunks.push(new Chunk(this.from, this.to, this.value, this.maxPoint));
3431
+ this.chunkPos.push(this.chunkStart);
3432
+ this.chunkStart = -1;
3433
+ this.setMaxPoint = Math.max(this.setMaxPoint, this.maxPoint);
3434
+ this.maxPoint = -1;
3435
+ if (newArrays) {
3436
+ this.from = [];
3437
+ this.to = [];
3438
+ this.value = [];
3439
+ }
3440
+ }
3420
3441
  /**
3421
3442
  Create an empty builder.
3422
3443
  */
@@ -3434,18 +3455,6 @@ class RangeSetBuilder {
3434
3455
  this.setMaxPoint = -1;
3435
3456
  this.nextLayer = null;
3436
3457
  }
3437
- finishChunk(newArrays) {
3438
- this.chunks.push(new Chunk(this.from, this.to, this.value, this.maxPoint));
3439
- this.chunkPos.push(this.chunkStart);
3440
- this.chunkStart = -1;
3441
- this.setMaxPoint = Math.max(this.setMaxPoint, this.maxPoint);
3442
- this.maxPoint = -1;
3443
- if (newArrays) {
3444
- this.from = [];
3445
- this.to = [];
3446
- this.value = [];
3447
- }
3448
- }
3449
3458
  /**
3450
3459
  Add a range. Ranges should be added in sorted (by `from` and
3451
3460
  `value.startSide`) order.
@@ -3805,7 +3814,7 @@ function compare(a, startA, b, startB, length, comparator) {
3805
3814
  let end = diff < 0 ? a.to + dPos : b.to, clipEnd = Math.min(end, endB);
3806
3815
  if (a.point || b.point) {
3807
3816
  if (!(a.point && b.point && (a.point == b.point || a.point.eq(b.point)) &&
3808
- sameValues(a.activeForPoint(a.to + dPos), b.activeForPoint(b.to))))
3817
+ sameValues(a.activeForPoint(a.to), b.activeForPoint(b.to))))
3809
3818
  comparator.comparePoint(pos, clipEnd, a.point, b.point);
3810
3819
  }
3811
3820
  else {