@atlaskit/editor-plugin-annotation 0.1.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/.eslintrc.js +18 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +13 -0
- package/README.md +30 -0
- package/dist/cjs/commands/index.js +150 -0
- package/dist/cjs/commands/transform.js +86 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/nodeviews/index.js +59 -0
- package/dist/cjs/plugin.js +132 -0
- package/dist/cjs/pm-plugins/inline-comment.js +246 -0
- package/dist/cjs/pm-plugins/keymap.js +15 -0
- package/dist/cjs/pm-plugins/plugin-factory.js +107 -0
- package/dist/cjs/pm-plugins/reducer.js +84 -0
- package/dist/cjs/pm-plugins/types.js +17 -0
- package/dist/cjs/toolbar.js +59 -0
- package/dist/cjs/types.js +20 -0
- package/dist/cjs/ui/AnnotationViewWrapper.js +39 -0
- package/dist/cjs/ui/InlineCommentView.js +149 -0
- package/dist/cjs/utils.js +372 -0
- package/dist/es2019/commands/index.js +123 -0
- package/dist/es2019/commands/transform.js +64 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/nodeviews/index.js +31 -0
- package/dist/es2019/plugin.js +127 -0
- package/dist/es2019/pm-plugins/inline-comment.js +181 -0
- package/dist/es2019/pm-plugins/keymap.js +9 -0
- package/dist/es2019/pm-plugins/plugin-factory.js +108 -0
- package/dist/es2019/pm-plugins/reducer.js +94 -0
- package/dist/es2019/pm-plugins/types.js +11 -0
- package/dist/es2019/toolbar.js +53 -0
- package/dist/es2019/types.js +14 -0
- package/dist/es2019/ui/AnnotationViewWrapper.js +15 -0
- package/dist/es2019/ui/InlineCommentView.js +145 -0
- package/dist/es2019/utils.js +334 -0
- package/dist/esm/commands/index.js +143 -0
- package/dist/esm/commands/transform.js +80 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/nodeviews/index.js +52 -0
- package/dist/esm/plugin.js +120 -0
- package/dist/esm/pm-plugins/inline-comment.js +239 -0
- package/dist/esm/pm-plugins/keymap.js +9 -0
- package/dist/esm/pm-plugins/plugin-factory.js +101 -0
- package/dist/esm/pm-plugins/reducer.js +77 -0
- package/dist/esm/pm-plugins/types.js +11 -0
- package/dist/esm/toolbar.js +52 -0
- package/dist/esm/types.js +14 -0
- package/dist/esm/ui/AnnotationViewWrapper.js +32 -0
- package/dist/esm/ui/InlineCommentView.js +142 -0
- package/dist/esm/utils.js +345 -0
- package/dist/types/commands/index.d.ts +15 -0
- package/dist/types/commands/transform.d.ts +11 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/nodeviews/index.d.ts +11 -0
- package/dist/types/plugin.d.ts +6 -0
- package/dist/types/pm-plugins/inline-comment.d.ts +3 -0
- package/dist/types/pm-plugins/keymap.d.ts +3 -0
- package/dist/types/pm-plugins/plugin-factory.d.ts +2 -0
- package/dist/types/pm-plugins/reducer.d.ts +3 -0
- package/dist/types/pm-plugins/types.d.ts +78 -0
- package/dist/types/toolbar.d.ts +5 -0
- package/dist/types/types.d.ts +100 -0
- package/dist/types/ui/AnnotationViewWrapper.d.ts +10 -0
- package/dist/types/ui/InlineCommentView.d.ts +12 -0
- package/dist/types/utils.d.ts +44 -0
- package/dist/types-ts4.5/commands/index.d.ts +15 -0
- package/dist/types-ts4.5/commands/transform.d.ts +11 -0
- package/dist/types-ts4.5/index.d.ts +3 -0
- package/dist/types-ts4.5/nodeviews/index.d.ts +11 -0
- package/dist/types-ts4.5/plugin.d.ts +6 -0
- package/dist/types-ts4.5/pm-plugins/inline-comment.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/plugin-factory.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/reducer.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/types.d.ts +78 -0
- package/dist/types-ts4.5/toolbar.d.ts +5 -0
- package/dist/types-ts4.5/types.d.ts +102 -0
- package/dist/types-ts4.5/ui/AnnotationViewWrapper.d.ts +10 -0
- package/dist/types-ts4.5/ui/InlineCommentView.d.ts +12 -0
- package/dist/types-ts4.5/utils.d.ts +44 -0
- package/package.json +106 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.inlineCommentPlugin = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
+
var _adfSchema = require("@atlaskit/adf-schema");
|
|
12
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
13
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
14
|
+
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
15
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
16
|
+
var _commands = require("../commands");
|
|
17
|
+
var _nodeviews = require("../nodeviews");
|
|
18
|
+
var _utils = require("../utils");
|
|
19
|
+
var _pluginFactory = require("./plugin-factory");
|
|
20
|
+
var fetchProviderStates = /*#__PURE__*/function () {
|
|
21
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(provider, annotationIds) {
|
|
22
|
+
var data, result;
|
|
23
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
24
|
+
while (1) switch (_context.prev = _context.next) {
|
|
25
|
+
case 0:
|
|
26
|
+
_context.next = 2;
|
|
27
|
+
return provider.getState(annotationIds);
|
|
28
|
+
case 2:
|
|
29
|
+
data = _context.sent;
|
|
30
|
+
result = {};
|
|
31
|
+
data.forEach(function (annotation) {
|
|
32
|
+
if (annotation.annotationType === _adfSchema.AnnotationTypes.INLINE_COMMENT) {
|
|
33
|
+
result[annotation.id] = annotation.state.resolved;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return _context.abrupt("return", result);
|
|
37
|
+
case 6:
|
|
38
|
+
case "end":
|
|
39
|
+
return _context.stop();
|
|
40
|
+
}
|
|
41
|
+
}, _callee);
|
|
42
|
+
}));
|
|
43
|
+
return function fetchProviderStates(_x, _x2) {
|
|
44
|
+
return _ref.apply(this, arguments);
|
|
45
|
+
};
|
|
46
|
+
}();
|
|
47
|
+
|
|
48
|
+
// fetchState is unable to return a command as it's runs async and may dispatch at a later time
|
|
49
|
+
// Requires `editorView` instead of the decomposition as the async means state may end up stale
|
|
50
|
+
var fetchState = /*#__PURE__*/function () {
|
|
51
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(provider, annotationIds, editorView, editorAnalyticsAPI) {
|
|
52
|
+
var inlineCommentStates;
|
|
53
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
54
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
55
|
+
case 0:
|
|
56
|
+
if (!(!annotationIds || !annotationIds.length)) {
|
|
57
|
+
_context2.next = 2;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
return _context2.abrupt("return");
|
|
61
|
+
case 2:
|
|
62
|
+
_context2.next = 4;
|
|
63
|
+
return fetchProviderStates(provider, annotationIds);
|
|
64
|
+
case 4:
|
|
65
|
+
inlineCommentStates = _context2.sent;
|
|
66
|
+
if (editorView.dispatch) {
|
|
67
|
+
(0, _commands.updateInlineCommentResolvedState)(editorAnalyticsAPI)(inlineCommentStates)(editorView.state, editorView.dispatch);
|
|
68
|
+
}
|
|
69
|
+
case 6:
|
|
70
|
+
case "end":
|
|
71
|
+
return _context2.stop();
|
|
72
|
+
}
|
|
73
|
+
}, _callee2);
|
|
74
|
+
}));
|
|
75
|
+
return function fetchState(_x3, _x4, _x5, _x6) {
|
|
76
|
+
return _ref2.apply(this, arguments);
|
|
77
|
+
};
|
|
78
|
+
}();
|
|
79
|
+
var initialState = function initialState() {
|
|
80
|
+
var disallowOnWhitespace = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
81
|
+
return {
|
|
82
|
+
annotations: {},
|
|
83
|
+
selectedAnnotations: [],
|
|
84
|
+
mouseData: {
|
|
85
|
+
isSelecting: false
|
|
86
|
+
},
|
|
87
|
+
disallowOnWhitespace: disallowOnWhitespace,
|
|
88
|
+
isInlineCommentViewClosed: false,
|
|
89
|
+
isVisible: true,
|
|
90
|
+
skipSelectionHandling: false
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
var hideToolbar = function hideToolbar(state, dispatch) {
|
|
94
|
+
return function () {
|
|
95
|
+
(0, _commands.updateMouseState)({
|
|
96
|
+
isSelecting: true
|
|
97
|
+
})(state, dispatch);
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// Subscribe to updates from consumer
|
|
102
|
+
var onResolve = function onResolve(editorAnalyticsAPI) {
|
|
103
|
+
return function (state, dispatch) {
|
|
104
|
+
return function (annotationId) {
|
|
105
|
+
(0, _commands.updateInlineCommentResolvedState)(editorAnalyticsAPI)((0, _defineProperty2.default)({}, annotationId, true), _analytics.RESOLVE_METHOD.CONSUMER)(state, dispatch);
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
var onUnResolve = function onUnResolve(editorAnalyticsAPI) {
|
|
110
|
+
return function (state, dispatch) {
|
|
111
|
+
return function (annotationId) {
|
|
112
|
+
(0, _commands.updateInlineCommentResolvedState)(editorAnalyticsAPI)((0, _defineProperty2.default)({}, annotationId, false))(state, dispatch);
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
var onMouseUp = function onMouseUp(state, dispatch) {
|
|
117
|
+
return function (e) {
|
|
118
|
+
var _ref3 = (0, _utils.getPluginState)(state) || {},
|
|
119
|
+
mouseData = _ref3.mouseData;
|
|
120
|
+
if (mouseData !== null && mouseData !== void 0 && mouseData.isSelecting) {
|
|
121
|
+
(0, _commands.updateMouseState)({
|
|
122
|
+
isSelecting: false
|
|
123
|
+
})(state, dispatch);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
var onSetVisibility = function onSetVisibility(view) {
|
|
128
|
+
return function (isVisible) {
|
|
129
|
+
var state = view.state,
|
|
130
|
+
dispatch = view.dispatch;
|
|
131
|
+
(0, _commands.setInlineCommentsVisibility)(isVisible)(state, dispatch);
|
|
132
|
+
if (isVisible) {
|
|
133
|
+
// PM retains focus when we click away from the editor.
|
|
134
|
+
// This will restore the visual aspect of the selection,
|
|
135
|
+
// otherwise it will seem a floating toolbar will appear
|
|
136
|
+
// for no reason.
|
|
137
|
+
view.focus();
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
var inlineCommentPlugin = exports.inlineCommentPlugin = function inlineCommentPlugin(options) {
|
|
142
|
+
var provider = options.provider,
|
|
143
|
+
portalProviderAPI = options.portalProviderAPI,
|
|
144
|
+
eventDispatcher = options.eventDispatcher;
|
|
145
|
+
return new _safePlugin.SafePlugin({
|
|
146
|
+
key: _utils.inlineCommentPluginKey,
|
|
147
|
+
state: (0, _pluginFactory.createPluginState)(options.dispatch, initialState(provider.disallowOnWhitespace)),
|
|
148
|
+
view: function view(editorView) {
|
|
149
|
+
// Get initial state
|
|
150
|
+
// Need to pass `editorView` to mitigate editor state going stale
|
|
151
|
+
fetchState(provider, (0, _utils.getAllAnnotations)(editorView.state.doc), editorView, options.editorAnalyticsAPI);
|
|
152
|
+
var resolve = function resolve(annotationId) {
|
|
153
|
+
return onResolve(options.editorAnalyticsAPI)(editorView.state, editorView.dispatch)(annotationId);
|
|
154
|
+
};
|
|
155
|
+
var unResolve = function unResolve(annotationId) {
|
|
156
|
+
return onUnResolve(options.editorAnalyticsAPI)(editorView.state, editorView.dispatch)(annotationId);
|
|
157
|
+
};
|
|
158
|
+
var mouseUp = function mouseUp(event) {
|
|
159
|
+
return onMouseUp(editorView.state, editorView.dispatch)(event);
|
|
160
|
+
};
|
|
161
|
+
var setVisibility = function setVisibility(isVisible) {
|
|
162
|
+
return onSetVisibility(editorView)(isVisible);
|
|
163
|
+
};
|
|
164
|
+
var setSelectedAnnotationFn = function setSelectedAnnotationFn(annotationId) {
|
|
165
|
+
if (!annotationId) {
|
|
166
|
+
(0, _commands.closeComponent)()(editorView.state, editorView.dispatch);
|
|
167
|
+
} else {
|
|
168
|
+
(0, _commands.setSelectedAnnotation)(annotationId)(editorView.state, editorView.dispatch);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
var updateSubscriber = provider.updateSubscriber;
|
|
172
|
+
if (updateSubscriber) {
|
|
173
|
+
updateSubscriber.on('resolve', resolve).on('delete', resolve).on('unresolve', unResolve).on('create', unResolve).on('setvisibility', setVisibility).on('setselectedannotation', setSelectedAnnotationFn);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
177
|
+
editorView.root.addEventListener('mouseup', mouseUp);
|
|
178
|
+
return {
|
|
179
|
+
update: function update(view, _prevState) {
|
|
180
|
+
var _ref4 = (0, _utils.getPluginState)(view.state) || {},
|
|
181
|
+
dirtyAnnotations = _ref4.dirtyAnnotations;
|
|
182
|
+
if (!dirtyAnnotations) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
(0, _commands.clearDirtyMark)()(view.state, view.dispatch);
|
|
186
|
+
fetchState(provider, (0, _utils.getAllAnnotations)(view.state.doc), view, options.editorAnalyticsAPI);
|
|
187
|
+
},
|
|
188
|
+
destroy: function destroy() {
|
|
189
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
190
|
+
editorView.root.removeEventListener('mouseup', mouseUp);
|
|
191
|
+
if (updateSubscriber) {
|
|
192
|
+
updateSubscriber.off('resolve', resolve).off('delete', resolve).off('unresolve', unResolve).off('create', unResolve).off('setvisibility', setVisibility).off('setselectedannotation', setSelectedAnnotationFn);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
},
|
|
197
|
+
props: {
|
|
198
|
+
nodeViews: {
|
|
199
|
+
annotation: function annotation(node, view, getPos) {
|
|
200
|
+
return new _nodeviews.AnnotationNodeView(node, view, getPos, portalProviderAPI, eventDispatcher) // resolved
|
|
201
|
+
.init();
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
handleDOMEvents: {
|
|
205
|
+
mousedown: function mousedown(view) {
|
|
206
|
+
var pluginState = (0, _utils.getPluginState)(view.state);
|
|
207
|
+
if (!(pluginState !== null && pluginState !== void 0 && pluginState.mouseData.isSelecting)) {
|
|
208
|
+
hideToolbar(view.state, view.dispatch)();
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
decorations: function decorations(state) {
|
|
214
|
+
// highlight comments, depending on state
|
|
215
|
+
var _ref5 = (0, _utils.getPluginState)(state) || {},
|
|
216
|
+
draftDecorationSet = _ref5.draftDecorationSet,
|
|
217
|
+
annotations = _ref5.annotations,
|
|
218
|
+
selectedAnnotations = _ref5.selectedAnnotations,
|
|
219
|
+
isVisible = _ref5.isVisible,
|
|
220
|
+
isInlineCommentViewClosed = _ref5.isInlineCommentViewClosed;
|
|
221
|
+
var decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : _view.DecorationSet.empty;
|
|
222
|
+
var focusDecorations = [];
|
|
223
|
+
state.doc.descendants(function (node, pos) {
|
|
224
|
+
node.marks.filter(function (mark) {
|
|
225
|
+
return mark.type === state.schema.marks.annotation;
|
|
226
|
+
}).forEach(function (mark) {
|
|
227
|
+
var isSelected = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
|
|
228
|
+
return selectedAnnotation.id === mark.attrs.id;
|
|
229
|
+
})) : !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
|
|
230
|
+
return selectedAnnotation.id === mark.attrs.id;
|
|
231
|
+
}));
|
|
232
|
+
var isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
|
|
233
|
+
if (isVisible) {
|
|
234
|
+
focusDecorations.push(_view.Decoration.inline(pos, pos + node.nodeSize, {
|
|
235
|
+
class: "".concat((0, _nodeviews.getAnnotationViewClassname)(isUnresolved, isSelected), " ").concat(isUnresolved),
|
|
236
|
+
nodeName: 'span'
|
|
237
|
+
}));
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
decorations = decorations.add(state.doc, focusDecorations);
|
|
242
|
+
return decorations;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.keymapPlugin = keymapPlugin;
|
|
7
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
|
+
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
9
|
+
var _keymap = require("@atlaskit/editor-prosemirror/keymap");
|
|
10
|
+
var _commands = require("../commands");
|
|
11
|
+
function keymapPlugin(editorAnalyticsAPI) {
|
|
12
|
+
var list = {};
|
|
13
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.addInlineComment.common, (0, _commands.setInlineCommentDraftState)(editorAnalyticsAPI)(true, _analytics.INPUT_METHOD.SHORTCUT), list);
|
|
14
|
+
return (0, _keymap.keymap)(list);
|
|
15
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createPluginState = exports.createCommand = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
10
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
11
|
+
var _utils2 = require("../utils");
|
|
12
|
+
var _reducer = _interopRequireDefault(require("./reducer"));
|
|
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; }
|
|
14
|
+
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
|
+
var handleDocChanged = function handleDocChanged(tr, prevPluginState) {
|
|
16
|
+
if (!tr.getMeta('replaceDocument')) {
|
|
17
|
+
return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? getSelectionChangedHandler(false)(tr, prevPluginState) : handleSelectionChanged(tr, prevPluginState);
|
|
18
|
+
}
|
|
19
|
+
return _objectSpread(_objectSpread({}, prevPluginState), {}, {
|
|
20
|
+
dirtyAnnotations: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
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
|
+
var getSelectionChangedHandler = function getSelectionChangedHandler(reopenCommentView) {
|
|
43
|
+
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
|
+
if (pluginState.skipSelectionHandling) {
|
|
57
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
58
|
+
skipSelectionHandling: false
|
|
59
|
+
}, reopenCommentView && {
|
|
60
|
+
isInlineCommentViewClosed: false
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
var selectedAnnotations = (0, _utils2.findAnnotationsInSelection)(tr.selection, tr.doc);
|
|
64
|
+
if (selectedAnnotations.length === 0) {
|
|
65
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
66
|
+
selectedAnnotations: selectedAnnotations,
|
|
67
|
+
isInlineCommentViewClosed: true
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if ((0, _utils2.isSelectedAnnotationsChanged)(selectedAnnotations, pluginState.selectedAnnotations)) {
|
|
71
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
72
|
+
selectedAnnotations: selectedAnnotations
|
|
73
|
+
}, reopenCommentView && {
|
|
74
|
+
isInlineCommentViewClosed: false
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return _objectSpread(_objectSpread({}, pluginState), reopenCommentView && {
|
|
78
|
+
isInlineCommentViewClosed: false
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
var _pluginFactory = (0, _utils.pluginFactory)(_utils2.inlineCommentPluginKey, _reducer.default, {
|
|
83
|
+
onSelectionChanged: getSelectionChangedHandler(true),
|
|
84
|
+
onDocChanged: handleDocChanged,
|
|
85
|
+
mapping: function mapping(tr, pluginState) {
|
|
86
|
+
var draftDecorationSet = pluginState.draftDecorationSet,
|
|
87
|
+
bookmark = pluginState.bookmark;
|
|
88
|
+
var mappedDecorationSet, mappedBookmark;
|
|
89
|
+
if (draftDecorationSet) {
|
|
90
|
+
mappedDecorationSet = draftDecorationSet.map(tr.mapping, tr.doc);
|
|
91
|
+
}
|
|
92
|
+
if (bookmark) {
|
|
93
|
+
mappedBookmark = bookmark.map(tr.mapping);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// return same pluginState if mappings did not change
|
|
97
|
+
if (mappedBookmark === bookmark && mappedDecorationSet === draftDecorationSet) {
|
|
98
|
+
return pluginState;
|
|
99
|
+
}
|
|
100
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
101
|
+
draftDecorationSet: mappedDecorationSet,
|
|
102
|
+
bookmark: mappedBookmark
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}),
|
|
106
|
+
createPluginState = exports.createPluginState = _pluginFactory.createPluginState,
|
|
107
|
+
createCommand = exports.createCommand = _pluginFactory.createCommand;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
11
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
12
|
+
var _utils = require("../utils");
|
|
13
|
+
var _types = require("./types");
|
|
14
|
+
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; }
|
|
15
|
+
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; }
|
|
16
|
+
var _default = exports.default = function _default(pluginState, action) {
|
|
17
|
+
switch (action.type) {
|
|
18
|
+
case _types.ACTIONS.UPDATE_INLINE_COMMENT_STATE:
|
|
19
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
20
|
+
annotations: _objectSpread(_objectSpread({}, pluginState.annotations), action.data)
|
|
21
|
+
});
|
|
22
|
+
case _types.ACTIONS.INLINE_COMMENT_UPDATE_MOUSE_STATE:
|
|
23
|
+
var mouseData = Object.assign({}, pluginState.mouseData, action.data.mouseData);
|
|
24
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
25
|
+
mouseData: mouseData
|
|
26
|
+
});
|
|
27
|
+
case _types.ACTIONS.SET_INLINE_COMMENT_DRAFT_STATE:
|
|
28
|
+
return getNewDraftState(pluginState, action.data.drafting, action.data.editorState);
|
|
29
|
+
case _types.ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK:
|
|
30
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
31
|
+
dirtyAnnotations: false,
|
|
32
|
+
annotations: {}
|
|
33
|
+
});
|
|
34
|
+
case _types.ACTIONS.CLOSE_COMPONENT:
|
|
35
|
+
return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
36
|
+
isInlineCommentViewClosed: true
|
|
37
|
+
}) : _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
38
|
+
selectedAnnotations: []
|
|
39
|
+
});
|
|
40
|
+
case _types.ACTIONS.ADD_INLINE_COMMENT:
|
|
41
|
+
var updatedPluginState = getNewDraftState(pluginState, action.data.drafting, action.data.editorState);
|
|
42
|
+
return _objectSpread(_objectSpread({}, updatedPluginState), {}, {
|
|
43
|
+
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') && {
|
|
46
|
+
isInlineCommentViewClosed: false
|
|
47
|
+
});
|
|
48
|
+
case _types.ACTIONS.INLINE_COMMENT_SET_VISIBLE:
|
|
49
|
+
var isVisible = action.data.isVisible;
|
|
50
|
+
if (isVisible === pluginState.isVisible) {
|
|
51
|
+
return pluginState;
|
|
52
|
+
}
|
|
53
|
+
return _objectSpread(_objectSpread({}, isVisible ? pluginState : getNewDraftState(pluginState, false)), {}, {
|
|
54
|
+
isVisible: isVisible
|
|
55
|
+
});
|
|
56
|
+
case _types.ACTIONS.SET_SELECTED_ANNOTATION:
|
|
57
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
58
|
+
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
|
|
62
|
+
isInlineCommentViewClosed: false
|
|
63
|
+
});
|
|
64
|
+
default:
|
|
65
|
+
return pluginState;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
function getNewDraftState(pluginState, drafting, editorState) {
|
|
69
|
+
var draftDecorationSet = pluginState.draftDecorationSet;
|
|
70
|
+
if (!draftDecorationSet || !drafting) {
|
|
71
|
+
draftDecorationSet = _view.DecorationSet.empty;
|
|
72
|
+
}
|
|
73
|
+
var newState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
74
|
+
draftDecorationSet: draftDecorationSet
|
|
75
|
+
});
|
|
76
|
+
newState.bookmark = undefined;
|
|
77
|
+
if (drafting && editorState) {
|
|
78
|
+
newState.bookmark = editorState.selection.getBookmark();
|
|
79
|
+
var resolvedBookmark = newState.bookmark.resolve(editorState.doc);
|
|
80
|
+
var draftDecoration = (0, _utils.addDraftDecoration)(resolvedBookmark.from, resolvedBookmark.to);
|
|
81
|
+
newState.draftDecorationSet = draftDecorationSet.add(editorState.doc, [draftDecoration]);
|
|
82
|
+
}
|
|
83
|
+
return newState;
|
|
84
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ACTIONS = void 0;
|
|
7
|
+
var ACTIONS = exports.ACTIONS = /*#__PURE__*/function (ACTIONS) {
|
|
8
|
+
ACTIONS[ACTIONS["UPDATE_INLINE_COMMENT_STATE"] = 0] = "UPDATE_INLINE_COMMENT_STATE";
|
|
9
|
+
ACTIONS[ACTIONS["SET_INLINE_COMMENT_DRAFT_STATE"] = 1] = "SET_INLINE_COMMENT_DRAFT_STATE";
|
|
10
|
+
ACTIONS[ACTIONS["INLINE_COMMENT_UPDATE_MOUSE_STATE"] = 2] = "INLINE_COMMENT_UPDATE_MOUSE_STATE";
|
|
11
|
+
ACTIONS[ACTIONS["INLINE_COMMENT_CLEAR_DIRTY_MARK"] = 3] = "INLINE_COMMENT_CLEAR_DIRTY_MARK";
|
|
12
|
+
ACTIONS[ACTIONS["ADD_INLINE_COMMENT"] = 4] = "ADD_INLINE_COMMENT";
|
|
13
|
+
ACTIONS[ACTIONS["INLINE_COMMENT_SET_VISIBLE"] = 5] = "INLINE_COMMENT_SET_VISIBLE";
|
|
14
|
+
ACTIONS[ACTIONS["CLOSE_COMPONENT"] = 6] = "CLOSE_COMPONENT";
|
|
15
|
+
ACTIONS[ACTIONS["SET_SELECTED_ANNOTATION"] = 7] = "SET_SELECTED_ANNOTATION";
|
|
16
|
+
return ACTIONS;
|
|
17
|
+
}({});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.buildToolbar = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
10
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
11
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
12
|
+
var _comment = _interopRequireDefault(require("@atlaskit/icon/glyph/comment"));
|
|
13
|
+
var _commands = require("./commands");
|
|
14
|
+
var _types = require("./types");
|
|
15
|
+
var _utils2 = require("./utils");
|
|
16
|
+
var buildToolbar = exports.buildToolbar = function buildToolbar(editorAnalyticsAPI) {
|
|
17
|
+
return function (state, intl) {
|
|
18
|
+
var isToolbarAbove = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
19
|
+
var schema = state.schema;
|
|
20
|
+
var selectionValid = (0, _utils2.isSelectionValid)(state);
|
|
21
|
+
if (selectionValid === _types.AnnotationSelectionType.INVALID) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
var createCommentMessage = intl.formatMessage(_messages.annotationMessages.createComment);
|
|
25
|
+
var commentDisabledMessage = intl.formatMessage(_messages.annotationMessages.createCommentInvalid);
|
|
26
|
+
var createComment = {
|
|
27
|
+
type: 'button',
|
|
28
|
+
showTitle: true,
|
|
29
|
+
disabled: selectionValid === _types.AnnotationSelectionType.DISABLED,
|
|
30
|
+
testId: _types.AnnotationTestIds.floatingToolbarCreateButton,
|
|
31
|
+
icon: _comment.default,
|
|
32
|
+
tooltipContent: selectionValid === _types.AnnotationSelectionType.DISABLED ? commentDisabledMessage : /*#__PURE__*/_react.default.createElement(_keymaps.ToolTipContent, {
|
|
33
|
+
description: createCommentMessage,
|
|
34
|
+
keymap: _keymaps.addInlineComment
|
|
35
|
+
}),
|
|
36
|
+
title: createCommentMessage,
|
|
37
|
+
onClick: function onClick(state, dispatch) {
|
|
38
|
+
return (0, _commands.setInlineCommentDraftState)(editorAnalyticsAPI)(true)(state, dispatch);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var annotation = schema.marks.annotation;
|
|
42
|
+
var validNodes = Object.keys(schema.nodes).reduce(function (acc, current) {
|
|
43
|
+
var type = schema.nodes[current];
|
|
44
|
+
if (type.allowsMarkType(annotation)) {
|
|
45
|
+
acc.push(type);
|
|
46
|
+
}
|
|
47
|
+
return acc;
|
|
48
|
+
}, []);
|
|
49
|
+
var toolbarTitle = intl.formatMessage(_messages.annotationMessages.toolbar);
|
|
50
|
+
var calcToolbarPosition = isToolbarAbove ? _utils.calculateToolbarPositionAboveSelection : _utils.calculateToolbarPositionTrackHead;
|
|
51
|
+
var onPositionCalculated = calcToolbarPosition(toolbarTitle);
|
|
52
|
+
return {
|
|
53
|
+
title: toolbarTitle,
|
|
54
|
+
nodeType: validNodes,
|
|
55
|
+
items: [createComment],
|
|
56
|
+
onPositionCalculated: onPositionCalculated
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AnnotationTestIds = exports.AnnotationSelectionType = void 0;
|
|
7
|
+
var AnnotationSelectionType = exports.AnnotationSelectionType = /*#__PURE__*/function (AnnotationSelectionType) {
|
|
8
|
+
AnnotationSelectionType["INVALID"] = "invalid";
|
|
9
|
+
AnnotationSelectionType["DISABLED"] = "disabled";
|
|
10
|
+
AnnotationSelectionType["VALID"] = "valid";
|
|
11
|
+
return AnnotationSelectionType;
|
|
12
|
+
}({}); // Annotation can be created
|
|
13
|
+
var prefix = 'ak-editor-annotation';
|
|
14
|
+
var AnnotationTestIds = exports.AnnotationTestIds = {
|
|
15
|
+
prefix: prefix,
|
|
16
|
+
floatingComponent: "".concat(prefix, "-floating-component"),
|
|
17
|
+
floatingToolbarCreateButton: "".concat(prefix, "-toolbar-create-button"),
|
|
18
|
+
componentSave: "".concat(prefix, "-dummy-save-button"),
|
|
19
|
+
componentClose: "".concat(prefix, "-dummy-close-button")
|
|
20
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.AnnotationViewWrapper = void 0;
|
|
8
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
11
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
12
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
13
|
+
var _react = _interopRequireDefault(require("react"));
|
|
14
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
15
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
16
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
17
|
+
var AnnotationViewWrapper = exports.AnnotationViewWrapper = /*#__PURE__*/function (_React$PureComponent) {
|
|
18
|
+
(0, _inherits2.default)(AnnotationViewWrapper, _React$PureComponent);
|
|
19
|
+
var _super = _createSuper(AnnotationViewWrapper);
|
|
20
|
+
function AnnotationViewWrapper() {
|
|
21
|
+
(0, _classCallCheck2.default)(this, AnnotationViewWrapper);
|
|
22
|
+
return _super.apply(this, arguments);
|
|
23
|
+
}
|
|
24
|
+
(0, _createClass2.default)(AnnotationViewWrapper, [{
|
|
25
|
+
key: "componentDidMount",
|
|
26
|
+
value: function componentDidMount() {
|
|
27
|
+
var onViewed = this.props.onViewed;
|
|
28
|
+
if (onViewed) {
|
|
29
|
+
onViewed();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
key: "render",
|
|
34
|
+
value: function render() {
|
|
35
|
+
return this.props.children;
|
|
36
|
+
}
|
|
37
|
+
}]);
|
|
38
|
+
return AnnotationViewWrapper;
|
|
39
|
+
}(_react.default.PureComponent);
|