@steroidsjs/core 2.1.0-beta.27 → 2.1.0-beta.31

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 (64) hide show
  1. package/components/SocialComponent.js +10 -8
  2. package/components/social/FacebookProvider.d.ts +1 -1
  3. package/components/social/FacebookProvider.js +5 -6
  4. package/components/social/GitlabProvider.d.ts +1 -1
  5. package/components/social/GitlabProvider.js +5 -5
  6. package/components/social/GoogleProvider.d.ts +1 -1
  7. package/components/social/GoogleProvider.js +2 -2
  8. package/components/social/SteamProvider.d.ts +1 -1
  9. package/components/social/SteamProvider.js +8 -9
  10. package/components/social/VkProvider.d.ts +1 -1
  11. package/components/social/VkProvider.js +8 -9
  12. package/hooks/useDataProvider.d.ts +1 -0
  13. package/hooks/useDataProvider.js +3 -3
  14. package/hooks/useDataSelect.d.ts +3 -3
  15. package/hooks/useDataSelect.js +22 -9
  16. package/hooks/useFetch.js +3 -0
  17. package/hooks/useLayout.js +21 -12
  18. package/hooks/useList.d.ts +4 -0
  19. package/hooks/useList.js +1 -0
  20. package/package.json +1 -1
  21. package/ui/content/Detail/Detail.d.ts +1 -1
  22. package/ui/crud/Crud/Crud.js +4 -2
  23. package/ui/crud/Crud/CrudContent.d.ts +5 -1
  24. package/ui/crud/Crud/CrudContent.js +5 -5
  25. package/ui/crud/index.d.ts +1 -0
  26. package/ui/form/AutoCompleteField/AutoCompleteField.d.ts +1 -6
  27. package/ui/form/BlankField/BlankField.d.ts +1 -6
  28. package/ui/form/CheckboxField/CheckboxField.d.ts +1 -6
  29. package/ui/form/CheckboxListField/CheckboxListField.d.ts +1 -6
  30. package/ui/form/DateField/DateField.d.ts +1 -7
  31. package/ui/form/DateField/useDateTime.js +2 -2
  32. package/ui/form/DateRangeField/DateRangeField.d.ts +1 -7
  33. package/ui/form/DateRangeField/DateRangeField.js +2 -1
  34. package/ui/form/DateTimeField/DateTimeField.d.ts +1 -7
  35. package/ui/form/DateTimeRangeField/DateTimeRangeField.d.ts +1 -7
  36. package/ui/form/DropDownField/DropDownField.d.ts +2 -8
  37. package/ui/form/DropDownField/DropDownField.js +8 -6
  38. package/ui/form/Field/fieldWrapper.d.ts +4 -4
  39. package/ui/form/FieldList/FieldList.d.ts +1 -6
  40. package/ui/form/FileField/FileField.d.ts +1 -6
  41. package/ui/form/Form/Form.js +1 -1
  42. package/ui/form/HtmlField/HtmlField.d.ts +1 -7
  43. package/ui/form/ImageField/ImageField.d.ts +1 -7
  44. package/ui/form/ImageField/ImageField.js +2 -2
  45. package/ui/form/InputField/InputField.d.ts +1 -6
  46. package/ui/form/NavField/NavField.d.ts +2 -8
  47. package/ui/form/NumberField/NumberField.d.ts +1 -6
  48. package/ui/form/PasswordField/PasswordField.d.ts +1 -6
  49. package/ui/form/RadioListField/RadioListField.d.ts +1 -6
  50. package/ui/form/RateField/RateField.d.ts +2 -8
  51. package/ui/form/ReCaptchaField/ReCaptchaField.d.ts +1 -7
  52. package/ui/form/SliderField/SliderField.d.ts +4 -11
  53. package/ui/form/SliderField/demo/marks.js +8 -10
  54. package/ui/form/SwitcherField/SwitcherField.d.ts +1 -7
  55. package/ui/form/TextField/TextField.d.ts +1 -6
  56. package/ui/form/TimeField/TimeField.d.ts +1 -7
  57. package/ui/form/index.d.ts +22 -132
  58. package/ui/format/EnumFormatter/EnumFormatter.js +1 -1
  59. package/ui/list/Grid/Grid.js +2 -1
  60. package/ui/list/Grid/demo/inner-search-form.d.ts +1 -6
  61. package/ui/list/List/List.js +2 -1
  62. package/ui/nav/Router/Router.d.ts +5 -0
  63. package/components/social/index.d.ts +0 -13
  64. package/components/social/index.js +0 -17
