@preline/textarea-auto-height 2.6.0 → 3.0.0

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.
Files changed (2) hide show
  1. package/index.js +3 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,9 +1,9 @@
1
- !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var o in n)("object"==typeof exports?exports:t)[o]=n[o]}}(self,(()=>(()=>{"use strict";var t={961:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t,e,n){this.el=t,this.options=e,this.events=n,this.el=t,this.options=e,this.events={}}return t.prototype.createCollection=function(t,e){var n;t.push({id:(null===(n=null==e?void 0:e.el)||void 0===n?void 0:n.id)||t.length+1,element:e})},t.prototype.fireEvent=function(t,e){if(void 0===e&&(e=null),this.events.hasOwnProperty(t))return this.events[t](e)},t.prototype.on=function(t,e){this.events[t]=e},t}();e.default=n},144:function(t,e,n){
1
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i=t();for(var n in i)("object"==typeof exports?exports:e)[n]=i[n]}}(self,(()=>(()=>{"use strict";var e={961:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(e,t,i){this.el=e,this.options=t,this.events=i,this.el=e,this.options=t,this.events={}}createCollection(e,t){var i;e.push({id:(null===(i=null==t?void 0:t.el)||void 0===i?void 0:i.id)||e.length+1,element:t})}fireEvent(e,t=null){if(this.events.hasOwnProperty(e))return this.events[e](t)}on(e,t){this.events[e]=t}}},144:function(e,t,i){
2
2
  /*
3
3
  * HSTextareaAutoHeight
4
- * @version: 2.6.0
4
+ * @version: 3.0.0
5
5
  * @author: Preline Labs Ltd.
6
6
  * @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
7
7
  * Copyright 2024 Preline Labs Ltd.
8
8
  */
9
- var o,i=this&&this.__extends||(o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},o(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),r=this&&this.__assign||function(){return r=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},r.apply(this,arguments)},l=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var s=function(t){function e(e,n){var o=t.call(this,e,n)||this,i=e.getAttribute("data-hs-copy-markup"),l=i?JSON.parse(i):{},s=r(r({},l),n);return o.defaultHeight=(null==s?void 0:s.defaultHeight)||0,o.init(),o}return i(e,t),e.prototype.elementInput=function(){this.textareaSetHeight(3)},e.prototype.init=function(){this.createCollection(window.$hsTextareaAutoHeightCollection,this),this.setAutoHeight()},e.prototype.setAutoHeight=function(){var t=this;this.isParentHidden()?this.callbackAccordingToType():this.textareaSetHeight(3),this.onElementInputListener=function(){return t.elementInput()},this.el.addEventListener("input",this.onElementInputListener)},e.prototype.textareaSetHeight=function(t){void 0===t&&(t=0),this.el.style.height="auto",this.el.style.height=this.checkIfOneLine()&&this.defaultHeight?"".concat(this.defaultHeight,"px"):"".concat(this.el.scrollHeight+t,"px")},e.prototype.checkIfOneLine=function(){var t=this.el.clientHeight;return!(this.el.scrollHeight>t)},e.prototype.isParentHidden=function(){return this.el.closest(".hs-collapse")||this.el.closest(".hs-overlay")||this.el.closest('[role="tabpanel"]')},e.prototype.parentType=function(){return this.el.closest(".hs-collapse")?"collapse":this.el.closest(".hs-overlay")?"overlay":!!this.el.closest('[role="tabpanel"]')&&"tabs"},e.prototype.callbackAccordingToType=function(){var t,e=this;if("tabs"===this.parentType()){var n=null===(t=this.el.closest('[role="tabpanel"]'))||void 0===t?void 0:t.id,o=document.querySelector('[data-hs-tab="#'.concat(n,'"]')).closest('[role="tablist"]');(window.HSTabs.getInstance(o,!0)||null).element.on("change",(function(){if(!e.el)return!1;e.textareaSetHeight(3)}))}else if("collapse"===this.parentType()){var i=this.el.closest(".hs-collapse").id;window.HSCollapse.getInstance('[data-hs-collapse="#'.concat(i,'"]'),!0).element.on("beforeOpen",(function(){if(!e.el)return!1;e.textareaSetHeight(3)}))}else{if("overlay"!==this.parentType())return!1;window.HSOverlay.getInstance(this.el.closest(".hs-overlay"),!0).element.on("open",(function(){if(!e.el)return!1;e.textareaSetHeight(3)}))}},e.prototype.destroy=function(){var t=this;this.el.removeEventListener("input",this.onElementInputListener),window.$hsTextareaAutoHeightCollection=window.$hsTextareaAutoHeightCollection.filter((function(e){return e.element.el!==t.el}))},e.getInstance=function(t,e){var n=window.$hsTextareaAutoHeightCollection.find((function(e){return e.element.el===("string"==typeof t?document.querySelector(t):t)}));return n?e?n:n.element:null},e.autoInit=function(){window.$hsTextareaAutoHeightCollection||(window.$hsTextareaAutoHeightCollection=[]),window.$hsTextareaAutoHeightCollection&&(window.$hsTextareaAutoHeightCollection=window.$hsTextareaAutoHeightCollection.filter((function(t){var e=t.element;return document.contains(e.el)}))),document.querySelectorAll("[data-hs-textarea-auto-height]:not(.--prevent-on-load-init)").forEach((function(t){if(!window.$hsTextareaAutoHeightCollection.find((function(e){var n;return(null===(n=null==e?void 0:e.element)||void 0===n?void 0:n.el)===t}))){var n=t.getAttribute("data-hs-textarea-auto-height"),o=n?JSON.parse(n):{};new e(t,o)}}))},e}(l(n(961)).default);window.addEventListener("load",(function(){s.autoInit()})),"undefined"!=typeof window&&(window.HSTextareaAutoHeight=s),e.default=s}},e={};var n=function n(o){var i=e[o];if(void 0!==i)return i.exports;var r=e[o]={exports:{}};return t[o].call(r.exports,r,r.exports,n),r.exports}(144);return n})()));
9
+ var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(i(961));class l extends o.default{constructor(e,t){super(e,t);const i=e.getAttribute("data-hs-copy-markup"),n=i?JSON.parse(i):{},o=Object.assign(Object.assign({},n),t);this.defaultHeight=(null==o?void 0:o.defaultHeight)||0,this.init()}elementInput(){this.textareaSetHeight(3)}init(){this.createCollection(window.$hsTextareaAutoHeightCollection,this),this.setAutoHeight()}setAutoHeight(){this.isParentHidden()?this.callbackAccordingToType():this.textareaSetHeight(3),this.onElementInputListener=()=>this.elementInput(),this.el.addEventListener("input",this.onElementInputListener)}textareaSetHeight(e=0){this.el.style.height="auto",this.el.style.height=this.checkIfOneLine()&&this.defaultHeight?`${this.defaultHeight}px`:`${this.el.scrollHeight+e}px`}checkIfOneLine(){const e=this.el.clientHeight;return!(this.el.scrollHeight>e)}isParentHidden(){return this.el.closest(".hs-overlay.hidden")||this.el.closest('[role="tabpanel"].hidden')||this.el.closest(".hs-collapse.hidden")}parentType(){return this.el.closest(".hs-collapse")?"collapse":this.el.closest(".hs-overlay")?"overlay":!!this.el.closest('[role="tabpanel"]')&&"tabs"}callbackAccordingToType(){var e;if("collapse"===this.parentType()){const e=this.el.closest(".hs-collapse").id,{element:t}=window.HSCollapse.getInstance(`[data-hs-collapse="#${e}"]`,!0);t.on("beforeOpen",(()=>{if(!this.el)return!1;this.textareaSetHeight(3)}))}else if("overlay"===this.parentType()){const e=window.HSOverlay.getInstance(this.el.closest(".hs-overlay"),!0);e.element.on("open",(()=>{window.$hsTextareaAutoHeightCollection.filter((({element:t})=>t.el.closest(".hs-overlay")===e.element.el)).forEach((({element:e})=>e.textareaSetHeight(3)))}))}else{if("tabs"!==this.parentType())return!1;{const t=null===(e=this.el.closest('[role="tabpanel"]'))||void 0===e?void 0:e.id,i=document.querySelector(`[data-hs-tab="#${t}"]`).closest('[role="tablist"]'),{element:n}=window.HSTabs.getInstance(i,!0)||null;n.on("change",(e=>{const t=document.querySelectorAll(`${e.current} [data-hs-textarea-auto-height]`);if(!t.length)return!1;t.forEach((e=>{const t=window.HSTextareaAutoHeight.getInstance(e,!0)||null;t&&t.element.textareaSetHeight(3)}))}))}}}destroy(){this.el.removeEventListener("input",this.onElementInputListener),window.$hsTextareaAutoHeightCollection=window.$hsTextareaAutoHeightCollection.filter((({element:e})=>e.el!==this.el))}static getInstance(e,t){const i=window.$hsTextareaAutoHeightCollection.find((t=>t.element.el===("string"==typeof e?document.querySelector(e):e)));return i?t?i:i.element:null}static autoInit(){window.$hsTextareaAutoHeightCollection||(window.$hsTextareaAutoHeightCollection=[]),window.$hsTextareaAutoHeightCollection&&(window.$hsTextareaAutoHeightCollection=window.$hsTextareaAutoHeightCollection.filter((({element:e})=>document.contains(e.el)))),document.querySelectorAll("[data-hs-textarea-auto-height]:not(.--prevent-on-load-init)").forEach((e=>{if(!window.$hsTextareaAutoHeightCollection.find((t=>{var i;return(null===(i=null==t?void 0:t.element)||void 0===i?void 0:i.el)===e}))){const t=e.getAttribute("data-hs-textarea-auto-height"),i=t?JSON.parse(t):{};new l(e,i)}}))}}window.addEventListener("load",(()=>{l.autoInit()})),"undefined"!=typeof window&&(window.HSTextareaAutoHeight=l),t.default=l}},t={};var i=function i(n){var o=t[n];if(void 0!==o)return o.exports;var l=t[n]={exports:{}};return e[n].call(l.exports,l,l.exports,i),l.exports}(144);return i})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preline/textarea-auto-height",
3
- "version": "2.6.0",
3
+ "version": "3.0.0",
4
4
  "description": "Preline UI is an open-source set of prebuilt UI components based on the utility-first Tailwind CSS framework.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",