@atlaskit/editor-plugin-limited-mode 4.0.1 → 4.0.3

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,22 @@
1
1
  # @atlaskit/editor-plugin-limited-mode
2
2
 
3
+ ## 4.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`256b4fc86bae0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/256b4fc86bae0) -
8
+ [ux] EDITOR-4464 Limited Mode: Change threshold to activate limited mode to use the node count
9
+ rather than the raw document size.
10
+ - Updated dependencies
11
+
12
+ ## 4.0.2
13
+
14
+ ### Patch Changes
15
+
16
+ - [`2c3c92548bb9c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2c3c92548bb9c) -
17
+ EDITOR-4639 cleanup cc_editor_limited_mode, cc_editor_limited_mode_include_lcm and unshipped code.
18
+ - Updated dependencies
19
+
3
20
  ## 4.0.1
4
21
 
5
22
  ### Patch Changes
@@ -24,9 +24,6 @@
24
24
  {
25
25
  "path": "../../../platform/feature-flags/afm-cc/tsconfig.json"
26
26
  },
27
- {
28
- "path": "../../../design-system/primitives/afm-cc/tsconfig.json"
29
- },
30
27
  {
31
28
  "path": "../../tmp-editor-statsig/afm-cc/tsconfig.json"
32
29
  },
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "../../../../tsconfig.entry-points.jira.json",
2
+ "extends": "../../../../tsconfig.local-consumption.json",
3
3
  "compilerOptions": {
4
4
  "target": "es5",
5
5
  "outDir": "../../../../../jira/tsDist/@atlaskit__editor-plugin-limited-mode/app",
@@ -24,9 +24,6 @@
24
24
  {
25
25
  "path": "../../../platform/feature-flags/afm-jira/tsconfig.json"
26
26
  },
27
- {
28
- "path": "../../../design-system/primitives/afm-jira/tsconfig.json"
29
- },
30
27
  {
31
28
  "path": "../../tmp-editor-statsig/afm-jira/tsconfig.json"
32
29
  },
@@ -24,9 +24,6 @@
24
24
  {
25
25
  "path": "../../../platform/feature-flags/afm-products/tsconfig.json"
26
26
  },
27
- {
28
- "path": "../../../design-system/primitives/afm-products/tsconfig.json"
29
- },
30
27
  {
31
28
  "path": "../../tmp-editor-statsig/afm-products/tsconfig.json"
32
29
  },
@@ -1,26 +1,16 @@
1
1
  "use strict";
2
2
 
3
- var _typeof = require("@babel/runtime/helpers/typeof");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.limitedModePlugin = void 0;
8
- var _react = _interopRequireWildcard(require("react"));
9
- var _bindEventListener = require("bind-event-listener");
10
- var _reactIntlNext = require("react-intl-next");
11
- var _messages = require("@atlaskit/editor-common/messages");
12
7
  var _nodeAnchor = require("@atlaskit/editor-common/node-anchor");
13
8
  var _usePluginStateEffect = require("@atlaskit/editor-common/use-plugin-state-effect");
14
9
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
15
- var _compiled = require("@atlaskit/primitives/compiled");
16
10
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
17
- var _expVal = require("@atlaskit/tmp-editor-statsig/expVal");
18
11
  var _main = require("./pm-plugins/main");
19
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
20
12
  var limitedModePlugin = exports.limitedModePlugin = function limitedModePlugin(_ref) {
21
- var _ref$config = _ref.config,
22
- options = _ref$config === void 0 ? {} : _ref$config,
23
- api = _ref.api;
13
+ var api = _ref.api;
24
14
  return {
25
15
  name: 'limitedMode',
26
16
  pmPlugins: function pmPlugins() {
@@ -46,76 +36,17 @@ var limitedModePlugin = exports.limitedModePlugin = function limitedModePlugin(_
46
36
  },
47
37
  usePluginHook: function usePluginHook(_ref2) {
48
38
  var editorView = _ref2.editorView;
49
- var hasEditorBeenFocusedRef = (0, _react.useRef)(false);
50
- var hasShownFlagRef = (0, _react.useRef)(false);
51
- var _useIntl = (0, _reactIntlNext.useIntl)(),
52
- formatMessage = _useIntl.formatMessage;
53
-
54
- // Reset hasEditorBeenFocusedRef so live-to-live page navigation refreshes the flag. We rely on the page's contentId for this.
55
- (0, _react.useEffect)(function () {
56
- hasShownFlagRef.current = false;
57
- // eslint-disable-next-line react-hooks/exhaustive-deps
58
- }, [options.contentId]);
59
- var checkAndShowFlag = (0, _react.useCallback)(function (isLimitedModeEnabled) {
60
- // @ts-expect-error - true is not allowed as a default value
61
- if (!((0, _expVal.expVal)('cc_editor_limited_mode', 'flagEnabled', true) === true)) {
62
- // Disable the flag behavior entirely if the flag is off
63
- return;
64
- }
65
- var _learnMoreLink = (0, _expVal.expVal)('cc_editor_limited_mode', 'learnMoreLink', '');
66
- if (isLimitedModeEnabled && hasEditorBeenFocusedRef.current && !hasShownFlagRef.current) {
67
- var _options$showFlag;
68
- void ((_options$showFlag = options.showFlag) === null || _options$showFlag === void 0 ? void 0 : _options$showFlag.call(options, {
69
- title: formatMessage(_messages.limitedModeMessages.limitedModeTitle),
70
- description: _learnMoreLink ? formatMessage(_messages.limitedModeMessages.limitedModeDescriptionWithLink, {
71
- learnMoreLink: function learnMoreLink(chunks) {
72
- return /*#__PURE__*/_react.default.createElement(_compiled.Anchor, {
73
- target: "_blank",
74
- href: _learnMoreLink
75
- }, chunks);
76
- }
77
- }) : formatMessage(_messages.limitedModeMessages.limitedModeDescriptionWithoutLink),
78
- close: 'auto'
79
- }));
80
- hasShownFlagRef.current = true;
81
- }
82
- }, [formatMessage]);
83
-
84
- // Track if the editor has been focused. On focus, check if the flag should be shown.
85
- (0, _react.useEffect)(function () {
86
- var handleFocus = function handleFocus() {
87
- var _api$limitedMode$shar, _api$limitedMode;
88
- hasEditorBeenFocusedRef.current = true;
89
- // Get current state when focus happens
90
- var isLimitedModeEnabled = (_api$limitedMode$shar = api === null || api === void 0 || (_api$limitedMode = api.limitedMode) === null || _api$limitedMode === void 0 || (_api$limitedMode = _api$limitedMode.sharedState.currentState()) === null || _api$limitedMode === void 0 ? void 0 : _api$limitedMode.enabled) !== null && _api$limitedMode$shar !== void 0 ? _api$limitedMode$shar : false;
91
- checkAndShowFlag(isLimitedModeEnabled);
92
- };
93
- var unbind = (0, _bindEventListener.bind)(editorView.dom, {
94
- type: 'focus',
95
- listener: handleFocus
96
- });
97
- return function () {
98
- unbind();
99
- };
100
- }, [editorView, checkAndShowFlag]);
101
-
102
- // On change of the limited mode enabled state, check if the flag should be shown.
103
39
  (0, _usePluginStateEffect.usePluginStateEffect)(api, ['limitedMode'], function (_ref3) {
104
- var _limitedModeState$ena;
105
40
  var limitedModeState = _ref3.limitedModeState;
106
- var isLimitedModeEnabled = (_limitedModeState$ena = limitedModeState === null || limitedModeState === void 0 ? void 0 : limitedModeState.enabled) !== null && _limitedModeState$ena !== void 0 ? _limitedModeState$ena : false;
107
- checkAndShowFlag(isLimitedModeEnabled);
108
- });
109
- (0, _usePluginStateEffect.usePluginStateEffect)(api, ['limitedMode'], function (_ref4) {
110
- var limitedModeState = _ref4.limitedModeState;
111
41
  if ((0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true)) {
112
42
  if ((0, _platformFeatureFlags.fg)('platform_editor_native_anchor_patch_2')) {
113
- var _limitedModeState$ena2;
114
- var isEnabled = (_limitedModeState$ena2 = limitedModeState === null || limitedModeState === void 0 ? void 0 : limitedModeState.enabled) !== null && _limitedModeState$ena2 !== void 0 ? _limitedModeState$ena2 : false;
43
+ var _limitedModeState$ena;
44
+ var isEnabled = (_limitedModeState$ena = limitedModeState === null || limitedModeState === void 0 ? void 0 : limitedModeState.enabled) !== null && _limitedModeState$ena !== void 0 ? _limitedModeState$ena : false;
115
45
  var nodeIdProvider = (0, _nodeAnchor.getNodeIdProvider)(editorView);
116
46
  // When limited mode is enabled first time,
117
47
  // We need to remove all existing data-node-anchor attributes
118
48
  // And nodeIdProvider to limited mode to prevent adding data-node-anchor on new nodes
49
+
119
50
  if (isEnabled && nodeIdProvider && !nodeIdProvider.isLimitedMode()) {
120
51
  nodeIdProvider.setLimitedMode();
121
52
  }
@@ -1,17 +1,46 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.limitedModePluginKey = exports.createPlugin = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
7
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
8
  var _state = require("@atlaskit/editor-prosemirror/state");
11
9
  var _expVal = require("@atlaskit/tmp-editor-statsig/expVal");
12
- 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; }
13
- 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; }
14
10
  var limitedModePluginKey = exports.limitedModePluginKey = new _state.PluginKey('limitedModePlugin');
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
+ };
15
44
  var createPlugin = exports.createPlugin = function createPlugin() {
16
45
  return new _safePlugin.SafePlugin({
17
46
  key: limitedModePluginKey,
@@ -20,65 +49,59 @@ var createPlugin = exports.createPlugin = function createPlugin() {
20
49
  },
21
50
  state: {
22
51
  init: function init(config, editorState) {
23
- // @ts-expect-error - true is not allowed as a default value
24
- if ((0, _expVal.expVal)('cc_editor_limited_mode_include_lcm', 'isEnabled', true)) {
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 {
25
60
  // calculates the size of the doc, where when there are legacy content macros, the content
26
61
  // is stored in the attrs.
27
62
  // This is essentiall doc.nod
28
63
  var customDocSize = editorState.doc.nodeSize;
29
64
  editorState.doc.descendants(function (node) {
30
- var _node$attrs;
31
- if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
32
- var _node$attrs$parameter, _node$attrs2;
33
- 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;
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;
34
69
  }
35
70
  });
36
71
  return {
37
- documentSizeBreachesThreshold: customDocSize > (0, _expVal.expVal)('cc_editor_limited_mode', 'nodeSize', 100)
38
- };
39
- } else {
40
- if (editorState.doc.nodeSize > (0, _expVal.expVal)('cc_editor_limited_mode', 'nodeSize', 100)) {
41
- return {
42
- documentSizeBreachesThreshold: true
43
- };
44
- }
45
- return {
46
- documentSizeBreachesThreshold: false
72
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
47
73
  };
48
74
  }
49
75
  },
50
- apply: function apply(tr, currentPluginState) {
76
+ apply: function apply(tr, currentPluginState, _oldState, _newState) {
51
77
  // Don't check the document size if we're already in limited mode.
52
78
  // We ALWAYS want to re-check the document size if we're replacing the document (e.g. live-to-live page navigation).
79
+
53
80
  if (currentPluginState.documentSizeBreachesThreshold && !tr.getMeta('replaceDocument')) {
54
81
  return currentPluginState;
55
82
  }
56
-
57
- // @ts-expect-error - true is not allowed as a default value
58
- if ((0, _expVal.expVal)('cc_editor_limited_mode_include_lcm', 'isEnabled', true)) {
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 {
59
91
  // calculates the size of the doc, where when there are legacy content macros, the content
60
92
  // is stored in the attrs.
61
93
  // This is essentiall doc.nod
62
94
  var customDocSize = tr.doc.nodeSize;
63
95
  tr.doc.descendants(function (node) {
64
- var _node$attrs3;
65
- if (((_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.extensionKey) === 'legacy-content') {
66
- var _node$attrs$parameter2, _node$attrs4;
67
- 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;
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;
68
100
  }
69
101
  });
70
102
  return {
71
- documentSizeBreachesThreshold: customDocSize > (0, _expVal.expVal)('cc_editor_limited_mode', 'nodeSize', 100)
103
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
72
104
  };
73
- } else {
74
- if (tr.doc.nodeSize > (0, _expVal.expVal)('cc_editor_limited_mode', 'nodeSize', 100)) {
75
- return _objectSpread(_objectSpread({}, currentPluginState), {}, {
76
- documentSizeBreachesThreshold: true
77
- });
78
- }
79
- return _objectSpread(_objectSpread({}, currentPluginState), {}, {
80
- documentSizeBreachesThreshold: false
81
- });
82
105
  }
83
106
  }
84
107
  }
@@ -1,16 +1,9 @@
1
- import React, { useCallback, useEffect, useRef } from 'react';
2
- import { bind } from 'bind-event-listener';
3
- import { useIntl } from 'react-intl-next';
4
- import { limitedModeMessages } from '@atlaskit/editor-common/messages';
5
1
  import { getNodeIdProvider } from '@atlaskit/editor-common/node-anchor';
6
2
  import { usePluginStateEffect } from '@atlaskit/editor-common/use-plugin-state-effect';
7
3
  import { fg } from '@atlaskit/platform-feature-flags';
8
- import { Anchor } from '@atlaskit/primitives/compiled';
9
4
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
10
- import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
11
5
  import { createPlugin, limitedModePluginKey } from './pm-plugins/main';
12
6
  export const limitedModePlugin = ({
13
- config: options = {},
14
7
  api
15
8
  }) => {
16
9
  return {
@@ -39,77 +32,18 @@ export const limitedModePlugin = ({
39
32
  usePluginHook: ({
40
33
  editorView
41
34
  }) => {
42
- const hasEditorBeenFocusedRef = useRef(false);
43
- const hasShownFlagRef = useRef(false);
44
- const {
45
- formatMessage
46
- } = useIntl();
47
-
48
- // Reset hasEditorBeenFocusedRef so live-to-live page navigation refreshes the flag. We rely on the page's contentId for this.
49
- useEffect(() => {
50
- hasShownFlagRef.current = false;
51
- // eslint-disable-next-line react-hooks/exhaustive-deps
52
- }, [options.contentId]);
53
- const checkAndShowFlag = useCallback(isLimitedModeEnabled => {
54
- // @ts-expect-error - true is not allowed as a default value
55
- if (!(expVal('cc_editor_limited_mode', 'flagEnabled', true) === true)) {
56
- // Disable the flag behavior entirely if the flag is off
57
- return;
58
- }
59
- const learnMoreLink = expVal('cc_editor_limited_mode', 'learnMoreLink', '');
60
- if (isLimitedModeEnabled && hasEditorBeenFocusedRef.current && !hasShownFlagRef.current) {
61
- var _options$showFlag;
62
- void ((_options$showFlag = options.showFlag) === null || _options$showFlag === void 0 ? void 0 : _options$showFlag.call(options, {
63
- title: formatMessage(limitedModeMessages.limitedModeTitle),
64
- description: learnMoreLink ? formatMessage(limitedModeMessages.limitedModeDescriptionWithLink, {
65
- learnMoreLink: chunks => /*#__PURE__*/React.createElement(Anchor, {
66
- target: "_blank",
67
- href: learnMoreLink
68
- }, chunks)
69
- }) : formatMessage(limitedModeMessages.limitedModeDescriptionWithoutLink),
70
- close: 'auto'
71
- }));
72
- hasShownFlagRef.current = true;
73
- }
74
- }, [formatMessage]);
75
-
76
- // Track if the editor has been focused. On focus, check if the flag should be shown.
77
- useEffect(() => {
78
- const handleFocus = () => {
79
- var _api$limitedMode$shar, _api$limitedMode, _api$limitedMode$shar2;
80
- hasEditorBeenFocusedRef.current = true;
81
- // Get current state when focus happens
82
- const isLimitedModeEnabled = (_api$limitedMode$shar = api === null || api === void 0 ? void 0 : (_api$limitedMode = api.limitedMode) === null || _api$limitedMode === void 0 ? void 0 : (_api$limitedMode$shar2 = _api$limitedMode.sharedState.currentState()) === null || _api$limitedMode$shar2 === void 0 ? void 0 : _api$limitedMode$shar2.enabled) !== null && _api$limitedMode$shar !== void 0 ? _api$limitedMode$shar : false;
83
- checkAndShowFlag(isLimitedModeEnabled);
84
- };
85
- const unbind = bind(editorView.dom, {
86
- type: 'focus',
87
- listener: handleFocus
88
- });
89
- return () => {
90
- unbind();
91
- };
92
- }, [editorView, checkAndShowFlag]);
93
-
94
- // On change of the limited mode enabled state, check if the flag should be shown.
95
- usePluginStateEffect(api, ['limitedMode'], ({
96
- limitedModeState
97
- }) => {
98
- var _limitedModeState$ena;
99
- const isLimitedModeEnabled = (_limitedModeState$ena = limitedModeState === null || limitedModeState === void 0 ? void 0 : limitedModeState.enabled) !== null && _limitedModeState$ena !== void 0 ? _limitedModeState$ena : false;
100
- checkAndShowFlag(isLimitedModeEnabled);
101
- });
102
35
  usePluginStateEffect(api, ['limitedMode'], ({
103
36
  limitedModeState
104
37
  }) => {
105
38
  if (expValEquals('platform_editor_native_anchor_with_dnd', 'isEnabled', true)) {
106
39
  if (fg('platform_editor_native_anchor_patch_2')) {
107
- var _limitedModeState$ena2;
108
- const isEnabled = (_limitedModeState$ena2 = limitedModeState === null || limitedModeState === void 0 ? void 0 : limitedModeState.enabled) !== null && _limitedModeState$ena2 !== void 0 ? _limitedModeState$ena2 : false;
40
+ var _limitedModeState$ena;
41
+ const isEnabled = (_limitedModeState$ena = limitedModeState === null || limitedModeState === void 0 ? void 0 : limitedModeState.enabled) !== null && _limitedModeState$ena !== void 0 ? _limitedModeState$ena : false;
109
42
  const nodeIdProvider = getNodeIdProvider(editorView);
110
43
  // When limited mode is enabled first time,
111
44
  // We need to remove all existing data-node-anchor attributes
112
45
  // And nodeIdProvider to limited mode to prevent adding data-node-anchor on new nodes
46
+
113
47
  if (isEnabled && nodeIdProvider && !nodeIdProvider.isLimitedMode()) {
114
48
  nodeIdProvider.setLimitedMode();
115
49
  }
@@ -2,6 +2,39 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
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
+ /**
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,66 +43,58 @@ export const createPlugin = () => {
10
43
  },
11
44
  state: {
12
45
  init(config, editorState) {
13
- // @ts-expect-error - true is not allowed as a default value
14
- if (expVal('cc_editor_limited_mode_include_lcm', 'isEnabled', true)) {
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 {
15
54
  // calculates the size of the doc, where when there are legacy content macros, the content
16
55
  // is stored in the attrs.
17
56
  // This is essentiall doc.nod
18
57
  let customDocSize = editorState.doc.nodeSize;
19
58
  editorState.doc.descendants(node => {
20
- var _node$attrs;
21
- if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
22
- var _node$attrs$parameter, _node$attrs2, _node$attrs2$paramete, _node$attrs2$paramete2;
23
- 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;
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;
24
63
  }
25
64
  });
26
65
  return {
27
- documentSizeBreachesThreshold: customDocSize > expVal('cc_editor_limited_mode', 'nodeSize', 100)
28
- };
29
- } else {
30
- if (editorState.doc.nodeSize > expVal('cc_editor_limited_mode', 'nodeSize', 100)) {
31
- return {
32
- documentSizeBreachesThreshold: true
33
- };
34
- }
35
- return {
36
- documentSizeBreachesThreshold: false
66
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
37
67
  };
38
68
  }
39
69
  },
40
- apply: (tr, currentPluginState) => {
70
+ apply: (tr, currentPluginState, _oldState, _newState) => {
41
71
  // Don't check the document size if we're already in limited mode.
42
72
  // We ALWAYS want to re-check the document size if we're replacing the document (e.g. live-to-live page navigation).
73
+
43
74
  if (currentPluginState.documentSizeBreachesThreshold && !tr.getMeta('replaceDocument')) {
44
75
  return currentPluginState;
45
76
  }
46
-
47
- // @ts-expect-error - true is not allowed as a default value
48
- if (expVal('cc_editor_limited_mode_include_lcm', 'isEnabled', true)) {
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 {
49
85
  // calculates the size of the doc, where when there are legacy content macros, the content
50
86
  // is stored in the attrs.
51
87
  // This is essentiall doc.nod
52
88
  let customDocSize = tr.doc.nodeSize;
53
89
  tr.doc.descendants(node => {
54
- var _node$attrs3;
55
- if (((_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.extensionKey) === 'legacy-content') {
56
- var _node$attrs$parameter2, _node$attrs4, _node$attrs4$paramete, _node$attrs4$paramete2;
57
- 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;
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;
58
94
  }
59
95
  });
60
96
  return {
61
- documentSizeBreachesThreshold: customDocSize > expVal('cc_editor_limited_mode', 'nodeSize', 100)
62
- };
63
- } else {
64
- if (tr.doc.nodeSize > expVal('cc_editor_limited_mode', 'nodeSize', 100)) {
65
- return {
66
- ...currentPluginState,
67
- documentSizeBreachesThreshold: true
68
- };
69
- }
70
- return {
71
- ...currentPluginState,
72
- documentSizeBreachesThreshold: false
97
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
73
98
  };
74
99
  }
75
100
  }
@@ -1,18 +1,10 @@
1
- import React, { useCallback, useEffect, useRef } from 'react';
2
- import { bind } from 'bind-event-listener';
3
- import { useIntl } from 'react-intl-next';
4
- import { limitedModeMessages } from '@atlaskit/editor-common/messages';
5
1
  import { getNodeIdProvider } from '@atlaskit/editor-common/node-anchor';
6
2
  import { usePluginStateEffect } from '@atlaskit/editor-common/use-plugin-state-effect';
7
3
  import { fg } from '@atlaskit/platform-feature-flags';
8
- import { Anchor } from '@atlaskit/primitives/compiled';
9
4
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
10
- import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
11
5
  import { createPlugin, limitedModePluginKey } from './pm-plugins/main';
12
6
  export var limitedModePlugin = function limitedModePlugin(_ref) {
13
- var _ref$config = _ref.config,
14
- options = _ref$config === void 0 ? {} : _ref$config,
15
- api = _ref.api;
7
+ var api = _ref.api;
16
8
  return {
17
9
  name: 'limitedMode',
18
10
  pmPlugins: function pmPlugins() {
@@ -38,76 +30,17 @@ export var limitedModePlugin = function limitedModePlugin(_ref) {
38
30
  },
39
31
  usePluginHook: function usePluginHook(_ref2) {
40
32
  var editorView = _ref2.editorView;
41
- var hasEditorBeenFocusedRef = useRef(false);
42
- var hasShownFlagRef = useRef(false);
43
- var _useIntl = useIntl(),
44
- formatMessage = _useIntl.formatMessage;
45
-
46
- // Reset hasEditorBeenFocusedRef so live-to-live page navigation refreshes the flag. We rely on the page's contentId for this.
47
- useEffect(function () {
48
- hasShownFlagRef.current = false;
49
- // eslint-disable-next-line react-hooks/exhaustive-deps
50
- }, [options.contentId]);
51
- var checkAndShowFlag = useCallback(function (isLimitedModeEnabled) {
52
- // @ts-expect-error - true is not allowed as a default value
53
- if (!(expVal('cc_editor_limited_mode', 'flagEnabled', true) === true)) {
54
- // Disable the flag behavior entirely if the flag is off
55
- return;
56
- }
57
- var _learnMoreLink = expVal('cc_editor_limited_mode', 'learnMoreLink', '');
58
- if (isLimitedModeEnabled && hasEditorBeenFocusedRef.current && !hasShownFlagRef.current) {
59
- var _options$showFlag;
60
- void ((_options$showFlag = options.showFlag) === null || _options$showFlag === void 0 ? void 0 : _options$showFlag.call(options, {
61
- title: formatMessage(limitedModeMessages.limitedModeTitle),
62
- description: _learnMoreLink ? formatMessage(limitedModeMessages.limitedModeDescriptionWithLink, {
63
- learnMoreLink: function learnMoreLink(chunks) {
64
- return /*#__PURE__*/React.createElement(Anchor, {
65
- target: "_blank",
66
- href: _learnMoreLink
67
- }, chunks);
68
- }
69
- }) : formatMessage(limitedModeMessages.limitedModeDescriptionWithoutLink),
70
- close: 'auto'
71
- }));
72
- hasShownFlagRef.current = true;
73
- }
74
- }, [formatMessage]);
75
-
76
- // Track if the editor has been focused. On focus, check if the flag should be shown.
77
- useEffect(function () {
78
- var handleFocus = function handleFocus() {
79
- var _api$limitedMode$shar, _api$limitedMode;
80
- hasEditorBeenFocusedRef.current = true;
81
- // Get current state when focus happens
82
- var isLimitedModeEnabled = (_api$limitedMode$shar = api === null || api === void 0 || (_api$limitedMode = api.limitedMode) === null || _api$limitedMode === void 0 || (_api$limitedMode = _api$limitedMode.sharedState.currentState()) === null || _api$limitedMode === void 0 ? void 0 : _api$limitedMode.enabled) !== null && _api$limitedMode$shar !== void 0 ? _api$limitedMode$shar : false;
83
- checkAndShowFlag(isLimitedModeEnabled);
84
- };
85
- var unbind = bind(editorView.dom, {
86
- type: 'focus',
87
- listener: handleFocus
88
- });
89
- return function () {
90
- unbind();
91
- };
92
- }, [editorView, checkAndShowFlag]);
93
-
94
- // On change of the limited mode enabled state, check if the flag should be shown.
95
33
  usePluginStateEffect(api, ['limitedMode'], function (_ref3) {
96
- var _limitedModeState$ena;
97
34
  var limitedModeState = _ref3.limitedModeState;
98
- var isLimitedModeEnabled = (_limitedModeState$ena = limitedModeState === null || limitedModeState === void 0 ? void 0 : limitedModeState.enabled) !== null && _limitedModeState$ena !== void 0 ? _limitedModeState$ena : false;
99
- checkAndShowFlag(isLimitedModeEnabled);
100
- });
101
- usePluginStateEffect(api, ['limitedMode'], function (_ref4) {
102
- var limitedModeState = _ref4.limitedModeState;
103
35
  if (expValEquals('platform_editor_native_anchor_with_dnd', 'isEnabled', true)) {
104
36
  if (fg('platform_editor_native_anchor_patch_2')) {
105
- var _limitedModeState$ena2;
106
- var isEnabled = (_limitedModeState$ena2 = limitedModeState === null || limitedModeState === void 0 ? void 0 : limitedModeState.enabled) !== null && _limitedModeState$ena2 !== void 0 ? _limitedModeState$ena2 : false;
37
+ var _limitedModeState$ena;
38
+ var isEnabled = (_limitedModeState$ena = limitedModeState === null || limitedModeState === void 0 ? void 0 : limitedModeState.enabled) !== null && _limitedModeState$ena !== void 0 ? _limitedModeState$ena : false;
107
39
  var nodeIdProvider = getNodeIdProvider(editorView);
108
40
  // When limited mode is enabled first time,
109
41
  // We need to remove all existing data-node-anchor attributes
110
42
  // And nodeIdProvider to limited mode to prevent adding data-node-anchor on new nodes
43
+
111
44
  if (isEnabled && nodeIdProvider && !nodeIdProvider.isLimitedMode()) {
112
45
  nodeIdProvider.setLimitedMode();
113
46
  }
@@ -1,10 +1,40 @@
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
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
3
  import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
7
4
  export var limitedModePluginKey = new PluginKey('limitedModePlugin');
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
+ };
8
38
  export var createPlugin = function createPlugin() {
9
39
  return new SafePlugin({
10
40
  key: limitedModePluginKey,
@@ -13,65 +43,59 @@ export var createPlugin = function createPlugin() {
13
43
  },
14
44
  state: {
15
45
  init: function init(config, editorState) {
16
- // @ts-expect-error - true is not allowed as a default value
17
- if (expVal('cc_editor_limited_mode_include_lcm', 'isEnabled', true)) {
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 {
18
54
  // calculates the size of the doc, where when there are legacy content macros, the content
19
55
  // is stored in the attrs.
20
56
  // This is essentiall doc.nod
21
57
  var customDocSize = editorState.doc.nodeSize;
22
58
  editorState.doc.descendants(function (node) {
23
- var _node$attrs;
24
- if (((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.extensionKey) === 'legacy-content') {
25
- var _node$attrs$parameter, _node$attrs2;
26
- 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;
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;
27
63
  }
28
64
  });
29
65
  return {
30
- documentSizeBreachesThreshold: customDocSize > expVal('cc_editor_limited_mode', 'nodeSize', 100)
31
- };
32
- } else {
33
- if (editorState.doc.nodeSize > expVal('cc_editor_limited_mode', 'nodeSize', 100)) {
34
- return {
35
- documentSizeBreachesThreshold: true
36
- };
37
- }
38
- return {
39
- documentSizeBreachesThreshold: false
66
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
40
67
  };
41
68
  }
42
69
  },
43
- apply: function apply(tr, currentPluginState) {
70
+ apply: function apply(tr, currentPluginState, _oldState, _newState) {
44
71
  // Don't check the document size if we're already in limited mode.
45
72
  // We ALWAYS want to re-check the document size if we're replacing the document (e.g. live-to-live page navigation).
73
+
46
74
  if (currentPluginState.documentSizeBreachesThreshold && !tr.getMeta('replaceDocument')) {
47
75
  return currentPluginState;
48
76
  }
49
-
50
- // @ts-expect-error - true is not allowed as a default value
51
- if (expVal('cc_editor_limited_mode_include_lcm', 'isEnabled', true)) {
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 {
52
85
  // calculates the size of the doc, where when there are legacy content macros, the content
53
86
  // is stored in the attrs.
54
87
  // This is essentiall doc.nod
55
88
  var customDocSize = tr.doc.nodeSize;
56
89
  tr.doc.descendants(function (node) {
57
- var _node$attrs3;
58
- if (((_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.extensionKey) === 'legacy-content') {
59
- var _node$attrs$parameter2, _node$attrs4;
60
- 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;
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;
61
94
  }
62
95
  });
63
96
  return {
64
- documentSizeBreachesThreshold: customDocSize > expVal('cc_editor_limited_mode', 'nodeSize', 100)
97
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
65
98
  };
66
- } else {
67
- if (tr.doc.nodeSize > expVal('cc_editor_limited_mode', 'nodeSize', 100)) {
68
- return _objectSpread(_objectSpread({}, currentPluginState), {}, {
69
- documentSizeBreachesThreshold: true
70
- });
71
- }
72
- return _objectSpread(_objectSpread({}, currentPluginState), {}, {
73
- documentSizeBreachesThreshold: false
74
- });
75
99
  }
76
100
  }
77
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-limited-mode",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "LimitedMode plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -30,14 +30,13 @@
30
30
  "dependencies": {
31
31
  "@atlaskit/editor-prosemirror": "^7.2.0",
32
32
  "@atlaskit/platform-feature-flags": "^1.1.0",
33
- "@atlaskit/primitives": "^17.1.0",
34
- "@atlaskit/tmp-editor-statsig": "^16.26.0",
33
+ "@atlaskit/tmp-editor-statsig": "^17.0.0",
35
34
  "@babel/runtime": "^7.0.0",
36
35
  "bind-event-listener": "^3.0.0",
37
36
  "react-intl-next": "npm:react-intl@^5.18.1"
38
37
  },
39
38
  "peerDependencies": {
40
- "@atlaskit/editor-common": "^111.8.0",
39
+ "@atlaskit/editor-common": "^111.9.0",
41
40
  "react": "^18.2.0"
42
41
  },
43
42
  "devDependencies": {