nextia 6.0.4 → 6.1.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/package.json +4 -5
- package/src/lib.js +20 -28
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextia",
|
|
3
3
|
"description": "Create fast web applications",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.1.1",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">22"
|
|
7
7
|
},
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"main": "src/lib.js",
|
|
24
24
|
"scripts": {
|
|
25
|
-
"clean": "rm -fr node_modules package-lock.json pnpm-lock.yaml .coverage",
|
|
25
|
+
"clean": "rm -fr node_modules package-lock.json pnpm-lock.yaml .coverage target",
|
|
26
26
|
"format": "biome format",
|
|
27
27
|
"lint": "biome lint src",
|
|
28
28
|
"check": "biome check --reporter=summary src",
|
|
@@ -36,10 +36,9 @@
|
|
|
36
36
|
"react-dom": "^19.2.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@vitejs/plugin-react": "^5.1.3",
|
|
39
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
41
40
|
"@vitest/coverage-v8": "^4.0.18",
|
|
42
|
-
"jsdom": "^
|
|
41
|
+
"jsdom": "^29.0.0",
|
|
43
42
|
"vitest": "^4.0.18"
|
|
44
43
|
}
|
|
45
44
|
}
|
package/src/lib.js
CHANGED
|
@@ -9,39 +9,32 @@
|
|
|
9
9
|
|
|
10
10
|
import { createContext, use, useReducer } from 'react'
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const PagesContext = createContext()
|
|
13
|
+
const isLogger = import.meta.env.DEV
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
+
* util
|
|
16
17
|
*/
|
|
17
|
-
const isLogger = import.meta.env.DEV && import.meta.env.VITE_LOGGER !== 'false'
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* css
|
|
21
|
-
*/
|
|
22
19
|
function css(...classNames) {
|
|
23
|
-
|
|
24
|
-
.filter((e) => e)
|
|
20
|
+
return classNames
|
|
25
21
|
.reduce((accumulator, currentValue) => {
|
|
26
22
|
if (typeof currentValue === 'string') {
|
|
27
|
-
accumulator.push(currentValue)
|
|
23
|
+
accumulator.push(currentValue.trim())
|
|
28
24
|
} else if (
|
|
29
25
|
!Array.isArray(currentValue) &&
|
|
30
26
|
typeof currentValue === 'object'
|
|
31
27
|
) {
|
|
32
28
|
for (const e in currentValue) {
|
|
33
|
-
if (currentValue[e]) accumulator.push(e)
|
|
29
|
+
if (currentValue[e]) accumulator.push(e.trim())
|
|
34
30
|
}
|
|
35
31
|
}
|
|
36
32
|
return accumulator
|
|
37
33
|
}, [])
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
.filter((e) => e)
|
|
35
|
+
.join(' ')
|
|
40
36
|
}
|
|
41
37
|
|
|
42
|
-
/**
|
|
43
|
-
* values
|
|
44
|
-
*/
|
|
45
38
|
function values(state, payload, value) {
|
|
46
39
|
const paths = payload.split('.')
|
|
47
40
|
|
|
@@ -68,9 +61,6 @@ function values(state, payload, value) {
|
|
|
68
61
|
return stateClone
|
|
69
62
|
}
|
|
70
63
|
|
|
71
|
-
/**
|
|
72
|
-
* merge
|
|
73
|
-
*/
|
|
74
64
|
function merge(target, source) {
|
|
75
65
|
// in array return all source
|
|
76
66
|
if (Array.isArray(target)) return source
|
|
@@ -91,6 +81,7 @@ function merge(target, source) {
|
|
|
91
81
|
/**
|
|
92
82
|
* reducer
|
|
93
83
|
*/
|
|
84
|
+
|
|
94
85
|
const reducer = (state, action) => {
|
|
95
86
|
const { type, payload, initialState } = action
|
|
96
87
|
|
|
@@ -160,7 +151,7 @@ const reducerLogger = (state, action) => {
|
|
|
160
151
|
}
|
|
161
152
|
|
|
162
153
|
console.log(
|
|
163
|
-
`%c${action.isContext ? 'Context' : 'Page
|
|
154
|
+
`%c${action.isContext ? 'Pages Context' : 'Page'} %c${action.type}`,
|
|
164
155
|
'color: #90b1d1',
|
|
165
156
|
'color: #6592c8',
|
|
166
157
|
payloadLog(action),
|
|
@@ -173,8 +164,9 @@ const reducerLogger = (state, action) => {
|
|
|
173
164
|
/**
|
|
174
165
|
* useFx
|
|
175
166
|
*/
|
|
167
|
+
|
|
176
168
|
function useFx(functions = { initialState: {} }) {
|
|
177
|
-
const
|
|
169
|
+
const pageContext = use(PagesContext)
|
|
178
170
|
const { initialState } = functions
|
|
179
171
|
const [state, dispatch] = useReducer(
|
|
180
172
|
isLogger ? reducerLogger : reducer,
|
|
@@ -185,7 +177,7 @@ function useFx(functions = { initialState: {} }) {
|
|
|
185
177
|
const commonActions = ['set', 'show', 'hide', 'change', 'reset'].reduce(
|
|
186
178
|
(acc, e) => {
|
|
187
179
|
acc[e] = (payload) =>
|
|
188
|
-
dispatch({ type: e, payload, initialState, isContext: !
|
|
180
|
+
dispatch({ type: e, payload, initialState, isContext: !pageContext })
|
|
189
181
|
return acc
|
|
190
182
|
},
|
|
191
183
|
{}
|
|
@@ -195,16 +187,16 @@ function useFx(functions = { initialState: {} }) {
|
|
|
195
187
|
const actions = Object.keys(functions).reduce((ac, e) => {
|
|
196
188
|
if (functions[e] instanceof Function) {
|
|
197
189
|
ac[e] = (payload) => {
|
|
198
|
-
const
|
|
190
|
+
const actionsProps = {
|
|
199
191
|
...commonActions,
|
|
200
192
|
state,
|
|
201
193
|
payload
|
|
202
194
|
}
|
|
203
|
-
if (
|
|
204
|
-
|
|
195
|
+
if (pageContext) {
|
|
196
|
+
actionsProps.context = pageContext
|
|
205
197
|
}
|
|
206
198
|
|
|
207
|
-
return functions[e](Object.freeze(
|
|
199
|
+
return functions[e](Object.freeze(actionsProps))
|
|
208
200
|
}
|
|
209
201
|
}
|
|
210
202
|
return ac
|
|
@@ -216,11 +208,11 @@ function useFx(functions = { initialState: {} }) {
|
|
|
216
208
|
state,
|
|
217
209
|
fx: { ...commonActions, ...actions }
|
|
218
210
|
}
|
|
219
|
-
if (
|
|
220
|
-
props.context =
|
|
211
|
+
if (pageContext) {
|
|
212
|
+
props.context = pageContext
|
|
221
213
|
}
|
|
222
214
|
|
|
223
215
|
return Object.freeze(props)
|
|
224
216
|
}
|
|
225
217
|
|
|
226
|
-
export {
|
|
218
|
+
export { css, PagesContext, useFx }
|