@atlaskit/editor-core 190.1.20 → 190.1.23

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 (120) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/dist/cjs/index.js +1 -1
  4. package/dist/cjs/plugins/index.js +0 -7
  5. package/dist/cjs/plugins/paste/pm-plugins/main.js +14 -10
  6. package/dist/cjs/presets/default.js +2 -2
  7. package/dist/cjs/presets/universal.js +2 -1
  8. package/dist/cjs/utils/index.js +12 -18
  9. package/dist/cjs/utils/performance/measure-enum.js +1 -2
  10. package/dist/cjs/version-wrapper.js +1 -1
  11. package/dist/es2019/index.js +14 -1
  12. package/dist/es2019/plugins/index.js +0 -1
  13. package/dist/es2019/plugins/paste/pm-plugins/main.js +11 -5
  14. package/dist/es2019/presets/default.js +1 -1
  15. package/dist/es2019/presets/universal.js +2 -1
  16. package/dist/es2019/utils/index.js +0 -7
  17. package/dist/es2019/utils/performance/measure-enum.js +1 -2
  18. package/dist/es2019/version-wrapper.js +1 -1
  19. package/dist/esm/index.js +14 -1
  20. package/dist/esm/plugins/index.js +0 -1
  21. package/dist/esm/plugins/paste/pm-plugins/main.js +9 -5
  22. package/dist/esm/presets/default.js +1 -1
  23. package/dist/esm/presets/universal.js +2 -1
  24. package/dist/esm/utils/index.js +0 -5
  25. package/dist/esm/utils/performance/measure-enum.js +1 -2
  26. package/dist/esm/version-wrapper.js +1 -1
  27. package/dist/types/index.d.ts +15 -2
  28. package/dist/types/plugins/index.d.ts +0 -1
  29. package/dist/types/plugins/paste/pm-plugins/main.d.ts +2 -0
  30. package/dist/types/presets/default.d.ts +1 -1
  31. package/dist/types/types/editor-props.d.ts +1 -1
  32. package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +2 -2
  33. package/dist/types/ui/ContentStyles/index.d.ts +2 -2
  34. package/dist/types/utils/index.d.ts +0 -1
  35. package/dist/types/utils/performance/measure-enum.d.ts +0 -1
  36. package/dist/types-ts4.5/index.d.ts +15 -2
  37. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  38. package/dist/types-ts4.5/plugins/paste/pm-plugins/main.d.ts +2 -0
  39. package/dist/types-ts4.5/presets/default.d.ts +1 -1
  40. package/dist/types-ts4.5/types/editor-props.d.ts +1 -1
  41. package/dist/types-ts4.5/ui/Appearance/FullPage/StyledComponents.d.ts +2 -2
  42. package/dist/types-ts4.5/ui/ContentStyles/index.d.ts +2 -2
  43. package/dist/types-ts4.5/utils/index.d.ts +0 -1
  44. package/dist/types-ts4.5/utils/performance/measure-enum.d.ts +0 -1
  45. package/package.json +5 -3
  46. package/dist/cjs/plugins/annotation/commands/index.js +0 -150
  47. package/dist/cjs/plugins/annotation/commands/transform.js +0 -86
  48. package/dist/cjs/plugins/annotation/index.js +0 -130
  49. package/dist/cjs/plugins/annotation/nodeviews/index.js +0 -59
  50. package/dist/cjs/plugins/annotation/pm-plugins/inline-comment.js +0 -243
  51. package/dist/cjs/plugins/annotation/pm-plugins/keymap.js +0 -15
  52. package/dist/cjs/plugins/annotation/pm-plugins/plugin-factory.js +0 -107
  53. package/dist/cjs/plugins/annotation/pm-plugins/reducer.js +0 -84
  54. package/dist/cjs/plugins/annotation/pm-plugins/types.js +0 -17
  55. package/dist/cjs/plugins/annotation/toolbar.js +0 -59
  56. package/dist/cjs/plugins/annotation/types.js +0 -20
  57. package/dist/cjs/plugins/annotation/ui/AnnotationViewWrapper.js +0 -38
  58. package/dist/cjs/plugins/annotation/ui/InlineCommentView.js +0 -149
  59. package/dist/cjs/plugins/annotation/update-provider.js +0 -36
  60. package/dist/cjs/plugins/annotation/utils.js +0 -372
  61. package/dist/es2019/plugins/annotation/commands/index.js +0 -123
  62. package/dist/es2019/plugins/annotation/commands/transform.js +0 -64
  63. package/dist/es2019/plugins/annotation/index.js +0 -125
  64. package/dist/es2019/plugins/annotation/nodeviews/index.js +0 -31
  65. package/dist/es2019/plugins/annotation/pm-plugins/inline-comment.js +0 -178
  66. package/dist/es2019/plugins/annotation/pm-plugins/keymap.js +0 -9
  67. package/dist/es2019/plugins/annotation/pm-plugins/plugin-factory.js +0 -108
  68. package/dist/es2019/plugins/annotation/pm-plugins/reducer.js +0 -94
  69. package/dist/es2019/plugins/annotation/pm-plugins/types.js +0 -11
  70. package/dist/es2019/plugins/annotation/toolbar.js +0 -53
  71. package/dist/es2019/plugins/annotation/types.js +0 -14
  72. package/dist/es2019/plugins/annotation/ui/AnnotationViewWrapper.js +0 -14
  73. package/dist/es2019/plugins/annotation/ui/InlineCommentView.js +0 -147
  74. package/dist/es2019/plugins/annotation/update-provider.js +0 -9
  75. package/dist/es2019/plugins/annotation/utils.js +0 -334
  76. package/dist/esm/plugins/annotation/commands/index.js +0 -143
  77. package/dist/esm/plugins/annotation/commands/transform.js +0 -80
  78. package/dist/esm/plugins/annotation/index.js +0 -118
  79. package/dist/esm/plugins/annotation/nodeviews/index.js +0 -52
  80. package/dist/esm/plugins/annotation/pm-plugins/inline-comment.js +0 -236
  81. package/dist/esm/plugins/annotation/pm-plugins/keymap.js +0 -9
  82. package/dist/esm/plugins/annotation/pm-plugins/plugin-factory.js +0 -101
  83. package/dist/esm/plugins/annotation/pm-plugins/reducer.js +0 -77
  84. package/dist/esm/plugins/annotation/pm-plugins/types.js +0 -11
  85. package/dist/esm/plugins/annotation/toolbar.js +0 -52
  86. package/dist/esm/plugins/annotation/types.js +0 -14
  87. package/dist/esm/plugins/annotation/ui/AnnotationViewWrapper.js +0 -31
  88. package/dist/esm/plugins/annotation/ui/InlineCommentView.js +0 -144
  89. package/dist/esm/plugins/annotation/update-provider.js +0 -29
  90. package/dist/esm/plugins/annotation/utils.js +0 -345
  91. package/dist/types/plugins/annotation/commands/index.d.ts +0 -15
  92. package/dist/types/plugins/annotation/commands/transform.d.ts +0 -11
  93. package/dist/types/plugins/annotation/index.d.ts +0 -15
  94. package/dist/types/plugins/annotation/nodeviews/index.d.ts +0 -11
  95. package/dist/types/plugins/annotation/pm-plugins/inline-comment.d.ts +0 -3
  96. package/dist/types/plugins/annotation/pm-plugins/keymap.d.ts +0 -3
  97. package/dist/types/plugins/annotation/pm-plugins/plugin-factory.d.ts +0 -2
  98. package/dist/types/plugins/annotation/pm-plugins/reducer.d.ts +0 -3
  99. package/dist/types/plugins/annotation/pm-plugins/types.d.ts +0 -78
  100. package/dist/types/plugins/annotation/toolbar.d.ts +0 -5
  101. package/dist/types/plugins/annotation/types.d.ts +0 -86
  102. package/dist/types/plugins/annotation/ui/AnnotationViewWrapper.d.ts +0 -10
  103. package/dist/types/plugins/annotation/ui/InlineCommentView.d.ts +0 -13
  104. package/dist/types/plugins/annotation/update-provider.d.ts +0 -12
  105. package/dist/types/plugins/annotation/utils.d.ts +0 -45
  106. package/dist/types-ts4.5/plugins/annotation/commands/index.d.ts +0 -15
  107. package/dist/types-ts4.5/plugins/annotation/commands/transform.d.ts +0 -11
  108. package/dist/types-ts4.5/plugins/annotation/index.d.ts +0 -17
  109. package/dist/types-ts4.5/plugins/annotation/nodeviews/index.d.ts +0 -11
  110. package/dist/types-ts4.5/plugins/annotation/pm-plugins/inline-comment.d.ts +0 -3
  111. package/dist/types-ts4.5/plugins/annotation/pm-plugins/keymap.d.ts +0 -3
  112. package/dist/types-ts4.5/plugins/annotation/pm-plugins/plugin-factory.d.ts +0 -2
  113. package/dist/types-ts4.5/plugins/annotation/pm-plugins/reducer.d.ts +0 -3
  114. package/dist/types-ts4.5/plugins/annotation/pm-plugins/types.d.ts +0 -78
  115. package/dist/types-ts4.5/plugins/annotation/toolbar.d.ts +0 -5
  116. package/dist/types-ts4.5/plugins/annotation/types.d.ts +0 -86
  117. package/dist/types-ts4.5/plugins/annotation/ui/AnnotationViewWrapper.d.ts +0 -10
  118. package/dist/types-ts4.5/plugins/annotation/ui/InlineCommentView.d.ts +0 -13
  119. package/dist/types-ts4.5/plugins/annotation/update-provider.d.ts +0 -12
  120. package/dist/types-ts4.5/plugins/annotation/utils.d.ts +0 -45
