@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @atlaskit/editor-common
|
|
2
2
|
|
|
3
|
+
## 87.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#125133](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/125133)
|
|
8
|
+
[`d804e5dd3216b`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d804e5dd3216b) -
|
|
9
|
+
ED-24226 - Add state to manage the toggle word wrap state of code blocks. New WeakMap added in
|
|
10
|
+
editor-common/src/code-block, as word wrap state is shared throughout the editor. Covers regular
|
|
11
|
+
changes to code block by the user via the node view update function. Covers breakout of code block
|
|
12
|
+
node. Does not cover drag&drop & cut&paste edge cases.
|
|
13
|
+
|
|
14
|
+
## 87.0.3
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [#124585](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/124585)
|
|
19
|
+
[`38ebc7f4f4ce9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/38ebc7f4f4ce9) -
|
|
20
|
+
Fix LazyNodeView race condition
|
|
21
|
+
- [#124302](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/124302)
|
|
22
|
+
[`45dc9b6543007`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/45dc9b6543007) -
|
|
23
|
+
[ux] ED-24228 adding wrap content functionality with feature gate
|
|
24
|
+
|
|
3
25
|
## 87.0.2
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/editor-common/code-block",
|
|
3
|
+
"main": "../dist/cjs/code-block/index.js",
|
|
4
|
+
"module": "../dist/esm/code-block/index.js",
|
|
5
|
+
"module:es2019": "../dist/es2019/code-block/index.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"types": "../dist/types/code-block/index.d.ts",
|
|
8
|
+
"typesVersions": {
|
|
9
|
+
">=4.5 <5.4": {
|
|
10
|
+
"*": [
|
|
11
|
+
"../dist/types-ts4.5/code-block/index.d.ts"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.transferCodeBlockWrappedValue = exports.isCodeBlockWordWrapEnabled = exports.defaultWordWrapState = exports.codeBlockWrappedStates = void 0;
|
|
7
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
8
|
+
var defaultWordWrapState = exports.defaultWordWrapState = false;
|
|
9
|
+
var codeBlockWrappedStates = exports.codeBlockWrappedStates = new WeakMap();
|
|
10
|
+
var isCodeBlockWordWrapEnabled = exports.isCodeBlockWordWrapEnabled = function isCodeBlockWordWrapEnabled(codeBlockNode) {
|
|
11
|
+
if (!(0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping')) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
var currentNodeWordWrapState = codeBlockWrappedStates.get(codeBlockNode);
|
|
15
|
+
return currentNodeWordWrapState !== undefined ? currentNodeWordWrapState : defaultWordWrapState;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 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.
|
|
20
|
+
* In these instances, we must get the value from that old node and set it to the value of the new node.
|
|
21
|
+
*/
|
|
22
|
+
var transferCodeBlockWrappedValue = exports.transferCodeBlockWrappedValue = function transferCodeBlockWrappedValue(oldCodeBlockNode, newCodeBlockNode) {
|
|
23
|
+
if (!(0, _platformFeatureFlags.fg)('editor_support_code_block_wrapping')) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
var previousValue = codeBlockWrappedStates.get(oldCodeBlockNode);
|
|
27
|
+
if (previousValue !== undefined) {
|
|
28
|
+
codeBlockWrappedStates.set(newCodeBlockNode, previousValue);
|
|
29
|
+
codeBlockWrappedStates.delete(oldCodeBlockNode);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
|
-
exports.withLazyLoading =
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
var _debounce = _interopRequireDefault(require("lodash/debounce"));
|
|
12
|
-
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
13
|
-
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; }
|
|
14
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
+
exports.withLazyLoading = void 0;
|
|
7
|
+
var _nodeView = require("./node-view");
|
|
8
|
+
var _replaceNodeViews = require("./replace-node-views");
|
|
15
9
|
/**
|
|
16
10
|
* 📢 Public Type
|
|
17
11
|
*
|
|
@@ -26,116 +20,10 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
26
20
|
|
|
27
21
|
/**
|
|
28
22
|
* 🧱 Internal: Editor FE Platform
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 🧱 Internal: Editor FE Platform
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 🧱 Internal: Editor FE Platform
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 🧱 Internal: Editor FE Platform
|
|
41
|
-
*
|
|
42
|
-
* A cache to store loaded React NodeViews for each EditorView.
|
|
43
|
-
*
|
|
44
|
-
* This cache will help us to avoid any race condition
|
|
45
|
-
* when multiple Editors exist in the same page.
|
|
46
|
-
*
|
|
47
|
-
* @type {CacheType}
|
|
48
|
-
*/
|
|
49
|
-
var cachePerEditorView = new WeakMap();
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 🧱 Internal: Editor FE Platform
|
|
53
|
-
*/
|
|
54
|
-
var isFirefox = /gecko\/\d/i.test(navigator.userAgent);
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 🧱 Internal: Editor FE Platform
|
|
58
|
-
*
|
|
59
|
-
* A NodeView that serves as a placeholder until the actual NodeView is loaded.
|
|
60
|
-
*/
|
|
61
|
-
var LazyNodeView = /*#__PURE__*/(0, _createClass2.default)(function LazyNodeView(node, view, getPos) {
|
|
62
|
-
var _node$type;
|
|
63
|
-
(0, _classCallCheck2.default)(this, LazyNodeView);
|
|
64
|
-
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') {
|
|
65
|
-
this.dom = document.createElement('div');
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
var fallback = _model.DOMSerializer.renderSpec(document, node.type.spec.toDOM(node));
|
|
69
|
-
this.dom = fallback.dom;
|
|
70
|
-
this.contentDOM = fallback.contentDOM;
|
|
71
|
-
if (this.dom instanceof HTMLElement) {
|
|
72
|
-
// This attribute is mostly used for debugging purposed
|
|
73
|
-
// It will help us to found out when the node was replaced
|
|
74
|
-
this.dom.setAttribute('data-lazy-node-view', node.type.name);
|
|
75
|
-
// This is used on Libra tests
|
|
76
|
-
// We are using this to make sure all lazy noded were replaced
|
|
77
|
-
// before the test started
|
|
78
|
-
this.dom.setAttribute('data-lazy-node-view-fallback', 'true');
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
/**
|
|
82
|
-
* 🧱 Internal: Editor FE Platform
|
|
83
|
-
*
|
|
84
|
-
* Debounces and replaces the node views in a ProseMirror editor with lazy-loaded node views.
|
|
85
|
-
*
|
|
86
|
-
* This function is used to update the `nodeViews` property of the `EditorView` after lazy-loaded
|
|
87
|
-
* node views have been loaded. It uses a debounced approach to ensure that the replacement does
|
|
88
|
-
* not happen too frequently, which can be performance-intensive.
|
|
89
23
|
*
|
|
90
|
-
*
|
|
91
|
-
* `EditorView`. If there are, it replaces the current `nodeViews` in the `EditorView` with the
|
|
92
|
-
* loaded node views. The replacement is scheduled using `requestIdleCallback` or
|
|
93
|
-
* `requestAnimationFrame` to avoid blocking the main thread, especially in Firefox where
|
|
94
|
-
* `requestIdleCallback` may not be supported.
|
|
95
|
-
*
|
|
96
|
-
* @param {WeakMap<EditorView, Record<string, NodeViewConstructor>>} cache - A WeakMap that stores
|
|
97
|
-
* the loaded node views for each `EditorView`. The key is the `EditorView`, and the value
|
|
98
|
-
* is a record of node type names to their corresponding `NodeViewConstructor`.
|
|
99
|
-
* @param {EditorView} view - The ProseMirror `EditorView` instance whose `nodeViews` property
|
|
100
|
-
* needs to be updated.
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* const cache = new WeakMap();
|
|
104
|
-
* const view = new EditorView(...);
|
|
105
|
-
*
|
|
106
|
-
* // Assume some node views have been loaded and stored in the cache
|
|
107
|
-
* cache.set(view, {
|
|
108
|
-
* 'table': TableViewConstructor,
|
|
109
|
-
* 'tableCell': TableCellViewConstructor,
|
|
110
|
-
* });
|
|
111
|
-
*
|
|
112
|
-
* debouncedReplaceNodeviews(cache, view);
|
|
24
|
+
* Controls which node was scheduled to load the original node view code
|
|
113
25
|
*/
|
|
114
|
-
var
|
|
115
|
-
var loadedNodeviews = cache.get(view);
|
|
116
|
-
if (!loadedNodeviews) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
cache.delete(view);
|
|
120
|
-
|
|
121
|
-
// eslint-disable-next-line compat/compat
|
|
122
|
-
var idle = window.requestIdleCallback;
|
|
123
|
-
|
|
124
|
-
/*
|
|
125
|
-
* For reasons that goes beyond my knowledge
|
|
126
|
-
* some Firefox versions aren't calling the requestIdleCallback.
|
|
127
|
-
*
|
|
128
|
-
* So, we need this check to make sure we use the requestAnimationFrame instead
|
|
129
|
-
*/
|
|
130
|
-
var later = isFirefox || typeof idle !== 'function' ? window.requestAnimationFrame : idle;
|
|
131
|
-
later(function () {
|
|
132
|
-
var currentNodeViews = view.props.nodeViews;
|
|
133
|
-
var nextNodeViews = _objectSpread(_objectSpread({}, currentNodeViews), loadedNodeviews);
|
|
134
|
-
view.setProps({
|
|
135
|
-
nodeViews: nextNodeViews
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
});
|
|
26
|
+
var requestedNodesPerEditorView = new WeakMap();
|
|
139
27
|
|
|
140
28
|
/**
|
|
141
29
|
* 📢 Public: Any EditorPlugin can use this function
|
|
@@ -183,23 +71,26 @@ var withLazyLoading = exports.withLazyLoading = function withLazyLoading(_ref) {
|
|
|
183
71
|
getNodeViewOptions = _ref.getNodeViewOptions,
|
|
184
72
|
dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent;
|
|
185
73
|
var createLazyNodeView = function createLazyNodeView(node, view, getPos, decorations) {
|
|
186
|
-
var _node$
|
|
187
|
-
var
|
|
188
|
-
if (!
|
|
189
|
-
|
|
190
|
-
cachePerEditorView.set(view, cachedMap);
|
|
74
|
+
var _node$type;
|
|
75
|
+
var requestedNodes = requestedNodesPerEditorView.get(view);
|
|
76
|
+
if (!requestedNodes) {
|
|
77
|
+
requestedNodes = new Set(), requestedNodesPerEditorView.set(view, requestedNodes);
|
|
191
78
|
}
|
|
192
|
-
var wasAlreadyRequested =
|
|
79
|
+
var wasAlreadyRequested = requestedNodes.has(nodeName);
|
|
193
80
|
if (wasAlreadyRequested) {
|
|
194
|
-
return new LazyNodeView(node, view, getPos);
|
|
81
|
+
return new _nodeView.LazyNodeView(node, view, getPos);
|
|
195
82
|
}
|
|
83
|
+
requestedNodes.add(nodeName);
|
|
196
84
|
loader().then(function (nodeViewFuncModule) {
|
|
197
|
-
|
|
85
|
+
var nodeViewFunc = function nodeViewFunc(node, view, getPos, decorations) {
|
|
198
86
|
return nodeViewFuncModule(node, view, getPos, decorations, getNodeViewOptions);
|
|
199
87
|
};
|
|
200
|
-
|
|
88
|
+
(0, _replaceNodeViews.queueReplaceNodeViews)(view, {
|
|
89
|
+
nodeName: nodeName,
|
|
90
|
+
nodeViewFunc: nodeViewFunc
|
|
91
|
+
});
|
|
201
92
|
});
|
|
202
|
-
if (typeof ((_node$
|
|
93
|
+
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') {
|
|
203
94
|
// TODO: Analytics ED-23982
|
|
204
95
|
// dispatchAnalyticsEvent({
|
|
205
96
|
// action: ACTION.LAZY_NODE_VIEW_ERROR,
|
|
@@ -211,7 +102,7 @@ var withLazyLoading = exports.withLazyLoading = function withLazyLoading(_ref) {
|
|
|
211
102
|
// },
|
|
212
103
|
// });
|
|
213
104
|
}
|
|
214
|
-
return new LazyNodeView(node, view, getPos);
|
|
105
|
+
return new _nodeView.LazyNodeView(node, view, getPos);
|
|
215
106
|
};
|
|
216
107
|
return createLazyNodeView;
|
|
217
108
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.LazyNodeView = void 0;
|
|
8
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
9
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
11
|
+
/**
|
|
12
|
+
* 🧱 Internal: Editor FE Platform
|
|
13
|
+
*
|
|
14
|
+
* A NodeView that serves as a placeholder until the actual NodeView is loaded.
|
|
15
|
+
*/
|
|
16
|
+
var LazyNodeView = exports.LazyNodeView = /*#__PURE__*/(0, _createClass2.default)(function LazyNodeView(node, view, getPos) {
|
|
17
|
+
var _node$type;
|
|
18
|
+
(0, _classCallCheck2.default)(this, LazyNodeView);
|
|
19
|
+
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') {
|
|
20
|
+
this.dom = document.createElement('div');
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
var fallback = _model.DOMSerializer.renderSpec(document, node.type.spec.toDOM(node));
|
|
24
|
+
this.dom = fallback.dom;
|
|
25
|
+
this.contentDOM = fallback.contentDOM;
|
|
26
|
+
if (this.dom instanceof HTMLElement) {
|
|
27
|
+
// This attribute is mostly used for debugging purposed
|
|
28
|
+
// It will help us to found out when the node was replaced
|
|
29
|
+
this.dom.setAttribute('data-lazy-node-view', node.type.name);
|
|
30
|
+
// This is used on Libra tests
|
|
31
|
+
// We are using this to make sure all lazy noded were replaced
|
|
32
|
+
// before the test started
|
|
33
|
+
this.dom.setAttribute('data-lazy-node-view-fallback', 'true');
|
|
34
|
+
}
|
|
35
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.queueReplaceNodeViews = exports.debouncedReplaceNodeviews = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _debounce = _interopRequireDefault(require("lodash/debounce"));
|
|
10
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
+
/**
|
|
13
|
+
* 🧱 Internal: Editor FE Platform
|
|
14
|
+
*/
|
|
15
|
+
var isFirefox = /gecko\/\d/i.test(navigator.userAgent);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 🧱 Internal: Editor FE Platform
|
|
19
|
+
*
|
|
20
|
+
* Debounces and replaces the node views in a ProseMirror editor with lazy-loaded node views.
|
|
21
|
+
*
|
|
22
|
+
* This function is used to update the `nodeViews` property of the `EditorView` after lazy-loaded
|
|
23
|
+
* node views have been loaded. It uses a debounced approach to ensure that the replacement does
|
|
24
|
+
* not happen too frequently, which can be performance-intensive.
|
|
25
|
+
*
|
|
26
|
+
* The function checks if there are any loaded node views in the cache associated with the given
|
|
27
|
+
* `EditorView`. If there are, it replaces the current `nodeViews` in the `EditorView` with the
|
|
28
|
+
* loaded node views. The replacement is scheduled using `requestIdleCallback` or
|
|
29
|
+
* `requestAnimationFrame` to avoid blocking the main thread, especially in Firefox where
|
|
30
|
+
* `requestIdleCallback` may not be supported.
|
|
31
|
+
*
|
|
32
|
+
* @param {WeakMap<EditorView, Record<string, NodeViewConstructor>>} cache - A WeakMap that stores
|
|
33
|
+
* the loaded node views for each `EditorView`. The key is the `EditorView`, and the value
|
|
34
|
+
* is a record of node type names to their corresponding `NodeViewConstructor`.
|
|
35
|
+
* @param {EditorView} view - The ProseMirror `EditorView` instance whose `nodeViews` property
|
|
36
|
+
* needs to be updated.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const cache = new WeakMap();
|
|
40
|
+
* const view = new EditorView(...);
|
|
41
|
+
*
|
|
42
|
+
* // Assume some node views have been loaded and stored in the cache
|
|
43
|
+
* cache.set(view, {
|
|
44
|
+
* 'table': TableViewConstructor,
|
|
45
|
+
* 'tableCell': TableCellViewConstructor,
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* debouncedReplaceNodeviews(cache, view);
|
|
49
|
+
*/
|
|
50
|
+
var debouncedReplaceNodeviews = exports.debouncedReplaceNodeviews = (0, _debounce.default)(function (cache, view) {
|
|
51
|
+
var loadedNodeviews = cache.get(view);
|
|
52
|
+
if (!loadedNodeviews || Object.keys(loadedNodeviews).length === 0) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
var nodeViewsToReplace = _objectSpread({}, loadedNodeviews);
|
|
56
|
+
|
|
57
|
+
// Make sure the cache is cleaned
|
|
58
|
+
// From here, we will access the loaded node views by lexical scope
|
|
59
|
+
cache.set(view, {});
|
|
60
|
+
|
|
61
|
+
// eslint-disable-next-line compat/compat
|
|
62
|
+
var idle = window.requestIdleCallback;
|
|
63
|
+
|
|
64
|
+
/*
|
|
65
|
+
* For reasons that goes beyond my knowledge
|
|
66
|
+
* some Firefox versions aren't calling the requestIdleCallback.
|
|
67
|
+
*
|
|
68
|
+
* So, we need this check to make sure we use the requestAnimationFrame instead
|
|
69
|
+
*/
|
|
70
|
+
var later = isFirefox || typeof idle !== 'function' ? window.requestAnimationFrame : idle;
|
|
71
|
+
later(function () {
|
|
72
|
+
var currentNodeViews = view.props.nodeViews;
|
|
73
|
+
var nextNodeViews = _objectSpread(_objectSpread({}, currentNodeViews), nodeViewsToReplace);
|
|
74
|
+
view.setProps({
|
|
75
|
+
nodeViews: nextNodeViews
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 🧱 Internal: Editor FE Platform
|
|
82
|
+
*/
|
|
83
|
+
var loadedPerEditorView = new WeakMap();
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 🧱 Internal: Editor FE Platform
|
|
87
|
+
*/
|
|
88
|
+
var queueReplaceNodeViews = exports.queueReplaceNodeViews = function queueReplaceNodeViews(view, _ref) {
|
|
89
|
+
var nodeName = _ref.nodeName,
|
|
90
|
+
nodeViewFunc = _ref.nodeViewFunc;
|
|
91
|
+
var nodeViews = loadedPerEditorView.get(view) || {};
|
|
92
|
+
nodeViews[nodeName] = nodeViewFunc;
|
|
93
|
+
loadedPerEditorView.set(view, nodeViews);
|
|
94
|
+
debouncedReplaceNodeviews(loadedPerEditorView, view);
|
|
95
|
+
};
|
|
@@ -17,7 +17,7 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
17
17
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
18
|
var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
|
|
19
19
|
var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
|
|
20
|
-
var packageVersion = "87.0.
|
|
20
|
+
var packageVersion = "87.0.4";
|
|
21
21
|
var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
|
|
22
22
|
// Remove URL as it has UGC
|
|
23
23
|
// TODO: Sanitise the URL instead of just removing it
|
|
@@ -20,12 +20,13 @@ var CodeBlockSharedCssClassName = exports.CodeBlockSharedCssClassName = {
|
|
|
20
20
|
CODEBLOCK_CONTENT_WRAPPER: 'code-block-content-wrapper',
|
|
21
21
|
CODEBLOCK_LINE_NUMBER_GUTTER: 'line-number-gutter',
|
|
22
22
|
CODEBLOCK_CONTENT: 'code-content',
|
|
23
|
-
DS_CODEBLOCK: '[data-ds--code--code-block]'
|
|
23
|
+
DS_CODEBLOCK: '[data-ds--code--code-block]',
|
|
24
|
+
CODEBLOCK_CONTENT_WRAPPED: 'code-content--wrapped'
|
|
24
25
|
};
|
|
25
26
|
var codeBlockSharedStyles = exports.codeBlockSharedStyles = function codeBlockSharedStyles() {
|
|
26
|
-
return (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\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)", _editorSharedStyles.blockNodesVerticalMargin, _editorSharedStyles.akEditorCodeFontFamily, _editorSharedStyles.akEditorTableCellMinWidth, CodeBlockSharedCssClassName.CODEBLOCK_START, CodeBlockSharedCssClassName.CODEBLOCK_END, CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER, "var(--ds-background-neutral, ".concat(_colors.N20, ")"), "var(--ds-border-radius, 3px)", (0, _editorSharedStyles.overflowShadow)({
|
|
27
|
+
return (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\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)", _editorSharedStyles.blockNodesVerticalMargin, _editorSharedStyles.akEditorCodeFontFamily, _editorSharedStyles.akEditorTableCellMinWidth, CodeBlockSharedCssClassName.CODEBLOCK_START, CodeBlockSharedCssClassName.CODEBLOCK_END, CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPER, "var(--ds-background-neutral, ".concat(_colors.N20, ")"), "var(--ds-border-radius, 3px)", (0, _editorSharedStyles.overflowShadow)({
|
|
27
28
|
leftCoverWidth: "var(--ds-space-300, 24px)"
|
|
28
|
-
}), "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(_colors.N30, ")"), "var(--ds-space-100, 8px)", "var(--ds-text-subtlest, ".concat(_colors.N400, ")"), (0, _editorSharedStyles.relativeFontSizeToBase16)((0, _constants.fontSize)()), CodeBlockSharedCssClassName.CODEBLOCK_CONTENT, "var(--ds-text, ".concat(_colors.N800, ")"), "var(--ds-border-radius, 3px)", "var(--ds-space-100, 8px)", (0, _editorSharedStyles.relativeFontSizeToBase16)((0, _constants.fontSize)()));
|
|
29
|
+
}), "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(_colors.N30, ")"), "var(--ds-space-100, 8px)", "var(--ds-text-subtlest, ".concat(_colors.N400, ")"), (0, _editorSharedStyles.relativeFontSizeToBase16)((0, _constants.fontSize)()), CodeBlockSharedCssClassName.CODEBLOCK_CONTENT, "var(--ds-text, ".concat(_colors.N800, ")"), "var(--ds-border-radius, 3px)", "var(--ds-space-100, 8px)", (0, _editorSharedStyles.relativeFontSizeToBase16)((0, _constants.fontSize)()), CodeBlockSharedCssClassName.CODEBLOCK_CONTENT_WRAPPED);
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766
|
|
@@ -23,7 +23,7 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
23
23
|
* @jsx jsx
|
|
24
24
|
*/ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
25
25
|
var packageName = "@atlaskit/editor-common";
|
|
26
|
-
var packageVersion = "87.0.
|
|
26
|
+
var packageVersion = "87.0.4";
|
|
27
27
|
var halfFocusRing = 1;
|
|
28
28
|
var dropOffset = '0, 8';
|
|
29
29
|
var DropList = /*#__PURE__*/function (_Component) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
+
export const defaultWordWrapState = false;
|
|
3
|
+
export const codeBlockWrappedStates = new WeakMap();
|
|
4
|
+
export const isCodeBlockWordWrapEnabled = codeBlockNode => {
|
|
5
|
+
if (!fg('editor_support_code_block_wrapping')) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
const 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 const transferCodeBlockWrappedValue = (oldCodeBlockNode, newCodeBlockNode) => {
|
|
17
|
+
if (!fg('editor_support_code_block_wrapping')) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const previousValue = codeBlockWrappedStates.get(oldCodeBlockNode);
|
|
21
|
+
if (previousValue !== undefined) {
|
|
22
|
+
codeBlockWrappedStates.set(newCodeBlockNode, previousValue);
|
|
23
|
+
codeBlockWrappedStates.delete(oldCodeBlockNode);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { LazyNodeView } from './node-view';
|
|
2
|
+
import { queueReplaceNodeViews } from './replace-node-views';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 📢 Public Type
|
|
@@ -13,123 +13,12 @@ import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
|
13
13
|
* @see {withLazyLoading}
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* 🧱 Internal: Editor FE Platform
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 🧱 Internal: Editor FE Platform
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 🧱 Internal: Editor FE Platform
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
16
|
/**
|
|
29
17
|
* 🧱 Internal: Editor FE Platform
|
|
30
18
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* This cache will help us to avoid any race condition
|
|
34
|
-
* when multiple Editors exist in the same page.
|
|
35
|
-
*
|
|
36
|
-
* @type {CacheType}
|
|
37
|
-
*/
|
|
38
|
-
const cachePerEditorView = new WeakMap();
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 🧱 Internal: Editor FE Platform
|
|
19
|
+
* Controls which node was scheduled to load the original node view code
|
|
42
20
|
*/
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 🧱 Internal: Editor FE Platform
|
|
47
|
-
*
|
|
48
|
-
* A NodeView that serves as a placeholder until the actual NodeView is loaded.
|
|
49
|
-
*/
|
|
50
|
-
class LazyNodeView {
|
|
51
|
-
constructor(node, view, getPos) {
|
|
52
|
-
var _node$type, _node$type$spec;
|
|
53
|
-
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') {
|
|
54
|
-
this.dom = document.createElement('div');
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const fallback = DOMSerializer.renderSpec(document, node.type.spec.toDOM(node));
|
|
58
|
-
this.dom = fallback.dom;
|
|
59
|
-
this.contentDOM = fallback.contentDOM;
|
|
60
|
-
if (this.dom instanceof HTMLElement) {
|
|
61
|
-
// This attribute is mostly used for debugging purposed
|
|
62
|
-
// It will help us to found out when the node was replaced
|
|
63
|
-
this.dom.setAttribute('data-lazy-node-view', node.type.name);
|
|
64
|
-
// This is used on Libra tests
|
|
65
|
-
// We are using this to make sure all lazy noded were replaced
|
|
66
|
-
// before the test started
|
|
67
|
-
this.dom.setAttribute('data-lazy-node-view-fallback', 'true');
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* 🧱 Internal: Editor FE Platform
|
|
74
|
-
*
|
|
75
|
-
* Debounces and replaces the node views in a ProseMirror editor with lazy-loaded node views.
|
|
76
|
-
*
|
|
77
|
-
* This function is used to update the `nodeViews` property of the `EditorView` after lazy-loaded
|
|
78
|
-
* node views have been loaded. It uses a debounced approach to ensure that the replacement does
|
|
79
|
-
* not happen too frequently, which can be performance-intensive.
|
|
80
|
-
*
|
|
81
|
-
* The function checks if there are any loaded node views in the cache associated with the given
|
|
82
|
-
* `EditorView`. If there are, it replaces the current `nodeViews` in the `EditorView` with the
|
|
83
|
-
* loaded node views. The replacement is scheduled using `requestIdleCallback` or
|
|
84
|
-
* `requestAnimationFrame` to avoid blocking the main thread, especially in Firefox where
|
|
85
|
-
* `requestIdleCallback` may not be supported.
|
|
86
|
-
*
|
|
87
|
-
* @param {WeakMap<EditorView, Record<string, NodeViewConstructor>>} cache - A WeakMap that stores
|
|
88
|
-
* the loaded node views for each `EditorView`. The key is the `EditorView`, and the value
|
|
89
|
-
* is a record of node type names to their corresponding `NodeViewConstructor`.
|
|
90
|
-
* @param {EditorView} view - The ProseMirror `EditorView` instance whose `nodeViews` property
|
|
91
|
-
* needs to be updated.
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* const cache = new WeakMap();
|
|
95
|
-
* const view = new EditorView(...);
|
|
96
|
-
*
|
|
97
|
-
* // Assume some node views have been loaded and stored in the cache
|
|
98
|
-
* cache.set(view, {
|
|
99
|
-
* 'table': TableViewConstructor,
|
|
100
|
-
* 'tableCell': TableCellViewConstructor,
|
|
101
|
-
* });
|
|
102
|
-
*
|
|
103
|
-
* debouncedReplaceNodeviews(cache, view);
|
|
104
|
-
*/
|
|
105
|
-
export const debouncedReplaceNodeviews = debounce((cache, view) => {
|
|
106
|
-
const loadedNodeviews = cache.get(view);
|
|
107
|
-
if (!loadedNodeviews) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
cache.delete(view);
|
|
111
|
-
|
|
112
|
-
// eslint-disable-next-line compat/compat
|
|
113
|
-
const idle = window.requestIdleCallback;
|
|
114
|
-
|
|
115
|
-
/*
|
|
116
|
-
* For reasons that goes beyond my knowledge
|
|
117
|
-
* some Firefox versions aren't calling the requestIdleCallback.
|
|
118
|
-
*
|
|
119
|
-
* So, we need this check to make sure we use the requestAnimationFrame instead
|
|
120
|
-
*/
|
|
121
|
-
const later = isFirefox || typeof idle !== 'function' ? window.requestAnimationFrame : idle;
|
|
122
|
-
later(() => {
|
|
123
|
-
const currentNodeViews = view.props.nodeViews;
|
|
124
|
-
const nextNodeViews = {
|
|
125
|
-
...currentNodeViews,
|
|
126
|
-
...loadedNodeviews
|
|
127
|
-
};
|
|
128
|
-
view.setProps({
|
|
129
|
-
nodeViews: nextNodeViews
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
21
|
+
const requestedNodesPerEditorView = new WeakMap();
|
|
133
22
|
|
|
134
23
|
/**
|
|
135
24
|
* 📢 Public: Any EditorPlugin can use this function
|
|
@@ -178,23 +67,26 @@ export const withLazyLoading = ({
|
|
|
178
67
|
dispatchAnalyticsEvent
|
|
179
68
|
}) => {
|
|
180
69
|
const createLazyNodeView = (node, view, getPos, decorations) => {
|
|
181
|
-
var _node$
|
|
182
|
-
let
|
|
183
|
-
if (!
|
|
184
|
-
|
|
185
|
-
cachePerEditorView.set(view, cachedMap);
|
|
70
|
+
var _node$type, _node$type$spec;
|
|
71
|
+
let requestedNodes = requestedNodesPerEditorView.get(view);
|
|
72
|
+
if (!requestedNodes) {
|
|
73
|
+
requestedNodes = new Set(), requestedNodesPerEditorView.set(view, requestedNodes);
|
|
186
74
|
}
|
|
187
|
-
const wasAlreadyRequested =
|
|
75
|
+
const wasAlreadyRequested = requestedNodes.has(nodeName);
|
|
188
76
|
if (wasAlreadyRequested) {
|
|
189
77
|
return new LazyNodeView(node, view, getPos);
|
|
190
78
|
}
|
|
79
|
+
requestedNodes.add(nodeName);
|
|
191
80
|
loader().then(nodeViewFuncModule => {
|
|
192
|
-
|
|
81
|
+
const nodeViewFunc = (node, view, getPos, decorations) => {
|
|
193
82
|
return nodeViewFuncModule(node, view, getPos, decorations, getNodeViewOptions);
|
|
194
83
|
};
|
|
195
|
-
|
|
84
|
+
queueReplaceNodeViews(view, {
|
|
85
|
+
nodeName,
|
|
86
|
+
nodeViewFunc
|
|
87
|
+
});
|
|
196
88
|
});
|
|
197
|
-
if (typeof ((_node$
|
|
89
|
+
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') {
|
|
198
90
|
// TODO: Analytics ED-23982
|
|
199
91
|
// dispatchAnalyticsEvent({
|
|
200
92
|
// action: ACTION.LAZY_NODE_VIEW_ERROR,
|