index.d.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. import { Node, Schema, Slice, Fragment, NodeRange, NodeType, Attrs, Mark, MarkType, ContentMatch } from 'prosemirror-model';
  2. /**
  3. There are several things that positions can be mapped through.
  4. Such objects conform to this interface.
  5. */
  6. interface Mappable {
  7. /**
  8. Map a position through this object. When given, `assoc` (should
  9. be -1 or 1, defaults to 1) determines with which side the
  10. position is associated, which determines in which direction to
  11. move when a chunk of content is inserted at the mapped position.
  12. */
  13. map: (pos: number, assoc?: number) => number;
  14. /**
  15. Map a position, and return an object containing additional
  16. information about the mapping. The result's `deleted` field tells
  17. you whether the position was deleted (completely enclosed in a
  18. replaced range) during the mapping. When content on only one side
  19. is deleted, the position itself is only considered deleted when
  20. `assoc` points in the direction of the deleted content.
  21. */
  22. mapResult: (pos: number, assoc?: number) => MapResult;
  23. }
  24. /**
  25. An object representing a mapped position with extra
  26. information.
  27. */
  28. declare class MapResult {
  29. /**
  30. The mapped version of the position.
  31. */
  32. readonly pos: number;
  33. /**
  34. Tells you whether the position was deleted, that is, whether the
  35. step removed the token on the side queried (via the `assoc`)
  36. argument from the document.
  37. */
  38. get deleted(): boolean;
  39. /**
  40. Tells you whether the token before the mapped position was deleted.
  41. */
  42. get deletedBefore(): boolean;
  43. /**
  44. True when the token after the mapped position was deleted.
  45. */
  46. get deletedAfter(): boolean;
  47. /**
  48. Tells whether any of the steps mapped through deletes across the
  49. position (including both the token before and after the
  50. position).
  51. */
  52. get deletedAcross(): boolean;
  53. }
  54. /**
  55. A map describing the deletions and insertions made by a step, which
  56. can be used to find the correspondence between positions in the
  57. pre-step version of a document and the same position in the
  58. post-step version.
  59. */
  60. declare class StepMap implements Mappable {
  61. /**
  62. Create a position map. The modifications to the document are
  63. represented as an array of numbers, in which each group of three
  64. represents a modified chunk as `[start, oldSize, newSize]`.
  65. */
  66. constructor(
  67. /**
  68. @internal
  69. */
  70. ranges: readonly number[],
  71. /**
  72. @internal
  73. */
  74. inverted?: boolean);
  75. mapResult(pos: number, assoc?: number): MapResult;
  76. map(pos: number, assoc?: number): number;
  77. /**
  78. Calls the given function on each of the changed ranges included in
  79. this map.
  80. */
  81. forEach(f: (oldStart: number, oldEnd: number, newStart: number, newEnd: number) => void): void;
  82. /**
  83. Create an inverted version of this map. The result can be used to
  84. map positions in the post-step document to the pre-step document.
  85. */
  86. invert(): StepMap;
  87. /**
  88. Create a map that moves all positions by offset `n` (which may be
  89. negative). This can be useful when applying steps meant for a
  90. sub-document to a larger document, or vice-versa.
  91. */
  92. static offset(n: number): StepMap;
  93. /**
  94. A StepMap that contains no changed ranges.
  95. */
  96. static empty: StepMap;
  97. }
  98. /**
  99. A mapping represents a pipeline of zero or more [step
  100. maps](https://prosemirror.net/docs/ref/#transform.StepMap). It has special provisions for losslessly
  101. handling mapping positions through a series of steps in which some
  102. steps are inverted versions of earlier steps. (This comes up when
  103. ‘[rebasing](/docs/guide/#transform.rebasing)’ steps for
  104. collaboration or history management.)
  105. */
  106. declare class Mapping implements Mappable {
  107. /**
  108. The step maps in this mapping.
  109. */
  110. readonly maps: StepMap[];
  111. /**
  112. The starting position in the `maps` array, used when `map` or
  113. `mapResult` is called.
  114. */
  115. from: number;
  116. /**
  117. The end position in the `maps` array.
  118. */
  119. to: number;
  120. /**
  121. Create a new mapping with the given position maps.
  122. */
  123. constructor(
  124. /**
  125. The step maps in this mapping.
  126. */
  127. maps?: StepMap[],
  128. /**
  129. @internal
  130. */
  131. mirror?: number[] | undefined,
  132. /**
  133. The starting position in the `maps` array, used when `map` or
  134. `mapResult` is called.
  135. */
  136. from?: number,
  137. /**
  138. The end position in the `maps` array.
  139. */
  140. to?: number);
  141. /**
  142. Create a mapping that maps only through a part of this one.
  143. */
  144. slice(from?: number, to?: number): Mapping;
  145. /**
  146. Add a step map to the end of this mapping. If `mirrors` is
  147. given, it should be the index of the step map that is the mirror
  148. image of this one.
  149. */
  150. appendMap(map: StepMap, mirrors?: number): void;
  151. /**
  152. Add all the step maps in a given mapping to this one (preserving
  153. mirroring information).
  154. */
  155. appendMapping(mapping: Mapping): void;
  156. /**
  157. Finds the offset of the step map that mirrors the map at the
  158. given offset, in this mapping (as per the second argument to
  159. `appendMap`).
  160. */
  161. getMirror(n: number): number | undefined;
  162. /**
  163. Append the inverse of the given mapping to this one.
  164. */
  165. appendMappingInverted(mapping: Mapping): void;
  166. /**
  167. Create an inverted version of this mapping.
  168. */
  169. invert(): Mapping;
  170. /**
  171. Map a position through this mapping.
  172. */
  173. map(pos: number, assoc?: number): number;
  174. /**
  175. Map a position through this mapping, returning a mapping
  176. result.
  177. */
  178. mapResult(pos: number, assoc?: number): MapResult;
  179. }
  180. /**
  181. A step object represents an atomic change. It generally applies
  182. only to the document it was created for, since the positions
  183. stored in it will only make sense for that document.
  184. New steps are defined by creating classes that extend `Step`,
  185. overriding the `apply`, `invert`, `map`, `getMap` and `fromJSON`
  186. methods, and registering your class with a unique
  187. JSON-serialization identifier using
  188. [`Step.jsonID`](https://prosemirror.net/docs/ref/#transform.Step^jsonID).
  189. */
  190. declare abstract class Step {
  191. /**
  192. Applies this step to the given document, returning a result
  193. object that either indicates failure, if the step can not be
  194. applied to this document, or indicates success by containing a
  195. transformed document.
  196. */
  197. abstract apply(doc: Node): StepResult;
  198. /**
  199. Get the step map that represents the changes made by this step,
  200. and which can be used to transform between positions in the old
  201. and the new document.
  202. */
  203. getMap(): StepMap;
  204. /**
  205. Create an inverted version of this step. Needs the document as it
  206. was before the step as argument.
  207. */
  208. abstract invert(doc: Node): Step;
  209. /**
  210. Map this step through a mappable thing, returning either a
  211. version of that step with its positions adjusted, or `null` if
  212. the step was entirely deleted by the mapping.
  213. */
  214. abstract map(mapping: Mappable): Step | null;
  215. /**
  216. Try to merge this step with another one, to be applied directly
  217. after it. Returns the merged step when possible, null if the
  218. steps can't be merged.
  219. */
  220. merge(other: Step): Step | null;
  221. /**
  222. Create a JSON-serializeable representation of this step. When
  223. defining this for a custom subclass, make sure the result object
  224. includes the step type's [JSON id](https://prosemirror.net/docs/ref/#transform.Step^jsonID) under
  225. the `stepType` property.
  226. */
  227. abstract toJSON(): any;
  228. /**
  229. Deserialize a step from its JSON representation. Will call
  230. through to the step class' own implementation of this method.
  231. */
  232. static fromJSON(schema: Schema, json: any): Step;
  233. /**
  234. To be able to serialize steps to JSON, each step needs a string
  235. ID to attach to its JSON representation. Use this method to
  236. register an ID for your step classes. Try to pick something
  237. that's unlikely to clash with steps from other modules.
  238. */
  239. static jsonID(id: string, stepClass: {
  240. fromJSON(schema: Schema, json: any): Step;
  241. }): {
  242. fromJSON(schema: Schema, json: any): Step;
  243. };
  244. }
  245. /**
  246. The result of [applying](https://prosemirror.net/docs/ref/#transform.Step.apply) a step. Contains either a
  247. new document or a failure value.
  248. */
  249. declare class StepResult {
  250. /**
  251. The transformed document, if successful.
  252. */
  253. readonly doc: Node | null;
  254. /**
  255. The failure message, if unsuccessful.
  256. */
  257. readonly failed: string | null;
  258. /**
  259. Create a successful step result.
  260. */
  261. static ok(doc: Node): StepResult;
  262. /**
  263. Create a failed step result.
  264. */
  265. static fail(message: string): StepResult;
  266. /**
  267. Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given
  268. arguments. Create a successful result if it succeeds, and a
  269. failed one if it throws a `ReplaceError`.
  270. */
  271. static fromReplace(doc: Node, from: number, to: number, slice: Slice): StepResult;
  272. }
  273. /**
  274. Abstraction to build up and track an array of
  275. [steps](https://prosemirror.net/docs/ref/#transform.Step) representing a document transformation.
  276. Most transforming methods return the `Transform` object itself, so
  277. that they can be chained.
  278. */
  279. declare class Transform {
  280. /**
  281. The current document (the result of applying the steps in the
  282. transform).
  283. */
  284. doc: Node;
  285. /**
  286. The steps in this transform.
  287. */
  288. readonly steps: Step[];
  289. /**
  290. The documents before each of the steps.
  291. */
  292. readonly docs: Node[];
  293. /**
  294. A mapping with the maps for each of the steps in this transform.
  295. */
  296. readonly mapping: Mapping;
  297. /**
  298. Create a transform that starts with the given document.
  299. */
  300. constructor(
  301. /**
  302. The current document (the result of applying the steps in the
  303. transform).
  304. */
  305. doc: Node);
  306. /**
  307. The starting document.
  308. */
  309. get before(): Node;
  310. /**
  311. Apply a new step in this transform, saving the result. Throws an
  312. error when the step fails.
  313. */
  314. step(step: Step): this;
  315. /**
  316. Try to apply a step in this transformation, ignoring it if it
  317. fails. Returns the step result.
  318. */
  319. maybeStep(step: Step): StepResult;
  320. /**
  321. True when the document has been changed (when there are any
  322. steps).
  323. */
  324. get docChanged(): boolean;
  325. /**
  326. Replace the part of the document between `from` and `to` with the
  327. given `slice`.
  328. */
  329. replace(from: number, to?: number, slice?: Slice): this;
  330. /**
  331. Replace the given range with the given content, which may be a
  332. fragment, node, or array of nodes.
  333. */
  334. replaceWith(from: number, to: number, content: Fragment | Node | readonly Node[]): this;
  335. /**
  336. Delete the content between the given positions.
  337. */
  338. delete(from: number, to: number): this;
  339. /**
  340. Insert the given content at the given position.
  341. */
  342. insert(pos: number, content: Fragment | Node | readonly Node[]): this;
  343. /**
  344. Replace a range of the document with a given slice, using
  345. `from`, `to`, and the slice's
  346. [`openStart`](https://prosemirror.net/docs/ref/#model.Slice.openStart) property as hints, rather
  347. than fixed start and end points. This method may grow the
  348. replaced area or close open nodes in the slice in order to get a
  349. fit that is more in line with WYSIWYG expectations, by dropping
  350. fully covered parent nodes of the replaced region when they are
  351. marked [non-defining as
  352. context](https://prosemirror.net/docs/ref/#model.NodeSpec.definingAsContext), or including an
  353. open parent node from the slice that _is_ marked as [defining
  354. its content](https://prosemirror.net/docs/ref/#model.NodeSpec.definingForContent).
  355. This is the method, for example, to handle paste. The similar
  356. [`replace`](https://prosemirror.net/docs/ref/#transform.Transform.replace) method is a more
  357. primitive tool which will _not_ move the start and end of its given
  358. range, and is useful in situations where you need more precise
  359. control over what happens.
  360. */
  361. replaceRange(from: number, to: number, slice: Slice): this;
  362. /**
  363. Replace the given range with a node, but use `from` and `to` as
  364. hints, rather than precise positions. When from and to are the same
  365. and are at the start or end of a parent node in which the given
  366. node doesn't fit, this method may _move_ them out towards a parent
  367. that does allow the given node to be placed. When the given range
  368. completely covers a parent node, this method may completely replace
  369. that parent node.
  370. */
  371. replaceRangeWith(from: number, to: number, node: Node): this;
  372. /**
  373. Delete the given range, expanding it to cover fully covered
  374. parent nodes until a valid replace is found.
  375. */
  376. deleteRange(from: number, to: number): this;
  377. /**
  378. Split the content in the given range off from its parent, if there
  379. is sibling content before or after it, and move it up the tree to
  380. the depth specified by `target`. You'll probably want to use
  381. [`liftTarget`](https://prosemirror.net/docs/ref/#transform.liftTarget) to compute `target`, to make
  382. sure the lift is valid.
  383. */
  384. lift(range: NodeRange, target: number): this;
  385. /**
  386. Join the blocks around the given position. If depth is 2, their
  387. last and first siblings are also joined, and so on.
  388. */
  389. join(pos: number, depth?: number): this;
  390. /**
  391. Wrap the given [range](https://prosemirror.net/docs/ref/#model.NodeRange) in the given set of wrappers.
  392. The wrappers are assumed to be valid in this position, and should
  393. probably be computed with [`findWrapping`](https://prosemirror.net/docs/ref/#transform.findWrapping).
  394. */
  395. wrap(range: NodeRange, wrappers: readonly {
  396. type: NodeType;
  397. attrs?: Attrs | null;
  398. }[]): this;
  399. /**
  400. Set the type of all textblocks (partly) between `from` and `to` to
  401. the given node type with the given attributes.
  402. */
  403. setBlockType(from: number, to: number | undefined, type: NodeType, attrs?: Attrs | null): this;
  404. /**
  405. Change the type, attributes, and/or marks of the node at `pos`.
  406. When `type` isn't given, the existing node type is preserved,
  407. */
  408. setNodeMarkup(pos: number, type?: NodeType | null, attrs?: Attrs | null, marks?: readonly Mark[]): this;
  409. /**
  410. Set a single attribute on a given node to a new value.
  411. The `pos` addresses the document content. Use `setDocAttribute`
  412. to set attributes on the document itself.
  413. */
  414. setNodeAttribute(pos: number, attr: string, value: any): this;
  415. /**
  416. Set a single attribute on the document to a new value.
  417. */
  418. setDocAttribute(attr: string, value: any): this;
  419. /**
  420. Add a mark to the node at position `pos`.
  421. */
  422. addNodeMark(pos: number, mark: Mark): this;
  423. /**
  424. Remove a mark (or a mark of the given type) from the node at
  425. position `pos`.
  426. */
  427. removeNodeMark(pos: number, mark: Mark | MarkType): this;
  428. /**
  429. Split the node at the given position, and optionally, if `depth` is
  430. greater than one, any number of nodes above that. By default, the
  431. parts split off will inherit the node type of the original node.
  432. This can be changed by passing an array of types and attributes to
  433. use after the split.
  434. */
  435. split(pos: number, depth?: number, typesAfter?: (null | {
  436. type: NodeType;
  437. attrs?: Attrs | null;
  438. })[]): this;
  439. /**
  440. Add the given mark to the inline content between `from` and `to`.
  441. */
  442. addMark(from: number, to: number, mark: Mark): this;
  443. /**
  444. Remove marks from inline nodes between `from` and `to`. When
  445. `mark` is a single mark, remove precisely that mark. When it is
  446. a mark type, remove all marks of that type. When it is null,
  447. remove all marks of any type.
  448. */
  449. removeMark(from: number, to: number, mark?: Mark | MarkType | null): this;
  450. /**
  451. Removes all marks and nodes from the content of the node at
  452. `pos` that don't match the given new parent node type. Accepts
  453. an optional starting [content match](https://prosemirror.net/docs/ref/#model.ContentMatch) as
  454. third argument.
  455. */
  456. clearIncompatible(pos: number, parentType: NodeType, match?: ContentMatch): this;
  457. }
  458. /**
  459. Try to find a target depth to which the content in the given range
  460. can be lifted. Will not go across
  461. [isolating](https://prosemirror.net/docs/ref/#model.NodeSpec.isolating) parent nodes.
  462. */
  463. declare function liftTarget(range: NodeRange): number | null;
  464. /**
  465. Try to find a valid way to wrap the content in the given range in a
  466. node of the given type. May introduce extra nodes around and inside
  467. the wrapper node, if necessary. Returns null if no valid wrapping
  468. could be found. When `innerRange` is given, that range's content is
  469. used as the content to fit into the wrapping, instead of the
  470. content of `range`.
  471. */
  472. declare function findWrapping(range: NodeRange, nodeType: NodeType, attrs?: Attrs | null, innerRange?: NodeRange): {
  473. type: NodeType;
  474. attrs: Attrs | null;
  475. }[] | null;
  476. /**
  477. Check whether splitting at the given position is allowed.
  478. */
  479. declare function canSplit(doc: Node, pos: number, depth?: number, typesAfter?: (null | {
  480. type: NodeType;
  481. attrs?: Attrs | null;
  482. })[]): boolean;
  483. /**
  484. Test whether the blocks before and after a given position can be
  485. joined.
  486. */
  487. declare function canJoin(doc: Node, pos: number): boolean;
  488. /**
  489. Find an ancestor of the given position that can be joined to the
  490. block before (or after if `dir` is positive). Returns the joinable
  491. point, if any.
  492. */
  493. declare function joinPoint(doc: Node, pos: number, dir?: number): number | undefined;
  494. /**
  495. Try to find a point where a node of the given type can be inserted
  496. near `pos`, by searching up the node hierarchy when `pos` itself
  497. isn't a valid place but is at the start or end of a node. Return
  498. null if no position was found.
  499. */
  500. declare function insertPoint(doc: Node, pos: number, nodeType: NodeType): number | null;
  501. /**
  502. Finds a position at or around the given position where the given
  503. slice can be inserted. Will look at parent nodes' nearest boundary
  504. and try there, even if the original position wasn't directly at the
  505. start or end of that node. Returns null when no position was found.
  506. */
  507. declare function dropPoint(doc: Node, pos: number, slice: Slice): number | null;
  508. /**
  509. Add a mark to all inline content between two positions.
  510. */
  511. declare class AddMarkStep extends Step {
  512. /**
  513. The start of the marked range.
  514. */
  515. readonly from: number;
  516. /**
  517. The end of the marked range.
  518. */
  519. readonly to: number;
  520. /**
  521. The mark to add.
  522. */
  523. readonly mark: Mark;
  524. /**
  525. Create a mark step.
  526. */
  527. constructor(
  528. /**
  529. The start of the marked range.
  530. */
  531. from: number,
  532. /**
  533. The end of the marked range.
  534. */
  535. to: number,
  536. /**
  537. The mark to add.
  538. */
  539. mark: Mark);
  540. apply(doc: Node): StepResult;
  541. invert(): Step;
  542. map(mapping: Mappable): Step | null;
  543. merge(other: Step): Step | null;
  544. toJSON(): any;
  545. }
  546. /**
  547. Remove a mark from all inline content between two positions.
  548. */
  549. declare class RemoveMarkStep extends Step {
  550. /**
  551. The start of the unmarked range.
  552. */
  553. readonly from: number;
  554. /**
  555. The end of the unmarked range.
  556. */
  557. readonly to: number;
  558. /**
  559. The mark to remove.
  560. */
  561. readonly mark: Mark;
  562. /**
  563. Create a mark-removing step.
  564. */
  565. constructor(
  566. /**
  567. The start of the unmarked range.
  568. */
  569. from: number,
  570. /**
  571. The end of the unmarked range.
  572. */
  573. to: number,
  574. /**
  575. The mark to remove.
  576. */
  577. mark: Mark);
  578. apply(doc: Node): StepResult;
  579. invert(): Step;
  580. map(mapping: Mappable): Step | null;
  581. merge(other: Step): Step | null;
  582. toJSON(): any;
  583. }
  584. /**
  585. Add a mark to a specific node.
  586. */
  587. declare class AddNodeMarkStep extends Step {
  588. /**
  589. The position of the target node.
  590. */
  591. readonly pos: number;
  592. /**
  593. The mark to add.
  594. */
  595. readonly mark: Mark;
  596. /**
  597. Create a node mark step.
  598. */
  599. constructor(
  600. /**
  601. The position of the target node.
  602. */
  603. pos: number,
  604. /**
  605. The mark to add.
  606. */
  607. mark: Mark);
  608. apply(doc: Node): StepResult;
  609. invert(doc: Node): Step;
  610. map(mapping: Mappable): Step | null;
  611. toJSON(): any;
  612. }
  613. /**
  614. Remove a mark from a specific node.
  615. */
  616. declare class RemoveNodeMarkStep extends Step {
  617. /**
  618. The position of the target node.
  619. */
  620. readonly pos: number;
  621. /**
  622. The mark to remove.
  623. */
  624. readonly mark: Mark;
  625. /**
  626. Create a mark-removing step.
  627. */
  628. constructor(
  629. /**
  630. The position of the target node.
  631. */
  632. pos: number,
  633. /**
  634. The mark to remove.
  635. */
  636. mark: Mark);
  637. apply(doc: Node): StepResult;
  638. invert(doc: Node): Step;
  639. map(mapping: Mappable): Step | null;
  640. toJSON(): any;
  641. }
  642. /**
  643. Replace a part of the document with a slice of new content.
  644. */
  645. declare class ReplaceStep extends Step {
  646. /**
  647. The start position of the replaced range.
  648. */
  649. readonly from: number;
  650. /**
  651. The end position of the replaced range.
  652. */
  653. readonly to: number;
  654. /**
  655. The slice to insert.
  656. */
  657. readonly slice: Slice;
  658. /**
  659. The given `slice` should fit the 'gap' between `from` and
  660. `to`—the depths must line up, and the surrounding nodes must be
  661. able to be joined with the open sides of the slice. When
  662. `structure` is true, the step will fail if the content between
  663. from and to is not just a sequence of closing and then opening
  664. tokens (this is to guard against rebased replace steps
  665. overwriting something they weren't supposed to).
  666. */
  667. constructor(
  668. /**
  669. The start position of the replaced range.
  670. */
  671. from: number,
  672. /**
  673. The end position of the replaced range.
  674. */
  675. to: number,
  676. /**
  677. The slice to insert.
  678. */
  679. slice: Slice,
  680. /**
  681. @internal
  682. */
  683. structure?: boolean);
  684. apply(doc: Node): StepResult;
  685. getMap(): StepMap;
  686. invert(doc: Node): ReplaceStep;
  687. map(mapping: Mappable): ReplaceStep | null;
  688. merge(other: Step): ReplaceStep | null;
  689. toJSON(): any;
  690. }
  691. /**
  692. Replace a part of the document with a slice of content, but
  693. preserve a range of the replaced content by moving it into the
  694. slice.
  695. */
  696. declare class ReplaceAroundStep extends Step {
  697. /**
  698. The start position of the replaced range.
  699. */
  700. readonly from: number;
  701. /**
  702. The end position of the replaced range.
  703. */
  704. readonly to: number;
  705. /**
  706. The start of preserved range.
  707. */
  708. readonly gapFrom: number;
  709. /**
  710. The end of preserved range.
  711. */
  712. readonly gapTo: number;
  713. /**
  714. The slice to insert.
  715. */
  716. readonly slice: Slice;
  717. /**
  718. The position in the slice where the preserved range should be
  719. inserted.
  720. */
  721. readonly insert: number;
  722. /**
  723. Create a replace-around step with the given range and gap.
  724. `insert` should be the point in the slice into which the content
  725. of the gap should be moved. `structure` has the same meaning as
  726. it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class.
  727. */
  728. constructor(
  729. /**
  730. The start position of the replaced range.
  731. */
  732. from: number,
  733. /**
  734. The end position of the replaced range.
  735. */
  736. to: number,
  737. /**
  738. The start of preserved range.
  739. */
  740. gapFrom: number,
  741. /**
  742. The end of preserved range.
  743. */
  744. gapTo: number,
  745. /**
  746. The slice to insert.
  747. */
  748. slice: Slice,
  749. /**
  750. The position in the slice where the preserved range should be
  751. inserted.
  752. */
  753. insert: number,
  754. /**
  755. @internal
  756. */
  757. structure?: boolean);
  758. apply(doc: Node): StepResult;
  759. getMap(): StepMap;
  760. invert(doc: Node): ReplaceAroundStep;
  761. map(mapping: Mappable): ReplaceAroundStep | null;
  762. toJSON(): any;
  763. }
  764. /**
  765. Update an attribute in a specific node.
  766. */
  767. declare class AttrStep extends Step {
  768. /**
  769. The position of the target node.
  770. */
  771. readonly pos: number;
  772. /**
  773. The attribute to set.
  774. */
  775. readonly attr: string;
  776. readonly value: any;
  777. /**
  778. Construct an attribute step.
  779. */
  780. constructor(
  781. /**
  782. The position of the target node.
  783. */
  784. pos: number,
  785. /**
  786. The attribute to set.
  787. */
  788. attr: string, value: any);
  789. apply(doc: Node): StepResult;
  790. getMap(): StepMap;
  791. invert(doc: Node): AttrStep;
  792. map(mapping: Mappable): AttrStep | null;
  793. toJSON(): any;
  794. static fromJSON(schema: Schema, json: any): AttrStep;
  795. }
  796. /**
  797. Update an attribute in the doc node.
  798. */
  799. declare class DocAttrStep extends Step {
  800. /**
  801. The attribute to set.
  802. */
  803. readonly attr: string;
  804. readonly value: any;
  805. /**
  806. Construct an attribute step.
  807. */
  808. constructor(
  809. /**
  810. The attribute to set.
  811. */
  812. attr: string, value: any);
  813. apply(doc: Node): StepResult;
  814. getMap(): StepMap;
  815. invert(doc: Node): DocAttrStep;
  816. map(mapping: Mappable): this;
  817. toJSON(): any;
  818. static fromJSON(schema: Schema, json: any): DocAttrStep;
  819. }
  820. /**
  821. ‘Fit’ a slice into a given position in the document, producing a
  822. [step](https://prosemirror.net/docs/ref/#transform.Step) that inserts it. Will return null if
  823. there's no meaningful way to insert the slice here, or inserting it
  824. would be a no-op (an empty slice over an empty range).
  825. */
  826. declare function replaceStep(doc: Node, from: number, to?: number, slice?: Slice): Step | null;
  827. export { AddMarkStep, AddNodeMarkStep, AttrStep, DocAttrStep, MapResult, Mappable, Mapping, RemoveMarkStep, RemoveNodeMarkStep, ReplaceAroundStep, ReplaceStep, Step, StepMap, StepResult, Transform, canJoin, canSplit, dropPoint, findWrapping, insertPoint, joinPoint, liftTarget, replaceStep };