@manuscripts/body-editor 2.0.46-LEAN-3883.1 → 2.0.46

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 (35) hide show
  1. package/dist/cjs/commands.js +12 -20
  2. package/dist/cjs/components/views/FootnotesSelector.js +4 -2
  3. package/dist/cjs/keys/misc.js +0 -1
  4. package/dist/cjs/lib/track-changes-utils.js +14 -46
  5. package/dist/cjs/plugins/footnotes/index.js +27 -129
  6. package/dist/cjs/plugins/footnotes/widgets.js +131 -0
  7. package/dist/cjs/plugins/{section_title/index.js → section_title.js} +1 -18
  8. package/dist/cjs/versions.js +1 -1
  9. package/dist/cjs/views/footnote.js +1 -0
  10. package/dist/cjs/views/inline_footnote.js +13 -7
  11. package/dist/es/commands.js +10 -17
  12. package/dist/es/components/views/FootnotesSelector.js +4 -2
  13. package/dist/es/keys/misc.js +2 -3
  14. package/dist/es/lib/track-changes-utils.js +13 -42
  15. package/dist/es/plugins/footnotes/index.js +23 -121
  16. package/dist/es/plugins/footnotes/widgets.js +122 -0
  17. package/dist/es/plugins/{section_title/index.js → section_title.js} +1 -18
  18. package/dist/es/versions.js +1 -1
  19. package/dist/es/views/footnote.js +1 -0
  20. package/dist/es/views/inline_footnote.js +14 -8
  21. package/dist/types/commands.d.ts +0 -1
  22. package/dist/types/lib/track-changes-utils.d.ts +1 -4
  23. package/dist/types/plugins/footnotes/index.d.ts +0 -1
  24. package/dist/types/plugins/footnotes/widgets.d.ts +22 -0
  25. package/dist/types/versions.d.ts +1 -1
  26. package/dist/types/views/inline_footnote.d.ts +2 -6
  27. package/package.json +3 -3
  28. package/styles/AdvancedEditor.css +43 -62
  29. package/dist/cjs/lib/section-titles.js +0 -35
  30. package/dist/cjs/plugins/section_title/autocompletion.js +0 -45
  31. package/dist/es/lib/section-titles.js +0 -32
  32. package/dist/es/plugins/section_title/autocompletion.js +0 -40
  33. package/dist/types/lib/section-titles.d.ts +0 -17
  34. package/dist/types/plugins/section_title/autocompletion.d.ts +0 -10
  35. /package/dist/types/plugins/{section_title/index.d.ts → section_title.d.ts} +0 -0
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.autoComplete = exports.mergeCellsWithSpace = exports.addColumns = exports.addRows = exports.insertTableFootnote = exports.addInlineComment = exports.addNodeComment = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreMetaNodeBackspaceCommand = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertKeywords = exports.insertContributors = exports.insertAbstract = exports.insertBackMatterSection = exports.insertSection = exports.insertGraphicalAbstract = exports.insertInlineFootnote = exports.insertFootnote = exports.createFootnote = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.findPosBeforeFirstSubsection = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertSupplement = exports.insertTable = exports.insertFigure = exports.insertGeneralFootnote = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = void 0;
18
+ exports.mergeCellsWithSpace = exports.addColumns = exports.addRows = exports.insertTableFootnote = exports.addInlineComment = exports.addNodeComment = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreMetaNodeBackspaceCommand = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertKeywords = exports.insertContributors = exports.insertAbstract = exports.insertBackMatterSection = exports.insertSection = exports.insertGraphicalAbstract = exports.insertInlineFootnote = exports.insertFootnote = exports.createFootnote = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.findPosBeforeFirstSubsection = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertSupplement = exports.insertTable = exports.insertFigure = exports.insertGeneralFootnote = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = void 0;
19
19
  const json_schema_1 = require("@manuscripts/json-schema");
20
20
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
21
21
  const transform_1 = require("@manuscripts/transform");
@@ -29,13 +29,11 @@ const comments_1 = require("./lib/comments");
29
29
  const doc_1 = require("./lib/doc");
30
30
  const footnotes_1 = require("./lib/footnotes");
31
31
  const helpers_1 = require("./lib/helpers");
32
- const section_titles_1 = require("./lib/section-titles");
33
32
  const track_changes_utils_1 = require("./lib/track-changes-utils");
34
33
  const utils_1 = require("./lib/utils");
35
34
  const comments_2 = require("./plugins/comments");
36
35
  const editor_props_1 = require("./plugins/editor-props");
37
36
  const footnotes_2 = require("./plugins/footnotes");
