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