@atlaskit/renderer 115.0.3 → 115.0.4
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 +10 -0
- package/dist/cjs/ui/Renderer/index.js +1 -1
- package/dist/cjs/ui/annotations/contexts/AnnotationManagerContext.js +421 -0
- package/dist/cjs/ui/annotations/draft/component.js +13 -1
- package/dist/cjs/ui/annotations/element/index.js +38 -6
- package/dist/cjs/ui/annotations/element/mark.js +16 -0
- package/dist/cjs/ui/annotations/hooks/use-events.js +77 -27
- package/dist/cjs/ui/annotations/hooks/use-load-annotations.js +18 -2
- package/dist/cjs/ui/annotations/index.js +49 -12
- package/dist/cjs/ui/annotations/selection/mounter.js +177 -4
- package/dist/es2019/ui/Renderer/index.js +1 -1
- package/dist/es2019/ui/annotations/contexts/AnnotationManagerContext.js +416 -0
- package/dist/es2019/ui/annotations/draft/component.js +15 -3
- package/dist/es2019/ui/annotations/element/index.js +39 -6
- package/dist/es2019/ui/annotations/element/mark.js +18 -0
- package/dist/es2019/ui/annotations/hooks/use-events.js +85 -28
- package/dist/es2019/ui/annotations/hooks/use-load-annotations.js +19 -2
- package/dist/es2019/ui/annotations/index.js +47 -10
- package/dist/es2019/ui/annotations/selection/mounter.js +177 -6
- package/dist/esm/ui/Renderer/index.js +1 -1
- package/dist/esm/ui/annotations/contexts/AnnotationManagerContext.js +411 -0
- package/dist/esm/ui/annotations/draft/component.js +14 -3
- package/dist/esm/ui/annotations/element/index.js +38 -6
- package/dist/esm/ui/annotations/element/mark.js +16 -0
- package/dist/esm/ui/annotations/hooks/use-events.js +78 -28
- package/dist/esm/ui/annotations/hooks/use-load-annotations.js +18 -2
- package/dist/esm/ui/annotations/index.js +45 -10
- package/dist/esm/ui/annotations/selection/mounter.js +179 -6
- package/dist/types/ui/annotations/contexts/AnnotationManagerContext.d.ts +71 -0
- package/dist/types/ui/annotations/draft/component.d.ts +5 -1
- package/dist/types/ui/annotations/element/mark.d.ts +6 -0
- package/dist/types/ui/annotations/index.d.ts +1 -0
- package/dist/types-ts4.5/ui/annotations/contexts/AnnotationManagerContext.d.ts +71 -0
- package/dist/types-ts4.5/ui/annotations/draft/component.d.ts +5 -1
- package/dist/types-ts4.5/ui/annotations/element/mark.d.ts +6 -0
- package/dist/types-ts4.5/ui/annotations/index.d.ts +1 -0
- package/package.json +9 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaskit/renderer
|
|
2
2
|
|
|
3
|
+
## 115.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#142925](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/142925)
|
|
8
|
+
[`e013698350bef`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e013698350bef) -
|
|
9
|
+
This updates the renderer to use the new annotation manager create comment APIs and disables the
|
|
10
|
+
use of the old create hooks. This should be backward compatible and can be controled by a FG
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
3
13
|
## 115.0.3
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -60,7 +60,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
60
60
|
var NORMAL_SEVERITY_THRESHOLD = exports.NORMAL_SEVERITY_THRESHOLD = 2000;
|
|
61
61
|
var DEGRADED_SEVERITY_THRESHOLD = exports.DEGRADED_SEVERITY_THRESHOLD = 3000;
|
|
62
62
|
var packageName = "@atlaskit/renderer";
|
|
63
|
-
var packageVersion = "115.0.
|
|
63
|
+
var packageVersion = "115.0.4";
|
|
64
64
|
var setAsQueryContainerStyles = (0, _react2.css)({
|
|
65
65
|
containerName: 'ak-renderer-wrapper',
|
|
66
66
|
containerType: 'inline-size',
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useAnnotationManagerState = exports.useAnnotationManagerDispatch = exports.AnnotationManagerProvider = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
+
var _adfSchema = require("@atlaskit/adf-schema");
|
|
13
|
+
var _types = require("@atlaskit/editor-common/types");
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
var initState = {
|
|
19
|
+
isDrafting: false,
|
|
20
|
+
draftId: undefined,
|
|
21
|
+
draftMarkRef: undefined,
|
|
22
|
+
draftActionResult: undefined,
|
|
23
|
+
annotations: {},
|
|
24
|
+
currentSelectedAnnotationId: undefined,
|
|
25
|
+
currentSelectedMarkRef: undefined,
|
|
26
|
+
currentHoveredAnnotationId: undefined
|
|
27
|
+
};
|
|
28
|
+
var AnnotationManagerStateContext = /*#__PURE__*/(0, _react.createContext)(initState);
|
|
29
|
+
var AnnotationManagerDispatchContext = /*#__PURE__*/(0, _react.createContext)({
|
|
30
|
+
annotationManager: undefined,
|
|
31
|
+
dispatch: function dispatch() {}
|
|
32
|
+
});
|
|
33
|
+
function reducer(state, action) {
|
|
34
|
+
switch (action.type) {
|
|
35
|
+
case 'reset':
|
|
36
|
+
{
|
|
37
|
+
return _objectSpread(_objectSpread({}, state), initState);
|
|
38
|
+
}
|
|
39
|
+
case 'loadAnnotation':
|
|
40
|
+
{
|
|
41
|
+
var currentIds = Object.keys(state.annotations);
|
|
42
|
+
var uids = Array.from(new Set(currentIds.concat(action.data.map(function (a) {
|
|
43
|
+
return a.id;
|
|
44
|
+
}))));
|
|
45
|
+
var updates = [];
|
|
46
|
+
var _loop = function _loop() {
|
|
47
|
+
var _state$annotations$id, _state$annotations$id2;
|
|
48
|
+
var id = _uids[_i];
|
|
49
|
+
var loadedAnnotation = action.data.find(function (a) {
|
|
50
|
+
return a.id === id;
|
|
51
|
+
});
|
|
52
|
+
if (!loadedAnnotation && ((_state$annotations$id = state.annotations[id]) === null || _state$annotations$id === void 0 ? void 0 : _state$annotations$id.markState) === _adfSchema.AnnotationMarkStates.ACTIVE) {
|
|
53
|
+
// If the annotation is not in the loaded data, we need to remove it from the state. However,
|
|
54
|
+
// rather then removing it, we will set the mark state to resolved. This is to align it better with
|
|
55
|
+
// how the editor works.
|
|
56
|
+
updates.push({
|
|
57
|
+
id: id,
|
|
58
|
+
markState: _adfSchema.AnnotationMarkStates.RESOLVED
|
|
59
|
+
});
|
|
60
|
+
return 0; // continue
|
|
61
|
+
}
|
|
62
|
+
if (!!(loadedAnnotation !== null && loadedAnnotation !== void 0 && loadedAnnotation.markState) && ((_state$annotations$id2 = state.annotations[id]) === null || _state$annotations$id2 === void 0 ? void 0 : _state$annotations$id2.markState) !== loadedAnnotation.markState) {
|
|
63
|
+
updates.push({
|
|
64
|
+
id: id,
|
|
65
|
+
markState: loadedAnnotation.markState
|
|
66
|
+
});
|
|
67
|
+
return 0; // continue
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
_ret;
|
|
71
|
+
for (var _i = 0, _uids = uids; _i < _uids.length; _i++) {
|
|
72
|
+
_ret = _loop();
|
|
73
|
+
if (_ret === 0) continue;
|
|
74
|
+
}
|
|
75
|
+
if (updates.length > 0) {
|
|
76
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
77
|
+
annotations: updates.reduce(function (nextAnnotations, update) {
|
|
78
|
+
return _objectSpread(_objectSpread({}, nextAnnotations), {}, (0, _defineProperty2.default)({}, update.id, _objectSpread(_objectSpread({}, nextAnnotations[update.id]), update)));
|
|
79
|
+
}, state.annotations)
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return state;
|
|
83
|
+
}
|
|
84
|
+
case 'updateAnnotation':
|
|
85
|
+
{
|
|
86
|
+
var current = state.annotations[action.data.id];
|
|
87
|
+
var _action$data = action.data,
|
|
88
|
+
id = _action$data.id,
|
|
89
|
+
selected = _action$data.selected,
|
|
90
|
+
hovered = _action$data.hovered,
|
|
91
|
+
_action$data$markStat = _action$data.markState,
|
|
92
|
+
markState = _action$data$markStat === void 0 ? current === null || current === void 0 ? void 0 : current.markState : _action$data$markStat;
|
|
93
|
+
var _updates = [];
|
|
94
|
+
|
|
95
|
+
// If the annotation is not currently in the state, we need to add it to the state.
|
|
96
|
+
if (!current) {
|
|
97
|
+
_updates.push({
|
|
98
|
+
id: id,
|
|
99
|
+
markState: markState !== null && markState !== void 0 ? markState : _adfSchema.AnnotationMarkStates.ACTIVE
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// The goal of the following is to enforce a single selection and a single hover state across all annotations.
|
|
104
|
+
var nextSelectedId = state.currentSelectedAnnotationId;
|
|
105
|
+
if (selected && nextSelectedId !== id) {
|
|
106
|
+
nextSelectedId = id;
|
|
107
|
+
}
|
|
108
|
+
// If the annotation is currently selected and it's being unselected, we need to remove it from the
|
|
109
|
+
// current selected annotation id.
|
|
110
|
+
if (selected === false && nextSelectedId === id) {
|
|
111
|
+
nextSelectedId = undefined;
|
|
112
|
+
}
|
|
113
|
+
var nextHoveredId = state.currentHoveredAnnotationId;
|
|
114
|
+
if (hovered && nextHoveredId !== id) {
|
|
115
|
+
nextHoveredId = id;
|
|
116
|
+
}
|
|
117
|
+
// If the annotation is currently hovered and it's being unhovered, we need to remove it from the
|
|
118
|
+
// current hovered annotation id.
|
|
119
|
+
if (hovered === false && nextHoveredId === id) {
|
|
120
|
+
nextHoveredId = undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// If the annotations mark state is not the same as the current mark state, we need to update it.
|
|
124
|
+
if ((current === null || current === void 0 ? void 0 : current.markState) !== markState) {
|
|
125
|
+
_updates.push({
|
|
126
|
+
id: id,
|
|
127
|
+
markState: markState !== null && markState !== void 0 ? markState : _adfSchema.AnnotationMarkStates.ACTIVE
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// If the annotation is currently selected and it's being resolved, then we need to remove it from the
|
|
131
|
+
// current selected annotation id also.
|
|
132
|
+
if (markState === _adfSchema.AnnotationMarkStates.RESOLVED && nextSelectedId === id) {
|
|
133
|
+
nextSelectedId = undefined;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (_updates.length > 0 || nextSelectedId !== state.currentSelectedAnnotationId || nextHoveredId !== state.currentHoveredAnnotationId) {
|
|
137
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
138
|
+
currentSelectedAnnotationId: nextSelectedId,
|
|
139
|
+
currentHoveredAnnotationId: nextHoveredId,
|
|
140
|
+
annotations: _updates.reduce(function (nextAnnotations, update) {
|
|
141
|
+
return _objectSpread(_objectSpread({}, nextAnnotations), {}, (0, _defineProperty2.default)({}, update.id, _objectSpread(_objectSpread({}, nextAnnotations[update.id]), update)));
|
|
142
|
+
}, state.annotations)
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return state;
|
|
146
|
+
}
|
|
147
|
+
case 'resetSelectedAnnotation':
|
|
148
|
+
{
|
|
149
|
+
if (state.currentSelectedAnnotationId !== undefined) {
|
|
150
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
151
|
+
currentSelectedAnnotationId: undefined,
|
|
152
|
+
currentSelectedMarkRef: undefined
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return state;
|
|
156
|
+
}
|
|
157
|
+
case 'resetHoveredAnnotation':
|
|
158
|
+
{
|
|
159
|
+
if (state.currentHoveredAnnotationId !== undefined) {
|
|
160
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
161
|
+
currentHoveredAnnotationId: undefined
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return state;
|
|
165
|
+
}
|
|
166
|
+
case 'setDrafting':
|
|
167
|
+
{
|
|
168
|
+
if (state.isDrafting !== action.data.isDrafting || state.draftId !== action.data.draftId || state.draftActionResult !== action.data.draftActionResult) {
|
|
169
|
+
// XXX: When a draft is open the current selected annotation should no longer be selected. We need
|
|
170
|
+
// to decide what is better UX,
|
|
171
|
+
// 1 - do we want to deselct the selected annotation on draft open, if so then when draft is closed the s
|
|
172
|
+
// selected annotation will not come back
|
|
173
|
+
// 2 - do we want to still allow the selected annotation to be selected when draft is open, however the underlying
|
|
174
|
+
// mark style just shows the annotation as not selected when a draft is active. Then when a draft closes
|
|
175
|
+
// we can reopen the previous selected annotation.
|
|
176
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
177
|
+
isDrafting: action.data.isDrafting,
|
|
178
|
+
draftId: action.data.draftId,
|
|
179
|
+
draftActionResult: action.data.draftActionResult
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return state;
|
|
183
|
+
}
|
|
184
|
+
case 'setDraftMarkRef':
|
|
185
|
+
{
|
|
186
|
+
if (state.draftMarkRef !== action.data.draftMarkRef) {
|
|
187
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
188
|
+
draftMarkRef: action.data.draftMarkRef
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return state;
|
|
192
|
+
}
|
|
193
|
+
case 'setSelectedMarkRef':
|
|
194
|
+
{
|
|
195
|
+
if (state.currentSelectedMarkRef !== action.data.markRef) {
|
|
196
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
197
|
+
currentSelectedMarkRef: action.data.markRef
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return state;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
var AnnotationManagerProvider = exports.AnnotationManagerProvider = function AnnotationManagerProvider(_ref) {
|
|
205
|
+
var children = _ref.children,
|
|
206
|
+
annotationManager = _ref.annotationManager,
|
|
207
|
+
updateSubscriber = _ref.updateSubscriber;
|
|
208
|
+
var _useReducer = (0, _react.useReducer)(reducer, initState),
|
|
209
|
+
_useReducer2 = (0, _slicedToArray2.default)(_useReducer, 2),
|
|
210
|
+
state = _useReducer2[0],
|
|
211
|
+
dispatch = _useReducer2[1];
|
|
212
|
+
(0, _react.useEffect)(function () {
|
|
213
|
+
var getDraft = function getDraft() {
|
|
214
|
+
var _state$draftActionRes;
|
|
215
|
+
if (!state.isDrafting || !state.draftActionResult || !state.draftMarkRef || !state.draftId) {
|
|
216
|
+
return {
|
|
217
|
+
success: false,
|
|
218
|
+
reason: 'draft-not-started'
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
success: true,
|
|
223
|
+
inlineNodeTypes: (_state$draftActionRes = state.draftActionResult.inlineNodeTypes) !== null && _state$draftActionRes !== void 0 ? _state$draftActionRes : [],
|
|
224
|
+
targetElement: state.draftMarkRef,
|
|
225
|
+
actionResult: {
|
|
226
|
+
step: state.draftActionResult.step,
|
|
227
|
+
doc: state.draftActionResult.doc,
|
|
228
|
+
inlineNodeTypes: state.draftActionResult.inlineNodeTypes,
|
|
229
|
+
targetNodeType: state.draftActionResult.targetNodeType,
|
|
230
|
+
originalSelection: state.draftActionResult.originalSelection,
|
|
231
|
+
numMatches: state.draftActionResult.numMatches,
|
|
232
|
+
matchIndex: state.draftActionResult.matchIndex,
|
|
233
|
+
pos: state.draftActionResult.pos
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
annotationManager === null || annotationManager === void 0 || annotationManager.hook('getDraft', getDraft);
|
|
238
|
+
return function () {
|
|
239
|
+
annotationManager === null || annotationManager === void 0 || annotationManager.unhook('getDraft', getDraft);
|
|
240
|
+
};
|
|
241
|
+
}, [annotationManager, state.draftId, state.isDrafting, state.draftMarkRef, state.draftActionResult]);
|
|
242
|
+
|
|
243
|
+
// We need to watch for the draft mark element to exist, so we can inform any listeners that the draft has been started
|
|
244
|
+
// and give them a reference to the element
|
|
245
|
+
(0, _react.useEffect)(function () {
|
|
246
|
+
if (state.isDrafting && state.draftId && state.draftMarkRef && state.draftActionResult) {
|
|
247
|
+
var _state$draftActionRes2;
|
|
248
|
+
annotationManager === null || annotationManager === void 0 || annotationManager.emit({
|
|
249
|
+
name: 'draftAnnotationStarted',
|
|
250
|
+
data: {
|
|
251
|
+
inlineNodeTypes: (_state$draftActionRes2 = state.draftActionResult.inlineNodeTypes) !== null && _state$draftActionRes2 !== void 0 ? _state$draftActionRes2 : [],
|
|
252
|
+
targetElement: state.draftMarkRef,
|
|
253
|
+
actionResult: {
|
|
254
|
+
step: state.draftActionResult.step,
|
|
255
|
+
doc: state.draftActionResult.doc,
|
|
256
|
+
inlineNodeTypes: state.draftActionResult.inlineNodeTypes,
|
|
257
|
+
targetNodeType: state.draftActionResult.targetNodeType,
|
|
258
|
+
originalSelection: state.draftActionResult.originalSelection,
|
|
259
|
+
numMatches: state.draftActionResult.numMatches,
|
|
260
|
+
matchIndex: state.draftActionResult.matchIndex,
|
|
261
|
+
pos: state.draftActionResult.pos
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}, [annotationManager, state.draftId, state.isDrafting, state.draftMarkRef, state.draftActionResult]);
|
|
267
|
+
|
|
268
|
+
// useEffect(() => {
|
|
269
|
+
// const setIsAnnotationSelected = (id: AnnotationId, isSelected: boolean): SelectAnnotationResult => {
|
|
270
|
+
// if (!state.annotations?.[id]) {
|
|
271
|
+
// return {
|
|
272
|
+
// success: false,
|
|
273
|
+
// reason: 'id-not-valid',
|
|
274
|
+
// };
|
|
275
|
+
// }
|
|
276
|
+
|
|
277
|
+
// dispatch({
|
|
278
|
+
// type: 'updateAnnotation',
|
|
279
|
+
// data: {
|
|
280
|
+
// id,
|
|
281
|
+
// selected: isSelected,
|
|
282
|
+
// },
|
|
283
|
+
// })
|
|
284
|
+
|
|
285
|
+
// return {
|
|
286
|
+
// success: true,
|
|
287
|
+
// isSelected,
|
|
288
|
+
// };
|
|
289
|
+
// };
|
|
290
|
+
|
|
291
|
+
// annotationManager?.hook('setIsAnnotationSelected', setIsAnnotationSelected);
|
|
292
|
+
// return () => {
|
|
293
|
+
// annotationManager?.unhook('setIsAnnotationSelected', setIsAnnotationSelected);
|
|
294
|
+
// };
|
|
295
|
+
// }, [state.annotations]);
|
|
296
|
+
|
|
297
|
+
// useEffect(() => {
|
|
298
|
+
// console.log('annotationsSelectedChanged', state.annotationsSelectedChanged);
|
|
299
|
+
|
|
300
|
+
// // if (state.isDrafting && state.currentDraftId && state.draftMarkRef) {
|
|
301
|
+
// // annotationManager?.emit({
|
|
302
|
+
// // name: 'annotationSelectionChanged',
|
|
303
|
+
// // data: {
|
|
304
|
+
// // annotationId: state.currentDraftId,
|
|
305
|
+
// // inlineNodeTypes: [],
|
|
306
|
+
// // isSelected: true,
|
|
307
|
+
// // },
|
|
308
|
+
// // });
|
|
309
|
+
// // }
|
|
310
|
+
// }, [annotationManager, state.annotationsSelectedChanged]);
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* This is a temporary solution to ensure that the annotation manager state is in sync with the
|
|
314
|
+
* old updateSubscriber. The updateSubscriber will eventually be deprecated and the state will be managed
|
|
315
|
+
* by the annotation manager itself.
|
|
316
|
+
*/
|
|
317
|
+
(0, _react.useEffect)(function () {
|
|
318
|
+
var onSetAnnotationState = function onSetAnnotationState(payload) {
|
|
319
|
+
if (!payload) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
Object.values(payload).forEach(function (annotation) {
|
|
323
|
+
if (annotation.id && annotation.annotationType === _adfSchema.AnnotationTypes.INLINE_COMMENT && !annotation.state) {
|
|
324
|
+
var _annotation$state;
|
|
325
|
+
dispatch({
|
|
326
|
+
type: 'updateAnnotation',
|
|
327
|
+
data: {
|
|
328
|
+
id: annotation.id,
|
|
329
|
+
markState: (_annotation$state = annotation.state) !== null && _annotation$state !== void 0 ? _annotation$state : undefined
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
};
|
|
335
|
+
var onAnnotationSelected = function onAnnotationSelected(payload) {
|
|
336
|
+
dispatch({
|
|
337
|
+
type: 'updateAnnotation',
|
|
338
|
+
data: {
|
|
339
|
+
id: payload.annotationId,
|
|
340
|
+
selected: true
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
var onAnnotationHovered = function onAnnotationHovered(payload) {
|
|
345
|
+
dispatch({
|
|
346
|
+
type: 'updateAnnotation',
|
|
347
|
+
data: {
|
|
348
|
+
id: payload.annotationId,
|
|
349
|
+
hovered: true
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
};
|
|
353
|
+
var onAnnotationSelectedRemoved = function onAnnotationSelectedRemoved() {
|
|
354
|
+
dispatch({
|
|
355
|
+
type: 'resetSelectedAnnotation'
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
var onAnnotationHoveredRemoved = function onAnnotationHoveredRemoved() {
|
|
359
|
+
dispatch({
|
|
360
|
+
type: 'resetHoveredAnnotation'
|
|
361
|
+
});
|
|
362
|
+
};
|
|
363
|
+
var onAnnotationClick = function onAnnotationClick(_ref2) {
|
|
364
|
+
var annotationIds = _ref2.annotationIds,
|
|
365
|
+
eventTarget = _ref2.eventTarget,
|
|
366
|
+
eventTargetType = _ref2.eventTargetType,
|
|
367
|
+
viewMethod = _ref2.viewMethod;
|
|
368
|
+
dispatch({
|
|
369
|
+
type: 'updateAnnotation',
|
|
370
|
+
data: {
|
|
371
|
+
id: annotationIds[0],
|
|
372
|
+
selected: true
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
dispatch({
|
|
376
|
+
type: 'setSelectedMarkRef',
|
|
377
|
+
data: {
|
|
378
|
+
markRef: eventTarget
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
};
|
|
382
|
+
var onAnnotationDeselect = function onAnnotationDeselect() {
|
|
383
|
+
dispatch({
|
|
384
|
+
type: 'resetSelectedAnnotation'
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
updateSubscriber === null || updateSubscriber === void 0 || updateSubscriber.on(_types.AnnotationUpdateEvent.SET_ANNOTATION_STATE, onSetAnnotationState);
|
|
388
|
+
updateSubscriber === null || updateSubscriber === void 0 || updateSubscriber.on(_types.AnnotationUpdateEvent.SET_ANNOTATION_FOCUS, onAnnotationSelected);
|
|
389
|
+
updateSubscriber === null || updateSubscriber === void 0 || updateSubscriber.on(_types.AnnotationUpdateEvent.SET_ANNOTATION_HOVERED, onAnnotationHovered);
|
|
390
|
+
updateSubscriber === null || updateSubscriber === void 0 || updateSubscriber.on(_types.AnnotationUpdateEvent.REMOVE_ANNOTATION_FOCUS, onAnnotationSelectedRemoved);
|
|
391
|
+
updateSubscriber === null || updateSubscriber === void 0 || updateSubscriber.on(_types.AnnotationUpdateEvent.REMOVE_ANNOTATION_HOVERED, onAnnotationHoveredRemoved);
|
|
392
|
+
updateSubscriber === null || updateSubscriber === void 0 || updateSubscriber.on(_types.AnnotationUpdateEvent.ON_ANNOTATION_CLICK, onAnnotationClick);
|
|
393
|
+
updateSubscriber === null || updateSubscriber === void 0 || updateSubscriber.on(_types.AnnotationUpdateEvent.DESELECT_ANNOTATIONS, onAnnotationDeselect);
|
|
394
|
+
return function () {
|
|
395
|
+
updateSubscriber === null || updateSubscriber === void 0 || updateSubscriber.off(_types.AnnotationUpdateEvent.SET_ANNOTATION_STATE, onSetAnnotationState);
|
|
396
|
+
updateSubscriber === null || updateSubscriber === void 0 || updateSubscriber.off(_types.AnnotationUpdateEvent.SET_ANNOTATION_FOCUS, onAnnotationSelected);
|
|
397
|
+
updateSubscriber === null || updateSubscriber === void 0 || updateSubscriber.off(_types.AnnotationUpdateEvent.SET_ANNOTATION_HOVERED, onAnnotationHovered);
|
|
398
|
+
updateSubscriber === null || updateSubscriber === void 0 || updateSubscriber.off(_types.AnnotationUpdateEvent.REMOVE_ANNOTATION_FOCUS, onAnnotationSelectedRemoved);
|
|
399
|
+
updateSubscriber === null || updateSubscriber === void 0 || updateSubscriber.off(_types.AnnotationUpdateEvent.REMOVE_ANNOTATION_HOVERED, onAnnotationHoveredRemoved);
|
|
400
|
+
updateSubscriber === null || updateSubscriber === void 0 || updateSubscriber.off(_types.AnnotationUpdateEvent.ON_ANNOTATION_CLICK, onAnnotationClick);
|
|
401
|
+
updateSubscriber === null || updateSubscriber === void 0 || updateSubscriber.off(_types.AnnotationUpdateEvent.DESELECT_ANNOTATIONS, onAnnotationDeselect);
|
|
402
|
+
};
|
|
403
|
+
}, [updateSubscriber]);
|
|
404
|
+
var dispatchData = (0, _react.useMemo)(function () {
|
|
405
|
+
return {
|
|
406
|
+
annotationManager: annotationManager,
|
|
407
|
+
dispatch: dispatch
|
|
408
|
+
};
|
|
409
|
+
}, [annotationManager, dispatch]);
|
|
410
|
+
return /*#__PURE__*/_react.default.createElement(AnnotationManagerStateContext.Provider, {
|
|
411
|
+
value: state
|
|
412
|
+
}, /*#__PURE__*/_react.default.createElement(AnnotationManagerDispatchContext.Provider, {
|
|
413
|
+
value: dispatchData
|
|
414
|
+
}, children));
|
|
415
|
+
};
|
|
416
|
+
var useAnnotationManagerState = exports.useAnnotationManagerState = function useAnnotationManagerState() {
|
|
417
|
+
return (0, _react.useContext)(AnnotationManagerStateContext);
|
|
418
|
+
};
|
|
419
|
+
var useAnnotationManagerDispatch = exports.useAnnotationManagerDispatch = function useAnnotationManagerDispatch() {
|
|
420
|
+
return (0, _react.useContext)(AnnotationManagerDispatchContext);
|
|
421
|
+
};
|
|
@@ -16,6 +16,7 @@ var _position = require("./position");
|
|
|
16
16
|
var _dom = require("./dom");
|
|
17
17
|
var _segmentText = require("../../../react/utils/segment-text");
|
|
18
18
|
var _renderTextSegments = require("../../../react/utils/render-text-segments");
|
|
19
|
+
var _AnnotationManagerContext = require("../contexts/AnnotationManagerContext");
|
|
19
20
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
20
21
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
21
22
|
/**
|
|
@@ -48,12 +49,23 @@ var markStyles = (0, _react2.css)({
|
|
|
48
49
|
var AnnotationDraft = exports.AnnotationDraft = function AnnotationDraft(_ref) {
|
|
49
50
|
var draftPosition = _ref.draftPosition,
|
|
50
51
|
children = _ref.children;
|
|
52
|
+
var _useAnnotationManager = (0, _AnnotationManagerContext.useAnnotationManagerDispatch)(),
|
|
53
|
+
dispatch = _useAnnotationManager.dispatch;
|
|
54
|
+
var markRef = (0, _react.useCallback)(function (node) {
|
|
55
|
+
dispatch({
|
|
56
|
+
type: 'setDraftMarkRef',
|
|
57
|
+
data: {
|
|
58
|
+
draftMarkRef: node !== null && node !== void 0 ? node : undefined
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}, [dispatch]);
|
|
51
62
|
return (0, _react2.jsx)("mark", (0, _extends2.default)({
|
|
52
63
|
"data-renderer-mark": true
|
|
53
64
|
// Ignored via go/ees005
|
|
54
65
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
55
66
|
}, (0, _dom.dataAttributes)(draftPosition), {
|
|
56
|
-
css: markStyles
|
|
67
|
+
css: markStyles,
|
|
68
|
+
ref: markRef
|
|
57
69
|
}), children);
|
|
58
70
|
};
|
|
59
71
|
var getAnnotationIndex = exports.getAnnotationIndex = function getAnnotationIndex(annotationPosition, fragmentCount) {
|
|
@@ -7,12 +7,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.MarkElement = void 0;
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _adfSchema = require("@atlaskit/adf-schema");
|
|
10
|
+
var _types = require("@atlaskit/editor-common/types");
|
|
11
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
10
12
|
var _mark = require("./mark");
|
|
11
13
|
var _useInlineCommentsFilter = require("../hooks/use-inline-comments-filter");
|
|
12
14
|
var _useInlineCommentSubscriber = require("../hooks/use-inline-comment-subscriber");
|
|
13
15
|
var _useEvents = require("../hooks/use-events");
|
|
14
16
|
var _context = require("../context");
|
|
15
|
-
var
|
|
17
|
+
var _AnnotationManagerContext = require("../contexts/AnnotationManagerContext");
|
|
16
18
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
17
19
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
20
|
var MarkElement = exports.MarkElement = function MarkElement(_ref) {
|
|
@@ -32,6 +34,9 @@ var MarkElement = exports.MarkElement = function MarkElement(_ref) {
|
|
|
32
34
|
var dataAttributesMemorized = (0, _react.useMemo)(function () {
|
|
33
35
|
return dataAttributes;
|
|
34
36
|
}, [dataAttributes]);
|
|
37
|
+
var _useAnnotationManager = (0, _AnnotationManagerContext.useAnnotationManagerDispatch)(),
|
|
38
|
+
dispatch = _useAnnotationManager.dispatch,
|
|
39
|
+
annotationManager = _useAnnotationManager.annotationManager;
|
|
35
40
|
var onClick = (0, _react.useCallback)(function (props) {
|
|
36
41
|
if (!updateSubscriber) {
|
|
37
42
|
return;
|
|
@@ -41,11 +46,38 @@ var MarkElement = exports.MarkElement = function MarkElement(_ref) {
|
|
|
41
46
|
}
|
|
42
47
|
var eventTarget = props.eventTarget,
|
|
43
48
|
annotationIds = props.annotationIds;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_comments_api_manager')) {
|
|
50
|
+
if (hasFocus) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
annotationManager === null || annotationManager === void 0 || annotationManager.checkPreemptiveGate().then(function (canSelect) {
|
|
54
|
+
if (canSelect) {
|
|
55
|
+
dispatch({
|
|
56
|
+
type: 'updateAnnotation',
|
|
57
|
+
data: {
|
|
58
|
+
id: annotationIds[0],
|
|
59
|
+
selected: true
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
dispatch({
|
|
63
|
+
type: 'setSelectedMarkRef',
|
|
64
|
+
data: {
|
|
65
|
+
markRef: eventTarget
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
} else {
|
|
69
|
+
// TODO: EDITOR-595 - If the preemptive gate returns false, should we track the analytics event?
|
|
70
|
+
}
|
|
71
|
+
}).catch(function (error) {
|
|
72
|
+
// TODO: EDITOR-595 - An error occurred while checking the preemptive gate. We should report this error.
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
updateSubscriber.emit(_types.AnnotationUpdateEvent.ON_ANNOTATION_CLICK, {
|
|
76
|
+
annotationIds: annotationIds,
|
|
77
|
+
eventTarget: eventTarget
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}, [updateSubscriber, useBlockLevel, dispatch, annotationManager, hasFocus]);
|
|
49
81
|
var activeParentIds = (0, _useInlineCommentsFilter.useInlineCommentsFilter)({
|
|
50
82
|
annotationIds: annotationParentIds,
|
|
51
83
|
filter: {
|
|
@@ -13,6 +13,7 @@ var _adfSchema = require("@atlaskit/adf-schema");
|
|
|
13
13
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
14
|
var _reactIntlNext = require("react-intl-next");
|
|
15
15
|
var _messages = require("../../../messages");
|
|
16
|
+
var _AnnotationManagerContext = require("../contexts/AnnotationManagerContext");
|
|
16
17
|
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; }
|
|
17
18
|
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; } /**
|
|
18
19
|
* @jsxRuntime classic
|
|
@@ -126,6 +127,20 @@ var MarkComponent = exports.MarkComponent = function MarkComponent(_ref) {
|
|
|
126
127
|
var annotationIds = (0, _react.useMemo)(function () {
|
|
127
128
|
return (0, _toConsumableArray2.default)(new Set([].concat((0, _toConsumableArray2.default)(annotationParentIds), [id])));
|
|
128
129
|
}, [id, annotationParentIds]);
|
|
130
|
+
var _useAnnotationManager = (0, _AnnotationManagerContext.useAnnotationManagerDispatch)(),
|
|
131
|
+
dispatch = _useAnnotationManager.dispatch;
|
|
132
|
+
var _useAnnotationManager2 = (0, _AnnotationManagerContext.useAnnotationManagerState)(),
|
|
133
|
+
currentSelectedAnnotationId = _useAnnotationManager2.currentSelectedAnnotationId;
|
|
134
|
+
var markRef = (0, _react.useCallback)(function (node) {
|
|
135
|
+
if (id === currentSelectedAnnotationId && node) {
|
|
136
|
+
dispatch({
|
|
137
|
+
type: 'setSelectedMarkRef',
|
|
138
|
+
data: {
|
|
139
|
+
markRef: node
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}, [dispatch, id, currentSelectedAnnotationId]);
|
|
129
144
|
var onMarkClick = (0, _react.useCallback)(function (event) {
|
|
130
145
|
// prevent inline mark logic for media block marks
|
|
131
146
|
if (event.currentTarget instanceof HTMLElement && event.currentTarget.getAttribute('data-block-mark')) {
|
|
@@ -184,6 +199,7 @@ var MarkComponent = exports.MarkComponent = function MarkComponent(_ref) {
|
|
|
184
199
|
'aria-details': annotationIds.join(', ')
|
|
185
200
|
}, desktopAccessibilityAttributes);
|
|
186
201
|
return (0, _react2.jsx)(useBlockLevel ? 'div' : 'mark', _objectSpread(_objectSpread(_objectSpread((0, _defineProperty2.default)({
|
|
202
|
+
ref: id === currentSelectedAnnotationId ? markRef : undefined,
|
|
187
203
|
id: id
|
|
188
204
|
}, (0, _platformFeatureFlags.fg)('editor_inline_comments_on_inline_nodes') ? 'onClickCapture' : 'onClick', onMarkClick), accessibility), overriddenData), !useBlockLevel && {
|
|
189
205
|
css: [markStyles, (0, _platformFeatureFlags.fg)('platform_renderer_nested_annotation_styling') && markStylesLayeringFix, (0, _platformFeatureFlags.fg)('editor_inline_comments_on_inline_nodes') && markStylesWithInlineComments, (0, _platformFeatureFlags.fg)('confluence-frontend-comments-panel') && markStylesWithCommentsPanel, !isMobile() && accessibilityStyles, markStylesWithUpdatedShadow],
|