@creopse/react 0.0.16 → 0.0.18

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.
@@ -6974,6 +6974,7 @@ const useHelper = () => {
6974
6974
  const page = react.usePage();
6975
6975
  const { request } = useApi();
6976
6976
  const { apiBaseUrl, langKey } = useConfig();
6977
+ const config = React.useContext(ConfigContext);
6977
6978
  const currentRoutePath = React.useMemo(() => page.url, [page.url]);
6978
6979
  const resolveUrl = React.useCallback(
6979
6980
  (path) => {
@@ -7017,15 +7018,26 @@ const useHelper = () => {
7017
7018
  const getTranslation = React.useCallback(
7018
7019
  (data, lang2) => {
7019
7020
  let parsedData;
7020
- if (!lang2) lang2 = localStorage.getItem(langKey) || "en";
7021
+ let userLanguage = (
7022
+ // @ts-expect-error ignore
7023
+ (window.navigator.language || window.navigator.userLanguage)?.split(
7024
+ "-"
7025
+ )[0]
7026
+ );
7027
+ if (props.userData && props.userData.preferences && props.userData.preferences.locale) {
7028
+ userLanguage = props.userData.preferences.locale;
7029
+ }
7030
+ if (!lang2) {
7031
+ lang2 = localStorage.getItem(langKey) || userLanguage || props.appLocale || config?.locale || "en";
7032
+ }
7021
7033
  try {
7022
7034
  parsedData = JSON.parse(data);
7023
7035
  } catch (e) {
7024
7036
  parsedData = {};
7025
7037
  }
7026
- return parsedData ? parsedData[lang2.toUpperCase()] || parsedData[lang2] || parsedData["en"] || "" : "";
7038
+ return parsedData ? parsedData[lang2.toUpperCase()] || parsedData[lang2] || "" : "";
7027
7039
  },
7028
- [langKey]
7040
+ [config?.locale, langKey, props.appLocale, props.userData]
7029
7041
  );
7030
7042
  const tr = React.useCallback(
7031
7043
  (data, lang2) => {
@@ -7082,7 +7094,7 @@ const useHelper = () => {
7082
7094
  const languages = React.useMemo(
7083
7095
  () => [
7084
7096
  {
7085
- label: "French",
7097
+ label: "Français",
7086
7098
  value: "fr",
7087
7099
  flag: "flag:fr-1x1"
7088
7100
  },
@@ -6973,6 +6973,7 @@ const useHelper = () => {
6973
6973
  const page = usePage();
6974
6974
  const { request } = useApi();
6975
6975
  const { apiBaseUrl, langKey } = useConfig();
6976
+ const config = useContext(ConfigContext);
6976
6977
  const currentRoutePath = useMemo(() => page.url, [page.url]);
6977
6978
  const resolveUrl = useCallback(
6978
6979
  (path) => {
@@ -7016,15 +7017,26 @@ const useHelper = () => {
7016
7017
  const getTranslation = useCallback(
7017
7018
  (data, lang2) => {
7018
7019
  let parsedData;
7019
- if (!lang2) lang2 = localStorage.getItem(langKey) || "en";
7020
+ let userLanguage = (
7021
+ // @ts-expect-error ignore
7022
+ (window.navigator.language || window.navigator.userLanguage)?.split(
7023
+ "-"
7024
+ )[0]
7025
+ );
7026
+ if (props.userData && props.userData.preferences && props.userData.preferences.locale) {
7027
+ userLanguage = props.userData.preferences.locale;
7028
+ }
7029
+ if (!lang2) {
7030
+ lang2 = localStorage.getItem(langKey) || userLanguage || props.appLocale || config?.locale || "en";
7031
+ }
7020
7032
  try {
7021
7033
  parsedData = JSON.parse(data);
7022
7034
  } catch (e) {
7023
7035
  parsedData = {};
7024
7036
  }
7025
- return parsedData ? parsedData[lang2.toUpperCase()] || parsedData[lang2] || parsedData["en"] || "" : "";
7037
+ return parsedData ? parsedData[lang2.toUpperCase()] || parsedData[lang2] || "" : "";
7026
7038
  },
7027
- [langKey]
7039
+ [config?.locale, langKey, props.appLocale, props.userData]
7028
7040
  );
7029
7041
  const tr = useCallback(
7030
7042
  (data, lang2) => {
@@ -7081,7 +7093,7 @@ const useHelper = () => {
7081
7093
  const languages = useMemo(
7082
7094
  () => [
7083
7095
  {
7084
- label: "French",
7096
+ label: "Français",
7085
7097
  value: "fr",
7086
7098
  flag: "flag:fr-1x1"
7087
7099
  },
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const content = require("../content-yneKOQn5.cjs");
3
+ const content = require("../content-CGhgyzQQ.cjs");
4
4
  const React = require("react");
5
5
  const useNewsletter = () => {
6
6
  const { request } = content.useApi();
@@ -1,5 +1,5 @@
1
- import { e as useApi } from "../content-CfIj9nZq.js";
2
- import { f, a, u, b } from "../content-CfIj9nZq.js";
1
+ import { e as useApi } from "../content-j9XJsmqN.js";
2
+ import { f, a, u, b } from "../content-j9XJsmqN.js";
3
3
  import { useState, useCallback } from "react";
4
4
  const useNewsletter = () => {
5
5
  const { request } = useApi();
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const React = require("react");
4
- const content = require("./content-yneKOQn5.cjs");
5
- require("@inertiajs/react");
4
+ const content = require("./content-CGhgyzQQ.cjs");
5
+ const react = require("@inertiajs/react");
6
6
  const reactDom = require("react-dom");
7
7
  function _interopNamespaceDefault(e) {
8
8
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -8184,7 +8184,7 @@ const resetStyles = "_reset-styles_1tka1_1";
8184
8184
  const styles = {
8185
8185
  resetStyles
8186
8186
  };
8187
- const RootContainer = () => {
8187
+ const RootContainer$1 = () => {
8188
8188
  const { page } = content.useContent();
8189
8189
  const props = content.useProps();
8190
8190
  const manager = React.useContext(content.PropsContext);
@@ -8403,6 +8403,15 @@ const RootContainer = () => {
8403
8403
  );
8404
8404
  }) }, sectionsWrapperKey);
8405
8405
  };
8406
+ function RootContainer() {
8407
+ const [key, setKey] = React.useState(() => v4());
8408
+ React.useEffect(() => {
8409
+ return react.router.on("navigate", () => {
8410
+ setKey(v4());
8411
+ });
8412
+ }, []);
8413
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(RootContainer$1, {}, key);
8414
+ }
8406
8415
  function CreopseProvider({ children, options }) {
8407
8416
  if (!options?.initialProps) {
8408
8417
  throw new Error("[@creopse/react] initialProps is required");
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import React__default, { useState, useEffect, createContext, useRef, useLayoutEffect, useId, useContext, useInsertionEffect, useMemo, useCallback, Children, isValidElement, Fragment, createElement, forwardRef, Component } from "react";
3
- import { u as useHelper, a as useContent, b as useProps, P as PropsContext, R as ResolveSectionsContext, c as cloneDeep, s as slideToId, E as EditorMessageType, d as RouterContext, C as ConfigContext } from "./content-CfIj9nZq.js";
4
- import "@inertiajs/react";
3
+ import { u as useHelper, a as useContent, b as useProps, P as PropsContext, R as ResolveSectionsContext, c as cloneDeep, s as slideToId, E as EditorMessageType, d as RouterContext, C as ConfigContext } from "./content-j9XJsmqN.js";
4
+ import { router } from "@inertiajs/react";
5
5
  import { createPortal } from "react-dom";
6
6
  var jsxRuntime = { exports: {} };
7
7
  var reactJsxRuntime_production = {};
@@ -8166,7 +8166,7 @@ const resetStyles = "_reset-styles_1tka1_1";
8166
8166
  const styles = {
8167
8167
  resetStyles
8168
8168
  };
8169
- const RootContainer = () => {
8169
+ const RootContainer$1 = () => {
8170
8170
  const { page } = useContent();
8171
8171
  const props = useProps();
8172
8172
  const manager = useContext(PropsContext);
@@ -8385,6 +8385,15 @@ const RootContainer = () => {
8385
8385
  );
8386
8386
  }) }, sectionsWrapperKey);
8387
8387
  };
8388
+ function RootContainer() {
8389
+ const [key, setKey] = useState(() => v4());
8390
+ useEffect(() => {
8391
+ return router.on("navigate", () => {
8392
+ setKey(v4());
8393
+ });
8394
+ }, []);
8395
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(RootContainer$1, {}, key);
8396
+ }
8388
8397
  function CreopseProvider({ children, options }) {
8389
8398
  if (!options?.initialProps) {
8390
8399
  throw new Error("[@creopse/react] initialProps is required");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@creopse/react",
3
3
  "description": "Creopse React Toolkit",
4
- "version": "0.0.16",
4
+ "version": "0.0.18",
5
5
  "private": false,
6
6
  "author": "Noé Gnanih <noegnanih@gmail.com>",
7
7
  "license": "MIT",
@@ -43,7 +43,7 @@
43
43
  "react-dom": "^19.1.0"
44
44
  },
45
45
  "dependencies": {
46
- "@creopse/utils": "^0.0.11",
46
+ "@creopse/utils": "^0.0.12",
47
47
  "@vueuse/core": "^14.1.0",
48
48
  "axios": "^1.13.2",
49
49
  "framer-motion": "^12.23.9",
@@ -0,0 +1,2 @@
1
+ declare const RootContainer: () => import("react/jsx-runtime").JSX.Element;
2
+ export default RootContainer;
@@ -1,2 +1 @@
1
- declare const RootContainer: () => import("react/jsx-runtime").JSX.Element;
2
- export default RootContainer;
1
+ export default function RootContainer(): import("react/jsx-runtime").JSX.Element;
@@ -16,6 +16,8 @@ export declare const useConfig: () => {
16
16
  debug: boolean;
17
17
  appUrl: string;
18
18
  xApiKey: string;
19
+ locale: string;
20
+ fallbackLocale: string;
19
21
  encryptionKey: string;
20
22
  langKey: string;
21
23
  };
@@ -8,6 +8,8 @@ export interface PluginConfig {
8
8
  debug: boolean;
9
9
  appUrl: string;
10
10
  xApiKey: string;
11
+ locale: string;
12
+ fallbackLocale: string;
11
13
  encryptionKey: string;
12
14
  langKey: string;
13
15
  }