@variousjs/various 5.3.0 → 6.0.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
@@ -1,1757 +1,1398 @@
1
- define(["react"], function(__WEBPACK_EXTERNAL_MODULE_react__) { return /******/ (function() { // webpackBootstrap
2
- /******/ var __webpack_modules__ = ({
3
-
4
- /***/ "./node_modules/@babel/runtime/helpers/esm/extends.js":
5
- /*!************************************************************!*\
6
- !*** ./node_modules/@babel/runtime/helpers/esm/extends.js ***!
7
- \************************************************************/
8
- /***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
9
-
10
- "use strict";
11
- __webpack_require__.r(__webpack_exports__);
12
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
13
- /* harmony export */ "default": function() { return /* binding */ _extends; }
14
- /* harmony export */ });
15
- function _extends() {
16
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
17
- for (var e = 1; e < arguments.length; e++) {
18
- var t = arguments[e];
19
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
20
- }
21
- return n;
22
- }, _extends.apply(null, arguments);
1
+ import e, { Component, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
2
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/typeof.js
3
+ function _typeof(o) {
4
+ "@babel/helpers - typeof";
5
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
6
+ return typeof o;
7
+ } : function(o) {
8
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
9
+ }, _typeof(o);
23
10
  }
24
-
25
-
26
- /***/ }),
27
-
28
- /***/ "./node_modules/nycticorax/dist/index.js":
29
- /*!***********************************************!*\
30
- !*** ./node_modules/nycticorax/dist/index.js ***!
31
- \***********************************************/
32
- /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
33
-
34
- !function(t,e){ true?module.exports=e(__webpack_require__(/*! react */ "react")):0}(self,t=>(()=>{"use strict";var e={17(t){t.exports=function t(e,r){if(e===r)return!0;if(e&&r&&"object"==typeof e&&"object"==typeof r){if(e.constructor!==r.constructor)return!1;var o,s,n;if(Array.isArray(e)){if((o=e.length)!=r.length)return!1;for(s=o;0!==s--;)if(!t(e[s],r[s]))return!1;return!0}if(e.constructor===RegExp)return e.source===r.source&&e.flags===r.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===r.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===r.toString();if((o=(n=Object.keys(e)).length)!==Object.keys(r).length)return!1;for(s=o;0!==s--;)if(!Object.prototype.hasOwnProperty.call(r,n[s]))return!1;for(s=o;0!==s--;){var i=n[s];if(!t(e[i],r[i]))return!1}return!0}return e!=e&&r!=r}},232(t,e,r){r.d(e,{default:()=>u});var o=r(705),s=r(17),n=r.n(s);function i(t,e=new WeakMap){if("object"!=typeof t||null===t)return t;if(e.has(t))return e.get(t);const r=Array.isArray(t)?[]:{};e.set(t,r);const o=Reflect.ownKeys(t);for(const s of o)r[s]=i(t[s],e);return r}class u{constructor(){var t;(0,o.A)(this,"state",void 0),(0,o.A)(this,"listeners",void 0),(0,o.A)(this,"emits",void 0),(0,o.A)(this,"timer",void 0),(0,o.A)(this,"onStateChange",void 0),(0,o.A)(this,"getStore",void 0),(0,o.A)(this,"createStore",t=>{this.listeners=Reflect.ownKeys(t).reduce((e,r)=>{const o=r;return this.state[o]=t[o],{...e,[r]:[]}},{})}),(0,o.A)(this,"subscribe",t=>{const e={};return Reflect.ownKeys(t).forEach(r=>{const o=r;this.listeners[o]||(this.listeners[o]=[]),this.listeners[o].push(t[o]),e[o]=t[o]}),()=>{Reflect.ownKeys(e).forEach(t=>{const r=t;this.listeners[r]=this.listeners[r].filter(t=>t!==e[r])})}}),(0,o.A)(this,"emit",(t,e)=>{this.emits={...this.emits,...t},e?this.trigger():(clearTimeout(this.timer),this.timer=setTimeout(this.trigger))}),(0,o.A)(this,"dispatch",(t,...e)=>t({getStore:this.getStore,emit:t=>this.emit(t,!0)},...e)),(0,o.A)(this,"trigger",()=>{const t=this.emits,e=[],r=Reflect.ownKeys(t);for(let o=0;o<r.length;o+=1){const s=r[o];if(n()(this.state[s],t[s]))continue;const u=t[s],c=this.state[s];this.state[s]=i(t[s]),e.push({key:s,newValue:u,oldValue:c})}const o={};e.forEach(t=>{o[t.key]=[t.newValue,t.oldValue],this.listeners[t.key]&&this.listeners[t.key].forEach(e=>e(t.newValue,t.oldValue))}),e.length&&this.onStateChange(o),this.emits={},this.timer=void 0}),this.state={},this.listeners={},this.emits={},this.timer=void 0,this.onStateChange=()=>null,this.getStore=(t=this.state,function(e){return e?i(t[e]):t})}set onChange(t){this.onStateChange=t}}},438(e){e.exports=t},705(t,e,r){function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}function s(t,e,r){return(e=function(t){var e=function(t){if("object"!=o(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=o(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==o(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}r.d(e,{A:()=>s})}},r={};function o(t){var s=r[t];if(void 0!==s)return s.exports;var n=r[t]={exports:{}};return e[t](n,n.exports,o),n.exports}o.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return o.d(e,{a:e}),e},o.d=(t,e)=>{for(var r in e)o.o(e,r)&&!o.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var s={};o.d(s,{default:()=>l});var n=o(705),i=o(232),u=o(438),c=o.n(u);const a=["name","prototype","length","getDerivedStateFromProps","getDerivedStateFromError"];class f extends i.default{constructor(...t){super(...t),(0,n.A)(this,"connect",function(t){const{getStore:e,subscribe:r}=t;return function(...t){return function(o){class s extends u.Component{constructor(o){super(o),(0,n.A)(this,"unsubscribe",void 0),(0,n.A)(this,"state",{props:e()}),this.unsubscribe=r(t.reduce((t,r)=>({...t,[r]:()=>{this.setState({props:e()})}}),{}))}componentWillUnmount(){this.unsubscribe()}render(){const{props:t}=this.state,e={...t,...this.props};return c().createElement(o,e)}}return Reflect.ownKeys(o).forEach(t=>{const e=String(t);if(!a.includes(e)){const e=Object.getOwnPropertyDescriptor(o,t);e&&Object.defineProperty(s,t,e)}}),s}}}(this)),(0,n.A)(this,"useStore",function(t){const{getStore:e,subscribe:r}=t;return function(...t){const[o,s]=(0,u.useState)(e());return(0,u.useLayoutEffect)(()=>r(t.reduce((t,r)=>({...t,[r]:()=>{s(t=>({...t,[r]:e()[r]}))}}),{}))),o}}(this))}}const l=f;return s.default})());
35
- //# sourceMappingURL=index.js.map
36
-
37
- /***/ }),
38
-
39
- /***/ "./src/core/config.ts":
40
- /*!****************************!*\
41
- !*** ./src/core/config.ts ***!
42
- \****************************/
43
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
44
-
45
- "use strict";
46
- __webpack_require__.r(__webpack_exports__);
47
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
48
- /* harmony export */ BASE_DEPENDENCIES: function() { return /* binding */ BASE_DEPENDENCIES; },
49
- /* harmony export */ CONFIG_KEY: function() { return /* binding */ CONFIG_KEY; },
50
- /* harmony export */ DEFAULT_LOCALE: function() { return /* binding */ DEFAULT_LOCALE; },
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; },
54
- /* harmony export */ MESSAGE_KEY: function() { return /* binding */ MESSAGE_KEY; },
55
- /* harmony export */ MOUNTED_COMPONENTS_KEY: function() { return /* binding */ MOUNTED_COMPONENTS_KEY; },
56
- /* harmony export */ STANDALONE_CONFIG_READY: function() { return /* binding */ STANDALONE_CONFIG_READY; },
57
- /* harmony export */ VUE_FUNCTION_OPTIONS: function() { return /* binding */ VUE_FUNCTION_OPTIONS; },
58
- /* harmony export */ VUE_VERSION: function() { return /* binding */ VUE_VERSION; }
59
- /* harmony export */ });
60
- const MOUNTED_COMPONENTS_KEY = Symbol('MOUNTED_COMPONENTS');
61
- const MESSAGE_KEY = Symbol('MESSAGE');
62
- const CONFIG_KEY = Symbol('CONFIG');
63
- const DEPENDENCIES_KEY = Symbol('DEPENDENCIES');
64
- const LOCALE_KEY = Symbol('LOCALE');
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
- }({});
73
- const VUE_FUNCTION_OPTIONS = ['beforeCreate', 'created', 'beforeMount', 'mounted', 'beforeUpdate', 'updated', 'beforeUnmount', 'unmounted', 'errorCaptured', 'renderTracked', 'renderTriggered', 'activated', 'deactivated', 'setup', 'data', 'render'];
74
- const VUE_VERSION = 3;
75
- const BASE_DEPENDENCIES = ['react', 'react-dom', '@variousjs/various', 'app'];
76
-
77
- /***/ }),
78
-
79
- /***/ "./src/core/connector.ts":
80
- /*!*******************************!*\
81
- !*** ./src/core/connector.ts ***!
82
- \*******************************/
83
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
84
-
85
- "use strict";
86
- __webpack_require__.r(__webpack_exports__);
87
- /* harmony import */ var _default_component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./default-component */ "./src/core/default-component.tsx");
88
-
89
- class Connector {
90
- constructor() {
91
- this.fallbackComponent = _default_component__WEBPACK_IMPORTED_MODULE_0__.Fallback;
92
- this.errorFallbackComponent = _default_component__WEBPACK_IMPORTED_MODULE_0__.ErrorFallback;
93
- this.storeActions = {};
94
- this.componentActions = {};
95
- this.i18nConfigs = {};
96
- this.middlewares = {};
97
- }
98
- setMiddlewares(m) {
99
- this.middlewares = m;
100
- }
101
- getMiddlewares() {
102
- return this.middlewares;
103
- }
104
- setI18nConfig(module, config) {
105
- this.i18nConfigs[module] = {
106
- ...this.i18nConfigs[module],
107
- ...config
108
- };
109
- }
110
- getI18nConfig(module) {
111
- return this.i18nConfigs[module];
112
- }
113
- setGlobalI18nConfig(config) {
114
- this.globalI18nConfig = {
115
- ...this.globalI18nConfig,
116
- ...config
117
- };
118
- }
119
- getGlobalI18nConfig() {
120
- return this.globalI18nConfig;
121
- }
122
- setComponentActions(module, actions) {
123
- this.componentActions[module] = actions;
124
- }
125
- deleteComponentActions(module) {
126
- delete this.componentActions[module];
127
- }
128
- getComponentActions(module) {
129
- return this.componentActions[module];
130
- }
131
- setStoreActions(actions) {
132
- this.storeActions = actions;
133
- }
134
- getStoreActions() {
135
- return this.storeActions;
136
- }
137
- setFallbackComponent(fallbackComponent) {
138
- this.fallbackComponent = fallbackComponent;
139
- }
140
- getFallbackComponent() {
141
- return this.fallbackComponent;
142
- }
143
- setErrorFallbackComponent(errorFallbackComponent) {
144
- this.errorFallbackComponent = errorFallbackComponent;
145
- }
146
- getErrorFallbackComponent() {
147
- return this.errorFallbackComponent;
148
- }
11
+ //#endregion
12
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPrimitive.js
13
+ function toPrimitive(t, r) {
14
+ if ("object" != _typeof(t) || !t) return t;
15
+ var e = t[Symbol.toPrimitive];
16
+ if (void 0 !== e) {
17
+ var i = e.call(t, r || "default");
18
+ if ("object" != _typeof(i)) return i;
19
+ throw new TypeError("@@toPrimitive must return a primitive value.");
20
+ }
21
+ return ("string" === r ? String : Number)(t);
149
22
  }
150
- /* harmony default export */ __webpack_exports__["default"] = (new Connector());
151
-
152
- /***/ }),
153
-
154
- /***/ "./src/core/create-component.tsx":
155
- /*!***************************************!*\
156
- !*** ./src/core/create-component.tsx ***!
157
- \***************************************/
158
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
159
-
160
- "use strict";
161
- __webpack_require__.r(__webpack_exports__);
162
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
163
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
164
- /* harmony import */ var _react_component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./react-component */ "./src/core/react-component.tsx");
165
- /* harmony import */ var _vue_component__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./vue-component */ "./src/core/vue-component.tsx");
166
- /* harmony import */ var _error_boundary__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./error-boundary */ "./src/core/error-boundary.tsx");
167
-
168
-
169
-
170
-
171
- const createComponent = (config, storeKeys) => {
172
- const {
173
- module,
174
- url,
175
- type = 'react'
176
- } = config;
177
- const C = (type === 'vue3' ? _vue_component__WEBPACK_IMPORTED_MODULE_2__["default"] : _react_component__WEBPACK_IMPORTED_MODULE_1__["default"])({
178
- module,
179
- url,
180
- watchKeys: storeKeys
181
- });
182
- const component = props => {
183
- const {
184
- $silent,
185
- $ref,
186
- ...rest
187
- } = props || {};
188
- const nextProps = {
189
- $componentProps: rest,
190
- $silent,
191
- $ref
192
- };
193
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_error_boundary__WEBPACK_IMPORTED_MODULE_3__["default"], {
194
- module: module,
195
- url: url
196
- }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(C, nextProps));
197
- };
198
- component.displayName = 'various-creator';
199
- return component;
23
+ //#endregion
24
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPropertyKey.js
25
+ function toPropertyKey(t) {
26
+ var i = toPrimitive(t, "string");
27
+ return "symbol" == _typeof(i) ? i : i + "";
28
+ }
29
+ //#endregion
30
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/defineProperty.js
31
+ function _defineProperty(e, r, t) {
32
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
33
+ value: t,
34
+ enumerable: !0,
35
+ configurable: !0,
36
+ writable: !0
37
+ }) : e[r] = t, e;
38
+ }
39
+ //#endregion
40
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/objectSpread2.js
41
+ function ownKeys(e, r) {
42
+ var t = Object.keys(e);
43
+ if (Object.getOwnPropertySymbols) {
44
+ var o = Object.getOwnPropertySymbols(e);
45
+ r && (o = o.filter(function(r) {
46
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
47
+ })), t.push.apply(t, o);
48
+ }
49
+ return t;
50
+ }
51
+ function _objectSpread2(e) {
52
+ for (var r = 1; r < arguments.length; r++) {
53
+ var t = null != arguments[r] ? arguments[r] : {};
54
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
55
+ _defineProperty(e, r, t[r]);
56
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
57
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
58
+ });
59
+ }
60
+ return e;
61
+ }
62
+ //#endregion
63
+ //#region node_modules/nycticorax/dist/esm/index.js
64
+ var o = {
65
+ 17(t) {
66
+ t.exports = function t(e, r) {
67
+ if (e === r) return !0;
68
+ if (e && r && "object" == typeof e && "object" == typeof r) {
69
+ if (e.constructor !== r.constructor) return !1;
70
+ var s, o, n;
71
+ if (Array.isArray(e)) {
72
+ if ((s = e.length) != r.length) return !1;
73
+ for (o = s; 0 !== o--;) if (!t(e[o], r[o])) return !1;
74
+ return !0;
75
+ }
76
+ if (e.constructor === RegExp) return e.source === r.source && e.flags === r.flags;
77
+ if (e.valueOf !== Object.prototype.valueOf) return e.valueOf() === r.valueOf();
78
+ if (e.toString !== Object.prototype.toString) return e.toString() === r.toString();
79
+ if ((s = (n = Object.keys(e)).length) !== Object.keys(r).length) return !1;
80
+ for (o = s; 0 !== o--;) if (!Object.prototype.hasOwnProperty.call(r, n[o])) return !1;
81
+ for (o = s; 0 !== o--;) {
82
+ var i = n[o];
83
+ if (!t(e[i], r[i])) return !1;
84
+ }
85
+ return !0;
86
+ }
87
+ return e != e && r != r;
88
+ };
89
+ },
90
+ 232(t, e, r) {
91
+ r.d(e, { A: () => u });
92
+ var s = r(705), o = r(17), n = r.n(o);
93
+ function i(t, e = /* @__PURE__ */ new WeakMap()) {
94
+ if ("object" != typeof t || null === t) return t;
95
+ if (e.has(t)) return e.get(t);
96
+ const r = Array.isArray(t) ? [] : {};
97
+ e.set(t, r);
98
+ const s = Reflect.ownKeys(t);
99
+ for (const o of s) r[o] = i(t[o], e);
100
+ return r;
101
+ }
102
+ class u {
103
+ constructor() {
104
+ var t;
105
+ (0, s.A)(this, "state", void 0), (0, s.A)(this, "listeners", void 0), (0, s.A)(this, "emits", void 0), (0, s.A)(this, "timer", void 0), (0, s.A)(this, "onStateChange", void 0), (0, s.A)(this, "getStore", void 0), (0, s.A)(this, "createStore", (t) => {
106
+ this.listeners = Reflect.ownKeys(t).reduce((e, r) => {
107
+ const s = r;
108
+ return this.state[s] = t[s], _objectSpread2(_objectSpread2({}, e), {}, { [r]: [] });
109
+ }, {});
110
+ }), (0, s.A)(this, "subscribe", (t) => {
111
+ const e = {};
112
+ return Reflect.ownKeys(t).forEach((r) => {
113
+ const s = r;
114
+ this.listeners[s] || (this.listeners[s] = []), this.listeners[s].push(t[s]), e[s] = t[s];
115
+ }), () => {
116
+ Reflect.ownKeys(e).forEach((t) => {
117
+ const r = t;
118
+ this.listeners[r] = this.listeners[r].filter((t) => t !== e[r]);
119
+ });
120
+ };
121
+ }), (0, s.A)(this, "emit", (t, e) => {
122
+ this.emits = _objectSpread2(_objectSpread2({}, this.emits), t), e ? this.trigger() : (clearTimeout(this.timer), this.timer = setTimeout(this.trigger));
123
+ }), (0, s.A)(this, "dispatch", (t, ...e) => t({
124
+ getStore: this.getStore,
125
+ emit: (t) => this.emit(t, !0)
126
+ }, ...e)), (0, s.A)(this, "trigger", () => {
127
+ const t = this.emits, e = [], r = Reflect.ownKeys(t);
128
+ for (let s = 0; s < r.length; s += 1) {
129
+ const o = r[s];
130
+ if (n()(this.state[o], t[o])) continue;
131
+ const u = t[o], c = this.state[o];
132
+ this.state[o] = i(t[o]), e.push({
133
+ key: o,
134
+ newValue: u,
135
+ oldValue: c
136
+ });
137
+ }
138
+ const s = {};
139
+ e.forEach((t) => {
140
+ s[t.key] = [t.newValue, t.oldValue], this.listeners[t.key] && this.listeners[t.key].forEach((e) => e(t.newValue, t.oldValue));
141
+ }), e.length && this.onStateChange(s), this.emits = {}, this.timer = void 0;
142
+ }), this.state = {}, this.listeners = {}, this.emits = {}, this.timer = void 0, this.onStateChange = () => null, this.getStore = (t = this.state, function(e) {
143
+ return e ? i(t[e]) : t;
144
+ });
145
+ }
146
+ set onChange(t) {
147
+ this.onStateChange = t;
148
+ }
149
+ }
150
+ },
151
+ 705(t, e, r) {
152
+ function s(t) {
153
+ return s = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
154
+ return typeof t;
155
+ } : function(t) {
156
+ return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
157
+ }, s(t);
158
+ }
159
+ function o(t, e, r) {
160
+ return (e = function(t) {
161
+ var e = function(t) {
162
+ if ("object" != s(t) || !t) return t;
163
+ var e = t[Symbol.toPrimitive];
164
+ if (void 0 !== e) {
165
+ var r = e.call(t, "string");
166
+ if ("object" != s(r)) return r;
167
+ throw new TypeError("@@toPrimitive must return a primitive value.");
168
+ }
169
+ return String(t);
170
+ }(t);
171
+ return "symbol" == s(e) ? e : e + "";
172
+ }(e)) in t ? Object.defineProperty(t, e, {
173
+ value: r,
174
+ enumerable: !0,
175
+ configurable: !0,
176
+ writable: !0
177
+ }) : t[e] = r, t;
178
+ }
179
+ r.d(e, { A: () => o });
180
+ }
200
181
  };
