uni-textarea-field 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -299,7 +299,8 @@ export class UniTextareaField extends HTMLElement {
299
299
 
300
300
  // data
301
301
  this.#data = {
302
- controller: ''
302
+ controller: '',
303
+ elementController: ''
303
304
  };
304
305
 
305
306
  // nodes
@@ -309,6 +310,7 @@ export class UniTextareaField extends HTMLElement {
309
310
  subject: this.shadowRoot.querySelector('.main__subject__span'),
310
311
  message: this.shadowRoot.querySelector('.main__info__message'),
311
312
  counter: this.shadowRoot.querySelector('.main__info__counter'),
313
+ slot: this.shadowRoot.querySelector('slot[name=textarea]'),
312
314
  };
313
315
 
314
316
  // config
@@ -320,11 +322,12 @@ export class UniTextareaField extends HTMLElement {
320
322
  // evts
321
323
  this._onInput = this._onInput.bind(this);
322
324
  this._onKeydown = this._onKeydown.bind(this);
325
+ this._onSlotchange = this._onSlotchange.bind(this);
323
326
  }
324
327
 
325
328
  async connectedCallback() {
326
329
  const { config, error } = await _wcl.getWCConfig(this);
327
- const { textarea } = this.#nodes;
330
+ const { slot } = this.#nodes;
328
331
 
329
332
  if (error) {
330
333
  console.warn(`${_wcl.classToTagName(this.constructor.name)}: ${error}`);
@@ -343,17 +346,14 @@ export class UniTextareaField extends HTMLElement {
343
346
  // evts
344
347
  this.#data.controller = new AbortController();
345
348
  const signal = this.#data.controller.signal;
346
- textarea.addEventListener('input', this._onInput, { signal });
347
- textarea.addEventListener('keydown', this._onKeydown, { signal });
348
-
349
- // init
350
- this._onInput();
349
+ slot.addEventListener('slotchange', this._onSlotchange, { signal });
350
+
351
+ this.#setupEventListeners();
351
352
  }
352
353
 
353
354
  disconnectedCallback() {
354
- if (this.#data?.controller) {
355
- this.#data.controller.abort();
356
- }
355
+ this.#data.controller.abort?.();
356
+ this.#data.elementController.abort?.();
357
357
  }
358
358
 
359
359
  #format(attrName, oldValue, newValue) {
@@ -444,6 +444,24 @@ export class UniTextareaField extends HTMLElement {
444
444
  }
445
445
  }
446
446
 
447
+ #setupEventListeners() {
448
+ if (this.#data.elementController) {
449
+ this.#data.elementController.abort();
450
+ }
451
+
452
+ this.#nodes.textarea = this.querySelector('[slot=textarea]');
453
+
454
+ if (this.#nodes.textarea) {
455
+ this.#data.elementController = new AbortController();
456
+ const signal = this.#data.elementController.signal;
457
+
458
+ this.#nodes.textarea.addEventListener('input', this._onInput, { signal });
459
+ this.#nodes.textarea.addEventListener('keydown', this._onKeydown, { signal });
460
+
461
+ this._onInput();
462
+ }
463
+ }
464
+
447
465
  set subject(value) {
448
466
  if (value) {
449
467
  this.setAttribute('subject', value);
@@ -523,6 +541,10 @@ export class UniTextareaField extends HTMLElement {
523
541
  }
524
542
  }
525
543
 
544
+ _onSlotchange() {
545
+ this.#setupEventListeners();
546
+ }
547
+
526
548
  refresh() {
527
549
  this.hidden = true;
528
550
  this.offsetHeight;
@@ -264,4 +264,4 @@ ${_uniColorPalette}
264
264
  <p class="main__info__counter" data-maxlength="?">0</p>
265
265
  </div>
266
266
  </div>
267
- `;class UniTextareaField extends HTMLElement{#data;#nodes;#config;constructor(e){super(),this.attachShadow({mode:"open",delegatesFocus:!0}),this.shadowRoot.appendChild(template.content.cloneNode(!0)),this.#data={controller:""},this.#nodes={styleSheet:this.shadowRoot.querySelector("style"),textarea:this.querySelector("[slot=textarea]"),subject:this.shadowRoot.querySelector(".main__subject__span"),message:this.shadowRoot.querySelector(".main__info__message"),counter:this.shadowRoot.querySelector(".main__info__counter")},this.#config={...defaults,...e},this._onInput=this._onInput.bind(this),this._onKeydown=this._onKeydown.bind(this)}async connectedCallback(){var{config:e,error:t}=await _wcl.getWCConfig(this),a=this.#nodes["textarea"];t?(console.warn(_wcl.classToTagName(this.constructor.name)+": "+t),this.remove()):(this.#config={...this.#config,...e},Object.keys(defaults).forEach(e=>this.#upgradeProperty(e)),this.#data.controller=new AbortController,t=this.#data.controller.signal,a.addEventListener("input",this._onInput,{signal:t}),a.addEventListener("keydown",this._onKeydown,{signal:t}),this._onInput())}disconnectedCallback(){this.#data?.controller&&this.#data.controller.abort()}#format(e,t,a){if(null!==a)switch(e){case"subject":case"message":this.#config[e]=a;break;case"stat":this.#config[e]=["","valid","invalid"].includes(a)?a:defaults.state;break;case"appearance":this.#config[e]=["filled","outlined"].includes(a)?a:defaults.appearance;break;case"size":this.#config[e]=["large","medium","small"].includes(a)?a:defaults.size}else booleanAttrs.includes(e)?this.#config[e]=!1:this.#config[e]=defaults[e]}attributeChangedCallback(e,t,a){if(UniTextareaField.observedAttributes.includes(e))switch(this.#format(e,t,a),e){case"subject":this.#nodes.subject.textContent=this.subject;break;case"message":this.#nodes.message.textContent=this.message}}static get observedAttributes(){return Object.keys(defaults)}static get supportedEvents(){return Object.keys(custumEvents).map(e=>custumEvents[e])}#upgradeProperty(e){let t;UniTextareaField.observedAttributes.includes(e)&&(Object.prototype.hasOwnProperty.call(this,e)?(t=this[e],delete this[e]):t=booleanAttrs.includes(e)?!(!this.hasAttribute(e)&&!this.#config[e]):objectAttrs.includes(e)?this.hasAttribute(e)?this.getAttribute(e):JSON.stringify(this.#config[e]):this.hasAttribute(e)?this.getAttribute(e):this.#config[e],this[e]=t)}set subject(e){e?this.setAttribute("subject",e):this.removeAttribute("subject")}get subject(){return this.#config.subject}set message(e){e?this.setAttribute("message",e):this.removeAttribute("message")}get message(){return this.#config.message}set stat(e){e?this.setAttribute("stat",e):this.removeAttribute("stat")}get stat(){return this.#config.stat}set appearance(e){e?this.setAttribute("appearance",e):this.removeAttribute("appearance")}get appearance(){return this.#config.appearance}set size(e){e?this.setAttribute("size",e):this.removeAttribute("size")}get size(){return this.#config.size}_onInput(e){var{textarea:t,counter:a}=this.#nodes;a.dataset.maxlength=t.maxLength,a.textContent=t.value.length,e&&"invalid"===this.stat&&(this.stat="")}_onKeydown(e){var{key:e,isComposing:t}=e;"Enter"===e&&t&&event.preventDefault()}refresh(){this.hidden=!0,this.offsetHeight,this.hidden=!1}}const S=_wcl.supports(),T=_wcl.classToTagName("UniTextareaField");S.customElements&&S.shadowDOM&&S.template&&!window.customElements.get(T)&&window.customElements.define(_wcl.classToTagName("UniTextareaField"),UniTextareaField);export{UniTextareaField};
267
+ `;class UniTextareaField extends HTMLElement{#data;#nodes;#config;constructor(e){super(),this.attachShadow({mode:"open",delegatesFocus:!0}),this.shadowRoot.appendChild(template.content.cloneNode(!0)),this.#data={controller:"",elementController:""},this.#nodes={styleSheet:this.shadowRoot.querySelector("style"),textarea:this.querySelector("[slot=textarea]"),subject:this.shadowRoot.querySelector(".main__subject__span"),message:this.shadowRoot.querySelector(".main__info__message"),counter:this.shadowRoot.querySelector(".main__info__counter"),slot:this.shadowRoot.querySelector("slot[name=textarea]")},this.#config={...defaults,...e},this._onInput=this._onInput.bind(this),this._onKeydown=this._onKeydown.bind(this),this._onSlotchange=this._onSlotchange.bind(this)}async connectedCallback(){var{config:e,error:t}=await _wcl.getWCConfig(this),a=this.#nodes["slot"];t?(console.warn(_wcl.classToTagName(this.constructor.name)+": "+t),this.remove()):(this.#config={...this.#config,...e},Object.keys(defaults).forEach(e=>this.#upgradeProperty(e)),this.#data.controller=new AbortController,t=this.#data.controller.signal,a.addEventListener("slotchange",this._onSlotchange,{signal:t}),this.#setupEventListeners())}disconnectedCallback(){this.#data.controller.abort?.(),this.#data.elementController.abort?.()}#format(e,t,a){if(null!==a)switch(e){case"subject":case"message":this.#config[e]=a;break;case"stat":this.#config[e]=["","valid","invalid"].includes(a)?a:defaults.state;break;case"appearance":this.#config[e]=["filled","outlined"].includes(a)?a:defaults.appearance;break;case"size":this.#config[e]=["large","medium","small"].includes(a)?a:defaults.size}else booleanAttrs.includes(e)?this.#config[e]=!1:this.#config[e]=defaults[e]}attributeChangedCallback(e,t,a){if(UniTextareaField.observedAttributes.includes(e))switch(this.#format(e,t,a),e){case"subject":this.#nodes.subject.textContent=this.subject;break;case"message":this.#nodes.message.textContent=this.message}}static get observedAttributes(){return Object.keys(defaults)}static get supportedEvents(){return Object.keys(custumEvents).map(e=>custumEvents[e])}#upgradeProperty(e){let t;UniTextareaField.observedAttributes.includes(e)&&(Object.prototype.hasOwnProperty.call(this,e)?(t=this[e],delete this[e]):t=booleanAttrs.includes(e)?!(!this.hasAttribute(e)&&!this.#config[e]):objectAttrs.includes(e)?this.hasAttribute(e)?this.getAttribute(e):JSON.stringify(this.#config[e]):this.hasAttribute(e)?this.getAttribute(e):this.#config[e],this[e]=t)}#setupEventListeners(){var e;this.#data.elementController&&this.#data.elementController.abort(),this.#nodes.textarea=this.querySelector("[slot=textarea]"),this.#nodes.textarea&&(this.#data.elementController=new AbortController,e=this.#data.elementController.signal,this.#nodes.textarea.addEventListener("input",this._onInput,{signal:e}),this.#nodes.textarea.addEventListener("keydown",this._onKeydown,{signal:e}),this._onInput())}set subject(e){e?this.setAttribute("subject",e):this.removeAttribute("subject")}get subject(){return this.#config.subject}set message(e){e?this.setAttribute("message",e):this.removeAttribute("message")}get message(){return this.#config.message}set stat(e){e?this.setAttribute("stat",e):this.removeAttribute("stat")}get stat(){return this.#config.stat}set appearance(e){e?this.setAttribute("appearance",e):this.removeAttribute("appearance")}get appearance(){return this.#config.appearance}set size(e){e?this.setAttribute("size",e):this.removeAttribute("size")}get size(){return this.#config.size}_onInput(e){var{textarea:t,counter:a}=this.#nodes;a.dataset.maxlength=t.maxLength,a.textContent=t.value.length,e&&"invalid"===this.stat&&(this.stat="")}_onKeydown(e){var{key:e,isComposing:t}=e;"Enter"===e&&t&&event.preventDefault()}_onSlotchange(){this.#setupEventListeners()}refresh(){this.hidden=!0,this.offsetHeight,this.hidden=!1}}const S=_wcl.supports(),T=_wcl.classToTagName("UniTextareaField");S.customElements&&S.shadowDOM&&S.template&&!window.customElements.get(T)&&window.customElements.define(_wcl.classToTagName("UniTextareaField"),UniTextareaField);export{UniTextareaField};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uni-textarea-field",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "<uni-textarea-field /> is an encapsulated Web Component built upon the foundation of the uniopen design language. Implementation is straightforward: simply slot a standard textarea element inside <uni-textarea-field />. The component instantly applies a user interface that aligns seamlessly with the uniopen design language guidelines. Furthermore, its visual styles can be dynamically adapted via native HTML attributes or JavaScript properties. The component also exposes comprehensive character count and textarea length metadata, providing users with a clear and intuitive understanding of predefined character constraints.",
5
5
  "keywords": [
6
6
  "web"