@gravity-ui/page-constructor 3.2.0 → 3.4.0

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 (258) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +2 -0
  3. package/build/cjs/blocks/Banner/schema.d.ts +63 -21
  4. package/build/cjs/blocks/CardLayout/schema.d.ts +10 -4
  5. package/build/cjs/blocks/Companies/schema.d.ts +5 -2
  6. package/build/cjs/blocks/ContentLayout/ContentLayout.js +3 -2
  7. package/build/cjs/blocks/ContentLayout/schema.d.ts +107 -61
  8. package/build/cjs/blocks/ContentLayout/schema.js +23 -18
  9. package/build/cjs/blocks/ExtendedFeatures/schema.d.ts +31 -4
  10. package/build/cjs/blocks/ExtendedFeatures/schema.js +2 -3
  11. package/build/cjs/blocks/FilterBlock/schema.d.ts +13 -5
  12. package/build/cjs/blocks/FilterBlock/schema.js +13 -2
  13. package/build/cjs/blocks/Header/schema.d.ts +92 -36
  14. package/build/cjs/blocks/Header/schema.js +1 -0
  15. package/build/cjs/blocks/HeaderSlider/schema.d.ts +48 -53
  16. package/build/cjs/blocks/HeaderSlider/schema.js +3 -1
  17. package/build/cjs/blocks/Icons/schema.d.ts +3 -1
  18. package/build/cjs/blocks/Icons/schema.js +2 -1
  19. package/build/cjs/blocks/Info/schema.d.ts +19 -8
  20. package/build/cjs/blocks/Map/schema.d.ts +17 -6
  21. package/build/cjs/blocks/Media/schema.d.ts +204 -152
  22. package/build/cjs/blocks/Media/schema.js +1 -1
  23. package/build/cjs/blocks/PromoFeaturesBlock/schema.d.ts +22 -8
  24. package/build/cjs/blocks/PromoFeaturesBlock/schema.js +1 -0
  25. package/build/cjs/blocks/Questions/schema.d.ts +7 -3
  26. package/build/cjs/blocks/Slider/schema.d.ts +13 -18
  27. package/build/cjs/blocks/Slider/schema.js +4 -5
  28. package/build/cjs/blocks/Table/schema.d.ts +5 -2
  29. package/build/cjs/blocks/Table/schema.js +12 -2
  30. package/build/cjs/blocks/Tabs/schema.d.ts +43 -16
  31. package/build/cjs/components/BlockBase/BlockBase.js +2 -2
  32. package/build/cjs/components/HeaderBreadcrumbs/HeaderBreadcrumbs.js +1 -1
  33. package/build/cjs/components/Image/schema.d.ts +1 -0
  34. package/build/cjs/components/Image/schema.js +3 -2
  35. package/build/cjs/containers/PageConstructor/components/ConstructorBlock/ConstructorBlock.js +1 -1
  36. package/build/cjs/containers/PageConstructor/components/ConstructorItem/ConstructorItem.js +1 -1
  37. package/build/cjs/customization/BlockDecoration.d.ts +1 -1
  38. package/build/cjs/customization/BlockDecoration.js +5 -6
  39. package/build/cjs/editor/{Components → components}/AddBlock/AddBlock.css +1 -1
  40. package/build/cjs/editor/components/AddBlock/AddBlock.d.ts +7 -0
  41. package/build/cjs/editor/{Components → components}/AddBlock/AddBlock.js +2 -2
  42. package/build/cjs/editor/components/BlockForm/BlockForm.d.ts +12 -0
  43. package/build/cjs/editor/components/BlockForm/BlockForm.js +33 -0
  44. package/build/cjs/editor/components/ControlPanel/ControlPanel.css +26 -0
  45. package/build/cjs/editor/components/ControlPanel/ControlPanel.d.ts +8 -0
  46. package/build/cjs/editor/components/ControlPanel/ControlPanel.js +24 -0
  47. package/build/cjs/editor/components/ControlPanel/i18n/en.json +3 -0
  48. package/build/cjs/editor/components/ControlPanel/i18n/index.d.ts +2 -0
  49. package/build/cjs/editor/components/ControlPanel/i18n/index.js +8 -0
  50. package/build/cjs/editor/components/ControlPanel/i18n/ru.json +3 -0
  51. package/build/cjs/editor/components/EditBlock/EditBlock.d.ts +13 -0
  52. package/build/cjs/editor/components/EditBlock/EditBlock.js +44 -0
  53. package/build/cjs/editor/components/ErrorBoundary/ErrorBoundary.css +27 -0
  54. package/build/cjs/editor/components/ErrorBoundary/ErrorBoundary.d.ts +13 -0
  55. package/build/cjs/editor/components/ErrorBoundary/ErrorBoundary.js +35 -0
  56. package/build/cjs/editor/components/ErrorBoundary/i18n/en.json +4 -0
  57. package/build/cjs/editor/components/ErrorBoundary/i18n/index.d.ts +2 -0
  58. package/build/cjs/editor/components/ErrorBoundary/i18n/index.js +8 -0
  59. package/build/cjs/editor/components/ErrorBoundary/i18n/ru.json +4 -0
  60. package/build/cjs/editor/components/Layout/Layout.css +36 -0
  61. package/build/cjs/editor/components/Layout/Layout.d.ts +16 -0
  62. package/build/cjs/editor/components/Layout/Layout.js +34 -0
  63. package/build/cjs/editor/components/PagePropsForm/PagePropsForm.d.ts +10 -0
  64. package/build/cjs/editor/components/PagePropsForm/PagePropsForm.js +17 -0
  65. package/build/cjs/editor/containers/Editor/Editor.d.ts +2 -0
  66. package/build/cjs/editor/containers/Editor/Editor.js +40 -0
  67. package/build/cjs/editor/containers/Form/Form.css +94 -0
  68. package/build/cjs/editor/containers/Form/Form.d.ts +11 -0
  69. package/build/cjs/editor/containers/Form/Form.js +47 -0
  70. package/build/cjs/editor/containers/Form/dynamic-form-custom.css +0 -0
  71. package/build/cjs/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.css +27 -0
  72. package/build/cjs/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.d.ts +19 -0
  73. package/build/cjs/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.js +72 -0
  74. package/build/cjs/editor/dynamic-forms-custom/config.d.ts +2 -0
  75. package/build/cjs/editor/dynamic-forms-custom/config.js +13 -0
  76. package/build/cjs/editor/dynamic-forms-custom/hooks/useOneOf.d.ts +12 -0
  77. package/build/cjs/editor/dynamic-forms-custom/hooks/useOneOf.js +75 -0
  78. package/build/cjs/editor/dynamic-forms-custom/parser/detect.d.ts +9 -0
  79. package/build/cjs/editor/dynamic-forms-custom/parser/detect.js +36 -0
  80. package/build/cjs/editor/dynamic-forms-custom/parser/index.d.ts +28 -0
  81. package/build/cjs/editor/dynamic-forms-custom/parser/index.js +188 -0
  82. package/build/cjs/editor/dynamic-forms-custom/parser/types.d.ts +29 -0
  83. package/build/cjs/editor/dynamic-forms-custom/parser/types.js +2 -0
  84. package/build/cjs/editor/dynamic-forms-custom/parser/views.d.ts +37 -0
  85. package/build/cjs/editor/dynamic-forms-custom/parser/views.js +46 -0
  86. package/build/cjs/editor/hooks/useFormSpec.d.ts +2 -0
  87. package/build/cjs/editor/hooks/useFormSpec.js +13 -0
  88. package/build/cjs/editor/hooks/usePreviousValue.d.ts +1 -0
  89. package/build/cjs/editor/hooks/usePreviousValue.js +11 -0
  90. package/build/cjs/editor/index.d.ts +1 -1
  91. package/build/cjs/editor/index.js +1 -1
  92. package/build/cjs/editor/store/index.d.ts +10 -11
  93. package/build/cjs/editor/store/index.js +66 -15
  94. package/build/cjs/editor/store/reducer.d.ts +24 -9
  95. package/build/cjs/editor/store/reducer.js +17 -31
  96. package/build/cjs/editor/store/utils.d.ts +1 -0
  97. package/build/cjs/editor/store/utils.js +3 -1
  98. package/build/cjs/editor/styles/root.css +5 -0
  99. package/build/cjs/editor/types/index.d.ts +15 -9
  100. package/build/cjs/editor/types/index.js +6 -0
  101. package/build/cjs/editor/utils/index.d.ts +4 -3
  102. package/build/cjs/editor/utils/index.js +6 -4
  103. package/build/cjs/grid/Col/Col.d.ts +1 -1
  104. package/build/cjs/models/constructor-items/blocks.d.ts +13 -8
  105. package/build/cjs/models/constructor.d.ts +2 -2
  106. package/build/cjs/models/customization.d.ts +3 -8
  107. package/build/cjs/navigation/schema.d.ts +1 -0
  108. package/build/cjs/schema/constants.d.ts +908 -0
  109. package/build/cjs/schema/constants.js +42 -0
  110. package/build/cjs/schema/index.d.ts +9 -228
  111. package/build/cjs/schema/index.js +8 -46
  112. package/build/cjs/schema/validators/common.d.ts +71 -27
  113. package/build/cjs/schema/validators/common.js +50 -17
  114. package/build/cjs/sub-blocks/BackgroundCard/schema.d.ts +12 -5
  115. package/build/cjs/sub-blocks/BasicCard/schema.d.ts +8 -3
  116. package/build/cjs/sub-blocks/Content/schema.d.ts +14 -6
  117. package/build/cjs/sub-blocks/Content/schema.js +9 -1
  118. package/build/cjs/sub-blocks/LayoutItem/schema.d.ts +23 -9
  119. package/build/cjs/sub-blocks/MediaCard/schema.d.ts +16 -6
  120. package/build/cjs/sub-blocks/PriceDetailed/schema.d.ts +1 -0
  121. package/build/cjs/sub-blocks/PriceDetailed/schema.js +5 -1
  122. package/build/cjs/sub-blocks/Quote/schema.d.ts +6 -2
  123. package/build/esm/blocks/Banner/schema.d.ts +63 -21
  124. package/build/esm/blocks/CardLayout/schema.d.ts +10 -4
  125. package/build/esm/blocks/Companies/schema.d.ts +5 -2
  126. package/build/esm/blocks/ContentLayout/ContentLayout.js +3 -2
  127. package/build/esm/blocks/ContentLayout/schema.d.ts +107 -61
  128. package/build/esm/blocks/ContentLayout/schema.js +23 -18
  129. package/build/esm/blocks/ExtendedFeatures/schema.d.ts +31 -4
  130. package/build/esm/blocks/ExtendedFeatures/schema.js +3 -4
  131. package/build/esm/blocks/FilterBlock/schema.d.ts +13 -5
  132. package/build/esm/blocks/FilterBlock/schema.js +13 -2
  133. package/build/esm/blocks/Header/schema.d.ts +92 -36
  134. package/build/esm/blocks/Header/schema.js +1 -0
  135. package/build/esm/blocks/HeaderSlider/schema.d.ts +48 -53
  136. package/build/esm/blocks/HeaderSlider/schema.js +2 -1
  137. package/build/esm/blocks/Icons/schema.d.ts +3 -1
  138. package/build/esm/blocks/Icons/schema.js +2 -1
  139. package/build/esm/blocks/Info/schema.d.ts +19 -8
  140. package/build/esm/blocks/Map/schema.d.ts +17 -6
  141. package/build/esm/blocks/Media/schema.d.ts +204 -152
  142. package/build/esm/blocks/Media/schema.js +2 -2
  143. package/build/esm/blocks/PromoFeaturesBlock/schema.d.ts +22 -8
  144. package/build/esm/blocks/PromoFeaturesBlock/schema.js +1 -0
  145. package/build/esm/blocks/Questions/schema.d.ts +7 -3
  146. package/build/esm/blocks/Slider/schema.d.ts +13 -18
  147. package/build/esm/blocks/Slider/schema.js +4 -5
  148. package/build/esm/blocks/Table/schema.d.ts +5 -2
  149. package/build/esm/blocks/Table/schema.js +12 -2
  150. package/build/esm/blocks/Tabs/schema.d.ts +43 -16
  151. package/build/esm/components/BlockBase/BlockBase.js +2 -2
  152. package/build/esm/components/HeaderBreadcrumbs/HeaderBreadcrumbs.js +1 -1
  153. package/build/esm/components/Image/schema.d.ts +1 -0
  154. package/build/esm/components/Image/schema.js +3 -2
  155. package/build/esm/containers/PageConstructor/components/ConstructorBlock/ConstructorBlock.js +1 -1
  156. package/build/esm/containers/PageConstructor/components/ConstructorItem/ConstructorItem.js +1 -1
  157. package/build/esm/customization/BlockDecoration.d.ts +1 -1
  158. package/build/esm/customization/BlockDecoration.js +6 -6
  159. package/build/esm/editor/{Components → components}/AddBlock/AddBlock.css +1 -1
  160. package/build/esm/editor/components/AddBlock/AddBlock.d.ts +8 -0
  161. package/build/esm/editor/{Components → components}/AddBlock/AddBlock.js +2 -2
  162. package/build/esm/editor/components/BlockForm/BlockForm.d.ts +12 -0
  163. package/build/esm/editor/components/BlockForm/BlockForm.js +30 -0
  164. package/build/esm/editor/components/ControlPanel/ControlPanel.css +26 -0
  165. package/build/esm/editor/components/ControlPanel/ControlPanel.d.ts +9 -0
  166. package/build/esm/editor/components/ControlPanel/ControlPanel.js +22 -0
  167. package/build/esm/editor/components/ControlPanel/i18n/en.json +3 -0
  168. package/build/esm/editor/components/ControlPanel/i18n/index.d.ts +2 -0
  169. package/build/esm/editor/components/ControlPanel/i18n/index.js +5 -0
  170. package/build/esm/editor/components/ControlPanel/i18n/ru.json +3 -0
  171. package/build/esm/editor/components/EditBlock/EditBlock.d.ts +14 -0
  172. package/build/esm/editor/components/EditBlock/EditBlock.js +41 -0
  173. package/build/esm/editor/components/ErrorBoundary/ErrorBoundary.css +27 -0
  174. package/build/esm/editor/components/ErrorBoundary/ErrorBoundary.d.ts +14 -0
  175. package/build/esm/editor/components/ErrorBoundary/ErrorBoundary.js +31 -0
  176. package/build/esm/editor/components/ErrorBoundary/i18n/en.json +4 -0
  177. package/build/esm/editor/components/ErrorBoundary/i18n/index.d.ts +2 -0
  178. package/build/esm/editor/components/ErrorBoundary/i18n/index.js +5 -0
  179. package/build/esm/editor/components/ErrorBoundary/i18n/ru.json +4 -0
  180. package/build/esm/editor/components/Layout/Layout.css +36 -0
  181. package/build/esm/editor/components/Layout/Layout.d.ts +17 -0
  182. package/build/esm/editor/components/Layout/Layout.js +32 -0
  183. package/build/esm/editor/components/PagePropsForm/PagePropsForm.d.ts +10 -0
  184. package/build/esm/editor/components/PagePropsForm/PagePropsForm.js +13 -0
  185. package/build/esm/editor/containers/Editor/Editor.d.ts +2 -0
  186. package/build/esm/editor/containers/Editor/Editor.js +36 -0
  187. package/build/esm/editor/containers/Form/Form.css +94 -0
  188. package/build/esm/editor/containers/Form/Form.d.ts +12 -0
  189. package/build/esm/editor/containers/Form/Form.js +45 -0
  190. package/build/esm/editor/containers/Form/dynamic-form-custom.css +0 -0
  191. package/build/esm/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.css +27 -0
  192. package/build/esm/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.d.ts +20 -0
  193. package/build/esm/editor/dynamic-forms-custom/components/OneOfCustom/OneOfCustom.js +68 -0
  194. package/build/esm/editor/dynamic-forms-custom/config.d.ts +2 -0
  195. package/build/esm/editor/dynamic-forms-custom/config.js +9 -0
  196. package/build/esm/editor/dynamic-forms-custom/hooks/useOneOf.d.ts +12 -0
  197. package/build/esm/editor/dynamic-forms-custom/hooks/useOneOf.js +69 -0
  198. package/build/esm/editor/dynamic-forms-custom/parser/detect.d.ts +9 -0
  199. package/build/esm/editor/dynamic-forms-custom/parser/detect.js +32 -0
  200. package/build/esm/editor/dynamic-forms-custom/parser/index.d.ts +28 -0
  201. package/build/esm/editor/dynamic-forms-custom/parser/index.js +186 -0
  202. package/build/esm/editor/dynamic-forms-custom/parser/types.d.ts +29 -0
  203. package/build/esm/editor/dynamic-forms-custom/parser/types.js +1 -0
  204. package/build/esm/editor/dynamic-forms-custom/parser/views.d.ts +37 -0
  205. package/build/esm/editor/dynamic-forms-custom/parser/views.js +39 -0
  206. package/build/esm/editor/hooks/useFormSpec.d.ts +2 -0
  207. package/build/esm/editor/hooks/useFormSpec.js +9 -0
  208. package/build/esm/editor/hooks/usePreviousValue.d.ts +1 -0
  209. package/build/esm/editor/hooks/usePreviousValue.js +8 -0
  210. package/build/esm/editor/index.d.ts +1 -1
  211. package/build/esm/editor/index.js +1 -1
  212. package/build/esm/editor/store/index.d.ts +10 -11
  213. package/build/esm/editor/store/index.js +68 -17
  214. package/build/esm/editor/store/reducer.d.ts +24 -9
  215. package/build/esm/editor/store/reducer.js +15 -29
  216. package/build/esm/editor/store/utils.d.ts +1 -0
  217. package/build/esm/editor/store/utils.js +1 -0
  218. package/build/esm/editor/styles/root.css +5 -0
  219. package/build/esm/editor/types/index.d.ts +15 -9
  220. package/build/esm/editor/types/index.js +5 -1
  221. package/build/esm/editor/utils/index.d.ts +4 -3
  222. package/build/esm/editor/utils/index.js +4 -3
  223. package/build/esm/grid/Col/Col.d.ts +1 -1
  224. package/build/esm/models/constructor-items/blocks.d.ts +13 -8
  225. package/build/esm/models/constructor.d.ts +2 -2
  226. package/build/esm/models/customization.d.ts +3 -8
  227. package/build/esm/navigation/schema.d.ts +1 -0
  228. package/build/esm/schema/constants.d.ts +908 -0
  229. package/build/esm/schema/constants.js +39 -0
  230. package/build/esm/schema/index.d.ts +9 -228
  231. package/build/esm/schema/index.js +4 -42
  232. package/build/esm/schema/validators/common.d.ts +71 -27
  233. package/build/esm/schema/validators/common.js +49 -16
  234. package/build/esm/sub-blocks/BackgroundCard/schema.d.ts +12 -5
  235. package/build/esm/sub-blocks/BasicCard/schema.d.ts +8 -3
  236. package/build/esm/sub-blocks/Content/schema.d.ts +14 -6
  237. package/build/esm/sub-blocks/Content/schema.js +9 -1
  238. package/build/esm/sub-blocks/LayoutItem/schema.d.ts +23 -9
  239. package/build/esm/sub-blocks/MediaCard/schema.d.ts +16 -6
  240. package/build/esm/sub-blocks/PriceDetailed/schema.d.ts +1 -0
  241. package/build/esm/sub-blocks/PriceDetailed/schema.js +5 -1
  242. package/build/esm/sub-blocks/Quote/schema.d.ts +6 -2
  243. package/package.json +5 -1
  244. package/server/models/constructor-items/blocks.d.ts +13 -8
  245. package/server/models/constructor.d.ts +2 -2
  246. package/server/models/customization.d.ts +3 -8
  247. package/build/cjs/editor/Components/AddBlock/AddBlock.d.ts +0 -7
  248. package/build/cjs/editor/Components/EditBlock/EditBlock.d.ts +0 -4
  249. package/build/cjs/editor/Components/EditBlock/EditBlock.js +0 -32
  250. package/build/cjs/editor/Containers/Editor.d.ts +0 -2
  251. package/build/cjs/editor/Containers/Editor.js +0 -24
  252. package/build/esm/editor/Components/AddBlock/AddBlock.d.ts +0 -8
  253. package/build/esm/editor/Components/EditBlock/EditBlock.d.ts +0 -5
  254. package/build/esm/editor/Components/EditBlock/EditBlock.js +0 -30
  255. package/build/esm/editor/Containers/Editor.d.ts +0 -2
  256. package/build/esm/editor/Containers/Editor.js +0 -20
  257. /package/build/cjs/editor/{Components → components}/EditBlock/EditBlock.css +0 -0
  258. /package/build/esm/editor/{Components → components}/EditBlock/EditBlock.css +0 -0
