index.d.cts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. import { Schema, Node, Mark, MarkType, Slice, ResolvedPos } from 'prosemirror-model';
  2. import { Transform, Mappable } from 'prosemirror-transform';
  3. import { EditorProps, EditorView } from 'prosemirror-view';
  4. /**
  5. The type of object passed to
  6. [`EditorState.create`](https://prosemirror.net/docs/ref/#state.EditorState^create).
  7. */
  8. interface EditorStateConfig {
  9. /**
  10. The schema to use (only relevant if no `doc` is specified).
  11. */
  12. schema?: Schema;
  13. /**
  14. The starting document. Either this or `schema` _must_ be
  15. provided.
  16. */
  17. doc?: Node;
  18. /**
  19. A valid selection in the document.
  20. */
  21. selection?: Selection;
  22. /**
  23. The initial set of [stored marks](https://prosemirror.net/docs/ref/#state.EditorState.storedMarks).
  24. */
  25. storedMarks?: readonly Mark[] | null;
  26. /**
  27. The plugins that should be active in this state.
  28. */
  29. plugins?: readonly Plugin[];
  30. }
  31. /**
  32. The state of a ProseMirror editor is represented by an object of
  33. this type. A state is a persistent data structure—it isn't
  34. updated, but rather a new state value is computed from an old one
  35. using the [`apply`](https://prosemirror.net/docs/ref/#state.EditorState.apply) method.
  36. A state holds a number of built-in fields, and plugins can
  37. [define](https://prosemirror.net/docs/ref/#state.PluginSpec.state) additional fields.
  38. */
  39. declare class EditorState {
  40. /**
  41. The current document.
  42. */
  43. doc: Node;
  44. /**
  45. The selection.
  46. */
  47. selection: Selection;
  48. /**
  49. A set of marks to apply to the next input. Will be null when
  50. no explicit marks have been set.
  51. */
  52. storedMarks: readonly Mark[] | null;
  53. /**
  54. The schema of the state's document.
  55. */
  56. get schema(): Schema;
  57. /**
  58. The plugins that are active in this state.
  59. */
  60. get plugins(): readonly Plugin[];
  61. /**
  62. Apply the given transaction to produce a new state.
  63. */
  64. apply(tr: Transaction): EditorState;
  65. /**
  66. Verbose variant of [`apply`](https://prosemirror.net/docs/ref/#state.EditorState.apply) that
  67. returns the precise transactions that were applied (which might
  68. be influenced by the [transaction
  69. hooks](https://prosemirror.net/docs/ref/#state.PluginSpec.filterTransaction) of
  70. plugins) along with the new state.
  71. */
  72. applyTransaction(rootTr: Transaction): {
  73. state: EditorState;
  74. transactions: readonly Transaction[];
  75. };
  76. /**
  77. Start a [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state.
  78. */
  79. get tr(): Transaction;
  80. /**
  81. Create a new state.
  82. */
  83. static create(config: EditorStateConfig): EditorState;
  84. /**
  85. Create a new state based on this one, but with an adjusted set
  86. of active plugins. State fields that exist in both sets of
  87. plugins are kept unchanged. Those that no longer exist are
  88. dropped, and those that are new are initialized using their
  89. [`init`](https://prosemirror.net/docs/ref/#state.StateField.init) method, passing in the new
  90. configuration object..
  91. */
  92. reconfigure(config: {
  93. /**
  94. New set of active plugins.
  95. */
  96. plugins?: readonly Plugin[];
  97. }): EditorState;
  98. /**
  99. Serialize this state to JSON. If you want to serialize the state
  100. of plugins, pass an object mapping property names to use in the
  101. resulting JSON object to plugin objects. The argument may also be
  102. a string or number, in which case it is ignored, to support the
  103. way `JSON.stringify` calls `toString` methods.
  104. */
  105. toJSON(pluginFields?: {
  106. [propName: string]: Plugin;
  107. }): any;
  108. /**
  109. Deserialize a JSON representation of a state. `config` should
  110. have at least a `schema` field, and should contain array of
  111. plugins to initialize the state with. `pluginFields` can be used
  112. to deserialize the state of plugins, by associating plugin
  113. instances with the property names they use in the JSON object.
  114. */
  115. static fromJSON(config: {
  116. /**
  117. The schema to use.
  118. */
  119. schema: Schema;
  120. /**
  121. The set of active plugins.
  122. */
  123. plugins?: readonly Plugin[];
  124. }, json: any, pluginFields?: {
  125. [propName: string]: Plugin;
  126. }): EditorState;
  127. }
  128. /**
  129. This is the type passed to the [`Plugin`](https://prosemirror.net/docs/ref/#state.Plugin)
  130. constructor. It provides a definition for a plugin.
  131. */
  132. interface PluginSpec<PluginState> {
  133. /**
  134. The [view props](https://prosemirror.net/docs/ref/#view.EditorProps) added by this plugin. Props
  135. that are functions will be bound to have the plugin instance as
  136. their `this` binding.
  137. */
  138. props?: EditorProps<Plugin<PluginState>>;
  139. /**
  140. Allows a plugin to define a [state field](https://prosemirror.net/docs/ref/#state.StateField), an
  141. extra slot in the state object in which it can keep its own data.
  142. */
  143. state?: StateField<PluginState>;
  144. /**
  145. Can be used to make this a keyed plugin. You can have only one
  146. plugin with a given key in a given state, but it is possible to
  147. access the plugin's configuration and state through the key,
  148. without having access to the plugin instance object.
  149. */
  150. key?: PluginKey;
  151. /**
  152. When the plugin needs to interact with the editor view, or
  153. set something up in the DOM, use this field. The function
  154. will be called when the plugin's state is associated with an
  155. editor view.
  156. */
  157. view?: (view: EditorView) => PluginView;
  158. /**
  159. When present, this will be called before a transaction is
  160. applied by the state, allowing the plugin to cancel it (by
  161. returning false).
  162. */
  163. filterTransaction?: (tr: Transaction, state: EditorState) => boolean;
  164. /**
  165. Allows the plugin to append another transaction to be applied
  166. after the given array of transactions. When another plugin
  167. appends a transaction after this was called, it is called again
  168. with the new state and new transactions—but only the new
  169. transactions, i.e. it won't be passed transactions that it
  170. already saw.
  171. */
  172. appendTransaction?: (transactions: readonly Transaction[], oldState: EditorState, newState: EditorState) => Transaction | null | undefined;
  173. /**
  174. Additional properties are allowed on plugin specs, which can be
  175. read via [`Plugin.spec`](https://prosemirror.net/docs/ref/#state.Plugin.spec).
  176. */
  177. [key: string]: any;
  178. }
  179. /**
  180. A stateful object that can be installed in an editor by a
  181. [plugin](https://prosemirror.net/docs/ref/#state.PluginSpec.view).
  182. */
  183. declare type PluginView = {
  184. /**
  185. Called whenever the view's state is updated.
  186. */
  187. update?: (view: EditorView, prevState: EditorState) => void;
  188. /**
  189. Called when the view is destroyed or receives a state
  190. with different plugins.
  191. */
  192. destroy?: () => void;
  193. };
  194. /**
  195. Plugins bundle functionality that can be added to an editor.
  196. They are part of the [editor state](https://prosemirror.net/docs/ref/#state.EditorState) and
  197. may influence that state and the view that contains it.
  198. */
  199. declare class Plugin<PluginState = any> {
  200. /**
  201. The plugin's [spec object](https://prosemirror.net/docs/ref/#state.PluginSpec).
  202. */
  203. readonly spec: PluginSpec<PluginState>;
  204. /**
  205. Create a plugin.
  206. */
  207. constructor(
  208. /**
  209. The plugin's [spec object](https://prosemirror.net/docs/ref/#state.PluginSpec).
  210. */
  211. spec: PluginSpec<PluginState>);
  212. /**
  213. The [props](https://prosemirror.net/docs/ref/#view.EditorProps) exported by this plugin.
  214. */
  215. readonly props: EditorProps<Plugin<PluginState>>;
  216. /**
  217. Extract the plugin's state field from an editor state.
  218. */
  219. getState(state: EditorState): PluginState | undefined;
  220. }
  221. /**
  222. A plugin spec may provide a state field (under its
  223. [`state`](https://prosemirror.net/docs/ref/#state.PluginSpec.state) property) of this type, which
  224. describes the state it wants to keep. Functions provided here are
  225. always called with the plugin instance as their `this` binding.
  226. */
  227. interface StateField<T> {
  228. /**
  229. Initialize the value of the field. `config` will be the object
  230. passed to [`EditorState.create`](https://prosemirror.net/docs/ref/#state.EditorState^create). Note
  231. that `instance` is a half-initialized state instance, and will
  232. not have values for plugin fields initialized after this one.
  233. */
  234. init: (config: EditorStateConfig, instance: EditorState) => T;
  235. /**
  236. Apply the given transaction to this state field, producing a new
  237. field value. Note that the `newState` argument is again a partially
  238. constructed state does not yet contain the state from plugins
  239. coming after this one.
  240. */
  241. apply: (tr: Transaction, value: T, oldState: EditorState, newState: EditorState) => T;
  242. /**
  243. Convert this field to JSON. Optional, can be left off to disable
  244. JSON serialization for the field.
  245. */
  246. toJSON?: (value: T) => any;
  247. /**
  248. Deserialize the JSON representation of this field. Note that the
  249. `state` argument is again a half-initialized state.
  250. */
  251. fromJSON?: (config: EditorStateConfig, value: any, state: EditorState) => T;
  252. }
  253. /**
  254. A key is used to [tag](https://prosemirror.net/docs/ref/#state.PluginSpec.key) plugins in a way
  255. that makes it possible to find them, given an editor state.
  256. Assigning a key does mean only one plugin of that type can be
  257. active in a state.
  258. */
  259. declare class PluginKey<PluginState = any> {
  260. /**
  261. Create a plugin key.
  262. */
  263. constructor(name?: string);
  264. /**
  265. Get the active plugin with this key, if any, from an editor
  266. state.
  267. */
  268. get(state: EditorState): Plugin<PluginState> | undefined;
  269. /**
  270. Get the plugin's state from an editor state.
  271. */
  272. getState(state: EditorState): PluginState | undefined;
  273. }
  274. /**
  275. Commands are functions that take a state and a an optional
  276. transaction dispatch function and...
  277. - determine whether they apply to this state
  278. - if not, return false
  279. - if `dispatch` was passed, perform their effect, possibly by
  280. passing a transaction to `dispatch`
  281. - return true
  282. In some cases, the editor view is passed as a third argument.
  283. */
  284. declare type Command = (state: EditorState, dispatch?: (tr: Transaction) => void, view?: EditorView) => boolean;
  285. /**
  286. An editor state transaction, which can be applied to a state to
  287. create an updated state. Use
  288. [`EditorState.tr`](https://prosemirror.net/docs/ref/#state.EditorState.tr) to create an instance.
  289. Transactions track changes to the document (they are a subclass of
  290. [`Transform`](https://prosemirror.net/docs/ref/#transform.Transform)), but also other state changes,
  291. like selection updates and adjustments of the set of [stored
  292. marks](https://prosemirror.net/docs/ref/#state.EditorState.storedMarks). In addition, you can store
  293. metadata properties in a transaction, which are extra pieces of
  294. information that client code or plugins can use to describe what a
  295. transaction represents, so that they can update their [own
  296. state](https://prosemirror.net/docs/ref/#state.StateField) accordingly.
  297. The [editor view](https://prosemirror.net/docs/ref/#view.EditorView) uses a few metadata
  298. properties: it will attach a property `"pointer"` with the value
  299. `true` to selection transactions directly caused by mouse or touch
  300. input, a `"composition"` property holding an ID identifying the
  301. composition that caused it to transactions caused by composed DOM
  302. input, and a `"uiEvent"` property of that may be `"paste"`,
  303. `"cut"`, or `"drop"`.
  304. */
  305. declare class Transaction extends Transform {
  306. /**
  307. The timestamp associated with this transaction, in the same
  308. format as `Date.now()`.
  309. */
  310. time: number;
  311. private curSelection;
  312. private curSelectionFor;
  313. private updated;
  314. private meta;
  315. /**
  316. The stored marks set by this transaction, if any.
  317. */
  318. storedMarks: readonly Mark[] | null;
  319. /**
  320. The transaction's current selection. This defaults to the editor
  321. selection [mapped](https://prosemirror.net/docs/ref/#state.Selection.map) through the steps in the
  322. transaction, but can be overwritten with
  323. [`setSelection`](https://prosemirror.net/docs/ref/#state.Transaction.setSelection).
  324. */
  325. get selection(): Selection;
  326. /**
  327. Update the transaction's current selection. Will determine the
  328. selection that the editor gets when the transaction is applied.
  329. */
  330. setSelection(selection: Selection): this;
  331. /**
  332. Whether the selection was explicitly updated by this transaction.
  333. */
  334. get selectionSet(): boolean;
  335. /**
  336. Set the current stored marks.
  337. */
  338. setStoredMarks(marks: readonly Mark[] | null): this;
  339. /**
  340. Make sure the current stored marks or, if that is null, the marks
  341. at the selection, match the given set of marks. Does nothing if
  342. this is already the case.
  343. */
  344. ensureMarks(marks: readonly Mark[]): this;
  345. /**
  346. Add a mark to the set of stored marks.
  347. */
  348. addStoredMark(mark: Mark): this;
  349. /**
  350. Remove a mark or mark type from the set of stored marks.
  351. */
  352. removeStoredMark(mark: Mark | MarkType): this;
  353. /**
  354. Whether the stored marks were explicitly set for this transaction.
  355. */
  356. get storedMarksSet(): boolean;
  357. /**
  358. Update the timestamp for the transaction.
  359. */
  360. setTime(time: number): this;
  361. /**
  362. Replace the current selection with the given slice.
  363. */
  364. replaceSelection(slice: Slice): this;
  365. /**
  366. Replace the selection with the given node. When `inheritMarks` is
  367. true and the content is inline, it inherits the marks from the
  368. place where it is inserted.
  369. */
  370. replaceSelectionWith(node: Node, inheritMarks?: boolean): this;
  371. /**
  372. Delete the selection.
  373. */
  374. deleteSelection(): this;
  375. /**
  376. Replace the given range, or the selection if no range is given,
  377. with a text node containing the given string.
  378. */
  379. insertText(text: string, from?: number, to?: number): this;
  380. /**
  381. Store a metadata property in this transaction, keyed either by
  382. name or by plugin.
  383. */
  384. setMeta(key: string | Plugin | PluginKey, value: any): this;
  385. /**
  386. Retrieve a metadata property for a given name or plugin.
  387. */
  388. getMeta(key: string | Plugin | PluginKey): any;
  389. /**
  390. Returns true if this transaction doesn't contain any metadata,
  391. and can thus safely be extended.
  392. */
  393. get isGeneric(): boolean;
  394. /**
  395. Indicate that the editor should scroll the selection into view
  396. when updated to the state produced by this transaction.
  397. */
  398. scrollIntoView(): this;
  399. /**
  400. True when this transaction has had `scrollIntoView` called on it.
  401. */
  402. get scrolledIntoView(): boolean;
  403. }
  404. /**
  405. Superclass for editor selections. Every selection type should
  406. extend this. Should not be instantiated directly.
  407. */
  408. declare abstract class Selection {
  409. /**
  410. The resolved anchor of the selection (the side that stays in
  411. place when the selection is modified).
  412. */
  413. readonly $anchor: ResolvedPos;
  414. /**
  415. The resolved head of the selection (the side that moves when
  416. the selection is modified).
  417. */
  418. readonly $head: ResolvedPos;
  419. /**
  420. Initialize a selection with the head and anchor and ranges. If no
  421. ranges are given, constructs a single range across `$anchor` and
  422. `$head`.
  423. */
  424. constructor(
  425. /**
  426. The resolved anchor of the selection (the side that stays in
  427. place when the selection is modified).
  428. */
  429. $anchor: ResolvedPos,
  430. /**
  431. The resolved head of the selection (the side that moves when
  432. the selection is modified).
  433. */
  434. $head: ResolvedPos, ranges?: readonly SelectionRange[]);
  435. /**
  436. The ranges covered by the selection.
  437. */
  438. ranges: readonly SelectionRange[];
  439. /**
  440. The selection's anchor, as an unresolved position.
  441. */
  442. get anchor(): number;
  443. /**
  444. The selection's head.
  445. */
  446. get head(): number;
  447. /**
  448. The lower bound of the selection's main range.
  449. */
  450. get from(): number;
  451. /**
  452. The upper bound of the selection's main range.
  453. */
  454. get to(): number;
  455. /**
  456. The resolved lower bound of the selection's main range.
  457. */
  458. get $from(): ResolvedPos;
  459. /**
  460. The resolved upper bound of the selection's main range.
  461. */
  462. get $to(): ResolvedPos;
  463. /**
  464. Indicates whether the selection contains any content.
  465. */
  466. get empty(): boolean;
  467. /**
  468. Test whether the selection is the same as another selection.
  469. */
  470. abstract eq(selection: Selection): boolean;
  471. /**
  472. Map this selection through a [mappable](https://prosemirror.net/docs/ref/#transform.Mappable)
  473. thing. `doc` should be the new document to which we are mapping.
  474. */
  475. abstract map(doc: Node, mapping: Mappable): Selection;
  476. /**
  477. Get the content of this selection as a slice.
  478. */
  479. content(): Slice;
  480. /**
  481. Replace the selection with a slice or, if no slice is given,
  482. delete the selection. Will append to the given transaction.
  483. */
  484. replace(tr: Transaction, content?: Slice): void;
  485. /**
  486. Replace the selection with the given node, appending the changes
  487. to the given transaction.
  488. */
  489. replaceWith(tr: Transaction, node: Node): void;
  490. /**
  491. Convert the selection to a JSON representation. When implementing
  492. this for a custom selection class, make sure to give the object a
  493. `type` property whose value matches the ID under which you
  494. [registered](https://prosemirror.net/docs/ref/#state.Selection^jsonID) your class.
  495. */
  496. abstract toJSON(): any;
  497. /**
  498. Find a valid cursor or leaf node selection starting at the given
  499. position and searching back if `dir` is negative, and forward if
  500. positive. When `textOnly` is true, only consider cursor
  501. selections. Will return null when no valid selection position is
  502. found.
  503. */
  504. static findFrom($pos: ResolvedPos, dir: number, textOnly?: boolean): Selection | null;
  505. /**
  506. Find a valid cursor or leaf node selection near the given
  507. position. Searches forward first by default, but if `bias` is
  508. negative, it will search backwards first.
  509. */
  510. static near($pos: ResolvedPos, bias?: number): Selection;
  511. /**
  512. Find the cursor or leaf node selection closest to the start of
  513. the given document. Will return an
  514. [`AllSelection`](https://prosemirror.net/docs/ref/#state.AllSelection) if no valid position
  515. exists.
  516. */
  517. static atStart(doc: Node): Selection;
  518. /**
  519. Find the cursor or leaf node selection closest to the end of the
  520. given document.
  521. */
  522. static atEnd(doc: Node): Selection;
  523. /**
  524. Deserialize the JSON representation of a selection. Must be
  525. implemented for custom classes (as a static class method).
  526. */
  527. static fromJSON(doc: Node, json: any): Selection;
  528. /**
  529. To be able to deserialize selections from JSON, custom selection
  530. classes must register themselves with an ID string, so that they
  531. can be disambiguated. Try to pick something that's unlikely to
  532. clash with classes from other modules.
  533. */
  534. static jsonID(id: string, selectionClass: {
  535. fromJSON: (doc: Node, json: any) => Selection;
  536. }): {
  537. fromJSON: (doc: Node, json: any) => Selection;
  538. };
  539. /**
  540. Get a [bookmark](https://prosemirror.net/docs/ref/#state.SelectionBookmark) for this selection,
  541. which is a value that can be mapped without having access to a
  542. current document, and later resolved to a real selection for a
  543. given document again. (This is used mostly by the history to
  544. track and restore old selections.) The default implementation of
  545. this method just converts the selection to a text selection and
  546. returns the bookmark for that.
  547. */
  548. getBookmark(): SelectionBookmark;
  549. /**
  550. Controls whether, when a selection of this type is active in the
  551. browser, the selected range should be visible to the user.
  552. Defaults to `true`.
  553. */
  554. visible: boolean;
  555. }
  556. /**
  557. A lightweight, document-independent representation of a selection.
  558. You can define a custom bookmark type for a custom selection class
  559. to make the history handle it well.
  560. */
  561. interface SelectionBookmark {
  562. /**
  563. Map the bookmark through a set of changes.
  564. */
  565. map: (mapping: Mappable) => SelectionBookmark;
  566. /**
  567. Resolve the bookmark to a real selection again. This may need to
  568. do some error checking and may fall back to a default (usually
  569. [`TextSelection.between`](https://prosemirror.net/docs/ref/#state.TextSelection^between)) if
  570. mapping made the bookmark invalid.
  571. */
  572. resolve: (doc: Node) => Selection;
  573. }
  574. /**
  575. Represents a selected range in a document.
  576. */
  577. declare class SelectionRange {
  578. /**
  579. The lower bound of the range.
  580. */
  581. readonly $from: ResolvedPos;
  582. /**
  583. The upper bound of the range.
  584. */
  585. readonly $to: ResolvedPos;
  586. /**
  587. Create a range.
  588. */
  589. constructor(
  590. /**
  591. The lower bound of the range.
  592. */
  593. $from: ResolvedPos,
  594. /**
  595. The upper bound of the range.
  596. */
  597. $to: ResolvedPos);
  598. }
  599. /**
  600. A text selection represents a classical editor selection, with a
  601. head (the moving side) and anchor (immobile side), both of which
  602. point into textblock nodes. It can be empty (a regular cursor
  603. position).
  604. */
  605. declare class TextSelection extends Selection {
  606. /**
  607. Construct a text selection between the given points.
  608. */
  609. constructor($anchor: ResolvedPos, $head?: ResolvedPos);
  610. /**
  611. Returns a resolved position if this is a cursor selection (an
  612. empty text selection), and null otherwise.
  613. */
  614. get $cursor(): ResolvedPos | null;
  615. map(doc: Node, mapping: Mappable): Selection;
  616. replace(tr: Transaction, content?: Slice): void;
  617. eq(other: Selection): boolean;
  618. getBookmark(): TextBookmark;
  619. toJSON(): any;
  620. /**
  621. Create a text selection from non-resolved positions.
  622. */
  623. static create(doc: Node, anchor: number, head?: number): TextSelection;
  624. /**
  625. Return a text selection that spans the given positions or, if
  626. they aren't text positions, find a text selection near them.
  627. `bias` determines whether the method searches forward (default)
  628. or backwards (negative number) first. Will fall back to calling
  629. [`Selection.near`](https://prosemirror.net/docs/ref/#state.Selection^near) when the document
  630. doesn't contain a valid text position.
  631. */
  632. static between($anchor: ResolvedPos, $head: ResolvedPos, bias?: number): Selection;
  633. }
  634. declare class TextBookmark {
  635. readonly anchor: number;
  636. readonly head: number;
  637. constructor(anchor: number, head: number);
  638. map(mapping: Mappable): TextBookmark;
  639. resolve(doc: Node): Selection;
  640. }
  641. /**
  642. A node selection is a selection that points at a single node. All
  643. nodes marked [selectable](https://prosemirror.net/docs/ref/#model.NodeSpec.selectable) can be the
  644. target of a node selection. In such a selection, `from` and `to`
  645. point directly before and after the selected node, `anchor` equals
  646. `from`, and `head` equals `to`..
  647. */
  648. declare class NodeSelection extends Selection {
  649. /**
  650. Create a node selection. Does not verify the validity of its
  651. argument.
  652. */
  653. constructor($pos: ResolvedPos);
  654. /**
  655. The selected node.
  656. */
  657. node: Node;
  658. map(doc: Node, mapping: Mappable): Selection;
  659. content(): Slice;
  660. eq(other: Selection): boolean;
  661. toJSON(): any;
  662. getBookmark(): NodeBookmark;
  663. /**
  664. Create a node selection from non-resolved positions.
  665. */
  666. static create(doc: Node, from: number): NodeSelection;
  667. /**
  668. Determines whether the given node may be selected as a node
  669. selection.
  670. */
  671. static isSelectable(node: Node): boolean;
  672. }
  673. declare class NodeBookmark {
  674. readonly anchor: number;
  675. constructor(anchor: number);
  676. map(mapping: Mappable): TextBookmark | NodeBookmark;
  677. resolve(doc: Node): Selection | NodeSelection;
  678. }
  679. /**
  680. A selection type that represents selecting the whole document
  681. (which can not necessarily be expressed with a text selection, when
  682. there are for example leaf block nodes at the start or end of the
  683. document).
  684. */
  685. declare class AllSelection extends Selection {
  686. /**
  687. Create an all-selection over the given document.
  688. */
  689. constructor(doc: Node);
  690. replace(tr: Transaction, content?: Slice): void;
  691. toJSON(): any;
  692. map(doc: Node): AllSelection;
  693. eq(other: Selection): boolean;
  694. getBookmark(): {
  695. map(): any;
  696. resolve(doc: Node): AllSelection;
  697. };
  698. }
  699. export { AllSelection, Command, EditorState, EditorStateConfig, NodeSelection, Plugin, PluginKey, PluginSpec, PluginView, Selection, SelectionBookmark, SelectionRange, StateField, TextSelection, Transaction };