@gravity-ui/page-constructor 3.12.2 → 3.13.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.
@@ -0,0 +1,12 @@
1
+ .pc-yaml-editor {
2
+ height: 100%;
3
+ position: relative;
4
+ }
5
+ .pc-yaml-editor__copy-button {
6
+ position: absolute;
7
+ top: 12px;
8
+ right: 12px;
9
+ }
10
+ .pc-yaml-editor__copy-button_hidden {
11
+ visibility: hidden;
12
+ }
@@ -0,0 +1,6 @@
1
+ import { PageContent } from '../../../models';
2
+ interface YamlEditorProps {
3
+ content: PageContent;
4
+ }
5
+ export declare const YamlEditor: ({ content }: YamlEditorProps) => JSX.Element;
6
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.YamlEditor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importStar(require("react"));
6
+ const uikit_1 = require("@gravity-ui/uikit");
7
+ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
8
+ const react_monaco_editor_1 = tslib_1.__importDefault(require("react-monaco-editor"));
9
+ const utils_1 = require("../../../utils");
10
+ const b = (0, utils_1.block)('yaml-editor');
11
+ const YamlEditor = ({ content }) => {
12
+ const value = (0, react_1.useMemo)(() => {
13
+ return js_yaml_1.default.dump(content);
14
+ }, [content]);
15
+ const options = (0, react_1.useMemo)(() => {
16
+ return {
17
+ minimap: {
18
+ enabled: false,
19
+ },
20
+ renderWhitespace: 'all',
21
+ overviewRulerLanes: 0,
22
+ hideCursorInOverviewRuler: true,
23
+ scrollbar: {
24
+ vertical: 'hidden',
25
+ },
26
+ overviewRulerBorder: false,
27
+ readOnly: true,
28
+ };
29
+ }, []);
30
+ return (react_1.default.createElement("div", { className: b() },
31
+ react_1.default.createElement(react_monaco_editor_1.default, { value: value, language: "yaml", options: options }),
32
+ react_1.default.createElement(uikit_1.ClipboardButton, { className: b('copy-button'), text: value })));
33
+ };
34
+ exports.YamlEditor = YamlEditor;
@@ -109,4 +109,7 @@ unpredictable css rules order in build */
109
109
  }
110
110
  .pc-editor-form__block-form {
111
111
  margin-bottom: 16px;
112
+ }
113
+ .pc-editor-form_yaml-editor-enabled {
114
+ height: 100%;
112
115
  }
@@ -7,10 +7,12 @@ const uikit_1 = require("@gravity-ui/uikit");
7
7
  const utils_1 = require("../../../utils");
8
8
  const BlockForm_1 = require("../../components/BlockForm/BlockForm");
9
9
  const PagePropsForm_1 = require("../../components/PagePropsForm/PagePropsForm");
10
+ const YamlEditor_1 = require("../../components/YamlEditor/YamlEditor");
10
11
  var FormTab;
11
12
  (function (FormTab) {
12
13
  FormTab["Blocks"] = "blocks";
13
14
  FormTab["Page"] = "page";
15
+ FormTab["Yaml"] = "yaml";
14
16
  })(FormTab || (FormTab = {}));
15
17
  const b = (0, utils_1.block)('editor-form');
16
18
  const tabsItems = Object.values(FormTab).map((tab) => ({
@@ -40,8 +42,12 @@ exports.Form = (0, react_1.memo)(({ content, onChange, activeBlockIndex, onSelec
40
42
  }, onSelect: () => onSelect(index) }))) : null)));
41
43
  break;
42
44
  }
45
+ case FormTab.Yaml: {
46
+ form = react_1.default.createElement(YamlEditor_1.YamlEditor, { content: content });
47
+ break;
48
+ }
43
49
  }
44
- return (react_1.default.createElement("div", { className: b() },
50
+ return (react_1.default.createElement("div", { className: b({ 'yaml-editor-enabled': activeTab === FormTab.Yaml }) },
45
51
  react_1.default.createElement(uikit_1.Tabs, { activeTab: activeTab, className: b('tabs'), items: tabsItems, onSelectTab: setActiveTab }),
46
52
  form));
47
53
  });
