@atlaskit/editor-core 191.0.8 → 191.0.9

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.
Files changed (127) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/afm-cc/tsconfig.json +3 -3
  3. package/dist/cjs/plugins/index.js +0 -7
  4. package/dist/cjs/presets/universal.js +2 -1
  5. package/dist/cjs/ui/Appearance/FullPage/FullPageToolbar.js +1 -1
  6. package/dist/cjs/ui/ContentStyles/index.js +1 -1
  7. package/dist/cjs/version-wrapper.js +1 -1
  8. package/dist/es2019/plugins/index.js +0 -1
  9. package/dist/es2019/presets/universal.js +2 -1
  10. package/dist/es2019/ui/Appearance/FullPage/FullPageToolbar.js +1 -1
  11. package/dist/es2019/ui/ContentStyles/index.js +1 -1
  12. package/dist/es2019/version-wrapper.js +1 -1
  13. package/dist/esm/plugins/index.js +0 -1
  14. package/dist/esm/presets/universal.js +2 -1
  15. package/dist/esm/ui/Appearance/FullPage/FullPageToolbar.js +1 -1
  16. package/dist/esm/ui/ContentStyles/index.js +1 -1
  17. package/dist/esm/version-wrapper.js +1 -1
  18. package/dist/types/plugins/index.d.ts +0 -1
  19. package/dist/types/types/editor-props.d.ts +1 -1
  20. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  21. package/dist/types-ts4.5/types/editor-props.d.ts +1 -1
  22. package/package.json +4 -8
  23. package/dist/cjs/plugins/find-replace/FindReplaceToolbarButtonWithState.js +0 -166
  24. package/dist/cjs/plugins/find-replace/actions.js +0 -19
  25. package/dist/cjs/plugins/find-replace/commands-with-analytics.js +0 -101
  26. package/dist/cjs/plugins/find-replace/commands.js +0 -255
  27. package/dist/cjs/plugins/find-replace/index.js +0 -94
  28. package/dist/cjs/plugins/find-replace/keymap.js +0 -24
  29. package/dist/cjs/plugins/find-replace/plugin-key.js +0 -8
  30. package/dist/cjs/plugins/find-replace/plugin.js +0 -138
  31. package/dist/cjs/plugins/find-replace/reducer.js +0 -61
  32. package/dist/cjs/plugins/find-replace/styles.js +0 -16
  33. package/dist/cjs/plugins/find-replace/types.js +0 -5
  34. package/dist/cjs/plugins/find-replace/ui/Find.js +0 -308
  35. package/dist/cjs/plugins/find-replace/ui/FindReplace.js +0 -103
  36. package/dist/cjs/plugins/find-replace/ui/FindReplaceToolbarButton.js +0 -132
  37. package/dist/cjs/plugins/find-replace/ui/FindReplaceTooltipButton.js +0 -76
  38. package/dist/cjs/plugins/find-replace/ui/Replace.js +0 -174
  39. package/dist/cjs/plugins/find-replace/ui/styles.js +0 -44
  40. package/dist/cjs/plugins/find-replace/utils/batch-decorations.js +0 -310
  41. package/dist/cjs/plugins/find-replace/utils/commands.js +0 -16
  42. package/dist/cjs/plugins/find-replace/utils/index.js +0 -290
  43. package/dist/cjs/utils/array.js +0 -13
  44. package/dist/es2019/plugins/find-replace/FindReplaceToolbarButtonWithState.js +0 -153
  45. package/dist/es2019/plugins/find-replace/actions.js +0 -13
  46. package/dist/es2019/plugins/find-replace/commands-with-analytics.js +0 -72
  47. package/dist/es2019/plugins/find-replace/commands.js +0 -240
  48. package/dist/es2019/plugins/find-replace/index.js +0 -89
  49. package/dist/es2019/plugins/find-replace/keymap.js +0 -16
  50. package/dist/es2019/plugins/find-replace/plugin-key.js +0 -2
  51. package/dist/es2019/plugins/find-replace/plugin.js +0 -117
  52. package/dist/es2019/plugins/find-replace/reducer.js +0 -56
  53. package/dist/es2019/plugins/find-replace/styles.js +0 -17
  54. package/dist/es2019/plugins/find-replace/types.js +0 -1
  55. package/dist/es2019/plugins/find-replace/ui/Find.js +0 -284
  56. package/dist/es2019/plugins/find-replace/ui/FindReplace.js +0 -78
  57. package/dist/es2019/plugins/find-replace/ui/FindReplaceToolbarButton.js +0 -122
  58. package/dist/es2019/plugins/find-replace/ui/FindReplaceTooltipButton.js +0 -50
  59. package/dist/es2019/plugins/find-replace/ui/Replace.js +0 -152
  60. package/dist/es2019/plugins/find-replace/ui/styles.js +0 -48
  61. package/dist/es2019/plugins/find-replace/utils/batch-decorations.js +0 -189
  62. package/dist/es2019/plugins/find-replace/utils/commands.js +0 -6
  63. package/dist/es2019/plugins/find-replace/utils/index.js +0 -249
  64. package/dist/es2019/utils/array.js +0 -3
  65. package/dist/esm/plugins/find-replace/FindReplaceToolbarButtonWithState.js +0 -157
  66. package/dist/esm/plugins/find-replace/actions.js +0 -13
  67. package/dist/esm/plugins/find-replace/commands-with-analytics.js +0 -95
  68. package/dist/esm/plugins/find-replace/commands.js +0 -248
  69. package/dist/esm/plugins/find-replace/index.js +0 -87
  70. package/dist/esm/plugins/find-replace/keymap.js +0 -18
  71. package/dist/esm/plugins/find-replace/plugin-key.js +0 -2
  72. package/dist/esm/plugins/find-replace/plugin.js +0 -133
  73. package/dist/esm/plugins/find-replace/reducer.js +0 -54
  74. package/dist/esm/plugins/find-replace/styles.js +0 -10
  75. package/dist/esm/plugins/find-replace/types.js +0 -1
  76. package/dist/esm/plugins/find-replace/ui/Find.js +0 -302
  77. package/dist/esm/plugins/find-replace/ui/FindReplace.js +0 -97
  78. package/dist/esm/plugins/find-replace/ui/FindReplaceToolbarButton.js +0 -126
  79. package/dist/esm/plugins/find-replace/ui/FindReplaceTooltipButton.js +0 -69
  80. package/dist/esm/plugins/find-replace/ui/Replace.js +0 -168
  81. package/dist/esm/plugins/find-replace/ui/styles.js +0 -37
  82. package/dist/esm/plugins/find-replace/utils/batch-decorations.js +0 -304
  83. package/dist/esm/plugins/find-replace/utils/commands.js +0 -10
  84. package/dist/esm/plugins/find-replace/utils/index.js +0 -280
  85. package/dist/esm/utils/array.js +0 -7
  86. package/dist/types/plugins/find-replace/FindReplaceToolbarButtonWithState.d.ts +0 -4
  87. package/dist/types/plugins/find-replace/actions.d.ts +0 -64
  88. package/dist/types/plugins/find-replace/commands-with-analytics.d.ts +0 -27
  89. package/dist/types/plugins/find-replace/commands.d.ts +0 -12
  90. package/dist/types/plugins/find-replace/index.d.ts +0 -3
  91. package/dist/types/plugins/find-replace/keymap.d.ts +0 -4
  92. package/dist/types/plugins/find-replace/plugin-key.d.ts +0 -3
  93. package/dist/types/plugins/find-replace/plugin.d.ts +0 -6
  94. package/dist/types/plugins/find-replace/reducer.d.ts +0 -4
  95. package/dist/types/plugins/find-replace/styles.d.ts +0 -3
  96. package/dist/types/plugins/find-replace/types.d.ts +0 -79
  97. package/dist/types/plugins/find-replace/ui/Find.d.ts +0 -71
  98. package/dist/types/plugins/find-replace/ui/FindReplace.d.ts +0 -43
  99. package/dist/types/plugins/find-replace/ui/FindReplaceToolbarButton.d.ts +0 -21
  100. package/dist/types/plugins/find-replace/ui/FindReplaceTooltipButton.d.ts +0 -18
  101. package/dist/types/plugins/find-replace/ui/Replace.d.ts +0 -27
  102. package/dist/types/plugins/find-replace/ui/styles.d.ts +0 -6
  103. package/dist/types/plugins/find-replace/utils/batch-decorations.d.ts +0 -36
  104. package/dist/types/plugins/find-replace/utils/commands.d.ts +0 -2
  105. package/dist/types/plugins/find-replace/utils/index.d.ts +0 -49
  106. package/dist/types/utils/array.d.ts +0 -1
  107. package/dist/types-ts4.5/plugins/find-replace/FindReplaceToolbarButtonWithState.d.ts +0 -4
  108. package/dist/types-ts4.5/plugins/find-replace/actions.d.ts +0 -64
  109. package/dist/types-ts4.5/plugins/find-replace/commands-with-analytics.d.ts +0 -27
  110. package/dist/types-ts4.5/plugins/find-replace/commands.d.ts +0 -12
  111. package/dist/types-ts4.5/plugins/find-replace/index.d.ts +0 -3
  112. package/dist/types-ts4.5/plugins/find-replace/keymap.d.ts +0 -4
  113. package/dist/types-ts4.5/plugins/find-replace/plugin-key.d.ts +0 -3
  114. package/dist/types-ts4.5/plugins/find-replace/plugin.d.ts +0 -6
  115. package/dist/types-ts4.5/plugins/find-replace/reducer.d.ts +0 -4
  116. package/dist/types-ts4.5/plugins/find-replace/styles.d.ts +0 -3
  117. package/dist/types-ts4.5/plugins/find-replace/types.d.ts +0 -79
  118. package/dist/types-ts4.5/plugins/find-replace/ui/Find.d.ts +0 -71
  119. package/dist/types-ts4.5/plugins/find-replace/ui/FindReplace.d.ts +0 -43
  120. package/dist/types-ts4.5/plugins/find-replace/ui/FindReplaceToolbarButton.d.ts +0 -21
  121. package/dist/types-ts4.5/plugins/find-replace/ui/FindReplaceTooltipButton.d.ts +0 -18
  122. package/dist/types-ts4.5/plugins/find-replace/ui/Replace.d.ts +0 -27
  123. package/dist/types-ts4.5/plugins/find-replace/ui/styles.d.ts +0 -6
  124. package/dist/types-ts4.5/plugins/find-replace/utils/batch-decorations.d.ts +0 -36
  125. package/dist/types-ts4.5/plugins/find-replace/utils/commands.d.ts +0 -2
  126. package/dist/types-ts4.5/plugins/find-replace/utils/index.d.ts +0 -49
  127. package/dist/types-ts4.5/utils/array.d.ts +0 -1
