ywana-core8 0.1.55 → 0.1.56
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/dist/index.cjs +102 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +102 -58
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +102 -57
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/site/index.js +3 -1
- package/src/site/link.js +75 -0
- package/src/site/navigation.js +51 -0
- package/src/site/site.js +4 -41
package/package.json
CHANGED
package/src/site/index.js
CHANGED
package/src/site/link.js
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
import { useEffect, useState, useRef } from "react"
|
2
|
+
import React, { useContext } from 'react'
|
3
|
+
import { SiteContext } from './siteContext'
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Use Hash Page
|
7
|
+
*/
|
8
|
+
export function useHashPage(defaultPage = "home") {
|
9
|
+
const getCurrentPageFromURL = () => {
|
10
|
+
const hash = window.location.hash.replace("#", "")
|
11
|
+
return hash || defaultPage
|
12
|
+
}
|
13
|
+
|
14
|
+
const [page, setPage] = useState(getCurrentPageFromURL())
|
15
|
+
const [history, setHistory] = useState([])
|
16
|
+
const isFirstLoad = useRef(true)
|
17
|
+
|
18
|
+
useEffect(() => {
|
19
|
+
const handleHashChange = () => {
|
20
|
+
const newPage = getCurrentPageFromURL()
|
21
|
+
if (!isFirstLoad.current) {
|
22
|
+
setHistory(prev => [...prev, page]) // Guarda la página anterior
|
23
|
+
} else {
|
24
|
+
isFirstLoad.current = false
|
25
|
+
}
|
26
|
+
setPage(newPage)
|
27
|
+
}
|
28
|
+
|
29
|
+
window.addEventListener("hashchange", handleHashChange)
|
30
|
+
return () => window.removeEventListener("hashchange", handleHashChange)
|
31
|
+
}, [page])
|
32
|
+
|
33
|
+
const goto = (id) => {
|
34
|
+
if (page) {
|
35
|
+
setHistory(prev => [...prev, page])
|
36
|
+
}
|
37
|
+
setPage(id)
|
38
|
+
window.location.hash = id
|
39
|
+
}
|
40
|
+
|
41
|
+
const goBack = () => {
|
42
|
+
if (history.length > 0) {
|
43
|
+
const lastPage = history[history.length - 1]
|
44
|
+
setHistory(prev => prev.slice(0, -1))
|
45
|
+
setPage(lastPage)
|
46
|
+
window.location.hash = lastPage
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
return { page, goto, goBack, history }
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* PageLink - Navegación declarativa usando el sistema de hash
|
55
|
+
*
|
56
|
+
* Props:
|
57
|
+
* - page: string → ID de la página a mostrar
|
58
|
+
* - children: ReactNode → contenido visual del enlace
|
59
|
+
* - className: string → clases opcionales
|
60
|
+
* - style: object → estilos en línea opcionales
|
61
|
+
*/
|
62
|
+
export const PageLink = ({ page, children, className = '', style = {} }) => {
|
63
|
+
const { goto } = useContext(SiteContext)
|
64
|
+
|
65
|
+
const handleClick = (e) => {
|
66
|
+
e.preventDefault()
|
67
|
+
goto(page)
|
68
|
+
}
|
69
|
+
|
70
|
+
return (
|
71
|
+
<a href={`#${page}`} onClick={handleClick} className={className} style={style}>
|
72
|
+
{children}
|
73
|
+
</a>
|
74
|
+
)
|
75
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { useEffect, useState, useRef } from "react"
|
2
|
+
import React, { useContext } from 'react'
|
3
|
+
import { SiteContext } from './siteContext'
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Use Hash Page
|
7
|
+
*/
|
8
|
+
export function useHashPage(defaultPage = "home") {
|
9
|
+
const getCurrentPageFromURL = () => {
|
10
|
+
const hash = window.location.hash.replace("#", "")
|
11
|
+
return hash || defaultPage
|
12
|
+
}
|
13
|
+
|
14
|
+
const [page, setPage] = useState(getCurrentPageFromURL())
|
15
|
+
const [history, setHistory] = useState([])
|
16
|
+
const isFirstLoad = useRef(true)
|
17
|
+
|
18
|
+
useEffect(() => {
|
19
|
+
const handleHashChange = () => {
|
20
|
+
const newPage = getCurrentPageFromURL()
|
21
|
+
if (!isFirstLoad.current) {
|
22
|
+
setHistory(prev => [...prev, page]) // Guarda la página anterior
|
23
|
+
} else {
|
24
|
+
isFirstLoad.current = false
|
25
|
+
}
|
26
|
+
setPage(newPage)
|
27
|
+
}
|
28
|
+
|
29
|
+
window.addEventListener("hashchange", handleHashChange)
|
30
|
+
return () => window.removeEventListener("hashchange", handleHashChange)
|
31
|
+
}, [page])
|
32
|
+
|
33
|
+
const goto = (id) => {
|
34
|
+
if (page) {
|
35
|
+
setHistory(prev => [...prev, page])
|
36
|
+
}
|
37
|
+
setPage(id)
|
38
|
+
window.location.hash = id
|
39
|
+
}
|
40
|
+
|
41
|
+
const goBack = () => {
|
42
|
+
if (history.length > 0) {
|
43
|
+
const lastPage = history[history.length - 1]
|
44
|
+
setHistory(prev => prev.slice(0, -1))
|
45
|
+
setPage(lastPage)
|
46
|
+
window.location.hash = lastPage
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
return { page, goto, goBack, history }
|
51
|
+
}
|
package/src/site/site.js
CHANGED
@@ -6,6 +6,7 @@ import { Tooltip } from '../html/tooltip'
|
|
6
6
|
import { Page } from './page'
|
7
7
|
import { SiteContext } from './siteContext'
|
8
8
|
import { ReactNotifications, Store } from 'react-notifications-component'
|
9
|
+
import { useHashPage } from './navigation'
|
9
10
|
import 'react-notifications-component/dist/theme.css'
|
10
11
|
import './site.css'
|
11
12
|
|
@@ -25,25 +26,8 @@ export const SiteProvider = ({ children, siteLang, siteDictionary }) => {
|
|
25
26
|
const [promptDialog, setPromptDialog] = useState()
|
26
27
|
const [preview, setPreview] = useState()
|
27
28
|
const [breadcrumb, setBreadcrumb] = useState()
|
28
|
-
const [history, setHistory] = useState([])
|
29
29
|
|
30
|
-
|
31
|
-
const getCurrentPageFromURL = () => {
|
32
|
-
const path = window.location.pathname.replace("/", "")
|
33
|
-
return path || "home"
|
34
|
-
}
|
35
|
-
const [page, setPage] = useState(getCurrentPageFromURL())
|
36
|
-
|
37
|
-
useEffect(() => {
|
38
|
-
// 📌 Detectar cambios en la URL cuando el usuario presiona "Atrás" o "Adelante"
|
39
|
-
const handlePopState = (event) => {
|
40
|
-
const previousPage = event.state?.page || "home"
|
41
|
-
setPage(previousPage)
|
42
|
-
}
|
43
|
-
|
44
|
-
window.addEventListener("popstate", handlePopState)
|
45
|
-
return () => window.removeEventListener("popstate", handlePopState)
|
46
|
-
}, [])
|
30
|
+
const { page, goto, goBack } = useHashPage()
|
47
31
|
|
48
32
|
const value = {
|
49
33
|
|
@@ -53,14 +37,6 @@ export const SiteProvider = ({ children, siteLang, siteDictionary }) => {
|
|
53
37
|
dictionary,
|
54
38
|
setDictionary,
|
55
39
|
translate: useCallback((key) => dictionary?.[key]?.[lang] || key, [lang, dictionary]),
|
56
|
-
/*
|
57
|
-
translate: (key) => {
|
58
|
-
if (!key) return key
|
59
|
-
if (dictionary === undefined) return key
|
60
|
-
const term = dictionary[key]
|
61
|
-
return term ? term[lang] : key
|
62
|
-
},
|
63
|
-
*/
|
64
40
|
|
65
41
|
sideNav,
|
66
42
|
setSideNav,
|
@@ -85,21 +61,8 @@ export const SiteProvider = ({ children, siteLang, siteDictionary }) => {
|
|
85
61
|
setBreadcrumb,
|
86
62
|
|
87
63
|
page,
|
88
|
-
goto
|
89
|
-
|
90
|
-
setHistory(prev => [...prev, page]) // 🔹 Guarda la página actual en el historial antes de cambiar
|
91
|
-
}
|
92
|
-
setPage(id)
|
93
|
-
window.history.pushState({ page: id }, "", `/${id}`) // 🔹 Actualiza la URL
|
94
|
-
},
|
95
|
-
goBack: () => {
|
96
|
-
if (history.length > 0) {
|
97
|
-
const lastPage = history[history.length - 1]
|
98
|
-
setHistory(prev => prev.slice(0, -1)) // 🔹 Elimina la última entrada del historial
|
99
|
-
setPage(lastPage) // 🔹 Vuelve a la página anterior
|
100
|
-
window.history.back() // 🔹 Regresa en la navegación del navegador
|
101
|
-
}
|
102
|
-
},
|
64
|
+
goto,
|
65
|
+
goBack,
|
103
66
|
|
104
67
|
dialog,
|
105
68
|
openDialog: (dialog) => { setDialog(dialog) },
|