@atlaskit/editor-common 88.6.1 → 88.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/cjs/analytics/fire-analytics-event.js +2 -2
- package/dist/cjs/element-browser/components/CategoryList.js +2 -2
- package/dist/cjs/element-browser/components/ElementList/ElementList.js +2 -2
- package/dist/cjs/element-browser/components/ElementSearch.js +2 -2
- package/dist/cjs/element-browser/components/StatelessElementBrowser.js +4 -3
- package/dist/cjs/lazy-node-view/index.js +89 -11
- package/dist/cjs/lazy-node-view/node-view.js +27 -7
- package/dist/cjs/link/ConfigureLinkOverlay/Dropdown.js +2 -2
- package/dist/cjs/link/ConfigureLinkOverlay/index.js +2 -2
- package/dist/cjs/link/ConfigureLinkOverlay/useLinkOverlayAnalyticsEvents.js +6 -6
- package/dist/cjs/link/LinkPicker/EditorLinkPicker/index.js +2 -2
- package/dist/cjs/link/LinkPicker/HyperlinkAddToolbar/HyperlinkAddToolbar.js +2 -2
- package/dist/cjs/media-inline/media-inline-image-card.js +2 -2
- package/dist/cjs/monitoring/error.js +1 -1
- package/dist/cjs/ui/DropList/index.js +7 -5
- package/dist/cjs/ui/WithCreateAnalyticsEvent/index.js +2 -2
- package/dist/cjs/ui-menu/ColorPickerButton/index.js +4 -3
- package/dist/cjs/ui-menu/ToolbarButton/index.js +2 -2
- package/dist/es2019/analytics/fire-analytics-event.js +1 -1
- package/dist/es2019/element-browser/components/CategoryList.js +1 -1
- package/dist/es2019/element-browser/components/ElementList/ElementList.js +1 -1
- package/dist/es2019/element-browser/components/ElementSearch.js +1 -1
- package/dist/es2019/element-browser/components/StatelessElementBrowser.js +2 -1
- package/dist/es2019/lazy-node-view/index.js +81 -11
- package/dist/es2019/lazy-node-view/node-view.js +25 -6
- package/dist/es2019/link/ConfigureLinkOverlay/Dropdown.js +1 -1
- package/dist/es2019/link/ConfigureLinkOverlay/index.js +1 -1
- package/dist/es2019/link/ConfigureLinkOverlay/useLinkOverlayAnalyticsEvents.js +2 -2
- package/dist/es2019/link/LinkPicker/EditorLinkPicker/index.js +1 -1
- package/dist/es2019/link/LinkPicker/HyperlinkAddToolbar/HyperlinkAddToolbar.js +1 -1
- package/dist/es2019/media-inline/media-inline-image-card.js +1 -1
- package/dist/es2019/monitoring/error.js +1 -1
- package/dist/es2019/ui/DropList/index.js +4 -2
- package/dist/es2019/ui/WithCreateAnalyticsEvent/index.js +1 -1
- package/dist/es2019/ui-menu/ColorPickerButton/index.js +2 -1
- package/dist/es2019/ui-menu/ToolbarButton/index.js +1 -1
- package/dist/esm/analytics/fire-analytics-event.js +1 -1
- package/dist/esm/element-browser/components/CategoryList.js +1 -1
- package/dist/esm/element-browser/components/ElementList/ElementList.js +1 -1
- package/dist/esm/element-browser/components/ElementSearch.js +1 -1
- package/dist/esm/element-browser/components/StatelessElementBrowser.js +2 -1
- package/dist/esm/lazy-node-view/index.js +85 -11
- package/dist/esm/lazy-node-view/node-view.js +27 -7
- package/dist/esm/link/ConfigureLinkOverlay/Dropdown.js +1 -1
- package/dist/esm/link/ConfigureLinkOverlay/index.js +1 -1
- package/dist/esm/link/ConfigureLinkOverlay/useLinkOverlayAnalyticsEvents.js +2 -2
- package/dist/esm/link/LinkPicker/EditorLinkPicker/index.js +1 -1
- package/dist/esm/link/LinkPicker/HyperlinkAddToolbar/HyperlinkAddToolbar.js +1 -1
- package/dist/esm/media-inline/media-inline-image-card.js +1 -1
- package/dist/esm/monitoring/error.js +1 -1
- package/dist/esm/ui/DropList/index.js +4 -2
- package/dist/esm/ui/WithCreateAnalyticsEvent/index.js +1 -1
- package/dist/esm/ui-menu/ColorPickerButton/index.js +2 -1
- package/dist/esm/ui-menu/ToolbarButton/index.js +1 -1
- package/dist/types/analytics/fire-analytics-event.d.ts +1 -1
- package/dist/types/analytics/types/events.d.ts +1 -1
- package/dist/types/element-browser/components/ElementSearch.d.ts +1 -1
- package/dist/types/lazy-node-view/index.d.ts +18 -1
- package/dist/types/lazy-node-view/node-view.d.ts +4 -5
- package/dist/types/link/ConfigureLinkOverlay/Dropdown.d.ts +1 -1
- package/dist/types/link/ConfigureLinkOverlay/index.d.ts +1 -1
- package/dist/types-ts4.5/analytics/fire-analytics-event.d.ts +1 -1
- package/dist/types-ts4.5/analytics/types/events.d.ts +1 -1
- package/dist/types-ts4.5/element-browser/components/ElementSearch.d.ts +1 -1
- package/dist/types-ts4.5/lazy-node-view/index.d.ts +18 -1
- package/dist/types-ts4.5/lazy-node-view/node-view.d.ts +4 -5
- package/dist/types-ts4.5/link/ConfigureLinkOverlay/Dropdown.d.ts +1 -1
- package/dist/types-ts4.5/link/ConfigureLinkOverlay/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/lazy-node-view/replace-node-views.js +0 -173
- package/dist/es2019/lazy-node-view/replace-node-views.js +0 -166
- package/dist/esm/lazy-node-view/replace-node-views.js +0 -166
- package/dist/types/lazy-node-view/replace-node-views.d.ts +0 -34
- package/dist/types-ts4.5/lazy-node-view/replace-node-views.d.ts +0 -34
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
import debounce from 'lodash/debounce';
|
|
5
|
-
import memoize from 'lodash/memoize';
|
|
6
|
-
/**
|
|
7
|
-
* 🧱 Internal: Editor FE Platform
|
|
8
|
-
*/
|
|
9
|
-
var isFirefox = /gecko\/\d/i.test(navigator.userAgent);
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 🧱 Internal: Editor FE Platform
|
|
13
|
-
*
|
|
14
|
-
* Replaces the node views in a ProseMirror editor with lazy-loaded node views.
|
|
15
|
-
*
|
|
16
|
-
* This function is used to update the `nodeViews` property of the `EditorView` after lazy-loaded
|
|
17
|
-
* node views have been loaded.
|
|
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
|
-
* replaceNodeViews(cache, view);
|
|
42
|
-
*/
|
|
43
|
-
var replaceNodeViews = function replaceNodeViews(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
|
-
var callback = function callback() {
|
|
54
|
-
var currentNodeViews = view.props.nodeViews;
|
|
55
|
-
var nextNodeViews = _objectSpread(_objectSpread({}, currentNodeViews), nodeViewsToReplace);
|
|
56
|
-
view.setProps({
|
|
57
|
-
nodeViews: nextNodeViews
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
// eslint-disable-next-line compat/compat
|
|
61
|
-
var idle = window.requestIdleCallback;
|
|
62
|
-
|
|
63
|
-
/*
|
|
64
|
-
* For reasons that goes beyond my knowledge
|
|
65
|
-
* some Firefox versions aren't calling the requestIdleCallback.
|
|
66
|
-
*
|
|
67
|
-
* So, we need this check to make sure we are using the requestAnimationFrame for Firefox
|
|
68
|
-
*/
|
|
69
|
-
if (isFirefox || typeof idle !== 'function') {
|
|
70
|
-
window.requestAnimationFrame(callback);
|
|
71
|
-
} else {
|
|
72
|
-
idle(callback, {
|
|
73
|
-
timeout: 2000
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 🧱 Internal: Editor FE Platform
|
|
80
|
-
*/
|
|
81
|
-
var loadedPerEditorView = new WeakMap();
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* 🧱 Internal: Editor FE Platform
|
|
85
|
-
* Based on https://github.com/lodash/lodash/issues/2403#issuecomment-1706130395
|
|
86
|
-
*
|
|
87
|
-
* Creates a debounced function that delays invoking the provided function until after a specified
|
|
88
|
-
* wait time has elapsed since the last time the debounced function was invoked. Additionally, the
|
|
89
|
-
* debounced function is memoized so that the same function instance is used for each unique set
|
|
90
|
-
* of arguments based on the resolver.
|
|
91
|
-
*
|
|
92
|
-
* This is particularly useful in scenarios where you want to debounce function calls while ensuring
|
|
93
|
-
* that each unique input combination receives its own debounced function instance. It's a combination
|
|
94
|
-
* of lodash's `debounce` and `memoize`.
|
|
95
|
-
*
|
|
96
|
-
* @template T
|
|
97
|
-
* @param {T} func - The function to debounce.
|
|
98
|
-
* @param {number} [wait=0] - The number of milliseconds to delay.
|
|
99
|
-
* @param {Object} [options] - The options object to pass to `debounce`.
|
|
100
|
-
* @param {Function} [resolver] - The function to resolve the cache key for memoization.
|
|
101
|
-
* @returns {Function} A new debounced and memoized function.
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* const debouncedFunction = memoizeDebounce(myFunction, 300, { leading: true }, myResolver);
|
|
105
|
-
* debouncedFunction(arg1, arg2);
|
|
106
|
-
*/
|
|
107
|
-
function memoizeDebounce(func) {
|
|
108
|
-
var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
109
|
-
var options = arguments.length > 2 ? arguments[2] : undefined;
|
|
110
|
-
var resolver = arguments.length > 3 ? arguments[3] : undefined;
|
|
111
|
-
var mem = memoize(function () {
|
|
112
|
-
return debounce(func, wait, options);
|
|
113
|
-
}, resolver);
|
|
114
|
-
return function () {
|
|
115
|
-
return mem.apply(void 0, arguments).apply(void 0, arguments);
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* 🧱 Internal: Editor FE Platform
|
|
121
|
-
*
|
|
122
|
-
* Debounced and memoized version of `replaceNodeViews`.
|
|
123
|
-
*
|
|
124
|
-
* This function is designed to update the `nodeViews` property of an `EditorView` after a
|
|
125
|
-
* period of inactivity (debounce), ensuring that multiple rapid updates do not occur in quick
|
|
126
|
-
* succession. It uses lodash's `debounce` to handle the debouncing.
|
|
127
|
-
*
|
|
128
|
-
* Memoization is crucial here to ensure that each `EditorView` instance has its own opportunity
|
|
129
|
-
* to update the node views. Without memoization, if you have multiple `EditorView` instances on
|
|
130
|
-
* the same page, only one instance would potentially call `view.setProps`, which could lead to
|
|
131
|
-
* incorrect or missing updates in other `EditorView` instances. By memoizing the debounced function,
|
|
132
|
-
* we ensure that each `EditorView` maintains its own debounced update logic.
|
|
133
|
-
*
|
|
134
|
-
* @param {CacheLoadedReactNodeViews} cache - A WeakMap that stores the loaded node views for each
|
|
135
|
-
* `EditorView`. The key is the `EditorView`, and the value is a record of node type names
|
|
136
|
-
* to their corresponding `NodeViewConstructor`.
|
|
137
|
-
* @param {EditorView} view - The ProseMirror `EditorView` instance whose `nodeViews` property
|
|
138
|
-
* needs to be updated.
|
|
139
|
-
*
|
|
140
|
-
* This function is typically not called directly. Instead, it is invoked through `queueReplaceNodeViews`,
|
|
141
|
-
* which handles adding node views to the cache and triggering this debounced update.
|
|
142
|
-
*/
|
|
143
|
-
export var debouncedReplaceNodeviews = memoizeDebounce(replaceNodeViews, 0,
|
|
144
|
-
/**
|
|
145
|
-
* Use the default debounce options:
|
|
146
|
-
* {leading: false, trailing: true}
|
|
147
|
-
*/
|
|
148
|
-
undefined, function (cache, view) {
|
|
149
|
-
/**
|
|
150
|
-
* EditorView is a singleton.
|
|
151
|
-
* There is only one instance per Editor.
|
|
152
|
-
*/
|
|
153
|
-
return view;
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* 🧱 Internal: Editor FE Platform
|
|
158
|
-
*/
|
|
159
|
-
export var queueReplaceNodeViews = function queueReplaceNodeViews(view, _ref) {
|
|
160
|
-
var nodeName = _ref.nodeName,
|
|
161
|
-
nodeViewFunc = _ref.nodeViewFunc;
|
|
162
|
-
var nodeViews = loadedPerEditorView.get(view) || {};
|
|
163
|
-
nodeViews[nodeName] = nodeViewFunc;
|
|
164
|
-
loadedPerEditorView.set(view, nodeViews);
|
|
165
|
-
debouncedReplaceNodeviews(loadedPerEditorView, view);
|
|
166
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
2
|
-
import type { CacheLoadedReactNodeViews, NodeViewConstructor } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* 🧱 Internal: Editor FE Platform
|
|
5
|
-
*
|
|
6
|
-
* Debounced and memoized version of `replaceNodeViews`.
|
|
7
|
-
*
|
|
8
|
-
* This function is designed to update the `nodeViews` property of an `EditorView` after a
|
|
9
|
-
* period of inactivity (debounce), ensuring that multiple rapid updates do not occur in quick
|
|
10
|
-
* succession. It uses lodash's `debounce` to handle the debouncing.
|
|
11
|
-
*
|
|
12
|
-
* Memoization is crucial here to ensure that each `EditorView` instance has its own opportunity
|
|
13
|
-
* to update the node views. Without memoization, if you have multiple `EditorView` instances on
|
|
14
|
-
* the same page, only one instance would potentially call `view.setProps`, which could lead to
|
|
15
|
-
* incorrect or missing updates in other `EditorView` instances. By memoizing the debounced function,
|
|
16
|
-
* we ensure that each `EditorView` maintains its own debounced update logic.
|
|
17
|
-
*
|
|
18
|
-
* @param {CacheLoadedReactNodeViews} cache - A WeakMap that stores the loaded node views for each
|
|
19
|
-
* `EditorView`. The key is the `EditorView`, and the value is a record of node type names
|
|
20
|
-
* to their corresponding `NodeViewConstructor`.
|
|
21
|
-
* @param {EditorView} view - The ProseMirror `EditorView` instance whose `nodeViews` property
|
|
22
|
-
* needs to be updated.
|
|
23
|
-
*
|
|
24
|
-
* This function is typically not called directly. Instead, it is invoked through `queueReplaceNodeViews`,
|
|
25
|
-
* which handles adding node views to the cache and triggering this debounced update.
|
|
26
|
-
*/
|
|
27
|
-
export declare const debouncedReplaceNodeviews: (cache: CacheLoadedReactNodeViews, view: EditorView) => void | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* 🧱 Internal: Editor FE Platform
|
|
30
|
-
*/
|
|
31
|
-
export declare const queueReplaceNodeViews: (view: EditorView, { nodeName, nodeViewFunc }: {
|
|
32
|
-
nodeName: string;
|
|
33
|
-
nodeViewFunc: NodeViewConstructor;
|
|
34
|
-
}) => void;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
2
|
-
import type { CacheLoadedReactNodeViews, NodeViewConstructor } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* 🧱 Internal: Editor FE Platform
|
|
5
|
-
*
|
|
6
|
-
* Debounced and memoized version of `replaceNodeViews`.
|
|
7
|
-
*
|
|
8
|
-
* This function is designed to update the `nodeViews` property of an `EditorView` after a
|
|
9
|
-
* period of inactivity (debounce), ensuring that multiple rapid updates do not occur in quick
|
|
10
|
-
* succession. It uses lodash's `debounce` to handle the debouncing.
|
|
11
|
-
*
|
|
12
|
-
* Memoization is crucial here to ensure that each `EditorView` instance has its own opportunity
|
|
13
|
-
* to update the node views. Without memoization, if you have multiple `EditorView` instances on
|
|
14
|
-
* the same page, only one instance would potentially call `view.setProps`, which could lead to
|
|
15
|
-
* incorrect or missing updates in other `EditorView` instances. By memoizing the debounced function,
|
|
16
|
-
* we ensure that each `EditorView` maintains its own debounced update logic.
|
|
17
|
-
*
|
|
18
|
-
* @param {CacheLoadedReactNodeViews} cache - A WeakMap that stores the loaded node views for each
|
|
19
|
-
* `EditorView`. The key is the `EditorView`, and the value is a record of node type names
|
|
20
|
-
* to their corresponding `NodeViewConstructor`.
|
|
21
|
-
* @param {EditorView} view - The ProseMirror `EditorView` instance whose `nodeViews` property
|
|
22
|
-
* needs to be updated.
|
|
23
|
-
*
|
|
24
|
-
* This function is typically not called directly. Instead, it is invoked through `queueReplaceNodeViews`,
|
|
25
|
-
* which handles adding node views to the cache and triggering this debounced update.
|
|
26
|
-
*/
|
|
27
|
-
export declare const debouncedReplaceNodeviews: (cache: CacheLoadedReactNodeViews, view: EditorView) => void | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* 🧱 Internal: Editor FE Platform
|
|
30
|
-
*/
|
|
31
|
-
export declare const queueReplaceNodeViews: (view: EditorView, { nodeName, nodeViewFunc }: {
|
|
32
|
-
nodeName: string;
|
|
33
|
-
nodeViewFunc: NodeViewConstructor;
|
|
34
|
-
}) => void;
|