@steroidsjs/core 2.1.0-beta.9 → 2.1.0-beta.9.1
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/actions/list.d.ts +1 -0
- package/actions/list.js +1 -0
- package/components/ClientStorageComponent.d.ts +3 -3
- package/components/ClientStorageComponent.js +28 -22
- package/components/HttpComponent.js +32 -15
- package/components/LocaleComponent.js +9 -9
- package/components/MetricsComponent.js +3 -1
- package/components/StoreComponent.d.ts +6 -0
- package/components/StoreComponent.js +5 -6
- package/components/UiComponent.d.ts +1 -1
- package/components/WebSocketComponent.d.ts +1 -1
- package/hoc/components.d.ts +1 -1
- package/hoc/components.js +1 -1
- package/hooks/index.d.ts +2 -1
- package/hooks/index.js +3 -1
- package/hooks/useApplication.d.ts +29 -26
- package/hooks/useApplication.js +17 -82
- package/hooks/useComponents.d.ts +1 -14
- package/hooks/useComponents.js +5 -5
- package/hooks/useFetch.d.ts +11 -3
- package/hooks/useFetch.js +35 -31
- package/hooks/useLayout.d.ts +9 -0
- package/hooks/useLayout.js +64 -44
- package/hooks/useList.d.ts +45 -0
- package/hooks/useList.js +83 -53
- package/hooks/useModel.js +1 -1
- package/hooks/useScreen.d.ts +1 -1
- package/hooks/useScreen.js +2 -2
- package/hooks/useSsr.d.ts +2 -0
- package/hooks/useSsr.js +8 -0
- package/package.json +5 -3
- package/providers/ComponentsProvider.d.ts +26 -0
- package/providers/ComponentsProvider.js +28 -0
- package/providers/ScreenProvider.d.ts +20 -0
- package/providers/ScreenProvider.js +87 -0
- package/providers/SsrProvider.d.ts +17 -0
- package/providers/SsrProvider.js +32 -0
- package/providers/index.d.ts +4 -0
- package/providers/index.js +12 -0
- package/reducers/form.d.ts +1 -1
- package/reducers/form.js +1 -1
- package/reducers/list.js +1 -3
- package/reducers/router.js +1 -1
- package/ui/crud/Crud/Crud.d.ts +1 -1
- package/ui/crud/index.d.ts +1 -0
- package/ui/form/TextField/TextField.d.ts +2 -1
- package/ui/form/TextField/TextField.js +1 -1
- package/ui/icon/Icon/Icon.js +3 -0
- package/ui/layout/Meta/Meta.d.ts +56 -0
- package/ui/layout/Meta/Meta.js +36 -0
- package/ui/layout/Meta/index.d.ts +2 -0
- package/ui/layout/Meta/index.js +7 -0
- package/ui/layout/Notifications/Notifications.js +1 -1
- package/ui/layout/Portal.js +3 -0
- package/ui/nav/Router/Router.d.ts +13 -0
- package/ui/nav/Router/Router.js +1 -1
- package/ui/nav/Router/SsrProvider.d.ts +0 -15
- package/ui/nav/Router/SsrProvider.js +0 -55
package/actions/list.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export declare const listInit: (listId: any, payload: any) => {
|
|
|
51
51
|
};
|
|
52
52
|
export declare const listSetItems: (listId: any, items: any) => {
|
|
53
53
|
type: string;
|
|
54
|
+
listId: any;
|
|
54
55
|
items: any;
|
|
55
56
|
};
|
|
56
57
|
export declare const listSetLayout: (listId: any, layoutName: any) => {
|
package/actions/list.js
CHANGED
|
@@ -133,6 +133,7 @@ var listInit = function (listId, payload) { return ({
|
|
|
133
133
|
exports.listInit = listInit;
|
|
134
134
|
var listSetItems = function (listId, items) { return ({
|
|
135
135
|
type: exports.LIST_SET_ITEMS,
|
|
136
|
+
listId: listId,
|
|
136
137
|
items: items
|
|
137
138
|
}); };
|
|
138
139
|
exports.listSetItems = listSetItems;
|
|
@@ -6,16 +6,16 @@ export default class ClientStorageComponent {
|
|
|
6
6
|
STORAGE_COOKIE: string;
|
|
7
7
|
STORAGE_LOCAL: any;
|
|
8
8
|
STORAGE_SESSION: any;
|
|
9
|
-
cookieAvailable: any;
|
|
10
9
|
localStorageAvailable: boolean;
|
|
11
10
|
sessionStorageAvailable: boolean;
|
|
12
|
-
|
|
11
|
+
private _ssrCookie;
|
|
12
|
+
constructor(components: any, config: any);
|
|
13
13
|
/**
|
|
14
14
|
* @param {string} name
|
|
15
15
|
* @param {string} [storageName]
|
|
16
16
|
* @returns {*}
|
|
17
17
|
*/
|
|
18
|
-
get(name: any, storageName: any):
|
|
18
|
+
get(name: any, storageName: any): any;
|
|
19
19
|
/**
|
|
20
20
|
* @param {string} name
|
|
21
21
|
* @param {*} value
|
|
@@ -18,17 +18,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
18
|
__setModuleDefault(result, mod);
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
21
24
|
exports.__esModule = true;
|
|
22
25
|
var cookie = __importStar(require("js-cookie"));
|
|
26
|
+
var moment_1 = __importDefault(require("moment"));
|
|
23
27
|
/**
|
|
24
28
|
* Client Storage Component
|
|
25
29
|
* Слой хранения данных в браузере (cookie, local/session storage) или ReactNative
|
|
26
30
|
*/
|
|
27
31
|
var ClientStorageComponent = /** @class */ (function () {
|
|
28
|
-
function ClientStorageComponent(components) {
|
|
32
|
+
function ClientStorageComponent(components, config) {
|
|
29
33
|
this.localStorageAvailable = !process.env.IS_SSR;
|
|
30
34
|
this.sessionStorageAvailable = !process.env.IS_SSR;
|
|
31
|
-
this.cookieAvailable = !process.env.IS_SSR;
|
|
32
35
|
this.STORAGE_SESSION = 'session';
|
|
33
36
|
this.STORAGE_LOCAL = 'local';
|
|
34
37
|
this.STORAGE_COOKIE = 'cookie';
|
|
@@ -52,6 +55,7 @@ var ClientStorageComponent = /** @class */ (function () {
|
|
|
52
55
|
this.sessionStorageAvailable = false;
|
|
53
56
|
}
|
|
54
57
|
}
|
|
58
|
+
this._ssrCookie = config === null || config === void 0 ? void 0 : config.ssrCookie;
|
|
55
59
|
}
|
|
56
60
|
/**
|
|
57
61
|
* @param {string} name
|
|
@@ -63,14 +67,11 @@ var ClientStorageComponent = /** @class */ (function () {
|
|
|
63
67
|
if (this.localStorageAvailable && storageName === this.STORAGE_LOCAL) {
|
|
64
68
|
return window.localStorage.getItem(name);
|
|
65
69
|
}
|
|
66
|
-
|
|
67
|
-
storageName === this.STORAGE_SESSION) {
|
|
70
|
+
if (this.sessionStorageAvailable
|
|
71
|
+
&& storageName === this.STORAGE_SESSION) {
|
|
68
72
|
return window.sessionStorage.getItem(name);
|
|
69
73
|
}
|
|
70
|
-
|
|
71
|
-
return cookie.get(name);
|
|
72
|
-
}
|
|
73
|
-
return null;
|
|
74
|
+
return process.env.IS_SSR ? this._ssrCookie.get(name) : cookie.get(name);
|
|
74
75
|
};
|
|
75
76
|
/**
|
|
76
77
|
* @param {string} name
|
|
@@ -84,15 +85,19 @@ var ClientStorageComponent = /** @class */ (function () {
|
|
|
84
85
|
if (this.localStorageAvailable && storageName === this.STORAGE_LOCAL) {
|
|
85
86
|
window.localStorage.setItem(name, value);
|
|
86
87
|
}
|
|
87
|
-
else if (this.sessionStorageAvailable
|
|
88
|
-
storageName === this.STORAGE_SESSION) {
|
|
88
|
+
else if (this.sessionStorageAvailable
|
|
89
|
+
&& storageName === this.STORAGE_SESSION) {
|
|
89
90
|
window.sessionStorage.setItem(name, value);
|
|
90
91
|
}
|
|
91
|
-
else
|
|
92
|
-
|
|
92
|
+
else {
|
|
93
|
+
var options = {
|
|
93
94
|
expires: expires,
|
|
94
95
|
domain: this._getDomain()
|
|
95
|
-
}
|
|
96
|
+
};
|
|
97
|
+
if (expires && process.env.IS_SSR) {
|
|
98
|
+
options.expires = moment_1["default"]().add(options.expires).utc().toDate();
|
|
99
|
+
}
|
|
100
|
+
process.env.IS_SSR ? this._ssrCookie.set(name, value, options) : cookie.set(name, value, options);
|
|
96
101
|
}
|
|
97
102
|
};
|
|
98
103
|
/**
|
|
@@ -105,24 +110,25 @@ var ClientStorageComponent = /** @class */ (function () {
|
|
|
105
110
|
if (this.localStorageAvailable && storageName === this.STORAGE_LOCAL) {
|
|
106
111
|
window.localStorage.removeItem(name);
|
|
107
112
|
}
|
|
108
|
-
else if (this.sessionStorageAvailable
|
|
109
|
-
storageName === this.STORAGE_SESSION) {
|
|
113
|
+
else if (this.sessionStorageAvailable
|
|
114
|
+
&& storageName === this.STORAGE_SESSION) {
|
|
110
115
|
window.sessionStorage.removeItem(name);
|
|
111
116
|
}
|
|
112
|
-
else
|
|
113
|
-
|
|
117
|
+
else {
|
|
118
|
+
var options = {
|
|
114
119
|
domain: this._getDomain()
|
|
115
|
-
}
|
|
120
|
+
};
|
|
121
|
+
process.env.IS_SSR ? this._ssrCookie.remove(name, options) : cookie.remove(name, options);
|
|
116
122
|
}
|
|
117
123
|
};
|
|
118
124
|
ClientStorageComponent.prototype._getDomain = function () {
|
|
119
125
|
var host = (typeof location !== 'undefined' && location.hostname) || '';
|
|
120
|
-
return ((!/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/.test(host)
|
|
121
|
-
host
|
|
126
|
+
return ((!/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/.test(host)
|
|
127
|
+
&& host
|
|
122
128
|
.split('.')
|
|
123
129
|
.slice(-2)
|
|
124
|
-
.join('.'))
|
|
125
|
-
host);
|
|
130
|
+
.join('.'))
|
|
131
|
+
|| host);
|
|
126
132
|
};
|
|
127
133
|
return ClientStorageComponent;
|
|
128
134
|
}());
|
|
@@ -52,6 +52,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
52
52
|
exports.__esModule = true;
|
|
53
53
|
var trimStart_1 = __importDefault(require("lodash-es/trimStart"));
|
|
54
54
|
var trimEnd_1 = __importDefault(require("lodash-es/trimEnd"));
|
|
55
|
+
var isEmpty_1 = __importDefault(require("lodash-es/isEmpty"));
|
|
56
|
+
var set_cookie_parser_1 = __importDefault(require("set-cookie-parser"));
|
|
55
57
|
var axios_1 = __importDefault(require("axios"));
|
|
56
58
|
var notifications_1 = require("../actions/notifications");
|
|
57
59
|
/**
|
|
@@ -65,13 +67,12 @@ var HttpComponent = /** @class */ (function () {
|
|
|
65
67
|
this._components = components;
|
|
66
68
|
this.apiUrl = config.apiUrl
|
|
67
69
|
//|| process.env.APP_BACKEND_URL
|
|
68
|
-
|| (
|
|
70
|
+
|| (!process.env.IS_SSR ? window.location.protocol + '//' + window.location.host : '');
|
|
69
71
|
this.accessTokenKey = config.accessTokenKey || 'accessToken';
|
|
70
72
|
this._lazyRequests = {};
|
|
71
73
|
this._axios = null;
|
|
72
74
|
this._csrfToken = null;
|
|
73
75
|
this._accessToken = false;
|
|
74
|
-
this._promises = [];
|
|
75
76
|
}
|
|
76
77
|
HttpComponent.prototype.getAxiosConfig = function () {
|
|
77
78
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -191,7 +192,7 @@ var HttpComponent = /** @class */ (function () {
|
|
|
191
192
|
});
|
|
192
193
|
};
|
|
193
194
|
HttpComponent.prototype.getUrl = function (method) {
|
|
194
|
-
if (method === null &&
|
|
195
|
+
if (method === null && !process.env.IS_SSR) {
|
|
195
196
|
method = window.location.pathname;
|
|
196
197
|
}
|
|
197
198
|
if (method.indexOf('://') === -1) {
|
|
@@ -236,7 +237,21 @@ var HttpComponent = /** @class */ (function () {
|
|
|
236
237
|
};
|
|
237
238
|
HttpComponent.prototype._send = function (method, config, options) {
|
|
238
239
|
var _this = this;
|
|
240
|
+
var _a;
|
|
239
241
|
var axiosConfig = __assign(__assign({}, config), { url: this.getUrl(method) });
|
|
242
|
+
// Manual send cookies for preload data in ssr
|
|
243
|
+
if (process.env.IS_SSR && axiosConfig.url.indexOf(this.apiUrl) !== -1) {
|
|
244
|
+
var clientStorage = this._components.clientStorage;
|
|
245
|
+
axiosConfig.headers = __assign(__assign({}, axiosConfig.headers), { Cookie: Object
|
|
246
|
+
.entries(clientStorage.get(null, clientStorage.STORAGE_COOKIE) || {})
|
|
247
|
+
.map(function (_a) {
|
|
248
|
+
var key = _a[0], value = _a[1];
|
|
249
|
+
return key + "=" + value;
|
|
250
|
+
})
|
|
251
|
+
.concat([(_a = axiosConfig.headers) === null || _a === void 0 ? void 0 : _a.Cookie])
|
|
252
|
+
.filter(Boolean)
|
|
253
|
+
.join(';') });
|
|
254
|
+
}
|
|
240
255
|
if (options.cancelToken) {
|
|
241
256
|
axiosConfig.cancelToken = options.cancelToken;
|
|
242
257
|
}
|
|
@@ -258,25 +273,27 @@ var HttpComponent = /** @class */ (function () {
|
|
|
258
273
|
};
|
|
259
274
|
HttpComponent.prototype._sendAxios = function (config, options) {
|
|
260
275
|
var _this = this;
|
|
261
|
-
|
|
276
|
+
return this.getAxiosInstance()
|
|
262
277
|
.then(function (instance) { return instance(config); })
|
|
263
278
|
.then(function (response) { return _this.afterRequest(response, config, options).then(function (newResponse) { return newResponse || response; }); })["catch"](function (error) {
|
|
264
279
|
console.error('Error, request/response: ', config, String(error)); // eslint-disable-line no-console
|
|
265
280
|
throw error;
|
|
266
281
|
});
|
|
267
|
-
// Store promises for SSR
|
|
268
|
-
if (process.env.IS_SSR) {
|
|
269
|
-
this._promises.push(promise);
|
|
270
|
-
}
|
|
271
|
-
return promise;
|
|
272
282
|
};
|
|
273
283
|
HttpComponent.prototype.afterRequest = function (response, config, options) {
|
|
274
284
|
return __awaiter(this, void 0, void 0, function () {
|
|
275
|
-
var store, match, providerName;
|
|
276
|
-
return __generator(this, function (
|
|
277
|
-
switch (
|
|
285
|
+
var _a, store, clientStorage, cookie, match, providerName;
|
|
286
|
+
return __generator(this, function (_b) {
|
|
287
|
+
switch (_b.label) {
|
|
278
288
|
case 0:
|
|
279
|
-
|
|
289
|
+
_a = this._components, store = _a.store, clientStorage = _a.clientStorage;
|
|
290
|
+
cookie = response.headers['set-cookie'];
|
|
291
|
+
if (process.env.IS_SSR && config.url.indexOf(this.apiUrl) !== -1 && !isEmpty_1["default"](cookie)) {
|
|
292
|
+
set_cookie_parser_1["default"].parse(cookie).forEach(function (_a) {
|
|
293
|
+
var name = _a.name, value = _a.value, expires = _a.expires;
|
|
294
|
+
return (clientStorage.set(name, value, clientStorage.STORAGE_COOKIE, expires));
|
|
295
|
+
});
|
|
296
|
+
}
|
|
280
297
|
// Flash
|
|
281
298
|
if (response.data.flashes) {
|
|
282
299
|
store.dispatch(notifications_1.setFlashes(response.data.flashes));
|
|
@@ -301,14 +318,14 @@ var HttpComponent = /** @class */ (function () {
|
|
|
301
318
|
if (!options.onTwoFactor) return [3 /*break*/, 2];
|
|
302
319
|
return [4 /*yield*/, options.onTwoFactor(providerName)];
|
|
303
320
|
case 1:
|
|
304
|
-
|
|
321
|
+
_b.sent();
|
|
305
322
|
return [3 /*break*/, 4];
|
|
306
323
|
case 2:
|
|
307
324
|
// Require verification code
|
|
308
325
|
return [4 /*yield*/, this._onTwoFactor(providerName)];
|
|
309
326
|
case 3:
|
|
310
327
|
// Require verification code
|
|
311
|
-
|
|
328
|
+
_b.sent();
|
|
312
329
|
// Retry request
|
|
313
330
|
return [2 /*return*/, this._sendAxios(config, options)];
|
|
314
331
|
case 4: return [2 /*return*/, response];
|
|
@@ -73,11 +73,11 @@ var LocaleComponent = /** @class */ (function () {
|
|
|
73
73
|
LocaleComponent.prototype.moment = function (date, format) {
|
|
74
74
|
if (date === void 0) { date = undefined; }
|
|
75
75
|
if (format === void 0) { format = undefined; }
|
|
76
|
-
if (this.backendTimeZone
|
|
77
|
-
date
|
|
78
|
-
date.length === 19
|
|
79
|
-
moment_1["default"](date, 'YYYY-MM-DD HH:mm:ss').isValid()) {
|
|
80
|
-
date
|
|
76
|
+
if (this.backendTimeZone
|
|
77
|
+
&& date
|
|
78
|
+
&& date.length === 19
|
|
79
|
+
&& moment_1["default"](date, 'YYYY-MM-DD HH:mm:ss').isValid()) {
|
|
80
|
+
date += this.backendTimeZone;
|
|
81
81
|
}
|
|
82
82
|
return moment_1["default"](date, format).locale(this.language);
|
|
83
83
|
};
|
|
@@ -126,7 +126,7 @@ var LocaleComponent = /** @class */ (function () {
|
|
|
126
126
|
if (a.index < b.index) {
|
|
127
127
|
return -1;
|
|
128
128
|
}
|
|
129
|
-
|
|
129
|
+
if (a.index > b.index) {
|
|
130
130
|
return 1;
|
|
131
131
|
}
|
|
132
132
|
return 0;
|
|
@@ -136,9 +136,9 @@ var LocaleComponent = /** @class */ (function () {
|
|
|
136
136
|
var textParts = message.split('!!component!!');
|
|
137
137
|
for (var i = 0, j = 0; i < textParts.length; i++) {
|
|
138
138
|
var isComponentAdded = false;
|
|
139
|
-
if (j === 0
|
|
140
|
-
j < indexedComponents.length
|
|
141
|
-
indexedComponents[j].index === 0) {
|
|
139
|
+
if (j === 0
|
|
140
|
+
&& j < indexedComponents.length
|
|
141
|
+
&& indexedComponents[j].index === 0) {
|
|
142
142
|
result.push(React.createElement("span", { key: "element-" + j }, indexedComponents[j].component));
|
|
143
143
|
isComponentAdded = true;
|
|
144
144
|
j++;
|
|
@@ -15,7 +15,9 @@ var MetricsComponent = /** @class */ (function () {
|
|
|
15
15
|
this._enable = config.enable === undefined
|
|
16
16
|
? process.env.APP_ENV === 'prod'
|
|
17
17
|
: !!config.enable;
|
|
18
|
-
|
|
18
|
+
if (!process.env.IS_SSR) {
|
|
19
|
+
this._init();
|
|
20
|
+
}
|
|
19
21
|
}
|
|
20
22
|
MetricsComponent.prototype._init = function () {
|
|
21
23
|
var _this = this;
|
|
@@ -37,7 +37,7 @@ var StoreComponent = /** @class */ (function () {
|
|
|
37
37
|
this.dispatch = this.dispatch.bind(this);
|
|
38
38
|
this.subscribe = this.subscribe.bind(this);
|
|
39
39
|
if (!lazyInit) {
|
|
40
|
-
this.initStore();
|
|
40
|
+
this.initStore(config);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
StoreComponent.prototype.init = function (config) {
|
|
@@ -49,8 +49,10 @@ var StoreComponent = /** @class */ (function () {
|
|
|
49
49
|
var _this = this;
|
|
50
50
|
if (config === void 0) { config = {}; }
|
|
51
51
|
var initialState = __assign(__assign({}, (process.env.IS_WEB
|
|
52
|
-
// @ts-ignore
|
|
53
52
|
? merge_1["default"].apply(void 0, (window.APP_REDUX_PRELOAD_STATES || [{}])) : {})), config.initialState);
|
|
53
|
+
if (window === null || window === void 0 ? void 0 : window.APP_REDUX_PRELOAD_STATES) {
|
|
54
|
+
delete window.APP_REDUX_PRELOAD_STATES;
|
|
55
|
+
}
|
|
54
56
|
if (process.env.PLATFORM !== 'mobile') {
|
|
55
57
|
var createHistory = process.env.IS_SSR || typeof location === 'undefined'
|
|
56
58
|
? history_1.createMemoryHistory
|
|
@@ -70,10 +72,7 @@ var StoreComponent = /** @class */ (function () {
|
|
|
70
72
|
} : {}), initialState, redux_1.compose(redux_1.applyMiddleware(function (_a) {
|
|
71
73
|
var getState = _a.getState;
|
|
72
74
|
return function (next) { return function (action) { return _this._prepare(action, next, getState); }; };
|
|
73
|
-
}), redux_1.applyMiddleware(connected_react_router_1.routerMiddleware(this.history)),
|
|
74
|
-
// @ts-ignore
|
|
75
|
-
!process.env.IS_SSR && window.__REDUX_DEVTOOLS_EXTENSION__ && process.env.PLATFORM !== 'mobile'
|
|
76
|
-
// @ts-ignore
|
|
75
|
+
}), redux_1.applyMiddleware(connected_react_router_1.routerMiddleware(this.history)), !process.env.IS_SSR && window.__REDUX_DEVTOOLS_EXTENSION__ && process.env.PLATFORM !== 'mobile'
|
|
77
76
|
? window.__REDUX_DEVTOOLS_EXTENSION__()
|
|
78
77
|
: function (f) { return f; }));
|
|
79
78
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Компонент, обеспечивающий постоянное web-socket соединение с сервером. Поддерживает подписку на каналы, обработку
|
|
4
4
|
* ответов и токен авторизации
|
|
5
5
|
*/
|
|
6
|
-
import { IComponents } from '../
|
|
6
|
+
import { IComponents } from '../providers/ComponentsProvider';
|
|
7
7
|
export default class WebSocketComponent {
|
|
8
8
|
wsUrl: string;
|
|
9
9
|
streams: string[] | [string, string | number[]][];
|
package/hoc/components.d.ts
CHANGED
package/hoc/components.js
CHANGED
|
@@ -36,7 +36,7 @@ var exportComponents = function (components, names) {
|
|
|
36
36
|
var props = {};
|
|
37
37
|
names.forEach(function (items) {
|
|
38
38
|
[].concat(items).forEach(function (name) {
|
|
39
|
-
props[name] =
|
|
39
|
+
props[name] = components[name];
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
42
|
return props;
|
package/hooks/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ import useDataProvider from './useDataProvider';
|
|
|
4
4
|
import useDataSelect from './useDataSelect';
|
|
5
5
|
import useSelector from './useSelector';
|
|
6
6
|
import useForm from './useForm';
|
|
7
|
-
|
|
7
|
+
import useSsr from './useSsr';
|
|
8
|
+
export { useBem, useComponents, useDataProvider, useDataSelect, useSelector, useForm, useSsr, };
|
package/hooks/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
exports.__esModule = true;
|
|
6
|
-
exports.useForm = exports.useSelector = exports.useDataSelect = exports.useDataProvider = exports.useComponents = exports.useBem = void 0;
|
|
6
|
+
exports.useSsr = exports.useForm = exports.useSelector = exports.useDataSelect = exports.useDataProvider = exports.useComponents = exports.useBem = void 0;
|
|
7
7
|
var useBem_1 = __importDefault(require("./useBem"));
|
|
8
8
|
exports.useBem = useBem_1["default"];
|
|
9
9
|
var useComponents_1 = __importDefault(require("./useComponents"));
|
|
@@ -16,3 +16,5 @@ var useSelector_1 = __importDefault(require("./useSelector"));
|
|
|
16
16
|
exports.useSelector = useSelector_1["default"];
|
|
17
17
|
var useForm_1 = __importDefault(require("./useForm"));
|
|
18
18
|
exports.useForm = useForm_1["default"];
|
|
19
|
+
var useSsr_1 = __importDefault(require("./useSsr"));
|
|
20
|
+
exports.useSsr = useSsr_1["default"];
|
|
@@ -1,29 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import ClientStorageComponent from '../components/ClientStorageComponent';
|
|
3
|
+
import HtmlComponent from '../components/HtmlComponent';
|
|
4
|
+
import StoreComponent from '../components/StoreComponent';
|
|
5
|
+
import UiComponent from '../components/UiComponent';
|
|
6
|
+
import MetaComponent from '../components/MetaComponent';
|
|
7
|
+
import { IComponents } from '../providers/ComponentsProvider';
|
|
4
8
|
import { IRouteItem } from '../ui/nav/Router/Router';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
media: Record<string, any>;
|
|
8
|
-
setMedia: any;
|
|
9
|
-
isPhone: () => boolean;
|
|
10
|
-
isTablet: () => boolean;
|
|
11
|
-
isDesktop: () => boolean;
|
|
12
|
-
getDeviceType: () => string;
|
|
13
|
-
}
|
|
14
|
-
export declare const ScreenContext: React.Context<IScreen>;
|
|
15
|
-
export interface IScreenProviderProps extends PropsWithChildren<any> {
|
|
16
|
-
media?: Record<string, any>;
|
|
17
|
-
skipTimeout?: boolean;
|
|
18
|
-
}
|
|
19
|
-
export declare const SCREEN_PHONE = "phone";
|
|
20
|
-
export declare const SCREEN_TABLET = "tablet";
|
|
21
|
-
export declare const SCREEN_DESKTOP = "desktop";
|
|
22
|
-
declare global {
|
|
23
|
-
interface Window {
|
|
24
|
-
SteroidsComponents: IComponents;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
9
|
+
import MetricsComponent from '../components/MetricsComponent';
|
|
10
|
+
import { IScreenProviderProps } from '../providers/ScreenProvider';
|
|
27
11
|
/**
|
|
28
12
|
* Application HOC
|
|
29
13
|
* Обертка над корневым компонентом приложения, используется только в `Application.tsx`. Добавляет через React Context
|
|
@@ -48,5 +32,24 @@ export interface IApplicationHookResult {
|
|
|
48
32
|
renderApplication: (children?: any) => JSX.Element;
|
|
49
33
|
components: IComponents;
|
|
50
34
|
}
|
|
51
|
-
export declare const
|
|
35
|
+
export declare const defaultComponents: {
|
|
36
|
+
clientStorage: {
|
|
37
|
+
className: typeof ClientStorageComponent;
|
|
38
|
+
};
|
|
39
|
+
html: {
|
|
40
|
+
className: typeof HtmlComponent;
|
|
41
|
+
};
|
|
42
|
+
meta: {
|
|
43
|
+
className: typeof MetaComponent;
|
|
44
|
+
};
|
|
45
|
+
store: {
|
|
46
|
+
className: typeof StoreComponent;
|
|
47
|
+
};
|
|
48
|
+
ui: {
|
|
49
|
+
className: typeof UiComponent;
|
|
50
|
+
};
|
|
51
|
+
metrics: {
|
|
52
|
+
className: typeof MetricsComponent;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
52
55
|
export default function useApplication(config?: IApplicationHookConfig): IApplicationHookResult;
|
package/hooks/useApplication.js
CHANGED
|
@@ -44,86 +44,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
44
44
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
45
45
|
};
|
|
46
46
|
exports.__esModule = true;
|
|
47
|
-
exports.
|
|
47
|
+
exports.defaultComponents = void 0;
|
|
48
48
|
var React = __importStar(require("react"));
|
|
49
49
|
var react_redux_1 = require("react-redux");
|
|
50
50
|
var merge_1 = __importDefault(require("lodash-es/merge"));
|
|
51
51
|
var react_1 = require("react");
|
|
52
|
-
var react_use_1 = require("react-use");
|
|
53
52
|
var ClientStorageComponent_1 = __importDefault(require("../components/ClientStorageComponent"));
|
|
54
53
|
var HtmlComponent_1 = __importDefault(require("../components/HtmlComponent"));
|
|
55
54
|
var StoreComponent_1 = __importDefault(require("../components/StoreComponent"));
|
|
56
55
|
var UiComponent_1 = __importDefault(require("../components/UiComponent"));
|
|
57
56
|
var MetaComponent_1 = __importDefault(require("../components/MetaComponent"));
|
|
57
|
+
var ComponentsProvider_1 = __importDefault(require("../providers/ComponentsProvider"));
|
|
58
58
|
var Router_1 = __importDefault(require("../ui/nav/Router/Router"));
|
|
59
59
|
var MetricsComponent_1 = __importDefault(require("../components/MetricsComponent"));
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
exports.
|
|
63
|
-
exports.SCREEN_DESKTOP = 'desktop';
|
|
64
|
-
function ScreenProvider(props) {
|
|
65
|
-
var _a;
|
|
66
|
-
var _b = react_1.useState(typeof window !== 'undefined' ? window.innerWidth : 1280), width = _b[0], setWidth = _b[1];
|
|
67
|
-
var _c = react_1.useState(props.media || (_a = {},
|
|
68
|
-
_a[exports.SCREEN_PHONE] = 320,
|
|
69
|
-
_a[exports.SCREEN_TABLET] = 768,
|
|
70
|
-
_a[exports.SCREEN_DESKTOP] = 1024,
|
|
71
|
-
_a)), media = _c[0], setMedia = _c[1];
|
|
72
|
-
var timer = null;
|
|
73
|
-
var onResize = function () {
|
|
74
|
-
if (timer) {
|
|
75
|
-
clearTimeout(timer);
|
|
76
|
-
}
|
|
77
|
-
if (props.skipTimeout) {
|
|
78
|
-
setWidth(window.innerWidth);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
timer = setTimeout(function () { return setWidth(window.innerWidth); }, 100);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
react_use_1.useMount(function () {
|
|
85
|
-
if (typeof window !== 'undefined') {
|
|
86
|
-
window.addEventListener('resize', onResize, false);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
react_use_1.useUnmount(function () {
|
|
90
|
-
if (typeof window !== 'undefined') {
|
|
91
|
-
window.removeEventListener('resize', onResize);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
var getDeviceType = react_1.useCallback(function () {
|
|
95
|
-
if (width < media[exports.SCREEN_TABLET]) {
|
|
96
|
-
return exports.SCREEN_PHONE;
|
|
97
|
-
}
|
|
98
|
-
if (width < media[exports.SCREEN_DESKTOP]) {
|
|
99
|
-
return exports.SCREEN_TABLET;
|
|
100
|
-
}
|
|
101
|
-
return exports.SCREEN_DESKTOP;
|
|
102
|
-
}, [width, media]);
|
|
103
|
-
var isPhone = react_1.useCallback(function () { return getDeviceType() === exports.SCREEN_PHONE; }, [getDeviceType]);
|
|
104
|
-
var isTablet = react_1.useCallback(function () { return getDeviceType() === exports.SCREEN_TABLET; }, [getDeviceType]);
|
|
105
|
-
var isDesktop = react_1.useCallback(function () { return getDeviceType() === exports.SCREEN_DESKTOP; }, [getDeviceType]);
|
|
106
|
-
var value = react_1.useMemo(function () { return ({
|
|
107
|
-
width: width,
|
|
108
|
-
media: media,
|
|
109
|
-
setMedia: setMedia,
|
|
110
|
-
isPhone: isPhone,
|
|
111
|
-
isTablet: isTablet,
|
|
112
|
-
isDesktop: isDesktop,
|
|
113
|
-
getDeviceType: getDeviceType
|
|
114
|
-
}); }, [
|
|
115
|
-
width,
|
|
116
|
-
media,
|
|
117
|
-
setMedia,
|
|
118
|
-
isPhone,
|
|
119
|
-
isTablet,
|
|
120
|
-
isDesktop,
|
|
121
|
-
getDeviceType,
|
|
122
|
-
]);
|
|
123
|
-
return (React.createElement(exports.ScreenContext.Provider, { value: value }, props.children));
|
|
124
|
-
}
|
|
125
|
-
exports.ComponentsContext = React.createContext({});
|
|
126
|
-
var defaultComponents = {
|
|
60
|
+
var ScreenProvider_1 = __importDefault(require("../providers/ScreenProvider"));
|
|
61
|
+
var useComponents_1 = __importDefault(require("./useComponents"));
|
|
62
|
+
exports.defaultComponents = {
|
|
127
63
|
clientStorage: {
|
|
128
64
|
className: ClientStorageComponent_1["default"]
|
|
129
65
|
},
|
|
@@ -151,31 +87,30 @@ var defaultComponents = {
|
|
|
151
87
|
};
|
|
152
88
|
function useApplication(config) {
|
|
153
89
|
if (config === void 0) { config = {}; }
|
|
154
|
-
var
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (useGlobal) {
|
|
90
|
+
var useGlobal = config.useGlobal !== false;
|
|
91
|
+
var components = useComponents_1["default"]();
|
|
92
|
+
if (useGlobal && !process.env.IS_SSR) {
|
|
158
93
|
components = window.SteroidsComponents || null;
|
|
159
94
|
}
|
|
160
95
|
// Create components
|
|
161
96
|
if (!components) {
|
|
162
97
|
components = {};
|
|
163
|
-
var componentsConfig_1 = merge_1["default"]({}, defaultComponents, config.components);
|
|
98
|
+
var componentsConfig_1 = merge_1["default"]({}, exports.defaultComponents, config.components);
|
|
164
99
|
Object.keys(componentsConfig_1).forEach(function (name) {
|
|
165
100
|
if (typeof componentsConfig_1[name] === 'function') {
|
|
166
101
|
componentsConfig_1[name] = { className: componentsConfig_1[name] };
|
|
167
102
|
}
|
|
168
103
|
var _a = componentsConfig_1[name], className = _a.className, componentConfig = __rest(_a, ["className"]);
|
|
169
104
|
// Append reducers to store
|
|
170
|
-
if (name === 'store'
|
|
171
|
-
|
|
105
|
+
if (name === 'store') {
|
|
106
|
+
if (config.reducers) {
|
|
107
|
+
componentConfig.reducers = config.reducers;
|
|
108
|
+
}
|
|
172
109
|
}
|
|
173
110
|
// eslint-disable-next-line new-cap
|
|
174
111
|
components[name] = new className(components, componentConfig);
|
|
175
112
|
});
|
|
176
|
-
|
|
177
|
-
window.SteroidsComponents = components;
|
|
178
|
-
}
|
|
113
|
+
window.SteroidsComponents = components;
|
|
179
114
|
// Init callback
|
|
180
115
|
if (config.onInit) {
|
|
181
116
|
config.onInit(components);
|
|
@@ -190,10 +125,10 @@ function useApplication(config) {
|
|
|
190
125
|
content = (React.createElement(Router_1["default"], { routes: config.routes(), wrapperView: config.layoutView(), wrapperProps: config.layoutProps }));
|
|
191
126
|
}
|
|
192
127
|
if (config.screen) {
|
|
193
|
-
content = (React.createElement(
|
|
128
|
+
content = (React.createElement(ScreenProvider_1["default"], __assign({}, config.screen), content));
|
|
194
129
|
}
|
|
195
|
-
if (!useGlobal) {
|
|
196
|
-
content = (React.createElement(
|
|
130
|
+
if (!(useGlobal || process.env.IS_SSR)) {
|
|
131
|
+
content = (React.createElement(ComponentsProvider_1["default"], { components: components }, content));
|
|
197
132
|
}
|
|
198
133
|
return (React.createElement(react_redux_1.Provider, { store: components.store.store }, content));
|
|
199
134
|
}, [components, config, useGlobal]);
|
package/hooks/useComponents.d.ts
CHANGED
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
api?: any;
|
|
3
|
-
clientStorage?: any;
|
|
4
|
-
html?: any;
|
|
5
|
-
http?: any;
|
|
6
|
-
locale?: any;
|
|
7
|
-
store?: any;
|
|
8
|
-
ui?: any;
|
|
9
|
-
resource?: any;
|
|
10
|
-
ws?: any;
|
|
11
|
-
pushNotification?: any;
|
|
12
|
-
meta?: any;
|
|
13
|
-
[key: string]: any;
|
|
14
|
-
}
|
|
1
|
+
import { IComponents } from '../providers/ComponentsProvider';
|
|
15
2
|
export default function useComponents(): IComponents;
|