nextia 7.0.11 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nextia",
3
3
  "description": "Create fast web applications",
4
- "version": "7.0.11",
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.3",
45
+ "@vitest/coverage-v8": "4.1.5",
46
46
  "jsdom": "29.0.2",
47
- "vitest": "4.1.3"
47
+ "vitest": "4.1.5"
48
48
  }
49
49
  }
package/src/bin.js CHANGED
@@ -9,7 +9,7 @@
9
9
  * https://github.com/sinuhedev/nextia
10
10
  */
11
11
 
12
- import { writeFile } from 'node:fs/promises'
12
+ import { mkdir, writeFile } from 'node:fs/promises'
13
13
 
14
14
  function toPascalCase(str) {
15
15
  return str
@@ -21,7 +21,7 @@ function toPascalCase(str) {
21
21
  }
22
22
 
23
23
  async function createPage(name) {
24
- const dirName = `./src/pages/${name}`
24
+ const dirName = `./src/app/${name}`
25
25
  const pageName = `${toPascalCase(name)}Page`
26
26
 
27
27
  try {
@@ -30,13 +30,12 @@ async function createPage(name) {
30
30
  // index.jsx
31
31
  writeFile(
32
32
  `${dirName}/index.jsx`,
33
- `import { css, useFx } from 'nextia'
34
- import { useEffect } from 'react'
35
- import functions from './functions'
33
+ `import { css } from 'nextia'
34
+ import useFunctions from './functions'
36
35
  import './style.css'
37
36
 
38
- export default function ${pageName} () {
39
- const { state, fx } = useFx(functions)
37
+ export default function ${pageName}() {
38
+ const { state, fx } = useFunctions()
40
39
 
41
40
  return (
42
41
  <section className={css('${pageName}', '')}>
@@ -58,9 +57,15 @@ export default function ${pageName} () {
58
57
  // function.js
59
58
  writeFile(
60
59
  `${dirName}/functions.js`,
61
- `const initialState = {}
60
+ `import { useFx } from 'nextia'
61
+
62
+ export default () => {
63
+ const initialState = {}
62
64
 
63
- export default { initialState }
65
+ return useFx({
66
+ initialState
67
+ })
68
+ }
64
69
  `
65
70
  )
66
71
  console.info(`✔ Page "${pageName}" created at ${dirName}`)
@@ -71,19 +76,18 @@ export default { initialState }
71
76
 
72
77
  async function createComponent(name) {
73
78
  const dirName = `./src/components/${name}`
79
+ const componentName = toPascalCase(name)
74
80
 
75
81
  try {
76
82
  await mkdir(dirName)
77
- const componentName = toPascalCase(name)
78
83
 
79
84
  // index.jsx
80
85
  writeFile(
81
86
  `${dirName}/index.jsx`,
82
87
  `import { css } from 'nextia'
83
- import { useEffect } from 'react'
84
88
  import './style.css'
85
89
 
86
- export default function ${componentName} ({ className, style }) {
90
+ export default function ${componentName}({ className, style }) {
87
91
  return (
88
92
  <article className={css('${componentName}', className)} style={style}>
89
93
  ${componentName}
@@ -106,55 +110,6 @@ export default function ${componentName} ({ className, style }) {
106
110
  }
107
111
  }
108
112
 
109
- async function createContainer(name) {
110
- const dirName = `./src/components/${name}`
111
-
112
- try {
113
- await mkdir(dirName)
114
- const containerName = toPascalCase(name)
115
-
116
- // index.jsx
117
- writeFile(
118
- `${dirName}/index.jsx`,
119
- `import { css, useFx } from 'nextia'
120
- import { useEffect } from 'react'
121
- import functions from './functions'
122
- import './style.css'
123
-
124
- export default function ${containerName} ({ className, style }) {
125
- const { state, fx } = useFx(functions)
126
-
127
- return (
128
- <article className={css('${containerName}', className, '')} style={style}>
129
- ${containerName}
130
- </article>
131
- )
132
- }
133
- `
134
- )
135
-
136
- // style.css
137
- writeFile(
138
- `${dirName}/style.css`,
139
- `.${containerName} {
140
- }
141
- `
142
- )
143
-
144
- // function.js
145
- writeFile(
146
- `${dirName}/functions.js`,
147
- `const initialState = {}
148
-
149
- export default { initialState }
150
- `
151
- )
152
- console.info(`✔ Container "${name}" created at ${dirName}`)
153
- } catch (err) {
154
- console.error(`Failed to create container: ${err.message}`)
155
- }
156
- }
157
-
158
113
  async function main() {
159
114
  const ARG1 = process.argv[2]
160
115
  const ARG2 = process.argv[3]
@@ -162,17 +117,12 @@ async function main() {
162
117
  switch (ARG1) {
163
118
  case 'page':
164
119
  if (ARG2) await createPage(ARG2)
165
- else console.warn('node --run nextia page <page-name>')
120
+ else console.warn('node --run page -- <page-name>')
166
121
  break
167
122
 
168
123
  case 'component':
169
124
  if (ARG2) await createComponent(ARG2)
170
- else console.warn('node --run nextia component <ComponentName>')
171
- break
172
-
173
- case 'container':
174
- if (ARG2) await createContainer(ARG2)
175
- else console.warn('node --run nextia container <ContainerName>')
125
+ else console.warn('node --run component -- <ComponentName>')
176
126
  break
177
127
  }
178
128
  }
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 PagesFx = createContext()
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 pagesFx = use(PagesFx)
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: !pagesFx?.context
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: pagesFx?.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 { PagesFx, useFx }
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 { PagesFx, useFx } from './fx.js'
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
- PagesFx,
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 { useFx } from './fx'
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 } = useFx()
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 } = useFx()
67
+ const { iconsFile } = useCx()
68
68
  const ref = useRef()
69
69
 
70
70
  useEffect(() => {