@atlaskit/editor-plugin-annotation 1.4.1 → 1.5.1
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 +16 -0
- package/dist/cjs/commands/index.js +28 -4
- package/dist/cjs/commands/transform.js +21 -11
- package/dist/cjs/plugin.js +2 -1
- package/dist/cjs/pm-plugins/inline-comment.js +4 -5
- package/dist/cjs/pm-plugins/plugin-factory.js +9 -0
- package/dist/cjs/ui/InlineCommentView.js +2 -1
- package/dist/cjs/utils.js +27 -5
- package/dist/es2019/commands/index.js +20 -4
- package/dist/es2019/commands/transform.js +24 -13
- package/dist/es2019/plugin.js +3 -2
- package/dist/es2019/pm-plugins/inline-comment.js +3 -4
- package/dist/es2019/pm-plugins/plugin-factory.js +13 -1
- package/dist/es2019/ui/InlineCommentView.js +2 -1
- package/dist/es2019/utils.js +21 -4
- package/dist/esm/commands/index.js +27 -3
- package/dist/esm/commands/transform.js +23 -13
- package/dist/esm/plugin.js +3 -2
- package/dist/esm/pm-plugins/inline-comment.js +5 -6
- package/dist/esm/pm-plugins/plugin-factory.js +10 -1
- package/dist/esm/ui/InlineCommentView.js +2 -1
- package/dist/esm/utils.js +26 -4
- package/dist/types/commands/index.d.ts +4 -2
- package/dist/types/commands/transform.d.ts +3 -2
- package/dist/types/types.d.ts +8 -0
- package/dist/types/utils.d.ts +5 -1
- package/dist/types-ts4.5/commands/index.d.ts +4 -2
- package/dist/types-ts4.5/commands/transform.d.ts +3 -2
- package/dist/types-ts4.5/types.d.ts +8 -0
- package/dist/types-ts4.5/utils.d.ts +5 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-annotation
|
|
2
2
|
|
|
3
|
+
## 1.5.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#83942](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/83942) [`210a84148721`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/210a84148721) - [ED-22547] Publish draft comment for media node when saving
|
|
8
|
+
|
|
9
|
+
## 1.5.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#82581](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/82581) [`c1be75ae15b6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c1be75ae15b6) - ED-22606 add toggle inline comment action
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#81777](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/81777) [`c6d7a5378751`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c6d7a5378751) - Bump adf-schema to 35.7.0
|
|
18
|
+
|
|
3
19
|
## 1.4.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.updateMouseState = exports.updateInlineCommentResolvedState = exports.setSelectedAnnotation = exports.setInlineCommentsVisibility = exports.setInlineCommentDraftState = exports.removeInlineCommentNearSelection = exports.createAnnotation = exports.closeComponent = exports.clearDirtyMark = exports.addInlineComment = void 0;
|
|
7
|
+
exports.updateMouseState = exports.updateInlineCommentResolvedState = exports.showInlineCommentForBlockNode = exports.setSelectedAnnotation = exports.setInlineCommentsVisibility = exports.setInlineCommentDraftState = exports.removeInlineCommentNearSelection = exports.createAnnotation = exports.closeComponent = exports.clearDirtyMark = exports.addInlineComment = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _adfSchema = require("@atlaskit/adf-schema");
|
|
10
10
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
@@ -118,6 +118,29 @@ var getDraftCommandAction = function getDraftCommandAction(drafting, targetType,
|
|
|
118
118
|
};
|
|
119
119
|
};
|
|
120
120
|
};
|
|
121
|
+
var showInlineCommentForBlockNode = exports.showInlineCommentForBlockNode = function showInlineCommentForBlockNode() {
|
|
122
|
+
var supportedBlockNodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
123
|
+
return function (node) {
|
|
124
|
+
if (node && node.isBlock && supportedBlockNodes.includes(node.type.name)) {
|
|
125
|
+
var annotationMarks = ((node === null || node === void 0 ? void 0 : node.marks) || []).filter(function (mark) {
|
|
126
|
+
return mark.type.name === 'annotation';
|
|
127
|
+
}).map(function (mark) {
|
|
128
|
+
return {
|
|
129
|
+
id: mark.attrs.id,
|
|
130
|
+
type: mark.attrs.annotationType
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
if (annotationMarks.length) {
|
|
134
|
+
return (0, _pluginFactory.createCommand)({
|
|
135
|
+
type: _types.ACTIONS.SET_SELECTED_ANNOTATION,
|
|
136
|
+
data: {
|
|
137
|
+
selectedAnnotations: annotationMarks
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
};
|
|
121
144
|
var setInlineCommentDraftState = exports.setInlineCommentDraftState = function setInlineCommentDraftState(editorAnalyticsAPI) {
|
|
122
145
|
var supportedBlockNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
123
146
|
return function (drafting) {
|
|
@@ -129,7 +152,7 @@ var setInlineCommentDraftState = exports.setInlineCommentDraftState = function s
|
|
|
129
152
|
};
|
|
130
153
|
};
|
|
131
154
|
var addInlineComment = exports.addInlineComment = function addInlineComment(editorAnalyticsAPI, editorAPI) {
|
|
132
|
-
return function (id) {
|
|
155
|
+
return function (id, supportedBlockNodes) {
|
|
133
156
|
var commandAction = function commandAction(editorState) {
|
|
134
157
|
return {
|
|
135
158
|
type: _types.ACTIONS.ADD_INLINE_COMMENT,
|
|
@@ -146,7 +169,7 @@ var addInlineComment = exports.addInlineComment = function addInlineComment(edit
|
|
|
146
169
|
}
|
|
147
170
|
};
|
|
148
171
|
};
|
|
149
|
-
return (0, _pluginFactory.createCommand)(commandAction, _transform.default.addInlineComment(editorAnalyticsAPI, editorAPI)(id));
|
|
172
|
+
return (0, _pluginFactory.createCommand)(commandAction, _transform.default.addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes));
|
|
150
173
|
};
|
|
151
174
|
};
|
|
152
175
|
var updateMouseState = exports.updateMouseState = function updateMouseState(mouseData) {
|
|
@@ -171,6 +194,7 @@ var setSelectedAnnotation = exports.setSelectedAnnotation = function setSelected
|
|
|
171
194
|
var createAnnotation = exports.createAnnotation = function createAnnotation(editorAnalyticsAPI, editorAPI) {
|
|
172
195
|
return function (id) {
|
|
173
196
|
var annotationType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _adfSchema.AnnotationTypes.INLINE_COMMENT;
|
|
197
|
+
var supportedBlockNodes = arguments.length > 2 ? arguments[2] : undefined;
|
|
174
198
|
return function (state, dispatch) {
|
|
175
199
|
// don't try to add if there are is no temp highlight bookmarked
|
|
176
200
|
var _ref = (0, _utils.getPluginState)(state) || {},
|
|
@@ -179,7 +203,7 @@ var createAnnotation = exports.createAnnotation = function createAnnotation(edit
|
|
|
179
203
|
return false;
|
|
180
204
|
}
|
|
181
205
|
if (annotationType === _adfSchema.AnnotationTypes.INLINE_COMMENT) {
|
|
182
|
-
return addInlineComment(editorAnalyticsAPI, editorAPI)(id)(state, dispatch);
|
|
206
|
+
return addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes)(state, dispatch);
|
|
183
207
|
}
|
|
184
208
|
return false;
|
|
185
209
|
};
|
|
@@ -9,29 +9,39 @@ var _analytics = require("@atlaskit/editor-common/analytics");
|
|
|
9
9
|
var _mark = require("@atlaskit/editor-common/mark");
|
|
10
10
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
11
11
|
var _utils = require("../utils");
|
|
12
|
-
var addAnnotationMark = function addAnnotationMark(id) {
|
|
12
|
+
var addAnnotationMark = function addAnnotationMark(id, supportedBlockNodes) {
|
|
13
13
|
return function (transaction, state) {
|
|
14
14
|
var inlineCommentState = (0, _utils.getPluginState)(state);
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
to = _getSelectionPosition.to,
|
|
18
|
-
head = _getSelectionPosition.head;
|
|
15
|
+
var _ref = inlineCommentState || {},
|
|
16
|
+
bookmark = _ref.bookmark;
|
|
19
17
|
var annotationMark = state.schema.marks.annotation.create({
|
|
20
18
|
id: id,
|
|
21
19
|
type: _adfSchema.AnnotationTypes.INLINE_COMMENT
|
|
22
20
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
var _resolveDraftBookmark = (0, _utils.resolveDraftBookmark)(state, bookmark, supportedBlockNodes),
|
|
22
|
+
from = _resolveDraftBookmark.from,
|
|
23
|
+
to = _resolveDraftBookmark.to,
|
|
24
|
+
head = _resolveDraftBookmark.head,
|
|
25
|
+
isBlockNode = _resolveDraftBookmark.isBlockNode;
|
|
26
|
+
var tr = transaction;
|
|
27
|
+
if (isBlockNode) {
|
|
28
|
+
tr = tr.addNodeMark(from, annotationMark);
|
|
29
|
+
// Set selection on the node so that we can display view component
|
|
30
|
+
tr.setSelection(_state.NodeSelection.create(tr.doc, from));
|
|
31
|
+
} else {
|
|
32
|
+
// Apply the mark only to text node in the range.
|
|
33
|
+
var _tr = (0, _mark.applyMarkOnRange)(from, to, false, annotationMark, transaction);
|
|
34
|
+
// set selection back to the end of annotation once annotation mark is applied
|
|
35
|
+
_tr.setSelection(_state.TextSelection.create(_tr.doc, head));
|
|
36
|
+
}
|
|
27
37
|
return tr;
|
|
28
38
|
};
|
|
29
39
|
};
|
|
30
40
|
var addInlineComment = function addInlineComment(editorAnalyticsAPI, editorAPI) {
|
|
31
|
-
return function (id) {
|
|
41
|
+
return function (id, supportedBlockNodes) {
|
|
32
42
|
return function (transaction, state) {
|
|
33
43
|
var _editorAPI$editorView;
|
|
34
|
-
var tr = addAnnotationMark(id)(transaction, state);
|
|
44
|
+
var tr = addAnnotationMark(id, supportedBlockNodes)(transaction, state);
|
|
35
45
|
editorAPI === null || editorAPI === void 0 || (_editorAPI$editorView = editorAPI.editorViewMode) === null || _editorAPI$editorView === void 0 || _editorAPI$editorView.actions.applyViewModeStepAt(tr);
|
|
36
46
|
|
|
37
47
|
// add insert analytics step to transaction
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -37,7 +37,8 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
|
|
|
37
37
|
},
|
|
38
38
|
actions: {
|
|
39
39
|
stripNonExistingAnnotations: _utils.stripNonExistingAnnotations,
|
|
40
|
-
setInlineCommentDraftState: (0, _commands.setInlineCommentDraftState)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes)
|
|
40
|
+
setInlineCommentDraftState: (0, _commands.setInlineCommentDraftState)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes),
|
|
41
|
+
showCommentForBlockNode: (0, _commands.showInlineCommentForBlockNode)(annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes)
|
|
41
42
|
},
|
|
42
43
|
getSharedState: function getSharedState(editorState) {
|
|
43
44
|
if (!editorState) {
|
|
@@ -231,18 +231,17 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
|
|
|
231
231
|
}).forEach(function (mark) {
|
|
232
232
|
if (isVisible) {
|
|
233
233
|
var isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
|
|
234
|
+
var isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
|
|
235
|
+
return selectedAnnotation.id === mark.attrs.id;
|
|
236
|
+
}));
|
|
234
237
|
if (isSupportedBlockNode) {
|
|
235
|
-
var isBlockNodeSelected = (0, _utils.isCurrentBlockNodeSelected)(state, node);
|
|
236
238
|
var attrs = isUnresolved ? {
|
|
237
|
-
class:
|
|
239
|
+
class: isSelected ? "".concat(_styles.BlockAnnotationSharedClassNames.focus) : "".concat(_styles.BlockAnnotationSharedClassNames.blur)
|
|
238
240
|
} : {};
|
|
239
241
|
focusDecorations.push(_view.Decoration.node(pos, pos + node.nodeSize, attrs, {
|
|
240
242
|
key: _utils.decorationKey.block
|
|
241
243
|
}));
|
|
242
244
|
} else {
|
|
243
|
-
var isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
|
|
244
|
-
return selectedAnnotation.id === mark.attrs.id;
|
|
245
|
-
}));
|
|
246
245
|
focusDecorations.push(_view.Decoration.inline(pos, pos + node.nodeSize, {
|
|
247
246
|
class: "".concat((0, _nodeviews.getAnnotationViewClassname)(isUnresolved, isSelected), " ").concat(isUnresolved),
|
|
248
247
|
nodeName: 'span'
|
|
@@ -22,6 +22,7 @@ var handleDocChanged = function handleDocChanged(tr, prevPluginState) {
|
|
|
22
22
|
};
|
|
23
23
|
var getSelectionChangedHandler = function getSelectionChangedHandler(reopenCommentView) {
|
|
24
24
|
return function (tr, pluginState) {
|
|
25
|
+
var _pluginState$featureF;
|
|
25
26
|
if (pluginState.skipSelectionHandling) {
|
|
26
27
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
27
28
|
skipSelectionHandling: false
|
|
@@ -29,6 +30,14 @@ var getSelectionChangedHandler = function getSelectionChangedHandler(reopenComme
|
|
|
29
30
|
isInlineCommentViewClosed: false
|
|
30
31
|
});
|
|
31
32
|
}
|
|
33
|
+
if ((_pluginState$featureF = pluginState.featureFlagsPluginState) !== null && _pluginState$featureF !== void 0 && _pluginState$featureF.commentsOnMedia &&
|
|
34
|
+
// If pluginState.selectedAnnotations is annotations of block node, i.e. when a new comment is created,
|
|
35
|
+
// we keep it as it is so that we can show comment view component with the newly created comment
|
|
36
|
+
(0, _utils2.isBlockNodeAnnotationsSelected)(tr.selection, pluginState.selectedAnnotations)) {
|
|
37
|
+
return _objectSpread(_objectSpread({}, pluginState), reopenCommentView && {
|
|
38
|
+
isInlineCommentViewClosed: false
|
|
39
|
+
});
|
|
40
|
+
}
|
|
32
41
|
var selectedAnnotations = (0, _utils2.findAnnotationsInSelection)(tr.selection, tr.doc);
|
|
33
42
|
if (selectedAnnotations.length === 0) {
|
|
34
43
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.InlineCommentView = InlineCommentView;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _adfSchema = require("@atlaskit/adf-schema");
|
|
10
11
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
12
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
12
13
|
var _commands = require("../commands");
|
|
@@ -91,7 +92,7 @@ function InlineCommentView(_ref) {
|
|
|
91
92
|
dom: dom,
|
|
92
93
|
textSelection: textSelection,
|
|
93
94
|
onCreate: function onCreate(id) {
|
|
94
|
-
(0, _commands.createAnnotation)(editorAnalyticsAPI, editorAPI)(id)(editorView.state, editorView.dispatch);
|
|
95
|
+
(0, _commands.createAnnotation)(editorAnalyticsAPI, editorAPI)(id, _adfSchema.AnnotationTypes.INLINE_COMMENT, inlineCommentProvider.supportedBlockNodes)(editorView.state, editorView.dispatch);
|
|
95
96
|
!editorView.hasFocus() && editorView.focus();
|
|
96
97
|
},
|
|
97
98
|
onClose: function onClose() {
|
package/dist/cjs/utils.js
CHANGED
|
@@ -21,7 +21,7 @@ Object.defineProperty(exports, "hasAnnotationMark", {
|
|
|
21
21
|
});
|
|
22
22
|
exports.hasInvalidNodes = void 0;
|
|
23
23
|
exports.hasInvalidWhitespaceNode = hasInvalidWhitespaceNode;
|
|
24
|
-
exports.isCurrentBlockNodeSelected = exports.inlineCommentPluginKey = void 0;
|
|
24
|
+
exports.isCurrentBlockNodeSelected = exports.isBlockNodeAnnotationsSelected = exports.inlineCommentPluginKey = void 0;
|
|
25
25
|
exports.isSelectedAnnotationsChanged = isSelectedAnnotationsChanged;
|
|
26
26
|
exports.resolveDraftBookmark = exports.isSupportedBlockNode = exports.isSelectionValid = void 0;
|
|
27
27
|
exports.stripNonExistingAnnotations = stripNonExistingAnnotations;
|
|
@@ -202,14 +202,15 @@ var findAnnotationsInSelection = exports.findAnnotationsInSelection = function f
|
|
|
202
202
|
var resolveDraftBookmark = exports.resolveDraftBookmark = function resolveDraftBookmark(editorState, bookmark) {
|
|
203
203
|
var supportedBlockNodes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
204
204
|
var doc = editorState.doc;
|
|
205
|
-
var resolvedBookmark = bookmark.resolve(doc);
|
|
205
|
+
var resolvedBookmark = bookmark ? bookmark.resolve(doc) : editorState.selection;
|
|
206
206
|
var from = resolvedBookmark.from,
|
|
207
207
|
to = resolvedBookmark.to,
|
|
208
208
|
head = resolvedBookmark.head;
|
|
209
209
|
var draftBookmark = {
|
|
210
210
|
from: from,
|
|
211
211
|
to: to,
|
|
212
|
-
head: head
|
|
212
|
+
head: head,
|
|
213
|
+
isBlockNode: false
|
|
213
214
|
};
|
|
214
215
|
if (resolvedBookmark instanceof _state.NodeSelection) {
|
|
215
216
|
// It's possible that annotation is only allowed in child node instead parent (e.g. mediaSingle vs media),
|
|
@@ -225,7 +226,8 @@ var resolveDraftBookmark = exports.resolveDraftBookmark = function resolveDraftB
|
|
|
225
226
|
draftBookmark = {
|
|
226
227
|
from: pos,
|
|
227
228
|
to: nodeEndsAt,
|
|
228
|
-
head: nodeEndsAt
|
|
229
|
+
head: nodeEndsAt,
|
|
230
|
+
isBlockNode: node.isBlock
|
|
229
231
|
};
|
|
230
232
|
nodeFound = true;
|
|
231
233
|
return false;
|
|
@@ -444,4 +446,24 @@ function isSelectedAnnotationsChanged(oldSelectedAnnotations, newSelectedAnnotat
|
|
|
444
446
|
return annotation.id === pluginStateAnnotation.id && annotation.type === pluginStateAnnotation.type;
|
|
445
447
|
});
|
|
446
448
|
});
|
|
447
|
-
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Checks if the selectedAnnotations are the same as the annotations on the selected block node
|
|
453
|
+
*/
|
|
454
|
+
var isBlockNodeAnnotationsSelected = exports.isBlockNodeAnnotationsSelected = function isBlockNodeAnnotationsSelected(selection) {
|
|
455
|
+
var selectedAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
456
|
+
if (selectedAnnotations.length && selection instanceof _state.NodeSelection) {
|
|
457
|
+
var node = selection.node.type.name === 'mediaSingle' ? selection.node.firstChild : selection.node;
|
|
458
|
+
var annotationMarks = (node === null || node === void 0 ? void 0 : node.marks.filter(function (mark) {
|
|
459
|
+
return mark.type.name === 'annotation';
|
|
460
|
+
}).map(function (mark) {
|
|
461
|
+
return {
|
|
462
|
+
id: mark.attrs.id,
|
|
463
|
+
type: mark.attrs.annotationType
|
|
464
|
+
};
|
|
465
|
+
})) || [];
|
|
466
|
+
return !isSelectedAnnotationsChanged(selectedAnnotations, annotationMarks);
|
|
467
|
+
}
|
|
468
|
+
return false;
|
|
469
|
+
};
|
|
@@ -104,11 +104,27 @@ const getDraftCommandAction = (drafting, targetType, isCommentOnMediaOn, support
|
|
|
104
104
|
};
|
|
105
105
|
};
|
|
106
106
|
};
|
|
107
|
+
export const showInlineCommentForBlockNode = (supportedBlockNodes = []) => node => {
|
|
108
|
+
if (node && node.isBlock && supportedBlockNodes.includes(node.type.name)) {
|
|
109
|
+
const annotationMarks = ((node === null || node === void 0 ? void 0 : node.marks) || []).filter(mark => mark.type.name === 'annotation').map(mark => ({
|
|
110
|
+
id: mark.attrs.id,
|
|
111
|
+
type: mark.attrs.annotationType
|
|
112
|
+
}));
|
|
113
|
+
if (annotationMarks.length) {
|
|
114
|
+
return createCommand({
|
|
115
|
+
type: ACTIONS.SET_SELECTED_ANNOTATION,
|
|
116
|
+
data: {
|
|
117
|
+
selectedAnnotations: annotationMarks
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
107
123
|
export const setInlineCommentDraftState = (editorAnalyticsAPI, supportedBlockNodes = []) => (drafting, inputMethod = INPUT_METHOD.TOOLBAR, targetType = 'inline', isCommentOnMediaOn = false) => {
|
|
108
124
|
const commandAction = getDraftCommandAction(drafting, targetType, isCommentOnMediaOn, supportedBlockNodes);
|
|
109
125
|
return createCommand(commandAction, transform.addOpenCloseAnalytics(editorAnalyticsAPI)(drafting, inputMethod));
|
|
110
126
|
};
|
|
111
|
-
export const addInlineComment = (editorAnalyticsAPI, editorAPI) => id => {
|
|
127
|
+
export const addInlineComment = (editorAnalyticsAPI, editorAPI) => (id, supportedBlockNodes) => {
|
|
112
128
|
const commandAction = editorState => ({
|
|
113
129
|
type: ACTIONS.ADD_INLINE_COMMENT,
|
|
114
130
|
data: {
|
|
@@ -125,7 +141,7 @@ export const addInlineComment = (editorAnalyticsAPI, editorAPI) => id => {
|
|
|
125
141
|
editorState
|
|
126
142
|
}
|
|
127
143
|
});
|
|
128
|
-
return createCommand(commandAction, transform.addInlineComment(editorAnalyticsAPI, editorAPI)(id));
|
|
144
|
+
return createCommand(commandAction, transform.addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes));
|
|
129
145
|
};
|
|
130
146
|
export const updateMouseState = mouseData => createCommand({
|
|
131
147
|
type: ACTIONS.INLINE_COMMENT_UPDATE_MOUSE_STATE,
|
|
@@ -142,7 +158,7 @@ export const setSelectedAnnotation = id => createCommand({
|
|
|
142
158
|
}]
|
|
143
159
|
}
|
|
144
160
|
});
|
|
145
|
-
export const createAnnotation = (editorAnalyticsAPI, editorAPI) => (id, annotationType = AnnotationTypes.INLINE_COMMENT) => (state, dispatch) => {
|
|
161
|
+
export const createAnnotation = (editorAnalyticsAPI, editorAPI) => (id, annotationType = AnnotationTypes.INLINE_COMMENT, supportedBlockNodes) => (state, dispatch) => {
|
|
146
162
|
// don't try to add if there are is no temp highlight bookmarked
|
|
147
163
|
const {
|
|
148
164
|
bookmark
|
|
@@ -151,7 +167,7 @@ export const createAnnotation = (editorAnalyticsAPI, editorAPI) => (id, annotati
|
|
|
151
167
|
return false;
|
|
152
168
|
}
|
|
153
169
|
if (annotationType === AnnotationTypes.INLINE_COMMENT) {
|
|
154
|
-
return addInlineComment(editorAnalyticsAPI, editorAPI)(id)(state, dispatch);
|
|
170
|
+
return addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes)(state, dispatch);
|
|
155
171
|
}
|
|
156
172
|
return false;
|
|
157
173
|
};
|
|
@@ -1,28 +1,39 @@
|
|
|
1
1
|
import { AnnotationTypes } from '@atlaskit/adf-schema';
|
|
2
2
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import { applyMarkOnRange } from '@atlaskit/editor-common/mark';
|
|
4
|
-
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
-
import { getDraftCommandAnalyticsPayload, getPluginState,
|
|
6
|
-
const addAnnotationMark = id => (transaction, state) => {
|
|
4
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import { getDraftCommandAnalyticsPayload, getPluginState, resolveDraftBookmark } from '../utils';
|
|
6
|
+
const addAnnotationMark = (id, supportedBlockNodes) => (transaction, state) => {
|
|
7
7
|
const inlineCommentState = getPluginState(state);
|
|
8
8
|
const {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
head
|
|
12
|
-
} = getSelectionPositions(state, inlineCommentState);
|
|
9
|
+
bookmark
|
|
10
|
+
} = inlineCommentState || {};
|
|
13
11
|
const annotationMark = state.schema.marks.annotation.create({
|
|
14
12
|
id,
|
|
15
13
|
type: AnnotationTypes.INLINE_COMMENT
|
|
16
14
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const {
|
|
16
|
+
from,
|
|
17
|
+
to,
|
|
18
|
+
head,
|
|
19
|
+
isBlockNode
|
|
20
|
+
} = resolveDraftBookmark(state, bookmark, supportedBlockNodes);
|
|
21
|
+
let tr = transaction;
|
|
22
|
+
if (isBlockNode) {
|
|
23
|
+
tr = tr.addNodeMark(from, annotationMark);
|
|
24
|
+
// Set selection on the node so that we can display view component
|
|
25
|
+
tr.setSelection(NodeSelection.create(tr.doc, from));
|
|
26
|
+
} else {
|
|
27
|
+
// Apply the mark only to text node in the range.
|
|
28
|
+
let tr = applyMarkOnRange(from, to, false, annotationMark, transaction);
|
|
29
|
+
// set selection back to the end of annotation once annotation mark is applied
|
|
30
|
+
tr.setSelection(TextSelection.create(tr.doc, head));
|
|
31
|
+
}
|
|
21
32
|
return tr;
|
|
22
33
|
};
|
|
23
|
-
const addInlineComment = (editorAnalyticsAPI, editorAPI) => id => (transaction, state) => {
|
|
34
|
+
const addInlineComment = (editorAnalyticsAPI, editorAPI) => (id, supportedBlockNodes) => (transaction, state) => {
|
|
24
35
|
var _editorAPI$editorView;
|
|
25
|
-
let tr = addAnnotationMark(id)(transaction, state);
|
|
36
|
+
let tr = addAnnotationMark(id, supportedBlockNodes)(transaction, state);
|
|
26
37
|
editorAPI === null || editorAPI === void 0 ? void 0 : (_editorAPI$editorView = editorAPI.editorViewMode) === null || _editorAPI$editorView === void 0 ? void 0 : _editorAPI$editorView.actions.applyViewModeStepAt(tr);
|
|
27
38
|
|
|
28
39
|
// add insert analytics step to transaction
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -3,7 +3,7 @@ import { annotation } from '@atlaskit/adf-schema';
|
|
|
3
3
|
import { AnnotationUpdateEmitter } from '@atlaskit/editor-common/annotation';
|
|
4
4
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
5
5
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
6
|
-
import { setInlineCommentDraftState } from './commands';
|
|
6
|
+
import { setInlineCommentDraftState, showInlineCommentForBlockNode } from './commands';
|
|
7
7
|
import { inlineCommentPlugin } from './pm-plugins/inline-comment';
|
|
8
8
|
import { keymapPlugin } from './pm-plugins/keymap';
|
|
9
9
|
import { buildToolbar } from './toolbar';
|
|
@@ -25,7 +25,8 @@ export const annotationPlugin = ({
|
|
|
25
25
|
},
|
|
26
26
|
actions: {
|
|
27
27
|
stripNonExistingAnnotations,
|
|
28
|
-
setInlineCommentDraftState: setInlineCommentDraftState(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes)
|
|
28
|
+
setInlineCommentDraftState: setInlineCommentDraftState(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes),
|
|
29
|
+
showCommentForBlockNode: showInlineCommentForBlockNode(annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes)
|
|
29
30
|
},
|
|
30
31
|
getSharedState(editorState) {
|
|
31
32
|
if (!editorState) {
|
|
@@ -5,7 +5,7 @@ import { BlockAnnotationSharedClassNames } from '@atlaskit/editor-common/styles'
|
|
|
5
5
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
6
6
|
import { clearDirtyMark, closeComponent, setInlineCommentsVisibility, setSelectedAnnotation, updateInlineCommentResolvedState, updateMouseState } from '../commands';
|
|
7
7
|
import { AnnotationNodeView, getAnnotationViewClassname } from '../nodeviews';
|
|
8
|
-
import { decorationKey, getAllAnnotations, getPluginState, inlineCommentPluginKey
|
|
8
|
+
import { decorationKey, getAllAnnotations, getPluginState, inlineCommentPluginKey } from '../utils';
|
|
9
9
|
import { createPluginState } from './plugin-factory';
|
|
10
10
|
const fetchProviderStates = async (provider, annotationIds) => {
|
|
11
11
|
const data = await provider.getState(annotationIds);
|
|
@@ -169,16 +169,15 @@ export const inlineCommentPlugin = options => {
|
|
|
169
169
|
node.marks.filter(mark => mark.type === state.schema.marks.annotation).forEach(mark => {
|
|
170
170
|
if (isVisible) {
|
|
171
171
|
const isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
|
|
172
|
+
const isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(selectedAnnotation => selectedAnnotation.id === mark.attrs.id));
|
|
172
173
|
if (isSupportedBlockNode) {
|
|
173
|
-
const isBlockNodeSelected = isCurrentBlockNodeSelected(state, node);
|
|
174
174
|
const attrs = isUnresolved ? {
|
|
175
|
-
class:
|
|
175
|
+
class: isSelected ? `${BlockAnnotationSharedClassNames.focus}` : `${BlockAnnotationSharedClassNames.blur}`
|
|
176
176
|
} : {};
|
|
177
177
|
focusDecorations.push(Decoration.node(pos, pos + node.nodeSize, attrs, {
|
|
178
178
|
key: decorationKey.block
|
|
179
179
|
}));
|
|
180
180
|
} else {
|
|
181
|
-
const isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(selectedAnnotation => selectedAnnotation.id === mark.attrs.id));
|
|
182
181
|
focusDecorations.push(Decoration.inline(pos, pos + node.nodeSize, {
|
|
183
182
|
class: `${getAnnotationViewClassname(isUnresolved, isSelected)} ${isUnresolved}`,
|
|
184
183
|
nodeName: 'span'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { pluginFactory } from '@atlaskit/editor-common/utils';
|
|
2
2
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
-
import { decorationKey, findAnnotationsInSelection, inlineCommentPluginKey, isSelectedAnnotationsChanged } from '../utils';
|
|
3
|
+
import { decorationKey, findAnnotationsInSelection, inlineCommentPluginKey, isBlockNodeAnnotationsSelected, isSelectedAnnotationsChanged } from '../utils';
|
|
4
4
|
import reducer from './reducer';
|
|
5
5
|
const handleDocChanged = (tr, prevPluginState) => {
|
|
6
6
|
if (!tr.getMeta('replaceDocument')) {
|
|
@@ -12,6 +12,7 @@ const handleDocChanged = (tr, prevPluginState) => {
|
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
const getSelectionChangedHandler = reopenCommentView => (tr, pluginState) => {
|
|
15
|
+
var _pluginState$featureF;
|
|
15
16
|
if (pluginState.skipSelectionHandling) {
|
|
16
17
|
return {
|
|
17
18
|
...pluginState,
|
|
@@ -21,6 +22,17 @@ const getSelectionChangedHandler = reopenCommentView => (tr, pluginState) => {
|
|
|
21
22
|
})
|
|
22
23
|
};
|
|
23
24
|
}
|
|
25
|
+
if ((_pluginState$featureF = pluginState.featureFlagsPluginState) !== null && _pluginState$featureF !== void 0 && _pluginState$featureF.commentsOnMedia &&
|
|
26
|
+
// If pluginState.selectedAnnotations is annotations of block node, i.e. when a new comment is created,
|
|
27
|
+
// we keep it as it is so that we can show comment view component with the newly created comment
|
|
28
|
+
isBlockNodeAnnotationsSelected(tr.selection, pluginState.selectedAnnotations)) {
|
|
29
|
+
return {
|
|
30
|
+
...pluginState,
|
|
31
|
+
...(reopenCommentView && {
|
|
32
|
+
isInlineCommentViewClosed: false
|
|
33
|
+
})
|
|
34
|
+
};
|
|
35
|
+
}
|
|
24
36
|
const selectedAnnotations = findAnnotationsInSelection(tr.selection, tr.doc);
|
|
25
37
|
if (selectedAnnotations.length === 0) {
|
|
26
38
|
return {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { AnnotationTypes } from '@atlaskit/adf-schema';
|
|
2
3
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, CONTENT_COMPONENT, EVENT_TYPE, RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
4
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
4
5
|
import { closeComponent, createAnnotation, removeInlineCommentNearSelection, setInlineCommentDraftState, updateInlineCommentResolvedState } from '../commands';
|
|
@@ -91,7 +92,7 @@ export function InlineCommentView({
|
|
|
91
92
|
dom: dom,
|
|
92
93
|
textSelection: textSelection,
|
|
93
94
|
onCreate: id => {
|
|
94
|
-
createAnnotation(editorAnalyticsAPI, editorAPI)(id)(editorView.state, editorView.dispatch);
|
|
95
|
+
createAnnotation(editorAnalyticsAPI, editorAPI)(id, AnnotationTypes.INLINE_COMMENT, inlineCommentProvider.supportedBlockNodes)(editorView.state, editorView.dispatch);
|
|
95
96
|
!editorView.hasFocus() && editorView.focus();
|
|
96
97
|
},
|
|
97
98
|
onClose: () => {
|
package/dist/es2019/utils.js
CHANGED
|
@@ -162,7 +162,7 @@ export const resolveDraftBookmark = (editorState, bookmark, supportedBlockNodes
|
|
|
162
162
|
const {
|
|
163
163
|
doc
|
|
164
164
|
} = editorState;
|
|
165
|
-
const resolvedBookmark = bookmark.resolve(doc);
|
|
165
|
+
const resolvedBookmark = bookmark ? bookmark.resolve(doc) : editorState.selection;
|
|
166
166
|
const {
|
|
167
167
|
from,
|
|
168
168
|
to,
|
|
@@ -171,7 +171,8 @@ export const resolveDraftBookmark = (editorState, bookmark, supportedBlockNodes
|
|
|
171
171
|
let draftBookmark = {
|
|
172
172
|
from,
|
|
173
173
|
to,
|
|
174
|
-
head
|
|
174
|
+
head,
|
|
175
|
+
isBlockNode: false
|
|
175
176
|
};
|
|
176
177
|
if (resolvedBookmark instanceof NodeSelection) {
|
|
177
178
|
// It's possible that annotation is only allowed in child node instead parent (e.g. mediaSingle vs media),
|
|
@@ -187,7 +188,8 @@ export const resolveDraftBookmark = (editorState, bookmark, supportedBlockNodes
|
|
|
187
188
|
draftBookmark = {
|
|
188
189
|
from: pos,
|
|
189
190
|
to: nodeEndsAt,
|
|
190
|
-
head: nodeEndsAt
|
|
191
|
+
head: nodeEndsAt,
|
|
192
|
+
isBlockNode: node.isBlock
|
|
191
193
|
};
|
|
192
194
|
nodeFound = true;
|
|
193
195
|
return false;
|
|
@@ -408,4 +410,19 @@ export function isSelectedAnnotationsChanged(oldSelectedAnnotations, newSelected
|
|
|
408
410
|
return newSelectedAnnotations.length !== oldSelectedAnnotations.length ||
|
|
409
411
|
// assuming annotations have unique id's for simplicity
|
|
410
412
|
newSelectedAnnotations.some(annotation => !oldSelectedAnnotations.find(pluginStateAnnotation => annotation.id === pluginStateAnnotation.id && annotation.type === pluginStateAnnotation.type));
|
|
411
|
-
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Checks if the selectedAnnotations are the same as the annotations on the selected block node
|
|
417
|
+
*/
|
|
418
|
+
export const isBlockNodeAnnotationsSelected = (selection, selectedAnnotations = []) => {
|
|
419
|
+
if (selectedAnnotations.length && selection instanceof NodeSelection) {
|
|
420
|
+
const node = selection.node.type.name === 'mediaSingle' ? selection.node.firstChild : selection.node;
|
|
421
|
+
const annotationMarks = (node === null || node === void 0 ? void 0 : node.marks.filter(mark => mark.type.name === 'annotation').map(mark => ({
|
|
422
|
+
id: mark.attrs.id,
|
|
423
|
+
type: mark.attrs.annotationType
|
|
424
|
+
}))) || [];
|
|
425
|
+
return !isSelectedAnnotationsChanged(selectedAnnotations, annotationMarks);
|
|
426
|
+
}
|
|
427
|
+
return false;
|
|
428
|
+
};
|
|
@@ -111,6 +111,29 @@ var getDraftCommandAction = function getDraftCommandAction(drafting, targetType,
|
|
|
111
111
|
};
|
|
112
112
|
};
|
|
113
113
|
};
|
|
114
|
+
export var showInlineCommentForBlockNode = function showInlineCommentForBlockNode() {
|
|
115
|
+
var supportedBlockNodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
116
|
+
return function (node) {
|
|
117
|
+
if (node && node.isBlock && supportedBlockNodes.includes(node.type.name)) {
|
|
118
|
+
var annotationMarks = ((node === null || node === void 0 ? void 0 : node.marks) || []).filter(function (mark) {
|
|
119
|
+
return mark.type.name === 'annotation';
|
|
120
|
+
}).map(function (mark) {
|
|
121
|
+
return {
|
|
122
|
+
id: mark.attrs.id,
|
|
123
|
+
type: mark.attrs.annotationType
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
if (annotationMarks.length) {
|
|
127
|
+
return createCommand({
|
|
128
|
+
type: ACTIONS.SET_SELECTED_ANNOTATION,
|
|
129
|
+
data: {
|
|
130
|
+
selectedAnnotations: annotationMarks
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
};
|
|
114
137
|
export var setInlineCommentDraftState = function setInlineCommentDraftState(editorAnalyticsAPI) {
|
|
115
138
|
var supportedBlockNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
116
139
|
return function (drafting) {
|
|
@@ -122,7 +145,7 @@ export var setInlineCommentDraftState = function setInlineCommentDraftState(edit
|
|
|
122
145
|
};
|
|
123
146
|
};
|
|
124
147
|
export var addInlineComment = function addInlineComment(editorAnalyticsAPI, editorAPI) {
|
|
125
|
-
return function (id) {
|
|
148
|
+
return function (id, supportedBlockNodes) {
|
|
126
149
|
var commandAction = function commandAction(editorState) {
|
|
127
150
|
return {
|
|
128
151
|
type: ACTIONS.ADD_INLINE_COMMENT,
|
|
@@ -139,7 +162,7 @@ export var addInlineComment = function addInlineComment(editorAnalyticsAPI, edit
|
|
|
139
162
|
}
|
|
140
163
|
};
|
|
141
164
|
};
|
|
142
|
-
return createCommand(commandAction, transform.addInlineComment(editorAnalyticsAPI, editorAPI)(id));
|
|
165
|
+
return createCommand(commandAction, transform.addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes));
|
|
143
166
|
};
|
|
144
167
|
};
|
|
145
168
|
export var updateMouseState = function updateMouseState(mouseData) {
|
|
@@ -164,6 +187,7 @@ export var setSelectedAnnotation = function setSelectedAnnotation(id) {
|
|
|
164
187
|
export var createAnnotation = function createAnnotation(editorAnalyticsAPI, editorAPI) {
|
|
165
188
|
return function (id) {
|
|
166
189
|
var annotationType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : AnnotationTypes.INLINE_COMMENT;
|
|
190
|
+
var supportedBlockNodes = arguments.length > 2 ? arguments[2] : undefined;
|
|
167
191
|
return function (state, dispatch) {
|
|
168
192
|
// don't try to add if there are is no temp highlight bookmarked
|
|
169
193
|
var _ref = getPluginState(state) || {},
|
|
@@ -172,7 +196,7 @@ export var createAnnotation = function createAnnotation(editorAnalyticsAPI, edit
|
|
|
172
196
|
return false;
|
|
173
197
|
}
|
|
174
198
|
if (annotationType === AnnotationTypes.INLINE_COMMENT) {
|
|
175
|
-
return addInlineComment(editorAnalyticsAPI, editorAPI)(id)(state, dispatch);
|
|
199
|
+
return addInlineComment(editorAnalyticsAPI, editorAPI)(id, supportedBlockNodes)(state, dispatch);
|
|
176
200
|
}
|
|
177
201
|
return false;
|
|
178
202
|
};
|
|
@@ -1,31 +1,41 @@
|
|
|
1
1
|
import { AnnotationTypes } from '@atlaskit/adf-schema';
|
|
2
2
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import { applyMarkOnRange } from '@atlaskit/editor-common/mark';
|
|
4
|
-
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
-
import { getDraftCommandAnalyticsPayload, getPluginState,
|
|
6
|
-
var addAnnotationMark = function addAnnotationMark(id) {
|
|
4
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import { getDraftCommandAnalyticsPayload, getPluginState, resolveDraftBookmark } from '../utils';
|
|
6
|
+
var addAnnotationMark = function addAnnotationMark(id, supportedBlockNodes) {
|
|
7
7
|
return function (transaction, state) {
|
|
8
8
|
var inlineCommentState = getPluginState(state);
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
to = _getSelectionPosition.to,
|
|
12
|
-
head = _getSelectionPosition.head;
|
|
9
|
+
var _ref = inlineCommentState || {},
|
|
10
|
+
bookmark = _ref.bookmark;
|
|
13
11
|
var annotationMark = state.schema.marks.annotation.create({
|
|
14
12
|
id: id,
|
|
15
13
|
type: AnnotationTypes.INLINE_COMMENT
|
|
16
14
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
var _resolveDraftBookmark = resolveDraftBookmark(state, bookmark, supportedBlockNodes),
|
|
16
|
+
from = _resolveDraftBookmark.from,
|
|
17
|
+
to = _resolveDraftBookmark.to,
|
|
18
|
+
head = _resolveDraftBookmark.head,
|
|
19
|
+
isBlockNode = _resolveDraftBookmark.isBlockNode;
|
|
20
|
+
var tr = transaction;
|
|
21
|
+
if (isBlockNode) {
|
|
22
|
+
tr = tr.addNodeMark(from, annotationMark);
|
|
23
|
+
// Set selection on the node so that we can display view component
|
|
24
|
+
tr.setSelection(NodeSelection.create(tr.doc, from));
|
|
25
|
+
} else {
|
|
26
|
+
// Apply the mark only to text node in the range.
|
|
27
|
+
var _tr = applyMarkOnRange(from, to, false, annotationMark, transaction);
|
|
28
|
+
// set selection back to the end of annotation once annotation mark is applied
|
|
29
|
+
_tr.setSelection(TextSelection.create(_tr.doc, head));
|
|
30
|
+
}
|
|
21
31
|
return tr;
|
|
22
32
|
};
|
|
23
33
|
};
|
|
24
34
|
var addInlineComment = function addInlineComment(editorAnalyticsAPI, editorAPI) {
|
|
25
|
-
return function (id) {
|
|
35
|
+
return function (id, supportedBlockNodes) {
|
|
26
36
|
return function (transaction, state) {
|
|
27
37
|
var _editorAPI$editorView;
|
|
28
|
-
var tr = addAnnotationMark(id)(transaction, state);
|
|
38
|
+
var tr = addAnnotationMark(id, supportedBlockNodes)(transaction, state);
|
|
29
39
|
editorAPI === null || editorAPI === void 0 || (_editorAPI$editorView = editorAPI.editorViewMode) === null || _editorAPI$editorView === void 0 || _editorAPI$editorView.actions.applyViewModeStepAt(tr);
|
|
30
40
|
|
|
31
41
|
// add insert analytics step to transaction
|
package/dist/esm/plugin.js
CHANGED
|
@@ -3,7 +3,7 @@ import { annotation } from '@atlaskit/adf-schema';
|
|
|
3
3
|
import { AnnotationUpdateEmitter } from '@atlaskit/editor-common/annotation';
|
|
4
4
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
5
5
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
6
|
-
import { setInlineCommentDraftState } from './commands';
|
|
6
|
+
import { setInlineCommentDraftState, showInlineCommentForBlockNode } from './commands';
|
|
7
7
|
import { inlineCommentPlugin } from './pm-plugins/inline-comment';
|
|
8
8
|
import { keymapPlugin } from './pm-plugins/keymap';
|
|
9
9
|
import { buildToolbar } from './toolbar';
|
|
@@ -24,7 +24,8 @@ export var annotationPlugin = function annotationPlugin(_ref) {
|
|
|
24
24
|
},
|
|
25
25
|
actions: {
|
|
26
26
|
stripNonExistingAnnotations: stripNonExistingAnnotations,
|
|
27
|
-
setInlineCommentDraftState: setInlineCommentDraftState(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes)
|
|
27
|
+
setInlineCommentDraftState: setInlineCommentDraftState(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes),
|
|
28
|
+
showCommentForBlockNode: showInlineCommentForBlockNode(annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.inlineComment.supportedBlockNodes)
|
|
28
29
|
},
|
|
29
30
|
getSharedState: function getSharedState(editorState) {
|
|
30
31
|
if (!editorState) {
|
|
@@ -8,7 +8,7 @@ import { BlockAnnotationSharedClassNames } from '@atlaskit/editor-common/styles'
|
|
|
8
8
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
9
9
|
import { clearDirtyMark, closeComponent, setInlineCommentsVisibility, setSelectedAnnotation, updateInlineCommentResolvedState, updateMouseState } from '../commands';
|
|
10
10
|
import { AnnotationNodeView, getAnnotationViewClassname } from '../nodeviews';
|
|
11
|
-
import { decorationKey, getAllAnnotations, getPluginState, inlineCommentPluginKey
|
|
11
|
+
import { decorationKey, getAllAnnotations, getPluginState, inlineCommentPluginKey } from '../utils';
|
|
12
12
|
import { createPluginState } from './plugin-factory';
|
|
13
13
|
var fetchProviderStates = /*#__PURE__*/function () {
|
|
14
14
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(provider, annotationIds) {
|
|
@@ -224,18 +224,17 @@ export var inlineCommentPlugin = function inlineCommentPlugin(options) {
|
|
|
224
224
|
}).forEach(function (mark) {
|
|
225
225
|
if (isVisible) {
|
|
226
226
|
var isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
|
|
227
|
+
var isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
|
|
228
|
+
return selectedAnnotation.id === mark.attrs.id;
|
|
229
|
+
}));
|
|
227
230
|
if (isSupportedBlockNode) {
|
|
228
|
-
var isBlockNodeSelected = isCurrentBlockNodeSelected(state, node);
|
|
229
231
|
var attrs = isUnresolved ? {
|
|
230
|
-
class:
|
|
232
|
+
class: isSelected ? "".concat(BlockAnnotationSharedClassNames.focus) : "".concat(BlockAnnotationSharedClassNames.blur)
|
|
231
233
|
} : {};
|
|
232
234
|
focusDecorations.push(Decoration.node(pos, pos + node.nodeSize, attrs, {
|
|
233
235
|
key: decorationKey.block
|
|
234
236
|
}));
|
|
235
237
|
} else {
|
|
236
|
-
var isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
|
|
237
|
-
return selectedAnnotation.id === mark.attrs.id;
|
|
238
|
-
}));
|
|
239
238
|
focusDecorations.push(Decoration.inline(pos, pos + node.nodeSize, {
|
|
240
239
|
class: "".concat(getAnnotationViewClassname(isUnresolved, isSelected), " ").concat(isUnresolved),
|
|
241
240
|
nodeName: 'span'
|
|
@@ -3,7 +3,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
3
3
|
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; }
|
|
4
4
|
import { pluginFactory } from '@atlaskit/editor-common/utils';
|
|
5
5
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
6
|
-
import { decorationKey, findAnnotationsInSelection, inlineCommentPluginKey, isSelectedAnnotationsChanged } from '../utils';
|
|
6
|
+
import { decorationKey, findAnnotationsInSelection, inlineCommentPluginKey, isBlockNodeAnnotationsSelected, isSelectedAnnotationsChanged } from '../utils';
|
|
7
7
|
import reducer from './reducer';
|
|
8
8
|
var handleDocChanged = function handleDocChanged(tr, prevPluginState) {
|
|
9
9
|
if (!tr.getMeta('replaceDocument')) {
|
|
@@ -15,6 +15,7 @@ var handleDocChanged = function handleDocChanged(tr, prevPluginState) {
|
|
|
15
15
|
};
|
|
16
16
|
var getSelectionChangedHandler = function getSelectionChangedHandler(reopenCommentView) {
|
|
17
17
|
return function (tr, pluginState) {
|
|
18
|
+
var _pluginState$featureF;
|
|
18
19
|
if (pluginState.skipSelectionHandling) {
|
|
19
20
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
20
21
|
skipSelectionHandling: false
|
|
@@ -22,6 +23,14 @@ var getSelectionChangedHandler = function getSelectionChangedHandler(reopenComme
|
|
|
22
23
|
isInlineCommentViewClosed: false
|
|
23
24
|
});
|
|
24
25
|
}
|
|
26
|
+
if ((_pluginState$featureF = pluginState.featureFlagsPluginState) !== null && _pluginState$featureF !== void 0 && _pluginState$featureF.commentsOnMedia &&
|
|
27
|
+
// If pluginState.selectedAnnotations is annotations of block node, i.e. when a new comment is created,
|
|
28
|
+
// we keep it as it is so that we can show comment view component with the newly created comment
|
|
29
|
+
isBlockNodeAnnotationsSelected(tr.selection, pluginState.selectedAnnotations)) {
|
|
30
|
+
return _objectSpread(_objectSpread({}, pluginState), reopenCommentView && {
|
|
31
|
+
isInlineCommentViewClosed: false
|
|
32
|
+
});
|
|
33
|
+
}
|
|
25
34
|
var selectedAnnotations = findAnnotationsInSelection(tr.selection, tr.doc);
|
|
26
35
|
if (selectedAnnotations.length === 0) {
|
|
27
36
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import { AnnotationTypes } from '@atlaskit/adf-schema';
|
|
3
4
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, CONTENT_COMPONENT, EVENT_TYPE, RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
5
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
5
6
|
import { closeComponent, createAnnotation, removeInlineCommentNearSelection, setInlineCommentDraftState, updateInlineCommentResolvedState } from '../commands';
|
|
@@ -84,7 +85,7 @@ export function InlineCommentView(_ref) {
|
|
|
84
85
|
dom: dom,
|
|
85
86
|
textSelection: textSelection,
|
|
86
87
|
onCreate: function onCreate(id) {
|
|
87
|
-
createAnnotation(editorAnalyticsAPI, editorAPI)(id)(editorView.state, editorView.dispatch);
|
|
88
|
+
createAnnotation(editorAnalyticsAPI, editorAPI)(id, AnnotationTypes.INLINE_COMMENT, inlineCommentProvider.supportedBlockNodes)(editorView.state, editorView.dispatch);
|
|
88
89
|
!editorView.hasFocus() && editorView.focus();
|
|
89
90
|
},
|
|
90
91
|
onClose: function onClose() {
|
package/dist/esm/utils.js
CHANGED
|
@@ -175,14 +175,15 @@ export var findAnnotationsInSelection = function findAnnotationsInSelection(sele
|
|
|
175
175
|
export var resolveDraftBookmark = function resolveDraftBookmark(editorState, bookmark) {
|
|
176
176
|
var supportedBlockNodes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
177
177
|
var doc = editorState.doc;
|
|
178
|
-
var resolvedBookmark = bookmark.resolve(doc);
|
|
178
|
+
var resolvedBookmark = bookmark ? bookmark.resolve(doc) : editorState.selection;
|
|
179
179
|
var from = resolvedBookmark.from,
|
|
180
180
|
to = resolvedBookmark.to,
|
|
181
181
|
head = resolvedBookmark.head;
|
|
182
182
|
var draftBookmark = {
|
|
183
183
|
from: from,
|
|
184
184
|
to: to,
|
|
185
|
-
head: head
|
|
185
|
+
head: head,
|
|
186
|
+
isBlockNode: false
|
|
186
187
|
};
|
|
187
188
|
if (resolvedBookmark instanceof NodeSelection) {
|
|
188
189
|
// It's possible that annotation is only allowed in child node instead parent (e.g. mediaSingle vs media),
|
|
@@ -198,7 +199,8 @@ export var resolveDraftBookmark = function resolveDraftBookmark(editorState, boo
|
|
|
198
199
|
draftBookmark = {
|
|
199
200
|
from: pos,
|
|
200
201
|
to: nodeEndsAt,
|
|
201
|
-
head: nodeEndsAt
|
|
202
|
+
head: nodeEndsAt,
|
|
203
|
+
isBlockNode: node.isBlock
|
|
202
204
|
};
|
|
203
205
|
nodeFound = true;
|
|
204
206
|
return false;
|
|
@@ -417,4 +419,24 @@ export function isSelectedAnnotationsChanged(oldSelectedAnnotations, newSelected
|
|
|
417
419
|
return annotation.id === pluginStateAnnotation.id && annotation.type === pluginStateAnnotation.type;
|
|
418
420
|
});
|
|
419
421
|
});
|
|
420
|
-
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Checks if the selectedAnnotations are the same as the annotations on the selected block node
|
|
426
|
+
*/
|
|
427
|
+
export var isBlockNodeAnnotationsSelected = function isBlockNodeAnnotationsSelected(selection) {
|
|
428
|
+
var selectedAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
429
|
+
if (selectedAnnotations.length && selection instanceof NodeSelection) {
|
|
430
|
+
var node = selection.node.type.name === 'mediaSingle' ? selection.node.firstChild : selection.node;
|
|
431
|
+
var annotationMarks = (node === null || node === void 0 ? void 0 : node.marks.filter(function (mark) {
|
|
432
|
+
return mark.type.name === 'annotation';
|
|
433
|
+
}).map(function (mark) {
|
|
434
|
+
return {
|
|
435
|
+
id: mark.attrs.id,
|
|
436
|
+
type: mark.attrs.annotationType
|
|
437
|
+
};
|
|
438
|
+
})) || [];
|
|
439
|
+
return !isSelectedAnnotationsChanged(selectedAnnotations, annotationMarks);
|
|
440
|
+
}
|
|
441
|
+
return false;
|
|
442
|
+
};
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { AnnotationTypes } from '@atlaskit/adf-schema';
|
|
2
2
|
import type { EditorAnalyticsAPI, RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
4
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
4
5
|
import type { InlineCommentMap, InlineCommentMouseData } from '../pm-plugins/types';
|
|
5
6
|
import type { AnnotationPlugin, InlineCommentInputMethod, TargetType } from '../types';
|
|
6
7
|
export declare const updateInlineCommentResolvedState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (partialNewState: InlineCommentMap, resolveMethod?: RESOLVE_METHOD) => Command;
|
|
7
8
|
export declare const closeComponent: () => Command;
|
|
8
9
|
export declare const clearDirtyMark: () => Command;
|
|
9
10
|
export declare const removeInlineCommentNearSelection: (id: string, supportedNodes?: string[]) => Command;
|
|
11
|
+
export declare const showInlineCommentForBlockNode: (supportedBlockNodes?: string[]) => (node: PMNode | null) => Command | undefined;
|
|
10
12
|
export declare const setInlineCommentDraftState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, supportedBlockNodes?: string[]) => (drafting: boolean, inputMethod?: InlineCommentInputMethod, targetType?: TargetType, isCommentOnMediaOn?: boolean) => Command;
|
|
11
|
-
export declare const addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI?: ExtractInjectionAPI<AnnotationPlugin> | undefined) => (id: string) => Command;
|
|
13
|
+
export declare const addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI?: ExtractInjectionAPI<AnnotationPlugin> | undefined) => (id: string, supportedBlockNodes?: string[]) => Command;
|
|
12
14
|
export declare const updateMouseState: (mouseData: InlineCommentMouseData) => Command;
|
|
13
15
|
export declare const setSelectedAnnotation: (id: string) => Command;
|
|
14
|
-
export declare const createAnnotation: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI?: ExtractInjectionAPI<AnnotationPlugin> | undefined) => (id: string, annotationType?: AnnotationTypes) => Command;
|
|
16
|
+
export declare const createAnnotation: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI?: ExtractInjectionAPI<AnnotationPlugin> | undefined) => (id: string, annotationType?: AnnotationTypes, supportedBlockNodes?: string[]) => Command;
|
|
15
17
|
export declare const setInlineCommentsVisibility: (isVisible: boolean) => Command;
|
|
@@ -2,7 +2,7 @@ import type { EditorAnalyticsAPI, RESOLVE_METHOD } from '@atlaskit/editor-common
|
|
|
2
2
|
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import type { InlineCommentInputMethod } from '../types';
|
|
4
4
|
declare const _default: {
|
|
5
|
-
addAnnotationMark: (id: string) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
5
|
+
addAnnotationMark: (id: string, supportedBlockNodes?: string[] | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
6
6
|
addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI: import("@atlaskit/editor-common/types").PublicPluginAPI<[import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"annotation", {
|
|
7
7
|
pluginConfiguration: import("../types").AnnotationProviders | undefined;
|
|
8
8
|
sharedState: import("..").InlineCommentPluginState | undefined;
|
|
@@ -69,6 +69,7 @@ declare const _default: {
|
|
|
69
69
|
actions: {
|
|
70
70
|
stripNonExistingAnnotations: (slice: import("prosemirror-model").Slice, state: EditorState) => boolean | undefined;
|
|
71
71
|
setInlineCommentDraftState: (drafting: boolean, inputMethod: InlineCommentInputMethod, targetType?: import("../types").TargetType | undefined, isCommentOnMediaOn?: boolean | undefined) => import("@atlaskit/editor-common/types").Command;
|
|
72
|
+
showCommentForBlockNode: (node: import("prosemirror-model").Node | null) => import("@atlaskit/editor-common/types").Command | undefined;
|
|
72
73
|
};
|
|
73
74
|
}, import("../types").AnnotationProviders | undefined>, import("@atlaskit/editor-common/types").OptionalPlugin<import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"analytics", {
|
|
74
75
|
pluginConfiguration: import("@atlaskit/editor-plugin-analytics").AnalyticsPluginOptions;
|
|
@@ -129,7 +130,7 @@ declare const _default: {
|
|
|
129
130
|
} | undefined>>, import("@atlaskit/editor-common/types").OptionalPlugin<import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"featureFlags", {
|
|
130
131
|
pluginConfiguration: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
131
132
|
sharedState: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
132
|
-
}, import("@atlaskit/editor-common/types").FeatureFlags>>]> | undefined) => (id: string) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
133
|
+
}, import("@atlaskit/editor-common/types").FeatureFlags>>]> | undefined) => (id: string, supportedBlockNodes?: string[] | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
133
134
|
addOpenCloseAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (drafting: boolean, method?: InlineCommentInputMethod) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
134
135
|
addInsertAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
135
136
|
addResolveAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (method?: RESOLVE_METHOD | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmo
|
|
|
8
8
|
import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
9
9
|
import type { Slice } from '@atlaskit/editor-prosemirror/model';
|
|
10
10
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
11
|
+
import type { showInlineCommentForBlockNode } from './commands';
|
|
11
12
|
import type { InlineCommentPluginState } from './pm-plugins/types';
|
|
12
13
|
type StripNonExistingAnnotations = (slice: Slice, state: EditorState) => boolean | undefined;
|
|
13
14
|
/**
|
|
@@ -35,6 +36,12 @@ export type AnnotationPlugin = NextEditorPlugin<'annotation', {
|
|
|
35
36
|
actions: {
|
|
36
37
|
stripNonExistingAnnotations: StripNonExistingAnnotations;
|
|
37
38
|
setInlineCommentDraftState: SetInlineCommentDraftState;
|
|
39
|
+
/**
|
|
40
|
+
* This function attempts to display the inline comment popup for a given node.
|
|
41
|
+
* @returns A command function if the given node is supported and has an annotation mark;
|
|
42
|
+
* otherwise, it will return undefined.
|
|
43
|
+
*/
|
|
44
|
+
showCommentForBlockNode: ReturnType<typeof showInlineCommentForBlockNode>;
|
|
38
45
|
};
|
|
39
46
|
}>;
|
|
40
47
|
export type AnnotationInfo = {
|
|
@@ -133,5 +140,6 @@ export type DraftBookmark = {
|
|
|
133
140
|
from: number;
|
|
134
141
|
to: number;
|
|
135
142
|
head: number;
|
|
143
|
+
isBlockNode?: boolean;
|
|
136
144
|
};
|
|
137
145
|
export {};
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare const addDraftDecoration: (start: number, end: number, targetType
|
|
|
22
22
|
export declare const getAnnotationViewKey: (annotations: AnnotationInfo[]) => string;
|
|
23
23
|
export declare const isCurrentBlockNodeSelected: (state: EditorState, node: Node) => boolean;
|
|
24
24
|
export declare const findAnnotationsInSelection: (selection: Selection, doc: Node) => AnnotationInfo[];
|
|
25
|
-
export declare const resolveDraftBookmark: (editorState: EditorState, bookmark
|
|
25
|
+
export declare const resolveDraftBookmark: (editorState: EditorState, bookmark?: SelectionBookmark, supportedBlockNodes?: string[]) => DraftBookmark;
|
|
26
26
|
/**
|
|
27
27
|
* get selection from position to apply new comment for
|
|
28
28
|
* @return bookmarked positions if they exists, otherwise current selection positions
|
|
@@ -49,3 +49,7 @@ export declare function stripNonExistingAnnotations(slice: Slice, state: EditorS
|
|
|
49
49
|
* This function assumes annotations will have unique id's for simplicity
|
|
50
50
|
*/
|
|
51
51
|
export declare function isSelectedAnnotationsChanged(oldSelectedAnnotations: AnnotationInfo[], newSelectedAnnotations: AnnotationInfo[]): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Checks if the selectedAnnotations are the same as the annotations on the selected block node
|
|
54
|
+
*/
|
|
55
|
+
export declare const isBlockNodeAnnotationsSelected: (selection: Selection, selectedAnnotations?: AnnotationInfo[]) => boolean;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { AnnotationTypes } from '@atlaskit/adf-schema';
|
|
2
2
|
import type { EditorAnalyticsAPI, RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
4
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
4
5
|
import type { InlineCommentMap, InlineCommentMouseData } from '../pm-plugins/types';
|
|
5
6
|
import type { AnnotationPlugin, InlineCommentInputMethod, TargetType } from '../types';
|
|
6
7
|
export declare const updateInlineCommentResolvedState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (partialNewState: InlineCommentMap, resolveMethod?: RESOLVE_METHOD) => Command;
|
|
7
8
|
export declare const closeComponent: () => Command;
|
|
8
9
|
export declare const clearDirtyMark: () => Command;
|
|
9
10
|
export declare const removeInlineCommentNearSelection: (id: string, supportedNodes?: string[]) => Command;
|
|
11
|
+
export declare const showInlineCommentForBlockNode: (supportedBlockNodes?: string[]) => (node: PMNode | null) => Command | undefined;
|
|
10
12
|
export declare const setInlineCommentDraftState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, supportedBlockNodes?: string[]) => (drafting: boolean, inputMethod?: InlineCommentInputMethod, targetType?: TargetType, isCommentOnMediaOn?: boolean) => Command;
|
|
11
|
-
export declare const addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI?: ExtractInjectionAPI<AnnotationPlugin> | undefined) => (id: string) => Command;
|
|
13
|
+
export declare const addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI?: ExtractInjectionAPI<AnnotationPlugin> | undefined) => (id: string, supportedBlockNodes?: string[]) => Command;
|
|
12
14
|
export declare const updateMouseState: (mouseData: InlineCommentMouseData) => Command;
|
|
13
15
|
export declare const setSelectedAnnotation: (id: string) => Command;
|
|
14
|
-
export declare const createAnnotation: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI?: ExtractInjectionAPI<AnnotationPlugin> | undefined) => (id: string, annotationType?: AnnotationTypes) => Command;
|
|
16
|
+
export declare const createAnnotation: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI?: ExtractInjectionAPI<AnnotationPlugin> | undefined) => (id: string, annotationType?: AnnotationTypes, supportedBlockNodes?: string[]) => Command;
|
|
15
17
|
export declare const setInlineCommentsVisibility: (isVisible: boolean) => Command;
|
|
@@ -2,7 +2,7 @@ import type { EditorAnalyticsAPI, RESOLVE_METHOD } from '@atlaskit/editor-common
|
|
|
2
2
|
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import type { InlineCommentInputMethod } from '../types';
|
|
4
4
|
declare const _default: {
|
|
5
|
-
addAnnotationMark: (id: string) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
5
|
+
addAnnotationMark: (id: string, supportedBlockNodes?: string[] | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
6
6
|
addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, editorAPI: import("@atlaskit/editor-common/types").PublicPluginAPI<[
|
|
7
7
|
import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"annotation", {
|
|
8
8
|
pluginConfiguration: import("../types").AnnotationProviders | undefined;
|
|
@@ -83,6 +83,7 @@ declare const _default: {
|
|
|
83
83
|
actions: {
|
|
84
84
|
stripNonExistingAnnotations: (slice: import("prosemirror-model").Slice, state: EditorState) => boolean | undefined;
|
|
85
85
|
setInlineCommentDraftState: (drafting: boolean, inputMethod: InlineCommentInputMethod, targetType?: import("../types").TargetType | undefined, isCommentOnMediaOn?: boolean | undefined) => import("@atlaskit/editor-common/types").Command;
|
|
86
|
+
showCommentForBlockNode: (node: import("prosemirror-model").Node | null) => import("@atlaskit/editor-common/types").Command | undefined;
|
|
86
87
|
};
|
|
87
88
|
}, import("../types").AnnotationProviders | undefined>,
|
|
88
89
|
import("@atlaskit/editor-common/types").OptionalPlugin<import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"analytics", {
|
|
@@ -156,7 +157,7 @@ declare const _default: {
|
|
|
156
157
|
pluginConfiguration: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
157
158
|
sharedState: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
158
159
|
}, import("@atlaskit/editor-common/types").FeatureFlags>>
|
|
159
|
-
]> | undefined) => (id: string) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
160
|
+
]> | undefined) => (id: string, supportedBlockNodes?: string[] | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
160
161
|
addOpenCloseAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (drafting: boolean, method?: InlineCommentInputMethod) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
161
162
|
addInsertAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
162
163
|
addResolveAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (method?: RESOLVE_METHOD | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
|
|
@@ -8,6 +8,7 @@ import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmo
|
|
|
8
8
|
import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
9
9
|
import type { Slice } from '@atlaskit/editor-prosemirror/model';
|
|
10
10
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
11
|
+
import type { showInlineCommentForBlockNode } from './commands';
|
|
11
12
|
import type { InlineCommentPluginState } from './pm-plugins/types';
|
|
12
13
|
type StripNonExistingAnnotations = (slice: Slice, state: EditorState) => boolean | undefined;
|
|
13
14
|
/**
|
|
@@ -35,6 +36,12 @@ export type AnnotationPlugin = NextEditorPlugin<'annotation', {
|
|
|
35
36
|
actions: {
|
|
36
37
|
stripNonExistingAnnotations: StripNonExistingAnnotations;
|
|
37
38
|
setInlineCommentDraftState: SetInlineCommentDraftState;
|
|
39
|
+
/**
|
|
40
|
+
* This function attempts to display the inline comment popup for a given node.
|
|
41
|
+
* @returns A command function if the given node is supported and has an annotation mark;
|
|
42
|
+
* otherwise, it will return undefined.
|
|
43
|
+
*/
|
|
44
|
+
showCommentForBlockNode: ReturnType<typeof showInlineCommentForBlockNode>;
|
|
38
45
|
};
|
|
39
46
|
}>;
|
|
40
47
|
export type AnnotationInfo = {
|
|
@@ -133,5 +140,6 @@ export type DraftBookmark = {
|
|
|
133
140
|
from: number;
|
|
134
141
|
to: number;
|
|
135
142
|
head: number;
|
|
143
|
+
isBlockNode?: boolean;
|
|
136
144
|
};
|
|
137
145
|
export {};
|
|
@@ -22,7 +22,7 @@ export declare const addDraftDecoration: (start: number, end: number, targetType
|
|
|
22
22
|
export declare const getAnnotationViewKey: (annotations: AnnotationInfo[]) => string;
|
|
23
23
|
export declare const isCurrentBlockNodeSelected: (state: EditorState, node: Node) => boolean;
|
|
24
24
|
export declare const findAnnotationsInSelection: (selection: Selection, doc: Node) => AnnotationInfo[];
|
|
25
|
-
export declare const resolveDraftBookmark: (editorState: EditorState, bookmark
|
|
25
|
+
export declare const resolveDraftBookmark: (editorState: EditorState, bookmark?: SelectionBookmark, supportedBlockNodes?: string[]) => DraftBookmark;
|
|
26
26
|
/**
|
|
27
27
|
* get selection from position to apply new comment for
|
|
28
28
|
* @return bookmarked positions if they exists, otherwise current selection positions
|
|
@@ -49,3 +49,7 @@ export declare function stripNonExistingAnnotations(slice: Slice, state: EditorS
|
|
|
49
49
|
* This function assumes annotations will have unique id's for simplicity
|
|
50
50
|
*/
|
|
51
51
|
export declare function isSelectedAnnotationsChanged(oldSelectedAnnotations: AnnotationInfo[], newSelectedAnnotations: AnnotationInfo[]): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Checks if the selectedAnnotations are the same as the annotations on the selected block node
|
|
54
|
+
*/
|
|
55
|
+
export declare const isBlockNodeAnnotationsSelected: (selection: Selection, selectedAnnotations?: AnnotationInfo[]) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-annotation",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Annotation plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
".": "./src/index.ts"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@atlaskit/adf-schema": "^35.
|
|
36
|
-
"@atlaskit/editor-common": "^78.
|
|
35
|
+
"@atlaskit/adf-schema": "^35.7.0",
|
|
36
|
+
"@atlaskit/editor-common": "^78.19.0",
|
|
37
37
|
"@atlaskit/editor-plugin-analytics": "^1.0.0",
|
|
38
38
|
"@atlaskit/editor-plugin-editor-viewmode": "^1.0.0",
|
|
39
39
|
"@atlaskit/editor-plugin-feature-flags": "^1.0.0",
|