nextia 7.0.12 → 8.0.0
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 +3 -3
- package/src/bin.js +14 -61
- package/src/lib/fx.js +17 -10
- package/src/lib/index.js +3 -2
- package/src/lib/ui.js +3 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextia",
|
|
3
3
|
"description": "Create fast web applications",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "8.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@vitejs/plugin-react": "6.0.1",
|
|
45
|
-
"@vitest/coverage-v8": "4.1.
|
|
45
|
+
"@vitest/coverage-v8": "4.1.5",
|
|
46
46
|
"jsdom": "29.0.2",
|
|
47
|
-
"vitest": "4.1.
|
|
47
|
+
"vitest": "4.1.5"
|
|
48
48
|
}
|
|
49
49
|
}
|
package/src/bin.js
CHANGED
|
@@ -21,7 +21,7 @@ function toPascalCase(str) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
async function createPage(name) {
|
|
24
|
-
const dirName = `./src/
|
|
24
|
+
const dirName = `./src/app/${name}`
|
|
25
25
|
const pageName = `${toPascalCase(name)}Page`
|
|
26
26
|
|
|
27
27
|
try {
|
|
@@ -30,12 +30,12 @@ async function createPage(name) {
|
|
|
30
30
|
// index.jsx
|
|
31
31
|
writeFile(
|
|
32
32
|
`${dirName}/index.jsx`,
|
|
33
|
-
`import { css
|
|
34
|
-
import
|
|
33
|
+
`import { css } from 'nextia'
|
|
34
|
+
import useFunctions from './functions'
|
|
35
35
|
import './style.css'
|
|
36
36
|
|
|
37
|
-
export default function ${pageName}
|
|
38
|
-
const { state, fx } =
|
|
37
|
+
export default function ${pageName}() {
|
|
38
|
+
const { state, fx } = useFunctions()
|
|
39
39
|
|
|
40
40
|
return (
|
|
41
41
|
<section className={css('${pageName}', '')}>
|
|
@@ -57,9 +57,15 @@ export default function ${pageName} () {
|
|
|
57
57
|
// function.js
|
|
58
58
|
writeFile(
|
|
59
59
|
`${dirName}/functions.js`,
|
|
60
|
-
`
|
|
60
|
+
`import { useFx } from 'nextia'
|
|
61
|
+
|
|
62
|
+
export default () => {
|
|
63
|
+
const initialState = {}
|
|
61
64
|
|
|
62
|
-
|
|
65
|
+
return useFx({
|
|
66
|
+
initialState
|
|
67
|
+
})
|
|
68
|
+
}
|
|
63
69
|
`
|
|
64
70
|
)
|
|
65
71
|
console.info(`✔ Page "${pageName}" created at ${dirName}`)
|
|
@@ -81,7 +87,7 @@ async function createComponent(name) {
|
|
|
81
87
|
`import { css } from 'nextia'
|
|
82
88
|
import './style.css'
|
|
83
89
|
|
|
84
|
-
export default function ${componentName}
|
|
90
|
+
export default function ${componentName}({ className, style }) {
|
|
85
91
|
return (
|
|
86
92
|
<article className={css('${componentName}', className)} style={style}>
|
|
87
93
|
${componentName}
|
|
@@ -104,54 +110,6 @@ export default function ${componentName} ({ className, style }) {
|
|
|
104
110
|
}
|
|
105
111
|
}
|
|
106
112
|
|
|
107
|
-
async function createComponentFx(name) {
|
|
108
|
-
const dirName = `./src/components/${name}`
|
|
109
|
-
const componentFxName = toPascalCase(name)
|
|
110
|
-
|
|
111
|
-
try {
|
|
112
|
-
await mkdir(dirName)
|
|
113
|
-
|
|
114
|
-
// index.jsx
|
|
115
|
-
writeFile(
|
|
116
|
-
`${dirName}/index.jsx`,
|
|
117
|
-
`import { css, useFx } from 'nextia'
|
|
118
|
-
import functions from './functions'
|
|
119
|
-
import './style.css'
|
|
120
|
-
|
|
121
|
-
export default function ${componentFxName} ({ className, style }) {
|
|
122
|
-
const { state, fx } = useFx(functions)
|
|
123
|
-
|
|
124
|
-
return (
|
|
125
|
-
<article className={css('${componentFxName}', className, '')} style={style}>
|
|
126
|
-
${componentFxName}
|
|
127
|
-
</article>
|
|
128
|
-
)
|
|
129
|
-
}
|
|
130
|
-
`
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
// style.css
|
|
134
|
-
writeFile(
|
|
135
|
-
`${dirName}/style.css`,
|
|
136
|
-
`.${componentFxName} {
|
|
137
|
-
}
|
|
138
|
-
`
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
// function.js
|
|
142
|
-
writeFile(
|
|
143
|
-
`${dirName}/functions.js`,
|
|
144
|
-
`const initialState = {}
|
|
145
|
-
|
|
146
|
-
export default { initialState }
|
|
147
|
-
`
|
|
148
|
-
)
|
|
149
|
-
console.info(`✔ ComponentFx "${name}" created at ${dirName}`)
|
|
150
|
-
} catch (err) {
|
|
151
|
-
console.error(`Failed to create component:fx: ${err.message}`)
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
113
|
async function main() {
|
|
156
114
|
const ARG1 = process.argv[2]
|
|
157
115
|
const ARG2 = process.argv[3]
|
|
@@ -166,11 +124,6 @@ async function main() {
|
|
|
166
124
|
if (ARG2) await createComponent(ARG2)
|
|
167
125
|
else console.warn('node --run component -- <ComponentName>')
|
|
168
126
|
break
|
|
169
|
-
|
|
170
|
-
case 'component:fx':
|
|
171
|
-
if (ARG2) await createComponentFx(ARG2)
|
|
172
|
-
else console.warn('node --run component:fx -- <ComponentFxName>')
|
|
173
|
-
break
|
|
174
127
|
}
|
|
175
128
|
}
|
|
176
129
|
|
package/src/lib/fx.js
CHANGED
|
@@ -11,7 +11,7 @@ import { createContext, use, useReducer } from 'react'
|
|
|
11
11
|
import { env } from './utils.js'
|
|
12
12
|
|
|
13
13
|
const LOGGER = env.DEV && env.PUBLIC_LOGGER !== 'false'
|
|
14
|
-
const
|
|
14
|
+
const Pages = createContext()
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* util
|
|
@@ -144,11 +144,21 @@ const reducerLogger = (state, action) => {
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
|
-
* useFx
|
|
147
|
+
* useCx and useFx
|
|
148
148
|
*/
|
|
149
149
|
|
|
150
|
+
function useCx() {
|
|
151
|
+
const pages = use(Pages)
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
context: pages?.context,
|
|
155
|
+
iconsFile: pages?.iconsFile,
|
|
156
|
+
i18nFile: pages?.i18nFile
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
150
160
|
function useFx(functions = { initialState: {} }) {
|
|
151
|
-
const
|
|
161
|
+
const pages = useCx()
|
|
152
162
|
const { initialState } = functions
|
|
153
163
|
const [state, dispatch] = useReducer(
|
|
154
164
|
LOGGER ? reducerLogger : reducer,
|
|
@@ -163,7 +173,7 @@ function useFx(functions = { initialState: {} }) {
|
|
|
163
173
|
type: e,
|
|
164
174
|
payload,
|
|
165
175
|
initialState,
|
|
166
|
-
isContext: !
|
|
176
|
+
isContext: !pages?.context
|
|
167
177
|
})
|
|
168
178
|
return acc
|
|
169
179
|
},
|
|
@@ -178,7 +188,7 @@ function useFx(functions = { initialState: {} }) {
|
|
|
178
188
|
...commonActions,
|
|
179
189
|
state,
|
|
180
190
|
payload,
|
|
181
|
-
context:
|
|
191
|
+
context: pages?.context
|
|
182
192
|
}
|
|
183
193
|
|
|
184
194
|
return functions[e](Object.freeze(actionsProps))
|
|
@@ -192,13 +202,10 @@ function useFx(functions = { initialState: {} }) {
|
|
|
192
202
|
initialState,
|
|
193
203
|
state,
|
|
194
204
|
fx: { ...commonActions, ...actions },
|
|
195
|
-
|
|
196
|
-
context: pagesFx?.context,
|
|
197
|
-
iconsFile: pagesFx?.iconsFile,
|
|
198
|
-
i18nFile: pagesFx?.i18nFile
|
|
205
|
+
...pages
|
|
199
206
|
}
|
|
200
207
|
|
|
201
208
|
return Object.freeze(props)
|
|
202
209
|
}
|
|
203
210
|
|
|
204
|
-
export {
|
|
211
|
+
export { Pages, useCx, useFx }
|
package/src/lib/index.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* https://github.com/sinuhedev/nextia
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { Pages, useCx, useFx } from './fx.js'
|
|
11
11
|
import { useQueryString, useResize } from './hooks.js'
|
|
12
12
|
import { I18n, Icon, Link, Svg } from './ui.js'
|
|
13
13
|
import { css, env, startViewTransition } from './utils.js'
|
|
@@ -18,9 +18,10 @@ export {
|
|
|
18
18
|
I18n,
|
|
19
19
|
Icon,
|
|
20
20
|
Link,
|
|
21
|
-
|
|
21
|
+
Pages,
|
|
22
22
|
Svg,
|
|
23
23
|
startViewTransition,
|
|
24
|
+
useCx,
|
|
24
25
|
useFx,
|
|
25
26
|
useQueryString,
|
|
26
27
|
useResize
|
package/src/lib/ui.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { createElement, useEffect, useRef } from 'react'
|
|
11
|
-
import {
|
|
11
|
+
import { useCx } from './fx'
|
|
12
12
|
|
|
13
13
|
function Link({ children, href, value = {}, ...props }) {
|
|
14
14
|
href ??= window.location.hash.split('?')[0]
|
|
@@ -20,7 +20,7 @@ function Link({ children, href, value = {}, ...props }) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function I18n({ value, args = [] }) {
|
|
23
|
-
const { context, i18nFile } =
|
|
23
|
+
const { context, i18nFile } = useCx()
|
|
24
24
|
|
|
25
25
|
if (i18nFile) {
|
|
26
26
|
try {
|
|
@@ -64,7 +64,7 @@ function Icon({
|
|
|
64
64
|
strokeLinejoin = 'round',
|
|
65
65
|
...props
|
|
66
66
|
}) {
|
|
67
|
-
const { iconsFile } =
|
|
67
|
+
const { iconsFile } = useCx()
|
|
68
68
|
const ref = useRef()
|
|
69
69
|
|
|
70
70
|
useEffect(() => {
|