@preline/textarea-auto-height 4.0.0 → 4.1.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.
- package/index.d.ts +8 -12
- package/index.js +11 -3
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export interface ITextareaAutoHeightOptions {
|
|
2
|
+
defaultHeight: number;
|
|
3
|
+
}
|
|
4
|
+
export interface ITextareaAutoHeight {
|
|
5
|
+
options?: ITextareaAutoHeightOptions;
|
|
6
|
+
destroy(): void;
|
|
7
|
+
}
|
|
1
8
|
export interface IBasePlugin<O, E> {
|
|
2
9
|
el: E;
|
|
3
10
|
options?: O;
|
|
@@ -12,17 +19,6 @@ declare class HSBasePlugin<O, E = HTMLElement> implements IBasePlugin<O, E> {
|
|
|
12
19
|
fireEvent(evt: string, payload?: any): any;
|
|
13
20
|
on(evt: string, cb: Function): void;
|
|
14
21
|
}
|
|
15
|
-
export interface ICollectionItem<T> {
|
|
16
|
-
id: string | number;
|
|
17
|
-
element: T;
|
|
18
|
-
}
|
|
19
|
-
export interface ITextareaAutoHeightOptions {
|
|
20
|
-
defaultHeight: number;
|
|
21
|
-
}
|
|
22
|
-
export interface ITextareaAutoHeight {
|
|
23
|
-
options?: ITextareaAutoHeightOptions;
|
|
24
|
-
destroy(): void;
|
|
25
|
-
}
|
|
26
22
|
declare class HSTextareaAutoHeight extends HSBasePlugin<ITextareaAutoHeightOptions> implements ITextareaAutoHeight {
|
|
27
23
|
private readonly defaultHeight;
|
|
28
24
|
private onElementInputListener;
|
|
@@ -36,7 +32,7 @@ declare class HSTextareaAutoHeight extends HSBasePlugin<ITextareaAutoHeightOptio
|
|
|
36
32
|
private parentType;
|
|
37
33
|
private callbackAccordingToType;
|
|
38
34
|
destroy(): void;
|
|
39
|
-
static getInstance(target: HTMLTextAreaElement | string, isInstance?: boolean):
|
|
35
|
+
static getInstance(target: HTMLTextAreaElement | string, isInstance?: boolean): any;
|
|
40
36
|
static autoInit(): void;
|
|
41
37
|
}
|
|
42
38
|
|
package/index.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
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={
|
|
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={2961:(e,t)=>{
|
|
2
|
+
/*
|
|
3
|
+
* HSBasePlugin
|
|
4
|
+
* @version: 4.1.0
|
|
5
|
+
* @author: Preline Labs Ltd.
|
|
6
|
+
* @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
|
|
7
|
+
* Copyright 2024 Preline Labs Ltd.
|
|
8
|
+
*/
|
|
9
|
+
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}}},6473:function(e,t,i){
|
|
2
10
|
/*
|
|
3
11
|
* HSTextareaAutoHeight
|
|
4
|
-
* @version: 4.
|
|
12
|
+
* @version: 4.1.0
|
|
5
13
|
* @author: Preline Labs Ltd.
|
|
6
14
|
* @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
|
|
7
15
|
* Copyright 2024 Preline Labs Ltd.
|
|
8
16
|
*/
|
|
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(
|
|
17
|
+
var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(i(2961));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)}}))}}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}(6473);return i})()));
|
package/package.json
CHANGED