@variousjs/various 5.1.1 → 5.1.2

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