@zuzjs/ui 0.3.3 → 0.3.5

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