@zuzjs/ui 0.3.2 → 0.3.4

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.
Files changed (88) hide show
  1. package/README.md +0 -0
  2. package/dist/hooks.js +89 -0
  3. package/dist/styles.css +37 -62
  4. package/dist/ui.js +665 -0
  5. package/jest.config.js +0 -0
  6. package/package.json +16 -18
  7. package/rollup.config.js +30 -47
  8. package/src/comps/box.tsx +24 -28
  9. package/src/comps/button.tsx +23 -47
  10. package/src/comps/crumb.tsx +9 -0
  11. package/src/comps/form.tsx +57 -88
  12. package/src/comps/heading.tsx +25 -31
  13. package/src/comps/icon.tsx +24 -36
  14. package/src/comps/input.tsx +24 -224
  15. package/src/comps/select.tsx +23 -63
  16. package/src/comps/spinner.tsx +23 -35
  17. package/src/comps/stylesheet.tsx +5 -0
  18. package/src/context/AppContext.tsx +2 -2
  19. package/src/context/AppProvider.tsx +68 -105
  20. package/src/context/createSlice.tsx +15 -39
  21. package/src/context/index.tsx +4 -5
  22. package/src/core/css.ts +1 -0
  23. package/src/core/index.tsx +241 -0
  24. package/src/core/styles.ts +378 -371
  25. package/src/hooks/index.tsx +2 -10
  26. package/src/hooks/useDispatch.tsx +36 -36
  27. package/src/hooks/useStore.tsx +24 -26
  28. package/src/hooks.tsx +8 -0
  29. package/src/scss/mixins.scss +2 -2
  30. package/src/scss/props.scss +91 -69
  31. package/src/scss/{style.scss → styles.scss} +102 -132
  32. package/src/ui.tsx +13 -0
  33. package/tsconfig.json +0 -0
  34. package/tsconfig.lib.json +0 -0
  35. package/tsconfig.spec.json +0 -0
  36. package/dist/index.js +0 -1868
  37. package/src/actions/addForm.tsx +0 -0
  38. package/src/actions/index.tsx +0 -29
  39. package/src/actions/redo.tsx +0 -1
  40. package/src/actions/reset.tsx +0 -1
  41. package/src/actions/undo.tsx +0 -1
  42. package/src/comps/app.tsx +0 -34
  43. package/src/comps/checkbox.tsx +0 -74
  44. package/src/comps/component.tsx +0 -32
  45. package/src/comps/contextmenu.tsx +0 -60
  46. package/src/comps/cover.tsx +0 -34
  47. package/src/comps/image.tsx +0 -34
  48. package/src/comps/masonry.tsx +0 -192
  49. package/src/comps/mediaplayer.tsx +0 -12
  50. package/src/comps/placeholder.tsx +0 -58
  51. package/src/comps/root.tsx +0 -32
  52. package/src/comps/spacer.tsx +0 -20
  53. package/src/comps/text.tsx +0 -27
  54. package/src/comps/toaster.tsx +0 -117
  55. package/src/comps/tweet.tsx +0 -48
  56. package/src/context/_AppProvider.tsx +0 -116
  57. package/src/context/combineReducers.tsx +0 -47
  58. package/src/context/combineState.tsx +0 -14
  59. package/src/context/reduceReducers.tsx +0 -6
  60. package/src/context/store/appbase.tsx +0 -19
  61. package/src/context/store/lang.tsx +0 -26
  62. package/src/context/store/theme.tsx +0 -54
  63. package/src/core/defaultTheme.ts +0 -90
  64. package/src/core/extractCurrentDesignState.tsx +0 -0
  65. package/src/core/index.ts +0 -431
  66. package/src/core/router.ts +0 -86
  67. package/src/hooks/useAppReducer.tsx +0 -40
  68. package/src/hooks/useChooseEffect.tsx +0 -6
  69. package/src/hooks/useContextMenu.tsx +0 -123
  70. package/src/hooks/useDevice.tsx +0 -164
  71. package/src/hooks/useImage.tsx +0 -84
  72. package/src/hooks/useLang.tsx +0 -9
  73. package/src/hooks/useMediaPlayer.tsx +0 -27
  74. package/src/hooks/useNavigator.tsx +0 -6
  75. package/src/hooks/useRender.tsx +0 -29
  76. package/src/hooks/useResizeObserver.tsx +0 -84
  77. package/src/hooks/useRouter.tsx +0 -45
  78. package/src/hooks/useSelector.tsx +0 -9
  79. package/src/hooks/useTheme.tsx +0 -9
  80. package/src/hooks/useToast.tsx +0 -11
  81. package/src/index.tsx +0 -35
  82. package/src/kit/Builder.tsx +0 -18
  83. package/src/kit/Component.tsx +0 -32
  84. package/src/kit/Header.tsx +0 -21
  85. package/src/redux/slices/app.js +0 -26
  86. package/src/redux/slices/form.js +0 -46
  87. package/src/redux/store.js +0 -33
  88. package/src/scss/constants.scss +0 -4