201
- /* harmony default export */ __webpack_exports__["default"] = (createComponent);
202
-
203
- /***/ }),
204
-
205
- /***/ "./src/core/create-module.ts":
206
- /*!***********************************!*\
207
- !*** ./src/core/create-module.ts ***!
208
- \***********************************/
209
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
210
-
211
- "use strict";
212
- __webpack_require__.r(__webpack_exports__);
213
- /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./config */ "./src/core/config.ts");
214
- /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./store */ "./src/core/store.ts");
215
- /* harmony import */ var _connector__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./connector */ "./src/core/connector.ts");
216
- /* harmony import */ var _helper__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./helper */ "./src/core/helper.ts");
217
-
218
-
219
-
220
-
221
- const createModule = (config, logError = true) => {
222
- const dependencies = (0,_store__WEBPACK_IMPORTED_MODULE_1__.getStore)(_config__WEBPACK_IMPORTED_MODULE_0__.DEPENDENCIES_KEY);
223
- const middlewares = _connector__WEBPACK_IMPORTED_MODULE_2__["default"].getMiddlewares();
224
- const {
225
- url,
226
- module
227
- } = config;
228
- const {
229
- name,
230
- entry
231
- } = (0,_helper__WEBPACK_IMPORTED_MODULE_3__.getModuleInfo)(module);
232
- const loadStart = +new Date();
233
- const logOnError = e => {
234
- if (logError) {
235
- (0,_helper__WEBPACK_IMPORTED_MODULE_3__.onError)(e);
236
- }
237
- };
238
- if (url) {
239
- (0,_helper__WEBPACK_IMPORTED_MODULE_3__.resetDependencyConfig)(module, url);
240
- }
241
- return new Promise((resolve, reject) => {
242
- if (!url && !dependencies[name] && !(0,_helper__WEBPACK_IMPORTED_MODULE_3__.isModuleSpecified)(module)) {
243
- const error = new _helper__WEBPACK_IMPORTED_MODULE_3__.VariousError({
244
- module,
245
- type: 'NOT_DEFINED',
246
- originalError: new Error(`module "${name}" not defined`)
247
- });
248
- logOnError(error);
249
- reject(error);
250
- return;
251
- }
252
- window.requirejs([name], C => {
253
- const loadEnd = +new Date();
254
- middlewares?.onLoad?.({
255
- module,
256
- loadStart,
257
- loadEnd,
258
- beenLoaded: (0,_helper__WEBPACK_IMPORTED_MODULE_3__.isModuleLoaded)(module)
259
- });
260
- if (!C) {
261
- const error = new _helper__WEBPACK_IMPORTED_MODULE_3__.VariousError({
262
- module,
263
- type: 'INVALID_MODULE',
264
- originalError: new Error(`module "${name}" invalid`)
265
- });
266
- (0,_helper__WEBPACK_IMPORTED_MODULE_3__.resetDependencyConfig)(module);
267
- logOnError(error);
268
- reject(error);
269
- return;
270
- }
271
- const defaultModule = 'default' in C ? C.default : C;
272
- const actualModule = !entry ? defaultModule : C[entry];
273
- if (actualModule === undefined && entry) {
274
- const error = new _helper__WEBPACK_IMPORTED_MODULE_3__.VariousError({
275
- module,
276
- type: 'SUBMODULE_NOT_DEFINED',
277
- originalError: new Error(`submodule "${entry}" not defined`)
278
- });
279
- (0,_helper__WEBPACK_IMPORTED_MODULE_3__.resetDependencyConfig)(module);
280
- logOnError(error);
281
- reject(error);
282
- return;
283
- }
284
- resolve(actualModule);
285
- }, e => {
286
- const [requireModule] = e.requireModules;
287
- (0,_helper__WEBPACK_IMPORTED_MODULE_3__.resetDependencyConfig)(module, url);
288
- (0,_helper__WEBPACK_IMPORTED_MODULE_3__.resetDependencyConfig)(requireModule);
289
- let errorType = 'LOADING_ERROR';
290
- if (requireModule !== name) {
291
- errorType = 'SUBMODULE_LOADING_ERROR';
292
- }
293
- if (!e.message.includes('https://requirejs.org/docs/errors.html')) {
294
- errorType = requireModule === name ? 'SCRIPT_ERROR' : 'SUBMODULE_SCRIPT_ERROR';
295
- }
296
- const error = new _helper__WEBPACK_IMPORTED_MODULE_3__.VariousError({
297
- module: requireModule,
298
- type: errorType,
299
- originalError: e
300
- });
301
- logOnError(error);
302
- reject(error);
303
- });
304
- });
182
+ var n = {};
183
+ function i(t) {
184
+ var e = n[t];
185
+ if (void 0 !== e) return e.exports;
186
+ var r = n[t] = { exports: {} };
187
+ return o[t](r, r.exports, i), r.exports;
188
+ }
189
+ i.n = (t) => {
190
+ var e = t && t.__esModule ? () => t.default : () => t;
191
+ return i.d(e, { a: e }), e;
192
+ }, i.d = (t, e) => {
193
+ for (var r in e) i.o(e, r) && !i.o(t, r) && Object.defineProperty(t, r, {
194
+ enumerable: !0,
195
+ get: e[r]
196
+ });
197
+ }, i.o = (t, e) => Object.prototype.hasOwnProperty.call(t, e);
198
+ var u = i(705);
199
+ var c = i(232);
200
+ var a = [
201
+ "name",
202
+ "prototype",
203
+ "length",
204
+ "getDerivedStateFromProps",
205
+ "getDerivedStateFromError"
206
+ ];
207
+ var f = class extends c.A {
208
+ constructor(...o) {
209
+ super(...o), (0, u.A)(this, "connect", function(r) {
210
+ const { getStore: s, subscribe: o } = r;
211
+ return function(...r) {
212
+ return function(n) {
213
+ class i extends Component {
214
+ constructor(t) {
215
+ super(t), (0, u.A)(this, "unsubscribe", void 0), (0, u.A)(this, "state", { props: s() }), this.unsubscribe = o(r.reduce((t, e) => _objectSpread2(_objectSpread2({}, t), {}, { [e]: () => {
216
+ this.setState({ props: s() });
217
+ } }), {}));
218
+ }
219
+ componentWillUnmount() {
220
+ this.unsubscribe();
221
+ }
222
+ render() {
223
+ const { props: t } = this.state, r = _objectSpread2(_objectSpread2({}, t), this.props);
224
+ return e.createElement(n, r);
225
+ }
226
+ }
227
+ return Reflect.ownKeys(n).forEach((t) => {
228
+ const e = String(t);
229
+ if (!a.includes(e)) {
230
+ const e = Object.getOwnPropertyDescriptor(n, t);
231
+ e && Object.defineProperty(i, t, e);
232
+ }
233
+ }), i;
234
+ };
235
+ };
236
+ }(this)), (0, u.A)(this, "useStore", function(t) {
237
+ const { getStore: e, subscribe: o } = t;
238
+ return function(...t) {
239
+ const [n, i] = useState(e());
240
+ return useLayoutEffect(() => o(t.reduce((t, r) => _objectSpread2(_objectSpread2({}, t), {}, { [r]: () => {
241
+ i((t) => _objectSpread2(_objectSpread2({}, t), {}, { [r]: e()[r] }));
242
+ } }), {}))), n;
243
+ };
244
+ }(this));
245
+ }
305
246
  };
306
- /* harmony default export */ __webpack_exports__["default"] = (createModule);
307
-
308
- /***/ }),
309
-
310
- /***/ "./src/core/default-component.tsx":
311
- /*!****************************************!*\
312
- !*** ./src/core/default-component.tsx ***!
313
- \****************************************/
314
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
315
-
316
- "use strict";
317
- __webpack_require__.r(__webpack_exports__);
318
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
319
- /* harmony export */ ErrorFallback: function() { return /* binding */ ErrorFallback; },
320
- /* harmony export */ Fallback: function() { return /* binding */ Fallback; },
321
- /* harmony export */ Root: function() { return /* binding */ Root; }
322
- /* harmony export */ });
323
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
324
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
325
- /* harmony import */ var _helper__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helper */ "./src/core/helper.ts");
326
-
327
-
328
- const Fallback = props => {
329
- const className = (0,_helper__WEBPACK_IMPORTED_MODULE_1__.getClassNameWithModule)(props.$self.module, 'various-component-fallback');
330
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
331
- className: className
332
- }, "Loading");
247
+ var h = f;
248
+ //#endregion
249
+ //#region src/core/store.ts
250
+ var { createStore, getStore, connect, emit, subscribe, dispatch, useStore } = new h();
251
+ function getUserStore() {
252
+ const globalStore = getStore();
253
+ const keys = Object.keys(globalStore);
254
+ const store = {};
255
+ keys.forEach((key) => {
256
+ store[key] = globalStore[key];
257
+ });
258
+ return store;
259
+ }
260
+ //#endregion
261
+ //#region src/core/config.ts
262
+ var MOUNTED_COMPONENTS_KEY = Symbol("MOUNTED_COMPONENTS");
263
+ var MESSAGE_KEY = Symbol("MESSAGE");
264
+ var CONFIG_KEY = Symbol("CONFIG");
265
+ var DEPENDENCIES_KEY = Symbol("DEPENDENCIES");
266
+ var LOCALE_KEY = Symbol("LOCALE");
267
+ var I18NActions = /* @__PURE__ */ function(I18NActions) {
268
+ I18NActions["SetLocale"] = "setLocale";
269
+ I18NActions["GetLocale"] = "getLocale";
270
+ I18NActions["UpdateI18nConfig"] = "updateI18nConfig";
271
+ return I18NActions;
272
+ }({});
273
+ var VUE_FUNCTION_OPTIONS = [
274
+ "beforeCreate",
275
+ "created",
276
+ "beforeMount",
277
+ "mounted",
278
+ "beforeUpdate",
279
+ "updated",
280
+ "beforeUnmount",
281
+ "unmounted",
282
+ "errorCaptured",
283
+ "renderTracked",
284
+ "renderTriggered",
285
+ "activated",
286
+ "deactivated",
287
+ "setup",
288
+ "data",
289
+ "render"
290
+ ];
291
+ var BASE_DEPENDENCIES = [
292
+ "react",
293
+ "react-dom",
294
+ "@variousjs/various",
295
+ "app"
296
+ ];
297
+ //#endregion
298
+ //#region src/core/logger.ts
299
+ var logger = (args) => {
300
+ var _middlewares$onLog;
301
+ const middlewares = connector_default.getMiddlewares();
302
+ if ((middlewares === null || middlewares === void 0 || (_middlewares$onLog = middlewares.onLog) === null || _middlewares$onLog === void 0 ? void 0 : _middlewares$onLog.call(middlewares, args)) === false) return;
303
+ const color = {
304
+ info: "blue",
305
+ warn: "orange",
306
+ error: "red"
307
+ }[args.level];
308
+ const params = [`%c ${args.module} `, `background:${color};border:1px solid ${color};padding:1px;border-radius:2px 0 0 2px;color: #fff;`];
309
+ if (args.type) {
310
+ params[0] = `${params[0]}%c ${args.type} %c`;
311
+ params.push(`border:1px solid ${color};padding:1px;border-radius:0 2px 2px 0;color:${color};`, "background:transparent");
312
+ }
313
+ if (args.level !== "info") params[0] = ` ${params[0]}`;
314
+ window.console[args.level](...params, args.message);
333
315
  };
334
- const ErrorFallback = ({
335
- $error,
336
- $reload,
337
- $self
338
- }) => {
339
- const className = (0,_helper__WEBPACK_IMPORTED_MODULE_1__.getClassNameWithModule)($self.module, 'various-component-error_fallback');
340
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
341
- className: className
342
- }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h3", null, $error.type), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", null, $error.message), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("button", {
343
- type: "button",
344
- onClick: $reload
345
- }, "Reload"));
316
+ var createLogger = (module) => ({
317
+ info(message, type) {
318
+ logger({
319
+ module,
320
+ level: "info",
321
+ type,
322
+ message
323
+ });
324
+ },
325
+ warn(message, type) {
326
+ logger({
327
+ module,
328
+ level: "warn",
329
+ type,
330
+ message
331
+ });
332
+ },
333
+ error(message, type) {
334
+ var _middlewares$onError;
335
+ const middlewares = connector_default.getMiddlewares();
336
+ const error = message instanceof VariousError ? message : new VariousError({
337
+ module,
338
+ type: type || "unknow",
339
+ originalError: message instanceof Error ? message : new Error(message)
340
+ });
341
+ middlewares === null || middlewares === void 0 || (_middlewares$onError = middlewares.onError) === null || _middlewares$onError === void 0 || _middlewares$onError.call(middlewares, error);
342
+ logger({
343
+ module,
344
+ level: "error",
345
+ type,
346
+ message
347
+ });
348
+ }
349
+ });
350
+ //#endregion
351
+ //#region src/core/message.ts
352
+ var createPostMessage = (module) => async ({ event, payload }) => {
353
+ const middlewares = connector_default.getMiddlewares();
354
+ const logger = createLogger(module);
355
+ let next = {
356
+ trigger: module,
357
+ event,
358
+ payload
359
+ };
360
+ if (middlewares === null || middlewares === void 0 ? void 0 : middlewares.onMessage) {
361
+ const check = await middlewares.onMessage(next);
362
+ if (check === false) {
363
+ logger.warn("blocked by middleware", "POST_MESSAGE");
364
+ return;
365
+ }
366
+ if (check !== true) next = _objectSpread2(_objectSpread2({}, next), check);
367
+ }
368
+ emit({ [MESSAGE_KEY]: {
369
+ timestamp: +/* @__PURE__ */ new Date(),
370
+ event: next.event,
371
+ trigger: module,
372
+ payload: next.payload
373
+ } });
346
374
  };
