@flexilla/dismissible 2.0.1 → 2.0.3
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/README.md +8 -2
- package/dist/dismissible.js +60 -43
- package/dist/dismissible.umd.cjs +1 -1
- package/dist/index.d.ts +9 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -27,7 +27,13 @@ import Dismissible from '@flexilla/dismissible';
|
|
|
27
27
|
action: "remove-from-dom",
|
|
28
28
|
onDismiss: () => {
|
|
29
29
|
console.log("Element dismissed!");
|
|
30
|
-
}
|
|
31
|
-
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// or
|
|
33
|
+
fDismissible('.dismissable-element',
|
|
34
|
+
action: "remove-from-dom",
|
|
35
|
+
onDismiss: () => {
|
|
36
|
+
console.log("Element dismissed!");
|
|
37
|
+
})
|
|
32
38
|
</script>
|
|
33
39
|
```
|
package/dist/dismissible.js
CHANGED
|
@@ -1,74 +1,91 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
const
|
|
5
|
-
element:
|
|
6
|
-
callback:
|
|
1
|
+
var b = Object.defineProperty;
|
|
2
|
+
var u = (t, e, s) => e in t ? b(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
|
|
3
|
+
var i = (t, e, s) => u(t, typeof e != "symbol" ? e + "" : e, s);
|
|
4
|
+
const E = (t, e = document.body) => e.querySelector(t), r = (t, e = document.body) => Array.from(e.querySelectorAll(t)), f = ({
|
|
5
|
+
element: t,
|
|
6
|
+
callback: e,
|
|
7
|
+
type: s,
|
|
8
|
+
keysCheck: n
|
|
7
9
|
}) => {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
"transitionend",
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
10
|
+
const l = getComputedStyle(t), o = s === "transition" ? l.transition : l.animation;
|
|
11
|
+
if (o !== "none" && o !== "" && !n.includes(o)) {
|
|
12
|
+
const d = s === "transition" ? "transitionend" : "animationend", a = () => {
|
|
13
|
+
t.removeEventListener(d, a), e();
|
|
14
|
+
};
|
|
15
|
+
t.addEventListener(d, a, { once: !0 });
|
|
16
|
+
} else
|
|
17
|
+
e();
|
|
18
|
+
}, c = ({
|
|
19
|
+
element: t,
|
|
20
|
+
callback: e
|
|
21
|
+
}) => {
|
|
22
|
+
f({
|
|
23
|
+
element: t,
|
|
24
|
+
callback: e,
|
|
25
|
+
type: "transition",
|
|
26
|
+
keysCheck: ["all 0s ease 0s", "all"]
|
|
27
|
+
});
|
|
28
|
+
}, m = class m {
|
|
17
29
|
/**
|
|
18
30
|
* Dismissible Component
|
|
19
31
|
* @param dismissible
|
|
20
32
|
* @param action
|
|
21
33
|
* @param onDissmiss
|
|
22
34
|
*/
|
|
23
|
-
constructor(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var
|
|
30
|
-
this.dismissibleElement.style.display = "none", (
|
|
35
|
+
constructor(e, s, n) {
|
|
36
|
+
i(this, "dismissibleElement");
|
|
37
|
+
i(this, "dismissButtons");
|
|
38
|
+
i(this, "action");
|
|
39
|
+
i(this, "onDismiss");
|
|
40
|
+
i(this, "hideFromScreen", () => {
|
|
41
|
+
var e;
|
|
42
|
+
this.dismissibleElement.style.display = "none", (e = this.onDismiss) == null || e.call(this);
|
|
31
43
|
});
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
(
|
|
44
|
+
i(this, "removeFromDom", () => {
|
|
45
|
+
var e, s;
|
|
46
|
+
(e = this.onDismiss) == null || e.call(this), (s = this.dismissibleElement.parentElement) == null || s.removeChild(this.dismissibleElement);
|
|
35
47
|
});
|
|
36
|
-
|
|
48
|
+
i(this, "dismiss", () => {
|
|
37
49
|
switch (this.action) {
|
|
38
50
|
case "hide-from-screen":
|
|
39
|
-
this.dismissibleElement.setAttribute("aria-hidden", "true"),
|
|
51
|
+
this.dismissibleElement.setAttribute("aria-hidden", "true"), this.dismissibleElement.setAttribute("data-state", "hidden"), c({
|
|
40
52
|
element: this.dismissibleElement,
|
|
41
53
|
callback: this.hideFromScreen
|
|
42
54
|
});
|
|
43
55
|
break;
|
|
44
56
|
default:
|
|
45
|
-
this.dismissibleElement.setAttribute("data-hidden", ""), this.dismissibleElement.setAttribute("aria-hidden", "true"),
|
|
57
|
+
this.dismissibleElement.setAttribute("data-hidden", ""), this.dismissibleElement.setAttribute("aria-hidden", "true"), this.dismissibleElement.setAttribute("data-state", "removed"), c({
|
|
46
58
|
element: this.dismissibleElement,
|
|
47
59
|
callback: this.removeFromDom
|
|
48
60
|
});
|
|
49
61
|
break;
|
|
50
62
|
}
|
|
51
63
|
});
|
|
52
|
-
const
|
|
53
|
-
if (!(
|
|
54
|
-
|
|
55
|
-
this.dismissibleElement = m, this.action = e || this.dismissibleElement.dataset.action || "hide-from-screen", this.dismissButtons = d("[data-dismiss-btn]", this.dismissibleElement), this.onDismiss = n, this.dismissibleElement.setAttribute("aria-hidden", "false"), this.init();
|
|
64
|
+
const l = typeof e == "string" ? E(e, document.body) : e;
|
|
65
|
+
if (!(l instanceof HTMLElement)) throw new Error("Provided Element not a valid HTMLElement");
|
|
66
|
+
this.dismissibleElement = l, this.action = s || this.dismissibleElement.dataset.action || "hide-from-screen", this.dismissButtons = r("[data-dismiss-btn]", this.dismissibleElement), this.onDismiss = n, this.dismissibleElement.setAttribute("aria-hidden", "false"), this.setupDismissible();
|
|
56
67
|
}
|
|
57
|
-
|
|
58
|
-
for (const
|
|
59
|
-
|
|
68
|
+
setupDismissible() {
|
|
69
|
+
for (const e of this.dismissButtons)
|
|
70
|
+
e.addEventListener("click", this.dismiss);
|
|
60
71
|
}
|
|
61
72
|
};
|
|
62
73
|
/**
|
|
63
74
|
* auto init Dismissible Element based on the selector provided
|
|
64
75
|
* @param selector {string} default is [data-fx-dismissible]
|
|
65
76
|
*/
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
for (const n of
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
i(m, "autoInit", (e = "[data-fx-dismissible]") => {
|
|
78
|
+
const s = r(e);
|
|
79
|
+
for (const n of s) new m(n);
|
|
80
|
+
}), /**
|
|
81
|
+
*
|
|
82
|
+
* @param dismissible
|
|
83
|
+
* @param action
|
|
84
|
+
* @param onDissmiss
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
i(m, "init", (e, s, n) => new m(e, s, n));
|
|
88
|
+
let h = m;
|
|
72
89
|
export {
|
|
73
|
-
|
|
90
|
+
h as Dismissible
|
|
74
91
|
};
|
package/dist/dismissible.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s
|
|
1
|
+
(function(i,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(i=typeof globalThis<"u"?globalThis:i||self,s(i["@flexilla/dismissible"]={}))})(this,function(i){"use strict";var E=Object.defineProperty;var y=(i,s,o)=>s in i?E(i,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[s]=o;var n=(i,s,o)=>y(i,typeof s!="symbol"?s+"":s,o);const s=(l,e=document.body)=>e.querySelector(l),o=(l,e=document.body)=>Array.from(e.querySelectorAll(l)),f=({element:l,callback:e,type:t,keysCheck:d})=>{const a=getComputedStyle(l),c=t==="transition"?a.transition:a.animation;if(c!=="none"&&c!==""&&!d.includes(c)){const b=t==="transition"?"transitionend":"animationend",u=()=>{l.removeEventListener(b,u),e()};l.addEventListener(b,u,{once:!0})}else e()},h=({element:l,callback:e})=>{f({element:l,callback:e,type:"transition",keysCheck:["all 0s ease 0s","all"]})},m=class m{constructor(e,t,d){n(this,"dismissibleElement");n(this,"dismissButtons");n(this,"action");n(this,"onDismiss");n(this,"hideFromScreen",()=>{var e;this.dismissibleElement.style.display="none",(e=this.onDismiss)==null||e.call(this)});n(this,"removeFromDom",()=>{var e,t;(e=this.onDismiss)==null||e.call(this),(t=this.dismissibleElement.parentElement)==null||t.removeChild(this.dismissibleElement)});n(this,"dismiss",()=>{switch(this.action){case"hide-from-screen":this.dismissibleElement.setAttribute("aria-hidden","true"),this.dismissibleElement.setAttribute("data-state","hidden"),h({element:this.dismissibleElement,callback:this.hideFromScreen});break;default:this.dismissibleElement.setAttribute("data-hidden",""),this.dismissibleElement.setAttribute("aria-hidden","true"),this.dismissibleElement.setAttribute("data-state","removed"),h({element:this.dismissibleElement,callback:this.removeFromDom});break}});const a=typeof e=="string"?s(e,document.body):e;if(!(a instanceof HTMLElement))throw new Error("Provided Element not a valid HTMLElement");this.dismissibleElement=a,this.action=t||this.dismissibleElement.dataset.action||"hide-from-screen",this.dismissButtons=o("[data-dismiss-btn]",this.dismissibleElement),this.onDismiss=d,this.dismissibleElement.setAttribute("aria-hidden","false"),this.setupDismissible()}setupDismissible(){for(const e of this.dismissButtons)e.addEventListener("click",this.dismiss)}};n(m,"autoInit",(e="[data-fx-dismissible]")=>{const t=o(e);for(const d of t)new m(d)}),n(m,"init",(e,t,d)=>new m(e,t,d));let r=m;i.Dismissible=r,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.d.ts
CHANGED
|
@@ -13,12 +13,20 @@ export declare class Dismissible {
|
|
|
13
13
|
private hideFromScreen;
|
|
14
14
|
private removeFromDom;
|
|
15
15
|
dismiss: () => void;
|
|
16
|
-
private
|
|
16
|
+
private setupDismissible;
|
|
17
17
|
/**
|
|
18
18
|
* auto init Dismissible Element based on the selector provided
|
|
19
19
|
* @param selector {string} default is [data-fx-dismissible]
|
|
20
20
|
*/
|
|
21
21
|
static autoInit: (selector?: string) => void;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param dismissible
|
|
25
|
+
* @param action
|
|
26
|
+
* @param onDissmiss
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
static init: (dismissible: string | HTMLElement, action?: "remove-from-dom" | "hide-from-screen", onDissmiss?: () => void) => Dismissible;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
export { }
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flexilla/dismissible",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A lightweight JavaScript component that automatically makes a component dismissible for easy user interaction.",
|
|
7
7
|
"publishConfig": {
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
},
|
|
65
65
|
"license": "MIT",
|
|
66
66
|
"author": "johnkat-mj",
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "2eb26c556c72eb0c607dfc2de61b3ca6ef3128c9"
|
|
68
68
|
}
|