@gravity-ui/page-constructor 6.0.0-alpha.3 → 6.0.0-alpha.5
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/Share/Share.js +5 -1
- 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/Table/Table.css +4 -3
- package/build/cjs/blocks/Table/Table.js +3 -1
- package/build/cjs/components/Title/TitleItem.css +1 -0
- package/build/cjs/models/constructor-items/blocks.d.ts +1 -1
- package/build/cjs/sub-blocks/BannerCard/BannerCard.css +4 -0
- package/build/cjs/sub-blocks/Content/Content.css +27 -25
- 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 +84 -43
- package/build/cjs/text-transform/transformers.js +2 -2
- package/build/esm/blocks/Share/Share.js +5 -1
- 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/Table/Table.css +4 -3
- package/build/esm/blocks/Table/Table.js +4 -2
- package/build/esm/components/Title/TitleItem.css +1 -0
- package/build/esm/models/constructor-items/blocks.d.ts +1 -1
- package/build/esm/sub-blocks/BannerCard/BannerCard.css +4 -0
- package/build/esm/sub-blocks/Content/Content.css +27 -25
- 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 +85 -44
- 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 +84 -43
- package/server/text-transform/transformers.js +2 -2
- package/widget/index.js +1 -1
|
@@ -1,27 +1,50 @@
|
|
|
1
1
|
import defaultPlugins from '@diplodoc/transform/lib/plugins';
|
|
2
2
|
import { fullTransform, typografToHTML } from './utils';
|
|
3
|
-
export const createItemsParser = (fields) => (transformer, items) =>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
3
|
+
export const createItemsParser = (fields) => (transformer, items) => {
|
|
4
|
+
const applyTransform = (itemLocal) => typeof itemLocal === 'string' ? transformer(itemLocal) : itemLocal;
|
|
5
|
+
return items.map((item) => {
|
|
6
|
+
if (!item) {
|
|
7
|
+
return item;
|
|
8
|
+
}
|
|
9
|
+
else if (typeof item === 'string') {
|
|
10
|
+
return transformer(item);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return Object.assign(Object.assign({}, item), fields.reduce((acc, fieldName) => {
|
|
14
|
+
if (fieldName.includes('.')) {
|
|
15
|
+
const [firstProperty, secondProperty] = fieldName.split('.');
|
|
16
|
+
const root = item[firstProperty];
|
|
17
|
+
if (!root || typeof root !== 'object') {
|
|
18
|
+
return acc;
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(root)) {
|
|
21
|
+
if (!acc[firstProperty]) {
|
|
22
|
+
// eslint-disable-next-line no-param-reassign
|
|
23
|
+
acc[firstProperty] = [];
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line no-param-reassign
|
|
26
|
+
acc[firstProperty] = root.map((subItem) => (Object.assign(Object.assign({}, subItem), { [secondProperty]: applyTransform(subItem[secondProperty]) })));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// eslint-disable-next-line no-param-reassign
|
|
30
|
+
acc[firstProperty] = Object.assign(Object.assign({}, root), { [secondProperty]: applyTransform(root[secondProperty]) });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (item[fieldName]) {
|
|
34
|
+
// eslint-disable-next-line no-param-reassign
|
|
35
|
+
acc[fieldName] = applyTransform(item[fieldName]);
|
|
36
|
+
}
|
|
37
|
+
return acc;
|
|
38
|
+
}, {}));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
export function yfmTransformer(lang, content, options = {}, renderInline = false) {
|
|
21
43
|
const { plugins = [] } = options;
|
|
22
44
|
const { html } = fullTransform(content, {
|
|
23
45
|
lang,
|
|
24
46
|
plugins: [...defaultPlugins, ...plugins],
|
|
47
|
+
renderInline,
|
|
25
48
|
});
|
|
26
49
|
return html;
|
|
27
50
|
}
|
|
@@ -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;
|
|
@@ -2,11 +2,27 @@
|
|
|
2
2
|
/* eslint-disable no-not-accumulator-reassign/no-not-accumulator-reassign */
|
|
3
3
|
import { __rest } from "tslib";
|
|
4
4
|
import { BlockType, SubBlockType, } from '../models';
|
|
5
|
-
import { createItemsParser,
|
|
6
|
-
function
|
|
5
|
+
import { createItemsParser, yfmTransformer } from './common';
|
|
6
|
+
function parseTableBlockLegend(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
|
+
}
|
|
10
26
|
function parseFeatures(transformer, items) {
|
|
11
27
|
return items.map((_a) => {
|
|
12
28
|
var { title, text } = _a, rest = __rest(_a, ["title", "text"]);
|
|
@@ -81,8 +97,9 @@ function parseContentLayoutTitle(transformer, content) {
|
|
|
81
97
|
export const blockHeaderTransformer = [
|
|
82
98
|
{
|
|
83
99
|
fields: ['title'],
|
|
84
|
-
transformer:
|
|
100
|
+
transformer: yfmTransformer,
|
|
85
101
|
parser: parseTitle,
|
|
102
|
+
renderInline: true,
|
|
86
103
|
},
|
|
87
104
|
{
|
|
88
105
|
fields: ['description'],
|
|
@@ -93,7 +110,8 @@ export const config = {
|
|
|
93
110
|
[SubBlockType.BasicCard]: [
|
|
94
111
|
{
|
|
95
112
|
fields: ['title'],
|
|
96
|
-
transformer:
|
|
113
|
+
transformer: yfmTransformer,
|
|
114
|
+
renderInline: true,
|
|
97
115
|
},
|
|
98
116
|
{
|
|
99
117
|
fields: ['text', 'additionalInfo'],
|
|
@@ -102,22 +120,16 @@ export const config = {
|
|
|
102
120
|
],
|
|
103
121
|
[SubBlockType.BackgroundCard]: [
|
|
104
122
|
{
|
|
105
|
-
fields: ['text', 'additionalInfo'],
|
|
123
|
+
fields: ['title', 'text', 'additionalInfo'],
|
|
106
124
|
transformer: yfmTransformer,
|
|
107
|
-
|
|
108
|
-
{
|
|
109
|
-
fields: ['title'],
|
|
110
|
-
transformer: typografTransformer,
|
|
125
|
+
renderInline: true,
|
|
111
126
|
},
|
|
112
127
|
],
|
|
113
128
|
[SubBlockType.ImageCard]: [
|
|
114
129
|
{
|
|
115
|
-
fields: ['text', 'additionalInfo'],
|
|
130
|
+
fields: ['title', 'text', 'additionalInfo'],
|
|
116
131
|
transformer: yfmTransformer,
|
|
117
|
-
|
|
118
|
-
{
|
|
119
|
-
fields: ['title'],
|
|
120
|
-
transformer: typografTransformer,
|
|
132
|
+
renderInline: true,
|
|
121
133
|
},
|
|
122
134
|
],
|
|
123
135
|
[SubBlockType.LayoutItem]: [
|
|
@@ -129,7 +141,8 @@ export const config = {
|
|
|
129
141
|
{
|
|
130
142
|
fields: ['content'],
|
|
131
143
|
parser: parseContentLayoutTitle,
|
|
132
|
-
transformer:
|
|
144
|
+
transformer: yfmTransformer,
|
|
145
|
+
renderInline: true,
|
|
133
146
|
},
|
|
134
147
|
{
|
|
135
148
|
fields: ['metaInfo'],
|
|
@@ -139,26 +152,30 @@ export const config = {
|
|
|
139
152
|
],
|
|
140
153
|
[SubBlockType.Quote]: [
|
|
141
154
|
{
|
|
142
|
-
fields: ['text'],
|
|
143
|
-
transformer: typografTransformer,
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
fields: ['yfmText'],
|
|
155
|
+
fields: ['text', 'yfmText'],
|
|
147
156
|
transformer: yfmTransformer,
|
|
157
|
+
renderInline: true,
|
|
148
158
|
},
|
|
149
159
|
],
|
|
150
160
|
[BlockType.ExtendedFeaturesBlock]: [
|
|
151
161
|
...blockHeaderTransformer,
|
|
152
162
|
{
|
|
153
163
|
fields: ['items'],
|
|
154
|
-
transformer:
|
|
164
|
+
transformer: yfmTransformer,
|
|
155
165
|
parser: createItemsParser(['title']),
|
|
166
|
+
renderInline: true,
|
|
156
167
|
},
|
|
157
168
|
{
|
|
158
169
|
fields: ['items'],
|
|
159
170
|
transformer: yfmTransformer,
|
|
160
171
|
parser: createItemsParser(['text', 'additionalInfo']),
|
|
161
172
|
},
|
|
173
|
+
{
|
|
174
|
+
fields: ['items'],
|
|
175
|
+
transformer: yfmTransformer,
|
|
176
|
+
parser: createItemsParser(['list.text']),
|
|
177
|
+
renderInline: true,
|
|
178
|
+
},
|
|
162
179
|
],
|
|
163
180
|
[BlockType.PromoFeaturesBlock]: [
|
|
164
181
|
...blockHeaderTransformer,
|
|
@@ -169,15 +186,13 @@ export const config = {
|
|
|
169
186
|
},
|
|
170
187
|
],
|
|
171
188
|
[BlockType.SliderOldBlock]: blockHeaderTransformer,
|
|
189
|
+
[BlockType.SliderBlock]: blockHeaderTransformer,
|
|
172
190
|
[BlockType.CompaniesBlock]: blockHeaderTransformer,
|
|
173
191
|
[BlockType.QuestionsBlock]: [
|
|
174
192
|
{
|
|
175
|
-
fields: ['title'],
|
|
176
|
-
transformer: typografTransformer,
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
fields: ['text', 'additionalInfo'],
|
|
193
|
+
fields: ['title', 'text', 'additionalInfo'],
|
|
180
194
|
transformer: yfmTransformer,
|
|
195
|
+
renderInline: true,
|
|
181
196
|
},
|
|
182
197
|
{
|
|
183
198
|
fields: ['items'],
|
|
@@ -188,7 +203,8 @@ export const config = {
|
|
|
188
203
|
[BlockType.BannerBlock]: [
|
|
189
204
|
{
|
|
190
205
|
fields: ['title'],
|
|
191
|
-
transformer:
|
|
206
|
+
transformer: yfmTransformer,
|
|
207
|
+
renderInline: true,
|
|
192
208
|
},
|
|
193
209
|
{
|
|
194
210
|
fields: ['subtitle'],
|
|
@@ -198,7 +214,8 @@ export const config = {
|
|
|
198
214
|
[SubBlockType.BannerCard]: [
|
|
199
215
|
{
|
|
200
216
|
fields: ['title'],
|
|
201
|
-
transformer:
|
|
217
|
+
transformer: yfmTransformer,
|
|
218
|
+
renderInline: true,
|
|
202
219
|
},
|
|
203
220
|
{
|
|
204
221
|
fields: ['subtitle'],
|
|
@@ -208,7 +225,7 @@ export const config = {
|
|
|
208
225
|
[BlockType.MediaBlock]: [
|
|
209
226
|
...blockHeaderTransformer,
|
|
210
227
|
{
|
|
211
|
-
fields: ['
|
|
228
|
+
fields: ['additionalInfo'],
|
|
212
229
|
transformer: yfmTransformer,
|
|
213
230
|
},
|
|
214
231
|
{
|
|
@@ -233,27 +250,35 @@ export const config = {
|
|
|
233
250
|
},
|
|
234
251
|
{
|
|
235
252
|
fields: ['items'],
|
|
236
|
-
transformer:
|
|
253
|
+
transformer: yfmTransformer,
|
|
237
254
|
parser: parseItemsTitle,
|
|
255
|
+
renderInline: true,
|
|
238
256
|
},
|
|
239
257
|
],
|
|
240
258
|
[BlockType.TableBlock]: [
|
|
259
|
+
{
|
|
260
|
+
fields: ['title'],
|
|
261
|
+
transformer: yfmTransformer,
|
|
262
|
+
renderInline: true,
|
|
263
|
+
},
|
|
241
264
|
{
|
|
242
265
|
fields: ['table'],
|
|
243
266
|
transformer: yfmTransformer,
|
|
244
|
-
parser:
|
|
267
|
+
parser: parseTableBlockLegend,
|
|
245
268
|
},
|
|
246
|
-
],
|
|
247
|
-
[BlockType.HeaderSliderBlock]: [
|
|
248
269
|
{
|
|
249
|
-
fields: ['
|
|
250
|
-
transformer:
|
|
251
|
-
parser:
|
|
270
|
+
fields: ['table'],
|
|
271
|
+
transformer: yfmTransformer,
|
|
272
|
+
parser: parseTableBlockContent,
|
|
273
|
+
renderInline: true,
|
|
252
274
|
},
|
|
275
|
+
],
|
|
276
|
+
[BlockType.HeaderSliderBlock]: [
|
|
253
277
|
{
|
|
254
278
|
fields: ['items'],
|
|
255
279
|
transformer: yfmTransformer,
|
|
256
|
-
parser: createItemsParser(['description']),
|
|
280
|
+
parser: createItemsParser(['title', 'overtitle', 'description']),
|
|
281
|
+
renderInline: true,
|
|
257
282
|
},
|
|
258
283
|
],
|
|
259
284
|
[SubBlockType.PriceDetailed]: [
|
|
@@ -267,6 +292,11 @@ export const config = {
|
|
|
267
292
|
fields: ['description'],
|
|
268
293
|
transformer: yfmTransformer,
|
|
269
294
|
},
|
|
295
|
+
{
|
|
296
|
+
fields: ['overtitle', 'title'],
|
|
297
|
+
transformer: yfmTransformer,
|
|
298
|
+
renderInline: true,
|
|
299
|
+
},
|
|
270
300
|
],
|
|
271
301
|
[BlockType.ContentLayoutBlock]: [
|
|
272
302
|
{
|
|
@@ -276,8 +306,9 @@ export const config = {
|
|
|
276
306
|
},
|
|
277
307
|
{
|
|
278
308
|
fields: ['textContent'],
|
|
279
|
-
transformer:
|
|
309
|
+
transformer: yfmTransformer,
|
|
280
310
|
parser: parseContentLayoutTitle,
|
|
311
|
+
renderInline: true,
|
|
281
312
|
},
|
|
282
313
|
],
|
|
283
314
|
[SubBlockType.Content]: [
|
|
@@ -287,8 +318,9 @@ export const config = {
|
|
|
287
318
|
},
|
|
288
319
|
{
|
|
289
320
|
fields: ['title'],
|
|
290
|
-
transformer:
|
|
321
|
+
transformer: yfmTransformer,
|
|
291
322
|
parser: parseTitle,
|
|
323
|
+
renderInline: true,
|
|
292
324
|
},
|
|
293
325
|
{
|
|
294
326
|
fields: ['list'],
|
|
@@ -297,6 +329,11 @@ export const config = {
|
|
|
297
329
|
},
|
|
298
330
|
],
|
|
299
331
|
[BlockType.InfoBlock]: [
|
|
332
|
+
{
|
|
333
|
+
fields: ['title'],
|
|
334
|
+
transformer: yfmTransformer,
|
|
335
|
+
renderInline: true,
|
|
336
|
+
},
|
|
300
337
|
{
|
|
301
338
|
fields: ['rightContent', 'leftContent'],
|
|
302
339
|
transformer: yfmTransformer,
|
|
@@ -304,14 +341,16 @@ export const config = {
|
|
|
304
341
|
},
|
|
305
342
|
{
|
|
306
343
|
fields: ['rightContent', 'leftContent'],
|
|
307
|
-
transformer:
|
|
344
|
+
transformer: yfmTransformer,
|
|
308
345
|
parser: parseContentLayoutTitle,
|
|
346
|
+
renderInline: true,
|
|
309
347
|
},
|
|
310
348
|
],
|
|
311
349
|
[BlockType.ShareBlock]: [
|
|
312
350
|
{
|
|
313
351
|
fields: ['title'],
|
|
314
|
-
transformer:
|
|
352
|
+
transformer: yfmTransformer,
|
|
353
|
+
renderInline: true,
|
|
315
354
|
},
|
|
316
355
|
],
|
|
317
356
|
[BlockType.CardLayoutBlock]: blockHeaderTransformer,
|
|
@@ -320,12 +359,13 @@ export const config = {
|
|
|
320
359
|
[SubBlockType.PriceCard]: [
|
|
321
360
|
{
|
|
322
361
|
fields: ['title'],
|
|
323
|
-
transformer:
|
|
362
|
+
transformer: yfmTransformer,
|
|
363
|
+
renderInline: true,
|
|
324
364
|
},
|
|
325
365
|
{
|
|
326
366
|
fields: ['list'],
|
|
327
367
|
transformer: yfmTransformer,
|
|
328
|
-
parser: createItemsParser(['text']),
|
|
368
|
+
parser: createItemsParser(['title', 'text']),
|
|
329
369
|
},
|
|
330
370
|
],
|
|
331
371
|
[BlockType.FormBlock]: [
|
|
@@ -336,8 +376,9 @@ export const config = {
|
|
|
336
376
|
},
|
|
337
377
|
{
|
|
338
378
|
fields: ['textContent'],
|
|
339
|
-
transformer:
|
|
379
|
+
transformer: yfmTransformer,
|
|
340
380
|
parser: parseContentLayoutTitle,
|
|
381
|
+
renderInline: true,
|
|
341
382
|
},
|
|
342
383
|
],
|
|
343
384
|
};
|
|
@@ -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 } = transformConfig;
|
|
21
|
+
const { fields, transformer: transformerRaw, parser, renderInline } = 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, renderInline });
|
|
25
25
|
if (fields) {
|
|
26
26
|
fields.forEach((field) => {
|
|
27
27
|
if (block[field]) {
|