nextia 8.0.0 → 8.0.2
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 +2 -2
- package/src/bin.js +2 -12
- package/src/lib/fx.js +50 -22
- package/src/lib/ui.js +38 -46
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.
|
|
4
|
+
"version": "8.0.2",
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
//
|
|
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 ? '
|
|
147
|
+
`%c${action.isContext ? 'Context' : 'Page'} %c${action.type}`,
|
|
137
148
|
'color: #90b1d1',
|
|
138
149
|
'color: #6592c8',
|
|
139
150
|
payloadLog(action),
|
|
@@ -149,16 +160,29 @@ 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
|
+
if (!pages?.icons) return
|
|
167
|
+
|
|
168
|
+
fetch(pages?.icons)
|
|
169
|
+
.then((r) => r.text())
|
|
170
|
+
.then((text) => {
|
|
171
|
+
setIcons(
|
|
172
|
+
new DOMParser().parseFromString(text, 'image/svg+xml').documentElement
|
|
173
|
+
)
|
|
174
|
+
})
|
|
175
|
+
}, [pages?.icons])
|
|
152
176
|
|
|
153
177
|
return {
|
|
154
178
|
context: pages?.context,
|
|
155
|
-
|
|
156
|
-
|
|
179
|
+
i18n: pages?.i18n,
|
|
180
|
+
icons
|
|
157
181
|
}
|
|
158
182
|
}
|
|
159
183
|
|
|
160
184
|
function useFx(functions = { initialState: {} }) {
|
|
161
|
-
const
|
|
185
|
+
const cx = useCx()
|
|
162
186
|
const { initialState } = functions
|
|
163
187
|
const [state, dispatch] = useReducer(
|
|
164
188
|
LOGGER ? reducerLogger : reducer,
|
|
@@ -166,19 +190,23 @@ function useFx(functions = { initialState: {} }) {
|
|
|
166
190
|
)
|
|
167
191
|
|
|
168
192
|
// Common actions
|
|
169
|
-
const commonActions = [
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
193
|
+
const commonActions = [
|
|
194
|
+
'set',
|
|
195
|
+
'show',
|
|
196
|
+
'hide',
|
|
197
|
+
'change',
|
|
198
|
+
'toggle',
|
|
199
|
+
'reset'
|
|
200
|
+
].reduce((acc, e) => {
|
|
201
|
+
acc[e] = (payload) =>
|
|
202
|
+
dispatch({
|
|
203
|
+
type: e,
|
|
204
|
+
payload,
|
|
205
|
+
initialState,
|
|
206
|
+
isContext: !cx?.context
|
|
207
|
+
})
|
|
208
|
+
return acc
|
|
209
|
+
}, {})
|
|
182
210
|
|
|
183
211
|
// Actions
|
|
184
212
|
const actions = Object.keys(functions).reduce((ac, e) => {
|
|
@@ -188,7 +216,7 @@ function useFx(functions = { initialState: {} }) {
|
|
|
188
216
|
...commonActions,
|
|
189
217
|
state,
|
|
190
218
|
payload,
|
|
191
|
-
context:
|
|
219
|
+
context: cx?.context
|
|
192
220
|
}
|
|
193
221
|
|
|
194
222
|
return functions[e](Object.freeze(actionsProps))
|
|
@@ -202,7 +230,7 @@ function useFx(functions = { initialState: {} }) {
|
|
|
202
230
|
initialState,
|
|
203
231
|
state,
|
|
204
232
|
fx: { ...commonActions, ...actions },
|
|
205
|
-
|
|
233
|
+
context: cx.context
|
|
206
234
|
}
|
|
207
235
|
|
|
208
236
|
return Object.freeze(props)
|
package/src/lib/ui.js
CHANGED
|
@@ -20,31 +20,26 @@ function Link({ children, href, value = {}, ...props }) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function I18n({ value, args = [] }) {
|
|
23
|
-
const { context,
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
]
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
text = text.replace(
|
|
38
|
-
/([{}])\\1|[{](.*?)(?:!(.+?))?[}]/g,
|
|
39
|
-
(match, _literal, number) => args[number] || match
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return text
|
|
44
|
-
} catch {
|
|
45
|
-
console.error(`Error in [il8n] => ${value}`)
|
|
46
|
-
return value
|
|
23
|
+
const { context, i18n } = useCx()
|
|
24
|
+
|
|
25
|
+
if (!i18n) return null
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
let text = value.split('.').reduce((ac, el) => ac[el], i18n)
|
|
29
|
+
|
|
30
|
+
text = text[i18n.locales.indexOf(context.state?.i18n || i18n.defaultLocale)]
|
|
31
|
+
|
|
32
|
+
if (args) {
|
|
33
|
+
text = text.replace(
|
|
34
|
+
/([{}])\\1|[{](.*?)(?:!(.+?))?[}]/g,
|
|
35
|
+
(match, _literal, number) => args[number] || match
|
|
36
|
+
)
|
|
47
37
|
}
|
|
38
|
+
|
|
39
|
+
return text
|
|
40
|
+
} catch {
|
|
41
|
+
console.error(`Error in [il8n] => ${value}`)
|
|
42
|
+
return value
|
|
48
43
|
}
|
|
49
44
|
}
|
|
50
45
|
|
|
@@ -64,20 +59,13 @@ function Icon({
|
|
|
64
59
|
strokeLinejoin = 'round',
|
|
65
60
|
...props
|
|
66
61
|
}) {
|
|
67
|
-
const {
|
|
62
|
+
const { icons } = useCx()
|
|
68
63
|
const ref = useRef()
|
|
69
64
|
|
|
70
65
|
useEffect(() => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
.documentElement.getElementById(id)
|
|
75
|
-
|
|
76
|
-
if (svg) {
|
|
77
|
-
ref.current.innerHTML = svg.innerHTML
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}, [id, iconsFile])
|
|
66
|
+
const el = icons?.getElementById(id)
|
|
67
|
+
if (ref.current && el) ref.current.innerHTML = el.innerHTML
|
|
68
|
+
}, [id, icons])
|
|
81
69
|
|
|
82
70
|
return createElement('svg', {
|
|
83
71
|
xmlns: 'http://www.w3.org/2000/svg',
|
|
@@ -102,17 +90,21 @@ function Svg({ ref, src, width, height, ...props }) {
|
|
|
102
90
|
ref ??= useRef()
|
|
103
91
|
|
|
104
92
|
useEffect(() => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
93
|
+
fetch(src)
|
|
94
|
+
.then((r) => r.text())
|
|
95
|
+
.then((text) => {
|
|
96
|
+
const svg = new DOMParser().parseFromString(
|
|
97
|
+
text,
|
|
98
|
+
'image/svg+xml'
|
|
99
|
+
).documentElement
|
|
100
|
+
|
|
101
|
+
for (const { name, value } of svg.attributes) {
|
|
102
|
+
if (name !== 'width' && name !== 'height')
|
|
103
|
+
ref.current.setAttribute(name, value)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
ref.current.replaceChildren(...svg.children)
|
|
107
|
+
})
|
|
116
108
|
}, [src, ref])
|
|
117
109
|
|
|
118
110
|
return createElement('svg', {
|