@pyreon/rocketstyle 0.11.4 → 0.11.6
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 +32 -32
- package/lib/index.d.ts +25 -6
- package/lib/index.js +85 -72
- package/package.json +25 -24
- package/src/__tests__/attrs.test.ts +49 -49
- package/src/__tests__/chaining.test.ts +27 -27
- package/src/__tests__/collection.test.ts +12 -12
- package/src/__tests__/compose.test.ts +10 -10
- package/src/__tests__/context.test.ts +65 -65
- package/src/__tests__/createLocalProvider.test.ts +53 -53
- package/src/__tests__/dimensions.test.ts +54 -54
- package/src/__tests__/e2e-styler.test.ts +78 -136
- package/src/__tests__/hooks.test.ts +41 -70
- package/src/__tests__/isRocketComponent.test.ts +11 -11
- package/src/__tests__/misc.test.ts +91 -91
- package/src/__tests__/providerConsumer.test.ts +54 -126
- package/src/__tests__/rocketstyleIntegration.test.ts +180 -253
- package/src/__tests__/themeUtils.test.ts +173 -173
- package/src/cache/index.ts +1 -1
- package/src/constants/booleanTags.ts +25 -25
- package/src/constants/defaultDimensions.ts +5 -5
- package/src/constants/index.ts +16 -16
- package/src/context/context.ts +13 -10
- package/src/context/createLocalProvider.ts +22 -12
- package/src/context/localContext.ts +2 -2
- package/src/hoc/index.ts +1 -1
- package/src/hoc/rocketstyleAttrsHoc.ts +12 -9
- package/src/hooks/index.ts +2 -2
- package/src/hooks/usePseudoState.ts +3 -3
- package/src/hooks/useTheme.ts +14 -17
- package/src/index.ts +32 -15
- package/src/init.ts +12 -12
- package/src/isRocketComponent.ts +2 -2
- package/src/rocketstyle.ts +103 -109
- package/src/types/attrs.ts +2 -2
- package/src/types/config.ts +4 -4
- package/src/types/configuration.ts +5 -5
- package/src/types/dimensions.ts +5 -5
- package/src/types/hoc.ts +1 -1
- package/src/types/rocketComponent.ts +4 -4
- package/src/types/rocketstyle.ts +10 -10
- package/src/types/styles.ts +9 -4
- package/src/types/theme.ts +4 -4
- package/src/types/utils.ts +1 -1
- package/src/utils/attrs.ts +2 -2
- package/src/utils/chaining.ts +2 -2
- package/src/utils/compose.ts +1 -1
- package/src/utils/dimensions.ts +6 -6
- package/src/utils/statics.ts +2 -2
- package/src/utils/styles.ts +2 -2
- package/src/utils/theme.ts +10 -10
|
@@ -4,29 +4,29 @@
|
|
|
4
4
|
* out as unknown styling props.
|
|
5
5
|
*/
|
|
6
6
|
export default [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
7
|
+
'allowFullScreen',
|
|
8
|
+
'allowPaymentRequest',
|
|
9
|
+
'async',
|
|
10
|
+
'autoFocus',
|
|
11
|
+
'autoPlay',
|
|
12
|
+
'checked',
|
|
13
|
+
'controls',
|
|
14
|
+
'default',
|
|
15
|
+
'defer',
|
|
16
|
+
'disabled',
|
|
17
|
+
'formNoValidate',
|
|
18
|
+
'hidden',
|
|
19
|
+
'isMap',
|
|
20
|
+
'itemScope',
|
|
21
|
+
'loop',
|
|
22
|
+
'multiple',
|
|
23
|
+
'muted',
|
|
24
|
+
'noModule',
|
|
25
|
+
'noValidate',
|
|
26
|
+
'open',
|
|
27
|
+
'readOnly',
|
|
28
|
+
'required',
|
|
29
|
+
'reversed',
|
|
30
|
+
'selected',
|
|
31
|
+
'typeMustMatch',
|
|
32
32
|
]
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
* and `multiple` (a multi-select dimension).
|
|
5
5
|
*/
|
|
6
6
|
const DEFAULT_DIMENSIONS = {
|
|
7
|
-
states:
|
|
8
|
-
sizes:
|
|
9
|
-
variants:
|
|
7
|
+
states: 'state',
|
|
8
|
+
sizes: 'size',
|
|
9
|
+
variants: 'variant',
|
|
10
10
|
multiple: {
|
|
11
|
-
propName:
|
|
11
|
+
propName: 'multiple',
|
|
12
12
|
multi: true,
|
|
13
13
|
},
|
|
14
14
|
modifiers: {
|
|
15
|
-
propName:
|
|
15
|
+
propName: 'modifier',
|
|
16
16
|
multi: true,
|
|
17
17
|
transform: true,
|
|
18
18
|
},
|
package/src/constants/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/** Default theme mode used when no mode is provided via context. */
|
|
2
|
-
export const MODE_DEFAULT =
|
|
2
|
+
export const MODE_DEFAULT = 'light'
|
|
3
3
|
|
|
4
4
|
/** Pseudo-state interaction keys tracked for styling (hover, active, focus, pressed). */
|
|
5
|
-
export const PSEUDO_KEYS = [
|
|
5
|
+
export const PSEUDO_KEYS = ['hover', 'active', 'focus', 'pressed'] as const
|
|
6
6
|
|
|
7
7
|
/** Meta pseudo-state keys representing non-interactive states (disabled, readOnly). */
|
|
8
|
-
export const PSEUDO_META_KEYS = [
|
|
8
|
+
export const PSEUDO_META_KEYS = ['disabled', 'readOnly'] as const
|
|
9
9
|
|
|
10
10
|
/** Supported theme mode flags. */
|
|
11
11
|
export const THEME_MODES = {
|
|
@@ -15,30 +15,30 @@ export const THEME_MODES = {
|
|
|
15
15
|
|
|
16
16
|
/** Maps each theme mode to its inverse (light -> dark, dark -> light). */
|
|
17
17
|
export const THEME_MODES_INVERSED = {
|
|
18
|
-
dark:
|
|
19
|
-
light:
|
|
18
|
+
dark: 'light',
|
|
19
|
+
light: 'dark',
|
|
20
20
|
} as const
|
|
21
21
|
|
|
22
22
|
/** Reserved configuration keys accepted by the `.config()` chaining method. */
|
|
23
23
|
export const CONFIG_KEYS = [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
'provider',
|
|
25
|
+
'consumer',
|
|
26
|
+
'DEBUG',
|
|
27
|
+
'name',
|
|
28
|
+
'component',
|
|
29
|
+
'inversed',
|
|
30
|
+
'passProps',
|
|
31
|
+
'styled',
|
|
32
32
|
] as const
|
|
33
33
|
|
|
34
34
|
/** Keys for theme and styles chaining methods. */
|
|
35
|
-
export const STYLING_KEYS = [
|
|
36
|
-
export const STATIC_KEYS = [...STYLING_KEYS,
|
|
35
|
+
export const STYLING_KEYS = ['theme', 'styles'] as const
|
|
36
|
+
export const STATIC_KEYS = [...STYLING_KEYS, 'compose'] as const
|
|
37
37
|
|
|
38
38
|
/** Union of all reserved keys that cannot be used as dimension names. */
|
|
39
39
|
export const ALL_RESERVED_KEYS = [
|
|
40
40
|
...Object.keys(THEME_MODES),
|
|
41
41
|
...CONFIG_KEYS,
|
|
42
42
|
...STATIC_KEYS,
|
|
43
|
-
|
|
43
|
+
'attrs',
|
|
44
44
|
] as const
|
package/src/context/context.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { VNodeChild } from
|
|
2
|
-
import { useContext } from
|
|
3
|
-
import { Provider as CoreProvider, context } from
|
|
4
|
-
import { MODE_DEFAULT, THEME_MODES_INVERSED } from
|
|
1
|
+
import type { VNodeChild } from '@pyreon/core'
|
|
2
|
+
import { useContext } from '@pyreon/core'
|
|
3
|
+
import { Provider as CoreProvider, context } from '@pyreon/ui-core'
|
|
4
|
+
import { MODE_DEFAULT, THEME_MODES_INVERSED } from '../constants'
|
|
5
5
|
|
|
6
6
|
type Theme = {
|
|
7
7
|
rootSize: number
|
|
@@ -11,7 +11,7 @@ type Theme = {
|
|
|
11
11
|
export type TProvider = {
|
|
12
12
|
children: VNodeChild
|
|
13
13
|
theme?: Theme | undefined
|
|
14
|
-
mode?:
|
|
14
|
+
mode?: 'light' | 'dark' | undefined
|
|
15
15
|
inversed?: boolean | undefined
|
|
16
16
|
provider?: ((props: Record<string, unknown>) => VNodeChild) | undefined
|
|
17
17
|
}
|
|
@@ -24,9 +24,11 @@ export type TProvider = {
|
|
|
24
24
|
* In Pyreon, context is provided via provide() instead of React.Provider.
|
|
25
25
|
*/
|
|
26
26
|
const Provider = ({ provider = CoreProvider, inversed, ...props }: TProvider): VNodeChild => {
|
|
27
|
-
const
|
|
27
|
+
const getCtx = useContext(context)
|
|
28
|
+
const ctx = getCtx()
|
|
28
29
|
|
|
29
|
-
const {
|
|
30
|
+
const merged = { ...ctx, ...props, provider } as unknown as TProvider & Record<string, unknown>
|
|
31
|
+
const { theme, mode, provider: RocketstyleProvider, children } = merged
|
|
30
32
|
|
|
31
33
|
let newMode = MODE_DEFAULT
|
|
32
34
|
|
|
@@ -34,10 +36,11 @@ const Provider = ({ provider = CoreProvider, inversed, ...props }: TProvider): V
|
|
|
34
36
|
newMode = inversed ? THEME_MODES_INVERSED[mode] : mode
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
const
|
|
39
|
+
const FinalProvider = RocketstyleProvider ?? CoreProvider
|
|
40
|
+
const result = FinalProvider({
|
|
38
41
|
mode: newMode,
|
|
39
|
-
isDark: newMode ===
|
|
40
|
-
isLight: newMode ===
|
|
42
|
+
isDark: newMode === 'dark',
|
|
43
|
+
isLight: newMode === 'light',
|
|
41
44
|
...(theme !== undefined ? { theme } : {}),
|
|
42
45
|
provider,
|
|
43
46
|
children,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { provide } from
|
|
2
|
-
import { signal } from
|
|
3
|
-
import type { PseudoProps } from
|
|
4
|
-
import type { ComponentFn } from
|
|
5
|
-
import { localContext } from
|
|
1
|
+
import { provide } from '@pyreon/core'
|
|
2
|
+
import { signal } from '@pyreon/reactivity'
|
|
3
|
+
import type { PseudoProps } from '../types/pseudo'
|
|
4
|
+
import type { ComponentFn } from '../types/utils'
|
|
5
|
+
import { localContext } from './localContext'
|
|
6
6
|
|
|
7
7
|
type Props = PseudoProps & Record<string, any>
|
|
8
8
|
|
|
@@ -29,12 +29,6 @@ const createLocalProvider = (WrappedComponent: ComponentFn<any>) => {
|
|
|
29
29
|
const focus = signal(false)
|
|
30
30
|
const pressed = signal(false)
|
|
31
31
|
|
|
32
|
-
const pseudoState = () => ({
|
|
33
|
-
hover: hover(),
|
|
34
|
-
focus: focus(),
|
|
35
|
-
pressed: pressed(),
|
|
36
|
-
})
|
|
37
|
-
|
|
38
32
|
const events = {
|
|
39
33
|
onMouseEnter: (e: MouseEvent) => {
|
|
40
34
|
hover.set(true)
|
|
@@ -63,9 +57,25 @@ const createLocalProvider = (WrappedComponent: ComponentFn<any>) => {
|
|
|
63
57
|
},
|
|
64
58
|
}
|
|
65
59
|
|
|
60
|
+
// Use getters so pseudo-state signals are read lazily by consumers
|
|
61
|
+
// inside their own reactive scopes — NOT eagerly during parent setup.
|
|
62
|
+
// Without getters, hover()/focus()/pressed() reads here would register
|
|
63
|
+
// as dependencies of any parent effect, causing cascading re-renders
|
|
64
|
+
// on every mouse event.
|
|
66
65
|
const updatedState = {
|
|
67
66
|
...$rocketstate,
|
|
68
|
-
pseudo: {
|
|
67
|
+
pseudo: {
|
|
68
|
+
...$rocketstate?.pseudo,
|
|
69
|
+
get hover() {
|
|
70
|
+
return hover()
|
|
71
|
+
},
|
|
72
|
+
get focus() {
|
|
73
|
+
return focus()
|
|
74
|
+
},
|
|
75
|
+
get pressed() {
|
|
76
|
+
return pressed()
|
|
77
|
+
},
|
|
78
|
+
},
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
// Provide local context for child rocketstyle components
|
package/src/hoc/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { render } from
|
|
2
|
-
import { useTheme } from
|
|
3
|
-
import type { Configuration } from
|
|
4
|
-
import type { ComponentFn } from
|
|
5
|
-
import { calculateChainOptions, removeUndefinedProps } from
|
|
1
|
+
import { render } from '@pyreon/ui-core'
|
|
2
|
+
import { useTheme } from '../hooks'
|
|
3
|
+
import type { Configuration } from '../types/configuration'
|
|
4
|
+
import type { ComponentFn } from '../types/utils'
|
|
5
|
+
import { calculateChainOptions, removeUndefinedProps } from '../utils/attrs'
|
|
6
6
|
|
|
7
7
|
export type RocketStyleHOC = ({
|
|
8
8
|
inversed,
|
|
9
9
|
attrs,
|
|
10
10
|
priorityAttrs,
|
|
11
|
-
}: Pick<Configuration,
|
|
11
|
+
}: Pick<Configuration, 'inversed' | 'attrs' | 'priorityAttrs'>) => (
|
|
12
12
|
WrappedComponent: ComponentFn<any>,
|
|
13
13
|
) => ComponentFn<any>
|
|
14
14
|
|
|
@@ -32,14 +32,17 @@ const rocketStyleHOC: RocketStyleHOC = ({ inversed, attrs, priorityAttrs }) => {
|
|
|
32
32
|
// Keep the object reference so properties re-evaluate lazily.
|
|
33
33
|
const themeAttrs = useTheme({ inversed })
|
|
34
34
|
|
|
35
|
+
// Remove undefined props not to override potential default props
|
|
36
|
+
const filteredProps = removeUndefinedProps(props)
|
|
37
|
+
|
|
38
|
+
// Read theme attrs eagerly — .attrs() callbacks run once at mount.
|
|
39
|
+
// Mode-dependent styling is handled reactively by the $rocketstyle
|
|
40
|
+
// accessor in EnhancedComponent, not by re-running attrs.
|
|
35
41
|
const callbackParams = [
|
|
36
42
|
themeAttrs.theme,
|
|
37
43
|
{ render, mode: themeAttrs.mode, isDark: themeAttrs.isDark, isLight: themeAttrs.isLight },
|
|
38
44
|
]
|
|
39
45
|
|
|
40
|
-
// Remove undefined props not to override potential default props
|
|
41
|
-
const filteredProps = removeUndefinedProps(props)
|
|
42
|
-
|
|
43
46
|
const prioritizedAttrs = calculatePriorityAttrs([filteredProps, ...callbackParams])
|
|
44
47
|
|
|
45
48
|
const finalAttrs = calculateAttrs([
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { signal } from
|
|
2
|
-
import type { PseudoActions, PseudoState } from
|
|
1
|
+
import { signal } from '@pyreon/reactivity'
|
|
2
|
+
import type { PseudoActions, PseudoState } from '../types/pseudo'
|
|
3
3
|
|
|
4
4
|
type UsePseudoState = ({
|
|
5
5
|
onMouseEnter,
|
|
@@ -9,7 +9,7 @@ type UsePseudoState = ({
|
|
|
9
9
|
onFocus,
|
|
10
10
|
onBlur,
|
|
11
11
|
}: Partial<PseudoActions>) => {
|
|
12
|
-
state: Pick<PseudoState,
|
|
12
|
+
state: Pick<PseudoState, 'hover' | 'focus' | 'pressed'>
|
|
13
13
|
events: PseudoActions
|
|
14
14
|
}
|
|
15
15
|
|
package/src/hooks/useTheme.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useContext } from
|
|
2
|
-
import { THEME_MODES_INVERSED } from
|
|
3
|
-
import { context } from
|
|
4
|
-
import type { ThemeModeKeys } from
|
|
1
|
+
import { useContext } from '@pyreon/core'
|
|
2
|
+
import { THEME_MODES_INVERSED } from '../constants'
|
|
3
|
+
import { context } from '../context/context'
|
|
4
|
+
import type { ThemeModeKeys } from '../types/theme'
|
|
5
5
|
|
|
6
6
|
type Context = {
|
|
7
7
|
theme: Record<string, unknown>
|
|
@@ -16,32 +16,29 @@ type UseThemeAttrs = ({ inversed }: { inversed?: boolean | undefined }) => Conte
|
|
|
16
16
|
* Retrieves the current theme object and resolved mode from context.
|
|
17
17
|
*
|
|
18
18
|
* Returns an object with getter properties so that mode/isDark/isLight
|
|
19
|
-
* are evaluated lazily on each access.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* Without getters, destructuring would capture the mode value once at
|
|
24
|
-
* setup time, making theme switching permanently broken.
|
|
19
|
+
* are evaluated lazily on each access. The context is a ReactiveContext,
|
|
20
|
+
* so useContext returns `() => CoreContextValue` — we call it inside
|
|
21
|
+
* each getter to ensure reactive tracking.
|
|
25
22
|
*/
|
|
26
23
|
const useThemeAttrs: UseThemeAttrs = ({ inversed }) => {
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
const
|
|
24
|
+
// ReactiveContext: useContext returns () => CoreContextValue.
|
|
25
|
+
// Call the getter inside each property getter for reactive tracking.
|
|
26
|
+
const getCtx = useContext(context)
|
|
30
27
|
|
|
31
28
|
return {
|
|
32
29
|
get theme() {
|
|
33
|
-
return
|
|
30
|
+
return getCtx().theme ?? ({} as Record<string, unknown>)
|
|
34
31
|
},
|
|
35
32
|
get mode() {
|
|
36
|
-
const ctxMode =
|
|
33
|
+
const ctxMode = getCtx().mode ?? 'light'
|
|
37
34
|
return inversed ? THEME_MODES_INVERSED[ctxMode] : ctxMode
|
|
38
35
|
},
|
|
39
36
|
get isDark() {
|
|
40
|
-
const ctxDark =
|
|
37
|
+
const ctxDark = getCtx().isDark ?? false
|
|
41
38
|
return inversed ? !ctxDark : ctxDark
|
|
42
39
|
},
|
|
43
40
|
get isLight() {
|
|
44
|
-
const ctxDark =
|
|
41
|
+
const ctxDark = getCtx().isDark ?? false
|
|
45
42
|
const isDark = inversed ? !ctxDark : ctxDark
|
|
46
43
|
return !isDark
|
|
47
44
|
},
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { TProvider } from
|
|
2
|
-
import Provider, { context } from
|
|
3
|
-
import type { Rocketstyle } from
|
|
4
|
-
import rocketstyle from
|
|
5
|
-
import type { IsRocketComponent } from
|
|
6
|
-
import isRocketComponent from
|
|
7
|
-
import type { AttrsCb } from
|
|
1
|
+
import type { TProvider } from './context/context'
|
|
2
|
+
import Provider, { context } from './context/context'
|
|
3
|
+
import type { Rocketstyle } from './init'
|
|
4
|
+
import rocketstyle from './init'
|
|
5
|
+
import type { IsRocketComponent } from './isRocketComponent'
|
|
6
|
+
import isRocketComponent from './isRocketComponent'
|
|
7
|
+
import type { AttrsCb } from './types/attrs'
|
|
8
8
|
import type {
|
|
9
9
|
ConfigAttrs,
|
|
10
10
|
ConsumerCb,
|
|
@@ -12,8 +12,8 @@ import type {
|
|
|
12
12
|
ConsumerCtxCb,
|
|
13
13
|
RocketComponentType,
|
|
14
14
|
RocketProviderState,
|
|
15
|
-
} from
|
|
16
|
-
import type { DefaultProps } from
|
|
15
|
+
} from './types/config'
|
|
16
|
+
import type { DefaultProps } from './types/configuration'
|
|
17
17
|
import type {
|
|
18
18
|
DimensionCallbackParam,
|
|
19
19
|
DimensionProps,
|
|
@@ -22,18 +22,18 @@ import type {
|
|
|
22
22
|
ExtractDimensionProps,
|
|
23
23
|
ExtractDimensions,
|
|
24
24
|
TDKP,
|
|
25
|
-
} from
|
|
26
|
-
import type { ComposeParam, GenericHoc } from
|
|
27
|
-
import type { IRocketStyleComponent, RocketStyleComponent } from
|
|
28
|
-
import type { RocketStyleInterpolationProps, StylesCb, StylesDefault } from
|
|
25
|
+
} from './types/dimensions'
|
|
26
|
+
import type { ComposeParam, GenericHoc } from './types/hoc'
|
|
27
|
+
import type { IRocketStyleComponent, RocketStyleComponent } from './types/rocketstyle'
|
|
28
|
+
import type { RocketStyleInterpolationProps, StylesCb, StylesDefault } from './types/styles'
|
|
29
29
|
import type {
|
|
30
30
|
ThemeCb,
|
|
31
31
|
ThemeDefault,
|
|
32
32
|
ThemeMode,
|
|
33
33
|
ThemeModeCallback,
|
|
34
34
|
ThemeModeKeys,
|
|
35
|
-
} from
|
|
36
|
-
import type { ComponentFn, ElementType, ExtractProps, MergeTypes, TObj } from
|
|
35
|
+
} from './types/theme'
|
|
36
|
+
import type { ComponentFn, ElementType, ExtractProps, MergeTypes, TObj } from './types/utils'
|
|
37
37
|
|
|
38
38
|
export type {
|
|
39
39
|
AttrsCb,
|
|
@@ -73,5 +73,22 @@ export type {
|
|
|
73
73
|
TProvider,
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Resolve a $rocketstyle value — handles both function accessor and plain object.
|
|
78
|
+
* Use in styled() interpolation functions when $rocketstyle may be a reactive accessor.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* styled(Component)`
|
|
83
|
+
* color: ${(props) => resolveTheme(props.$rocketstyle).color};
|
|
84
|
+
* `
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export function resolveTheme<T = Record<string, unknown>>(
|
|
88
|
+
value: (() => T) | T,
|
|
89
|
+
): T {
|
|
90
|
+
return typeof value === 'function' ? (value as () => T)() : value
|
|
91
|
+
}
|
|
92
|
+
|
|
76
93
|
export { context, isRocketComponent, Provider, rocketstyle }
|
|
77
94
|
export default rocketstyle
|
package/src/init.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { isEmpty } from
|
|
2
|
-
import { ALL_RESERVED_KEYS } from
|
|
3
|
-
import defaultDimensions from
|
|
4
|
-
import rocketComponent from
|
|
5
|
-
import type { DefaultDimensions, Dimensions } from
|
|
6
|
-
import type { RocketComponent } from
|
|
7
|
-
import type { ElementType } from
|
|
1
|
+
import { isEmpty } from '@pyreon/ui-core'
|
|
2
|
+
import { ALL_RESERVED_KEYS } from './constants'
|
|
3
|
+
import defaultDimensions from './constants/defaultDimensions'
|
|
4
|
+
import rocketComponent from './rocketstyle'
|
|
5
|
+
import type { DefaultDimensions, Dimensions } from './types/dimensions'
|
|
6
|
+
import type { RocketComponent } from './types/rocketComponent'
|
|
7
|
+
import type { ElementType } from './types/utils'
|
|
8
8
|
import {
|
|
9
9
|
getDimensionsValues,
|
|
10
10
|
getKeys,
|
|
11
11
|
getMultipleDimensions,
|
|
12
12
|
getTransformDimensions,
|
|
13
|
-
} from
|
|
13
|
+
} from './utils/dimensions'
|
|
14
14
|
|
|
15
15
|
export type Rocketstyle = <
|
|
16
16
|
const D extends Dimensions = DefaultDimensions,
|
|
@@ -45,15 +45,15 @@ const validateInit = (name: string, component: unknown, dimensions: Dimensions)
|
|
|
45
45
|
const errors: InitErrors = {}
|
|
46
46
|
|
|
47
47
|
if (!component) {
|
|
48
|
-
errors.component =
|
|
48
|
+
errors.component = 'Parameter `component` is missing in params!'
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (!name) {
|
|
52
|
-
errors.name =
|
|
52
|
+
errors.name = 'Parameter `name` is missing in params!'
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
if (isEmpty(dimensions)) {
|
|
56
|
-
errors.dimensions =
|
|
56
|
+
errors.dimensions = 'Parameter `dimensions` is missing in params!'
|
|
57
57
|
} else {
|
|
58
58
|
const definedDimensions = getKeys(dimensions)
|
|
59
59
|
const invalidDimension = ALL_RESERVED_KEYS.some((item) =>
|
|
@@ -73,7 +73,7 @@ const validateInit = (name: string, component: unknown, dimensions: Dimensions)
|
|
|
73
73
|
|
|
74
74
|
const rocketstyle = (({ dimensions = defaultDimensions, useBooleans = true } = {}) =>
|
|
75
75
|
({ name, component }: { name: string; component: any }) => {
|
|
76
|
-
if (process.env.NODE_ENV !==
|
|
76
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
77
77
|
validateInit(name, component, dimensions)
|
|
78
78
|
}
|
|
79
79
|
|
package/src/isRocketComponent.ts
CHANGED
|
@@ -4,8 +4,8 @@ export type IsRocketComponent = <T>(component: T) => boolean
|
|
|
4
4
|
const isRocketComponent: IsRocketComponent = (component) => {
|
|
5
5
|
if (
|
|
6
6
|
component &&
|
|
7
|
-
(typeof component ===
|
|
8
|
-
Object.hasOwn(component as object,
|
|
7
|
+
(typeof component === 'object' || typeof component === 'function') &&
|
|
8
|
+
Object.hasOwn(component as object, 'IS_ROCKETSTYLE')
|
|
9
9
|
) {
|
|
10
10
|
return true
|
|
11
11
|
}
|