@atlaskit/editor-plugin-base 2.0.12 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/cjs/basePlugin.js +70 -23
- package/dist/cjs/pm-plugins/frozen-editor.js +1 -4
- package/dist/cjs/pm-plugins/scroll-gutter/plugin.js +22 -239
- package/dist/es2019/basePlugin.js +68 -15
- package/dist/es2019/pm-plugins/frozen-editor.js +1 -4
- package/dist/es2019/pm-plugins/scroll-gutter/plugin.js +19 -224
- package/dist/esm/basePlugin.js +69 -23
- package/dist/esm/pm-plugins/frozen-editor.js +1 -4
- package/dist/esm/pm-plugins/scroll-gutter/plugin.js +21 -238
- package/dist/types/basePlugin.d.ts +3 -1
- package/dist/types/basePluginType.d.ts +11 -0
- package/dist/types/pm-plugins/scroll-gutter/plugin.d.ts +4 -0
- package/dist/types-ts4.5/basePlugin.d.ts +3 -1
- package/dist/types-ts4.5/basePluginType.d.ts +11 -0
- package/dist/types-ts4.5/pm-plugins/scroll-gutter/plugin.d.ts +4 -0
- package/package.json +4 -9
- package/tsconfig.app.json +0 -3
- package/dist/cjs/pm-plugins/scroll-gutter/plugin-next.js +0 -75
- package/dist/es2019/pm-plugins/scroll-gutter/plugin-next.js +0 -65
- package/dist/esm/pm-plugins/scroll-gutter/plugin-next.js +0 -69
- package/dist/types/pm-plugins/scroll-gutter/plugin-next.d.ts +0 -24
- package/dist/types-ts4.5/pm-plugins/scroll-gutter/plugin-next.d.ts +0 -24
|
@@ -1,160 +1,31 @@
|
|
|
1
|
-
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
2
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
-
import { GUTTER_SELECTOR, GUTTER_SIZE_IN_PX, isEmptyDocument } from '@atlaskit/editor-common/utils';
|
|
6
2
|
import { scrollGutterPluginKey } from './plugin-key';
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
function supportsIntersectionObserver() {
|
|
10
|
-
if (typeof window !== 'undefined' && 'IntersectionObserver' in window && 'IntersectionObserverEntry' in window && 'intersectionRatio' in
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
-
window.IntersectionObserverEntry.prototype) {
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
function listenForGutterVisibilityChanges(scrollElement, gutterIsVisible) {
|
|
18
|
-
if (supportsIntersectionObserver()) {
|
|
19
|
-
var observer = new IntersectionObserver(function (entries, _) {
|
|
20
|
-
entries.forEach(function (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
|
-
}
|
|
3
|
+
var GUTTER_SIZE_IN_PX = 120;
|
|
4
|
+
var GUTTER_SELECTOR_NAME = 'editor-scroll-gutter';
|
|
32
5
|
|
|
33
6
|
/**
|
|
34
7
|
* Create a gutter element that can be added or removed from the DOM.
|
|
35
8
|
*/
|
|
36
|
-
function createGutter(gutterSize) {
|
|
9
|
+
function createGutter(gutterSize, parent) {
|
|
37
10
|
var gutter = document.createElement('div');
|
|
38
11
|
gutter.style.paddingBottom = "".concat(gutterSize, "px");
|
|
39
|
-
gutter.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var observer;
|
|
44
|
-
var isVisible = false;
|
|
45
|
-
return {
|
|
46
|
-
addGutter: function addGutter(parent) {
|
|
47
|
-
if (parent) {
|
|
48
|
-
var _parent$deref;
|
|
49
|
-
currentParent = parent;
|
|
50
|
-
(_parent$deref = parent.deref()) === null || _parent$deref === void 0 || _parent$deref.appendChild(gutter);
|
|
51
|
-
mounted = true;
|
|
52
|
-
if (observer) {
|
|
53
|
-
observer.observe(gutter);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
removeGutter: function removeGutter() {
|
|
58
|
-
var _currentParent;
|
|
59
|
-
var parentRef = (_currentParent = currentParent) === null || _currentParent === void 0 ? void 0 : _currentParent.deref();
|
|
60
|
-
if (parentRef && mounted) {
|
|
61
|
-
mounted = false;
|
|
62
|
-
parentRef.removeChild(gutter);
|
|
63
|
-
if (observer) {
|
|
64
|
-
observer.unobserve(gutter);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
element: function element() {
|
|
69
|
-
return gutter;
|
|
70
|
-
},
|
|
71
|
-
isMounted: function isMounted() {
|
|
72
|
-
return mounted;
|
|
73
|
-
},
|
|
74
|
-
visible: function visible() {
|
|
75
|
-
// If we know whether it's visible we can avoid expensive calculations
|
|
76
|
-
if (observer) {
|
|
77
|
-
return isVisible;
|
|
78
|
-
}
|
|
79
|
-
// Fallback for legacy browsers assumes it's visible (if mounted)
|
|
80
|
-
return mounted;
|
|
81
|
-
},
|
|
82
|
-
observe: function observe(scrollElement) {
|
|
83
|
-
if (!initialized) {
|
|
84
|
-
initialized = true;
|
|
85
|
-
observer = listenForGutterVisibilityChanges(scrollElement, function (visible) {
|
|
86
|
-
return isVisible = visible;
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
destroy: function destroy() {
|
|
91
|
-
if (observer) {
|
|
92
|
-
observer.disconnect();
|
|
93
|
-
}
|
|
94
|
-
observer = undefined;
|
|
95
|
-
this.removeGutter();
|
|
96
|
-
initialized = mounted = false;
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Get caret top position given the current selection,
|
|
103
|
-
* use start container position as fallback
|
|
104
|
-
*/
|
|
105
|
-
function getCaretTopPosition() {
|
|
106
|
-
var windowSelection = window.getSelection();
|
|
107
|
-
if (windowSelection && windowSelection.rangeCount > 0) {
|
|
108
|
-
var range = windowSelection.getRangeAt(0);
|
|
109
|
-
if (range) {
|
|
110
|
-
var clientRects = range.getClientRects();
|
|
111
|
-
// Return client rects
|
|
112
|
-
if (clientRects && clientRects.length > 0) {
|
|
113
|
-
return clientRects[0].top;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Return container top
|
|
117
|
-
// Ignored via go/ees005
|
|
118
|
-
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
119
|
-
var container = range.startContainer;
|
|
120
|
-
if (container && container.getBoundingClientRect) {
|
|
121
|
-
return container.getBoundingClientRect().top;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
function scrollToGutterElement(scrollContainer, gutterElement, gutterSize) {
|
|
128
|
-
var viewportHeight = scrollContainer.offsetHeight;
|
|
129
|
-
var viewportOffsetY = scrollContainer.getBoundingClientRect().top;
|
|
130
|
-
var caretTopPosition = getCaretTopPosition();
|
|
131
|
-
if (!caretTopPosition) {
|
|
132
|
-
return false;
|
|
12
|
+
gutter.setAttribute('data-vc', 'scroll-gutter');
|
|
13
|
+
gutter.id = GUTTER_SELECTOR_NAME;
|
|
14
|
+
if (parent) {
|
|
15
|
+
parent.appendChild(gutter);
|
|
133
16
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Clamp the scroll position to above the scroll gutter element.
|
|
141
|
-
gutterElement.scrollIntoView(false);
|
|
142
|
-
|
|
143
|
-
// Mark scrolling as handled so that other plugin's don't override our position.
|
|
144
|
-
return true;
|
|
17
|
+
return function () {
|
|
18
|
+
return parent === null || parent === void 0 ? void 0 : parent.removeChild(gutter);
|
|
19
|
+
};
|
|
145
20
|
}
|
|
146
21
|
export default (function () {
|
|
147
22
|
var pluginOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
148
23
|
var getScrollElement = pluginOptions.getScrollElement,
|
|
149
|
-
allowCustomScrollHandler = pluginOptions.allowCustomScrollHandler,
|
|
150
24
|
_pluginOptions$gutter = pluginOptions.gutterSize,
|
|
151
25
|
gutterSize = _pluginOptions$gutter === void 0 ? GUTTER_SIZE_IN_PX : _pluginOptions$gutter;
|
|
152
26
|
if (!getScrollElement) {
|
|
153
27
|
return undefined;
|
|
154
28
|
}
|
|
155
|
-
var gutter = createGutter(gutterSize);
|
|
156
|
-
var scrollElement = null; // | undefined;
|
|
157
|
-
|
|
158
29
|
return new SafePlugin({
|
|
159
30
|
key: scrollGutterPluginKey,
|
|
160
31
|
state: {
|
|
@@ -172,113 +43,25 @@ export default (function () {
|
|
|
172
43
|
// Determines the distance (in pixels) between the cursor and the end of the visible viewport at which point,
|
|
173
44
|
// when scrolling the cursor into view, scrolling takes place.
|
|
174
45
|
// Defaults to 0: https://prosemirror.net/docs/ref/#view.EditorProps.scrollThreshold
|
|
175
|
-
scrollThreshold: gutterSize
|
|
46
|
+
scrollThreshold: gutterSize,
|
|
176
47
|
// Determines the extra space (in pixels) that is left above or below the cursor when it is scrolled into view.
|
|
177
48
|
// Defaults to 5: https://prosemirror.net/docs/ref/#view.EditorProps.scrollMargin
|
|
178
|
-
scrollMargin: gutterSize
|
|
179
|
-
// Called when the view, after updating its state, tries to scroll the selection into view
|
|
180
|
-
// https://prosemirror.net/docs/ref/#view.EditorProps.handleScrollToSelection
|
|
181
|
-
handleScrollToSelection: function handleScrollToSelection() {
|
|
182
|
-
if (allowCustomScrollHandler === false) {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
if (!gutter.isMounted() || !gutter.visible() || !scrollElement) {
|
|
186
|
-
// Avoid scrolling until applicable
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
return scrollToGutterElement(scrollElement, gutter.element(), gutterSize);
|
|
190
|
-
}
|
|
49
|
+
scrollMargin: gutterSize
|
|
191
50
|
},
|
|
192
51
|
view: function view(_view) {
|
|
52
|
+
var _editorElement;
|
|
193
53
|
// Store references to avoid lookups on successive checks.
|
|
194
|
-
scrollElement = getScrollElement(_view);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
var
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
var contentElementHeight = 0;
|
|
201
|
-
var addAndObserveGutter = function addAndObserveGutter() {
|
|
202
|
-
if (!gutter.isMounted()) {
|
|
203
|
-
// Ignored via go/ees005
|
|
204
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
205
|
-
gutter.observe(scrollElement);
|
|
206
|
-
gutter.addGutter(editorParentElement ? new WeakRef(editorParentElement) : null);
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
var toggleGutter = function toggleGutter(contentSize, threshold) {
|
|
210
|
-
if (pluginOptions.persistScrollGutter) {
|
|
211
|
-
if (!isEmptyDocument(_view.state.doc)) {
|
|
212
|
-
addAndObserveGutter();
|
|
213
|
-
} else {
|
|
214
|
-
gutter.removeGutter();
|
|
215
|
-
}
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Add or remove the gutter based on whether the content is about to exceed the viewport height.
|
|
220
|
-
// We do this to ensure there is sufficient white space below the last content node in order to
|
|
221
|
-
// see any UI control elements which may sit beneath it.
|
|
222
|
-
if (contentSize >= threshold) {
|
|
223
|
-
addAndObserveGutter();
|
|
224
|
-
} else {
|
|
225
|
-
if (gutter.isMounted()) {
|
|
226
|
-
gutter.removeGutter();
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
var observerCallback = function observerCallback(entries) {
|
|
231
|
-
var _iterator = _createForOfIteratorHelper(entries),
|
|
232
|
-
_step;
|
|
233
|
-
try {
|
|
234
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
235
|
-
var entry = _step.value;
|
|
236
|
-
var elementHeight = Math.round(entry.contentRect.height);
|
|
237
|
-
if (entry.target === scrollElement) {
|
|
238
|
-
var _getKeyboardHeight;
|
|
239
|
-
var keyboardHeight = (_getKeyboardHeight = getKeyboardHeight(_view === null || _view === void 0 ? void 0 : _view.state)) !== null && _getKeyboardHeight !== void 0 ? _getKeyboardHeight : 0;
|
|
240
|
-
viewportElementHeight = elementHeight - keyboardHeight;
|
|
241
|
-
} else if (entry.target === editorParentElement) {
|
|
242
|
-
contentElementHeight = elementHeight - (gutter.isMounted() ? gutterSize : 0);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
} catch (err) {
|
|
246
|
-
_iterator.e(err);
|
|
247
|
-
} finally {
|
|
248
|
-
_iterator.f();
|
|
249
|
-
}
|
|
250
|
-
toggleGutter(contentElementHeight, viewportElementHeight);
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
// Subscribe to updates of the height of the viewport and content elements
|
|
254
|
-
// We toggle the value when it is set here or when PM updates to ensure we're using
|
|
255
|
-
// the latest.
|
|
256
|
-
var resizeObserver = new ResizeObserver(observerCallback);
|
|
257
|
-
if (scrollElement && editorParentElement) {
|
|
258
|
-
resizeObserver.observe(scrollElement);
|
|
259
|
-
resizeObserver.observe(editorParentElement);
|
|
54
|
+
var scrollElement = getScrollElement(_view);
|
|
55
|
+
var editorElement = _view.dom instanceof HTMLElement ? _view.dom : null;
|
|
56
|
+
var editorParentElement = (_editorElement = editorElement) === null || _editorElement === void 0 ? void 0 : _editorElement.parentElement;
|
|
57
|
+
var cleanup = function cleanup() {};
|
|
58
|
+
if (editorParentElement && scrollElement) {
|
|
59
|
+
cleanup = createGutter(gutterSize, editorParentElement);
|
|
260
60
|
}
|
|
261
61
|
return {
|
|
262
62
|
destroy: function destroy() {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
scrollElement = editorParentElement = editorElement = null;
|
|
266
|
-
resizeObserver.disconnect();
|
|
267
|
-
},
|
|
268
|
-
/**
|
|
269
|
-
* Toggle the Scroll Gutter Element
|
|
270
|
-
*/
|
|
271
|
-
update: function update(view, prevState) {
|
|
272
|
-
if (!scrollElement || !editorParentElement) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
var state = view.state;
|
|
276
|
-
if (prevState.selection === state.selection) {
|
|
277
|
-
// No need to recheck if the selected node hasn't changed.
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
var gutterThresholdHeight = viewportElementHeight - gutterSize;
|
|
281
|
-
toggleGutter(contentElementHeight, gutterThresholdHeight);
|
|
63
|
+
cleanup();
|
|
64
|
+
editorParentElement = editorElement = null;
|
|
282
65
|
}
|
|
283
66
|
};
|
|
284
67
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { BasePlugin, Callback } from './basePluginType';
|
|
3
|
+
export declare function resolveCallbacks(from: number, to: number, tr: Transaction, callbacks: Callback[]): void;
|
|
2
4
|
declare const basePlugin: BasePlugin;
|
|
3
5
|
export default basePlugin;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { BrowserFreezetracking, InputTracking, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { ContextIdentifierPlugin } from '@atlaskit/editor-plugin-context-identifier';
|
|
3
3
|
import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
4
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
5
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
6
|
import { type setKeyboardHeight } from './editor-commands/set-keyboard-height';
|
|
5
7
|
import type { ScrollGutterPluginOptions } from './pm-plugins/scroll-gutter/plugin';
|
|
6
8
|
export interface BasePluginOptions {
|
|
@@ -25,5 +27,14 @@ export type BasePlugin = NextEditorPlugin<'base', {
|
|
|
25
27
|
sharedState: BasePluginState;
|
|
26
28
|
actions: {
|
|
27
29
|
setKeyboardHeight: typeof setKeyboardHeight;
|
|
30
|
+
registerMarks: (callback: Callback) => void;
|
|
31
|
+
resolveMarks: (from: number, to: number, tr: Transaction) => void;
|
|
28
32
|
};
|
|
29
33
|
}>;
|
|
34
|
+
export type Callback = ({ node, tr, pos, from, to, }: {
|
|
35
|
+
node: PMNode;
|
|
36
|
+
tr: Transaction;
|
|
37
|
+
pos: number;
|
|
38
|
+
from: number;
|
|
39
|
+
to: number;
|
|
40
|
+
}) => void;
|
|
@@ -4,12 +4,16 @@ export type ScrollGutterPluginOptions = {
|
|
|
4
4
|
/** Element the page uses for scrolling */
|
|
5
5
|
getScrollElement?: (view: EditorView) => HTMLElement | null;
|
|
6
6
|
/**
|
|
7
|
+
* @deprecated
|
|
8
|
+
*
|
|
7
9
|
* Whether to allow custom functionality to scroll to gutter element in
|
|
8
10
|
* plugin's handleScrollToSelection function
|
|
9
11
|
* Default is true
|
|
10
12
|
*/
|
|
11
13
|
allowCustomScrollHandler?: boolean;
|
|
12
14
|
/**
|
|
15
|
+
* @deprecated
|
|
16
|
+
*
|
|
13
17
|
* Persist scroll gutter when the mobile appearance is COMPACT
|
|
14
18
|
* Default is false
|
|
15
19
|
*/
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { BasePlugin, Callback } from './basePluginType';
|
|
3
|
+
export declare function resolveCallbacks(from: number, to: number, tr: Transaction, callbacks: Callback[]): void;
|
|
2
4
|
declare const basePlugin: BasePlugin;
|
|
3
5
|
export default basePlugin;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { BrowserFreezetracking, InputTracking, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { ContextIdentifierPlugin } from '@atlaskit/editor-plugin-context-identifier';
|
|
3
3
|
import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
4
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
5
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
6
|
import { type setKeyboardHeight } from './editor-commands/set-keyboard-height';
|
|
5
7
|
import type { ScrollGutterPluginOptions } from './pm-plugins/scroll-gutter/plugin';
|
|
6
8
|
export interface BasePluginOptions {
|
|
@@ -28,5 +30,14 @@ export type BasePlugin = NextEditorPlugin<'base', {
|
|
|
28
30
|
sharedState: BasePluginState;
|
|
29
31
|
actions: {
|
|
30
32
|
setKeyboardHeight: typeof setKeyboardHeight;
|
|
33
|
+
registerMarks: (callback: Callback) => void;
|
|
34
|
+
resolveMarks: (from: number, to: number, tr: Transaction) => void;
|
|
31
35
|
};
|
|
32
36
|
}>;
|
|
37
|
+
export type Callback = ({ node, tr, pos, from, to, }: {
|
|
38
|
+
node: PMNode;
|
|
39
|
+
tr: Transaction;
|
|
40
|
+
pos: number;
|
|
41
|
+
from: number;
|
|
42
|
+
to: number;
|
|
43
|
+
}) => void;
|
|
@@ -4,12 +4,16 @@ export type ScrollGutterPluginOptions = {
|
|
|
4
4
|
/** Element the page uses for scrolling */
|
|
5
5
|
getScrollElement?: (view: EditorView) => HTMLElement | null;
|
|
6
6
|
/**
|
|
7
|
+
* @deprecated
|
|
8
|
+
*
|
|
7
9
|
* Whether to allow custom functionality to scroll to gutter element in
|
|
8
10
|
* plugin's handleScrollToSelection function
|
|
9
11
|
* Default is true
|
|
10
12
|
*/
|
|
11
13
|
allowCustomScrollHandler?: boolean;
|
|
12
14
|
/**
|
|
15
|
+
* @deprecated
|
|
16
|
+
*
|
|
13
17
|
* Persist scroll gutter when the mobile appearance is COMPACT
|
|
14
18
|
* Default is false
|
|
15
19
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-base",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Base plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@atlaskit/adf-schema": "^46.1.0",
|
|
35
|
-
"@atlaskit/editor-common": "^
|
|
35
|
+
"@atlaskit/editor-common": "^99.7.0",
|
|
36
36
|
"@atlaskit/editor-plugin-context-identifier": "^1.3.0",
|
|
37
37
|
"@atlaskit/editor-plugin-feature-flags": "^1.2.0",
|
|
38
38
|
"@atlaskit/editor-prosemirror": "6.2.1",
|
|
39
|
-
"@atlaskit/platform-feature-flags": "^0.
|
|
40
|
-
"@atlaskit/tmp-editor-statsig": "^2.
|
|
39
|
+
"@atlaskit/platform-feature-flags": "^1.0.0",
|
|
40
|
+
"@atlaskit/tmp-editor-statsig": "^2.41.0",
|
|
41
41
|
"@babel/runtime": "^7.0.0"
|
|
42
42
|
},
|
|
43
43
|
"techstack": {
|
|
@@ -77,10 +77,5 @@
|
|
|
77
77
|
"no-unused-dependencies": {
|
|
78
78
|
"checkDevDependencies": true
|
|
79
79
|
}
|
|
80
|
-
},
|
|
81
|
-
"platform-feature-flags": {
|
|
82
|
-
"platform_editor_improved_scroll_gutter": {
|
|
83
|
-
"type": "boolean"
|
|
84
|
-
}
|
|
85
80
|
}
|
|
86
81
|
}
|
package/tsconfig.app.json
CHANGED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
8
|
-
var _pluginKey = require("./plugin-key");
|
|
9
|
-
var GUTTER_SIZE_IN_PX = 120;
|
|
10
|
-
var GUTTER_SELECTOR_NAME = 'editor-scroll-gutter';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Create a gutter element that can be added or removed from the DOM.
|
|
14
|
-
*/
|
|
15
|
-
function createGutter(gutterSize, parent) {
|
|
16
|
-
var gutter = document.createElement('div');
|
|
17
|
-
gutter.style.paddingBottom = "".concat(gutterSize, "px");
|
|
18
|
-
gutter.setAttribute('data-vc', 'scroll-gutter');
|
|
19
|
-
gutter.id = GUTTER_SELECTOR_NAME;
|
|
20
|
-
if (parent) {
|
|
21
|
-
parent.appendChild(gutter);
|
|
22
|
-
}
|
|
23
|
-
return function () {
|
|
24
|
-
return parent === null || parent === void 0 ? void 0 : parent.removeChild(gutter);
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
var _default = exports.default = function _default() {
|
|
28
|
-
var pluginOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
29
|
-
var getScrollElement = pluginOptions.getScrollElement,
|
|
30
|
-
_pluginOptions$gutter = pluginOptions.gutterSize,
|
|
31
|
-
gutterSize = _pluginOptions$gutter === void 0 ? GUTTER_SIZE_IN_PX : _pluginOptions$gutter;
|
|
32
|
-
if (!getScrollElement) {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
return new _safePlugin.SafePlugin({
|
|
36
|
-
key: _pluginKey.scrollGutterPluginKey,
|
|
37
|
-
state: {
|
|
38
|
-
init: function init() {
|
|
39
|
-
return {};
|
|
40
|
-
},
|
|
41
|
-
apply: function apply(tr, pluginState) {
|
|
42
|
-
if (tr.getMeta(_pluginKey.scrollGutterPluginKey)) {
|
|
43
|
-
return tr.getMeta(_pluginKey.scrollGutterPluginKey);
|
|
44
|
-
}
|
|
45
|
-
return pluginState;
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
props: {
|
|
49
|
-
// Determines the distance (in pixels) between the cursor and the end of the visible viewport at which point,
|
|
50
|
-
// when scrolling the cursor into view, scrolling takes place.
|
|
51
|
-
// Defaults to 0: https://prosemirror.net/docs/ref/#view.EditorProps.scrollThreshold
|
|
52
|
-
scrollThreshold: gutterSize,
|
|
53
|
-
// Determines the extra space (in pixels) that is left above or below the cursor when it is scrolled into view.
|
|
54
|
-
// Defaults to 5: https://prosemirror.net/docs/ref/#view.EditorProps.scrollMargin
|
|
55
|
-
scrollMargin: gutterSize
|
|
56
|
-
},
|
|
57
|
-
view: function view(_view) {
|
|
58
|
-
var _editorElement;
|
|
59
|
-
// Store references to avoid lookups on successive checks.
|
|
60
|
-
var scrollElement = getScrollElement(_view);
|
|
61
|
-
var editorElement = _view.dom instanceof HTMLElement ? _view.dom : null;
|
|
62
|
-
var editorParentElement = (_editorElement = editorElement) === null || _editorElement === void 0 ? void 0 : _editorElement.parentElement;
|
|
63
|
-
var cleanup = function cleanup() {};
|
|
64
|
-
if (editorParentElement && scrollElement) {
|
|
65
|
-
cleanup = createGutter(gutterSize, editorParentElement);
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
destroy: function destroy() {
|
|
69
|
-
cleanup();
|
|
70
|
-
editorParentElement = editorElement = null;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import { scrollGutterPluginKey } from './plugin-key';
|
|
3
|
-
const GUTTER_SIZE_IN_PX = 120;
|
|
4
|
-
const GUTTER_SELECTOR_NAME = 'editor-scroll-gutter';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Create a gutter element that can be added or removed from the DOM.
|
|
8
|
-
*/
|
|
9
|
-
function createGutter(gutterSize, parent) {
|
|
10
|
-
const gutter = document.createElement('div');
|
|
11
|
-
gutter.style.paddingBottom = `${gutterSize}px`;
|
|
12
|
-
gutter.setAttribute('data-vc', 'scroll-gutter');
|
|
13
|
-
gutter.id = GUTTER_SELECTOR_NAME;
|
|
14
|
-
if (parent) {
|
|
15
|
-
parent.appendChild(gutter);
|
|
16
|
-
}
|
|
17
|
-
return () => parent === null || parent === void 0 ? void 0 : parent.removeChild(gutter);
|
|
18
|
-
}
|
|
19
|
-
export default ((pluginOptions = {}) => {
|
|
20
|
-
const {
|
|
21
|
-
getScrollElement,
|
|
22
|
-
gutterSize = GUTTER_SIZE_IN_PX
|
|
23
|
-
} = pluginOptions;
|
|
24
|
-
if (!getScrollElement) {
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
return new SafePlugin({
|
|
28
|
-
key: scrollGutterPluginKey,
|
|
29
|
-
state: {
|
|
30
|
-
init: () => ({}),
|
|
31
|
-
apply: (tr, pluginState) => {
|
|
32
|
-
if (tr.getMeta(scrollGutterPluginKey)) {
|
|
33
|
-
return tr.getMeta(scrollGutterPluginKey);
|
|
34
|
-
}
|
|
35
|
-
return pluginState;
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
props: {
|
|
39
|
-
// Determines the distance (in pixels) between the cursor and the end of the visible viewport at which point,
|
|
40
|
-
// when scrolling the cursor into view, scrolling takes place.
|
|
41
|
-
// Defaults to 0: https://prosemirror.net/docs/ref/#view.EditorProps.scrollThreshold
|
|
42
|
-
scrollThreshold: gutterSize,
|
|
43
|
-
// Determines the extra space (in pixels) that is left above or below the cursor when it is scrolled into view.
|
|
44
|
-
// Defaults to 5: https://prosemirror.net/docs/ref/#view.EditorProps.scrollMargin
|
|
45
|
-
scrollMargin: gutterSize
|
|
46
|
-
},
|
|
47
|
-
view(view) {
|
|
48
|
-
var _editorElement;
|
|
49
|
-
// Store references to avoid lookups on successive checks.
|
|
50
|
-
const scrollElement = getScrollElement(view);
|
|
51
|
-
let editorElement = view.dom instanceof HTMLElement ? view.dom : null;
|
|
52
|
-
let editorParentElement = (_editorElement = editorElement) === null || _editorElement === void 0 ? void 0 : _editorElement.parentElement;
|
|
53
|
-
let cleanup = () => {};
|
|
54
|
-
if (editorParentElement && scrollElement) {
|
|
55
|
-
cleanup = createGutter(gutterSize, editorParentElement);
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
destroy() {
|
|
59
|
-
cleanup();
|
|
60
|
-
editorParentElement = editorElement = null;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import { scrollGutterPluginKey } from './plugin-key';
|
|
3
|
-
var GUTTER_SIZE_IN_PX = 120;
|
|
4
|
-
var GUTTER_SELECTOR_NAME = 'editor-scroll-gutter';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Create a gutter element that can be added or removed from the DOM.
|
|
8
|
-
*/
|
|
9
|
-
function createGutter(gutterSize, parent) {
|
|
10
|
-
var gutter = document.createElement('div');
|
|
11
|
-
gutter.style.paddingBottom = "".concat(gutterSize, "px");
|
|
12
|
-
gutter.setAttribute('data-vc', 'scroll-gutter');
|
|
13
|
-
gutter.id = GUTTER_SELECTOR_NAME;
|
|
14
|
-
if (parent) {
|
|
15
|
-
parent.appendChild(gutter);
|
|
16
|
-
}
|
|
17
|
-
return function () {
|
|
18
|
-
return parent === null || parent === void 0 ? void 0 : parent.removeChild(gutter);
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
export default (function () {
|
|
22
|
-
var pluginOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
23
|
-
var getScrollElement = pluginOptions.getScrollElement,
|
|
24
|
-
_pluginOptions$gutter = pluginOptions.gutterSize,
|
|
25
|
-
gutterSize = _pluginOptions$gutter === void 0 ? GUTTER_SIZE_IN_PX : _pluginOptions$gutter;
|
|
26
|
-
if (!getScrollElement) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
return new SafePlugin({
|
|
30
|
-
key: scrollGutterPluginKey,
|
|
31
|
-
state: {
|
|
32
|
-
init: function init() {
|
|
33
|
-
return {};
|
|
34
|
-
},
|
|
35
|
-
apply: function apply(tr, pluginState) {
|
|
36
|
-
if (tr.getMeta(scrollGutterPluginKey)) {
|
|
37
|
-
return tr.getMeta(scrollGutterPluginKey);
|
|
38
|
-
}
|
|
39
|
-
return pluginState;
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
props: {
|
|
43
|
-
// Determines the distance (in pixels) between the cursor and the end of the visible viewport at which point,
|
|
44
|
-
// when scrolling the cursor into view, scrolling takes place.
|
|
45
|
-
// Defaults to 0: https://prosemirror.net/docs/ref/#view.EditorProps.scrollThreshold
|
|
46
|
-
scrollThreshold: gutterSize,
|
|
47
|
-
// Determines the extra space (in pixels) that is left above or below the cursor when it is scrolled into view.
|
|
48
|
-
// Defaults to 5: https://prosemirror.net/docs/ref/#view.EditorProps.scrollMargin
|
|
49
|
-
scrollMargin: gutterSize
|
|
50
|
-
},
|
|
51
|
-
view: function view(_view) {
|
|
52
|
-
var _editorElement;
|
|
53
|
-
// Store references to avoid lookups on successive checks.
|
|
54
|
-
var scrollElement = getScrollElement(_view);
|
|
55
|
-
var editorElement = _view.dom instanceof HTMLElement ? _view.dom : null;
|
|
56
|
-
var editorParentElement = (_editorElement = editorElement) === null || _editorElement === void 0 ? void 0 : _editorElement.parentElement;
|
|
57
|
-
var cleanup = function cleanup() {};
|
|
58
|
-
if (editorParentElement && scrollElement) {
|
|
59
|
-
cleanup = createGutter(gutterSize, editorParentElement);
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
destroy: function destroy() {
|
|
63
|
-
cleanup();
|
|
64
|
-
editorParentElement = editorElement = null;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|