ywana-core8 0.1.47 → 0.1.49
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 +71 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +73 -32
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +71 -30
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/site/site.js +50 -14
package/package.json
CHANGED
package/src/site/site.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { Children, Fragment, useState, useContext, useEffect } from 'react'
|
1
|
+
import React, { Children, Fragment, useState, useContext, useEffect, useCallback, useMemo } from 'react'
|
2
2
|
import { Icon } from '../html/icon'
|
3
3
|
import { Tabs, Tab } from '../html/tab'
|
4
4
|
import { Header } from '../html/header'
|
@@ -21,12 +21,30 @@ export const SiteProvider = ({ children, siteLang, siteDictionary }) => {
|
|
21
21
|
const [info, setInfo] = useState(null)
|
22
22
|
const [showConsole, setShowConsole] = useState(false)
|
23
23
|
const [consoleLines, setConsoleLines] = useState([])
|
24
|
-
const [page, setPage] = useState()
|
25
24
|
const [dialog, setDialog] = useState()
|
26
25
|
const [promptDialog, setPromptDialog] = useState()
|
27
26
|
const [preview, setPreview] = useState()
|
28
27
|
const [breadcrumb, setBreadcrumb] = useState()
|
29
|
-
|
28
|
+
const [history, setHistory] = useState([])
|
29
|
+
|
30
|
+
// 📌 Extraer la página actual desde la URL (por defecto "home")
|
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
|
+
}, [])
|
47
|
+
|
30
48
|
const value = {
|
31
49
|
|
32
50
|
lang,
|
@@ -34,13 +52,16 @@ export const SiteProvider = ({ children, siteLang, siteDictionary }) => {
|
|
34
52
|
|
35
53
|
dictionary,
|
36
54
|
setDictionary,
|
55
|
+
translate: useCallback((key) => dictionary?.[key]?.[lang] || key, [lang, dictionary]),
|
56
|
+
/*
|
37
57
|
translate: (key) => {
|
38
58
|
if (!key) return key
|
39
59
|
if (dictionary === undefined) return key
|
40
60
|
const term = dictionary[key]
|
41
61
|
return term ? term[lang] : key
|
42
62
|
},
|
43
|
-
|
63
|
+
*/
|
64
|
+
|
44
65
|
sideNav,
|
45
66
|
setSideNav,
|
46
67
|
|
@@ -64,7 +85,21 @@ export const SiteProvider = ({ children, siteLang, siteDictionary }) => {
|
|
64
85
|
setBreadcrumb,
|
65
86
|
|
66
87
|
page,
|
67
|
-
goto: (id) => {
|
88
|
+
goto: (id) => {
|
89
|
+
if (page) {
|
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
|
+
},
|
68
103
|
|
69
104
|
dialog,
|
70
105
|
openDialog: (dialog) => { setDialog(dialog) },
|
@@ -101,7 +136,7 @@ export const SiteProvider = ({ children, siteLang, siteDictionary }) => {
|
|
101
136
|
|
102
137
|
return (
|
103
138
|
<SiteContext.Provider value={value}>
|
104
|
-
|
139
|
+
{children}
|
105
140
|
</SiteContext.Provider>
|
106
141
|
)
|
107
142
|
}
|
@@ -204,14 +239,15 @@ const SiteMenu = ({ iconSrc, title, children, min }) => {
|
|
204
239
|
context.goto(id)
|
205
240
|
}
|
206
241
|
|
207
|
-
const sections =
|
208
|
-
|
209
|
-
const section =
|
210
|
-
if (!
|
211
|
-
const {
|
212
|
-
if (title)
|
213
|
-
return
|
214
|
-
}, {})
|
242
|
+
const sections = useMemo(() => {
|
243
|
+
return children.reduce((acc, child) => {
|
244
|
+
const section = child.props.section || "";
|
245
|
+
if (!acc[section]) acc[section] = [];
|
246
|
+
const { title } = child.props;
|
247
|
+
if (title) acc[section].push(child.props);
|
248
|
+
return acc;
|
249
|
+
}, {});
|
250
|
+
}, [children]);
|
215
251
|
|
216
252
|
const style = sideNav === 'max' ? 'max' : 'min'
|
217
253
|
const toggleIcon = sideNav === 'max' ? 'chevron_left' : 'chevron_right'
|