@pyreon/coolgrid 0.24.0 → 0.24.1
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/lib/index.js +3 -4
- package/package.json +8 -8
- package/src/useContext.tsx +10 -13
package/lib/index.js
CHANGED
|
@@ -43,14 +43,13 @@ var RowContext_default = createContext({});
|
|
|
43
43
|
|
|
44
44
|
//#endregion
|
|
45
45
|
//#region src/useContext.tsx
|
|
46
|
-
const pickThemeProps = (props, keywords) => pick(props, keywords);
|
|
47
46
|
const getGridContext = (props = {}, theme = {}) => ({
|
|
48
|
-
columns:
|
|
49
|
-
containerWidth:
|
|
47
|
+
columns: props.columns || get(theme, "grid.columns") || get(theme, "coolgrid.columns"),
|
|
48
|
+
containerWidth: props.width || get(theme, "grid.container") || get(theme, "coolgrid.container")
|
|
50
49
|
});
|
|
51
50
|
const useGridContext = (props) => {
|
|
52
51
|
const { theme } = useContext(context)();
|
|
53
|
-
const ctxProps =
|
|
52
|
+
const ctxProps = pick(props, CONTEXT_KEYS);
|
|
54
53
|
return {
|
|
55
54
|
...getGridContext(ctxProps, theme),
|
|
56
55
|
...ctxProps
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pyreon/coolgrid",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.1",
|
|
4
4
|
"description": "Responsive grid system for Pyreon",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@pyreon/test-utils": "^0.13.11",
|
|
46
|
-
"@pyreon/typescript": "^0.24.
|
|
47
|
-
"@pyreon/ui-core": "^0.24.
|
|
46
|
+
"@pyreon/typescript": "^0.24.1",
|
|
47
|
+
"@pyreon/ui-core": "^0.24.1",
|
|
48
48
|
"@vitest/browser-playwright": "^4.1.4",
|
|
49
49
|
"@vitus-labs/tools-rolldown": "^2.4.0"
|
|
50
50
|
},
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"node": ">= 22"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@pyreon/core": "^0.24.
|
|
56
|
-
"@pyreon/reactivity": "^0.24.
|
|
57
|
-
"@pyreon/styler": "^0.24.
|
|
58
|
-
"@pyreon/ui-core": "^0.24.
|
|
59
|
-
"@pyreon/unistyle": "^0.24.
|
|
55
|
+
"@pyreon/core": "^0.24.1",
|
|
56
|
+
"@pyreon/reactivity": "^0.24.1",
|
|
57
|
+
"@pyreon/styler": "^0.24.1",
|
|
58
|
+
"@pyreon/ui-core": "^0.24.1",
|
|
59
|
+
"@pyreon/unistyle": "^0.24.1"
|
|
60
60
|
}
|
|
61
61
|
}
|
package/src/useContext.tsx
CHANGED
|
@@ -4,16 +4,6 @@ import { context } from '@pyreon/unistyle'
|
|
|
4
4
|
import { CONTEXT_KEYS } from './constants'
|
|
5
5
|
import type { Context, Obj, ValueType } from './types'
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Picks only the recognized grid configuration keys from a props object,
|
|
9
|
-
* filtering out any non-grid props before they enter context resolution.
|
|
10
|
-
*/
|
|
11
|
-
export type PickThemeProps = <T extends Record<string, unknown>>(
|
|
12
|
-
props: T,
|
|
13
|
-
keywords: Array<keyof T>,
|
|
14
|
-
) => ReturnType<typeof pick>
|
|
15
|
-
const pickThemeProps: PickThemeProps = (props, keywords) => pick(props, keywords)
|
|
16
|
-
|
|
17
7
|
/**
|
|
18
8
|
* Resolves grid columns and container width using a three-layer fallback:
|
|
19
9
|
* 1. Explicit component props (e.g. `columns={6}`)
|
|
@@ -29,10 +19,15 @@ type GetGridContext = (
|
|
|
29
19
|
}
|
|
30
20
|
|
|
31
21
|
export const getGridContext: GetGridContext = (props = {}, theme = {}) => ({
|
|
32
|
-
|
|
22
|
+
// `props` is always a plain object (callers pass a `pick()` result or a
|
|
23
|
+
// user-supplied object literal), so direct property access is safe and
|
|
24
|
+
// skips `get`'s path-parsing for these single-key lookups. Ported from
|
|
25
|
+
// vitus-labs `55402572`. Two `get` calls per `getGridContext` invocation
|
|
26
|
+
// saved; fires once per Container/Row/Col render.
|
|
27
|
+
columns: ((props as Obj).columns ||
|
|
33
28
|
get(theme, 'grid.columns') ||
|
|
34
29
|
get(theme, 'coolgrid.columns')) as ValueType,
|
|
35
|
-
containerWidth: (
|
|
30
|
+
containerWidth: ((props as Obj).width ||
|
|
36
31
|
get(theme, 'grid.container') ||
|
|
37
32
|
get(theme, 'coolgrid.container')) as Record<string, number>,
|
|
38
33
|
})
|
|
@@ -46,7 +41,9 @@ type UseGridContext = (props: Obj) => Context
|
|
|
46
41
|
const useGridContext: UseGridContext = (props) => {
|
|
47
42
|
const getCtx = useContext(context)
|
|
48
43
|
const { theme } = getCtx()
|
|
49
|
-
|
|
44
|
+
// Direct `pick` (vs the `pickThemeProps` one-liner wrapper that was
|
|
45
|
+
// removed in vitus-labs `55402572`) saves one function call per render.
|
|
46
|
+
const ctxProps = pick(props, CONTEXT_KEYS as Array<keyof typeof props>)
|
|
50
47
|
const gridContext = getGridContext(ctxProps, theme as Record<string, unknown>)
|
|
51
48
|
|
|
52
49
|
return { ...gridContext, ...ctxProps }
|