@atlaskit/editor-plugin-find-replace 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +26 -0
- package/CHANGELOG.md +11 -0
- package/LICENSE.md +13 -0
- package/README.md +30 -0
- package/dist/cjs/FindReplaceToolbarButtonWithState.js +166 -0
- package/dist/cjs/actions.js +19 -0
- package/dist/cjs/commands-with-analytics.js +101 -0
- package/dist/cjs/commands.js +255 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/plugin.js +93 -0
- package/dist/cjs/pm-plugins/keymap.js +24 -0
- package/dist/cjs/pm-plugins/main.js +39 -0
- package/dist/cjs/pm-plugins/plugin-factory.js +109 -0
- package/dist/cjs/pm-plugins/plugin-key.js +8 -0
- package/dist/cjs/reducer.js +61 -0
- package/dist/cjs/styles.js +17 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/ui/Find.js +309 -0
- package/dist/cjs/ui/FindReplace.js +104 -0
- package/dist/cjs/ui/FindReplaceToolbarButton.js +133 -0
- package/dist/cjs/ui/FindReplaceTooltipButton.js +77 -0
- package/dist/cjs/ui/Replace.js +176 -0
- package/dist/cjs/ui/styles.js +46 -0
- package/dist/cjs/utils/array.js +13 -0
- package/dist/cjs/utils/batch-decorations.js +310 -0
- package/dist/cjs/utils/commands.js +16 -0
- package/dist/cjs/utils/index.js +290 -0
- package/dist/es2019/FindReplaceToolbarButtonWithState.js +153 -0
- package/dist/es2019/actions.js +13 -0
- package/dist/es2019/commands-with-analytics.js +72 -0
- package/dist/es2019/commands.js +240 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/plugin.js +88 -0
- package/dist/es2019/pm-plugins/keymap.js +16 -0
- package/dist/es2019/pm-plugins/main.js +30 -0
- package/dist/es2019/pm-plugins/plugin-factory.js +91 -0
- package/dist/es2019/pm-plugins/plugin-key.js +2 -0
- package/dist/es2019/reducer.js +56 -0
- package/dist/es2019/styles.js +18 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/ui/Find.js +286 -0
- package/dist/es2019/ui/FindReplace.js +81 -0
- package/dist/es2019/ui/FindReplaceToolbarButton.js +122 -0
- package/dist/es2019/ui/FindReplaceTooltipButton.js +51 -0
- package/dist/es2019/ui/Replace.js +155 -0
- package/dist/es2019/ui/styles.js +50 -0
- package/dist/es2019/utils/array.js +3 -0
- package/dist/es2019/utils/batch-decorations.js +189 -0
- package/dist/es2019/utils/commands.js +6 -0
- package/dist/es2019/utils/index.js +249 -0
- package/dist/esm/FindReplaceToolbarButtonWithState.js +157 -0
- package/dist/esm/actions.js +13 -0
- package/dist/esm/commands-with-analytics.js +95 -0
- package/dist/esm/commands.js +248 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/plugin.js +86 -0
- package/dist/esm/pm-plugins/keymap.js +18 -0
- package/dist/esm/pm-plugins/main.js +33 -0
- package/dist/esm/pm-plugins/plugin-factory.js +104 -0
- package/dist/esm/pm-plugins/plugin-key.js +2 -0
- package/dist/esm/reducer.js +54 -0
- package/dist/esm/styles.js +11 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/ui/Find.js +304 -0
- package/dist/esm/ui/FindReplace.js +100 -0
- package/dist/esm/ui/FindReplaceToolbarButton.js +126 -0
- package/dist/esm/ui/FindReplaceTooltipButton.js +70 -0
- package/dist/esm/ui/Replace.js +171 -0
- package/dist/esm/ui/styles.js +39 -0
- package/dist/esm/utils/array.js +7 -0
- package/dist/esm/utils/batch-decorations.js +304 -0
- package/dist/esm/utils/commands.js +10 -0
- package/dist/esm/utils/index.js +280 -0
- package/dist/types/FindReplaceToolbarButtonWithState.d.ts +4 -0
- package/dist/types/actions.d.ts +64 -0
- package/dist/types/commands-with-analytics.d.ts +27 -0
- package/dist/types/commands.d.ts +12 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/plugin.d.ts +2 -0
- package/dist/types/pm-plugins/keymap.d.ts +4 -0
- package/dist/types/pm-plugins/main.d.ts +5 -0
- package/dist/types/pm-plugins/plugin-factory.d.ts +2 -0
- package/dist/types/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types/reducer.d.ts +4 -0
- package/dist/types/styles.d.ts +3 -0
- package/dist/types/types.d.ts +76 -0
- package/dist/types/ui/Find.d.ts +71 -0
- package/dist/types/ui/FindReplace.d.ts +43 -0
- package/dist/types/ui/FindReplaceToolbarButton.d.ts +21 -0
- package/dist/types/ui/FindReplaceTooltipButton.d.ts +18 -0
- package/dist/types/ui/Replace.d.ts +27 -0
- package/dist/types/ui/styles.d.ts +6 -0
- package/dist/types/utils/array.d.ts +1 -0
- package/dist/types/utils/batch-decorations.d.ts +36 -0
- package/dist/types/utils/commands.d.ts +2 -0
- package/dist/types/utils/index.d.ts +49 -0
- package/dist/types-ts4.5/FindReplaceToolbarButtonWithState.d.ts +4 -0
- package/dist/types-ts4.5/actions.d.ts +64 -0
- package/dist/types-ts4.5/commands-with-analytics.d.ts +27 -0
- package/dist/types-ts4.5/commands.d.ts +12 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/plugin.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +5 -0
- package/dist/types-ts4.5/pm-plugins/plugin-factory.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types-ts4.5/reducer.d.ts +4 -0
- package/dist/types-ts4.5/styles.d.ts +3 -0
- package/dist/types-ts4.5/types.d.ts +76 -0
- package/dist/types-ts4.5/ui/Find.d.ts +71 -0
- package/dist/types-ts4.5/ui/FindReplace.d.ts +43 -0
- package/dist/types-ts4.5/ui/FindReplaceToolbarButton.d.ts +21 -0
- package/dist/types-ts4.5/ui/FindReplaceTooltipButton.d.ts +18 -0
- package/dist/types-ts4.5/ui/Replace.d.ts +27 -0
- package/dist/types-ts4.5/ui/styles.d.ts +6 -0
- package/dist/types-ts4.5/utils/array.d.ts +1 -0
- package/dist/types-ts4.5/utils/batch-decorations.d.ts +36 -0
- package/dist/types-ts4.5/utils/commands.d.ts +2 -0
- package/dist/types-ts4.5/utils/index.d.ts +49 -0
- package/package.json +117 -0
- package/styles/package.json +17 -0
|
@@ -0,0 +1,171 @@
|
|
|
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
|
+
/* eslint-disable @atlaskit/design-system/consistent-css-prop-usage */
|
|
11
|
+
/** @jsx jsx */
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { jsx } from '@emotion/react';
|
|
14
|
+
import { defineMessages, injectIntl } from 'react-intl-next';
|
|
15
|
+
import Button from '@atlaskit/button/standard-button';
|
|
16
|
+
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, TRIGGER_METHOD } from '@atlaskit/editor-common/analytics';
|
|
17
|
+
import Textfield from '@atlaskit/textfield';
|
|
18
|
+
import { replaceSectionButtonStyles, sectionWrapperStyles } from './styles';
|
|
19
|
+
var messages = defineMessages({
|
|
20
|
+
replaceWith: {
|
|
21
|
+
id: 'fabric.editor.replaceWith',
|
|
22
|
+
defaultMessage: 'Replace with',
|
|
23
|
+
description: 'The value that will replace the word or phrase that was searched for'
|
|
24
|
+
},
|
|
25
|
+
replace: {
|
|
26
|
+
id: 'fabric.editor.replace',
|
|
27
|
+
defaultMessage: 'Replace',
|
|
28
|
+
description: 'Replace only the currently selected instance of the word or phrase'
|
|
29
|
+
},
|
|
30
|
+
replaceAll: {
|
|
31
|
+
id: 'fabric.editor.replaceAll',
|
|
32
|
+
defaultMessage: 'Replace all',
|
|
33
|
+
description: 'Replace all instances of the word or phrase throughout the entire document'
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
38
|
+
var Replace = /*#__PURE__*/function (_React$PureComponent) {
|
|
39
|
+
_inherits(Replace, _React$PureComponent);
|
|
40
|
+
var _super = _createSuper(Replace);
|
|
41
|
+
function Replace(props) {
|
|
42
|
+
var _this;
|
|
43
|
+
_classCallCheck(this, Replace);
|
|
44
|
+
_this = _super.call(this, props);
|
|
45
|
+
_defineProperty(_assertThisInitialized(_this), "replaceTextfieldRef", /*#__PURE__*/React.createRef());
|
|
46
|
+
_defineProperty(_assertThisInitialized(_this), "skipWhileComposing", function (fn) {
|
|
47
|
+
if (_this.state.isComposing) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
fn();
|
|
51
|
+
});
|
|
52
|
+
_defineProperty(_assertThisInitialized(_this), "handleReplaceClick", function () {
|
|
53
|
+
return _this.skipWhileComposing(function () {
|
|
54
|
+
_this.props.onReplace({
|
|
55
|
+
triggerMethod: TRIGGER_METHOD.BUTTON,
|
|
56
|
+
replaceText: _this.state.replaceText
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
_defineProperty(_assertThisInitialized(_this), "handleReplaceChange", function (event) {
|
|
61
|
+
return _this.skipWhileComposing(function () {
|
|
62
|
+
_this.updateReplaceValue(event.target.value);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
_defineProperty(_assertThisInitialized(_this), "updateReplaceValue", function (replaceText) {
|
|
66
|
+
var dispatchAnalyticsEvent = _this.props.dispatchAnalyticsEvent;
|
|
67
|
+
if (dispatchAnalyticsEvent) {
|
|
68
|
+
dispatchAnalyticsEvent({
|
|
69
|
+
eventType: EVENT_TYPE.TRACK,
|
|
70
|
+
action: ACTION.CHANGED_REPLACEMENT_TEXT,
|
|
71
|
+
actionSubject: ACTION_SUBJECT.FIND_REPLACE_DIALOG
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
_this.setState({
|
|
75
|
+
replaceText: replaceText
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
_defineProperty(_assertThisInitialized(_this), "handleReplaceKeyDown", function (event) {
|
|
79
|
+
return _this.skipWhileComposing(function () {
|
|
80
|
+
if (event.key === 'Enter') {
|
|
81
|
+
_this.props.onReplace({
|
|
82
|
+
triggerMethod: TRIGGER_METHOD.KEYBOARD,
|
|
83
|
+
replaceText: _this.state.replaceText
|
|
84
|
+
});
|
|
85
|
+
} else if (event.key === 'ArrowUp') {
|
|
86
|
+
// we want to move focus between find & replace texfields when user hits up/down arrows
|
|
87
|
+
_this.props.onArrowUp();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
_defineProperty(_assertThisInitialized(_this), "handleReplaceAllClick", function () {
|
|
92
|
+
return _this.skipWhileComposing(function () {
|
|
93
|
+
_this.props.onReplaceAll({
|
|
94
|
+
replaceText: _this.state.replaceText
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
_defineProperty(_assertThisInitialized(_this), "handleCompositionStart", function () {
|
|
99
|
+
_this.setState({
|
|
100
|
+
isComposing: true
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
_defineProperty(_assertThisInitialized(_this), "handleCompositionEnd", function (event) {
|
|
104
|
+
_this.setState({
|
|
105
|
+
isComposing: false
|
|
106
|
+
});
|
|
107
|
+
// type for React.CompositionEvent doesn't set type for target correctly
|
|
108
|
+
_this.updateReplaceValue(event.target.value);
|
|
109
|
+
});
|
|
110
|
+
var _replaceText = props.replaceText,
|
|
111
|
+
formatMessage = props.intl.formatMessage;
|
|
112
|
+
_this.state = {
|
|
113
|
+
replaceText: _replaceText || '',
|
|
114
|
+
isComposing: false
|
|
115
|
+
};
|
|
116
|
+
_this.replaceWith = formatMessage(messages.replaceWith);
|
|
117
|
+
_this.replace = formatMessage(messages.replace);
|
|
118
|
+
_this.replaceAll = formatMessage(messages.replaceAll);
|
|
119
|
+
return _this;
|
|
120
|
+
}
|
|
121
|
+
_createClass(Replace, [{
|
|
122
|
+
key: "componentDidMount",
|
|
123
|
+
value: function componentDidMount() {
|
|
124
|
+
this.props.onReplaceTextfieldRefSet(this.replaceTextfieldRef);
|
|
125
|
+
}
|
|
126
|
+
}, {
|
|
127
|
+
key: "componentDidUpdate",
|
|
128
|
+
value: function componentDidUpdate(_ref) {
|
|
129
|
+
var prevReplaceText = _ref.replaceText;
|
|
130
|
+
var replaceText = this.props.replaceText;
|
|
131
|
+
if (replaceText && replaceText !== prevReplaceText) {
|
|
132
|
+
this.setState({
|
|
133
|
+
replaceText: replaceText,
|
|
134
|
+
isComposing: false
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}, {
|
|
139
|
+
key: "render",
|
|
140
|
+
value: function render() {
|
|
141
|
+
var replaceText = this.state.replaceText;
|
|
142
|
+
var canReplace = this.props.canReplace;
|
|
143
|
+
return jsx("div", {
|
|
144
|
+
css: sectionWrapperStyles
|
|
145
|
+
}, jsx(Textfield, {
|
|
146
|
+
name: "replace",
|
|
147
|
+
appearance: "none",
|
|
148
|
+
placeholder: this.replaceWith,
|
|
149
|
+
defaultValue: replaceText,
|
|
150
|
+
ref: this.replaceTextfieldRef,
|
|
151
|
+
autoComplete: "off",
|
|
152
|
+
onChange: this.handleReplaceChange,
|
|
153
|
+
onKeyDown: this.handleReplaceKeyDown,
|
|
154
|
+
onCompositionStart: this.handleCompositionStart,
|
|
155
|
+
onCompositionEnd: this.handleCompositionEnd
|
|
156
|
+
}), jsx(Button, {
|
|
157
|
+
css: replaceSectionButtonStyles,
|
|
158
|
+
testId: this.replace,
|
|
159
|
+
onClick: this.handleReplaceClick,
|
|
160
|
+
isDisabled: !canReplace
|
|
161
|
+
}, this.replace), jsx(Button, {
|
|
162
|
+
css: replaceSectionButtonStyles,
|
|
163
|
+
testId: this.replaceAll,
|
|
164
|
+
onClick: this.handleReplaceAllClick,
|
|
165
|
+
isDisabled: !canReplace
|
|
166
|
+
}, this.replaceAll));
|
|
167
|
+
}
|
|
168
|
+
}]);
|
|
169
|
+
return Replace;
|
|
170
|
+
}(React.PureComponent);
|
|
171
|
+
export default injectIntl(Replace);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
2
|
+
var _templateObject;
|
|
3
|
+
/* eslint-disable @atlaskit/design-system/no-nested-styles */
|
|
4
|
+
/* eslint-disable @repo/internal/styles/no-exported-styles */
|
|
5
|
+
/** @jsx jsx */
|
|
6
|
+
import { css } from '@emotion/react';
|
|
7
|
+
import { relativeFontSizeToBase16 } from '@atlaskit/editor-shared-styles';
|
|
8
|
+
import { N30A, N60 } from '@atlaskit/theme/colors';
|
|
9
|
+
export var replaceSectionButtonStyles = css({
|
|
10
|
+
marginLeft: "var(--ds-space-050, 4px)"
|
|
11
|
+
});
|
|
12
|
+
export var ruleStyles = css({
|
|
13
|
+
width: '100%',
|
|
14
|
+
border: 'none',
|
|
15
|
+
backgroundColor: "".concat("var(--ds-border, ".concat(N30A, ")")),
|
|
16
|
+
margin: "var(--ds-space-050, 4px)".concat(" 0px"),
|
|
17
|
+
height: '1px',
|
|
18
|
+
borderRadius: '1px'
|
|
19
|
+
});
|
|
20
|
+
export var wrapperStyles = css({
|
|
21
|
+
display: 'flex',
|
|
22
|
+
flexDirection: 'column',
|
|
23
|
+
'> *:not(#replace-hr-element)': {
|
|
24
|
+
margin: "0px ".concat("var(--ds-space-050, 4px)")
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
export var sectionWrapperStyles = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n\n & > * {\n display: inline-flex;\n height: 32px;\n flex: 0 0 auto;\n }\n\n & > [data-ds--text-field--container] {\n display: flex;\n flex: 1 1 auto;\n }\n"])));
|
|
28
|
+
export var countStyles = css({
|
|
29
|
+
color: "".concat("var(--ds-text-subtlest, ".concat(N60, ")")),
|
|
30
|
+
fontSize: "".concat(relativeFontSizeToBase16(12)),
|
|
31
|
+
flex: '0 0 auto',
|
|
32
|
+
justifyContent: 'center',
|
|
33
|
+
alignItems: 'center',
|
|
34
|
+
marginLeft: "var(--ds-space-050, 4px)",
|
|
35
|
+
marginRight: "var(--ds-space-100, 8px)"
|
|
36
|
+
});
|
|
37
|
+
export var countWrapperStyles = css({
|
|
38
|
+
alignItems: 'center'
|
|
39
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function findUniqueItemsIn(findIn, checkWith, comparator) {
|
|
2
|
+
return findIn.filter(function (firstItem) {
|
|
3
|
+
return checkWith.findIndex(function (secondItem) {
|
|
4
|
+
return comparator ? comparator(firstItem, secondItem) : firstItem === secondItem;
|
|
5
|
+
}) === -1;
|
|
6
|
+
});
|
|
7
|
+
}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
+
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
6
|
+
import { createDecorations, findDecorationFromMatch } from './index';
|
|
7
|
+
|
|
8
|
+
// max number of decorations to apply at once
|
|
9
|
+
var batchIncrement = 100;
|
|
10
|
+
// position range to apply decorations between before alternating above or below viewport
|
|
11
|
+
var posIncrement = 2000;
|
|
12
|
+
/**
|
|
13
|
+
* Provides support for applying search match highlight decorations in batches
|
|
14
|
+
*/
|
|
15
|
+
var BatchDecorations = /*#__PURE__*/function () {
|
|
16
|
+
function BatchDecorations() {
|
|
17
|
+
_classCallCheck(this, BatchDecorations);
|
|
18
|
+
}
|
|
19
|
+
_createClass(BatchDecorations, [{
|
|
20
|
+
key: "stop",
|
|
21
|
+
value: function stop() {
|
|
22
|
+
if (this.rafId) {
|
|
23
|
+
cancelAnimationFrame(this.rafId);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Applies the decorations needed for the current search results
|
|
29
|
+
* It does so async, splitting them up into batches to help with performance
|
|
30
|
+
*/
|
|
31
|
+
}, {
|
|
32
|
+
key: "applyAllSearchDecorations",
|
|
33
|
+
value: function () {
|
|
34
|
+
var _applyAllSearchDecorations = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(editorView, containerElement, addDecorations, removeDecorations) {
|
|
35
|
+
var pmElement, positions, startPos, endPos, viewportStartPos, viewportEndPos, dir, before, after, diff;
|
|
36
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
37
|
+
while (1) switch (_context.prev = _context.next) {
|
|
38
|
+
case 0:
|
|
39
|
+
this.stop();
|
|
40
|
+
this.addDecorations = addDecorations;
|
|
41
|
+
this.removeDecorations = removeDecorations;
|
|
42
|
+
if (containerElement) {
|
|
43
|
+
_context.next = 5;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
return _context.abrupt("return");
|
|
47
|
+
case 5:
|
|
48
|
+
pmElement = containerElement.querySelector('.ProseMirror');
|
|
49
|
+
if (pmElement) {
|
|
50
|
+
_context.next = 8;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
return _context.abrupt("return");
|
|
54
|
+
case 8:
|
|
55
|
+
positions = this.calcDecorationPositions(editorView, containerElement, pmElement);
|
|
56
|
+
startPos = positions.startPos, endPos = positions.endPos, viewportStartPos = positions.viewportStartPos, viewportEndPos = positions.viewportEndPos;
|
|
57
|
+
dir = 0;
|
|
58
|
+
before = viewportStartPos;
|
|
59
|
+
after = viewportEndPos - posIncrement;
|
|
60
|
+
_context.next = 15;
|
|
61
|
+
return this.updateDecorationsBetween(editorView, viewportStartPos, viewportEndPos);
|
|
62
|
+
case 15:
|
|
63
|
+
if (!(before > startPos || after < endPos)) {
|
|
64
|
+
_context.next = 28;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
if (!(dir++ % 2 === 0 && before > startPos || after >= endPos)) {
|
|
68
|
+
_context.next = 23;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
diff = before - startPos;
|
|
72
|
+
before = Math.max(before - posIncrement, startPos);
|
|
73
|
+
_context.next = 21;
|
|
74
|
+
return this.updateDecorationsBetween(editorView, before, before + Math.min(diff, posIncrement));
|
|
75
|
+
case 21:
|
|
76
|
+
_context.next = 26;
|
|
77
|
+
break;
|
|
78
|
+
case 23:
|
|
79
|
+
after = Math.min(after + posIncrement, endPos);
|
|
80
|
+
_context.next = 26;
|
|
81
|
+
return this.updateDecorationsBetween(editorView, after, Math.min(after + posIncrement, endPos));
|
|
82
|
+
case 26:
|
|
83
|
+
_context.next = 15;
|
|
84
|
+
break;
|
|
85
|
+
case 28:
|
|
86
|
+
case "end":
|
|
87
|
+
return _context.stop();
|
|
88
|
+
}
|
|
89
|
+
}, _callee, this);
|
|
90
|
+
}));
|
|
91
|
+
function applyAllSearchDecorations(_x, _x2, _x3, _x4) {
|
|
92
|
+
return _applyAllSearchDecorations.apply(this, arguments);
|
|
93
|
+
}
|
|
94
|
+
return applyAllSearchDecorations;
|
|
95
|
+
}()
|
|
96
|
+
}, {
|
|
97
|
+
key: "updateDecorationsBetween",
|
|
98
|
+
value: function () {
|
|
99
|
+
var _updateDecorationsBetween = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(editorView, startPos, endPos) {
|
|
100
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
101
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
102
|
+
case 0:
|
|
103
|
+
_context2.next = 2;
|
|
104
|
+
return this.removeDecorationsBetween(editorView, startPos, endPos);
|
|
105
|
+
case 2:
|
|
106
|
+
_context2.next = 4;
|
|
107
|
+
return this.addDecorationsBetween(editorView, startPos, endPos);
|
|
108
|
+
case 4:
|
|
109
|
+
case "end":
|
|
110
|
+
return _context2.stop();
|
|
111
|
+
}
|
|
112
|
+
}, _callee2, this);
|
|
113
|
+
}));
|
|
114
|
+
function updateDecorationsBetween(_x5, _x6, _x7) {
|
|
115
|
+
return _updateDecorationsBetween.apply(this, arguments);
|
|
116
|
+
}
|
|
117
|
+
return updateDecorationsBetween;
|
|
118
|
+
}()
|
|
119
|
+
}, {
|
|
120
|
+
key: "addDecorationsBetween",
|
|
121
|
+
value: function () {
|
|
122
|
+
var _addDecorationsBetween = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(editorView, startPos, endPos) {
|
|
123
|
+
var _this = this;
|
|
124
|
+
var selection, _getPluginState, matches, decorationSet, matchesBetween, selectionMatch, selectionIndex;
|
|
125
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
126
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
127
|
+
case 0:
|
|
128
|
+
selection = editorView.state.selection;
|
|
129
|
+
_getPluginState = getPluginState(editorView.state), matches = _getPluginState.matches, decorationSet = _getPluginState.decorationSet;
|
|
130
|
+
if (!(matches.length === 0)) {
|
|
131
|
+
_context3.next = 4;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
return _context3.abrupt("return");
|
|
135
|
+
case 4:
|
|
136
|
+
matchesBetween = matches.filter(function (m) {
|
|
137
|
+
return m.start >= startPos && (endPos === undefined || m.start < endPos);
|
|
138
|
+
});
|
|
139
|
+
selectionMatch = matches.find(function (match) {
|
|
140
|
+
return match.start >= selection.from;
|
|
141
|
+
});
|
|
142
|
+
selectionIndex = matchesBetween.findIndex(function (match) {
|
|
143
|
+
return match === selectionMatch;
|
|
144
|
+
});
|
|
145
|
+
_context3.next = 9;
|
|
146
|
+
return this.batchRequests(function (counter) {
|
|
147
|
+
var matchesToDecorate = matchesBetween.slice(counter, counter + batchIncrement);
|
|
148
|
+
if (matchesToDecorate.length === 0) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
var useSelectionIndex = selectionIndex >= counter && selectionIndex < counter + batchIncrement;
|
|
152
|
+
if (selectionMatch && useSelectionIndex) {
|
|
153
|
+
var selectionMatchDecoration = findDecorationFromMatch(decorationSet, selectionMatch);
|
|
154
|
+
if (selectionMatchDecoration) {
|
|
155
|
+
matchesToDecorate.splice(selectionIndex % batchIncrement, 1);
|
|
156
|
+
useSelectionIndex = false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (_this.addDecorations) {
|
|
160
|
+
_this.addDecorations(createDecorations(useSelectionIndex ? selectionIndex % batchIncrement : -1, matchesToDecorate));
|
|
161
|
+
}
|
|
162
|
+
}, {
|
|
163
|
+
increment: batchIncrement,
|
|
164
|
+
until: matchesBetween.length
|
|
165
|
+
});
|
|
166
|
+
case 9:
|
|
167
|
+
return _context3.abrupt("return", _context3.sent);
|
|
168
|
+
case 10:
|
|
169
|
+
case "end":
|
|
170
|
+
return _context3.stop();
|
|
171
|
+
}
|
|
172
|
+
}, _callee3, this);
|
|
173
|
+
}));
|
|
174
|
+
function addDecorationsBetween(_x8, _x9, _x10) {
|
|
175
|
+
return _addDecorationsBetween.apply(this, arguments);
|
|
176
|
+
}
|
|
177
|
+
return addDecorationsBetween;
|
|
178
|
+
}()
|
|
179
|
+
}, {
|
|
180
|
+
key: "removeDecorationsBetween",
|
|
181
|
+
value: function () {
|
|
182
|
+
var _removeDecorationsBetween = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(editorView, startPos, endPos) {
|
|
183
|
+
var _this2 = this;
|
|
184
|
+
var _getPluginState2, decorationSet, decorations;
|
|
185
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
186
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
187
|
+
case 0:
|
|
188
|
+
_getPluginState2 = getPluginState(editorView.state), decorationSet = _getPluginState2.decorationSet;
|
|
189
|
+
decorations = decorationSet.find(startPos, endPos);
|
|
190
|
+
if (!(decorations.length === 0)) {
|
|
191
|
+
_context4.next = 4;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
return _context4.abrupt("return");
|
|
195
|
+
case 4:
|
|
196
|
+
_context4.next = 6;
|
|
197
|
+
return this.batchRequests(function (counter) {
|
|
198
|
+
var decorationsToRemove = decorations.slice(counter, counter + batchIncrement);
|
|
199
|
+
if (decorationsToRemove.length === 0) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
// only get those decorations whose from >= startPos
|
|
203
|
+
for (var i = 0; i < decorationsToRemove.length; i++) {
|
|
204
|
+
if (decorationsToRemove[i].from >= startPos) {
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
decorationsToRemove = decorationsToRemove.slice(1);
|
|
208
|
+
}
|
|
209
|
+
if (_this2.removeDecorations) {
|
|
210
|
+
_this2.removeDecorations(decorationsToRemove);
|
|
211
|
+
}
|
|
212
|
+
}, {
|
|
213
|
+
increment: batchIncrement,
|
|
214
|
+
until: decorations.length
|
|
215
|
+
});
|
|
216
|
+
case 6:
|
|
217
|
+
return _context4.abrupt("return", _context4.sent);
|
|
218
|
+
case 7:
|
|
219
|
+
case "end":
|
|
220
|
+
return _context4.stop();
|
|
221
|
+
}
|
|
222
|
+
}, _callee4, this);
|
|
223
|
+
}));
|
|
224
|
+
function removeDecorationsBetween(_x11, _x12, _x13) {
|
|
225
|
+
return _removeDecorationsBetween.apply(this, arguments);
|
|
226
|
+
}
|
|
227
|
+
return removeDecorationsBetween;
|
|
228
|
+
}()
|
|
229
|
+
/**
|
|
230
|
+
* Calculates Prosemirror start and end positions we want to apply the decorations
|
|
231
|
+
* between
|
|
232
|
+
* Also calculates the positions the are the start and end of the user's viewport
|
|
233
|
+
* so we can apply decorations there first and work outwards
|
|
234
|
+
*/
|
|
235
|
+
}, {
|
|
236
|
+
key: "calcDecorationPositions",
|
|
237
|
+
value: function calcDecorationPositions(editorView, containerElement, pmElement) {
|
|
238
|
+
var containerRect = containerElement.getBoundingClientRect();
|
|
239
|
+
var pmRect = pmElement.getBoundingClientRect();
|
|
240
|
+
var viewportStartPos = this.getStartPos(editorView, 0, pmRect.left);
|
|
241
|
+
var viewportEndPos = this.getEndPos(editorView, containerRect.top + containerRect.height, pmRect.left);
|
|
242
|
+
return {
|
|
243
|
+
viewportStartPos: viewportStartPos,
|
|
244
|
+
viewportEndPos: viewportEndPos,
|
|
245
|
+
startPos: 1,
|
|
246
|
+
endPos: editorView.state.doc.nodeSize
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
}, {
|
|
250
|
+
key: "getStartPos",
|
|
251
|
+
value: function getStartPos(editorView, y, x) {
|
|
252
|
+
var startPos = editorView.posAtCoords({
|
|
253
|
+
top: y,
|
|
254
|
+
left: x
|
|
255
|
+
});
|
|
256
|
+
return startPos ? startPos.pos : 1;
|
|
257
|
+
}
|
|
258
|
+
}, {
|
|
259
|
+
key: "getEndPos",
|
|
260
|
+
value: function getEndPos(editorView, y, x) {
|
|
261
|
+
var maxPos = editorView.state.doc.nodeSize;
|
|
262
|
+
var endPos = editorView.posAtCoords({
|
|
263
|
+
top: y,
|
|
264
|
+
left: x
|
|
265
|
+
});
|
|
266
|
+
return endPos ? endPos.pos : maxPos;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Util to batch function calls by animation frames
|
|
271
|
+
* A counter will start at 0 and increment by provided value until reaches limit
|
|
272
|
+
* Passed in fn receives the counter as a param, return false to skip waiting
|
|
273
|
+
* for the animation frame for the next call
|
|
274
|
+
*/
|
|
275
|
+
}, {
|
|
276
|
+
key: "batchRequests",
|
|
277
|
+
value: function batchRequests(fn, opts) {
|
|
278
|
+
var _this3 = this;
|
|
279
|
+
var counter = 0;
|
|
280
|
+
var increment = opts.increment,
|
|
281
|
+
until = opts.until;
|
|
282
|
+
return new Promise(function (resolve) {
|
|
283
|
+
var batchedFn = function batchedFn() {
|
|
284
|
+
var result = fn(counter);
|
|
285
|
+
while (result === false && counter < until) {
|
|
286
|
+
counter += increment;
|
|
287
|
+
result = fn(counter);
|
|
288
|
+
}
|
|
289
|
+
if (counter < until) {
|
|
290
|
+
counter += increment;
|
|
291
|
+
_this3.rafId = requestAnimationFrame(batchedFn);
|
|
292
|
+
} else {
|
|
293
|
+
_this3.rafId = undefined;
|
|
294
|
+
resolve();
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
_this3.rafId = requestAnimationFrame(batchedFn);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}]);
|
|
301
|
+
return BatchDecorations;
|
|
302
|
+
}();
|
|
303
|
+
var batchDecorations = new BatchDecorations();
|
|
304
|
+
export default batchDecorations;
|