@steroidsjs/core 2.1.0-beta.15 → 2.1.0-beta.19

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.
Files changed (97) hide show
  1. package/actions/list.d.ts +1 -0
  2. package/actions/list.js +1 -0
  3. package/components/ClientStorageComponent.d.ts +3 -3
  4. package/components/ClientStorageComponent.js +28 -22
  5. package/components/HttpComponent.js +32 -15
  6. package/components/LocaleComponent.js +9 -9
  7. package/components/MetricsComponent.js +3 -1
  8. package/components/StoreComponent.d.ts +6 -0
  9. package/components/StoreComponent.js +5 -6
  10. package/components/UiComponent.d.ts +1 -1
  11. package/components/WebSocketComponent.d.ts +1 -1
  12. package/hoc/components.d.ts +1 -1
  13. package/hoc/components.js +1 -1
  14. package/hooks/index.d.ts +2 -1
  15. package/hooks/index.js +3 -1
  16. package/hooks/useApplication.d.ts +29 -26
  17. package/hooks/useApplication.js +17 -82
  18. package/hooks/useComponents.d.ts +1 -14
  19. package/hooks/useComponents.js +5 -5
  20. package/hooks/useFetch.d.ts +11 -3
  21. package/hooks/useFetch.js +34 -31
  22. package/hooks/useLayout.d.ts +9 -0
  23. package/hooks/useLayout.js +64 -44
  24. package/hooks/useList.d.ts +45 -0
  25. package/hooks/useList.js +83 -53
  26. package/hooks/useModel.js +1 -1
  27. package/hooks/useScreen.d.ts +1 -1
  28. package/hooks/useScreen.js +2 -2
  29. package/hooks/useSsr.d.ts +2 -0
  30. package/hooks/useSsr.js +8 -0
  31. package/index.d.ts +8 -2
  32. package/package.json +4 -2
  33. package/providers/ComponentsProvider.d.ts +26 -0
  34. package/providers/ComponentsProvider.js +28 -0
  35. package/providers/ScreenProvider.d.ts +20 -0
  36. package/providers/ScreenProvider.js +87 -0
  37. package/providers/SsrProvider.d.ts +17 -0
  38. package/providers/SsrProvider.js +32 -0
  39. package/providers/index.d.ts +4 -0
  40. package/providers/index.js +12 -0
  41. package/reducers/form.d.ts +1 -1
  42. package/reducers/form.js +1 -1
  43. package/reducers/list.js +1 -3
  44. package/reducers/router.js +1 -1
  45. package/ui/content/Alert/Alert.d.ts +50 -0
  46. package/ui/content/Alert/Alert.js +39 -0
  47. package/ui/content/Alert/index.d.ts +2 -0
  48. package/ui/content/Alert/index.js +7 -0
  49. package/ui/content/Avatar/Avatar.d.ts +53 -12
  50. package/ui/content/Avatar/Avatar.js +25 -4
  51. package/ui/content/Avatar/index.d.ts +6 -1
  52. package/ui/content/Avatar/index.js +4 -0
  53. package/ui/content/Card/Card.d.ts +61 -13
  54. package/ui/content/Card/Card.js +3 -2
  55. package/ui/content/Collapse/Collapse.d.ts +63 -0
  56. package/ui/content/Collapse/Collapse.js +75 -0
  57. package/ui/content/Collapse/CollapseItem.d.ts +67 -0
  58. package/ui/content/Collapse/CollapseItem.js +22 -0
  59. package/ui/content/Collapse/index.d.ts +7 -0
  60. package/ui/content/Collapse/index.js +8 -0
  61. package/ui/content/index.d.ts +13 -0
  62. package/ui/content/index.js +22 -0
  63. package/ui/crud/Crud/Crud.d.ts +1 -1
  64. package/ui/crud/index.d.ts +1 -0
  65. package/ui/form/Button/Button.d.ts +1 -0
  66. package/ui/form/Button/Button.js +1 -0
  67. package/ui/form/DropDownField/DropDownField.js +4 -2
  68. package/ui/form/Form/Form.js +1 -1
  69. package/ui/form/InputField/InputField.d.ts +7 -0
  70. package/ui/form/InputField/InputField.js +1 -0
  71. package/ui/form/TextField/TextField.d.ts +2 -1
  72. package/ui/form/TextField/TextField.js +1 -1
  73. package/ui/icon/Icon/Icon.js +3 -0
  74. package/ui/layout/Meta/Meta.d.ts +56 -0
  75. package/ui/layout/Meta/Meta.js +38 -0
  76. package/ui/layout/Meta/index.d.ts +2 -0
  77. package/ui/layout/Meta/index.js +7 -0
  78. package/ui/layout/Notifications/Notifications.js +1 -1
  79. package/ui/layout/Portal.js +3 -0
  80. package/ui/layout/ProgressBar/ProgressBar.d.ts +55 -0
  81. package/ui/layout/ProgressBar/ProgressBar.js +52 -0
  82. package/ui/layout/ProgressBar/index.d.ts +2 -0
  83. package/ui/layout/ProgressBar/index.js +7 -0
  84. package/ui/layout/Skeleton/Skeleton.d.ts +25 -0
  85. package/ui/layout/Skeleton/Skeleton.js +11 -0
  86. package/ui/layout/Skeleton/index.d.ts +2 -0
  87. package/ui/layout/Skeleton/index.js +7 -0
  88. package/ui/list/Steps/Steps.d.ts +32 -0
  89. package/ui/list/Steps/Steps.js +23 -0
  90. package/ui/list/Steps/index.d.ts +2 -0
  91. package/ui/list/Steps/index.js +7 -0
  92. package/ui/nav/Router/Router.d.ts +13 -0
  93. package/ui/nav/Router/Router.js +1 -1
  94. package/ui/content/Avatar/SizeContext.d.ts +0 -1
  95. package/ui/content/Avatar/SizeContext.js +0 -14
  96. package/ui/nav/Router/SsrProvider.d.ts +0 -15
  97. package/ui/nav/Router/SsrProvider.js +0 -55
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
- //import {useContext} from 'react';
3
2
  exports.__esModule = true;