@@ -0,0 +1,12 @@
1
+ .pc-yaml-editor {
2
+ height: 100%;
3
+ position: relative;
4
+ }
5
+ .pc-yaml-editor__copy-button {
6
+ position: absolute;
7
+ top: 12px;
8
+ right: 12px;
9
+ }
10
+ .pc-yaml-editor__copy-button_hidden {
11
+ visibility: hidden;
12
+ }
@@ -0,0 +1,7 @@
1
+ import { PageContent } from '../../../models';
2
+ import './YamlEditor.css';
3
+ interface YamlEditorProps {
4
+ content: PageContent;
5
+ }
6
+ export declare const YamlEditor: ({ content }: YamlEditorProps) => JSX.Element;
7
+ export {};
@@ -0,0 +1,30 @@
1
+ import React, { useMemo } from 'react';
2
+ import { ClipboardButton } from '@gravity-ui/uikit';
3
+ import yaml from 'js-yaml';
4
+ import MonacoEditor from 'react-monaco-editor';
5
+ import { block } from '../../../utils';
6
+ import './YamlEditor.css';
7
+ const b = block('yaml-editor');
8
+ export const YamlEditor = ({ content }) => {
9
+ const value = useMemo(() => {
10
+ return yaml.dump(content);
11
+ }, [content]);
12
+ const options = useMemo(() => {
13
+ return {
14
+ minimap: {
15
+ enabled: false,
16
+ },
17
+ renderWhitespace: 'all',
18
+ overviewRulerLanes: 0,
19
+ hideCursorInOverviewRuler: true,
20
+ scrollbar: {
21
+ vertical: 'hidden',
22
+ },
23
+ overviewRulerBorder: false,
24
+ readOnly: true,
25
+ };
26
+ }, []);
27
+ return (React.createElement("div", { className: b() },
28
+ React.createElement(MonacoEditor, { value: value, language: "yaml", options: options }),
29
+ React.createElement(ClipboardButton, { className: b('copy-button'), text: value })));
30
+ };
@@ -109,4 +109,7 @@ unpredictable css rules order in build */
109
109
  }
110
110
  .pc-editor-form__block-form {
111
111
  margin-bottom: 16px;
112
+ }
113
+ .pc-editor-form_yaml-editor-enabled {
114
+ height: 100%;
112
115
  }
@@ -4,11 +4,13 @@ import { Tabs } from '@gravity-ui/uikit';
4
4
  import { block, getBlockKey } from '../../../utils';
5
5
  import { BlockForm } from '../../components/BlockForm/BlockForm';
6
6
  import { PagePropsForm } from '../../components/PagePropsForm/PagePropsForm';
7
+ import { YamlEditor } from '../../components/YamlEditor/YamlEditor';
7
8
  import './Form.css';
8
9
  var FormTab;
9
10
  (function (FormTab) {
10
11
  FormTab["Blocks"] = "blocks";
11
12
  FormTab["Page"] = "page";
13
+ FormTab["Yaml"] = "yaml";
12
14
  })(FormTab || (FormTab = {}));
13
15
  const b = block('editor-form');
14
16
  const tabsItems = Object.values(FormTab).map((tab) => ({
@@ -38,8 +40,12 @@ export const Form = memo(({ content, onChange, activeBlockIndex, onSelect, spec
38
40
  }, onSelect: () => onSelect(index) }))) : null)));
39
41
  break;
40
42
  }
43
+ case FormTab.Yaml: {
44
+ form = React.createElement(YamlEditor, { content: content });
45
+ break;
46
+ }
41
47
  }
42
- return (React.createElement("div", { className: b() },
48
+ return (React.createElement("div", { className: b({ 'yaml-editor-enabled': activeTab === FormTab.Yaml }) },
43
49
  React.createElement(Tabs, { activeTab: activeTab, className: b('tabs'), items: tabsItems, onSelectTab: setActiveTab }),
44
50
  form));
45
51
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/page-constructor",
3
- "version": "3.12.2",
3
+ "version": "3.13.0",
4
4
  "description": "Gravity UI Page Constructor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -87,7 +87,9 @@
87
87
  "final-form": "^4.20.9",
88
88
  "github-buttons": "2.23.0",
89
89
  "lodash": "^4.17.21",
90
+ "monaco-editor": "^0.38.0",
90
91
  "react-final-form": "^6.5.9",
92
+ "react-monaco-editor": "^0.53.0",
91
93
  "react-player": "^2.9.0",
92
94
  "react-slick": "^0.29.0",
93
95
  "react-spring": "^9.3.0",
@@ -128,6 +130,7 @@
128
130
  "@testing-library/react": "^13.4.0",
129
131
  "@testing-library/user-event": "^14.4.3",
130
132
  "@types/jest": "^29.2.4",
133
+ "@types/js-yaml": "^4.0.5",
131
134
  "@types/json-schema": "^7.0.12",
132
135
  "@types/lodash": "^4.14.176",
133
136
  "@types/react": "^18.0.27",