@manuscripts/body-editor 1.7.6 → 1.7.8-LEAN-3377-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 (40) hide show
  1. package/dist/cjs/assets.js +17 -1
  2. package/dist/cjs/components/views/FigureDropdown.js +4 -4
  3. package/dist/cjs/configs/editor-plugins.js +1 -1
  4. package/dist/cjs/lib/build-file-models.js +41 -0
  5. package/dist/cjs/plugins/bibliography/bibliography-utils.js +9 -7
  6. package/dist/cjs/plugins/bibliography/index.js +4 -4
  7. package/dist/cjs/plugins/footnotes/footnotes-utils.js +30 -0
  8. package/dist/cjs/plugins/footnotes/index.js +22 -2
  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/figure_editable.js +2 -1
  12. package/dist/cjs/views/figure_element.js +16 -5
  13. package/dist/es/assets.js +16 -0
  14. package/dist/es/components/views/FigureDropdown.js +4 -4
  15. package/dist/es/configs/editor-plugins.js +1 -1
  16. package/dist/es/lib/build-file-models.js +37 -0
  17. package/dist/es/plugins/bibliography/bibliography-utils.js +5 -5
  18. package/dist/es/plugins/bibliography/index.js +4 -4
  19. package/dist/es/plugins/footnotes/footnotes-utils.js +26 -0
  20. package/dist/es/plugins/footnotes/index.js +20 -1
  21. package/dist/es/plugins/toc.js +9 -43
  22. package/dist/es/testing/default-editor-data.js +0 -5
  23. package/dist/es/views/figure_editable.js +2 -1
  24. package/dist/es/views/figure_element.js +16 -5
  25. package/dist/types/assets.d.ts +1 -0
  26. package/dist/types/components/views/FigureDropdown.d.ts +1 -1
  27. package/dist/types/configs/ManuscriptsEditor.d.ts +1 -3
  28. package/dist/types/configs/editor-plugins.d.ts +1 -3
  29. package/dist/types/lib/build-file-models.d.ts +2 -0
  30. package/dist/types/plugins/bibliography/bibliography-utils.d.ts +4 -0
  31. package/dist/types/plugins/{styles.d.ts → footnotes/footnotes-utils.d.ts} +3 -10
  32. package/dist/types/plugins/footnotes/index.d.ts +1 -0
  33. package/dist/types/plugins/toc.d.ts +1 -5
  34. package/dist/types/views/base_node_view.d.ts +0 -2
  35. package/dist/types/views/figure_editable.d.ts +0 -2
  36. package/dist/types/views/figure_element.d.ts +1 -3
  37. package/package.json +2 -2
  38. package/styles/Editor.css +13 -1
  39. package/dist/cjs/plugins/styles.js +0 -120
  40. package/dist/es/plugins/styles.js +0 -118
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.editAttrsTrackingIcon = exports.commentIcon = exports.editIcon = void 0;
18
+ exports.alertIcon = exports.editAttrsTrackingIcon = exports.commentIcon = exports.editIcon = void 0;
19
19
  exports.editIcon = `
20
20
  <svg
21
21
  width="14"
@@ -102,3 +102,19 @@ exports.editAttrsTrackingIcon = `
102
102
  />
103
103
  </svg>
