@atlaskit/editor-plugin-annotation 27.0.6 → 28.0.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 +3 -1
- package/dist/cjs/pm-plugins/annotation-manager-hooks.js +107 -37
- package/dist/es2019/annotationPlugin.js +4 -1
- package/dist/es2019/pm-plugins/annotation-manager-hooks.js +89 -16
- package/dist/esm/annotationPlugin.js +3 -1
- package/dist/esm/pm-plugins/annotation-manager-hooks.js +107 -37
- package/dist/types/annotationPluginType.d.ts +6 -1
- package/dist/types/pm-plugins/annotation-manager-hooks.d.ts +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-annotation
|
|
2
2
|
|
|
3
|
+
## 28.0.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`ebf585edb7bcc`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ebf585edb7bcc) -
|
|
8
|
+
Support starting an annotation draft on a block node, behind
|
|
9
|
+
`platform_editor_comments_api_manager`.
|
|
10
|
+
- The `startDraft` manager hook accepts an optional `localId`. It resolves the target through
|
|
11
|
+
`resolveAnnotatableTargetFromLocalId`, selects the node ProseMirror can select (a `media` node's
|
|
12
|
+
`mediaSingle` parent), starts a block draft, and reports `targetNodeType` on both the result and
|
|
13
|
+
the `draftAnnotationStarted` event. An unresolvable `localId` fails with `invalid-localId` and
|
|
14
|
+
leaves the document untouched.
|
|
15
|
+
- `clearDraft` now emits `draftAnnotationCleared`.
|
|
16
|
+
- The annotation plugin's shared state exposes `annotationManager`, so other plugins (media) can
|
|
17
|
+
drive the manager without the provider being threaded through them.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
|
|
3
23
|
## 27.0.6
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -120,7 +120,9 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
|
|
|
120
120
|
var pluginState = (0, _utils.getPluginState)(editorState) || undefined;
|
|
121
121
|
var clonedPluginState = Object.assign({}, pluginState);
|
|
122
122
|
clonedPluginState === null || clonedPluginState === void 0 || delete clonedPluginState.featureFlagsPluginState;
|
|
123
|
-
return clonedPluginState
|
|
123
|
+
return _objectSpread(_objectSpread({}, clonedPluginState), {}, {
|
|
124
|
+
annotationManager: annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.annotationManager
|
|
125
|
+
});
|
|
124
126
|
},
|
|
125
127
|
pmPlugins: function pmPlugins() {
|
|
126
128
|
return [{
|
|
@@ -5,16 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.startDraft = exports.setIsAnnotationSelected = exports.setIsAnnotationHovered = exports.getDraft = exports.clearDraft = exports.clearAnnotation = exports.applyDraft = exports.allowAnnotation = void 0;
|
|
7
7
|
var _annotation = require("@atlaskit/adf-schema/annotation");
|
|
8
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
9
|
var _annotation2 = require("@atlaskit/editor-common/utils/annotation");
|
|
10
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
11
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
10
12
|
var _editorCommands = require("../editor-commands");
|
|
11
13
|
var _types = require("../types");
|
|
14
|
+
var _resolveAnnotatableTarget = require("./resolve-annotatable-target");
|
|
12
15
|
var _utils2 = require("./utils");
|
|
13
16
|
var ERROR_REASON_DRAFT_NOT_STARTED = 'draft-not-started';
|
|
14
17
|
var ERROR_REASON_DRAFT_IN_PROGRESS = 'draft-in-progress';
|
|
15
18
|
var ERROR_REASON_RANGE_MISSING = 'range-no-longer-exists';
|
|
16
19
|
var ERROR_REASON_RANGE_INVALID = 'invalid-range';
|
|
17
20
|
var ERROR_REASON_ID_INVALID = 'id-not-valid';
|
|
21
|
+
var ERROR_REASON_INVALID_LOCAL_ID = 'invalid-localId';
|
|
18
22
|
var domRefFromPos = function domRefFromPos(view, position) {
|
|
19
23
|
var dom;
|
|
20
24
|
try {
|
|
@@ -46,8 +50,8 @@ var allowAnnotation = exports.allowAnnotation = function allowAnnotation(editorV
|
|
|
46
50
|
};
|
|
47
51
|
};
|
|
48
52
|
var startDraft = exports.startDraft = function startDraft(editorView, options) {
|
|
49
|
-
return function () {
|
|
50
|
-
var
|
|
53
|
+
return function (localId) {
|
|
54
|
+
var _getRangeInlineNodeNa2, _options$annotationMa3;
|
|
51
55
|
var _ref2 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
|
|
52
56
|
isDrafting = _ref2.isDrafting,
|
|
53
57
|
selectedAnnotations = _ref2.selectedAnnotations;
|
|
@@ -75,9 +79,71 @@ var startDraft = exports.startDraft = function startDraft(editorView, options) {
|
|
|
75
79
|
});
|
|
76
80
|
});
|
|
77
81
|
}
|
|
82
|
+
if (localId !== undefined) {
|
|
83
|
+
var _$target$parent, _target$node$attrs$id, _getRangeInlineNodeNa, _options$annotationMa2;
|
|
84
|
+
var target = (0, _resolveAnnotatableTarget.resolveAnnotatableTargetFromLocalId)(editorView.state, localId, {
|
|
85
|
+
supportedBlockNodes: options.provider.supportedBlockNodes
|
|
86
|
+
});
|
|
87
|
+
if (!target) {
|
|
88
|
+
return {
|
|
89
|
+
success: false,
|
|
90
|
+
reason: ERROR_REASON_INVALID_LOCAL_ID
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// The resolver returns the node accepting the annotation (the inner `media`), but
|
|
95
|
+
// `isSelectionValid` requires the selection to be on the selectable `mediaSingle`.
|
|
96
|
+
var doc = editorView.state.doc;
|
|
97
|
+
var selectionPos = target.pos;
|
|
98
|
+
var $target = doc.resolve(target.pos);
|
|
99
|
+
if (target.node.type.name === 'media' && ((_$target$parent = $target.parent) === null || _$target$parent === void 0 ? void 0 : _$target$parent.type.name) === 'mediaSingle') {
|
|
100
|
+
selectionPos = $target.before();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// A NodeSelection makes resolveDraftBookmark record isBlockNode: true.
|
|
104
|
+
editorView.dispatch(editorView.state.tr.setSelection(_state.NodeSelection.create(doc, selectionPos)));
|
|
105
|
+
var targetNodeId = (_target$node$attrs$id = target.node.attrs.id) !== null && _target$node$attrs$id !== void 0 ? _target$node$attrs$id : target.node.attrs.localId;
|
|
106
|
+
(0, _editorCommands.setInlineCommentDraftState)(options.editorAnalyticsAPI, options.provider.supportedBlockNodes, options.api, options.provider.isBlockNodeSupported)(true, _analytics.INPUT_METHOD.FLOATING_TB, 'block', targetNodeId, true)(editorView.state, editorView.dispatch);
|
|
107
|
+
var _ref3 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
|
|
108
|
+
_draftDecorationSet = _ref3.draftDecorationSet;
|
|
109
|
+
var _decorations = _draftDecorationSet === null || _draftDecorationSet === void 0 ? void 0 : _draftDecorationSet.find();
|
|
110
|
+
if (!(_decorations !== null && _decorations !== void 0 && _decorations.length)) {
|
|
111
|
+
return {
|
|
112
|
+
success: false,
|
|
113
|
+
reason: ERROR_REASON_RANGE_INVALID
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
var _from = _decorations[0].from;
|
|
117
|
+
var _targetElement = domRefFromPos(editorView, _from);
|
|
118
|
+
var _inlineNodeTypes = (_getRangeInlineNodeNa = (0, _annotation2.getRangeInlineNodeNames)({
|
|
119
|
+
doc: editorView.state.doc,
|
|
120
|
+
pos: {
|
|
121
|
+
from: _from,
|
|
122
|
+
to: _decorations[_decorations.length - 1].to
|
|
123
|
+
}
|
|
124
|
+
})) !== null && _getRangeInlineNodeNa !== void 0 ? _getRangeInlineNodeNa : [];
|
|
125
|
+
var targetNodeType = target.node.type.name;
|
|
126
|
+
(_options$annotationMa2 = options.annotationManager) === null || _options$annotationMa2 === void 0 || _options$annotationMa2.emit({
|
|
127
|
+
name: 'draftAnnotationStarted',
|
|
128
|
+
data: {
|
|
129
|
+
targetElement: _targetElement,
|
|
130
|
+
actionResult: undefined,
|
|
131
|
+
inlineNodeTypes: _inlineNodeTypes,
|
|
132
|
+
targetNodeType: targetNodeType
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
success: true,
|
|
137
|
+
targetElement: _targetElement,
|
|
138
|
+
// In Editor the action result is undefined, because the editor will perform the transaction on the document.
|
|
139
|
+
actionResult: undefined,
|
|
140
|
+
inlineNodeTypes: _inlineNodeTypes,
|
|
141
|
+
targetNodeType: targetNodeType
|
|
142
|
+
};
|
|
143
|
+
}
|
|
78
144
|
(0, _editorCommands.setInlineCommentDraftState)(options.editorAnalyticsAPI, options.provider.supportedBlockNodes, options.api, options.provider.isBlockNodeSupported)(true)(editorView.state, editorView.dispatch);
|
|
79
|
-
var
|
|
80
|
-
draftDecorationSet =
|
|
145
|
+
var _ref4 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
|
|
146
|
+
draftDecorationSet = _ref4.draftDecorationSet;
|
|
81
147
|
var decorations = draftDecorationSet === null || draftDecorationSet === void 0 ? void 0 : draftDecorationSet.find();
|
|
82
148
|
|
|
83
149
|
// If the matching decorations is not found containing the id, it means something went wrong with the draft.
|
|
@@ -89,14 +155,14 @@ var startDraft = exports.startDraft = function startDraft(editorView, options) {
|
|
|
89
155
|
}
|
|
90
156
|
var from = decorations[0].from;
|
|
91
157
|
var targetElement = domRefFromPos(editorView, from);
|
|
92
|
-
var inlineNodeTypes = (
|
|
158
|
+
var inlineNodeTypes = (_getRangeInlineNodeNa2 = (0, _annotation2.getRangeInlineNodeNames)({
|
|
93
159
|
doc: editorView.state.doc,
|
|
94
160
|
pos: {
|
|
95
161
|
from: from,
|
|
96
162
|
to: decorations[decorations.length - 1].to
|
|
97
163
|
}
|
|
98
|
-
})) !== null &&
|
|
99
|
-
(_options$
|
|
164
|
+
})) !== null && _getRangeInlineNodeNa2 !== void 0 ? _getRangeInlineNodeNa2 : [];
|
|
165
|
+
(_options$annotationMa3 = options.annotationManager) === null || _options$annotationMa3 === void 0 || _options$annotationMa3.emit({
|
|
100
166
|
name: 'draftAnnotationStarted',
|
|
101
167
|
data: {
|
|
102
168
|
targetElement: targetElement,
|
|
@@ -115,9 +181,10 @@ var startDraft = exports.startDraft = function startDraft(editorView, options) {
|
|
|
115
181
|
};
|
|
116
182
|
var clearDraft = exports.clearDraft = function clearDraft(editorView, options) {
|
|
117
183
|
return function () {
|
|
118
|
-
var
|
|
119
|
-
|
|
120
|
-
|
|
184
|
+
var _options$annotationMa4;
|
|
185
|
+
var _ref5 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
|
|
186
|
+
isDrafting = _ref5.isDrafting,
|
|
187
|
+
draftDecorationSet = _ref5.draftDecorationSet;
|
|
121
188
|
if (!isDrafting) {
|
|
122
189
|
return {
|
|
123
190
|
success: false,
|
|
@@ -133,6 +200,9 @@ var clearDraft = exports.clearDraft = function clearDraft(editorView, options) {
|
|
|
133
200
|
}
|
|
134
201
|
(0, _editorCommands.setInlineCommentDraftState)(options.editorAnalyticsAPI, undefined, options.api)(false)(editorView.state, editorView.dispatch);
|
|
135
202
|
!editorView.hasFocus() && editorView.focus();
|
|
203
|
+
(_options$annotationMa4 = options.annotationManager) === null || _options$annotationMa4 === void 0 || _options$annotationMa4.emit({
|
|
204
|
+
name: 'draftAnnotationCleared'
|
|
205
|
+
});
|
|
136
206
|
return {
|
|
137
207
|
success: true
|
|
138
208
|
};
|
|
@@ -140,11 +210,11 @@ var clearDraft = exports.clearDraft = function clearDraft(editorView, options) {
|
|
|
140
210
|
};
|
|
141
211
|
var applyDraft = exports.applyDraft = function applyDraft(editorView, options) {
|
|
142
212
|
return function (id) {
|
|
143
|
-
var _options$
|
|
144
|
-
var
|
|
145
|
-
isDrafting =
|
|
146
|
-
draftDecorationSet =
|
|
147
|
-
bookmark =
|
|
213
|
+
var _options$annotationMa5, _getAnnotationInlineN2;
|
|
214
|
+
var _ref6 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
|
|
215
|
+
isDrafting = _ref6.isDrafting,
|
|
216
|
+
draftDecorationSet = _ref6.draftDecorationSet,
|
|
217
|
+
bookmark = _ref6.bookmark;
|
|
148
218
|
if (!isDrafting) {
|
|
149
219
|
return {
|
|
150
220
|
success: false,
|
|
@@ -168,7 +238,7 @@ var applyDraft = exports.applyDraft = function applyDraft(editorView, options) {
|
|
|
168
238
|
|
|
169
239
|
// When a draft is applied it is automatically selected, so we need to set the selected annotation.
|
|
170
240
|
// emit the event for the selected annotation.
|
|
171
|
-
(_options$
|
|
241
|
+
(_options$annotationMa5 = options.annotationManager) === null || _options$annotationMa5 === void 0 || _options$annotationMa5.emit({
|
|
172
242
|
name: 'annotationSelectionChanged',
|
|
173
243
|
data: {
|
|
174
244
|
annotationId: id,
|
|
@@ -187,10 +257,10 @@ var applyDraft = exports.applyDraft = function applyDraft(editorView, options) {
|
|
|
187
257
|
};
|
|
188
258
|
var getDraft = exports.getDraft = function getDraft(editorView, _options) {
|
|
189
259
|
return function () {
|
|
190
|
-
var
|
|
191
|
-
var
|
|
192
|
-
isDrafting =
|
|
193
|
-
draftDecorationSet =
|
|
260
|
+
var _getRangeInlineNodeNa3;
|
|
261
|
+
var _ref7 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
|
|
262
|
+
isDrafting = _ref7.isDrafting,
|
|
263
|
+
draftDecorationSet = _ref7.draftDecorationSet;
|
|
194
264
|
if (!isDrafting) {
|
|
195
265
|
return {
|
|
196
266
|
success: false,
|
|
@@ -206,13 +276,13 @@ var getDraft = exports.getDraft = function getDraft(editorView, _options) {
|
|
|
206
276
|
}
|
|
207
277
|
var from = decorations[0].from;
|
|
208
278
|
var targetElement = domRefFromPos(editorView, from);
|
|
209
|
-
var inlineNodeTypes = (
|
|
279
|
+
var inlineNodeTypes = (_getRangeInlineNodeNa3 = (0, _annotation2.getRangeInlineNodeNames)({
|
|
210
280
|
doc: editorView.state.doc,
|
|
211
281
|
pos: {
|
|
212
282
|
from: from,
|
|
213
283
|
to: decorations[decorations.length - 1].to
|
|
214
284
|
}
|
|
215
|
-
})) !== null &&
|
|
285
|
+
})) !== null && _getRangeInlineNodeNa3 !== void 0 ? _getRangeInlineNodeNa3 : [];
|
|
216
286
|
return {
|
|
217
287
|
success: true,
|
|
218
288
|
inlineNodeTypes: inlineNodeTypes,
|
|
@@ -224,10 +294,10 @@ var getDraft = exports.getDraft = function getDraft(editorView, _options) {
|
|
|
224
294
|
var setIsAnnotationSelected = exports.setIsAnnotationSelected = function setIsAnnotationSelected(editorView, options) {
|
|
225
295
|
return function (id, isSelected) {
|
|
226
296
|
var _selectedAnnotations$;
|
|
227
|
-
var
|
|
228
|
-
annotations =
|
|
229
|
-
isDrafting =
|
|
230
|
-
selectedAnnotations =
|
|
297
|
+
var _ref8 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
|
|
298
|
+
annotations = _ref8.annotations,
|
|
299
|
+
isDrafting = _ref8.isDrafting,
|
|
300
|
+
selectedAnnotations = _ref8.selectedAnnotations;
|
|
231
301
|
if (isDrafting) {
|
|
232
302
|
return {
|
|
233
303
|
success: false,
|
|
@@ -249,10 +319,10 @@ var setIsAnnotationSelected = exports.setIsAnnotationSelected = function setIsAn
|
|
|
249
319
|
if (isSelected !== isCurrentlySelected) {
|
|
250
320
|
// the annotation is selection is changing.
|
|
251
321
|
if (isCurrentlySelected && !isSelected) {
|
|
252
|
-
var _options$
|
|
322
|
+
var _options$annotationMa6, _getAnnotationInlineN3;
|
|
253
323
|
// the selected annotaion is being unselected, so we need to close the view.
|
|
254
324
|
(0, _editorCommands.closeComponent)()(editorView.state, editorView.dispatch);
|
|
255
|
-
(_options$
|
|
325
|
+
(_options$annotationMa6 = options.annotationManager) === null || _options$annotationMa6 === void 0 || _options$annotationMa6.emit({
|
|
256
326
|
name: 'annotationSelectionChanged',
|
|
257
327
|
data: {
|
|
258
328
|
annotationId: id,
|
|
@@ -261,15 +331,15 @@ var setIsAnnotationSelected = exports.setIsAnnotationSelected = function setIsAn
|
|
|
261
331
|
}
|
|
262
332
|
});
|
|
263
333
|
} else if (!isCurrentlySelected && isSelected) {
|
|
264
|
-
var _options$
|
|
334
|
+
var _options$annotationMa8, _getAnnotationInlineN5;
|
|
265
335
|
// the annotation is currently not selected and is being selected, so we need to open the view.
|
|
266
336
|
(0, _editorCommands.setSelectedAnnotation)(id)(editorView.state, editorView.dispatch);
|
|
267
337
|
|
|
268
338
|
// the current annotations are going to be unselected. So we need to notify listeners of this change also.
|
|
269
339
|
selectedAnnotations === null || selectedAnnotations === void 0 || selectedAnnotations.forEach(function (annotation) {
|
|
270
340
|
if (annotation.id !== id) {
|
|
271
|
-
var _options$
|
|
272
|
-
(_options$
|
|
341
|
+
var _options$annotationMa7, _getAnnotationInlineN4;
|
|
342
|
+
(_options$annotationMa7 = options.annotationManager) === null || _options$annotationMa7 === void 0 || _options$annotationMa7.emit({
|
|
273
343
|
name: 'annotationSelectionChanged',
|
|
274
344
|
data: {
|
|
275
345
|
annotationId: annotation.id,
|
|
@@ -281,7 +351,7 @@ var setIsAnnotationSelected = exports.setIsAnnotationSelected = function setIsAn
|
|
|
281
351
|
});
|
|
282
352
|
|
|
283
353
|
// Lastly we need to emit the event for the selected annotation.
|
|
284
|
-
(_options$
|
|
354
|
+
(_options$annotationMa8 = options.annotationManager) === null || _options$annotationMa8 === void 0 || _options$annotationMa8.emit({
|
|
285
355
|
name: 'annotationSelectionChanged',
|
|
286
356
|
data: {
|
|
287
357
|
annotationId: id,
|
|
@@ -300,9 +370,9 @@ var setIsAnnotationSelected = exports.setIsAnnotationSelected = function setIsAn
|
|
|
300
370
|
var setIsAnnotationHovered = exports.setIsAnnotationHovered = function setIsAnnotationHovered(editorView, _options) {
|
|
301
371
|
return function (id, isHovered) {
|
|
302
372
|
var _hoveredAnnotations$f;
|
|
303
|
-
var
|
|
304
|
-
annotations =
|
|
305
|
-
hoveredAnnotations =
|
|
373
|
+
var _ref9 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
|
|
374
|
+
annotations = _ref9.annotations,
|
|
375
|
+
hoveredAnnotations = _ref9.hoveredAnnotations;
|
|
306
376
|
|
|
307
377
|
// If there is no annotation state with this id then we can assume the annotation is invalid.
|
|
308
378
|
if (!(annotations !== null && annotations !== void 0 && annotations.hasOwnProperty(id))) {
|
|
@@ -333,8 +403,8 @@ var setIsAnnotationHovered = exports.setIsAnnotationHovered = function setIsAnno
|
|
|
333
403
|
};
|
|
334
404
|
var clearAnnotation = exports.clearAnnotation = function clearAnnotation(editorView, options) {
|
|
335
405
|
return function (id) {
|
|
336
|
-
var
|
|
337
|
-
annotations =
|
|
406
|
+
var _ref0 = _utils2.inlineCommentPluginKey.getState(editorView.state) || {},
|
|
407
|
+
annotations = _ref0.annotations;
|
|
338
408
|
|
|
339
409
|
// If there is no annotation state with this id then we can assume the annotation is invalid.
|
|
340
410
|
if (!(annotations !== null && annotations !== void 0 && annotations.hasOwnProperty(id))) {
|
|
@@ -88,7 +88,10 @@ export const annotationPlugin = ({
|
|
|
88
88
|
const pluginState = getPluginState(editorState) || undefined;
|
|
89
89
|
const clonedPluginState = Object.assign({}, pluginState);
|
|
90
90
|
clonedPluginState === null || clonedPluginState === void 0 ? true : delete clonedPluginState.featureFlagsPluginState;
|
|
91
|
-
return
|
|
91
|
+
return {
|
|
92
|
+
...clonedPluginState,
|
|
93
|
+
annotationManager: annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.annotationManager
|
|
94
|
+
};
|
|
92
95
|
},
|
|
93
96
|
pmPlugins: () => [{
|
|
94
97
|
name: 'annotation',
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { AnnotationTypes } from '@atlaskit/adf-schema/annotation';
|
|
2
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import { getAnnotationInlineNodeTypes, getRangeInlineNodeNames } from '@atlaskit/editor-common/utils/annotation';
|
|
4
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
5
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
4
6
|
import { setInlineCommentDraftState, createAnnotation, setSelectedAnnotation, closeComponent, setHoveredAnnotation, removeInlineCommentFromDoc } from '../editor-commands';
|
|
5
7
|
import { AnnotationSelectionType } from '../types';
|
|
8
|
+
import { resolveAnnotatableTargetFromLocalId } from './resolve-annotatable-target';
|
|
6
9
|
import { inlineCommentPluginKey, isSelectionValid } from './utils';
|
|
7
10
|
const ERROR_REASON_DRAFT_NOT_STARTED = 'draft-not-started';
|
|
8
11
|
const ERROR_REASON_DRAFT_IN_PROGRESS = 'draft-in-progress';
|
|
9
12
|
const ERROR_REASON_RANGE_MISSING = 'range-no-longer-exists';
|
|
10
13
|
const ERROR_REASON_RANGE_INVALID = 'invalid-range';
|
|
11
14
|
const ERROR_REASON_ID_INVALID = 'id-not-valid';
|
|
15
|
+
const ERROR_REASON_INVALID_LOCAL_ID = 'invalid-localId';
|
|
12
16
|
const domRefFromPos = (view, position) => {
|
|
13
17
|
let dom;
|
|
14
18
|
try {
|
|
@@ -38,8 +42,8 @@ export const allowAnnotation = (editorView, options) => () => {
|
|
|
38
42
|
}
|
|
39
43
|
return isSelectionValid(editorView.state, options.provider.supportedBlockNodes, options.provider.isBlockNodeSupported) === AnnotationSelectionType.VALID;
|
|
40
44
|
};
|
|
41
|
-
export const startDraft = (editorView, options) =>
|
|
42
|
-
var
|
|
45
|
+
export const startDraft = (editorView, options) => localId => {
|
|
46
|
+
var _getRangeInlineNodeNa2, _options$annotationMa3;
|
|
43
47
|
const {
|
|
44
48
|
isDrafting,
|
|
45
49
|
selectedAnnotations
|
|
@@ -68,6 +72,71 @@ export const startDraft = (editorView, options) => () => {
|
|
|
68
72
|
});
|
|
69
73
|
});
|
|
70
74
|
}
|
|
75
|
+
if (localId !== undefined) {
|
|
76
|
+
var _$target$parent, _target$node$attrs$id, _getRangeInlineNodeNa, _options$annotationMa2;
|
|
77
|
+
const target = resolveAnnotatableTargetFromLocalId(editorView.state, localId, {
|
|
78
|
+
supportedBlockNodes: options.provider.supportedBlockNodes
|
|
79
|
+
});
|
|
80
|
+
if (!target) {
|
|
81
|
+
return {
|
|
82
|
+
success: false,
|
|
83
|
+
reason: ERROR_REASON_INVALID_LOCAL_ID
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// The resolver returns the node accepting the annotation (the inner `media`), but
|
|
88
|
+
// `isSelectionValid` requires the selection to be on the selectable `mediaSingle`.
|
|
89
|
+
const {
|
|
90
|
+
doc
|
|
91
|
+
} = editorView.state;
|
|
92
|
+
let selectionPos = target.pos;
|
|
93
|
+
const $target = doc.resolve(target.pos);
|
|
94
|
+
if (target.node.type.name === 'media' && ((_$target$parent = $target.parent) === null || _$target$parent === void 0 ? void 0 : _$target$parent.type.name) === 'mediaSingle') {
|
|
95
|
+
selectionPos = $target.before();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// A NodeSelection makes resolveDraftBookmark record isBlockNode: true.
|
|
99
|
+
editorView.dispatch(editorView.state.tr.setSelection(NodeSelection.create(doc, selectionPos)));
|
|
100
|
+
const targetNodeId = (_target$node$attrs$id = target.node.attrs.id) !== null && _target$node$attrs$id !== void 0 ? _target$node$attrs$id : target.node.attrs.localId;
|
|
101
|
+
setInlineCommentDraftState(options.editorAnalyticsAPI, options.provider.supportedBlockNodes, options.api, options.provider.isBlockNodeSupported)(true, INPUT_METHOD.FLOATING_TB, 'block', targetNodeId, true)(editorView.state, editorView.dispatch);
|
|
102
|
+
const {
|
|
103
|
+
draftDecorationSet
|
|
104
|
+
} = inlineCommentPluginKey.getState(editorView.state) || {};
|
|
105
|
+
const decorations = draftDecorationSet === null || draftDecorationSet === void 0 ? void 0 : draftDecorationSet.find();
|
|
106
|
+
if (!(decorations !== null && decorations !== void 0 && decorations.length)) {
|
|
107
|
+
return {
|
|
108
|
+
success: false,
|
|
109
|
+
reason: ERROR_REASON_RANGE_INVALID
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const from = decorations[0].from;
|
|
113
|
+
const targetElement = domRefFromPos(editorView, from);
|
|
114
|
+
const inlineNodeTypes = (_getRangeInlineNodeNa = getRangeInlineNodeNames({
|
|
115
|
+
doc: editorView.state.doc,
|
|
116
|
+
pos: {
|
|
117
|
+
from,
|
|
118
|
+
to: decorations[decorations.length - 1].to
|
|
119
|
+
}
|
|
120
|
+
})) !== null && _getRangeInlineNodeNa !== void 0 ? _getRangeInlineNodeNa : [];
|
|
121
|
+
const targetNodeType = target.node.type.name;
|
|
122
|
+
(_options$annotationMa2 = options.annotationManager) === null || _options$annotationMa2 === void 0 ? void 0 : _options$annotationMa2.emit({
|
|
123
|
+
name: 'draftAnnotationStarted',
|
|
124
|
+
data: {
|
|
125
|
+
targetElement,
|
|
126
|
+
actionResult: undefined,
|
|
127
|
+
inlineNodeTypes,
|
|
128
|
+
targetNodeType
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
success: true,
|
|
133
|
+
targetElement,
|
|
134
|
+
// In Editor the action result is undefined, because the editor will perform the transaction on the document.
|
|
135
|
+
actionResult: undefined,
|
|
136
|
+
inlineNodeTypes,
|
|
137
|
+
targetNodeType
|
|
138
|
+
};
|
|
139
|
+
}
|
|
71
140
|
setInlineCommentDraftState(options.editorAnalyticsAPI, options.provider.supportedBlockNodes, options.api, options.provider.isBlockNodeSupported)(true)(editorView.state, editorView.dispatch);
|
|
72
141
|
const {
|
|
73
142
|
draftDecorationSet
|
|
@@ -83,14 +152,14 @@ export const startDraft = (editorView, options) => () => {
|
|
|
83
152
|
}
|
|
84
153
|
const from = decorations[0].from;
|
|
85
154
|
const targetElement = domRefFromPos(editorView, from);
|
|
86
|
-
const inlineNodeTypes = (
|
|
155
|
+
const inlineNodeTypes = (_getRangeInlineNodeNa2 = getRangeInlineNodeNames({
|
|
87
156
|
doc: editorView.state.doc,
|
|
88
157
|
pos: {
|
|
89
158
|
from,
|
|
90
159
|
to: decorations[decorations.length - 1].to
|
|
91
160
|
}
|
|
92
|
-
})) !== null &&
|
|
93
|
-
(_options$
|
|
161
|
+
})) !== null && _getRangeInlineNodeNa2 !== void 0 ? _getRangeInlineNodeNa2 : [];
|
|
162
|
+
(_options$annotationMa3 = options.annotationManager) === null || _options$annotationMa3 === void 0 ? void 0 : _options$annotationMa3.emit({
|
|
94
163
|
name: 'draftAnnotationStarted',
|
|
95
164
|
data: {
|
|
96
165
|
targetElement,
|
|
@@ -107,6 +176,7 @@ export const startDraft = (editorView, options) => () => {
|
|
|
107
176
|
};
|
|
108
177
|
};
|
|
109
178
|
export const clearDraft = (editorView, options) => () => {
|
|
179
|
+
var _options$annotationMa4;
|
|
110
180
|
const {
|
|
111
181
|
isDrafting,
|
|
112
182
|
draftDecorationSet
|
|
@@ -126,12 +196,15 @@ export const clearDraft = (editorView, options) => () => {
|
|
|
126
196
|
}
|
|
127
197
|
setInlineCommentDraftState(options.editorAnalyticsAPI, undefined, options.api)(false)(editorView.state, editorView.dispatch);
|
|
128
198
|
!editorView.hasFocus() && editorView.focus();
|
|
199
|
+
(_options$annotationMa4 = options.annotationManager) === null || _options$annotationMa4 === void 0 ? void 0 : _options$annotationMa4.emit({
|
|
200
|
+
name: 'draftAnnotationCleared'
|
|
201
|
+
});
|
|
129
202
|
return {
|
|
130
203
|
success: true
|
|
131
204
|
};
|
|
132
205
|
};
|
|
133
206
|
export const applyDraft = (editorView, options) => id => {
|
|
134
|
-
var _options$
|
|
207
|
+
var _options$annotationMa5, _getAnnotationInlineN2;
|
|
135
208
|
const {
|
|
136
209
|
isDrafting,
|
|
137
210
|
draftDecorationSet,
|
|
@@ -160,7 +233,7 @@ export const applyDraft = (editorView, options) => id => {
|
|
|
160
233
|
|
|
161
234
|
// When a draft is applied it is automatically selected, so we need to set the selected annotation.
|
|
162
235
|
// emit the event for the selected annotation.
|
|
163
|
-
(_options$
|
|
236
|
+
(_options$annotationMa5 = options.annotationManager) === null || _options$annotationMa5 === void 0 ? void 0 : _options$annotationMa5.emit({
|
|
164
237
|
name: 'annotationSelectionChanged',
|
|
165
238
|
data: {
|
|
166
239
|
annotationId: id,
|
|
@@ -177,7 +250,7 @@ export const applyDraft = (editorView, options) => id => {
|
|
|
177
250
|
};
|
|
178
251
|
};
|
|
179
252
|
export const getDraft = (editorView, _options) => () => {
|
|
180
|
-
var
|
|
253
|
+
var _getRangeInlineNodeNa3;
|
|
181
254
|
const {
|
|
182
255
|
isDrafting,
|
|
183
256
|
draftDecorationSet
|
|
@@ -197,13 +270,13 @@ export const getDraft = (editorView, _options) => () => {
|
|
|
197
270
|
}
|
|
198
271
|
const from = decorations[0].from;
|
|
199
272
|
const targetElement = domRefFromPos(editorView, from);
|
|
200
|
-
const inlineNodeTypes = (
|
|
273
|
+
const inlineNodeTypes = (_getRangeInlineNodeNa3 = getRangeInlineNodeNames({
|
|
201
274
|
doc: editorView.state.doc,
|
|
202
275
|
pos: {
|
|
203
276
|
from,
|
|
204
277
|
to: decorations[decorations.length - 1].to
|
|
205
278
|
}
|
|
206
|
-
})) !== null &&
|
|
279
|
+
})) !== null && _getRangeInlineNodeNa3 !== void 0 ? _getRangeInlineNodeNa3 : [];
|
|
207
280
|
return {
|
|
208
281
|
success: true,
|
|
209
282
|
inlineNodeTypes,
|
|
@@ -237,10 +310,10 @@ export const setIsAnnotationSelected = (editorView, options) => (id, isSelected)
|
|
|
237
310
|
if (isSelected !== isCurrentlySelected) {
|
|
238
311
|
// the annotation is selection is changing.
|
|
239
312
|
if (isCurrentlySelected && !isSelected) {
|
|
240
|
-
var _options$
|
|
313
|
+
var _options$annotationMa6, _getAnnotationInlineN3;
|
|
241
314
|
// the selected annotaion is being unselected, so we need to close the view.
|
|
242
315
|
closeComponent()(editorView.state, editorView.dispatch);
|
|
243
|
-
(_options$
|
|
316
|
+
(_options$annotationMa6 = options.annotationManager) === null || _options$annotationMa6 === void 0 ? void 0 : _options$annotationMa6.emit({
|
|
244
317
|
name: 'annotationSelectionChanged',
|
|
245
318
|
data: {
|
|
246
319
|
annotationId: id,
|
|
@@ -249,15 +322,15 @@ export const setIsAnnotationSelected = (editorView, options) => (id, isSelected)
|
|
|
249
322
|
}
|
|
250
323
|
});
|
|
251
324
|
} else if (!isCurrentlySelected && isSelected) {
|
|
252
|
-
var _options$
|
|
325
|
+
var _options$annotationMa8, _getAnnotationInlineN5;
|
|
253
326
|
// the annotation is currently not selected and is being selected, so we need to open the view.
|
|
254
327
|
setSelectedAnnotation(id)(editorView.state, editorView.dispatch);
|
|
255
328
|
|
|
256
329
|
// the current annotations are going to be unselected. So we need to notify listeners of this change also.
|
|
257
330
|
selectedAnnotations === null || selectedAnnotations === void 0 ? void 0 : selectedAnnotations.forEach(annotation => {
|
|
258
331
|
if (annotation.id !== id) {
|
|
259
|
-
var _options$
|
|
260
|
-
(_options$
|
|
332
|
+
var _options$annotationMa7, _getAnnotationInlineN4;
|
|
333
|
+
(_options$annotationMa7 = options.annotationManager) === null || _options$annotationMa7 === void 0 ? void 0 : _options$annotationMa7.emit({
|
|
261
334
|
name: 'annotationSelectionChanged',
|
|
262
335
|
data: {
|
|
263
336
|
annotationId: annotation.id,
|
|
@@ -269,7 +342,7 @@ export const setIsAnnotationSelected = (editorView, options) => (id, isSelected)
|
|
|
269
342
|
});
|
|
270
343
|
|
|
271
344
|
// Lastly we need to emit the event for the selected annotation.
|
|
272
|
-
(_options$
|
|
345
|
+
(_options$annotationMa8 = options.annotationManager) === null || _options$annotationMa8 === void 0 ? void 0 : _options$annotationMa8.emit({
|
|
273
346
|
name: 'annotationSelectionChanged',
|
|
274
347
|
data: {
|
|
275
348
|
annotationId: id,
|
|
@@ -113,7 +113,9 @@ export var annotationPlugin = function annotationPlugin(_ref) {
|
|
|
113
113
|
var pluginState = getPluginState(editorState) || undefined;
|
|
114
114
|
var clonedPluginState = Object.assign({}, pluginState);
|
|
115
115
|
clonedPluginState === null || clonedPluginState === void 0 || delete clonedPluginState.featureFlagsPluginState;
|
|
116
|
-
return clonedPluginState
|
|
116
|
+
return _objectSpread(_objectSpread({}, clonedPluginState), {}, {
|
|
117
|
+
annotationManager: annotationProviders === null || annotationProviders === void 0 ? void 0 : annotationProviders.annotationManager
|
|
118
|
+
});
|
|
117
119
|
},
|
|
118
120
|
pmPlugins: function pmPlugins() {
|
|
119
121
|
return [{
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { AnnotationTypes } from '@atlaskit/adf-schema/annotation';
|
|
2
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import { getAnnotationInlineNodeTypes, getRangeInlineNodeNames } from '@atlaskit/editor-common/utils/annotation';
|
|
4
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
5
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
4
6
|
import { setInlineCommentDraftState, createAnnotation, setSelectedAnnotation, closeComponent, setHoveredAnnotation, removeInlineCommentFromDoc } from '../editor-commands';
|
|
5
7
|
import { AnnotationSelectionType } from '../types';
|
|
8
|
+
import { resolveAnnotatableTargetFromLocalId } from './resolve-annotatable-target';
|
|
6
9
|
import { inlineCommentPluginKey, isSelectionValid } from './utils';
|
|
7
10
|
var ERROR_REASON_DRAFT_NOT_STARTED = 'draft-not-started';
|
|
8
11
|
var ERROR_REASON_DRAFT_IN_PROGRESS = 'draft-in-progress';
|
|
9
12
|
var ERROR_REASON_RANGE_MISSING = 'range-no-longer-exists';
|
|
10
13
|
var ERROR_REASON_RANGE_INVALID = 'invalid-range';
|
|
11
14
|
var ERROR_REASON_ID_INVALID = 'id-not-valid';
|
|
15
|
+
var ERROR_REASON_INVALID_LOCAL_ID = 'invalid-localId';
|
|
12
16
|
var domRefFromPos = function domRefFromPos(view, position) {
|
|
13
17
|
var dom;
|
|
14
18
|
try {
|
|
@@ -40,8 +44,8 @@ export var allowAnnotation = function allowAnnotation(editorView, options) {
|
|
|
40
44
|
};
|
|
41
45
|
};
|
|
42
46
|
export var startDraft = function startDraft(editorView, options) {
|
|
43
|
-
return function () {
|
|
44
|
-
var
|
|
47
|
+
return function (localId) {
|
|
48
|
+
var _getRangeInlineNodeNa2, _options$annotationMa3;
|
|
45
49
|
var _ref2 = inlineCommentPluginKey.getState(editorView.state) || {},
|
|
46
50
|
isDrafting = _ref2.isDrafting,
|
|
47
51
|
selectedAnnotations = _ref2.selectedAnnotations;
|
|
@@ -69,9 +73,71 @@ export var startDraft = function startDraft(editorView, options) {
|
|
|
69
73
|
});
|
|
70
74
|
});
|
|
71
75
|
}
|
|
76
|
+
if (localId !== undefined) {
|
|
77
|
+
var _$target$parent, _target$node$attrs$id, _getRangeInlineNodeNa, _options$annotationMa2;
|
|
78
|
+
var target = resolveAnnotatableTargetFromLocalId(editorView.state, localId, {
|
|
79
|
+
supportedBlockNodes: options.provider.supportedBlockNodes
|
|
80
|
+
});
|
|
81
|
+
if (!target) {
|
|
82
|
+
return {
|
|
83
|
+
success: false,
|
|
84
|
+
reason: ERROR_REASON_INVALID_LOCAL_ID
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// The resolver returns the node accepting the annotation (the inner `media`), but
|
|
89
|
+
// `isSelectionValid` requires the selection to be on the selectable `mediaSingle`.
|
|
90
|
+
var doc = editorView.state.doc;
|
|
91
|
+
var selectionPos = target.pos;
|
|
92
|
+
var $target = doc.resolve(target.pos);
|
|
93
|
+
if (target.node.type.name === 'media' && ((_$target$parent = $target.parent) === null || _$target$parent === void 0 ? void 0 : _$target$parent.type.name) === 'mediaSingle') {
|
|
94
|
+
selectionPos = $target.before();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// A NodeSelection makes resolveDraftBookmark record isBlockNode: true.
|
|
98
|
+
editorView.dispatch(editorView.state.tr.setSelection(NodeSelection.create(doc, selectionPos)));
|
|
99
|
+
var targetNodeId = (_target$node$attrs$id = target.node.attrs.id) !== null && _target$node$attrs$id !== void 0 ? _target$node$attrs$id : target.node.attrs.localId;
|
|
100
|
+
setInlineCommentDraftState(options.editorAnalyticsAPI, options.provider.supportedBlockNodes, options.api, options.provider.isBlockNodeSupported)(true, INPUT_METHOD.FLOATING_TB, 'block', targetNodeId, true)(editorView.state, editorView.dispatch);
|
|
101
|
+
var _ref3 = inlineCommentPluginKey.getState(editorView.state) || {},
|
|
102
|
+
_draftDecorationSet = _ref3.draftDecorationSet;
|
|
103
|
+
var _decorations = _draftDecorationSet === null || _draftDecorationSet === void 0 ? void 0 : _draftDecorationSet.find();
|
|
104
|
+
if (!(_decorations !== null && _decorations !== void 0 && _decorations.length)) {
|
|
105
|
+
return {
|
|
106
|
+
success: false,
|
|
107
|
+
reason: ERROR_REASON_RANGE_INVALID
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
var _from = _decorations[0].from;
|
|
111
|
+
var _targetElement = domRefFromPos(editorView, _from);
|
|
112
|
+
var _inlineNodeTypes = (_getRangeInlineNodeNa = getRangeInlineNodeNames({
|
|
113
|
+
doc: editorView.state.doc,
|
|
114
|
+
pos: {
|
|
115
|
+
from: _from,
|
|
116
|
+
to: _decorations[_decorations.length - 1].to
|
|
117
|
+
}
|
|
118
|
+
})) !== null && _getRangeInlineNodeNa !== void 0 ? _getRangeInlineNodeNa : [];
|
|
119
|
+
var targetNodeType = target.node.type.name;
|
|
120
|
+
(_options$annotationMa2 = options.annotationManager) === null || _options$annotationMa2 === void 0 || _options$annotationMa2.emit({
|
|
121
|
+
name: 'draftAnnotationStarted',
|
|
122
|
+
data: {
|
|
123
|
+
targetElement: _targetElement,
|
|
124
|
+
actionResult: undefined,
|
|
125
|
+
inlineNodeTypes: _inlineNodeTypes,
|
|
126
|
+
targetNodeType: targetNodeType
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return {
|
|
130
|
+
success: true,
|
|
131
|
+
targetElement: _targetElement,
|
|
132
|
+
// In Editor the action result is undefined, because the editor will perform the transaction on the document.
|
|
133
|
+
actionResult: undefined,
|
|
134
|
+
inlineNodeTypes: _inlineNodeTypes,
|
|
135
|
+
targetNodeType: targetNodeType
|
|
136
|
+
};
|
|
137
|
+
}
|
|
72
138
|
setInlineCommentDraftState(options.editorAnalyticsAPI, options.provider.supportedBlockNodes, options.api, options.provider.isBlockNodeSupported)(true)(editorView.state, editorView.dispatch);
|
|
73
|
-
var
|
|
74
|
-
draftDecorationSet =
|
|
139
|
+
var _ref4 = inlineCommentPluginKey.getState(editorView.state) || {},
|
|
140
|
+
draftDecorationSet = _ref4.draftDecorationSet;
|
|
75
141
|
var decorations = draftDecorationSet === null || draftDecorationSet === void 0 ? void 0 : draftDecorationSet.find();
|
|
76
142
|
|
|
77
143
|
// If the matching decorations is not found containing the id, it means something went wrong with the draft.
|
|
@@ -83,14 +149,14 @@ export var startDraft = function startDraft(editorView, options) {
|
|
|
83
149
|
}
|
|
84
150
|
var from = decorations[0].from;
|
|
85
151
|
var targetElement = domRefFromPos(editorView, from);
|
|
86
|
-
var inlineNodeTypes = (
|
|
152
|
+
var inlineNodeTypes = (_getRangeInlineNodeNa2 = getRangeInlineNodeNames({
|
|
87
153
|
doc: editorView.state.doc,
|
|
88
154
|
pos: {
|
|
89
155
|
from: from,
|
|
90
156
|
to: decorations[decorations.length - 1].to
|
|
91
157
|
}
|
|
92
|
-
})) !== null &&
|
|
93
|
-
(_options$
|
|
158
|
+
})) !== null && _getRangeInlineNodeNa2 !== void 0 ? _getRangeInlineNodeNa2 : [];
|
|
159
|
+
(_options$annotationMa3 = options.annotationManager) === null || _options$annotationMa3 === void 0 || _options$annotationMa3.emit({
|
|
94
160
|
name: 'draftAnnotationStarted',
|
|
95
161
|
data: {
|
|
96
162
|
targetElement: targetElement,
|
|
@@ -109,9 +175,10 @@ export var startDraft = function startDraft(editorView, options) {
|
|
|
109
175
|
};
|
|
110
176
|
export var clearDraft = function clearDraft(editorView, options) {
|
|
111
177
|
return function () {
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
|
|
178
|
+
var _options$annotationMa4;
|
|
179
|
+
var _ref5 = inlineCommentPluginKey.getState(editorView.state) || {},
|
|
180
|
+
isDrafting = _ref5.isDrafting,
|
|
181
|
+
draftDecorationSet = _ref5.draftDecorationSet;
|
|
115
182
|
if (!isDrafting) {
|
|
116
183
|
return {
|
|
117
184
|
success: false,
|
|
@@ -127,6 +194,9 @@ export var clearDraft = function clearDraft(editorView, options) {
|
|
|
127
194
|
}
|
|
128
195
|
setInlineCommentDraftState(options.editorAnalyticsAPI, undefined, options.api)(false)(editorView.state, editorView.dispatch);
|
|
129
196
|
!editorView.hasFocus() && editorView.focus();
|
|
197
|
+
(_options$annotationMa4 = options.annotationManager) === null || _options$annotationMa4 === void 0 || _options$annotationMa4.emit({
|
|
198
|
+
name: 'draftAnnotationCleared'
|
|
199
|
+
});
|
|
130
200
|
return {
|
|
131
201
|
success: true
|
|
132
202
|
};
|
|
@@ -134,11 +204,11 @@ export var clearDraft = function clearDraft(editorView, options) {
|
|
|
134
204
|
};
|
|
135
205
|
export var applyDraft = function applyDraft(editorView, options) {
|
|
136
206
|
return function (id) {
|
|
137
|
-
var _options$
|
|
138
|
-
var
|
|
139
|
-
isDrafting =
|
|
140
|
-
draftDecorationSet =
|
|
141
|
-
bookmark =
|
|
207
|
+
var _options$annotationMa5, _getAnnotationInlineN2;
|
|
208
|
+
var _ref6 = inlineCommentPluginKey.getState(editorView.state) || {},
|
|
209
|
+
isDrafting = _ref6.isDrafting,
|
|
210
|
+
draftDecorationSet = _ref6.draftDecorationSet,
|
|
211
|
+
bookmark = _ref6.bookmark;
|
|
142
212
|
if (!isDrafting) {
|
|
143
213
|
return {
|
|
144
214
|
success: false,
|
|
@@ -162,7 +232,7 @@ export var applyDraft = function applyDraft(editorView, options) {
|
|
|
162
232
|
|
|
163
233
|
// When a draft is applied it is automatically selected, so we need to set the selected annotation.
|
|
164
234
|
// emit the event for the selected annotation.
|
|
165
|
-
(_options$
|
|
235
|
+
(_options$annotationMa5 = options.annotationManager) === null || _options$annotationMa5 === void 0 || _options$annotationMa5.emit({
|
|
166
236
|
name: 'annotationSelectionChanged',
|
|
167
237
|
data: {
|
|
168
238
|
annotationId: id,
|
|
@@ -181,10 +251,10 @@ export var applyDraft = function applyDraft(editorView, options) {
|
|
|
181
251
|
};
|
|
182
252
|
export var getDraft = function getDraft(editorView, _options) {
|
|
183
253
|
return function () {
|
|
184
|
-
var
|
|
185
|
-
var
|
|
186
|
-
isDrafting =
|
|
187
|
-
draftDecorationSet =
|
|
254
|
+
var _getRangeInlineNodeNa3;
|
|
255
|
+
var _ref7 = inlineCommentPluginKey.getState(editorView.state) || {},
|
|
256
|
+
isDrafting = _ref7.isDrafting,
|
|
257
|
+
draftDecorationSet = _ref7.draftDecorationSet;
|
|
188
258
|
if (!isDrafting) {
|
|
189
259
|
return {
|
|
190
260
|
success: false,
|
|
@@ -200,13 +270,13 @@ export var getDraft = function getDraft(editorView, _options) {
|
|
|
200
270
|
}
|
|
201
271
|
var from = decorations[0].from;
|
|
202
272
|
var targetElement = domRefFromPos(editorView, from);
|
|
203
|
-
var inlineNodeTypes = (
|
|
273
|
+
var inlineNodeTypes = (_getRangeInlineNodeNa3 = getRangeInlineNodeNames({
|
|
204
274
|
doc: editorView.state.doc,
|
|
205
275
|
pos: {
|
|
206
276
|
from: from,
|
|
207
277
|
to: decorations[decorations.length - 1].to
|
|
208
278
|
}
|
|
209
|
-
})) !== null &&
|
|
279
|
+
})) !== null && _getRangeInlineNodeNa3 !== void 0 ? _getRangeInlineNodeNa3 : [];
|
|
210
280
|
return {
|
|
211
281
|
success: true,
|
|
212
282
|
inlineNodeTypes: inlineNodeTypes,
|
|
@@ -218,10 +288,10 @@ export var getDraft = function getDraft(editorView, _options) {
|
|
|
218
288
|
export var setIsAnnotationSelected = function setIsAnnotationSelected(editorView, options) {
|
|
219
289
|
return function (id, isSelected) {
|
|
220
290
|
var _selectedAnnotations$;
|
|
221
|
-
var
|
|
222
|
-
annotations =
|
|
223
|
-
isDrafting =
|
|
224
|
-
selectedAnnotations =
|
|
291
|
+
var _ref8 = inlineCommentPluginKey.getState(editorView.state) || {},
|
|
292
|
+
annotations = _ref8.annotations,
|
|
293
|
+
isDrafting = _ref8.isDrafting,
|
|
294
|
+
selectedAnnotations = _ref8.selectedAnnotations;
|
|
225
295
|
if (isDrafting) {
|
|
226
296
|
return {
|
|
227
297
|
success: false,
|
|
@@ -243,10 +313,10 @@ export var setIsAnnotationSelected = function setIsAnnotationSelected(editorView
|
|
|
243
313
|
if (isSelected !== isCurrentlySelected) {
|
|
244
314
|
// the annotation is selection is changing.
|
|
245
315
|
if (isCurrentlySelected && !isSelected) {
|
|
246
|
-
var _options$
|
|
316
|
+
var _options$annotationMa6, _getAnnotationInlineN3;
|
|
247
317
|
// the selected annotaion is being unselected, so we need to close the view.
|
|
248
318
|
closeComponent()(editorView.state, editorView.dispatch);
|
|
249
|
-
(_options$
|
|
319
|
+
(_options$annotationMa6 = options.annotationManager) === null || _options$annotationMa6 === void 0 || _options$annotationMa6.emit({
|
|
250
320
|
name: 'annotationSelectionChanged',
|
|
251
321
|
data: {
|
|
252
322
|
annotationId: id,
|
|
@@ -255,15 +325,15 @@ export var setIsAnnotationSelected = function setIsAnnotationSelected(editorView
|
|
|
255
325
|
}
|
|
256
326
|
});
|
|
257
327
|
} else if (!isCurrentlySelected && isSelected) {
|
|
258
|
-
var _options$
|
|
328
|
+
var _options$annotationMa8, _getAnnotationInlineN5;
|
|
259
329
|
// the annotation is currently not selected and is being selected, so we need to open the view.
|
|
260
330
|
setSelectedAnnotation(id)(editorView.state, editorView.dispatch);
|
|
261
331
|
|
|
262
332
|
// the current annotations are going to be unselected. So we need to notify listeners of this change also.
|
|
263
333
|
selectedAnnotations === null || selectedAnnotations === void 0 || selectedAnnotations.forEach(function (annotation) {
|
|
264
334
|
if (annotation.id !== id) {
|
|
265
|
-
var _options$
|
|
266
|
-
(_options$
|
|
335
|
+
var _options$annotationMa7, _getAnnotationInlineN4;
|
|
336
|
+
(_options$annotationMa7 = options.annotationManager) === null || _options$annotationMa7 === void 0 || _options$annotationMa7.emit({
|
|
267
337
|
name: 'annotationSelectionChanged',
|
|
268
338
|
data: {
|
|
269
339
|
annotationId: annotation.id,
|
|
@@ -275,7 +345,7 @@ export var setIsAnnotationSelected = function setIsAnnotationSelected(editorView
|
|
|
275
345
|
});
|
|
276
346
|
|
|
277
347
|
// Lastly we need to emit the event for the selected annotation.
|
|
278
|
-
(_options$
|
|
348
|
+
(_options$annotationMa8 = options.annotationManager) === null || _options$annotationMa8 === void 0 || _options$annotationMa8.emit({
|
|
279
349
|
name: 'annotationSelectionChanged',
|
|
280
350
|
data: {
|
|
281
351
|
annotationId: id,
|
|
@@ -294,9 +364,9 @@ export var setIsAnnotationSelected = function setIsAnnotationSelected(editorView
|
|
|
294
364
|
export var setIsAnnotationHovered = function setIsAnnotationHovered(editorView, _options) {
|
|
295
365
|
return function (id, isHovered) {
|
|
296
366
|
var _hoveredAnnotations$f;
|
|
297
|
-
var
|
|
298
|
-
annotations =
|
|
299
|
-
hoveredAnnotations =
|
|
367
|
+
var _ref9 = inlineCommentPluginKey.getState(editorView.state) || {},
|
|
368
|
+
annotations = _ref9.annotations,
|
|
369
|
+
hoveredAnnotations = _ref9.hoveredAnnotations;
|
|
300
370
|
|
|
301
371
|
// If there is no annotation state with this id then we can assume the annotation is invalid.
|
|
302
372
|
if (!(annotations !== null && annotations !== void 0 && annotations.hasOwnProperty(id))) {
|
|
@@ -327,8 +397,8 @@ export var setIsAnnotationHovered = function setIsAnnotationHovered(editorView,
|
|
|
327
397
|
};
|
|
328
398
|
export var clearAnnotation = function clearAnnotation(editorView, options) {
|
|
329
399
|
return function (id) {
|
|
330
|
-
var
|
|
331
|
-
annotations =
|
|
400
|
+
var _ref0 = inlineCommentPluginKey.getState(editorView.state) || {},
|
|
401
|
+
annotations = _ref0.annotations;
|
|
332
402
|
|
|
333
403
|
// If there is no annotation state with this id then we can assume the annotation is invalid.
|
|
334
404
|
if (!(annotations !== null && annotations !== void 0 && annotations.hasOwnProperty(id))) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AnnotationManager } from '@atlaskit/editor-common/annotation';
|
|
1
2
|
import type { Command } from '@atlaskit/editor-common/types/command';
|
|
2
3
|
import type { ExtractInjectionAPI, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types/next-editor-plugin';
|
|
3
4
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics/analyticsPluginType';
|
|
@@ -26,6 +27,10 @@ export type AnnotationPluginDependencies = [
|
|
|
26
27
|
OptionalPlugin<UserIntentPlugin>
|
|
27
28
|
];
|
|
28
29
|
export type AnnotationPluginOptions = AnnotationProviders;
|
|
30
|
+
/** Inline comment plugin state, plus the manager so other plugins (e.g. media) can use it. */
|
|
31
|
+
export type AnnotationSharedState = InlineCommentPluginState & {
|
|
32
|
+
annotationManager?: AnnotationManager;
|
|
33
|
+
};
|
|
29
34
|
export type AnnotationPlugin = NextEditorPlugin<'annotation', {
|
|
30
35
|
actions: {
|
|
31
36
|
/**
|
|
@@ -73,7 +78,7 @@ export type AnnotationPlugin = NextEditorPlugin<'annotation', {
|
|
|
73
78
|
};
|
|
74
79
|
dependencies: AnnotationPluginDependencies;
|
|
75
80
|
pluginConfiguration: AnnotationPluginOptions | undefined;
|
|
76
|
-
sharedState:
|
|
81
|
+
sharedState: AnnotationSharedState | undefined;
|
|
77
82
|
}>;
|
|
78
83
|
export type AnnotationPluginInjectionAPI = ExtractInjectionAPI<AnnotationPlugin> | undefined;
|
|
79
84
|
export {};
|
|
@@ -3,7 +3,7 @@ import type { ApplyDraftResult, ClearAnnotationResult, ClearDraftResult, GetDraf
|
|
|
3
3
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
4
|
import type { InlineCommentPluginOptions } from './types';
|
|
5
5
|
export declare const allowAnnotation: (editorView: EditorView, options: InlineCommentPluginOptions) => () => boolean;
|
|
6
|
-
export declare const startDraft: (editorView: EditorView, options: InlineCommentPluginOptions) => () => StartDraftResult;
|
|
6
|
+
export declare const startDraft: (editorView: EditorView, options: InlineCommentPluginOptions) => (localId?: string) => StartDraftResult;
|
|
7
7
|
export declare const clearDraft: (editorView: EditorView, options: InlineCommentPluginOptions) => () => ClearDraftResult;
|
|
8
8
|
export declare const applyDraft: (editorView: EditorView, options: InlineCommentPluginOptions) => (id: AnnotationId) => ApplyDraftResult;
|
|
9
9
|
export declare const getDraft: (editorView: EditorView, _options: InlineCommentPluginOptions) => () => GetDraftResult;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-annotation",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "28.0.0",
|
|
4
4
|
"description": "Annotation plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"atlaskit:src": "src/index.ts",
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@atlaskit/adf-schema": "^57.7.0",
|
|
23
|
-
"@atlaskit/editor-plugin-analytics": "^
|
|
24
|
-
"@atlaskit/editor-plugin-connectivity": "^
|
|
25
|
-
"@atlaskit/editor-plugin-editor-viewmode-effects": "^
|
|
26
|
-
"@atlaskit/editor-plugin-feature-flags": "^
|
|
27
|
-
"@atlaskit/editor-plugin-toolbar": "^
|
|
28
|
-
"@atlaskit/editor-plugin-user-intent": "^
|
|
23
|
+
"@atlaskit/editor-plugin-analytics": "^28.0.0",
|
|
24
|
+
"@atlaskit/editor-plugin-connectivity": "^28.0.0",
|
|
25
|
+
"@atlaskit/editor-plugin-editor-viewmode-effects": "^28.0.0",
|
|
26
|
+
"@atlaskit/editor-plugin-feature-flags": "^27.0.0",
|
|
27
|
+
"@atlaskit/editor-plugin-toolbar": "^25.0.0",
|
|
28
|
+
"@atlaskit/editor-plugin-user-intent": "^26.0.0",
|
|
29
29
|
"@atlaskit/editor-prosemirror": "^9.0.0",
|
|
30
30
|
"@atlaskit/editor-toolbar": "^2.8.0",
|
|
31
31
|
"@atlaskit/editor-toolbar-model": "^1.2.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@babel/runtime": "^7.0.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@atlaskit/editor-common": "^
|
|
38
|
+
"@atlaskit/editor-common": "^132.0.0",
|
|
39
39
|
"react": "^18.2.0 || ^19.2.0",
|
|
40
40
|
"react-dom": "^18.2.0 || ^19.2.0",
|
|
41
41
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|