@zuzjs/ui 0.3.2 → 0.3.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 CHANGED
@@ -7,7 +7,6 @@ import axios from 'axios';
7
7
  import { nanoid } from 'nanoid';
8
8
  import { ClassNames } from '@emotion/react';
9
9
  import ReactDOM from 'react-dom/client';
10
- export { Link } from 'react-router-dom';
11
10
  import styled from '@emotion/styled';
12
11
 
13
12
  const AppContext = createContext({});
@@ -50,7 +49,12 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
50
49
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
51
50
  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");
52
51
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
53
- }
52
+ }
53
+
54
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
55
+ var e = new Error(message);
56
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
57
+ };
54
58
 
55
59
  var _AppTheme_mode, _AppTheme_listen, _AppTheme_lightTheme, _AppTheme_darkTheme;
56
60
  class AppTheme {
@@ -62,11 +66,11 @@ class AppTheme {
62
66
  this.get = () => {
63
67
  let self = this;
64
68
  if (__classPrivateFieldGet(self, _AppTheme_mode, "f") === "auto") {
65
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
69
+ typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
66
70
  __classPrivateFieldSet(self, _AppTheme_mode, event.matches ? "dark" : "light", "f");
67
71
  __classPrivateFieldGet(self, _AppTheme_listen, "f").call(self, __classPrivateFieldGet(self, _AppTheme_mode, "f"));
68
72
  });
69
- return window.matchMedia &&
73
+ return typeof window !== 'undefined' && window.matchMedia &&
70
74
  window.matchMedia('(prefers-color-scheme: dark)').matches ?
71
75
  __classPrivateFieldGet(self, _AppTheme_darkTheme, "f") : __classPrivateFieldGet(self, _AppTheme_lightTheme, "f");
72
76
  }
@@ -155,7 +159,7 @@ const AppProvider = ({ children, initialState = {}, theme = {}, lang = {} }) =>
155
159
  // }
156
160
  // }, [_dispatch]);
157
161
  const providedValue = useMemo(() => (Object.assign(Object.assign({}, state), { dispatch })), [state]);
158
- return jsx(AppContext.Provider, Object.assign({ value: providedValue }, { children: children }));
162
+ return jsx(AppContext.Provider, { value: providedValue, children: children });
159
163
  };
160
164
  AppProvider.defaultProps = {
161
165
  theme: {},
@@ -592,7 +596,7 @@ const UPDATE_FORM_FIELD = (formName, field, value, forms) => {
592
596
  return {};
593
597
  };
594
598
 
595
- !!document.documentElement.currentStyle;
599
+ typeof window !== "undefined" && !!document.documentElement.currentStyle;
596
600
  const Input = forwardRef((props, ref) => {
597
601
  const { as, accept, multiple, onChange, onKeyUp, onClick, onBlur, onFocus, readOnly, type, tag, placeholder, name, form, touched, onSubmit, value, defaultValue, fref, autoComplete, elastic, minRows, maxRows } = props;
598
602
  const dispatch = useDispatch(STORE_FORM_KEY);
@@ -642,12 +646,12 @@ const Select = forwardRef((props, ref) => {
642
646
  var _a;
643
647
  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)));
644
648
  }, []);
