@atlaskit/editor-core 187.47.9 → 187.48.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 (108) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cjs/editor-next/index.js +2 -2
  3. package/dist/cjs/index.js +7 -7
  4. package/dist/cjs/labs/next/presets/default.js +2 -2
  5. package/dist/cjs/plugins/index.js +0 -7
  6. package/dist/cjs/test-utils.js +2 -2
  7. package/dist/cjs/version-wrapper.js +1 -1
  8. package/dist/es2019/editor-next/index.js +1 -1
  9. package/dist/es2019/index.js +1 -1
  10. package/dist/es2019/labs/next/presets/default.js +1 -1
  11. package/dist/es2019/plugins/index.js +0 -1
  12. package/dist/es2019/test-utils.js +1 -1
  13. package/dist/es2019/version-wrapper.js +1 -1
  14. package/dist/esm/editor-next/index.js +1 -1
  15. package/dist/esm/index.js +1 -1
  16. package/dist/esm/labs/next/presets/default.js +1 -1
  17. package/dist/esm/plugins/index.js +0 -1
  18. package/dist/esm/test-utils.js +1 -1
  19. package/dist/esm/version-wrapper.js +1 -1
  20. package/dist/types/create-editor/create-plugins-list.d.ts +1 -1
  21. package/dist/types/index.d.ts +1 -1
  22. package/dist/types/labs/next/presets/default.d.ts +1 -1
  23. package/dist/types/plugins/code-block/ide-ux/quote-handling.d.ts +1 -1
  24. package/dist/types/plugins/index.d.ts +0 -1
  25. package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
  26. package/dist/types/ui/ConfigPanel/FormErrorBoundary.d.ts +1 -1
  27. package/dist/types/ui/ContentStyles/index.d.ts +2 -2
  28. package/dist/types-ts4.5/create-editor/create-plugins-list.d.ts +1 -1
  29. package/dist/types-ts4.5/index.d.ts +1 -1
  30. package/dist/types-ts4.5/labs/next/presets/default.d.ts +1 -1
  31. package/dist/types-ts4.5/plugins/code-block/ide-ux/quote-handling.d.ts +1 -1
  32. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  33. package/dist/types-ts4.5/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
  34. package/dist/types-ts4.5/ui/ConfigPanel/FormErrorBoundary.d.ts +1 -1
  35. package/dist/types-ts4.5/ui/ContentStyles/index.d.ts +2 -2
  36. package/package.json +8 -9
  37. package/report.api.md +3 -26
  38. package/tmp/api-report-tmp.d.ts +3 -26
  39. package/dist/cjs/plugins/base/commands.js +0 -20
  40. package/dist/cjs/plugins/base/index.js +0 -13
  41. package/dist/cjs/plugins/base/plugin.js +0 -143
  42. package/dist/cjs/plugins/base/pm-plugins/context-identifier.js +0 -58
  43. package/dist/cjs/plugins/base/pm-plugins/disable-spell-checking.js +0 -63
  44. package/dist/cjs/plugins/base/pm-plugins/filter-steps.js +0 -34
  45. package/dist/cjs/plugins/base/pm-plugins/fix-chrome-88-selection.js +0 -34
  46. package/dist/cjs/plugins/base/pm-plugins/frozen-editor.js +0 -265
  47. package/dist/cjs/plugins/base/pm-plugins/inline-cursor-target.js +0 -183
  48. package/dist/cjs/plugins/base/pm-plugins/newline-preserve-marks.js +0 -34
  49. package/dist/cjs/plugins/base/pm-plugins/scroll-gutter/index.js +0 -262
  50. package/dist/cjs/plugins/base/pm-plugins/scroll-gutter/plugin-key.js +0 -15
  51. package/dist/cjs/plugins/base/utils/frozen-editor.js +0 -11
  52. package/dist/cjs/plugins/base/utils/input-latency-tracking.js +0 -134
  53. package/dist/es2019/plugins/base/commands.js +0 -13
  54. package/dist/es2019/plugins/base/index.js +0 -2
  55. package/dist/es2019/plugins/base/plugin.js +0 -113
  56. package/dist/es2019/plugins/base/pm-plugins/context-identifier.js +0 -43
  57. package/dist/es2019/plugins/base/pm-plugins/disable-spell-checking.js +0 -54
  58. package/dist/es2019/plugins/base/pm-plugins/filter-steps.js +0 -23
  59. package/dist/es2019/plugins/base/pm-plugins/fix-chrome-88-selection.js +0 -24
  60. package/dist/es2019/plugins/base/pm-plugins/frozen-editor.js +0 -258
  61. package/dist/es2019/plugins/base/pm-plugins/inline-cursor-target.js +0 -186
  62. package/dist/es2019/plugins/base/pm-plugins/newline-preserve-marks.js +0 -20
  63. package/dist/es2019/plugins/base/pm-plugins/scroll-gutter/index.js +0 -242
  64. package/dist/es2019/plugins/base/pm-plugins/scroll-gutter/plugin-key.js +0 -7
  65. package/dist/es2019/plugins/base/utils/frozen-editor.js +0 -2
  66. package/dist/es2019/plugins/base/utils/input-latency-tracking.js +0 -104
  67. package/dist/esm/plugins/base/commands.js +0 -13
  68. package/dist/esm/plugins/base/index.js +0 -2
  69. package/dist/esm/plugins/base/plugin.js +0 -131
  70. package/dist/esm/plugins/base/pm-plugins/context-identifier.js +0 -48
  71. package/dist/esm/plugins/base/pm-plugins/disable-spell-checking.js +0 -56
  72. package/dist/esm/plugins/base/pm-plugins/filter-steps.js +0 -27
  73. package/dist/esm/plugins/base/pm-plugins/fix-chrome-88-selection.js +0 -26
  74. package/dist/esm/plugins/base/pm-plugins/frozen-editor.js +0 -251
  75. package/dist/esm/plugins/base/pm-plugins/inline-cursor-target.js +0 -174
  76. package/dist/esm/plugins/base/pm-plugins/newline-preserve-marks.js +0 -26
  77. package/dist/esm/plugins/base/pm-plugins/scroll-gutter/index.js +0 -254
  78. package/dist/esm/plugins/base/pm-plugins/scroll-gutter/plugin-key.js +0 -7
  79. package/dist/esm/plugins/base/utils/frozen-editor.js +0 -4
  80. package/dist/esm/plugins/base/utils/input-latency-tracking.js +0 -128
  81. package/dist/types/plugins/base/commands.d.ts +0 -2
  82. package/dist/types/plugins/base/index.d.ts +0 -5
  83. package/dist/types/plugins/base/plugin.d.ts +0 -25
  84. package/dist/types/plugins/base/pm-plugins/context-identifier.d.ts +0 -13
  85. package/dist/types/plugins/base/pm-plugins/disable-spell-checking.d.ts +0 -4
  86. package/dist/types/plugins/base/pm-plugins/filter-steps.d.ts +0 -4
  87. package/dist/types/plugins/base/pm-plugins/fix-chrome-88-selection.d.ts +0 -5
  88. package/dist/types/plugins/base/pm-plugins/frozen-editor.d.ts +0 -12
  89. package/dist/types/plugins/base/pm-plugins/inline-cursor-target.d.ts +0 -17
  90. package/dist/types/plugins/base/pm-plugins/newline-preserve-marks.d.ts +0 -5
  91. package/dist/types/plugins/base/pm-plugins/scroll-gutter/index.d.ts +0 -22
  92. package/dist/types/plugins/base/pm-plugins/scroll-gutter/plugin-key.d.ts +0 -7
  93. package/dist/types/plugins/base/utils/frozen-editor.d.ts +0 -2
  94. package/dist/types/plugins/base/utils/input-latency-tracking.d.ts +0 -42
  95. package/dist/types-ts4.5/plugins/base/commands.d.ts +0 -2
  96. package/dist/types-ts4.5/plugins/base/index.d.ts +0 -5
  97. package/dist/types-ts4.5/plugins/base/plugin.d.ts +0 -27
  98. package/dist/types-ts4.5/plugins/base/pm-plugins/context-identifier.d.ts +0 -13
  99. package/dist/types-ts4.5/plugins/base/pm-plugins/disable-spell-checking.d.ts +0 -4
  100. package/dist/types-ts4.5/plugins/base/pm-plugins/filter-steps.d.ts +0 -4
  101. package/dist/types-ts4.5/plugins/base/pm-plugins/fix-chrome-88-selection.d.ts +0 -5
  102. package/dist/types-ts4.5/plugins/base/pm-plugins/frozen-editor.d.ts +0 -12
  103. package/dist/types-ts4.5/plugins/base/pm-plugins/inline-cursor-target.d.ts +0 -17
  104. package/dist/types-ts4.5/plugins/base/pm-plugins/newline-preserve-marks.d.ts +0 -5
  105. package/dist/types-ts4.5/plugins/base/pm-plugins/scroll-gutter/index.d.ts +0 -22
  106. package/dist/types-ts4.5/plugins/base/pm-plugins/scroll-gutter/plugin-key.d.ts +0 -7
  107. package/dist/types-ts4.5/plugins/base/utils/frozen-editor.d.ts +0 -2
  108. package/dist/types-ts4.5/plugins/base/utils/input-latency-tracking.d.ts +0 -42
