Socket
Socket
Sign inDemoInstall

y-prosemirror

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

y-prosemirror - npm Package Compare versions

Comparing version 0.3.6 to 0.3.7

2

dist/src/lib.d.ts
export function setMeta(view: any, key: any, value: any): void;
export function absolutePositionToRelativePosition(pos: number, type: any, mapping: Map<any, import("prosemirror-model").Node<any> | import("prosemirror-model").Node<any>[]>): any;
export function relativePositionToAbsolutePosition(y: any, documentType: any, relPos: any, mapping: Map<any, import("prosemirror-model").Node<any> | import("prosemirror-model").Node<any>[]>): number;
export function relativePositionToAbsolutePosition(y: any, documentType: any, relPos: any, mapping: Map<any, import("prosemirror-model").Node<any> | import("prosemirror-model").Node<any>[]>): null | number;

@@ -12,4 +12,5 @@ /**

getSelection: (arg0: any) => any;
}): any;
cursorStateField: string;
}, cursorStateField?: string): any;
import { PluginKey } from "prosemirror-state";
import { Awareness } from "y-protocols/awareness";

@@ -47,2 +47,5 @@ export function isVisible(item: any, snapshot?: any): boolean;

};
_domSelectionInView: boolean;
_isLocalCursorInView(): boolean;
_isDomSelectionInView(): boolean;
renderSnapshot(snapshot: any, prevSnapshot: any): void;

@@ -49,0 +52,0 @@ unrenderSnapshot(): void;

{
"name": "y-prosemirror",
"version": "0.3.6",
"version": "0.3.7",
"description": "Prosemirror bindings for Yjs",

@@ -46,3 +46,6 @@ "main": "./dist/y-prosemirror.cjs",

"dependencies": {
"lib0": "^0.2.33"
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"lib0": "^0.2.33",
"rollup": "^2.26.11"
},

@@ -57,4 +60,2 @@ "peerDependencies": {

"devDependencies": {
"@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-node-resolve": "^7.1.3",
"@types/prosemirror-state": "^1.2.5",

@@ -64,12 +65,13 @@ "concurrently": "^4.1.0",

"jsdom": "^15.1.1",
"prosemirror-model": "^1.11.0",
"prosemirror-example-setup": "^1.1.2",
"prosemirror-model": "^1.11.2",
"prosemirror-schema-basic": "^1.0.1",
"prosemirror-state": "^1.3.3",
"prosemirror-view": "^1.15.2",
"rollup": "^1.32.1",
"prosemirror-view": "^1.15.7",
"standard": "^12.0.1",
"typescript": "^3.9.7",
"y-protocols": "^1.0.1",
"y-webrtc": "^10.1.6",
"yjs": "13.3.2"
}
}

@@ -116,2 +116,3 @@ import { ProsemirrorMapping } from './plugins/sync-plugin.js' // eslint-disable-line

* @param {ProsemirrorMapping} mapping
* @return {null|number}
*/

@@ -118,0 +119,0 @@ export const relativePositionToAbsolutePosition = (y, documentType, relPos, mapping) => {

@@ -85,5 +85,6 @@

* @param {function(any):any} [opts.getSelection]
* @param {string} [opts.cursorStateField] By default all editor bindings use the awareness 'cursor' field to propagate cursor information.
* @return {any}
*/
export const yCursorPlugin = (awareness, { cursorBuilder = defaultCursorBuilder, getSelection = state => state.selection } = {}) => new Plugin({
export const yCursorPlugin = (awareness, { cursorBuilder = defaultCursorBuilder, getSelection = state => state.selection } = {}, cursorStateField = 'cursor') => new Plugin({
key: yCursorPluginKey,

@@ -130,8 +131,9 @@ state: {

if (current.cursor == null || !Y.compareRelativePositions(Y.createRelativePositionFromJSON(current.cursor.anchor), anchor) || !Y.compareRelativePositions(Y.createRelativePositionFromJSON(current.cursor.head), head)) {
awareness.setLocalStateField('cursor', {
awareness.setLocalStateField(cursorStateField, {
anchor, head
})
}
} else if (current.cursor != null) {
awareness.setLocalStateField('cursor', null)
} else if (current.cursor != null && relativePositionToAbsolutePosition(ystate.doc, ystate.type, Y.createRelativePositionFromJSON(current.cursor.anchor), ystate.binding.mapping) !== null) {
// delete cursor information if current cursor information is owned by this editor binding
awareness.setLocalStateField(cursorStateField, null)
}

@@ -146,3 +148,3 @@ }

awareness.off('change', awarenessListener)
awareness.setLocalStateField('cursor', null)
awareness.setLocalStateField(cursorStateField, null)
}

@@ -149,0 +151,0 @@ }

@@ -16,2 +16,4 @@ /**

import * as random from 'lib0/random.js'
import * as environment from 'lib0/environment.js'
import * as dom from 'lib0/dom.js'

@@ -219,4 +221,33 @@ /**

yXmlFragment.observeDeep(this._observeFunction)
this._domSelectionInView = null
}
_isLocalCursorInView () {
if (!this.prosemirrorView.hasFocus()) return false
if (environment.isBrowser && this._domSelectionInView === null) {
// Calculte the domSelectionInView and clear by next tick after all events are finished
setTimeout(() => {
this._domSelectionInView = null
}, 0)
this._domSelectionInView = this._isDomSelectionInView()
}
return this._domSelectionInView
}
_isDomSelectionInView () {
const selection = this.prosemirrorView._root.getSelection()
const range = this.prosemirrorView._root.createRange()
range.setStart(selection.anchorNode, selection.anchorOffset)
range.setEnd(selection.focusNode, selection.focusOffset)
const bounding = range.getBoundingClientRect()
const documentElement = dom.doc.documentElement
return bounding.bottom >= 0 && bounding.right >= 0 &&
bounding.left <= (window.innerWidth || documentElement.clientWidth || 0) &&
bounding.top <= (window.innerHeight || documentElement.clientHeight || 0)
}
renderSnapshot (snapshot, prevSnapshot) {

@@ -321,3 +352,3 @@ if (!prevSnapshot) {

tr = tr.setMeta(ySyncPluginKey, { isChangeOrigin: true })
if (this.beforeTransactionSelection !== null && this.prosemirrorView.hasFocus()) {
if (this.beforeTransactionSelection !== null && this._isLocalCursorInView()) {
tr.scrollIntoView()

@@ -324,0 +355,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc