@atlaskit/editor-core 191.0.8 → 191.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/CHANGELOG.md +13 -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/Comment/Comment.js +6 -3
  6. package/dist/cjs/ui/Appearance/Comment/Toolbar.js +19 -6
  7. package/dist/cjs/ui/Appearance/FullPage/FullPageToolbar.js +1 -1
  8. package/dist/cjs/ui/ContentStyles/index.js +1 -1
  9. package/dist/cjs/version-wrapper.js +1 -1
  10. package/dist/es2019/plugins/index.js +0 -1
  11. package/dist/es2019/presets/universal.js +2 -1
  12. package/dist/es2019/ui/Appearance/Comment/Comment.js +6 -3
  13. package/dist/es2019/ui/Appearance/Comment/Toolbar.js +38 -6
  14. package/dist/es2019/ui/Appearance/FullPage/FullPageToolbar.js +1 -1
  15. package/dist/es2019/ui/ContentStyles/index.js +1 -1
  16. package/dist/es2019/version-wrapper.js +1 -1
  17. package/dist/esm/plugins/index.js +0 -1
  18. package/dist/esm/presets/universal.js +2 -1
  19. package/dist/esm/ui/Appearance/Comment/Comment.js +6 -3
  20. package/dist/esm/ui/Appearance/Comment/Toolbar.js +19 -6
  21. package/dist/esm/ui/Appearance/FullPage/FullPageToolbar.js +1 -1
  22. package/dist/esm/ui/ContentStyles/index.js +1 -1
  23. package/dist/esm/version-wrapper.js +1 -1
  24. package/dist/types/plugins/index.d.ts +0 -1
  25. package/dist/types/types/editor-props.d.ts +1 -1
  26. package/dist/types/ui/Appearance/Comment/Toolbar.d.ts +2 -1
  27. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  28. package/dist/types-ts4.5/types/editor-props.d.ts +1 -1
  29. package/dist/types-ts4.5/ui/Appearance/Comment/Toolbar.d.ts +2 -1
  30. package/package.json +6 -10
  31. package/dist/cjs/plugins/find-replace/FindReplaceToolbarButtonWithState.js +0 -166
  32. package/dist/cjs/plugins/find-replace/actions.js +0 -19
  33. package/dist/cjs/plugins/find-replace/commands-with-analytics.js +0 -101
  34. package/dist/cjs/plugins/find-replace/commands.js +0 -255
  35. package/dist/cjs/plugins/find-replace/index.js +0 -94
  36. package/dist/cjs/plugins/find-replace/keymap.js +0 -24
  37. package/dist/cjs/plugins/find-replace/plugin-key.js +0 -8
  38. package/dist/cjs/plugins/find-replace/plugin.js +0 -138
  39. package/dist/cjs/plugins/find-replace/reducer.js +0 -61
  40. package/dist/cjs/plugins/find-replace/styles.js +0 -16
  41. package/dist/cjs/plugins/find-replace/types.js +0 -5
  42. package/dist/cjs/plugins/find-replace/ui/Find.js +0 -308
  43. package/dist/cjs/plugins/find-replace/ui/FindReplace.js +0 -103
  44. package/dist/cjs/plugins/find-replace/ui/FindReplaceToolbarButton.js +0 -132
  45. package/dist/cjs/plugins/find-replace/ui/FindReplaceTooltipButton.js +0 -76
  46. package/dist/cjs/plugins/find-replace/ui/Replace.js +0 -174
  47. package/dist/cjs/plugins/find-replace/ui/styles.js +0 -44
  48. package/dist/cjs/plugins/find-replace/utils/batch-decorations.js +0 -310
  49. package/dist/cjs/plugins/find-replace/utils/commands.js +0 -16
  50. package/dist/cjs/plugins/find-replace/utils/index.js +0 -290
  51. package/dist/cjs/utils/array.js +0 -13
  52. package/dist/es2019/plugins/find-replace/FindReplaceToolbarButtonWithState.js +0 -153
  53. package/dist/es2019/plugins/find-replace/actions.js +0 -13
  54. package/dist/es2019/plugins/find-replace/commands-with-analytics.js +0 -72
  55. package/dist/es2019/plugins/find-replace/commands.js +0 -240
  56. package/dist/es2019/plugins/find-replace/index.js +0 -89
  57. package/dist/es2019/plugins/find-replace/keymap.js +0 -16
  58. package/dist/es2019/plugins/find-replace/plugin-key.js +0 -2
  59. package/dist/es2019/plugins/find-replace/plugin.js +0 -117
  60. package/dist/es2019/plugins/find-replace/reducer.js +0 -56
  61. package/dist/es2019/plugins/find-replace/styles.js +0 -17
  62. package/dist/es2019/plugins/find-replace/types.js +0 -1
  63. package/dist/es2019/plugins/find-replace/ui/Find.js +0 -284
  64. package/dist/es2019/plugins/find-replace/ui/FindReplace.js +0 -78
  65. package/dist/es2019/plugins/find-replace/ui/FindReplaceToolbarButton.js +0 -122
  66. package/dist/es2019/plugins/find-replace/ui/FindReplaceTooltipButton.js +0 -50
  67. package/dist/es2019/plugins/find-replace/ui/Replace.js +0 -152
  68. package/dist/es2019/plugins/find-replace/ui/styles.js +0 -48
  69. package/dist/es2019/plugins/find-replace/utils/batch-decorations.js +0 -189
  70. package/dist/es2019/plugins/find-replace/utils/commands.js +0 -6
  71. package/dist/es2019/plugins/find-replace/utils/index.js +0 -249
  72. package/dist/es2019/utils/array.js +0 -3
  73. package/dist/esm/plugins/find-replace/FindReplaceToolbarButtonWithState.js +0 -157
  74. package/dist/esm/plugins/find-replace/actions.js +0 -13
  75. package/dist/esm/plugins/find-replace/commands-with-analytics.js +0 -95
  76. package/dist/esm/plugins/find-replace/commands.js +0 -248
  77. package/dist/esm/plugins/find-replace/index.js +0 -87
  78. package/dist/esm/plugins/find-replace/keymap.js +0 -18
  79. package/dist/esm/plugins/find-replace/plugin-key.js +0 -2
  80. package/dist/esm/plugins/find-replace/plugin.js +0 -133
  81. package/dist/esm/plugins/find-replace/reducer.js +0 -54
  82. package/dist/esm/plugins/find-replace/styles.js +0 -10
  83. package/dist/esm/plugins/find-replace/types.js +0 -1
  84. package/dist/esm/plugins/find-replace/ui/Find.js +0 -302
  85. package/dist/esm/plugins/find-replace/ui/FindReplace.js +0 -97
  86. package/dist/esm/plugins/find-replace/ui/FindReplaceToolbarButton.js +0 -126
  87. package/dist/esm/plugins/find-replace/ui/FindReplaceTooltipButton.js +0 -69
  88. package/dist/esm/plugins/find-replace/ui/Replace.js +0 -168
  89. package/dist/esm/plugins/find-replace/ui/styles.js +0 -37
  90. package/dist/esm/plugins/find-replace/utils/batch-decorations.js +0 -304
  91. package/dist/esm/plugins/find-replace/utils/commands.js +0 -10
  92. package/dist/esm/plugins/find-replace/utils/index.js +0 -280
  93. package/dist/esm/utils/array.js +0 -7
  94. package/dist/types/plugins/find-replace/FindReplaceToolbarButtonWithState.d.ts +0 -4
  95. package/dist/types/plugins/find-replace/actions.d.ts +0 -64
  96. package/dist/types/plugins/find-replace/commands-with-analytics.d.ts +0 -27
  97. package/dist/types/plugins/find-replace/commands.d.ts +0 -12
  98. package/dist/types/plugins/find-replace/index.d.ts +0 -3
  99. package/dist/types/plugins/find-replace/keymap.d.ts +0 -4
  100. package/dist/types/plugins/find-replace/plugin-key.d.ts +0 -3
  101. package/dist/types/plugins/find-replace/plugin.d.ts +0 -6
  102. package/dist/types/plugins/find-replace/reducer.d.ts +0 -4
  103. package/dist/types/plugins/find-replace/styles.d.ts +0 -3
  104. package/dist/types/plugins/find-replace/types.d.ts +0 -79
  105. package/dist/types/plugins/find-replace/ui/Find.d.ts +0 -71
  106. package/dist/types/plugins/find-replace/ui/FindReplace.d.ts +0 -43
  107. package/dist/types/plugins/find-replace/ui/FindReplaceToolbarButton.d.ts +0 -21
  108. package/dist/types/plugins/find-replace/ui/FindReplaceTooltipButton.d.ts +0 -18
  109. package/dist/types/plugins/find-replace/ui/Replace.d.ts +0 -27
  110. package/dist/types/plugins/find-replace/ui/styles.d.ts +0 -6
  111. package/dist/types/plugins/find-replace/utils/batch-decorations.d.ts +0 -36
  112. package/dist/types/plugins/find-replace/utils/commands.d.ts +0 -2
  113. package/dist/types/plugins/find-replace/utils/index.d.ts +0 -49
  114. package/dist/types/utils/array.d.ts +0 -1
  115. package/dist/types-ts4.5/plugins/find-replace/FindReplaceToolbarButtonWithState.d.ts +0 -4
  116. package/dist/types-ts4.5/plugins/find-replace/actions.d.ts +0 -64
  117. package/dist/types-ts4.5/plugins/find-replace/commands-with-analytics.d.ts +0 -27
  118. package/dist/types-ts4.5/plugins/find-replace/commands.d.ts +0 -12
  119. package/dist/types-ts4.5/plugins/find-replace/index.d.ts +0 -3
  120. package/dist/types-ts4.5/plugins/find-replace/keymap.d.ts +0 -4
  121. package/dist/types-ts4.5/plugins/find-replace/plugin-key.d.ts +0 -3
  122. package/dist/types-ts4.5/plugins/find-replace/plugin.d.ts +0 -6
  123. package/dist/types-ts4.5/plugins/find-replace/reducer.d.ts +0 -4
  124. package/dist/types-ts4.5/plugins/find-replace/styles.d.ts +0 -3
  125. package/dist/types-ts4.5/plugins/find-replace/types.d.ts +0 -79
  126. package/dist/types-ts4.5/plugins/find-replace/ui/Find.d.ts +0 -71
  127. package/dist/types-ts4.5/plugins/find-replace/ui/FindReplace.d.ts +0 -43
  128. package/dist/types-ts4.5/plugins/find-replace/ui/FindReplaceToolbarButton.d.ts +0 -21
  129. package/dist/types-ts4.5/plugins/find-replace/ui/FindReplaceTooltipButton.d.ts +0 -18
  130. package/dist/types-ts4.5/plugins/find-replace/ui/Replace.d.ts +0 -27
  131. package/dist/types-ts4.5/plugins/find-replace/ui/styles.d.ts +0 -6
  132. package/dist/types-ts4.5/plugins/find-replace/utils/batch-decorations.d.ts +0 -36
  133. package/dist/types-ts4.5/plugins/find-replace/utils/commands.d.ts +0 -2
  134. package/dist/types-ts4.5/plugins/find-replace/utils/index.d.ts +0 -49
  135. package/dist/types-ts4.5/utils/array.d.ts +0 -1
