@gravity-ui/page-constructor 1.15.0-alpha.13 → 1.15.0-alpha.14

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.
@@ -11,13 +11,14 @@ const ConstructorItem_1 = require("../ConstructorItem");
11
11
  const ConstructorBlock_1 = require("../ConstructorBlock/ConstructorBlock");
12
12
  const ConstructorBlocks = ({ items, shouldRenderBlock }) => {
13
13
  const { blockTypes, loadables, itemMap } = (0, react_1.useContext)(innerContext_1.InnerContext);
14
- const renderer = (item, index) => {
14
+ const renderer = (parentContext = '', item, index) => {
15
15
  if (!itemMap[item.type]) {
16
16
  return null;
17
17
  }
18
18
  let children;
19
19
  let itemElement;
20
20
  const key = (0, utils_1.getBlockKey)(item, index);
21
+ const context = (0, utils_1.getBlockContext)({ parentContext, block: item, index });
21
22
  if (shouldRenderBlock && !shouldRenderBlock(item, key)) {
22
23
  return null;
23
24
  }
@@ -31,12 +32,12 @@ const ConstructorBlocks = ({ items, shouldRenderBlock }) => {
31
32
  }
32
33
  else {
33
34
  if ('children' in item && item.children) {
34
- children = item.children.map(renderer);
35
+ children = item.children.map(renderer.bind(null, parentContext));
35
36
  }
36
- itemElement = (react_1.default.createElement(ConstructorItem_1.ConstructorItem, { data: item, key: key }, children));
37
+ itemElement = (react_1.default.createElement(ConstructorItem_1.ConstructorItem, { data: item, key: key, context: context }, children));
37
38
  }
38
39
  return blockTypes.includes(item.type) ? (react_1.default.createElement(ConstructorBlock_1.ConstructorBlock, { data: item, key: key, Component: itemElement })) : (itemElement);
39
40
  };
40
- return react_1.default.createElement(react_1.Fragment, null, items.map(renderer));
41
+ return react_1.default.createElement(react_1.Fragment, null, items.map(renderer.bind(null, '')));
41
42
  };
42
43
  exports.ConstructorBlocks = ConstructorBlocks;
@@ -1,6 +1,7 @@
1
1
  import { ConstructorItem as ConstructorItemType, WithChildren } from '../../../../models';
2
2
  export interface ConstructorItemProps {
3
3
  data: ConstructorItemType;
4
+ context?: string;
4
5
  }
5
- export declare const ConstructorItem: ({ data, children }: WithChildren<ConstructorItemProps>) => JSX.Element;
6
+ export declare const ConstructorItem: ({ data, children, context, }: WithChildren<ConstructorItemProps>) => JSX.Element;
6
7
  export declare const ConstructorHeader: ({ data }: Pick<ConstructorItemProps, 'data'>) => JSX.Element;
@@ -4,11 +4,12 @@ exports.ConstructorHeader = exports.ConstructorItem = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importStar(require("react"));
6
6
  const innerContext_1 = require("../../../../context/innerContext");
7
- const ConstructorItem = ({ data, children }) => {
7
+ const ConstructorItem = ({ data, children, context = '', }) => {
8
8
  const { itemMap } = (0, react_1.useContext)(innerContext_1.InnerContext);
9
- const { type } = data, rest = tslib_1.__rest(data, ["type"]);
9
+ const { type } = data;
10
+ const localContext = context + type ? `_${type}` : '';
10
11
  const Component = itemMap[type];
11
- return react_1.default.createElement(Component, Object.assign({}, rest), children);
12
+ return (react_1.default.createElement(Component, Object.assign({}, data, { context: localContext }), children));
12
13
  };
13
14
  exports.ConstructorItem = ConstructorItem;
14
15
  const ConstructorHeader = ({ data }) => (react_1.default.createElement(exports.ConstructorItem, { data: data, key: data.type }));
@@ -2,9 +2,16 @@ import { ConstructorBlock } from '../models/constructor';
2
2
  import { TextSize, CustomConfig, PCShareSocialNetwork } from '../models';
3
3
  export declare function getHeaderTag(size: TextSize): "h1" | "h4" | "h2";
4
4
  export declare function getBlockKey(block: ConstructorBlock, index: number): string;
5
+ type GetBlockContextArgs = {
6
+ block: ConstructorBlock;
7
+ index: number;
8
+ parentContext?: string;
9
+ };
10
+ export declare function getBlockContext({ parentContext, block, index }: GetBlockContextArgs): string;
5
11
  export declare const getCustomBlockTypes: ({ blocks, headers }?: CustomConfig) => string[];
6
12
  export declare const getCustomItems: ({ blocks, headers, subBlocks }?: CustomConfig) => {
7
13
  [x: string]: any;
8
14
  };
9
15
  export declare const getCustomHeaderTypes: (customBlocks?: CustomConfig) => string[];
10
16
  export declare const getShareLink: (url: string, type: PCShareSocialNetwork, title?: string, text?: string) => string | undefined;
17
+ export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getShareLink = exports.getCustomHeaderTypes = exports.getCustomItems = exports.getCustomBlockTypes = exports.getBlockKey = exports.getHeaderTag = void 0;
3
+ exports.getShareLink = exports.getCustomHeaderTypes = exports.getCustomItems = exports.getCustomBlockTypes = exports.getBlockContext = exports.getBlockKey = exports.getHeaderTag = void 0;
4
4
  const models_1 = require("../models");
5
5
  function getHeaderTag(size) {
6
6
  switch (size) {
@@ -18,6 +18,10 @@ function getBlockKey(block, index) {
18
18
  return `${block.type}-${index}`;
19
19
  }
20
20
  exports.getBlockKey = getBlockKey;
21
+ function getBlockContext({ parentContext = '', block, index }) {
22
+ return `${parentContext}${parentContext ? '-' : ''}${block.type}-${index}`;
23
+ }
24
+ exports.getBlockContext = getBlockContext;
21
25
  const getCustomBlockTypes = ({ blocks = {}, headers = {} } = {}) => [
22
26
  ...Object.keys(blocks),
23
27
  ...Object.keys(headers),
@@ -1,19 +1,20 @@
1
1
  import _ from 'lodash';
2
2
  import React, { Fragment, useContext } from 'react';
3
- import { getBlockKey } from '../../../../utils';
3
+ import { getBlockContext, getBlockKey } from '../../../../utils';
4
4
  import { InnerContext } from '../../../../context/innerContext';
5
5
  import { ConstructorLoadable } from '../ConstructorLoadable';
6
6
  import { ConstructorItem } from '../ConstructorItem';
7
7
  import { ConstructorBlock } from '../ConstructorBlock/ConstructorBlock';
8
8
  export const ConstructorBlocks = ({ items, shouldRenderBlock }) => {
9
9
  const { blockTypes, loadables, itemMap } = useContext(InnerContext);
10
- const renderer = (item, index) => {
10
+ const renderer = (parentContext = '', item, index) => {
11
11
  if (!itemMap[item.type]) {
12
12
  return null;
13
13
  }
14
14
  let children;
15
15
  let itemElement;
16
16
  const key = getBlockKey(item, index);
17
+ const context = getBlockContext({ parentContext, block: item, index });
17
18
  if (shouldRenderBlock && !shouldRenderBlock(item, key)) {
18
19
  return null;
19
20
  }
@@ -27,11 +28,11 @@ export const ConstructorBlocks = ({ items, shouldRenderBlock }) => {
27
28
  }
28
29
  else {
29
30
  if ('children' in item && item.children) {
30
- children = item.children.map(renderer);
31
+ children = item.children.map(renderer.bind(null, parentContext));
31
32
  }
32
- itemElement = (React.createElement(ConstructorItem, { data: item, key: key }, children));
33
+ itemElement = (React.createElement(ConstructorItem, { data: item, key: key, context: context }, children));
33
34
  }
34
35
  return blockTypes.includes(item.type) ? (React.createElement(ConstructorBlock, { data: item, key: key, Component: itemElement })) : (itemElement);
35
36
  };
36
- return React.createElement(Fragment, null, items.map(renderer));
37
+ return React.createElement(Fragment, null, items.map(renderer.bind(null, '')));
37
38
  };
@@ -1,6 +1,7 @@
1
1
  import { ConstructorItem as ConstructorItemType, WithChildren } from '../../../../models';
2
2
  export interface ConstructorItemProps {
3
3
  data: ConstructorItemType;
4
+ context?: string;
4
5
  }
5
- export declare const ConstructorItem: ({ data, children }: WithChildren<ConstructorItemProps>) => JSX.Element;
6
+ export declare const ConstructorItem: ({ data, children, context, }: WithChildren<ConstructorItemProps>) => JSX.Element;
6
7
  export declare const ConstructorHeader: ({ data }: Pick<ConstructorItemProps, 'data'>) => JSX.Element;
@@ -1,10 +1,10 @@
1
- import { __rest } from "tslib";
2
1
  import React, { useContext } from 'react';
3
2
  import { InnerContext } from '../../../../context/innerContext';
4
- export const ConstructorItem = ({ data, children }) => {
3
+ export const ConstructorItem = ({ data, children, context = '', }) => {
5
4
  const { itemMap } = useContext(InnerContext);
6
- const { type } = data, rest = __rest(data, ["type"]);
5
+ const { type } = data;
6
+ const localContext = context + type ? `_${type}` : '';
7
7
  const Component = itemMap[type];
8
- return React.createElement(Component, Object.assign({}, rest), children);
8
+ return (React.createElement(Component, Object.assign({}, data, { context: localContext }), children));
9
9
  };
10
10
  export const ConstructorHeader = ({ data }) => (React.createElement(ConstructorItem, { data: data, key: data.type }));
@@ -2,9 +2,16 @@ import { ConstructorBlock } from '../models/constructor';
2
2
  import { TextSize, CustomConfig, PCShareSocialNetwork } from '../models';
3
3
  export declare function getHeaderTag(size: TextSize): "h1" | "h4" | "h2";
4
4
  export declare function getBlockKey(block: ConstructorBlock, index: number): string;
5
+ type GetBlockContextArgs = {
6
+ block: ConstructorBlock;
7
+ index: number;
8
+ parentContext?: string;
9
+ };
10
+ export declare function getBlockContext({ parentContext, block, index }: GetBlockContextArgs): string;
5
11
  export declare const getCustomBlockTypes: ({ blocks, headers }?: CustomConfig) => string[];
6
12
  export declare const getCustomItems: ({ blocks, headers, subBlocks }?: CustomConfig) => {
7
13
  [x: string]: any;
8
14
  };
9
15
  export declare const getCustomHeaderTypes: (customBlocks?: CustomConfig) => string[];
10
16
  export declare const getShareLink: (url: string, type: PCShareSocialNetwork, title?: string, text?: string) => string | undefined;
17
+ export {};
@@ -13,6 +13,9 @@ export function getHeaderTag(size) {
13
13
  export function getBlockKey(block, index) {
14
14
  return `${block.type}-${index}`;
15
15
  }
16
+ export function getBlockContext({ parentContext = '', block, index }) {
17
+ return `${parentContext}${parentContext ? '-' : ''}${block.type}-${index}`;
18
+ }
16
19
  export const getCustomBlockTypes = ({ blocks = {}, headers = {} } = {}) => [
17
20
  ...Object.keys(blocks),
18
21
  ...Object.keys(headers),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/page-constructor",
3
- "version": "1.15.0-alpha.13",
3
+ "version": "1.15.0-alpha.14",
4
4
  "description": "Gravity UI Page Constructor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -2,9 +2,16 @@ import { ConstructorBlock } from '../models/constructor';
2
2
  import { TextSize, CustomConfig, PCShareSocialNetwork } from '../models';
3
3
  export declare function getHeaderTag(size: TextSize): "h1" | "h4" | "h2";
4
4
  export declare function getBlockKey(block: ConstructorBlock, index: number): string;
5
+ type GetBlockContextArgs = {
6
+ block: ConstructorBlock;
7
+ index: number;
8
+ parentContext?: string;
9
+ };
10
+ export declare function getBlockContext({ parentContext, block, index }: GetBlockContextArgs): string;
5
11
  export declare const getCustomBlockTypes: ({ blocks, headers }?: CustomConfig) => string[];
6
12
  export declare const getCustomItems: ({ blocks, headers, subBlocks }?: CustomConfig) => {
7
13
  [x: string]: any;
8
14
  };
9
15
  export declare const getCustomHeaderTypes: (customBlocks?: CustomConfig) => string[];
10
16
  export declare const getShareLink: (url: string, type: PCShareSocialNetwork, title?: string, text?: string) => string | undefined;
17
+ export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getShareLink = exports.getCustomHeaderTypes = exports.getCustomItems = exports.getCustomBlockTypes = exports.getBlockKey = exports.getHeaderTag = void 0;
3
+ exports.getShareLink = exports.getCustomHeaderTypes = exports.getCustomItems = exports.getCustomBlockTypes = exports.getBlockContext = exports.getBlockKey = exports.getHeaderTag = void 0;
4
4
  const models_1 = require("../models");
5
5
  function getHeaderTag(size) {
6
6
  switch (size) {
@@ -18,6 +18,10 @@ function getBlockKey(block, index) {
18
18
  return `${block.type}-${index}`;
19
19
  }
20
20
  exports.getBlockKey = getBlockKey;
21
+ function getBlockContext({ parentContext = '', block, index }) {
22
+ return `${parentContext}${parentContext ? '-' : ''}${block.type}-${index}`;
23
+ }
24
+ exports.getBlockContext = getBlockContext;
21
25
  const getCustomBlockTypes = ({ blocks = {}, headers = {} } = {}) => [
22
26
  ...Object.keys(blocks),
23
27
  ...Object.keys(headers),