@atlaskit/editor-core 191.0.8 → 191.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 (135) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/afm-cc/tsconfig.json +3 -3
  3. package/dist/cjs/plugins/index.js +0 -7
  4. package/dist/cjs/presets/universal.js +2 -1
  5. package/dist/cjs/ui/Appearance/Comment/Comment.js +6 -3
  6. package/dist/cjs/ui/Appearance/Comment/Toolbar.js +19 -6
  7. package/dist/cjs/ui/Appearance/FullPage/FullPageToolbar.js +1 -1
  8. package/dist/cjs/ui/ContentStyles/index.js +1 -1
  9. package/dist/cjs/version-wrapper.js +1 -1
  10. package/dist/es2019/plugins/index.js +0 -1
  11. package/dist/es2019/presets/universal.js +2 -1
  12. package/dist/es2019/ui/Appearance/Comment/Comment.js +6 -3
  13. package/dist/es2019/ui/Appearance/Comment/Toolbar.js +38 -6
  14. package/dist/es2019/ui/Appearance/FullPage/FullPageToolbar.js +1 -1
  15. package/dist/es2019/ui/ContentStyles/index.js +1 -1
  16. package/dist/es2019/version-wrapper.js +1 -1
  17. package/dist/esm/plugins/index.js +0 -1
  18. package/dist/esm/presets/universal.js +2 -1
  19. package/dist/esm/ui/Appearance/Comment/Comment.js +6 -3
  20. package/dist/esm/ui/Appearance/Comment/Toolbar.js +19 -6
  21. package/dist/esm/ui/Appearance/FullPage/FullPageToolbar.js +1 -1
  22. package/dist/esm/ui/ContentStyles/index.js +1 -1
  23. package/dist/esm/version-wrapper.js +1 -1
  24. package/dist/types/plugins/index.d.ts +0 -1
  25. package/dist/types/types/editor-props.d.ts +1 -1
  26. package/dist/types/ui/Appearance/Comment/Toolbar.d.ts +2 -1
  27. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  28. package/dist/types-ts4.5/types/editor-props.d.ts +1 -1
  29. package/dist/types-ts4.5/ui/Appearance/Comment/Toolbar.d.ts +2 -1
  30. package/package.json +6 -10
  31. package/dist/cjs/plugins/find-replace/FindReplaceToolbarButtonWithState.js +0 -166
  32. package/dist/cjs/plugins/find-replace/actions.js +0 -19
  33. package/dist/cjs/plugins/find-replace/commands-with-analytics.js +0 -101
  34. package/dist/cjs/plugins/find-replace/commands.js +0 -255
  35. package/dist/cjs/plugins/find-replace/index.js +0 -94
  36. package/dist/cjs/plugins/find-replace/keymap.js +0 -24
  37. package/dist/cjs/plugins/find-replace/plugin-key.js +0 -8
  38. package/dist/cjs/plugins/find-replace/plugin.js +0 -138
  39. package/dist/cjs/plugins/find-replace/reducer.js +0 -61
  40. package/dist/cjs/plugins/find-replace/styles.js +0 -16
  41. package/dist/cjs/plugins/find-replace/types.js +0 -5
  42. package/dist/cjs/plugins/find-replace/ui/Find.js +0 -308
  43. package/dist/cjs/plugins/find-replace/ui/FindReplace.js +0 -103
  44. package/dist/cjs/plugins/find-replace/ui/FindReplaceToolbarButton.js +0 -132
  45. package/dist/cjs/plugins/find-replace/ui/FindReplaceTooltipButton.js +0 -76
  46. package/dist/cjs/plugins/find-replace/ui/Replace.js +0 -174
  47. package/dist/cjs/plugins/find-replace/ui/styles.js +0 -44
  48. package/dist/cjs/plugins/find-replace/utils/batch-decorations.js +0 -310
  49. package/dist/cjs/plugins/find-replace/utils/commands.js +0 -16
  50. package/dist/cjs/plugins/find-replace/utils/index.js +0 -290
  51. package/dist/cjs/utils/array.js +0 -13
  52. package/dist/es2019/plugins/find-replace/FindReplaceToolbarButtonWithState.js +0 -153
  53. package/dist/es2019/plugins/find-replace/actions.js +0 -13
  54. package/dist/es2019/plugins/find-replace/commands-with-analytics.js +0 -72
  55. package/dist/es2019/plugins/find-replace/commands.js +0 -240
  56. package/dist/es2019/plugins/find-replace/index.js +0 -89
  57. package/dist/es2019/plugins/find-replace/keymap.js +0 -16
  58. package/dist/es2019/plugins/find-replace/plugin-key.js +0 -2
  59. package/dist/es2019/plugins/find-replace/plugin.js +0 -117
  60. package/dist/es2019/plugins/find-replace/reducer.js +0 -56
  61. package/dist/es2019/plugins/find-replace/styles.js +0 -17
  62. package/dist/es2019/plugins/find-replace/types.js +0 -1
  63. package/dist/es2019/plugins/find-replace/ui/Find.js +0 -284
  64. package/dist/es2019/plugins/find-replace/ui/FindReplace.js +0 -78
  65. package/dist/es2019/plugins/find-replace/ui/FindReplaceToolbarButton.js +0 -122
  66. package/dist/es2019/plugins/find-replace/ui/FindReplaceTooltipButton.js +0 -50
  67. package/dist/es2019/plugins/find-replace/ui/Replace.js +0 -152
  68. package/dist/es2019/plugins/find-replace/ui/styles.js +0 -48
  69. package/dist/es2019/plugins/find-replace/utils/batch-decorations.js +0 -189
  70. package/dist/es2019/plugins/find-replace/utils/commands.js +0 -6
  71. package/dist/es2019/plugins/find-replace/utils/index.js +0 -249
  72. package/dist/es2019/utils/array.js +0 -3
  73. package/dist/esm/plugins/find-replace/FindReplaceToolbarButtonWithState.js +0 -157
  74. package/dist/esm/plugins/find-replace/actions.js +0 -13
  75. package/dist/esm/plugins/find-replace/commands-with-analytics.js +0 -95
  76. package/dist/esm/plugins/find-replace/commands.js +0 -248
  77. package/dist/esm/plugins/find-replace/index.js +0 -87
  78. package/dist/esm/plugins/find-replace/keymap.js +0 -18
  79. package/dist/esm/plugins/find-replace/plugin-key.js +0 -2
  80. package/dist/esm/plugins/find-replace/plugin.js +0 -133
  81. package/dist/esm/plugins/find-replace/reducer.js +0 -54
  82. package/dist/esm/plugins/find-replace/styles.js +0 -10
  83. package/dist/esm/plugins/find-replace/types.js +0 -1
  84. package/dist/esm/plugins/find-replace/ui/Find.js +0 -302
  85. package/dist/esm/plugins/find-replace/ui/FindReplace.js +0 -97
  86. package/dist/esm/plugins/find-replace/ui/FindReplaceToolbarButton.js +0 -126
  87. package/dist/esm/plugins/find-replace/ui/FindReplaceTooltipButton.js +0 -69
  88. package/dist/esm/plugins/find-replace/ui/Replace.js +0 -168
  89. package/dist/esm/plugins/find-replace/ui/styles.js +0 -37
  90. package/dist/esm/plugins/find-replace/utils/batch-decorations.js +0 -304
  91. package/dist/esm/plugins/find-replace/utils/commands.js +0 -10
  92. package/dist/esm/plugins/find-replace/utils/index.js +0 -280
  93. package/dist/esm/utils/array.js +0 -7
  94. package/dist/types/plugins/find-replace/FindReplaceToolbarButtonWithState.d.ts +0 -4
  95. package/dist/types/plugins/find-replace/actions.d.ts +0 -64
  96. package/dist/types/plugins/find-replace/commands-with-analytics.d.ts +0 -27
  97. package/dist/types/plugins/find-replace/commands.d.ts +0 -12
  98. package/dist/types/plugins/find-replace/index.d.ts +0 -3
  99. package/dist/types/plugins/find-replace/keymap.d.ts +0 -4
  100. package/dist/types/plugins/find-replace/plugin-key.d.ts +0 -3
  101. package/dist/types/plugins/find-replace/plugin.d.ts +0 -6
  102. package/dist/types/plugins/find-replace/reducer.d.ts +0 -4
  103. package/dist/types/plugins/find-replace/styles.d.ts +0 -3
  104. package/dist/types/plugins/find-replace/types.d.ts +0 -79
  105. package/dist/types/plugins/find-replace/ui/Find.d.ts +0 -71
  106. package/dist/types/plugins/find-replace/ui/FindReplace.d.ts +0 -43
  107. package/dist/types/plugins/find-replace/ui/FindReplaceToolbarButton.d.ts +0 -21
  108. package/dist/types/plugins/find-replace/ui/FindReplaceTooltipButton.d.ts +0 -18
  109. package/dist/types/plugins/find-replace/ui/Replace.d.ts +0 -27
  110. package/dist/types/plugins/find-replace/ui/styles.d.ts +0 -6
  111. package/dist/types/plugins/find-replace/utils/batch-decorations.d.ts +0 -36
  112. package/dist/types/plugins/find-replace/utils/commands.d.ts +0 -2
  113. package/dist/types/plugins/find-replace/utils/index.d.ts +0 -49
  114. package/dist/types/utils/array.d.ts +0 -1
  115. package/dist/types-ts4.5/plugins/find-replace/FindReplaceToolbarButtonWithState.d.ts +0 -4
  116. package/dist/types-ts4.5/plugins/find-replace/actions.d.ts +0 -64
  117. package/dist/types-ts4.5/plugins/find-replace/commands-with-analytics.d.ts +0 -27
  118. package/dist/types-ts4.5/plugins/find-replace/commands.d.ts +0 -12
  119. package/dist/types-ts4.5/plugins/find-replace/index.d.ts +0 -3
  120. package/dist/types-ts4.5/plugins/find-replace/keymap.d.ts +0 -4
  121. package/dist/types-ts4.5/plugins/find-replace/plugin-key.d.ts +0 -3
  122. package/dist/types-ts4.5/plugins/find-replace/plugin.d.ts +0 -6
  123. package/dist/types-ts4.5/plugins/find-replace/reducer.d.ts +0 -4
  124. package/dist/types-ts4.5/plugins/find-replace/styles.d.ts +0 -3
  125. package/dist/types-ts4.5/plugins/find-replace/types.d.ts +0 -79
  126. package/dist/types-ts4.5/plugins/find-replace/ui/Find.d.ts +0 -71
  127. package/dist/types-ts4.5/plugins/find-replace/ui/FindReplace.d.ts +0 -43
  128. package/dist/types-ts4.5/plugins/find-replace/ui/FindReplaceToolbarButton.d.ts +0 -21
  129. package/dist/types-ts4.5/plugins/find-replace/ui/FindReplaceTooltipButton.d.ts +0 -18
  130. package/dist/types-ts4.5/plugins/find-replace/ui/Replace.d.ts +0 -27
  131. package/dist/types-ts4.5/plugins/find-replace/ui/styles.d.ts +0 -6
  132. package/dist/types-ts4.5/plugins/find-replace/utils/batch-decorations.d.ts +0 -36
  133. package/dist/types-ts4.5/plugins/find-replace/utils/commands.d.ts +0 -2
  134. package/dist/types-ts4.5/plugins/find-replace/utils/index.d.ts +0 -49
  135. package/dist/types-ts4.5/utils/array.d.ts +0 -1
