@variousjs/various 5.2.0 → 5.3.0

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.dev.js CHANGED
@@ -47,7 +47,10 @@ __webpack_require__.r(__webpack_exports__);
47
47
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
48
48
  /* harmony export */ BASE_DEPENDENCIES: function() { return /* binding */ BASE_DEPENDENCIES; },
49
49
  /* harmony export */ CONFIG_KEY: function() { return /* binding */ CONFIG_KEY; },
50
+ /* harmony export */ DEFAULT_LOCALE: function() { return /* binding */ DEFAULT_LOCALE; },
50
51
  /* harmony export */ DEPENDENCIES_KEY: function() { return /* binding */ DEPENDENCIES_KEY; },
52
+ /* harmony export */ I18NActions: function() { return /* binding */ I18NActions; },
53
+ /* harmony export */ LOCALE_KEY: function() { return /* binding */ LOCALE_KEY; },
51
54
  /* harmony export */ MESSAGE_KEY: function() { return /* binding */ MESSAGE_KEY; },
52
55
  /* harmony export */ MOUNTED_COMPONENTS_KEY: function() { return /* binding */ MOUNTED_COMPONENTS_KEY; },
53
56
  /* harmony export */ STANDALONE_CONFIG_READY: function() { return /* binding */ STANDALONE_CONFIG_READY; },
@@ -58,7 +61,15 @@ const MOUNTED_COMPONENTS_KEY = Symbol('MOUNTED_COMPONENTS');
58
61
  const MESSAGE_KEY = Symbol('MESSAGE');
59
62
  const CONFIG_KEY = Symbol('CONFIG');
60
63
  const DEPENDENCIES_KEY = Symbol('DEPENDENCIES');
64
+ const LOCALE_KEY = Symbol('LOCALE');
61
65
  const STANDALONE_CONFIG_READY = Symbol('STANDALONE_CONFIG_READY');
66
+ const DEFAULT_LOCALE = 'en';
67
+ let I18NActions = /*#__PURE__*/function (I18NActions) {
68
+ I18NActions["SetLocale"] = "setLocale";
69
+ I18NActions["GetLocale"] = "getLocale";
70
+ I18NActions["UpdateI18nConfig"] = "updateI18nConfig";
71
+ return I18NActions;
72
+ }({});
62
73
  const VUE_FUNCTION_OPTIONS = ['beforeCreate', 'created', 'beforeMount', 'mounted', 'beforeUpdate', 'updated', 'beforeUnmount', 'unmounted', 'errorCaptured', 'renderTracked', 'renderTriggered', 'activated', 'deactivated', 'setup', 'data', 'render'];
63
74
  const VUE_VERSION = 3;
64
75
  const BASE_DEPENDENCIES = ['react', 'react-dom', '@variousjs/various', 'app'];
@@ -349,6 +360,8 @@ __webpack_require__.r(__webpack_exports__);
349
360
  /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./store */ "./src/core/store.ts");
350
361
  /* harmony import */ var _helper__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./helper */ "./src/core/helper.ts");
351
362
  /* harmony import */ var _logger__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./logger */ "./src/core/logger.ts");
363
+ /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./config */ "./src/core/config.ts");
364
+
352
365
 
353
366
 
354
367
 
