@gravity-ui/page-constructor 6.0.0-alpha.1 → 6.0.0-alpha.2
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/build/cjs/components/ContentList/ContentList.css +26 -9
- package/build/cjs/components/ContentList/ContentList.js +1 -1
- package/build/cjs/components/FullscreenMedia/FullscreenMedia.css +6 -2
- package/build/cjs/sub-blocks/PriceCard/PriceCard.js +1 -1
- package/build/cjs/text-transform/common.d.ts +3 -4
- package/build/cjs/text-transform/common.js +3 -30
- package/build/cjs/text-transform/config.d.ts +2 -5
- package/build/cjs/text-transform/config.js +11 -51
- package/build/cjs/text-transform/transformers.js +2 -2
- package/build/esm/components/ContentList/ContentList.css +26 -9
- package/build/esm/components/ContentList/ContentList.js +1 -1
- package/build/esm/components/FullscreenMedia/FullscreenMedia.css +6 -2
- package/build/esm/sub-blocks/PriceCard/PriceCard.js +1 -1
- package/build/esm/text-transform/common.d.ts +3 -4
- package/build/esm/text-transform/common.js +3 -30
- package/build/esm/text-transform/config.d.ts +2 -5
- package/build/esm/text-transform/config.js +11 -51
- package/build/esm/text-transform/transformers.js +2 -2
- package/package.json +1 -1
- package/server/text-transform/common.d.ts +3 -4
- package/server/text-transform/common.js +3 -30
- package/server/text-transform/config.d.ts +2 -5
- package/server/text-transform/config.js +11 -51
- package/server/text-transform/transformers.js +2 -2
- package/widget/index.js +1 -1
|
@@ -3,26 +3,10 @@
|
|
|
3
3
|
import { __rest } from "tslib";
|
|
4
4
|
import { BlockType, SubBlockType, } from '../models';
|
|
5
5
|
import { createItemsParser, typografTransformer, yfmTransformer, } from './common';
|
|
6
|
-
function
|
|
6
|
+
function parseTableBlock(transformer, content) {
|
|
7
7
|
const legend = content === null || content === void 0 ? void 0 : content.legend;
|
|
8
8
|
return Object.assign(Object.assign({}, (content || {})), { legend: legend && legend.map((string) => transformer(string)) });
|
|
9
9
|
}
|
|
10
|
-
function parseTableBlockContent(transformer, content) {
|
|
11
|
-
const legend = content === null || content === void 0 ? void 0 : content.legend;
|
|
12
|
-
const tableContent = content === null || content === void 0 ? void 0 : content.content;
|
|
13
|
-
return Object.assign(Object.assign({}, (content || {})), { content: tableContent &&
|
|
14
|
-
tableContent.map((row, i) => row.map((cell, j) => {
|
|
15
|
-
if (legend) {
|
|
16
|
-
if (i === 0 || j === 0) {
|
|
17
|
-
return transformer(cell);
|
|
18
|
-
}
|
|
19
|
-
return cell;
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
return transformer(cell);
|
|
23
|
-
}
|
|
24
|
-
})) });
|
|
25
|
-
}
|
|
26
10
|
function parseFeatures(transformer, items) {
|
|
27
11
|
return items.map((_a) => {
|
|
28
12
|
var { title, text } = _a, rest = __rest(_a, ["title", "text"]);
|
|
@@ -97,9 +81,8 @@ function parseContentLayoutTitle(transformer, content) {
|
|
|
97
81
|
export const blockHeaderTransformer = [
|
|
98
82
|
{
|
|
99
83
|
fields: ['title'],
|
|
100
|
-
transformer:
|
|
84
|
+
transformer: typografTransformer,
|
|
101
85
|
parser: parseTitle,
|
|
102
|
-
renderInline: true,
|
|
103
86
|
},
|
|
104
87
|
{
|
|
105
88
|
fields: ['description'],
|
|
@@ -156,30 +139,26 @@ export const config = {
|
|
|
156
139
|
],
|
|
157
140
|
[SubBlockType.Quote]: [
|
|
158
141
|
{
|
|
159
|
-
fields: ['text'
|
|
142
|
+
fields: ['text'],
|
|
143
|
+
transformer: typografTransformer,
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
fields: ['yfmText'],
|
|
160
147
|
transformer: yfmTransformer,
|
|
161
|
-
renderInline: true,
|
|
162
148
|
},
|
|
163
149
|
],
|
|
164
150
|
[BlockType.ExtendedFeaturesBlock]: [
|
|
165
151
|
...blockHeaderTransformer,
|
|
166
152
|
{
|
|
167
153
|
fields: ['items'],
|
|
168
|
-
transformer:
|
|
154
|
+
transformer: typografTransformer,
|
|
169
155
|
parser: createItemsParser(['title']),
|
|
170
|
-
renderInline: true,
|
|
171
156
|
},
|
|
172
157
|
{
|
|
173
158
|
fields: ['items'],
|
|
174
159
|
transformer: yfmTransformer,
|
|
175
160
|
parser: createItemsParser(['text', 'additionalInfo']),
|
|
176
161
|
},
|
|
177
|
-
{
|
|
178
|
-
fields: ['items'],
|
|
179
|
-
transformer: yfmTransformer,
|
|
180
|
-
parser: createItemsParser(['list.text']),
|
|
181
|
-
renderInline: true,
|
|
182
|
-
},
|
|
183
162
|
],
|
|
184
163
|
[BlockType.PromoFeaturesBlock]: [
|
|
185
164
|
...blockHeaderTransformer,
|
|
@@ -209,8 +188,7 @@ export const config = {
|
|
|
209
188
|
[BlockType.BannerBlock]: [
|
|
210
189
|
{
|
|
211
190
|
fields: ['title'],
|
|
212
|
-
transformer:
|
|
213
|
-
renderInline: true,
|
|
191
|
+
transformer: typografTransformer,
|
|
214
192
|
},
|
|
215
193
|
{
|
|
216
194
|
fields: ['subtitle'],
|
|
@@ -263,13 +241,7 @@ export const config = {
|
|
|
263
241
|
{
|
|
264
242
|
fields: ['table'],
|
|
265
243
|
transformer: yfmTransformer,
|
|
266
|
-
parser:
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
fields: ['table'],
|
|
270
|
-
transformer: yfmTransformer,
|
|
271
|
-
parser: parseTableBlockContent,
|
|
272
|
-
renderInline: true,
|
|
244
|
+
parser: parseTableBlock,
|
|
273
245
|
},
|
|
274
246
|
],
|
|
275
247
|
[BlockType.HeaderSliderBlock]: [
|
|
@@ -295,11 +267,6 @@ export const config = {
|
|
|
295
267
|
fields: ['description'],
|
|
296
268
|
transformer: yfmTransformer,
|
|
297
269
|
},
|
|
298
|
-
{
|
|
299
|
-
fields: ['overtitle', 'title'],
|
|
300
|
-
transformer: yfmTransformer,
|
|
301
|
-
renderInline: true,
|
|
302
|
-
},
|
|
303
270
|
],
|
|
304
271
|
[BlockType.ContentLayoutBlock]: [
|
|
305
272
|
{
|
|
@@ -353,20 +320,13 @@ export const config = {
|
|
|
353
320
|
[SubBlockType.PriceCard]: [
|
|
354
321
|
{
|
|
355
322
|
fields: ['title'],
|
|
356
|
-
transformer:
|
|
357
|
-
renderInline: true,
|
|
323
|
+
transformer: typografTransformer,
|
|
358
324
|
},
|
|
359
325
|
{
|
|
360
326
|
fields: ['list'],
|
|
361
327
|
transformer: yfmTransformer,
|
|
362
328
|
parser: createItemsParser(['text']),
|
|
363
329
|
},
|
|
364
|
-
{
|
|
365
|
-
fields: ['list'],
|
|
366
|
-
transformer: yfmTransformer,
|
|
367
|
-
parser: createItemsParser(['title']),
|
|
368
|
-
renderInline: true,
|
|
369
|
-
},
|
|
370
330
|
],
|
|
371
331
|
[BlockType.FormBlock]: [
|
|
372
332
|
{
|
|
@@ -18,10 +18,10 @@ function transformBlock(lang, blocksConfig, block, plugins) {
|
|
|
18
18
|
if (blockConfig) {
|
|
19
19
|
const configs = Array.isArray(blockConfig) ? blockConfig : [blockConfig];
|
|
20
20
|
configs.forEach((transformConfig) => {
|
|
21
|
-
const { fields, transformer: transformerRaw, parser
|
|
21
|
+
const { fields, transformer: transformerRaw, parser } = transformConfig;
|
|
22
22
|
const transformer = (content) =>
|
|
23
23
|
// eslint-disable-next-line no-useless-call
|
|
24
|
-
transformerRaw.call(null, lang, content, { plugins
|
|
24
|
+
transformerRaw.call(null, lang, content, { plugins });
|
|
25
25
|
if (fields) {
|
|
26
26
|
fields.forEach((field) => {
|
|
27
27
|
if (block[field]) {
|
package/package.json
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { MarkdownItPluginCb } from '@diplodoc/transform/lib/plugins/typings';
|
|
2
2
|
import { Lang } from './types';
|
|
3
3
|
export type ComplexItem = {
|
|
4
|
-
[key: string]: string
|
|
4
|
+
[key: string]: string;
|
|
5
5
|
};
|
|
6
6
|
export type Item = string | null | ComplexItem;
|
|
7
7
|
export type Transformer = (text: string) => string;
|
|
8
8
|
export type TransformerRaw = (lang: Lang, content: string, options: {
|
|
9
9
|
plugins: MarkdownItPluginCb[];
|
|
10
|
-
renderInline?: boolean;
|
|
11
10
|
}) => string;
|
|
12
11
|
export type Parser<T = any> = (transformer: Transformer, block: T) => T;
|
|
13
12
|
export declare const createItemsParser: (fields: string[]) => (transformer: Transformer, items: Item[]) => (string | {
|
|
14
|
-
[x: string]: string
|
|
13
|
+
[x: string]: string;
|
|
15
14
|
} | null)[];
|
|
16
15
|
export declare function yfmTransformer(lang: Lang, content: string, options?: {
|
|
17
16
|
plugins?: MarkdownItPluginCb[];
|
|
18
|
-
}
|
|
17
|
+
}): string;
|
|
19
18
|
export declare function typografTransformer(lang: Lang, content: string): string;
|
|
@@ -15,47 +15,20 @@ const createItemsParser = (fields) => (transformer, items) => items.map((item) =
|
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
17
17
|
return Object.assign(Object.assign({}, item), fields.reduce((acc, fieldName) => {
|
|
18
|
-
if (fieldName
|
|
19
|
-
const [firstProperty, secondProperty] = fieldName.split('.');
|
|
20
|
-
const root = item[firstProperty];
|
|
21
|
-
if (!root || typeof root !== 'object') {
|
|
22
|
-
return acc;
|
|
23
|
-
}
|
|
24
|
-
if (Array.isArray(root)) {
|
|
25
|
-
if (!acc[firstProperty]) {
|
|
26
|
-
// eslint-disable-next-line no-param-reassign
|
|
27
|
-
acc[firstProperty] = [];
|
|
28
|
-
}
|
|
29
|
-
// eslint-disable-next-line no-param-reassign
|
|
30
|
-
acc[firstProperty] = root.map((subItem) => (Object.assign(Object.assign({}, subItem), { [secondProperty]: typeof subItem[secondProperty] === 'string'
|
|
31
|
-
? transformer(subItem[secondProperty])
|
|
32
|
-
: subItem[secondProperty] })));
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
// eslint-disable-next-line no-param-reassign
|
|
36
|
-
acc[firstProperty] = Object.assign(Object.assign({}, root), { [secondProperty]: typeof root[secondProperty] === 'string'
|
|
37
|
-
? transformer(root[secondProperty])
|
|
38
|
-
: root[secondProperty] });
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else if (item[fieldName]) {
|
|
18
|
+
if (item[fieldName]) {
|
|
42
19
|
// eslint-disable-next-line no-param-reassign
|
|
43
|
-
acc[fieldName] =
|
|
44
|
-
typeof item[fieldName] === 'string'
|
|
45
|
-
? transformer(item[fieldName])
|
|
46
|
-
: item[fieldName];
|
|
20
|
+
acc[fieldName] = transformer(item[fieldName]);
|
|
47
21
|
}
|
|
48
22
|
return acc;
|
|
49
23
|
}, {}));
|
|
50
24
|
}
|
|
51
25
|
});
|
|
52
26
|
exports.createItemsParser = createItemsParser;
|
|
53
|
-
function yfmTransformer(lang, content, options = {}
|
|
27
|
+
function yfmTransformer(lang, content, options = {}) {
|
|
54
28
|
const { plugins = [] } = options;
|
|
55
29
|
const { html } = (0, utils_1.fullTransform)(content, {
|
|
56
30
|
lang,
|
|
57
31
|
plugins: [...plugins_1.default, ...plugins],
|
|
58
|
-
renderInline,
|
|
59
32
|
});
|
|
60
33
|
return html;
|
|
61
34
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TitleItemProps } from '../models';
|
|
2
|
-
import { Parser, Transformer, TransformerRaw, yfmTransformer } from './common';
|
|
2
|
+
import { Parser, Transformer, TransformerRaw, typografTransformer, yfmTransformer } from './common';
|
|
3
3
|
export declare const blockHeaderTransformer: ({
|
|
4
4
|
fields: string[];
|
|
5
|
-
transformer: typeof
|
|
5
|
+
transformer: typeof typografTransformer;
|
|
6
6
|
parser: (transformer: Transformer, title: TitleItemProps | string) => string | {
|
|
7
7
|
text: string;
|
|
8
8
|
navTitle?: string | undefined;
|
|
@@ -14,18 +14,15 @@ export declare const blockHeaderTransformer: ({
|
|
|
14
14
|
custom?: import("react").ReactNode;
|
|
15
15
|
onClick?: (() => void) | undefined;
|
|
16
16
|
};
|
|
17
|
-
renderInline: boolean;
|
|
18
17
|
} | {
|
|
19
18
|
fields: string[];
|
|
20
19
|
transformer: typeof yfmTransformer;
|
|
21
20
|
parser?: undefined;
|
|
22
|
-
renderInline?: undefined;
|
|
23
21
|
})[];
|
|
24
22
|
interface BlockConfig {
|
|
25
23
|
transformer: TransformerRaw;
|
|
26
24
|
fields?: string[];
|
|
27
25
|
parser?: Parser;
|
|
28
|
-
renderInline?: boolean;
|
|
29
26
|
}
|
|
30
27
|
export type BlocksConfig = Record<string, BlockConfig | BlockConfig[]>;
|
|
31
28
|
export declare const config: BlocksConfig;
|
|
@@ -16,26 +16,10 @@ 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 parseTableBlock(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
|
-
}
|
|
39
23
|
function parseFeatures(transformer, items) {
|
|
40
24
|
return items.map((_a) => {
|
|
41
25
|
var { title, text } = _a, rest = __rest(_a, ["title", "text"]);
|
|
@@ -110,9 +94,8 @@ function parseContentLayoutTitle(transformer, content) {
|
|
|
110
94
|
exports.blockHeaderTransformer = [
|
|
111
95
|
{
|
|
112
96
|
fields: ['title'],
|
|
113
|
-
transformer: common_1.
|
|
97
|
+
transformer: common_1.typografTransformer,
|
|
114
98
|
parser: parseTitle,
|
|
115
|
-
renderInline: true,
|
|
116
99
|
},
|
|
117
100
|
{
|
|
118
101
|
fields: ['description'],
|
|
@@ -169,30 +152,26 @@ exports.config = {
|
|
|
169
152
|
],
|
|
170
153
|
[models_1.SubBlockType.Quote]: [
|
|
171
154
|
{
|
|
172
|
-
fields: ['text'
|
|
155
|
+
fields: ['text'],
|
|
156
|
+
transformer: common_1.typografTransformer,
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
fields: ['yfmText'],
|
|
173
160
|
transformer: common_1.yfmTransformer,
|
|
174
|
-
renderInline: true,
|
|
175
161
|
},
|
|
176
162
|
],
|
|
177
163
|
[models_1.BlockType.ExtendedFeaturesBlock]: [
|
|
178
164
|
...exports.blockHeaderTransformer,
|
|
179
165
|
{
|
|
180
166
|
fields: ['items'],
|
|
181
|
-
transformer: common_1.
|
|
167
|
+
transformer: common_1.typografTransformer,
|
|
182
168
|
parser: (0, common_1.createItemsParser)(['title']),
|
|
183
|
-
renderInline: true,
|
|
184
169
|
},
|
|
185
170
|
{
|
|
186
171
|
fields: ['items'],
|
|
187
172
|
transformer: common_1.yfmTransformer,
|
|
188
173
|
parser: (0, common_1.createItemsParser)(['text', 'additionalInfo']),
|
|
189
174
|
},
|
|
190
|
-
{
|
|
191
|
-
fields: ['items'],
|
|
192
|
-
transformer: common_1.yfmTransformer,
|
|
193
|
-
parser: (0, common_1.createItemsParser)(['list.text']),
|
|
194
|
-
renderInline: true,
|
|
195
|
-
},
|
|
196
175
|
],
|
|
197
176
|
[models_1.BlockType.PromoFeaturesBlock]: [
|
|
198
177
|
...exports.blockHeaderTransformer,
|
|
@@ -222,8 +201,7 @@ exports.config = {
|
|
|
222
201
|
[models_1.BlockType.BannerBlock]: [
|
|
223
202
|
{
|
|
224
203
|
fields: ['title'],
|
|
225
|
-
transformer: common_1.
|
|
226
|
-
renderInline: true,
|
|
204
|
+
transformer: common_1.typografTransformer,
|
|
227
205
|
},
|
|
228
206
|
{
|
|
229
207
|
fields: ['subtitle'],
|
|
@@ -276,13 +254,7 @@ exports.config = {
|
|
|
276
254
|
{
|
|
277
255
|
fields: ['table'],
|
|
278
256
|
transformer: common_1.yfmTransformer,
|
|
279
|
-
parser:
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
fields: ['table'],
|
|
283
|
-
transformer: common_1.yfmTransformer,
|
|
284
|
-
parser: parseTableBlockContent,
|
|
285
|
-
renderInline: true,
|
|
257
|
+
parser: parseTableBlock,
|
|
286
258
|
},
|
|
287
259
|
],
|
|
288
260
|
[models_1.BlockType.HeaderSliderBlock]: [
|
|
@@ -308,11 +280,6 @@ exports.config = {
|
|
|
308
280
|
fields: ['description'],
|
|
309
281
|
transformer: common_1.yfmTransformer,
|
|
310
282
|
},
|
|
311
|
-
{
|
|
312
|
-
fields: ['overtitle', 'title'],
|
|
313
|
-
transformer: common_1.yfmTransformer,
|
|
314
|
-
renderInline: true,
|
|
315
|
-
},
|
|
316
283
|
],
|
|
317
284
|
[models_1.BlockType.ContentLayoutBlock]: [
|
|
318
285
|
{
|
|
@@ -366,20 +333,13 @@ exports.config = {
|
|
|
366
333
|
[models_1.SubBlockType.PriceCard]: [
|
|
367
334
|
{
|
|
368
335
|
fields: ['title'],
|
|
369
|
-
transformer: common_1.
|
|
370
|
-
renderInline: true,
|
|
336
|
+
transformer: common_1.typografTransformer,
|
|
371
337
|
},
|
|
372
338
|
{
|
|
373
339
|
fields: ['list'],
|
|
374
340
|
transformer: common_1.yfmTransformer,
|
|
375
341
|
parser: (0, common_1.createItemsParser)(['text']),
|
|
376
342
|
},
|
|
377
|
-
{
|
|
378
|
-
fields: ['list'],
|
|
379
|
-
transformer: common_1.yfmTransformer,
|
|
380
|
-
parser: (0, common_1.createItemsParser)(['title']),
|
|
381
|
-
renderInline: true,
|
|
382
|
-
},
|
|
383
343
|
],
|
|
384
344
|
[models_1.BlockType.FormBlock]: [
|
|
385
345
|
{
|
|
@@ -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
|
|
27
|
+
const { fields, transformer: transformerRaw, parser } = 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 });
|
|
31
31
|
if (fields) {
|
|
32
32
|
fields.forEach((field) => {
|
|
33
33
|
if (block[field]) {
|