Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 */
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);
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>,
);
});
});
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;
};
function testJsonAgainstSchema(jsonInput) {
const schema = new Schema(getSpec());
const node = Node.fromJSON(schema, JSON.parse(jsonInput));
node.check();
}
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(
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;
};
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);
}
}
export const modelToEditor = function(doc, schema) {
return Node.fromJSON(schema, doc.contents);
};
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);
}
}