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

y-text2

v1.6.0

Published

Text Type for Yjs

Downloads

2

Readme

Text Type for Yjs

Use the Y.Text type to share text content. The shared content can be bound to Ace, CodeMirror, Monaco, or any HTML input element (e.g. <input>, <textarea>, any element that has the contenteditable property)

// bind text to the first p element that is contenteditable
y.share.text.bind(document.querySelector("p[contenteditable]"))

Use it!

Retrieve this with bower or npm.

Bower
bower install y-text --save
NPM
npm install y-text y-array --save

This type depends on y-array. So you have to extend Yjs in the right order:

var Y = require('yjs')
require('y-array')(Y)
require('y-text')(Y)

Text Object

Reference
  • .insert(position, string)
    • Insert a string at a position
  • .delete(position, length)
    • Delete a substring. The length parameter is optional and defaults to 1
  • .get(i)
    • Retrieve the i-th character
  • .toString()
    • Return the content as a String
  • .bindTextarea(htmlElement)
    • Supports textareas, inputs, and any contenteditable element
  • .bindCodeMirror(codemirror)
  • .bindAce(aceEditor)
    • Bind shared content to an Ace instance
    • options supports the following properties:
      • aceClass: In case ace is not defined on the global object
      • aceRequire: An alternative method to require Ace modules (default is aceClass.require). Must work similar to ace.require
  • .bindMonaco(editor)
    • Bind shared content to a Monaco editor
  • .bind(editor, options) - deprecated
    • Tries to detect the editor, and applies the arguments to .bind[editor](..)
    • .bind*(editor) does not preserve the existing value of the bound editor.
  • .unbindTextarea(htmlElement)
    • Remove bindings to a html element
  • .unbindCodeMirror(codemirror)
    • Remove bindings to a CodeMirror instance
  • .unbindAce(aceEditor)
    • Remove bindings to a Ace instance
  • .unbindMonaco(editor)
    • Remove bindings to a Monaco instance
  • .unbindTextareaAll()
    • Remove all bindings to html elements
  • .unbindCodeMirrorAll()
    • Remove all bindings to CodeMirror instances
  • .unbindAceAll()
    • Remove all bindings to Ace instances
  • .unbindMonacoAll()
    • Remove all Monaco editor bindings
  • .unbindAll()
    • Remove all bindings
  • .observe(f)
    • The observer is called whenever something on this text changed. (throws insert, and delete events)
  • .unobserve(f)
    • Delete an observer

A note on intention preservation

If two users insert something at the same position concurrently, the content that was inserted by the user with the higher user-id will be to the right of the other content. In the OT world we often speak of intention preservation, which is very loosely defined in most cases. This type has the following notion of intention preservation: When a user inserts content c after a set of content C_left, and before a set of content C_right, then C_left will be always to the left of c, and C_right will be always to the right of c. This property will also hold when content is deleted or when a deletion is undone.

A note on time complexities

  • .insert(position, contents)
    • O(position + |contents|)
  • .toString()
    • O(this.length)
  • Apply an insert operation from another user
    • Yjs does not transform against operations that do not conflict with each other.
    • An operation conflicts with another operation if it intends to be inserted at the same position.
    • Overall worst case complexety: O(|conflicts|!)

Contribution

We thank @NathanaelA who sponsored the bindings to the Monaco editor!

License

Yjs is licensed under the MIT License.

[email protected]