@@ -381,6 +394,26 @@ const createDispatch = module => async function (params) {
381
394
  if (target === 'app') {
382
395
  const storeActions = _connector__WEBPACK_IMPORTED_MODULE_0__["default"].getStoreActions();
383
396
  const storeAction = storeActions[action];
397
+ if (action === _config__WEBPACK_IMPORTED_MODULE_4__.I18NActions.SetLocale) {
398
+ (0,_store__WEBPACK_IMPORTED_MODULE_1__.emit)({
399
+ [_config__WEBPACK_IMPORTED_MODULE_4__.LOCALE_KEY]: payload
400
+ }, true);
401
+ return payload;
402
+ }
403
+ if (action === _config__WEBPACK_IMPORTED_MODULE_4__.I18NActions.GetLocale) {
404
+ return (0,_store__WEBPACK_IMPORTED_MODULE_1__.getStore)(_config__WEBPACK_IMPORTED_MODULE_4__.LOCALE_KEY);
405
+ }
406
+ if (action === _config__WEBPACK_IMPORTED_MODULE_4__.I18NActions.UpdateI18nConfig) {
407
+ const locale = (0,_store__WEBPACK_IMPORTED_MODULE_1__.getStore)(_config__WEBPACK_IMPORTED_MODULE_4__.LOCALE_KEY);
408
+ _connector__WEBPACK_IMPORTED_MODULE_0__["default"].setGlobalI18nConfig(payload);
409
+ (0,_store__WEBPACK_IMPORTED_MODULE_1__.emit)({
410
+ [_config__WEBPACK_IMPORTED_MODULE_4__.LOCALE_KEY]: undefined
411
+ }, true);
412
+ (0,_store__WEBPACK_IMPORTED_MODULE_1__.emit)({
413
+ [_config__WEBPACK_IMPORTED_MODULE_4__.LOCALE_KEY]: locale
414
+ }, true);
415
+ return locale;
416
+ }
384
417
  if (!storeAction) {
385
418
  const errorMessage = `action "${action}" is not present`;
386
419
  const error = new _helper__WEBPACK_IMPORTED_MODULE_2__.VariousError({
@@ -437,6 +470,8 @@ __webpack_require__.r(__webpack_exports__);
437
470
  /* harmony import */ var _helper__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helper */ "./src/core/helper.ts");
438
471
  /* harmony import */ var _connector__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./connector */ "./src/core/connector.ts");
439
472
  /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./store */ "./src/core/store.ts");
473
+ /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./config */ "./src/core/config.ts");
474
+
440
475
 
441
476
 
442
477
 
@@ -473,12 +508,14 @@ class ErrorBoundary extends react__WEBPACK_IMPORTED_MODULE_0__.Component {
473
508
  render() {
474
509
  const ErrorFallbackNode = _connector__WEBPACK_IMPORTED_MODULE_2__["default"].getErrorFallbackComponent();
475
510
  const store = (0,_store__WEBPACK_IMPORTED_MODULE_3__.getUserStore)();
511
+ const locale = (0,_store__WEBPACK_IMPORTED_MODULE_3__.getStore)(_config__WEBPACK_IMPORTED_MODULE_4__.LOCALE_KEY);
476
512
  if (this.state.hasError) {
477
513
  return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(ErrorFallbackNode, {
478
514
  $self: this.$self,
479
515
  $reload: this.reload,
480
516
  $store: store,
481
- $error: this.error
517
+ $error: this.error,
518
+ $locale: locale
482
519
  });
483
520
  }
484
521
  return this.props.children;
@@ -774,6 +811,8 @@ __webpack_require__.r(__webpack_exports__);
774
811
  /* harmony import */ var _connector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./connector */ "./src/core/connector.ts");
775
812
  /* harmony import */ var _helper__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helper */ "./src/core/helper.ts");
776
813
  /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./store */ "./src/core/store.ts");
814
+ /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./config */ "./src/core/config.ts");
815
+
777
816
 
778
817
 
779
818
 