@@ -0,0 +1,2 @@
1
+ import { SchemaCustomConfig } from '../../schema';
2
+ export default function useFormSpec(customSchema?: SchemaCustomConfig): import("../dynamic-forms-custom/parser/types").FormSpecs;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = require("react");
5
+ const schema_1 = require("../../schema");
6
+ const parser_1 = tslib_1.__importDefault(require("../dynamic-forms-custom/parser"));
7
+ function useFormSpec(customSchema) {
8
+ return (0, react_1.useMemo)(() => {
9
+ const schema = (0, schema_1.generateDefaultSchema)(customSchema);
10
+ return parser_1.default.parse(schema);
11
+ }, [customSchema]);
12
+ }
13
+ exports.default = useFormSpec;
@@ -0,0 +1 @@
1
+ export default function usePreviousValue<T>(value: T): T | undefined;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("react");
4
+ function usePreviousValue(value) {
5
+ const ref = (0, react_1.useRef)();
6
+ (0, react_1.useEffect)(() => {
7
+ ref.current = value;
8
+ }, [value]);
9
+ return ref.current;
10
+ }
11
+ exports.default = usePreviousValue;
@@ -1,2 +1,2 @@
1
- export { Editor } from './Containers/Editor';
1
+ export { Editor } from './containers/Editor/Editor';
2
2
  export * from './types';
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Editor = void 0;
4
4
  const tslib_1 = require("tslib");
