@contentful/field-editor-rich-text 3.29.0 → 3.30.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "3.29.0",
3
+ "version": "3.30.0",
4
4
  "source": "./src/index.tsx",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -46,8 +46,8 @@
46
46
  "@contentful/f36-utils": "^4.24.3",
47
47
  "@contentful/field-editor-reference": "^5.31.2",
48
48
  "@contentful/field-editor-shared": "^1.8.0",
49
- "@contentful/rich-text-plain-text-renderer": "^16.0.4",
50
- "@contentful/rich-text-types": "16.7.0",
49
+ "@contentful/rich-text-plain-text-renderer": "^17.0.0",
50
+ "@contentful/rich-text-types": "^17.0.0",
51
51
  "@popperjs/core": "^2.11.5",
52
52
  "@udecode/plate-basic-marks": "36.0.0",
53
53
  "@udecode/plate-break": "36.0.0",
@@ -77,7 +77,7 @@
77
77
  },
78
78
  "devDependencies": {
79
79
  "@contentful/field-editor-test-utils": "^1.5.2",
80
- "@contentful/rich-text-react-renderer": "^15.16.4",
80
+ "@contentful/rich-text-react-renderer": "^16.0.0",
81
81
  "@types/is-hotkey": "^0.1.6",
82
82
  "@udecode/plate-test-utils": "^3.2.0",
83
83
  "prism-react-renderer": "2.4.0",
@@ -86,5 +86,5 @@
86
86
  "publishConfig": {
87
87
  "registry": "https://npm.pkg.github.com/"
88
88
  },
89
- "gitHead": "70980d4606762773174d9b8c3b5a1f06228839c4"
89
+ "gitHead": "617172986bc02e431405a0e994bda361b6c4bf05"
90
90
  }
