@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/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@zuzjs/ui",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
7
- ".": "./dist/index.js",
7
+ ".": "./dist/ui.js",
8
+ "./core": "./dist/index.js",
9
+ "./hooks": "./dist/hooks.js",
8
10
  "./styles": "./dist/styles.css"
9
11
  },
10
12
  "scripts": {
@@ -13,35 +15,31 @@
13
15
  "test": "jest"
14
16
  },
15
17
  "dependencies": {
16
- "@emotion/react": "^11.10.6",
17
- "@emotion/styled": "^11.10.6",
18
18
  "@testing-library/react": "14.0.0",
19
19
  "@types/jest": "^29.5.0",
20
20
  "@types/react": "^18.0.31",
21
- "axios": "^1.3.4",
22
- "jest": "^29.5.0",
23
- "js-cookie": "^3.0.1",
24
- "nanoid": "^4.0.2",
21
+ "axios": "^1.6.2",
22
+ "hashids": "^2.3.0",
23
+ "jest": "^29.7.0",
24
+ "js-cookie": "^3.0.5",
25
+ "nanoid": "^5.0.4",
25
26
  "prop-types": "^15.8.1",
26
27
  "react": "18.2.0",
27
28
  "react-children-utilities": "^2.9.0",
28
29
  "react-dom": "18.2.0",
29
- "react-hot-toast": "^2.4.0",
30
- "ts-jest": "^29.0.5",
31
- "tslib": "^2.5.0",
32
- "typescript": "^5.0.2"
30
+ "ts-jest": "^29.1.1",
31
+ "tslib": "^2.6.2",
32
+ "typescript": "^5.3.3"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@rollup/plugin-commonjs": "^24.0.1",
36
36
  "postcss": "^8.4.21",
37
- "react-router-dom": "^6.14.2",
38
- "rimraf": "^4.4.1",
39
- "rollup": "^3.20.2",
37
+ "rimraf": "^5.0.5",
38
+ "rollup": "^4.8.0",
40
39
  "rollup-plugin-livereload": "^2.0.5",
41
40
  "rollup-plugin-scss": "^4.0.0",
42
- "rollup-plugin-typescript2": "^0.34.1",
41
+ "rollup-plugin-typescript2": "^0.36.0",
43
42
  "rollup-plugin-uglify": "^6.0.4",
44
- "sass": "^1.60.0",
45
- "vite-plugin-environment": "^1.1.3"
43
+ "sass": "^1.69.5"
46
44
  }
47
45
  }
package/rollup.config.js CHANGED
@@ -6,63 +6,46 @@ import livereload from 'rollup-plugin-livereload'
6
6
  import { uglify } from 'rollup-plugin-uglify';
7
7
 
8
8
  const isWatching = process && process.argv.includes('-w') || process.argv.includes('--watch')
9
+ const plugins = [
10
+ typescript(),
11
+ commonjs(),
12
+ scss({
13
+ processor: () => postcss(),
14
+ fileName: 'styles.css',
15
+ failOnError: true
16
+ }),
17
+ !isWatching && uglify()
18
+ // livereload()
19
+ ]
20
+ const externals = [
21
+ "react","react-children-utilities","js-cookie","axios","nanoid","hashids","react/jsx-runtime","prop-types"
22
+ ]
9
23
 
