@contentful/field-editor-rich-text 3.28.2 → 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.
@@ -117,7 +117,8 @@ const ConnectedRichTextEditor = (props)=>{
117
117
  plugins: plugins,
118
118
  disableCorePlugins: _plugins.disableCorePlugins
119
119
  }, !props.isToolbarHidden && _react.createElement(_StickyToolbarWrapper.default, {
120
- isDisabled: props.isDisabled
120
+ isDisabled: props.isDisabled,
121
+ offset: props.stickyToolbarOffset
121
122
  }, _react.createElement(_Toolbar.default, {
122
123
  isDisabled: props.isDisabled
123
124
  })), _react.createElement(_SyncEditorChanges.SyncEditorChanges, {
@@ -16,14 +16,14 @@ function _interop_require_default(obj) {
16
16
  };
17
17
  }
18
18
  const styles = {
19
- nativeSticky: (0, _emotion.css)`
19
+ nativeSticky: (offset)=>(0, _emotion.css)`
20
20
  position: -webkit-sticky;
21
21
  position: sticky;
22
- top: -1px;
22
+ top: ${offset ? offset : -1}px;
23
23
  z-index: 2;
24
24
  `
25
25
  };
26
- const StickyToolbarWrapper = ({ isDisabled, children })=>_react.default.createElement("div", {
27
- className: isDisabled ? '' : styles.nativeSticky
26
+ const StickyToolbarWrapper = ({ isDisabled, offset, children })=>_react.default.createElement("div", {
27
+ className: isDisabled ? '' : styles.nativeSticky(offset)
28
28
  }, children);
29
29
  const _default = StickyToolbarWrapper;
@@ -53,7 +53,8 @@ export const ConnectedRichTextEditor = (props)=>{
53
53
  plugins: plugins,
54
54
  disableCorePlugins: disableCorePlugins
55
55
  }, !props.isToolbarHidden && React.createElement(StickyToolbarWrapper, {
56
- isDisabled: props.isDisabled
56
+ isDisabled: props.isDisabled,
57
+ offset: props.stickyToolbarOffset
57
58
  }, React.createElement(Toolbar, {
58
59
  isDisabled: props.isDisabled
59
60
  })), React.createElement(SyncEditorChanges, {
@@ -1,14 +1,14 @@
1
1
  import React from 'react';
2
2
  import { css } from 'emotion';
3
3
  const styles = {
4
- nativeSticky: css`
4
+ nativeSticky: (offset)=>css`
5
5
  position: -webkit-sticky;
6
6
  position: sticky;
7
- top: -1px;
7
+ top: ${offset ? offset : -1}px;
8
8
  z-index: 2;
9
9
  `
10
10
  };
11
- const StickyToolbarWrapper = ({ isDisabled, children })=>React.createElement("div", {
12
- className: isDisabled ? '' : styles.nativeSticky
11
+ const StickyToolbarWrapper = ({ isDisabled, offset, children })=>React.createElement("div", {
12
+ className: isDisabled ? '' : styles.nativeSticky(offset)
13
13
  }, children);
14
14
  export default StickyToolbarWrapper;
@@ -29,6 +29,7 @@ type ConnectedRichTextProps = {
29
29
  isDisabled?: boolean;
30
30
  isToolbarHidden?: boolean;
31
31
  actionsDisabled?: boolean;
32
+ stickyToolbarOffset?: number;
32
33
  };
33
34
  export declare const ConnectedRichTextEditor: (props: ConnectedRichTextProps) => React.JSX.Element;
34
35
  declare const RichTextEditor: (props: RichTextProps) => React.JSX.Element;
@@ -1,7 +1,8 @@
1
1
  import React, { ReactNode } from 'react';
2
2
  type StickyToolbarProps = {
3
3
  isDisabled?: boolean;
4
+ offset?: number;
4
5
  children: ReactNode;
5
6
  };
6
- declare const StickyToolbarWrapper: ({ isDisabled, children }: StickyToolbarProps) => React.JSX.Element;
7
+ declare const StickyToolbarWrapper: ({ isDisabled, offset, children }: StickyToolbarProps) => React.JSX.Element;
7
8
  export default StickyToolbarWrapper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "3.28.2",
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": "eb3a6f6fd6b37d1ec6fb83dc8401a55ebfe4ff68"
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[];