@atlaskit/editor-plugin-find-replace 2.2.7 → 2.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @atlaskit/editor-plugin-find-replace
2
2
 
3
+ ## 2.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#165698](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/165698)
8
+ [`e97682ca74f19`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e97682ca74f19) -
9
+ [ux] [ED-27954] this change is extending the Find algorithm to status nodes behind the
10
+ platform_editor_find_and_replace_1 flag
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
16
+ ## 2.2.8
17
+
18
+ ### Patch Changes
19
+
20
+ - [#165597](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/165597)
21
+ [`7091d26926b74`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7091d26926b74) -
22
+ [ED-28128] this change is adding an optional field to the Match type in the FindReplace plugin
23
+ - Updated dependencies
24
+
3
25
  ## 2.2.7
4
26
 
5
27
  ### Patch Changes
@@ -146,7 +146,7 @@ var findReplacePlugin = exports.findReplacePlugin = function findReplacePlugin(_
146
146
  primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined,
147
147
  contentComponent: (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1', {
148
148
  exposure: true
149
- }) && (0, _platformFeatureFlags.fg)('platform_editor_controls_move_actions') ? function (_ref5) {
149
+ }) ? function (_ref5) {
150
150
  var editorView = _ref5.editorView,
151
151
  containerElement = _ref5.containerElement,
152
152
  popupsMountPoint = _ref5.popupsMountPoint,
@@ -40,7 +40,8 @@ var handleDocChanged = function handleDocChanged(tr, pluginState) {
40
40
  var mappedMatches = matches.map(function (match) {
41
41
  return {
42
42
  start: tr.mapping.map(match.start),
43
- end: tr.mapping.map(match.end)
43
+ end: tr.mapping.map(match.end),
44
+ canReplace: match.canReplace
44
45
  };
45
46
  });
46
47
  var matchesToAdd = [];
@@ -10,6 +10,7 @@ exports.getSelectedText = getSelectedText;
10
10
  exports.removeMatchesFromSet = exports.removeDecorationsFromSet = exports.prevIndex = exports.nextIndex = exports.isMatchAffectedByStep = exports.getSelectionForMatch = void 0;
11
11
  var _state = require("@atlaskit/editor-prosemirror/state");
12
12
  var _view = require("@atlaskit/editor-prosemirror/view");
13
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
13
14
  var _styles = require("../../ui/styles");
14
15
  function getSelectedText(selection) {
15
16
  var text = '';
@@ -40,7 +41,7 @@ function findMatches(content, searchText, shouldMatchCase) {
40
41
  var matches = [];
41
42
  var searchTextLength = searchText.length;
42
43
  var textGrouping = null;
43
- var collectMatch = function collectMatch(textGrouping) {
44
+ var collectTextMatch = function collectTextMatch(textGrouping) {
44
45
  if (!textGrouping) {
45
46
  return;
46
47
  }
@@ -60,11 +61,28 @@ function findMatches(content, searchText, shouldMatchCase) {
60
61
  // Add the substring index to the position of the node
61
62
  matches.push({
62
63
  start: pos + index,
63
- end: pos + end
64
+ end: pos + end,
65
+ canReplace: (0, _platformFeatureFlags.fg)('platform_editor_find_and_replace_1') ? true : undefined
64
66
  });
65
67
  index = text.indexOf(searchText, end);
66
68
  }
67
69
  };
70
+ var collectStatusMatch = function collectStatusMatch(textGrouping, nodeSize) {
71
+ if (!textGrouping) {
72
+ return;
73
+ }
74
+ var text = textGrouping.text,
75
+ pos = textGrouping.pos;
76
+ var index = text.toLowerCase().indexOf(searchText.toLowerCase());
77
+ if (index !== -1) {
78
+ var start = pos;
79
+ matches.push({
80
+ start: start,
81
+ end: start + nodeSize,
82
+ canReplace: false
83
+ });
84
+ }
85
+ };
68
86
  if (searchTextLength > 0) {
69
87
  content.descendants(function (node, pos) {
70
88
  if (node.isText) {
@@ -77,13 +95,25 @@ function findMatches(content, searchText, shouldMatchCase) {
77
95
  textGrouping.text = textGrouping.text + node.text;
78
96
  }
79
97
  } else {
80
- collectMatch(textGrouping);
98
+ collectTextMatch(textGrouping);
81
99
  textGrouping = null;
100
+ if ((0, _platformFeatureFlags.fg)('platform_editor_find_and_replace_1')) {
101
+ switch (node.type.name) {
102
+ case 'status':
103
+ collectStatusMatch({
104
+ text: node.attrs.text,
105
+ pos: pos
106
+ }, node.nodeSize);
107
+ break;
108
+ default:
109
+ break;
110
+ }
111
+ }
82
112
  }
83
113
  });
84
- // if there's a dangling text grouping and no non-text node to trigger collectMatch, manually collectMatch
114
+ // if there's a dangling text grouping and no non-text node to trigger collectTextMatch, manually collectTextMatch
85
115
  if (textGrouping) {
86
- collectMatch(textGrouping);
116
+ collectTextMatch(textGrouping);
87
117
  }
88
118
  }
89
119
  return matches;
@@ -142,7 +142,7 @@ export const findReplacePlugin = ({
142
142
  primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined,
143
143
  contentComponent: editorExperiment('platform_editor_controls', 'variant1', {
144
144
  exposure: true
145
- }) && fg('platform_editor_controls_move_actions') ? ({
145
+ }) ? ({
146
146
  editorView,
147
147
  containerElement,
148
148
  popupsMountPoint,
@@ -31,7 +31,8 @@ const handleDocChanged = (tr, pluginState) => {
31
31
  const numDecorations = decorationSet.find().length;
32
32
  const mappedMatches = matches.map(match => ({
33
33
  start: tr.mapping.map(match.start),
34
- end: tr.mapping.map(match.end)
34
+ end: tr.mapping.map(match.end),
35
+ canReplace: match.canReplace
35
36
  }));
36
37
  let matchesToAdd = [];
37
38
  let matchesToDelete = [];
@@ -1,5 +1,6 @@
1
1
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
2
2
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import { searchMatchClass, selectedSearchMatchClass } from '../../ui/styles';
4
5
  export function getSelectedText(selection) {
5
6
  let text = '';
@@ -26,7 +27,7 @@ export function findMatches(content, searchText, shouldMatchCase, contentIndex =
26
27
  const matches = [];
27
28
  const searchTextLength = searchText.length;
28
29
  let textGrouping = null;
29
- const collectMatch = textGrouping => {
30
+ const collectTextMatch = textGrouping => {
30
31
  if (!textGrouping) {
31
32
  return;
32
33
  }
@@ -48,11 +49,30 @@ export function findMatches(content, searchText, shouldMatchCase, contentIndex =
48
49
  // Add the substring index to the position of the node
49
50
  matches.push({
50
51
  start: pos + index,
51
- end: pos + end
52
+ end: pos + end,
53
+ canReplace: fg('platform_editor_find_and_replace_1') ? true : undefined
52
54
  });
53
55
  index = text.indexOf(searchText, end);
54
56
  }
55
57
  };
58
+ const collectStatusMatch = (textGrouping, nodeSize) => {
59
+ if (!textGrouping) {
60
+ return;
61
+ }
62
+ const {
63
+ text,
64
+ pos
65
+ } = textGrouping;
66
+ const index = text.toLowerCase().indexOf(searchText.toLowerCase());
67
+ if (index !== -1) {
68
+ const start = pos;
69
+ matches.push({
70
+ start,
71
+ end: start + nodeSize,
72
+ canReplace: false
73
+ });
74
+ }
75
+ };
56
76
  if (searchTextLength > 0) {
57
77
  content.descendants((node, pos) => {
58
78
  if (node.isText) {
@@ -65,13 +85,25 @@ export function findMatches(content, searchText, shouldMatchCase, contentIndex =
65
85
  textGrouping.text = textGrouping.text + node.text;
66
86
  }
67
87
  } else {
68
- collectMatch(textGrouping);
88
+ collectTextMatch(textGrouping);
69
89
  textGrouping = null;
90
+ if (fg('platform_editor_find_and_replace_1')) {
91
+ switch (node.type.name) {
92
+ case 'status':
93
+ collectStatusMatch({
94
+ text: node.attrs.text,
95
+ pos
96
+ }, node.nodeSize);
97
+ break;
98
+ default:
99
+ break;
100
+ }
101
+ }
70
102
  }
71
103
  });
72
- // if there's a dangling text grouping and no non-text node to trigger collectMatch, manually collectMatch
104
+ // if there's a dangling text grouping and no non-text node to trigger collectTextMatch, manually collectTextMatch
73
105
  if (textGrouping) {
74
- collectMatch(textGrouping);
106
+ collectTextMatch(textGrouping);
75
107
  }
76
108
  }
77
109
  return matches;
@@ -139,7 +139,7 @@ export var findReplacePlugin = function findReplacePlugin(_ref) {
139
139
  primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined,
140
140
  contentComponent: editorExperiment('platform_editor_controls', 'variant1', {
141
141
  exposure: true
142
- }) && fg('platform_editor_controls_move_actions') ? function (_ref5) {
142
+ }) ? function (_ref5) {
143
143
  var editorView = _ref5.editorView,
144
144
  containerElement = _ref5.containerElement,
145
145
  popupsMountPoint = _ref5.popupsMountPoint,
@@ -32,7 +32,8 @@ var handleDocChanged = function handleDocChanged(tr, pluginState) {
32
32
  var mappedMatches = matches.map(function (match) {
33
33
  return {
34
34
  start: tr.mapping.map(match.start),
35
- end: tr.mapping.map(match.end)
35
+ end: tr.mapping.map(match.end),
36
+ canReplace: match.canReplace
36
37
  };
37
38
  });
38
39
  var matchesToAdd = [];
@@ -1,5 +1,6 @@
1
1
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
2
2
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import { searchMatchClass, selectedSearchMatchClass } from '../../ui/styles';
4
5
  export function getSelectedText(selection) {
5
6
  var text = '';
@@ -30,7 +31,7 @@ export function findMatches(content, searchText, shouldMatchCase) {
30
31
  var matches = [];
31
32
  var searchTextLength = searchText.length;
32
33
  var textGrouping = null;
33
- var collectMatch = function collectMatch(textGrouping) {
34
+ var collectTextMatch = function collectTextMatch(textGrouping) {
34
35
  if (!textGrouping) {
35
36
  return;
36
37
  }
@@ -50,11 +51,28 @@ export function findMatches(content, searchText, shouldMatchCase) {
50
51
  // Add the substring index to the position of the node
51
52
  matches.push({
52
53
  start: pos + index,
53
- end: pos + end
54
+ end: pos + end,
55
+ canReplace: fg('platform_editor_find_and_replace_1') ? true : undefined
54
56
  });
55
57
  index = text.indexOf(searchText, end);
56
58
  }
57
59
  };
60
+ var collectStatusMatch = function collectStatusMatch(textGrouping, nodeSize) {
61
+ if (!textGrouping) {
62
+ return;
63
+ }
64
+ var text = textGrouping.text,
65
+ pos = textGrouping.pos;
66
+ var index = text.toLowerCase().indexOf(searchText.toLowerCase());
67
+ if (index !== -1) {
68
+ var start = pos;
69
+ matches.push({
70
+ start: start,
71
+ end: start + nodeSize,
72
+ canReplace: false
73
+ });
74
+ }
75
+ };
58
76
  if (searchTextLength > 0) {
59
77
  content.descendants(function (node, pos) {
60
78
  if (node.isText) {
@@ -67,13 +85,25 @@ export function findMatches(content, searchText, shouldMatchCase) {
67
85
  textGrouping.text = textGrouping.text + node.text;
68
86
  }
69
87
  } else {
70
- collectMatch(textGrouping);
88
+ collectTextMatch(textGrouping);
71
89
  textGrouping = null;
90
+ if (fg('platform_editor_find_and_replace_1')) {
91
+ switch (node.type.name) {
92
+ case 'status':
93
+ collectStatusMatch({
94
+ text: node.attrs.text,
95
+ pos: pos
96
+ }, node.nodeSize);
97
+ break;
98
+ default:
99
+ break;
100
+ }
101
+ }
72
102
  }
73
103
  });
74
- // if there's a dangling text grouping and no non-text node to trigger collectMatch, manually collectMatch
104
+ // if there's a dangling text grouping and no non-text node to trigger collectTextMatch, manually collectTextMatch
75
105
  if (textGrouping) {
76
- collectMatch(textGrouping);
106
+ collectTextMatch(textGrouping);
77
107
  }
78
108
  }
79
109
  return matches;
@@ -42,6 +42,8 @@ export type Match = {
42
42
  start: number;
43
43
  /** End position */
44
44
  end: number;
45
+ /** Boolean for whether the match can be replaced */
46
+ canReplace?: boolean;
45
47
  };
46
48
  export type TextGrouping = {
47
49
  /** The concatenated text across nodes */
@@ -42,6 +42,8 @@ export type Match = {
42
42
  start: number;
43
43
  /** End position */
44
44
  end: number;
45
+ /** Boolean for whether the match can be replaced */
46
+ canReplace?: boolean;
45
47
  };
46
48
  export type TextGrouping = {
47
49
  /** The concatenated text across nodes */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-find-replace",
3
- "version": "2.2.7",
3
+ "version": "2.3.0",
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": "^106.1.0",
36
+ "@atlaskit/editor-common": "^106.3.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,9 +44,9 @@
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.7.0",
48
- "@atlaskit/tokens": "^5.0.0",
49
- "@atlaskit/tooltip": "^20.2.0",
47
+ "@atlaskit/tmp-editor-statsig": "^5.13.0",
48
+ "@atlaskit/tokens": "^5.1.0",
49
+ "@atlaskit/tooltip": "^20.3.0",
50
50
  "@babel/runtime": "^7.0.0",
51
51
  "@emotion/react": "^11.7.1",
52
52
  "lodash": "^4.17.21",
@@ -113,10 +113,10 @@
113
113
  "platform_editor_toolbar_responsive_fixes": {
114
114
  "type": "boolean"
115
115
  },
116
- "platform_editor_controls_move_actions": {
116
+ "editor_a11y_refactor_find_replace_style": {
117
117
  "type": "boolean"
118
118
  },
119
- "editor_a11y_refactor_find_replace_style": {
119
+ "platform_editor_find_and_replace_1": {
120
120
  "type": "boolean"
121
121
  }
122
122
  }