ywana-core8 0.1.46 → 0.1.48
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 +12 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +12 -2
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +12 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/html/tree.js +6 -1
- package/src/site/index.js +1 -1
- package/src/site/site.js +48 -12
- package/src/site/site2.js +338 -0
package/package.json
CHANGED
package/src/html/tree.js
CHANGED
@@ -43,17 +43,22 @@ export const TreeNode = ({ id, icon = 'folder', label, tooltip, open=false, chil
|
|
43
43
|
/**
|
44
44
|
* Tree Item
|
45
45
|
*/
|
46
|
-
export const TreeItem = ({ id, icon = 'description', label, actions, onSelect, selected = false }) => {
|
46
|
+
export const TreeItem = ({ id, icon = 'description', label, actions, onSelect, selected = false, onCheck, checked = false }) => {
|
47
47
|
|
48
48
|
function select() {
|
49
49
|
if (onSelect) onSelect(id)
|
50
50
|
}
|
51
51
|
|
52
|
+
function check(event) {
|
53
|
+
if (onCheck) onCheck(id, event.target.checked)
|
54
|
+
}
|
55
|
+
|
52
56
|
const style = selected ? "selected" : ""
|
53
57
|
const labelTxt = label ? <Text format={TEXTFORMATS.STRING}>{label}</Text> : null
|
54
58
|
|
55
59
|
return (
|
56
60
|
<div className={`tree-item final ${style}`} onClick={select}>
|
61
|
+
{ onCheck ? <input type="checkbox" checked={checked} onChange={check} /> : null }
|
57
62
|
<Icon icon={icon} size="small" small />
|
58
63
|
<div className="label">{labelTxt}</div>
|
59
64
|
<div className="actions">{actions}</div>
|
package/src/site/index.js
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,12 +52,15 @@ 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
|
},
|
63
|
+
*/
|
43
64
|
|
44
65
|
sideNav,
|
45
66
|
setSideNav,
|
@@ -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) },
|
@@ -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'
|
@@ -0,0 +1,338 @@
|
|
1
|
+
import React, { Children, Fragment, useState, useContext, useEffect, useCallback, useMemo } from 'react'
|
2
|
+
import { Header } from './header'
|
3
|
+
import { Icon } from '../html/icon'
|
4
|
+
import { Page } from './page'
|
5
|
+
import { ConfirmDialog } from './dialog'
|
6
|
+
import './site.css'
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Site Context
|
10
|
+
*/
|
11
|
+
export const SiteContext = React.createContext({})
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Site Provider
|
15
|
+
*/
|
16
|
+
export const SiteProvider = ({ children, siteLang, siteDictionary }) => {
|
17
|
+
|
18
|
+
const [lang, setLang] = useState(siteLang)
|
19
|
+
const [dictionary, setDictionary] = useState(siteDictionary)
|
20
|
+
const [sideNav, setSideNav] = useState('max')
|
21
|
+
const [showNav, setShowNav] = useState(false)
|
22
|
+
const [info, setInfo] = useState(true)
|
23
|
+
const [showConsole, setShowConsole] = useState(false)
|
24
|
+
const [consoleLines, setConsoleLines] = useState([])
|
25
|
+
const [dialog, setDialog] = useState()
|
26
|
+
const [promptDialog, setPromptDialog] = useState()
|
27
|
+
const [preview, setPreview] = useState()
|
28
|
+
const [breadcrumb, setBreadcrumb] = useState()
|
29
|
+
const [history, setHistory] = useState([])
|
30
|
+
|
31
|
+
// 📌 Extraer la página actual desde la URL (por defecto "home")
|
32
|
+
const getCurrentPageFromURL = () => {
|
33
|
+
const path = window.location.pathname.replace("/", "")
|
34
|
+
return path || "home"
|
35
|
+
}
|
36
|
+
const [page, setPage] = useState(getCurrentPageFromURL())
|
37
|
+
|
38
|
+
useEffect(() => {
|
39
|
+
// 📌 Detectar cambios en la URL cuando el usuario presiona "Atrás" o "Adelante"
|
40
|
+
const handlePopState = (event) => {
|
41
|
+
const previousPage = event.state?.page || "home"
|
42
|
+
setPage(previousPage)
|
43
|
+
}
|
44
|
+
|
45
|
+
window.addEventListener("popstate", handlePopState)
|
46
|
+
return () => window.removeEventListener("popstate", handlePopState)
|
47
|
+
}, [])
|
48
|
+
|
49
|
+
const value = useMemo(() => ({
|
50
|
+
|
51
|
+
lang,
|
52
|
+
setLang,
|
53
|
+
dictionary,
|
54
|
+
setDictionary,
|
55
|
+
translate: useCallback((key) => dictionary?.[key]?.[lang] || key, [lang, dictionary]),
|
56
|
+
|
57
|
+
sideNav,
|
58
|
+
setSideNav,
|
59
|
+
|
60
|
+
showNav,
|
61
|
+
setShowNav,
|
62
|
+
|
63
|
+
info,
|
64
|
+
openInfo: (info) => { setInfo(info) },
|
65
|
+
closeInfo: () => { setInfo(null) },
|
66
|
+
|
67
|
+
consoleLines,
|
68
|
+
showConsole,
|
69
|
+
toggleConsole: () => { setShowConsole(!showConsole) },
|
70
|
+
writeLog: (line) => {
|
71
|
+
const next = consoleLines.concat(line)
|
72
|
+
setConsoleLines(next)
|
73
|
+
},
|
74
|
+
clearLog: () => { setConsoleLines([]) },
|
75
|
+
|
76
|
+
breadcrumb,
|
77
|
+
setBreadcrumb,
|
78
|
+
|
79
|
+
page,
|
80
|
+
goto: (id) => {
|
81
|
+
if (page) {
|
82
|
+
setHistory(prev => [...prev, page]) // 🔹 Guarda la página actual en el historial antes de cambiar
|
83
|
+
}
|
84
|
+
setPage(id)
|
85
|
+
window.history.pushState({ page: id }, "", `/${id}`) // 🔹 Actualiza la URL
|
86
|
+
},
|
87
|
+
goBack: () => {
|
88
|
+
if (history.length > 0) {
|
89
|
+
const lastPage = history[history.length - 1]
|
90
|
+
setHistory(prev => prev.slice(0, -1)) // 🔹 Elimina la última entrada del historial
|
91
|
+
setPage(lastPage) // 🔹 Vuelve a la página anterior
|
92
|
+
window.history.back() // 🔹 Regresa en la navegación del navegador
|
93
|
+
}
|
94
|
+
},
|
95
|
+
|
96
|
+
dialog,
|
97
|
+
openDialog: (dialog) => { setDialog(dialog) },
|
98
|
+
closeDialog: () => { setDialog(null) },
|
99
|
+
|
100
|
+
preview,
|
101
|
+
openPreview: (preview) => { setPreview(preview) },
|
102
|
+
closePreview: () => { setPreview(null) },
|
103
|
+
|
104
|
+
confirm: (props) => {
|
105
|
+
setPromptDialog(<ConfirmDialog {...props} />)
|
106
|
+
},
|
107
|
+
|
108
|
+
prompt: (message) => window.prompt(message),
|
109
|
+
|
110
|
+
promptDialog,
|
111
|
+
openPromptDialog: (dialog) => { setPromptDialog(dialog) },
|
112
|
+
closePromptDialog: () => { setPromptDialog(null) },
|
113
|
+
|
114
|
+
}), [lang, dictionary, sideNav, showNav, info, consoleLines, showConsole, breadcrumb, page, dialog, promptDialog, preview])
|
115
|
+
|
116
|
+
return (
|
117
|
+
<SiteContext.Provider value={value}>
|
118
|
+
{children}
|
119
|
+
</SiteContext.Provider>
|
120
|
+
)
|
121
|
+
}
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Site
|
125
|
+
*/
|
126
|
+
export const Site = ({ icon, logo, title, headerBar, asideBar, footer, children, init, min, lang, dictionary }) => {
|
127
|
+
return (
|
128
|
+
<SiteErrorBoundary>
|
129
|
+
<SiteProvider siteLang={lang} siteDictionary={dictionary}>
|
130
|
+
<div className="site10">
|
131
|
+
<SiteHeader icon={icon} logo={logo} title={title} >
|
132
|
+
{headerBar}
|
133
|
+
</SiteHeader>
|
134
|
+
<SiteMenu title={title} min={min} >{children}</SiteMenu>
|
135
|
+
<SitePage init={init}>
|
136
|
+
{children}
|
137
|
+
<Page id="EMPTY">EMPTY</Page>
|
138
|
+
</SitePage>
|
139
|
+
<SiteBar>{asideBar}</SiteBar>
|
140
|
+
<SiteAside />
|
141
|
+
<SiteDialog />
|
142
|
+
<SitePromptDialog />
|
143
|
+
<SitePreview />
|
144
|
+
<SiteFooter>{footer}</SiteFooter>
|
145
|
+
</div>
|
146
|
+
</SiteProvider>
|
147
|
+
</SiteErrorBoundary>
|
148
|
+
)
|
149
|
+
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
* Site Header
|
153
|
+
*/
|
154
|
+
const SiteHeader = (props) => {
|
155
|
+
|
156
|
+
const context = useContext(SiteContext)
|
157
|
+
const { sideNav, setSideNav } = context
|
158
|
+
const { icon = "equalizer", logo, title } = props
|
159
|
+
|
160
|
+
function toggleMenu() {
|
161
|
+
const next = sideNav === 'max' ? 'min' : 'max'
|
162
|
+
setSideNav(next)
|
163
|
+
}
|
164
|
+
|
165
|
+
return (
|
166
|
+
<Header icon={icon} iconAction={toggleMenu} logo={logo} title={title} />
|
167
|
+
)
|
168
|
+
}
|
169
|
+
|
170
|
+
/**
|
171
|
+
* Site Bar
|
172
|
+
*/
|
173
|
+
const SiteBar = ({ children }) => {
|
174
|
+
return (
|
175
|
+
<nav>
|
176
|
+
{children}
|
177
|
+
</nav>
|
178
|
+
)
|
179
|
+
}
|
180
|
+
|
181
|
+
/**
|
182
|
+
* Site Footer
|
183
|
+
*/
|
184
|
+
const SiteFooter = ({ children }) => {
|
185
|
+
return (
|
186
|
+
<footer>
|
187
|
+
{children}
|
188
|
+
</footer>
|
189
|
+
)
|
190
|
+
}
|
191
|
+
|
192
|
+
/**
|
193
|
+
* Site Aside
|
194
|
+
*/
|
195
|
+
const SiteAside = () => {
|
196
|
+
const context = useContext(SiteContext)
|
197
|
+
return context.info ? (
|
198
|
+
<aside>
|
199
|
+
{context.info}
|
200
|
+
</aside>
|
201
|
+
) : ''
|
202
|
+
}
|
203
|
+
|
204
|
+
/**
|
205
|
+
* SiteMenu
|
206
|
+
*/
|
207
|
+
const SiteMenu = ({ iconSrc, title, children, min }) => {
|
208
|
+
|
209
|
+
const context = useContext(SiteContext)
|
210
|
+
const { page, sideNav, setSideNav, showNav } = context
|
211
|
+
|
212
|
+
useEffect(() => {
|
213
|
+
if (min) context.setSideNav('min')
|
214
|
+
}, [])
|
215
|
+
|
216
|
+
function toggle() {
|
217
|
+
const next = sideNav === 'max' ? 'min' : 'max'
|
218
|
+
setSideNav(next)
|
219
|
+
}
|
220
|
+
|
221
|
+
const goto = (id) => {
|
222
|
+
context.setShowNav(false)
|
223
|
+
context.goto(id)
|
224
|
+
}
|
225
|
+
|
226
|
+
const sections = useMemo(() => {
|
227
|
+
return children.reduce((acc, child) => {
|
228
|
+
const section = child.props.section || "";
|
229
|
+
if (!acc[section]) acc[section] = [];
|
230
|
+
const { title } = child.props;
|
231
|
+
if (title) acc[section].push(child.props);
|
232
|
+
return acc;
|
233
|
+
}, {});
|
234
|
+
}, [children]);
|
235
|
+
|
236
|
+
const style = sideNav === 'max' ? 'max' : 'min'
|
237
|
+
return (
|
238
|
+
<menu className={`${style} ${showNav ? 'show' : ''}`}>
|
239
|
+
<main >
|
240
|
+
{Object.keys(sections).map(title => (
|
241
|
+
<Fragment key={title}>
|
242
|
+
{title === 'undefined' ? '' : <div className={`section-title ${style}`}>{sideNav === "max" ? title : ''}</div>}
|
243
|
+
{sections[title].map(({ id, icon = 'info', title }) => {
|
244
|
+
const styleItem = id === page ? 'selected' : ''
|
245
|
+
const titleTxt = context.translate(title)
|
246
|
+
return (
|
247
|
+
<div className={`site-menu-item ${styleItem}`} key={id} onClick={() => goto(id)}>
|
248
|
+
<Icon key={id} icon={icon} clickable />
|
249
|
+
{sideNav === 'max' ? <label>{titleTxt}</label> : null}
|
250
|
+
</div>
|
251
|
+
)
|
252
|
+
})}
|
253
|
+
<div className="section-divider" ></div>
|
254
|
+
</Fragment>
|
255
|
+
))}
|
256
|
+
</main>
|
257
|
+
</menu>
|
258
|
+
)
|
259
|
+
}
|
260
|
+
|
261
|
+
/**
|
262
|
+
* SitePage
|
263
|
+
*/
|
264
|
+
const SitePage = ({ children, init }) => {
|
265
|
+
const context = useContext(SiteContext)
|
266
|
+
const { page } = context
|
267
|
+
useEffect(() => {
|
268
|
+
if (init) {
|
269
|
+
context.goto(init)
|
270
|
+
} else {
|
271
|
+
context.goto("EMPTY")
|
272
|
+
}
|
273
|
+
}, [])
|
274
|
+
return (
|
275
|
+
<main>
|
276
|
+
{React.Children.toArray(children).filter(child => child.props ? child.props.id === page : false)}
|
277
|
+
</main>
|
278
|
+
)
|
279
|
+
}
|
280
|
+
|
281
|
+
/**
|
282
|
+
* Site Dialog
|
283
|
+
*/
|
284
|
+
const SiteDialog = () => {
|
285
|
+
const context = useContext(SiteContext)
|
286
|
+
return context.dialog ? context.dialog : ''
|
287
|
+
}
|
288
|
+
|
289
|
+
/**
|
290
|
+
* Site Promtp Dialog
|
291
|
+
*/
|
292
|
+
const SitePromptDialog = () => {
|
293
|
+
const context = useContext(SiteContext)
|
294
|
+
return context.promptDialog ? context.promptDialog : ''
|
295
|
+
}
|
296
|
+
|
297
|
+
/**
|
298
|
+
* Site Preview
|
299
|
+
*/
|
300
|
+
const SitePreview = () => {
|
301
|
+
const context = useContext(SiteContext)
|
302
|
+
return context.preview ? (
|
303
|
+
<div className="site-preview" >
|
304
|
+
{context.preview}
|
305
|
+
</div>
|
306
|
+
) : ''
|
307
|
+
}
|
308
|
+
|
309
|
+
class SiteErrorBoundary extends React.Component {
|
310
|
+
|
311
|
+
constructor(props) {
|
312
|
+
super(props)
|
313
|
+
this.state = { hasError: false }
|
314
|
+
}
|
315
|
+
|
316
|
+
static getDerivedStateFromError(error) {
|
317
|
+
return { hasError: true, error }
|
318
|
+
}
|
319
|
+
|
320
|
+
componentDidCatch(error, errorInfo) {
|
321
|
+
console.error("SiteErrorBoundary >", error, errorInfo)
|
322
|
+
}
|
323
|
+
|
324
|
+
render() {
|
325
|
+
if (this.state.hasError) {
|
326
|
+
|
327
|
+
const { error } = this.state
|
328
|
+
|
329
|
+
return (
|
330
|
+
<div className="site-error">
|
331
|
+
<h1>Site Error</h1>
|
332
|
+
<p>Error {error.status}: {error.message}</p>
|
333
|
+
</div>
|
334
|
+
)
|
335
|
+
}
|
336
|
+
return this.props.children
|
337
|
+
}
|
338
|
+
}
|