10
24
  export default [
11
25
  {
12
- input: ["src/index.tsx"],
26
+ input: ["src/ui.tsx"],
13
27
  output: [
14
28
  {
15
29
  dir: "dist",
16
30
  entryFileNames: "[name].js",
17
31
  format: "es",
18
32
  exports: "named",
19
- // preserveModules: true,
20
- // preserveModulesRoot: 'src',
21
33
  }
22
34
  ],
23
- plugins: [
24
- typescript(),
25
- commonjs(),
26
- scss({
27
- processor: () => postcss(),
28
- fileName: 'styles.css',
29
- failOnError: true
30
- }),
31
- !isWatching && uglify()
32
- // livereload()
35
+ plugins: plugins,
36
+ externals: externals
37
+ },
38
+ {
39
+ input: ["src/hooks.tsx"],
40
+ output: [
41
+ {
42
+ dir: "dist",
43
+ entryFileNames: "[name].js",
44
+ format: "es",
45
+ exports: "named",
46
+ }
33
47
  ],
34
- external: [
35
- "react","react-children-utilities","js-cookie","axios","nanoid","@reduxjs/toolkit","react-redux","react/jsx-runtime",
36
- "@emotion/react","@emotion/styled","prop-types","react-hot-toast"
37
- ]
48
+ plugins: plugins,
49
+ externals: externals
38
50
  }
39
- // ,
40
- // {
41
- // input: ["src/kit/index.tsx"],
42
- // output: [
43
- // {
44
- // dir: "dist",
45
- // entryFileNames: "kit.js",
46
- // format: "es",
47
- // exports: "named",
48
- // // preserveModules: true,
49
- // // preserveModulesRoot: 'src',
50
- // }
51
- // ],
52
- // plugins: [
53
- // typescript(),
54
- // // commonjs(),
55
- // // scss({
56
- // // processor: () => postcss(),
57
- // // fileName: 'styles.css',
58
- // // failOnError: true
59
- // // }),
60
- // // !isWatching && uglify()
61
- // // livereload()
62
- // ],
63
- // // external: [
64
- // // "react","react-children-utilities","js-cookie","axios","nanoid","@reduxjs/toolkit","react-redux","react/jsx-runtime",
65
- // // "@emotion/react","@emotion/styled","prop-types","react-hot-toast"
66
- // // ]
67
- // }
68
- ];
51
+ ]
package/src/comps/box.tsx CHANGED
@@ -1,28 +1,24 @@
1
- import {
2
- forwardRef,
3
- useEffect
4
- } from 'react';
5
- import { ClassNames } from '@emotion/react'
6
- import { cleanProps, buildCSS } from '../core'
7
-
8
- const Box = forwardRef((props : { [ key: string ] : any }, ref) => {
9
-
10
- const _noClick = () => {}
11
-
12
- // console.log(props)
13
-
14
- return (
15
- <ClassNames>
16
- {({ css, cx }) => <div
17
- {...cleanProps(props)}
18
- title={props.title || undefined}
19
- id={props.id || undefined}
20
- onDoubleClick={props.onDoubleClick || undefined}
21
- onClick={props.onClick || _noClick}
22
- className={`${props.as ? `${props.as} ` : ``}${cx(css`${buildCSS(props)} &:hover {${buildCSS(props.hover || {})}} &:active {${buildCSS(props.active || {})}}`)}`}
23
- ref={props.bref || ref}>{props.html ? <span dangerouslySetInnerHTML={{ __html: props.html }} /> : props.children}</div>}
24
- </ClassNames>
25
- )
26
- })
27
-
28
- export default Box;
1
+ import {
2
+ forwardRef
3
+ } from "react";
4
+ import {
5
+ cleanProps,
6
+ withStyle,
7
+ getStylesheet
8
+ } from "../core";
9
+
10
+ const Box = forwardRef(( props: { [ key: string ] : any }, ref) => {
11
+
12
+ const _styles = withStyle(props)
13
+
14
+ return <div
15
+ ref={props.ref || ref}
16
+ className={_styles}
17
+ { ...cleanProps(props) }>
18
+ {props.html ? <span dangerouslySetInnerHTML={{ __html: props.html }} /> : props.children}
19
+ {/* {getStylesheet().join("")} */}
20
+ </div>
21
+
22
+ });
23
+
24
+ export default Box
@@ -1,47 +1,23 @@
1
- import React, {
2
- forwardRef,
3
- LegacyRef
4
- } from 'react';
5
- import { ClassNames } from '@emotion/react'
6
- import {
7
- buildCSS,
8
- cleanProps
9
- } from '../core'
10
- import { useStore } from '../hooks'
11
- import { STORE_FORM_KEY } from '../context/AppProvider'
12
- const Button = forwardRef((props: { [ key: string ] : any }, ref : LegacyRef<HTMLButtonElement>) => {
13
-
14
- const { forms } = useStore(state => state[STORE_FORM_KEY], false);
15
- const _otherProps = {}
16
- if(props.html){
17
- _otherProps['dangerouslySetInnerHTML'] = { __html: props.html }
18
- }
19
-
20
- return (
21
- <ClassNames>
22
- {({ css, cx }) => {
23
- return (
24
- <button
25
- {...cleanProps(props)}
26
- title={"title" in props ? props.title : undefined}
27
- type={props.type}
28
- className={`button${props.as ? ` ${props.as}` : ``} ${cx(css`
29
- padding: 5px 10px;
30
- border-radius: 2px;
31
- ${buildCSS(props)} &:hover {${buildCSS(props.hover || {})}} &:active {${buildCSS(props.active || {})}}`)}`}
32
- ref={ref}
33
- onDoubleClick={props.onDoubleClick || undefined}
34
- onClick={e => {
35
- if(props.form && props.type && props.type == 'submit'){
36
- props.onSubmit(forms[props.form]);
37
- }else{
38
- props.onClick ? props.onClick(e) : () => console.warn('onClick Missing')
39
- }
40
- }} disabled={props.disabled || false} >{props.html ? <span dangerouslySetInnerHTML={{ __html: props.html }} /> : props.children}</button>
41
- )
42
- }}
43
- </ClassNames>
44
- )
45
- })
46
-
47
- export default Button;
1
+ import {
2
+ LegacyRef,
3
+ forwardRef
4
+ } from "react";
5
+ import {
6
+ cleanProps,
7
+ withStyle
8
+ } from "../core";
9
+
10
+ const Button = forwardRef(( props: { [ key: string ] : any }, ref : LegacyRef<HTMLButtonElement>) => {
11
+
12
+ const _styles = withStyle(props)
13
+
14
+ return <button
15
+ ref={props.ref || ref}
16
+ className={_styles}
17
+ { ...cleanProps(props) }>
18
+ {props.html ? <span dangerouslySetInnerHTML={{ __html: props.html }} /> : props.children}
19
+ </button>
20
+
21
+ });
22
+
23
+ export default Button
@@ -0,0 +1,9 @@
1
+ import Box from './box'
2
+
3
+ const Icon = (props: any) => {
4
+
5
+ return <Box as={`icon-${props.as}`} size={props.size || 16} />
6
+
7
+ }
8
+
9
+ export default Icon
@@ -1,89 +1,58 @@
1
- import {
2
- Ref,
3
- LegacyRef,
4
- forwardRef,
5
- useState,
6
- createElement,
7
- useEffect,
8
- useImperativeHandle
9
- } from 'react';
10
- import PropTypes from 'prop-types'
11
- import Box from './box'
12
- import Cover from './cover'
13
- import { addProps } from '../core'
14
- import useDispatch from '../hooks/useDispatch'
15
- import useStore from '../hooks/useStore'
16
- import { STORE_FORM_KEY, STORE_DEFAUTLS } from '../context/AppProvider'
17
- import { nanoid } from 'nanoid'
18
- import {
19
- ADD_FORM,
20
- UPDATE_FORM_FIELD
21
- } from '../actions'
22
-
23
- const Form = forwardRef((props : { [ key: string ] : any }, ref : Ref<any>) => {
24
-
25
- const {
26
- name,
27
- children,
28
- onSubmit,
29
- cover,
30
- debug
31
- } = props;
32
-
33
- const [_html, setHTML] = useState(null);
34
- const [_loading, setLoading] = useState(debug?.loading || false);
35
- const dispatch = useDispatch(STORE_FORM_KEY)
36
- const { forms } = useStore(state => state[STORE_FORM_KEY], false)
37
-
38
- const buildFields = () => {
39
- return addProps(children, { form : name, touched: undefined, loading: undefined, onSubmit: onSubmit ? onSubmit : () => console.log(`onSubmit Missing`) })
40
- }
41
-
42
- const update = (e : object) => Object.keys(e).map(k => {
43
- dispatch( UPDATE_FORM_FIELD( name || 'orphan', k, e[k], forms ) )
44
- if(k == 'loading') setLoading(e[k])
45
- })
46
-
47
- const get = (k : string) => forms[name][k] || null
48
-
49
- useImperativeHandle(ref, () => ({
50
- update,
51
- get
52
- }))
53
-
54
- useEffect(() => {
55
- let f = buildFields();
56
- setHTML(f.children);
57
- if(!forms[name]){
58
- dispatch(ADD_FORM(name, f.fields, forms))
59
- }
60
- }, [children, forms[name]?.loading])
61
-
62
- return createElement(
63
- Box,
64
- {
65
- rel: true,
66
- ...props,
67
- as: name
68
- },
69
- [
70
- _loading? <Cover key={`form-${name}-cover`} backdrop={cover?.filter || { saturate: 80, blur: 10 }} bg={cover?.bg || `rgba(0,0,0,0.5)`} /> : null,
71
- _html
72
- ]
73
- )
74
-
75
- })
76
-
77
- Form.defaultProps = {
78
- name: 'form1',
79
- onSubmit: () => { console.log(`onSubmit not provided`) }
80
- }
81
-
82
- Form.propTypes = {
83
- name: PropTypes.string.isRequired,
84
- children: PropTypes.node.isRequired,
85
- onSubmit: PropTypes.func.isRequired
86
- }
87
-
88
-
1
+ import Box from './box'
2
+ import { buildFormData, isEmail } from '../core'
3
+ // import { useEffect, useState } from 'react'
4
+ import Children from 'react-children-utilities'
5
+
6
+ const Form = (props: any) => {
7
+
8
+ const _props = { ...props }
9
+ delete _props['children']
10
+ const formName = `form-${props.name}`
11
+ const fields = []
12
+
13
+ const validateForm = () => {
14
+ const _data = buildFormData(document.querySelector(`form[name="${formName}"]`))
15
+ const data = []
16
+ _data.map(f => {
17
+ const id = Object.keys(f)[0]
18
+ const field = fields.find(x => x.name == id)
19
+ if(field){
20
+ const value = decodeURIComponent(f[id])
21
+ let valid = 'should' in field ? field.value != "" : true
22
+ if('should' in field){
23
+ switch(field.should){
24
+ case "email":
25
+ valid = isEmail(value)
26
+ break;
27
+ }
28
+ }
29
+ data.push({ name: field.name, value: value, valid: valid })
30
+ }
31
+ })
32
+ if(props.onSubmit){
33
+ props.onSubmit({ validation: !data.find(x => x.valid == false), data: data })
34
+ }
35
+ }
36
+
37
+ Children.deepMap(props.children, c => {
38
+ if(c['props'].name && !fields.find(x => x.name == c['props'].name)){
39
+ let xyz = { name: c['props'].name, touched: false }
40
+ if('should' in c['props']){
41
+ xyz['should'] = c['props'].should
42
+ }
43
+ fields.push(xyz)
44
+ }
45
+ return null
46
+ })
47
+
48
+ return <form name={formName} method={props.method || undefined} onSubmit={e => {
49
+ e.preventDefault(); e.stopPropagation();
50
+ validateForm()
51
+ }} >
52
+ <Box {..._props}>
53
+ {props.children}
54
+ </Box>
55
+ </form>
56
+ }
57
+
89
58
  export default Form
