@localazy/strapi-plugin 1.0.4 → 1.0.9

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.
Files changed (61) hide show
  1. package/dist/_chunks/FetchIdentity-4kkW9N7Y.js +981 -0
  2. package/dist/_chunks/FetchIdentity-BWSQAXt-.mjs +983 -0
  3. package/dist/_chunks/{LanguagesSelector-CeB7tVcb.mjs → LanguagesSelector-DwAGgpcR.mjs} +4 -2
  4. package/dist/_chunks/{LanguagesSelector-Bd8VFHib.js → LanguagesSelector-yWC_Yb_S.js} +12 -10
  5. package/dist/_chunks/{App-NRmSxuW3.js → LocalazyApp-DnaA768k.js} +136 -117
  6. package/dist/_chunks/{App-CtS6CrNn.mjs → LocalazyApp-zySanVTu.mjs} +32 -13
  7. package/dist/_chunks/{ContentTransferSetup-CeKXlzw_.mjs → LocalazyContentTransferSetup-C7qVIeix.mjs} +49 -456
  8. package/dist/_chunks/{ContentTransferSetup-DGs8MZPj.js → LocalazyContentTransferSetup-CeOM6bYA.js} +113 -520
  9. package/dist/_chunks/{GlobalSettings-rOwd0Y0E.mjs → LocalazyGlobalSettings-QvuLdsLe.mjs} +17 -8
  10. package/dist/_chunks/{GlobalSettings-CRMPRA3Y.js → LocalazyGlobalSettings-ewETL3oG.js} +61 -52
  11. package/dist/_chunks/LocalazyPanel-BXVLvFgD.js +83 -0
  12. package/dist/_chunks/LocalazyPanel-BotUsX-y.mjs +83 -0
  13. package/dist/_chunks/LocalazyStatusColumn-C81HewMg.mjs +51 -0
  14. package/dist/_chunks/LocalazyStatusColumn-Dt96YcGQ.js +51 -0
  15. package/dist/_chunks/{isEqual-CC-cEPwY.mjs → RequireLocalazyAuth-CDuyGCrT.mjs} +22 -1
  16. package/dist/_chunks/{isEqual-0M0aSdTT.js → RequireLocalazyAuth-CWBWETzC.js} +50 -29
  17. package/dist/_chunks/_commonjsHelpers-Bc2YnDe1.js +7 -0
  18. package/dist/_chunks/_commonjsHelpers-DWwsNxpa.mjs +8 -0
  19. package/dist/_chunks/en-CMWcM0nM.js +10 -0
  20. package/dist/_chunks/en-RX915msK.mjs +10 -0
  21. package/dist/_chunks/entry-exclusion-service-BVPICve2.mjs +60 -0
  22. package/dist/_chunks/entry-exclusion-service-CGV6iOkB.js +60 -0
  23. package/dist/_chunks/{has-model-changed-gNSOSMBa.js → has-model-changed-DVYRxVhM.js} +33 -32
  24. package/dist/_chunks/{has-model-changed-DViUIQHk.mjs → has-model-changed-DZL36gWh.mjs} +3 -2
  25. package/dist/_chunks/i18n-0dV2P-Hm.js +2378 -0
  26. package/dist/_chunks/i18n-RoETLXdU.mjs +2378 -0
  27. package/dist/_chunks/index-1he9s_bs.js +430 -0
  28. package/dist/_chunks/index-BIbKC7-V.mjs +432 -0
  29. package/dist/_chunks/index-CCxXsn7Z.js +254 -0
  30. package/dist/_chunks/{set-Cbi1yYuW.js → index-CaY3BYnQ.js} +878 -4379
  31. package/dist/_chunks/{set-Dnhh_SyE.mjs → index-CgI_aKe_.mjs} +906 -4408
  32. package/dist/_chunks/index-DsrYI6aB.mjs +231 -0
  33. package/dist/_chunks/initReactI18next-B0H8_DlW.js +60 -0
  34. package/dist/_chunks/initReactI18next-MHHxeg_9.mjs +61 -0
  35. package/dist/_chunks/{index-Dj68Ixl2.mjs → strapi-api-base-BE8VMlaA.js} +7 -234
  36. package/dist/_chunks/{index-Bbwk3kp3.js → strapi-api-base-DjeKGUw7.mjs} +15 -242
  37. package/dist/_chunks/useTranslation-BdIl-aLe.js +188 -0
  38. package/dist/_chunks/useTranslation-CZQ4lU1m.mjs +189 -0
  39. package/dist/admin/index.js +1 -1
  40. package/dist/admin/index.mjs +1 -1
  41. package/dist/admin/src/components/LocalazyPanel.d.ts +4 -0
  42. package/dist/admin/src/components/LocalazyStatusColumn.d.ts +3 -0
  43. package/dist/admin/src/components/RequireLocalazyAuth.d.ts +6 -0
  44. package/dist/admin/src/index.d.ts +1 -0
  45. package/dist/admin/src/modules/entry-exclusion/services/entry-exclusion-service.d.ts +18 -0
  46. package/dist/admin/src/modules/plugin-settings/locale/en.d.ts +8 -0
  47. package/dist/admin/src/pages/LocalazyApp.d.ts +2 -0
  48. package/dist/admin/src/pages/LocalazyContentTransferSetup.d.ts +2 -0
  49. package/dist/admin/src/pages/LocalazyGlobalSettings.d.ts +2 -0
  50. package/dist/server/index.js +202 -35
  51. package/dist/server/index.mjs +202 -35
  52. package/dist/server/src/controllers/entry-exclusion-controller.d.ts +21 -0
  53. package/dist/server/src/controllers/index.d.ts +7 -0
  54. package/dist/server/src/core/index.d.ts +6 -0
  55. package/dist/server/src/index.d.ts +15 -0
  56. package/dist/server/src/routes/entry-exclusion-routes.d.ts +9 -0
  57. package/dist/server/src/services/entry-exclusion-service.d.ts +23 -0
  58. package/dist/server/src/services/index.d.ts +8 -0
  59. package/package.json +2 -2
  60. package/dist/_chunks/en-BTf8goGM.mjs +0 -8
  61. package/dist/_chunks/en-CRtsEFtl.js +0 -8