347
- const Root = () => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", null, "App Container is not defined");
348
-
349
- /***/ }),
350
-
351
- /***/ "./src/core/dispatch.ts":
352
- /*!******************************!*\
353
- !*** ./src/core/dispatch.ts ***!
354
- \******************************/
355
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
356
-
357
- "use strict";
358
- __webpack_require__.r(__webpack_exports__);
359
- /* harmony import */ var _connector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./connector */ "./src/core/connector.ts");
360
- /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./store */ "./src/core/store.ts");
361
- /* harmony import */ var _helper__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./helper */ "./src/core/helper.ts");
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
-
365
-
366
-
367
-
368
-
369
- const createDispatch = module => async function (params) {
370
- const middlewares = _connector__WEBPACK_IMPORTED_MODULE_0__["default"].getMiddlewares();
371
- const logger = (0,_logger__WEBPACK_IMPORTED_MODULE_3__["default"])(module);
372
- let {
373
- action,
374
- payload,
375
- target
376
- } = params;
377
- if (middlewares?.onDispatch) {
378
- const check = await middlewares.onDispatch({
379
- target,
380
- action,
381
- payload,
382
- trigger: module
383
- });
384
- if (check === false) {
385
- logger.warn('blocked by middleware', 'DISPATCH');
386
- return Promise.resolve();
387
- }
388
- if (check !== true) {
389
- target = check.target;
390
- action = check.action;
391
- payload = check.payload;
392
- }
393
- }
394
- if (target === 'app') {
395
- const storeActions = _connector__WEBPACK_IMPORTED_MODULE_0__["default"].getStoreActions();
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
- }
417
- if (!storeAction) {
418
- const errorMessage = `action "${action}" is not present`;
419
- const error = new _helper__WEBPACK_IMPORTED_MODULE_2__.VariousError({
420
- module,
421
- type: 'DISPATCH',
422
- originalError: new Error(errorMessage)
423
- });
424
- (0,_helper__WEBPACK_IMPORTED_MODULE_2__.onError)(error);
425
- throw error;
426
- }
427
- return (0,_store__WEBPACK_IMPORTED_MODULE_1__.dispatch)(storeAction, payload, module);
428
- }
429
- const componentActions = _connector__WEBPACK_IMPORTED_MODULE_0__["default"].getComponentActions(target);
430
- if (!componentActions) {
431
- const errorMessage = 'component is not ready';
432
- const error = new _helper__WEBPACK_IMPORTED_MODULE_2__.VariousError({
433
- module,
434
- type: 'DISPATCH',
435
- originalError: new Error(errorMessage)
436
- });
437
- (0,_helper__WEBPACK_IMPORTED_MODULE_2__.onError)(error);
438
- throw error;
439
- }
440
- const componentAction = componentActions[action];
441
- if (!componentAction) {
442
- const errorMessage = `action "${action}" is not present`;
443
- const error = new _helper__WEBPACK_IMPORTED_MODULE_2__.VariousError({
444
- module,
445
- type: 'DISPATCH',
446
- originalError: new Error(errorMessage)
447
- });
448
- (0,_helper__WEBPACK_IMPORTED_MODULE_2__.onError)(error);
449
- throw error;
450
- }
451
- return Promise.resolve(componentAction({
452
- payload,
453
- trigger: module
454
- }));
375
+ var createOnMessage = (module, onMessage) => subscribe({ [MESSAGE_KEY](v) {
376
+ const { trigger, payload, event } = v;
377
+ if (module !== trigger) onMessage({
378
+ event,
379
+ payload,
380
+ trigger
381
+ });
382
+ } });
383
+ //#endregion
384
+ //#region src/core/i18n.ts
385
+ function createI18nConfig(method, module, callback) {
386
+ if (!method) return;
387
+ const i18nConfig = method();
388
+ if (!isPromiseLike(i18nConfig)) {
389
+ if (module) connector_default.setI18nConfig(module, i18nConfig);
390
+ else connector_default.setGlobalI18nConfig(i18nConfig);
391
+ return;
392
+ }
393
+ if (module) connector_default.setI18nConfig(module, {
394
+ loading: true,
395
+ resources: {}
396
+ });
397
+ else connector_default.setGlobalI18nConfig({
398
+ loading: true,
399
+ resources: {}
400
+ });
401
+ i18nConfig.then((res) => {
402
+ if (module) {
403
+ connector_default.setI18nConfig(module, _objectSpread2(_objectSpread2({}, res), {}, { loading: false }));
404
+ callback === null || callback === void 0 || callback();
405
+ return;
406
+ }
407
+ const locale = getStore(LOCALE_KEY);
408
+ emit({ [LOCALE_KEY]: void 0 }, true);
409
+ emit({ [LOCALE_KEY]: locale }, true);
410
+ connector_default.setGlobalI18nConfig(_objectSpread2(_objectSpread2({}, res), {}, { loading: false }));
411
+ }).catch((e) => {
412
+ onError(new VariousError({
413
+ module: module || "app",
414
+ type: "I18N",
415
+ originalError: e
416
+ }));
417
+ });
418
+ }
419
+ function createI18n(module, updater) {
420
+ const ctx = (key, params, defaultString) => {
421
+ const i18nConfig = connector_default.getI18nConfig(module) || connector_default.getGlobalI18nConfig();
422
+ let defaultText = defaultString;
423
+ if (defaultText === void 0) defaultText = typeof params === "string" ? params : key;
424
+ if (!i18nConfig) {
425
+ onError(new VariousError({
426
+ module,
427
+ type: "I18N",
428
+ originalError: /* @__PURE__ */ new Error("config not exist")
429
+ }));
430
+ return defaultText;
431
+ }
432
+ if (i18nConfig.loading) return defaultText;
433
+ const { resources } = i18nConfig;
434
+ const locale = getStore(LOCALE_KEY);
435
+ const resource = resources === null || resources === void 0 ? void 0 : resources[locale];
436
+ if (!resource) {
437
+ onError(new VariousError({
438
+ module,
439
+ type: "I18N",
440
+ originalError: /* @__PURE__ */ new Error(`locale resource \`${locale}\` not exist`)
441
+ }));
442
+ return defaultText;
443
+ }
444
+ if (!resource[key]) {
445
+ onError(new VariousError({
446
+ module,
447
+ type: "I18N",
448
+ originalError: /* @__PURE__ */ new Error(`locale key \`${key}\` not exist`)
449
+ }));
450
+ return defaultText;
451
+ }
452
+ const text = resource[key];
453
+ if (!params || typeof params === "string" || Object.prototype.toString.call(params) !== "[object Object]") return text;
454
+ const args = Object.keys(params);
455
+ if (!args.length) return text;
456
+ return args.reduce((next, arg) => {
457
+ const regex = new RegExp(`{\\s*${arg}\\s*}`, "g");
458
+ return next.replace(regex, params[arg].toString());
459
+ }, text);
460
+ };
461
+ ctx.update = (config) => {
462
+ const next = _objectSpread2(_objectSpread2({}, connector_default.getI18nConfig(module)), config);
463
+ connector_default.setI18nConfig(module, next);
464
+ updater();
465
+ };
466
+ return ctx;
467
+ }
468
+ //#endregion
469
+ //#region \0vite/preload-helper.js
470
+ var scriptRel = "modulepreload";
471
+ var assetsURL = function(dep) {
472
+ return "/" + dep;
455
473
  };
456
- /* harmony default export */ __webpack_exports__["default"] = (createDispatch);
457
-
458
- /***/ }),
459
-
460
- /***/ "./src/core/error-boundary.tsx":
461
- /*!*************************************!*\
462
- !*** ./src/core/error-boundary.tsx ***!
463
- \*************************************/
464
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
465
-
466
- "use strict";
467
- __webpack_require__.r(__webpack_exports__);
468
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
469
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
470
- /* harmony import */ var _helper__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helper */ "./src/core/helper.ts");
471
- /* harmony import */ var _connector__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./connector */ "./src/core/connector.ts");
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
-
475
-
476
-
477
-
478
-
479
- class ErrorBoundary extends react__WEBPACK_IMPORTED_MODULE_0__.Component {
480
- static displayName = 'various-error-boundary';
481
- state = {
482
- hasError: false
483
- };
484
- componentDidCatch(e) {
485
- const {
486
- module
487
- } = this.props;
488
- const error = e instanceof _helper__WEBPACK_IMPORTED_MODULE_1__.VariousError ? e : new _helper__WEBPACK_IMPORTED_MODULE_1__.VariousError({
489
- module,
490
- type: module === 'app' ? 'APP_ERROR' : 'SCRIPT_ERROR',
491
- originalError: e
492
- });
493
- this.setState({
494
- hasError: true
495
- });
496
- this.error = error;
497
- (0,_helper__WEBPACK_IMPORTED_MODULE_1__.onError)(error);
498
- (0,_helper__WEBPACK_IMPORTED_MODULE_1__.resetDependencyConfig)(module);
499
- (0,_helper__WEBPACK_IMPORTED_MODULE_1__.updateUnMountComponent)(module);
500
- }
501
- $self = (0,_helper__WEBPACK_IMPORTED_MODULE_1__.getSelfInfo)(this.props);
502
- reload = () => {
503
- this.error = undefined;
504
- this.setState({
505
- hasError: false
506
- });
507
- };
508
- render() {
509
- const ErrorFallbackNode = _connector__WEBPACK_IMPORTED_MODULE_2__["default"].getErrorFallbackComponent();
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);
512
- if (this.state.hasError) {
513
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(ErrorFallbackNode, {
514
- $self: this.$self,
515
- $reload: this.reload,
516
- $store: store,
517
- $error: this.error,
518
- $locale: locale
519
- });
520
- }
521
- return this.props.children;
522
- }
474
+ var seen = {};
475
+ var __vitePreload = function preload(baseModule, deps, importerUrl) {
476
+ let promise = Promise.resolve();
477
+ if (deps && deps.length > 0) {
478
+ const links = document.getElementsByTagName("link");
479
+ const cspNonceMeta = document.querySelector("meta[property=csp-nonce]");
480
+ const cspNonce = (cspNonceMeta === null || cspNonceMeta === void 0 ? void 0 : cspNonceMeta.nonce) || (cspNonceMeta === null || cspNonceMeta === void 0 ? void 0 : cspNonceMeta.getAttribute("nonce"));
481
+ function allSettled(promises) {
482
+ return Promise.all(promises.map((p) => Promise.resolve(p).then((value) => ({
483
+ status: "fulfilled",
484
+ value
485
+ }), (reason) => ({
486
+ status: "rejected",
487
+ reason
488
+ }))));
489
+ }
490
+ function importMetaResolve(specifier) {
491
+ if (import.meta.resolve) return import.meta.resolve(specifier);
492
+ return new URL(
493
+ specifier,
494
+ /** #__KEEP__ */
495
+ import.meta.url
496
+ ).href;
497
+ }
498
+ promise = allSettled(deps.map((dep) => {
499
+ dep = assetsURL(dep, importerUrl);
500
+ dep = importMetaResolve(dep);
501
+ if (dep in seen) return;
502
+ seen[dep] = true;
503
+ const isCss = dep.endsWith(".css");
504
+ for (let i = links.length - 1; i >= 0; i--) {
505
+ const link = links[i];
506
+ if (link.href === dep && (!isCss || link.rel === "stylesheet")) return;
507
+ }
508
+ const link = document.createElement("link");
509
+ link.rel = isCss ? "stylesheet" : scriptRel;
510
+ if (!isCss) link.as = "script";
511
+ link.crossOrigin = "";
512
+ link.href = dep;
513
+ if (cspNonce) link.setAttribute("nonce", cspNonce);
514
+ document.head.appendChild(link);
515
+ if (isCss) return new Promise((res, rej) => {
516
+ link.addEventListener("load", res);
517
+ link.addEventListener("error", () => rej(/* @__PURE__ */ new Error(`Unable to preload CSS for ${dep}`)));
518
+ });
519
+ }));
520
+ }
521
+ function handlePreloadError(err) {
522
+ const e = new Event("vite:preloadError", { cancelable: true });
523
+ e.payload = err;
524
+ window.dispatchEvent(e);
525
+ if (!e.defaultPrevented) throw err;
526
+ }
527
+ return promise.then((res) => {
528
+ for (const item of res || []) {
529
+ if (item.status !== "rejected") continue;
530
+ handlePreloadError(item.reason);
531
+ }
532
+ return baseModule().catch(handlePreloadError);
533
+ });
534
+ };
535
+ //#endregion
536
+ //#region src/core/system.ts
537
+ function getRegistry() {
538
+ if (!window.__various) window.__various = {
539
+ modules: /* @__PURE__ */ new Map(),
540
+ urls: /* @__PURE__ */ new Map(),
541
+ loaded: /* @__PURE__ */ new Map()
542
+ };
543
+ return window.__various;
523
544
  }
