ywana-core8 0.1.58 → 0.1.60

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,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.1.58",
3
+ "version": "0.1.60",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
package/src/site/link.js CHANGED
@@ -1,55 +1,6 @@
1
- import { useEffect, useState, useRef } from "react"
2
1
  import React, { useContext } from 'react'
3
2
  import { SiteContext } from './siteContext'
4
3
 
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
4
  /**
54
5
  * PageLink - Navegación declarativa usando el sistema de hash
55
6
  *
@@ -50,5 +50,5 @@ export function useHashPage(defaultPage = "home") {
50
50
  }
51
51
  }
52
52
 
53
- return { page, goto, goBack, history }
53
+ return { page, goto, goBack, history, direction }
54
54
  }
package/src/site/site.css CHANGED
@@ -119,8 +119,32 @@
119
119
  }
120
120
 
121
121
  .site-page-container {
122
- position:relative;
123
- overflow: hidden;
122
+ position: relative;
123
+ transition: all 0.3s ease;
124
+ }
125
+
126
+ /* Cuando una página sale */
127
+ .site-page-container.page-out {
128
+ opacity: 0;
129
+ transform: translateX(-30px);
130
+ }
131
+
132
+ /* Cuando una página entra */
133
+ .site-page-container.page-in {
134
+ opacity: 0;
135
+ transform: translateX(30px);
136
+ animation: pageIn 0.3s forwards;
137
+ }
138
+
139
+ @keyframes pageIn {
140
+ from {
141
+ opacity: 0;
142
+ transform: translateX(30px);
143
+ }
144
+ to {
145
+ opacity: 1;
146
+ transform: translateX(0);
147
+ }
124
148
  }
125
149
 
126
150
  .site6>main {
package/src/site/site.js CHANGED
@@ -6,11 +6,9 @@ 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'
10
9
  import 'react-notifications-component/dist/theme.css'
11
10
  import './site.css'
12
- import motion from "framer-motion/dist/framer-motion.cjs"
13
- const { AnimatePresence, motion: MotionDiv } = motion
11
+ import { useHashPage } from './navigation'
14
12
 
15
13
  /**
16
14
  * Site Provider
@@ -29,7 +27,7 @@ export const SiteProvider = ({ children, siteLang, siteDictionary }) => {
29
27
  const [preview, setPreview] = useState()
30
28
  const [breadcrumb, setBreadcrumb] = useState()
31
29
 
32
- const { page, goto, goBack } = useHashPage()
30
+ const { page, goto, goBack, direction } = useHashPage()
33
31
 
34
32
  const value = {
35
33
 
@@ -65,6 +63,7 @@ export const SiteProvider = ({ children, siteLang, siteDictionary }) => {
65
63
  page,
66
64
  goto,
67
65
  goBack,
66
+ direction,
68
67
 
69
68
  dialog,
70
69
  openDialog: (dialog) => { setDialog(dialog) },
@@ -254,8 +253,13 @@ const SiteMenu = ({ iconSrc, title, children, min }) => {
254
253
  * SitePage
255
254
  */
256
255
  const SitePage = ({ children, init }) => {
256
+
257
257
  const context = useContext(SiteContext)
258
- const { page, direction } = context
258
+ const { page } = context
259
+
260
+ const [renderedPage, setRenderedPage] = useState(page)
261
+ const [transitionClass, setTransitionClass] = useState('')
262
+
259
263
  useEffect(() => {
260
264
  if (init) {
261
265
  context.goto(init)
@@ -263,24 +267,25 @@ const SitePage = ({ children, init }) => {
263
267
  context.goto("EMPTY")
264
268
  }
265
269
  }, [])
266
-
267
- const currentPage = React.Children.toArray(children).filter(child => child.props ? child.props.id === page : false)
268
- const xOffset = direction === "left" ? 40 : -40
270
+
271
+ useEffect(() => {
272
+ if (page !== renderedPage) {
273
+ setTransitionClass(`page-out-${context.direction}`)
274
+ setTimeout(() => {
275
+ setTransitionClass(`page-in-${context.direction}`)
276
+ setRenderedPage(page)
277
+ setTimeout(() => {
278
+ setTransitionClass('')
279
+ }, 300)
280
+ }, 300)
281
+ setRenderedPage(page)
282
+ }
283
+ }, [page])
284
+
285
+ const currentPage = Children.toArray(children).filter(child => child.props ? child.props.id === renderedPage : false)
269
286
  return (
270
- <main className='site-page-container'>
271
- <AnimatePresence exitBeforeEnter>
272
- {currentPage && (
273
- <MotionDiv
274
- key={page}
275
- initial={{ opacity: 0, x: xOffset }}
276
- animate={{ opacity: 1, x: 0 }}
277
- exit={{ opacity: 0, x: -xOffset }}
278
- transition={{ duration: 0.3 }}
279
- >
280
- {currentPage}
281
- </MotionDiv>
282
- )}
283
- </AnimatePresence>
287
+ <main className={`site-page-container ${transitionClass}`}>
288
+ {currentPage}
284
289
  </main>
285
290
  )
286
291
  }