How to use the prosemirror-transform.Transform 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
storiesOf('Editor', module).add('stepTesting', () => {
	const schema = buildSchema();
	const doc = Node.fromJSON(schema, emptyDoc);
	const tr = new Transform(doc);
	const hydratedSteps = steps.map((step) => {
		return Step.fromJSON(schema, step);
	});
	const adjustedSteps = adjustSteps2(doc, schema, hydratedSteps, 1);
	adjustedSteps.forEach((step) => {
		tr.step(step);
	});
	const generatedDoc = tr.doc;
	// console.log(JSON.stringify(generatedDoc.toJSON()));

	return (
github pubpub / pubpub-editor / stories / stepTestStories.js View on Github external
const adjustSteps = (doc, schema, stepsToAdjust, startIndex) => {
	const tr = new Transform(doc);
	const mapping = new Mapping();
	const newSteps = [];
	stepsToAdjust.forEach((step, index) => {
		if (index < startIndex) {
			/* Before the track changes starts */
			newSteps.push(step);
			tr.step(step);
		} else if (step.from === step.to) {
			/* If it's an insertion */
			const mappedStep = step.map(mapping);
			// console.log('----');
			// console.log(JSON.stringify(mapping.maps));
			// console.log(JSON.stringify(step.toJSON()));
			// console.log(JSON.stringify(mappedStep.toJSON()));
			// console.log(mappedStep.slice.content)
			newSteps.push(mappedStep);
github pubpub / pubpub-editor / stories / stepTestStories.js View on Github external
export const adjustSteps2 = (doc, schema, stepsToAdjust, startIndex) => {
	/* The header and structure-gap-replace with replace around */
	/* is wonky because the inputRules plugin is removing '# ' */
	/* and replacing it with headers. It's a problem when we try to invert */
	/* the removal of '# ' */
	console.log('********');
	stepsToAdjust.forEach((step) => {
		console.log(JSON.stringify(step.toJSON()));
	});
	const tr = new Transform(doc);
	let mapping = new Mapping();
	// const newSteps = [];
	stepsToAdjust.forEach((step, index) => {
		console.log('Mapping is', mapping.maps, step.jsonID);
		/* TODO: need to be more rigorous about detecting mightBeInputRule */
		/* We should verify that the item that is being removed matches */
		/* one of the regexes */
		const mightBeInputRule =
			stepsToAdjust.length > index + 1 &&
			stepsToAdjust[index + 1].jsonID === 'replaceAround' &&
			step.to - step.from === 1;

		if (index < startIndex || step.jsonID !== 'replace' || mightBeInputRule) {
			/* Before the track changes starts */
			// newSteps.push(step);
			tr.step(step);
github ProseMirror / prosemirror-view / test / test-decoration.js View on Github external
it("calls onRemove when dropping decorations", () => {
      let d = doc(blockquote(p("hello"), p("abc")))
      let set = build(d, {from: 3, to: 5, name: "a"}, {pos: 10, name: "b"})
      let tr = new Transform(d).delete(2, 6), dropped = []
      set.map(tr.mapping, tr.doc, {onRemove: o => dropped.push(o.name)})
      ist(JSON.stringify(dropped), '["a"]')
      let tr2 = new Transform(d).delete(0, d.content.size), dropped2 = []
      set.map(tr2.mapping, tr2.doc, {onRemove: o => dropped2.push(o.name)})
      ist(JSON.stringify(dropped2.sort()), '["a","b"]')
    })
github ProseMirror / prosemirror-changeset / test / test-changed-range.js View on Github external
function mk(doc, change) {
  let tr = change(new Transform(doc))
  let data = new Array(tr.steps.length).fill("a")
  let set0 = ChangeSet.create(doc)
  return {doc0: doc, tr, data, set0,
          set: set0.addSteps(tr.doc, tr.mapping.maps, data)}
}
github ProseMirror / prosemirror-view / test / test-decoration.js View on Github external
function buildMap(doc, ...decorations) {
  let f = decorations.pop()
  let oldSet = build(doc, ...decorations)
  let tr = f(new Transform(doc))
  return {set: oldSet.map(tr.mapping, tr.doc), oldSet}
}
github pubpub / pubpub-editor / src / plugins / changes.js View on Github external
const amendStep = (step, doc, schema, futureSteps = []) => {
	const additionalSteps = createAdditionalSteps(step, doc, schema).filter((x) => x);
	const amendedSteps = [step, ...additionalSteps];
	const futureStepsMapping = new Mapping(
		additionalSteps.map((as) => {
			if (as.slice) {
				const size = as.slice.size;
				return new StepMap(as.from - size, 0, as.size);
			}
			return as.getMap();
		}),
	);
	//const futureStepsMapping = new Mapping(additionalSteps.map((as) => as.getMap()));
	const tr = new Transform(doc);
	console.log('  -- with futureStepsMapping', futureStepsMapping);
	amendedSteps.forEach((as) => tr.step(as));
	return {
		resultingDoc: tr.doc,
		amendedSteps: amendedSteps,
		futureSteps: futureSteps.map((fs) => fs.map(futureStepsMapping)),
	};
};
github ProseMirror / prosemirror-tables / src / copypaste.js View on Github external
export function fitSlice(nodeType, slice) {
  let node = nodeType.createAndFill()
  let tr = new Transform(node).replace(0, node.content.size, slice)
  return tr.doc
}
github pubpub / pubpub-editor / stories / stepTestingPanelsStories.js View on Github external
const createDiffDoc = (doc, schema, hydratedSteps, divergeKey) => {
	const empty = schema.nodeFromJSON(doc);
	const fixedSteps = hydratedSteps.map((step) => {
		return Step.fromJSON(schema, step.toJSON());
	});
	const adjustedSteps = adjustSteps2(empty, schema, fixedSteps, divergeKey);
	const tr = new Transform(empty);
	adjustedSteps.forEach((step) => {
		tr.step(step);
	});
	return tr.doc;
};