@manuscripts/body-editor 1.8.4-LEAN-2974-1 → 1.8.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/dist/cjs/plugins/comment_annotation.js +9 -40
- package/dist/cjs/views/citation.js +0 -2
- package/dist/cjs/views/citation_editable.js +0 -7
- package/dist/es/plugins/comment_annotation.js +8 -38
- package/dist/es/views/citation.js +0 -2
- package/dist/es/views/citation_editable.js +0 -7
- package/dist/types/plugins/comment_annotation.d.ts +1 -2
- package/dist/types/types.d.ts +0 -6
- package/dist/types/views/citation_editable.d.ts +0 -1
- package/package.json +1 -1
- package/styles/AdvancedEditor.css +7 -0
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
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");
|
|
7
6
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
8
7
|
const highlight_1 = require("./highlight");
|
|
9
8
|
exports.commentAnnotation = new prosemirror_state_1.PluginKey('comment_annotation');
|
|
@@ -44,26 +43,14 @@ exports.default = (props) => {
|
|
|
44
43
|
return new prosemirror_view_1.DecorationSet();
|
|
45
44
|
}
|
|
46
45
|
},
|
|
47
|
-
apply: (tr
|
|
46
|
+
apply: (tr) => {
|
|
48
47
|
const meta = tr.getMeta(exports.commentAnnotation);
|
|
49
48
|
if (meta) {
|
|
50
49
|
if (highlight_1.SET_COMMENT in meta) {
|
|
51
50
|
props.setComment(meta[highlight_1.SET_COMMENT]);
|
|
52
|
-
return value;
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
|
|
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;
|
|
53
|
+
return commentsState(props.setSelectedComment, tr.doc);
|
|
67
54
|
},
|
|
68
55
|
},
|
|
69
56
|
props: {
|
|
@@ -112,23 +99,16 @@ const commentsState = (setSelectedComment, doc) => {
|
|
|
112
99
|
const id = node.attrs['id'] || node.attrs['rid'];
|
|
113
100
|
const targetComment = commentsMap.get(id);
|
|
114
101
|
if (targetComment) {
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
}
|
|
102
|
+
const position = getNodePosition(node, pos);
|
|
103
|
+
decorations.push(prosemirror_view_1.Decoration.widget(position, getCommentIcon(Object.assign(Object.assign({}, targetComment), { targetType: node.type }), setSelectedComment), { key: targetComment.id }));
|
|
124
104
|
}
|
|
125
105
|
});
|
|
126
106
|
return prosemirror_view_1.DecorationSet.create(doc, decorations);
|
|
127
107
|
};
|
|
128
108
|
const getCommentIcon = (comment, setSelectedComment) => () => {
|
|
129
|
-
const { id, targetType, target, count, location
|
|
109
|
+
const { id, targetType, target, count, location } = comment;
|
|
130
110
|
const commentId = location === 'block' ? target : id;
|
|
131
|
-
const element = document.createElement(
|
|
111
|
+
const element = document.createElement('div');
|
|
132
112
|
element.id = commentId;
|
|
133
113
|
let elementClass;
|
|
134
114
|
switch (targetType) {
|
|
@@ -146,8 +126,8 @@ const getCommentIcon = (comment, setSelectedComment) => () => {
|
|
|
146
126
|
default:
|
|
147
127
|
elementClass = 'inline-comment';
|
|
148
128
|
}
|
|
149
|
-
if (
|
|
150
|
-
element.classList.add('point-comment');
|
|
129
|
+
if (targetType === transform_1.schema.nodes.citation || location === 'point') {
|
|
130
|
+
element.classList.add(location === 'point' ? 'point-comment' : 'inline-citation');
|
|
151
131
|
}
|
|
152
132
|
element.classList.add('block-comment-button', elementClass);
|
|
153
133
|
element.onclick = (e) => {
|
|
@@ -172,14 +152,3 @@ const getCommentIcon = (comment, setSelectedComment) => () => {
|
|
|
172
152
|
`;
|
|
173
153
|
return element;
|
|
174
154
|
};
|
|
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,7 +21,6 @@ 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");
|
|
25
24
|
const base_node_view_1 = require("./base_node_view");
|
|
26
25
|
const creators_1 = require("./creators");
|
|
27
26
|
class CitationView extends base_node_view_1.BaseNodeView {
|
|
@@ -56,7 +55,6 @@ class CitationView extends base_node_view_1.BaseNodeView {
|
|
|
56
55
|
this.dom.className = 'citation-wrapper';
|
|
57
56
|
this.dom.innerHTML = '';
|
|
58
57
|
this.dom.appendChild(element);
|
|
59
|
-
(0, comment_annotation_1.addCommentToLeafNode)(this.getPos(), this.getPos() + this.node.nodeSize, this.view.state, this.dom);
|
|
60
58
|
this.setDomAttrs(this.node, this.dom, ['rids', 'contents', 'selectedText']);
|
|
61
59
|
};
|
|
62
60
|
this.getCitation = () => {
|
|
@@ -42,13 +42,6 @@ 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
|
-
};
|
|
52
45
|
this.selectNode = () => {
|
|
53
46
|
var _a;
|
|
54
47
|
const dataTracked = this.node.attrs.dataTracked;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { schema } from '@manuscripts/transform';
|
|
2
2
|
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
3
|
-
import { ReplaceStep } from 'prosemirror-transform';
|
|
4
3
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
5
4
|
import { SET_COMMENT } from './highlight';
|
|
6
5
|
export const commentAnnotation = new PluginKey('comment_annotation');
|
|
@@ -38,26 +37,14 @@ export default (props) => {
|
|
|
38
37
|
return new DecorationSet();
|
|
39
38
|
}
|
|
40
39
|
},
|
|
41
|
-
apply: (tr
|
|
40
|
+
apply: (tr) => {
|
|
42
41
|
const meta = tr.getMeta(commentAnnotation);
|
|
43
42
|
if (meta) {
|
|
44
43
|
if (SET_COMMENT in meta) {
|
|
45
44
|
props.setComment(meta[SET_COMMENT]);
|
|
46
|
-
return value;
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
|
-
|
|
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;
|
|
47
|
+
return commentsState(props.setSelectedComment, tr.doc);
|
|
61
48
|
},
|
|
62
49
|
},
|
|
63
50
|
props: {
|
|
@@ -106,23 +93,16 @@ const commentsState = (setSelectedComment, doc) => {
|
|
|
106
93
|
const id = node.attrs['id'] || node.attrs['rid'];
|
|
107
94
|
const targetComment = commentsMap.get(id);
|
|
108
95
|
if (targetComment) {
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
}
|
|
96
|
+
const position = getNodePosition(node, pos);
|
|
97
|
+
decorations.push(Decoration.widget(position, getCommentIcon(Object.assign(Object.assign({}, targetComment), { targetType: node.type }), setSelectedComment), { key: targetComment.id }));
|
|
118
98
|
}
|
|
119
99
|
});
|
|
120
100
|
return DecorationSet.create(doc, decorations);
|
|
121
101
|
};
|
|
122
102
|
const getCommentIcon = (comment, setSelectedComment) => () => {
|
|
123
|
-
const { id, targetType, target, count, location
|
|
103
|
+
const { id, targetType, target, count, location } = comment;
|
|
124
104
|
const commentId = location === 'block' ? target : id;
|
|
125
|
-
const element = document.createElement(
|
|
105
|
+
const element = document.createElement('div');
|
|
126
106
|
element.id = commentId;
|
|
127
107
|
let elementClass;
|
|
128
108
|
switch (targetType) {
|
|
@@ -140,8 +120,8 @@ const getCommentIcon = (comment, setSelectedComment) => () => {
|
|
|
140
120
|
default:
|
|
141
121
|
elementClass = 'inline-comment';
|
|
142
122
|
}
|
|
143
|
-
if (
|
|
144
|
-
element.classList.add('point-comment');
|
|
123
|
+
if (targetType === schema.nodes.citation || location === 'point') {
|
|
124
|
+
element.classList.add(location === 'point' ? 'point-comment' : 'inline-citation');
|
|
145
125
|
}
|
|
146
126
|
element.classList.add('block-comment-button', elementClass);
|
|
147
127
|
element.onclick = (e) => {
|
|
@@ -166,13 +146,3 @@ const getCommentIcon = (comment, setSelectedComment) => () => {
|
|
|
166
146
|
`;
|
|
167
147
|
return element;
|
|
168
148
|
};
|
|
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,7 +18,6 @@ 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';
|
|
22
21
|
import { BaseNodeView } from './base_node_view';
|
|
23
22
|
import { createNodeView } from './creators';
|
|
24
23
|
export class CitationView extends BaseNodeView {
|
|
@@ -53,7 +52,6 @@ export class CitationView extends BaseNodeView {
|
|
|
53
52
|
this.dom.className = 'citation-wrapper';
|
|
54
53
|
this.dom.innerHTML = '';
|
|
55
54
|
this.dom.appendChild(element);
|
|
56
|
-
addCommentToLeafNode(this.getPos(), this.getPos() + this.node.nodeSize, this.view.state, this.dom);
|
|
57
55
|
this.setDomAttrs(this.node, this.dom, ['rids', 'contents', 'selectedText']);
|
|
58
56
|
};
|
|
59
57
|
this.getCitation = () => {
|
|
@@ -36,13 +36,6 @@ 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
|
-
};
|
|
46
39
|
this.selectNode = () => {
|
|
47
40
|
var _a;
|
|
48
41
|
const dataTracked = this.node.attrs.dataTracked;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommentAnnotation } from '@manuscripts/json-schema';
|
|
2
|
-
import {
|
|
2
|
+
import { 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,4 +11,3 @@ 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,9 +28,3 @@ 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,7 +19,6 @@ export declare class CitationEditableView extends CitationView<EditableBlockProp
|
|
|
19
19
|
private decoder;
|
|
20
20
|
private editor;
|
|
21
21
|
private contextMenu;
|
|
22
|
-
stopEvent: (event: Event) => boolean;
|
|
23
22
|
selectNode: () => void;
|
|
24
23
|
deselectNode: () => void;
|
|
25
24
|
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
|
|
4
|
+
"version": "1.8.4",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -483,6 +483,13 @@ 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
|
+
|
|
486
493
|
.block-comment-button.point-comment {
|
|
487
494
|
z-index: 1;
|
|
488
495
|
left: 0;
|