@manuscripts/body-editor 1.10.8-LEAN-3591.1 → 1.10.8
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/commands.js +118 -75
- package/dist/cjs/configs/editor-plugins.js +5 -5
- package/dist/cjs/index.js +6 -3
- package/dist/cjs/lib/context-menu.js +4 -16
- package/dist/cjs/menus.js +2 -2
- package/dist/cjs/plugins/comment_annotation.js +191 -0
- package/dist/cjs/plugins/highlight/findHighlightMarkers.js +26 -0
- package/dist/cjs/plugins/highlight/index.js +85 -0
- package/dist/cjs/plugins/highlight/types.js +2 -0
- package/dist/cjs/plugins/sections.js +4 -1
- package/dist/cjs/toolbar.js +1 -1
- package/dist/cjs/views/bibliography_element.js +41 -64
- package/dist/cjs/views/citation.js +6 -9
- package/dist/cjs/views/citation_editable.js +2 -2
- package/dist/cjs/views/contributors.js +6 -2
- package/dist/cjs/views/editable_block.js +2 -1
- package/dist/cjs/views/keyword_group.js +1 -0
- package/dist/es/commands.js +115 -74
- package/dist/es/configs/editor-plugins.js +5 -5
- package/dist/es/index.js +2 -2
- package/dist/es/lib/context-menu.js +5 -17
- package/dist/es/menus.js +3 -3
- package/dist/es/plugins/comment_annotation.js +184 -0
- package/dist/es/plugins/highlight/findHighlightMarkers.js +22 -0
- package/dist/es/plugins/highlight/index.js +79 -0
- package/dist/es/plugins/highlight/types.js +1 -0
- package/dist/es/plugins/sections.js +4 -1
- package/dist/es/toolbar.js +2 -2
- package/dist/es/views/bibliography_element.js +42 -65
- package/dist/es/views/citation.js +6 -9
- package/dist/es/views/citation_editable.js +3 -3
- package/dist/es/views/contributors.js +6 -2
- package/dist/es/views/editable_block.js +2 -1
- package/dist/es/views/keyword_group.js +1 -0
- package/dist/types/commands.d.ts +7 -3
- package/dist/types/configs/ManuscriptsEditor.d.ts +3 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/lib/context-menu.d.ts +2 -2
- package/dist/types/lib/references.d.ts +2 -3
- package/dist/types/plugins/comment_annotation.d.ts +14 -0
- package/dist/types/plugins/highlight/findHighlightMarkers.d.ts +3 -0
- package/dist/types/plugins/highlight/index.d.ts +26 -0
- package/dist/types/plugins/highlight/types.d.ts +18 -0
- package/dist/types/views/bibliography_element.d.ts +8 -3
- package/dist/types/views/citation_editable.d.ts +1 -1
- package/dist/types/views/editable_block.d.ts +2 -0
- package/dist/types/views/keyword_group.d.ts +1 -0
- package/package.json +6 -6
- package/styles/AdvancedEditor.css +54 -45
- package/dist/cjs/lib/comments.js +0 -49
- package/dist/cjs/plugins/comments.js +0 -209
- package/dist/cjs/plugins/editor-props.js +0 -22
- package/dist/es/lib/comments.js +0 -42
- package/dist/es/plugins/comments.js +0 -204
- package/dist/es/plugins/editor-props.js +0 -18
- package/dist/types/lib/comments.d.ts +0 -33
- package/dist/types/plugins/comments.d.ts +0 -15
- package/dist/types/plugins/editor-props.d.ts +0 -7
package/dist/cjs/commands.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.insertTableFootnote = exports.
|
|
18
|
+
exports.insertTableFootnote = exports.updateCommentAnnotationState = exports.addComment = exports.deleteHighlightMarkers = exports.insertHighlight = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreMetaNodeBackspaceCommand = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.ifInTableBody = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertSection = exports.insertGraphicalAbstract = exports.insertInlineFootnote = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertFileAsFigure = exports.insertGeneralFootnote = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = void 0;
|
|
19
19
|
const json_schema_1 = require("@manuscripts/json-schema");
|
|
20
20
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
21
21
|
const transform_1 = require("@manuscripts/transform");
|
|
@@ -24,13 +24,12 @@ const prosemirror_schema_list_1 = require("prosemirror-schema-list");
|
|
|
24
24
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
25
25
|
const prosemirror_transform_1 = require("prosemirror-transform");
|
|
26
26
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
27
|
-
const comments_1 = require("./lib/comments");
|
|
28
27
|
const helpers_1 = require("./lib/helpers");
|
|
29
28
|
const track_changes_utils_1 = require("./lib/track-changes-utils");
|
|
30
29
|
const utils_1 = require("./lib/utils");
|
|
31
|
-
const
|
|
32
|
-
const editor_props_1 = require("./plugins/editor-props");
|
|
30
|
+
const comment_annotation_1 = require("./plugins/comment_annotation");
|
|
33
31
|
const footnotes_utils_1 = require("./plugins/footnotes/footnotes-utils");
|
|
32
|
+
const highlight_1 = require("./plugins/highlight");
|
|
34
33
|
const markActive = (type) => (state) => {
|
|
35
34
|
const { from, $from, to, empty } = state.selection;
|
|
36
35
|
return empty
|
|
@@ -660,6 +659,83 @@ const createAndFillFigcaptionElement = (state) => state.schema.nodes.figcaption.
|
|
|
660
659
|
state.schema.nodes.caption_title.create(),
|
|
661
660
|
state.schema.nodes.caption.create(),
|
|
662
661
|
]);
|
|
662
|
+
const insertHighlight = (state, comment, dispatch) => {
|
|
663
|
+
const { from, to } = state.selection;
|
|
664
|
+
const fromNode = state.schema.nodes.highlight_marker.create({
|
|
665
|
+
id: comment._id,
|
|
666
|
+
tid: comment.target,
|
|
667
|
+
position: 'start',
|
|
668
|
+
});
|
|
669
|
+
const toNode = state.schema.nodes.highlight_marker.create({
|
|
670
|
+
id: comment._id,
|
|
671
|
+
tid: comment.target,
|
|
672
|
+
position: 'end',
|
|
673
|
+
});
|
|
674
|
+
const tr = state.tr
|
|
675
|
+
.insert(from, fromNode)
|
|
676
|
+
.insert(to + 1, toNode)
|
|
677
|
+
.setMeta(highlight_1.highlightKey, {
|
|
678
|
+
[highlight_1.SET_COMMENT]: Object.assign(Object.assign({}, comment), { selector: { from, to }, originalText: state.tr.doc.textBetween(from, to, '\n') }),
|
|
679
|
+
});
|
|
680
|
+
tr.setMeta('addToHistory', false);
|
|
681
|
+
if (dispatch) {
|
|
682
|
+
dispatch(tr);
|
|
683
|
+
}
|
|
684
|
+
return true;
|
|
685
|
+
};
|
|
686
|
+
exports.insertHighlight = insertHighlight;
|
|
687
|
+
const deleteHighlightMarkers = (rid) => (state, dispatch) => {
|
|
688
|
+
var _a;
|
|
689
|
+
const markersToDelete = [];
|
|
690
|
+
(_a = highlight_1.highlightKey.getState(state)) === null || _a === void 0 ? void 0 : _a.highlights.forEach((highlight) => {
|
|
691
|
+
if (highlight.id === rid) {
|
|
692
|
+
markersToDelete.push(highlight.start - 1);
|
|
693
|
+
markersToDelete.push(highlight.end);
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
if (markersToDelete.length === 0) {
|
|
697
|
+
return false;
|
|
698
|
+
}
|
|
699
|
+
const { tr } = state;
|
|
700
|
+
markersToDelete
|
|
701
|
+
.sort((a, b) => b - a)
|
|
702
|
+
.forEach((pos) => {
|
|
703
|
+
tr.delete(pos, pos + 1);
|
|
704
|
+
});
|
|
705
|
+
tr.setMeta('track-changes-skip-tracking', true);
|
|
706
|
+
dispatch && dispatch(tr);
|
|
707
|
+
return true;
|
|
708
|
+
};
|
|
709
|
+
exports.deleteHighlightMarkers = deleteHighlightMarkers;
|
|
710
|
+
function addComment(state, dispatch, viewNode, resolvePos) {
|
|
711
|
+
const { selection } = state;
|
|
712
|
+
const hasText = selection.content().size > 0;
|
|
713
|
+
const parent = getParentNode(selection);
|
|
714
|
+
if (!parent) {
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
717
|
+
if (viewNode && resolvePos) {
|
|
718
|
+
const viewNode = getParentNode(prosemirror_state_1.TextSelection.near(resolvePos));
|
|
719
|
+
if (!viewNode) {
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
if (hasText && parent.attrs.id === viewNode.attrs.id) {
|
|
723
|
+
return addHighlightComment(viewNode, state, dispatch);
|
|
724
|
+
}
|
|
725
|
+
else {
|
|
726
|
+
return addBlockComment(viewNode, state, dispatch);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
if (hasText) {
|
|
731
|
+
return addHighlightComment(parent, state, dispatch);
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
return addBlockComment(parent, state, dispatch);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
exports.addComment = addComment;
|
|
663
739
|
const getParentNode = (selection) => {
|
|
664
740
|
var _a;
|
|
665
741
|
const parentNode = (0, utils_1.findParentNodeWithId)(selection);
|
|
@@ -669,94 +745,61 @@ const getParentNode = (selection) => {
|
|
|
669
745
|
}
|
|
670
746
|
return node;
|
|
671
747
|
};
|
|
672
|
-
const
|
|
673
|
-
type === transform_1.schema.nodes.citation ||
|
|
674
|
-
type === transform_1.schema.nodes.bibliography_item ||
|
|
748
|
+
const isAllowedType = (type) => type === transform_1.schema.nodes.section ||
|
|
675
749
|
type === transform_1.schema.nodes.footnotes_section ||
|
|
676
750
|
type === transform_1.schema.nodes.bibliography_section ||
|
|
677
751
|
type === transform_1.schema.nodes.keyword_group ||
|
|
678
752
|
type === transform_1.schema.nodes.paragraph ||
|
|
679
753
|
type === transform_1.schema.nodes.figure_element ||
|
|
680
754
|
type === transform_1.schema.nodes.table_element;
|
|
681
|
-
const
|
|
682
|
-
if (
|
|
683
|
-
|
|
755
|
+
const getNode = (node) => {
|
|
756
|
+
if (node.type === transform_1.schema.nodes.keywords) {
|
|
757
|
+
const keywordGroups = (0, prosemirror_utils_1.findChildrenByType)(node, transform_1.schema.nodes.keyword_group, true);
|
|
758
|
+
return keywordGroups.length ? keywordGroups[0].node : node;
|
|
684
759
|
}
|
|
685
|
-
|
|
686
|
-
const contribution = (0, json_schema_1.buildContribution)(props.userID);
|
|
687
|
-
const attrs = {
|
|
688
|
-
id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.CommentAnnotation),
|
|
689
|
-
contents: '',
|
|
690
|
-
target: node.attrs.id,
|
|
691
|
-
contributions: [contribution],
|
|
692
|
-
};
|
|
693
|
-
const comment = transform_1.schema.nodes.comment.create(attrs);
|
|
694
|
-
const comments = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.comments)[0];
|
|
695
|
-
const pos = comments.pos + 1;
|
|
696
|
-
const tr = state.tr.insert(pos, comment);
|
|
697
|
-
const key = (0, comments_1.getCommentKey)(attrs, undefined, node);
|
|
698
|
-
(0, comments_2.setCommentSelection)(tr, key, attrs.id, true);
|
|
699
|
-
if (dispatch) {
|
|
700
|
-
dispatch(tr);
|
|
701
|
-
}
|
|
702
|
-
return true;
|
|
760
|
+
return node;
|
|
703
761
|
};
|
|
704
|
-
|
|
705
|
-
const
|
|
706
|
-
const
|
|
707
|
-
const
|
|
708
|
-
|
|
762
|
+
const addBlockComment = (node, state, dispatch) => {
|
|
763
|
+
const { attrs: { id }, type, } = getNode(node);
|
|
764
|
+
const comment = (0, transform_1.buildComment)(id);
|
|
765
|
+
const tr = state.tr.setMeta(comment_annotation_1.commentAnnotation, {
|
|
766
|
+
[highlight_1.SET_COMMENT]: comment,
|
|
767
|
+
});
|
|
768
|
+
tr.setMeta('addToHistory', false);
|
|
769
|
+
if (isAllowedType(type)) {
|
|
770
|
+
dispatch && dispatch(tr);
|
|
771
|
+
return true;
|
|
772
|
+
}
|
|
773
|
+
else {
|
|
709
774
|
return false;
|
|
710
775
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
const
|
|
714
|
-
const
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
|
-
const comment = transform_1.schema.nodes.comment.create(attrs);
|
|
727
|
-
const comments = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.comments)[0];
|
|
728
|
-
const pos = comments.pos + 1;
|
|
729
|
-
const tr = state.tr.insert(pos, comment);
|
|
730
|
-
if (from === to) {
|
|
731
|
-
const point = transform_1.schema.nodes.highlight_marker.create({
|
|
732
|
-
id: comment.attrs.id,
|
|
733
|
-
tid: node.attrs.id,
|
|
734
|
-
position: 'point',
|
|
735
|
-
});
|
|
736
|
-
tr.insert(from, point);
|
|
776
|
+
};
|
|
777
|
+
const addHighlightComment = (node, state, dispatch) => {
|
|
778
|
+
const { attrs: { id }, type, } = node;
|
|
779
|
+
const comment = (0, transform_1.buildComment)(id);
|
|
780
|
+
if (type === transform_1.schema.nodes.paragraph) {
|
|
781
|
+
const { $anchor, $head } = state.selection;
|
|
782
|
+
const isAllTextSelected = ($anchor.textOffset === 0 && $head.textOffset === 0) ||
|
|
783
|
+
$anchor.textOffset === $head.textOffset;
|
|
784
|
+
if (isAllTextSelected) {
|
|
785
|
+
return addBlockComment(node, state, dispatch);
|
|
786
|
+
}
|
|
787
|
+
else {
|
|
788
|
+
return (0, exports.insertHighlight)(state, comment, dispatch);
|
|
789
|
+
}
|
|
737
790
|
}
|
|
738
791
|
else {
|
|
739
|
-
|
|
740
|
-
id: comment.attrs.id,
|
|
741
|
-
tid: node.attrs.id,
|
|
742
|
-
position: 'start',
|
|
743
|
-
});
|
|
744
|
-
const end = transform_1.schema.nodes.highlight_marker.create({
|
|
745
|
-
id: comment.attrs.id,
|
|
746
|
-
tid: node.attrs.id,
|
|
747
|
-
position: 'end',
|
|
748
|
-
});
|
|
749
|
-
tr.insert(from, start).insert(to + 1, end);
|
|
792
|
+
return (0, exports.insertHighlight)(state, comment, dispatch);
|
|
750
793
|
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
794
|
+
};
|
|
795
|
+
const updateCommentAnnotationState = (state, dispatch) => {
|
|
796
|
+
const tr = state.tr.setMeta(comment_annotation_1.commentAnnotation, {});
|
|
797
|
+
tr.setMeta('addToHistory', false);
|
|
754
798
|
if (dispatch) {
|
|
755
799
|
dispatch(tr);
|
|
756
800
|
}
|
|
757
|
-
return true;
|
|
758
801
|
};
|
|
759
|
-
exports.
|
|
802
|
+
exports.updateCommentAnnotationState = updateCommentAnnotationState;
|
|
760
803
|
const insertTableFootnote = (node, position, view, inlineFootnote) => {
|
|
761
804
|
var _a;
|
|
762
805
|
const { state, dispatch } = view;
|
|
@@ -28,10 +28,10 @@ const prosemirror_tables_1 = require("prosemirror-tables");
|
|
|
28
28
|
const keys_1 = __importDefault(require("../keys"));
|
|
29
29
|
const affiliations_1 = __importDefault(require("../plugins/affiliations"));
|
|
30
30
|
const bibliography_1 = __importDefault(require("../plugins/bibliography"));
|
|
31
|
-
const
|
|
32
|
-
const editor_props_1 = __importDefault(require("../plugins/editor-props"));
|
|
31
|
+
const comment_annotation_1 = __importDefault(require("../plugins/comment_annotation"));
|
|
33
32
|
const elements_1 = __importDefault(require("../plugins/elements"));
|
|
34
33
|
const footnotes_1 = __importDefault(require("../plugins/footnotes"));
|
|
34
|
+
const highlight_1 = __importDefault(require("../plugins/highlight"));
|
|
35
35
|
const objects_1 = __importDefault(require("../plugins/objects"));
|
|
36
36
|
const paragraphs_1 = __importDefault(require("../plugins/paragraphs"));
|
|
37
37
|
const persist_1 = __importDefault(require("../plugins/persist"));
|
|
@@ -63,14 +63,14 @@ exports.default = (props) => {
|
|
|
63
63
|
(0, bibliography_1.default)(props),
|
|
64
64
|
(0, objects_1.default)(props),
|
|
65
65
|
(0, affiliations_1.default)(),
|
|
66
|
-
(0,
|
|
66
|
+
(0, comment_annotation_1.default)(props),
|
|
67
67
|
(0, paragraphs_1.default)(),
|
|
68
68
|
(0, placeholder_1.default)(),
|
|
69
69
|
(0, prosemirror_tables_1.tableEditing)(),
|
|
70
|
-
(0,
|
|
70
|
+
(0, highlight_1.default)(props),
|
|
71
71
|
(0, footnotes_1.default)(props),
|
|
72
72
|
(0, table_footnote_1.default)(),
|
|
73
|
-
(0,
|
|
73
|
+
(0, selected_suggestion_1.default)(),
|
|
74
74
|
];
|
|
75
75
|
if (props.collabProvider) {
|
|
76
76
|
allPlugins.push((0, prosemirror_collab_1.collab)({ version: props.collabProvider.currentVersion }));
|
package/dist/cjs/index.js
CHANGED
|
@@ -29,7 +29,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
29
29
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.selectedSuggestionKey = exports.PopperManager = exports.CollabProvider = exports.LevelSelector = exports.OutlineItemIcon = exports.ManuscriptOutline = void 0;
|
|
32
|
+
exports.isHighlightComment = exports.isThereSelector = exports.commentScroll = exports.selectedSuggestionKey = exports.PopperManager = exports.CollabProvider = exports.LevelSelector = exports.OutlineItemIcon = exports.ManuscriptOutline = void 0;
|
|
33
33
|
__exportStar(require("./commands"), exports);
|
|
34
34
|
var ManuscriptOutline_1 = require("./components/outline/ManuscriptOutline");
|
|
35
35
|
Object.defineProperty(exports, "ManuscriptOutline", { enumerable: true, get: function () { return ManuscriptOutline_1.ManuscriptOutline; } });
|
|
@@ -43,10 +43,13 @@ Object.defineProperty(exports, "CollabProvider", { enumerable: true, get: functi
|
|
|
43
43
|
var popper_1 = require("./lib/popper");
|
|
44
44
|
Object.defineProperty(exports, "PopperManager", { enumerable: true, get: function () { return popper_1.PopperManager; } });
|
|
45
45
|
__exportStar(require("./toolbar"), exports);
|
|
46
|
-
__exportStar(require("./lib/comments"), exports);
|
|
47
|
-
__exportStar(require("./plugins/comments"), exports);
|
|
48
46
|
var selected_suggestion_1 = require("./plugins/selected-suggestion");
|
|
49
47
|
Object.defineProperty(exports, "selectedSuggestionKey", { enumerable: true, get: function () { return selected_suggestion_1.selectedSuggestionKey; } });
|
|
48
|
+
__exportStar(require("./plugins/highlight"), exports);
|
|
49
|
+
var comment_annotation_1 = require("./plugins/comment_annotation");
|
|
50
|
+
Object.defineProperty(exports, "commentScroll", { enumerable: true, get: function () { return comment_annotation_1.commentScroll; } });
|
|
51
|
+
Object.defineProperty(exports, "isThereSelector", { enumerable: true, get: function () { return comment_annotation_1.isThereSelector; } });
|
|
52
|
+
Object.defineProperty(exports, "isHighlightComment", { enumerable: true, get: function () { return comment_annotation_1.isHighlightComment; } });
|
|
50
53
|
__exportStar(require("./lib/utils"), exports);
|
|
51
54
|
__exportStar(require("./lib/track-changes-utils"), exports);
|
|
52
55
|
__exportStar(require("./useEditor"), exports);
|
|
@@ -164,12 +164,12 @@ class ContextMenu {
|
|
|
164
164
|
}
|
|
165
165
|
}));
|
|
166
166
|
}
|
|
167
|
-
const {
|
|
168
|
-
if (
|
|
167
|
+
const { setComment } = this.actions;
|
|
168
|
+
if (setComment) {
|
|
169
169
|
menu.appendChild(this.createMenuSection((section) => {
|
|
170
170
|
section.appendChild(this.createMenuItem('Comment', () => {
|
|
171
|
-
const
|
|
172
|
-
(0, commands_1.
|
|
171
|
+
const { state, dispatch } = this.view;
|
|
172
|
+
(0, commands_1.addComment)(state, dispatch, this.node, this.resolvePos());
|
|
173
173
|
popper.destroy();
|
|
174
174
|
}));
|
|
175
175
|
}));
|
|
@@ -378,18 +378,6 @@ class ContextMenu {
|
|
|
378
378
|
this.trimTitle = (title, max) => {
|
|
379
379
|
return title.length > max ? title.substring(0, max) + '…' : title;
|
|
380
380
|
};
|
|
381
|
-
this.getCommentTarget = () => {
|
|
382
|
-
if (this.node.type === transform_1.schema.nodes.section_title) {
|
|
383
|
-
const $pos = this.resolvePos();
|
|
384
|
-
const parent = $pos.parent;
|
|
385
|
-
if (parent.type === transform_1.schema.nodes.keywords) {
|
|
386
|
-
const groups = (0, prosemirror_utils_1.findChildrenByType)(parent, transform_1.schema.nodes.keyword_group);
|
|
387
|
-
return groups.length ? groups[0].node : this.node;
|
|
388
|
-
}
|
|
389
|
-
return parent;
|
|
390
|
-
}
|
|
391
|
-
return this.node;
|
|
392
|
-
};
|
|
393
381
|
this.node = node;
|
|
394
382
|
this.view = view;
|
|
395
383
|
this.getPos = getPos;
|
package/dist/cjs/menus.js
CHANGED
|
@@ -215,8 +215,8 @@ const getEditorMenus = (editor) => {
|
|
|
215
215
|
{
|
|
216
216
|
id: 'insert-comment',
|
|
217
217
|
label: 'Comment',
|
|
218
|
-
isEnabled: isCommandValid(commands_1.
|
|
219
|
-
run: doCommand(commands_1.
|
|
218
|
+
isEnabled: isCommandValid(commands_1.addComment),
|
|
219
|
+
run: doCommand(commands_1.addComment),
|
|
220
220
|
},
|
|
221
221
|
],
|
|
222
222
|
};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addCommentToLeafNode = exports.isHighlightComment = exports.isThereSelector = exports.commentScroll = exports.commentAnnotation = void 0;
|
|
4
|
+
const transform_1 = require("@manuscripts/transform");
|
|
5
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
6
|
+
const prosemirror_transform_1 = require("prosemirror-transform");
|
|
7
|
+
const prosemirror_view_1 = require("prosemirror-view");
|
|
8
|
+
const highlight_1 = require("./highlight");
|
|
9
|
+
exports.commentAnnotation = new prosemirror_state_1.PluginKey('comment_annotation');
|
|
10
|
+
const commentScroll = (id, direction, isHighlight) => {
|
|
11
|
+
const elementClass = isHighlight ? 'highlight-marker' : 'block-comment-button';
|
|
12
|
+
const commentIcon = document.querySelector(`[id="${id}"].${elementClass}`);
|
|
13
|
+
const commentCard = document.querySelectorAll(`.comments-group [id="${id}"]`);
|
|
14
|
+
if (commentIcon && commentCard.length > 0) {
|
|
15
|
+
const element = direction === 'editor' ? commentIcon : commentCard.item(0);
|
|
16
|
+
document
|
|
17
|
+
.querySelectorAll(`.selected-comment`)
|
|
18
|
+
.forEach((element) => element.classList.remove('selected-comment'));
|
|
19
|
+
commentIcon.classList.add('selected-comment');
|
|
20
|
+
commentCard.forEach((node) => node.classList.add('selected-comment'));
|
|
21
|
+
element === null || element === void 0 ? void 0 : element.scrollIntoView({
|
|
22
|
+
behavior: 'auto',
|
|
23
|
+
block: 'start',
|
|
24
|
+
inline: 'start',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.commentScroll = commentScroll;
|
|
29
|
+
const isThereSelector = (selector) => !!(selector && Object.keys(selector).length);
|
|
30
|
+
exports.isThereSelector = isThereSelector;
|
|
31
|
+
const isHighlightComment = (comment) => comment.selector &&
|
|
32
|
+
(0, exports.isThereSelector)(comment.selector) &&
|
|
33
|
+
comment.selector.from !== comment.selector.to;
|
|
34
|
+
exports.isHighlightComment = isHighlightComment;
|
|
35
|
+
exports.default = (props) => {
|
|
36
|
+
return new prosemirror_state_1.Plugin({
|
|
37
|
+
key: exports.commentAnnotation,
|
|
38
|
+
state: {
|
|
39
|
+
init: (tr) => {
|
|
40
|
+
if (tr.doc) {
|
|
41
|
+
return commentsState(props.setSelectedComment, tr.doc);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return new prosemirror_view_1.DecorationSet();
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
apply: (tr, value, oldState, newState) => {
|
|
48
|
+
const meta = tr.getMeta(exports.commentAnnotation);
|
|
49
|
+
if (meta) {
|
|
50
|
+
if (highlight_1.SET_COMMENT in meta) {
|
|
51
|
+
props.setComment(meta[highlight_1.SET_COMMENT]);
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const hasCommentChange = !!tr.steps.find((s) => {
|
|
56
|
+
var _a, _b, _c, _d;
|
|
57
|
+
if (s instanceof prosemirror_transform_1.ReplaceStep) {
|
|
58
|
+
if (s.slice.size > 0) {
|
|
59
|
+
return (((_a = newState.doc.nodeAt(s.from + 1)) === null || _a === void 0 ? void 0 : _a.type) ===
|
|
60
|
+
transform_1.schema.nodes.comment ||
|
|
61
|
+
((_b = newState.doc.nodeAt(s.from)) === null || _b === void 0 ? void 0 : _b.type) ===
|
|
62
|
+
transform_1.schema.nodes.highlight_marker);
|
|
63
|
+
}
|
|
64
|
+
return (((_c = oldState.doc.nodeAt(s.from)) === null || _c === void 0 ? void 0 : _c.type) === transform_1.schema.nodes.comment ||
|
|
65
|
+
((_d = oldState.doc.nodeAt(s.from)) === null || _d === void 0 ? void 0 : _d.type) ===
|
|
66
|
+
transform_1.schema.nodes.highlight_marker);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
if (hasCommentChange) {
|
|
70
|
+
return commentsState(props.setSelectedComment, tr.doc);
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
props: {
|
|
76
|
+
decorations: (state) => {
|
|
77
|
+
const pluginState = exports.commentAnnotation.getState(state);
|
|
78
|
+
if (pluginState) {
|
|
79
|
+
return pluginState;
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
const getNodePosition = (node, pos) => {
|
|
86
|
+
switch (node.type) {
|
|
87
|
+
case transform_1.schema.nodes.keywords:
|
|
88
|
+
return pos + 2;
|
|
89
|
+
default:
|
|
90
|
+
return pos + 1;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const commentsState = (setSelectedComment, doc) => {
|
|
94
|
+
const comments = [];
|
|
95
|
+
doc.descendants((node) => {
|
|
96
|
+
if (node.type === transform_1.schema.nodes.comments) {
|
|
97
|
+
node.descendants((comment) => {
|
|
98
|
+
comments.push(comment.attrs);
|
|
99
|
+
});
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
const commentsMap = comments.reduce((map, { id, target, selector }) => {
|
|
104
|
+
var _a;
|
|
105
|
+
if (!(0, exports.isHighlightComment)({ selector })) {
|
|
106
|
+
const commentId = (0, exports.isThereSelector)(selector) ? id : target;
|
|
107
|
+
map.set(commentId, {
|
|
108
|
+
id,
|
|
109
|
+
target,
|
|
110
|
+
location: (0, exports.isThereSelector)(selector) ? 'point' : 'block',
|
|
111
|
+
count: (((_a = map.get(commentId)) === null || _a === void 0 ? void 0 : _a.count) || 0) + 1,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return map;
|
|
115
|
+
}, new Map());
|
|
116
|
+
const decorations = [];
|
|
117
|
+
doc.descendants((node, pos) => {
|
|
118
|
+
const id = node.attrs['id'] || node.attrs['rid'];
|
|
119
|
+
const targetComment = commentsMap.get(id);
|
|
120
|
+
if (targetComment) {
|
|
121
|
+
if (node.isAtom && node.type !== transform_1.schema.nodes.highlight_marker) {
|
|
122
|
+
decorations.push(prosemirror_view_1.Decoration.inline(pos, pos + node.nodeSize, {}, {
|
|
123
|
+
toDOM: getCommentIcon(Object.assign(Object.assign({}, targetComment), { targetType: node.type, isAtom: node.isAtom }), setSelectedComment),
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
const position = getNodePosition(node, pos);
|
|
128
|
+
decorations.push(prosemirror_view_1.Decoration.widget(position, getCommentIcon(Object.assign(Object.assign({}, targetComment), { targetType: node.type }), setSelectedComment), { key: targetComment.id }));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return prosemirror_view_1.DecorationSet.create(doc, decorations);
|
|
133
|
+
};
|
|
134
|
+
const getCommentIcon = (comment, setSelectedComment) => () => {
|
|
135
|
+
const { id, targetType, target, count, location, isAtom } = comment;
|
|
136
|
+
const commentId = location === 'block' ? target : id;
|
|
137
|
+
const element = document.createElement(isAtom ? 'span' : 'div');
|
|
138
|
+
element.id = commentId;
|
|
139
|
+
let elementClass;
|
|
140
|
+
switch (targetType) {
|
|
141
|
+
case transform_1.schema.nodes.section:
|
|
142
|
+
case transform_1.schema.nodes.footnotes_section:
|
|
143
|
+
case transform_1.schema.nodes.bibliography_section:
|
|
144
|
+
elementClass = 'block-comment';
|
|
145
|
+
break;
|
|
146
|
+
case transform_1.schema.nodes.figure_element:
|
|
147
|
+
elementClass = 'figure-comment';
|
|
148
|
+
break;
|
|
149
|
+
case transform_1.schema.nodes.bibliography_item:
|
|
150
|
+
elementClass = 'bibliography-comment';
|
|
151
|
+
break;
|
|
152
|
+
default:
|
|
153
|
+
elementClass = 'inline-comment';
|
|
154
|
+
}
|
|
155
|
+
if (isAtom || location === 'point') {
|
|
156
|
+
element.classList.add('point-comment');
|
|
157
|
+
}
|
|
158
|
+
element.classList.add('block-comment-button', elementClass);
|
|
159
|
+
element.onclick = (e) => {
|
|
160
|
+
e.stopPropagation();
|
|
161
|
+
setSelectedComment(commentId);
|
|
162
|
+
(0, exports.commentScroll)(commentId, 'inspector');
|
|
163
|
+
};
|
|
164
|
+
const groupCommentIcon = (count > 1 &&
|
|
165
|
+
` <svg class="group-comment-icon" width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
166
|
+
<rect width="12" height="12" rx="6" fill="#F7B314"></rect>
|
|
167
|
+
<text x="6" y="8" fill="#FFF" font-size="9px" text-anchor="middle" font-weight="400">${count}</text>
|
|
168
|
+
</svg>`) ||
|
|
169
|
+
'';
|
|
170
|
+
element.innerHTML = `
|
|
171
|
+
<svg class="comment-icon" width="16" height="13" viewBox="0 0 16 13" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
172
|
+
<path d="M4.0625 2.9375V7.3125L1.4375 11.6875H12.8125C13.7794 11.6875 14.5625 10.9044 14.5625 9.9375V2.9375C14.5625 1.97062 13.7794 1.1875 12.8125 1.1875H5.8125C4.84562 1.1875 4.0625 1.97062 4.0625 2.9375Z"
|
|
173
|
+
fill="#FFFCDB" stroke="#FFBD26" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
|
174
|
+
<path d="M6.6875 4.6875H11.9375" stroke="#FFBD26" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
|
175
|
+
<path d="M6.6875 8.1875H9.3125" stroke="#FFBD26" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
|
176
|
+
</svg>
|
|
177
|
+
${groupCommentIcon}
|
|
178
|
+
`;
|
|
179
|
+
return element;
|
|
180
|
+
};
|
|
181
|
+
const addCommentToLeafNode = (from, to, state, dom) => {
|
|
182
|
+
const commentsDecorationSet = exports.commentAnnotation.getState(state);
|
|
183
|
+
if (commentsDecorationSet) {
|
|
184
|
+
const commentWidget = commentsDecorationSet.find(from, to);
|
|
185
|
+
if (commentWidget.length) {
|
|
186
|
+
const commentElement = commentWidget[0].type.spec.toDOM();
|
|
187
|
+
dom.appendChild(commentElement);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
exports.addCommentToLeafNode = addCommentToLeafNode;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findHighlightMarkers = void 0;
|
|
4
|
+
const transform_1 = require("@manuscripts/transform");
|
|
5
|
+
function findHighlightMarkers(doc) {
|
|
6
|
+
const markers = [];
|
|
7
|
+
let current;
|
|
8
|
+
doc.descendants((node, pos) => {
|
|
9
|
+
if ((0, transform_1.isHighlightMarkerNode)(node)) {
|
|
10
|
+
const { position, tid, id } = node.attrs;
|
|
11
|
+
if (position === 'start') {
|
|
12
|
+
current = {
|
|
13
|
+
start: pos + 1,
|
|
14
|
+
id,
|
|
15
|
+
tid,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
else if (position === 'end' && current) {
|
|
19
|
+
markers.push(Object.assign(Object.assign({}, current), { text: doc.textBetween(current.start, pos, '\n'), end: pos }));
|
|
20
|
+
current = undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return markers;
|
|
25
|
+
}
|
|
26
|
+
exports.findHighlightMarkers = findHighlightMarkers;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2019 Atypon Systems LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.selectedHighlights = exports.getHighlightTarget = exports.hasHighlightTarget = exports.SET_COMMENT = exports.highlightKey = void 0;
|
|
19
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
20
|
+
const prosemirror_view_1 = require("prosemirror-view");
|
|
21
|
+
const findHighlightMarkers_1 = require("./findHighlightMarkers");
|
|
22
|
+
exports.highlightKey = new prosemirror_state_1.PluginKey('highlight');
|
|
23
|
+
exports.SET_COMMENT = 'SET_COMMENT';
|
|
24
|
+
const hasHighlightTarget = (comment) => comment.target.startsWith('MPHighlight:');
|
|
25
|
+
exports.hasHighlightTarget = hasHighlightTarget;
|
|
26
|
+
const getHighlightTarget = (comment, state) => {
|
|
27
|
+
var _a;
|
|
28
|
+
return (_a = exports.highlightKey
|
|
29
|
+
.getState(state)) === null || _a === void 0 ? void 0 : _a.highlights.find((item) => item.id === comment._id);
|
|
30
|
+
};
|
|
31
|
+
exports.getHighlightTarget = getHighlightTarget;
|
|
32
|
+
const selectedHighlights = (state) => {
|
|
33
|
+
var _a;
|
|
34
|
+
const items = [];
|
|
35
|
+
const { selection } = state;
|
|
36
|
+
if (!(selection instanceof prosemirror_state_1.TextSelection)) {
|
|
37
|
+
return items;
|
|
38
|
+
}
|
|
39
|
+
const { $cursor } = selection;
|
|
40
|
+
if (!$cursor) {
|
|
41
|
+
return items;
|
|
42
|
+
}
|
|
43
|
+
const { pos } = $cursor;
|
|
44
|
+
(_a = exports.highlightKey.getState(state)) === null || _a === void 0 ? void 0 : _a.highlights.forEach((highlight) => {
|
|
45
|
+
if (highlight.start <= pos && highlight.end >= pos) {
|
|
46
|
+
items.push(highlight);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return items;
|
|
50
|
+
};
|
|
51
|
+
exports.selectedHighlights = selectedHighlights;
|
|
52
|
+
const buildPluginState = (doc) => {
|
|
53
|
+
const highlights = (0, findHighlightMarkers_1.findHighlightMarkers)(doc);
|
|
54
|
+
const decorations = prosemirror_view_1.DecorationSet.create(doc, highlights.map((h) => prosemirror_view_1.Decoration.inline(h.start, h.end, {
|
|
55
|
+
nodeName: 'span',
|
|
56
|
+
class: 'highlight',
|
|
57
|
+
})));
|
|
58
|
+
return { highlights, decorations };
|
|
59
|
+
};
|
|
60
|
+
exports.default = (props) => {
|
|
61
|
+
return new prosemirror_state_1.Plugin({
|
|
62
|
+
key: exports.highlightKey,
|
|
63
|
+
state: {
|
|
64
|
+
init: (tr, state) => buildPluginState(state.doc),
|
|
65
|
+
apply: (tr, value) => {
|
|
66
|
+
const meta = tr.getMeta(exports.highlightKey);
|
|
67
|
+
if (meta && exports.SET_COMMENT in meta) {
|
|
68
|
+
props.setComment(meta[exports.SET_COMMENT]);
|
|
69
|
+
}
|
|
70
|
+
else if (!tr.docChanged || tr.step.length === 0) {
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
return buildPluginState(tr.doc);
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
props: {
|
|
77
|
+
decorations: (state) => {
|
|
78
|
+
const pluginState = exports.highlightKey.getState(state);
|
|
79
|
+
if (pluginState) {
|
|
80
|
+
return pluginState.decorations;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
};
|