@gravity-ui/page-constructor 4.9.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).
@@ -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;
@@ -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
  };
@@ -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) {
@@ -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.9.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;
@@ -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
  };