38
- const autocompletion_1 = require("./plugins/section_title/autocompletion");
39
37
  const markActive = (type) => (state) => {
40
38
  const { from, $from, to, empty } = state.selection;
41
39
  return empty
@@ -483,6 +481,16 @@ const insertSection = (subsection = false) => (state, dispatch, view) => {
483
481
  return true;
484
482
  };
485
483
  exports.insertSection = insertSection;
484
+ const sectionTitles = new Map([
485
+ ['MPSectionCategory:acknowledgement', 'Acknowledgments'],
486
+ ['MPSectionCategory:availability', 'Availability'],
487
+ ['MPSectionCategory:competing-interests', 'COI Statement'],
488
+ ['MPSectionCategory:con', 'Contributed-by information'],
489
+ ['MPSectionCategory:ethics-statement', 'Ethics Statement'],
490
+ ['MPSectionCategory:financial-disclosure', 'Financial Disclosure'],
491
+ ['MPSectionCategory:supplementary-material', 'Supplementary Material'],
492
+ ['MPSectionCategory:supported-by', 'Supported By'],
493
+ ]);
486
494
  const insertBackMatterSection = (category) => (state, dispatch, view) => {
487
495
  const backmatter = (0, doc_1.findBackmatter)(state.doc);
488
496
  const sections = (0, prosemirror_utils_1.findChildrenByType)(backmatter.node, transform_1.schema.nodes.section);
@@ -500,7 +508,7 @@ const insertBackMatterSection = (category) => (state, dispatch, view) => {
500
508
  const node = transform_1.schema.nodes.section.createAndFill({
501
509
  category,
502
510
  }, [
503
- transform_1.schema.nodes.section_title.create({}, transform_1.schema.text(section_titles_1.sectionTitles.get(category) || '')),
511
+ transform_1.schema.nodes.section_title.create({}, transform_1.schema.text(sectionTitles.get(category) || '')),
504
512
  ]);
505
513
  const tr = state.tr.insert(pos, node);
506
514
  if (dispatch) {
@@ -1131,19 +1139,3 @@ function mergeCellsWithSpace(state, dispatch) {
1131
1139
  return true;
1132
1140
  }
1133
1141
  exports.mergeCellsWithSpace = mergeCellsWithSpace;
1134
- const autoComplete = (state, dispatch) => {
1135
- const complete = (0, autocompletion_1.checkForCompletion)(state);
1136
- if (complete) {
1137
- const tr = state.tr.insertText(complete.suggestion, state.selection.from);
1138
- const inserted = complete.title.substring(0, complete.title.length - complete.suggestion.length);
1139
- console.log(inserted);
1140
- console.log(complete);
1141
- if (inserted) {
1142
- tr.replaceWith(state.selection.from - inserted.length, state.selection.from, transform_1.schema.text(inserted));
1143
- }
1144
- dispatch && dispatch(tr);
1145
- return true;
1146
- }
1147
- return false;
1148
- };
1149
- exports.autoComplete = autoComplete;
@@ -45,6 +45,7 @@ exports.FootnotesSelector = void 0;
45
45
  const style_guide_1 = require("@manuscripts/style-guide");
46
46
  const react_1 = __importStar(require("react"));
47
47
  const styled_components_1 = __importDefault(require("styled-components"));
48
+ const track_changes_utils_1 = require("../../lib/track-changes-utils");
48
49
  const NotesContainer = styled_components_1.default.div `
49
50
  height: 90vh;
50
51
  max-height: 400px;
@@ -79,7 +80,7 @@ const AddNewFootnote = (0, styled_components_1.default)(style_guide_1.ButtonGrou
79
80
  const FootnotesSelector = ({ notes, inlineFootnote, onAdd, onInsert, onCancel, addNewLabel }) => {
80
81
  let selectedNotesMap;
81
82
  if (inlineFootnote) {
82
- const rids = inlineFootnote.attrs.rids;
83
+ const rids = (0, track_changes_utils_1.getActualAttrs)(inlineFootnote).rids;
83
84
  const selectedNotes = notes.filter(({ node }) => rids.includes(node.attrs.id));
84
85
  selectedNotesMap = new Map(selectedNotes.map(({ node }) => [node.attrs.id, node]));
85
86
  }
@@ -118,7 +119,8 @@ const FootnotesList = ({ notes, isSelected, onSelect, inlineFootnote }) => {
118
119
  const selectedNotes = [];
119
120
  const remainingNotes = [];
120
121
  notes.forEach((note) => {
121
- const isNoteSelected = inlineFootnote && inlineFootnote.attrs.rids.includes(note.node.attrs.id);
122
+ const isNoteSelected = inlineFootnote &&
123
+ (0, track_changes_utils_1.getActualAttrs)(inlineFootnote).rids.includes(note.node.attrs.id);
122
124
  if (isNoteSelected) {
123
125
  selectedNotes.push(note);
124
126
  }
@@ -39,7 +39,6 @@ const customKeymap = {
39
39
  'Mod-Alt-=': (0, prosemirror_commands_1.toggleMark)(transform_1.schema.marks.superscript),
40
40
  'Mod-Alt--': (0, prosemirror_commands_1.toggleMark)(transform_1.schema.marks.subscript),
41
41
  'Ctrl->': (0, prosemirror_commands_1.wrapIn)(transform_1.schema.nodes.blockquote),
42
- Enter: (0, prosemirror_commands_1.chainCommands)(commands_1.autoComplete, prosemirror_commands_1.newlineInCode, prosemirror_commands_1.createParagraphNear, prosemirror_commands_1.liftEmptyBlock, prosemirror_commands_1.splitBlock),
43
42
  'Shift-Mod-Enter': (0, commands_1.insertSection)(true),
44
43
  'Mod-Enter': (0, prosemirror_commands_1.chainCommands)(prosemirror_commands_1.exitCode, (0, commands_1.insertSection)()),
45
44
  'Shift-Enter': (0, prosemirror_commands_1.chainCommands)(prosemirror_commands_1.exitCode, commands_1.insertBreak),
@@ -15,9 +15,8 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.sanitizeAttrsChange = exports.getActualTextContent = exports.isRejectedText = exports.isDeletedText = exports.isHidden = exports.getAttrsTrackingButton = exports.getActualAttrs = exports.isTracked = exports.getChangeClasses = exports.isPendingSetAttrs = exports.isPending = exports.isPendingInsert = exports.isDeleted = exports.isRejectedInsert = void 0;
18
+ exports.sanitizeAttrsChange = exports.isHidden = exports.getAttrsTrackingButton = exports.getActualAttrs = exports.isTracked = exports.getChangeClasses = exports.isPendingSetAttrs = exports.isPending = exports.isPendingInsert = exports.isDeleted = exports.isRejectedInsert = void 0;
19
19
  const style_guide_1 = require("@manuscripts/style-guide");
20
- const transform_1 = require("@manuscripts/transform");
21
20
  const react_1 = require("react");
22
21
  const server_1 = require("react-dom/server");
23
22
  function isRejectedInsert(node) {
@@ -85,11 +84,20 @@ function isTracked(node) {
85
84
  }
86
85
  exports.isTracked = isTracked;
87
86
  function getActualAttrs(node) {
87
+ var _a;
88
88
  const attrs = node.attrs;
89
- if (attrs.dataTracked &&
90
- attrs.dataTracked[0].status === 'rejected' &&
91
- attrs.dataTracked[0].operation === 'set_attrs') {
92
- return attrs.dataTracked[0].oldAttrs;
89
+ if ((_a = attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.length) {
90
+ const changes = attrs.dataTracked.filter((c) => c.operation === 'set_attrs');
91
+ const hasPendingAttrs = changes.some((c) => c.status === 'pending');
92
+ if (hasPendingAttrs) {
93
+ return attrs;
94
+ }
95
+ const rejected = changes
96
+ .filter((c) => c.status === 'rejected')
97
+ .sort((a, b) => b.statusUpdateAt - a.statusUpdateAt)[0];
98
+ if (rejected && rejected.status === 'rejected') {
99
+ return rejected.oldAttrs;
100
+ }
93
101
  }
94
102
  return attrs;
95
103
  }
@@ -106,46 +114,6 @@ function isHidden(node) {
106
114
  return isDeleted(node) || isRejectedInsert(node);
107
115
  }
108
116
  exports.isHidden = isHidden;
109
- function isDeletedText(node) {
110
- var _a, _b, _c, _d;
111
- if (node.type === transform_1.schema.nodes.text && node.marks.length) {
112
- const deleteMark = node.marks.find((mark) => mark.type === transform_1.schema.marks.tracked_delete);
113
- if (deleteMark &&
114
- ((_b = (_a = deleteMark.attrs) === null || _a === void 0 ? void 0 : _a.dataTracked) === null || _b === void 0 ? void 0 : _b.status) &&
115
- ['pending', 'approved'].includes((_d = (_c = deleteMark.attrs) === null || _c === void 0 ? void 0 : _c.dataTracked) === null || _d === void 0 ? void 0 : _d.status)) {
116
- return true;
117
- }
118
- }
119
- return false;
120
- }
121
- exports.isDeletedText = isDeletedText;
122
- function isRejectedText(node) {
123
- var _a, _b;
124
- if (node.type === transform_1.schema.nodes.text) {
125
- const insertMark = node.marks.find((mark) => mark.type === transform_1.schema.marks.tracked_insert);
126
- if (insertMark && ((_b = (_a = insertMark.attrs) === null || _a === void 0 ? void 0 : _a.dataTracked) === null || _b === void 0 ? void 0 : _b.status) === 'rejected') {
127
- return true;
128
- }
129
- }
130
- return false;
131
- }
132
- exports.isRejectedText = isRejectedText;
133
- function getActualTextContent(fragment) {
134
- let finalContent = '';
135
- function getContent(fragment) {
136
- fragment.forEach((node) => {
137
- if (node.type !== transform_1.schema.nodes.text) {
138
- finalContent += getContent(node.content);
139
- }
140
- if (!isDeletedText(node) && !isRejectedText(node)) {
141
- finalContent += node.textContent;
142
- }
143
- });
144
- }
145
- getContent(fragment);
146
- return finalContent;
147
- }
148
- exports.getActualTextContent = getActualTextContent;
149
117
  function sanitizeAttrsChange(newAttr, currentAttrs) {
150
118
  return Object.keys(newAttr).reduce((acc, attr) => {
151
119
  const key = attr;
@@ -14,123 +14,20 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
17
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.buildPluginState = exports.uncitedFootnoteWidget = exports.footnotesKey = void 0;
22
- const style_guide_1 = require("@manuscripts/style-guide");
18
+ exports.buildPluginState = exports.footnotesKey = void 0;
23
19
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
24
20
  const transform_1 = require("@manuscripts/transform");
25
21
  const lodash_1 = require("lodash");
26
22
  const prosemirror_state_1 = require("prosemirror-state");
27
23
  const prosemirror_utils_1 = require("prosemirror-utils");
28
24
  const prosemirror_view_1 = require("prosemirror-view");
29
- const react_1 = require("react");
30
- const server_1 = require("react-dom/server");
31
25
  const commands_1 = require("../../commands");
32
- const DeleteFootnoteDialog_1 = require("../../components/views/DeleteFootnoteDialog");
33
26
  const footnotes_1 = require("../../lib/footnotes");
34
- const utils_1 = require("../../lib/utils");
35
- const ReactSubView_1 = __importDefault(require("../../views/ReactSubView"));
36
27
  const placeholder_1 = require("../placeholder");
28
+ const track_changes_utils_1 = require("../../lib/track-changes-utils");
29
+ const widgets_1 = require("./widgets");
37
30
  exports.footnotesKey = new prosemirror_state_1.PluginKey('footnotes');
38
- const scrollToInlineFootnote = (rid, view) => {
39
- view.state.doc.descendants((node, pos) => {
40
- const footnote = node;
41
- if ((0, transform_1.isInlineFootnoteNode)(node) && footnote.attrs.rids.includes(rid)) {
42
- const selection = prosemirror_state_1.NodeSelection.create(view.state.doc, pos);
43
- view.dispatch(view.state.tr.setSelection(selection).scrollIntoView());
44
- }
45
- });
46
- };
47
- const labelWidget = (label, id) => (view) => {
48
- const element = document.createElement('span');
49
- element.className = 'footnote-label';
50
- element.textContent = label;
51
- element.addEventListener('mousedown', () => {
52
- scrollToInlineFootnote(id, view);
53
- });
54
- return element;
55
- };
56
- const uncitedFootnoteWidget = () => () => {
57
- const element = document.createElement('span');
58
- element.className = 'uncited-footnote';
59
- element.innerHTML = (0, server_1.renderToStaticMarkup)((0, react_1.createElement)(style_guide_1.AlertIcon));
60
- return element;
61
- };
62
- exports.uncitedFootnoteWidget = uncitedFootnoteWidget;
63
- const deleteFootnoteWidget = (node, props, id, tableElement, tableElementFooter) => (view, getPos) => {
64
- const deleteBtn = document.createElement('span');
65
- deleteBtn.className = 'delete-icon';
66
- deleteBtn.innerHTML = (0, server_1.renderToStaticMarkup)((0, react_1.createElement)(style_guide_1.DeleteIcon));
67
- const parentType = tableElement ? 'table ' : '';
68
- const footnote = {
69
- type: node.type === transform_1.schema.nodes.footnote
70
- ? `${parentType}footnote`
71
- : 'table general note',
72
- message: node.type === transform_1.schema.nodes.footnote
73
- ? `This action will entirely remove the ${parentType}footnote from the list because it will no longer be used.`
74
- : 'This action will entirely remove the table general note.',
75
- };
76
- deleteBtn.addEventListener('mousedown', () => {
77
- const handleDelete = () => {
78
- const tr = view.state.tr;
79
- const pos = getPos();
80
- if (node.type === transform_1.schema.nodes.general_table_footnote && pos) {
81
- if (tableElementFooter &&
82
- !(0, utils_1.getChildOfType)(tableElementFooter.node, transform_1.schema.nodes.footnotes_element, true) &&
83
- tableElementFooter.pos) {
84
- tr.delete(tableElementFooter.pos - 1, tableElementFooter.pos + tableElementFooter.node.nodeSize);
85
- }
86
- else {
87
- tr.delete(pos - 1, pos + node.nodeSize + 1);
88
- }
89
- }
90
- if (node.type === transform_1.schema.nodes.footnote && pos) {
91
- const targetNode = tableElement ? tableElement.node : view.state.doc;
92
- const inlineFootnotes = (0, footnotes_1.getInlineFootnotes)(id, targetNode);
93
- const footnotesElement = (0, prosemirror_utils_1.findParentNodeClosestToPos)(tr.doc.resolve(pos), (node) => node.type === transform_1.schema.nodes.footnotes_element);
94
- if ((footnotesElement === null || footnotesElement === void 0 ? void 0 : footnotesElement.node.childCount) === 1 &&
95
- (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.node.childCount) === 1) {
96
- const { pos: fnPos, node: fnNode } = tableElementFooter;
97
- tr.delete(fnPos, fnPos + fnNode.nodeSize + 1);
98
- }
99
- else if ((footnotesElement === null || footnotesElement === void 0 ? void 0 : footnotesElement.node.childCount) === 1) {
100
- const { pos: fnPos, node: fnNode } = footnotesElement;
101
- tr.delete(fnPos, fnPos + fnNode.nodeSize + 1);
102
- }
103
- else {
104
- const footnote = (0, prosemirror_utils_1.findParentNodeClosestToPos)(tr.doc.resolve(pos), (node) => node.type === transform_1.schema.nodes.footnote);
105
- if (footnote) {
106
- const { pos: fnPos, node: fnNode } = footnote;
107
- tr.delete(fnPos, fnPos + fnNode.nodeSize + 1);
108
- }
109
- }
110
- if (inlineFootnotes) {
111
- inlineFootnotes.forEach((footnote) => {
112
- const pos = footnote.pos + (tableElement ? tableElement.pos + 1 : 0);
113
- if (footnote.node.attrs.rids.length > 1) {
114
- const updatedRids = footnote.node.attrs.rids.filter((rid) => rid !== id);
115
- tr.setNodeMarkup(tr.mapping.map(pos), undefined, Object.assign(Object.assign({}, node.attrs), { rids: updatedRids }));
116
- }
117
- else {
118
- tr.delete(tr.mapping.map(pos), tr.mapping.map(pos + footnote.node.nodeSize));
119
- }
120
- });
121
- }
122
- }
123
- view.dispatch(tr);
124
- };
125
- const componentProps = {
126
- footnoteType: footnote.type,
127
- footnoteMessage: footnote.message,
128
- handleDelete: handleDelete,
129
- };
130
- (0, ReactSubView_1.default)(Object.assign(Object.assign({}, props), { dispatch: view.dispatch }), DeleteFootnoteDialog_1.DeleteFootnoteDialog, componentProps, node, () => getPos(), view);
131
- });
132
- return deleteBtn;
133
- };
134
31
  const buildPluginState = (doc) => {
135
32
  const inlineFootnotes = [];
136
33
  const footnotes = new Map();
@@ -157,25 +54,25 @@ const buildPluginState = (doc) => {
157
54
  const labels = new Map();
158
55
  inlineFootnotes.sort((a, b) => a[1] - b[1]);
159
56
  inlineFootnotes.forEach(([node]) => {
160
- node.attrs.rids.forEach((rid) => {
57
+ (0, track_changes_utils_1.getActualAttrs)(node).rids.forEach((rid) => {
161
58
  labels.set(rid, (0, footnotes_1.getAlphaOrderIndices)(index++));
162
59
  });
163
60
  });
164
61
  const footnotesReordered = [];
165
- const footnotesRest = new Map(footnotes);
62
+ const unusedFootnotes = new Map(footnotes);
166
63
  inlineFootnotes.forEach(([node]) => {
167
64
  const footnote = node;
168
- footnote.attrs.rids.forEach((rid) => {
169
- const currentfNode = footnotesRest.get(rid);
170
- if (currentfNode) {
171
- footnotesReordered.push(currentfNode[0]);
172
- footnotesRest.delete(rid);
65
+ (0, track_changes_utils_1.getActualAttrs)(footnote).rids.forEach((rid) => {
66
+ const currentFnNode = unusedFootnotes.get(rid);
67
+ if (currentFnNode) {
68
+ footnotesReordered.push(currentFnNode[0]);
69
+ unusedFootnotes.delete(rid);
173
70
  }
174
71
  });
175
72
  });
176
73
  return {
177
74
  inlineFootnotes,
178
- unusedFootnotes: footnotesRest,
75
+ unusedFootnotes,
179
76
  footnotes,
180
77
  footnoteElement,
181
78
  labels,
@@ -200,8 +97,8 @@ exports.default = (props) => {
200
97
  appendTransaction(transactions, oldState, newState) {
201
98
  const { inlineFootnotes: oldInlineFootnoteNodes } = exports.footnotesKey.getState(oldState);
202
99
  const { inlineFootnotes: inlineFootnoteNodes, footnotes, labels, footnoteElement, unusedFootnotes, } = exports.footnotesKey.getState(newState);
203
- const prevIds = oldInlineFootnoteNodes.map(([node]) => node.attrs.rids);
204
- const newIds = inlineFootnoteNodes.map(([node]) => node.attrs.rids);
100
+ const prevIds = oldInlineFootnoteNodes.map(([node]) => (0, track_changes_utils_1.getActualAttrs)(node).rids);
101
+ const newIds = inlineFootnoteNodes.map(([node]) => (0, track_changes_utils_1.getActualAttrs)(node).rids);
205
102
  const initTransaction = transactions.find((t) => t.getMeta('INIT'));
206
103
  if (!footnoteElement || (!initTransaction && (0, lodash_1.isEqual)(prevIds, newIds))) {
207
104
  return null;
@@ -210,23 +107,24 @@ exports.default = (props) => {
210
107
  const footnotesReordered = [];
211
108
  inlineFootnoteNodes.forEach(([node, pos]) => {
212
109
  const footnote = node;
213
- const contents = footnote.attrs.rids
110
+ const attrs = (0, track_changes_utils_1.getActualAttrs)(footnote);
111
+ const contents = attrs.rids
214
112
  .map((rid) => {
215
- const currentfNode = footnotes.get(rid);
216
- if (currentfNode) {
217
- footnotesReordered.push(currentfNode[0]);
113
+ const currentFnNode = footnotes.get(rid);
114
+ if (currentFnNode) {
115
+ footnotesReordered.push(currentFnNode[0]);
218
116
  }
219
117
  return labels.get(rid);
220
118
  })
221
119
  .join('');
222
- if (footnote.attrs.contents !== contents) {
120
+ if (attrs.contents !== contents) {
223
121
  tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, footnote.attrs), { rids: footnote.attrs.rids, contents }));
224
122
  }
225
123
  });
226
124
  unusedFootnotes.forEach(([node]) => footnotesReordered.push(node));
227
- const newFElement = transform_1.schema.nodes.footnotes_element.create(footnoteElement[0].attrs, footnotesReordered);
228
- if (newFElement && footnotes.size > 0) {
229
- tr.replaceWith(footnoteElement[1], footnoteElement[1] + footnoteElement[0].nodeSize, newFElement);
125
+ const newFnElement = transform_1.schema.nodes.footnotes_element.create(footnoteElement[0].attrs, footnotesReordered);
126
+ if (newFnElement && footnotes.size > 0) {
127
+ tr.replaceWith(footnoteElement[1], footnoteElement[1] + footnoteElement[0].nodeSize, newFnElement);
230
128
  }
231
129
  const prevSelection = newState.selection;
232
130
  const selectedFootnote = (0, prosemirror_utils_1.findParentNodeClosestToPos)(prevSelection.$anchor, (node) => (0, transform_1.isFootnoteNode)(node));
@@ -263,7 +161,7 @@ exports.default = (props) => {
263
161
  decorations.push(prosemirror_view_1.Decoration.node(targetNode.pos, targetNode.pos + targetNode.node.nodeSize, {
264
162
  class: 'footnote-selected',
265
163
  }));
266
- decorations.push(prosemirror_view_1.Decoration.widget(targetNode.pos + 1, deleteFootnoteWidget(targetNode.node, props, targetNode.node.attrs.id, tableElement, tableElementFooter), {
164
+ decorations.push(prosemirror_view_1.Decoration.widget(targetNode.pos + 1, (0, widgets_1.deleteFootnoteWidget)(targetNode.node, props, targetNode.node.attrs.id, tableElement, tableElementFooter), {
267
165
  key: targetNode.node.attrs.id,
268
166
  }));
269
167
  }
@@ -284,19 +182,19 @@ exports.default = (props) => {
284
182
  if (!tableInlineFootnoteIds) {
285
183
  const id = node.attrs.id;
286
184
  if (!labels || !labels.has(id)) {
287
- decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, (0, exports.uncitedFootnoteWidget)(), {
185
+ decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, (0, widgets_1.uncitedFootnoteWidget)(), {
288
186
  side: -1,
289
187
  }));
290
188
  }
291
189
  else {
292
190
  const label = labels.get(id);
293
191
  if (label) {
294
- decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, labelWidget(label, id), {
192
+ decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, (0, widgets_1.labelWidget)(label, id), {
295
193
  side: -1,
296
194
  }));
297
195
  }
298
196
  else {
299
- decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, (0, exports.uncitedFootnoteWidget)(), {
197
+ decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, (0, widgets_1.uncitedFootnoteWidget)(), {
300
198
  side: -1,
301
199
  }));
302
200
  }
@@ -307,7 +205,7 @@ exports.default = (props) => {
307
205
  }
308
206
  if (tableInlineFootnoteIds &&
309
207
  !tableInlineFootnoteIds.has(node.attrs.id)) {
310
- decorations.push(prosemirror_view_1.Decoration.widget(pos + node.nodeSize - 1, (0, exports.uncitedFootnoteWidget)()));
208
+ decorations.push(prosemirror_view_1.Decoration.widget(pos + node.nodeSize - 1, (0, widgets_1.uncitedFootnoteWidget)()));
311
209
  }
312
210
  }
313
211
  });
@@ -0,0 +1,131 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.uncitedFootnoteWidget = exports.labelWidget = exports.deleteFootnoteWidget = void 0;
22
+ const style_guide_1 = require("@manuscripts/style-guide");
23
+ const transform_1 = require("@manuscripts/transform");
24
+ const prosemirror_state_1 = require("prosemirror-state");
25
+ const prosemirror_utils_1 = require("prosemirror-utils");
26
+ const react_1 = require("react");
27
+ const server_1 = require("react-dom/server");
28
+ const DeleteFootnoteDialog_1 = require("../../components/views/DeleteFootnoteDialog");
29
+ const footnotes_1 = require("../../lib/footnotes");
30
+ const utils_1 = require("../../lib/utils");
31
+ const ReactSubView_1 = __importDefault(require("../../views/ReactSubView"));
32
+ const track_changes_utils_1 = require("../../lib/track-changes-utils");
33
+ const deleteFootnoteWidget = (node, props, id, tableElement, tableElementFooter) => (view, getPos) => {
34
+ const deleteBtn = document.createElement('span');
35
+ deleteBtn.className = 'delete-icon';
36
+ deleteBtn.innerHTML = (0, server_1.renderToStaticMarkup)((0, react_1.createElement)(style_guide_1.DeleteIcon));
37
+ const parentType = tableElement ? 'table ' : '';
38
+ const footnote = {
39
+ type: node.type === transform_1.schema.nodes.footnote
40
+ ? `${parentType}footnote`
41
+ : 'table general note',
42
+ message: node.type === transform_1.schema.nodes.footnote
43
+ ? `This action will entirely remove the ${parentType}footnote from the list because it will no longer be used.`
44
+ : 'This action will entirely remove the table general note.',
45
+ };
46
+ deleteBtn.addEventListener('mousedown', () => {
47
+ const handleDelete = () => {
48
+ const tr = view.state.tr;
49
+ const pos = getPos();
50
+ if (node.type === transform_1.schema.nodes.general_table_footnote && pos) {
51
+ if (tableElementFooter &&
52
+ !(0, utils_1.getChildOfType)(tableElementFooter.node, transform_1.schema.nodes.footnotes_element, true) &&
53
+ tableElementFooter.pos) {
54
+ tr.delete(tableElementFooter.pos - 1, tableElementFooter.pos + tableElementFooter.node.nodeSize);
55
+ }
56
+ else {
57
+ tr.delete(pos - 1, pos + node.nodeSize + 1);
58
+ }
59
+ }
60
+ if (node.type === transform_1.schema.nodes.footnote && pos) {
61
+ const targetNode = tableElement ? tableElement.node : view.state.doc;
62
+ const inlineFootnotes = (0, footnotes_1.getInlineFootnotes)(id, targetNode);
63
+ const footnotesElement = (0, prosemirror_utils_1.findParentNodeClosestToPos)(tr.doc.resolve(pos), (node) => node.type === transform_1.schema.nodes.footnotes_element);
64
+ if ((footnotesElement === null || footnotesElement === void 0 ? void 0 : footnotesElement.node.childCount) === 1 &&
65
+ (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.node.childCount) === 1) {
66
+ const { pos: fnPos, node: fnNode } = tableElementFooter;
67
+ tr.delete(fnPos, fnPos + fnNode.nodeSize + 1);
68
+ }
69
+ else if ((footnotesElement === null || footnotesElement === void 0 ? void 0 : footnotesElement.node.childCount) === 1) {
70
+ const { pos: fnPos, node: fnNode } = footnotesElement;
71
+ tr.delete(fnPos, fnPos + fnNode.nodeSize + 1);
72
+ }
73
+ else {
74
+ const footnote = (0, prosemirror_utils_1.findParentNodeClosestToPos)(tr.doc.resolve(pos), (node) => node.type === transform_1.schema.nodes.footnote);
75
+ if (footnote) {
76
+ const { pos: fnPos, node: fnNode } = footnote;
77
+ tr.delete(fnPos, fnPos + fnNode.nodeSize + 1);
78
+ }
79
+ }
80
+ if (inlineFootnotes) {
81
+ inlineFootnotes.forEach((footnote) => {
82
+ const pos = footnote.pos + (tableElement ? tableElement.pos + 1 : 0);
83
+ if (footnote.node.attrs.rids.length > 1) {
84
+ const updatedRids = footnote.node.attrs.rids.filter((rid) => rid !== id);
85
+ tr.setNodeMarkup(tr.mapping.map(pos), undefined, Object.assign(Object.assign({}, node.attrs), { rids: updatedRids }));
86
+ }
87
+ else {
88
+ tr.delete(tr.mapping.map(pos), tr.mapping.map(pos + footnote.node.nodeSize));
89
+ }
90
+ });
91
+ }
92
+ }
93
+ view.dispatch(tr);
94
+ };
95
+ const componentProps = {
96
+ footnoteType: footnote.type,
97
+ footnoteMessage: footnote.message,
98
+ handleDelete: handleDelete,
99
+ };
100
+ (0, ReactSubView_1.default)(Object.assign(Object.assign({}, props), { dispatch: view.dispatch }), DeleteFootnoteDialog_1.DeleteFootnoteDialog, componentProps, node, () => getPos(), view);
101
+ });
102
+ return deleteBtn;
103
+ };
104
+ exports.deleteFootnoteWidget = deleteFootnoteWidget;
105
+ const scrollToInlineFootnote = (rid, view) => {
106
+ view.state.doc.descendants((node, pos) => {
107
+ const footnote = node;
108
+ if ((0, transform_1.isInlineFootnoteNode)(node) &&
109
+ (0, track_changes_utils_1.getActualAttrs)(footnote).rids.includes(rid)) {
110
+ const selection = prosemirror_state_1.NodeSelection.create(view.state.doc, pos);
111
+ view.dispatch(view.state.tr.setSelection(selection).scrollIntoView());
112
+ }
113
+ });
114
+ };
115
+ const labelWidget = (label, id) => (view) => {
116
+ const element = document.createElement('span');
117
+ element.className = 'footnote-label';
118
+ element.textContent = label;
119
+ element.addEventListener('mousedown', () => {
120
+ scrollToInlineFootnote(id, view);
121
+ });
122
+ return element;
123
+ };
124
+ exports.labelWidget = labelWidget;
125
+ const uncitedFootnoteWidget = () => () => {
126
+ const element = document.createElement('span');
127
+ element.className = 'uncited-footnote';
128
+ element.innerHTML = (0, server_1.renderToStaticMarkup)((0, react_1.createElement)(style_guide_1.AlertIcon));
129
+ return element;
130
+ };
131
+ exports.uncitedFootnoteWidget = uncitedFootnoteWidget;
@@ -4,9 +4,7 @@ exports.sectionTitleKey = void 0;
4
4
  const transform_1 = require("@manuscripts/transform");
5
5
  const prosemirror_state_1 = require("prosemirror-state");
6
6
  const prosemirror_utils_1 = require("prosemirror-utils");
7
- const prosemirror_view_1 = require("prosemirror-view");
8
- const track_changes_utils_1 = require("../../lib/track-changes-utils");
9
- const autocompletion_1 = require("./autocompletion");
7
+ const track_changes_utils_1 = require("../lib/track-changes-utils");
10
8
  exports.sectionTitleKey = new prosemirror_state_1.PluginKey('sectionNumbering');
11
9
  const calculateSectionLevels = (node, startPos, sectionNumberMap, numbering = [0]) => {
12
10
  node.forEach((childNode, offset) => {
@@ -37,21 +35,6 @@ const getPluginState = (doc) => {
37
35
  exports.default = () => {
38
36
  return new prosemirror_state_1.Plugin({
39
37
  key: exports.sectionTitleKey,
40
- props: {
41
- decorations(state) {
42
- const text = (0, autocompletion_1.checkForCompletion)(state);
43
- if (text) {
44
- const decoration = prosemirror_view_1.Decoration.widget(state.selection.from, () => {
45
- const node = document.createElement('span');
46
- node.classList.add('completion-bearer');
47
- node.dataset.suggest = text.suggestion;
48
- return node;
49
- });
50
- return prosemirror_view_1.DecorationSet.create(state.doc, [decoration]);
51
- }
52
- return prosemirror_view_1.DecorationSet.empty;
53
- },
54
- },
55
38
  state: {
56
39
  init: (_, state) => {
57
40
  return getPluginState(state.doc);
@@ -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 = '2.0.46-LEAN-3883.1';
4
+ exports.VERSION = '2.0.46';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -36,6 +36,7 @@ const setTCClasses = (node, dom) => {
36
36
  const changeClasses = (0, track_changes_utils_1.getChangeClasses)([lastChange]);
37
37
  dom.classList.add(...changeClasses);
38
38
  }
39
+ dom.setAttribute('id', node.attrs.id);
39
40
  };
40
41
  exports.setTCClasses = setTCClasses;
41
42
  exports.default = (0, creators_1.createNodeOrElementView)(FootnoteView, 'div', exports.setTCClasses);