You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

y-prosemirror

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.19 to 1.0.20

45

dist/src/lib.d.ts

@@ -14,2 +14,18 @@ /**

/**
* Utility method to update an empty Y.XmlFragment with content from a Prosemirror Doc Node.
*
* This can be used when importing existing content to Y.Doc for the first time,
* note that this should not be used to rehydrate a Y.Doc from a database once
* collaboration has begun as all history will be lost
*
* Note: The Y.XmlFragment does not need to be part of a Y.Doc document at the time that this
* method is called, but it must be added before any other operations are performed on it.
*
* @param {Node} doc prosemirror document.
* @param {Y.XmlFragment} [xmlFragment] If supplied, an xml fragment to be
* populated from the prosemirror state; otherwise a new XmlFragment will be created.
* @return {Y.XmlFragment}
*/
export function prosemirrorToYXmlFragment(doc: Node, xmlFragment?: Y.XmlFragment): Y.XmlFragment;
/**
* Utility method to convert Prosemirror compatible JSON into a Y.Doc.

@@ -28,2 +44,16 @@ *

/**
* Utility method to convert Prosemirror compatible JSON to a Y.XmlFragment
*
* This can be used when importing existing content to Y.Doc for the first time,
* note that this should not be used to rehydrate a Y.Doc from a database once
* collaboration has begun as all history will be lost
*
* @param {Schema} schema
* @param {any} state
* @param {Y.XmlFragment} [xmlFragment] If supplied, an xml fragment to be
* populated from the prosemirror state; otherwise a new XmlFragment will be created.
* @return {Y.XmlFragment}
*/
export function prosemirrorJSONToYXmlFragment(schema: Schema, state: any, xmlFragment?: Y.XmlFragment): Y.XmlFragment;
/**
* Utility method to convert a Y.Doc to a Prosemirror Doc node.

@@ -37,2 +67,10 @@ *

/**
* Utility method to convert a Y.XmlFragment to a Prosemirror Doc node.
*
* @param {Schema} schema
* @param {Y.XmlFragment} xmlFragment
* @return {Node}
*/
export function yXmlFragmentToProsemirror(schema: Schema, xmlFragment: Y.XmlFragment): Node;
/**
* Utility method to convert a Y.Doc to Prosemirror compatible JSON.

@@ -45,2 +83,9 @@ *

export function yDocToProsemirrorJSON(ydoc: Y.Doc, xmlFragment?: string): Record<string, any>;
/**
* Utility method to convert a Y.Doc to Prosemirror compatible JSON.
*
* @param {Y.XmlFragment} xmlFragment The fragment, which must be part of a Y.Doc.
* @return {Record<string, any>}
*/
export function yXmlFragmentToProsemirrorJSON(xmlFragment: Y.XmlFragment): Record<string, any>;
export function setMeta(view: any, key: any, value: any): void;

@@ -47,0 +92,0 @@ export function absolutePositionToRelativePosition(pos: number, type: Y.XmlFragment, mapping: Map<Y.AbstractType<any>, Node<any> | Node<any>[]>): any;

10

dist/src/plugins/sync-plugin.d.ts
export function isVisible(item: Y.Item, snapshot?: Y.Snapshot): boolean;
export function ySyncPlugin(yXmlFragment: Y.XmlFragment, { colors, colorMapping, permanentUserData }?: YSyncOpts): any;
export function ySyncPlugin(yXmlFragment: Y.XmlFragment, { colors, colorMapping, permanentUserData, onFirstRender }?: YSyncOpts): any;
export function getRelativeSelection(pmbinding: any, state: any): {

@@ -66,3 +66,5 @@ anchor: any;

}
export function updateYFragment(y: Y.Doc, yDomFragment: Y.XmlFragment, pNode: any, mapping: Map<Y.AbstractType<any>, PModel.Node<any> | PModel.Node<any>[]>): void;
export function updateYFragment(y: {
transact: Function;
}, yDomFragment: Y.XmlFragment, pNode: any, mapping: Map<Y.AbstractType<any>, PModel.Node<any> | PModel.Node<any>[]>): void;
/**

@@ -80,2 +82,6 @@ * Either a node if type is YXmlElement or an Array of text nodes if YXmlText

permanentUserData?: Y.PermanentUserData | null;
/**
* Fired when the content from Yjs is initially rendered to ProseMirror
*/
onFirstRender?: Function;
};

@@ -82,0 +88,0 @@ export type NormalizedPNodeContent = (PModel.Node<any> | PModel.Node<any>[])[];

2

dist/src/y-prosemirror.d.ts

@@ -5,2 +5,2 @@ export * from "./plugins/cursor-plugin.js";

export { ySyncPlugin, isVisible, getRelativeSelection, ProsemirrorBinding } from "./plugins/sync-plugin.js";
export { absolutePositionToRelativePosition, relativePositionToAbsolutePosition, setMeta, prosemirrorJSONToYDoc, yDocToProsemirrorJSON, yDocToProsemirror, prosemirrorToYDoc } from "./lib.js";
export { absolutePositionToRelativePosition, relativePositionToAbsolutePosition, setMeta, prosemirrorJSONToYDoc, yDocToProsemirrorJSON, yDocToProsemirror, prosemirrorToYDoc, prosemirrorJSONToYXmlFragment, yXmlFragmentToProsemirrorJSON, yXmlFragmentToProsemirror, prosemirrorToYXmlFragment } from "./lib.js";
{
"name": "y-prosemirror",
"version": "1.0.19",
"version": "1.0.20",
"description": "Prosemirror bindings for Yjs",

@@ -5,0 +5,0 @@ "main": "./dist/y-prosemirror.cjs",

@@ -212,3 +212,3 @@ import { updateYFragment } from './plugins/sync-plugin.js' // eslint-disable-line

updateYFragment(type.doc, type, doc, new Map())
prosemirrorToYXmlFragment(doc, type)
return type.doc

@@ -218,2 +218,24 @@ }