5
- var Editor_1 = require("./Containers/Editor");
5
+ var Editor_1 = require("./containers/Editor/Editor");
6
6
  Object.defineProperty(exports, "Editor", { enumerable: true, get: function () { return Editor_1.Editor; } });
7
7
  tslib_1.__exportStar(require("./types"), exports);
@@ -1,15 +1,14 @@
1
- import { Block } from '../../models';
2
- import { EditorProps } from '../types';
1
+ import { Block, BlockDecorationProps, PageContent } from '../../models';
2
+ import { EditBlockProps, EditorProps, ViewModeItem } from '../types';
3
3
  export type EditorBlockId = number | string;
4
4
  export declare function useEditorState({ content: intialContent, custom }: Omit<EditorProps, 'children'>): {
5
- content: import("../../models").PageContent;
6
- editControlsProps: {
7
- activeBlockId: import("./reducer").EditorBlockId;
8
- orderedBlocksCount: number;
9
- onDelete: (id: EditorBlockId) => void;
10
- onSelect: (id: EditorBlockId) => void;
11
- onCopy: (index: number) => void;
12
- onOrderChange: (oldIndex: number, newIndex: number) => void;
13
- };
5
+ activeBlockIndex: number;
6
+ content: PageContent;
7
+ errorBoundaryState: number;
8
+ viewMode: ViewModeItem;
9
+ injectEditBlockProps: ({ type, index: relativeIndex, children, }: BlockDecorationProps) => EditBlockProps;
14
10
  onAdd: (block: Block) => void;
11
+ onSelect: (index: number) => void;
12
+ onContentUpdate: (newContent: PageContent) => void;
13
+ onViewModeUpdate: (newViewMode: ViewModeItem) => void;
15
14
  };
