@manuscripts/body-editor 1.10.0 → 1.10.1-LEAN-3535.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/components/authors/AuthorAffiliations.js +6 -0
- package/dist/cjs/components/authors/AuthorsModal.js +4 -0
- package/dist/cjs/configs/editor-plugins.js +2 -2
- package/dist/cjs/configs/editor-views.js +0 -2
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/lib/authors.js +15 -1
- package/dist/cjs/lib/context-menu.js +7 -2
- package/dist/cjs/lib/popper.js +25 -3
- package/dist/cjs/plugins/affiliations.js +53 -43
- package/dist/cjs/plugins/selected-suggestion.js +127 -0
- package/dist/cjs/useEditor.js +1 -1
- package/dist/cjs/views/affiliations.js +102 -9
- package/dist/cjs/views/bibliography_element.js +46 -57
- package/dist/cjs/views/citation.js +13 -5
- package/dist/cjs/views/citation_editable.js +11 -19
- package/dist/cjs/views/contributors.js +92 -95
- package/dist/cjs/views/editable_block.js +2 -4
- package/dist/cjs/views/keyword_group.js +0 -10
- package/dist/es/components/authors/AuthorAffiliations.js +6 -0
- package/dist/es/components/authors/AuthorsModal.js +4 -0
- package/dist/es/configs/editor-plugins.js +2 -2
- package/dist/es/configs/editor-views.js +2 -4
- package/dist/es/index.js +1 -1
- package/dist/es/lib/authors.js +13 -0
- package/dist/es/lib/context-menu.js +6 -1
- package/dist/es/lib/popper.js +25 -3
- package/dist/es/plugins/affiliations.js +53 -43
- package/dist/es/plugins/selected-suggestion.js +124 -0
- package/dist/es/useEditor.js +1 -1
- package/dist/es/views/affiliations.js +102 -9
- package/dist/es/views/bibliography_element.js +47 -58
- package/dist/es/views/citation.js +13 -5
- package/dist/es/views/citation_editable.js +11 -19
- package/dist/es/views/contributors.js +95 -98
- package/dist/es/views/editable_block.js +3 -5
- package/dist/es/views/keyword_group.js +0 -10
- package/dist/types/configs/ManuscriptsEditor.d.ts +0 -1
- package/dist/types/configs/editor-plugins.d.ts +2 -21
- package/dist/types/configs/editor-views.d.ts +2 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types/lib/authors.d.ts +4 -2
- package/dist/types/lib/context-menu.d.ts +1 -0
- package/dist/types/lib/popper.d.ts +3 -1
- package/dist/types/plugins/affiliations.d.ts +8 -5
- package/dist/types/plugins/footnotes/index.d.ts +2 -2
- package/dist/types/plugins/selected-suggestion.d.ts +10 -0
- package/dist/types/views/affiliations.d.ts +28 -3
- package/dist/types/views/base_node_view.d.ts +0 -1
- package/dist/types/views/bibliography_element.d.ts +5 -4
- package/dist/types/views/citation.d.ts +2 -0
- package/dist/types/views/citation_editable.d.ts +1 -1
- package/dist/types/views/contributors.d.ts +13 -15
- package/dist/types/views/keyword_group.d.ts +0 -2
- package/package.json +1 -1
- package/styles/AdvancedEditor.css +29 -22
- package/dist/cjs/plugins/selected-suggestion-ui.js +0 -132
- package/dist/cjs/views/affiliation.js +0 -76
- package/dist/es/plugins/selected-suggestion-ui.js +0 -129
- package/dist/es/views/affiliation.js +0 -72
- package/dist/types/plugins/selected-suggestion-ui.d.ts +0 -25
- package/dist/types/views/affiliation.d.ts +0 -30
|
@@ -92,10 +92,16 @@ const AuthorAffiliations = ({ author, affiliations, onSave, onAdd, onRemove, })
|
|
|
92
92
|
const affiliation = {
|
|
93
93
|
id: (0, json_schema_1.generateID)(json_schema_1.ObjectTypes.Affiliation),
|
|
94
94
|
addressLine1: '',
|
|
95
|
+
addressLine2: '',
|
|
96
|
+
addressLine3: '',
|
|
95
97
|
city: '',
|
|
96
98
|
country: '',
|
|
97
99
|
county: '',
|
|
98
100
|
department: '',
|
|
101
|
+
email: {
|
|
102
|
+
href: '',
|
|
103
|
+
text: '',
|
|
104
|
+
},
|
|
99
105
|
institution: institution,
|
|
100
106
|
postCode: '',
|
|
101
107
|
priority: 0,
|
|
@@ -91,6 +91,8 @@ const normalize = (author) => ({
|
|
|
91
91
|
ORCIDIdentifier: author.ORCIDIdentifier || '',
|
|
92
92
|
priority: author.priority,
|
|
93
93
|
isJointContributor: author.isJointContributor || false,
|
|
94
|
+
userID: '',
|
|
95
|
+
invitationID: '',
|
|
94
96
|
});
|
|
95
97
|
const AuthorsModal = ({ authors: $authors, affiliations: $affiliations, author, onSaveAuthor, onDeleteAuthor, onSaveAffiliation, }) => {
|
|
96
98
|
const [isOpen, setOpen] = (0, react_1.useState)(true);
|
|
@@ -158,6 +160,8 @@ const AuthorsModal = ({ authors: $authors, affiliations: $affiliations, author,
|
|
|
158
160
|
ORCIDIdentifier: '',
|
|
159
161
|
priority: authors.length,
|
|
160
162
|
isJointContributor: false,
|
|
163
|
+
userID: '',
|
|
164
|
+
invitationID: '',
|
|
161
165
|
};
|
|
162
166
|
onSaveAuthor(author);
|
|
163
167
|
setSelection(author);
|
|
@@ -37,7 +37,7 @@ const paragraphs_1 = __importDefault(require("../plugins/paragraphs"));
|
|
|
37
37
|
const persist_1 = __importDefault(require("../plugins/persist"));
|
|
38
38
|
const placeholder_1 = __importDefault(require("../plugins/placeholder"));
|
|
39
39
|
const sections_1 = __importDefault(require("../plugins/sections"));
|
|
40
|
-
const
|
|
40
|
+
const selected_suggestion_1 = __importDefault(require("../plugins/selected-suggestion"));
|
|
41
41
|
const table_footnote_1 = __importDefault(require("../plugins/table-footnote"));
|
|
42
42
|
const tables_cursor_fix_1 = __importDefault(require("../plugins/tables-cursor-fix"));
|
|
43
43
|
const toc_1 = __importDefault(require("../plugins/toc"));
|
|
@@ -68,9 +68,9 @@ exports.default = (props) => {
|
|
|
68
68
|
(0, placeholder_1.default)(),
|
|
69
69
|
(0, prosemirror_tables_1.tableEditing)(),
|
|
70
70
|
(0, highlight_1.default)(props),
|
|
71
|
-
(0, selected_suggestion_ui_1.default)(props),
|
|
72
71
|
(0, footnotes_1.default)(props),
|
|
73
72
|
(0, table_footnote_1.default)(),
|
|
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 }));
|
|
@@ -18,7 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
const affiliation_1 = __importDefault(require("../views/affiliation"));
|
|
22
21
|
const affiliations_1 = __importDefault(require("../views/affiliations"));
|
|
23
22
|
const bibliography_element_editable_1 = __importDefault(require("../views/bibliography_element_editable"));
|
|
24
23
|
const blockquote_element_editable_1 = __importDefault(require("../views/blockquote_element_editable"));
|
|
@@ -61,7 +60,6 @@ exports.default = (props, dispatch) => {
|
|
|
61
60
|
cross_reference: (0, cross_reference_editable_1.default)(props, dispatch),
|
|
62
61
|
contributors: (0, contributors_1.default)(props, dispatch),
|
|
63
62
|
affiliations: (0, affiliations_1.default)(props, dispatch),
|
|
64
|
-
affiliation: (0, affiliation_1.default)(props, dispatch),
|
|
65
63
|
equation: (0, equation_editable_1.default)(props),
|
|
66
64
|
equation_element: (0, equation_element_editable_1.default)(props),
|
|
67
65
|
figure: (0, figure_editable_1.default)(props, dispatch),
|
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.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,13 +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
|
+
var selected_suggestion_1 = require("./plugins/selected-suggestion");
|
|
47
|
+
Object.defineProperty(exports, "selectedSuggestionKey", { enumerable: true, get: function () { return selected_suggestion_1.selectedSuggestionKey; } });
|
|
46
48
|
__exportStar(require("./plugins/highlight"), exports);
|
|
47
49
|
var comment_annotation_1 = require("./plugins/comment_annotation");
|
|
48
50
|
Object.defineProperty(exports, "commentScroll", { enumerable: true, get: function () { return comment_annotation_1.commentScroll; } });
|
|
49
51
|
Object.defineProperty(exports, "isThereSelector", { enumerable: true, get: function () { return comment_annotation_1.isThereSelector; } });
|
|
50
52
|
Object.defineProperty(exports, "isHighlightComment", { enumerable: true, get: function () { return comment_annotation_1.isHighlightComment; } });
|
|
51
|
-
var selected_suggestion_ui_1 = require("./plugins/selected-suggestion-ui");
|
|
52
|
-
Object.defineProperty(exports, "SET_SUGGESTION_ID", { enumerable: true, get: function () { return selected_suggestion_ui_1.SET_SUGGESTION_ID; } });
|
|
53
53
|
__exportStar(require("./lib/utils"), exports);
|
|
54
54
|
__exportStar(require("./lib/track-changes-utils"), exports);
|
|
55
55
|
__exportStar(require("./useEditor"), exports);
|
package/dist/cjs/lib/authors.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.authorComparator = exports.initials = exports.authorLabel = exports.affiliationLabel = void 0;
|
|
18
|
+
exports.authorComparator = exports.initials = exports.authorLabel = exports.affiliationName = exports.affiliationLabel = void 0;
|
|
19
19
|
const affiliationLabel = (affiliation) => {
|
|
20
20
|
const institution = affiliation.institution;
|
|
21
21
|
if (!institution) {
|
|
@@ -25,6 +25,20 @@ const affiliationLabel = (affiliation) => {
|
|
|
25
25
|
return department ? `${institution} (${department})`.trim() : institution;
|
|
26
26
|
};
|
|
27
27
|
exports.affiliationLabel = affiliationLabel;
|
|
28
|
+
const affiliationName = (affiliation) => {
|
|
29
|
+
return [
|
|
30
|
+
affiliation.department,
|
|
31
|
+
affiliation.institution,
|
|
32
|
+
affiliation.addressLine1,
|
|
33
|
+
affiliation.city,
|
|
34
|
+
affiliation.county,
|
|
35
|
+
affiliation.country,
|
|
36
|
+
affiliation.postCode,
|
|
37
|
+
]
|
|
38
|
+
.filter(Boolean)
|
|
39
|
+
.join(', ');
|
|
40
|
+
};
|
|
41
|
+
exports.affiliationName = affiliationName;
|
|
28
42
|
const authorLabel = (author) => {
|
|
29
43
|
const name = author.bibliographicName;
|
|
30
44
|
const parts = [(0, exports.initials)(name), name.family, name.suffix].filter(Boolean);
|
|
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.ContextMenu = exports.sectionLevel = void 0;
|
|
21
|
+
exports.ContextMenu = exports.contextMenuBtnClass = exports.sectionLevel = void 0;
|
|
22
22
|
const style_guide_1 = require("@manuscripts/style-guide");
|
|
23
23
|
const transform_1 = require("@manuscripts/transform");
|
|
24
24
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
@@ -42,6 +42,7 @@ exports.sectionLevel = sectionLevel;
|
|
|
42
42
|
const hasAny = (set, ...items) => {
|
|
43
43
|
return items.some((i) => set.has(i));
|
|
44
44
|
};
|
|
45
|
+
exports.contextMenuBtnClass = 'btn-context-menu';
|
|
45
46
|
class ContextMenu {
|
|
46
47
|
constructor(node, view, getPos, actions = {}, props) {
|
|
47
48
|
this.showAddMenu = (target, after) => {
|
|
@@ -355,7 +356,11 @@ class ContextMenu {
|
|
|
355
356
|
};
|
|
356
357
|
this.resolvePos = () => this.view.state.doc.resolve(this.getPos());
|
|
357
358
|
this.addPopperEventListeners = () => {
|
|
358
|
-
const mouseListener = () => {
|
|
359
|
+
const mouseListener = (event) => {
|
|
360
|
+
const target = event.target;
|
|
361
|
+
if (target.classList.contains(exports.contextMenuBtnClass)) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
359
364
|
window.requestAnimationFrame(() => {
|
|
360
365
|
window.removeEventListener('mousedown', mouseListener);
|
|
361
366
|
popper.destroy();
|
package/dist/cjs/lib/popper.js
CHANGED
|
@@ -22,12 +22,14 @@ exports.PopperManager = void 0;
|
|
|
22
22
|
const popper_js_1 = __importDefault(require("popper.js"));
|
|
23
23
|
class PopperManager {
|
|
24
24
|
show(target, contents, placement = 'bottom', showArrow = true, modifiers = {}) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
25
|
+
console.log(target);
|
|
26
|
+
this.destroy();
|
|
28
27
|
window.requestAnimationFrame(() => {
|
|
29
28
|
const container = document.createElement('div');
|
|
30
29
|
container.className = 'popper';
|
|
30
|
+
container.addEventListener('click', (e) => {
|
|
31
|
+
e.stopPropagation();
|
|
32
|
+
});
|
|
31
33
|
if (showArrow) {
|
|
32
34
|
const arrow = document.createElement('div');
|
|
33
35
|
arrow.className = 'popper-arrow';
|
|
@@ -55,12 +57,32 @@ class PopperManager {
|
|
|
55
57
|
this.focusInput(container);
|
|
56
58
|
},
|
|
57
59
|
});
|
|
60
|
+
this.handleDocumentClick = (e) => {
|
|
61
|
+
const node = e.target;
|
|
62
|
+
if (!container.contains(node) && !target.contains(node)) {
|
|
63
|
+
this.destroy();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
if (contents.classList.contains('context-menu')) {
|
|
67
|
+
window.addEventListener('click', this.handleDocumentClick);
|
|
68
|
+
}
|
|
58
69
|
});
|
|
59
70
|
}
|
|
71
|
+
clickEventHandler(event) {
|
|
72
|
+
const contextMenuElement = document.querySelector('.context-menu');
|
|
73
|
+
if (contextMenuElement === null || contextMenuElement === void 0 ? void 0 : contextMenuElement.contains(event.target)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this.destroy();
|
|
77
|
+
}
|
|
60
78
|
destroy() {
|
|
61
79
|
if (this.activePopper) {
|
|
80
|
+
window.removeEventListener('click', this.clickEventHandler);
|
|
62
81
|
this.removeContainerClass(this.activePopper.reference);
|
|
63
82
|
this.activePopper.destroy();
|
|
83
|
+
if (this.handleDocumentClick) {
|
|
84
|
+
window.removeEventListener('click', this.handleDocumentClick);
|
|
85
|
+
}
|
|
64
86
|
delete this.activePopper;
|
|
65
87
|
}
|
|
66
88
|
}
|
|
@@ -17,41 +17,53 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.buildPluginState = exports.affiliationsKey = void 0;
|
|
19
19
|
const transform_1 = require("@manuscripts/transform");
|
|
20
|
+
const lodash_1 = require("lodash");
|
|
20
21
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
21
22
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
23
|
+
const authors_1 = require("../lib/authors");
|
|
22
24
|
const track_changes_utils_1 = require("../lib/track-changes-utils");
|
|
23
25
|
exports.affiliationsKey = new prosemirror_state_1.PluginKey('affiliations');
|
|
24
26
|
let id = 1;
|
|
25
|
-
const buildPluginState = (doc) => {
|
|
27
|
+
const buildPluginState = (doc, $old) => {
|
|
28
|
+
const nodes = [];
|
|
26
29
|
const contributors = [];
|
|
27
30
|
const affiliations = [];
|
|
28
31
|
doc.descendants((node, pos) => {
|
|
29
|
-
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
+
const attrs = (0, track_changes_utils_1.isDeleted)(node) ? node.attrs : (0, track_changes_utils_1.getActualAttrs)(node);
|
|
32
33
|
if ((0, transform_1.isAffiliationNode)(node)) {
|
|
33
|
-
|
|
34
|
+
nodes.push([node, pos]);
|
|
35
|
+
affiliations.push(attrs);
|
|
34
36
|
}
|
|
35
37
|
if ((0, transform_1.isContributorNode)(node)) {
|
|
36
|
-
|
|
38
|
+
nodes.push([node, pos]);
|
|
39
|
+
contributors.push(attrs);
|
|
37
40
|
}
|
|
38
41
|
});
|
|
42
|
+
if ($old &&
|
|
43
|
+
(0, lodash_1.isEqual)(contributors, $old.contributors) &&
|
|
44
|
+
(0, lodash_1.isEqual)(affiliations, $old.affiliations)) {
|
|
45
|
+
return $old;
|
|
46
|
+
}
|
|
39
47
|
const iAffiliations = new Set();
|
|
40
|
-
contributors
|
|
41
|
-
.
|
|
42
|
-
return (Number((0, track_changes_utils_1.getActualAttrs)(a).priority) - Number((0, track_changes_utils_1.getActualAttrs)(b).priority));
|
|
43
|
-
})
|
|
44
|
-
.forEach(([author]) => {
|
|
45
|
-
(0, track_changes_utils_1.getActualAttrs)(author).affiliations.forEach((aff) => {
|
|
48
|
+
contributors.sort(authors_1.authorComparator).forEach((attrs) => {
|
|
49
|
+
attrs.affiliations.forEach((aff) => {
|
|
46
50
|
iAffiliations.add(aff);
|
|
47
51
|
});
|
|
48
52
|
});
|
|
49
53
|
const indexedAffiliationIds = new Map([...iAffiliations].map((id, i) => [id, i + 1]));
|
|
54
|
+
const version = String(id++);
|
|
55
|
+
const decorations = [];
|
|
56
|
+
nodes.forEach(([node, pos]) => {
|
|
57
|
+
decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
|
|
58
|
+
version,
|
|
59
|
+
}));
|
|
60
|
+
});
|
|
50
61
|
return {
|
|
51
|
-
version
|
|
62
|
+
version,
|
|
52
63
|
indexedAffiliationIds,
|
|
53
64
|
contributors,
|
|
54
65
|
affiliations,
|
|
66
|
+
decorations: prosemirror_view_1.DecorationSet.create(doc, decorations),
|
|
55
67
|
};
|
|
56
68
|
};
|
|
57
69
|
exports.buildPluginState = buildPluginState;
|
|
@@ -63,54 +75,52 @@ exports.default = () => {
|
|
|
63
75
|
return (0, exports.buildPluginState)(instance.doc);
|
|
64
76
|
},
|
|
65
77
|
apply(tr, value, oldState, newState) {
|
|
66
|
-
const
|
|
67
|
-
if (!tr.docChanged &&
|
|
68
|
-
return
|
|
78
|
+
const $old = exports.affiliationsKey.getState(oldState);
|
|
79
|
+
if (!tr.docChanged && $old) {
|
|
80
|
+
return $old;
|
|
69
81
|
}
|
|
70
82
|
else {
|
|
71
|
-
return (0, exports.buildPluginState)(newState.doc);
|
|
83
|
+
return (0, exports.buildPluginState)(newState.doc, $old);
|
|
72
84
|
}
|
|
73
85
|
},
|
|
74
86
|
},
|
|
75
87
|
appendTransaction(transactions, oldState, newState) {
|
|
76
|
-
const
|
|
77
|
-
if (!transactions.find((tr) => tr.docChanged)) {
|
|
88
|
+
const affs = exports.affiliationsKey.getState(newState);
|
|
89
|
+
if (!affs || !transactions.find((tr) => tr.docChanged)) {
|
|
78
90
|
return;
|
|
79
91
|
}
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
const affiliations = [];
|
|
92
|
+
const $old = exports.affiliationsKey.getState(oldState);
|
|
93
|
+
const affiliations = new Map();
|
|
83
94
|
newState.doc.descendants((node, pos) => {
|
|
84
|
-
if ((0, track_changes_utils_1.isDeleted)(node)) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
95
|
if ((0, transform_1.isAffiliationNode)(node)) {
|
|
88
|
-
affiliations.
|
|
96
|
+
affiliations.set(node.attrs.id, [node, pos]);
|
|
89
97
|
}
|
|
90
98
|
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
tr.delete(affiliation[1], affiliation[1] + affiliation[0].nodeSize);
|
|
96
|
-
}
|
|
99
|
+
const deleteIDs = [];
|
|
100
|
+
for (const [id] of $old.indexedAffiliationIds.entries()) {
|
|
101
|
+
if (!affs.indexedAffiliationIds.has(id)) {
|
|
102
|
+
deleteIDs.push(id);
|
|
97
103
|
}
|
|
98
104
|
}
|
|
105
|
+
if (!deleteIDs.length) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const tr = newState.tr;
|
|
99
109
|
tr.setMeta('origin', 'affiliations');
|
|
110
|
+
for (const id of deleteIDs) {
|
|
111
|
+
const affiliation = affiliations.get(id);
|
|
112
|
+
if (!affiliation) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const [node, pos] = affiliation;
|
|
116
|
+
if (node && !(0, track_changes_utils_1.isPendingInsert)(node)) {
|
|
117
|
+
tr.delete(pos, pos + node.nodeSize);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
100
120
|
return tr;
|
|
101
121
|
},
|
|
102
122
|
props: {
|
|
103
|
-
decorations: (state) => {
|
|
104
|
-
const decorations = [];
|
|
105
|
-
const aff = exports.affiliationsKey.getState(state);
|
|
106
|
-
const nodes = [...aff.contributors, ...aff.affiliations];
|
|
107
|
-
nodes.forEach(([node, pos]) => {
|
|
108
|
-
decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
|
|
109
|
-
version: aff.version,
|
|
110
|
-
}));
|
|
111
|
-
});
|
|
112
|
-
return prosemirror_view_1.DecorationSet.create(state.doc, decorations);
|
|
113
|
-
},
|
|
123
|
+
decorations: (state) => { var _a; return (_a = exports.affiliationsKey.getState(state)) === null || _a === void 0 ? void 0 : _a.decorations; },
|
|
114
124
|
},
|
|
115
125
|
});
|
|
116
126
|
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.selectedSuggestionKey = void 0;
|
|
4
|
+
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
5
|
+
const transform_1 = require("@manuscripts/transform");
|
|
6
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
7
|
+
const prosemirror_view_1 = require("prosemirror-view");
|
|
8
|
+
const commands_1 = require("../commands");
|
|
9
|
+
exports.selectedSuggestionKey = new prosemirror_state_1.PluginKey('selected-suggestion');
|
|
10
|
+
exports.default = () => {
|
|
11
|
+
return new prosemirror_state_1.Plugin({
|
|
12
|
+
key: exports.selectedSuggestionKey,
|
|
13
|
+
state: {
|
|
14
|
+
init: (_, state) => buildPluginState(state),
|
|
15
|
+
apply: (tr, value, oldState, newState) => buildPluginState(newState),
|
|
16
|
+
},
|
|
17
|
+
props: {
|
|
18
|
+
decorations: (state) => {
|
|
19
|
+
const suggestion = exports.selectedSuggestionKey.getState(state);
|
|
20
|
+
return (suggestion === null || suggestion === void 0 ? void 0 : suggestion.decorations) || prosemirror_view_1.DecorationSet.empty;
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
const buildPluginState = (state) => {
|
|
26
|
+
if ((0, commands_1.isTextSelection)(state.selection)) {
|
|
27
|
+
const $cursor = state.selection.$cursor;
|
|
28
|
+
if (!$cursor) {
|
|
29
|
+
return empty;
|
|
30
|
+
}
|
|
31
|
+
const selection = getEffectiveSelection(state.doc, $cursor);
|
|
32
|
+
if (!selection) {
|
|
33
|
+
return empty;
|
|
34
|
+
}
|
|
35
|
+
if (selection.node.isText) {
|
|
36
|
+
return buildTextDecoration(state.doc, selection);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return buildNodeDecoration(state.doc, selection);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if ((0, commands_1.isNodeSelection)(state.selection)) {
|
|
43
|
+
return buildNodeDecoration(state.doc, state.selection);
|
|
44
|
+
}
|
|
45
|
+
return empty;
|
|
46
|
+
};
|
|
47
|
+
const getEffectiveSelection = (doc, $pos) => {
|
|
48
|
+
const pos = $pos.pos;
|
|
49
|
+
let current;
|
|
50
|
+
for (let depth = $pos.depth; depth > 0; depth--) {
|
|
51
|
+
const node = $pos.node(depth);
|
|
52
|
+
if (node.attrs.dataTracked) {
|
|
53
|
+
current = {
|
|
54
|
+
node,
|
|
55
|
+
from: $pos.before(depth),
|
|
56
|
+
to: $pos.after(depth),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (current) {
|
|
64
|
+
return current;
|
|
65
|
+
}
|
|
66
|
+
const node = doc.nodeAt(pos);
|
|
67
|
+
if (node === null || node === void 0 ? void 0 : node.isText) {
|
|
68
|
+
const from = pos - $pos.textOffset;
|
|
69
|
+
const to = from + node.nodeSize;
|
|
70
|
+
return {
|
|
71
|
+
node,
|
|
72
|
+
from,
|
|
73
|
+
to,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const buildNodeDecoration = (doc, selection) => {
|
|
78
|
+
var _a;
|
|
79
|
+
const node = selection.node;
|
|
80
|
+
const suggestion = (_a = node.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a[0];
|
|
81
|
+
if (!(suggestion === null || suggestion === void 0 ? void 0 : suggestion.status) || suggestion.status === track_changes_plugin_1.CHANGE_STATUS.rejected) {
|
|
82
|
+
return empty;
|
|
83
|
+
}
|
|
84
|
+
const from = selection.from;
|
|
85
|
+
const to = selection.to;
|
|
86
|
+
const inline = node.type === transform_1.schema.nodes.keyword || node.isInline;
|
|
87
|
+
const decoration = prosemirror_view_1.Decoration.node(from, to, {
|
|
88
|
+
nodeName: inline ? 'span' : 'div',
|
|
89
|
+
class: 'selected-suggestion',
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
suggestion,
|
|
93
|
+
decorations: prosemirror_view_1.DecorationSet.create(doc, [decoration]),
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
const buildTextDecoration = (doc, selection) => {
|
|
97
|
+
var _a;
|
|
98
|
+
const node = selection.node;
|
|
99
|
+
const suggestion = (_a = getTrackedMark(node)) === null || _a === void 0 ? void 0 : _a.attrs.dataTracked;
|
|
100
|
+
if (!suggestion) {
|
|
101
|
+
return empty;
|
|
102
|
+
}
|
|
103
|
+
const from = selection.from;
|
|
104
|
+
const to = selection.to;
|
|
105
|
+
const decoration = prosemirror_view_1.Decoration.inline(from, to, {
|
|
106
|
+
nodeName: 'span',
|
|
107
|
+
class: 'selected-suggestion',
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
suggestion,
|
|
111
|
+
decorations: prosemirror_view_1.DecorationSet.create(doc, [decoration]),
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
const trackedMarkTypes = new Set([
|
|
115
|
+
transform_1.schema.marks.tracked_insert,
|
|
116
|
+
transform_1.schema.marks.tracked_delete,
|
|
117
|
+
]);
|
|
118
|
+
const getTrackedMark = (node) => {
|
|
119
|
+
for (const mark of node.marks) {
|
|
120
|
+
if (trackedMarkTypes.has(mark.type)) {
|
|
121
|
+
return mark;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const empty = {
|
|
126
|
+
decorations: prosemirror_view_1.DecorationSet.empty,
|
|
127
|
+
};
|
package/dist/cjs/useEditor.js
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2023 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
|
+
*/
|
|
2
17
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
19
|
};
|
|
5
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
21
|
exports.AffiliationsView = void 0;
|
|
7
22
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
23
|
+
const authors_1 = require("../lib/authors");
|
|
24
|
+
const view_1 = require("../lib/view");
|
|
25
|
+
const affiliations_1 = require("../plugins/affiliations");
|
|
26
|
+
const selected_suggestion_1 = require("../plugins/selected-suggestion");
|
|
8
27
|
const block_view_1 = __importDefault(require("./block_view"));
|
|
9
28
|
const creators_1 = require("./creators");
|
|
10
29
|
class AffiliationsView extends block_view_1.default {
|
|
@@ -13,19 +32,93 @@ class AffiliationsView extends block_view_1.default {
|
|
|
13
32
|
this.ignoreMutation = () => true;
|
|
14
33
|
this.stopEvent = () => true;
|
|
15
34
|
this.createElement = () => {
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
35
|
+
this.container = document.createElement('div');
|
|
36
|
+
this.container.classList.add('affiliations', 'block');
|
|
37
|
+
this.container.contentEditable = 'false';
|
|
38
|
+
this.container.addEventListener('click', this.handleClick);
|
|
19
39
|
this.dom.setAttribute('contenteditable', 'false');
|
|
20
|
-
this.dom.appendChild(this.
|
|
40
|
+
this.dom.appendChild(this.container);
|
|
21
41
|
};
|
|
22
42
|
this.updateContents = () => {
|
|
23
|
-
|
|
43
|
+
const affs = affiliations_1.affiliationsKey.getState(this.view.state);
|
|
44
|
+
if (!affs) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (this.version === affs.version) {
|
|
48
|
+
this.updateSelection();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.version = affs.version;
|
|
52
|
+
this.container.innerHTML = '';
|
|
53
|
+
this.buildAffiliations(affs);
|
|
54
|
+
this.updateSelection();
|
|
24
55
|
};
|
|
25
|
-
this.
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
56
|
+
this.buildAffiliations = (affs) => {
|
|
57
|
+
const elements = [];
|
|
58
|
+
for (const affiliation of affs.affiliations) {
|
|
59
|
+
const index = affs.indexedAffiliationIds.get(affiliation.id);
|
|
60
|
+
elements.push({
|
|
61
|
+
index,
|
|
62
|
+
element: this.buildAffiliation(affiliation, index),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
elements
|
|
66
|
+
.sort(this.sortAffiliations)
|
|
67
|
+
.forEach((e) => this.container.appendChild(e.element));
|
|
68
|
+
};
|
|
69
|
+
this.buildAffiliation = (attrs, index) => {
|
|
70
|
+
var _a;
|
|
71
|
+
const element = document.createElement('div');
|
|
72
|
+
element.classList.add('affiliation');
|
|
73
|
+
element.id = attrs.id;
|
|
74
|
+
if ((_a = attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.length) {
|
|
75
|
+
const change = attrs.dataTracked[0];
|
|
76
|
+
element.setAttribute('data-track-id', change.id);
|
|
77
|
+
element.setAttribute('data-track-status', change.status);
|
|
78
|
+
element.setAttribute('data-track-op', change.operation);
|
|
79
|
+
}
|
|
80
|
+
if (index) {
|
|
81
|
+
const label = document.createElement('span');
|
|
82
|
+
label.classList.add('affiliation-label');
|
|
83
|
+
label.innerHTML = String(index);
|
|
84
|
+
element.appendChild(label);
|
|
85
|
+
}
|
|
86
|
+
const name = document.createElement('span');
|
|
87
|
+
name.classList.add('affiliation-name');
|
|
88
|
+
name.innerHTML = (0, authors_1.affiliationName)(attrs);
|
|
89
|
+
element.appendChild(name);
|
|
90
|
+
return element;
|
|
91
|
+
};
|
|
92
|
+
this.sortAffiliations = (aff1, aff2) => {
|
|
93
|
+
const index1 = aff1.index || 10000;
|
|
94
|
+
const index2 = aff2.index || 10000;
|
|
95
|
+
return index1 - index2;
|
|
96
|
+
};
|
|
97
|
+
this.handleClick = (event) => {
|
|
98
|
+
const element = event.target;
|
|
99
|
+
const item = element.closest('.affiliation');
|
|
100
|
+
if (item) {
|
|
101
|
+
const node = (0, view_1.findChildByID)(this.view, item.id);
|
|
102
|
+
if (!node) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const view = this.view;
|
|
106
|
+
const tr = view.state.tr;
|
|
107
|
+
tr.setSelection(prosemirror_state_1.NodeSelection.create(view.state.doc, node.pos));
|
|
108
|
+
view.dispatch(tr);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
this.updateSelection = () => {
|
|
112
|
+
var _a;
|
|
113
|
+
const state = this.view.state;
|
|
114
|
+
const selection = (_a = selected_suggestion_1.selectedSuggestionKey.getState(state)) === null || _a === void 0 ? void 0 : _a.suggestion;
|
|
115
|
+
this.container
|
|
116
|
+
.querySelectorAll('.selected-suggestion')
|
|
117
|
+
.forEach((e) => e.classList.remove('selected-suggestion'));
|
|
118
|
+
if (selection) {
|
|
119
|
+
const item = this.container.querySelector(`[data-track-id="${selection.id}"]`);
|
|
120
|
+
item === null || item === void 0 ? void 0 : item.classList.add('selected-suggestion');
|
|
121
|
+
}
|
|
29
122
|
};
|
|
30
123
|
}
|
|
31
124
|
}
|