@@ -1,242 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { GUTTER_SELECTOR, GUTTER_SIZE_IN_PX, isEmptyDocument } from '@atlaskit/editor-common/utils';
3
- import { getScrollGutterPluginState, scrollGutterPluginKey } from './plugin-key';
4
- export const getKeyboardHeight = state => {
5
- if (state) {
6
- const scrollGutterPluginState = getScrollGutterPluginState(state);
7
- return scrollGutterPluginState ? scrollGutterPluginState.keyboardHeight : undefined;
8
- }
9
- };
10
- const MIN_TAP_SIZE_IN_PX = 40;
11
- function supportsIntersectionObserver() {
12
- if (typeof window !== 'undefined' && 'IntersectionObserver' in window && 'IntersectionObserverEntry' in window && 'intersectionRatio' in window.IntersectionObserverEntry.prototype) {
13
- return true;
14
- }
15
- return false;
16
- }
17
- function listenForGutterVisibilityChanges(scrollElement, gutterIsVisible) {
18
- if (supportsIntersectionObserver()) {
19
- const observer = new IntersectionObserver((entries, _) => {
20
- entries.forEach(entry => {
21
- gutterIsVisible(entry.intersectionRatio > 0);
22
- });
23
- }, {
24
- root: scrollElement,
25
- rootMargin: '0px',
26
- threshold: 0
27
- });
28
- return observer;
29
- }
30
- return undefined;
31
- }
32
-
33
- /**
34
- * Create a gutter element that can be added or removed from the DOM.
35
- */
36
- function createGutter(gutterSize) {
37
- const gutter = document.createElement('div');
38
- gutter.style.paddingBottom = `${gutterSize}px`;
39
- gutter.id = GUTTER_SELECTOR.substr(1);
40
- let initialized = false;
41
- let mounted = false;
42
- let currentParent = null;
43
- let observer;
44
- let isVisible = false;
45
- return {
46
- addGutter(parent) {
47
- if (parent) {
48
- currentParent = parent;
49
- parent.appendChild(gutter);
50
- mounted = true;
51
- if (observer) {
52
- observer.observe(gutter);
53
- }
54
- }
55
- },
56
- removeGutter() {
57
- if (currentParent && mounted) {
58
- mounted = false;
59
- currentParent.removeChild(gutter);
60
- if (observer) {
61
- observer.unobserve(gutter);
62
- }
63
- }
64
- },
65
- element() {
66
- return gutter;
67
- },
68
- isMounted() {
69
- return mounted;
70
- },
71
- visible() {
72
- // If we know whether it's visible we can avoid expensive calculations
73
- if (observer) {
74
- return isVisible;
75
- }
76
- // Fallback for legacy browsers assumes it's visible (if mounted)
77
- return mounted;
78
- },
79
- observe(scrollElement) {
80
- if (!initialized) {
81
- initialized = true;
82
- observer = listenForGutterVisibilityChanges(scrollElement, visible => isVisible = visible);
83
- }
84
- },
85
- destroy() {
86
- if (observer) {
87
- observer.disconnect();
88
- }
89
- observer = undefined;
90
- this.removeGutter();
91
- initialized = mounted = false;
92
- }
93
- };
94
- }
95
-
96
- /**
97
- * Get caret top position given the current selection,
98
- * use start container position as fallback
99
- */
100
- function getCaretTopPosition() {
101
- const windowSelection = window.getSelection();
102
- if (windowSelection && windowSelection.rangeCount > 0) {
103
- const range = windowSelection.getRangeAt(0);
104
- if (range) {
105
- const clientRects = range.getClientRects();
106
- // Return client rects
107
- if (clientRects && clientRects.length > 0) {
108
- return clientRects[0].top;
109
- }
110
-
111
- // Return container top
112
- const container = range.startContainer;
113
- if (container && container.getBoundingClientRect) {
114
- return container.getBoundingClientRect().top;
115
- }
116
- }
117
- }
118
- return;
119
- }
120
- function scrollToGutterElement(scrollContainer, gutterElement, gutterSize) {
121
- const viewportHeight = scrollContainer.offsetHeight;
122
- const viewportOffsetY = scrollContainer.getBoundingClientRect().top;
123
- const caretTopPosition = getCaretTopPosition();
124
- if (!caretTopPosition) {
125
- return false;
126
- }
127
- const caretTopFromContainer = caretTopPosition - viewportOffsetY;
128
- const gutterThresholdTop = viewportHeight - gutterSize - MIN_TAP_SIZE_IN_PX * 2;
129
- if (caretTopFromContainer < gutterThresholdTop) {
130
- return false;
131
- }
132
-
133
- // Clamp the scroll position to above the scroll gutter element.
134
- gutterElement.scrollIntoView(false);
135
-
136
- // Mark scrolling as handled so that other plugin's don't override our position.
137
- return true;
138
- }
139
- export default ((pluginOptions = {}) => {
140
- const {
141
- getScrollElement,
142
- allowCustomScrollHandler,
143
- gutterSize = GUTTER_SIZE_IN_PX
144
- } = pluginOptions;
145
- if (!getScrollElement) {
146
- return undefined;
147
- }
148
- const gutter = createGutter(gutterSize);
149
- let scrollElement = null; // | undefined;
150
-
151
- return new SafePlugin({
152
- key: scrollGutterPluginKey,
153
- state: {
154
- init: () => ({}),
155
- apply: (tr, pluginState) => {
156
- if (tr.getMeta(scrollGutterPluginKey)) {
157
- return tr.getMeta(scrollGutterPluginKey);
158
- }
159
- return pluginState;
160
- }
161
- },
162
- props: {
163
- // Determines the distance (in pixels) between the cursor and the end of the visible viewport at which point,
164
- // when scrolling the cursor into view, scrolling takes place.
165
- // Defaults to 0: https://prosemirror.net/docs/ref/#view.EditorProps.scrollThreshold
166
- scrollThreshold: gutterSize / 2,
167
- // Determines the extra space (in pixels) that is left above or below the cursor when it is scrolled into view.
168
- // Defaults to 5: https://prosemirror.net/docs/ref/#view.EditorProps.scrollMargin
169
- scrollMargin: gutterSize,
170
- // Called when the view, after updating its state, tries to scroll the selection into view
171
- // https://prosemirror.net/docs/ref/#view.EditorProps.handleScrollToSelection
172
- handleScrollToSelection: () => {
173
- if (allowCustomScrollHandler === false) {
174
- return false;
175
- }
176
- if (!gutter.isMounted() || !gutter.visible() || !scrollElement) {
177
- // Avoid scrolling until applicable
178
- return false;
179
- }
180
- return scrollToGutterElement(scrollElement, gutter.element(), gutterSize);
181
- }
182
- },
183
- view(view) {
184
- // Store references to avoid lookups on successive checks.
185
- scrollElement = getScrollElement(view);
186
- let editorElement = view.dom;
187
- let editorParentElement = editorElement.parentElement;
188
- return {
189
- destroy() {
190
- // Remove if it's mounted
191
- gutter.destroy();
192
- scrollElement = editorParentElement = editorElement = null;
193
- },
194
- /**
195
- * Toggle the Scroll Gutter Element
196
- */
197
- update(view, prevState) {
198
- var _getKeyboardHeight;
199
- if (!scrollElement || !editorParentElement) {
200
- return;
201
- }
202
- const state = view.state;
203
- if (prevState.selection === state.selection) {
204
- // No need to recheck if the selected node hasn't changed.
205
- return;
206
- }
207
- const gutterMounted = gutter.isMounted();
208
- const addAndObserveGutter = () => {
209
- if (!gutterMounted) {
210
- gutter.observe(scrollElement);
211
- gutter.addGutter(editorParentElement);
212
- }
213
- };
214
- if (pluginOptions.persistScrollGutter) {
215
- if (!isEmptyDocument(state.doc)) {
216
- addAndObserveGutter();
217
- } else {
218
- gutter.removeGutter();
219
- }
220
- return;
221
- }
222
- // Determine whether we need to consider Keyboard Height
223
- const keyboardHeight = (_getKeyboardHeight = getKeyboardHeight(state)) !== null && _getKeyboardHeight !== void 0 ? _getKeyboardHeight : 0;
224
- const viewportHeight = scrollElement.offsetHeight - keyboardHeight;
225
- const contentHeight = editorParentElement.offsetHeight - (gutterMounted ? gutterSize : 0);
226
-
227
- // Add or remove the gutter based on whether the content is about to exceed the viewport height.
228
- // We do this to ensure there is sufficient white space below the last content node in order to
229
- // see any UI control elements which may sit beneath it.
230
- const gutterThresholdHeight = viewportHeight - gutterSize;
231
- if (contentHeight >= gutterThresholdHeight) {
232
- addAndObserveGutter();
233
- } else {
234
- if (gutterMounted) {
235
- gutter.removeGutter();
236
- }
237
- }
238
- }
239
- };
240
- }
241
- });
242
- });
@@ -1,7 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
- export const scrollGutterPluginKey = new PluginKey('scrollGutter');
3
- export const getScrollGutterPluginState = state => {
4
- if (state) {
5
- return scrollGutterPluginKey.getState(state);
6
- }
7
- };
@@ -1,2 +0,0 @@
1
- /** Allows the possibility of overriding interaction type values in unit tests via jest.mock or spyOn. */
2
- export const setInteractionType = value => value;
@@ -1,104 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import { getTimeSince } from '@atlaskit/editor-common/utils';
3
- import { getAnalyticsEventSeverity } from '@atlaskit/editor-common/utils';
4
- export default class InputLatencyTracker {
5
- constructor({
6
- samplingRate,
7
- slowThreshold,
8
- normalThreshold,
9
- degradedThreshold,
10
- dispatchAverage,
11
- dispatchSample,
12
- onSampleStart,
13
- onSampleEnd,
14
- onSlowInput
15
- }) {
16
- _defineProperty(this, "samples", []);
17
- _defineProperty(this, "total", 0);
18
- this.samplingRate = samplingRate;
19
- this.slowThreshold = slowThreshold;
20
- this.normalThreshold = normalThreshold;
21
- this.degradedThreshold = degradedThreshold;
22
- this.dispatchAverage = dispatchAverage;
23
- this.dispatchSample = dispatchSample;
24
- this.onSampleStart = onSampleStart;
25
- this.onSampleEnd = onSampleEnd;
26
- this.onSlowInput = onSlowInput;
27
- }
28
- start() {
29
- const currentStart = performance.now();
30
- if (this.samples.length + 1 === this.samplingRate) {
31
- var _this$onSampleStart;
32
- (_this$onSampleStart = this.onSampleStart) === null || _this$onSampleStart === void 0 ? void 0 : _this$onSampleStart.call(this);
33
- }
34
- const end = () => {
35
- if (currentStart === null) {
36
- return;
37
- }
38
- let isSlow = false;
39
- const time = getTimeSince(currentStart);
40
- this.push(time);
41
- if (time > this.slowThreshold) {
42
- var _this$onSlowInput;
43
- (_this$onSlowInput = this.onSlowInput) === null || _this$onSlowInput === void 0 ? void 0 : _this$onSlowInput.call(this, time);
44
- isSlow = true;
45
- }
46
- if (this.samples.length === this.samplingRate) {
47
- var _this$onSampleEnd;
48
- this.flush();
49
- (_this$onSampleEnd = this.onSampleEnd) === null || _this$onSampleEnd === void 0 ? void 0 : _this$onSampleEnd.call(this, time, {
50
- isSlow,
51
- severity: this.severity(time)
52
- });
53
- }
54
- };
55
- return end;
56
- }
57
- flush() {
58
- if (this.samples.length === 0) {
59
- return;
60
- }
61
- this.dispatch();
62
- this.samples = [];
63
- this.total = 0;
64
- }
65
- dispatch() {
66
- var _this$dispatchSample, _this$dispatchAverage;
67
- (_this$dispatchSample = this.dispatchSample) === null || _this$dispatchSample === void 0 ? void 0 : _this$dispatchSample.call(this, this.getLast(), this.severity(this.getLast()));
68
- // cache
69
- const median = this.getMedian();
70
- (_this$dispatchAverage = this.dispatchAverage) === null || _this$dispatchAverage === void 0 ? void 0 : _this$dispatchAverage.call(this, {
71
- mean: this.getMean(),
72
- median,
73
- sampleSize: this.samples.length
74
- }, this.severity(median));
75
- }
76
- push(latency) {
77
- this.samples.push(latency);
78
- this.total += latency;
79
- }
80
- severity(time) {
81
- return getAnalyticsEventSeverity(time, this.normalThreshold, this.degradedThreshold);
82
- }
83
- getLast() {
84
- return this.samples[this.samples.length - 1];
85
- }
86
- getMean() {
87
- return this.total / this.samples.length;
88
- }
89
- getMedian() {
90
- if (this.samples.length === 1) {
91
- return this.samples[0];
92
- }
93
- this.samples.sort((a, b) => a - b);
94
- const middle = (this.samples.length + 1) / 2;
95
- const floorMiddle = Math.floor(middle);
96
- const remainder = middle % floorMiddle;
97
- if (remainder === 0) {
98
- return this.samples[middle - 1];
99
- }
100
- const left = this.samples[floorMiddle - 1];
101
- const right = this.samples[floorMiddle];
102
- return (left + right) / 2;
103
- }
104
- }
@@ -1,13 +0,0 @@
1
- import { scrollGutterPluginKey } from './pm-plugins/scroll-gutter/plugin-key';
2
- export var setKeyboardHeight = function setKeyboardHeight(keyboardHeight) {
3
- return function (state, dispatch) {
4
- var tr = state.tr;
5
- tr.setMeta(scrollGutterPluginKey, {
6
- keyboardHeight: keyboardHeight
7
- });
8
- if (dispatch) {
9
- dispatch(tr);
10
- }
11
- return true;
12
- };
13
- };
@@ -1,2 +0,0 @@
1
- import basePlugin from './plugin';
2
- export { basePlugin };
@@ -1,131 +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 { baseKeymap } from '@atlaskit/editor-prosemirror/commands';
5
- import { history } from '@atlaskit/editor-prosemirror/history';
6
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
- import { browser } from '@atlaskit/editor-common/utils';
8
- import { doc, paragraph, text } from '@atlaskit/adf-schema';
9
- import filterStepsPlugin from './pm-plugins/filter-steps';
10
- import fixChrome88SelectionPlugin from './pm-plugins/fix-chrome-88-selection';
11
- import disableSpellcheckingPlugin from './pm-plugins/disable-spell-checking';
12
- import contextIdentifierPlugin, { getContextIdentifier } from './pm-plugins/context-identifier';
13
- import newlinePreserveMarksPlugin from './pm-plugins/newline-preserve-marks';
14
- import inlineCursorTargetPlugin from './pm-plugins/inline-cursor-target';
15
- import scrollGutter, { getKeyboardHeight } from './pm-plugins/scroll-gutter';
16
- import { keymap } from '@atlaskit/editor-common/keymaps';
17
- import frozenEditor from './pm-plugins/frozen-editor';
18
- // Chrome >= 88
19
- export var isChromeWithSelectionBug = browser.chrome && browser.chrome_version >= 88;
20
- var basePlugin = function basePlugin(_ref) {
21
- var _api$featureFlags;
22
- var options = _ref.config,
23
- api = _ref.api;
24
- var featureFlags = (api === null || api === void 0 ? void 0 : (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
25
- return {
26
- name: 'base',
27
- getSharedState: function getSharedState(editorState) {
28
- return {
29
- contextIdentifier: getContextIdentifier(editorState),
30
- keyboardHeight: getKeyboardHeight(editorState)
31
- };
32
- },
33
- pmPlugins: function pmPlugins() {
34
- var plugins = [{
35
- name: 'filterStepsPlugin',
36
- plugin: function plugin(_ref2) {
37
- var dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent;
38
- return filterStepsPlugin(dispatchAnalyticsEvent);
39
- }
40
- }];
41
-
42
- // In Chrome, when the selection is placed between adjacent nodes which are not contenteditatble
43
- // the cursor appears at the right most point of the parent container.
44
- // In Firefox, when the selection is placed between adjacent nodes which are not contenteditatble
45
- // no cursor is presented to users.
46
- // In Safari, when the selection is placed between adjacent nodes which are not contenteditatble
47
- // it is not possible to navigate with arrow keys.
48
- // This plugin works around the issues by inserting decorations between
49
- // inline nodes which are set as contenteditable, and have a zero width space.
50
- plugins.push({
51
- name: 'inlineCursorTargetPlugin',
52
- plugin: function plugin() {
53
- return options && options.allowInlineCursorTarget ? inlineCursorTargetPlugin() : undefined;
54
- }
55
- });
56
- plugins.push({
57
- name: 'newlinePreserveMarksPlugin',
58
- plugin: newlinePreserveMarksPlugin
59
- }, {
60
- name: 'frozenEditor',
61
- plugin: function plugin(_ref3) {
62
- var _options$inputTrackin;
63
- var dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent;
64
- return options !== null && options !== void 0 && (_options$inputTrackin = options.inputTracking) !== null && _options$inputTrackin !== void 0 && _options$inputTrackin.enabled || options !== null && options !== void 0 && options.ufo ? frozenEditor(dispatchAnalyticsEvent, options.inputTracking, options.browserFreezeTracking, options.ufo) : undefined;
65
- }
66
- }, {
67
- name: 'history',
68
- plugin: function plugin() {
69
- return history();
70
- }
71
- },
72
- // should be last :(
73
- {
74
- name: 'codeBlockIndent',
75
- plugin: function plugin() {
76
- return keymap(_objectSpread(_objectSpread({}, baseKeymap), {}, {
77
- 'Mod-[': function Mod() {
78
- return true;
79
- },
80
- 'Mod-]': function Mod() {
81
- return true;
82
- }
83
- }));
84
- }
85
- }, {
86
- name: 'contextIdentifier',
87
- plugin: function plugin(_ref4) {
88
- var dispatch = _ref4.dispatch,
89
- providerFactory = _ref4.providerFactory;
90
- return contextIdentifierPlugin(dispatch, providerFactory);
91
- }
92
- });
93
- if (options && options.allowScrollGutter) {
94
- plugins.push({
95
- name: 'scrollGutterPlugin',
96
- plugin: function plugin() {
97
- return scrollGutter(options.allowScrollGutter);
98
- }
99
- });
100
- }
101
- if (isChromeWithSelectionBug && !getBooleanFF('platform.editor.disable-chrome-88-selection-fix_uk53m')) {
102
- plugins.push({
103
- name: 'fixChrome88SelectionPlugin',
104
- plugin: function plugin() {
105
- return fixChrome88SelectionPlugin();
106
- }
107
- });
108
- }
109
- plugins.push({
110
- name: 'disableSpellcheckingPlugin',
111
- plugin: function plugin() {
112
- return disableSpellcheckingPlugin(featureFlags);
113
- }
114
- });
115
- return plugins;
116
- },
117
- nodes: function nodes() {
118
- return [{
119
- name: 'doc',
120
- node: doc
121
- }, {
122
- name: 'paragraph',
123
- node: paragraph
124
- }, {
125
- name: 'text',
126
- node: text
127
- }];
128
- }
129
- };
130
- };
131
- export default basePlugin;
@@ -1,48 +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 { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
- export var stateKey = new PluginKey('contextIdentiferPlugin');
7
- export var getContextIdentifier = function getContextIdentifier(state) {
8
- if (state) {
9
- var _stateKey$getState;
10
- return (_stateKey$getState = stateKey.getState(state)) === null || _stateKey$getState === void 0 ? void 0 : _stateKey$getState.contextIdentifierProvider;
11
- }
12
- };
13
- export default (function (dispatch, providerFactory) {
14
- return new SafePlugin({
15
- key: stateKey,
16
- state: {
17
- init: function init() {
18
- return {};
19
- },
20
- apply: function apply(tr, pluginState) {
21
- if (tr.getMeta(stateKey)) {
22
- return tr.getMeta(stateKey);
23
- }
24
- return pluginState;
25
- }
26
- },
27
- view: function view(_view) {
28
- var providerPromiseHandler = function providerPromiseHandler(name, providerPromise) {
29
- if (providerPromise && name === 'contextIdentifierProvider') {
30
- providerPromise.then(function (provider) {
31
- var tr = _view.state.tr.setMeta(stateKey, {
32
- contextIdentifierProvider: _objectSpread({}, provider)
33
- });
34
- _view.dispatch(tr);
35
- });
36
- }
37
- };
38
- if (providerFactory) {
39
- providerFactory.subscribe('contextIdentifierProvider', providerPromiseHandler);
40
- }
41
- return {
42
- destroy: function destroy() {
43
- providerFactory && providerFactory.unsubscribe('contextIdentifierProvider', providerPromiseHandler);
44
- }
45
- };
46
- }
47
- });
48
- });
@@ -1,56 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import { browser as browserEnv } from '@atlaskit/editor-common/utils';
4
- function getCurrentBrowserAndVersion() {
5
- switch (true) {
6
- case browserEnv.chrome === true:
7
- return {
8
- browser: 'chrome',
9
- version: browserEnv.chrome_version
10
- };
11
- case browserEnv.ie === true:
12
- return {
13
- browser: 'ie',
14
- version: browserEnv.ie_version
15
- };
16
- case browserEnv.gecko === true:
17
- return {
18
- browser: 'gecko',
19
- version: browserEnv.gecko_version
20
- };
21
- case browserEnv.safari === true:
22
- return {
23
- browser: 'safari',
24
- version: browserEnv.safari_version
25
- };
26
- }
27
- return undefined;
28
- }
29
- export default (function (featureFlags) {
30
- return new SafePlugin({
31
- key: new PluginKey('disableSpellchecking'),
32
- props: {
33
- attributes: function attributes(editorState) {
34
- if (!featureFlags) {
35
- return {};
36
- }
37
- var browserConfigFeatureFlag = featureFlags.disableSpellcheckByBrowser;
38
- var userCurrentBrowserAndVersion = getCurrentBrowserAndVersion();
39
- if (!userCurrentBrowserAndVersion || !browserConfigFeatureFlag) {
40
- return {};
41
- }
42
- var browserVersionDisableRange = browserConfigFeatureFlag[userCurrentBrowserAndVersion.browser];
43
- if (!browserVersionDisableRange || !browserEnv[userCurrentBrowserAndVersion.browser]) {
44
- return {};
45
- }
46
- var shouldDisableSpellcheck = !!browserVersionDisableRange.maximum ? userCurrentBrowserAndVersion.version >= browserVersionDisableRange.minimum && userCurrentBrowserAndVersion.version <= browserVersionDisableRange.maximum : browserEnv[userCurrentBrowserAndVersion.browser] && userCurrentBrowserAndVersion.version >= browserVersionDisableRange.minimum;
47
- if (shouldDisableSpellcheck) {
48
- return {
49
- spellcheck: 'false'
50
- };
51
- }
52
- return {};
53
- }
54
- }
55
- });
56
- });
@@ -1,27 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { ACTION_SUBJECT, ACTION, EVENT_TYPE, getAnalyticsEventsFromTransaction } from '@atlaskit/editor-common/analytics';
3
- var hasInvalidSteps = function hasInvalidSteps(tr) {
4
- return (tr.steps || []).some(function (step) {
5
- return step.from > step.to;
6
- });
7
- };
8
- export default (function (dispatchAnalyticsEvent) {
9
- return new SafePlugin({
10
- filterTransaction: function filterTransaction(transaction) {
11
- if (hasInvalidSteps(transaction)) {
12
- // eslint-disable-next-line no-console
13
- console.warn('The transaction was blocked because it contains invalid steps', transaction.steps);
14
- dispatchAnalyticsEvent({
15
- action: ACTION.DISCARDED_INVALID_STEPS_FROM_TRANSACTION,
16
- actionSubject: ACTION_SUBJECT.EDITOR,
17
- attributes: {
18
- analyticsEventPayloads: getAnalyticsEventsFromTransaction(transaction)
19
- },
20
- eventType: EVENT_TYPE.OPERATIONAL
21
- });
22
- return false;
23
- }
24
- return true;
25
- }
26
- });
27
- });
@@ -1,26 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import { isNodeSelection } from '@atlaskit/editor-prosemirror/utils';
4
- function isDivHTMLElement(elm) {
5
- return elm.tagName.toLowerCase() === 'div';
6
- }
7
- export var fixChromeSelectionKey = new PluginKey('fixChromeSelectionPlugin');
8
- export default (function () {
9
- return new SafePlugin({
10
- key: fixChromeSelectionKey,
11
- props: {
12
- handleDOMEvents: {
13
- focus: function focus(view) {
14
- // We don't need to reset when there's a NodeSelection
15
- // It creates other problem. @see HOT-94478
16
- if (isDivHTMLElement(view.dom) && !isNodeSelection(view.state.selection)) {
17
- view.dom.style.display = 'inline-block';
18
- view.dom.offsetHeight;
19
- view.dom.style.display = 'block';
20
- }
21
- return false;
22
- }
23
- }
24
- }
25
- });
26
- });