@atlaskit/editor-core 201.1.5 → 201.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/cjs/composable-editor/editor-internal.js +60 -2
- package/dist/cjs/create-editor/ReactEditorView/formatFullWidthAppearance.js +13 -0
- package/dist/cjs/create-editor/ReactEditorView/getUAPrefix.js +19 -0
- package/dist/cjs/create-editor/ReactEditorView/handleEditorFocus.js +44 -0
- package/dist/cjs/create-editor/ReactEditorView/useDispatchTransaction.js +90 -0
- package/dist/cjs/create-editor/ReactEditorView/useFireFullWidthEvent.js +28 -0
- package/dist/cjs/create-editor/ReactEditorView/usePluginPerformanceObserver.js +48 -0
- package/dist/cjs/create-editor/ReactEditorView.js +2 -1
- package/dist/cjs/create-editor/ReactEditorViewNext.js +538 -0
- package/dist/cjs/presets/universal.js +2 -1
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/composable-editor/editor-internal.js +61 -2
- package/dist/es2019/create-editor/ReactEditorView/formatFullWidthAppearance.js +7 -0
- package/dist/es2019/create-editor/ReactEditorView/getUAPrefix.js +13 -0
- package/dist/es2019/create-editor/ReactEditorView/handleEditorFocus.js +38 -0
- package/dist/es2019/create-editor/ReactEditorView/useDispatchTransaction.js +82 -0
- package/dist/es2019/create-editor/ReactEditorView/useFireFullWidthEvent.js +22 -0
- package/dist/es2019/create-editor/ReactEditorView/usePluginPerformanceObserver.js +32 -0
- package/dist/es2019/create-editor/ReactEditorView.js +2 -1
- package/dist/es2019/create-editor/ReactEditorViewNext.js +515 -0
- package/dist/es2019/presets/universal.js +2 -1
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/composable-editor/editor-internal.js +60 -2
- package/dist/esm/create-editor/ReactEditorView/formatFullWidthAppearance.js +7 -0
- package/dist/esm/create-editor/ReactEditorView/getUAPrefix.js +13 -0
- package/dist/esm/create-editor/ReactEditorView/handleEditorFocus.js +38 -0
- package/dist/esm/create-editor/ReactEditorView/useDispatchTransaction.js +84 -0
- package/dist/esm/create-editor/ReactEditorView/useFireFullWidthEvent.js +22 -0
- package/dist/esm/create-editor/ReactEditorView/usePluginPerformanceObserver.js +42 -0
- package/dist/esm/create-editor/ReactEditorView.js +2 -1
- package/dist/esm/create-editor/ReactEditorViewNext.js +528 -0
- package/dist/esm/presets/universal.js +2 -1
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/create-editor/ReactEditorView/formatFullWidthAppearance.d.ts +3 -0
- package/dist/types/create-editor/ReactEditorView/getUAPrefix.d.ts +1 -0
- package/dist/types/create-editor/ReactEditorView/handleEditorFocus.d.ts +2 -0
- package/dist/types/create-editor/ReactEditorView/useDispatchTransaction.d.ts +12 -0
- package/dist/types/create-editor/ReactEditorView/useFireFullWidthEvent.d.ts +3 -0
- package/dist/types/create-editor/ReactEditorView/usePluginPerformanceObserver.d.ts +5 -0
- package/dist/types/create-editor/ReactEditorViewNext.d.ts +48 -0
- package/dist/types/create-editor/create-universal-preset.d.ts +8 -2
- package/dist/types/presets/universal.d.ts +8 -2
- package/dist/types/presets/useUniversalPreset.d.ts +8 -2
- package/dist/types/types/editor-config.d.ts +1 -2
- package/dist/types-ts4.5/create-editor/ReactEditorView/formatFullWidthAppearance.d.ts +3 -0
- package/dist/types-ts4.5/create-editor/ReactEditorView/getUAPrefix.d.ts +1 -0
- package/dist/types-ts4.5/create-editor/ReactEditorView/handleEditorFocus.d.ts +2 -0
- package/dist/types-ts4.5/create-editor/ReactEditorView/useDispatchTransaction.d.ts +12 -0
- package/dist/types-ts4.5/create-editor/ReactEditorView/useFireFullWidthEvent.d.ts +3 -0
- package/dist/types-ts4.5/create-editor/ReactEditorView/usePluginPerformanceObserver.d.ts +5 -0
- package/dist/types-ts4.5/create-editor/ReactEditorViewNext.d.ts +48 -0
- package/dist/types-ts4.5/create-editor/create-universal-preset.d.ts +11 -2
- package/dist/types-ts4.5/presets/universal.d.ts +11 -2
- package/dist/types-ts4.5/presets/useUniversalPreset.d.ts +11 -2
- package/dist/types-ts4.5/types/editor-config.d.ts +1 -2
- package/package.json +14 -4
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, getAnalyticsEventsFromTransaction } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import { getDocStructure } from '@atlaskit/editor-common/core-utils';
|
|
4
|
+
import { startMeasure, stopMeasure } from '@atlaskit/editor-common/performance-measures';
|
|
5
|
+
import { findChangedNodesFromTransaction } from '../../utils/findChangedNodesFromTransaction';
|
|
6
|
+
import { freezeUnsafeTransactionProperties } from '../../utils/performance/safer-transactions';
|
|
7
|
+
import { EVENT_NAME_ON_CHANGE } from '../../utils/performance/track-transactions';
|
|
8
|
+
import { validateNodes, validNode } from '../../utils/validateNodes';
|
|
9
|
+
export var useDispatchTransaction = function useDispatchTransaction(_ref) {
|
|
10
|
+
var onChange = _ref.onChange,
|
|
11
|
+
dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
|
|
12
|
+
onEditorViewUpdated = _ref.onEditorViewUpdated;
|
|
13
|
+
// We need to have a ref to the latest `onChange` since the `dispatchTransaction` gets captured
|
|
14
|
+
var onChangeRef = useRef(onChange);
|
|
15
|
+
useEffect(function () {
|
|
16
|
+
onChangeRef.current = onChange;
|
|
17
|
+
}, [onChange]);
|
|
18
|
+
var dispatchTransaction = useCallback(function (view, unsafeTransaction) {
|
|
19
|
+
if (!view) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
var nodes = findChangedNodesFromTransaction(unsafeTransaction);
|
|
23
|
+
var changedNodesValid = validateNodes(nodes);
|
|
24
|
+
var transaction = new Proxy(unsafeTransaction, freezeUnsafeTransactionProperties({
|
|
25
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
26
|
+
pluginKey: 'unknown-reacteditorview'
|
|
27
|
+
}));
|
|
28
|
+
if (changedNodesValid) {
|
|
29
|
+
var oldEditorState = view.state;
|
|
30
|
+
|
|
31
|
+
// go ahead and update the state now we know the transaction is good
|
|
32
|
+
var _view$state$applyTran = view.state.applyTransaction(transaction),
|
|
33
|
+
newEditorState = _view$state$applyTran.state,
|
|
34
|
+
transactions = _view$state$applyTran.transactions;
|
|
35
|
+
if (newEditorState === oldEditorState) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
view.updateState(newEditorState);
|
|
39
|
+
onEditorViewUpdated({
|
|
40
|
+
originalTransaction: transaction,
|
|
41
|
+
transactions: transactions,
|
|
42
|
+
oldEditorState: oldEditorState,
|
|
43
|
+
newEditorState: newEditorState
|
|
44
|
+
});
|
|
45
|
+
if (onChangeRef.current && transaction.docChanged) {
|
|
46
|
+
var source = transaction.getMeta('isRemote') ? 'remote' : 'local';
|
|
47
|
+
startMeasure(EVENT_NAME_ON_CHANGE);
|
|
48
|
+
onChangeRef.current(view, {
|
|
49
|
+
source: source
|
|
50
|
+
});
|
|
51
|
+
stopMeasure(EVENT_NAME_ON_CHANGE, function (duration, startTime) {
|
|
52
|
+
dispatchAnalyticsEvent({
|
|
53
|
+
action: ACTION.ON_CHANGE_CALLBACK,
|
|
54
|
+
actionSubject: ACTION_SUBJECT.EDITOR,
|
|
55
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
56
|
+
attributes: {
|
|
57
|
+
duration: duration,
|
|
58
|
+
startTime: startTime
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return newEditorState;
|
|
64
|
+
} else {
|
|
65
|
+
var invalidNodes = nodes.filter(function (node) {
|
|
66
|
+
return !validNode(node);
|
|
67
|
+
}).map(function (node) {
|
|
68
|
+
return getDocStructure(node, {
|
|
69
|
+
compact: true
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
dispatchAnalyticsEvent({
|
|
73
|
+
action: ACTION.DISPATCHED_INVALID_TRANSACTION,
|
|
74
|
+
actionSubject: ACTION_SUBJECT.EDITOR,
|
|
75
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
76
|
+
attributes: {
|
|
77
|
+
analyticsEventPayloads: getAnalyticsEventsFromTransaction(transaction),
|
|
78
|
+
invalidNodes: invalidNodes
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}, [dispatchAnalyticsEvent, onEditorViewUpdated]);
|
|
83
|
+
return dispatchTransaction;
|
|
84
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import { usePreviousState } from '@atlaskit/editor-common/hooks';
|
|
4
|
+
import { formatFullWidthAppearance } from './formatFullWidthAppearance';
|
|
5
|
+
export var useFireFullWidthEvent = function useFireFullWidthEvent(appearance, dispatchAnalyticsEvent) {
|
|
6
|
+
var previousAppearance = usePreviousState(appearance);
|
|
7
|
+
useEffect(function () {
|
|
8
|
+
if (appearance !== previousAppearance) {
|
|
9
|
+
if (appearance === 'full-width' || previousAppearance === 'full-width') {
|
|
10
|
+
dispatchAnalyticsEvent({
|
|
11
|
+
action: ACTION.CHANGED_FULL_WIDTH_MODE,
|
|
12
|
+
actionSubject: ACTION_SUBJECT.EDITOR,
|
|
13
|
+
eventType: EVENT_TYPE.TRACK,
|
|
14
|
+
attributes: {
|
|
15
|
+
previousMode: formatFullWidthAppearance(previousAppearance),
|
|
16
|
+
newMode: formatFullWidthAppearance(appearance)
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}, [appearance, previousAppearance, dispatchAnalyticsEvent]);
|
|
22
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useMemo } from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import { countNodes } from '@atlaskit/editor-common/count-nodes';
|
|
4
|
+
import { PluginPerformanceObserver } from '../../utils/performance/plugin-performance-observer';
|
|
5
|
+
export var usePluginPerformanceObserver = function usePluginPerformanceObserver(editorState, pluginInjectionAPI, dispatchAnalyticsEvent) {
|
|
6
|
+
var onPluginObservation = useCallback(function (report) {
|
|
7
|
+
var _pluginInjectionAPI$c;
|
|
8
|
+
dispatchAnalyticsEvent({
|
|
9
|
+
action: ACTION.TRANSACTION_DISPATCHED,
|
|
10
|
+
actionSubject: ACTION_SUBJECT.EDITOR,
|
|
11
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
12
|
+
attributes: {
|
|
13
|
+
report: report,
|
|
14
|
+
participants: ((_pluginInjectionAPI$c = pluginInjectionAPI.current) === null || _pluginInjectionAPI$c === void 0 || (_pluginInjectionAPI$c = _pluginInjectionAPI$c.api().collabEdit) === null || _pluginInjectionAPI$c === void 0 || (_pluginInjectionAPI$c = _pluginInjectionAPI$c.sharedState.currentState()) === null || _pluginInjectionAPI$c === void 0 || (_pluginInjectionAPI$c = _pluginInjectionAPI$c.participants) === null || _pluginInjectionAPI$c === void 0 ? void 0 : _pluginInjectionAPI$c.size()) || 1
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}, [dispatchAnalyticsEvent, pluginInjectionAPI]);
|
|
18
|
+
var getPluginNames = useCallback(function () {
|
|
19
|
+
var _editorState$current;
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
return (_editorState$current = editorState.current) === null || _editorState$current === void 0 ? void 0 : _editorState$current.plugins.map(function (p) {
|
|
22
|
+
return p.key;
|
|
23
|
+
});
|
|
24
|
+
}, [editorState]);
|
|
25
|
+
var pluginPerformanceObserver = useMemo(function () {
|
|
26
|
+
return new PluginPerformanceObserver(function (report) {
|
|
27
|
+
return onPluginObservation(report);
|
|
28
|
+
}).withPlugins(function () {
|
|
29
|
+
return getPluginNames();
|
|
30
|
+
}).withNodeCounts(function () {
|
|
31
|
+
return editorState.current ? countNodes(editorState.current) : {
|
|
32
|
+
nodeCount: {},
|
|
33
|
+
extensionNodeCount: {}
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}, [onPluginObservation, getPluginNames, editorState]);
|
|
37
|
+
useLayoutEffect(function () {
|
|
38
|
+
return function () {
|
|
39
|
+
pluginPerformanceObserver.disconnect();
|
|
40
|
+
};
|
|
41
|
+
}, [pluginPerformanceObserver]);
|
|
42
|
+
};
|
|
@@ -647,7 +647,8 @@ export var ReactEditorView = /*#__PURE__*/function (_React$Component) {
|
|
|
647
647
|
key: "render",
|
|
648
648
|
value: function render() {
|
|
649
649
|
var _this$props$render, _this$props$render2, _this$props;
|
|
650
|
-
|
|
650
|
+
// Render tracking is firing too many events in Jira so we are disabling them for now. See - https://product-fabric.atlassian.net/browse/ED-25616
|
|
651
|
+
var renderTrackingEnabled = !fg('platform_editor_disable_rerender_tracking_jira');
|
|
651
652
|
var useShallow = true;
|
|
652
653
|
return /*#__PURE__*/React.createElement(ReactEditorViewContext.Provider, {
|
|
653
654
|
value: {
|