@flexilla/dismissible 2.0.15 → 2.0.16
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/dist/index.cjs +1 -0
- package/dist/index.d.cts +43 -0
- package/dist/index.d.ts +43 -42
- package/dist/index.js +1 -0
- package/package.json +18 -26
- package/dist/dismissible.js +0 -163
- package/dist/dismissible.umd.cjs +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@flexilla/utilities`),t=require(`@flexilla/manager`);var n=class n{dismissibleElement;dismissButtons;restoreButtons;action;onDismiss;onRestore;parentElement;previousSibling;originalDisplay;constructor(n,r,i,a){let o=typeof n==`string`?(0,e.$)(n,document.body):n;if(!(o instanceof HTMLElement))throw Error(`Provided Element not a valid HTMLElement`);this.dismissibleElement=o,this.action=r||this.dismissibleElement.dataset.action||`hide-from-screen`,this.dismissButtons=(0,e.$$)(`[data-dismiss-btn]`,this.dismissibleElement),this.restoreButtons=(0,e.$$)(`[data-restore-btn]`,document.body),this.onDismiss=i,this.onRestore=a,this.parentElement=this.dismissibleElement.parentElement,this.previousSibling=this.dismissibleElement.previousSibling,this.originalDisplay=this.dismissibleElement.style.display||getComputedStyle(this.dismissibleElement).display,this.dismissibleElement.setAttribute(`aria-hidden`,`false`);let s=t.FlexillaManager.getInstance(`dismissible`,this.dismissibleElement);if(s)return s;this.setupDismissible(),t.FlexillaManager.register(`dismissible`,this.dismissibleElement,this)}hideFromScreen=()=>{this.dismissibleElement.style.display=`none`,this.onDismiss?.()};removeFromDom=()=>{this.onDismiss?.(),this.dismissibleElement.parentElement?.removeChild(this.dismissibleElement)};showOnScreen=()=>{this.dismissibleElement.style.display=this.originalDisplay,this.dismissibleElement.setAttribute(`aria-hidden`,`false`),this.dismissibleElement.setAttribute(`data-state`,`visible`),this.onRestore?.()};restoreToDom=()=>{this.parentElement&&(this.previousSibling&&this.previousSibling.nextSibling?this.parentElement.insertBefore(this.dismissibleElement,this.previousSibling.nextSibling):this.parentElement.appendChild(this.dismissibleElement),this.dismissibleElement.setAttribute(`aria-hidden`,`false`),this.dismissibleElement.removeAttribute(`data-hidden`),this.dismissibleElement.setAttribute(`data-state`,`visible`),this.onRestore?.())};dismiss=()=>{switch(this.action){case`hide-from-screen`:this.dismissibleElement.setAttribute(`aria-hidden`,`true`),this.dismissibleElement.setAttribute(`data-state`,`hidden`),(0,e.afterTransition)({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`),(0,e.afterTransition)({element:this.dismissibleElement,callback:this.removeFromDom});break}};restore=()=>{switch(this.action){case`hide-from-screen`:(0,e.afterTransition)({element:this.dismissibleElement,callback:this.showOnScreen});break;default:(0,e.afterTransition)({element:this.dismissibleElement,callback:this.restoreToDom});break}};setupDismissible(){for(let e of this.dismissButtons)e.addEventListener(`click`,this.dismiss);for(let e of this.restoreButtons)e.addEventListener(`click`,this.restore)}cleanup(){for(let e of this.dismissButtons)e.removeEventListener(`click`,this.dismiss);for(let e of this.restoreButtons)e.removeEventListener(`click`,this.restore);t.FlexillaManager.removeInstance(`dismissible`,this.dismissibleElement)}static autoInit=(t=`[data-fx-dismissible]`)=>{let r=(0,e.$$)(t);for(let e of r)new n(e)};static init=(e,t,r,i)=>new n(e,t,r,i)};exports.Dismissible=n;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region src/dismissible.d.ts
|
|
2
|
+
declare class Dismissible {
|
|
3
|
+
private dismissibleElement;
|
|
4
|
+
private dismissButtons;
|
|
5
|
+
private restoreButtons;
|
|
6
|
+
private action;
|
|
7
|
+
private onDismiss;
|
|
8
|
+
private onRestore;
|
|
9
|
+
private parentElement;
|
|
10
|
+
private previousSibling;
|
|
11
|
+
private originalDisplay;
|
|
12
|
+
/**
|
|
13
|
+
* Dismissible Component
|
|
14
|
+
* @param dismissible
|
|
15
|
+
* @param action
|
|
16
|
+
* @param onDismiss
|
|
17
|
+
* @param onRestore
|
|
18
|
+
*/
|
|
19
|
+
constructor(dismissible: string | HTMLElement, action?: "remove-from-dom" | "hide-from-screen", onDismiss?: () => void, onRestore?: () => void);
|
|
20
|
+
private hideFromScreen;
|
|
21
|
+
private removeFromDom;
|
|
22
|
+
private showOnScreen;
|
|
23
|
+
private restoreToDom;
|
|
24
|
+
dismiss: () => void;
|
|
25
|
+
restore: () => void;
|
|
26
|
+
private setupDismissible;
|
|
27
|
+
/**
|
|
28
|
+
* Cleanup method to remove event listeners
|
|
29
|
+
*/
|
|
30
|
+
cleanup(): void;
|
|
31
|
+
static autoInit: (selector?: string) => void;
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param dismissible
|
|
35
|
+
* @param action
|
|
36
|
+
* @param onDismiss
|
|
37
|
+
* @param onRestore
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
static init: (dismissible: string | HTMLElement, action?: "remove-from-dom" | "hide-from-screen", onDismiss?: () => void, onRestore?: () => void) => Dismissible;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { Dismissible };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,42 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
1
|
+
//#region src/dismissible.d.ts
|
|
2
|
+
declare class Dismissible {
|
|
3
|
+
private dismissibleElement;
|
|
4
|
+
private dismissButtons;
|
|
5
|
+
private restoreButtons;
|
|
6
|
+
private action;
|
|
7
|
+
private onDismiss;
|
|
8
|
+
private onRestore;
|
|
9
|
+
private parentElement;
|
|
10
|
+
private previousSibling;
|
|
11
|
+
private originalDisplay;
|
|
12
|
+
/**
|
|
13
|
+
* Dismissible Component
|
|
14
|
+
* @param dismissible
|
|
15
|
+
* @param action
|
|
16
|
+
* @param onDismiss
|
|
17
|
+
* @param onRestore
|
|
18
|
+
*/
|
|
19
|
+
constructor(dismissible: string | HTMLElement, action?: "remove-from-dom" | "hide-from-screen", onDismiss?: () => void, onRestore?: () => void);
|
|
20
|
+
private hideFromScreen;
|
|
21
|
+
private removeFromDom;
|
|
22
|
+
private showOnScreen;
|
|
23
|
+
private restoreToDom;
|
|
24
|
+
dismiss: () => void;
|
|
25
|
+
restore: () => void;
|
|
26
|
+
private setupDismissible;
|
|
27
|
+
/**
|
|
28
|
+
* Cleanup method to remove event listeners
|
|
29
|
+
*/
|
|
30
|
+
cleanup(): void;
|
|
31
|
+
static autoInit: (selector?: string) => void;
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param dismissible
|
|
35
|
+
* @param action
|
|
36
|
+
* @param onDismiss
|
|
37
|
+
* @param onRestore
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
static init: (dismissible: string | HTMLElement, action?: "remove-from-dom" | "hide-from-screen", onDismiss?: () => void, onRestore?: () => void) => Dismissible;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { Dismissible };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$ as e,$$ as t,afterTransition as n}from"@flexilla/utilities";import{FlexillaManager as r}from"@flexilla/manager";var i=class i{dismissibleElement;dismissButtons;restoreButtons;action;onDismiss;onRestore;parentElement;previousSibling;originalDisplay;constructor(n,i,a,o){let s=typeof n==`string`?e(n,document.body):n;if(!(s instanceof HTMLElement))throw Error(`Provided Element not a valid HTMLElement`);this.dismissibleElement=s,this.action=i||this.dismissibleElement.dataset.action||`hide-from-screen`,this.dismissButtons=t(`[data-dismiss-btn]`,this.dismissibleElement),this.restoreButtons=t(`[data-restore-btn]`,document.body),this.onDismiss=a,this.onRestore=o,this.parentElement=this.dismissibleElement.parentElement,this.previousSibling=this.dismissibleElement.previousSibling,this.originalDisplay=this.dismissibleElement.style.display||getComputedStyle(this.dismissibleElement).display,this.dismissibleElement.setAttribute(`aria-hidden`,`false`);let c=r.getInstance(`dismissible`,this.dismissibleElement);if(c)return c;this.setupDismissible(),r.register(`dismissible`,this.dismissibleElement,this)}hideFromScreen=()=>{this.dismissibleElement.style.display=`none`,this.onDismiss?.()};removeFromDom=()=>{this.onDismiss?.(),this.dismissibleElement.parentElement?.removeChild(this.dismissibleElement)};showOnScreen=()=>{this.dismissibleElement.style.display=this.originalDisplay,this.dismissibleElement.setAttribute(`aria-hidden`,`false`),this.dismissibleElement.setAttribute(`data-state`,`visible`),this.onRestore?.()};restoreToDom=()=>{this.parentElement&&(this.previousSibling&&this.previousSibling.nextSibling?this.parentElement.insertBefore(this.dismissibleElement,this.previousSibling.nextSibling):this.parentElement.appendChild(this.dismissibleElement),this.dismissibleElement.setAttribute(`aria-hidden`,`false`),this.dismissibleElement.removeAttribute(`data-hidden`),this.dismissibleElement.setAttribute(`data-state`,`visible`),this.onRestore?.())};dismiss=()=>{switch(this.action){case`hide-from-screen`:this.dismissibleElement.setAttribute(`aria-hidden`,`true`),this.dismissibleElement.setAttribute(`data-state`,`hidden`),n({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`),n({element:this.dismissibleElement,callback:this.removeFromDom});break}};restore=()=>{switch(this.action){case`hide-from-screen`:n({element:this.dismissibleElement,callback:this.showOnScreen});break;default:n({element:this.dismissibleElement,callback:this.restoreToDom});break}};setupDismissible(){for(let e of this.dismissButtons)e.addEventListener(`click`,this.dismiss);for(let e of this.restoreButtons)e.addEventListener(`click`,this.restore)}cleanup(){for(let e of this.dismissButtons)e.removeEventListener(`click`,this.dismiss);for(let e of this.restoreButtons)e.removeEventListener(`click`,this.restore);r.removeInstance(`dismissible`,this.dismissibleElement)}static autoInit=(e=`[data-fx-dismissible]`)=>{let n=t(e);for(let e of n)new i(e)};static init=(e,t,n,r)=>new i(e,t,n,r)};export{i as Dismissible};
|
package/package.json
CHANGED
|
@@ -1,45 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flexilla/dismissible",
|
|
3
|
+
"version": "2.0.16",
|
|
3
4
|
"private": false,
|
|
4
|
-
"version": "2.0.15",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
6
7
|
"description": "A lightweight JavaScript component that automatically makes a component dismissible for easy user interaction.",
|
|
7
8
|
"publishConfig": {
|
|
8
9
|
"access": "public"
|
|
9
10
|
},
|
|
10
|
-
"main": "./dist/
|
|
11
|
-
"module": "./dist/
|
|
11
|
+
"main": "./dist/index.cjs",
|
|
12
|
+
"module": "./dist/index.js",
|
|
12
13
|
"types": "./dist/index.d.ts",
|
|
13
14
|
"exports": {
|
|
14
15
|
".": {
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
},
|
|
19
|
-
"require": {
|
|
20
|
-
"types": "./dist/index.d.ts",
|
|
21
|
-
"default": "./dist/dismissible.umd.cjs"
|
|
22
|
-
}
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
23
19
|
}
|
|
24
20
|
},
|
|
25
21
|
"files": [
|
|
26
22
|
"dist",
|
|
27
23
|
"README.md",
|
|
28
|
-
"
|
|
29
|
-
"!vite.config.ts",
|
|
30
|
-
"!.gitignore",
|
|
31
|
-
"!tsconfig.json"
|
|
24
|
+
"LICENSE"
|
|
32
25
|
],
|
|
33
26
|
"scripts": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
27
|
+
"build": "tsdown",
|
|
28
|
+
"clean": "rm -rf dist",
|
|
29
|
+
"dev": "tsdown --watch",
|
|
30
|
+
"typecheck": "tsc --noEmit -p ../../tsconfig.json"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@flexilla/manager": "0.2.3",
|
|
34
|
+
"@flexilla/utilities": "2.5.4"
|
|
37
35
|
},
|
|
38
36
|
"devDependencies": {
|
|
39
|
-
"
|
|
40
|
-
"typescript": "^5.8.3",
|
|
41
|
-
"vite": "^6.3.5",
|
|
42
|
-
"vite-plugin-dts": "^4.5.4"
|
|
37
|
+
"typescript": "5.9.3"
|
|
43
38
|
},
|
|
44
39
|
"keywords": [
|
|
45
40
|
"dismissible",
|
|
@@ -61,8 +56,5 @@
|
|
|
61
56
|
},
|
|
62
57
|
"license": "MIT",
|
|
63
58
|
"author": "johnkat-mj",
|
|
64
|
-
"
|
|
65
|
-
"@flexilla/manager": "^0.2.2"
|
|
66
|
-
},
|
|
67
|
-
"gitHead": "d7ff0b1f6b816f508b255714a15504b41992723d"
|
|
59
|
+
"gitHead": "b642d6db4a3bb9d7d8193c4374b3d2fecbe6ed2e"
|
|
68
60
|
}
|
package/dist/dismissible.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
var u = Object.defineProperty;
|
|
2
|
-
var E = (i, e, s) => e in i ? u(i, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : i[e] = s;
|
|
3
|
-
var t = (i, e, s) => E(i, typeof e != "symbol" ? e + "" : e, s);
|
|
4
|
-
const f = (i, e = document.body) => e.querySelector(i), d = (i, e = document.body) => Array.from(e.querySelectorAll(i)), p = ({
|
|
5
|
-
element: i,
|
|
6
|
-
callback: e,
|
|
7
|
-
type: s,
|
|
8
|
-
keysCheck: n
|
|
9
|
-
}) => {
|
|
10
|
-
const l = getComputedStyle(i), a = l.transition;
|
|
11
|
-
if (a !== "none" && a !== "" && !n.includes(a)) {
|
|
12
|
-
const r = "transitionend", h = () => {
|
|
13
|
-
i.removeEventListener(r, h), e();
|
|
14
|
-
};
|
|
15
|
-
i.addEventListener(r, h, { once: !0 });
|
|
16
|
-
} else
|
|
17
|
-
e();
|
|
18
|
-
}, m = ({
|
|
19
|
-
element: i,
|
|
20
|
-
callback: e
|
|
21
|
-
}) => {
|
|
22
|
-
p({
|
|
23
|
-
element: i,
|
|
24
|
-
callback: e,
|
|
25
|
-
type: "transition",
|
|
26
|
-
keysCheck: ["all 0s ease 0s", "all"]
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
class c {
|
|
30
|
-
static initGlobalRegistry() {
|
|
31
|
-
window.$flexillaInstances || (window.$flexillaInstances = {});
|
|
32
|
-
}
|
|
33
|
-
static register(e, s, n) {
|
|
34
|
-
return this.initGlobalRegistry(), window.$flexillaInstances[e] || (window.$flexillaInstances[e] = []), this.getInstance(e, s) || (window.$flexillaInstances[e].push({ element: s, instance: n }), n);
|
|
35
|
-
}
|
|
36
|
-
static getInstance(e, s) {
|
|
37
|
-
var n, l;
|
|
38
|
-
return this.initGlobalRegistry(), (l = (n = window.$flexillaInstances[e]) == null ? void 0 : n.find(
|
|
39
|
-
(a) => a.element === s
|
|
40
|
-
)) == null ? void 0 : l.instance;
|
|
41
|
-
}
|
|
42
|
-
static removeInstance(e, s) {
|
|
43
|
-
this.initGlobalRegistry(), window.$flexillaInstances[e] && (window.$flexillaInstances[e] = window.$flexillaInstances[e].filter(
|
|
44
|
-
(n) => n.element !== s
|
|
45
|
-
));
|
|
46
|
-
}
|
|
47
|
-
static setup(e) {
|
|
48
|
-
e.setAttribute("data-fx-component", "fx");
|
|
49
|
-
}
|
|
50
|
-
static initialized(e) {
|
|
51
|
-
e.setAttribute("data-component-initialized", "initialized");
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const o = class o {
|
|
55
|
-
// Store original display style
|
|
56
|
-
/**
|
|
57
|
-
* Dismissible Component
|
|
58
|
-
* @param dismissible
|
|
59
|
-
* @param action
|
|
60
|
-
* @param onDismiss
|
|
61
|
-
* @param onRestore
|
|
62
|
-
*/
|
|
63
|
-
constructor(e, s, n, l) {
|
|
64
|
-
t(this, "dismissibleElement");
|
|
65
|
-
t(this, "dismissButtons");
|
|
66
|
-
t(this, "restoreButtons");
|
|
67
|
-
t(this, "action");
|
|
68
|
-
t(this, "onDismiss");
|
|
69
|
-
t(this, "onRestore");
|
|
70
|
-
t(this, "parentElement");
|
|
71
|
-
// Store parent for DOM restoration
|
|
72
|
-
t(this, "previousSibling");
|
|
73
|
-
// Store sibling for precise restoration
|
|
74
|
-
t(this, "originalDisplay");
|
|
75
|
-
t(this, "hideFromScreen", () => {
|
|
76
|
-
var e;
|
|
77
|
-
this.dismissibleElement.style.display = "none", (e = this.onDismiss) == null || e.call(this);
|
|
78
|
-
});
|
|
79
|
-
t(this, "removeFromDom", () => {
|
|
80
|
-
var e, s;
|
|
81
|
-
(e = this.onDismiss) == null || e.call(this), (s = this.dismissibleElement.parentElement) == null || s.removeChild(this.dismissibleElement);
|
|
82
|
-
});
|
|
83
|
-
t(this, "showOnScreen", () => {
|
|
84
|
-
var e;
|
|
85
|
-
this.dismissibleElement.style.display = this.originalDisplay, this.dismissibleElement.setAttribute("aria-hidden", "false"), this.dismissibleElement.setAttribute("data-state", "visible"), (e = this.onRestore) == null || e.call(this);
|
|
86
|
-
});
|
|
87
|
-
t(this, "restoreToDom", () => {
|
|
88
|
-
var e;
|
|
89
|
-
this.parentElement && (this.previousSibling && this.previousSibling.nextSibling ? this.parentElement.insertBefore(this.dismissibleElement, this.previousSibling.nextSibling) : this.parentElement.appendChild(this.dismissibleElement), this.dismissibleElement.setAttribute("aria-hidden", "false"), this.dismissibleElement.removeAttribute("data-hidden"), this.dismissibleElement.setAttribute("data-state", "visible"), (e = this.onRestore) == null || e.call(this));
|
|
90
|
-
});
|
|
91
|
-
t(this, "dismiss", () => {
|
|
92
|
-
switch (this.action) {
|
|
93
|
-
case "hide-from-screen":
|
|
94
|
-
this.dismissibleElement.setAttribute("aria-hidden", "true"), this.dismissibleElement.setAttribute("data-state", "hidden"), m({
|
|
95
|
-
element: this.dismissibleElement,
|
|
96
|
-
callback: this.hideFromScreen
|
|
97
|
-
});
|
|
98
|
-
break;
|
|
99
|
-
default:
|
|
100
|
-
this.dismissibleElement.setAttribute("data-hidden", ""), this.dismissibleElement.setAttribute("aria-hidden", "true"), this.dismissibleElement.setAttribute("data-state", "removed"), m({
|
|
101
|
-
element: this.dismissibleElement,
|
|
102
|
-
callback: this.removeFromDom
|
|
103
|
-
});
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
t(this, "restore", () => {
|
|
108
|
-
switch (this.action) {
|
|
109
|
-
case "hide-from-screen":
|
|
110
|
-
m({
|
|
111
|
-
element: this.dismissibleElement,
|
|
112
|
-
callback: this.showOnScreen
|
|
113
|
-
});
|
|
114
|
-
break;
|
|
115
|
-
default:
|
|
116
|
-
m({
|
|
117
|
-
element: this.dismissibleElement,
|
|
118
|
-
callback: this.restoreToDom
|
|
119
|
-
});
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
const a = typeof e == "string" ? f(e, document.body) : e;
|
|
124
|
-
if (!(a instanceof HTMLElement)) throw new Error("Provided Element not a valid HTMLElement");
|
|
125
|
-
this.dismissibleElement = a, this.action = s || this.dismissibleElement.dataset.action || "hide-from-screen", this.dismissButtons = d("[data-dismiss-btn]", this.dismissibleElement), this.restoreButtons = d("[data-restore-btn]", document.body), this.onDismiss = n, this.onRestore = l, this.parentElement = this.dismissibleElement.parentElement, this.previousSibling = this.dismissibleElement.previousSibling, this.originalDisplay = this.dismissibleElement.style.display || getComputedStyle(this.dismissibleElement).display, this.dismissibleElement.setAttribute("aria-hidden", "false");
|
|
126
|
-
const r = c.getInstance("dismissible", this.dismissibleElement);
|
|
127
|
-
if (r)
|
|
128
|
-
return r;
|
|
129
|
-
this.setupDismissible(), c.register("dismissible", this.dismissibleElement, this);
|
|
130
|
-
}
|
|
131
|
-
setupDismissible() {
|
|
132
|
-
for (const e of this.dismissButtons)
|
|
133
|
-
e.addEventListener("click", this.dismiss);
|
|
134
|
-
for (const e of this.restoreButtons)
|
|
135
|
-
e.addEventListener("click", this.restore);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Cleanup method to remove event listeners
|
|
139
|
-
*/
|
|
140
|
-
cleanup() {
|
|
141
|
-
for (const e of this.dismissButtons)
|
|
142
|
-
e.removeEventListener("click", this.dismiss);
|
|
143
|
-
for (const e of this.restoreButtons)
|
|
144
|
-
e.removeEventListener("click", this.restore);
|
|
145
|
-
c.removeInstance("dismissible", this.dismissibleElement);
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
t(o, "autoInit", (e = "[data-fx-dismissible]") => {
|
|
149
|
-
const s = d(e);
|
|
150
|
-
for (const n of s) new o(n);
|
|
151
|
-
}), /**
|
|
152
|
-
*
|
|
153
|
-
* @param dismissible
|
|
154
|
-
* @param action
|
|
155
|
-
* @param onDismiss
|
|
156
|
-
* @param onRestore
|
|
157
|
-
* @returns
|
|
158
|
-
*/
|
|
159
|
-
t(o, "init", (e, s, n, l) => new o(e, s, n, l));
|
|
160
|
-
let b = o;
|
|
161
|
-
export {
|
|
162
|
-
b as Dismissible
|
|
163
|
-
};
|
package/dist/dismissible.umd.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(l,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(l=typeof globalThis<"u"?globalThis:l||self,n(l["@flexilla/dismissible"]={}))})(this,(function(l){"use strict";var p=Object.defineProperty;var y=(l,n,r)=>n in l?p(l,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):l[n]=r;var i=(l,n,r)=>y(l,typeof n!="symbol"?n+"":n,r);const n=(o,e=document.body)=>e.querySelector(o),r=(o,e=document.body)=>Array.from(e.querySelectorAll(o)),E=({element:o,callback:e,type:s,keysCheck:t})=>{const a=getComputedStyle(o),d=a.transition;if(d!=="none"&&d!==""&&!t.includes(d)){const c="transitionend",f=()=>{o.removeEventListener(c,f),e()};o.addEventListener(c,f,{once:!0})}else e()},h=({element:o,callback:e})=>{E({element:o,callback:e,type:"transition",keysCheck:["all 0s ease 0s","all"]})};class b{static initGlobalRegistry(){window.$flexillaInstances||(window.$flexillaInstances={})}static register(e,s,t){return this.initGlobalRegistry(),window.$flexillaInstances[e]||(window.$flexillaInstances[e]=[]),this.getInstance(e,s)||(window.$flexillaInstances[e].push({element:s,instance:t}),t)}static getInstance(e,s){var t,a;return this.initGlobalRegistry(),(a=(t=window.$flexillaInstances[e])==null?void 0:t.find(d=>d.element===s))==null?void 0:a.instance}static removeInstance(e,s){this.initGlobalRegistry(),window.$flexillaInstances[e]&&(window.$flexillaInstances[e]=window.$flexillaInstances[e].filter(t=>t.element!==s))}static setup(e){e.setAttribute("data-fx-component","fx")}static initialized(e){e.setAttribute("data-component-initialized","initialized")}}const m=class m{constructor(e,s,t,a){i(this,"dismissibleElement");i(this,"dismissButtons");i(this,"restoreButtons");i(this,"action");i(this,"onDismiss");i(this,"onRestore");i(this,"parentElement");i(this,"previousSibling");i(this,"originalDisplay");i(this,"hideFromScreen",()=>{var e;this.dismissibleElement.style.display="none",(e=this.onDismiss)==null||e.call(this)});i(this,"removeFromDom",()=>{var e,s;(e=this.onDismiss)==null||e.call(this),(s=this.dismissibleElement.parentElement)==null||s.removeChild(this.dismissibleElement)});i(this,"showOnScreen",()=>{var e;this.dismissibleElement.style.display=this.originalDisplay,this.dismissibleElement.setAttribute("aria-hidden","false"),this.dismissibleElement.setAttribute("data-state","visible"),(e=this.onRestore)==null||e.call(this)});i(this,"restoreToDom",()=>{var e;this.parentElement&&(this.previousSibling&&this.previousSibling.nextSibling?this.parentElement.insertBefore(this.dismissibleElement,this.previousSibling.nextSibling):this.parentElement.appendChild(this.dismissibleElement),this.dismissibleElement.setAttribute("aria-hidden","false"),this.dismissibleElement.removeAttribute("data-hidden"),this.dismissibleElement.setAttribute("data-state","visible"),(e=this.onRestore)==null||e.call(this))});i(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}});i(this,"restore",()=>{switch(this.action){case"hide-from-screen":h({element:this.dismissibleElement,callback:this.showOnScreen});break;default:h({element:this.dismissibleElement,callback:this.restoreToDom});break}});const d=typeof e=="string"?n(e,document.body):e;if(!(d instanceof HTMLElement))throw new Error("Provided Element not a valid HTMLElement");this.dismissibleElement=d,this.action=s||this.dismissibleElement.dataset.action||"hide-from-screen",this.dismissButtons=r("[data-dismiss-btn]",this.dismissibleElement),this.restoreButtons=r("[data-restore-btn]",document.body),this.onDismiss=t,this.onRestore=a,this.parentElement=this.dismissibleElement.parentElement,this.previousSibling=this.dismissibleElement.previousSibling,this.originalDisplay=this.dismissibleElement.style.display||getComputedStyle(this.dismissibleElement).display,this.dismissibleElement.setAttribute("aria-hidden","false");const c=b.getInstance("dismissible",this.dismissibleElement);if(c)return c;this.setupDismissible(),b.register("dismissible",this.dismissibleElement,this)}setupDismissible(){for(const e of this.dismissButtons)e.addEventListener("click",this.dismiss);for(const e of this.restoreButtons)e.addEventListener("click",this.restore)}cleanup(){for(const e of this.dismissButtons)e.removeEventListener("click",this.dismiss);for(const e of this.restoreButtons)e.removeEventListener("click",this.restore);b.removeInstance("dismissible",this.dismissibleElement)}};i(m,"autoInit",(e="[data-fx-dismissible]")=>{const s=r(e);for(const t of s)new m(t)}),i(m,"init",(e,s,t,a)=>new m(e,s,t,a));let u=m;l.Dismissible=u,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
|