var e,t,i={7386(e,t,i){i.d(t,{I:()=>f,O:()=>c}),i(9189);var s=i(9609),r=i(3331),a=i(4084),o=i(925),l=i(2927),n=i(8899),d=i(4955),p=i(3517),h=i(9956),m=function(e,t,i,s){var r,a=arguments.length,o=a<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var l=e.length-1;l>=0;l--)(r=e[l])&&(o=(a<3?r(o):a>3?r(t,i,o):r(t,i))||o);return a>3&&o&&Object.defineProperty(t,i,o),o};const c=["left","right","center"];var f;!function(e){let t=class extends l.LitElement{constructor(){super(...arguments),this.alignment="left",this.disabled=!1,this.isEditing=!1,this.maxLines="",this.content="Click to edit text",this.message={type:"error",message:"That is not a valid input."},this.alert=!1,this.hideMessage=!1,this.pattern="",this.type=null,this.ariaLabel="editable field",this.ariaDescribedBy="",this.reportValidity=()=>{this.dispatchEvent(new Event("invalid",{bubbles:!1,cancelable:!0,composed:!0}))},this.checkValidity=e=>{let t=!0;const i=i=>{null===e.match(i)&&(t=!1)};if(this.pattern)i(new RegExp(this.pattern));else if(e&&this.type)switch(this.type){case"integer":i(new RegExp(r.b.integerString));break;case"decimal":i(new RegExp(r.b.decimalString))}return t},this.handleFocus=()=>{this.disabled||(this.isEditing=!0,this.setRange())},this.handleKeydown=e=>{var t,i;const{key:s,code:r}=e;if(!["Tab","Meta","Shift","Delete","Backspace","Arrow"].some(e=>r.includes(e)))if("integer"===this.type&&(s.includes(".")||"-"===s&&(null===(t=this.editableField)||void 0===t?void 0:t.innerText.includes("-"))))e.preventDefault();else if("integer"!==this.type&&"decimal"!==this.type||!r.match("Space")){if(this.type&&1===s.length){const t=((null===(i=this.editableField)||void 0===i?void 0:i.innerText.trim())||"")+s;("integer"!==this.type||/^-?\d*$/.test(t))&&("decimal"!==this.type||/^-?\d*\.?\d*$/.test(t))||e.preventDefault()}}else e.preventDefault()},this.handleBlur=()=>{var e,t,i;this.isEditing=!1,this.maxLines.length>0&&(null===(e=this.editableField)||void 0===e||e.scrollTo(0,0));const s=(null===(i=null===(t=this.editableField)||void 0===t?void 0:t.innerText)||void 0===i?void 0:i.trim())||"",r=o.default.sanitize(s);r!==this.content&&(this.content=r),this.alert=!1,this.handleValidation()}}connectedCallback(){super.connectedCallback(),this.addEventListener("focus",this.handleFocus)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("focus",this.handleFocus)}firstUpdated(e){super.firstUpdated(e),this.innerText&&this.innerText.trim().length>0&&this.innerText.trim()!==this.content&&(this.content=this.innerText.trim())}setRange(){var e;if(this.editableField){const t=document.createRange(),i=window.getSelection(),s=this.editableField.childNodes[0];if(!s||s.nodeType!==Node.TEXT_NODE)return;const r=(null===(e=s.nodeValue)||void 0===e?void 0:e.length)||0;t.setStart(s,r),t.collapse(!0),i&&0===i.toString().length&&(i.removeAllRanges(),i.addRange(t)),this.maxLines.length>0&&(this.editableField.scrollTop=this.editableField.scrollHeight)}}handleValidation(){var e;(this.type||this.pattern)&&((null===(e=this.checkValidity)||void 0===e?void 0:e.call(this,this.content))||(this.reportValidity(),this.showAlert()))}showAlert(){this.alert=!0}static get styles(){return[a.A,h.A]}get overflowStyles(){return this.maxLines.length&&this.maxLines.length>0&&`max-height: ${2*parseInt(this.maxLines)}rem; -webkit-line-clamp: ${this.maxLines}; word-break: break-all;`}messagesTemplate(){var e,t,i;return this.alert?l.html`
            <div class="md-editable-textfield__messages" style="display: ${this.hideMessage?"none":"block"}">
              <md-help-text
                id="alert-message"
                role="alert"
                aria-live="assertive"
                .messageType=${null===(e=this.message)||void 0===e?void 0:e.type}
                aria-errormessage=${(0,p.ifDefined)(null===(t=this.message)||void 0===t?void 0:t.message)}
              >
                ${null===(i=this.message)||void 0===i?void 0:i.message}
              </md-help-text>
            </div>
          `:l.nothing}render(){var e;const t={[`md-editable-textfield--${this.alignment}`]:this.alignment,"md-editable-textfield--disabled":this.disabled,[`md-editable-textfield--${null===(e=this.message)||void 0===e?void 0:e.type}`]:this.alert&&!!this.message,"md-editable-textfield--textoverflow":this.maxLines.length>0&&!this.isEditing};return l.html`
        <div
          part="editable-textfield"
          style="${this.overflowStyles}"
          class="md-editable-textfield ${(0,d.classMap)(t)}"
          role=${(0,p.ifDefined)(this.disabled?void 0:"textbox")}
          tabindex=${this.disabled?"-1":"0"}
          ?contenteditable=${this.isEditing}
          @focus=${this.handleFocus}
          @blur=${this.handleBlur}
          @keydown=${e=>{this.handleKeydown(e)}}
          aria-invalid=${(0,p.ifDefined)(this.disabled?void 0:this.alert?"true":"false")}
          aria-label=${(0,p.ifDefined)(this.disabled?void 0:this.ariaLabel)}
          aria-describedby=${(0,p.ifDefined)(this.disabled?void 0:this.ariaDescribedBy)}
          .innerText=${this.content}
        ></div>
        ${this.messagesTemplate()}
      `}};m([(0,n.property)({type:String})],t.prototype,"alignment",void 0),m([(0,n.property)({type:Boolean})],t.prototype,"disabled",void 0),m([(0,n.property)({type:Boolean})],t.prototype,"isEditing",void 0),m([(0,n.property)({type:String,attribute:"max-lines",reflect:!0})],t.prototype,"maxLines",void 0),m([(0,n.property)({type:String,reflect:!0})],t.prototype,"content",void 0),m([(0,n.property)({type:Object})],t.prototype,"message",void 0),m([(0,n.property)({type:Boolean,reflect:!0})],t.prototype,"alert",void 0),m([(0,n.property)({type:Boolean})],t.prototype,"hideMessage",void 0),m([(0,n.property)({type:String})],t.prototype,"pattern",void 0),m([(0,n.property)({type:String})],t.prototype,"type",void 0),m([(0,n.property)({type:String})],t.prototype,"ariaLabel",void 0),m([(0,n.property)({type:String,attribute:"aria-described-by"})],t.prototype,"ariaDescribedBy",void 0),m([(0,n.query)(".md-editable-textfield")],t.prototype,"editableField",void 0),t=m([(0,s.w)("md-editable-field")],t),e.ELEMENT=t}(f||(f={}))}},s={};function r(e){var t=s[e];if(void 0!==t)return t.exports;var a=s[e]={exports:{}};return i[e](a,a.exports,r),a.exports}r.m=i,e=[],r.O=(t,i,s,a)=>{if(!i){var o=1/0;for(p=0;p<e.length;p++){for(var[i,s,a]=e[p],l=!0,n=0;n<i.length;n++)(!1&a||o>=a)&&Object.keys(r.O).every(e=>r.O[e](i[n]))?i.splice(n--,1):(l=!1,a<o&&(o=a));if(l){e.splice(p--,1);var d=s();void 0!==d&&(t=d)}}return t}a=a||0;for(var p=e.length;p>0&&e[p-1][2]>a;p--)e[p]=e[p-1];e[p]=[i,s,a]},r.d=(e,t)=>{for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);export{r as __webpack_require__};t={1807:0},r.C=e=>{var i,s,{__webpack_esm_ids__:a,__webpack_esm_modules__:o,__webpack_esm_runtime__:l}=e,n=0;for(i in o)r.o(o,i)&&(r.m[i]=o[i]);for(l&&l(r);n<a.length;n++)s=a[n],r.o(t,s)&&t[s]&&t[s][0](),t[a[n]]=0;r.O()},r.O.j=e=>0===t[e];import*as a from"../9609.js";r.C(a);import*as o from"../4084.js";r.C(o);import*as l from"../4955.js";r.C(l);import*as n from"../3517.js";r.C(n);import*as d from"../1156.js";r.C(d);import*as p from"../3305.js";r.C(p);import*as h from"../4739.js";r.C(h);import*as m from"../7154.js";r.C(m);import*as c from"../9773.js";r.C(c);import*as f from"../5983.js";r.C(f);import*as v from"../7755.js";r.C(v);import*as y from"../1821.js";r.C(y);import*as g from"../4980.js";r.C(g);import*as b from"../5308.js";r.C(b);import*as u from"../519.js";r.C(u);import*as x from"../4137.js";r.C(x);import*as j from"../2577.js";r.C(j);import*as C from"../8441.js";r.C(C);import*as w from"../2797.js";r.C(w);import*as $ from"../9983.js";r.C($);import*as _ from"../3970.js";r.C(_);import*as E from"../7906.js";r.C(E);import*as T from"../9336.js";r.C(T);import*as k from"../2369.js";r.C(k);import*as O from"../7119.js";r.C(O);import*as L from"../9189.js";r.C(L);import*as S from"../3331.js";r.C(S);import*as D from"../4060.js";r.C(D);var F=r.O(void 0,[9609,4084,4955,3517,1156,3305,4739,7154,9773,5983,7755,1821,4980,5308,519,4137,2577,8441,2797,9983,3970,7906,9336,2369,7119,9189,3331,4060],()=>r(7386));const R=(F=r.O(F)).I,B=F.O;export{R as EditableTextfield,B as alignment};