How to use the prosemirror-model.Fragment function in prosemirror-model

To help you get started, we’ve selected a few prosemirror-model examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yjs / yjs / bindings / prosemirror.js View on Github external
this.mux(() => {
      events.forEach(event => {
        // recompute node for each parent
        // except main node, compute main node in the end
        let target = event.target
        if (target !== this.type) {
          do {
            if (target.constructor === Y.XmlElement) {
              createNodeFromYElement(target, this.prosemirrorView.state.schema, this.mapping)
            }
            target = target._parent
          } while (target._parent !== this.type)
        }
      })
      const fragmentContent = this.type.toArray().map(t => createNodeIfNotExists(t, this.prosemirrorView.state.schema, this.mapping))
      const tr = this.prosemirrorView.state.tr.replace(0, this.prosemirrorView.state.doc.content.size, new PModel.Slice(new PModel.Fragment(fragmentContent), 0, 0))
      this.prosemirrorView.updateState(this.prosemirrorView.state.apply(tr))
    })
  }
github yjs / yjs / bindings / prosemirror.js View on Github external
this.mux(() => {
      const delStruct = (_, struct) => this.mapping.delete(struct)
      transaction.deletedStructs.forEach(struct => this.mapping.delete(struct))
      transaction.changedTypes.forEach(delStruct)
      transaction.changedParentTypes.forEach(delStruct)
      const fragmentContent = this.type.toArray().map(t => createNodeIfNotExists(t, this.prosemirrorView.state.schema, this.mapping)).filter(n => n !== null)
      const tr = this.prosemirrorView.state.tr.replace(0, this.prosemirrorView.state.doc.content.size, new PModel.Slice(new PModel.Fragment(fragmentContent), 0, 0))
      const relSel = this._relSelection
      if (relSel !== null && relSel.anchor !== null && relSel.head !== null) {
        const anchor = relativePositionToAbsolutePosition(this.type, relSel.anchor, this.mapping)
        const head = relativePositionToAbsolutePosition(this.type, relSel.head, this.mapping)
        if (anchor !== null && head !== null) {
          tr.setSelection(TextSelection.create(tr.doc, anchor, head))
        }
      }
      this.prosemirrorView.updateState(this.prosemirrorView.state.apply(tr))
    })
  }