@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,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 {};
@@ -1,284 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- /** @jsx jsx */
3
- import React from 'react';
4
- import { jsx } from '@emotion/react';
5
- import { defineMessages, injectIntl } from 'react-intl-next';
6
- import debounce from 'lodash/debounce';
7
- import EditorCloseIcon from '@atlaskit/icon/glyph/editor/close';
8
- import ChevronDownIcon from '@atlaskit/icon/glyph/hipchat/chevron-down';
9
- import ChevronUpIcon from '@atlaskit/icon/glyph/hipchat/chevron-up';
10
- import MatchCaseIcon from '@atlaskit/icon/glyph/emoji/keyboard';
11
- import Textfield from '@atlaskit/textfield';
12
- import { countStyles, countWrapperStyles, sectionWrapperStyles } from './styles';
13
- import { TRIGGER_METHOD } from '@atlaskit/editor-common/analytics';
14
- import { FindReplaceTooltipButton } from './FindReplaceTooltipButton';
15
- import rafSchd from 'raf-schd';
16
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
17
- export const FIND_DEBOUNCE_MS = 100;
18
- const messages = defineMessages({
19
- find: {
20
- id: 'fabric.editor.find',
21
- defaultMessage: 'Find',
22
- description: 'The word or phrase to search for on the document'
23
- },
24
- matchCase: {
25
- id: 'fabric.editor.matchCase',
26
- defaultMessage: 'Match case',
27
- description: 'Toggle whether should also match case when searching for text'
28
- },
29
- findNext: {
30
- id: 'fabric.editor.findNext',
31
- defaultMessage: 'Find next',
32
- description: 'Locate the next occurrence of the word or phrase that was searched for'
33
- },
34
- findPrevious: {
35
- id: 'fabric.editor.findPrevious',
36
- defaultMessage: 'Find previous',
37
- description: 'Locate the previous occurrence of the word or phrase that was searched for'
38
- },
39
- closeFindReplaceDialog: {
40
- id: 'fabric.editor.closeFindReplaceDialog',
41
- defaultMessage: 'Close',
42
- description: 'Cancel search and close the "Find and Replace" dialog'
43
- },
44
- noResultsFound: {
45
- id: 'fabric.editor.noResultsFound',
46
- defaultMessage: 'No results',
47
- description: 'No matches were found for the word or phrase that was searched for'
48
- },
49
- resultsCount: {
50
- id: 'fabric.editor.resultsCount',
51
- description: 'Text for selected search match position and total results count',
52
- defaultMessage: '{selectedMatchPosition} of {totalResultsCount}'
53
- }
54
- });
55
- class Find extends React.Component {
56
- constructor(props) {
57
- super(props);
58
- _defineProperty(this, "findTextfieldRef", /*#__PURE__*/React.createRef());
59
- _defineProperty(this, "isComposing", false);
60
- _defineProperty(this, "syncFindText", onSynced => {
61
- var _this$state;
62
- // If the external prop findText changes and we aren't in a composition we should update to
63
- // use the external prop value.
64
- //
65
- // An example of where this may happen is when a find occurs through the user selecting some text
66
- // and pressing Mod-f.
67
- if (!this.isComposing && this.props.findText !== ((_this$state = this.state) === null || _this$state === void 0 ? void 0 : _this$state.localFindText)) {
68
- this.updateFindValue(this.props.findText || '', onSynced);
69
- }
70
- });
71
- _defineProperty(this, "focusFindTextfield", () => {
72
- const input = this.findTextfieldRef.current;
73
- if (this.props.shouldFocus && input) {
74
- input.select();
75
- }
76
- });
77
- _defineProperty(this, "handleFindChange", event => {
78
- this.updateFindValue(event.target.value);
79
- });
80
- // debounce (vs throttle) to not block typing inside find input while onFind runs
81
- _defineProperty(this, "debouncedFind", debounce(value => {
82
- this.props.onFind(value);
83
- }, FIND_DEBOUNCE_MS));
84
- _defineProperty(this, "updateFindValue", (value, onSynced) => {
85
- this.setState({
86
- localFindText: value
87
- }, () => {
88
- if (this.isComposing) {
89
- return;
90
- }
91
- onSynced && onSynced();
92
- this.debouncedFind(value);
93
- });
94
- });
95
- // throtlle between animation frames gives better experience on Enter compared to arbitrary value
96
- // it adjusts based on performance (and document size)
97
- _defineProperty(this, "handleFindKeyDownThrottled", rafSchd(event => {
98
- if (event.key === 'Enter') {
99
- if (event.shiftKey) {
100
- this.props.onFindPrev({
101
- triggerMethod: TRIGGER_METHOD.KEYBOARD
102
- });
103
- } else {
104
- this.props.onFindNext({
105
- triggerMethod: TRIGGER_METHOD.KEYBOARD
106
- });
107
- }
108
- } else if (event.key === 'ArrowDown') {
109
- // we want to move focus between find & replace texfields when user hits up/down arrows
110
- this.props.onArrowDown();
111
- }
112
- }));
113
- _defineProperty(this, "handleFindKeyDown", event => {
114
- if (this.isComposing) {
115
- return;
116
- }
117
- event.persist();
118
- this.handleFindKeyDownThrottled(event);
119
- });
120
- _defineProperty(this, "handleFindKeyUp", () => {
121
- this.handleFindKeyDownThrottled.cancel();
122
- });
123
- _defineProperty(this, "handleFindNextClick", ref => {
124
- if (this.isComposing) {
125
- return;
126
- }
127
- this.props.onFindNext({
128
- triggerMethod: TRIGGER_METHOD.BUTTON
129
- });
130
- });
131
- _defineProperty(this, "handleFindPrevClick", ref => {
132
- if (this.isComposing) {
133
- return;
134
- }
135
- this.props.onFindPrev({
136
- triggerMethod: TRIGGER_METHOD.BUTTON
137
- });
138
- });
139
- _defineProperty(this, "handleCompositionStart", () => {
140
- this.isComposing = true;
141
- });
142
- _defineProperty(this, "handleCompositionEnd", event => {
143
- this.isComposing = false;
144
- // type for React.CompositionEvent doesn't set type for target correctly
145
- this.updateFindValue(event.target.value);
146
- });
147
- _defineProperty(this, "clearSearch", () => {
148
- this.props.onCancel({
149
- triggerMethod: TRIGGER_METHOD.BUTTON
150
- });
151
- });
152
- _defineProperty(this, "handleMatchCaseClick", buttonRef => {
153
- if (this.props.allowMatchCase && this.props.onToggleMatchCase) {
154
- this.props.onToggleMatchCase();
155
- this.props.onFind(this.props.findText);
156
- }
157
- });
158
- const {
159
- intl: {
160
- formatMessage
161
- }
162
- } = props;
163
- this.find = formatMessage(messages.find);
164
- this.closeFindReplaceDialog = formatMessage(messages.closeFindReplaceDialog);
165
- this.noResultsFound = formatMessage(messages.noResultsFound);
166
- this.findNext = formatMessage(messages.findNext);
167
- this.findPrevious = formatMessage(messages.findPrevious);
168
- this.matchCase = formatMessage(messages.matchCase);
169
- this.matchCaseIcon = jsx(MatchCaseIcon, {
170
- label: this.matchCase
171
- });
172
- this.findNextIcon = jsx(ChevronDownIcon, {
173
- label: this.findNext
174
- });
175
- this.findPrevIcon = jsx(ChevronUpIcon, {
176
- label: this.findPrevious
177
- });
178
- this.closeIcon = jsx(EditorCloseIcon, {
179
- label: this.closeFindReplaceDialog
180
- });
181
-
182
- // We locally manage the value of the input inside this component in order to support compositions.
183
- // This requires some additional work inside componentDidUpdate to ensure we support changes that
184
- // occur to this value which do not originate from this component.
185
- this.state = {
186
- localFindText: ''
187
- };
188
- }
189
- componentDidMount() {
190
- this.props.onFindTextfieldRefSet(this.findTextfieldRef);
191
-
192
- // focus initially on dialog mount if there is no find text provided
193
- if (!this.props.findText) {
194
- this.focusFindTextfield();
195
- }
196
- this.syncFindText(() => {
197
- // focus after input is synced if find text provided
198
- if (this.props.findText) {
199
- this.focusFindTextfield();
200
- }
201
- });
202
- }
203
- componentDidUpdate(prevProps) {
204
- // focus on update if find text did not change
205
- if (!getBooleanFF('platform.editor.a11y-find-replace')) {
206
- var _this$state2;
207
- if (this.props.findText === ((_this$state2 = this.state) === null || _this$state2 === void 0 ? void 0 : _this$state2.localFindText)) {
208
- this.focusFindTextfield();
209
- }
210
- if (this.props.findText !== prevProps.findText) {
211
- this.syncFindText(() => {
212
- // focus after input is synced if find text provided
213
- if (this.props.findText) {
214
- this.focusFindTextfield();
215
- }
216
- });
217
- }
218
- }
219
- }
220
- componentWillUnmount() {
221
- this.debouncedFind.cancel();
222
- this.handleFindKeyDownThrottled.cancel();
223
- }
224
- render() {
225
- const {
226
- findText,
227
- count,
228
- allowMatchCase,
229
- shouldMatchCase,
230
- intl: {
231
- formatMessage
232
- }
233
- } = this.props;
234
- const resultsCount = formatMessage(messages.resultsCount, {
235
- selectedMatchPosition: count.index + 1,
236
- totalResultsCount: count.total
237
- });
238
- return jsx("div", {
239
- css: sectionWrapperStyles
240
- }, jsx(Textfield, {
241
- name: "find",
242
- appearance: "none",
243
- placeholder: this.find,
244
- value: this.state.localFindText,
245
- ref: this.findTextfieldRef,
246
- autoComplete: "off",
247
- onChange: this.handleFindChange,
248
- onKeyDown: this.handleFindKeyDown,
249
- onKeyUp: this.handleFindKeyUp,
250
- onBlur: this.props.onFindBlur,
251
- onCompositionStart: this.handleCompositionStart,
252
- onCompositionEnd: this.handleCompositionEnd
253
- }), jsx("div", {
254
- css: countWrapperStyles,
255
- "aria-live": "polite"
256
- }, findText && jsx("span", {
257
- "data-testid": "textfield-count",
258
- css: countStyles
259
- }, count.total === 0 ? this.noResultsFound : resultsCount)), allowMatchCase && jsx(FindReplaceTooltipButton, {
260
- title: this.matchCase,
261
- icon: this.matchCaseIcon,
262
- onClick: this.handleMatchCaseClick,
263
- isPressed: shouldMatchCase
264
- }), jsx(FindReplaceTooltipButton, {
265
- title: this.findNext,
266
- icon: this.findNextIcon,
267
- keymapDescription: 'Enter',
268
- onClick: this.handleFindNextClick,
269
- disabled: count.total <= 1
270
- }), jsx(FindReplaceTooltipButton, {
271
- title: this.findPrevious,
272
- icon: this.findPrevIcon,
273
- keymapDescription: 'Shift Enter',
274
- onClick: this.handleFindPrevClick,
275
- disabled: count.total <= 1
276
- }), jsx(FindReplaceTooltipButton, {
277
- title: this.closeFindReplaceDialog,
278
- icon: this.closeIcon,
279
- keymapDescription: 'Escape',
280
- onClick: this.clearSearch
281
- }));
282
- }
283
- }
284
- export default injectIntl(Find);
@@ -1,78 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- /** @jsx jsx */
3
- import React from 'react';
4
- import { jsx } from '@emotion/react';
5
- import Find from './Find';
6
- import Replace from './Replace';
7
- import { ruleStyles, wrapperStyles } from './styles';
8
- class FindReplace extends React.PureComponent {
9
- constructor(...args) {
10
- super(...args);
11
- _defineProperty(this, "findTextfield", null);
12
- _defineProperty(this, "replaceTextfield", null);
13
- _defineProperty(this, "setFindTextfieldRef", findTextfieldRef => {
14
- this.findTextfield = findTextfieldRef.current;
15
- });
16
- _defineProperty(this, "setReplaceTextfieldRef", replaceTextfieldRef => {
17
- this.replaceTextfield = replaceTextfieldRef.current;
18
- });
19
- _defineProperty(this, "setFocusToFind", () => {
20
- if (this.findTextfield) {
21
- this.findTextfield.focus();
22
- }
23
- });
24
- _defineProperty(this, "setFocusToReplace", () => {
25
- if (this.replaceTextfield) {
26
- this.replaceTextfield.focus();
27
- }
28
- });
29
- }
30
- render() {
31
- const {
32
- findText,
33
- count,
34
- shouldFocus,
35
- onFind,
36
- onFindBlur,
37
- onFindNext,
38
- onFindPrev,
39
- onCancel,
40
- replaceText,
41
- onReplace,
42
- onReplaceAll,
43
- dispatchAnalyticsEvent,
44
- allowMatchCase,
45
- shouldMatchCase,
46
- onToggleMatchCase
47
- } = this.props;
48
- return jsx("div", {
49
- css: wrapperStyles
50
- }, jsx(Find, {
51
- allowMatchCase: allowMatchCase,
52
- shouldMatchCase: shouldMatchCase,
53
- onToggleMatchCase: onToggleMatchCase,
54
- findText: findText,
55
- count: count,
56
- shouldFocus: shouldFocus,
57
- onFind: onFind,
58
- onFindBlur: onFindBlur,
59
- onFindPrev: onFindPrev,
60
- onFindNext: onFindNext,
61
- onFindTextfieldRefSet: this.setFindTextfieldRef,
62
- onCancel: onCancel,
63
- onArrowDown: this.setFocusToReplace
64
- }), jsx("hr", {
65
- css: ruleStyles,
66
- id: "replace-hr-element"
67
- }), jsx(Replace, {
68
- canReplace: count.total > 0,
69
- replaceText: replaceText,
70
- onReplace: onReplace,
71
- onReplaceAll: onReplaceAll,
72
- onReplaceTextfieldRefSet: this.setReplaceTextfieldRef,
73
- onArrowUp: this.setFocusToFind,
74
- dispatchAnalyticsEvent: dispatchAnalyticsEvent
75
- }));
76
- }
77
- }
78
- export default FindReplace;
@@ -1,122 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- /** @jsx jsx */
4
- import React from 'react';
5
- import { css, jsx } from '@emotion/react';
6
- import { defineMessages, injectIntl } from 'react-intl-next';
7
- import { akEditorFloatingPanelZIndex, akEditorMobileMaxWidth } from '@atlaskit/editor-shared-styles';
8
- import { ToolbarButton, TOOLBAR_BUTTON } from '@atlaskit/editor-common/ui-menu';
9
- import { Dropdown, ArrowKeyNavigationType } from '@atlaskit/editor-common/ui-menu';
10
- import EditorSearchIcon from '@atlaskit/icon/glyph/editor/search';
11
- import FindReplace from './FindReplace';
12
- import { TRIGGER_METHOD } from '@atlaskit/editor-common/analytics';
13
- import { ToolTipContent, findKeymapByDescription, tooltip } from '../../../keymaps';
14
- import { getAriaKeyshortcuts } from '@atlaskit/editor-common/keymaps';
15
- const toolbarButtonWrapper = css`
16
- display: flex;
17
- flex: 1 1 auto;
18
- flex-grow: 0;
19
- justify-content: flex-end;
20
- align-items: center;
21
- padding: 0 ${"var(--ds-space-100, 8px)"};
22
- @media (max-width: ${akEditorMobileMaxWidth}px) {
23
- justify-content: center;
24
- padding: 0;
25
- }
26
- `;
27
- const toolbarButtonWrapperFullWith = css`
28
- flex-grow: 1;
29
- `;
30
- const wrapper = css`
31
- display: flex;
32
- flex-direction: column;
33
- `;
34
- const messages = defineMessages({
35
- findReplaceToolbarButton: {
36
- id: 'fabric.editor.findReplaceToolbarButton',
37
- defaultMessage: 'Find and replace',
38
- description: '"Find" highlights all instances of a word or phrase on the document, and "Replace" changes one or all of those instances to something else'
39
- }
40
- });
41
- class FindReplaceToolbarButton extends React.PureComponent {
42
- constructor(...args) {
43
- super(...args);
44
- _defineProperty(this, "toggleOpen", () => {
45
- if (this.props.isActive) {
46
- this.props.onCancel({
47
- triggerMethod: TRIGGER_METHOD.TOOLBAR
48
- });
49
- } else {
50
- this.props.onActivate();
51
- }
52
- });
53
- }
54
- render() {
55
- const {
56
- popupsMountPoint,
57
- popupsBoundariesElement,
58
- popupsScrollableElement,
59
- isReducedSpacing,
60
- findText,
61
- replaceText,
62
- isActive,
63
- index,
64
- numMatches,
65
- intl: {
66
- formatMessage
67
- },
68
- takeFullWidth
69
- } = this.props;
70
- const title = formatMessage(messages.findReplaceToolbarButton);
71
- const stackBelowOtherEditorFloatingPanels = akEditorFloatingPanelZIndex - 1;
72
- const keymap = findKeymapByDescription('Find');
73
- return jsx("div", {
74
- css: [toolbarButtonWrapper, takeFullWidth && toolbarButtonWrapperFullWith]
75
- }, jsx(Dropdown, {
76
- mountTo: popupsMountPoint,
77
- boundariesElement: popupsBoundariesElement,
78
- scrollableElement: popupsScrollableElement,
79
- isOpen: isActive,
80
- handleEscapeKeydown: () => {
81
- if (isActive) {
82
- this.props.onCancel({
83
- triggerMethod: TRIGGER_METHOD.KEYBOARD
84
- });
85
- }
86
- },
87
- fitWidth: 352,
88
- zIndex: stackBelowOtherEditorFloatingPanels,
89
- arrowKeyNavigationProviderOptions: {
90
- type: ArrowKeyNavigationType.MENU,
91
- disableArrowKeyNavigation: true
92
- },
93
- trigger: jsx(ToolbarButton, {
94
- buttonId: TOOLBAR_BUTTON.FIND_REPLACE,
95
- spacing: isReducedSpacing ? 'none' : 'default',
96
- selected: isActive,
97
- title: jsx(ToolTipContent, {
98
- description: title,
99
- keymap: keymap
100
- }),
101
- iconBefore: jsx(EditorSearchIcon, {
102
- label: title
103
- }),
104
- onClick: this.toggleOpen,
105
- "aria-expanded": isActive,
106
- "aria-haspopup": true,
107
- "aria-label": keymap ? tooltip(keymap, title) : title,
108
- "aria-keyshortcuts": getAriaKeyshortcuts(keymap)
109
- })
110
- }, jsx("div", {
111
- css: wrapper
112
- }, jsx(FindReplace, _extends({
113
- findText: findText,
114
- replaceText: replaceText,
115
- count: {
116
- index,
117
- total: numMatches
118
- }
119
- }, this.props)))));
120
- }
121
- }
122
- export default injectIntl(FindReplaceToolbarButton);