@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,95 +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 var activateWithAnalytics = function activateWithAnalytics(editorAnalyticsAPI) {
6
- return function (_ref) {
7
- var triggerMethod = _ref.triggerMethod;
8
- return withAnalytics(editorAnalyticsAPI, function (state) {
9
- return {
10
- eventType: EVENT_TYPE.UI,
11
- action: ACTION.ACTIVATED,
12
- actionSubject: ACTION_SUBJECT.FIND_REPLACE_DIALOG,
13
- attributes: {
14
- inputMethod: state.selection instanceof TextSelection && !state.selection.empty ? INPUT_METHOD.PREFILL : INPUT_METHOD.KEYBOARD,
15
- triggerMethod: triggerMethod
16
- }
17
- };
18
- })(activate());
19
- };
20
- };
21
- export var findWithAnalytics = function findWithAnalytics(editorAnalyticsAPI) {
22
- return function (_ref2) {
23
- var editorView = _ref2.editorView,
24
- containerElement = _ref2.containerElement,
25
- keyword = _ref2.keyword;
26
- return withAnalytics(editorAnalyticsAPI, {
27
- eventType: EVENT_TYPE.TRACK,
28
- action: ACTION.FIND_PERFORMED,
29
- actionSubject: ACTION_SUBJECT.TEXT
30
- })(find(editorView, containerElement, keyword));
31
- };
32
- };
33
- export var findNextWithAnalytics = function findNextWithAnalytics(editorAnalyticsAPI) {
34
- return function (_ref3) {
35
- var triggerMethod = _ref3.triggerMethod;
36
- return withAnalytics(editorAnalyticsAPI, {
37
- eventType: EVENT_TYPE.TRACK,
38
- action: ACTION.FIND_NEXT_PERFORMED,
39
- actionSubject: ACTION_SUBJECT.TEXT,
40
- attributes: {
41
- triggerMethod: triggerMethod
42
- }
43
- })(findNext());
44
- };
45
- };
46
- export var findPrevWithAnalytics = function findPrevWithAnalytics(editorAnalyticsAPI) {
47
- return function (_ref4) {
48
- var triggerMethod = _ref4.triggerMethod;
49
- return withAnalytics(editorAnalyticsAPI, {
50
- eventType: EVENT_TYPE.TRACK,
51
- action: ACTION.FIND_PREV_PERFORMED,
52
- actionSubject: ACTION_SUBJECT.TEXT,
53
- attributes: {
54
- triggerMethod: triggerMethod
55
- }
56
- })(findPrevious());
57
- };
58
- };
59
- export var replaceWithAnalytics = function replaceWithAnalytics(editorAnalyticsAPI) {
60
- return function (_ref5) {
61
- var triggerMethod = _ref5.triggerMethod,
62
- replaceText = _ref5.replaceText;
63
- return withAnalytics(editorAnalyticsAPI, {
64
- eventType: EVENT_TYPE.TRACK,
65
- action: ACTION.REPLACED_ONE,
66
- actionSubject: ACTION_SUBJECT.TEXT,
67
- attributes: {
68
- triggerMethod: triggerMethod
69
- }
70
- })(replace(replaceText));
71
- };
72
- };
73
- export var replaceAllWithAnalytics = function replaceAllWithAnalytics(editorAnalyticsAPI) {
74
- return function (_ref6) {
75
- var replaceText = _ref6.replaceText;
76
- return withAnalytics(editorAnalyticsAPI, {
77
- eventType: EVENT_TYPE.TRACK,
78
- action: ACTION.REPLACED_ALL,
79
- actionSubject: ACTION_SUBJECT.TEXT
80
- })(replaceAll(replaceText));
81
- };
82
- };
83
- export var cancelSearchWithAnalytics = function cancelSearchWithAnalytics(editorAnalyticsAPI) {
84
- return function (_ref7) {
85
- var triggerMethod = _ref7.triggerMethod;
86
- return withAnalytics(editorAnalyticsAPI, {
87
- eventType: EVENT_TYPE.UI,
88
- action: ACTION.DEACTIVATED,
89
- actionSubject: ACTION_SUBJECT.FIND_REPLACE_DIALOG,
90
- attributes: {
91
- triggerMethod: triggerMethod
92
- }
93
- })(cancelSearch());
94
- };
95
- };
@@ -1,248 +0,0 @@
1
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
2
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
3
- import { createCommand, getPluginState } from './plugin';
4
- import { FindReplaceActionTypes } from './actions';
5
- import { findMatches, findSearchIndex, getSelectedText, createDecoration, nextIndex, prevIndex, findDecorationFromMatch, removeDecorationsFromSet, getSelectionForMatch, removeMatchesFromSet } from './utils';
6
- import { withScrollIntoView } from './utils/commands';
7
- import batchDecorations from './utils/batch-decorations';
8
- export var activate = function activate() {
9
- return createCommand(function (state) {
10
- var selection = state.selection;
11
- var findText;
12
- var matches;
13
- var index;
14
-
15
- // if user has selected text and hit cmd-f, set that as the keyword
16
- if (selection instanceof TextSelection && !selection.empty) {
17
- findText = getSelectedText(selection);
18
- var _getPluginState = getPluginState(state),
19
- shouldMatchCase = _getPluginState.shouldMatchCase;
20
- matches = findMatches(state.doc, findText, shouldMatchCase);
21
- index = findSearchIndex(selection.from, matches);
22
- }
23
- return {
24
- type: FindReplaceActionTypes.ACTIVATE,
25
- findText: findText,
26
- matches: matches,
27
- index: index
28
- };
29
- });
30
- };
31
- export var find = function find(editorView, containerElement, keyword) {
32
- return withScrollIntoView(createCommand(function (state) {
33
- var selection = state.selection;
34
- var _getPluginState2 = getPluginState(state),
35
- shouldMatchCase = _getPluginState2.shouldMatchCase;
36
- var matches = keyword !== undefined ? findMatches(state.doc, keyword, shouldMatchCase) : [];
37
- var index = findSearchIndex(selection.from, matches);
38
-
39
- // we can't just apply all the decorations to highlight the search results at once
40
- // as if there are a lot ProseMirror cries :'(
41
- batchDecorations.applyAllSearchDecorations(editorView, containerElement, function (decorations) {
42
- return addDecorations(decorations)(editorView.state, editorView.dispatch);
43
- }, function (decorations) {
44
- return removeDecorations(decorations)(editorView.state, editorView.dispatch);
45
- });
46
- return {
47
- type: FindReplaceActionTypes.FIND,
48
- findText: keyword || '',
49
- matches: matches,
50
- index: index
51
- };
52
- }, function (tr, state) {
53
- var selection = state.selection;
54
- var _getPluginState3 = getPluginState(state),
55
- shouldMatchCase = _getPluginState3.shouldMatchCase;
56
- var matches = keyword !== undefined ? findMatches(state.doc, keyword, shouldMatchCase) : [];
57
- if (matches.length > 0) {
58
- var index = findSearchIndex(selection.from, matches);
59
- return tr.setSelection(getSelectionForMatch(tr.selection, tr.doc, index, matches));
60
- }
61
- return tr;
62
- }));
63
- };
64
- export var findNext = function findNext() {
65
- return withScrollIntoView(createCommand(function (state) {
66
- return findInDirection(state, 'next');
67
- }, function (tr, state) {
68
- var _getPluginState4 = getPluginState(state),
69
- matches = _getPluginState4.matches,
70
- index = _getPluginState4.index;
71
- // can't use index from plugin state because if the cursor has moved, it will still be the
72
- // OLD index (the find next operation should look for the first match forward starting
73
- // from the current cursor position)
74
- var searchIndex = findSearchIndex(state.selection.from, matches);
75
- if (searchIndex === index) {
76
- // cursor has not moved, so we just want to find the next in matches array
77
- searchIndex = nextIndex(searchIndex, matches.length);
78
- }
79
- return tr.setSelection(getSelectionForMatch(tr.selection, tr.doc, searchIndex, matches));
80
- }));
81
- };
82
- export var findPrevious = function findPrevious() {
83
- return withScrollIntoView(createCommand(function (state) {
84
- return findInDirection(state, 'previous');
85
- }, function (tr, state) {
86
- var _getPluginState5 = getPluginState(state),
87
- matches = _getPluginState5.matches;
88
- // can't use index from plugin state because if the cursor has moved, it will still be the
89
- // OLD index (the find prev operation should look for the first match backward starting
90
- // from the current cursor position)
91
- var searchIndex = findSearchIndex(state.selection.from, matches, true);
92
- return tr.setSelection(getSelectionForMatch(tr.selection, tr.doc, searchIndex, matches));
93
- }));
94
- };
95
- var findInDirection = function findInDirection(state, dir) {
96
- var pluginState = getPluginState(state);
97
- var matches = pluginState.matches,
98
- findText = pluginState.findText;
99
- var decorationSet = pluginState.decorationSet,
100
- index = pluginState.index;
101
- if (findText) {
102
- var searchIndex = findSearchIndex(state.selection.from, matches, dir === 'previous');
103
- // compare index from plugin state and index of first match forward from cursor position
104
- if (index === searchIndex) {
105
- // normal case, cycling through matches
106
- index = dir === 'next' ? nextIndex(index, matches.length) : prevIndex(index, matches.length);
107
- } else {
108
- // cursor has moved
109
- index = searchIndex;
110
- }
111
- decorationSet = updateSelectedHighlight(state, index);
112
- }
113
- return {
114
- type: dir === 'next' ? FindReplaceActionTypes.FIND_NEXT : FindReplaceActionTypes.FIND_PREVIOUS,
115
- index: index,
116
- decorationSet: decorationSet
117
- };
118
- };
119
- export var replace = function replace(replaceText) {
120
- return withScrollIntoView(createCommand(function (state) {
121
- var pluginState = getPluginState(state);
122
- var findText = pluginState.findText;
123
- var decorationSet = pluginState.decorationSet,
124
- matches = pluginState.matches,
125
- index = pluginState.index;
126
- decorationSet = updateSelectedHighlight(state, nextIndex(index, matches.length));
127
- if (replaceText.toLowerCase().indexOf(findText.toLowerCase()) === -1) {
128
- decorationSet = removeMatchesFromSet(decorationSet, [matches[index]], state.doc);
129
- matches.splice(index, 1);
130
- if (index > matches.length - 1) {
131
- index = 0;
132
- }
133
- } else {
134
- index = nextIndex(index, matches.length);
135
- }
136
- return {
137
- type: FindReplaceActionTypes.REPLACE,
138
- replaceText: replaceText,
139
- decorationSet: decorationSet,
140
- matches: matches,
141
- index: index
142
- };
143
- }, function (tr, state) {
144
- var _getPluginState6 = getPluginState(state),
145
- matches = _getPluginState6.matches,
146
- index = _getPluginState6.index,
147
- findText = _getPluginState6.findText;
148
- if (matches[index]) {
149
- var _matches$index = matches[index],
150
- start = _matches$index.start,
151
- end = _matches$index.end;
152
- var newIndex = nextIndex(index, matches.length);
153
- tr.insertText(replaceText, start, end).setSelection(getSelectionForMatch(tr.selection, tr.doc, newIndex, matches, newIndex === 0 ? 0 : replaceText.length - findText.length));
154
- }
155
- return tr;
156
- }));
157
- };
158
- export var replaceAll = function replaceAll(replaceText) {
159
- return createCommand({
160
- type: FindReplaceActionTypes.REPLACE_ALL,
161
- replaceText: replaceText,
162
- decorationSet: DecorationSet.empty,
163
- matches: [],
164
- index: 0
165
- }, function (tr, state) {
166
- var pluginState = getPluginState(state);
167
- pluginState.matches.forEach(function (match) {
168
- tr.insertText(replaceText, tr.mapping.map(match.start), tr.mapping.map(match.end));
169
- });
170
- tr.setMeta('scrollIntoView', false);
171
- return tr;
172
- });
173
- };
174
- export var addDecorations = function addDecorations(decorations) {
175
- return createCommand(function (state) {
176
- var _getPluginState7 = getPluginState(state),
177
- decorationSet = _getPluginState7.decorationSet;
178
- return {
179
- type: FindReplaceActionTypes.UPDATE_DECORATIONS,
180
- decorationSet: decorationSet.add(state.doc, decorations)
181
- };
182
- });
183
- };
184
- export var removeDecorations = function removeDecorations(decorations) {
185
- return createCommand(function (state) {
186
- var _getPluginState8 = getPluginState(state),
187
- decorationSet = _getPluginState8.decorationSet;
188
- return {
189
- type: FindReplaceActionTypes.UPDATE_DECORATIONS,
190
- decorationSet: removeDecorationsFromSet(decorationSet, decorations, state.doc)
191
- };
192
- });
193
- };
194
- export var cancelSearch = function cancelSearch() {
195
- return createCommand(function () {
196
- batchDecorations.stop();
197
- return {
198
- type: FindReplaceActionTypes.CANCEL
199
- };
200
- });
201
- };
202
- export var blur = function blur() {
203
- return createCommand({
204
- type: FindReplaceActionTypes.BLUR
205
- });
206
- };
207
- export var toggleMatchCase = function toggleMatchCase() {
208
- return createCommand({
209
- type: FindReplaceActionTypes.TOGGLE_MATCH_CASE
210
- });
211
- };
212
- var updateSelectedHighlight = function updateSelectedHighlight(state, nextSelectedIndex) {
213
- var _getPluginState9 = getPluginState(state),
214
- decorationSet = _getPluginState9.decorationSet,
215
- index = _getPluginState9.index,
216
- matches = _getPluginState9.matches;
217
- var currentSelectedMatch = matches[index];
218
- var nextSelectedMatch = matches[nextSelectedIndex];
219
- if (index === nextSelectedIndex) {
220
- return decorationSet;
221
- }
222
- var currentSelectedDecoration = findDecorationFromMatch(decorationSet, currentSelectedMatch);
223
- var nextSelectedDecoration = findDecorationFromMatch(decorationSet, nextSelectedMatch);
224
-
225
- // Update decorations so the current selected match becomes a normal match
226
- // and the next selected gets the selected styling
227
- var decorationsToRemove = [];
228
- if (currentSelectedDecoration) {
229
- decorationsToRemove.push(currentSelectedDecoration);
230
- }
231
- if (nextSelectedDecoration) {
232
- decorationsToRemove.push(nextSelectedDecoration);
233
- }
234
- if (decorationsToRemove.length > 0) {
235
- // removeDecorationsFromSet depends on decorations being pre-sorted
236
- decorationsToRemove.sort(function (a, b) {
237
- return a.from < b.from ? -1 : 1;
238
- });
239
- decorationSet = removeDecorationsFromSet(decorationSet, decorationsToRemove, state.doc);
240
- }
241
- if (currentSelectedMatch) {
242
- decorationSet = decorationSet.add(state.doc, [createDecoration(currentSelectedMatch.start, currentSelectedMatch.end)]);
243
- }
244
- if (nextSelectedMatch) {
245
- decorationSet = decorationSet.add(state.doc, [createDecoration(nextSelectedMatch.start, nextSelectedMatch.end, true)]);
246
- }
247
- return decorationSet;
248
- };
@@ -1,87 +0,0 @@
1
- import React from 'react';
2
- import { createPlugin } from './plugin';
3
- import keymapPlugin from './keymap';
4
- import FindReplaceToolbarButtonWithState from './FindReplaceToolbarButtonWithState';
5
- import { findReplacePluginKey } from './plugin-key';
6
- export var findReplacePlugin = function findReplacePlugin(_ref) {
7
- var _api$featureFlags;
8
- var props = _ref.config,
9
- api = _ref.api;
10
- var featureFlags = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
11
- return {
12
- name: 'findReplace',
13
- pmPlugins: function pmPlugins() {
14
- return [{
15
- name: 'findReplace',
16
- plugin: function plugin(_ref2) {
17
- var dispatch = _ref2.dispatch;
18
- return createPlugin(dispatch);
19
- }
20
- }, {
21
- name: 'findReplaceKeymap',
22
- plugin: function plugin() {
23
- var _api$analytics;
24
- return keymapPlugin(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
25
- }
26
- }];
27
- },
28
- getSharedState: function getSharedState(editorState) {
29
- if (!editorState) {
30
- return undefined;
31
- }
32
- return findReplacePluginKey.getState(editorState) || undefined;
33
- },
34
- actions: {
35
- getToolbar: function getToolbar(_ref3) {
36
- var popupsBoundariesElement = _ref3.popupsBoundariesElement,
37
- popupsMountPoint = _ref3.popupsMountPoint,
38
- popupsScrollableElement = _ref3.popupsScrollableElement,
39
- editorView = _ref3.editorView,
40
- containerElement = _ref3.containerElement,
41
- dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent,
42
- isToolbarReducedSpacing = _ref3.isToolbarReducedSpacing;
43
- return /*#__PURE__*/React.createElement(FindReplaceToolbarButtonWithState, {
44
- popupsBoundariesElement: popupsBoundariesElement,
45
- popupsMountPoint: popupsMountPoint,
46
- popupsScrollableElement: popupsScrollableElement,
47
- editorView: editorView,
48
- containerElement: containerElement,
49
- dispatchAnalyticsEvent: dispatchAnalyticsEvent
50
- // `allowMatchCase` comes through the preset, but not the feature flags
51
- // prop with the `ComposableEditor` - grab the FFs from the editor API
52
- // instead until we clean this up.
53
- ,
54
- featureFlags: featureFlags,
55
- isToolbarReducedSpacing: isToolbarReducedSpacing,
56
- api: api
57
- });
58
- }
59
- },
60
- primaryToolbarComponent: function primaryToolbarComponent(_ref4) {
61
- var popupsBoundariesElement = _ref4.popupsBoundariesElement,
62
- popupsMountPoint = _ref4.popupsMountPoint,
63
- popupsScrollableElement = _ref4.popupsScrollableElement,
64
- isToolbarReducedSpacing = _ref4.isToolbarReducedSpacing,
65
- editorView = _ref4.editorView,
66
- containerElement = _ref4.containerElement,
67
- dispatchAnalyticsEvent = _ref4.dispatchAnalyticsEvent;
68
- if (props !== null && props !== void 0 && props.twoLineEditorToolbar) {
69
- return null;
70
- } else {
71
- return /*#__PURE__*/React.createElement(FindReplaceToolbarButtonWithState, {
72
- popupsBoundariesElement: popupsBoundariesElement,
73
- popupsMountPoint: popupsMountPoint,
74
- popupsScrollableElement: popupsScrollableElement,
75
- isToolbarReducedSpacing: isToolbarReducedSpacing,
76
- editorView: editorView,
77
- containerElement: containerElement,
78
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
79
- takeFullWidth: props === null || props === void 0 ? void 0 : props.takeFullWidth,
80
- featureFlags: featureFlags,
81
- api: api
82
- });
83
- }
84
- }
85
- };
86
- };
87
- export default findReplacePlugin;
@@ -1,18 +0,0 @@
1
- import { keymap } from '@atlaskit/editor-prosemirror/keymap';
2
- import { bindKeymapWithCommand, find as findKeymap } from '@atlaskit/editor-common/keymaps';
3
- import { activateWithAnalytics } from './commands-with-analytics';
4
- import { TRIGGER_METHOD } from '@atlaskit/editor-common/analytics';
5
- var activateFindReplace = function activateFindReplace(editorAnalyticsAPI) {
6
- return function (state, dispatch) {
7
- activateWithAnalytics(editorAnalyticsAPI)({
8
- triggerMethod: TRIGGER_METHOD.SHORTCUT
9
- })(state, dispatch);
10
- return true;
11
- };
12
- };
13
- var keymapPlugin = function keymapPlugin(editorAnalyticsAPI) {
14
- var list = {};
15
- bindKeymapWithCommand(findKeymap.common, activateFindReplace(editorAnalyticsAPI), list);
16
- return keymap(list);
17
- };
18
- export default keymapPlugin;
@@ -1,2 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
- export var findReplacePluginKey = new PluginKey('findReplace');
@@ -1,133 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
- import { pluginFactory } from '@atlaskit/editor-common/utils';
8
- import reducer from './reducer';
9
- import { findMatches, createDecorations, removeDecorationsFromSet, findSearchIndex, removeMatchesFromSet, findDecorationFromMatch, isMatchAffectedByStep } from './utils';
10
- import { findUniqueItemsIn } from '../../utils/array';
11
- import { stepHasSlice } from '@atlaskit/editor-common/utils';
12
- import { findReplacePluginKey } from './plugin-key';
13
- export var initialState = {
14
- isActive: false,
15
- shouldFocus: false,
16
- findText: '',
17
- replaceText: '',
18
- index: 0,
19
- matches: [],
20
- decorationSet: DecorationSet.empty,
21
- shouldMatchCase: false
22
- };
23
- var handleDocChanged = function handleDocChanged(tr, pluginState) {
24
- var isActive = pluginState.isActive,
25
- findText = pluginState.findText;
26
- if (!isActive || !findText) {
27
- return pluginState;
28
- }
29
- if (!tr.steps.find(stepHasSlice)) {
30
- return pluginState;
31
- }
32
- var index = pluginState.index,
33
- decorationSet = pluginState.decorationSet,
34
- matches = pluginState.matches,
35
- shouldMatchCase = pluginState.shouldMatchCase;
36
- var newMatches = findMatches(tr.doc, findText, shouldMatchCase);
37
- decorationSet = decorationSet.map(tr.mapping, tr.doc);
38
- var numDecorations = decorationSet.find().length;
39
- var mappedMatches = matches.map(function (match) {
40
- return {
41
- start: tr.mapping.map(match.start),
42
- end: tr.mapping.map(match.end)
43
- };
44
- });
45
- var matchesToAdd = [];
46
- var matchesToDelete = [];
47
- if (newMatches.length > 0 && numDecorations === 0) {
48
- matchesToAdd = newMatches;
49
- } else if (newMatches.length === 0 && numDecorations > 0) {
50
- decorationSet = DecorationSet.empty;
51
- } else if (newMatches.length > 0 || numDecorations > 0) {
52
- // go through tr steps and find any new matches from user adding content or
53
- // any dead matches from user deleting content
54
- tr.steps.forEach(function (step) {
55
- if (stepHasSlice(step)) {
56
- // add all matches that are between the affected positions and don't already have
57
- // corresponding decorations
58
- matchesToAdd = [].concat(_toConsumableArray(matchesToAdd), _toConsumableArray(newMatches.filter(function (match) {
59
- return isMatchAffectedByStep(match, step, tr) && !findDecorationFromMatch(decorationSet, match);
60
- })));
61
-
62
- // delete any matches that are missing from the newMatches array and have a
63
- // corresponding decoration
64
- matchesToDelete = [].concat(_toConsumableArray(matchesToDelete), _toConsumableArray(findUniqueItemsIn(mappedMatches.filter(function (match) {
65
- return isMatchAffectedByStep(match, step, tr) && !!findDecorationFromMatch(decorationSet, match);
66
- }), newMatches, function (firstMatch, secondMatch) {
67
- return firstMatch.start === secondMatch.start && firstMatch.end === secondMatch.end;
68
- })));
69
- }
70
- });
71
- }
72
-
73
- // update decorations if matches changed following document update
74
- if (matchesToDelete.length > 0) {
75
- var decorationsToDelete = matchesToDelete.reduce(function (decorations, match) {
76
- return [].concat(_toConsumableArray(decorations), _toConsumableArray(decorationSet.find(match.start, match.end)));
77
- }, []);
78
- decorationSet = removeDecorationsFromSet(decorationSet, decorationsToDelete, tr.doc);
79
- }
80
- if (matchesToAdd.length > 0) {
81
- decorationSet = decorationSet.add(tr.doc, createDecorations(tr.selection.from, matchesToAdd));
82
- }
83
-
84
- // update selected match if it has changed
85
- var newIndex = index;
86
- var selectedMatch = mappedMatches[index];
87
- if (selectedMatch) {
88
- newIndex = newMatches.findIndex(function (match) {
89
- return match.start === selectedMatch.start;
90
- });
91
- }
92
- if (newIndex === undefined || newIndex === -1) {
93
- newIndex = findSearchIndex(tr.selection.from, newMatches);
94
- }
95
- var newSelectedMatch = newMatches[newIndex];
96
- decorationSet = removeMatchesFromSet(decorationSet, [selectedMatch, newSelectedMatch], tr.doc);
97
- if (newSelectedMatch) {
98
- decorationSet = decorationSet.add(tr.doc, createDecorations(0, [newSelectedMatch]));
99
- }
100
- return _objectSpread(_objectSpread({}, pluginState), {}, {
101
- matches: newMatches,
102
- index: newIndex,
103
- decorationSet: decorationSet
104
- });
105
- };
106
- var _pluginFactory = pluginFactory(findReplacePluginKey, reducer(function () {
107
- return initialState;
108
- }), {
109
- onDocChanged: handleDocChanged
110
- }),
111
- createCommand = _pluginFactory.createCommand,
112
- getPluginState = _pluginFactory.getPluginState,
113
- createPluginState = _pluginFactory.createPluginState;
114
- export { createCommand, getPluginState, createPluginState };
115
- export var createPlugin = function createPlugin(dispatch) {
116
- return new SafePlugin({
117
- key: findReplacePluginKey,
118
- state: createPluginState(dispatch, function () {
119
- return initialState;
120
- }),
121
- props: {
122
- decorations: function decorations(state) {
123
- var _getPluginState = getPluginState(state),
124
- isActive = _getPluginState.isActive,
125
- findText = _getPluginState.findText,
126
- decorationSet = _getPluginState.decorationSet;
127
- if (isActive && findText) {
128
- return decorationSet;
129
- }
130
- }
131
- }
132
- });
133
- };
@@ -1,54 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- import { FindReplaceActionTypes } from './actions';
5
- var reducer = function reducer(getInitialState) {
6
- return function (state, action) {
7
- switch (action.type) {
8
- case FindReplaceActionTypes.ACTIVATE:
9
- case FindReplaceActionTypes.FIND:
10
- return _objectSpread(_objectSpread({}, state), {}, {
11
- isActive: true,
12
- shouldFocus: action.type === FindReplaceActionTypes.ACTIVATE,
13
- findText: action.findText !== undefined ? action.findText : state.findText,
14
- matches: action.matches || state.matches,
15
- index: action.index !== undefined ? action.index : state.index
16
- });
17
- case FindReplaceActionTypes.UPDATE_DECORATIONS:
18
- return _objectSpread(_objectSpread({}, state), {}, {
19
- decorationSet: action.decorationSet
20
- });
21
- case FindReplaceActionTypes.FIND_NEXT:
22
- return _objectSpread(_objectSpread({}, state), {}, {
23
- index: action.index,
24
- decorationSet: action.decorationSet
25
- });
26
- case FindReplaceActionTypes.FIND_PREVIOUS:
27
- return _objectSpread(_objectSpread({}, state), {}, {
28
- index: action.index,
29
- decorationSet: action.decorationSet
30
- });
31
- case FindReplaceActionTypes.REPLACE:
32
- case FindReplaceActionTypes.REPLACE_ALL:
33
- return _objectSpread(_objectSpread({}, state), {}, {
34
- replaceText: action.replaceText,
35
- decorationSet: action.decorationSet,
36
- matches: action.matches,
37
- index: action.index
38
- });
39
- case FindReplaceActionTypes.CANCEL:
40
- return getInitialState();
41
- case FindReplaceActionTypes.BLUR:
42
- return _objectSpread(_objectSpread({}, state), {}, {
43
- shouldFocus: false
44
- });
45
- case FindReplaceActionTypes.TOGGLE_MATCH_CASE:
46
- return _objectSpread(_objectSpread({}, state), {}, {
47
- shouldMatchCase: !state.shouldMatchCase
48
- });
49
- default:
50
- return state;
51
- }
52
- };
53
- };
54
- export default reducer;
@@ -1,10 +0,0 @@
1
- import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
2
- var _templateObject;
3
- /* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
4
-
5
- // TODO: https://product-fabric.atlassian.net/browse/DSP-4290
6
- import { css } from '@emotion/react';
7
- import { B75, B200 } from '@atlaskit/theme/colors';
8
- export var searchMatchClass = 'search-match';
9
- export var selectedSearchMatchClass = 'selected-search-match';
10
- export var findReplaceStyles = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .", " {\n background-color: ", ";\n }\n\n .", " {\n background-color: ", ";\n color: white;\n }\n"])), searchMatchClass, B75, selectedSearchMatchClass, B200);
@@ -1 +0,0 @@
1
- export {};