npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dom-ot

v3.0.1

Published

Operational transform library for DOM operations (conforms to shareJS' spec)

Downloads

74

Readme

dom-ot

The DOM changes. You can capture those changes and sync multiple documents in real-time using this library to transform the changes for automagic conflict resolution.

Sounds awesome? It is. To learn more about operational transformation, go to wikipedia or check out this guide to textual ot. Also, check out gulf-contenteditable for a ready-made wrapper.

browser support

Install

npm install dom-ot

API

domOT

The object you get from require('dom-ot') is a full-featured shareJS ottype. This allows you to use dom-ot together with shareJS or the more unixy gulf. The shareJS interface will deal only with edits. An edit is essentially an array of operations.

new domOT.Move(fromPath, toPath, [serializedNode])

This operation allows you to move a node from one path to another. Set fromPath to null to insert a node into the tree (which should be passed as serializedNode, serialized with vdom-serialize). Set toPath to null, to remove a node from the tree (you should also pass serializedNode here to enable inversion of the operation).

new domOT.Manipulate(path, attribute, value, oldValue=null)

This operation allows you to set an attribute named attribute of a given node at path to a specific value. Set value to null to remove the attribute.

new domOT.ManipulateText(path, diff)

This operation allows you to modify the nodeValue of a text node, by specifying a diff (which should be a packed changeset).

Operation#transformAgainst(op, [left])

Transforms this operation in-place against another one, so that it assumes the changes of the other one have already happened. Use left to break ties.

Operation#invert()

Inverts the operation in-place.

Operation#apply(rootNode, [index])

Apply an operation on a document, specified by rootNode. Optionally, you may set index to true, to automatically index nodes for importing MutationSummaries (see the mutationSummary adapter).

domOT.adapters

Usually you will not create these operations by hand: Fortunately there's a handy adapter that will turn MutationObserver summaries into dom-ot edits. Currently there's only an import method available that allows you to convert mutation summaries into dom-ot edits, but not the other way around. I simply couldn't find a use case for that, so that's it.

domOT.adapters.mutationSummary

domOT.adapters.mutationSummary.import(summary, rootNode)
  • summary is a summary object as returned by MutationSummary
  • rootNode is the rootNode that was observed Before installing a MutationObserver with MutationSummary and importing the changes with this function, you will need to run an indexing function on the rootNode, so that the adapter can figure out where the nodes were before. Also, you need to continuously index newly inserted or moved nodes. You can set the optional index param of <Operation>#apply to true, to do this automatically and efficiently.
domOT.adapters.mutationSummary.createIndex(rootNode)

Creates an index for all children of rootNode which is necessary for import() to work.

Tests

Run browserify test/tests.js > bundle.js, then open test/index.html in the browser of your choice.

Changelog

v3.0.0

  • Implement operation inversion

Legal

(c) 2015 by Marcel Klehr

Licensed under the terms of the LGPL. See LICENSE.txt in the root directory of this project.