@atlaskit/editor-plugin-limited-mode 4.0.2 → 4.0.4

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,20 @@
1
1
  # @atlaskit/editor-plugin-limited-mode
2
2
 
3
+ ## 4.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 4.0.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [`256b4fc86bae0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/256b4fc86bae0) -
14
+ [ux] EDITOR-4464 Limited Mode: Change threshold to activate limited mode to use the node count
15
+ rather than the raw document size.
16
+ - Updated dependencies
17
+
3
18
  ## 4.0.2
4
19
 
5
20
  ### Patch Changes
@@ -6,8 +6,41 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.limitedModePluginKey = exports.createPlugin = void 0;
7
7
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
+ var _expVal = require("@atlaskit/tmp-editor-statsig/expVal");
9
10
  var limitedModePluginKey = exports.limitedModePluginKey = new _state.PluginKey('limitedModePlugin');
10
11
  var LIMITED_MODE_NODE_SIZE_THRESHOLD = 40000;
12
+ /**
13
+ * Counts nodes in the document.
14
+ *
15
+ * Note: legacy-content macros add a damped contribution based on ADF length to avoid
16
+ * parsing nested ADF on every check, which is inefficient.
17
+ */
18
+ var countNodesInDoc = function countNodesInDoc(doc, lcmDampingFactor) {
19
+ var nodeCount = 0;
20
+ doc.descendants(function (node) {
21
+ var _node$attrs;
22
+ nodeCount += 1;
23
+ if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
24
+ var _node$attrs2;
25
+ var adfLength = (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 || (_node$attrs2 = _node$attrs2.parameters) === null || _node$attrs2 === void 0 || (_node$attrs2 = _node$attrs2.adf) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.length;
26
+ if (typeof adfLength === 'number' && lcmDampingFactor > 0) {
27
+ nodeCount += Math.ceil(adfLength / lcmDampingFactor);
28
+ }
29
+ }
30
+ });
31
+ return nodeCount;
32
+ };
33
+
34
+ /**
35
+ * Guard against test overrides returning booleans for numeric params.
36
+ */
37
+ var getNumericExperimentParam = function getNumericExperimentParam(experimentName, paramName, fallbackValue) {
38
+ var rawValue = (0, _expVal.expVal)(experimentName, paramName, fallbackValue);
39
+ if (typeof rawValue === 'number') {
40
+ return rawValue;
41
+ }
42
+ return fallbackValue;
43
+ };
11
44
  var createPlugin = exports.createPlugin = function createPlugin() {
12
45
  return new _safePlugin.SafePlugin({
13
46
  key: limitedModePluginKey,
@@ -16,42 +49,60 @@ var createPlugin = exports.createPlugin = function createPlugin() {
16
49
  },
17
50
  state: {
18
51
  init: function init(config, editorState) {
19
- // calculates the size of the doc, where when there are legacy content macros, the content
20
- // is stored in the attrs.
21
- // This is essentiall doc.nod
22
- var customDocSize = editorState.doc.nodeSize;
23
- editorState.doc.descendants(function (node) {
24
- var _node$attrs;
25
- if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
26
- var _node$attrs$parameter, _node$attrs2;
27
- customDocSize += (_node$attrs$parameter = (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 || (_node$attrs2 = _node$attrs2.parameters) === null || _node$attrs2 === void 0 || (_node$attrs2 = _node$attrs2.adf) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.length) !== null && _node$attrs$parameter !== void 0 ? _node$attrs$parameter : 0;
28
- }
29
- });
30
- return {
31
- documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
32
- };
52
+ if ((0, _expVal.expVal)('cc_editor_limited_mode_expanded', 'isEnabled', false)) {
53
+ var lcmNodeCountDampingFactor = getNumericExperimentParam('cc_editor_limited_mode_expanded', 'lcmNodeCountDampingFactor', 10);
54
+ var nodeCountThreshold = getNumericExperimentParam('cc_editor_limited_mode_expanded', 'nodeCountThreshold', 1000);
55
+ var nodeCount = countNodesInDoc(editorState.doc, lcmNodeCountDampingFactor);
56
+ return {
57
+ documentSizeBreachesThreshold: nodeCount > nodeCountThreshold
58
+ };
59
+ } else {
60
+ // calculates the size of the doc, where when there are legacy content macros, the content
61
+ // is stored in the attrs.
62
+ // This is essentiall doc.nod
63
+ var customDocSize = editorState.doc.nodeSize;
64
+ editorState.doc.descendants(function (node) {
65
+ var _node$attrs3;
66
+ if (((_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.extensionKey) === 'legacy-content') {
67
+ var _node$attrs$parameter, _node$attrs4;
68
+ customDocSize += (_node$attrs$parameter = (_node$attrs4 = node.attrs) === null || _node$attrs4 === void 0 || (_node$attrs4 = _node$attrs4.parameters) === null || _node$attrs4 === void 0 || (_node$attrs4 = _node$attrs4.adf) === null || _node$attrs4 === void 0 ? void 0 : _node$attrs4.length) !== null && _node$attrs$parameter !== void 0 ? _node$attrs$parameter : 0;
69
+ }
70
+ });
71
+ return {
72
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
73
+ };
74
+ }
33
75
  },
34
- apply: function apply(tr, currentPluginState) {
76
+ apply: function apply(tr, currentPluginState, _oldState, _newState) {
35
77
  // Don't check the document size if we're already in limited mode.
36
78
  // We ALWAYS want to re-check the document size if we're replacing the document (e.g. live-to-live page navigation).
79
+
37
80
  if (currentPluginState.documentSizeBreachesThreshold && !tr.getMeta('replaceDocument')) {
38
81
  return currentPluginState;
39
82
  }
40
-
41
- // calculates the size of the doc, where when there are legacy content macros, the content
42
- // is stored in the attrs.
43
- // This is essentiall doc.nod
44
- var customDocSize = tr.doc.nodeSize;
45
- tr.doc.descendants(function (node) {
46
- var _node$attrs3;
47
- if (((_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.extensionKey) === 'legacy-content') {
48
- var _node$attrs$parameter2, _node$attrs4;
49
- customDocSize += (_node$attrs$parameter2 = (_node$attrs4 = node.attrs) === null || _node$attrs4 === void 0 || (_node$attrs4 = _node$attrs4.parameters) === null || _node$attrs4 === void 0 || (_node$attrs4 = _node$attrs4.adf) === null || _node$attrs4 === void 0 ? void 0 : _node$attrs4.length) !== null && _node$attrs$parameter2 !== void 0 ? _node$attrs$parameter2 : 0;
50
- }
51
- });
52
- return {
53
- documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
54
- };
83
+ if ((0, _expVal.expVal)('cc_editor_limited_mode_expanded', 'isEnabled', false)) {
84
+ var lcmNodeCountDampingFactor = getNumericExperimentParam('cc_editor_limited_mode_expanded', 'lcmNodeCountDampingFactor', 10);
85
+ var nodeCountThreshold = getNumericExperimentParam('cc_editor_limited_mode_expanded', 'nodeCountThreshold', 1000);
86
+ var nodeCount = countNodesInDoc(tr.doc, lcmNodeCountDampingFactor);
87
+ return {
88
+ documentSizeBreachesThreshold: nodeCount > nodeCountThreshold
89
+ };
90
+ } else {
91
+ // calculates the size of the doc, where when there are legacy content macros, the content
92
+ // is stored in the attrs.
93
+ // This is essentiall doc.nod
94
+ var customDocSize = tr.doc.nodeSize;
95
+ tr.doc.descendants(function (node) {
96
+ var _node$attrs5;
97
+ if (((_node$attrs5 = node.attrs) === null || _node$attrs5 === void 0 ? void 0 : _node$attrs5.extensionKey) === 'legacy-content') {
98
+ var _node$attrs$parameter2, _node$attrs6;
99
+ customDocSize += (_node$attrs$parameter2 = (_node$attrs6 = node.attrs) === null || _node$attrs6 === void 0 || (_node$attrs6 = _node$attrs6.parameters) === null || _node$attrs6 === void 0 || (_node$attrs6 = _node$attrs6.adf) === null || _node$attrs6 === void 0 ? void 0 : _node$attrs6.length) !== null && _node$attrs$parameter2 !== void 0 ? _node$attrs$parameter2 : 0;
100
+ }
101
+ });
102
+ return {
103
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
104
+ };
105
+ }
55
106
  }
56
107
  }
57
108
  });
@@ -1,7 +1,40 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
+ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
3
4
  export const limitedModePluginKey = new PluginKey('limitedModePlugin');
4
5
  const LIMITED_MODE_NODE_SIZE_THRESHOLD = 40000;
6
+ /**
7
+ * Counts nodes in the document.
8
+ *
9
+ * Note: legacy-content macros add a damped contribution based on ADF length to avoid
10
+ * parsing nested ADF on every check, which is inefficient.
11
+ */
12
+ const countNodesInDoc = (doc, lcmDampingFactor) => {
13
+ let nodeCount = 0;
14
+ doc.descendants(node => {
15
+ var _node$attrs;
16
+ nodeCount += 1;
17
+ if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
18
+ var _node$attrs2, _node$attrs2$paramete, _node$attrs2$paramete2;
19
+ const adfLength = (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : (_node$attrs2$paramete = _node$attrs2.parameters) === null || _node$attrs2$paramete === void 0 ? void 0 : (_node$attrs2$paramete2 = _node$attrs2$paramete.adf) === null || _node$attrs2$paramete2 === void 0 ? void 0 : _node$attrs2$paramete2.length;
20
+ if (typeof adfLength === 'number' && lcmDampingFactor > 0) {
21
+ nodeCount += Math.ceil(adfLength / lcmDampingFactor);
22
+ }
23
+ }
24
+ });
25
+ return nodeCount;
26
+ };
27
+
28
+ /**
29
+ * Guard against test overrides returning booleans for numeric params.
30
+ */
31
+ const getNumericExperimentParam = (experimentName, paramName, fallbackValue) => {
32
+ const rawValue = expVal(experimentName, paramName, fallbackValue);
33
+ if (typeof rawValue === 'number') {
34
+ return rawValue;
35
+ }
36
+ return fallbackValue;
37
+ };
5
38
  export const createPlugin = () => {
6
39
  return new SafePlugin({
7
40
  key: limitedModePluginKey,
@@ -10,42 +43,60 @@ export const createPlugin = () => {
10
43
  },
11
44
  state: {
12
45
  init(config, editorState) {
13
- // calculates the size of the doc, where when there are legacy content macros, the content
14
- // is stored in the attrs.
15
- // This is essentiall doc.nod
16
- let customDocSize = editorState.doc.nodeSize;
17
- editorState.doc.descendants(node => {
18
- var _node$attrs;
19
- if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
20
- var _node$attrs$parameter, _node$attrs2, _node$attrs2$paramete, _node$attrs2$paramete2;
21
- customDocSize += (_node$attrs$parameter = (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : (_node$attrs2$paramete = _node$attrs2.parameters) === null || _node$attrs2$paramete === void 0 ? void 0 : (_node$attrs2$paramete2 = _node$attrs2$paramete.adf) === null || _node$attrs2$paramete2 === void 0 ? void 0 : _node$attrs2$paramete2.length) !== null && _node$attrs$parameter !== void 0 ? _node$attrs$parameter : 0;
22
- }
23
- });
24
- return {
25
- documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
26
- };
46
+ if (expVal('cc_editor_limited_mode_expanded', 'isEnabled', false)) {
47
+ const lcmNodeCountDampingFactor = getNumericExperimentParam('cc_editor_limited_mode_expanded', 'lcmNodeCountDampingFactor', 10);
48
+ const nodeCountThreshold = getNumericExperimentParam('cc_editor_limited_mode_expanded', 'nodeCountThreshold', 1000);
49
+ const nodeCount = countNodesInDoc(editorState.doc, lcmNodeCountDampingFactor);
50
+ return {
51
+ documentSizeBreachesThreshold: nodeCount > nodeCountThreshold
52
+ };
53
+ } else {
54
+ // calculates the size of the doc, where when there are legacy content macros, the content
55
+ // is stored in the attrs.
56
+ // This is essentiall doc.nod
57
+ let customDocSize = editorState.doc.nodeSize;
58
+ editorState.doc.descendants(node => {
59
+ var _node$attrs3;
60
+ if (((_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.extensionKey) === 'legacy-content') {
61
+ var _node$attrs$parameter, _node$attrs4, _node$attrs4$paramete, _node$attrs4$paramete2;
62
+ customDocSize += (_node$attrs$parameter = (_node$attrs4 = node.attrs) === null || _node$attrs4 === void 0 ? void 0 : (_node$attrs4$paramete = _node$attrs4.parameters) === null || _node$attrs4$paramete === void 0 ? void 0 : (_node$attrs4$paramete2 = _node$attrs4$paramete.adf) === null || _node$attrs4$paramete2 === void 0 ? void 0 : _node$attrs4$paramete2.length) !== null && _node$attrs$parameter !== void 0 ? _node$attrs$parameter : 0;
63
+ }
64
+ });
65
+ return {
66
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
67
+ };
68
+ }
27
69
  },
28
- apply: (tr, currentPluginState) => {
70
+ apply: (tr, currentPluginState, _oldState, _newState) => {
29
71
  // Don't check the document size if we're already in limited mode.
30
72
  // We ALWAYS want to re-check the document size if we're replacing the document (e.g. live-to-live page navigation).
73
+
31
74
  if (currentPluginState.documentSizeBreachesThreshold && !tr.getMeta('replaceDocument')) {
32
75
  return currentPluginState;
33
76
  }
34
-
35
- // calculates the size of the doc, where when there are legacy content macros, the content
36
- // is stored in the attrs.
37
- // This is essentiall doc.nod
38
- let customDocSize = tr.doc.nodeSize;
39
- tr.doc.descendants(node => {
40
- var _node$attrs3;
41
- if (((_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.extensionKey) === 'legacy-content') {
42
- var _node$attrs$parameter2, _node$attrs4, _node$attrs4$paramete, _node$attrs4$paramete2;
43
- customDocSize += (_node$attrs$parameter2 = (_node$attrs4 = node.attrs) === null || _node$attrs4 === void 0 ? void 0 : (_node$attrs4$paramete = _node$attrs4.parameters) === null || _node$attrs4$paramete === void 0 ? void 0 : (_node$attrs4$paramete2 = _node$attrs4$paramete.adf) === null || _node$attrs4$paramete2 === void 0 ? void 0 : _node$attrs4$paramete2.length) !== null && _node$attrs$parameter2 !== void 0 ? _node$attrs$parameter2 : 0;
44
- }
45
- });
46
- return {
47
- documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
48
- };
77
+ if (expVal('cc_editor_limited_mode_expanded', 'isEnabled', false)) {
78
+ const lcmNodeCountDampingFactor = getNumericExperimentParam('cc_editor_limited_mode_expanded', 'lcmNodeCountDampingFactor', 10);
79
+ const nodeCountThreshold = getNumericExperimentParam('cc_editor_limited_mode_expanded', 'nodeCountThreshold', 1000);
80
+ const nodeCount = countNodesInDoc(tr.doc, lcmNodeCountDampingFactor);
81
+ return {
82
+ documentSizeBreachesThreshold: nodeCount > nodeCountThreshold
83
+ };
84
+ } else {
85
+ // calculates the size of the doc, where when there are legacy content macros, the content
86
+ // is stored in the attrs.
87
+ // This is essentiall doc.nod
88
+ let customDocSize = tr.doc.nodeSize;
89
+ tr.doc.descendants(node => {
90
+ var _node$attrs5;
91
+ if (((_node$attrs5 = node.attrs) === null || _node$attrs5 === void 0 ? void 0 : _node$attrs5.extensionKey) === 'legacy-content') {
92
+ var _node$attrs$parameter2, _node$attrs6, _node$attrs6$paramete, _node$attrs6$paramete2;
93
+ customDocSize += (_node$attrs$parameter2 = (_node$attrs6 = node.attrs) === null || _node$attrs6 === void 0 ? void 0 : (_node$attrs6$paramete = _node$attrs6.parameters) === null || _node$attrs6$paramete === void 0 ? void 0 : (_node$attrs6$paramete2 = _node$attrs6$paramete.adf) === null || _node$attrs6$paramete2 === void 0 ? void 0 : _node$attrs6$paramete2.length) !== null && _node$attrs$parameter2 !== void 0 ? _node$attrs$parameter2 : 0;
94
+ }
95
+ });
96
+ return {
97
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
98
+ };
99
+ }
49
100
  }
50
101
  }
51
102
  });
@@ -1,7 +1,40 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
+ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
3
4
  export var limitedModePluginKey = new PluginKey('limitedModePlugin');
4
5
  var LIMITED_MODE_NODE_SIZE_THRESHOLD = 40000;
6
+ /**
7
+ * Counts nodes in the document.
8
+ *
9
+ * Note: legacy-content macros add a damped contribution based on ADF length to avoid
10
+ * parsing nested ADF on every check, which is inefficient.
11
+ */
12
+ var countNodesInDoc = function countNodesInDoc(doc, lcmDampingFactor) {
13
+ var nodeCount = 0;
14
+ doc.descendants(function (node) {
15
+ var _node$attrs;
16
+ nodeCount += 1;
17
+ if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
18
+ var _node$attrs2;
19
+ var adfLength = (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 || (_node$attrs2 = _node$attrs2.parameters) === null || _node$attrs2 === void 0 || (_node$attrs2 = _node$attrs2.adf) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.length;
20
+ if (typeof adfLength === 'number' && lcmDampingFactor > 0) {
21
+ nodeCount += Math.ceil(adfLength / lcmDampingFactor);
22
+ }
23
+ }
24
+ });
25
+ return nodeCount;
26
+ };
27
+
28
+ /**
29
+ * Guard against test overrides returning booleans for numeric params.
30
+ */
31
+ var getNumericExperimentParam = function getNumericExperimentParam(experimentName, paramName, fallbackValue) {
32
+ var rawValue = expVal(experimentName, paramName, fallbackValue);
33
+ if (typeof rawValue === 'number') {
34
+ return rawValue;
35
+ }
36
+ return fallbackValue;
37
+ };
5
38
  export var createPlugin = function createPlugin() {
6
39
  return new SafePlugin({
7
40
  key: limitedModePluginKey,
@@ -10,42 +43,60 @@ export var createPlugin = function createPlugin() {
10
43
  },
11
44
  state: {
12
45
  init: function init(config, editorState) {
13
- // calculates the size of the doc, where when there are legacy content macros, the content
14
- // is stored in the attrs.
15
- // This is essentiall doc.nod
16
- var customDocSize = editorState.doc.nodeSize;
17
- editorState.doc.descendants(function (node) {
18
- var _node$attrs;
19
- if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
20
- var _node$attrs$parameter, _node$attrs2;
21
- customDocSize += (_node$attrs$parameter = (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 || (_node$attrs2 = _node$attrs2.parameters) === null || _node$attrs2 === void 0 || (_node$attrs2 = _node$attrs2.adf) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.length) !== null && _node$attrs$parameter !== void 0 ? _node$attrs$parameter : 0;
22
- }
23
- });
24
- return {
25
- documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
26
- };
46
+ if (expVal('cc_editor_limited_mode_expanded', 'isEnabled', false)) {
47
+ var lcmNodeCountDampingFactor = getNumericExperimentParam('cc_editor_limited_mode_expanded', 'lcmNodeCountDampingFactor', 10);
48
+ var nodeCountThreshold = getNumericExperimentParam('cc_editor_limited_mode_expanded', 'nodeCountThreshold', 1000);
49
+ var nodeCount = countNodesInDoc(editorState.doc, lcmNodeCountDampingFactor);
50
+ return {
51
+ documentSizeBreachesThreshold: nodeCount > nodeCountThreshold
52
+ };
53
+ } else {
54
+ // calculates the size of the doc, where when there are legacy content macros, the content
55
+ // is stored in the attrs.
56
+ // This is essentiall doc.nod
57
+ var customDocSize = editorState.doc.nodeSize;
58
+ editorState.doc.descendants(function (node) {
59
+ var _node$attrs3;
60
+ if (((_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.extensionKey) === 'legacy-content') {
61
+ var _node$attrs$parameter, _node$attrs4;
62
+ customDocSize += (_node$attrs$parameter = (_node$attrs4 = node.attrs) === null || _node$attrs4 === void 0 || (_node$attrs4 = _node$attrs4.parameters) === null || _node$attrs4 === void 0 || (_node$attrs4 = _node$attrs4.adf) === null || _node$attrs4 === void 0 ? void 0 : _node$attrs4.length) !== null && _node$attrs$parameter !== void 0 ? _node$attrs$parameter : 0;
63
+ }
64
+ });
65
+ return {
66
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
67
+ };
68
+ }
27
69
  },
28
- apply: function apply(tr, currentPluginState) {
70
+ apply: function apply(tr, currentPluginState, _oldState, _newState) {
29
71
  // Don't check the document size if we're already in limited mode.
30
72
  // We ALWAYS want to re-check the document size if we're replacing the document (e.g. live-to-live page navigation).
73
+
31
74
  if (currentPluginState.documentSizeBreachesThreshold && !tr.getMeta('replaceDocument')) {
32
75
  return currentPluginState;
33
76
  }
34
-
35
- // calculates the size of the doc, where when there are legacy content macros, the content
36
- // is stored in the attrs.
37
- // This is essentiall doc.nod
38
- var customDocSize = tr.doc.nodeSize;
39
- tr.doc.descendants(function (node) {
40
- var _node$attrs3;
41
- if (((_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.extensionKey) === 'legacy-content') {
42
- var _node$attrs$parameter2, _node$attrs4;
43
- customDocSize += (_node$attrs$parameter2 = (_node$attrs4 = node.attrs) === null || _node$attrs4 === void 0 || (_node$attrs4 = _node$attrs4.parameters) === null || _node$attrs4 === void 0 || (_node$attrs4 = _node$attrs4.adf) === null || _node$attrs4 === void 0 ? void 0 : _node$attrs4.length) !== null && _node$attrs$parameter2 !== void 0 ? _node$attrs$parameter2 : 0;
44
- }
45
- });
46
- return {
47
- documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
48
- };
77
+ if (expVal('cc_editor_limited_mode_expanded', 'isEnabled', false)) {
78
+ var lcmNodeCountDampingFactor = getNumericExperimentParam('cc_editor_limited_mode_expanded', 'lcmNodeCountDampingFactor', 10);
79
+ var nodeCountThreshold = getNumericExperimentParam('cc_editor_limited_mode_expanded', 'nodeCountThreshold', 1000);
80
+ var nodeCount = countNodesInDoc(tr.doc, lcmNodeCountDampingFactor);
81
+ return {
82
+ documentSizeBreachesThreshold: nodeCount > nodeCountThreshold
83
+ };
84
+ } else {
85
+ // calculates the size of the doc, where when there are legacy content macros, the content
86
+ // is stored in the attrs.
87
+ // This is essentiall doc.nod
88
+ var customDocSize = tr.doc.nodeSize;
89
+ tr.doc.descendants(function (node) {
90
+ var _node$attrs5;
91
+ if (((_node$attrs5 = node.attrs) === null || _node$attrs5 === void 0 ? void 0 : _node$attrs5.extensionKey) === 'legacy-content') {
92
+ var _node$attrs$parameter2, _node$attrs6;
93
+ customDocSize += (_node$attrs$parameter2 = (_node$attrs6 = node.attrs) === null || _node$attrs6 === void 0 || (_node$attrs6 = _node$attrs6.parameters) === null || _node$attrs6 === void 0 || (_node$attrs6 = _node$attrs6.adf) === null || _node$attrs6 === void 0 ? void 0 : _node$attrs6.length) !== null && _node$attrs$parameter2 !== void 0 ? _node$attrs$parameter2 : 0;
94
+ }
95
+ });
96
+ return {
97
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
98
+ };
99
+ }
49
100
  }
50
101
  }
51
102
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-limited-mode",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "LimitedMode plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -28,15 +28,15 @@
28
28
  "sideEffects": false,
29
29
  "atlaskit:src": "src/index.ts",
30
30
  "dependencies": {
31
- "@atlaskit/editor-prosemirror": "^7.2.0",
31
+ "@atlaskit/editor-prosemirror": "^7.3.0",
32
32
  "@atlaskit/platform-feature-flags": "^1.1.0",
33
- "@atlaskit/tmp-editor-statsig": "^16.29.0",
33
+ "@atlaskit/tmp-editor-statsig": "^18.0.0",
34
34
  "@babel/runtime": "^7.0.0",
35
35
  "bind-event-listener": "^3.0.0",
36
36
  "react-intl-next": "npm:react-intl@^5.18.1"
37
37
  },
38
38
  "peerDependencies": {
39
- "@atlaskit/editor-common": "^111.8.0",
39
+ "@atlaskit/editor-common": "^111.11.0",
40
40
  "react": "^18.2.0"
41
41
  },
42
42
  "devDependencies": {