@atlaskit/editor-common 87.0.2 → 87.0.4
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 +22 -0
- package/code-block/package.json +15 -0
- package/dist/cjs/code-block/index.js +31 -0
- package/dist/cjs/lazy-node-view/index.js +19 -128
- package/dist/cjs/lazy-node-view/node-view.js +35 -0
- package/dist/cjs/lazy-node-view/replace-node-views.js +95 -0
- package/dist/cjs/lazy-node-view/types.js +5 -0
- package/dist/cjs/monitoring/error.js +1 -1
- package/dist/cjs/styles/shared/code-block.js +4 -3
- package/dist/cjs/ui/DropList/index.js +1 -1
- package/dist/es2019/code-block/index.js +25 -0
- package/dist/es2019/lazy-node-view/index.js +16 -124
- package/dist/es2019/lazy-node-view/node-view.js +27 -0
- package/dist/es2019/lazy-node-view/replace-node-views.js +91 -0
- package/dist/es2019/lazy-node-view/types.js +1 -0
- package/dist/es2019/monitoring/error.js +1 -1
- package/dist/es2019/styles/shared/code-block.js +9 -1
- package/dist/es2019/ui/DropList/index.js +1 -1
- package/dist/esm/code-block/index.js +25 -0
- package/dist/esm/lazy-node-view/index.js +16 -124
- package/dist/esm/lazy-node-view/node-view.js +28 -0
- package/dist/esm/lazy-node-view/replace-node-views.js +88 -0
- package/dist/esm/lazy-node-view/types.js +1 -0
- package/dist/esm/monitoring/error.js +1 -1
- package/dist/esm/styles/shared/code-block.js +4 -3
- package/dist/esm/ui/DropList/index.js +1 -1
- package/dist/types/code-block/index.d.ts +9 -0
- package/dist/types/lazy-node-view/index.d.ts +3 -49
- package/dist/types/lazy-node-view/node-view.d.ts +12 -0
- package/dist/types/lazy-node-view/replace-node-views.d.ts +44 -0
- package/dist/types/lazy-node-view/types.d.ts +14 -0
- package/dist/types/styles/shared/code-block.d.ts +1 -0
- package/dist/types-ts4.5/code-block/index.d.ts +9 -0
- package/dist/types-ts4.5/lazy-node-view/index.d.ts +3 -49
- package/dist/types-ts4.5/lazy-node-view/node-view.d.ts +12 -0
- package/dist/types-ts4.5/lazy-node-view/replace-node-views.d.ts +44 -0
- package/dist/types-ts4.5/lazy-node-view/types.d.ts +14 -0
- package/dist/types-ts4.5/styles/shared/code-block.d.ts +1 -0
- package/package.json +6 -2
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
/**
|
|
3
|
+
* 🧱 Internal: Editor FE Platform
|
|
4
|
+
*
|
|
5
|
+
* A NodeView that serves as a placeholder until the actual NodeView is loaded.
|
|
6
|
+
*/
|
|
7
|
+
export class LazyNodeView {
|
|
8
|
+
constructor(node, view, getPos) {
|
|
9
|
+
var _node$type, _node$type$spec;
|
|
10
|
+
if (typeof ((_node$type = node.type) === null || _node$type === void 0 ? void 0 : (_node$type$spec = _node$type.spec) === null || _node$type$spec === void 0 ? void 0 : _node$type$spec.toDOM) !== 'function') {
|
|
11
|
+
this.dom = document.createElement('div');
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const fallback = DOMSerializer.renderSpec(document, node.type.spec.toDOM(node));
|
|
15
|
+
this.dom = fallback.dom;
|
|
16
|
+
this.contentDOM = fallback.contentDOM;
|
|
17
|
+
if (this.dom instanceof HTMLElement) {
|
|
18
|
+
// This attribute is mostly used for debugging purposed
|
|
19
|
+
// It will help us to found out when the node was replaced
|
|
20
|
+
this.dom.setAttribute('data-lazy-node-view', node.type.name);
|
|
21
|
+
// This is used on Libra tests
|
|
22
|
+
// We are using this to make sure all lazy noded were replaced
|
|
23
|
+
// before the test started
|
|
24
|
+
this.dom.setAttribute('data-lazy-node-view-fallback', 'true');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import debounce from 'lodash/debounce';
|
|
2
|
+
/**
|
|
3
|
+
* 🧱 Internal: Editor FE Platform
|
|
4
|
+
*/
|
|
5
|
+
const isFirefox = /gecko\/\d/i.test(navigator.userAgent);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 🧱 Internal: Editor FE Platform
|
|
9
|
+
*
|
|
10
|
+
* Debounces and replaces the node views in a ProseMirror editor with lazy-loaded node views.
|
|
11
|
+
*
|
|
12
|
+
* This function is used to update the `nodeViews` property of the `EditorView` after lazy-loaded
|
|
13
|
+
* node views have been loaded. It uses a debounced approach to ensure that the replacement does
|
|
14
|
+
* not happen too frequently, which can be performance-intensive.
|
|
15
|
+
*
|
|
16
|
+
* The function checks if there are any loaded node views in the cache associated with the given
|
|
17
|
+
* `EditorView`. If there are, it replaces the current `nodeViews` in the `EditorView` with the
|
|
18
|
+
* loaded node views. The replacement is scheduled using `requestIdleCallback` or
|
|
19
|
+
* `requestAnimationFrame` to avoid blocking the main thread, especially in Firefox where
|
|
20
|
+
* `requestIdleCallback` may not be supported.
|
|
21
|
+
*
|
|
22
|
+
* @param {WeakMap<EditorView, Record<string, NodeViewConstructor>>} cache - A WeakMap that stores
|
|
23
|
+
* the loaded node views for each `EditorView`. The key is the `EditorView`, and the value
|
|
24
|
+
* is a record of node type names to their corresponding `NodeViewConstructor`.
|
|
25
|
+
* @param {EditorView} view - The ProseMirror `EditorView` instance whose `nodeViews` property
|
|
26
|
+
* needs to be updated.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const cache = new WeakMap();
|
|
30
|
+
* const view = new EditorView(...);
|
|
31
|
+
*
|
|
32
|
+
* // Assume some node views have been loaded and stored in the cache
|
|
33
|
+
* cache.set(view, {
|
|
34
|
+
* 'table': TableViewConstructor,
|
|
35
|
+
* 'tableCell': TableCellViewConstructor,
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* debouncedReplaceNodeviews(cache, view);
|
|
39
|
+
*/
|
|
40
|
+
export const debouncedReplaceNodeviews = debounce((cache, view) => {
|
|
41
|
+
const loadedNodeviews = cache.get(view);
|
|
42
|
+
if (!loadedNodeviews || Object.keys(loadedNodeviews).length === 0) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const nodeViewsToReplace = {
|
|
46
|
+
...loadedNodeviews
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Make sure the cache is cleaned
|
|
50
|
+
// From here, we will access the loaded node views by lexical scope
|
|
51
|
+
cache.set(view, {});
|
|
52
|
+
|
|
53
|
+
// eslint-disable-next-line compat/compat
|
|
54
|
+
const idle = window.requestIdleCallback;
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
* For reasons that goes beyond my knowledge
|
|
58
|
+
* some Firefox versions aren't calling the requestIdleCallback.
|
|
59
|
+
*
|
|
60
|
+
* So, we need this check to make sure we use the requestAnimationFrame instead
|
|
61
|
+
*/
|
|
62
|
+
const later = isFirefox || typeof idle !== 'function' ? window.requestAnimationFrame : idle;
|
|
63
|
+
later(() => {
|
|
64
|
+
const currentNodeViews = view.props.nodeViews;
|
|
65
|
+
const nextNodeViews = {
|
|
66
|
+
...currentNodeViews,
|
|
67
|
+
...nodeViewsToReplace
|
|
68
|
+
};
|
|
69
|
+
view.setProps({
|
|
70
|
+
nodeViews: nextNodeViews
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 🧱 Internal: Editor FE Platform
|
|
77
|
+
*/
|
|
78
|
+
const loadedPerEditorView = new WeakMap();
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 🧱 Internal: Editor FE Platform
|
|
82
|
+
*/
|
|
83
|
+
export const queueReplaceNodeViews = (view, {
|
|
84
|
+
nodeName,
|
|
85
|
+
nodeViewFunc
|
|
86
|
+
}) => {
|
|
87
|
+
const nodeViews = loadedPerEditorView.get(view) || {};
|
|
88
|
+
nodeViews[nodeName] = nodeViewFunc;
|
|
89
|
+
loadedPerEditorView.set(view, nodeViews);
|
|
90
|
+
debouncedReplaceNodeviews(loadedPerEditorView, view);
|
|
91
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isFedRamp } from './environment';
|
|
2
2
|
const SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
|
|
3
3
|
const packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
|
|
4
|
-
const packageVersion = "87.0.
|
|
4
|
+
const packageVersion = "87.0.4";
|
|
5
5
|
const sanitiseSentryEvents = (data, _hint) => {
|
|
6
6
|
// Remove URL as it has UGC
|
|
7
7
|
// TODO: Sanitise the URL instead of just removing it
|
|
@@ -11,7 +11,8 @@ export const CodeBlockSharedCssClassName = {
|
|
|
11
11
|
CODEBLOCK_CONTENT_WRAPPER: 'code-block-content-wrapper',
|
|
12
12
|
CODEBLOCK_LINE_NUMBER_GUTTER: 'line-number-gutter',
|
|
13
13
|
CODEBLOCK_CONTENT: 'code-content',
|
|
14
|
-
DS_CODEBLOCK: '[data-ds--code--code-block]'
|
|
14
|
+
DS_CODEBLOCK: '[data-ds--code--code-block]',
|
|
15
|
+
CODEBLOCK_CONTENT_WRAPPED: 'code-content--wrapped'
|
|
15
16
|
};
|
|
16
17
|
export const codeBlockSharedStyles = () => css`
|
|
17
18
|
.${CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER} {
|
|
@@ -120,6 +121,13 @@ export const codeBlockSharedStyles = () => css`
|
|
|
120
121
|
line-height: 1.5rem;
|
|
121
122
|
}
|
|
122
123
|
}
|
|
124
|
+
|
|
125
|
+
.${CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPED} {
|
|
126
|
+
code {
|
|
127
|
+
word-break: break-word;
|
|
128
|
+
white-space: pre-wrap;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
123
131
|
}
|
|
124
132
|
`;
|
|
125
133
|
|
|
@@ -12,7 +12,7 @@ import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@
|
|
|
12
12
|
import { N0, N50A, N60A, N900 } from '@atlaskit/theme/colors';
|
|
13
13
|
import Layer from '../Layer';
|
|
14
14
|
const packageName = "@atlaskit/editor-common";
|
|
15
|
-
const packageVersion = "87.0.
|
|
15
|
+
const packageVersion = "87.0.4";
|
|
16
16
|
const halfFocusRing = 1;
|
|
17
17
|
const dropOffset = '0, 8';
|
|
18
18
|
class DropList extends Component {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
+
export var defaultWordWrapState = false;
|
|
3
|
+
export var codeBlockWrappedStates = new WeakMap();
|
|
4
|
+
export var isCodeBlockWordWrapEnabled = function isCodeBlockWordWrapEnabled(codeBlockNode) {
|
|
5
|
+
if (!fg('editor_support_code_block_wrapping')) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
var currentNodeWordWrapState = codeBlockWrappedStates.get(codeBlockNode);
|
|
9
|
+
return currentNodeWordWrapState !== undefined ? currentNodeWordWrapState : defaultWordWrapState;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* As the code block node is used as the key, there is instances where the node will be destroyed & recreated and is no longer a valid key.
|
|
14
|
+
* In these instances, we must get the value from that old node and set it to the value of the new node.
|
|
15
|
+
*/
|
|
16
|
+
export var transferCodeBlockWrappedValue = function transferCodeBlockWrappedValue(oldCodeBlockNode, newCodeBlockNode) {
|
|
17
|
+
if (!fg('editor_support_code_block_wrapping')) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
var previousValue = codeBlockWrappedStates.get(oldCodeBlockNode);
|
|
21
|
+
if (previousValue !== undefined) {
|
|
22
|
+
codeBlockWrappedStates.set(newCodeBlockNode, previousValue);
|
|
23
|
+
codeBlockWrappedStates.delete(oldCodeBlockNode);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
|
-
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; }
|
|
5
|
-
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; }
|
|
6
|
-
import debounce from 'lodash/debounce';
|
|
7
|
-
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
1
|
+
import { LazyNodeView } from './node-view';
|
|
2
|
+
import { queueReplaceNodeViews } from './replace-node-views';
|
|
8
3
|
|
|
9
4
|
/**
|
|
10
5
|
* 📢 Public Type
|
|
@@ -18,118 +13,12 @@ import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
|
18
13
|
* @see {withLazyLoading}
|
|
19
14
|
*/
|
|
20
15
|
|
|
21
|
-
/**
|
|
22
|
-
* 🧱 Internal: Editor FE Platform
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 🧱 Internal: Editor FE Platform
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 🧱 Internal: Editor FE Platform
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 🧱 Internal: Editor FE Platform
|
|
35
|
-
*
|
|
36
|
-
* A cache to store loaded React NodeViews for each EditorView.
|
|
37
|
-
*
|
|
38
|
-
* This cache will help us to avoid any race condition
|
|
39
|
-
* when multiple Editors exist in the same page.
|
|
40
|
-
*
|
|
41
|
-
* @type {CacheType}
|
|
42
|
-
*/
|
|
43
|
-
var cachePerEditorView = new WeakMap();
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 🧱 Internal: Editor FE Platform
|
|
47
|
-
*/
|
|
48
|
-
var isFirefox = /gecko\/\d/i.test(navigator.userAgent);
|
|
49
|
-
|
|
50
16
|
/**
|
|
51
17
|
* 🧱 Internal: Editor FE Platform
|
|
52
18
|
*
|
|
53
|
-
*
|
|
19
|
+
* Controls which node was scheduled to load the original node view code
|
|
54
20
|
*/
|
|
55
|
-
var
|
|
56
|
-
var _node$type;
|
|
57
|
-
_classCallCheck(this, LazyNodeView);
|
|
58
|
-
if (typeof ((_node$type = node.type) === null || _node$type === void 0 || (_node$type = _node$type.spec) === null || _node$type === void 0 ? void 0 : _node$type.toDOM) !== 'function') {
|
|
59
|
-
this.dom = document.createElement('div');
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
var fallback = DOMSerializer.renderSpec(document, node.type.spec.toDOM(node));
|
|
63
|
-
this.dom = fallback.dom;
|
|
64
|
-
this.contentDOM = fallback.contentDOM;
|
|
65
|
-
if (this.dom instanceof HTMLElement) {
|
|
66
|
-
// This attribute is mostly used for debugging purposed
|
|
67
|
-
// It will help us to found out when the node was replaced
|
|
68
|
-
this.dom.setAttribute('data-lazy-node-view', node.type.name);
|
|
69
|
-
// This is used on Libra tests
|
|
70
|
-
// We are using this to make sure all lazy noded were replaced
|
|
71
|
-
// before the test started
|
|
72
|
-
this.dom.setAttribute('data-lazy-node-view-fallback', 'true');
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
/**
|
|
76
|
-
* 🧱 Internal: Editor FE Platform
|
|
77
|
-
*
|
|
78
|
-
* Debounces and replaces the node views in a ProseMirror editor with lazy-loaded node views.
|
|
79
|
-
*
|
|
80
|
-
* This function is used to update the `nodeViews` property of the `EditorView` after lazy-loaded
|
|
81
|
-
* node views have been loaded. It uses a debounced approach to ensure that the replacement does
|
|
82
|
-
* not happen too frequently, which can be performance-intensive.
|
|
83
|
-
*
|
|
84
|
-
* The function checks if there are any loaded node views in the cache associated with the given
|
|
85
|
-
* `EditorView`. If there are, it replaces the current `nodeViews` in the `EditorView` with the
|
|
86
|
-
* loaded node views. The replacement is scheduled using `requestIdleCallback` or
|
|
87
|
-
* `requestAnimationFrame` to avoid blocking the main thread, especially in Firefox where
|
|
88
|
-
* `requestIdleCallback` may not be supported.
|
|
89
|
-
*
|
|
90
|
-
* @param {WeakMap<EditorView, Record<string, NodeViewConstructor>>} cache - A WeakMap that stores
|
|
91
|
-
* the loaded node views for each `EditorView`. The key is the `EditorView`, and the value
|
|
92
|
-
* is a record of node type names to their corresponding `NodeViewConstructor`.
|
|
93
|
-
* @param {EditorView} view - The ProseMirror `EditorView` instance whose `nodeViews` property
|
|
94
|
-
* needs to be updated.
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* const cache = new WeakMap();
|
|
98
|
-
* const view = new EditorView(...);
|
|
99
|
-
*
|
|
100
|
-
* // Assume some node views have been loaded and stored in the cache
|
|
101
|
-
* cache.set(view, {
|
|
102
|
-
* 'table': TableViewConstructor,
|
|
103
|
-
* 'tableCell': TableCellViewConstructor,
|
|
104
|
-
* });
|
|
105
|
-
*
|
|
106
|
-
* debouncedReplaceNodeviews(cache, view);
|
|
107
|
-
*/
|
|
108
|
-
export var debouncedReplaceNodeviews = debounce(function (cache, view) {
|
|
109
|
-
var loadedNodeviews = cache.get(view);
|
|
110
|
-
if (!loadedNodeviews) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
cache.delete(view);
|
|
114
|
-
|
|
115
|
-
// eslint-disable-next-line compat/compat
|
|
116
|
-
var idle = window.requestIdleCallback;
|
|
117
|
-
|
|
118
|
-
/*
|
|
119
|
-
* For reasons that goes beyond my knowledge
|
|
120
|
-
* some Firefox versions aren't calling the requestIdleCallback.
|
|
121
|
-
*
|
|
122
|
-
* So, we need this check to make sure we use the requestAnimationFrame instead
|
|
123
|
-
*/
|
|
124
|
-
var later = isFirefox || typeof idle !== 'function' ? window.requestAnimationFrame : idle;
|
|
125
|
-
later(function () {
|
|
126
|
-
var currentNodeViews = view.props.nodeViews;
|
|
127
|
-
var nextNodeViews = _objectSpread(_objectSpread({}, currentNodeViews), loadedNodeviews);
|
|
128
|
-
view.setProps({
|
|
129
|
-
nodeViews: nextNodeViews
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
21
|
+
var requestedNodesPerEditorView = new WeakMap();
|
|
133
22
|
|
|
134
23
|
/**
|
|
135
24
|
* 📢 Public: Any EditorPlugin can use this function
|
|
@@ -177,23 +66,26 @@ export var withLazyLoading = function withLazyLoading(_ref) {
|
|
|
177
66
|
getNodeViewOptions = _ref.getNodeViewOptions,
|
|
178
67
|
dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent;
|
|
179
68
|
var createLazyNodeView = function createLazyNodeView(node, view, getPos, decorations) {
|
|
180
|
-
var _node$
|
|
181
|
-
var
|
|
182
|
-
if (!
|
|
183
|
-
|
|
184
|
-
cachePerEditorView.set(view, cachedMap);
|
|
69
|
+
var _node$type;
|
|
70
|
+
var requestedNodes = requestedNodesPerEditorView.get(view);
|
|
71
|
+
if (!requestedNodes) {
|
|
72
|
+
requestedNodes = new Set(), requestedNodesPerEditorView.set(view, requestedNodes);
|
|
185
73
|
}
|
|
186
|
-
var wasAlreadyRequested =
|
|
74
|
+
var wasAlreadyRequested = requestedNodes.has(nodeName);
|
|
187
75
|
if (wasAlreadyRequested) {
|
|
188
76
|
return new LazyNodeView(node, view, getPos);
|
|
189
77
|
}
|
|
78
|
+
requestedNodes.add(nodeName);
|
|
190
79
|
loader().then(function (nodeViewFuncModule) {
|
|
191
|
-
|
|
80
|
+
var nodeViewFunc = function nodeViewFunc(node, view, getPos, decorations) {
|
|
192
81
|
return nodeViewFuncModule(node, view, getPos, decorations, getNodeViewOptions);
|
|
193
82
|
};
|
|
194
|
-
|
|
83
|
+
queueReplaceNodeViews(view, {
|
|
84
|
+
nodeName: nodeName,
|
|
85
|
+
nodeViewFunc: nodeViewFunc
|
|
86
|
+
});
|
|
195
87
|
});
|
|
196
|
-
if (typeof ((_node$
|
|
88
|
+
if (typeof ((_node$type = node.type) === null || _node$type === void 0 || (_node$type = _node$type.spec) === null || _node$type === void 0 ? void 0 : _node$type.toDOM) !== 'function') {
|
|
197
89
|
// TODO: Analytics ED-23982
|
|
198
90
|
// dispatchAnalyticsEvent({
|
|
199
91
|
// action: ACTION.LAZY_NODE_VIEW_ERROR,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
+
/**
|
|
5
|
+
* 🧱 Internal: Editor FE Platform
|
|
6
|
+
*
|
|
7
|
+
* A NodeView that serves as a placeholder until the actual NodeView is loaded.
|
|
8
|
+
*/
|
|
9
|
+
export var LazyNodeView = /*#__PURE__*/_createClass(function LazyNodeView(node, view, getPos) {
|
|
10
|
+
var _node$type;
|
|
11
|
+
_classCallCheck(this, LazyNodeView);
|
|
12
|
+
if (typeof ((_node$type = node.type) === null || _node$type === void 0 || (_node$type = _node$type.spec) === null || _node$type === void 0 ? void 0 : _node$type.toDOM) !== 'function') {
|
|
13
|
+
this.dom = document.createElement('div');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
var fallback = DOMSerializer.renderSpec(document, node.type.spec.toDOM(node));
|
|
17
|
+
this.dom = fallback.dom;
|
|
18
|
+
this.contentDOM = fallback.contentDOM;
|
|
19
|
+
if (this.dom instanceof HTMLElement) {
|
|
20
|
+
// This attribute is mostly used for debugging purposed
|
|
21
|
+
// It will help us to found out when the node was replaced
|
|
22
|
+
this.dom.setAttribute('data-lazy-node-view', node.type.name);
|
|
23
|
+
// This is used on Libra tests
|
|
24
|
+
// We are using this to make sure all lazy noded were replaced
|
|
25
|
+
// before the test started
|
|
26
|
+
this.dom.setAttribute('data-lazy-node-view-fallback', 'true');
|
|
27
|
+
}
|
|
28
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
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 debounce from 'lodash/debounce';
|
|
5
|
+
/**
|
|
6
|
+
* 🧱 Internal: Editor FE Platform
|
|
7
|
+
*/
|
|
8
|
+
var isFirefox = /gecko\/\d/i.test(navigator.userAgent);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 🧱 Internal: Editor FE Platform
|
|
12
|
+
*
|
|
13
|
+
* Debounces and replaces the node views in a ProseMirror editor with lazy-loaded node views.
|
|
14
|
+
*
|
|
15
|
+
* This function is used to update the `nodeViews` property of the `EditorView` after lazy-loaded
|
|
16
|
+
* node views have been loaded. It uses a debounced approach to ensure that the replacement does
|
|
17
|
+
* not happen too frequently, which can be performance-intensive.
|
|
18
|
+
*
|
|
19
|
+
* The function checks if there are any loaded node views in the cache associated with the given
|
|
20
|
+
* `EditorView`. If there are, it replaces the current `nodeViews` in the `EditorView` with the
|
|
21
|
+
* loaded node views. The replacement is scheduled using `requestIdleCallback` or
|
|
22
|
+
* `requestAnimationFrame` to avoid blocking the main thread, especially in Firefox where
|
|
23
|
+
* `requestIdleCallback` may not be supported.
|
|
24
|
+
*
|
|
25
|
+
* @param {WeakMap<EditorView, Record<string, NodeViewConstructor>>} cache - A WeakMap that stores
|
|
26
|
+
* the loaded node views for each `EditorView`. The key is the `EditorView`, and the value
|
|
27
|
+
* is a record of node type names to their corresponding `NodeViewConstructor`.
|
|
28
|
+
* @param {EditorView} view - The ProseMirror `EditorView` instance whose `nodeViews` property
|
|
29
|
+
* needs to be updated.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const cache = new WeakMap();
|
|
33
|
+
* const view = new EditorView(...);
|
|
34
|
+
*
|
|
35
|
+
* // Assume some node views have been loaded and stored in the cache
|
|
36
|
+
* cache.set(view, {
|
|
37
|
+
* 'table': TableViewConstructor,
|
|
38
|
+
* 'tableCell': TableCellViewConstructor,
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* debouncedReplaceNodeviews(cache, view);
|
|
42
|
+
*/
|
|
43
|
+
export var debouncedReplaceNodeviews = debounce(function (cache, view) {
|
|
44
|
+
var loadedNodeviews = cache.get(view);
|
|
45
|
+
if (!loadedNodeviews || Object.keys(loadedNodeviews).length === 0) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
var nodeViewsToReplace = _objectSpread({}, loadedNodeviews);
|
|
49
|
+
|
|
50
|
+
// Make sure the cache is cleaned
|
|
51
|
+
// From here, we will access the loaded node views by lexical scope
|
|
52
|
+
cache.set(view, {});
|
|
53
|
+
|
|
54
|
+
// eslint-disable-next-line compat/compat
|
|
55
|
+
var idle = window.requestIdleCallback;
|
|
56
|
+
|
|
57
|
+
/*
|
|
58
|
+
* For reasons that goes beyond my knowledge
|
|
59
|
+
* some Firefox versions aren't calling the requestIdleCallback.
|
|
60
|
+
*
|
|
61
|
+
* So, we need this check to make sure we use the requestAnimationFrame instead
|
|
62
|
+
*/
|
|
63
|
+
var later = isFirefox || typeof idle !== 'function' ? window.requestAnimationFrame : idle;
|
|
64
|
+
later(function () {
|
|
65
|
+
var currentNodeViews = view.props.nodeViews;
|
|
66
|
+
var nextNodeViews = _objectSpread(_objectSpread({}, currentNodeViews), nodeViewsToReplace);
|
|
67
|
+
view.setProps({
|
|
68
|
+
nodeViews: nextNodeViews
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 🧱 Internal: Editor FE Platform
|
|
75
|
+
*/
|
|
76
|
+
var loadedPerEditorView = new WeakMap();
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 🧱 Internal: Editor FE Platform
|
|
80
|
+
*/
|
|
81
|
+
export var queueReplaceNodeViews = function queueReplaceNodeViews(view, _ref) {
|
|
82
|
+
var nodeName = _ref.nodeName,
|
|
83
|
+
nodeViewFunc = _ref.nodeViewFunc;
|
|
84
|
+
var nodeViews = loadedPerEditorView.get(view) || {};
|
|
85
|
+
nodeViews[nodeName] = nodeViewFunc;
|
|
86
|
+
loadedPerEditorView.set(view, nodeViews);
|
|
87
|
+
debouncedReplaceNodeviews(loadedPerEditorView, view);
|
|
88
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -7,7 +7,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
7
7
|
import { isFedRamp } from './environment';
|
|
8
8
|
var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
|
|
9
9
|
var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
|
|
10
|
-
var packageVersion = "87.0.
|
|
10
|
+
var packageVersion = "87.0.4";
|
|
11
11
|
var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
|
|
12
12
|
// Remove URL as it has UGC
|
|
13
13
|
// TODO: Sanitise the URL instead of just removing it
|
|
@@ -13,12 +13,13 @@ export var CodeBlockSharedCssClassName = {
|
|
|
13
13
|
CODEBLOCK_CONTENT_WRAPPER: 'code-block-content-wrapper',
|
|
14
14
|
CODEBLOCK_LINE_NUMBER_GUTTER: 'line-number-gutter',
|
|
15
15
|
CODEBLOCK_CONTENT: 'code-content',
|
|
16
|
-
DS_CODEBLOCK: '[data-ds--code--code-block]'
|
|
16
|
+
DS_CODEBLOCK: '[data-ds--code--code-block]',
|
|
17
|
+
CODEBLOCK_CONTENT_WRAPPED: 'code-content--wrapped'
|
|
17
18
|
};
|
|
18
19
|
export var codeBlockSharedStyles = function codeBlockSharedStyles() {
|
|
19
|
-
return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n\t.", " {\n\t\tposition: relative;\n\t\tbackground-color: ", ";\n\t\tborder-radius: ", ";\n\t\tmargin: ", " 0 0 0;\n\t\tfont-family: ", ";\n\t\tmin-width: ", "px;\n\t\tcursor: pointer;\n\n\t\t--ds--code--bg-color: transparent;\n\n\t\t/* This is necessary to allow for arrow key navigation in/out of code blocks in Firefox. */\n\t\twhite-space: normal;\n\n\t\t.", " {\n\t\t\tposition: absolute;\n\t\t\tvisibility: hidden;\n\t\t\theight: 1.5rem;\n\t\t\ttop: 0px;\n\t\t\tleft: 0px;\n\t\t}\n\n\t\t.", " {\n\t\t\tposition: absolute;\n\t\t\tvisibility: hidden;\n\t\t\theight: 1.5rem;\n\t\t\tbottom: 0px;\n\t\t\tright: 0px;\n\t\t}\n\n\t\t.", " {\n\t\t\tbackground-color: ", ";\n\t\t\tdisplay: flex;\n\t\t\tborder-radius: ", ";\n\t\t\twidth: 100%;\n\t\t\tcounter-reset: line;\n\t\t\toverflow-x: auto;\n\n\t\t\tbackground-image: ", ";\n\n\t\t\tbackground-repeat: no-repeat;\n\t\t\tbackground-attachment: local, local, local, local, scroll, scroll, scroll, scroll;\n\t\t\tbackground-size:\n\t\t\t\t", " 100%,\n\t\t\t\t", " 100%,\n\t\t\t\t", " 100%,\n\t\t\t\t", " 100%,\n\t\t\t\t", " 100%,\n\t\t\t\t1px 100%,\n\t\t\t\t", " 100%,\n\t\t\t\t1px 100%;\n\t\t\tbackground-position:\n\t\t\t\t0 0,\n\t\t\t\t0 0,\n\t\t\t\t100% 0,\n\t\t\t\t100% 0,\n\t\t\t\t100% 0,\n\t\t\t\t100% 0,\n\t\t\t\t0 0,\n\t\t\t\t0 0;\n\n\t\t\t/* Be careful if refactoring this; it is needed to keep arrow key navigation in Firefox consistent with other browsers. */\n\t\t\toverflow-y: hidden;\n\t\t}\n\n\t\t.", " {\n\t\t\tflex-shrink: 0;\n\t\t\ttext-align: right;\n\t\t\tbackground-color: ", ";\n\t\t\tpadding: ", ";\n\t\t\tposition: relative;\n\n\t\t\tspan {\n\t\t\t\tdisplay: block;\n\t\t\t\tline-height: 0;\n\t\t\t\tfont-size: 0;\n\n\t\t\t\t::before {\n\t\t\t\t\tdisplay: inline-block;\n\t\t\t\t\tcontent: counter(line);\n\t\t\t\t\tcounter-increment: line;\n\t\t\t\t\tcolor: ", ";\n\t\t\t\t\tfont-size: ", ";\n\t\t\t\t\tline-height: 1.5rem;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t.", " {\n\t\t\tdisplay: flex;\n\t\t\tflex: 1;\n\n\t\t\tcode {\n\t\t\t\tflex-grow: 1;\n\t\t\t\ttab-size: 4;\n\t\t\t\tcursor: text;\n\t\t\t\tcolor: ", ";\n\t\t\t\tborder-radius: ", ";\n\t\t\t\tmargin: ", ";\n\t\t\t\twhite-space: pre;\n\t\t\t\tfont-size: ", ";\n\t\t\t\tline-height: 1.5rem;\n\t\t\t}\n\t\t}\n\t}\n"])), CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER, "var(--ds-surface-raised, transparent)", "var(--ds-border-radius, 3px)", blockNodesVerticalMargin, akEditorCodeFontFamily, akEditorTableCellMinWidth, CodeBlockSharedCssClassName.CODEBLOCK_START, CodeBlockSharedCssClassName.CODEBLOCK_END, CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER, "var(--ds-background-neutral, ".concat(N20, ")"), "var(--ds-border-radius, 3px)", overflowShadow({
|
|
20
|
+
return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n\t.", " {\n\t\tposition: relative;\n\t\tbackground-color: ", ";\n\t\tborder-radius: ", ";\n\t\tmargin: ", " 0 0 0;\n\t\tfont-family: ", ";\n\t\tmin-width: ", "px;\n\t\tcursor: pointer;\n\n\t\t--ds--code--bg-color: transparent;\n\n\t\t/* This is necessary to allow for arrow key navigation in/out of code blocks in Firefox. */\n\t\twhite-space: normal;\n\n\t\t.", " {\n\t\t\tposition: absolute;\n\t\t\tvisibility: hidden;\n\t\t\theight: 1.5rem;\n\t\t\ttop: 0px;\n\t\t\tleft: 0px;\n\t\t}\n\n\t\t.", " {\n\t\t\tposition: absolute;\n\t\t\tvisibility: hidden;\n\t\t\theight: 1.5rem;\n\t\t\tbottom: 0px;\n\t\t\tright: 0px;\n\t\t}\n\n\t\t.", " {\n\t\t\tbackground-color: ", ";\n\t\t\tdisplay: flex;\n\t\t\tborder-radius: ", ";\n\t\t\twidth: 100%;\n\t\t\tcounter-reset: line;\n\t\t\toverflow-x: auto;\n\n\t\t\tbackground-image: ", ";\n\n\t\t\tbackground-repeat: no-repeat;\n\t\t\tbackground-attachment: local, local, local, local, scroll, scroll, scroll, scroll;\n\t\t\tbackground-size:\n\t\t\t\t", " 100%,\n\t\t\t\t", " 100%,\n\t\t\t\t", " 100%,\n\t\t\t\t", " 100%,\n\t\t\t\t", " 100%,\n\t\t\t\t1px 100%,\n\t\t\t\t", " 100%,\n\t\t\t\t1px 100%;\n\t\t\tbackground-position:\n\t\t\t\t0 0,\n\t\t\t\t0 0,\n\t\t\t\t100% 0,\n\t\t\t\t100% 0,\n\t\t\t\t100% 0,\n\t\t\t\t100% 0,\n\t\t\t\t0 0,\n\t\t\t\t0 0;\n\n\t\t\t/* Be careful if refactoring this; it is needed to keep arrow key navigation in Firefox consistent with other browsers. */\n\t\t\toverflow-y: hidden;\n\t\t}\n\n\t\t.", " {\n\t\t\tflex-shrink: 0;\n\t\t\ttext-align: right;\n\t\t\tbackground-color: ", ";\n\t\t\tpadding: ", ";\n\t\t\tposition: relative;\n\n\t\t\tspan {\n\t\t\t\tdisplay: block;\n\t\t\t\tline-height: 0;\n\t\t\t\tfont-size: 0;\n\n\t\t\t\t::before {\n\t\t\t\t\tdisplay: inline-block;\n\t\t\t\t\tcontent: counter(line);\n\t\t\t\t\tcounter-increment: line;\n\t\t\t\t\tcolor: ", ";\n\t\t\t\t\tfont-size: ", ";\n\t\t\t\t\tline-height: 1.5rem;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t.", " {\n\t\t\tdisplay: flex;\n\t\t\tflex: 1;\n\n\t\t\tcode {\n\t\t\t\tflex-grow: 1;\n\t\t\t\ttab-size: 4;\n\t\t\t\tcursor: text;\n\t\t\t\tcolor: ", ";\n\t\t\t\tborder-radius: ", ";\n\t\t\t\tmargin: ", ";\n\t\t\t\twhite-space: pre;\n\t\t\t\tfont-size: ", ";\n\t\t\t\tline-height: 1.5rem;\n\t\t\t}\n\t\t}\n\n\t\t.", " {\n\t\t\tcode {\n\t\t\t\tword-break: break-word;\n\t\t\t\twhite-space: pre-wrap;\n\t\t\t}\n\t\t}\n\t}\n"])), CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER, "var(--ds-surface-raised, transparent)", "var(--ds-border-radius, 3px)", blockNodesVerticalMargin, akEditorCodeFontFamily, akEditorTableCellMinWidth, CodeBlockSharedCssClassName.CODEBLOCK_START, CodeBlockSharedCssClassName.CODEBLOCK_END, CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER, "var(--ds-background-neutral, ".concat(N20, ")"), "var(--ds-border-radius, 3px)", overflowShadow({
|
|
20
21
|
leftCoverWidth: "var(--ds-space-300, 24px)"
|
|
21
|
-
}), "var(--ds-space-300, 24px)", "var(--ds-space-300, 24px)", "var(--ds-space-100, 8px)", "var(--ds-space-100, 8px)", "var(--ds-space-100, 8px)", "var(--ds-space-100, 8px)", CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER, "var(--ds-background-neutral, ".concat(N30, ")"), "var(--ds-space-100, 8px)", "var(--ds-text-subtlest, ".concat(N400, ")"), relativeFontSizeToBase16(fontSize()), CodeBlockSharedCssClassName.CODEBLOCK_CONTENT, "var(--ds-text, ".concat(N800, ")"), "var(--ds-border-radius, 3px)", "var(--ds-space-100, 8px)", relativeFontSizeToBase16(fontSize()));
|
|
22
|
+
}), "var(--ds-space-300, 24px)", "var(--ds-space-300, 24px)", "var(--ds-space-100, 8px)", "var(--ds-space-100, 8px)", "var(--ds-space-100, 8px)", "var(--ds-space-100, 8px)", CodeBlockSharedCssClassName.CODEBLOCK_LINE_NUMBER_GUTTER, "var(--ds-background-neutral, ".concat(N30, ")"), "var(--ds-space-100, 8px)", "var(--ds-text-subtlest, ".concat(N400, ")"), relativeFontSizeToBase16(fontSize()), CodeBlockSharedCssClassName.CODEBLOCK_CONTENT, "var(--ds-text, ".concat(N800, ")"), "var(--ds-border-radius, 3px)", "var(--ds-space-100, 8px)", relativeFontSizeToBase16(fontSize()), CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPED);
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766
|
|
@@ -20,7 +20,7 @@ import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@
|
|
|
20
20
|
import { N0, N50A, N60A, N900 } from '@atlaskit/theme/colors';
|
|
21
21
|
import Layer from '../Layer';
|
|
22
22
|
var packageName = "@atlaskit/editor-common";
|
|
23
|
-
var packageVersion = "87.0.
|
|
23
|
+
var packageVersion = "87.0.4";
|
|
24
24
|
var halfFocusRing = 1;
|
|
25
25
|
var dropOffset = '0, 8';
|
|
26
26
|
var DropList = /*#__PURE__*/function (_Component) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
export declare const defaultWordWrapState = false;
|
|
3
|
+
export declare const codeBlockWrappedStates: WeakMap<PmNode, boolean | undefined>;
|
|
4
|
+
export declare const isCodeBlockWordWrapEnabled: (codeBlockNode: PmNode) => boolean;
|
|
5
|
+
/**
|
|
6
|
+
* As the code block node is used as the key, there is instances where the node will be destroyed & recreated and is no longer a valid key.
|
|
7
|
+
* In these instances, we must get the value from that old node and set it to the value of the new node.
|
|
8
|
+
*/
|
|
9
|
+
export declare const transferCodeBlockWrappedValue: (oldCodeBlockNode: PmNode, newCodeBlockNode: PmNode) => void;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
/// <reference types="lodash" />
|
|
2
1
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import type { Decoration,
|
|
2
|
+
import type { Decoration, EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
|
|
4
3
|
import type { DispatchAnalyticsEvent } from '../analytics';
|
|
4
|
+
import type { NodeViewConstructor } from './types';
|
|
5
|
+
export type { NodeViewConstructor };
|
|
5
6
|
/**
|
|
6
7
|
* 📢 Public Type
|
|
7
8
|
*
|
|
@@ -19,52 +20,6 @@ export type LazyLoadingProps<NodeViewOptions> = {
|
|
|
19
20
|
getNodeViewOptions: () => NodeViewOptions;
|
|
20
21
|
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
21
22
|
};
|
|
22
|
-
/**
|
|
23
|
-
* 🧱 Internal: Editor FE Platform
|
|
24
|
-
*/
|
|
25
|
-
export type NodeViewConstructor = (node: PMNode, view: EditorView, getPos: () => number | undefined, decorations: readonly Decoration[], innerDecorations: DecorationSource) => NodeView;
|
|
26
|
-
/**
|
|
27
|
-
* 🧱 Internal: Editor FE Platform
|
|
28
|
-
*/
|
|
29
|
-
type LoadedReactNodeViews = Record<string, NodeViewConstructor>;
|
|
30
|
-
/**
|
|
31
|
-
* 🧱 Internal: Editor FE Platform
|
|
32
|
-
*/
|
|
33
|
-
type CacheType = WeakMap<EditorView, LoadedReactNodeViews>;
|
|
34
|
-
/**
|
|
35
|
-
* 🧱 Internal: Editor FE Platform
|
|
36
|
-
*
|
|
37
|
-
* Debounces and replaces the node views in a ProseMirror editor with lazy-loaded node views.
|
|
38
|
-
*
|
|
39
|
-
* This function is used to update the `nodeViews` property of the `EditorView` after lazy-loaded
|
|
40
|
-
* node views have been loaded. It uses a debounced approach to ensure that the replacement does
|
|
41
|
-
* not happen too frequently, which can be performance-intensive.
|
|
42
|
-
*
|
|
43
|
-
* The function checks if there are any loaded node views in the cache associated with the given
|
|
44
|
-
* `EditorView`. If there are, it replaces the current `nodeViews` in the `EditorView` with the
|
|
45
|
-
* loaded node views. The replacement is scheduled using `requestIdleCallback` or
|
|
46
|
-
* `requestAnimationFrame` to avoid blocking the main thread, especially in Firefox where
|
|
47
|
-
* `requestIdleCallback` may not be supported.
|
|
48
|
-
*
|
|
49
|
-
* @param {WeakMap<EditorView, Record<string, NodeViewConstructor>>} cache - A WeakMap that stores
|
|
50
|
-
* the loaded node views for each `EditorView`. The key is the `EditorView`, and the value
|
|
51
|
-
* is a record of node type names to their corresponding `NodeViewConstructor`.
|
|
52
|
-
* @param {EditorView} view - The ProseMirror `EditorView` instance whose `nodeViews` property
|
|
53
|
-
* needs to be updated.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* const cache = new WeakMap();
|
|
57
|
-
* const view = new EditorView(...);
|
|
58
|
-
*
|
|
59
|
-
* // Assume some node views have been loaded and stored in the cache
|
|
60
|
-
* cache.set(view, {
|
|
61
|
-
* 'table': TableViewConstructor,
|
|
62
|
-
* 'tableCell': TableCellViewConstructor,
|
|
63
|
-
* });
|
|
64
|
-
*
|
|
65
|
-
* debouncedReplaceNodeviews(cache, view);
|
|
66
|
-
*/
|
|
67
|
-
export declare const debouncedReplaceNodeviews: import("lodash").DebouncedFunc<(cache: CacheType, view: EditorView) => void>;
|
|
68
23
|
/**
|
|
69
24
|
* 📢 Public: Any EditorPlugin can use this function
|
|
70
25
|
*
|
|
@@ -106,4 +61,3 @@ export declare const debouncedReplaceNodeviews: import("lodash").DebouncedFunc<(
|
|
|
106
61
|
* // Then, use `lazyTableView` in ProseMirror editor setup to enhance 'table' nodes with lazy loading
|
|
107
62
|
*/
|
|
108
63
|
export declare const withLazyLoading: <Options>({ nodeName, loader, getNodeViewOptions, dispatchAnalyticsEvent, }: LazyLoadingProps<Options>) => NodeViewConstructor;
|
|
109
|
-
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
/**
|
|
4
|
+
* 🧱 Internal: Editor FE Platform
|
|
5
|
+
*
|
|
6
|
+
* A NodeView that serves as a placeholder until the actual NodeView is loaded.
|
|
7
|
+
*/
|
|
8
|
+
export declare class LazyNodeView implements NodeView {
|
|
9
|
+
dom: Node;
|
|
10
|
+
contentDOM?: HTMLElement;
|
|
11
|
+
constructor(node: PMNode, view: EditorView, getPos: () => number | undefined);
|
|
12
|
+
}
|