@@ -793,13 +832,11 @@ function createI18nConfig(method, module, callback) {
793
832
  if (module) {
794
833
  _connector__WEBPACK_IMPORTED_MODULE_0__["default"].setI18nConfig(module, {
795
834
  loading: true,
796
- lngStoreKey: '',
797
835
  resources: {}
798
836
  });
799
837
  } else {
800
838
  _connector__WEBPACK_IMPORTED_MODULE_0__["default"].setGlobalI18nConfig({
801
839
  loading: true,
802
- lngStoreKey: '',
803
840
  resources: {}
804
841
  });
805
842
  }
@@ -812,12 +849,12 @@ function createI18nConfig(method, module, callback) {
812
849
  callback?.();
813
850
  return;
814
851
  }
815
- const locale = (0,_store__WEBPACK_IMPORTED_MODULE_2__.getStore)(res.lngStoreKey);
852
+ const locale = (0,_store__WEBPACK_IMPORTED_MODULE_2__.getStore)(_config__WEBPACK_IMPORTED_MODULE_3__.LOCALE_KEY);
816
853
  (0,_store__WEBPACK_IMPORTED_MODULE_2__.emit)({
817
- [res.lngStoreKey]: undefined
854
+ [_config__WEBPACK_IMPORTED_MODULE_3__.LOCALE_KEY]: undefined
818
855
  }, true);
819
856
  (0,_store__WEBPACK_IMPORTED_MODULE_2__.emit)({
820
- [res.lngStoreKey]: locale
857
+ [_config__WEBPACK_IMPORTED_MODULE_3__.LOCALE_KEY]: locale
821
858
  }, true);
822
859
  _connector__WEBPACK_IMPORTED_MODULE_0__["default"].setGlobalI18nConfig({
823
860
  ...res,
@@ -850,18 +887,9 @@ function createI18n(module, updater) {
850
887
  return defaultText;
851
888
  }
852
889
  const {
853
- lngStoreKey,
854
890
  resources
855
891
  } = i18nConfig;
856
- const locale = (0,_store__WEBPACK_IMPORTED_MODULE_2__.getStore)(lngStoreKey);
857
- if (lngStoreKey === undefined || locale === undefined) {
858
- (0,_helper__WEBPACK_IMPORTED_MODULE_1__.onError)(new _helper__WEBPACK_IMPORTED_MODULE_1__.VariousError({
859
- module,
860
- type: 'I18N',
861
- originalError: new Error('locale key not defined')
862
- }));
863
- return defaultText;
864
- }
892
+ const locale = (0,_store__WEBPACK_IMPORTED_MODULE_2__.getStore)(_config__WEBPACK_IMPORTED_MODULE_3__.LOCALE_KEY);
865
893
  const resource = resources?.[locale];
866
894
  if (!resource) {
867
895
  (0,_helper__WEBPACK_IMPORTED_MODULE_1__.onError)(new _helper__WEBPACK_IMPORTED_MODULE_1__.VariousError({
@@ -892,17 +920,13 @@ function createI18n(module, updater) {
892
920
  return next.replace(regex, params[arg].toString());
893
921
  }, text);
894
922
  };
895
- ctx.update = (config, type) => {
896
- const i18nConfig = type === 'app' ? _connector__WEBPACK_IMPORTED_MODULE_0__["default"].getGlobalI18nConfig() : _connector__WEBPACK_IMPORTED_MODULE_0__["default"].getI18nConfig(module);
923
+ ctx.update = config => {
924
+ const i18nConfig = _connector__WEBPACK_IMPORTED_MODULE_0__["default"].getI18nConfig(module);
897
925
  const next = {
898
926
  ...i18nConfig,
899
927
  ...config
900
928
  };
901
- if (type === 'app') {
902
- _connector__WEBPACK_IMPORTED_MODULE_0__["default"].setGlobalI18nConfig(next);
903
- } else {
904
- _connector__WEBPACK_IMPORTED_MODULE_0__["default"].setI18nConfig(module, next);
905
- }
929
+ _connector__WEBPACK_IMPORTED_MODULE_0__["default"].setI18nConfig(module, next);
906
930
  updater();
907
931
  };
908
932
  return ctx;
@@ -1072,6 +1096,8 @@ __webpack_require__.r(__webpack_exports__);
1072
1096
  /* harmony import */ var _logger__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./logger */ "./src/core/logger.ts");
1073
1097
  /* harmony import */ var _i18n__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./i18n */ "./src/core/i18n.ts");
1074
1098
  /* harmony import */ var _create_module__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./create-module */ "./src/core/create-module.ts");
1099
+ /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./config */ "./src/core/config.ts");
1100
+
1075
1101
 
1076
1102
 
1077
1103
 
@@ -1161,6 +1187,7 @@ function reactComponent(config) {
1161
1187
  isError
1162
1188
  } = this.state;
1163
1189
  const store = (0,_store__WEBPACK_IMPORTED_MODULE_3__.getUserStore)();
1190
+ const locale = (0,_store__WEBPACK_IMPORTED_MODULE_3__.getStore)(_config__WEBPACK_IMPORTED_MODULE_10__.LOCALE_KEY);
1164
1191
  const ComponentNode = this.ComponentNode;
1165
1192
  if (isError) {
1166
1193
  throw this.error;
@@ -1171,7 +1198,8 @@ function reactComponent(config) {
1171
1198
  }
1172
1199
  return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().createElement(Fallback, {
1173
1200
  $self: this.$self,
1174
- $store: store
1201
+ $store: store,
1202
+ $locale: locale
1175
1203
  });
1176
1204
  }
1177
1205
  return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().createElement(ComponentNode, (0,_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__["default"])({}, $componentProps, {
@@ -1181,11 +1209,12 @@ function reactComponent(config) {
1181
1209
  $postMessage: this.$postMessage,
1182
1210
  $t: this.$t,
1183
1211
  $logger: this.$logger,
1184
- ref: $ref
1212
+ ref: $ref,
1213
+ $locale: locale
1185
1214
  }));
1186
1215
  }
1187
1216
  }
1188
- const Connected = (0,_store__WEBPACK_IMPORTED_MODULE_3__.connect)(...storeKeys)(R);
1217
+ const Connected = (0,_store__WEBPACK_IMPORTED_MODULE_3__.connect)(...storeKeys, _config__WEBPACK_IMPORTED_MODULE_10__.LOCALE_KEY)(R);
1189
1218
  Connected.displayName = 'various-connector';
1190
1219
  return Connected;
1191
1220
  }
