@gravity-ui/page-constructor 6.0.0-alpha.3 → 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/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/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/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/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
package/README.md
CHANGED
|
@@ -146,6 +146,10 @@ const post = {
|
|
|
146
146
|
|
|
147
147
|
You can find more utilities in this [section](https://github.com/gravity-ui/page-constructor/tree/main/src/text-transform)
|
|
148
148
|
|
|
149
|
+
### Detailed Documentation on Server Utilities and Transformers
|
|
150
|
+
|
|
151
|
+
For a comprehensive guide on using server utilities, including detailed explanations and advanced use cases, visit the [additional chapter on server utils usage](./docs/data-preparation.md).
|
|
152
|
+
|
|
149
153
|
### Custom blocks
|
|
150
154
|
|
|
151
155
|
The page constructor lets you use blocks that are user-defined in their app. Blocks are regular React components.
|
|
@@ -69,7 +69,16 @@ export declare const SliderProps: {
|
|
|
69
69
|
type: string;
|
|
70
70
|
patternProperties: {
|
|
71
71
|
'.*': {
|
|
72
|
-
|
|
72
|
+
oneOf: ({
|
|
73
|
+
type: string[];
|
|
74
|
+
additionalProperties?: undefined;
|
|
75
|
+
} | {
|
|
76
|
+
type: string;
|
|
77
|
+
additionalProperties: boolean;
|
|
78
|
+
} | {
|
|
79
|
+
type: string;
|
|
80
|
+
additionalProperties?: undefined;
|
|
81
|
+
})[];
|
|
73
82
|
};
|
|
74
83
|
};
|
|
75
84
|
};
|
|
@@ -193,7 +202,16 @@ export declare const SliderBlock: {
|
|
|
193
202
|
type: string;
|
|
194
203
|
patternProperties: {
|
|
195
204
|
'.*': {
|
|
196
|
-
|
|
205
|
+
oneOf: ({
|
|
206
|
+
type: string[];
|
|
207
|
+
additionalProperties?: undefined;
|
|
208
|
+
} | {
|
|
209
|
+
type: string;
|
|
210
|
+
additionalProperties: boolean;
|
|
211
|
+
} | {
|
|
212
|
+
type: string;
|
|
213
|
+
additionalProperties?: undefined;
|
|
214
|
+
})[];
|
|
197
215
|
};
|
|
198
216
|
};
|
|
199
217
|
};
|
|
@@ -21,7 +21,18 @@ const LoadableProps = {
|
|
|
21
21
|
type: 'object',
|
|
22
22
|
patternProperties: {
|
|
23
23
|
'.*': {
|
|
24
|
-
|
|
24
|
+
oneOf: [
|
|
25
|
+
{
|
|
26
|
+
type: ['string', 'number', 'boolean'],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: 'object',
|
|
30
|
+
additionalProperties: true,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: 'array',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
25
36
|
},
|
|
26
37
|
},
|
|
27
38
|
},
|
|
@@ -60,7 +60,16 @@ export declare const SliderOldProps: {
|
|
|
60
60
|
type: string;
|
|
61
61
|
patternProperties: {
|
|
62
62
|
'.*': {
|
|
63
|
-
|
|
63
|
+
oneOf: ({
|
|
64
|
+
type: string[];
|
|
65
|
+
additionalProperties?: undefined;
|
|
66
|
+
} | {
|
|
67
|
+
type: string;
|
|
68
|
+
additionalProperties: boolean;
|
|
69
|
+
} | {
|
|
70
|
+
type: string;
|
|
71
|
+
additionalProperties?: undefined;
|
|
72
|
+
})[];
|
|
64
73
|
};
|
|
65
74
|
};
|
|
66
75
|
};
|
|
@@ -176,7 +185,16 @@ export declare const SliderOldBlock: {
|
|
|
176
185
|
type: string;
|
|
177
186
|
patternProperties: {
|
|
178
187
|
'.*': {
|
|
179
|
-
|
|
188
|
+
oneOf: ({
|
|
189
|
+
type: string[];
|
|
190
|
+
additionalProperties?: undefined;
|
|
191
|
+
} | {
|
|
192
|
+
type: string;
|
|
193
|
+
additionalProperties: boolean;
|
|
194
|
+
} | {
|
|
195
|
+
type: string;
|
|
196
|
+
additionalProperties?: undefined;
|
|
197
|
+
})[];
|
|
180
198
|
};
|
|
181
199
|
};
|
|
182
200
|
};
|
|
@@ -21,7 +21,18 @@ const LoadableProps = {
|
|
|
21
21
|
type: 'object',
|
|
22
22
|
patternProperties: {
|
|
23
23
|
'.*': {
|
|
24
|
-
|
|
24
|
+
oneOf: [
|
|
25
|
+
{
|
|
26
|
+
type: ['string', 'number', 'boolean'],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: 'object',
|
|
30
|
+
additionalProperties: true,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: 'array',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
25
36
|
},
|
|
26
37
|
},
|
|
27
38
|
},
|
|
@@ -50,7 +50,7 @@ export interface LoadableProps {
|
|
|
50
50
|
* @deprecated Will be moved to params
|
|
51
51
|
*/
|
|
52
52
|
serviceId?: number;
|
|
53
|
-
params?: Record<string, string | number | boolean>;
|
|
53
|
+
params?: Record<string, string | number | boolean | object>;
|
|
54
54
|
}
|
|
55
55
|
export interface LoadableChildren {
|
|
56
56
|
loadable?: LoadableProps;
|
|
@@ -1,18 +1,19 @@
|
|
|
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 | object;
|
|
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;
|
|
10
11
|
}) => string;
|
|
11
12
|
export type Parser<T = any> = (transformer: Transformer, block: T) => T;
|
|
12
13
|
export declare const createItemsParser: (fields: string[]) => (transformer: Transformer, items: Item[]) => (string | {
|
|
13
|
-
[x: string]: string;
|
|
14
|
+
[x: string]: string | object;
|
|
14
15
|
} | null)[];
|
|
15
16
|
export declare function yfmTransformer(lang: Lang, content: string, options?: {
|
|
16
17
|
plugins?: MarkdownItPluginCb[];
|
|
17
|
-
}): string;
|
|
18
|
+
}, renderInline?: boolean): string;
|
|
18
19
|
export declare function typografTransformer(lang: Lang, content: string): string;
|
|
@@ -4,29 +4,52 @@ exports.typografTransformer = exports.yfmTransformer = exports.createItemsParser
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const plugins_1 = tslib_1.__importDefault(require("@diplodoc/transform/lib/plugins"));
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
-
const createItemsParser = (fields) => (transformer, items) =>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
7
|
+
const createItemsParser = (fields) => (transformer, items) => {
|
|
8
|
+
const applyTransform = (itemLocal) => typeof itemLocal === 'string' ? transformer(itemLocal) : itemLocal;
|
|
9
|
+
return items.map((item) => {
|
|
10
|
+
if (!item) {
|
|
11
|
+
return item;
|
|
12
|
+
}
|
|
13
|
+
else if (typeof item === 'string') {
|
|
14
|
+
return transformer(item);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return Object.assign(Object.assign({}, item), fields.reduce((acc, fieldName) => {
|
|
18
|
+
if (fieldName.includes('.')) {
|
|
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]: applyTransform(subItem[secondProperty]) })));
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// eslint-disable-next-line no-param-reassign
|
|
34
|
+
acc[firstProperty] = Object.assign(Object.assign({}, root), { [secondProperty]: applyTransform(root[secondProperty]) });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (item[fieldName]) {
|
|
38
|
+
// eslint-disable-next-line no-param-reassign
|
|
39
|
+
acc[fieldName] = applyTransform(item[fieldName]);
|
|
40
|
+
}
|
|
41
|
+
return acc;
|
|
42
|
+
}, {}));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
24
46
|
exports.createItemsParser = createItemsParser;
|
|
25
|
-
function yfmTransformer(lang, content, options = {}) {
|
|
47
|
+
function yfmTransformer(lang, content, options = {}, renderInline = false) {
|
|
26
48
|
const { plugins = [] } = options;
|
|
27
49
|
const { html } = (0, utils_1.fullTransform)(content, {
|
|
28
50
|
lang,
|
|
29
51
|
plugins: [...plugins_1.default, ...plugins],
|
|
52
|
+
renderInline,
|
|
30
53
|
});
|
|
31
54
|
return html;
|
|
32
55
|
}
|
|
@@ -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;
|
|
@@ -6,10 +6,26 @@ exports.config = exports.blockHeaderTransformer = void 0;
|
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
7
|
const models_1 = require("../models");
|
|
8
8
|
const common_1 = require("./common");
|
|
9
|
-
function
|
|
9
|
+
function parseTableBlockLegend(transformer, content) {
|
|
10
10
|
const legend = content === null || content === void 0 ? void 0 : content.legend;
|
|
11
11
|
return Object.assign(Object.assign({}, (content || {})), { legend: legend && legend.map((string) => transformer(string)) });
|
|
12
12
|
}
|
|
13
|
+
function parseTableBlockContent(transformer, content) {
|
|
14
|
+
const legend = content === null || content === void 0 ? void 0 : content.legend;
|
|
15
|
+
const tableContent = content === null || content === void 0 ? void 0 : content.content;
|
|
16
|
+
return Object.assign(Object.assign({}, (content || {})), { content: tableContent &&
|
|
17
|
+
tableContent.map((row, i) => row.map((cell, j) => {
|
|
18
|
+
if (legend) {
|
|
19
|
+
if (i === 0 || j === 0) {
|
|
20
|
+
return transformer(cell);
|
|
21
|
+
}
|
|
22
|
+
return cell;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return transformer(cell);
|
|
26
|
+
}
|
|
27
|
+
})) });
|
|
28
|
+
}
|
|
13
29
|
function parseFeatures(transformer, items) {
|
|
14
30
|
return items.map((_a) => {
|
|
15
31
|
var { title, text } = _a, rest = tslib_1.__rest(_a, ["title", "text"]);
|
|
@@ -84,8 +100,9 @@ function parseContentLayoutTitle(transformer, content) {
|
|
|
84
100
|
exports.blockHeaderTransformer = [
|
|
85
101
|
{
|
|
86
102
|
fields: ['title'],
|
|
87
|
-
transformer: common_1.
|
|
103
|
+
transformer: common_1.yfmTransformer,
|
|
88
104
|
parser: parseTitle,
|
|
105
|
+
renderInline: true,
|
|
89
106
|
},
|
|
90
107
|
{
|
|
91
108
|
fields: ['description'],
|
|
@@ -142,26 +159,30 @@ exports.config = {
|
|
|
142
159
|
],
|
|
143
160
|
[models_1.SubBlockType.Quote]: [
|
|
144
161
|
{
|
|
145
|
-
fields: ['text'],
|
|
146
|
-
transformer: common_1.typografTransformer,
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
fields: ['yfmText'],
|
|
162
|
+
fields: ['text', 'yfmText'],
|
|
150
163
|
transformer: common_1.yfmTransformer,
|
|
164
|
+
renderInline: true,
|
|
151
165
|
},
|
|
152
166
|
],
|
|
153
167
|
[models_1.BlockType.ExtendedFeaturesBlock]: [
|
|
154
168
|
...exports.blockHeaderTransformer,
|
|
155
169
|
{
|
|
156
170
|
fields: ['items'],
|
|
157
|
-
transformer: common_1.
|
|
171
|
+
transformer: common_1.yfmTransformer,
|
|
158
172
|
parser: (0, common_1.createItemsParser)(['title']),
|
|
173
|
+
renderInline: true,
|
|
159
174
|
},
|
|
160
175
|
{
|
|
161
176
|
fields: ['items'],
|
|
162
177
|
transformer: common_1.yfmTransformer,
|
|
163
178
|
parser: (0, common_1.createItemsParser)(['text', 'additionalInfo']),
|
|
164
179
|
},
|
|
180
|
+
{
|
|
181
|
+
fields: ['items'],
|
|
182
|
+
transformer: common_1.yfmTransformer,
|
|
183
|
+
parser: (0, common_1.createItemsParser)(['list.text']),
|
|
184
|
+
renderInline: true,
|
|
185
|
+
},
|
|
165
186
|
],
|
|
166
187
|
[models_1.BlockType.PromoFeaturesBlock]: [
|
|
167
188
|
...exports.blockHeaderTransformer,
|
|
@@ -191,7 +212,8 @@ exports.config = {
|
|
|
191
212
|
[models_1.BlockType.BannerBlock]: [
|
|
192
213
|
{
|
|
193
214
|
fields: ['title'],
|
|
194
|
-
transformer: common_1.
|
|
215
|
+
transformer: common_1.yfmTransformer,
|
|
216
|
+
renderInline: true,
|
|
195
217
|
},
|
|
196
218
|
{
|
|
197
219
|
fields: ['subtitle'],
|
|
@@ -244,7 +266,13 @@ exports.config = {
|
|
|
244
266
|
{
|
|
245
267
|
fields: ['table'],
|
|
246
268
|
transformer: common_1.yfmTransformer,
|
|
247
|
-
parser:
|
|
269
|
+
parser: parseTableBlockLegend,
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
fields: ['table'],
|
|
273
|
+
transformer: common_1.yfmTransformer,
|
|
274
|
+
parser: parseTableBlockContent,
|
|
275
|
+
renderInline: true,
|
|
248
276
|
},
|
|
249
277
|
],
|
|
250
278
|
[models_1.BlockType.HeaderSliderBlock]: [
|
|
@@ -270,6 +298,11 @@ exports.config = {
|
|
|
270
298
|
fields: ['description'],
|
|
271
299
|
transformer: common_1.yfmTransformer,
|
|
272
300
|
},
|
|
301
|
+
{
|
|
302
|
+
fields: ['overtitle', 'title'],
|
|
303
|
+
transformer: common_1.yfmTransformer,
|
|
304
|
+
renderInline: true,
|
|
305
|
+
},
|
|
273
306
|
],
|
|
274
307
|
[models_1.BlockType.ContentLayoutBlock]: [
|
|
275
308
|
{
|
|
@@ -323,7 +356,8 @@ exports.config = {
|
|
|
323
356
|
[models_1.SubBlockType.PriceCard]: [
|
|
324
357
|
{
|
|
325
358
|
fields: ['title'],
|
|
326
|
-
transformer: common_1.
|
|
359
|
+
transformer: common_1.yfmTransformer,
|
|
360
|
+
renderInline: true,
|
|
327
361
|
},
|
|
328
362
|
{
|
|
329
363
|
fields: ['list'],
|
|
@@ -22,10 +22,10 @@ function transformBlock(lang, blocksConfig, block, plugins) {
|
|
|
22
22
|
if (blockConfig) {
|
|
23
23
|
const configs = Array.isArray(blockConfig) ? blockConfig : [blockConfig];
|
|
24
24
|
configs.forEach((transformConfig) => {
|
|
25
|
-
const { fields, transformer: transformerRaw, parser } = transformConfig;
|
|
25
|
+
const { fields, transformer: transformerRaw, parser, renderInline } = transformConfig;
|
|
26
26
|
const transformer = (content) =>
|
|
27
27
|
// eslint-disable-next-line no-useless-call
|
|
28
|
-
transformerRaw.call(null, lang, content, { plugins });
|
|
28
|
+
transformerRaw.call(null, lang, content, { plugins, renderInline });
|
|
29
29
|
if (fields) {
|
|
30
30
|
fields.forEach((field) => {
|
|
31
31
|
if (block[field]) {
|
|
@@ -69,7 +69,16 @@ export declare const SliderProps: {
|
|
|
69
69
|
type: string;
|
|
70
70
|
patternProperties: {
|
|
71
71
|
'.*': {
|
|
72
|
-
|
|
72
|
+
oneOf: ({
|
|
73
|
+
type: string[];
|
|
74
|
+
additionalProperties?: undefined;
|
|
75
|
+
} | {
|
|
76
|
+
type: string;
|
|
77
|
+
additionalProperties: boolean;
|
|
78
|
+
} | {
|
|
79
|
+
type: string;
|
|
80
|
+
additionalProperties?: undefined;
|
|
81
|
+
})[];
|
|
73
82
|
};
|
|
74
83
|
};
|
|
75
84
|
};
|
|
@@ -193,7 +202,16 @@ export declare const SliderBlock: {
|
|
|
193
202
|
type: string;
|
|
194
203
|
patternProperties: {
|
|
195
204
|
'.*': {
|
|
196
|
-
|
|
205
|
+
oneOf: ({
|
|
206
|
+
type: string[];
|
|
207
|
+
additionalProperties?: undefined;
|
|
208
|
+
} | {
|
|
209
|
+
type: string;
|
|
210
|
+
additionalProperties: boolean;
|
|
211
|
+
} | {
|
|
212
|
+
type: string;
|
|
213
|
+
additionalProperties?: undefined;
|
|
214
|
+
})[];
|
|
197
215
|
};
|
|
198
216
|
};
|
|
199
217
|
};
|
|
@@ -18,7 +18,18 @@ const LoadableProps = {
|
|
|
18
18
|
type: 'object',
|
|
19
19
|
patternProperties: {
|
|
20
20
|
'.*': {
|
|
21
|
-
|
|
21
|
+
oneOf: [
|
|
22
|
+
{
|
|
23
|
+
type: ['string', 'number', 'boolean'],
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
type: 'object',
|
|
27
|
+
additionalProperties: true,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: 'array',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
22
33
|
},
|
|
23
34
|
},
|
|
24
35
|
},
|
|
@@ -60,7 +60,16 @@ export declare const SliderOldProps: {
|
|
|
60
60
|
type: string;
|
|
61
61
|
patternProperties: {
|
|
62
62
|
'.*': {
|
|
63
|
-
|
|
63
|
+
oneOf: ({
|
|
64
|
+
type: string[];
|
|
65
|
+
additionalProperties?: undefined;
|
|
66
|
+
} | {
|
|
67
|
+
type: string;
|
|
68
|
+
additionalProperties: boolean;
|
|
69
|
+
} | {
|
|
70
|
+
type: string;
|
|
71
|
+
additionalProperties?: undefined;
|
|
72
|
+
})[];
|
|
64
73
|
};
|
|
65
74
|
};
|
|
66
75
|
};
|
|
@@ -176,7 +185,16 @@ export declare const SliderOldBlock: {
|
|
|
176
185
|
type: string;
|
|
177
186
|
patternProperties: {
|
|
178
187
|
'.*': {
|
|
179
|
-
|
|
188
|
+
oneOf: ({
|
|
189
|
+
type: string[];
|
|
190
|
+
additionalProperties?: undefined;
|
|
191
|
+
} | {
|
|
192
|
+
type: string;
|
|
193
|
+
additionalProperties: boolean;
|
|
194
|
+
} | {
|
|
195
|
+
type: string;
|
|
196
|
+
additionalProperties?: undefined;
|
|
197
|
+
})[];
|
|
180
198
|
};
|
|
181
199
|
};
|
|
182
200
|
};
|
|
@@ -18,7 +18,18 @@ const LoadableProps = {
|
|
|
18
18
|
type: 'object',
|
|
19
19
|
patternProperties: {
|
|
20
20
|
'.*': {
|
|
21
|
-
|
|
21
|
+
oneOf: [
|
|
22
|
+
{
|
|
23
|
+
type: ['string', 'number', 'boolean'],
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
type: 'object',
|
|
27
|
+
additionalProperties: true,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: 'array',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
22
33
|
},
|
|
23
34
|
},
|
|
24
35
|
},
|
|
@@ -50,7 +50,7 @@ export interface LoadableProps {
|
|
|
50
50
|
* @deprecated Will be moved to params
|
|
51
51
|
*/
|
|
52
52
|
serviceId?: number;
|
|
53
|
-
params?: Record<string, string | number | boolean>;
|
|
53
|
+
params?: Record<string, string | number | boolean | object>;
|
|
54
54
|
}
|
|
55
55
|
export interface LoadableChildren {
|
|
56
56
|
loadable?: LoadableProps;
|
|
@@ -1,18 +1,19 @@
|
|
|
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 | object;
|
|
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;
|
|
10
11
|
}) => string;
|
|
11
12
|
export type Parser<T = any> = (transformer: Transformer, block: T) => T;
|
|
12
13
|
export declare const createItemsParser: (fields: string[]) => (transformer: Transformer, items: Item[]) => (string | {
|
|
13
|
-
[x: string]: string;
|
|
14
|
+
[x: string]: string | object;
|
|
14
15
|
} | null)[];
|
|
15
16
|
export declare function yfmTransformer(lang: Lang, content: string, options?: {
|
|
16
17
|
plugins?: MarkdownItPluginCb[];
|
|
17
|
-
}): string;
|
|
18
|
+
}, renderInline?: boolean): string;
|
|
18
19
|
export declare function typografTransformer(lang: Lang, content: string): string;
|
|
@@ -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;
|