@atlaskit/editor-plugin-annotation 19.0.3 → 19.2.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 +20 -0
- package/dist/cjs/annotationPlugin.js +23 -14
- package/dist/cjs/editor-commands/index.js +22 -14
- package/dist/cjs/editor-commands/transform.js +4 -4
- package/dist/cjs/pm-plugins/annotation-manager-hooks.js +5 -5
- package/dist/cjs/pm-plugins/inline-comment.js +2 -3
- package/dist/cjs/pm-plugins/reducer.js +3 -3
- package/dist/cjs/pm-plugins/utils.js +10 -5
- package/dist/cjs/ui/InlineCommentView.js +3 -3
- package/dist/es2019/annotationPlugin.js +19 -10
- package/dist/es2019/editor-commands/index.js +20 -18
- package/dist/es2019/editor-commands/transform.js +4 -4
- package/dist/es2019/pm-plugins/annotation-manager-hooks.js +5 -5
- package/dist/es2019/pm-plugins/inline-comment.js +3 -4
- package/dist/es2019/pm-plugins/reducer.js +3 -3
- package/dist/es2019/pm-plugins/utils.js +9 -7
- package/dist/es2019/ui/InlineCommentView.js +3 -3
- package/dist/esm/annotationPlugin.js +24 -15
- package/dist/esm/editor-commands/index.js +22 -14
- package/dist/esm/editor-commands/transform.js +4 -4
- package/dist/esm/pm-plugins/annotation-manager-hooks.js +5 -5
- package/dist/esm/pm-plugins/inline-comment.js +3 -4
- package/dist/esm/pm-plugins/reducer.js +3 -3
- package/dist/esm/pm-plugins/utils.js +10 -5
- package/dist/esm/ui/InlineCommentView.js +3 -3
- package/dist/types/annotationPluginType.d.ts +12 -0
- package/dist/types/editor-commands/index.d.ts +7 -7
- package/dist/types/editor-commands/transform.d.ts +3 -3
- package/dist/types/pm-plugins/annotation-manager-hooks.d.ts +1 -1
- package/dist/types/pm-plugins/types.d.ts +1 -0
- package/dist/types/pm-plugins/utils.d.ts +4 -4
- package/dist/types/types/index.d.ts +9 -0
- package/package.json +6 -2
|
@@ -58,12 +58,13 @@ export const setPendingSelectedAnnotation = id => createCommand({
|
|
|
58
58
|
}]
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
|
-
const removeInlineCommentFromNode = (id, supportedBlockNodes = [], state, dispatch) => {
|
|
61
|
+
const removeInlineCommentFromNode = (id, supportedBlockNodes = [], isBlockNodeSupported, state, dispatch) => {
|
|
62
62
|
const {
|
|
63
63
|
tr,
|
|
64
64
|
selection
|
|
65
65
|
} = state;
|
|
66
|
-
|
|
66
|
+
const selectedNodeIsSupported = selection instanceof NodeSelection && (isSupportedBlockNode(selection.node, supportedBlockNodes, isBlockNodeSupported) || selection.node.type === state.schema.nodes.mediaSingle && !!selection.node.firstChild && isSupportedBlockNode(selection.node.firstChild, supportedBlockNodes, isBlockNodeSupported));
|
|
67
|
+
if (selectedNodeIsSupported) {
|
|
67
68
|
const {
|
|
68
69
|
$from
|
|
69
70
|
} = selection;
|
|
@@ -93,14 +94,14 @@ const removeInlineCommentFromNode = (id, supportedBlockNodes = [], state, dispat
|
|
|
93
94
|
}
|
|
94
95
|
return false;
|
|
95
96
|
};
|
|
96
|
-
export const removeInlineCommentNearSelection = (id, supportedNodes = []) => (state, dispatch) => {
|
|
97
|
+
export const removeInlineCommentNearSelection = (id, supportedNodes = [], isBlockNodeSupported) => (state, dispatch) => {
|
|
97
98
|
const {
|
|
98
99
|
tr,
|
|
99
100
|
selection: {
|
|
100
101
|
$from
|
|
101
102
|
}
|
|
102
103
|
} = state;
|
|
103
|
-
if (removeInlineCommentFromNode(id, supportedNodes, state, dispatch)) {
|
|
104
|
+
if (removeInlineCommentFromNode(id, supportedNodes, isBlockNodeSupported, state, dispatch)) {
|
|
104
105
|
return true;
|
|
105
106
|
}
|
|
106
107
|
const {
|
|
@@ -121,7 +122,7 @@ export const removeInlineCommentNearSelection = (id, supportedNodes = []) => (st
|
|
|
121
122
|
}
|
|
122
123
|
return true;
|
|
123
124
|
};
|
|
124
|
-
export const removeInlineCommentFromDoc = editorAnalyticsAPI => (id, supportedNodes = []) => (state, dispatch) => {
|
|
125
|
+
export const removeInlineCommentFromDoc = editorAnalyticsAPI => (id, supportedNodes = [], isBlockNodeSupported) => (state, dispatch) => {
|
|
125
126
|
const {
|
|
126
127
|
tr
|
|
127
128
|
} = state;
|
|
@@ -131,9 +132,9 @@ export const removeInlineCommentFromDoc = editorAnalyticsAPI => (id, supportedNo
|
|
|
131
132
|
if (node.type.name === 'mediaInline') {
|
|
132
133
|
return false;
|
|
133
134
|
}
|
|
134
|
-
const
|
|
135
|
+
const isSupportedBlock = node.isBlock && isSupportedBlockNode(node, supportedNodes, isBlockNodeSupported);
|
|
135
136
|
node.marks.filter(mark => mark.type === state.schema.marks.annotation && mark.attrs.id === id).forEach(mark => {
|
|
136
|
-
if (
|
|
137
|
+
if (isSupportedBlock) {
|
|
137
138
|
tr.removeNodeMark(pos, mark);
|
|
138
139
|
} else {
|
|
139
140
|
tr.removeMark(pos, pos + node.nodeSize, mark);
|
|
@@ -146,10 +147,10 @@ export const removeInlineCommentFromDoc = editorAnalyticsAPI => (id, supportedNo
|
|
|
146
147
|
}
|
|
147
148
|
return false;
|
|
148
149
|
};
|
|
149
|
-
const getDraftCommandAction = (drafting, targetType, targetNodeId, supportedBlockNodes, isOpeningMediaCommentFromToolbar) => {
|
|
150
|
+
const getDraftCommandAction = (drafting, targetType, targetNodeId, supportedBlockNodes, isBlockNodeSupported, isOpeningMediaCommentFromToolbar) => {
|
|
150
151
|
return editorState => {
|
|
151
152
|
// validate selection only when entering draft mode
|
|
152
|
-
if (drafting && isSelectionValid(editorState) !== AnnotationSelectionType.VALID) {
|
|
153
|
+
if (drafting && isSelectionValid(editorState, supportedBlockNodes, isBlockNodeSupported) !== AnnotationSelectionType.VALID) {
|
|
153
154
|
return false;
|
|
154
155
|
}
|
|
155
156
|
return {
|
|
@@ -159,6 +160,7 @@ const getDraftCommandAction = (drafting, targetType, targetNodeId, supportedBloc
|
|
|
159
160
|
editorState,
|
|
160
161
|
targetType,
|
|
161
162
|
supportedBlockNodes,
|
|
163
|
+
isBlockNodeSupported,
|
|
162
164
|
targetNodeId,
|
|
163
165
|
isOpeningMediaCommentFromToolbar
|
|
164
166
|
}
|
|
@@ -172,12 +174,12 @@ const getDraftCommandAction = (drafting, targetType, targetNodeId, supportedBloc
|
|
|
172
174
|
* @param supportedBlockNodes
|
|
173
175
|
* @example
|
|
174
176
|
*/
|
|
175
|
-
export const showInlineCommentForBlockNode = (supportedBlockNodes = []) => (node, viewMethod, isOpeningMediaCommentFromToolbar) => (state, dispatch) => {
|
|
177
|
+
export const showInlineCommentForBlockNode = (supportedBlockNodes = [], isBlockNodeSupported) => (node, viewMethod, isOpeningMediaCommentFromToolbar) => (state, dispatch) => {
|
|
176
178
|
const pluginState = getPluginState(state);
|
|
177
179
|
const {
|
|
178
180
|
annotation
|
|
179
181
|
} = state.schema.marks;
|
|
180
|
-
if (node && node.isBlock &&
|
|
182
|
+
if (node && node.isBlock && isSupportedBlockNode(node, supportedBlockNodes, isBlockNodeSupported)) {
|
|
181
183
|
const unresolvedAnnotationMarks = ((node === null || node === void 0 ? void 0 : node.marks) || []).filter(mark => mark.type === annotation && !(pluginState !== null && pluginState !== void 0 && pluginState.annotations[mark.attrs.id])).map(mark => ({
|
|
182
184
|
id: mark.attrs.id,
|
|
183
185
|
type: mark.attrs.annotationType
|
|
@@ -201,8 +203,8 @@ export const showInlineCommentForBlockNode = (supportedBlockNodes = []) => (node
|
|
|
201
203
|
}
|
|
202
204
|
return false;
|
|
203
205
|
};
|
|
204
|
-
export const setInlineCommentDraftState = (editorAnalyticsAPI, supportedBlockNodes = [], api) => (drafting, inputMethod = INPUT_METHOD.TOOLBAR, targetType = 'inline', targetNodeId = undefined, isOpeningMediaCommentFromToolbar) => {
|
|
205
|
-
const commandAction = getDraftCommandAction(drafting, targetType, targetNodeId, supportedBlockNodes, isOpeningMediaCommentFromToolbar);
|
|
206
|
+
export const setInlineCommentDraftState = (editorAnalyticsAPI, supportedBlockNodes = [], api, isBlockNodeSupported) => (drafting, inputMethod = INPUT_METHOD.TOOLBAR, targetType = 'inline', targetNodeId = undefined, isOpeningMediaCommentFromToolbar) => {
|
|
207
|
+
const commandAction = getDraftCommandAction(drafting, targetType, targetNodeId, supportedBlockNodes, isBlockNodeSupported, isOpeningMediaCommentFromToolbar);
|
|
206
208
|
if (Boolean(api === null || api === void 0 ? void 0 : api.toolbar)) {
|
|
207
209
|
return (state, dispatch) => {
|
|
208
210
|
const tr = transform.handleDraftState(editorAnalyticsAPI)(drafting, inputMethod)(state.tr, state);
|
|
@@ -226,7 +228,7 @@ export const setInlineCommentDraftState = (editorAnalyticsAPI, supportedBlockNod
|
|
|
226
228
|
return createCommand(commandAction, transform.handleDraftState(editorAnalyticsAPI)(drafting, inputMethod));
|
|
227
229
|
}
|
|
228
230
|
};
|
|
229
|
-
export const addInlineComment = (editorAnalyticsAPI, editorAPI) => (id, supportedBlockNodes) => {
|
|
231
|
+
export const addInlineComment = (editorAnalyticsAPI, editorAPI) => (id, supportedBlockNodes, isBlockNodeSupported) => {
|
|
230
232
|
const commandAction = editorState => ({
|
|
231
233
|
type: ACTIONS.ADD_INLINE_COMMENT,
|
|
232
234
|
data: {
|
|
@@ -245,7 +247,7 @@ export const addInlineComment = (editorAnalyticsAPI, editorAPI) => (id, supporte
|
|
|
245
247
|
});
|
|
246
248
|
if (Boolean(editorAPI === null || editorAPI === void 0 ? void 0 : editorAPI.toolbar)) {
|
|
247
249
|
return (state, dispatch) => {
|
|
248
|
-
const tr = transform.addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes)(state.tr, state);
|
|
250
|
+
const tr = transform.addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes, isBlockNodeSupported)(state.tr, state);
|
|
249
251
|
tr.setMeta(inlineCommentPluginKey, commandAction(state));
|
|
250
252
|
resetUserIntent(editorAPI, tr);
|
|
251
253
|
if (dispatch) {
|
|
@@ -255,7 +257,7 @@ export const addInlineComment = (editorAnalyticsAPI, editorAPI) => (id, supporte
|
|
|
255
257
|
return false;
|
|
256
258
|
};
|
|
257
259
|
} else {
|
|
258
|
-
return createCommand(commandAction, transform.addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes));
|
|
260
|
+
return createCommand(commandAction, transform.addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes, isBlockNodeSupported));
|
|
259
261
|
}
|
|
260
262
|
};
|
|
261
263
|
export const updateMouseState = mouseData => createCommand({
|
|
@@ -282,7 +284,7 @@ export const setHoveredAnnotation = id => createCommand({
|
|
|
282
284
|
}]
|
|
283
285
|
}
|
|
284
286
|
});
|
|
285
|
-
export const createAnnotation = (editorAnalyticsAPI, editorAPI) => (id, annotationType = AnnotationTypes.INLINE_COMMENT, supportedBlockNodes) => (state, dispatch) => {
|
|
287
|
+
export const createAnnotation = (editorAnalyticsAPI, editorAPI) => (id, annotationType = AnnotationTypes.INLINE_COMMENT, supportedBlockNodes, isBlockNodeSupported) => (state, dispatch) => {
|
|
286
288
|
// don't try to add if there are is no temp highlight bookmarked
|
|
287
289
|
const {
|
|
288
290
|
bookmark
|
|
@@ -291,7 +293,7 @@ export const createAnnotation = (editorAnalyticsAPI, editorAPI) => (id, annotati
|
|
|
291
293
|
return false;
|
|
292
294
|
}
|
|
293
295
|
if (annotationType === AnnotationTypes.INLINE_COMMENT) {
|
|
294
|
-
return addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes)(state, dispatch);
|
|
296
|
+
return addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes, isBlockNodeSupported)(state, dispatch);
|
|
295
297
|
}
|
|
296
298
|
return false;
|
|
297
299
|
};
|
|
@@ -7,7 +7,7 @@ import { AddMarkStep } from '@atlaskit/editor-prosemirror/transform';
|
|
|
7
7
|
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
8
8
|
import { getDraftCommandAnalyticsPayload, getPluginState, resolveDraftBookmark } from '../pm-plugins/utils';
|
|
9
9
|
const isAnnotationStep = step => step instanceof AddMarkStep && step.mark.type.name === 'annotation';
|
|
10
|
-
const addAnnotationMark = (id, supportedBlockNodes) => (transaction, state) => {
|
|
10
|
+
const addAnnotationMark = (id, supportedBlockNodes, isBlockNodeSupported) => (transaction, state) => {
|
|
11
11
|
const inlineCommentState = getPluginState(state);
|
|
12
12
|
const {
|
|
13
13
|
bookmark
|
|
@@ -21,7 +21,7 @@ const addAnnotationMark = (id, supportedBlockNodes) => (transaction, state) => {
|
|
|
21
21
|
to,
|
|
22
22
|
head,
|
|
23
23
|
isBlockNode
|
|
24
|
-
} = resolveDraftBookmark(state, bookmark, supportedBlockNodes);
|
|
24
|
+
} = resolveDraftBookmark(state, bookmark, supportedBlockNodes, isBlockNodeSupported);
|
|
25
25
|
let tr = transaction;
|
|
26
26
|
if (isBlockNode) {
|
|
27
27
|
tr = tr.addNodeMark(from, annotationMark);
|
|
@@ -39,9 +39,9 @@ const addAnnotationMark = (id, supportedBlockNodes) => (transaction, state) => {
|
|
|
39
39
|
}
|
|
40
40
|
return tr;
|
|
41
41
|
};
|
|
42
|
-
const addInlineComment = (editorAnalyticsAPI, editorAPI) => (id, supportedBlockNodes) => (transaction, state) => {
|
|
42
|
+
const addInlineComment = (editorAnalyticsAPI, editorAPI) => (id, supportedBlockNodes, isBlockNodeSupported) => (transaction, state) => {
|
|
43
43
|
var _editorAPI$editorView, _pluginState$featureF;
|
|
44
|
-
let tr = addAnnotationMark(id, supportedBlockNodes)(transaction, state);
|
|
44
|
+
let tr = addAnnotationMark(id, supportedBlockNodes, isBlockNodeSupported)(transaction, state);
|
|
45
45
|
editorAPI === null || editorAPI === void 0 ? void 0 : (_editorAPI$editorView = editorAPI.editorViewModeEffects) === null || _editorAPI$editorView === void 0 ? void 0 : _editorAPI$editorView.actions.applyViewModeStepAt(tr);
|
|
46
46
|
|
|
47
47
|
// add insert analytics step to transaction
|
|
@@ -22,7 +22,7 @@ const domRefFromPos = (view, position) => {
|
|
|
22
22
|
}
|
|
23
23
|
return dom;
|
|
24
24
|
};
|
|
25
|
-
export const allowAnnotation = (editorView,
|
|
25
|
+
export const allowAnnotation = (editorView, options) => () => {
|
|
26
26
|
const {
|
|
27
27
|
isDrafting,
|
|
28
28
|
draftDecorationSet
|
|
@@ -36,7 +36,7 @@ export const allowAnnotation = (editorView, _options) => () => {
|
|
|
36
36
|
if (!!(decoration !== null && decoration !== void 0 && decoration.length)) {
|
|
37
37
|
return false;
|
|
38
38
|
}
|
|
39
|
-
return isSelectionValid(editorView.state) === AnnotationSelectionType.VALID;
|
|
39
|
+
return isSelectionValid(editorView.state, options.provider.supportedBlockNodes, options.provider.isBlockNodeSupported) === AnnotationSelectionType.VALID;
|
|
40
40
|
};
|
|
41
41
|
export const startDraft = (editorView, options) => () => {
|
|
42
42
|
var _getRangeInlineNodeNa, _options$annotationMa2;
|
|
@@ -68,7 +68,7 @@ export const startDraft = (editorView, options) => () => {
|
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
setInlineCommentDraftState(options.editorAnalyticsAPI,
|
|
71
|
+
setInlineCommentDraftState(options.editorAnalyticsAPI, options.provider.supportedBlockNodes, options.api, options.provider.isBlockNodeSupported)(true)(editorView.state, editorView.dispatch);
|
|
72
72
|
const {
|
|
73
73
|
draftDecorationSet
|
|
74
74
|
} = inlineCommentPluginKey.getState(editorView.state) || {};
|
|
@@ -151,7 +151,7 @@ export const applyDraft = (editorView, options) => id => {
|
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
153
|
const from = decorations[0].from;
|
|
154
|
-
createAnnotation(options.editorAnalyticsAPI, options.api)(id, AnnotationTypes.INLINE_COMMENT, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
|
|
154
|
+
createAnnotation(options.editorAnalyticsAPI, options.api)(id, AnnotationTypes.INLINE_COMMENT, options.provider.supportedBlockNodes, options.provider.isBlockNodeSupported)(editorView.state, editorView.dispatch);
|
|
155
155
|
!editorView.hasFocus() && editorView.focus();
|
|
156
156
|
|
|
157
157
|
// Using the original decoration from position we should be able to locate the new target element.
|
|
@@ -327,7 +327,7 @@ export const clearAnnotation = (editorView, options) => id => {
|
|
|
327
327
|
reason: ERROR_REASON_ID_INVALID
|
|
328
328
|
};
|
|
329
329
|
}
|
|
330
|
-
removeInlineCommentFromDoc(options.editorAnalyticsAPI)(id, options.provider.supportedBlockNodes)(editorView.state, editorView.dispatch);
|
|
330
|
+
removeInlineCommentFromDoc(options.editorAnalyticsAPI)(id, options.provider.supportedBlockNodes, options.provider.isBlockNodeSupported)(editorView.state, editorView.dispatch);
|
|
331
331
|
return {
|
|
332
332
|
success: true,
|
|
333
333
|
actionResult: undefined
|
|
@@ -10,7 +10,7 @@ import { getAnnotationViewClassname, getBlockAnnotationViewClassname } from '../
|
|
|
10
10
|
import { allowAnnotation, applyDraft, clearDraft, clearAnnotation, getDraft, setIsAnnotationHovered, setIsAnnotationSelected, startDraft } from './annotation-manager-hooks';
|
|
11
11
|
import { createPluginState } from './plugin-factory';
|
|
12
12
|
import { shouldSuppressFloatingToolbar } from './toolbar';
|
|
13
|
-
import { decorationKey, getAllAnnotations, getPluginState, inlineCommentPluginKey } from './utils';
|
|
13
|
+
import { decorationKey, getAllAnnotations, getPluginState, inlineCommentPluginKey, isSupportedBlockNode } from './utils';
|
|
14
14
|
const fetchProviderStates = async (provider, annotationIds) => {
|
|
15
15
|
if (!provider || !provider.getState) {
|
|
16
16
|
return {};
|
|
@@ -409,19 +409,18 @@ export const inlineCommentPlugin = options => {
|
|
|
409
409
|
// everytime we need to update the decorations. This handler will be called alot. We should be caching
|
|
410
410
|
// the decorations in plugin state and only updating them when required.
|
|
411
411
|
state.doc.descendants((node, pos) => {
|
|
412
|
-
var _provider$supportedBl;
|
|
413
412
|
// Inline comment on mediaInline is not supported as part of comments on media project
|
|
414
413
|
// Thus, we skip the decoration for mediaInline node
|
|
415
414
|
if (node.type.name === 'mediaInline') {
|
|
416
415
|
return false;
|
|
417
416
|
}
|
|
418
|
-
const
|
|
417
|
+
const isSupportedBlock = node.isBlock && isSupportedBlockNode(node, provider.supportedBlockNodes, provider.isBlockNodeSupported);
|
|
419
418
|
node.marks.filter(mark => mark.type === state.schema.marks.annotation).forEach(mark => {
|
|
420
419
|
if (isVisible) {
|
|
421
420
|
const isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
|
|
422
421
|
const isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(selectedAnnotation => selectedAnnotation.id === mark.attrs.id));
|
|
423
422
|
const isHovered = !isInlineCommentViewClosed && !!(hoveredAnnotations !== null && hoveredAnnotations !== void 0 && hoveredAnnotations.some(hoveredAnnotation => hoveredAnnotation.id === mark.attrs.id));
|
|
424
|
-
if (
|
|
423
|
+
if (isSupportedBlock) {
|
|
425
424
|
focusDecorations.push(Decoration.node(pos, pos + node.nodeSize, {
|
|
426
425
|
class: `${getBlockAnnotationViewClassname(isUnresolved, isSelected)} ${isUnresolved}`
|
|
427
426
|
}, {
|
|
@@ -24,7 +24,7 @@ export default ((pluginState, action) => {
|
|
|
24
24
|
mouseData
|
|
25
25
|
};
|
|
26
26
|
case ACTIONS.SET_INLINE_COMMENT_DRAFT_STATE:
|
|
27
|
-
return getNewDraftState(pluginState, action.data.drafting, action.data.editorState, action.data.targetType, action.data.supportedBlockNodes, action.data.targetNodeId, action.data.isOpeningMediaCommentFromToolbar);
|
|
27
|
+
return getNewDraftState(pluginState, action.data.drafting, action.data.editorState, action.data.targetType, action.data.supportedBlockNodes, action.data.isBlockNodeSupported, action.data.targetNodeId, action.data.isOpeningMediaCommentFromToolbar);
|
|
28
28
|
case ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK:
|
|
29
29
|
return {
|
|
30
30
|
...pluginState,
|
|
@@ -100,7 +100,7 @@ export default ((pluginState, action) => {
|
|
|
100
100
|
return pluginState;
|
|
101
101
|
}
|
|
102
102
|
});
|
|
103
|
-
function getNewDraftState(pluginState, drafting, editorState, targetType, supportedBlockNodes, targetNodeId, isOpeningMediaCommentFromToolbar) {
|
|
103
|
+
function getNewDraftState(pluginState, drafting, editorState, targetType, supportedBlockNodes, isBlockNodeSupported, targetNodeId, isOpeningMediaCommentFromToolbar) {
|
|
104
104
|
let {
|
|
105
105
|
draftDecorationSet
|
|
106
106
|
} = pluginState;
|
|
@@ -119,7 +119,7 @@ function getNewDraftState(pluginState, drafting, editorState, targetType, suppor
|
|
|
119
119
|
const {
|
|
120
120
|
from,
|
|
121
121
|
to
|
|
122
|
-
} = resolveDraftBookmark(editorState, newState.bookmark, supportedBlockNodes);
|
|
122
|
+
} = resolveDraftBookmark(editorState, newState.bookmark, supportedBlockNodes, isBlockNodeSupported);
|
|
123
123
|
const draftDecoration = addDraftDecoration(from, to, targetType);
|
|
124
124
|
newState.draftDecorationSet = draftDecorationSet.add(editorState.doc, [draftDecoration]);
|
|
125
125
|
}
|
|
@@ -159,7 +159,7 @@ export const findAnnotationsInSelection = (selection, doc) => {
|
|
|
159
159
|
reorderAnnotations(annotations, $anchor);
|
|
160
160
|
return annotations;
|
|
161
161
|
};
|
|
162
|
-
export const resolveDraftBookmark = (editorState, bookmark, supportedBlockNodes = []) => {
|
|
162
|
+
export const resolveDraftBookmark = (editorState, bookmark, supportedBlockNodes = [], isBlockNodeSupported) => {
|
|
163
163
|
const {
|
|
164
164
|
doc
|
|
165
165
|
} = editorState;
|
|
@@ -185,7 +185,8 @@ export const resolveDraftBookmark = (editorState, bookmark, supportedBlockNodes
|
|
|
185
185
|
return false;
|
|
186
186
|
}
|
|
187
187
|
const nodeEndsAt = pos + node.nodeSize;
|
|
188
|
-
|
|
188
|
+
const isLegacyMediaSingleWrapper = node.type.name === 'mediaSingle' && supportedBlockNodes.includes('media') && !supportedBlockNodes.includes('mediaSingle');
|
|
189
|
+
if (isSupportedBlockNode(node, supportedBlockNodes, isBlockNodeSupported) && !isLegacyMediaSingleWrapper) {
|
|
189
190
|
draftBookmark = {
|
|
190
191
|
from: pos,
|
|
191
192
|
to: nodeEndsAt,
|
|
@@ -262,7 +263,7 @@ export const getDraftCommandAnalyticsPayload = (drafting, inputMethod) => {
|
|
|
262
263
|
};
|
|
263
264
|
return payload;
|
|
264
265
|
};
|
|
265
|
-
export const isSelectionValid = (state,
|
|
266
|
+
export const isSelectionValid = (state, supportedBlockNodes = [], isBlockNodeSupported) => {
|
|
266
267
|
var _currentMediaNodeWith;
|
|
267
268
|
const {
|
|
268
269
|
selection
|
|
@@ -273,7 +274,8 @@ export const isSelectionValid = (state, _supportedNodes = []) => {
|
|
|
273
274
|
const allowedInlineNodes = ['emoji', 'status', 'date', 'mention', 'inlineCard'];
|
|
274
275
|
const isSelectionEmpty = selection.empty;
|
|
275
276
|
const isTextOrAllSelection = selection instanceof TextSelection || selection instanceof AllSelection;
|
|
276
|
-
const
|
|
277
|
+
const isSupportedBlockNodeSelection = selection instanceof NodeSelection && isSupportedBlockNode(selection.node, supportedBlockNodes, isBlockNodeSupported);
|
|
278
|
+
const isValidNodeSelection = selection instanceof NodeSelection && (allowedInlineNodes.includes(selection.node.type.name) || isSupportedBlockNodeSelection);
|
|
277
279
|
const isValidSelection = isTextOrAllSelection || isValidNodeSelection;
|
|
278
280
|
|
|
279
281
|
// Allow media so that it can enter draft mode
|
|
@@ -283,7 +285,7 @@ export const isSelectionValid = (state, _supportedNodes = []) => {
|
|
|
283
285
|
if (isSelectionEmpty || !isValidSelection) {
|
|
284
286
|
return AnnotationSelectionType.INVALID;
|
|
285
287
|
}
|
|
286
|
-
const containsInvalidNodes = hasInvalidNodes(state);
|
|
288
|
+
const containsInvalidNodes = !isSupportedBlockNodeSelection && hasInvalidNodes(state);
|
|
287
289
|
|
|
288
290
|
// A selection that only covers 1 pos, and is an invalid node
|
|
289
291
|
// e.g. a text selection over a mention
|
|
@@ -312,8 +314,8 @@ export const hasInvalidNodes = state => {
|
|
|
312
314
|
to: selection.to
|
|
313
315
|
}, doc, schema);
|
|
314
316
|
};
|
|
315
|
-
export const isSupportedBlockNode = (node, supportedBlockNodes = []) => {
|
|
316
|
-
return supportedBlockNodes.indexOf(node.type.name) >= 0 || node.type.name === 'mediaSingle' && supportedBlockNodes.indexOf('media') >= 0;
|
|
317
|
+
export const isSupportedBlockNode = (node, supportedBlockNodes = [], isBlockNodeSupported) => {
|
|
318
|
+
return supportedBlockNodes.indexOf(node.type.name) >= 0 || node.type.name === 'mediaSingle' && supportedBlockNodes.indexOf('media') >= 0 || fg('cc_maui_annotations_on_extensions') && (isBlockNodeSupported === null || isBlockNodeSupported === void 0 ? void 0 : isBlockNodeSupported(node)) === true;
|
|
317
319
|
};
|
|
318
320
|
|
|
319
321
|
/**
|
|
@@ -122,7 +122,7 @@ export function InlineCommentView({
|
|
|
122
122
|
,
|
|
123
123
|
onCreate: id => {
|
|
124
124
|
if (!isAnnotationManagerEnabled) {
|
|
125
|
-
const createAnnotationResult = createAnnotation(editorAnalyticsAPI, editorAPI)(id, AnnotationTypes.INLINE_COMMENT, inlineCommentProvider.supportedBlockNodes)(editorView.state, editorView.dispatch);
|
|
125
|
+
const createAnnotationResult = createAnnotation(editorAnalyticsAPI, editorAPI)(id, AnnotationTypes.INLINE_COMMENT, inlineCommentProvider.supportedBlockNodes, inlineCommentProvider.isBlockNodeSupported)(editorView.state, editorView.dispatch);
|
|
126
126
|
!editorView.hasFocus() && editorView.focus();
|
|
127
127
|
if (!createAnnotationResult) {
|
|
128
128
|
throw new Error('Failed to create annotation');
|
|
@@ -134,7 +134,7 @@ export function InlineCommentView({
|
|
|
134
134
|
onCreateError: id =>
|
|
135
135
|
// This is called when optimistic create inline comment encounters an error,
|
|
136
136
|
// in which case the optimistically added annotation must be removed.
|
|
137
|
-
removeInlineCommentNearSelection(id, inlineCommentProvider.supportedBlockNodes)(editorView.state, editorView.dispatch)
|
|
137
|
+
removeInlineCommentNearSelection(id, inlineCommentProvider.supportedBlockNodes, inlineCommentProvider.isBlockNodeSupported)(editorView.state, editorView.dispatch)
|
|
138
138
|
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
|
|
139
139
|
,
|
|
140
140
|
onClose: () => {
|
|
@@ -196,7 +196,7 @@ export function InlineCommentView({
|
|
|
196
196
|
dom: dom
|
|
197
197
|
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
|
|
198
198
|
,
|
|
199
|
-
onDelete: id => removeInlineCommentNearSelection(id, inlineCommentProvider.supportedBlockNodes)(editorView.state, dispatch)
|
|
199
|
+
onDelete: id => removeInlineCommentNearSelection(id, inlineCommentProvider.supportedBlockNodes, inlineCommentProvider.isBlockNodeSupported)(editorView.state, dispatch)
|
|
200
200
|
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
|
|
201
201
|
,
|
|
202
202
|
onResolve: id => updateInlineCommentResolvedState(editorAnalyticsAPI)({
|
|
@@ -4,10 +4,11 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
4
4
|
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; }
|
|
5
5
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
6
|
import React from 'react';
|
|
7
|
+
import { AnnotationTypes } from '@atlaskit/adf-schema/annotation';
|
|
7
8
|
import { isSSR } from '@atlaskit/editor-common/core-utils';
|
|
8
9
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
9
10
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/editor-experiment';
|
|
10
|
-
import { setInlineCommentDraftState, setSelectedAnnotation, setPendingSelectedAnnotation, showInlineCommentForBlockNode } from './editor-commands';
|
|
11
|
+
import { createAnnotation, removeInlineCommentFromDoc, setInlineCommentDraftState, setSelectedAnnotation, setPendingSelectedAnnotation, showInlineCommentForBlockNode } from './editor-commands';
|
|
11
12
|
import { annotationWithToDOMFix } from './nodeviews/annotationMark';
|
|
12
13
|
import { inlineCommentPlugin } from './pm-plugins/inline-comment';
|
|
13
14
|
import { keymapPlugin } from './pm-plugins/keymap';
|
|
@@ -17,7 +18,7 @@ import { getPluginState, hasAnyUnResolvedAnnotationInPage, inlineCommentPluginKe
|
|
|
17
18
|
import { InlineCommentView } from './ui/InlineCommentView';
|
|
18
19
|
import { getToolbarComponents } from './ui/toolbar-components';
|
|
19
20
|
export var annotationPlugin = function annotationPlugin(_ref) {
|
|
20
|
-
var _api$featureFlags, _api$
|
|
21
|
+
var _api$featureFlags, _api$analytics3;
|
|
21
22
|
var annotationProviders = _ref.config,
|
|
22
23
|
api = _ref.api;
|
|
23
24
|
var featureFlags = api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState();
|
|
@@ -87,8 +88,16 @@ export var annotationPlugin = function annotationPlugin(_ref) {
|
|
|
87
88
|
hasAnyUnResolvedAnnotationInPage: hasAnyUnResolvedAnnotationInPage,
|
|
88
89
|
requestCloseInlineComment: requestCloseInlineComment,
|
|
89
90
|
stripNonExistingAnnotations: stripNonExistingAnnotations,
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
applyInlineCommentDraft: function applyInlineCommentDraft(annotationId) {
|
|
92
|
+
var _api$analytics;
|
|
93
|
+
return createAnnotation(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api)(annotationId, AnnotationTypes.INLINE_COMMENT, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes);
|
|
94
|
+
},
|
|
95
|
+
removeInlineCommentAnnotation: function removeInlineCommentAnnotation(annotationId) {
|
|
96
|
+
var _api$analytics2, _annotationProviders$;
|
|
97
|
+
return removeInlineCommentFromDoc(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(annotationId, (_annotationProviders$ = annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes) !== null && _annotationProviders$ !== void 0 ? _annotationProviders$ : []);
|
|
98
|
+
},
|
|
99
|
+
setInlineCommentDraftState: setInlineCommentDraftState(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes, undefined, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.isBlockNodeSupported),
|
|
100
|
+
showCommentForBlockNode: showInlineCommentForBlockNode(annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.isBlockNodeSupported),
|
|
92
101
|
setSelectedAnnotation: setSelectedAnnotation,
|
|
93
102
|
setPendingSelectedAnnotation: setPendingSelectedAnnotation
|
|
94
103
|
},
|
|
@@ -107,11 +116,11 @@ export var annotationPlugin = function annotationPlugin(_ref) {
|
|
|
107
116
|
plugin: function plugin(_ref4) {
|
|
108
117
|
var dispatch = _ref4.dispatch;
|
|
109
118
|
if (annotationProviders) {
|
|
110
|
-
var _api$
|
|
119
|
+
var _api$analytics4;
|
|
111
120
|
return inlineCommentPlugin({
|
|
112
121
|
dispatch: dispatch,
|
|
113
122
|
provider: annotationProviders.inlineComment,
|
|
114
|
-
editorAnalyticsAPI: api === null || api === void 0 || (_api$
|
|
123
|
+
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions,
|
|
115
124
|
featureFlagsPluginState: featureFlags,
|
|
116
125
|
selectCommentExperience: annotationProviders.selectCommentExperience,
|
|
117
126
|
viewInlineCommentTraceUFOPress: annotationProviders.viewInlineCommentTraceUFOPress,
|
|
@@ -151,13 +160,13 @@ export var annotationPlugin = function annotationPlugin(_ref) {
|
|
|
151
160
|
}
|
|
152
161
|
var pluginState = getPluginState(state);
|
|
153
162
|
if (pluginState && pluginState.isVisible && !pluginState.bookmark && !pluginState.mouseData.isSelecting) {
|
|
154
|
-
var _api$
|
|
155
|
-
var _annotationProviders$ = annotationProviders.inlineComment,
|
|
156
|
-
isToolbarAbove = _annotationProviders
|
|
157
|
-
onCommentButtonMount = _annotationProviders
|
|
158
|
-
getCanAddComments = _annotationProviders
|
|
159
|
-
contentType = _annotationProviders
|
|
160
|
-
var toolbarConfig = buildToolbar(api === null || api === void 0 || (_api$
|
|
163
|
+
var _api$analytics5;
|
|
164
|
+
var _annotationProviders$2 = annotationProviders.inlineComment,
|
|
165
|
+
isToolbarAbove = _annotationProviders$2.isToolbarAbove,
|
|
166
|
+
onCommentButtonMount = _annotationProviders$2.onCommentButtonMount,
|
|
167
|
+
getCanAddComments = _annotationProviders$2.getCanAddComments,
|
|
168
|
+
contentType = _annotationProviders$2.contentType;
|
|
169
|
+
var toolbarConfig = buildToolbar(api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions)({
|
|
161
170
|
state: state,
|
|
162
171
|
intl: intl,
|
|
163
172
|
isToolbarAbove: isToolbarAbove,
|
|
@@ -202,7 +211,7 @@ var selector = function selector(states) {
|
|
|
202
211
|
};
|
|
203
212
|
};
|
|
204
213
|
function AnnotationContentComponent(_ref6) {
|
|
205
|
-
var _api$
|
|
214
|
+
var _api$analytics6;
|
|
206
215
|
var api = _ref6.api,
|
|
207
216
|
editorView = _ref6.editorView,
|
|
208
217
|
annotationProviders = _ref6.annotationProviders,
|
|
@@ -219,7 +228,7 @@ function AnnotationContentComponent(_ref6) {
|
|
|
219
228
|
providers: annotationProviders,
|
|
220
229
|
editorView: editorView,
|
|
221
230
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
222
|
-
editorAnalyticsAPI: api === null || api === void 0 || (_api$
|
|
231
|
+
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : _api$analytics6.actions,
|
|
223
232
|
editorAPI: api
|
|
224
233
|
}));
|
|
225
234
|
}
|
|
@@ -81,11 +81,13 @@ export var setPendingSelectedAnnotation = function setPendingSelectedAnnotation(
|
|
|
81
81
|
};
|
|
82
82
|
var removeInlineCommentFromNode = function removeInlineCommentFromNode(id) {
|
|
83
83
|
var supportedBlockNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
84
|
-
var
|
|
85
|
-
var
|
|
84
|
+
var isBlockNodeSupported = arguments.length > 2 ? arguments[2] : undefined;
|
|
85
|
+
var state = arguments.length > 3 ? arguments[3] : undefined;
|
|
86
|
+
var dispatch = arguments.length > 4 ? arguments[4] : undefined;
|
|
86
87
|
var tr = state.tr,
|
|
87
88
|
selection = state.selection;
|
|
88
|
-
|
|
89
|
+
var selectedNodeIsSupported = selection instanceof NodeSelection && (isSupportedBlockNode(selection.node, supportedBlockNodes, isBlockNodeSupported) || selection.node.type === state.schema.nodes.mediaSingle && !!selection.node.firstChild && isSupportedBlockNode(selection.node.firstChild, supportedBlockNodes, isBlockNodeSupported));
|
|
90
|
+
if (selectedNodeIsSupported) {
|
|
89
91
|
var $from = selection.$from;
|
|
90
92
|
var currNode = selection.node;
|
|
91
93
|
var from = $from.start();
|
|
@@ -115,10 +117,11 @@ var removeInlineCommentFromNode = function removeInlineCommentFromNode(id) {
|
|
|
115
117
|
};
|
|
116
118
|
export var removeInlineCommentNearSelection = function removeInlineCommentNearSelection(id) {
|
|
117
119
|
var supportedNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
120
|
+
var isBlockNodeSupported = arguments.length > 2 ? arguments[2] : undefined;
|
|
118
121
|
return function (state, dispatch) {
|
|
119
122
|
var tr = state.tr,
|
|
120
123
|
$from = state.selection.$from;
|
|
121
|
-
if (removeInlineCommentFromNode(id, supportedNodes, state, dispatch)) {
|
|
124
|
+
if (removeInlineCommentFromNode(id, supportedNodes, isBlockNodeSupported, state, dispatch)) {
|
|
122
125
|
return true;
|
|
123
126
|
}
|
|
124
127
|
var annotationMarkType = state.schema.marks.annotation;
|
|
@@ -143,6 +146,7 @@ export var removeInlineCommentNearSelection = function removeInlineCommentNearSe
|
|
|
143
146
|
export var removeInlineCommentFromDoc = function removeInlineCommentFromDoc(editorAnalyticsAPI) {
|
|
144
147
|
return function (id) {
|
|
145
148
|
var supportedNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
149
|
+
var isBlockNodeSupported = arguments.length > 2 ? arguments[2] : undefined;
|
|
146
150
|
return function (state, dispatch) {
|
|
147
151
|
var tr = state.tr;
|
|
148
152
|
state.doc.descendants(function (node, pos) {
|
|
@@ -151,11 +155,11 @@ export var removeInlineCommentFromDoc = function removeInlineCommentFromDoc(edit
|
|
|
151
155
|
if (node.type.name === 'mediaInline') {
|
|
152
156
|
return false;
|
|
153
157
|
}
|
|
154
|
-
var
|
|
158
|
+
var isSupportedBlock = node.isBlock && isSupportedBlockNode(node, supportedNodes, isBlockNodeSupported);
|
|
155
159
|
node.marks.filter(function (mark) {
|
|
156
160
|
return mark.type === state.schema.marks.annotation && mark.attrs.id === id;
|
|
157
161
|
}).forEach(function (mark) {
|
|
158
|
-
if (
|
|
162
|
+
if (isSupportedBlock) {
|
|
159
163
|
tr.removeNodeMark(pos, mark);
|
|
160
164
|
} else {
|
|
161
165
|
tr.removeMark(pos, pos + node.nodeSize, mark);
|
|
@@ -170,10 +174,10 @@ export var removeInlineCommentFromDoc = function removeInlineCommentFromDoc(edit
|
|
|
170
174
|
};
|
|
171
175
|
};
|
|
172
176
|
};
|
|
173
|
-
var getDraftCommandAction = function getDraftCommandAction(drafting, targetType, targetNodeId, supportedBlockNodes, isOpeningMediaCommentFromToolbar) {
|
|
177
|
+
var getDraftCommandAction = function getDraftCommandAction(drafting, targetType, targetNodeId, supportedBlockNodes, isBlockNodeSupported, isOpeningMediaCommentFromToolbar) {
|
|
174
178
|
return function (editorState) {
|
|
175
179
|
// validate selection only when entering draft mode
|
|
176
|
-
if (drafting && isSelectionValid(editorState) !== AnnotationSelectionType.VALID) {
|
|
180
|
+
if (drafting && isSelectionValid(editorState, supportedBlockNodes, isBlockNodeSupported) !== AnnotationSelectionType.VALID) {
|
|
177
181
|
return false;
|
|
178
182
|
}
|
|
179
183
|
return {
|
|
@@ -183,6 +187,7 @@ var getDraftCommandAction = function getDraftCommandAction(drafting, targetType,
|
|
|
183
187
|
editorState: editorState,
|
|
184
188
|
targetType: targetType,
|
|
185
189
|
supportedBlockNodes: supportedBlockNodes,
|
|
190
|
+
isBlockNodeSupported: isBlockNodeSupported,
|
|
186
191
|
targetNodeId: targetNodeId,
|
|
187
192
|
isOpeningMediaCommentFromToolbar: isOpeningMediaCommentFromToolbar
|
|
188
193
|
}
|
|
@@ -198,11 +203,12 @@ var getDraftCommandAction = function getDraftCommandAction(drafting, targetType,
|
|
|
198
203
|
*/
|
|
199
204
|
export var showInlineCommentForBlockNode = function showInlineCommentForBlockNode() {
|
|
200
205
|
var supportedBlockNodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
206
|
+
var isBlockNodeSupported = arguments.length > 1 ? arguments[1] : undefined;
|
|
201
207
|
return function (node, viewMethod, isOpeningMediaCommentFromToolbar) {
|
|
202
208
|
return function (state, dispatch) {
|
|
203
209
|
var pluginState = getPluginState(state);
|
|
204
210
|
var annotation = state.schema.marks.annotation;
|
|
205
|
-
if (node && node.isBlock &&
|
|
211
|
+
if (node && node.isBlock && isSupportedBlockNode(node, supportedBlockNodes, isBlockNodeSupported)) {
|
|
206
212
|
var unresolvedAnnotationMarks = ((node === null || node === void 0 ? void 0 : node.marks) || []).filter(function (mark) {
|
|
207
213
|
return mark.type === annotation && !(pluginState !== null && pluginState !== void 0 && pluginState.annotations[mark.attrs.id]);
|
|
208
214
|
}).map(function (mark) {
|
|
@@ -235,12 +241,13 @@ export var showInlineCommentForBlockNode = function showInlineCommentForBlockNod
|
|
|
235
241
|
export var setInlineCommentDraftState = function setInlineCommentDraftState(editorAnalyticsAPI) {
|
|
236
242
|
var supportedBlockNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
237
243
|
var api = arguments.length > 2 ? arguments[2] : undefined;
|
|
244
|
+
var isBlockNodeSupported = arguments.length > 3 ? arguments[3] : undefined;
|
|
238
245
|
return function (drafting) {
|
|
239
246
|
var inputMethod = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : INPUT_METHOD.TOOLBAR;
|
|
240
247
|
var targetType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'inline';
|
|
241
248
|
var targetNodeId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
|
|
242
249
|
var isOpeningMediaCommentFromToolbar = arguments.length > 4 ? arguments[4] : undefined;
|
|
243
|
-
var commandAction = getDraftCommandAction(drafting, targetType, targetNodeId, supportedBlockNodes, isOpeningMediaCommentFromToolbar);
|
|
250
|
+
var commandAction = getDraftCommandAction(drafting, targetType, targetNodeId, supportedBlockNodes, isBlockNodeSupported, isOpeningMediaCommentFromToolbar);
|
|
244
251
|
if (Boolean(api === null || api === void 0 ? void 0 : api.toolbar)) {
|
|
245
252
|
return function (state, dispatch) {
|
|
246
253
|
var tr = transform.handleDraftState(editorAnalyticsAPI)(drafting, inputMethod)(state.tr, state);
|
|
@@ -266,7 +273,7 @@ export var setInlineCommentDraftState = function setInlineCommentDraftState(edit
|
|
|
266
273
|
};
|
|
267
274
|
};
|
|
268
275
|
export var addInlineComment = function addInlineComment(editorAnalyticsAPI, editorAPI) {
|
|
269
|
-
return function (id, supportedBlockNodes) {
|
|
276
|
+
return function (id, supportedBlockNodes, isBlockNodeSupported) {
|
|
270
277
|
var commandAction = function commandAction(editorState) {
|
|
271
278
|
return {
|
|
272
279
|
type: ACTIONS.ADD_INLINE_COMMENT,
|
|
@@ -285,7 +292,7 @@ export var addInlineComment = function addInlineComment(editorAnalyticsAPI, edit
|
|
|
285
292
|
};
|
|
286
293
|
if (Boolean(editorAPI === null || editorAPI === void 0 ? void 0 : editorAPI.toolbar)) {
|
|
287
294
|
return function (state, dispatch) {
|
|
288
|
-
var tr = transform.addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes)(state.tr, state);
|
|
295
|
+
var tr = transform.addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes, isBlockNodeSupported)(state.tr, state);
|
|
289
296
|
tr.setMeta(inlineCommentPluginKey, commandAction(state));
|
|
290
297
|
resetUserIntent(editorAPI, tr);
|
|
291
298
|
if (dispatch) {
|
|
@@ -295,7 +302,7 @@ export var addInlineComment = function addInlineComment(editorAnalyticsAPI, edit
|
|
|
295
302
|
return false;
|
|
296
303
|
};
|
|
297
304
|
} else {
|
|
298
|
-
return createCommand(commandAction, transform.addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes));
|
|
305
|
+
return createCommand(commandAction, transform.addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes, isBlockNodeSupported));
|
|
299
306
|
}
|
|
300
307
|
};
|
|
301
308
|
};
|
|
@@ -333,6 +340,7 @@ export var createAnnotation = function createAnnotation(editorAnalyticsAPI, edit
|
|
|
333
340
|
return function (id) {
|
|
334
341
|
var annotationType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : AnnotationTypes.INLINE_COMMENT;
|
|
335
342
|
var supportedBlockNodes = arguments.length > 2 ? arguments[2] : undefined;
|
|
343
|
+
var isBlockNodeSupported = arguments.length > 3 ? arguments[3] : undefined;
|
|
336
344
|
return function (state, dispatch) {
|
|
337
345
|
// don't try to add if there are is no temp highlight bookmarked
|
|
338
346
|
var _ref = getPluginState(state) || {},
|
|
@@ -341,7 +349,7 @@ export var createAnnotation = function createAnnotation(editorAnalyticsAPI, edit
|
|
|
341
349
|
return false;
|
|
342
350
|
}
|
|
343
351
|
if (annotationType === AnnotationTypes.INLINE_COMMENT) {
|
|
344
|
-
return addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes)(state, dispatch);
|
|
352
|
+
return addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes, isBlockNodeSupported)(state, dispatch);
|
|
345
353
|
}
|
|
346
354
|
return false;
|
|
347
355
|
};
|
|
@@ -9,7 +9,7 @@ import { getDraftCommandAnalyticsPayload, getPluginState, resolveDraftBookmark }
|
|
|
9
9
|
var isAnnotationStep = function isAnnotationStep(step) {
|
|
10
10
|
return step instanceof AddMarkStep && step.mark.type.name === 'annotation';
|
|
11
11
|
};
|
|
12
|
-
var addAnnotationMark = function addAnnotationMark(id, supportedBlockNodes) {
|
|
12
|
+
var addAnnotationMark = function addAnnotationMark(id, supportedBlockNodes, isBlockNodeSupported) {
|
|
13
13
|
return function (transaction, state) {
|
|
14
14
|
var inlineCommentState = getPluginState(state);
|
|
15
15
|
var _ref = inlineCommentState || {},
|
|
@@ -18,7 +18,7 @@ var addAnnotationMark = function addAnnotationMark(id, supportedBlockNodes) {
|
|
|
18
18
|
id: id,
|
|
19
19
|
type: AnnotationTypes.INLINE_COMMENT
|
|
20
20
|
});
|
|
21
|
-
var _resolveDraftBookmark = resolveDraftBookmark(state, bookmark, supportedBlockNodes),
|
|
21
|
+
var _resolveDraftBookmark = resolveDraftBookmark(state, bookmark, supportedBlockNodes, isBlockNodeSupported),
|
|
22
22
|
from = _resolveDraftBookmark.from,
|
|
23
23
|
to = _resolveDraftBookmark.to,
|
|
24
24
|
head = _resolveDraftBookmark.head,
|
|
@@ -42,10 +42,10 @@ var addAnnotationMark = function addAnnotationMark(id, supportedBlockNodes) {
|
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
44
|
var addInlineComment = function addInlineComment(editorAnalyticsAPI, editorAPI) {
|
|
45
|
-
return function (id, supportedBlockNodes) {
|
|
45
|
+
return function (id, supportedBlockNodes, isBlockNodeSupported) {
|
|
46
46
|
return function (transaction, state) {
|
|
47
47
|
var _editorAPI$editorView, _pluginState$featureF;
|
|
48
|
-
var tr = addAnnotationMark(id, supportedBlockNodes)(transaction, state);
|
|
48
|
+
var tr = addAnnotationMark(id, supportedBlockNodes, isBlockNodeSupported)(transaction, state);
|
|
49
49
|
editorAPI === null || editorAPI === void 0 || (_editorAPI$editorView = editorAPI.editorViewModeEffects) === null || _editorAPI$editorView === void 0 || _editorAPI$editorView.actions.applyViewModeStepAt(tr);
|
|
50
50
|
|
|
51
51
|
// add insert analytics step to transaction
|