@manuscripts/body-editor 1.6.20 → 1.7.0-LEAN-3181-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.
Files changed (52) hide show
  1. package/dist/cjs/components/views/FigureDropdown.js +4 -4
  2. package/dist/cjs/configs/editor-plugins.js +3 -1
  3. package/dist/cjs/configs/editor-views.js +5 -0
  4. package/dist/cjs/index.js +1 -0
  5. package/dist/cjs/lib/track-changes-utils.js +11 -1
  6. package/dist/cjs/plugins/affiliations.js +118 -0
  7. package/dist/cjs/plugins/bibliography/bibliography-utils.js +3 -3
  8. package/dist/cjs/plugins/bibliography/index.js +4 -4
  9. package/dist/cjs/plugins/toc.js +6 -40
  10. package/dist/cjs/testing/default-editor-data.js +0 -5
  11. package/dist/cjs/views/affiliation.js +75 -0
  12. package/dist/cjs/views/affiliations.js +24 -0
  13. package/dist/cjs/views/contributors.js +150 -11
  14. package/dist/cjs/views/figure_editable.js +4 -6
  15. package/dist/cjs/views/figure_element.js +2 -5
  16. package/dist/cjs/views/keyword.js +2 -1
  17. package/dist/es/components/views/FigureDropdown.js +4 -4
  18. package/dist/es/configs/editor-plugins.js +3 -1
  19. package/dist/es/configs/editor-views.js +5 -0
  20. package/dist/es/index.js +1 -0
  21. package/dist/es/lib/track-changes-utils.js +9 -0
  22. package/dist/es/plugins/affiliations.js +114 -0
  23. package/dist/es/plugins/bibliography/bibliography-utils.js +3 -3
  24. package/dist/es/plugins/bibliography/index.js +4 -4
  25. package/dist/es/plugins/toc.js +9 -43
  26. package/dist/es/testing/default-editor-data.js +0 -5
  27. package/dist/es/views/affiliation.js +71 -0
  28. package/dist/es/views/affiliations.js +17 -0
  29. package/dist/es/views/contributors.js +150 -11
  30. package/dist/es/views/figure_editable.js +4 -6
  31. package/dist/es/views/figure_element.js +2 -5
  32. package/dist/es/views/keyword.js +2 -1
  33. package/dist/types/components/views/FigureDropdown.d.ts +1 -1
  34. package/dist/types/configs/ManuscriptsEditor.d.ts +3 -3
  35. package/dist/types/configs/editor-plugins.d.ts +1 -3
  36. package/dist/types/configs/editor-views.d.ts +5 -0
  37. package/dist/types/index.d.ts +1 -0
  38. package/dist/types/lib/track-changes-utils.d.ts +2 -0
  39. package/dist/types/plugins/{styles.d.ts → affiliations.d.ts} +9 -7
  40. package/dist/types/plugins/toc.d.ts +1 -5
  41. package/dist/types/types.d.ts +4 -0
  42. package/dist/types/views/affiliation.d.ts +31 -0
  43. package/dist/types/views/affiliations.d.ts +9 -0
  44. package/dist/types/views/base_node_view.d.ts +0 -2
  45. package/dist/types/views/contributors.d.ts +24 -8
  46. package/dist/types/views/figure_editable.d.ts +0 -2
  47. package/dist/types/views/figure_element.d.ts +0 -3
  48. package/package.json +3 -3
  49. package/styles/AdvancedEditor.css +143 -47
  50. package/styles/Editor.css +1 -2
  51. package/dist/cjs/plugins/styles.js +0 -120
  52. package/dist/es/plugins/styles.js +0 -118