/**
* Utility method to update an empty Y.XmlFragment with content from a Prosemirror Doc Node.
*
* This can be used when importing existing content to Y.Doc for the first time,
* note that this should not be used to rehydrate a Y.Doc from a database once
* collaboration has begun as all history will be lost
*
* Note: The Y.XmlFragment does not need to be part of a Y.Doc document at the time that this
* method is called, but it must be added before any other operations are performed on it.
*
* @param {Node} doc prosemirror document.
* @param {Y.XmlFragment} [xmlFragment] If supplied, an xml fragment to be
* populated from the prosemirror state; otherwise a new XmlFragment will be created.
* @return {Y.XmlFragment}
*/
export function prosemirrorToYXmlFragment (doc, xmlFragment) {
const type = xmlFragment || new Y.XmlFragment()
const ydoc = type.doc ? type.doc : { transact: (transaction) => transaction(undefined) }
updateYFragment(ydoc, type, doc, new Map())
return type
}
/**
* Utility method to convert Prosemirror compatible JSON into a Y.Doc.

@@ -236,2 +258,20 @@ *

/**
* Utility method to convert Prosemirror compatible JSON to a Y.XmlFragment
*
* This can be used when importing existing content to Y.Doc for the first time,
* note that this should not be used to rehydrate a Y.Doc from a database once
* collaboration has begun as all history will be lost
*
* @param {Schema} schema
* @param {any} state
* @param {Y.XmlFragment} [xmlFragment] If supplied, an xml fragment to be
* populated from the prosemirror state; otherwise a new XmlFragment will be created.
* @return {Y.XmlFragment}
*/
export function prosemirrorJSONToYXmlFragment (schema, state, xmlFragment) {
const doc = Node.fromJSON(schema, state)
return prosemirrorToYXmlFragment(doc, xmlFragment)
}
/**
* Utility method to convert a Y.Doc to a Prosemirror Doc node.

@@ -249,2 +289,14 @@ *

/**
* Utility method to convert a Y.XmlFragment to a Prosemirror Doc node.
*
* @param {Schema} schema
* @param {Y.XmlFragment} xmlFragment
* @return {Node}
*/
export function yXmlFragmentToProsemirror (schema, xmlFragment) {
const state = yXmlFragmentToProsemirrorJSON(xmlFragment)
return Node.fromJSON(schema, state)
}
/**
* Utility method to convert a Y.Doc to Prosemirror compatible JSON.

@@ -260,4 +312,14 @@ *

) {
const items = ydoc.getXmlFragment(xmlFragment).toArray()
return yXmlFragmentToProsemirrorJSON(ydoc.getXmlFragment(xmlFragment))
}
/**
* Utility method to convert a Y.Doc to Prosemirror compatible JSON.
*
* @param {Y.XmlFragment} xmlFragment The fragment, which must be part of a Y.Doc.
* @return {Record<string, any>}
*/
export function yXmlFragmentToProsemirrorJSON (xmlFragment) {
const items = xmlFragment.toArray()
function serialize (item) {

@@ -264,0 +326,0 @@ /**

@@ -43,2 +43,3 @@ /**

* @property {Y.PermanentUserData|null} [YSyncOpts.permanentUserData]
* @property {function} [YSyncOpts.onFirstRender] Fired when the content from Yjs is initially rendered to ProseMirror
*/

@@ -78,3 +79,8 @@

*/
export const ySyncPlugin = (yXmlFragment, { colors = defaultColors, colorMapping = new Map(), permanentUserData = null } = {}) => {
export const ySyncPlugin = (yXmlFragment, {
colors = defaultColors,
colorMapping = new Map(),
permanentUserData = null,
onFirstRender = () => {}
} = {}) => {
let changedInitialContent = false

@@ -146,2 +152,3 @@ let rerenderTimeoutId

view.dispatch(view.state.tr.setMeta(ySyncPluginKey, { binding }))
onFirstRender()
})

@@ -718,3 +725,3 @@ return {

* @private
* @param {Y.Doc} y
* @param {{transact: Function}} y
* @param {Y.XmlFragment} yDomFragment

@@ -826,3 +833,7 @@ * @param {any} pNode

const yDelLen = yChildCnt - left - right
if (yDelLen > 0) {
if (yChildCnt === 1 && pChildCnt === 0 && yChildren[0] instanceof Y.XmlText) {
// Edge case handling https://github.com/yjs/y-prosemirror/issues/108
// Only delete the content of the Y.Text to retain remote changes on the same Y.Text object
yChildren[0].delete(0, yChildren[0].length)
} else if (yDelLen > 0) {
yDomFragment.delete(left, yDelLen)

@@ -829,0 +840,0 @@ }

@@ -5,2 +5,3 @@ export * from './plugins/cursor-plugin.js'

export * from './plugins/keys.js'
export { absolutePositionToRelativePosition, relativePositionToAbsolutePosition, setMeta, prosemirrorJSONToYDoc, yDocToProsemirrorJSON, yDocToProsemirror, prosemirrorToYDoc } from './lib.js'
export { absolutePositionToRelativePosition, relativePositionToAbsolutePosition, setMeta, prosemirrorJSONToYDoc, yDocToProsemirrorJSON, yDocToProsemirror, prosemirrorToYDoc,
prosemirrorJSONToYXmlFragment, yXmlFragmentToProsemirrorJSON, yXmlFragmentToProsemirror, prosemirrorToYXmlFragment } from './lib.js'

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc