{"id":24379685,"url":"https://github.com/y-js/y-text","last_synced_at":"2025-04-10T21:09:48.561Z","repository":{"id":27939716,"uuid":"31432266","full_name":"y-js/y-text","owner":"y-js","description":"Text Type for Yjs","archived":false,"fork":false,"pushed_at":"2017-10-06T21:51:54.000Z","size":1252,"stargazers_count":20,"open_issues_count":3,"forks_count":5,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-24T18:47:05.583Z","etag":null,"topics":["ace-editor","yjs","yjs-type"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/y-js.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-27T18:05:35.000Z","updated_at":"2025-02-10T22:33:18.000Z","dependencies_parsed_at":"2022-08-20T06:20:40.963Z","dependency_job_id":null,"html_url":"https://github.com/y-js/y-text","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/y-js%2Fy-text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/y-js%2Fy-text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/y-js%2Fy-text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/y-js%2Fy-text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/y-js","download_url":"https://codeload.github.com/y-js/y-text/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247792898,"owners_count":20996901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ace-editor","yjs","yjs-type"],"created_at":"2025-01-19T07:18:45.206Z","updated_at":"2025-04-10T21:09:48.541Z","avatar_url":"https://github.com/y-js.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Text Type for [Yjs](https://github.com/y-js/yjs)\n\nUse the Y.Text type to share text content. The shared content can be bound to\n[Ace](https://ace.c9.io/), [CodeMirror](https://codemirror.net/), [Monaco](https://github.com/Microsoft/monaco-editor), or any HTML\ninput element (e.g. \u0026lt;input\u0026gt;, \u0026lt;textarea\u0026gt;, any element that has the [contenteditable](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contenteditable) property)\n\n```\n// bind text to the first p element that is contenteditable\ny.share.text.bind(document.querySelector(\"p[contenteditable]\"))\n```\n\n## Use it!\nRetrieve this with bower or npm.\n\n##### Bower\n```\nbower install y-text --save\n```\n\n##### NPM\n```\nnpm install y-text y-array --save\n```\n\nThis type depends on [y-array](https://github.com/y-js/y-array). So you have to\nextend Yjs in the right order:\n\n```javascript\nvar Y = require('yjs')\nrequire('y-array')(Y)\nrequire('y-text')(Y)\n```\n\n### Text Object\n\n##### Reference\n* .insert(position, string)\n  * Insert a string at a position\n* .delete(position, length)\n  * Delete a substring. The *length* parameter is optional and defaults to 1\n* .get(i)\n  * Retrieve the i-th character\n* .toString()\n  * Return the content as a String\n* .bindTextarea(htmlElement)\n  * Supports textareas, inputs, and any contenteditable element\n* .bindCodeMirror(codemirror)\n  * Bind shared content to a [CodeMirror](https://codemirror.net/) instance\n* .bindAce(aceEditor)\n  * Bind shared content to an [Ace](https://ace.c9.io/) instance\n  * `options` supports the following properties:\n    * **aceClass**: In case `ace` is not defined on the global object\n    * **aceRequire**: An alternative method to require Ace modules (default is\n      `aceClass.require`). Must work similar to `ace.require`\n* .bindMonaco(editor)\n  * Bind shared content to a [Monaco](https://github.com/Microsoft/monaco-editor) editor\n* .bind(editor, options) - *deprecated*\n  * Tries to detect the editor, and applies the arguments to `.bind[editor](..)`\n  * `.bind*(editor)` does not preserve the existing value of the bound editor.\n* .unbindTextarea(htmlElement)\n  * Remove bindings to a html element\n* .unbindCodeMirror(codemirror)\n  * Remove bindings to a CodeMirror instance\n* .unbindAce(aceEditor)\n  * Remove bindings to a Ace instance\n* .unbindMonaco(editor)\n  * Remove bindings to a Monaco instance\n* .unbindTextareaAll()\n  * Remove all bindings to html elements\n* .unbindCodeMirrorAll()\n  * Remove all bindings to CodeMirror instances\n* .unbindAceAll()\n  * Remove all bindings to Ace instances\n* .unbindMonacoAll()\n  * Remove all Monaco editor bindings\n* .unbindAll()\n  * Remove all bindings\n* .observe(f)\n  * The observer is called whenever something on this text changed. (throws\n    insert, and delete events)\n* .unobserve(f)\n  * Delete an observer\n\n# A note on intention preservation\nIf two users insert something at the same position concurrently, the content\nthat was inserted by the user with the higher user-id will be to the right of\nthe other content. In the OT world we often speak of *intention preservation*,\nwhich is very loosely defined in most cases. This type has the following notion\nof intention preservation: When a user inserts content *c* after a set of\ncontent *C_left*, and before a set of content *C_right*, then *C_left* will be\nalways to the left of c, and *C_right* will be always to the right of *c*. This\nproperty will also hold when content is deleted or when a deletion is undone.\n\n# A note on time complexities\n* .insert(position, contents)\n  * O(position + |contents|)\n* .toString()\n  * O(this.length)\n* Apply an insert operation from another user\n  * Yjs does not transform against operations that do not conflict with each\n    other.\n  * An operation conflicts with another operation if it intends to be inserted\n    at the same position.\n  * Overall worst case complexety: O(|conflicts|!)\n\n\n## Contribution\nWe thank [@NathanaelA](https://github.com/nathanaela) who sponsored the bindings to the Monaco editor!\n\n\n## License\nYjs is licensed under the [MIT License](./LICENSE).\n\n\u003ckevin.jahns@rwth-aachen.de\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fy-js%2Fy-text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fy-js%2Fy-text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fy-js%2Fy-text/lists"}