UNPKG

@wener/ui

Version:

3 lines (2 loc) 17 kB
import e,{useState as t,useEffect as n,useRef as r,useContext as o,useReducer as i}from"react";import{loadStyles as u}from"@wener/utils";import{Menu as a,Layout as c}from"antd";import{BehaviorSubject as l}from"rxjs";import"lodash";function f(e){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function p(){return(p=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function d(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function y(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?d(Object(n),!0).forEach((function(t){s(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):d(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function h(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function m(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],r=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return n}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return v(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return v(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function b(e){var t=null!=e?e:{},n=t.theme,r=t.type,o=t.url,i=void 0===o?"":o,a="data-".concat(r,"-theme"),c=document.querySelector("link[".concat(a,'="').concat(n,'"]'));return c?(document.querySelectorAll("link[".concat(a,"]:not([").concat(a,'="').concat(n,'"])')).forEach((function(e){return e.setAttribute("disabled","true")})),c.removeAttribute("disabled"),!0):!!i&&(console.info("load theme ".concat(r," ").concat(n," ").concat(i)),u(i,{attributes:s({},a,n)}).then((function(){return document.querySelectorAll("link[".concat(a,"]:not([").concat(a,'="').concat(n,'"])')).forEach((function(e){return e.setAttribute("disabled","true")})),!0})))}var g={light:"https://unpkg.com/antd/dist/antd.min.css",dark:"https://unpkg.com/antd/dist/antd.dark.min.css"};function O(e){var t=e||{},n=t.theme,r=void 0===n?"light":n,o=t.src||g[r];return o?b({theme:r,type:"antd",url:o}):(console.error("Theme not found: ".concat(r)),!1)}function P(e){var r=e||{},o=r.theme,i=void 0===o?"light":o,u=r.src,a=m(t(!0),2),c=a[0],l=a[1];return n((function(){var e=u||g[i];e?(l(!0),Promise.resolve(b({theme:i,type:"antd",url:e})).finally((function(){return l(!1)}))):console.error("Theme not found: ".concat(i))}),[i,u]),c}function E(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];if("production"!==process.env.NODE_ENV){var o=ue[e],i=o?"function"==typeof o?o.apply(null,n):o:"unknown error nr: "+e;throw Error("[Immer] "+i)}throw Error("[Immer] minified error nr: "+e+(n.length?" "+n.join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function j(e){return!!e&&!!e[ie]}function w(e){return!!e&&(function(e){if(!e||"object"!=f(e))return!1;var t=Object.getPrototypeOf(e);return!t||t===Object.prototype}(e)||Array.isArray(e)||!!e[oe]||!!e.constructor[oe]||N(e)||x(e))}function S(e,t,n){void 0===n&&(n=!1),0===A(e)?(n?Object.keys:ae)(e).forEach((function(n){return t(n,e[n],e)})):e.forEach((function(n,r){return t(r,n,e)}))}function A(e){var t=e[ie];return t?t.i>3?t.i-4:t.i:Array.isArray(e)?1:N(e)?2:x(e)?3:0}function k(e,t){return 2===A(e)?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function D(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function N(e){return ee&&e instanceof Map}function x(e){return te&&e instanceof Set}function I(e){return e.o||e.t}function _(e,t){if(void 0===t&&(t=!1),Array.isArray(e))return e.slice();var n=Object.create(Object.getPrototypeOf(e));return S(e,(function(r){if(r!==ie){var o=Object.getOwnPropertyDescriptor(e,r),i=o.value;o.get&&(t||E(1),i=o.get.call(e)),o.enumerable?n[r]=i:Object.defineProperty(n,r,{value:i,writable:!0,configurable:!0})}})),n}function C(e,t){j(e)||z(e)||!w(e)||(A(e)>1&&(e.set=e.add=e.clear=e.delete=F),Object.freeze(e),t&&S(e,(function(e,t){return C(t,!0)}),!0))}function F(){E(2)}function z(e){return null==e||"object"!=f(e)||Object.isFrozen(e)}function R(e){var t=ce[e];return t||E("production"!==process.env.NODE_ENV?18:19,e),t}function T(){return"production"===process.env.NODE_ENV||Q||E(0),Q}function V(e,t){t&&(R("Patches"),e.u=[],e.s=[],e.v=t)}function H(e){M(e),e.p.forEach(U),e.p=null}function M(e){e===Q&&(Q=e.l)}function W(e){return Q={p:[],l:Q,h:e,m:!0,_:0}}function U(e){var t=e[ie];0===t.i||1===t.i?t.j():t.O=!0}function K(e,t){t._=t.p.length;var n=t.p[0],r=void 0!==e&&e!==n;return t.h.g||R("ES5").S(t,e,r),r?(n[ie].P&&(H(t),E(4)),w(e)&&(e=q(t,e),t.l||$(t,e)),t.u&&R("Patches").M(n[ie],e,t.u,t.s)):e=q(t,n,[]),H(t),t.u&&t.v(t.u,t.s),e!==re?e:void 0}function q(e,t,n){if(z(t))return t;var r=t[ie];if(!r)return S(t,(function(o,i){return B(e,r,t,o,i,n)}),!0),t;if(r.A!==e)return t;if(!r.P)return $(e,r.t,!0),r.t;if(!r.I){r.I=!0,r.A._--;var o=4===r.i||5===r.i?r.o=_(r.k,!0):r.o;S(o,(function(t,i){return B(e,r,o,t,i,n)})),$(e,o,!1),n&&e.u&&R("Patches").R(r,n,e.u,e.s)}return r.o}function B(e,t,n,r,o,i){if("production"!==process.env.NODE_ENV&&o===n&&E(5),j(o)){var u=q(e,o,i&&t&&3!==t.i&&!k(t.D,r)?i.concat(r):void 0);if(c=r,l=u,2===(f=A(a=n))?a.set(c,l):3===f?(a.delete(c),a.add(l)):a[c]=l,!j(u))return;e.m=!1}var a,c,l,f;if((!t||!D(o,function(e,t){return 2===A(e)?e.get(t):e[t]}(t.t,r)))&&w(o)){if(!e.h.N&&e._<1)return;q(e,o),t&&t.A.l||$(e,o)}}function $(e,t,n){void 0===n&&(n=!1),e.h.N&&e.m&&C(t,n)}function Y(e,t){var n=e[ie],r=Reflect.getOwnPropertyDescriptor(n?I(n):e,t);return r&&r.value}function J(e){if(!e.P){if(e.P=!0,0===e.i||1===e.i){var t=e.o=_(e.t);S(e.p,(function(e,n){t[e]=n})),e.p=void 0}e.l&&J(e.l)}}function L(e){e.o||(e.o=_(e.t))}function X(e,t,n){var r=N(t)?R("MapSet").T(t,n):x(t)?R("MapSet").F(t,n):e.g?function(e,t){var n=Array.isArray(e),r={i:n?1:0,A:t?t.A:T(),P:!1,I:!1,D:{},l:t,t:e,k:null,p:{},o:null,j:null,C:!1},o=r,i=le;n&&(o=[r],i=fe);var u=Proxy.revocable(o,i),a=u.revoke,c=u.proxy;return r.k=c,r.j=a,c}(t,n):R("ES5").J(t,n);return(n?n.A:T()).p.push(r),r}var G,Q,Z="undefined"!=typeof Symbol&&"symbol"==f(Symbol("x")),ee="undefined"!=typeof Map,te="undefined"!=typeof Set,ne="undefined"!=typeof Proxy&&void 0!==Proxy.revocable&&"undefined"!=typeof Reflect,re=Z?Symbol("immer-nothing"):((G={})["immer-nothing"]=!0,G),oe=Z?Symbol("immer-draftable"):"__$immer_draftable",ie=Z?Symbol("immer-state"):"__$immer_state",ue={0:"Illegal state",1:"Immer drafts cannot have computed properties",2:"This object has been frozen and should not be mutated",3:function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},4:"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",5:"Immer forbids circular references",6:"The first or second argument to `produce` must be a function",7:"The third argument to `produce` must be a function or undefined",8:"First argument to `createDraft` must be a plain object, an array, or an immerable object",9:"First argument to `finishDraft` must be a draft returned by `createDraft`",10:"The given draft is already finalized",11:"Object.defineProperty() cannot be used on an Immer draft",12:"Object.setPrototypeOf() cannot be used on an Immer draft",13:"Immer only supports deleting array indices",14:"Immer only supports setting array indices and the 'length' property",15:function(e){return"Cannot apply patch, path doesn't resolve: "+e},16:'Sets cannot have "replace" patches.',17:function(e){return"Unsupported patch operation: "+e},18:function(e){return"The plugin for '"+e+"' has not been loaded into Immer. To enable the plugin, import and call `enable"+e+"()` when initializing your application."},19:function(e){return"plugin not loaded: "+e},20:"Cannot use proxies if Proxy, Proxy.revocable or Reflect are not available"},ae="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames,ce={},le={get:function(e,t){if(t===ie)return e;var n=e.p;if(!e.P&&k(n,t))return n[t];var r=I(e)[t];if(e.I||!w(r))return r;if(e.P){if(r!==Y(e.t,t))return r;n=e.o}return n[t]=X(e.A.h,r,e)},has:function(e,t){return t in I(e)},ownKeys:function(e){return Reflect.ownKeys(I(e))},set:function(e,t,n){if(!e.P){var r=Y(e.t,t);if(n?D(r,n)||n===e.p[t]:D(r,n)&&t in e.t)return!0;L(e),J(e)}return e.D[t]=!0,e.o[t]=n,!0},deleteProperty:function(e,t){return void 0!==Y(e.t,t)||t in e.t?(e.D[t]=!1,L(e),J(e)):e.D[t]&&delete e.D[t],e.o&&delete e.o[t],!0},getOwnPropertyDescriptor:function(e,t){var n=I(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&(r.writable=!0,r.configurable=1!==e.i||"length"!==t),r},defineProperty:function(){E(11)},getPrototypeOf:function(e){return Object.getPrototypeOf(e.t)},setPrototypeOf:function(){E(12)}},fe={};S(le,(function(e,t){fe[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}})),fe.deleteProperty=function(e,t){return"production"!==process.env.NODE_ENV&&isNaN(parseInt(t))&&E(13),le.deleteProperty.call(this,e[0],t)},fe.set=function(e,t,n){return"production"!==process.env.NODE_ENV&&"length"!==t&&isNaN(parseInt(t))&&E(14),le.set.call(this,e[0],t,n,e[0])};var se=new(function(){function e(e){this.g=ne,this.N="production"!==process.env.NODE_ENV,"boolean"==typeof(null==e?void 0:e.useProxies)&&this.setUseProxies(e.useProxies),"boolean"==typeof(null==e?void 0:e.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),this.produce=this.produce.bind(this),this.produceWithPatches=this.produceWithPatches.bind(this)}var t=e.prototype;return t.produce=function(e,t,n){if("function"==typeof e&&"function"!=typeof t){var r=t;t=e;var o=this;return function(e){var n=this;void 0===e&&(e=r);for(var i=arguments.length,u=Array(i>1?i-1:0),a=1;a<i;a++)u[a-1]=arguments[a];return o.produce(e,(function(e){var r;return(r=t).call.apply(r,[n,e].concat(u))}))}}var i;if("function"!=typeof t&&E(6),void 0!==n&&"function"!=typeof n&&E(7),w(e)){var u=W(this),a=X(this,e,void 0),c=!0;try{i=t(a),c=!1}finally{c?H(u):M(u)}return"undefined"!=typeof Promise&&i instanceof Promise?i.then((function(e){return V(u,n),K(e,u)}),(function(e){throw H(u),e})):(V(u,n),K(i,u))}if((i=t(e))!==re)return void 0===i&&(i=e),this.N&&C(i,!0),i},t.produceWithPatches=function(e,t){var n,r,o=this;return"function"==typeof e?function(t){for(var n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return o.produceWithPatches(t,(function(t){return e.apply(void 0,[t].concat(r))}))}:[this.produce(e,t,(function(e,t){n=e,r=t})),n,r]},t.createDraft=function(e){w(e)||E(8);var t=W(this),n=X(this,e,void 0);return n[ie].C=!0,M(t),n},t.finishDraft=function(e,t){var n=e&&e[ie];"production"!==process.env.NODE_ENV&&(n&&n.C||E(9),n.I&&E(10));var r=n.A;return V(r,t),K(void 0,r)},t.setAutoFreeze=function(e){this.N=e},t.setUseProxies=function(e){ne||E(20),this.g=e},t.applyPatches=function(e,t){var n;for(n=t.length-1;n>=0;n--){var r=t[n];if(0===r.path.length&&"replace"===r.op){e=r.value;break}}var o=R("Patches").U;return j(e)?o(e,t):this.produce(e,(function(e){return o(e,t.slice(n+1))}))},e}()),pe=se.produce,de=(se.produceWithPatches.bind(se),se.setAutoFreeze.bind(se),se.setUseProxies.bind(se),se.applyPatches.bind(se),se.createDraft.bind(se),se.finishDraft.bind(se),e.createContext(null)),ye=function(e,o){var i=ve(),u=r(),a=m(t((function(){return u.current=e(i.getState())})),2),c=a[0],l=a[1];return n((function(){return i.subscribe((function(t){var n=e(t);(o&&!o(n,u.current)||n!==u.current)&&l(u.current=n)}))}),[]),c};function he(){return o(de).options}var me=function(t){var n=t.layout,r=t.options,o=t.children;return e.createElement(de.Provider,{value:{layout:n,options:r}},o)};function ve(t){var n,r=t||{},u=r.layout,a=r.name,c=void 0===a?"default":a,f=r.initialState,s=e.useRef(),p=(m(i((function(e){return e+1}),0),2)[1],null===(n=o(de))||void 0===n?void 0:n.layout);return s.current||(p&&p.name===c?s.current=p:s.current=u||function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.initialState,n=e.name,r=void 0===n?"default":n,o=(e.current,new l(y({},"function"==typeof t?t():null!=t?t:{}))),i={get name(){return r},subscribe:function(e){var t=o.subscribe(e);return t.unsubscribe.bind(t)},getState:function(){return o.value},update:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}((function(e){if("function"==typeof e){var t=o.value,n=pe(t,e);t!==n&&(o.next(n),console.debug("next layout state",n,t))}else i.update((function(t){Object.assign(t,e)}))})),dispose:function(){}};return i}({name:c,initialState:f,current:p})),s.current}var be=e.createContext(new l(null));function ge(){var e=o(be),r=m(t(e.value),2),i=r[0],u=r[1];return n((function(){var t=e.subscribe(u);return t.unsubscribe.bind(t)}),[e]),[i,function(t){return e.next(t)}]}var Oe=function(t){t.children;var n=h(t,["children"]),r=he(),o=r.menus,i=r.link,u=void 0===i?"a":i,c=r.menuProps,l=void 0===c?{}:c,f=m(ge(),1)[0];return e.createElement(a,p({theme:"dark"===f?"dark":"light",mode:"inline"},l,n),function(t,n){return t.map((function(t){return function(t,n){var r=t.path,o=t.title,i=t.iconComponent,u=t.children,c=void 0===u?[]:u;if(r||0===c.length)return Pe(t,n);return e.createElement(a.SubMenu,{key:r||o,title:e.createElement("div",null,i,e.createElement("span",null,o))},c.map((function(e){return Pe(e,n)})))}(t,n)}))}(o,{link:u}))};function Pe(t,n){var r=n.link,o=t.path,i=t.title,u=t.iconComponent;return e.createElement(a.Item,{key:o||i},e.createElement(r,{href:o},e.createElement("div",null,u,e.createElement("span",{style:y({},u?{marginLeft:10}:{})},i))))}var Ee=function(n){var r=n.style,o=m(t(!1),2),i=o[0],u=o[1],a=m(t(!0),2),l=a[0],f=a[1],s=m(ge(),1)[0];return e.createElement(c.Sider,{theme:"dark"===s?"dark":"light",breakpoint:"md",onBreakpoint:u,collapsedWidth:i?0:80,collapsible:!0,collapsed:l,onCollapse:function(e){return f(e)},style:y({height:"100%"},r)},e.createElement("div",{style:{height:"100%",overflowY:"auto"}},e.createElement(Oe,null)))},je=function(t){var n=t.header,r=t.footer,o=t.children,i=t.showHeader,u=t.showFooter;"boolean"!=typeof i&&(i=Boolean(n)),"boolean"!=typeof u&&(u=Boolean(r));var a=ve(),l=m(ge(),1)[0];return e.createElement(c,{style:{height:"100%",minHeight:"100vh"},"data-layout-frame-name":a.name},n&&i&&e.createElement(c.Header,{style:"light"===l?{backgroundColor:"#fff"}:{}},n),e.createElement(c,{hasSider:!0},e.createElement(Ee,null),e.createElement(c,null,e.createElement(c.Content,{style:{maxHeight:"100%",overflowY:"auto"}},o),r&&u&&e.createElement(c.Footer,null,r))))},we=function(t){var n=t.children,r=t.showFooter,o=t.showHeader,i=t.footer,u=t.header,a=t.name,c=t.menus,l=t.link,f=t.menuProps,s=ve(t.layout?{layout:t.layout}:{});return e.createElement(me,{layout:s,options:{name:a,menus:c,link:l,menuProps:f}},e.createElement(je,{children:n,showFooter:r,showHeader:o,footer:i,header:u}))},Se=function(t){var n=t.children,r=t.style,o=m(ge(),1)[0];return e.createElement("div",{style:y(y({},"dark"!==o?{backgroundColor:"white"}:{}),{},{margin:8,padding:12,minHeight:"calc(100% - 16px)"},r)},n)};export{we as LayoutFrame,Se as LayoutFrameContent,je as LayoutFrameLayout,Oe as LayoutFrameMenu,me as LayoutFrameProvider,Ee as LayoutFrameSider,O as loadAntdTheme,P as useAntdTheme,ve as useLayoutFrame,he as useLayoutFrameOptions,ye as useLayoutFrameSelector}; //# sourceMappingURL=wener-ui-antds.esm.min.js.map