524
- /* harmony default export */ __webpack_exports__["default"] = (ErrorBoundary);
525
-
526
- /***/ }),
527
-
528
- /***/ "./src/core/helper.ts":
529
- /*!****************************!*\
530
- !*** ./src/core/helper.ts ***!
531
- \****************************/
532
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
533
-
534
- "use strict";
535
- __webpack_require__.r(__webpack_exports__);
536
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
537
- /* harmony export */ VariousError: function() { return /* binding */ VariousError; },
538
- /* harmony export */ checkReactComponent: function() { return /* binding */ checkReactComponent; },
539
- /* harmony export */ checkVueComponent: function() { return /* binding */ checkVueComponent; },
540
- /* harmony export */ defineDependencies: function() { return /* binding */ defineDependencies; },
541
- /* harmony export */ getClassNameWithModule: function() { return /* binding */ getClassNameWithModule; },
542
- /* harmony export */ getConfig: function() { return /* binding */ getConfig; },
543
- /* harmony export */ getModuleInfo: function() { return /* binding */ getModuleInfo; },
544
- /* harmony export */ getMountedComponents: function() { return /* binding */ getMountedComponents; },
545
- /* harmony export */ getSelfInfo: function() { return /* binding */ getSelfInfo; },
546
- /* harmony export */ isModuleLoaded: function() { return /* binding */ isModuleLoaded; },
547
- /* harmony export */ isModuleSpecified: function() { return /* binding */ isModuleSpecified; },
548
- /* harmony export */ isPromiseLike: function() { return /* binding */ isPromiseLike; },
549
- /* harmony export */ onComponentMounted: function() { return /* binding */ onComponentMounted; },
550
- /* harmony export */ onError: function() { return /* binding */ onError; },
551
- /* harmony export */ parseComponentActions: function() { return /* binding */ parseComponentActions; },
552
- /* harmony export */ preloadModules: function() { return /* binding */ preloadModules; },
553
- /* harmony export */ removeLoadedModules: function() { return /* binding */ removeLoadedModules; },
554
- /* harmony export */ resetDependencyConfig: function() { return /* binding */ resetDependencyConfig; },
555
- /* harmony export */ updateMountedComponent: function() { return /* binding */ updateMountedComponent; },
556
- /* harmony export */ updateUnMountComponent: function() { return /* binding */ updateUnMountComponent; }
557
- /* harmony export */ });
558
- /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./store */ "./src/core/store.ts");
559
- /* harmony import */ var _logger__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./logger */ "./src/core/logger.ts");
560
- /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./config */ "./src/core/config.ts");
561
- /* harmony import */ var _connector__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./connector */ "./src/core/connector.ts");
562
- /* harmony import */ var _message__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./message */ "./src/core/message.ts");
563
- /* harmony import */ var _i18n__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./i18n */ "./src/core/i18n.ts");
564
-
565
-
566
-
567
-
568
-
569
-
570
- const getUrlHash = url => `${url}?${+new Date()}`;
571
- const getModuleInfo = module => {
572
- const [name, entry] = module.split('.');
573
- return {
574
- name,
575
- entry
576
- };
545
+ var { modules: moduleRegistry, urls: moduleUrls, loaded: loadedModules } = getRegistry();
546
+ function resolveUrl(url) {
547
+ if (url.startsWith("http") || url.startsWith("/") || url.startsWith("blob:")) return url;
548
+ return new URL(url, document.baseURI).href;
549
+ }
550
+ function setModuleUrl(name, url) {
551
+ moduleUrls.set(name, url);
552
+ }
553
+ function getModuleUrl(name) {
554
+ return moduleUrls.get(name);
555
+ }
556
+ async function importModule(name) {
557
+ const url = moduleUrls.get(name);
558
+ if (url) {
559
+ const absoluteUrl = resolveUrl(url);
560
+ if (loadedModules.has(absoluteUrl)) return loadedModules.get(absoluteUrl);
561
+ const mod = await __vitePreload(() => import(
562
+ /* @vite-ignore */
563
+ absoluteUrl
564
+ ), []);
565
+ loadedModules.set(absoluteUrl, mod);
566
+ return mod;
567
+ }
568
+ if (moduleRegistry.has(name)) return moduleRegistry.get(name);
569
+ throw new Error(`module "${name}" not defined`);
570
+ }
571
+ function isModuleDefined(name) {
572
+ if (moduleRegistry.has(name)) return true;
573
+ const url = moduleUrls.get(name);
574
+ if (url && loadedModules.has(resolveUrl(url))) return true;
575
+ return false;
576
+ }
577
+ function isModuleSpecified$1(name) {
578
+ return moduleUrls.has(name) || isModuleDefined(name);
579
+ }
580
+ function deleteModule(name) {
581
+ moduleRegistry.delete(name);
582
+ const url = moduleUrls.get(name);
583
+ if (url) loadedModules.delete(resolveUrl(url));
584
+ }
585
+ //#endregion
586
+ //#region src/core/helper.ts
587
+ var getUrlHash = (url) => `${url}?${+/* @__PURE__ */ new Date()}`;
588
+ var getModuleInfo = (module) => {
589
+ const [name, entry] = module.split(".");
590
+ return {
591
+ name,
592
+ entry
593
+ };
577
594
  };
578
- const preloadModules = modules => new Promise((resolve, reject) => {
579
- const names = modules.map(m => getModuleInfo(m).name);
580
- window.requirejs(names, resolve, reject);
581
- });
582
- const removeLoadedModules = modules => {
583
- modules.forEach(module => {
584
- const {
585
- name
586
- } = getModuleInfo(module);
587
- if (!_config__WEBPACK_IMPORTED_MODULE_2__.BASE_DEPENDENCIES.includes(name)) {
588
- window.requirejs.undef(name);
589
- }
590
- });
595
+ var preloadModules = (modules) => {
596
+ const names = modules.map((m) => getModuleInfo(m).name);
597
+ return Promise.all(names.map((n) => importModule(n))).then(() => void 0);
591
598
  };
592
- const defineDependencies = deps => {
593
- const dependencies = (0,_store__WEBPACK_IMPORTED_MODULE_0__.getStore)(_config__WEBPACK_IMPORTED_MODULE_2__.DEPENDENCIES_KEY);
594
- const next = {};
595
- Object.keys(deps).forEach(name => {
596
- if (!_config__WEBPACK_IMPORTED_MODULE_2__.BASE_DEPENDENCIES.includes(name)) {
597
- next[name] = `${deps[name]}#${name}`;
598
- window.requirejs.undef(name);
599
- }
600
- });
601
- window.requirejs.config({
602
- paths: next
603
- });
604
- (0,_store__WEBPACK_IMPORTED_MODULE_0__.emit)({
605
- [_config__WEBPACK_IMPORTED_MODULE_2__.DEPENDENCIES_KEY]: {
606
- ...dependencies,
607
- ...next
608
- }
609
- }, true);
599
+ var removeLoadedModules = (modules) => {
600
+ modules.forEach((module) => {
601
+ const { name } = getModuleInfo(module);
602
+ if (!BASE_DEPENDENCIES.includes(name)) deleteModule(name);
603
+ });
610
604
  };
611
- const isModuleLoaded = module => {
612
- const {
613
- name
614
- } = getModuleInfo(module);
615
- return window.requirejs.defined(name);
605
+ var defineDependencies = (deps) => {
606
+ const dependencies = getStore(DEPENDENCIES_KEY);
607
+ const next = {};
608
+ Object.keys(deps).forEach((name) => {
609
+ if (!BASE_DEPENDENCIES.includes(name)) {
610
+ next[name] = deps[name];
611
+ if (getModuleUrl(name) !== deps[name]) deleteModule(name);
612
+ setModuleUrl(name, deps[name]);
613
+ }
614
+ });
615
+ emit({ [DEPENDENCIES_KEY]: _objectSpread2(_objectSpread2({}, dependencies), next) }, true);
616
616
  };
617
- const isModuleSpecified = module => {
618
- const {
619
- name
620
- } = getModuleInfo(module);
621
- return window.requirejs.specified(name);
617
+ var isModuleLoaded = (module) => {
618
+ const { name } = getModuleInfo(module);
619
+ return isModuleDefined(name);
622
620
  };
623
- const getMountedComponents = () => (0,_store__WEBPACK_IMPORTED_MODULE_0__.getStore)(_config__WEBPACK_IMPORTED_MODULE_2__.MOUNTED_COMPONENTS_KEY);
624
- const onComponentMounted = (module, callback) => {
625
- const modules = Array.isArray(module) ? module : [module];
626
- if (modules.every(m => getMountedComponents().includes(m))) {
627
- callback();
628
- }
629
- const unSubscribe = (0,_store__WEBPACK_IMPORTED_MODULE_0__.subscribe)({
630
- [_config__WEBPACK_IMPORTED_MODULE_2__.MOUNTED_COMPONENTS_KEY](value) {
631
- if (modules.every(n => value.includes(n))) {
632
- unSubscribe();
633
- callback();
634
- }
635
- }
636
- });
637
- return unSubscribe;
621
+ var isModuleSpecified = (module) => {
622
+ const { name } = getModuleInfo(module);
623
+ return isModuleSpecified$1(name);
638
624
  };
639
- const resetDependencyConfig = (module, url) => {
640
- const {
641
- name
642
- } = getModuleInfo(module);
643
- const dependencies = (0,_store__WEBPACK_IMPORTED_MODULE_0__.getStore)(_config__WEBPACK_IMPORTED_MODULE_2__.DEPENDENCIES_KEY);
644
-
645
- // ignore multiple custom module url
646
- if (url && isModuleLoaded(name)) {
647
- return;
648
- }
649
- if (!dependencies[name] && url) {
650
- window.requirejs.config({
651
- paths: {
652
- [name]: `${url}#${name}`
653
- }
654
- });
655
- return;
656
- }
657
- let path = getUrlHash(dependencies[name]);
658
- if (url) {
659
- path = getUrlHash(`${url}#${name}`);
660
- }
661
- window.requirejs.undef(name);
662
- window.requirejs.config({
663
- paths: {
664
- [name]: path
665
- }
666
- });
625
+ var getMountedComponents = () => getStore(MOUNTED_COMPONENTS_KEY);
626
+ var onComponentMounted = (module, callback) => {
627
+ const modules = Array.isArray(module) ? module : [module];
628
+ if (modules.every((m) => getMountedComponents().includes(m))) callback();
629
+ const unSubscribe = subscribe({ [MOUNTED_COMPONENTS_KEY](value) {
630
+ if (modules.every((n) => value.includes(n))) {
631
+ unSubscribe();
632
+ callback();
633
+ }
634
+ } });
635
+ return unSubscribe;
636
+ };
637
+ var resetDependencyConfig = (module, url) => {
638
+ const { name } = getModuleInfo(module);
639
+ const dependencies = getStore(DEPENDENCIES_KEY);
640
+ if (url && isModuleDefined(name)) return;
641
+ if (!dependencies[name] && url) {
642
+ setModuleUrl(name, url);
643
+ return;
644
+ }
645
+ let moduleUrl = getUrlHash(dependencies[name]);
646
+ if (url) moduleUrl = getUrlHash(url);
647
+ deleteModule(name);
648
+ setModuleUrl(name, moduleUrl);
667
649
  };
668
650
  function getConfig() {
669
- return (0,_store__WEBPACK_IMPORTED_MODULE_0__.getStore)(_config__WEBPACK_IMPORTED_MODULE_2__.CONFIG_KEY);
651
+ return getStore(CONFIG_KEY);
670
652
  }
671
- const onError = e => {
672
- const {
673
- module,
674
- type
675
- } = e;
676
- const logger = (0,_logger__WEBPACK_IMPORTED_MODULE_1__["default"])(module);
677
- logger.error(e, type);
653
+ var onError = (e) => {
654
+ const { module, type } = e;
655
+ createLogger(module).error(e, type);
656
+ };
657
+ var VariousError = class extends Error {
658
+ constructor(data) {
659
+ super(data.originalError.message);
660
+ _defineProperty(this, "type", void 0);
661
+ _defineProperty(this, "originalError", void 0);
662
+ _defineProperty(this, "module", void 0);
663
+ this.type = data.type;
664
+ this.originalError = data.originalError;
665
+ this.module = data.module;
666
+ }
678
667
  };
679
- class VariousError extends Error {
680
- constructor(data) {
681
- super(data.originalError.message);
682
- this.type = data.type;
683
- this.originalError = data.originalError;
684
- this.module = data.module;
685
- }
686
- }
687
668
  function checkReactComponent(component, module) {
688
- return new Promise((reslove, reject) => {
689
- if (component.$$typeof || component.prototype?.isReactComponent || typeof component === 'function') {
690
- reslove();
691
- return;
692
- }
693
- reject(new VariousError({
694
- module,
695
- originalError: new Error('not a valid React component'),
696
- type: 'INVALID_COMPONENT'
697
- }));
698
- });
669
+ return new Promise((reslove, reject) => {
670
+ var _component$prototype;
671
+ if (component.$$typeof || ((_component$prototype = component.prototype) === null || _component$prototype === void 0 ? void 0 : _component$prototype.isReactComponent) || typeof component === "function") {
672
+ reslove();
673
+ return;
674
+ }
675
+ reject(new VariousError({
676
+ module,
677
+ originalError: /* @__PURE__ */ new Error("not a valid React component"),
678
+ type: "INVALID_COMPONENT"
679
+ }));
680
+ });
699
681
  }
700
682
  function isPromiseLike(value) {
701
- return value != null && typeof value.then === 'function';
683
+ return value != null && typeof value.then === "function";
702
684
  }
703
685
  function checkVueComponent(component, module) {
704
- const versionRegex = new RegExp(`^${_config__WEBPACK_IMPORTED_MODULE_2__.VUE_VERSION}\\.`);
705
- return new Promise((resolve, reject) => {
706
- window.requirejs(['vue'], Vue => {
707
- if (!versionRegex.test(Vue.version)) {
708
- reject(new Error(`Vue ${_config__WEBPACK_IMPORTED_MODULE_2__.VUE_VERSION}+ required, detected an incompatible version`));
709
- }
710
- if (typeof component?.render === 'function' || typeof component?.setup === 'function') {
711
- resolve();
712
- return;
713
- }
714
- reject(new VariousError({
715
- module,
716
- originalError: new Error('not a valid Vue component'),
717
- type: 'INVALID_COMPONENT'
718
- }));
719
- });
720
- });
686
+ const versionRegex = new RegExp(`^3\\.`);
687
+ return new Promise((resolve, reject) => {
688
+ importModule("vue").then((Vue) => {
689
+ const vueObj = Vue.default || Vue;
690
+ if (!versionRegex.test(vueObj.version)) {
691
+ reject(/* @__PURE__ */ new Error(`Vue 3+ required, detected an incompatible version`));
692
+ return;
693
+ }
694
+ if (typeof (component === null || component === void 0 ? void 0 : component.render) === "function" || typeof (component === null || component === void 0 ? void 0 : component.setup) === "function") {
695
+ resolve();
696
+ return;
697
+ }
698
+ reject(new VariousError({
699
+ module,
700
+ originalError: /* @__PURE__ */ new Error("not a valid Vue component"),
701
+ type: "INVALID_COMPONENT"
702
+ }));
703
+ }).catch(reject);
704
+ });
721
705
  }
722
706
  function parseComponentActions(params) {
723
- const {
724
- componentNode,
725
- module,
726
- type,
727
- i18nUpdate
728
- } = params;
729
- const actions = {};
730
- let onMessageAction;
731
- let i18nAction;
732
- Object.getOwnPropertyNames(componentNode).forEach(method => {
733
- if (typeof componentNode[method] !== 'function') {
734
- return;
735
- }
736
- if (method === '$onMessage') {
737
- onMessageAction = componentNode[method];
738
- return;
739
- }
740
- if (method === '$i18n') {
741
- i18nAction = componentNode[method];
742
- return;
743
- }
744
- if (type === 'vue3' && _config__WEBPACK_IMPORTED_MODULE_2__.VUE_FUNCTION_OPTIONS.includes(method)) {
745
- return;
746
- }
747
- actions[method] = componentNode[method];
748
- });
749
- if (i18nAction) {
750
- (0,_i18n__WEBPACK_IMPORTED_MODULE_5__.createI18nConfig)(i18nAction, module, i18nUpdate);
751
- }
752
- _connector__WEBPACK_IMPORTED_MODULE_3__["default"].setComponentActions(module, actions);
753
- if (onMessageAction) {
754
- return (0,_message__WEBPACK_IMPORTED_MODULE_4__.createOnMessage)(module, onMessageAction);
755
- }
756
- return () => null;
707
+ const { componentNode, module, type, i18nUpdate } = params;
708
+ const actions = {};
709
+ let onMessageAction;
710
+ let i18nAction;
711
+ Object.getOwnPropertyNames(componentNode).forEach((method) => {
712
+ if (typeof componentNode[method] !== "function") return;
713
+ if (method === "$onMessage") {
714
+ onMessageAction = componentNode[method];
715
+ return;
716
+ }
717
+ if (method === "$i18n") {
718
+ i18nAction = componentNode[method];
719
+ return;
720
+ }
721
+ if (type === "vue3" && VUE_FUNCTION_OPTIONS.includes(method)) return;
722
+ actions[method] = componentNode[method];
723
+ });
724
+ if (i18nAction) createI18nConfig(i18nAction, module, i18nUpdate);
725
+ connector_default.setComponentActions(module, actions);
726
+ if (onMessageAction) return createOnMessage(module, onMessageAction);
727
+ return () => null;
757
728
  }
758
729
  function updateMountedComponent(module) {
759
- const mountedComponents = getMountedComponents();
760
- if (!mountedComponents.includes(module)) {
761
- mountedComponents.push(module);
762
- }
763
- (0,_store__WEBPACK_IMPORTED_MODULE_0__.emit)({
764
- [_config__WEBPACK_IMPORTED_MODULE_2__.MOUNTED_COMPONENTS_KEY]: mountedComponents
765
- }, true);
730
+ const mountedComponents = getMountedComponents();
731
+ if (!mountedComponents.includes(module)) mountedComponents.push(module);
732
+ emit({ [MOUNTED_COMPONENTS_KEY]: mountedComponents }, true);
766
733
  }
767
734
  function updateUnMountComponent(module) {
768
- let mountedComponents = getMountedComponents();
769
- mountedComponents = mountedComponents.filter(item => item !== module);
770
- (0,_store__WEBPACK_IMPORTED_MODULE_0__.emit)({
771
- [_config__WEBPACK_IMPORTED_MODULE_2__.MOUNTED_COMPONENTS_KEY]: mountedComponents
772
- }, true);
773
- _connector__WEBPACK_IMPORTED_MODULE_3__["default"].deleteComponentActions(module);
735
+ let mountedComponents = getMountedComponents();
736
+ mountedComponents = mountedComponents.filter((item) => item !== module);
737
+ emit({ [MOUNTED_COMPONENTS_KEY]: mountedComponents }, true);
738
+ connector_default.deleteComponentActions(module);
774
739
  }
775
740
  function getSelfInfo(params) {
776
- const {
777
- module,
778
- url
779
- } = params;
780
- const dependencies = (0,_store__WEBPACK_IMPORTED_MODULE_0__.getStore)(_config__WEBPACK_IMPORTED_MODULE_2__.DEPENDENCIES_KEY);
781
- const {
782
- name
783
- } = getModuleInfo(module);
784
- return {
785
- module,
786
- url: url || dependencies[name]
787
- };
741
+ const { module, url } = params;
742
+ const dependencies = getStore(DEPENDENCIES_KEY);
743
+ const { name } = getModuleInfo(module);
744
+ return {
745
+ module,
746
+ url: url || dependencies[name] || getModuleUrl(name) || ""
747
+ };
788
748
  }
789
749
  function getClassNameWithModule(module, prefix) {
790
- const {
791
- name,
792
- entry
793
- } = getModuleInfo(module);
794
- return `${prefix} ${[name, entry].filter(Boolean).join('-')}`;
750
+ const { name, entry } = getModuleInfo(module);
751
+ return `${prefix} ${[name, entry].filter(Boolean).join("-")}`;
795
752
  }
796
-
797
- /***/ }),
798
-
799
- /***/ "./src/core/i18n.ts":
800
- /*!**************************!*\
801
- !*** ./src/core/i18n.ts ***!
802
- \**************************/
803
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
804
-
805
- "use strict";
806
- __webpack_require__.r(__webpack_exports__);
807
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
808
- /* harmony export */ createI18n: function() { return /* binding */ createI18n; },
809
- /* harmony export */ createI18nConfig: function() { return /* binding */ createI18nConfig; }
810
- /* harmony export */ });
811
- /* harmony import */ var _connector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./connector */ "./src/core/connector.ts");
812
- /* harmony import */ var _helper__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helper */ "./src/core/helper.ts");
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
-
816
-
817
-
818
-
819
- function createI18nConfig(method, module, callback) {
820
- if (!method) {
821
- return;
822
- }
823
- const i18nConfig = method();
824
- if (!(0,_helper__WEBPACK_IMPORTED_MODULE_1__.isPromiseLike)(i18nConfig)) {
825
- if (module) {
826
- _connector__WEBPACK_IMPORTED_MODULE_0__["default"].setI18nConfig(module, i18nConfig);
827
- } else {
828
- _connector__WEBPACK_IMPORTED_MODULE_0__["default"].setGlobalI18nConfig(i18nConfig);
829
- }
830
- return;
831
- }
832
- if (module) {
833
- _connector__WEBPACK_IMPORTED_MODULE_0__["default"].setI18nConfig(module, {
834
- loading: true,
835
- resources: {}
836
- });
837
- } else {
838
- _connector__WEBPACK_IMPORTED_MODULE_0__["default"].setGlobalI18nConfig({
839
- loading: true,
840
- resources: {}
841
- });
842
- }
843
- i18nConfig.then(res => {
844
- if (module) {
845
- _connector__WEBPACK_IMPORTED_MODULE_0__["default"].setI18nConfig(module, {
846
- ...res,
847
- loading: false
848
- });
849
- callback?.();
850
- return;
851
- }
852
- const locale = (0,_store__WEBPACK_IMPORTED_MODULE_2__.getStore)(_config__WEBPACK_IMPORTED_MODULE_3__.LOCALE_KEY);
853
- (0,_store__WEBPACK_IMPORTED_MODULE_2__.emit)({
854
- [_config__WEBPACK_IMPORTED_MODULE_3__.LOCALE_KEY]: undefined
855
- }, true);
856
- (0,_store__WEBPACK_IMPORTED_MODULE_2__.emit)({
857
- [_config__WEBPACK_IMPORTED_MODULE_3__.LOCALE_KEY]: locale
858
- }, true);
859
- _connector__WEBPACK_IMPORTED_MODULE_0__["default"].setGlobalI18nConfig({
860
- ...res,
861
- loading: false
862
- });
863
- }).catch(e => {
864
- (0,_helper__WEBPACK_IMPORTED_MODULE_1__.onError)(new _helper__WEBPACK_IMPORTED_MODULE_1__.VariousError({
865
- module: module || 'app',
866
- type: 'I18N',
867
- originalError: e
868
- }));
869
- });
753
+ //#endregion
754
+ //#region src/core/default-component.tsx
755
+ var Fallback = (props) => {
756
+ const className = getClassNameWithModule(props.$self.module, "various-component-fallback");
757
+ return /* @__PURE__ */ e.createElement("div", { className }, "Loading");
758
+ };
759
+ var ErrorFallback = ({ $error, $reload, $self }) => {
760
+ const className = getClassNameWithModule($self.module, "various-component-error_fallback");
761
+ return /* @__PURE__ */ e.createElement("div", { className }, /* @__PURE__ */ e.createElement("h3", null, $error.type), /* @__PURE__ */ e.createElement("p", null, $error.message), /* @__PURE__ */ e.createElement("button", {
762
+ type: "button",
763
+ onClick: $reload
764
+ }, "Reload"));
765
+ };
766
+ var Root = () => /* @__PURE__ */ e.createElement("div", null, "App Container is not defined");
767
+ //#endregion
768
+ //#region src/core/connector.ts
769
+ var Connector = class {
770
+ constructor() {
771
+ _defineProperty(this, "fallbackComponent", void 0);
772
+ _defineProperty(this, "errorFallbackComponent", void 0);
773
+ _defineProperty(this, "storeActions", void 0);
774
+ _defineProperty(this, "componentActions", void 0);
775
+ _defineProperty(this, "i18nConfigs", void 0);
776
+ _defineProperty(this, "globalI18nConfig", void 0);
777
+ _defineProperty(this, "middlewares", void 0);
778
+ this.fallbackComponent = Fallback;
779
+ this.errorFallbackComponent = ErrorFallback;
780
+ this.storeActions = {};
781
+ this.componentActions = {};
782
+ this.i18nConfigs = {};
783
+ this.middlewares = {};
784
+ }
785
+ setMiddlewares(m) {
786
+ this.middlewares = m;
787
+ }
788
+ getMiddlewares() {
789
+ return this.middlewares;
790
+ }
791
+ setI18nConfig(module, config) {
792
+ this.i18nConfigs[module] = _objectSpread2(_objectSpread2({}, this.i18nConfigs[module]), config);
793
+ }
794
+ getI18nConfig(module) {
795
+ return this.i18nConfigs[module];
796
+ }
797
+ setGlobalI18nConfig(config) {
798
+ this.globalI18nConfig = _objectSpread2(_objectSpread2({}, this.globalI18nConfig), config);
799
+ }
800
+ getGlobalI18nConfig() {
801
+ return this.globalI18nConfig;
802
+ }
803
+ setComponentActions(module, actions) {
804
+ this.componentActions[module] = actions;
805
+ }
806
+ deleteComponentActions(module) {
807
+ delete this.componentActions[module];
808
+ }
809
+ getComponentActions(module) {
810
+ return this.componentActions[module];
811
+ }
812
+ setStoreActions(actions) {
813
+ this.storeActions = actions;
814
+ }
815
+ getStoreActions() {
816
+ return this.storeActions;
817
+ }
818
+ setFallbackComponent(fallbackComponent) {
819
+ this.fallbackComponent = fallbackComponent;
820
+ }
821
+ getFallbackComponent() {
822
+ return this.fallbackComponent;
823
+ }
824
+ setErrorFallbackComponent(errorFallbackComponent) {
825
+ this.errorFallbackComponent = errorFallbackComponent;
826
+ }
827
+ getErrorFallbackComponent() {
828
+ return this.errorFallbackComponent;
829
+ }
830
+ };
831
+ var connector_default = new Connector();
832
+ //#endregion
833
+ //#region src/core/error-boundary.tsx
834
+ var ErrorBoundary = class extends Component {
835
+ constructor(..._args) {
836
+ super(..._args);
837
+ _defineProperty(this, "state", { hasError: false });
838
+ _defineProperty(this, "error", void 0);
839
+ _defineProperty(this, "$self", getSelfInfo(this.props));
840
+ _defineProperty(this, "reload", () => {
841
+ this.error = void 0;
842
+ this.setState({ hasError: false });
843
+ });
844
+ }
845
+ componentDidCatch(e) {
846
+ const { module } = this.props;
847
+ const error = e instanceof VariousError ? e : new VariousError({
848
+ module,
849
+ type: module === "app" ? "APP_ERROR" : "SCRIPT_ERROR",
850
+ originalError: e
851
+ });
852
+ this.setState({ hasError: true });
853
+ this.error = error;
854
+ onError(error);
855
+ resetDependencyConfig(module);
856
+ updateUnMountComponent(module);
857
+ }
858
+ render() {
859
+ const ErrorFallbackNode = connector_default.getErrorFallbackComponent();
860
+ const store = getUserStore();
861
+ const locale = getStore(LOCALE_KEY);
862
+ if (this.state.hasError) return /* @__PURE__ */ e.createElement(ErrorFallbackNode, {
863
+ $self: this.$self,
864
+ $reload: this.reload,
865
+ $store: store,
866
+ $error: this.error,
867
+ $locale: locale
868
+ });
869
+ return this.props.children;
870
+ }
871
+ };
872
+ _defineProperty(ErrorBoundary, "displayName", "various-error-boundary");
873
+ //#endregion
874
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/objectWithoutPropertiesLoose.js
875
+ function _objectWithoutPropertiesLoose(r, e) {
876
+ if (null == r) return {};
877
+ var t = {};
878
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
879
+ if (e.includes(n)) continue;
880
+ t[n] = r[n];
881
+ }
882
+ return t;
870
883
  }
871
- function createI18n(module, updater) {
872
- const ctx = (key, params, defaultString) => {
873
- const i18nConfig = _connector__WEBPACK_IMPORTED_MODULE_0__["default"].getI18nConfig(module) || _connector__WEBPACK_IMPORTED_MODULE_0__["default"].getGlobalI18nConfig();
874
- let defaultText = defaultString;
875
- if (defaultText === undefined) {
876
- defaultText = typeof params === 'string' ? params : key;
877
- }
878
- if (!i18nConfig) {
879
- (0,_helper__WEBPACK_IMPORTED_MODULE_1__.onError)(new _helper__WEBPACK_IMPORTED_MODULE_1__.VariousError({
880
- module,
881
- type: 'I18N',
882
- originalError: new Error('config not exist')
883
- }));
884
- return defaultText;
885
- }
886
- if (i18nConfig.loading) {
887
- return defaultText;
888
- }
889
- const {
890
- resources
891
- } = i18nConfig;
892
- const locale = (0,_store__WEBPACK_IMPORTED_MODULE_2__.getStore)(_config__WEBPACK_IMPORTED_MODULE_3__.LOCALE_KEY);
893
- const resource = resources?.[locale];
894
- if (!resource) {
895
- (0,_helper__WEBPACK_IMPORTED_MODULE_1__.onError)(new _helper__WEBPACK_IMPORTED_MODULE_1__.VariousError({
896
- module,
897
- type: 'I18N',
898
- originalError: new Error(`locale resource \`${locale}\` not exist`)
899
- }));
900
- return defaultText;
901
- }
902
- if (!resource[key]) {
903
- (0,_helper__WEBPACK_IMPORTED_MODULE_1__.onError)(new _helper__WEBPACK_IMPORTED_MODULE_1__.VariousError({
904
- module,
905
- type: 'I18N',
906
- originalError: new Error(`locale key \`${key}\` not exist`)
907
- }));
908
- return defaultText;
909
- }
910
- const text = resource[key];
911
- if (!params || typeof params === 'string' || Object.prototype.toString.call(params) !== '[object Object]') {
912
- return text;
913
- }
914
- const args = Object.keys(params);
915
- if (!args.length) {
916
- return text;
917
- }
918
- return args.reduce((next, arg) => {
919
- const regex = new RegExp(`{\\s*${arg}\\s*}`, 'g');
920
- return next.replace(regex, params[arg].toString());
921
- }, text);
922
- };
923
- ctx.update = config => {
924
- const i18nConfig = _connector__WEBPACK_IMPORTED_MODULE_0__["default"].getI18nConfig(module);
925
- const next = {
926
- ...i18nConfig,
927
- ...config
928
- };
929
- _connector__WEBPACK_IMPORTED_MODULE_0__["default"].setI18nConfig(module, next);
930
- updater();
931
- };
932
- return ctx;
884
+ //#endregion
885
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/objectWithoutProperties.js
886
+ function _objectWithoutProperties(e, t) {
887
+ if (null == e) return {};
888
+ var o, r, i = _objectWithoutPropertiesLoose(e, t);
889
+ if (Object.getOwnPropertySymbols) {
890
+ var s = Object.getOwnPropertySymbols(e);
891
+ for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
892
+ }
893
+ return i;
933
894
  }
934
-
935
- /***/ }),
936
-
937
- /***/ "./src/core/logger.ts":
938
- /*!****************************!*\
939
- !*** ./src/core/logger.ts ***!
940
- \****************************/
941
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
942
-
943
- "use strict";
944
- __webpack_require__.r(__webpack_exports__);
945
- /* harmony import */ var _connector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./connector */ "./src/core/connector.ts");
946
- /* harmony import */ var _helper__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helper */ "./src/core/helper.ts");
947
-
948
-
949
- const logger = args => {
950
- const middlewares = _connector__WEBPACK_IMPORTED_MODULE_0__["default"].getMiddlewares();
951
- const canLog = middlewares?.onLog?.(args);
952
- if (canLog === false) {
953
- return;
954
- }
955
- const colorMap = {
956
- info: 'blue',
957
- warn: 'orange',
958
- error: 'red'
959
- };
960
- const color = colorMap[args.level];
961
- const params = [`%c ${args.module} `, `background:${color};border:1px solid ${color};padding:1px;border-radius:2px 0 0 2px;color: #fff;`];
962
- if (args.type) {
963
- params[0] = `${params[0]}%c ${args.type} %c`;
964
- params.push(`border:1px solid ${color};padding:1px;border-radius:0 2px 2px 0;color:${color};`, 'background:transparent');
965
- }
966
- if (args.level !== 'info') {
967
- params[0] = ` ${params[0]}`;
968
- }
969
- window.console[args.level](...params, args.message);
895
+ //#endregion
896
+ //#region src/core/dispatch.ts
897
+ var createDispatch = (module) => async function(params) {
898
+ const middlewares = connector_default.getMiddlewares();
899
+ const logger = createLogger(module);
900
+ let { action, payload, target } = params;
901
+ if (middlewares === null || middlewares === void 0 ? void 0 : middlewares.onDispatch) {
902
+ const check = await middlewares.onDispatch({
903
+ target,
904
+ action,
905
+ payload,
906
+ trigger: module
907
+ });
908
+ if (check === false) {
909
+ logger.warn("blocked by middleware", "DISPATCH");
910
+ return Promise.resolve();
911
+ }
912
+ if (check !== true) {
913
+ target = check.target;
914
+ action = check.action;
915
+ payload = check.payload;
916
+ }
917
+ }
918
+ if (target === "app") {
919
+ const storeAction = connector_default.getStoreActions()[action];
920
+ if (action === I18NActions.SetLocale) {
921
+ emit({ [LOCALE_KEY]: payload }, true);
922
+ return payload;
923
+ }
924
+ if (action === I18NActions.GetLocale) return getStore(LOCALE_KEY);
925
+ if (action === I18NActions.UpdateI18nConfig) {
926
+ const locale = getStore(LOCALE_KEY);
927
+ connector_default.setGlobalI18nConfig(payload);
928
+ emit({ [LOCALE_KEY]: void 0 }, true);
929
+ emit({ [LOCALE_KEY]: locale }, true);
930
+ return locale;
931
+ }
932
+ if (!storeAction) {
933
+ const errorMessage = `action "${action}" is not present`;
934
+ const error = new VariousError({
935
+ module,
936
+ type: "DISPATCH",
937
+ originalError: new Error(errorMessage)
938
+ });
939
+ onError(error);
940
+ throw error;
941
+ }
942
+ return dispatch(storeAction, payload, module);
943
+ }
944
+ const componentActions = connector_default.getComponentActions(target);
945
+ if (!componentActions) {
946
+ const error = new VariousError({
947
+ module,
948
+ type: "DISPATCH",
949
+ originalError: /* @__PURE__ */ new Error("component is not ready")
950
+ });
951
+ onError(error);
952
+ throw error;
953
+ }
954
+ const componentAction = componentActions[action];
955
+ if (!componentAction) {
956
+ const errorMessage = `action "${action}" is not present`;
957
+ const error = new VariousError({
958
+ module,
959
+ type: "DISPATCH",
960
+ originalError: new Error(errorMessage)
961
+ });
962
+ onError(error);
963
+ throw error;
964
+ }
965
+ return Promise.resolve(componentAction({
966
+ payload,
967
+ trigger: module
968
+ }));
970
969
  };
971
- const createLogger = module => ({
972
- info(message, type) {
973
- logger({
974
- module,
975
- level: 'info',
976
- type,
977
- message
978
- });
979
- },
980
- warn(message, type) {
981
- logger({
982
- module,
983
- level: 'warn',
984
- type,
985
- message
986
- });
987
- },
988
- error(message, type) {
989
- const middlewares = _connector__WEBPACK_IMPORTED_MODULE_0__["default"].getMiddlewares();
990
- const error = message instanceof _helper__WEBPACK_IMPORTED_MODULE_1__.VariousError ? message : new _helper__WEBPACK_IMPORTED_MODULE_1__.VariousError({
991
- module,
992
- type: type || 'unknow',
993
- originalError: message instanceof Error ? message : new Error(message)
994
- });
995
- middlewares?.onError?.(error);
996
- logger({
997
- module,
998
- level: 'error',
999
- type,
1000
- message
1001
- });
1002
- }
1003
- });
1004
- /* harmony default export */ __webpack_exports__["default"] = (createLogger);
1005
-
1006
- /***/ }),
1007
-
1008
- /***/ "./src/core/message.ts":
1009
- /*!*****************************!*\
1010
- !*** ./src/core/message.ts ***!
1011
- \*****************************/
1012
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1013
-
1014
- "use strict";
1015
- __webpack_require__.r(__webpack_exports__);
1016
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1017
- /* harmony export */ createOnMessage: function() { return /* binding */ createOnMessage; },
1018
- /* harmony export */ createPostMessage: function() { return /* binding */ createPostMessage; }
1019
- /* harmony export */ });
1020
- /* harmony import */ var _connector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./connector */ "./src/core/connector.ts");
1021
- /* harmony import */ var _logger__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./logger */ "./src/core/logger.ts");
1022
- /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./store */ "./src/core/store.ts");
1023
- /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./config */ "./src/core/config.ts");
1024
-
1025
-
1026
-
1027
-
1028
- const createPostMessage = module => async ({
1029
- event,
1030
- payload
1031
- }) => {
1032
- const middlewares = _connector__WEBPACK_IMPORTED_MODULE_0__["default"].getMiddlewares();
1033
- const logger = (0,_logger__WEBPACK_IMPORTED_MODULE_1__["default"])(module);
1034
- let next = {
1035
- trigger: module,
1036
- event,
1037
- payload
1038
- };
1039
- if (middlewares?.onMessage) {
1040
- const check = await middlewares.onMessage(next);
1041
- if (check === false) {
1042
- logger.warn('blocked by middleware', 'POST_MESSAGE');
1043
- return;
1044
- }
1045
- if (check !== true) {
1046
- next = {
1047
- ...next,
1048
- ...check
1049
- };
1050
- }
1051
- }
1052
- (0,_store__WEBPACK_IMPORTED_MODULE_2__.emit)({
1053
- [_config__WEBPACK_IMPORTED_MODULE_3__.MESSAGE_KEY]: {
1054
- timestamp: +new Date(),
1055
- event: next.event,
1056
- trigger: module,
1057
- payload: next.payload
1058
- }
1059
- });
970
+ //#endregion
971
+ //#region src/core/create-module.ts
972
+ var createModule = (config, logError = true) => {
973
+ const dependencies = getStore(DEPENDENCIES_KEY);
974
+ const middlewares = connector_default.getMiddlewares();
975
+ const { url, module } = config;
976
+ const { name, entry } = getModuleInfo(module);
977
+ const loadStart = +/* @__PURE__ */ new Date();
978
+ const logOnError = (e) => {
979
+ if (logError) onError(e);
980
+ };
981
+ if (url) resetDependencyConfig(module, url);
982
+ return new Promise((resolve, reject) => {
983
+ if (!url && !dependencies[name] && !isModuleSpecified(module)) {
984
+ const error = new VariousError({
985
+ module,
986
+ type: "NOT_DEFINED",
987
+ originalError: /* @__PURE__ */ new Error(`module "${name}" not defined`)
988
+ });
989
+ logOnError(error);
990
+ reject(error);
991
+ return;
992
+ }
993
+ importModule(name).then((C) => {
994
+ var _middlewares$onLoad;
995
+ const loadEnd = +/* @__PURE__ */ new Date();
996
+ middlewares === null || middlewares === void 0 || (_middlewares$onLoad = middlewares.onLoad) === null || _middlewares$onLoad === void 0 || _middlewares$onLoad.call(middlewares, {
997
+ module,
998
+ loadStart,
999
+ loadEnd,
1000
+ beenLoaded: isModuleLoaded(module)
1001
+ });
1002
+ if (!C || typeof C === "object" && Object.keys(C).length === 0) {
1003
+ const error = new VariousError({
1004
+ module,
1005
+ type: "INVALID_MODULE",
1006
+ originalError: /* @__PURE__ */ new Error(`module "${name}" invalid`)
1007
+ });
1008
+ resetDependencyConfig(module);
1009
+ logOnError(error);
1010
+ reject(error);
1011
+ return;
1012
+ }
1013
+ const defaultModule = "default" in C ? C.default : C;
1014
+ const actualModule = !entry ? defaultModule : C[entry];
1015
+ if (actualModule === void 0 && entry) {
1016
+ const error = new VariousError({
1017
+ module,
1018
+ type: "SUBMODULE_NOT_DEFINED",
1019
+ originalError: /* @__PURE__ */ new Error(`submodule "${entry}" not defined`)
1020
+ });
1021
+ resetDependencyConfig(module);
1022
+ logOnError(error);
1023
+ reject(error);
1024
+ return;
1025
+ }
1026
+ resolve(actualModule);
1027
+ }).catch((e) => {
1028
+ resetDependencyConfig(module, url);
1029
+ let errorType = "LOADING_ERROR";
1030
+ if (!url && e.message && !e.message.includes(name)) errorType = "SUBMODULE_LOADING_ERROR";
1031
+ const error = new VariousError({
1032
+ module: name,
1033
+ type: errorType,
1034
+ originalError: e
1035
+ });
1036
+ logOnError(error);
1037
+ reject(error);
1038
+ });
1039
+ });
1060
1040
  };
1061
- const createOnMessage = (module, onMessage) => (0,_store__WEBPACK_IMPORTED_MODULE_2__.subscribe)({
1062
- [_config__WEBPACK_IMPORTED_MODULE_3__.MESSAGE_KEY](v) {
1063
- const {
1064
- trigger,
1065
- payload,
1066
- event
1067
- } = v;
1068
- if (module !== trigger) {
1069
- onMessage({
1070
- event,
1071
- payload,
1072
- trigger
1073
- });
1074
- }
1075
- }
1076
- });
1077
-
1078
- /***/ }),
1079
-
1080
- /***/ "./src/core/react-component.tsx":
1081
- /*!**************************************!*\
1082
- !*** ./src/core/react-component.tsx ***!
1083
- \**************************************/
1084
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1085
-
1086
- "use strict";
1087
- __webpack_require__.r(__webpack_exports__);
1088
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/extends */ "./node_modules/@babel/runtime/helpers/esm/extends.js");
1089
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react */ "react");
1090
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
1091
- /* harmony import */ var _helper__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./helper */ "./src/core/helper.ts");
1092
- /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./store */ "./src/core/store.ts");
1093
- /* harmony import */ var _connector__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./connector */ "./src/core/connector.ts");
1094
- /* harmony import */ var _message__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./message */ "./src/core/message.ts");
1095
- /* harmony import */ var _dispatch__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./dispatch */ "./src/core/dispatch.ts");
1096
- /* harmony import */ var _logger__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./logger */ "./src/core/logger.ts");
1097
- /* harmony import */ var _i18n__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./i18n */ "./src/core/i18n.ts");
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
-
1101
-
1102
-
1103
-
1104
-
1105
-
1106
-
1107
-
1108
-
1109
-
1110
-
1041
+ //#endregion
1042
+ //#region src/core/react-component.tsx
1111
1043
  function reactComponent(config) {
1112
- const {
1113
- module,
1114
- url,
1115
- watchKeys,
1116
- onMounted
1117
- } = config;
1118
- const storeKeys = watchKeys || Object.keys((0,_store__WEBPACK_IMPORTED_MODULE_3__.getStore)());
1119
- class R extends react__WEBPACK_IMPORTED_MODULE_1__.Component {
1120
- static displayName = 'various-react-component';
1121
- state = {
1122
- componentReady: false,
1123
- isError: false
1124
- };
1125
- unSubscribeMessage = () => null;
1126
- componentDidMount() {
1127
- this.isUnMounted = false; // fix StrictMode
1128
- this.mountComponent();
1129
- }
1130
- componentWillUnmount() {
1131
- this.error = undefined;
1132
- this.ComponentNode = null;
1133
- this.isUnMounted = true;
1134
- this.unSubscribeMessage();
1135
- (0,_helper__WEBPACK_IMPORTED_MODULE_2__.updateUnMountComponent)(module);
1136
- }
1137
- mountComponent = async () => {
1138
- try {
1139
- const componentNode = await (0,_create_module__WEBPACK_IMPORTED_MODULE_9__["default"])({
1140
- module,
1141
- url
1142
- }, false);
1143
- if (this.isUnMounted) {
1144
- return;
1145
- }
1146
- await (0,_helper__WEBPACK_IMPORTED_MODULE_2__.checkReactComponent)(componentNode, module);
1147
- componentNode.displayName = module;
1148
- (0,_helper__WEBPACK_IMPORTED_MODULE_2__.updateMountedComponent)(module);
1149
- this.unSubscribeMessage = (0,_helper__WEBPACK_IMPORTED_MODULE_2__.parseComponentActions)({
1150
- componentNode,
1151
- module,
1152
- i18nUpdate: () => this.forceUpdate()
1153
- });
1154
- this.ComponentNode = componentNode;
1155
- this.setState({
1156
- componentReady: true
1157
- });
1158
- onMounted?.();
1159
- } catch (e) {
1160
- if (this.isUnMounted) {
1161
- return;
1162
- }
1163
- this.error = e;
1164
- this.setState({
1165
- componentReady: true,
1166
- isError: true
1167
- });
1168
- }
1169
- };
1170
- $postMessage = (0,_message__WEBPACK_IMPORTED_MODULE_5__.createPostMessage)(module);
1171
- $dispatch = (0,_dispatch__WEBPACK_IMPORTED_MODULE_6__["default"])(module);
1172
- $t = (0,_i18n__WEBPACK_IMPORTED_MODULE_8__.createI18n)(module, () => this.forceUpdate());
1173
- $logger = (0,_logger__WEBPACK_IMPORTED_MODULE_7__["default"])(module);
1174
- $self = (0,_helper__WEBPACK_IMPORTED_MODULE_2__.getSelfInfo)({
1175
- module,
1176
- url
1177
- });
1178
- render() {
1179
- const Fallback = _connector__WEBPACK_IMPORTED_MODULE_4__["default"].getFallbackComponent();
1180
- const {
1181
- $silent,
1182
- $componentProps,
1183
- $ref
1184
- } = this.props;
1185
- const {
1186
- componentReady,
1187
- isError
1188
- } = this.state;
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);
1191
- const ComponentNode = this.ComponentNode;
1192
- if (isError) {
1193
- throw this.error;
1194
- }
1195
- if (!componentReady) {
1196
- if ($silent || (0,_helper__WEBPACK_IMPORTED_MODULE_2__.isModuleLoaded)(module)) {
1197
- return null;
1198
- }
1199
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().createElement(Fallback, {
1200
- $self: this.$self,
1201
- $store: store,
1202
- $locale: locale
1203
- });
1204
- }
1205
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().createElement(ComponentNode, (0,_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__["default"])({}, $componentProps, {
1206
- $self: this.$self,
1207
- $dispatch: this.$dispatch,
1208
- $store: store,
1209
- $postMessage: this.$postMessage,
1210
- $t: this.$t,
1211
- $logger: this.$logger,
1212
- ref: $ref,
1213
- $locale: locale
1214
- }));
1215
- }
1216
- }
1217
- const Connected = (0,_store__WEBPACK_IMPORTED_MODULE_3__.connect)(...storeKeys, _config__WEBPACK_IMPORTED_MODULE_10__.LOCALE_KEY)(R);
1218
- Connected.displayName = 'various-connector';
1219
- return Connected;
1220
- }
1221
- /* harmony default export */ __webpack_exports__["default"] = (reactComponent);
1222
-
1223
- /***/ }),
1224
-
1225
- /***/ "./src/core/render-component.tsx":
1226
- /*!***************************************!*\
1227
- !*** ./src/core/render-component.tsx ***!
1228
- \***************************************/
1229
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1230
-
1231
- "use strict";
1232
- __webpack_require__.r(__webpack_exports__);
1233
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
1234
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1235
- /* harmony import */ var _react_component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./react-component */ "./src/core/react-component.tsx");
1236
- /* harmony import */ var _vue_component__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./vue-component */ "./src/core/vue-component.tsx");
1237
- /* harmony import */ var _helper__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./helper */ "./src/core/helper.ts");
1238
- /* harmony import */ var _error_boundary__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./error-boundary */ "./src/core/error-boundary.tsx");
1239
- /* harmony import */ var _create_module__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./create-module */ "./src/core/create-module.ts");
1240
-
1241
-
1242
-
1243
-
1244
-
1245
-
1246
- const renderComponent = async ({
1247
- module,
1248
- url,
1249
- target,
1250
- props,
1251
- type = 'react',
1252
- renderNode,
1253
- onMounted
1254
- }) => {
1255
- try {
1256
- const ReactDOM = await (0,_create_module__WEBPACK_IMPORTED_MODULE_5__["default"])({
1257
- module: 'react-dom'
1258
- });
1259
- const C = (type === 'vue3' ? _vue_component__WEBPACK_IMPORTED_MODULE_2__["default"] : _react_component__WEBPACK_IMPORTED_MODULE_1__["default"])({
1260
- module,
1261
- url,
1262
- onMounted
1263
- });
1264
- const root = ReactDOM.createRoot(target);
1265
- const {
1266
- $silent,
1267
- $ref,
1268
- ...rest
1269
- } = props || {};
1270
- const nextProps = {
1271
- $componentProps: rest,
1272
- $silent,
1273
- $ref
1274
- };
1275
- const node = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_error_boundary__WEBPACK_IMPORTED_MODULE_4__["default"], {
1276
- module: module,
1277
- url: url
1278
- }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(C, nextProps));
1279
- root.render(renderNode ? renderNode(node) : node);
1280
- return () => new Promise(resolve => {
1281
- setTimeout(() => {
1282
- root.unmount();
1283
- resolve();
1284
- });
1285
- });
1286
- } catch (e) {
1287
- const error = new _helper__WEBPACK_IMPORTED_MODULE_3__.VariousError({
1288
- module,
1289
- type: 'SCRIPT_ERROR',
1290
- originalError: e
1291
- });
1292
- (0,_helper__WEBPACK_IMPORTED_MODULE_3__.onError)(error);
1293
- return () => Promise.resolve();
1294
- }
1295
- };
1296
- /* harmony default export */ __webpack_exports__["default"] = (renderComponent);
1297
-
1298
- /***/ }),
1299
-
1300
- /***/ "./src/core/store.ts":
1301
- /*!***************************!*\
1302
- !*** ./src/core/store.ts ***!
1303
- \***************************/
1304
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1305
-
1306
- "use strict";
1307
- __webpack_require__.r(__webpack_exports__);
1308
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1309
- /* harmony export */ connect: function() { return /* binding */ connect; },
1310
- /* harmony export */ createStore: function() { return /* binding */ createStore; },
1311
- /* harmony export */ dispatch: function() { return /* binding */ dispatch; },
1312
- /* harmony export */ emit: function() { return /* binding */ emit; },
1313
- /* harmony export */ getStore: function() { return /* binding */ getStore; },
1314
- /* harmony export */ getUserStore: function() { return /* binding */ getUserStore; },
1315
- /* harmony export */ subscribe: function() { return /* binding */ subscribe; },
1316
- /* harmony export */ useStore: function() { return /* binding */ useStore; }
1317
- /* harmony export */ });
1318
- /* harmony import */ var nycticorax__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! nycticorax */ "./node_modules/nycticorax/dist/index.js");
1319
- /* harmony import */ var nycticorax__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(nycticorax__WEBPACK_IMPORTED_MODULE_0__);
1320
-
1321
- const {
1322
- createStore,
1323
- getStore,
1324
- connect,
1325
- emit,
1326
- subscribe,
1327
- dispatch,
1328
- useStore
1329
- } = new (nycticorax__WEBPACK_IMPORTED_MODULE_0___default())();
1330
- function getUserStore() {
1331
- const globalStore = getStore();
1332
- const keys = Object.keys(globalStore);
1333
- const store = {};
1334
- keys.forEach(key => {
1335
- store[key] = globalStore[key];
1336
- });
1337
- return store;
1044
+ const { module, url, watchKeys, onMounted } = config;
1045
+ const storeKeys = watchKeys || Object.keys(getStore());
1046
+ class R extends Component {
1047
+ constructor(..._args) {
1048
+ var _this;
1049
+ super(..._args);
1050
+ _this = this;
1051
+ _defineProperty(this, "state", {
1052
+ componentReady: false,
1053
+ isError: false
1054
+ });
1055
+ _defineProperty(this, "error", void 0);
1056
+ _defineProperty(this, "ComponentNode", void 0);
1057
+ _defineProperty(this, "isUnMounted", void 0);
1058
+ _defineProperty(this, "unSubscribeMessage", () => null);
1059
+ _defineProperty(this, "mountComponent", async () => {
1060
+ try {
1061
+ const componentNode = await createModule({
1062
+ module,
1063
+ url
1064
+ }, false);
1065
+ if (_this.isUnMounted) return;
1066
+ await checkReactComponent(componentNode, module);
1067
+ componentNode.displayName = module;
1068
+ updateMountedComponent(module);
1069
+ _this.unSubscribeMessage = parseComponentActions({
1070
+ componentNode,
1071
+ module,
1072
+ i18nUpdate: () => _this.forceUpdate()
1073
+ });
1074
+ _this.ComponentNode = componentNode;
1075
+ _this.setState({ componentReady: true });
1076
+ onMounted === null || onMounted === void 0 || onMounted();
1077
+ } catch (e) {
1078
+ if (_this.isUnMounted) return;
1079
+ _this.error = e;
1080
+ _this.setState({
1081
+ componentReady: true,
1082
+ isError: true
1083
+ });
1084
+ }
1085
+ });
1086
+ _defineProperty(this, "$postMessage", createPostMessage(module));
1087
+ _defineProperty(this, "$dispatch", createDispatch(module));
1088
+ _defineProperty(this, "$t", createI18n(module, () => this.forceUpdate()));
1089
+ _defineProperty(this, "$logger", createLogger(module));
1090
+ _defineProperty(this, "$self", getSelfInfo({
1091
+ module,
1092
+ url
1093
+ }));
1094
+ }
1095
+ componentDidMount() {
1096
+ this.isUnMounted = false;
1097
+ this.mountComponent();
1098
+ }
1099
+ componentWillUnmount() {
1100
+ this.error = void 0;
1101
+ this.ComponentNode = null;
1102
+ this.isUnMounted = true;
1103
+ this.unSubscribeMessage();
1104
+ updateUnMountComponent(module);
1105
+ }
1106
+ render() {
1107
+ const Fallback = connector_default.getFallbackComponent();
1108
+ const { $silent, $componentProps, $ref } = this.props;
1109
+ const { componentReady, isError } = this.state;
1110
+ const store = getUserStore();
1111
+ const locale = getStore(LOCALE_KEY);
1112
+ const ComponentNode = this.ComponentNode;
1113
+ if (isError) throw this.error;
1114
+ if (!componentReady) {
1115
+ if ($silent || isModuleLoaded(module)) return null;
1116
+ return /* @__PURE__ */ e.createElement(Fallback, {
1117
+ $self: this.$self,
1118
+ $store: store,
1119
+ $locale: locale
1120
+ });
1121
+ }
1122
+ return /* @__PURE__ */ e.createElement(ComponentNode, _objectSpread2(_objectSpread2({}, $componentProps), {}, {
1123
+ $self: this.$self,
1124
+ $dispatch: this.$dispatch,
1125
+ $store: store,
1126
+ $postMessage: this.$postMessage,
1127
+ $t: this.$t,
1128
+ $logger: this.$logger,
1129
+ ref: $ref,
1130
+ $locale: locale
1131
+ }));
1132
+ }
1133
+ }
1134
+ _defineProperty(R, "displayName", "various-react-component");
1135
+ const Connected = connect(...storeKeys, LOCALE_KEY)(R);
1136
+ Connected.displayName = "various-connector";
1137
+ return Connected;
1338
1138
  }