104
104
  `;
105
+ exports.alertIcon = `
106
+ <svg
107
+ width="12"
108
+ height="12"
109
+ viewBox="0 0 12 12"
110
+ fill="none"
111
+ xmlns="http://www.w3.org/2000/svg"
112
+ >
113
+ <path
114
+ fill-rule="evenodd"
115
+ clip-rule="evenodd"
116
+ d="M6 12C2.68629 12 1.18852e-06 9.31371 1.47821e-06 6C1.7679e-06 2.68629 2.68629 1.39444e-07 6 4.29138e-07C9.31371 7.18831e-07 12 2.68629 12 6C12 9.31371 9.31371 12 6 12ZM6.74998 2.99996L6.75 6.37462C6.75 6.78819 6.41522 7.12243 6.00166 7.12334C5.58681 7.12426 5.25001 6.78821 5.25001 6.37335L5.25 3.00082C5.25 2.58629 5.58629 2.25037 6.00082 2.25083C6.4147 2.25128 6.74998 2.58607 6.74998 2.99996ZM6.75 8.99263C6.75 9.46884 6.47288 9.75 5.99853 9.75C5.52419 9.75 5.25 9.47179 5.25 8.99558C5.25 8.51937 5.52421 8.25 5.99855 8.25C6.47289 8.25 6.75 8.51642 6.75 8.99263Z"
117
+ fill="#FE8F1F"
118
+ />
119
+ </svg>
120
+ `;
@@ -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, getFilesMap, 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)(getFilesMap(), 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, getFilesMap, 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)(getFilesMap(), 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;
@@ -52,7 +52,7 @@ exports.default = (props) => {
52
52
  (0, elements_1.default)(),
53
53
  (0, persist_1.default)(),
54
54
  (0, sections_1.default)(),
55
- (0, toc_1.default)(props),
55
+ (0, toc_1.default)(),
56
56
  (0, bibliography_1.default)(props),
57
57
  (0, objects_1.default)(props),
58
58
  (0, affiliations_1.default)(),
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildFileMap = void 0;
4
+ const json_schema_1 = require("@manuscripts/json-schema");
5
+ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
6
+ const transform_1 = require("@manuscripts/transform");
7
+ const bibliography_utils_1 = require("../plugins/bibliography/bibliography-utils");
8
+ const buildFileMap = (doc) => {
9
+ const figures = [];
10
+ const supplements = [];
11
+ const sections = [];
12
+ const buildNode = (node, group) => {
13
+ var _a;
14
+ const attrs = (0, bibliography_utils_1.getEffectiveAttrs)(node, true);
15
+ if (attrs) {
16
+ const nodeChange = (_a = node.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.reduce(bibliography_utils_1.getLatest);
17
+ if (nodeChange &&
18
+ nodeChange.operation === track_changes_plugin_1.CHANGE_OPERATION.insert &&
19
+ nodeChange.status === track_changes_plugin_1.CHANGE_STATUS.rejected) {
20
+ return false;
21
+ }
22
+ group.push(node.type.create(Object.assign({}, attrs), node.content));
23
+ }
24
+ return false;
25
+ };
26
+ doc.descendants((node) => {
27
+ if (node.type === transform_1.schema.nodes.section &&
28
+ node.attrs.category === 'MPSectionCategory:abstract-graphical') {
29
+ return buildNode(node, sections);
30
+ }
31
+ if (node.type === transform_1.schema.nodes.figure_element) {
32
+ return buildNode(node, figures);
33
+ }
34
+ if (node.type === transform_1.schema.nodes.supplement) {
35
+ buildNode(node, supplements);
36
+ }
37
+ });
38
+ sections.push(transform_1.schema.nodes.section.create({ id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.Section) }, figures), transform_1.schema.nodes.supplements.create({ id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.Supplement) }, supplements));
39
+ return (0, transform_1.encode)(transform_1.schema.nodes.manuscript.create({}, sections));
40
+ };
41
+ exports.buildFileMap = buildFileMap;
@@ -26,7 +26,7 @@ var __rest = (this && this.__rest) || function (s, e) {
26
26
  return t;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.buildCitations = exports.getBibliographyItemModelMap = exports.getBibliographyItem = exports.getCitation = exports.buildDecorations = exports.isBibliographyElement = void 0;
29
+ exports.buildCitations = exports.getBibliographyItemModelMap = exports.getEffectiveAttrs = exports.getLatest = exports.getBibliographyItem = exports.getCitation = exports.buildDecorations = exports.isBibliographyElement = void 0;
30
30
  const json_schema_1 = require("@manuscripts/json-schema");
31
31
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
32
32
  const transform_1 = require("@manuscripts/transform");
@@ -85,7 +85,7 @@ const buildDecorations = (state, doc) => {
85
85
  };
86
86
  exports.buildDecorations = buildDecorations;
87
87
  const getCitation = (node) => {
88
- const attrs = getEffectiveAttrs(node);
88
+ const attrs = (0, exports.getEffectiveAttrs)(node);
89
89
  if (!attrs) {
90
90
  return undefined;
91
91
  }
@@ -103,7 +103,7 @@ const getCitation = (node) => {
103
103
  };
104
104
  exports.getCitation = getCitation;
105
105
  const getBibliographyItem = (node) => {
106
- const attrs = getEffectiveAttrs(node, true);
106
+ const attrs = (0, exports.getEffectiveAttrs)(node, true);
107
107
  if (!attrs) {
108
108
  return undefined;
109
109
  }
@@ -113,9 +113,10 @@ const getBibliographyItem = (node) => {
113
113
  };
114
114
  exports.getBibliographyItem = getBibliographyItem;
115
115
  const getLatest = (a, b) => a.updatedAt > b.updatedAt ? a : b;
116
+ exports.getLatest = getLatest;
116
117
  const getEffectiveAttrs = (node, excludeDeletedNode) => {
117
118
  const _a = node.attrs, { dataTracked } = _a, attrs = __rest(_a, ["dataTracked"]);
118
- const nodeChange = dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.reduce(getLatest);
119
+ const nodeChange = dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.reduce(exports.getLatest);
119
120
  const isDeleted = nodeChange &&
120
121
  nodeChange.operation === track_changes_plugin_1.CHANGE_OPERATION.delete &&
121
122
  nodeChange.status !== track_changes_plugin_1.CHANGE_STATUS.rejected;
@@ -127,17 +128,18 @@ const getEffectiveAttrs = (node, excludeDeletedNode) => {
127
128
  nodeChange.status === track_changes_plugin_1.CHANGE_STATUS.rejected;
128
129
  return isRejected ? nodeChange === null || nodeChange === void 0 ? void 0 : nodeChange.oldAttrs : attrs;
129
130
  };
131
+ exports.getEffectiveAttrs = getEffectiveAttrs;
130
132
  const getBibliographyItemModelMap = (doc) => {
131
- const modelMap = new Map();
133
+ const bibliographyItemMap = new Map();
132
134
  doc.descendants((node) => {
133
135
  if (node.type === transform_1.schema.nodes.bibliography_item) {
134
136
  const model = (0, exports.getBibliographyItem)(node);
135
137
  if (model) {
136
- modelMap.set(model._id, model);
138
+ bibliographyItemMap.set(model._id, model);
137
139
  }
138
140
  }
139
141
  });
140
- return modelMap;
142
+ return bibliographyItemMap;
141
143
  };
142
144
  exports.getBibliographyItemModelMap = getBibliographyItemModelMap;
143
145
  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
  });
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2024 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.findTableInlineFootnoteIds = void 0;
19
+ const transform_1 = require("@manuscripts/transform");
20
+ const prosemirror_utils_1 = require("prosemirror-utils");
21
+ const findTableInlineFootnoteIds = ($pos) => {
22
+ var _a;
23
+ const tableElement = (_a = (0, prosemirror_utils_1.findParentNodeClosestToPos)($pos, (node) => node.type === transform_1.schema.nodes.table_element)) === null || _a === void 0 ? void 0 : _a.node.firstChild;
24
+ return new Set(tableElement
25
+ ? (0, prosemirror_utils_1.findChildren)(tableElement, (node) => node.type === transform_1.schema.nodes.inline_footnote)
26
+ .map(({ node }) => node.attrs.rids)
27
+ .flat()
28
+ : []);
29
+ };
30
+ exports.findTableInlineFootnoteIds = findTableInlineFootnoteIds;
@@ -15,14 +15,16 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.buildPluginState = exports.footnotesKey = void 0;
18
+ exports.uncitedFootnoteWidget = exports.buildPluginState = exports.footnotesKey = void 0;
19
19
  const transform_1 = require("@manuscripts/transform");
20
20
  const lodash_1 = require("lodash");
21
21
  const prosemirror_state_1 = require("prosemirror-state");
22
22
  const prosemirror_utils_1 = require("prosemirror-utils");
23
23
  const prosemirror_view_1 = require("prosemirror-view");
24
+ const assets_1 = require("../../assets");
24
25
  const utils_1 = require("../../lib/utils");
25
26
  const placeholder_1 = require("../placeholder");
27
+ const footnotes_utils_1 = require("./footnotes-utils");
26
28
  exports.footnotesKey = new prosemirror_state_1.PluginKey('footnotes');
27
29
  const buildPluginState = (doc) => {
28
30
  const nodes = [];
@@ -59,6 +61,13 @@ const labelWidget = (label, id) => (view) => {
59
61
  });
60
62
  return element;
61
63
  };
64
+ const uncitedFootnoteWidget = () => () => {
65
+ const element = document.createElement('span');
66
+ element.className = 'unctied-table-footnote';
67
+ element.innerHTML = assets_1.alertIcon;
68
+ return element;
69
+ };
70
+ exports.uncitedFootnoteWidget = uncitedFootnoteWidget;
62
71
  exports.default = () => {
63
72
  return new prosemirror_state_1.Plugin({
64
73
  key: exports.footnotesKey,
@@ -101,7 +110,8 @@ exports.default = () => {
101
110
  }
102
111
  }
103
112
  const { labels } = exports.footnotesKey.getState(state);
104
- state.doc.descendants((node, pos) => {
113
+ let tableInlineFootnoteIds = undefined;
114
+ state.doc.descendants((node, pos, parent) => {
105
115
  var _a;
106
116
  if ((0, transform_1.isFootnoteNode)(node)) {
107
117
  const id = node.attrs.id;
@@ -116,11 +126,21 @@ exports.default = () => {
116
126
  if (!((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.textContent)) {
117
127
  decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, (0, placeholder_1.placeholderWidget)('Add new note here')));
118
128
  }
129
+ if (tableInlineFootnoteIds &&
130
+ !tableInlineFootnoteIds.has(node.attrs.id)) {
131
+ decorations.push(prosemirror_view_1.Decoration.widget(pos + node.nodeSize - 1, (0, exports.uncitedFootnoteWidget)()));
132
+ }
119
133
  }
120
134
  if (node.type === transform_1.schema.nodes.footnotes_element) {
121
135
  decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
122
136
  class: 'footnote-element',
123
137
  }));
138
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === transform_1.schema.nodes.table_element_footer) {
139
+ tableInlineFootnoteIds = (0, footnotes_utils_1.findTableInlineFootnoteIds)(state.doc.resolve(pos));
140
+ }
141
+ else {
142
+ tableInlineFootnoteIds = undefined;
143
+ }
124
144
  }
125
145
  });
126
146
  return prosemirror_view_1.DecorationSet.create(state.doc, decorations);
@@ -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,
@@ -32,6 +32,7 @@ const style_guide_1 = require("@manuscripts/style-guide");
32
32
  const react_1 = require("react");
33
33
  const react_dom_1 = __importDefault(require("react-dom"));
34
34
  const FigureDropdown_1 = require("../components/views/FigureDropdown");
35
+ const build_file_models_1 = require("../lib/build-file-models");
35
36
  const track_changes_utils_1 = require("../lib/track-changes-utils");
36
37
  const creators_1 = require("./creators");
37
38
  const figure_1 = require("./figure");
@@ -134,7 +135,7 @@ class FigureEditableView extends figure_1.FigureView {
134
135
  const componentProps = {
135
136
  can,
136
137
  files,
137
- modelMap: this.props.getModelMap(),
138
+ getFilesMap: () => (0, build_file_models_1.buildFileMap)(this.view.state.doc),
138
139
  handleDownload,
139
140
  handleUpload,
140
141
  handleDetach,
@@ -28,8 +28,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.FigureElementView = void 0;
31
- const style_guide_1 = require("@manuscripts/style-guide");
31
+ const transform_1 = require("@manuscripts/transform");
32
32
  const FigureDropdown_1 = require("../components/views/FigureDropdown");
33
+ const build_file_models_1 = require("../lib/build-file-models");
33
34
  const utils_1 = require("../lib/utils");
34
35
  const block_view_1 = __importDefault(require("./block_view"));
35
36
  const creators_1 = require("./creators");
@@ -96,9 +97,7 @@ class FigureElementView extends block_view_1.default {
96
97
  tr.setNodeMarkup(this.getPos() + 1, undefined, Object.assign(Object.assign({}, figure.attrs), { src })).setSelection(selection.map(tr.doc, tr.mapping));
97
98
  dispatch(tr);
98
99
  }
99
- if ((0, style_guide_1.isModelFile)(file)) {
100
- yield this.props.deleteModel(file.modelId);
101
- }
100
+ this.deleteSupplementNode(file);
102
101
  });
103
102
  if (can.uploadFile) {
104
103
  const upload = (file) => __awaiter(this, void 0, void 0, function* () {
@@ -111,7 +110,7 @@ class FigureElementView extends block_view_1.default {
111
110
  const componentProps = {
112
111
  can: can,
113
112
  files: this.props.getFiles(),
114
- modelMap: this.props.getModelMap(),
113
+ getFilesMap: () => (0, build_file_models_1.buildFileMap)(this.view.state.doc),
115
114
  handleUpload,
116
115
  handleAdd,
117
116
  };
@@ -121,6 +120,18 @@ class FigureElementView extends block_view_1.default {
121
120
  }
122
121
  };
123
122
  }
123
+ deleteSupplementNode(file) {
124
+ if (file.type.id === 'supplementary') {
125
+ const tr = this.view.state.tr;
126
+ this.view.state.doc.descendants((node, pos) => {
127
+ if (node.type === transform_1.schema.nodes.supplement &&
128
+ node.attrs.href === file.id) {
129
+ tr.delete(pos, pos + node.nodeSize);
130
+ }
131
+ });
132
+ this.view.dispatch(tr);
133
+ }
134
+ }
124
135
  }
125
136
  exports.FigureElementView = FigureElementView;
126
137
  exports.default = (0, creators_1.createNodeView)(FigureElementView);
package/dist/es/assets.js CHANGED
@@ -99,3 +99,19 @@ export const editAttrsTrackingIcon = `
99
99
  />
