@gravity-ui/page-constructor 6.0.0-alpha.2 → 6.0.0-alpha.4
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/README.md +4 -0
- package/build/cjs/blocks/Slider/Slider.d.ts +3 -2
- package/build/cjs/blocks/Slider/schema.d.ts +20 -2
- package/build/cjs/blocks/Slider/schema.js +12 -1
- package/build/cjs/blocks/SliderOld/schema.d.ts +20 -2
- package/build/cjs/blocks/SliderOld/schema.js +12 -1
- package/build/cjs/blocks/index.d.ts +1 -0
- package/build/cjs/models/constructor-items/blocks.d.ts +1 -1
- package/build/cjs/text-transform/common.d.ts +4 -3
- package/build/cjs/text-transform/common.js +41 -18
- package/build/cjs/text-transform/config.d.ts +5 -2
- package/build/cjs/text-transform/config.js +45 -11
- package/build/cjs/text-transform/transformers.js +2 -2
- package/build/esm/blocks/Slider/Slider.d.ts +3 -2
- package/build/esm/blocks/Slider/Slider.js +4 -4
- package/build/esm/blocks/Slider/schema.d.ts +20 -2
- package/build/esm/blocks/Slider/schema.js +12 -1
- package/build/esm/blocks/SliderOld/schema.d.ts +20 -2
- package/build/esm/blocks/SliderOld/schema.js +12 -1
- package/build/esm/blocks/index.d.ts +1 -0
- package/build/esm/models/constructor-items/blocks.d.ts +1 -1
- package/build/esm/text-transform/common.d.ts +4 -3
- package/build/esm/text-transform/common.js +41 -18
- package/build/esm/text-transform/config.d.ts +5 -2
- package/build/esm/text-transform/config.js +45 -11
- package/build/esm/text-transform/transformers.js +2 -2
- package/package.json +1 -1
- package/schema/index.js +1 -1
- package/server/models/constructor-items/blocks.d.ts +1 -1
- package/server/text-transform/common.d.ts +4 -3
- package/server/text-transform/common.js +41 -18
- package/server/text-transform/config.d.ts +5 -2
- package/server/text-transform/config.js +45 -11
- package/server/text-transform/transformers.js +2 -2
|
@@ -6,29 +6,52 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.typografTransformer = exports.yfmTransformer = exports.createItemsParser = void 0;
|
|
7
7
|
const plugins_1 = __importDefault(require("@diplodoc/transform/lib/plugins"));
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
|
-
const createItemsParser = (fields) => (transformer, items) =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
9
|
+
const createItemsParser = (fields) => (transformer, items) => {
|
|
10
|
+
const applyTransform = (itemLocal) => typeof itemLocal === 'string' ? transformer(itemLocal) : itemLocal;
|
|
11
|
+
return items.map((item) => {
|
|
12
|
+
if (!item) {
|
|
13
|
+
return item;
|
|
14
|
+
}
|
|
15
|
+
else if (typeof item === 'string') {
|
|
16
|
+
return transformer(item);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return Object.assign(Object.assign({}, item), fields.reduce((acc, fieldName) => {
|
|
20
|
+
if (fieldName.includes('.')) {
|
|
21
|
+
const [firstProperty, secondProperty] = fieldName.split('.');
|
|
22
|
+
const root = item[firstProperty];
|
|
23
|
+
if (!root || typeof root !== 'object') {
|
|
24
|
+
return acc;
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(root)) {
|
|
27
|
+
if (!acc[firstProperty]) {
|
|
28
|
+
// eslint-disable-next-line no-param-reassign
|
|
29
|
+
acc[firstProperty] = [];
|
|
30
|
+
}
|
|
31
|
+
// eslint-disable-next-line no-param-reassign
|
|
32
|
+
acc[firstProperty] = root.map((subItem) => (Object.assign(Object.assign({}, subItem), { [secondProperty]: applyTransform(subItem[secondProperty]) })));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// eslint-disable-next-line no-param-reassign
|
|
36
|
+
acc[firstProperty] = Object.assign(Object.assign({}, root), { [secondProperty]: applyTransform(root[secondProperty]) });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (item[fieldName]) {
|
|
40
|
+
// eslint-disable-next-line no-param-reassign
|
|
41
|
+
acc[fieldName] = applyTransform(item[fieldName]);
|
|
42
|
+
}
|
|
43
|
+
return acc;
|
|
44
|
+
}, {}));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
26
48
|
exports.createItemsParser = createItemsParser;
|
|
27
|
-
function yfmTransformer(lang, content, options = {}) {
|
|
49
|
+
function yfmTransformer(lang, content, options = {}, renderInline = false) {
|
|
28
50
|
const { plugins = [] } = options;
|
|
29
51
|
const { html } = (0, utils_1.fullTransform)(content, {
|
|
30
52
|
lang,
|
|
31
53
|
plugins: [...plugins_1.default, ...plugins],
|
|
54
|
+
renderInline,
|
|
32
55
|
});
|
|
33
56
|
return html;
|
|
34
57
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TitleItemProps } from '../models';
|
|
2
|
-
import { Parser, Transformer, TransformerRaw,
|
|
2
|
+
import { Parser, Transformer, TransformerRaw, yfmTransformer } from './common';
|
|
3
3
|
export declare const blockHeaderTransformer: ({
|
|
4
4
|
fields: string[];
|
|
5
|
-
transformer: typeof
|
|
5
|
+
transformer: typeof yfmTransformer;
|
|
6
6
|
parser: (transformer: Transformer, title: TitleItemProps | string) => string | {
|
|
7
7
|
text: string;
|
|
8
8
|
navTitle?: string | undefined;
|
|
@@ -14,15 +14,18 @@ export declare const blockHeaderTransformer: ({
|
|
|
14
14
|
custom?: import("react").ReactNode;
|
|
15
15
|
onClick?: (() => void) | undefined;
|
|
16
16
|
};
|
|
17
|
+
renderInline: boolean;
|
|
17
18
|
} | {
|
|
18
19
|
fields: string[];
|
|
19
20
|
transformer: typeof yfmTransformer;
|
|
20
21
|
parser?: undefined;
|
|
22
|
+
renderInline?: undefined;
|
|
21
23
|
})[];
|
|
22
24
|
interface BlockConfig {
|
|
23
25
|
transformer: TransformerRaw;
|
|
24
26
|
fields?: string[];
|
|
25
27
|
parser?: Parser;
|
|
28
|
+
renderInline?: boolean;
|
|
26
29
|
}
|
|
27
30
|
export type BlocksConfig = Record<string, BlockConfig | BlockConfig[]>;
|
|
28
31
|
export declare const config: BlocksConfig;
|
|
@@ -16,10 +16,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
exports.config = exports.blockHeaderTransformer = void 0;
|
|
17
17
|
const models_1 = require("../models");
|
|
18
18
|
const common_1 = require("./common");
|
|
19
|
-
function
|
|
19
|
+
function parseTableBlockLegend(transformer, content) {
|
|
20
20
|
const legend = content === null || content === void 0 ? void 0 : content.legend;
|
|
21
21
|
return Object.assign(Object.assign({}, (content || {})), { legend: legend && legend.map((string) => transformer(string)) });
|
|
22
22
|
}
|
|
23
|
+
function parseTableBlockContent(transformer, content) {
|
|
24
|
+
const legend = content === null || content === void 0 ? void 0 : content.legend;
|
|
25
|
+
const tableContent = content === null || content === void 0 ? void 0 : content.content;
|
|
26
|
+
return Object.assign(Object.assign({}, (content || {})), { content: tableContent &&
|
|
27
|
+
tableContent.map((row, i) => row.map((cell, j) => {
|
|
28
|
+
if (legend) {
|
|
29
|
+
if (i === 0 || j === 0) {
|
|
30
|
+
return transformer(cell);
|
|
31
|
+
}
|
|
32
|
+
return cell;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return transformer(cell);
|
|
36
|
+
}
|
|
37
|
+
})) });
|
|
38
|
+
}
|
|
23
39
|
function parseFeatures(transformer, items) {
|
|
24
40
|
return items.map((_a) => {
|
|
25
41
|
var { title, text } = _a, rest = __rest(_a, ["title", "text"]);
|
|
@@ -94,8 +110,9 @@ function parseContentLayoutTitle(transformer, content) {
|
|
|
94
110
|
exports.blockHeaderTransformer = [
|
|
95
111
|
{
|
|
96
112
|
fields: ['title'],
|
|
97
|
-
transformer: common_1.
|
|
113
|
+
transformer: common_1.yfmTransformer,
|
|
98
114
|
parser: parseTitle,
|
|
115
|
+
renderInline: true,
|
|
99
116
|
},
|
|
100
117
|
{
|
|
101
118
|
fields: ['description'],
|
|
@@ -152,26 +169,30 @@ exports.config = {
|
|
|
152
169
|
],
|
|
153
170
|
[models_1.SubBlockType.Quote]: [
|
|
154
171
|
{
|
|
155
|
-
fields: ['text'],
|
|
156
|
-
transformer: common_1.typografTransformer,
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
fields: ['yfmText'],
|
|
172
|
+
fields: ['text', 'yfmText'],
|
|
160
173
|
transformer: common_1.yfmTransformer,
|
|
174
|
+
renderInline: true,
|
|
161
175
|
},
|
|
162
176
|
],
|
|
163
177
|
[models_1.BlockType.ExtendedFeaturesBlock]: [
|
|
164
178
|
...exports.blockHeaderTransformer,
|
|
165
179
|
{
|
|
166
180
|
fields: ['items'],
|
|
167
|
-
transformer: common_1.
|
|
181
|
+
transformer: common_1.yfmTransformer,
|
|
168
182
|
parser: (0, common_1.createItemsParser)(['title']),
|
|
183
|
+
renderInline: true,
|
|
169
184
|
},
|
|
170
185
|
{
|
|
171
186
|
fields: ['items'],
|
|
172
187
|
transformer: common_1.yfmTransformer,
|
|
173
188
|
parser: (0, common_1.createItemsParser)(['text', 'additionalInfo']),
|
|
174
189
|
},
|
|
190
|
+
{
|
|
191
|
+
fields: ['items'],
|
|
192
|
+
transformer: common_1.yfmTransformer,
|
|
193
|
+
parser: (0, common_1.createItemsParser)(['list.text']),
|
|
194
|
+
renderInline: true,
|
|
195
|
+
},
|
|
175
196
|
],
|
|
176
197
|
[models_1.BlockType.PromoFeaturesBlock]: [
|
|
177
198
|
...exports.blockHeaderTransformer,
|
|
@@ -201,7 +222,8 @@ exports.config = {
|
|
|
201
222
|
[models_1.BlockType.BannerBlock]: [
|
|
202
223
|
{
|
|
203
224
|
fields: ['title'],
|
|
204
|
-
transformer: common_1.
|
|
225
|
+
transformer: common_1.yfmTransformer,
|
|
226
|
+
renderInline: true,
|
|
205
227
|
},
|
|
206
228
|
{
|
|
207
229
|
fields: ['subtitle'],
|
|
@@ -254,7 +276,13 @@ exports.config = {
|
|
|
254
276
|
{
|
|
255
277
|
fields: ['table'],
|
|
256
278
|
transformer: common_1.yfmTransformer,
|
|
257
|
-
parser:
|
|
279
|
+
parser: parseTableBlockLegend,
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
fields: ['table'],
|
|
283
|
+
transformer: common_1.yfmTransformer,
|
|
284
|
+
parser: parseTableBlockContent,
|
|
285
|
+
renderInline: true,
|
|
258
286
|
},
|
|
259
287
|
],
|
|
260
288
|
[models_1.BlockType.HeaderSliderBlock]: [
|
|
@@ -280,6 +308,11 @@ exports.config = {
|
|
|
280
308
|
fields: ['description'],
|
|
281
309
|
transformer: common_1.yfmTransformer,
|
|
282
310
|
},
|
|
311
|
+
{
|
|
312
|
+
fields: ['overtitle', 'title'],
|
|
313
|
+
transformer: common_1.yfmTransformer,
|
|
314
|
+
renderInline: true,
|
|
315
|
+
},
|
|
283
316
|
],
|
|
284
317
|
[models_1.BlockType.ContentLayoutBlock]: [
|
|
285
318
|
{
|
|
@@ -333,7 +366,8 @@ exports.config = {
|
|
|
333
366
|
[models_1.SubBlockType.PriceCard]: [
|
|
334
367
|
{
|
|
335
368
|
fields: ['title'],
|
|
336
|
-
transformer: common_1.
|
|
369
|
+
transformer: common_1.yfmTransformer,
|
|
370
|
+
renderInline: true,
|
|
337
371
|
},
|
|
338
372
|
{
|
|
339
373
|
fields: ['list'],
|
|
@@ -24,10 +24,10 @@ function transformBlock(lang, blocksConfig, block, plugins) {
|
|
|
24
24
|
if (blockConfig) {
|
|
25
25
|
const configs = Array.isArray(blockConfig) ? blockConfig : [blockConfig];
|
|
26
26
|
configs.forEach((transformConfig) => {
|
|
27
|
-
const { fields, transformer: transformerRaw, parser } = transformConfig;
|
|
27
|
+
const { fields, transformer: transformerRaw, parser, renderInline } = transformConfig;
|
|
28
28
|
const transformer = (content) =>
|
|
29
29
|
// eslint-disable-next-line no-useless-call
|
|
30
|
-
transformerRaw.call(null, lang, content, { plugins });
|
|
30
|
+
transformerRaw.call(null, lang, content, { plugins, renderInline });
|
|
31
31
|
if (fields) {
|
|
32
32
|
fields.forEach((field) => {
|
|
33
33
|
if (block[field]) {
|