@@ -1,31 +1,25 @@
1
- import {
2
- FC,
3
- LegacyRef,
4
- forwardRef,
5
- HTMLAttributes
6
- } from 'react';
7
- import { ClassNames } from '@emotion/react'
8
- import { buildCSS } from '../core'
9
-
10
- const Heading = forwardRef((props : { [ key: string ] : any }, ref : LegacyRef<HTMLHeadingElement>) => {
11
-
12
- const {
13
- children,
14
- as,
15
- h
16
- } = props;
17
-
18
- let Tag : string = `h${h || 1}`;
19
- const HeadingTag = Tag as `h1` | `h2` | `h3` | `h4` | `h5` | `h6`
20
-
21
- return (
22
- <ClassNames>
23
- {({ css, cx }) => <HeadingTag
24
- className={`${as ? `${as} ` : ``}${cx(css`${buildCSS(props)}`)}`}
25
- ref={ref}
26
- >{props.html ? <span dangerouslySetInnerHTML={{ __html: props.html }} /> : children}</HeadingTag>}
27
- </ClassNames>
28
- )
29
- })
30
-
31
- export default Heading;
1
+ import {
2
+ LegacyRef,
3
+ forwardRef
4
+ } from "react";
5
+ import {
6
+ cleanProps,
7
+ withStyle
8
+ } from "../core";
9
+
10
+ const Heading = forwardRef(( props: { [ key: string ] : any }, ref : LegacyRef<HTMLHeadingElement>) => {
11
+
12
+ const _styles = withStyle(props)
13
+
14
+ const Tag : string = `h${props.h || 1}`;
15
+ const HeadingTag = Tag as `h1` | `h2` | `h3` | `h4` | `h5` | `h6`
16
+
17
+ return <HeadingTag
18
+ className={_styles}
19
+ { ...cleanProps(props) }>
20
+ {props.html ? <span dangerouslySetInnerHTML={{ __html: props.html }} /> : props.children}
21
+ </HeadingTag>
22
+
23
+ });
24
+
25
+ export default Heading
@@ -1,36 +1,24 @@
1
- import {
2
- FC,
3
- LegacyRef,
4
- forwardRef,
5
- useRef,
6
- SyntheticEvent,
7
- } from 'react';
8
- import Box from './box'
9
-
10
- const Icon = forwardRef((props : { [ key: string ] : any }, ref : LegacyRef<HTMLHeadingElement>) => {
11
-
12
- const {
13
- as,
14
- path,
15
- size,
16
- color,
17
- hover
18
- } = props;
19
-
20
- return (
21
- <Box
22
- hover={hover || {}}
23
- flex
24
- bref={ref}
25
- as={`icon-${as}`}
26
- ai={`c`}
27
- jc={`c`}
28
- size={size || 24}
29
- color={color || `#111111`}
30
- >
31
- {path && Array(path).fill(undefined).map((p : any, i : any) => <span key={`ico-${as}-${i}`} className={`path${i+1}`} />)}
32
- </Box>
33
- )
34
- })
35
-
36
- export default Icon;
1
+ import {
2
+ forwardRef
3
+ } from "react";
4
+ import {
5
+ cleanProps,
6
+ withStyle,
7
+ getStylesheet
8
+ } from "../core";
9
+
10
+ const Icon = forwardRef(( props: { [ key: string ] : any }, ref) => {
11
+
12
+ const _styles = withStyle({ ...props, as: `icon-${props.as}`, size: props.size || 16 })
13
+
14
+ return <span
15
+ ref={props.ref || ref}
16
+ className={_styles}
17
+ { ...cleanProps(props) }>
18
+ {props.html ? <span dangerouslySetInnerHTML={{ __html: props.html }} /> : props.children}
19
+ {/* {getStylesheet().join("")} */}
20
+ </span>
21
+
22
+ });
23
+
24
+ export default Icon