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