y-prosemirror
Advanced tools
Comparing version 0.3.6 to 0.3.7
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
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
3697299
14
35614
9
+ Addedrollup@^2.26.11
+ Added@rollup/plugin-commonjs@15.1.0(transitive)
+ Added@rollup/plugin-node-resolve@9.0.0(transitive)
+ Added@rollup/pluginutils@3.1.0(transitive)
+ Added@types/estree@0.0.39(transitive)
+ Added@types/node@22.7.4(transitive)
+ Added@types/resolve@1.17.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbuiltin-modules@3.3.0(transitive)
+ Addedcommondir@1.0.1(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddeepmerge@4.3.1(transitive)
+ Addedestree-walker@1.0.12.0.2(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-module@1.0.0(transitive)
+ Addedis-reference@1.2.1(transitive)
+ Addedmagic-string@0.25.9(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedrollup@2.79.2(transitive)
+ Addedsourcemap-codec@1.4.8(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedwrappy@1.0.2(transitive)