Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
y-textarea
Advanced tools
This package binds a YJS, Y.Text type to a HTML input element where type="text" or a TextArea element. Shared cursors are also supported.
This package binds a YJS, Y.Text type to a HTML input element where type="text" or a TextArea element. Shared cursors are also supported.
import * as Y from 'yjs'
import { WebsocketProvider } from 'y-websocket'
import { TextAreaBinding } from 'y-textarea'
..
const yTextArea = doc.getText("textArea");
const AreaBinding = new TextAreaBinding(yTextArea, textArea);
Shared cursors are not natively supported by input elements or text area, so y-textarea uses an absolutely positioned div with alpha for the shared cursors.
To enable shared cursors, supply at least the "awareness" parameter in the options.
const wsProvider = new WebsocketProvider(`ws://someURL:1234`, 'roomname', doc)
...
const AreaBinding = new TextAreaBinding(
yText,
textArea,
{
awareness : wsProvider.awareness,
clientName: "SoftPenguin",
color : {r:47, g:226, b:147}
}
);
clientName and color can optionally be added. These control the shared cursor label and color.
Due to how the shared cursors work its sometimes necessary to manually reposition the cursors, if for example your app, moves the text area, then the currently displayed cursors will have to be repositioned. To do this call rePositionCursors()
window.addEventListener('resize', ()=>{
AreaBinding.rePositionCursors();
});
The selection box div can be styled using the "selectedText" class. The name tag can be styled using the "nameTag" class. e.g:
.selectedText {
border-radius: 2px;
}
.nameTag {
color: white;
font-family: Verdana, Geneva, sans-serif;
font-weight: 400;
font-style: italic;
font-size: 12px;
padding : 3px;
border-radius: 3px;
}
There are some properties that y-textarea.js overwrites, so cant be styled using css, they are:
Currently multi-line select on text areas doesn't work. It turns out that this was pretty tricky to implement performantly. I might think of a way to do this in the future. For now when multi-line selection is being done the cursor will stay at the start of the selection.
Clone this repo, and run:
npm install
HOST=localhost PORT=1234 npx y-websocket-server
npm run dev
FAQs
Text area and input binding for Y.JS
The npm package y-textarea receives a total of 2,890 weekly downloads. As such, y-textarea popularity was classified as popular.
We found that y-textarea demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.