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

@convergence/dom-utils

v0.3.1

Published

A utility to bind a Convergence Model to a DOM Element

Downloads

17

Readme

Convergence DOM Utils

Build Status

This project contains utilities to that make binding the DOM to a Convergence Model.

Dependencies

This library depends on the following libraries:

  • @convergence/convergence: The main Convergence client API.

Building the Distribution

npm install
npm run dist

Usage

<!DOCTYPE html>
<html lang="en">
<head>
  <style>
    .edit { border: 1px solid black; height: 400px; width: 400px; margin-top: 15px; }
  </style>
</head>
<body>
<h3>Content Editable Rich Text Area</h3>
<div class="edit" id="editable">Loading...</div>
<script>
  const editable = document.getElementById("editable"); 
  const DOMAIN_URL = "http://localhost:8000/api/realtime/convergence/default";
  Convergence.connectAnonymously(DOMAIN_URL).then(function (domain) {
    return domain.models().open("content-editable", "test", function () {
      return ConvergenceDomUtils.DomConverter.htmlToJson(
        "Here is some initial text with a <b>bold</b> section and some <i>italics</i>."
      );
    });
  }).then(function (model) {
    const binder = new ConvergenceDomUtils.DomBinder(editable, model);
    editable.contentEditable = true;
  });
</script>
</body>
</html>

API

ConvergenceDomUtils.DomBinder

constructor(element: HTMLElement, data: RealTimeObject | RealTimeModel, autoBind: boolean = true)

Creates a new DomBinder associated with a specific HTMLElement and RealTimeObject. If an instance of RealTimeModel is passed in, the HTMLElemenet will be bound to the root element of the model. The current contents of the element will be replaced by the DOM representation contained in the RealTimeObject. The autoBind parameter configures whether or not the DomBinder will automatically bind upon construction. The default is true.

unbind(): void

Disconnects the HTMLElement from the RealTimeObject. The element and model will be left as is, but the two-way data binding will be disconnected. This method can only be called when the DomBinder is bound.

bind(): void

Sets up the two-way data binding between the element and RealTimeObject. This method can only be called when the DomBinder is not already bound.

isBound(): boolean

Determines if the HTMLElement and RealTimeObject are currently bound.

ConvergenceDomUtils.DomConverter

static htmlToJson(html: string): any

Converts a string containing HTML into the JSON representation of the DOM Tree.

static nodeToJson(node: Node): any

Converts a DOM Node (e.g. Element, Text) into the JSON representation of the DOM Tree.

static jsonToNode(json: any): Node

Converts the JSON Representation of a DOM Tree into a DOM Node.

Running the Example

To run the example you must first:

  1. Build the distribution
  2. Follow the steps in the example/config.example.js file
  3. Open the example/index.html file in your browser

Note: to run the example you must have a running Convergence Server. The easiest way to get one running is using Docker:

docker run \
  --name convergence \
  -p 8000:80 \
  convergencelabs/convergence-omnibus