@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
package/.eslintrc.js ADDED
@@ -0,0 +1,26 @@
1
+ module.exports = {
2
+ rules: {
3
+ '@typescript-eslint/no-duplicate-imports': 'error',
4
+ '@typescript-eslint/no-explicit-any': 'error',
5
+ '@typescript-eslint/ban-types': [
6
+ 'error',
7
+ {
8
+ types: {
9
+ 'React.FC':
10
+ 'Please use types directly on props instead, and explicitly define children if required',
11
+ 'React.FunctionalComponent':
12
+ 'Please use types directly on props instead, and explicitly define children if required',
13
+ },
14
+ extendDefaults: false,
15
+ },
16
+ ],
17
+ },
18
+ overrides: [
19
+ {
20
+ files: ['**/__tests__/**/*.{js,ts,tsx}', '**/examples/**/*.{js,ts,tsx}'],
21
+ rules: {
22
+ '@typescript-eslint/no-explicit-any': 'off',
23
+ },
24
+ },
25
+ ],
26
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # @atlaskit/editor-plugin-find-replace
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#66388](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/66388) [`1698d83da05f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1698d83da05f) - ED-21743: Extract find replace plugin from editor-core
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
package/LICENSE.md ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Atlassian Pty Ltd
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Editor plugin find replace
2
+
3
+ Find replace plugin for @atlaskit/editor-core
4
+
5
+ **Note:** This component is designed for internal Atlassian development.
6
+ External contributors will be able to use this component but will not be able to submit issues.
7
+
8
+ ## Install
9
+ ---
10
+ - **Install** - *yarn add @atlaskit/editor-plugin-analytics*
11
+ - **npm** - [@atlaskit/editor-plugin-analytics](https://www.npmjs.com/package/@atlaskit/editor-plugin-find-replace)
12
+ - **Source** - [Bitbucket](https://bitbucket.org/atlassian/atlassian-frontend/src/master/packages/editor/editor-plugin-find-replace)
13
+ - **Bundle** - [unpkg.com](https://unpkg.com/@atlaskit/editor-plugin-find-replace/dist/)
14
+
15
+ ## Usage
16
+ ---
17
+ **Internal use only**
18
+
19
+ @atlaskit/editor-plugin-find-replace is intended for internal use by the @atlaskit/editor-core and as a plugin dependency of the Editor within your product.
20
+
21
+ Direct use of this component is not supported.
22
+
23
+ Please see [Atlaskit - Editor plugin find-replace](https://atlaskit.atlassian.com/packages/editor/editor-plugin-find-replace) for documentation and examples for this package.
24
+
25
+ ## Support
26
+ ---
27
+ For internal Atlassian, visit the slacknv channel [#help-editor](https://atlassian.slack.com/archives/CFG3PSQ9E) for support or visit [go/editor-help](https://go/editor-help) to submit a bug.
28
+ ## License
29
+ ---
30
+ Please see [Atlassian Frontend - License](https://hello.atlassian.net/wiki/spaces/AF/pages/2589099144/Documentation#License) for more licensing information.
@@ -0,0 +1,166 @@
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 _analytics = require("@atlaskit/editor-common/analytics");
12
+ var _commands = require("./commands");
13
+ var _commandsWithAnalytics = require("./commands-with-analytics");
14
+ var _FindReplaceToolbarButton = _interopRequireDefault(require("./ui/FindReplaceToolbarButton"));
15
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+ // light implementation of useSharedPluginState(). This is due to findreplace
18
+ // being the only plugin that previously used WithPluginState with
19
+ // debounce=false. That was implemented because of text sync issues
20
+ // between editor & findreplace dialog.
21
+ // To address under ENGHEALTH-5853
22
+ var useSharedPluginStateNoDebounce = function useSharedPluginStateNoDebounce(api) {
23
+ var _useState = (0, _react.useState)(api === null || api === void 0 ? void 0 : api.findReplace.sharedState.currentState()),
24
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
25
+ state = _useState2[0],
26
+ setState = _useState2[1];
27
+ (0, _react.useLayoutEffect)(function () {
28
+ var unsub = api === null || api === void 0 ? void 0 : api.findReplace.sharedState.onChange(function (_ref) {
29
+ var nextSharedState = _ref.nextSharedState;
30
+ setState(nextSharedState);
31
+ });
32
+ return function () {
33
+ unsub === null || unsub === void 0 || unsub();
34
+ };
35
+ }, [api]);
36
+ return {
37
+ findReplaceState: state
38
+ };
39
+ };
40
+ var FindReplaceToolbarButtonWithState = function FindReplaceToolbarButtonWithState(_ref2) {
41
+ var _api$analytics;
42
+ var popupsBoundariesElement = _ref2.popupsBoundariesElement,
43
+ popupsMountPoint = _ref2.popupsMountPoint,
44
+ popupsScrollableElement = _ref2.popupsScrollableElement,
45
+ isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing,
46
+ editorView = _ref2.editorView,
47
+ containerElement = _ref2.containerElement,
48
+ dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent,
49
+ featureFlags = _ref2.featureFlags,
50
+ takeFullWidth = _ref2.takeFullWidth,
51
+ api = _ref2.api;
52
+ var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
53
+ var _useSharedPluginState = useSharedPluginStateNoDebounce(api),
54
+ findReplaceState = _useSharedPluginState.findReplaceState;
55
+ if (!editorView) {
56
+ return null;
57
+ }
58
+
59
+ // we need the editor to be in focus for scrollIntoView() to work
60
+ // so we focus it while we run the command, then put focus back into
61
+ // whatever element was previously focused in find replace component
62
+ var runWithEditorFocused = function runWithEditorFocused(fn) {
63
+ var activeElement = document.activeElement;
64
+ editorView.focus();
65
+ fn();
66
+ activeElement === null || activeElement === void 0 || activeElement.focus();
67
+ };
68
+ var dispatchCommand = function dispatchCommand(cmd) {
69
+ var state = editorView.state,
70
+ dispatch = editorView.dispatch;
71
+ cmd(state, dispatch);
72
+ };
73
+ var handleActivate = function handleActivate() {
74
+ runWithEditorFocused(function () {
75
+ return dispatchCommand((0, _commandsWithAnalytics.activateWithAnalytics)(editorAnalyticsAPI)({
76
+ triggerMethod: _analytics.TRIGGER_METHOD.TOOLBAR
77
+ }));
78
+ });
79
+ };
80
+ var handleFind = function handleFind(keyword) {
81
+ runWithEditorFocused(function () {
82
+ return dispatchCommand((0, _commandsWithAnalytics.findWithAnalytics)(editorAnalyticsAPI)({
83
+ editorView: editorView,
84
+ containerElement: containerElement,
85
+ keyword: keyword
86
+ }));
87
+ });
88
+ };
89
+ var handleFindNext = function handleFindNext(_ref3) {
90
+ var triggerMethod = _ref3.triggerMethod;
91
+ runWithEditorFocused(function () {
92
+ return dispatchCommand((0, _commandsWithAnalytics.findNextWithAnalytics)(editorAnalyticsAPI)({
93
+ triggerMethod: triggerMethod
94
+ }));
95
+ });
96
+ };
97
+ var handleFindPrev = function handleFindPrev(_ref4) {
98
+ var triggerMethod = _ref4.triggerMethod;
99
+ runWithEditorFocused(function () {
100
+ return dispatchCommand((0, _commandsWithAnalytics.findPrevWithAnalytics)(editorAnalyticsAPI)({
101
+ triggerMethod: triggerMethod
102
+ }));
103
+ });
104
+ };
105
+ var handleReplace = function handleReplace(_ref5) {
106
+ var triggerMethod = _ref5.triggerMethod,
107
+ replaceText = _ref5.replaceText;
108
+ runWithEditorFocused(function () {
109
+ return dispatchCommand((0, _commandsWithAnalytics.replaceWithAnalytics)(editorAnalyticsAPI)({
110
+ triggerMethod: triggerMethod,
111
+ replaceText: replaceText
112
+ }));
113
+ });
114
+ };
115
+ var handleReplaceAll = function handleReplaceAll(_ref6) {
116
+ var replaceText = _ref6.replaceText;
117
+ runWithEditorFocused(function () {
118
+ return dispatchCommand((0, _commandsWithAnalytics.replaceAllWithAnalytics)(editorAnalyticsAPI)({
119
+ replaceText: replaceText
120
+ }));
121
+ });
122
+ };
123
+ var handleFindBlur = function handleFindBlur() {
124
+ dispatchCommand((0, _commands.blur)());
125
+ };
126
+ var handleCancel = function handleCancel(_ref7) {
127
+ var triggerMethod = _ref7.triggerMethod;
128
+ dispatchCommand((0, _commandsWithAnalytics.cancelSearchWithAnalytics)(editorAnalyticsAPI)({
129
+ triggerMethod: triggerMethod
130
+ }));
131
+ editorView.focus();
132
+ };
133
+ var handleToggleMatchCase = function handleToggleMatchCase() {
134
+ dispatchCommand((0, _commands.toggleMatchCase)());
135
+ };
136
+ var findReplaceMatchCase = featureFlags.findReplaceMatchCase;
137
+ if (!findReplaceState) {
138
+ return null;
139
+ }
140
+ return /*#__PURE__*/_react.default.createElement(_FindReplaceToolbarButton.default, {
141
+ allowMatchCase: findReplaceMatchCase,
142
+ shouldMatchCase: findReplaceState.shouldMatchCase,
143
+ onToggleMatchCase: handleToggleMatchCase,
144
+ isActive: findReplaceState.isActive,
145
+ findText: findReplaceState.findText,
146
+ index: findReplaceState.index,
147
+ numMatches: findReplaceState.matches.length,
148
+ replaceText: findReplaceState.replaceText,
149
+ shouldFocus: findReplaceState.shouldFocus,
150
+ popupsBoundariesElement: popupsBoundariesElement,
151
+ popupsMountPoint: popupsMountPoint,
152
+ popupsScrollableElement: popupsScrollableElement,
153
+ isReducedSpacing: !!isToolbarReducedSpacing,
154
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
155
+ onFindBlur: handleFindBlur,
156
+ onCancel: handleCancel,
157
+ onActivate: handleActivate,
158
+ onFind: handleFind,
159
+ onFindNext: handleFindNext,
160
+ onFindPrev: handleFindPrev,
161
+ onReplace: handleReplace,
162
+ onReplaceAll: handleReplaceAll,
163
+ takeFullWidth: !!takeFullWidth
164
+ });
165
+ };
166
+ var _default = exports.default = /*#__PURE__*/_react.default.memo(FindReplaceToolbarButtonWithState);
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FindReplaceActionTypes = void 0;
7
+ var FindReplaceActionTypes = exports.FindReplaceActionTypes = /*#__PURE__*/function (FindReplaceActionTypes) {
8
+ FindReplaceActionTypes["ACTIVATE"] = "ACTIVATE";
9
+ FindReplaceActionTypes["FIND"] = "FIND";
10
+ FindReplaceActionTypes["UPDATE_DECORATIONS"] = "UPDATE_DECORATIONS";
11
+ FindReplaceActionTypes["FIND_NEXT"] = "FIND_NEXT";
12
+ FindReplaceActionTypes["FIND_PREVIOUS"] = "FIND_PREVIOUS";
13
+ FindReplaceActionTypes["REPLACE"] = "REPLACE";
14
+ FindReplaceActionTypes["REPLACE_ALL"] = "REPLACE_ALL";
15
+ FindReplaceActionTypes["CANCEL"] = "CANCEL";
16
+ FindReplaceActionTypes["BLUR"] = "BLUR";
17
+ FindReplaceActionTypes["TOGGLE_MATCH_CASE"] = "TOGGLE_MATCH_CASE";
18
+ return FindReplaceActionTypes;
19
+ }({});
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.replaceWithAnalytics = exports.replaceAllWithAnalytics = exports.findWithAnalytics = exports.findPrevWithAnalytics = exports.findNextWithAnalytics = exports.cancelSearchWithAnalytics = exports.activateWithAnalytics = void 0;
7
+ var _analytics = require("@atlaskit/editor-common/analytics");
8
+ var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
9
+ var _state = require("@atlaskit/editor-prosemirror/state");
10
+ var _commands = require("./commands");
11
+ var activateWithAnalytics = exports.activateWithAnalytics = function activateWithAnalytics(editorAnalyticsAPI) {
12
+ return function (_ref) {
13
+ var triggerMethod = _ref.triggerMethod;
14
+ return (0, _editorAnalytics.withAnalytics)(editorAnalyticsAPI, function (state) {
15
+ return {
16
+ eventType: _analytics.EVENT_TYPE.UI,
17
+ action: _analytics.ACTION.ACTIVATED,
18
+ actionSubject: _analytics.ACTION_SUBJECT.FIND_REPLACE_DIALOG,
19
+ attributes: {
20
+ inputMethod: state.selection instanceof _state.TextSelection && !state.selection.empty ? _analytics.INPUT_METHOD.PREFILL : _analytics.INPUT_METHOD.KEYBOARD,
21
+ triggerMethod: triggerMethod
22
+ }
23
+ };
24
+ })((0, _commands.activate)());
25
+ };
26
+ };
27
+ var findWithAnalytics = exports.findWithAnalytics = function findWithAnalytics(editorAnalyticsAPI) {
28
+ return function (_ref2) {
29
+ var editorView = _ref2.editorView,
30
+ containerElement = _ref2.containerElement,
31
+ keyword = _ref2.keyword;
32
+ return (0, _editorAnalytics.withAnalytics)(editorAnalyticsAPI, {
33
+ eventType: _analytics.EVENT_TYPE.TRACK,
34
+ action: _analytics.ACTION.FIND_PERFORMED,
35
+ actionSubject: _analytics.ACTION_SUBJECT.TEXT
36
+ })((0, _commands.find)(editorView, containerElement, keyword));
37
+ };
38
+ };
39
+ var findNextWithAnalytics = exports.findNextWithAnalytics = function findNextWithAnalytics(editorAnalyticsAPI) {
40
+ return function (_ref3) {
41
+ var triggerMethod = _ref3.triggerMethod;
42
+ return (0, _editorAnalytics.withAnalytics)(editorAnalyticsAPI, {
43
+ eventType: _analytics.EVENT_TYPE.TRACK,
44
+ action: _analytics.ACTION.FIND_NEXT_PERFORMED,
45
+ actionSubject: _analytics.ACTION_SUBJECT.TEXT,
46
+ attributes: {
47
+ triggerMethod: triggerMethod
48
+ }
49
+ })((0, _commands.findNext)());
50
+ };
51
+ };
52
+ var findPrevWithAnalytics = exports.findPrevWithAnalytics = function findPrevWithAnalytics(editorAnalyticsAPI) {
53
+ return function (_ref4) {
54
+ var triggerMethod = _ref4.triggerMethod;
55
+ return (0, _editorAnalytics.withAnalytics)(editorAnalyticsAPI, {
56
+ eventType: _analytics.EVENT_TYPE.TRACK,
57
+ action: _analytics.ACTION.FIND_PREV_PERFORMED,
58
+ actionSubject: _analytics.ACTION_SUBJECT.TEXT,
59
+ attributes: {
60
+ triggerMethod: triggerMethod
61
+ }
62
+ })((0, _commands.findPrevious)());
63
+ };
64
+ };
65
+ var replaceWithAnalytics = exports.replaceWithAnalytics = function replaceWithAnalytics(editorAnalyticsAPI) {
66
+ return function (_ref5) {
67
+ var triggerMethod = _ref5.triggerMethod,
68
+ replaceText = _ref5.replaceText;
69
+ return (0, _editorAnalytics.withAnalytics)(editorAnalyticsAPI, {
70
+ eventType: _analytics.EVENT_TYPE.TRACK,
71
+ action: _analytics.ACTION.REPLACED_ONE,
72
+ actionSubject: _analytics.ACTION_SUBJECT.TEXT,
73
+ attributes: {
74
+ triggerMethod: triggerMethod
75
+ }
76
+ })((0, _commands.replace)(replaceText));
77
+ };
78
+ };
79
+ var replaceAllWithAnalytics = exports.replaceAllWithAnalytics = function replaceAllWithAnalytics(editorAnalyticsAPI) {
80
+ return function (_ref6) {
81
+ var replaceText = _ref6.replaceText;
82
+ return (0, _editorAnalytics.withAnalytics)(editorAnalyticsAPI, {
83
+ eventType: _analytics.EVENT_TYPE.TRACK,
84
+ action: _analytics.ACTION.REPLACED_ALL,
85
+ actionSubject: _analytics.ACTION_SUBJECT.TEXT
86
+ })((0, _commands.replaceAll)(replaceText));
87
+ };
88
+ };
89
+ var cancelSearchWithAnalytics = exports.cancelSearchWithAnalytics = function cancelSearchWithAnalytics(editorAnalyticsAPI) {
90
+ return function (_ref7) {
91
+ var triggerMethod = _ref7.triggerMethod;
92
+ return (0, _editorAnalytics.withAnalytics)(editorAnalyticsAPI, {
93
+ eventType: _analytics.EVENT_TYPE.UI,
94
+ action: _analytics.ACTION.DEACTIVATED,
95
+ actionSubject: _analytics.ACTION_SUBJECT.FIND_REPLACE_DIALOG,
96
+ attributes: {
97
+ triggerMethod: triggerMethod
98
+ }
99
+ })((0, _commands.cancelSearch)());
100
+ };
101
+ };
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.toggleMatchCase = exports.replaceAll = exports.replace = exports.removeDecorations = exports.findPrevious = exports.findNext = exports.find = exports.cancelSearch = exports.blur = exports.addDecorations = exports.activate = void 0;
8
+ var _state = require("@atlaskit/editor-prosemirror/state");
9
+ var _view = require("@atlaskit/editor-prosemirror/view");
10
+ var _actions = require("./actions");
11
+ var _pluginFactory = require("./pm-plugins/plugin-factory");
12
+ var _utils = require("./utils");
13
+ var _batchDecorations = _interopRequireDefault(require("./utils/batch-decorations"));
14
+ var _commands = require("./utils/commands");
15
+ var activate = exports.activate = function activate() {
16
+ return (0, _pluginFactory.createCommand)(function (state) {
17
+ var selection = state.selection;
18
+ var findText;
19
+ var matches;
20
+ var index;
21
+
22
+ // if user has selected text and hit cmd-f, set that as the keyword
23
+ if (selection instanceof _state.TextSelection && !selection.empty) {
24
+ findText = (0, _utils.getSelectedText)(selection);
25
+ var _getPluginState = (0, _pluginFactory.getPluginState)(state),
26
+ shouldMatchCase = _getPluginState.shouldMatchCase;
27
+ matches = (0, _utils.findMatches)(state.doc, findText, shouldMatchCase);
28
+ index = (0, _utils.findSearchIndex)(selection.from, matches);
29
+ }
30
+ return {
31
+ type: _actions.FindReplaceActionTypes.ACTIVATE,
32
+ findText: findText,
33
+ matches: matches,
34
+ index: index
35
+ };
36
+ });
37
+ };
38
+ var find = exports.find = function find(editorView, containerElement, keyword) {
39
+ return (0, _commands.withScrollIntoView)((0, _pluginFactory.createCommand)(function (state) {
40
+ var selection = state.selection;
41
+ var _getPluginState2 = (0, _pluginFactory.getPluginState)(state),
42
+ shouldMatchCase = _getPluginState2.shouldMatchCase;
43
+ var matches = keyword !== undefined ? (0, _utils.findMatches)(state.doc, keyword, shouldMatchCase) : [];
44
+ var index = (0, _utils.findSearchIndex)(selection.from, matches);
45
+
46
+ // we can't just apply all the decorations to highlight the search results at once
47
+ // as if there are a lot ProseMirror cries :'(
48
+ _batchDecorations.default.applyAllSearchDecorations(editorView, containerElement, function (decorations) {
49
+ return addDecorations(decorations)(editorView.state, editorView.dispatch);
50
+ }, function (decorations) {
51
+ return removeDecorations(decorations)(editorView.state, editorView.dispatch);
52
+ });
53
+ return {
54
+ type: _actions.FindReplaceActionTypes.FIND,
55
+ findText: keyword || '',
56
+ matches: matches,
57
+ index: index
58
+ };
59
+ }, function (tr, state) {
60
+ var selection = state.selection;
61
+ var _getPluginState3 = (0, _pluginFactory.getPluginState)(state),
62
+ shouldMatchCase = _getPluginState3.shouldMatchCase;
63
+ var matches = keyword !== undefined ? (0, _utils.findMatches)(state.doc, keyword, shouldMatchCase) : [];
64
+ if (matches.length > 0) {
65
+ var index = (0, _utils.findSearchIndex)(selection.from, matches);
66
+ return tr.setSelection((0, _utils.getSelectionForMatch)(tr.selection, tr.doc, index, matches));
67
+ }
68
+ return tr;
69
+ }));
70
+ };
71
+ var findNext = exports.findNext = function findNext() {
72
+ return (0, _commands.withScrollIntoView)((0, _pluginFactory.createCommand)(function (state) {
73
+ return findInDirection(state, 'next');
74
+ }, function (tr, state) {
75
+ var _getPluginState4 = (0, _pluginFactory.getPluginState)(state),
76
+ matches = _getPluginState4.matches,
77
+ index = _getPluginState4.index;
78
+ // can't use index from plugin state because if the cursor has moved, it will still be the
79
+ // OLD index (the find next operation should look for the first match forward starting
80
+ // from the current cursor position)
81
+ var searchIndex = (0, _utils.findSearchIndex)(state.selection.from, matches);
82
+ if (searchIndex === index) {
83
+ // cursor has not moved, so we just want to find the next in matches array
84
+ searchIndex = (0, _utils.nextIndex)(searchIndex, matches.length);
85
+ }
86
+ return tr.setSelection((0, _utils.getSelectionForMatch)(tr.selection, tr.doc, searchIndex, matches));
87
+ }));
88
+ };
89
+ var findPrevious = exports.findPrevious = function findPrevious() {
90
+ return (0, _commands.withScrollIntoView)((0, _pluginFactory.createCommand)(function (state) {
91
+ return findInDirection(state, 'previous');
92
+ }, function (tr, state) {
93
+ var _getPluginState5 = (0, _pluginFactory.getPluginState)(state),
94
+ matches = _getPluginState5.matches;
95
+ // can't use index from plugin state because if the cursor has moved, it will still be the
96
+ // OLD index (the find prev operation should look for the first match backward starting
97
+ // from the current cursor position)
98
+ var searchIndex = (0, _utils.findSearchIndex)(state.selection.from, matches, true);
99
+ return tr.setSelection((0, _utils.getSelectionForMatch)(tr.selection, tr.doc, searchIndex, matches));
100
+ }));
101
+ };
102
+ var findInDirection = function findInDirection(state, dir) {
103
+ var pluginState = (0, _pluginFactory.getPluginState)(state);
104
+ var matches = pluginState.matches,
105
+ findText = pluginState.findText;
106
+ var decorationSet = pluginState.decorationSet,
107
+ index = pluginState.index;
108
+ if (findText) {
109
+ var searchIndex = (0, _utils.findSearchIndex)(state.selection.from, matches, dir === 'previous');
110
+ // compare index from plugin state and index of first match forward from cursor position
111
+ if (index === searchIndex) {
112
+ // normal case, cycling through matches
113
+ index = dir === 'next' ? (0, _utils.nextIndex)(index, matches.length) : (0, _utils.prevIndex)(index, matches.length);
114
+ } else {
115
+ // cursor has moved
116
+ index = searchIndex;
117
+ }
118
+ decorationSet = updateSelectedHighlight(state, index);
119
+ }
120
+ return {
121
+ type: dir === 'next' ? _actions.FindReplaceActionTypes.FIND_NEXT : _actions.FindReplaceActionTypes.FIND_PREVIOUS,
122
+ index: index,
123
+ decorationSet: decorationSet
124
+ };
125
+ };
126
+ var replace = exports.replace = function replace(replaceText) {
127
+ return (0, _commands.withScrollIntoView)((0, _pluginFactory.createCommand)(function (state) {
128
+ var pluginState = (0, _pluginFactory.getPluginState)(state);
129
+ var findText = pluginState.findText;
130
+ var decorationSet = pluginState.decorationSet,
131
+ matches = pluginState.matches,
132
+ index = pluginState.index;
133
+ decorationSet = updateSelectedHighlight(state, (0, _utils.nextIndex)(index, matches.length));
134
+ if (replaceText.toLowerCase().indexOf(findText.toLowerCase()) === -1) {
135
+ decorationSet = (0, _utils.removeMatchesFromSet)(decorationSet, [matches[index]], state.doc);
136
+ matches.splice(index, 1);
137
+ if (index > matches.length - 1) {
138
+ index = 0;
139
+ }
140
+ } else {
141
+ index = (0, _utils.nextIndex)(index, matches.length);
142
+ }
143
+ return {
144
+ type: _actions.FindReplaceActionTypes.REPLACE,
145
+ replaceText: replaceText,
146
+ decorationSet: decorationSet,
147
+ matches: matches,
148
+ index: index
149
+ };
150
+ }, function (tr, state) {
151
+ var _getPluginState6 = (0, _pluginFactory.getPluginState)(state),
152
+ matches = _getPluginState6.matches,
153
+ index = _getPluginState6.index,
154
+ findText = _getPluginState6.findText;
155
+ if (matches[index]) {
156
+ var _matches$index = matches[index],
157
+ start = _matches$index.start,
158
+ end = _matches$index.end;
159
+ var newIndex = (0, _utils.nextIndex)(index, matches.length);
160
+ tr.insertText(replaceText, start, end).setSelection((0, _utils.getSelectionForMatch)(tr.selection, tr.doc, newIndex, matches, newIndex === 0 ? 0 : replaceText.length - findText.length));
161
+ }
162
+ return tr;
163
+ }));
164
+ };
165
+ var replaceAll = exports.replaceAll = function replaceAll(replaceText) {
166
+ return (0, _pluginFactory.createCommand)({
167
+ type: _actions.FindReplaceActionTypes.REPLACE_ALL,
168
+ replaceText: replaceText,
169
+ decorationSet: _view.DecorationSet.empty,
170
+ matches: [],
171
+ index: 0
172
+ }, function (tr, state) {
173
+ var pluginState = (0, _pluginFactory.getPluginState)(state);
174
+ pluginState.matches.forEach(function (match) {
175
+ tr.insertText(replaceText, tr.mapping.map(match.start), tr.mapping.map(match.end));
176
+ });
177
+ tr.setMeta('scrollIntoView', false);
178
+ return tr;
179
+ });
180
+ };
181
+ var addDecorations = exports.addDecorations = function addDecorations(decorations) {
182
+ return (0, _pluginFactory.createCommand)(function (state) {
183
+ var _getPluginState7 = (0, _pluginFactory.getPluginState)(state),
184
+ decorationSet = _getPluginState7.decorationSet;
185
+ return {
186
+ type: _actions.FindReplaceActionTypes.UPDATE_DECORATIONS,
187
+ decorationSet: decorationSet.add(state.doc, decorations)
188
+ };
189
+ });
190
+ };
191
+ var removeDecorations = exports.removeDecorations = function removeDecorations(decorations) {
192
+ return (0, _pluginFactory.createCommand)(function (state) {
193
+ var _getPluginState8 = (0, _pluginFactory.getPluginState)(state),
194
+ decorationSet = _getPluginState8.decorationSet;
195
+ return {
196
+ type: _actions.FindReplaceActionTypes.UPDATE_DECORATIONS,
197
+ decorationSet: (0, _utils.removeDecorationsFromSet)(decorationSet, decorations, state.doc)
198
+ };
199
+ });
200
+ };
201
+ var cancelSearch = exports.cancelSearch = function cancelSearch() {
202
+ return (0, _pluginFactory.createCommand)(function () {
203
+ _batchDecorations.default.stop();
204
+ return {
205
+ type: _actions.FindReplaceActionTypes.CANCEL
206
+ };
207
+ });
208
+ };
209
+ var blur = exports.blur = function blur() {
210
+ return (0, _pluginFactory.createCommand)({
211
+ type: _actions.FindReplaceActionTypes.BLUR
212
+ });
213
+ };
214
+ var toggleMatchCase = exports.toggleMatchCase = function toggleMatchCase() {
215
+ return (0, _pluginFactory.createCommand)({
216
+ type: _actions.FindReplaceActionTypes.TOGGLE_MATCH_CASE
217
+ });
218
+ };
219
+ var updateSelectedHighlight = function updateSelectedHighlight(state, nextSelectedIndex) {
220
+ var _getPluginState9 = (0, _pluginFactory.getPluginState)(state),
221
+ decorationSet = _getPluginState9.decorationSet,
222
+ index = _getPluginState9.index,
223
+ matches = _getPluginState9.matches;
224
+ var currentSelectedMatch = matches[index];
225
+ var nextSelectedMatch = matches[nextSelectedIndex];
226
+ if (index === nextSelectedIndex) {
227
+ return decorationSet;
228
+ }
229
+ var currentSelectedDecoration = (0, _utils.findDecorationFromMatch)(decorationSet, currentSelectedMatch);
230
+ var nextSelectedDecoration = (0, _utils.findDecorationFromMatch)(decorationSet, nextSelectedMatch);
231
+
232
+ // Update decorations so the current selected match becomes a normal match
233
+ // and the next selected gets the selected styling
234
+ var decorationsToRemove = [];
235
+ if (currentSelectedDecoration) {
236
+ decorationsToRemove.push(currentSelectedDecoration);
237
+ }
238
+ if (nextSelectedDecoration) {
239
+ decorationsToRemove.push(nextSelectedDecoration);
240
+ }
241
+ if (decorationsToRemove.length > 0) {
242
+ // removeDecorationsFromSet depends on decorations being pre-sorted
243
+ decorationsToRemove.sort(function (a, b) {
244
+ return a.from < b.from ? -1 : 1;
245
+ });
246
+ decorationSet = (0, _utils.removeDecorationsFromSet)(decorationSet, decorationsToRemove, state.doc);
247
+ }
248
+ if (currentSelectedMatch) {
249
+ decorationSet = decorationSet.add(state.doc, [(0, _utils.createDecoration)(currentSelectedMatch.start, currentSelectedMatch.end)]);
250
+ }
251
+ if (nextSelectedMatch) {
252
+ decorationSet = decorationSet.add(state.doc, [(0, _utils.createDecoration)(nextSelectedMatch.start, nextSelectedMatch.end, true)]);
253
+ }
254
+ return decorationSet;
255
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "findReplacePlugin", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _plugin.findReplacePlugin;
10
+ }
11
+ });
12
+ var _plugin = require("./plugin");