nextia 8.0.0 → 8.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nextia",
3
3
  "description": "Create fast web applications",
4
- "version": "8.0.0",
4
+ "version": "8.0.1",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "engines": {
@@ -43,7 +43,7 @@
43
43
  "devDependencies": {
44
44
  "@vitejs/plugin-react": "6.0.1",
45
45
  "@vitest/coverage-v8": "4.1.5",
46
- "jsdom": "29.0.2",
46
+ "jsdom": "29.1.0",
47
47
  "vitest": "4.1.5"
48
48
  }
49
49
  }
package/src/bin.js CHANGED
@@ -30,15 +30,13 @@ async function createPage(name) {
30
30
  // index.jsx
31
31
  writeFile(
32
32
  `${dirName}/index.jsx`,
33
- `import { css } from 'nextia'
34
- import useFunctions from './functions'
35
- import './style.css'
33
+ `import useFunctions from './functions'
36
34
 
37
35
  export default function ${pageName}() {
38
36
  const { state, fx } = useFunctions()
39
37
 
40
38
  return (
41
- <section className={css('${pageName}', '')}>
39
+ <section>
42
40
  ${pageName}
43
41
  </section>
44
42
  )
@@ -46,14 +44,6 @@ export default function ${pageName}() {
46
44
  `
47
45
  )
48
46
 
49
- // style.sss
50
- writeFile(
51
- `${dirName}/style.css`,
52
- `.${pageName} {
53
- }
54
- `
55
- )
56
-
57
47
  // function.js
58
48
  writeFile(
59
49
  `${dirName}/functions.js`,
package/src/lib/fx.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * https://github.com/sinuhedev/nextia
8
8
  */
9
9
 
10
- import { createContext, use, useReducer } from 'react'
10
+ import { createContext, use, useEffect, useReducer, useState } from 'react'
11
11
  import { env } from './utils.js'
12
12
 
13
13
  const LOGGER = env.DEV && env.PUBLIC_LOGGER !== 'false'
@@ -69,7 +69,7 @@ const reducer = (state, action) => {
69
69
 
70
70
  switch (type) {
71
71
  case 'set':
72
- // Merge only item
72
+ // Merge custom items
73
73
  if (Object.keys(payload).length === 1) {
74
74
  const key = Object.keys(payload)[0]
75
75
  return values(state, key, payload[key])
@@ -93,8 +93,19 @@ const reducer = (state, action) => {
93
93
  : payload.target.value
94
94
  )
95
95
 
96
+ case 'toggle':
97
+ // toggle custom items
98
+ if (payload) {
99
+ const paths = Array.isArray(payload) ? payload : [payload]
100
+
101
+ return paths.reduce((ac, path) => {
102
+ const value = path.split('.').reduce((ac, e) => ac[e], state)
103
+ return values(ac, path, !value)
104
+ }, state)
105
+ } else return state
106
+
96
107
  case 'reset':
97
- // value reset
108
+ // reset custom items
98
109
  if (payload) {
99
110
  const paths = Array.isArray(payload) ? payload : [payload]
100
111
 
@@ -133,7 +144,7 @@ const reducerLogger = (state, action) => {
133
144
  }
134
145
 
135
146
  console.log(
136
- `%c${action.isContext ? 'Pages Context' : 'Page'} %c${action.type}`,
147
+ `%c${action.isContext ? 'Context' : 'Page'} %c${action.type}`,
137
148
  'color: #90b1d1',
138
149
  'color: #6592c8',
139
150
  payloadLog(action),
@@ -149,16 +160,27 @@ const reducerLogger = (state, action) => {
149
160
 
150
161
  function useCx() {
151
162
  const pages = use(Pages)
163
+ const [icons, setIcons] = useState()
164
+
165
+ useEffect(() => {
166
+ fetch(pages?.icons)
167
+ .then((r) => r.text())
168
+ .then((text) => {
169
+ setIcons(
170
+ new DOMParser().parseFromString(text, 'image/svg+xml').documentElement
171
+ )
172
+ })
173
+ }, [pages?.icons])
152
174
 
153
175
  return {
154
176
  context: pages?.context,
155
- iconsFile: pages?.iconsFile,
156
- i18nFile: pages?.i18nFile
177
+ i18n: pages?.i18n,
178
+ icons
157
179
  }
158
180
  }
159
181
 
160
182
  function useFx(functions = { initialState: {} }) {
161
- const pages = useCx()
183
+ const cx = useCx()
162
184
  const { initialState } = functions
163
185
  const [state, dispatch] = useReducer(
164
186
  LOGGER ? reducerLogger : reducer,
@@ -166,19 +188,23 @@ function useFx(functions = { initialState: {} }) {
166
188
  )
167
189
 
168
190
  // Common actions
169
- const commonActions = ['set', 'show', 'hide', 'change', 'reset'].reduce(
170
- (acc, e) => {
171
- acc[e] = (payload) =>
172
- dispatch({
173
- type: e,
174
- payload,
175
- initialState,
176
- isContext: !pages?.context
177
- })
178
- return acc
179
- },
180
- {}
181
- )
191
+ const commonActions = [
192
+ 'set',
193
+ 'show',
194
+ 'hide',
195
+ 'change',
196
+ 'toggle',
197
+ 'reset'
198
+ ].reduce((acc, e) => {
199
+ acc[e] = (payload) =>
200
+ dispatch({
201
+ type: e,
202
+ payload,
203
+ initialState,
204
+ isContext: !cx?.context
205
+ })
206
+ return acc
207
+ }, {})
182
208
 
183
209
  // Actions
184
210
  const actions = Object.keys(functions).reduce((ac, e) => {
@@ -188,7 +214,7 @@ function useFx(functions = { initialState: {} }) {
188
214
  ...commonActions,
189
215
  state,
190
216
  payload,
191
- context: pages?.context
217
+ context: cx?.context
192
218
  }
193
219
 
194
220
  return functions[e](Object.freeze(actionsProps))
@@ -202,7 +228,7 @@ function useFx(functions = { initialState: {} }) {
202
228
  initialState,
203
229
  state,
204
230
  fx: { ...commonActions, ...actions },
205
- ...pages
231
+ context: cx.context
206
232
  }
207
233
 
208
234
  return Object.freeze(props)
package/src/lib/ui.js CHANGED
@@ -20,18 +20,14 @@ function Link({ children, href, value = {}, ...props }) {
20
20
  }
21
21
 
22
22
  function I18n({ value, args = [] }) {
23
- const { context, i18nFile } = useCx()
23
+ const { context, i18n } = useCx()
24
24
 
25
- if (i18nFile) {
25
+ if (i18n) {
26
26
  try {
27
- let text = value.split('.').reduce((ac, el) => ac[el], i18nFile)
27
+ let text = value.split('.').reduce((ac, el) => ac[el], i18n)
28
28
 
29
29
  text =
30
- text[
31
- i18nFile.locales.indexOf(
32
- context.state?.i18n || i18nFile.defaultLocale
33
- )
34
- ]
30
+ text[i18n.locales.indexOf(context.state?.i18n || i18n.defaultLocale)]
35
31
 
36
32
  if (args) {
37
33
  text = text.replace(
@@ -64,20 +60,14 @@ function Icon({
64
60
  strokeLinejoin = 'round',
65
61
  ...props
66
62
  }) {
67
- const { iconsFile } = useCx()
63
+ const { icons } = useCx()
68
64
  const ref = useRef()
69
65
 
70
66
  useEffect(() => {
71
- if (iconsFile) {
72
- const svg = new DOMParser()
73
- .parseFromString(iconsFile, 'image/svg+xml')
74
- .documentElement.getElementById(id)
75
-
76
- if (svg) {
77
- ref.current.innerHTML = svg.innerHTML
78
- }
67
+ if (icons) {
68
+ ref.current.innerHTML = icons.getElementById(id).innerHTML
79
69
  }
80
- }, [id, iconsFile])
70
+ }, [id, icons])
81
71
 
82
72
  return createElement('svg', {
83
73
  xmlns: 'http://www.w3.org/2000/svg',
@@ -102,17 +92,21 @@ function Svg({ ref, src, width, height, ...props }) {
102
92
  ref ??= useRef()
103
93
 
104
94
  useEffect(() => {
105
- const svg = new DOMParser().parseFromString(
106
- src,
107
- 'image/svg+xml'
108
- ).documentElement
109
-
110
- for (const { name, value } of svg.attributes) {
111
- if (name !== 'width' && name !== 'height')
112
- ref.current.setAttribute(name, value)
113
- }
114
-
115
- ref.current.replaceChildren(...svg.children)
95
+ fetch(src)
96
+ .then((r) => r.text())
97
+ .then((text) => {
98
+ const svg = new DOMParser().parseFromString(
99
+ text,
100
+ 'image/svg+xml'
101
+ ).documentElement
102
+
103
+ for (const { name, value } of svg.attributes) {
104
+ if (name !== 'width' && name !== 'height')
105
+ ref.current.setAttribute(name, value)
106
+ }
107
+
108
+ ref.current.replaceChildren(...svg.children)
109
+ })
116
110
  }, [src, ref])
117
111
 
118
112
  return createElement('svg', {