@codemirror/state 6.2.1 → 6.3.1

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/index.d.ts CHANGED
@@ -528,11 +528,19 @@ Examples of uses of facets are the [tab
528
528
  size](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize), [editor
529
529
  attributes](https://codemirror.net/6/docs/ref/#view.EditorView^editorAttributes), and [update
530
530
  listeners](https://codemirror.net/6/docs/ref/#view.EditorView^updateListener).
531
+
532
+ Note that `Facet` instances can be used anywhere where
533
+ [`FacetReader`](https://codemirror.net/6/docs/ref/#state.FacetReader) is expected.
531
534
  */
532
- declare class Facet<Input, Output = readonly Input[]> {
535
+ declare class Facet<Input, Output = readonly Input[]> implements FacetReader<Output> {
533
536
  private isStatic;
534
537
  private constructor();
535
538
  /**
539
+ Returns a facet reader for this facet, which can be used to
540
+ [read](https://codemirror.net/6/docs/ref/#state.EditorState.facet) it but not to define values for it.
541
+ */
542
+ get reader(): FacetReader<Output>;
543
+ /**
536
544
  Define a new facet.
537
545
  */
538
546
  static define<Input, Output = readonly Input[]>(config?: FacetConfig<Input, Output>): Facet<Input, Output>;
@@ -563,8 +571,23 @@ declare class Facet<Input, Output = readonly Input[]> {
563
571
  */
564
572
  from<T extends Input>(field: StateField<T>): Extension;
565
573
  from<T>(field: StateField<T>, get: (value: T) => Input): Extension;
574
+ tag: Output;
566
575
  }
567
- type Slot<T> = Facet<any, T> | StateField<T> | "doc" | "selection";
576
+ /**
577
+ A facet reader can be used to fetch the value of a facet, though
578
+ [`EditorState.facet`](https://codemirror.net/6/docs/ref/#state.EditorState.facet) or as a dependency
579
+ in [`Facet.compute`](https://codemirror.net/6/docs/ref/#state.Facet.compute), but not to define new
580
+ values for the facet.
581
+ */
582
+ type FacetReader<Output> = {
583
+ /**
584
+ Dummy tag that makes sure TypeScript doesn't consider all object
585
+ types as conforming to this type. Not actually present on the
586
+ object.
587
+ */
588
+ tag: Output;
589
+ };
590
+ type Slot<T> = FacetReader<T> | StateField<T> | "doc" | "selection";
568
591
  type StateFieldSpec<Value> = {
569
592
  /**
570
593
  Creates the initial value for the field when a state is created.
@@ -1123,7 +1146,7 @@ declare class EditorState {
1123
1146
  /**
1124
1147
  Get the value of a state [facet](https://codemirror.net/6/docs/ref/#state.Facet).
1125
1148
  */
1126
- facet<Output>(facet: Facet<any, Output>): Output;
1149
+ facet<Output>(facet: FacetReader<Output>): Output;
1127
1150
  /**
1128
1151
  Convert this state to a JSON-serializable object. When custom
1129
1152
  fields should be serialized, you can pass them in as an object
@@ -1660,4 +1683,4 @@ situation.
1660
1683
  */
1661
1684
  declare function findColumn(string: string, col: number, tabSize: number, strict?: boolean): number;
1662
1685
 
1663
- export { Annotation, AnnotationType, ChangeDesc, ChangeSet, ChangeSpec, CharCategory, Compartment, EditorSelection, EditorState, EditorStateConfig, Extension, Facet, Line, MapMode, Prec, Range, RangeComparator, RangeCursor, RangeSet, RangeSetBuilder, RangeValue, SelectionRange, SpanIterator, StateCommand, StateEffect, StateEffectType, StateField, Text, TextIterator, Transaction, TransactionSpec, codePointAt, codePointSize, combineConfig, countColumn, findClusterBreak, findColumn, fromCodePoint };
1686
+ export { Annotation, AnnotationType, ChangeDesc, ChangeSet, ChangeSpec, CharCategory, Compartment, EditorSelection, EditorState, EditorStateConfig, Extension, Facet, FacetReader, Line, MapMode, Prec, Range, RangeComparator, RangeCursor, RangeSet, RangeSetBuilder, RangeValue, SelectionRange, SpanIterator, StateCommand, StateEffect, StateEffectType, StateField, Text, TextIterator, Transaction, TransactionSpec, codePointAt, codePointSize, combineConfig, countColumn, findClusterBreak, findColumn, fromCodePoint };
package/dist/index.js CHANGED
@@ -1312,12 +1312,12 @@ class SelectionRange {
1312
1312
  The anchor of the range—the side that doesn't move when you
1313
1313
  extend it.
1314
1314
  */
1315
- get anchor() { return this.flags & 16 /* RangeFlag.Inverted */ ? this.to : this.from; }
1315
+ get anchor() { return this.flags & 32 /* RangeFlag.Inverted */ ? this.to : this.from; }
1316
1316
  /**
1317
1317
  The head of the range, which is moved when the range is
1318
1318
  [extended](https://codemirror.net/6/docs/ref/#state.SelectionRange.extend).
1319
1319
  */
1320
- get head() { return this.flags & 16 /* RangeFlag.Inverted */ ? this.from : this.to; }
1320
+ get head() { return this.flags & 32 /* RangeFlag.Inverted */ ? this.from : this.to; }
1321
1321
  /**
1322
1322
  True when `anchor` and `head` are at the same position.
1323
1323
  */
@@ -1328,14 +1328,14 @@ class SelectionRange {
1328
1328
  the character before its position, 1 the character after, and 0
1329
1329
  means no association.
1330
1330
  */
1331
- get assoc() { return this.flags & 4 /* RangeFlag.AssocBefore */ ? -1 : this.flags & 8 /* RangeFlag.AssocAfter */ ? 1 : 0; }
1331
+ get assoc() { return this.flags & 8 /* RangeFlag.AssocBefore */ ? -1 : this.flags & 16 /* RangeFlag.AssocAfter */ ? 1 : 0; }
1332
1332
  /**
1333
1333
  The bidirectional text level associated with this cursor, if
1334
1334
  any.
1335
1335
  */
1336
1336
  get bidiLevel() {
1337
- let level = this.flags & 3 /* RangeFlag.BidiLevelMask */;
1338
- return level == 3 ? null : level;
1337
+ let level = this.flags & 7 /* RangeFlag.BidiLevelMask */;
1338
+ return level == 7 ? null : level;
1339
1339
  }
1340
1340
  /**
1341
1341
  The goal column (stored vertical offset) associated with a
@@ -1344,8 +1344,8 @@ class SelectionRange {
1344
1344
  lines of different length.
1345
1345
  */
1346
1346
  get goalColumn() {
1347
- let value = this.flags >> 5 /* RangeFlag.GoalColumnOffset */;
1348
- return value == 33554431 /* RangeFlag.NoGoalColumn */ ? undefined : value;
1347
+ let value = this.flags >> 6 /* RangeFlag.GoalColumnOffset */;
1348
+ return value == 16777215 /* RangeFlag.NoGoalColumn */ ? undefined : value;
1349
1349
  }
1350
1350
  /**
1351
1351
  Map this range through a change, producing a valid range in the
@@ -1505,18 +1505,18 @@ class EditorSelection {
1505
1505
  safely ignore the optional arguments in most situations.
1506
1506
  */
1507
1507
  static cursor(pos, assoc = 0, bidiLevel, goalColumn) {
1508
- return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 4 /* RangeFlag.AssocBefore */ : 8 /* RangeFlag.AssocAfter */) |
1509
- (bidiLevel == null ? 3 : Math.min(2, bidiLevel)) |
1510
- ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* RangeFlag.NoGoalColumn */) << 5 /* RangeFlag.GoalColumnOffset */));
1508
+ return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 8 /* RangeFlag.AssocBefore */ : 16 /* RangeFlag.AssocAfter */) |
1509
+ (bidiLevel == null ? 7 : Math.min(6, bidiLevel)) |
1510
+ ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215 /* RangeFlag.NoGoalColumn */) << 6 /* RangeFlag.GoalColumnOffset */));
1511
1511
  }
