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.
@@ -1,7 +1,7 @@
1
1
  import 'material-design-icons-iconfont/dist/material-design-icons.css';
2
- import React, { useContext, useState, useEffect, useCallback, Fragment, Children, useMemo, useRef } from 'react';
2
+ import React, { useContext, useState, useEffect, useCallback, Fragment, useMemo, useRef } from 'react';
3
3
  import ResumableJS from 'resumablejs';
4
- import { ReactNotifications, Store } from 'react-notifications-component';
4
+ import { Store, ReactNotifications } from 'react-notifications-component';
5
5
  import 'react-notifications-component/dist/theme.css';
6
6
  import RSwitch from 'react-switch';
7
7
  import moment$1 from 'moment';
@@ -2042,31 +2042,59 @@ var SiteProvider = function SiteProvider(_ref) {
2042
2042
  consoleLines = _useState7[0],
2043
2043
  setConsoleLines = _useState7[1];
2044
2044
  var _useState8 = useState(),
2045
- page = _useState8[0],
2046
- setPage = _useState8[1];
2045
+ dialog = _useState8[0],
2046
+ setDialog = _useState8[1];
2047
2047
  var _useState9 = useState(),
2048
- dialog = _useState9[0],
2049
- setDialog = _useState9[1];
2048
+ promptDialog = _useState9[0],
2049
+ setPromptDialog = _useState9[1];
2050
2050
  var _useState10 = useState(),
2051
- promptDialog = _useState10[0],
2052
- setPromptDialog = _useState10[1];
2051
+ preview = _useState10[0],
2052
+ setPreview = _useState10[1];
2053
2053
  var _useState11 = useState(),
2054
- preview = _useState11[0],
2055
- setPreview = _useState11[1];
2056
- var _useState12 = useState(),
2057
- breadcrumb = _useState12[0],
2058
- setBreadcrumb = _useState12[1];
2054
+ breadcrumb = _useState11[0],
2055
+ setBreadcrumb = _useState11[1];
2056
+ var _useState12 = useState([]),
2057
+ history = _useState12[0],
2058
+ setHistory = _useState12[1];
2059
+
2060
+ // 📌 Extraer la página actual desde la URL (por defecto "home")
2061
+ var getCurrentPageFromURL = function getCurrentPageFromURL() {
2062
+ var path = window.location.pathname.replace("/", "");
2063
+ return path || "home";
2064
+ };
2065
+ var _useState13 = useState(getCurrentPageFromURL()),
2066
+ page = _useState13[0],
2067
+ setPage = _useState13[1];
2068
+ useEffect(function () {
2069
+ // 📌 Detectar cambios en la URL cuando el usuario presiona "Atrás" o "Adelante"
2070
+ var handlePopState = function handlePopState(event) {
2071
+ var _event$state;
2072
+ var previousPage = ((_event$state = event.state) == null ? void 0 : _event$state.page) || "home";
2073
+ setPage(previousPage);
2074
+ };
2075
+ window.addEventListener("popstate", handlePopState);
2076
+ return function () {
2077
+ return window.removeEventListener("popstate", handlePopState);
2078
+ };
2079
+ }, []);
2059
2080
  var value = {
2060
2081
  lang: lang,
2061
2082
  setLang: setLang,
2062
2083
  dictionary: dictionary,
2063
2084
  setDictionary: setDictionary,
2064
- translate: function translate(key) {
2065
- if (!key) return key;
2066
- if (dictionary === undefined) return key;
2067
- var term = dictionary[key];
2068
- return term ? term[lang] : key;
2085
+ translate: useCallback(function (key) {
2086
+ var _dictionary$key;
2087
+ return (dictionary == null ? void 0 : (_dictionary$key = dictionary[key]) == null ? void 0 : _dictionary$key[lang]) || key;
2088
+ }, [lang, dictionary]),
2089
+ /*
2090
+ translate: (key) => {
2091
+ if (!key) return key
2092
+ if (dictionary === undefined) return key
2093
+ const term = dictionary[key]
2094
+ return term ? term[lang] : key
2069
2095
  },
2096
+ */
2097
+
2070
2098
  sideNav: sideNav,
2071
2099
  setSideNav: setSideNav,
2072
2100
  showNav: showNav,
@@ -2094,7 +2122,25 @@ var SiteProvider = function SiteProvider(_ref) {
2094
2122
  setBreadcrumb: setBreadcrumb,
2095
2123
  page: page,
2096
2124
  "goto": function goto(id) {
2125
+ if (page) {
2126
+ setHistory(function (prev) {
2127
+ return [].concat(prev, [page]);
2128
+ }); // 🔹 Guarda la página actual en el historial antes de cambiar
2129
+ }
2097
2130
  setPage(id);
2131
+ window.history.pushState({
2132
+ page: id
2133
+ }, "", "/" + id); // 🔹 Actualiza la URL
2134
+ },
2135
+ goBack: function goBack() {
2136
+ if (history.length > 0) {
2137
+ var lastPage = history[history.length - 1];
2138
+ setHistory(function (prev) {
2139
+ return prev.slice(0, -1);
2140
+ }); // 🔹 Elimina la última entrada del historial
2141
+ setPage(lastPage); // 🔹 Vuelve a la página anterior
2142
+ window.history.back(); // 🔹 Regresa en la navegación del navegador
2143
+ }
2098
2144
  },
2099
2145
  dialog: dialog,
2100
2146
  openDialog: function openDialog(dialog) {
@@ -2252,20 +2298,15 @@ var SiteMenu = function SiteMenu(_ref6) {
2252
2298
  context.setShowNav(false);
2253
2299
  context["goto"](id);
2254
2300
  };
2255
- var sections = children ? Children.toArray(children).reduce(function (sections, page) {
2256
- var section = page.props ? page.props.section : '...';
2257
- if (!sections[section]) sections[section] = [];
2258
- var _page$props = page.props,
2259
- id = _page$props.id,
2260
- icon = _page$props.icon,
2261
- title = _page$props.title;
2262
- if (title) sections[section].push({
2263
- id: id,
2264
- icon: icon,
2265
- title: title
2266
- });
2267
- return sections;
2268
- }, {}) : {};
2301
+ var sections = useMemo(function () {
2302
+ return children.reduce(function (acc, child) {
2303
+ var section = child.props.section || "";
2304
+ if (!acc[section]) acc[section] = [];
2305
+ var title = child.props.title;
2306
+ if (title) acc[section].push(child.props);
2307
+ return acc;
2308
+ }, {});
2309
+ }, [children]);
2269
2310
  var style = sideNav === 'max' ? 'max' : 'min';
2270
2311
  var toggleIcon = sideNav === 'max' ? 'chevron_left' : 'chevron_right';
2271
2312
  var menutTitle = sideNav === 'max' ? title : '';