@zuzjs/ui 0.1.9 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1328 -2
- package/dist/styles.css +272 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,1330 @@
|
|
|
1
|
-
import{createContext,useEffect,useMemo,useReducer,useCallback,cloneElement,useContext,useRef,useState,useLayoutEffect,forwardRef,useImperativeHandle,createElement}from"react";import{jsx,jsxs}from"react/jsx-runtime";import PropTypes from"prop-types";import Children from"react-children-utilities";import Cookies from"js-cookie";import axios from"axios";import{nanoid}from"nanoid";import{ClassNames}from"@emotion/react";import styled from"@emotion/styled";import toast,{Toaster}from"react-hot-toast";const AppContext=createContext({});function __classPrivateFieldGet(e,t,r,o){if("a"===r&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e===t&&o:t.has(e))return"m"===r?o:"a"===r?o.call(e):o?o.value:t.get(e);throw new TypeError("Cannot read private member from an object whose class did not declare it")}function __classPrivateFieldSet(e,t,r,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e===t&&i:t.has(e))return"a"===o?i.call(e,r):i?i.value=r:t.set(e,r),r;throw new TypeError("Cannot write private member to an object whose class did not declare it")}var _AppTheme_mode,_AppTheme_listen,_AppTheme_lightTheme,_AppTheme_darkTheme;class AppTheme{constructor(e){_AppTheme_mode.set(this,void 0),_AppTheme_listen.set(this,void 0),_AppTheme_lightTheme.set(this,void 0),_AppTheme_darkTheme.set(this,void 0),this.get=()=>{let t=this;return"auto"===__classPrivateFieldGet(t,_AppTheme_mode,"f")?(window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{__classPrivateFieldSet(t,_AppTheme_mode,e.matches?"dark":"light","f"),__classPrivateFieldGet(t,_AppTheme_listen,"f").call(t,__classPrivateFieldGet(t,_AppTheme_mode,"f"))}),window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?__classPrivateFieldGet(t,_AppTheme_darkTheme,"f"):__classPrivateFieldGet(t,_AppTheme_lightTheme,"f")):"light"===__classPrivateFieldGet(t,_AppTheme_mode,"f")?__classPrivateFieldGet(t,_AppTheme_lightTheme,"f"):"dark"===__classPrivateFieldGet(t,_AppTheme_mode,"f")?__classPrivateFieldGet(t,_AppTheme_darkTheme,"f"):void 0};e=e||{};__classPrivateFieldSet(this,_AppTheme_listen,"listen"in e?e.listen:e=>{console.log("Theme switched to "+e)},"f"),__classPrivateFieldSet(this,_AppTheme_mode,e.mode||"auto","f"),__classPrivateFieldSet(this,_AppTheme_lightTheme,Object.assign({tag:"light",dark:!1,primary:"#edeef5",secondary:"#f9f9f9",textColor:"#111111"},"theme"in e&&"light"in e.theme?Object.assign({},e.theme.light):{}),"f"),__classPrivateFieldSet(this,_AppTheme_darkTheme,Object.assign({tag:"dark",dark:!0,primary:"#21222d",secondary:"#282a37",textColor:"#f9f9f9"},"theme"in e&&"dark"in e.theme?Object.assign({},e.theme.dark):{}),"f")}}_AppTheme_mode=new WeakMap,_AppTheme_listen=new WeakMap,_AppTheme_lightTheme=new WeakMap,_AppTheme_darkTheme=new WeakMap;let isMounted=!0;const STORE_KEY="__zuzjs",STORE_FORM_KEY=STORE_KEY+"forms",defaultState={[STORE_KEY+"base"]:{debug:!0,loading:!1,_tmp:Math.random()},[STORE_FORM_KEY]:{forms:{}}},rootReducer=(e,t)=>Object.assign(Object.assign({},e),t.payload),AppProvider=({children:e,initialState:t={},theme:r={}})=>{useEffect(()=>(isMounted=!0,()=>{isMounted=!1}),[]);var o=useMemo(()=>Object.assign(Object.assign(Object.assign({},defaultState),t),{theme:new AppTheme({theme:r}).get()}),[t]);const[i,a]=useReducer(rootReducer,o),n=useCallback(e=>{isMounted&&a(Object.assign({},e))},[a]);o=useMemo(()=>Object.assign(Object.assign({},i),{dispatch:n}),[i]);return jsx(AppContext.Provider,Object.assign({value:o},{children:e}))},createSlice=(AppProvider.defaultProps={theme:{},initialState:{}},AppProvider.propTypes={children:PropTypes.node.isRequired,initialState:PropTypes.instanceOf(Object),theme:PropTypes.instanceOf(Object)},({name:e,initialState:t,reducers:r})=>({name:e,reducer:r,actions:r,state:t})),cssProps=(createSlice.defaultProps={name:"app",initialState:{},reducers:{}},createSlice.propTypes={name:PropTypes.string.isRequired,initialState:PropTypes.instanceOf(Object).isRequired,reducers:PropTypes.instanceOf(Object).isRequired},{ac:"align-content",alignContent:"align-content",aic:"aic",ai:"align-items",alignItems:"align-items",ass:"ass",asc:"asc",ase:"ase",alignSelf:"align-self",all:"all",animation:"animation",animationDelay:"animation-delay",animationDirection:"animation-direction",animationDuration:"animation-duration",animationFillMode:"animation-fill-mode",animationIterationCount:"animation-iteration-count",animationName:"animation-name",animationPlayState:"animation-play-state",animationTimingFunction:"animation-timing-function",backfaceVisibility:"backface-visibility",backgroundAttachment:"background-attachment",backgroundBlendMode:"background-blend-mode",backgroundClip:"background-clip",bg:"background",background:"background",bgc:"background-color",bgColor:"background-color",backgroundColor:"background-color",backgroundImage:"background-image",backgroundOrigin:"background-origin",backgroundPosition:"background-position",backgroundRepeat:"background-repeat",backgroundSize:"background-size",border:"border",borderBottom:"border-bottom",borderBottomColor:"border-bottom-color",borderBottomStyle:"border-bottom-style",borderBottomWidth:"border-bottom-width",borderCollapse:"border-collapse",borderColor:"border-color",borderImage:"border-image",borderImageOutset:"border-image-outset",borderImageRepeat:"border-image-repeat",borderImageSlice:"border-image-slice",borderImageSource:"border-image-source",borderImageWidth:"border-image-width",borderLeft:"border-left",borderLeftColor:"border-left-color",borderLeftStyle:"border-left-style",borderLeftWidth:"border-left-width",r:"border-radius",br:"border-radius",borderRadius:"border-radius",brtl:"border-top-left-radius",borderTopLeftRadius:"border-top-left-radius",brtr:"border-top-right-radius",borderTopRightRadius:"border-top-right-radius",brbl:"border-bottom-left-radius",borderBottomLeftRadius:"border-bottom-left-radius",brbr:"border-bottom-right-radius",borderBottomRightRadius:"border-bottom-right-radius",borderRight:"border-right",borderRightColor:"border-right-color",borderRightStyle:"border-right-style",borderRightWidth:"border-right-width",borderSpacing:"border-spacing",borderStyle:"border-style",borderTop:"border-top",borderTopColor:"border-top-color",borderTopStyle:"border-top-style",borderTopWidth:"border-top-width",borderWidth:"border-width",bottom:"bottom",boxDecorationBreak:"box-decoration-break",boxShadow:"box-shadow",boxSizing:"box-sizing",captionSide:"caption-side",caretColor:"caret-color","@charset":"@charset",clear:"clear",clip:"clip",color:"color",columnCount:"column-count",columnFill:"column-fill",columnGap:"column-gap",colGap:"column-gap",columnRule:"column-rule",columnRuleColor:"column-rule-color",columnRuleStyle:"column-rule-style",columnRuleWidth:"column-rule-width",columnSpan:"column-span",columnWidth:"column-width",colW:"column-width",columns:"columns",content:"content",counterIncrement:"counter-increment",counterReset:"counter-reset",cursor:"cursor",pointer:"pointer",direction:"direction",display:"display",emptyCells:"empty-cells",filter:"filter",flex:"flex",flexBasis:"flex-basis",dir:"flex-direction",flexDirection:"flex-direction",flexFlow:"flex-flow",flexGrow:"flex-grow",flexShrink:"flex-shrink",flexWrap:"flex-wrap",float:"float",font:"font",fontFamily:"font-family",fontKerning:"font-kerning",size:"font-size",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",bold:"bold",fontWeight:"font-weight",gap:"gap",grid:"grid",gridArea:"grid-area",gridAutoColumns:"grid-auto-columns",gridAutoFlow:"grid-auto-flow",gridAutoRows:"grid-auto-rows",gridColumn:"grid-column",gridColumnEnd:"grid-column-end",gridColumnGap:"grid-column-gap",gridColumnStart:"grid-column-start",gridGap:"grid-gap",gridRow:"grid-row",gridRowEnd:"grid-row-end",gridRowGap:"grid-row-gap",gridRowStart:"grid-row-start",gridTemplate:"grid-template",gridTemplateAreas:"grid-template-areas",gridTemplateColumns:"grid-template-columns",gridTemplateRows:"grid-template-rows",hangingPunctuation:"hanging-punctuation",hyphens:"hyphens",isolation:"isolation",jcc:"jcc",jcs:"jcs",jce:"jce",jc:"justify-content",justifyContent:"justify-content",left:"left",letterSpacing:"letter-spacing",lineHeight:"line-height",listStyle:"list-style",listStyleImage:"list-style-image",listStylePosition:"list-style-position",listStyleType:"list-style-type",m:"margin",margin:"margin",mb:"margin-bottom",marginBottom:"margin-bottom",ml:"margin-left",marginLeft:"margin-left",mr:"margin-right",marginRight:"margin-right",mt:"margin-top",marginTop:"margin-top",h:"height",height:"height",minH:"min-height",minHeight:"min-height",maxH:"max-height",maxHeight:"max-height",w:"width",width:"width",minW:"min-width",minWidth:"min-width",maxW:"max-width",maxWidth:"max-width",mixBlendMode:"mix-blend-mode",objectFit:"object-fit",objectPosition:"object-position",opacity:"opacity",order:"order",outline:"outline",outlineColor:"outline-color",outlineOffset:"outline-offset",outlineStyle:"outline-style",outlineWidth:"outline-width",overflow:"overflow",overflowX:"overflow-x",overflowY:"overflow-y",p:"padding",padding:"padding",pb:"padding-bottom",paddingBottom:"padding-bottom",pl:"padding-left",paddingLeft:"padding-left",pr:"padding-right",paddingRight:"padding-right",pt:"padding-top",paddingTop:"padding-top",pageBreakAfter:"page-break-after",pageBreakBefore:"page-break-before",pageBreakInside:"page-break-inside",perspective:"perspective",perspectiveOrigin:"perspective-origin",pointerEvents:"pointer-events",rel:"rel",abs:"abs",fixed:"fixed",sticky:"sticky",pos:"position",position:"position",quotes:"quotes",resize:"resize",right:"right",scrollBehavior:"scroll-behavior",tabSize:"tab-size",tableLayout:"table-layout",align:"text-align",textAlign:"text-align",textAlignLast:"text-align-last",tdh:"tdh",td:"text-decoration",textDecoration:"text-decoration",textDecorationColor:"text-decoration-color",textDecorationLine:"text-decoration-line",textDecorationStyle:"text-decoration-style",textIndent:"text-indent",textJustify:"text-justify",textOverflow:"text-overflow",textShadow:"text-shadow",textTransform:"text-transform",top:"top",transform:"transform","transform(2D)":"transform(2D)","transformOrigin(twoValue syntax)":"transform-origin(two-value syntax)",transformStyle:"transform-style",transition:"transition",transitionDelay:"transition-delay",transitionDuration:"transition-duration",transitionProperty:"transition-property",transitionTimingFunction:"transition-timing-function",unicodeBidi:"unicode-bidi",userSelect:"user-select",verticalAlign:"vertical-align",visibility:"visibility",weight:"flex",whiteSpace:"white-space",ws:"white-space",wordBreak:"word-break",wordSpacing:"word-spacing",wrap:"wrap",wordWrap:"word-wrap",writingMode:"writing-mode",zIndex:"z-index",backdropFilter:"backdrop-filter",bgFilter:"backdrop-filter",anim:"anim",fill:"fill",abc:"abc",fb:"fb",ph:"ph",pv:"pv",mv:"mv",mh:"mh"}),cssPropsVals={primary:"var(--primary-color)",c:"center",cols:"column",rows:"row",rel:"relative",abs:"absolute"},cssPropsDirect={rel:"position: relative;",fixed:"position: fixed;",abs:"position: absolute;",sticky:"position: sticky;",flex:"display: flex;",aic:"align-items: center;",ass:"align-self: flex-start;",asc:"align-self: center;",ase:"align-self: flex-end;",jcc:"justify-content: center;",jcs:"justify-content: flex-start;",jce:"justify-content: flex-end;",grid:"display: grid;",fill:"top: 0px;left: 0px;right: 0px;bottom: 0px;",abc:"top: 50%;left: 50%;transform: translate(-50%, -50%);",block:"display: block;",bold:"font-weight: bold;",wrap:"word-wrap: break-word;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 99%;",pointer:"cursor: pointer;",fb:"font-family: var(--primary-font-bold);",ph:"padding-left: __VALUE__;padding-right: __VALUE__;",pv:"padding-bottom: __VALUE__;padding-top: __VALUE__;",mv:"margin-bottom: __VALUE__;margin-top: __VALUE__;",mh:"margin-left: __VALUE__;margin-right: __VALUE__;",anim:"transition:all __VALUE__s linear 0s;"},cssPropsIgnore=["weight","opacity"],_cssColors=["white","black","gray","red","orange","yellow","green","teal","blue","cyan","purple","pink","linkedin","facebook","messenger","whatsapp","twitter","telegram"],_cssColorsRange=["50","100","200","300","400","500","600","700","800","900"];let cssColors=[];0==cssColors.length&&_cssColors.map(t=>{_cssColorsRange.map(e=>cssColors.push(t+"."+e))});const makeCSSValue=(e,t,r)=>{r=-1==cssPropsIgnore.indexOf(r);if(e in cssPropsDirect&&1==r)return-1<cssPropsDirect[e].indexOf("__VALUE__")?cssPropsDirect[e].replaceAll("__VALUE__",t+("number"==typeof t?"px":"")):cssPropsDirect[e];let o="number"==typeof t&&r?"px":"";return-1<cssColors.indexOf(t)?(t=`var(--colors-${t.replaceAll(".","-")})`,o=""):t in cssPropsVals&&(t=cssPropsVals[t]),`${e}:${t}${o};`},buildCSS=t=>{let r="";return Object.keys(t).map(e=>{r+=e in cssProps?makeCSSValue(cssProps[e],t[e],e):""}),r},setCSSVar=(e,t)=>{document.documentElement.style.setProperty("--"+e,t)},isUrl=e=>{let t;try{t=new URL(e)}catch(e){return!1}return"http:"===t.protocol||"https:"===t.protocol},isEmail=e=>{return/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(e)},isIPv4=e=>/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(e),randstr=function(e){var t="",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";e=e||10;for(var o=0;o<e;o++)t+=r.charAt(Math.floor(Math.random()*r.length));return t},setCookie=(e,t,r)=>Cookies.set(e,t,{expires:r||7}),getCookie=e=>Cookies.get(e)||null,removeCookie=e=>Cookies.remove(e),buildFormData=t=>{var r=new FormData,o=Cookies.get();return Object.keys(o).map(e=>r.append(e,o[e])),Object.keys(t).filter(e=>"files"!=e).map(e=>r.append(e,t[e])),"files"in t&&[t.files].map(e=>r.append("files[]",e)),r},grab=async(e,o,i=60,t=null,r,a="__ha")=>{var n=getCookie(a)||randstr(8)+"^"+randstr(8);return window.__grabToken=axios.CancelToken.source(),t?new Promise((t,r)=>{axios({method:"post",url:e,data:buildFormData(o),timeout:1e3*i,cancelToken:window.__grabToken.token,headers:{"Content-Type":"multipart/form-data",Authorization:"Bearer "+n},onUploadProgress:e=>{}}).then(e=>{(e.data&&"kind"in e.data?t:r)(e.data)}).catch(e=>r(e))}):new Promise((t,r)=>{axios.post(e,Object.assign(Object.assign(Object.assign({},Cookies.get()),o),{__ustmp:(new Date).getTime()/1e3}),{timeout:1e3*i,headers:{"Content-Type":"application/json",Authorization:"Bearer "+n},cancelToken:window.__grabToken.token}).then(e=>{(e.data&&"kind"in e.data?t:r)(e.data)}).catch(e=>r(e))})},el=e=>document.querySelector(e),byName=e=>document.querySelector(`*[name="${e}"]`),byId=e=>document.getElementById(e),addProps=(e,t)=>{let r={};return{children:Children.deepMap(e,e=>(e.props&&!r[e.props.name]&&(r[e.props.name]=e.props.value||null),cloneElement(e,t))),fields:r}},ucfirst=e=>e.charAt(0).toUpperCase()+e.slice(1),filterStyleProps=e=>{const t=Object.keys(e);return Object.keys(cssProps).filter(e=>t.includes(e)),{}},filterHTMLProps=t=>{var e=Object.keys(t);const r=Object.keys(cssProps);let o={};return e.filter(e=>{"for"==e||r.includes(e)||(o[e]=t[e])}),o},uuid=()=>nanoid(),useTheme=(e=0)=>{return useContext(AppContext).theme||{}},useImage=(o,i,a)=>{const n=useRef("loading"),s=useRef(),[,l]=useState(0);var e=useRef(),t=useRef(),r=useRef();return e.current===o&&t.current===i&&r.current===a||(n.current="loading",s.current=void 0,e.current=o,t.current=i,r.current=a),useLayoutEffect(function(){var e;if(o)return(e=document.createElement("img")).addEventListener("load",t),e.addEventListener("error",r),i&&(e.crossOrigin=i),a&&(e.referrerPolicy=a),e.src=o,function(){e.removeEventListener("load",t),e.removeEventListener("error",r)};function t(){n.current="loaded",s.current=e,l(Math.random())}function r(){n.current="failed",s.current=void 0,l(Math.random())}},[o,i,a]),[s.current,n.current]},useStore=(e,t=!0)=>{let r=useContext(AppContext),o=t?{}:r;if(t){const i=["defaultState","theme","dispatch",STORE_KEY+"base",STORE_KEY+"forms"];Object.keys(r).map(e=>{-1==i.indexOf(e)&&(o[e]=r[e])})}return"function"==typeof e?e(o):o},useDispatch=o=>{const i=useContext(AppContext),a=i.dispatch;return o?(e={})=>{var t,r;a({action:o,payload:{[o]:(t=i[o],r=e,Object.keys(r).map(e=>{t[e]!==r[e]&&(t[e]=r[e])}),Object.assign(Object.assign({},t),r))}})}:a},AppMain=forwardRef((r,e)=>jsx(ClassNames,{children:({css:e,cx:t})=>jsx("main",Object.assign({className:`${r.as||"zuz-app"} `+t(e`${buildCSS(r)} &:hover {${buildCSS(r.hover||{})}} &:active {${buildCSS(r.active||{})}}`)},{children:r.children}))})),App=forwardRef((e,t)=>jsx(AppProvider,{children:jsx(AppMain,{})})),Box=forwardRef((r,o)=>{const i=()=>{};return jsx(ClassNames,{children:({css:e,cx:t})=>jsx("div",Object.assign({id:r.id||void 0,onClick:r.onClick||i,className:(r.as?r.as+" ":"")+t(e`${buildCSS(r)} &:hover {${buildCSS(r.hover||{})}} &:active {${buildCSS(r.active||{})}}`),ref:r.bref||o},{children:r.html?jsx("span",{dangerouslySetInnerHTML:{__html:r.html}}):r.children}))})}),Button=forwardRef((r,o)=>{const i=useStore(e=>e[STORE_FORM_KEY],!1)["forms"];return r.html&&r.html,jsx(ClassNames,{children:({css:e,cx:t})=>jsx("button",Object.assign({title:"title"in r?r.title:void 0,type:r.type,className:`button${r.as?" "+r.as:""} `+t(e`
|
|
1
|
+
import { createContext, useEffect, useMemo, useReducer, useCallback, useContext, forwardRef, useRef, useState, useLayoutEffect, useDebugValue, cloneElement, useImperativeHandle, createElement } from 'react';
|
|
2
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import Children from 'react-children-utilities';
|
|
5
|
+
import Cookies from 'js-cookie';
|
|
6
|
+
import axios from 'axios';
|
|
7
|
+
import { nanoid } from 'nanoid';
|
|
8
|
+
import { ClassNames } from '@emotion/react';
|
|
9
|
+
import styled from '@emotion/styled';
|
|
10
|
+
|
|
11
|
+
const AppContext = createContext({});
|
|
12
|
+
|
|
13
|
+
/******************************************************************************
|
|
14
|
+
Copyright (c) Microsoft Corporation.
|
|
15
|
+
|
|
16
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
17
|
+
purpose with or without fee is hereby granted.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
20
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
21
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
22
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
23
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
24
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
25
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
26
|
+
***************************************************************************** */
|
|
27
|
+
|
|
28
|
+
function __rest(s, e) {
|
|
29
|
+
var t = {};
|
|
30
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
31
|
+
t[p] = s[p];
|
|
32
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
33
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
34
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
35
|
+
t[p[i]] = s[p[i]];
|
|
36
|
+
}
|
|
37
|
+
return t;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
41
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
42
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
43
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
47
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
48
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
49
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
50
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
var _AppTheme_mode, _AppTheme_listen, _AppTheme_lightTheme, _AppTheme_darkTheme;
|
|
54
|
+
class AppTheme {
|
|
55
|
+
constructor(_conf) {
|
|
56
|
+
_AppTheme_mode.set(this, void 0);
|
|
57
|
+
_AppTheme_listen.set(this, void 0);
|
|
58
|
+
_AppTheme_lightTheme.set(this, void 0);
|
|
59
|
+
_AppTheme_darkTheme.set(this, void 0);
|
|
60
|
+
this.get = () => {
|
|
61
|
+
let self = this;
|
|
62
|
+
if (__classPrivateFieldGet(self, _AppTheme_mode, "f") === "auto") {
|
|
63
|
+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
|
|
64
|
+
__classPrivateFieldSet(self, _AppTheme_mode, event.matches ? "dark" : "light", "f");
|
|
65
|
+
__classPrivateFieldGet(self, _AppTheme_listen, "f").call(self, __classPrivateFieldGet(self, _AppTheme_mode, "f"));
|
|
66
|
+
});
|
|
67
|
+
return window.matchMedia &&
|
|
68
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches ?
|
|
69
|
+
__classPrivateFieldGet(self, _AppTheme_darkTheme, "f") : __classPrivateFieldGet(self, _AppTheme_lightTheme, "f");
|
|
70
|
+
}
|
|
71
|
+
else if (__classPrivateFieldGet(self, _AppTheme_mode, "f") === "light") {
|
|
72
|
+
return __classPrivateFieldGet(self, _AppTheme_lightTheme, "f");
|
|
73
|
+
}
|
|
74
|
+
else if (__classPrivateFieldGet(self, _AppTheme_mode, "f") === "dark") {
|
|
75
|
+
return __classPrivateFieldGet(self, _AppTheme_darkTheme, "f");
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const conf = _conf || {};
|
|
79
|
+
__classPrivateFieldSet(this, _AppTheme_listen, "listen" in conf ? conf.listen : (mod) => { console.log(`Theme switched to ${mod}`); }, "f");
|
|
80
|
+
__classPrivateFieldSet(this, _AppTheme_mode, conf.mode || "auto", "f");
|
|
81
|
+
__classPrivateFieldSet(this, _AppTheme_lightTheme, Object.assign({
|
|
82
|
+
//CORE
|
|
83
|
+
tag: "light", dark: false, primary: '#edeef5', secondary: '#f9f9f9', textColor: '#111111' }, ("theme" in conf && "light" in conf.theme ? Object.assign({}, conf.theme.light) : {})), "f");
|
|
84
|
+
__classPrivateFieldSet(this, _AppTheme_darkTheme, Object.assign({
|
|
85
|
+
//CORE
|
|
86
|
+
tag: "dark", dark: true, primary: '#21222d', secondary: '#282a37', textColor: '#f9f9f9' }, ("theme" in conf && "dark" in conf.theme ? Object.assign({}, conf.theme.dark) : {})), "f");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
_AppTheme_mode = new WeakMap(), _AppTheme_listen = new WeakMap(), _AppTheme_lightTheme = new WeakMap(), _AppTheme_darkTheme = new WeakMap();
|
|
90
|
+
|
|
91
|
+
let isMounted = true;
|
|
92
|
+
const STORE_KEY = `__zuzjs`;
|
|
93
|
+
const STORE_FORM_KEY = `${STORE_KEY}forms`;
|
|
94
|
+
const defaultState = {
|
|
95
|
+
[`${STORE_KEY}base`]: {
|
|
96
|
+
debug: true,
|
|
97
|
+
loading: false,
|
|
98
|
+
_tmp: Math.random()
|
|
99
|
+
},
|
|
100
|
+
[STORE_FORM_KEY]: {
|
|
101
|
+
forms: {}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const rootReducer = (state, action) => (Object.assign(Object.assign({}, state), action.payload));
|
|
105
|
+
const AppProvider = ({ children, initialState = {}, theme = {} }) => {
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
isMounted = true;
|
|
108
|
+
return () => {
|
|
109
|
+
isMounted = false;
|
|
110
|
+
};
|
|
111
|
+
}, []);
|
|
112
|
+
const rootState = useMemo(() => (Object.assign(Object.assign(Object.assign({}, defaultState), initialState), { theme: new AppTheme({ theme }).get() })), [initialState]);
|
|
113
|
+
const [state, _dispatch] = useReducer(rootReducer, rootState);
|
|
114
|
+
const dispatch = useCallback((args) => {
|
|
115
|
+
if (isMounted) {
|
|
116
|
+
_dispatch(Object.assign({}, args));
|
|
117
|
+
}
|
|
118
|
+
}, [_dispatch]);
|
|
119
|
+
// const dispatch = useCallback((payload = {}, _key = 'base') => {
|
|
120
|
+
// if(isMounted){
|
|
121
|
+
// const key = STORE_DEFAUTLS.indexOf(`${STORE_KEY}${_key}`) > -1 ? `${STORE_KEY}${_key}` : _key;
|
|
122
|
+
// const _state = { ...state[key] }
|
|
123
|
+
// console.log('key', key)
|
|
124
|
+
// console.log('state', _state)
|
|
125
|
+
// _dispatch({
|
|
126
|
+
// type: 'any',
|
|
127
|
+
// payload: {
|
|
128
|
+
// payload
|
|
129
|
+
// }
|
|
130
|
+
// })
|
|
131
|
+
// }
|
|
132
|
+
// }, [_dispatch]);
|
|
133
|
+
const providedValue = useMemo(() => (Object.assign(Object.assign({}, state), { dispatch })), [state]);
|
|
134
|
+
return jsx(AppContext.Provider, Object.assign({ value: providedValue }, { children: children }));
|
|
135
|
+
};
|
|
136
|
+
AppProvider.defaultProps = {
|
|
137
|
+
theme: {},
|
|
138
|
+
initialState: {},
|
|
139
|
+
};
|
|
140
|
+
AppProvider.propTypes = {
|
|
141
|
+
children: PropTypes.node.isRequired,
|
|
142
|
+
initialState: PropTypes.instanceOf(Object),
|
|
143
|
+
theme: PropTypes.instanceOf(Object)
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const createSlice = ({ name, initialState, reducers }) => {
|
|
147
|
+
// const _dynamiceReducers = {}
|
|
148
|
+
// Object.keys(reducers).map(k => {
|
|
149
|
+
// _dynamiceReducers[reducers[k].name] = [reducers[k].reducer, initialState]
|
|
150
|
+
// })
|
|
151
|
+
// const _keys = Object.keys(reducers);
|
|
152
|
+
// const [reducer, state] = combineReducers(_dynamiceReducers);
|
|
153
|
+
return {
|
|
154
|
+
name,
|
|
155
|
+
reducer: reducers,
|
|
156
|
+
actions: reducers,
|
|
157
|
+
state: initialState
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
createSlice.defaultProps = {
|
|
161
|
+
name: `app`,
|
|
162
|
+
initialState: {},
|
|
163
|
+
reducers: {}
|
|
164
|
+
};
|
|
165
|
+
createSlice.propTypes = {
|
|
166
|
+
name: PropTypes.string.isRequired,
|
|
167
|
+
initialState: PropTypes.instanceOf(Object).isRequired,
|
|
168
|
+
reducers: PropTypes.instanceOf(Object).isRequired
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const cssProps = {
|
|
172
|
+
"ac": "align-content",
|
|
173
|
+
"alignContent": "align-content",
|
|
174
|
+
"aic": "aic",
|
|
175
|
+
"ai": "align-items",
|
|
176
|
+
"alignItems": "align-items",
|
|
177
|
+
"ass": "ass",
|
|
178
|
+
"asc": "asc",
|
|
179
|
+
"ase": "ase",
|
|
180
|
+
"alignSelf": "align-self",
|
|
181
|
+
"all": "all",
|
|
182
|
+
"animation": "animation",
|
|
183
|
+
"animationDelay": "animation-delay",
|
|
184
|
+
"animationDirection": "animation-direction",
|
|
185
|
+
"animationDuration": "animation-duration",
|
|
186
|
+
"animationFillMode": "animation-fill-mode",
|
|
187
|
+
"animationIterationCount": "animation-iteration-count",
|
|
188
|
+
"animationName": "animation-name",
|
|
189
|
+
"animationPlayState": "animation-play-state",
|
|
190
|
+
"animationTimingFunction": "animation-timing-function",
|
|
191
|
+
"backfaceVisibility": "backface-visibility",
|
|
192
|
+
"backgroundAttachment": "background-attachment",
|
|
193
|
+
"backgroundBlendMode": "background-blend-mode",
|
|
194
|
+
"backgroundClip": "background-clip",
|
|
195
|
+
"bg": "background",
|
|
196
|
+
"background": "background",
|
|
197
|
+
"bgc": "background-color",
|
|
198
|
+
"bgColor": "background-color",
|
|
199
|
+
"backgroundColor": "background-color",
|
|
200
|
+
"backgroundImage": "background-image",
|
|
201
|
+
"backgroundOrigin": "background-origin",
|
|
202
|
+
"backgroundPosition": "background-position",
|
|
203
|
+
"backgroundRepeat": "background-repeat",
|
|
204
|
+
"backgroundSize": "background-size",
|
|
205
|
+
"border": "border",
|
|
206
|
+
"borderBottom": "border-bottom",
|
|
207
|
+
"borderBottomColor": "border-bottom-color",
|
|
208
|
+
"borderBottomStyle": "border-bottom-style",
|
|
209
|
+
"borderBottomWidth": "border-bottom-width",
|
|
210
|
+
"borderCollapse": "border-collapse",
|
|
211
|
+
"borderColor": "border-color",
|
|
212
|
+
"borderImage": "border-image",
|
|
213
|
+
"borderImageOutset": "border-image-outset",
|
|
214
|
+
"borderImageRepeat": "border-image-repeat",
|
|
215
|
+
"borderImageSlice": "border-image-slice",
|
|
216
|
+
"borderImageSource": "border-image-source",
|
|
217
|
+
"borderImageWidth": "border-image-width",
|
|
218
|
+
"borderLeft": "border-left",
|
|
219
|
+
"borderLeftColor": "border-left-color",
|
|
220
|
+
"borderLeftStyle": "border-left-style",
|
|
221
|
+
"borderLeftWidth": "border-left-width",
|
|
222
|
+
//Radius
|
|
223
|
+
"r": "border-radius",
|
|
224
|
+
"br": "border-radius",
|
|
225
|
+
"borderRadius": "border-radius",
|
|
226
|
+
"brtl": "border-top-left-radius",
|
|
227
|
+
"borderTopLeftRadius": "border-top-left-radius",
|
|
228
|
+
"brtr": "border-top-right-radius",
|
|
229
|
+
"borderTopRightRadius": "border-top-right-radius",
|
|
230
|
+
"brbl": "border-bottom-left-radius",
|
|
231
|
+
"borderBottomLeftRadius": "border-bottom-left-radius",
|
|
232
|
+
"brbr": "border-bottom-right-radius",
|
|
233
|
+
"borderBottomRightRadius": "border-bottom-right-radius",
|
|
234
|
+
"borderRight": "border-right",
|
|
235
|
+
"borderRightColor": "border-right-color",
|
|
236
|
+
"borderRightStyle": "border-right-style",
|
|
237
|
+
"borderRightWidth": "border-right-width",
|
|
238
|
+
"borderSpacing": "border-spacing",
|
|
239
|
+
"borderStyle": "border-style",
|
|
240
|
+
"borderTop": "border-top",
|
|
241
|
+
"borderTopColor": "border-top-color",
|
|
242
|
+
"borderTopStyle": "border-top-style",
|
|
243
|
+
"borderTopWidth": "border-top-width",
|
|
244
|
+
"borderWidth": "border-width",
|
|
245
|
+
"bottom": "bottom",
|
|
246
|
+
"boxDecorationBreak": "box-decoration-break",
|
|
247
|
+
"boxShadow": "box-shadow",
|
|
248
|
+
"boxSizing": "box-sizing",
|
|
249
|
+
"captionSide": "caption-side",
|
|
250
|
+
"caretColor": "caret-color",
|
|
251
|
+
"@charset": "@charset",
|
|
252
|
+
"clear": "clear",
|
|
253
|
+
"clip": "clip",
|
|
254
|
+
"color": "color",
|
|
255
|
+
"columnCount": "column-count",
|
|
256
|
+
"columnFill": "column-fill",
|
|
257
|
+
"columnGap": "column-gap",
|
|
258
|
+
"colGap": "column-gap",
|
|
259
|
+
"columnRule": "column-rule",
|
|
260
|
+
"columnRuleColor": "column-rule-color",
|
|
261
|
+
"columnRuleStyle": "column-rule-style",
|
|
262
|
+
"columnRuleWidth": "column-rule-width",
|
|
263
|
+
"columnSpan": "column-span",
|
|
264
|
+
"columnWidth": "column-width",
|
|
265
|
+
"colW": "column-width",
|
|
266
|
+
"columns": "columns",
|
|
267
|
+
"content": "content",
|
|
268
|
+
"counterIncrement": "counter-increment",
|
|
269
|
+
"counterReset": "counter-reset",
|
|
270
|
+
"cursor": "cursor",
|
|
271
|
+
"pointer": "pointer",
|
|
272
|
+
"direction": "direction",
|
|
273
|
+
"display": "display",
|
|
274
|
+
"emptyCells": "empty-cells",
|
|
275
|
+
"filter": "filter",
|
|
276
|
+
"flex": "flex",
|
|
277
|
+
"flexBasis": "flex-basis",
|
|
278
|
+
"dir": "flex-direction",
|
|
279
|
+
"flexDirection": "flex-direction",
|
|
280
|
+
"flexFlow": "flex-flow",
|
|
281
|
+
"flexGrow": "flex-grow",
|
|
282
|
+
"flexShrink": "flex-shrink",
|
|
283
|
+
"flexWrap": "flex-wrap",
|
|
284
|
+
"float": "float",
|
|
285
|
+
"font": "font",
|
|
286
|
+
"fontFamily": "font-family",
|
|
287
|
+
"fontKerning": "font-kerning",
|
|
288
|
+
"size": "font-size",
|
|
289
|
+
"fontSize": "font-size",
|
|
290
|
+
"fontSizeAdjust": "font-size-adjust",
|
|
291
|
+
"fontStretch": "font-stretch",
|
|
292
|
+
"fontStyle": "font-style",
|
|
293
|
+
"fontVariant": "font-variant",
|
|
294
|
+
"bold": "bold",
|
|
295
|
+
"fontWeight": "font-weight",
|
|
296
|
+
"gap": "gap",
|
|
297
|
+
"grid": "grid",
|
|
298
|
+
"gridArea": "grid-area",
|
|
299
|
+
"gridAutoColumns": "grid-auto-columns",
|
|
300
|
+
"gridAutoFlow": "grid-auto-flow",
|
|
301
|
+
"gridAutoRows": "grid-auto-rows",
|
|
302
|
+
"gridColumn": "grid-column",
|
|
303
|
+
"gridColumnEnd": "grid-column-end",
|
|
304
|
+
"gridColumnGap": "grid-column-gap",
|
|
305
|
+
"gridColumnStart": "grid-column-start",
|
|
306
|
+
"gridGap": "grid-gap",
|
|
307
|
+
"gridRow": "grid-row",
|
|
308
|
+
"gridRowEnd": "grid-row-end",
|
|
309
|
+
"gridRowGap": "grid-row-gap",
|
|
310
|
+
"gridRowStart": "grid-row-start",
|
|
311
|
+
"gridTemplate": "grid-template",
|
|
312
|
+
"gridTemplateAreas": "grid-template-areas",
|
|
313
|
+
"gridTemplateColumns": "grid-template-columns",
|
|
314
|
+
"gridTemplateRows": "grid-template-rows",
|
|
315
|
+
"hangingPunctuation": "hanging-punctuation",
|
|
316
|
+
"hyphens": "hyphens",
|
|
317
|
+
"isolation": "isolation",
|
|
318
|
+
"jcc": "jcc",
|
|
319
|
+
"jcs": "jcs",
|
|
320
|
+
"jce": "jce",
|
|
321
|
+
"jc": "justify-content",
|
|
322
|
+
"justifyContent": "justify-content",
|
|
323
|
+
"left": "left",
|
|
324
|
+
"letterSpacing": "letter-spacing",
|
|
325
|
+
"lineHeight": "line-height",
|
|
326
|
+
"listStyle": "list-style",
|
|
327
|
+
"listStyleImage": "list-style-image",
|
|
328
|
+
"listStylePosition": "list-style-position",
|
|
329
|
+
"listStyleType": "list-style-type",
|
|
330
|
+
//Margin
|
|
331
|
+
"m": "margin",
|
|
332
|
+
"margin": "margin",
|
|
333
|
+
"mb": "margin-bottom",
|
|
334
|
+
"marginBottom": "margin-bottom",
|
|
335
|
+
"ml": "margin-left",
|
|
336
|
+
"marginLeft": "margin-left",
|
|
337
|
+
"mr": "margin-right",
|
|
338
|
+
"marginRight": "margin-right",
|
|
339
|
+
"mt": "margin-top",
|
|
340
|
+
"marginTop": "margin-top",
|
|
341
|
+
//Height
|
|
342
|
+
"h": "height",
|
|
343
|
+
"height": "height",
|
|
344
|
+
"minH": "min-height",
|
|
345
|
+
"minHeight": "min-height",
|
|
346
|
+
"maxH": "max-height",
|
|
347
|
+
"maxHeight": "max-height",
|
|
348
|
+
//Width
|
|
349
|
+
"w": "width",
|
|
350
|
+
"width": "width",
|
|
351
|
+
"minW": "min-width",
|
|
352
|
+
"minWidth": "min-width",
|
|
353
|
+
"maxW": "max-width",
|
|
354
|
+
"maxWidth": "max-width",
|
|
355
|
+
"mixBlendMode": "mix-blend-mode",
|
|
356
|
+
"objectFit": "object-fit",
|
|
357
|
+
"objectPosition": "object-position",
|
|
358
|
+
"opacity": "opacity",
|
|
359
|
+
"order": "order",
|
|
360
|
+
"outline": "outline",
|
|
361
|
+
"outlineColor": "outline-color",
|
|
362
|
+
"outlineOffset": "outline-offset",
|
|
363
|
+
"outlineStyle": "outline-style",
|
|
364
|
+
"outlineWidth": "outline-width",
|
|
365
|
+
"overflow": "overflow",
|
|
366
|
+
"overflowX": "overflow-x",
|
|
367
|
+
"overflowY": "overflow-y",
|
|
368
|
+
"p": "padding",
|
|
369
|
+
"padding": "padding",
|
|
370
|
+
"pb": "padding-bottom",
|
|
371
|
+
"paddingBottom": "padding-bottom",
|
|
372
|
+
"pl": "padding-left",
|
|
373
|
+
"paddingLeft": "padding-left",
|
|
374
|
+
"pr": "padding-right",
|
|
375
|
+
"paddingRight": "padding-right",
|
|
376
|
+
"pt": "padding-top",
|
|
377
|
+
"paddingTop": "padding-top",
|
|
378
|
+
"pageBreakAfter": "page-break-after",
|
|
379
|
+
"pageBreakBefore": "page-break-before",
|
|
380
|
+
"pageBreakInside": "page-break-inside",
|
|
381
|
+
"perspective": "perspective",
|
|
382
|
+
"perspectiveOrigin": "perspective-origin",
|
|
383
|
+
"pointerEvents": "pointer-events",
|
|
384
|
+
"rel": "rel",
|
|
385
|
+
"abs": "abs",
|
|
386
|
+
"fixed": "fixed",
|
|
387
|
+
"sticky": "sticky",
|
|
388
|
+
"pos": "position",
|
|
389
|
+
"position": "position",
|
|
390
|
+
"quotes": "quotes",
|
|
391
|
+
"resize": "resize",
|
|
392
|
+
"right": "right",
|
|
393
|
+
"scrollBehavior": "scroll-behavior",
|
|
394
|
+
"tabSize": "tab-size",
|
|
395
|
+
"tableLayout": "table-layout",
|
|
396
|
+
"align": "text-align",
|
|
397
|
+
"textAlign": "text-align",
|
|
398
|
+
"textAlignLast": "text-align-last",
|
|
399
|
+
"tdh": "tdh",
|
|
400
|
+
"td": "text-decoration",
|
|
401
|
+
"textDecoration": "text-decoration",
|
|
402
|
+
"textDecorationColor": "text-decoration-color",
|
|
403
|
+
"textDecorationLine": "text-decoration-line",
|
|
404
|
+
"textDecorationStyle": "text-decoration-style",
|
|
405
|
+
"textIndent": "text-indent",
|
|
406
|
+
"textJustify": "text-justify",
|
|
407
|
+
"textOverflow": "text-overflow",
|
|
408
|
+
"textShadow": "text-shadow",
|
|
409
|
+
"textTransform": "text-transform",
|
|
410
|
+
"top": "top",
|
|
411
|
+
"transform": "transform",
|
|
412
|
+
"transform(2D)": "transform(2D)",
|
|
413
|
+
"transformOrigin(twoValue syntax)": "transform-origin(two-value syntax)",
|
|
414
|
+
"transformStyle": "transform-style",
|
|
415
|
+
"transition": "transition",
|
|
416
|
+
"transitionDelay": "transition-delay",
|
|
417
|
+
"transitionDuration": "transition-duration",
|
|
418
|
+
"transitionProperty": "transition-property",
|
|
419
|
+
"transitionTimingFunction": "transition-timing-function",
|
|
420
|
+
"unicodeBidi": "unicode-bidi",
|
|
421
|
+
"userSelect": "user-select",
|
|
422
|
+
"verticalAlign": "vertical-align",
|
|
423
|
+
"visibility": "visibility",
|
|
424
|
+
"weight": "flex",
|
|
425
|
+
"whiteSpace": "white-space",
|
|
426
|
+
"ws": "white-space",
|
|
427
|
+
"wordBreak": "word-break",
|
|
428
|
+
"wordSpacing": "word-spacing",
|
|
429
|
+
"wrap": "wrap",
|
|
430
|
+
"wordWrap": "word-wrap",
|
|
431
|
+
"writingMode": "writing-mode",
|
|
432
|
+
"zIndex": "z-index",
|
|
433
|
+
"backdropFilter": "backdrop-filter",
|
|
434
|
+
"bgFilter": "backdrop-filter",
|
|
435
|
+
//Custom
|
|
436
|
+
"anim": "anim",
|
|
437
|
+
"fill": "fill",
|
|
438
|
+
"abc": "abc",
|
|
439
|
+
"fb": "fb",
|
|
440
|
+
"ph": "ph",
|
|
441
|
+
"pv": "pv",
|
|
442
|
+
"mv": "mv",
|
|
443
|
+
"mh": "mh"
|
|
444
|
+
};
|
|
445
|
+
const cssPropsVals = {
|
|
446
|
+
//Colors
|
|
447
|
+
"primary": 'var(--primary-color)',
|
|
448
|
+
"c": "center",
|
|
449
|
+
//Flex Directions
|
|
450
|
+
"cols": "column",
|
|
451
|
+
"colsr": "column-reverse",
|
|
452
|
+
"rows": "row",
|
|
453
|
+
"rowsr": "row-reverse",
|
|
454
|
+
//Positions
|
|
455
|
+
"rel": "relative",
|
|
456
|
+
"abs": "absolute",
|
|
457
|
+
};
|
|
458
|
+
const cssPropsDirect = {
|
|
459
|
+
'rel': 'position: relative;',
|
|
460
|
+
'fixed': 'position: fixed;',
|
|
461
|
+
'abs': 'position: absolute;',
|
|
462
|
+
'sticky': 'position: sticky;',
|
|
463
|
+
'flex': 'display: flex;',
|
|
464
|
+
'fwrap': 'flex-wrap: wrap;',
|
|
465
|
+
'aic': 'align-items: center;',
|
|
466
|
+
'ass': 'align-self: flex-start;',
|
|
467
|
+
'asc': 'align-self: center;',
|
|
468
|
+
'ase': 'align-self: flex-end;',
|
|
469
|
+
'jcc': 'justify-content: center;',
|
|
470
|
+
'jcs': 'justify-content: flex-start;',
|
|
471
|
+
'jce': 'justify-content: flex-end;',
|
|
472
|
+
'grid': 'display: grid;',
|
|
473
|
+
'fill': 'top: 0px;left: 0px;right: 0px;bottom: 0px;',
|
|
474
|
+
'abc': 'top: 50%;left: 50%;transform: translate(-50%, -50%);',
|
|
475
|
+
'block': 'display: block;',
|
|
476
|
+
'bold': "font-weight: bold;",
|
|
477
|
+
'wrap': "word-wrap: break-word;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 99%;",
|
|
478
|
+
'pointer': "cursor: pointer;",
|
|
479
|
+
'fb': 'font-family: var(--primary-font-bold);',
|
|
480
|
+
'ph': 'padding-left: __VALUE__;padding-right: __VALUE__;',
|
|
481
|
+
'pv': 'padding-bottom: __VALUE__;padding-top: __VALUE__;',
|
|
482
|
+
'mv': 'margin-bottom: __VALUE__;margin-top: __VALUE__;',
|
|
483
|
+
'mh': 'margin-left: __VALUE__;margin-right: __VALUE__;',
|
|
484
|
+
'anim': 'transition:all __VALUE__s linear 0s;'
|
|
485
|
+
};
|
|
486
|
+
const cssPropsIgnore = [
|
|
487
|
+
'weight', `opacity`
|
|
488
|
+
];
|
|
489
|
+
const _cssColors = [`white`, `black`, `gray`, `red`, `orange`, `yellow`, `green`, `teal`, `blue`, `cyan`, `purple`, `pink`, `linkedin`, `facebook`, `messenger`, `whatsapp`, `twitter`, `telegram`];
|
|
490
|
+
const _cssColorsRange = [`50`, `100`, `200`, `300`, `400`, `500`, `600`, `700`, `800`, `900`];
|
|
491
|
+
let cssColors = [];
|
|
492
|
+
if (cssColors.length == 0) {
|
|
493
|
+
_cssColors.map(c => {
|
|
494
|
+
_cssColorsRange.map(r => cssColors.push(`${c}.${r}`));
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const useDispatch = (key) => {
|
|
499
|
+
const state = useContext(AppContext);
|
|
500
|
+
const dispatch = state['dispatch'];
|
|
501
|
+
const prepareState = (prevState, nextState) => {
|
|
502
|
+
const nextKeys = Object.keys(nextState);
|
|
503
|
+
nextKeys.map(k => {
|
|
504
|
+
if (prevState[k] !== nextState[k]) {
|
|
505
|
+
prevState[k] = nextState[k];
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
return Object.assign(Object.assign({}, prevState), nextState);
|
|
509
|
+
};
|
|
510
|
+
if (key) {
|
|
511
|
+
return (payload = {}) => {
|
|
512
|
+
dispatch({
|
|
513
|
+
action: key,
|
|
514
|
+
payload: {
|
|
515
|
+
[key]: prepareState(state[key], payload)
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
return dispatch;
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
const useStore = (callback, withFilter = true) => {
|
|
524
|
+
// if(withInititalState){
|
|
525
|
+
// return useContext(AppContext)
|
|
526
|
+
// }
|
|
527
|
+
let _state = useContext(AppContext);
|
|
528
|
+
let state = withFilter ? {} : _state;
|
|
529
|
+
if (withFilter) {
|
|
530
|
+
const filters = ['defaultState', 'theme', 'dispatch', `${STORE_KEY}base`, `${STORE_KEY}forms`];
|
|
531
|
+
Object.keys(_state).map(k => {
|
|
532
|
+
if (filters.indexOf(k) == -1) {
|
|
533
|
+
state[k] = _state[k];
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
if ("function" == typeof callback) {
|
|
538
|
+
return callback(state);
|
|
539
|
+
}
|
|
540
|
+
return state;
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
const ADD_FORM = (name, fields, forms) => ({
|
|
544
|
+
forms: Object.assign(Object.assign({}, forms), { [name]: Object.assign({ touched: false, loading: false }, fields) })
|
|
545
|
+
});
|
|
546
|
+
const UPDATE_FORM_FIELD = (formName, field, value, forms) => {
|
|
547
|
+
if (forms[formName]) {
|
|
548
|
+
let _forms = Object.assign({}, forms);
|
|
549
|
+
_forms[formName][field] = value;
|
|
550
|
+
return {
|
|
551
|
+
forms: _forms
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
return {};
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
const Input = forwardRef((props, ref) => {
|
|
558
|
+
const { as, accept, multiple, onChange, type, tag, placeholder, name, form, touched, onSubmit, defaultValue } = props;
|
|
559
|
+
const dispatch = useDispatch(STORE_FORM_KEY);
|
|
560
|
+
const { forms } = useStore(state => state[STORE_FORM_KEY], false);
|
|
561
|
+
let Tag = tag || 'input';
|
|
562
|
+
const El = Tag;
|
|
563
|
+
const _ref = useRef();
|
|
564
|
+
const _defaultCSS = `width: 100%;border-radius: var(--radius-base);padding-left: 4px;padding-right: 4px;border-style: solid;border-width: 1px;border-color: var(--colors-gray-200);`;
|
|
565
|
+
return (jsx(ClassNames, { children: ({ css, cx }) => jsx(El, { type: type || `text`, placeholder: placeholder || undefined, name: name || nanoid(), multiple: type == 'file' ? multiple : undefined, accept: accept || `*`, className: `${as ? `${as} ` : ``}f ${cx(css `${_defaultCSS}${buildCSS(props)}&:hover {${buildCSS(props.hover || {})}} &:focus {${buildCSS(props.focus || {})}}`)}`, ref: _ref, defaultValue: defaultValue || ``, onKeyUp: (e) => {
|
|
566
|
+
let k = e['keyCode'] || ['which'];
|
|
567
|
+
if (El != 'textarea' && k == 13 && form && onSubmit) {
|
|
568
|
+
onSubmit(forms[form]);
|
|
569
|
+
}
|
|
570
|
+
}, onChange: e => {
|
|
571
|
+
let val = type == 'file' ?
|
|
572
|
+
e.currentTarget.files
|
|
573
|
+
: e.currentTarget.value;
|
|
574
|
+
dispatch(dispatch(UPDATE_FORM_FIELD(form || 'orphan', name, val == "" ? null : val, forms)));
|
|
575
|
+
onChange && onChange(e.target.value == "" ? null : e.target.value);
|
|
576
|
+
}, onBlur: e => {
|
|
577
|
+
}, onFocus: e => touched == false && dispatch(UPDATE_FORM_FIELD(form || 'orphan', `touched`, true, forms)) }) }));
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
const Select = forwardRef((props, ref) => {
|
|
581
|
+
const { as, onChange, name, form, touched, options, defaultValue } = props;
|
|
582
|
+
const _ref = useRef();
|
|
583
|
+
const dispatch = useDispatch(STORE_FORM_KEY);
|
|
584
|
+
const { forms } = useStore(state => state[STORE_FORM_KEY], false);
|
|
585
|
+
const _defaultCSS = `width: 100%;border-radius: var(--radius-base);padding-left: 4px;padding-right: 4px;border-style: solid;border-width: 1px;border-color: var(--colors-gray-200);`;
|
|
586
|
+
useEffect(() => {
|
|
587
|
+
var _a;
|
|
588
|
+
dispatch(dispatch(UPDATE_FORM_FIELD(form || 'orphan', name, defaultValue && defaultValue != null && defaultValue != "" && defaultValue != undefined ? defaultValue : ((_a = options[0]) === null || _a === void 0 ? void 0 : _a.value) || '-1', forms)));
|
|
589
|
+
}, []);
|
|
590
|
+
return (jsx(ClassNames, { children: ({ css, cx }) => jsx("select", Object.assign({ onChange: e => {
|
|
591
|
+
let val = e.currentTarget.value;
|
|
592
|
+
dispatch(dispatch(UPDATE_FORM_FIELD(form || 'orphan', name, val, forms)));
|
|
593
|
+
onChange && onChange(val);
|
|
594
|
+
}, onFocus: e => touched == false && dispatch(UPDATE_FORM_FIELD(form || 'orphan', `touched`, true, forms)), onBlur: e => {
|
|
595
|
+
}, name: name || nanoid(), className: `${as ? as : ``} ${cx(css `${_defaultCSS}${buildCSS(props)}&:hover {${buildCSS(props.hover || {})}}`)}`, ref: _ref }, { children: options === null || options === void 0 ? void 0 : options.map(o => jsx("option", Object.assign({ value: o.value }, { children: o.label }), `select-${name}-option-${o.value}`)) })) }));
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
const useTheme = (mod = 'auto') => {
|
|
599
|
+
const state = useContext(AppContext);
|
|
600
|
+
return state['theme'] || {};
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
const useImage = (url, crossOrigin, referrerpolicy) => {
|
|
604
|
+
const statusRef = useRef('loading');
|
|
605
|
+
const imageRef = useRef();
|
|
606
|
+
const [_, setStateToken] = useState(0);
|
|
607
|
+
const oldUrl = useRef();
|
|
608
|
+
const oldCrossOrigin = useRef();
|
|
609
|
+
const oldReferrerPolicy = useRef();
|
|
610
|
+
if (oldUrl.current !== url || oldCrossOrigin.current !== crossOrigin || oldReferrerPolicy.current !== referrerpolicy) {
|
|
611
|
+
statusRef.current = 'loading';
|
|
612
|
+
imageRef.current = undefined;
|
|
613
|
+
oldUrl.current = url;
|
|
614
|
+
oldCrossOrigin.current = crossOrigin;
|
|
615
|
+
oldReferrerPolicy.current = referrerpolicy;
|
|
616
|
+
}
|
|
617
|
+
useLayoutEffect(function () {
|
|
618
|
+
if (!url)
|
|
619
|
+
return;
|
|
620
|
+
var img = document.createElement('img');
|
|
621
|
+
function onload() {
|
|
622
|
+
statusRef.current = 'loaded';
|
|
623
|
+
imageRef.current = img;
|
|
624
|
+
setStateToken(Math.random());
|
|
625
|
+
}
|
|
626
|
+
function onerror() {
|
|
627
|
+
statusRef.current = 'failed';
|
|
628
|
+
imageRef.current = undefined;
|
|
629
|
+
setStateToken(Math.random());
|
|
630
|
+
}
|
|
631
|
+
img.addEventListener('load', onload);
|
|
632
|
+
img.addEventListener('error', onerror);
|
|
633
|
+
crossOrigin && (img.crossOrigin = crossOrigin);
|
|
634
|
+
referrerpolicy && (img.referrerPolicy = referrerpolicy);
|
|
635
|
+
img.src = url;
|
|
636
|
+
return function cleanup() {
|
|
637
|
+
img.removeEventListener('load', onload);
|
|
638
|
+
img.removeEventListener('error', onerror);
|
|
639
|
+
};
|
|
640
|
+
}, [url, crossOrigin, referrerpolicy]);
|
|
641
|
+
return [imageRef.current, statusRef.current];
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
/** External Dependencies */
|
|
645
|
+
const useResizeObserver = (onResized) => {
|
|
646
|
+
const onResize = onResized ? onResized : () => { };
|
|
647
|
+
const onResizeCallback = useRef(onResize);
|
|
648
|
+
const resizeObserver = useRef();
|
|
649
|
+
const observerCallback = useCallback((entries) => {
|
|
650
|
+
entries.forEach((entry) => {
|
|
651
|
+
if (entry.contentRect) {
|
|
652
|
+
const { width, height } = entry.contentRect;
|
|
653
|
+
onResizeCallback.current({
|
|
654
|
+
entry,
|
|
655
|
+
width,
|
|
656
|
+
height,
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
}, []);
|
|
661
|
+
const updateOnResizeCallback = useCallback((newOnResizeCallback) => {
|
|
662
|
+
onResizeCallback.current = newOnResizeCallback;
|
|
663
|
+
}, []);
|
|
664
|
+
const initObserver = useCallback(() => {
|
|
665
|
+
if (!resizeObserver.current) {
|
|
666
|
+
resizeObserver.current = new ResizeObserver(observerCallback);
|
|
667
|
+
}
|
|
668
|
+
}, []);
|
|
669
|
+
const observeElement = useCallback((element, newOnResizeCallback) => {
|
|
670
|
+
if (element) {
|
|
671
|
+
if (!resizeObserver.current) {
|
|
672
|
+
initObserver();
|
|
673
|
+
}
|
|
674
|
+
resizeObserver.current.observe(element);
|
|
675
|
+
if (newOnResizeCallback) {
|
|
676
|
+
onResizeCallback.current = newOnResizeCallback;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}, []);
|
|
680
|
+
const unobserveElement = useCallback((element, newOnResizeCallback) => {
|
|
681
|
+
if (resizeObserver.current && element) {
|
|
682
|
+
resizeObserver.current.unobserve(element);
|
|
683
|
+
if (newOnResizeCallback) {
|
|
684
|
+
onResizeCallback.current = newOnResizeCallback;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}, []);
|
|
688
|
+
const removeObserver = useCallback(() => {
|
|
689
|
+
if (resizeObserver.current) {
|
|
690
|
+
resizeObserver.current.disconnect();
|
|
691
|
+
}
|
|
692
|
+
}, []);
|
|
693
|
+
useEffect(() => {
|
|
694
|
+
initObserver();
|
|
695
|
+
return removeObserver;
|
|
696
|
+
}, []);
|
|
697
|
+
return useMemo(() => [observeElement, unobserveElement, updateOnResizeCallback], []);
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
const useChooseEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
|
701
|
+
|
|
702
|
+
const EMPTY_BREAKPOINT = {
|
|
703
|
+
breakpoint: undefined,
|
|
704
|
+
minWidth: undefined,
|
|
705
|
+
maxWidth: undefined,
|
|
706
|
+
};
|
|
707
|
+
const useDevice = (config, defaultBreakpoint, hydrateInitial = true) => {
|
|
708
|
+
const buildQueries = (breakpoints) => {
|
|
709
|
+
const sorted = Object.keys(breakpoints).sort((a, b) => breakpoints[b] - breakpoints[a]);
|
|
710
|
+
return sorted.map((breakpoint, index) => {
|
|
711
|
+
let query = '';
|
|
712
|
+
const minWidth = breakpoints[breakpoint];
|
|
713
|
+
const nextBreakpoint = sorted[index - 1];
|
|
714
|
+
const maxWidth = nextBreakpoint ? breakpoints[nextBreakpoint] : null;
|
|
715
|
+
if (minWidth >= 0) {
|
|
716
|
+
query = `(min-width: ${minWidth}px)`;
|
|
717
|
+
}
|
|
718
|
+
if (maxWidth !== null) {
|
|
719
|
+
if (query) {
|
|
720
|
+
query += ' and ';
|
|
721
|
+
}
|
|
722
|
+
query += `(max-width: ${maxWidth - 1}px)`;
|
|
723
|
+
}
|
|
724
|
+
const mediaQuery = {
|
|
725
|
+
breakpoint,
|
|
726
|
+
maxWidth: maxWidth ? maxWidth - 1 : null,
|
|
727
|
+
minWidth,
|
|
728
|
+
query,
|
|
729
|
+
};
|
|
730
|
+
return mediaQuery;
|
|
731
|
+
});
|
|
732
|
+
};
|
|
733
|
+
/** Memoize list of calculated media queries from config */
|
|
734
|
+
const mediaQueries = useMemo(() => buildQueries(config), [config]);
|
|
735
|
+
/** Get initial breakpoint value */
|
|
736
|
+
const [currentBreakpoint, setCurrentBreakpoint] = useState(() => {
|
|
737
|
+
/** Loop through all media queries */
|
|
738
|
+
for (let _a of mediaQueries) {
|
|
739
|
+
const { query } = _a, breakpoint = __rest(_a, ["query"]);
|
|
740
|
+
/**
|
|
741
|
+
* If we're in the browser and there's no default value,
|
|
742
|
+
* try to match actual breakpoint. If the default value
|
|
743
|
+
* should not be hydrated, use the actual breakpoint.
|
|
744
|
+
*/
|
|
745
|
+
if (typeof window !== 'undefined' &&
|
|
746
|
+
!(defaultBreakpoint && hydrateInitial)) {
|
|
747
|
+
const mediaQuery = window.matchMedia(query);
|
|
748
|
+
if (mediaQuery.matches) {
|
|
749
|
+
return breakpoint;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
else if (breakpoint.breakpoint === defaultBreakpoint) {
|
|
753
|
+
/** Otherwise, try to match default value */
|
|
754
|
+
return breakpoint;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
return EMPTY_BREAKPOINT;
|
|
758
|
+
});
|
|
759
|
+
/** If there's a match, update the current breakpoint */
|
|
760
|
+
const updateBreakpoint = useCallback(({ matches }, breakpoint) => {
|
|
761
|
+
if (matches) {
|
|
762
|
+
setCurrentBreakpoint(breakpoint);
|
|
763
|
+
}
|
|
764
|
+
}, []);
|
|
765
|
+
/** On changes to mediaQueries, subscribe to changes using window.matchMedia */
|
|
766
|
+
useChooseEffect(() => {
|
|
767
|
+
const unsubscribers = mediaQueries.map((_a) => {
|
|
768
|
+
var { query } = _a, breakpoint = __rest(_a, ["query"]);
|
|
769
|
+
const list = window.matchMedia(query);
|
|
770
|
+
updateBreakpoint(list, breakpoint);
|
|
771
|
+
const handleChange = (event) => {
|
|
772
|
+
updateBreakpoint(event, breakpoint);
|
|
773
|
+
};
|
|
774
|
+
const supportsNewEventListeners = 'addEventListener' in list && 'removeEventListener' in list;
|
|
775
|
+
if (supportsNewEventListeners) {
|
|
776
|
+
list.addEventListener('change', handleChange);
|
|
777
|
+
}
|
|
778
|
+
else {
|
|
779
|
+
list.addListener(handleChange);
|
|
780
|
+
}
|
|
781
|
+
/** Map the unsubscribers array to a list of unsubscriber methods */
|
|
782
|
+
return () => {
|
|
783
|
+
if (supportsNewEventListeners) {
|
|
784
|
+
list.removeEventListener('change', handleChange);
|
|
785
|
+
}
|
|
786
|
+
else {
|
|
787
|
+
list.removeListener(handleChange);
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
});
|
|
791
|
+
/** Return a function that when called, will call all unsubscribers */
|
|
792
|
+
return () => unsubscribers.forEach((unsubscriber) => unsubscriber());
|
|
793
|
+
}, [mediaQueries, updateBreakpoint]);
|
|
794
|
+
/** Print a nice debug value for React Devtools */
|
|
795
|
+
useDebugValue(currentBreakpoint, (c) => typeof c.breakpoint === 'string'
|
|
796
|
+
? `${c.breakpoint} (${c.minWidth} ≤ x${c.maxWidth ? ` < ${c.maxWidth + 1}` : ''})`
|
|
797
|
+
: '');
|
|
798
|
+
return currentBreakpoint;
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
var _Toaster_container, _Toaster_startTop, _Toaster_tout, _Toaster_defaultTimeLeft;
|
|
802
|
+
class Toaster {
|
|
803
|
+
constructor(config) {
|
|
804
|
+
_Toaster_container.set(this, void 0);
|
|
805
|
+
_Toaster_startTop.set(this, void 0);
|
|
806
|
+
_Toaster_tout.set(this, void 0);
|
|
807
|
+
_Toaster_defaultTimeLeft.set(this, void 0);
|
|
808
|
+
this.show = (message, duration) => {
|
|
809
|
+
let self = this;
|
|
810
|
+
self.toast({
|
|
811
|
+
message: message,
|
|
812
|
+
duration: duration
|
|
813
|
+
});
|
|
814
|
+
};
|
|
815
|
+
__classPrivateFieldSet(this, _Toaster_startTop, 20, "f");
|
|
816
|
+
__classPrivateFieldSet(this, _Toaster_defaultTimeLeft, 4, "f");
|
|
817
|
+
const rootID = (config === null || config === void 0 ? void 0 : config.root) || `toast-container`;
|
|
818
|
+
if (document.querySelector(`#${rootID}`))
|
|
819
|
+
return;
|
|
820
|
+
var root = document.createElement('div');
|
|
821
|
+
root.id = rootID;
|
|
822
|
+
document.body.appendChild(root);
|
|
823
|
+
__classPrivateFieldSet(this, _Toaster_container, document.querySelector(`#${rootID}`), "f");
|
|
824
|
+
}
|
|
825
|
+
dismiss(ID) {
|
|
826
|
+
let self = this;
|
|
827
|
+
__classPrivateFieldGet(self, _Toaster_tout, "f") && clearTimeout(__classPrivateFieldGet(self, _Toaster_tout, "f"));
|
|
828
|
+
setTimeout(() => {
|
|
829
|
+
let tost = document.querySelector(`#${ID}`);
|
|
830
|
+
tost && tost.classList.remove("visible");
|
|
831
|
+
// tost && tost.classList.add("hidden");
|
|
832
|
+
setTimeout(() => {
|
|
833
|
+
try {
|
|
834
|
+
document.getElementById(ID).parentNode.removeChild(document.getElementById(ID));
|
|
835
|
+
}
|
|
836
|
+
catch (e) { }
|
|
837
|
+
self.arrangeToasts();
|
|
838
|
+
}, 200);
|
|
839
|
+
}, 200);
|
|
840
|
+
}
|
|
841
|
+
toast(config) {
|
|
842
|
+
var self = this;
|
|
843
|
+
var ID = 'toast-' + nanoid(), toast = document.createElement('div'); document.createElement('div');
|
|
844
|
+
toast.id = ID;
|
|
845
|
+
toast.style.backgroundColor = `#111`;
|
|
846
|
+
toast.style.color = `#fff`;
|
|
847
|
+
toast.style.transform = `translate(-50%, -300px) scale(0.5)`;
|
|
848
|
+
toast.style.position = `fixed`;
|
|
849
|
+
toast.style.padding = `6px 12px`;
|
|
850
|
+
toast.style.fontSize = `14px`;
|
|
851
|
+
toast.style.left = `50%`;
|
|
852
|
+
toast.style.maxWidth = `95%`;
|
|
853
|
+
toast.style.zIndex = `2147483647`;
|
|
854
|
+
toast.classList.add('zuz-toast');
|
|
855
|
+
toast.classList.add('fixed');
|
|
856
|
+
toast.classList.add('f');
|
|
857
|
+
toast.innerHTML = config.message || `You haven't passed "message" in this toast`;
|
|
858
|
+
__classPrivateFieldGet(self, _Toaster_container, "f").appendChild(toast);
|
|
859
|
+
self.arrangeToasts()
|
|
860
|
+
.then(() => {
|
|
861
|
+
setTimeout(() => {
|
|
862
|
+
let tost = document.querySelector("#" + ID);
|
|
863
|
+
tost.classList.add("showing");
|
|
864
|
+
setTimeout(() => self.dismiss(ID), ((config === null || config === void 0 ? void 0 : config.duration) == undefined ? __classPrivateFieldGet(self, _Toaster_defaultTimeLeft, "f") : (config === null || config === void 0 ? void 0 : config.duration) == -1 ? 86400 : config === null || config === void 0 ? void 0 : config.duration) * 1000);
|
|
865
|
+
setTimeout(() => {
|
|
866
|
+
let tost = document.querySelector("#" + ID);
|
|
867
|
+
tost.classList.remove("showing");
|
|
868
|
+
tost.classList.add("visible");
|
|
869
|
+
}, 200);
|
|
870
|
+
}, 10);
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
arrangeToasts() {
|
|
874
|
+
var self = this, top = __classPrivateFieldGet(self, _Toaster_startTop, "f");
|
|
875
|
+
return new Promise((resolve, reject) => {
|
|
876
|
+
var toasts = document.querySelectorAll(".zuz-toast"), i = toasts.length;
|
|
877
|
+
while (i--) {
|
|
878
|
+
toasts[i]['style'].top = `${top}px`;
|
|
879
|
+
top += parseInt(getComputedStyle(toasts[i]).height.replace('px', '')) + 6;
|
|
880
|
+
}
|
|
881
|
+
resolve(null);
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
_Toaster_container = new WeakMap(), _Toaster_startTop = new WeakMap(), _Toaster_tout = new WeakMap(), _Toaster_defaultTimeLeft = new WeakMap();
|
|
886
|
+
|
|
887
|
+
const useToast = () => {
|
|
888
|
+
const toaster = useMemo(() => new Toaster(), []);
|
|
889
|
+
return toaster;
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
const Button = forwardRef((props, ref) => {
|
|
893
|
+
const { forms } = useStore(state => state[STORE_FORM_KEY], false);
|
|
894
|
+
if (props.html) {
|
|
895
|
+
({ __html: props.html });
|
|
896
|
+
}
|
|
897
|
+
return (jsx(ClassNames, { children: ({ css, cx }) => {
|
|
898
|
+
return (jsx("button", Object.assign({ title: "title" in props ? props.title : undefined, type: props.type, className: `button${props.as ? ` ${props.as}` : ``} ${cx(css `
|
|
2
899
|
padding: 5px 10px;
|
|
3
900
|
border-radius: 2px;
|
|
4
|
-
${buildCSS(
|
|
901
|
+
${buildCSS(props)} &:hover {${buildCSS(props.hover || {})}} &:active {${buildCSS(props.active || {})}}`)}`, ref: ref, onClick: e => {
|
|
902
|
+
if (props.form && props.type && props.type == 'submit') {
|
|
903
|
+
props.onSubmit(forms[props.form]);
|
|
904
|
+
}
|
|
905
|
+
else {
|
|
906
|
+
props.onClick ? props.onClick(e) : () => console.warn('onClick Missing');
|
|
907
|
+
}
|
|
908
|
+
}, disabled: props.disabled || false }, { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children })));
|
|
909
|
+
} }));
|
|
910
|
+
});
|
|
911
|
+
|
|
912
|
+
const makeCSSValue = (k, v, o) => {
|
|
913
|
+
let ignore = cssPropsIgnore.indexOf(o) == -1;
|
|
914
|
+
if (k in cssPropsDirect && ignore == true) {
|
|
915
|
+
// return cssPropsDirect[k];
|
|
916
|
+
return cssPropsDirect[k].indexOf(`__VALUE__`) > -1 ?
|
|
917
|
+
cssPropsDirect[k].replaceAll(`__VALUE__`, `${v}${"number" == typeof v ? `px` : ``}`)
|
|
918
|
+
: cssPropsDirect[k];
|
|
919
|
+
}
|
|
920
|
+
let unit = "number" == typeof v && ignore ? `px` : ``;
|
|
921
|
+
if (cssColors.indexOf(v) > -1) {
|
|
922
|
+
v = `var(--colors-${v.replaceAll(`.`, `-`)})`;
|
|
923
|
+
unit = ``;
|
|
924
|
+
}
|
|
925
|
+
else if (v in cssPropsVals) {
|
|
926
|
+
v = cssPropsVals[v];
|
|
927
|
+
}
|
|
928
|
+
return `${k}:${v}${unit};`;
|
|
929
|
+
};
|
|
930
|
+
const buildCSS = (props) => {
|
|
931
|
+
let css = ``;
|
|
932
|
+
Object.keys(props).map(k => {
|
|
933
|
+
css += k in cssProps ? makeCSSValue(cssProps[k], props[k], k) : '';
|
|
934
|
+
});
|
|
935
|
+
return css;
|
|
936
|
+
};
|
|
937
|
+
const setCSSVar = (key, val) => {
|
|
938
|
+
document.documentElement.style.setProperty(`--${key}`, val);
|
|
939
|
+
};
|
|
940
|
+
const isUrl = (u) => {
|
|
941
|
+
let url;
|
|
942
|
+
try {
|
|
943
|
+
url = new URL(u);
|
|
944
|
+
}
|
|
945
|
+
catch (_) {
|
|
946
|
+
return false;
|
|
947
|
+
}
|
|
948
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
949
|
+
};
|
|
950
|
+
const isEmail = (e) => {
|
|
951
|
+
let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
|
|
952
|
+
return reg.test(e);
|
|
953
|
+
};
|
|
954
|
+
const isIPv4 = (ipaddress) => {
|
|
955
|
+
return /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress);
|
|
956
|
+
};
|
|
957
|
+
const randstr = function (len) {
|
|
958
|
+
var text = "";
|
|
959
|
+
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
960
|
+
len = len || 10;
|
|
961
|
+
for (var i = 0; i < len; i++) {
|
|
962
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
963
|
+
}
|
|
964
|
+
return text;
|
|
965
|
+
};
|
|
966
|
+
const setCookie = (key, value, expiry) => Cookies.set(key, value, { expires: expiry || 7 });
|
|
967
|
+
const getCookie = (key) => Cookies.get(key) || null;
|
|
968
|
+
const removeCookie = (key) => Cookies.remove(key);
|
|
969
|
+
const buildFormData = (data) => {
|
|
970
|
+
var formData = new FormData();
|
|
971
|
+
var _data = Cookies.get();
|
|
972
|
+
Object.keys(_data).map(k => formData.append(k, _data[k]));
|
|
973
|
+
Object.keys(data).filter(x => x != 'files').map(k => formData.append(k, data[k]));
|
|
974
|
+
if ('files' in data)
|
|
975
|
+
[data['files']].map((f) => formData.append('files[]', f));
|
|
976
|
+
return formData;
|
|
977
|
+
};
|
|
978
|
+
const grab = async (uri, data, timeout = 60, fd = null, progress, bearer = `__ha`) => {
|
|
979
|
+
var Bearer = getCookie(bearer) || `${randstr(8)}^${randstr(8)}`;
|
|
980
|
+
window['__grabToken'] = axios.CancelToken.source();
|
|
981
|
+
if (fd) {
|
|
982
|
+
return new Promise((resolve, reject) => {
|
|
983
|
+
axios({
|
|
984
|
+
method: "post",
|
|
985
|
+
url: uri,
|
|
986
|
+
data: buildFormData(data),
|
|
987
|
+
timeout: 1000 * timeout,
|
|
988
|
+
cancelToken: window['__grabToken'].token,
|
|
989
|
+
headers: {
|
|
990
|
+
'Content-Type': 'multipart/form-data',
|
|
991
|
+
'Authorization': `Bearer ${Bearer}`
|
|
992
|
+
},
|
|
993
|
+
onUploadProgress: ev => {
|
|
994
|
+
//TODO: Add progress
|
|
995
|
+
// if(progress) progress(ev.)
|
|
996
|
+
}
|
|
997
|
+
})
|
|
998
|
+
.then(resp => {
|
|
999
|
+
if (resp.data && "kind" in resp.data) {
|
|
1000
|
+
resolve(resp.data);
|
|
1001
|
+
}
|
|
1002
|
+
else {
|
|
1003
|
+
reject(resp.data);
|
|
1004
|
+
}
|
|
1005
|
+
})
|
|
1006
|
+
.catch(err => reject(err));
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
return new Promise((resolve, reject) => {
|
|
1010
|
+
axios.post(uri, Object.assign(Object.assign(Object.assign({}, Cookies.get()), data), { __ustmp: new Date().getTime() / 1000 }), {
|
|
1011
|
+
timeout: 1000 * timeout,
|
|
1012
|
+
headers: {
|
|
1013
|
+
'Content-Type': 'application/json',
|
|
1014
|
+
'Authorization': `Bearer ${Bearer}`
|
|
1015
|
+
},
|
|
1016
|
+
cancelToken: window['__grabToken'].token
|
|
1017
|
+
})
|
|
1018
|
+
.then(resp => {
|
|
1019
|
+
if (resp.data && "kind" in resp.data) {
|
|
1020
|
+
resolve(resp.data);
|
|
1021
|
+
}
|
|
1022
|
+
else {
|
|
1023
|
+
reject(resp.data);
|
|
1024
|
+
}
|
|
1025
|
+
})
|
|
1026
|
+
.catch(err => reject(err));
|
|
1027
|
+
});
|
|
1028
|
+
};
|
|
1029
|
+
const el = (e) => document.querySelector(e);
|
|
1030
|
+
const byName = (e) => document.querySelector(`*[name="${e}"]`);
|
|
1031
|
+
const byId = (e) => document.getElementById(e);
|
|
1032
|
+
const addProps = (children, prop) => {
|
|
1033
|
+
let form = {};
|
|
1034
|
+
let allowedFields = [Input, Select, Button];
|
|
1035
|
+
let child = Children.deepMap(children, c => {
|
|
1036
|
+
if (allowedFields.indexOf(c['type']) > -1 && c['props'] && !form[c['props'].name]) {
|
|
1037
|
+
form[c['props'].name] = c['props'].value || null;
|
|
1038
|
+
}
|
|
1039
|
+
let Clone = cloneElement(c, prop);
|
|
1040
|
+
return Clone;
|
|
1041
|
+
});
|
|
1042
|
+
return {
|
|
1043
|
+
children: child,
|
|
1044
|
+
fields: form
|
|
1045
|
+
};
|
|
1046
|
+
};
|
|
1047
|
+
const ucfirst = (str) => {
|
|
1048
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
1049
|
+
};
|
|
1050
|
+
const filterStyleProps = (props) => {
|
|
1051
|
+
const pks = Object.keys(props);
|
|
1052
|
+
const css = Object.keys(cssProps);
|
|
1053
|
+
let filter = {};
|
|
1054
|
+
css.filter(x => pks.includes(x));
|
|
1055
|
+
// .map(k => filter[k] = props[k].toString());
|
|
1056
|
+
return filter;
|
|
1057
|
+
// const allowed = Object.keys(props);
|
|
1058
|
+
// let allowed = Object.keys(cssProps);
|
|
1059
|
+
// return Object.keys(props)
|
|
1060
|
+
// .filter( k => allowed.includes(k))
|
|
1061
|
+
// .reduce( (o, k) => {
|
|
1062
|
+
// // console.log(o)
|
|
1063
|
+
// console.log(k, props[k])
|
|
1064
|
+
// // o[k] = props[k].toString();
|
|
1065
|
+
// // return o;
|
|
1066
|
+
// })
|
|
1067
|
+
// return [props].filter( row => (
|
|
1068
|
+
// Object.keys(row)
|
|
1069
|
+
// .map(key => css.includes(key))
|
|
1070
|
+
// ));
|
|
1071
|
+
};
|
|
1072
|
+
const filterHTMLProps = (props) => {
|
|
1073
|
+
const pks = Object.keys(props);
|
|
1074
|
+
const css = Object.keys(cssProps);
|
|
1075
|
+
let filter = {};
|
|
1076
|
+
pks.filter(x => {
|
|
1077
|
+
if (x != `for` && !css.includes(x)) {
|
|
1078
|
+
filter[x] = props[x];
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
1081
|
+
return filter;
|
|
1082
|
+
};
|
|
1083
|
+
const uuid = () => nanoid();
|
|
1084
|
+
const addScript = (src, callback) => {
|
|
1085
|
+
var s = document.createElement('script');
|
|
1086
|
+
s.setAttribute('src', src);
|
|
1087
|
+
s.addEventListener('load', callback, false);
|
|
1088
|
+
document.body.appendChild(s);
|
|
1089
|
+
};
|
|
1090
|
+
const shuffleArray = array => {
|
|
1091
|
+
for (let i = array.length - 1; i > 0; i--) {
|
|
1092
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
1093
|
+
[array[i], array[j]] = [array[j], array[i]];
|
|
1094
|
+
}
|
|
1095
|
+
return array;
|
|
1096
|
+
};
|
|
1097
|
+
const getUriParams = () => {
|
|
1098
|
+
var search = location.search.substring(1);
|
|
1099
|
+
if (search == '')
|
|
1100
|
+
return JSON.parse('{}');
|
|
1101
|
+
var xny = {};
|
|
1102
|
+
if ("URLSearchParams" in window) {
|
|
1103
|
+
var items = new URLSearchParams(search);
|
|
1104
|
+
for (const [k, v] of items) {
|
|
1105
|
+
xny[k] = v || ``;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
else {
|
|
1109
|
+
try {
|
|
1110
|
+
xny = JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}');
|
|
1111
|
+
}
|
|
1112
|
+
catch (e) {
|
|
1113
|
+
xny = {};
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
return xny;
|
|
1117
|
+
};
|
|
1118
|
+
const rgb2hex = rgb => `#${rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/).slice(1).map(n => parseInt(n, 10).toString(16).padStart(2, '0')).join('')}`;
|
|
1119
|
+
|
|
1120
|
+
const AppMain = forwardRef((props, ref) => {
|
|
1121
|
+
// const { dispatch } = useStore()
|
|
1122
|
+
// if("theme" in props && !theme){
|
|
1123
|
+
// dispatch(setTheme(props.theme));
|
|
1124
|
+
// }
|
|
1125
|
+
return (jsx(ClassNames, { children: ({ css, cx }) => jsx("main", Object.assign({ className: `${props.as ? props.as : `zuz-app`} ${cx(css `${buildCSS(props)} &:hover {${buildCSS(props.hover || {})}} &:active {${buildCSS(props.active || {})}}`)}` }, { children: props.children })) }));
|
|
1126
|
+
});
|
|
1127
|
+
const App = forwardRef((props, ref) => {
|
|
1128
|
+
return (jsx(AppProvider, { children: jsx(AppMain, {}) }));
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
const Box = forwardRef((props, ref) => {
|
|
1132
|
+
const _noClick = () => { };
|
|
1133
|
+
return (jsx(ClassNames, { children: ({ css, cx }) => jsx("div", Object.assign({ id: props.id || undefined, onClick: props.onClick || _noClick, className: `${props.as ? `${props.as} ` : ``}${cx(css `${buildCSS(props)} &:hover {${buildCSS(props.hover || {})}} &:active {${buildCSS(props.active || {})}}`)}`, ref: props.bref || ref }, { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children })) }));
|
|
1134
|
+
});
|
|
1135
|
+
|
|
1136
|
+
// const CoreBlock = styled.section`display: block;`
|
|
1137
|
+
// const buildComponent = (props: any) => Block.withComponent(props.for || `div`)`${buildCSS(props)}`
|
|
1138
|
+
const Component = forwardRef((props, ref) => {
|
|
1139
|
+
const Tag = props.for;
|
|
1140
|
+
const Block = (typeof props.for == 'string' ?
|
|
1141
|
+
styled[props.for || `div`] : Tag) `${buildCSS(props)}`;
|
|
1142
|
+
// const Block = styled.`${buildCSS(props)}`;
|
|
1143
|
+
// const Block = CoreBlock.withComponent(props.for)`background: red`
|
|
1144
|
+
// console.log(props)
|
|
1145
|
+
// console.log(Styles)
|
|
1146
|
+
// return <button>{props.children}</button>
|
|
1147
|
+
return jsx(Block, Object.assign({ className: props.as || `` }, filterHTMLProps(props)));
|
|
1148
|
+
});
|
|
1149
|
+
|
|
1150
|
+
function Checkbox(props) {
|
|
1151
|
+
const { checked, as, name, form, touched, onChange } = props;
|
|
1152
|
+
const [_checked, setChecked] = useState(checked || false);
|
|
1153
|
+
const theme = useTheme();
|
|
1154
|
+
const dispatch = useDispatch(STORE_FORM_KEY);
|
|
1155
|
+
const { forms } = useStore(state => state[STORE_FORM_KEY], false);
|
|
1156
|
+
const switchCheck = useCallback(() => {
|
|
1157
|
+
let nextVal = !_checked;
|
|
1158
|
+
onChange && onChange(nextVal);
|
|
1159
|
+
setChecked(nextVal);
|
|
1160
|
+
dispatch(dispatch(UPDATE_FORM_FIELD(form || 'orphan', name, nextVal, forms)));
|
|
1161
|
+
}, [_checked]);
|
|
1162
|
+
const defaultCSS = `cursor: pointer;&:before {
|
|
1163
|
+
background: ${!_checked ? `transparent` : theme.color} !important;
|
|
1164
|
+
}`;
|
|
1165
|
+
const _name = useMemo(() => name || nanoid(), [name]);
|
|
1166
|
+
return (jsx(ClassNames, { children: ({ css, cx }) => jsxs(Fragment, { children: [jsx("input", { onChange: switchCheck, id: `zuz${_name}`,
|
|
1167
|
+
// className={`${_checked ? 'y' : 'n'} ${as ? ` ${as} ` : ``}f ${cx(css`opacity: 0;position: absolute;&:checked {${defaultCSSChecked}}`)}`}
|
|
1168
|
+
className: `zuz-checkbox`, name: _name, type: `checkbox`, value: `checked` }), jsx("label", { className: `${as ? `${as} ` : ``}f ${cx(css `${defaultCSS}`)}`, htmlFor: `zuz${_name}` })] }) })
|
|
1169
|
+
// <Button
|
|
1170
|
+
// overflow={`hidden`}
|
|
1171
|
+
// name={name || nanoid()}
|
|
1172
|
+
// onClick={switchCheck}
|
|
1173
|
+
// w={38} h={22} r={20} bg={`#ddd`} rel>
|
|
1174
|
+
// <Box w={38} h={22} anim={`0.2`} abs top={0} r={20} left={0} transform={`translateX(${_checked ? 0 : -16}px)`} bg={theme.color}>
|
|
1175
|
+
// <Box w={18} h={18} abs right={2} top={2} bg={`#fff`} r={20} boxShadow={`0px 0px 0px 5px ${_checked ? theme.color : `#ddd`}`} />
|
|
1176
|
+
// </Box>
|
|
1177
|
+
// </Button>
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
const Spinner = (props) => {
|
|
1182
|
+
return (jsxs(Box, Object.assign({ rel: true, w: props.size, h: props.size, zIndex: `1`, useSelect: `none` }, { children: [jsx(Box, { abs: true, as: `spinner rotating`, animationDirection: `reverse`, animationDuration: typeof props.s1 == `string` ? props.s1 : `${props.s1}s`, w: props.size, r: props.radius, h: props.size, bg: props.color, opacity: 0.2 }), jsx(Box, { abs: true, as: `spinner rotating`, animationDuration: typeof props.s2 == `string` ? props.s2 : `${props.s2}s`, w: props.size, r: props.radius, h: props.size, bg: props.color, opacity: 0.5 })] })));
|
|
1183
|
+
};
|
|
1184
|
+
Spinner.defaultProps = {
|
|
1185
|
+
size: 30,
|
|
1186
|
+
radius: 4,
|
|
1187
|
+
color: `black`,
|
|
1188
|
+
s1: `5s`,
|
|
1189
|
+
s2: `1s`
|
|
1190
|
+
};
|
|
1191
|
+
Spinner.propTypes = {
|
|
1192
|
+
size: PropTypes.number.isRequired,
|
|
1193
|
+
color: PropTypes.string,
|
|
1194
|
+
radius: PropTypes.number,
|
|
1195
|
+
s1: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
1196
|
+
s2: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
1197
|
+
};
|
|
1198
|
+
|
|
1199
|
+
const Heading = forwardRef((props, ref) => {
|
|
1200
|
+
const { children, as, h } = props;
|
|
1201
|
+
let Tag = `h${h || 1}`;
|
|
1202
|
+
const HeadingTag = Tag;
|
|
1203
|
+
return (jsx(ClassNames, { children: ({ css, cx }) => jsx(HeadingTag, Object.assign({ className: `${as ? `${as} ` : ``}${cx(css `${buildCSS(props)}`)}`, ref: ref }, { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : children })) }));
|
|
1204
|
+
});
|
|
1205
|
+
|
|
1206
|
+
const Cover = (props) => {
|
|
1207
|
+
return (jsx(Box, Object.assign({ abs: true, fill: true, bgFilter: props.backdrop ? `saturate(${props.backdrop.saturate}%) blur(${props.backdrop.blur}px)` : undefined, zIndex: `2`, bg: props.bg }, { children: jsxs(Box, Object.assign({ abs: true, abc: true, aic: true, jcc: true, flex: true, dir: `cols`, gap: 20 }, { children: [jsx(Spinner, {}, `cover-spinner`), props.label && jsx(Heading, Object.assign({ size: 16, as: `f`, opacity: 0.7 }, { children: props.label }), `cover-label`)] }), `cover-shadow`) }), `cover-cloud`));
|
|
1208
|
+
};
|
|
1209
|
+
Cover.defaultProps = {
|
|
1210
|
+
bg: `rgba(0,0,0,0.5)`,
|
|
1211
|
+
backdrop: { saturate: 80, blur: 10 },
|
|
1212
|
+
label: null
|
|
1213
|
+
};
|
|
1214
|
+
Cover.propTypes = {
|
|
1215
|
+
bg: PropTypes.string,
|
|
1216
|
+
backdrop: PropTypes.object,
|
|
1217
|
+
label: PropTypes.string,
|
|
1218
|
+
};
|
|
1219
|
+
|
|
1220
|
+
const Form = forwardRef((props, ref) => {
|
|
1221
|
+
var _a;
|
|
1222
|
+
const { name, children, onSubmit, cover, debug } = props;
|
|
1223
|
+
const [_html, setHTML] = useState(null);
|
|
1224
|
+
const [_loading, setLoading] = useState((debug === null || debug === void 0 ? void 0 : debug.loading) || false);
|
|
1225
|
+
const dispatch = useDispatch(STORE_FORM_KEY);
|
|
1226
|
+
const { forms } = useStore(state => state[STORE_FORM_KEY], false);
|
|
1227
|
+
const buildFields = () => {
|
|
1228
|
+
return addProps(children, { form: name, touched: undefined, loading: undefined, onSubmit: onSubmit ? onSubmit : () => console.log(`onSubmit Missing`) });
|
|
1229
|
+
};
|
|
1230
|
+
const update = (e) => Object.keys(e).map(k => {
|
|
1231
|
+
dispatch(UPDATE_FORM_FIELD(name || 'orphan', k, e[k], forms));
|
|
1232
|
+
if (k == 'loading')
|
|
1233
|
+
setLoading(e[k]);
|
|
1234
|
+
});
|
|
1235
|
+
const get = (k) => forms[name][k] || null;
|
|
1236
|
+
useImperativeHandle(ref, () => ({
|
|
1237
|
+
update,
|
|
1238
|
+
get
|
|
1239
|
+
}));
|
|
1240
|
+
useEffect(() => {
|
|
1241
|
+
if (!forms[name]) {
|
|
1242
|
+
let f = buildFields();
|
|
1243
|
+
setHTML(f.children);
|
|
1244
|
+
dispatch(ADD_FORM(name, f.fields, forms));
|
|
1245
|
+
}
|
|
1246
|
+
}, [children, (_a = forms[name]) === null || _a === void 0 ? void 0 : _a.loading]);
|
|
1247
|
+
return createElement(Box, Object.assign(Object.assign({ rel: true }, props), { as: name }), [
|
|
1248
|
+
_loading ? jsx(Cover, { backdrop: (cover === null || cover === void 0 ? void 0 : cover.filter) || { saturate: 80, blur: 10 }, bg: (cover === null || cover === void 0 ? void 0 : cover.bg) || `rgba(0,0,0,0.5)` }, `form-${name}-cover`) : null,
|
|
1249
|
+
_html
|
|
1250
|
+
]);
|
|
1251
|
+
});
|
|
1252
|
+
Form.defaultProps = {
|
|
1253
|
+
name: 'form1',
|
|
1254
|
+
onSubmit: () => { console.log(`onSubmit not provided`); }
|
|
1255
|
+
};
|
|
1256
|
+
Form.propTypes = {
|
|
1257
|
+
name: PropTypes.string.isRequired,
|
|
1258
|
+
children: PropTypes.node.isRequired,
|
|
1259
|
+
onSubmit: PropTypes.func.isRequired
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1262
|
+
const Icon = forwardRef((props, ref) => {
|
|
1263
|
+
const { as, path, size, color, hover } = props;
|
|
1264
|
+
return (jsx(Box, Object.assign({ hover: hover || {}, flex: true, bref: ref, as: `icon-${as}`, ai: `c`, jc: `c`, size: size || 24, color: color || `#111111` }, { children: path && Array(path).fill(undefined).map((p, i) => jsx("span", { className: `path${i + 1}` }, `ico-${as}-${i}`)) })));
|
|
1265
|
+
});
|
|
1266
|
+
|
|
1267
|
+
const Image = forwardRef((props, ref) => {
|
|
1268
|
+
const [photo, status] = useImage(props.src, 'anonymous', 'origin');
|
|
1269
|
+
return (jsx(ClassNames, { children: ({ css, cx }) => jsxs("picture", Object.assign({ className: cx(css `${buildCSS({ flex: true })}`) }, { children: [status == 'loading' && jsx(Box, { className: `${props.as ? `${props.as} ` : ``}${cx(css `background: #eee;${buildCSS(props)}`)}` }), status == 'loaded' && jsx("img", { src: props.src, className: `${props.as ? `${props.as} ` : ``}${cx(css `${buildCSS(props)}`)}`, ref: ref })] })) }));
|
|
1270
|
+
});
|
|
1271
|
+
|
|
1272
|
+
const calcPlaceholderStyle = (width, height, duration = 1600) => ({
|
|
1273
|
+
backgroundSize: `${parseInt(width.toString()) * 10}px ${height}px`,
|
|
1274
|
+
animationDuration: `${(duration / 1000).toFixed(1)}s`,
|
|
1275
|
+
});
|
|
1276
|
+
const Placeholder = forwardRef(({ width, height, duration, bg, bgFrom, bgTo }, ref) => {
|
|
1277
|
+
const placeholderStyle = calcPlaceholderStyle(width, height, duration);
|
|
1278
|
+
return (jsx(Box, { as: `shimmer`, w: width, h: height, bg: bg || `#f6f7f8`, backgroundImage: `linear-gradient(to right, ${bgFrom || `rgb(238, 238, 238)`} 8%, ${bgTo || `rgb(203, 203, 203)`} 18%, ${bgFrom || `rgb(238, 238, 238)`} 33%);`, backgroundSize: placeholderStyle.backgroundSize, animationDuration: placeholderStyle.animationDuration }));
|
|
1279
|
+
});
|
|
1280
|
+
Placeholder.propTypes = {
|
|
1281
|
+
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
1282
|
+
height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
1283
|
+
duration: PropTypes.number,
|
|
1284
|
+
bg: PropTypes.string,
|
|
1285
|
+
bgFrom: PropTypes.string,
|
|
1286
|
+
bgTo: PropTypes.string
|
|
1287
|
+
};
|
|
1288
|
+
|
|
1289
|
+
const Spacer = ({ w, h }) => {
|
|
1290
|
+
return (jsx(Box, { as: `spacer`, w: w || 0, h: h || 0 }));
|
|
1291
|
+
};
|
|
1292
|
+
|
|
1293
|
+
const Text = forwardRef((props, ref) => {
|
|
1294
|
+
const { children, as } = props;
|
|
1295
|
+
return (jsx(ClassNames, { children: ({ css, cx }) => jsx("p", Object.assign({ className: `${as ? `${as} ` : ``}${cx(css `${buildCSS(props)}`)}`, ref: ref }, { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : children })) }));
|
|
1296
|
+
});
|
|
1297
|
+
|
|
1298
|
+
const Tweet = (props) => {
|
|
1299
|
+
const [rand, setRand] = useState(Math.random());
|
|
1300
|
+
const _tweet = useRef();
|
|
1301
|
+
const renderTweet = () => {
|
|
1302
|
+
const twttr = window['twttr'];
|
|
1303
|
+
twttr.ready().then(({ widgets }) => {
|
|
1304
|
+
const { options, onTweetLoadSuccess, onTweetLoadError } = props;
|
|
1305
|
+
widgets
|
|
1306
|
+
.createTweetEmbed(props.id, _tweet.current, options || {})
|
|
1307
|
+
.then((twitterWidgetElement) => {
|
|
1308
|
+
// this.setState({
|
|
1309
|
+
// isLoading: false
|
|
1310
|
+
// })
|
|
1311
|
+
// onTweetLoadSuccess && onTweetLoadSuccess(twitterWidgetElement)
|
|
1312
|
+
})
|
|
1313
|
+
.catch(() => { });
|
|
1314
|
+
});
|
|
1315
|
+
};
|
|
1316
|
+
useEffect(() => {
|
|
1317
|
+
const twttr = window['twttr'];
|
|
1318
|
+
if (!(twttr && twttr.ready)) {
|
|
1319
|
+
addScript(`https://platform.twitter.com/widgets.js`, renderTweet);
|
|
1320
|
+
}
|
|
1321
|
+
else {
|
|
1322
|
+
renderTweet();
|
|
1323
|
+
}
|
|
1324
|
+
}, []);
|
|
1325
|
+
useEffect(() => {
|
|
1326
|
+
}, [rand]);
|
|
1327
|
+
return (jsx(Box, { as: `tweet`, weight: 1, bref: _tweet }));
|
|
1328
|
+
};
|
|
1329
|
+
|
|
1330
|
+
export { App, Component as Block, Box, Button, Checkbox, Cover, Form, Heading, Icon, Image, Input, Placeholder, AppProvider as Provider, Select, Spacer, Spinner, Text, Toaster, Tweet, addProps, addScript, buildCSS, buildFormData, byId, byName, createSlice, el, filterHTMLProps, filterStyleProps, getCookie, getUriParams, grab, isEmail, isIPv4, isUrl, randstr, removeCookie, rgb2hex, setCSSVar, setCookie, shuffleArray, ucfirst, useDevice, useDispatch, useImage, useResizeObserver, useStore, useTheme, useToast, uuid };
|