jb-modal 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +48 -2
  2. package/dist/JBModal.cjs.js +2 -0
  3. package/dist/JBModal.cjs.js.br +0 -0
  4. package/dist/JBModal.cjs.js.gz +0 -0
  5. package/dist/JBModal.cjs.js.map +1 -0
  6. package/dist/JBModal.js +1 -185
  7. package/dist/JBModal.js.br +0 -0
  8. package/dist/JBModal.js.gz +0 -0
  9. package/dist/JBModal.js.map +1 -1
  10. package/dist/JBModal.umd.js +1 -195
  11. package/dist/JBModal.umd.js.br +0 -0
  12. package/dist/JBModal.umd.js.gz +0 -0
  13. package/dist/JBModal.umd.js.map +1 -1
  14. package/dist/{JBModal.d.ts → web-component/jb-modal/lib/JBModal.d.ts} +7 -7
  15. package/index.js +1 -1
  16. package/lib/JBModal.scss +2 -2
  17. package/lib/JBModal.ts +148 -150
  18. package/package.json +5 -3
  19. package/react/LICENSE +21 -0
  20. package/react/README.md +82 -0
  21. package/react/dist/JBModal.cjs.js +67 -0
  22. package/react/dist/JBModal.cjs.js.map +1 -0
  23. package/react/dist/JBModal.js +65 -0
  24. package/react/dist/JBModal.js.map +1 -0
  25. package/react/dist/JBModal.umd.js +70 -0
  26. package/react/dist/JBModal.umd.js.map +1 -0
  27. package/react/dist/common/hooks/use-event.d.ts +3 -0
  28. package/react/dist/common/hooks/useLazyRef.d.ts +4 -0
  29. package/react/dist/common/hooks/useMobx.d.ts +4 -0
  30. package/react/dist/common/scripts/device-detection.d.ts +1 -0
  31. package/react/dist/common/scripts/persian-helper.d.ts +3 -0
  32. package/react/dist/web-component/jb-modal/react/lib/JBModal.d.ts +30 -0
  33. package/react/index.js +1 -0
  34. package/react/lib/JBModal.tsx +80 -0
  35. package/react/package.json +38 -0
  36. package/react/tsconfig.json +18 -0
  37. package/lib/global.d.ts +0 -11
  38. /package/dist/{Types.d.ts → web-component/jb-modal/lib/Types.d.ts} +0 -0
package/README.md CHANGED
@@ -1,14 +1,25 @@
1
1
  # jb-modal
