How to use the prosemirror-transform.AddMarkStep function in prosemirror-transform

To help you get started, we’ve selected a few prosemirror-transform examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pubpub / pubpub-editor / stories / stepTestStories.js View on Github external
mappedStep.from + mappedStep.slice.content.size,
					schema.marks.strong.create(),
				),
			);
			tr.step(step);
		} else {
			/* If it's a deletion */
			const mappedStep = step.map(mapping);
			const invertedStep = mappedStep.invert(tr.doc);
			console.log('----');
			console.log(JSON.stringify(mappedStep.toJSON()));
			console.log(JSON.stringify(invertedStep.toJSON()));
			newSteps.push(mappedStep);
			newSteps.push(invertedStep);
			newSteps.push(
				new AddMarkStep(
					invertedStep.from,
					invertedStep.from + invertedStep.slice.content.size,
					schema.marks.strike.create(),
				),
			);
			mapping.appendMap(invertedStep.getMap());

			tr.step(mappedStep);
			tr.step(invertedStep);
		}
	});
	return newSteps;
github pubpub / pubpub-editor / src / plugins / changes.js View on Github external
if (child.marks.some((mark) => mark.type.name === 'addition')) {
			sliceIsAddition = true;
		}
	});
	if (step instanceof ReplaceStep) {
		if (sliceIsAddition) {
			return [];
		}
		// Invert the replacement...
		const deletionSize = step.to - step.from;
		const additionSize = step.slice.size;
		const addReplacedStep = new ReplaceStep(step.from, step.from, docSlice);
		const addDeletionMark = new AddMarkStep(step.from, step.to, schema.marks.deletion.create());
		const addAdditionMark =
			additionSize &&
			new AddMarkStep(
				step.from + deletionSize,
				step.to + additionSize + deletionSize,
				schema.marks.addition.create(),
			);
		return [addReplacedStep, addDeletionMark, addAdditionMark];
	}
	if (step instanceof ReplaceAroundStep) {
		throw new Error("Can't handle this step yet");
	}
	return [];
};
github pubpub / pubpub-editor / src / plugins / changes.js View on Github external
const docSlice = doc.slice(step.from, step.to);
	let sliceIsAddition = false;
	docSlice.content.forEach((child) => {
		if (child.marks.some((mark) => mark.type.name === 'addition')) {
			sliceIsAddition = true;
		}
	});
	if (step instanceof ReplaceStep) {
		if (sliceIsAddition) {
			return [];
		}
		// Invert the replacement...
		const deletionSize = step.to - step.from;
		const additionSize = step.slice.size;
		const addReplacedStep = new ReplaceStep(step.from, step.from, docSlice);
		const addDeletionMark = new AddMarkStep(step.from, step.to, schema.marks.deletion.create());
		const addAdditionMark =
			additionSize &&
			new AddMarkStep(
				step.from + deletionSize,
				step.to + additionSize + deletionSize,
				schema.marks.addition.create(),
			);
		return [addReplacedStep, addDeletionMark, addAdditionMark];
	}
	if (step instanceof ReplaceAroundStep) {
		throw new Error("Can't handle this step yet");
	}
	return [];
};