@atlaskit/editor-plugin-limited-mode 0.0.2 → 0.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,14 @@
1
1
  # @atlaskit/editor-plugin-limited-mode
2
2
 
3
+ ## 0.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`e33be5daddd2b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e33be5daddd2b) -
8
+ ED-28892 Limited mode: adjust how we're triggering cleanup logic for block control plugin. Hook up
9
+ banner. Other misc setup.
10
+ - Updated dependencies
11
+
3
12
  ## 0.0.2
4
13
 
5
14
  ### Patch Changes
@@ -1,38 +1,26 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.limitedModePluginKey = exports.createPlugin = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
7
9
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
10
  var _state = require("@atlaskit/editor-prosemirror/state");
9
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; }
10
14
  var limitedModePluginKey = exports.limitedModePluginKey = new _state.PluginKey('limitedModePlugin');
11
15
  var createPlugin = exports.createPlugin = function createPlugin() {
12
- var _view2;
13
- var stateUpdated = false;
14
- function updateState(view) {
15
- var newState = _state.EditorState.create({
16
- schema: view.state.schema,
17
- doc: view.state.doc,
18
- // remove the state plugin to trigger the view cleanup function
19
- // @ts-ignore This plugin interaction is expected to be temporary - we can't pass the key via standard inter plugin communication as that would introduce cyclical dependencies
20
- plugins: view.state.plugins.filter(function (p) {
21
- return p.key !== 'blockControls$';
22
- }) // Filter out the unwanted plugin
23
- });
24
- view.updateState(newState);
25
- stateUpdated = true;
26
- }
27
16
  return new _safePlugin.SafePlugin({
28
17
  key: limitedModePluginKey,
29
18
  view: function view(_view) {
30
- _view2 = _view;
31
19
  return {};
32
20
  },
33
21
  state: {
34
22
  init: function init(config, editorState) {
35
- if (editorState.doc.childCount > (0, _expVal.expVal)('cc_editor_limited_mode', 'nodeSize', 100)) {
23
+ if (editorState.doc.nodeSize > (0, _expVal.expVal)('cc_editor_limited_mode', 'nodeSize', 100)) {
36
24
  return {
37
25
  documentSizeBreachesThreshold: true
38
26
  };
@@ -41,30 +29,17 @@ var createPlugin = exports.createPlugin = function createPlugin() {
41
29
  documentSizeBreachesThreshold: false
42
30
  };
43
31
  },
44
- apply: function apply(tr, _currentPluginState) {
45
- if (_currentPluginState.documentSizeBreachesThreshold) {
46
- if (!stateUpdated) {
47
- // when the document size reaches the threshold from the state initialisation there is no existing seam to communicate this
48
- // to the controls plug-in without putting in limited mode specific logic inside the controls plug-in as well.
49
- // to mitigate this we call the update state here. Which will mean the editor does not have state divergence
50
- // between when limited mode kicks in on first load versus mid edit session.
51
- updateState(_view2);
52
- }
53
- return {
54
- documentSizeBreachesThreshold: true
55
- };
32
+ apply: function apply(tr, currentPluginState) {
33
+ // Don't check the document size if we're already in limited mode.
34
+ if (currentPluginState.documentSizeBreachesThreshold) {
35
+ return currentPluginState;
56
36
  }
57
- if (tr.doc.childCount > (0, _expVal.expVal)('cc_editor_limited_mode', 'nodeSize', 100)) {
58
- var customEvent = new CustomEvent('limited-mode-activated');
59
- document.dispatchEvent(customEvent);
60
- updateState(_view2);
61
- return {
37
+ if (tr.doc.nodeSize > (0, _expVal.expVal)('cc_editor_limited_mode', 'nodeSize', 100)) {
38
+ return _objectSpread(_objectSpread({}, currentPluginState), {}, {
62
39
  documentSizeBreachesThreshold: true
63
- };
40
+ });
64
41
  }
65
- return {
66
- documentSizeBreachesThreshold: false
67
- };
42
+ return currentPluginState;
68
43
  }
69
44
  }
70
45
  });
@@ -1,30 +1,16 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { EditorState, PluginKey } from '@atlaskit/editor-prosemirror/state';
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
5
  export const createPlugin = () => {
6
- let view;
7
- let stateUpdated = false;
8
- function updateState(view) {
9
- const newState = EditorState.create({
10
- schema: view.state.schema,
11
- doc: view.state.doc,
12
- // remove the state plugin to trigger the view cleanup function
13
- // @ts-ignore This plugin interaction is expected to be temporary - we can't pass the key via standard inter plugin communication as that would introduce cyclical dependencies
14
- plugins: view.state.plugins.filter(p => p.key !== 'blockControls$') // Filter out the unwanted plugin
15
- });
16
- view.updateState(newState);
17
- stateUpdated = true;
18
- }
19
6
  return new SafePlugin({
20
7
  key: limitedModePluginKey,
21
8
  view: _view => {
22
- view = _view;
23
9
  return {};
24
10
  },
25
11
  state: {
26
12
  init(config, editorState) {
27
- if (editorState.doc.childCount > expVal('cc_editor_limited_mode', 'nodeSize', 100)) {
13
+ if (editorState.doc.nodeSize > expVal('cc_editor_limited_mode', 'nodeSize', 100)) {
28
14
  return {
29
15
  documentSizeBreachesThreshold: true
30
16
  };
@@ -33,30 +19,18 @@ export const createPlugin = () => {
33
19
  documentSizeBreachesThreshold: false
34
20
  };
35
21
  },
36
- apply: (tr, _currentPluginState) => {
37
- if (_currentPluginState.documentSizeBreachesThreshold) {
38
- if (!stateUpdated) {
39
- // when the document size reaches the threshold from the state initialisation there is no existing seam to communicate this
40
- // to the controls plug-in without putting in limited mode specific logic inside the controls plug-in as well.
41
- // to mitigate this we call the update state here. Which will mean the editor does not have state divergence
42
- // between when limited mode kicks in on first load versus mid edit session.
43
- updateState(view);
44
- }
45
- return {
46
- documentSizeBreachesThreshold: true
47
- };
22
+ apply: (tr, currentPluginState) => {
23
+ // Don't check the document size if we're already in limited mode.
24
+ if (currentPluginState.documentSizeBreachesThreshold) {
25
+ return currentPluginState;
48
26
  }
49
- if (tr.doc.childCount > expVal('cc_editor_limited_mode', 'nodeSize', 100)) {
50
- const customEvent = new CustomEvent('limited-mode-activated');
51
- document.dispatchEvent(customEvent);
52
- updateState(view);
27
+ if (tr.doc.nodeSize > expVal('cc_editor_limited_mode', 'nodeSize', 100)) {
53
28
  return {
29
+ ...currentPluginState,
54
30
  documentSizeBreachesThreshold: true
55
31
  };
56
32
  }
57
- return {
58
- documentSizeBreachesThreshold: false
59
- };
33
+ return currentPluginState;
60
34
  }
61
35
  }
62
36
  });
@@ -1,32 +1,19 @@
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; }
1
4
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { EditorState, PluginKey } from '@atlaskit/editor-prosemirror/state';
5
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
6
  import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
4
7
  export var limitedModePluginKey = new PluginKey('limitedModePlugin');
5
8
  export var createPlugin = function createPlugin() {
6
- var _view2;
7
- var stateUpdated = false;
8
- function updateState(view) {
9
- var newState = EditorState.create({
10
- schema: view.state.schema,
11
- doc: view.state.doc,
12
- // remove the state plugin to trigger the view cleanup function
13
- // @ts-ignore This plugin interaction is expected to be temporary - we can't pass the key via standard inter plugin communication as that would introduce cyclical dependencies
14
- plugins: view.state.plugins.filter(function (p) {
15
- return p.key !== 'blockControls$';
16
- }) // Filter out the unwanted plugin
17
- });
18
- view.updateState(newState);
19
- stateUpdated = true;
20
- }
21
9
  return new SafePlugin({
22
10
  key: limitedModePluginKey,
23
11
  view: function view(_view) {
24
- _view2 = _view;
25
12
  return {};
26
13
  },
27
14
  state: {
28
15
  init: function init(config, editorState) {
29
- if (editorState.doc.childCount > expVal('cc_editor_limited_mode', 'nodeSize', 100)) {
16
+ if (editorState.doc.nodeSize > expVal('cc_editor_limited_mode', 'nodeSize', 100)) {
30
17
  return {
31
18
  documentSizeBreachesThreshold: true
32
19
  };
@@ -35,30 +22,17 @@ export var createPlugin = function createPlugin() {
35
22
  documentSizeBreachesThreshold: false
36
23
  };
37
24
  },
38
- apply: function apply(tr, _currentPluginState) {
39
- if (_currentPluginState.documentSizeBreachesThreshold) {
40
- if (!stateUpdated) {
41
- // when the document size reaches the threshold from the state initialisation there is no existing seam to communicate this
42
- // to the controls plug-in without putting in limited mode specific logic inside the controls plug-in as well.
43
- // to mitigate this we call the update state here. Which will mean the editor does not have state divergence
44
- // between when limited mode kicks in on first load versus mid edit session.
45
- updateState(_view2);
46
- }
47
- return {
48
- documentSizeBreachesThreshold: true
49
- };
25
+ apply: function apply(tr, currentPluginState) {
26
+ // Don't check the document size if we're already in limited mode.
27
+ if (currentPluginState.documentSizeBreachesThreshold) {
28
+ return currentPluginState;
50
29
  }
51
- if (tr.doc.childCount > expVal('cc_editor_limited_mode', 'nodeSize', 100)) {
52
- var customEvent = new CustomEvent('limited-mode-activated');
53
- document.dispatchEvent(customEvent);
54
- updateState(_view2);
55
- return {
30
+ if (tr.doc.nodeSize > expVal('cc_editor_limited_mode', 'nodeSize', 100)) {
31
+ return _objectSpread(_objectSpread({}, currentPluginState), {}, {
56
32
  documentSizeBreachesThreshold: true
57
- };
33
+ });
58
34
  }
59
- return {
60
- documentSizeBreachesThreshold: false
61
- };
35
+ return currentPluginState;
62
36
  }
63
37
  }
64
38
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-limited-mode",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "LimitedMode plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@atlaskit/editor-prosemirror": "7.0.0",
35
- "@atlaskit/tmp-editor-statsig": "^11.0.0",
35
+ "@atlaskit/tmp-editor-statsig": "^11.1.0",
36
36
  "@babel/runtime": "^7.0.0"
37
37
  },
38
38
  "peerDependencies": {