@manuscripts/body-editor 1.10.11-LEAN-3651.0 → 1.11.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/commands.js +75 -118
- package/dist/cjs/configs/ManuscriptsEditor.js +0 -2
- package/dist/cjs/configs/editor-plugins.js +5 -5
- package/dist/cjs/index.js +3 -6
- package/dist/cjs/lib/comments.js +49 -0
- package/dist/cjs/lib/context-menu.js +16 -4
- package/dist/cjs/menus.js +2 -2
- package/dist/cjs/plugins/comments.js +209 -0
- package/dist/cjs/plugins/editor-props.js +22 -0
- package/dist/cjs/plugins/sections.js +1 -4
- package/dist/cjs/toolbar.js +1 -1
- package/dist/cjs/views/bibliography_element.js +64 -41
- package/dist/cjs/views/citation.js +9 -6
- package/dist/cjs/views/citation_editable.js +2 -2
- package/dist/cjs/views/contributors.js +2 -6
- package/dist/cjs/views/editable_block.js +1 -2
- package/dist/cjs/views/keyword_group.js +0 -1
- package/dist/es/commands.js +74 -115
- package/dist/es/configs/ManuscriptsEditor.js +0 -2
- package/dist/es/configs/editor-plugins.js +5 -5
- package/dist/es/index.js +2 -2
- package/dist/es/lib/comments.js +42 -0
- package/dist/es/lib/context-menu.js +17 -5
- package/dist/es/menus.js +3 -3
- package/dist/es/plugins/comments.js +204 -0
- package/dist/es/plugins/editor-props.js +18 -0
- package/dist/es/plugins/sections.js +1 -4
- package/dist/es/toolbar.js +2 -2
- package/dist/es/views/bibliography_element.js +65 -42
- package/dist/es/views/citation.js +9 -6
- package/dist/es/views/citation_editable.js +3 -3
- package/dist/es/views/contributors.js +2 -6
- package/dist/es/views/editable_block.js +1 -2
- package/dist/es/views/keyword_group.js +0 -1
- package/dist/types/commands.d.ts +3 -7
- package/dist/types/configs/ManuscriptsEditor.d.ts +1 -3
- package/dist/types/index.d.ts +2 -2
- package/dist/types/lib/comments.d.ts +33 -0
- package/dist/types/lib/context-menu.d.ts +2 -2
- package/dist/types/lib/references.d.ts +3 -2
- package/dist/types/plugins/comments.d.ts +15 -0
- package/dist/types/plugins/editor-props.d.ts +7 -0
- package/dist/types/views/bibliography_element.d.ts +3 -8
- package/dist/types/views/citation_editable.d.ts +1 -1
- package/dist/types/views/editable_block.d.ts +0 -2
- package/dist/types/views/keyword_group.d.ts +0 -1
- package/package.json +2 -2
- package/styles/AdvancedEditor.css +45 -54
- package/dist/cjs/clipboard.js +0 -19
- package/dist/cjs/plugins/comment_annotation.js +0 -191
- package/dist/cjs/plugins/highlight/findHighlightMarkers.js +0 -26
- package/dist/cjs/plugins/highlight/index.js +0 -85
- package/dist/cjs/plugins/highlight/types.js +0 -2
- package/dist/es/clipboard.js +0 -16
- package/dist/es/plugins/comment_annotation.js +0 -184
- package/dist/es/plugins/highlight/findHighlightMarkers.js +0 -22
- package/dist/es/plugins/highlight/index.js +0 -79
- package/dist/es/plugins/highlight/types.js +0 -1
- package/dist/types/clipboard.d.ts +0 -2
- package/dist/types/plugins/comment_annotation.d.ts +0 -14
- package/dist/types/plugins/highlight/findHighlightMarkers.d.ts +0 -3
- package/dist/types/plugins/highlight/index.d.ts +0 -26
- package/dist/types/plugins/highlight/types.d.ts +0 -18
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.addInlineComment = exports.addNodeComment = 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,12 +24,13 @@ 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");
|
|
27
28
|
const helpers_1 = require("./lib/helpers");
|
|
28
29
|
const track_changes_utils_1 = require("./lib/track-changes-utils");
|
|
29
30
|
const utils_1 = require("./lib/utils");
|
|
30
|
-
const
|
|
31
|
+
const comments_2 = require("./plugins/comments");
|
|
32
|
+
const editor_props_1 = require("./plugins/editor-props");
|
|
31
33
|
const footnotes_utils_1 = require("./plugins/footnotes/footnotes-utils");
|
|
32
|
-
const highlight_1 = require("./plugins/highlight");
|
|
33
34
|
const markActive = (type) => (state) => {
|
|
34
35
|
const { from, $from, to, empty } = state.selection;
|
|
35
36
|
return empty
|
|
@@ -659,83 +660,6 @@ const createAndFillFigcaptionElement = (state) => state.schema.nodes.figcaption.
|
|
|
659
660
|
state.schema.nodes.caption_title.create(),
|
|
660
661
|
state.schema.nodes.caption.create(),
|
|
661
662
|
]);
|
|
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;
|
|
739
663
|
const getParentNode = (selection) => {
|
|
740
664
|
var _a;
|
|
741
665
|
const parentNode = (0, utils_1.findParentNodeWithId)(selection);
|
|
@@ -745,61 +669,94 @@ const getParentNode = (selection) => {
|
|
|
745
669
|
}
|
|
746
670
|
return node;
|
|
747
671
|
};
|
|
748
|
-
const
|
|
672
|
+
const isCommentingAllowed = (type) => type === transform_1.schema.nodes.section ||
|
|
673
|
+
type === transform_1.schema.nodes.citation ||
|
|
674
|
+
type === transform_1.schema.nodes.bibliography_item ||
|
|
749
675
|
type === transform_1.schema.nodes.footnotes_section ||
|
|
750
676
|
type === transform_1.schema.nodes.bibliography_section ||
|
|
751
677
|
type === transform_1.schema.nodes.keyword_group ||
|
|
752
678
|
type === transform_1.schema.nodes.paragraph ||
|
|
753
679
|
type === transform_1.schema.nodes.figure_element ||
|
|
754
680
|
type === transform_1.schema.nodes.table_element;
|
|
755
|
-
const
|
|
756
|
-
if (node.type
|
|
757
|
-
|
|
758
|
-
return keywordGroups.length ? keywordGroups[0].node : node;
|
|
681
|
+
const addNodeComment = (node, state, dispatch) => {
|
|
682
|
+
if (!isCommentingAllowed(node.type)) {
|
|
683
|
+
return false;
|
|
759
684
|
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
[
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
685
|
+
const props = (0, editor_props_1.getEditorProps)(state);
|
|
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);
|
|
772
701
|
}
|
|
773
|
-
|
|
702
|
+
return true;
|
|
703
|
+
};
|
|
704
|
+
exports.addNodeComment = addNodeComment;
|
|
705
|
+
const addInlineComment = (state, dispatch) => {
|
|
706
|
+
const selection = state.selection;
|
|
707
|
+
const node = getParentNode(selection);
|
|
708
|
+
if (!node || !isCommentingAllowed(node.type)) {
|
|
774
709
|
return false;
|
|
775
710
|
}
|
|
776
|
-
|
|
777
|
-
const
|
|
778
|
-
const
|
|
779
|
-
const
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
}
|
|
711
|
+
const from = selection.from;
|
|
712
|
+
const to = selection.to;
|
|
713
|
+
const props = (0, editor_props_1.getEditorProps)(state);
|
|
714
|
+
const contribution = (0, json_schema_1.buildContribution)(props.userID);
|
|
715
|
+
const attrs = {
|
|
716
|
+
id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.CommentAnnotation),
|
|
717
|
+
contents: '',
|
|
718
|
+
target: node.attrs.id,
|
|
719
|
+
contributions: [contribution],
|
|
720
|
+
originalText: selectedText(),
|
|
721
|
+
selector: {
|
|
722
|
+
from,
|
|
723
|
+
to,
|
|
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);
|
|
790
737
|
}
|
|
791
738
|
else {
|
|
792
|
-
|
|
739
|
+
const start = transform_1.schema.nodes.highlight_marker.create({
|
|
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);
|
|
793
750
|
}
|
|
794
|
-
|
|
795
|
-
const
|
|
796
|
-
|
|
797
|
-
tr.setMeta('addToHistory', false);
|
|
751
|
+
const range = (0, comments_1.getCommentRange)(attrs);
|
|
752
|
+
const key = (0, comments_1.getCommentKey)(attrs, range, node);
|
|
753
|
+
(0, comments_2.setCommentSelection)(tr, key, attrs.id, true);
|
|
798
754
|
if (dispatch) {
|
|
799
755
|
dispatch(tr);
|
|
800
756
|
}
|
|
757
|
+
return true;
|
|
801
758
|
};
|
|
802
|
-
exports.
|
|
759
|
+
exports.addInlineComment = addInlineComment;
|
|
803
760
|
const insertTableFootnote = (node, position, view, inlineFootnote) => {
|
|
804
761
|
var _a;
|
|
805
762
|
const { state, dispatch } = view;
|
|
@@ -23,7 +23,6 @@ require("prosemirror-view/style/prosemirror.css");
|
|
|
23
23
|
const transform_1 = require("@manuscripts/transform");
|
|
24
24
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
25
25
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
26
|
-
const clipboard_1 = require("../clipboard");
|
|
27
26
|
const paste_1 = require("../lib/paste");
|
|
28
27
|
const editor_plugins_1 = __importDefault(require("./editor-plugins"));
|
|
29
28
|
const editor_views_1 = __importDefault(require("./editor-views"));
|
|
@@ -47,7 +46,6 @@ const createEditorView = (props, root, state, dispatch) => {
|
|
|
47
46
|
nodeViews: (0, editor_views_1.default)(props, dispatch),
|
|
48
47
|
attributes: props.attributes,
|
|
49
48
|
transformPasted: paste_1.transformPasted,
|
|
50
|
-
clipboardParser: clipboard_1.clipboardParser,
|
|
51
49
|
});
|
|
52
50
|
const tr = view.state.tr.setMeta('INIT', true);
|
|
53
51
|
const nextState = view.state.apply(tr);
|
|
@@ -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
|
|
31
|
+
const comments_1 = __importDefault(require("../plugins/comments"));
|
|
32
|
+
const editor_props_1 = __importDefault(require("../plugins/editor-props"));
|
|
32
33
|
const elements_1 = __importDefault(require("../plugins/elements"));
|
|
33
34
|
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, comments_1.default)(),
|
|
67
67
|
(0, paragraphs_1.default)(),
|
|
68
68
|
(0, placeholder_1.default)(),
|
|
69
69
|
(0, prosemirror_tables_1.tableEditing)(),
|
|
70
|
-
(0,
|
|
70
|
+
(0, selected_suggestion_1.default)(),
|
|
71
71
|
(0, footnotes_1.default)(props),
|
|
72
72
|
(0, table_footnote_1.default)(),
|
|
73
|
-
(0,
|
|
73
|
+
(0, editor_props_1.default)(props),
|
|
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.
|
|
32
|
+
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,13 +43,10 @@ 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);
|
|
46
48
|
var selected_suggestion_1 = require("./plugins/selected-suggestion");
|
|
47
49
|
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; } });
|
|
53
50
|
__exportStar(require("./lib/utils"), exports);
|
|
54
51
|
__exportStar(require("./lib/track-changes-utils"), exports);
|
|
55
52
|
__exportStar(require("./useEditor"), exports);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCommentMarker = exports.getCommentRange = exports.getCommentKey = exports.isNodeComment = void 0;
|
|
4
|
+
const isNodeComment = (comment) => !comment.range;
|
|
5
|
+
exports.isNodeComment = isNodeComment;
|
|
6
|
+
const getCommentKey = (comment, range, target) => {
|
|
7
|
+
if (!range) {
|
|
8
|
+
return target.attrs.id;
|
|
9
|
+
}
|
|
10
|
+
else if (!range.size) {
|
|
11
|
+
return `${target.attrs.id}-${range.pos}`;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return comment.id;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.getCommentKey = getCommentKey;
|
|
18
|
+
const getCommentRange = (comment) => {
|
|
19
|
+
if (!comment.selector) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
pos: comment.selector.from,
|
|
24
|
+
size: comment.selector.to - comment.selector.from,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
exports.getCommentRange = getCommentRange;
|
|
28
|
+
const createCommentMarker = (tagName, key, count) => {
|
|
29
|
+
const element = document.createElement(tagName);
|
|
30
|
+
element.id = getMarkerID(key);
|
|
31
|
+
element.dataset.key = key;
|
|
32
|
+
element.classList.add('comment-marker');
|
|
33
|
+
if (count && count > 1) {
|
|
34
|
+
element.dataset.count = String(count);
|
|
35
|
+
}
|
|
36
|
+
element.innerHTML = `
|
|
37
|
+
<svg width="16" height="13" viewBox="0 0 16 13" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
38
|
+
<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"
|
|
39
|
+
fill="#FFFCDB" stroke="#FFBD26" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
|
40
|
+
<path d="M6.6875 4.6875H11.9375" stroke="#FFBD26" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
|
41
|
+
<path d="M6.6875 8.1875H9.3125" stroke="#FFBD26" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
|
42
|
+
</svg>
|
|
43
|
+
`;
|
|
44
|
+
return element;
|
|
45
|
+
};
|
|
46
|
+
exports.createCommentMarker = createCommentMarker;
|
|
47
|
+
const getMarkerID = (id) => {
|
|
48
|
+
return `${id}-comment-marker`;
|
|
49
|
+
};
|
|
@@ -164,12 +164,12 @@ class ContextMenu {
|
|
|
164
164
|
}
|
|
165
165
|
}));
|
|
166
166
|
}
|
|
167
|
-
const {
|
|
168
|
-
if (
|
|
167
|
+
const { addComment } = this.actions;
|
|
168
|
+
if (addComment) {
|
|
169
169
|
menu.appendChild(this.createMenuSection((section) => {
|
|
170
170
|
section.appendChild(this.createMenuItem('Comment', () => {
|
|
171
|
-
const
|
|
172
|
-
(0, commands_1.
|
|
171
|
+
const target = this.getCommentTarget();
|
|
172
|
+
(0, commands_1.addNodeComment)(target, this.view.state, this.view.dispatch);
|
|
173
173
|
popper.destroy();
|
|
174
174
|
}));
|
|
175
175
|
}));
|
|
@@ -378,6 +378,18 @@ 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
|
+
};
|
|
381
393
|
this.node = node;
|
|
382
394
|
this.view = view;
|
|
383
395
|
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.addInlineComment),
|
|
219
|
+
run: doCommand(commands_1.addInlineComment),
|
|
220
220
|
},
|
|
221
221
|
],
|
|
222
222
|
};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clearCommentSelection = exports.setCommentSelection = exports.commentsKey = void 0;
|
|
4
|
+
const transform_1 = require("@manuscripts/transform");
|
|
5
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
6
|
+
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
7
|
+
const prosemirror_view_1 = require("prosemirror-view");
|
|
8
|
+
const comments_1 = require("../lib/comments");
|
|
9
|
+
exports.commentsKey = new prosemirror_state_1.PluginKey('comments');
|
|
10
|
+
const COMMENT_SELECTION = 'comment-selection';
|
|
11
|
+
const EMPTY_SELECTION = {};
|
|
12
|
+
exports.default = () => {
|
|
13
|
+
return new prosemirror_state_1.Plugin({
|
|
14
|
+
key: exports.commentsKey,
|
|
15
|
+
state: {
|
|
16
|
+
init: (_, state) => {
|
|
17
|
+
return buildPluginState(state.doc);
|
|
18
|
+
},
|
|
19
|
+
apply: (tr, value) => {
|
|
20
|
+
if (tr.docChanged || tr.getMeta(COMMENT_SELECTION)) {
|
|
21
|
+
const selection = tr.getMeta(COMMENT_SELECTION) || value.selection;
|
|
22
|
+
return buildPluginState(tr.doc, selection === EMPTY_SELECTION ? undefined : selection);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
props: {
|
|
28
|
+
decorations: (state) => { var _a; return (_a = exports.commentsKey.getState(state)) === null || _a === void 0 ? void 0 : _a.decorations; },
|
|
29
|
+
handleClick: (view, pos, e) => {
|
|
30
|
+
const state = view.state;
|
|
31
|
+
const com = exports.commentsKey.getState(state);
|
|
32
|
+
const target = e.target;
|
|
33
|
+
const marker = target.closest('[data-key]');
|
|
34
|
+
if (!marker && !(com === null || com === void 0 ? void 0 : com.selection)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const tr = state.tr;
|
|
38
|
+
if (marker) {
|
|
39
|
+
const key = marker.dataset.key;
|
|
40
|
+
(0, exports.setCommentSelection)(tr, key, undefined, false);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
(0, exports.clearCommentSelection)(tr);
|
|
44
|
+
}
|
|
45
|
+
view.dispatch(tr);
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
const setCommentSelection = (tr, key, id, isNew) => {
|
|
51
|
+
tr.setMeta(COMMENT_SELECTION, {
|
|
52
|
+
key,
|
|
53
|
+
id,
|
|
54
|
+
isNew,
|
|
55
|
+
});
|
|
56
|
+
tr.setMeta('origin', exports.commentsKey);
|
|
57
|
+
return tr;
|
|
58
|
+
};
|
|
59
|
+
exports.setCommentSelection = setCommentSelection;
|
|
60
|
+
const clearCommentSelection = (tr) => {
|
|
61
|
+
tr.setMeta(COMMENT_SELECTION, EMPTY_SELECTION);
|
|
62
|
+
tr.setMeta('origin', exports.commentsKey);
|
|
63
|
+
return tr;
|
|
64
|
+
};
|
|
65
|
+
exports.clearCommentSelection = clearCommentSelection;
|
|
66
|
+
const findCommentRanges = (doc) => {
|
|
67
|
+
const nodes = (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.highlight_marker);
|
|
68
|
+
const ranges = new Map();
|
|
69
|
+
let start;
|
|
70
|
+
for (const { node, pos } of nodes) {
|
|
71
|
+
const attrs = node.attrs;
|
|
72
|
+
const position = attrs.position;
|
|
73
|
+
if (position === 'point') {
|
|
74
|
+
ranges.set(attrs.id, {
|
|
75
|
+
pos: pos + 1,
|
|
76
|
+
size: 0,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
else if (position === 'start') {
|
|
80
|
+
start = pos + 1;
|
|
81
|
+
}
|
|
82
|
+
else if (position === 'end' && start) {
|
|
83
|
+
ranges.set(attrs.id, {
|
|
84
|
+
pos: start,
|
|
85
|
+
size: pos - start,
|
|
86
|
+
});
|
|
87
|
+
start = undefined;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return ranges;
|
|
91
|
+
};
|
|
92
|
+
const findComments = (doc) => {
|
|
93
|
+
const nodes = (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.comment);
|
|
94
|
+
const commentsByTarget = new Map();
|
|
95
|
+
for (const { node } of nodes) {
|
|
96
|
+
const attrs = node.attrs;
|
|
97
|
+
const targetID = attrs.target;
|
|
98
|
+
const comments = commentsByTarget.get(targetID) || [];
|
|
99
|
+
commentsByTarget.set(targetID, [...comments, attrs]);
|
|
100
|
+
}
|
|
101
|
+
return commentsByTarget;
|
|
102
|
+
};
|
|
103
|
+
const buildPluginState = (doc, selection) => {
|
|
104
|
+
const commentsByTarget = findComments(doc);
|
|
105
|
+
const ranges = findCommentRanges(doc);
|
|
106
|
+
const decorations = [];
|
|
107
|
+
const allComments = [];
|
|
108
|
+
doc.descendants((node, pos) => {
|
|
109
|
+
const id = node.attrs.id;
|
|
110
|
+
const comments = commentsByTarget.get(id);
|
|
111
|
+
if (!comments || !comments.length) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const target = {
|
|
115
|
+
node,
|
|
116
|
+
pos,
|
|
117
|
+
};
|
|
118
|
+
const nodeComments = [];
|
|
119
|
+
const highlightComments = [];
|
|
120
|
+
const pointComments = [];
|
|
121
|
+
for (const attrs of comments) {
|
|
122
|
+
const id = attrs.id;
|
|
123
|
+
const range = ranges.get(id);
|
|
124
|
+
const key = (0, comments_1.getCommentKey)(attrs, range, node);
|
|
125
|
+
const comment = {
|
|
126
|
+
key,
|
|
127
|
+
attrs,
|
|
128
|
+
target,
|
|
129
|
+
range,
|
|
130
|
+
};
|
|
131
|
+
allComments.push(comment);
|
|
132
|
+
if (!comment.range) {
|
|
133
|
+
nodeComments.push(comment);
|
|
134
|
+
}
|
|
135
|
+
else if (comment.range.size) {
|
|
136
|
+
highlightComments.push(comment);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
pointComments.push(comment);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
for (const comment of highlightComments) {
|
|
143
|
+
const key = comment.key;
|
|
144
|
+
const range = comment.range;
|
|
145
|
+
decorations.push(createHighlightDecoration(key, range, selection));
|
|
146
|
+
}
|
|
147
|
+
if (pointComments.length) {
|
|
148
|
+
groupByKey(pointComments).forEach((comments, key) => {
|
|
149
|
+
const count = comments.length;
|
|
150
|
+
const pos = comments[0].range.pos;
|
|
151
|
+
decorations.push(createMarkerDecoration(key, 'span', pos, count, selection));
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (nodeComments.length) {
|
|
155
|
+
const count = nodeComments.length;
|
|
156
|
+
const key = nodeComments[0].key;
|
|
157
|
+
const tagName = node.isAtom ? 'span' : 'div';
|
|
158
|
+
const dpos = getDecorationPos(node, pos);
|
|
159
|
+
decorations.push(createMarkerDecoration(key, tagName, dpos, count, selection));
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return {
|
|
163
|
+
decorations: prosemirror_view_1.DecorationSet.create(doc, decorations),
|
|
164
|
+
comments: new Map(allComments.map((c) => [c.attrs.id, c])),
|
|
165
|
+
commentsByKey: groupByKey(allComments),
|
|
166
|
+
selection,
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
const groupByKey = (comments) => {
|
|
170
|
+
const map = new Map();
|
|
171
|
+
for (const comment of comments) {
|
|
172
|
+
const key = comment.key;
|
|
173
|
+
const value = map.get(key) || [];
|
|
174
|
+
map.set(key, [...value, comment]);
|
|
175
|
+
}
|
|
176
|
+
return map;
|
|
177
|
+
};
|
|
178
|
+
const getDecorationPos = (node, pos) => {
|
|
179
|
+
switch (node.type) {
|
|
180
|
+
case transform_1.schema.nodes.keywords:
|
|
181
|
+
return pos + 2;
|
|
182
|
+
default:
|
|
183
|
+
return pos + 1;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
const createHighlightDecoration = (key, range, selection) => {
|
|
187
|
+
const classNames = ['highlight'];
|
|
188
|
+
if (key === (selection === null || selection === void 0 ? void 0 : selection.key)) {
|
|
189
|
+
classNames.push('selected-comment');
|
|
190
|
+
}
|
|
191
|
+
return prosemirror_view_1.Decoration.inline(range.pos, range.pos + range.size, {
|
|
192
|
+
nodeName: 'span',
|
|
193
|
+
class: classNames.join(' '),
|
|
194
|
+
'data-key': key,
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
const createMarkerDecoration = (key, tagName, pos, count, selection) => {
|
|
198
|
+
const isSelected = (selection === null || selection === void 0 ? void 0 : selection.key) === key;
|
|
199
|
+
const toDOM = () => {
|
|
200
|
+
const marker = (0, comments_1.createCommentMarker)(tagName, key, count);
|
|
201
|
+
if (isSelected) {
|
|
202
|
+
marker.classList.add('selected-comment');
|
|
203
|
+
}
|
|
204
|
+
return marker;
|
|
205
|
+
};
|
|
206
|
+
return prosemirror_view_1.Decoration.widget(pos, toDOM, {
|
|
207
|
+
key: `${key}-${count}-${isSelected}`,
|
|
208
|
+
});
|
|
209
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEditorProps = exports.editorPropsKey = void 0;
|
|
4
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
5
|
+
exports.editorPropsKey = new prosemirror_state_1.PluginKey('editor-props');
|
|
6
|
+
exports.default = (props) => {
|
|
7
|
+
return new prosemirror_state_1.Plugin({
|
|
8
|
+
key: exports.editorPropsKey,
|
|
9
|
+
state: {
|
|
10
|
+
init: () => {
|
|
11
|
+
return props;
|
|
12
|
+
},
|
|
13
|
+
apply: () => {
|
|
14
|
+
return props;
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
const getEditorProps = (state) => {
|
|
20
|
+
return exports.editorPropsKey.getState(state);
|
|
21
|
+
};
|
|
22
|
+
exports.getEditorProps = getEditorProps;
|
|
@@ -19,7 +19,6 @@ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
|
19
19
|
const transform_1 = require("@manuscripts/transform");
|
|
20
20
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
21
21
|
const prosemirror_transform_1 = require("prosemirror-transform");
|
|
22
|
-
const highlight_1 = require("./highlight");
|
|
23
22
|
const preventTitleEdit = (tr) => {
|
|
24
23
|
let dontPrevent = true;
|
|
25
24
|
const isInRange = (start, end, position) => position >= start && position <= end;
|
|
@@ -29,9 +28,7 @@ const preventTitleEdit = (tr) => {
|
|
|
29
28
|
if (tr.getMeta('origin') === track_changes_plugin_1.trackChangesPluginKey) {
|
|
30
29
|
return dontPrevent;
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
if ((meta && highlight_1.SET_COMMENT in meta) ||
|
|
34
|
-
tr.getMeta('track-changes-skip-tracking')) {
|
|
31
|
+
if (tr.getMeta('track-changes-skip-tracking')) {
|
|
35
32
|
return dontPrevent;
|
|
36
33
|
}
|
|
37
34
|
const hasReplaceAroundSteps = tr.steps.some((step) => step instanceof prosemirror_transform_1.ReplaceAroundStep);
|