@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.
- package/README.md +0 -0
- package/dist/hooks.js +89 -0
- package/dist/styles.css +37 -62
- package/dist/ui.js +665 -0
- package/jest.config.js +0 -0
- package/package.json +16 -18
- package/rollup.config.js +30 -47
- package/src/comps/box.tsx +24 -28
- package/src/comps/button.tsx +23 -47
- package/src/comps/crumb.tsx +9 -0
- package/src/comps/form.tsx +57 -88
- package/src/comps/heading.tsx +25 -31
- package/src/comps/icon.tsx +24 -36
- package/src/comps/input.tsx +24 -224
- package/src/comps/select.tsx +23 -63
- package/src/comps/spinner.tsx +23 -35
- package/src/comps/stylesheet.tsx +5 -0
- package/src/context/AppContext.tsx +2 -2
- package/src/context/AppProvider.tsx +68 -105
- package/src/context/createSlice.tsx +15 -39
- package/src/context/index.tsx +4 -5
- package/src/core/css.ts +1 -0
- package/src/core/index.tsx +241 -0
- package/src/core/styles.ts +378 -371
- package/src/hooks/index.tsx +2 -10
- package/src/hooks/useDispatch.tsx +36 -36
- package/src/hooks/useStore.tsx +24 -26
- package/src/hooks.tsx +8 -0
- package/src/scss/mixins.scss +2 -2
- package/src/scss/props.scss +91 -69
- package/src/scss/{style.scss → styles.scss} +102 -132
- package/src/ui.tsx +13 -0
- package/tsconfig.json +0 -0
- package/tsconfig.lib.json +0 -0
- package/tsconfig.spec.json +0 -0
- package/dist/index.js +0 -1868
- package/src/actions/addForm.tsx +0 -0
- package/src/actions/index.tsx +0 -29
- package/src/actions/redo.tsx +0 -1
- package/src/actions/reset.tsx +0 -1
- package/src/actions/undo.tsx +0 -1
- package/src/comps/app.tsx +0 -34
- package/src/comps/checkbox.tsx +0 -74
- package/src/comps/component.tsx +0 -32
- package/src/comps/contextmenu.tsx +0 -60
- package/src/comps/cover.tsx +0 -34
- package/src/comps/image.tsx +0 -34
- package/src/comps/masonry.tsx +0 -192
- package/src/comps/mediaplayer.tsx +0 -12
- package/src/comps/placeholder.tsx +0 -58
- package/src/comps/root.tsx +0 -32
- package/src/comps/spacer.tsx +0 -20
- package/src/comps/text.tsx +0 -27
- package/src/comps/toaster.tsx +0 -117
- package/src/comps/tweet.tsx +0 -48
- package/src/context/_AppProvider.tsx +0 -116
- package/src/context/combineReducers.tsx +0 -47
- package/src/context/combineState.tsx +0 -14
- package/src/context/reduceReducers.tsx +0 -6
- package/src/context/store/appbase.tsx +0 -19
- package/src/context/store/lang.tsx +0 -26
- package/src/context/store/theme.tsx +0 -54
- package/src/core/defaultTheme.ts +0 -90
- package/src/core/extractCurrentDesignState.tsx +0 -0
- package/src/core/index.ts +0 -431
- package/src/core/router.ts +0 -86
- package/src/hooks/useAppReducer.tsx +0 -40
- package/src/hooks/useChooseEffect.tsx +0 -6
- package/src/hooks/useContextMenu.tsx +0 -123
- package/src/hooks/useDevice.tsx +0 -164
- package/src/hooks/useImage.tsx +0 -84
- package/src/hooks/useLang.tsx +0 -9
- package/src/hooks/useMediaPlayer.tsx +0 -27
- package/src/hooks/useNavigator.tsx +0 -6
- package/src/hooks/useRender.tsx +0 -29
- package/src/hooks/useResizeObserver.tsx +0 -84
- package/src/hooks/useRouter.tsx +0 -45
- package/src/hooks/useSelector.tsx +0 -9
- package/src/hooks/useTheme.tsx +0 -9
- package/src/hooks/useToast.tsx +0 -11
- package/src/index.tsx +0 -35
- package/src/kit/Builder.tsx +0 -18
- package/src/kit/Component.tsx +0 -32
- package/src/kit/Header.tsx +0 -21
- package/src/redux/slices/app.js +0 -26
- package/src/redux/slices/form.js +0 -46
- package/src/redux/store.js +0 -33
- package/src/scss/constants.scss +0 -4
package/src/comps/input.tsx
CHANGED
|
@@ -1,224 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
'borderTopWidth',
|
|
26
|
-
'boxSizing',
|
|
27
|
-
'fontFamily',
|
|
28
|
-
'fontSize',
|
|
29
|
-
'fontStyle',
|
|
30
|
-
'fontWeight',
|
|
31
|
-
'letterSpacing',
|
|
32
|
-
'lineHeight',
|
|
33
|
-
'paddingBottom',
|
|
34
|
-
'paddingLeft',
|
|
35
|
-
'paddingRight',
|
|
36
|
-
'paddingTop',
|
|
37
|
-
// non-standard
|
|
38
|
-
'tabSize',
|
|
39
|
-
'textIndent',
|
|
40
|
-
// non-standard
|
|
41
|
-
'textRendering',
|
|
42
|
-
'textTransform',
|
|
43
|
-
'width',
|
|
44
|
-
'wordBreak',
|
|
45
|
-
] as const;
|
|
46
|
-
type SizingProps = Extract<
|
|
47
|
-
(typeof SIZING_STYLE)[number],
|
|
48
|
-
keyof CSSStyleDeclaration
|
|
49
|
-
>;
|
|
50
|
-
|
|
51
|
-
export const noop = () => {};
|
|
52
|
-
|
|
53
|
-
const pick = <Obj extends { [key: string]: any }, Key extends keyof Obj>(
|
|
54
|
-
props: Key[],
|
|
55
|
-
obj: Obj,
|
|
56
|
-
): Pick<Obj, Key> =>
|
|
57
|
-
props.reduce((acc, prop) => {
|
|
58
|
-
acc[prop] = obj[prop];
|
|
59
|
-
return acc;
|
|
60
|
-
}, {} as Pick<Obj, Key>);
|
|
61
|
-
|
|
62
|
-
type SizingStyle = Pick<CSSStyleDeclaration, SizingProps>;
|
|
63
|
-
|
|
64
|
-
export type SizingData = {
|
|
65
|
-
sizingStyle: SizingStyle;
|
|
66
|
-
paddingSize: number;
|
|
67
|
-
borderSize: number;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const isIE = !!(document.documentElement as any).currentStyle
|
|
71
|
-
|
|
72
|
-
const getSizingData = (node: HTMLElement): SizingData | null => {
|
|
73
|
-
|
|
74
|
-
const style = window.getComputedStyle(node);
|
|
75
|
-
|
|
76
|
-
if (style === null) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const sizingStyle = pick(SIZING_STYLE as unknown as SizingProps[], style);
|
|
81
|
-
const { boxSizing } = sizingStyle;
|
|
82
|
-
|
|
83
|
-
// probably node is detached from DOM, can't read computed dimensions
|
|
84
|
-
if (boxSizing === '') {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// IE (Edge has already correct behaviour) returns content width as computed width
|
|
89
|
-
// so we need to add manually padding and border widths
|
|
90
|
-
if (isIE && boxSizing === 'border-box') {
|
|
91
|
-
sizingStyle.width =
|
|
92
|
-
parseFloat(sizingStyle.width!) +
|
|
93
|
-
parseFloat(sizingStyle.borderRightWidth!) +
|
|
94
|
-
parseFloat(sizingStyle.borderLeftWidth!) +
|
|
95
|
-
parseFloat(sizingStyle.paddingRight!) +
|
|
96
|
-
parseFloat(sizingStyle.paddingLeft!) +
|
|
97
|
-
'px';
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const paddingSize =
|
|
101
|
-
parseFloat(sizingStyle.paddingBottom!) +
|
|
102
|
-
parseFloat(sizingStyle.paddingTop!);
|
|
103
|
-
|
|
104
|
-
const borderSize =
|
|
105
|
-
parseFloat(sizingStyle.borderBottomWidth!) +
|
|
106
|
-
parseFloat(sizingStyle.borderTopWidth!);
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
sizingStyle,
|
|
110
|
-
paddingSize,
|
|
111
|
-
borderSize,
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const Input = forwardRef((props : { [ key: string ] : any }, ref : Ref<HTMLTextAreaElement|HTMLInputElement>) => {
|
|
117
|
-
|
|
118
|
-
const {
|
|
119
|
-
as,
|
|
120
|
-
accept,
|
|
121
|
-
multiple,
|
|
122
|
-
onChange,
|
|
123
|
-
onKeyUp,
|
|
124
|
-
onClick,
|
|
125
|
-
onBlur,
|
|
126
|
-
onFocus,
|
|
127
|
-
readOnly,
|
|
128
|
-
type,
|
|
129
|
-
tag,
|
|
130
|
-
placeholder,
|
|
131
|
-
name,
|
|
132
|
-
form,
|
|
133
|
-
touched,
|
|
134
|
-
onSubmit,
|
|
135
|
-
value,
|
|
136
|
-
defaultValue,
|
|
137
|
-
fref,
|
|
138
|
-
autoComplete,
|
|
139
|
-
elastic,
|
|
140
|
-
minRows,
|
|
141
|
-
maxRows
|
|
142
|
-
} = props;
|
|
143
|
-
|
|
144
|
-
const dispatch = useDispatch(STORE_FORM_KEY)
|
|
145
|
-
const { forms } = useStore(state => state[STORE_FORM_KEY], false)
|
|
146
|
-
|
|
147
|
-
let Tag : string = tag || 'input';
|
|
148
|
-
const El = Tag as `textarea` | `input`
|
|
149
|
-
const _ref = fref || useRef();
|
|
150
|
-
|
|
151
|
-
const _defaultCSS = `width: 100%;border-radius: var(--radius-base);padding-left: 4px;padding-right: 4px;border-style: solid;border-width: 1px;border-color: var(--colors-gray-200);`;
|
|
152
|
-
|
|
153
|
-
const isControlled = props.value !== undefined;
|
|
154
|
-
const measurementsCacheRef = useRef<SizingData>();
|
|
155
|
-
|
|
156
|
-
const handleElastic = () => {
|
|
157
|
-
const node = _ref.current!
|
|
158
|
-
const nodeSizingData = measurementsCacheRef.current
|
|
159
|
-
? measurementsCacheRef.current : getSizingData(node)
|
|
160
|
-
if (!nodeSizingData) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
measurementsCacheRef.current = nodeSizingData;
|
|
164
|
-
|
|
165
|
-
// const [height, rowHeight] = calculateNodeHeight(
|
|
166
|
-
// nodeSizingData,
|
|
167
|
-
// node.value || node.placeholder || 'x',
|
|
168
|
-
// minRows || 6,
|
|
169
|
-
// maxRows || 6,
|
|
170
|
-
// );
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
useEffect(() => {}, [])
|
|
175
|
-
|
|
176
|
-
return (
|
|
177
|
-
<ClassNames>
|
|
178
|
-
{({ css, cx }) => <El
|
|
179
|
-
{...cleanProps(props)}
|
|
180
|
-
type={type || `text`}
|
|
181
|
-
placeholder={placeholder || undefined}
|
|
182
|
-
autoComplete={autoComplete || undefined}
|
|
183
|
-
name={name || nanoid()}
|
|
184
|
-
multiple={type == 'file' ? multiple : undefined}
|
|
185
|
-
accept={accept || `*`}
|
|
186
|
-
className={`${as ? `${as} ` : ``}f ${cx(css`${_defaultCSS}${buildCSS(props)}&:hover {${buildCSS(props.hover || {})}} &:focus {${buildCSS(props.focus || {})}}`)}`}
|
|
187
|
-
ref={_ref}
|
|
188
|
-
value={value || undefined}
|
|
189
|
-
defaultValue={defaultValue || ``}
|
|
190
|
-
onKeyUp={(e : SyntheticEvent) => {
|
|
191
|
-
let k = e['keyCode'] || ['which'];
|
|
192
|
-
if(form && onSubmit && El != 'textarea' && k == 13){
|
|
193
|
-
onSubmit(forms[form]);
|
|
194
|
-
}else{
|
|
195
|
-
if(onKeyUp) onKeyUp(e)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
}}
|
|
199
|
-
onChange={e => {
|
|
200
|
-
let val = type == 'file' ?
|
|
201
|
-
e.currentTarget.files
|
|
202
|
-
: e.currentTarget.value;
|
|
203
|
-
if(form) dispatch( dispatch( UPDATE_FORM_FIELD( form || 'orphan', name, val == "" ? null : val, forms ) ) );
|
|
204
|
-
// if(El == `textarea` && elastic) handleElastic()
|
|
205
|
-
onChange && onChange(val == "" ? null : val)
|
|
206
|
-
}}
|
|
207
|
-
onClick={onClick ? onClick : () => {}}
|
|
208
|
-
readOnly={readOnly || false}
|
|
209
|
-
onBlur={e => {
|
|
210
|
-
if(onBlur) onBlur(e)
|
|
211
|
-
if(touched){}
|
|
212
|
-
}}
|
|
213
|
-
onFocus={ e => {
|
|
214
|
-
if(touched == false)dispatch( UPDATE_FORM_FIELD( form || 'orphan', `touched`, true, forms ) )
|
|
215
|
-
if(onFocus) onFocus(e)
|
|
216
|
-
}}
|
|
217
|
-
/>}
|
|
218
|
-
</ClassNames>
|
|
219
|
-
)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
})
|
|
223
|
-
|
|
224
|
-
export default Input
|
|
1
|
+
import {
|
|
2
|
+
Ref,
|
|
3
|
+
forwardRef
|
|
4
|
+
} from "react";
|
|
5
|
+
import {
|
|
6
|
+
cleanProps,
|
|
7
|
+
withStyle
|
|
8
|
+
} from "../core";
|
|
9
|
+
|
|
10
|
+
const Input = forwardRef(( props: { [ key: string ] : any }, ref : Ref<HTMLTextAreaElement|HTMLInputElement>) => {
|
|
11
|
+
|
|
12
|
+
let Tag : string = props.tag || 'input';
|
|
13
|
+
const El = Tag as `textarea` | `input`
|
|
14
|
+
const _styles = withStyle(props)
|
|
15
|
+
|
|
16
|
+
return <El
|
|
17
|
+
className={_styles}
|
|
18
|
+
onChange={e => { props.onChange && props.onChange(e) }}
|
|
19
|
+
{ ...cleanProps(props) }
|
|
20
|
+
/>
|
|
21
|
+
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
export default Input
|
package/src/comps/select.tsx
CHANGED
|
@@ -1,63 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
form,
|
|
25
|
-
touched,
|
|
26
|
-
options,
|
|
27
|
-
defaultValue
|
|
28
|
-
} = props;
|
|
29
|
-
|
|
30
|
-
const _ref = useRef();
|
|
31
|
-
const dispatch = useDispatch(STORE_FORM_KEY)
|
|
32
|
-
const { forms } = useStore(state => state[STORE_FORM_KEY], false)
|
|
33
|
-
|
|
34
|
-
const _defaultCSS = `width: 100%;border-radius: var(--radius-base);padding-left: 4px;padding-right: 4px;border-style: solid;border-width: 1px;border-color: var(--colors-gray-200);`;
|
|
35
|
-
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
dispatch( dispatch( UPDATE_FORM_FIELD( form || 'orphan', name,
|
|
38
|
-
defaultValue && defaultValue != null && defaultValue != "" && defaultValue != undefined ? defaultValue : options[0]?.value || '-1',
|
|
39
|
-
forms ) ) );
|
|
40
|
-
}, [])
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<ClassNames>
|
|
44
|
-
{({ css, cx }) => <select
|
|
45
|
-
onChange={e => {
|
|
46
|
-
let val = e.currentTarget.value;
|
|
47
|
-
dispatch( dispatch( UPDATE_FORM_FIELD( form || 'orphan', name, val, forms ) ) );
|
|
48
|
-
onChange && onChange(val)
|
|
49
|
-
}}
|
|
50
|
-
onFocus={ e => touched == false && dispatch( UPDATE_FORM_FIELD( form || 'orphan', `touched`, true, forms ) ) }
|
|
51
|
-
onBlur={e => {
|
|
52
|
-
if(touched){}
|
|
53
|
-
}}
|
|
54
|
-
name={name || nanoid()}
|
|
55
|
-
className={`${as ? as : ``} ${cx(css`${_defaultCSS}${buildCSS(props)}&:hover {${buildCSS(props.hover || {})}}`)}`}
|
|
56
|
-
ref={_ref}>{options?.map(o => <option key={`select-${name}-option-${o.value}`} value={o.value}>{o.label}</option>)}</select>}
|
|
57
|
-
</ClassNames>
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
export default Select
|
|
1
|
+
import {
|
|
2
|
+
Ref,
|
|
3
|
+
forwardRef
|
|
4
|
+
} from "react";
|
|
5
|
+
import {
|
|
6
|
+
cleanProps,
|
|
7
|
+
withStyle
|
|
8
|
+
} from "../core";
|
|
9
|
+
|
|
10
|
+
const Select = forwardRef(( props: { [ key: string ] : any }, ref : Ref<HTMLTextAreaElement|HTMLInputElement>) => {
|
|
11
|
+
|
|
12
|
+
const _styles = withStyle(props)
|
|
13
|
+
|
|
14
|
+
return <select
|
|
15
|
+
className={_styles}
|
|
16
|
+
{ ...cleanProps(props) }
|
|
17
|
+
onChange={e => { props.onChange && props.onChange(e) }}>
|
|
18
|
+
{props.options && props.options.map(o => <option key={`${props.id || props.as || props.name}-option-${o.value}`} value={o.value}>{o.label}</option>)}
|
|
19
|
+
</select>
|
|
20
|
+
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export default Select
|
package/src/comps/spinner.tsx
CHANGED
|
@@ -1,36 +1,24 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import Box from './box'
|
|
3
|
-
import PropTypes from 'prop-types'
|
|
4
|
-
|
|
5
|
-
const Spinner = (props : any) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
s1: `5s`,
|
|
25
|
-
s2: `1s`
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
Spinner.propTypes = {
|
|
29
|
-
size: PropTypes.number.isRequired,
|
|
30
|
-
color: PropTypes.string,
|
|
31
|
-
radius: PropTypes.number,
|
|
32
|
-
s1: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
33
|
-
s2: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
34
|
-
}
|
|
35
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Box from './box'
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
|
|
5
|
+
const Spinner = (props : any) => {
|
|
6
|
+
|
|
7
|
+
const { size, w, h, color, radius, anim } = props
|
|
8
|
+
|
|
9
|
+
return <Box w={size || 50} rel zIndex={`1`} userSelect={`none`} h={size || 50} as={`zuz-spinner`} anim={(anim || 2).toString()} flex aic jcc>
|
|
10
|
+
<Box as={`zuz-loader`} r={radius || 4} w={w || 30} h={h || 6} bg={color || `#111`} />
|
|
11
|
+
</Box>
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Spinner.propTypes = {
|
|
16
|
+
size: PropTypes.number,
|
|
17
|
+
w: PropTypes.number,
|
|
18
|
+
h: PropTypes.number,
|
|
19
|
+
radius: PropTypes.number,
|
|
20
|
+
color: PropTypes.string,
|
|
21
|
+
anim: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
22
|
+
}
|
|
23
|
+
|
|
36
24
|
export default Spinner;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { createContext } from 'react'
|
|
2
|
-
const AppContext = createContext({});
|
|
1
|
+
import { createContext } from 'react'
|
|
2
|
+
const AppContext = createContext({});
|
|
3
3
|
export default AppContext;
|
|
@@ -1,106 +1,69 @@
|
|
|
1
|
-
import
|
|
2
|
-
useCallback,
|
|
3
|
-
useEffect,
|
|
4
|
-
useMemo,
|
|
5
|
-
useReducer
|
|
6
|
-
} from 'react'
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
[
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// console.log('key', key)
|
|
70
|
-
// console.log('state', _state)
|
|
71
|
-
// _dispatch({
|
|
72
|
-
// type: 'any',
|
|
73
|
-
// payload: {
|
|
74
|
-
// payload
|
|
75
|
-
// }
|
|
76
|
-
// })
|
|
77
|
-
// }
|
|
78
|
-
// }, [_dispatch]);
|
|
79
|
-
|
|
80
|
-
const providedValue = useMemo(
|
|
81
|
-
() => ({
|
|
82
|
-
...state,
|
|
83
|
-
dispatch
|
|
84
|
-
}),
|
|
85
|
-
[state]
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return <AppContext.Provider value={providedValue}>{children}</AppContext.Provider>
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
AppProvider.defaultProps = {
|
|
94
|
-
theme: {},
|
|
95
|
-
lang: {},
|
|
96
|
-
initialState : {},
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
AppProvider.propTypes = {
|
|
100
|
-
children: PropTypes.node.isRequired,
|
|
101
|
-
initialState: PropTypes.instanceOf(Object),
|
|
102
|
-
theme: PropTypes.instanceOf(Object),
|
|
103
|
-
lang: PropTypes.instanceOf(Object)
|
|
104
|
-
}
|
|
105
|
-
|
|
1
|
+
import {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo,
|
|
5
|
+
useReducer
|
|
6
|
+
} from 'react'
|
|
7
|
+
import AppContext from './AppContext'
|
|
8
|
+
|
|
9
|
+
let isMounted = true;
|
|
10
|
+
export const STORE_KEY = `__zuzjs`
|
|
11
|
+
export const STORE_FORM_KEY = `${STORE_KEY}forms`
|
|
12
|
+
export const STORE_DEFAUTLS = [`${STORE_KEY}base`, `${STORE_KEY}forms`]
|
|
13
|
+
|
|
14
|
+
const defaultState = {
|
|
15
|
+
[`${STORE_KEY}base`] : {
|
|
16
|
+
debug: true,
|
|
17
|
+
loading: false,
|
|
18
|
+
_tmp: Math.random()
|
|
19
|
+
},
|
|
20
|
+
[STORE_FORM_KEY] : {
|
|
21
|
+
forms: {}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const rootReducer = (state, action ) => ({
|
|
26
|
+
...state,
|
|
27
|
+
...action.payload
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const AppProvider = ({
|
|
31
|
+
children,
|
|
32
|
+
initialState = {}
|
|
33
|
+
}) => {
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
isMounted = true;
|
|
37
|
+
return () => {
|
|
38
|
+
isMounted = false;
|
|
39
|
+
}
|
|
40
|
+
}, [])
|
|
41
|
+
|
|
42
|
+
const rootState = useMemo(() => ({
|
|
43
|
+
...defaultState,
|
|
44
|
+
...initialState
|
|
45
|
+
}), [initialState])
|
|
46
|
+
|
|
47
|
+
const [state, _dispatch] = useReducer(rootReducer, rootState);
|
|
48
|
+
|
|
49
|
+
const dispatch = useCallback((args) => {
|
|
50
|
+
if (isMounted) {
|
|
51
|
+
_dispatch({ ...args });
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
[_dispatch],
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const providedValue = useMemo(
|
|
58
|
+
() => ({
|
|
59
|
+
...state,
|
|
60
|
+
dispatch
|
|
61
|
+
}),
|
|
62
|
+
[state]
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
return <AppContext.Provider value={providedValue}>{children}</AppContext.Provider>
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
106
69
|
export default AppProvider
|
|
@@ -1,40 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// const _keys = Object.keys(reducers);
|
|
17
|
-
// const [reducer, state] = combineReducers(_dynamiceReducers);
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
name,
|
|
21
|
-
reducer: reducers,
|
|
22
|
-
actions: reducers,
|
|
23
|
-
state: initialState
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
createSlice.defaultProps = {
|
|
29
|
-
name: `app`,
|
|
30
|
-
initialState: {},
|
|
31
|
-
reducers: {}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
createSlice.propTypes = {
|
|
35
|
-
name: PropTypes.string.isRequired,
|
|
36
|
-
initialState: PropTypes.instanceOf(Object).isRequired,
|
|
37
|
-
reducers: PropTypes.instanceOf(Object).isRequired
|
|
38
|
-
}
|
|
39
|
-
|
|
1
|
+
const createSlice = ({
|
|
2
|
+
name,
|
|
3
|
+
initialState,
|
|
4
|
+
reducers
|
|
5
|
+
}) => {
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
name,
|
|
9
|
+
reducer: reducers,
|
|
10
|
+
actions: reducers,
|
|
11
|
+
state: initialState
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
40
16
|
export default createSlice;
|
package/src/context/index.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import AppContext from './AppContext'
|
|
2
|
-
|
|
3
|
-
export default AppContext;
|
|
4
|
-
|
|
5
|
-
export { default as Provider } from './AppProvider';
|
|
1
|
+
import AppContext from './AppContext'
|
|
2
|
+
|
|
3
|
+
export default AppContext;
|
|
4
|
+
export { default as Provider } from './AppProvider';
|
|
6
5
|
export { default as createSlice } from './createSlice';
|
package/src/core/css.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {}
|