react-async-alert-confirm
Version:
A reusable React component library for alert dialog and confirm dialog
32 lines (29 loc) • 18.6 kB
JavaScript
(function(){"use strict";try{if(typeof document<"u"){var a=document.createElement("style");a.appendChild(document.createTextNode("._modal-overlay_pac0m_1{position:fixed;width:100vw;height:100vh;background-color:#00000080;display:flex;align-items:center;justify-content:center;inset:0;z-index:20;opacity:0}._modal-container_pac0m_14{padding:12px 64px;background-color:#fff;box-shadow:2px 2px 30px 10px #ffffff1a;border-radius:8px;display:flex;flex-direction:column;align-items:center;justify-content:center;max-width:600px;box-sizing:border-box}@media (max-width: 768px){._modal-container_pac0m_14{width:calc(100% - 32px);max-width:calc(100% - 32px);padding:24px}}._modal-title_pac0m_36{display:flex;font-size:16px;color:#000;font-weight:700;align-items:center;justify-content:center}._modal-content_pac0m_45{font-size:16px;margin-top:20px;color:#000;text-align:center;display:flex;flex-direction:column;align-items:center;justify-content:center}._modal-actions_pac0m_56{width:100%;display:flex;justify-content:space-around;margin-top:24px;gap:16px}@media (max-width: 768px){._modal-actions_pac0m_56{gap:8px}}._modal-button_pac0m_69{padding:8px 24px;cursor:pointer;display:flex;align-items:center;justify-content:center;width:136px;margin-top:20px;border-radius:8px;font-size:14px;color:#fff;background-color:#000}._modal-button-cancel_pac0m_82{background-color:#0000004d}@keyframes _board_show_pac0m_1{0%{opacity:0;transform:scale(.5)}to{opacity:1;transform:scale(1)}}@keyframes _overlay_show_pac0m_1{0%{opacity:0}to{opacity:1}}@keyframes _board_hide_pac0m_1{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.5)}}@keyframes _overlay_hide_pac0m_1{0%{opacity:1}to{opacity:0}}._overlay-show_pac0m_134{animation:_overlay_show_pac0m_1 .3s forwards}._overlay-hide_pac0m_137{animation:_overlay_hide_pac0m_1 .3s forwards}._container-show_pac0m_140{animation:_board_show_pac0m_1 .3s forwards}._container-hide_pac0m_143{animation:_board_hide_pac0m_1 .3s forwards}")),document.head.appendChild(a)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})();
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("react"),Se=require("react-dom/client");var B={exports:{}},N={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var Oe;function vr(){if(Oe)return N;Oe=1;var E=W,R=Symbol.for("react.element"),w=Symbol.for("react.fragment"),y=Object.prototype.hasOwnProperty,b=E.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,T={key:!0,ref:!0,__self:!0,__source:!0};function v(d,u,O){var m,C={},x=null,L=null;O!==void 0&&(x=""+O),u.key!==void 0&&(x=""+u.key),u.ref!==void 0&&(L=u.ref);for(m in u)y.call(u,m)&&!T.hasOwnProperty(m)&&(C[m]=u[m]);if(d&&d.defaultProps)for(m in u=d.defaultProps,u)C[m]===void 0&&(C[m]=u[m]);return{$$typeof:R,type:d,key:x,ref:L,props:C,_owner:b.current}}return N.Fragment=w,N.jsx=v,N.jsxs=v,N}var Y={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var Ce;function mr(){return Ce||(Ce=1,process.env.NODE_ENV!=="production"&&function(){var E=W,R=Symbol.for("react.element"),w=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),b=Symbol.for("react.strict_mode"),T=Symbol.for("react.profiler"),v=Symbol.for("react.provider"),d=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),O=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),C=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),L=Symbol.for("react.offscreen"),ee=Symbol.iterator,Pe="@@iterator";function ke(e){if(e===null||typeof e!="object")return null;var r=ee&&e[ee]||e[Pe];return typeof r=="function"?r:null}var $=E.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function p(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];$e("error",e,t)}}function $e(e,r,t){{var n=$.ReactDebugCurrentFrame,i=n.getStackAddendum();i!==""&&(r+="%s",t=t.concat([i]));var c=t.map(function(o){return String(o)});c.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,c)}}var De=!1,Ae=!1,Fe=!1,Ie=!1,Ne=!1,re;re=Symbol.for("react.module.reference");function Ye(e){return!!(typeof e=="string"||typeof e=="function"||e===y||e===T||Ne||e===b||e===O||e===m||Ie||e===L||De||Ae||Fe||typeof e=="object"&&e!==null&&(e.$$typeof===x||e.$$typeof===C||e.$$typeof===v||e.$$typeof===d||e.$$typeof===u||e.$$typeof===re||e.getModuleId!==void 0))}function We(e,r,t){var n=e.displayName;if(n)return n;var i=r.displayName||r.name||"";return i!==""?t+"("+i+")":t}function te(e){return e.displayName||"Context"}function S(e){if(e==null)return null;if(typeof e.tag=="number"&&p("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case y:return"Fragment";case w:return"Portal";case T:return"Profiler";case b:return"StrictMode";case O:return"Suspense";case m:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case d:var r=e;return te(r)+".Consumer";case v:var t=e;return te(t._context)+".Provider";case u:return We(e,e.render,"ForwardRef");case C:var n=e.displayName||null;return n!==null?n:S(e.type)||"Memo";case x:{var i=e,c=i._payload,o=i._init;try{return S(o(c))}catch{return null}}}return null}var P=Object.assign,F=0,ne,ae,oe,ie,ce,se,le;function ue(){}ue.__reactDisabledLog=!0;function Le(){{if(F===0){ne=console.log,ae=console.info,oe=console.warn,ie=console.error,ce=console.group,se=console.groupCollapsed,le=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ue,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}F++}}function Me(){{if(F--,F===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:P({},e,{value:ne}),info:P({},e,{value:ae}),warn:P({},e,{value:oe}),error:P({},e,{value:ie}),group:P({},e,{value:ce}),groupCollapsed:P({},e,{value:se}),groupEnd:P({},e,{value:le})})}F<0&&p("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var J=$.ReactCurrentDispatcher,K;function M(e,r,t){{if(K===void 0)try{throw Error()}catch(i){var n=i.stack.trim().match(/\n( *(at )?)/);K=n&&n[1]||""}return`
`+K+e}}var G=!1,V;{var Ve=typeof WeakMap=="function"?WeakMap:Map;V=new Ve}function fe(e,r){if(!e||G)return"";{var t=V.get(e);if(t!==void 0)return t}var n;G=!0;var i=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var c;c=J.current,J.current=null,Le();try{if(r){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(o,[])}catch(g){n=g}Reflect.construct(e,[],o)}else{try{o.call()}catch(g){n=g}e.call(o.prototype)}}else{try{throw Error()}catch(g){n=g}e()}}catch(g){if(g&&n&&typeof g.stack=="string"){for(var a=g.stack.split(`
`),_=n.stack.split(`
`),l=a.length-1,f=_.length-1;l>=1&&f>=0&&a[l]!==_[f];)f--;for(;l>=1&&f>=0;l--,f--)if(a[l]!==_[f]){if(l!==1||f!==1)do if(l--,f--,f<0||a[l]!==_[f]){var j=`
`+a[l].replace(" at new "," at ");return e.displayName&&j.includes("<anonymous>")&&(j=j.replace("<anonymous>",e.displayName)),typeof e=="function"&&V.set(e,j),j}while(l>=1&&f>=0);break}}}finally{G=!1,J.current=c,Me(),Error.prepareStackTrace=i}var A=e?e.displayName||e.name:"",k=A?M(A):"";return typeof e=="function"&&V.set(e,k),k}function Ue(e,r,t){return fe(e,!1)}function qe(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function U(e,r,t){if(e==null)return"";if(typeof e=="function")return fe(e,qe(e));if(typeof e=="string")return M(e);switch(e){case O:return M("Suspense");case m:return M("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case u:return Ue(e.render);case C:return U(e.type,r,t);case x:{var n=e,i=n._payload,c=n._init;try{return U(c(i),r,t)}catch{}}}return""}var I=Object.prototype.hasOwnProperty,de={},ve=$.ReactDebugCurrentFrame;function q(e){if(e){var r=e._owner,t=U(e.type,e._source,r?r.type:null);ve.setExtraStackFrame(t)}else ve.setExtraStackFrame(null)}function Be(e,r,t,n,i){{var c=Function.call.bind(I);for(var o in e)if(c(e,o)){var a=void 0;try{if(typeof e[o]!="function"){var _=Error((n||"React class")+": "+t+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw _.name="Invariant Violation",_}a=e[o](r,o,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(l){a=l}a&&!(a instanceof Error)&&(q(i),p("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,o,typeof a),q(null)),a instanceof Error&&!(a.message in de)&&(de[a.message]=!0,q(i),p("Failed %s type: %s",t,a.message),q(null))}}}var Je=Array.isArray;function z(e){return Je(e)}function Ke(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function Ge(e){try{return me(e),!1}catch{return!0}}function me(e){return""+e}function pe(e){if(Ge(e))return p("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ke(e)),me(e)}var _e=$.ReactCurrentOwner,ze={key:!0,ref:!0,__self:!0,__source:!0},he,ye;function Xe(e){if(I.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function He(e){if(I.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function Ze(e,r){typeof e.ref=="string"&&_e.current}function Qe(e,r){{var t=function(){he||(he=!0,p("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function er(e,r){{var t=function(){ye||(ye=!0,p("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var rr=function(e,r,t,n,i,c,o){var a={$$typeof:R,type:e,key:r,ref:t,props:o,_owner:c};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function tr(e,r,t,n,i){{var c,o={},a=null,_=null;t!==void 0&&(pe(t),a=""+t),He(r)&&(pe(r.key),a=""+r.key),Xe(r)&&(_=r.ref,Ze(r,i));for(c in r)I.call(r,c)&&!ze.hasOwnProperty(c)&&(o[c]=r[c]);if(e&&e.defaultProps){var l=e.defaultProps;for(c in l)o[c]===void 0&&(o[c]=l[c])}if(a||_){var f=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&Qe(o,f),_&&er(o,f)}return rr(e,a,_,i,n,_e.current,o)}}var X=$.ReactCurrentOwner,be=$.ReactDebugCurrentFrame;function D(e){if(e){var r=e._owner,t=U(e.type,e._source,r?r.type:null);be.setExtraStackFrame(t)}else be.setExtraStackFrame(null)}var H;H=!1;function Z(e){return typeof e=="object"&&e!==null&&e.$$typeof===R}function ge(){{if(X.current){var e=S(X.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function nr(e){return""}var Ee={};function ar(e){{var r=ge();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
Check the top-level render call using <`+t+">.")}return r}}function Re(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=ar(r);if(Ee[t])return;Ee[t]=!0;var n="";e&&e._owner&&e._owner!==X.current&&(n=" It was passed a child from "+S(e._owner.type)+"."),D(e),p('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),D(null)}}function Te(e,r){{if(typeof e!="object")return;if(z(e))for(var t=0;t<e.length;t++){var n=e[t];Z(n)&&Re(n,r)}else if(Z(e))e._store&&(e._store.validated=!0);else if(e){var i=ke(e);if(typeof i=="function"&&i!==e.entries)for(var c=i.call(e),o;!(o=c.next()).done;)Z(o.value)&&Re(o.value,r)}}}function or(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===u||r.$$typeof===C))t=r.propTypes;else return;if(t){var n=S(r);Be(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!H){H=!0;var i=S(r);p("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",i||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&p("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ir(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){D(e),p("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),D(null);break}}e.ref!==null&&(D(e),p("Invalid attribute `ref` supplied to `React.Fragment`."),D(null))}}var je={};function we(e,r,t,n,i,c){{var o=Ye(e);if(!o){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var _=nr();_?a+=_:a+=ge();var l;e===null?l="null":z(e)?l="array":e!==void 0&&e.$$typeof===R?(l="<"+(S(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):l=typeof e,p("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",l,a)}var f=tr(e,r,t,i,c);if(f==null)return f;if(o){var j=r.children;if(j!==void 0)if(n)if(z(j)){for(var A=0;A<j.length;A++)Te(j[A],e);Object.freeze&&Object.freeze(j)}else p("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Te(j,e)}if(I.call(r,"key")){var k=S(e),g=Object.keys(r).filter(function(dr){return dr!=="key"}),Q=g.length>0?"{key: someKey, "+g.join(": ..., ")+": ...}":"{key: someKey}";if(!je[k+Q]){var fr=g.length>0?"{"+g.join(": ..., ")+": ...}":"{}";p(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,Q,k,fr,k),je[k+Q]=!0}}return e===y?ir(f):or(f),f}}function cr(e,r,t){return we(e,r,t,!0)}function sr(e,r,t){return we(e,r,t,!1)}var lr=sr,ur=cr;Y.Fragment=y,Y.jsx=lr,Y.jsxs=ur}()),Y}var xe;function pr(){return xe||(xe=1,process.env.NODE_ENV==="production"?B.exports=vr():B.exports=mr()),B.exports}var h=pr();const s={"modal-overlay":"_modal-overlay_pac0m_1","modal-container":"_modal-container_pac0m_14","modal-title":"_modal-title_pac0m_36","modal-content":"_modal-content_pac0m_45","modal-actions":"_modal-actions_pac0m_56","modal-button":"_modal-button_pac0m_69","modal-button-cancel":"_modal-button-cancel_pac0m_82","overlay-show":"_overlay-show_pac0m_134","overlay-hide":"_overlay-hide_pac0m_137","container-show":"_container-show_pac0m_140","container-hide":"_container-hide_pac0m_143"},_r=({title:E="",content:R="",yes:w=()=>{},confirm_text:y="Okay"})=>{const[b,T]=W.useState(!1),v=()=>{T(!0)};return h.jsx("div",{className:`${s["modal-overlay"]} ${b?s["overlay-hide"]:s["overlay-show"]} react-aac-overlay`,children:h.jsxs("div",{onAnimationEnd:d=>{d.stopPropagation(),b&&w()},className:`${s["modal-container"]} ${b?s["container-hide"]:s["container-show"]} react-aac-container`,children:[!!E&&h.jsx("div",{className:`${s["modal-title"]} react-aac-title`,children:E}),h.jsx("div",{className:`${s["modal-content"]} react-aac-content`,children:R}),h.jsx("div",{className:`${s["modal-actions"]} react-aac-actions`,children:h.jsx("div",{className:`${s["modal-button"]} react-aac-btn`,onClick:v,children:y})})]})})},hr=async({title:E="",content:R="I am an alert content",confirm_text:w="Okay",node_name:y="confirm-and-alert"})=>new Promise(b=>{const T=document.getElementById(y),v=Se.createRoot(T),d=()=>{v.unmount(),b(!0)};v.render(h.jsx(_r,{title:E,content:R,confirm_text:w,yes:d}))}),yr=({title:E="I am a confirm title",content:R="I am a confirm content",yes:w=()=>{},no:y=()=>{},confirm_text:b="Confirm",cancel_text:T="Cancel"})=>{const[v,d]=W.useState(!1),[u,O]=W.useState(""),m=()=>{d(!0),O("yes")},C=()=>{d(!0),O("no")};return h.jsx("div",{className:`${s["modal-overlay"]} ${v?s["overlay-hide"]:s["overlay-show"]} react-aac-overlay`,children:h.jsxs("div",{onAnimationEnd:x=>{x.stopPropagation(),u==="no"&&y(),u==="yes"&&w()},className:`${s["modal-container"]} ${v?s["container-hide"]:s["container-show"]} react-aac-container`,children:[!!E&&h.jsx("div",{className:`${s["modal-title"]} react-aac-title`,children:E}),h.jsx("div",{className:`${s["modal-content"]} react-aac-content`,children:R}),h.jsxs("div",{className:`${s["modal-actions"]} react-aac-actions`,children:[h.jsx("div",{className:`${s["modal-button"]} ${s["modal-button-cancel"]} react-aac-cancel-button`,onClick:C,children:T}),h.jsx("div",{className:`${s["modal-button"]} react-aac-confirm-button`,onClick:m,children:b})]})]})})},br=async({title:E="I am a confirm title",content:R="I am a confirm content",cancel_text:w="Cancel",confirm_text:y="Confirm",node_name:b="confirm-and-alert"})=>new Promise(T=>{const v=document.getElementById(b),d=Se.createRoot(v),u=()=>{d.unmount(),T(!1)},O=()=>{d.unmount(),T(!0)};d.render(h.jsx(yr,{title:E,content:R,cancel_text:w,confirm_text:y,no:u,yes:O}))});exports.app_alert=hr;exports.app_confirm=br;