645
- return (jsx(ClassNames, { children: ({ css, cx }) => jsx("select", Object.assign({ onChange: e => {
649
+ return (jsx(ClassNames, { children: ({ css, cx }) => jsx("select", { onChange: e => {
646
650
  let val = e.currentTarget.value;
647
651
  dispatch(dispatch(UPDATE_FORM_FIELD(form || 'orphan', name, val, forms)));
648
652
  onChange && onChange(val);
649
653
  }, onFocus: e => touched == false && dispatch(UPDATE_FORM_FIELD(form || 'orphan', `touched`, true, forms)), onBlur: e => {
650
- }, 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}`)) })) }));
654
+ }, 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", { value: o.value, children: o.label }, `select-${name}-option-${o.value}`)) }) }));
651
655
  });
652
656
 
653
657
  const useTheme = (mod = 'auto') => {
@@ -784,6 +788,7 @@ const EMPTY_BREAKPOINT = {
784
788
  minWidth: undefined,
785
789
  maxWidth: undefined,
786
790
  };
791
+ const isBrowser = typeof window !== 'undefined';
787
792
  const useDevice = (config, defaultBreakpoint, hydrateInitial = true) => {
788
793
  const buildQueries = (breakpoints) => {
789
794
  const sorted = Object.keys(breakpoints).sort((a, b) => breakpoints[b] - breakpoints[a]);
@@ -824,7 +829,7 @@ const useDevice = (config, defaultBreakpoint, hydrateInitial = true) => {
824
829
  */
825
830
  if (typeof window !== 'undefined' &&
826
831
  !(defaultBreakpoint && hydrateInitial)) {
827
- const mediaQuery = window.matchMedia(query);
832
+ const mediaQuery = window === null || window === void 0 ? void 0 : window.matchMedia(query);
828
833
  if (mediaQuery.matches) {
829
834
  return breakpoint;
830
835
  }
@@ -844,32 +849,34 @@ const useDevice = (config, defaultBreakpoint, hydrateInitial = true) => {
844
849
  }, []);
845
850
  /** On changes to mediaQueries, subscribe to changes using window.matchMedia */
846
851
  useChooseEffect(() => {
847
- const unsubscribers = mediaQueries.map((_a) => {
848
- var { query } = _a, breakpoint = __rest(_a, ["query"]);
849
- const list = window.matchMedia(query);
850
- updateBreakpoint(list, breakpoint);
851
- const handleChange = (event) => {
852
- updateBreakpoint(event, breakpoint);
853
- };
854
- const supportsNewEventListeners = 'addEventListener' in list && 'removeEventListener' in list;
855
- if (supportsNewEventListeners) {
856
- list.addEventListener('change', handleChange);
857
- }
858
- else {
859
- list.addListener(handleChange);
860
- }
861
- /** Map the unsubscribers array to a list of unsubscriber methods */
862
- return () => {
852
+ if (isBrowser) {
853
+ const unsubscribers = mediaQueries.map((_a) => {
854
+ var { query } = _a, breakpoint = __rest(_a, ["query"]);
855
+ const list = window.matchMedia(query);
856
+ updateBreakpoint(list, breakpoint);
857
+ const handleChange = (event) => {
858
+ updateBreakpoint(event, breakpoint);
859
+ };
860
+ const supportsNewEventListeners = 'addEventListener' in list && 'removeEventListener' in list;
863
861
  if (supportsNewEventListeners) {
864
- list.removeEventListener('change', handleChange);
862
+ list.addEventListener('change', handleChange);
865
863
  }
866
864
  else {
867
- list.removeListener(handleChange);
865
+ list.addListener(handleChange);
868
866
  }
869
- };
870
- });
871
- /** Return a function that when called, will call all unsubscribers */
872
- return () => unsubscribers.forEach((unsubscriber) => unsubscriber());
867
+ /** Map the unsubscribers array to a list of unsubscriber methods */
868
+ return () => {
869
+ if (supportsNewEventListeners) {
870
+ list.removeEventListener('change', handleChange);
871
+ }
872
+ else {
873
+ list.removeListener(handleChange);
874
+ }
875
+ };
876
+ });
877
+ /** Return a function that when called, will call all unsubscribers */
878
+ return () => unsubscribers.forEach((unsubscriber) => unsubscriber());
879
+ }
873
880
  }, [mediaQueries, updateBreakpoint]);
874
881
  /** Print a nice debug value for React Devtools */
875
882
  useDebugValue(currentBreakpoint, (c) => typeof c.breakpoint === 'string'
@@ -897,12 +904,15 @@ class Toaster {
897
904
  __classPrivateFieldSet(this, _Toaster_defaultTimeLeft, 4, "f");
898
905
  const rootID = (config === null || config === void 0 ? void 0 : config.root) || `toast-container`;
899
906
  __classPrivateFieldSet(this, _Toaster_root, rootID, "f");
900
- if (window.document.querySelector(`#${rootID}`))
907
+ this.addRoot();
908
+ }
909
+ addRoot() {
910
+ if (window.document.querySelector(`#${__classPrivateFieldGet(this, _Toaster_root, "f")}`))
901
911
  return;
902
912
  var root = window.document.createElement('div');
903
- root.id = rootID;
913
+ root.id = __classPrivateFieldGet(this, _Toaster_root, "f");
904
914
  window.document.body.appendChild(root);
905
- __classPrivateFieldSet(this, _Toaster_container, window.document.querySelector(`#${rootID}`), "f");
915
+ __classPrivateFieldSet(this, _Toaster_container, window.document.querySelector(`#${__classPrivateFieldGet(this, _Toaster_root, "f")}`), "f");
906
916
  }
907
917
  dismiss(ID) {
908
918
  let self = this;
@@ -922,6 +932,7 @@ class Toaster {
922
932
  }
923
933
  toast(config) {
924
934
  var self = this;
935
+ self.addRoot();
925
936
  var ID = 'toast-' + nanoid(), toast = window.document.createElement('div'); window.document.createElement('div');
926
937
  toast.id = ID;
927
938
  toast.style.backgroundColor = `#111`;
@@ -979,7 +990,7 @@ const useLang = (mod = 'en') => {
979
990
  const Box = forwardRef((props, ref) => {
980
991
  const _noClick = () => { };
981
992
  // console.log(props)
982
- return (jsx(ClassNames, { children: ({ css, cx }) => jsx("div", Object.assign({}, cleanProps(props), { title: props.title || undefined, id: props.id || undefined, onDoubleClick: props.onDoubleClick || 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 })) }));
993
+ return (jsx(ClassNames, { children: ({ css, cx }) => jsx("div", Object.assign({}, cleanProps(props), { title: props.title || undefined, id: props.id || undefined, onDoubleClick: props.onDoubleClick || 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 })) }));
983
994
  });
984
995
 
985
996
  const Menu = ({ ID, hide, e, items, width }) => {
@@ -1001,7 +1012,7 @@ const Menu = ({ ID, hide, e, items, width }) => {
1001
1012
  useEffect(() => {
1002
1013
  checkBoundaries(p.x, p.y);
1003
1014
  }, [e]);
1004
- return (jsx(Box, Object.assign({ bref: nodeRef, flex: true, dir: `cols`, fixed: true, top: p.y, left: p.x, w: width || 220, opacity: visible ? 1 : 0, as: `zuz-contextmenu ${ID}` }, { children: items.map((m, i) => m.id == `line` ? jsx(Box, { as: `line` }, `line-${i}-${m.id}`) : jsx("button", Object.assign({ onClick: ev => {
1015
+ return (jsx(Box, { bref: nodeRef, flex: true, dir: `cols`, fixed: true, top: p.y, left: p.x, w: width || 220, opacity: visible ? 1 : 0, as: `zuz-contextmenu ${ID}`, children: items.map((m, i) => m.id == `line` ? jsx(Box, { as: `line` }, `line-${i}-${m.id}`) : jsx("button", { onClick: ev => {
1005
1016
  if (m.onClick) {
1006
1017
  m.onClick(ev, m);
1007
1018
  }
@@ -1009,7 +1020,7 @@ const Menu = ({ ID, hide, e, items, width }) => {
1009
1020
  console.log(`No onClick eventFound`);
1010
1021
  }
1011
1022
  hide();
1012
- } }, { children: m.label }), `cm-${i}-${m.id}`)) })));
1023
+ }, children: m.label }, `cm-${i}-${m.id}`)) }));
1013
1024
  };
1014
1025
  const useContextMenu = (contextID, contextWidth, contextToken = `____uchides`) => {
1015
1026
  const ID = `contextmenu-${contextID}`;
@@ -1104,7 +1115,7 @@ const Button = forwardRef((props, ref) => {
1104
1115
  else {
1105
1116
  props.onClick ? props.onClick(e) : () => console.warn('onClick Missing');
1106
1117
  }
1107
- }, disabled: props.disabled || false }, { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children })));
1118
+ }, disabled: props.disabled || false, children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children })));
1108
1119
  } }));
1109
1120
  });
1110
1121
 
@@ -1258,7 +1269,7 @@ const buildFormData = (data) => {
1258
1269
  [data['files']].map((f) => formData.append('files[]', f));
1259
1270
  return formData;
1260
1271
  };
1261
- const grab = async (uri, data, timeout = 60, fd = null, progress, bearer = `__ha`) => {
1272
+ const withRest = async (uri, data, timeout = 60, fd = null, progress, bearer = `__ha`) => {
1262
1273
  var Bearer = getCookie(bearer) || `${randstr(8)}^${randstr(8)}`;
1263
1274
  window['__grabToken'] = axios.CancelToken.source();
1264
1275
  if (fd) {
@@ -1514,7 +1525,7 @@ const AppMain = forwardRef((props, ref) => {
1514
1525
  // if("theme" in props && !theme){
1515
1526
  // dispatch(setTheme(props.theme));
1516
1527
  // }
1517
- 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 })) }));
1528
+ return (jsx(ClassNames, { children: ({ css, cx }) => jsx("main", { className: `${props.as ? props.as : `zuz-app`} ${cx(css `${buildCSS(props)} &:hover {${buildCSS(props.hover || {})}} &:active {${buildCSS(props.active || {})}}`)}`, children: props.children }) }));
1518
1529
  });
