Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Prosemirror - transactions

node v10.17.0
version: 1.1.2
endpointsharetweet
const { Schema, Slice } = require('prosemirror-model'); const { Transform } = require('prosemirror-transform'); const { EditorState } = require('prosemirror-state'); const { nodes, marks } = require('prosemirror-schema-basic'); const schema = new Schema({ nodes, marks, });
const doc = (...children) => schema.node('doc', null, children); const p = (...children) => schema.node('paragraph', null, children); const textNode = (content, marks = null) => schema.text(content, marks); const emptyState = EditorState.create({ doc: doc(p()), schema, });
Trying out `insertText`
const apply2StepsInsertText = () => { const step1Transaction = emptyState.tr.insertText('hello', 1); const step1State = emptyState.apply(step1Transaction); const step2Transaction = step1Transaction.insertText('a', 2); const step2State = emptyState.apply(step2Transaction); return { step1Transaction, step1State, step2Transaction, step2State } } states = apply2StepsInsertText(); output = { step1: JSON.stringify(states.step1State.doc.toJSON()), step2: JSON.stringify(states.step2State.doc.toJSON()) }
Trying out `replaceWith`
const apply2StepsReplaceStep = () => { const step1Transaction = emptyState.tr.replaceWith(1, 1, textNode('hello')); const step1State = emptyState.apply(step1Transaction); const step2Transaction = step1State.tr.replaceWith(2, 2, textNode('a')); const step2State = step1State.apply(step2Transaction); return { step1Transaction, step1State, step2Transaction, step2State } } states = apply2StepsReplaceStep(); output = { step1: JSON.stringify(states.step1State.doc.toJSON()), step2: JSON.stringify(states.step2State.doc.toJSON()) }
Loading…

no comments

    sign in to comment