@gravity-ui/page-constructor 4.8.0 → 4.9.1-alpha.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/README.md CHANGED
@@ -386,3 +386,7 @@ export const MyAppEditor = ({initialContent, onChange, transformContent}: MyAppE
386
386
  <Editor content={initialContent} onChange={onChange} transformContent={transformContent} />
387
387
  );
388
388
  ```
389
+
390
+ ## Tests
391
+
392
+ Comprehensive documentation is available at the provided [link](./test-utils/docs/README.md).
@@ -5,8 +5,6 @@ unpredictable css rules order in build */
5
5
  line-height: var(--g-text-body-2-line-height);
6
6
  display: flex;
7
7
  align-items: center;
8
- font-weight: 500;
9
- color: var(--pc-media-card-meta-info-color);
10
8
  }
11
9
  .pc-meta-info__item:not(:first-child) {
12
10
  margin-left: 16px;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const react_1 = tslib_1.__importDefault(require("react"));
5
5
  const utils_1 = require("../../utils");
6
+ const index_1 = require("../index");
6
7
  const b = (0, utils_1.block)('meta-info');
7
- const MetaInfo = ({ items, className }) => (react_1.default.createElement("h4", { className: b(null, className) }, items.map((metaInfoItem) => (react_1.default.createElement("span", { key: metaInfoItem, className: b('item') }, metaInfoItem)))));
8
+ const MetaInfo = ({ items, className }) => (react_1.default.createElement("h4", { className: b(null, className) }, items.map((metaInfoItem) => (react_1.default.createElement(index_1.YFMWrapper, { content: metaInfoItem, key: metaInfoItem, className: b('item'), modifiers: { constructor: true, constructorMetaInfo: true } })))));
8
9
  exports.default = MetaInfo;
@@ -84,6 +84,10 @@ unpredictable css rules order in build */
84
84
  .yfm_constructor.yfm_constructor_notice p {
85
85
  color: var(--g-color-text-secondary);
86
86
  }
87
+ .yfm_constructor.yfm_constructor_meta_info p {
88
+ color: var(--pc-media-card-meta-info-color);
89
+ font-weight: var(--g-text-accent-font-weight);
90
+ }
87
91
  .yfm_constructor.yfm_constructor ul,
88
92
  .yfm_constructor.yfm_constructor ol,
89
93
  .yfm_constructor.yfm_constructor li,
@@ -1,13 +1,14 @@
1
+ import { MarkdownItPluginCb } from '@doc-tools/transform/lib/plugins/typings';
1
2
  import { Lang } from '../utils/configure';
2
3
  export type ComplexItem = {
3
4
  [key: string]: string;
4
5
  };
5
6
  export type Item = string | null | ComplexItem;
6
7
  export type Transformer = (text: string) => string;
7
- export type TransformerRaw = (lang: Lang, content: string) => string;
8
+ export type TransformerRaw = (lang: Lang, content: string, additionalPlugins: MarkdownItPluginCb[]) => string;
8
9
  export type Parser<T = any> = (transformer: Transformer, block: T) => T;
9
10
  export declare const createItemsParser: (fields: string[]) => (transformer: Transformer, items: Item[]) => (string | {
10
11
  [x: string]: string;
11
12
  } | null)[];
12
- export declare function yfmTransformer(lang: Lang, content: string): string;
13
+ export declare function yfmTransformer(lang: Lang, content: string, additionalPlugins?: MarkdownItPluginCb[]): string;
13
14
  export declare function typografTransformer(lang: Lang, content: string): string;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.typografTransformer = exports.yfmTransformer = exports.createItemsParser = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const plugins_1 = tslib_1.__importDefault(require("@doc-tools/transform/lib/plugins"));
4
6
  const utils_1 = require("./utils");
5
7
  const createItemsParser = (fields) => (transformer, items) => items.map((item) => {
6
8
  if (!item) {
@@ -20,8 +22,11 @@ const createItemsParser = (fields) => (transformer, items) => items.map((item) =
20
22
  }
21
23
  });
22
24
  exports.createItemsParser = createItemsParser;
23
- function yfmTransformer(lang, content) {
24
- const { html } = (0, utils_1.fullTransform)(content, { lang });
25
+ function yfmTransformer(lang, content, additionalPlugins = []) {
26
+ const { html } = (0, utils_1.fullTransform)(content, {
27
+ lang,
28
+ plugins: [...plugins_1.default, ...additionalPlugins],
29
+ });
25
30
  return html;
26
31
  }
27
32
  exports.yfmTransformer = yfmTransformer;
@@ -125,7 +125,7 @@ exports.config = {
125
125
  {
126
126
  fields: ['metaInfo'],
127
127
  parser: (0, common_1.createItemsParser)([]),
128
- transformer: common_1.typografTransformer,
128
+ transformer: common_1.yfmTransformer,
129
129
  },
130
130
  ],
131
131
  [models_1.SubBlockType.Quote]: {
@@ -1,3 +1,4 @@
1
+ import { MarkdownItPluginCb } from '@doc-tools/transform/lib/plugins/typings';
1
2
  import { ConstructorBlock } from '../models/constructor';
2
3
  import { Lang } from '../utils/configure';
3
4
  export type ContentVariables = Record<string, string>;
@@ -9,6 +10,7 @@ export type ContentTransformerProps = {
9
10
  lang: Lang;
10
11
  customConfig?: {};
11
12
  vars?: ContentVariables;
13
+ additionalPlugins?: MarkdownItPluginCb[];
12
14
  };
13
15
  };
14
16
  export declare const contentTransformer: ({ content, options }: ContentTransformerProps) => {
@@ -2,17 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.contentTransformer = void 0;
4
4
  const tslib_1 = require("tslib");
5
- /* eslint-disable no-param-reassign */
6
- /* eslint-disable no-not-accumulator-reassign/no-not-accumulator-reassign */
7
5
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
8
6
  const config_1 = require("./config");
9
7
  const filter_1 = require("./filter");
10
- function transformBlocks(blocks, lang, customConfig = {}) {
8
+ function transformBlocks(blocks, lang, customConfig = {}, additionalPlugins = []) {
11
9
  const fullConfig = Object.assign(Object.assign({}, config_1.config), customConfig);
12
10
  const clonedBlocks = lodash_1.default.cloneDeep(blocks);
13
- return clonedBlocks.map((block) => transformBlock(lang, fullConfig, block));
11
+ return clonedBlocks.map((block) => transformBlock(lang, fullConfig, block, additionalPlugins));
14
12
  }
15
- function transformBlock(lang, blocksConfig, block) {
13
+ function transformBlock(lang, blocksConfig, block, additionalPlugins) {
16
14
  const blockConfig = blocksConfig[block.type];
17
15
  if (block) {
18
16
  if ('randomOrder' in block && block.randomOrder && 'children' in block && block.children) {
@@ -23,7 +21,7 @@ function transformBlock(lang, blocksConfig, block) {
23
21
  const configs = Array.isArray(blockConfig) ? blockConfig : [blockConfig];
24
22
  configs.forEach((transformConfig) => {
25
23
  const { fields, transformer: transformerRaw, parser } = transformConfig;
26
- const transformer = transformerRaw.bind(null, lang);
24
+ const transformer = (content) => transformerRaw(lang, content, additionalPlugins);
27
25
  if (fields) {
28
26
  fields.forEach((field) => {
29
27
  if (block[field]) {
@@ -47,9 +45,9 @@ function transformBlock(lang, blocksConfig, block) {
47
45
  return block;
48
46
  }
49
47
  const contentTransformer = ({ content, options }) => {
50
- const { lang, customConfig = {}, vars } = options;
48
+ const { lang, customConfig = {}, vars, additionalPlugins = [] } = options;
51
49
  const { blocks = [] } = (vars ? (0, filter_1.filterContent)(content, vars) : content);
52
- const transformedBlocks = transformBlocks(blocks, lang, customConfig);
50
+ const transformedBlocks = transformBlocks(blocks, lang, customConfig, additionalPlugins);
53
51
  return {
54
52
  blocks: transformedBlocks,
55
53
  };
@@ -5,8 +5,6 @@ unpredictable css rules order in build */
5
5
  line-height: var(--g-text-body-2-line-height);
6
6
  display: flex;
7
7
  align-items: center;
8
- font-weight: 500;
9
- color: var(--pc-media-card-meta-info-color);
10
8
  }
11
9
  .pc-meta-info__item:not(:first-child) {
12
10
  margin-left: 16px;
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { block } from '../../utils';
3
+ import { YFMWrapper } from '../index';
3
4
  import './MetaInfo.css';
4
5
  const b = block('meta-info');
5
- const MetaInfo = ({ items, className }) => (React.createElement("h4", { className: b(null, className) }, items.map((metaInfoItem) => (React.createElement("span", { key: metaInfoItem, className: b('item') }, metaInfoItem)))));
6
+ const MetaInfo = ({ items, className }) => (React.createElement("h4", { className: b(null, className) }, items.map((metaInfoItem) => (React.createElement(YFMWrapper, { content: metaInfoItem, key: metaInfoItem, className: b('item'), modifiers: { constructor: true, constructorMetaInfo: true } })))));
6
7
  export default MetaInfo;
@@ -84,6 +84,10 @@ unpredictable css rules order in build */
84
84
  .yfm_constructor.yfm_constructor_notice p {
85
85
  color: var(--g-color-text-secondary);
86
86
  }
87
+ .yfm_constructor.yfm_constructor_meta_info p {
88
+ color: var(--pc-media-card-meta-info-color);
89
+ font-weight: var(--g-text-accent-font-weight);
90
+ }
87
91
  .yfm_constructor.yfm_constructor ul,
88
92
  .yfm_constructor.yfm_constructor ol,
89
93
  .yfm_constructor.yfm_constructor li,
@@ -1,13 +1,14 @@
1
+ import { MarkdownItPluginCb } from '@doc-tools/transform/lib/plugins/typings';
1
2
  import { Lang } from '../utils/configure';
2
3
  export type ComplexItem = {
3
4
  [key: string]: string;
4
5
  };
5
6
  export type Item = string | null | ComplexItem;
6
7
  export type Transformer = (text: string) => string;
7
- export type TransformerRaw = (lang: Lang, content: string) => string;
8
+ export type TransformerRaw = (lang: Lang, content: string, additionalPlugins: MarkdownItPluginCb[]) => string;
8
9
  export type Parser<T = any> = (transformer: Transformer, block: T) => T;
9
10
  export declare const createItemsParser: (fields: string[]) => (transformer: Transformer, items: Item[]) => (string | {
10
11
  [x: string]: string;
11
12
  } | null)[];
12
- export declare function yfmTransformer(lang: Lang, content: string): string;
13
+ export declare function yfmTransformer(lang: Lang, content: string, additionalPlugins?: MarkdownItPluginCb[]): string;
13
14
  export declare function typografTransformer(lang: Lang, content: string): string;
@@ -1,3 +1,4 @@
1
+ import defaultPlugins from '@doc-tools/transform/lib/plugins';
1
2
  import { fullTransform, typografToHTML } from './utils';
2
3
  export const createItemsParser = (fields) => (transformer, items) => items.map((item) => {
3
4
  if (!item) {
@@ -16,8 +17,11 @@ export const createItemsParser = (fields) => (transformer, items) => items.map((
16
17
  }, {}));
17
18
  }
18
19
  });
19
- export function yfmTransformer(lang, content) {
20
- const { html } = fullTransform(content, { lang });
20
+ export function yfmTransformer(lang, content, additionalPlugins = []) {
21
+ const { html } = fullTransform(content, {
22
+ lang,
23
+ plugins: [...defaultPlugins, ...additionalPlugins],
24
+ });
21
25
  return html;
22
26
  }
23
27
  export function typografTransformer(lang, content) {
@@ -122,7 +122,7 @@ export const config = {
122
122
  {
123
123
  fields: ['metaInfo'],
124
124
  parser: createItemsParser([]),
125
- transformer: typografTransformer,
125
+ transformer: yfmTransformer,
126
126
  },
127
127
  ],
128
128
  [SubBlockType.Quote]: {
@@ -1,3 +1,4 @@
1
+ import { MarkdownItPluginCb } from '@doc-tools/transform/lib/plugins/typings';
1
2
  import { ConstructorBlock } from '../models/constructor';
2
3
  import { Lang } from '../utils/configure';
3
4
  export type ContentVariables = Record<string, string>;
@@ -9,6 +10,7 @@ export type ContentTransformerProps = {
9
10
  lang: Lang;
10
11
  customConfig?: {};
11
12
  vars?: ContentVariables;
13
+ additionalPlugins?: MarkdownItPluginCb[];
12
14
  };
13
15
  };
14
16
  export declare const contentTransformer: ({ content, options }: ContentTransformerProps) => {
@@ -1,14 +1,12 @@
1
- /* eslint-disable no-param-reassign */
2
- /* eslint-disable no-not-accumulator-reassign/no-not-accumulator-reassign */
3
1
  import _ from 'lodash';
4
2
  import { config } from './config';
5
3
  import { filterContent } from './filter';
6
- function transformBlocks(blocks, lang, customConfig = {}) {
4
+ function transformBlocks(blocks, lang, customConfig = {}, additionalPlugins = []) {
7
5
  const fullConfig = Object.assign(Object.assign({}, config), customConfig);
8
6
  const clonedBlocks = _.cloneDeep(blocks);
9
- return clonedBlocks.map((block) => transformBlock(lang, fullConfig, block));
7
+ return clonedBlocks.map((block) => transformBlock(lang, fullConfig, block, additionalPlugins));
10
8
  }
11
- function transformBlock(lang, blocksConfig, block) {
9
+ function transformBlock(lang, blocksConfig, block, additionalPlugins) {
12
10
  const blockConfig = blocksConfig[block.type];
13
11
  if (block) {
14
12
  if ('randomOrder' in block && block.randomOrder && 'children' in block && block.children) {
@@ -19,7 +17,7 @@ function transformBlock(lang, blocksConfig, block) {
19
17
  const configs = Array.isArray(blockConfig) ? blockConfig : [blockConfig];
20
18
  configs.forEach((transformConfig) => {
21
19
  const { fields, transformer: transformerRaw, parser } = transformConfig;
22
- const transformer = transformerRaw.bind(null, lang);
20
+ const transformer = (content) => transformerRaw(lang, content, additionalPlugins);
23
21
  if (fields) {
24
22
  fields.forEach((field) => {
25
23
  if (block[field]) {
@@ -43,9 +41,9 @@ function transformBlock(lang, blocksConfig, block) {
43
41
  return block;
44
42
  }
45
43
  export const contentTransformer = ({ content, options }) => {
46
- const { lang, customConfig = {}, vars } = options;
44
+ const { lang, customConfig = {}, vars, additionalPlugins = [] } = options;
47
45
  const { blocks = [] } = (vars ? filterContent(content, vars) : content);
48
- const transformedBlocks = transformBlocks(blocks, lang, customConfig);
46
+ const transformedBlocks = transformBlocks(blocks, lang, customConfig, additionalPlugins);
49
47
  return {
50
48
  blocks: transformedBlocks,
51
49
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/page-constructor",
3
- "version": "4.8.0",
3
+ "version": "4.9.1-alpha.0",
4
4
  "description": "Gravity UI Page Constructor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,13 +1,14 @@
1
+ import { MarkdownItPluginCb } from '@doc-tools/transform/lib/plugins/typings';
1
2
  import { Lang } from '../utils/configure';
2
3
  export type ComplexItem = {
3
4
  [key: string]: string;
4
5
  };
5
6
  export type Item = string | null | ComplexItem;
6
7
  export type Transformer = (text: string) => string;
7
- export type TransformerRaw = (lang: Lang, content: string) => string;
8
+ export type TransformerRaw = (lang: Lang, content: string, additionalPlugins: MarkdownItPluginCb[]) => string;
8
9
  export type Parser<T = any> = (transformer: Transformer, block: T) => T;
9
10
  export declare const createItemsParser: (fields: string[]) => (transformer: Transformer, items: Item[]) => (string | {
10
11
  [x: string]: string;
11
12
  } | null)[];
12
- export declare function yfmTransformer(lang: Lang, content: string): string;
13
+ export declare function yfmTransformer(lang: Lang, content: string, additionalPlugins?: MarkdownItPluginCb[]): string;
13
14
  export declare function typografTransformer(lang: Lang, content: string): string;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.typografTransformer = exports.yfmTransformer = exports.createItemsParser = void 0;
7
+ const plugins_1 = __importDefault(require("@doc-tools/transform/lib/plugins"));
4
8
  const utils_1 = require("./utils");
5
9
  const createItemsParser = (fields) => (transformer, items) => items.map((item) => {
6
10
  if (!item) {
@@ -20,8 +24,11 @@ const createItemsParser = (fields) => (transformer, items) => items.map((item) =
20
24
  }
21
25
  });
22
26
  exports.createItemsParser = createItemsParser;
23
- function yfmTransformer(lang, content) {
24
- const { html } = (0, utils_1.fullTransform)(content, { lang });
27
+ function yfmTransformer(lang, content, additionalPlugins = []) {
28
+ const { html } = (0, utils_1.fullTransform)(content, {
29
+ lang,
30
+ plugins: [...plugins_1.default, ...additionalPlugins],
31
+ });
25
32
  return html;
26
33
  }
27
34
  exports.yfmTransformer = yfmTransformer;
@@ -135,7 +135,7 @@ exports.config = {
135
135
  {
136
136
  fields: ['metaInfo'],
137
137
  parser: (0, common_1.createItemsParser)([]),
138
- transformer: common_1.typografTransformer,
138
+ transformer: common_1.yfmTransformer,
139
139
  },
140
140
  ],
141
141
  [models_1.SubBlockType.Quote]: {
@@ -1,3 +1,4 @@
1
+ import { MarkdownItPluginCb } from '@doc-tools/transform/lib/plugins/typings';
1
2
  import { ConstructorBlock } from '../models/constructor';
2
3
  import { Lang } from '../utils/configure';
3
4
  export type ContentVariables = Record<string, string>;
@@ -9,6 +10,7 @@ export type ContentTransformerProps = {
9
10
  lang: Lang;
10
11
  customConfig?: {};
11
12
  vars?: ContentVariables;
13
+ additionalPlugins?: MarkdownItPluginCb[];
12
14
  };
13
15
  };
14
16
  export declare const contentTransformer: ({ content, options }: ContentTransformerProps) => {
@@ -4,17 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.contentTransformer = void 0;
7
- /* eslint-disable no-param-reassign */
8
- /* eslint-disable no-not-accumulator-reassign/no-not-accumulator-reassign */
9
7
  const lodash_1 = __importDefault(require("lodash"));
10
8
  const config_1 = require("./config");
11
9
  const filter_1 = require("./filter");
12
- function transformBlocks(blocks, lang, customConfig = {}) {
10
+ function transformBlocks(blocks, lang, customConfig = {}, additionalPlugins = []) {
13
11
  const fullConfig = Object.assign(Object.assign({}, config_1.config), customConfig);
14
12
  const clonedBlocks = lodash_1.default.cloneDeep(blocks);
15
- return clonedBlocks.map((block) => transformBlock(lang, fullConfig, block));
13
+ return clonedBlocks.map((block) => transformBlock(lang, fullConfig, block, additionalPlugins));
16
14
  }
17
- function transformBlock(lang, blocksConfig, block) {
15
+ function transformBlock(lang, blocksConfig, block, additionalPlugins) {
18
16
  const blockConfig = blocksConfig[block.type];
19
17
  if (block) {
20
18
  if ('randomOrder' in block && block.randomOrder && 'children' in block && block.children) {
@@ -25,7 +23,7 @@ function transformBlock(lang, blocksConfig, block) {
25
23
  const configs = Array.isArray(blockConfig) ? blockConfig : [blockConfig];
26
24
  configs.forEach((transformConfig) => {
27
25
  const { fields, transformer: transformerRaw, parser } = transformConfig;
28
- const transformer = transformerRaw.bind(null, lang);
26
+ const transformer = (content) => transformerRaw(lang, content, additionalPlugins);
29
27
  if (fields) {
30
28
  fields.forEach((field) => {
31
29
  if (block[field]) {
@@ -49,9 +47,9 @@ function transformBlock(lang, blocksConfig, block) {
49
47
  return block;
50
48
  }
51
49
  const contentTransformer = ({ content, options }) => {
52
- const { lang, customConfig = {}, vars } = options;
50
+ const { lang, customConfig = {}, vars, additionalPlugins = [] } = options;
53
51
  const { blocks = [] } = (vars ? (0, filter_1.filterContent)(content, vars) : content);
54
- const transformedBlocks = transformBlocks(blocks, lang, customConfig);
52
+ const transformedBlocks = transformBlocks(blocks, lang, customConfig, additionalPlugins);
55
53
  return {
56
54
  blocks: transformedBlocks,
57
55
  };
package/styles/styles.css CHANGED
@@ -30,6 +30,10 @@ unpredictable css rules order in build */
30
30
  .yfm_constructor.yfm_constructor_notice p {
31
31
  color: var(--g-color-text-secondary);
32
32
  }
33
+ .yfm_constructor.yfm_constructor_meta_info p {
34
+ color: var(--pc-media-card-meta-info-color);
35
+ font-weight: var(--g-text-accent-font-weight);
36
+ }
33
37
  .yfm_constructor.yfm_constructor ul,
34
38
  .yfm_constructor.yfm_constructor ol,
35
39
  .yfm_constructor.yfm_constructor li,
package/styles/yfm.scss CHANGED
@@ -34,6 +34,13 @@
34
34
  }
35
35
  }
36
36
 
37
+ &_meta_info {
38
+ p {
39
+ color: var(--pc-media-card-meta-info-color);
40
+ font-weight: var(--g-text-accent-font-weight);
41
+ }
42
+ }
43
+
37
44
  ul,
38
45
  ol,
39
46
  li,