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