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