@atlaskit/editor-core 201.1.4 → 201.1.6
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 +25 -0
- package/dist/cjs/composable-editor/editor-internal.js +57 -1
- 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/ReactEditorViewNext.js +538 -0
- package/dist/cjs/presets/universal.js +2 -1
- package/dist/cjs/ui/Addon/click-area-helper.js +0 -1
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/composable-editor/editor-internal.js +58 -1
- 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/ReactEditorViewNext.js +515 -0
- package/dist/es2019/presets/universal.js +2 -1
- package/dist/es2019/ui/Addon/click-area-helper.js +0 -1
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/composable-editor/editor-internal.js +57 -1
- 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/ReactEditorViewNext.js +528 -0
- package/dist/esm/presets/universal.js +2 -1
- package/dist/esm/ui/Addon/click-area-helper.js +0 -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 +12 -2
- package/dist/types/presets/default.d.ts +8 -0
- package/dist/types/presets/universal.d.ts +12 -2
- package/dist/types/presets/useUniversalPreset.d.ts +12 -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 +15 -2
- package/dist/types-ts4.5/presets/default.d.ts +8 -0
- package/dist/types-ts4.5/presets/universal.d.ts +15 -2
- package/dist/types-ts4.5/presets/useUniversalPreset.d.ts +15 -2
- package/dist/types-ts4.5/types/editor-config.d.ts +1 -2
- package/package.json +20 -9
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
export function handleEditorFocus(view) {
|
|
3
|
+
if (view.hasFocus()) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
return window.setTimeout(() => {
|
|
7
|
+
if (view.hasFocus()) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (!window.getSelection) {
|
|
11
|
+
view.focus();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const domSelection = window.getSelection();
|
|
15
|
+
if (!domSelection || domSelection.rangeCount === 0) {
|
|
16
|
+
view.focus();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const range = domSelection.getRangeAt(0);
|
|
20
|
+
// if selection is outside editor focus and exit
|
|
21
|
+
if (range.startContainer.contains(view.dom)) {
|
|
22
|
+
view.focus();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// set cursor/selection and focus
|
|
26
|
+
const anchor = view.posAtDOM(range.startContainer, range.startOffset);
|
|
27
|
+
const head = view.posAtDOM(range.endContainer, range.endOffset);
|
|
28
|
+
// if anchor or head < 0 focus and exit
|
|
29
|
+
if (anchor < 0 || head < 0) {
|
|
30
|
+
view.focus();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const selection = TextSelection.create(view.state.doc, anchor, head);
|
|
34
|
+
const tr = view.state.tr.setSelection(selection);
|
|
35
|
+
view.dispatch(tr);
|
|
36
|
+
view.focus();
|
|
37
|
+
}, 0);
|
|
38
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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 const useDispatchTransaction = ({
|
|
10
|
+
onChange,
|
|
11
|
+
dispatchAnalyticsEvent,
|
|
12
|
+
onEditorViewUpdated
|
|
13
|
+
}) => {
|
|
14
|
+
// We need to have a ref to the latest `onChange` since the `dispatchTransaction` gets captured
|
|
15
|
+
const onChangeRef = useRef(onChange);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
onChangeRef.current = onChange;
|
|
18
|
+
}, [onChange]);
|
|
19
|
+
const dispatchTransaction = useCallback((view, unsafeTransaction) => {
|
|
20
|
+
if (!view) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const nodes = findChangedNodesFromTransaction(unsafeTransaction);
|
|
24
|
+
const changedNodesValid = validateNodes(nodes);
|
|
25
|
+
const transaction = new Proxy(unsafeTransaction, freezeUnsafeTransactionProperties({
|
|
26
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
27
|
+
pluginKey: 'unknown-reacteditorview'
|
|
28
|
+
}));
|
|
29
|
+
if (changedNodesValid) {
|
|
30
|
+
const oldEditorState = view.state;
|
|
31
|
+
|
|
32
|
+
// go ahead and update the state now we know the transaction is good
|
|
33
|
+
const {
|
|
34
|
+
state: newEditorState,
|
|
35
|
+
transactions
|
|
36
|
+
} = view.state.applyTransaction(transaction);
|
|
37
|
+
if (newEditorState === oldEditorState) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
view.updateState(newEditorState);
|
|
41
|
+
onEditorViewUpdated({
|
|
42
|
+
originalTransaction: transaction,
|
|
43
|
+
transactions,
|
|
44
|
+
oldEditorState,
|
|
45
|
+
newEditorState
|
|
46
|
+
});
|
|
47
|
+
if (onChangeRef.current && transaction.docChanged) {
|
|
48
|
+
const source = transaction.getMeta('isRemote') ? 'remote' : 'local';
|
|
49
|
+
startMeasure(EVENT_NAME_ON_CHANGE);
|
|
50
|
+
onChangeRef.current(view, {
|
|
51
|
+
source
|
|
52
|
+
});
|
|
53
|
+
stopMeasure(EVENT_NAME_ON_CHANGE, (duration, startTime) => {
|
|
54
|
+
dispatchAnalyticsEvent({
|
|
55
|
+
action: ACTION.ON_CHANGE_CALLBACK,
|
|
56
|
+
actionSubject: ACTION_SUBJECT.EDITOR,
|
|
57
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
58
|
+
attributes: {
|
|
59
|
+
duration,
|
|
60
|
+
startTime
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return newEditorState;
|
|
66
|
+
} else {
|
|
67
|
+
const invalidNodes = nodes.filter(node => !validNode(node)).map(node => getDocStructure(node, {
|
|
68
|
+
compact: true
|
|
69
|
+
}));
|
|
70
|
+
dispatchAnalyticsEvent({
|
|
71
|
+
action: ACTION.DISPATCHED_INVALID_TRANSACTION,
|
|
72
|
+
actionSubject: ACTION_SUBJECT.EDITOR,
|
|
73
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
74
|
+
attributes: {
|
|
75
|
+
analyticsEventPayloads: getAnalyticsEventsFromTransaction(transaction),
|
|
76
|
+
invalidNodes
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}, [dispatchAnalyticsEvent, onEditorViewUpdated]);
|
|
81
|
+
return dispatchTransaction;
|
|
82
|
+
};
|
|
@@ -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 const useFireFullWidthEvent = (appearance, dispatchAnalyticsEvent) => {
|
|
6
|
+
const previousAppearance = usePreviousState(appearance);
|
|
7
|
+
useEffect(() => {
|
|
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,32 @@
|
|
|
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 const usePluginPerformanceObserver = (editorState, pluginInjectionAPI, dispatchAnalyticsEvent) => {
|
|
6
|
+
const onPluginObservation = useCallback(report => {
|
|
7
|
+
var _pluginInjectionAPI$c, _pluginInjectionAPI$c2, _pluginInjectionAPI$c3, _pluginInjectionAPI$c4;
|
|
8
|
+
dispatchAnalyticsEvent({
|
|
9
|
+
action: ACTION.TRANSACTION_DISPATCHED,
|
|
10
|
+
actionSubject: ACTION_SUBJECT.EDITOR,
|
|
11
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
12
|
+
attributes: {
|
|
13
|
+
report,
|
|
14
|
+
participants: ((_pluginInjectionAPI$c = pluginInjectionAPI.current) === null || _pluginInjectionAPI$c === void 0 ? void 0 : (_pluginInjectionAPI$c2 = _pluginInjectionAPI$c.api().collabEdit) === null || _pluginInjectionAPI$c2 === void 0 ? void 0 : (_pluginInjectionAPI$c3 = _pluginInjectionAPI$c2.sharedState.currentState()) === null || _pluginInjectionAPI$c3 === void 0 ? void 0 : (_pluginInjectionAPI$c4 = _pluginInjectionAPI$c3.participants) === null || _pluginInjectionAPI$c4 === void 0 ? void 0 : _pluginInjectionAPI$c4.size()) || 1
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}, [dispatchAnalyticsEvent, pluginInjectionAPI]);
|
|
18
|
+
const getPluginNames = useCallback(() => {
|
|
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(p => p.key);
|
|
22
|
+
}, [editorState]);
|
|
23
|
+
const pluginPerformanceObserver = useMemo(() => new PluginPerformanceObserver(report => onPluginObservation(report)).withPlugins(() => getPluginNames()).withNodeCounts(() => editorState.current ? countNodes(editorState.current) : {
|
|
24
|
+
nodeCount: {},
|
|
25
|
+
extensionNodeCount: {}
|
|
26
|
+
}), [onPluginObservation, getPluginNames, editorState]);
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
return () => {
|
|
29
|
+
pluginPerformanceObserver.disconnect();
|
|
30
|
+
};
|
|
31
|
+
}, [pluginPerformanceObserver]);
|
|
32
|
+
};
|