y-textarea
Advanced tools
Comparing version 0.2.5 to 1.0.0
import { options } from './y-textarea-options'; | ||
import * as Y from 'yjs'; | ||
export declare class TextAreaCursors { | ||
private static areaIDCounter; | ||
private _unobserveFns; | ||
@@ -6,0 +5,0 @@ private _cursors; |
@@ -124,10 +124,3 @@ import * as Y from "yjs"; | ||
var rectangleOverlap = getOverlap; | ||
const events = [ | ||
"keyup", | ||
"mouseup", | ||
"touchstart", | ||
"paste", | ||
"cut", | ||
"selectend" | ||
]; | ||
const events = ["keyup", "mouseup", "touchstart", "paste", "cut", "selectend"]; | ||
class Cursor { | ||
@@ -165,2 +158,8 @@ constructor(fontSize, cssColor, element, name) { | ||
}); | ||
Object.defineProperty(this, "_name", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "_parent", { | ||
@@ -174,7 +173,5 @@ enumerable: true, | ||
this._fontSize = fontSize; | ||
this._color = cssColor; | ||
this._parent = element.offsetParent || document.body; | ||
this._div = document.createElement("div"); | ||
this._div.style.position = "absolute"; | ||
this._div.style.backgroundColor = `rgba(${cssColor.r}, ${cssColor.g}, ${cssColor.b}, 0.4)`; | ||
this._div.style.height = fontSize; | ||
@@ -185,11 +182,4 @@ this._div.style.width = "1px"; | ||
this._parent.appendChild(this._div); | ||
if (name !== void 0) { | ||
this._nameDiv = document.createElement("div"); | ||
this._nameDiv.style.position = "absolute"; | ||
this._nameDiv.style.display = "none"; | ||
this._nameDiv.style.backgroundColor = `rgba(${cssColor.r}, ${cssColor.g}, ${cssColor.b}, 1.0)`; | ||
this._nameDiv.classList.add("nameTag"); | ||
this._nameDiv.innerHTML = name; | ||
this._parent.appendChild(this._nameDiv); | ||
} | ||
if (name !== void 0) | ||
this.updateCursor(name, cssColor); | ||
} | ||
@@ -206,2 +196,18 @@ show() { | ||
} | ||
updateCursor(name, cssColor) { | ||
if (this._name === name && this._color.r === cssColor.r && this._color.g === cssColor.g && this._color.b === cssColor.b) | ||
return; | ||
this._color = cssColor; | ||
this._name = name; | ||
if (!this._nameDiv) { | ||
this._nameDiv = document.createElement("div"); | ||
this._nameDiv.style.position = "absolute"; | ||
this._nameDiv.style.display = "none"; | ||
this._nameDiv.classList.add("nameTag"); | ||
this._parent.appendChild(this._nameDiv); | ||
} | ||
this._nameDiv.innerHTML = name; | ||
this._nameDiv.style.backgroundColor = `rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 1.0)`; | ||
this._div.style.backgroundColor = `rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.4)`; | ||
} | ||
setPosition(start, end) { | ||
@@ -291,4 +297,7 @@ this._selectedIndex = { start, end }; | ||
}); | ||
this._areaID = (TextAreaCursors.areaIDCounter++).toString(); | ||
this._areaID = textField.id; | ||
this._textField = textField; | ||
if (textField.id === "") { | ||
throw new Error("ID attribute is required on textarea/field if using cursors"); | ||
} | ||
if (textField.selectionStart === null || textField.selectionEnd === null) { | ||
@@ -324,2 +333,5 @@ throw new Error("unSupported Input type"); | ||
const selection = user["selection"]; | ||
if (!this._cursors.has(clientID) && !selection) { | ||
continue; | ||
} | ||
if (!this._cursors.has(clientID)) { | ||
@@ -334,2 +346,3 @@ this._cursors.set(clientID, new Cursor(fontSize, color, textField, name)); | ||
} | ||
cursorMarker == null ? void 0 : cursorMarker.updateCursor(name, color); | ||
if (encodedStart === void 0 || encodedEnd === void 0) | ||
@@ -405,8 +418,2 @@ continue; | ||
} | ||
Object.defineProperty(TextAreaCursors, "areaIDCounter", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: 0 | ||
}); | ||
var DIFF_DELETE = -1; | ||
@@ -413,0 +420,0 @@ var DIFF_INSERT = 1; |
@@ -1,1 +0,1 @@ | ||
(function(R,C){typeof exports=="object"&&typeof module!="undefined"?C(exports,require("yjs")):typeof define=="function"&&define.amd?define(["exports","yjs"],C):(R=typeof globalThis!="undefined"?globalThis:R||self,C(R["y-textArea"]={},R.Y))})(this,function(R,C){"use strict";function X(t){if(t&&t.__esModule)return t;var n={__proto__:null,[Symbol.toStringTag]:"Module"};return t&&Object.keys(t).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(n,e,i.get?i:{enumerable:!0,get:function(){return t[e]}})}}),n.default=t,Object.freeze(n)}var j=X(C),T={exports:{}};(function(t){(function(){var n=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderStyle","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing","tabSize","MozTabSize"],e=typeof window!="undefined",i=e&&window.mozInnerScreenX!=null;function s(r,a,o){if(!e)throw new Error("textarea-caret-position#getCaretCoordinates should only be called in a browser");var l=o&&o.debug||!1;if(l){var h=document.querySelector("#input-textarea-caret-position-mirror-div");h&&h.parentNode.removeChild(h)}var u=document.createElement("div");u.id="input-textarea-caret-position-mirror-div",document.body.appendChild(u);var c=u.style,v=window.getComputedStyle?window.getComputedStyle(r):r.currentStyle,b=r.nodeName==="INPUT";c.whiteSpace="pre-wrap",b||(c.wordWrap="break-word"),c.position="absolute",l||(c.visibility="hidden"),n.forEach(function(p){b&&p==="lineHeight"?c.lineHeight=v.height:c[p]=v[p]}),i?r.scrollHeight>parseInt(v.height)&&(c.overflowY="scroll"):c.overflow="hidden",u.textContent=r.value.substring(0,a),b&&(u.textContent=u.textContent.replace(/\s/g,"\xA0"));var g=document.createElement("span");g.textContent=r.value.substring(a)||".",u.appendChild(g);var m={top:g.offsetTop+parseInt(v.borderTopWidth),left:g.offsetLeft+parseInt(v.borderLeftWidth),height:parseInt(v.lineHeight)};return l?g.style.backgroundColor="#aaa":document.body.removeChild(u),m}t.exports=s})()})(T);var W=T.exports;function Q(t,n){const e=Math.max(t.x,n.x),i=Math.min(t.x+t.width,n.x+n.width);if(i<e)return null;const s=Math.max(t.y,n.y),r=Math.min(t.y+t.height,n.y+n.height);return r<s?null:new V(e,s,i-e,r-s)}class V{constructor(n,e,i,s){this.x=n,this.y=e,this.width=i,this.height=s}get area(){return this.width*this.height}}var G=Q;const K=["keyup","mouseup","touchstart","paste","cut","selectend"];class Z{constructor(n,e,i,s){Object.defineProperty(this,"_div",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nameDiv",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_color",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_fontSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_selectedIndex",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._selectedIndex={start:-1,end:-1},this._fontSize=n,this._color=e,this._parent=i.offsetParent||document.body,this._div=document.createElement("div"),this._div.style.position="absolute",this._div.style.backgroundColor=`rgba(${e.r}, ${e.g}, ${e.b}, 0.4)`,this._div.style.height=n,this._div.style.width="1px",this._div.style.display="none",this._div.classList.add("selectedText"),this._parent.appendChild(this._div),s!==void 0&&(this._nameDiv=document.createElement("div"),this._nameDiv.style.position="absolute",this._nameDiv.style.display="none",this._nameDiv.style.backgroundColor=`rgba(${e.r}, ${e.g}, ${e.b}, 1.0)`,this._nameDiv.classList.add("nameTag"),this._nameDiv.innerHTML=s,this._parent.appendChild(this._nameDiv))}show(){this._div.style.display="block",this._nameDiv&&(this._nameDiv.style.display="block")}hide(){this._div.style.display="none",this._nameDiv&&(this._nameDiv.style.display="none")}setPosition(n,e){this._selectedIndex={start:n,end:e}}setWidth(n){this._div.style.width=n+"px",n===1?this._div.style.backgroundColor=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 1.0)`:this._div.style.backgroundColor=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.4)`}rePosition(n){if(this._selectedIndex.start===-1||this._selectedIndex.end===-1)return;const e=W(n,this._selectedIndex.start),i=n.offsetTop-n.scrollTop+e.top,s=n.offsetLeft-n.scrollLeft+e.left;let r=1,a=0;if(this._selectedIndex.start!==this._selectedIndex.end){let u=W(n,this._selectedIndex.end);r=u.left-e.left,a=u.top-e.top,a!==0&&(r=1)}const o={x:n.offsetLeft,y:n.offsetTop,width:n.clientWidth,height:n.clientHeight},l={x:s,y:i,width:r,height:parseInt(this._fontSize)},h=G(o,l);if(!h){this.hide();return}this._div.style.top=h.y+"px",this._div.style.left=h.x+"px",this.setWidth(h.width),this.show(),this._nameDiv&&(this._nameDiv.style.top=h.y+parseInt(this._fontSize)+"px",this._nameDiv.style.left=h.x+"px")}destroy(){this._parent.removeChild(this._div),this._nameDiv&&this._parent.removeChild(this._nameDiv)}}class A{constructor(n,e,i){if(Object.defineProperty(this,"_unobserveFns",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_cursors",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_areaID",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_textField",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._areaID=(A.areaIDCounter++).toString(),this._textField=e,e.selectionStart===null||e.selectionEnd===null)throw new Error("unSupported Input type");const s=n.doc;if(s===null)throw new Error("Missing doc on yText");const r=h=>{if(h.removed.length!=0){for(const v of h.removed)if(this._cursors.has(v)){const b=this._cursors.get(v);b==null||b.destroy(),this._cursors.delete(v)}}const u=getComputedStyle(e).getPropertyValue("font-size"),c=i.awareness.getStates();for(const[v,b]of c.entries()){if(v===i.awareness.clientID)continue;const g=b[this._areaID];if(g===void 0)continue;const m=g.start,p=g.end,_=g.name,f=g.color,w=g.selection;this._cursors.has(v)||this._cursors.set(v,new Z(u,f,e,_));const d=this._cursors.get(v);if(!w){d==null||d.setPosition(-1,-1),d==null||d.hide();continue}if(m===void 0||p===void 0)continue;const y=j.createAbsolutePositionFromRelativePosition(JSON.parse(m),s),S=j.createAbsolutePositionFromRelativePosition(JSON.parse(p),s);if(y===null||S===null){d==null||d.hide();continue}d==null||d.setPosition(y.index,S.index),d==null||d.rePosition(e)}};i.awareness.on("update",r),this._unobserveFns.push(()=>i.awareness.off("update",r));const a=()=>{const h=e.selectionStart,u=e.selectionEnd,c=j.createRelativePositionFromTypeIndex(n,h),v=j.createRelativePositionFromTypeIndex(n,u);i.awareness.setLocalStateField(this._areaID,{user:i.awareness.clientID,selection:!0,start:JSON.stringify(c),end:JSON.stringify(v),name:i.clientName,color:i.color||{r:45,g:80,b:237}})};for(const h of K)e.addEventListener(h,a),this._unobserveFns.push(()=>{e.removeEventListener(h,a)});const o=()=>{i.awareness.setLocalStateField(this._areaID,{user:i.awareness.clientID,selection:!1})};e.addEventListener("focusout",o),this._unobserveFns.push(()=>{e.removeEventListener("focusout",o)});const l=()=>{this.rePositionCursors()};e.addEventListener("scroll",l),this._unobserveFns.push(()=>{e.removeEventListener("scroll",l)})}rePositionCursors(){if(this._textField)for(const[n,e]of this._cursors)e.rePosition(this._textField)}destroy(){for(const n of this._unobserveFns)n();this._unobserveFns=[];for(const[n,e]of this._cursors)e.destroy();this._cursors.clear()}}Object.defineProperty(A,"areaIDCounter",{enumerable:!0,configurable:!0,writable:!0,value:0});var E=-1,D=1,P=0;function M(t,n,e,i){if(t===n)return t?[[P,t]]:[];if(e!=null){var s=te(t,n,e);if(s)return s}var r=z(t,n),a=t.substring(0,r);t=t.substring(r),n=n.substring(r),r=$(t,n);var o=t.substring(t.length-r);t=t.substring(0,t.length-r),n=n.substring(0,n.length-r);var l=k(t,n);return a&&l.unshift([P,a]),o&&l.push([P,o]),H(l,i),l}function k(t,n){var e;if(!t)return[[D,n]];if(!n)return[[E,t]];var i=t.length>n.length?t:n,s=t.length>n.length?n:t,r=i.indexOf(s);if(r!==-1)return e=[[D,i.substring(0,r)],[P,s],[D,i.substring(r+s.length)]],t.length>n.length&&(e[0][0]=e[2][0]=E),e;if(s.length===1)return[[E,t],[D,n]];var a=x(t,n);if(a){var o=a[0],l=a[1],h=a[2],u=a[3],c=a[4],v=M(o,h),b=M(l,u);return v.concat([[P,c]],b)}return q(t,n)}function q(t,n){for(var e=t.length,i=n.length,s=Math.ceil((e+i)/2),r=s,a=2*s,o=new Array(a),l=new Array(a),h=0;h<a;h++)o[h]=-1,l[h]=-1;o[r+1]=0,l[r+1]=0;for(var u=e-i,c=u%2!==0,v=0,b=0,g=0,m=0,p=0;p<s;p++){for(var _=-p+v;_<=p-b;_+=2){var f=r+_,w;_===-p||_!==p&&o[f-1]<o[f+1]?w=o[f+1]:w=o[f-1]+1;for(var d=w-_;w<e&&d<i&&t.charAt(w)===n.charAt(d);)w++,d++;if(o[f]=w,w>e)b+=2;else if(d>i)v+=2;else if(c){var y=r+u-_;if(y>=0&&y<a&&l[y]!==-1){var S=e-l[y];if(w>=S)return N(t,n,w,d)}}}for(var I=-p+g;I<=p-m;I+=2){var y=r+I,S;I===-p||I!==p&&l[y-1]<l[y+1]?S=l[y+1]:S=l[y-1]+1;for(var O=S-I;S<e&&O<i&&t.charAt(e-S-1)===n.charAt(i-O-1);)S++,O++;if(l[y]=S,S>e)m+=2;else if(O>i)g+=2;else if(!c){var f=r+u-I;if(f>=0&&f<a&&o[f]!==-1){var w=o[f],d=r+w-f;if(S=e-S,w>=S)return N(t,n,w,d)}}}}return[[E,t],[D,n]]}function N(t,n,e,i){var s=t.substring(0,e),r=n.substring(0,i),a=t.substring(e),o=n.substring(i),l=M(s,r),h=M(a,o);return l.concat(h)}function z(t,n){if(!t||!n||t.charAt(0)!==n.charAt(0))return 0;for(var e=0,i=Math.min(t.length,n.length),s=i,r=0;e<s;)t.substring(r,s)==n.substring(r,s)?(e=s,r=e):i=s,s=Math.floor((i-e)/2+e);return Y(t.charCodeAt(s-1))&&s--,s}function $(t,n){if(!t||!n||t.slice(-1)!==n.slice(-1))return 0;for(var e=0,i=Math.min(t.length,n.length),s=i,r=0;e<s;)t.substring(t.length-s,t.length-r)==n.substring(n.length-s,n.length-r)?(e=s,r=e):i=s,s=Math.floor((i-e)/2+e);return B(t.charCodeAt(t.length-s))&&s--,s}function x(t,n){var e=t.length>n.length?t:n,i=t.length>n.length?n:t;if(e.length<4||i.length*2<e.length)return null;function s(b,g,m){for(var p=b.substring(m,m+Math.floor(b.length/4)),_=-1,f="",w,d,y,S;(_=g.indexOf(p,_+1))!==-1;){var I=z(b.substring(m),g.substring(_)),O=$(b.substring(0,m),g.substring(0,_));f.length<O+I&&(f=g.substring(_-O,_)+g.substring(_,_+I),w=b.substring(0,m-O),d=b.substring(m+I),y=g.substring(0,_-O),S=g.substring(_+I))}return f.length*2>=b.length?[w,d,y,S,f]:null}var r=s(e,i,Math.ceil(e.length/4)),a=s(e,i,Math.ceil(e.length/2)),o;if(!r&&!a)return null;a?r?o=r[4].length>a[4].length?r:a:o=a:o=r;var l,h,u,c;t.length>n.length?(l=o[0],h=o[1],u=o[2],c=o[3]):(u=o[0],c=o[1],l=o[2],h=o[3]);var v=o[4];return[l,h,u,c,v]}function H(t,n){t.push([P,""]);for(var e=0,i=0,s=0,r="",a="",o;e<t.length;){if(e<t.length-1&&!t[e][1]){t.splice(e,1);continue}switch(t[e][0]){case D:s++,a+=t[e][1],e++;break;case E:i++,r+=t[e][1],e++;break;case P:var l=e-s-i-1;if(n){if(l>=0&&U(t[l][1])){var h=t[l][1].slice(-1);if(t[l][1]=t[l][1].slice(0,-1),r=h+r,a=h+a,!t[l][1]){t.splice(l,1),e--;var u=l-1;t[u]&&t[u][0]===D&&(s++,a=t[u][1]+a,u--),t[u]&&t[u][0]===E&&(i++,r=t[u][1]+r,u--),l=u}}if(J(t[e][1])){var h=t[e][1].charAt(0);t[e][1]=t[e][1].slice(1),r+=h,a+=h}}if(e<t.length-1&&!t[e][1]){t.splice(e,1);break}if(r.length>0||a.length>0){r.length>0&&a.length>0&&(o=z(a,r),o!==0&&(l>=0?t[l][1]+=a.substring(0,o):(t.splice(0,0,[P,a.substring(0,o)]),e++),a=a.substring(o),r=r.substring(o)),o=$(a,r),o!==0&&(t[e][1]=a.substring(a.length-o)+t[e][1],a=a.substring(0,a.length-o),r=r.substring(0,r.length-o)));var c=s+i;r.length===0&&a.length===0?(t.splice(e-c,c),e=e-c):r.length===0?(t.splice(e-c,c,[D,a]),e=e-c+1):a.length===0?(t.splice(e-c,c,[E,r]),e=e-c+1):(t.splice(e-c,c,[E,r],[D,a]),e=e-c+2)}e!==0&&t[e-1][0]===P?(t[e-1][1]+=t[e][1],t.splice(e,1)):e++,s=0,i=0,r="",a="";break}}t[t.length-1][1]===""&&t.pop();var v=!1;for(e=1;e<t.length-1;)t[e-1][0]===P&&t[e+1][0]===P&&(t[e][1].substring(t[e][1].length-t[e-1][1].length)===t[e-1][1]?(t[e][1]=t[e-1][1]+t[e][1].substring(0,t[e][1].length-t[e-1][1].length),t[e+1][1]=t[e-1][1]+t[e+1][1],t.splice(e-1,1),v=!0):t[e][1].substring(0,t[e+1][1].length)==t[e+1][1]&&(t[e-1][1]+=t[e+1][1],t[e][1]=t[e][1].substring(t[e+1][1].length)+t[e+1][1],t.splice(e+1,1),v=!0)),e++;v&&H(t,n)}function Y(t){return t>=55296&&t<=56319}function B(t){return t>=56320&&t<=57343}function J(t){return B(t.charCodeAt(0))}function U(t){return Y(t.charCodeAt(t.length-1))}function ee(t){for(var n=[],e=0;e<t.length;e++)t[e][1].length>0&&n.push(t[e]);return n}function F(t,n,e,i){return U(t)||J(i)?null:ee([[P,t],[E,n],[D,e],[P,i]])}function te(t,n,e){var i=typeof e=="number"?{index:e,length:0}:e.oldRange,s=typeof e=="number"?null:e.newRange,r=t.length,a=n.length;if(i.length===0&&(s===null||s.length===0)){var o=i.index,l=t.slice(0,o),h=t.slice(o),u=s?s.index:null;e:{var c=o+a-r;if(u!==null&&u!==c||c<0||c>a)break e;var v=n.slice(0,c),b=n.slice(c);if(b!==h)break e;var g=Math.min(o,c),m=l.slice(0,g),p=v.slice(0,g);if(m!==p)break e;var _=l.slice(g),f=v.slice(g);return F(m,_,f,h)}e:{if(u!==null&&u!==o)break e;var w=o,v=n.slice(0,w),b=n.slice(w);if(v!==l)break e;var d=Math.min(r-w,a-w),y=h.slice(h.length-d),S=b.slice(b.length-d);if(y!==S)break e;var _=h.slice(0,h.length-d),f=b.slice(0,b.length-d);return F(l,_,f,y)}}if(i.length>0&&s&&s.length===0){e:{var m=t.slice(0,i.index),y=t.slice(i.index+i.length),g=m.length,d=y.length;if(a<g+d)break e;var p=n.slice(0,g),S=n.slice(a-d);if(m!==p||y!==S)break e;var _=t.slice(g,r-d),f=n.slice(g,a-d);return F(m,_,f,y)}}return null}function L(t,n,e){return M(t,n,e,!0)}L.INSERT=D,L.DELETE=E,L.EQUAL=P;var ne=L;class re{constructor(n,e,i){Object.defineProperty(this,"_cursors",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_unobserveFns",{enumerable:!0,configurable:!0,writable:!0,value:[]});let s=n.doc;if(s===null)throw new Error("Missing doc on yText");if(e.selectionStart===void 0||e.selectionEnd===void 0)throw new Error("textField argument doesn't look like a text field");i&&(this._cursors=new A(n,e,i)),e.value=n.toString();let r,a,o;const l=()=>{o=e.selectionDirection;const v=this.createRange(e);r=j.createRelativePositionFromTypeIndex(n,v.left),a=j.createRelativePositionFromTypeIndex(n,v.right)};s.on("beforeTransaction",l),this._unobserveFns.push(()=>s.off("beforeTransaction",l));let h=!1;const u=(v,b)=>{if(b.local&&h){h=!1;return}if(e.value=n.toString(),e.getRootNode().activeElement===e){const g=j.createAbsolutePositionFromRelativePosition(r,s),m=j.createAbsolutePositionFromRelativePosition(a,s);g!==null&&m!==null&&(o===null&&(o="forward"),e.setSelectionRange(g.index,m.index,o))}};n.observe(u),this._unobserveFns.push(()=>n.unobserve(u));const c=()=>{h=!0;const v=this.createRange(e);let b=n.toString(),g=e.value,m=ne(b,g,v.left),p=0;for(let _=0;_<m.length;_++){let f=m[_];f[0]===0?p+=f[1].length:f[0]===-1?n.delete(p,f[1].length):(n.insert(p,f[1]),p+=f[1].length)}};e.addEventListener("input",c),this._unobserveFns.push(()=>e.removeEventListener("input",c))}createRange(n){const e=n.selectionStart,i=n.selectionEnd;return{left:e,right:i}}rePositionCursors(){var n;(n=this._cursors)==null||n.rePositionCursors()}destroy(){for(const n of this._unobserveFns)n();this._unobserveFns=[],this._cursors&&this._cursors.destroy()}}R.TextAreaBinding=re,Object.defineProperty(R,"__esModule",{value:!0}),R[Symbol.toStringTag]="Module"}); | ||
(function(C,j){typeof exports=="object"&&typeof module!="undefined"?j(exports,require("yjs")):typeof define=="function"&&define.amd?define(["exports","yjs"],j):(C=typeof globalThis!="undefined"?globalThis:C||self,j(C["y-textArea"]={},C.Y))})(this,function(C,j){"use strict";function U(t){if(t&&t.__esModule)return t;var r={__proto__:null,[Symbol.toStringTag]:"Module"};return t&&Object.keys(t).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(r,e,i.get?i:{enumerable:!0,get:function(){return t[e]}})}}),r.default=t,Object.freeze(r)}var R=U(j),$={exports:{}};(function(t){(function(){var r=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderStyle","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing","tabSize","MozTabSize"],e=typeof window!="undefined",i=e&&window.mozInnerScreenX!=null;function s(n,o,a){if(!e)throw new Error("textarea-caret-position#getCaretCoordinates should only be called in a browser");var l=a&&a.debug||!1;if(l){var h=document.querySelector("#input-textarea-caret-position-mirror-div");h&&h.parentNode.removeChild(h)}var u=document.createElement("div");u.id="input-textarea-caret-position-mirror-div",document.body.appendChild(u);var c=u.style,v=window.getComputedStyle?window.getComputedStyle(n):n.currentStyle,b=n.nodeName==="INPUT";c.whiteSpace="pre-wrap",b||(c.wordWrap="break-word"),c.position="absolute",l||(c.visibility="hidden"),r.forEach(function(p){b&&p==="lineHeight"?c.lineHeight=v.height:c[p]=v[p]}),i?n.scrollHeight>parseInt(v.height)&&(c.overflowY="scroll"):c.overflow="hidden",u.textContent=n.value.substring(0,o),b&&(u.textContent=u.textContent.replace(/\s/g,"\xA0"));var d=document.createElement("span");d.textContent=n.value.substring(o)||".",u.appendChild(d);var m={top:d.offsetTop+parseInt(v.borderTopWidth),left:d.offsetLeft+parseInt(v.borderLeftWidth),height:parseInt(v.lineHeight)};return l?d.style.backgroundColor="#aaa":document.body.removeChild(u),m}t.exports=s})()})($);var W=$.exports;function X(t,r){const e=Math.max(t.x,r.x),i=Math.min(t.x+t.width,r.x+r.width);if(i<e)return null;const s=Math.max(t.y,r.y),n=Math.min(t.y+t.height,r.y+r.height);return n<s?null:new Q(e,s,i-e,n-s)}class Q{constructor(r,e,i,s){this.x=r,this.y=e,this.width=i,this.height=s}get area(){return this.width*this.height}}var V=X;const G=["keyup","mouseup","touchstart","paste","cut","selectend"];class K{constructor(r,e,i,s){Object.defineProperty(this,"_div",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_nameDiv",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_color",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_fontSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_selectedIndex",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_name",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._selectedIndex={start:-1,end:-1},this._fontSize=r,this._parent=i.offsetParent||document.body,this._div=document.createElement("div"),this._div.style.position="absolute",this._div.style.height=r,this._div.style.width="1px",this._div.style.display="none",this._div.classList.add("selectedText"),this._parent.appendChild(this._div),s!==void 0&&this.updateCursor(s,e)}show(){this._div.style.display="block",this._nameDiv&&(this._nameDiv.style.display="block")}hide(){this._div.style.display="none",this._nameDiv&&(this._nameDiv.style.display="none")}updateCursor(r,e){this._name===r&&this._color.r===e.r&&this._color.g===e.g&&this._color.b===e.b||(this._color=e,this._name=r,this._nameDiv||(this._nameDiv=document.createElement("div"),this._nameDiv.style.position="absolute",this._nameDiv.style.display="none",this._nameDiv.classList.add("nameTag"),this._parent.appendChild(this._nameDiv)),this._nameDiv.innerHTML=r,this._nameDiv.style.backgroundColor=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 1.0)`,this._div.style.backgroundColor=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.4)`)}setPosition(r,e){this._selectedIndex={start:r,end:e}}setWidth(r){this._div.style.width=r+"px",r===1?this._div.style.backgroundColor=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 1.0)`:this._div.style.backgroundColor=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.4)`}rePosition(r){if(this._selectedIndex.start===-1||this._selectedIndex.end===-1)return;const e=W(r,this._selectedIndex.start),i=r.offsetTop-r.scrollTop+e.top,s=r.offsetLeft-r.scrollLeft+e.left;let n=1,o=0;if(this._selectedIndex.start!==this._selectedIndex.end){let u=W(r,this._selectedIndex.end);n=u.left-e.left,o=u.top-e.top,o!==0&&(n=1)}const a={x:r.offsetLeft,y:r.offsetTop,width:r.clientWidth,height:r.clientHeight},l={x:s,y:i,width:n,height:parseInt(this._fontSize)},h=V(a,l);if(!h){this.hide();return}this._div.style.top=h.y+"px",this._div.style.left=h.x+"px",this.setWidth(h.width),this.show(),this._nameDiv&&(this._nameDiv.style.top=h.y+parseInt(this._fontSize)+"px",this._nameDiv.style.left=h.x+"px")}destroy(){this._parent.removeChild(this._div),this._nameDiv&&this._parent.removeChild(this._nameDiv)}}class Z{constructor(r,e,i){if(Object.defineProperty(this,"_unobserveFns",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_cursors",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_areaID",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_textField",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._areaID=e.id,this._textField=e,e.id==="")throw new Error("ID attribute is required on textarea/field if using cursors");if(e.selectionStart===null||e.selectionEnd===null)throw new Error("unSupported Input type");const s=r.doc;if(s===null)throw new Error("Missing doc on yText");const n=h=>{if(h.removed.length!=0){for(const v of h.removed)if(this._cursors.has(v)){const b=this._cursors.get(v);b==null||b.destroy(),this._cursors.delete(v)}}const u=getComputedStyle(e).getPropertyValue("font-size"),c=i.awareness.getStates();for(const[v,b]of c.entries()){if(v===i.awareness.clientID)continue;const d=b[this._areaID];if(d===void 0)continue;const m=d.start,p=d.end,_=d.name,f=d.color,w=d.selection;if(!this._cursors.has(v)&&!w)continue;this._cursors.has(v)||this._cursors.set(v,new K(u,f,e,_));const g=this._cursors.get(v);if(!w){g==null||g.setPosition(-1,-1),g==null||g.hide();continue}if(g==null||g.updateCursor(_,f),m===void 0||p===void 0)continue;const y=R.createAbsolutePositionFromRelativePosition(JSON.parse(m),s),S=R.createAbsolutePositionFromRelativePosition(JSON.parse(p),s);if(y===null||S===null){g==null||g.hide();continue}g==null||g.setPosition(y.index,S.index),g==null||g.rePosition(e)}};i.awareness.on("update",n),this._unobserveFns.push(()=>i.awareness.off("update",n));const o=()=>{const h=e.selectionStart,u=e.selectionEnd,c=R.createRelativePositionFromTypeIndex(r,h),v=R.createRelativePositionFromTypeIndex(r,u);i.awareness.setLocalStateField(this._areaID,{user:i.awareness.clientID,selection:!0,start:JSON.stringify(c),end:JSON.stringify(v),name:i.clientName,color:i.color||{r:45,g:80,b:237}})};for(const h of G)e.addEventListener(h,o),this._unobserveFns.push(()=>{e.removeEventListener(h,o)});const a=()=>{i.awareness.setLocalStateField(this._areaID,{user:i.awareness.clientID,selection:!1})};e.addEventListener("focusout",a),this._unobserveFns.push(()=>{e.removeEventListener("focusout",a)});const l=()=>{this.rePositionCursors()};e.addEventListener("scroll",l),this._unobserveFns.push(()=>{e.removeEventListener("scroll",l)})}rePositionCursors(){if(this._textField)for(const[r,e]of this._cursors)e.rePosition(this._textField)}destroy(){for(const r of this._unobserveFns)r();this._unobserveFns=[];for(const[r,e]of this._cursors)e.destroy();this._cursors.clear()}}var E=-1,I=1,P=0;function A(t,r,e,i){if(t===r)return t?[[P,t]]:[];if(e!=null){var s=te(t,r,e);if(s)return s}var n=L(t,r),o=t.substring(0,n);t=t.substring(n),r=r.substring(n),n=z(t,r);var a=t.substring(t.length-n);t=t.substring(0,t.length-n),r=r.substring(0,r.length-n);var l=q(t,r);return o&&l.unshift([P,o]),a&&l.push([P,a]),N(l,i),l}function q(t,r){var e;if(!t)return[[I,r]];if(!r)return[[E,t]];var i=t.length>r.length?t:r,s=t.length>r.length?r:t,n=i.indexOf(s);if(n!==-1)return e=[[I,i.substring(0,n)],[P,s],[I,i.substring(n+s.length)]],t.length>r.length&&(e[0][0]=e[2][0]=E),e;if(s.length===1)return[[E,t],[I,r]];var o=x(t,r);if(o){var a=o[0],l=o[1],h=o[2],u=o[3],c=o[4],v=A(a,h),b=A(l,u);return v.concat([[P,c]],b)}return k(t,r)}function k(t,r){for(var e=t.length,i=r.length,s=Math.ceil((e+i)/2),n=s,o=2*s,a=new Array(o),l=new Array(o),h=0;h<o;h++)a[h]=-1,l[h]=-1;a[n+1]=0,l[n+1]=0;for(var u=e-i,c=u%2!==0,v=0,b=0,d=0,m=0,p=0;p<s;p++){for(var _=-p+v;_<=p-b;_+=2){var f=n+_,w;_===-p||_!==p&&a[f-1]<a[f+1]?w=a[f+1]:w=a[f-1]+1;for(var g=w-_;w<e&&g<i&&t.charAt(w)===r.charAt(g);)w++,g++;if(a[f]=w,w>e)b+=2;else if(g>i)v+=2;else if(c){var y=n+u-_;if(y>=0&&y<o&&l[y]!==-1){var S=e-l[y];if(w>=S)return F(t,r,w,g)}}}for(var D=-p+d;D<=p-m;D+=2){var y=n+D,S;D===-p||D!==p&&l[y-1]<l[y+1]?S=l[y+1]:S=l[y-1]+1;for(var O=S-D;S<e&&O<i&&t.charAt(e-S-1)===r.charAt(i-O-1);)S++,O++;if(l[y]=S,S>e)m+=2;else if(O>i)d+=2;else if(!c){var f=n+u-D;if(f>=0&&f<o&&a[f]!==-1){var w=a[f],g=n+w-f;if(S=e-S,w>=S)return F(t,r,w,g)}}}}return[[E,t],[I,r]]}function F(t,r,e,i){var s=t.substring(0,e),n=r.substring(0,i),o=t.substring(e),a=r.substring(i),l=A(s,n),h=A(o,a);return l.concat(h)}function L(t,r){if(!t||!r||t.charAt(0)!==r.charAt(0))return 0;for(var e=0,i=Math.min(t.length,r.length),s=i,n=0;e<s;)t.substring(n,s)==r.substring(n,s)?(e=s,n=e):i=s,s=Math.floor((i-e)/2+e);return H(t.charCodeAt(s-1))&&s--,s}function z(t,r){if(!t||!r||t.slice(-1)!==r.slice(-1))return 0;for(var e=0,i=Math.min(t.length,r.length),s=i,n=0;e<s;)t.substring(t.length-s,t.length-n)==r.substring(r.length-s,r.length-n)?(e=s,n=e):i=s,s=Math.floor((i-e)/2+e);return Y(t.charCodeAt(t.length-s))&&s--,s}function x(t,r){var e=t.length>r.length?t:r,i=t.length>r.length?r:t;if(e.length<4||i.length*2<e.length)return null;function s(b,d,m){for(var p=b.substring(m,m+Math.floor(b.length/4)),_=-1,f="",w,g,y,S;(_=d.indexOf(p,_+1))!==-1;){var D=L(b.substring(m),d.substring(_)),O=z(b.substring(0,m),d.substring(0,_));f.length<O+D&&(f=d.substring(_-O,_)+d.substring(_,_+D),w=b.substring(0,m-O),g=b.substring(m+D),y=d.substring(0,_-O),S=d.substring(_+D))}return f.length*2>=b.length?[w,g,y,S,f]:null}var n=s(e,i,Math.ceil(e.length/4)),o=s(e,i,Math.ceil(e.length/2)),a;if(!n&&!o)return null;o?n?a=n[4].length>o[4].length?n:o:a=o:a=n;var l,h,u,c;t.length>r.length?(l=a[0],h=a[1],u=a[2],c=a[3]):(u=a[0],c=a[1],l=a[2],h=a[3]);var v=a[4];return[l,h,u,c,v]}function N(t,r){t.push([P,""]);for(var e=0,i=0,s=0,n="",o="",a;e<t.length;){if(e<t.length-1&&!t[e][1]){t.splice(e,1);continue}switch(t[e][0]){case I:s++,o+=t[e][1],e++;break;case E:i++,n+=t[e][1],e++;break;case P:var l=e-s-i-1;if(r){if(l>=0&&J(t[l][1])){var h=t[l][1].slice(-1);if(t[l][1]=t[l][1].slice(0,-1),n=h+n,o=h+o,!t[l][1]){t.splice(l,1),e--;var u=l-1;t[u]&&t[u][0]===I&&(s++,o=t[u][1]+o,u--),t[u]&&t[u][0]===E&&(i++,n=t[u][1]+n,u--),l=u}}if(B(t[e][1])){var h=t[e][1].charAt(0);t[e][1]=t[e][1].slice(1),n+=h,o+=h}}if(e<t.length-1&&!t[e][1]){t.splice(e,1);break}if(n.length>0||o.length>0){n.length>0&&o.length>0&&(a=L(o,n),a!==0&&(l>=0?t[l][1]+=o.substring(0,a):(t.splice(0,0,[P,o.substring(0,a)]),e++),o=o.substring(a),n=n.substring(a)),a=z(o,n),a!==0&&(t[e][1]=o.substring(o.length-a)+t[e][1],o=o.substring(0,o.length-a),n=n.substring(0,n.length-a)));var c=s+i;n.length===0&&o.length===0?(t.splice(e-c,c),e=e-c):n.length===0?(t.splice(e-c,c,[I,o]),e=e-c+1):o.length===0?(t.splice(e-c,c,[E,n]),e=e-c+1):(t.splice(e-c,c,[E,n],[I,o]),e=e-c+2)}e!==0&&t[e-1][0]===P?(t[e-1][1]+=t[e][1],t.splice(e,1)):e++,s=0,i=0,n="",o="";break}}t[t.length-1][1]===""&&t.pop();var v=!1;for(e=1;e<t.length-1;)t[e-1][0]===P&&t[e+1][0]===P&&(t[e][1].substring(t[e][1].length-t[e-1][1].length)===t[e-1][1]?(t[e][1]=t[e-1][1]+t[e][1].substring(0,t[e][1].length-t[e-1][1].length),t[e+1][1]=t[e-1][1]+t[e+1][1],t.splice(e-1,1),v=!0):t[e][1].substring(0,t[e+1][1].length)==t[e+1][1]&&(t[e-1][1]+=t[e+1][1],t[e][1]=t[e][1].substring(t[e+1][1].length)+t[e+1][1],t.splice(e+1,1),v=!0)),e++;v&&N(t,r)}function H(t){return t>=55296&&t<=56319}function Y(t){return t>=56320&&t<=57343}function B(t){return Y(t.charCodeAt(0))}function J(t){return H(t.charCodeAt(t.length-1))}function ee(t){for(var r=[],e=0;e<t.length;e++)t[e][1].length>0&&r.push(t[e]);return r}function T(t,r,e,i){return J(t)||B(i)?null:ee([[P,t],[E,r],[I,e],[P,i]])}function te(t,r,e){var i=typeof e=="number"?{index:e,length:0}:e.oldRange,s=typeof e=="number"?null:e.newRange,n=t.length,o=r.length;if(i.length===0&&(s===null||s.length===0)){var a=i.index,l=t.slice(0,a),h=t.slice(a),u=s?s.index:null;e:{var c=a+o-n;if(u!==null&&u!==c||c<0||c>o)break e;var v=r.slice(0,c),b=r.slice(c);if(b!==h)break e;var d=Math.min(a,c),m=l.slice(0,d),p=v.slice(0,d);if(m!==p)break e;var _=l.slice(d),f=v.slice(d);return T(m,_,f,h)}e:{if(u!==null&&u!==a)break e;var w=a,v=r.slice(0,w),b=r.slice(w);if(v!==l)break e;var g=Math.min(n-w,o-w),y=h.slice(h.length-g),S=b.slice(b.length-g);if(y!==S)break e;var _=h.slice(0,h.length-g),f=b.slice(0,b.length-g);return T(l,_,f,y)}}if(i.length>0&&s&&s.length===0){e:{var m=t.slice(0,i.index),y=t.slice(i.index+i.length),d=m.length,g=y.length;if(o<d+g)break e;var p=r.slice(0,d),S=r.slice(o-g);if(m!==p||y!==S)break e;var _=t.slice(d,n-g),f=r.slice(d,o-g);return T(m,_,f,y)}}return null}function M(t,r,e){return A(t,r,e,!0)}M.INSERT=I,M.DELETE=E,M.EQUAL=P;var re=M;class ne{constructor(r,e,i){Object.defineProperty(this,"_cursors",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_unobserveFns",{enumerable:!0,configurable:!0,writable:!0,value:[]});let s=r.doc;if(s===null)throw new Error("Missing doc on yText");if(e.selectionStart===void 0||e.selectionEnd===void 0)throw new Error("textField argument doesn't look like a text field");i&&(this._cursors=new Z(r,e,i)),e.value=r.toString();let n,o,a;const l=()=>{a=e.selectionDirection;const v=this.createRange(e);n=R.createRelativePositionFromTypeIndex(r,v.left),o=R.createRelativePositionFromTypeIndex(r,v.right)};s.on("beforeTransaction",l),this._unobserveFns.push(()=>s.off("beforeTransaction",l));let h=!1;const u=(v,b)=>{if(b.local&&h){h=!1;return}if(e.value=r.toString(),e.getRootNode().activeElement===e){const d=R.createAbsolutePositionFromRelativePosition(n,s),m=R.createAbsolutePositionFromRelativePosition(o,s);d!==null&&m!==null&&(a===null&&(a="forward"),e.setSelectionRange(d.index,m.index,a))}};r.observe(u),this._unobserveFns.push(()=>r.unobserve(u));const c=()=>{h=!0;const v=this.createRange(e);let b=r.toString(),d=e.value,m=re(b,d,v.left),p=0;for(let _=0;_<m.length;_++){let f=m[_];f[0]===0?p+=f[1].length:f[0]===-1?r.delete(p,f[1].length):(r.insert(p,f[1]),p+=f[1].length)}};e.addEventListener("input",c),this._unobserveFns.push(()=>e.removeEventListener("input",c))}createRange(r){const e=r.selectionStart,i=r.selectionEnd;return{left:e,right:i}}rePositionCursors(){var r;(r=this._cursors)==null||r.rePositionCursors()}destroy(){for(const r of this._unobserveFns)r();this._unobserveFns=[],this._cursors&&this._cursors.destroy()}}C.TextAreaBinding=ne,Object.defineProperty(C,"__esModule",{value:!0}),C[Symbol.toStringTag]="Module"}); |
@@ -16,3 +16,3 @@ { | ||
"types": "./dist/y-textArea.d.ts", | ||
"version": "0.2.5", | ||
"version": "1.0.0", | ||
"scripts": { | ||
@@ -22,3 +22,7 @@ "dev": "vite --host", | ||
"preview": "vite preview", | ||
"test": "echo \"No test specified\"" | ||
"version": "npm run build", | ||
"release": "np", | ||
"test": "echo \"No test specified\"", | ||
"prettier:check": "prettier --check .", | ||
"prettier:fix": "prettier --write ." | ||
}, | ||
@@ -28,10 +32,11 @@ "devDependencies": { | ||
"@types/textarea-caret": "^3.0.1", | ||
"np": "^7.6.0", | ||
"fast-diff": "^1.2.0", | ||
"np": "^7.6.3", | ||
"prettier": "^2.8.3", | ||
"rectangle-overlap": "^2.0.0", | ||
"textarea-caret": "^3.1.0", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.5.4", | ||
"vite": "^2.8.0", | ||
"y-websocket": "^1.3.18", | ||
"fast-diff": "^1.2.0", | ||
"rectangle-overlap": "^2.0.0", | ||
"textarea-caret": "^3.1.0" | ||
"y-websocket": "^1.3.18" | ||
}, | ||
@@ -38,0 +43,0 @@ "peerDependencies": { |
# y-TextArea | ||
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. | ||
![](demo.gif) | ||
## Basic Example: | ||
## Basic Example: | ||
@@ -24,3 +24,4 @@ ```js | ||
To enable shared cursors, supply at least the "awareness" parameter in the options. | ||
To enable shared cursors, supply the "awareness" parameter in the options. | ||
y-textarea uses the ID attribute of the textarea to associate cursors to textareas, so ensure you uses consistent IDs all clients for textareas. | ||
@@ -40,12 +41,13 @@ ```typescript | ||
``` | ||
clientName and color can optionally be added. These control the shared cursor label and color. | ||
### Repositioning | ||
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()` | ||
``` typescript | ||
window.addEventListener('resize', ()=>{ | ||
AreaBinding.rePositionCursors(); | ||
}); | ||
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()` | ||
```typescript | ||
window.addEventListener('resize', () => { | ||
AreaBinding.rePositionCursors() | ||
}) | ||
``` | ||
@@ -68,3 +70,3 @@ | ||
font-size: 12px; | ||
padding : 3px; | ||
padding: 3px; | ||
border-radius: 3px; | ||
@@ -74,3 +76,4 @@ } | ||
There are some properties that y-textarea.js overwrites, so cant be styled using css, they are: | ||
There are some properties that y-textarea.js overwrites, so cant be styled using css, they are: | ||
- position | ||
@@ -83,3 +86,3 @@ - backgroundColor | ||
To destroy the binding call `destroy` on the `TextAreaBinding`. This will remove all event listeners and if used remove all cursors from the DOM. | ||
To destroy the binding call `destroy` on the `TextAreaBinding`. This will remove all event listeners and if used remove all cursors from the DOM. | ||
@@ -93,6 +96,9 @@ ```typescript | ||
### Caveats | ||
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. | ||
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. | ||
## Run Demo | ||
Clone this repo, and run: | ||
```bash | ||
@@ -103,4 +109,1 @@ npm install | ||
``` | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
57131
1115
2
103
11