3
+ var react_1 = require("react");
4
+ var ComponentsProvider_1 = require("../providers/ComponentsProvider");
4
5
  function useComponents() {
5
- if (typeof window !== 'undefined' && window.SteroidsComponents) {
6
+ var components = react_1.useContext(ComponentsProvider_1.ComponentsContext);
7
+ if (!process.env.IS_SSR) {
6
8
  return window.SteroidsComponents;
7
9
  }
8
- // TODO Get components from context
9
- //return useContext(ComponentsContext);
10
- return null;
10
+ return components;
11
11
  }
12
12
  exports["default"] = useComponents;
@@ -1,5 +1,10 @@
1
- import { IComponents } from './useComponents';
1
+ import { IComponents } from '../providers/ComponentsProvider';
2
2
  import { IApiMethod } from '../components/ApiComponent';
3
+ declare global {
4
+ interface Window {
5
+ APP_PRELOADED_DATA: any;
6
+ }
7
+ }
3
8
  export interface IFetchConfig {
4
9
  id?: string | number;
5
10
  url?: string | IApiMethod;
@@ -18,6 +23,10 @@ export interface IFetchResult {
18
23
  isLoading: boolean;
19
24
  fetch?: (newParams?: Record<string, unknown>) => void;
20
25
  }
26
+ export declare const normalizeConfig: (config: any) => any;
27
+ export declare const getConfigId: (config: any) => any;
28
+ export declare const defaultFetchHandler: (config: any, components: any, addCancelToken: any) => any;
29
+ export declare const fetchData: (config: any, components: any, addCancelToken: any) => any;
21
30
  /**
22
31
  * Fetch
23
32
  * Используется для подгрузки данных с бекенда перед рендером компонента, на котором он применяется.
@@ -25,7 +34,6 @@ export interface IFetchResult {
25
34
  * которые описывают откуда нужно подтянуть данные.
26
35
  *
27
36
  * В процесс загрузки HOC будет отображать "Загрузка...", а после уже отрендерит компонент, передав данные в указанный
28
- * ключ `key`. Все данные сохраняются в Redux Store, что позволяет избежать дополнительных запросов при использовании
29
- * SSR.
37
+ * ключ `key`.
30
38
  */
31
39
  export default function useFetch(rawConfig?: IFetchConfig): IFetchResult;
package/hooks/useFetch.js CHANGED
@@ -50,12 +50,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
51
  };
52
52
  exports.__esModule = true;
53
+ exports.fetchData = exports.defaultFetchHandler = exports.getConfigId = exports.normalizeConfig = void 0;
53
54
  var react_1 = require("react");
54
55
  var react_use_1 = require("react-use");
56
+ var trim_1 = __importDefault(require("lodash-es/trim"));
55
57
  var axios_1 = __importDefault(require("axios"));
56
58
  var index_1 = require("./index");
57
59
  var normalizeConfig = function (config) { return (config
58
60
  ? __assign({ id: null, url: '', method: 'get', params: {}, options: null, onFetch: null }, config) : null); };
61
+ exports.normalizeConfig = normalizeConfig;
62
+ var getConfigId = function (config) {
63
+ var result = trim_1["default"](config.id || config.url, '/');
64
+ if (!result) {
65
+ // eslint-disable-next-line no-console
66
+ console.warn('Please set id for fetch config, it`s necessary for SSR to work properly');
67
+ }
68
+ return result;
69
+ };
70
+ exports.getConfigId = getConfigId;
59
71
  var defaultFetchHandler = function (config, components, addCancelToken) {
60
72
  var cancelToken = new axios_1["default"].CancelToken(function (cancel) {
61
73
  addCancelToken(cancel);
@@ -67,6 +79,9 @@ var defaultFetchHandler = function (config, components, addCancelToken) {
67
79
  .send(config.method, config.url, config.params, __assign(__assign({}, config.options), { cancelToken: cancelToken }))
68
80
  .then(function (result) { return result.data; });
69
81
  };
82
+ exports.defaultFetchHandler = defaultFetchHandler;
83
+ var fetchData = function (config, components, addCancelToken) { return ((config.onFetch || exports.defaultFetchHandler).call(null, config, components, addCancelToken)); };
84
+ exports.fetchData = fetchData;
70
85
  /**
71
86
  * Fetch
72
87
  * Используется для подгрузки данных с бекенда перед рендером компонента, на котором он применяется.
@@ -74,26 +89,26 @@ var defaultFetchHandler = function (config, components, addCancelToken) {
74
89
  * которые описывают откуда нужно подтянуть данные.
75
90
  *
76
91
  * В процесс загрузки HOC будет отображать "Загрузка...", а после уже отрендерит компонент, передав данные в указанный
77
- * ключ `key`. Все данные сохраняются в Redux Store, что позволяет избежать дополнительных запросов при использовании
78
- * SSR.
92
+ * ключ `key`.
79
93
  */
80
94
  function useFetch(rawConfig) {
81
95
  var _this = this;
82
96
  if (rawConfig === void 0) { rawConfig = null; }
83
97
  var components = index_1.useComponents();
84
98
  // Store config in state
85
- var _a = react_1.useState(normalizeConfig(rawConfig)), config = _a[0], setConfig = _a[1];
99
+ var _a = react_1.useState(exports.normalizeConfig(rawConfig)), config = _a[0], setConfig = _a[1];
86
100
  // Update config in state on raw config updated
87
101
  react_use_1.useUpdateEffect(function () {
88
102
  setConfig(rawConfig);
89
103
  }, [rawConfig]);
90
- // Resolve config id
91
- // TODO Get initial state from HttpComponent (for SSR) by configId
92
- //const idRef = useRef(_uniqueId('fetch'));
93
- //const configId = config ? _trim(config.id || config.url || idRef.current, '/') : null;
104
+ // Get preloaded data
105
+ var configId = exports.getConfigId(config);
106
+ var ssrValueContext = index_1.useSsr();
107
+ var preloadedData = process.env.IS_SSR ? ssrValueContext.preloadedData : window.APP_PRELOADED_DATA;
108
+ var preloadedDataByConfigId = (preloadedData && configId) ? preloadedData[configId] : null;
94
109
  // State for data and loading flag
95
- var _b = react_1.useState(null), data = _b[0], setData = _b[1];
96
- var _c = react_1.useState(!!config), isLoading = _c[0], setIsLoading = _c[1];
110
+ var _b = react_1.useState(preloadedDataByConfigId || null), data = _b[0], setData = _b[1];
111
+ var _c = react_1.useState(!!config && !data), isLoading = _c[0], setIsLoading = _c[1];
97
112
  // Cancel tokens
98
113
  var cancelTokens = react_1.useRef([]);
99
114
  var addCancelToken = function (token) { return cancelTokens.current.push(token); };
@@ -109,10 +124,11 @@ function useFetch(rawConfig) {
109
124
  if (newConfig) {
110
125
  setConfig(__assign(__assign(__assign({}, config), newConfig), { params: __assign(__assign({}, config === null || config === void 0 ? void 0 : config.params), newConfig === null || newConfig === void 0 ? void 0 : newConfig.params) }));
111
126
  }
127
+ setData(null);
112
128
  if (!config) return [3 /*break*/, 2];
113
129
  setIsLoading(true);
114
130
  _a = setData;
115
- return [4 /*yield*/, (config.onFetch || defaultFetchHandler).call(null, config, components, addCancelToken)];
131
+ return [4 /*yield*/, exports.fetchData(config, components, addCancelToken)];
116
132
  case 1:
117
133
  _a.apply(void 0, [_b.sent()]);
118
134
  setIsLoading(false);
@@ -122,28 +138,15 @@ function useFetch(rawConfig) {
122
138
  });
123
139
  });
124
140
  }, [components, config]);
141
+ react_use_1.useEffectOnce(function () {
142
+ if (!data) {
143
+ fetch();
144
+ }
145
+ });
125
146
  // Fetch data on config update
126
- react_1.useLayoutEffect(function () {
127
- var fetchData = function () { return __awaiter(_this, void 0, void 0, function () {
128
- var _a;
129
- return __generator(this, function (_b) {
130
- switch (_b.label) {
131
- case 0:
132
- setData(null);
133
- if (!config) return [3 /*break*/, 2];
134
- setIsLoading(true);
135
- _a = setData;
136
- return [4 /*yield*/, (config.onFetch || defaultFetchHandler).call(null, config, components, addCancelToken)];
137
- case 1:
138
- _a.apply(void 0, [_b.sent()]);
139
- setIsLoading(false);
140
- _b.label = 2;
141
- case 2: return [2 /*return*/];
142
- }
143
- });
144
- }); };
145
- fetchData();
146
- }, [components, config]);
147
+ react_use_1.useUpdateEffect(function () {
148
+ fetch();
149
+ }, [fetch]);
147
150
  return { data: data, isLoading: isLoading, fetch: fetch };
148
151
  }