@@ -1,127 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "validateRichTextDocument", {
6
- enumerable: true,
7
- get: function() {
8
- return validateRichTextDocument;
9
- }
10
- });
11
- const _richtexttypes = require("@contentful/rich-text-types");
12
- const _schemas = require("@contentful/rich-text-types/dist/schemas");
13
- const _ajv = _interop_require_default(require("ajv"));
14
- function _interop_require_default(obj) {
15
- return obj && obj.__esModule ? obj : {
16
- default: obj
17
- };
18
- }
19
- const ajv = new _ajv.default({
20
- allErrors: true,
21
- verbose: true
22
- });
23
- function validateRichTextDocument(document) {
24
- const validateRootNode = getValidator(_richtexttypes.BLOCKS.DOCUMENT);
25
- const rootNodeIsValid = validateRootNode(removeGrandChildNodes(document));
26
- const errors = [];
27
- if (rootNodeIsValid) {
28
- validateChildNodes(document, [
29
- 'content'
30
- ], errors);
31
- } else {
32
- buildSchemaErrors(validateRootNode, [], errors);
33
- }
34
- return errors;
35
- }
36
- function validateChildNodes(node, path, errors) {
37
- for(let i = 0; i < node.content.length; i++){
38
- validateNode(node.content[i], [
39
- ...path,
40
- i
41
- ], errors);
42
- }
43
- }
44
- function validateNode(node, path, errors) {
45
- const validateSchema = getValidator(node.nodeType);
46
- const isValid = validateSchema(removeGrandChildNodes(resetChildNodes(node)));
47
- if (!isValid) {
48
- buildSchemaErrors(validateSchema, path, errors);
49
- return;
50
- }
51
- if (!isLeafNode(node)) {
52
- validateChildNodes(node, [
53
- ...path,
54
- 'content'
55
- ], errors);
56
- }
57
- }
58
- function getValidator(nodeType) {
59
- const schema = (0, _schemas.getSchemaWithNodeType)(nodeType);
60
- const validate = ajv.compile(schema);
61
- const validator = (data)=>{
62
- validate(data);
63
- validator.errors = removeGrandChildrenMinItemsErrors(validate.errors ?? []);
64
- return validator.errors.length === 0;
65
- };
66
- return validator;
67
- }
68
- function buildSchemaErrors(validateSchema, _, errors) {
69
- const schemaErrors = validateSchema.errors;
70
- const constraintError = schemaErrors.find((e)=>e.keyword === 'enum' || e.keyword === 'anyOf');
71
- if (constraintError) {
72
- errors.push(constraintError);
73
- return;
74
- }
75
- errors.push(...schemaErrors);
76
- }
77
- function resetChildNodes(node) {
78
- const { content } = node;
79
- if (isLeafNode(node)) {
80
- return node;
81
- }
82
- return Object.assign({}, node, {
83
- content: content.map(resetNode)
84
- });
85
- }
86
- function resetNode(node) {
87
- const { nodeType } = node;
88
- if (_richtexttypes.helpers.isText(node)) {
89
- return {
90
- nodeType,
91
- data: {},
92
- value: '',
93
- marks: []
94
- };
95
- }
96
- return {
97
- nodeType,
98
- data: {},
99
- content: []
100
- };
101
- }
102
- function removeGrandChildNodes(node) {
103
- const { content } = node;
104
- if (isLeafNode(node)) {
105
- return node;
106
- }
107
- return Object.assign({}, node, {
108
- content: content.map(removeChildNodes)
109
- });
110
- }
111
- function removeChildNodes(node) {
112
- if (_richtexttypes.helpers.isText(node)) {
113
- return node;
114
- }
115
- return Object.assign({}, node, {
116
- content: []
117
- });
118
- }
119
- function isLeafNode(node) {
120
- return _richtexttypes.helpers.isText(node) || !Array.isArray(node.content);
121
- }
122
- function removeGrandChildrenMinItemsErrors(errors) {
123
- return errors.filter((error)=>{
124
- const level = error.instancePath.split('/').length;
125
- return !(level > 3 && error.keyword === 'minItems');
126
- });
127
- }
@@ -1,112 +0,0 @@
1
- import { helpers, BLOCKS } from '@contentful/rich-text-types';
2
- import { getSchemaWithNodeType } from '@contentful/rich-text-types/dist/schemas';
3
- import Ajv from 'ajv';
4
- const ajv = new Ajv({
5
- allErrors: true,
6
- verbose: true
7
- });
8
- export function validateRichTextDocument(document) {
9
- const validateRootNode = getValidator(BLOCKS.DOCUMENT);
10
- const rootNodeIsValid = validateRootNode(removeGrandChildNodes(document));
11
- const errors = [];
12
- if (rootNodeIsValid) {
13
- validateChildNodes(document, [
14
- 'content'
15
- ], errors);
16
- } else {
17
- buildSchemaErrors(validateRootNode, [], errors);
18
- }
19
- return errors;
20
- }
21
- function validateChildNodes(node, path, errors) {
22
- for(let i = 0; i < node.content.length; i++){
23
- validateNode(node.content[i], [
24
- ...path,
25
- i
26
- ], errors);
27
- }
28
- }
29
- function validateNode(node, path, errors) {
30
- const validateSchema = getValidator(node.nodeType);
31
- const isValid = validateSchema(removeGrandChildNodes(resetChildNodes(node)));
32
- if (!isValid) {
33
- buildSchemaErrors(validateSchema, path, errors);
34
- return;
35
- }
36
- if (!isLeafNode(node)) {
37
- validateChildNodes(node, [
38
- ...path,
39
- 'content'
40
- ], errors);
41
- }
42
- }
43
- function getValidator(nodeType) {
44
- const schema = getSchemaWithNodeType(nodeType);
45
- const validate = ajv.compile(schema);
46
- const validator = (data)=>{
47
- validate(data);
48
- validator.errors = removeGrandChildrenMinItemsErrors(validate.errors ?? []);
49
- return validator.errors.length === 0;
50
- };
51
- return validator;
52
- }
53
- function buildSchemaErrors(validateSchema, _, errors) {
54
- const schemaErrors = validateSchema.errors;
55
- const constraintError = schemaErrors.find((e)=>e.keyword === 'enum' || e.keyword === 'anyOf');
56
- if (constraintError) {
57
- errors.push(constraintError);
58
- return;
59
- }
60
- errors.push(...schemaErrors);
61
- }
62
- function resetChildNodes(node) {
63
- const { content } = node;
64
- if (isLeafNode(node)) {
65
- return node;
66
- }
67
- return Object.assign({}, node, {
68
- content: content.map(resetNode)
69
- });
70
- }
71
- function resetNode(node) {
72
- const { nodeType } = node;
73
- if (helpers.isText(node)) {
74
- return {
75
- nodeType,
76
- data: {},
77
- value: '',
78
- marks: []
79
- };
80
- }
81
- return {
82
- nodeType,
83
- data: {},
84
- content: []
85
- };
86
- }
87
- function removeGrandChildNodes(node) {
88
- const { content } = node;
89
- if (isLeafNode(node)) {
90
- return node;
91
- }
92
- return Object.assign({}, node, {
93
- content: content.map(removeChildNodes)
94
- });
95
- }
96
- function removeChildNodes(node) {
97
- if (helpers.isText(node)) {
98
- return node;
99
- }
100
- return Object.assign({}, node, {
101
- content: []
102
- });
103
- }
104
- function isLeafNode(node) {
105
- return helpers.isText(node) || !Array.isArray(node.content);
106
- }
107
- function removeGrandChildrenMinItemsErrors(errors) {
108
- return errors.filter((error)=>{
109
- const level = error.instancePath.split('/').length;
110
- return !(level > 3 && error.keyword === 'minItems');
111
- });
112
- }
@@ -1 +0,0 @@
1
- export declare function validateRichTextDocument(document: any): never[];