@atlaskit/editor-plugin-annotation 1.0.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/commands/index.js +7 -4
- package/dist/cjs/plugin.js +15 -11
- package/dist/cjs/pm-plugins/inline-comment.js +1 -4
- package/dist/cjs/pm-plugins/plugin-factory.js +1 -33
- package/dist/cjs/pm-plugins/reducer.js +6 -12
- package/dist/cjs/toolbar.js +7 -2
- package/dist/cjs/types.js +7 -0
- package/dist/cjs/ui/InlineCommentView.js +1 -2
- package/dist/cjs/utils.js +14 -1
- package/dist/es2019/commands/index.js +6 -5
- package/dist/es2019/plugin.js +15 -11
- package/dist/es2019/pm-plugins/inline-comment.js +1 -2
- package/dist/es2019/pm-plugins/plugin-factory.js +1 -33
- package/dist/es2019/pm-plugins/reducer.js +6 -15
- package/dist/es2019/toolbar.js +7 -3
- package/dist/es2019/types.js +9 -0
- package/dist/es2019/ui/InlineCommentView.js +1 -2
- package/dist/es2019/utils.js +14 -2
- package/dist/esm/commands/index.js +7 -4
- package/dist/esm/plugin.js +15 -11
- package/dist/esm/pm-plugins/inline-comment.js +1 -4
- package/dist/esm/pm-plugins/plugin-factory.js +1 -33
- package/dist/esm/pm-plugins/reducer.js +6 -12
- package/dist/esm/toolbar.js +7 -2
- package/dist/esm/types.js +9 -0
- package/dist/esm/ui/InlineCommentView.js +1 -2
- package/dist/esm/utils.js +14 -1
- package/dist/types/commands/index.d.ts +2 -3
- package/dist/types/commands/transform.d.ts +11 -4
- package/dist/types/index.d.ts +1 -1
- package/dist/types/pm-plugins/types.d.ts +2 -1
- package/dist/types/toolbar.d.ts +1 -1
- package/dist/types/types.d.ts +20 -2
- package/dist/types/utils.d.ts +5 -5
- package/dist/types-ts4.5/commands/index.d.ts +2 -3
- package/dist/types-ts4.5/commands/transform.d.ts +13 -4
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/types.d.ts +2 -1
- package/dist/types-ts4.5/toolbar.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +20 -2
- package/dist/types-ts4.5/utils.d.ts +5 -5
- package/package.json +3 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-annotation
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#78508](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/78508) [`1d2b9d7a0542`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1d2b9d7a0542) - Expose setInlineCommentDraftState as one of the annotation plugin actions, extend the action with the ability to apply comment highlight to node, and add optional plugin dependency, FeatureFlagsPlugin
|
|
8
|
+
|
|
9
|
+
## 1.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#78363](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/78363) [`3a8e207fbf7c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3a8e207fbf7c) - EDF-27 Cleaned up platform.editor.annotation.decouple-inline-comment-closed_flmox FF. This decouples selected annotation logic from logic to close the inline comment view by default. This fixed a bug where the inline comment view can be unexpectedly opened from doc changes (through remote editors or non-selection altering changes such as expanding / collapsing expand blocks)
|
|
14
|
+
|
|
3
15
|
## 1.0.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -61,17 +61,18 @@ var removeInlineCommentNearSelection = exports.removeInlineCommentNearSelection
|
|
|
61
61
|
return true;
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
|
-
var getDraftCommandAction = function getDraftCommandAction(drafting) {
|
|
64
|
+
var getDraftCommandAction = function getDraftCommandAction(drafting, targetType, isCommentOnMediaOn) {
|
|
65
65
|
return function (editorState) {
|
|
66
66
|
// validate selection only when entering draft mode
|
|
67
|
-
if (drafting && (0, _utils.isSelectionValid)(editorState) !== _types2.AnnotationSelectionType.VALID) {
|
|
67
|
+
if (drafting && (0, _utils.isSelectionValid)(editorState, isCommentOnMediaOn) !== _types2.AnnotationSelectionType.VALID) {
|
|
68
68
|
return false;
|
|
69
69
|
}
|
|
70
70
|
return {
|
|
71
71
|
type: _types.ACTIONS.SET_INLINE_COMMENT_DRAFT_STATE,
|
|
72
72
|
data: {
|
|
73
73
|
drafting: drafting,
|
|
74
|
-
editorState: editorState
|
|
74
|
+
editorState: editorState,
|
|
75
|
+
targetType: targetType
|
|
75
76
|
}
|
|
76
77
|
};
|
|
77
78
|
};
|
|
@@ -79,7 +80,9 @@ var getDraftCommandAction = function getDraftCommandAction(drafting) {
|
|
|
79
80
|
var setInlineCommentDraftState = exports.setInlineCommentDraftState = function setInlineCommentDraftState(editorAnalyticsAPI) {
|
|
80
81
|
return function (drafting) {
|
|
81
82
|
var inputMethod = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _analytics.INPUT_METHOD.TOOLBAR;
|
|
82
|
-
var
|
|
83
|
+
var targetType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'inline';
|
|
84
|
+
var isCommentOnMediaOn = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
85
|
+
var commandAction = getDraftCommandAction(drafting, targetType, isCommentOnMediaOn);
|
|
83
86
|
return (0, _pluginFactory.createCommand)(commandAction, _transform.default.addOpenCloseAnalytics(editorAnalyticsAPI)(drafting, inputMethod));
|
|
84
87
|
};
|
|
85
88
|
};
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -16,14 +16,17 @@ var _adfSchema = require("@atlaskit/adf-schema");
|
|
|
16
16
|
var _annotation = require("@atlaskit/editor-common/annotation");
|
|
17
17
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
18
18
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
19
|
+
var _commands = require("./commands");
|
|
19
20
|
var _inlineComment = require("./pm-plugins/inline-comment");
|
|
20
21
|
var _keymap = require("./pm-plugins/keymap");
|
|
21
22
|
var _toolbar = require("./toolbar");
|
|
22
23
|
var _InlineCommentView = require("./ui/InlineCommentView");
|
|
23
24
|
var _utils = require("./utils");
|
|
24
25
|
var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref) {
|
|
26
|
+
var _api$featureFlags, _api$analytics;
|
|
25
27
|
var annotationProviders = _ref.config,
|
|
26
28
|
api = _ref.api;
|
|
29
|
+
var featureFlags = api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState();
|
|
27
30
|
return {
|
|
28
31
|
name: 'annotation',
|
|
29
32
|
marks: function marks() {
|
|
@@ -33,7 +36,8 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
|
|
|
33
36
|
}];
|
|
34
37
|
},
|
|
35
38
|
actions: {
|
|
36
|
-
stripNonExistingAnnotations: _utils.stripNonExistingAnnotations
|
|
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)
|
|
37
41
|
},
|
|
38
42
|
getSharedState: function getSharedState(editorState) {
|
|
39
43
|
if (!editorState) {
|
|
@@ -49,13 +53,13 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
|
|
|
49
53
|
portalProviderAPI = _ref2.portalProviderAPI,
|
|
50
54
|
eventDispatcher = _ref2.eventDispatcher;
|
|
51
55
|
if (annotationProviders) {
|
|
52
|
-
var _api$
|
|
56
|
+
var _api$analytics2;
|
|
53
57
|
return (0, _inlineComment.inlineCommentPlugin)({
|
|
54
58
|
dispatch: dispatch,
|
|
55
59
|
portalProviderAPI: portalProviderAPI,
|
|
56
60
|
eventDispatcher: eventDispatcher,
|
|
57
61
|
provider: annotationProviders.inlineComment,
|
|
58
|
-
editorAnalyticsAPI: api === null || api === void 0 || (_api$
|
|
62
|
+
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions
|
|
59
63
|
});
|
|
60
64
|
}
|
|
61
65
|
return;
|
|
@@ -64,8 +68,8 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
|
|
|
64
68
|
name: 'annotationKeymap',
|
|
65
69
|
plugin: function plugin() {
|
|
66
70
|
if (annotationProviders) {
|
|
67
|
-
var _api$
|
|
68
|
-
return (0, _keymap.keymapPlugin)(api === null || api === void 0 || (_api$
|
|
71
|
+
var _api$analytics3;
|
|
72
|
+
return (0, _keymap.keymapPlugin)(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
|
|
69
73
|
}
|
|
70
74
|
return;
|
|
71
75
|
}
|
|
@@ -78,9 +82,9 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
|
|
|
78
82
|
}
|
|
79
83
|
var pluginState = (0, _utils.getPluginState)(state);
|
|
80
84
|
if (pluginState && pluginState.isVisible && !pluginState.bookmark && !pluginState.mouseData.isSelecting) {
|
|
81
|
-
var _api$
|
|
85
|
+
var _api$analytics4;
|
|
82
86
|
var isToolbarAbove = annotationProviders.inlineComment.isToolbarAbove;
|
|
83
|
-
return (0, _toolbar.buildToolbar)(api === null || api === void 0 || (_api$
|
|
87
|
+
return (0, _toolbar.buildToolbar)(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions)(state, intl, isToolbarAbove, featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.commentsOnMedia);
|
|
84
88
|
}
|
|
85
89
|
},
|
|
86
90
|
selectionToolbar: function selectionToolbar(state, intl) {
|
|
@@ -89,9 +93,9 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
|
|
|
89
93
|
}
|
|
90
94
|
var pluginState = (0, _utils.getPluginState)(state);
|
|
91
95
|
if (pluginState && pluginState.isVisible && !pluginState.bookmark && !pluginState.mouseData.isSelecting) {
|
|
92
|
-
var _api$
|
|
96
|
+
var _api$analytics5;
|
|
93
97
|
var isToolbarAbove = annotationProviders.inlineComment.isToolbarAbove;
|
|
94
|
-
return (0, _toolbar.buildToolbar)(api === null || api === void 0 || (_api$
|
|
98
|
+
return (0, _toolbar.buildToolbar)(api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions)(state, intl, isToolbarAbove, featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.commentsOnMedia);
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
},
|
|
@@ -111,7 +115,7 @@ var annotationPlugin = exports.annotationPlugin = function annotationPlugin(_ref
|
|
|
111
115
|
};
|
|
112
116
|
};
|
|
113
117
|
function AnnotationContentComponent(_ref4) {
|
|
114
|
-
var _api$
|
|
118
|
+
var _api$analytics6;
|
|
115
119
|
var api = _ref4.api,
|
|
116
120
|
editorView = _ref4.editorView,
|
|
117
121
|
annotationProviders = _ref4.annotationProviders,
|
|
@@ -127,7 +131,7 @@ function AnnotationContentComponent(_ref4) {
|
|
|
127
131
|
providers: annotationProviders,
|
|
128
132
|
editorView: editorView,
|
|
129
133
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
130
|
-
editorAnalyticsAPI: api === null || api === void 0 || (_api$
|
|
134
|
+
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : _api$analytics6.actions,
|
|
131
135
|
editorAPI: api
|
|
132
136
|
}));
|
|
133
137
|
}
|
|
@@ -12,7 +12,6 @@ var _adfSchema = require("@atlaskit/adf-schema");
|
|
|
12
12
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
13
13
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
14
14
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
15
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
16
15
|
var _commands = require("../commands");
|
|
17
16
|
var _nodeviews = require("../nodeviews");
|
|
18
17
|
var _utils = require("../utils");
|
|
@@ -224,9 +223,7 @@ var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPl
|
|
|
224
223
|
node.marks.filter(function (mark) {
|
|
225
224
|
return mark.type === state.schema.marks.annotation;
|
|
226
225
|
}).forEach(function (mark) {
|
|
227
|
-
var isSelected =
|
|
228
|
-
return selectedAnnotation.id === mark.attrs.id;
|
|
229
|
-
})) : !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
|
|
226
|
+
var isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
|
|
230
227
|
return selectedAnnotation.id === mark.attrs.id;
|
|
231
228
|
}));
|
|
232
229
|
var isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
|
|
@@ -7,52 +7,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.createPluginState = exports.createCommand = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
10
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
11
10
|
var _utils2 = require("../utils");
|
|
12
11
|
var _reducer = _interopRequireDefault(require("./reducer"));
|
|
13
12
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
13
|
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) { (0, _defineProperty2.default)(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; }
|
|
15
14
|
var handleDocChanged = function handleDocChanged(tr, prevPluginState) {
|
|
16
15
|
if (!tr.getMeta('replaceDocument')) {
|
|
17
|
-
return
|
|
16
|
+
return getSelectionChangedHandler(false)(tr, prevPluginState);
|
|
18
17
|
}
|
|
19
18
|
return _objectSpread(_objectSpread({}, prevPluginState), {}, {
|
|
20
19
|
dirtyAnnotations: true
|
|
21
20
|
});
|
|
22
21
|
};
|
|
23
|
-
var handleSelectionChanged = function handleSelectionChanged(tr, pluginState) {
|
|
24
|
-
if (pluginState.skipSelectionHandling) {
|
|
25
|
-
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
26
|
-
skipSelectionHandling: false
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
var selectedAnnotations = (0, _utils2.findAnnotationsInSelection)(tr.selection, tr.doc);
|
|
30
|
-
var changed = selectedAnnotations.length !== pluginState.selectedAnnotations.length || selectedAnnotations.some(function (annotationInfo) {
|
|
31
|
-
return !pluginState.selectedAnnotations.some(function (aInfo) {
|
|
32
|
-
return aInfo.type === annotationInfo.id;
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
if (changed) {
|
|
36
|
-
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
37
|
-
selectedAnnotations: selectedAnnotations
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return pluginState;
|
|
41
|
-
};
|
|
42
22
|
var getSelectionChangedHandler = function getSelectionChangedHandler(reopenCommentView) {
|
|
43
23
|
return function (tr, pluginState) {
|
|
44
|
-
/**
|
|
45
|
-
* If feature flag is **OFF** we want to keep the old behavior. Note that
|
|
46
|
-
* reopenCommentView is not relevant here when using old behaviour.
|
|
47
|
-
*
|
|
48
|
-
* Feature flag is evaluated here rather than directly in onSelectionChanged where it is assigned
|
|
49
|
-
* to prevent the plugin from setting up the handler before the feature flag is evaluated.
|
|
50
|
-
*
|
|
51
|
-
* This comment / logic can be cleaned up once the feature flag is removed.
|
|
52
|
-
*/
|
|
53
|
-
if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.annotation.decouple-inline-comment-closed_flmox')) {
|
|
54
|
-
return handleSelectionChanged(tr, pluginState);
|
|
55
|
-
}
|
|
56
24
|
if (pluginState.skipSelectionHandling) {
|
|
57
25
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
58
26
|
skipSelectionHandling: false
|
|
@@ -8,7 +8,6 @@ exports.default = void 0;
|
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
10
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
11
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
12
11
|
var _utils = require("../utils");
|
|
13
12
|
var _types = require("./types");
|
|
14
13
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -25,24 +24,21 @@ var _default = exports.default = function _default(pluginState, action) {
|
|
|
25
24
|
mouseData: mouseData
|
|
26
25
|
});
|
|
27
26
|
case _types.ACTIONS.SET_INLINE_COMMENT_DRAFT_STATE:
|
|
28
|
-
return getNewDraftState(pluginState, action.data.drafting, action.data.editorState);
|
|
27
|
+
return getNewDraftState(pluginState, action.data.drafting, action.data.editorState, action.data.targetType);
|
|
29
28
|
case _types.ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK:
|
|
30
29
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
31
30
|
dirtyAnnotations: false,
|
|
32
31
|
annotations: {}
|
|
33
32
|
});
|
|
34
33
|
case _types.ACTIONS.CLOSE_COMPONENT:
|
|
35
|
-
return
|
|
34
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
36
35
|
isInlineCommentViewClosed: true
|
|
37
|
-
}) : _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
38
|
-
selectedAnnotations: []
|
|
39
36
|
});
|
|
40
37
|
case _types.ACTIONS.ADD_INLINE_COMMENT:
|
|
41
38
|
var updatedPluginState = getNewDraftState(pluginState, action.data.drafting, action.data.editorState);
|
|
42
39
|
return _objectSpread(_objectSpread({}, updatedPluginState), {}, {
|
|
43
40
|
selectedAnnotations: [].concat((0, _toConsumableArray2.default)(updatedPluginState.selectedAnnotations), (0, _toConsumableArray2.default)(action.data.selectedAnnotations)),
|
|
44
|
-
annotations: _objectSpread(_objectSpread({}, pluginState.annotations), action.data.inlineComments)
|
|
45
|
-
}, (0, _platformFeatureFlags.getBooleanFF)('platform.editor.annotation.decouple-inline-comment-closed_flmox') && {
|
|
41
|
+
annotations: _objectSpread(_objectSpread({}, pluginState.annotations), action.data.inlineComments),
|
|
46
42
|
isInlineCommentViewClosed: false
|
|
47
43
|
});
|
|
48
44
|
case _types.ACTIONS.INLINE_COMMENT_SET_VISIBLE:
|
|
@@ -56,16 +52,14 @@ var _default = exports.default = function _default(pluginState, action) {
|
|
|
56
52
|
case _types.ACTIONS.SET_SELECTED_ANNOTATION:
|
|
57
53
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
58
54
|
selectedAnnotations: (0, _toConsumableArray2.default)(action.data.selectedAnnotations),
|
|
59
|
-
skipSelectionHandling: true
|
|
60
|
-
}, (0, _platformFeatureFlags.getBooleanFF)('platform.editor.annotation.decouple-inline-comment-closed_flmox') && {
|
|
61
|
-
// if selecting annotation explicitly, reopen the comment view
|
|
55
|
+
skipSelectionHandling: true,
|
|
62
56
|
isInlineCommentViewClosed: false
|
|
63
57
|
});
|
|
64
58
|
default:
|
|
65
59
|
return pluginState;
|
|
66
60
|
}
|
|
67
61
|
};
|
|
68
|
-
function getNewDraftState(pluginState, drafting, editorState) {
|
|
62
|
+
function getNewDraftState(pluginState, drafting, editorState, targetType) {
|
|
69
63
|
var draftDecorationSet = pluginState.draftDecorationSet;
|
|
70
64
|
if (!draftDecorationSet || !drafting) {
|
|
71
65
|
draftDecorationSet = _view.DecorationSet.empty;
|
|
@@ -77,7 +71,7 @@ function getNewDraftState(pluginState, drafting, editorState) {
|
|
|
77
71
|
if (drafting && editorState) {
|
|
78
72
|
newState.bookmark = editorState.selection.getBookmark();
|
|
79
73
|
var resolvedBookmark = newState.bookmark.resolve(editorState.doc);
|
|
80
|
-
var draftDecoration = (0, _utils.addDraftDecoration)(resolvedBookmark.from, resolvedBookmark.to);
|
|
74
|
+
var draftDecoration = (0, _utils.addDraftDecoration)(resolvedBookmark.from, resolvedBookmark.to, targetType);
|
|
81
75
|
newState.draftDecorationSet = draftDecorationSet.add(editorState.doc, [draftDecoration]);
|
|
82
76
|
}
|
|
83
77
|
return newState;
|
package/dist/cjs/toolbar.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.buildToolbar = void 0;
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
10
|
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
11
|
+
var _mediaSingle = require("@atlaskit/editor-common/media-single");
|
|
11
12
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
12
13
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
13
14
|
var _comment = _interopRequireDefault(require("@atlaskit/icon/glyph/comment"));
|
|
@@ -17,9 +18,13 @@ var _utils2 = require("./utils");
|
|
|
17
18
|
var buildToolbar = exports.buildToolbar = function buildToolbar(editorAnalyticsAPI) {
|
|
18
19
|
return function (state, intl) {
|
|
19
20
|
var isToolbarAbove = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
21
|
+
var isCommentOnMediaOn = arguments.length > 3 ? arguments[3] : undefined;
|
|
20
22
|
var schema = state.schema;
|
|
21
|
-
var selectionValid = (0, _utils2.isSelectionValid)(state);
|
|
22
|
-
|
|
23
|
+
var selectionValid = (0, _utils2.isSelectionValid)(state, isCommentOnMediaOn);
|
|
24
|
+
var isMediaSelected = isCommentOnMediaOn && (0, _mediaSingle.currentMediaNodeWithPos)(state);
|
|
25
|
+
|
|
26
|
+
// comments on media can only be added via media floating toolbar
|
|
27
|
+
if (isMediaSelected || selectionValid === _types.AnnotationSelectionType.INVALID) {
|
|
23
28
|
return undefined;
|
|
24
29
|
}
|
|
25
30
|
var createCommentMessage = intl.formatMessage(_messages.annotationMessages.createComment);
|
package/dist/cjs/types.js
CHANGED
|
@@ -4,6 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.AnnotationTestIds = exports.AnnotationSelectionType = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* type of target that annotation apply to.
|
|
9
|
+
* This is used to apply correct decoration to a draft comment
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* The source of draft comment being created
|
|
13
|
+
*/
|
|
7
14
|
var AnnotationSelectionType = exports.AnnotationSelectionType = /*#__PURE__*/function (AnnotationSelectionType) {
|
|
8
15
|
AnnotationSelectionType["INVALID"] = "invalid";
|
|
9
16
|
AnnotationSelectionType["DISABLED"] = "disabled";
|
|
@@ -9,7 +9,6 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
11
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
12
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
13
12
|
var _commands = require("../commands");
|
|
14
13
|
var _types = require("../types");
|
|
15
14
|
var _utils2 = require("../utils");
|
|
@@ -125,7 +124,7 @@ function InlineCommentView(_ref) {
|
|
|
125
124
|
};
|
|
126
125
|
dispatchAnalyticsEvent(payload);
|
|
127
126
|
};
|
|
128
|
-
if (
|
|
127
|
+
if (isInlineCommentViewClosed || !selectedAnnotations) {
|
|
129
128
|
return null;
|
|
130
129
|
}
|
|
131
130
|
return /*#__PURE__*/_react.default.createElement(_AnnotationViewWrapper.AnnotationViewWrapper, {
|
package/dist/cjs/utils.js
CHANGED
|
@@ -28,6 +28,7 @@ exports.stripNonExistingAnnotations = stripNonExistingAnnotations;
|
|
|
28
28
|
exports.surroundingMarks = void 0;
|
|
29
29
|
var _adfSchema = require("@atlaskit/adf-schema");
|
|
30
30
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
31
|
+
var _mediaSingle = require("@atlaskit/editor-common/media-single");
|
|
31
32
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
32
33
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
33
34
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
@@ -130,6 +131,12 @@ var validateAnnotationMark = function validateAnnotationMark(annotationMark) {
|
|
|
130
131
|
* (when creating new comment)
|
|
131
132
|
*/
|
|
132
133
|
var addDraftDecoration = exports.addDraftDecoration = function addDraftDecoration(start, end) {
|
|
134
|
+
var targetType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'inline';
|
|
135
|
+
if (targetType === 'block') {
|
|
136
|
+
return _view.Decoration.node(start, end, {
|
|
137
|
+
class: "".concat(_styles.AnnotationSharedClassNames.draft)
|
|
138
|
+
});
|
|
139
|
+
}
|
|
133
140
|
return _view.Decoration.inline(start, end, {
|
|
134
141
|
class: "".concat(_styles.AnnotationSharedClassNames.draft)
|
|
135
142
|
});
|
|
@@ -228,10 +235,16 @@ var getDraftCommandAnalyticsPayload = exports.getDraftCommandAnalyticsPayload =
|
|
|
228
235
|
};
|
|
229
236
|
return payload;
|
|
230
237
|
};
|
|
231
|
-
var isSelectionValid = exports.isSelectionValid = function isSelectionValid(state) {
|
|
238
|
+
var isSelectionValid = exports.isSelectionValid = function isSelectionValid(state, isCommentOnMediaOn) {
|
|
239
|
+
var _currentMediaNodeWith;
|
|
232
240
|
var selection = state.selection;
|
|
233
241
|
var _ref3 = getPluginState(state) || {},
|
|
234
242
|
disallowOnWhitespace = _ref3.disallowOnWhitespace;
|
|
243
|
+
|
|
244
|
+
// Allow media so that it can enter draft mode
|
|
245
|
+
if (isCommentOnMediaOn && (_currentMediaNodeWith = (0, _mediaSingle.currentMediaNodeWithPos)(state)) !== null && _currentMediaNodeWith !== void 0 && _currentMediaNodeWith.node) {
|
|
246
|
+
return _types.AnnotationSelectionType.VALID;
|
|
247
|
+
}
|
|
235
248
|
if (selection.empty || !(selection instanceof _state.TextSelection || selection instanceof _state.AllSelection)) {
|
|
236
249
|
return _types.AnnotationSelectionType.INVALID;
|
|
237
250
|
}
|
|
@@ -47,23 +47,24 @@ export const removeInlineCommentNearSelection = id => (state, dispatch) => {
|
|
|
47
47
|
}
|
|
48
48
|
return true;
|
|
49
49
|
};
|
|
50
|
-
const getDraftCommandAction = drafting => {
|
|
50
|
+
const getDraftCommandAction = (drafting, targetType, isCommentOnMediaOn) => {
|
|
51
51
|
return editorState => {
|
|
52
52
|
// validate selection only when entering draft mode
|
|
53
|
-
if (drafting && isSelectionValid(editorState) !== AnnotationSelectionType.VALID) {
|
|
53
|
+
if (drafting && isSelectionValid(editorState, isCommentOnMediaOn) !== AnnotationSelectionType.VALID) {
|
|
54
54
|
return false;
|
|
55
55
|
}
|
|
56
56
|
return {
|
|
57
57
|
type: ACTIONS.SET_INLINE_COMMENT_DRAFT_STATE,
|
|
58
58
|
data: {
|
|
59
59
|
drafting,
|
|
60
|
-
editorState
|
|
60
|
+
editorState,
|
|
61
|
+
targetType
|
|
61
62
|
}
|
|
62
63
|
};
|
|
63
64
|
};
|
|
64
65
|
};
|
|
65
|
-
export const setInlineCommentDraftState = editorAnalyticsAPI => (drafting, inputMethod = INPUT_METHOD.TOOLBAR) => {
|
|
66
|
-
const commandAction = getDraftCommandAction(drafting);
|
|
66
|
+
export const setInlineCommentDraftState = editorAnalyticsAPI => (drafting, inputMethod = INPUT_METHOD.TOOLBAR, targetType = 'inline', isCommentOnMediaOn = false) => {
|
|
67
|
+
const commandAction = getDraftCommandAction(drafting, targetType, isCommentOnMediaOn);
|
|
67
68
|
return createCommand(commandAction, transform.addOpenCloseAnalytics(editorAnalyticsAPI)(drafting, inputMethod));
|
|
68
69
|
};
|
|
69
70
|
export const addInlineComment = (editorAnalyticsAPI, editorAPI) => id => {
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -3,6 +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
7
|
import { inlineCommentPlugin } from './pm-plugins/inline-comment';
|
|
7
8
|
import { keymapPlugin } from './pm-plugins/keymap';
|
|
8
9
|
import { buildToolbar } from './toolbar';
|
|
@@ -12,6 +13,8 @@ export const annotationPlugin = ({
|
|
|
12
13
|
config: annotationProviders,
|
|
13
14
|
api
|
|
14
15
|
}) => {
|
|
16
|
+
var _api$featureFlags, _api$analytics;
|
|
17
|
+
const featureFlags = api === null || api === void 0 ? void 0 : (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState();
|
|
15
18
|
return {
|
|
16
19
|
name: 'annotation',
|
|
17
20
|
marks() {
|
|
@@ -21,7 +24,8 @@ export const annotationPlugin = ({
|
|
|
21
24
|
}];
|
|
22
25
|
},
|
|
23
26
|
actions: {
|
|
24
|
-
stripNonExistingAnnotations
|
|
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)
|
|
25
29
|
},
|
|
26
30
|
getSharedState(editorState) {
|
|
27
31
|
if (!editorState) {
|
|
@@ -37,13 +41,13 @@ export const annotationPlugin = ({
|
|
|
37
41
|
eventDispatcher
|
|
38
42
|
}) => {
|
|
39
43
|
if (annotationProviders) {
|
|
40
|
-
var _api$
|
|
44
|
+
var _api$analytics2;
|
|
41
45
|
return inlineCommentPlugin({
|
|
42
46
|
dispatch,
|
|
43
47
|
portalProviderAPI,
|
|
44
48
|
eventDispatcher,
|
|
45
49
|
provider: annotationProviders.inlineComment,
|
|
46
|
-
editorAnalyticsAPI: api === null || api === void 0 ? void 0 : (_api$
|
|
50
|
+
editorAnalyticsAPI: api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions
|
|
47
51
|
});
|
|
48
52
|
}
|
|
49
53
|
return;
|
|
@@ -52,8 +56,8 @@ export const annotationPlugin = ({
|
|
|
52
56
|
name: 'annotationKeymap',
|
|
53
57
|
plugin: () => {
|
|
54
58
|
if (annotationProviders) {
|
|
55
|
-
var _api$
|
|
56
|
-
return keymapPlugin(api === null || api === void 0 ? void 0 : (_api$
|
|
59
|
+
var _api$analytics3;
|
|
60
|
+
return keymapPlugin(api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
|
|
57
61
|
}
|
|
58
62
|
return;
|
|
59
63
|
}
|
|
@@ -65,11 +69,11 @@ export const annotationPlugin = ({
|
|
|
65
69
|
}
|
|
66
70
|
const pluginState = getPluginState(state);
|
|
67
71
|
if (pluginState && pluginState.isVisible && !pluginState.bookmark && !pluginState.mouseData.isSelecting) {
|
|
68
|
-
var _api$
|
|
72
|
+
var _api$analytics4;
|
|
69
73
|
const {
|
|
70
74
|
isToolbarAbove
|
|
71
75
|
} = annotationProviders.inlineComment;
|
|
72
|
-
return buildToolbar(api === null || api === void 0 ? void 0 : (_api$
|
|
76
|
+
return buildToolbar(api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions)(state, intl, isToolbarAbove, featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.commentsOnMedia);
|
|
73
77
|
}
|
|
74
78
|
},
|
|
75
79
|
selectionToolbar(state, intl) {
|
|
@@ -78,11 +82,11 @@ export const annotationPlugin = ({
|
|
|
78
82
|
}
|
|
79
83
|
const pluginState = getPluginState(state);
|
|
80
84
|
if (pluginState && pluginState.isVisible && !pluginState.bookmark && !pluginState.mouseData.isSelecting) {
|
|
81
|
-
var _api$
|
|
85
|
+
var _api$analytics5;
|
|
82
86
|
const {
|
|
83
87
|
isToolbarAbove
|
|
84
88
|
} = annotationProviders.inlineComment;
|
|
85
|
-
return buildToolbar(api === null || api === void 0 ? void 0 : (_api$
|
|
89
|
+
return buildToolbar(api === null || api === void 0 ? void 0 : (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions)(state, intl, isToolbarAbove, featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.commentsOnMedia);
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
92
|
},
|
|
@@ -108,7 +112,7 @@ function AnnotationContentComponent({
|
|
|
108
112
|
annotationProviders,
|
|
109
113
|
dispatchAnalyticsEvent
|
|
110
114
|
}) {
|
|
111
|
-
var _api$
|
|
115
|
+
var _api$analytics6;
|
|
112
116
|
const {
|
|
113
117
|
annotationState: inlineCommentState
|
|
114
118
|
} = useSharedPluginState(api, ['annotation']);
|
|
@@ -121,7 +125,7 @@ function AnnotationContentComponent({
|
|
|
121
125
|
providers: annotationProviders,
|
|
122
126
|
editorView: editorView,
|
|
123
127
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
124
|
-
editorAnalyticsAPI: api === null || api === void 0 ? void 0 : (_api$
|
|
128
|
+
editorAnalyticsAPI: api === null || api === void 0 ? void 0 : (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : _api$analytics6.actions,
|
|
125
129
|
editorAPI: api
|
|
126
130
|
}));
|
|
127
131
|
}
|
|
@@ -2,7 +2,6 @@ import { AnnotationTypes } from '@atlaskit/adf-schema';
|
|
|
2
2
|
import { RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
4
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
6
5
|
import { clearDirtyMark, closeComponent, setInlineCommentsVisibility, setSelectedAnnotation, updateInlineCommentResolvedState, updateMouseState } from '../commands';
|
|
7
6
|
import { AnnotationNodeView, getAnnotationViewClassname } from '../nodeviews';
|
|
8
7
|
import { getAllAnnotations, getPluginState, inlineCommentPluginKey } from '../utils';
|
|
@@ -163,7 +162,7 @@ export const inlineCommentPlugin = options => {
|
|
|
163
162
|
const focusDecorations = [];
|
|
164
163
|
state.doc.descendants((node, pos) => {
|
|
165
164
|
node.marks.filter(mark => mark.type === state.schema.marks.annotation).forEach(mark => {
|
|
166
|
-
const isSelected =
|
|
165
|
+
const isSelected = !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(selectedAnnotation => selectedAnnotation.id === mark.attrs.id));
|
|
167
166
|
const isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
|
|
168
167
|
if (isVisible) {
|
|
169
168
|
focusDecorations.push(Decoration.inline(pos, pos + node.nodeSize, {
|
|
@@ -1,48 +1,16 @@
|
|
|
1
1
|
import { pluginFactory } from '@atlaskit/editor-common/utils';
|
|
2
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
3
2
|
import { findAnnotationsInSelection, inlineCommentPluginKey, isSelectedAnnotationsChanged } from '../utils';
|
|
4
3
|
import reducer from './reducer';
|
|
5
4
|
const handleDocChanged = (tr, prevPluginState) => {
|
|
6
5
|
if (!tr.getMeta('replaceDocument')) {
|
|
7
|
-
return
|
|
6
|
+
return getSelectionChangedHandler(false)(tr, prevPluginState);
|
|
8
7
|
}
|
|
9
8
|
return {
|
|
10
9
|
...prevPluginState,
|
|
11
10
|
dirtyAnnotations: true
|
|
12
11
|
};
|
|
13
12
|
};
|
|
14
|
-
const handleSelectionChanged = (tr, pluginState) => {
|
|
15
|
-
if (pluginState.skipSelectionHandling) {
|
|
16
|
-
return {
|
|
17
|
-
...pluginState,
|
|
18
|
-
skipSelectionHandling: false
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
const selectedAnnotations = findAnnotationsInSelection(tr.selection, tr.doc);
|
|
22
|
-
const changed = selectedAnnotations.length !== pluginState.selectedAnnotations.length || selectedAnnotations.some(annotationInfo => {
|
|
23
|
-
return !pluginState.selectedAnnotations.some(aInfo => aInfo.type === annotationInfo.id);
|
|
24
|
-
});
|
|
25
|
-
if (changed) {
|
|
26
|
-
return {
|
|
27
|
-
...pluginState,
|
|
28
|
-
selectedAnnotations
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
return pluginState;
|
|
32
|
-
};
|
|
33
13
|
const getSelectionChangedHandler = reopenCommentView => (tr, pluginState) => {
|
|
34
|
-
/**
|
|
35
|
-
* If feature flag is **OFF** we want to keep the old behavior. Note that
|
|
36
|
-
* reopenCommentView is not relevant here when using old behaviour.
|
|
37
|
-
*
|
|
38
|
-
* Feature flag is evaluated here rather than directly in onSelectionChanged where it is assigned
|
|
39
|
-
* to prevent the plugin from setting up the handler before the feature flag is evaluated.
|
|
40
|
-
*
|
|
41
|
-
* This comment / logic can be cleaned up once the feature flag is removed.
|
|
42
|
-
*/
|
|
43
|
-
if (!getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox')) {
|
|
44
|
-
return handleSelectionChanged(tr, pluginState);
|
|
45
|
-
}
|
|
46
14
|
if (pluginState.skipSelectionHandling) {
|
|
47
15
|
return {
|
|
48
16
|
...pluginState,
|