@atlaskit/editor-plugin-limited-mode 7.0.3 → 7.1.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 +12 -0
- package/dist/cjs/pm-plugins/main.js +24 -90
- package/dist/es2019/pm-plugins/main.js +24 -90
- package/dist/esm/pm-plugins/main.js +24 -90
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-limited-mode
|
|
2
2
|
|
|
3
|
+
## 7.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`f25ff7f70d948`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f25ff7f70d948) -
|
|
8
|
+
FFCLEANUP-91667 Remove shipped limited-mode experiment from Statsig config; use fixed document
|
|
9
|
+
thresholds in editor-common for limited-mode detection.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
3
15
|
## 7.0.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -4,101 +4,53 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.limitedModePluginKey = exports.createPlugin = void 0;
|
|
7
|
+
var _limitedModeDocumentThresholds = require("@atlaskit/editor-common/limited-mode-document-thresholds");
|
|
7
8
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
8
9
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
|
-
var _expVal = require("@atlaskit/tmp-editor-statsig/expVal");
|
|
10
10
|
var limitedModePluginKey = exports.limitedModePluginKey = new _state.PluginKey('limitedModePlugin');
|
|
11
|
-
var LIMITED_MODE_NODE_SIZE_THRESHOLD = 40000;
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
14
|
-
* This guards against test overrides returning booleans or strings for numeric params.
|
|
15
|
-
*/
|
|
16
|
-
var getNumericExperimentParam = function getNumericExperimentParam(paramName, fallbackValue) {
|
|
17
|
-
var rawValue = (0, _expVal.expVal)('cc_editor_limited_mode_expanded', paramName, fallbackValue);
|
|
18
|
-
if (typeof rawValue === 'number') {
|
|
19
|
-
return rawValue;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Handle string values from test overrides
|
|
23
|
-
if (typeof rawValue === 'string') {
|
|
24
|
-
var parsed = parseInt(rawValue, 10);
|
|
25
|
-
if (!isNaN(parsed)) {
|
|
26
|
-
return parsed;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return undefined;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Calculates custom document size including LCM ADF lengths (for non-expanded path).
|
|
34
|
-
* This function can be removed when cc_editor_limited_mode_expanded is cleaned up.
|
|
35
|
-
*/
|
|
36
|
-
var getCustomDocSize = function getCustomDocSize(doc) {
|
|
37
|
-
var lcmAdfLength = 0;
|
|
38
|
-
doc.descendants(function (node) {
|
|
39
|
-
var _node$attrs;
|
|
40
|
-
if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
|
|
41
|
-
var _node$attrs$parameter, _node$attrs2;
|
|
42
|
-
lcmAdfLength += (_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;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return doc.nodeSize + lcmAdfLength;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Determines whether limited mode should be enabled under the expanded gate.
|
|
12
|
+
* Determines whether limited mode should be enabled for a document.
|
|
50
13
|
* If this logic changes, update the duplicate in `editor-common/src/node-anchor/node-anchor-provider.ts` to avoid drift.
|
|
51
14
|
*
|
|
52
15
|
* Limited mode is activated when ANY of the following conditions are met:
|
|
53
|
-
* 1. Document size exceeds `
|
|
54
|
-
* 2. Node count exceeds `
|
|
55
|
-
* 3. Document contains a legacy-content macro (LCM)
|
|
16
|
+
* 1. Document size exceeds `LIMITED_MODE_DEFAULT_DOC_SIZE_THRESHOLD`
|
|
17
|
+
* 2. Node count exceeds `LIMITED_MODE_DEFAULT_NODE_COUNT_THRESHOLD`
|
|
18
|
+
* 3. Document contains a legacy-content macro (LCM)
|
|
56
19
|
*
|
|
57
20
|
* Performance optimisations:
|
|
58
21
|
* - Doc size is checked first (O(1)) - if it exceeds threshold, we skip traversal entirely.
|
|
59
|
-
* - If
|
|
60
|
-
* since we already know limited mode will be enabled.
|
|
61
|
-
* - If neither node count nor LCM conditions are configured, we skip traversal entirely.
|
|
22
|
+
* - If we find an LCM during traversal, we exit early since limited mode will be enabled.
|
|
62
23
|
*/
|
|
63
|
-
var
|
|
64
|
-
var nodeCountThreshold =
|
|
65
|
-
var docSizeThreshold =
|
|
66
|
-
var includeLcmInThreshold = Boolean((0, _expVal.expVal)('cc_editor_limited_mode_expanded', 'includeLcmInThreshold', false));
|
|
24
|
+
var shouldEnableLimitedModeForDocument = function shouldEnableLimitedModeForDocument(doc) {
|
|
25
|
+
var nodeCountThreshold = _limitedModeDocumentThresholds.LIMITED_MODE_DEFAULT_NODE_COUNT_THRESHOLD;
|
|
26
|
+
var docSizeThreshold = _limitedModeDocumentThresholds.LIMITED_MODE_DEFAULT_DOC_SIZE_THRESHOLD;
|
|
67
27
|
|
|
68
28
|
// Early exit: doc size exceeds threshold - O(1), no traversal needed
|
|
69
|
-
if (
|
|
29
|
+
if (doc.nodeSize > docSizeThreshold) {
|
|
70
30
|
return true;
|
|
71
31
|
}
|
|
72
32
|
|
|
73
|
-
//
|
|
74
|
-
var needNodeCount = nodeCountThreshold !== undefined;
|
|
75
|
-
if (!needNodeCount && !includeLcmInThreshold) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Single traversal for node count and/or LCM detection
|
|
33
|
+
// Single traversal for node count and LCM detection
|
|
80
34
|
var nodeCount = 0;
|
|
81
35
|
var hasLcm = false;
|
|
82
36
|
doc.descendants(function (node) {
|
|
83
|
-
var _node$
|
|
37
|
+
var _node$attrs;
|
|
84
38
|
nodeCount += 1;
|
|
85
|
-
if (((_node$
|
|
39
|
+
if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
|
|
86
40
|
hasLcm = true;
|
|
87
41
|
|
|
88
|
-
// Early exit: LCM found
|
|
89
|
-
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
42
|
+
// Early exit: LCM found — limited mode will be enabled
|
|
43
|
+
return false;
|
|
92
44
|
}
|
|
93
45
|
});
|
|
94
46
|
|
|
95
47
|
// LCM condition takes precedence (if we early exited traversal, this is why)
|
|
96
|
-
if (
|
|
48
|
+
if (hasLcm) {
|
|
97
49
|
return true;
|
|
98
50
|
}
|
|
99
51
|
|
|
100
52
|
// Check node count threshold
|
|
101
|
-
if (
|
|
53
|
+
if (nodeCount > nodeCountThreshold) {
|
|
102
54
|
return true;
|
|
103
55
|
}
|
|
104
56
|
return false;
|
|
@@ -110,19 +62,10 @@ var createPlugin = exports.createPlugin = function createPlugin() {
|
|
|
110
62
|
return {};
|
|
111
63
|
},
|
|
112
64
|
state: {
|
|
113
|
-
init: function init(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
};
|
|
118
|
-
} else {
|
|
119
|
-
// calculates the size of the doc, where when there are legacy content macros, the content
|
|
120
|
-
// is stored in the attrs.
|
|
121
|
-
var customDocSize = getCustomDocSize(editorState.doc);
|
|
122
|
-
return {
|
|
123
|
-
documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
|
|
124
|
-
};
|
|
125
|
-
}
|
|
65
|
+
init: function init(_config, editorState) {
|
|
66
|
+
return {
|
|
67
|
+
documentSizeBreachesThreshold: shouldEnableLimitedModeForDocument(editorState.doc)
|
|
68
|
+
};
|
|
126
69
|
},
|
|
127
70
|
apply: function apply(tr, currentPluginState, _oldState, _newState) {
|
|
128
71
|
// Don't check the document size if we're already in limited mode.
|
|
@@ -131,18 +74,9 @@ var createPlugin = exports.createPlugin = function createPlugin() {
|
|
|
131
74
|
if (currentPluginState.documentSizeBreachesThreshold && !tr.getMeta('replaceDocument')) {
|
|
132
75
|
return currentPluginState;
|
|
133
76
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
};
|
|
138
|
-
} else {
|
|
139
|
-
// calculates the size of the doc, where when there are legacy content macros, the content
|
|
140
|
-
// is stored in the attrs.
|
|
141
|
-
var customDocSize = getCustomDocSize(tr.doc);
|
|
142
|
-
return {
|
|
143
|
-
documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
|
|
144
|
-
};
|
|
145
|
-
}
|
|
77
|
+
return {
|
|
78
|
+
documentSizeBreachesThreshold: shouldEnableLimitedModeForDocument(tr.doc)
|
|
79
|
+
};
|
|
146
80
|
}
|
|
147
81
|
}
|
|
148
82
|
});
|
|
@@ -1,98 +1,50 @@
|
|
|
1
|
+
import { LIMITED_MODE_DEFAULT_DOC_SIZE_THRESHOLD, LIMITED_MODE_DEFAULT_NODE_COUNT_THRESHOLD } from '@atlaskit/editor-common/limited-mode-document-thresholds';
|
|
1
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
|
|
4
4
|
export const limitedModePluginKey = new PluginKey('limitedModePlugin');
|
|
5
|
-
const LIMITED_MODE_NODE_SIZE_THRESHOLD = 40000;
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
8
|
-
* This guards against test overrides returning booleans or strings for numeric params.
|
|
9
|
-
*/
|
|
10
|
-
const getNumericExperimentParam = (paramName, fallbackValue) => {
|
|
11
|
-
const rawValue = expVal('cc_editor_limited_mode_expanded', paramName, fallbackValue);
|
|
12
|
-
if (typeof rawValue === 'number') {
|
|
13
|
-
return rawValue;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Handle string values from test overrides
|
|
17
|
-
if (typeof rawValue === 'string') {
|
|
18
|
-
const parsed = parseInt(rawValue, 10);
|
|
19
|
-
if (!isNaN(parsed)) {
|
|
20
|
-
return parsed;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return undefined;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Calculates custom document size including LCM ADF lengths (for non-expanded path).
|
|
28
|
-
* This function can be removed when cc_editor_limited_mode_expanded is cleaned up.
|
|
29
|
-
*/
|
|
30
|
-
const getCustomDocSize = doc => {
|
|
31
|
-
let lcmAdfLength = 0;
|
|
32
|
-
doc.descendants(node => {
|
|
33
|
-
var _node$attrs;
|
|
34
|
-
if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
|
|
35
|
-
var _node$attrs$parameter, _node$attrs2, _node$attrs2$paramete, _node$attrs2$paramete2;
|
|
36
|
-
lcmAdfLength += (_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;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return doc.nodeSize + lcmAdfLength;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Determines whether limited mode should be enabled under the expanded gate.
|
|
6
|
+
* Determines whether limited mode should be enabled for a document.
|
|
44
7
|
* If this logic changes, update the duplicate in `editor-common/src/node-anchor/node-anchor-provider.ts` to avoid drift.
|
|
45
8
|
*
|
|
46
9
|
* Limited mode is activated when ANY of the following conditions are met:
|
|
47
|
-
* 1. Document size exceeds `
|
|
48
|
-
* 2. Node count exceeds `
|
|
49
|
-
* 3. Document contains a legacy-content macro (LCM)
|
|
10
|
+
* 1. Document size exceeds `LIMITED_MODE_DEFAULT_DOC_SIZE_THRESHOLD`
|
|
11
|
+
* 2. Node count exceeds `LIMITED_MODE_DEFAULT_NODE_COUNT_THRESHOLD`
|
|
12
|
+
* 3. Document contains a legacy-content macro (LCM)
|
|
50
13
|
*
|
|
51
14
|
* Performance optimisations:
|
|
52
15
|
* - Doc size is checked first (O(1)) - if it exceeds threshold, we skip traversal entirely.
|
|
53
|
-
* - If
|
|
54
|
-
* since we already know limited mode will be enabled.
|
|
55
|
-
* - If neither node count nor LCM conditions are configured, we skip traversal entirely.
|
|
16
|
+
* - If we find an LCM during traversal, we exit early since limited mode will be enabled.
|
|
56
17
|
*/
|
|
57
|
-
const
|
|
58
|
-
const nodeCountThreshold =
|
|
59
|
-
const docSizeThreshold =
|
|
60
|
-
const includeLcmInThreshold = Boolean(expVal('cc_editor_limited_mode_expanded', 'includeLcmInThreshold', false));
|
|
18
|
+
const shouldEnableLimitedModeForDocument = doc => {
|
|
19
|
+
const nodeCountThreshold = LIMITED_MODE_DEFAULT_NODE_COUNT_THRESHOLD;
|
|
20
|
+
const docSizeThreshold = LIMITED_MODE_DEFAULT_DOC_SIZE_THRESHOLD;
|
|
61
21
|
|
|
62
22
|
// Early exit: doc size exceeds threshold - O(1), no traversal needed
|
|
63
|
-
if (
|
|
23
|
+
if (doc.nodeSize > docSizeThreshold) {
|
|
64
24
|
return true;
|
|
65
25
|
}
|
|
66
26
|
|
|
67
|
-
//
|
|
68
|
-
const needNodeCount = nodeCountThreshold !== undefined;
|
|
69
|
-
if (!needNodeCount && !includeLcmInThreshold) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Single traversal for node count and/or LCM detection
|
|
27
|
+
// Single traversal for node count and LCM detection
|
|
74
28
|
let nodeCount = 0;
|
|
75
29
|
let hasLcm = false;
|
|
76
30
|
doc.descendants(node => {
|
|
77
|
-
var _node$
|
|
31
|
+
var _node$attrs;
|
|
78
32
|
nodeCount += 1;
|
|
79
|
-
if (((_node$
|
|
33
|
+
if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
|
|
80
34
|
hasLcm = true;
|
|
81
35
|
|
|
82
|
-
// Early exit: LCM found
|
|
83
|
-
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
36
|
+
// Early exit: LCM found — limited mode will be enabled
|
|
37
|
+
return false;
|
|
86
38
|
}
|
|
87
39
|
});
|
|
88
40
|
|
|
89
41
|
// LCM condition takes precedence (if we early exited traversal, this is why)
|
|
90
|
-
if (
|
|
42
|
+
if (hasLcm) {
|
|
91
43
|
return true;
|
|
92
44
|
}
|
|
93
45
|
|
|
94
46
|
// Check node count threshold
|
|
95
|
-
if (
|
|
47
|
+
if (nodeCount > nodeCountThreshold) {
|
|
96
48
|
return true;
|
|
97
49
|
}
|
|
98
50
|
return false;
|
|
@@ -104,19 +56,10 @@ export const createPlugin = () => {
|
|
|
104
56
|
return {};
|
|
105
57
|
},
|
|
106
58
|
state: {
|
|
107
|
-
init(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
};
|
|
112
|
-
} else {
|
|
113
|
-
// calculates the size of the doc, where when there are legacy content macros, the content
|
|
114
|
-
// is stored in the attrs.
|
|
115
|
-
const customDocSize = getCustomDocSize(editorState.doc);
|
|
116
|
-
return {
|
|
117
|
-
documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
|
|
118
|
-
};
|
|
119
|
-
}
|
|
59
|
+
init(_config, editorState) {
|
|
60
|
+
return {
|
|
61
|
+
documentSizeBreachesThreshold: shouldEnableLimitedModeForDocument(editorState.doc)
|
|
62
|
+
};
|
|
120
63
|
},
|
|
121
64
|
apply: (tr, currentPluginState, _oldState, _newState) => {
|
|
122
65
|
// Don't check the document size if we're already in limited mode.
|
|
@@ -125,18 +68,9 @@ export const createPlugin = () => {
|
|
|
125
68
|
if (currentPluginState.documentSizeBreachesThreshold && !tr.getMeta('replaceDocument')) {
|
|
126
69
|
return currentPluginState;
|
|
127
70
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
};
|
|
132
|
-
} else {
|
|
133
|
-
// calculates the size of the doc, where when there are legacy content macros, the content
|
|
134
|
-
// is stored in the attrs.
|
|
135
|
-
const customDocSize = getCustomDocSize(tr.doc);
|
|
136
|
-
return {
|
|
137
|
-
documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
|
|
138
|
-
};
|
|
139
|
-
}
|
|
71
|
+
return {
|
|
72
|
+
documentSizeBreachesThreshold: shouldEnableLimitedModeForDocument(tr.doc)
|
|
73
|
+
};
|
|
140
74
|
}
|
|
141
75
|
}
|
|
142
76
|
});
|
|
@@ -1,98 +1,50 @@
|
|
|
1
|
+
import { LIMITED_MODE_DEFAULT_DOC_SIZE_THRESHOLD, LIMITED_MODE_DEFAULT_NODE_COUNT_THRESHOLD } from '@atlaskit/editor-common/limited-mode-document-thresholds';
|
|
1
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
|
|
4
4
|
export var limitedModePluginKey = new PluginKey('limitedModePlugin');
|
|
5
|
-
var LIMITED_MODE_NODE_SIZE_THRESHOLD = 40000;
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
8
|
-
* This guards against test overrides returning booleans or strings for numeric params.
|
|
9
|
-
*/
|
|
10
|
-
var getNumericExperimentParam = function getNumericExperimentParam(paramName, fallbackValue) {
|
|
11
|
-
var rawValue = expVal('cc_editor_limited_mode_expanded', paramName, fallbackValue);
|
|
12
|
-
if (typeof rawValue === 'number') {
|
|
13
|
-
return rawValue;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Handle string values from test overrides
|
|
17
|
-
if (typeof rawValue === 'string') {
|
|
18
|
-
var parsed = parseInt(rawValue, 10);
|
|
19
|
-
if (!isNaN(parsed)) {
|
|
20
|
-
return parsed;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return undefined;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Calculates custom document size including LCM ADF lengths (for non-expanded path).
|
|
28
|
-
* This function can be removed when cc_editor_limited_mode_expanded is cleaned up.
|
|
29
|
-
*/
|
|
30
|
-
var getCustomDocSize = function getCustomDocSize(doc) {
|
|
31
|
-
var lcmAdfLength = 0;
|
|
32
|
-
doc.descendants(function (node) {
|
|
33
|
-
var _node$attrs;
|
|
34
|
-
if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
|
|
35
|
-
var _node$attrs$parameter, _node$attrs2;
|
|
36
|
-
lcmAdfLength += (_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;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return doc.nodeSize + lcmAdfLength;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Determines whether limited mode should be enabled under the expanded gate.
|
|
6
|
+
* Determines whether limited mode should be enabled for a document.
|
|
44
7
|
* If this logic changes, update the duplicate in `editor-common/src/node-anchor/node-anchor-provider.ts` to avoid drift.
|
|
45
8
|
*
|
|
46
9
|
* Limited mode is activated when ANY of the following conditions are met:
|
|
47
|
-
* 1. Document size exceeds `
|
|
48
|
-
* 2. Node count exceeds `
|
|
49
|
-
* 3. Document contains a legacy-content macro (LCM)
|
|
10
|
+
* 1. Document size exceeds `LIMITED_MODE_DEFAULT_DOC_SIZE_THRESHOLD`
|
|
11
|
+
* 2. Node count exceeds `LIMITED_MODE_DEFAULT_NODE_COUNT_THRESHOLD`
|
|
12
|
+
* 3. Document contains a legacy-content macro (LCM)
|
|
50
13
|
*
|
|
51
14
|
* Performance optimisations:
|
|
52
15
|
* - Doc size is checked first (O(1)) - if it exceeds threshold, we skip traversal entirely.
|
|
53
|
-
* - If
|
|
54
|
-
* since we already know limited mode will be enabled.
|
|
55
|
-
* - If neither node count nor LCM conditions are configured, we skip traversal entirely.
|
|
16
|
+
* - If we find an LCM during traversal, we exit early since limited mode will be enabled.
|
|
56
17
|
*/
|
|
57
|
-
var
|
|
58
|
-
var nodeCountThreshold =
|
|
59
|
-
var docSizeThreshold =
|
|
60
|
-
var includeLcmInThreshold = Boolean(expVal('cc_editor_limited_mode_expanded', 'includeLcmInThreshold', false));
|
|
18
|
+
var shouldEnableLimitedModeForDocument = function shouldEnableLimitedModeForDocument(doc) {
|
|
19
|
+
var nodeCountThreshold = LIMITED_MODE_DEFAULT_NODE_COUNT_THRESHOLD;
|
|
20
|
+
var docSizeThreshold = LIMITED_MODE_DEFAULT_DOC_SIZE_THRESHOLD;
|
|
61
21
|
|
|
62
22
|
// Early exit: doc size exceeds threshold - O(1), no traversal needed
|
|
63
|
-
if (
|
|
23
|
+
if (doc.nodeSize > docSizeThreshold) {
|
|
64
24
|
return true;
|
|
65
25
|
}
|
|
66
26
|
|
|
67
|
-
//
|
|
68
|
-
var needNodeCount = nodeCountThreshold !== undefined;
|
|
69
|
-
if (!needNodeCount && !includeLcmInThreshold) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Single traversal for node count and/or LCM detection
|
|
27
|
+
// Single traversal for node count and LCM detection
|
|
74
28
|
var nodeCount = 0;
|
|
75
29
|
var hasLcm = false;
|
|
76
30
|
doc.descendants(function (node) {
|
|
77
|
-
var _node$
|
|
31
|
+
var _node$attrs;
|
|
78
32
|
nodeCount += 1;
|
|
79
|
-
if (((_node$
|
|
33
|
+
if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
|
|
80
34
|
hasLcm = true;
|
|
81
35
|
|
|
82
|
-
// Early exit: LCM found
|
|
83
|
-
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
36
|
+
// Early exit: LCM found — limited mode will be enabled
|
|
37
|
+
return false;
|
|
86
38
|
}
|
|
87
39
|
});
|
|
88
40
|
|
|
89
41
|
// LCM condition takes precedence (if we early exited traversal, this is why)
|
|
90
|
-
if (
|
|
42
|
+
if (hasLcm) {
|
|
91
43
|
return true;
|
|
92
44
|
}
|
|
93
45
|
|
|
94
46
|
// Check node count threshold
|
|
95
|
-
if (
|
|
47
|
+
if (nodeCount > nodeCountThreshold) {
|
|
96
48
|
return true;
|
|
97
49
|
}
|
|
98
50
|
return false;
|
|
@@ -104,19 +56,10 @@ export var createPlugin = function createPlugin() {
|
|
|
104
56
|
return {};
|
|
105
57
|
},
|
|
106
58
|
state: {
|
|
107
|
-
init: function init(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
};
|
|
112
|
-
} else {
|
|
113
|
-
// calculates the size of the doc, where when there are legacy content macros, the content
|
|
114
|
-
// is stored in the attrs.
|
|
115
|
-
var customDocSize = getCustomDocSize(editorState.doc);
|
|
116
|
-
return {
|
|
117
|
-
documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
|
|
118
|
-
};
|
|
119
|
-
}
|
|
59
|
+
init: function init(_config, editorState) {
|
|
60
|
+
return {
|
|
61
|
+
documentSizeBreachesThreshold: shouldEnableLimitedModeForDocument(editorState.doc)
|
|
62
|
+
};
|
|
120
63
|
},
|
|
121
64
|
apply: function apply(tr, currentPluginState, _oldState, _newState) {
|
|
122
65
|
// Don't check the document size if we're already in limited mode.
|
|
@@ -125,18 +68,9 @@ export var createPlugin = function createPlugin() {
|
|
|
125
68
|
if (currentPluginState.documentSizeBreachesThreshold && !tr.getMeta('replaceDocument')) {
|
|
126
69
|
return currentPluginState;
|
|
127
70
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
};
|
|
132
|
-
} else {
|
|
133
|
-
// calculates the size of the doc, where when there are legacy content macros, the content
|
|
134
|
-
// is stored in the attrs.
|
|
135
|
-
var customDocSize = getCustomDocSize(tr.doc);
|
|
136
|
-
return {
|
|
137
|
-
documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
|
|
138
|
-
};
|
|
139
|
-
}
|
|
71
|
+
return {
|
|
72
|
+
documentSizeBreachesThreshold: shouldEnableLimitedModeForDocument(tr.doc)
|
|
73
|
+
};
|
|
140
74
|
}
|
|
141
75
|
}
|
|
142
76
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-limited-mode",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "LimitedMode plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@atlaskit/editor-prosemirror": "^7.3.0",
|
|
32
32
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
33
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
33
|
+
"@atlaskit/tmp-editor-statsig": "^66.0.0",
|
|
34
34
|
"@babel/runtime": "^7.0.0",
|
|
35
35
|
"bind-event-listener": "^3.0.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@atlaskit/editor-common": "^114.
|
|
38
|
+
"@atlaskit/editor-common": "^114.7.0",
|
|
39
39
|
"react": "^18.2.0",
|
|
40
40
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|
|
41
41
|
},
|