UNPKG

@ahmiao666/ahmiao-react-dialog-element

Version:
12 lines (11 loc) 10.5 kB
import e from"react";import{AnimatePresence as t,motion as r}from"motion/react";import{createPortal as o}from"react-dom";var n,i={exports:{}},l={};var s,a={}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */"production"===process.env.NODE_ENV?i.exports=function(){if(n)return l;n=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function r(t,r,o){var n=null;if(void 0!==o&&(n=""+o),void 0!==r.key&&(n=""+r.key),"key"in r)for(var i in o={},r)"key"!==i&&(o[i]=r[i]);else o=r;return r=o.ref,{$$typeof:e,type:t,key:n,ref:void 0!==r?r:null,props:o}}return l.Fragment=t,l.jsx=r,l.jsxs=r,l}():i.exports=(s||(s=1,"production"!==process.env.NODE_ENV&&function(){function t(e){if(null==e)return null;if("function"==typeof e)return e.$$typeof===_?null:e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case p:return"Fragment";case b:return"Profiler";case m:return"StrictMode";case j:return"Suspense";case S:return"SuspenseList";case x:return"Activity"}if("object"==typeof e)switch("number"==typeof e.tag&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case y:return"Portal";case h:return(e.displayName||"Context")+".Provider";case v:return(e._context.displayName||"Context")+".Consumer";case g:var r=e.render;return(e=e.displayName)||(e=""!==(e=r.displayName||r.name||"")?"ForwardRef("+e+")":"ForwardRef"),e;case k:return null!==(r=e.displayName||null)?r:t(e.type)||"Memo";case w:r=e._payload,e=e._init;try{return t(e(r))}catch(e){}}return null}function r(e){return""+e}function o(e){try{r(e);var t=!1}catch(e){t=!0}if(t){var o=(t=console).error,n="function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return o.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",n),r(e)}}function n(e){if(e===p)return"<>";if("object"==typeof e&&null!==e&&e.$$typeof===w)return"<...>";try{var r=t(e);return r?"<"+r+">":"<...>"}catch(e){return"<...>"}}function i(){return Error("react-stack-top-frame")}function l(){var e=t(this.type);return R[e]||(R[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),void 0!==(e=this.props.ref)?e:null}function s(e,r,n,i,s,a,f,y){var p,m=r.children;if(void 0!==m)if(i)if(C(m)){for(i=0;i<m.length;i++)c(m[i]);Object.freeze&&Object.freeze(m)}else console.error("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 c(m);if(O.call(r,"key")){m=t(e);var b=Object.keys(r).filter(function(e){return"key"!==e});i=0<b.length?"{key: someKey, "+b.join(": ..., ")+": ...}":"{key: someKey}",P[m+i]||(b=0<b.length?"{"+b.join(": ..., ")+": ...}":"{}",console.error('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',i,m,b,m),P[m+i]=!0)}if(m=null,void 0!==n&&(o(n),m=""+n),function(e){if(O.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(r)&&(o(r.key),m=""+r.key),"key"in r)for(var v in n={},r)"key"!==v&&(n[v]=r[v]);else n=r;return m&&function(e,t){function r(){u||(u=!0,console.error("%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://react.dev/link/special-props)",t))}r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}(n,"function"==typeof e?e.displayName||e.name||"Unknown":e),function(e,t,r,o,n,i,s,a){return r=i.ref,e={$$typeof:d,type:e,key:t,props:i,_owner:n},null!==(void 0!==r?r:null)?Object.defineProperty(e,"ref",{enumerable:!1,get:l}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:s}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(e,m,a,0,null===(p=N.A)?null:p.getOwner(),n,f,y)}function c(e){"object"==typeof e&&null!==e&&e.$$typeof===d&&e._store&&(e._store.validated=1)}var u,f=e,d=Symbol.for("react.transitional.element"),y=Symbol.for("react.portal"),p=Symbol.for("react.fragment"),m=Symbol.for("react.strict_mode"),b=Symbol.for("react.profiler"),v=Symbol.for("react.consumer"),h=Symbol.for("react.context"),g=Symbol.for("react.forward_ref"),j=Symbol.for("react.suspense"),S=Symbol.for("react.suspense_list"),k=Symbol.for("react.memo"),w=Symbol.for("react.lazy"),x=Symbol.for("react.activity"),_=Symbol.for("react.client.reference"),N=f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,O=Object.prototype.hasOwnProperty,C=Array.isArray,E=console.createTask?console.createTask:function(){return null},R={},A=(f={react_stack_bottom_frame:function(e){return e()}}).react_stack_bottom_frame.bind(f,i)(),T=E(n(i)),P={};a.Fragment=p,a.jsx=function(e,t,r,o,i){var l=1e4>N.recentlyCreatedOwnerStacks++;return s(e,t,r,!1,0,i,l?Error("react-stack-top-frame"):A,l?E(n(e)):T)},a.jsxs=function(e,t,r,o,i){var l=1e4>N.recentlyCreatedOwnerStacks++;return s(e,t,r,!0,0,i,l?Error("react-stack-top-frame"):A,l?E(n(e)):T)}}()),a);var c=i.exports;function u(e){const{open:n,width:i="40vw",title:l="",showIcon:s=!0,showClose:a=!0,onCancel:u,children:f,icon:d,style:y}=e,p="number"==typeof i?`${Math.min(i,100)}vw`:i,m={x:"-50%",y:"-50%"};return o(c.jsx(t,{children:n&&c.jsxs(r.div,{className:"dialog-custom",style:{width:p,position:"fixed",top:"50%",left:"50%",zIndex:2007,...y},initial:{opacity:0,scale:.3,...m},animate:{opacity:1,scale:1,...m},exit:{opacity:0,scale:.3,...m},transition:{duration:.3},children:[(l||s||a)&&c.jsxs("div",{className:"dialog-custom-title",children:[c.jsxs("div",{className:"left",children:[s&&c.jsx("div",{className:"dialog-title-icon",children:d||"📣"}),c.jsx("span",{children:l})]}),c.jsx("div",{className:"right",children:a&&c.jsx("div",{className:"dialog-close-icon",onClick:u,role:"button","aria-label":"关闭弹窗",children:"✕"})})]}),c.jsx("div",{className:"dialog-custom-content",children:f})]})}),document.body)}let f=new Map;const d=new Set;function y(){return f}function p(e){return d.add(e),()=>d.delete(e)}function m(){d.forEach(e=>e())}const b="default";class v{static lockScroll(){if(this.openCount++,1===this.openCount){this.originalStyles={overflow:document.body.style.overflow,paddingRight:document.body.style.paddingRight};const e=function(){const e=document.createElement("div");e.style.visibility="hidden",e.style.overflow="scroll",e.style.msOverflowStyle="scrollbar",document.body.appendChild(e);const t=document.createElement("div");e.appendChild(t);const r=e.offsetWidth-t.offsetWidth;return document.body.removeChild(e),r}();document.body.style.overflow="hidden",document.body.style.paddingRight=`${e}px`}}static unlockScroll(){this.openCount=Math.max(0,this.openCount-1),0===this.openCount&&this.originalStyles&&(document.body.style.overflow=this.originalStyles.overflow,document.body.style.paddingRight=this.originalStyles.paddingRight,this.originalStyles=null)}}function h(e){const t=f,r=t.get(e);if(r)return r;const o={visible:!1,options:null,resolve:void 0,reject:void 0},n=new Map(t);return n.set(e,o),f=n,m(),o}function g(e,t){const r=f,o=r.get(e);if(o){const n=new Map(r);n.set(e,{...o,...t}),f=n,m()}}function j(e){const t=e.familyName||b;return new Promise((r,o)=>{h(t),v.lockScroll();const n=(e,n=!1)=>{g(t,{visible:!1}),setTimeout(()=>{v.unlockScroll(),g(t,{options:null,resolve:void 0,reject:void 0}),n?o(new Error("弹窗被取消")):r(e)},300)};g(t,{visible:!0,options:{...e,familyName:t},resolve:e=>n(e,!1),reject:()=>n(null,!0)})})}v.originalStyles=null,v.openCount=0;const S={open:(e,t)=>j({component:e,...t}),openWithFamily:(e,t,r)=>j({component:t,familyName:e,...r}),close:(e=b)=>{const t=h(e);t.visible&&t.reject?.()},closeAll:()=>{f.forEach(e=>{e.visible&&e.reject?.()})},getStates:()=>f,hasOpenDialog:e=>{const t=f;if(e){const r=t.get(e);return r?.visible??!1}return Array.from(t.values()).some(e=>e.visible)}};function k(t){return e.useSyncExternalStore(p,()=>t(y()),()=>t(y()))}function w(){return k(e=>Array.from(e.values()).some(e=>e.visible))}function x(e){return k(t=>!0===t.get(e)?.visible)}function _(){return f}function N(e){const t=()=>Array.from(f.values()).some(e=>e.visible);let r=t();e(r);const o=p(()=>{const o=t();o!==r&&(r=o,e(o))});return()=>o()}const O=j;function C(){const n=e.useSyncExternalStore(p,y,y),i=Array.from(n.values()).some(e=>e.visible),l=Array.from(n.entries()).filter(([e,t])=>t.visible&&t.options),s=l.length>0?l[l.length-1]:void 0,a=s?.[1].options?.maskBg;return c.jsxs(c.Fragment,{children:[o(c.jsx(t,{children:i&&c.jsx(r.div,{className:"global-dialog-mask",onClick:()=>{for(let e=l.length-1;e>=0;e--){const[t,r]=l[e],{maskClosable:o=!0}=r.options;if(o){r.reject?.();break}}},initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.3},style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:a??"rgba(0, 0, 0, 0.4)",zIndex:2006,display:"flex",alignItems:"center",justifyContent:"center"}})}),document.body),Array.from(n.entries()).map(([e,t])=>{if(!t.options)return null;const{component:r,...o}=t.options;return c.jsx(u,{open:t.visible,title:o.title,width:o.width,showIcon:o.showIcon,showClose:o.showClose,onCancel:t.reject,icon:o.icon,style:o.style,children:c.jsx(r,{...o.props||{},onClose:t.resolve,onNext:o.onNext||o.props?.onNext})},e)})]})}export{u as DialogCustom,C as DialogCustomProvider,S as DialogCustomStaticMethods,O as default,_ as getDialogFrozenSnapshot,j as openDialogCustom,N as subscribeHasOpen,O as useDialogCustom,k as useDialogSelector,x as useFamilyVisible,w as useHasOpenDialog}; //# sourceMappingURL=index.esm.js.map