prosemirror-transform
Advanced tools
Comparing version 1.9.0 to 1.10.0
@@ -0,1 +1,7 @@ | ||
## 1.10.0 (2024-08-13) | ||
### New features | ||
`setBlockType` can now take a function that computes attributes for the new nodes, instead of a static attribute object. | ||
## 1.9.0 (2024-05-06) | ||
@@ -2,0 +8,0 @@ |
@@ -409,3 +409,3 @@ import { Node, Schema, Slice, Fragment, NodeRange, NodeType, Attrs, Mark, MarkType, ContentMatch } from 'prosemirror-model'; | ||
*/ | ||
setBlockType(from: number, to: number | undefined, type: NodeType, attrs?: Attrs | null): this; | ||
setBlockType(from: number, to: number | undefined, type: NodeType, attrs?: Attrs | null | ((oldNode: Node) => Attrs)): this; | ||
/** | ||
@@ -412,0 +412,0 @@ Change the type, attributes, and/or marks of the node at `pos`. |
{ | ||
"name": "prosemirror-transform", | ||
"version": "1.9.0", | ||
"version": "1.10.0", | ||
"description": "ProseMirror document transformations", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -115,7 +115,10 @@ import {Slice, Fragment, NodeRange, NodeType, Node, Mark, Attrs, ContentMatch} from "prosemirror-model" | ||
export function setBlockType(tr: Transform, from: number, to: number, type: NodeType, attrs: Attrs | null) { | ||
export function setBlockType(tr: Transform, from: number, to: number, | ||
type: NodeType, attrs: Attrs | null | ((oldNode: Node) => Attrs)) { | ||
if (!type.isTextblock) throw new RangeError("Type given to setBlockType should be a textblock") | ||
let mapFrom = tr.steps.length | ||
tr.doc.nodesBetween(from, to, (node, pos) => { | ||
if (node.isTextblock && !node.hasMarkup(type, attrs) && canChangeType(tr.doc, tr.mapping.slice(mapFrom).map(pos), type)) { | ||
let attrsHere = typeof attrs == "function" ? attrs(node) : attrs | ||
if (node.isTextblock && !node.hasMarkup(type, attrsHere) && | ||
canChangeType(tr.doc, tr.mapping.slice(mapFrom).map(pos), type)) { | ||
let convertNewlines = null | ||
@@ -133,3 +136,3 @@ if (type.schema.linebreakReplacement) { | ||
tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, | ||
new Slice(Fragment.from(type.create(attrs, null, node.marks)), 0, 0), 1, true)) | ||
new Slice(Fragment.from(type.create(attrsHere, null, node.marks)), 0, 0), 1, true)) | ||
if (convertNewlines === true) replaceNewlines(tr, node, pos, mapFrom) | ||
@@ -136,0 +139,0 @@ return false |
@@ -169,3 +169,3 @@ import {Node, NodeType, Mark, MarkType, ContentMatch, Slice, Fragment, NodeRange, Attrs} from "prosemirror-model" | ||
/// the given node type with the given attributes. | ||
setBlockType(from: number, to = from, type: NodeType, attrs: Attrs | null = null): this { | ||
setBlockType(from: number, to = from, type: NodeType, attrs: Attrs | null | ((oldNode: Node) => Attrs) = null): this { | ||
setBlockType(this, from, to, type, attrs) | ||
@@ -172,0 +172,0 @@ return this |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
309592
6528