@@ -4,29 +4,80 @@ exports.useEditorState = void 0;
4
4
  const react_1 = require("react");
5
5
  const models_1 = require("../../models");
6
6
  const utils_1 = require("../../utils");
7
+ const EditBlock_1 = require("../components/EditBlock/EditBlock");
8
+ const types_1 = require("../types");
7
9
  const reducer_1 = require("./reducer");
8
10
  const utils_2 = require("./utils");
9
11
  function useEditorState({ content: intialContent, custom }) {
10
- const headerBlockTypes = (0, react_1.useMemo)(() => [...models_1.HeaderBlockTypes, ...(0, utils_1.getCustomHeaderTypes)(custom)], [custom]);
11
- const reducer = (0, react_1.useMemo)(() => (0, reducer_1.getReducer)(headerBlockTypes), [headerBlockTypes]);
12
- const [{ activeBlockId, content, orderedBlocksCount }, dispatch] = (0, react_1.useReducer)(reducer, {
13
- activeBlockId: 0,
14
- orderedBlocksCount: (0, utils_1.getOrderedBlocks)(intialContent.blocks, headerBlockTypes).length,
12
+ const [{ activeBlockIndex, content, errorBoundaryState, viewMode }, dispatch] = (0, react_1.useReducer)(reducer_1.reducer, {
13
+ activeBlockIndex: 0,
14
+ errorBoundaryState: 0,
15
15
  content: (0, utils_2.addEditorProps)(intialContent),
16
+ viewMode: types_1.ViewModeItem.Edititng,
16
17
  });
17
18
  return (0, react_1.useMemo)(() => {
19
+ const headerBlockTypes = [...models_1.HeaderBlockTypes, ...(0, utils_1.getCustomHeaderTypes)(custom)];
20
+ const contentHasHeader = Boolean((0, utils_1.getHeaderBlock)(content.blocks, headerBlockTypes));
21
+ const checkIsHeader = (type) => headerBlockTypes.includes(type);
22
+ const onAdd = (block) => {
23
+ const isHeader = checkIsHeader(block.type);
24
+ if (contentHasHeader && isHeader) {
25
+ //TODO: add warning that it should be only one header block
26
+ return;
27
+ }
28
+ // eslint-disable-next-line no-nested-ternary
29
+ const index = isHeader
30
+ ? 0
31
+ : activeBlockIndex === -1
32
+ ? content.blocks.length
33
+ : activeBlockIndex + 1;
34
+ dispatch({ type: reducer_1.ADD_BLOCK, payload: { block, index } });
35
+ };
36
+ const onSelect = (index) => dispatch({ type: reducer_1.SELECT_BLOCK, payload: index });
37
+ const onContentUpdate = (newContent) => dispatch({ type: reducer_1.UPDATE_CONTENT, payload: newContent });
38
+ const onViewModeUpdate = (newViewMode) => dispatch({ type: reducer_1.UPDATE_VIEW_MODE, payload: newViewMode });
39
+ const injectEditBlockProps = ({ type, index: relativeIndex = 0, children, }) => {
40
+ const orderedBlocksStartIndex = contentHasHeader ? 1 : 0;
41
+ const isHeader = checkIsHeader(type);
42
+ const index = isHeader ? 0 : relativeIndex + orderedBlocksStartIndex;
43
+ const isActive = activeBlockIndex === index;
44
+ const actions = {
45
+ [EditBlock_1.EditBlockControls.Delete]: () => dispatch({ type: reducer_1.DELETE_BLOCK, payload: index }),
46
+ };
47
+ if (!isHeader) {
48
+ actions[EditBlock_1.EditBlockControls.Copy] = () => dispatch({ type: reducer_1.COPY_BLOCK, payload: index });
49
+ if (index > orderedBlocksStartIndex) {
50
+ actions[EditBlock_1.EditBlockControls.Up] = () => dispatch({
51
+ type: reducer_1.ORDER_BLOCK,
52
+ payload: { oldIndex: index, newIndex: index - 1 },
53
+ });
54
+ }
55
+ if (index < content.blocks.length - 1) {
56
+ actions[EditBlock_1.EditBlockControls.Down] = () => dispatch({
57
+ type: reducer_1.ORDER_BLOCK,
58
+ payload: { oldIndex: index, newIndex: index + 1 },
59
+ });
60
+ }
61
+ }
62
+ return {
63
+ children,
64
+ isHeader,
65
+ isActive,
66
+ actions,
67
+ onSelect: () => onSelect(index),
68
+ };
69
+ };
18
70
  return {
71
+ activeBlockIndex,
19
72
  content,
20
- editControlsProps: {
21
- activeBlockId,
22
- orderedBlocksCount,
23
- onDelete: (id) => dispatch({ type: reducer_1.DELETE_BLOCK, payload: id }),
24
- onSelect: (id) => dispatch({ type: reducer_1.SELECT_BLOCK, payload: id }),
25
- onCopy: (index) => dispatch({ type: reducer_1.COPY_BLOCK, payload: index }),
26
- onOrderChange: (oldIndex, newIndex) => dispatch({ type: reducer_1.ORDER_BLOCK, payload: { oldIndex, newIndex } }),
27
- },
28
- onAdd: (block) => dispatch({ type: reducer_1.ADD_BLOCK, payload: block }),
73
+ errorBoundaryState,
74
+ viewMode,
75
+ injectEditBlockProps,
76
+ onAdd,
77
+ onSelect,
78
+ onContentUpdate,
79
+ onViewModeUpdate,
29
80
  };
30
- }, [content, activeBlockId, orderedBlocksCount]);
81
+ }, [content, activeBlockIndex, errorBoundaryState, custom, viewMode]);
31
82
  }