@@ -10,9 +10,9 @@ const TriangleCollapsed_1 = __importDefault(require("@manuscripts/assets/react/T
10
10
  const style_guide_1 = require("@manuscripts/style-guide");
11
11
  const react_1 = __importDefault(require("react"));
12
12
  const styled_components_1 = __importDefault(require("styled-components"));
13
- const FigureElementOptions = ({ can, files, modelMap, handleAdd, handleUpload, }) => {
13
+ const FigureElementOptions = ({ can, files, filesMap, handleAdd, handleUpload, }) => {
14
14
  const { isOpen, toggleOpen, wrapperRef } = (0, style_guide_1.useDropdown)();
15
- let { supplements, otherFiles } = (0, style_guide_1.useFiles)(modelMap, files);
15
+ let { supplements, otherFiles } = (0, style_guide_1.useFiles)(filesMap, files);
16
16
  supplements = supplements.filter(style_guide_1.isImageFile);
17
17
  otherFiles = otherFiles.filter(style_guide_1.isImageFile);
18
18
  return (react_1.default.createElement(FilesDropdownWrapper, { onClick: toggleOpen, ref: wrapperRef },
@@ -30,9 +30,9 @@ const FigureElementOptions = ({ can, files, modelMap, handleAdd, handleUpload, }
30
30
  " New file...")))));
31
31
  };
32
32
  exports.FigureElementOptions = FigureElementOptions;
33
- const FigureOptions = ({ can, files, modelMap, handleDownload, handleUpload, handleDetach, handleReplace, }) => {
33
+ const FigureOptions = ({ can, files, filesMap, handleDownload, handleUpload, handleDetach, handleReplace, }) => {
34
34
  const { isOpen, toggleOpen, wrapperRef } = (0, style_guide_1.useDropdown)();
35
- const otherFiles = (0, style_guide_1.useFiles)(modelMap, files).otherFiles.filter(style_guide_1.isImageFile);
35
+ const otherFiles = (0, style_guide_1.useFiles)(filesMap, files).otherFiles.filter(style_guide_1.isImageFile);
36
36
  const showDownload = handleDownload && can.downloadFiles;
37
37
  const showUpload = handleUpload && can.uploadFile;
38
38
  const showDetach = handleDetach && can.editArticle;
@@ -25,6 +25,7 @@ const prosemirror_dropcursor_1 = require("prosemirror-dropcursor");
25
25
  const prosemirror_history_1 = require("prosemirror-history");
26
26
  const prosemirror_tables_1 = require("prosemirror-tables");
27
27
  const keys_1 = __importDefault(require("../keys"));
28
+ const affiliations_1 = __importDefault(require("../plugins/affiliations"));
28
29
  const bibliography_1 = __importDefault(require("../plugins/bibliography"));
29
30
  const comment_annotation_1 = __importDefault(require("../plugins/comment_annotation"));
30
31
  const elements_1 = __importDefault(require("../plugins/elements"));
@@ -52,9 +53,10 @@ exports.default = (props) => {
52
53
  (0, elements_1.default)(),
53
54
  (0, persist_1.default)(),
54
55
  (0, sections_1.default)(),
55
- (0, toc_1.default)(props),
56
+ (0, toc_1.default)(),
56
57
  (0, bibliography_1.default)(props),
57
58
  (0, objects_1.default)(props),
59
+ (0, affiliations_1.default)(),
58
60
  (0, comment_annotation_1.default)(props),
59
61
  (0, paragraphs_1.default)(),
60
62
  (0, placeholder_1.default)(),
@@ -18,6 +18,8 @@ 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
+ const affiliations_1 = __importDefault(require("../views/affiliations"));
21
23
  const bibliography_element_editable_1 = __importDefault(require("../views/bibliography_element_editable"));
22
24
  const blockquote_element_editable_1 = __importDefault(require("../views/blockquote_element_editable"));
23
25
  const bullet_list_editable_1 = __importDefault(require("../views/bullet_list_editable"));
@@ -58,6 +60,8 @@ exports.default = (props, dispatch) => {
58
60
  citation: (0, citation_editable_1.default)(props, dispatch),
59
61
  cross_reference: (0, cross_reference_editable_1.default)(props, dispatch),
60
62
  contributors: (0, contributors_1.default)(props, dispatch),
63
+ affiliations: (0, affiliations_1.default)(props, dispatch),
64
+ affiliation: (0, affiliation_1.default)(props, dispatch),
61
65
  equation: (0, equation_editable_1.default)(props),
62
66
  equation_element: (0, equation_element_editable_1.default)(props),
63
67
  figure: (0, figure_editable_1.default)(props, dispatch),
@@ -82,5 +86,6 @@ exports.default = (props, dispatch) => {
82
86
  table_element_footer: (0, table_element_footer_editable_1.default)(props),
83
87
  toc_element: (0, toc_element_editable_1.default)(props),
84
88
  comments: (0, empty_1.default)('comments'),
89
+ supplements: (0, empty_1.default)('supplements'),
85
90
  };
86
91
  };
package/dist/cjs/index.js CHANGED
@@ -52,4 +52,5 @@ Object.defineProperty(exports, "commentScroll", { enumerable: true, get: functio
52
52
  Object.defineProperty(exports, "isThereSelector", { enumerable: true, get: function () { return comment_annotation_1.isThereSelector; } });
53
53
  Object.defineProperty(exports, "isHighlightComment", { enumerable: true, get: function () { return comment_annotation_1.isHighlightComment; } });
54
54
  __exportStar(require("./lib/utils"), exports);
55
+ __exportStar(require("./lib/track-changes-utils"), exports);
55
56
  __exportStar(require("./useEditor"), exports);
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.isTracked = exports.getChangeClasses = exports.isPendingSetAttrs = exports.isPending = exports.isPendingInsert = exports.isDeleted = exports.isRejectedInsert = void 0;
18
+ exports.getActualAttrs = exports.isTracked = exports.getChangeClasses = exports.isPendingSetAttrs = exports.isPending = exports.isPendingInsert = exports.isDeleted = exports.isRejectedInsert = void 0;
19
19
  function isRejectedInsert(node) {
20
20
  if (node.attrs.dataTracked) {
21
21
  const changes = node.attrs.dataTracked;
@@ -80,3 +80,13 @@ function isTracked(node) {
80
80
  return false;
81
81
  }
82
82
  exports.isTracked = isTracked;
83
+ function getActualAttrs(node) {
84
+ const attrs = node.attrs;
85
+ if (attrs.dataTracked &&
86
+ attrs.dataTracked[0].status === 'rejected' &&
87
+ attrs.dataTracked[0].operation === 'set_attrs') {
88
+ return attrs.dataTracked[0].oldAttrs;
89
+ }
90
+ return attrs;
91
+ }
92
+ exports.getActualAttrs = getActualAttrs;
@@ -0,0 +1,118 @@
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.buildPluginState = exports.affiliationsKey = void 0;
19
+ const transform_1 = require("@manuscripts/transform");
20
+ const prosemirror_state_1 = require("prosemirror-state");
21
+ const prosemirror_view_1 = require("prosemirror-view");
22
+ const track_changes_utils_1 = require("../lib/track-changes-utils");
23
+ exports.affiliationsKey = new prosemirror_state_1.PluginKey('affiliations');
24
+ const buildPluginState = (doc) => {
25
+ const contributors = [];
26
+ const affiliations = [];
27
+ doc.descendants((node, pos) => {
28
+ if ((0, track_changes_utils_1.isDeleted)(node)) {
29
+ return;
30
+ }
31
+ if ((0, transform_1.isAffiliationNode)(node)) {
32
+ affiliations.push([node, pos]);
33
+ }
34
+ if ((0, transform_1.isContributorNode)(node)) {
35
+ contributors.push([node, pos]);
36
+ }
37
+ });
38
+ const iAffiliations = new Set();
39
+ contributors
40
+ .sort(([a], [b]) => {
41
+ return (Number((0, track_changes_utils_1.getActualAttrs)(a).priority) - Number((0, track_changes_utils_1.getActualAttrs)(b).priority));
42
+ })
43
+ .forEach(([author]) => {
44
+ (0, track_changes_utils_1.getActualAttrs)(author).affiliations.forEach((aff) => {
45
+ iAffiliations.add(aff);
46
+ });
47
+ });
48
+ const indexedAffiliationIds = new Map([...iAffiliations].map((id, i) => [id, i + 1]));
49
+ return {
50
+ indexedAffiliationIds,
51
+ contributors,
52
+ affiliations,
53
+ };
54
+ };
55
+ exports.buildPluginState = buildPluginState;
56
+ let count = 0;
57
+ exports.default = () => {
58
+ return new prosemirror_state_1.Plugin({
59
+ key: exports.affiliationsKey,
60
+ state: {
61
+ init(config, instance) {
62
+ return (0, exports.buildPluginState)(instance.doc);
63
+ },
64
+ apply(tr, value, oldState, newState) {
65
+ const prevPluginState = exports.affiliationsKey.getState(oldState);
66
+ if (!tr.docChanged && prevPluginState) {
67
+ return prevPluginState;
68
+ }
69
+ else {
70
+ return (0, exports.buildPluginState)(newState.doc);
71
+ }
72
+ },
73
+ },
74
+ appendTransaction(transactions, oldState, newState) {
75
+ const { indexedAffiliationIds } = exports.affiliationsKey.getState(newState);
76
+ const oldPluginState = exports.affiliationsKey.getState(oldState);
77
+ const { tr } = newState;
78
+ const affiliations = [];
79
+ newState.doc.descendants((node, pos) => {
80
+ if ((0, track_changes_utils_1.isDeleted)(node)) {
81
+ return;
82
+ }
83
+ if ((0, transform_1.isAffiliationNode)(node)) {
84
+ affiliations.push([node, pos]);
85
+ }
86
+ });
87
+ for (const [id] of oldPluginState.indexedAffiliationIds.entries()) {
88
+ if (!indexedAffiliationIds.has(id)) {
89
+ const affiliation = affiliations.find(([node]) => node.attrs.id === id);
90
+ if (affiliation && !(0, track_changes_utils_1.isPendingInsert)(affiliation[0])) {
91
+ tr.delete(affiliation[1], affiliation[1] + affiliation[0].nodeSize);
92
+ }
93
+ }
94
+ }
95
+ tr.setMeta('origin', 'affiliations');
96
+ return tr;
97
+ },
98
+ props: {
99
+ decorations: (state) => {
100
+ const decorations = [];
101
+ const allNodes = [];
102
+ state.doc.descendants((node, pos) => {
103
+ if ((0, transform_1.isAffiliationNode)(node) || (0, transform_1.isContributorNode)(node)) {
104
+ allNodes.push([node, pos]);
105
+ }
106
+ });
107
+ if (allNodes.length) {
108
+ allNodes.forEach(([node, pos]) => {
109
+ decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {}, {
110
+ refresh: count++,
111
+ }));
112
+ });
113
+ }
114
+ return prosemirror_view_1.DecorationSet.create(state.doc, decorations);
115
+ },
116
+ },
117
+ });
118
+ };
@@ -128,16 +128,16 @@ const getEffectiveAttrs = (node, excludeDeletedNode) => {
128
128
  return isRejected ? nodeChange === null || nodeChange === void 0 ? void 0 : nodeChange.oldAttrs : attrs;
129
129
  };
130
130
  const getBibliographyItemModelMap = (doc) => {
131
- const modelMap = new Map();
131
+ const bibliographyItemMap = new Map();
132
132
  doc.descendants((node) => {
133
133
  if (node.type === transform_1.schema.nodes.bibliography_item) {
134
134
  const model = (0, exports.getBibliographyItem)(node);
135
135
  if (model) {
136
- modelMap.set(model._id, model);
136
+ bibliographyItemMap.set(model._id, model);
137
137
  }
138
138
  }
139
139
  });
140
- return modelMap;
140
+ return bibliographyItemMap;
141
141
  };
142
142
  exports.getBibliographyItemModelMap = getBibliographyItemModelMap;
143
143
  const buildCitations = (citations) => citations.map((citation) => ({
@@ -53,19 +53,19 @@ const buildBibliographyPluginState = (doc, csl, $old) => {
53
53
  nodes.push([node, pos]);
54
54
  }
55
55
  });
56
- const modelMap = (0, bibliography_utils_1.getBibliographyItemModelMap)(doc);
56
+ const bibliographyItemMap = (0, bibliography_utils_1.getBibliographyItemModelMap)(doc);
57
57
  const citations = (0, bibliography_utils_1.buildCitations)(nodes);
58
58
  const $new = {
59
59
  citationNodes: nodes,
60
60
  citations,
61
- bibliographyItems: modelMap,
61
+ bibliographyItems: bibliographyItemMap,
62
62
  };
63
63
  if (!csl.style) {
64
64
  return $new;
65
65
  }
66
66
  if ($old &&
67
67
  (0, lodash_1.isEqual)(citations, $old.citations) &&
68
- (0, lodash_1.isEqual)(modelMap, $old.bibliographyItems)) {
68
+ (0, lodash_1.isEqual)(bibliographyItemMap, $old.bibliographyItems)) {
69
69
  $new.citationCounts = $old.citationCounts;
70
70
  $new.provider = $old.provider;
71
71
  $new.renderedCitations = $old.renderedCitations;
@@ -78,7 +78,7 @@ const buildBibliographyPluginState = (doc, csl, $old) => {
78
78
  citationCounts.set(rid, count + 1);
79
79
  });
80
80
  const provider = new library_1.CitationProvider({
81
- getLibraryItem: (id) => modelMap.get(id),
81
+ getLibraryItem: (id) => bibliographyItemMap.get(id),
82
82
  citationStyle: csl.style || '',
83
83
  locale: csl.locale,
84
84
  });
@@ -21,27 +21,17 @@ const transform_1 = require("@manuscripts/transform");
21
21
  const prosemirror_state_1 = require("prosemirror-state");
22
22
  const utils_1 = require("../lib/utils");
23
23
  exports.tocKey = new prosemirror_state_1.PluginKey('toc');
24
- const buildTOCList = (headingStyles, list, node, depth = 1, prefix = '') => {
24
+ const buildTOCList = (list, node, depth = 1, prefix = '') => {
25
25
  list.classList.add('manuscript-toc-list');
26
26
  if (depth > 1) {
27
27
  list.classList.add('manuscript-toc-inner-list');
28
28
  }
29
- const paragraphStyle = headingStyles.get(`heading${depth}`);
30
- const sectionNumberingStyle = paragraphStyle
31
- ? paragraphStyle.sectionNumberingStyle
32
- : undefined;
33
- const numberingScheme = sectionNumberingStyle && sectionNumberingStyle.numberingScheme
34
- ? sectionNumberingStyle.numberingScheme
35
- : 'decimal';
36
- const suffix = sectionNumberingStyle && sectionNumberingStyle.suffix !== undefined
37
- ? sectionNumberingStyle.suffix
38
- : '.';
39
- let index = sectionNumberingStyle ? sectionNumberingStyle.startIndex : 1;
29
+ let index = 1;
40
30
  node.forEach((child) => {
41
31
  if (child.type === transform_1.schema.nodes.body) {
42
32
  for (const childNode of (0, utils_1.iterateChildren)(child)) {
43
33
  if ((0, transform_1.isSectionNodeType)(childNode.type) && !(0, transform_1.isTOCSectionNode)(childNode)) {
44
- const numbering = numberingScheme === 'none' ? '' : `${prefix}${index}`;
34
+ const numbering = `${prefix}${index}`;
45
35
  const firstChildNode = childNode.child(0);
46
36
  if (firstChildNode.type ===
47
37
  firstChildNode.type.schema.nodes.section_title) {
@@ -49,39 +39,16 @@ const buildTOCList = (headingStyles, list, node, depth = 1, prefix = '') => {
49
39
  item.classList.add('manuscript-toc-list-item');
50
40
  item.setAttribute('data-referenced-section', childNode.attrs.id);
51
41
  item.setAttribute('data-referenced-section-path-length', String(depth));
52
- item.textContent = `${numbering ? `${numbering}${suffix}` : ''} ${firstChildNode.textContent || 'Untitled Section'}`;
42
+ item.textContent = `${numbering ? `${numbering}.` : ''} ${firstChildNode.textContent || 'Untitled Section'}`;
53
43
  list.appendChild(item);
54
44
  }
55
- const childSection = (0, utils_1.getMatchingChild)(childNode, (node) => (0, transform_1.isSectionNodeType)(node.type));
56
- if (childSection) {
57
- const paragraphStyle = headingStyles.get(`heading${depth + 1}`);
58
- if (!paragraphStyle || paragraphStyle.partOfTOC) {
59
- const sublist = document.createElement('ul');
60
- buildTOCList(headingStyles, sublist, childNode, depth + 1, numbering ? `${numbering}.` : '');
61
- const item = document.createElement('li');
62
- item.appendChild(sublist);
63
- list.appendChild(item);
64
- }
65
- }
66
45
  index++;
67
46
  }
68
47
  }
69
48
  }
70
49
  });
71
50
  };
72
- const isParagraphStyle = (0, transform_1.hasObjectType)(json_schema_1.ObjectTypes.ParagraphStyle);
73
- const buildHeadingStyles = (modelMap) => {
74
- const styles = new Map();
75
- for (const model of modelMap.values()) {
76
- if (isParagraphStyle(model)) {
77
- if (model.name && /^heading\d+$/.test(model.name)) {
78
- styles.set(model.name, model);
79
- }
80
- }
81
- }
82
- return styles;
83
- };
84
- exports.default = (props) => {
51
+ exports.default = () => {
85
52
  return new prosemirror_state_1.Plugin({
86
53
  key: exports.tocKey,
87
54
  appendTransaction(transactions, oldState, newState) {
@@ -94,8 +61,7 @@ exports.default = (props) => {
94
61
  if (node.type === node.type.schema.nodes.toc_element) {
95
62
  const list = document.createElement('ul');
96
63
  list.setAttribute('data-paragraph-style', node.attrs.paragraphStyle);
97
- const headingStyles = buildHeadingStyles(props.getModelMap());
98
- buildTOCList(headingStyles, list, newState.doc);
64
+ buildTOCList(list, newState.doc);
99
65
  const contents = list.outerHTML;
100
66
  if (contents !== node.attrs.contents) {
101
67
  nodesToUpdate.push({
@@ -75,7 +75,6 @@ exports.defaultEditorProps = {
75
75
  download: () => { },
76
76
  },
77
77
  getCapabilities: () => (0, style_guide_1.getAllPermitted)(),
78
- getModelMap: () => exports.TEST_DATA.MODEL_MAP,
79
78
  getManuscript: () => exports.TEST_DATA.MANUSCRIPT,
80
79
  cslProps: {
81
80
  style: '',
@@ -83,10 +82,6 @@ exports.defaultEditorProps = {
83
82
  },
84
83
  getCitationProvider: () => undefined,
85
84
  plugins: [],
86
- deleteModel: (id) => {
87
- exports.TEST_DATA.MODEL_MAP.delete(id);
88
- return Promise.resolve(id);
89
- },
90
85
  retrySync: () => Promise.resolve(),
91
86
  setComment: () => undefined,
92
87
  setSelectedComment: () => undefined,
@@ -0,0 +1,75 @@
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-status', attrs.dataTracked[0].status);
43
+ this.dom.setAttribute('data-track-op', attrs.dataTracked[0].operation);
44
+ }
45
+ else {
46
+ this.dom.removeAttribute('data-track-status');
47
+ this.dom.removeAttribute('data-track-type');
48
+ }
49
+ };
50
+ this.createDOM = () => {
51
+ this.dom = document.createElement('div');
52
+ this.dom.classList.add('affiliation');
53
+ this.dom.setAttribute('id', this.node.attrs.id);
54
+ this.updateContents();
55
+ };
56
+ this.ignoreMutation = () => true;
57
+ this.stopEvent = () => true;
58
+ this.formatAddress = (affiliation) => {
59
+ const { department, institution, addressLine1, city, county, country, postCode, } = affiliation;
60
+ return [
61
+ department,
62
+ institution,
63
+ addressLine1,
64
+ city,
65
+ county,
66
+ country,
67
+ postCode,
68
+ ]
69
+ .filter(Boolean)
70
+ .join(', ');
71
+ };
72
+ }
73
+ }
74
+ exports.AffiliationView = AffiliationView;
75
+ exports.default = (0, creators_1.createNodeView)(AffiliationView);
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AffiliationsView = void 0;
7
+ const block_view_1 = __importDefault(require("./block_view"));
8
+ const creators_1 = require("./creators");
9
+ class AffiliationsView extends block_view_1.default {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.ignoreMutation = () => true;
13
+ this.stopEvent = () => true;
14
+ this.createElement = () => {
15
+ this.contentDOM = document.createElement(this.elementType);
16
+ this.contentDOM.className = 'block';
17
+ this.contentDOM.setAttribute('contenteditable', 'false');
18
+ this.dom.setAttribute('contenteditable', 'false');
19
+ this.dom.appendChild(this.contentDOM);
20
+ };
21
+ }
22
+ }
23
+ exports.AffiliationsView = AffiliationsView;
24
+ exports.default = (0, creators_1.createNodeView)(AffiliationsView);
@@ -4,32 +4,171 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ContributorsView = void 0;
7
- const base_node_view_1 = require("./base_node_view");
7
+ const style_guide_1 = require("@manuscripts/style-guide");
8
+ const transform_1 = require("@manuscripts/transform");
9
+ const track_changes_utils_1 = require("../lib/track-changes-utils");
10
+ const affiliations_1 = require("../plugins/affiliations");
11
+ const block_view_1 = __importDefault(require("./block_view"));
8
12
  const creators_1 = require("./creators");
9
13
  const ReactSubView_1 = __importDefault(require("./ReactSubView"));
10
- class ContributorsView extends base_node_view_1.BaseNodeView {
14
+ class ContributorsView extends block_view_1.default {
11
15
  constructor() {
12
16
  super(...arguments);
13
17
  this.initialise = () => {
14
18
  this.createDOM();
19
+ this.createGutter('block-gutter', this.gutterButtons().filter(Boolean));
20
+ this.createElement();
21
+ this.createGutter('action-gutter', this.actionGutterButtons().filter(Boolean));
22
+ this.updateContents();
23
+ };
24
+ this.updateContents = () => {
25
+ this.updateClasses();
26
+ this.updateAttributes();
27
+ this.container.innerHTML = '';
28
+ this.buildAuthors();
29
+ this.createEditButton();
30
+ this.createLegend();
31
+ };
32
+ this.buildAuthors = () => {
33
+ var _a;
34
+ const authors = [];
35
+ const authorsWrapper = document.createElement('div');
36
+ authorsWrapper.classList.add('contributors-list');
37
+ (_a = this.node.content) === null || _a === void 0 ? void 0 : _a.forEach((node) => {
38
+ if ((0, transform_1.isContributorNode)(node)) {
39
+ authors.push(node);
40
+ }
41
+ });
42
+ authors
43
+ .sort((a, b) => Number(a.attrs.priority) - Number(b.attrs.priority))
44
+ .forEach((author, i) => {
45
+ if ((0, track_changes_utils_1.getActualAttrs)(author).role !== 'author') {
46
+ return;
47
+ }
48
+ const jointAuthors = this.isJointFirstAuthor(authors, i);
49
+ authorsWrapper.appendChild(this.buildAuthor(author, jointAuthors));
50
+ });
51
+ this.container.appendChild(authorsWrapper);
52
+ };
53
+ this.buildAuthor = (node, isJointFirstAuthor) => {
54
+ var _a;
55
+ const pluginState = affiliations_1.affiliationsKey.getState(this.view.state);
56
+ const attrs = node.attrs;
57
+ const displayAttr = (0, track_changes_utils_1.getActualAttrs)(node);
58
+ const container = document.createElement('button');
59
+ container.classList.add('contributor');
60
+ container.setAttribute('id', attrs.id);
61
+ container.setAttribute('contenteditable', 'false');
62
+ if ((_a = attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.length) {
63
+ container.setAttribute('data-track-status', attrs.dataTracked[0].status);
64
+ container.setAttribute('data-track-op', attrs.dataTracked[0].operation);
65
+ }
66
+ else {
67
+ container.removeAttribute('data-track-status');
68
+ container.removeAttribute('data-track-type');
69
+ }
70
+ const can = this.props.getCapabilities();
71
+ const disableEditButton = !can.editMetadata;
72
+ const { bibliographicName, isCorresponding, email, id } = displayAttr;
73
+ container.addEventListener('click', (e) => {
74
+ e.preventDefault();
75
+ if (!disableEditButton) {
76
+ this.props.openAuthorEditing();
77
+ this.props.selectAuthorForEditing(id);
78
+ }
79
+ });
80
+ const name = this.buildNameLiteral(bibliographicName);
81
+ container.innerHTML =
82
+ isCorresponding && email
83
+ ? `<span class="name">${name} (${email})</span>`
84
+ : `<span class="name">${name}</span>`;
85
+ const noteText = [];
86
+ if (pluginState === null || pluginState === void 0 ? void 0 : pluginState.indexedAffiliationIds) {
87
+ displayAttr.affiliations.map((af) => {
88
+ const index = pluginState === null || pluginState === void 0 ? void 0 : pluginState.indexedAffiliationIds.get(af);
89
+ if (index) {
90
+ noteText.push(index.toString());
91
+ }
92
+ });
93
+ }
94
+ if (isJointFirstAuthor) {
95
+ container.appendChild(this.createNote('†', 'Joint contributor'));
96
+ }
97
+ if (noteText) {
98
+ container.appendChild(this.createNote(noteText.join(',')));
99
+ }
100
+ if (displayAttr.isCorresponding) {
101
+ container.appendChild(this.createNote('*', 'Corresponding author'));
102
+ }
103
+ return container;
104
+ };
105
+ this.initials = (given) => given
106
+ ? given
107
+ .trim()
108
+ .split(' ')
109
+ .map((part) => part.substr(0, 1).toUpperCase() + '.')
110
+ .join('')
111
+ : '';
112
+ this.buildNameLiteral = ({ given = '', family = '', suffix = '' }) => {
113
+ if (!given && !family) {
114
+ return 'Unknown Author';
115
+ }
116
+ return [this.initials(given), family, suffix]
117
+ .filter((part) => part)
118
+ .join(' ');
119
+ };
120
+ this.isJointFirstAuthor = (authors, index) => {
121
+ const author = index === 0 ? authors[index] : authors[index - 1];
122
+ return Boolean(author.attrs.isJointContributor);
123
+ };
124
+ this.createElement = () => {
125
+ this.inner = document.createElement('div');
126
+ this.inner.classList.add('authors-container', 'block');
127
+ this.dom.appendChild(this.inner);
128
+ this.container = document.createElement('div');
129
+ this.container.classList.add('contributors');
130
+ this.inner.appendChild(this.container);
15
131
  };
16
132
  this.createDOM = () => {
17
133
  this.dom = document.createElement('div');
18
- this.dom.classList.add('contributors');
134
+ this.dom.classList.add('block-container', `block-${this.node.type.name}`);
135
+ };
136
+ this.createEditButton = () => {
19
137
  const can = this.props.getCapabilities();
20
- const { components: { AuthorsInlineViewContainer }, subscribeStore, } = this.props;
21
- this.metadata = (0, ReactSubView_1.default)(this.props, AuthorsInlineViewContainer, {
22
- showAuthorEditButton: true,
23
- disableEditButton: !can.editMetadata,
24
- subscribe: subscribeStore,
25
- }, this.node, this.getPos, this.view, 'metadata-container');
26
- if (this.metadata) {
27
- this.dom.appendChild(this.metadata);
138
+ const button = (0, ReactSubView_1.default)(this.props, style_guide_1.SecondaryButton, {
139
+ mini: true,
140
+ onClick: this.props.openAuthorEditing,
141
+ className: 'edit-authors-button',
142
+ disabled: !can.editMetadata,
143
+ children: 'Edit Authors',
144
+ }, this.node, this.getPos, this.view);
145
+ this.container.appendChild(button);
146
+ };
147
+ this.createLegend = () => {
148
+ const state = affiliations_1.affiliationsKey.getState(this.view.state);
149
+ if (state === null || state === void 0 ? void 0 : state.contributors) {
150
+ const isThereJointContributor = state.contributors.find(([contributor]) => contributor.attrs.isJointContributor);
151
+ if (isThereJointContributor) {
152
+ const element = document.createElement('p');
153
+ element.classList.add('contributors-legend');
154
+ element.innerHTML =
155
+ '<span class="symbol">†</span>These authors contributed equally to this work.';
156
+ this.container.appendChild(element);
157
+ }
28
158
  }
29
159
  };
30
160
  this.ignoreMutation = () => true;
31
161
  this.stopEvent = () => true;
32
162
  }
163
+ createNote(text = '', title = '') {
164
+ const el = document.createElement('span');
165
+ el.innerHTML = text;
166
+ if (title) {
167
+ el.setAttribute('title', title);
168
+ }
169
+ el.classList.add('contributor-note');
170
+ return el;
171
+ }
33
172
  }
34
173
  exports.ContributorsView = ContributorsView;
35
174
  exports.default = (0, creators_1.createNodeView)(ContributorsView);