@atlaskit/editor-core 191.0.8 → 191.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/afm-cc/tsconfig.json +3 -3
  3. package/dist/cjs/plugins/index.js +0 -7
  4. package/dist/cjs/presets/universal.js +2 -1
  5. package/dist/cjs/ui/Appearance/Comment/Comment.js +6 -3
  6. package/dist/cjs/ui/Appearance/Comment/Toolbar.js +19 -6
  7. package/dist/cjs/ui/Appearance/FullPage/FullPageToolbar.js +1 -1
  8. package/dist/cjs/ui/ContentStyles/index.js +1 -1
  9. package/dist/cjs/version-wrapper.js +1 -1
  10. package/dist/es2019/plugins/index.js +0 -1
  11. package/dist/es2019/presets/universal.js +2 -1
  12. package/dist/es2019/ui/Appearance/Comment/Comment.js +6 -3
  13. package/dist/es2019/ui/Appearance/Comment/Toolbar.js +38 -6
  14. package/dist/es2019/ui/Appearance/FullPage/FullPageToolbar.js +1 -1
  15. package/dist/es2019/ui/ContentStyles/index.js +1 -1
  16. package/dist/es2019/version-wrapper.js +1 -1
  17. package/dist/esm/plugins/index.js +0 -1
  18. package/dist/esm/presets/universal.js +2 -1
  19. package/dist/esm/ui/Appearance/Comment/Comment.js +6 -3
  20. package/dist/esm/ui/Appearance/Comment/Toolbar.js +19 -6
  21. package/dist/esm/ui/Appearance/FullPage/FullPageToolbar.js +1 -1
  22. package/dist/esm/ui/ContentStyles/index.js +1 -1
  23. package/dist/esm/version-wrapper.js +1 -1
  24. package/dist/types/plugins/index.d.ts +0 -1
  25. package/dist/types/types/editor-props.d.ts +1 -1
  26. package/dist/types/ui/Appearance/Comment/Toolbar.d.ts +2 -1
  27. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  28. package/dist/types-ts4.5/types/editor-props.d.ts +1 -1
  29. package/dist/types-ts4.5/ui/Appearance/Comment/Toolbar.d.ts +2 -1
  30. package/package.json +6 -10
  31. package/dist/cjs/plugins/find-replace/FindReplaceToolbarButtonWithState.js +0 -166
  32. package/dist/cjs/plugins/find-replace/actions.js +0 -19
  33. package/dist/cjs/plugins/find-replace/commands-with-analytics.js +0 -101
  34. package/dist/cjs/plugins/find-replace/commands.js +0 -255
  35. package/dist/cjs/plugins/find-replace/index.js +0 -94
  36. package/dist/cjs/plugins/find-replace/keymap.js +0 -24
  37. package/dist/cjs/plugins/find-replace/plugin-key.js +0 -8
  38. package/dist/cjs/plugins/find-replace/plugin.js +0 -138
  39. package/dist/cjs/plugins/find-replace/reducer.js +0 -61
  40. package/dist/cjs/plugins/find-replace/styles.js +0 -16
  41. package/dist/cjs/plugins/find-replace/types.js +0 -5
  42. package/dist/cjs/plugins/find-replace/ui/Find.js +0 -308
  43. package/dist/cjs/plugins/find-replace/ui/FindReplace.js +0 -103
  44. package/dist/cjs/plugins/find-replace/ui/FindReplaceToolbarButton.js +0 -132
  45. package/dist/cjs/plugins/find-replace/ui/FindReplaceTooltipButton.js +0 -76
  46. package/dist/cjs/plugins/find-replace/ui/Replace.js +0 -174
  47. package/dist/cjs/plugins/find-replace/ui/styles.js +0 -44
  48. package/dist/cjs/plugins/find-replace/utils/batch-decorations.js +0 -310
  49. package/dist/cjs/plugins/find-replace/utils/commands.js +0 -16
  50. package/dist/cjs/plugins/find-replace/utils/index.js +0 -290
  51. package/dist/cjs/utils/array.js +0 -13
  52. package/dist/es2019/plugins/find-replace/FindReplaceToolbarButtonWithState.js +0 -153
  53. package/dist/es2019/plugins/find-replace/actions.js +0 -13
  54. package/dist/es2019/plugins/find-replace/commands-with-analytics.js +0 -72
  55. package/dist/es2019/plugins/find-replace/commands.js +0 -240
  56. package/dist/es2019/plugins/find-replace/index.js +0 -89
  57. package/dist/es2019/plugins/find-replace/keymap.js +0 -16
  58. package/dist/es2019/plugins/find-replace/plugin-key.js +0 -2
  59. package/dist/es2019/plugins/find-replace/plugin.js +0 -117
  60. package/dist/es2019/plugins/find-replace/reducer.js +0 -56
  61. package/dist/es2019/plugins/find-replace/styles.js +0 -17
  62. package/dist/es2019/plugins/find-replace/types.js +0 -1
  63. package/dist/es2019/plugins/find-replace/ui/Find.js +0 -284
  64. package/dist/es2019/plugins/find-replace/ui/FindReplace.js +0 -78
  65. package/dist/es2019/plugins/find-replace/ui/FindReplaceToolbarButton.js +0 -122
  66. package/dist/es2019/plugins/find-replace/ui/FindReplaceTooltipButton.js +0 -50
  67. package/dist/es2019/plugins/find-replace/ui/Replace.js +0 -152
  68. package/dist/es2019/plugins/find-replace/ui/styles.js +0 -48
  69. package/dist/es2019/plugins/find-replace/utils/batch-decorations.js +0 -189
  70. package/dist/es2019/plugins/find-replace/utils/commands.js +0 -6
  71. package/dist/es2019/plugins/find-replace/utils/index.js +0 -249
  72. package/dist/es2019/utils/array.js +0 -3
  73. package/dist/esm/plugins/find-replace/FindReplaceToolbarButtonWithState.js +0 -157
  74. package/dist/esm/plugins/find-replace/actions.js +0 -13
  75. package/dist/esm/plugins/find-replace/commands-with-analytics.js +0 -95
  76. package/dist/esm/plugins/find-replace/commands.js +0 -248
  77. package/dist/esm/plugins/find-replace/index.js +0 -87
  78. package/dist/esm/plugins/find-replace/keymap.js +0 -18
  79. package/dist/esm/plugins/find-replace/plugin-key.js +0 -2
  80. package/dist/esm/plugins/find-replace/plugin.js +0 -133
  81. package/dist/esm/plugins/find-replace/reducer.js +0 -54
  82. package/dist/esm/plugins/find-replace/styles.js +0 -10
  83. package/dist/esm/plugins/find-replace/types.js +0 -1
  84. package/dist/esm/plugins/find-replace/ui/Find.js +0 -302
  85. package/dist/esm/plugins/find-replace/ui/FindReplace.js +0 -97
  86. package/dist/esm/plugins/find-replace/ui/FindReplaceToolbarButton.js +0 -126
  87. package/dist/esm/plugins/find-replace/ui/FindReplaceTooltipButton.js +0 -69
  88. package/dist/esm/plugins/find-replace/ui/Replace.js +0 -168
  89. package/dist/esm/plugins/find-replace/ui/styles.js +0 -37
  90. package/dist/esm/plugins/find-replace/utils/batch-decorations.js +0 -304
  91. package/dist/esm/plugins/find-replace/utils/commands.js +0 -10
  92. package/dist/esm/plugins/find-replace/utils/index.js +0 -280
  93. package/dist/esm/utils/array.js +0 -7
  94. package/dist/types/plugins/find-replace/FindReplaceToolbarButtonWithState.d.ts +0 -4
  95. package/dist/types/plugins/find-replace/actions.d.ts +0 -64
  96. package/dist/types/plugins/find-replace/commands-with-analytics.d.ts +0 -27
  97. package/dist/types/plugins/find-replace/commands.d.ts +0 -12
  98. package/dist/types/plugins/find-replace/index.d.ts +0 -3
  99. package/dist/types/plugins/find-replace/keymap.d.ts +0 -4
  100. package/dist/types/plugins/find-replace/plugin-key.d.ts +0 -3
  101. package/dist/types/plugins/find-replace/plugin.d.ts +0 -6
  102. package/dist/types/plugins/find-replace/reducer.d.ts +0 -4
  103. package/dist/types/plugins/find-replace/styles.d.ts +0 -3
  104. package/dist/types/plugins/find-replace/types.d.ts +0 -79
  105. package/dist/types/plugins/find-replace/ui/Find.d.ts +0 -71
  106. package/dist/types/plugins/find-replace/ui/FindReplace.d.ts +0 -43
  107. package/dist/types/plugins/find-replace/ui/FindReplaceToolbarButton.d.ts +0 -21
  108. package/dist/types/plugins/find-replace/ui/FindReplaceTooltipButton.d.ts +0 -18
  109. package/dist/types/plugins/find-replace/ui/Replace.d.ts +0 -27
  110. package/dist/types/plugins/find-replace/ui/styles.d.ts +0 -6
  111. package/dist/types/plugins/find-replace/utils/batch-decorations.d.ts +0 -36
  112. package/dist/types/plugins/find-replace/utils/commands.d.ts +0 -2
  113. package/dist/types/plugins/find-replace/utils/index.d.ts +0 -49
  114. package/dist/types/utils/array.d.ts +0 -1
  115. package/dist/types-ts4.5/plugins/find-replace/FindReplaceToolbarButtonWithState.d.ts +0 -4
  116. package/dist/types-ts4.5/plugins/find-replace/actions.d.ts +0 -64
  117. package/dist/types-ts4.5/plugins/find-replace/commands-with-analytics.d.ts +0 -27
  118. package/dist/types-ts4.5/plugins/find-replace/commands.d.ts +0 -12
  119. package/dist/types-ts4.5/plugins/find-replace/index.d.ts +0 -3
  120. package/dist/types-ts4.5/plugins/find-replace/keymap.d.ts +0 -4
  121. package/dist/types-ts4.5/plugins/find-replace/plugin-key.d.ts +0 -3
  122. package/dist/types-ts4.5/plugins/find-replace/plugin.d.ts +0 -6
  123. package/dist/types-ts4.5/plugins/find-replace/reducer.d.ts +0 -4
  124. package/dist/types-ts4.5/plugins/find-replace/styles.d.ts +0 -3
  125. package/dist/types-ts4.5/plugins/find-replace/types.d.ts +0 -79
  126. package/dist/types-ts4.5/plugins/find-replace/ui/Find.d.ts +0 -71
  127. package/dist/types-ts4.5/plugins/find-replace/ui/FindReplace.d.ts +0 -43
  128. package/dist/types-ts4.5/plugins/find-replace/ui/FindReplaceToolbarButton.d.ts +0 -21
  129. package/dist/types-ts4.5/plugins/find-replace/ui/FindReplaceTooltipButton.d.ts +0 -18
  130. package/dist/types-ts4.5/plugins/find-replace/ui/Replace.d.ts +0 -27
  131. package/dist/types-ts4.5/plugins/find-replace/ui/styles.d.ts +0 -6
  132. package/dist/types-ts4.5/plugins/find-replace/utils/batch-decorations.d.ts +0 -36
  133. package/dist/types-ts4.5/plugins/find-replace/utils/commands.d.ts +0 -2
  134. package/dist/types-ts4.5/plugins/find-replace/utils/index.d.ts +0 -49
  135. package/dist/types-ts4.5/utils/array.d.ts +0 -1
