在一个非常基本的示例中,重基准化不起作用
作者: mitar创建于 2018年11月23日更新于 2026年4月7日
const {rebaseSteps} = require('prosemirror-collab');
const {Step, Transform} = require('prosemirror-transform');
const {Schema} = require('prosemirror-model');
const nodes = {
doc: {
content: 'title (paragraph|block)+',
},
title: {
content: 'inline*',
parseDOM: [{
tag: 'h1',
}],
toDOM(node) {
return ['h1', 0];
},
},
paragraph: {
content: 'inline*',
group: 'block',
parseDOM: [{
tag: 'p',
}],
toDOM(node) {
return ['p', 0];
},
},
text: {
group: 'inline',
},
};
const marks = {};
const schema = new Schema({nodes, marks});
const INITIAL_STEPS = [{
stepType: 'replace',
from: 3,
to: 3,
slice: {
content: [{
type: 'text',
text: 't',
}],
},
}, {
stepType: 'replace',
from: 4,
to: 4,
slice: {
content: [{
type: 'text',
text: 'e',
}],
},
}, {
stepType: 'replace',
from: 5,
to: 5,
slice: {
content: [{
type: 'text',
text: 's',
}],
},
}, {
stepType: 'replace',
from: 6,
to: 6,
slice: {
content: [{
type: 'text',
text: 't',
}],
},
}];
const FORK1_STEPS = [{
stepType: 'replace',
from: 7,
to: 7,
slice: {
content: [{
type: 'text',
text: '.',
}],
},
}];
const FORK2_STEPS = [{
stepType: 'replace',
from: 3,
to: 4,
slice: {
content: [{
type: 'text',
text: 'T',
}],
},
}];
const doc = schema.topNodeType.createAndFill();
const transform = new Transform(doc);
const initialSteps = [];
for (const step of INITIAL_STEPS) {
initialSteps.push(Step.fromJSON(schema, step));
transform.step(initialSteps[initialSteps.length - 1]);
}
const fork2steps = [];
for (const step of FORK2_STEPS) {
fork2steps.push(Step.fromJSON(schema, step));
transform.step(fork2steps[fork2steps.length - 1]);
}
const fork1steps = [];
for (const step of FORK1_STEPS) {
fork1steps.push(Step.fromJSON(schema, step));
}
rebaseSteps(fork2steps.map((s, i) => {
return {
step: s,
inverted: s.invert(transform.docs[initialSteps.length + i]),
};
}), fork1steps, transform);
console.log(transform.doc.toJSON().content[1]);内容来源: ProseMirror/prosemirror