package/dist/ui.js ADDED
@@ -0,0 +1,665 @@
1
+ import Hashids from 'hashids';
2
+ import { nanoid } from 'nanoid';
3
+ import Cookies from 'js-cookie';
4
+ import axios from 'axios';
5
+ import { jsx } from 'react/jsx-runtime';
6
+ import { forwardRef } from 'react';
7
+ import Children from 'react-children-utilities';
8
+ import PropTypes from 'prop-types';
9
+
10
+ var StyleCache = {};
11
+
12
+ const cssProps = {
13
+ "ac": "align-content",
14
+ "alignContent": "align-content",
15
+ "aic": "aic",
16
+ "ais": "ais",
17
+ "aie": "aie",
18
+ "nous": "nous",
19
+ "nope": "nope",
20
+ "ai": "align-items",
21
+ "alignItems": "align-items",
22
+ "ass": "ass",
23
+ "asc": "asc",
24
+ "ase": "ase",
25
+ "alignSelf": "align-self",
26
+ "all": "all",
27
+ "animation": "animation",
28
+ "animationDelay": "animation-delay",
29
+ "animationDirection": "animation-direction",
30
+ "animationDuration": "animation-duration",
31
+ "animationFillMode": "animation-fill-mode",
32
+ "animationIterationCount": "animation-iteration-count",
33
+ "animationName": "animation-name",
34
+ "animationPlayState": "animation-play-state",
35
+ "animationTimingFunction": "animation-timing-function",
36
+ "backfaceVisibility": "backface-visibility",
37
+ "backgroundAttachment": "background-attachment",
38
+ "backgroundBlendMode": "background-blend-mode",
39
+ "backgroundClip": "background-clip",
40
+ "bg": "background",
41
+ "background": "background",
42
+ "bgc": "background-color",
43
+ "bgColor": "background-color",
44
+ "backgroundColor": "background-color",
45
+ "backgroundImage": "background-image",
46
+ "backgroundOrigin": "background-origin",
47
+ "backgroundPosition": "background-position",
48
+ "backgroundRepeat": "background-repeat",
49
+ "backgroundSize": "background-size",
50
+ "border": "border",
51
+ "borderBottom": "border-bottom",
52
+ "borderBottomColor": "border-bottom-color",
53
+ "borderBottomStyle": "border-bottom-style",
54
+ "borderBottomWidth": "border-bottom-width",
55
+ "borderCollapse": "border-collapse",
56
+ "borderColor": "border-color",
57
+ "borderImage": "border-image",
58
+ "borderImageOutset": "border-image-outset",
59
+ "borderImageRepeat": "border-image-repeat",
60
+ "borderImageSlice": "border-image-slice",
61
+ "borderImageSource": "border-image-source",
62
+ "borderImageWidth": "border-image-width",
63
+ "borderLeft": "border-left",
64
+ "borderLeftColor": "border-left-color",
65
+ "borderLeftStyle": "border-left-style",
66
+ "borderLeftWidth": "border-left-width",
67
+ //Radius
68
+ "r": "border-radius",
69
+ "br": "border-radius",
70
+ "borderRadius": "border-radius",
71
+ "brtl": "border-top-left-radius",
72
+ "borderTopLeftRadius": "border-top-left-radius",
73
+ "brtr": "border-top-right-radius",
74
+ "borderTopRightRadius": "border-top-right-radius",
75
+ "brbl": "border-bottom-left-radius",
76
+ "borderBottomLeftRadius": "border-bottom-left-radius",
77
+ "brbr": "border-bottom-right-radius",
78
+ "borderBottomRightRadius": "border-bottom-right-radius",
79
+ "borderRight": "border-right",
80
+ "borderRightColor": "border-right-color",
81
+ "borderRightStyle": "border-right-style",
82
+ "borderRightWidth": "border-right-width",
83
+ "borderSpacing": "border-spacing",
84
+ "borderStyle": "border-style",
85
+ "borderTop": "border-top",
86
+ "borderTopColor": "border-top-color",
87
+ "borderTopStyle": "border-top-style",
88
+ "borderTopWidth": "border-top-width",
89
+ "borderWidth": "border-width",
90
+ "bottom": "bottom",
91
+ "boxDecorationBreak": "box-decoration-break",
92
+ "boxShadow": "box-shadow",
93
+ "boxSizing": "box-sizing",
94
+ "captionSide": "caption-side",
95
+ "caretColor": "caret-color",
96
+ "@charset": "@charset",
97
+ "clear": "clear",
98
+ "clip": "clip",
99
+ "clipPath": "clip-path",
100
+ "color": "color",
101
+ "columnCount": "column-count",
102
+ "columnFill": "column-fill",
103
+ "columnGap": "column-gap",
104
+ "colGap": "column-gap",
105
+ "columnRule": "column-rule",
106
+ "columnRuleColor": "column-rule-color",
107
+ "columnRuleStyle": "column-rule-style",
108
+ "columnRuleWidth": "column-rule-width",
109
+ "columnSpan": "column-span",
110
+ "columnWidth": "column-width",
111
+ "colW": "column-width",
112
+ "columns": "columns",
113
+ "content": "content",
114
+ "counterIncrement": "counter-increment",
115
+ "counterReset": "counter-reset",
116
+ "cursor": "cursor",
117
+ "pointer": "pointer",
118
+ "direction": "direction",
119
+ "display": "display",
120
+ "emptyCells": "empty-cells",
121
+ "filter": "filter",
122
+ "flex": "flex",
123
+ "flexBasis": "flex-basis",
124
+ "dir": "flex-direction",
125
+ "flexDirection": "flex-direction",
126
+ "flexFlow": "flex-flow",
127
+ "flexGrow": "flex-grow",
128
+ "flexShrink": "flex-shrink",
129
+ "flexWrap": "flex-wrap",
130
+ "float": "float",
131
+ "font": "font",
132
+ "fontFamily": "font-family",
133
+ "fontKerning": "font-kerning",
134
+ "size": "font-size",
135
+ "fontSize": "font-size",
136
+ "fontSizeAdjust": "font-size-adjust",
137
+ "fontStretch": "font-stretch",
138
+ "fontStyle": "font-style",
139
+ "fontVariant": "font-variant",
140
+ "bold": "bold",
141
+ "b900": "b900",
142
+ "b800": "b800",
143
+ "b700": "b700",
144
+ "fontWeight": "font-weight",
145
+ "gap": "gap",
146
+ "grid": "grid",
147
+ "gridArea": "grid-area",
148
+ "gridAutoColumns": "grid-auto-columns",
149
+ "gridAutoFlow": "grid-auto-flow",
150
+ "gridAutoRows": "grid-auto-rows",
151
+ "gridColumn": "grid-column",
152
+ "gridColumnEnd": "grid-column-end",
153
+ "gridColumnGap": "grid-column-gap",
154
+ "gridColumnStart": "grid-column-start",
155
+ "gridGap": "grid-gap",
156
+ "gridRow": "grid-row",
157
+ "gridRowEnd": "grid-row-end",
158
+ "gridRowGap": "grid-row-gap",
159
+ "gridRowStart": "grid-row-start",
160
+ "gridTemplate": "grid-template",
161
+ "gridTemplateAreas": "grid-template-areas",
162
+ "gridTemplateColumns": "grid-template-columns",
163
+ "gridTemplateRows": "grid-template-rows",
164
+ "hangingPunctuation": "hanging-punctuation",
165
+ "hyphens": "hyphens",
166
+ "isolation": "isolation",
167
+ "jcc": "jcc",
168
+ "jcs": "jcs",
169
+ "jce": "jce",
170
+ "jc": "justify-content",
171
+ "justifyContent": "justify-content",
172
+ "left": "left",
173
+ "letterSpacing": "letter-spacing",
174
+ "lineHeight": "line-height",
175
+ "listStyle": "list-style",
176
+ "listStyleImage": "list-style-image",
177
+ "listStylePosition": "list-style-position",
178
+ "listStyleType": "list-style-type",
179
+ "aspectRatio": "aspect-ratio",
180
+ //Margin
181
+ "m": "margin",
182
+ "margin": "margin",
183
+ "mb": "margin-bottom",
184
+ "marginBottom": "margin-bottom",
185
+ "ml": "margin-left",
186
+ "marginLeft": "margin-left",
187
+ "mr": "margin-right",
188
+ "marginRight": "margin-right",
189
+ "mt": "margin-top",
190
+ "marginTop": "margin-top",
191
+ //Height
192
+ "h": "height",
193
+ "height": "height",
194
+ "minH": "min-height",
195
+ "minHeight": "min-height",
196
+ "maxH": "max-height",
197
+ "maxHeight": "max-height",
198
+ //Width
199
+ "w": "width",
200
+ "width": "width",
201
+ "minW": "min-width",
202
+ "minWidth": "min-width",
203
+ "maxW": "max-width",
204
+ "maxWidth": "max-width",
205
+ "mixBlendMode": "mix-blend-mode",
206
+ "objectFit": "object-fit",
207
+ "objectPosition": "object-position",
208
+ "opacity": "opacity",
209
+ "order": "order",
210
+ "outline": "outline",
211
+ "outlineColor": "outline-color",
212
+ "outlineOffset": "outline-offset",
213
+ "outlineStyle": "outline-style",
214
+ "outlineWidth": "outline-width",
215
+ "overflow": "overflow",
216
+ "overflowX": "overflow-x",
217
+ "overflowY": "overflow-y",
218
+ "p": "padding",
219
+ "padding": "padding",
220
+ "pb": "padding-bottom",
221
+ "paddingBottom": "padding-bottom",
222
+ "pl": "padding-left",
223
+ "paddingLeft": "padding-left",
224
+ "pr": "padding-right",
225
+ "paddingRight": "padding-right",
226
+ "pt": "padding-top",
227
+ "paddingTop": "padding-top",
228
+ "pageBreakAfter": "page-break-after",
229
+ "pageBreakBefore": "page-break-before",
230
+ "pageBreakInside": "page-break-inside",
231
+ "perspective": "perspective",
232
+ "perspectiveOrigin": "perspective-origin",
233
+ "pointerEvents": "pointer-events",
234
+ "rel": "rel",
235
+ "abs": "abs",
236
+ "fixed": "fixed",
237
+ "sticky": "sticky",
238
+ "pos": "position",
239
+ "position": "position",
240
+ "quotes": "quotes",
241
+ "resize": "resize",
242
+ "right": "right",
243
+ "scrollBehavior": "scroll-behavior",
244
+ "tabSize": "tab-size",
245
+ "tableLayout": "table-layout",
246
+ "align": "text-align",
247
+ "textAlign": "text-align",
248
+ "textAlignLast": "text-align-last",
249
+ "tdh": "tdh", //text-decoration: underline on hover
250
+ "td": "text-decoration",
251
+ "textDecoration": "text-decoration",
252
+ "textDecorationColor": "text-decoration-color",
253
+ "textDecorationLine": "text-decoration-line",
254
+ "textDecorationStyle": "text-decoration-style",
255
+ "textIndent": "text-indent",
256
+ "textJustify": "text-justify",
257
+ "textOverflow": "text-overflow",
258
+ "textShadow": "text-shadow",
259
+ "textTransform": "text-transform",
260
+ "top": "top",
261
+ "transform": "transform",
262
+ "transform(2D)": "transform(2D)",
263
+ "transformOrigin(twoValue syntax)": "transform-origin(two-value syntax)",
264
+ "transformStyle": "transform-style",
265
+ "transition": "transition",
266
+ "transitionDelay": "transition-delay",
267
+ "transitionDuration": "transition-duration",
268
+ "transitionProperty": "transition-property",
269
+ "transitionTimingFunction": "transition-timing-function",
270
+ "unicodeBidi": "unicode-bidi",
271
+ "userSelect": "user-select",
272
+ "verticalAlign": "vertical-align",
273
+ "visibility": "visibility",
274
+ "weight": "flex",
275
+ "whiteSpace": "white-space",
276
+ "ws": "white-space",
277
+ "wordBreak": "word-break",
278
+ "wordSpacing": "word-spacing",
279
+ "wrap": "wrap",
280
+ "textWrap": "textWrap",
281
+ "wordWrap": "word-wrap",
282
+ "writingMode": "writing-mode",
283
+ "zIndex": "z-index",
284
+ "backdropFilter": "backdrop-filter",
285
+ "bgFilter": "backdrop-filter",
286
+ //Custom
287
+ "anim": "anim",
288
+ "fill": "fill",
289
+ "abc": "abc",
290
+ "fb": "fb",
291
+ "ph": "ph",
292
+ "pv": "pv",
293
+ "mv": "mv",
294
+ "mh": "mh"
295
+ };
296
+ const cssPropsVals = {
297
+ //Colors
298
+ "primary": 'var(--primary-color)',
299
+ "c": "center",
300
+ //Flex Directions
301
+ "cols": "column",
302
+ "colsr": "column-reverse",
303
+ "rows": "row",
304
+ "rowsr": "row-reverse",
305
+ //Positions
306
+ "rel": "relative",
307
+ "abs": "absolute",
308
+ };
309
+ const cssPropsDirect = {
310
+ 'rel': 'position: relative;',
311
+ 'fixed': 'position: fixed;',
312
+ 'abs': 'position: absolute;',
313
+ 'sticky': 'position: sticky;',
314
+ 'flex': 'display: flex;',
315
+ 'fwrap': 'flex-wrap: wrap;',
316
+ 'aic': 'align-items: center;',
317
+ 'ais': 'align-items: flex-start;',
318
+ 'aie': 'align-items: flex-end;',
319
+ 'ass': 'align-self: flex-start;',
320
+ 'asc': 'align-self: center;',
321
+ 'ase': 'align-self: flex-end;',
322
+ 'jcc': 'justify-content: center;',
323
+ 'jcs': 'justify-content: flex-start;',
324
+ 'jce': 'justify-content: flex-end;',
325
+ 'grid': 'display: grid;',
326
+ 'fill': 'top: 0px;left: 0px;right: 0px;bottom: 0px;',
327
+ 'abc': 'top: 50%;left: 50%;transform: translate(-50%, -50%);',
328
+ 'block': 'display: block;',
329
+ 'bold': "font-weight: bold;",
330
+ 'b900': "font-weight: 900;",
331
+ 'b800': "font-weight: 800;",
332
+ 'b700': "font-weight: 700;",
333
+ 'wrap': "word-wrap: break-word;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 99%;",
334
+ 'textWrap': "word-wrap: break-word;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 99%;",
335
+ 'pointer': "cursor: pointer;",
336
+ 'fb': 'font-family: var(--primary-font-bold);',
337
+ 'ph': 'padding-left: __VALUE__;padding-right: __VALUE__;',
338
+ 'pv': 'padding-bottom: __VALUE__;padding-top: __VALUE__;',
339
+ 'mv': 'margin-bottom: __VALUE__;margin-top: __VALUE__;',
340
+ 'mh': 'margin-left: __VALUE__;margin-right: __VALUE__;',
341
+ 'anim': 'transition:all __VALUE__s linear 0s;',
342
+ 'nous': 'user-select: none;',
343
+ 'nope': 'pointer-events: none;',
344
+ 'tdn': 'text-decoration: none;',
345
+ 'aspectRatio': 'aspect-ratio: __VALUE__;'
346
+ };
347
+ const cssPropsIgnore = [
348
+ 'weight', `opacity`
349
+ ];
350
+ const _cssColors = [`white`, `black`, `gray`, `red`, `orange`, `yellow`, `green`, `teal`, `blue`, `cyan`, `purple`, `pink`, `linkedin`, `facebook`, `messenger`, `whatsapp`, `twitter`, `telegram`];
351
+ const _cssColorsRange = [`50`, `100`, `200`, `300`, `400`, `500`, `600`, `700`, `800`, `900`];
352
+ let cssColors = [];
353
+ if (cssColors.length == 0) {
354
+ _cssColors.map(c => {
355
+ _cssColorsRange.map(r => cssColors.push(`${c}.${r}`));
356
+ });
357
+ }
358
+
359
+ const _Hashids = new Hashids('', 4);
360
+ const _Alphabets = "#abcdefghijklmnopqrstuvwxyz0123456789";
361
+ const setCookie = (key, value, expiry, host) => Cookies.set(key, value, { expires: expiry || 7, domain: host || window.location.host });
362
+ const getCookie = (key) => key == `` ? Cookies.get() : Cookies.get(key) || null;
363
+ const removeCookie = (key) => Cookies.remove(key);
364
+ const uuid = (len = 11) => nanoid(len);
365
+ const makeCSSValue = (k, v, o) => {
366
+ let ignore = cssPropsIgnore.indexOf(o) == -1;
367
+ if (k in cssPropsDirect && ignore == true) {
368
+ return cssPropsDirect[k].indexOf(`__VALUE__`) > -1 ?
369
+ cssPropsDirect[k].replaceAll(`__VALUE__`, `${v}${"number" == typeof v ? `px` : ``}`)
370
+ : cssPropsDirect[k];
371
+ }
372
+ let unit = "number" == typeof v && ignore ? `px` : ``;
373
+ if (cssColors.indexOf(v) > -1) {
374
+ v = `var(--colors-${v.replaceAll(`.`, `-`)})`;
375
+ unit = ``;
376
+ }
377
+ else if (v in cssPropsVals) {
378
+ v = cssPropsVals[v];
379
+ }
380
+ return `${k}:${v}${unit};`;
381
+ };
382
+ const cleanProps = (props, del = true) => {
383
+ const ignore = [`as`, `hover`, `bref`, `tag`, `onSubmit`, `method`, `should`, `options`, `required`];
384
+ let items = Object.assign({}, props);
385
+ Object.keys(props).map(k => {
386
+ if (k in cssProps || ignore.indexOf(k) > -1) {
387
+ if (del)
388
+ delete items[k];
389
+ else
390
+ items[k] = undefined;
391
+ }
392
+ });
393
+ return items;
394
+ };
395
+ const buildCSS = (k, v) => {
396
+ if (k in cssProps) {
397
+ return makeCSSValue(cssProps[k], v, k);
398
+ }
399
+ return ``;
400
+ };
401
+ const _withStyle = (props, pseudo = ``) => {
402
+ if (!props)
403
+ return ``;
404
+ let cx = [props.className || props.as || ``];
405
+ Object.keys(props).map(k => {
406
+ if (k != 'children' && k in cssProps) {
407
+ const _css = buildCSS(k, props[k]).toString().replace(/;|:|\s/g, "");
408
+ let _indices = 0;
409
+ for (let i = 0; i < _css.length; i++) {
410
+ _indices += _Alphabets.indexOf(_css.charAt(i));
411
+ }
412
+ let _cp = k.substring(0, 1);
413
+ if (cssProps[k].indexOf("-") > -1) {
414
+ _cp = "";
415
+ cssProps[k].split("-").map(c => _cp += c.substring(0, 1));
416
+ }
417
+ if (props[k].toString().indexOf("-") > -1) {
418
+ props[k].toString().split("-").map(c => _cp += c.substring(0, 1));
419
+ }
420
+ const _id = `${_cp}${_Hashids.encode(cssProps[k].length + _indices + (isNaN(parseInt(props[k])) ? 0 : parseInt(props[k])))}`;
421
+ // const _id = `${_cp}${cssProps[k]}-${props[k]}`
422
+ cx.push(_id);
423
+ StyleCache[_id + pseudo] = buildCSS(k, props[k]);
424
+ }
425
+ });
426
+ return cx.join(" ").trim();
427
+ };
428
+ const withStyle = (props) => {
429
+ const style = [_withStyle(props)];
430
+ if ("hover" in props) {
431
+ style.push(_withStyle(props.hover, `:hover`));
432
+ }
433
+ if ("before" in props) {
434
+ style.push(_withStyle(props.hover, `:before`));
435
+ }
436
+ if ("after" in props) {
437
+ style.push(_withStyle(props.hover, `:after`));
438
+ }
439
+ return style.join(style.length > 1 ? " " : "");
440
+ };
441
+ const getStylesheet = () => Object.keys(StyleCache).map(ck => StyleCache[ck] != "" ? `.${ck}{${StyleCache[ck]}}` : `__`).filter(x => x != `__`);
442
+ const isEmail = (e) => {
443
+ let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
444
+ return reg.test(e);
445
+ };
446
+ const buildFormData = form => {
447
+ if (!form || form.nodeName !== "FORM") {
448
+ return;
449
+ }
450
+ var i, j, q = [];
451
+ for (i = form.elements.length - 1; i >= 0; i = i - 1) {
452
+ if (form.elements[i].name === "") {
453
+ continue;
454
+ }
455
+ switch (form.elements[i].nodeName) {
456
+ case 'INPUT':
457
+ switch (form.elements[i].type) {
458
+ case 'text':
459
+ case 'hidden':
460
+ case 'password':
461
+ case 'button':
462
+ case 'reset':
463
+ case 'submit':
464
+ q.push({ [form.elements[i].name]: encodeURIComponent(form.elements[i].value) });
465
+ break;
466
+ case 'checkbox':
467
+ case 'radio':
468
+ if (form.elements[i].checked) {
469
+ q.push({ [form.elements[i].name]: encodeURIComponent(form.elements[i].value) });
470
+ }
471
+ break;
472
+ }
473
+ break;
474
+ case 'TEXTAREA':
475
+ q.push({ [form.elements[i].name]: encodeURIComponent(form.elements[i].value) });
476
+ break;
477
+ case 'SELECT':
478
+ switch (form.elements[i].type) {
479
+ case 'select-one':
480
+ q.push({ [form.elements[i].name]: encodeURIComponent(form.elements[i].value) });
481
+ break;
482
+ case 'select-multiple':
483
+ for (j = form.elements[i].options.length - 1; j >= 0; j = j - 1) {
484
+ if (form.elements[i].options[j].selected) {
485
+ q.push({ [form.elements[i].name]: encodeURIComponent(form.elements[i].options[j].value) });
486
+ }
487
+ }
488
+ break;
489
+ }
490
+ break;
491
+ case 'BUTTON':
492
+ switch (form.elements[i].type) {
493
+ case 'reset':
494
+ case 'submit':
495
+ case 'button':
496
+ q.push({ [form.elements[i].name]: encodeURIComponent(form.elements[i].value) });
497
+ break;
498
+ }
499
+ break;
500
+ }
501
+ }
502
+ return q; //return q.join("&");
503
+ };
504
+ const withRest = async (uri, data, timeout = 60, fd = null, progress, bearer = `__ha`) => {
505
+ var Bearer = getCookie(bearer) || `${uuid(8)}^${uuid(8)}`;
506
+ var isWindow = typeof window !== 'undefined';
507
+ var cancelToken = null;
508
+ if (isWindow) {
509
+ window['__grabToken'] = axios.CancelToken.source();
510
+ cancelToken = window['__grabToken'].token;
511
+ }
512
+ if (fd) {
513
+ return new Promise((resolve, reject) => {
514
+ axios({
515
+ method: "post",
516
+ url: uri,
517
+ data: buildFormData(data),
518
+ timeout: 1000 * timeout,
519
+ cancelToken: cancelToken,
520
+ headers: {
521
+ 'Content-Type': 'multipart/form-data',
522
+ 'Authorization': `Bearer ${Bearer}`
523
+ },
524
+ onUploadProgress: ev => {
525
+ //TODO: Add progress
526
+ }
527
+ })
528
+ .then(resp => {
529
+ if (resp.data && "kind" in resp.data) {
530
+ resolve(resp.data);
531
+ }
532
+ else {
533
+ reject(resp.data);
534
+ }
535
+ })
536
+ .catch(err => reject(err));
537
+ });
538
+ }
539
+ return new Promise((resolve, reject) => {
540
+ axios.post(uri, Object.assign(Object.assign(Object.assign({}, Cookies.get()), data), { __poken: new Date().getTime() / 1000 }), {
541
+ timeout: 1000 * timeout,
542
+ headers: {
543
+ 'Content-Type': 'application/json',
544
+ 'Authorization': `Bearer ${Bearer}`
545
+ },
546
+ cancelToken: cancelToken
547
+ })
548
+ .then(resp => {
549
+ if (resp.data && "kind" in resp.data) {
550
+ resolve(resp.data);
551
+ }
552
+ else {
553
+ reject(resp.data);
554
+ }
555
+ })
556
+ .catch(err => reject(err));
557
+ });
558
+ };
559
+ const formatBytes = bytes => {
560
+ var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
561
+ if (bytes == 0)
562
+ return '0 Byte';
563
+ var i = Math.floor(Math.log(bytes) / Math.log(1024)), nx = bytes / Math.pow(1024, i);
564
+ return nx.toFixed(2) + ' ' + sizes[i];
565
+ };
566
+ const formatSeconds = (n) => {
567
+ let d = new Date(n * 1000).toISOString().slice(11, 19);
568
+ return d.indexOf("00:") > -1 ? d.replace("00:", "") : d;
569
+ };
570
+
571
+ const Stylesheet = (props) => jsx("style", { className: props.id || undefined, children: getStylesheet().join("") });
572
+
573
+ const Box = forwardRef((props, ref) => {
574
+ const _styles = withStyle(props);
575
+ return jsx("div", Object.assign({ ref: props.ref || ref, className: _styles }, cleanProps(props), { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children }));
576
+ });
577
+
578
+ const Heading = forwardRef((props, ref) => {
579
+ const _styles = withStyle(props);
580
+ const Tag = `h${props.h || 1}`;
581
+ const HeadingTag = Tag;
582
+ return jsx(HeadingTag, Object.assign({ className: _styles }, cleanProps(props), { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children }));
583
+ });
584
+
585
+ const Input = forwardRef((props, ref) => {
586
+ let Tag = props.tag || 'input';
587
+ const El = Tag;
588
+ const _styles = withStyle(props);
589
+ return jsx(El, Object.assign({ className: _styles, onChange: e => { props.onChange && props.onChange(e); } }, cleanProps(props)));
590
+ });
591
+
592
+ const Button = forwardRef((props, ref) => {
593
+ const _styles = withStyle(props);
594
+ return jsx("button", Object.assign({ ref: props.ref || ref, className: _styles }, cleanProps(props), { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children }));
595
+ });
596
+
597
+ const Form = (props) => {
598
+ const _props = Object.assign({}, props);
599
+ delete _props['children'];
600
+ const formName = `form-${props.name}`;
601
+ const fields = [];
602
+ const validateForm = () => {
603
+ const _data = buildFormData(document.querySelector(`form[name="${formName}"]`));
604
+ const data = [];
605
+ _data.map(f => {
606
+ const id = Object.keys(f)[0];
607
+ const field = fields.find(x => x.name == id);
608
+ if (field) {
609
+ const value = decodeURIComponent(f[id]);
610
+ let valid = 'should' in field ? field.value != "" : true;
611
+ if ('should' in field) {
612
+ switch (field.should) {
613
+ case "email":
614
+ valid = isEmail(value);
615
+ break;
616
+ }
617
+ }
618
+ data.push({ name: field.name, value: value, valid: valid });
619
+ }
620
+ });
621
+ if (props.onSubmit) {
622
+ props.onSubmit({ validation: !data.find(x => x.valid == false), data: data });
623
+ }
624
+ };
625
+ Children.deepMap(props.children, c => {
626
+ if (c['props'].name && !fields.find(x => x.name == c['props'].name)) {
627
+ let xyz = { name: c['props'].name, touched: false };
628
+ if ('should' in c['props']) {
629
+ xyz['should'] = c['props'].should;
630
+ }
631
+ fields.push(xyz);
632
+ }
633
+ return null;
634
+ });
635
+ return jsx("form", { name: formName, method: props.method || undefined, onSubmit: e => {
636
+ e.preventDefault();
637
+ e.stopPropagation();
638
+ validateForm();
639
+ }, children: jsx(Box, Object.assign({}, _props, { children: props.children })) });
640
+ };
641
+
642
+ const Icon = forwardRef((props, ref) => {
643
+ const _styles = withStyle(Object.assign(Object.assign({}, props), { as: `icon-${props.as}`, size: props.size || 16 }));
644
+ return jsx("span", Object.assign({ ref: props.ref || ref, className: _styles }, cleanProps(props), { children: props.html ? jsx("span", { dangerouslySetInnerHTML: { __html: props.html } }) : props.children }));
645
+ });
646
+
647
+ const Spinner = (props) => {
648
+ const { size, w, h, color, radius, anim } = props;
649
+ return jsx(Box, { w: size || 50, rel: true, zIndex: `1`, userSelect: `none`, h: size || 50, as: `zuz-spinner`, anim: (anim || 2).toString(), flex: true, aic: true, jcc: true, children: jsx(Box, { as: `zuz-loader`, r: radius || 4, w: w || 30, h: h || 6, bg: color || `#111` }) });
650
+ };
651
+ Spinner.propTypes = {
652
+ size: PropTypes.number,
653
+ w: PropTypes.number,
654
+ h: PropTypes.number,
655
+ radius: PropTypes.number,
656
+ color: PropTypes.string,
657
+ anim: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
658
+ };
659
+
660
+ const Select = forwardRef((props, ref) => {
661
+ const _styles = withStyle(props);
662
+ return jsx("select", Object.assign({ className: _styles }, cleanProps(props), { onChange: e => { props.onChange && props.onChange(e); }, children: props.options && props.options.map(o => jsx("option", { value: o.value, children: o.label }, `${props.id || props.as || props.name}-option-${o.value}`)) }));
663
+ });
664
+
665
+ export { Box, Button, Form, Heading, Icon, Input, Select, Spinner, Stylesheet, buildCSS, buildFormData, cleanProps, formatBytes, formatSeconds, getCookie, getStylesheet, isEmail, makeCSSValue, removeCookie, setCookie, uuid, withRest, withStyle };
package/jest.config.js CHANGED
File without changes