@steroidsjs/core 2.1.0-beta.7 → 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.
Files changed (62) 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/useDataProvider.js +4 -2
  21. package/hooks/useDataSelect.d.ts +12 -6
  22. package/hooks/useDataSelect.js +2 -2
  23. package/hooks/useFetch.d.ts +11 -3
  24. package/hooks/useFetch.js +35 -31
  25. package/hooks/useLayout.d.ts +9 -0
  26. package/hooks/useLayout.js +64 -44
  27. package/hooks/useList.d.ts +45 -0
  28. package/hooks/useList.js +83 -53
  29. package/hooks/useModel.js +1 -1
  30. package/hooks/useScreen.d.ts +1 -1
  31. package/hooks/useScreen.js +2 -2
  32. package/hooks/useSsr.d.ts +2 -0
  33. package/hooks/useSsr.js +8 -0
  34. package/package.json +5 -3
  35. package/providers/ComponentsProvider.d.ts +26 -0
  36. package/providers/ComponentsProvider.js +28 -0
  37. package/providers/ScreenProvider.d.ts +20 -0
  38. package/providers/ScreenProvider.js +87 -0
  39. package/providers/SsrProvider.d.ts +17 -0
  40. package/providers/SsrProvider.js +32 -0
  41. package/providers/index.d.ts +4 -0
  42. package/providers/index.js +12 -0
  43. package/reducers/form.d.ts +1 -1
  44. package/reducers/form.js +1 -1
  45. package/reducers/list.js +1 -3
  46. package/reducers/router.js +1 -1
  47. package/ui/crud/Crud/Crud.d.ts +1 -1
  48. package/ui/crud/index.d.ts +1 -0
  49. package/ui/form/DropDownField/DropDownField.js +2 -1
  50. package/ui/form/TextField/TextField.d.ts +2 -1
  51. package/ui/form/TextField/TextField.js +1 -1
  52. package/ui/icon/Icon/Icon.js +3 -0
  53. package/ui/layout/Meta/Meta.d.ts +56 -0
  54. package/ui/layout/Meta/Meta.js +36 -0
  55. package/ui/layout/Meta/index.d.ts +2 -0
  56. package/ui/layout/Meta/index.js +7 -0
  57. package/ui/layout/Notifications/Notifications.js +1 -1
  58. package/ui/layout/Portal.js +3 -0
  59. package/ui/nav/Router/Router.d.ts +13 -0
  60. package/ui/nav/Router/Router.js +1 -1
  61. package/ui/nav/Router/SsrProvider.d.ts +0 -15
  62. package/ui/nav/Router/SsrProvider.js +0 -55
