@atlaskit/editor-plugin-find-replace 6.0.9 → 6.1.1

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.
@@ -1,7 +1,3 @@
1
- /**
2
- * @jsxRuntime classic
3
- * @jsx jsx
4
- */
5
1
  import React from 'react';
6
2
  import type { WrappedComponentProps } from 'react-intl-next';
7
3
  import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
@@ -37,13 +33,6 @@ export type ReplaceProps = {
37
33
  replaceText?: string;
38
34
  setFindTyped: (value: boolean) => void;
39
35
  };
40
- export type ReplaceState = {
41
- fakeSuccessReplacementMessageUpdate: boolean;
42
- isComposing: boolean;
43
- isHelperMessageVisible: boolean;
44
- replaceCount: number;
45
- replaceText: string;
46
- };
47
36
  declare const _default: React.FC<import("react-intl-next").WithIntlProps<ReplaceProps & WrappedComponentProps>> & {
48
37
  WrappedComponent: React.ComponentType<ReplaceProps & WrappedComponentProps>;
49
38
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-find-replace",
3
- "version": "6.0.9",
3
+ "version": "6.1.1",
4
4
  "description": "find replace plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -35,18 +35,18 @@
35
35
  "@atlaskit/editor-plugin-mentions": "^8.2.0",
36
36
  "@atlaskit/editor-plugin-primary-toolbar": "^7.0.0",
37
37
  "@atlaskit/editor-prosemirror": "7.0.0",
38
- "@atlaskit/editor-shared-styles": "^3.9.0",
39
- "@atlaskit/form": "^14.2.0",
38
+ "@atlaskit/editor-shared-styles": "^3.10.0",
39
+ "@atlaskit/form": "^14.3.0",
40
40
  "@atlaskit/icon": "^29.0.0",
41
41
  "@atlaskit/icon-lab": "^5.12.0",
42
42
  "@atlaskit/mention": "^24.4.0",
43
43
  "@atlaskit/platform-feature-flags": "^1.1.0",
44
- "@atlaskit/primitives": "^16.1.0",
45
- "@atlaskit/textfield": "^8.0.0",
44
+ "@atlaskit/primitives": "^16.2.0",
45
+ "@atlaskit/textfield": "^8.1.0",
46
46
  "@atlaskit/theme": "^21.0.0",
47
- "@atlaskit/tmp-editor-statsig": "^13.36.0",
48
- "@atlaskit/tokens": "^8.0.0",
49
- "@atlaskit/tooltip": "^20.8.0",
47
+ "@atlaskit/tmp-editor-statsig": "^13.41.0",
48
+ "@atlaskit/tokens": "^8.2.0",
49
+ "@atlaskit/tooltip": "^20.10.0",
50
50
  "@babel/runtime": "^7.0.0",
51
51
  "@emotion/react": "^11.7.1",
52
52
  "classnames": "^2.2.5",
@@ -64,7 +64,7 @@
64
64
  "react-dom": "^18.2.0"
65
65
  },
66
66
  "peerDependencies": {
67
- "@atlaskit/editor-common": "^110.27.0",
67
+ "@atlaskit/editor-common": "^110.33.0",
68
68
  "react": "^18.2.0",
69
69
  "react-intl-next": "npm:react-intl@^5.18.1"
70
70
  },
@@ -115,9 +115,6 @@
115
115
  "platform_editor_toolbar_responsive_fixes": {
116
116
  "type": "boolean"
117
117
  },
118
- "editor_a11y_refactor_find_replace_style": {
119
- "type": "boolean"
120
- },
121
118
  "platform_editor_a11y_find_replace_focus_fix": {
122
119
  "type": "boolean"
123
120
  }