@@ -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
- var social_1 = __importDefault(require("./social"));
6
+ var isFunction_1 = __importDefault(require("lodash-es/isFunction"));
7
7
  /**
8
8
  * Social Component
9
9
  * Провайдер для социальных сетей. Обеспечивает вызов окна соц сети для oauth авторизации
@@ -17,11 +17,15 @@ var SocialComponent = /** @class */ (function () {
17
17
  SocialComponent.prototype.init = function () {
18
18
  var _this = this;
19
19
  Object.keys(this.providers).forEach(function (name) {
20
- if (social_1["default"][name]) {
21
- var config = _this.providers[name] || {};
22
- _this.providers[name] = new social_1["default"][name](_this._components);
23
- Object.assign(_this.providers[name], config);
20
+ if (isFunction_1["default"](_this.providers[name])) {
21
+ _this.providers[name] = { className: _this.providers[name] };
24
22
  }
23
+ var ProviderClass = _this.providers[name].className;
24
+ delete _this.providers[name].className;
25
+ if (!ProviderClass) {
26
+ throw new Error('Not found class for social provider: ' + name);
27
+ }
28
+ _this.providers[name] = new ProviderClass(_this._components, _this.providers[name]);
25
29
  });
26
30
  Object.keys(this.providers).forEach(function (name) {
27
31
  _this._initializing[name] = _this.providers[name].init();
@@ -32,9 +36,7 @@ var SocialComponent = /** @class */ (function () {
32
36
  if (!this._initializing[socialName]) {
33
37
  return Promise.reject();
34
38
  }
35
- return this._initializing[socialName].then(function () {
36
- return _this.providers[socialName].start();
37
- });
39
+ return this._initializing[socialName].then(function () { return _this.providers[socialName].start(); });
38
40
  };
39
41
  return SocialComponent;
40
42
  }());
@@ -2,7 +2,7 @@ export default class FacebookProvider {
2
2
  _components: any;
3
3
  clientId: string;
4
4
  language: string;
5
- constructor(components: any);
5
+ constructor(components: any, config: any);
6
6
  init(): Promise<any>;
7
7
  start(): Promise<unknown>;
8
8
  }
@@ -37,13 +37,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  exports.__esModule = true;
39
39
  var FacebookProvider = /** @class */ (function () {
40
- function FacebookProvider(components) {
40
+ function FacebookProvider(components, config) {
41
41
  this._components = components;
42
- this.clientId = '';
43
- this.language =
44
- this._components.locale.language +
45
- '_' +
46
- this._components.locale.language.toUpperCase();
42
+ this.clientId = config.clientId || '';
43
+ this.language = this._components.locale.language
44
+ + '_'
45
+ + this._components.locale.language.toUpperCase();
47
46
  }
48
47
  FacebookProvider.prototype.init = function () {
49
48
  return __awaiter(this, void 0, void 0, function () {
@@ -2,7 +2,7 @@ export default class GitlabProvider {
2
2
  _components: any;
3
3
  url: string;
4
4
  redirectUrl: any;
5
- constructor(components: any);
5
+ constructor(components: any, config: any);
6
6
  init(): Promise<void>;
7
7
  start(): Promise<unknown>;
8
8
  }
@@ -37,10 +37,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  exports.__esModule = true;
39
39
  var GitlabProvider = /** @class */ (function () {
40
- function GitlabProvider(components) {
40
+ function GitlabProvider(components, config) {
41
41
  this._components = components;
42
- this.url = '';
43
- this.redirectUrl = this._components.http.getUrl('/api/v1/auth/social/proxy');
42
+ this.url = config.url || '';
43
+ this.redirectUrl = config.redirectUrl || this._components.http.getUrl('/api/v1/auth/social/proxy');
44
44
  }
45
45
  GitlabProvider.prototype.init = function () {
46
46
  return __awaiter(this, void 0, void 0, function () {
@@ -78,9 +78,9 @@ var GitlabProvider = /** @class */ (function () {
78
78
  .join(','));
79
79
  popup.onbeforeunload = function () { return reject(); };
80
80
  // This is a handler which is used by child window to pass auth result
81
- // @ts-ignore
82
81
  window.authCallback = function (link) {
83
- // link: http://127.0.0.1:9424/api/v1/auth/social/proxy?provider=gitlab_kozhindev#access_token=7b87e3de0000000111111122222223333333d1b4ff3ee3f040085518198d885d&token_type=Bearer
82
+ // link: http://127.0.0.1:9424/api/v1/auth/social/proxy
83
+ // ?provider=gitlab_kozhindev#access_token=7b87e3de0...5518198d885d&token_type=Bearer
84
84
  var token = (/access_token=(\w+)/.exec(link) || [])[1];
85
85
  if (token) {
86
86
  resolve({ token: token });
@@ -1,7 +1,7 @@
1
1
  export default class GoogleProvider {
2
2
  _components: any;
3
3
  clientId: string;
4
- constructor(components: any);
4
+ constructor(components: any, config: any);
5
5
  init(): Promise<any>;
6
6
  start(): Promise<{
7
7
  token: any;
@@ -37,9 +37,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  exports.__esModule = true;
39
39
  var GoogleProvider = /** @class */ (function () {
40
- function GoogleProvider(components) {
40
+ function GoogleProvider(components, config) {
41
41
  this._components = components;
42
- this.clientId = '';
42
+ this.clientId = config.clientId;
43
43
  }
44
44
  GoogleProvider.prototype.init = function () {
45
45
  return __awaiter(this, void 0, void 0, function () {
@@ -1,7 +1,7 @@
1
1
  export default class Vk {
2
2
  _components: any;
3
3
  clientId: string;
4
- constructor(components: any);
4
+ constructor(components: any, config: any);
5
5
  init(): Promise<void>;
6
6
  start(): Promise<unknown>;
7
7
  }
@@ -57,9 +57,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
57
57
  exports.__esModule = true;
58
58
  var queryString = __importStar(require("qs"));
59
59
  var Vk = /** @class */ (function () {
60
- function Vk(components) {
60
+ function Vk(components, config) {
61
61
  this._components = components;
62
- this.clientId = '';
62
+ this.clientId = config.clientId;
63
63
  }
64
64
  Vk.prototype.init = function () {
65
65
  return __awaiter(this, void 0, void 0, function () {
@@ -74,14 +74,14 @@ var Vk = /** @class */ (function () {
74
74
  return __generator(this, function (_a) {
75
75
  return [2 /*return*/, new Promise(function (resolve, reject) {
76
76
  // Generate url
77
- var url = 'https://steamcommunity.com/openid/login?' +
78
- queryString.stringify({
77
+ var url = 'https://steamcommunity.com/openid/login?'
78
+ + queryString.stringify({
79
79
  'openid.mode': 'checkid_setup',
80
80
  'openid.ns': 'http://specs.openid.net/auth/2.0',
81
81
  'openid.identity': 'http://specs.openid.net/auth/2.0/identifier_select',
82
82
  'openid.claimed_id': 'http://specs.openid.net/auth/2.0/identifier_select',
83
83
  'openid.return_to': _this._components.http.getUrl('/api/v1/auth/social/proxy'),
84
- 'openid.realm': location.origin
84
+ 'openid.realm': window.location.origin
85
85
  });
86
86
  // Open popup auth window
87
87
  var width = 900;
@@ -107,14 +107,13 @@ var Vk = /** @class */ (function () {
107
107
  .join(','));
108
108
  popup.onbeforeunload = function () { return reject(); };
109
109
  // This is a handler which is used by child window to pass auth result
110
- // @ts-ignore
111
110
  window.authCallback = function (link) {
112
- var params = queryString.parse(new URL(link).search);
113
- if (!params['openid.mode']) {
111
+ var query = queryString.parse(new URL(link).search);
112
+ if (!query['openid.mode']) {
114
113
  reject();
115
114
  }
116
115
  else {
117
- resolve(params);
116
+ resolve(query);
118
117
  }
119
118
  };
120
119
  })];
@@ -2,7 +2,7 @@ export default class VkProvider {
2
2
  _components: any;
3
3
  clientId: string;
4
4
  redirectUrl: any;
5
- constructor(components: any);
5
+ constructor(components: any, config: any);
6
6
  init(): Promise<void>;
7
7
  start(): Promise<unknown>;
8
8
  }
@@ -57,10 +57,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
57
57
  exports.__esModule = true;
58
58
  var queryString = __importStar(require("qs"));
59
59
  var VkProvider = /** @class */ (function () {
60
- function VkProvider(components) {
60
+ function VkProvider(components, config) {
61
61
  this._components = components;
62
- this.clientId = '';
63
- this.redirectUrl = this._components.http.getUrl('/api/v1/auth/social/proxy');
62
+ this.clientId = config.clientId;
63
+ this.redirectUrl = config.redirectUrl || this._components.http.getUrl('/api/v1/auth/social/proxy');
64
64
  }
65
65
  VkProvider.prototype.init = function () {
66
66
  return __awaiter(this, void 0, void 0, function () {
@@ -75,8 +75,8 @@ var VkProvider = /** @class */ (function () {
75
75
  return __generator(this, function (_a) {
76
76
  return [2 /*return*/, new Promise(function (resolve, reject) {
77
77
  // Generate url
78
- var url = 'https://oauth.vk.com/authorize/?' +
79
- queryString.stringify({
78
+ var url = 'https://oauth.vk.com/authorize/?'
79
+ + queryString.stringify({
80
80
  client_id: _this.clientId,
81
81
  redirect_uri: _this.redirectUrl,
82
82
  scope: 'offline,public_profile',
@@ -106,16 +106,15 @@ var VkProvider = /** @class */ (function () {
106
106
  .join(','));
107
107
  popup.onbeforeunload = function () { return reject(); };
108
108
  // This is a handler which is used by child window to pass auth result
109
- // @ts-ignore
110
109
  window.authCallback = function (link) {
111
- var params = new URL(link).searchParams;
112
- var error = params.get('error');
110
+ var query = new URL(link).searchParams;
111
+ var error = query.get('error');
113
112
  if (error) {
114
113
  reject(error);
115
114
  }
116
115
  else {
117
116
  resolve({
118
- token: params.get('code')
117
+ token: query.get('code')
119
118
  });
120
119
  }
121
120
  };
@@ -22,6 +22,7 @@ export declare type DataProviderItems = string | ({
22
22
  }) | (string | number | {
23
23
  id: string | number | boolean;
24
24
  label: string | any;
25
+ [key: string]: any;
25
26
  })[];
26
27
  export interface IDataProviderConfig {
27
28
  /**
@@ -54,11 +54,11 @@ var react_redux_1 = require("react-redux");
54
54
  var isString_1 = __importDefault(require("lodash-es/isString"));
55
55
  var isFunction_1 = __importDefault(require("lodash-es/isFunction"));
56
56
  var react_1 = require("react");
57
+ var react_use_1 = require("react-use");
57
58
  var data_1 = require("../utils/data");
58
59
  var index_1 = require("./index");
59
60
  var fields_1 = require("../reducers/fields");
60
61
  var text_1 = require("../utils/text");
61
- var react_use_1 = require("react-use");
62
62
  var defaultProps = {
63
63
  autoComplete: {
64
64
  enable: false,
@@ -137,8 +137,8 @@ function useDataProvider(config) {
137
137
  delayTimerRef.current = setTimeout(fetchRemote, autoComplete.delay);
138
138
  }
139
139
  }
140
- }, [autoComplete, components.api, components.http, config.autoFetch, config.dataProvider, config.query,
141
- dataProvider, dataProvider.action, dataProvider.onSearch, sourceItems]);
140
+ }, [autoComplete, components.api, components.http, config.autoFetch, config.dataProvider,
141
+ config.query, dataProvider, dataProvider.action, dataProvider.onSearch, prevQuery, sourceItems]);
142
142
  return {
143
143
  sourceItems: sourceItems,
144
144
  items: items,
@@ -13,7 +13,7 @@ export interface IDataSelectConfig {
13
13
  * Список с видимыми элементами
14
14
  * @example [{id: 1, label: 'Krasnoyarsk'}, {id: 2, label: 'Moscow'}]
15
15
  */
16
- items: IDataSelectItem[];
16
+ items?: IDataSelectItem[];
17
17
  /**
18
18
  * Сделать активным первый элемент в списке
19
19
  * @example true
@@ -23,7 +23,7 @@ export interface IDataSelectConfig {
23
23
  * Список с идентификаторами выбранных элементов
24
24
  * @example [1, 4]
25
25
  */
26
- selectedIds: any;
26
+ selectedIds?: any;
27
27
  /**
28
28
  * Первичный ключ для item
29
29
  * @example id
@@ -32,7 +32,7 @@ export interface IDataSelectConfig {
32
32
  /**
33
33
  * Значение поля в форме
34
34
  */
35
- inputValue: any;
35
+ inputValue?: any;
36
36
  /**
37
37
  * Список со всеми элементами
38
38
  */
@@ -34,7 +34,9 @@ function useDataSelect(config) {
34
34
  }, [config.items, config.selectFirst, config.selectedIds, primaryKey, config.inputValue]);
35
35
  var initialSelectedItems = react_1.useMemo(function () { return config.items.length > 0
36
36
  && initialSelectedIds.length > 0
37
- ? initialSelectedIds.map(function (selectedId) { return config.items.find(function (item) { return item.id === selectedId; }); })
37
+ ? initialSelectedIds
38
+ .map(function (selectedId) { return config.items.find(function (item) { return item.id === selectedId; }); })
39
+ .filter(Boolean)
38
40
  : []; }, [initialSelectedIds, config.items]);
39
41
  // State
40
42
  var _a = react_1.useState(false), isOpened = _a[0], setIsOpened = _a[1];
@@ -49,7 +51,7 @@ function useDataSelect(config) {
49
51
  if (!config.multiple && ids.length > 1) {
50
52
  ids = [ids[0]];
51
53
  }
52
- setSelectedIdsInternal(ids);
54
+ setSelectedIdsInternal(ids.sort());
53
55
  }
54
56
  else {
55
57
  var id_1 = ids;
@@ -59,11 +61,11 @@ function useDataSelect(config) {
59
61
  else if (config.multiple) {
60
62
  if (selectedIds.indexOf(id_1) !== -1) {
61
63
  if (!skipToggle) {
62
- setSelectedIdsInternal(selectedIds.filter(function (itemValue) { return itemValue !== id_1; }));
64
+ setSelectedIdsInternal(selectedIds.filter(function (itemValue) { return itemValue !== id_1; }).sort());
63
65
  }
64
66
  }
65
67
  else {
66
- setSelectedIdsInternal(__spreadArray(__spreadArray([], selectedIds), [id_1]));
68
+ setSelectedIdsInternal(__spreadArray(__spreadArray([], selectedIds), [id_1]).sort());
67
69
  }
68
70
  }
69
71
  else {
@@ -81,7 +83,7 @@ function useDataSelect(config) {
81
83
  var hasChanges = false;
82
84
  selectedIds.forEach(function (selectedId) {
83
85
  var finedItem = config.items.find(function (item) { return item[primaryKey] === selectedId; });
84
- if (!finedItem) {
86
+ if (!finedItem && config.sourceItems) {
85
87
  finedItem = config.sourceItems.find(function (item) { return item[primaryKey] === selectedId; });
86
88
  }
87
89
  var selectedItem = selectedItems.find(function (item) { return item[primaryKey] === selectedId; });
@@ -117,16 +119,19 @@ function useDataSelect(config) {
117
119
  newSelectedIds.push(selectedItem.id);
118
120
  }
119
121
  });
120
- if (!isEqual_1["default"](prevConfigSelectedIds, newSelectedIds) && newSelectedIds.length !== 0) {
122
+ if (!isEqual_1["default"](prevConfigSelectedIds.sort(), newSelectedIds.sort())
123
+ && !isEqual_1["default"](selectedIds.sort(), newSelectedIds.sort()) && newSelectedIds.length !== 0) {
121
124
  setSelectedIdsInternal(newSelectedIds);
122
125
  }
123
- }, [config.items, config.selectedIds, primaryKey, prevConfigSelectedIds, selectedItems, config.sourceItems]);
126
+ }, [config.items, config.selectedIds, primaryKey, prevConfigSelectedIds,
127
+ selectedItems, config.sourceItems, selectedIds]);
124
128
  // Global key down handler for navigate on items
125
129
  // Support keys:
126
130
  // - tab
127
131
  // - esc
128
132
  // - enter
129
133
  // - up/down arrows
134
+ // - space
130
135
  var onKeyDown = react_1.useCallback(function (e) {
131
136
  // Skip no active
132
137
  if (!isFocused && !isOpened) {
@@ -136,9 +141,8 @@ function useDataSelect(config) {
136
141
  if ([9, 27].includes(e.which)) {
137
142
  e.preventDefault();
138
143
  setIsOpened(false);
139
- return;
140
144
  }
141
- // Keys: enter
145
+ // Keys: enter (select and close)
142
146
  if (e.which === 13 && isOpened) {
143
147
  e.preventDefault();
144
148
  if (hoveredId) {
@@ -153,6 +157,15 @@ function useDataSelect(config) {
153
157
  // Select first result
154
158
  setSelectedIds(config.items[0], true);
155
159
  }
160
+ setIsOpened(false);
161
+ }
162
+ // Keys: space (toggle select)
163
+ if (e.which === 32 && isOpened) {
164
+ e.preventDefault();
165
+ if (hoveredId) {
166
+ // Select hovered
167
+ setSelectedIds(hoveredId);
168
+ }
156
169
  }
157
170
  // Keys: arrow up, arrow down
158
171
  if ([38, 40].includes(e.which)) {
package/hooks/useFetch.js CHANGED
@@ -60,6 +60,9 @@ var normalizeConfig = function (config) { return (config
60
60
  ? __assign({ id: null, url: '', method: 'get', params: {}, options: null, onFetch: null }, config) : null); };
61
61
  exports.normalizeConfig = normalizeConfig;
62
62
  var getConfigId = function (config) {
63
+ if (config === null) {
64
+ return null;
65
+ }
63
66
  var result = trim_1["default"](config.id || config.url, '/');
64
67
  if (!result) {
65
68
  // eslint-disable-next-line no-console
@@ -81,14 +81,18 @@ var runInitAction = function (initAction, components, dispatch) { return (initAc
81
81
  exports.runInitAction = runInitAction;
82
82
  function useLayout(initAction) {
83
83
  if (initAction === void 0) { initAction = null; }
84
- var _a = useSelector_1["default"](function (state) { return ({
85
- route: router_1.getRoute(state),
86
- user: auth_1.getUser(state),
87
- data: auth_1.getData(state),
88
- isInitialized: auth_1.isInitialized(state),
89
- initializeCounter: auth_1.getInitializeCounter(state),
90
- redirectPageId: state.auth.redirectPageId
91
- }); }), route = _a.route, user = _a.user, data = _a.data, isInitialized = _a.isInitialized, initializeCounter = _a.initializeCounter, redirectPageId = _a.redirectPageId;
84
+ var _a = useSelector_1["default"](function (state) {
85
+ var routesMap = router_1.getRoutesMap(state);
86
+ return {
87
+ route: router_1.getRoute(state),
88
+ user: auth_1.getUser(state),
89
+ data: auth_1.getData(state),
90
+ isInitialized: auth_1.isInitialized(state),
91
+ initializeCounter: auth_1.getInitializeCounter(state),
92
+ redirectPageId: state.auth.redirectPageId,
93
+ loginRouteId: Object.keys(routesMap).find(function (name) { return routesMap[name].role === 'login'; })
94
+ };
95
+ }), route = _a.route, user = _a.user, data = _a.data, isInitialized = _a.isInitialized, initializeCounter = _a.initializeCounter, redirectPageId = _a.redirectPageId, loginRouteId = _a.loginRouteId;
92
96
  var _b = react_1.useState(null), error = _b[0], setError = _b[1];
93
97
  var dispatch = useDispatch_1["default"]();
94
98
  var components = useComponents_1["default"]();
@@ -133,10 +137,15 @@ function useLayout(initAction) {
133
137
  userRoles.push(null); // Guest
134
138
  }
135
139
  if (intersection_1["default"](pageRoles, userRoles).length === 0) {
136
- status = exports.STATUS_ACCESS_DENIED;
137
- if (process.env.NODE_ENV !== 'production') {
138
- // eslint-disable-next-line no-console
139
- console.log('Access denied. Page roles: ', pageRoles, 'User roles:', userRoles.join(), 'Route:', route);
140
+ if (loginRouteId && route.id !== loginRouteId) {
141
+ dispatch(router_2.goToRoute(loginRouteId));
142
+ }
143
+ else {
144
+ status = exports.STATUS_ACCESS_DENIED;
145
+ if (process.env.NODE_ENV !== 'production') {
146
+ // eslint-disable-next-line no-console
147
+ console.log('Access denied. Page roles: ', pageRoles, 'User roles:', userRoles.join(), 'Route:', route);
148
+ }
140
149
  }
141
150
  }
142
151
  }
@@ -134,6 +134,10 @@ export interface IListConfig {
134
134
  * и последующие запросы на бекенд для 2-й и следующих страниц
135
135
  */
136
136
  initialItems?: Array<any>;
137
+ /**
138
+ * Количество элементов всего в списке (для отрисовки пагинации), заданное вручную
139
+ */
140
+ initialTotal?: number;
137
141
  }
138
142
  export interface IListOutput {
139
143
  list: IList;
package/hooks/useList.js CHANGED
@@ -193,6 +193,7 @@ function useList(config) {
193
193
  scope: config.scope,
194
194
  items: null,
195
195
  sourceItems: config.items || null,
196
+ total: config.initialTotal,
196
197
  isRemote: !config.items,
197
198
  primaryKey: config.primaryKey || exports.defaultConfig.primaryKey,
198
199
  formId: formId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steroidsjs/core",
3
- "version": "2.1.0-beta.27",
3
+ "version": "2.1.0-beta.31",
4
4
  "description": "",
5
5
  "author": "Vladimir Kozhin <hello@kozhindev.com>",
6
6
  "repository": {
@@ -74,7 +74,7 @@ export interface IDetailProps {
74
74
  /**
75
75
  * Дочерние компоненты
76
76
  */
77
- children: React.ReactNode | React.ReactNode[];
77
+ children?: React.ReactNode | React.ReactNode[];
78
78
  [key: string]: any;
79
79
  }
80
80
  export interface IDetailItemOutputProps extends IDetailItemProps {
@@ -150,13 +150,15 @@ function Crud(props) {
150
150
  model: props.model,
151
151
  restUrl: props.restUrl,
152
152
  restApi: props.restApi,
153
+ grid: props.grid,
154
+ form: props.form,
153
155
  goToAction: goToAction,
154
156
  items: items,
155
157
  itemsToControls: itemsToControls,
156
158
  record: record,
157
159
  recordId: recordId
158
- }); }, [crudId, goToAction, items, itemsToControls, props.model, props.primaryKey,
159
- props.queryKey, props.restUrl, props.restApi, record, recordId]);
160
+ }); }, [crudId, props.queryKey, props.primaryKey, props.model, props.restUrl, props.restApi, props.grid,
161
+ props.form, goToAction, items, itemsToControls, record, recordId]);
160
162
  // Open modal on route change
161
163
  react_1.useEffect(function () {
162
164
  if (mode === MODE_MODAL && routeAction !== utils_1.CRUD_ACTION_INDEX) {
@@ -1,4 +1,6 @@
1
- /// <reference types="react" />
1
+ import * as React from 'react';
2
+ import { IGridProps } from '@steroidsjs/core/ui/list/Grid/Grid';
3
+ import { IFormProps } from '@steroidsjs/core/ui/form/Form/Form';
2
4
  import { ICrudItem } from './Crud';
3
5
  import { IApiRest } from '../../../components/ApiComponent';
4
6
  export interface ICrudContentProps {
@@ -14,5 +16,7 @@ export interface ICrudContentProps {
14
16
  record?: Record<string, unknown>;
15
17
  recordId?: PrimaryKey;
16
18
  action?: string;
19
+ grid?: IGridProps | React.ReactNode;
20
+ form?: IFormProps | React.ReactNode;
17
21
  }
18
22
  export default function CrudContent(props: ICrudContentProps): JSX.Element;
@@ -68,23 +68,23 @@ function CrudContent(props) {
68
68
  ItemComponent = Grid_1["default"];
69
69
  }
70
70
  return (React.createElement(ItemComponent // Grid
71
- , { key: props.crudId, listId: props.crudId, action: props.restApi ? props.restApi.index : props.restUrl, scope: ['model', 'permission'], primaryKey: props.primaryKey, model: props.model,
71
+ , __assign({ key: props.crudId, listId: props.crudId, action: props.restApi ? props.restApi.index : props.restUrl, scope: ['model', 'permission'], primaryKey: props.primaryKey, model: props.model,
72
72
  //searchModel={props.searchModel}
73
73
  controls: controlsGetter, columns: [props.primaryKey], pagination: {
74
74
  loadMore: false
75
- } }));
75
+ } }, props.grid)));
76
76
  case utils_1.CRUD_ACTION_CREATE:
77
77
  case utils_1.CRUD_ACTION_UPDATE:
78
78
  if (!ItemComponent) {
79
79
  ItemComponent = Form_1["default"];
80
80
  }
81
- if (props.action === utils_1.CRUD_ACTION_UPDATE && !props.record) {
81
+ if (props.action === utils_1.CRUD_ACTION_UPDATE && (props.restUrl || props.restApi) && !props.record) {
82
82
  return null;
83
83
  }
84
84
  return (React.createElement(ItemComponent // Form
85
- , { key: formId, formId: formId, action: props.restApi
85
+ , __assign({ key: formId, formId: formId, action: props.restApi
86
86
  ? (props.recordId ? props.restApi.update : props.restApi.create)
87
- : [props.restUrl, props.recordId].filter(Boolean).join('/'), model: props.model, autoFocus: true, submitLabel: props.recordId ? __('Сохранить') : __('Добавить'), layout: 'horizontal', onComplete: onFormComplete, initialValues: formInitialValues }));
87
+ : [props.restUrl, props.recordId].filter(Boolean).join('/'), model: props.model, autoFocus: true, submitLabel: props.recordId ? __('Сохранить') : __('Добавить'), layout: 'horizontal', onComplete: onFormComplete }, props.form, { initialValues: formInitialValues })));
88
88
  default:
89
89
  if (ItemComponent) {
90
90
  return (React.createElement(ItemComponent, __assign({ key: props.crudId + '_' + props.action }, props, crudItem.componentProps)));
@@ -26,6 +26,7 @@ export declare const generateCrud: (routeId: string, props: ICrudGeneratorProps)
26
26
  isNavVisible?: boolean;
27
27
  models: string | string[];
28
28
  enums: string | string[];
29
+ role?: string;
29
30
  roles?: string[];
30
31
  fetch?: import("../../hoc/fetch").IFetchHocConfigFunc;
31
32
  items?: IRouteItem[] | {
@@ -35,10 +35,5 @@ export interface IAutoCompleteFieldViewProps extends Omit<IAutoCompleteFieldProp
35
35
  onItemSelect: (id: PrimaryKey | any) => void;
36
36
  onItemHover: (id: PrimaryKey | any) => void;
37
37
  }
38
- declare const _default: {
39
- (props: import("../../../ui/form/Field/fieldWrapper").IFieldWrapperInputProps): JSX.Element;
40
- WrappedComponent: any;
41
- displayName: any;
42
- defaultProps: any;
43
- };
38
+ declare const _default: import("../../../ui/form/Field/fieldWrapper").FieldWrapperComponent<IAutoCompleteFieldProps>;
44
39
  export default _default;
@@ -4,10 +4,5 @@ export interface IBlankFieldProps extends IFieldWrapperInputProps {
4
4
  text?: string | React.ReactNode;
5
5
  children?: React.ReactNode;
6
6
  }
7
- declare const _default: {
8
- (props: IFieldWrapperInputProps): JSX.Element;
9
- WrappedComponent: any;
10
- displayName: any;
11
- defaultProps: any;
12
- };
7
+ declare const _default: import("../Field/fieldWrapper").FieldWrapperComponent<IBlankFieldProps>;
13
8
  export default _default;
@@ -30,10 +30,5 @@ export interface ICheckboxFieldViewProps extends ICheckboxFieldProps, IFieldWrap
30
30
  disabled: boolean;
31
31
  };
32
32
  }
33
- declare const _default: {
34
- (props: IFieldWrapperInputProps): JSX.Element;
35
- WrappedComponent: any;
36
- displayName: any;
37
- defaultProps: any;
38
- };
33
+ declare const _default: import("../Field/fieldWrapper").FieldWrapperComponent<ICheckboxFieldProps>;
39
34
  export default _default;
@@ -40,10 +40,5 @@ export interface ICheckboxListFieldViewProps extends IFieldWrapperOutputProps {
40
40
  onItemSelect: (id: PrimaryKey | any) => void;
41
41
  onItemHover: (id: PrimaryKey | any) => void;
42
42
  }
43
- declare const _default: {
44
- (props: IFieldWrapperInputProps): JSX.Element;
45
- WrappedComponent: any;
46
- displayName: any;
47
- defaultProps: any;
48
- };
43
+ declare const _default: import("../../../ui/form/Field/fieldWrapper").FieldWrapperComponent<ICheckboxListFieldProps>;
49
44
  export default _default;