32
83
  exports.useEditorState = useEditorState;
@@ -1,28 +1,35 @@
1
- import { Block, CustomConfig, PageContent } from '../../models';
1
+ import { Block, PageContent } from '../../models';
2
+ import { ViewModeItem } from '../types';
2
3
  export type EditorBlockId = number | string;
3
4
  interface EditorState {
4
5
  content: PageContent;
5
- activeBlockId: EditorBlockId;
6
- orderedBlocksCount: number;
7
- custom?: CustomConfig;
6
+ activeBlockIndex: number;
7
+ errorBoundaryState: number;
8
+ viewMode: ViewModeItem;
8
9
  }
9
10
  interface OrderBlockParams {
10
11
  oldIndex: number;
11
12
  newIndex: number;
12
13
  }
14
+ interface AddBlockParams {
15
+ block: Block;
16
+ index: number;
17
+ }
13
18
  export declare const SELECT_BLOCK = "SELECT_BLOCK";
14
19
  export declare const DELETE_BLOCK = "DELETE_BLOCK";
15
20
  export declare const COPY_BLOCK = "COPY_BLOCK";
16
21
  export declare const ADD_BLOCK = "ADD_BLOCK";
17
22
  export declare const SET_REGION = "SET_REGION";
18
23
  export declare const ORDER_BLOCK = "ORDER_BLOCK";
