@gravity-ui/page-constructor 2.22.0-alpha → 2.22.0-alpha.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 (162) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/build/cjs/components/Anchor/Anchor.d.ts +2 -2
  3. package/build/cjs/components/Anchor/Anchor.js +1 -1
  4. package/build/cjs/components/BackgroundImage/BackgroundImage.js +2 -2
  5. package/build/cjs/components/BlockBase/BlockBase.d.ts +3 -2
  6. package/build/cjs/components/BlockBase/BlockBase.js +4 -2
  7. package/build/cjs/components/Button/Button.css +3 -0
  8. package/build/cjs/components/Button/Button.js +5 -4
  9. package/build/cjs/components/Image/Image.d.ts +1 -0
  10. package/build/cjs/components/Image/Image.js +2 -2
  11. package/build/cjs/containers/Loadable/Loadable.d.ts +2 -2
  12. package/build/cjs/containers/PageConstructor/PageConstructor.js +5 -3
  13. package/build/cjs/containers/PageConstructor/components/ConstructorBlocks/ConstructorBlocks.js +3 -2
  14. package/build/cjs/containers/PageConstructor/components/ConstructorItem/ConstructorItem.d.ts +1 -1
  15. package/build/cjs/containers/PageConstructor/components/ConstructorItem/ConstructorItem.js +5 -5
  16. package/build/cjs/context/innerContext/InnerContext.d.ts +2 -1
  17. package/build/cjs/customization/BlockDecoration.d.ts +3 -0
  18. package/build/cjs/customization/BlockDecoration.js +22 -0
  19. package/build/cjs/editor/Components/AddBlock/AddBlock.css +82 -0
  20. package/build/cjs/editor/Components/AddBlock/AddBlock.d.ts +7 -0
  21. package/build/cjs/editor/Components/AddBlock/AddBlock.js +43 -0
  22. package/build/cjs/editor/Components/EditBlock/EditBlock.css +47 -0
  23. package/build/cjs/editor/Components/EditBlock/EditBlock.d.ts +4 -0
  24. package/build/cjs/editor/Components/EditBlock/EditBlock.js +32 -0
  25. package/build/cjs/editor/Containers/Editor.d.ts +2 -0
  26. package/build/cjs/editor/Containers/Editor.js +24 -0
  27. package/build/cjs/editor/data/index.d.ts +13 -0
  28. package/build/cjs/editor/data/index.js +27 -0
  29. package/build/cjs/editor/data/previews/default-preview.d.ts +3 -0
  30. package/build/cjs/editor/data/previews/default-preview.js +18 -0
  31. package/build/cjs/editor/data/previews/header-block.d.ts +3 -0
  32. package/build/cjs/editor/data/previews/header-block.js +19 -0
  33. package/build/cjs/editor/index.d.ts +2 -0
  34. package/build/cjs/editor/index.js +7 -0
  35. package/build/cjs/editor/store/index.d.ts +15 -0
  36. package/build/cjs/editor/store/index.js +32 -0
  37. package/build/cjs/editor/store/reducer.d.ts +41 -0
  38. package/build/cjs/editor/store/reducer.js +59 -0
  39. package/build/cjs/editor/store/utils.d.ts +13 -0
  40. package/build/cjs/editor/store/utils.js +34 -0
  41. package/build/cjs/editor/styles/mixins.css +0 -0
  42. package/build/cjs/editor/styles/variables.css +0 -0
  43. package/build/cjs/editor/types/index.d.ts +17 -0
  44. package/build/cjs/editor/types/index.js +2 -0
  45. package/build/cjs/editor/utils/index.d.ts +11 -0
  46. package/build/cjs/editor/utils/index.js +12 -0
  47. package/build/cjs/grid/Col/Col.d.ts +1 -1
  48. package/build/cjs/hooks/useMetrika.js +0 -7
  49. package/build/cjs/internal-typings/global.d.ts +18 -16
  50. package/build/cjs/models/constructor-items/blocks.d.ts +1 -11
  51. package/build/cjs/models/constructor-items/blocks.js +0 -2
  52. package/build/cjs/models/constructor-items/common.d.ts +3 -3
  53. package/build/cjs/models/constructor.d.ts +4 -1
  54. package/build/cjs/models/customization.d.ts +9 -0
  55. package/build/cjs/models/customization.js +2 -0
  56. package/build/cjs/models/index.d.ts +1 -0
  57. package/build/cjs/models/index.js +1 -0
  58. package/build/cjs/sub-blocks/HubspotForm/HubspotFormContainer.d.ts +2 -1
  59. package/build/cjs/sub-blocks/HubspotForm/HubspotFormContainer.js +5 -2
  60. package/build/cjs/sub-blocks/HubspotForm/index.d.ts +1 -1
  61. package/build/cjs/sub-blocks/HubspotForm/index.js +6 -5
  62. package/build/cjs/utils/blocks.d.ts +4 -1
  63. package/build/cjs/utils/blocks.js +11 -1
  64. package/build/esm/components/Anchor/Anchor.d.ts +2 -2
  65. package/build/esm/components/Anchor/Anchor.js +1 -1
  66. package/build/esm/components/BackgroundImage/BackgroundImage.js +2 -2
  67. package/build/esm/components/BlockBase/BlockBase.d.ts +3 -2
  68. package/build/esm/components/BlockBase/BlockBase.js +4 -2
  69. package/build/esm/components/Button/Button.css +3 -0
  70. package/build/esm/components/Button/Button.js +5 -4
  71. package/build/esm/components/Image/Image.d.ts +1 -0
  72. package/build/esm/components/Image/Image.js +2 -2
  73. package/build/esm/containers/Loadable/Loadable.d.ts +2 -2
  74. package/build/esm/containers/PageConstructor/PageConstructor.js +6 -4
  75. package/build/esm/containers/PageConstructor/components/ConstructorBlocks/ConstructorBlocks.js +3 -2
  76. package/build/esm/containers/PageConstructor/components/ConstructorItem/ConstructorItem.d.ts +1 -1
  77. package/build/esm/containers/PageConstructor/components/ConstructorItem/ConstructorItem.js +5 -5
  78. package/build/esm/context/innerContext/InnerContext.d.ts +2 -1
  79. package/build/esm/customization/BlockDecoration.d.ts +3 -0
  80. package/build/esm/customization/BlockDecoration.js +17 -0
  81. package/build/esm/editor/Components/AddBlock/AddBlock.css +82 -0
  82. package/build/esm/editor/Components/AddBlock/AddBlock.d.ts +8 -0
  83. package/build/esm/editor/Components/AddBlock/AddBlock.js +41 -0
  84. package/build/esm/editor/Components/EditBlock/EditBlock.css +47 -0
  85. package/build/esm/editor/Components/EditBlock/EditBlock.d.ts +5 -0
  86. package/build/esm/editor/Components/EditBlock/EditBlock.js +30 -0
  87. package/build/esm/editor/Containers/Editor.d.ts +2 -0
  88. package/build/esm/editor/Containers/Editor.js +20 -0
  89. package/build/esm/editor/data/index.d.ts +13 -0
  90. package/build/esm/editor/data/index.js +24 -0
  91. package/build/esm/editor/data/previews/default-preview.d.ts +3 -0
  92. package/build/esm/editor/data/previews/default-preview.js +15 -0
  93. package/build/esm/editor/data/previews/header-block.d.ts +3 -0
  94. package/build/esm/editor/data/previews/header-block.js +16 -0
  95. package/build/esm/editor/index.d.ts +2 -0
  96. package/build/esm/editor/index.js +2 -0
  97. package/build/esm/editor/store/index.d.ts +15 -0
  98. package/build/esm/editor/store/index.js +28 -0
  99. package/build/esm/editor/store/reducer.d.ts +41 -0
  100. package/build/esm/editor/store/reducer.js +55 -0
  101. package/build/esm/editor/store/utils.d.ts +13 -0
  102. package/build/esm/editor/store/utils.js +26 -0
  103. package/build/esm/editor/styles/mixins.css +0 -0
  104. package/build/esm/editor/styles/variables.css +0 -0
  105. package/build/esm/editor/types/index.d.ts +17 -0
  106. package/build/esm/editor/utils/index.d.ts +11 -0
  107. package/build/esm/editor/utils/index.js +6 -0
  108. package/build/esm/grid/Col/Col.d.ts +1 -1
  109. package/build/esm/hooks/useMetrika.js +0 -7
  110. package/build/esm/internal-typings/global.d.ts +18 -16
  111. package/build/esm/models/constructor-items/blocks.d.ts +1 -11
  112. package/build/esm/models/constructor-items/blocks.js +0 -2
  113. package/build/esm/models/constructor-items/common.d.ts +3 -3
  114. package/build/esm/models/constructor.d.ts +4 -1
  115. package/build/esm/models/customization.d.ts +9 -0
  116. package/build/esm/models/index.d.ts +1 -0
  117. package/build/esm/models/index.js +1 -0
  118. package/build/esm/sub-blocks/HubspotForm/HubspotFormContainer.d.ts +2 -1
  119. package/build/esm/sub-blocks/HubspotForm/HubspotFormContainer.js +6 -3
  120. package/build/esm/sub-blocks/HubspotForm/index.d.ts +1 -1
  121. package/build/esm/sub-blocks/HubspotForm/index.js +7 -6
  122. package/build/esm/utils/blocks.d.ts +4 -1
  123. package/build/esm/utils/blocks.js +7 -0
  124. package/package.json +4 -3
  125. package/server/models/constructor-items/blocks.d.ts +1 -11
  126. package/server/models/constructor-items/blocks.js +0 -2
  127. package/server/models/constructor-items/common.d.ts +3 -3
  128. package/server/models/constructor.d.ts +4 -1
  129. package/server/models/customization.d.ts +9 -0
  130. package/server/models/customization.js +2 -0
  131. package/server/models/index.d.ts +1 -0
  132. package/server/models/index.js +1 -0
  133. package/server/utils/blocks.d.ts +4 -1
  134. package/server/utils/blocks.js +11 -1
  135. package/build/cjs/components/Anchor/__tests__/Anchor.test.js +0 -21
  136. package/build/cjs/components/AnimateBlock/__tests__/AnimateBlock.test.js +0 -36
  137. package/build/cjs/components/Author/__tests__/Author.test.d.ts +0 -1
  138. package/build/cjs/components/Author/__tests__/Author.test.js +0 -49
  139. package/build/cjs/components/BackLink/__tests__/BackLink.test.d.ts +0 -1
  140. package/build/cjs/components/BackLink/__tests__/BackLink.test.js +0 -63
  141. package/build/cjs/components/BlockBase/__tests__/BlockBase.test.d.ts +0 -1
  142. package/build/cjs/components/BlockBase/__tests__/BlockBase.test.js +0 -44
  143. package/build/cjs/components/Button/__tests__/Button.test.d.ts +0 -1
  144. package/build/cjs/components/Button/__tests__/Button.test.js +0 -91
  145. package/build/cjs/components/ButtonTabs/__tests__/ButtonTabs.test.d.ts +0 -1
  146. package/build/cjs/components/ButtonTabs/__tests__/ButtonTabs.test.js +0 -58
  147. package/build/esm/components/Anchor/__tests__/Anchor.test.d.ts +0 -1
  148. package/build/esm/components/Anchor/__tests__/Anchor.test.js +0 -18
  149. package/build/esm/components/AnimateBlock/__tests__/AnimateBlock.test.d.ts +0 -1
  150. package/build/esm/components/AnimateBlock/__tests__/AnimateBlock.test.js +0 -33
  151. package/build/esm/components/Author/__tests__/Author.test.d.ts +0 -1
  152. package/build/esm/components/Author/__tests__/Author.test.js +0 -46
  153. package/build/esm/components/BackLink/__tests__/BackLink.test.d.ts +0 -1
  154. package/build/esm/components/BackLink/__tests__/BackLink.test.js +0 -60
  155. package/build/esm/components/BlockBase/__tests__/BlockBase.test.d.ts +0 -1
  156. package/build/esm/components/BlockBase/__tests__/BlockBase.test.js +0 -41
  157. package/build/esm/components/Button/__tests__/Button.test.d.ts +0 -1
  158. package/build/esm/components/Button/__tests__/Button.test.js +0 -88
  159. package/build/esm/components/ButtonTabs/__tests__/ButtonTabs.test.d.ts +0 -1
  160. package/build/esm/components/ButtonTabs/__tests__/ButtonTabs.test.js +0 -55
  161. /package/build/{cjs/components/Anchor/__tests__/Anchor.test.d.ts → esm/editor/types/index.js} +0 -0
  162. /package/build/{cjs/components/AnimateBlock/__tests__/AnimateBlock.test.d.ts → esm/models/customization.js} +0 -0
