nextia 9.0.0 → 9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nextia",
3
3
  "description": "Create fast web applications",
4
- "version": "9.0.0",
4
+ "version": "9.0.2",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "engines": {
package/src/fx.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * https://github.com/sinuhedev/nextia
8
8
  */
9
9
 
10
- import { createContext, use, useEffect, useReducer, useState } from 'react'
10
+ import { createContext, use, useReducer } from 'react'
11
11
 
12
12
  const Pagex = createContext()
13
13
 
@@ -158,24 +158,11 @@ const reducerLogger = (state, action) => {
158
158
 
159
159
  function useCx() {
160
160
  const pages = use(Pagex)
161
- const [icons, setIcons] = useState()
162
-
163
- useEffect(() => {
164
- if (!pages?.icons) return
165
-
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])
174
161
 
175
162
  return {
176
163
  context: pages?.context,
177
164
  i18n: pages?.i18n,
178
- icons,
165
+ icons: pages?.icons,
179
166
  logger: pages?.logger ?? false
180
167
  }
181
168
  }
package/src/index.js CHANGED
@@ -10,10 +10,11 @@
10
10
  import { Pagex, useCx, useFx } from './fx.js'
11
11
  import { useQueryString, useResize } from './hooks.js'
12
12
  import { I18n, Icon, Link, Svg } from './ui.js'
13
- import { css, startViewTransition, version } from './utils.js'
13
+ import { css, getVersion, startViewTransition } from './utils.js'
14
14
 
15
15
  export {
16
16
  css,
17
+ getVersion,
17
18
  I18n,
18
19
  Icon,
19
20
  Link,
@@ -23,6 +24,5 @@ export {
23
24
  useCx,
24
25
  useFx,
25
26
  useQueryString,
26
- useResize,
27
- version
27
+ useResize
28
28
  }
package/src/ui.js CHANGED
@@ -10,35 +10,27 @@
10
10
  import { createElement, useEffect, useRef } from 'react'
11
11
  import { useCx } from './fx.js'
12
12
 
13
- function Link({ children, href, value = {}, ...props }) {
14
- href ??= window.location.hash.split('?')[0]
15
- value = Object.keys(value).length
16
- ? `?${new URLSearchParams(value).toString()}`
17
- : ''
18
-
19
- return createElement('a', { href: href + value, ...props }, children)
20
- }
21
-
22
13
  function I18n({ value, args = [] }) {
23
14
  const { context, i18n } = useCx()
24
15
 
25
16
  if (!i18n) return null
26
17
 
27
18
  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
19
+ const text = value.split('.').reduce((ac, el) => ac[el], i18n)
20
+ const locale = context.state?.i18n ?? i18n.defaultLocale
21
+ const index = i18n.locales.indexOf(locale)
22
+ let translated = text[index]
23
+
24
+ if (args?.length) {
25
+ translated = translated.replace(
26
+ /([{}])\1|[{](.*?)(?:!(.+?))?[}]/g,
27
+ (match, _literal, number) => args[number] ?? match
36
28
  )
37
29
  }
38
30
 
39
- return text
31
+ return translated
40
32
  } catch {
41
- console.error(`Error in [il8n] => ${value}`)
33
+ console.error(`[i18n] key not found: "${value}"`)
42
34
  return value
43
35
  }
44
36
  }
@@ -46,7 +38,6 @@ function I18n({ value, args = [] }) {
46
38
  function Icon({
47
39
  id,
48
40
  className,
49
- animate = false,
50
41
  style,
51
42
  width = '48',
52
43
  height,
@@ -63,8 +54,13 @@ function Icon({
63
54
  const ref = useRef()
64
55
 
65
56
  useEffect(() => {
66
- const el = icons?.getElementById(id)
67
- if (ref.current && el) ref.current.innerHTML = el.innerHTML
57
+ if (!ref.current || !icons) return
58
+
59
+ const el = new DOMParser()
60
+ .parseFromString(icons, 'image/svg+xml')
61
+ .documentElement.getElementById(id)
62
+
63
+ if (el) ref.current.innerHTML = el.innerHTML
68
64
  }, [id, icons])
69
65
 
70
66
  return createElement('svg', {
@@ -86,6 +82,16 @@ function Icon({
86
82
  })
87
83
  }
88
84
 
85
+ function Link({ children, href, value, ...props }) {
86
+ const base = href ?? window.location.hash.split('?')[0]
87
+ const query =
88
+ value && Object.keys(value).length
89
+ ? `?${new URLSearchParams(value).toString()}`
90
+ : ''
91
+
92
+ return createElement('a', { href: base + query, ...props }, children)
93
+ }
94
+
89
95
  function Svg({ ref, src, width, height, ...props }) {
90
96
  ref ??= useRef()
91
97
 
package/src/utils.js CHANGED
@@ -7,18 +7,6 @@
7
7
  * https://github.com/sinuhedev/nextia
8
8
  */
9
9
 
10
- /**
11
- * View Transition
12
- */
13
-
14
- async function startViewTransition(fun = () => {}, ref, animation = 'fade') {
15
- if (!document.startViewTransition) return fun()
16
-
17
- ref.style.viewTransitionName = animation
18
- await document.startViewTransition(() => fun).finished
19
- ref.style.viewTransitionName = ''
20
- }
21
-
22
10
  /**
23
11
  * css
24
12
  */
@@ -46,7 +34,7 @@ function css(...classNames) {
46
34
  * getVersion
47
35
  */
48
36
 
49
- const version = () =>
37
+ const getVersion = () =>
50
38
  Object.fromEntries(
51
39
  document
52
40
  .querySelector('meta[name="version"]')
@@ -58,4 +46,16 @@ const version = () =>
58
46
  }) ?? ''
59
47
  )
60
48
 
61
- export { css, startViewTransition, version }
49
+ /**
50
+ * View Transition
51
+ */
52
+
53
+ async function startViewTransition(fun = () => {}, ref, animation = 'fade') {
54
+ if (!document.startViewTransition) return fun()
55
+
56
+ ref.style.viewTransitionName = animation
57
+ await document.startViewTransition(() => fun).finished
58
+ ref.style.viewTransitionName = ''
59
+ }
60
+
61
+ export { css, getVersion, startViewTransition }