@@ -1,31 +0,0 @@
1
- import React from 'react';
2
- import { AnnotationSharedClassNames } from '@atlaskit/editor-common/styles';
3
- import ReactNodeView from '@atlaskit/editor-common/react-node-view';
4
- export class AnnotationNodeView extends ReactNodeView {
5
- createDomRef() {
6
- return document.createElement('span');
7
- }
8
- getContentDOM() {
9
- const dom = document.createElement('span');
10
- dom.className = 'ak-editor-annotation';
11
- return {
12
- dom
13
- };
14
- }
15
- render(_props, forwardRef) {
16
- return (
17
- /*#__PURE__*/
18
- // all inline comment states are now set in decorations at ../pm-plugins/inline-comment.ts
19
- React.createElement("span", {
20
- "data-mark-type": "annotation",
21
- ref: forwardRef
22
- })
23
- );
24
- }
25
- }
26
- export const getAnnotationViewClassname = (isUnresolved, hasFocus) => {
27
- if (!isUnresolved) {
28
- return;
29
- }
30
- return hasFocus ? AnnotationSharedClassNames.focus : AnnotationSharedClassNames.blur;
31
- };
@@ -1,178 +0,0 @@
1
- import { RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
2
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
- import { AnnotationTypes } from '@atlaskit/adf-schema';
5
- import { AnnotationNodeView, getAnnotationViewClassname } from '../nodeviews';
6
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
- import { updateInlineCommentResolvedState, updateMouseState, clearDirtyMark, setInlineCommentsVisibility, setSelectedAnnotation, closeComponent } from '../commands';
8
- import { getAllAnnotations, inlineCommentPluginKey, getPluginState } from '../utils';
9
- import { createPluginState } from './plugin-factory';
10
- const fetchProviderStates = async (provider, annotationIds) => {
11
- const data = await provider.getState(annotationIds);
12
- let result = {};
13
- data.forEach(annotation => {
14
- if (annotation.annotationType === AnnotationTypes.INLINE_COMMENT) {
15
- result[annotation.id] = annotation.state.resolved;
16
- }
17
- });
18
- return result;
19
- };
20
-
21
- // fetchState is unable to return a command as it's runs async and may dispatch at a later time
22
- // Requires `editorView` instead of the decomposition as the async means state may end up stale
23
- const fetchState = async (provider, annotationIds, editorView, editorAnalyticsAPI) => {
24
- if (!annotationIds || !annotationIds.length) {
25
- return;
26
- }
27
- const inlineCommentStates = await fetchProviderStates(provider, annotationIds);
28
- if (editorView.dispatch) {
29
- updateInlineCommentResolvedState(editorAnalyticsAPI)(inlineCommentStates)(editorView.state, editorView.dispatch);
30
- }
31
- };
32
- const initialState = (disallowOnWhitespace = false) => {
33
- return {
34
- annotations: {},
35
- selectedAnnotations: [],
36
- mouseData: {
37
- isSelecting: false
38
- },
39
- disallowOnWhitespace,
40
- isInlineCommentViewClosed: false,
41
- isVisible: true,
42
- skipSelectionHandling: false
43
- };
44
- };
45
- const hideToolbar = (state, dispatch) => () => {
46
- updateMouseState({
47
- isSelecting: true
48
- })(state, dispatch);
49
- };
50
-
51
- // Subscribe to updates from consumer
52
- const onResolve = editorAnalyticsAPI => (state, dispatch) => annotationId => {
53
- updateInlineCommentResolvedState(editorAnalyticsAPI)({
54
- [annotationId]: true
55
- }, RESOLVE_METHOD.CONSUMER)(state, dispatch);
56
- };
57
- const onUnResolve = editorAnalyticsAPI => (state, dispatch) => annotationId => {
58
- updateInlineCommentResolvedState(editorAnalyticsAPI)({
59
- [annotationId]: false
60
- })(state, dispatch);
61
- };
62
- const onMouseUp = (state, dispatch) => e => {
63
- const {
64
- mouseData
65
- } = getPluginState(state) || {};
66
- if (mouseData !== null && mouseData !== void 0 && mouseData.isSelecting) {
67
- updateMouseState({
68
- isSelecting: false
69
- })(state, dispatch);
70
- }
71
- };
72
- const onSetVisibility = view => isVisible => {
73
- const {
74
- state,
75
- dispatch
76
- } = view;
77
- setInlineCommentsVisibility(isVisible)(state, dispatch);
78
- if (isVisible) {
79
- // PM retains focus when we click away from the editor.
80
- // This will restore the visual aspect of the selection,
81
- // otherwise it will seem a floating toolbar will appear
82
- // for no reason.
83
- view.focus();
84
- }
85
- };
86
- export const inlineCommentPlugin = options => {
87
- const {
88
- provider,
89
- portalProviderAPI,
90
- eventDispatcher
91
- } = options;
92
- return new SafePlugin({
93
- key: inlineCommentPluginKey,
94
- state: createPluginState(options.dispatch, initialState(provider.disallowOnWhitespace)),
95
- view(editorView) {
96
- // Get initial state
97
- // Need to pass `editorView` to mitigate editor state going stale
98
- fetchState(provider, getAllAnnotations(editorView.state.doc), editorView, options.editorAnalyticsAPI);
99
- const resolve = annotationId => onResolve(options.editorAnalyticsAPI)(editorView.state, editorView.dispatch)(annotationId);
100
- const unResolve = annotationId => onUnResolve(options.editorAnalyticsAPI)(editorView.state, editorView.dispatch)(annotationId);
101
- const mouseUp = event => onMouseUp(editorView.state, editorView.dispatch)(event);
102
- const setVisibility = isVisible => onSetVisibility(editorView)(isVisible);
103
- const setSelectedAnnotationFn = annotationId => {
104
- if (!annotationId) {
105
- closeComponent()(editorView.state, editorView.dispatch);
106
- } else {
107
- setSelectedAnnotation(annotationId)(editorView.state, editorView.dispatch);
108
- }
109
- };
110
- const {
111
- updateSubscriber
112
- } = provider;
113
- if (updateSubscriber) {
114
- updateSubscriber.on('resolve', resolve).on('delete', resolve).on('unresolve', unResolve).on('create', unResolve).on('setvisibility', setVisibility).on('setselectedannotation', setSelectedAnnotationFn);
115
- }
116
- editorView.root.addEventListener('mouseup', mouseUp);
117
- return {
118
- update(view, _prevState) {
119
- const {
120
- dirtyAnnotations
121
- } = getPluginState(view.state) || {};
122
- if (!dirtyAnnotations) {
123
- return;
124
- }
125
- clearDirtyMark()(view.state, view.dispatch);
126
- fetchState(provider, getAllAnnotations(view.state.doc), view, options.editorAnalyticsAPI);
127
- },
128
- destroy() {
129
- editorView.root.removeEventListener('mouseup', mouseUp);
130
- if (updateSubscriber) {
131
- updateSubscriber.off('resolve', resolve).off('delete', resolve).off('unresolve', unResolve).off('create', unResolve).off('setvisibility', setVisibility).off('setselectedannotation', setSelectedAnnotationFn);
132
- }
133
- }
134
- };
135
- },
136
- props: {
137
- nodeViews: {
138
- annotation: (node, view, getPos) => new AnnotationNodeView(node, view, getPos, portalProviderAPI, eventDispatcher) // resolved
139
- .init()
140
- },
141
- handleDOMEvents: {
142
- mousedown: view => {
143
- const pluginState = getPluginState(view.state);
144
- if (!(pluginState !== null && pluginState !== void 0 && pluginState.mouseData.isSelecting)) {
145
- hideToolbar(view.state, view.dispatch)();
146
- }
147
- return false;
148
- }
149
- },
150
- decorations(state) {
151
- // highlight comments, depending on state
152
- const {
153
- draftDecorationSet,
154
- annotations,
155
- selectedAnnotations,
156
- isVisible,
157
- isInlineCommentViewClosed
158
- } = getPluginState(state) || {};
159
- let decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : DecorationSet.empty;
160
- const focusDecorations = [];
161
- state.doc.descendants((node, pos) => {
162
- node.marks.filter(mark => mark.type === state.schema.marks.annotation).forEach(mark => {
163
- const isSelected = getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(selectedAnnotation => selectedAnnotation.id === mark.attrs.id)) : !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(selectedAnnotation => selectedAnnotation.id === mark.attrs.id));
164
- const isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
165
- if (isVisible) {
166
- focusDecorations.push(Decoration.inline(pos, pos + node.nodeSize, {
167
- class: `${getAnnotationViewClassname(isUnresolved, isSelected)} ${isUnresolved}`,
168
- nodeName: 'span'
169
- }));
170
- }
171
- });
172
- });
173
- decorations = decorations.add(state.doc, focusDecorations);
174
- return decorations;
175
- }
176
- }
177
- });
178
- };
@@ -1,9 +0,0 @@
1
- import { keymap } from '@atlaskit/editor-prosemirror/keymap';
2
- import { bindKeymapWithCommand, addInlineComment } from '../../../keymaps';
3
- import { setInlineCommentDraftState } from '../commands';
4
- import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
- export function keymapPlugin(editorAnalyticsAPI) {
6
- const list = {};
7
- bindKeymapWithCommand(addInlineComment.common, setInlineCommentDraftState(editorAnalyticsAPI)(true, INPUT_METHOD.SHORTCUT), list);
8
- return keymap(list);
9
- }
@@ -1,108 +0,0 @@
1
- import { pluginFactory } from '../../../utils/plugin-state-factory';
2
- import { findAnnotationsInSelection, inlineCommentPluginKey, isSelectedAnnotationsChanged } from '../utils';
3
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
4
- import reducer from './reducer';
5
- const handleDocChanged = (tr, prevPluginState) => {
6
- if (!tr.getMeta('replaceDocument')) {
7
- return getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? getSelectionChangedHandler(false)(tr, prevPluginState) : handleSelectionChanged(tr, prevPluginState);
8
- }
9
- return {
10
- ...prevPluginState,
11
- dirtyAnnotations: true
12
- };
13
- };
14
- const handleSelectionChanged = (tr, pluginState) => {
15
- if (pluginState.skipSelectionHandling) {
16
- return {
17
- ...pluginState,
18
- skipSelectionHandling: false
19
- };
20
- }
21
- const selectedAnnotations = findAnnotationsInSelection(tr.selection, tr.doc);
22
- const changed = selectedAnnotations.length !== pluginState.selectedAnnotations.length || selectedAnnotations.some(annotationInfo => {
23
- return !pluginState.selectedAnnotations.some(aInfo => aInfo.type === annotationInfo.id);
24
- });
25
- if (changed) {
26
- return {
27
- ...pluginState,
28
- selectedAnnotations
29
- };
30
- }
31
- return pluginState;
32
- };
33
- const getSelectionChangedHandler = reopenCommentView => (tr, pluginState) => {
34
- /**
35
- * If feature flag is **OFF** we want to keep the old behavior. Note that
36
- * reopenCommentView is not relevant here when using old behaviour.
37
- *
38
- * Feature flag is evaluated here rather than directly in onSelectionChanged where it is assigned
39
- * to prevent the plugin from setting up the handler before the feature flag is evaluated.
40
- *
41
- * This comment / logic can be cleaned up once the feature flag is removed.
42
- */
43
- if (!getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox')) {
44
- return handleSelectionChanged(tr, pluginState);
45
- }
46
- if (pluginState.skipSelectionHandling) {
47
- return {
48
- ...pluginState,
49
- skipSelectionHandling: false,
50
- ...(reopenCommentView && {
51
- isInlineCommentViewClosed: false
52
- })
53
- };
54
- }
55
- const selectedAnnotations = findAnnotationsInSelection(tr.selection, tr.doc);
56
- if (selectedAnnotations.length === 0) {
57
- return {
58
- ...pluginState,
59
- selectedAnnotations,
60
- isInlineCommentViewClosed: true
61
- };
62
- }
63
- if (isSelectedAnnotationsChanged(selectedAnnotations, pluginState.selectedAnnotations)) {
64
- return {
65
- ...pluginState,
66
- selectedAnnotations,
67
- ...(reopenCommentView && {
68
- isInlineCommentViewClosed: false
69
- })
70
- };
71
- }
72
- return {
73
- ...pluginState,
74
- ...(reopenCommentView && {
75
- isInlineCommentViewClosed: false
76
- })
77
- };
78
- };
79
- export const {
80
- createPluginState,
81
- createCommand
82
- } = pluginFactory(inlineCommentPluginKey, reducer, {
83
- onSelectionChanged: getSelectionChangedHandler(true),
84
- onDocChanged: handleDocChanged,
85
- mapping: (tr, pluginState) => {
86
- let {
87
- draftDecorationSet,
88
- bookmark
89
- } = pluginState;
90
- let mappedDecorationSet, mappedBookmark;
91
- if (draftDecorationSet) {
92
- mappedDecorationSet = draftDecorationSet.map(tr.mapping, tr.doc);
93
- }
94
- if (bookmark) {
95
- mappedBookmark = bookmark.map(tr.mapping);
96
- }
97
-
98
- // return same pluginState if mappings did not change
99
- if (mappedBookmark === bookmark && mappedDecorationSet === draftDecorationSet) {
100
- return pluginState;
101
- }
102
- return {
103
- ...pluginState,
104
- draftDecorationSet: mappedDecorationSet,
105
- bookmark: mappedBookmark
106
- };
107
- }
108
- });
@@ -1,94 +0,0 @@
1
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
- import { addDraftDecoration } from '../utils';
4
- import { ACTIONS } from './types';
5
- export default ((pluginState, action) => {
6
- switch (action.type) {
7
- case ACTIONS.UPDATE_INLINE_COMMENT_STATE:
8
- return {
9
- ...pluginState,
10
- annotations: {
11
- ...pluginState.annotations,
12
- ...action.data
13
- }
14
- };
15
- case ACTIONS.INLINE_COMMENT_UPDATE_MOUSE_STATE:
16
- const mouseData = Object.assign({}, pluginState.mouseData, action.data.mouseData);
17
- return {
18
- ...pluginState,
19
- mouseData
20
- };
21
- case ACTIONS.SET_INLINE_COMMENT_DRAFT_STATE:
22
- return getNewDraftState(pluginState, action.data.drafting, action.data.editorState);
23
- case ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK:
24
- return {
25
- ...pluginState,
26
- dirtyAnnotations: false,
27
- annotations: {}
28
- };
29
- case ACTIONS.CLOSE_COMPONENT:
30
- return getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? {
31
- ...pluginState,
32
- isInlineCommentViewClosed: true
33
- } : {
34
- ...pluginState,
35
- selectedAnnotations: []
36
- };
37
- case ACTIONS.ADD_INLINE_COMMENT:
38
- const updatedPluginState = getNewDraftState(pluginState, action.data.drafting, action.data.editorState);
39
- return {
40
- ...updatedPluginState,
41
- selectedAnnotations: [...updatedPluginState.selectedAnnotations, ...action.data.selectedAnnotations],
42
- annotations: {
43
- ...pluginState.annotations,
44
- ...action.data.inlineComments
45
- },
46
- ...(getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') && {
47
- isInlineCommentViewClosed: false
48
- })
49
- };
50
- case ACTIONS.INLINE_COMMENT_SET_VISIBLE:
51
- const {
52
- isVisible
53
- } = action.data;
54
- if (isVisible === pluginState.isVisible) {
55
- return pluginState;
56
- }
57
- return {
58
- ...(isVisible ? pluginState : getNewDraftState(pluginState, false)),
59
- isVisible
60
- };
61
- case ACTIONS.SET_SELECTED_ANNOTATION:
62
- return {
63
- ...pluginState,
64
- selectedAnnotations: [...action.data.selectedAnnotations],
65
- skipSelectionHandling: true,
66
- ...(getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') && {
67
- // if selecting annotation explicitly, reopen the comment view
68
- isInlineCommentViewClosed: false
69
- })
70
- };
71
- default:
72
- return pluginState;
73
- }
74
- });
75
- function getNewDraftState(pluginState, drafting, editorState) {
76
- let {
77
- draftDecorationSet
78
- } = pluginState;
79
- if (!draftDecorationSet || !drafting) {
80
- draftDecorationSet = DecorationSet.empty;
81
- }
82
- let newState = {
83
- ...pluginState,
84
- draftDecorationSet
85
- };
86
- newState.bookmark = undefined;
87
- if (drafting && editorState) {
88
- newState.bookmark = editorState.selection.getBookmark();
89
- const resolvedBookmark = newState.bookmark.resolve(editorState.doc);
90
- const draftDecoration = addDraftDecoration(resolvedBookmark.from, resolvedBookmark.to);
91
- newState.draftDecorationSet = draftDecorationSet.add(editorState.doc, [draftDecoration]);
92
- }
93
- return newState;
94
- }
@@ -1,11 +0,0 @@
1
- export let ACTIONS = /*#__PURE__*/function (ACTIONS) {
2
- ACTIONS[ACTIONS["UPDATE_INLINE_COMMENT_STATE"] = 0] = "UPDATE_INLINE_COMMENT_STATE";
3
- ACTIONS[ACTIONS["SET_INLINE_COMMENT_DRAFT_STATE"] = 1] = "SET_INLINE_COMMENT_DRAFT_STATE";
4
- ACTIONS[ACTIONS["INLINE_COMMENT_UPDATE_MOUSE_STATE"] = 2] = "INLINE_COMMENT_UPDATE_MOUSE_STATE";
5
- ACTIONS[ACTIONS["INLINE_COMMENT_CLEAR_DIRTY_MARK"] = 3] = "INLINE_COMMENT_CLEAR_DIRTY_MARK";
6
- ACTIONS[ACTIONS["ADD_INLINE_COMMENT"] = 4] = "ADD_INLINE_COMMENT";
7
- ACTIONS[ACTIONS["INLINE_COMMENT_SET_VISIBLE"] = 5] = "INLINE_COMMENT_SET_VISIBLE";
8
- ACTIONS[ACTIONS["CLOSE_COMPONENT"] = 6] = "CLOSE_COMPONENT";
9
- ACTIONS[ACTIONS["SET_SELECTED_ANNOTATION"] = 7] = "SET_SELECTED_ANNOTATION";
10
- return ACTIONS;
11
- }({});
@@ -1,53 +0,0 @@
1
- import React from 'react';
2
- import CommentIcon from '@atlaskit/icon/glyph/comment';
3
- import { addInlineComment, ToolTipContent } from '../../keymaps';
4
- import { setInlineCommentDraftState } from './commands';
5
- import { AnnotationTestIds, AnnotationSelectionType } from './types';
6
- import { isSelectionValid } from './utils';
7
- import { annotationMessages } from '@atlaskit/editor-common/messages';
8
- import { calculateToolbarPositionAboveSelection, calculateToolbarPositionTrackHead } from '@atlaskit/editor-common/utils';
9
- export const buildToolbar = editorAnalyticsAPI => (state, intl, isToolbarAbove = false) => {
10
- const {
11
- schema
12
- } = state;
13
- const selectionValid = isSelectionValid(state);
14
- if (selectionValid === AnnotationSelectionType.INVALID) {
15
- return undefined;
16
- }
17
- const createCommentMessage = intl.formatMessage(annotationMessages.createComment);
18
- const commentDisabledMessage = intl.formatMessage(annotationMessages.createCommentInvalid);
19
- const createComment = {
20
- type: 'button',
21
- showTitle: true,
22
- disabled: selectionValid === AnnotationSelectionType.DISABLED,
23
- testId: AnnotationTestIds.floatingToolbarCreateButton,
24
- icon: CommentIcon,
25
- tooltipContent: selectionValid === AnnotationSelectionType.DISABLED ? commentDisabledMessage : /*#__PURE__*/React.createElement(ToolTipContent, {
26
- description: createCommentMessage,
27
- keymap: addInlineComment
28
- }),
29
- title: createCommentMessage,
30
- onClick: (state, dispatch) => {
31
- return setInlineCommentDraftState(editorAnalyticsAPI)(true)(state, dispatch);
32
- }
33
- };
34
- const {
35
- annotation
36
- } = schema.marks;
37
- const validNodes = Object.keys(schema.nodes).reduce((acc, current) => {
38
- const type = schema.nodes[current];
39
- if (type.allowsMarkType(annotation)) {
40
- acc.push(type);
41
- }
42
- return acc;
43
- }, []);
44
- const toolbarTitle = intl.formatMessage(annotationMessages.toolbar);
45
- const calcToolbarPosition = isToolbarAbove ? calculateToolbarPositionAboveSelection : calculateToolbarPositionTrackHead;
46
- const onPositionCalculated = calcToolbarPosition(toolbarTitle);
47
- return {
48
- title: toolbarTitle,
49
- nodeType: validNodes,
50
- items: [createComment],
51
- onPositionCalculated
52
- };
53
- };
@@ -1,14 +0,0 @@
1
- export let AnnotationSelectionType = /*#__PURE__*/function (AnnotationSelectionType) {
2
- AnnotationSelectionType["INVALID"] = "invalid";
3
- AnnotationSelectionType["DISABLED"] = "disabled";
4
- AnnotationSelectionType["VALID"] = "valid";
5
- return AnnotationSelectionType;
6
- }({}); // Annotation can be created
7
- const prefix = 'ak-editor-annotation';
8
- export const AnnotationTestIds = {
9
- prefix,
10
- floatingComponent: `${prefix}-floating-component`,
11
- floatingToolbarCreateButton: `${prefix}-toolbar-create-button`,
12
- componentSave: `${prefix}-dummy-save-button`,
13
- componentClose: `${prefix}-dummy-close-button`
14
- };
@@ -1,14 +0,0 @@
1
- import React from 'react';
2
- export class AnnotationViewWrapper extends React.PureComponent {
3
- componentDidMount() {
4
- const {
5
- onViewed
6
- } = this.props;
7
- if (onViewed) {
8
- onViewed();
9
- }
10
- }
11
- render() {
12
- return this.props.children;
13
- }
14
- }
@@ -1,147 +0,0 @@
1
- import React from 'react';
2
- import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
3
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
4
- import { AnnotationViewWrapper } from './AnnotationViewWrapper';
5
- import { AnnotationTestIds } from '../types';
6
- import { getAnnotationViewKey, getSelectionPositions, getPluginState, getAllAnnotations } from '../utils';
7
- import { removeInlineCommentNearSelection, updateInlineCommentResolvedState, setInlineCommentDraftState, createAnnotation, closeComponent } from '../commands';
8
- import { ACTION, ACTION_SUBJECT, EVENT_TYPE, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
9
- import { CONTENT_COMPONENT } from '@atlaskit/editor-common/analytics';
10
- import { RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
11
- const findPosForDOM = sel => {
12
- const {
13
- $from,
14
- from
15
- } = sel;
16
-
17
- // Retrieve current TextNode
18
- const index = $from.index();
19
- const node = index < $from.parent.childCount && $from.parent.child(index);
20
-
21
- // Right edge of a mark.
22
- if (!node && $from.nodeBefore && $from.nodeBefore.isText && $from.nodeBefore.marks.find(mark => mark.type.name === 'annotation')) {
23
- return from - 1;
24
- }
25
- return from;
26
- };
27
- export function InlineCommentView({
28
- providers,
29
- editorView,
30
- editorAnalyticsAPI,
31
- dispatchAnalyticsEvent
32
- }) {
33
- // As inlineComment is the only annotation present, this function is not generic
34
- const {
35
- inlineComment: inlineCommentProvider
36
- } = providers;
37
- const {
38
- state,
39
- dispatch
40
- } = editorView;
41
- const {
42
- createComponent: CreateComponent,
43
- viewComponent: ViewComponent
44
- } = inlineCommentProvider;
45
- const inlineCommentState = getPluginState(state);
46
- const {
47
- bookmark,
48
- selectedAnnotations,
49
- annotations,
50
- isInlineCommentViewClosed
51
- } = inlineCommentState || {};
52
- const annotationsList = getAllAnnotations(editorView.state.doc);
53
- const selection = getSelectionPositions(state, inlineCommentState);
54
- const position = findPosForDOM(selection);
55
- let dom;
56
- try {
57
- dom = findDomRefAtPos(position, editorView.domAtPos.bind(editorView));
58
- } catch (error) {
59
- // eslint-disable-next-line no-console
60
- console.warn(error);
61
- if (dispatchAnalyticsEvent) {
62
- const payload = {
63
- action: ACTION.ERRORED,
64
- actionSubject: ACTION_SUBJECT.CONTENT_COMPONENT,
65
- eventType: EVENT_TYPE.OPERATIONAL,
66
- attributes: {
67
- component: CONTENT_COMPONENT.INLINE_COMMENT,
68
- selection: selection.toJSON(),
69
- position,
70
- docSize: editorView.state.doc.nodeSize,
71
- error: error.toString()
72
- }
73
- };
74
- dispatchAnalyticsEvent(payload);
75
- }
76
- }
77
- if (!dom) {
78
- return null;
79
- }
80
-
81
- // Create Component
82
- if (bookmark) {
83
- if (!CreateComponent) {
84
- return null;
85
- }
86
-
87
- //getting all text between bookmarked positions
88
- const textSelection = state.doc.textBetween(selection.from, selection.to);
89
- return /*#__PURE__*/React.createElement("div", {
90
- "data-testid": AnnotationTestIds.floatingComponent,
91
- "data-editor-popup": "true"
92
- }, /*#__PURE__*/React.createElement(CreateComponent, {
93
- dom: dom,
94
- textSelection: textSelection,
95
- onCreate: id => {
96
- createAnnotation(editorAnalyticsAPI)(id)(editorView.state, editorView.dispatch);
97
- !editorView.hasFocus() && editorView.focus();
98
- },
99
- onClose: () => {
100
- setInlineCommentDraftState(editorAnalyticsAPI)(false)(editorView.state, editorView.dispatch);
101
- !editorView.hasFocus() && editorView.focus();
102
- }
103
- }));
104
- }
105
-
106
- // View Component
107
- const activeAnnotations = (selectedAnnotations === null || selectedAnnotations === void 0 ? void 0 : selectedAnnotations.filter(mark => annotations && annotations[mark.id] === false)) || [];
108
- if (!ViewComponent || activeAnnotations.length === 0) {
109
- return null;
110
- }
111
- const onAnnotationViewed = () => {
112
- if (!dispatchAnalyticsEvent) {
113
- return;
114
- }
115
- // fire analytics
116
- const payload = {
117
- action: ACTION.VIEWED,
118
- actionSubject: ACTION_SUBJECT.ANNOTATION,
119
- actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
120
- eventType: EVENT_TYPE.TRACK,
121
- attributes: {
122
- overlap: activeAnnotations.length ? activeAnnotations.length - 1 : 0
123
- }
124
- };
125
- dispatchAnalyticsEvent(payload);
126
- };
127
- if (getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') && isInlineCommentViewClosed || !selectedAnnotations) {
128
- return null;
129
- }
130
- return /*#__PURE__*/React.createElement(AnnotationViewWrapper, {
131
- "data-editor-popup": "true",
132
- "data-testid": AnnotationTestIds.floatingComponent,
133
- key: getAnnotationViewKey(activeAnnotations),
134
- onViewed: onAnnotationViewed
135
- }, /*#__PURE__*/React.createElement(ViewComponent, {
136
- annotationsList: annotationsList,
137
- annotations: activeAnnotations,
138
- dom: dom,
139
- onDelete: id => removeInlineCommentNearSelection(id)(state, dispatch),
140
- onResolve: id => updateInlineCommentResolvedState(editorAnalyticsAPI)({
141
- [id]: true
142
- }, RESOLVE_METHOD.COMPONENT)(editorView.state, editorView.dispatch),
143
- onClose: () => {
144
- closeComponent()(editorView.state, editorView.dispatch);
145
- }
146
- }));
147
- }
@@ -1,9 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- export class AnnotationUpdateEmitter extends EventEmitter {
3
- on(event, listener) {
4
- return super.on(event, listener);
5
- }
6
- off(event, listener) {
7
- return super.removeListener(event, listener);
8
- }
9
- }