@manuscripts/body-editor 1.8.4 → 1.8.5-LEAN-2974-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/plugins/comment_annotation.js +40 -9
- package/dist/cjs/views/citation.js +2 -0
- package/dist/cjs/views/citation_editable.js +7 -0
- package/dist/es/plugins/comment_annotation.js +38 -8
- package/dist/es/views/citation.js +2 -0
- package/dist/es/views/citation_editable.js +7 -0
- package/dist/types/plugins/comment_annotation.d.ts +2 -1
- package/dist/types/types.d.ts +6 -0
- package/dist/types/views/citation_editable.d.ts +1 -0
- package/package.json +3 -3
- package/styles/AdvancedEditor.css +0 -7
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isHighlightComment = exports.isThereSelector = exports.commentScroll = exports.commentAnnotation = void 0;
|
|
3
|
+
exports.addCommentToLeafNode = exports.isHighlightComment = exports.isThereSelector = exports.commentScroll = exports.commentAnnotation = void 0;
|
|
4
4
|
const transform_1 = require("@manuscripts/transform");
|
|
5
5
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
6
|
+
const prosemirror_transform_1 = require("prosemirror-transform");
|
|
6
7
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
7
8
|
const highlight_1 = require("./highlight");
|
|
8
9
|
exports.commentAnnotation = new prosemirror_state_1.PluginKey('comment_annotation');
|
|
@@ -43,14 +44,26 @@ exports.default = (props) => {
|
|
|
43
44
|
return new prosemirror_view_1.DecorationSet();
|
|
44
45
|
}
|
|
45
46
|
},
|
|
46
|
-
apply: (tr) => {
|
|
47
|
+
apply: (tr, value, oldState, newState) => {
|
|
47
48
|
const meta = tr.getMeta(exports.commentAnnotation);
|
|
48
49
|
if (meta) {
|
|
49
50
|
if (highlight_1.SET_COMMENT in meta) {
|
|
50
51
|
props.setComment(meta[highlight_1.SET_COMMENT]);
|
|
52
|
+
return value;
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
const hasCommentChange = !!tr.steps.find((s) => {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
if (s instanceof prosemirror_transform_1.ReplaceStep) {
|
|
58
|
+
return s.slice.size > 0
|
|
59
|
+
? ((_a = newState.doc.nodeAt(s.from + 1)) === null || _a === void 0 ? void 0 : _a.type) === transform_1.schema.nodes.comment
|
|
60
|
+
: ((_b = oldState.doc.nodeAt(s.from)) === null || _b === void 0 ? void 0 : _b.type) === transform_1.schema.nodes.comment;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (hasCommentChange) {
|
|
64
|
+
return commentsState(props.setSelectedComment, tr.doc);
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
54
67
|
},
|
|
55
68
|
},
|
|
56
69
|
props: {
|
|
@@ -99,16 +112,23 @@ const commentsState = (setSelectedComment, doc) => {
|
|
|
99
112
|
const id = node.attrs['id'] || node.attrs['rid'];
|
|
100
113
|
const targetComment = commentsMap.get(id);
|
|
101
114
|
if (targetComment) {
|
|
102
|
-
|
|
103
|
-
|
|
115
|
+
if (node.isAtom && node.type !== transform_1.schema.nodes.highlight_marker) {
|
|
116
|
+
decorations.push(prosemirror_view_1.Decoration.inline(pos, pos + node.nodeSize, {}, {
|
|
117
|
+
toDOM: getCommentIcon(Object.assign(Object.assign({}, targetComment), { targetType: node.type, isAtom: node.isAtom }), setSelectedComment),
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const position = getNodePosition(node, pos);
|
|
122
|
+
decorations.push(prosemirror_view_1.Decoration.widget(position, getCommentIcon(Object.assign(Object.assign({}, targetComment), { targetType: node.type }), setSelectedComment), { key: targetComment.id }));
|
|
123
|
+
}
|
|
104
124
|
}
|
|
105
125
|
});
|
|
106
126
|
return prosemirror_view_1.DecorationSet.create(doc, decorations);
|
|
107
127
|
};
|
|
108
128
|
const getCommentIcon = (comment, setSelectedComment) => () => {
|
|
109
|
-
const { id, targetType, target, count, location } = comment;
|
|
129
|
+
const { id, targetType, target, count, location, isAtom } = comment;
|
|
110
130
|
const commentId = location === 'block' ? target : id;
|
|
111
|
-
const element = document.createElement('div');
|
|
131
|
+
const element = document.createElement(isAtom ? 'span' : 'div');
|
|
112
132
|
element.id = commentId;
|
|
113
133
|
let elementClass;
|
|
114
134
|
switch (targetType) {
|
|
@@ -126,8 +146,8 @@ const getCommentIcon = (comment, setSelectedComment) => () => {
|
|
|
126
146
|
default:
|
|
127
147
|
elementClass = 'inline-comment';
|
|
128
148
|
}
|
|
129
|
-
if (
|
|
130
|
-
element.classList.add(
|
|
149
|
+
if (isAtom || location === 'point') {
|
|
150
|
+
element.classList.add('point-comment');
|
|
131
151
|
}
|
|
132
152
|
element.classList.add('block-comment-button', elementClass);
|
|
133
153
|
element.onclick = (e) => {
|
|
@@ -152,3 +172,14 @@ const getCommentIcon = (comment, setSelectedComment) => () => {
|
|
|
152
172
|
`;
|
|
153
173
|
return element;
|
|
154
174
|
};
|
|
175
|
+
const addCommentToLeafNode = (from, to, state, dom) => {
|
|
176
|
+
const commentsDecorationSet = exports.commentAnnotation.getState(state);
|
|
177
|
+
if (commentsDecorationSet) {
|
|
178
|
+
const commentWidget = commentsDecorationSet.find(from, to);
|
|
179
|
+
if (commentWidget.length) {
|
|
180
|
+
const commentElement = commentWidget[0].type.spec.toDOM();
|
|
181
|
+
dom.appendChild(commentElement);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
exports.addCommentToLeafNode = addCommentToLeafNode;
|
|
@@ -21,6 +21,7 @@ const dompurify_1 = require("../lib/dompurify");
|
|
|
21
21
|
const track_changes_utils_1 = require("../lib/track-changes-utils");
|
|
22
22
|
const bibliography_1 = require("../plugins/bibliography");
|
|
23
23
|
const bibliography_utils_1 = require("../plugins/bibliography/bibliography-utils");
|
|
24
|
+
const comment_annotation_1 = require("../plugins/comment_annotation");
|
|
24
25
|
const base_node_view_1 = require("./base_node_view");
|
|
25
26
|
const creators_1 = require("./creators");
|
|
26
27
|
class CitationView extends base_node_view_1.BaseNodeView {
|
|
@@ -55,6 +56,7 @@ class CitationView extends base_node_view_1.BaseNodeView {
|
|
|
55
56
|
this.dom.className = 'citation-wrapper';
|
|
56
57
|
this.dom.innerHTML = '';
|
|
57
58
|
this.dom.appendChild(element);
|
|
59
|
+
(0, comment_annotation_1.addCommentToLeafNode)(this.getPos(), this.getPos() + this.node.nodeSize, this.view.state, this.dom);
|
|
58
60
|
this.setDomAttrs(this.node, this.dom, ['rids', 'contents', 'selectedText']);
|
|
59
61
|
};
|
|
60
62
|
this.getCitation = () => {
|
|
@@ -42,6 +42,13 @@ class CitationEditableView extends citation_1.CitationView {
|
|
|
42
42
|
constructor() {
|
|
43
43
|
super(...arguments);
|
|
44
44
|
this.decoder = new transform_1.Decoder(new Map());
|
|
45
|
+
this.stopEvent = (event) => {
|
|
46
|
+
var _a;
|
|
47
|
+
const element = event.target;
|
|
48
|
+
return !!(element.classList.contains('point-comment') ||
|
|
49
|
+
element.classList.contains('comment-icon') ||
|
|
50
|
+
((_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains('comment-icon')));
|
|
51
|
+
};
|
|
45
52
|
this.selectNode = () => {
|
|
46
53
|
var _a;
|
|
47
54
|
const dataTracked = this.node.attrs.dataTracked;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { schema } from '@manuscripts/transform';
|
|
2
2
|
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
3
|
+
import { ReplaceStep } from 'prosemirror-transform';
|
|
3
4
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
4
5
|
import { SET_COMMENT } from './highlight';
|
|
5
6
|
export const commentAnnotation = new PluginKey('comment_annotation');
|
|
@@ -37,14 +38,26 @@ export default (props) => {
|
|
|
37
38
|
return new DecorationSet();
|
|
38
39
|
}
|
|
39
40
|
},
|
|
40
|
-
apply: (tr) => {
|
|
41
|
+
apply: (tr, value, oldState, newState) => {
|
|
41
42
|
const meta = tr.getMeta(commentAnnotation);
|
|
42
43
|
if (meta) {
|
|
43
44
|
if (SET_COMMENT in meta) {
|
|
44
45
|
props.setComment(meta[SET_COMMENT]);
|
|
46
|
+
return value;
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
|
-
|
|
49
|
+
const hasCommentChange = !!tr.steps.find((s) => {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
if (s instanceof ReplaceStep) {
|
|
52
|
+
return s.slice.size > 0
|
|
53
|
+
? ((_a = newState.doc.nodeAt(s.from + 1)) === null || _a === void 0 ? void 0 : _a.type) === schema.nodes.comment
|
|
54
|
+
: ((_b = oldState.doc.nodeAt(s.from)) === null || _b === void 0 ? void 0 : _b.type) === schema.nodes.comment;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
if (hasCommentChange) {
|
|
58
|
+
return commentsState(props.setSelectedComment, tr.doc);
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
48
61
|
},
|
|
49
62
|
},
|
|
50
63
|
props: {
|
|
@@ -93,16 +106,23 @@ const commentsState = (setSelectedComment, doc) => {
|
|
|
93
106
|
const id = node.attrs['id'] || node.attrs['rid'];
|
|
94
107
|
const targetComment = commentsMap.get(id);
|
|
95
108
|
if (targetComment) {
|
|
96
|
-
|
|
97
|
-
|
|
109
|
+
if (node.isAtom && node.type !== schema.nodes.highlight_marker) {
|
|
110
|
+
decorations.push(Decoration.inline(pos, pos + node.nodeSize, {}, {
|
|
111
|
+
toDOM: getCommentIcon(Object.assign(Object.assign({}, targetComment), { targetType: node.type, isAtom: node.isAtom }), setSelectedComment),
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const position = getNodePosition(node, pos);
|
|
116
|
+
decorations.push(Decoration.widget(position, getCommentIcon(Object.assign(Object.assign({}, targetComment), { targetType: node.type }), setSelectedComment), { key: targetComment.id }));
|
|
117
|
+
}
|
|
98
118
|
}
|
|
99
119
|
});
|
|
100
120
|
return DecorationSet.create(doc, decorations);
|
|
101
121
|
};
|
|
102
122
|
const getCommentIcon = (comment, setSelectedComment) => () => {
|
|
103
|
-
const { id, targetType, target, count, location } = comment;
|
|
123
|
+
const { id, targetType, target, count, location, isAtom } = comment;
|
|
104
124
|
const commentId = location === 'block' ? target : id;
|
|
105
|
-
const element = document.createElement('div');
|
|
125
|
+
const element = document.createElement(isAtom ? 'span' : 'div');
|
|
106
126
|
element.id = commentId;
|
|
107
127
|
let elementClass;
|
|
108
128
|
switch (targetType) {
|
|
@@ -120,8 +140,8 @@ const getCommentIcon = (comment, setSelectedComment) => () => {
|
|
|
120
140
|
default:
|
|
121
141
|
elementClass = 'inline-comment';
|
|
122
142
|
}
|
|
123
|
-
if (
|
|
124
|
-
element.classList.add(
|
|
143
|
+
if (isAtom || location === 'point') {
|
|
144
|
+
element.classList.add('point-comment');
|
|
125
145
|
}
|
|
126
146
|
element.classList.add('block-comment-button', elementClass);
|
|
127
147
|
element.onclick = (e) => {
|
|
@@ -146,3 +166,13 @@ const getCommentIcon = (comment, setSelectedComment) => () => {
|
|
|
146
166
|
`;
|
|
147
167
|
return element;
|
|
148
168
|
};
|
|
169
|
+
export const addCommentToLeafNode = (from, to, state, dom) => {
|
|
170
|
+
const commentsDecorationSet = commentAnnotation.getState(state);
|
|
171
|
+
if (commentsDecorationSet) {
|
|
172
|
+
const commentWidget = commentsDecorationSet.find(from, to);
|
|
173
|
+
if (commentWidget.length) {
|
|
174
|
+
const commentElement = commentWidget[0].type.spec.toDOM();
|
|
175
|
+
dom.appendChild(commentElement);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
@@ -18,6 +18,7 @@ import { sanitize } from '../lib/dompurify';
|
|
|
18
18
|
import { getChangeClasses } from '../lib/track-changes-utils';
|
|
19
19
|
import { getBibliographyPluginState } from '../plugins/bibliography';
|
|
20
20
|
import { getCitation } from '../plugins/bibliography/bibliography-utils';
|
|
21
|
+
import { addCommentToLeafNode } from '../plugins/comment_annotation';
|
|
21
22
|
import { BaseNodeView } from './base_node_view';
|
|
22
23
|
import { createNodeView } from './creators';
|
|
23
24
|
export class CitationView extends BaseNodeView {
|
|
@@ -52,6 +53,7 @@ export class CitationView extends BaseNodeView {
|
|
|
52
53
|
this.dom.className = 'citation-wrapper';
|
|
53
54
|
this.dom.innerHTML = '';
|
|
54
55
|
this.dom.appendChild(element);
|
|
56
|
+
addCommentToLeafNode(this.getPos(), this.getPos() + this.node.nodeSize, this.view.state, this.dom);
|
|
55
57
|
this.setDomAttrs(this.node, this.dom, ['rids', 'contents', 'selectedText']);
|
|
56
58
|
};
|
|
57
59
|
this.getCitation = () => {
|
|
@@ -36,6 +36,13 @@ export class CitationEditableView extends CitationView {
|
|
|
36
36
|
constructor() {
|
|
37
37
|
super(...arguments);
|
|
38
38
|
this.decoder = new Decoder(new Map());
|
|
39
|
+
this.stopEvent = (event) => {
|
|
40
|
+
var _a;
|
|
41
|
+
const element = event.target;
|
|
42
|
+
return !!(element.classList.contains('point-comment') ||
|
|
43
|
+
element.classList.contains('comment-icon') ||
|
|
44
|
+
((_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains('comment-icon')));
|
|
45
|
+
};
|
|
39
46
|
this.selectNode = () => {
|
|
40
47
|
var _a;
|
|
41
48
|
const dataTracked = this.node.attrs.dataTracked;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommentAnnotation } from '@manuscripts/json-schema';
|
|
2
|
-
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
+
import { EditorState, Plugin, PluginKey } from 'prosemirror-state';
|
|
3
3
|
import { DecorationSet } from 'prosemirror-view';
|
|
4
4
|
export declare const commentAnnotation: PluginKey<DecorationSet>;
|
|
5
5
|
export declare const commentScroll: (id: string, direction: 'editor' | 'inspector', isHighlight?: boolean) => void;
|
|
@@ -11,3 +11,4 @@ interface CommentAnnotationProps {
|
|
|
11
11
|
}
|
|
12
12
|
declare const _default: (props: CommentAnnotationProps) => Plugin<DecorationSet>;
|
|
13
13
|
export default _default;
|
|
14
|
+
export declare const addCommentToLeafNode: (from: number, to: number, state: EditorState, dom: HTMLElement) => void;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -28,3 +28,9 @@ export interface SyncError {
|
|
|
28
28
|
export type TrackableAttributes<T extends ManuscriptNode> = T['attrs'] & {
|
|
29
29
|
dataTracked?: TrackedAttrs[];
|
|
30
30
|
};
|
|
31
|
+
export type WidgetDecoration = Decoration & {
|
|
32
|
+
type: {
|
|
33
|
+
toDOM: () => HTMLElement;
|
|
34
|
+
spec: Decoration['spec'];
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -19,6 +19,7 @@ export declare class CitationEditableView extends CitationView<EditableBlockProp
|
|
|
19
19
|
private decoder;
|
|
20
20
|
private editor;
|
|
21
21
|
private contextMenu;
|
|
22
|
+
stopEvent: (event: Event) => boolean;
|
|
22
23
|
selectNode: () => void;
|
|
23
24
|
deselectNode: () => void;
|
|
24
25
|
destroy: () => void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/body-editor",
|
|
3
3
|
"description": "Prosemirror components for editing and viewing manuscripts",
|
|
4
|
-
"version": "1.8.
|
|
4
|
+
"version": "1.8.5-LEAN-2974-0",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@manuscripts/json-schema": "^2.2.7",
|
|
33
33
|
"@manuscripts/library": "^1.3.6",
|
|
34
34
|
"@manuscripts/style-guide": "^1.11.2",
|
|
35
|
-
"@manuscripts/track-changes-plugin": "1.7.
|
|
35
|
+
"@manuscripts/track-changes-plugin": "1.7.10",
|
|
36
36
|
"@manuscripts/transform": "^2.2.1",
|
|
37
37
|
"astrocite-eutils": "^0.16.4",
|
|
38
38
|
"axios": "^1.6.7",
|
|
@@ -112,4 +112,4 @@
|
|
|
112
112
|
"@types/react": "^17.0.2",
|
|
113
113
|
"prosemirror-tables": "^1.3.5"
|
|
114
114
|
}
|
|
115
|
-
}
|
|
115
|
+
}
|
|
@@ -483,13 +483,6 @@ Next levels are shifted 'up' by 1
|
|
|
483
483
|
top: 6px;
|
|
484
484
|
}
|
|
485
485
|
|
|
486
|
-
.block-comment-button.inline-citation {
|
|
487
|
-
z-index: 1;
|
|
488
|
-
left: -1%;
|
|
489
|
-
top: -8%;
|
|
490
|
-
display: inline-flex;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
486
|
.block-comment-button.point-comment {
|
|
494
487
|
z-index: 1;
|
|
495
488
|
left: 0;
|