1512
1512
  /**
1513
1513
  Create a selection range.
1514
1514
  */
1515
1515
  static range(anchor, head, goalColumn, bidiLevel) {
1516
- let flags = ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* RangeFlag.NoGoalColumn */) << 5 /* RangeFlag.GoalColumnOffset */) |
1517
- (bidiLevel == null ? 3 : Math.min(2, bidiLevel));
1518
- return head < anchor ? SelectionRange.create(head, anchor, 16 /* RangeFlag.Inverted */ | 8 /* RangeFlag.AssocAfter */ | flags)
1519
- : SelectionRange.create(anchor, head, (head > anchor ? 4 /* RangeFlag.AssocBefore */ : 0) | flags);
1516
+ let flags = ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215 /* RangeFlag.NoGoalColumn */) << 6 /* RangeFlag.GoalColumnOffset */) |
1517
+ (bidiLevel == null ? 7 : Math.min(6, bidiLevel));
1518
+ return head < anchor ? SelectionRange.create(head, anchor, 32 /* RangeFlag.Inverted */ | 16 /* RangeFlag.AssocAfter */ | flags)
1519
+ : SelectionRange.create(anchor, head, (head > anchor ? 8 /* RangeFlag.AssocBefore */ : 0) | flags);
1520
1520
  }
1521
1521
  /**
1522
1522
  @internal
@@ -1553,6 +1553,9 @@ Examples of uses of facets are the [tab
1553
1553
  size](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize), [editor
1554
1554
  attributes](https://codemirror.net/6/docs/ref/#view.EditorView^editorAttributes), and [update
1555
1555
  listeners](https://codemirror.net/6/docs/ref/#view.EditorView^updateListener).
1556
+
1557
+ Note that `Facet` instances can be used anywhere where
1558
+ [`FacetReader`](https://codemirror.net/6/docs/ref/#state.FacetReader) is expected.
1556
1559
  */
1557
1560
  class Facet {
1558
1561
  constructor(
@@ -1580,6 +1583,11 @@ class Facet {
1580
1583
  this.extensions = typeof enables == "function" ? enables(this) : enables;
1581
1584
  }
1582
1585
  /**
1586
+ Returns a facet reader for this facet, which can be used to
1587
+ [read](https://codemirror.net/6/docs/ref/#state.EditorState.facet) it but not to define values for it.
1588
+ */
1589
+ get reader() { return this; }
1590
+ /**
1583
1591
  Define a new facet.
1584
1592
  */
1585
1593
  static define(config = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/state",
3
- "version": "6.2.1",
3
+ "version": "6.3.1",
4
4
  "description": "Editor state data structures for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",
@@ -26,7 +26,7 @@
26
26
  "sideEffects": false,
27
27
  "license": "MIT",
28
28
  "devDependencies": {
29
- "@codemirror/buildhelper": "^0.1.5"
29
+ "@codemirror/buildhelper": "^1.0.0"
30
30
  },
31
31
  "repository": {
32
32
  "type": "git",