y-prosemirror
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -57,2 +57,4 @@ /** | ||
/** | ||
* @deprecated Use `yXmlFragmentToProseMirrorNode` instead | ||
* | ||
* Utility method to convert a Y.Doc to a Prosemirror Doc node. | ||
@@ -66,2 +68,5 @@ * | ||
/** | ||
* | ||
* @deprecated Use `yXmlFragmentToProseMirrorNode` instead | ||
* | ||
* Utility method to convert a Y.XmlFragment to a Prosemirror Doc node. | ||
@@ -75,2 +80,5 @@ * | ||
/** | ||
* | ||
* @deprecated Use `yXmlFragmentToProseMirrorNode` instead | ||
* | ||
* Utility method to convert a Y.Doc to Prosemirror compatible JSON. | ||
@@ -84,2 +92,4 @@ * | ||
/** | ||
* @deprecated Use `yXmlFragmentToProseMirrorNode` instead | ||
* | ||
* Utility method to convert a Y.Doc to Prosemirror compatible JSON. | ||
@@ -94,2 +104,4 @@ * | ||
export function relativePositionToAbsolutePosition(y: Y.Doc, documentType: Y.XmlFragment, relPos: any, mapping: ProsemirrorMapping): null | number; | ||
export function yXmlFragmentToProseMirrorFragment(yXmlFragment: Y.XmlFragment, schema: Schema): Fragment; | ||
export function yXmlFragmentToProseMirrorRootNode(yXmlFragment: Y.XmlFragment, schema: Schema): Node; | ||
/** | ||
@@ -102,1 +114,2 @@ * Either a node if type is YXmlElement or an Array of text nodes if YXmlText | ||
import { Schema } from "prosemirror-model"; | ||
import { Fragment } from "prosemirror-model"; |
@@ -70,2 +70,3 @@ export function isVisible(item: Y.Item, snapshot?: Y.Snapshot): boolean; | ||
} | ||
export function createNodeFromYElement(el: Y.XmlElement, schema: any, mapping: ProsemirrorMapping, snapshot?: Y.Snapshot, prevSnapshot?: Y.Snapshot, computeYChange?: (arg0: 'removed' | 'added', arg1: Y.ID) => any): PModel.Node | null; | ||
export function updateYFragment(y: { | ||
@@ -72,0 +73,0 @@ transact: Function; |
@@ -5,2 +5,2 @@ export * from "./plugins/cursor-plugin.js"; | ||
export { ySyncPlugin, isVisible, getRelativeSelection, ProsemirrorBinding, updateYFragment } from "./plugins/sync-plugin.js"; | ||
export { absolutePositionToRelativePosition, relativePositionToAbsolutePosition, setMeta, prosemirrorJSONToYDoc, yDocToProsemirrorJSON, yDocToProsemirror, prosemirrorToYDoc, prosemirrorJSONToYXmlFragment, yXmlFragmentToProsemirrorJSON, yXmlFragmentToProsemirror, prosemirrorToYXmlFragment } from "./lib.js"; | ||
export { absolutePositionToRelativePosition, relativePositionToAbsolutePosition, setMeta, prosemirrorJSONToYDoc, yDocToProsemirrorJSON, yDocToProsemirror, prosemirrorToYDoc, prosemirrorJSONToYXmlFragment, yXmlFragmentToProsemirrorJSON, yXmlFragmentToProsemirror, prosemirrorToYXmlFragment, yXmlFragmentToProseMirrorRootNode, yXmlFragmentToProseMirrorFragment } from "./lib.js"; |
{ | ||
"name": "y-prosemirror", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "Prosemirror bindings for Yjs", | ||
@@ -15,3 +15,4 @@ "main": "./dist/y-prosemirror.cjs", | ||
"scripts": { | ||
"dist": "rm -rf dist && rollup -c && tsc", | ||
"clean": "rm -rf dist", | ||
"dist": "npm run clean && rollup -c && tsc", | ||
"test": "npm run lint && rollup -c && node dist/test.cjs", | ||
@@ -18,0 +19,0 @@ "lint": "standard && tsc", |
@@ -1,6 +0,6 @@ | ||
import { updateYFragment } from './plugins/sync-plugin.js' // eslint-disable-line | ||
import { updateYFragment, createNodeFromYElement } from './plugins/sync-plugin.js' // eslint-disable-line | ||
import { ySyncPluginKey } from './plugins/keys.js' | ||
import * as Y from 'yjs' | ||
import { EditorView } from 'prosemirror-view' // eslint-disable-line | ||
import { Node, Schema } from 'prosemirror-model' // eslint-disable-line | ||
import { Node, Schema, Fragment } from 'prosemirror-model' // eslint-disable-line | ||
import * as error from 'lib0/error' | ||
@@ -195,2 +195,29 @@ import * as map from 'lib0/map' | ||
/** | ||
* Utility function for converting an Y.Fragment to a ProseMirror fragment. | ||
* | ||
* @param {Y.XmlFragment} yXmlFragment | ||
* @param {Schema} schema | ||
*/ | ||
export const yXmlFragmentToProseMirrorFragment = (yXmlFragment, schema) => { | ||
const fragmentContent = yXmlFragment.toArray().map((t) => | ||
createNodeFromYElement( | ||
/** @type {Y.XmlElement} */ (t), | ||
schema, | ||
new Map() | ||
) | ||
).filter((n) => n !== null) | ||
return Fragment.fromArray(fragmentContent) | ||
} | ||
/** | ||
* Utility function for converting an Y.Fragment to a ProseMirror node. | ||
* This can be used for supplying the initial content to ProseMirror state. | ||
* | ||
* @param {Y.XmlFragment} yXmlFragment | ||
* @param {Schema} schema | ||
*/ | ||
export const yXmlFragmentToProseMirrorRootNode = (yXmlFragment, schema) => | ||
schema.topNodeType.create(null, yXmlFragmentToProseMirrorFragment(yXmlFragment, schema)) | ||
/** | ||
* Utility method to convert a Prosemirror Doc Node into a Y.Doc. | ||
@@ -275,2 +302,4 @@ * | ||
/** | ||
* @deprecated Use `yXmlFragmentToProseMirrorNode` instead | ||
* | ||
* Utility method to convert a Y.Doc to a Prosemirror Doc node. | ||
@@ -288,2 +317,5 @@ * | ||
/** | ||
* | ||
* @deprecated Use `yXmlFragmentToProseMirrorNode` instead | ||
* | ||
* Utility method to convert a Y.XmlFragment to a Prosemirror Doc node. | ||
@@ -301,2 +333,5 @@ * | ||
/** | ||
* | ||
* @deprecated Use `yXmlFragmentToProseMirrorNode` instead | ||
* | ||
* Utility method to convert a Y.Doc to Prosemirror compatible JSON. | ||
@@ -316,2 +351,4 @@ * | ||
/** | ||
* @deprecated Use `yXmlFragmentToProseMirrorNode` instead | ||
* | ||
* Utility method to convert a Y.Doc to Prosemirror compatible JSON. | ||
@@ -318,0 +355,0 @@ * |
@@ -1,2 +0,1 @@ | ||
import { PluginKey } from 'prosemirror-state' // eslint-disable-line | ||
@@ -3,0 +2,0 @@ |
@@ -92,4 +92,4 @@ /** | ||
} = {}) => { | ||
let changedInitialContent = false | ||
let rerenderTimeout | ||
let initialContentChanged = false | ||
const plugin = new Plugin({ | ||
@@ -180,8 +180,4 @@ props: { | ||
} | ||
// Make sure this is called in a separate context | ||
rerenderTimeout = eventloop.timeout(0, () => { | ||
binding._forceRerender() | ||
view.dispatch(view.state.tr.setMeta(ySyncPluginKey, { binding })) | ||
onFirstRender() | ||
}) | ||
binding._forceRerender() | ||
onFirstRender() | ||
return { | ||
@@ -194,3 +190,6 @@ update: () => { | ||
if ( | ||
changedInitialContent || | ||
// If the content doesn't change initially, we don't render anything to Yjs | ||
// If the content was cleared by a user action, we want to catch the change and | ||
// represent it in Yjs | ||
initialContentChanged || | ||
view.state.doc.content.findDiffStart( | ||
@@ -200,3 +199,3 @@ view.state.doc.type.createAndFill().content | ||
) { | ||
changedInitialContent = true | ||
initialContentChanged = true | ||
if ( | ||
@@ -419,3 +418,3 @@ pluginState.addToHistory === false && | ||
this.prosemirrorView.dispatch( | ||
tr.setMeta(ySyncPluginKey, { isChangeOrigin: true }) | ||
tr.setMeta(ySyncPluginKey, { isChangeOrigin: true, binding: this }) | ||
) | ||
@@ -620,3 +619,3 @@ }) | ||
*/ | ||
const createNodeFromYElement = ( | ||
export const createNodeFromYElement = ( | ||
el, | ||
@@ -623,0 +622,0 @@ schema, |
@@ -1,2 +0,1 @@ | ||
import { Plugin } from 'prosemirror-state' // eslint-disable-line | ||
@@ -3,0 +2,0 @@ |
@@ -6,4 +6,6 @@ export * from './plugins/cursor-plugin.js' | ||
export { | ||
absolutePositionToRelativePosition, relativePositionToAbsolutePosition, setMeta, prosemirrorJSONToYDoc, yDocToProsemirrorJSON, yDocToProsemirror, prosemirrorToYDoc, | ||
prosemirrorJSONToYXmlFragment, yXmlFragmentToProsemirrorJSON, yXmlFragmentToProsemirror, prosemirrorToYXmlFragment | ||
absolutePositionToRelativePosition, relativePositionToAbsolutePosition, setMeta, | ||
prosemirrorJSONToYDoc, yDocToProsemirrorJSON, yDocToProsemirror, prosemirrorToYDoc, | ||
prosemirrorJSONToYXmlFragment, yXmlFragmentToProsemirrorJSON, yXmlFragmentToProsemirror, | ||
prosemirrorToYXmlFragment, yXmlFragmentToProseMirrorRootNode, yXmlFragmentToProseMirrorFragment | ||
} from './lib.js' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
257574
4010