UNPKG

@kitschpatrol/tweakpane-plugin-textarea

Version:

A fork of @pangenerator/tweakpane-textarea-plugin with build optimizations.

2 lines (1 loc) 2.69 kB
import{ClassName as e,forceCast as t,createPlugin as r,parseRecord as i}from"@tweakpane/core";const n=e("txtr");class o{constructor(e,t){this.onChange_=this.onChange_.bind(this),this.element=e.createElement("div"),this.element.classList.add(n()),t.viewProps.bindClassModifiers(this.element);const r=e.createElement("textarea");r.rows=t.rows,r.cols=22,r.placeholder=t.placeholder,r.classList.add(n("i")),t.viewProps.bindDisabled(r),this.element.appendChild(r),this.inputElement=r,t.value.emitter.on("change",this.onChange_),this.value_=t.value,this.refresh()}refresh(){this.inputElement.value=this.value_.rawValue}onChange_(){this.refresh()}}class a{constructor(e,t){this.onInputChange_=this.onInputChange_.bind(this),this.value=t.value,this.viewProps=t.viewProps,this.rows=t.rows,this.placeholder=t.placeholder,this.view=new o(e,{value:this.value,viewProps:this.viewProps,rows:this.rows,placeholder:this.placeholder}),this.view.inputElement.addEventListener("keyup",this.onInputChange_)}onInputChange_(e){const r=t(e.currentTarget).value;this.value.rawValue=r,this.view.refresh()}}const s="textarea",l=".tp-txtrv{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-color:rgba(0,0,0,0);border-width:0;font-family:inherit;font-size:inherit;font-weight:inherit;margin:0;outline:none;padding:0}.tp-txtrv{background-color:var(--in-bg);border-radius:var(--bld-br);box-sizing:border-box;color:var(--in-fg);font-family:inherit;height:var(--cnt-usz);line-height:var(--cnt-usz);min-width:0;width:100%}.tp-txtrv:hover{background-color:var(--in-bg-h)}.tp-txtrv:focus{background-color:var(--in-bg-f)}.tp-txtrv:active{background-color:var(--in-bg-a)}.tp-txtrv:disabled{opacity:.5}.tp-txtrv{display:block;height:auto;padding-bottom:0;overflow:hidden;position:relative}.tp-txtrv.tp-v-disabled{opacity:.5}.tp-txtrv .tp-txtrv_i{font-family:var(--font-family);background-color:var(--in-bg);border-radius:var(--bld-br);box-sizing:border-box;color:var(--in-fg);font-size:11px;padding:4px;line-height:16px;min-width:0;width:100%;border:none;height:100%;resize:none;margin-bottom:-8px}.tp-txtrv .tp-txtrv_i:focus{outline:none}",h=[r({id:"input-template",type:"input",accept(e,t){if("string"!=typeof e)return null;const r=i(t,(e=>({view:e.required.constant("textarea"),rows:e.optional.number,placeholder:e.optional.string})));return r?{initialValue:e,params:r}:null},binding:{reader:e=>e=>"string"==typeof e?e:"",writer:e=>(e,t)=>{e.write(t)}},controller(e){var t,r;return new a(e.document,{value:e.value,rows:null!==(t=e.params.rows)&&void 0!==t?t:3,placeholder:null!==(r=e.params.placeholder)&&void 0!==r?r:"Enter text here",viewProps:e.viewProps})}})];export{l as css,s as id,h as plugins};