1339
-
1340
- /***/ }),
1341
-
1342
- /***/ "./src/core/vue-component.tsx":
1343
- /*!************************************!*\
1344
- !*** ./src/core/vue-component.tsx ***!
1345
- \************************************/
1346
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1347
-
1348
- "use strict";
1349
- __webpack_require__.r(__webpack_exports__);
1350
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
1351
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1352
- /* harmony import */ var _connector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./connector */ "./src/core/connector.ts");
1353
- /* harmony import */ var _create_module__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./create-module */ "./src/core/create-module.ts");
1354
- /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./store */ "./src/core/store.ts");
1355
- /* harmony import */ var _helper__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./helper */ "./src/core/helper.ts");
1356
- /* harmony import */ var _dispatch__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./dispatch */ "./src/core/dispatch.ts");
1357
- /* harmony import */ var _logger__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./logger */ "./src/core/logger.ts");
1358
- /* harmony import */ var _message__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./message */ "./src/core/message.ts");
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
-
1362
-
1363
-
1364
-
1365
-
1366
-
1367
-
1368
-
1369
-
1370
-
1139
+ //#endregion
1140
+ //#region src/core/vue-component.tsx
1371
1141
  function vueComponent(config) {
1372
- const {
1373
- module,
1374
- url,
1375
- watchKeys,
1376
- onMounted
1377
- } = config;
1378
- const storeKeys = watchKeys || Object.keys((0,_store__WEBPACK_IMPORTED_MODULE_3__.getStore)());
1379
- const V = props => {
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];
1382
- const vueRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1383
- const vmRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1384
- const isVueMounted = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(false);
1385
- const errorRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1386
- const isUnMountedRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(false);
1387
- const ComponentNodeRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1388
- const selfRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)((0,_helper__WEBPACK_IMPORTED_MODULE_4__.getSelfInfo)({
1389
- module,
1390
- url
1391
- }));
1392
- const containerDivRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(null);
1393
- const propsReactiveRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1394
- const storeReactiveRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1395
- const localeReactiveRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1396
- const unMountVue = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1397
- const unSubscribeMessageRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1398
- const updateVueComponentRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
1399
- const [componentReady, setComponentReady] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(false);
1400
- const [isError, setIsError] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(false);
1401
- const Fallback = _connector__WEBPACK_IMPORTED_MODULE_1__["default"].getFallbackComponent();
1402
- const {
1403
- $silent,
1404
- $componentProps
1405
- } = props;
1406
- const mountVue = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(() => {
1407
- const $logger = (0,_logger__WEBPACK_IMPORTED_MODULE_6__["default"])(module);
1408
- const $dispatch = (0,_dispatch__WEBPACK_IMPORTED_MODULE_5__["default"])(module);
1409
- const $postMessage = (0,_message__WEBPACK_IMPORTED_MODULE_7__.createPostMessage)(module);
1410
- const $t = (0,_i18n__WEBPACK_IMPORTED_MODULE_8__.createI18n)(module, () => {
1411
- updateVueComponentRef.current?.();
1412
- });
1413
- propsReactiveRef.current = vueRef.current.ref({
1414
- ...$componentProps
1415
- });
1416
- storeReactiveRef.current = vueRef.current.ref({
1417
- ...store
1418
- });
1419
- localeReactiveRef.current = vueRef.current.ref(locale);
1420
- const vueApp = vueRef.current.createApp({
1421
- setup() {
1422
- const renderKey = vueRef.current.ref(0);
1423
- updateVueComponentRef.current = () => {
1424
- renderKey.value += 1;
1425
- };
1426
- return {
1427
- key: renderKey
1428
- };
1429
- },
1430
- errorCaptured(e) {
1431
- const error = e;
1432
- errorRef.current = error.message?.includes('https://react') ? new _helper__WEBPACK_IMPORTED_MODULE_4__.VariousError({
1433
- originalError: new Error('not a valid Vue component'),
1434
- module,
1435
- type: 'INVALID_COMPONENT'
1436
- }) : error;
1437
- setIsError(true);
1438
- },
1439
- render() {
1440
- return vueRef.current.h(ComponentNodeRef.current, {
1441
- ...propsReactiveRef.current.value,
1442
- various: {
1443
- $dispatch,
1444
- $logger,
1445
- $postMessage,
1446
- $t,
1447
- $store: storeReactiveRef.current.value,
1448
- $self: selfRef.current,
1449
- $locale: localeReactiveRef.current.value
1450
- },
1451
- // eslint-disable-next-line react/no-this-in-sfc
1452
- key: this.key
1453
- });
1454
- }
1455
- });
1456
-
1457
- // fix StrictMode
1458
- if (!vmRef.current) {
1459
- vmRef.current = vueApp.mount(containerDivRef.current);
1460
- }
1461
- isVueMounted.current = true;
1462
- unMountVue.current = () => vueApp.unmount();
1463
- }, [$componentProps, store, locale]);
1464
- const mountComponent = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(async () => {
1465
- try {
1466
- const vue = await (0,_create_module__WEBPACK_IMPORTED_MODULE_2__["default"])({
1467
- module: 'vue'
1468
- });
1469
- vueRef.current = vue;
1470
- const componentNode = await (0,_create_module__WEBPACK_IMPORTED_MODULE_2__["default"])({
1471
- module,
1472
- url
1473
- }, false);
1474
- if (isUnMountedRef.current) {
1475
- return;
1476
- }
1477
- await (0,_helper__WEBPACK_IMPORTED_MODULE_4__.checkVueComponent)(componentNode, module);
1478
- (0,_helper__WEBPACK_IMPORTED_MODULE_4__.updateMountedComponent)(module);
1479
- unSubscribeMessageRef.current = (0,_helper__WEBPACK_IMPORTED_MODULE_4__.parseComponentActions)({
1480
- componentNode,
1481
- module,
1482
- type: 'vue3',
1483
- i18nUpdate() {
1484
- updateVueComponentRef.current?.();
1485
- }
1486
- });
1487
- ComponentNodeRef.current = componentNode;
1488
- setTimeout(mountVue);
1489
- setComponentReady(true);
1490
- onMounted?.();
1491
- } catch (e) {
1492
- if (isUnMountedRef.current) {
1493
- return;
1494
- }
1495
- errorRef.current = e;
1496
- setComponentReady(true);
1497
- setIsError(true);
1498
- }
1499
- }, [mountVue]);
1500
- (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
1501
- // fix StrictMode
1502
- isUnMountedRef.current = false;
1503
- return () => {
1504
- errorRef.current = undefined;
1505
- ComponentNodeRef.current = undefined;
1506
- isUnMountedRef.current = true;
1507
- (0,_helper__WEBPACK_IMPORTED_MODULE_4__.updateUnMountComponent)(module);
1508
- unMountVue.current?.();
1509
- unSubscribeMessageRef.current?.();
1510
- isVueMounted.current = false;
1511
- };
1512
- }, []);
1513
- (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
1514
- if (isVueMounted.current) {
1515
- return;
1516
- }
1517
- mountComponent();
1518
- }, [mountComponent]);
1519
- (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
1520
- if (propsReactiveRef.current) {
1521
- propsReactiveRef.current.value = {
1522
- ...$componentProps
1523
- };
1524
- }
1525
- }, [$componentProps]);
1526
- (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
1527
- if (storeReactiveRef.current) {
1528
- storeReactiveRef.current.value = {
1529
- ...store
1530
- };
1531
- }
1532
- }, [store]);
1533
- (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
1534
- if (localeReactiveRef.current) {
1535
- localeReactiveRef.current.value = locale;
1536
- }
1537
- }, [locale]);
1538
- if (isError) {
1539
- throw errorRef.current;
1540
- }
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, {
1542
- $self: selfRef.current,
1543
- $store: store,
1544
- $locale: locale
1545
- }) : null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
1546
- className: (0,_helper__WEBPACK_IMPORTED_MODULE_4__.getClassNameWithModule)(module, 'various-vue-component'),
1547
- ref: containerDivRef
1548
- }));
1549
- };
1550
- V.displayName = module;
1551
- const VueComponent = props => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(V, props);
1552
- VueComponent.displayName = 'various-vue-component';
1553
- return VueComponent;
1142
+ const { module, url, watchKeys, onMounted } = config;
1143
+ const storeKeys = watchKeys || Object.keys(getStore());
1144
+ const V = (props) => {
1145
+ const store = useStore(...storeKeys, LOCALE_KEY);
1146
+ const locale = store[LOCALE_KEY];
1147
+ const vueRef = useRef();
1148
+ const vmRef = useRef();
1149
+ const isVueMounted = useRef(false);
1150
+ const errorRef = useRef();
1151
+ const isUnMountedRef = useRef(false);
1152
+ const ComponentNodeRef = useRef();
1153
+ const selfRef = useRef(getSelfInfo({
1154
+ module,
1155
+ url
1156
+ }));
1157
+ const containerDivRef = useRef(null);
1158
+ const propsReactiveRef = useRef();
1159
+ const storeReactiveRef = useRef();
1160
+ const localeReactiveRef = useRef();
1161
+ const unMountVue = useRef();
1162
+ const unSubscribeMessageRef = useRef();
1163
+ const updateVueComponentRef = useRef();
1164
+ const [componentReady, setComponentReady] = useState(false);
1165
+ const [isError, setIsError] = useState(false);
1166
+ const Fallback = connector_default.getFallbackComponent();
1167
+ const { $silent, $componentProps } = props;
1168
+ const mountVue = useCallback(() => {
1169
+ const $logger = createLogger(module);
1170
+ const $dispatch = createDispatch(module);
1171
+ const $postMessage = createPostMessage(module);
1172
+ const $t = createI18n(module, () => {
1173
+ var _updateVueComponentRe;
1174
+ (_updateVueComponentRe = updateVueComponentRef.current) === null || _updateVueComponentRe === void 0 || _updateVueComponentRe.call(updateVueComponentRef);
1175
+ });
1176
+ propsReactiveRef.current = vueRef.current.ref(_objectSpread2({}, $componentProps));
1177
+ storeReactiveRef.current = vueRef.current.ref(_objectSpread2({}, store));
1178
+ localeReactiveRef.current = vueRef.current.ref(locale);
1179
+ const vueApp = vueRef.current.createApp({
1180
+ setup() {
1181
+ const renderKey = vueRef.current.ref(0);
1182
+ updateVueComponentRef.current = () => {
1183
+ renderKey.value += 1;
1184
+ };
1185
+ return { key: renderKey };
1186
+ },
1187
+ errorCaptured(e) {
1188
+ var _error$message;
1189
+ const error = e;
1190
+ errorRef.current = ((_error$message = error.message) === null || _error$message === void 0 ? void 0 : _error$message.includes("https://react")) ? new VariousError({
1191
+ originalError: /* @__PURE__ */ new Error("not a valid Vue component"),
1192
+ module,
1193
+ type: "INVALID_COMPONENT"
1194
+ }) : error;
1195
+ setIsError(true);
1196
+ },
1197
+ render() {
1198
+ return vueRef.current.h(ComponentNodeRef.current, _objectSpread2(_objectSpread2({}, propsReactiveRef.current.value), {}, {
1199
+ various: {
1200
+ $dispatch,
1201
+ $logger,
1202
+ $postMessage,
1203
+ $t,
1204
+ $store: storeReactiveRef.current.value,
1205
+ $self: selfRef.current,
1206
+ $locale: localeReactiveRef.current.value
1207
+ },
1208
+ key: this.key
1209
+ }));
1210
+ }
1211
+ });
1212
+ if (!vmRef.current) vmRef.current = vueApp.mount(containerDivRef.current);
1213
+ isVueMounted.current = true;
1214
+ unMountVue.current = () => vueApp.unmount();
1215
+ }, [
1216
+ $componentProps,
1217
+ store,
1218
+ locale
1219
+ ]);
1220
+ const mountComponent = useCallback(async () => {
1221
+ try {
1222
+ const vue = await createModule({ module: "vue" });
1223
+ vueRef.current = vue;
1224
+ const componentNode = await createModule({
1225
+ module,
1226
+ url
1227
+ }, false);
1228
+ if (isUnMountedRef.current) return;
1229
+ await checkVueComponent(componentNode, module);
1230
+ updateMountedComponent(module);
1231
+ unSubscribeMessageRef.current = parseComponentActions({
1232
+ componentNode,
1233
+ module,
1234
+ type: "vue3",
1235
+ i18nUpdate() {
1236
+ var _updateVueComponentRe2;
1237
+ (_updateVueComponentRe2 = updateVueComponentRef.current) === null || _updateVueComponentRe2 === void 0 || _updateVueComponentRe2.call(updateVueComponentRef);
1238
+ }
1239
+ });
1240
+ ComponentNodeRef.current = componentNode;
1241
+ setTimeout(mountVue);
1242
+ setComponentReady(true);
1243
+ onMounted === null || onMounted === void 0 || onMounted();
1244
+ } catch (e) {
1245
+ if (isUnMountedRef.current) return;
1246
+ errorRef.current = e;
1247
+ setComponentReady(true);
1248
+ setIsError(true);
1249
+ }
1250
+ }, [mountVue]);
1251
+ useEffect(() => {
1252
+ isUnMountedRef.current = false;
1253
+ return () => {
1254
+ var _unMountVue$current, _unSubscribeMessageRe;
1255
+ errorRef.current = void 0;
1256
+ ComponentNodeRef.current = void 0;
1257
+ isUnMountedRef.current = true;
1258
+ updateUnMountComponent(module);
1259
+ (_unMountVue$current = unMountVue.current) === null || _unMountVue$current === void 0 || _unMountVue$current.call(unMountVue);
1260
+ (_unSubscribeMessageRe = unSubscribeMessageRef.current) === null || _unSubscribeMessageRe === void 0 || _unSubscribeMessageRe.call(unSubscribeMessageRef);
1261
+ isVueMounted.current = false;
1262
+ };
1263
+ }, []);
1264
+ useEffect(() => {
1265
+ if (isVueMounted.current) return;
1266
+ mountComponent();
1267
+ }, [mountComponent]);
1268
+ useEffect(() => {
1269
+ if (propsReactiveRef.current) propsReactiveRef.current.value = _objectSpread2({}, $componentProps);
1270
+ }, [$componentProps]);
1271
+ useEffect(() => {
1272
+ if (storeReactiveRef.current) storeReactiveRef.current.value = _objectSpread2({}, store);
1273
+ }, [store]);
1274
+ useEffect(() => {
1275
+ if (localeReactiveRef.current) localeReactiveRef.current.value = locale;
1276
+ }, [locale]);
1277
+ if (isError) throw errorRef.current;
1278
+ return /* @__PURE__ */ e.createElement(e.Fragment, null, !componentReady && !$silent && !isModuleLoaded(module) ? /* @__PURE__ */ e.createElement(Fallback, {
1279
+ $self: selfRef.current,
1280
+ $store: store,
1281
+ $locale: locale
1282
+ }) : null, /* @__PURE__ */ e.createElement("div", {
1283
+ className: getClassNameWithModule(module, "various-vue-component"),
1284
+ ref: containerDivRef
1285
+ }));
1286
+ };
1287
+ V.displayName = module;
1288
+ const VueComponent = (props) => /* @__PURE__ */ e.createElement(V, props);
1289
+ VueComponent.displayName = "various-vue-component";
1290
+ return VueComponent;
1554
1291
  }
