File size: 65,198 Bytes
bc20498 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 |
/**
A text iterator iterates over a sequence of strings. When
iterating over a [`Text`](https://codemirror.net/6/docs/ref/#state.Text) document, result values will
either be lines or line breaks.
*/
interface TextIterator extends Iterator<string>, Iterable<string> {
/**
Retrieve the next string. Optionally skip a given number of
positions after the current position. Always returns the object
itself.
*/
next(skip?: number): this;
/**
The current string. Will be the empty string when the cursor is
at its end or `next` hasn't been called on it yet.
*/
value: string;
/**
Whether the end of the iteration has been reached. You should
probably check this right after calling `next`.
*/
done: boolean;
/**
Whether the current string represents a line break.
*/
lineBreak: boolean;
}
/**
The data structure for documents. @nonabstract
*/
declare abstract class Text implements Iterable<string> {
/**
The length of the string.
*/
abstract readonly length: number;
/**
The number of lines in the string (always >= 1).
*/
abstract readonly lines: number;
/**
Get the line description around the given position.
*/
lineAt(pos: number): Line;
/**
Get the description for the given (1-based) line number.
*/
line(n: number): Line;
/**
Replace a range of the text with the given content.
*/
replace(from: number, to: number, text: Text): Text;
/**
Append another document to this one.
*/
append(other: Text): Text;
/**
Retrieve the text between the given points.
*/
slice(from: number, to?: number): Text;
/**
Retrieve a part of the document as a string
*/
abstract sliceString(from: number, to?: number, lineSep?: string): string;
/**
Test whether this text is equal to another instance.
*/
eq(other: Text): boolean;
/**
Iterate over the text. When `dir` is `-1`, iteration happens
from end to start. This will return lines and the breaks between
them as separate strings.
*/
iter(dir?: 1 | -1): TextIterator;
/**
Iterate over a range of the text. When `from` > `to`, the
iterator will run in reverse.
*/
iterRange(from: number, to?: number): TextIterator;
/**
Return a cursor that iterates over the given range of lines,
_without_ returning the line breaks between, and yielding empty
strings for empty lines.
When `from` and `to` are given, they should be 1-based line numbers.
*/
iterLines(from?: number, to?: number): TextIterator;
/**
Return the document as a string, using newline characters to
separate lines.
*/
toString(): string;
/**
Convert the document to an array of lines (which can be
deserialized again via [`Text.of`](https://codemirror.net/6/docs/ref/#state.Text^of)).
*/
toJSON(): string[];
/**
If this is a branch node, `children` will hold the `Text`
objects that it is made up of. For leaf nodes, this holds null.
*/
abstract readonly children: readonly Text[] | null;
[Symbol.iterator]: () => Iterator<string>;
/**
Create a `Text` instance for the given array of lines.
*/
static of(text: readonly string[]): Text;
/**
The empty document.
*/
static empty: Text;
}
/**
This type describes a line in the document. It is created
on-demand when lines are [queried](https://codemirror.net/6/docs/ref/#state.Text.lineAt).
*/
declare class Line {
/**
The position of the start of the line.
*/
readonly from: number;
/**
The position at the end of the line (_before_ the line break,
or at the end of document for the last line).
*/
readonly to: number;
/**
This line's line number (1-based).
*/
readonly number: number;
/**
The line's content.
*/
readonly text: string;
/**
The length of the line (not including any line break after it).
*/
get length(): number;
}
/**
Distinguishes different ways in which positions can be mapped.
*/
declare enum MapMode {
/**
Map a position to a valid new position, even when its context
was deleted.
*/
Simple = 0,
/**
Return null if deletion happens across the position.
*/
TrackDel = 1,
/**
Return null if the character _before_ the position is deleted.
*/
TrackBefore = 2,
/**
Return null if the character _after_ the position is deleted.
*/
TrackAfter = 3
}
/**
A change description is a variant of [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet)
that doesn't store the inserted text. As such, it can't be
applied, but is cheaper to store and manipulate.
*/
declare class ChangeDesc {
/**
The length of the document before the change.
*/
get length(): number;
/**
The length of the document after the change.
*/
get newLength(): number;
/**
False when there are actual changes in this set.
*/
get empty(): boolean;
/**
Iterate over the unchanged parts left by these changes. `posA`
provides the position of the range in the old document, `posB`
the new position in the changed document.
*/
iterGaps(f: (posA: number, posB: number, length: number) => void): void;
/**
Iterate over the ranges changed by these changes. (See
[`ChangeSet.iterChanges`](https://codemirror.net/6/docs/ref/#state.ChangeSet.iterChanges) for a
variant that also provides you with the inserted text.)
`fromA`/`toA` provides the extent of the change in the starting
document, `fromB`/`toB` the extent of the replacement in the
changed document.
When `individual` is true, adjacent changes (which are kept
separate for [position mapping](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) are
reported separately.
*/
iterChangedRanges(f: (fromA: number, toA: number, fromB: number, toB: number) => void, individual?: boolean): void;
/**
Get a description of the inverted form of these changes.
*/
get invertedDesc(): ChangeDesc;
/**
Compute the combined effect of applying another set of changes
after this one. The length of the document after this set should
match the length before `other`.
*/
composeDesc(other: ChangeDesc): ChangeDesc;
/**
Map this description, which should start with the same document
as `other`, over another set of changes, so that it can be
applied after it. When `before` is true, map as if the changes
in `other` happened before the ones in `this`.
*/
mapDesc(other: ChangeDesc, before?: boolean): ChangeDesc;
/**
Map a given position through these changes, to produce a
position pointing into the new document.
`assoc` indicates which side the position should be associated
with. When it is negative or zero, the mapping will try to keep
the position close to the character before it (if any), and will
move it before insertions at that point or replacements across
that point. When it is positive, the position is associated with
the character after it, and will be moved forward for insertions
at or replacements across the position. Defaults to -1.
`mode` determines whether deletions should be
[reported](https://codemirror.net/6/docs/ref/#state.MapMode). It defaults to
[`MapMode.Simple`](https://codemirror.net/6/docs/ref/#state.MapMode.Simple) (don't report
deletions).
*/
mapPos(pos: number, assoc?: number): number;
mapPos(pos: number, assoc: number, mode: MapMode): number | null;
/**
Check whether these changes touch a given range. When one of the
changes entirely covers the range, the string `"cover"` is
returned.
*/
touchesRange(from: number, to?: number): boolean | "cover";
/**
Serialize this change desc to a JSON-representable value.
*/
toJSON(): readonly number[];
/**
Create a change desc from its JSON representation (as produced
by [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeDesc.toJSON).
*/
static fromJSON(json: any): ChangeDesc;
}
/**
This type is used as argument to
[`EditorState.changes`](https://codemirror.net/6/docs/ref/#state.EditorState.changes) and in the
[`changes` field](https://codemirror.net/6/docs/ref/#state.TransactionSpec.changes) of transaction
specs to succinctly describe document changes. It may either be a
plain object describing a change (a deletion, insertion, or
replacement, depending on which fields are present), a [change
set](https://codemirror.net/6/docs/ref/#state.ChangeSet), or an array of change specs.
*/
type ChangeSpec = {
from: number;
to?: number;
insert?: string | Text;
} | ChangeSet | readonly ChangeSpec[];
/**
A change set represents a group of modifications to a document. It
stores the document length, and can only be applied to documents
with exactly that length.
*/
declare class ChangeSet extends ChangeDesc {
private constructor();
/**
Apply the changes to a document, returning the modified
document.
*/
apply(doc: Text): Text;
mapDesc(other: ChangeDesc, before?: boolean): ChangeDesc;
/**
Given the document as it existed _before_ the changes, return a
change set that represents the inverse of this set, which could
be used to go from the document created by the changes back to
the document as it existed before the changes.
*/
invert(doc: Text): ChangeSet;
/**
Combine two subsequent change sets into a single set. `other`
must start in the document produced by `this`. If `this` goes
`docA` → `docB` and `other` represents `docB` → `docC`, the
returned value will represent the change `docA` → `docC`.
*/
compose(other: ChangeSet): ChangeSet;
/**
Given another change set starting in the same document, maps this
change set over the other, producing a new change set that can be
applied to the document produced by applying `other`. When
`before` is `true`, order changes as if `this` comes before
`other`, otherwise (the default) treat `other` as coming first.
Given two changes `A` and `B`, `A.compose(B.map(A))` and
`B.compose(A.map(B, true))` will produce the same document. This
provides a basic form of [operational
transformation](https://en.wikipedia.org/wiki/Operational_transformation),
and can be used for collaborative editing.
*/
map(other: ChangeDesc, before?: boolean): ChangeSet;
/**
Iterate over the changed ranges in the document, calling `f` for
each, with the range in the original document (`fromA`-`toA`)
and the range that replaces it in the new document
(`fromB`-`toB`).
When `individual` is true, adjacent changes are reported
separately.
*/
iterChanges(f: (fromA: number, toA: number, fromB: number, toB: number, inserted: Text) => void, individual?: boolean): void;
/**
Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change
set.
*/
get desc(): ChangeDesc;
/**
Serialize this change set to a JSON-representable value.
*/
toJSON(): any;
/**
Create a change set for the given changes, for a document of the
given length, using `lineSep` as line separator.
*/
static of(changes: ChangeSpec, length: number, lineSep?: string): ChangeSet;
/**
Create an empty changeset of the given length.
*/
static empty(length: number): ChangeSet;
/**
Create a changeset from its JSON representation (as produced by
[`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeSet.toJSON).
*/
static fromJSON(json: any): ChangeSet;
}
/**
A single selection range. When
[`allowMultipleSelections`](https://codemirror.net/6/docs/ref/#state.EditorState^allowMultipleSelections)
is enabled, a [selection](https://codemirror.net/6/docs/ref/#state.EditorSelection) may hold
multiple ranges. By default, selections hold exactly one range.
*/
declare class SelectionRange {
/**
The lower boundary of the range.
*/
readonly from: number;
/**
The upper boundary of the range.
*/
readonly to: number;
private flags;
private constructor();
/**
The anchor of the range—the side that doesn't move when you
extend it.
*/
get anchor(): number;
/**
The head of the range, which is moved when the range is
[extended](https://codemirror.net/6/docs/ref/#state.SelectionRange.extend).
*/
get head(): number;
/**
True when `anchor` and `head` are at the same position.
*/
get empty(): boolean;
/**
If this is a cursor that is explicitly associated with the
character on one of its sides, this returns the side. -1 means
the character before its position, 1 the character after, and 0
means no association.
*/
get assoc(): -1 | 0 | 1;
/**
The bidirectional text level associated with this cursor, if
any.
*/
get bidiLevel(): number | null;
/**
The goal column (stored vertical offset) associated with a
cursor. This is used to preserve the vertical position when
[moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
lines of different length.
*/
get goalColumn(): number | undefined;
/**
Map this range through a change, producing a valid range in the
updated document.
*/
map(change: ChangeDesc, assoc?: number): SelectionRange;
/**
Extend this range to cover at least `from` to `to`.
*/
extend(from: number, to?: number): SelectionRange;
/**
Compare this range to another range.
*/
eq(other: SelectionRange, includeAssoc?: boolean): boolean;
/**
Return a JSON-serializable object representing the range.
*/
toJSON(): any;
/**
Convert a JSON representation of a range to a `SelectionRange`
instance.
*/
static fromJSON(json: any): SelectionRange;
}
/**
An editor selection holds one or more selection ranges.
*/
declare class EditorSelection {
/**
The ranges in the selection, sorted by position. Ranges cannot
overlap (but they may touch, if they aren't empty).
*/
readonly ranges: readonly SelectionRange[];
/**
The index of the _main_ range in the selection (which is
usually the range that was added last).
*/
readonly mainIndex: number;
private constructor();
/**
Map a selection through a change. Used to adjust the selection
position for changes.
*/
map(change: ChangeDesc, assoc?: number): EditorSelection;
/**
Compare this selection to another selection. By default, ranges
are compared only by position. When `includeAssoc` is true,
cursor ranges must also have the same
[`assoc`](https://codemirror.net/6/docs/ref/#state.SelectionRange.assoc) value.
*/
eq(other: EditorSelection, includeAssoc?: boolean): boolean;
/**
Get the primary selection range. Usually, you should make sure
your code applies to _all_ ranges, by using methods like
[`changeByRange`](https://codemirror.net/6/docs/ref/#state.EditorState.changeByRange).
*/
get main(): SelectionRange;
/**
Make sure the selection only has one range. Returns a selection
holding only the main range from this selection.
*/
asSingle(): EditorSelection;
/**
Extend this selection with an extra range.
*/
addRange(range: SelectionRange, main?: boolean): EditorSelection;
/**
Replace a given range with another range, and then normalize the
selection to merge and sort ranges if necessary.
*/
replaceRange(range: SelectionRange, which?: number): EditorSelection;
/**
Convert this selection to an object that can be serialized to
JSON.
*/
toJSON(): any;
/**
Create a selection from a JSON representation.
*/
static fromJSON(json: any): EditorSelection;
/**
Create a selection holding a single range.
*/
static single(anchor: number, head?: number): EditorSelection;
/**
Sort and merge the given set of ranges, creating a valid
selection.
*/
static create(ranges: readonly SelectionRange[], mainIndex?: number): EditorSelection;
/**
Create a cursor selection range at the given position. You can
safely ignore the optional arguments in most situations.
*/
static cursor(pos: number, assoc?: number, bidiLevel?: number, goalColumn?: number): SelectionRange;
/**
Create a selection range.
*/
static range(anchor: number, head: number, goalColumn?: number, bidiLevel?: number): SelectionRange;
}
type FacetConfig<Input, Output> = {
/**
How to combine the input values into a single output value. When
not given, the array of input values becomes the output. This
function will immediately be called on creating the facet, with
an empty array, to compute the facet's default value when no
inputs are present.
*/
combine?: (value: readonly Input[]) => Output;
/**
How to compare output values to determine whether the value of
the facet changed. Defaults to comparing by `===` or, if no
`combine` function was given, comparing each element of the
array with `===`.
*/
compare?: (a: Output, b: Output) => boolean;
/**
How to compare input values to avoid recomputing the output
value when no inputs changed. Defaults to comparing with `===`.
*/
compareInput?: (a: Input, b: Input) => boolean;
/**
Forbids dynamic inputs to this facet.
*/
static?: boolean;
/**
If given, these extension(s) (or the result of calling the given
function with the facet) will be added to any state where this
facet is provided. (Note that, while a facet's default value can
be read from a state even if the facet wasn't present in the
state at all, these extensions won't be added in that
situation.)
*/
enables?: Extension | ((self: Facet<Input, Output>) => Extension);
};
/**
A facet is a labeled value that is associated with an editor
state. It takes inputs from any number of extensions, and combines
those into a single output value.
Examples of uses of facets are the [tab
size](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize), [editor
attributes](https://codemirror.net/6/docs/ref/#view.EditorView^editorAttributes), and [update
listeners](https://codemirror.net/6/docs/ref/#view.EditorView^updateListener).
Note that `Facet` instances can be used anywhere where
[`FacetReader`](https://codemirror.net/6/docs/ref/#state.FacetReader) is expected.
*/
declare class Facet<Input, Output = readonly Input[]> implements FacetReader<Output> {
private isStatic;
private constructor();
/**
Returns a facet reader for this facet, which can be used to
[read](https://codemirror.net/6/docs/ref/#state.EditorState.facet) it but not to define values for it.
*/
get reader(): FacetReader<Output>;
/**
Define a new facet.
*/
static define<Input, Output = readonly Input[]>(config?: FacetConfig<Input, Output>): Facet<Input, Output>;
/**
Returns an extension that adds the given value to this facet.
*/
of(value: Input): Extension;
/**
Create an extension that computes a value for the facet from a
state. You must take care to declare the parts of the state that
this value depends on, since your function is only called again
for a new state when one of those parts changed.
In cases where your value depends only on a single field, you'll
want to use the [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method instead.
*/
compute(deps: readonly Slot<any>[], get: (state: EditorState) => Input): Extension;
/**
Create an extension that computes zero or more values for this
facet from a state.
*/
computeN(deps: readonly Slot<any>[], get: (state: EditorState) => readonly Input[]): Extension;
/**
Shorthand method for registering a facet source with a state
field as input. If the field's type corresponds to this facet's
input type, the getter function can be omitted. If given, it
will be used to retrieve the input from the field value.
*/
from<T extends Input>(field: StateField<T>): Extension;
from<T>(field: StateField<T>, get: (value: T) => Input): Extension;
tag: Output;
}
/**
A facet reader can be used to fetch the value of a facet, through
[`EditorState.facet`](https://codemirror.net/6/docs/ref/#state.EditorState.facet) or as a dependency
in [`Facet.compute`](https://codemirror.net/6/docs/ref/#state.Facet.compute), but not to define new
values for the facet.
*/
type FacetReader<Output> = {
/**
Dummy tag that makes sure TypeScript doesn't consider all object
types as conforming to this type. Not actually present on the
object.
*/
tag: Output;
};
type Slot<T> = FacetReader<T> | StateField<T> | "doc" | "selection";
type StateFieldSpec<Value> = {
/**
Creates the initial value for the field when a state is created.
*/
create: (state: EditorState) => Value;
/**
Compute a new value from the field's previous value and a
[transaction](https://codemirror.net/6/docs/ref/#state.Transaction).
*/
update: (value: Value, transaction: Transaction) => Value;
/**
Compare two values of the field, returning `true` when they are
the same. This is used to avoid recomputing facets that depend
on the field when its value did not change. Defaults to using
`===`.
*/
compare?: (a: Value, b: Value) => boolean;
/**
Provide extensions based on this field. The given function will
be called once with the initialized field. It will usually want
to call some facet's [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method to
create facet inputs from this field, but can also return other
extensions that should be enabled when the field is present in a
configuration.
*/
provide?: (field: StateField<Value>) => Extension;
/**
A function used to serialize this field's content to JSON. Only
necessary when this field is included in the argument to
[`EditorState.toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON).
*/
toJSON?: (value: Value, state: EditorState) => any;
/**
A function that deserializes the JSON representation of this
field's content.
*/
fromJSON?: (json: any, state: EditorState) => Value;
};
/**
Fields can store additional information in an editor state, and
keep it in sync with the rest of the state.
*/
declare class StateField<Value> {
private createF;
private updateF;
private compareF;
private constructor();
/**
Define a state field.
*/
static define<Value>(config: StateFieldSpec<Value>): StateField<Value>;
private create;
/**
Returns an extension that enables this field and overrides the
way it is initialized. Can be useful when you need to provide a
non-default starting value for the field.
*/
init(create: (state: EditorState) => Value): Extension;
/**
State field instances can be used as
[`Extension`](https://codemirror.net/6/docs/ref/#state.Extension) values to enable the field in a
given state.
*/
get extension(): Extension;
}
/**
Extension values can be
[provided](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions) when creating a
state to attach various kinds of configuration and behavior
information. They can either be built-in extension-providing
objects, such as [state fields](https://codemirror.net/6/docs/ref/#state.StateField) or [facet
providers](https://codemirror.net/6/docs/ref/#state.Facet.of), or objects with an extension in its
`extension` property. Extensions can be nested in arrays
arbitrarily deep—they will be flattened when processed.
*/
type Extension = {
extension: Extension;
} | readonly Extension[];
/**
By default extensions are registered in the order they are found
in the flattened form of nested array that was provided.
Individual extension values can be assigned a precedence to
override this. Extensions that do not have a precedence set get
the precedence of the nearest parent with a precedence, or
[`default`](https://codemirror.net/6/docs/ref/#state.Prec.default) if there is no such parent. The
final ordering of extensions is determined by first sorting by
precedence and then by order within each precedence.
*/
declare const Prec: {
/**
The highest precedence level, for extensions that should end up
near the start of the precedence ordering.
*/
highest: (ext: Extension) => Extension;
/**
A higher-than-default precedence, for extensions that should
come before those with default precedence.
*/
high: (ext: Extension) => Extension;
/**
The default precedence, which is also used for extensions
without an explicit precedence.
*/
default: (ext: Extension) => Extension;
/**
A lower-than-default precedence.
*/
low: (ext: Extension) => Extension;
/**
The lowest precedence level. Meant for things that should end up
near the end of the extension order.
*/
lowest: (ext: Extension) => Extension;
};
/**
Extension compartments can be used to make a configuration
dynamic. By [wrapping](https://codemirror.net/6/docs/ref/#state.Compartment.of) part of your
configuration in a compartment, you can later
[replace](https://codemirror.net/6/docs/ref/#state.Compartment.reconfigure) that part through a
transaction.
*/
declare class Compartment {
/**
Create an instance of this compartment to add to your [state
configuration](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions).
*/
of(ext: Extension): Extension;
/**
Create an [effect](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) that
reconfigures this compartment.
*/
reconfigure(content: Extension): StateEffect<unknown>;
/**
Get the current content of the compartment in the state, or
`undefined` if it isn't present.
*/
get(state: EditorState): Extension | undefined;
}
/**
Annotations are tagged values that are used to add metadata to
transactions in an extensible way. They should be used to model
things that effect the entire transaction (such as its [time
stamp](https://codemirror.net/6/docs/ref/#state.Transaction^time) or information about its
[origin](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent)). For effects that happen
_alongside_ the other changes made by the transaction, [state
effects](https://codemirror.net/6/docs/ref/#state.StateEffect) are more appropriate.
*/
declare class Annotation<T> {
/**
The annotation type.
*/
readonly type: AnnotationType<T>;
/**
The value of this annotation.
*/
readonly value: T;
/**
Define a new type of annotation.
*/
static define<T>(): AnnotationType<T>;
private _isAnnotation;
}
/**
Marker that identifies a type of [annotation](https://codemirror.net/6/docs/ref/#state.Annotation).
*/
declare class AnnotationType<T> {
/**
Create an instance of this annotation.
*/
of(value: T): Annotation<T>;
}
interface StateEffectSpec<Value> {
/**
Provides a way to map an effect like this through a position
mapping. When not given, the effects will simply not be mapped.
When the function returns `undefined`, that means the mapping
deletes the effect.
*/
map?: (value: Value, mapping: ChangeDesc) => Value | undefined;
}
/**
Representation of a type of state effect. Defined with
[`StateEffect.define`](https://codemirror.net/6/docs/ref/#state.StateEffect^define).
*/
declare class StateEffectType<Value> {
/**
@internal
*/
readonly map: (value: any, mapping: ChangeDesc) => any | undefined;
/**
Create a [state effect](https://codemirror.net/6/docs/ref/#state.StateEffect) instance of this
type.
*/
of(value: Value): StateEffect<Value>;
}
/**
State effects can be used to represent additional effects
associated with a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction.effects). They
are often useful to model changes to custom [state
fields](https://codemirror.net/6/docs/ref/#state.StateField), when those changes aren't implicit in
document or selection changes.
*/
declare class StateEffect<Value> {
/**
The value of this effect.
*/
readonly value: Value;
/**
Map this effect through a position mapping. Will return
`undefined` when that ends up deleting the effect.
*/
map(mapping: ChangeDesc): StateEffect<Value> | undefined;
/**
Tells you whether this effect object is of a given
[type](https://codemirror.net/6/docs/ref/#state.StateEffectType).
*/
is<T>(type: StateEffectType<T>): this is StateEffect<T>;
/**
Define a new effect type. The type parameter indicates the type
of values that his effect holds. It should be a type that
doesn't include `undefined`, since that is used in
[mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is
removed.
*/
static define<Value = null>(spec?: StateEffectSpec<Value>): StateEffectType<Value>;
/**
Map an array of effects through a change set.
*/
static mapEffects(effects: readonly StateEffect<any>[], mapping: ChangeDesc): readonly StateEffect<any>[];
/**
This effect can be used to reconfigure the root extensions of
the editor. Doing this will discard any extensions
[appended](https://codemirror.net/6/docs/ref/#state.StateEffect^appendConfig), but does not reset
the content of [reconfigured](https://codemirror.net/6/docs/ref/#state.Compartment.reconfigure)
compartments.
*/
static reconfigure: StateEffectType<Extension>;
/**
Append extensions to the top-level configuration of the editor.
*/
static appendConfig: StateEffectType<Extension>;
}
/**
Describes a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction) when calling the
[`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update) method.
*/
interface TransactionSpec {
/**
The changes to the document made by this transaction.
*/
changes?: ChangeSpec;
/**
When set, this transaction explicitly updates the selection.
Offsets in this selection should refer to the document as it is
_after_ the transaction.
*/
selection?: EditorSelection | {
anchor: number;
head?: number;
} | undefined;
/**
Attach [state effects](https://codemirror.net/6/docs/ref/#state.StateEffect) to this transaction.
Again, when they contain positions and this same spec makes
changes, those positions should refer to positions in the
updated document.
*/
effects?: StateEffect<any> | readonly StateEffect<any>[];
/**
Set [annotations](https://codemirror.net/6/docs/ref/#state.Annotation) for this transaction.
*/
annotations?: Annotation<any> | readonly Annotation<any>[];
/**
Shorthand for `annotations:` [`Transaction.userEvent`](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent)`.of(...)`.
*/
userEvent?: string;
/**
When set to `true`, the transaction is marked as needing to
scroll the current selection into view.
*/
scrollIntoView?: boolean;
/**
By default, transactions can be modified by [change
filters](https://codemirror.net/6/docs/ref/#state.EditorState^changeFilter) and [transaction
filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter). You can set this
to `false` to disable that. This can be necessary for
transactions that, for example, include annotations that must be
kept consistent with their changes.
*/
filter?: boolean;
/**
Normally, when multiple specs are combined (for example by
[`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update)), the
positions in `changes` are taken to refer to the document
positions in the initial document. When a spec has `sequental`
set to true, its positions will be taken to refer to the
document created by the specs before it instead.
*/
sequential?: boolean;
}
/**
Changes to the editor state are grouped into transactions.
Typically, a user action creates a single transaction, which may
contain any number of document changes, may change the selection,
or have other effects. Create a transaction by calling
[`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update), or immediately
dispatch one by calling
[`EditorView.dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch).
*/
declare class Transaction {
/**
The state from which the transaction starts.
*/
readonly startState: EditorState;
/**
The document changes made by this transaction.
*/
readonly changes: ChangeSet;
/**
The selection set by this transaction, or undefined if it
doesn't explicitly set a selection.
*/
readonly selection: EditorSelection | undefined;
/**
The effects added to the transaction.
*/
readonly effects: readonly StateEffect<any>[];
/**
Whether the selection should be scrolled into view after this
transaction is dispatched.
*/
readonly scrollIntoView: boolean;
private constructor();
/**
The new document produced by the transaction. Contrary to
[`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't
force the entire new state to be computed right away, so it is
recommended that [transaction
filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) use this getter
when they need to look at the new document.
*/
get newDoc(): Text;
/**
The new selection produced by the transaction. If
[`this.selection`](https://codemirror.net/6/docs/ref/#state.Transaction.selection) is undefined,
this will [map](https://codemirror.net/6/docs/ref/#state.EditorSelection.map) the start state's
current selection through the changes made by the transaction.
*/
get newSelection(): EditorSelection;
/**
The new state created by the transaction. Computed on demand
(but retained for subsequent access), so it is recommended not to
access it in [transaction
filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) when possible.
*/
get state(): EditorState;
/**
Get the value of the given annotation type, if any.
*/
annotation<T>(type: AnnotationType<T>): T | undefined;
/**
Indicates whether the transaction changed the document.
*/
get docChanged(): boolean;
/**
Indicates whether this transaction reconfigures the state
(through a [configuration compartment](https://codemirror.net/6/docs/ref/#state.Compartment) or
with a top-level configuration
[effect](https://codemirror.net/6/docs/ref/#state.StateEffect^reconfigure).
*/
get reconfigured(): boolean;
/**
Returns true if the transaction has a [user
event](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent) annotation that is equal to
or more specific than `event`. For example, if the transaction
has `"select.pointer"` as user event, `"select"` and
`"select.pointer"` will match it.
*/
isUserEvent(event: string): boolean;
/**
Annotation used to store transaction timestamps. Automatically
added to every transaction, holding `Date.now()`.
*/
static time: AnnotationType<number>;
/**
Annotation used to associate a transaction with a user interface
event. Holds a string identifying the event, using a
dot-separated format to support attaching more specific
information. The events used by the core libraries are:
- `"input"` when content is entered
- `"input.type"` for typed input
- `"input.type.compose"` for composition
- `"input.paste"` for pasted input
- `"input.drop"` when adding content with drag-and-drop
- `"input.complete"` when autocompleting
- `"delete"` when the user deletes content
- `"delete.selection"` when deleting the selection
- `"delete.forward"` when deleting forward from the selection
- `"delete.backward"` when deleting backward from the selection
- `"delete.cut"` when cutting to the clipboard
- `"move"` when content is moved
- `"move.drop"` when content is moved within the editor through drag-and-drop
- `"select"` when explicitly changing the selection
- `"select.pointer"` when selecting with a mouse or other pointing device
- `"undo"` and `"redo"` for history actions
Use [`isUserEvent`](https://codemirror.net/6/docs/ref/#state.Transaction.isUserEvent) to check
whether the annotation matches a given event.
*/
static userEvent: AnnotationType<string>;
/**
Annotation indicating whether a transaction should be added to
the undo history or not.
*/
static addToHistory: AnnotationType<boolean>;
/**
Annotation indicating (when present and true) that a transaction
represents a change made by some other actor, not the user. This
is used, for example, to tag other people's changes in
collaborative editing.
*/
static remote: AnnotationType<boolean>;
}
/**
The categories produced by a [character
categorizer](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer). These are used
do things like selecting by word.
*/
declare enum CharCategory {
/**
Word characters.
*/
Word = 0,
/**
Whitespace.
*/
Space = 1,
/**
Anything else.
*/
Other = 2
}
/**
Options passed when [creating](https://codemirror.net/6/docs/ref/#state.EditorState^create) an
editor state.
*/
interface EditorStateConfig {
/**
The initial document. Defaults to an empty document. Can be
provided either as a plain string (which will be split into
lines according to the value of the [`lineSeparator`
facet](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator)), or an instance of
the [`Text`](https://codemirror.net/6/docs/ref/#state.Text) class (which is what the state will use
to represent the document).
*/
doc?: string | Text;
/**
The starting selection. Defaults to a cursor at the very start
of the document.
*/
selection?: EditorSelection | {
anchor: number;
head?: number;
};
/**
[Extension(s)](https://codemirror.net/6/docs/ref/#state.Extension) to associate with this state.
*/
extensions?: Extension;
}
/**
The editor state class is a persistent (immutable) data structure.
To update a state, you [create](https://codemirror.net/6/docs/ref/#state.EditorState.update) a
[transaction](https://codemirror.net/6/docs/ref/#state.Transaction), which produces a _new_ state
instance, without modifying the original object.
As such, _never_ mutate properties of a state directly. That'll
just break things.
*/
declare class EditorState {
/**
The current document.
*/
readonly doc: Text;
/**
The current selection.
*/
readonly selection: EditorSelection;
private constructor();
/**
Retrieve the value of a [state field](https://codemirror.net/6/docs/ref/#state.StateField). Throws
an error when the state doesn't have that field, unless you pass
`false` as second parameter.
*/
field<T>(field: StateField<T>): T;
field<T>(field: StateField<T>, require: false): T | undefined;
/**
Create a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction) that updates this
state. Any number of [transaction specs](https://codemirror.net/6/docs/ref/#state.TransactionSpec)
can be passed. Unless
[`sequential`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.sequential) is set, the
[changes](https://codemirror.net/6/docs/ref/#state.TransactionSpec.changes) (if any) of each spec
are assumed to start in the _current_ document (not the document
produced by previous specs), and its
[selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) and
[effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) are assumed to refer
to the document created by its _own_ changes. The resulting
transaction contains the combined effect of all the different
specs. For [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection), later
specs take precedence over earlier ones.
*/
update(...specs: readonly TransactionSpec[]): Transaction;
/**
Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
replaces every selection range with the given content.
*/
replaceSelection(text: string | Text): TransactionSpec;
/**
Create a set of changes and a new selection by running the given
function for each range in the active selection. The function
can return an optional set of changes (in the coordinate space
of the start document), plus an updated range (in the coordinate
space of the document produced by the call's own changes). This
method will merge all the changes and ranges into a single
changeset and selection, and return it as a [transaction
spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec), which can be passed to
[`update`](https://codemirror.net/6/docs/ref/#state.EditorState.update).
*/
changeByRange(f: (range: SelectionRange) => {
range: SelectionRange;
changes?: ChangeSpec;
effects?: StateEffect<any> | readonly StateEffect<any>[];
}): {
changes: ChangeSet;
selection: EditorSelection;
effects: readonly StateEffect<any>[];
};
/**
Create a [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet) from the given change
description, taking the state's document length and line
separator into account.
*/
changes(spec?: ChangeSpec): ChangeSet;
/**
Using the state's [line
separator](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator), create a
[`Text`](https://codemirror.net/6/docs/ref/#state.Text) instance from the given string.
*/
toText(string: string): Text;
/**
Return the given range of the document as a string.
*/
sliceDoc(from?: number, to?: number): string;
/**
Get the value of a state [facet](https://codemirror.net/6/docs/ref/#state.Facet).
*/
facet<Output>(facet: FacetReader<Output>): Output;
/**
Convert this state to a JSON-serializable object. When custom
fields should be serialized, you can pass them in as an object
mapping property names (in the resulting object, which should
not use `doc` or `selection`) to fields.
*/
toJSON(fields?: {
[prop: string]: StateField<any>;
}): any;
/**
Deserialize a state from its JSON representation. When custom
fields should be deserialized, pass the same object you passed
to [`toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) when serializing as
third argument.
*/
static fromJSON(json: any, config?: EditorStateConfig, fields?: {
[prop: string]: StateField<any>;
}): EditorState;
/**
Create a new state. You'll usually only need this when
initializing an editor—updated states are created by applying
transactions.
*/
static create(config?: EditorStateConfig): EditorState;
/**
A facet that, when enabled, causes the editor to allow multiple
ranges to be selected. Be careful though, because by default the
editor relies on the native DOM selection, which cannot handle
multiple selections. An extension like
[`drawSelection`](https://codemirror.net/6/docs/ref/#view.drawSelection) can be used to make
secondary selections visible to the user.
*/
static allowMultipleSelections: Facet<boolean, boolean>;
/**
Configures the tab size to use in this state. The first
(highest-precedence) value of the facet is used. If no value is
given, this defaults to 4.
*/
static tabSize: Facet<number, number>;
/**
The size (in columns) of a tab in the document, determined by
the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet.
*/
get tabSize(): number;
/**
The line separator to use. By default, any of `"\n"`, `"\r\n"`
and `"\r"` is treated as a separator when splitting lines, and
lines are joined with `"\n"`.
When you configure a value here, only that precise separator
will be used, allowing you to round-trip documents through the
editor without normalizing line separators.
*/
static lineSeparator: Facet<string, string | undefined>;
/**
Get the proper [line-break](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator)
string for this state.
*/
get lineBreak(): string;
/**
This facet controls the value of the
[`readOnly`](https://codemirror.net/6/docs/ref/#state.EditorState.readOnly) getter, which is
consulted by commands and extensions that implement editing
functionality to determine whether they should apply. It
defaults to false, but when its highest-precedence value is
`true`, such functionality disables itself.
Not to be confused with
[`EditorView.editable`](https://codemirror.net/6/docs/ref/#view.EditorView^editable), which
controls whether the editor's DOM is set to be editable (and
thus focusable).
*/
static readOnly: Facet<boolean, boolean>;
/**
Returns true when the editor is
[configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only.
*/
get readOnly(): boolean;
/**
Registers translation phrases. The
[`phrase`](https://codemirror.net/6/docs/ref/#state.EditorState.phrase) method will look through
all objects registered with this facet to find translations for
its argument.
*/
static phrases: Facet<{
[key: string]: string;
}, readonly {
[key: string]: string;
}[]>;
/**
Look up a translation for the given phrase (via the
[`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
original string if no translation is found.
If additional arguments are passed, they will be inserted in
place of markers like `$1` (for the first value) and `$2`, etc.
A single `$` is equivalent to `$1`, and `$$` will produce a
literal dollar sign.
*/
phrase(phrase: string, ...insert: any[]): string;
/**
A facet used to register [language
data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) providers.
*/
static languageData: Facet<(state: EditorState, pos: number, side: 0 | 1 | -1) => readonly {
[name: string]: any;
}[], readonly ((state: EditorState, pos: number, side: 0 | 1 | -1) => readonly {
[name: string]: any;
}[])[]>;
/**
Find the values for a given language data field, provided by the
the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
Examples of language data fields are...
- [`"commentTokens"`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) for specifying
comment syntax.
- [`"autocomplete"`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.override)
for providing language-specific completion sources.
- [`"wordChars"`](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) for adding
characters that should be considered part of words in this
language.
- [`"closeBrackets"`](https://codemirror.net/6/docs/ref/#autocomplete.CloseBracketConfig) controls
bracket closing behavior.
*/
languageDataAt<T>(name: string, pos: number, side?: -1 | 0 | 1): readonly T[];
/**
Return a function that can categorize strings (expected to
represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak))
into one of:
- Word (contains an alphanumeric character or a character
explicitly listed in the local language's `"wordChars"`
language data, which should be a string)
- Space (contains only whitespace)
- Other (anything else)
*/
charCategorizer(at: number): (char: string) => CharCategory;
/**
Find the word at the given position, meaning the range
containing all [word](https://codemirror.net/6/docs/ref/#state.CharCategory.Word) characters
around it. If no word characters are adjacent to the position,
this returns null.
*/
wordAt(pos: number): SelectionRange | null;
/**
Facet used to register change filters, which are called for each
transaction (unless explicitly
[disabled](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter)), and can suppress
part of the transaction's changes.
Such a function can return `true` to indicate that it doesn't
want to do anything, `false` to completely stop the changes in
the transaction, or a set of ranges in which changes should be
suppressed. Such ranges are represented as an array of numbers,
with each pair of two numbers indicating the start and end of a
range. So for example `[10, 20, 100, 110]` suppresses changes
between 10 and 20, and between 100 and 110.
*/
static changeFilter: Facet<(tr: Transaction) => boolean | readonly number[], readonly ((tr: Transaction) => boolean | readonly number[])[]>;
/**
Facet used to register a hook that gets a chance to update or
replace transaction specs before they are applied. This will
only be applied for transactions that don't have
[`filter`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter) set to `false`. You
can either return a single transaction spec (possibly the input
transaction), or an array of specs (which will be combined in
the same way as the arguments to
[`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update)).
When possible, it is recommended to avoid accessing
[`Transaction.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state) in a filter,
since it will force creation of a state that will then be
discarded again, if the transaction is actually filtered.
(This functionality should be used with care. Indiscriminately
modifying transaction is likely to break something or degrade
the user experience.)
*/
static transactionFilter: Facet<(tr: Transaction) => TransactionSpec | readonly TransactionSpec[], readonly ((tr: Transaction) => TransactionSpec | readonly TransactionSpec[])[]>;
/**
This is a more limited form of
[`transactionFilter`](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter),
which can only add
[annotations](https://codemirror.net/6/docs/ref/#state.TransactionSpec.annotations) and
[effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects). _But_, this type
of filter runs even if the transaction has disabled regular
[filtering](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter), making it suitable
for effects that don't need to touch the changes or selection,
but do want to process every transaction.
Extenders run _after_ filters, when both are present.
*/
static transactionExtender: Facet<(tr: Transaction) => Pick<TransactionSpec, "effects" | "annotations"> | null, readonly ((tr: Transaction) => Pick<TransactionSpec, "effects" | "annotations"> | null)[]>;
}
/**
Subtype of [`Command`](https://codemirror.net/6/docs/ref/#view.Command) that doesn't require access
to the actual editor view. Mostly useful to define commands that
can be run and tested outside of a browser environment.
*/
type StateCommand = (target: {
state: EditorState;
dispatch: (transaction: Transaction) => void;
}) => boolean;
/**
Utility function for combining behaviors to fill in a config
object from an array of provided configs. `defaults` should hold
default values for all optional fields in `Config`.
The function will, by default, error
when a field gets two values that aren't `===`-equal, but you can
provide combine functions per field to do something else.
*/
declare function combineConfig<Config extends object>(configs: readonly Partial<Config>[], defaults: Partial<Config>, // Should hold only the optional properties of Config, but I haven't managed to express that
combine?: {
[P in keyof Config]?: (first: Config[P], second: Config[P]) => Config[P];
}): Config;
/**
Each range is associated with a value, which must inherit from
this class.
*/
declare abstract class RangeValue {
/**
Compare this value with another value. Used when comparing
rangesets. The default implementation compares by identity.
Unless you are only creating a fixed number of unique instances
of your value type, it is a good idea to implement this
properly.
*/
eq(other: RangeValue): boolean;
/**
The bias value at the start of the range. Determines how the
range is positioned relative to other ranges starting at this
position. Defaults to 0.
*/
startSide: number;
/**
The bias value at the end of the range. Defaults to 0.
*/
endSide: number;
/**
The mode with which the location of the range should be mapped
when its `from` and `to` are the same, to decide whether a
change deletes the range. Defaults to `MapMode.TrackDel`.
*/
mapMode: MapMode;
/**
Determines whether this value marks a point range. Regular
ranges affect the part of the document they cover, and are
meaningless when empty. Point ranges have a meaning on their
own. When non-empty, a point range is treated as atomic and
shadows any ranges contained in it.
*/
point: boolean;
/**
Create a [range](https://codemirror.net/6/docs/ref/#state.Range) with this value.
*/
range(from: number, to?: number): Range<this>;
}
/**
A range associates a value with a range of positions.
*/
declare class Range<T extends RangeValue> {
/**
The range's start position.
*/
readonly from: number;
/**
Its end position.
*/
readonly to: number;
/**
The value associated with this range.
*/
readonly value: T;
private constructor();
}
/**
Collection of methods used when comparing range sets.
*/
interface RangeComparator<T extends RangeValue> {
/**
Notifies the comparator that a range (in positions in the new
document) has the given sets of values associated with it, which
are different in the old (A) and new (B) sets.
*/
compareRange(from: number, to: number, activeA: T[], activeB: T[]): void;
/**
Notification for a changed (or inserted, or deleted) point range.
*/
comparePoint(from: number, to: number, pointA: T | null, pointB: T | null): void;
}
/**
Methods used when iterating over the spans created by a set of
ranges. The entire iterated range will be covered with either
`span` or `point` calls.
*/
interface SpanIterator<T extends RangeValue> {
/**
Called for any ranges not covered by point decorations. `active`
holds the values that the range is marked with (and may be
empty). `openStart` indicates how many of those ranges are open
(continued) at the start of the span.
*/
span(from: number, to: number, active: readonly T[], openStart: number): void;
/**
Called when going over a point decoration. The active range
decorations that cover the point and have a higher precedence
are provided in `active`. The open count in `openStart` counts
the number of those ranges that started before the point and. If
the point started before the iterated range, `openStart` will be
`active.length + 1` to signal this.
*/
point(from: number, to: number, value: T, active: readonly T[], openStart: number, index: number): void;
}
/**
A range cursor is an object that moves to the next range every
time you call `next` on it. Note that, unlike ES6 iterators, these
start out pointing at the first element, so you should call `next`
only after reading the first range (if any).
*/
interface RangeCursor<T> {
/**
Move the iterator forward.
*/
next: () => void;
/**
The next range's value. Holds `null` when the cursor has reached
its end.
*/
value: T | null;
/**
The next range's start position.
*/
from: number;
/**
The next end position.
*/
to: number;
}
type RangeSetUpdate<T extends RangeValue> = {
/**
An array of ranges to add. If given, this should be sorted by
`from` position and `startSide` unless
[`sort`](https://codemirror.net/6/docs/ref/#state.RangeSet.update^updateSpec.sort) is given as
`true`.
*/
add?: readonly Range<T>[];
/**
Indicates whether the library should sort the ranges in `add`.
Defaults to `false`.
*/
sort?: boolean;
/**
Filter the ranges already in the set. Only those for which this
function returns `true` are kept.
*/
filter?: (from: number, to: number, value: T) => boolean;
/**
Can be used to limit the range on which the filter is
applied. Filtering only a small range, as opposed to the entire
set, can make updates cheaper.
*/
filterFrom?: number;
/**
The end position to apply the filter to.
*/
filterTo?: number;
};
/**
A range set stores a collection of [ranges](https://codemirror.net/6/docs/ref/#state.Range) in a
way that makes them efficient to [map](https://codemirror.net/6/docs/ref/#state.RangeSet.map) and
[update](https://codemirror.net/6/docs/ref/#state.RangeSet.update). This is an immutable data
structure.
*/
declare class RangeSet<T extends RangeValue> {
private constructor();
/**
The number of ranges in the set.
*/
get size(): number;
/**
Update the range set, optionally adding new ranges or filtering
out existing ones.
(Note: The type parameter is just there as a kludge to work
around TypeScript variance issues that prevented `RangeSet<X>`
from being a subtype of `RangeSet<Y>` when `X` is a subtype of
`Y`.)
*/
update<U extends T>(updateSpec: RangeSetUpdate<U>): RangeSet<T>;
/**
Map this range set through a set of changes, return the new set.
*/
map(changes: ChangeDesc): RangeSet<T>;
/**
Iterate over the ranges that touch the region `from` to `to`,
calling `f` for each. There is no guarantee that the ranges will
be reported in any specific order. When the callback returns
`false`, iteration stops.
*/
between(from: number, to: number, f: (from: number, to: number, value: T) => void | false): void;
/**
Iterate over the ranges in this set, in order, including all
ranges that end at or after `from`.
*/
iter(from?: number): RangeCursor<T>;
/**
Iterate over the ranges in a collection of sets, in order,
starting from `from`.
*/
static iter<T extends RangeValue>(sets: readonly RangeSet<T>[], from?: number): RangeCursor<T>;
/**
Iterate over two groups of sets, calling methods on `comparator`
to notify it of possible differences.
*/
static compare<T extends RangeValue>(oldSets: readonly RangeSet<T>[], newSets: readonly RangeSet<T>[],
/**
This indicates how the underlying data changed between these
ranges, and is needed to synchronize the iteration.
*/
textDiff: ChangeDesc, comparator: RangeComparator<T>,
/**
Can be used to ignore all non-point ranges, and points below
the given size. When -1, all ranges are compared.
*/
minPointSize?: number): void;
/**
Compare the contents of two groups of range sets, returning true
if they are equivalent in the given range.
*/
static eq<T extends RangeValue>(oldSets: readonly RangeSet<T>[], newSets: readonly RangeSet<T>[], from?: number, to?: number): boolean;
/**
Iterate over a group of range sets at the same time, notifying
the iterator about the ranges covering every given piece of
content. Returns the open count (see
[`SpanIterator.span`](https://codemirror.net/6/docs/ref/#state.SpanIterator.span)) at the end
of the iteration.
*/
static spans<T extends RangeValue>(sets: readonly RangeSet<T>[], from: number, to: number, iterator: SpanIterator<T>,
/**
When given and greater than -1, only points of at least this
size are taken into account.
*/
minPointSize?: number): number;
/**
Create a range set for the given range or array of ranges. By
default, this expects the ranges to be _sorted_ (by start
position and, if two start at the same position,
`value.startSide`). You can pass `true` as second argument to
cause the method to sort them.
*/
static of<T extends RangeValue>(ranges: readonly Range<T>[] | Range<T>, sort?: boolean): RangeSet<T>;
/**
Join an array of range sets into a single set.
*/
static join<T extends RangeValue>(sets: readonly RangeSet<T>[]): RangeSet<T>;
/**
The empty set of ranges.
*/
static empty: RangeSet<any>;
}
/**
A range set builder is a data structure that helps build up a
[range set](https://codemirror.net/6/docs/ref/#state.RangeSet) directly, without first allocating
an array of [`Range`](https://codemirror.net/6/docs/ref/#state.Range) objects.
*/
declare class RangeSetBuilder<T extends RangeValue> {
private chunks;
private chunkPos;
private chunkStart;
private last;
private lastFrom;
private lastTo;
private from;
private to;
private value;
private maxPoint;
private setMaxPoint;
private nextLayer;
private finishChunk;
/**
Create an empty builder.
*/
constructor();
/**
Add a range. Ranges should be added in sorted (by `from` and
`value.startSide`) order.
*/
add(from: number, to: number, value: T): void;
/**
Finish the range set. Returns the new set. The builder can't be
used anymore after this has been called.
*/
finish(): RangeSet<T>;
}
/**
Returns a next grapheme cluster break _after_ (not equal to)
`pos`, if `forward` is true, or before otherwise. Returns `pos`
itself if no further cluster break is available in the string.
Moves across surrogate pairs, extending characters (when
`includeExtending` is true), characters joined with zero-width
joiners, and flag emoji.
*/
declare function findClusterBreak(str: string, pos: number, forward?: boolean, includeExtending?: boolean): number;
/**
Find the code point at the given position in a string (like the
[`codePointAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
string method).
*/
declare function codePointAt(str: string, pos: number): number;
/**
Given a Unicode codepoint, return the JavaScript string that
respresents it (like
[`String.fromCodePoint`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)).
*/
declare function fromCodePoint(code: number): string;
/**
The amount of positions a character takes up a JavaScript string.
*/
declare function codePointSize(code: number): 1 | 2;
/**
Count the column position at the given offset into the string,
taking extending characters and tab size into account.
*/
declare function countColumn(string: string, tabSize: number, to?: number): number;
/**
Find the offset that corresponds to the given column position in a
string, taking extending characters and tab size into account. By
default, the string length is returned when it is too short to
reach the column. Pass `strict` true to make it return -1 in that
situation.
*/
declare function findColumn(string: string, col: number, tabSize: number, strict?: boolean): number;
export { Annotation, AnnotationType, ChangeDesc, ChangeSet, type ChangeSpec, CharCategory, Compartment, EditorSelection, EditorState, type EditorStateConfig, type Extension, Facet, type FacetReader, Line, MapMode, Prec, Range, type RangeComparator, type RangeCursor, RangeSet, RangeSetBuilder, RangeValue, SelectionRange, type SpanIterator, type StateCommand, StateEffect, StateEffectType, StateField, Text, type TextIterator, Transaction, type TransactionSpec, codePointAt, codePointSize, combineConfig, countColumn, findClusterBreak, findColumn, fromCodePoint };
|