@atlaskit/editor-plugin-find-replace 2.5.0 → 2.6.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,18 @@
1
1
  # @atlaskit/editor-plugin-find-replace
2
2
 
3
+ ## 2.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#169485](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/169485)
8
+ [`271cb7104a7f9`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/271cb7104a7f9) -
9
+ [ux] [ED-27955] this change is extending the Find algorithm to date nodes behind the
10
+ platform_editor_find_and_replace_part_2 flag
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
3
16
  ## 2.5.0
4
17
 
5
18
  ### Minor Changes
@@ -66,8 +66,9 @@ var findReplacePlugin = exports.findReplacePlugin = function findReplacePlugin(_
66
66
  var plugins = [{
67
67
  name: 'findReplace',
68
68
  plugin: function plugin(_ref3) {
69
- var dispatch = _ref3.dispatch;
70
- return (0, _main.createPlugin)(dispatch);
69
+ var dispatch = _ref3.dispatch,
70
+ getIntl = _ref3.getIntl;
71
+ return (0, _main.createPlugin)(dispatch, getIntl);
71
72
  }
72
73
  }, {
73
74
  name: 'findReplaceKeymap',
@@ -24,8 +24,9 @@ var activate = exports.activate = function activate() {
24
24
  if (selection instanceof _state.TextSelection && !selection.empty) {
25
25
  findText = (0, _utils.getSelectedText)(selection);
26
26
  var _getPluginState = (0, _pluginFactory.getPluginState)(state),
27
- shouldMatchCase = _getPluginState.shouldMatchCase;
28
- matches = (0, _utils.findMatches)(state.doc, findText, shouldMatchCase);
27
+ shouldMatchCase = _getPluginState.shouldMatchCase,
28
+ getIntl = _getPluginState.getIntl;
29
+ matches = (0, _utils.findMatches)(state.doc, findText, shouldMatchCase, undefined, getIntl);
29
30
  index = (0, _utils.findSearchIndex)(selection.from, matches);
30
31
  }
31
32
  return {
@@ -40,8 +41,9 @@ var find = exports.find = function find(editorView, containerElement, keyword) {
40
41
  return (0, _commands.withScrollIntoView)((0, _pluginFactory.createCommand)(function (state) {
41
42
  var selection = state.selection;
42
43
  var _getPluginState2 = (0, _pluginFactory.getPluginState)(state),
43
- shouldMatchCase = _getPluginState2.shouldMatchCase;
44
- var matches = keyword !== undefined ? (0, _utils.findMatches)(state.doc, keyword, shouldMatchCase) : [];
44
+ shouldMatchCase = _getPluginState2.shouldMatchCase,
45
+ getIntl = _getPluginState2.getIntl;
46
+ var matches = keyword !== undefined ? (0, _utils.findMatches)(state.doc, keyword, shouldMatchCase, undefined, getIntl) : [];
45
47
  var index = (0, _utils.findSearchIndex)(selection.from, matches);
46
48
 
47
49
  // we can't just apply all the decorations to highlight the search results at once
@@ -60,8 +62,9 @@ var find = exports.find = function find(editorView, containerElement, keyword) {
60
62
  }, function (tr, state) {
61
63
  var selection = state.selection;
62
64
  var _getPluginState3 = (0, _pluginFactory.getPluginState)(state),
63
- shouldMatchCase = _getPluginState3.shouldMatchCase;
64
- var matches = keyword !== undefined ? (0, _utils.findMatches)(state.doc, keyword, shouldMatchCase) : [];
65
+ shouldMatchCase = _getPluginState3.shouldMatchCase,
66
+ getIntl = _getPluginState3.getIntl;
67
+ var matches = keyword !== undefined ? (0, _utils.findMatches)(state.doc, keyword, shouldMatchCase, undefined, getIntl) : [];
65
68
  if (matches.length > 0) {
66
69
  var index = (0, _utils.findSearchIndex)(selection.from, matches);
67
70
  return tr.setSelection((0, _utils.getSelectionForMatch)(tr.selection, tr.doc, index, matches));
@@ -1,13 +1,18 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.initialState = exports.createPlugin = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
7
9
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
10
  var _view = require("@atlaskit/editor-prosemirror/view");
11
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
9
12
  var _pluginFactory = require("./plugin-factory");
10
13
  var _pluginKey = require("./plugin-key");
14
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
16
  var initialState = exports.initialState = {
12
17
  isActive: false,
13
18
  shouldFocus: false,
@@ -18,11 +23,13 @@ var initialState = exports.initialState = {
18
23
  decorationSet: _view.DecorationSet.empty,
19
24
  shouldMatchCase: false
20
25
  };
21
- var createPlugin = exports.createPlugin = function createPlugin(dispatch) {
26
+ var createPlugin = exports.createPlugin = function createPlugin(dispatch, getIntl) {
22
27
  return new _safePlugin.SafePlugin({
23
28
  key: _pluginKey.findReplacePluginKey,
24
29
  state: (0, _pluginFactory.createPluginState)(dispatch, function () {
25
- return initialState;
30
+ return (0, _platformFeatureFlags.fg)('platform_editor_find_and_replace_part_2') ? _objectSpread(_objectSpread({}, initialState), {}, {
31
+ getIntl: getIntl
32
+ }) : _objectSpread({}, initialState);
26
33
  }),
27
34
  props: {
28
35
  decorations: function decorations(state) {
@@ -33,8 +33,9 @@ var handleDocChanged = function handleDocChanged(tr, pluginState) {
33
33
  var index = pluginState.index,
34
34
  decorationSet = pluginState.decorationSet,
35
35
  matches = pluginState.matches,
36
- shouldMatchCase = pluginState.shouldMatchCase;
37
- var newMatches = (0, _utils2.findMatches)(tr.doc, findText, shouldMatchCase);
36
+ shouldMatchCase = pluginState.shouldMatchCase,
37
+ getIntl = pluginState.getIntl;
38
+ var newMatches = (0, _utils2.findMatches)(tr.doc, findText, shouldMatchCase, undefined, getIntl);
38
39
  decorationSet = decorationSet.map(tr.mapping, tr.doc);
39
40
  var numDecorations = decorationSet.find().length;
40
41
  var mappedMatches = matches.map(function (match) {
@@ -8,6 +8,7 @@ exports.findMatches = findMatches;
8
8
  exports.findSearchIndex = findSearchIndex;
9
9
  exports.getSelectedText = getSelectedText;
10
10
  exports.removeMatchesFromSet = exports.removeDecorationsFromSet = exports.prevIndex = exports.nextIndex = exports.isMatchAffectedByStep = exports.getSelectionForMatch = void 0;
11
+ var _utils = require("@atlaskit/editor-common/utils");
11
12
  var _state = require("@atlaskit/editor-prosemirror/state");
12
13
  var _view = require("@atlaskit/editor-prosemirror/view");
13
14
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
@@ -38,6 +39,7 @@ var createDecoration = exports.createDecoration = function createDecoration(star
38
39
  };
39
40
  function findMatches(content, searchText, shouldMatchCase) {
40
41
  var contentIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
42
+ var getIntl = arguments.length > 4 ? arguments[4] : undefined;
41
43
  var matches = [];
42
44
  var searchTextLength = searchText.length;
43
45
  var textGrouping = null;
@@ -45,10 +47,8 @@ function findMatches(content, searchText, shouldMatchCase) {
45
47
  if (!textGrouping) {
46
48
  return;
47
49
  }
48
- // Ignored via go/ees005
49
- // eslint-disable-next-line prefer-const
50
- var text = textGrouping.text,
51
- relativePos = textGrouping.pos;
50
+ var text = textGrouping.text;
51
+ var relativePos = textGrouping.pos;
52
52
  var pos = contentIndex + relativePos;
53
53
  if (!shouldMatchCase) {
54
54
  searchText = searchText.toLowerCase();
@@ -95,6 +95,26 @@ function findMatches(content, searchText, shouldMatchCase) {
95
95
  });
96
96
  }
97
97
  };
98
+ var collectDateMatch = function collectDateMatch(textGrouping, nodeSize) {
99
+ if (!textGrouping) {
100
+ return;
101
+ }
102
+ var text = textGrouping.text;
103
+ var pos = textGrouping.pos;
104
+ if (!shouldMatchCase) {
105
+ searchText = searchText.toLowerCase();
106
+ text = text.toLowerCase();
107
+ }
108
+ var index = text.indexOf(searchText);
109
+ if (index !== -1) {
110
+ var start = pos;
111
+ matches.push({
112
+ start: start,
113
+ end: start + nodeSize,
114
+ canReplace: false
115
+ });
116
+ }
117
+ };
98
118
  if (searchTextLength > 0) {
99
119
  content.descendants(function (node, pos) {
100
120
  if (node.isText) {
@@ -117,6 +137,14 @@ function findMatches(content, searchText, shouldMatchCase) {
117
137
  pos: pos
118
138
  }, node.nodeSize);
119
139
  break;
140
+ case 'date':
141
+ if ((0, _platformFeatureFlags.fg)('platform_editor_find_and_replace_part_2')) {
142
+ collectDateMatch({
143
+ text: (0, _utils.timestampToString)(node.attrs.timestamp, getIntl ? getIntl() : null),
144
+ pos: pos
145
+ }, node.nodeSize);
146
+ }
147
+ break;
120
148
  default:
121
149
  break;
122
150
  }
@@ -61,8 +61,9 @@ export const findReplacePlugin = ({
61
61
  const plugins = [{
62
62
  name: 'findReplace',
63
63
  plugin: ({
64
- dispatch
65
- }) => createPlugin(dispatch)
64
+ dispatch,
65
+ getIntl
66
+ }) => createPlugin(dispatch, getIntl)
66
67
  }, {
67
68
  name: 'findReplaceKeymap',
68
69
  plugin: () => {
@@ -18,9 +18,10 @@ export const activate = () => createCommand(state => {
18
18
  if (selection instanceof TextSelection && !selection.empty) {
19
19
  findText = getSelectedText(selection);
20
20
  const {
21
- shouldMatchCase
21
+ shouldMatchCase,
22
+ getIntl
22
23
  } = getPluginState(state);
23
- matches = findMatches(state.doc, findText, shouldMatchCase);
24
+ matches = findMatches(state.doc, findText, shouldMatchCase, undefined, getIntl);
24
25
  index = findSearchIndex(selection.from, matches);
25
26
  }
26
27
  return {
@@ -35,9 +36,10 @@ export const find = (editorView, containerElement, keyword) => withScrollIntoVie
35
36
  selection
36
37
  } = state;
37
38
  const {
38
- shouldMatchCase
39
+ shouldMatchCase,
40
+ getIntl
39
41
  } = getPluginState(state);
40
- const matches = keyword !== undefined ? findMatches(state.doc, keyword, shouldMatchCase) : [];
42
+ const matches = keyword !== undefined ? findMatches(state.doc, keyword, shouldMatchCase, undefined, getIntl) : [];
41
43
  const index = findSearchIndex(selection.from, matches);
42
44
 
43
45
  // we can't just apply all the decorations to highlight the search results at once
@@ -54,9 +56,10 @@ export const find = (editorView, containerElement, keyword) => withScrollIntoVie
54
56
  selection
55
57
  } = state;
56
58
  const {
57
- shouldMatchCase
59
+ shouldMatchCase,
60
+ getIntl
58
61
  } = getPluginState(state);
59
- const matches = keyword !== undefined ? findMatches(state.doc, keyword, shouldMatchCase) : [];
62
+ const matches = keyword !== undefined ? findMatches(state.doc, keyword, shouldMatchCase, undefined, getIntl) : [];
60
63
  if (matches.length > 0) {
61
64
  const index = findSearchIndex(selection.from, matches);
62
65
  return tr.setSelection(getSelectionForMatch(tr.selection, tr.doc, index, matches));
@@ -1,5 +1,6 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import { createPluginState, getPluginState } from './plugin-factory';
4
5
  import { findReplacePluginKey } from './plugin-key';
5
6
  export const initialState = {
@@ -12,19 +13,26 @@ export const initialState = {
12
13
  decorationSet: DecorationSet.empty,
13
14
  shouldMatchCase: false
14
15
  };
15
- export const createPlugin = dispatch => new SafePlugin({
16
- key: findReplacePluginKey,
17
- state: createPluginState(dispatch, () => initialState),
18
- props: {
19
- decorations(state) {
20
- const {
21
- isActive,
22
- findText,
23
- decorationSet
24
- } = getPluginState(state);
25
- if (isActive && findText) {
26
- return decorationSet;
16
+ export const createPlugin = (dispatch, getIntl) => {
17
+ return new SafePlugin({
18
+ key: findReplacePluginKey,
19
+ state: createPluginState(dispatch, () => fg('platform_editor_find_and_replace_part_2') ? {
20
+ ...initialState,
21
+ getIntl
22
+ } : {
23
+ ...initialState
24
+ }),
25
+ props: {
26
+ decorations(state) {
27
+ const {
28
+ isActive,
29
+ findText,
30
+ decorationSet
31
+ } = getPluginState(state);
32
+ if (isActive && findText) {
33
+ return decorationSet;
34
+ }
27
35
  }
28
36
  }
29
- }
30
- });
37
+ });
38
+ };
@@ -24,9 +24,10 @@ const handleDocChanged = (tr, pluginState) => {
24
24
  index,
25
25
  decorationSet,
26
26
  matches,
27
- shouldMatchCase
27
+ shouldMatchCase,
28
+ getIntl
28
29
  } = pluginState;
29
- const newMatches = findMatches(tr.doc, findText, shouldMatchCase);
30
+ const newMatches = findMatches(tr.doc, findText, shouldMatchCase, undefined, getIntl);
30
31
  decorationSet = decorationSet.map(tr.mapping, tr.doc);
31
32
  const numDecorations = decorationSet.find().length;
32
33
  const mappedMatches = matches.map(match => ({
@@ -1,3 +1,4 @@
1
+ import { timestampToString } from '@atlaskit/editor-common/utils';
1
2
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
2
3
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
4
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -23,7 +24,7 @@ export const createDecoration = (start, end, isSelected) => {
23
24
  class: className
24
25
  });
25
26
  };
26
- export function findMatches(content, searchText, shouldMatchCase, contentIndex = 0) {
27
+ export function findMatches(content, searchText, shouldMatchCase, contentIndex = 0, getIntl) {
27
28
  const matches = [];
28
29
  const searchTextLength = searchText.length;
29
30
  let textGrouping = null;
@@ -31,10 +32,10 @@ export function findMatches(content, searchText, shouldMatchCase, contentIndex =
31
32
  if (!textGrouping) {
32
33
  return;
33
34
  }
34
- // Ignored via go/ees005
35
- // eslint-disable-next-line prefer-const
36
35
  let {
37
- text,
36
+ text
37
+ } = textGrouping;
38
+ const {
38
39
  pos: relativePos
39
40
  } = textGrouping;
40
41
  const pos = contentIndex + relativePos;
@@ -87,6 +88,30 @@ export function findMatches(content, searchText, shouldMatchCase, contentIndex =
87
88
  });
88
89
  }
89
90
  };
91
+ const collectDateMatch = (textGrouping, nodeSize) => {
92
+ if (!textGrouping) {
93
+ return;
94
+ }
95
+ let {
96
+ text
97
+ } = textGrouping;
98
+ const {
99
+ pos
100
+ } = textGrouping;
101
+ if (!shouldMatchCase) {
102
+ searchText = searchText.toLowerCase();
103
+ text = text.toLowerCase();
104
+ }
105
+ const index = text.indexOf(searchText);
106
+ if (index !== -1) {
107
+ const start = pos;
108
+ matches.push({
109
+ start,
110
+ end: start + nodeSize,
111
+ canReplace: false
112
+ });
113
+ }
114
+ };
90
115
  if (searchTextLength > 0) {
91
116
  content.descendants((node, pos) => {
92
117
  if (node.isText) {
@@ -109,6 +134,14 @@ export function findMatches(content, searchText, shouldMatchCase, contentIndex =
109
134
  pos
110
135
  }, node.nodeSize);
111
136
  break;
137
+ case 'date':
138
+ if (fg('platform_editor_find_and_replace_part_2')) {
139
+ collectDateMatch({
140
+ text: timestampToString(node.attrs.timestamp, getIntl ? getIntl() : null),
141
+ pos
142
+ }, node.nodeSize);
143
+ }
144
+ break;
112
145
  default:
113
146
  break;
114
147
  }
@@ -59,8 +59,9 @@ export var findReplacePlugin = function findReplacePlugin(_ref) {
59
59
  var plugins = [{
60
60
  name: 'findReplace',
61
61
  plugin: function plugin(_ref3) {
62
- var dispatch = _ref3.dispatch;
63
- return createPlugin(dispatch);
62
+ var dispatch = _ref3.dispatch,
63
+ getIntl = _ref3.getIntl;
64
+ return createPlugin(dispatch, getIntl);
64
65
  }
65
66
  }, {
66
67
  name: 'findReplaceKeymap',
@@ -17,8 +17,9 @@ export var activate = function activate() {
17
17
  if (selection instanceof TextSelection && !selection.empty) {
18
18
  findText = getSelectedText(selection);
19
19
  var _getPluginState = getPluginState(state),
20
- shouldMatchCase = _getPluginState.shouldMatchCase;
21
- matches = findMatches(state.doc, findText, shouldMatchCase);
20
+ shouldMatchCase = _getPluginState.shouldMatchCase,
21
+ getIntl = _getPluginState.getIntl;
22
+ matches = findMatches(state.doc, findText, shouldMatchCase, undefined, getIntl);
22
23
  index = findSearchIndex(selection.from, matches);
23
24
  }
24
25
  return {
@@ -33,8 +34,9 @@ export var find = function find(editorView, containerElement, keyword) {
33
34
  return withScrollIntoView(createCommand(function (state) {
34
35
  var selection = state.selection;
35
36
  var _getPluginState2 = getPluginState(state),
36
- shouldMatchCase = _getPluginState2.shouldMatchCase;
37
- var matches = keyword !== undefined ? findMatches(state.doc, keyword, shouldMatchCase) : [];
37
+ shouldMatchCase = _getPluginState2.shouldMatchCase,
38
+ getIntl = _getPluginState2.getIntl;
39
+ var matches = keyword !== undefined ? findMatches(state.doc, keyword, shouldMatchCase, undefined, getIntl) : [];
38
40
  var index = findSearchIndex(selection.from, matches);
39
41
 
40
42
  // we can't just apply all the decorations to highlight the search results at once
@@ -53,8 +55,9 @@ export var find = function find(editorView, containerElement, keyword) {
53
55
  }, function (tr, state) {
54
56
  var selection = state.selection;
55
57
  var _getPluginState3 = getPluginState(state),
56
- shouldMatchCase = _getPluginState3.shouldMatchCase;
57
- var matches = keyword !== undefined ? findMatches(state.doc, keyword, shouldMatchCase) : [];
58
+ shouldMatchCase = _getPluginState3.shouldMatchCase,
59
+ getIntl = _getPluginState3.getIntl;
60
+ var matches = keyword !== undefined ? findMatches(state.doc, keyword, shouldMatchCase, undefined, getIntl) : [];
58
61
  if (matches.length > 0) {
59
62
  var index = findSearchIndex(selection.from, matches);
60
63
  return tr.setSelection(getSelectionForMatch(tr.selection, tr.doc, index, matches));
@@ -1,5 +1,9 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1
4
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
5
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
+ import { fg } from '@atlaskit/platform-feature-flags';
3
7
  import { createPluginState, getPluginState } from './plugin-factory';
4
8
  import { findReplacePluginKey } from './plugin-key';
5
9
  export var initialState = {
@@ -12,11 +16,13 @@ export var initialState = {
12
16
  decorationSet: DecorationSet.empty,
13
17
  shouldMatchCase: false
14
18
  };
15
- export var createPlugin = function createPlugin(dispatch) {
19
+ export var createPlugin = function createPlugin(dispatch, getIntl) {
16
20
  return new SafePlugin({
17
21
  key: findReplacePluginKey,
18
22
  state: createPluginState(dispatch, function () {
19
- return initialState;
23
+ return fg('platform_editor_find_and_replace_part_2') ? _objectSpread(_objectSpread({}, initialState), {}, {
24
+ getIntl: getIntl
25
+ }) : _objectSpread({}, initialState);
20
26
  }),
21
27
  props: {
22
28
  decorations: function decorations(state) {
@@ -25,8 +25,9 @@ var handleDocChanged = function handleDocChanged(tr, pluginState) {
25
25
  var index = pluginState.index,
26
26
  decorationSet = pluginState.decorationSet,
27
27
  matches = pluginState.matches,
28
- shouldMatchCase = pluginState.shouldMatchCase;
29
- var newMatches = findMatches(tr.doc, findText, shouldMatchCase);
28
+ shouldMatchCase = pluginState.shouldMatchCase,
29
+ getIntl = pluginState.getIntl;
30
+ var newMatches = findMatches(tr.doc, findText, shouldMatchCase, undefined, getIntl);
30
31
  decorationSet = decorationSet.map(tr.mapping, tr.doc);
31
32
  var numDecorations = decorationSet.find().length;
32
33
  var mappedMatches = matches.map(function (match) {
@@ -1,3 +1,4 @@
1
+ import { timestampToString } from '@atlaskit/editor-common/utils';
1
2
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
2
3
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
4
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -28,6 +29,7 @@ export var createDecoration = function createDecoration(start, end, isSelected)
28
29
  };
29
30
  export function findMatches(content, searchText, shouldMatchCase) {
30
31
  var contentIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
32
+ var getIntl = arguments.length > 4 ? arguments[4] : undefined;
31
33
  var matches = [];
32
34
  var searchTextLength = searchText.length;
33
35
  var textGrouping = null;
@@ -35,10 +37,8 @@ export function findMatches(content, searchText, shouldMatchCase) {
35
37
  if (!textGrouping) {
36
38
  return;
37
39
  }
38
- // Ignored via go/ees005
39
- // eslint-disable-next-line prefer-const
40
- var text = textGrouping.text,
41
- relativePos = textGrouping.pos;
40
+ var text = textGrouping.text;
41
+ var relativePos = textGrouping.pos;
42
42
  var pos = contentIndex + relativePos;
43
43
  if (!shouldMatchCase) {
44
44
  searchText = searchText.toLowerCase();
@@ -85,6 +85,26 @@ export function findMatches(content, searchText, shouldMatchCase) {
85
85
  });
86
86
  }
87
87
  };
88
+ var collectDateMatch = function collectDateMatch(textGrouping, nodeSize) {
89
+ if (!textGrouping) {
90
+ return;
91
+ }
92
+ var text = textGrouping.text;
93
+ var pos = textGrouping.pos;
94
+ if (!shouldMatchCase) {
95
+ searchText = searchText.toLowerCase();
96
+ text = text.toLowerCase();
97
+ }
98
+ var index = text.indexOf(searchText);
99
+ if (index !== -1) {
100
+ var start = pos;
101
+ matches.push({
102
+ start: start,
103
+ end: start + nodeSize,
104
+ canReplace: false
105
+ });
106
+ }
107
+ };
88
108
  if (searchTextLength > 0) {
89
109
  content.descendants(function (node, pos) {
90
110
  if (node.isText) {
@@ -107,6 +127,14 @@ export function findMatches(content, searchText, shouldMatchCase) {
107
127
  pos: pos
108
128
  }, node.nodeSize);
109
129
  break;
130
+ case 'date':
131
+ if (fg('platform_editor_find_and_replace_part_2')) {
132
+ collectDateMatch({
133
+ text: timestampToString(node.attrs.timestamp, getIntl ? getIntl() : null),
134
+ pos: pos
135
+ }, node.nodeSize);
136
+ }
137
+ break;
110
138
  default:
111
139
  break;
112
140
  }
@@ -1,5 +1,6 @@
1
1
  import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { PMPluginFactoryParams } from '@atlaskit/editor-common/types';
3
4
  import type { FindReplacePluginState } from '../types';
4
5
  export declare const initialState: FindReplacePluginState;
5
- export declare const createPlugin: (dispatch: Dispatch) => SafePlugin<FindReplacePluginState>;
6
+ export declare const createPlugin: (dispatch: Dispatch, getIntl: PMPluginFactoryParams['getIntl']) => SafePlugin<FindReplacePluginState>;
@@ -1,3 +1,4 @@
1
+ import { IntlShape } from 'react-intl-next';
1
2
  import type { Fragment, Node as PmNode, Slice } from '@atlaskit/editor-prosemirror/model';
2
3
  import type { ReadonlyTransaction, Selection } from '@atlaskit/editor-prosemirror/state';
3
4
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
@@ -11,7 +12,7 @@ export declare const createDecorations: (selectedIndex: number, matches: {
11
12
  end: number;
12
13
  }[]) => Decoration[];
13
14
  export declare const createDecoration: (start: number, end: number, isSelected?: boolean) => Decoration;
14
- export declare function findMatches(content: PmNode | Fragment, searchText: string, shouldMatchCase: boolean, contentIndex?: number): Match[];
15
+ export declare function findMatches(content: PmNode | Fragment, searchText: string, shouldMatchCase: boolean, contentIndex?: number, getIntl?: () => IntlShape): Match[];
15
16
  /**
16
17
  * Finds index of first item in matches array that comes after user's cursor pos.
17
18
  * If `backward` is `true`, finds index of first item that comes before instead.
@@ -1,3 +1,4 @@
1
+ import { IntlShape } from 'react-intl-next';
1
2
  import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
2
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
4
  import type { DecorationSet, EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -22,6 +23,8 @@ export interface FindReplacePluginState {
22
23
  decorationSet: DecorationSet;
23
24
  /** Whether find/replace should match case when searching for results */
24
25
  shouldMatchCase: boolean;
26
+ /** Intl object */
27
+ getIntl?: () => IntlShape;
25
28
  }
26
29
  export type FindReplaceToolbarButtonWithStateProps = {
27
30
  popupsBoundariesElement?: HTMLElement;
@@ -1,5 +1,6 @@
1
1
  import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { PMPluginFactoryParams } from '@atlaskit/editor-common/types';
3
4
  import type { FindReplacePluginState } from '../types';
4
5
  export declare const initialState: FindReplacePluginState;
5
- export declare const createPlugin: (dispatch: Dispatch) => SafePlugin<FindReplacePluginState>;
6
+ export declare const createPlugin: (dispatch: Dispatch, getIntl: PMPluginFactoryParams['getIntl']) => SafePlugin<FindReplacePluginState>;
@@ -1,3 +1,4 @@
1
+ import { IntlShape } from 'react-intl-next';
1
2
  import type { Fragment, Node as PmNode, Slice } from '@atlaskit/editor-prosemirror/model';
2
3
  import type { ReadonlyTransaction, Selection } from '@atlaskit/editor-prosemirror/state';
3
4
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
@@ -11,7 +12,7 @@ export declare const createDecorations: (selectedIndex: number, matches: {
11
12
  end: number;
12
13
  }[]) => Decoration[];
13
14
  export declare const createDecoration: (start: number, end: number, isSelected?: boolean) => Decoration;
14
- export declare function findMatches(content: PmNode | Fragment, searchText: string, shouldMatchCase: boolean, contentIndex?: number): Match[];
15
+ export declare function findMatches(content: PmNode | Fragment, searchText: string, shouldMatchCase: boolean, contentIndex?: number, getIntl?: () => IntlShape): Match[];
15
16
  /**
16
17
  * Finds index of first item in matches array that comes after user's cursor pos.
17
18
  * If `backward` is `true`, finds index of first item that comes before instead.
@@ -1,3 +1,4 @@
1
+ import { IntlShape } from 'react-intl-next';
1
2
  import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
2
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
4
  import type { DecorationSet, EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -22,6 +23,8 @@ export interface FindReplacePluginState {
22
23
  decorationSet: DecorationSet;
23
24
  /** Whether find/replace should match case when searching for results */
24
25
  shouldMatchCase: boolean;
26
+ /** Intl object */
27
+ getIntl?: () => IntlShape;
25
28
  }
26
29
  export type FindReplaceToolbarButtonWithStateProps = {
27
30
  popupsBoundariesElement?: HTMLElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-find-replace",
3
- "version": "2.5.0",
3
+ "version": "2.6.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.9.0",
36
+ "@atlaskit/editor-common": "^106.10.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",