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