@atlaskit/editor-core 190.1.20 → 190.1.23
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 +7 -0
- package/afm-cc/tsconfig.json +3 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/plugins/index.js +0 -7
- package/dist/cjs/plugins/paste/pm-plugins/main.js +14 -10
- package/dist/cjs/presets/default.js +2 -2
- package/dist/cjs/presets/universal.js +2 -1
- package/dist/cjs/utils/index.js +12 -18
- package/dist/cjs/utils/performance/measure-enum.js +1 -2
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/index.js +14 -1
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/plugins/paste/pm-plugins/main.js +11 -5
- package/dist/es2019/presets/default.js +1 -1
- package/dist/es2019/presets/universal.js +2 -1
- package/dist/es2019/utils/index.js +0 -7
- package/dist/es2019/utils/performance/measure-enum.js +1 -2
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/index.js +14 -1
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/plugins/paste/pm-plugins/main.js +9 -5
- package/dist/esm/presets/default.js +1 -1
- package/dist/esm/presets/universal.js +2 -1
- package/dist/esm/utils/index.js +0 -5
- package/dist/esm/utils/performance/measure-enum.js +1 -2
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/index.d.ts +15 -2
- package/dist/types/plugins/index.d.ts +0 -1
- package/dist/types/plugins/paste/pm-plugins/main.d.ts +2 -0
- package/dist/types/presets/default.d.ts +1 -1
- package/dist/types/types/editor-props.d.ts +1 -1
- package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +2 -2
- package/dist/types/ui/ContentStyles/index.d.ts +2 -2
- package/dist/types/utils/index.d.ts +0 -1
- package/dist/types/utils/performance/measure-enum.d.ts +0 -1
- package/dist/types-ts4.5/index.d.ts +15 -2
- package/dist/types-ts4.5/plugins/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/paste/pm-plugins/main.d.ts +2 -0
- package/dist/types-ts4.5/presets/default.d.ts +1 -1
- package/dist/types-ts4.5/types/editor-props.d.ts +1 -1
- package/dist/types-ts4.5/ui/Appearance/FullPage/StyledComponents.d.ts +2 -2
- package/dist/types-ts4.5/ui/ContentStyles/index.d.ts +2 -2
- package/dist/types-ts4.5/utils/index.d.ts +0 -1
- package/dist/types-ts4.5/utils/performance/measure-enum.d.ts +0 -1
- package/package.json +5 -3
- package/dist/cjs/plugins/annotation/commands/index.js +0 -150
- package/dist/cjs/plugins/annotation/commands/transform.js +0 -86
- package/dist/cjs/plugins/annotation/index.js +0 -130
- package/dist/cjs/plugins/annotation/nodeviews/index.js +0 -59
- package/dist/cjs/plugins/annotation/pm-plugins/inline-comment.js +0 -243
- package/dist/cjs/plugins/annotation/pm-plugins/keymap.js +0 -15
- package/dist/cjs/plugins/annotation/pm-plugins/plugin-factory.js +0 -107
- package/dist/cjs/plugins/annotation/pm-plugins/reducer.js +0 -84
- package/dist/cjs/plugins/annotation/pm-plugins/types.js +0 -17
- package/dist/cjs/plugins/annotation/toolbar.js +0 -59
- package/dist/cjs/plugins/annotation/types.js +0 -20
- package/dist/cjs/plugins/annotation/ui/AnnotationViewWrapper.js +0 -38
- package/dist/cjs/plugins/annotation/ui/InlineCommentView.js +0 -149
- package/dist/cjs/plugins/annotation/update-provider.js +0 -36
- package/dist/cjs/plugins/annotation/utils.js +0 -372
- package/dist/es2019/plugins/annotation/commands/index.js +0 -123
- package/dist/es2019/plugins/annotation/commands/transform.js +0 -64
- package/dist/es2019/plugins/annotation/index.js +0 -125
- package/dist/es2019/plugins/annotation/nodeviews/index.js +0 -31
- package/dist/es2019/plugins/annotation/pm-plugins/inline-comment.js +0 -178
- package/dist/es2019/plugins/annotation/pm-plugins/keymap.js +0 -9
- package/dist/es2019/plugins/annotation/pm-plugins/plugin-factory.js +0 -108
- package/dist/es2019/plugins/annotation/pm-plugins/reducer.js +0 -94
- package/dist/es2019/plugins/annotation/pm-plugins/types.js +0 -11
- package/dist/es2019/plugins/annotation/toolbar.js +0 -53
- package/dist/es2019/plugins/annotation/types.js +0 -14
- package/dist/es2019/plugins/annotation/ui/AnnotationViewWrapper.js +0 -14
- package/dist/es2019/plugins/annotation/ui/InlineCommentView.js +0 -147
- package/dist/es2019/plugins/annotation/update-provider.js +0 -9
- package/dist/es2019/plugins/annotation/utils.js +0 -334
- package/dist/esm/plugins/annotation/commands/index.js +0 -143
- package/dist/esm/plugins/annotation/commands/transform.js +0 -80
- package/dist/esm/plugins/annotation/index.js +0 -118
- package/dist/esm/plugins/annotation/nodeviews/index.js +0 -52
- package/dist/esm/plugins/annotation/pm-plugins/inline-comment.js +0 -236
- package/dist/esm/plugins/annotation/pm-plugins/keymap.js +0 -9
- package/dist/esm/plugins/annotation/pm-plugins/plugin-factory.js +0 -101
- package/dist/esm/plugins/annotation/pm-plugins/reducer.js +0 -77
- package/dist/esm/plugins/annotation/pm-plugins/types.js +0 -11
- package/dist/esm/plugins/annotation/toolbar.js +0 -52
- package/dist/esm/plugins/annotation/types.js +0 -14
- package/dist/esm/plugins/annotation/ui/AnnotationViewWrapper.js +0 -31
- package/dist/esm/plugins/annotation/ui/InlineCommentView.js +0 -144
- package/dist/esm/plugins/annotation/update-provider.js +0 -29
- package/dist/esm/plugins/annotation/utils.js +0 -345
- package/dist/types/plugins/annotation/commands/index.d.ts +0 -15
- package/dist/types/plugins/annotation/commands/transform.d.ts +0 -11
- package/dist/types/plugins/annotation/index.d.ts +0 -15
- package/dist/types/plugins/annotation/nodeviews/index.d.ts +0 -11
- package/dist/types/plugins/annotation/pm-plugins/inline-comment.d.ts +0 -3
- package/dist/types/plugins/annotation/pm-plugins/keymap.d.ts +0 -3
- package/dist/types/plugins/annotation/pm-plugins/plugin-factory.d.ts +0 -2
- package/dist/types/plugins/annotation/pm-plugins/reducer.d.ts +0 -3
- package/dist/types/plugins/annotation/pm-plugins/types.d.ts +0 -78
- package/dist/types/plugins/annotation/toolbar.d.ts +0 -5
- package/dist/types/plugins/annotation/types.d.ts +0 -86
- package/dist/types/plugins/annotation/ui/AnnotationViewWrapper.d.ts +0 -10
- package/dist/types/plugins/annotation/ui/InlineCommentView.d.ts +0 -13
- package/dist/types/plugins/annotation/update-provider.d.ts +0 -12
- package/dist/types/plugins/annotation/utils.d.ts +0 -45
- package/dist/types-ts4.5/plugins/annotation/commands/index.d.ts +0 -15
- package/dist/types-ts4.5/plugins/annotation/commands/transform.d.ts +0 -11
- package/dist/types-ts4.5/plugins/annotation/index.d.ts +0 -17
- package/dist/types-ts4.5/plugins/annotation/nodeviews/index.d.ts +0 -11
- package/dist/types-ts4.5/plugins/annotation/pm-plugins/inline-comment.d.ts +0 -3
- package/dist/types-ts4.5/plugins/annotation/pm-plugins/keymap.d.ts +0 -3
- package/dist/types-ts4.5/plugins/annotation/pm-plugins/plugin-factory.d.ts +0 -2
- package/dist/types-ts4.5/plugins/annotation/pm-plugins/reducer.d.ts +0 -3
- package/dist/types-ts4.5/plugins/annotation/pm-plugins/types.d.ts +0 -78
- package/dist/types-ts4.5/plugins/annotation/toolbar.d.ts +0 -5
- package/dist/types-ts4.5/plugins/annotation/types.d.ts +0 -86
- package/dist/types-ts4.5/plugins/annotation/ui/AnnotationViewWrapper.d.ts +0 -10
- package/dist/types-ts4.5/plugins/annotation/ui/InlineCommentView.d.ts +0 -13
- package/dist/types-ts4.5/plugins/annotation/update-provider.d.ts +0 -12
- package/dist/types-ts4.5/plugins/annotation/utils.d.ts +0 -45
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
import { PluginKey, TextSelection, AllSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
-
import { AnnotationSharedClassNames } from '@atlaskit/editor-common/styles';
|
|
4
|
-
import { canApplyAnnotationOnRange, getAnnotationIdsFromRange, isText, isParagraph, hasAnnotationMark, containsAnyAnnotations } from '@atlaskit/editor-common/utils';
|
|
5
|
-
import { AnnotationTypes } from '@atlaskit/adf-schema';
|
|
6
|
-
import { AnnotationSelectionType } from './types';
|
|
7
|
-
import { ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, ACTION } from '@atlaskit/editor-common/analytics';
|
|
8
|
-
export { hasAnnotationMark, containsAnyAnnotations };
|
|
9
|
-
function sum(arr, f) {
|
|
10
|
-
return arr.reduce((val, x) => val + f(x), 0);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Finds the marks in the nodes to the left and right.
|
|
14
|
-
* @param $pos Position to center search around
|
|
15
|
-
*/
|
|
16
|
-
export const surroundingMarks = $pos => {
|
|
17
|
-
const {
|
|
18
|
-
nodeBefore,
|
|
19
|
-
nodeAfter
|
|
20
|
-
} = $pos;
|
|
21
|
-
const markNodeBefore = nodeBefore && $pos.doc.nodeAt(Math.max(0, $pos.pos - nodeBefore.nodeSize - 1));
|
|
22
|
-
const markNodeAfter = nodeAfter && $pos.doc.nodeAt($pos.pos + nodeAfter.nodeSize);
|
|
23
|
-
return [markNodeBefore && markNodeBefore.marks || [], markNodeAfter && markNodeAfter.marks || []];
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Finds annotation marks, and returns their IDs.
|
|
28
|
-
* @param marks Array of marks to search in
|
|
29
|
-
*/
|
|
30
|
-
const filterAnnotationIds = marks => {
|
|
31
|
-
if (!marks.length) {
|
|
32
|
-
return [];
|
|
33
|
-
}
|
|
34
|
-
const {
|
|
35
|
-
annotation
|
|
36
|
-
} = marks[0].type.schema.marks;
|
|
37
|
-
return marks.filter(mark => mark.type === annotation).map(mark => mark.attrs.id);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Re-orders the annotation array based on the order in the document.
|
|
42
|
-
*
|
|
43
|
-
* This places the marks that do not appear in the surrounding nodes
|
|
44
|
-
* higher in the list. That is, the inner-most one appears first.
|
|
45
|
-
*
|
|
46
|
-
* Undo, for example, can re-order annotation marks in the document.
|
|
47
|
-
* @param annotations annotation metadata
|
|
48
|
-
* @param $from location to look around (usually the selection)
|
|
49
|
-
*/
|
|
50
|
-
const reorderAnnotations = (annotations, $from) => {
|
|
51
|
-
const idSet = surroundingMarks($from).map(filterAnnotationIds);
|
|
52
|
-
annotations.sort((a, b) => sum(idSet, ids => ids.indexOf(a.id)) - sum(idSet, ids => ids.indexOf(b.id)));
|
|
53
|
-
};
|
|
54
|
-
export const getAllAnnotations = doc => {
|
|
55
|
-
const allAnnotationIds = new Set();
|
|
56
|
-
doc.descendants(node => {
|
|
57
|
-
node.marks.filter(mark => mark.type.name === 'annotation')
|
|
58
|
-
// filter out annotations with invalid attributes as they cause errors when interacting with them
|
|
59
|
-
.filter(validateAnnotationMark).forEach(m => allAnnotationIds.add(m.attrs.id));
|
|
60
|
-
return true;
|
|
61
|
-
});
|
|
62
|
-
return Array.from(allAnnotationIds);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/*
|
|
66
|
-
* verifies if annotation mark contains valid attributes
|
|
67
|
-
*/
|
|
68
|
-
const validateAnnotationMark = annotationMark => {
|
|
69
|
-
const {
|
|
70
|
-
id,
|
|
71
|
-
annotationType
|
|
72
|
-
} = annotationMark.attrs;
|
|
73
|
-
return validateAnnotationId(id) && validateAnnotationType(annotationType);
|
|
74
|
-
function validateAnnotationId(id) {
|
|
75
|
-
if (!id || typeof id !== 'string') {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
const invalidIds = ['null', 'undefined'];
|
|
79
|
-
return !invalidIds.includes(id.toLowerCase());
|
|
80
|
-
}
|
|
81
|
-
function validateAnnotationType(type) {
|
|
82
|
-
if (!type || typeof type !== 'string') {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
const allowedTypes = Object.values(AnnotationTypes);
|
|
86
|
-
return allowedTypes.includes(type);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
/*
|
|
91
|
-
* add decoration for the comment selection in draft state
|
|
92
|
-
* (when creating new comment)
|
|
93
|
-
*/
|
|
94
|
-
export const addDraftDecoration = (start, end) => {
|
|
95
|
-
return Decoration.inline(start, end, {
|
|
96
|
-
class: `${AnnotationSharedClassNames.draft}`
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
export const getAnnotationViewKey = annotations => {
|
|
100
|
-
const keys = annotations.map(mark => mark.id).join('_');
|
|
101
|
-
return `view-annotation-wrapper_${keys}`;
|
|
102
|
-
};
|
|
103
|
-
export const findAnnotationsInSelection = (selection, doc) => {
|
|
104
|
-
const {
|
|
105
|
-
empty,
|
|
106
|
-
$anchor,
|
|
107
|
-
anchor
|
|
108
|
-
} = selection;
|
|
109
|
-
// Only detect annotations on caret selection
|
|
110
|
-
if (!empty || !doc) {
|
|
111
|
-
return [];
|
|
112
|
-
}
|
|
113
|
-
const node = doc.nodeAt(anchor);
|
|
114
|
-
if (!node && !$anchor.nodeBefore) {
|
|
115
|
-
return [];
|
|
116
|
-
}
|
|
117
|
-
const annotationMark = doc.type.schema.marks.annotation;
|
|
118
|
-
const nodeBefore = $anchor.nodeBefore;
|
|
119
|
-
const anchorAnnotationMarks = node && node.marks || [];
|
|
120
|
-
let marks = [];
|
|
121
|
-
if (annotationMark.isInSet(anchorAnnotationMarks)) {
|
|
122
|
-
marks = anchorAnnotationMarks;
|
|
123
|
-
} else if (nodeBefore && annotationMark.isInSet(nodeBefore.marks)) {
|
|
124
|
-
marks = nodeBefore.marks;
|
|
125
|
-
}
|
|
126
|
-
const annotations = marks.filter(mark => mark.type.name === 'annotation').map(mark => ({
|
|
127
|
-
id: mark.attrs.id,
|
|
128
|
-
type: mark.attrs.annotationType
|
|
129
|
-
}));
|
|
130
|
-
reorderAnnotations(annotations, $anchor);
|
|
131
|
-
return annotations;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* get selection from position to apply new comment for
|
|
136
|
-
* @return bookmarked positions if they exists, otherwise current selection positions
|
|
137
|
-
*/
|
|
138
|
-
export function getSelectionPositions(editorState, inlineCommentState) {
|
|
139
|
-
const {
|
|
140
|
-
bookmark
|
|
141
|
-
} = inlineCommentState || {};
|
|
142
|
-
// get positions via saved bookmark if it is available
|
|
143
|
-
// this is to make comments box positioned relative to temporary highlight rather then current selection
|
|
144
|
-
if (bookmark) {
|
|
145
|
-
return bookmark.resolve(editorState.doc);
|
|
146
|
-
}
|
|
147
|
-
return editorState.selection;
|
|
148
|
-
}
|
|
149
|
-
export const inlineCommentPluginKey = new PluginKey('inlineCommentPluginKey');
|
|
150
|
-
export const getPluginState = state => {
|
|
151
|
-
return inlineCommentPluginKey.getState(state);
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* get number of unique annotations within current selection
|
|
156
|
-
*/
|
|
157
|
-
const getAnnotationsInSelectionCount = state => {
|
|
158
|
-
const {
|
|
159
|
-
from,
|
|
160
|
-
to
|
|
161
|
-
} = state.selection;
|
|
162
|
-
const annotations = getAnnotationIdsFromRange({
|
|
163
|
-
from,
|
|
164
|
-
to
|
|
165
|
-
}, state.doc, state.schema);
|
|
166
|
-
return annotations.length;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* get payload for the open/close analytics event
|
|
171
|
-
*/
|
|
172
|
-
export const getDraftCommandAnalyticsPayload = (drafting, inputMethod) => {
|
|
173
|
-
const payload = state => {
|
|
174
|
-
let attributes = {};
|
|
175
|
-
if (drafting) {
|
|
176
|
-
attributes = {
|
|
177
|
-
inputMethod,
|
|
178
|
-
overlap: getAnnotationsInSelectionCount(state)
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
return {
|
|
182
|
-
action: drafting ? ACTION.OPENED : ACTION.CLOSED,
|
|
183
|
-
actionSubject: ACTION_SUBJECT.ANNOTATION,
|
|
184
|
-
actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
|
|
185
|
-
eventType: EVENT_TYPE.TRACK,
|
|
186
|
-
attributes
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
return payload;
|
|
190
|
-
};
|
|
191
|
-
export const isSelectionValid = state => {
|
|
192
|
-
const {
|
|
193
|
-
selection
|
|
194
|
-
} = state;
|
|
195
|
-
const {
|
|
196
|
-
disallowOnWhitespace
|
|
197
|
-
} = getPluginState(state) || {};
|
|
198
|
-
if (selection.empty || !(selection instanceof TextSelection || selection instanceof AllSelection)) {
|
|
199
|
-
return AnnotationSelectionType.INVALID;
|
|
200
|
-
}
|
|
201
|
-
const containsInvalidNodes = hasInvalidNodes(state);
|
|
202
|
-
|
|
203
|
-
// A selection that only covers 1 pos, and is an invalid node
|
|
204
|
-
// e.g. a text selection over a mention
|
|
205
|
-
if (containsInvalidNodes && selection.to - selection.from === 1) {
|
|
206
|
-
return AnnotationSelectionType.INVALID;
|
|
207
|
-
}
|
|
208
|
-
if (containsInvalidNodes) {
|
|
209
|
-
return AnnotationSelectionType.DISABLED;
|
|
210
|
-
}
|
|
211
|
-
if (disallowOnWhitespace && hasInvalidWhitespaceNode(selection, state.schema)) {
|
|
212
|
-
return AnnotationSelectionType.INVALID;
|
|
213
|
-
}
|
|
214
|
-
if (isEmptyTextSelection(selection, state.schema)) {
|
|
215
|
-
return AnnotationSelectionType.INVALID;
|
|
216
|
-
}
|
|
217
|
-
return AnnotationSelectionType.VALID;
|
|
218
|
-
};
|
|
219
|
-
export const hasInvalidNodes = state => {
|
|
220
|
-
const {
|
|
221
|
-
selection,
|
|
222
|
-
doc,
|
|
223
|
-
schema
|
|
224
|
-
} = state;
|
|
225
|
-
return !canApplyAnnotationOnRange({
|
|
226
|
-
from: selection.from,
|
|
227
|
-
to: selection.to
|
|
228
|
-
}, doc, schema);
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Checks if selection contains only empty text
|
|
233
|
-
* e.g. when you select across multiple empty paragraphs
|
|
234
|
-
*/
|
|
235
|
-
function isEmptyTextSelection(selection, schema) {
|
|
236
|
-
const {
|
|
237
|
-
text,
|
|
238
|
-
paragraph
|
|
239
|
-
} = schema.nodes;
|
|
240
|
-
let hasContent = false;
|
|
241
|
-
selection.content().content.descendants(node => {
|
|
242
|
-
// for empty paragraph - consider empty (nothing to comment on)
|
|
243
|
-
if (node.type === paragraph && !node.content.size) {
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
// for not a text or nonempty text - consider nonempty (can comment if the node is supported for annotations)
|
|
247
|
-
if (node.type !== text || !node.textContent) {
|
|
248
|
-
hasContent = true;
|
|
249
|
-
}
|
|
250
|
-
return !hasContent;
|
|
251
|
-
});
|
|
252
|
-
return !hasContent;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Checks if any of the nodes in a given selection are completely whitespace
|
|
257
|
-
* This is to conform to Confluence annotation specifications
|
|
258
|
-
*/
|
|
259
|
-
export function hasInvalidWhitespaceNode(selection, schema) {
|
|
260
|
-
let foundInvalidWhitespace = false;
|
|
261
|
-
const content = selection.content().content;
|
|
262
|
-
content.descendants(node => {
|
|
263
|
-
if (isText(node, schema)) {
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
266
|
-
if (node.textContent.trim() === '') {
|
|
267
|
-
// Trailing new lines do not result in the annotation spanning into
|
|
268
|
-
// the trailing new line so can be ignored when looking for invalid
|
|
269
|
-
// whitespace nodes.
|
|
270
|
-
const nodeIsTrailingNewLine =
|
|
271
|
-
// it is the final node
|
|
272
|
-
node.eq(content.lastChild) &&
|
|
273
|
-
// and there are multiple nodes
|
|
274
|
-
!node.eq(content.firstChild) &&
|
|
275
|
-
// and it is a paragraph node
|
|
276
|
-
isParagraph(node, schema);
|
|
277
|
-
if (!nodeIsTrailingNewLine) {
|
|
278
|
-
foundInvalidWhitespace = true;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
return !foundInvalidWhitespace;
|
|
282
|
-
});
|
|
283
|
-
return foundInvalidWhitespace;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/*
|
|
287
|
-
* verifies that the annotation exists by the given id
|
|
288
|
-
*/
|
|
289
|
-
export function annotationExists(annotationId, state) {
|
|
290
|
-
const commentsPluginState = getPluginState(state);
|
|
291
|
-
return !!(commentsPluginState !== null && commentsPluginState !== void 0 && commentsPluginState.annotations) && Object.keys(commentsPluginState.annotations).includes(annotationId);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/*
|
|
295
|
-
* remove annotations that dont exsist in plugin state from slice
|
|
296
|
-
*/
|
|
297
|
-
export function stripNonExistingAnnotations(slice, state) {
|
|
298
|
-
if (!slice.content.size) {
|
|
299
|
-
return false;
|
|
300
|
-
}
|
|
301
|
-
slice.content.forEach(node => {
|
|
302
|
-
stripNonExistingAnnotationsFromNode(node, state);
|
|
303
|
-
node.content.descendants(node => {
|
|
304
|
-
stripNonExistingAnnotationsFromNode(node, state);
|
|
305
|
-
return true;
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/*
|
|
311
|
-
* remove annotations that dont exsist in plugin state
|
|
312
|
-
* from node
|
|
313
|
-
*/
|
|
314
|
-
function stripNonExistingAnnotationsFromNode(node, state) {
|
|
315
|
-
if (hasAnnotationMark(node, state)) {
|
|
316
|
-
node.marks = node.marks.filter(mark => {
|
|
317
|
-
if (mark.type.name === 'annotation') {
|
|
318
|
-
return annotationExists(mark.attrs.id, state);
|
|
319
|
-
}
|
|
320
|
-
return true;
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
return node;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Compares two sets of annotationInfos to see if the annotations have changed
|
|
328
|
-
* This function assumes annotations will have unique id's for simplicity
|
|
329
|
-
*/
|
|
330
|
-
export function isSelectedAnnotationsChanged(oldSelectedAnnotations, newSelectedAnnotations) {
|
|
331
|
-
return newSelectedAnnotations.length !== oldSelectedAnnotations.length ||
|
|
332
|
-
// assuming annotations have unique id's for simplicity
|
|
333
|
-
newSelectedAnnotations.some(annotation => !oldSelectedAnnotations.find(pluginStateAnnotation => annotation.id === pluginStateAnnotation.id && annotation.type === pluginStateAnnotation.type));
|
|
334
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import { AnnotationTypes } from '@atlaskit/adf-schema';
|
|
3
|
-
import { createCommand } from '../pm-plugins/plugin-factory';
|
|
4
|
-
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
5
|
-
import { isSelectionValid, getPluginState } from '../utils';
|
|
6
|
-
import { ACTIONS } from '../pm-plugins/types';
|
|
7
|
-
import transform from './transform';
|
|
8
|
-
import { AnnotationSelectionType } from '../types';
|
|
9
|
-
export var updateInlineCommentResolvedState = function updateInlineCommentResolvedState(editorAnalyticsAPI) {
|
|
10
|
-
return function (partialNewState, resolveMethod) {
|
|
11
|
-
var command = {
|
|
12
|
-
type: ACTIONS.UPDATE_INLINE_COMMENT_STATE,
|
|
13
|
-
data: partialNewState
|
|
14
|
-
};
|
|
15
|
-
var allResolved = Object.values(partialNewState).every(function (state) {
|
|
16
|
-
return state;
|
|
17
|
-
});
|
|
18
|
-
if (resolveMethod && allResolved) {
|
|
19
|
-
return createCommand(command, transform.addResolveAnalytics(editorAnalyticsAPI)(resolveMethod));
|
|
20
|
-
}
|
|
21
|
-
return createCommand(command);
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export var closeComponent = function closeComponent() {
|
|
25
|
-
return createCommand({
|
|
26
|
-
type: ACTIONS.CLOSE_COMPONENT
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
export var clearDirtyMark = function clearDirtyMark() {
|
|
30
|
-
return createCommand({
|
|
31
|
-
type: ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
export var removeInlineCommentNearSelection = function removeInlineCommentNearSelection(id) {
|
|
35
|
-
return function (state, dispatch) {
|
|
36
|
-
var tr = state.tr,
|
|
37
|
-
$from = state.selection.$from;
|
|
38
|
-
var annotationMarkType = state.schema.marks.annotation;
|
|
39
|
-
var hasAnnotation = $from.marks().some(function (mark) {
|
|
40
|
-
return mark.type === annotationMarkType;
|
|
41
|
-
});
|
|
42
|
-
if (!hasAnnotation) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// just remove entire mark from around the node
|
|
47
|
-
tr.removeMark($from.start(), $from.end(), annotationMarkType.create({
|
|
48
|
-
id: id,
|
|
49
|
-
type: AnnotationTypes.INLINE_COMMENT
|
|
50
|
-
}));
|
|
51
|
-
if (dispatch) {
|
|
52
|
-
dispatch(tr);
|
|
53
|
-
}
|
|
54
|
-
return true;
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
var getDraftCommandAction = function getDraftCommandAction(drafting) {
|
|
58
|
-
return function (editorState) {
|
|
59
|
-
// validate selection only when entering draft mode
|
|
60
|
-
if (drafting && isSelectionValid(editorState) !== AnnotationSelectionType.VALID) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
type: ACTIONS.SET_INLINE_COMMENT_DRAFT_STATE,
|
|
65
|
-
data: {
|
|
66
|
-
drafting: drafting,
|
|
67
|
-
editorState: editorState
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
export var setInlineCommentDraftState = function setInlineCommentDraftState(editorAnalyticsAPI) {
|
|
73
|
-
return function (drafting) {
|
|
74
|
-
var inputMethod = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : INPUT_METHOD.TOOLBAR;
|
|
75
|
-
var commandAction = getDraftCommandAction(drafting);
|
|
76
|
-
return createCommand(commandAction, transform.addOpenCloseAnalytics(editorAnalyticsAPI)(drafting, inputMethod));
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
export var addInlineComment = function addInlineComment(editorAnalyticsAPI) {
|
|
80
|
-
return function (id) {
|
|
81
|
-
var commandAction = function commandAction(editorState) {
|
|
82
|
-
return {
|
|
83
|
-
type: ACTIONS.ADD_INLINE_COMMENT,
|
|
84
|
-
data: {
|
|
85
|
-
drafting: false,
|
|
86
|
-
inlineComments: _defineProperty({}, id, false),
|
|
87
|
-
// Auto make the newly inserted comment selected.
|
|
88
|
-
// We move the selection to the head of the comment selection.
|
|
89
|
-
selectedAnnotations: [{
|
|
90
|
-
id: id,
|
|
91
|
-
type: AnnotationTypes.INLINE_COMMENT
|
|
92
|
-
}],
|
|
93
|
-
editorState: editorState
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
return createCommand(commandAction, transform.addInlineComment(editorAnalyticsAPI)(id));
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
export var updateMouseState = function updateMouseState(mouseData) {
|
|
101
|
-
return createCommand({
|
|
102
|
-
type: ACTIONS.INLINE_COMMENT_UPDATE_MOUSE_STATE,
|
|
103
|
-
data: {
|
|
104
|
-
mouseData: mouseData
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
export var setSelectedAnnotation = function setSelectedAnnotation(id) {
|
|
109
|
-
return createCommand({
|
|
110
|
-
type: ACTIONS.SET_SELECTED_ANNOTATION,
|
|
111
|
-
data: {
|
|
112
|
-
selectedAnnotations: [{
|
|
113
|
-
id: id,
|
|
114
|
-
type: AnnotationTypes.INLINE_COMMENT
|
|
115
|
-
}]
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
|
-
export var createAnnotation = function createAnnotation(editorAnalyticsAPI) {
|
|
120
|
-
return function (id) {
|
|
121
|
-
var annotationType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : AnnotationTypes.INLINE_COMMENT;
|
|
122
|
-
return function (state, dispatch) {
|
|
123
|
-
// don't try to add if there are is no temp highlight bookmarked
|
|
124
|
-
var _ref = getPluginState(state) || {},
|
|
125
|
-
bookmark = _ref.bookmark;
|
|
126
|
-
if (!bookmark || !dispatch) {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
if (annotationType === AnnotationTypes.INLINE_COMMENT) {
|
|
130
|
-
return addInlineComment(editorAnalyticsAPI)(id)(state, dispatch);
|
|
131
|
-
}
|
|
132
|
-
return false;
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
export var setInlineCommentsVisibility = function setInlineCommentsVisibility(isVisible) {
|
|
137
|
-
return createCommand({
|
|
138
|
-
type: ACTIONS.INLINE_COMMENT_SET_VISIBLE,
|
|
139
|
-
data: {
|
|
140
|
-
isVisible: isVisible
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { AnnotationTypes } from '@atlaskit/adf-schema';
|
|
3
|
-
import { ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, ACTION, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
|
-
import { getSelectionPositions, getPluginState, getDraftCommandAnalyticsPayload } from '../utils';
|
|
5
|
-
import { applyMarkOnRange } from '@atlaskit/editor-common/mark';
|
|
6
|
-
var addAnnotationMark = function addAnnotationMark(id) {
|
|
7
|
-
return function (transaction, state) {
|
|
8
|
-
var inlineCommentState = getPluginState(state);
|
|
9
|
-
var _getSelectionPosition = getSelectionPositions(state, inlineCommentState),
|
|
10
|
-
from = _getSelectionPosition.from,
|
|
11
|
-
to = _getSelectionPosition.to,
|
|
12
|
-
head = _getSelectionPosition.head;
|
|
13
|
-
var annotationMark = state.schema.marks.annotation.create({
|
|
14
|
-
id: id,
|
|
15
|
-
type: AnnotationTypes.INLINE_COMMENT
|
|
16
|
-
});
|
|
17
|
-
// Apply the mark only to text node in the range.
|
|
18
|
-
var tr = applyMarkOnRange(from, to, false, annotationMark, transaction);
|
|
19
|
-
// set selection back to the end of annotation once annotation mark is applied
|
|
20
|
-
tr.setSelection(TextSelection.create(tr.doc, head));
|
|
21
|
-
return tr;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
var addInlineComment = function addInlineComment(editorAnalyticsAPI) {
|
|
25
|
-
return function (id) {
|
|
26
|
-
return function (transaction, state) {
|
|
27
|
-
var tr = addAnnotationMark(id)(transaction, state);
|
|
28
|
-
// add insert analytics step to transaction
|
|
29
|
-
tr = addInsertAnalytics(editorAnalyticsAPI)(tr, state);
|
|
30
|
-
// add close analytics step to transaction
|
|
31
|
-
tr = addOpenCloseAnalytics(editorAnalyticsAPI)(false, INPUT_METHOD.TOOLBAR)(tr, state);
|
|
32
|
-
return tr;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
var addOpenCloseAnalytics = function addOpenCloseAnalytics(editorAnalyticsAPI) {
|
|
37
|
-
return function (drafting) {
|
|
38
|
-
var method = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : INPUT_METHOD.TOOLBAR;
|
|
39
|
-
return function (transaction, state) {
|
|
40
|
-
var draftingPayload = getDraftCommandAnalyticsPayload(drafting, method)(state);
|
|
41
|
-
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(draftingPayload)(transaction);
|
|
42
|
-
return transaction;
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
var addInsertAnalytics = function addInsertAnalytics(editorAnalyticsAPI) {
|
|
47
|
-
return function (transaction, state) {
|
|
48
|
-
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
49
|
-
action: ACTION.INSERTED,
|
|
50
|
-
actionSubject: ACTION_SUBJECT.ANNOTATION,
|
|
51
|
-
eventType: EVENT_TYPE.TRACK,
|
|
52
|
-
actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT
|
|
53
|
-
})(transaction);
|
|
54
|
-
return transaction;
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
var addResolveAnalytics = function addResolveAnalytics(editorAnalyticsAPI) {
|
|
58
|
-
return function (method) {
|
|
59
|
-
return function (transaction, state) {
|
|
60
|
-
var resolvedPayload = {
|
|
61
|
-
action: ACTION.RESOLVED,
|
|
62
|
-
actionSubject: ACTION_SUBJECT.ANNOTATION,
|
|
63
|
-
actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
|
|
64
|
-
eventType: EVENT_TYPE.TRACK,
|
|
65
|
-
attributes: {
|
|
66
|
-
method: method
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(resolvedPayload)(transaction);
|
|
70
|
-
return transaction;
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
export default {
|
|
75
|
-
addAnnotationMark: addAnnotationMark,
|
|
76
|
-
addInlineComment: addInlineComment,
|
|
77
|
-
addOpenCloseAnalytics: addOpenCloseAnalytics,
|
|
78
|
-
addInsertAnalytics: addInsertAnalytics,
|
|
79
|
-
addResolveAnalytics: addResolveAnalytics
|
|
80
|
-
};
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { annotation } from '@atlaskit/adf-schema';
|
|
3
|
-
import { keymapPlugin } from './pm-plugins/keymap';
|
|
4
|
-
import { inlineCommentPlugin } from './pm-plugins/inline-comment';
|
|
5
|
-
import { AnnotationUpdateEmitter } from './update-provider';
|
|
6
|
-
import { getPluginState } from './utils';
|
|
7
|
-
import { buildToolbar } from './toolbar';
|
|
8
|
-
import { InlineCommentView } from './ui/InlineCommentView';
|
|
9
|
-
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
10
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
11
|
-
var annotationPlugin = function annotationPlugin(_ref) {
|
|
12
|
-
var annotationProviders = _ref.config,
|
|
13
|
-
api = _ref.api;
|
|
14
|
-
return {
|
|
15
|
-
name: 'annotation',
|
|
16
|
-
marks: function marks() {
|
|
17
|
-
return [{
|
|
18
|
-
name: 'annotation',
|
|
19
|
-
mark: annotation
|
|
20
|
-
}];
|
|
21
|
-
},
|
|
22
|
-
getSharedState: function getSharedState(editorState) {
|
|
23
|
-
if (!editorState) {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
return getPluginState(editorState) || undefined;
|
|
27
|
-
},
|
|
28
|
-
pmPlugins: function pmPlugins() {
|
|
29
|
-
return [{
|
|
30
|
-
name: 'annotation',
|
|
31
|
-
plugin: function plugin(_ref2) {
|
|
32
|
-
var dispatch = _ref2.dispatch,
|
|
33
|
-
portalProviderAPI = _ref2.portalProviderAPI,
|
|
34
|
-
eventDispatcher = _ref2.eventDispatcher;
|
|
35
|
-
if (annotationProviders) {
|
|
36
|
-
var _api$analytics;
|
|
37
|
-
return inlineCommentPlugin({
|
|
38
|
-
dispatch: dispatch,
|
|
39
|
-
portalProviderAPI: portalProviderAPI,
|
|
40
|
-
eventDispatcher: eventDispatcher,
|
|
41
|
-
provider: annotationProviders.inlineComment,
|
|
42
|
-
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
}, {
|
|
48
|
-
name: 'annotationKeymap',
|
|
49
|
-
plugin: function plugin() {
|
|
50
|
-
if (annotationProviders) {
|
|
51
|
-
var _api$analytics2;
|
|
52
|
-
return keymapPlugin(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
|
|
53
|
-
}
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
}];
|
|
57
|
-
},
|
|
58
|
-
pluginsOptions: {
|
|
59
|
-
floatingToolbar: function floatingToolbar(state, intl) {
|
|
60
|
-
if (getBooleanFF('platform.editor.enable-selection-toolbar_ucdwd') || !annotationProviders) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
var pluginState = getPluginState(state);
|
|
64
|
-
if (pluginState && pluginState.isVisible && !pluginState.bookmark && !pluginState.mouseData.isSelecting) {
|
|
65
|
-
var _api$analytics3;
|
|
66
|
-
var isToolbarAbove = annotationProviders.inlineComment.isToolbarAbove;
|
|
67
|
-
return buildToolbar(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions)(state, intl, isToolbarAbove);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
selectionToolbar: function selectionToolbar(state, intl) {
|
|
71
|
-
if (!getBooleanFF('platform.editor.enable-selection-toolbar_ucdwd') || !annotationProviders) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
var pluginState = getPluginState(state);
|
|
75
|
-
if (pluginState && pluginState.isVisible && !pluginState.bookmark && !pluginState.mouseData.isSelecting) {
|
|
76
|
-
var _api$analytics4;
|
|
77
|
-
var isToolbarAbove = annotationProviders.inlineComment.isToolbarAbove;
|
|
78
|
-
return buildToolbar(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions)(state, intl, isToolbarAbove);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
contentComponent: function contentComponent(_ref3) {
|
|
83
|
-
var editorView = _ref3.editorView,
|
|
84
|
-
dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent;
|
|
85
|
-
if (!annotationProviders) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
return /*#__PURE__*/React.createElement(AnnotationContentComponent, {
|
|
89
|
-
api: api,
|
|
90
|
-
editorView: editorView,
|
|
91
|
-
annotationProviders: annotationProviders,
|
|
92
|
-
dispatchAnalyticsEvent: dispatchAnalyticsEvent
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
function AnnotationContentComponent(_ref4) {
|
|
98
|
-
var _api$analytics5;
|
|
99
|
-
var api = _ref4.api,
|
|
100
|
-
editorView = _ref4.editorView,
|
|
101
|
-
annotationProviders = _ref4.annotationProviders,
|
|
102
|
-
dispatchAnalyticsEvent = _ref4.dispatchAnalyticsEvent;
|
|
103
|
-
var _useSharedPluginState = useSharedPluginState(api, ['annotation']),
|
|
104
|
-
inlineCommentState = _useSharedPluginState.annotationState;
|
|
105
|
-
if (inlineCommentState && !inlineCommentState.isVisible) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
109
|
-
"data-editor-popup": "true"
|
|
110
|
-
}, /*#__PURE__*/React.createElement(InlineCommentView, {
|
|
111
|
-
providers: annotationProviders,
|
|
112
|
-
editorView: editorView,
|
|
113
|
-
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
114
|
-
editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions
|
|
115
|
-
}));
|
|
116
|
-
}
|
|
117
|
-
export default annotationPlugin;
|
|
118
|
-
export { AnnotationUpdateEmitter };
|