@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
@@ -1,117 +0,0 @@
1
- import { nanoid } from 'nanoid'
2
-
3
- class Toaster {
4
-
5
- #container : any;
6
- #startTop : number
7
- #tout : null
8
- #defaultTimeLeft : number
9
- #root : string
10
-
11
- constructor(config?: {
12
- root : string,
13
- duration: number
14
- }){
15
- this.#startTop = 20
16
- this.#defaultTimeLeft = 4
17
- const rootID = config?.root || `toast-container`;
18
- this.#root = rootID;
19
- if(window.document.querySelector(`#${rootID}`)) return;
20
- var self = this;
21
- var root = window.document.createElement('div');
22
- root.id = rootID;
23
- window.document.body.appendChild(root);
24
- this.#container = window.document.querySelector(`#${rootID}`)
25
- }
26
-
27
- show = (
28
- message: string | null,
29
- duration?: number
30
- ) => {
31
- let self = this;
32
- self.toast({
33
- message: message,
34
- duration: duration
35
- });
36
- }
37
-
38
- dismiss(ID: string){
39
- let self = this
40
- self.#tout && clearTimeout(self.#tout);
41
- setTimeout(()=>{
42
- let tost = document.querySelector(`#${ID}`);
43
- tost && tost.classList.remove("visible");
44
- // tost && tost.classList.add("hidden");
45
- setTimeout(()=>{
46
- try{
47
- document.getElementById(ID).parentNode.removeChild(document.getElementById(ID));
48
- }catch(e){}
49
- self.arrangeToasts();
50
- }, 200);
51
- }, 200);
52
- }
53
-
54
- toast(config?: {
55
- message: string | null,
56
- duration: number
57
- }){
58
-
59
- var self = this;
60
- var tout = null,
61
- ID = 'toast-' + nanoid(),
62
- toast = window.document.createElement('div'),
63
- toastBG = window.document.createElement('div');
64
-
65
- toast.id = ID;
66
- toast.style.backgroundColor = `#111`
67
- toast.style.color = `#fff`
68
- toast.style.transform = `translate(-50%, -300px) scale(0.5)`;
69
- toast.style.position = `fixed`
70
- toast.style.padding = `6px 12px`
71
- toast.style.fontSize = `14px`
72
- toast.style.left = `50%`
73
- toast.style.maxWidth = `95%`
74
- toast.style.zIndex = `2147483647`
75
- toast.classList.add( 'zuz-toast' );
76
- toast.classList.add( 'fixed' );
77
- toast.classList.add( 'f' );
78
-
79
- toast.innerHTML = config.message || `You haven't passed "message" in this toast`;
80
-
81
- (self.#container || window.document.querySelector(`#${self.#root}`)).appendChild(toast);
82
-
83
- self.arrangeToasts()
84
- .then(() => {
85
- setTimeout(()=>{
86
- let tost = document.querySelector("#"+ID);
87
- tost.classList.add("showing");
88
- tout = setTimeout(() => self.dismiss(ID), (config?.duration == undefined ? self.#defaultTimeLeft : config?.duration == -1 ? 86400 : config?.duration) * 1000);
89
- setTimeout(()=>{
90
- let tost = document.querySelector("#"+ID);
91
- tost.classList.remove("showing");
92
- tost.classList.add("visible");
93
- }, 200)
94
-
95
- }, 10)
96
- });
97
- }
98
-
99
- arrangeToasts(){
100
- var self = this, top = self.#startTop;
101
- return new Promise((resolve, reject) => {
102
- var toasts = document.querySelectorAll(".zuz-toast"),
103
- i = toasts.length;
104
- while(i--){
105
- toasts[i]['style'].top = `${top}px`
106
- top += parseInt(getComputedStyle(toasts[i]).height.replace('px', '')) + 6;
107
- }
108
- resolve(null);
109
- });
110
- }
111
-
112
-
113
-
114
-
115
- }
116
-
117
- export default Toaster;
@@ -1,48 +0,0 @@
1
- import React, { useEffect, useRef, useState } from 'react';
2
- // import PropTypes from `prop-types`
3
- import Box from './box'
4
- import { addScript } from '../core';
5
-
6
- const Tweet = (props) => {
7
-
8
- const [rand, setRand] = useState(Math.random())
9
- const _tweet = useRef()
10
-
11
- const renderTweet = () => {
12
- const twttr = window['twttr']
13
- twttr.ready().then(({ widgets }) => {
14
- const { options, onTweetLoadSuccess, onTweetLoadError } = props
15
- widgets
16
- .createTweetEmbed(props.id, _tweet.current, options || {})
17
- .then((twitterWidgetElement) => {
18
- // this.setState({
19
- // isLoading: false
20
- // })
21
- // onTweetLoadSuccess && onTweetLoadSuccess(twitterWidgetElement)
22
- })
23
- .catch(() => {})
24
-
25
- })
26
- }
27
-
28
- useEffect(() => {
29
- const twttr = window['twttr']
30
- if (!(twttr && twttr.ready)){
31
- addScript(`https://platform.twitter.com/widgets.js`, renderTweet)
32
- }else{
33
- renderTweet()
34
- }
35
- }, [])
36
-
37
- useEffect(() => {
38
-
39
- }, [rand])
40
-
41
- return (
42
- <Box as={`tweet`} weight={1} bref={_tweet}></Box>
43
- );
44
- }
45
-
46
-
47
-
48
- export default Tweet;
@@ -1,116 +0,0 @@
1
- import React, {
2
- useCallback,
3
- useEffect,
4
- useMemo,
5
- useReducer
6
- } from 'react'
7
- import PropTypes from 'prop-types'
8
- import AppContext from './AppContext'
9
- // import useAppReducer from '../hooks/useAppReducer'
10
- import AppTheme from './store/theme'
11
- let isMounted = true;
12
- import appSlice from './store/appbase'
13
- import combineReducers, { combineState } from './combineReducers'
14
- import reduceReducers from './reduceReducers'
15
- // const rootReducer = (state, action ) => ({
16
- // ...state,
17
- // ...action.payload
18
- // })
19
-
20
- // const rootReducer = combineReducers()
21
-
22
- const AppProvider = ({
23
- children,
24
- // initialState = {},
25
- reducers = {},
26
- theme = {}
27
- }) => {
28
-
29
- const _dynamiceState = useMemo(() => {
30
- const __ = {}
31
- Object.keys(reducers).map(k => {
32
- __[reducers[k].name] = [reducers[k].reducer, reducers[k].state]
33
- })
34
- return __
35
- }, [reducers])
36
-
37
- const _dynamiceReducers = useMemo(() => {
38
- const __ = {}
39
- Object.keys(reducers).map(k => {
40
- __[reducers[k].name] = reduceReducers(reducers[k].reducer)
41
- })
42
- return __
43
- }, [reducers])
44
-
45
- const themeReducer = useCallback(() => {
46
- (state, action) => ({
47
- ...state,
48
- ...action.payload
49
- })
50
- }, [])
51
-
52
- // const [rootReducer, rootState] = useMemo(() => combineReducers({
53
- // theme: [themeReducer, new AppTheme({ theme }).get()],
54
- // [appSlice.name] : [appSlice.reducer, appSlice.state],
55
- // ..._dynamiceReducers
56
- // }), [reducers]);
57
-
58
- const [_, rootState] = combineState({
59
- theme: [themeReducer, new AppTheme({ theme }).get()],
60
- [appSlice.name] : [appSlice.reducer, appSlice.state],
61
- ..._dynamiceState
62
- })
63
-
64
- const rootReducer = combineReducers({
65
- theme: reduceReducers(themeReducer),
66
- [appSlice.name] : reduceReducers(appSlice.reducer),
67
- ..._dynamiceReducers
68
- })
69
-
70
- console.log(rootState)
71
-
72
- const [state, dispatch] = useReducer(
73
- rootReducer,
74
- rootState
75
- );
76
-
77
- useEffect(() => {
78
- isMounted = true;
79
- return () => {
80
- isMounted = false;
81
- }
82
- }, [])
83
-
84
- // const dispatch = useCallback(() => {
85
- // if(isMounted){
86
- // // let ags = { ...args, action: }
87
- // _dispatch();
88
- // // _dispatch({ action: action, payload: payload })
89
- // }
90
- // }, [_dispatch]);
91
-
92
- const providedValue = useMemo(
93
- () => ({
94
- ...rootState,
95
- // defaultState,
96
- dispatch
97
- }),
98
- [state]
99
- // [defaultState, state]
100
- )
101
-
102
- return <AppContext.Provider value={providedValue}>{children}</AppContext.Provider>
103
- }
104
-
105
- AppProvider.defaultProps = {
106
- reducers: {}
107
- // initialState : {},
108
- }
109
-
110
- AppProvider.propTypes = {
111
- children: PropTypes.node.isRequired,
112
- // initialState: PropTypes.instanceOf(Object)
113
- reducers: PropTypes.instanceOf(Object)
114
- }
115
-
116
- export default AppProvider
@@ -1,47 +0,0 @@
1
- export const combineState = reducers => {
2
- const reducerKeys = Object.keys(reducers);
3
- const reducerValues = Object.values(reducers);
4
-
5
- let globalState
6
- reducerKeys.forEach((k, i) => globalState = { ...globalState, [k]: reducerValues[i][1] } )
7
-
8
- let finalReducers = {}
9
- reducerValues.forEach((v, i) => finalReducers = { ...finalReducers, [reducerKeys[i]] : v[0] });
10
-
11
- return [
12
- (state, action) => {
13
- console.log('state', state)
14
- console.log('action', action)
15
- let hasStateChanged = false
16
- const newState = {}
17
- let nextStateForCurrentKey = {}
18
- for(let i = 0; i < reducerKeys.length; i++){
19
- const currentKey = reducerKeys[i]
20
- const currentReducer = finalReducers[currentKey]
21
- const prevStateForCurrentKey = state[currentKey]
22
- nextStateForCurrentKey = currentReducer(
23
- prevStateForCurrentKey,
24
- action
25
- )
26
- hasStateChanged = hasStateChanged || nextStateForCurrentKey !== prevStateForCurrentKey
27
- newState[currentKey] = nextStateForCurrentKey
28
- }
29
- return hasStateChanged ? newState : state
30
- },
31
- globalState
32
- ]
33
-
34
- }
35
-
36
- const combineReducers = slices => {
37
- return (state, action) =>
38
- Object.keys(slices).reduce(
39
- (acc, prop) => ({
40
- ...acc,
41
- [prop]: slices[prop](acc[prop], action)
42
- }),
43
- state
44
- )
45
- }
46
-
47
- export default combineReducers;
@@ -1,14 +0,0 @@
1
- const combineState = (state) => {
2
- // const reducerKeys = Object.keys(state);
3
- // const stateValues = Object.values(state);
4
-
5
- // let globalState
6
-
7
- // reducerKeys.forEach((k, i) => globalState = { ...globalState, [k]: reducerValues[i][1] } )
8
-
9
- // console.log(globalState)
10
-
11
- return state;
12
- }
13
-
14
- export default combineState
@@ -1,6 +0,0 @@
1
- const reduceReducers = (...reducers) => {
2
- return (state, action) =>
3
- reducers.reduce((acc, nextReducer) => nextReducer(acc, action), state)
4
- }
5
-
6
- export default reduceReducers;
@@ -1,19 +0,0 @@
1
- import createSlice from '../createSlice'
2
-
3
- const appSlice = createSlice({
4
- name: 'app',
5
- initialState: {
6
- debug: true,
7
- version: 1.2,
8
- loading: false
9
- },
10
- reducers: {
11
- setCVersion: (state, action) => state.version = action.payload
12
- }
13
- });
14
-
15
- export const {
16
- setLoading
17
- } = appSlice.actions
18
-
19
- export default appSlice;
@@ -1,26 +0,0 @@
1
- class AppLang {
2
-
3
- #mode;
4
- #listen;
5
- #lang;
6
-
7
- constructor(_conf){
8
- const conf = _conf || {}
9
- this.#listen = "listen" in conf ? conf.listen : (mod) => { console.log(`Lang switched to ${mod}`); };
10
- this.#mode = conf.mode || "en";
11
- this.#lang = {
12
- //CORE
13
- tag: "en",
14
- ...( "lang" in conf ? {...conf.lang} : {})
15
- };
16
- }
17
-
18
- get = () => {
19
- let self = this;
20
- return self.#lang
21
- }
22
-
23
-
24
- }
25
-
26
- export default AppLang
@@ -1,54 +0,0 @@
1
- class AppTheme {
2
-
3
- #mode;
4
- #listen;
5
- #lightTheme;
6
- #darkTheme;
7
-
8
- constructor(_conf){
9
- const conf = _conf || {}
10
- this.#listen = "listen" in conf ? conf.listen : (mod) => { console.log(`Theme switched to ${mod}`); };
11
- this.#mode = conf.mode || conf.theme.mode || "auto";
12
- this.#lightTheme = {
13
- //CORE
14
- tag: "light",
15
- dark: false,
16
- primary: '#edeef5',
17
- secondary: '#f9f9f9',
18
- textColor: '#111111',
19
- ...( "theme" in conf && "light" in conf.theme ? {...conf.theme.light} : {})
20
- };
21
- this.#darkTheme = {
22
- //CORE
23
- tag: "dark",
24
- dark: true,
25
- primary: '#21222d',
26
- secondary: '#282a37',
27
- textColor: '#f9f9f9',
28
- ...( "theme" in conf && "dark" in conf.theme ? {...conf.theme.dark} : {})
29
- };
30
- }
31
-
32
- get = () => {
33
- let self = this;
34
- if(self.#mode === "auto"){
35
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
36
- self.#mode = event.matches ? "dark" : "light";
37
- self.#listen(self.#mode);
38
- });
39
- return window.matchMedia &&
40
- window.matchMedia('(prefers-color-scheme: dark)').matches ?
41
- self.#darkTheme : self.#lightTheme;
42
- }else{
43
- if(self.#mode === "light"){
44
- return self.#lightTheme;
45
- }else if(self.#mode === "dark"){
46
- return self.#darkTheme;
47
- }
48
- }
49
- }
50
-
51
-
52
- }
53
-
54
- export default AppTheme
@@ -1,90 +0,0 @@
1
- class AppTheme {
2
-
3
- #mode;
4
- #listen;
5
- #lightTheme;
6
- #darkTheme;
7
-
8
- constructor(_conf){
9
- const conf = _conf || {}
10
- this.#listen = "listen" in conf ? conf.listen : (mod) => { console.log(`Theme switched to ${mod}`); };
11
- this.#mode = conf.mode || "auto";
12
- this.#lightTheme = {
13
- //CORE
14
- tag: "light",
15
- dark: false,
16
- color: "#3a43ac",
17
- primary: '#edeef5',
18
- secondary: '#e8e9f0',
19
- textColor: '#111111',
20
- borderColor: '#dcdce1',
21
- //APP
22
- app: {
23
- action: 'rgba(0,0,0,0.1)',
24
- actionHover: 'rgba(255,255,255,0.1)',
25
- actionActive: 'rgba(0,0,0,0.8)',
26
- actionDisabled: 'rgba(255,255,255,0.01)',
27
- shimmerBG: '#383a48',
28
- shimmerFrom: '#383a48',
29
- shimmerTo: '#4a4c5b',
30
- iconBG: '#4a4c5b',
31
- icon: '#111111',
32
- sidebarHover: 'rgba(255,255,255,0.2)',
33
- sidebarActive: 'rgba(255,255,255,1)',
34
- toolbar: '#d5d6dc',
35
- tool: 'transparent',
36
- toolActive: 'rgba(255,255,255,0.75)',
37
- toolHover: 'rgba(255,255,255,0.5)',
38
- }
39
- };
40
- this.#darkTheme = {
41
- //CORE
42
- tag: "dark",
43
- dark: true,
44
- color: "#3a43ac",
45
- primary: '#21222d',
46
- secondary: '#282a37',
47
- textColor: '#f9f9f9',
48
- borderColor: '#353640',
49
- //APP
50
- app: {
51
- action: 'rgba(255,255,255,0.05)',
52
- actionHover: 'rgba(255,255,255,0.1)',
53
- actionActive: 'rgba(255,255,255,0.2)',
54
- actionDisabled: 'rgba(255,255,255,0.01)',
55
- shimmerBG: '#383a48',
56
- shimmerFrom: '#383a48',
57
- shimmerTo: '#4a4c5b',
58
- iconBG: '#4a4c5b',
59
- icon: '#ffffff',
60
- toolbar: '#21222d',
61
- tool: 'transparent',
62
- toolHover: '#2f3144',
63
- toolActive: '#2f3144',
64
- }
65
- };
66
- }
67
-
68
- get = () => {
69
- let self = this;
70
- if(self.#mode === "auto"){
71
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
72
- self.#mode = event.matches ? "dark" : "light";
73
- self.#listen(self.#mode);
74
- });
75
- return window.matchMedia &&
76
- window.matchMedia('(prefers-color-scheme: dark)').matches ?
77
- self.#darkTheme : self.#lightTheme;
78
- }else{
79
- if(self.#mode === "light"){
80
- return self.#lightTheme;
81
- }else if(self.#mode === "dark"){
82
- return self.#darkTheme;
83
- }
84
- }
85
- }
86
-
87
-
88
- }
89
-
90
- export default AppTheme
File without changes