How to use the prosemirror-model.Node.fromJSON function in prosemirror-model

To help you get started, we’ve selected a few prosemirror-model 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 / src / plugins / collaborativeold.js View on Github external
Object.keys(changesSnapshotVal).forEach((key) => {
					const compressedStepsJSON = changesSnapshotVal[key].s;
					const uncompressedSteps = compressedStepsJSON.map((compressedStepJSON) => {
						return Step.fromJSON(
							this.view.state.schema,
							uncompressStepJSON(compressedStepJSON),
						);
					});
					steps.push(...uncompressedSteps);
					stepClientIds.push(
						...new Array(compressedStepsJSON.length).fill(changesSnapshotVal[key].c),
					);
				});

				/* Update the prosemirror view with new doc */
				const newDoc = Node.fromJSON(
					this.view.state.schema,
					this.pluginProps.initialContent,
				);
				this.view.updateState(
					EditorState.create({
						doc: newDoc,
						plugins: this.view.state.plugins,
					}),
				);

				this.pluginProps.onUpdateLatestKey(this.mostRecentRemoteKey);

				const trans = receiveTransaction(this.view.state, steps, stepClientIds);
				this.view.dispatch(trans);

				/* Retrieve and Listen to Cursors */
github zodiac-team / zodiac-ui / libs / editor / src / lib / editor.service.ts View on Github external
createEditorState(state) {
        this.config = createConfig(this.plugins, {})
        const schema = createSchema(this.config)
        const dispatch = createDispatch(this.eventDispatcher)
        const doc = Node.fromJSON(schema, state ? state.doc : defaultState)
        const selection = state ? Selection.fromJSON(doc, state.selection) : undefined
        // const errorReporter = createErrorReporter(errorReporterHandler);

        const plugins = createPMPlugins({
            schema,
            dispatch,
            editorConfig: this.config,
            eventDispatcher: this.eventDispatcher,
        })

        // let doc;
        // if (options.replaceDoc) {
        //     doc =
        //         this.contentTransformer && typeof defaultValue === 'string'
        //             ? this.contentTransformer.parse(defaultValue)
        //             : processRawValue(schema, defaultValue);
github ifiokjr / remirror / @remirror / react-renderer / src / __tests__ / react-serializer.spec.tsx View on Github external
it('serializes a deeply nested custom node', () => {
      const node = PMNode.fromJSON(schema, {
        type: 'foo',
        content: [{ type: 'paragraph', content: [{ type: 'text', text: 'This is the foo thing' }] }],
      });

      expect(shallow(serializer.serializeNode(node) as JSX.Element)).toMatchElement(
        <div data-foo-type="true">
          <div>
            <p>This is the foo thing</p>
          </div>
        </div>,
      );
    });
  });
github pubpub / pubpub-editor / src / __tests__ / utils / editor.js View on Github external
export const createEditorViewWithInitialDoc = (doc = getEmptyDoc(), plugins = []) => {
	const editorState = EditorState.create({
		schema: schema,
		doc: Node.fromJSON(schema, doc),
		plugins: plugins,
	});
	const editorView = new EditorView(null, { state: editorState });
	return editorView;
};
github cosmocode / dokuwiki-plugin-prosemirror / _jstest / testmodule.js View on Github external
function testJsonAgainstSchema(jsonInput) {
    const schema = new Schema(getSpec());
    const node = Node.fromJSON(schema, JSON.parse(jsonInput));
    node.check();
}
github xylk / prosemirror-firebase / src / index.js View on Github external
function (snapshot) {
        progress(1 / 2)
        let { d, k: latestKey = -1 } = snapshot.val() || {}
        latestKey = Number(latestKey)
        stateConfig.doc = d && Node.fromJSON(stateConfig.schema, uncompressStateJSON({ d }).doc)
        stateConfig.plugins = (stateConfig.plugins || []).concat(collab({ clientID: selfClientID }))

        function compressedStepJSONToStep(compressedStepJSON) {
          return Step.fromJSON(stateConfig.schema, uncompressStepJSON(compressedStepJSON)) }

        function updateCollab({ docChanged, mapping }, newState) {
          if (docChanged) {
            for (let clientID in selections) {
              selections[clientID] = selections[clientID].map(newState.doc, mapping)
            }
          }

          const sendable = sendableSteps(newState)
          if (sendable) {
            const { steps, clientID } = sendable
            changesRef.child(latestKey + 1).transaction(
github pubpub / pubpub-editor / src / utils / index.js View on Github external
export const importDocJson = (editorView, docJson) => {
	const doc = Node.fromJSON(editorView.state.schema, docJson);
	const tr = editorView.state.tr;
	tr.setSelection(Selection.atStart(editorView.state.doc));
	tr.replaceSelection(new Slice(doc.content, 0, 0));
	editorView.dispatch(tr);
	return doc;
};
github gamejolt / frontend-lib / components / content / content-editor / content-editor.ts View on Github external
public setContent(doc: ContentDocument) {
		if (doc.context !== this.contentContext) {
			throw new Error(
				`The passed in content context is invalid. ${doc.context} != ${this.contentContext}`
			);
		}
		if (this.schema instanceof ContentEditorSchema) {
			this.hydrator = new ContentHydrator(doc.hydration);
			const jsonObj = ContentFormatAdapter.adaptIn(doc);
			const state = EditorState.create({
				doc: Node.fromJSON(this.schema, jsonObj),
				plugins: this.plugins,
			});
			this.createView(state);
		}
	}
github pubpub / pubpub-editor / packages / pubpub-prose / src / prosemirror-setup / collab / node-convert.js View on Github external
export const modelToEditor = function(doc, schema) {
	return Node.fromJSON(schema, doc.contents);
};
github taktik / icure-backend / web / icure-ht / app / src / elements / prose-editor / prose-editor / prose-editor.ts View on Github external
setJSONContent(doc:string) {
    if (this.editorView) {
      const node = Node.fromJSON(this.editorSchema, JSON.parse(doc))
      let newState = EditorState.create({schema: this.editorSchema, doc: node, plugins: this.editorView.state.plugins});
      this.editorView.updateState(newState);
    }
  }