2
+ [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/jb-modal)
3
+ [![GitHub license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://raw.githubusercontent.com/javadbat/jb-modal/main/LICENSE)
4
+ [![NPM Downloads](https://img.shields.io/npm/dw/jb-modal)](https://www.npmjs.com/package/jb-modal)
5
+
2
6
  modal web component with features:
3
7
 
4
- - customizable content
8
+ - framework free so you can use it anywhere
9
+ - customizable content & style
5
10
  - support typescript
6
11
  - auto close on background click
7
- - you can add custom route history in browser so back button can close modal and refresh (when modal is open) is open modal again
12
+ - you can add custom route history in browser
13
+ - back button handler to just close the modal instead of real back
14
+ - keep modal open in case of page refresh (by just provide an id)
8
15
 
9
16
  Demo & Sample
10
17
  in github: <https://javadbat.github.io/jb-modal/>
11
18
 
19
+ ## using with JS frameworks
20
+
21
+ to use this component in **react** see [`jb-modal/react`](https://github.com/javadbat/jb-modal/tree/main/react);
22
+
12
23
  ## install
13
24
 
14
25
  ```cmd
@@ -25,6 +36,33 @@ npm i jb-modal
25
36
  ```js
26
37
  document.querySelector('jb-modal').config.autoCloseOnBackgroundClick = true;
27
38
  ```
39
+
40
+ ## keep modal state
41
+
42
+ if you want your modal to keep open when user refresh the page or you want capture back button in mobile when modal is open you just need to provide an `id` attribute.
43
+
44
+ ```html
45
+ <jb-modal is-open="true" id="Something">
46
+ </jb-modal>
47
+ ```
48
+ ## events
49
+
50
+ ```js
51
+ //when web-component load and you can access modal logic
52
+ document.querySelector('jb-modal').addEventListener("load",(e)=>{/*your function*/});
53
+ // when modal load and initiated completely
54
+ document.querySelector('jb-modal').addEventListener("init",(e)=>{/*your function*/});
55
+ // when page refresh and modal open by default because of url
56
+ document.querySelector('jb-modal').addEventListener("urlOpen",(e)=>{/*your function*/});
57
+ // when modal closed
58
+ document.querySelector('jb-modal').addEventListener("close",(e)=>{
59
+ // could be "BACKGROUND_CLICK" "HISTORY_BACK_EVENT" "CLOSE_BUTTON_CLICK"
60
+ const closeType = e.detail.eventType
61
+ /*your function*/
62
+ });
63
+
64
+ ```
65
+
28
66
  ## customize modal look
29
67
 
30
68
  you can customize modal look by following css properties
@@ -34,3 +72,11 @@ you can customize modal look by following css properties
34
72
  | --jb-modal-back-bg-color | modal back background color |
35
73
  | --jb-modal-border-radius | modal border-radius default `24px` |
36
74
  | --jb-modal-border-radius-mobile | modal border-radius on mobile default is `24px 24px 0 0` |
75
+
76
+ ## Other Related Docs:
77
+
78
+ - see [`jb-modal/react`](https://github.com/javadbat/jb-modal/tree/main/react); if you want to use this component in react
79
+
80
+ - see [All JB Design system Component List](https://github.com/javadbat/design-system/blob/main/docs/component-list.md) for more components
81
+
82
+ - use [Contribution Guide](https://github.com/javadbat/design-system/blob/main/docs/contribution-guide.md) if you want to contribute in this component.
@@ -0,0 +1,2 @@
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
Binary file
Binary file
@@ -0,0 +1 @@
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,kBACLh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ACD,iBAAAoC,GACExC,KAAKwD,mBAAmB,oBACpBxD,KAAKY,OAAOC,4BACdb,KAAKuD,OAER,CACD,kBAAAC,CAAmBC,GAEjB,MAAMtC,EAAQ,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 CHANGED
@@ -1,186 +1,2 @@
1
- /******************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
-
16
- function __classPrivateFieldGet(receiver, state, kind, f) {
17
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
18
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
- }
21
-
22
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
23
- if (kind === "m") throw new TypeError("Private method is not writable");
24
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
25
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
26
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
27
- }
28
-
29
- var HTML = "<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>";
30
-
31
- var css_248z = ".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 .jb-modal-web-component.--closed {\n display: none; }\n @media (min-width: 320px) and (max-width: 767px) {\n .jb-modal-web-component.--closed .modal-content-wrapper {\n transform: translateY(100%); } }\n .jb-modal-web-component.--opened {\n display: block; }\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@keyframes swipe-up {\n 0% {\n transform: translateY(100%); }\n 100% {\n transform: translateY(0%); } }\n .jb-modal-web-component .modal-background {\n position: absolute;\n top: 0;\n left: 0;\n background-color: var(jb-modal-bg-color, rgba(255, 255, 255, 0.1));\n backdrop-filter: blur(10px);\n z-index: 2;\n width: 100%;\n height: 100%; }\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 @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 .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 @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";
32
-
33
- var _JBModalWebComponent_instances, _JBModalWebComponent_isOpen, _JBModalWebComponent_id, _JBModalWebComponent_onBrowserBack;
34
- class JBModalWebComponent extends HTMLElement {
35
- get id() {
36
- const id = this.getAttribute('id') || "";
37
- return __classPrivateFieldGet(this, _JBModalWebComponent_id, "f") || id;
38
- }
39
- set id(value) {
40
- __classPrivateFieldSet(this, _JBModalWebComponent_id, value, "f");
41
- this.checkInitialOpenness();
42
- }
43
- get isOpen() {
44
- return __classPrivateFieldGet(this, _JBModalWebComponent_isOpen, "f");
45
- }
46
- constructor() {
47
- super();
48
- _JBModalWebComponent_instances.add(this);
49
- _JBModalWebComponent_isOpen.set(this, false);
50
- _JBModalWebComponent_id.set(this, "");
51
- this.config = {
52
- autoCloseOnBackgroundClick: false
53
- };
54
- this.initWebComponent();
55
- }
56
- connectedCallback() {
57
- // standard web component event that called when all of dom is binded
58
- this.callOnLoadEvent();
59
- this.initProp();
60
- this.callOnInitEvent();
61
- }
62
- callOnLoadEvent() {
63
- const event = new CustomEvent('load', { bubbles: true, composed: true });
64
- this.dispatchEvent(event);
65
- }
66
- callOnInitEvent() {
67
- const event = new CustomEvent('init', { bubbles: true, composed: true });
68
- this.dispatchEvent(event);
69
- }
70
- initWebComponent() {
71
- const shadowRoot = this.attachShadow({
72
- mode: 'open'
73
- });
74
- const html = `<style>${css_248z}</style>` + '\n' + HTML;
75
- const element = document.createElement('template');
76
- element.innerHTML = html;
77
- shadowRoot.appendChild(element.content.cloneNode(true));
78
- this.elements = {
79
- componentWrapper: shadowRoot.querySelector('.jb-modal-web-component'),
80
- background: shadowRoot.querySelector('.modal-background'),
81
- };
82
- }
83
- registerEventListener() {
84
- this.elements.background.addEventListener('click', this.onBackgroundClick.bind(this));
85
- //TODO: remove listener on component unmount
86
- window.addEventListener('popstate', __classPrivateFieldGet(this, _JBModalWebComponent_instances, "m", _JBModalWebComponent_onBrowserBack).bind(this));
87
- }
88
- initProp() {
89
- this.registerEventListener();
90
- }
91
- checkInitialOpenness() {
92
- //if page has modal url we open it automatically
93
- const location = window.location;
94
- if (location.hash == `#${this.id}`) {
95
- this.triggerUrlOpenEvent();
96
- this.open();
97
- }
98
- }
99
- triggerUrlOpenEvent() {
100
- //when modal open itself becuase url contain modal id
101
- const event = new CustomEvent('urlOpen', { bubbles: true, composed: true });
102
- this.dispatchEvent(event);
103
- }
104
- static get observedAttributes() {
105
- return ['is-open', 'id'];
106
- }
107
- attributeChangedCallback(name, oldValue, newValue) {
108
- // do something when an attribute has changed
109
- this.onAttributeChange(name, newValue);
110
- }
111
- onAttributeChange(name, value) {
112
- switch (name) {
113
- case 'is-open':
114
- if (value == 'true') {
115
- if (!__classPrivateFieldGet(this, _JBModalWebComponent_isOpen, "f")) {
116
- this.open();
117
- }
118
- }
119
- else {
120
- if (__classPrivateFieldGet(this, _JBModalWebComponent_isOpen, "f")) {
121
- this.close();
122
- }
123
- }
124
- break;
125
- case 'id':
126
- this.id = value;
127
- break;
128
- }
129
- }
130
- onBackgroundClick() {
131
- this.dispatchCloseEvent('BACKGROUND_CLICK');
132
- if (this.config.autoCloseOnBackgroundClick) {
133
- this.close();
134
- }
135
- }
136
- dispatchCloseEvent(type) {
137
- //we have many ways to dispatch close event like back button on close clicked
138
- const event = new CustomEvent("close", { detail: { eventType: type } });
139
- this.dispatchEvent(event);
140
- }
141
- /**
142
- * @public
143
- * will close modal
144
- */
145
- close() {
146
- __classPrivateFieldSet(this, _JBModalWebComponent_isOpen, false, "f");
147
- this.elements.componentWrapper.classList.remove('--opened');
148
- this.elements.componentWrapper.classList.add('--closed');
149
- const history = window.history;
150
- const location = window.location;
151
- if (location.hash == `#${this.id}`) {
152
- history.go(-1);
153
- }
154
- }
155
- /**
156
- * @public
157
- * will open modal
158
- */
159
- open() {
160
- __classPrivateFieldSet(this, _JBModalWebComponent_isOpen, true, "f");
161
- this.elements.componentWrapper.classList.remove('--closed');
162
- this.elements.componentWrapper.classList.add('--opened');
163
- if (this.id) {
164
- const history = window.history;
165
- const location = window.location;
166
- if (!(location.hash == `#${this.id}`)) {
167
- history.pushState({ JBModal: {} }, "", `#${this.id}`);
168
- }
169
- }
170
- }
171
- }
172
- _JBModalWebComponent_isOpen = new WeakMap(), _JBModalWebComponent_id = new WeakMap(), _JBModalWebComponent_instances = new WeakSet(), _JBModalWebComponent_onBrowserBack = function _JBModalWebComponent_onBrowserBack(e) {
173
- if (this.isOpen) {
174
- this.dispatchCloseEvent('HISTORY_BACK_EVENT');
175
- if (this.config.autoCloseOnBackgroundClick) {
176
- this.close();
177
- }
178
- }
179
- };
180
- const myElementNotExists = !customElements.get('jb-modal');
181
- if (myElementNotExists) {
182
- window.customElements.define('jb-modal', JBModalWebComponent);
183
- }
184
-
185
- export { JBModalWebComponent };
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};
186
2
  //# sourceMappingURL=JBModal.js.map
Binary file
Binary file
@@ -1 +1 @@
1
- {"version":3,"file":"JBModal.js","sources":["../../../node_modules/tslib/tslib.es6.js","../lib/JBModal.ts"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.push(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.push(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n","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 }\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 }\r\n registerEventListener() {\r\n this.elements.background.addEventListener('click', this.onBackgroundClick.bind(this));\r\n //TODO: remove listener on component unmount\r\n window.addEventListener('popstate', this.#onBrowserBack.bind(this));\r\n }\r\n initProp() {\r\n \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, oldValue, newValue) {\r\n // do something when an attribute has changed\r\n this.onAttributeChange(name, newValue);\r\n }\r\n onAttributeChange(name, value) {\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 }\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 }\r\n dispatchCloseEvent(type) {\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(e) {\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":["CSS"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAsQA;AACO,SAAS,sBAAsB,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE;AACjE,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,CAAC,EAAE,MAAM,IAAI,SAAS,CAAC,+CAA+C,CAAC,CAAC;AACjG,IAAI,IAAI,OAAO,KAAK,KAAK,UAAU,GAAG,QAAQ,KAAK,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,SAAS,CAAC,0EAA0E,CAAC,CAAC;AACvL,IAAI,OAAO,IAAI,KAAK,GAAG,GAAG,CAAC,GAAG,IAAI,KAAK,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,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oB,CAAC,CAAC;AAC9C,QAAA,IAAI,IAAI,CAAC,MAAM,CAAC,0BAA0B,EAAE;YACxC,IAAI,CAAC,KAAK,EAAE,CAAC;AAChB,SAAA;AACJ,KAAA;AACL,CAAC,CAAA;AAEL,MAAM,kBAAkB,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC3D,IAAI,kBAAkB,EAAE;IACpB,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;AACjE;;;;"}
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,EAAAF,KAAQG,EAAA,MAAIJ,CACpB,CACD,M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ory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JBModal = {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- /******************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
-
22
- function __classPrivateFieldGet(receiver, state, kind, f) {
23
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
24
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
25
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
26
- }
27
-
28
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
29
- if (kind === "m") throw new TypeError("Private method is not writable");
30
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
31
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
32
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
33
- }
34
-
35
- var HTML = "<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>";
36
-
37
- var css_248z = ".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 .jb-modal-web-component.--closed {\n display: none; }\n @media (min-width: 320px) and (max-width: 767px) {\n .jb-modal-web-component.--closed .modal-content-wrapper {\n transform: translateY(100%); } }\n .jb-modal-web-component.--opened {\n display: block; }\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@keyframes swipe-up {\n 0% {\n transform: translateY(100%); }\n 100% {\n transform: translateY(0%); } }\n .jb-modal-web-component .modal-background {\n position: absolute;\n top: 0;\n left: 0;\n background-color: var(jb-modal-bg-color, rgba(255, 255, 255, 0.1));\n backdrop-filter: blur(10px);\n z-index: 2;\n width: 100%;\n height: 100%; }\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 @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 .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 @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";
38
-
39
- var _JBModalWebComponent_instances, _JBModalWebComponent_isOpen, _JBModalWebComponent_id, _JBModalWebComponent_onBrowserBack;
40
- class JBModalWebComponent extends HTMLElement {
41
- get id() {
42
- const id = this.getAttribute('id') || "";
43
- return __classPrivateFieldGet(this, _JBModalWebComponent_id, "f") || id;
44
- }
45
- set id(value) {
46
- __classPrivateFieldSet(this, _JBModalWebComponent_id, value, "f");
47
- this.checkInitialOpenness();
48
- }
49
- get isOpen() {
50
- return __classPrivateFieldGet(this, _JBModalWebComponent_isOpen, "f");
51
- }
52
- constructor() {
53
- super();
54
- _JBModalWebComponent_instances.add(this);
55
- _JBModalWebComponent_isOpen.set(this, false);
56
- _JBModalWebComponent_id.set(this, "");
57
- this.config = {
58
- autoCloseOnBackgroundClick: false
59
- };
60
- this.initWebComponent();
61
- }
62
- connectedCallback() {
63
- // standard web component event that called when all of dom is binded
64
- this.callOnLoadEvent();
65
- this.initProp();
66
- this.callOnInitEvent();
67
- }
68
- callOnLoadEvent() {
69
- const event = new CustomEvent('load', { bubbles: true, composed: true });
70
- this.dispatchEvent(event);
71
- }
72
- callOnInitEvent() {
73
- const event = new CustomEvent('init', { bubbles: true, composed: true });
74
- this.dispatchEvent(event);
75
- }
76
- initWebComponent() {
77
- const shadowRoot = this.attachShadow({
78
- mode: 'open'
79
- });
80
- const html = `<style>${css_248z}</style>` + '\n' + HTML;
81
- const element = document.createElement('template');
82
- element.innerHTML = html;
83
- shadowRoot.appendChild(element.content.cloneNode(true));
84
- this.elements = {
85
- componentWrapper: shadowRoot.querySelector('.jb-modal-web-component'),
86
- background: shadowRoot.querySelector('.modal-background'),
87
- };
88
- }
89
- registerEventListener() {
90
- this.elements.background.addEventListener('click', this.onBackgroundClick.bind(this));
91
- //TODO: remove listener on component unmount
92
- window.addEventListener('popstate', __classPrivateFieldGet(this, _JBModalWebComponent_instances, "m", _JBModalWebComponent_onBrowserBack).bind(this));
93
- }
94
- initProp() {
95
- this.registerEventListener();
96
- }
97
- checkInitialOpenness() {
98
- //if page has modal url we open it automatically
99
- const location = window.location;
100
- if (location.hash == `#${this.id}`) {
101
- this.triggerUrlOpenEvent();
102
- this.open();
103
- }
104
- }
105
- triggerUrlOpenEvent() {
106
- //when modal open itself becuase url contain modal id
107
- const event = new CustomEvent('urlOpen', { bubbles: true, composed: true });
108
- this.dispatchEvent(event);
109
- }
110
- static get observedAttributes() {
111
- return ['is-open', 'id'];
112
- }
113
- attributeChangedCallback(name, oldValue, newValue) {
114
- // do something when an attribute has changed
115
- this.onAttributeChange(name, newValue);
116
- }
117
- onAttributeChange(name, value) {
118
- switch (name) {
119
- case 'is-open':
120
- if (value == 'true') {
121
- if (!__classPrivateFieldGet(this, _JBModalWebComponent_isOpen, "f")) {
122
- this.open();
123
- }
124
- }
125
- else {
126
- if (__classPrivateFieldGet(this, _JBModalWebComponent_isOpen, "f")) {
127
- this.close();
128
- }
129
- }
130
- break;
131
- case 'id':
132
- this.id = value;
133
- break;
134
- }
135
- }
136
- onBackgroundClick() {
137
- this.dispatchCloseEvent('BACKGROUND_CLICK');
138
- if (this.config.autoCloseOnBackgroundClick) {
139
- this.close();
140
- }
141
- }
142
- dispatchCloseEvent(type) {
143
- //we have many ways to dispatch close event like back button on close clicked
144
- const event = new CustomEvent("close", { detail: { eventType: type } });
145
- this.dispatchEvent(event);
146
- }
147
- /**
148
- * @public
149
- * will close modal
150
- */
151
- close() {
152
- __classPrivateFieldSet(this, _JBModalWebComponent_isOpen, false, "f");
153
- this.elements.componentWrapper.classList.remove('--opened');
154
- this.elements.componentWrapper.classList.add('--closed');
155
- const history = window.history;
156
- const location = window.location;
157
- if (location.hash == `#${this.id}`) {
158
- history.go(-1);
159
- }
160
- }
161
- /**
162
- * @public
163
- * will open modal
164
- */
165
- open() {
166
- __classPrivateFieldSet(this, _JBModalWebComponent_isOpen, true, "f");
167
- this.elements.componentWrapper.classList.remove('--closed');
168
- this.elements.componentWrapper.classList.add('--opened');
169
- if (this.id) {
170
- const history = window.history;
171
- const location = window.location;
172
- if (!(location.hash == `#${this.id}`)) {
173
- history.pushState({ JBModal: {} }, "", `#${this.id}`);
174
- }
175
- }
176
- }
177
- }
178
- _JBModalWebComponent_isOpen = new WeakMap(), _JBModalWebComponent_id = new WeakMap(), _JBModalWebComponent_instances = new WeakSet(), _JBModalWebComponent_onBrowserBack = function _JBModalWebComponent_onBrowserBack(e) {
179
- if (this.isOpen) {
180
- this.dispatchCloseEvent('HISTORY_BACK_EVENT');
181
- if (this.config.autoCloseOnBackgroundClick) {
182
- this.close();
183
- }
184
- }
185
- };
186
- const myElementNotExists = !customElements.get('jb-modal');
187
- if (myElementNotExists) {
188
- window.customElements.define('jb-modal', JBModalWebComponent);
189
- }
190
-
191
- exports.JBModalWebComponent = JBModalWebComponent;
192
-
193
- Object.defineProperty(exports, '__esModule', { value: true });
194
-
195
- }));
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}));
196
2
  //# sourceMappingURL=JBModal.umd.js.map
Binary file
Binary file