jb-modal 1.7.0 → 1.8.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/dist/jb-modal.cjs.js +2 -0
- package/dist/jb-modal.cjs.js.br +0 -0
- package/dist/jb-modal.cjs.js.gz +0 -0
- package/dist/jb-modal.cjs.js.map +1 -0
- package/dist/{web-component/jb-modal/lib/JBModal.d.ts → jb-modal.d.ts} +37 -35
- package/dist/jb-modal.d.ts.map +1 -0
- package/dist/jb-modal.js +2 -0
- package/dist/jb-modal.js.br +0 -0
- package/dist/jb-modal.js.gz +0 -0
- package/dist/jb-modal.js.map +1 -0
- package/dist/jb-modal.umd.js +2 -0
- package/dist/jb-modal.umd.js.br +0 -0
- package/dist/jb-modal.umd.js.gz +0 -0
- package/dist/jb-modal.umd.js.map +1 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -0
- package/index.js +1 -1
- package/lib/global.d.ts +15 -0
- package/lib/{JBModal.scss → jb-modal.scss} +5 -3
- package/lib/{JBModal.ts → jb-modal.ts} +6 -3
- package/lib/types.ts +9 -0
- package/lib/variables.css +4 -0
- package/package.json +6 -2
- package/react/dist/JBModal.cjs.js +2 -67
- package/react/dist/JBModal.cjs.js.map +1 -1
- package/react/dist/JBModal.d.ts +26 -0
- package/react/dist/JBModal.js +2 -65
- package/react/dist/JBModal.js.map +1 -1
- package/react/dist/JBModal.umd.js +2 -70
- package/react/dist/JBModal.umd.js.map +1 -1
- package/react/dist/events-hook.d.ts +18 -0
- package/react/dist/lib/JBModal.d.ts +26 -0
- package/react/dist/lib/events-hook.d.ts +18 -0
- package/react/dist/web-component/jb-modal/react/lib/JBModal.d.ts +3 -7
- package/react/dist/web-component/jb-modal/react/lib/events-hook.d.ts +18 -0
- package/react/lib/JBModal.tsx +7 -25
- package/react/lib/events-hook.ts +25 -0
- package/react/package.json +1 -1
- package/react/tsconfig.json +4 -5
- package/dist/JBModal.cjs.js +0 -2
- package/dist/JBModal.cjs.js.br +0 -0
- package/dist/JBModal.cjs.js.gz +0 -0
- package/dist/JBModal.cjs.js.map +0 -1
- package/dist/JBModal.js +0 -2
- package/dist/JBModal.js.br +0 -0
- package/dist/JBModal.js.gz +0 -0
- package/dist/JBModal.js.map +0 -1
- package/dist/JBModal.umd.js +0 -2
- package/dist/JBModal.umd.js.br +0 -0
- package/dist/JBModal.umd.js.gz +0 -0
- package/dist/JBModal.umd.js.map +0 -1
- package/dist/web-component/jb-modal/lib/Types.d.ts +0 -4
- package/lib/Types.ts +0 -4
- /package/lib/{JBModal.html → jb-modal.html} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JBModal.cjs.js","sources":["
|
|
1
|
+
{"version":3,"file":"JBModal.cjs.js","names":[],"sources":["../lib/events-hook.ts","../lib/JBModal.tsx"],"sourcesContent":["",""],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBM,SAAU,UAAU,SAAuC,OAAgB;AAC/E,6BAAS,SAAS,QAAQ,MAAM,QAAQ,KAAK;AAC7C,6BAAS,SAAS,QAAQ,MAAM,QAAQ,KAAK;AAC7C,6BAAS,SAAS,SAAS,MAAM,QAAQ;AACzC,6BAAS,SAAS,WAAW,MAAM,UAAU;AAC/C;;;;MCAa,wBAAgB,cAAY,WAAkB,CAAE,OAAA,QAAA;CAC3D,MAAM,UAAU,kBAA4B,KAAK;CACjD,MAAM,CAAC,gBAAgB,qBAAqB,GAAG,oBAAS,EAAE;AAC1D,gCACE,KACA,MAAG,UAAW,QAAG,UAAe,CAAE,GAAC,CAGrC;AAEA,sBAAI,MAAQ;AACZ,uBAAe,iBAAA,EAAA;aAEP;sBAEJ,MAAA;cAAO,aACL,MAAA,UAAgB,KAClB,SAAA,QAAA,MAAA;MAGM,SAAQ,QAAA,OAAA;KAIhB,MAAA,MACD,EAAA;AAED,sBAAU,MAAA;AACV,MACE,QAAA,QACE,SAAA,QAAA,KAAA,MAAK;CAOX,GAAO"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import 'jb-modal';
|
|
3
|
+
import { JBModalWebComponent } from 'jb-modal';
|
|
4
|
+
import { EventProps } from './events-hook.js';
|
|
5
|
+
export type Props = EventProps & React.PropsWithChildren<{
|
|
6
|
+
className?: string;
|
|
7
|
+
isOpen?: boolean;
|
|
8
|
+
id?: string;
|
|
9
|
+
}>;
|
|
10
|
+
declare global {
|
|
11
|
+
namespace JSX {
|
|
12
|
+
interface IntrinsicElements {
|
|
13
|
+
'jb-modal': JBModalType;
|
|
14
|
+
}
|
|
15
|
+
interface JBModalType extends React.DetailedHTMLProps<React.HTMLAttributes<JBModalWebComponent>, JBModalWebComponent> {
|
|
16
|
+
class?: string;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export declare const JBModal: React.ForwardRefExoticComponent<EventProps & {
|
|
21
|
+
className?: string;
|
|
22
|
+
isOpen?: boolean;
|
|
23
|
+
id?: string;
|
|
24
|
+
} & {
|
|
25
|
+
children?: React.ReactNode | undefined;
|
|
26
|
+
} & React.RefAttributes<unknown>>;
|
package/react/dist/JBModal.js
CHANGED
|
@@ -1,65 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function useBindEvent(ref, event, handler, passive = false) {
|
|
5
|
-
useEffect(() => {
|
|
6
|
-
const dom = ref.current;
|
|
7
|
-
if (dom) {
|
|
8
|
-
// initiate the event handler
|
|
9
|
-
dom.addEventListener(event, handler, passive);
|
|
10
|
-
}
|
|
11
|
-
// this will clean up the event every time the component is re-rendered
|
|
12
|
-
return function cleanup() {
|
|
13
|
-
if (dom) {
|
|
14
|
-
dom.removeEventListener(event, handler, passive);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
}, [ref, event, handler, passive]);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const JBModal = React.forwardRef((props, ref) => {
|
|
21
|
-
const element = useRef(null);
|
|
22
|
-
const [refChangeCount, refChangeCountSetter] = useState(0);
|
|
23
|
-
useImperativeHandle(ref, () => (element ? element.current : {}), [element]);
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
refChangeCountSetter(refChangeCount + 1);
|
|
26
|
-
}, [element.current]);
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
if (element.current) {
|
|
29
|
-
if (props.isOpen == true) {
|
|
30
|
-
element.current.open();
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
element.current.close();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}, [props.isOpen]);
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
if (props.id !== undefined && element.current) {
|
|
39
|
-
element.current.addEventListener('urlOpen', onUrlOpen);
|
|
40
|
-
element.current.id = props.id;
|
|
41
|
-
}
|
|
42
|
-
return () => {
|
|
43
|
-
if (props.id !== undefined && element.current) {
|
|
44
|
-
element.current.removeEventListener('urlOpen', onUrlOpen);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}, [props.id]);
|
|
48
|
-
function onClose() {
|
|
49
|
-
if (props.onClose) {
|
|
50
|
-
props.onClose();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function onUrlOpen() {
|
|
54
|
-
if (props.onUrlOpen) {
|
|
55
|
-
props.onUrlOpen();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
useBindEvent(element, 'close', onClose);
|
|
59
|
-
return (React.createElement("jb-modal", { ref: element, class: props.className ? props.className : '' },
|
|
60
|
-
React.createElement("div", { slot: "content" }, props.children)));
|
|
61
|
-
});
|
|
62
|
-
JBModal.displayName = "JBModal";
|
|
63
|
-
|
|
64
|
-
export { JBModal };
|
|
65
|
-
//# sourceMappingURL=JBModal.js.map
|
|
1
|
+
import e,{useEffect as r,useImperativeHandle as n,useRef as t,useState as o}from"react";import"jb-modal";import{useEvent as l}from"jb-core/react";let c=e.forwardRef((c,a)=>{let i=t(null),[d,s]=o(0);return n(a,()=>i?i.current:{},[i]),r(()=>{s(d+1)},[i.current]),r(()=>{i.current&&(!0==c.isOpen?i.current.open():i.current.close())},[c.isOpen]),r(()=>{i.current&&(i.current.id=c.id)},[c.id]),l(i,"load",c.onLoad,!0),l(i,"init",c.onInit,!0),l(i,"close",c.onClose),l(i,"urlOpen",c.onUrlOpen),e.createElement("jb-modal",{ref:i,class:c.className?c.className:""},e.createElement("div",{slot:"content"},c.children))});c.displayName="JBModal";export{c as JBModal};
|
|
2
|
+
//# sourceMappingURL=JBModal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JBModal.js","sources":["
|
|
1
|
+
{"version":3,"file":"JBModal.js","names":[],"sources":["../lib/events-hook.ts","../lib/JBModal.tsx"],"sourcesContent":["",""],"mappings":";;;;;AAmBM,SAAU,UAAU,SAAuC,OAAgB;AAC/E,UAAS,SAAS,QAAQ,MAAM,QAAQ,KAAK;AAC7C,UAAS,SAAS,QAAQ,MAAM,QAAQ,KAAK;AAC7C,UAAS,SAAS,SAAS,MAAM,QAAQ;AACzC,UAAS,SAAS,WAAW,MAAM,UAAU;AAC/C;;;;MCAa,wBAAgB,MAAY,WAAkB,CAAE,OAAA,QAAA;CAC3D,MAAM,UAAU,OAA4B,KAAK;CACjD,MAAM,CAAC,gBAAgB,qBAAqB,GAAG,SAAS,EAAE;AAC1D,qBACE,KACA,MAAG,UAAW,QAAG,UAAe,CAAE,GAAC,CAGrC;AAEA,WAAI,MAAQ;AACZ,uBAAe,iBAAA,EAAA;aAEP;WAEJ,MAAA;cAAO,aACL,MAAA,UAAgB,KAClB,SAAA,QAAA,MAAA;MAGM,SAAQ,QAAA,OAAA;KAIhB,MAAA,MACD,EAAA;AAED,WAAU,MAAA;AACV,MACE,QAAA,QACE,SAAA,QAAA,KAAA,MAAK;CAOX,GAAO"}
|
|
@@ -1,70 +1,2 @@
|
|
|
1
|
-
(function (
|
|
2
|
-
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'react', 'jb-modal'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JBModal = {}, global.React));
|
|
5
|
-
})(this, (function (exports, React) { 'use strict';
|
|
6
|
-
|
|
7
|
-
function useBindEvent(ref, event, handler, passive = false) {
|
|
8
|
-
React.useEffect(() => {
|
|
9
|
-
const dom = ref.current;
|
|
10
|
-
if (dom) {
|
|
11
|
-
// initiate the event handler
|
|
12
|
-
dom.addEventListener(event, handler, passive);
|
|
13
|
-
}
|
|
14
|
-
// this will clean up the event every time the component is re-rendered
|
|
15
|
-
return function cleanup() {
|
|
16
|
-
if (dom) {
|
|
17
|
-
dom.removeEventListener(event, handler, passive);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}, [ref, event, handler, passive]);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const JBModal = React.forwardRef((props, ref) => {
|
|
24
|
-
const element = React.useRef(null);
|
|
25
|
-
const [refChangeCount, refChangeCountSetter] = React.useState(0);
|
|
26
|
-
React.useImperativeHandle(ref, () => (element ? element.current : {}), [element]);
|
|
27
|
-
React.useEffect(() => {
|
|
28
|
-
refChangeCountSetter(refChangeCount + 1);
|
|
29
|
-
}, [element.current]);
|
|
30
|
-
React.useEffect(() => {
|
|
31
|
-
if (element.current) {
|
|
32
|
-
if (props.isOpen == true) {
|
|
33
|
-
element.current.open();
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
element.current.close();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}, [props.isOpen]);
|
|
40
|
-
React.useEffect(() => {
|
|
41
|
-
if (props.id !== undefined && element.current) {
|
|
42
|
-
element.current.addEventListener('urlOpen', onUrlOpen);
|
|
43
|
-
element.current.id = props.id;
|
|
44
|
-
}
|
|
45
|
-
return () => {
|
|
46
|
-
if (props.id !== undefined && element.current) {
|
|
47
|
-
element.current.removeEventListener('urlOpen', onUrlOpen);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}, [props.id]);
|
|
51
|
-
function onClose() {
|
|
52
|
-
if (props.onClose) {
|
|
53
|
-
props.onClose();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function onUrlOpen() {
|
|
57
|
-
if (props.onUrlOpen) {
|
|
58
|
-
props.onUrlOpen();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
useBindEvent(element, 'close', onClose);
|
|
62
|
-
return (React.createElement("jb-modal", { ref: element, class: props.className ? props.className : '' },
|
|
63
|
-
React.createElement("div", { slot: "content" }, props.children)));
|
|
64
|
-
});
|
|
65
|
-
JBModal.displayName = "JBModal";
|
|
66
|
-
|
|
67
|
-
exports.JBModal = JBModal;
|
|
68
|
-
|
|
69
|
-
}));
|
|
70
|
-
//# sourceMappingURL=JBModal.umd.js.map
|
|
1
|
+
var e,t;e=this,t=function(e,t,r,n){"use strict";var o=Object.create,l=Object.defineProperty,a=Object.getOwnPropertyDescriptor,c=Object.getOwnPropertyNames,u=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,d=(e,t,r,n)=>{if(t&&"object"==typeof t||"function"==typeof t)for(var o,u=c(t),d=0,f=u.length;d<f;d++)o=u[d],s.call(e,o)||o===r||l(e,o,{get:(e=>t[e]).bind(null,o),enumerable:!(n=a(t,o))||n.enumerable});return e},f=(e,t,r)=>(r=null!=e?o(u(e)):{},d(!t&&e&&e.__esModule?r:l(r,"default",{value:e,enumerable:!0}),e));t=f(t),n=f(n);let i=t.default.forwardRef((e,r)=>{let o=(0,t.useRef)(null),[l,a]=(0,t.useState)(0);return(0,t.useImperativeHandle)(r,()=>o?o.current:{},[o]),(0,t.useEffect)(()=>{a(l+1)},[o.current]),(0,t.useEffect)(()=>{o.current&&(!0==e.isOpen?o.current.open():o.current.close())},[e.isOpen]),(0,t.useEffect)(()=>{o.current&&(o.current.id=e.id)},[e.id]),(0,n.useEvent)(o,"load",e.onLoad,!0),(0,n.useEvent)(o,"init",e.onInit,!0),(0,n.useEvent)(o,"close",e.onClose),(0,n.useEvent)(o,"urlOpen",e.onUrlOpen),t.default.createElement("jb-modal",{ref:o,class:e.className?e.className:""},t.default.createElement("div",{slot:"content"},e.children))});i.displayName="JBModal",e.JBModal=i},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("jb-modal"),require("jb-core/react")):"function"==typeof define&&define.amd?define(["exports","react","jb-modal","jb-core/react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).JBModalReact={},e.React,e.JBModal,e.JBCoreReact);
|
|
2
|
+
//# sourceMappingURL=JBModal.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JBModal.umd.js","sources":["
|
|
1
|
+
{"version":3,"file":"JBModal.umd.js","names":[],"sources":["../lib/events-hook.ts","../lib/JBModal.tsx"],"sourcesContent":["",""],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBM,SAAU,UAAU,SAAuC,OAAgB;AAC/E,6BAAS,SAAS,QAAQ,MAAM,QAAQ,KAAK;AAC7C,6BAAS,SAAS,QAAQ,MAAM,QAAQ,KAAK;AAC7C,6BAAS,SAAS,SAAS,MAAM,QAAQ;AACzC,6BAAS,SAAS,WAAW,MAAM,UAAU;AAC/C;;;;MCAa,wBAAgB,cAAY,WAAkB,CAAE,OAAA,QAAA;CAC3D,MAAM,UAAU,kBAA4B,KAAK;CACjD,MAAM,CAAC,gBAAgB,qBAAqB,GAAG,oBAAS,EAAE;AAC1D,gCACE,KACA,MAAG,UAAW,QAAG,UAAe,CAAE,GAAC,CAGrC;AAEA,sBAAI,MAAQ;AACZ,uBAAe,iBAAA,EAAA;aAEP;sBAEJ,MAAA;cAAO,aACL,MAAA,UAAgB,KAClB,SAAA,QAAA,MAAA;MAGM,SAAQ,QAAA,OAAA;KAIhB,MAAA,MACD,EAAA;AAED,sBAAU,MAAA;AACV,MACE,QAAA,QACE,SAAA,QAAA,KAAA,MAAK;CAOX,GAAO"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
import type { JBModalWebComponent, JBModalEventType } from 'jb-modal';
|
|
3
|
+
export type EventProps = {
|
|
4
|
+
/**
|
|
5
|
+
* when component loaded, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
6
|
+
*/
|
|
7
|
+
onLoad?: (e: JBModalEventType<CustomEvent>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* when all property set and ready to use, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
10
|
+
*/
|
|
11
|
+
onInit?: (e: JBModalEventType<CustomEvent>) => void;
|
|
12
|
+
onClose?: (e: JBModalEventType<CustomEvent>) => void;
|
|
13
|
+
/**
|
|
14
|
+
* when modal opened automatically by url hash (when element have id and url has #id) use this to update open state in parent component
|
|
15
|
+
*/
|
|
16
|
+
onUrlOpen?: (e: JBModalEventType<CustomEvent>) => void;
|
|
17
|
+
};
|
|
18
|
+
export declare function useEvents(element: RefObject<JBModalWebComponent>, props: EventProps): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import 'jb-modal';
|
|
3
|
+
import { JBModalWebComponent } from 'jb-modal';
|
|
4
|
+
import { EventProps } from './events-hook.js';
|
|
5
|
+
export type Props = EventProps & React.PropsWithChildren<{
|
|
6
|
+
className?: string;
|
|
7
|
+
isOpen?: boolean;
|
|
8
|
+
id?: string;
|
|
9
|
+
}>;
|
|
10
|
+
declare global {
|
|
11
|
+
namespace JSX {
|
|
12
|
+
interface IntrinsicElements {
|
|
13
|
+
'jb-modal': JBModalType;
|
|
14
|
+
}
|
|
15
|
+
interface JBModalType extends React.DetailedHTMLProps<React.HTMLAttributes<JBModalWebComponent>, JBModalWebComponent> {
|
|
16
|
+
class?: string;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export declare const JBModal: React.ForwardRefExoticComponent<EventProps & {
|
|
21
|
+
className?: string;
|
|
22
|
+
isOpen?: boolean;
|
|
23
|
+
id?: string;
|
|
24
|
+
} & {
|
|
25
|
+
children?: React.ReactNode;
|
|
26
|
+
} & React.RefAttributes<unknown>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
import type { JBModalWebComponent, JBModalEventType } from 'jb-modal';
|
|
3
|
+
export type EventProps = {
|
|
4
|
+
/**
|
|
5
|
+
* when component loaded, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
6
|
+
*/
|
|
7
|
+
onLoad?: (e: JBModalEventType<CustomEvent>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* when all property set and ready to use, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
10
|
+
*/
|
|
11
|
+
onInit?: (e: JBModalEventType<CustomEvent>) => void;
|
|
12
|
+
onClose?: (e: JBModalEventType<CustomEvent>) => void;
|
|
13
|
+
/**
|
|
14
|
+
* when modal opened automatically by url hash (when element have id and url has #id) use this to update open state in parent component
|
|
15
|
+
*/
|
|
16
|
+
onUrlOpen?: (e: JBModalEventType<CustomEvent>) => void;
|
|
17
|
+
};
|
|
18
|
+
export declare function useEvents(element: RefObject<JBModalWebComponent>, props: EventProps): void;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import 'jb-modal';
|
|
3
3
|
import { JBModalWebComponent } from 'jb-modal';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
onUrlOpen?: () => void;
|
|
4
|
+
import { EventProps } from './events-hook.js';
|
|
5
|
+
export type Props = EventProps & React.PropsWithChildren<{
|
|
7
6
|
className?: string;
|
|
8
7
|
isOpen?: boolean;
|
|
9
8
|
id?: string;
|
|
@@ -18,13 +17,10 @@ declare global {
|
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
|
-
declare const JBModal: React.ForwardRefExoticComponent<{
|
|
22
|
-
onClose?: () => void;
|
|
23
|
-
onUrlOpen?: () => void;
|
|
20
|
+
export declare const JBModal: React.ForwardRefExoticComponent<EventProps & {
|
|
24
21
|
className?: string;
|
|
25
22
|
isOpen?: boolean;
|
|
26
23
|
id?: string;
|
|
27
24
|
} & {
|
|
28
25
|
children?: React.ReactNode;
|
|
29
26
|
} & React.RefAttributes<unknown>>;
|
|
30
|
-
export { JBModal };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
import type { JBModalWebComponent, JBModalEventType } from 'jb-modal';
|
|
3
|
+
export type EventProps = {
|
|
4
|
+
/**
|
|
5
|
+
* when component loaded, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
6
|
+
*/
|
|
7
|
+
onLoad?: (e: JBModalEventType<CustomEvent>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* when all property set and ready to use, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
10
|
+
*/
|
|
11
|
+
onInit?: (e: JBModalEventType<CustomEvent>) => void;
|
|
12
|
+
onClose?: (e: JBModalEventType<CustomEvent>) => void;
|
|
13
|
+
/**
|
|
14
|
+
* when modal opened automatically by url hash (when element have id and url has #id) use this to update open state in parent component
|
|
15
|
+
*/
|
|
16
|
+
onUrlOpen?: (e: JBModalEventType<CustomEvent>) => void;
|
|
17
|
+
};
|
|
18
|
+
export declare function useEvents(element: RefObject<JBModalWebComponent>, props: EventProps): void;
|
package/react/lib/JBModal.tsx
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import PropTypes from 'prop-types';
|
|
2
1
|
import React, { useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
3
2
|
import 'jb-modal';
|
|
4
3
|
// eslint-disable-next-line no-duplicate-imports
|
|
5
4
|
import { JBModalWebComponent } from 'jb-modal';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
onUrlOpen?: () => void,
|
|
5
|
+
import { useEvents, EventProps } from './events-hook.js';
|
|
6
|
+
|
|
7
|
+
export type Props = EventProps & React.PropsWithChildren<{
|
|
10
8
|
className?:string,
|
|
11
9
|
isOpen?: boolean,
|
|
12
10
|
id?: string,
|
|
@@ -24,7 +22,7 @@ declare global {
|
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
const JBModal = React.forwardRef((props:
|
|
25
|
+
export const JBModal = React.forwardRef((props:Props, ref) => {
|
|
28
26
|
const element = useRef<JBModalWebComponent>(null);
|
|
29
27
|
const [refChangeCount, refChangeCountSetter] = useState(0);
|
|
30
28
|
useImperativeHandle(
|
|
@@ -46,27 +44,12 @@ const JBModal = React.forwardRef((props:JBModalProps, ref) => {
|
|
|
46
44
|
|
|
47
45
|
}, [props.isOpen]);
|
|
48
46
|
useEffect(() => {
|
|
49
|
-
if (
|
|
50
|
-
element.current.addEventListener('urlOpen', onUrlOpen);
|
|
47
|
+
if (element.current) {
|
|
51
48
|
element.current.id = props.id;
|
|
52
49
|
}
|
|
53
|
-
return () => {
|
|
54
|
-
if (props.id !== undefined && element.current) {
|
|
55
|
-
element.current.removeEventListener('urlOpen', onUrlOpen);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
50
|
}, [props.id]);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
props.onClose();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function onUrlOpen() {
|
|
65
|
-
if (props.onUrlOpen) {
|
|
66
|
-
props.onUrlOpen();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
useBindEvent(element, 'close', onClose);
|
|
51
|
+
|
|
52
|
+
useEvents(element, props);
|
|
70
53
|
return (
|
|
71
54
|
<jb-modal ref={element} class={props.className ? props.className : ''}>
|
|
72
55
|
<div slot="content">
|
|
@@ -77,4 +60,3 @@ const JBModal = React.forwardRef((props:JBModalProps, ref) => {
|
|
|
77
60
|
});
|
|
78
61
|
|
|
79
62
|
JBModal.displayName = "JBModal";
|
|
80
|
-
export {JBModal};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useEvent } from "jb-core/react";
|
|
2
|
+
import { RefObject } from "react";
|
|
3
|
+
import type {JBModalWebComponent, JBModalEventType} from 'jb-modal';
|
|
4
|
+
|
|
5
|
+
export type EventProps = {
|
|
6
|
+
/**
|
|
7
|
+
* when component loaded, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
8
|
+
*/
|
|
9
|
+
onLoad?: (e: JBModalEventType<CustomEvent>) => void,
|
|
10
|
+
/**
|
|
11
|
+
* when all property set and ready to use, in most cases component is already loaded before react mount so you dont need this but if you load web-component dynamically with lazy load it will be called after react mount
|
|
12
|
+
*/
|
|
13
|
+
onInit?: (e: JBModalEventType<CustomEvent>) => void,
|
|
14
|
+
onClose?: (e: JBModalEventType<CustomEvent>) => void,
|
|
15
|
+
/**
|
|
16
|
+
* when modal opened automatically by url hash (when element have id and url has #id) use this to update open state in parent component
|
|
17
|
+
*/
|
|
18
|
+
onUrlOpen?: (e: JBModalEventType<CustomEvent>) => void,
|
|
19
|
+
}
|
|
20
|
+
export function useEvents(element:RefObject<JBModalWebComponent>,props:EventProps){
|
|
21
|
+
useEvent(element, 'load', props.onLoad, true);
|
|
22
|
+
useEvent(element, 'init', props.onInit, true);
|
|
23
|
+
useEvent(element, 'close', props.onClose);
|
|
24
|
+
useEvent(element, 'urlOpen', props.onUrlOpen);
|
|
25
|
+
}
|
package/react/package.json
CHANGED
package/react/tsconfig.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"baseUrl": "."
|
|
3
|
+
"baseUrl": ".",
|
|
4
|
+
"rootDir": "./lib",
|
|
5
|
+
"declarationDir": "./dist"
|
|
4
6
|
},
|
|
5
7
|
"include": [
|
|
6
|
-
"../../../common/scripts/**/*.ts",
|
|
7
|
-
"../../../common/hooks/**/*.ts",
|
|
8
|
-
"../../../common/hooks/**/*.js",
|
|
9
8
|
"lib/**/*.ts",
|
|
10
9
|
"lib/**/*.tsx"
|
|
11
10
|
],
|
|
@@ -14,5 +13,5 @@
|
|
|
14
13
|
"**/*.spec.ts",
|
|
15
14
|
"dist",
|
|
16
15
|
],
|
|
17
|
-
"extends":"
|
|
16
|
+
"extends":"jb-core/configs/tsconfig-react.json"
|
|
18
17
|
}
|
package/dist/JBModal.cjs.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";function n(n,e,t,o){if("a"===t&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?n!==e||!o:!e.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===t?o:"a"===t?o.call(n):o?o.value:e.get(n)}function e(n,e,t,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?n!==e||!i:!e.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(n,t):i?i.value=t:e.set(n,t),t}"function"==typeof SuppressedError&&SuppressedError;var t,o,i,a;class s extends HTMLElement{get id(){const e=this.getAttribute("id")||"";return n(this,i,"f")||e}set id(n){e(this,i,n,"f"),this.checkInitialOpenness()}get isOpen(){return n(this,o,"f")}constructor(){super(),t.add(this),o.set(this,!1),i.set(this,""),this.config={autoCloseOnBackgroundClick:!1},this.initWebComponent()}connectedCallback(){this.callOnLoadEvent(),this.initProp(),this.callOnInitEvent()}callOnLoadEvent(){const n=new CustomEvent("load",{bubbles:!0,composed:!0});this.dispatchEvent(n)}callOnInitEvent(){const n=new CustomEvent("init",{bubbles:!0,composed:!0});this.dispatchEvent(n)}initWebComponent(){const n=this.attachShadow({mode:"open"}),e=document.createElement("template");e.innerHTML='<style>.jb-modal-web-component {\n position: fixed;\n top: 0;\n left: 0;\n z-index: var(--jb-modal-z-index, 1);\n width: 100%;\n height: 100%;\n}\n.jb-modal-web-component.--closed {\n display: none;\n}\n@media (min-width: 320px) and (max-width: 767px) {\n .jb-modal-web-component.--closed .modal-content-wrapper {\n transform: translateY(100%);\n }\n}\n.jb-modal-web-component.--opened {\n display: block;\n}\n@media (min-width: 320px) and (max-width: 767px) {\n .jb-modal-web-component.--opened .modal-content-wrapper {\n animation-name: swipe-up;\n animation-duration: 0.3s;\n animation-delay: 0s;\n animation-iteration-count: 1;\n animation-timing-function: ease;\n }\n}\n@keyframes swipe-up {\n 0% {\n transform: translateY(100%);\n }\n 100% {\n transform: translateY(0%);\n }\n}\n.jb-modal-web-component .modal-background {\n position: absolute;\n top: 0;\n left: 0;\n background-color: var(--jb-modal-back-bg-color, rgba(255, 255, 255, 0.1));\n backdrop-filter: blur(10px);\n z-index: 2;\n width: 100%;\n height: 100%;\n}\n.jb-modal-web-component .modal-content-wrapper {\n position: absolute;\n top: 0;\n left: 0;\n z-index: 3;\n width: 100%;\n height: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n pointer-events: none;\n}\n@media (min-width: 320px) and (max-width: 767px) {\n .jb-modal-web-component .modal-content-wrapper {\n bottom: 0;\n top: initial;\n align-items: flex-end;\n }\n}\n.jb-modal-web-component .modal-content-wrapper .modal-content {\n pointer-events: all;\n width: auto;\n height: auto;\n background-color: var(--jb-modal-bg-color, #fff);\n border-radius: var(--jb-modal-border-radius, 24px);\n}\n@media (min-width: 320px) and (max-width: 767px) {\n .jb-modal-web-component .modal-content-wrapper .modal-content {\n width: 100%;\n height: auto;\n max-height: calc(100% - 80px);\n min-height: 32px;\n border-radius: var(--jb-modal-border-radius-mobile, 24px 24px 0 0);\n overflow-y: auto;\n }\n}</style>\n<div class="jb-modal-web-component --closed">\r\n <div class="modal-background"></div>\r\n <div class="modal-content-wrapper">\r\n <div class="modal-content">\r\n <slot name="content"></slot>\r\n </div>\r\n </div>\r\n</div>',n.appendChild(e.content.cloneNode(!0)),this.elements={componentWrapper:n.querySelector(".jb-modal-web-component"),background:n.querySelector(".modal-background")}}registerEventListener(){this.elements.background.addEventListener("click",this.onBackgroundClick.bind(this)),window.addEventListener("popstate",n(this,t,"m",a).bind(this))}initProp(){this.registerEventListener()}checkInitialOpenness(){window.location.hash==`#${this.id}`&&(this.triggerUrlOpenEvent(),this.open())}triggerUrlOpenEvent(){const n=new CustomEvent("urlOpen",{bubbles:!0,composed:!0});this.dispatchEvent(n)}static get observedAttributes(){return["is-open","id"]}attributeChangedCallback(n,e,t){this.onAttributeChange(n,t)}onAttributeChange(e,t){switch(e){case"is-open":"true"==t?n(this,o,"f")||this.open():n(this,o,"f")&&this.close();break;case"id":this.id=t}}onBackgroundClick(){this.dispatchCloseEvent("BACKGROUND_CLICK"),this.config.autoCloseOnBackgroundClick&&this.close()}dispatchCloseEvent(n){const e=new CustomEvent("close",{detail:{eventType:n}});this.dispatchEvent(e)}close(){e(this,o,!1,"f"),this.elements.componentWrapper.classList.remove("--opened"),this.elements.componentWrapper.classList.add("--closed");const n=window.history;window.location.hash==`#${this.id}`&&n.go(-1)}open(){if(e(this,o,!0,"f"),this.elements.componentWrapper.classList.remove("--closed"),this.elements.componentWrapper.classList.add("--opened"),this.id){const n=window.history;window.location.hash!=`#${this.id}`&&n.pushState({JBModal:{}},"",`#${this.id}`)}}}o=new WeakMap,i=new WeakMap,t=new WeakSet,a=function(){this.isOpen&&(this.dispatchCloseEvent("HISTORY_BACK_EVENT"),this.config.autoCloseOnBackgroundClick&&this.close())};!customElements.get("jb-modal")&&window.customElements.define("jb-modal",s),exports.JBModalWebComponent=s;
|
|
2
|
-
//# sourceMappingURL=JBModal.cjs.js.map
|
package/dist/JBModal.cjs.js.br
DELETED
|
Binary file
|
package/dist/JBModal.cjs.js.gz
DELETED
|
Binary file
|
package/dist/JBModal.cjs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JBModal.cjs.js","sources":["../lib/JBModal.ts"],"sourcesContent":["import HTML from \"./JBModal.html\";\r\nimport CSS from \"./JBModal.scss\";\r\nimport { ElementsObject } from \"./Types\";\r\n\r\nexport class JBModalWebComponent extends HTMLElement {\r\n #isOpen = false;\r\n #id = \"\";\r\n elements!: ElementsObject;\r\n config = {\r\n autoCloseOnBackgroundClick: false,\r\n };\r\n get id() {\r\n const id: string = this.getAttribute(\"id\") || \"\";\r\n return this.#id || id;\r\n }\r\n set id(value: string) {\r\n this.#id = value;\r\n this.checkInitialOpenness();\r\n }\r\n get isOpen() {\r\n return this.#isOpen;\r\n }\r\n constructor() {\r\n super();\r\n this.initWebComponent();\r\n }\r\n connectedCallback() {\r\n // standard web component event that called when all of dom is binded\r\n this.callOnLoadEvent();\r\n this.initProp();\r\n this.callOnInitEvent();\r\n }\r\n callOnLoadEvent() {\r\n const event = new CustomEvent(\"load\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n callOnInitEvent() {\r\n const event = new CustomEvent(\"init\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n initWebComponent() {\r\n const shadowRoot = this.attachShadow({\r\n mode: \"open\",\r\n });\r\n const html = `<style>${CSS}</style>` + \"\\n\" + HTML;\r\n const element = document.createElement(\"template\");\r\n element.innerHTML = html;\r\n shadowRoot.appendChild(element.content.cloneNode(true));\r\n this.elements = {\r\n componentWrapper: shadowRoot.querySelector(\".jb-modal-web-component\")!,\r\n background: shadowRoot.querySelector(\".modal-background\")!,\r\n };\r\n }\r\n registerEventListener() {\r\n this.elements.background.addEventListener(\r\n \"click\",\r\n this.onBackgroundClick.bind(this)\r\n );\r\n //TODO: remove listener on component unmount\r\n window.addEventListener(\"popstate\", this.#onBrowserBack.bind(this));\r\n }\r\n initProp() {\r\n this.registerEventListener();\r\n }\r\n checkInitialOpenness() {\r\n //if page has modal url we open it automatically\r\n const location = window.location;\r\n if (location.hash == `#${this.id}`) {\r\n this.triggerUrlOpenEvent();\r\n this.open();\r\n }\r\n }\r\n triggerUrlOpenEvent() {\r\n //when modal open itself becuase url contain modal id\r\n const event = new CustomEvent(\"urlOpen\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n static get observedAttributes() {\r\n return [\"is-open\", \"id\"];\r\n }\r\n attributeChangedCallback(name:string, oldValue:string, newValue:string) {\r\n // do something when an attribute has changed\r\n this.onAttributeChange(name, newValue);\r\n }\r\n onAttributeChange(name:string, value:string) {\r\n switch (name) {\r\n case \"is-open\":\r\n if (value == \"true\") {\r\n if (!this.#isOpen) {\r\n this.open();\r\n }\r\n } else {\r\n if (this.#isOpen) {\r\n this.close();\r\n }\r\n }\r\n break;\r\n case \"id\":\r\n this.id = value;\r\n break;\r\n }\r\n }\r\n onBackgroundClick() {\r\n this.dispatchCloseEvent(\"BACKGROUND_CLICK\");\r\n if (this.config.autoCloseOnBackgroundClick) {\r\n this.close();\r\n }\r\n }\r\n dispatchCloseEvent(type:\"BACKGROUND_CLICK\"| \"HISTORY_BACK_EVENT\" | \"CLOSE_BUTTON_CLICK\") {\r\n //we have many ways to dispatch close event like back button on close clicked\r\n const event = new CustomEvent(\"close\", { detail: { eventType: type } });\r\n this.dispatchEvent(event);\r\n }\r\n /**\r\n * @public\r\n * will close modal\r\n */\r\n close() {\r\n this.#isOpen = false;\r\n this.elements.componentWrapper.classList.remove(\"--opened\");\r\n this.elements.componentWrapper.classList.add(\"--closed\");\r\n const history = window.history;\r\n const location = window.location;\r\n if (location.hash == `#${this.id}`) {\r\n history.go(-1);\r\n }\r\n }\r\n /**\r\n * @public\r\n * will open modal\r\n */\r\n open() {\r\n this.#isOpen = true;\r\n this.elements.componentWrapper.classList.remove(\"--closed\");\r\n this.elements.componentWrapper.classList.add(\"--opened\");\r\n if (this.id) {\r\n const history = window.history;\r\n const location = window.location;\r\n if (!(location.hash == `#${this.id}`)) {\r\n history.pushState({ JBModal: {} }, \"\", `#${this.id}`);\r\n }\r\n }\r\n }\r\n #onBrowserBack() {\r\n if (this.isOpen) {\r\n this.dispatchCloseEvent(\"HISTORY_BACK_EVENT\");\r\n if (this.config.autoCloseOnBackgroundClick) {\r\n this.close();\r\n }\r\n }\r\n }\r\n}\r\nconst myElementNotExists = !customElements.get(\"jb-modal\");\r\nif (myElementNotExists) {\r\n window.customElements.define(\"jb-modal\", JBModalWebComponent);\r\n}\r\n"],"names":["JBModalWebComponent","HTMLElement","id","this","getAttribute","__classPrivateFieldGet","_JBModalWebComponent_id","value","__classPrivateFieldSet","checkInitialOpenness","isOpen","_JBModalWebComponent_isOpen","constructor","super","set","config","autoCloseOnBackgroundClick","initWebComponent","connectedCallback","callOnLoadEvent","initProp","callOnInitEvent","event","CustomEvent","bubbles","composed","dispatchEvent","shadowRoot","attachShadow","mode","element","document","createElement","innerHTML","appendChild","content","cloneNode","elements","componentWrapper","querySelector","background","registerEventListener","addEventListener","onBackgroundClick","bind","window","_JBModalWebComponent_instances","_JBModalWebComponent_onBrowserBack","location","hash","triggerUrlOpenEvent","open","observedAttributes","attributeChangedCallback","name","oldValue","newValue","onAttributeChange","close","dispatchCloseEvent","type","detail","eventType","classList","remove","add","history","go","pushState","JBModal","customElements","get","define"],"mappings":"+tBAIM,MAAOA,UAA4BC,YAOvC,MAAIC,GACF,MAAMA,EAAaC,KAAKC,aAAa,OAAS,GAC9C,OAAOC,EAAAF,KAAQG,EAAA,MAAIJ,CACpB,CACD,MAAIA,CAAGK,GACLC,EAAAL,KAAIG,EAAOC,EAAK,KAChBJ,KAAKM,sBACN,CACD,UAAIC,GACF,OAAOL,EAAAF,KAAIQ,EAAA,IACZ,CACD,WAAAC,GACEC,oBAlBFF,EAAAG,IAAAX,MAAU,GACVG,EAAAQ,IAAAX,KAAM,IAENA,KAAAY,OAAS,CACPC,4BAA4B,GAe5Bb,KAAKc,kBACN,CACD,iBAAAC,GAEEf,KAAKgB,kBACLhB,KAAKiB,WACLjB,KAAKkB,iBACN,CACD,eAAAF,GACE,MAAMG,EAAQ,IAAIC,YAAY,OAAQ,CAAEC,SAAS,EAAMC,UAAU,IACjEtB,KAAK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,IAAIC,YAAY,QAAS,CAAEsC,OAAQ,CAAEC,UAAWF,KAC9DzD,KAAKuB,cAAcJ,EACpB,CAKD,KAAAoC,GACElD,EAAAL,KAAIQ,GAAW,EAAK,KACpBR,KAAKkC,SAASC,iBAAiByB,UAAUC,OAAO,YAChD7D,KAAKkC,SAASC,iBAAiByB,UAAUE,IAAI,YAC7C,MAAMC,EAAUrB,OAAOqB,QACNrB,OAAOG,SACXC,MAAQ,IAAI9C,KAAKD,MAC5BgE,EAAQC,IAAI,EAEf,CAKD,IAAAhB,GAIE,GAHA3C,EAAAL,KAAIQ,GAAW,EAAI,KACnBR,KAAKkC,SAASC,iBAAiByB,UAAUC,OAAO,YAChD7D,KAAKkC,SAASC,iBAAiByB,UAAUE,IAAI,YACzC9D,KAAKD,GAAI,CACX,MAAMgE,EAAUrB,OAAOqB,QACNrB,OAAOG,SACTC,MAAQ,IAAI9C,KAAKD,MAC9BgE,EAAQE,UAAU,CAAEC,QAAS,IAAM,GAAI,IAAIlE,KAAKD,KAEnD,CACF,yDAEKC,KAAKO,SACPP,KAAKwD,mBAAmB,sBACpBxD,KAAKY,OAAOC,4BACdb,KAAKuD,QAGX,GAE0BY,eAAeC,IAAI,aAE7C1B,OAAOyB,eAAeE,OAAO,WAAYxE"}
|
package/dist/JBModal.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function n(n,e,t,o){if("a"===t&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?n!==e||!o:!e.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===t?o:"a"===t?o.call(n):o?o.value:e.get(n)}function e(n,e,t,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?n!==e||!i:!e.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(n,t):i?i.value=t:e.set(n,t),t}"function"==typeof SuppressedError&&SuppressedError;var t,o,i,a;class s extends HTMLElement{get id(){const e=this.getAttribute("id")||"";return n(this,i,"f")||e}set id(n){e(this,i,n,"f"),this.checkInitialOpenness()}get isOpen(){return n(this,o,"f")}constructor(){super(),t.add(this),o.set(this,!1),i.set(this,""),this.config={autoCloseOnBackgroundClick:!1},this.initWebComponent()}connectedCallback(){this.callOnLoadEvent(),this.initProp(),this.callOnInitEvent()}callOnLoadEvent(){const n=new CustomEvent("load",{bubbles:!0,composed:!0});this.dispatchEvent(n)}callOnInitEvent(){const n=new CustomEvent("init",{bubbles:!0,composed:!0});this.dispatchEvent(n)}initWebComponent(){const n=this.attachShadow({mode:"open"}),e=document.createElement("template");e.innerHTML='<style>.jb-modal-web-component {\n position: fixed;\n top: 0;\n left: 0;\n z-index: var(--jb-modal-z-index, 1);\n width: 100%;\n height: 100%;\n}\n.jb-modal-web-component.--closed {\n display: none;\n}\n@media (min-width: 320px) and (max-width: 767px) {\n .jb-modal-web-component.--closed .modal-content-wrapper {\n transform: translateY(100%);\n }\n}\n.jb-modal-web-component.--opened {\n display: block;\n}\n@media (min-width: 320px) and (max-width: 767px) {\n .jb-modal-web-component.--opened .modal-content-wrapper {\n animation-name: swipe-up;\n animation-duration: 0.3s;\n animation-delay: 0s;\n animation-iteration-count: 1;\n animation-timing-function: ease;\n }\n}\n@keyframes swipe-up {\n 0% {\n transform: translateY(100%);\n }\n 100% {\n transform: translateY(0%);\n }\n}\n.jb-modal-web-component .modal-background {\n position: absolute;\n top: 0;\n left: 0;\n background-color: var(--jb-modal-back-bg-color, rgba(255, 255, 255, 0.1));\n backdrop-filter: blur(10px);\n z-index: 2;\n width: 100%;\n height: 100%;\n}\n.jb-modal-web-component .modal-content-wrapper {\n position: absolute;\n top: 0;\n left: 0;\n z-index: 3;\n width: 100%;\n height: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n pointer-events: none;\n}\n@media (min-width: 320px) and (max-width: 767px) {\n .jb-modal-web-component .modal-content-wrapper {\n bottom: 0;\n top: initial;\n align-items: flex-end;\n }\n}\n.jb-modal-web-component .modal-content-wrapper .modal-content {\n pointer-events: all;\n width: auto;\n height: auto;\n background-color: var(--jb-modal-bg-color, #fff);\n border-radius: var(--jb-modal-border-radius, 24px);\n}\n@media (min-width: 320px) and (max-width: 767px) {\n .jb-modal-web-component .modal-content-wrapper .modal-content {\n width: 100%;\n height: auto;\n max-height: calc(100% - 80px);\n min-height: 32px;\n border-radius: var(--jb-modal-border-radius-mobile, 24px 24px 0 0);\n overflow-y: auto;\n }\n}</style>\n<div class="jb-modal-web-component --closed">\r\n <div class="modal-background"></div>\r\n <div class="modal-content-wrapper">\r\n <div class="modal-content">\r\n <slot name="content"></slot>\r\n </div>\r\n </div>\r\n</div>',n.appendChild(e.content.cloneNode(!0)),this.elements={componentWrapper:n.querySelector(".jb-modal-web-component"),background:n.querySelector(".modal-background")}}registerEventListener(){this.elements.background.addEventListener("click",this.onBackgroundClick.bind(this)),window.addEventListener("popstate",n(this,t,"m",a).bind(this))}initProp(){this.registerEventListener()}checkInitialOpenness(){window.location.hash==`#${this.id}`&&(this.triggerUrlOpenEvent(),this.open())}triggerUrlOpenEvent(){const n=new CustomEvent("urlOpen",{bubbles:!0,composed:!0});this.dispatchEvent(n)}static get observedAttributes(){return["is-open","id"]}attributeChangedCallback(n,e,t){this.onAttributeChange(n,t)}onAttributeChange(e,t){switch(e){case"is-open":"true"==t?n(this,o,"f")||this.open():n(this,o,"f")&&this.close();break;case"id":this.id=t}}onBackgroundClick(){this.dispatchCloseEvent("BACKGROUND_CLICK"),this.config.autoCloseOnBackgroundClick&&this.close()}dispatchCloseEvent(n){const e=new CustomEvent("close",{detail:{eventType:n}});this.dispatchEvent(e)}close(){e(this,o,!1,"f"),this.elements.componentWrapper.classList.remove("--opened"),this.elements.componentWrapper.classList.add("--closed");const n=window.history;window.location.hash==`#${this.id}`&&n.go(-1)}open(){if(e(this,o,!0,"f"),this.elements.componentWrapper.classList.remove("--closed"),this.elements.componentWrapper.classList.add("--opened"),this.id){const n=window.history;window.location.hash!=`#${this.id}`&&n.pushState({JBModal:{}},"",`#${this.id}`)}}}o=new WeakMap,i=new WeakMap,t=new WeakSet,a=function(){this.isOpen&&(this.dispatchCloseEvent("HISTORY_BACK_EVENT"),this.config.autoCloseOnBackgroundClick&&this.close())};!customElements.get("jb-modal")&&window.customElements.define("jb-modal",s);export{s as JBModalWebComponent};
|
|
2
|
-
//# sourceMappingURL=JBModal.js.map
|
package/dist/JBModal.js.br
DELETED
|
Binary file
|
package/dist/JBModal.js.gz
DELETED
|
Binary file
|
package/dist/JBModal.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JBModal.js","sources":["../lib/JBModal.ts"],"sourcesContent":["import HTML from \"./JBModal.html\";\r\nimport CSS from \"./JBModal.scss\";\r\nimport { ElementsObject } from \"./Types\";\r\n\r\nexport class JBModalWebComponent extends HTMLElement {\r\n #isOpen = false;\r\n #id = \"\";\r\n elements!: ElementsObject;\r\n config = {\r\n autoCloseOnBackgroundClick: false,\r\n };\r\n get id() {\r\n const id: string = this.getAttribute(\"id\") || \"\";\r\n return this.#id || id;\r\n }\r\n set id(value: string) {\r\n this.#id = value;\r\n this.checkInitialOpenness();\r\n }\r\n get isOpen() {\r\n return this.#isOpen;\r\n }\r\n constructor() {\r\n super();\r\n this.initWebComponent();\r\n }\r\n connectedCallback() {\r\n // standard web component event that called when all of dom is binded\r\n this.callOnLoadEvent();\r\n this.initProp();\r\n this.callOnInitEvent();\r\n }\r\n callOnLoadEvent() {\r\n const event = new CustomEvent(\"load\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n callOnInitEvent() {\r\n const event = new CustomEvent(\"init\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n initWebComponent() {\r\n const shadowRoot = this.attachShadow({\r\n mode: \"open\",\r\n });\r\n const html = `<style>${CSS}</style>` + \"\\n\" + HTML;\r\n const element = document.createElement(\"template\");\r\n element.innerHTML = html;\r\n shadowRoot.appendChild(element.content.cloneNode(true));\r\n this.elements = {\r\n componentWrapper: shadowRoot.querySelector(\".jb-modal-web-component\")!,\r\n background: shadowRoot.querySelector(\".modal-background\")!,\r\n };\r\n }\r\n registerEventListener() {\r\n this.elements.background.addEventListener(\r\n \"click\",\r\n this.onBackgroundClick.bind(this)\r\n );\r\n //TODO: remove listener on component unmount\r\n window.addEventListener(\"popstate\", this.#onBrowserBack.bind(this));\r\n }\r\n initProp() {\r\n this.registerEventListener();\r\n }\r\n checkInitialOpenness() {\r\n //if page has modal url we open it automatically\r\n const location = window.location;\r\n if (location.hash == `#${this.id}`) {\r\n this.triggerUrlOpenEvent();\r\n this.open();\r\n }\r\n }\r\n triggerUrlOpenEvent() {\r\n //when modal open itself becuase url contain modal id\r\n const event = new CustomEvent(\"urlOpen\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n static get observedAttributes() {\r\n return [\"is-open\", \"id\"];\r\n }\r\n attributeChangedCallback(name:string, oldValue:string, newValue:string) {\r\n // do something when an attribute has changed\r\n this.onAttributeChange(name, newValue);\r\n }\r\n onAttributeChange(name:string, value:string) {\r\n switch (name) {\r\n case \"is-open\":\r\n if (value == \"true\") {\r\n if (!this.#isOpen) {\r\n this.open();\r\n }\r\n } else {\r\n if (this.#isOpen) {\r\n this.close();\r\n }\r\n }\r\n break;\r\n case \"id\":\r\n this.id = value;\r\n break;\r\n }\r\n }\r\n onBackgroundClick() {\r\n this.dispatchCloseEvent(\"BACKGROUND_CLICK\");\r\n if (this.config.autoCloseOnBackgroundClick) {\r\n this.close();\r\n }\r\n }\r\n dispatchCloseEvent(type:\"BACKGROUND_CLICK\"| \"HISTORY_BACK_EVENT\" | \"CLOSE_BUTTON_CLICK\") {\r\n //we have many ways to dispatch close event like back button on close clicked\r\n const event = new CustomEvent(\"close\", { detail: { eventType: type } });\r\n this.dispatchEvent(event);\r\n }\r\n /**\r\n * @public\r\n * will close modal\r\n */\r\n close() {\r\n this.#isOpen = false;\r\n this.elements.componentWrapper.classList.remove(\"--opened\");\r\n this.elements.componentWrapper.classList.add(\"--closed\");\r\n const history = window.history;\r\n const location = window.location;\r\n if (location.hash == `#${this.id}`) {\r\n history.go(-1);\r\n }\r\n }\r\n /**\r\n * @public\r\n * will open modal\r\n */\r\n open() {\r\n this.#isOpen = true;\r\n this.elements.componentWrapper.classList.remove(\"--closed\");\r\n this.elements.componentWrapper.classList.add(\"--opened\");\r\n if (this.id) {\r\n const history = window.history;\r\n const location = window.location;\r\n if (!(location.hash == `#${this.id}`)) {\r\n history.pushState({ JBModal: {} }, \"\", `#${this.id}`);\r\n }\r\n }\r\n }\r\n #onBrowserBack() {\r\n if (this.isOpen) {\r\n this.dispatchCloseEvent(\"HISTORY_BACK_EVENT\");\r\n if (this.config.autoCloseOnBackgroundClick) {\r\n this.close();\r\n }\r\n }\r\n }\r\n}\r\nconst myElementNotExists = !customElements.get(\"jb-modal\");\r\nif (myElementNotExists) {\r\n window.customElements.define(\"jb-modal\", JBModalWebComponent);\r\n}\r\n"],"names":["JBModalWebComponent","HTMLElement","id","this","getAttribute","__classPrivateFieldGet","_JBModalWebComponent_id","value","__classPrivateFieldSet","checkInitialOpenness","isOpen","_JBModalWebComponent_isOpen","constructor","super","set","config","autoCloseOnBackgroundClick","initWebComponent","connectedCallback","callOnLoadEvent","initProp","callOnInitEvent","event","CustomEvent","bubbles","composed","dispatchEvent","shadowRoot","attachShadow","mode","element","document","createElement","innerHTML","appendChild","content","cloneNode","elements","componentWrapper","querySelector","background","registerEventListener","addEventListener","onBackgroundClick","bind","window","_JBModalWebComponent_instances","_JBModalWebComponent_onBrowserBack","location","hash","triggerUrlOpenEvent","open","observedAttributes","attributeChangedCallback","name","oldValue","newValue","onAttributeChange","close","dispatchCloseEvent","type","detail","eventType","classList","remove","add","history","go","pushState","JBModal","customElements","get","define"],"mappings":"ktBAIM,MAAOA,UAA4BC,YAOvC,MAAIC,GACF,MAAMA,EAAaC,KAAKC,aAAa,OAAS,GAC9C,OAAOC,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WAAYxE"}
|
package/dist/JBModal.umd.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).JBModal={})}(this,(function(n){"use strict";function e(n,e,t,o){if("a"===t&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?n!==e||!o:!e.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===t?o:"a"===t?o.call(n):o?o.value:e.get(n)}function t(n,e,t,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?n!==e||!i:!e.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(n,t):i?i.value=t:e.set(n,t),t}"function"==typeof SuppressedError&&SuppressedError;var o,i,a,s;class d extends HTMLElement{get id(){const n=this.getAttribute("id")||"";return e(this,a,"f")||n}set id(n){t(this,a,n,"f"),this.checkInitialOpenness()}get isOpen(){return e(this,i,"f")}constructor(){super(),o.add(this),i.set(this,!1),a.set(this,""),this.config={autoCloseOnBackgroundClick:!1},this.initWebComponent()}connectedCallback(){this.callOnLoadEvent(),this.initProp(),this.callOnInitEvent()}callOnLoadEvent(){const n=new CustomEvent("load",{bubbles:!0,composed:!0});this.dispatchEvent(n)}callOnInitEvent(){const n=new CustomEvent("init",{bubbles:!0,composed:!0});this.dispatchEvent(n)}initWebComponent(){const n=this.attachShadow({mode:"open"}),e=document.createElement("template");e.innerHTML='<style>.jb-modal-web-component {\n position: fixed;\n top: 0;\n left: 0;\n z-index: var(--jb-modal-z-index, 1);\n width: 100%;\n height: 100%;\n}\n.jb-modal-web-component.--closed {\n display: none;\n}\n@media (min-width: 320px) and (max-width: 767px) {\n .jb-modal-web-component.--closed .modal-content-wrapper {\n transform: translateY(100%);\n }\n}\n.jb-modal-web-component.--opened {\n display: block;\n}\n@media (min-width: 320px) and (max-width: 767px) {\n .jb-modal-web-component.--opened .modal-content-wrapper {\n animation-name: swipe-up;\n animation-duration: 0.3s;\n animation-delay: 0s;\n animation-iteration-count: 1;\n animation-timing-function: ease;\n }\n}\n@keyframes swipe-up {\n 0% {\n transform: translateY(100%);\n }\n 100% {\n transform: translateY(0%);\n }\n}\n.jb-modal-web-component .modal-background {\n position: absolute;\n top: 0;\n left: 0;\n background-color: var(--jb-modal-back-bg-color, rgba(255, 255, 255, 0.1));\n backdrop-filter: blur(10px);\n z-index: 2;\n width: 100%;\n height: 100%;\n}\n.jb-modal-web-component .modal-content-wrapper {\n position: absolute;\n top: 0;\n left: 0;\n z-index: 3;\n width: 100%;\n height: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n pointer-events: none;\n}\n@media (min-width: 320px) and (max-width: 767px) {\n .jb-modal-web-component .modal-content-wrapper {\n bottom: 0;\n top: initial;\n align-items: flex-end;\n }\n}\n.jb-modal-web-component .modal-content-wrapper .modal-content {\n pointer-events: all;\n width: auto;\n height: auto;\n background-color: var(--jb-modal-bg-color, #fff);\n border-radius: var(--jb-modal-border-radius, 24px);\n}\n@media (min-width: 320px) and (max-width: 767px) {\n .jb-modal-web-component .modal-content-wrapper .modal-content {\n width: 100%;\n height: auto;\n max-height: calc(100% - 80px);\n min-height: 32px;\n border-radius: var(--jb-modal-border-radius-mobile, 24px 24px 0 0);\n overflow-y: auto;\n }\n}</style>\n<div class="jb-modal-web-component --closed">\r\n <div class="modal-background"></div>\r\n <div class="modal-content-wrapper">\r\n <div class="modal-content">\r\n <slot name="content"></slot>\r\n </div>\r\n </div>\r\n</div>',n.appendChild(e.content.cloneNode(!0)),this.elements={componentWrapper:n.querySelector(".jb-modal-web-component"),background:n.querySelector(".modal-background")}}registerEventListener(){this.elements.background.addEventListener("click",this.onBackgroundClick.bind(this)),window.addEventListener("popstate",e(this,o,"m",s).bind(this))}initProp(){this.registerEventListener()}checkInitialOpenness(){window.location.hash==`#${this.id}`&&(this.triggerUrlOpenEvent(),this.open())}triggerUrlOpenEvent(){const n=new CustomEvent("urlOpen",{bubbles:!0,composed:!0});this.dispatchEvent(n)}static get observedAttributes(){return["is-open","id"]}attributeChangedCallback(n,e,t){this.onAttributeChange(n,t)}onAttributeChange(n,t){switch(n){case"is-open":"true"==t?e(this,i,"f")||this.open():e(this,i,"f")&&this.close();break;case"id":this.id=t}}onBackgroundClick(){this.dispatchCloseEvent("BACKGROUND_CLICK"),this.config.autoCloseOnBackgroundClick&&this.close()}dispatchCloseEvent(n){const e=new CustomEvent("close",{detail:{eventType:n}});this.dispatchEvent(e)}close(){t(this,i,!1,"f"),this.elements.componentWrapper.classList.remove("--opened"),this.elements.componentWrapper.classList.add("--closed");const n=window.history;window.location.hash==`#${this.id}`&&n.go(-1)}open(){if(t(this,i,!0,"f"),this.elements.componentWrapper.classList.remove("--closed"),this.elements.componentWrapper.classList.add("--opened"),this.id){const n=window.history;window.location.hash!=`#${this.id}`&&n.pushState({JBModal:{}},"",`#${this.id}`)}}}i=new WeakMap,a=new WeakMap,o=new WeakSet,s=function(){this.isOpen&&(this.dispatchCloseEvent("HISTORY_BACK_EVENT"),this.config.autoCloseOnBackgroundClick&&this.close())};!customElements.get("jb-modal")&&window.customElements.define("jb-modal",d),n.JBModalWebComponent=d}));
|
|
2
|
-
//# sourceMappingURL=JBModal.umd.js.map
|
package/dist/JBModal.umd.js.br
DELETED
|
Binary file
|
package/dist/JBModal.umd.js.gz
DELETED
|
Binary file
|
package/dist/JBModal.umd.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JBModal.umd.js","sources":["../lib/JBModal.ts"],"sourcesContent":["import HTML from \"./JBModal.html\";\r\nimport CSS from \"./JBModal.scss\";\r\nimport { ElementsObject } from \"./Types\";\r\n\r\nexport class JBModalWebComponent extends HTMLElement {\r\n #isOpen = false;\r\n #id = \"\";\r\n elements!: ElementsObject;\r\n config = {\r\n autoCloseOnBackgroundClick: false,\r\n };\r\n get id() {\r\n const id: string = this.getAttribute(\"id\") || \"\";\r\n return this.#id || id;\r\n }\r\n set id(value: string) {\r\n this.#id = value;\r\n this.checkInitialOpenness();\r\n }\r\n get isOpen() {\r\n return this.#isOpen;\r\n }\r\n constructor() {\r\n super();\r\n this.initWebComponent();\r\n }\r\n connectedCallback() {\r\n // standard web component event that called when all of dom is binded\r\n this.callOnLoadEvent();\r\n this.initProp();\r\n this.callOnInitEvent();\r\n }\r\n callOnLoadEvent() {\r\n const event = new CustomEvent(\"load\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n callOnInitEvent() {\r\n const event = new CustomEvent(\"init\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n initWebComponent() {\r\n const shadowRoot = this.attachShadow({\r\n mode: \"open\",\r\n });\r\n const html = `<style>${CSS}</style>` + \"\\n\" + HTML;\r\n const element = document.createElement(\"template\");\r\n element.innerHTML = html;\r\n shadowRoot.appendChild(element.content.cloneNode(true));\r\n this.elements = {\r\n componentWrapper: shadowRoot.querySelector(\".jb-modal-web-component\")!,\r\n background: shadowRoot.querySelector(\".modal-background\")!,\r\n };\r\n }\r\n registerEventListener() {\r\n this.elements.background.addEventListener(\r\n \"click\",\r\n this.onBackgroundClick.bind(this)\r\n );\r\n //TODO: remove listener on component unmount\r\n window.addEventListener(\"popstate\", this.#onBrowserBack.bind(this));\r\n }\r\n initProp() {\r\n this.registerEventListener();\r\n }\r\n checkInitialOpenness() {\r\n //if page has modal url we open it automatically\r\n const location = window.location;\r\n if (location.hash == `#${this.id}`) {\r\n this.triggerUrlOpenEvent();\r\n this.open();\r\n }\r\n }\r\n triggerUrlOpenEvent() {\r\n //when modal open itself becuase url contain modal id\r\n const event = new CustomEvent(\"urlOpen\", { bubbles: true, composed: true });\r\n this.dispatchEvent(event);\r\n }\r\n static get observedAttributes() {\r\n return [\"is-open\", \"id\"];\r\n }\r\n attributeChangedCallback(name:string, oldValue:string, newValue:string) {\r\n // do something when an attribute has changed\r\n this.onAttributeChange(name, newValue);\r\n }\r\n onAttributeChange(name:string, value:string) {\r\n switch (name) {\r\n case \"is-open\":\r\n if (value == \"true\") {\r\n if (!this.#isOpen) {\r\n this.open();\r\n }\r\n } else {\r\n if (this.#isOpen) {\r\n this.close();\r\n }\r\n }\r\n break;\r\n case \"id\":\r\n this.id = value;\r\n break;\r\n }\r\n }\r\n onBackgroundClick() {\r\n this.dispatchCloseEvent(\"BACKGROUND_CLICK\");\r\n if (this.config.autoCloseOnBackgroundClick) {\r\n this.close();\r\n }\r\n }\r\n dispatchCloseEvent(type:\"BACKGROUND_CLICK\"| \"HISTORY_BACK_EVENT\" | \"CLOSE_BUTTON_CLICK\") {\r\n //we have many ways to dispatch close event like back button on close clicked\r\n const event = new CustomEvent(\"close\", { detail: { eventType: type } });\r\n this.dispatchEvent(event);\r\n }\r\n /**\r\n * @public\r\n * will close modal\r\n */\r\n close() {\r\n this.#isOpen = false;\r\n this.elements.componentWrapper.classList.remove(\"--opened\");\r\n this.elements.componentWrapper.classList.add(\"--closed\");\r\n const history = window.history;\r\n const location = window.location;\r\n if (location.hash == `#${this.id}`) {\r\n history.go(-1);\r\n }\r\n }\r\n /**\r\n * @public\r\n * will open modal\r\n */\r\n open() {\r\n this.#isOpen = true;\r\n this.elements.componentWrapper.classList.remove(\"--closed\");\r\n this.elements.componentWrapper.classList.add(\"--opened\");\r\n if (this.id) {\r\n const history = window.history;\r\n const location = window.location;\r\n if (!(location.hash == `#${this.id}`)) {\r\n history.pushState({ JBModal: {} }, \"\", `#${this.id}`);\r\n }\r\n }\r\n }\r\n #onBrowserBack() {\r\n if (this.isOpen) {\r\n this.dispatchCloseEvent(\"HISTORY_BACK_EVENT\");\r\n if (this.config.autoCloseOnBackgroundClick) {\r\n this.close();\r\n }\r\n }\r\n }\r\n}\r\nconst myElementNotExists = !customElements.get(\"jb-modal\");\r\nif (myElementNotExists) {\r\n window.customElements.define(\"jb-modal\", JBModalWebComponent);\r\n}\r\n"],"names":["JBModalWebComponent","HTMLElement","id","this","getAttribute","__classPrivateFieldGet","_JBModalWebComponent_id","value","__classPrivateFieldSet","checkInitialOpenness","isOpen","_JBModalWebComponent_isOpen","constructor","super","set","config","autoCloseOnBackgroundClick","initWebComponent","connectedCallback","callOnLoadEvent","initProp","callOnInitEvent","event","CustomEvent","bubbles","composed","dispatchEvent","shadowRoot","attachShadow","mode","element","document","createElement","innerHTML","appendChild","content","cloneNode","elements","componentWrapper","querySelector","background","registerEventListener","addEventListener","onBackgroundClick","bind","window","_JBModalWebComponent_instances","_JBModalWebComponent_onBrowserBack","location","hash","triggerUrlOpenEvent","open","observedAttributes","attributeChangedCallback","name","oldValue","newValue","onAttributeChange","close","dispatchCloseEvent","type","detail","eventType","classList","remove","add","history","go","pushState","JBModal","customElements","get","define"],"mappings":"i8BAIM,MAAOA,UAA4BC,YAOvC,MAAIC,GACF,MAAMA,EAAaC,KAAKC,aAAa,OAAS,GAC9C,OAAOC,EAAAF,KAAQG,EAAA,MAAIJ,CACpB,CACD,MAAIA,CAAGK,GACLC,EAAAL,KAAIG,EAAOC,EAAK,KAChBJ,KAAKM,sBACN,CACD,UAAIC,GACF,OAAOL,EAAAF,KAAIQ,EAAA,IACZ,CACD,WAAAC,GACEC,oBAlBFF,EAAAG,IAAAX,MAAU,GACVG,EAAAQ,IAAAX,KAAM,IAENA,KAAAY,OAAS,CACPC,4BAA4B,GAe5Bb,KAAKc,kBACN,CACD,iBAAAC,GAEEf,KAAKgB,kBACLhB,KAAKiB,WACLjB,KAAKkB,iBACN,CACD,eAAAF,GACE,MAAMG,EAAQ,IAAIC,YAAY,OAAQ,CAAEC,SAAS,EAAMC,UAAU,IACjEtB,KAAKuB,cAAcJ,EACpB,CACD,eAAAD,GACE,MAAMC,EAAQ,IAAIC,YAAY,OAAQ,CAAEC,SAAS,EAAMC,UAAU,IACjEtB,KAAKuB,cAAcJ,EACpB,CACD,gBAAAL,GACE,MAAMU,EAAaxB,KAAKyB,aAAa,C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