@@ -1,133 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
- 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; }
4
- 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; }
5
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
- import { pluginFactory } from '@atlaskit/editor-common/utils';
8
- import reducer from './reducer';
9
- import { findMatches, createDecorations, removeDecorationsFromSet, findSearchIndex, removeMatchesFromSet, findDecorationFromMatch, isMatchAffectedByStep } from './utils';
10
- import { findUniqueItemsIn } from '../../utils/array';
11
- import { stepHasSlice } from '@atlaskit/editor-common/utils';
12
- import { findReplacePluginKey } from './plugin-key';
13
- export var initialState = {
14
- isActive: false,
15
- shouldFocus: false,
16
- findText: '',
17
- replaceText: '',
18
- index: 0,
19
- matches: [],
20
- decorationSet: DecorationSet.empty,
21
- shouldMatchCase: false
22
- };
23
- var handleDocChanged = function handleDocChanged(tr, pluginState) {
24
- var isActive = pluginState.isActive,
25
- findText = pluginState.findText;
26
- if (!isActive || !findText) {
27
- return pluginState;
28
- }
29
- if (!tr.steps.find(stepHasSlice)) {
30
- return pluginState;
31
- }
32
- var index = pluginState.index,
33
- decorationSet = pluginState.decorationSet,
34
- matches = pluginState.matches,
35
- shouldMatchCase = pluginState.shouldMatchCase;
36
- var newMatches = findMatches(tr.doc, findText, shouldMatchCase);
37
- decorationSet = decorationSet.map(tr.mapping, tr.doc);
38
- var numDecorations = decorationSet.find().length;
39
- var mappedMatches = matches.map(function (match) {
40
- return {
41
- start: tr.mapping.map(match.start),
42
- end: tr.mapping.map(match.end)
43
- };
44
- });
45
- var matchesToAdd = [];
46
- var matchesToDelete = [];
47
- if (newMatches.length > 0 && numDecorations === 0) {
48
- matchesToAdd = newMatches;
49
- } else if (newMatches.length === 0 && numDecorations > 0) {
50
- decorationSet = DecorationSet.empty;
51
- } else if (newMatches.length > 0 || numDecorations > 0) {
52
- // go through tr steps and find any new matches from user adding content or
53
- // any dead matches from user deleting content
54
- tr.steps.forEach(function (step) {
55
- if (stepHasSlice(step)) {
56
- // add all matches that are between the affected positions and don't already have
57
- // corresponding decorations
58
- matchesToAdd = [].concat(_toConsumableArray(matchesToAdd), _toConsumableArray(newMatches.filter(function (match) {
59
- return isMatchAffectedByStep(match, step, tr) && !findDecorationFromMatch(decorationSet, match);
60
- })));
61
-
62
- // delete any matches that are missing from the newMatches array and have a
63
- // corresponding decoration
64
- matchesToDelete = [].concat(_toConsumableArray(matchesToDelete), _toConsumableArray(findUniqueItemsIn(mappedMatches.filter(function (match) {
65
- return isMatchAffectedByStep(match, step, tr) && !!findDecorationFromMatch(decorationSet, match);
66
- }), newMatches, function (firstMatch, secondMatch) {
67
- return firstMatch.start === secondMatch.start && firstMatch.end === secondMatch.end;
68
- })));
69
- }
70
- });
71
- }
72
-
73
- // update decorations if matches changed following document update
74
- if (matchesToDelete.length > 0) {
75
- var decorationsToDelete = matchesToDelete.reduce(function (decorations, match) {
76
- return [].concat(_toConsumableArray(decorations), _toConsumableArray(decorationSet.find(match.start, match.end)));
77
- }, []);
78
- decorationSet = removeDecorationsFromSet(decorationSet, decorationsToDelete, tr.doc);
79
- }
80
- if (matchesToAdd.length > 0) {
81
- decorationSet = decorationSet.add(tr.doc, createDecorations(tr.selection.from, matchesToAdd));
82
- }
83
-
84
- // update selected match if it has changed
85
- var newIndex = index;
86
- var selectedMatch = mappedMatches[index];
87
- if (selectedMatch) {
88
- newIndex = newMatches.findIndex(function (match) {
89
- return match.start === selectedMatch.start;
90
- });
91
- }
92
- if (newIndex === undefined || newIndex === -1) {
93
- newIndex = findSearchIndex(tr.selection.from, newMatches);
94
- }
95
- var newSelectedMatch = newMatches[newIndex];
96
- decorationSet = removeMatchesFromSet(decorationSet, [selectedMatch, newSelectedMatch], tr.doc);
97
- if (newSelectedMatch) {
98
- decorationSet = decorationSet.add(tr.doc, createDecorations(0, [newSelectedMatch]));
99
- }
100
- return _objectSpread(_objectSpread({}, pluginState), {}, {
101
- matches: newMatches,
102
- index: newIndex,
103
- decorationSet: decorationSet
104
- });
105
- };
106
- var _pluginFactory = pluginFactory(findReplacePluginKey, reducer(function () {
107
- return initialState;
108
- }), {
109
- onDocChanged: handleDocChanged
110
- }),
111
- createCommand = _pluginFactory.createCommand,
112
- getPluginState = _pluginFactory.getPluginState,
113
- createPluginState = _pluginFactory.createPluginState;
114
- export { createCommand, getPluginState, createPluginState };
115
- export var createPlugin = function createPlugin(dispatch) {
116
- return new SafePlugin({
117
- key: findReplacePluginKey,
118
- state: createPluginState(dispatch, function () {
119
- return initialState;
120
- }),
121
- props: {
122
- decorations: function decorations(state) {
123
- var _getPluginState = getPluginState(state),
124
- isActive = _getPluginState.isActive,
125
- findText = _getPluginState.findText,
126
- decorationSet = _getPluginState.decorationSet;
127
- if (isActive && findText) {
128
- return decorationSet;
129
- }
130
- }
131
- }
132
- });
133
- };
@@ -1,54 +0,0 @@
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; }
4
- import { FindReplaceActionTypes } from './actions';
5
- var reducer = function reducer(getInitialState) {
6
- return function (state, action) {
7
- switch (action.type) {
8
- case FindReplaceActionTypes.ACTIVATE:
9
- case FindReplaceActionTypes.FIND:
10
- return _objectSpread(_objectSpread({}, state), {}, {
11
- isActive: true,
12
- shouldFocus: action.type === FindReplaceActionTypes.ACTIVATE,
13
- findText: action.findText !== undefined ? action.findText : state.findText,
14
- matches: action.matches || state.matches,
15
- index: action.index !== undefined ? action.index : state.index
16
- });
17
- case FindReplaceActionTypes.UPDATE_DECORATIONS:
18
- return _objectSpread(_objectSpread({}, state), {}, {
19
- decorationSet: action.decorationSet
20
- });
21
- case FindReplaceActionTypes.FIND_NEXT:
22
- return _objectSpread(_objectSpread({}, state), {}, {
23
- index: action.index,
24
- decorationSet: action.decorationSet
25
- });
26
- case FindReplaceActionTypes.FIND_PREVIOUS:
27
- return _objectSpread(_objectSpread({}, state), {}, {
28
- index: action.index,
29
- decorationSet: action.decorationSet
30
- });
31
- case FindReplaceActionTypes.REPLACE:
32
- case FindReplaceActionTypes.REPLACE_ALL:
33
- return _objectSpread(_objectSpread({}, state), {}, {
34
- replaceText: action.replaceText,
35
- decorationSet: action.decorationSet,
36
- matches: action.matches,
37
- index: action.index
38
- });
39
- case FindReplaceActionTypes.CANCEL:
40
- return getInitialState();
41
- case FindReplaceActionTypes.BLUR:
42
- return _objectSpread(_objectSpread({}, state), {}, {
43
- shouldFocus: false
44
- });
45
- case FindReplaceActionTypes.TOGGLE_MATCH_CASE:
46
- return _objectSpread(_objectSpread({}, state), {}, {
47
- shouldMatchCase: !state.shouldMatchCase
48
- });
49
- default:
50
- return state;
51
- }
52
- };
53
- };
54
- export default reducer;
@@ -1,10 +0,0 @@
1
- import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
2
- var _templateObject;
3
- /* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
4
-
5
- // TODO: https://product-fabric.atlassian.net/browse/DSP-4290
6
- import { css } from '@emotion/react';
7
- import { B75, B200 } from '@atlaskit/theme/colors';
8
- export var searchMatchClass = 'search-match';
9
- export var selectedSearchMatchClass = 'selected-search-match';
10
- export var findReplaceStyles = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .", " {\n background-color: ", ";\n }\n\n .", " {\n background-color: ", ";\n color: white;\n }\n"])), searchMatchClass, B75, selectedSearchMatchClass, B200);
@@ -1 +0,0 @@
1
- export {};
@@ -1,302 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
- /** @jsx jsx */
11
- import React from 'react';
12
- import { jsx } from '@emotion/react';
13
- import { defineMessages, injectIntl } from 'react-intl-next';
14
- import debounce from 'lodash/debounce';
15
- import EditorCloseIcon from '@atlaskit/icon/glyph/editor/close';
16
- import ChevronDownIcon from '@atlaskit/icon/glyph/hipchat/chevron-down';
17
- import ChevronUpIcon from '@atlaskit/icon/glyph/hipchat/chevron-up';
18
- import MatchCaseIcon from '@atlaskit/icon/glyph/emoji/keyboard';
19
- import Textfield from '@atlaskit/textfield';
20
- import { countStyles, countWrapperStyles, sectionWrapperStyles } from './styles';
21
- import { TRIGGER_METHOD } from '@atlaskit/editor-common/analytics';
22
- import { FindReplaceTooltipButton } from './FindReplaceTooltipButton';
23
- import rafSchd from 'raf-schd';
24
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
25
- export var FIND_DEBOUNCE_MS = 100;
26
- var messages = defineMessages({
27
- find: {
28
- id: 'fabric.editor.find',
29
- defaultMessage: 'Find',
30
- description: 'The word or phrase to search for on the document'
31
- },
32
- matchCase: {
33
- id: 'fabric.editor.matchCase',
34
- defaultMessage: 'Match case',
35
- description: 'Toggle whether should also match case when searching for text'
36
- },
37
- findNext: {
38
- id: 'fabric.editor.findNext',
39
- defaultMessage: 'Find next',
40
- description: 'Locate the next occurrence of the word or phrase that was searched for'
41
- },
42
- findPrevious: {
43
- id: 'fabric.editor.findPrevious',
44
- defaultMessage: 'Find previous',
45
- description: 'Locate the previous occurrence of the word or phrase that was searched for'
46
- },
47
- closeFindReplaceDialog: {
48
- id: 'fabric.editor.closeFindReplaceDialog',
49
- defaultMessage: 'Close',
50
- description: 'Cancel search and close the "Find and Replace" dialog'
51
- },
52
- noResultsFound: {
53
- id: 'fabric.editor.noResultsFound',
54
- defaultMessage: 'No results',
55
- description: 'No matches were found for the word or phrase that was searched for'
56
- },
57
- resultsCount: {
58
- id: 'fabric.editor.resultsCount',
59
- description: 'Text for selected search match position and total results count',
60
- defaultMessage: '{selectedMatchPosition} of {totalResultsCount}'
61
- }
62
- });
63
- var Find = /*#__PURE__*/function (_React$Component) {
64
- _inherits(Find, _React$Component);
65
- var _super = _createSuper(Find);
66
- function Find(props) {
67
- var _this;
68
- _classCallCheck(this, Find);
69
- _this = _super.call(this, props);
70
- _defineProperty(_assertThisInitialized(_this), "findTextfieldRef", /*#__PURE__*/React.createRef());
71
- _defineProperty(_assertThisInitialized(_this), "isComposing", false);
72
- _defineProperty(_assertThisInitialized(_this), "syncFindText", function (onSynced) {
73
- var _this$state;
74
- // If the external prop findText changes and we aren't in a composition we should update to
75
- // use the external prop value.
76
- //
77
- // An example of where this may happen is when a find occurs through the user selecting some text
78
- // and pressing Mod-f.
79
- if (!_this.isComposing && _this.props.findText !== ((_this$state = _this.state) === null || _this$state === void 0 ? void 0 : _this$state.localFindText)) {
80
- _this.updateFindValue(_this.props.findText || '', onSynced);
81
- }
82
- });
83
- _defineProperty(_assertThisInitialized(_this), "focusFindTextfield", function () {
84
- var input = _this.findTextfieldRef.current;
85
- if (_this.props.shouldFocus && input) {
86
- input.select();
87
- }
88
- });
89
- _defineProperty(_assertThisInitialized(_this), "handleFindChange", function (event) {
90
- _this.updateFindValue(event.target.value);
91
- });
92
- // debounce (vs throttle) to not block typing inside find input while onFind runs
93
- _defineProperty(_assertThisInitialized(_this), "debouncedFind", debounce(function (value) {
94
- _this.props.onFind(value);
95
- }, FIND_DEBOUNCE_MS));
96
- _defineProperty(_assertThisInitialized(_this), "updateFindValue", function (value, onSynced) {
97
- _this.setState({
98
- localFindText: value
99
- }, function () {
100
- if (_this.isComposing) {
101
- return;
102
- }
103
- onSynced && onSynced();
104
- _this.debouncedFind(value);
105
- });
106
- });
107
- // throtlle between animation frames gives better experience on Enter compared to arbitrary value
108
- // it adjusts based on performance (and document size)
109
- _defineProperty(_assertThisInitialized(_this), "handleFindKeyDownThrottled", rafSchd(function (event) {
110
- if (event.key === 'Enter') {
111
- if (event.shiftKey) {
112
- _this.props.onFindPrev({
113
- triggerMethod: TRIGGER_METHOD.KEYBOARD
114
- });
115
- } else {
116
- _this.props.onFindNext({
117
- triggerMethod: TRIGGER_METHOD.KEYBOARD
118
- });
119
- }
120
- } else if (event.key === 'ArrowDown') {
121
- // we want to move focus between find & replace texfields when user hits up/down arrows
122
- _this.props.onArrowDown();
123
- }
124
- }));
125
- _defineProperty(_assertThisInitialized(_this), "handleFindKeyDown", function (event) {
126
- if (_this.isComposing) {
127
- return;
128
- }
129
- event.persist();
130
- _this.handleFindKeyDownThrottled(event);
131
- });
132
- _defineProperty(_assertThisInitialized(_this), "handleFindKeyUp", function () {
133
- _this.handleFindKeyDownThrottled.cancel();
134
- });
135
- _defineProperty(_assertThisInitialized(_this), "handleFindNextClick", function (ref) {
136
- if (_this.isComposing) {
137
- return;
138
- }
139
- _this.props.onFindNext({
140
- triggerMethod: TRIGGER_METHOD.BUTTON
141
- });
142
- });
143
- _defineProperty(_assertThisInitialized(_this), "handleFindPrevClick", function (ref) {
144
- if (_this.isComposing) {
145
- return;
146
- }
147
- _this.props.onFindPrev({
148
- triggerMethod: TRIGGER_METHOD.BUTTON
149
- });
150
- });
151
- _defineProperty(_assertThisInitialized(_this), "handleCompositionStart", function () {
152
- _this.isComposing = true;
153
- });
154
- _defineProperty(_assertThisInitialized(_this), "handleCompositionEnd", function (event) {
155
- _this.isComposing = false;
156
- // type for React.CompositionEvent doesn't set type for target correctly
157
- _this.updateFindValue(event.target.value);
158
- });
159
- _defineProperty(_assertThisInitialized(_this), "clearSearch", function () {
160
- _this.props.onCancel({
161
- triggerMethod: TRIGGER_METHOD.BUTTON
162
- });
163
- });
164
- _defineProperty(_assertThisInitialized(_this), "handleMatchCaseClick", function (buttonRef) {
165
- if (_this.props.allowMatchCase && _this.props.onToggleMatchCase) {
166
- _this.props.onToggleMatchCase();
167
- _this.props.onFind(_this.props.findText);
168
- }
169
- });
170
- var formatMessage = props.intl.formatMessage;
171
- _this.find = formatMessage(messages.find);
172
- _this.closeFindReplaceDialog = formatMessage(messages.closeFindReplaceDialog);
173
- _this.noResultsFound = formatMessage(messages.noResultsFound);
174
- _this.findNext = formatMessage(messages.findNext);
175
- _this.findPrevious = formatMessage(messages.findPrevious);
176
- _this.matchCase = formatMessage(messages.matchCase);
177
- _this.matchCaseIcon = jsx(MatchCaseIcon, {
178
- label: _this.matchCase
179
- });
180
- _this.findNextIcon = jsx(ChevronDownIcon, {
181
- label: _this.findNext
182
- });
183
- _this.findPrevIcon = jsx(ChevronUpIcon, {
184
- label: _this.findPrevious
185
- });
186
- _this.closeIcon = jsx(EditorCloseIcon, {
187
- label: _this.closeFindReplaceDialog
188
- });
189
-
190
- // We locally manage the value of the input inside this component in order to support compositions.
191
- // This requires some additional work inside componentDidUpdate to ensure we support changes that
192
- // occur to this value which do not originate from this component.
193
- _this.state = {
194
- localFindText: ''
195
- };
196
- return _this;
197
- }
198
- _createClass(Find, [{
199
- key: "componentDidMount",
200
- value: function componentDidMount() {
201
- var _this2 = this;
202
- this.props.onFindTextfieldRefSet(this.findTextfieldRef);
203
-
204
- // focus initially on dialog mount if there is no find text provided
205
- if (!this.props.findText) {
206
- this.focusFindTextfield();
207
- }
208
- this.syncFindText(function () {
209
- // focus after input is synced if find text provided
210
- if (_this2.props.findText) {
211
- _this2.focusFindTextfield();
212
- }
213
- });
214
- }
215
- }, {
216
- key: "componentDidUpdate",
217
- value: function componentDidUpdate(prevProps) {
218
- var _this3 = this;
219
- // focus on update if find text did not change
220
- if (!getBooleanFF('platform.editor.a11y-find-replace')) {
221
- var _this$state2;
222
- if (this.props.findText === ((_this$state2 = this.state) === null || _this$state2 === void 0 ? void 0 : _this$state2.localFindText)) {
223
- this.focusFindTextfield();
224
- }
225
- if (this.props.findText !== prevProps.findText) {
226
- this.syncFindText(function () {
227
- // focus after input is synced if find text provided
228
- if (_this3.props.findText) {
229
- _this3.focusFindTextfield();
230
- }
231
- });
232
- }
233
- }
234
- }
235
- }, {
236
- key: "componentWillUnmount",
237
- value: function componentWillUnmount() {
238
- this.debouncedFind.cancel();
239
- this.handleFindKeyDownThrottled.cancel();
240
- }
241
- }, {
242
- key: "render",
243
- value: function render() {
244
- var _this$props = this.props,
245
- findText = _this$props.findText,
246
- count = _this$props.count,
247
- allowMatchCase = _this$props.allowMatchCase,
248
- shouldMatchCase = _this$props.shouldMatchCase,
249
- formatMessage = _this$props.intl.formatMessage;
250
- var resultsCount = formatMessage(messages.resultsCount, {
251
- selectedMatchPosition: count.index + 1,
252
- totalResultsCount: count.total
253
- });
254
- return jsx("div", {
255
- css: sectionWrapperStyles
256
- }, jsx(Textfield, {
257
- name: "find",
258
- appearance: "none",
259
- placeholder: this.find,
260
- value: this.state.localFindText,
261
- ref: this.findTextfieldRef,
262
- autoComplete: "off",
263
- onChange: this.handleFindChange,
264
- onKeyDown: this.handleFindKeyDown,
265
- onKeyUp: this.handleFindKeyUp,
266
- onBlur: this.props.onFindBlur,
267
- onCompositionStart: this.handleCompositionStart,
268
- onCompositionEnd: this.handleCompositionEnd
269
- }), jsx("div", {
270
- css: countWrapperStyles,
271
- "aria-live": "polite"
272
- }, findText && jsx("span", {
273
- "data-testid": "textfield-count",
274
- css: countStyles
275
- }, count.total === 0 ? this.noResultsFound : resultsCount)), allowMatchCase && jsx(FindReplaceTooltipButton, {
276
- title: this.matchCase,
277
- icon: this.matchCaseIcon,
278
- onClick: this.handleMatchCaseClick,
279
- isPressed: shouldMatchCase
280
- }), jsx(FindReplaceTooltipButton, {
281
- title: this.findNext,
282
- icon: this.findNextIcon,
283
- keymapDescription: 'Enter',
284
- onClick: this.handleFindNextClick,
285
- disabled: count.total <= 1
286
- }), jsx(FindReplaceTooltipButton, {
287
- title: this.findPrevious,
288
- icon: this.findPrevIcon,
289
- keymapDescription: 'Shift Enter',
290
- onClick: this.handleFindPrevClick,
291
- disabled: count.total <= 1
292
- }), jsx(FindReplaceTooltipButton, {
293
- title: this.closeFindReplaceDialog,
294
- icon: this.closeIcon,
295
- keymapDescription: 'Escape',
296
- onClick: this.clearSearch
297
- }));
298
- }
299
- }]);
300
- return Find;
301
- }(React.Component);
302
- export default injectIntl(Find);
@@ -1,97 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
- /** @jsx jsx */
11
- import React from 'react';
12
- import { jsx } from '@emotion/react';
13
- import Find from './Find';
14
- import Replace from './Replace';
15
- import { ruleStyles, wrapperStyles } from './styles';
16
- var FindReplace = /*#__PURE__*/function (_React$PureComponent) {
17
- _inherits(FindReplace, _React$PureComponent);
18
- var _super = _createSuper(FindReplace);
19
- function FindReplace() {
20
- var _this;
21
- _classCallCheck(this, FindReplace);
22
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
23
- args[_key] = arguments[_key];
24
- }
25
- _this = _super.call.apply(_super, [this].concat(args));
26
- _defineProperty(_assertThisInitialized(_this), "findTextfield", null);
27
- _defineProperty(_assertThisInitialized(_this), "replaceTextfield", null);
28
- _defineProperty(_assertThisInitialized(_this), "setFindTextfieldRef", function (findTextfieldRef) {
29
- _this.findTextfield = findTextfieldRef.current;
30
- });
31
- _defineProperty(_assertThisInitialized(_this), "setReplaceTextfieldRef", function (replaceTextfieldRef) {
32
- _this.replaceTextfield = replaceTextfieldRef.current;
33
- });
34
- _defineProperty(_assertThisInitialized(_this), "setFocusToFind", function () {
35
- if (_this.findTextfield) {
36
- _this.findTextfield.focus();
37
- }
38
- });
39
- _defineProperty(_assertThisInitialized(_this), "setFocusToReplace", function () {
40
- if (_this.replaceTextfield) {
41
- _this.replaceTextfield.focus();
42
- }
43
- });
44
- return _this;
45
- }
46
- _createClass(FindReplace, [{
47
- key: "render",
48
- value: function render() {
49
- var _this$props = this.props,
50
- findText = _this$props.findText,
51
- count = _this$props.count,
52
- shouldFocus = _this$props.shouldFocus,
53
- onFind = _this$props.onFind,
54
- onFindBlur = _this$props.onFindBlur,
55
- onFindNext = _this$props.onFindNext,
56
- onFindPrev = _this$props.onFindPrev,
57
- onCancel = _this$props.onCancel,
58
- replaceText = _this$props.replaceText,
59
- onReplace = _this$props.onReplace,
60
- onReplaceAll = _this$props.onReplaceAll,
61
- dispatchAnalyticsEvent = _this$props.dispatchAnalyticsEvent,
62
- allowMatchCase = _this$props.allowMatchCase,
63
- shouldMatchCase = _this$props.shouldMatchCase,
64
- onToggleMatchCase = _this$props.onToggleMatchCase;
65
- return jsx("div", {
66
- css: wrapperStyles
67
- }, jsx(Find, {
68
- allowMatchCase: allowMatchCase,
69
- shouldMatchCase: shouldMatchCase,
70
- onToggleMatchCase: onToggleMatchCase,
71
- findText: findText,
72
- count: count,
73
- shouldFocus: shouldFocus,
74
- onFind: onFind,
75
- onFindBlur: onFindBlur,
76
- onFindPrev: onFindPrev,
77
- onFindNext: onFindNext,
78
- onFindTextfieldRefSet: this.setFindTextfieldRef,
79
- onCancel: onCancel,
80
- onArrowDown: this.setFocusToReplace
81
- }), jsx("hr", {
82
- css: ruleStyles,
83
- id: "replace-hr-element"
84
- }), jsx(Replace, {
85
- canReplace: count.total > 0,
86
- replaceText: replaceText,
87
- onReplace: onReplace,
88
- onReplaceAll: onReplaceAll,
89
- onReplaceTextfieldRefSet: this.setReplaceTextfieldRef,
90
- onArrowUp: this.setFocusToFind,
91
- dispatchAnalyticsEvent: dispatchAnalyticsEvent
92
- }));
93
- }
94
- }]);
95
- return FindReplace;
96
- }(React.PureComponent);
97
- export default FindReplace;