ywana-core8 0.1.48 → 0.1.50

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 CHANGED
@@ -2051,31 +2051,59 @@ var SiteProvider = function SiteProvider(_ref) {
2051
2051
  consoleLines = _useState7[0],
2052
2052
  setConsoleLines = _useState7[1];
2053
2053
  var _useState8 = React.useState(),
2054
- page = _useState8[0],
2055
- setPage = _useState8[1];
2054
+ dialog = _useState8[0],
2055
+ setDialog = _useState8[1];
2056
2056
  var _useState9 = React.useState(),
2057
- dialog = _useState9[0],
2058
- setDialog = _useState9[1];
2057
+ promptDialog = _useState9[0],
2058
+ setPromptDialog = _useState9[1];
2059
2059
  var _useState10 = React.useState(),
2060
- promptDialog = _useState10[0],
2061
- setPromptDialog = _useState10[1];
2060
+ preview = _useState10[0],
2061
+ setPreview = _useState10[1];
2062
2062
  var _useState11 = React.useState(),
2063
- preview = _useState11[0],
2064
- setPreview = _useState11[1];
2065
- var _useState12 = React.useState(),
2066
- breadcrumb = _useState12[0],
2067
- setBreadcrumb = _useState12[1];
2063
+ breadcrumb = _useState11[0],
2064
+ setBreadcrumb = _useState11[1];
2065
+ var _useState12 = React.useState([]),
2066
+ history = _useState12[0],
2067
+ setHistory = _useState12[1];
2068
+
2069
+ // 📌 Extraer la página actual desde la URL (por defecto "home")
2070
+ var getCurrentPageFromURL = function getCurrentPageFromURL() {
2071
+ var path = window.location.pathname.replace("/", "");
2072
+ return path || "home";
2073
+ };
2074
+ var _useState13 = React.useState(getCurrentPageFromURL()),
2075
+ page = _useState13[0],
2076
+ setPage = _useState13[1];
2077
+ React.useEffect(function () {
2078
+ // 📌 Detectar cambios en la URL cuando el usuario presiona "Atrás" o "Adelante"
2079
+ var handlePopState = function handlePopState(event) {
2080
+ var _event$state;
2081
+ var previousPage = ((_event$state = event.state) == null ? void 0 : _event$state.page) || "home";
2082
+ setPage(previousPage);
2083
+ };
2084
+ window.addEventListener("popstate", handlePopState);
2085
+ return function () {
2086
+ return window.removeEventListener("popstate", handlePopState);
2087
+ };
2088
+ }, []);
2068
2089
  var value = {
2069
2090
  lang: lang,
2070
2091
  setLang: setLang,
2071
2092
  dictionary: dictionary,
2072
2093
  setDictionary: setDictionary,
2073
- translate: function translate(key) {
2074
- if (!key) return key;
2075
- if (dictionary === undefined) return key;
2076
- var term = dictionary[key];
2077
- return term ? term[lang] : key;
2094
+ translate: React.useCallback(function (key) {
2095
+ var _dictionary$key;
2096
+ return (dictionary == null ? void 0 : (_dictionary$key = dictionary[key]) == null ? void 0 : _dictionary$key[lang]) || key;
2097
+ }, [lang, dictionary]),
2098
+ /*
2099
+ translate: (key) => {
2100
+ if (!key) return key
2101
+ if (dictionary === undefined) return key
2102
+ const term = dictionary[key]
2103
+ return term ? term[lang] : key
2078
2104
  },
2105
+ */
2106
+
2079
2107
  sideNav: sideNav,
2080
2108
  setSideNav: setSideNav,
2081
2109
  showNav: showNav,
@@ -2103,7 +2131,25 @@ var SiteProvider = function SiteProvider(_ref) {
2103
2131
  setBreadcrumb: setBreadcrumb,
2104
2132
  page: page,
2105
2133
  "goto": function goto(id) {
2134
+ if (page) {
2135
+ setHistory(function (prev) {
2136
+ return [].concat(prev, [page]);
2137
+ }); // 🔹 Guarda la página actual en el historial antes de cambiar
2138
+ }
2106
2139
  setPage(id);
2140
+ window.history.pushState({
2141
+ page: id
2142
+ }, "", "/" + id); // 🔹 Actualiza la URL
2143
+ },
2144
+ goBack: function goBack() {
2145
+ if (history.length > 0) {
2146
+ var lastPage = history[history.length - 1];
2147
+ setHistory(function (prev) {
2148
+ return prev.slice(0, -1);
2149
+ }); // 🔹 Elimina la última entrada del historial
2150
+ setPage(lastPage); // 🔹 Vuelve a la página anterior
2151
+ window.history.back(); // 🔹 Regresa en la navegación del navegador
2152
+ }
2107
2153
  },
2108
2154
  dialog: dialog,
2109
2155
  openDialog: function openDialog(dialog) {
@@ -2261,20 +2307,15 @@ var SiteMenu = function SiteMenu(_ref6) {
2261
2307
  context.setShowNav(false);
2262
2308
  context["goto"](id);
2263
2309
  };
2264
- var sections = children ? React.Children.toArray(children).reduce(function (sections, page) {
2265
- var section = page.props ? page.props.section : '...';
2266
- if (!sections[section]) sections[section] = [];
2267
- var _page$props = page.props,
2268
- id = _page$props.id,
2269
- icon = _page$props.icon,
2270
- title = _page$props.title;
2271
- if (title) sections[section].push({
2272
- id: id,
2273
- icon: icon,
2274
- title: title
2275
- });
2276
- return sections;
2277
- }, {}) : {};
2310
+ var sections = React.useMemo(function () {
2311
+ return children.reduce(function (acc, child) {
2312
+ var section = child.props.section || "";
2313
+ if (!acc[section]) acc[section] = [];
2314
+ var title = child.props.title;
2315
+ if (title) acc[section].push(child.props);
2316
+ return acc;
2317
+ }, {});
2318
+ }, [children]);
2278
2319
  var style = sideNav === 'max' ? 'max' : 'min';
2279
2320
  var toggleIcon = sideNav === 'max' ? 'chevron_left' : 'chevron_right';
2280
2321
  var menutTitle = sideNav === 'max' ? title : '';