1519
1530
  const App = forwardRef((props, ref) => {
1520
1531
  return (jsx(AppProvider, { children: jsx(AppMain, {}) }));
@@ -1566,7 +1577,7 @@ function Checkbox(props) {
1566
1577
  }
1567
1578
 
1568
1579
  const Spinner = (props) => {
1569
- 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 })] })));
1580
+ return (jsxs(Box, { 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 })] }));
1570
1581
  };
1571
1582
  Spinner.defaultProps = {
1572
1583
  size: 30,
@@ -1587,11 +1598,11 @@ const Heading = forwardRef((props, ref) => {
1587
1598
  const { children, as, h } = props;
1588
1599
  let Tag = `h${h || 1}`;
1589
1600
  const HeadingTag = Tag;
1590
- 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 })) }));
1601
+ return (jsx(ClassNames, { children: ({ css, cx }) => jsx(HeadingTag, { className: `${as ? `${as} ` : ``}${cx(css `${buildCSS(props)}`)}`, ref: ref, children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : children }) }));
1591
1602
  });
1592
1603
 
1593
1604
  const Cover = (props) => {
1594
- 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`));
1605
+ return (jsx(Box, { 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, { abs: true, abc: true, aic: true, jcc: true, flex: true, dir: `cols`, gap: 20, children: [jsx(Spinner, {}, `cover-spinner`), props.label && jsx(Heading, { size: 16, as: `f`, opacity: 0.7, children: props.label }, `cover-label`)] }, `cover-shadow`) }, `cover-cloud`));
1595
1606
  };
1596
1607
  Cover.defaultProps = {
1597
1608
  bg: `rgba(0,0,0,0.5)`,
@@ -1648,7 +1659,7 @@ Form.propTypes = {
1648
1659
 
1649
1660
  const Icon = forwardRef((props, ref) => {
1650
1661
  const { as, path, size, color, hover } = props;
1651
- 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}`)) })));
1662
+ return (jsx(Box, { 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}`)) }));
1652
1663
  });
1653
1664
 
1654
1665
  const Image$1 = forwardRef((props, ref) => {
@@ -1786,7 +1797,7 @@ class Masonry extends Component$1 {
1786
1797
  classNameOutput = 'my-masonry-grid';
1787
1798
  }
1788
1799
  }
1789
- return (jsx("div", Object.assign({}, rest, { className: classNameOutput }, { children: this.renderColumns() })));
1800
+ return (jsx("div", Object.assign({}, rest, { className: classNameOutput, children: this.renderColumns() })));
1790
1801
  }
1791
1802
  }
1792
1803
 
@@ -1813,7 +1824,7 @@ const Spacer = ({ w, h }) => {
1813
1824
 
1814
1825
  const Text = forwardRef((props, ref) => {
1815
1826
  const { children, as } = props;
1816
- 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 })) }));
1827
+ return (jsx(ClassNames, { children: ({ css, cx }) => jsx("p", { className: `${as ? `${as} ` : ``}${cx(css `${buildCSS(props)}`)}`, ref: ref, children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : children }) }));
1817
1828
  });
1818
1829
 
1819
1830
  const Tweet = (props) => {
@@ -1865,4 +1876,4 @@ const Header = forwardRef((props, ref) => {
1865
1876
  return (jsx(Fragment, { children: buildComponent(data) }));
1866
1877
  });
1867
1878
 
1868
- export { App, Component as Block, Box, Button, Checkbox, Cover, Form, Header, Heading, Icon, Image$1 as Image, Input, Masonry, Placeholder, AppProvider as Provider, Select, Spacer, Spinner, Text, Toaster, Tweet, addProps, addScript, buildCSS, buildFormData, byId, byName, camelCase, cleanProps, copyToClipboard, createSlice, el, filterHTMLProps, filterStyleProps, formatSize, generateModalRoutes, generatePreservedRoutes, generateRegularRoutes, getCookie, getHostname, getMousePosition, getUriParams, grab, imgPromiseFactory, isEmail, isIPv4, isUrl, parseFilename, randstr, removeCookie, rgb2hex, setCSSVar, setCookie, shuffleArray, slugify, ucfirst, useContextMenu, useDevice, useDispatch, useImage, useLang, useRender, useResizeObserver, useStore, useTheme, useToast, uuid };
1879
+ export { App, Component as Block, Box, Button, Checkbox, Cover, Form, Header, Heading, Icon, Image$1 as Image, Input, Masonry, Placeholder, AppProvider as Provider, Select, Spacer, Spinner, Text, Toaster, Tweet, addProps, addScript, buildCSS, buildFormData, byId, byName, camelCase, cleanProps, copyToClipboard, createSlice, el, filterHTMLProps, filterStyleProps, formatSize, generateModalRoutes, generatePreservedRoutes, generateRegularRoutes, getCookie, getHostname, getMousePosition, getUriParams, imgPromiseFactory, isEmail, isIPv4, isUrl, parseFilename, randstr, removeCookie, rgb2hex, setCSSVar, setCookie, shuffleArray, slugify, ucfirst, useContextMenu, useDevice, useDispatch, useImage, useLang, useRender, useResizeObserver, useStore, useTheme, useToast, uuid, withRest };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuzjs/ui",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -67,7 +67,7 @@ export type SizingData = {
67
67
  borderSize: number;
68
68
  };
69
69
 
70
- const isIE = !!(document.documentElement as any).currentStyle
70
+ const isIE = typeof window !== "undefined" && !!(document.documentElement as any).currentStyle
71
71
 
72
72
  const getSizingData = (node: HTMLElement): SizingData | null => {
73
73
 
@@ -16,12 +16,17 @@ class Toaster {
16
16
  this.#defaultTimeLeft = 4
17
17
  const rootID = config?.root || `toast-container`;
18
18
  this.#root = rootID;
19
- if(window.document.querySelector(`#${rootID}`)) return;
20
- var self = this;
19
+
20
+ this.addRoot();
21
+
22
+ }
23
+
24
+ addRoot(){
25
+ if(window.document.querySelector(`#${this.#root}`)) return;
21
26
  var root = window.document.createElement('div');
22
- root.id = rootID;
23
- window.document.body.appendChild(root);
24
- this.#container = window.document.querySelector(`#${rootID}`)
27
+ root.id = this.#root;
28
+ window.document.body.appendChild(root);
29
+ this.#container = window.document.querySelector(`#${this.#root}`)
25
30
  }
26
31
 
27
32
  show = (
@@ -57,6 +62,7 @@ class Toaster {
57
62
  }){
58
63
 
59
64
  var self = this;
65
+ self.addRoot();
60
66
  var tout = null,
61
67
  ID = 'toast-' + nanoid(),
62
68
  toast = window.document.createElement('div'),
@@ -32,11 +32,11 @@ class AppTheme {
32
32
  get = () => {
33
33
  let self = this;
34
34
  if(self.#mode === "auto"){
35
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
35
+ typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
36
36
  self.#mode = event.matches ? "dark" : "light";
37
37
  self.#listen(self.#mode);
38
38
  });
39
- return window.matchMedia &&
39
+ return typeof window !== 'undefined' && window.matchMedia &&
40
40
  window.matchMedia('(prefers-color-scheme: dark)').matches ?
41
41
  self.#darkTheme : self.#lightTheme;
42
42
  }else{
package/src/core/index.ts CHANGED
@@ -105,7 +105,7 @@ const buildFormData = (data : object) : FormData => {
105
105
  return formData;
106
106
  }
107
107
 
108
- const grab = async (uri : string, data : object, timeout : number = 60, fd : object = null, progress? : Function, bearer : string = `__ha`) => {
108
+ const withRest = async (uri : string, data : object, timeout : number = 60, fd : object = null, progress? : Function, bearer : string = `__ha`) => {
109
109
  var Bearer = getCookie(bearer) || `${randstr(8)}^${randstr(8)}`;
110
110
  window['__grabToken'] = axios.CancelToken.source();
111
111
  if(fd){
@@ -400,7 +400,7 @@ export {
400
400
  byName,
401
401
  byId,
402
402
  el,
403
- grab,
403
+ withRest,
404
404
  isEmail,
405
405
  isIPv4,
406
406
  isUrl,
@@ -30,6 +30,8 @@ type Return<C extends Config, D> = D extends undefined
30
30
  ? Breakpoint<C>
31
31
  : never
32
32
 
33
+ const isBrowser = typeof window !== 'undefined'
34
+
33
35
  const useDevice = <C extends Config, D extends keyof C | undefined>(
34
36
  config: C,
35
37
  defaultBreakpoint?: D,
@@ -89,7 +91,7 @@ const useDevice = <C extends Config, D extends keyof C | undefined>(
89
91
  typeof window !== 'undefined' &&
90
92
  !(defaultBreakpoint && hydrateInitial)
91
93
  ) {
92
- const mediaQuery = window.matchMedia(query)
94
+ const mediaQuery = window?.matchMedia(query)
93
95
  if (mediaQuery.matches) {
94
96
  return breakpoint as Breakpoint<C>
95
97
  }
@@ -117,35 +119,37 @@ const useDevice = <C extends Config, D extends keyof C | undefined>(
117
119
 
118
120
  /** On changes to mediaQueries, subscribe to changes using window.matchMedia */
119
121
  useChooseEffect(() => {
120
- const unsubscribers = mediaQueries.map(({ query, ...breakpoint }) => {
121
- const list = window.matchMedia(query)
122
- updateBreakpoint(list, breakpoint as Breakpoint<C>)
123
-
124
- const handleChange = (event: MediaQueryListEvent) => {
125
- updateBreakpoint(event, breakpoint as Breakpoint<C>)
126
- }
122
+ if (isBrowser) {
123
+ const unsubscribers = mediaQueries.map(({ query, ...breakpoint }) => {
124
+ const list = window.matchMedia(query)
125
+ updateBreakpoint(list, breakpoint as Breakpoint<C>)
127
126
 
128
- const supportsNewEventListeners =
129
- 'addEventListener' in list && 'removeEventListener' in list
127
+ const handleChange = (event: MediaQueryListEvent) => {
128
+ updateBreakpoint(event, breakpoint as Breakpoint<C>)
129
+ }
130
130
 
131
- if (supportsNewEventListeners) {
132
- list.addEventListener('change', handleChange)
133
- } else {
134
- ;(list as MediaQueryList).addListener(handleChange)
135
- }
131
+ const supportsNewEventListeners =
132
+ 'addEventListener' in list && 'removeEventListener' in list
136
133
 
137
- /** Map the unsubscribers array to a list of unsubscriber methods */
138
- return () => {
139
134
  if (supportsNewEventListeners) {
140
- list.removeEventListener('change', handleChange)
135
+ list.addEventListener('change', handleChange)
141
136
  } else {
142
- ;(list as MediaQueryList).removeListener(handleChange)
137
+ ;(list as MediaQueryList).addListener(handleChange)
143
138
  }
144
- }
145
- })
146
139
 
147
- /** Return a function that when called, will call all unsubscribers */
148
- return () => unsubscribers.forEach((unsubscriber) => unsubscriber())
140
+ /** Map the unsubscribers array to a list of unsubscriber methods */
141
+ return () => {
142
+ if (supportsNewEventListeners) {
143
+ list.removeEventListener('change', handleChange)
144
+ } else {
145
+ ;(list as MediaQueryList).removeListener(handleChange)
146
+ }
147
+ }
148
+ })
149
+
150
+ /** Return a function that when called, will call all unsubscribers */
151
+ return () => unsubscribers.forEach((unsubscriber) => unsubscriber())
152
+ }
149
153
  }, [mediaQueries, updateBreakpoint])
150
154
 
151
155
  /** Print a nice debug value for React Devtools */
package/src/index.tsx CHANGED
@@ -4,8 +4,6 @@ import { Provider, createSlice } from './context'
4
4
  export * from './core/index';
5
5
  export * from './hooks/index';
6
6
 
7
- export { Link } from "react-router-dom"
8
-
9
7
  export { default as App } from './comps/app'
10
8
  export { default as Box } from './comps/box'
11
9
  export { default as Button } from './comps/button'
@@ -1,90 +0,0 @@
1
- class AppTheme {
2
-
3
- #mode;
4
- #listen;
5
- #lightTheme;
6
- #darkTheme;
7
-
8
- constructor(_conf){
9
- const conf = _conf || {}
10
- this.#listen = "listen" in conf ? conf.listen : (mod) => { console.log(`Theme switched to ${mod}`); };
11
- this.#mode = conf.mode || "auto";
12
- this.#lightTheme = {
13
- //CORE
14
- tag: "light",
15
- dark: false,
16
- color: "#3a43ac",
17
- primary: '#edeef5',
18
- secondary: '#e8e9f0',
19
- textColor: '#111111',
20
- borderColor: '#dcdce1',
21
- //APP
22
- app: {
23
- action: 'rgba(0,0,0,0.1)',
24
- actionHover: 'rgba(255,255,255,0.1)',
25
- actionActive: 'rgba(0,0,0,0.8)',
26
- actionDisabled: 'rgba(255,255,255,0.01)',
27
- shimmerBG: '#383a48',
28
- shimmerFrom: '#383a48',
29
- shimmerTo: '#4a4c5b',
30
- iconBG: '#4a4c5b',
31
- icon: '#111111',
32
- sidebarHover: 'rgba(255,255,255,0.2)',
33
- sidebarActive: 'rgba(255,255,255,1)',
34
- toolbar: '#d5d6dc',
35
- tool: 'transparent',
36
- toolActive: 'rgba(255,255,255,0.75)',
37
- toolHover: 'rgba(255,255,255,0.5)',
38
- }
39
- };
40
- this.#darkTheme = {
41
- //CORE
42
- tag: "dark",
43
- dark: true,
44
- color: "#3a43ac",
45
- primary: '#21222d',
46
- secondary: '#282a37',
47
- textColor: '#f9f9f9',
48
- borderColor: '#353640',
49
- //APP
50
- app: {
51
- action: 'rgba(255,255,255,0.05)',
52
- actionHover: 'rgba(255,255,255,0.1)',
53
- actionActive: 'rgba(255,255,255,0.2)',
54
- actionDisabled: 'rgba(255,255,255,0.01)',
55
- shimmerBG: '#383a48',
56
- shimmerFrom: '#383a48',
57
- shimmerTo: '#4a4c5b',
58
- iconBG: '#4a4c5b',
59
- icon: '#ffffff',
60
- toolbar: '#21222d',
61
- tool: 'transparent',
62
- toolHover: '#2f3144',
63
- toolActive: '#2f3144',
64
- }
65
- };
66
- }
67
-
68
- get = () => {
69
- let self = this;
70
- if(self.#mode === "auto"){
71
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
72
- self.#mode = event.matches ? "dark" : "light";
73
- self.#listen(self.#mode);
74
- });
75
- return window.matchMedia &&
76
- window.matchMedia('(prefers-color-scheme: dark)').matches ?
77
- self.#darkTheme : self.#lightTheme;
78
- }else{
79
- if(self.#mode === "light"){
80
- return self.#lightTheme;
81
- }else if(self.#mode === "dark"){
82
- return self.#darkTheme;
83
- }
84
- }
85
- }
86
-
87
-
88
- }
89
-
90
- export default AppTheme
@@ -1,26 +0,0 @@
1
- import { createSlice } from '@reduxjs/toolkit'
2
-
3
- export const appSlice = createSlice({
4
- name: `app`,
5
- initialState: {
6
- debug: true,
7
- loading: true,
8
- theme: null,
9
- _tmp: Math.random()
10
- },
11
- reducers: {
12
- setLoading: (state, action) => {
13
- state.loading = action.payload || false;
14
- },
15
- setTheme: (state, action) => { state.theme = action.payload },
16
- forceUpdate: (state, action) => { state._tmp = Math.random() }
17
- }
18
- });
19
-
20
- export const {
21
- setLoading,
22
- setTheme,
23
- forceUpdate
24
- } = appSlice.actions;
25
-
26
- export default appSlice.reducer;
@@ -1,46 +0,0 @@
1
- import { createSlice } from '@reduxjs/toolkit'
2
-
3
- export const formSlice = createSlice({
4
- name: `form`,
5
- initialState: {
6
- forms: {}
7
- },
8
- reducers: {
9
- addForm: (state, action) => {
10
- state.forms[action.payload] = { touched: false, loading: false }
11
- },
12
- updateForm: (state, action) => {
13
- // console.log(action.payload)
14
- const { name, k, v } = action.payload;
15
- if(state.forms[name]) state.forms[name][k] = v;
16
- },
17
- addFields: (state, action) => {
18
- const { form, fields } = action.payload;
19
- if(state.forms[form]) state.forms[form] = { ...state.forms[form], ...fields };
20
- },
21
- addField: (state, action) => {
22
- // console.log('addField', action.payload)
23
- // state.forms[action.payload.form][action.payload.name] = action.payload.value
24
- // if(
25
- // state.forms[action.payload.form] &&
26
- // !state.forms[action.payload.form][action.payload.name]
27
- // ){
28
- // state.forms[action.payload.form][action.payload.name] = action.payload.value
29
- // }
30
- },
31
- updateField: (state, action) => {
32
- const { form, name, value } = action.payload;
33
- // console.log(`updatingField: ${form} = ${name} => ${value}`, state.forms[form])
34
- state.forms[form][name] = value;
35
- }
36
- }
37
- });
38
-
39
- export const {
40
- addForm,
41
- updateForm,
42
- addField,
43
- addFields,
44
- updateField
45
- } = formSlice.actions;
46
- export default formSlice.reducer;
@@ -1,33 +0,0 @@
1
- import {
2
- configureStore,
3
- combineReducers
4
- } from '@reduxjs/toolkit'
5
- import appReducer from './slices/app'
6
- import formReducer from './slices/form'
7
-
8
- const staticReducers = {
9
- app: appReducer,
10
- form: formReducer
11
- }
12
-
13
- const appstore = configureStore({
14
- reducer: staticReducers,
15
- middleware: getDefaultMiddleware => getDefaultMiddleware({
16
- serializableCheck: false
17
- })
18
- })
19
-
20
- appstore.asyncReducers = {}
21
- appstore.injectReducer = (k, asyncReducer) => {
22
- appstore.asyncReducers[k] = asyncReducer;
23
- appstore.replaceReducer(createReducer(appstore.asyncReducers))
24
- }
25
-
26
- const createReducer = asyncReducers => {
27
- return combineReducers({
28
- ...staticReducers,
29
- ...asyncReducers
30
- })
31
- }
32
-
33
- export default appstore;