@fctc/sme-widget-ui 1.8.3 → 1.8.4

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.d.mts CHANGED
@@ -3,5 +3,18 @@ export { AddIcon, ArchiveIcon, ArrowDownIcon, ArrowRightIcon, AttachIcon, BackIc
3
3
  export { IInputFieldProps, LoginData, LoginProps, Provider, ValuePropsType, loginSchema } from './types.mjs';
4
4
  export { ActiveBadgeField, AvatarField, BinaryField, ButtonBadgeField, ButtonField, ButtonSelectFiles, CharField, CheckboxField, ColorField, ColorWrapper, CopyLinkButtonField, DateField, DateOptionField, DownLoadBinaryField, DownloadFileField, DropdownField, EmptyTable, FeeField, FileUploadField, FloatField, FloatTimeField, HtmlField, IActiveBadgeProps, IAvatarProps, IBinaryFieldProps, IButtonBadgeProps, IButtonProps, ICharFieldProps, IColorFieldProps, IColorWrapperProps, ICopyLinkButtonProps, IDateFieldProps, IDownLoadBinary, IDownloadFileProps, IDurationProps, IFileUploadProps, IMany2ManyTagsProps, IMonetaryProps, IOptionProps, IPaginationProps, IPriorityFieldProps, IRadioGroupProps, IRatingStarProps, ISelectDropdownProps, IStatusDropdownFieldProps, ImageField, InfomationField, IntegerField, LayerLoading, LoadingSmall, Login, Many2ManyField, Many2ManyProps, Many2ManyTagField, Many2OneField, Many2OneProps, ModalConfirm, ModalDetail, ModalLayer, MonetaryField, PaginationView, PaidBadgedField, PriorityField, RadioGroupField, RatingStarField, RemainingDaysField, RenderFiles, Row, Search, SelectDropdownField, StatusBarOptionField, StatusDropdownField, StatusbarDurationField, TDropdownSelectorProps, TableBody, TableFilter, TableFooter, TableGroup, TableHead, TextAreaField, ToggleButtonField, VideoPlayer, usePagination } from './widgets.mjs';
5
5
  export { COLORS, DOTS, SearchType, checkIsImageLink, convertFloatToTime, convertTimeToFloat, formatFileSize, formatFloatNumber, formatNumberOnly, getPasswordMessage, isBase64Image, isObjectEmpty, parseFormattedNumber, range, useFormatDate, validateAndParseDate, validateInput } from './utils.mjs';
6
- import 'react';
6
+ import { ReactNode } from 'react';
7
7
  import 'zod';
8
+
9
+ type I18nContextType = {
10
+ lang: string;
11
+ t: (key: string, options?: any) => string;
12
+ changeLanguage: any;
13
+ };
14
+ declare const I18nProvider: ({ children, lang, }: {
15
+ children: ReactNode;
16
+ lang: string;
17
+ }) => JSX.Element;
18
+ declare const useI18n: () => I18nContextType;
19
+
20
+ export { I18nProvider, useI18n };
package/dist/index.d.ts CHANGED
@@ -3,5 +3,18 @@ export { AddIcon, ArchiveIcon, ArrowDownIcon, ArrowRightIcon, AttachIcon, BackIc
3
3
  export { IInputFieldProps, LoginData, LoginProps, Provider, ValuePropsType, loginSchema } from './types.js';
4
4
  export { ActiveBadgeField, AvatarField, BinaryField, ButtonBadgeField, ButtonField, ButtonSelectFiles, CharField, CheckboxField, ColorField, ColorWrapper, CopyLinkButtonField, DateField, DateOptionField, DownLoadBinaryField, DownloadFileField, DropdownField, EmptyTable, FeeField, FileUploadField, FloatField, FloatTimeField, HtmlField, IActiveBadgeProps, IAvatarProps, IBinaryFieldProps, IButtonBadgeProps, IButtonProps, ICharFieldProps, IColorFieldProps, IColorWrapperProps, ICopyLinkButtonProps, IDateFieldProps, IDownLoadBinary, IDownloadFileProps, IDurationProps, IFileUploadProps, IMany2ManyTagsProps, IMonetaryProps, IOptionProps, IPaginationProps, IPriorityFieldProps, IRadioGroupProps, IRatingStarProps, ISelectDropdownProps, IStatusDropdownFieldProps, ImageField, InfomationField, IntegerField, LayerLoading, LoadingSmall, Login, Many2ManyField, Many2ManyProps, Many2ManyTagField, Many2OneField, Many2OneProps, ModalConfirm, ModalDetail, ModalLayer, MonetaryField, PaginationView, PaidBadgedField, PriorityField, RadioGroupField, RatingStarField, RemainingDaysField, RenderFiles, Row, Search, SelectDropdownField, StatusBarOptionField, StatusDropdownField, StatusbarDurationField, TDropdownSelectorProps, TableBody, TableFilter, TableFooter, TableGroup, TableHead, TextAreaField, ToggleButtonField, VideoPlayer, usePagination } from './widgets.js';
5
5
  export { COLORS, DOTS, SearchType, checkIsImageLink, convertFloatToTime, convertTimeToFloat, formatFileSize, formatFloatNumber, formatNumberOnly, getPasswordMessage, isBase64Image, isObjectEmpty, parseFormattedNumber, range, useFormatDate, validateAndParseDate, validateInput } from './utils.js';
6
- import 'react';
6
+ import { ReactNode } from 'react';
7
7
  import 'zod';
8
+
9
+ type I18nContextType = {
10
+ lang: string;
11
+ t: (key: string, options?: any) => string;
12
+ changeLanguage: any;
13
+ };
14
+ declare const I18nProvider: ({ children, lang, }: {
15
+ children: ReactNode;
16
+ lang: string;
17
+ }) => JSX.Element;
18
+ declare const useI18n: () => I18nContextType;
19
+
20
+ export { I18nProvider, useI18n };
package/dist/index.js CHANGED
@@ -4983,6 +4983,7 @@ __export(index_exports, {
4983
4983
  GoogleIcon: () => GoogleIcon,
4984
4984
  GroupByIcon: () => GroupByIcon,
4985
4985
  HtmlField: () => HtmlField,
4986
+ I18nProvider: () => I18nProvider,
4986
4987
  ImageField: () => ImageField,
4987
4988
  InfomationField: () => InfomationField,
4988
4989
  IntegerField: () => IntegerField,
@@ -5049,6 +5050,7 @@ __export(index_exports, {
5049
5050
  useClickOutside: () => useClickOutside,
5050
5051
  useFileInfo: () => useFileInfo,
5051
5052
  useFormatDate: () => useFormatDate,
5053
+ useI18n: () => useI18n,
5052
5054
  usePagination: () => usePagination,
5053
5055
  validateAndParseDate: () => validateAndParseDate,
5054
5056
  validateInput: () => validateInput
@@ -7080,6 +7082,69 @@ var import_react3 = require("react");
7080
7082
  // node_modules/html-parse-stringify/dist/html-parse-stringify.module.js
7081
7083
  var import_void_elements = __toESM(require_void_elements());
7082
7084
 
7085
+ // node_modules/react-i18next/dist/es/utils.js
7086
+ var warn = (i18n, code, msg, rest) => {
7087
+ const args = [msg, {
7088
+ code,
7089
+ ...rest || {}
7090
+ }];
7091
+ if (i18n?.services?.logger?.forward) {
7092
+ return i18n.services.logger.forward(args, "warn", "react-i18next::", true);
7093
+ }
7094
+ if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
7095
+ if (i18n?.services?.logger?.warn) {
7096
+ i18n.services.logger.warn(...args);
7097
+ } else if (console?.warn) {
7098
+ console.warn(...args);
7099
+ }
7100
+ };
7101
+ var alreadyWarned = {};
7102
+ var warnOnce = (i18n, code, msg, rest) => {
7103
+ if (isString(msg) && alreadyWarned[msg]) return;
7104
+ if (isString(msg)) alreadyWarned[msg] = /* @__PURE__ */ new Date();
7105
+ warn(i18n, code, msg, rest);
7106
+ };
7107
+ var loadedClb = (i18n, cb) => () => {
7108
+ if (i18n.isInitialized) {
7109
+ cb();
7110
+ } else {
7111
+ const initialized = () => {
7112
+ setTimeout(() => {
7113
+ i18n.off("initialized", initialized);
7114
+ }, 0);
7115
+ cb();
7116
+ };
7117
+ i18n.on("initialized", initialized);
7118
+ }
7119
+ };
7120
+ var loadNamespaces = (i18n, ns, cb) => {
7121
+ i18n.loadNamespaces(ns, loadedClb(i18n, cb));
7122
+ };
7123
+ var loadLanguages = (i18n, lng, ns, cb) => {
7124
+ if (isString(ns)) ns = [ns];
7125
+ if (i18n.options.preload && i18n.options.preload.indexOf(lng) > -1) return loadNamespaces(i18n, ns, cb);
7126
+ ns.forEach((n4) => {
7127
+ if (i18n.options.ns.indexOf(n4) < 0) i18n.options.ns.push(n4);
7128
+ });
7129
+ i18n.loadLanguages(lng, loadedClb(i18n, cb));
7130
+ };
7131
+ var hasLoadedNamespace = (ns, i18n, options2 = {}) => {
7132
+ if (!i18n.languages || !i18n.languages.length) {
7133
+ warnOnce(i18n, "NO_LANGUAGES", "i18n.languages were undefined or empty", {
7134
+ languages: i18n.languages
7135
+ });
7136
+ return true;
7137
+ }
7138
+ return i18n.hasLoadedNamespace(ns, {
7139
+ lng: options2.lng,
7140
+ precheck: (i18nInstance2, loadNotPending) => {
7141
+ if (options2.bindI18n && options2.bindI18n.indexOf("languageChanging") > -1 && i18nInstance2.services.backendConnector.backend && i18nInstance2.isLanguageChangingTo && !loadNotPending(i18nInstance2.isLanguageChangingTo, ns)) return false;
7142
+ }
7143
+ });
7144
+ };
7145
+ var isString = (obj) => typeof obj === "string";
7146
+ var isObject = (obj) => typeof obj === "object" && obj !== null;
7147
+
7083
7148
  // node_modules/react-i18next/dist/es/unescape.js
7084
7149
  var matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
7085
7150
  var htmlEntities = {
@@ -7124,12 +7189,14 @@ var setDefaults = (options2 = {}) => {
7124
7189
  ...options2
7125
7190
  };
7126
7191
  };
7192
+ var getDefaults = () => defaultOptions;
7127
7193
 
7128
7194
  // node_modules/react-i18next/dist/es/i18nInstance.js
7129
7195
  var i18nInstance;
7130
7196
  var setI18n = (instance2) => {
7131
7197
  i18nInstance = instance2;
7132
7198
  };
7199
+ var getI18n = () => i18nInstance;
7133
7200
 
7134
7201
  // node_modules/react-i18next/dist/es/context.js
7135
7202
  var import_react4 = require("react");
@@ -7145,15 +7212,145 @@ var initReactI18next = {
7145
7212
 
7146
7213
  // node_modules/react-i18next/dist/es/context.js
7147
7214
  var I18nContext = (0, import_react4.createContext)();
7215
+ var ReportNamespaces = class {
7216
+ constructor() {
7217
+ this.usedNamespaces = {};
7218
+ }
7219
+ addUsedNamespaces(namespaces) {
7220
+ namespaces.forEach((ns) => {
7221
+ if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
7222
+ });
7223
+ }
7224
+ getUsedNamespaces() {
7225
+ return Object.keys(this.usedNamespaces);
7226
+ }
7227
+ };
7148
7228
 
7149
7229
  // node_modules/react-i18next/dist/es/useTranslation.js
7150
7230
  var import_react6 = require("react");
7231
+ var usePrevious = (value, ignore) => {
7232
+ const ref = (0, import_react6.useRef)();
7233
+ (0, import_react6.useEffect)(() => {
7234
+ ref.current = ignore ? ref.current : value;
7235
+ }, [value, ignore]);
7236
+ return ref.current;
7237
+ };
7238
+ var alwaysNewT = (i18n, language, namespace, keyPrefix) => i18n.getFixedT(language, namespace, keyPrefix);
7239
+ var useMemoizedT = (i18n, language, namespace, keyPrefix) => (0, import_react6.useCallback)(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
7240
+ var useTranslation = (ns, props = {}) => {
7241
+ const {
7242
+ i18n: i18nFromProps
7243
+ } = props;
7244
+ const {
7245
+ i18n: i18nFromContext,
7246
+ defaultNS: defaultNSFromContext
7247
+ } = (0, import_react6.useContext)(I18nContext) || {};
7248
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
7249
+ if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
7250
+ if (!i18n) {
7251
+ warnOnce(i18n, "NO_I18NEXT_INSTANCE", "useTranslation: You will need to pass in an i18next instance by using initReactI18next");
7252
+ const notReadyT = (k2, optsOrDefaultValue) => {
7253
+ if (isString(optsOrDefaultValue)) return optsOrDefaultValue;
7254
+ if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
7255
+ return Array.isArray(k2) ? k2[k2.length - 1] : k2;
7256
+ };
7257
+ const retNotReady = [notReadyT, {}, false];
7258
+ retNotReady.t = notReadyT;
7259
+ retNotReady.i18n = {};
7260
+ retNotReady.ready = false;
7261
+ return retNotReady;
7262
+ }
7263
+ 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.");
7264
+ const i18nOptions = {
7265
+ ...getDefaults(),
7266
+ ...i18n.options.react,
7267
+ ...props
7268
+ };
7269
+ const {
7270
+ useSuspense,
7271
+ keyPrefix
7272
+ } = i18nOptions;
7273
+ let namespaces = ns || defaultNSFromContext || i18n.options?.defaultNS;
7274
+ namespaces = isString(namespaces) ? [namespaces] : namespaces || ["translation"];
7275
+ i18n.reportNamespaces.addUsedNamespaces?.(namespaces);
7276
+ const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every((n4) => hasLoadedNamespace(n4, i18n, i18nOptions));
7277
+ const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
7278
+ const getT = () => memoGetT;
7279
+ const getNewT = () => alwaysNewT(i18n, props.lng || null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
7280
+ const [t3, setT] = (0, import_react6.useState)(getT);
7281
+ let joinedNS = namespaces.join();
7282
+ if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
7283
+ const previousJoinedNS = usePrevious(joinedNS);
7284
+ const isMounted = (0, import_react6.useRef)(true);
7285
+ (0, import_react6.useEffect)(() => {
7286
+ const {
7287
+ bindI18n,
7288
+ bindI18nStore
7289
+ } = i18nOptions;
7290
+ isMounted.current = true;
7291
+ if (!ready && !useSuspense) {
7292
+ if (props.lng) {
7293
+ loadLanguages(i18n, props.lng, namespaces, () => {
7294
+ if (isMounted.current) setT(getNewT);
7295
+ });
7296
+ } else {
7297
+ loadNamespaces(i18n, namespaces, () => {
7298
+ if (isMounted.current) setT(getNewT);
7299
+ });
7300
+ }
7301
+ }
7302
+ if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
7303
+ setT(getNewT);
7304
+ }
7305
+ const boundReset = () => {
7306
+ if (isMounted.current) setT(getNewT);
7307
+ };
7308
+ if (bindI18n) i18n?.on(bindI18n, boundReset);
7309
+ if (bindI18nStore) i18n?.store.on(bindI18nStore, boundReset);
7310
+ return () => {
7311
+ isMounted.current = false;
7312
+ if (i18n && bindI18n) bindI18n?.split(" ").forEach((e3) => i18n.off(e3, boundReset));
7313
+ if (bindI18nStore && i18n) bindI18nStore.split(" ").forEach((e3) => i18n.store.off(e3, boundReset));
7314
+ };
7315
+ }, [i18n, joinedNS]);
7316
+ (0, import_react6.useEffect)(() => {
7317
+ if (isMounted.current && ready) {
7318
+ setT(getT);
7319
+ }
7320
+ }, [i18n, keyPrefix, ready]);
7321
+ const ret = [t3, i18n, ready];
7322
+ ret.t = t3;
7323
+ ret.i18n = i18n;
7324
+ ret.ready = ready;
7325
+ if (ready) return ret;
7326
+ if (!ready && !useSuspense) return ret;
7327
+ throw new Promise((resolve) => {
7328
+ if (props.lng) {
7329
+ loadLanguages(i18n, props.lng, namespaces, () => resolve());
7330
+ } else {
7331
+ loadNamespaces(i18n, namespaces, () => resolve());
7332
+ }
7333
+ });
7334
+ };
7151
7335
 
7152
7336
  // node_modules/react-i18next/dist/es/withTranslation.js
7153
7337
  var import_react7 = require("react");
7154
7338
 
7155
7339
  // node_modules/react-i18next/dist/es/I18nextProvider.js
7156
7340
  var import_react8 = require("react");
7341
+ function I18nextProvider({
7342
+ i18n,
7343
+ defaultNS,
7344
+ children
7345
+ }) {
7346
+ const value = (0, import_react8.useMemo)(() => ({
7347
+ i18n,
7348
+ defaultNS
7349
+ }), [i18n, defaultNS]);
7350
+ return (0, import_react8.createElement)(I18nContext.Provider, {
7351
+ value
7352
+ }, children);
7353
+ }
7157
7354
 
7158
7355
  // node_modules/react-i18next/dist/es/withSSR.js
7159
7356
  var import_react10 = require("react");
@@ -9892,6 +10089,28 @@ var i18n_default = instance;
9892
10089
  // src/provider/index.tsx
9893
10090
  var import_jsx_runtime38 = require("react/jsx-runtime");
9894
10091
  var I18nContext2 = (0, import_react11.createContext)(null);
10092
+ var I18nProvider = ({
10093
+ children,
10094
+ lang
10095
+ }) => {
10096
+ (0, import_react11.useEffect)(() => {
10097
+ if (lang) {
10098
+ i18n_default.changeLanguage(lang);
10099
+ }
10100
+ }, [lang]);
10101
+ const { t: t3 } = useTranslation();
10102
+ return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
10103
+ I18nContext2.Provider,
10104
+ {
10105
+ value: {
10106
+ lang: i18n_default.language,
10107
+ t: t3,
10108
+ changeLanguage: i18n_default.changeLanguage
10109
+ },
10110
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(I18nextProvider, { i18n: i18n_default, children })
10111
+ }
10112
+ );
10113
+ };
9895
10114
  var useI18n = () => {
9896
10115
  const context = (0, import_react11.useContext)(I18nContext2);
9897
10116
  if (!context) {
@@ -33972,6 +34191,7 @@ var DateOptionField = (props) => {
33972
34191
  GoogleIcon,
33973
34192
  GroupByIcon,
33974
34193
  HtmlField,
34194
+ I18nProvider,
33975
34195
  ImageField,
33976
34196
  InfomationField,
33977
34197
  IntegerField,
@@ -34038,6 +34258,7 @@ var DateOptionField = (props) => {
34038
34258
  useClickOutside,
34039
34259
  useFileInfo,
34040
34260
  useFormatDate,
34261
+ useI18n,
34041
34262
  usePagination,
34042
34263
  validateAndParseDate,
34043
34264
  validateInput
package/dist/index.mjs CHANGED
@@ -6960,6 +6960,69 @@ import { Fragment, isValidElement, cloneElement, createElement, Children } from
6960
6960
  // node_modules/html-parse-stringify/dist/html-parse-stringify.module.js
6961
6961
  var import_void_elements = __toESM(require_void_elements());
6962
6962
 
6963
+ // node_modules/react-i18next/dist/es/utils.js
6964
+ var warn = (i18n, code, msg, rest) => {
6965
+ const args = [msg, {
6966
+ code,
6967
+ ...rest || {}
6968
+ }];
6969
+ if (i18n?.services?.logger?.forward) {
6970
+ return i18n.services.logger.forward(args, "warn", "react-i18next::", true);
6971
+ }
6972
+ if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
6973
+ if (i18n?.services?.logger?.warn) {
6974
+ i18n.services.logger.warn(...args);
6975
+ } else if (console?.warn) {
6976
+ console.warn(...args);
6977
+ }
6978
+ };
6979
+ var alreadyWarned = {};
6980
+ var warnOnce = (i18n, code, msg, rest) => {
6981
+ if (isString(msg) && alreadyWarned[msg]) return;
6982
+ if (isString(msg)) alreadyWarned[msg] = /* @__PURE__ */ new Date();
6983
+ warn(i18n, code, msg, rest);
6984
+ };
6985
+ var loadedClb = (i18n, cb) => () => {
6986
+ if (i18n.isInitialized) {
6987
+ cb();
6988
+ } else {
6989
+ const initialized = () => {
6990
+ setTimeout(() => {
6991
+ i18n.off("initialized", initialized);
6992
+ }, 0);
6993
+ cb();
6994
+ };
6995
+ i18n.on("initialized", initialized);
6996
+ }
6997
+ };
6998
+ var loadNamespaces = (i18n, ns, cb) => {
6999
+ i18n.loadNamespaces(ns, loadedClb(i18n, cb));
7000
+ };
7001
+ var loadLanguages = (i18n, lng, ns, cb) => {
7002
+ if (isString(ns)) ns = [ns];
7003
+ if (i18n.options.preload && i18n.options.preload.indexOf(lng) > -1) return loadNamespaces(i18n, ns, cb);
7004
+ ns.forEach((n4) => {
7005
+ if (i18n.options.ns.indexOf(n4) < 0) i18n.options.ns.push(n4);
7006
+ });
7007
+ i18n.loadLanguages(lng, loadedClb(i18n, cb));
7008
+ };
7009
+ var hasLoadedNamespace = (ns, i18n, options2 = {}) => {
7010
+ if (!i18n.languages || !i18n.languages.length) {
7011
+ warnOnce(i18n, "NO_LANGUAGES", "i18n.languages were undefined or empty", {
7012
+ languages: i18n.languages
7013
+ });
7014
+ return true;
7015
+ }
7016
+ return i18n.hasLoadedNamespace(ns, {
7017
+ lng: options2.lng,
7018
+ precheck: (i18nInstance2, loadNotPending) => {
7019
+ if (options2.bindI18n && options2.bindI18n.indexOf("languageChanging") > -1 && i18nInstance2.services.backendConnector.backend && i18nInstance2.isLanguageChangingTo && !loadNotPending(i18nInstance2.isLanguageChangingTo, ns)) return false;
7020
+ }
7021
+ });
7022
+ };
7023
+ var isString = (obj) => typeof obj === "string";
7024
+ var isObject = (obj) => typeof obj === "object" && obj !== null;
7025
+
6963
7026
  // node_modules/react-i18next/dist/es/unescape.js
6964
7027
  var matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
6965
7028
  var htmlEntities = {
@@ -7004,12 +7067,14 @@ var setDefaults = (options2 = {}) => {
7004
7067
  ...options2
7005
7068
  };
7006
7069
  };
7070
+ var getDefaults = () => defaultOptions;
7007
7071
 
7008
7072
  // node_modules/react-i18next/dist/es/i18nInstance.js
7009
7073
  var i18nInstance;
7010
7074
  var setI18n = (instance2) => {
7011
7075
  i18nInstance = instance2;
7012
7076
  };
7077
+ var getI18n = () => i18nInstance;
7013
7078
 
7014
7079
  // node_modules/react-i18next/dist/es/context.js
7015
7080
  import { createContext } from "react";
@@ -7025,15 +7090,145 @@ var initReactI18next = {
7025
7090
 
7026
7091
  // node_modules/react-i18next/dist/es/context.js
7027
7092
  var I18nContext = createContext();
7093
+ var ReportNamespaces = class {
7094
+ constructor() {
7095
+ this.usedNamespaces = {};
7096
+ }
7097
+ addUsedNamespaces(namespaces) {
7098
+ namespaces.forEach((ns) => {
7099
+ if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
7100
+ });
7101
+ }
7102
+ getUsedNamespaces() {
7103
+ return Object.keys(this.usedNamespaces);
7104
+ }
7105
+ };
7028
7106
 
7029
7107
  // node_modules/react-i18next/dist/es/useTranslation.js
7030
7108
  import { useState as useState2, useEffect as useEffect3, useContext as useContext2, useRef as useRef3, useCallback } from "react";
7109
+ var usePrevious = (value, ignore) => {
7110
+ const ref = useRef3();
7111
+ useEffect3(() => {
7112
+ ref.current = ignore ? ref.current : value;
7113
+ }, [value, ignore]);
7114
+ return ref.current;
7115
+ };
7116
+ var alwaysNewT = (i18n, language, namespace, keyPrefix) => i18n.getFixedT(language, namespace, keyPrefix);
7117
+ var useMemoizedT = (i18n, language, namespace, keyPrefix) => useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
7118
+ var useTranslation = (ns, props = {}) => {
7119
+ const {
7120
+ i18n: i18nFromProps
7121
+ } = props;
7122
+ const {
7123
+ i18n: i18nFromContext,
7124
+ defaultNS: defaultNSFromContext
7125
+ } = useContext2(I18nContext) || {};
7126
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
7127
+ if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
7128
+ if (!i18n) {
7129
+ warnOnce(i18n, "NO_I18NEXT_INSTANCE", "useTranslation: You will need to pass in an i18next instance by using initReactI18next");
7130
+ const notReadyT = (k2, optsOrDefaultValue) => {
7131
+ if (isString(optsOrDefaultValue)) return optsOrDefaultValue;
7132
+ if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
7133
+ return Array.isArray(k2) ? k2[k2.length - 1] : k2;
7134
+ };
7135
+ const retNotReady = [notReadyT, {}, false];
7136
+ retNotReady.t = notReadyT;
7137
+ retNotReady.i18n = {};
7138
+ retNotReady.ready = false;
7139
+ return retNotReady;
7140
+ }
7141
+ 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.");
7142
+ const i18nOptions = {
7143
+ ...getDefaults(),
7144
+ ...i18n.options.react,
7145
+ ...props
7146
+ };
7147
+ const {
7148
+ useSuspense,
7149
+ keyPrefix
7150
+ } = i18nOptions;
7151
+ let namespaces = ns || defaultNSFromContext || i18n.options?.defaultNS;
7152
+ namespaces = isString(namespaces) ? [namespaces] : namespaces || ["translation"];
7153
+ i18n.reportNamespaces.addUsedNamespaces?.(namespaces);
7154
+ const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every((n4) => hasLoadedNamespace(n4, i18n, i18nOptions));
7155
+ const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
7156
+ const getT = () => memoGetT;
7157
+ const getNewT = () => alwaysNewT(i18n, props.lng || null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
7158
+ const [t3, setT] = useState2(getT);
7159
+ let joinedNS = namespaces.join();
7160
+ if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
7161
+ const previousJoinedNS = usePrevious(joinedNS);
7162
+ const isMounted = useRef3(true);
7163
+ useEffect3(() => {
7164
+ const {
7165
+ bindI18n,
7166
+ bindI18nStore
7167
+ } = i18nOptions;
7168
+ isMounted.current = true;
7169
+ if (!ready && !useSuspense) {
7170
+ if (props.lng) {
7171
+ loadLanguages(i18n, props.lng, namespaces, () => {
7172
+ if (isMounted.current) setT(getNewT);
7173
+ });
7174
+ } else {
7175
+ loadNamespaces(i18n, namespaces, () => {
7176
+ if (isMounted.current) setT(getNewT);
7177
+ });
7178
+ }
7179
+ }
7180
+ if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
7181
+ setT(getNewT);
7182
+ }
7183
+ const boundReset = () => {
7184
+ if (isMounted.current) setT(getNewT);
7185
+ };
7186
+ if (bindI18n) i18n?.on(bindI18n, boundReset);
7187
+ if (bindI18nStore) i18n?.store.on(bindI18nStore, boundReset);
7188
+ return () => {
7189
+ isMounted.current = false;
7190
+ if (i18n && bindI18n) bindI18n?.split(" ").forEach((e3) => i18n.off(e3, boundReset));
7191
+ if (bindI18nStore && i18n) bindI18nStore.split(" ").forEach((e3) => i18n.store.off(e3, boundReset));
7192
+ };
7193
+ }, [i18n, joinedNS]);
7194
+ useEffect3(() => {
7195
+ if (isMounted.current && ready) {
7196
+ setT(getT);
7197
+ }
7198
+ }, [i18n, keyPrefix, ready]);
7199
+ const ret = [t3, i18n, ready];
7200
+ ret.t = t3;
7201
+ ret.i18n = i18n;
7202
+ ret.ready = ready;
7203
+ if (ready) return ret;
7204
+ if (!ready && !useSuspense) return ret;
7205
+ throw new Promise((resolve) => {
7206
+ if (props.lng) {
7207
+ loadLanguages(i18n, props.lng, namespaces, () => resolve());
7208
+ } else {
7209
+ loadNamespaces(i18n, namespaces, () => resolve());
7210
+ }
7211
+ });
7212
+ };
7031
7213
 
7032
7214
  // node_modules/react-i18next/dist/es/withTranslation.js
7033
7215
  import { createElement as createElement2, forwardRef as forwardRefReact } from "react";
7034
7216
 
7035
7217
  // node_modules/react-i18next/dist/es/I18nextProvider.js
7036
7218
  import { createElement as createElement3, useMemo } from "react";
7219
+ function I18nextProvider({
7220
+ i18n,
7221
+ defaultNS,
7222
+ children
7223
+ }) {
7224
+ const value = useMemo(() => ({
7225
+ i18n,
7226
+ defaultNS
7227
+ }), [i18n, defaultNS]);
7228
+ return createElement3(I18nContext.Provider, {
7229
+ value
7230
+ }, children);
7231
+ }
7037
7232
 
7038
7233
  // node_modules/react-i18next/dist/es/withSSR.js
7039
7234
  import { createElement as createElement4 } from "react";
@@ -9772,6 +9967,28 @@ var i18n_default = instance;
9772
9967
  // src/provider/index.tsx
9773
9968
  import { jsx as jsx38 } from "react/jsx-runtime";
9774
9969
  var I18nContext2 = createContext2(null);
9970
+ var I18nProvider = ({
9971
+ children,
9972
+ lang
9973
+ }) => {
9974
+ useEffect4(() => {
9975
+ if (lang) {
9976
+ i18n_default.changeLanguage(lang);
9977
+ }
9978
+ }, [lang]);
9979
+ const { t: t3 } = useTranslation();
9980
+ return /* @__PURE__ */ jsx38(
9981
+ I18nContext2.Provider,
9982
+ {
9983
+ value: {
9984
+ lang: i18n_default.language,
9985
+ t: t3,
9986
+ changeLanguage: i18n_default.changeLanguage
9987
+ },
9988
+ children: /* @__PURE__ */ jsx38(I18nextProvider, { i18n: i18n_default, children })
9989
+ }
9990
+ );
9991
+ };
9775
9992
  var useI18n = () => {
9776
9993
  const context = useContext4(I18nContext2);
9777
9994
  if (!context) {
@@ -33851,6 +34068,7 @@ export {
33851
34068
  GoogleIcon,
33852
34069
  GroupByIcon,
33853
34070
  HtmlField,
34071
+ I18nProvider,
33854
34072
  ImageField,
33855
34073
  InfomationField,
33856
34074
  IntegerField,
@@ -33917,6 +34135,7 @@ export {
33917
34135
  useClickOutside,
33918
34136
  useFileInfo,
33919
34137
  useFormatDate,
34138
+ useI18n,
33920
34139
  usePagination,
33921
34140
  validateAndParseDate,
33922
34141
  validateInput
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fctc/sme-widget-ui",
3
- "version": "1.8.3",
3
+ "version": "1.8.4",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",