@@ -0,0 +1,2 @@
1
+ export { Editor } from './Containers/Editor';
2
+ export * from './types';
@@ -0,0 +1,15 @@
1
+ import { Block } from '../../models';
2
+ import { EditorProps } from '../types';
3
+ export type EditorBlockId = number | string;
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
+ };
14
+ onAdd: (block: Block) => void;
15
+ };
@@ -0,0 +1,28 @@
1
+ import { useMemo, useReducer } from 'react';
2
+ import { HeaderBlockTypes } from '../../models';
3
+ import { getCustomHeaderTypes, getOrderedBlocks } from '../../utils';
4
+ import { ADD_BLOCK, COPY_BLOCK, DELETE_BLOCK, ORDER_BLOCK, SELECT_BLOCK, getReducer, } from './reducer';
5
+ import { addEditorProps } from './utils';
6
+ export function useEditorState({ content: intialContent, custom }) {
7
+ const headerBlockTypes = useMemo(() => [...HeaderBlockTypes, ...getCustomHeaderTypes(custom)], [custom]);
8
+ const reducer = useMemo(() => getReducer(headerBlockTypes), [headerBlockTypes]);
9
+ const [{ activeBlockId, content, orderedBlocksCount }, dispatch] = useReducer(reducer, {
10
+ activeBlockId: 0,
11
+ orderedBlocksCount: getOrderedBlocks(intialContent.blocks, headerBlockTypes).length,
12
+ content: addEditorProps(intialContent),
13
+ });
14
+ return useMemo(() => {
15
+ return {
16
+ content,
17
+ editControlsProps: {
18
+ activeBlockId,
19
+ orderedBlocksCount,
20
+ onDelete: (id) => dispatch({ type: DELETE_BLOCK, payload: id }),
21
+ onSelect: (id) => dispatch({ type: SELECT_BLOCK, payload: id }),
22
+ onCopy: (index) => dispatch({ type: COPY_BLOCK, payload: index }),
23
+ onOrderChange: (oldIndex, newIndex) => dispatch({ type: ORDER_BLOCK, payload: { oldIndex, newIndex } }),
24
+ },
25
+ onAdd: (block) => dispatch({ type: ADD_BLOCK, payload: block }),
26
+ };
27
+ }, [content, activeBlockId, orderedBlocksCount]);
28
+ }
@@ -0,0 +1,41 @@
1
+ import { Block, CustomConfig, PageContent } from '../../models';
2
+ export type EditorBlockId = number | string;
3
+ interface EditorState {
4
+ content: PageContent;
5
+ activeBlockId: EditorBlockId;
6
+ orderedBlocksCount: number;
7
+ custom?: CustomConfig;
8
+ }
9
+ interface OrderBlockParams {
10
+ oldIndex: number;
11
+ newIndex: number;
12
+ }
13
+ export declare const SELECT_BLOCK = "SELECT_BLOCK";
14
+ export declare const DELETE_BLOCK = "DELETE_BLOCK";
15
+ export declare const COPY_BLOCK = "COPY_BLOCK";
16
+ export declare const ADD_BLOCK = "ADD_BLOCK";
17
+ export declare const SET_REGION = "SET_REGION";
18
+ export declare const ORDER_BLOCK = "ORDER_BLOCK";
19
+ interface SelectBlock {
20
+ type: typeof SELECT_BLOCK;
21
+ payload: EditorBlockId;
22
+ }
23
+ interface DeleteBlock {
24
+ type: typeof DELETE_BLOCK;
25
+ payload: EditorBlockId;
26
+ }
27
+ interface CopyBlock {
28
+ type: typeof COPY_BLOCK;
29
+ payload: number;
30
+ }
31
+ interface AddBlock {
32
+ type: typeof ADD_BLOCK;
33
+ payload: Block;
34
+ }
35
+ interface OrderBlock {
36
+ type: typeof ORDER_BLOCK;
37
+ payload: OrderBlockParams;
38
+ }
39
+ export type EditorAction = SelectBlock | DeleteBlock | CopyBlock | AddBlock | OrderBlock;
40
+ export declare const getReducer: (headerBlockTypes: string[]) => (state: EditorState, action: EditorAction) => EditorState;
41
+ export {};
@@ -0,0 +1,55 @@
1
+ import { getHeaderBlock, getOrderedBlocks } from '../../utils';
2
+ import { addBlock, changeBlocksOrder, duplicateBlock, getNewBlockIndex } from './utils';
3
+ // actions
4
+ export const SELECT_BLOCK = 'SELECT_BLOCK';
5
+ export const DELETE_BLOCK = 'DELETE_BLOCK';
6
+ export const COPY_BLOCK = 'COPY_BLOCK';
7
+ export const ADD_BLOCK = 'ADD_BLOCK';
8
+ export const SET_REGION = 'SET_REGION';
9
+ export const ORDER_BLOCK = 'ORDER_BLOCK';
10
+ // reducer
11
+ export const getReducer = (headerBlockTypes) => (state, action) => {
12
+ const { content } = state;
13
+ const header = getHeaderBlock(content.blocks, headerBlockTypes);
14
+ const orderedBlocks = getOrderedBlocks(content.blocks, headerBlockTypes);
15
+ const withHeader = (blocks) => [header, ...blocks].filter(Boolean);
16
+ const getNewState = (blocks, activeBlockId) => (Object.assign(Object.assign({}, state), { content: Object.assign(Object.assign({}, content), { blocks }), activeBlockId, orderedBlocksCount: orderedBlocks.length }));
17
+ switch (action.type) {
18
+ case SELECT_BLOCK:
19
+ return getNewState(content.blocks, action.payload);
20
+ case DELETE_BLOCK: {
21
+ const blockId = action.payload;
22
+ return getNewState(typeof blockId === 'string'
23
+ ? content.blocks.filter(({ type }) => type !== blockId)
24
+ : withHeader(orderedBlocks.filter((_block, index) => index !== blockId)), -1);
25
+ }
26
+ case COPY_BLOCK: {
27
+ const index = action.payload;
28
+ return getNewState(withHeader(duplicateBlock(orderedBlocks, index)), index + 1);
29
+ }
30
+ case ADD_BLOCK: {
31
+ let blocks;
32
+ let activeBlockId;
33
+ const block = action.payload;
34
+ if (headerBlockTypes.includes(block.type)) {
35
+ blocks = header ? blocks : [block, ...orderedBlocks];
36
+ activeBlockId = block.type;
37
+ }
38
+ else {
39
+ const newBlockIndex = getNewBlockIndex(state.activeBlockId, orderedBlocks.length);
40
+ blocks = withHeader(addBlock(orderedBlocks, block, newBlockIndex));
41
+ activeBlockId = newBlockIndex;
42
+ }
43
+ if (blocks) {
44
+ return getNewState(blocks, activeBlockId);
45
+ }
46
+ return state;
47
+ }
48
+ case ORDER_BLOCK: {
49
+ const { oldIndex, newIndex } = action.payload;
50
+ return getNewState(withHeader(changeBlocksOrder(orderedBlocks, oldIndex, newIndex)), newIndex);
51
+ }
52
+ default:
53
+ return state;
54
+ }
55
+ };
@@ -0,0 +1,13 @@
1
+ import { Block, PageContent } from '../../models';
2
+ import { EditorBlockId } from './reducer';
3
+ export declare const changeBlocksOrder: (array: Block[], oldIndex: number, newIndex: number) => Block[];
4
+ export declare const duplicateBlock: (array: Block[], index: number) => Block[];
5
+ export declare const getNewBlockIndex: (id: EditorBlockId, orderedBlocksCount: number) => number;
6
+ export declare const addBlock: (array: Block[], block: Block, index: number) => Block[];
7
+ export declare const addEditorProps: (content: PageContent) => {
8
+ animated: boolean;
9
+ blocks: Block[];
10
+ menu?: import("../../models").Menu | undefined;
11
+ background?: import("../../models").ThemedMediaProps | undefined;
12
+ footnotes?: string[] | undefined;
13
+ };
@@ -0,0 +1,26 @@
1
+ export const changeBlocksOrder = (array, oldIndex, newIndex) => {
2
+ const result = [...array];
3
+ const element = result.splice(oldIndex, 1)[0];
4
+ result.splice(newIndex, 0, element);
5
+ return result;
6
+ };
7
+ export const duplicateBlock = (array, index) => {
8
+ const result = [...array];
9
+ result.splice(index + 1, 0, result[index]);
10
+ return result;
11
+ };
12
+ export const getNewBlockIndex = (id, orderedBlocksCount) => {
13
+ if (id === -1) {
14
+ return orderedBlocksCount;
15
+ }
16
+ // id === 'string' - header block
17
+ return typeof id === 'string' ? 0 : id + 1;
18
+ };
19
+ export const addBlock = (array, block, index) => {
20
+ const result = [...array];
21
+ result.splice(index, 0, block);
22
+ return result;
23
+ };
24
+ export const addEditorProps = (content) => {
25
+ return Object.assign(Object.assign({}, content), { animated: false });
26
+ };
File without changes
File without changes
@@ -0,0 +1,17 @@
1
+ /// <reference types="react" />
2
+ import { PageConstructorProps } from '../../containers/PageConstructor';
3
+ import { BlockDecoratorProps, PageData } from '../../models';
4
+ export type EditorBlockId = number | string;
5
+ export interface EditorProps extends Required<Pick<PageConstructorProps, 'content'>>, Partial<Omit<PageConstructorProps, 'content'>> {
6
+ children: (props: Partial<PageConstructorProps>) => React.ReactNode;
7
+ onChange?: (data: PageData) => void;
8
+ }
9
+ 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;
16
+ }
17
+ export type EditBlockProps = EditBlockEditorProps & BlockDecoratorProps;
@@ -0,0 +1,11 @@
1
+ import { BlockDecorator, CustomConfig } from '../../models';
2
+ export declare const formatBlockName: (name: string) => string;
3
+ export declare const addCustomDecorator: (decorator: BlockDecorator, custom?: CustomConfig) => {
4
+ decorators: {
5
+ block: ((props: import("../../models").BlockDecoratorProps) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>)[];
6
+ };
7
+ blocks?: import("../../models").CustomItems | undefined;
8
+ subBlocks?: import("../../models").CustomItems | undefined;
9
+ headers?: import("../../models").CustomItems | undefined;
10
+ loadable?: import("../../models").LoadableConfig | undefined;
11
+ };
@@ -0,0 +1,6 @@
1
+ import _ from 'lodash';
2
+ export const formatBlockName = (name) => _.capitalize(name).replace(/(block|-)/g, ' ');
3
+ export const addCustomDecorator = (decorator, custom = {}) => {
4
+ const decorators = custom.decorators || {};
5
+ return Object.assign(Object.assign({}, custom), { decorators: Object.assign(Object.assign({}, decorators), { block: [...(decorators.block || []), decorator] }) });
6
+ };
@@ -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" | "dataQa" | "reset" | "visible" | "sizes" | "offsets" | "orders" | "hidden" | "alignSelf" | "justifyContent"> & React.RefAttributes<HTMLDivElement>>;
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>>;
@@ -1,6 +1,5 @@
1
1
  import { useContext } from 'react';
