@gravity-ui/page-constructor 3.8.3 → 3.9.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.
- package/CHANGELOG.md +8 -0
- package/build/cjs/blocks/Banner/schema.d.ts +9 -3
- package/build/cjs/blocks/CardLayout/schema.d.ts +6 -2
- package/build/cjs/blocks/Companies/schema.d.ts +3 -1
- package/build/cjs/blocks/ContentLayout/schema.d.ts +3 -1
- package/build/cjs/blocks/ExtendedFeatures/schema.d.ts +6 -2
- package/build/cjs/blocks/FilterBlock/schema.d.ts +6 -2
- package/build/cjs/blocks/Header/schema.d.ts +3 -1
- package/build/cjs/blocks/HeaderSlider/schema.d.ts +3 -1
- package/build/cjs/blocks/Icons/schema.d.ts +6 -2
- package/build/cjs/blocks/Info/schema.d.ts +3 -1
- package/build/cjs/blocks/Map/schema.d.ts +3 -1
- package/build/cjs/blocks/Media/schema.d.ts +6 -2
- package/build/cjs/blocks/PromoFeaturesBlock/schema.d.ts +3 -1
- package/build/cjs/blocks/Questions/schema.d.ts +3 -1
- package/build/cjs/blocks/Share/schema.d.ts +3 -1
- package/build/cjs/blocks/Slider/schema.d.ts +3 -1
- package/build/cjs/blocks/Table/schema.d.ts +6 -2
- package/build/cjs/blocks/Tabs/schema.d.ts +6 -2
- package/build/cjs/components/Author/schema.d.ts +3 -1
- package/build/cjs/editor/containers/Editor/Editor.js +5 -5
- package/build/cjs/editor/types/index.d.ts +4 -1
- package/build/cjs/schema/constants.d.ts +18 -6
- package/build/cjs/schema/validators/common.d.ts +9 -3
- package/build/cjs/schema/validators/common.js +3 -1
- package/build/cjs/sub-blocks/BackgroundCard/schema.d.ts +3 -1
- package/build/cjs/sub-blocks/BasicCard/schema.d.ts +3 -1
- package/build/cjs/sub-blocks/Divider/schema.d.ts +3 -1
- package/build/cjs/sub-blocks/LayoutItem/schema.d.ts +3 -1
- package/build/cjs/sub-blocks/MediaCard/schema.d.ts +3 -1
- package/build/cjs/sub-blocks/PriceDetailed/schema.d.ts +3 -1
- package/build/cjs/sub-blocks/Quote/schema.d.ts +3 -1
- package/build/cjs/text-transform/filter.d.ts +20 -0
- package/build/cjs/text-transform/filter.js +61 -0
- package/build/cjs/text-transform/index.d.ts +1 -0
- package/build/cjs/text-transform/index.js +1 -0
- package/build/cjs/text-transform/transformers.d.ts +2 -0
- package/build/cjs/text-transform/transformers.js +3 -2
- package/build/esm/blocks/Banner/schema.d.ts +9 -3
- package/build/esm/blocks/CardLayout/schema.d.ts +6 -2
- package/build/esm/blocks/Companies/schema.d.ts +3 -1
- package/build/esm/blocks/ContentLayout/schema.d.ts +3 -1
- package/build/esm/blocks/ExtendedFeatures/schema.d.ts +6 -2
- package/build/esm/blocks/FilterBlock/schema.d.ts +6 -2
- package/build/esm/blocks/Header/schema.d.ts +3 -1
- package/build/esm/blocks/HeaderSlider/schema.d.ts +3 -1
- package/build/esm/blocks/Icons/schema.d.ts +6 -2
- package/build/esm/blocks/Info/schema.d.ts +3 -1
- package/build/esm/blocks/Map/schema.d.ts +3 -1
- package/build/esm/blocks/Media/schema.d.ts +6 -2
- package/build/esm/blocks/PromoFeaturesBlock/schema.d.ts +3 -1
- package/build/esm/blocks/Questions/schema.d.ts +3 -1
- package/build/esm/blocks/Share/schema.d.ts +3 -1
- package/build/esm/blocks/Slider/schema.d.ts +3 -1
- package/build/esm/blocks/Table/schema.d.ts +6 -2
- package/build/esm/blocks/Tabs/schema.d.ts +6 -2
- package/build/esm/components/Author/schema.d.ts +3 -1
- package/build/esm/editor/containers/Editor/Editor.js +5 -5
- package/build/esm/editor/types/index.d.ts +4 -1
- package/build/esm/schema/constants.d.ts +18 -6
- package/build/esm/schema/validators/common.d.ts +9 -3
- package/build/esm/schema/validators/common.js +3 -1
- package/build/esm/sub-blocks/BackgroundCard/schema.d.ts +3 -1
- package/build/esm/sub-blocks/BasicCard/schema.d.ts +3 -1
- package/build/esm/sub-blocks/Divider/schema.d.ts +3 -1
- package/build/esm/sub-blocks/LayoutItem/schema.d.ts +3 -1
- package/build/esm/sub-blocks/MediaCard/schema.d.ts +3 -1
- package/build/esm/sub-blocks/PriceDetailed/schema.d.ts +3 -1
- package/build/esm/sub-blocks/Quote/schema.d.ts +3 -1
- package/build/esm/text-transform/filter.d.ts +20 -0
- package/build/esm/text-transform/filter.js +56 -0
- package/build/esm/text-transform/index.d.ts +1 -0
- package/build/esm/text-transform/index.js +1 -0
- package/build/esm/text-transform/transformers.d.ts +2 -0
- package/build/esm/text-transform/transformers.js +3 -2
- package/package.json +1 -1
- package/server/text-transform/filter.d.ts +20 -0
- package/server/text-transform/filter.js +63 -0
- package/server/text-transform/index.d.ts +1 -0
- package/server/text-transform/index.js +1 -0
- package/server/text-transform/transformers.d.ts +2 -0
- package/server/text-transform/transformers.js +3 -2
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
|
+
/* eslint-disable no-not-accumulator-reassign/no-not-accumulator-reassign */
|
|
3
|
+
import evalExp from '@doc-tools/transform/lib/liquid/evaluation';
|
|
4
|
+
function filterItems(items, vars, propertyName) {
|
|
5
|
+
if (!Array.isArray(items)) {
|
|
6
|
+
throw new Error(`Error while filtering: items has invalid key '${propertyName}' equals ${JSON.stringify(items)}`);
|
|
7
|
+
}
|
|
8
|
+
return items.reduce((result, item) => {
|
|
9
|
+
const passedFiltration = checkWhenCondition(item.when, vars);
|
|
10
|
+
if (passedFiltration) {
|
|
11
|
+
const property = propertyName && item[propertyName];
|
|
12
|
+
if (property === undefined) {
|
|
13
|
+
result.push(item);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
const filteredProperty = filterItems(property, vars, propertyName);
|
|
17
|
+
if (filteredProperty.length !== 0) {
|
|
18
|
+
result.push(Object.assign(Object.assign({}, item), { [propertyName]: filteredProperty }));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}, []);
|
|
24
|
+
}
|
|
25
|
+
function checkWhenCondition(whenValue, vars) {
|
|
26
|
+
return (whenValue === true ||
|
|
27
|
+
whenValue === undefined ||
|
|
28
|
+
(typeof whenValue === 'string' && (!whenValue || evalExp(whenValue, vars))));
|
|
29
|
+
}
|
|
30
|
+
function isItemArray(content) {
|
|
31
|
+
return Array.isArray(content);
|
|
32
|
+
}
|
|
33
|
+
function isItem(content) {
|
|
34
|
+
return content && typeof content === 'object' && !Array.isArray(content);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Filters content recoursively by result of it's 'when' property evaluation applied to vars argument.
|
|
38
|
+
* e.g. property {..., when: 'someVar == "someValue"' } will be included in result only if vars.someVar === 'someValue'
|
|
39
|
+
* @param {FilterableContent} content
|
|
40
|
+
* @param {ContentVariables} vars
|
|
41
|
+
* @return {FilteredContent}
|
|
42
|
+
*/
|
|
43
|
+
export function filterContent(content, vars) {
|
|
44
|
+
if (isItemArray(content)) {
|
|
45
|
+
return filterItems(content, vars).map((item) => filterContent(item, vars));
|
|
46
|
+
}
|
|
47
|
+
else if (isItem(content)) {
|
|
48
|
+
return Object.entries(content).reduce((acc, [key, value]) => {
|
|
49
|
+
acc[key] = filterContent(value, vars);
|
|
50
|
+
return acc;
|
|
51
|
+
}, {});
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return content;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ConstructorBlock } from '../models/constructor';
|
|
2
2
|
import { Lang } from '../utils/configure';
|
|
3
|
+
export type ContentVariables = Record<string, string>;
|
|
3
4
|
export type ContentTransformerProps = {
|
|
4
5
|
content: {
|
|
5
6
|
blocks?: ConstructorBlock[];
|
|
@@ -7,6 +8,7 @@ export type ContentTransformerProps = {
|
|
|
7
8
|
options: {
|
|
8
9
|
lang: Lang;
|
|
9
10
|
customConfig?: {};
|
|
11
|
+
vars?: ContentVariables;
|
|
10
12
|
};
|
|
11
13
|
};
|
|
12
14
|
export declare const contentTransformer: ({ content, options }: ContentTransformerProps) => {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/* eslint-disable no-not-accumulator-reassign/no-not-accumulator-reassign */
|
|
3
3
|
import _ from 'lodash';
|
|
4
4
|
import { config } from './config';
|
|
5
|
+
import { filterContent } from './filter';
|
|
5
6
|
function transformBlocks(blocks, lang, customConfig = {}) {
|
|
6
7
|
const fullConfig = Object.assign(Object.assign({}, config), customConfig);
|
|
7
8
|
const clonedBlocks = _.cloneDeep(blocks);
|
|
@@ -42,8 +43,8 @@ function transformBlock(lang, blocksConfig, block) {
|
|
|
42
43
|
return block;
|
|
43
44
|
}
|
|
44
45
|
export const contentTransformer = ({ content, options }) => {
|
|
45
|
-
const { lang, customConfig = {} } = options;
|
|
46
|
-
const { blocks = [] } = content;
|
|
46
|
+
const { lang, customConfig = {}, vars } = options;
|
|
47
|
+
const { blocks = [] } = (vars ? filterContent(content, vars) : content);
|
|
47
48
|
const transformedBlocks = transformBlocks(blocks, lang, customConfig);
|
|
48
49
|
return {
|
|
49
50
|
blocks: transformedBlocks,
|
package/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ContentVariables } from './transformers';
|
|
2
|
+
type WhenValue = string | boolean | undefined;
|
|
3
|
+
type OrArray<T> = T | T[];
|
|
4
|
+
type OrArrayRecord<T> = Record<string, OrArray<T>>;
|
|
5
|
+
interface FilteredContentItem extends OrArrayRecord<FilteredContentItem> {
|
|
6
|
+
}
|
|
7
|
+
type FilteredContent = OrArray<FilteredContentItem>;
|
|
8
|
+
type FilterableContentItem = FilteredContentItem & {
|
|
9
|
+
when: WhenValue;
|
|
10
|
+
};
|
|
11
|
+
export type FilterableContent = OrArray<FilterableContentItem>;
|
|
12
|
+
/**
|
|
13
|
+
* Filters content recoursively by result of it's 'when' property evaluation applied to vars argument.
|
|
14
|
+
* e.g. property {..., when: 'someVar == "someValue"' } will be included in result only if vars.someVar === 'someValue'
|
|
15
|
+
* @param {FilterableContent} content
|
|
16
|
+
* @param {ContentVariables} vars
|
|
17
|
+
* @return {FilteredContent}
|
|
18
|
+
*/
|
|
19
|
+
export declare function filterContent(content: FilterableContent | FilteredContent, vars: ContentVariables): FilteredContent;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-param-reassign */
|
|
3
|
+
/* eslint-disable no-not-accumulator-reassign/no-not-accumulator-reassign */
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.filterContent = void 0;
|
|
9
|
+
const evaluation_1 = __importDefault(require("@doc-tools/transform/lib/liquid/evaluation"));
|
|
10
|
+
function filterItems(items, vars, propertyName) {
|
|
11
|
+
if (!Array.isArray(items)) {
|
|
12
|
+
throw new Error(`Error while filtering: items has invalid key '${propertyName}' equals ${JSON.stringify(items)}`);
|
|
13
|
+
}
|
|
14
|
+
return items.reduce((result, item) => {
|
|
15
|
+
const passedFiltration = checkWhenCondition(item.when, vars);
|
|
16
|
+
if (passedFiltration) {
|
|
17
|
+
const property = propertyName && item[propertyName];
|
|
18
|
+
if (property === undefined) {
|
|
19
|
+
result.push(item);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const filteredProperty = filterItems(property, vars, propertyName);
|
|
23
|
+
if (filteredProperty.length !== 0) {
|
|
24
|
+
result.push(Object.assign(Object.assign({}, item), { [propertyName]: filteredProperty }));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}, []);
|
|
30
|
+
}
|
|
31
|
+
function checkWhenCondition(whenValue, vars) {
|
|
32
|
+
return (whenValue === true ||
|
|
33
|
+
whenValue === undefined ||
|
|
34
|
+
(typeof whenValue === 'string' && (!whenValue || (0, evaluation_1.default)(whenValue, vars))));
|
|
35
|
+
}
|
|
36
|
+
function isItemArray(content) {
|
|
37
|
+
return Array.isArray(content);
|
|
38
|
+
}
|
|
39
|
+
function isItem(content) {
|
|
40
|
+
return content && typeof content === 'object' && !Array.isArray(content);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Filters content recoursively by result of it's 'when' property evaluation applied to vars argument.
|
|
44
|
+
* e.g. property {..., when: 'someVar == "someValue"' } will be included in result only if vars.someVar === 'someValue'
|
|
45
|
+
* @param {FilterableContent} content
|
|
46
|
+
* @param {ContentVariables} vars
|
|
47
|
+
* @return {FilteredContent}
|
|
48
|
+
*/
|
|
49
|
+
function filterContent(content, vars) {
|
|
50
|
+
if (isItemArray(content)) {
|
|
51
|
+
return filterItems(content, vars).map((item) => filterContent(item, vars));
|
|
52
|
+
}
|
|
53
|
+
else if (isItem(content)) {
|
|
54
|
+
return Object.entries(content).reduce((acc, [key, value]) => {
|
|
55
|
+
acc[key] = filterContent(value, vars);
|
|
56
|
+
return acc;
|
|
57
|
+
}, {});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return content;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.filterContent = filterContent;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ConstructorBlock } from '../models/constructor';
|
|
2
2
|
import { Lang } from '../utils/configure';
|
|
3
|
+
export type ContentVariables = Record<string, string>;
|
|
3
4
|
export type ContentTransformerProps = {
|
|
4
5
|
content: {
|
|
5
6
|
blocks?: ConstructorBlock[];
|
|
@@ -7,6 +8,7 @@ export type ContentTransformerProps = {
|
|
|
7
8
|
options: {
|
|
8
9
|
lang: Lang;
|
|
9
10
|
customConfig?: {};
|
|
11
|
+
vars?: ContentVariables;
|
|
10
12
|
};
|
|
11
13
|
};
|
|
12
14
|
export declare const contentTransformer: ({ content, options }: ContentTransformerProps) => {
|
|
@@ -8,6 +8,7 @@ exports.contentTransformer = void 0;
|
|
|
8
8
|
/* eslint-disable no-not-accumulator-reassign/no-not-accumulator-reassign */
|
|
9
9
|
const lodash_1 = __importDefault(require("lodash"));
|
|
10
10
|
const config_1 = require("./config");
|
|
11
|
+
const filter_1 = require("./filter");
|
|
11
12
|
function transformBlocks(blocks, lang, customConfig = {}) {
|
|
12
13
|
const fullConfig = Object.assign(Object.assign({}, config_1.config), customConfig);
|
|
13
14
|
const clonedBlocks = lodash_1.default.cloneDeep(blocks);
|
|
@@ -48,8 +49,8 @@ function transformBlock(lang, blocksConfig, block) {
|
|
|
48
49
|
return block;
|
|
49
50
|
}
|
|
50
51
|
const contentTransformer = ({ content, options }) => {
|
|
51
|
-
const { lang, customConfig = {} } = options;
|
|
52
|
-
const { blocks = [] } = content;
|
|
52
|
+
const { lang, customConfig = {}, vars } = options;
|
|
53
|
+
const { blocks = [] } = (vars ? (0, filter_1.filterContent)(content, vars) : content);
|
|
53
54
|
const transformedBlocks = transformBlocks(blocks, lang, customConfig);
|
|
54
55
|
return {
|
|
55
56
|
blocks: transformedBlocks,
|