@atlaskit/editor-core 202.3.4 → 202.4.1
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/CHANGELOG.md +20 -0
- package/dist/cjs/create-editor/create-schema.js +2 -2
- package/dist/cjs/ui/Addon/ClickAreaBlock/index.js +8 -5
- package/dist/cjs/ui/Addon/ClickAreaInline/index.js +2 -0
- package/dist/cjs/ui/Addon/ClickAreaMobile/index.js +15 -12
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/create-editor/create-schema.js +1 -1
- package/dist/es2019/ui/Addon/ClickAreaBlock/index.js +8 -5
- package/dist/es2019/ui/Addon/ClickAreaInline/index.js +2 -0
- package/dist/es2019/ui/Addon/ClickAreaMobile/index.js +15 -12
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/create-editor/create-schema.js +1 -1
- package/dist/esm/ui/Addon/ClickAreaBlock/index.js +8 -5
- package/dist/esm/ui/Addon/ClickAreaInline/index.js +2 -0
- package/dist/esm/ui/Addon/ClickAreaMobile/index.js +15 -12
- package/dist/esm/version-wrapper.js +1 -1
- package/package.json +9 -9
- package/dist/cjs/utils/sanitizeNodes.js +0 -63
- package/dist/es2019/utils/sanitizeNodes.js +0 -49
- package/dist/esm/utils/sanitizeNodes.js +0 -56
- package/dist/types/utils/sanitizeNodes.d.ts +0 -8
- package/dist/types-ts4.5/utils/sanitizeNodes.d.ts +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @atlaskit/editor-core
|
|
2
2
|
|
|
3
|
+
## 202.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#167313](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/167313)
|
|
8
|
+
[`40d491ee58258`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/40d491ee58258) -
|
|
9
|
+
ED-24230 Remove code wrapping for editor FG
|
|
10
|
+
|
|
11
|
+
## 202.4.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [#165765](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/165765)
|
|
16
|
+
[`3f441f30e6507`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3f441f30e6507) -
|
|
17
|
+
Bump adf-schema to 46.0.0
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
|
|
3
23
|
## 202.3.4
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -8,10 +8,10 @@ exports.addMetadataAttributes = void 0;
|
|
|
8
8
|
exports.createSchema = createSchema;
|
|
9
9
|
exports.wrapToDOMProxy = exports.wrapNodeSpecProxy = void 0;
|
|
10
10
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
+
var _schema = require("@atlaskit/adf-schema/schema");
|
|
11
12
|
var _prosemirrorDomMetadata = require("@atlaskit/editor-common/prosemirror-dom-metadata");
|
|
12
13
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
13
14
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
|
-
var _sanitizeNodes = require("../utils/sanitizeNodes");
|
|
15
15
|
var _createEditor = require("./create-editor");
|
|
16
16
|
var _sortByOrder = require("./sort-by-order");
|
|
17
17
|
/**
|
|
@@ -103,7 +103,7 @@ function createSchema(editorConfig) {
|
|
|
103
103
|
}
|
|
104
104
|
return acc;
|
|
105
105
|
}, {}));
|
|
106
|
-
var nodes = (0,
|
|
106
|
+
var nodes = (0, _schema.sanitizeNodes)(editorConfig.nodes.sort((0, _sortByOrder.sortByOrder)('nodes')).reduce(function (acc, node) {
|
|
107
107
|
if ((0, _platformFeatureFlags.fg)('platform_editor_breakout_use_css')) {
|
|
108
108
|
acc[node.name] = wrapNodeSpecProxy(node.node);
|
|
109
109
|
} else {
|
|
@@ -31,10 +31,13 @@ var ClickAreaBlock = exports.ClickAreaBlock = function ClickAreaBlock(_ref) {
|
|
|
31
31
|
(0, _clickAreaHelper.clickAreaClickHandler)(editorView, event);
|
|
32
32
|
}
|
|
33
33
|
}, [editorView, editorDisabled]);
|
|
34
|
-
return (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
return (
|
|
35
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
36
|
+
(0, _react2.jsx)("div", {
|
|
37
|
+
"data-testid": "click-wrapper",
|
|
38
|
+
css: clickWrapper,
|
|
39
|
+
onMouseDown: handleMouseDown
|
|
40
|
+
}, children)
|
|
41
|
+
);
|
|
39
42
|
};
|
|
40
43
|
var _default = exports.default = ClickAreaBlock;
|
|
@@ -30,6 +30,8 @@ var ClickAreaInline = exports.ClickAreaInline = function ClickAreaInline(_ref) {
|
|
|
30
30
|
event.stopPropagation();
|
|
31
31
|
}
|
|
32
32
|
}, [editorView]);
|
|
33
|
+
|
|
34
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
33
35
|
return (0, _react2.jsx)("div", {
|
|
34
36
|
"data-testid": "click-wrapper",
|
|
35
37
|
css: clickArea,
|
|
@@ -85,18 +85,21 @@ var ClickAreaMobile = exports.default = /*#__PURE__*/function (_React$Component)
|
|
|
85
85
|
(0, _createClass2.default)(ClickAreaMobile, [{
|
|
86
86
|
key: "render",
|
|
87
87
|
value: function render() {
|
|
88
|
-
return (
|
|
89
|
-
// eslint-disable-next-line
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
return (
|
|
89
|
+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
|
|
90
|
+
(0, _react2.jsx)("div", {
|
|
91
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
92
|
+
css: clickWrapper({
|
|
93
|
+
isExpanded: this.props.isExpanded,
|
|
94
|
+
minHeight: this.props.minHeight
|
|
95
|
+
})
|
|
96
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
97
|
+
,
|
|
98
|
+
className: "editor-click-wrapper",
|
|
99
|
+
onClick: this.handleClick,
|
|
100
|
+
ref: this.clickElementRef
|
|
101
|
+
}, this.props.children)
|
|
102
|
+
);
|
|
100
103
|
}
|
|
101
104
|
}]);
|
|
102
105
|
return ClickAreaMobile;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { sanitizeNodes } from '@atlaskit/adf-schema/schema';
|
|
1
2
|
import { createProseMirrorMetadata } from '@atlaskit/editor-common/prosemirror-dom-metadata';
|
|
2
3
|
import { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
|
-
import { sanitizeNodes } from '../utils/sanitizeNodes';
|
|
5
5
|
import { fixExcludes } from './create-editor';
|
|
6
6
|
import { sortByOrder } from './sort-by-order';
|
|
7
7
|
/**
|
|
@@ -24,10 +24,13 @@ export const ClickAreaBlock = ({
|
|
|
24
24
|
clickAreaClickHandler(editorView, event);
|
|
25
25
|
}
|
|
26
26
|
}, [editorView, editorDisabled]);
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
return (
|
|
28
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
29
|
+
jsx("div", {
|
|
30
|
+
"data-testid": "click-wrapper",
|
|
31
|
+
css: clickWrapper,
|
|
32
|
+
onMouseDown: handleMouseDown
|
|
33
|
+
}, children)
|
|
34
|
+
);
|
|
32
35
|
};
|
|
33
36
|
export default ClickAreaBlock;
|
|
@@ -64,17 +64,20 @@ export default class ClickAreaMobile extends React.Component {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
render() {
|
|
67
|
-
return
|
|
68
|
-
// eslint-disable-next-line
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
return (
|
|
68
|
+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
|
|
69
|
+
jsx("div", {
|
|
70
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
71
|
+
css: clickWrapper({
|
|
72
|
+
isExpanded: this.props.isExpanded,
|
|
73
|
+
minHeight: this.props.minHeight
|
|
74
|
+
})
|
|
75
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
76
|
+
,
|
|
77
|
+
className: "editor-click-wrapper",
|
|
78
|
+
onClick: this.handleClick,
|
|
79
|
+
ref: this.clickElementRef
|
|
80
|
+
}, this.props.children)
|
|
81
|
+
);
|
|
79
82
|
}
|
|
80
83
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = "@atlaskit/editor-core";
|
|
2
|
-
export const version = "202.
|
|
2
|
+
export const version = "202.4.1";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
+
import { sanitizeNodes } from '@atlaskit/adf-schema/schema';
|
|
2
3
|
import { createProseMirrorMetadata } from '@atlaskit/editor-common/prosemirror-dom-metadata';
|
|
3
4
|
import { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
4
5
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
|
-
import { sanitizeNodes } from '../utils/sanitizeNodes';
|
|
6
6
|
import { fixExcludes } from './create-editor';
|
|
7
7
|
import { sortByOrder } from './sort-by-order';
|
|
8
8
|
/**
|
|
@@ -23,10 +23,13 @@ export var ClickAreaBlock = function ClickAreaBlock(_ref) {
|
|
|
23
23
|
clickAreaClickHandler(editorView, event);
|
|
24
24
|
}
|
|
25
25
|
}, [editorView, editorDisabled]);
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
return (
|
|
27
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
28
|
+
jsx("div", {
|
|
29
|
+
"data-testid": "click-wrapper",
|
|
30
|
+
css: clickWrapper,
|
|
31
|
+
onMouseDown: handleMouseDown
|
|
32
|
+
}, children)
|
|
33
|
+
);
|
|
31
34
|
};
|
|
32
35
|
export default ClickAreaBlock;
|
|
@@ -22,6 +22,8 @@ export var ClickAreaInline = function ClickAreaInline(_ref) {
|
|
|
22
22
|
event.stopPropagation();
|
|
23
23
|
}
|
|
24
24
|
}, [editorView]);
|
|
25
|
+
|
|
26
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
25
27
|
return jsx("div", {
|
|
26
28
|
"data-testid": "click-wrapper",
|
|
27
29
|
css: clickArea,
|
|
@@ -82,18 +82,21 @@ var ClickAreaMobile = /*#__PURE__*/function (_React$Component) {
|
|
|
82
82
|
_createClass(ClickAreaMobile, [{
|
|
83
83
|
key: "render",
|
|
84
84
|
value: function render() {
|
|
85
|
-
return
|
|
86
|
-
// eslint-disable-next-line
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
85
|
+
return (
|
|
86
|
+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
|
|
87
|
+
jsx("div", {
|
|
88
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
89
|
+
css: clickWrapper({
|
|
90
|
+
isExpanded: this.props.isExpanded,
|
|
91
|
+
minHeight: this.props.minHeight
|
|
92
|
+
})
|
|
93
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
94
|
+
,
|
|
95
|
+
className: "editor-click-wrapper",
|
|
96
|
+
onClick: this.handleClick,
|
|
97
|
+
ref: this.clickElementRef
|
|
98
|
+
}, this.props.children)
|
|
99
|
+
);
|
|
97
100
|
}
|
|
98
101
|
}]);
|
|
99
102
|
return ClickAreaMobile;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export var name = "@atlaskit/editor-core";
|
|
2
|
-
export var version = "202.
|
|
2
|
+
export var version = "202.4.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-core",
|
|
3
|
-
"version": "202.
|
|
3
|
+
"version": "202.4.1",
|
|
4
4
|
"description": "A package contains Atlassian editor core functionality",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@atlaskit/activity-provider": "^2.5.0",
|
|
41
|
-
"@atlaskit/adf-schema": "^
|
|
41
|
+
"@atlaskit/adf-schema": "^46.1.0",
|
|
42
42
|
"@atlaskit/analytics-namespaced-context": "^6.12.0",
|
|
43
43
|
"@atlaskit/analytics-next": "^10.1.0",
|
|
44
44
|
"@atlaskit/analytics-next-stable-react-context": "1.0.1",
|
|
45
45
|
"@atlaskit/button": "^20.3.0",
|
|
46
|
-
"@atlaskit/editor-common": "^95.
|
|
46
|
+
"@atlaskit/editor-common": "^95.7.0",
|
|
47
47
|
"@atlaskit/editor-json-transformer": "^8.21.0",
|
|
48
48
|
"@atlaskit/editor-plugin-quick-insert": "1.7.1",
|
|
49
49
|
"@atlaskit/editor-plugins": "^5.7.0",
|
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
"@af/visual-regression": "*",
|
|
84
84
|
"@atlaskit/adf-utils": "^19.13.0",
|
|
85
85
|
"@atlaskit/analytics-listeners": "^8.13.0",
|
|
86
|
-
"@atlaskit/collab-provider": "10.1.
|
|
87
|
-
"@atlaskit/editor-plugin-annotation": "1.25.
|
|
86
|
+
"@atlaskit/collab-provider": "10.1.3",
|
|
87
|
+
"@atlaskit/editor-plugin-annotation": "1.25.3",
|
|
88
88
|
"@atlaskit/editor-plugin-card": "^4.4.0",
|
|
89
89
|
"@atlaskit/editor-plugin-list": "^3.9.0",
|
|
90
90
|
"@atlaskit/editor-plugin-paste": "^2.0.0",
|
|
@@ -182,10 +182,6 @@
|
|
|
182
182
|
"type": "boolean",
|
|
183
183
|
"referenceOnly": true
|
|
184
184
|
},
|
|
185
|
-
"editor_support_code_block_wrapping": {
|
|
186
|
-
"type": "boolean",
|
|
187
|
-
"referenceOnly": true
|
|
188
|
-
},
|
|
189
185
|
"platform_editor_react_18_plugin_slot": {
|
|
190
186
|
"type": "boolean"
|
|
191
187
|
},
|
|
@@ -356,6 +352,10 @@
|
|
|
356
352
|
"platform_inline_node_as_valid_annotation_selection": {
|
|
357
353
|
"type": "boolean",
|
|
358
354
|
"referenceOnly": true
|
|
355
|
+
},
|
|
356
|
+
"platform_editor_hide_external_media_badge": {
|
|
357
|
+
"type": "boolean",
|
|
358
|
+
"referenceOnly": true
|
|
359
359
|
}
|
|
360
360
|
},
|
|
361
361
|
"stricter": {
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.sanitizeNodes = sanitizeNodes;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
-
function sanitizeNodes(nodes, supportedMarks) {
|
|
12
|
-
var nodeNames = Object.keys(nodes);
|
|
13
|
-
nodeNames.forEach(function (nodeKey) {
|
|
14
|
-
var nodeSpec = _objectSpread({}, nodes[nodeKey]);
|
|
15
|
-
if (nodeSpec.marks && nodeSpec.marks !== '_') {
|
|
16
|
-
nodeSpec.marks = nodeSpec.marks.split(' ').filter(function (mark) {
|
|
17
|
-
return !!supportedMarks[mark];
|
|
18
|
-
}).join(' ');
|
|
19
|
-
}
|
|
20
|
-
if (nodeSpec.content) {
|
|
21
|
-
nodeSpec.content = sanitizeNodeSpecContent(nodes, nodeSpec.content);
|
|
22
|
-
}
|
|
23
|
-
nodes[nodeKey] = nodeSpec;
|
|
24
|
-
});
|
|
25
|
-
return nodes;
|
|
26
|
-
}
|
|
27
|
-
function sanitizeNodeSpecContent(nodes, rawContent) {
|
|
28
|
-
var content = rawContent.replace(/\W/g, ' ');
|
|
29
|
-
var contentKeys = content.split(' ');
|
|
30
|
-
var unsupportedContentKeys = contentKeys.filter(function (contentKey) {
|
|
31
|
-
return !isContentSupported(nodes, contentKey);
|
|
32
|
-
});
|
|
33
|
-
return unsupportedContentKeys.reduce(function (newContent, nodeName) {
|
|
34
|
-
return sanitizedContent(newContent, nodeName);
|
|
35
|
-
}, rawContent);
|
|
36
|
-
}
|
|
37
|
-
function sanitizedContent(content, invalidContent) {
|
|
38
|
-
if (!invalidContent.length) {
|
|
39
|
-
return content || '';
|
|
40
|
-
}
|
|
41
|
-
if (!content || !content.match(/\w/)) {
|
|
42
|
-
return '';
|
|
43
|
-
}
|
|
44
|
-
var pattern = "(".concat(invalidContent, "((\\s)*\\|)+)|((\\|(\\s)*)+").concat(invalidContent, ")|(").concat(invalidContent, "$)|(").concat(invalidContent, "(\\+|\\*))");
|
|
45
|
-
return content.replace(new RegExp(pattern, 'g'), '').replace(' ', ' ').trim();
|
|
46
|
-
}
|
|
47
|
-
function isContentSupported(nodes, contentKey) {
|
|
48
|
-
var nodeKeys = Object.keys(nodes);
|
|
49
|
-
|
|
50
|
-
// content is with valid node
|
|
51
|
-
if (nodeKeys.indexOf(contentKey) > -1) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// content is with valid group
|
|
56
|
-
for (var supportedKey in nodes) {
|
|
57
|
-
var nodeSpec = nodes[supportedKey];
|
|
58
|
-
if (nodeSpec && nodeSpec.group === contentKey) {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export function sanitizeNodes(nodes, supportedMarks) {
|
|
2
|
-
const nodeNames = Object.keys(nodes);
|
|
3
|
-
nodeNames.forEach(nodeKey => {
|
|
4
|
-
const nodeSpec = {
|
|
5
|
-
...nodes[nodeKey]
|
|
6
|
-
};
|
|
7
|
-
if (nodeSpec.marks && nodeSpec.marks !== '_') {
|
|
8
|
-
nodeSpec.marks = nodeSpec.marks.split(' ').filter(mark => !!supportedMarks[mark]).join(' ');
|
|
9
|
-
}
|
|
10
|
-
if (nodeSpec.content) {
|
|
11
|
-
nodeSpec.content = sanitizeNodeSpecContent(nodes, nodeSpec.content);
|
|
12
|
-
}
|
|
13
|
-
nodes[nodeKey] = nodeSpec;
|
|
14
|
-
});
|
|
15
|
-
return nodes;
|
|
16
|
-
}
|
|
17
|
-
function sanitizeNodeSpecContent(nodes, rawContent) {
|
|
18
|
-
const content = rawContent.replace(/\W/g, ' ');
|
|
19
|
-
const contentKeys = content.split(' ');
|
|
20
|
-
const unsupportedContentKeys = contentKeys.filter(contentKey => !isContentSupported(nodes, contentKey));
|
|
21
|
-
return unsupportedContentKeys.reduce((newContent, nodeName) => sanitizedContent(newContent, nodeName), rawContent);
|
|
22
|
-
}
|
|
23
|
-
function sanitizedContent(content, invalidContent) {
|
|
24
|
-
if (!invalidContent.length) {
|
|
25
|
-
return content || '';
|
|
26
|
-
}
|
|
27
|
-
if (!content || !content.match(/\w/)) {
|
|
28
|
-
return '';
|
|
29
|
-
}
|
|
30
|
-
const pattern = `(${invalidContent}((\\s)*\\|)+)|((\\|(\\s)*)+${invalidContent})|(${invalidContent}$)|(${invalidContent}(\\+|\\*))`;
|
|
31
|
-
return content.replace(new RegExp(pattern, 'g'), '').replace(' ', ' ').trim();
|
|
32
|
-
}
|
|
33
|
-
function isContentSupported(nodes, contentKey) {
|
|
34
|
-
const nodeKeys = Object.keys(nodes);
|
|
35
|
-
|
|
36
|
-
// content is with valid node
|
|
37
|
-
if (nodeKeys.indexOf(contentKey) > -1) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// content is with valid group
|
|
42
|
-
for (const supportedKey in nodes) {
|
|
43
|
-
const nodeSpec = nodes[supportedKey];
|
|
44
|
-
if (nodeSpec && nodeSpec.group === contentKey) {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
export function sanitizeNodes(nodes, supportedMarks) {
|
|
5
|
-
var nodeNames = Object.keys(nodes);
|
|
6
|
-
nodeNames.forEach(function (nodeKey) {
|
|
7
|
-
var nodeSpec = _objectSpread({}, nodes[nodeKey]);
|
|
8
|
-
if (nodeSpec.marks && nodeSpec.marks !== '_') {
|
|
9
|
-
nodeSpec.marks = nodeSpec.marks.split(' ').filter(function (mark) {
|
|
10
|
-
return !!supportedMarks[mark];
|
|
11
|
-
}).join(' ');
|
|
12
|
-
}
|
|
13
|
-
if (nodeSpec.content) {
|
|
14
|
-
nodeSpec.content = sanitizeNodeSpecContent(nodes, nodeSpec.content);
|
|
15
|
-
}
|
|
16
|
-
nodes[nodeKey] = nodeSpec;
|
|
17
|
-
});
|
|
18
|
-
return nodes;
|
|
19
|
-
}
|
|
20
|
-
function sanitizeNodeSpecContent(nodes, rawContent) {
|
|
21
|
-
var content = rawContent.replace(/\W/g, ' ');
|
|
22
|
-
var contentKeys = content.split(' ');
|
|
23
|
-
var unsupportedContentKeys = contentKeys.filter(function (contentKey) {
|
|
24
|
-
return !isContentSupported(nodes, contentKey);
|
|
25
|
-
});
|
|
26
|
-
return unsupportedContentKeys.reduce(function (newContent, nodeName) {
|
|
27
|
-
return sanitizedContent(newContent, nodeName);
|
|
28
|
-
}, rawContent);
|
|
29
|
-
}
|
|
30
|
-
function sanitizedContent(content, invalidContent) {
|
|
31
|
-
if (!invalidContent.length) {
|
|
32
|
-
return content || '';
|
|
33
|
-
}
|
|
34
|
-
if (!content || !content.match(/\w/)) {
|
|
35
|
-
return '';
|
|
36
|
-
}
|
|
37
|
-
var pattern = "(".concat(invalidContent, "((\\s)*\\|)+)|((\\|(\\s)*)+").concat(invalidContent, ")|(").concat(invalidContent, "$)|(").concat(invalidContent, "(\\+|\\*))");
|
|
38
|
-
return content.replace(new RegExp(pattern, 'g'), '').replace(' ', ' ').trim();
|
|
39
|
-
}
|
|
40
|
-
function isContentSupported(nodes, contentKey) {
|
|
41
|
-
var nodeKeys = Object.keys(nodes);
|
|
42
|
-
|
|
43
|
-
// content is with valid node
|
|
44
|
-
if (nodeKeys.indexOf(contentKey) > -1) {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// content is with valid group
|
|
49
|
-
for (var supportedKey in nodes) {
|
|
50
|
-
var nodeSpec = nodes[supportedKey];
|
|
51
|
-
if (nodeSpec && nodeSpec.group === contentKey) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return false;
|
|
56
|
-
}
|