@@ -1,84 +1,4 @@
1
- "use strict";
2
- const React = require("react");
3
- const jsxRuntime = require("react/jsx-runtime");
4
- const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
5
- const React__default = /* @__PURE__ */ _interopDefault(React);
6
- const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
7
- const v = glob[path];
8
- if (v) {
9
- return typeof v === "function" ? v() : Promise.resolve(v);
10
- }
11
- return new Promise((_, reject) => {
12
- (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
13
- reject.bind(
14
- null,
15
- new Error(
16
- "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
17
- )
18
- )
19
- );
20
- });
21
- };
22
- const strapi = {
23
- name: "localazy"
24
- };
25
- const pluginPkg = {
26
- strapi
27
- };
28
- const PLUGIN_ID = pluginPkg.strapi.name;
29
- const getTranslation = (id) => `${PLUGIN_ID}.${id}`;
30
- const Initializer = ({ setPlugin }) => {
31
- const ref = React.useRef(setPlugin);
32
- React.useEffect(() => {
33
- ref.current(PLUGIN_ID);
34
- }, []);
35
- return null;
36
- };
37
- const Localazy = () => {
38
- return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", fill: "#8e8ea9", children: [
39
- /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M16.4517 2.56643L16.3247 2.87501L15.5632 4.67576H7.49071C7.18595 4.67576 6.98278 4.98434 7.1013 5.26333L9.05259 9.91314C9.12031 10.0695 9.27269 10.171 9.442 10.171H12.6211C12.9216 10.171 13.1247 10.4753 13.0147 10.7501L12.8919 11.046L12.1353 12.8468H10.9192C10.6187 12.8468 10.4113 13.1553 10.5298 13.4343L13.8229 21.2925C13.9626 21.6265 13.7171 21.9942 13.353 21.9942H11.3256C11.1224 21.9942 10.9362 21.8716 10.8557 21.6814L3.1056 3.17091C2.8728 2.61293 3.27915 2 3.88443 2H16.0538C16.3501 2 16.5533 2.29167 16.4517 2.56643Z" }),
40
- /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M17.2937 13.5315L21.0354 4.63345C21.2724 4.07548 20.8619 3.45832 20.2566 3.46255L17.2267 3.46255L16.4794 5.23793C16.4794 5.24638 16.4752 5.25484 16.4709 5.26329L16.4709 5.26329L16.3482 5.55074C16.2297 5.82973 16.4371 6.1383 16.7376 6.1383H16.8069C17.1074 6.1383 17.3148 6.44688 17.1963 6.72587L15.2408 11.3757C15.1773 11.5321 15.0207 11.6335 14.8514 11.6335H13.7902L12.9112 13.7217C12.7927 14.0007 13.0001 14.3093 13.3006 14.3093H16.1212C16.6334 14.3093 17.0947 14.0007 17.2937 13.5315Z" })
41
- ] });
42
- };
43
- const emptyIdentity = {
44
- accessToken: "",
45
- project: {
46
- id: "",
47
- image: "",
48
- name: "",
49
- url: ""
50
- },
51
- scope: "",
52
- user: {
53
- id: "",
54
- name: ""
55
- }
56
- };
57
- const LocalazyIdentityContextType = React.createContext(void 0);
58
- const LocalazyIdentityProvider = ({ children }) => {
59
- const [identity, setIdentity] = React.useState(emptyIdentity);
60
- const [isFetchingIdentity, setIsFetchingIdentity] = React.useState(true);
61
- const isLoggedIn = React.useMemo(() => !!identity.accessToken, [identity.accessToken]);
62
- return /* @__PURE__ */ jsxRuntime.jsx(
63
- LocalazyIdentityContextType.Provider,
64
- {
65
- value: { identity, setIdentity, isLoggedIn, isFetchingIdentity, setIsFetchingIdentity },
66
- children
67
- }
68
- );
69
- };
70
- const useLocalazyIdentity = () => {
71
- const context = React.useContext(LocalazyIdentityContextType);
72
- if (context === void 0) {
73
- throw new Error("useLocalazyIdentity must be used within a LocalazyIdentityProvider");
74
- }
75
- return context;
76
- };
77
- const localazyIdentity = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
78
- __proto__: null,
79
- LocalazyIdentityProvider,
80
- useLocalazyIdentity
81
- }, Symbol.toStringTag, { value: "Module" }));
1
+ import { P as PLUGIN_ID } from "./index-DsrYI6aB.mjs";
82
2
  function bind(fn, thisArg) {
83
3
  return function wrap() {
84
4
  return fn.apply(thisArg, arguments);
@@ -595,10 +515,10 @@ function toFormData$1(obj, formData, options) {
595
515
  value = JSON.stringify(value);
596
516
  } else if (utils$1.isArray(value) && isFlatArray(value) || (utils$1.isFileList(value) || utils$1.endsWith(key, "[]")) && (arr = utils$1.toArray(value))) {
597
517
  key = removeBrackets(key);
598
- arr.forEach(function each(el, index2) {
518
+ arr.forEach(function each(el, index) {
599
519
  !(utils$1.isUndefined(el) || el === null) && formData.append(
600
520
  // eslint-disable-next-line no-nested-ternary
601
- indexes === true ? renderKey([key], index2, dots) : indexes === null ? key : key + "[]",
521
+ indexes === true ? renderKey([key], index, dots) : indexes === null ? key : key + "[]",
602
522
  convertValue(el)
603
523
  );
604
524
  });
@@ -829,11 +749,11 @@ function arrayToObject(arr) {
829
749
  return obj;
830
750
  }
831
751
  function formDataToJSON(formData) {
832
- function buildPath(path, value, target, index2) {
833
- let name = path[index2++];
752
+ function buildPath(path, value, target, index) {
753
+ let name = path[index++];
834
754
  if (name === "__proto__") return true;
835
755
  const isNumericKey = Number.isFinite(+name);
836
- const isLast = index2 >= path.length;
756
+ const isLast = index >= path.length;
837
757
  name = !name && utils$1.isArray(target) ? target.length : name;
838
758
  if (isLast) {
839
759
  if (utils$1.hasOwnProp(target, name)) {
@@ -846,7 +766,7 @@ function formDataToJSON(formData) {
846
766
  if (!target[name] || !utils$1.isObject(target[name])) {
847
767
  target[name] = [];
848
768
  }
849
- const result = buildPath(path, value, target[name], index2);
769
+ const result = buildPath(path, value, target[name], index);
850
770
  if (result && utils$1.isArray(target[name])) {
851
771
  target[name] = arrayToObject(target[name]);
852
772
  }
@@ -2307,9 +2227,9 @@ let CancelToken$1 = class CancelToken {
2307
2227
  if (!this._listeners) {
2308
2228
  return;
2309
2229
  }
2310
- const index2 = this._listeners.indexOf(listener);
2311
- if (index2 !== -1) {
2312
- this._listeners.splice(index2, 1);
2230
+ const index = this._listeners.indexOf(listener);
2231
+ if (index !== -1) {
2232
+ this._listeners.splice(index, 1);
2313
2233
  }
2314
2234
  }
2315
2235
  toAbortSignal() {
@@ -2465,10 +2385,10 @@ const JWT_TOKEN_NAME = "jwtToken";
2465
2385
  const getToken = () => {
2466
2386
  const jwtTokenCookie = document.cookie.split("; ").find((row) => row.startsWith(`${JWT_TOKEN_NAME}=`));
2467
2387
  const jwtToken = jwtTokenCookie ? jwtTokenCookie.split("=")[1] : "";
2468
- return jwtToken || localStorage.getItem(JWT_TOKEN_NAME) || sessionStorage.getItem(JWT_TOKEN_NAME) || "";
2388
+ const raw = jwtToken || localStorage.getItem(JWT_TOKEN_NAME) || sessionStorage.getItem(JWT_TOKEN_NAME) || "";
2389
+ return raw.replace(/^["']|["']$/g, "");
2469
2390
  };
2470
2391
  const createStrapiApiAxiosInstance = (baseUrl = null) => {
2471
- const token = getToken();
2472
2392
  if (baseUrl === null) {
2473
2393
  baseUrl = `${BASE_PLUGIN_PATH}`;
2474
2394
  }
@@ -2483,6 +2403,7 @@ const createStrapiApiAxiosInstance = (baseUrl = null) => {
2483
2403
  // Add this header to identify the request as initiated by the plugin
2484
2404
  "X-Localazy-Initiated-By": "strapi-plugin-localazy"
2485
2405
  });
2406
+ const token = getToken();
2486
2407
  if (token) {
2487
2408
  config.headers.set("Authorization", `Bearer ${token}`);
2488
2409
  }
@@ -2495,159 +2416,11 @@ const createStrapiApiAxiosInstance = (baseUrl = null) => {
2495
2416
  instance.interceptors.response.use(
2496
2417
  (response) => response,
2497
2418
  (error) => {
2498
- if (error.response?.status === 401) ;
2499
2419
  throw error;
2500
2420
  }
2501
2421
  );
2502
2422
  return instance;
2503
2423
  };
2504
- const BASE_PATH = "/user";
2505
- const strapiApiInstance = createStrapiApiAxiosInstance();
2506
- class LocalazyUserService {
2507
- static async getIdentity() {
2508
- try {
2509
- const result = await strapiApiInstance.get(`${BASE_PATH}`);
2510
- return result.data;
2511
- } catch (e) {
2512
- throw e;
2513
- }
2514
- }
2515
- static async updateIdentity(localazyIdentity2) {
2516
- try {
2517
- const result = await strapiApiInstance.put(`${BASE_PATH}`, localazyIdentity2);
2518
- return result.data;
2519
- } catch (e) {
2520
- throw e;
2521
- }
2522
- }
2523
- static async deleteIdentity() {
2524
- try {
2525
- const result = await strapiApiInstance.delete(`${BASE_PATH}`);
2526
- return result.data;
2527
- } catch (e) {
2528
- throw e;
2529
- }
2530
- }
2531
- }
2532
- const FetchIdentity = () => {
2533
- const { setIdentity, setIsFetchingIdentity } = useLocalazyIdentity();
2534
- React.useEffect(() => {
2535
- const fetchIdentity = async () => {
2536
- try {
2537
- setIsFetchingIdentity(true);
2538
- const fetchedIdentity = await LocalazyUserService.getIdentity();
2539
- setIdentity(fetchedIdentity || emptyIdentity);
2540
- } catch (error) {
2541
- console.error("Error fetching identity:", error);
2542
- } finally {
2543
- setIsFetchingIdentity(false);
2544
- }
2545
- };
2546
- fetchIdentity();
2547
- }, [setIdentity, setIsFetchingIdentity]);
2548
- return null;
2549
- };
2550
- const index = {
2551
- register(app) {
2552
- addMenuLink(app);
2553
- addSettingsSection(app);
2554
- addPlugin(app);
2555
- },
2556
- async registerTrads({ locales }) {
2557
- return Promise.all(
2558
- locales.map(async (locale) => {
2559
- try {
2560
- const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => Promise.resolve().then(() => require("./en-CRtsEFtl.js")), "./translations/fr.json": () => Promise.resolve().then(() => require("./fr-C8Qw4iPZ.js")) }), `./translations/${locale}.json`, 3);
2561
- return { data, locale };
2562
- } catch {
2563
- return { data: {}, locale };
2564
- }
2565
- })
2566
- );
2567
- }
2568
- };
2569
- const addMenuLink = (app) => {
2570
- app.addMenuLink({
2571
- to: `plugins/${PLUGIN_ID}/`,
2572
- icon: Localazy,
2573
- intlLabel: {
2574
- id: `${PLUGIN_ID}.name`,
2575
- defaultMessage: getTranslation("name")
2576
- },
2577
- Component: async () => {
2578
- const { App } = await Promise.resolve().then(() => require("./App-NRmSxuW3.js"));
2579
- const { LocalazyIdentityProvider: LocalazyIdentityProvider2 } = await Promise.resolve().then(() => localazyIdentity);
2580
- const WrappedApp = () => React__default.default.createElement(LocalazyIdentityProvider2, {
2581
- children: React__default.default.createElement(React__default.default.Fragment, {}, [
2582
- React__default.default.createElement(FetchIdentity, {}),
2583
- React__default.default.createElement(App, {})
2584
- ])
2585
- });
2586
- return WrappedApp;
2587
- }
2588
- });
2589
- };
2590
- const addSettingsSection = (app) => {
2591
- app.createSettingSection(
2592
- {
2593
- id: `${PLUGIN_ID}-settings`,
2594
- intlLabel: {
2595
- id: `${PLUGIN_ID}.localazy_settings`,
2596
- defaultMessage: getTranslation("localazy_settings")
2597
- }
2598
- },
2599
- [
2600
- // General
2601
- {
2602
- id: `${PLUGIN_ID}-settings-global`,
2603
- intlLabel: {
2604
- id: `${PLUGIN_ID}.localazy_settings`,
2605
- defaultMessage: getTranslation("localazy_settings")
2606
- },
2607
- to: `/settings/${PLUGIN_ID}/global-settings`,
2608
- Component: async () => {
2609
- const { GlobalSettings } = await Promise.resolve().then(() => require("./GlobalSettings-CRMPRA3Y.js"));
2610
- const { LocalazyIdentityProvider: LocalazyIdentityProvider2 } = await Promise.resolve().then(() => localazyIdentity);
2611
- const WrappedGlobalSettings = () => React__default.default.createElement(LocalazyIdentityProvider2, { children: React__default.default.createElement(GlobalSettings, {}) });
2612
- return WrappedGlobalSettings;
2613
- },
2614
- permissions: []
2615
- },
2616
- // Content Transfer Setup
2617
- {
2618
- id: `${PLUGIN_ID}-settings-content-transfer-setup`,
2619
- intlLabel: {
2620
- id: `${PLUGIN_ID}.content_transfer_setup`,
2621
- defaultMessage: getTranslation("content_transfer_setup")
2622
- },
2623
- to: `/settings/${PLUGIN_ID}/content-transfer-setup`,
2624
- Component: async () => {
2625
- const { ContentTransferSetup } = await Promise.resolve().then(() => require("./ContentTransferSetup-DGs8MZPj.js"));
2626
- const { LocalazyIdentityProvider: LocalazyIdentityProvider2 } = await Promise.resolve().then(() => localazyIdentity);
2627
- const WrappedContentTransferSetup = () => React__default.default.createElement(LocalazyIdentityProvider2, {
2628
- children: React__default.default.createElement(React__default.default.Fragment, {}, [
2629
- React__default.default.createElement(FetchIdentity, {}),
2630
- React__default.default.createElement(ContentTransferSetup, {})
2631
- ])
2632
- });
2633
- return WrappedContentTransferSetup;
2634
- },
2635
- permissions: []
2636
- }
2637
- ]
2638
- );
2639
- };
2640
- const addPlugin = (app) => {
2641
- app.registerPlugin({
2642
- id: PLUGIN_ID,
2643
- initializer: Initializer,
2644
- isReady: false,
2645
- name: PLUGIN_ID
2646
- });
2424
+ export {
2425
+ createStrapiApiAxiosInstance as c
2647
2426
  };
2648
- exports.LocalazyUserService = LocalazyUserService;
2649
- exports.PLUGIN_ID = PLUGIN_ID;
2650
- exports.createStrapiApiAxiosInstance = createStrapiApiAxiosInstance;
2651
- exports.emptyIdentity = emptyIdentity;
2652
- exports.index = index;
2653
- exports.useLocalazyIdentity = useLocalazyIdentity;
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ const React = require("react");
3
+ const initReactI18next = require("./initReactI18next-B0H8_DlW.js");
4
+ const warn = (i18n, code, msg, rest) => {
5
+ const args = [msg, {
6
+ code,
7
+ ...rest || {}
8
+ }];
9
+ if (i18n?.services?.logger?.forward) {
10
+ return i18n.services.logger.forward(args, "warn", "react-i18next::", true);
11
+ }
12
+ if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
13
+ if (i18n?.services?.logger?.warn) {
14
+ i18n.services.logger.warn(...args);
15
+ } else if (console?.warn) {
16
+ console.warn(...args);
17
+ }
18
+ };
19
+ const alreadyWarned = {};
20
+ const warnOnce = (i18n, code, msg, rest) => {
21
+ if (isString(msg) && alreadyWarned[msg]) return;
22
+ if (isString(msg)) alreadyWarned[msg] = /* @__PURE__ */ new Date();
23
+ warn(i18n, code, msg, rest);
24
+ };
25
+ const loadedClb = (i18n, cb) => () => {
26
+ if (i18n.isInitialized) {
27
+ cb();
28
+ } else {
29
+ const initialized = () => {
30
+ setTimeout(() => {
31
+ i18n.off("initialized", initialized);
32
+ }, 0);
33
+ cb();
34
+ };
35
+ i18n.on("initialized", initialized);
36
+ }
37
+ };
38
+ const loadNamespaces = (i18n, ns, cb) => {
39
+ i18n.loadNamespaces(ns, loadedClb(i18n, cb));
40
+ };
41
+ const loadLanguages = (i18n, lng, ns, cb) => {
42
+ if (isString(ns)) ns = [ns];
43
+ if (i18n.options.preload && i18n.options.preload.indexOf(lng) > -1) return loadNamespaces(i18n, ns, cb);
44
+ ns.forEach((n) => {
45
+ if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
46
+ });
47
+ i18n.loadLanguages(lng, loadedClb(i18n, cb));
48
+ };
49
+ const hasLoadedNamespace = (ns, i18n, options = {}) => {
50
+ if (!i18n.languages || !i18n.languages.length) {
51
+ warnOnce(i18n, "NO_LANGUAGES", "i18n.languages were undefined or empty", {
52
+ languages: i18n.languages
53
+ });
54
+ return true;
55
+ }
56
+ return i18n.hasLoadedNamespace(ns, {
57
+ lng: options.lng,
58
+ precheck: (i18nInstance, loadNotPending) => {
59
+ if (options.bindI18n?.indexOf("languageChanging") > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
60
+ }
61
+ });
62
+ };
63
+ const isString = (obj) => typeof obj === "string";
64
+ const isObject = (obj) => typeof obj === "object" && obj !== null;
65
+ const I18nContext = React.createContext();
66
+ class ReportNamespaces {
67
+ constructor() {
68
+ this.usedNamespaces = {};
69
+ }
70
+ addUsedNamespaces(namespaces) {
71
+ namespaces.forEach((ns) => {
72
+ if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
73
+ });
74
+ }
75
+ getUsedNamespaces() {
76
+ return Object.keys(this.usedNamespaces);
77
+ }
78
+ }
79
+ const usePrevious = (value, ignore) => {
80
+ const ref = React.useRef();
81
+ React.useEffect(() => {
82
+ ref.current = value;
83
+ }, [value, ignore]);
84
+ return ref.current;
85
+ };
86
+ const alwaysNewT = (i18n, language, namespace, keyPrefix) => i18n.getFixedT(language, namespace, keyPrefix);
87
+ const useMemoizedT = (i18n, language, namespace, keyPrefix) => React.useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
88
+ const useTranslation = (ns, props = {}) => {
89
+ const {
90
+ i18n: i18nFromProps
91
+ } = props;
92
+ const {
93
+ i18n: i18nFromContext,
94
+ defaultNS: defaultNSFromContext
95
+ } = React.useContext(I18nContext) || {};
96
+ const i18n = i18nFromProps || i18nFromContext || initReactI18next.getI18n();
97
+ if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
98
+ if (!i18n) {
99
+ warnOnce(i18n, "NO_I18NEXT_INSTANCE", "useTranslation: You will need to pass in an i18next instance by using initReactI18next");
100
+ const notReadyT = (k, optsOrDefaultValue) => {
101
+ if (isString(optsOrDefaultValue)) return optsOrDefaultValue;
102
+ if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
103
+ return Array.isArray(k) ? k[k.length - 1] : k;
104
+ };
105
+ const retNotReady = [notReadyT, {}, false];
106
+ retNotReady.t = notReadyT;
107
+ retNotReady.i18n = {};
108
+ retNotReady.ready = false;
109
+ return retNotReady;
110
+ }
111
+ if (i18n.options.react?.wait) warnOnce(i18n, "DEPRECATED_OPTION", "useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");
112
+ const i18nOptions = {
113
+ ...initReactI18next.getDefaults(),
114
+ ...i18n.options.react,
115
+ ...props
116
+ };
117
+ const {
118
+ useSuspense,
119
+ keyPrefix
120
+ } = i18nOptions;
121
+ let namespaces = ns || defaultNSFromContext || i18n.options?.defaultNS;
122
+ namespaces = isString(namespaces) ? [namespaces] : namespaces || ["translation"];
123
+ i18n.reportNamespaces.addUsedNamespaces?.(namespaces);
124
+ const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every((n) => hasLoadedNamespace(n, i18n, i18nOptions));
125
+ const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
126
+ const getT = () => memoGetT;
127
+ const getNewT = () => alwaysNewT(i18n, props.lng || null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
128
+ const [t, setT] = React.useState(getT);
129
+ let joinedNS = namespaces.join();
130
+ if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
131
+ const previousJoinedNS = usePrevious(joinedNS);
132
+ const isMounted = React.useRef(true);
133
+ React.useEffect(() => {
134
+ const {
135
+ bindI18n,
136
+ bindI18nStore
137
+ } = i18nOptions;
138
+ isMounted.current = true;
139
+ if (!ready && !useSuspense) {
140
+ if (props.lng) {
141
+ loadLanguages(i18n, props.lng, namespaces, () => {
142
+ if (isMounted.current) setT(getNewT);
143
+ });
144
+ } else {
145
+ loadNamespaces(i18n, namespaces, () => {
146
+ if (isMounted.current) setT(getNewT);
147
+ });
148
+ }
149
+ }
150
+ if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
151
+ setT(getNewT);
152
+ }
153
+ const boundReset = () => {
154
+ if (isMounted.current) setT(getNewT);
155
+ };
156
+ if (bindI18n) i18n?.on(bindI18n, boundReset);
157
+ if (bindI18nStore) i18n?.store.on(bindI18nStore, boundReset);
158
+ return () => {
159
+ isMounted.current = false;
160
+ if (i18n) bindI18n?.split(" ").forEach((e) => i18n.off(e, boundReset));
161
+ if (bindI18nStore && i18n) bindI18nStore.split(" ").forEach((e) => i18n.store.off(e, boundReset));
162
+ };
163
+ }, [i18n, joinedNS]);
164
+ React.useEffect(() => {
165
+ if (isMounted.current && ready) {
166
+ setT(getT);
167
+ }
168
+ }, [i18n, keyPrefix, ready]);
169
+ const ret = [t, i18n, ready];
170
+ ret.t = t;
171
+ ret.i18n = i18n;
172
+ ret.ready = ready;
173
+ if (ready) return ret;
174
+ if (!ready && !useSuspense) return ret;
175
+ throw new Promise((resolve) => {
176
+ if (props.lng) {
177
+ loadLanguages(i18n, props.lng, namespaces, () => resolve());
178
+ } else {
179
+ loadNamespaces(i18n, namespaces, () => resolve());
180
+ }
181
+ });
182
+ };
183
+ exports.I18nContext = I18nContext;
184
+ exports.isObject = isObject;
185
+ exports.isString = isString;
186
+ exports.useTranslation = useTranslation;
187
+ exports.warn = warn;
188
+ exports.warnOnce = warnOnce;
@@ -0,0 +1,189 @@
1
+ import { createContext, useContext, useCallback, useState, useRef, useEffect } from "react";
2
+ import { g as getI18n, a as getDefaults } from "./initReactI18next-MHHxeg_9.mjs";
3
+ const warn = (i18n, code, msg, rest) => {
4
+ const args = [msg, {
5
+ code,
6
+ ...rest || {}
7
+ }];
8
+ if (i18n?.services?.logger?.forward) {
9
+ return i18n.services.logger.forward(args, "warn", "react-i18next::", true);
10
+ }
11
+ if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
12
+ if (i18n?.services?.logger?.warn) {
13
+ i18n.services.logger.warn(...args);
14
+ } else if (console?.warn) {
15
+ console.warn(...args);
16
+ }
17
+ };
18
+ const alreadyWarned = {};
19
+ const warnOnce = (i18n, code, msg, rest) => {
20
+ if (isString(msg) && alreadyWarned[msg]) return;
21
+ if (isString(msg)) alreadyWarned[msg] = /* @__PURE__ */ new Date();
22
+ warn(i18n, code, msg, rest);
23
+ };
24
+ const loadedClb = (i18n, cb) => () => {
25
+ if (i18n.isInitialized) {
26
+ cb();
27
+ } else {
28
+ const initialized = () => {
29
+ setTimeout(() => {
30
+ i18n.off("initialized", initialized);
31
+ }, 0);
32
+ cb();
33
+ };
34
+ i18n.on("initialized", initialized);
35
+ }
36
+ };
37
+ const loadNamespaces = (i18n, ns, cb) => {
38
+ i18n.loadNamespaces(ns, loadedClb(i18n, cb));
39
+ };
40
+ const loadLanguages = (i18n, lng, ns, cb) => {
41
+ if (isString(ns)) ns = [ns];
42
+ if (i18n.options.preload && i18n.options.preload.indexOf(lng) > -1) return loadNamespaces(i18n, ns, cb);
43
+ ns.forEach((n) => {
44
+ if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
45
+ });
46
+ i18n.loadLanguages(lng, loadedClb(i18n, cb));
47
+ };
48
+ const hasLoadedNamespace = (ns, i18n, options = {}) => {
49
+ if (!i18n.languages || !i18n.languages.length) {
50
+ warnOnce(i18n, "NO_LANGUAGES", "i18n.languages were undefined or empty", {
51
+ languages: i18n.languages
52
+ });
53
+ return true;
54
+ }
55
+ return i18n.hasLoadedNamespace(ns, {
56
+ lng: options.lng,
57
+ precheck: (i18nInstance, loadNotPending) => {
58
+ if (options.bindI18n?.indexOf("languageChanging") > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
59
+ }
60
+ });
61
+ };
62
+ const isString = (obj) => typeof obj === "string";
63
+ const isObject = (obj) => typeof obj === "object" && obj !== null;
64
+ const I18nContext = createContext();
65
+ class ReportNamespaces {
66
+ constructor() {
67
+ this.usedNamespaces = {};
68
+ }
69
+ addUsedNamespaces(namespaces) {
70
+ namespaces.forEach((ns) => {
71
+ if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
72
+ });
73
+ }
74
+ getUsedNamespaces() {
75
+ return Object.keys(this.usedNamespaces);
76
+ }
77
+ }
78
+ const usePrevious = (value, ignore) => {
79
+ const ref = useRef();
80
+ useEffect(() => {
81
+ ref.current = value;
82
+ }, [value, ignore]);
83
+ return ref.current;
84
+ };
85
+ const alwaysNewT = (i18n, language, namespace, keyPrefix) => i18n.getFixedT(language, namespace, keyPrefix);
86
+ const useMemoizedT = (i18n, language, namespace, keyPrefix) => useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
87
+ const useTranslation = (ns, props = {}) => {
88
+ const {
89
+ i18n: i18nFromProps
90
+ } = props;
91
+ const {
92
+ i18n: i18nFromContext,
93
+ defaultNS: defaultNSFromContext
94
+ } = useContext(I18nContext) || {};
95
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
96
+ if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
97
+ if (!i18n) {
98
+ warnOnce(i18n, "NO_I18NEXT_INSTANCE", "useTranslation: You will need to pass in an i18next instance by using initReactI18next");
99
+ const notReadyT = (k, optsOrDefaultValue) => {
100
+ if (isString(optsOrDefaultValue)) return optsOrDefaultValue;
101
+ if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
102
+ return Array.isArray(k) ? k[k.length - 1] : k;
103
+ };
104
+ const retNotReady = [notReadyT, {}, false];
105
+ retNotReady.t = notReadyT;
106
+ retNotReady.i18n = {};
107
+ retNotReady.ready = false;
108
+ return retNotReady;
109
+ }
110
+ if (i18n.options.react?.wait) warnOnce(i18n, "DEPRECATED_OPTION", "useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");
111
+ const i18nOptions = {
112
+ ...getDefaults(),
113
+ ...i18n.options.react,
114
+ ...props
115
+ };
116
+ const {
117
+ useSuspense,
118
+ keyPrefix
119
+ } = i18nOptions;
120
+ let namespaces = ns || defaultNSFromContext || i18n.options?.defaultNS;
121
+ namespaces = isString(namespaces) ? [namespaces] : namespaces || ["translation"];
122
+ i18n.reportNamespaces.addUsedNamespaces?.(namespaces);
123
+ const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every((n) => hasLoadedNamespace(n, i18n, i18nOptions));
124
+ const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
125
+ const getT = () => memoGetT;
126
+ const getNewT = () => alwaysNewT(i18n, props.lng || null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
127
+ const [t, setT] = useState(getT);
128
+ let joinedNS = namespaces.join();
129
+ if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
130
+ const previousJoinedNS = usePrevious(joinedNS);
131
+ const isMounted = useRef(true);
132
+ useEffect(() => {
133
+ const {
134
+ bindI18n,
135
+ bindI18nStore
136
+ } = i18nOptions;
137
+ isMounted.current = true;
138
+ if (!ready && !useSuspense) {
139
+ if (props.lng) {
140
+ loadLanguages(i18n, props.lng, namespaces, () => {
141
+ if (isMounted.current) setT(getNewT);
142
+ });
143
+ } else {
144
+ loadNamespaces(i18n, namespaces, () => {
145
+ if (isMounted.current) setT(getNewT);
146
+ });
147
+ }
148
+ }
149
+ if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
150
+ setT(getNewT);
151
+ }
152
+ const boundReset = () => {
153
+ if (isMounted.current) setT(getNewT);
154
+ };
155
+ if (bindI18n) i18n?.on(bindI18n, boundReset);
156
+ if (bindI18nStore) i18n?.store.on(bindI18nStore, boundReset);
157
+ return () => {
158
+ isMounted.current = false;
159
+ if (i18n) bindI18n?.split(" ").forEach((e) => i18n.off(e, boundReset));
160
+ if (bindI18nStore && i18n) bindI18nStore.split(" ").forEach((e) => i18n.store.off(e, boundReset));
161
+ };
162
+ }, [i18n, joinedNS]);
163
+ useEffect(() => {
164
+ if (isMounted.current && ready) {
165
+ setT(getT);
166
+ }
167
+ }, [i18n, keyPrefix, ready]);
168
+ const ret = [t, i18n, ready];
169
+ ret.t = t;
170
+ ret.i18n = i18n;
171
+ ret.ready = ready;
172
+ if (ready) return ret;
173
+ if (!ready && !useSuspense) return ret;
174
+ throw new Promise((resolve) => {
175
+ if (props.lng) {
176
+ loadLanguages(i18n, props.lng, namespaces, () => resolve());
177
+ } else {
178
+ loadNamespaces(i18n, namespaces, () => resolve());
179
+ }
180
+ });
181
+ };
182
+ export {
183
+ I18nContext as I,
184
+ warn as a,
185
+ isObject as b,
186
+ isString as i,
187
+ useTranslation as u,
188
+ warnOnce as w
189
+ };