@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/hooks/useDevice.tsx
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { useMemo, useState, useCallback, useDebugValue } from 'react'
|
|
2
|
-
import useChooseEffect from './useChooseEffect'
|
|
3
|
-
|
|
4
|
-
export type Config = {
|
|
5
|
-
readonly [key: string]: number
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export type MediaQuery<C extends Config> = {
|
|
9
|
-
breakpoint: keyof C
|
|
10
|
-
maxWidth: number | null
|
|
11
|
-
minWidth: C[keyof C]
|
|
12
|
-
query: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type Breakpoint<C extends Config> = {
|
|
16
|
-
breakpoint: keyof C
|
|
17
|
-
maxWidth?: number | null
|
|
18
|
-
minWidth: C[keyof C]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const EMPTY_BREAKPOINT = {
|
|
22
|
-
breakpoint: undefined,
|
|
23
|
-
minWidth: undefined,
|
|
24
|
-
maxWidth: undefined,
|
|
25
|
-
} as const
|
|
26
|
-
|
|
27
|
-
type Return<C extends Config, D> = D extends undefined
|
|
28
|
-
? Breakpoint<C> | typeof EMPTY_BREAKPOINT
|
|
29
|
-
: D extends keyof C
|
|
30
|
-
? Breakpoint<C>
|
|
31
|
-
: never
|
|
32
|
-
|
|
33
|
-
const useDevice = <C extends Config, D extends keyof C | undefined>(
|
|
34
|
-
config: C,
|
|
35
|
-
defaultBreakpoint?: D,
|
|
36
|
-
hydrateInitial = true
|
|
37
|
-
) : Return<C, D> => {
|
|
38
|
-
|
|
39
|
-
const buildQueries = (breakpoints: Config) : MediaQuery<Config>[] => {
|
|
40
|
-
const sorted = Object.keys(breakpoints).sort(
|
|
41
|
-
(a, b) => breakpoints[b] - breakpoints[a]
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
return sorted.map((breakpoint, index) => {
|
|
45
|
-
let query = ''
|
|
46
|
-
const minWidth = breakpoints[breakpoint]
|
|
47
|
-
const nextBreakpoint = sorted[index - 1] as string | undefined
|
|
48
|
-
const maxWidth = nextBreakpoint ? breakpoints[nextBreakpoint] : null
|
|
49
|
-
|
|
50
|
-
if (minWidth >= 0) {
|
|
51
|
-
query = `(min-width: ${minWidth}px)`
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (maxWidth !== null) {
|
|
55
|
-
if (query) {
|
|
56
|
-
query += ' and '
|
|
57
|
-
}
|
|
58
|
-
query += `(max-width: ${maxWidth - 1}px)`
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const mediaQuery: MediaQuery<Config> = {
|
|
62
|
-
breakpoint,
|
|
63
|
-
maxWidth: maxWidth ? maxWidth - 1 : null,
|
|
64
|
-
minWidth,
|
|
65
|
-
query,
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return mediaQuery
|
|
69
|
-
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** Memoize list of calculated media queries from config */
|
|
75
|
-
const mediaQueries = useMemo(() => buildQueries(config), [config])
|
|
76
|
-
|
|
77
|
-
/** Get initial breakpoint value */
|
|
78
|
-
const [currentBreakpoint, setCurrentBreakpoint] = useState<
|
|
79
|
-
Breakpoint<C> | typeof EMPTY_BREAKPOINT
|
|
80
|
-
>(() => {
|
|
81
|
-
/** Loop through all media queries */
|
|
82
|
-
for (const { query, ...breakpoint } of mediaQueries) {
|
|
83
|
-
/**
|
|
84
|
-
* If we're in the browser and there's no default value,
|
|
85
|
-
* try to match actual breakpoint. If the default value
|
|
86
|
-
* should not be hydrated, use the actual breakpoint.
|
|
87
|
-
*/
|
|
88
|
-
if (
|
|
89
|
-
typeof window !== 'undefined' &&
|
|
90
|
-
!(defaultBreakpoint && hydrateInitial)
|
|
91
|
-
) {
|
|
92
|
-
const mediaQuery = window.matchMedia(query)
|
|
93
|
-
if (mediaQuery.matches) {
|
|
94
|
-
return breakpoint as Breakpoint<C>
|
|
95
|
-
}
|
|
96
|
-
} else if (breakpoint.breakpoint === defaultBreakpoint) {
|
|
97
|
-
/** Otherwise, try to match default value */
|
|
98
|
-
return breakpoint as Breakpoint<C>
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return EMPTY_BREAKPOINT
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
/** If there's a match, update the current breakpoint */
|
|
106
|
-
const updateBreakpoint = useCallback(
|
|
107
|
-
(
|
|
108
|
-
{ matches }: MediaQueryList | MediaQueryListEvent,
|
|
109
|
-
breakpoint: Breakpoint<C>
|
|
110
|
-
) => {
|
|
111
|
-
if (matches) {
|
|
112
|
-
setCurrentBreakpoint(breakpoint)
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
[]
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
/** On changes to mediaQueries, subscribe to changes using window.matchMedia */
|
|
119
|
-
useChooseEffect(() => {
|
|
120
|
-
const unsubscribers = mediaQueries.map(({ query, ...breakpoint }) => {
|
|
121
|
-
const list = window.matchMedia(query)
|
|
122
|
-
updateBreakpoint(list, breakpoint as Breakpoint<C>)
|
|
123
|
-
|
|
124
|
-
const handleChange = (event: MediaQueryListEvent) => {
|
|
125
|
-
updateBreakpoint(event, breakpoint as Breakpoint<C>)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const supportsNewEventListeners =
|
|
129
|
-
'addEventListener' in list && 'removeEventListener' in list
|
|
130
|
-
|
|
131
|
-
if (supportsNewEventListeners) {
|
|
132
|
-
list.addEventListener('change', handleChange)
|
|
133
|
-
} else {
|
|
134
|
-
;(list as MediaQueryList).addListener(handleChange)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/** Map the unsubscribers array to a list of unsubscriber methods */
|
|
138
|
-
return () => {
|
|
139
|
-
if (supportsNewEventListeners) {
|
|
140
|
-
list.removeEventListener('change', handleChange)
|
|
141
|
-
} else {
|
|
142
|
-
;(list as MediaQueryList).removeListener(handleChange)
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
/** Return a function that when called, will call all unsubscribers */
|
|
148
|
-
return () => unsubscribers.forEach((unsubscriber) => unsubscriber())
|
|
149
|
-
}, [mediaQueries, updateBreakpoint])
|
|
150
|
-
|
|
151
|
-
/** Print a nice debug value for React Devtools */
|
|
152
|
-
useDebugValue(currentBreakpoint, (c) =>
|
|
153
|
-
typeof c.breakpoint === 'string'
|
|
154
|
-
? `${c.breakpoint} (${c.minWidth} ≤ x${
|
|
155
|
-
c.maxWidth ? ` < ${c.maxWidth + 1}` : ''
|
|
156
|
-
})`
|
|
157
|
-
: ''
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
return currentBreakpoint as Return<C, D>
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export default useDevice;
|
package/src/hooks/useImage.tsx
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import React, {useState} from 'react'
|
|
2
|
-
import { imgPromiseFactory } from '../core'
|
|
3
|
-
|
|
4
|
-
export type useImageProps = {
|
|
5
|
-
srcList: string | string[]
|
|
6
|
-
imgPromise?: (...args: any[]) => Promise<void>
|
|
7
|
-
useSuspense?: boolean
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const removeBlankArrayElements = (a) => a.filter((x) => x)
|
|
11
|
-
const stringToArray = (x) => (Array.isArray(x) ? x : [x])
|
|
12
|
-
const cache = {}
|
|
13
|
-
|
|
14
|
-
// sequential map.find for promises
|
|
15
|
-
const promiseFind = (arr, promiseFactory) => {
|
|
16
|
-
let done = false
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
const queueNext = (src) => {
|
|
19
|
-
return promiseFactory(src).then(() => {
|
|
20
|
-
done = true
|
|
21
|
-
resolve(src)
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
arr
|
|
26
|
-
.reduce((p, src) => {
|
|
27
|
-
// ensure we aren't done before enqueuing the next source
|
|
28
|
-
return p.catch(() => {
|
|
29
|
-
if (!done) return queueNext(src)
|
|
30
|
-
})
|
|
31
|
-
}, queueNext(arr.shift()))
|
|
32
|
-
.catch(reject)
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const useImage = ({
|
|
37
|
-
srcList,
|
|
38
|
-
imgPromise = imgPromiseFactory({decode: true}),
|
|
39
|
-
useSuspense = true,
|
|
40
|
-
} : useImageProps) : {src: string | undefined; isLoading: boolean; error: any} => {
|
|
41
|
-
|
|
42
|
-
const [, setIsSettled] = useState(false)
|
|
43
|
-
const sourceList = removeBlankArrayElements(stringToArray(srcList))
|
|
44
|
-
const sourceKey = sourceList.join('')
|
|
45
|
-
|
|
46
|
-
if (!cache[sourceKey]) {
|
|
47
|
-
// create promise to loop through sources and try to load one
|
|
48
|
-
cache[sourceKey] = {
|
|
49
|
-
promise: promiseFind(sourceList, imgPromise),
|
|
50
|
-
cache: 'pending',
|
|
51
|
-
error: null,
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// when promise resolves/reject, update cache & state
|
|
56
|
-
if (cache[sourceKey].cache === 'resolved') {
|
|
57
|
-
return {src: cache[sourceKey].src, isLoading: false, error: null}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (cache[sourceKey].cache === 'rejected') {
|
|
61
|
-
if (useSuspense) throw cache[sourceKey].error
|
|
62
|
-
return {isLoading: false, error: cache[sourceKey].error, src: undefined}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
cache[sourceKey].promise
|
|
66
|
-
// if a source was found, update cache
|
|
67
|
-
// when not using suspense, update state to force a rerender
|
|
68
|
-
.then((src) => {
|
|
69
|
-
cache[sourceKey] = {...cache[sourceKey], cache: 'resolved', src}
|
|
70
|
-
if (!useSuspense) setIsSettled(sourceKey)
|
|
71
|
-
})
|
|
72
|
-
// if no source was found, or if another error occurred, update cache
|
|
73
|
-
// when not using suspense, update state to force a rerender
|
|
74
|
-
.catch((error) => {
|
|
75
|
-
cache[sourceKey] = {...cache[sourceKey], cache: 'rejected', error}
|
|
76
|
-
if (!useSuspense) setIsSettled(sourceKey)
|
|
77
|
-
})
|
|
78
|
-
// cache[sourceKey].cache === 'pending')
|
|
79
|
-
if (useSuspense) throw cache[sourceKey].promise
|
|
80
|
-
return {isLoading: true, src: undefined, error: null}
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export default useImage;
|
package/src/hooks/useLang.tsx
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo } from "react"
|
|
2
|
-
import { uuid } from "../core"
|
|
3
|
-
|
|
4
|
-
const useMediaPlayer = (
|
|
5
|
-
playerID? : string
|
|
6
|
-
) => {
|
|
7
|
-
|
|
8
|
-
const pid = useMemo(() => playerID || uuid(), [playerID])
|
|
9
|
-
const ID = `media-player-${pid}`
|
|
10
|
-
|
|
11
|
-
const el = (e : string) => window.document.createElement(e)
|
|
12
|
-
|
|
13
|
-
const createRoot = () => {
|
|
14
|
-
if(!window.document.querySelector(`#${ID}`)){
|
|
15
|
-
let div = el(`div`)
|
|
16
|
-
div.id = ID
|
|
17
|
-
window.document.body.appendChild(div)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
|
|
23
|
-
}, [])
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default useMediaPlayer
|
package/src/hooks/useRender.tsx
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from "react"
|
|
2
|
-
|
|
3
|
-
const useRender = (isMounted: boolean, delay: number) => {
|
|
4
|
-
|
|
5
|
-
const [canRender, setCanRender] = useState(false)
|
|
6
|
-
|
|
7
|
-
// console.log(
|
|
8
|
-
// `isMounted:`, isMounted,
|
|
9
|
-
// `canRender:`, canRender,
|
|
10
|
-
// )
|
|
11
|
-
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
let outID : any
|
|
14
|
-
if(isMounted && !canRender){
|
|
15
|
-
setCanRender(true)
|
|
16
|
-
}else if(isMounted && canRender){
|
|
17
|
-
outID = setTimeout(
|
|
18
|
-
() => setCanRender(false),
|
|
19
|
-
delay * 1000
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
return () => clearTimeout(outID);
|
|
23
|
-
}, [isMounted, delay])
|
|
24
|
-
|
|
25
|
-
return canRender;
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default useRender
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/** External Dependencies */
|
|
2
|
-
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
3
|
-
|
|
4
|
-
const useResizeObserver = (onResized) => {
|
|
5
|
-
|
|
6
|
-
const onResize = onResized ? onResized : () => {};
|
|
7
|
-
const onResizeCallback = useRef(onResize);
|
|
8
|
-
const resizeObserver = useRef();
|
|
9
|
-
|
|
10
|
-
const observerCallback = useCallback((entries) => {
|
|
11
|
-
entries.forEach((entry) => {
|
|
12
|
-
if (entry.contentRect) {
|
|
13
|
-
const { width, height } = entry.contentRect;
|
|
14
|
-
|
|
15
|
-
onResizeCallback.current({
|
|
16
|
-
entry,
|
|
17
|
-
width,
|
|
18
|
-
height,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}, []);
|
|
23
|
-
|
|
24
|
-
const updateOnResizeCallback = useCallback((newOnResizeCallback) => {
|
|
25
|
-
onResizeCallback.current = newOnResizeCallback;
|
|
26
|
-
}, []);
|
|
27
|
-
|
|
28
|
-
const initObserver = useCallback(() => {
|
|
29
|
-
if (!resizeObserver.current) {
|
|
30
|
-
{/*
|
|
31
|
-
// @ts-ignore */}
|
|
32
|
-
resizeObserver.current = new ResizeObserver(observerCallback);
|
|
33
|
-
}
|
|
34
|
-
}, []);
|
|
35
|
-
|
|
36
|
-
const observeElement = useCallback((element, newOnResizeCallback) => {
|
|
37
|
-
if (element) {
|
|
38
|
-
if (!resizeObserver.current) {
|
|
39
|
-
initObserver();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
{/*
|
|
43
|
-
// @ts-ignore */}
|
|
44
|
-
resizeObserver.current.observe(element);
|
|
45
|
-
|
|
46
|
-
if (newOnResizeCallback) {
|
|
47
|
-
onResizeCallback.current = newOnResizeCallback;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}, []);
|
|
51
|
-
|
|
52
|
-
const unobserveElement = useCallback((element, newOnResizeCallback) => {
|
|
53
|
-
if (resizeObserver.current && element) {
|
|
54
|
-
|
|
55
|
-
{/*
|
|
56
|
-
// @ts-ignore */}
|
|
57
|
-
resizeObserver.current.unobserve(element);
|
|
58
|
-
|
|
59
|
-
if (newOnResizeCallback) {
|
|
60
|
-
onResizeCallback.current = newOnResizeCallback;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}, []);
|
|
64
|
-
|
|
65
|
-
const removeObserver = useCallback(() => {
|
|
66
|
-
if (resizeObserver.current) {
|
|
67
|
-
{/*
|
|
68
|
-
// @ts-ignore */}
|
|
69
|
-
resizeObserver.current.disconnect();
|
|
70
|
-
}
|
|
71
|
-
}, []);
|
|
72
|
-
|
|
73
|
-
useEffect(() => {
|
|
74
|
-
initObserver();
|
|
75
|
-
return removeObserver;
|
|
76
|
-
}, []);
|
|
77
|
-
|
|
78
|
-
return useMemo(
|
|
79
|
-
() => [observeElement, unobserveElement, updateOnResizeCallback],
|
|
80
|
-
[],
|
|
81
|
-
);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export default useResizeObserver;
|
package/src/hooks/useRouter.tsx
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Fragment, Suspense } from 'react'
|
|
2
|
-
import { createBrowserRouter, Outlet, RouterProvider, useLocation } from 'react-router-dom'
|
|
3
|
-
import type { ActionFunction, RouteObject, LoaderFunction } from 'react-router-dom'
|
|
4
|
-
|
|
5
|
-
import { generateModalRoutes, generatePreservedRoutes, generateRegularRoutes } from '../core'
|
|
6
|
-
|
|
7
|
-
type Element = () => JSX.Element
|
|
8
|
-
type Module = { default: Element; Loader?: LoaderFunction; Action?: ActionFunction; Catch?: Element; Pending?: Element }
|
|
9
|
-
|
|
10
|
-
const PRESERVED = import.meta.glob<Module>('/src/pages/(_app|404).{jsx,tsx}', { eager: true })
|
|
11
|
-
const MODALS = import.meta.glob<Pick<Module, 'default'>>('/src/pages/**/[+]*.{jsx,tsx}', { eager: true })
|
|
12
|
-
const ROUTES = import.meta.glob<Module>(['/src/pages/**/[\\w[-]*.{jsx,tsx}', '!**/(_app|404).*'], { eager: true })
|
|
13
|
-
|
|
14
|
-
const preservedRoutes = generatePreservedRoutes<Omit<Module, 'Action'>>(PRESERVED)
|
|
15
|
-
const modalRoutes = generateModalRoutes<Element>(MODALS)
|
|
16
|
-
|
|
17
|
-
const regularRoutes = generateRegularRoutes<RouteObject, Partial<Module>>(ROUTES, (module, key) => {
|
|
18
|
-
const index = /index\.(jsx|tsx)$/.test(key) && !key.includes('pages/index') ? { index: true } : {}
|
|
19
|
-
const Element = module?.default || Fragment
|
|
20
|
-
const Page = () => (module?.Pending ? <Suspense fallback={<module.Pending />} children={<Element />} /> : <Element />)
|
|
21
|
-
return { ...index, Component: Page, ErrorBoundary: module?.Catch, loader: module?.Loader, action: module?.Action }
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const _app = preservedRoutes?.['_app']
|
|
25
|
-
const _404 = preservedRoutes?.['404']
|
|
26
|
-
|
|
27
|
-
const Element = _app?.default || Fragment
|
|
28
|
-
const App = () => (_app?.Pending ? <Suspense fallback={<_app.Pending />} children={<Element />} /> : <Element />)
|
|
29
|
-
|
|
30
|
-
const app = { Component: _app?.default ? App : Outlet, ErrorBoundary: _app?.Catch, loader: _app?.Loader }
|
|
31
|
-
const fallback = { path: '*', Component: _404?.default || Fragment }
|
|
32
|
-
|
|
33
|
-
export const routes: RouteObject[] = [{ ...app, children: [...regularRoutes, fallback] }]
|
|
34
|
-
export const Routes = () => <RouterProvider router={createBrowserRouter(routes)} />
|
|
35
|
-
|
|
36
|
-
export const Modals = () => {
|
|
37
|
-
const Modal = modalRoutes[useLocation().state?.modal] || Fragment
|
|
38
|
-
return <Modal />
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const useRouter = (root : string) => {
|
|
42
|
-
return Routes;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export default useRouter;
|
package/src/hooks/useTheme.tsx
DELETED
package/src/hooks/useToast.tsx
DELETED
package/src/index.tsx
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import './scss/style.scss'
|
|
2
|
-
import { Provider, createSlice } from './context'
|
|
3
|
-
|
|
4
|
-
export * from './core/index';
|
|
5
|
-
export * from './hooks/index';
|
|
6
|
-
|
|
7
|
-
export { Link } from "react-router-dom"
|
|
8
|
-
|
|
9
|
-
export { default as App } from './comps/app'
|
|
10
|
-
export { default as Box } from './comps/box'
|
|
11
|
-
export { default as Button } from './comps/button'
|
|
12
|
-
export { default as Block } from './comps/component'
|
|
13
|
-
export { default as Checkbox } from './comps/checkbox'
|
|
14
|
-
export { default as Cover } from './comps/cover'
|
|
15
|
-
export { default as Form } from './comps/form'
|
|
16
|
-
export { default as Heading } from './comps/heading'
|
|
17
|
-
export { default as Icon } from './comps/icon'
|
|
18
|
-
export { default as Input } from './comps/input'
|
|
19
|
-
export { default as Image } from './comps/image'
|
|
20
|
-
export { default as Masonry } from './comps/masonry'
|
|
21
|
-
export { default as Placeholder } from './comps/placeholder'
|
|
22
|
-
export { default as Toaster } from './comps/toaster'
|
|
23
|
-
export { default as Select } from './comps/select'
|
|
24
|
-
export { default as Spacer } from './comps/spacer'
|
|
25
|
-
export { default as Spinner } from './comps/spinner'
|
|
26
|
-
export { default as Text } from './comps/text'
|
|
27
|
-
export { default as Tweet } from './comps/tweet'
|
|
28
|
-
// export { default as ContextMenu } from './comps/contextmenu'
|
|
29
|
-
|
|
30
|
-
export { default as Header } from './kit/Header'
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
Provider,
|
|
34
|
-
createSlice
|
|
35
|
-
}
|
package/src/kit/Builder.tsx
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import Box from '../comps/box'
|
|
2
|
-
import { nanoid } from 'nanoid'
|
|
3
|
-
|
|
4
|
-
const buildElement = (el) => {
|
|
5
|
-
switch(el.is){
|
|
6
|
-
case "Box":
|
|
7
|
-
return <Box key={el.key || nanoid()} {...(el.props || {})}>{el.children || null}</Box>
|
|
8
|
-
break;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const buildComponent = (data) => {
|
|
13
|
-
return data.map(e => buildElement(e))
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export {
|
|
17
|
-
buildComponent
|
|
18
|
-
}
|
package/src/kit/Component.tsx
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
forwardRef,
|
|
3
|
-
useCallback,
|
|
4
|
-
useEffect
|
|
5
|
-
} from 'react';
|
|
6
|
-
import { Box } from '../index'
|
|
7
|
-
|
|
8
|
-
const Component = forwardRef((props : { [ key: string ] : any }, ref) => {
|
|
9
|
-
|
|
10
|
-
const data = props.data || [
|
|
11
|
-
{ is: 'Box' }
|
|
12
|
-
]
|
|
13
|
-
|
|
14
|
-
const Element = useCallback((el) => {
|
|
15
|
-
switch(el.is){
|
|
16
|
-
case "Box":
|
|
17
|
-
return <Box {...(el.props || {})}>{el.children || null}</Box>
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
}, [])
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<>
|
|
24
|
-
{data.map(el => Element(el))}
|
|
25
|
-
</>
|
|
26
|
-
// <Box w={`100vw`} h={60} bg={`#eee`}>
|
|
27
|
-
// {}
|
|
28
|
-
// </Box>
|
|
29
|
-
)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
export default Component;
|
package/src/kit/Header.tsx
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
forwardRef,
|
|
3
|
-
useEffect
|
|
4
|
-
} from 'react';
|
|
5
|
-
import { Box } from '../index'
|
|
6
|
-
import { buildComponent } from './Builder'
|
|
7
|
-
|
|
8
|
-
const Header = forwardRef((props : { [ key: string ] : any }, ref) => {
|
|
9
|
-
|
|
10
|
-
const data = [
|
|
11
|
-
{ is: `Box` }
|
|
12
|
-
]
|
|
13
|
-
|
|
14
|
-
return (
|
|
15
|
-
<>
|
|
16
|
-
{buildComponent(data)}
|
|
17
|
-
</>
|
|
18
|
-
)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
export default Header;
|
package/src/redux/slices/app.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createSlice } from '@reduxjs/toolkit'
|
|
2
|
-
|
|
3
|
-
export const appSlice = createSlice({
|
|
4
|
-
name: `app`,
|
|
5
|
-
initialState: {
|
|
6
|
-
debug: true,
|
|
7
|
-
loading: true,
|
|
8
|
-
theme: null,
|
|
9
|
-
_tmp: Math.random()
|
|
10
|
-
},
|
|
11
|
-
reducers: {
|
|
12
|
-
setLoading: (state, action) => {
|
|
13
|
-
state.loading = action.payload || false;
|
|
14
|
-
},
|
|
15
|
-
setTheme: (state, action) => { state.theme = action.payload },
|
|
16
|
-
forceUpdate: (state, action) => { state._tmp = Math.random() }
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export const {
|
|
21
|
-
setLoading,
|
|
22
|
-
setTheme,
|
|
23
|
-
forceUpdate
|
|
24
|
-
} = appSlice.actions;
|
|
25
|
-
|
|
26
|
-
export default appSlice.reducer;
|
package/src/redux/slices/form.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { createSlice } from '@reduxjs/toolkit'
|
|
2
|
-
|
|
3
|
-
export const formSlice = createSlice({
|
|
4
|
-
name: `form`,
|
|
5
|
-
initialState: {
|
|
6
|
-
forms: {}
|
|
7
|
-
},
|
|
8
|
-
reducers: {
|
|
9
|
-
addForm: (state, action) => {
|
|
10
|
-
state.forms[action.payload] = { touched: false, loading: false }
|
|
11
|
-
},
|
|
12
|
-
updateForm: (state, action) => {
|
|
13
|
-
// console.log(action.payload)
|
|
14
|
-
const { name, k, v } = action.payload;
|
|
15
|
-
if(state.forms[name]) state.forms[name][k] = v;
|
|
16
|
-
},
|
|
17
|
-
addFields: (state, action) => {
|
|
18
|
-
const { form, fields } = action.payload;
|
|
19
|
-
if(state.forms[form]) state.forms[form] = { ...state.forms[form], ...fields };
|
|
20
|
-
},
|
|
21
|
-
addField: (state, action) => {
|
|
22
|
-
// console.log('addField', action.payload)
|
|
23
|
-
// state.forms[action.payload.form][action.payload.name] = action.payload.value
|
|
24
|
-
// if(
|
|
25
|
-
// state.forms[action.payload.form] &&
|
|
26
|
-
// !state.forms[action.payload.form][action.payload.name]
|
|
27
|
-
// ){
|
|
28
|
-
// state.forms[action.payload.form][action.payload.name] = action.payload.value
|
|
29
|
-
// }
|
|
30
|
-
},
|
|
31
|
-
updateField: (state, action) => {
|
|
32
|
-
const { form, name, value } = action.payload;
|
|
33
|
-
// console.log(`updatingField: ${form} = ${name} => ${value}`, state.forms[form])
|
|
34
|
-
state.forms[form][name] = value;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
export const {
|
|
40
|
-
addForm,
|
|
41
|
-
updateForm,
|
|
42
|
-
addField,
|
|
43
|
-
addFields,
|
|
44
|
-
updateField
|
|
45
|
-
} = formSlice.actions;
|
|
46
|
-
export default formSlice.reducer;
|