@@ -1328,6 +1357,8 @@ __webpack_require__.r(__webpack_exports__);
1328
1357
  /* harmony import */ var _logger__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./logger */ "./src/core/logger.ts");
1329
1358
  /* harmony import */ var _message__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./message */ "./src/core/message.ts");
1330
1359
  /* harmony import */ var _i18n__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./i18n */ "./src/core/i18n.ts");
1360
+ /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./config */ "./src/core/config.ts");
1361
+
1331
1362
 
1332
1363
 
1333
1364
 
@@ -1346,7 +1377,8 @@ function vueComponent(config) {
1346
1377
  } = config;
1347
1378
  const storeKeys = watchKeys || Object.keys((0,_store__WEBPACK_IMPORTED_MODULE_3__.getStore)());
1348
1379
  const V = props => {
1349
- const store = (0,_store__WEBPACK_IMPORTED_MODULE_3__.useStore)(...storeKeys);
1380
+ const store = (0,_store__WEBPACK_IMPORTED_MODULE_3__.useStore)(...storeKeys, _config__WEBPACK_IMPORTED_MODULE_9__.LOCALE_KEY);
1381
+ const locale = store[_config__WEBPACK_IMPORTED_MODULE_9__.LOCALE_KEY];
1350
1382
  const vueRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1351
1383
  const vmRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1352
1384
  const isVueMounted = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(false);
@@ -1360,6 +1392,7 @@ function vueComponent(config) {
1360
1392
  const containerDivRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(null);
1361
1393
  const propsReactiveRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1362
1394
  const storeReactiveRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1395
+ const localeReactiveRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1363
1396
  const unMountVue = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1364
1397
  const unSubscribeMessageRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1365
1398
  const updateVueComponentRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
@@ -1383,6 +1416,7 @@ function vueComponent(config) {
1383
1416
  storeReactiveRef.current = vueRef.current.ref({
1384
1417
  ...store
1385
1418
  });
1419
+ localeReactiveRef.current = vueRef.current.ref(locale);
1386
1420
  const vueApp = vueRef.current.createApp({
1387
1421
  setup() {
1388
1422
  const renderKey = vueRef.current.ref(0);
@@ -1411,7 +1445,8 @@ function vueComponent(config) {
1411
1445
  $postMessage,
1412
1446
  $t,
1413
1447
  $store: storeReactiveRef.current.value,
1414
- $self: selfRef.current
1448
+ $self: selfRef.current,
1449
+ $locale: localeReactiveRef.current.value
1415
1450
  },
1416
1451
  // eslint-disable-next-line react/no-this-in-sfc
1417
1452
  key: this.key
@@ -1425,7 +1460,7 @@ function vueComponent(config) {
1425
1460
  }
1426
1461
  isVueMounted.current = true;
1427
1462
  unMountVue.current = () => vueApp.unmount();
1428
- }, [$componentProps, store]);
1463
+ }, [$componentProps, store, locale]);
1429
1464
  const mountComponent = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(async () => {
1430
1465
  try {
1431
1466
  const vue = await (0,_create_module__WEBPACK_IMPORTED_MODULE_2__["default"])({
@@ -1495,12 +1530,18 @@ function vueComponent(config) {
1495
1530
  };
1496
1531
  }
1497
1532
  }, [store]);
1533
+ (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
1534
+ if (localeReactiveRef.current) {
1535
+ localeReactiveRef.current.value = locale;
1536
+ }
1537
+ }, [locale]);
1498
1538
  if (isError) {
1499
1539
  throw errorRef.current;
1500
1540
  }
1501
1541
  return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, !componentReady && !$silent && !(0,_helper__WEBPACK_IMPORTED_MODULE_4__.isModuleLoaded)(module) ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(Fallback, {
1502
1542
  $self: selfRef.current,
1503
- $store: store
1543
+ $store: store,
1544
+ $locale: locale
1504
1545
  }) : null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
1505
1546
  className: (0,_helper__WEBPACK_IMPORTED_MODULE_4__.getClassNameWithModule)(module, 'various-vue-component'),
1506
1547
  ref: containerDivRef
@@ -1663,7 +1704,7 @@ __webpack_require__.r(__webpack_exports__);
1663
1704
 
1664
1705
 
1665
1706
  // eslint-disable-next-line no-undef
1666
- const version = "5.2.0";
1707
+ const version = "5.3.0";
1667
1708
  const getApp = config => {
1668
1709
  const {
1669
1710
  dependencies,
@@ -1691,13 +1732,14 @@ const getApp = config => {
1691
1732
  [_config__WEBPACK_IMPORTED_MODULE_2__.MOUNTED_COMPONENTS_KEY]: [],
1692
1733
  [_config__WEBPACK_IMPORTED_MODULE_2__.CONFIG_KEY]: rest,
1693
1734
  [_config__WEBPACK_IMPORTED_MODULE_2__.DEPENDENCIES_KEY]: dependencies,
1694
- [_config__WEBPACK_IMPORTED_MODULE_2__.MESSAGE_KEY]: null
1735
+ [_config__WEBPACK_IMPORTED_MODULE_2__.MESSAGE_KEY]: null,
1736
+ [_config__WEBPACK_IMPORTED_MODULE_2__.LOCALE_KEY]: i18n?.defaultLocale || _config__WEBPACK_IMPORTED_MODULE_2__.DEFAULT_LOCALE
1695
1737
  });
1696
1738
  Root.displayName = 'various-app-root';
1697
1739
  return class extends react__WEBPACK_IMPORTED_MODULE_0__.Component {
1698
1740
  static displayName = 'various-app';
1699
1741
  componentDidMount() {
1700
- (0,_i18n__WEBPACK_IMPORTED_MODULE_4__.createI18nConfig)(i18n);
1742
+ (0,_i18n__WEBPACK_IMPORTED_MODULE_4__.createI18nConfig)(i18n?.getResources);
1701
1743
  }
1702
1744
  render() {
1703
1745
  return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_error_boundary__WEBPACK_IMPORTED_MODULE_6__["default"], {