@atlaskit/editor-plugin-find-replace 2.2.4 → 2.2.5
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.
- package/CHANGELOG.md +10 -0
- package/dist/cjs/ui/FindReplaceDropDownOrToolbarButtonWithState.js +48 -10
- package/dist/cjs/ui/hooks/useFindReplacePluginStateSelector.js +35 -0
- package/dist/es2019/ui/FindReplaceDropDownOrToolbarButtonWithState.js +49 -10
- package/dist/es2019/ui/hooks/useFindReplacePluginStateSelector.js +25 -0
- package/dist/esm/ui/FindReplaceDropDownOrToolbarButtonWithState.js +48 -10
- package/dist/esm/ui/hooks/useFindReplacePluginStateSelector.js +28 -0
- package/dist/types/ui/hooks/useFindReplacePluginStateSelector.d.ts +4 -0
- package/dist/types-ts4.5/ui/hooks/useFindReplacePluginStateSelector.d.ts +4 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-find-replace
|
|
2
2
|
|
|
3
|
+
## 2.2.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#159912](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/159912)
|
|
8
|
+
[`64c9284623ad5`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/64c9284623ad5) -
|
|
9
|
+
[ED-27785] Migrate find-replace plugin to custom non-debounced version of
|
|
10
|
+
useSharedPluginStateSelector
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
3
13
|
## 2.2.4
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -9,10 +9,12 @@ exports.default = void 0;
|
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
12
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
12
13
|
var _commands = require("../pm-plugins/commands");
|
|
13
14
|
var _commandsWithAnalytics = require("../pm-plugins/commands-with-analytics");
|
|
14
15
|
var _FindReplaceDropdown = _interopRequireDefault(require("./FindReplaceDropdown"));
|
|
15
16
|
var _FindReplaceToolbarButton = _interopRequireDefault(require("./FindReplaceToolbarButton"));
|
|
17
|
+
var _useFindReplacePluginStateSelector = require("./hooks/useFindReplacePluginStateSelector");
|
|
16
18
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
17
19
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
20
|
// light implementation of useSharedPluginState(). This is due to findreplace
|
|
@@ -40,6 +42,36 @@ var useSharedPluginStateNoDebounce = function useSharedPluginStateNoDebounce(api
|
|
|
40
42
|
findReplaceState: state
|
|
41
43
|
};
|
|
42
44
|
};
|
|
45
|
+
var useSharedState = (0, _hooks.sharedPluginStateHookMigratorFactory)(function (api) {
|
|
46
|
+
var shouldMatchCase = (0, _useFindReplacePluginStateSelector.useFindReplacePluginStateSelector)(api, 'shouldMatchCase');
|
|
47
|
+
var isActive = (0, _useFindReplacePluginStateSelector.useFindReplacePluginStateSelector)(api, 'isActive');
|
|
48
|
+
var findText = (0, _useFindReplacePluginStateSelector.useFindReplacePluginStateSelector)(api, 'findText');
|
|
49
|
+
var replaceText = (0, _useFindReplacePluginStateSelector.useFindReplacePluginStateSelector)(api, 'replaceText');
|
|
50
|
+
var index = (0, _useFindReplacePluginStateSelector.useFindReplacePluginStateSelector)(api, 'index');
|
|
51
|
+
var matches = (0, _useFindReplacePluginStateSelector.useFindReplacePluginStateSelector)(api, 'matches');
|
|
52
|
+
var shouldFocus = (0, _useFindReplacePluginStateSelector.useFindReplacePluginStateSelector)(api, 'shouldFocus');
|
|
53
|
+
return {
|
|
54
|
+
shouldMatchCase: shouldMatchCase,
|
|
55
|
+
isActive: isActive,
|
|
56
|
+
findText: findText,
|
|
57
|
+
replaceText: replaceText,
|
|
58
|
+
index: index,
|
|
59
|
+
matches: matches,
|
|
60
|
+
shouldFocus: shouldFocus
|
|
61
|
+
};
|
|
62
|
+
}, function (api) {
|
|
63
|
+
var _useSharedPluginState = useSharedPluginStateNoDebounce(api),
|
|
64
|
+
findReplaceState = _useSharedPluginState.findReplaceState;
|
|
65
|
+
return {
|
|
66
|
+
shouldMatchCase: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.shouldMatchCase,
|
|
67
|
+
isActive: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.isActive,
|
|
68
|
+
findText: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.findText,
|
|
69
|
+
replaceText: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.replaceText,
|
|
70
|
+
index: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.index,
|
|
71
|
+
matches: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.matches,
|
|
72
|
+
shouldFocus: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.shouldFocus
|
|
73
|
+
};
|
|
74
|
+
});
|
|
43
75
|
var FindReplaceToolbarButtonWithState = function FindReplaceToolbarButtonWithState(_ref2) {
|
|
44
76
|
var _api$analytics;
|
|
45
77
|
var popupsBoundariesElement = _ref2.popupsBoundariesElement,
|
|
@@ -54,8 +86,14 @@ var FindReplaceToolbarButtonWithState = function FindReplaceToolbarButtonWithSta
|
|
|
54
86
|
isButtonHidden = _ref2.isButtonHidden,
|
|
55
87
|
doesNotHaveButton = _ref2.doesNotHaveButton;
|
|
56
88
|
var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
57
|
-
var
|
|
58
|
-
|
|
89
|
+
var _useSharedState = useSharedState(api),
|
|
90
|
+
shouldMatchCase = _useSharedState.shouldMatchCase,
|
|
91
|
+
isActive = _useSharedState.isActive,
|
|
92
|
+
findText = _useSharedState.findText,
|
|
93
|
+
replaceText = _useSharedState.replaceText,
|
|
94
|
+
index = _useSharedState.index,
|
|
95
|
+
matches = _useSharedState.matches,
|
|
96
|
+
shouldFocus = _useSharedState.shouldFocus;
|
|
59
97
|
if (!editorView) {
|
|
60
98
|
return null;
|
|
61
99
|
}
|
|
@@ -137,19 +175,19 @@ var FindReplaceToolbarButtonWithState = function FindReplaceToolbarButtonWithSta
|
|
|
137
175
|
var handleToggleMatchCase = function handleToggleMatchCase() {
|
|
138
176
|
dispatchCommand((0, _commands.toggleMatchCase)());
|
|
139
177
|
};
|
|
140
|
-
if (
|
|
178
|
+
if (shouldMatchCase === undefined || isActive === undefined || findText === undefined || replaceText === undefined || index === undefined || matches === undefined || shouldFocus === undefined) {
|
|
141
179
|
return null;
|
|
142
180
|
}
|
|
143
181
|
var DropDownComponent = doesNotHaveButton ? _FindReplaceDropdown.default : _FindReplaceToolbarButton.default;
|
|
144
182
|
return /*#__PURE__*/_react.default.createElement(DropDownComponent, {
|
|
145
|
-
shouldMatchCase:
|
|
183
|
+
shouldMatchCase: shouldMatchCase,
|
|
146
184
|
onToggleMatchCase: handleToggleMatchCase,
|
|
147
|
-
isActive:
|
|
148
|
-
findText:
|
|
149
|
-
index:
|
|
150
|
-
numMatches:
|
|
151
|
-
replaceText:
|
|
152
|
-
shouldFocus:
|
|
185
|
+
isActive: isActive,
|
|
186
|
+
findText: findText,
|
|
187
|
+
index: index,
|
|
188
|
+
numMatches: matches.length,
|
|
189
|
+
replaceText: replaceText,
|
|
190
|
+
shouldFocus: shouldFocus,
|
|
153
191
|
popupsBoundariesElement: popupsBoundariesElement,
|
|
154
192
|
popupsMountPoint: popupsMountPoint,
|
|
155
193
|
popupsScrollableElement: popupsScrollableElement,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useFindReplacePluginStateSelector = useFindReplacePluginStateSelector;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
11
|
+
// custom non-debounced hook for the find-replace plugin shared state
|
|
12
|
+
function useFindReplacePluginStateSelector(api, key) {
|
|
13
|
+
var _useState = (0, _react.useState)(function () {
|
|
14
|
+
var currentState = api === null || api === void 0 ? void 0 : api.findReplace.sharedState.currentState();
|
|
15
|
+
return currentState === null || currentState === void 0 ? void 0 : currentState[key];
|
|
16
|
+
}),
|
|
17
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
18
|
+
selectedState = _useState2[0],
|
|
19
|
+
setSelectedState = _useState2[1];
|
|
20
|
+
var previousStateRef = (0, _react.useRef)(selectedState);
|
|
21
|
+
(0, _react.useEffect)(function () {
|
|
22
|
+
var unsub = api === null || api === void 0 ? void 0 : api.findReplace.sharedState.onChange(function (_ref) {
|
|
23
|
+
var nextSharedState = _ref.nextSharedState;
|
|
24
|
+
var newState = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState[key];
|
|
25
|
+
if (!(0, _isEqual.default)(previousStateRef.current, newState)) {
|
|
26
|
+
previousStateRef.current = newState;
|
|
27
|
+
setSelectedState(newState);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return function () {
|
|
31
|
+
unsub === null || unsub === void 0 || unsub();
|
|
32
|
+
};
|
|
33
|
+
}, [api, key]);
|
|
34
|
+
return selectedState;
|
|
35
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React, { useLayoutEffect, useState } from 'react';
|
|
2
2
|
import { TRIGGER_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import { sharedPluginStateHookMigratorFactory } from '@atlaskit/editor-common/hooks';
|
|
3
4
|
import { blur, toggleMatchCase } from '../pm-plugins/commands';
|
|
4
5
|
import { activateWithAnalytics, cancelSearchWithAnalytics, findNextWithAnalytics, findPrevWithAnalytics, findWithAnalytics, replaceAllWithAnalytics, replaceWithAnalytics } from '../pm-plugins/commands-with-analytics';
|
|
5
6
|
import FindReplaceDropdown from './FindReplaceDropdown';
|
|
6
7
|
import FindReplaceToolbarButton from './FindReplaceToolbarButton';
|
|
8
|
+
import { useFindReplacePluginStateSelector } from './hooks/useFindReplacePluginStateSelector';
|
|
7
9
|
|
|
8
10
|
// light implementation of useSharedPluginState(). This is due to findreplace
|
|
9
11
|
// being the only plugin that previously used WithPluginState with
|
|
@@ -28,6 +30,37 @@ const useSharedPluginStateNoDebounce = api => {
|
|
|
28
30
|
findReplaceState: state
|
|
29
31
|
};
|
|
30
32
|
};
|
|
33
|
+
const useSharedState = sharedPluginStateHookMigratorFactory(api => {
|
|
34
|
+
const shouldMatchCase = useFindReplacePluginStateSelector(api, 'shouldMatchCase');
|
|
35
|
+
const isActive = useFindReplacePluginStateSelector(api, 'isActive');
|
|
36
|
+
const findText = useFindReplacePluginStateSelector(api, 'findText');
|
|
37
|
+
const replaceText = useFindReplacePluginStateSelector(api, 'replaceText');
|
|
38
|
+
const index = useFindReplacePluginStateSelector(api, 'index');
|
|
39
|
+
const matches = useFindReplacePluginStateSelector(api, 'matches');
|
|
40
|
+
const shouldFocus = useFindReplacePluginStateSelector(api, 'shouldFocus');
|
|
41
|
+
return {
|
|
42
|
+
shouldMatchCase,
|
|
43
|
+
isActive,
|
|
44
|
+
findText,
|
|
45
|
+
replaceText,
|
|
46
|
+
index,
|
|
47
|
+
matches,
|
|
48
|
+
shouldFocus
|
|
49
|
+
};
|
|
50
|
+
}, api => {
|
|
51
|
+
const {
|
|
52
|
+
findReplaceState
|
|
53
|
+
} = useSharedPluginStateNoDebounce(api);
|
|
54
|
+
return {
|
|
55
|
+
shouldMatchCase: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.shouldMatchCase,
|
|
56
|
+
isActive: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.isActive,
|
|
57
|
+
findText: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.findText,
|
|
58
|
+
replaceText: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.replaceText,
|
|
59
|
+
index: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.index,
|
|
60
|
+
matches: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.matches,
|
|
61
|
+
shouldFocus: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.shouldFocus
|
|
62
|
+
};
|
|
63
|
+
});
|
|
31
64
|
const FindReplaceToolbarButtonWithState = ({
|
|
32
65
|
popupsBoundariesElement,
|
|
33
66
|
popupsMountPoint,
|
|
@@ -44,8 +77,14 @@ const FindReplaceToolbarButtonWithState = ({
|
|
|
44
77
|
var _api$analytics;
|
|
45
78
|
const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
46
79
|
const {
|
|
47
|
-
|
|
48
|
-
|
|
80
|
+
shouldMatchCase,
|
|
81
|
+
isActive,
|
|
82
|
+
findText,
|
|
83
|
+
replaceText,
|
|
84
|
+
index,
|
|
85
|
+
matches,
|
|
86
|
+
shouldFocus
|
|
87
|
+
} = useSharedState(api);
|
|
49
88
|
if (!editorView) {
|
|
50
89
|
return null;
|
|
51
90
|
}
|
|
@@ -122,19 +161,19 @@ const FindReplaceToolbarButtonWithState = ({
|
|
|
122
161
|
const handleToggleMatchCase = () => {
|
|
123
162
|
dispatchCommand(toggleMatchCase());
|
|
124
163
|
};
|
|
125
|
-
if (
|
|
164
|
+
if (shouldMatchCase === undefined || isActive === undefined || findText === undefined || replaceText === undefined || index === undefined || matches === undefined || shouldFocus === undefined) {
|
|
126
165
|
return null;
|
|
127
166
|
}
|
|
128
167
|
const DropDownComponent = doesNotHaveButton ? FindReplaceDropdown : FindReplaceToolbarButton;
|
|
129
168
|
return /*#__PURE__*/React.createElement(DropDownComponent, {
|
|
130
|
-
shouldMatchCase:
|
|
169
|
+
shouldMatchCase: shouldMatchCase,
|
|
131
170
|
onToggleMatchCase: handleToggleMatchCase,
|
|
132
|
-
isActive:
|
|
133
|
-
findText:
|
|
134
|
-
index:
|
|
135
|
-
numMatches:
|
|
136
|
-
replaceText:
|
|
137
|
-
shouldFocus:
|
|
171
|
+
isActive: isActive,
|
|
172
|
+
findText: findText,
|
|
173
|
+
index: index,
|
|
174
|
+
numMatches: matches.length,
|
|
175
|
+
replaceText: replaceText,
|
|
176
|
+
shouldFocus: shouldFocus,
|
|
138
177
|
popupsBoundariesElement: popupsBoundariesElement,
|
|
139
178
|
popupsMountPoint: popupsMountPoint,
|
|
140
179
|
popupsScrollableElement: popupsScrollableElement,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useState, useEffect, useRef } from 'react';
|
|
2
|
+
import isEqual from 'lodash/isEqual';
|
|
3
|
+
// custom non-debounced hook for the find-replace plugin shared state
|
|
4
|
+
export function useFindReplacePluginStateSelector(api, key) {
|
|
5
|
+
const [selectedState, setSelectedState] = useState(() => {
|
|
6
|
+
const currentState = api === null || api === void 0 ? void 0 : api.findReplace.sharedState.currentState();
|
|
7
|
+
return currentState === null || currentState === void 0 ? void 0 : currentState[key];
|
|
8
|
+
});
|
|
9
|
+
const previousStateRef = useRef(selectedState);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const unsub = api === null || api === void 0 ? void 0 : api.findReplace.sharedState.onChange(({
|
|
12
|
+
nextSharedState
|
|
13
|
+
}) => {
|
|
14
|
+
const newState = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState[key];
|
|
15
|
+
if (!isEqual(previousStateRef.current, newState)) {
|
|
16
|
+
previousStateRef.current = newState;
|
|
17
|
+
setSelectedState(newState);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return () => {
|
|
21
|
+
unsub === null || unsub === void 0 ? void 0 : unsub();
|
|
22
|
+
};
|
|
23
|
+
}, [api, key]);
|
|
24
|
+
return selectedState;
|
|
25
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import React, { useLayoutEffect, useState } from 'react';
|
|
3
3
|
import { TRIGGER_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import { sharedPluginStateHookMigratorFactory } from '@atlaskit/editor-common/hooks';
|
|
4
5
|
import { blur, toggleMatchCase } from '../pm-plugins/commands';
|
|
5
6
|
import { activateWithAnalytics, cancelSearchWithAnalytics, findNextWithAnalytics, findPrevWithAnalytics, findWithAnalytics, replaceAllWithAnalytics, replaceWithAnalytics } from '../pm-plugins/commands-with-analytics';
|
|
6
7
|
import FindReplaceDropdown from './FindReplaceDropdown';
|
|
7
8
|
import FindReplaceToolbarButton from './FindReplaceToolbarButton';
|
|
9
|
+
import { useFindReplacePluginStateSelector } from './hooks/useFindReplacePluginStateSelector';
|
|
8
10
|
|
|
9
11
|
// light implementation of useSharedPluginState(). This is due to findreplace
|
|
10
12
|
// being the only plugin that previously used WithPluginState with
|
|
@@ -31,6 +33,36 @@ var useSharedPluginStateNoDebounce = function useSharedPluginStateNoDebounce(api
|
|
|
31
33
|
findReplaceState: state
|
|
32
34
|
};
|
|
33
35
|
};
|
|
36
|
+
var useSharedState = sharedPluginStateHookMigratorFactory(function (api) {
|
|
37
|
+
var shouldMatchCase = useFindReplacePluginStateSelector(api, 'shouldMatchCase');
|
|
38
|
+
var isActive = useFindReplacePluginStateSelector(api, 'isActive');
|
|
39
|
+
var findText = useFindReplacePluginStateSelector(api, 'findText');
|
|
40
|
+
var replaceText = useFindReplacePluginStateSelector(api, 'replaceText');
|
|
41
|
+
var index = useFindReplacePluginStateSelector(api, 'index');
|
|
42
|
+
var matches = useFindReplacePluginStateSelector(api, 'matches');
|
|
43
|
+
var shouldFocus = useFindReplacePluginStateSelector(api, 'shouldFocus');
|
|
44
|
+
return {
|
|
45
|
+
shouldMatchCase: shouldMatchCase,
|
|
46
|
+
isActive: isActive,
|
|
47
|
+
findText: findText,
|
|
48
|
+
replaceText: replaceText,
|
|
49
|
+
index: index,
|
|
50
|
+
matches: matches,
|
|
51
|
+
shouldFocus: shouldFocus
|
|
52
|
+
};
|
|
53
|
+
}, function (api) {
|
|
54
|
+
var _useSharedPluginState = useSharedPluginStateNoDebounce(api),
|
|
55
|
+
findReplaceState = _useSharedPluginState.findReplaceState;
|
|
56
|
+
return {
|
|
57
|
+
shouldMatchCase: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.shouldMatchCase,
|
|
58
|
+
isActive: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.isActive,
|
|
59
|
+
findText: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.findText,
|
|
60
|
+
replaceText: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.replaceText,
|
|
61
|
+
index: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.index,
|
|
62
|
+
matches: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.matches,
|
|
63
|
+
shouldFocus: findReplaceState === null || findReplaceState === void 0 ? void 0 : findReplaceState.shouldFocus
|
|
64
|
+
};
|
|
65
|
+
});
|
|
34
66
|
var FindReplaceToolbarButtonWithState = function FindReplaceToolbarButtonWithState(_ref2) {
|
|
35
67
|
var _api$analytics;
|
|
36
68
|
var popupsBoundariesElement = _ref2.popupsBoundariesElement,
|
|
@@ -45,8 +77,14 @@ var FindReplaceToolbarButtonWithState = function FindReplaceToolbarButtonWithSta
|
|
|
45
77
|
isButtonHidden = _ref2.isButtonHidden,
|
|
46
78
|
doesNotHaveButton = _ref2.doesNotHaveButton;
|
|
47
79
|
var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
48
|
-
var
|
|
49
|
-
|
|
80
|
+
var _useSharedState = useSharedState(api),
|
|
81
|
+
shouldMatchCase = _useSharedState.shouldMatchCase,
|
|
82
|
+
isActive = _useSharedState.isActive,
|
|
83
|
+
findText = _useSharedState.findText,
|
|
84
|
+
replaceText = _useSharedState.replaceText,
|
|
85
|
+
index = _useSharedState.index,
|
|
86
|
+
matches = _useSharedState.matches,
|
|
87
|
+
shouldFocus = _useSharedState.shouldFocus;
|
|
50
88
|
if (!editorView) {
|
|
51
89
|
return null;
|
|
52
90
|
}
|
|
@@ -128,19 +166,19 @@ var FindReplaceToolbarButtonWithState = function FindReplaceToolbarButtonWithSta
|
|
|
128
166
|
var handleToggleMatchCase = function handleToggleMatchCase() {
|
|
129
167
|
dispatchCommand(toggleMatchCase());
|
|
130
168
|
};
|
|
131
|
-
if (
|
|
169
|
+
if (shouldMatchCase === undefined || isActive === undefined || findText === undefined || replaceText === undefined || index === undefined || matches === undefined || shouldFocus === undefined) {
|
|
132
170
|
return null;
|
|
133
171
|
}
|
|
134
172
|
var DropDownComponent = doesNotHaveButton ? FindReplaceDropdown : FindReplaceToolbarButton;
|
|
135
173
|
return /*#__PURE__*/React.createElement(DropDownComponent, {
|
|
136
|
-
shouldMatchCase:
|
|
174
|
+
shouldMatchCase: shouldMatchCase,
|
|
137
175
|
onToggleMatchCase: handleToggleMatchCase,
|
|
138
|
-
isActive:
|
|
139
|
-
findText:
|
|
140
|
-
index:
|
|
141
|
-
numMatches:
|
|
142
|
-
replaceText:
|
|
143
|
-
shouldFocus:
|
|
176
|
+
isActive: isActive,
|
|
177
|
+
findText: findText,
|
|
178
|
+
index: index,
|
|
179
|
+
numMatches: matches.length,
|
|
180
|
+
replaceText: replaceText,
|
|
181
|
+
shouldFocus: shouldFocus,
|
|
144
182
|
popupsBoundariesElement: popupsBoundariesElement,
|
|
145
183
|
popupsMountPoint: popupsMountPoint,
|
|
146
184
|
popupsScrollableElement: popupsScrollableElement,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import { useState, useEffect, useRef } from 'react';
|
|
3
|
+
import isEqual from 'lodash/isEqual';
|
|
4
|
+
// custom non-debounced hook for the find-replace plugin shared state
|
|
5
|
+
export function useFindReplacePluginStateSelector(api, key) {
|
|
6
|
+
var _useState = useState(function () {
|
|
7
|
+
var currentState = api === null || api === void 0 ? void 0 : api.findReplace.sharedState.currentState();
|
|
8
|
+
return currentState === null || currentState === void 0 ? void 0 : currentState[key];
|
|
9
|
+
}),
|
|
10
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
11
|
+
selectedState = _useState2[0],
|
|
12
|
+
setSelectedState = _useState2[1];
|
|
13
|
+
var previousStateRef = useRef(selectedState);
|
|
14
|
+
useEffect(function () {
|
|
15
|
+
var unsub = api === null || api === void 0 ? void 0 : api.findReplace.sharedState.onChange(function (_ref) {
|
|
16
|
+
var nextSharedState = _ref.nextSharedState;
|
|
17
|
+
var newState = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState[key];
|
|
18
|
+
if (!isEqual(previousStateRef.current, newState)) {
|
|
19
|
+
previousStateRef.current = newState;
|
|
20
|
+
setSelectedState(newState);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return function () {
|
|
24
|
+
unsub === null || unsub === void 0 || unsub();
|
|
25
|
+
};
|
|
26
|
+
}, [api, key]);
|
|
27
|
+
return selectedState;
|
|
28
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { FindReplacePlugin } from '../../findReplacePluginType';
|
|
3
|
+
import type { FindReplacePluginState } from '../../types';
|
|
4
|
+
export declare function useFindReplacePluginStateSelector<Key extends keyof FindReplacePluginState>(api: ExtractInjectionAPI<FindReplacePlugin> | null | undefined, key: Key): FindReplacePluginState[Key] | undefined;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { FindReplacePlugin } from '../../findReplacePluginType';
|
|
3
|
+
import type { FindReplacePluginState } from '../../types';
|
|
4
|
+
export declare function useFindReplacePluginStateSelector<Key extends keyof FindReplacePluginState>(api: ExtractInjectionAPI<FindReplacePlugin> | null | undefined, key: Key): FindReplacePluginState[Key] | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-find-replace",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"description": "find replace plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@atlaskit/button": "^23.2.0",
|
|
36
|
-
"@atlaskit/editor-common": "^105.
|
|
36
|
+
"@atlaskit/editor-common": "^105.11.0",
|
|
37
37
|
"@atlaskit/editor-plugin-analytics": "^2.3.0",
|
|
38
38
|
"@atlaskit/editor-plugin-primary-toolbar": "^3.2.0",
|
|
39
39
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@atlaskit/primitives": "^14.8.0",
|
|
45
45
|
"@atlaskit/textfield": "^8.0.0",
|
|
46
46
|
"@atlaskit/theme": "^18.0.0",
|
|
47
|
-
"@atlaskit/tmp-editor-statsig": "^5.
|
|
47
|
+
"@atlaskit/tmp-editor-statsig": "^5.1.0",
|
|
48
48
|
"@atlaskit/tokens": "^4.9.0",
|
|
49
49
|
"@atlaskit/tooltip": "^20.0.0",
|
|
50
50
|
"@babel/runtime": "^7.0.0",
|