mjs nodejs support
This commit is contained in:
@@ -1 +0,0 @@
|
||||
export * from './dom/DomBinding.js'
|
||||
1
bindings/dom.mjs
Normal file
1
bindings/dom.mjs
Normal file
@@ -0,0 +1 @@
|
||||
export * from './dom/DomBinding.mjs'
|
||||
@@ -4,14 +4,14 @@
|
||||
|
||||
/* global MutationObserver, getSelection */
|
||||
|
||||
import { fromRelativePosition } from '../../utils/relativePosition.js'
|
||||
import { createMutex } from '../../lib/mutex.js'
|
||||
import { createAssociation, removeAssociation } from './util.js'
|
||||
import { beforeTransactionSelectionFixer, afterTransactionSelectionFixer, getCurrentRelativeSelection } from './selection.js'
|
||||
import { defaultFilter, applyFilterOnType } from './filter.js'
|
||||
import { typeObserver } from './typeObserver.js'
|
||||
import { domObserver } from './domObserver.js'
|
||||
import { YXmlFragment } from '../../types/YXmlElement.js' // eslint-disable-line
|
||||
import { fromRelativePosition } from '../../utils/relativePosition.mjs'
|
||||
import { createMutex } from '../../lib/mutex.mjs'
|
||||
import { createAssociation, removeAssociation } from './util.mjs'
|
||||
import { beforeTransactionSelectionFixer, afterTransactionSelectionFixer, getCurrentRelativeSelection } from './selection.mjs'
|
||||
import { defaultFilter, applyFilterOnType } from './filter.mjs'
|
||||
import { typeObserver } from './typeObserver.mjs'
|
||||
import { domObserver } from './domObserver.mjs'
|
||||
import { YXmlFragment } from '../../types/YXmlElement.mjs' // eslint-disable-line
|
||||
|
||||
/**
|
||||
* @callback DomFilter
|
||||
@@ -2,13 +2,13 @@
|
||||
* @module bindings/dom
|
||||
*/
|
||||
|
||||
import { YXmlHook } from '../../types/YXmlHook.js'
|
||||
import { YXmlHook } from '../../types/YXmlHook.mjs'
|
||||
import {
|
||||
iterateUntilUndeleted,
|
||||
removeAssociation,
|
||||
insertNodeHelper } from './util.js'
|
||||
import { simpleDiff } from '../../lib/diff.js'
|
||||
import { YXmlFragment } from '../../types/YXmlElement.js'
|
||||
insertNodeHelper } from './util.mjs'
|
||||
import { simpleDiff } from '../../lib/diff.mjs'
|
||||
import { YXmlFragment } from '../../types/YXmlElement.mjs'
|
||||
|
||||
/**
|
||||
* 1. Check if any of the nodes was deleted
|
||||
@@ -3,12 +3,12 @@
|
||||
*/
|
||||
|
||||
/* eslint-env browser */
|
||||
import { YXmlText } from '../../types/YXmlText.js'
|
||||
import { YXmlHook } from '../../types/YXmlHook.js'
|
||||
import { YXmlElement } from '../../types/YXmlElement.js'
|
||||
import { createAssociation, domsToTypes } from './util.js'
|
||||
import { filterDomAttributes, defaultFilter } from './filter.js'
|
||||
import { DomBinding } from './DomBinding.js' // eslint-disable-line
|
||||
import { YXmlText } from '../../types/YXmlText.mjs'
|
||||
import { YXmlHook } from '../../types/YXmlHook.mjs'
|
||||
import { YXmlElement } from '../../types/YXmlElement.mjs'
|
||||
import { createAssociation, domsToTypes } from './util.mjs'
|
||||
import { filterDomAttributes, defaultFilter } from './filter.mjs'
|
||||
import { DomBinding } from './DomBinding.mjs' // eslint-disable-line
|
||||
|
||||
/**
|
||||
* @callback DomFilter
|
||||
@@ -2,9 +2,10 @@
|
||||
* @module bindings/dom
|
||||
*/
|
||||
|
||||
import { isParentOf } from '../../utils/isParentOf.js'
|
||||
import * as Y from '../../index.js'
|
||||
import { DomBinding } from './DomBinding.js' // eslint-disable-line
|
||||
import { Y } from '../../utils/Y.mjs' // eslint-disable-line
|
||||
import { YXmlElement, YXmlFragment } from '../../types/YXmlElement.mjs' // eslint-disable-line
|
||||
import { isParentOf } from '../../utils/isParentOf.mjs'
|
||||
import { DomBinding } from './DomBinding.mjs' // eslint-disable-line
|
||||
|
||||
/**
|
||||
* Default filter method (does nothing).
|
||||
@@ -34,14 +35,14 @@ export const filterDomAttributes = (dom, filter) => {
|
||||
/**
|
||||
* Applies a filter on a type.
|
||||
*
|
||||
* @param {Y.Y} y The Yjs instance.
|
||||
* @param {Y} y The Yjs instance.
|
||||
* @param {DomBinding} binding The DOM binding instance that has the dom filter.
|
||||
* @param {Y.XmlElement | Y.XmlFragment } type The type to apply the filter to.
|
||||
* @param {YXmlElement | YXmlFragment } type The type to apply the filter to.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
export const applyFilterOnType = (y, binding, type) => {
|
||||
if (isParentOf(binding.type, type) && type instanceof Y.XmlElement) {
|
||||
if (isParentOf(binding.type, type) && type instanceof YXmlElement) {
|
||||
const nodeName = type.nodeName
|
||||
let attributes = new Map()
|
||||
if (type.getAttributes !== undefined) {
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
/* globals getSelection */
|
||||
|
||||
import { getRelativePosition } from '../../utils/relativePosition.js'
|
||||
import { getRelativePosition } from '../../utils/relativePosition.mjs'
|
||||
|
||||
let relativeSelection = null
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
/* eslint-env browser */
|
||||
/* global getSelection */
|
||||
|
||||
import { YXmlText } from '../../types/YXmlText.js'
|
||||
import { YXmlHook } from '../../types/YXmlHook.js'
|
||||
import { removeDomChildrenUntilElementFound } from './util.js'
|
||||
import { YXmlText } from '../../types/YXmlText.mjs'
|
||||
import { YXmlHook } from '../../types/YXmlHook.mjs'
|
||||
import { removeDomChildrenUntilElementFound } from './util.mjs'
|
||||
|
||||
const findScrollReference = scrollingElement => {
|
||||
if (scrollingElement !== null) {
|
||||
@@ -2,11 +2,8 @@
|
||||
* @module bindings/dom
|
||||
*/
|
||||
|
||||
import { domToType } from './domToType.js'
|
||||
import { DomBinding } from './DomBinding.js' // eslint-disable-line
|
||||
import { YXmlHook } from '../../types/YXmlHook.js' // eslint-disable-line
|
||||
import { YXmlText } from '../../types/YXmlText.js' // eslint-disable-line
|
||||
import { YXmlElement, YXmlFragment } from '../../types/YXmlElement.js' // eslint-disable-line
|
||||
import { domToType } from './domToType.mjs'
|
||||
import { DomBinding } from './DomBinding.mjs' // eslint-disable-line
|
||||
|
||||
/**
|
||||
* Iterates items until an undeleted item is found.
|
||||
@@ -2,17 +2,16 @@
|
||||
* @module bindings/prosemirror
|
||||
*/
|
||||
|
||||
import { BindMapping } from '../utils/BindMapping.js'
|
||||
import * as Y from '../index.js'
|
||||
import { createMutex } from '../lib/mutex.js'
|
||||
import { BindMapping } from '../utils/BindMapping.mjs'
|
||||
import { YText } from '../types/YText.mjs' // eslint-disable-line
|
||||
import { YXmlElement, YXmlFragment } from '../types/YXmlElement.mjs' // eslint-disable-line
|
||||
import { createMutex } from '../lib/mutex.mjs'
|
||||
import * as PModel from 'prosemirror-model'
|
||||
import { Plugin, PluginKey } from 'prosemirror-state'
|
||||
import { Decoration, DecorationSet } from 'prosemirror-view'
|
||||
import { EditorView, Decoration, DecorationSet } from 'prosemirror-view' // eslint-disable-line
|
||||
import { Plugin, PluginKey, EditorState } from 'prosemirror-state' // eslint-disable-line
|
||||
|
||||
/**
|
||||
* @typedef {import('prosemirror-view').EditorView} EditorView
|
||||
* @typedef {import('prosemirror-state').EditorState} EditorState
|
||||
* @typedef {BindMapping<Y.Text | Y.XmlElement, PModel.Node>} ProsemirrorMapping
|
||||
* @typedef {BindMapping<YText | YXmlElement, PModel.Node>} ProsemirrorMapping
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -26,7 +25,7 @@ export const prosemirrorPluginKey = new PluginKey('yjs')
|
||||
* This plugin listens to changes in prosemirror view and keeps yXmlState and view in sync.
|
||||
*
|
||||
* This plugin also keeps references to the type and the shared document so other plugins can access it.
|
||||
* @param {Y.XmlFragment} yXmlFragment
|
||||
* @param {YXmlFragment} yXmlFragment
|
||||
* @return {Plugin} Returns a prosemirror plugin that binds to this type
|
||||
*/
|
||||
export const prosemirrorPlugin = yXmlFragment => {
|
||||
@@ -132,7 +131,7 @@ export const cursorPlugin = new Plugin({
|
||||
*/
|
||||
export class ProsemirrorBinding {
|
||||
/**
|
||||
* @param {Y.XmlFragment} yXmlFragment The bind source
|
||||
* @param {YXmlFragment} yXmlFragment The bind source
|
||||
* @param {EditorView} prosemirrorView The target binding
|
||||
*/
|
||||
constructor (yXmlFragment, prosemirrorView) {
|
||||
@@ -157,7 +156,7 @@ export class ProsemirrorBinding {
|
||||
let target = event.target
|
||||
if (target !== this.type) {
|
||||
do {
|
||||
if (target.constructor === Y.XmlElement) {
|
||||
if (target.constructor === YXmlElement) {
|
||||
createNodeFromYElement(target, this.prosemirrorView.state.schema, this.mapping)
|
||||
}
|
||||
target = target._parent
|
||||
@@ -204,7 +203,7 @@ export const createNodeIfNotExists = (el, schema, mapping) => {
|
||||
export const createNodeFromYElement = (el, schema, mapping) => {
|
||||
const children = []
|
||||
el.toArray().forEach(type => {
|
||||
if (type.constructor === Y.XmlElement) {
|
||||
if (type.constructor === YXmlElement) {
|
||||
children.push(createNodeIfNotExists(type, schema, mapping))
|
||||
} else {
|
||||
children.concat(createTextNodesFromYText(type, schema, mapping)).forEach(textchild => children.push(textchild))
|
||||
@@ -243,17 +242,17 @@ export const createTextNodesFromYText = (text, schema, mapping) => {
|
||||
* @private
|
||||
* @param {PModel.Node} node
|
||||
* @param {ProsemirrorMapping} mapping
|
||||
* @return {Y.XmlElement | Y.Text}
|
||||
* @return {YXmlElement | YText}
|
||||
*/
|
||||
export const createTypeFromNode = (node, mapping) => {
|
||||
let type
|
||||
if (node.isText) {
|
||||
type = new Y.Text()
|
||||
type = new YText()
|
||||
const attrs = {}
|
||||
node.marks.forEach(mark => { attrs[mark.type.name] = mark.attrs })
|
||||
type.insert(0, node.text, attrs)
|
||||
} else {
|
||||
type = new Y.XmlElement(node.type.name)
|
||||
type = new YXmlElement(node.type.name)
|
||||
for (let key in node.attrs) {
|
||||
type.setAttribute(key, node.attrs[key])
|
||||
}
|
||||
@@ -265,7 +264,7 @@ export const createTypeFromNode = (node, mapping) => {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Y.XmlFragment} yDomFragment
|
||||
* @param {YXmlFragment} yDomFragment
|
||||
* @param {EditorState} state
|
||||
* @param {BindMapping} mapping
|
||||
*/
|
||||
@@ -2,7 +2,7 @@
|
||||
* @module bindings/quill
|
||||
*/
|
||||
|
||||
import { createMutex } from '../lib/mutex.js'
|
||||
import { createMutex } from '../lib/mutex.mjs'
|
||||
|
||||
const typeObserver = function (event) {
|
||||
const quill = this.target
|
||||
@@ -2,9 +2,9 @@
|
||||
* @module bindings/textarea
|
||||
*/
|
||||
|
||||
import { simpleDiff } from '../lib/diff.js'
|
||||
import { getRelativePosition, fromRelativePosition } from '../utils/relativePosition.js'
|
||||
import { createMutex } from '../lib/mutex.js'
|
||||
import { simpleDiff } from '../lib/diff.mjs'
|
||||
import { getRelativePosition, fromRelativePosition } from '../utils/relativePosition.mjs'
|
||||
import { createMutex } from '../lib/mutex.mjs'
|
||||
|
||||
function typeObserver () {
|
||||
this._mutualExclude(() => {
|
||||
Reference in New Issue
Block a user