@atlaskit/renderer 109.10.7 → 109.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/actions/index.js +4 -1
- package/dist/cjs/ui/Renderer/index.js +1 -1
- package/dist/cjs/ui/annotations/context.js +16 -6
- package/dist/cjs/ui/annotations/contexts/AnnotationRangeContext.js +48 -8
- package/dist/cjs/ui/annotations/hooks/user-selection.js +18 -14
- package/dist/cjs/ui/annotations/selection/mounter.js +15 -4
- package/dist/cjs/ui/annotations/selection/range-validator.js +14 -5
- package/dist/cjs/ui/annotations/wrapper.js +15 -1
- package/dist/es2019/actions/index.js +4 -1
- package/dist/es2019/ui/Renderer/index.js +1 -1
- package/dist/es2019/ui/annotations/context.js +19 -7
- package/dist/es2019/ui/annotations/contexts/AnnotationRangeContext.js +42 -3
- package/dist/es2019/ui/annotations/hooks/user-selection.js +19 -15
- package/dist/es2019/ui/annotations/selection/mounter.js +15 -4
- package/dist/es2019/ui/annotations/selection/range-validator.js +12 -4
- package/dist/es2019/ui/annotations/wrapper.js +17 -1
- package/dist/esm/actions/index.js +4 -1
- package/dist/esm/ui/Renderer/index.js +1 -1
- package/dist/esm/ui/annotations/context.js +16 -6
- package/dist/esm/ui/annotations/contexts/AnnotationRangeContext.js +48 -8
- package/dist/esm/ui/annotations/hooks/user-selection.js +19 -15
- package/dist/esm/ui/annotations/selection/mounter.js +15 -4
- package/dist/esm/ui/annotations/selection/range-validator.js +14 -5
- package/dist/esm/ui/annotations/wrapper.js +15 -1
- package/dist/types/actions/index.d.ts +7 -6
- package/dist/types/ui/annotations/context.d.ts +2 -0
- package/dist/types/ui/annotations/contexts/AnnotationRangeContext.d.ts +3 -0
- package/dist/types/ui/annotations/hooks/user-selection.d.ts +1 -1
- package/dist/types/ui/annotations/hover/mounter.d.ts +2 -2
- package/dist/types/ui/annotations/selection/mounter.d.ts +5 -4
- package/dist/types/ui/annotations/selection/range-validator.d.ts +2 -2
- package/dist/types-ts4.5/actions/index.d.ts +7 -6
- package/dist/types-ts4.5/ui/annotations/context.d.ts +2 -0
- package/dist/types-ts4.5/ui/annotations/contexts/AnnotationRangeContext.d.ts +3 -0
- package/dist/types-ts4.5/ui/annotations/hooks/user-selection.d.ts +1 -0
- package/dist/types-ts4.5/ui/annotations/hover/mounter.d.ts +2 -2
- package/dist/types-ts4.5/ui/annotations/selection/mounter.d.ts +5 -4
- package/dist/types-ts4.5/ui/annotations/selection/range-validator.d.ts +2 -2
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/renderer
|
|
2
2
|
|
|
3
|
+
## 109.11.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#85141](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/85141) [`eb4d99e5be1e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/eb4d99e5be1e) - Adding a try-catch around selection validation to prevent errors being thrown by nested renderers
|
|
8
|
+
|
|
9
|
+
## 109.11.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#84616](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/84616) [`57b0c76cdce6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/57b0c76cdce6) - Adding support for draft ranges in selection component for renderer annotation provider
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 109.10.7
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -141,6 +141,9 @@ var RendererActions = exports.default = /*#__PURE__*/function () {
|
|
|
141
141
|
}, {
|
|
142
142
|
key: "isValidAnnotationRange",
|
|
143
143
|
value: function isValidAnnotationRange(range) {
|
|
144
|
+
if (!range) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
144
147
|
var pos = (0, _steps.getPosFromRange)(range);
|
|
145
148
|
if (!pos || !this.doc) {
|
|
146
149
|
return false;
|
|
@@ -158,7 +161,7 @@ var RendererActions = exports.default = /*#__PURE__*/function () {
|
|
|
158
161
|
}, {
|
|
159
162
|
key: "getPositionFromRange",
|
|
160
163
|
value: function getPositionFromRange(range) {
|
|
161
|
-
if (!this.doc || !this.schema) {
|
|
164
|
+
if (!this.doc || !this.schema || !range) {
|
|
162
165
|
return false;
|
|
163
166
|
}
|
|
164
167
|
return (0, _steps.getPosFromRange)(range);
|
|
@@ -55,7 +55,7 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
55
55
|
var NORMAL_SEVERITY_THRESHOLD = exports.NORMAL_SEVERITY_THRESHOLD = 2000;
|
|
56
56
|
var DEGRADED_SEVERITY_THRESHOLD = exports.DEGRADED_SEVERITY_THRESHOLD = 3000;
|
|
57
57
|
var packageName = "@atlaskit/renderer";
|
|
58
|
-
var packageVersion = "109.
|
|
58
|
+
var packageVersion = "109.11.1";
|
|
59
59
|
var Renderer = exports.Renderer = /*#__PURE__*/function (_PureComponent) {
|
|
60
60
|
(0, _inherits2.default)(Renderer, _PureComponent);
|
|
61
61
|
var _super = _createSuper(Renderer);
|
|
@@ -35,14 +35,24 @@ var AnnotationsDraftContextWrapper = exports.AnnotationsDraftContextWrapper = /*
|
|
|
35
35
|
position: null
|
|
36
36
|
});
|
|
37
37
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "applyAnnotationDraftAt", function (nextPosition) {
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
var setDraftRange = _this.props.setDraftRange;
|
|
39
|
+
|
|
40
|
+
// Set the draft range to preserve it downstream
|
|
41
|
+
setDraftRange();
|
|
42
|
+
|
|
43
|
+
// We need to support a new draft being made while one exists and overwrite it
|
|
44
|
+
// Set the document position for the newly created draft
|
|
45
|
+
_this.setState({
|
|
46
|
+
position: nextPosition
|
|
47
|
+
});
|
|
44
48
|
});
|
|
45
49
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "clearAnnotationDraft", function () {
|
|
50
|
+
var clearDraftRange = _this.props.clearDraftRange;
|
|
51
|
+
|
|
52
|
+
// Clear the draft range
|
|
53
|
+
clearDraftRange();
|
|
54
|
+
|
|
55
|
+
// Clear the draft position in the document
|
|
46
56
|
_this.setState({
|
|
47
57
|
position: null
|
|
48
58
|
});
|
|
@@ -7,49 +7,70 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.useAnnotationRangeState = exports.useAnnotationRangeDispatch = exports.AnnotationRangeStateContext = exports.AnnotationRangeProvider = exports.AnnotationRangeDispatchContext = void 0;
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
11
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
12
|
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); }
|
|
12
13
|
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 && Object.prototype.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; }
|
|
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; }
|
|
13
16
|
function reducer(state, action) {
|
|
14
17
|
switch (action.type) {
|
|
15
18
|
case 'clear':
|
|
16
19
|
if (!!state.range || !!state.type) {
|
|
17
20
|
return {
|
|
18
21
|
range: null,
|
|
22
|
+
draftRange: null,
|
|
19
23
|
type: null
|
|
20
24
|
};
|
|
21
25
|
}
|
|
22
26
|
return state;
|
|
23
27
|
case 'clearSelection':
|
|
24
28
|
if (state.type === 'selection') {
|
|
25
|
-
return {
|
|
29
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
26
30
|
range: null,
|
|
27
31
|
type: null
|
|
28
|
-
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return state;
|
|
35
|
+
case 'clearDraftSelection':
|
|
36
|
+
if (state.type === 'selection') {
|
|
37
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
38
|
+
draftRange: null
|
|
39
|
+
});
|
|
29
40
|
}
|
|
30
41
|
return state;
|
|
31
42
|
case 'clearHover':
|
|
32
43
|
if (state.type === 'hover') {
|
|
33
44
|
return {
|
|
34
45
|
range: null,
|
|
46
|
+
draftRange: null,
|
|
35
47
|
type: null
|
|
36
48
|
};
|
|
37
49
|
}
|
|
38
50
|
return state;
|
|
39
51
|
case 'setSelection':
|
|
40
52
|
if (state.range !== action.range || state.type !== 'selection') {
|
|
41
|
-
return {
|
|
53
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
42
54
|
range: action.range,
|
|
43
55
|
type: 'selection'
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return state;
|
|
59
|
+
case 'setDraftSelection':
|
|
60
|
+
if (state.draftRange !== action.draftRange || state.type !== 'selection') {
|
|
61
|
+
return {
|
|
62
|
+
range: null,
|
|
63
|
+
draftRange: action.draftRange,
|
|
64
|
+
type: null
|
|
44
65
|
};
|
|
45
66
|
}
|
|
46
67
|
return state;
|
|
47
68
|
case 'setHover':
|
|
48
69
|
if (state.range !== action.range || state.type !== 'hover') {
|
|
49
|
-
return {
|
|
70
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
50
71
|
range: action.range,
|
|
51
72
|
type: 'hover'
|
|
52
|
-
};
|
|
73
|
+
});
|
|
53
74
|
}
|
|
54
75
|
return state;
|
|
55
76
|
}
|
|
@@ -57,24 +78,29 @@ function reducer(state, action) {
|
|
|
57
78
|
}
|
|
58
79
|
var AnnotationRangeStateContext = exports.AnnotationRangeStateContext = /*#__PURE__*/(0, _react.createContext)({
|
|
59
80
|
range: null,
|
|
81
|
+
draftRange: null,
|
|
60
82
|
type: null
|
|
61
83
|
});
|
|
62
84
|
var AnnotationRangeDispatchContext = exports.AnnotationRangeDispatchContext = /*#__PURE__*/(0, _react.createContext)({
|
|
63
85
|
clearRange: function clearRange() {},
|
|
64
86
|
clearSelectionRange: function clearSelectionRange() {},
|
|
87
|
+
clearDraftRange: function clearDraftRange() {},
|
|
65
88
|
clearHoverRange: function clearHoverRange() {},
|
|
66
|
-
setRange: function setRange() {}
|
|
89
|
+
setRange: function setRange() {},
|
|
90
|
+
setDraftRange: function setDraftRange() {}
|
|
67
91
|
});
|
|
68
92
|
var AnnotationRangeProvider = exports.AnnotationRangeProvider = function AnnotationRangeProvider(_ref) {
|
|
69
93
|
var children = _ref.children,
|
|
70
94
|
allowCommentsOnMedia = _ref.allowCommentsOnMedia;
|
|
71
95
|
var _useReducer = (0, _react.useReducer)(reducer, {
|
|
72
96
|
range: null,
|
|
97
|
+
draftRange: null,
|
|
73
98
|
type: null
|
|
74
99
|
}),
|
|
75
100
|
_useReducer2 = (0, _slicedToArray2.default)(_useReducer, 2),
|
|
76
101
|
_useReducer2$ = _useReducer2[0],
|
|
77
102
|
range = _useReducer2$.range,
|
|
103
|
+
draftRange = _useReducer2$.draftRange,
|
|
78
104
|
type = _useReducer2$.type,
|
|
79
105
|
dispatch = _useReducer2[1];
|
|
80
106
|
var clearRange = (0, _react.useCallback)(function () {
|
|
@@ -87,6 +113,11 @@ var AnnotationRangeProvider = exports.AnnotationRangeProvider = function Annotat
|
|
|
87
113
|
type: 'clearSelection'
|
|
88
114
|
});
|
|
89
115
|
}, []);
|
|
116
|
+
var clearDraftRange = (0, _react.useCallback)(function () {
|
|
117
|
+
return dispatch({
|
|
118
|
+
type: 'clearDraftSelection'
|
|
119
|
+
});
|
|
120
|
+
}, []);
|
|
90
121
|
var clearHoverRange = (0, _react.useCallback)(function () {
|
|
91
122
|
return dispatch({
|
|
92
123
|
type: 'clearHover'
|
|
@@ -98,6 +129,12 @@ var AnnotationRangeProvider = exports.AnnotationRangeProvider = function Annotat
|
|
|
98
129
|
range: range
|
|
99
130
|
});
|
|
100
131
|
}, []);
|
|
132
|
+
var setDraftRange = (0, _react.useCallback)(function (range) {
|
|
133
|
+
dispatch({
|
|
134
|
+
type: 'setDraftSelection',
|
|
135
|
+
draftRange: range
|
|
136
|
+
});
|
|
137
|
+
}, []);
|
|
101
138
|
var setHoverTarget = (0, _react.useCallback)(function (target) {
|
|
102
139
|
var range = document.createRange();
|
|
103
140
|
range.setStartBefore(target);
|
|
@@ -110,18 +147,21 @@ var AnnotationRangeProvider = exports.AnnotationRangeProvider = function Annotat
|
|
|
110
147
|
var stateData = (0, _react.useMemo)(function () {
|
|
111
148
|
return {
|
|
112
149
|
range: range,
|
|
150
|
+
draftRange: draftRange,
|
|
113
151
|
type: type
|
|
114
152
|
};
|
|
115
|
-
}, [range, type]);
|
|
153
|
+
}, [range, draftRange, type]);
|
|
116
154
|
var dispatchData = (0, _react.useMemo)(function () {
|
|
117
155
|
return {
|
|
118
156
|
clearRange: clearRange,
|
|
119
157
|
clearSelectionRange: clearSelectionRange,
|
|
158
|
+
clearDraftRange: clearDraftRange,
|
|
120
159
|
clearHoverRange: clearHoverRange,
|
|
121
160
|
setRange: setRange,
|
|
161
|
+
setDraftRange: setDraftRange,
|
|
122
162
|
setHoverTarget: !!allowCommentsOnMedia ? setHoverTarget : undefined
|
|
123
163
|
};
|
|
124
|
-
}, [allowCommentsOnMedia, clearRange, clearSelectionRange, clearHoverRange, setRange, setHoverTarget]);
|
|
164
|
+
}, [allowCommentsOnMedia, clearRange, clearSelectionRange, clearDraftRange, clearHoverRange, setRange, setDraftRange, setHoverTarget]);
|
|
125
165
|
return /*#__PURE__*/_react.default.createElement(AnnotationRangeStateContext.Provider, {
|
|
126
166
|
value: stateData
|
|
127
167
|
}, /*#__PURE__*/_react.default.createElement(AnnotationRangeDispatchContext.Provider, {
|
|
@@ -6,37 +6,41 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useUserSelectionRange = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _AnnotationRangeContext = require("../contexts/AnnotationRangeContext");
|
|
9
|
-
var _context = require("../context");
|
|
10
9
|
var _utils = require("./utils");
|
|
11
10
|
var useUserSelectionRange = exports.useUserSelectionRange = function useUserSelectionRange(props) {
|
|
12
11
|
var rendererDOM = props.rendererRef.current;
|
|
12
|
+
var selectionTimeoutRef = (0, _react.useRef)();
|
|
13
13
|
var _useAnnotationRangeDi = (0, _AnnotationRangeContext.useAnnotationRangeDispatch)(),
|
|
14
|
-
|
|
14
|
+
clearRange = _useAnnotationRangeDi.clearRange,
|
|
15
15
|
setRange = _useAnnotationRangeDi.setRange;
|
|
16
16
|
var _useAnnotationRangeSt = (0, _AnnotationRangeContext.useAnnotationRangeState)(),
|
|
17
17
|
range = _useAnnotationRangeSt.range,
|
|
18
|
+
draftRange = _useAnnotationRangeSt.draftRange,
|
|
18
19
|
type = _useAnnotationRangeSt.type;
|
|
19
|
-
var annotationDraftPosition = (0, _react.useContext)(_context.AnnotationsDraftContext);
|
|
20
|
-
var hasAnnotationDraft = !!annotationDraftPosition;
|
|
21
20
|
(0, _react.useEffect)(function () {
|
|
22
21
|
if (!document || !rendererDOM) {
|
|
23
22
|
return;
|
|
24
23
|
}
|
|
25
24
|
var onSelectionChange = function onSelectionChange(event) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
var _range = sel.getRangeAt(0);
|
|
31
|
-
if (rendererDOM && (0, _utils.isRangeInsideOfRendererContainer)(rendererDOM, _range)) {
|
|
32
|
-
setRange(_range.cloneRange());
|
|
25
|
+
if (selectionTimeoutRef.current) {
|
|
26
|
+
clearTimeout(selectionTimeoutRef.current);
|
|
33
27
|
}
|
|
28
|
+
selectionTimeoutRef.current = setTimeout(function () {
|
|
29
|
+
var sel = document.getSelection();
|
|
30
|
+
if (!sel || sel.type !== 'Range' || sel.rangeCount !== 1) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
var _range = sel.getRangeAt(0);
|
|
34
|
+
if (rendererDOM && (0, _utils.isRangeInsideOfRendererContainer)(rendererDOM, _range)) {
|
|
35
|
+
setRange(_range.cloneRange());
|
|
36
|
+
}
|
|
37
|
+
}, 250);
|
|
34
38
|
};
|
|
35
39
|
document.addEventListener('selectionchange', onSelectionChange);
|
|
36
40
|
return function () {
|
|
37
41
|
document.removeEventListener('selectionchange', onSelectionChange);
|
|
38
|
-
|
|
42
|
+
clearRange();
|
|
39
43
|
};
|
|
40
|
-
}, [rendererDOM,
|
|
41
|
-
return [type === 'selection' ? range : null,
|
|
44
|
+
}, [rendererDOM, setRange, clearRange]);
|
|
45
|
+
return [type === 'selection' ? range : null, draftRange, clearRange];
|
|
42
46
|
};
|
|
@@ -18,6 +18,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
18
18
|
var SelectionInlineCommentMounter = exports.SelectionInlineCommentMounter = /*#__PURE__*/_react.default.memo(function (props) {
|
|
19
19
|
var Component = props.component,
|
|
20
20
|
range = props.range,
|
|
21
|
+
draftRange = props.draftRange,
|
|
21
22
|
isAnnotationAllowed = props.isAnnotationAllowed,
|
|
22
23
|
wrapperDOM = props.wrapperDOM,
|
|
23
24
|
onCloseProps = props.onClose,
|
|
@@ -33,7 +34,16 @@ var SelectionInlineCommentMounter = exports.SelectionInlineCommentMounter = /*#_
|
|
|
33
34
|
setDraftDocumentPosition = _useState2[1];
|
|
34
35
|
var actions = (0, _react.useContext)(_RendererActionsContext.RendererContext);
|
|
35
36
|
var onCreateCallback = (0, _react.useCallback)(function (annotationId) {
|
|
36
|
-
|
|
37
|
+
// We want to support creation on a documentPosition if the user is only using ranges
|
|
38
|
+
// but we want to prioritize draft positions if they are being used by consumers
|
|
39
|
+
var positionToAnnotate = draftDocumentPosition || documentPosition;
|
|
40
|
+
if (!positionToAnnotate || !applyAnnotation) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Evaluate position validity when the user commits the position to be annotated
|
|
45
|
+
var isCreateAllowedOnPosition = actions.isValidAnnotationPosition(positionToAnnotate);
|
|
46
|
+
if (!isCreateAllowedOnPosition) {
|
|
37
47
|
return false;
|
|
38
48
|
}
|
|
39
49
|
var annotation = {
|
|
@@ -49,8 +59,8 @@ var SelectionInlineCommentMounter = exports.SelectionInlineCommentMounter = /*#_
|
|
|
49
59
|
eventType: _analytics.EVENT_TYPE.TRACK
|
|
50
60
|
}).fire(_analyticsListeners.FabricChannel.editor);
|
|
51
61
|
}
|
|
52
|
-
return applyAnnotation(
|
|
53
|
-
}, [
|
|
62
|
+
return applyAnnotation(positionToAnnotate, annotation);
|
|
63
|
+
}, [actions, documentPosition, applyAnnotation, draftDocumentPosition, createAnalyticsEvent]);
|
|
54
64
|
var createIndexCallback = (0, _react.useCallback)(function () {
|
|
55
65
|
if (!documentPosition || !generateIndexMatch) {
|
|
56
66
|
return false;
|
|
@@ -78,7 +88,7 @@ var SelectionInlineCommentMounter = exports.SelectionInlineCommentMounter = /*#_
|
|
|
78
88
|
setDraftDocumentPosition(documentPosition);
|
|
79
89
|
applyAnnotationDraftAt(documentPosition);
|
|
80
90
|
if (createAnalyticsEvent) {
|
|
81
|
-
var uniqueAnnotationsInRange = actions.getAnnotationsByPosition(range);
|
|
91
|
+
var uniqueAnnotationsInRange = range ? actions.getAnnotationsByPosition(range) : [];
|
|
82
92
|
createAnalyticsEvent({
|
|
83
93
|
action: _analytics.ACTION.OPENED,
|
|
84
94
|
actionSubject: _analytics.ACTION_SUBJECT.ANNOTATION,
|
|
@@ -123,6 +133,7 @@ var SelectionInlineCommentMounter = exports.SelectionInlineCommentMounter = /*#_
|
|
|
123
133
|
}, [onCloseProps, removeDraftModeCallback, createAnalyticsEvent]);
|
|
124
134
|
return /*#__PURE__*/_react.default.createElement(Component, {
|
|
125
135
|
range: range,
|
|
136
|
+
draftRange: draftRange,
|
|
126
137
|
wrapperDOM: wrapperDOM.current,
|
|
127
138
|
isAnnotationAllowed: isAnnotationAllowed,
|
|
128
139
|
onClose: onCloseCallback,
|
|
@@ -23,21 +23,30 @@ var SelectionRangeValidator = exports.SelectionRangeValidator = function Selecti
|
|
|
23
23
|
var _useUserSelectionRang = (0, _userSelection.useUserSelectionRange)({
|
|
24
24
|
rendererRef: rendererRef
|
|
25
25
|
}),
|
|
26
|
-
_useUserSelectionRang2 = (0, _slicedToArray2.default)(_useUserSelectionRang,
|
|
26
|
+
_useUserSelectionRang2 = (0, _slicedToArray2.default)(_useUserSelectionRang, 3),
|
|
27
27
|
range = _useUserSelectionRang2[0],
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
draftRange = _useUserSelectionRang2[1],
|
|
29
|
+
clearRange = _useUserSelectionRang2[2];
|
|
30
|
+
if (!range && !draftRange) {
|
|
30
31
|
return null;
|
|
31
32
|
}
|
|
32
33
|
var documentPosition = actions.getPositionFromRange(range);
|
|
33
|
-
|
|
34
|
+
|
|
35
|
+
// This property is drilled down to consumers when a new range is selected to test it's validity
|
|
36
|
+
var isAnnotationAllowedOnRange = false;
|
|
37
|
+
try {
|
|
38
|
+
isAnnotationAllowedOnRange = documentPosition && actions.isValidAnnotationPosition(documentPosition);
|
|
39
|
+
} catch (_unused) {
|
|
40
|
+
isAnnotationAllowedOnRange = false;
|
|
41
|
+
}
|
|
34
42
|
return /*#__PURE__*/_react.default.createElement(_mounter.SelectionInlineCommentMounter, {
|
|
35
43
|
range: range,
|
|
44
|
+
draftRange: draftRange,
|
|
36
45
|
wrapperDOM: rendererRef,
|
|
37
46
|
component: selectionComponent,
|
|
38
47
|
onClose: clearRange,
|
|
39
48
|
documentPosition: documentPosition,
|
|
40
|
-
isAnnotationAllowed:
|
|
49
|
+
isAnnotationAllowed: isAnnotationAllowedOnRange,
|
|
41
50
|
applyAnnotation: actions.applyAnnotation.bind(actions),
|
|
42
51
|
applyAnnotationDraftAt: applyAnnotationDraftAt,
|
|
43
52
|
generateIndexMatch: actions.generateAnnotationIndexMatch.bind(actions),
|
|
@@ -9,16 +9,27 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
9
9
|
var _context = require("./context");
|
|
10
10
|
var _hover = require("./hover");
|
|
11
11
|
var _selection = require("./selection");
|
|
12
|
+
var _AnnotationRangeContext = require("./contexts/AnnotationRangeContext");
|
|
12
13
|
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); }
|
|
13
14
|
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 && Object.prototype.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; }
|
|
14
15
|
var AnnotationsContextWrapper = exports.AnnotationsContextWrapper = function AnnotationsContextWrapper(props) {
|
|
15
16
|
var providers = (0, _react.useContext)(_context.ProvidersContext);
|
|
17
|
+
var _useAnnotationRangeSt = (0, _AnnotationRangeContext.useAnnotationRangeState)(),
|
|
18
|
+
range = _useAnnotationRangeSt.range;
|
|
19
|
+
var _useAnnotationRangeDi = (0, _AnnotationRangeContext.useAnnotationRangeDispatch)(),
|
|
20
|
+
setDraftRange = _useAnnotationRangeDi.setDraftRange,
|
|
21
|
+
clearDraftRange = _useAnnotationRangeDi.clearDraftRange;
|
|
16
22
|
var rendererRef = props.rendererRef,
|
|
17
23
|
createAnalyticsEvent = props.createAnalyticsEvent,
|
|
18
24
|
children = props.children;
|
|
19
25
|
var inlineCommentProvider = providers && providers.inlineComment;
|
|
20
26
|
var selectionComponent = inlineCommentProvider && inlineCommentProvider.selectionComponent;
|
|
21
27
|
var hoverComponent = inlineCommentProvider && inlineCommentProvider.hoverComponent;
|
|
28
|
+
|
|
29
|
+
// We want to set the draft to the range the user highlighted
|
|
30
|
+
var setRangeForDraft = (0, _react.useCallback)(function () {
|
|
31
|
+
setDraftRange(range);
|
|
32
|
+
}, [range, setDraftRange]);
|
|
22
33
|
var render = (0, _react.useCallback)(function (_ref) {
|
|
23
34
|
var applyAnnotationDraftAt = _ref.applyAnnotationDraftAt,
|
|
24
35
|
clearAnnotationDraft = _ref.clearAnnotationDraft;
|
|
@@ -39,5 +50,8 @@ var AnnotationsContextWrapper = exports.AnnotationsContextWrapper = function Ann
|
|
|
39
50
|
if (!selectionComponent && !hoverComponent) {
|
|
40
51
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
|
|
41
52
|
}
|
|
42
|
-
return /*#__PURE__*/_react.default.createElement(_context.AnnotationsDraftContextWrapper,
|
|
53
|
+
return /*#__PURE__*/_react.default.createElement(_context.AnnotationsDraftContextWrapper, {
|
|
54
|
+
setDraftRange: setRangeForDraft,
|
|
55
|
+
clearDraftRange: clearDraftRange
|
|
56
|
+
}, render);
|
|
43
57
|
};
|
|
@@ -121,6 +121,9 @@ export default class RendererActions {
|
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
isValidAnnotationRange(range) {
|
|
124
|
+
if (!range) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
124
127
|
const pos = getPosFromRange(range);
|
|
125
128
|
if (!pos || !this.doc) {
|
|
126
129
|
return false;
|
|
@@ -134,7 +137,7 @@ export default class RendererActions {
|
|
|
134
137
|
return this._privateValidatePositionsForAnnotation(pos.from, pos.to);
|
|
135
138
|
}
|
|
136
139
|
getPositionFromRange(range) {
|
|
137
|
-
if (!this.doc || !this.schema) {
|
|
140
|
+
if (!this.doc || !this.schema || !range) {
|
|
138
141
|
return false;
|
|
139
142
|
}
|
|
140
143
|
return getPosFromRange(range);
|
|
@@ -36,7 +36,7 @@ import { EditorMediaClientProvider } from '../../react/utils/EditorMediaClientPr
|
|
|
36
36
|
export const NORMAL_SEVERITY_THRESHOLD = 2000;
|
|
37
37
|
export const DEGRADED_SEVERITY_THRESHOLD = 3000;
|
|
38
38
|
const packageName = "@atlaskit/renderer";
|
|
39
|
-
const packageVersion = "109.
|
|
39
|
+
const packageVersion = "109.11.1";
|
|
40
40
|
export class Renderer extends PureComponent {
|
|
41
41
|
constructor(props) {
|
|
42
42
|
super(props);
|
|
@@ -11,15 +11,27 @@ export class AnnotationsDraftContextWrapper extends React.Component {
|
|
|
11
11
|
});
|
|
12
12
|
_defineProperty(this, "applyAnnotationDraftAt", nextPosition => {
|
|
13
13
|
const {
|
|
14
|
-
|
|
15
|
-
} = this.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
setDraftRange
|
|
15
|
+
} = this.props;
|
|
16
|
+
|
|
17
|
+
// Set the draft range to preserve it downstream
|
|
18
|
+
setDraftRange();
|
|
19
|
+
|
|
20
|
+
// We need to support a new draft being made while one exists and overwrite it
|
|
21
|
+
// Set the document position for the newly created draft
|
|
22
|
+
this.setState({
|
|
23
|
+
position: nextPosition
|
|
24
|
+
});
|
|
21
25
|
});
|
|
22
26
|
_defineProperty(this, "clearAnnotationDraft", () => {
|
|
27
|
+
const {
|
|
28
|
+
clearDraftRange
|
|
29
|
+
} = this.props;
|
|
30
|
+
|
|
31
|
+
// Clear the draft range
|
|
32
|
+
clearDraftRange();
|
|
33
|
+
|
|
34
|
+
// Clear the draft position in the document
|
|
23
35
|
this.setState({
|
|
24
36
|
position: null
|
|
25
37
|
});
|
|
@@ -5,6 +5,7 @@ function reducer(state, action) {
|
|
|
5
5
|
if (!!state.range || !!state.type) {
|
|
6
6
|
return {
|
|
7
7
|
range: null,
|
|
8
|
+
draftRange: null,
|
|
8
9
|
type: null
|
|
9
10
|
};
|
|
10
11
|
}
|
|
@@ -12,15 +13,25 @@ function reducer(state, action) {
|
|
|
12
13
|
case 'clearSelection':
|
|
13
14
|
if (state.type === 'selection') {
|
|
14
15
|
return {
|
|
16
|
+
...state,
|
|
15
17
|
range: null,
|
|
16
18
|
type: null
|
|
17
19
|
};
|
|
18
20
|
}
|
|
19
21
|
return state;
|
|
22
|
+
case 'clearDraftSelection':
|
|
23
|
+
if (state.type === 'selection') {
|
|
24
|
+
return {
|
|
25
|
+
...state,
|
|
26
|
+
draftRange: null
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return state;
|
|
20
30
|
case 'clearHover':
|
|
21
31
|
if (state.type === 'hover') {
|
|
22
32
|
return {
|
|
23
33
|
range: null,
|
|
34
|
+
draftRange: null,
|
|
24
35
|
type: null
|
|
25
36
|
};
|
|
26
37
|
}
|
|
@@ -28,14 +39,25 @@ function reducer(state, action) {
|
|
|
28
39
|
case 'setSelection':
|
|
29
40
|
if (state.range !== action.range || state.type !== 'selection') {
|
|
30
41
|
return {
|
|
42
|
+
...state,
|
|
31
43
|
range: action.range,
|
|
32
44
|
type: 'selection'
|
|
33
45
|
};
|
|
34
46
|
}
|
|
35
47
|
return state;
|
|
48
|
+
case 'setDraftSelection':
|
|
49
|
+
if (state.draftRange !== action.draftRange || state.type !== 'selection') {
|
|
50
|
+
return {
|
|
51
|
+
range: null,
|
|
52
|
+
draftRange: action.draftRange,
|
|
53
|
+
type: null
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return state;
|
|
36
57
|
case 'setHover':
|
|
37
58
|
if (state.range !== action.range || state.type !== 'hover') {
|
|
38
59
|
return {
|
|
60
|
+
...state,
|
|
39
61
|
range: action.range,
|
|
40
62
|
type: 'hover'
|
|
41
63
|
};
|
|
@@ -46,13 +68,16 @@ function reducer(state, action) {
|
|
|
46
68
|
}
|
|
47
69
|
export const AnnotationRangeStateContext = /*#__PURE__*/createContext({
|
|
48
70
|
range: null,
|
|
71
|
+
draftRange: null,
|
|
49
72
|
type: null
|
|
50
73
|
});
|
|
51
74
|
export const AnnotationRangeDispatchContext = /*#__PURE__*/createContext({
|
|
52
75
|
clearRange: () => {},
|
|
53
76
|
clearSelectionRange: () => {},
|
|
77
|
+
clearDraftRange: () => {},
|
|
54
78
|
clearHoverRange: () => {},
|
|
55
|
-
setRange: () => {}
|
|
79
|
+
setRange: () => {},
|
|
80
|
+
setDraftRange: () => {}
|
|
56
81
|
});
|
|
57
82
|
export const AnnotationRangeProvider = ({
|
|
58
83
|
children,
|
|
@@ -60,9 +85,11 @@ export const AnnotationRangeProvider = ({
|
|
|
60
85
|
}) => {
|
|
61
86
|
const [{
|
|
62
87
|
range,
|
|
88
|
+
draftRange,
|
|
63
89
|
type
|
|
64
90
|
}, dispatch] = useReducer(reducer, {
|
|
65
91
|
range: null,
|
|
92
|
+
draftRange: null,
|
|
66
93
|
type: null
|
|
67
94
|
});
|
|
68
95
|
const clearRange = useCallback(() => dispatch({
|
|
@@ -71,6 +98,9 @@ export const AnnotationRangeProvider = ({
|
|
|
71
98
|
const clearSelectionRange = useCallback(() => dispatch({
|
|
72
99
|
type: 'clearSelection'
|
|
73
100
|
}), []);
|
|
101
|
+
const clearDraftRange = useCallback(() => dispatch({
|
|
102
|
+
type: 'clearDraftSelection'
|
|
103
|
+
}), []);
|
|
74
104
|
const clearHoverRange = useCallback(() => dispatch({
|
|
75
105
|
type: 'clearHover'
|
|
76
106
|
}), []);
|
|
@@ -78,6 +108,12 @@ export const AnnotationRangeProvider = ({
|
|
|
78
108
|
type: 'setSelection',
|
|
79
109
|
range
|
|
80
110
|
}), []);
|
|
111
|
+
const setDraftRange = useCallback(range => {
|
|
112
|
+
dispatch({
|
|
113
|
+
type: 'setDraftSelection',
|
|
114
|
+
draftRange: range
|
|
115
|
+
});
|
|
116
|
+
}, []);
|
|
81
117
|
const setHoverTarget = useCallback(target => {
|
|
82
118
|
const range = document.createRange();
|
|
83
119
|
range.setStartBefore(target);
|
|
@@ -89,15 +125,18 @@ export const AnnotationRangeProvider = ({
|
|
|
89
125
|
}, []);
|
|
90
126
|
const stateData = useMemo(() => ({
|
|
91
127
|
range,
|
|
128
|
+
draftRange,
|
|
92
129
|
type
|
|
93
|
-
}), [range, type]);
|
|
130
|
+
}), [range, draftRange, type]);
|
|
94
131
|
const dispatchData = useMemo(() => ({
|
|
95
132
|
clearRange,
|
|
96
133
|
clearSelectionRange,
|
|
134
|
+
clearDraftRange,
|
|
97
135
|
clearHoverRange,
|
|
98
136
|
setRange,
|
|
137
|
+
setDraftRange,
|
|
99
138
|
setHoverTarget: !!allowCommentsOnMedia ? setHoverTarget : undefined
|
|
100
|
-
}), [allowCommentsOnMedia, clearRange, clearSelectionRange, clearHoverRange, setRange, setHoverTarget]);
|
|
139
|
+
}), [allowCommentsOnMedia, clearRange, clearSelectionRange, clearDraftRange, clearHoverRange, setRange, setDraftRange, setHoverTarget]);
|
|
101
140
|
return /*#__PURE__*/React.createElement(AnnotationRangeStateContext.Provider, {
|
|
102
141
|
value: stateData
|
|
103
142
|
}, /*#__PURE__*/React.createElement(AnnotationRangeDispatchContext.Provider, {
|