@@ -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
- };
@@ -1,280 +0,0 @@
1
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
2
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
3
- import { selectedSearchMatchClass, searchMatchClass } from '../styles';
4
- export function getSelectedText(selection) {
5
- var text = '';
6
- var selectedContent = selection.content().content;
7
- for (var i = 0; i < selectedContent.childCount; i++) {
8
- text += selectedContent.child(i).textContent;
9
- }
10
- return text;
11
- }
12
- export var createDecorations = function createDecorations(selectedIndex, matches) {
13
- return matches.map(function (_ref, i) {
14
- var start = _ref.start,
15
- end = _ref.end;
16
- return createDecoration(start, end, i === selectedIndex);
17
- });
18
- };
19
- export var createDecoration = function createDecoration(start, end, isSelected) {
20
- var className = searchMatchClass;
21
- if (isSelected) {
22
- className += " ".concat(selectedSearchMatchClass);
23
- }
24
- return Decoration.inline(start, end, {
25
- class: className
26
- });
27
- };
28
- export function findMatches(content, searchText, shouldMatchCase) {
29
- var contentIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
30
- var matches = [];
31
- var searchTextLength = searchText.length;
32
- var textGrouping = null;
33
- var collectMatch = function collectMatch(textGrouping) {
34
- if (!textGrouping) {
35
- return;
36
- }
37
- var text = textGrouping.text,
38
- relativePos = textGrouping.pos;
39
- var pos = contentIndex + relativePos;
40
- if (!shouldMatchCase) {
41
- searchText = searchText.toLowerCase();
42
- text = text.toLowerCase();
43
- }
44
- var index = text.indexOf(searchText);
45
- while (index !== -1) {
46
- // Find the next substring from the end of the first, so that they don't overlap
47
- var end = index + searchTextLength;
48
- // Add the substring index to the position of the node
49
- matches.push({
50
- start: pos + index,
51
- end: pos + end
52
- });
53
- index = text.indexOf(searchText, end);
54
- }
55
- };
56
- if (searchTextLength > 0) {
57
- content.descendants(function (node, pos) {
58
- if (node.isText) {
59
- if (textGrouping === null) {
60
- textGrouping = {
61
- text: node.text,
62
- pos: pos
63
- };
64
- } else {
65
- textGrouping.text = textGrouping.text + node.text;
66
- }
67
- } else {
68
- collectMatch(textGrouping);
69
- textGrouping = null;
70
- }
71
- });
72
- // if there's a dangling text grouping and no non-text node to trigger collectMatch, manually collectMatch
73
- if (textGrouping) {
74
- collectMatch(textGrouping);
75
- }
76
- }
77
- return matches;
78
- }
79
-
80
- /**
81
- * Finds index of first item in matches array that comes after user's cursor pos.
82
- * If `backward` is `true`, finds index of first item that comes before instead.
83
- */
84
- export function findSearchIndex(selectionPos, matches) {
85
- var backward = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
86
- if (backward) {
87
- var matchIndex = matches.findIndex(function (match) {
88
- return match.start >= selectionPos;
89
- }) - 1;
90
- if (matchIndex < 0) {
91
- matchIndex = matches.length - 1; // wrap around from the end
92
- }
93
-
94
- return matchIndex;
95
- }
96
- return Math.max(matches.findIndex(function (match) {
97
- return match.start >= selectionPos;
98
- }), 0);
99
- }
100
- export var nextIndex = function nextIndex(currentIndex, total) {
101
- return (currentIndex + 1) % total;
102
- };
103
- export var prevIndex = function prevIndex(currentIndex, total) {
104
- return (currentIndex - 1 + total) % total;
105
- };
106
- export var getSelectionForMatch = function getSelectionForMatch(selection, doc, index, matches) {
107
- var offset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
108
- if (matches[index]) {
109
- return TextSelection.create(doc, matches[index].start + offset);
110
- }
111
- return selection;
112
- };
113
- export var findDecorationFromMatch = function findDecorationFromMatch(decorationSet, match) {
114
- if (!match) {
115
- return;
116
- }
117
- var decorations = decorationSet.find(match.start, match.end);
118
- return decorations.length ? decorations.find(
119
- // decorationSet.find() returns any decorations that touch the specifided
120
- // positions, but we want to be stricter
121
- function (decoration) {
122
- return decoration.from === match.start && decoration.to === match.end;
123
- }) : undefined;
124
- };
125
- export var removeDecorationsFromSet = function removeDecorationsFromSet(decorationSet, decorationsToRemove, doc) {
126
- var prevDecorations = decorationSet.find();
127
-
128
- // it is essential that we copy the decorations otherwise in some rare cases
129
- // prosemirror-view will update our decorationsToRemove array to contain nulls
130
- // instead of Decorations which ruins our check for lost decorations below
131
- decorationSet = decorationSet.remove(decorationsToRemove.map(function (decoration) {
132
- return (
133
- // copy exists but isn't on the type definition
134
- decoration.copy(decoration.from, decoration.to)
135
- );
136
- }));
137
- var newDecorations = decorationSet.find();
138
-
139
- // there is a bug in prosemirror-view where it can't cope with deleting inline
140
- // decorations from a set in some cases (where there are multiple levels of nested
141
- // children arrays), and it deletes more decorations than it should
142
- // todo: ticket link
143
- var lostDecorations = findLostAdjacentDecorations(decorationsToRemove, prevDecorations, newDecorations);
144
- if (lostDecorations.length > 0) {
145
- decorationSet = decorationSet.add(doc, lostDecorations);
146
- }
147
- return decorationSet;
148
- };
149
- export var removeMatchesFromSet = function removeMatchesFromSet(decorationSet, matches, doc) {
150
- var decorationsToRemove = matches.filter(function (match) {
151
- return !!match;
152
- }).map(function (match) {
153
- return findDecorationFromMatch(decorationSet, match);
154
- });
155
- decorationsToRemove.forEach(function (decoration) {
156
- if (decoration) {
157
- decorationSet = removeDecorationsFromSet(decorationSet, [decoration], doc);
158
- }
159
- });
160
- return decorationSet;
161
- };
162
-
163
- /**
164
- * Finds decorations in prevDecorations that are not in newDecorations or decorationsToRemove
165
- * These decorations have been lost by Prosemirror during an over eager decoration removal
166
- * We need to be smart to cope with thousands of decorations without crashing everything
167
- */
168
- export var findLostAdjacentDecorations = function findLostAdjacentDecorations(decorationsToRemove, prevDecorations, newDecorations) {
169
- var lostDecorations = [];
170
- if (prevDecorations.length - decorationsToRemove.length > newDecorations.length) {
171
- var position = decorationsToRemove.length > 0 ? decorationsToRemove[0].from : 0;
172
- var prevDecorationsStartIdx = findIndexBeforePosition(prevDecorations, position);
173
- var newDecorationsStartIdx = findIndexBeforePosition(newDecorations, position);
174
- var startIdx = Math.min(prevDecorationsStartIdx, newDecorationsStartIdx);
175
- var prevDecorationsToCheck = prevDecorations.slice(startIdx);
176
- var newDecorationsToCheck = newDecorations.slice(startIdx);
177
- var uniqueInPrev = [];
178
- var numToFind = prevDecorationsToCheck.length - newDecorationsToCheck.length;
179
- var foundAll = false;
180
- var newDecorationsIdxOffset = 0;
181
- var _loop = function _loop() {
182
- var prevDecoration = prevDecorationsToCheck[i];
183
- // this was a legit removal, skip and continue
184
- if (decorationsToRemove.find(function (decoration) {
185
- return decoration.from === prevDecoration.from;
186
- })) {
187
- newDecorationsIdxOffset -= 1;
188
- return 0; // continue
189
- }
190
- var j = i + newDecorationsIdxOffset;
191
-
192
- // this is a lost decoration
193
- if (j >= newDecorationsToCheck.length) {
194
- uniqueInPrev.push(prevDecoration);
195
- if (uniqueInPrev.length === numToFind) {
196
- foundAll = true;
197
- }
198
- }
199
- for (; j < newDecorationsToCheck.length; j++) {
200
- var newDecoration = newDecorationsToCheck[j];
201
-
202
- // decoration found in both arrays, skip and continue
203
- if (prevDecoration.from === newDecoration.from) {
204
- break;
205
- }
206
-
207
- // this is a lost decoration
208
- if (newDecoration.from > prevDecoration.from || j === newDecorationsToCheck.length - 1) {
209
- uniqueInPrev.push(prevDecoration);
210
- newDecorationsIdxOffset -= 1;
211
- if (uniqueInPrev.length === numToFind) {
212
- foundAll = true;
213
- }
214
- break;
215
- }
216
- }
217
- if (foundAll) {
218
- return 1; // break
219
- }
220
- },
221
- _ret;
222
- for (var i = 0; i < prevDecorationsToCheck.length; i++) {
223
- _ret = _loop();
224
- if (_ret === 0) continue;
225
- if (_ret === 1) break;
226
- }
227
-
228
- // make sure we ignore any that we wanted to delete
229
- lostDecorations = uniqueInPrev.filter(function (decoration) {
230
- return !decorationsToRemove.find(function (decorationToRemove) {
231
- return decoration.from === decorationToRemove.from;
232
- });
233
- });
234
- }
235
- return lostDecorations;
236
- };
237
-
238
- /**
239
- * Searches through array in bumps of 100 to return the index of the first
240
- * decoration whose 'from' value is before or equal to the position
241
- */
242
- export var findIndexBeforePosition = function findIndexBeforePosition(items, position) {
243
- // jump in batches to cope with arrays with thousands of decorations
244
- var increment = 100;
245
- var index = 0;
246
- for (var i = items.length - 1; i >= 0; i -= increment) {
247
- if (items[i].from < position) {
248
- // now we have found the 100 range, we can narrow it down to exact index
249
- index = i;
250
- for (var j = i; j <= items.length - 1; j++) {
251
- if (items[j].from <= position) {
252
- index = j;
253
- } else {
254
- break;
255
- }
256
- }
257
- break;
258
- }
259
- if (i < 100 && i > 0) {
260
- i = 100;
261
- }
262
- }
263
- return index;
264
- };
265
-
266
- /**
267
- * Determines whether a find/replace text Match will be changed as a result
268
- * of a Step modification to the document. This is evaluated by checking
269
- * both mapped and unmapped versions of the Step as in different cases the
270
- * matches will match.
271
- *
272
- * **Note:** Match state received here is after step has been applied.
273
- */
274
- export var isMatchAffectedByStep = function isMatchAffectedByStep(match, step, tr) {
275
- var from = step.from,
276
- to = step.to,
277
- slice = step.slice;
278
- var sliceSize = slice.content.size;
279
- return from + sliceSize >= match.start && to - sliceSize <= match.end || tr.mapping.map(from) + sliceSize >= match.start && tr.mapping.map(to) - sliceSize <= match.end;
280
- };
@@ -1,7 +0,0 @@
1
- export function findUniqueItemsIn(findIn, checkWith, comparator) {
2
- return findIn.filter(function (firstItem) {
3
- return checkWith.findIndex(function (secondItem) {
4
- return comparator ? comparator(firstItem, secondItem) : firstItem === secondItem;
5
- }) === -1;
6
- });
7
- }
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- import type { FindReplaceToolbarButtonWithStateProps } from './types';
3
- declare const _default: React.MemoExoticComponent<({ popupsBoundariesElement, popupsMountPoint, popupsScrollableElement, isToolbarReducedSpacing, editorView, containerElement, dispatchAnalyticsEvent, featureFlags, takeFullWidth, api, }: FindReplaceToolbarButtonWithStateProps) => JSX.Element | null>;
4
- export default _default;
@@ -1,64 +0,0 @@
1
- import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
- import type { Match } from './types';
3
- export declare enum FindReplaceActionTypes {
4
- ACTIVATE = "ACTIVATE",
5
- FIND = "FIND",
6
- UPDATE_DECORATIONS = "UPDATE_DECORATIONS",
7
- FIND_NEXT = "FIND_NEXT",
8
- FIND_PREVIOUS = "FIND_PREVIOUS",
9
- REPLACE = "REPLACE",
10
- REPLACE_ALL = "REPLACE_ALL",
11
- CANCEL = "CANCEL",
12
- BLUR = "BLUR",
13
- TOGGLE_MATCH_CASE = "TOGGLE_MATCH_CASE"
14
- }
15
- export interface Activate {
16
- type: FindReplaceActionTypes.ACTIVATE;
17
- findText?: string;
18
- matches?: Match[];
19
- index?: number;
20
- }
21
- export interface Find {
22
- type: FindReplaceActionTypes.FIND;
23
- findText: string;
24
- matches: Match[];
25
- index: number;
26
- }
27
- export interface FindNext {
28
- type: FindReplaceActionTypes.FIND_NEXT;
29
- index: number;
30
- decorationSet: DecorationSet;
31
- }
32
- export interface FindPrevious {
33
- type: FindReplaceActionTypes.FIND_PREVIOUS;
34
- index: number;
35
- decorationSet: DecorationSet;
36
- }
37
- export interface Replace {
38
- type: FindReplaceActionTypes.REPLACE;
39
- replaceText: string;
40
- decorationSet: DecorationSet;
41
- matches: Match[];
42
- index: number;
43
- }
44
- export interface ReplaceAll {
45
- type: FindReplaceActionTypes.REPLACE_ALL;
46
- replaceText: string;
47
- decorationSet: DecorationSet;
48
- matches: Match[];
49
- index: number;
50
- }
51
- export interface Cancel {
52
- type: FindReplaceActionTypes.CANCEL;
53
- }
54
- export interface Blur {
55
- type: FindReplaceActionTypes.BLUR;
56
- }
57
- export interface UpdateDecorations {
58
- type: FindReplaceActionTypes.UPDATE_DECORATIONS;
59
- decorationSet: DecorationSet;
60
- }
61
- export interface ToggleMatchCase {
62
- type: FindReplaceActionTypes.TOGGLE_MATCH_CASE;
63
- }
64
- export type FindReplaceAction = Activate | Find | FindNext | FindPrevious | Replace | ReplaceAll | Cancel | Blur | UpdateDecorations | ToggleMatchCase;