100
100
  </svg>
101
101
  `;
102
+ export const alertIcon = `
103
+ <svg
104
+ width="12"
105
+ height="12"
106
+ viewBox="0 0 12 12"
107
+ fill="none"
108
+ xmlns="http://www.w3.org/2000/svg"
109
+ >
110
+ <path
111
+ fill-rule="evenodd"
112
+ clip-rule="evenodd"
113
+ d="M6 12C2.68629 12 1.18852e-06 9.31371 1.47821e-06 6C1.7679e-06 2.68629 2.68629 1.39444e-07 6 4.29138e-07C9.31371 7.18831e-07 12 2.68629 12 6C12 9.31371 9.31371 12 6 12ZM6.74998 2.99996L6.75 6.37462C6.75 6.78819 6.41522 7.12243 6.00166 7.12334C5.58681 7.12426 5.25001 6.78821 5.25001 6.37335L5.25 3.00082C5.25 2.58629 5.58629 2.25037 6.00082 2.25083C6.4147 2.25128 6.74998 2.58607 6.74998 2.99996ZM6.75 8.99263C6.75 9.46884 6.47288 9.75 5.99853 9.75C5.52419 9.75 5.25 9.47179 5.25 8.99558C5.25 8.51937 5.52421 8.25 5.99855 8.25C6.47289 8.25 6.75 8.51642 6.75 8.99263Z"
114
+ fill="#FE8F1F"
115
+ />
116
+ </svg>
117
+ `;
@@ -4,9 +4,9 @@ import TriangleCollapsed from '@manuscripts/assets/react/TriangleCollapsed';
4
4
  import { AttachIcon, DropdownList, getFileIcon, IconButton, IconTextButton, isImageFile, RoundIconButton, UploadIcon, useDropdown, useFiles, } from '@manuscripts/style-guide';
5
5
  import React from 'react';
6
6
  import styled from 'styled-components';
7
- export const FigureElementOptions = ({ can, files, modelMap, handleAdd, handleUpload, }) => {
7
+ export const FigureElementOptions = ({ can, files, getFilesMap, handleAdd, handleUpload, }) => {
8
8
  const { isOpen, toggleOpen, wrapperRef } = useDropdown();
9
- let { supplements, otherFiles } = useFiles(modelMap, files);
9
+ let { supplements, otherFiles } = useFiles(getFilesMap(), files);
10
10
  supplements = supplements.filter(isImageFile);
11
11
  otherFiles = otherFiles.filter(isImageFile);
12
12
  return (React.createElement(FilesDropdownWrapper, { onClick: toggleOpen, ref: wrapperRef },
@@ -23,9 +23,9 @@ export const FigureElementOptions = ({ can, files, modelMap, handleAdd, handleUp
23
23
  React.createElement(AddIconHighlight, null),
24
24
  " New file...")))));
25
25
  };
26
- export const FigureOptions = ({ can, files, modelMap, handleDownload, handleUpload, handleDetach, handleReplace, }) => {
26
+ export const FigureOptions = ({ can, files, getFilesMap, handleDownload, handleUpload, handleDetach, handleReplace, }) => {
27
27
  const { isOpen, toggleOpen, wrapperRef } = useDropdown();
28
- const otherFiles = useFiles(modelMap, files).otherFiles.filter(isImageFile);
28
+ const otherFiles = useFiles(getFilesMap(), files).otherFiles.filter(isImageFile);
29
29
  const showDownload = handleDownload && can.downloadFiles;
30
30
  const showUpload = handleUpload && can.uploadFile;
31
31
  const showDetach = handleDetach && can.editArticle;
@@ -47,7 +47,7 @@ export default (props) => {
47
47
  elements(),
48
48
  persist(),
49
49
  sections(),
50
- toc(props),
50
+ toc(),
51
51
  bibliography(props),
52
52
  objects(props),
53
53
  affiliations(),
@@ -0,0 +1,37 @@
1
+ import { ObjectTypes } from '@manuscripts/json-schema';
2
+ import { CHANGE_OPERATION, CHANGE_STATUS, } from '@manuscripts/track-changes-plugin';
3
+ import { encode, generateID, schema, } from '@manuscripts/transform';
4
+ import { getEffectiveAttrs, getLatest, } from '../plugins/bibliography/bibliography-utils';
5
+ export const buildFileMap = (doc) => {
6
+ const figures = [];
7
+ const supplements = [];
8
+ const sections = [];
9
+ const buildNode = (node, group) => {
10
+ var _a;
11
+ const attrs = getEffectiveAttrs(node, true);
12
+ if (attrs) {
13
+ const nodeChange = (_a = node.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.reduce(getLatest);
14
+ if (nodeChange &&
15
+ nodeChange.operation === CHANGE_OPERATION.insert &&
16
+ nodeChange.status === CHANGE_STATUS.rejected) {
17
+ return false;
18
+ }
19
+ group.push(node.type.create(Object.assign({}, attrs), node.content));
20
+ }
21
+ return false;
22
+ };
23
+ doc.descendants((node) => {
24
+ if (node.type === schema.nodes.section &&
25
+ node.attrs.category === 'MPSectionCategory:abstract-graphical') {
26
+ return buildNode(node, sections);
27
+ }
28
+ if (node.type === schema.nodes.figure_element) {
29
+ return buildNode(node, figures);
30
+ }
31
+ if (node.type === schema.nodes.supplement) {
32
+ buildNode(node, supplements);
33
+ }
34
+ });
35
+ sections.push(schema.nodes.section.create({ id: generateID(ObjectTypes.Section) }, figures), schema.nodes.supplements.create({ id: generateID(ObjectTypes.Supplement) }, supplements));
36
+ return encode(schema.nodes.manuscript.create({}, sections));
37
+ };
@@ -105,8 +105,8 @@ export const getBibliographyItem = (node) => {
105
105
  const item = Object.assign({ _id: id, objectType: ObjectTypes.BibliographyItem, 'container-title': containerTitle, DOI: doi }, rest);
106
106
  return pickBy(item, (v) => v !== undefined);
107
107
  };
108
- const getLatest = (a, b) => a.updatedAt > b.updatedAt ? a : b;
109
- const getEffectiveAttrs = (node, excludeDeletedNode) => {
108
+ export const getLatest = (a, b) => a.updatedAt > b.updatedAt ? a : b;
109
+ export const getEffectiveAttrs = (node, excludeDeletedNode) => {
110
110
  const _a = node.attrs, { dataTracked } = _a, attrs = __rest(_a, ["dataTracked"]);
111
111
  const nodeChange = dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.reduce(getLatest);
112
112
  const isDeleted = nodeChange &&
@@ -121,16 +121,16 @@ const getEffectiveAttrs = (node, excludeDeletedNode) => {
121
121
  return isRejected ? nodeChange === null || nodeChange === void 0 ? void 0 : nodeChange.oldAttrs : attrs;
122
122
  };
123
123
  export const getBibliographyItemModelMap = (doc) => {
124
- const modelMap = new Map();
124
+ const bibliographyItemMap = new Map();
125
125
  doc.descendants((node) => {
126
126
  if (node.type === schema.nodes.bibliography_item) {
127
127
  const model = getBibliographyItem(node);
128
128
  if (model) {
129
- modelMap.set(model._id, model);
129
+ bibliographyItemMap.set(model._id, model);
130
130
  }
131
131
  }
132
132
  });
133
- return modelMap;
133
+ return bibliographyItemMap;
134
134
  };
135
135
  export const buildCitations = (citations) => citations.map((citation) => ({
136
136
  citationID: citation[0].attrs.id,
@@ -50,19 +50,19 @@ const buildBibliographyPluginState = (doc, csl, $old) => {
50
50
  nodes.push([node, pos]);
51
51
  }
52
52
  });
53
- const modelMap = getBibliographyItemModelMap(doc);
53
+ const bibliographyItemMap = getBibliographyItemModelMap(doc);
54
54
  const citations = buildCitations(nodes);
55
55
  const $new = {
56
56
  citationNodes: nodes,
57
57
  citations,
58
- bibliographyItems: modelMap,
58
+ bibliographyItems: bibliographyItemMap,
59
59
  };
60
60
  if (!csl.style) {
61
61
  return $new;
62
62
  }
63
63
  if ($old &&
64
64
  isEqual(citations, $old.citations) &&
65
- isEqual(modelMap, $old.bibliographyItems)) {
65
+ isEqual(bibliographyItemMap, $old.bibliographyItems)) {
66
66
  $new.citationCounts = $old.citationCounts;
67
67
  $new.provider = $old.provider;
68
68
  $new.renderedCitations = $old.renderedCitations;
@@ -75,7 +75,7 @@ const buildBibliographyPluginState = (doc, csl, $old) => {
75
75
  citationCounts.set(rid, count + 1);
76
76
  });
77
77
  const provider = new CitationProvider({
78
- getLibraryItem: (id) => modelMap.get(id),
78
+ getLibraryItem: (id) => bibliographyItemMap.get(id),
79
79
  citationStyle: csl.style || '',
80
80
  locale: csl.locale,
81
81
  });
@@ -0,0 +1,26 @@
1
+ /*!
2
+ * © 2024 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { schema } from '@manuscripts/transform';
17
+ import { findChildren, findParentNodeClosestToPos } from 'prosemirror-utils';
18
+ export const findTableInlineFootnoteIds = ($pos) => {
19
+ var _a;
20
+ const tableElement = (_a = findParentNodeClosestToPos($pos, (node) => node.type === schema.nodes.table_element)) === null || _a === void 0 ? void 0 : _a.node.firstChild;
21
+ return new Set(tableElement
22
+ ? findChildren(tableElement, (node) => node.type === schema.nodes.inline_footnote)
23
+ .map(({ node }) => node.attrs.rids)
24
+ .flat()
25
+ : []);
26
+ };