2
2
  import { MetrikaContext } from '../context/metrikaContext';
3
- import { PixelEventType } from '../models';
4
3
  import { isNewMetrikaFormat } from '../models/guards';
5
4
  // eslint-disable-next-line valid-jsdoc
6
5
  /**
@@ -26,12 +25,6 @@ export const useMetrika = () => {
26
25
  else {
27
26
  metrika.reachGoals(metrikaGoals);
28
27
  }
29
- if (!pixelEvents && pixel) {
30
- pixel.trackStandard(PixelEventType.SubmitApplication, {
31
- content_category: 'custom',
32
- content_ids: Array.isArray(metrikaGoals) ? metrikaGoals : [metrikaGoals],
33
- });
34
- }
35
28
  }
36
29
  if (pixel && pixelEvents) {
37
30
  if (isButtonPixel(pixelEvents)) {
@@ -10,22 +10,17 @@ declare module '*.svg' {
10
10
  export default path;
11
11
  }
12
12
 
13
- interface CreateFormProps {
14
- portalId: string;
15
- formId: string;
16
- region?: string;
17
- target?: string;
18
- cssClass?: string;
19
- formInstanceId?: string;
20
- }
13
+ declare module '*.md';
21
14
 
22
- interface Window {
23
- hbspt?: {
24
- forms: {
25
- create: (args: CreateFormProps) => unknown;
26
- };
27
- };
28
- ymaps: Ymaps;
15
+ declare namespace Hbspt {
16
+ interface CreateFormProps {
17
+ portalId: string;
18
+ formId: string;
19
+ region?: string;
20
+ target?: string;
21
+ cssClass?: string;
22
+ formInstanceId?: string;
23
+ }
29
24
  }
30
25
 
31
26
  declare namespace Ymaps {
@@ -63,4 +58,11 @@ declare namespace Ymaps {
63
58
  }
64
59
  }
65
60
 
66
- declare module '*.md';
61
+ interface Window {
62
+ hbspt?: {
63
+ forms: {
64
+ create: (args: Hbspt.CreateFormProps) => unknown;
65
+ };
66
+ };
67
+ ymaps: Ymaps;
68
+ }
@@ -8,8 +8,6 @@ export declare enum BlockType {
8
8
  PromoFeaturesBlock = "promo-features-block",
9
9
  ExtendedFeaturesBlock = "extended-features-block",
10
10
  SliderBlock = "slider-block",
11
- CalculatorBlock = "calculator-block",
12
- ServiceDemoBlock = "service-demo-block",
13
11
  QuestionsBlock = "questions-block",
14
12
  BannerBlock = "banner-block",
15
13
  CompaniesBlock = "companies-block",
@@ -52,7 +50,6 @@ export interface LoadableProps {
52
50
  export interface LoadableChildren {
53
51
  loadable?: LoadableProps;
54
52
  }
55
- export type ServiceDemoProps = Animatable;
56
53
  export declare enum SliderBreakpointNames {
57
54
  Sm = "sm",
58
55
  Md = "md",
@@ -114,7 +111,6 @@ export interface HeaderBlockProps {
114
111
  breadcrumbs?: HeaderBreadCrumbsProps;
115
112
  status?: JSX.Element;
116
113
  }
117
- export type CalculatorProps = Animatable;
118
114
  export interface SimpleBlockProps extends Animatable, Childable {
119
115
  title: TitleBaseProps;
120
116
  description: string;
@@ -317,15 +313,9 @@ export interface ShareBlockProps {
317
313
  export type HeaderBlockModel = {
318
314
  type: BlockType.HeaderBlock;
319
315
  } & HeaderBlockProps;
320
- export type CalculatorBlockModel = {
321
- type: BlockType.CalculatorBlock;
322
- } & CalculatorProps;
323
316
  export type SliderBlockModel = {
324
317
  type: BlockType.SliderBlock;
325
318
  } & SliderProps;
326
- export type ServiceDemoBlockModel = {
327
- type: BlockType.ServiceDemoBlock;
328
- } & ServiceDemoProps;
329
319
  export type ExtendedFeaturesBlockModel = {
330
320
  type: BlockType.ExtendedFeaturesBlock;
331
321
  } & ExtendedFeaturesProps;
@@ -386,6 +376,6 @@ export type ContentLayoutBlockModel = {
386
376
  export type ShareBLockModel = {
387
377
  type: BlockType.ShareBlock;
388
378
  } & ShareBlockProps;
389
- type BlockModels = SliderBlockModel | ServiceDemoBlockModel | ExtendedFeaturesBlockModel | PromoFeaturesBlockModel | QuestionsBlockModel | CalculatorBlockModel | BannerBlockModel | CompaniesBlockModel | MediaBlockModel | MapBlockModel | InfoBlockModel | SecurityBlockModel | TableBlockModel | TabsBlockModel | SimpleBlockModel | LinkTableBlockModel | HeaderBlockModel | PreviewBlockModel | IconsBlockModel | HeaderSliderBlockModel | CardLayoutBlockModel | ContentLayoutBlockModel | ShareBLockModel | FilterBlockModel;
379
+ type BlockModels = SliderBlockModel | ExtendedFeaturesBlockModel | PromoFeaturesBlockModel | QuestionsBlockModel | BannerBlockModel | CompaniesBlockModel | MediaBlockModel | MapBlockModel | InfoBlockModel | SecurityBlockModel | TableBlockModel | TabsBlockModel | SimpleBlockModel | LinkTableBlockModel | HeaderBlockModel | PreviewBlockModel | IconsBlockModel | HeaderSliderBlockModel | CardLayoutBlockModel | ContentLayoutBlockModel | ShareBLockModel | FilterBlockModel;
390
380
  export type Block = BlockModels & BlockBaseProps;
391
381
  export {};
@@ -3,8 +3,6 @@ export var BlockType;
3
3
  BlockType["PromoFeaturesBlock"] = "promo-features-block";
4
4
  BlockType["ExtendedFeaturesBlock"] = "extended-features-block";
5
5
  BlockType["SliderBlock"] = "slider-block";
6
- BlockType["CalculatorBlock"] = "calculator-block";
7
- BlockType["ServiceDemoBlock"] = "service-demo-block";
8
6
  BlockType["QuestionsBlock"] = "questions-block";
9
7
  BlockType["BannerBlock"] = "banner-block";
10
8
  BlockType["CompaniesBlock"] = "companies-block";
@@ -1,5 +1,5 @@
1
1
  import { CSSProperties, ReactNode } from 'react';
2
- import { ButtonSize, ButtonView } from '@gravity-ui/uikit';
2
+ import { ButtonView, ButtonProps as UikitButtonProps } from '@gravity-ui/uikit';
3
3
  import { ThemeSupporting } from '../../utils/theme';
4
4
  import { AnalyticsEventsBase, ClassNameProps, PixelEventType } from '../common';
5
5
  export declare enum AuthorType {
@@ -99,6 +99,7 @@ export interface BackgroundImageProps extends React.HTMLProps<HTMLDivElement>, P
99
99
  style?: CSSProperties;
100
100
  imageClassName?: string;
101
101
  hide?: boolean;
102
+ qa?: string;
102
103
  }
103
104
  export interface MediaVideoProps extends AnalyticsEventsBase {
104
105
  src: string[];
@@ -131,11 +132,10 @@ export interface FileLinkProps extends ClassNameProps {
131
132
  onClick?: () => void;
132
133
  }
133
134
  export type ButtonTheme = ButtonView | 'github' | 'app-store' | 'google-play' | 'scale' | 'monochrome';
134
- export interface ButtonProps extends AnalyticsEventsBase {
135
+ export interface ButtonProps extends AnalyticsEventsBase, Pick<UikitButtonProps, 'size' | 'width'> {
135
136
  text: string;
136
137
  url: string;
137
138
  primary?: boolean;
138
- size?: ButtonSize;
139
139
  theme?: ButtonTheme;
140
140
  img?: ButtonImageProps | string;
141
141
  metrikaGoals?: MetrikaGoal;
@@ -1,5 +1,5 @@
1
1
  import React, { PropsWithChildren } from 'react';
2
- import { Animatable, Block, ConstructorItem, ThemedMediaProps, WithChildren } from './';
2
+ import { Animatable, Block, BlockDecoratorProps, ConstructorItem, ThemedMediaProps, WithChildren } from './';
3
3
  export interface PageData {
4
4
  content: PageContent;
5
5
  }
@@ -41,5 +41,8 @@ export interface CustomConfig {
41
41
  subBlocks?: CustomItems;
42
42
  headers?: CustomItems;
43
43
  loadable?: LoadableConfig;
44
+ decorators?: {
45
+ block?: ((props: BlockDecoratorProps) => React.ReactElement)[];
46
+ };
44
47
  }
45
48
  export {};
@@ -0,0 +1,9 @@
1
+ import { PropsWithChildren } from 'react';
2
+ export interface BlockDecorationProps extends PropsWithChildren {
3
+ id?: string;
4
+ }
5
+ export interface BlockDecoratorProps extends PropsWithChildren {
6
+ id: string | number;
7
+ isHeader?: boolean;
8
+ }
9
+ export type BlockDecorator = (props: BlockDecoratorProps) => React.ReactElement;
@@ -5,3 +5,4 @@ export * from './components';
5
5
  export * from './guards';
6
6
  export * from './react';
7
7
  export * from './navigation';
8
+ export * from './customization';
@@ -5,3 +5,4 @@ export * from './components';
5
5
  export * from './guards';
6
6
  export * from './react';
7
7
  export * from './navigation';
8
+ export * from './customization';
@@ -1,5 +1,6 @@
1
+ import React from 'react';
1
2
  import { HubspotFormProps } from '../../models';
2
3
  type HubspotFormContainerPropsKeys = 'className' | 'formId' | 'formInstanceId' | 'portalId' | 'region' | 'formClassName' | 'createDOMElement';
3
4
  type HubspotFormContainerProps = Pick<HubspotFormProps, HubspotFormContainerPropsKeys>;
4
- declare const HubspotFormContainer: (props: HubspotFormContainerProps) => JSX.Element;
5
+ declare const HubspotFormContainer: React.ForwardRefExoticComponent<HubspotFormContainerProps & React.RefAttributes<HTMLDivElement>>;
5
6
  export default HubspotFormContainer;
@@ -1,10 +1,12 @@
1
- import React, { useRef } from 'react';
1
+ import React, { forwardRef, useImperativeHandle, useRef } from 'react';
2
2
  import { useMount } from '../../hooks';
3
3
  import loadHubspotScript from './loadHubspotScript';
4
- const HubspotFormContainer = (props) => {
4
+ const HubspotFormContainer = forwardRef((props, ref) => {
5
5
  const { className, formId, formInstanceId, portalId, region, formClassName, createDOMElement, } = props;
6
6
  const containerRef = useRef(null);
7
7
  const hsContainerRef = useRef();
8
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
9
+ useImperativeHandle(ref, () => containerRef.current);
8
10
  const containerId = formInstanceId
9
11
  ? `hubspot-form-${formId}-${formInstanceId}`
10
12
  : `hubspot-form-${formId}`;
@@ -42,5 +44,6 @@ const HubspotFormContainer = (props) => {
42
44
  };
43
45
  });
44
46
  return React.createElement("div", { className: className, id: containerId, ref: containerRef });
45
- };
47
+ });
48
+ HubspotFormContainer.displayName = 'HubspotFormContainer';
46
49
  export default HubspotFormContainer;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
2
  import { HubspotFormProps } from '../../models';
3
3
  import './HubspotForm.css';
4
- declare const HubspotForm: React.FunctionComponent<HubspotFormProps>;
4
+ declare const HubspotForm: React.ForwardRefExoticComponent<HubspotFormProps & React.RefAttributes<HTMLDivElement>>;
5
5
  export default HubspotForm;
@@ -1,4 +1,4 @@
1
- import React, { useContext, useMemo } from 'react';
1
+ import React, { forwardRef, useContext, useMemo } from 'react';
2
2
  import { MobileContext } from '../../context/mobileContext';
3
3
  import { ThemeValueContext } from '../../context/theme/ThemeValueContext';
4
4
  import { useAnalytics, useHandleHubspotEvents } from '../../hooks';
@@ -8,7 +8,7 @@ import { block } from '../../utils';
8
8
  import HubspotFormContainer from './HubspotFormContainer';
9
9
  import './HubspotForm.css';
10
10
  const b = block('hubspot-form');
11
- const HubspotForm = (props) => {
11
+ const HubspotForm = forwardRef((props, ref) => {
12
12
  const { className, theme: themeProp, isMobile: isMobileProp, formId, formInstanceId, portalId, region, formClassName, pixelEvents,
13
13
  // hubspotEvents, // TODO: decide how to handle them
14
14
  analyticsEvents, onBeforeSubmit, onSubmit, onBeforeLoad, onLoad, createDOMElement, onSubmitError, } = props;
@@ -23,10 +23,10 @@ const HubspotForm = (props) => {
23
23
  onBeforeSubmit,
24
24
  onLoad,
25
25
  onSubmitError,
26
- onSubmit: (e) => {
26
+ onSubmit: (event) => {
27
27
  handleMetrika === null || handleMetrika === void 0 ? void 0 : handleMetrika({ pixelEvents });
28
28
  handleAnalytics(analyticsEvents);
29
- onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(e);
29
+ onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(event);
30
30
  },
31
31
  }), [
32
32
  onBeforeLoad,
@@ -40,6 +40,7 @@ const HubspotForm = (props) => {
40
40
  onSubmitError,
41
41
  ]);
42
42
  useHandleHubspotEvents(handlers, formId);
43
- return (React.createElement(HubspotFormContainer, { createDOMElement: createDOMElement, key: [formClassName, formId, formInstanceId, portalId, region].join(), className: b({ theme, mobile }, className), formClassName: formClassName, formId: formId, portalId: portalId, formInstanceId: formInstanceId, region: region }));
44
- };
43
+ return (React.createElement(HubspotFormContainer, { createDOMElement: createDOMElement, key: [formClassName, formId, formInstanceId, portalId, region].join(), className: b({ theme, mobile }, className), formClassName: formClassName, formId: formId, portalId: portalId, formInstanceId: formInstanceId, region: region, ref: ref }));
44
+ });
45
+ HubspotForm.displayName = 'HubspotForm';
45
46
  export default HubspotForm;
@@ -1,4 +1,4 @@
1
- import { CustomConfig, PCShareSocialNetwork, TextSize } from '../models';
1
+ import { Block, CustomConfig, PCShareSocialNetwork, TextSize } from '../models';
2
2
  import { ConstructorBlock } from '../models/constructor';
3
3
  export declare function getHeaderTag(size: TextSize): "h1" | "h2" | "h4" | "h5";
4
4
  export declare function getBlockKey(block: ConstructorBlock, index: number): string;
@@ -8,4 +8,7 @@ export declare const getCustomItems: ({ blocks, headers, subBlocks }?: CustomCon
8
8
  };
9
9
  export declare const getCustomSubBlockTypes: (customBlocks?: CustomConfig) => string[];
10
10
  export declare const getCustomHeaderTypes: (customBlocks?: CustomConfig) => string[];
11
+ export declare const getOrderedBlocks: (blocks: Block[], headerBlockTypes?: string[]) => Block[];
12
+ export declare const getHeaderBlock: (blocks: Block[], headerBlockTypes?: string[]) => Block | undefined;
11
13
  export declare const getShareLink: (url: string, type: PCShareSocialNetwork, title?: string, text?: string) => string | undefined;
14
+ export declare const getBlockIndexFromId: (blockId?: string) => number;
@@ -37,6 +37,12 @@ const getShareUrlWithParams = (url, params = {}) => {
37
37
  });
38
38
  return result.toString();
39
39
  };
40
+ export const getOrderedBlocks = (blocks, headerBlockTypes = []) => {
41
+ return blocks.filter(({ type }) => !headerBlockTypes.includes(type));
42
+ };
43
+ export const getHeaderBlock = (blocks, headerBlockTypes = []) => {
44
+ return blocks.find(({ type }) => headerBlockTypes.includes(type));
45
+ };
40
46
  export const getShareLink = (url, type, title, text) => {
41
47
  // https://github.com/bradvin/social-share-urls
42
48
  switch (type) {
@@ -65,3 +71,4 @@ export const getShareLink = (url, type, title, text) => {
65
71
  return undefined;
66
72
  }
67
73
  };
74
+ export const getBlockIndexFromId = (blockId) => { var _a; return Number((_a = blockId === null || blockId === void 0 ? void 0 : blockId.split('-')) === null || _a === void 0 ? void 0 : _a.slice(-1).pop()); };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/page-constructor",
3
- "version": "2.22.0-alpha",
3
+ "version": "2.22.0-alpha.0",
4
4
  "description": "Gravity UI Page Constructor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -61,15 +61,16 @@
61
61
  "uuid": "^9.0.0"
62
62
  },
63
63
  "peerDependencies": {
64
- "react": "^16.0.0 || ^17.0.0 || ^18.0.0",
64
+ "@doc-tools/transform": "^2.6.1",
65
65
  "@gravity-ui/uikit": "^4.1.0",
66
- "@doc-tools/transform": "^2.6.1"
66
+ "react": "^16.0.0 || ^17.0.0 || ^18.0.0"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@commitlint/cli": "^17.1.2",
70
70
  "@commitlint/config-conventional": "^17.1.0",
71
71
  "@doc-tools/transform": "2.12.0",
72
72
  "@gravity-ui/eslint-config": "^2.0.0",
73
+ "@gravity-ui/icons": "^2.1.0",
73
74
  "@gravity-ui/prettier-config": "^1.0.1",
74
75
  "@gravity-ui/stylelint-config": "^1.0.0",
75
76
  "@gravity-ui/tsconfig": "^1.0.0",
@@ -8,8 +8,6 @@ export declare enum BlockType {
8
8
  PromoFeaturesBlock = "promo-features-block",
9
9
  ExtendedFeaturesBlock = "extended-features-block",
10
10
  SliderBlock = "slider-block",
11
- CalculatorBlock = "calculator-block",
12
- ServiceDemoBlock = "service-demo-block",
13
11
  QuestionsBlock = "questions-block",
14
12
  BannerBlock = "banner-block",
15
13
  CompaniesBlock = "companies-block",
@@ -52,7 +50,6 @@ export interface LoadableProps {
52
50
  export interface LoadableChildren {
53
51
  loadable?: LoadableProps;
54
52
  }
55
- export type ServiceDemoProps = Animatable;
56
53
  export declare enum SliderBreakpointNames {
57
54
  Sm = "sm",
58
55
  Md = "md",
@@ -114,7 +111,6 @@ export interface HeaderBlockProps {
114
111
  breadcrumbs?: HeaderBreadCrumbsProps;
115
112
  status?: JSX.Element;
116
113
  }
117
- export type CalculatorProps = Animatable;
118
114
  export interface SimpleBlockProps extends Animatable, Childable {
119
115
  title: TitleBaseProps;
120
116
  description: string;
@@ -317,15 +313,9 @@ export interface ShareBlockProps {
317
313
  export type HeaderBlockModel = {
318
314
  type: BlockType.HeaderBlock;
319
315
  } & HeaderBlockProps;
320
- export type CalculatorBlockModel = {
321
- type: BlockType.CalculatorBlock;
322
- } & CalculatorProps;
323
316
  export type SliderBlockModel = {
324
317
  type: BlockType.SliderBlock;
325
318
  } & SliderProps;
326
- export type ServiceDemoBlockModel = {
327
- type: BlockType.ServiceDemoBlock;
328
- } & ServiceDemoProps;
329
319
  export type ExtendedFeaturesBlockModel = {
330
320
  type: BlockType.ExtendedFeaturesBlock;
331
321
  } & ExtendedFeaturesProps;
@@ -386,6 +376,6 @@ export type ContentLayoutBlockModel = {
386
376
  export type ShareBLockModel = {
387
377
  type: BlockType.ShareBlock;
388
378
  } & ShareBlockProps;
389
- type BlockModels = SliderBlockModel | ServiceDemoBlockModel | ExtendedFeaturesBlockModel | PromoFeaturesBlockModel | QuestionsBlockModel | CalculatorBlockModel | BannerBlockModel | CompaniesBlockModel | MediaBlockModel | MapBlockModel | InfoBlockModel | SecurityBlockModel | TableBlockModel | TabsBlockModel | SimpleBlockModel | LinkTableBlockModel | HeaderBlockModel | PreviewBlockModel | IconsBlockModel | HeaderSliderBlockModel | CardLayoutBlockModel | ContentLayoutBlockModel | ShareBLockModel | FilterBlockModel;
379
+ type BlockModels = SliderBlockModel | ExtendedFeaturesBlockModel | PromoFeaturesBlockModel | QuestionsBlockModel | BannerBlockModel | CompaniesBlockModel | MediaBlockModel | MapBlockModel | InfoBlockModel | SecurityBlockModel | TableBlockModel | TabsBlockModel | SimpleBlockModel | LinkTableBlockModel | HeaderBlockModel | PreviewBlockModel | IconsBlockModel | HeaderSliderBlockModel | CardLayoutBlockModel | ContentLayoutBlockModel | ShareBLockModel | FilterBlockModel;
390
380
  export type Block = BlockModels & BlockBaseProps;
391
381
  export {};
@@ -6,8 +6,6 @@ var BlockType;
6
6
  BlockType["PromoFeaturesBlock"] = "promo-features-block";
7
7
  BlockType["ExtendedFeaturesBlock"] = "extended-features-block";
8
8
  BlockType["SliderBlock"] = "slider-block";
9
- BlockType["CalculatorBlock"] = "calculator-block";
10
- BlockType["ServiceDemoBlock"] = "service-demo-block";
11
9
  BlockType["QuestionsBlock"] = "questions-block";
12
10
  BlockType["BannerBlock"] = "banner-block";
13
11
  BlockType["CompaniesBlock"] = "companies-block";