1555
- /* harmony default export */ __webpack_exports__["default"] = (vueComponent);
1556
-
1557
- /***/ }),
1558
-
1559
- /***/ "react":
1560
- /*!************************!*\
1561
- !*** external "react" ***!
1562
- \************************/
1563
- /***/ (function(module) {
1564
-
1565
- "use strict";
1566
- module.exports = __WEBPACK_EXTERNAL_MODULE_react__;
1567
-
1568
- /***/ })
1569
-
1570
- /******/ });
1571
- /************************************************************************/
1572
- /******/ // The module cache
1573
- /******/ var __webpack_module_cache__ = {};
1574
- /******/
1575
- /******/ // The require function
1576
- /******/ function __webpack_require__(moduleId) {
1577
- /******/ // Check if module is in cache
1578
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
1579
- /******/ if (cachedModule !== undefined) {
1580
- /******/ return cachedModule.exports;
1581
- /******/ }
1582
- /******/ // Check if module exists (development only)
1583
- /******/ if (__webpack_modules__[moduleId] === undefined) {
1584
- /******/ var e = new Error("Cannot find module '" + moduleId + "'");
1585
- /******/ e.code = 'MODULE_NOT_FOUND';
1586
- /******/ throw e;
1587
- /******/ }
1588
- /******/ // Create a new module (and put it into the cache)
1589
- /******/ var module = __webpack_module_cache__[moduleId] = {
1590
- /******/ // no module.id needed
1591
- /******/ // no module.loaded needed
1592
- /******/ exports: {}
1593
- /******/ };
1594
- /******/
1595
- /******/ // Execute the module function
1596
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
1597
- /******/
1598
- /******/ // Return the exports of the module
1599
- /******/ return module.exports;
1600
- /******/ }
1601
- /******/
1602
- /************************************************************************/
1603
- /******/ /* webpack/runtime/compat get default export */
1604
- /******/ !function() {
1605
- /******/ // getDefaultExport function for compatibility with non-harmony modules
1606
- /******/ __webpack_require__.n = function(module) {
1607
- /******/ var getter = module && module.__esModule ?
1608
- /******/ function() { return module['default']; } :
1609
- /******/ function() { return module; };
1610
- /******/ __webpack_require__.d(getter, { a: getter });
1611
- /******/ return getter;
1612
- /******/ };
1613
- /******/ }();
1614
- /******/
1615
- /******/ /* webpack/runtime/define property getters */
1616
- /******/ !function() {
1617
- /******/ // define getter functions for harmony exports
1618
- /******/ __webpack_require__.d = function(exports, definition) {
1619
- /******/ for(var key in definition) {
1620
- /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
1621
- /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
1622
- /******/ }
1623
- /******/ }
1624
- /******/ };
1625
- /******/ }();
1626
- /******/
1627
- /******/ /* webpack/runtime/hasOwnProperty shorthand */
1628
- /******/ !function() {
1629
- /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
1630
- /******/ }();
1631
- /******/
1632
- /******/ /* webpack/runtime/make namespace object */
1633
- /******/ !function() {
1634
- /******/ // define __esModule on exports
1635
- /******/ __webpack_require__.r = function(exports) {
1636
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
1637
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1638
- /******/ }
1639
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
1640
- /******/ };
1641
- /******/ }();
1642
- /******/
1643
- /************************************************************************/
1644
- var __webpack_exports__ = {};
1645
- // This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
1646
- !function() {
1647
- "use strict";
1648
- /*!****************************!*\
1649
- !*** ./src/core/index.tsx ***!
1650
- \****************************/
1651
- __webpack_require__.r(__webpack_exports__);
1652
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1653
- /* harmony export */ Nycticorax: function() { return /* reexport default from dynamic */ nycticorax__WEBPACK_IMPORTED_MODULE_7___default.a; },
1654
- /* harmony export */ createComponent: function() { return /* reexport safe */ _create_component__WEBPACK_IMPORTED_MODULE_13__["default"]; },
1655
- /* harmony export */ createDispatch: function() { return /* reexport safe */ _dispatch__WEBPACK_IMPORTED_MODULE_8__["default"]; },
1656
- /* harmony export */ createLogger: function() { return /* reexport safe */ _logger__WEBPACK_IMPORTED_MODULE_10__["default"]; },
1657
- /* harmony export */ createModule: function() { return /* reexport safe */ _create_module__WEBPACK_IMPORTED_MODULE_12__["default"]; },
1658
- /* harmony export */ createPostMessage: function() { return /* reexport safe */ _message__WEBPACK_IMPORTED_MODULE_9__.createPostMessage; },
1659
- /* harmony export */ defineDependencies: function() { return /* reexport safe */ _helper__WEBPACK_IMPORTED_MODULE_11__.defineDependencies; },
1660
- /* harmony export */ getApp: function() { return /* binding */ getApp; },
1661
- /* harmony export */ getConfig: function() { return /* reexport safe */ _helper__WEBPACK_IMPORTED_MODULE_11__.getConfig; },
1662
- /* harmony export */ getModuleInfo: function() { return /* reexport safe */ _helper__WEBPACK_IMPORTED_MODULE_11__.getModuleInfo; },
1663
- /* harmony export */ getMountedComponents: function() { return /* reexport safe */ _helper__WEBPACK_IMPORTED_MODULE_11__.getMountedComponents; },
1664
- /* harmony export */ getStore: function() { return /* reexport safe */ _store__WEBPACK_IMPORTED_MODULE_1__.getUserStore; },
1665
- /* harmony export */ isModuleLoaded: function() { return /* reexport safe */ _helper__WEBPACK_IMPORTED_MODULE_11__.isModuleLoaded; },
1666
- /* harmony export */ onComponentMounted: function() { return /* reexport safe */ _helper__WEBPACK_IMPORTED_MODULE_11__.onComponentMounted; },
1667
- /* harmony export */ preloadModules: function() { return /* reexport safe */ _helper__WEBPACK_IMPORTED_MODULE_11__.preloadModules; },
1668
- /* harmony export */ removeLoadedModules: function() { return /* reexport safe */ _helper__WEBPACK_IMPORTED_MODULE_11__.removeLoadedModules; },
1669
- /* harmony export */ renderComponent: function() { return /* reexport safe */ _render_component__WEBPACK_IMPORTED_MODULE_14__["default"]; },
1670
- /* harmony export */ version: function() { return /* binding */ version; }
1671
- /* harmony export */ });
1672
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
1673
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1674
- /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./store */ "./src/core/store.ts");
1675
- /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./config */ "./src/core/config.ts");
1676
- /* harmony import */ var _connector__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./connector */ "./src/core/connector.ts");
1677
- /* harmony import */ var _i18n__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./i18n */ "./src/core/i18n.ts");
1678
- /* harmony import */ var _default_component__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./default-component */ "./src/core/default-component.tsx");
1679
- /* harmony import */ var _error_boundary__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./error-boundary */ "./src/core/error-boundary.tsx");
1680
- /* harmony import */ var nycticorax__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! nycticorax */ "./node_modules/nycticorax/dist/index.js");
1681
- /* harmony import */ var nycticorax__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(nycticorax__WEBPACK_IMPORTED_MODULE_7__);
1682
- /* harmony import */ var _dispatch__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./dispatch */ "./src/core/dispatch.ts");
1683
- /* harmony import */ var _message__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./message */ "./src/core/message.ts");
1684
- /* harmony import */ var _logger__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./logger */ "./src/core/logger.ts");
1685
- /* harmony import */ var _helper__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./helper */ "./src/core/helper.ts");
1686
- /* harmony import */ var _create_module__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./create-module */ "./src/core/create-module.ts");
1687
- /* harmony import */ var _create_component__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./create-component */ "./src/core/create-component.tsx");
1688
- /* harmony import */ var _render_component__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./render-component */ "./src/core/render-component.tsx");
1689
-
1690
-
1691
-
1692
-
1693
-
1694
-
1695
-
1696
-
1697
-
1698
-
1699
-
1700
-
1701
-
1702
-
1703
-
1704
-
1705
-
1706
- // eslint-disable-next-line no-undef
1707
- const version = "5.3.0";
1708
- const getApp = config => {
1709
- const {
1710
- dependencies,
1711
- store = {},
1712
- actions = {},
1713
- Fallback,
1714
- ErrorFallback,
1715
- Root = _default_component__WEBPACK_IMPORTED_MODULE_5__.Root,
1716
- middlewares,
1717
- i18n,
1718
- ...rest
1719
- } = config;
1720
- if (middlewares) {
1721
- _connector__WEBPACK_IMPORTED_MODULE_3__["default"].setMiddlewares(middlewares);
1722
- }
1723
- _connector__WEBPACK_IMPORTED_MODULE_3__["default"].setStoreActions(actions);
1724
- if (Fallback) {
1725
- _connector__WEBPACK_IMPORTED_MODULE_3__["default"].setFallbackComponent(Fallback);
1726
- }
1727
- if (ErrorFallback) {
1728
- _connector__WEBPACK_IMPORTED_MODULE_3__["default"].setErrorFallbackComponent(ErrorFallback);
1729
- }
1730
- (0,_store__WEBPACK_IMPORTED_MODULE_1__.createStore)({
1731
- ...store,
1732
- [_config__WEBPACK_IMPORTED_MODULE_2__.MOUNTED_COMPONENTS_KEY]: [],
1733
- [_config__WEBPACK_IMPORTED_MODULE_2__.CONFIG_KEY]: rest,
1734
- [_config__WEBPACK_IMPORTED_MODULE_2__.DEPENDENCIES_KEY]: dependencies,
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
1737
- });
1738
- Root.displayName = 'various-app-root';
1739
- return class extends react__WEBPACK_IMPORTED_MODULE_0__.Component {
1740
- static displayName = 'various-app';
1741
- componentDidMount() {
1742
- (0,_i18n__WEBPACK_IMPORTED_MODULE_4__.createI18nConfig)(i18n?.getResources);
1743
- }
1744
- render() {
1745
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_error_boundary__WEBPACK_IMPORTED_MODULE_6__["default"], {
1746
- module: "app",
1747
- url: dependencies.app
1748
- }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(Root, null));
1749
- }
1750
- };
1292
+ //#endregion
1293
+ //#region src/core/create-component.tsx
1294
+ var _excluded$2 = ["$silent", "$ref"];
1295
+ var createComponent = (config, storeKeys) => {
1296
+ const { module, url, type = "react" } = config;
1297
+ const C = (type === "vue3" ? vueComponent : reactComponent)({
1298
+ module,
1299
+ url,
1300
+ watchKeys: storeKeys
1301
+ });
1302
+ const component = (props) => {
1303
+ const _ref = props || {}, { $silent, $ref } = _ref;
1304
+ const nextProps = {
1305
+ $componentProps: _objectWithoutProperties(_ref, _excluded$2),
1306
+ $silent,
1307
+ $ref
1308
+ };
1309
+ return /* @__PURE__ */ e.createElement(ErrorBoundary, {
1310
+ module,
1311
+ url
1312
+ }, /* @__PURE__ */ e.createElement(C, nextProps));
1313
+ };
1314
+ component.displayName = "various-creator";
1315
+ return component;
1316
+ };
1317
+ //#endregion
1318
+ //#region src/core/render-component.tsx
1319
+ var _excluded$1 = ["$silent", "$ref"];
1320
+ var renderComponent = async ({ module, url, target, props, type = "react", renderNode, onMounted }) => {
1321
+ try {
1322
+ const ReactDOM = await createModule({ module: "react-dom/client" });
1323
+ const C = (type === "vue3" ? vueComponent : reactComponent)({
1324
+ module,
1325
+ url,
1326
+ onMounted
1327
+ });
1328
+ const root = ReactDOM.createRoot(target);
1329
+ const _ref = props || {}, { $silent, $ref } = _ref;
1330
+ const nextProps = {
1331
+ $componentProps: _objectWithoutProperties(_ref, _excluded$1),
1332
+ $silent,
1333
+ $ref
1334
+ };
1335
+ const node = /* @__PURE__ */ e.createElement(ErrorBoundary, {
1336
+ module,
1337
+ url
1338
+ }, /* @__PURE__ */ e.createElement(C, nextProps));
1339
+ root.render(renderNode ? renderNode(node) : node);
1340
+ return () => new Promise((resolve) => {
1341
+ setTimeout(() => {
1342
+ root.unmount();
1343
+ resolve();
1344
+ });
1345
+ });
1346
+ } catch (e) {
1347
+ onError(new VariousError({
1348
+ module,
1349
+ type: "SCRIPT_ERROR",
1350
+ originalError: e
1351
+ }));
1352
+ return () => Promise.resolve();
1353
+ }
1751
1354
  };
