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

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,13 @@
1
1
  # @atlaskit/editor-plugin-limited-mode
2
2
 
3
+ ## 4.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`2c3c92548bb9c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2c3c92548bb9c) -
8
+ EDITOR-4639 cleanup cc_editor_limited_mode, cc_editor_limited_mode_include_lcm and unshipped code.
9
+ - Updated dependencies
10
+
3
11
  ## 4.0.1
4
12
 
5
13
  ### 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,13 @@
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
- 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
9
  var limitedModePluginKey = exports.limitedModePluginKey = new _state.PluginKey('limitedModePlugin');
10
+ var LIMITED_MODE_NODE_SIZE_THRESHOLD = 40000;
15
11
  var createPlugin = exports.createPlugin = function createPlugin() {
16
12
  return new _safePlugin.SafePlugin({
17
13
  key: limitedModePluginKey,
@@ -20,32 +16,20 @@ var createPlugin = exports.createPlugin = function createPlugin() {
20
16
  },
21
17
  state: {
22
18
  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)) {
25
- // calculates the size of the doc, where when there are legacy content macros, the content
26
- // is stored in the attrs.
27
- // This is essentiall doc.nod
28
- var customDocSize = editorState.doc.nodeSize;
29
- 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;
34
- }
35
- });
36
- 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
- };
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;
44
28
  }
45
- return {
46
- documentSizeBreachesThreshold: false
47
- };
48
- }
29
+ });
30
+ return {
31
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
32
+ };
49
33
  },
50
34
  apply: function apply(tr, currentPluginState) {
51
35
  // Don't check the document size if we're already in limited mode.
@@ -54,32 +38,20 @@ var createPlugin = exports.createPlugin = function createPlugin() {
54
38
  return currentPluginState;
55
39
  }
56
40
 
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)) {
59
- // calculates the size of the doc, where when there are legacy content macros, the content
60
- // is stored in the attrs.
61
- // This is essentiall doc.nod
62
- var customDocSize = tr.doc.nodeSize;
63
- 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;
68
- }
69
- });
70
- return {
71
- documentSizeBreachesThreshold: customDocSize > (0, _expVal.expVal)('cc_editor_limited_mode', 'nodeSize', 100)
72
- };
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
- });
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;
78
50
  }
79
- return _objectSpread(_objectSpread({}, currentPluginState), {}, {
80
- documentSizeBreachesThreshold: false
81
- });
82
- }
51
+ });
52
+ return {
53
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
54
+ };
83
55
  }
84
56
  }
85
57
  });
@@ -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
  }
@@ -1,7 +1,7 @@
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';
4
3
  export const limitedModePluginKey = new PluginKey('limitedModePlugin');
4
+ const LIMITED_MODE_NODE_SIZE_THRESHOLD = 40000;
5
5
  export const createPlugin = () => {
6
6
  return new SafePlugin({
7
7
  key: limitedModePluginKey,
@@ -10,32 +10,20 @@ export const createPlugin = () => {
10
10
  },
11
11
  state: {
12
12
  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)) {
15
- // calculates the size of the doc, where when there are legacy content macros, the content
16
- // is stored in the attrs.
17
- // This is essentiall doc.nod
18
- let customDocSize = editorState.doc.nodeSize;
19
- 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;
24
- }
25
- });
26
- 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
- };
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;
34
22
  }
35
- return {
36
- documentSizeBreachesThreshold: false
37
- };
38
- }
23
+ });
24
+ return {
25
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
26
+ };
39
27
  },
40
28
  apply: (tr, currentPluginState) => {
41
29
  // Don't check the document size if we're already in limited mode.
@@ -44,34 +32,20 @@ export const createPlugin = () => {
44
32
  return currentPluginState;
45
33
  }
46
34
 
47
- // @ts-expect-error - true is not allowed as a default value
48
- if (expVal('cc_editor_limited_mode_include_lcm', 'isEnabled', true)) {
49
- // calculates the size of the doc, where when there are legacy content macros, the content
50
- // is stored in the attrs.
51
- // This is essentiall doc.nod
52
- let customDocSize = tr.doc.nodeSize;
53
- 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;
58
- }
59
- });
60
- 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
- };
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;
69
44
  }
70
- return {
71
- ...currentPluginState,
72
- documentSizeBreachesThreshold: false
73
- };
74
- }
45
+ });
46
+ return {
47
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
48
+ };
75
49
  }
76
50
  }
77
51
  });
@@ -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,7 @@
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
- import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
7
3
  export var limitedModePluginKey = new PluginKey('limitedModePlugin');
4
+ var LIMITED_MODE_NODE_SIZE_THRESHOLD = 40000;
8
5
  export var createPlugin = function createPlugin() {
9
6
  return new SafePlugin({
10
7
  key: limitedModePluginKey,
@@ -13,32 +10,20 @@ export var createPlugin = function createPlugin() {
13
10
  },
14
11
  state: {
15
12
  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)) {
18
- // calculates the size of the doc, where when there are legacy content macros, the content
19
- // is stored in the attrs.
20
- // This is essentiall doc.nod
21
- var customDocSize = editorState.doc.nodeSize;
22
- 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;
27
- }
28
- });
29
- 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
- };
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;
37
22
  }
38
- return {
39
- documentSizeBreachesThreshold: false
40
- };
41
- }
23
+ });
24
+ return {
25
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
26
+ };
42
27
  },
43
28
  apply: function apply(tr, currentPluginState) {
44
29
  // Don't check the document size if we're already in limited mode.
@@ -47,32 +32,20 @@ export var createPlugin = function createPlugin() {
47
32
  return currentPluginState;
48
33
  }
49
34
 
50
- // @ts-expect-error - true is not allowed as a default value
51
- if (expVal('cc_editor_limited_mode_include_lcm', 'isEnabled', true)) {
52
- // calculates the size of the doc, where when there are legacy content macros, the content
53
- // is stored in the attrs.
54
- // This is essentiall doc.nod
55
- var customDocSize = tr.doc.nodeSize;
56
- 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;
61
- }
62
- });
63
- return {
64
- documentSizeBreachesThreshold: customDocSize > expVal('cc_editor_limited_mode', 'nodeSize', 100)
65
- };
66
- } else {
67
- if (tr.doc.nodeSize > expVal('cc_editor_limited_mode', 'nodeSize', 100)) {
68
- return _objectSpread(_objectSpread({}, currentPluginState), {}, {
69
- documentSizeBreachesThreshold: true
70
- });
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;
71
44
  }
72
- return _objectSpread(_objectSpread({}, currentPluginState), {}, {
73
- documentSizeBreachesThreshold: false
74
- });
75
- }
45
+ });
46
+ return {
47
+ documentSizeBreachesThreshold: customDocSize > LIMITED_MODE_NODE_SIZE_THRESHOLD
48
+ };
76
49
  }
77
50
  }
78
51
  });
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.2",
4
4
  "description": "LimitedMode plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -30,8 +30,7 @@
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": "^16.29.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"