@manuscripts/body-editor 1.9.23-LEAN-3623.0 → 1.10.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 +26 -0
- package/dist/cjs/components/authors/AuthorAffiliations.js +0 -6
- package/dist/cjs/components/authors/AuthorsModal.js +0 -4
- package/dist/cjs/configs/editor-plugins.js +2 -2
- package/dist/cjs/configs/editor-views.js +2 -0
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/keys/list.js +1 -2
- package/dist/cjs/lib/authors.js +1 -15
- package/dist/cjs/lib/popper.js +0 -13
- package/dist/cjs/plugins/affiliations.js +43 -53
- package/dist/cjs/plugins/selected-suggestion-ui.js +132 -0
- package/dist/cjs/useEditor.js +1 -1
- package/dist/cjs/views/affiliation.js +76 -0
- package/dist/cjs/views/affiliations.js +9 -102
- package/dist/cjs/views/bibliography_element.js +56 -44
- package/dist/cjs/views/citation.js +5 -6
- package/dist/cjs/views/citation_editable.js +10 -2
- package/dist/cjs/views/contributors.js +95 -92
- package/dist/cjs/views/keyword_group.js +10 -0
- package/dist/es/commands.js +27 -1
- package/dist/es/components/authors/AuthorAffiliations.js +0 -6
- package/dist/es/components/authors/AuthorsModal.js +0 -4
- package/dist/es/configs/editor-plugins.js +2 -2
- package/dist/es/configs/editor-views.js +4 -2
- package/dist/es/index.js +1 -1
- package/dist/es/keys/list.js +2 -3
- package/dist/es/lib/authors.js +0 -13
- package/dist/es/lib/popper.js +0 -13
- package/dist/es/plugins/affiliations.js +43 -53
- package/dist/es/plugins/selected-suggestion-ui.js +129 -0
- package/dist/es/useEditor.js +1 -1
- package/dist/es/views/affiliation.js +72 -0
- package/dist/es/views/affiliations.js +9 -102
- package/dist/es/views/bibliography_element.js +57 -45
- package/dist/es/views/citation.js +5 -6
- package/dist/es/views/citation_editable.js +10 -2
- package/dist/es/views/contributors.js +98 -95
- package/dist/es/views/keyword_group.js +10 -0
- package/dist/types/configs/ManuscriptsEditor.d.ts +1 -0
- package/dist/types/configs/editor-plugins.d.ts +21 -2
- package/dist/types/configs/editor-views.d.ts +3 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/lib/authors.d.ts +2 -4
- package/dist/types/lib/popper.d.ts +1 -2
- package/dist/types/plugins/affiliations.d.ts +5 -8
- package/dist/types/plugins/footnotes/index.d.ts +2 -2
- package/dist/types/plugins/selected-suggestion-ui.d.ts +25 -0
- package/dist/types/views/affiliation.d.ts +30 -0
- package/dist/types/views/affiliations.d.ts +3 -28
- package/dist/types/views/base_node_view.d.ts +1 -0
- package/dist/types/views/bibliography_element.d.ts +4 -5
- package/dist/types/views/contributors.d.ts +15 -13
- package/dist/types/views/keyword_group.d.ts +2 -0
- package/package.json +1 -1
- package/styles/AdvancedEditor.css +22 -29
- package/dist/cjs/plugins/selected-suggestion.js +0 -127
- package/dist/es/plugins/selected-suggestion.js +0 -124
- package/dist/types/plugins/selected-suggestion.d.ts +0 -10
package/dist/cjs/commands.js
CHANGED
|
@@ -427,12 +427,38 @@ const findListsAtSameLevel = (doc, list) => {
|
|
|
427
427
|
});
|
|
428
428
|
return lists;
|
|
429
429
|
};
|
|
430
|
+
function toggleOffList(state, dispatch) {
|
|
431
|
+
const { selection: { $from }, tr, } = state;
|
|
432
|
+
const rootList = findRootList($from);
|
|
433
|
+
if (rootList) {
|
|
434
|
+
state.doc.nodesBetween(rootList.pos, rootList.pos + rootList.node.nodeSize, (node, pos) => {
|
|
435
|
+
const $fromPos = tr.doc.resolve(tr.mapping.map(pos));
|
|
436
|
+
const $toPos = tr.doc.resolve(tr.mapping.map(pos + node.nodeSize - 1));
|
|
437
|
+
const nodeRange = $fromPos.blockRange($toPos);
|
|
438
|
+
if (!nodeRange) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
const targetLiftDepth = (0, prosemirror_transform_1.liftTarget)(nodeRange);
|
|
442
|
+
if (targetLiftDepth || targetLiftDepth === 0) {
|
|
443
|
+
tr.lift(nodeRange, targetLiftDepth);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
dispatch((0, track_changes_plugin_1.skipTracking)(tr));
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
430
453
|
const insertList = (type, style) => (state, dispatch) => {
|
|
431
454
|
const list = findSelectedList(state.selection);
|
|
432
455
|
if (list) {
|
|
433
456
|
if (!dispatch) {
|
|
434
457
|
return true;
|
|
435
458
|
}
|
|
459
|
+
if (list.node.attrs.listStyleType === style) {
|
|
460
|
+
return toggleOffList(state, dispatch);
|
|
461
|
+
}
|
|
436
462
|
const nodes = findListsAtSameLevel(state.doc, list);
|
|
437
463
|
const tr = state.tr;
|
|
438
464
|
for (const { node, pos } of nodes) {
|
|
@@ -92,16 +92,10 @@ 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: '',
|
|
97
95
|
city: '',
|
|
98
96
|
country: '',
|
|
99
97
|
county: '',
|
|
100
98
|
department: '',
|
|
101
|
-
email: {
|
|
102
|
-
href: '',
|
|
103
|
-
text: '',
|
|
104
|
-
},
|
|
105
99
|
institution: institution,
|
|
106
100
|
postCode: '',
|
|
107
101
|
priority: 0,
|
|
@@ -91,8 +91,6 @@ const normalize = (author) => ({
|
|
|
91
91
|
ORCIDIdentifier: author.ORCIDIdentifier || '',
|
|
92
92
|
priority: author.priority,
|
|
93
93
|
isJointContributor: author.isJointContributor || false,
|
|
94
|
-
userID: '',
|
|
95
|
-
invitationID: '',
|
|
96
94
|
});
|
|
97
95
|
const AuthorsModal = ({ authors: $authors, affiliations: $affiliations, author, onSaveAuthor, onDeleteAuthor, onSaveAffiliation, }) => {
|
|
98
96
|
const [isOpen, setOpen] = (0, react_1.useState)(true);
|
|
@@ -160,8 +158,6 @@ const AuthorsModal = ({ authors: $authors, affiliations: $affiliations, author,
|
|
|
160
158
|
ORCIDIdentifier: '',
|
|
161
159
|
priority: authors.length,
|
|
162
160
|
isJointContributor: false,
|
|
163
|
-
userID: '',
|
|
164
|
-
invitationID: '',
|
|
165
161
|
};
|
|
166
162
|
onSaveAuthor(author);
|
|
167
163
|
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_ui_1 = __importDefault(require("../plugins/selected-suggestion-ui"));
|
|
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),
|
|
71
72
|
(0, footnotes_1.default)(props),
|
|
72
73
|
(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,6 +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
|
+
const affiliation_1 = __importDefault(require("../views/affiliation"));
|
|
21
22
|
const affiliations_1 = __importDefault(require("../views/affiliations"));
|
|
22
23
|
const bibliography_element_editable_1 = __importDefault(require("../views/bibliography_element_editable"));
|
|
23
24
|
const blockquote_element_editable_1 = __importDefault(require("../views/blockquote_element_editable"));
|
|
@@ -60,6 +61,7 @@ exports.default = (props, dispatch) => {
|
|
|
60
61
|
cross_reference: (0, cross_reference_editable_1.default)(props, dispatch),
|
|
61
62
|
contributors: (0, contributors_1.default)(props, dispatch),
|
|
62
63
|
affiliations: (0, affiliations_1.default)(props, dispatch),
|
|
64
|
+
affiliation: (0, affiliation_1.default)(props, dispatch),
|
|
63
65
|
equation: (0, equation_editable_1.default)(props),
|
|
64
66
|
equation_element: (0, equation_element_editable_1.default)(props),
|
|
65
67
|
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.SET_SUGGESTION_ID = exports.isHighlightComment = exports.isThereSelector = exports.commentScroll = 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; } });
|
|
48
46
|
__exportStar(require("./plugins/highlight"), exports);
|
|
49
47
|
var comment_annotation_1 = require("./plugins/comment_annotation");
|
|
50
48
|
Object.defineProperty(exports, "commentScroll", { enumerable: true, get: function () { return comment_annotation_1.commentScroll; } });
|
|
51
49
|
Object.defineProperty(exports, "isThereSelector", { enumerable: true, get: function () { return comment_annotation_1.isThereSelector; } });
|
|
52
50
|
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/keys/list.js
CHANGED
|
@@ -19,7 +19,6 @@ exports.skipCommandTracking = void 0;
|
|
|
19
19
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
20
20
|
const transform_1 = require("@manuscripts/transform");
|
|
21
21
|
const prosemirror_commands_1 = require("prosemirror-commands");
|
|
22
|
-
const prosemirror_inputrules_1 = require("prosemirror-inputrules");
|
|
23
22
|
const prosemirror_schema_list_1 = require("prosemirror-schema-list");
|
|
24
23
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
25
24
|
const skipCommandTracking = (command) => (state, dispatch) => {
|
|
@@ -65,6 +64,6 @@ const listKeymap = {
|
|
|
65
64
|
'Mod-Alt-k': (0, exports.skipCommandTracking)((0, prosemirror_schema_list_1.wrapInList)(transform_1.schema.nodes.bullet_list)),
|
|
66
65
|
'Shift-Tab': (0, exports.skipCommandTracking)(liftToOuterList(transform_1.schema.nodes.list_item)),
|
|
67
66
|
Tab: (0, exports.skipCommandTracking)((0, prosemirror_schema_list_1.sinkListItem)(transform_1.schema.nodes.list_item)),
|
|
68
|
-
Backspace: (0, exports.skipCommandTracking)(
|
|
67
|
+
Backspace: (0, exports.skipCommandTracking)(listItemBackward),
|
|
69
68
|
};
|
|
70
69
|
exports.default = listKeymap;
|
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.
|
|
18
|
+
exports.authorComparator = exports.initials = exports.authorLabel = exports.affiliationLabel = void 0;
|
|
19
19
|
const affiliationLabel = (affiliation) => {
|
|
20
20
|
const institution = affiliation.institution;
|
|
21
21
|
if (!institution) {
|
|
@@ -25,20 +25,6 @@ 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;
|
|
42
28
|
const authorLabel = (author) => {
|
|
43
29
|
const name = author.bibliographicName;
|
|
44
30
|
const parts = [(0, exports.initials)(name), name.family, name.suffix].filter(Boolean);
|
package/dist/cjs/lib/popper.js
CHANGED
|
@@ -28,9 +28,6 @@ class PopperManager {
|
|
|
28
28
|
window.requestAnimationFrame(() => {
|
|
29
29
|
const container = document.createElement('div');
|
|
30
30
|
container.className = 'popper';
|
|
31
|
-
container.addEventListener('click', (e) => {
|
|
32
|
-
e.stopPropagation();
|
|
33
|
-
});
|
|
34
31
|
if (showArrow) {
|
|
35
32
|
const arrow = document.createElement('div');
|
|
36
33
|
arrow.className = 'popper-arrow';
|
|
@@ -58,22 +55,12 @@ class PopperManager {
|
|
|
58
55
|
this.focusInput(container);
|
|
59
56
|
},
|
|
60
57
|
});
|
|
61
|
-
this.handleDocumentClick = (e) => {
|
|
62
|
-
const node = e.target;
|
|
63
|
-
if (!container.contains(node) && !target.contains(node)) {
|
|
64
|
-
this.destroy();
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
document.addEventListener('click', this.handleDocumentClick);
|
|
68
58
|
});
|
|
69
59
|
}
|
|
70
60
|
destroy() {
|
|
71
61
|
if (this.activePopper) {
|
|
72
62
|
this.removeContainerClass(this.activePopper.reference);
|
|
73
63
|
this.activePopper.destroy();
|
|
74
|
-
if (this.handleDocumentClick) {
|
|
75
|
-
document.removeEventListener('click', this.handleDocumentClick);
|
|
76
|
-
}
|
|
77
64
|
delete this.activePopper;
|
|
78
65
|
}
|
|
79
66
|
}
|
|
@@ -17,53 +17,41 @@
|
|
|
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");
|
|
21
20
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
22
21
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
23
|
-
const authors_1 = require("../lib/authors");
|
|
24
22
|
const track_changes_utils_1 = require("../lib/track-changes-utils");
|
|
25
23
|
exports.affiliationsKey = new prosemirror_state_1.PluginKey('affiliations');
|
|
26
24
|
let id = 1;
|
|
27
|
-
const buildPluginState = (doc
|
|
28
|
-
const nodes = [];
|
|
25
|
+
const buildPluginState = (doc) => {
|
|
29
26
|
const contributors = [];
|
|
30
27
|
const affiliations = [];
|
|
31
28
|
doc.descendants((node, pos) => {
|
|
32
|
-
|
|
29
|
+
if ((0, track_changes_utils_1.isDeleted)(node)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
33
32
|
if ((0, transform_1.isAffiliationNode)(node)) {
|
|
34
|
-
|
|
35
|
-
affiliations.push(attrs);
|
|
33
|
+
affiliations.push([node, pos]);
|
|
36
34
|
}
|
|
37
35
|
if ((0, transform_1.isContributorNode)(node)) {
|
|
38
|
-
|
|
39
|
-
contributors.push(attrs);
|
|
36
|
+
contributors.push([node, pos]);
|
|
40
37
|
}
|
|
41
38
|
});
|
|
42
|
-
if ($old &&
|
|
43
|
-
(0, lodash_1.isEqual)(contributors, $old.contributors) &&
|
|
44
|
-
(0, lodash_1.isEqual)(affiliations, $old.affiliations)) {
|
|
45
|
-
return $old;
|
|
46
|
-
}
|
|
47
39
|
const iAffiliations = new Set();
|
|
48
|
-
contributors
|
|
49
|
-
|
|
40
|
+
contributors
|
|
41
|
+
.sort(([a], [b]) => {
|
|
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) => {
|
|
50
46
|
iAffiliations.add(aff);
|
|
51
47
|
});
|
|
52
48
|
});
|
|
53
49
|
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
|
-
});
|
|
61
50
|
return {
|
|
62
|
-
version,
|
|
51
|
+
version: String(id++),
|
|
63
52
|
indexedAffiliationIds,
|
|
64
53
|
contributors,
|
|
65
54
|
affiliations,
|
|
66
|
-
decorations: prosemirror_view_1.DecorationSet.create(doc, decorations),
|
|
67
55
|
};
|
|
68
56
|
};
|
|
69
57
|
exports.buildPluginState = buildPluginState;
|
|
@@ -75,52 +63,54 @@ exports.default = () => {
|
|
|
75
63
|
return (0, exports.buildPluginState)(instance.doc);
|
|
76
64
|
},
|
|
77
65
|
apply(tr, value, oldState, newState) {
|
|
78
|
-
const
|
|
79
|
-
if (!tr.docChanged &&
|
|
80
|
-
return
|
|
66
|
+
const prevPluginState = exports.affiliationsKey.getState(oldState);
|
|
67
|
+
if (!tr.docChanged && prevPluginState) {
|
|
68
|
+
return prevPluginState;
|
|
81
69
|
}
|
|
82
70
|
else {
|
|
83
|
-
return (0, exports.buildPluginState)(newState.doc
|
|
71
|
+
return (0, exports.buildPluginState)(newState.doc);
|
|
84
72
|
}
|
|
85
73
|
},
|
|
86
74
|
},
|
|
87
75
|
appendTransaction(transactions, oldState, newState) {
|
|
88
|
-
const
|
|
89
|
-
if (!
|
|
76
|
+
const { indexedAffiliationIds } = exports.affiliationsKey.getState(newState);
|
|
77
|
+
if (!transactions.find((tr) => tr.docChanged)) {
|
|
90
78
|
return;
|
|
91
79
|
}
|
|
92
|
-
const
|
|
93
|
-
const
|
|
80
|
+
const oldPluginState = exports.affiliationsKey.getState(oldState);
|
|
81
|
+
const { tr } = newState;
|
|
82
|
+
const affiliations = [];
|
|
94
83
|
newState.doc.descendants((node, pos) => {
|
|
84
|
+
if ((0, track_changes_utils_1.isDeleted)(node)) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
95
87
|
if ((0, transform_1.isAffiliationNode)(node)) {
|
|
96
|
-
affiliations.
|
|
88
|
+
affiliations.push([node, pos]);
|
|
97
89
|
}
|
|
98
90
|
});
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
91
|
+
for (const [id] of oldPluginState.indexedAffiliationIds.entries()) {
|
|
92
|
+
if (!indexedAffiliationIds.has(id)) {
|
|
93
|
+
const affiliation = affiliations.find(([node]) => node.attrs.id === id);
|
|
94
|
+
if (affiliation && !(0, track_changes_utils_1.isPendingInsert)(affiliation[0])) {
|
|
95
|
+
tr.delete(affiliation[1], affiliation[1] + affiliation[0].nodeSize);
|
|
96
|
+
}
|
|
103
97
|
}
|
|
104
98
|
}
|
|
105
|
-
if (!deleteIDs.length) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
const tr = newState.tr;
|
|
109
99
|
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
|
-
}
|
|
120
100
|
return tr;
|
|
121
101
|
},
|
|
122
102
|
props: {
|
|
123
|
-
decorations: (state) => {
|
|
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
|
+
},
|
|
124
114
|
},
|
|
125
115
|
});
|
|
126
116
|
};
|
|
@@ -0,0 +1,132 @@
|
|
|
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.selectedSuggestionKey = exports.CLEAR_SUGGESTION_ID = exports.SET_SUGGESTION_ID = void 0;
|
|
19
|
+
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
20
|
+
const lodash_1 = require("lodash");
|
|
21
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
22
|
+
const prosemirror_view_1 = require("prosemirror-view");
|
|
23
|
+
class SuggestionView {
|
|
24
|
+
constructor(view) {
|
|
25
|
+
this.listener = (e) => {
|
|
26
|
+
const changeId = e.currentTarget.getAttribute('data-track-id');
|
|
27
|
+
this.view.dispatch(this.view.state.tr.setMeta(exports.SET_SUGGESTION_ID, changeId));
|
|
28
|
+
};
|
|
29
|
+
this.view = view;
|
|
30
|
+
this.addEventListener(view);
|
|
31
|
+
this.update(view, undefined);
|
|
32
|
+
}
|
|
33
|
+
update(view, prevState) {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
this.view = view;
|
|
36
|
+
if (!prevState) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const oldChanges = ((_a = track_changes_plugin_1.trackChangesPluginKey.getState(prevState)) === null || _a === void 0 ? void 0 : _a.changeSet.changes) || [];
|
|
40
|
+
const newChangeSet = (_b = track_changes_plugin_1.trackChangesPluginKey.getState(view.state)) === null || _b === void 0 ? void 0 : _b.changeSet;
|
|
41
|
+
if (newChangeSet && !(0, lodash_1.isEqual)(oldChanges, newChangeSet.changes)) {
|
|
42
|
+
this.addEventListener(view);
|
|
43
|
+
oldChanges.map((change) => {
|
|
44
|
+
var _a;
|
|
45
|
+
if (!newChangeSet.get(change.id) ||
|
|
46
|
+
((_a = newChangeSet.get(change.id)) === null || _a === void 0 ? void 0 : _a.dataTracked.status) === 'rejected') {
|
|
47
|
+
const dom = view.dom.querySelector(`[data-track-id="${change.id}"]`);
|
|
48
|
+
dom === null || dom === void 0 ? void 0 : dom.removeEventListener('click', this.listener);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
destroy() {
|
|
54
|
+
this.view.dom
|
|
55
|
+
.querySelectorAll('[data-track-status="pending"], [data-track-status="accepted"]')
|
|
56
|
+
.forEach((dom) => {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
if ((_b = (_a = dom.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.classList.contains('keyword')) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
dom.removeEventListener('click', this.listener);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
addEventListener(view) {
|
|
65
|
+
view.dom
|
|
66
|
+
.querySelectorAll('[data-track-status="pending"], [data-track-status="accepted"]')
|
|
67
|
+
.forEach((dom) => {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
if ((_b = (_a = dom.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.classList.contains('keyword')) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
dom.addEventListener('click', this.listener);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const getTrackChangesData = (node) => {
|
|
77
|
+
var _a;
|
|
78
|
+
const trackChangesMark = node.marks.find((mark) => (mark.type.name === 'tracked_insert' ||
|
|
79
|
+
mark.type.name === 'tracked_delete') &&
|
|
80
|
+
mark.attrs.dataTracked);
|
|
81
|
+
return (_a = trackChangesMark === null || trackChangesMark === void 0 ? void 0 : trackChangesMark.attrs) === null || _a === void 0 ? void 0 : _a.dataTracked;
|
|
82
|
+
};
|
|
83
|
+
exports.SET_SUGGESTION_ID = 'SET_SELECTED_SUGGESTION_ID';
|
|
84
|
+
exports.CLEAR_SUGGESTION_ID = 'CLEAR_SUGGESTION_ID';
|
|
85
|
+
exports.selectedSuggestionKey = new prosemirror_state_1.PluginKey('selected_suggestion');
|
|
86
|
+
exports.default = (props) => new prosemirror_state_1.Plugin({
|
|
87
|
+
key: exports.selectedSuggestionKey,
|
|
88
|
+
view: (view) => new SuggestionView(view),
|
|
89
|
+
state: {
|
|
90
|
+
init: () => prosemirror_view_1.DecorationSet.empty,
|
|
91
|
+
apply: (tr, value, _, state) => {
|
|
92
|
+
const suggestionId = tr.getMeta(exports.SET_SUGGESTION_ID);
|
|
93
|
+
if (suggestionId) {
|
|
94
|
+
return buildSelectedSuggestionDecoration(suggestionId, state, props);
|
|
95
|
+
}
|
|
96
|
+
if (tr.getMeta(exports.CLEAR_SUGGESTION_ID)) {
|
|
97
|
+
return prosemirror_view_1.DecorationSet.empty;
|
|
98
|
+
}
|
|
99
|
+
return value;
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
props: {
|
|
103
|
+
handleClick(view, pos) {
|
|
104
|
+
const nodeClicked = view.state.doc.nodeAt(pos);
|
|
105
|
+
const trackChangesData = nodeClicked && getTrackChangesData(nodeClicked);
|
|
106
|
+
if (!trackChangesData) {
|
|
107
|
+
setTimeout(() => {
|
|
108
|
+
const newTr = view.state.tr.setMeta(exports.CLEAR_SUGGESTION_ID, true);
|
|
109
|
+
view.dispatch(newTr);
|
|
110
|
+
props.setEditorSelectedSuggestion(undefined);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
decorations: (state) => exports.selectedSuggestionKey.getState(state),
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
const buildSelectedSuggestionDecoration = (suggestionId, state, props) => {
|
|
118
|
+
var _a;
|
|
119
|
+
const change = (_a = track_changes_plugin_1.trackChangesPluginKey
|
|
120
|
+
.getState(state)) === null || _a === void 0 ? void 0 : _a.changeSet.get(suggestionId);
|
|
121
|
+
const decorations = [];
|
|
122
|
+
if (change) {
|
|
123
|
+
const decoration = change.type === 'text-change' ? prosemirror_view_1.Decoration.inline : prosemirror_view_1.Decoration.node;
|
|
124
|
+
decorations.push(decoration(change.from, change.to, {
|
|
125
|
+
class: 'selected-suggestion',
|
|
126
|
+
}));
|
|
127
|
+
setTimeout(() => {
|
|
128
|
+
props.setEditorSelectedSuggestion(change.id);
|
|
129
|
+
}, 0);
|
|
130
|
+
}
|
|
131
|
+
return prosemirror_view_1.DecorationSet.create(state.doc, decorations);
|
|
132
|
+
};
|
package/dist/cjs/useEditor.js
CHANGED
|
@@ -0,0 +1,76 @@
|
|
|
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.AffiliationView = void 0;
|
|
19
|
+
const track_changes_utils_1 = require("../lib/track-changes-utils");
|
|
20
|
+
const affiliations_1 = require("../plugins/affiliations");
|
|
21
|
+
const base_node_view_1 = require("./base_node_view");
|
|
22
|
+
const creators_1 = require("./creators");
|
|
23
|
+
class AffiliationView extends base_node_view_1.BaseNodeView {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments);
|
|
26
|
+
this.initialise = () => {
|
|
27
|
+
this.createDOM();
|
|
28
|
+
};
|
|
29
|
+
this.updateContents = () => {
|
|
30
|
+
var _a;
|
|
31
|
+
const attrs = this.node.attrs;
|
|
32
|
+
const pluginState = affiliations_1.affiliationsKey.getState(this.view.state);
|
|
33
|
+
this.dom.innerHTML = this.formatAddress((0, track_changes_utils_1.getActualAttrs)(this.node));
|
|
34
|
+
if (pluginState === null || pluginState === void 0 ? void 0 : pluginState.indexedAffiliationIds) {
|
|
35
|
+
const order = pluginState.indexedAffiliationIds.get(attrs.id);
|
|
36
|
+
this.dom.innerHTML = order
|
|
37
|
+
? `<b>${order}</b> ${this.dom.innerHTML}`
|
|
38
|
+
: this.dom.innerHTML;
|
|
39
|
+
this.dom.setAttribute('style', 'order: ' + (order || (pluginState === null || pluginState === void 0 ? void 0 : pluginState.affiliations.length) + 1));
|
|
40
|
+
}
|
|
41
|
+
if ((_a = attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.length) {
|
|
42
|
+
this.dom.setAttribute('data-track-id', attrs.dataTracked[0].id);
|
|
43
|
+
this.dom.setAttribute('data-track-status', attrs.dataTracked[0].status);
|
|
44
|
+
this.dom.setAttribute('data-track-op', attrs.dataTracked[0].operation);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.dom.removeAttribute('data-track-id');
|
|
48
|
+
this.dom.removeAttribute('data-track-status');
|
|
49
|
+
this.dom.removeAttribute('data-track-type');
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
this.createDOM = () => {
|
|
53
|
+
this.dom = document.createElement('div');
|
|
54
|
+
this.dom.classList.add('affiliation');
|
|
55
|
+
this.dom.setAttribute('id', this.node.attrs.id);
|
|
56
|
+
this.updateContents();
|
|
57
|
+
};
|
|
58
|
+
this.ignoreMutation = () => true;
|
|
59
|
+
this.formatAddress = (affiliation) => {
|
|
60
|
+
const { department, institution, addressLine1, city, county, country, postCode, } = affiliation;
|
|
61
|
+
return [
|
|
62
|
+
department,
|
|
63
|
+
institution,
|
|
64
|
+
addressLine1,
|
|
65
|
+
city,
|
|
66
|
+
county,
|
|
67
|
+
country,
|
|
68
|
+
postCode,
|
|
69
|
+
]
|
|
70
|
+
.filter(Boolean)
|
|
71
|
+
.join(', ');
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.AffiliationView = AffiliationView;
|
|
76
|
+
exports.default = (0, creators_1.createNodeView)(AffiliationView);
|