1752
- }();
1753
- /******/ return __webpack_exports__;
1754
- /******/ })()
1755
- ;
1756
- });;
1355
+ //#endregion
1356
+ //#region src/core/index.tsx
1357
+ var _excluded = [
1358
+ "dependencies",
1359
+ "store",
1360
+ "actions",
1361
+ "Fallback",
1362
+ "ErrorFallback",
1363
+ "Root",
1364
+ "middlewares",
1365
+ "i18n"
1366
+ ];
1367
+ var version = "6.0.0";
1368
+ var getApp = (config) => {
1369
+ var _Class;
1370
+ const { dependencies, store = {}, actions = {}, Fallback, ErrorFallback, Root: Root$1 = Root, middlewares, i18n } = config, rest = _objectWithoutProperties(config, _excluded);
1371
+ if (middlewares) connector_default.setMiddlewares(middlewares);
1372
+ connector_default.setStoreActions(actions);
1373
+ if (Fallback) connector_default.setFallbackComponent(Fallback);
1374
+ if (ErrorFallback) connector_default.setErrorFallbackComponent(ErrorFallback);
1375
+ createStore(_objectSpread2(_objectSpread2({}, store), {}, {
1376
+ [MOUNTED_COMPONENTS_KEY]: [],
1377
+ [CONFIG_KEY]: rest,
1378
+ [DEPENDENCIES_KEY]: dependencies,
1379
+ [MESSAGE_KEY]: null,
1380
+ [LOCALE_KEY]: (i18n === null || i18n === void 0 ? void 0 : i18n.defaultLocale) || "en"
1381
+ }));
1382
+ Root$1.displayName = "various-app-root";
1383
+ return _Class = class extends Component {
1384
+ componentDidMount() {
1385
+ createI18nConfig(i18n === null || i18n === void 0 ? void 0 : i18n.getResources);
1386
+ }
1387
+ render() {
1388
+ return /* @__PURE__ */ e.createElement(ErrorBoundary, {
1389
+ module: "app",
1390
+ url: dependencies.app
1391
+ }, /* @__PURE__ */ e.createElement(Root$1, null));
1392
+ }
1393
+ }, _defineProperty(_Class, "displayName", "various-app"), _Class;
1394
+ };
1395
+ //#endregion
1396
+ export { h as Nycticorax, createComponent, createDispatch, createLogger, createModule, createPostMessage, defineDependencies, getApp, getConfig, getModuleInfo, getMountedComponents, getUserStore as getStore, isModuleLoaded, onComponentMounted, preloadModules, removeLoadedModules, renderComponent, version };
1397
+
1757
1398
  //# sourceMappingURL=index.dev.js.map