@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.
Files changed (59) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/cjs/composable-editor/editor-internal.js +57 -1
  3. package/dist/cjs/create-editor/ReactEditorView/formatFullWidthAppearance.js +13 -0
  4. package/dist/cjs/create-editor/ReactEditorView/getUAPrefix.js +19 -0
  5. package/dist/cjs/create-editor/ReactEditorView/handleEditorFocus.js +44 -0
  6. package/dist/cjs/create-editor/ReactEditorView/useDispatchTransaction.js +90 -0
  7. package/dist/cjs/create-editor/ReactEditorView/useFireFullWidthEvent.js +28 -0
  8. package/dist/cjs/create-editor/ReactEditorView/usePluginPerformanceObserver.js +48 -0
  9. package/dist/cjs/create-editor/ReactEditorViewNext.js +538 -0
  10. package/dist/cjs/presets/universal.js +2 -1
  11. package/dist/cjs/ui/Addon/click-area-helper.js +0 -1
  12. package/dist/cjs/version-wrapper.js +1 -1
  13. package/dist/es2019/composable-editor/editor-internal.js +58 -1
  14. package/dist/es2019/create-editor/ReactEditorView/formatFullWidthAppearance.js +7 -0
  15. package/dist/es2019/create-editor/ReactEditorView/getUAPrefix.js +13 -0
  16. package/dist/es2019/create-editor/ReactEditorView/handleEditorFocus.js +38 -0
  17. package/dist/es2019/create-editor/ReactEditorView/useDispatchTransaction.js +82 -0
  18. package/dist/es2019/create-editor/ReactEditorView/useFireFullWidthEvent.js +22 -0
  19. package/dist/es2019/create-editor/ReactEditorView/usePluginPerformanceObserver.js +32 -0
  20. package/dist/es2019/create-editor/ReactEditorViewNext.js +515 -0
  21. package/dist/es2019/presets/universal.js +2 -1
  22. package/dist/es2019/ui/Addon/click-area-helper.js +0 -1
  23. package/dist/es2019/version-wrapper.js +1 -1
  24. package/dist/esm/composable-editor/editor-internal.js +57 -1
  25. package/dist/esm/create-editor/ReactEditorView/formatFullWidthAppearance.js +7 -0
  26. package/dist/esm/create-editor/ReactEditorView/getUAPrefix.js +13 -0
  27. package/dist/esm/create-editor/ReactEditorView/handleEditorFocus.js +38 -0
  28. package/dist/esm/create-editor/ReactEditorView/useDispatchTransaction.js +84 -0
  29. package/dist/esm/create-editor/ReactEditorView/useFireFullWidthEvent.js +22 -0
  30. package/dist/esm/create-editor/ReactEditorView/usePluginPerformanceObserver.js +42 -0
  31. package/dist/esm/create-editor/ReactEditorViewNext.js +528 -0
  32. package/dist/esm/presets/universal.js +2 -1
  33. package/dist/esm/ui/Addon/click-area-helper.js +0 -1
  34. package/dist/esm/version-wrapper.js +1 -1
  35. package/dist/types/create-editor/ReactEditorView/formatFullWidthAppearance.d.ts +3 -0
  36. package/dist/types/create-editor/ReactEditorView/getUAPrefix.d.ts +1 -0
  37. package/dist/types/create-editor/ReactEditorView/handleEditorFocus.d.ts +2 -0
  38. package/dist/types/create-editor/ReactEditorView/useDispatchTransaction.d.ts +12 -0
  39. package/dist/types/create-editor/ReactEditorView/useFireFullWidthEvent.d.ts +3 -0
  40. package/dist/types/create-editor/ReactEditorView/usePluginPerformanceObserver.d.ts +5 -0
  41. package/dist/types/create-editor/ReactEditorViewNext.d.ts +48 -0
  42. package/dist/types/create-editor/create-universal-preset.d.ts +12 -2
  43. package/dist/types/presets/default.d.ts +8 -0
  44. package/dist/types/presets/universal.d.ts +12 -2
  45. package/dist/types/presets/useUniversalPreset.d.ts +12 -2
  46. package/dist/types/types/editor-config.d.ts +1 -2
  47. package/dist/types-ts4.5/create-editor/ReactEditorView/formatFullWidthAppearance.d.ts +3 -0
  48. package/dist/types-ts4.5/create-editor/ReactEditorView/getUAPrefix.d.ts +1 -0
  49. package/dist/types-ts4.5/create-editor/ReactEditorView/handleEditorFocus.d.ts +2 -0
  50. package/dist/types-ts4.5/create-editor/ReactEditorView/useDispatchTransaction.d.ts +12 -0
  51. package/dist/types-ts4.5/create-editor/ReactEditorView/useFireFullWidthEvent.d.ts +3 -0
  52. package/dist/types-ts4.5/create-editor/ReactEditorView/usePluginPerformanceObserver.d.ts +5 -0
  53. package/dist/types-ts4.5/create-editor/ReactEditorViewNext.d.ts +48 -0
  54. package/dist/types-ts4.5/create-editor/create-universal-preset.d.ts +15 -2
  55. package/dist/types-ts4.5/presets/default.d.ts +8 -0
  56. package/dist/types-ts4.5/presets/universal.d.ts +15 -2
  57. package/dist/types-ts4.5/presets/useUniversalPreset.d.ts +15 -2
  58. package/dist/types-ts4.5/types/editor-config.d.ts +1 -2
  59. 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
+ };