@manuscripts/body-editor 3.12.9 → 3.12.10

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.
@@ -37,6 +37,8 @@ const editor_props_1 = require("./plugins/editor-props");
37
37
  const search_replace_1 = require("./plugins/search-replace");
38
38
  const autocompletion_1 = require("./plugins/section_title/autocompletion");
39
39
  const persistent_cursor_1 = require("./plugins/persistent-cursor");
40
+ const AffiliationsModal_1 = require("./components/affiliations/AffiliationsModal");
41
+ const AuthorsModal_1 = require("./components/authors/AuthorsModal");
40
42
  const addToStart = (state, dispatch) => {
41
43
  const { selection } = state;
42
44
  const props = (0, editor_props_1.getEditorProps)(state);
@@ -745,10 +747,8 @@ const insertContributors = (state, dispatch, view) => {
745
747
  }
746
748
  if (dispatch) {
747
749
  const selection = prosemirror_state_1.NodeSelection.create(tr.doc, contributors.pos);
748
- if (view) {
749
- view.focus();
750
- }
751
750
  dispatch(tr.setSelection(selection).scrollIntoView());
751
+ (0, AuthorsModal_1.openAuthorsModal)(contributors.pos, view);
752
752
  }
753
753
  return true;
754
754
  };
@@ -769,10 +769,8 @@ const insertAffiliation = (state, dispatch, view) => {
769
769
  }
770
770
  if (dispatch) {
771
771
  const selection = prosemirror_state_1.NodeSelection.create(tr.doc, affiliations.pos);
772
- if (view) {
773
- view.focus();
774
- }
775
772
  dispatch(tr.setSelection(selection).scrollIntoView());
773
+ (0, AffiliationsModal_1.openAffiliationsModal)(affiliations.pos, view);
776
774
  }
777
775
  return true;
778
776
  };
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.AffiliationsModal = void 0;
39
+ exports.handleUpdateAuthors = exports.handleDeleteAffiliation = exports.handleSaveAffiliation = exports.openAffiliationsModal = exports.AffiliationsModal = void 0;
40
40
  const style_guide_1 = require("@manuscripts/style-guide");
41
41
  const transform_1 = require("@manuscripts/transform");
42
42
  const lodash_1 = require("lodash");
@@ -54,13 +54,16 @@ const GenericDrawer_1 = require("../modal-drawer/GenericDrawer");
54
54
  const GenericDrawerGroup_1 = require("../modal-drawer/GenericDrawerGroup");
55
55
  const AffiliationForm_1 = require("./AffiliationForm");
56
56
  const AffiliationList_1 = require("./AffiliationList");
57
+ const editor_props_1 = require("../../plugins/editor-props");
58
+ const ReactSubView_1 = __importDefault(require("../../views/ReactSubView"));
59
+ const view_1 = require("../../lib/view");
57
60
  function makeAuthorItems(authors) {
58
61
  return authors.map((author) => ({
59
62
  id: author.id,
60
63
  label: `${author.given} ${author.family}`,
61
64
  }));
62
65
  }
