Files
vanillajs-seed/node_modules/pnotify/dist/es/PNotifyConfirm.js
2019-12-20 20:02:44 +01:00

2 lines
12 KiB
JavaScript

import PNotify from"./PNotify.js";function data(){return Object.assign({_notice:null,_options:{}},PNotify.modules.Confirm.defaults)}var methods={initModule(t){this.set(t)},afterOpen(){if(this.get().prompt&&!1!==this.get().focus)this.get().promptMultiLine?this.refs.promptMulti.focus():this.refs.promptSingle.focus();else if(this.get().confirm&&(!0===this.get().focus||null===this.get().focus&&this.get()._options.stack.modal)){const t=this.get().buttons;if(t.length){let e=t.length-1;for(;e>=0&&!t[e].promptTrigger;)e--;this.refs.buttons.children[e].focus()}}},handleClick(t,e){t.click&&t.click(this.get()._notice,this.get().prompt?this.get().promptValue:null,e)},handleKeyPress(t){if(13===t.keyCode&&!t.shiftKey){t.preventDefault();const{buttons:e}=this.get();for(let n=0;n<e.length;n++)e[n].promptTrigger&&e[n].click&&e[n].click(this.get()._notice,this.get().prompt?this.get().promptValue:null,t)}}};function oncreate(){this.fire("init",{module:this})}function setup(t){t.key="Confirm",t.defaults={confirm:!1,prompt:!1,promptClass:"",promptValue:"",promptMultiLine:!1,focus:null,align:"flex-end",buttons:[{text:"Ok",textTrusted:!1,addClass:"",primary:!0,promptTrigger:!0,click:(t,e)=>{t.close(),t.fire("pnotify.confirm",{notice:t,value:e})}},{text:"Cancel",textTrusted:!1,addClass:"",click:t=>{t.close(),t.fire("pnotify.cancel",{notice:t})}}]},PNotify.modules.Confirm=t,PNotify.modulesAppendContainer.push(t),Object.assign(PNotify.styling.brighttheme,{actionBar:"",promptBar:"",btn:"",btnPrimary:"brighttheme-primary",input:""}),Object.assign(PNotify.styling.bootstrap3,{actionBar:"ui-pnotify-confirm-ml",promptBar:"ui-pnotify-confirm-ml",btn:"btn btn-default ui-pnotify-confirm-mx-1",btnPrimary:"btn btn-default ui-pnotify-confirm-mx-1 btn-primary",input:"form-control"}),Object.assign(PNotify.styling.bootstrap4,{actionBar:"ui-pnotify-confirm-ml",promptBar:"ui-pnotify-confirm-ml",btn:"btn btn-secondary mx-1",btnPrimary:"btn btn-primary mx-1",input:"form-control"}),PNotify.styling.material||(PNotify.styling.material={}),Object.assign(PNotify.styling.material,{actionBar:"",promptBar:"",btn:"",btnPrimary:"ui-pnotify-material-primary",input:""})}function add_css(){var t=createElement("style");t.id="svelte-1y9suua-style",t.textContent=".ui-pnotify-action-bar.svelte-1y9suua,.ui-pnotify-prompt-bar.svelte-1y9suua{margin-top:5px;clear:both}.ui-pnotify-action-bar.svelte-1y9suua{display:flex;flex-wrap:wrap;justify-content:flex-end}.ui-pnotify-prompt-input.svelte-1y9suua{margin-bottom:5px;display:block;width:100%}.ui-pnotify-confirm-mx-1.svelte-1y9suua{margin:0 5px}.ui-pnotify.ui-pnotify-with-icon .ui-pnotify-confirm-ml.svelte-1y9suua{margin-left:24px}[dir=rtl] .ui-pnotify.ui-pnotify-with-icon .ui-pnotify-confirm-ml.svelte-1y9suua{margin-right:24px;margin-left:0}",append(document.head,t)}function click_handler(t){const{component:e,ctx:n}=this._svelte;e.handleClick(n.button,t)}function get_each_context(t,e,n){const i=Object.create(t);return i.button=e[n],i}function create_main_fragment(t,e){var n,i=(e.confirm||e.prompt)&&create_if_block(t,e);return{c(){i&&i.c(),n=createComment()},m(t,e){i&&i.m(t,e),insert(t,n,e)},p(e,o){o.confirm||o.prompt?i?i.p(e,o):((i=create_if_block(t,o)).c(),i.m(n.parentNode,n)):i&&(i.d(1),i=null)},d(t){i&&i.d(t),t&&detachNode(n)}}}function create_if_block(t,e){for(var n,i,o,s,r=e.prompt&&create_if_block_2(t,e),a=e.buttons,c=[],l=0;l<a.length;l+=1)c[l]=create_each_block(t,get_each_context(e,a,l));return{c(){n=createElement("div"),r&&r.c(),i=createText("\n "),o=createElement("div");for(var t=0;t<c.length;t+=1)c[t].c();o.className=s="\n ui-pnotify-action-bar\n "+(e._notice.get()._styles.actionBar?e._notice.get()._styles.actionBar:"")+"\n "+(e._notice.get()._styles.text?e._notice.get()._styles.text:"")+"\n svelte-1y9suua",setStyle(o,"justify-content",e.align),n.className="ui-pnotify-confirm"},m(e,s){insert(e,n,s),r&&r.m(n,null),append(n,i),append(n,o);for(var a=0;a<c.length;a+=1)c[a].m(o,null);t.refs.buttons=o},p(e,l){if(l.prompt?r?r.p(e,l):((r=create_if_block_2(t,l)).c(),r.m(n,i)):r&&(r.d(1),r=null),e.buttons||e._notice){a=l.buttons;for(var u=0;u<a.length;u+=1){const n=get_each_context(l,a,u);c[u]?c[u].p(e,n):(c[u]=create_each_block(t,n),c[u].c(),c[u].m(o,null))}for(;u<c.length;u+=1)c[u].d(1);c.length=a.length}e._notice&&s!==(s="\n ui-pnotify-action-bar\n "+(l._notice.get()._styles.actionBar?l._notice.get()._styles.actionBar:"")+"\n "+(l._notice.get()._styles.text?l._notice.get()._styles.text:"")+"\n svelte-1y9suua")&&(o.className=s),e.align&&setStyle(o,"justify-content",l.align)},d(e){e&&detachNode(n),r&&r.d(),destroyEach(c,e),t.refs.buttons===o&&(t.refs.buttons=null)}}}function create_if_block_2(t,e){var n,i;function o(t){return t.promptMultiLine?create_if_block_3:create_else_block_1}var s=o(e),r=s(t,e);return{c(){n=createElement("div"),r.c(),n.className=i="\n ui-pnotify-prompt-bar\n "+(e._notice.get()._styles.promptBar?e._notice.get()._styles.promptBar:"")+"\n "+(e._notice.get()._styles.text?e._notice.get()._styles.text:"")+"\n svelte-1y9suua"},m(t,e){insert(t,n,e),r.m(n,null)},p(e,a){s===(s=o(a))&&r?r.p(e,a):(r.d(1),(r=s(t,a)).c(),r.m(n,null)),e._notice&&i!==(i="\n ui-pnotify-prompt-bar\n "+(a._notice.get()._styles.promptBar?a._notice.get()._styles.promptBar:"")+"\n "+(a._notice.get()._styles.text?a._notice.get()._styles.text:"")+"\n svelte-1y9suua")&&(n.className=i)},d(t){t&&detachNode(n),r.d()}}}function create_else_block_1(t,e){var n,i,o=!1;function s(){o=!0,t.set({promptValue:n.value}),o=!1}function r(e){t.handleKeyPress(e)}return{c(){addListener(n=createElement("input"),"input",s),addListener(n,"keypress",r),setAttribute(n,"type","text"),n.className=i="\n ui-pnotify-prompt-input\n "+(e._notice.get()._styles.input?e._notice.get()._styles.input:"")+"\n "+e.promptClass+"\n svelte-1y9suua"},m(i,o){insert(i,n,o),t.refs.promptSingle=n,n.value=e.promptValue},p(t,e){!o&&t.promptValue&&(n.value=e.promptValue),(t._notice||t.promptClass)&&i!==(i="\n ui-pnotify-prompt-input\n "+(e._notice.get()._styles.input?e._notice.get()._styles.input:"")+"\n "+e.promptClass+"\n svelte-1y9suua")&&(n.className=i)},d(e){e&&detachNode(n),removeListener(n,"input",s),removeListener(n,"keypress",r),t.refs.promptSingle===n&&(t.refs.promptSingle=null)}}}function create_if_block_3(t,e){var n,i,o=!1;function s(){o=!0,t.set({promptValue:n.value}),o=!1}function r(e){t.handleKeyPress(e)}return{c(){addListener(n=createElement("textarea"),"input",s),addListener(n,"keypress",r),n.rows="5",n.className=i="\n ui-pnotify-prompt-input\n "+(e._notice.get()._styles.input?e._notice.get()._styles.input:"")+"\n "+e.promptClass+"\n svelte-1y9suua"},m(i,o){insert(i,n,o),t.refs.promptMulti=n,n.value=e.promptValue},p(t,e){!o&&t.promptValue&&(n.value=e.promptValue),(t._notice||t.promptClass)&&i!==(i="\n ui-pnotify-prompt-input\n "+(e._notice.get()._styles.input?e._notice.get()._styles.input:"")+"\n "+e.promptClass+"\n svelte-1y9suua")&&(n.className=i)},d(e){e&&detachNode(n),removeListener(n,"input",s),removeListener(n,"keypress",r),t.refs.promptMulti===n&&(t.refs.promptMulti=null)}}}function create_else_block(t,e){var n,i=e.button.text;return{c(){n=createText(i)},m(t,e){insert(t,n,e)},p(t,e){t.buttons&&i!==(i=e.button.text)&&setData(n,i)},d(t){t&&detachNode(n)}}}function create_if_block_1(t,e){var n,i,o=e.button.text;return{c(){n=createElement("noscript"),i=createElement("noscript")},m(t,e){insert(t,n,e),n.insertAdjacentHTML("afterend",o),insert(t,i,e)},p(t,e){t.buttons&&o!==(o=e.button.text)&&(detachBetween(n,i),n.insertAdjacentHTML("afterend",o))},d(t){t&&(detachBetween(n,i),detachNode(n),detachNode(i))}}}function create_each_block(t,e){var n,i;function o(t){return t.button.textTrusted?create_if_block_1:create_else_block}var s=o(e),r=s(t,e);return{c(){n=createElement("button"),r.c(),n._svelte={component:t,ctx:e},addListener(n,"click",click_handler),n.type="button",n.className=i="\n ui-pnotify-action-button\n "+(e.button.primary?e._notice.get()._styles.btnPrimary?e._notice.get()._styles.btnPrimary:"":e._notice.get()._styles.btn?e._notice.get()._styles.btn:"")+"\n "+(e.button.addClass?e.button.addClass:"")+"\n svelte-1y9suua"},m(t,e){insert(t,n,e),r.m(n,null)},p(a,c){s===(s=o(e=c))&&r?r.p(a,e):(r.d(1),(r=s(t,e)).c(),r.m(n,null)),n._svelte.ctx=e,(a.buttons||a._notice)&&i!==(i="\n ui-pnotify-action-button\n "+(e.button.primary?e._notice.get()._styles.btnPrimary?e._notice.get()._styles.btnPrimary:"":e._notice.get()._styles.btn?e._notice.get()._styles.btn:"")+"\n "+(e.button.addClass?e.button.addClass:"")+"\n svelte-1y9suua")&&(n.className=i)},d(t){t&&detachNode(n),r.d(),removeListener(n,"click",click_handler)}}}function PNotifyConfirm(t){init(this,t),this.refs={},this._state=assign(data(),t.data),this._intro=!0,document.getElementById("svelte-1y9suua-style")||add_css(),this._fragment=create_main_fragment(this,this._state),this.root._oncreate.push(()=>{oncreate.call(this),this.fire("update",{changed:assignTrue({},this._state),current:this._state})}),t.target&&(this._fragment.c(),this._mount(t.target,t.anchor),flush(this))}function createElement(t){return document.createElement(t)}function append(t,e){t.appendChild(e)}function createComment(){return document.createComment("")}function insert(t,e,n){t.insertBefore(e,n)}function detachNode(t){t.parentNode.removeChild(t)}function createText(t){return document.createTextNode(t)}function setStyle(t,e,n){t.style.setProperty(e,n)}function destroyEach(t,e){for(var n=0;n<t.length;n+=1)t[n]&&t[n].d(e)}function addListener(t,e,n,i){t.addEventListener(e,n,i)}function setAttribute(t,e,n){null==n?t.removeAttribute(e):t.setAttribute(e,n)}function removeListener(t,e,n,i){t.removeEventListener(e,n,i)}function setData(t,e){t.data=""+e}function detachBetween(t,e){for(;t.nextSibling&&t.nextSibling!==e;)t.parentNode.removeChild(t.nextSibling)}function init(t,e){t._handlers=blankObject(),t._slots=blankObject(),t._bind=e._bind,t._staged={},t.options=e,t.root=e.root||t,t.store=e.store||t.root.store,e.root||(t._beforecreate=[],t._oncreate=[],t._aftercreate=[])}function assign(t,e){for(var n in e)t[n]=e[n];return t}function assignTrue(t,e){for(var n in e)t[n]=1;return t}function flush(t){t._lock=!0,callAll(t._beforecreate),callAll(t._oncreate),callAll(t._aftercreate),t._lock=!1}function destroy(t){this.destroy=noop,this.fire("destroy"),this.set=noop,this._fragment.d(!1!==t),this._fragment=null,this._state={}}function get(){return this._state}function fire(t,e){var n=t in this._handlers&&this._handlers[t].slice();if(n)for(var i=0;i<n.length;i+=1){var o=n[i];if(!o.__calling)try{o.__calling=!0,o.call(this,e)}finally{o.__calling=!1}}}function on(t,e){var n=this._handlers[t]||(this._handlers[t]=[]);return n.push(e),{cancel:function(){var t=n.indexOf(e);~t&&n.splice(t,1)}}}function set(t){this._set(assign({},t)),this.root._lock||flush(this.root)}function _set(t){var e=this._state,n={},i=!1;for(var o in t=assign(this._staged,t),this._staged={},t)this._differs(t[o],e[o])&&(n[o]=i=!0);i&&(this._state=assign(assign({},e),t),this._recompute(n,this._state),this._bind&&this._bind(n,this._state),this._fragment&&(this.fire("state",{changed:n,current:this._state,previous:e}),this._fragment.p(n,this._state),this.fire("update",{changed:n,current:this._state,previous:e})))}function _stage(t){assign(this._staged,t)}function _mount(t,e){this._fragment[this._fragment.i?"i":"m"](t,e||null)}function _differs(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function noop(){}function blankObject(){return Object.create(null)}function callAll(t){for(;t&&t.length;)t.shift()()}assign(PNotifyConfirm.prototype,{destroy:destroy,get:get,fire:fire,on:on,set:set,_set:_set,_stage:_stage,_mount:_mount,_differs:_differs}),assign(PNotifyConfirm.prototype,methods),PNotifyConfirm.prototype._recompute=noop,setup(PNotifyConfirm);export default PNotifyConfirm;
//# sourceMappingURL=PNotifyConfirm.js.map