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