63
- const AffiliationsModal = ({ authors: $authors, affiliations: $affiliations, affiliation, onSaveAffiliation, onDeleteAffiliation, onUpdateAuthors, clearSelection, addNewAffiliation = false, }) => {
66
+ const AffiliationsModal = ({ authors: $authors, affiliations: $affiliations, affiliation, onSaveAffiliation, onDeleteAffiliation, onUpdateAuthors, addNewAffiliation = false, }) => {
64
67
  const [isOpen, setIsOpen] = (0, react_1.useState)(true);
65
68
  const [selection, setSelection] = (0, react_1.useState)(affiliation);
66
69
  const [showingDeleteDialog, setShowDeleteDialog] = (0, react_1.useState)(false);
@@ -113,8 +116,8 @@ const AffiliationsModal = ({ authors: $authors, affiliations: $affiliations, aff
113
116
  }
114
117
  else {
115
118
  setIsOpen(false);
119
+ setSelection(undefined);
116
120
  }
117
- clearSelection();
118
121
  };
119
122
  const handleSelect = (affiliation) => {
120
123
  const values = valuesRef.current;
@@ -441,3 +444,41 @@ const StyledModalSidebarHeader = (0, styled_components_1.default)(style_guide_1.
441
444
  margin-top: 8px;
442
445
  margin-bottom: 16px;
443
446
  `;
447
+ const openAffiliationsModal = (pos, view) => {
448
+ if (!view) {
449
+ return;
450
+ }
451
+ const { state } = view;
452
+ const props = (0, editor_props_1.getEditorProps)(state);
453
+ const contributors = (0, view_1.findChildrenAttrsByType)(view, transform_1.schema.nodes.contributor);
454
+ const componentProps = {
455
+ affiliations: [],
456
+ authors: contributors,
457
+ onSaveAffiliation: (affiliation) => (0, exports.handleSaveAffiliation)(view, affiliation, pos),
458
+ onDeleteAffiliation: (affiliation) => (0, exports.handleDeleteAffiliation)(view, affiliation),
459
+ onUpdateAuthors: (authors) => (0, exports.handleUpdateAuthors)(view, authors),
460
+ addNewAffiliation: true,
461
+ };
462
+ const dialog = (0, ReactSubView_1.default)(props, exports.AffiliationsModal, componentProps, state.doc, () => pos, view);
463
+ view.focus();
464
+ document.body.appendChild(dialog);
465
+ };
466
+ exports.openAffiliationsModal = openAffiliationsModal;
467
+ const handleSaveAffiliation = (view, affiliation, affiliationsPos) => {
468
+ const update = (0, view_1.updateNodeAttrs)(view, transform_1.schema.nodes.affiliation, affiliation);
469
+ if (!update) {
470
+ const node = transform_1.schema.nodes.affiliation.create(affiliation);
471
+ view.dispatch(view.state.tr.insert(affiliationsPos + 1, node));
472
+ }
473
+ };
474
+ exports.handleSaveAffiliation = handleSaveAffiliation;
475
+ const handleDeleteAffiliation = (view, affiliation) => {
476
+ (0, view_1.deleteNode)(view, affiliation.id);
477
+ };
478
+ exports.handleDeleteAffiliation = handleDeleteAffiliation;
479
+ const handleUpdateAuthors = (view, authors) => {
480
+ authors.forEach((author) => {
481
+ (0, view_1.updateNodeAttrs)(view, transform_1.schema.nodes.contributor, author);
482
+ });
483
+ };
484
+ exports.handleUpdateAuthors = handleUpdateAuthors;
@@ -51,7 +51,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
51
51
  return (mod && mod.__esModule) ? mod : { "default": mod };
52
52
  };
53
53
  Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.AuthorsModal = exports.authorsReducer = void 0;
54
+ exports.handleDeleteContributor = exports.handleSaveContributor = exports.openAuthorsModal = exports.AuthorsModal = exports.authorsReducer = void 0;
55
55
  const style_guide_1 = require("@manuscripts/style-guide");
56
56
  const transform_1 = require("@manuscripts/transform");
57
57
  const lodash_1 = require("lodash");
@@ -71,6 +71,9 @@ const AuthorList_1 = require("./AuthorList");
71
71
  const CreditDrawer_1 = require("./CreditDrawer");
72
72
  const useManageAffiliations_1 = require("./useManageAffiliations");
73
73
  const useManageCredit_1 = require("./useManageCredit");
74
+ const editor_props_1 = require("../../plugins/editor-props");
75
+ const ReactSubView_1 = __importDefault(require("../../views/ReactSubView"));
76
+ const view_1 = require("../../lib/view");
74
77
  exports.authorsReducer = (0, array_reducer_1.arrayReducer)((a, b) => a.id === b.id);
75
78
  const AuthorsModal = ({ authors: $authors, affiliations: $affiliations, author, onSaveAuthor, onDeleteAuthor, addNewAuthor = false, }) => {
76
79
  const [isOpen, setOpen] = (0, react_1.useState)(true);
@@ -151,6 +154,7 @@ const AuthorsModal = ({ authors: $authors, affiliations: $affiliations, author,
151
154
  setShowRequiredFieldConfirmationDialog(false);
152
155
  setLastSavedAuthor(null);
153
156
  setOpen(false);
157
+ setSelection(undefined);
154
158
  }
155
159
  };
156
160
  const save = () => {
@@ -424,3 +428,34 @@ const StyledModalBody = (0, styled_components_1.default)(style_guide_1.ModalBody
424
428
  const StyledModalSidebarHeader = (0, styled_components_1.default)(style_guide_1.ModalSidebarHeader) `
425
429
  margin-bottom: 16px;
426
430
  `;
431
+ const openAuthorsModal = (pos, view) => {
432
+ if (!view) {
433
+ return;
434
+ }
435
+ const { state } = view;
436
+ const props = (0, editor_props_1.getEditorProps)(state);
437
+ const affiliations = (0, view_1.findChildrenAttrsByType)(view, transform_1.schema.nodes.affiliation);
438
+ const componentProps = {
439
+ authors: [],
440
+ affiliations,
441
+ onSaveAuthor: (contributor) => (0, exports.handleSaveContributor)(view, contributor, pos),
442
+ onDeleteAuthor: (contributor) => (0, exports.handleDeleteContributor)(view, contributor),
443
+ addNewAuthor: true,
444
+ };
445
+ const dialog = (0, ReactSubView_1.default)(props, exports.AuthorsModal, componentProps, state.doc, () => pos, view);
446
+ view.focus();
447
+ document.body.appendChild(dialog);
448
+ };
449
+ exports.openAuthorsModal = openAuthorsModal;
450
+ const handleSaveContributor = (view, contributor, contributorsPos) => {
451
+ const update = (0, view_1.updateNodeAttrs)(view, transform_1.schema.nodes.contributor, contributor);
452
+ if (!update) {
453
+ const node = transform_1.schema.nodes.contributor.create(contributor);
454
+ view.dispatch(view.state.tr.insert(contributorsPos + 1, node));
455
+ }
456
+ };
457
+ exports.handleSaveContributor = handleSaveContributor;
458
+ const handleDeleteContributor = (view, contributor) => {
459
+ (0, view_1.deleteNode)(view, contributor.id);
460
+ };
461
+ exports.handleDeleteContributor = handleDeleteContributor;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MATHJAX_VERSION = exports.VERSION = void 0;
4
- exports.VERSION = '3.12.9';
4
+ exports.VERSION = '3.12.10';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -56,21 +56,6 @@ class AffiliationsView extends block_view_1.default {
56
56
  tr.setSelection(prosemirror_state_1.NodeSelection.create(view.state.doc, pos));
57
57
  view.dispatch(tr);
58
58
  };
59
- this.insertAffiliationNode = (attrs) => {
60
- const pos = this.getPos();
61
- const tr = this.view.state.tr;
62
- const node = transform_1.schema.nodes.affiliation.create(attrs);
63
- this.view.dispatch(tr.insert(pos + 1, node));
64
- };
65
- this.handleSaveAffiliation = (affiliation) => {
66
- const update = (0, view_1.updateNodeAttrs)(this.view, transform_1.schema.nodes.affiliation, affiliation);
67
- if (!update) {
68
- this.insertAffiliationNode(affiliation);
69
- }
70
- };
71
- this.handleDeleteAffiliation = (affiliation) => {
72
- (0, view_1.deleteNode)(this.view, affiliation.id);
73
- };
74
59
  this.handleEdit = (id, addNew) => {
75
60
  this.props.popper.destroy();
76
61
  const contributors = (0, view_1.findChildrenAttrsByType)(this.view, transform_1.schema.nodes.contributor);
@@ -82,11 +67,10 @@ class AffiliationsView extends block_view_1.default {
82
67
  affiliation,
83
68
  authors: contributors,
84
69
  affiliations,
85
- onSaveAffiliation: this.handleSaveAffiliation,
86
- onDeleteAffiliation: this.handleDeleteAffiliation,
87
- onUpdateAuthors: this.handleUpdateAuthors,
70
+ onSaveAffiliation: (affiliation) => (0, AffiliationsModal_1.handleSaveAffiliation)(this.view, affiliation, this.getPos()),
71
+ onDeleteAffiliation: (affiliation) => (0, AffiliationsModal_1.handleDeleteAffiliation)(this.view, affiliation),
72
+ onUpdateAuthors: (authors) => (0, AffiliationsModal_1.handleUpdateAuthors)(this.view, authors),
88
73
  addNewAffiliation: addNew,
89
- clearSelection: this.clearSelection,
90
74
  };
91
75
  this.popper?.remove();
92
76
  this.popper = (0, ReactSubView_1.default)(this.props, AffiliationsModal_1.AffiliationsModal, componentProps, this.node, this.getPos, this.view);
@@ -137,22 +121,6 @@ class AffiliationsView extends block_view_1.default {
137
121
  const contextMenu = this.showGroupContextMenu();
138
122
  return contextMenu ? [contextMenu] : [];
139
123
  };
140
- this.selectNode = () => {
141
- const selectedMarker = document.querySelector('.comment-marker.selected-comment');
142
- this.dom.classList.add('ProseMirror-selectednode');
143
- if (!(0, track_changes_plugin_1.isDeleted)(this.node) && !selectedMarker) {
144
- this.handleEdit('', true);
145
- }
146
- };
147
- this.clearSelection = () => {
148
- const { state, dispatch } = this.view;
149
- dispatch(state.tr.setSelection(prosemirror_state_1.Selection.atStart(state.doc)));
150
- };
151
- this.handleUpdateAuthors = (authors) => {
152
- authors.forEach((author) => {
153
- (0, view_1.updateNodeAttrs)(this.view, transform_1.schema.nodes.contributor, author);
154
- });
155
- };
156
124
  }
157
125
  createElement() {
158
126
  this.container = document.createElement('div');
@@ -27,7 +27,6 @@ const AuthorsModal_1 = require("../components/authors/AuthorsModal");
27
27
  const authors_1 = require("../lib/authors");
28
28
  const comments_1 = require("../lib/comments");
29
29
  const navigation_utils_1 = require("../lib/navigation-utils");
30
- const utils_1 = require("../lib/utils");
31
30
  const view_1 = require("../lib/view");
32
31
  const affiliations_1 = require("../plugins/affiliations");
33
32
  const selected_suggestion_1 = require("../plugins/selected-suggestion");
@@ -40,13 +39,6 @@ class ContributorsView extends block_view_1.default {
40
39
  super(...arguments);
41
40
  this.ignoreMutation = () => true;
42
41
  this.stopEvent = () => true;
43
- this.selectNode = () => {
44
- const selectedMarker = document.querySelector('.comment-marker.selected-comment');
45
- this.dom.classList.add('ProseMirror-selectednode');
46
- if (!(0, track_changes_plugin_1.isDeleted)(this.node) && !selectedMarker) {
47
- this.handleEdit('', true);
48
- }
49
- };
50
42
  this.buildAuthors = (affs) => {
51
43
  const wrapper = document.createElement('div');
52
44
  wrapper.classList.add('contributors-list');
@@ -230,46 +222,14 @@ class ContributorsView extends block_view_1.default {
230
222
  author,
231
223
  authors: contributors,
232
224
  affiliations,
233
- onSaveAuthor: this.handleSaveAuthor,
234
- onDeleteAuthor: this.handleDeleteAuthor,
225
+ onSaveAuthor: (contributor) => (0, AuthorsModal_1.handleSaveContributor)(this.view, contributor, this.getPos()),
226
+ onDeleteAuthor: (contributor) => (0, AuthorsModal_1.handleDeleteContributor)(this.view, contributor),
235
227
  addNewAuthor: addNew,
236
228
  };
237
229
  this.popper?.remove();
238
230
  this.popper = (0, ReactSubView_1.default)(this.props, AuthorsModal_1.AuthorsModal, componentProps, this.node, this.getPos, this.view);
239
231
  this.container.appendChild(this.popper);
240
232
  };
241
- this.handleSaveAuthor = (author) => {
242
- const update = (0, view_1.updateNodeAttrs)(this.view, transform_1.schema.nodes.contributor, author);
243
- if (!update) {
244
- this.insertAuthorNode(author);
245
- }
246
- };
247
- this.handleDeleteAuthor = (author) => {
248
- (0, view_1.deleteNode)(this.view, author.id);
249
- };
250
- this.insertAuthorNode = (attrs) => {
251
- const parent = (0, view_1.findChildByType)(this.view, transform_1.schema.nodes.contributors);
252
- const tr = this.view.state.tr;
253
- const node = transform_1.schema.nodes.contributor.create(attrs);
254
- this.view.dispatch(tr.insert(parent.pos + 1, node));
255
- };
256
- this.insertAffiliationNode = (attrs) => {
257
- const { view } = this;
258
- const { dispatch } = view;
259
- const affiliationsNodeType = transform_1.schema.nodes.affiliations;
260
- let affiliations = (0, view_1.findChildByType)(view, affiliationsNodeType);
261
- if (!affiliations) {
262
- const { tr } = this.view.state;
263
- const insertPos = (0, utils_1.findInsertionPosition)(transform_1.schema.nodes.affiliations, view.state.doc);
264
- dispatch(tr.insert(insertPos, transform_1.schema.nodes.affiliations.create()));
265
- affiliations = (0, view_1.findChildByType)(view, affiliationsNodeType);
266
- }
267
- if (affiliations) {
268
- const { tr } = this.view.state;
269
- const affiliationNode = transform_1.schema.nodes.affiliation.create(attrs);
270
- dispatch(tr.insert(affiliations.pos + 1, affiliationNode));
271
- }
272
- };
273
233
  }
274
234
  updateContents() {
275
235
  super.updateContents();
@@ -33,6 +33,8 @@ import { getEditorProps } from './plugins/editor-props';
33
33
  import { searchReplaceKey } from './plugins/search-replace';
34
34
  import { checkForCompletion } from './plugins/section_title/autocompletion';
35
35
  import { persistentCursor } from './plugins/persistent-cursor';
36
+ import { openAffiliationsModal } from './components/affiliations/AffiliationsModal';
37
+ import { openAuthorsModal } from './components/authors/AuthorsModal';
36
38
  export const addToStart = (state, dispatch) => {
37
39
  const { selection } = state;
38
40
  const props = getEditorProps(state);
@@ -710,10 +712,8 @@ export const insertContributors = (state, dispatch, view) => {
710
712
  }
711
713
  if (dispatch) {
712
714
  const selection = NodeSelection.create(tr.doc, contributors.pos);
713
- if (view) {
714
- view.focus();
715
- }
716
715
  dispatch(tr.setSelection(selection).scrollIntoView());
716
+ openAuthorsModal(contributors.pos, view);
717
717
  }
718
718
  return true;
719
719
  };
@@ -733,10 +733,8 @@ export const insertAffiliation = (state, dispatch, view) => {
733
733
  }
734
734
  if (dispatch) {
735
735
  const selection = NodeSelection.create(tr.doc, affiliations.pos);
736
- if (view) {
737
- view.focus();
738
- }
739
736
  dispatch(tr.setSelection(selection).scrollIntoView());
737
+ openAffiliationsModal(affiliations.pos, view);
740
738
  }
741
739
  return true;
742
740
  };
@@ -15,13 +15,16 @@ import { GenericDrawer } from '../modal-drawer/GenericDrawer';
15
15
  import { DrawerGroup } from '../modal-drawer/GenericDrawerGroup';
16
16
  import { AffiliationForm } from './AffiliationForm';
17
17
  import { AffiliationList } from './AffiliationList';
18
+ import { getEditorProps } from '../../plugins/editor-props';
19
+ import ReactSubView from '../../views/ReactSubView';
20
+ import { deleteNode, findChildrenAttrsByType, updateNodeAttrs, } from '../../lib/view';
18
21
  function makeAuthorItems(authors) {
19
22
  return authors.map((author) => ({
20
23
  id: author.id,
21
24
  label: `${author.given} ${author.family}`,
22
25
  }));
23
26
  }
24
- export const AffiliationsModal = ({ authors: $authors, affiliations: $affiliations, affiliation, onSaveAffiliation, onDeleteAffiliation, onUpdateAuthors, clearSelection, addNewAffiliation = false, }) => {
27
+ export const AffiliationsModal = ({ authors: $authors, affiliations: $affiliations, affiliation, onSaveAffiliation, onDeleteAffiliation, onUpdateAuthors, addNewAffiliation = false, }) => {
25
28
  const [isOpen, setIsOpen] = useState(true);
26
29
  const [selection, setSelection] = useState(affiliation);
27
30
  const [showingDeleteDialog, setShowDeleteDialog] = useState(false);
@@ -74,8 +77,8 @@ export const AffiliationsModal = ({ authors: $authors, affiliations: $affiliatio
74
77
  }
75
78
  else {
76
79
  setIsOpen(false);
80
+ setSelection(undefined);
77
81
  }
78
- clearSelection();
79
82
  };
80
83
  const handleSelect = (affiliation) => {
81
84
  const values = valuesRef.current;
@@ -401,3 +404,37 @@ const StyledModalSidebarHeader = styled(ModalSidebarHeader) `
401
404
  margin-top: 8px;
402
405
  margin-bottom: 16px;
403
406
  `;
407
+ export const openAffiliationsModal = (pos, view) => {
408
+ if (!view) {
409
+ return;
410
+ }
411
+ const { state } = view;
412
+ const props = getEditorProps(state);
413
+ const contributors = findChildrenAttrsByType(view, schema.nodes.contributor);
414
+ const componentProps = {
415
+ affiliations: [],
416
+ authors: contributors,
417
+ onSaveAffiliation: (affiliation) => handleSaveAffiliation(view, affiliation, pos),
418
+ onDeleteAffiliation: (affiliation) => handleDeleteAffiliation(view, affiliation),
419
+ onUpdateAuthors: (authors) => handleUpdateAuthors(view, authors),
420
+ addNewAffiliation: true,
421
+ };
422
+ const dialog = ReactSubView(props, AffiliationsModal, componentProps, state.doc, () => pos, view);
423
+ view.focus();
424
+ document.body.appendChild(dialog);
425
+ };
426
+ export const handleSaveAffiliation = (view, affiliation, affiliationsPos) => {
427
+ const update = updateNodeAttrs(view, schema.nodes.affiliation, affiliation);
428
+ if (!update) {
429
+ const node = schema.nodes.affiliation.create(affiliation);
430
+ view.dispatch(view.state.tr.insert(affiliationsPos + 1, node));
431
+ }
432
+ };
433
+ export const handleDeleteAffiliation = (view, affiliation) => {
434
+ deleteNode(view, affiliation.id);
435
+ };
436
+ export const handleUpdateAuthors = (view, authors) => {
437
+ authors.forEach((author) => {
438
+ updateNodeAttrs(view, schema.nodes.contributor, author);
439
+ });
440
+ };
@@ -32,6 +32,9 @@ import { AuthorList } from './AuthorList';
32
32
  import { CreditDrawer } from './CreditDrawer';
33
33
  import { useManageAffiliations } from './useManageAffiliations';
34
34
  import { useManageCredit } from './useManageCredit';
35
+ import { getEditorProps } from '../../plugins/editor-props';
36
+ import ReactSubView from '../../views/ReactSubView';
37
+ import { deleteNode, findChildrenAttrsByType, updateNodeAttrs, } from '../../lib/view';
35
38
  export const authorsReducer = arrayReducer((a, b) => a.id === b.id);
36
39
  export const AuthorsModal = ({ authors: $authors, affiliations: $affiliations, author, onSaveAuthor, onDeleteAuthor, addNewAuthor = false, }) => {
37
40
  const [isOpen, setOpen] = useState(true);
@@ -112,6 +115,7 @@ export const AuthorsModal = ({ authors: $authors, affiliations: $affiliations, a
112
115
  setShowRequiredFieldConfirmationDialog(false);
113
116
  setLastSavedAuthor(null);
114
117
  setOpen(false);
118
+ setSelection(undefined);
115
119
  }
116
120
  };
117
121
  const save = () => {
@@ -384,3 +388,31 @@ const StyledModalBody = styled(ModalBody) `
384
388
  const StyledModalSidebarHeader = styled(ModalSidebarHeader) `
385
389
  margin-bottom: 16px;
386
390
  `;
391
+ export const openAuthorsModal = (pos, view) => {
392
+ if (!view) {
393
+ return;
394
+ }
395
+ const { state } = view;
396
+ const props = getEditorProps(state);
397
+ const affiliations = findChildrenAttrsByType(view, schema.nodes.affiliation);
398
+ const componentProps = {
399
+ authors: [],
400
+ affiliations,
401
+ onSaveAuthor: (contributor) => handleSaveContributor(view, contributor, pos),
402
+ onDeleteAuthor: (contributor) => handleDeleteContributor(view, contributor),
403
+ addNewAuthor: true,
404
+ };
405
+ const dialog = ReactSubView(props, AuthorsModal, componentProps, state.doc, () => pos, view);
406
+ view.focus();
407
+ document.body.appendChild(dialog);
408
+ };
409
+ export const handleSaveContributor = (view, contributor, contributorsPos) => {
410
+ const update = updateNodeAttrs(view, schema.nodes.contributor, contributor);
411
+ if (!update) {
412
+ const node = schema.nodes.contributor.create(contributor);
413
+ view.dispatch(view.state.tr.insert(contributorsPos + 1, node));
414
+ }
415
+ };
416
+ export const handleDeleteContributor = (view, contributor) => {
417
+ deleteNode(view, contributor.id);
418
+ };
@@ -1,2 +1,2 @@
1
- export const VERSION = '3.12.9';
1
+ export const VERSION = '3.12.10';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -16,12 +16,12 @@
16
16
  import { ContextMenu } from '@manuscripts/style-guide';
17
17
  import { addTrackChangesAttributes, isDeleted, } from '@manuscripts/track-changes-plugin';
18
18
  import { schema } from '@manuscripts/transform';
19
- import { NodeSelection, Selection } from 'prosemirror-state';
20
- import { AffiliationsModal, } from '../components/affiliations/AffiliationsModal';
19
+ import { NodeSelection } from 'prosemirror-state';
20
+ import { AffiliationsModal, handleDeleteAffiliation, handleSaveAffiliation, handleUpdateAuthors, } from '../components/affiliations/AffiliationsModal';
21
21
  import { alertIcon } from '../icons';
22
22
  import { affiliationName, } from '../lib/authors';
23
23
  import { handleComment } from '../lib/comments';
24
- import { deleteNode, findChildByID, findChildrenAttrsByType, updateNodeAttrs, } from '../lib/view';
24
+ import { findChildByID, findChildrenAttrsByType, } from '../lib/view';
25
25
  import { affiliationsKey } from '../plugins/affiliations';
26
26
  import { selectedSuggestionKey } from '../plugins/selected-suggestion';
27
27
  import BlockView from './block_view';
@@ -50,21 +50,6 @@ export class AffiliationsView extends BlockView {
50
50
  tr.setSelection(NodeSelection.create(view.state.doc, pos));
51
51
  view.dispatch(tr);
52
52
  };
53
- this.insertAffiliationNode = (attrs) => {
54
- const pos = this.getPos();
55
- const tr = this.view.state.tr;
56
- const node = schema.nodes.affiliation.create(attrs);
57
- this.view.dispatch(tr.insert(pos + 1, node));
58
- };
59
- this.handleSaveAffiliation = (affiliation) => {
60
- const update = updateNodeAttrs(this.view, schema.nodes.affiliation, affiliation);
61
- if (!update) {
62
- this.insertAffiliationNode(affiliation);
63
- }
64
- };
65
- this.handleDeleteAffiliation = (affiliation) => {
66
- deleteNode(this.view, affiliation.id);
67
- };
68
53
  this.handleEdit = (id, addNew) => {
69
54
  this.props.popper.destroy();
70
55
  const contributors = findChildrenAttrsByType(this.view, schema.nodes.contributor);
@@ -76,11 +61,10 @@ export class AffiliationsView extends BlockView {
76
61
  affiliation,
77
62
  authors: contributors,
78
63
  affiliations,
79
- onSaveAffiliation: this.handleSaveAffiliation,
80
- onDeleteAffiliation: this.handleDeleteAffiliation,
81
- onUpdateAuthors: this.handleUpdateAuthors,
64
+ onSaveAffiliation: (affiliation) => handleSaveAffiliation(this.view, affiliation, this.getPos()),
65
+ onDeleteAffiliation: (affiliation) => handleDeleteAffiliation(this.view, affiliation),
66
+ onUpdateAuthors: (authors) => handleUpdateAuthors(this.view, authors),
82
67
  addNewAffiliation: addNew,
83
- clearSelection: this.clearSelection,
84
68
  };
85
69
  this.popper?.remove();
86
70
  this.popper = ReactSubView(this.props, AffiliationsModal, componentProps, this.node, this.getPos, this.view);
@@ -131,22 +115,6 @@ export class AffiliationsView extends BlockView {
131
115
  const contextMenu = this.showGroupContextMenu();
132
116
  return contextMenu ? [contextMenu] : [];
133
117
  };
134
- this.selectNode = () => {
135
- const selectedMarker = document.querySelector('.comment-marker.selected-comment');
136
- this.dom.classList.add('ProseMirror-selectednode');
137
- if (!isDeleted(this.node) && !selectedMarker) {
138
- this.handleEdit('', true);
139
- }
140
- };
141
- this.clearSelection = () => {
142
- const { state, dispatch } = this.view;
143
- dispatch(state.tr.setSelection(Selection.atStart(state.doc)));
144
- };
145
- this.handleUpdateAuthors = (authors) => {
146
- authors.forEach((author) => {
147
- updateNodeAttrs(this.view, schema.nodes.contributor, author);
148
- });
149
- };
150
118
  }
151
119
  createElement() {
152
120
  this.container = document.createElement('div');
@@ -17,12 +17,11 @@ import { ContextMenu } from '@manuscripts/style-guide';
17
17
  import { addTrackChangesAttributes, isDeleted, } from '@manuscripts/track-changes-plugin';
18
18
  import { schema } from '@manuscripts/transform';
19
19
  import { NodeSelection } from 'prosemirror-state';
20
- import { AuthorsModal, } from '../components/authors/AuthorsModal';
20
+ import { AuthorsModal, handleDeleteContributor, handleSaveContributor, } from '../components/authors/AuthorsModal';
21
21
  import { authorComparator, authorLabel, } from '../lib/authors';
22
22
  import { handleComment } from '../lib/comments';
23
23
  import { createKeyboardInteraction } from '../lib/navigation-utils';
24
- import { findInsertionPosition } from '../lib/utils';
25
- import { deleteNode, findChildByID, findChildByType, findChildrenAttrsByType, updateNodeAttrs, } from '../lib/view';
24
+ import { findChildByID, findChildrenAttrsByType, } from '../lib/view';
26
25
  import { affiliationsKey } from '../plugins/affiliations';
27
26
  import { selectedSuggestionKey } from '../plugins/selected-suggestion';
28
27
  import BlockView from './block_view';
@@ -34,13 +33,6 @@ export class ContributorsView extends BlockView {
34
33
  super(...arguments);
35
34
  this.ignoreMutation = () => true;
36
35
  this.stopEvent = () => true;
37
- this.selectNode = () => {
38
- const selectedMarker = document.querySelector('.comment-marker.selected-comment');
39
- this.dom.classList.add('ProseMirror-selectednode');
40
- if (!isDeleted(this.node) && !selectedMarker) {
41
- this.handleEdit('', true);
42
- }
43
- };
44
36
  this.buildAuthors = (affs) => {
45
37
  const wrapper = document.createElement('div');
46
38
  wrapper.classList.add('contributors-list');
@@ -224,46 +216,14 @@ export class ContributorsView extends BlockView {
224
216
  author,
225
217
  authors: contributors,
226
218
  affiliations,
227
- onSaveAuthor: this.handleSaveAuthor,
228
- onDeleteAuthor: this.handleDeleteAuthor,
219
+ onSaveAuthor: (contributor) => handleSaveContributor(this.view, contributor, this.getPos()),
220
+ onDeleteAuthor: (contributor) => handleDeleteContributor(this.view, contributor),
229
221
  addNewAuthor: addNew,
230
222
  };
231
223
  this.popper?.remove();
232
224
  this.popper = ReactSubView(this.props, AuthorsModal, componentProps, this.node, this.getPos, this.view);
233
225
  this.container.appendChild(this.popper);
234
226
  };
235
- this.handleSaveAuthor = (author) => {
236
- const update = updateNodeAttrs(this.view, schema.nodes.contributor, author);
237
- if (!update) {
238
- this.insertAuthorNode(author);
239
- }
240
- };
241
- this.handleDeleteAuthor = (author) => {
242
- deleteNode(this.view, author.id);
243
- };
244
- this.insertAuthorNode = (attrs) => {
245
- const parent = findChildByType(this.view, schema.nodes.contributors);
246
- const tr = this.view.state.tr;
247
- const node = schema.nodes.contributor.create(attrs);
248
- this.view.dispatch(tr.insert(parent.pos + 1, node));
249
- };
250
- this.insertAffiliationNode = (attrs) => {
251
- const { view } = this;
252
- const { dispatch } = view;
253
- const affiliationsNodeType = schema.nodes.affiliations;
254
- let affiliations = findChildByType(view, affiliationsNodeType);
255
- if (!affiliations) {
256
- const { tr } = this.view.state;
257
- const insertPos = findInsertionPosition(schema.nodes.affiliations, view.state.doc);
258
- dispatch(tr.insert(insertPos, schema.nodes.affiliations.create()));
259
- affiliations = findChildByType(view, affiliationsNodeType);
260
- }
261
- if (affiliations) {
262
- const { tr } = this.view.state;
263
- const affiliationNode = schema.nodes.affiliation.create(attrs);
264
- dispatch(tr.insert(affiliations.pos + 1, affiliationNode));
265
- }
266
- };
267
227
  }
268
228
  updateContents() {
269
229
  super.updateContents();
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { AffiliationAttrs, ContributorAttrs } from '../../lib/authors';
3
+ import { EditorView } from 'prosemirror-view';
3
4
  export interface AffiliationsModalProps {
4
5
  affiliation?: AffiliationAttrs;
5
6
  authors: ContributorAttrs[];
@@ -7,7 +8,10 @@ export interface AffiliationsModalProps {
7
8
  onSaveAffiliation: (affiliation: AffiliationAttrs) => void;
8
9
  onDeleteAffiliation: (affiliation: AffiliationAttrs) => void;
9
10
  onUpdateAuthors: (authors: ContributorAttrs[]) => void;
10
- clearSelection: () => void;
11
11
  addNewAffiliation?: boolean;
12
12
  }
13
13
  export declare const AffiliationsModal: React.FC<AffiliationsModalProps>;
14
+ export declare const openAffiliationsModal: (pos: number, view?: EditorView) => void;
15
+ export declare const handleSaveAffiliation: (view: EditorView, affiliation: AffiliationAttrs, affiliationsPos: number) => void;
16
+ export declare const handleDeleteAffiliation: (view: EditorView, affiliation: AffiliationAttrs) => void;
17
+ export declare const handleUpdateAuthors: (view: EditorView, authors: ContributorAttrs[]) => void;
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import React from 'react';
17
17
  import { AffiliationAttrs, ContributorAttrs } from '../../lib/authors';
18
+ import { EditorView } from 'prosemirror-view';
18
19
  export declare const authorsReducer: (state: ContributorAttrs[], action: import("../../lib/array-reducer").Action<ContributorAttrs>) => ContributorAttrs[];
19
20
  export interface AuthorsModalProps {
20
21
  author?: ContributorAttrs;
@@ -25,3 +26,6 @@ export interface AuthorsModalProps {
25
26
  addNewAuthor?: boolean;
26
27
  }
27
28
  export declare const AuthorsModal: React.FC<AuthorsModalProps>;
29
+ export declare const openAuthorsModal: (pos: number, view?: EditorView) => void;
30
+ export declare const handleSaveContributor: (view: EditorView, contributor: ContributorAttrs, contributorsPos: number) => void;
31
+ export declare const handleDeleteContributor: (view: EditorView, contributor: ContributorAttrs) => void;
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "3.12.9";
1
+ export declare const VERSION = "3.12.10";
2
2
  export declare const MATHJAX_VERSION = "3.2.2";
@@ -14,7 +14,6 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { AffiliationNode } from '@manuscripts/transform';
17
- import { AffiliationAttrs, ContributorAttrs } from '../lib/authors';
18
17
  import { Trackable } from '../types';
19
18
  import BlockView from './block_view';
20
19
  export declare class AffiliationsView extends BlockView<Trackable<AffiliationNode>> {
@@ -31,16 +30,10 @@ export declare class AffiliationsView extends BlockView<Trackable<AffiliationNod
31
30
  private sortAffiliations;
32
31
  private handleClick;
33
32
  private updateSelection;
34
- insertAffiliationNode: (attrs: AffiliationAttrs) => void;
35
- handleSaveAffiliation: (affiliation: AffiliationAttrs) => void;
36
- handleDeleteAffiliation: (affiliation: AffiliationAttrs) => void;
37
33
  handleEdit: (id: string, addNew?: boolean) => void;
38
34
  showGroupContextMenu: () => HTMLElement | undefined;
39
35
  showContextMenu: (element: Element) => void;
40
36
  actionGutterButtons: () => HTMLElement[];
41
- selectNode: () => void;
42
- clearSelection: () => void;
43
- handleUpdateAuthors: (authors: ContributorAttrs[]) => void;
44
37
  }
45
38
  declare const _default: (props: import("../configs/ManuscriptsEditor").EditorProps, dispatch?: import("..").Dispatch) => import("../types").NodeViewCreator<AffiliationsView>;
46
39
  export default _default;
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { ContributorsNode } from '@manuscripts/transform';
17
- import { AffiliationAttrs, ContributorAttrs } from '../lib/authors';
17
+ import { ContributorAttrs } from '../lib/authors';
18
18
  import { PluginState } from '../plugins/affiliations';
19
19
  import { Trackable } from '../types';
20
20
  import BlockView from './block_view';
@@ -28,7 +28,6 @@ export declare class ContributorsView extends BlockView<Trackable<ContributorsNo
28
28
  stopEvent: () => boolean;
29
29
  private removeKeydownListener?;
30
30
  updateContents(): void;
31
- selectNode: () => void;
32
31
  buildAuthors: (affs: PluginState) => void;
33
32
  buildAuthor: (attrs: ContributorAttrs, isJointFirstAuthor: boolean, index: number) => HTMLSpanElement;
34
33
  private createNote;
@@ -42,10 +41,6 @@ export declare class ContributorsView extends BlockView<Trackable<ContributorsNo
42
41
  private updateSelection;
43
42
  showContextMenu: (element: Element) => void;
44
43
  handleEdit: (id: string, addNew?: boolean) => void;
45
- handleSaveAuthor: (author: ContributorAttrs) => void;
46
- handleDeleteAuthor: (author: ContributorAttrs) => void;
47
- insertAuthorNode: (attrs: ContributorAttrs) => void;
48
- insertAffiliationNode: (attrs: AffiliationAttrs) => void;
49
44
  destroy(): void;
50
45
  }
51
46
  declare const _default: (props: import("../configs/ManuscriptsEditor").EditorProps, dispatch?: import("..").Dispatch) => import("../types").NodeViewCreator<ContributorsView>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@manuscripts/body-editor",
3
3
  "description": "Prosemirror components for editing and viewing manuscripts",
4
- "version": "3.12.9",
4
+ "version": "3.12.10",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",