@gravity-ui/page-constructor 4.40.5 → 4.41.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/build/cjs/blocks/Header/Header.css +1 -1
- package/build/cjs/editor/components/CodeEditor/CodeEditor.css +56 -0
- package/build/cjs/editor/components/CodeEditor/CodeEditor.d.ts +12 -0
- package/build/cjs/editor/components/CodeEditor/CodeEditor.js +31 -0
- package/build/cjs/editor/components/CodeEditor/constants.d.ts +2 -0
- package/build/cjs/editor/components/CodeEditor/constants.js +20 -0
- package/build/cjs/editor/components/Layout/Layout.css +2 -1
- package/build/cjs/editor/containers/Editor/Editor.js +9 -5
- package/build/cjs/editor/containers/Form/Form.css +5 -2
- package/build/cjs/editor/containers/Form/Form.d.ts +10 -3
- package/build/cjs/editor/containers/Form/Form.js +12 -16
- package/build/cjs/editor/hooks/useCodeValidator.d.ts +4 -0
- package/build/cjs/editor/hooks/useCodeValidator.js +10 -0
- package/build/cjs/editor/hooks/useFormSpec.d.ts +2 -2
- package/build/cjs/editor/hooks/useFormSpec.js +2 -6
- package/build/cjs/editor/store/main/index.d.ts +12 -0
- package/build/cjs/editor/store/{index.js → main/index.js} +10 -16
- package/build/cjs/editor/store/{reducer.d.ts → main/reducer.d.ts} +5 -15
- package/build/cjs/editor/store/{reducer.js → main/reducer.js} +1 -7
- package/build/cjs/editor/store/{utils.d.ts → main/utils.d.ts} +3 -3
- package/build/cjs/editor/store/settings/index.d.ts +12 -0
- package/build/cjs/editor/store/settings/index.js +21 -0
- package/build/cjs/editor/store/settings/reducer.d.ts +37 -0
- package/build/cjs/editor/store/settings/reducer.js +32 -0
- package/build/cjs/editor/styles/root.css +2 -1
- package/build/cjs/editor/types/index.d.ts +5 -0
- package/build/cjs/editor/types/index.js +7 -1
- package/build/cjs/editor/utils/code.d.ts +6 -0
- package/build/cjs/editor/utils/code.js +11 -0
- package/build/cjs/editor/utils/validation.d.ts +13 -0
- package/build/cjs/editor/utils/validation.js +57 -0
- package/build/esm/blocks/Header/Header.css +1 -1
- package/build/esm/editor/components/CodeEditor/CodeEditor.css +56 -0
- package/build/esm/editor/components/CodeEditor/CodeEditor.d.ts +13 -0
- package/build/esm/editor/components/CodeEditor/CodeEditor.js +27 -0
- package/build/esm/editor/components/CodeEditor/constants.d.ts +2 -0
- package/build/esm/editor/components/CodeEditor/constants.js +17 -0
- package/build/esm/editor/components/Layout/Layout.css +2 -1
- package/build/esm/editor/containers/Editor/Editor.js +9 -5
- package/build/esm/editor/containers/Form/Form.css +5 -2
- package/build/esm/editor/containers/Form/Form.d.ts +10 -3
- package/build/esm/editor/containers/Form/Form.js +9 -13
- package/build/esm/editor/hooks/useCodeValidator.d.ts +4 -0
- package/build/esm/editor/hooks/useCodeValidator.js +6 -0
- package/build/esm/editor/hooks/useFormSpec.d.ts +2 -2
- package/build/esm/editor/hooks/useFormSpec.js +2 -6
- package/build/esm/editor/store/main/index.d.ts +12 -0
- package/build/esm/editor/store/{index.js → main/index.js} +9 -15
- package/build/esm/editor/store/{reducer.d.ts → main/reducer.d.ts} +5 -15
- package/build/esm/editor/store/{reducer.js → main/reducer.js} +0 -6
- package/build/esm/editor/store/{utils.d.ts → main/utils.d.ts} +3 -3
- package/build/esm/editor/store/settings/index.d.ts +12 -0
- package/build/esm/editor/store/settings/index.js +17 -0
- package/build/esm/editor/store/settings/reducer.d.ts +37 -0
- package/build/esm/editor/store/settings/reducer.js +28 -0
- package/build/esm/editor/styles/root.css +2 -1
- package/build/esm/editor/types/index.d.ts +5 -0
- package/build/esm/editor/types/index.js +6 -0
- package/build/esm/editor/utils/code.d.ts +6 -0
- package/build/esm/editor/utils/code.js +6 -0
- package/build/esm/editor/utils/validation.d.ts +13 -0
- package/build/esm/editor/utils/validation.js +51 -0
- package/package.json +4 -1
- package/styles/styles.css +1 -0
- package/styles/styles.scss +1 -0
- package/widget/index.js +1 -1
- package/build/cjs/editor/components/YamlEditor/YamlEditor.css +0 -12
- package/build/cjs/editor/components/YamlEditor/YamlEditor.d.ts +0 -6
- package/build/cjs/editor/components/YamlEditor/YamlEditor.js +0 -34
- package/build/cjs/editor/store/index.d.ts +0 -16
- package/build/esm/editor/components/YamlEditor/YamlEditor.css +0 -12
- package/build/esm/editor/components/YamlEditor/YamlEditor.d.ts +0 -7
- package/build/esm/editor/components/YamlEditor/YamlEditor.js +0 -30
- package/build/esm/editor/store/index.d.ts +0 -16
- /package/build/cjs/editor/store/{utils.js → main/utils.js} +0 -0
- /package/build/esm/editor/store/{utils.js → main/utils.js} +0 -0
|
@@ -5,3 +5,9 @@ export var ViewModeItem;
|
|
|
5
5
|
ViewModeItem["Tablet"] = "tablet";
|
|
6
6
|
ViewModeItem["Mobile"] = "mobile";
|
|
7
7
|
})(ViewModeItem || (ViewModeItem = {}));
|
|
8
|
+
export var FormTab;
|
|
9
|
+
(function (FormTab) {
|
|
10
|
+
FormTab["Blocks"] = "blocks";
|
|
11
|
+
FormTab["Page"] = "page";
|
|
12
|
+
FormTab["Code"] = "code";
|
|
13
|
+
})(FormTab || (FormTab = {}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ValidateFunction } from 'ajv';
|
|
2
|
+
import { JSONSchema4 } from 'json-schema';
|
|
3
|
+
export interface CodeEditorMessageProps {
|
|
4
|
+
text: string;
|
|
5
|
+
status: CodeEditorMessageStatus;
|
|
6
|
+
}
|
|
7
|
+
export declare enum CodeEditorMessageStatus {
|
|
8
|
+
SUCCESS = "success",
|
|
9
|
+
WARNING = "warning",
|
|
10
|
+
ERROR = "error"
|
|
11
|
+
}
|
|
12
|
+
export declare function createValidator(schema: JSONSchema4): ValidateFunction<unknown>;
|
|
13
|
+
export declare function validate(content: string, validator: ValidateFunction): CodeEditorMessageProps;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import Ajv from 'ajv';
|
|
2
|
+
import ajvKeywords from 'ajv-keywords';
|
|
3
|
+
import yaml from 'js-yaml';
|
|
4
|
+
import SourceMap from 'js-yaml-source-map';
|
|
5
|
+
import isArray from 'lodash/isArray';
|
|
6
|
+
const SUCCESS_MESSAGE = 'Valid';
|
|
7
|
+
export var CodeEditorMessageStatus;
|
|
8
|
+
(function (CodeEditorMessageStatus) {
|
|
9
|
+
CodeEditorMessageStatus["SUCCESS"] = "success";
|
|
10
|
+
CodeEditorMessageStatus["WARNING"] = "warning";
|
|
11
|
+
CodeEditorMessageStatus["ERROR"] = "error";
|
|
12
|
+
})(CodeEditorMessageStatus || (CodeEditorMessageStatus = {}));
|
|
13
|
+
export function createValidator(schema) {
|
|
14
|
+
const ajv = new Ajv({ $data: true, allErrors: true, schemas: [schema], strict: false });
|
|
15
|
+
// TODO: select is deprecated, replace with discriminator:
|
|
16
|
+
// https://github.com/ajv-validator/ajv-keywords#selectselectcasesselectdefault
|
|
17
|
+
ajvKeywords(ajv, 'select');
|
|
18
|
+
return ajv.compile(schema);
|
|
19
|
+
}
|
|
20
|
+
export function validate(content, validator) {
|
|
21
|
+
let result;
|
|
22
|
+
if (!content) {
|
|
23
|
+
return { status: CodeEditorMessageStatus.SUCCESS, text: SUCCESS_MESSAGE };
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const jsYamlMap = new SourceMap();
|
|
27
|
+
const data = yaml.load(content, { listener: jsYamlMap.listen() });
|
|
28
|
+
validator(data);
|
|
29
|
+
if (validator.errors) {
|
|
30
|
+
const messages = validator.errors.map(({ instancePath, schemaPath, message, params }) => {
|
|
31
|
+
const pointer = jsYamlMap.lookup(instancePath.split('/').filter(Boolean));
|
|
32
|
+
const stringParams = Object.entries(params).map(([key, value]) => {
|
|
33
|
+
if (isArray(value)) {
|
|
34
|
+
return `${key}: ${value.join(' | ')}`;
|
|
35
|
+
}
|
|
36
|
+
return `${key}: ${value}`;
|
|
37
|
+
});
|
|
38
|
+
const ref = pointer ? `${pointer.line}: ` : '';
|
|
39
|
+
return `${ref}${instancePath || schemaPath}: ${message}\n${stringParams.join('\n')}`;
|
|
40
|
+
});
|
|
41
|
+
result = { status: CodeEditorMessageStatus.WARNING, text: messages.join('\n\n') };
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
result = { status: CodeEditorMessageStatus.SUCCESS, text: SUCCESS_MESSAGE };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch ({ message }) {
|
|
48
|
+
result = { status: CodeEditorMessageStatus.ERROR, text: message };
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/page-constructor",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.41.0",
|
|
4
4
|
"description": "Gravity UI Page Constructor",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -86,8 +86,10 @@
|
|
|
86
86
|
"@gravity-ui/i18n": "^1.0.0",
|
|
87
87
|
"@react-spring/web": "^9.7.3",
|
|
88
88
|
"ajv": "^8.12.0",
|
|
89
|
+
"ajv-keywords": "^5.1.0",
|
|
89
90
|
"final-form": "^4.20.9",
|
|
90
91
|
"github-buttons": "2.23.0",
|
|
92
|
+
"js-yaml-source-map": "^0.2.2",
|
|
91
93
|
"lodash": "^4.17.21",
|
|
92
94
|
"monaco-editor": "^0.38.0",
|
|
93
95
|
"react-final-form": "^6.5.9",
|
|
@@ -164,6 +166,7 @@
|
|
|
164
166
|
"js-yaml": "^4.1.0",
|
|
165
167
|
"lint-staged": "^11.2.6",
|
|
166
168
|
"markdown-loader": "^6.0.0",
|
|
169
|
+
"monaco-editor-webpack-plugin": "^7.1.0",
|
|
167
170
|
"move-file-cli": "^3.0.0",
|
|
168
171
|
"npm-run-all": "^4.1.5",
|
|
169
172
|
"postcss": "^8.4.16",
|
package/styles/styles.css
CHANGED
package/styles/styles.scss
CHANGED