@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,290 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.findLostAdjacentDecorations = exports.findIndexBeforePosition = exports.findDecorationFromMatch = exports.createDecorations = exports.createDecoration = void 0;
7
- exports.findMatches = findMatches;
8
- exports.findSearchIndex = findSearchIndex;
9
- exports.getSelectedText = getSelectedText;
10
- exports.removeMatchesFromSet = exports.removeDecorationsFromSet = exports.prevIndex = exports.nextIndex = exports.isMatchAffectedByStep = exports.getSelectionForMatch = void 0;
11
- var _view = require("@atlaskit/editor-prosemirror/view");
12
- var _state = require("@atlaskit/editor-prosemirror/state");
13
- var _styles = require("../styles");
14
- function getSelectedText(selection) {
15
- var text = '';
16
- var selectedContent = selection.content().content;
17
- for (var i = 0; i < selectedContent.childCount; i++) {
18
- text += selectedContent.child(i).textContent;
19
- }
20
- return text;
21
- }
22
- var createDecorations = exports.createDecorations = function createDecorations(selectedIndex, matches) {
23
- return matches.map(function (_ref, i) {
24
- var start = _ref.start,
25
- end = _ref.end;
26
- return createDecoration(start, end, i === selectedIndex);
27
- });
28
- };
29
- var createDecoration = exports.createDecoration = function createDecoration(start, end, isSelected) {
30
- var className = _styles.searchMatchClass;
31
- if (isSelected) {
32
- className += " ".concat(_styles.selectedSearchMatchClass);
33
- }
34
- return _view.Decoration.inline(start, end, {
35
- class: className
36
- });
37
- };
38
- function findMatches(content, searchText, shouldMatchCase) {
39
- var contentIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
40
- var matches = [];
41
- var searchTextLength = searchText.length;
42
- var textGrouping = null;
43
- var collectMatch = function collectMatch(textGrouping) {
44
- if (!textGrouping) {
45
- return;
46
- }
47
- var text = textGrouping.text,
48
- relativePos = textGrouping.pos;
49
- var pos = contentIndex + relativePos;
50
- if (!shouldMatchCase) {
51
- searchText = searchText.toLowerCase();
52
- text = text.toLowerCase();
53
- }
54
- var index = text.indexOf(searchText);
55
- while (index !== -1) {
56
- // Find the next substring from the end of the first, so that they don't overlap
57
- var end = index + searchTextLength;
58
- // Add the substring index to the position of the node
59
- matches.push({
60
- start: pos + index,
61
- end: pos + end
62
- });
63
- index = text.indexOf(searchText, end);
64
- }
65
- };
66
- if (searchTextLength > 0) {
67
- content.descendants(function (node, pos) {
68
- if (node.isText) {
69
- if (textGrouping === null) {
70
- textGrouping = {
71
- text: node.text,
72
- pos: pos
73
- };
74
- } else {
75
- textGrouping.text = textGrouping.text + node.text;
76
- }
77
- } else {
78
- collectMatch(textGrouping);
79
- textGrouping = null;
80
- }
81
- });
82
- // if there's a dangling text grouping and no non-text node to trigger collectMatch, manually collectMatch
83
- if (textGrouping) {
84
- collectMatch(textGrouping);
85
- }
86
- }
87
- return matches;
88
- }
89
-
90
- /**
91
- * Finds index of first item in matches array that comes after user's cursor pos.
92
- * If `backward` is `true`, finds index of first item that comes before instead.
93
- */
94
- function findSearchIndex(selectionPos, matches) {
95
- var backward = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
96
- if (backward) {
97
- var matchIndex = matches.findIndex(function (match) {
98
- return match.start >= selectionPos;
99
- }) - 1;
100
- if (matchIndex < 0) {
101
- matchIndex = matches.length - 1; // wrap around from the end
102
- }
103
-
104
- return matchIndex;
105
- }
106
- return Math.max(matches.findIndex(function (match) {
107
- return match.start >= selectionPos;
108
- }), 0);
109
- }
110
- var nextIndex = exports.nextIndex = function nextIndex(currentIndex, total) {
111
- return (currentIndex + 1) % total;
112
- };
113
- var prevIndex = exports.prevIndex = function prevIndex(currentIndex, total) {
114
- return (currentIndex - 1 + total) % total;
115
- };
116
- var getSelectionForMatch = exports.getSelectionForMatch = function getSelectionForMatch(selection, doc, index, matches) {
117
- var offset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
118
- if (matches[index]) {
119
- return _state.TextSelection.create(doc, matches[index].start + offset);
120
- }
121
- return selection;
122
- };
123
- var findDecorationFromMatch = exports.findDecorationFromMatch = function findDecorationFromMatch(decorationSet, match) {
124
- if (!match) {
125
- return;
126
- }
127
- var decorations = decorationSet.find(match.start, match.end);
128
- return decorations.length ? decorations.find(
129
- // decorationSet.find() returns any decorations that touch the specifided
130
- // positions, but we want to be stricter
131
- function (decoration) {
132
- return decoration.from === match.start && decoration.to === match.end;
133
- }) : undefined;
134
- };
135
- var removeDecorationsFromSet = exports.removeDecorationsFromSet = function removeDecorationsFromSet(decorationSet, decorationsToRemove, doc) {
136
- var prevDecorations = decorationSet.find();
137
-
138
- // it is essential that we copy the decorations otherwise in some rare cases
139
- // prosemirror-view will update our decorationsToRemove array to contain nulls
140
- // instead of Decorations which ruins our check for lost decorations below
141
- decorationSet = decorationSet.remove(decorationsToRemove.map(function (decoration) {
142
- return (
143
- // copy exists but isn't on the type definition
144
- decoration.copy(decoration.from, decoration.to)
145
- );
146
- }));
147
- var newDecorations = decorationSet.find();
148
-
149
- // there is a bug in prosemirror-view where it can't cope with deleting inline
150
- // decorations from a set in some cases (where there are multiple levels of nested
151
- // children arrays), and it deletes more decorations than it should
152
- // todo: ticket link
153
- var lostDecorations = findLostAdjacentDecorations(decorationsToRemove, prevDecorations, newDecorations);
154
- if (lostDecorations.length > 0) {
155
- decorationSet = decorationSet.add(doc, lostDecorations);
156
- }
157
- return decorationSet;
158
- };
159
- var removeMatchesFromSet = exports.removeMatchesFromSet = function removeMatchesFromSet(decorationSet, matches, doc) {
160
- var decorationsToRemove = matches.filter(function (match) {
161
- return !!match;
162
- }).map(function (match) {
163
- return findDecorationFromMatch(decorationSet, match);
164
- });
165
- decorationsToRemove.forEach(function (decoration) {
166
- if (decoration) {
167
- decorationSet = removeDecorationsFromSet(decorationSet, [decoration], doc);
168
- }
169
- });
170
- return decorationSet;
171
- };
172
-
173
- /**
174
- * Finds decorations in prevDecorations that are not in newDecorations or decorationsToRemove
175
- * These decorations have been lost by Prosemirror during an over eager decoration removal
176
- * We need to be smart to cope with thousands of decorations without crashing everything
177
- */
178
- var findLostAdjacentDecorations = exports.findLostAdjacentDecorations = function findLostAdjacentDecorations(decorationsToRemove, prevDecorations, newDecorations) {
179
- var lostDecorations = [];
180
- if (prevDecorations.length - decorationsToRemove.length > newDecorations.length) {
181
- var position = decorationsToRemove.length > 0 ? decorationsToRemove[0].from : 0;
182
- var prevDecorationsStartIdx = findIndexBeforePosition(prevDecorations, position);
183
- var newDecorationsStartIdx = findIndexBeforePosition(newDecorations, position);
184
- var startIdx = Math.min(prevDecorationsStartIdx, newDecorationsStartIdx);
185
- var prevDecorationsToCheck = prevDecorations.slice(startIdx);
186
- var newDecorationsToCheck = newDecorations.slice(startIdx);
187
- var uniqueInPrev = [];
188
- var numToFind = prevDecorationsToCheck.length - newDecorationsToCheck.length;
189
- var foundAll = false;
190
- var newDecorationsIdxOffset = 0;
191
- var _loop = function _loop() {
192
- var prevDecoration = prevDecorationsToCheck[i];
193
- // this was a legit removal, skip and continue
194
- if (decorationsToRemove.find(function (decoration) {
195
- return decoration.from === prevDecoration.from;
196
- })) {
197
- newDecorationsIdxOffset -= 1;
198
- return 0; // continue
199
- }
200
- var j = i + newDecorationsIdxOffset;
201
-
202
- // this is a lost decoration
203
- if (j >= newDecorationsToCheck.length) {
204
- uniqueInPrev.push(prevDecoration);
205
- if (uniqueInPrev.length === numToFind) {
206
- foundAll = true;
207
- }
208
- }
209
- for (; j < newDecorationsToCheck.length; j++) {
210
- var newDecoration = newDecorationsToCheck[j];
211
-
212
- // decoration found in both arrays, skip and continue
213
- if (prevDecoration.from === newDecoration.from) {
214
- break;
215
- }
216
-
217
- // this is a lost decoration
218
- if (newDecoration.from > prevDecoration.from || j === newDecorationsToCheck.length - 1) {
219
- uniqueInPrev.push(prevDecoration);
220
- newDecorationsIdxOffset -= 1;
221
- if (uniqueInPrev.length === numToFind) {
222
- foundAll = true;
223
- }
224
- break;
225
- }
226
- }
227
- if (foundAll) {
228
- return 1; // break
229
- }
230
- },
231
- _ret;
232
- for (var i = 0; i < prevDecorationsToCheck.length; i++) {
233
- _ret = _loop();
234
- if (_ret === 0) continue;
235
- if (_ret === 1) break;
236
- }
237
-
238
- // make sure we ignore any that we wanted to delete
239
- lostDecorations = uniqueInPrev.filter(function (decoration) {
240
- return !decorationsToRemove.find(function (decorationToRemove) {
241
- return decoration.from === decorationToRemove.from;
242
- });
243
- });
244
- }
245
- return lostDecorations;
246
- };
247
-
248
- /**
249
- * Searches through array in bumps of 100 to return the index of the first
250
- * decoration whose 'from' value is before or equal to the position
251
- */
252
- var findIndexBeforePosition = exports.findIndexBeforePosition = function findIndexBeforePosition(items, position) {
253
- // jump in batches to cope with arrays with thousands of decorations
254
- var increment = 100;
255
- var index = 0;
256
- for (var i = items.length - 1; i >= 0; i -= increment) {
257
- if (items[i].from < position) {
258
- // now we have found the 100 range, we can narrow it down to exact index
259
- index = i;
260
- for (var j = i; j <= items.length - 1; j++) {
261
- if (items[j].from <= position) {
262
- index = j;
263
- } else {
264
- break;
265
- }
266
- }
267
- break;
268
- }
269
- if (i < 100 && i > 0) {
270
- i = 100;
271
- }
272
- }
273
- return index;
274
- };
275
-
276
- /**
277
- * Determines whether a find/replace text Match will be changed as a result
278
- * of a Step modification to the document. This is evaluated by checking
279
- * both mapped and unmapped versions of the Step as in different cases the
280
- * matches will match.
281
- *
282
- * **Note:** Match state received here is after step has been applied.
283
- */
284
- var isMatchAffectedByStep = exports.isMatchAffectedByStep = function isMatchAffectedByStep(match, step, tr) {
285
- var from = step.from,
286
- to = step.to,
287
- slice = step.slice;
288
- var sliceSize = slice.content.size;
289
- return from + sliceSize >= match.start && to - sliceSize <= match.end || tr.mapping.map(from) + sliceSize >= match.start && tr.mapping.map(to) - sliceSize <= match.end;
290
- };
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.findUniqueItemsIn = findUniqueItemsIn;
7
- function findUniqueItemsIn(findIn, checkWith, comparator) {
8
- return findIn.filter(function (firstItem) {
9
- return checkWith.findIndex(function (secondItem) {
10
- return comparator ? comparator(firstItem, secondItem) : firstItem === secondItem;
11
- }) === -1;
12
- });
13
- }
@@ -1,153 +0,0 @@
1
- import React, { useState, useLayoutEffect } from 'react';
2
- import { cancelSearchWithAnalytics, replaceWithAnalytics, replaceAllWithAnalytics, findWithAnalytics, findNextWithAnalytics, findPrevWithAnalytics, activateWithAnalytics } from './commands-with-analytics';
3
- import { blur, toggleMatchCase } from './commands';
4
- import FindReplaceToolbarButton from './ui/FindReplaceToolbarButton';
5
- import { TRIGGER_METHOD } from '@atlaskit/editor-common/analytics';
6
-
7
- // light implementation of useSharedPluginState(). This is due to findreplace
8
- // being the only plugin that previously used WithPluginState with
9
- // debounce=false. That was implemented because of text sync issues
10
- // between editor & findreplace dialog.
11
- // To address under ENGHEALTH-5853
12
- const useSharedPluginStateNoDebounce = api => {
13
- const [state, setState] = useState(api === null || api === void 0 ? void 0 : api.findReplace.sharedState.currentState());
14
- useLayoutEffect(() => {
15
- const unsub = api === null || api === void 0 ? void 0 : api.findReplace.sharedState.onChange(({
16
- nextSharedState
17
- }) => {
18
- setState(nextSharedState);
19
- });
20
- return () => {
21
- unsub === null || unsub === void 0 ? void 0 : unsub();
22
- };
23
- }, [api]);
24
- return {
25
- findReplaceState: state
26
- };
27
- };
28
- const FindReplaceToolbarButtonWithState = ({
29
- popupsBoundariesElement,
30
- popupsMountPoint,
31
- popupsScrollableElement,
32
- isToolbarReducedSpacing,
33
- editorView,
34
- containerElement,
35
- dispatchAnalyticsEvent,
36
- featureFlags,
37
- takeFullWidth,
38
- api
39
- }) => {
40
- var _api$analytics;
41
- const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
42
- const {
43
- findReplaceState
44
- } = useSharedPluginStateNoDebounce(api);
45
- if (!editorView) {
46
- return null;
47
- }
48
-
49
- // we need the editor to be in focus for scrollIntoView() to work
50
- // so we focus it while we run the command, then put focus back into
51
- // whatever element was previously focused in find replace component
52
- const runWithEditorFocused = fn => {
53
- const activeElement = document.activeElement;
54
- editorView.focus();
55
- fn();
56
- activeElement === null || activeElement === void 0 ? void 0 : activeElement.focus();
57
- };
58
- const dispatchCommand = cmd => {
59
- const {
60
- state,
61
- dispatch
62
- } = editorView;
63
- cmd(state, dispatch);
64
- };
65
- const handleActivate = () => {
66
- runWithEditorFocused(() => dispatchCommand(activateWithAnalytics(editorAnalyticsAPI)({
67
- triggerMethod: TRIGGER_METHOD.TOOLBAR
68
- })));
69
- };
70
- const handleFind = keyword => {
71
- runWithEditorFocused(() => dispatchCommand(findWithAnalytics(editorAnalyticsAPI)({
72
- editorView,
73
- containerElement,
74
- keyword
75
- })));
76
- };
77
- const handleFindNext = ({
78
- triggerMethod
79
- }) => {
80
- runWithEditorFocused(() => dispatchCommand(findNextWithAnalytics(editorAnalyticsAPI)({
81
- triggerMethod
82
- })));
83
- };
84
- const handleFindPrev = ({
85
- triggerMethod
86
- }) => {
87
- runWithEditorFocused(() => dispatchCommand(findPrevWithAnalytics(editorAnalyticsAPI)({
88
- triggerMethod
89
- })));
90
- };
91
- const handleReplace = ({
92
- triggerMethod,
93
- replaceText
94
- }) => {
95
- runWithEditorFocused(() => dispatchCommand(replaceWithAnalytics(editorAnalyticsAPI)({
96
- triggerMethod,
97
- replaceText
98
- })));
99
- };
100
- const handleReplaceAll = ({
101
- replaceText
102
- }) => {
103
- runWithEditorFocused(() => dispatchCommand(replaceAllWithAnalytics(editorAnalyticsAPI)({
104
- replaceText
105
- })));
106
- };
107
- const handleFindBlur = () => {
108
- dispatchCommand(blur());
109
- };
110
- const handleCancel = ({
111
- triggerMethod
112
- }) => {
113
- dispatchCommand(cancelSearchWithAnalytics(editorAnalyticsAPI)({
114
- triggerMethod
115
- }));
116
- editorView.focus();
117
- };
118
- const handleToggleMatchCase = () => {
119
- dispatchCommand(toggleMatchCase());
120
- };
121
- const {
122
- findReplaceMatchCase
123
- } = featureFlags;
124
- if (!findReplaceState) {
125
- return null;
126
- }
127
- return /*#__PURE__*/React.createElement(FindReplaceToolbarButton, {
128
- allowMatchCase: findReplaceMatchCase,
129
- shouldMatchCase: findReplaceState.shouldMatchCase,
130
- onToggleMatchCase: handleToggleMatchCase,
131
- isActive: findReplaceState.isActive,
132
- findText: findReplaceState.findText,
133
- index: findReplaceState.index,
134
- numMatches: findReplaceState.matches.length,
135
- replaceText: findReplaceState.replaceText,
136
- shouldFocus: findReplaceState.shouldFocus,
137
- popupsBoundariesElement: popupsBoundariesElement,
138
- popupsMountPoint: popupsMountPoint,
139
- popupsScrollableElement: popupsScrollableElement,
140
- isReducedSpacing: !!isToolbarReducedSpacing,
141
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
142
- onFindBlur: handleFindBlur,
143
- onCancel: handleCancel,
144
- onActivate: handleActivate,
145
- onFind: handleFind,
146
- onFindNext: handleFindNext,
147
- onFindPrev: handleFindPrev,
148
- onReplace: handleReplace,
149
- onReplaceAll: handleReplaceAll,
150
- takeFullWidth: !!takeFullWidth
151
- });
152
- };
153
- export default /*#__PURE__*/React.memo(FindReplaceToolbarButtonWithState);
@@ -1,13 +0,0 @@
1
- export let FindReplaceActionTypes = /*#__PURE__*/function (FindReplaceActionTypes) {
2
- FindReplaceActionTypes["ACTIVATE"] = "ACTIVATE";
3
- FindReplaceActionTypes["FIND"] = "FIND";
4
- FindReplaceActionTypes["UPDATE_DECORATIONS"] = "UPDATE_DECORATIONS";
5
- FindReplaceActionTypes["FIND_NEXT"] = "FIND_NEXT";
6
- FindReplaceActionTypes["FIND_PREVIOUS"] = "FIND_PREVIOUS";
7
- FindReplaceActionTypes["REPLACE"] = "REPLACE";
8
- FindReplaceActionTypes["REPLACE_ALL"] = "REPLACE_ALL";
9
- FindReplaceActionTypes["CANCEL"] = "CANCEL";
10
- FindReplaceActionTypes["BLUR"] = "BLUR";
11
- FindReplaceActionTypes["TOGGLE_MATCH_CASE"] = "TOGGLE_MATCH_CASE";
12
- return FindReplaceActionTypes;
13
- }({});
@@ -1,72 +0,0 @@
1
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
2
- import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
- import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
4
- import { activate, find, findNext, findPrevious, replace, replaceAll, cancelSearch } from './commands';
5
- export const activateWithAnalytics = editorAnalyticsAPI => ({
6
- triggerMethod
7
- }) => withAnalytics(editorAnalyticsAPI, state => ({
8
- eventType: EVENT_TYPE.UI,
9
- action: ACTION.ACTIVATED,
10
- actionSubject: ACTION_SUBJECT.FIND_REPLACE_DIALOG,
11
- attributes: {
12
- inputMethod: state.selection instanceof TextSelection && !state.selection.empty ? INPUT_METHOD.PREFILL : INPUT_METHOD.KEYBOARD,
13
- triggerMethod
14
- }
15
- }))(activate());
16
- export const findWithAnalytics = editorAnalyticsAPI => ({
17
- editorView,
18
- containerElement,
19
- keyword
20
- }) => withAnalytics(editorAnalyticsAPI, {
21
- eventType: EVENT_TYPE.TRACK,
22
- action: ACTION.FIND_PERFORMED,
23
- actionSubject: ACTION_SUBJECT.TEXT
24
- })(find(editorView, containerElement, keyword));
25
- export const findNextWithAnalytics = editorAnalyticsAPI => ({
26
- triggerMethod
27
- }) => withAnalytics(editorAnalyticsAPI, {
28
- eventType: EVENT_TYPE.TRACK,
29
- action: ACTION.FIND_NEXT_PERFORMED,
30
- actionSubject: ACTION_SUBJECT.TEXT,
31
- attributes: {
32
- triggerMethod
33
- }
34
- })(findNext());
35
- export const findPrevWithAnalytics = editorAnalyticsAPI => ({
36
- triggerMethod
37
- }) => withAnalytics(editorAnalyticsAPI, {
38
- eventType: EVENT_TYPE.TRACK,
39
- action: ACTION.FIND_PREV_PERFORMED,
40
- actionSubject: ACTION_SUBJECT.TEXT,
41
- attributes: {
42
- triggerMethod
43
- }
44
- })(findPrevious());
45
- export const replaceWithAnalytics = editorAnalyticsAPI => ({
46
- triggerMethod,
47
- replaceText
48
- }) => withAnalytics(editorAnalyticsAPI, {
49
- eventType: EVENT_TYPE.TRACK,
50
- action: ACTION.REPLACED_ONE,
51
- actionSubject: ACTION_SUBJECT.TEXT,
52
- attributes: {
53
- triggerMethod
54
- }
55
- })(replace(replaceText));
56
- export const replaceAllWithAnalytics = editorAnalyticsAPI => ({
57
- replaceText
58
- }) => withAnalytics(editorAnalyticsAPI, {
59
- eventType: EVENT_TYPE.TRACK,
60
- action: ACTION.REPLACED_ALL,
61
- actionSubject: ACTION_SUBJECT.TEXT
62
- })(replaceAll(replaceText));
63
- export const cancelSearchWithAnalytics = editorAnalyticsAPI => ({
64
- triggerMethod
65
- }) => withAnalytics(editorAnalyticsAPI, {
66
- eventType: EVENT_TYPE.UI,
67
- action: ACTION.DEACTIVATED,
68
- actionSubject: ACTION_SUBJECT.FIND_REPLACE_DIALOG,
69
- attributes: {
70
- triggerMethod
71
- }
72
- })(cancelSearch());