@@ -0,0 +1,56 @@
1
+ import { BaseHTMLAttributes, LinkHTMLAttributes, MetaHTMLAttributes, PropsWithChildren, ScriptHTMLAttributes, StyleHTMLAttributes } from 'react';
2
+ interface IInnerHTML {
3
+ /**
4
+ * Содержимое тега
5
+ */
6
+ innerHtml?: string;
7
+ }
8
+ interface IScript extends ScriptHTMLAttributes<any>, IInnerHTML {
9
+ }
10
+ interface IStyle extends StyleHTMLAttributes<any>, IInnerHTML {
11
+ }
12
+ /**
13
+ * Meta
14
+ * Компонент используется для ssr и нужен для конфигурации html-тегов в документе.
15
+ */
16
+ interface IMetaProps extends PropsWithChildren<any> {
17
+ /**
18
+ * Заголовок документа
19
+ * @example Home page
20
+ */
21
+ title?: string;
22
+ /**
23
+ * Описание документа
24
+ * @example The main page of the site
25
+ */
26
+ description?: string;
27
+ /**
28
+ * Скрипты, которые необходимо разместить на сайте
29
+ * @example [{src: '/lib/SomeLibrary.min.js'}]
30
+ */
31
+ scripts?: IScript[];
32
+ /**
33
+ * Мета-теги
34
+ * @example [{name: 'yandex-verification', content: 'ce...9e6'}]
35
+ */
36
+ meta?: MetaHTMLAttributes<any>[];
37
+ /**
38
+ * Ссылки на ресурсы
39
+ * @example [{href: '/lib/SomeLibrary.css', rel: 'stylesheet', type: 'text/css'}]
40
+ */
41
+ links?: LinkHTMLAttributes<any>[];
42
+ /**
43
+ * Контент для тегов \<style\>
44
+ */
45
+ styles?: IStyle[];
46
+ /**
47
+ * Контент для тегов \<noscript\>
48
+ */
49
+ noScripts?: IInnerHTML[];
50
+ /**
51
+ * Конфигурация тега \<base\>
52
+ */
53
+ base?: BaseHTMLAttributes<any>;
54
+ }
55
+ declare function Meta(props: IMetaProps): JSX.Element;
56
+ export default Meta;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ exports.__esModule = true;
17
+ var react_1 = __importDefault(require("react"));
18
+ var react_helmet_1 = __importDefault(require("react-helmet"));
19
+ function Meta(props) {
20
+ var _a, _b, _c, _d, _e;
21
+ return (react_1["default"].createElement(react_helmet_1["default"], null,
22
+ react_1["default"].createElement("title", null, props.title),
23
+ props.base && react_1["default"].createElement("base", __assign({}, props.base)),
24
+ props.description && react_1["default"].createElement("meta", { name: 'description', content: props.description }), (_a = props.meta) === null || _a === void 0 ? void 0 :
25
+ _a.map(function (attrs, index) { return react_1["default"].createElement("meta", __assign({ key: index }, attrs)); }), (_b = props.links) === null || _b === void 0 ? void 0 :
26
+ _b.map(function (attrs, index) { return react_1["default"].createElement("link", __assign({ key: index }, attrs)); }), (_c = props.styles) === null || _c === void 0 ? void 0 :
27
+ _c.map(function (attrs, index) { return (react_1["default"].createElement("style", __assign({ key: index }, attrs, { dangerouslySetInnerHTML: {
28
+ __html: attrs.innerHtml
29
+ } }))); }), (_d = props.scripts) === null || _d === void 0 ? void 0 :
30
+ _d.map(function (attrs, index) { return (react_1["default"].createElement("script", __assign({ key: index }, attrs), attrs.innerHtml || '')); }), (_e = props.noScripts) === null || _e === void 0 ? void 0 :
31
+ _e.map(function (attrs, index) { return (react_1["default"].createElement("noscript", { key: index, dangerouslySetInnerHTML: {
32
+ __html: attrs.innerHtml
33
+ } })); }),
34
+ props.children));
35
+ }
36
+ exports["default"] = Meta;
@@ -0,0 +1,2 @@
1
+ import Meta from './Meta';
2
+ export default Meta;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ exports.__esModule = true;
6
+ var Meta_1 = __importDefault(require("./Meta"));
7
+ exports["default"] = Meta_1["default"];
@@ -54,7 +54,7 @@ function Notifications(props) {
54
54
  if (props.initialFlashes) {
55
55
  dispatch(notifications_1.setFlashes(props.initialFlashes));
56
56
  // Disable scroll or scroll to top on show notifications
57
- if (typeof window !== 'undefined') {
57
+ if (!process.env.IS_SSR) {
58
58
  if ('scrollRestoration' in window.history) {
59
59
  window.history.scrollRestoration = 'manual';
60
60
  }
@@ -21,6 +21,9 @@ function Portal(props) {
21
21
  document.body.removeChild(elementRef.current);
22
22
  }
23
23
  });
24
+ if (process.env.IS_SSR) {
25
+ return null;
26
+ }
24
27
  return react_dom_1.createPortal(props.children, elementRef.current);
25
28
  }
26
29
  exports["default"] = Portal;
@@ -1,4 +1,6 @@
1
1
  import * as React from 'react';
2
+ import { IFetchConfig } from '@steroidsjs/core/hooks/useFetch';
3
+ import { IListProps } from '@steroidsjs/core/ui/list/List/List';
2
4
  import { IFetchHocConfigFunc } from '../../../hoc/fetch';
3
5
  /**
4
6
  * Router
@@ -89,6 +91,17 @@ export interface IRouteItem {
89
91
  items?: IRouteItem[] | {
90
92
  [key: string]: IRouteItem;
91
93
  };
94
+ /**
95
+ * Обработчик, который принимает параметры URL и возвращает массив с пропсами для хука useFetch и компонента
96
+ * List.
97
+ * Функция запускается перед рендерингом приложения в режиме SSR и используется для предварительной
98
+ * загрузки данных, необходимых на текущей странице.
99
+ * Хук useFetch и компонент List не будут повторно инициализироваться и делать запросы на клиенте,
100
+ * если подгруженные данные существуют.
101
+ * @param {Object} match
102
+ * @return {Array} Например, [{url: '/api/v1/some-data'}, {listId: 'someList', action: '/api/v1/some-list'}]
103
+ */
104
+ preloadData?: (match: Record<string, any>) => (IFetchConfig | IListProps)[];
92
105
  [key: string]: any;
93
106
  }
94
107
  export interface IRouterProps {
@@ -49,7 +49,7 @@ var hoc_1 = require("../../../hoc");
49
49
  var router_1 = require("../../../actions/router");
50
50
  var useDispatch_1 = __importDefault(require("../../../hooks/useDispatch"));
51
51
  var router_2 = require("../../../reducers/router");
52
- var SsrProvider_1 = require("./SsrProvider");
52
+ var SsrProvider_1 = require("../../../providers/SsrProvider");
53
53
  var findRedirectPathRecursive = function (route) {
54
54
  if (!route) {
55
55
  return null;
@@ -1,15 +0,0 @@
1
- import * as React from 'react';
2
- interface ISsrProviderContext {
3
- history?: any;
4
- staticContext?: any;
5
- }
6
- export declare const SsrProviderContext: React.Context<ISsrProviderContext>;
7
- interface ISsrProviderProps {
8
- history?: any;
9
- store?: any;
10
- staticContext?: any;
11
- }
12
- export default class SsrProvider extends React.PureComponent<ISsrProviderProps> {
13
- render(): JSX.Element;
14
- }
15
- export {};
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || function (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
35
- };
36
- exports.__esModule = true;
37
- exports.SsrProviderContext = void 0;
38
- var React = __importStar(require("react"));
39
- var react_redux_1 = require("react-redux");
40
- exports.SsrProviderContext = React.createContext(null);
41
- var SsrProvider = /** @class */ (function (_super) {
42
- __extends(SsrProvider, _super);
43
- function SsrProvider() {
44
- return _super !== null && _super.apply(this, arguments) || this;
45
- }
46
- SsrProvider.prototype.render = function () {
47
- return (React.createElement(exports.SsrProviderContext.Provider, { value: {
48
- history: this.props.history,
49
- staticContext: this.props.staticContext
50
- } },
51
- React.createElement(react_redux_1.Provider, { store: this.props.store }, this.props.children)));
52
- };
53
- return SsrProvider;
54
- }(React.PureComponent));
55
- exports["default"] = SsrProvider;