@@ -1,277 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
- var _react = _interopRequireWildcard(require("react"));
11
- var _reactIntlNext = require("react-intl-next");
12
- var _new = _interopRequireDefault(require("@atlaskit/button/new"));
13
- var _analytics = require("@atlaskit/editor-common/analytics");
14
- var _messages = require("@atlaskit/editor-common/messages");
15
- var _form = require("@atlaskit/form");
16
- var _chevronDownHipchatChevronDown = _interopRequireDefault(require("@atlaskit/icon/core/migration/chevron-down--hipchat-chevron-down"));
17
- var _chevronUpHipchatChevronUp = _interopRequireDefault(require("@atlaskit/icon/core/migration/chevron-up--hipchat-chevron-up"));
18
- var _primitives = require("@atlaskit/primitives");
19
- var _textfield = _interopRequireDefault(require("@atlaskit/textfield"));
20
- var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
21
- var _FindReplaceTooltipButton = require("./FindReplaceTooltipButton");
22
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
23
- // eslint-disable-next-line @atlaskit/design-system/no-emotion-primitives -- to be migrated to @atlaskit/primitives/compiled – go/akcss
24
-
25
- var replaceContainerStyles = (0, _primitives.xcss)({
26
- padding: 'space.100'
27
- });
28
- var replaceWithLabelStyle = (0, _primitives.xcss)({
29
- paddingBottom: 'space.050'
30
- });
31
- var actionButtonContainerStyles = (0, _primitives.xcss)({
32
- paddingTop: 'space.200'
33
- });
34
- var actionButtonParentInlineStyles = (0, _primitives.xcss)({
35
- justifyContent: 'space-between',
36
- flexDirection: 'row-reverse'
37
- });
38
- var actionButtonParentInlineStylesNew = (0, _primitives.xcss)({
39
- justifyContent: 'space-between',
40
- flexDirection: 'row-reverse',
41
- flexWrap: 'wrap'
42
- });
43
- var actionButtonInlineStyles = (0, _primitives.xcss)({
44
- gap: 'space.075'
45
- });
46
- var closeButtonInlineStyles = (0, _primitives.xcss)({
47
- marginRight: 'auto'
48
- });
49
- var Replace = function Replace(_ref) {
50
- var canReplace = _ref.canReplace,
51
- initialReplaceText = _ref.replaceText,
52
- onReplace = _ref.onReplace,
53
- onReplaceAll = _ref.onReplaceAll,
54
- onReplaceTextfieldRefSet = _ref.onReplaceTextfieldRefSet,
55
- onArrowUp = _ref.onArrowUp,
56
- onCancel = _ref.onCancel,
57
- count = _ref.count,
58
- onFindNext = _ref.onFindNext,
59
- onFindPrev = _ref.onFindPrev,
60
- dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
61
- setFindTyped = _ref.setFindTyped,
62
- findTyped = _ref.findTyped,
63
- focusToolbarButton = _ref.focusToolbarButton,
64
- formatMessage = _ref.intl.formatMessage;
65
- var _useState = (0, _react.useState)(initialReplaceText || ''),
66
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
67
- replaceText = _useState2[0],
68
- setReplaceText = _useState2[1];
69
- var _useState3 = (0, _react.useState)(false),
70
- _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
71
- isComposing = _useState4[0],
72
- setIsComposing = _useState4[1];
73
- var _useState5 = (0, _react.useState)(false),
74
- _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
75
- isHelperMessageVisible = _useState6[0],
76
- setIsHelperMessageVisible = _useState6[1];
77
- var _useState7 = (0, _react.useState)(false),
78
- _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
79
- fakeSuccessReplacementMessageUpdate = _useState8[0],
80
- setFakeSuccessReplacementMessageUpdate = _useState8[1];
81
- var _useState9 = (0, _react.useState)(0),
82
- _useState0 = (0, _slicedToArray2.default)(_useState9, 2),
83
- replaceCount = _useState0[0],
84
- setReplaceCount = _useState0[1];
85
- var replaceTextfieldRef = (0, _react.useRef)(null);
86
- var successReplacementMessageRef = (0, _react.useRef)(null);
87
- var replaceWith = formatMessage(_messages.findReplaceMessages.replaceWith);
88
- var replaceAll = formatMessage(_messages.findReplaceMessages.replaceAll);
89
- var findPrevious = formatMessage(_messages.findReplaceMessages.findPrevious);
90
- var closeFindReplaceDialog = formatMessage(_messages.findReplaceMessages.closeFindReplaceDialog);
91
- (0, _react.useEffect)(function () {
92
- onReplaceTextfieldRefSet(replaceTextfieldRef);
93
- }, [onReplaceTextfieldRefSet]);
94
- (0, _react.useEffect)(function () {
95
- setReplaceText(initialReplaceText || '');
96
- }, [initialReplaceText]);
97
- var skipWhileComposing = function skipWhileComposing(fn) {
98
- if (!isComposing) {
99
- fn();
100
- }
101
- };
102
- var triggerSuccessReplacementMessageUpdate = function triggerSuccessReplacementMessageUpdate(currentReplaceCount) {
103
- if (replaceCount === currentReplaceCount) {
104
- setFakeSuccessReplacementMessageUpdate(!fakeSuccessReplacementMessageUpdate);
105
- }
106
- if (successReplacementMessageRef.current) {
107
- var ariaLiveRegion = successReplacementMessageRef.current.querySelector('[aria-live="polite"]');
108
- ariaLiveRegion === null || ariaLiveRegion === void 0 || ariaLiveRegion.removeAttribute('aria-live');
109
- ariaLiveRegion === null || ariaLiveRegion === void 0 || ariaLiveRegion.setAttribute('aria-live', 'polite');
110
- }
111
- };
112
- var handleReplaceClick = function handleReplaceClick() {
113
- return skipWhileComposing(function () {
114
- onReplace({
115
- triggerMethod: _analytics.TRIGGER_METHOD.BUTTON,
116
- replaceText: replaceText
117
- });
118
- triggerSuccessReplacementMessageUpdate(1);
119
- setIsHelperMessageVisible(true);
120
- setReplaceCount(1);
121
- setFindTyped(false);
122
- });
123
- };
124
- var handleReplaceChange = function handleReplaceChange(event) {
125
- return skipWhileComposing(function () {
126
- updateReplaceValue(event.target.value);
127
- });
128
- };
129
- var updateReplaceValue = function updateReplaceValue(text) {
130
- if (dispatchAnalyticsEvent) {
131
- dispatchAnalyticsEvent({
132
- eventType: _analytics.EVENT_TYPE.TRACK,
133
- action: _analytics.ACTION.CHANGED_REPLACEMENT_TEXT,
134
- actionSubject: _analytics.ACTION_SUBJECT.FIND_REPLACE_DIALOG
135
- });
136
- }
137
- setReplaceText(text);
138
- };
139
- var handleReplaceKeyDown = function handleReplaceKeyDown(event) {
140
- return skipWhileComposing(function () {
141
- if (event.key === 'Enter') {
142
- onReplace({
143
- triggerMethod: _analytics.TRIGGER_METHOD.KEYBOARD,
144
- replaceText: replaceText
145
- });
146
- } else if (event.key === 'ArrowUp') {
147
- onArrowUp();
148
- }
149
- });
150
- };
151
- var handleReplaceAllClick = function handleReplaceAllClick() {
152
- return skipWhileComposing(function () {
153
- onReplaceAll({
154
- replaceText: replaceText
155
- });
156
- setIsHelperMessageVisible(true);
157
- if (count.totalReplaceable && (0, _expValEquals.expValEquals)('platform_editor_find_and_replace_improvements', 'isEnabled', true)) {
158
- triggerSuccessReplacementMessageUpdate(count.totalReplaceable);
159
- setReplaceCount(count.totalReplaceable);
160
- } else {
161
- triggerSuccessReplacementMessageUpdate(count.total);
162
- setReplaceCount(count.total);
163
- }
164
- setFindTyped(false);
165
- });
166
- };
167
- var handleCompositionStart = function handleCompositionStart() {
168
- setIsComposing(true);
169
- };
170
- var handleCompositionEnd = function handleCompositionEnd(event) {
171
- setIsComposing(false);
172
- updateReplaceValue(event.currentTarget.value);
173
- };
174
- var clearSearch = function clearSearch() {
175
- onCancel({
176
- triggerMethod: _analytics.TRIGGER_METHOD.BUTTON
177
- });
178
- focusToolbarButton();
179
- };
180
- var handleFindNextClick = function handleFindNextClick() {
181
- if (!isComposing) {
182
- onFindNext({
183
- triggerMethod: _analytics.TRIGGER_METHOD.BUTTON
184
- });
185
- }
186
- };
187
- var handleFindPrevClick = function handleFindPrevClick() {
188
- if (!isComposing) {
189
- onFindPrev({
190
- triggerMethod: _analytics.TRIGGER_METHOD.BUTTON
191
- });
192
- }
193
- };
194
- var resultsReplace = formatMessage(_messages.findReplaceMessages.replaceSuccess, {
195
- numberOfMatches: replaceCount
196
- });
197
- return /*#__PURE__*/_react.default.createElement(_primitives.Box, {
198
- xcss: replaceContainerStyles
199
- }, /*#__PURE__*/_react.default.createElement(_primitives.Box, {
200
- xcss: replaceWithLabelStyle
201
- }, /*#__PURE__*/_react.default.createElement(_primitives.Text, {
202
- id: "replace-text-field-label",
203
- size: "medium",
204
- weight: "bold",
205
- color: "color.text.subtle"
206
- }, replaceWith)), /*#__PURE__*/_react.default.createElement(_textfield.default, {
207
- name: "replace",
208
- "aria-labelledby": "replace-text-field-label",
209
- testId: "replace-field",
210
- appearance: "standard",
211
- defaultValue: replaceText,
212
- ref: replaceTextfieldRef,
213
- autoComplete: "off",
214
- onChange: handleReplaceChange,
215
- onKeyDown: handleReplaceKeyDown,
216
- onCompositionStart: handleCompositionStart,
217
- onCompositionEnd: handleCompositionEnd
218
- }), isHelperMessageVisible && !findTyped && /*#__PURE__*/_react.default.createElement("div", {
219
- ref: successReplacementMessageRef
220
- }, /*#__PURE__*/_react.default.createElement(_form.ValidMessage, {
221
- testId: "message-success-replacement"
222
- }, fakeSuccessReplacementMessageUpdate ?
223
- // @ts-ignore - TS1501 TypeScript 5.9.2 upgrade
224
- resultsReplace.replace(/ /, "\xA0") : resultsReplace)), /*#__PURE__*/_react.default.createElement(_primitives.Box, {
225
- xcss: actionButtonContainerStyles
226
- }, /*#__PURE__*/_react.default.createElement(_primitives.Inline, {
227
- xcss: (0, _expValEquals.expValEquals)('platform_editor_find_and_replace_improvements', 'isEnabled', true) ? [actionButtonInlineStyles, actionButtonParentInlineStylesNew] : [actionButtonInlineStyles, actionButtonParentInlineStyles]
228
- }, /*#__PURE__*/_react.default.createElement(_primitives.Inline, {
229
- xcss: actionButtonInlineStyles
230
- }, /*#__PURE__*/_react.default.createElement(_FindReplaceTooltipButton.FindReplaceTooltipButton, {
231
- title: formatMessage(_messages.findReplaceMessages.findNext),
232
- icon: function icon(iconProps) {
233
- return /*#__PURE__*/_react.default.createElement(_chevronDownHipchatChevronDown.default, {
234
- label: iconProps.label,
235
- size: "small"
236
- });
237
- },
238
- iconLabel: formatMessage(_messages.findReplaceMessages.findNext),
239
- keymapDescription: 'Enter',
240
- onClick: handleFindNextClick,
241
- disabled: count.total <= 1
242
- }), /*#__PURE__*/_react.default.createElement(_FindReplaceTooltipButton.FindReplaceTooltipButton, {
243
- title: findPrevious,
244
- icon: function icon(iconProps) {
245
- return /*#__PURE__*/_react.default.createElement(_chevronUpHipchatChevronUp.default, {
246
- label: iconProps.label,
247
- size: "small"
248
- });
249
- },
250
- iconLabel: findPrevious,
251
- keymapDescription: 'Shift Enter',
252
- onClick: handleFindPrevClick,
253
- disabled: count.total <= 1
254
- }), /*#__PURE__*/_react.default.createElement(_new.default, {
255
- testId: 'Replace',
256
- id: "replace-button",
257
- onClick: handleReplaceClick,
258
- isDisabled: !canReplace
259
- }, formatMessage(_messages.findReplaceMessages.replace)), /*#__PURE__*/_react.default.createElement(_new.default, {
260
- appearance: "primary",
261
- testId: replaceAll,
262
- id: "replaceAll-button",
263
- onClick: handleReplaceAllClick,
264
- isDisabled: (0, _expValEquals.expValEquals)('platform_editor_find_and_replace_improvements', 'isEnabled', true) ? count.totalReplaceable === 0 : !canReplace
265
- }, replaceAll)), (0, _expValEquals.expValEquals)('platform_editor_find_and_replace_improvements', 'isEnabled', true) ? /*#__PURE__*/_react.default.createElement(_primitives.Inline, {
266
- xcss: closeButtonInlineStyles
267
- }, /*#__PURE__*/_react.default.createElement(_new.default, {
268
- appearance: "subtle",
269
- testId: closeFindReplaceDialog,
270
- onClick: clearSearch
271
- }, closeFindReplaceDialog)) : /*#__PURE__*/_react.default.createElement(_new.default, {
272
- appearance: "subtle",
273
- testId: closeFindReplaceDialog,
274
- onClick: clearSearch
275
- }, closeFindReplaceDialog))));
276
- };
277
- var _default = exports.default = (0, _reactIntlNext.injectIntl)(Replace);
@@ -1,242 +0,0 @@
1
- import React, { useState, useRef, useEffect } from 'react';
2
- import { injectIntl } from 'react-intl-next';
3
- import Button from '@atlaskit/button/new';
4
- import { ACTION, ACTION_SUBJECT, EVENT_TYPE, TRIGGER_METHOD } from '@atlaskit/editor-common/analytics';
5
- import { findReplaceMessages as messages } from '@atlaskit/editor-common/messages';
6
- import { ValidMessage } from '@atlaskit/form';
7
- import ChevronDownIcon from '@atlaskit/icon/core/migration/chevron-down--hipchat-chevron-down';
8
- import ChevronUpIcon from '@atlaskit/icon/core/migration/chevron-up--hipchat-chevron-up';
9
- // eslint-disable-next-line @atlaskit/design-system/no-emotion-primitives -- to be migrated to @atlaskit/primitives/compiled – go/akcss
10
- import { Box, Inline, Text, xcss } from '@atlaskit/primitives';
11
- import Textfield from '@atlaskit/textfield';
12
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
13
- import { FindReplaceTooltipButton } from './FindReplaceTooltipButton';
14
- const replaceContainerStyles = xcss({
15
- padding: 'space.100'
16
- });
17
- const replaceWithLabelStyle = xcss({
18
- paddingBottom: 'space.050'
19
- });
20
- const actionButtonContainerStyles = xcss({
21
- paddingTop: 'space.200'
22
- });
23
- const actionButtonParentInlineStyles = xcss({
24
- justifyContent: 'space-between',
25
- flexDirection: 'row-reverse'
26
- });
27
- const actionButtonParentInlineStylesNew = xcss({
28
- justifyContent: 'space-between',
29
- flexDirection: 'row-reverse',
30
- flexWrap: 'wrap'
31
- });
32
- const actionButtonInlineStyles = xcss({
33
- gap: 'space.075'
34
- });
35
- const closeButtonInlineStyles = xcss({
36
- marginRight: 'auto'
37
- });
38
- const Replace = ({
39
- canReplace,
40
- replaceText: initialReplaceText,
41
- onReplace,
42
- onReplaceAll,
43
- onReplaceTextfieldRefSet,
44
- onArrowUp,
45
- onCancel,
46
- count,
47
- onFindNext,
48
- onFindPrev,
49
- dispatchAnalyticsEvent,
50
- setFindTyped,
51
- findTyped,
52
- focusToolbarButton,
53
- intl: {
54
- formatMessage
55
- }
56
- }) => {
57
- const [replaceText, setReplaceText] = useState(initialReplaceText || '');
58
- const [isComposing, setIsComposing] = useState(false);
59
- const [isHelperMessageVisible, setIsHelperMessageVisible] = useState(false);
60
- const [fakeSuccessReplacementMessageUpdate, setFakeSuccessReplacementMessageUpdate] = useState(false);
61
- const [replaceCount, setReplaceCount] = useState(0);
62
- const replaceTextfieldRef = useRef(null);
63
- const successReplacementMessageRef = useRef(null);
64
- const replaceWith = formatMessage(messages.replaceWith);
65
- const replaceAll = formatMessage(messages.replaceAll);
66
- const findPrevious = formatMessage(messages.findPrevious);
67
- const closeFindReplaceDialog = formatMessage(messages.closeFindReplaceDialog);
68
- useEffect(() => {
69
- onReplaceTextfieldRefSet(replaceTextfieldRef);
70
- }, [onReplaceTextfieldRefSet]);
71
- useEffect(() => {
72
- setReplaceText(initialReplaceText || '');
73
- }, [initialReplaceText]);
74
- const skipWhileComposing = fn => {
75
- if (!isComposing) {
76
- fn();
77
- }
78
- };
79
- const triggerSuccessReplacementMessageUpdate = currentReplaceCount => {
80
- if (replaceCount === currentReplaceCount) {
81
- setFakeSuccessReplacementMessageUpdate(!fakeSuccessReplacementMessageUpdate);
82
- }
83
- if (successReplacementMessageRef.current) {
84
- const ariaLiveRegion = successReplacementMessageRef.current.querySelector('[aria-live="polite"]');
85
- ariaLiveRegion === null || ariaLiveRegion === void 0 ? void 0 : ariaLiveRegion.removeAttribute('aria-live');
86
- ariaLiveRegion === null || ariaLiveRegion === void 0 ? void 0 : ariaLiveRegion.setAttribute('aria-live', 'polite');
87
- }
88
- };
89
- const handleReplaceClick = () => skipWhileComposing(() => {
90
- onReplace({
91
- triggerMethod: TRIGGER_METHOD.BUTTON,
92
- replaceText
93
- });
94
- triggerSuccessReplacementMessageUpdate(1);
95
- setIsHelperMessageVisible(true);
96
- setReplaceCount(1);
97
- setFindTyped(false);
98
- });
99
- const handleReplaceChange = event => skipWhileComposing(() => {
100
- updateReplaceValue(event.target.value);
101
- });
102
- const updateReplaceValue = text => {
103
- if (dispatchAnalyticsEvent) {
104
- dispatchAnalyticsEvent({
105
- eventType: EVENT_TYPE.TRACK,
106
- action: ACTION.CHANGED_REPLACEMENT_TEXT,
107
- actionSubject: ACTION_SUBJECT.FIND_REPLACE_DIALOG
108
- });
109
- }
110
- setReplaceText(text);
111
- };
112
- const handleReplaceKeyDown = event => skipWhileComposing(() => {
113
- if (event.key === 'Enter') {
114
- onReplace({
115
- triggerMethod: TRIGGER_METHOD.KEYBOARD,
116
- replaceText
117
- });
118
- } else if (event.key === 'ArrowUp') {
119
- onArrowUp();
120
- }
121
- });
122
- const handleReplaceAllClick = () => skipWhileComposing(() => {
123
- onReplaceAll({
124
- replaceText
125
- });
126
- setIsHelperMessageVisible(true);
127
- if (count.totalReplaceable && expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true)) {
128
- triggerSuccessReplacementMessageUpdate(count.totalReplaceable);
129
- setReplaceCount(count.totalReplaceable);
130
- } else {
131
- triggerSuccessReplacementMessageUpdate(count.total);
132
- setReplaceCount(count.total);
133
- }
134
- setFindTyped(false);
135
- });
136
- const handleCompositionStart = () => {
137
- setIsComposing(true);
138
- };
139
- const handleCompositionEnd = event => {
140
- setIsComposing(false);
141
- updateReplaceValue(event.currentTarget.value);
142
- };
143
- const clearSearch = () => {
144
- onCancel({
145
- triggerMethod: TRIGGER_METHOD.BUTTON
146
- });
147
- focusToolbarButton();
148
- };
149
- const handleFindNextClick = () => {
150
- if (!isComposing) {
151
- onFindNext({
152
- triggerMethod: TRIGGER_METHOD.BUTTON
153
- });
154
- }
155
- };
156
- const handleFindPrevClick = () => {
157
- if (!isComposing) {
158
- onFindPrev({
159
- triggerMethod: TRIGGER_METHOD.BUTTON
160
- });
161
- }
162
- };
163
- const resultsReplace = formatMessage(messages.replaceSuccess, {
164
- numberOfMatches: replaceCount
165
- });
166
- return /*#__PURE__*/React.createElement(Box, {
167
- xcss: replaceContainerStyles
168
- }, /*#__PURE__*/React.createElement(Box, {
169
- xcss: replaceWithLabelStyle
170
- }, /*#__PURE__*/React.createElement(Text, {
171
- id: "replace-text-field-label",
172
- size: "medium",
173
- weight: "bold",
174
- color: "color.text.subtle"
175
- }, replaceWith)), /*#__PURE__*/React.createElement(Textfield, {
176
- name: "replace",
177
- "aria-labelledby": "replace-text-field-label",
178
- testId: "replace-field",
179
- appearance: "standard",
180
- defaultValue: replaceText,
181
- ref: replaceTextfieldRef,
182
- autoComplete: "off",
183
- onChange: handleReplaceChange,
184
- onKeyDown: handleReplaceKeyDown,
185
- onCompositionStart: handleCompositionStart,
186
- onCompositionEnd: handleCompositionEnd
187
- }), isHelperMessageVisible && !findTyped && /*#__PURE__*/React.createElement("div", {
188
- ref: successReplacementMessageRef
189
- }, /*#__PURE__*/React.createElement(ValidMessage, {
190
- testId: "message-success-replacement"
191
- }, fakeSuccessReplacementMessageUpdate ?
192
- // @ts-ignore - TS1501 TypeScript 5.9.2 upgrade
193
- resultsReplace.replace(/ /u, '\u00a0') : resultsReplace)), /*#__PURE__*/React.createElement(Box, {
194
- xcss: actionButtonContainerStyles
195
- }, /*#__PURE__*/React.createElement(Inline, {
196
- xcss: expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true) ? [actionButtonInlineStyles, actionButtonParentInlineStylesNew] : [actionButtonInlineStyles, actionButtonParentInlineStyles]
197
- }, /*#__PURE__*/React.createElement(Inline, {
198
- xcss: actionButtonInlineStyles
199
- }, /*#__PURE__*/React.createElement(FindReplaceTooltipButton, {
200
- title: formatMessage(messages.findNext),
201
- icon: iconProps => /*#__PURE__*/React.createElement(ChevronDownIcon, {
202
- label: iconProps.label,
203
- size: "small"
204
- }),
205
- iconLabel: formatMessage(messages.findNext),
206
- keymapDescription: 'Enter',
207
- onClick: handleFindNextClick,
208
- disabled: count.total <= 1
209
- }), /*#__PURE__*/React.createElement(FindReplaceTooltipButton, {
210
- title: findPrevious,
211
- icon: iconProps => /*#__PURE__*/React.createElement(ChevronUpIcon, {
212
- label: iconProps.label,
213
- size: "small"
214
- }),
215
- iconLabel: findPrevious,
216
- keymapDescription: 'Shift Enter',
217
- onClick: handleFindPrevClick,
218
- disabled: count.total <= 1
219
- }), /*#__PURE__*/React.createElement(Button, {
220
- testId: 'Replace',
221
- id: "replace-button",
222
- onClick: handleReplaceClick,
223
- isDisabled: !canReplace
224
- }, formatMessage(messages.replace)), /*#__PURE__*/React.createElement(Button, {
225
- appearance: "primary",
226
- testId: replaceAll,
227
- id: "replaceAll-button",
228
- onClick: handleReplaceAllClick,
229
- isDisabled: expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true) ? count.totalReplaceable === 0 : !canReplace
230
- }, replaceAll)), expValEquals('platform_editor_find_and_replace_improvements', 'isEnabled', true) ? /*#__PURE__*/React.createElement(Inline, {
231
- xcss: closeButtonInlineStyles
232
- }, /*#__PURE__*/React.createElement(Button, {
233
- appearance: "subtle",
234
- testId: closeFindReplaceDialog,
235
- onClick: clearSearch
236
- }, closeFindReplaceDialog)) : /*#__PURE__*/React.createElement(Button, {
237
- appearance: "subtle",
238
- testId: closeFindReplaceDialog,
239
- onClick: clearSearch
240
- }, closeFindReplaceDialog))));
241
- };
242
- export default injectIntl(Replace);