24
+ export declare const UPDATE_CONTENT = "UPDATE_CONTENT";
25
+ export declare const UPDATE_VIEW_MODE = "UPDATE_VIEW_MODE";
19
26
  interface SelectBlock {
20
27
  type: typeof SELECT_BLOCK;
21
- payload: EditorBlockId;
28
+ payload: number;
22
29
  }
23
30
  interface DeleteBlock {
24
31
  type: typeof DELETE_BLOCK;
25
- payload: EditorBlockId;
32
+ payload: number;
26
33
  }
27
34
  interface CopyBlock {
28
35
  type: typeof COPY_BLOCK;
@@ -30,12 +37,20 @@ interface CopyBlock {
30
37
  }
31
38
  interface AddBlock {
32
39
  type: typeof ADD_BLOCK;
33
- payload: Block;
40
+ payload: AddBlockParams;
34
41
  }
35
42
  interface OrderBlock {
36
43
  type: typeof ORDER_BLOCK;
37
44
  payload: OrderBlockParams;
38
45
  }
39
- export type EditorAction = SelectBlock | DeleteBlock | CopyBlock | AddBlock | OrderBlock;
40
- export declare const getReducer: (headerBlockTypes: string[]) => (state: EditorState, action: EditorAction) => EditorState;
46
+ interface UpdateContent {
47
+ type: typeof UPDATE_CONTENT;
48
+ payload: PageContent;
49
+ }
50
+ interface UpdateViewMode {
51
+ type: typeof UPDATE_VIEW_MODE;
52
+ payload: ViewModeItem;
53
+ }
54
+ export type EditorAction = SelectBlock | DeleteBlock | CopyBlock | AddBlock | OrderBlock | UpdateContent | UpdateViewMode;
55
+ export declare const reducer: (state: EditorState, action: EditorAction) => EditorState;
41
56
  export {};
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getReducer = exports.ORDER_BLOCK = exports.SET_REGION = exports.ADD_BLOCK = exports.COPY_BLOCK = exports.DELETE_BLOCK = exports.SELECT_BLOCK = void 0;
4
- const utils_1 = require("../../utils");
5
- const utils_2 = require("./utils");
3
+ exports.reducer = exports.UPDATE_VIEW_MODE = exports.UPDATE_CONTENT = exports.ORDER_BLOCK = exports.SET_REGION = exports.ADD_BLOCK = exports.COPY_BLOCK = exports.DELETE_BLOCK = exports.SELECT_BLOCK = void 0;
4
+ const utils_1 = require("./utils");
6
5
  // actions
7
6
  exports.SELECT_BLOCK = 'SELECT_BLOCK';
8
7
  exports.DELETE_BLOCK = 'DELETE_BLOCK';
@@ -10,50 +9,37 @@ exports.COPY_BLOCK = 'COPY_BLOCK';
10
9
  exports.ADD_BLOCK = 'ADD_BLOCK';
11
10
  exports.SET_REGION = 'SET_REGION';
12
11
  exports.ORDER_BLOCK = 'ORDER_BLOCK';
12
+ exports.UPDATE_CONTENT = 'UPDATE_CONTENT';
13
+ exports.UPDATE_VIEW_MODE = 'UPDATE_VIEW_MODE';
13
14
  // reducer
14
- const getReducer = (headerBlockTypes) => (state, action) => {
15
+ const reducer = (state, action) => {
15
16
  const { content } = state;
16
- const header = (0, utils_1.getHeaderBlock)(content.blocks, headerBlockTypes);
17
- const orderedBlocks = (0, utils_1.getOrderedBlocks)(content.blocks, headerBlockTypes);
18
- const withHeader = (blocks) => [header, ...blocks].filter(Boolean);
19
- const getNewState = (blocks, activeBlockId) => (Object.assign(Object.assign({}, state), { content: Object.assign(Object.assign({}, content), { blocks }), activeBlockId, orderedBlocksCount: orderedBlocks.length }));
17
+ const getNewState = (blocks, activeBlockIndex) => (Object.assign(Object.assign({}, state), { content: Object.assign(Object.assign({}, content), { blocks }), activeBlockIndex }));
20
18
  switch (action.type) {
19
+ case exports.UPDATE_CONTENT:
20
+ return Object.assign(Object.assign({}, state), { content: action.payload, errorBoundaryState: (0, utils_1.getErrorBoundaryState)(state.errorBoundaryState) });
21
21
  case exports.SELECT_BLOCK:
22
- return getNewState(content.blocks, action.payload);
22
+ return Object.assign(Object.assign({}, state), { activeBlockIndex: action.payload });
23
23
  case exports.DELETE_BLOCK: {
24
24
  const blockId = action.payload;
25
- return getNewState(typeof blockId === 'string'
26
- ? content.blocks.filter(({ type }) => type !== blockId)
27
- : withHeader(orderedBlocks.filter((_block, index) => index !== blockId)), -1);
25
+ return getNewState(content.blocks.filter((_block, index) => index !== blockId), -1);
28
26
  }
29
27
  case exports.COPY_BLOCK: {
30
28
  const index = action.payload;
31
- return getNewState(withHeader((0, utils_2.duplicateBlock)(orderedBlocks, index)), index + 1);
29
+ return getNewState((0, utils_1.duplicateBlock)(content.blocks, index), index + 1);
32
30
  }
33
31
  case exports.ADD_BLOCK: {
34
- let blocks;
35
- let activeBlockId;
36
- const block = action.payload;
37
- if (headerBlockTypes.includes(block.type)) {
38
- blocks = header ? blocks : [block, ...orderedBlocks];
39
- activeBlockId = block.type;
40
- }
41
- else {
42
- const newBlockIndex = (0, utils_2.getNewBlockIndex)(state.activeBlockId, orderedBlocks.length);
43
- blocks = withHeader((0, utils_2.addBlock)(orderedBlocks, block, newBlockIndex));
44
- activeBlockId = newBlockIndex;
45
- }
46
- if (blocks) {
47
- return getNewState(blocks, activeBlockId);
48
- }
49
- return state;
32
+ const { block, index } = action.payload;
33
+ return getNewState((0, utils_1.addBlock)(content.blocks, block, index), index);
50
34
  }
51
35
  case exports.ORDER_BLOCK: {
52
36
  const { oldIndex, newIndex } = action.payload;
53
- return getNewState(withHeader((0, utils_2.changeBlocksOrder)(orderedBlocks, oldIndex, newIndex)), newIndex);
37
+ return getNewState((0, utils_1.changeBlocksOrder)(content.blocks, oldIndex, newIndex), newIndex);
54
38
  }
39
+ case exports.UPDATE_VIEW_MODE:
40
+ return Object.assign(Object.assign({}, state), { viewMode: action.payload });
55
41
  default:
56
42
  return state;
57
43
  }
58
44
  };
59
- exports.getReducer = getReducer;
45
+ exports.reducer = reducer;
@@ -10,3 +10,4 @@ export declare const addEditorProps: (content: PageContent) => {
10
10
  menu?: import("../../models").Menu | undefined;
11
11
  background?: import("../../models").ThemedMediaProps | undefined;
12
12
  };
13
+ export declare const getErrorBoundaryState: (prevState: number) => number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addEditorProps = exports.addBlock = exports.getNewBlockIndex = exports.duplicateBlock = exports.changeBlocksOrder = void 0;
3
+ exports.getErrorBoundaryState = exports.addEditorProps = exports.addBlock = exports.getNewBlockIndex = exports.duplicateBlock = exports.changeBlocksOrder = void 0;
4
4
  const changeBlocksOrder = (array, oldIndex, newIndex) => {
5
5
  const result = [...array];
6
6
  const element = result.splice(oldIndex, 1)[0];
@@ -32,3 +32,5 @@ const addEditorProps = (content) => {
32
32
  return Object.assign(Object.assign({}, content), { animated: false });
33
33
  };
34
34
  exports.addEditorProps = addEditorProps;
35
+ const getErrorBoundaryState = (prevState) => prevState === Number.MAX_SAFE_INTEGER ? 0 : prevState + 1;
36
+ exports.getErrorBoundaryState = getErrorBoundaryState;
@@ -0,0 +1,5 @@
1
+ :root {
2
+ --editor-header-height: 48px;
3
+ --editor-divider-width: 12px;
4
+ --editor-left-column-width: calc(400px + var(--editor-divider-width));
5
+ }
@@ -1,17 +1,23 @@
1
1
  /// <reference types="react" />
2
2
  import { PageConstructorProps } from '../../containers/PageConstructor';
3
- import { BlockDecoratorProps, PageData } from '../../models';
3
+ import { BlockDecorationProps, PageContent } from '../../models';
4
+ import { SchemaCustomConfig } from '../../schema';
5
+ import { EditBlockActions } from '../components/EditBlock/EditBlock';
4
6
  export type EditorBlockId = number | string;
5
7
  export interface EditorProps extends Required<Pick<PageConstructorProps, 'content'>>, Partial<Omit<PageConstructorProps, 'content'>> {
6
8
  children: (props: Partial<PageConstructorProps>) => React.ReactNode;
7
- onChange?: (data: PageData) => void;
9
+ onChange?: (data: PageContent) => void;
10
+ customSchema?: SchemaCustomConfig;
8
11
  }
9
12
  export interface EditBlockEditorProps {
10
- activeBlockId: EditorBlockId;
11
- orderedBlocksCount: number;
12
- onSelect: (index: EditorBlockId) => void;
13
- onDelete: (index: EditorBlockId) => void;
14
- onCopy: (index: number) => void;
15
- onOrderChange: (index: number, newIndex: number) => void;
13
+ isActive?: boolean;
14
+ onSelect: () => void;
15
+ actions: EditBlockActions;
16
+ }
17
+ export interface EditBlockProps extends EditBlockEditorProps, BlockDecorationProps {
18
+ isHeader?: boolean;
19
+ }
20
+ export declare enum ViewModeItem {
21
+ Edititng = "editing",
22
+ View = "view"
16
23
  }
17
- export type EditBlockProps = EditBlockEditorProps & BlockDecoratorProps;
@@ -1,2 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ViewModeItem = void 0;
4
+ var ViewModeItem;
5
+ (function (ViewModeItem) {
6
+ ViewModeItem["Edititng"] = "editing";
7
+ ViewModeItem["View"] = "view";
8
+ })(ViewModeItem = exports.ViewModeItem || (exports.ViewModeItem = {}));
@@ -1,11 +1,12 @@
1
- import { BlockDecorator, CustomConfig } from '../../models';
1
+ import { BlockDecorationProps, BlockDecorator, CustomConfig } from '../../models';
2
2
  export declare const formatBlockName: (name: string) => string;
3
- export declare const addCustomDecorator: (decorator: BlockDecorator, custom?: CustomConfig) => {
3
+ export declare const addCustomDecorator: (decorators: BlockDecorator[], custom?: CustomConfig) => {
4
4
  decorators: {
5
- block: ((props: import("../../models").BlockDecoratorProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>)[];
5
+ block: ((props: BlockDecorationProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>)[];
6
6
  };
7
7
  blocks?: import("../../models").CustomItems | undefined;
8
8
  subBlocks?: import("../../models").CustomItems | undefined;
9
9
  headers?: import("../../models").CustomItems | undefined;
10
10
  loadable?: import("../../models").LoadableConfig | undefined;
11
11
  };
12
+ export declare const getBlockId: ({ index, type }: BlockDecorationProps) => string;
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addCustomDecorator = exports.formatBlockName = void 0;
3
+ exports.getBlockId = exports.addCustomDecorator = exports.formatBlockName = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
6
  const formatBlockName = (name) => lodash_1.default.capitalize(name).replace(/(block|-)/g, ' ');
7
7
  exports.formatBlockName = formatBlockName;
8
- const addCustomDecorator = (decorator, custom = {}) => {
9
- const decorators = custom.decorators || {};
10
- return Object.assign(Object.assign({}, custom), { decorators: Object.assign(Object.assign({}, decorators), { block: [...(decorators.block || []), decorator] }) });
8
+ const addCustomDecorator = (decorators, custom = {}) => {
9
+ const customDecorators = custom.decorators || {};
10
+ return Object.assign(Object.assign({}, custom), { decorators: Object.assign(Object.assign({}, customDecorators), { block: [...(customDecorators.block || []), ...decorators] }) });
11
11
  };
12
12
  exports.addCustomDecorator = addCustomDecorator;
13
+ const getBlockId = ({ index, type }) => `${type}${index === undefined ? '' : `-${index}`}`;
14
+ exports.getBlockId = getBlockId;
@@ -7,4 +7,4 @@ export interface GridColumnProps extends GridColumnClassParams, Refable<HTMLDivE
7
7
  dataQa?: string;
8
8
  children?: React.ReactNode;
9
9
  }
10
- export declare const Col: React.ForwardRefExoticComponent<Pick<WithChildren<GridColumnProps>, "style" | "children" | "className" | "reset" | "visible" | "sizes" | "offsets" | "orders" | "hidden" | "alignSelf" | "justifyContent" | "dataQa"> & React.RefAttributes<HTMLDivElement>>;
10
+ export declare const Col: React.ForwardRefExoticComponent<Pick<WithChildren<GridColumnProps>, "style" | "children" | "className" | "visible" | "reset" | "sizes" | "offsets" | "orders" | "hidden" | "alignSelf" | "justifyContent" | "dataQa"> & React.RefAttributes<HTMLDivElement>>;
@@ -30,6 +30,7 @@ export interface Childable {
30
30
  children?: SubBlock[];
31
31
  }
32
32
  export interface BlockBaseProps {
33
+ type: BlockType;
33
34
  index?: number;
34
35
  anchor?: AnchorProps;
35
36
  visible?: GridColumnSize;
@@ -244,14 +245,18 @@ export interface IconsBlockProps {
244
245
  src: string;
245
246
  }[];
246
247
  }
247
- export interface ContentLayoutBlockProps {
248
- properties?: {
249
- size?: ContentSize;
250
- background?: BackgroundImageProps;
251
- centered?: boolean;
252
- theme?: ContentTheme;
253
- textWidth?: ContentTextSize;
254
- };
248
+ interface ContentLayoutBlockParams {
249
+ size?: ContentSize;
250
+ background?: BackgroundImageProps;
251
+ centered?: boolean;
252
+ theme?: ContentTheme;
253
+ textWidth?: ContentTextSize;
254
+ }
255
+ export interface ContentLayoutBlockProps extends ContentLayoutBlockParams {
256
+ /**
257
+ * @deprecated Use params on top level instead
258
+ */
259
+ properties?: ContentLayoutBlockParams;
255
260
  textContent: ContentBlockProps;
256
261
  fileContent?: FileLinkProps[];
257
262
  }
@@ -1,5 +1,5 @@
1
1
  import React, { PropsWithChildren } from 'react';
2
- import { Animatable, Block, BlockDecoratorProps, ConstructorItem, ThemedMediaProps, WithChildren } from './';
2
+ import { Animatable, Block, BlockDecorationProps, ConstructorItem, ThemedMediaProps, WithChildren } from './';
3
3
  export interface PageData {
4
4
  content: PageContent;
5
5
  }
@@ -41,7 +41,7 @@ export interface CustomConfig {
41
41
  headers?: CustomItems;
42
42
  loadable?: LoadableConfig;
43
43
  decorators?: {
44
- block?: ((props: BlockDecoratorProps) => React.ReactElement)[];
44
+ block?: ((props: BlockDecorationProps) => React.ReactElement)[];
45
45
  };
46
46
  }
47
47
  export {};
@@ -1,9 +1,4 @@
1
1
  import { PropsWithChildren } from 'react';
2
- export interface BlockDecorationProps extends PropsWithChildren {
3
- id: string | number;
4
- }
5
- export interface BlockDecoratorProps extends PropsWithChildren {
6
- id: string | number;
7
- isHeader?: boolean;
8
- }
9
- export type BlockDecorator = (props: BlockDecoratorProps) => React.ReactElement;
2
+ import { BlockBaseProps } from './constructor-items';
3
+ export type BlockDecorationProps = Pick<BlockBaseProps, 'index' | 'type'> & PropsWithChildren;
4
+ export type BlockDecorator = (props: BlockDecorationProps) => React.ReactElement;
@@ -14,6 +14,7 @@ export declare const LogoProps: {
14
14
  } | {
15
15
  type: string;
16
16
  pattern: string;
17
+ optionName: string;
17
18
  })[];
18
19
  };
19
20
  text: {