prosemirror-changeset
Advanced tools
+6
-0
@@ -0,1 +1,7 @@ | ||
| ## 2.3.1 (2025-05-28) | ||
| ### Bug fixes | ||
| Improve diffing to not treat closing tokens of different node types as the same token. | ||
| ## 2.3.0 (2025-05-05) | ||
@@ -2,0 +8,0 @@ |
+8
-2
@@ -15,2 +15,8 @@ 'use strict'; | ||
| function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
| function typeID(type) { | ||
| var cache = type.schema.cached.changeSetIDs || (type.schema.cached.changeSetIDs = Object.create(null)); | ||
| var id = cache[type.name]; | ||
| if (id == null) cache[type.name] = id = Object.keys(type.schema.nodes).indexOf(type.name) + 1; | ||
| return id; | ||
| } | ||
| var DefaultEncoder = { | ||
@@ -23,4 +29,4 @@ encodeCharacter: function encodeCharacter(_char) { | ||
| }, | ||
| encodeNodeEnd: function encodeNodeEnd() { | ||
| return -1; | ||
| encodeNodeEnd: function encodeNodeEnd(node) { | ||
| return -typeID(node.type); | ||
| }, | ||
@@ -27,0 +33,0 @@ compareTokens: function compareTokens(a, b) { |
+12
-4
@@ -0,10 +1,18 @@ | ||
| function typeID(type) { | ||
| let cache = type.schema.cached.changeSetIDs || (type.schema.cached.changeSetIDs = Object.create(null)); | ||
| let id = cache[type.name]; | ||
| if (id == null) | ||
| cache[type.name] = id = Object.keys(type.schema.nodes).indexOf(type.name) + 1; | ||
| return id; | ||
| } | ||
| // The default token encoder, which encodes node open tokens are | ||
| // encoded as strings holding the node name, characters as their | ||
| // character code, and node close tokens as negative numbers. | ||
| const DefaultEncoder = { | ||
| encodeCharacter: char => char, | ||
| encodeNodeStart: node => node.type.name, | ||
| encodeNodeEnd: () => -1, | ||
| encodeNodeEnd: node => -typeID(node.type), | ||
| compareTokens: (a, b) => a === b | ||
| }; | ||
| // Convert the given range of a fragment to tokens, where node open | ||
| // tokens are encoded as strings holding the node name, characters as | ||
| // their character code, and node close tokens as -1. | ||
| // Convert the given range of a fragment to tokens. | ||
| function tokens(frag, encoder, start, end, target) { | ||
@@ -11,0 +19,0 @@ for (let i = 0, off = 0; i < frag.childCount; i++) { |
+1
-1
| { | ||
| "name": "prosemirror-changeset", | ||
| "version": "2.3.0", | ||
| "version": "2.3.1", | ||
| "description": "Distills a series of editing steps into deleted and added ranges", | ||
@@ -5,0 +5,0 @@ "type": "module", |
+13
-5
@@ -1,2 +0,2 @@ | ||
| import {Fragment, Node, Mark} from "prosemirror-model" | ||
| import {Fragment, Node, NodeType, Mark} from "prosemirror-model" | ||
| import {Change} from "./change" | ||
@@ -26,12 +26,20 @@ | ||
| function typeID(type: NodeType) { | ||
| let cache: Record<string, number> = type.schema.cached.changeSetIDs || (type.schema.cached.changeSetIDs = Object.create(null)) | ||
| let id = cache[type.name] | ||
| if (id == null) cache[type.name] = id = Object.keys(type.schema.nodes).indexOf(type.name) + 1 | ||
| return id | ||
| } | ||
| // The default token encoder, which encodes node open tokens are | ||
| // encoded as strings holding the node name, characters as their | ||
| // character code, and node close tokens as negative numbers. | ||
| export const DefaultEncoder: TokenEncoder<number | string> = { | ||
| encodeCharacter: char => char, | ||
| encodeNodeStart: node => node.type.name, | ||
| encodeNodeEnd: () => -1, | ||
| encodeNodeEnd: node => -typeID(node.type), | ||
| compareTokens: (a, b) => a === b | ||
| } | ||
| // Convert the given range of a fragment to tokens, where node open | ||
| // tokens are encoded as strings holding the node name, characters as | ||
| // their character code, and node close tokens as -1. | ||
| // Convert the given range of a fragment to tokens. | ||
| function tokens<T>(frag: Fragment, encoder: TokenEncoder<T>, start: number, end: number, target: T[]) { | ||
@@ -38,0 +46,0 @@ for (let i = 0, off = 0; i < frag.childCount; i++) { |
@@ -66,2 +66,5 @@ import ist from "ist" | ||
| test(doc(p("abcbcd")), doc(p("abcd")), [4, 6, 4, 4])) | ||
| it("sees the difference between different closing tokens", () => | ||
| test(doc(p("a")), doc(h1("oo")), [0, 3, 0, 4])) | ||
| }) |
120945
1.07%2383
0.97%