149
152
  exports["default"] = useFetch;
@@ -1,3 +1,5 @@
1
+ import { Dispatch } from 'redux';
2
+ import { IComponents } from '../providers/ComponentsProvider';
1
3
  export interface ILayout {
2
4
  status?: string;
3
5
  error?: any;
@@ -9,4 +11,11 @@ export declare const STATUS_RENDER_ERROR = "render_error";
9
11
  export declare const STATUS_HTTP_ERROR = "render_error";
10
12
  export declare const STATUS_ACCESS_DENIED = "access_denied";
11
13
  export declare const STATUS_OK = "ok";
14
+ export declare const HTTP_STATUS_CODES: {
15
+ not_found: number;
16
+ access_denied: number;
17
+ ok: number;
18
+ render_error: number;
19
+ };
20
+ export declare const runInitAction: (initAction: (...args: any[]) => Promise<any>, components: IComponents, dispatch: Dispatch<any>) => Promise<void>;
12
21
  export default function useLayout(initAction?: any): ILayout;
@@ -2,8 +2,9 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
+ var _a;
5
6
  exports.__esModule = true;
6
- exports.STATUS_OK = exports.STATUS_ACCESS_DENIED = exports.STATUS_HTTP_ERROR = exports.STATUS_RENDER_ERROR = exports.STATUS_NOT_FOUND = exports.STATUS_LOADING = void 0;
7
+ exports.runInitAction = exports.HTTP_STATUS_CODES = exports.STATUS_OK = exports.STATUS_ACCESS_DENIED = exports.STATUS_HTTP_ERROR = exports.STATUS_RENDER_ERROR = exports.STATUS_NOT_FOUND = exports.STATUS_LOADING = void 0;
7
8
  var react_1 = require("react");
8
9
  var isFunction_1 = __importDefault(require("lodash-es/isFunction"));
9
10
  var isObject_1 = __importDefault(require("lodash-es/isObject"));
@@ -11,6 +12,7 @@ var upperFirst_1 = __importDefault(require("lodash-es/upperFirst"));
11
12
  var merge_1 = __importDefault(require("lodash-es/merge"));
12
13
  var intersection_1 = __importDefault(require("lodash-es/intersection"));
13
14
  var react_use_1 = require("react-use");
15
+ var useSsr_1 = __importDefault(require("./useSsr"));
14
16
  var useComponents_1 = __importDefault(require("./useComponents"));
15
17
  var router_1 = require("../reducers/router");
16
18
  var auth_1 = require("../reducers/auth");
@@ -25,6 +27,58 @@ exports.STATUS_RENDER_ERROR = 'render_error';
25
27
  exports.STATUS_HTTP_ERROR = 'render_error';
26
28
  exports.STATUS_ACCESS_DENIED = 'access_denied';
27
29
  exports.STATUS_OK = 'ok';
30
+ exports.HTTP_STATUS_CODES = (_a = {},
31
+ _a[exports.STATUS_NOT_FOUND] = 404,
32
+ _a[exports.STATUS_ACCESS_DENIED] = 403,
33
+ _a[exports.STATUS_OK] = 200,
34
+ _a[exports.STATUS_RENDER_ERROR] = 500,
35
+ _a[exports.STATUS_HTTP_ERROR] = 500,
36
+ _a);
37
+ var runInitAction = function (initAction, components, dispatch) { return (initAction(null, dispatch, components)
38
+ .then(function (result) {
39
+ // Configure components
40
+ if (isObject_1["default"](result.config)) {
41
+ Object.keys(result.config).forEach(function (name) {
42
+ if (!components[name]) {
43
+ return;
44
+ }
45
+ Object.keys(result.config[name]).forEach(function (key) {
46
+ var value = result.config[name][key];
47
+ var setter = 'set' + upperFirst_1["default"](key);
48
+ if (isFunction_1["default"](components[name][setter])) {
49
+ components[name][setter](value);
50
+ }
51
+ else if (isObject_1["default"](components[name][key])
52
+ && isObject_1["default"](value)) {
53
+ merge_1["default"](components[name][key], value);
54
+ }
55
+ else {
56
+ components[name][key] = value;
57
+ }
58
+ });
59
+ });
60
+ }
61
+ var resultMeta = result.meta;
62
+ var resultUser = result.user;
63
+ delete result.user;
64
+ delete result.meta;
65
+ if (resultMeta) {
66
+ Object.keys(resultMeta).forEach(function (modelName) {
67
+ if (resultMeta[modelName].attributes) {
68
+ components.meta.setModel(modelName, resultMeta[modelName]);
69
+ }
70
+ });
71
+ }
72
+ dispatch([
73
+ // Meta models & enums
74
+ Boolean(resultMeta) && fields_1.setMeta(resultMeta),
75
+ // User auth
76
+ auth_2.setData(result),
77
+ // User auth
78
+ auth_2.setUser(resultUser),
79
+ ].filter(Boolean));
80
+ })); };
81
+ exports.runInitAction = runInitAction;
28
82
  function useLayout(initAction) {
29
83
  if (initAction === void 0) { initAction = null; }
30
84
  var _a = useSelector_1["default"](function (state) { return ({
@@ -52,50 +106,11 @@ function useLayout(initAction) {
52
106
  if (!isFunction_1["default"](initAction) || initializeCounter <= initializeCounterPrev) {
53
107
  return;
54
108
  }
55
- initAction(null, dispatch)
56
- .then(function (result) {
57
- // Configure components
58
- if (isObject_1["default"](result.config)) {
59
- Object.keys(result.config).forEach(function (name) {
60
- if (!components[name]) {
61
- return;
62
- }
63
- Object.keys(result.config[name]).forEach(function (key) {
64
- var value = result.config[name][key];
65
- var setter = 'set' + upperFirst_1["default"](key);
66
- if (isFunction_1["default"](components[name][setter])) {
67
- components[name][setter](value);
68
- }
69
- else if (isObject_1["default"](components[name][key])
70
- && isObject_1["default"](value)) {
71
- merge_1["default"](components[name][key], value);
72
- }
73
- else {
74
- components[name][key] = value;
75
- }
76
- });
77
- });
109
+ exports.runInitAction(initAction, components, dispatch)
110
+ .then(function () {
111
+ if (redirectPageId) {
112
+ dispatch(router_2.goToRoute(redirectPageId));
78
113
  }
79
- var resultMeta = result.meta;
80
- var resultUser = result.user;
81
- delete result.user;
82
- delete result.meta;
83
- if (resultMeta) {
84
- Object.keys(resultMeta).forEach(function (modelName) {
85
- if (resultMeta[modelName].attributes) {
86
- components.meta.setModel(modelName, resultMeta[modelName]);
87
- }
88
- });
89
- }
90
- dispatch([
91
- // Meta models & enums
92
- Boolean(resultMeta) && fields_1.setMeta(resultMeta),
93
- // User auth
94
- auth_2.setData(result),
95
- // User auth
96
- auth_2.setUser(resultUser),
97
- redirectPageId && router_2.goToRoute(redirectPageId),
98
- ].filter(Boolean));
99
114
  })["catch"](function (e) {
100
115
  setError(e);
101
116
  throw e;
@@ -125,6 +140,11 @@ function useLayout(initAction) {
125
140
  }
126
141
  }
127
142
  }
143
+ //save status code for ssr
144
+ var ssrContextValue = useSsr_1["default"]();
145
+ if (process.env.IS_SSR) {
146
+ ssrContextValue.staticContext.statusCode = exports.HTTP_STATUS_CODES[status];
147
+ }
128
148
  return {
129
149
  status: status,
130
150
  error: error,
@@ -145,6 +145,51 @@ export interface IListOutput {
145
145
  onFetch: (params?: Record<string, unknown>) => void;
146
146
  onSort: (value: any) => void;
147
147
  }
148
+ export declare const defaultConfig: {
149
+ actionMethod: string;
150
+ primaryKey: string;
151
+ autoDestroy: boolean;
152
+ sort: {
153
+ enable: boolean;
154
+ attribute: string;
155
+ defaultValue: any;
156
+ };
157
+ addressBar: {
158
+ enable: boolean;
159
+ useHash: boolean;
160
+ };
161
+ };
162
+ export declare const normalizeSortProps: (props: IListConfig['sort']) => {
163
+ enable: boolean;
164
+ attribute: string;
165
+ defaultValue: any;
166
+ };
167
+ export declare const getDefaultSearchModel: ({ paginationProps, paginationSizeProps, sort, layoutNamesProps, }: {
168
+ paginationProps: any;
169
+ paginationSizeProps: any;
170
+ sort: any;
171
+ layoutNamesProps: any;
172
+ }) => {
173
+ attributes: ({
174
+ type: string;
175
+ attribute: any;
176
+ defaultValue: any;
177
+ jsType?: undefined;
178
+ } | {
179
+ type: string;
180
+ jsType: string;
181
+ attribute: any;
182
+ defaultValue: any;
183
+ })[];
184
+ };
185
+ export declare const createInitialValues: ({ paginationProps, paginationSizeProps, sort, layoutNamesProps, initialQuery, configQuery, }: {
186
+ paginationProps: any;
187
+ paginationSizeProps: any;
188
+ sort: any;
189
+ layoutNamesProps: any;
190
+ initialQuery: any;
191
+ configQuery: any;
192
+ }) => any;
148
193
  /**
149
194
  * useList
150
195
  * Добавляет массу возможностей для взаимодействия с коллекциями. Коллекции можно получать как с бекенда,
package/hooks/useList.js CHANGED
@@ -33,6 +33,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
33
  return (mod && mod.__esModule) ? mod : { "default": mod };
34
34
  };
35
35
  exports.__esModule = true;
36
+ exports.createInitialValues = exports.getDefaultSearchModel = exports.normalizeSortProps = exports.defaultConfig = void 0;
36
37
  var react_1 = require("react");
37
38
  var get_1 = __importDefault(require("lodash-es/get"));
38
39
  var union_1 = __importDefault(require("lodash-es/union"));
@@ -52,8 +53,7 @@ var useInitial_1 = __importDefault(require("../hooks/useInitial"));
52
53
  var Pagination_1 = require("../ui/list/Pagination/Pagination");
53
54
  var PaginationSize_1 = require("../ui/list/PaginationSize/PaginationSize");
54
55
  var Empty_1 = require("../ui/list/Empty/Empty");
55
- var index_1 = require("../hooks/index");
56
- var defaultConfig = {
56
+ exports.defaultConfig = {
57
57
  actionMethod: 'get',
58
58
  primaryKey: 'id',
59
59
  autoDestroy: true,
@@ -67,6 +67,43 @@ var defaultConfig = {
67
67
  useHash: false
68
68
  }
69
69
  };
70
+ var normalizeSortProps = function (props) { return (__assign(__assign(__assign({}, exports.defaultConfig.sort), { enable: !!props }), (typeof props === 'boolean' ? { enable: props } : props))); };
71
+ exports.normalizeSortProps = normalizeSortProps;
72
+ var getDefaultSearchModel = function (_a) {
73
+ var paginationProps = _a.paginationProps, paginationSizeProps = _a.paginationSizeProps, sort = _a.sort, layoutNamesProps = _a.layoutNamesProps;
74
+ return ({
75
+ attributes: [
76
+ paginationProps.enable && {
77
+ type: 'number',
78
+ attribute: paginationProps.attribute,
79
+ defaultValue: paginationProps.defaultValue
80
+ },
81
+ paginationSizeProps.enable && {
82
+ type: 'number',
83
+ attribute: paginationSizeProps.attribute,
84
+ defaultValue: paginationSizeProps.defaultValue
85
+ },
86
+ sort.enable && {
87
+ type: 'string',
88
+ jsType: 'string[]',
89
+ attribute: sort.attribute,
90
+ defaultValue: sort.defaultValue
91
+ },
92
+ layoutNamesProps.enable && {
93
+ type: 'string',
94
+ attribute: layoutNamesProps.attribute,
95
+ defaultValue: layoutNamesProps.defaultValue
96
+ },
97
+ ].filter(Boolean)
98
+ });
99
+ };
100
+ exports.getDefaultSearchModel = getDefaultSearchModel;
101
+ var createInitialValues = function (_a) {
102
+ var _b;
103
+ var paginationProps = _a.paginationProps, paginationSizeProps = _a.paginationSizeProps, sort = _a.sort, layoutNamesProps = _a.layoutNamesProps, initialQuery = _a.initialQuery, configQuery = _a.configQuery;
104
+ return (__assign(__assign((_b = {}, _b[paginationProps.attribute] = paginationProps.defaultValue, _b[paginationSizeProps.attribute] = paginationSizeProps.defaultValue, _b[sort.attribute] = sort.defaultValue, _b[layoutNamesProps.attribute] = layoutNamesProps.defaultValue, _b), initialQuery), configQuery));
105
+ };
106
+ exports.createInitialValues = createInitialValues;
70
107
  /**
71
108
  * useList
72
109
  * Добавляет массу возможностей для взаимодействия с коллекциями. Коллекции можно получать как с бекенда,
@@ -75,11 +112,10 @@ var defaultConfig = {
75
112
  */
76
113
  function useList(config) {
77
114
  var _a, _b;
78
- var components = index_1.useComponents();
79
115
  // Get list from redux state
80
116
  var list = useSelector_1["default"](function (state) { return list_1.getList(state, config.listId); });
81
117
  // Normalize sort config
82
- var sort = react_1.useMemo(function () { return (__assign(__assign(__assign({}, defaultConfig.sort), { enable: !!config.sort }), (typeof config.sort === 'boolean' ? { enable: config.sort } : config.sort))); }, [config.sort]);
118
+ var sort = exports.normalizeSortProps(config.sort);
83
119
  // Empty
84
120
  var Empty = require('../ui/list/Empty')["default"];
85
121
  var emptyProps = Empty_1.normalizeEmptyProps(config.empty);
@@ -107,32 +143,14 @@ function useList(config) {
107
143
  var layoutNamesProps = LayoutNames_1.normalizeLayoutNamesProps(config.layout);
108
144
  var renderLayoutNames = function () { return React.createElement(LayoutNames, __assign({ list: list }, layoutNamesProps)); };
109
145
  // Models
146
+ var defaultSearchModel = react_1.useMemo(function () { return exports.getDefaultSearchModel({
147
+ paginationProps: paginationProps,
148
+ paginationSizeProps: paginationSizeProps,
149
+ sort: sort,
150
+ layoutNamesProps: layoutNamesProps
151
+ }); }, [layoutNamesProps, paginationProps, paginationSizeProps, sort]);
110
152
  var model = useModel_1["default"](config.model);
111
- var searchModel = useModel_1["default"](config.searchModel || ((_a = config.searchForm) === null || _a === void 0 ? void 0 : _a.model), {
112
- attributes: [
113
- paginationProps.enable && {
114
- type: 'number',
115
- attribute: paginationProps.attribute,
116
- defaultValue: paginationProps.defaultValue
117
- },
118
- paginationSizeProps.enable && {
119
- type: 'number',
120
- attribute: paginationSizeProps.attribute,
121
- defaultValue: paginationSizeProps.defaultValue
122
- },
123
- sort.enable && {
124
- type: 'string',
125
- jsType: 'string[]',
126
- attribute: sort.attribute,
127
- defaultValue: sort.defaultValue
128
- },
129
- layoutNamesProps.enable && {
130
- type: 'string',
131
- attribute: layoutNamesProps.attribute,
132
- defaultValue: layoutNamesProps.defaultValue
133
- },
134
- ].filter(Boolean)
135
- });
153
+ var searchModel = useModel_1["default"](config.searchModel || ((_a = config.searchForm) === null || _a === void 0 ? void 0 : _a.model), defaultSearchModel);
136
154
  // Address bar synchronization
137
155
  var _c = useAddressBar_1["default"](__assign({ enable: !!config.addressBar, model: searchModel }, (typeof config.addressBar === 'boolean' ? { enable: config.addressBar } : config.addressBar))), initialQuery = _c.initialQuery, updateQuery = _c.updateQuery;
138
156
  // Outside search form
@@ -149,34 +167,46 @@ function useList(config) {
149
167
  var formId = get_1["default"](config, 'searchForm.formId') || config.listId;
150
168
  var dispatch = useDispatch_1["default"]();
151
169
  // List wrapper (form context)
152
- var initialValues = useInitial_1["default"](function () {
153
- var _a;
154
- return (__assign(__assign((_a = {}, _a[paginationProps.attribute] = paginationProps.defaultValue, _a[paginationSizeProps.attribute] = paginationSizeProps.defaultValue, _a[sort.attribute] = sort.defaultValue, _a[layoutNamesProps.attribute] = layoutNamesProps.defaultValue, _a), initialQuery), config.query));
155
- });
170
+ var _initialValues = react_1.useMemo(function () { return exports.createInitialValues({
171
+ paginationProps: paginationProps,
172
+ paginationSizeProps: paginationSizeProps,
173
+ sort: sort,
174
+ layoutNamesProps: layoutNamesProps,
175
+ initialQuery: initialQuery,
176
+ configQuery: config.query
177
+ }); }, [config.query, initialQuery, layoutNamesProps, paginationProps, paginationSizeProps, sort]);
178
+ var initialValues = useInitial_1["default"](function () { return _initialValues; });
156
179
  var renderList = react_1.useCallback(function (children) {
157
180
  var Form = require('../ui/form/Form')["default"];
158
181
  return (React.createElement(Form, { formId: formId, initialValues: initialValues, view: false, useRedux: true }, children));
159
182
  }, [formId, initialValues]);
160
183
  // Init list in redux store
161
184
  react_use_1.useMount(function () {
162
- dispatch(list_2.listInit(config.listId, {
163
- listId: config.listId,
164
- action: config.action || config.action === '' ? config.action : null,
165
- actionMethod: config.actionMethod || defaultConfig.actionMethod,
166
- onFetch: config.onFetch,
167
- condition: config.condition,
168
- scope: config.scope,
169
- items: null,
170
- sourceItems: config.items || null,
171
- isRemote: !config.items,
172
- primaryKey: config.primaryKey || defaultConfig.primaryKey,
173
- formId: formId,
174
- loadMore: paginationProps.loadMore,
175
- pageAttribute: paginationProps.attribute || null,
176
- pageSizeAttribute: paginationSizeProps.attribute || null,
177
- sortAttribute: sort.attribute || null,
178
- layoutAttribute: layoutNamesProps.attribute || null
179
- }));
185
+ if (!list) {
186
+ var toDispatch = [
187
+ list_2.listInit(config.listId, {
188
+ listId: config.listId,
189
+ action: config.action || config.action === '' ? config.action : null,
190
+ actionMethod: config.actionMethod || exports.defaultConfig.actionMethod,
191
+ onFetch: config.onFetch,
192
+ condition: config.condition,
193
+ scope: config.scope,
194
+ items: null,
195
+ sourceItems: config.items || null,
196
+ isRemote: !config.items,
197
+ primaryKey: config.primaryKey || exports.defaultConfig.primaryKey,
198
+ formId: formId,
199
+ loadMore: paginationProps.loadMore,
200
+ pageAttribute: paginationProps.attribute || null,
201
+ pageSizeAttribute: paginationSizeProps.attribute || null,
202
+ sortAttribute: sort.attribute || null,
203
+ layoutAttribute: layoutNamesProps.attribute || null
204
+ }),
205
+ list_2.listSetItems(config.listId, config.items),
206
+ list_2.listLazyFetch(config.listId),
207
+ ];
208
+ dispatch(toDispatch);
209
+ }
180
210
  });
181
211
  // Check form values change
182
212
  var formValues = useSelector_1["default"](function (state) { return form_2.formSelector(state, formId, function (_a) {
@@ -210,7 +240,7 @@ function useList(config) {
210
240
  });
211
241
  }, [formId, prevQuery, config.query, dispatch]);
212
242
  // Check change items
213
- react_1.useEffect(function () {
243
+ react_use_1.useUpdateEffect(function () {
214
244
  dispatch([
215
245
  list_2.listSetItems(config.listId, config.items),
216
246
  list_2.listLazyFetch(config.listId),
@@ -218,7 +248,7 @@ function useList(config) {
218
248
  }, [dispatch, config.items, config.listId]);
219
249
  // Destroy
220
250
  react_use_1.useUnmount(function () {
221
- var autoDestroy = typeof config.autoDestroy === 'boolean' ? config.autoDestroy : defaultConfig.autoDestroy;
251
+ var autoDestroy = typeof config.autoDestroy === 'boolean' ? config.autoDestroy : exports.defaultConfig.autoDestroy;
222
252
  if (autoDestroy) {
223
253
  dispatch(list_2.listDestroy(config.listId));
224
254
  }
package/hooks/useModel.js CHANGED
@@ -8,6 +8,6 @@ var useComponents_1 = __importDefault(require("./useComponents"));
8
8
  function useModel(model, defaultModel) {
9
9
  if (defaultModel === void 0) { defaultModel = null; }
10
10
  var components = useComponents_1["default"]();
11
- return react_1.useMemo(function () { return components.meta.normalizeModel(components.meta.getModel(model), defaultModel); }, [components.meta, defaultModel, model]);
11
+ return react_1.useMemo(function () { return components.meta.normalizeModel(typeof model === 'string' ? components.meta.getModel(model) : model, defaultModel); }, [components.meta, defaultModel, model]);
12
12
  }
13
13
  exports["default"] = useModel;
@@ -1,2 +1,2 @@
1
- import { IScreen } from './useApplication';
1
+ import { IScreen } from '../providers/ScreenProvider';
2
2
  export default function useScreen(): IScreen;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
3
  var react_1 = require("react");
4
- var useApplication_1 = require("../hooks/useApplication");
4
+ var ScreenProvider_1 = require("../providers/ScreenProvider");
5
5
  function useScreen() {
6
- return react_1.useContext(useApplication_1.ScreenContext);
6
+ return react_1.useContext(ScreenProvider_1.ScreenContext);
7
7
  }
8
8
  exports["default"] = useScreen;
@@ -0,0 +1,2 @@
1
+ import { ISsr } from '../providers/SsrProvider';
2
+ export default function useSsr(): ISsr;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ var react_1 = require("react");
4
+ var SsrProvider_1 = require("../providers/SsrProvider");
5
+ function useSsr() {
6
+ return react_1.useContext(SsrProvider_1.SsrProviderContext) || {};
7
+ }
8
+ exports["default"] = useSsr;
package/index.d.ts CHANGED
@@ -26,7 +26,7 @@ declare function __(phrase: string, params?: any): string;
26
26
  * Название цвета, соответствующее ему состоянию
27
27
  */
28
28
  declare type ColorName =
29
- 'primary'
29
+ | 'primary'
30
30
  | 'secondary'
31
31
  | 'success'
32
32
  | 'info'
@@ -44,7 +44,7 @@ declare type PrimaryKey = number | string;
44
44
  /**
45
45
  * Размер элемента
46
46
  */
47
- declare type Size = 'sm' | 'md' | 'lg' | string;
47
+ declare type Size = 'small' | 'middle' | 'large' | string;
48
48
 
49
49
  /**
50
50
  * Макет формы или ее части, влияющий на расположение полей
@@ -78,6 +78,12 @@ declare type FormInputType = {
78
78
  */
79
79
  declare type CssClassName = string;
80
80
 
81
+ /**
82
+ * Дополнительные стили
83
+ * @example my-block
84
+ */
85
+ declare type CustomStyle = React.CSSProperties;
86
+
81
87
  /**
82
88
  * Переопределение view React компонента для кастомизации отображения
83
89
  * @example MyCustomView