@@ -1,168 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
- /** @jsx jsx */
11
- import React from 'react';
12
- import { jsx } from '@emotion/react';
13
- import Button from '@atlaskit/button/standard-button';
14
- import { defineMessages, injectIntl } from 'react-intl-next';
15
- import Textfield from '@atlaskit/textfield';
16
- import { sectionWrapperStyles, replaceSectionButtonStyles } from './styles';
17
- import { EVENT_TYPE, ACTION, ACTION_SUBJECT, TRIGGER_METHOD } from '@atlaskit/editor-common/analytics';
18
- var messages = defineMessages({
19
- replaceWith: {
20
- id: 'fabric.editor.replaceWith',
21
- defaultMessage: 'Replace with',
22
- description: 'The value that will replace the word or phrase that was searched for'
23
- },
24
- replace: {
25
- id: 'fabric.editor.replace',
26
- defaultMessage: 'Replace',
27
- description: 'Replace only the currently selected instance of the word or phrase'
28
- },
29
- replaceAll: {
30
- id: 'fabric.editor.replaceAll',
31
- defaultMessage: 'Replace all',
32
- description: 'Replace all instances of the word or phrase throughout the entire document'
33
- }
34
- });
35
- var Replace = /*#__PURE__*/function (_React$PureComponent) {
36
- _inherits(Replace, _React$PureComponent);
37
- var _super = _createSuper(Replace);
38
- function Replace(props) {
39
- var _this;
40
- _classCallCheck(this, Replace);
41
- _this = _super.call(this, props);
42
- _defineProperty(_assertThisInitialized(_this), "replaceTextfieldRef", /*#__PURE__*/React.createRef());
43
- _defineProperty(_assertThisInitialized(_this), "skipWhileComposing", function (fn) {
44
- if (_this.state.isComposing) {
45
- return;
46
- }
47
- fn();
48
- });
49
- _defineProperty(_assertThisInitialized(_this), "handleReplaceClick", function () {
50
- return _this.skipWhileComposing(function () {
51
- _this.props.onReplace({
52
- triggerMethod: TRIGGER_METHOD.BUTTON,
53
- replaceText: _this.state.replaceText
54
- });
55
- });
56
- });
57
- _defineProperty(_assertThisInitialized(_this), "handleReplaceChange", function (event) {
58
- return _this.skipWhileComposing(function () {
59
- _this.updateReplaceValue(event.target.value);
60
- });
61
- });
62
- _defineProperty(_assertThisInitialized(_this), "updateReplaceValue", function (replaceText) {
63
- var dispatchAnalyticsEvent = _this.props.dispatchAnalyticsEvent;
64
- if (dispatchAnalyticsEvent) {
65
- dispatchAnalyticsEvent({
66
- eventType: EVENT_TYPE.TRACK,
67
- action: ACTION.CHANGED_REPLACEMENT_TEXT,
68
- actionSubject: ACTION_SUBJECT.FIND_REPLACE_DIALOG
69
- });
70
- }
71
- _this.setState({
72
- replaceText: replaceText
73
- });
74
- });
75
- _defineProperty(_assertThisInitialized(_this), "handleReplaceKeyDown", function (event) {
76
- return _this.skipWhileComposing(function () {
77
- if (event.key === 'Enter') {
78
- _this.props.onReplace({
79
- triggerMethod: TRIGGER_METHOD.KEYBOARD,
80
- replaceText: _this.state.replaceText
81
- });
82
- } else if (event.key === 'ArrowUp') {
83
- // we want to move focus between find & replace texfields when user hits up/down arrows
84
- _this.props.onArrowUp();
85
- }
86
- });
87
- });
88
- _defineProperty(_assertThisInitialized(_this), "handleReplaceAllClick", function () {
89
- return _this.skipWhileComposing(function () {
90
- _this.props.onReplaceAll({
91
- replaceText: _this.state.replaceText
92
- });
93
- });
94
- });
95
- _defineProperty(_assertThisInitialized(_this), "handleCompositionStart", function () {
96
- _this.setState({
97
- isComposing: true
98
- });
99
- });
100
- _defineProperty(_assertThisInitialized(_this), "handleCompositionEnd", function (event) {
101
- _this.setState({
102
- isComposing: false
103
- });
104
- // type for React.CompositionEvent doesn't set type for target correctly
105
- _this.updateReplaceValue(event.target.value);
106
- });
107
- var _replaceText = props.replaceText,
108
- formatMessage = props.intl.formatMessage;
109
- _this.state = {
110
- replaceText: _replaceText || '',
111
- isComposing: false
112
- };
113
- _this.replaceWith = formatMessage(messages.replaceWith);
114
- _this.replace = formatMessage(messages.replace);
115
- _this.replaceAll = formatMessage(messages.replaceAll);
116
- return _this;
117
- }
118
- _createClass(Replace, [{
119
- key: "componentDidMount",
120
- value: function componentDidMount() {
121
- this.props.onReplaceTextfieldRefSet(this.replaceTextfieldRef);
122
- }
123
- }, {
124
- key: "componentDidUpdate",
125
- value: function componentDidUpdate(_ref) {
126
- var prevReplaceText = _ref.replaceText;
127
- var replaceText = this.props.replaceText;
128
- if (replaceText && replaceText !== prevReplaceText) {
129
- this.setState({
130
- replaceText: replaceText,
131
- isComposing: false
132
- });
133
- }
134
- }
135
- }, {
136
- key: "render",
137
- value: function render() {
138
- var replaceText = this.state.replaceText;
139
- var canReplace = this.props.canReplace;
140
- return jsx("div", {
141
- css: sectionWrapperStyles
142
- }, jsx(Textfield, {
143
- name: "replace",
144
- appearance: "none",
145
- placeholder: this.replaceWith,
146
- defaultValue: replaceText,
147
- ref: this.replaceTextfieldRef,
148
- autoComplete: "off",
149
- onChange: this.handleReplaceChange,
150
- onKeyDown: this.handleReplaceKeyDown,
151
- onCompositionStart: this.handleCompositionStart,
152
- onCompositionEnd: this.handleCompositionEnd
153
- }), jsx(Button, {
154
- css: replaceSectionButtonStyles,
155
- testId: this.replace,
156
- onClick: this.handleReplaceClick,
157
- isDisabled: !canReplace
158
- }, this.replace), jsx(Button, {
159
- css: replaceSectionButtonStyles,
160
- testId: this.replaceAll,
161
- onClick: this.handleReplaceAllClick,
162
- isDisabled: !canReplace
163
- }, this.replaceAll));
164
- }
165
- }]);
166
- return Replace;
167
- }(React.PureComponent);
168
- export default injectIntl(Replace);
@@ -1,37 +0,0 @@
1
- import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
2
- var _templateObject;
3
- /** @jsx jsx */
4
- import { css } from '@emotion/react';
5
- import { N60, N30A } from '@atlaskit/theme/colors';
6
- import { relativeFontSizeToBase16 } from '@atlaskit/editor-shared-styles';
7
- export var replaceSectionButtonStyles = css({
8
- marginLeft: "var(--ds-space-050, 4px)"
9
- });
10
- export var ruleStyles = css({
11
- width: '100%',
12
- border: 'none',
13
- backgroundColor: "".concat("var(--ds-border, ".concat(N30A, ")")),
14
- margin: "var(--ds-space-050, 4px)".concat(" 0px"),
15
- height: '1px',
16
- borderRadius: '1px'
17
- });
18
- export var wrapperStyles = css({
19
- display: 'flex',
20
- flexDirection: 'column',
21
- '> *:not(#replace-hr-element)': {
22
- margin: "0px ".concat("var(--ds-space-050, 4px)")
23
- }
24
- });
25
- export var sectionWrapperStyles = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n\n & > * {\n display: inline-flex;\n height: 32px;\n flex: 0 0 auto;\n }\n\n & > [data-ds--text-field--container] {\n display: flex;\n flex: 1 1 auto;\n }\n"])));
26
- export var countStyles = css({
27
- color: "".concat("var(--ds-text-subtlest, ".concat(N60, ")")),
28
- fontSize: "".concat(relativeFontSizeToBase16(12)),
29
- flex: '0 0 auto',
30
- justifyContent: 'center',
31
- alignItems: 'center',
32
- marginLeft: "var(--ds-space-050, 4px)",
33
- marginRight: "var(--ds-space-100, 8px)"
34
- });
35
- export var countWrapperStyles = css({
36
- alignItems: 'center'
37
- });
@@ -1,304 +0,0 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _regeneratorRuntime from "@babel/runtime/regenerator";
5
- import { createDecorations, findDecorationFromMatch } from './index';
6
- import { getPluginState } from '../plugin';
7
-
8
- // max number of decorations to apply at once
9
- var batchIncrement = 100;
10
- // position range to apply decorations between before alternating above or below viewport
11
- var posIncrement = 2000;
12
- /**
13
- * Provides support for applying search match highlight decorations in batches
14
- */
15
- var BatchDecorations = /*#__PURE__*/function () {
16
- function BatchDecorations() {
17
- _classCallCheck(this, BatchDecorations);
18
- }
19
- _createClass(BatchDecorations, [{
20
- key: "stop",
21
- value: function stop() {
22
- if (this.rafId) {
23
- cancelAnimationFrame(this.rafId);
24
- }
25
- }
26
-
27
- /**
28
- * Applies the decorations needed for the current search results
29
- * It does so async, splitting them up into batches to help with performance
30
- */
31
- }, {
32
- key: "applyAllSearchDecorations",
33
- value: function () {
34
- var _applyAllSearchDecorations = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(editorView, containerElement, addDecorations, removeDecorations) {
35
- var pmElement, positions, startPos, endPos, viewportStartPos, viewportEndPos, dir, before, after, diff;
36
- return _regeneratorRuntime.wrap(function _callee$(_context) {
37
- while (1) switch (_context.prev = _context.next) {
38
- case 0:
39
- this.stop();
40
- this.addDecorations = addDecorations;
41
- this.removeDecorations = removeDecorations;
42
- if (containerElement) {
43
- _context.next = 5;
44
- break;
45
- }
46
- return _context.abrupt("return");
47
- case 5:
48
- pmElement = containerElement.querySelector('.ProseMirror');
49
- if (pmElement) {
50
- _context.next = 8;
51
- break;
52
- }
53
- return _context.abrupt("return");
54
- case 8:
55
- positions = this.calcDecorationPositions(editorView, containerElement, pmElement);
56
- startPos = positions.startPos, endPos = positions.endPos, viewportStartPos = positions.viewportStartPos, viewportEndPos = positions.viewportEndPos;
57
- dir = 0;
58
- before = viewportStartPos;
59
- after = viewportEndPos - posIncrement;
60
- _context.next = 15;
61
- return this.updateDecorationsBetween(editorView, viewportStartPos, viewportEndPos);
62
- case 15:
63
- if (!(before > startPos || after < endPos)) {
64
- _context.next = 28;
65
- break;
66
- }
67
- if (!(dir++ % 2 === 0 && before > startPos || after >= endPos)) {
68
- _context.next = 23;
69
- break;
70
- }
71
- diff = before - startPos;
72
- before = Math.max(before - posIncrement, startPos);
73
- _context.next = 21;
74
- return this.updateDecorationsBetween(editorView, before, before + Math.min(diff, posIncrement));
75
- case 21:
76
- _context.next = 26;
77
- break;
78
- case 23:
79
- after = Math.min(after + posIncrement, endPos);
80
- _context.next = 26;
81
- return this.updateDecorationsBetween(editorView, after, Math.min(after + posIncrement, endPos));
82
- case 26:
83
- _context.next = 15;
84
- break;
85
- case 28:
86
- case "end":
87
- return _context.stop();
88
- }
89
- }, _callee, this);
90
- }));
91
- function applyAllSearchDecorations(_x, _x2, _x3, _x4) {
92
- return _applyAllSearchDecorations.apply(this, arguments);
93
- }
94
- return applyAllSearchDecorations;
95
- }()
96
- }, {
97
- key: "updateDecorationsBetween",
98
- value: function () {
99
- var _updateDecorationsBetween = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(editorView, startPos, endPos) {
100
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
101
- while (1) switch (_context2.prev = _context2.next) {
102
- case 0:
103
- _context2.next = 2;
104
- return this.removeDecorationsBetween(editorView, startPos, endPos);
105
- case 2:
106
- _context2.next = 4;
107
- return this.addDecorationsBetween(editorView, startPos, endPos);
108
- case 4:
109
- case "end":
110
- return _context2.stop();
111
- }
112
- }, _callee2, this);
113
- }));
114
- function updateDecorationsBetween(_x5, _x6, _x7) {
115
- return _updateDecorationsBetween.apply(this, arguments);
116
- }
117
- return updateDecorationsBetween;
118
- }()
119
- }, {
120
- key: "addDecorationsBetween",
121
- value: function () {
122
- var _addDecorationsBetween = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(editorView, startPos, endPos) {
123
- var _this = this;
124
- var selection, _getPluginState, matches, decorationSet, matchesBetween, selectionMatch, selectionIndex;
125
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
126
- while (1) switch (_context3.prev = _context3.next) {
127
- case 0:
128
- selection = editorView.state.selection;
129
- _getPluginState = getPluginState(editorView.state), matches = _getPluginState.matches, decorationSet = _getPluginState.decorationSet;
130
- if (!(matches.length === 0)) {
131
- _context3.next = 4;
132
- break;
133
- }
134
- return _context3.abrupt("return");
135
- case 4:
136
- matchesBetween = matches.filter(function (m) {
137
- return m.start >= startPos && (endPos === undefined || m.start < endPos);
138
- });
139
- selectionMatch = matches.find(function (match) {
140
- return match.start >= selection.from;
141
- });
142
- selectionIndex = matchesBetween.findIndex(function (match) {
143
- return match === selectionMatch;
144
- });
145
- _context3.next = 9;
146
- return this.batchRequests(function (counter) {
147
- var matchesToDecorate = matchesBetween.slice(counter, counter + batchIncrement);
148
- if (matchesToDecorate.length === 0) {
149
- return false;
150
- }
151
- var useSelectionIndex = selectionIndex >= counter && selectionIndex < counter + batchIncrement;
152
- if (selectionMatch && useSelectionIndex) {
153
- var selectionMatchDecoration = findDecorationFromMatch(decorationSet, selectionMatch);
154
- if (selectionMatchDecoration) {
155
- matchesToDecorate.splice(selectionIndex % batchIncrement, 1);
156
- useSelectionIndex = false;
157
- }
158
- }
159
- if (_this.addDecorations) {
160
- _this.addDecorations(createDecorations(useSelectionIndex ? selectionIndex % batchIncrement : -1, matchesToDecorate));
161
- }
162
- }, {
163
- increment: batchIncrement,
164
- until: matchesBetween.length
165
- });
166
- case 9:
167
- return _context3.abrupt("return", _context3.sent);
168
- case 10:
169
- case "end":
170
- return _context3.stop();
171
- }
172
- }, _callee3, this);
173
- }));
174
- function addDecorationsBetween(_x8, _x9, _x10) {
175
- return _addDecorationsBetween.apply(this, arguments);
176
- }
177
- return addDecorationsBetween;
178
- }()
179
- }, {
180
- key: "removeDecorationsBetween",
181
- value: function () {
182
- var _removeDecorationsBetween = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(editorView, startPos, endPos) {
183
- var _this2 = this;
184
- var _getPluginState2, decorationSet, decorations;
185
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
186
- while (1) switch (_context4.prev = _context4.next) {
187
- case 0:
188
- _getPluginState2 = getPluginState(editorView.state), decorationSet = _getPluginState2.decorationSet;
189
- decorations = decorationSet.find(startPos, endPos);
190
- if (!(decorations.length === 0)) {
191
- _context4.next = 4;
192
- break;
193
- }
194
- return _context4.abrupt("return");
195
- case 4:
196
- _context4.next = 6;
197
- return this.batchRequests(function (counter) {
198
- var decorationsToRemove = decorations.slice(counter, counter + batchIncrement);
199
- if (decorationsToRemove.length === 0) {
200
- return false;
201
- }
202
- // only get those decorations whose from >= startPos
203
- for (var i = 0; i < decorationsToRemove.length; i++) {
204
- if (decorationsToRemove[i].from >= startPos) {
205
- break;
206
- }
207
- decorationsToRemove = decorationsToRemove.slice(1);
208
- }
209
- if (_this2.removeDecorations) {
210
- _this2.removeDecorations(decorationsToRemove);
211
- }
212
- }, {
213
- increment: batchIncrement,
214
- until: decorations.length
215
- });
216
- case 6:
217
- return _context4.abrupt("return", _context4.sent);
218
- case 7:
219
- case "end":
220
- return _context4.stop();
221
- }
222
- }, _callee4, this);
223
- }));
224
- function removeDecorationsBetween(_x11, _x12, _x13) {
225
- return _removeDecorationsBetween.apply(this, arguments);
226
- }
227
- return removeDecorationsBetween;
228
- }()
229
- /**
230
- * Calculates Prosemirror start and end positions we want to apply the decorations
231
- * between
232
- * Also calculates the positions the are the start and end of the user's viewport
233
- * so we can apply decorations there first and work outwards
234
- */
235
- }, {
236
- key: "calcDecorationPositions",
237
- value: function calcDecorationPositions(editorView, containerElement, pmElement) {
238
- var containerRect = containerElement.getBoundingClientRect();
239
- var pmRect = pmElement.getBoundingClientRect();
240
- var viewportStartPos = this.getStartPos(editorView, 0, pmRect.left);
241
- var viewportEndPos = this.getEndPos(editorView, containerRect.top + containerRect.height, pmRect.left);
242
- return {
243
- viewportStartPos: viewportStartPos,
244
- viewportEndPos: viewportEndPos,
245
- startPos: 1,
246
- endPos: editorView.state.doc.nodeSize
247
- };
248
- }
249
- }, {
250
- key: "getStartPos",
251
- value: function getStartPos(editorView, y, x) {
252
- var startPos = editorView.posAtCoords({
253
- top: y,
254
- left: x
255
- });
256
- return startPos ? startPos.pos : 1;
257
- }
258
- }, {
259
- key: "getEndPos",
260
- value: function getEndPos(editorView, y, x) {
261
- var maxPos = editorView.state.doc.nodeSize;
262
- var endPos = editorView.posAtCoords({
263
- top: y,
264
- left: x
265
- });
266
- return endPos ? endPos.pos : maxPos;
267
- }
268
-
269
- /**
270
- * Util to batch function calls by animation frames
271
- * A counter will start at 0 and increment by provided value until reaches limit
272
- * Passed in fn receives the counter as a param, return false to skip waiting
273
- * for the animation frame for the next call
274
- */
275
- }, {
276
- key: "batchRequests",
277
- value: function batchRequests(fn, opts) {
278
- var _this3 = this;
279
- var counter = 0;
280
- var increment = opts.increment,
281
- until = opts.until;
282
- return new Promise(function (resolve) {
283
- var batchedFn = function batchedFn() {
284
- var result = fn(counter);
285
- while (result === false && counter < until) {
286
- counter += increment;
287
- result = fn(counter);
288
- }
289
- if (counter < until) {
290
- counter += increment;
291
- _this3.rafId = requestAnimationFrame(batchedFn);
292
- } else {
293
- _this3.rafId = undefined;
294
- resolve();
295
- }
296
- };
297
- _this3.rafId = requestAnimationFrame(batchedFn);
298
- });
299
- }
300
- }]);
301
- return BatchDecorations;
302
- }();
303
- var batchDecorations = new BatchDecorations();
304
- export default batchDecorations;
@@ -1,10 +0,0 @@
1
- export var withScrollIntoView = function withScrollIntoView(command) {
2
- return function (state, dispatch, view) {
3
- return command(state, function (tr) {
4
- tr.scrollIntoView();
5
- if (dispatch) {
6
- dispatch(tr);
7
- }
8
- }, view);
9
- };
10
- };