@@ -1,157 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import React, { useState, useLayoutEffect } from 'react';
3
- import { cancelSearchWithAnalytics, replaceWithAnalytics, replaceAllWithAnalytics, findWithAnalytics, findNextWithAnalytics, findPrevWithAnalytics, activateWithAnalytics } from './commands-with-analytics';
4
- import { blur, toggleMatchCase } from './commands';
5
- import FindReplaceToolbarButton from './ui/FindReplaceToolbarButton';
6
- import { TRIGGER_METHOD } from '@atlaskit/editor-common/analytics';
7
-
8
- // light implementation of useSharedPluginState(). This is due to findreplace
9
- // being the only plugin that previously used WithPluginState with
10
- // debounce=false. That was implemented because of text sync issues
11
- // between editor & findreplace dialog.
12
- // To address under ENGHEALTH-5853
13
- var useSharedPluginStateNoDebounce = function useSharedPluginStateNoDebounce(api) {
14
- var _useState = useState(api === null || api === void 0 ? void 0 : api.findReplace.sharedState.currentState()),
15
- _useState2 = _slicedToArray(_useState, 2),
16
- state = _useState2[0],
17
- setState = _useState2[1];
18
- useLayoutEffect(function () {
19
- var unsub = api === null || api === void 0 ? void 0 : api.findReplace.sharedState.onChange(function (_ref) {
20
- var nextSharedState = _ref.nextSharedState;
21
- setState(nextSharedState);
22
- });
23
- return function () {
24
- unsub === null || unsub === void 0 || unsub();
25
- };
26
- }, [api]);
27
- return {
28
- findReplaceState: state
29
- };
30
- };
31
- var FindReplaceToolbarButtonWithState = function FindReplaceToolbarButtonWithState(_ref2) {
32
- var _api$analytics;
33
- var popupsBoundariesElement = _ref2.popupsBoundariesElement,
34
- popupsMountPoint = _ref2.popupsMountPoint,
35
- popupsScrollableElement = _ref2.popupsScrollableElement,
36
- isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing,
37
- editorView = _ref2.editorView,
38
- containerElement = _ref2.containerElement,
39
- dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent,
40
- featureFlags = _ref2.featureFlags,
41
- takeFullWidth = _ref2.takeFullWidth,
42
- api = _ref2.api;
43
- var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
44
- var _useSharedPluginState = useSharedPluginStateNoDebounce(api),
45
- findReplaceState = _useSharedPluginState.findReplaceState;
46
- if (!editorView) {
47
- return null;
48
- }
49
-
50
- // we need the editor to be in focus for scrollIntoView() to work
51
- // so we focus it while we run the command, then put focus back into
52
- // whatever element was previously focused in find replace component
53
- var runWithEditorFocused = function runWithEditorFocused(fn) {
54
- var activeElement = document.activeElement;
55
- editorView.focus();
56
- fn();
57
- activeElement === null || activeElement === void 0 || activeElement.focus();
58
- };
59
- var dispatchCommand = function dispatchCommand(cmd) {
60
- var state = editorView.state,
61
- dispatch = editorView.dispatch;
62
- cmd(state, dispatch);
63
- };
64
- var handleActivate = function handleActivate() {
65
- runWithEditorFocused(function () {
66
- return dispatchCommand(activateWithAnalytics(editorAnalyticsAPI)({
67
- triggerMethod: TRIGGER_METHOD.TOOLBAR
68
- }));
69
- });
70
- };
71
- var handleFind = function handleFind(keyword) {
72
- runWithEditorFocused(function () {
73
- return dispatchCommand(findWithAnalytics(editorAnalyticsAPI)({
74
- editorView: editorView,
75
- containerElement: containerElement,
76
- keyword: keyword
77
- }));
78
- });
79
- };
80
- var handleFindNext = function handleFindNext(_ref3) {
81
- var triggerMethod = _ref3.triggerMethod;
82
- runWithEditorFocused(function () {
83
- return dispatchCommand(findNextWithAnalytics(editorAnalyticsAPI)({
84
- triggerMethod: triggerMethod
85
- }));
86
- });
87
- };
88
- var handleFindPrev = function handleFindPrev(_ref4) {
89
- var triggerMethod = _ref4.triggerMethod;
90
- runWithEditorFocused(function () {
91
- return dispatchCommand(findPrevWithAnalytics(editorAnalyticsAPI)({
92
- triggerMethod: triggerMethod
93
- }));
94
- });
95
- };
96
- var handleReplace = function handleReplace(_ref5) {
97
- var triggerMethod = _ref5.triggerMethod,
98
- replaceText = _ref5.replaceText;
99
- runWithEditorFocused(function () {
100
- return dispatchCommand(replaceWithAnalytics(editorAnalyticsAPI)({
101
- triggerMethod: triggerMethod,
102
- replaceText: replaceText
103
- }));
104
- });
105
- };
106
- var handleReplaceAll = function handleReplaceAll(_ref6) {
107
- var replaceText = _ref6.replaceText;
108
- runWithEditorFocused(function () {
109
- return dispatchCommand(replaceAllWithAnalytics(editorAnalyticsAPI)({
110
- replaceText: replaceText
111
- }));
112
- });
113
- };
114
- var handleFindBlur = function handleFindBlur() {
115
- dispatchCommand(blur());
116
- };
117
- var handleCancel = function handleCancel(_ref7) {
118
- var triggerMethod = _ref7.triggerMethod;
119
- dispatchCommand(cancelSearchWithAnalytics(editorAnalyticsAPI)({
120
- triggerMethod: triggerMethod
121
- }));
122
- editorView.focus();
123
- };
124
- var handleToggleMatchCase = function handleToggleMatchCase() {
125
- dispatchCommand(toggleMatchCase());
126
- };
127
- var findReplaceMatchCase = featureFlags.findReplaceMatchCase;
128
- if (!findReplaceState) {
129
- return null;
130
- }
131
- return /*#__PURE__*/React.createElement(FindReplaceToolbarButton, {
132
- allowMatchCase: findReplaceMatchCase,
133
- shouldMatchCase: findReplaceState.shouldMatchCase,
134
- onToggleMatchCase: handleToggleMatchCase,
135
- isActive: findReplaceState.isActive,
136
- findText: findReplaceState.findText,
137
- index: findReplaceState.index,
138
- numMatches: findReplaceState.matches.length,
139
- replaceText: findReplaceState.replaceText,
140
- shouldFocus: findReplaceState.shouldFocus,
141
- popupsBoundariesElement: popupsBoundariesElement,
142
- popupsMountPoint: popupsMountPoint,
143
- popupsScrollableElement: popupsScrollableElement,
144
- isReducedSpacing: !!isToolbarReducedSpacing,
145
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
146
- onFindBlur: handleFindBlur,
147
- onCancel: handleCancel,
148
- onActivate: handleActivate,
149
- onFind: handleFind,
150
- onFindNext: handleFindNext,
151
- onFindPrev: handleFindPrev,
152
- onReplace: handleReplace,
153
- onReplaceAll: handleReplaceAll,
154
- takeFullWidth: !!takeFullWidth
155
- });
156
- };
157
- export default /*#__PURE__*/React.memo(FindReplaceToolbarButtonWithState);
@@ -1,13 +0,0 @@
1
- export var FindReplaceActionTypes = /*#__PURE__*/function (FindReplaceActionTypes) {
2
- FindReplaceActionTypes["ACTIVATE"] = "ACTIVATE";
3
- FindReplaceActionTypes["FIND"] = "FIND";
4
- FindReplaceActionTypes["UPDATE_DECORATIONS"] = "UPDATE_DECORATIONS";
5
- FindReplaceActionTypes["FIND_NEXT"] = "FIND_NEXT";
6
- FindReplaceActionTypes["FIND_PREVIOUS"] = "FIND_PREVIOUS";
7
- FindReplaceActionTypes["REPLACE"] = "REPLACE";
8
- FindReplaceActionTypes["REPLACE_ALL"] = "REPLACE_ALL";
9
- FindReplaceActionTypes["CANCEL"] = "CANCEL";
10
- FindReplaceActionTypes["BLUR"] = "BLUR";
11
- FindReplaceActionTypes["TOGGLE_MATCH_CASE"] = "TOGGLE_MATCH_CASE";
12
- return FindReplaceActionTypes;
13
- }({});
@@ -1,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');