@atlaskit/editor-core 207.16.0 → 207.17.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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 207.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#167295](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/167295)
8
+ [`6c94765105520`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6c94765105520) -
9
+ [https://product-fabric.atlassian.net/browse/ED-28212](ED-28212) - the `validNode()` function from
10
+ @atlaskit/editor-core package will use memoization
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
3
16
  ## 207.16.0
4
17
 
5
18
  ### Minor Changes
@@ -4,9 +4,54 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.validateNodes = exports.validNode = void 0;
7
+ var _model = require("@atlaskit/editor-prosemirror/model");
8
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
9
+ // We don't want to use memoize from lodash, because we need to use WeakMap or WeakSet
10
+ // to avoid memory leaks, but lodash allow to change the cache type only globally
11
+ // like `memoize.Cache = WeakMap`, and we don't want to do that.
12
+ // So we use our own cache implementation.
13
+ var cache = new WeakSet();
14
+
15
+ // See https://github.com/ProseMirror/prosemirror-model/blob/20d26c9843d6a69a1d417d937c401537ee0b2342/src/node.ts#L303
16
+ function checkNode(node) {
17
+ if (cache.has(node)) {
18
+ return;
19
+ }
20
+
21
+ // @ts-expect-error - This is internal ProseMirror API, but we okay with it
22
+ node.type.checkContent(node.content);
23
+ // @ts-expect-error - This is internal ProseMirror API, but we okay with it
24
+ node.type.checkAttrs(node.attrs);
25
+ var copy = _model.Mark.none;
26
+ for (var i = 0; i < node.marks.length; i++) {
27
+ var mark = node.marks[i];
28
+ // @ts-expect-error - This is internal ProseMirror API, but we okay with it
29
+ mark.type.checkAttrs(mark.attrs);
30
+ copy = mark.addToSet(copy);
31
+ }
32
+ if (!_model.Mark.sameSet(copy, node.marks)) {
33
+ throw new RangeError("Invalid collection of marks for node ".concat(node.type.name, ": ").concat(node.marks.map(function (m) {
34
+ return m.type.name;
35
+ })));
36
+ }
37
+ node.content.forEach(function (node) {
38
+ return checkNode(node);
39
+ });
40
+
41
+ // The set value should be added in the end of the function,
42
+ // because any previous check can throw an error,
43
+ // and we don't want to add invalid node to the cache.
44
+ cache.add(node);
45
+ }
7
46
  var validNode = exports.validNode = function validNode(node) {
8
47
  try {
9
- node.check(); // this will throw an error if the node is invalid
48
+ if ((0, _experiments.editorExperiment)('platform_editor_memoized_node_check', true, {
49
+ exposure: true
50
+ })) {
51
+ checkNode(node);
52
+ } else {
53
+ node.check();
54
+ }
10
55
  } catch (error) {
11
56
  return false;
12
57
  }
@@ -5,4 +5,4 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.version = exports.name = void 0;
7
7
  var name = exports.name = "@atlaskit/editor-core";
8
- var version = exports.version = "207.16.0";
8
+ var version = exports.version = "207.17.0";
@@ -1,6 +1,48 @@
1
+ import { Mark } from '@atlaskit/editor-prosemirror/model';
2
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
3
+
4
+ // We don't want to use memoize from lodash, because we need to use WeakMap or WeakSet
5
+ // to avoid memory leaks, but lodash allow to change the cache type only globally
6
+ // like `memoize.Cache = WeakMap`, and we don't want to do that.
7
+ // So we use our own cache implementation.
8
+ const cache = new WeakSet();
9
+
10
+ // See https://github.com/ProseMirror/prosemirror-model/blob/20d26c9843d6a69a1d417d937c401537ee0b2342/src/node.ts#L303
11
+ function checkNode(node) {
12
+ if (cache.has(node)) {
13
+ return;
14
+ }
15
+
16
+ // @ts-expect-error - This is internal ProseMirror API, but we okay with it
17
+ node.type.checkContent(node.content);
18
+ // @ts-expect-error - This is internal ProseMirror API, but we okay with it
19
+ node.type.checkAttrs(node.attrs);
20
+ let copy = Mark.none;
21
+ for (let i = 0; i < node.marks.length; i++) {
22
+ const mark = node.marks[i];
23
+ // @ts-expect-error - This is internal ProseMirror API, but we okay with it
24
+ mark.type.checkAttrs(mark.attrs);
25
+ copy = mark.addToSet(copy);
26
+ }
27
+ if (!Mark.sameSet(copy, node.marks)) {
28
+ throw new RangeError(`Invalid collection of marks for node ${node.type.name}: ${node.marks.map(m => m.type.name)}`);
29
+ }
30
+ node.content.forEach(node => checkNode(node));
31
+
32
+ // The set value should be added in the end of the function,
33
+ // because any previous check can throw an error,
34
+ // and we don't want to add invalid node to the cache.
35
+ cache.add(node);
36
+ }
1
37
  export const validNode = node => {
2
38
  try {
3
- node.check(); // this will throw an error if the node is invalid
39
+ if (editorExperiment('platform_editor_memoized_node_check', true, {
40
+ exposure: true
41
+ })) {
42
+ checkNode(node);
43
+ } else {
44
+ node.check();
45
+ }
4
46
  } catch (error) {
5
47
  return false;
6
48
  }
@@ -1,2 +1,2 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "207.16.0";
2
+ export const version = "207.17.0";
@@ -1,6 +1,52 @@
1
+ import { Mark } from '@atlaskit/editor-prosemirror/model';
2
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
3
+
4
+ // We don't want to use memoize from lodash, because we need to use WeakMap or WeakSet
5
+ // to avoid memory leaks, but lodash allow to change the cache type only globally
6
+ // like `memoize.Cache = WeakMap`, and we don't want to do that.
7
+ // So we use our own cache implementation.
8
+ var cache = new WeakSet();
9
+
10
+ // See https://github.com/ProseMirror/prosemirror-model/blob/20d26c9843d6a69a1d417d937c401537ee0b2342/src/node.ts#L303
11
+ function checkNode(node) {
12
+ if (cache.has(node)) {
13
+ return;
14
+ }
15
+
16
+ // @ts-expect-error - This is internal ProseMirror API, but we okay with it
17
+ node.type.checkContent(node.content);
18
+ // @ts-expect-error - This is internal ProseMirror API, but we okay with it
19
+ node.type.checkAttrs(node.attrs);
20
+ var copy = Mark.none;
21
+ for (var i = 0; i < node.marks.length; i++) {
22
+ var mark = node.marks[i];
23
+ // @ts-expect-error - This is internal ProseMirror API, but we okay with it
24
+ mark.type.checkAttrs(mark.attrs);
25
+ copy = mark.addToSet(copy);
26
+ }
27
+ if (!Mark.sameSet(copy, node.marks)) {
28
+ throw new RangeError("Invalid collection of marks for node ".concat(node.type.name, ": ").concat(node.marks.map(function (m) {
29
+ return m.type.name;
30
+ })));
31
+ }
32
+ node.content.forEach(function (node) {
33
+ return checkNode(node);
34
+ });
35
+
36
+ // The set value should be added in the end of the function,
37
+ // because any previous check can throw an error,
38
+ // and we don't want to add invalid node to the cache.
39
+ cache.add(node);
40
+ }
1
41
  export var validNode = function validNode(node) {
2
42
  try {
3
- node.check(); // this will throw an error if the node is invalid
43
+ if (editorExperiment('platform_editor_memoized_node_check', true, {
44
+ exposure: true
45
+ })) {
46
+ checkNode(node);
47
+ } else {
48
+ node.check();
49
+ }
4
50
  } catch (error) {
5
51
  return false;
6
52
  }
@@ -1,2 +1,2 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "207.16.0";
2
+ export var version = "207.17.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "207.16.0",
3
+ "version": "207.17.0",
4
4
  "description": "A package contains Atlassian editor core functionality",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -62,7 +62,7 @@
62
62
  "@atlaskit/platform-feature-flags-react": "^0.2.0",
63
63
  "@atlaskit/react-ufo": "^3.13.0",
64
64
  "@atlaskit/task-decision": "^19.2.0",
65
- "@atlaskit/tmp-editor-statsig": "^5.13.0",
65
+ "@atlaskit/tmp-editor-statsig": "^5.14.0",
66
66
  "@atlaskit/tokens": "^5.1.0",
67
67
  "@atlaskit/tooltip": "^20.3.0",
68
68
  "@atlaskit/width-detector": "^5.0.0",