@manuscripts/body-editor 1.5.16 → 1.6.1

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 (80) hide show
  1. package/dist/cjs/commands.js +53 -132
  2. package/dist/cjs/components/outline/DraggableTree.js +33 -25
  3. package/dist/cjs/components/toolbar/OrderListSelector.js +3 -11
  4. package/dist/cjs/configs/editor-plugins.js +2 -2
  5. package/dist/cjs/configs/editor-views.js +4 -6
  6. package/dist/cjs/lib/context-menu.js +6 -5
  7. package/dist/cjs/node-type-icons.js +0 -1
  8. package/dist/cjs/plugins/bibliography/bibliography-utils.js +60 -47
  9. package/dist/cjs/plugins/bibliography/index.js +48 -63
  10. package/dist/cjs/plugins/comment_annotation.js +2 -2
  11. package/dist/cjs/plugins/footnotes/index.js +19 -10
  12. package/dist/cjs/plugins/persist.js +21 -31
  13. package/dist/cjs/plugins/sections.js +1 -2
  14. package/dist/cjs/plugins/toc.js +28 -23
  15. package/dist/cjs/useEditor.js +1 -3
  16. package/dist/cjs/views/bibliography_element.js +20 -38
  17. package/dist/cjs/views/citation.js +29 -26
  18. package/dist/cjs/views/citation_editable.js +25 -44
  19. package/dist/cjs/views/{contributors_section.js → contributors.js} +4 -4
  20. package/dist/cjs/views/cross_reference.js +7 -36
  21. package/dist/cjs/views/cross_reference_editable.js +6 -14
  22. package/dist/cjs/views/editable_block.js +2 -2
  23. package/dist/cjs/views/{meta_section.js → empty.js} +3 -3
  24. package/dist/cjs/views/section_title.js +1 -16
  25. package/dist/es/commands.js +55 -110
  26. package/dist/es/components/outline/DraggableTree.js +33 -25
  27. package/dist/es/components/toolbar/OrderListSelector.js +4 -12
  28. package/dist/es/configs/editor-plugins.js +2 -2
  29. package/dist/es/configs/editor-views.js +4 -6
  30. package/dist/es/lib/context-menu.js +7 -6
  31. package/dist/es/node-type-icons.js +0 -1
  32. package/dist/es/plugins/bibliography/bibliography-utils.js +56 -45
  33. package/dist/es/plugins/bibliography/index.js +49 -65
  34. package/dist/es/plugins/comment_annotation.js +2 -2
  35. package/dist/es/plugins/footnotes/index.js +20 -11
  36. package/dist/es/plugins/persist.js +22 -32
  37. package/dist/es/plugins/sections.js +2 -3
  38. package/dist/es/plugins/toc.js +29 -24
  39. package/dist/es/useEditor.js +2 -4
  40. package/dist/es/views/bibliography_element.js +21 -39
  41. package/dist/es/views/citation.js +31 -28
  42. package/dist/es/views/citation_editable.js +28 -47
  43. package/dist/es/views/{contributors_section.js → contributors.js} +2 -2
  44. package/dist/es/views/cross_reference.js +7 -33
  45. package/dist/es/views/cross_reference_editable.js +6 -14
  46. package/dist/es/views/editable_block.js +3 -3
  47. package/dist/es/views/{meta_section.js → empty.js} +3 -3
  48. package/dist/es/views/section_title.js +0 -14
  49. package/dist/types/commands.d.ts +1 -2
  50. package/dist/types/components/outline/DraggableTree.d.ts +1 -2
  51. package/dist/types/configs/ManuscriptsEditor.d.ts +1 -10
  52. package/dist/types/configs/editor-plugins.d.ts +1 -5
  53. package/dist/types/configs/editor-views.d.ts +5 -6
  54. package/dist/types/lib/context-menu.d.ts +0 -1
  55. package/dist/types/plugins/bibliography/bibliography-utils.d.ts +10 -7
  56. package/dist/types/plugins/bibliography/index.d.ts +21 -3
  57. package/dist/types/views/bibliography_element.d.ts +1 -0
  58. package/dist/types/views/citation.d.ts +3 -4
  59. package/dist/types/views/citation_editable.d.ts +2 -8
  60. package/dist/types/views/{contributors_section.d.ts → contributors.d.ts} +3 -3
  61. package/dist/types/views/cross_reference.d.ts +0 -5
  62. package/dist/types/views/{meta_section.d.ts → empty.d.ts} +2 -2
  63. package/dist/types/views/section_title.d.ts +0 -2
  64. package/package.json +4 -22
  65. package/styles/AdvancedEditor.css +30 -34
  66. package/dist/cjs/plugins/auxiliary_object_order.js +0 -49
  67. package/dist/cjs/plugins/bibliography/types.js +0 -17
  68. package/dist/cjs/plugins/footnotes/footnotes-utils.js +0 -52
  69. package/dist/cjs/views/bibliography_item.js +0 -138
  70. package/dist/cjs/views/bibliography_item_editable.js +0 -20
  71. package/dist/es/plugins/auxiliary_object_order.js +0 -46
  72. package/dist/es/plugins/bibliography/types.js +0 -16
  73. package/dist/es/plugins/footnotes/footnotes-utils.js +0 -46
  74. package/dist/es/views/bibliography_item.js +0 -131
  75. package/dist/es/views/bibliography_item_editable.js +0 -18
  76. package/dist/types/plugins/auxiliary_object_order.d.ts +0 -12
  77. package/dist/types/plugins/bibliography/types.d.ts +0 -40
  78. package/dist/types/plugins/footnotes/footnotes-utils.d.ts +0 -25
  79. package/dist/types/views/bibliography_item.d.ts +0 -34
  80. package/dist/types/views/bibliography_item_editable.d.ts +0 -18
@@ -33,39 +33,20 @@ var __rest = (this && this.__rest) || function (s, e) {
33
33
  }
34
34
  return t;
35
35
  };
36
- import { CitationProvider } from '@manuscripts/library';
37
36
  import { CHANGE_OPERATION, CHANGE_STATUS, } from '@manuscripts/track-changes-plugin';
38
37
  import { buildComment } from '@manuscripts/transform';
39
38
  import React from 'react';
40
39
  import { commentIcon, editIcon } from '../assets';
41
40
  import { sanitize } from '../lib/dompurify';
42
- import { bibliographyKey } from '../plugins/bibliography';
43
- import { getReferencesModelMap } from '../plugins/bibliography/bibliography-utils';
41
+ import { getBibliographyPluginState } from '../plugins/bibliography';
44
42
  import { commentAnnotation } from '../plugins/comment_annotation';
45
43
  import { getAttrsTrackingButton, getMarkDecoration, } from '../plugins/tracking-mark';
46
44
  import BlockView from './block_view';
47
45
  import { createNodeView } from './creators';
48
- const createBibliography = (bibliographyItems, cslProps) => __awaiter(void 0, void 0, void 0, function* () {
49
- const bibliographyItemsMap = new Map(bibliographyItems.map((item) => [item._id, item]));
50
- const getLibraryItem = (id) => bibliographyItemsMap.get(id);
51
- const { style = '', locale } = cslProps;
52
- const provider = new CitationProvider({
53
- getLibraryItem,
54
- citationStyle: style,
55
- locale,
56
- });
57
- const [bibmeta, generatedBibliographyItems] = provider.makeBibliography(bibliographyItems);
58
- if (bibmeta.bibliography_errors.length) {
59
- console.error(bibmeta.bibliography_errors);
60
- }
61
- const bibliographyFragment = generatedBibliographyItems
62
- .map((item, i) => `<div id=${bibmeta.entry_ids[i]} class="bib-item"><div><div class="csl-bib-body">${item}</div></div></div>`)
63
- .join('');
64
- return sanitize(`<div class="contents">${bibliographyFragment}</div>`);
65
- });
66
46
  export class BibliographyElementBlockView extends BlockView {
67
47
  constructor() {
68
48
  super(...arguments);
49
+ this.gutterButtons = () => [];
69
50
  this.showPopper = (referenceID) => {
70
51
  const { renderReactComponent, components: { ReferencesEditor }, } = this.props;
71
52
  const handleSave = (data) => __awaiter(this, void 0, void 0, function* () {
@@ -78,13 +59,14 @@ export class BibliographyElementBlockView extends BlockView {
78
59
  this.popperContainer = document.createElement('div');
79
60
  this.popperContainer.className = 'references';
80
61
  }
81
- renderReactComponent(React.createElement(ReferencesEditor, { saveModel: handleSave, deleteModel: this.deleteNode, modelMap: getReferencesModelMap(this.view.state.doc, true), referenceID: referenceID }), this.popperContainer);
62
+ const bib = getBibliographyPluginState(this.view.state);
63
+ renderReactComponent(React.createElement(ReferencesEditor, { saveModel: handleSave, deleteModel: this.deleteNode, modelMap: bib.bibliographyItems, referenceID: referenceID }), this.popperContainer);
82
64
  this.props.popper.show(this.dom, this.popperContainer, 'right');
83
65
  };
84
66
  this.stopEvent = () => true;
85
67
  this.ignoreMutation = () => true;
86
68
  this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
87
- const bibliographyItems = bibliographyKey.getState(this.view.state).bibliographyItems;
69
+ const bib = getBibliographyPluginState(this.view.state);
88
70
  const commentsDecorationSet = commentAnnotation.getState(this.view.state);
89
71
  const commentElementMap = new Map();
90
72
  const dataTrackedMap = new Map();
@@ -103,9 +85,14 @@ export class BibliographyElementBlockView extends BlockView {
103
85
  dataTrackedMap.set(node.attrs.id, lastChange);
104
86
  }
105
87
  });
106
- const bibliographyFragment = yield createBibliography(bibliographyItems, this.props.cslProps);
107
- const bibItems = bibliographyFragment.querySelectorAll('.bib-item');
108
- bibItems.forEach((element) => {
88
+ const can = this.props.getCapabilities();
89
+ const wrapper = document.createElement('div');
90
+ wrapper.classList.add('contents');
91
+ const [meta, bibliography] = bib.provider.makeBibliography();
92
+ for (let i = 0; i < bibliography.length; i++) {
93
+ const id = meta.entry_ids[i];
94
+ const fragment = bibliography[i];
95
+ const element = sanitize(`<div id="${id}" class="bib-item"><div class="csl-bib-body">${fragment}</div></div>`).firstElementChild;
109
96
  const doubleButton = document.createElement('div');
110
97
  const editButton = document.createElement('button');
111
98
  const commentButton = document.createElement('button');
@@ -124,14 +111,14 @@ export class BibliographyElementBlockView extends BlockView {
124
111
  editButton.innerHTML = editIcon;
125
112
  commentButton.innerHTML = commentIcon;
126
113
  doubleButton.append(editButton, commentButton);
127
- if (this.props.getCapabilities().seeReferencesButtons &&
114
+ if (can.seeReferencesButtons &&
128
115
  !element.querySelector('.bibliography-double-button')) {
129
116
  element.appendChild(doubleButton);
130
117
  }
131
- editButton.disabled = !this.props.getCapabilities().editCitationsAndRefs;
118
+ editButton.disabled = !can.editCitationsAndRefs;
132
119
  const commentElement = commentElementMap.get(element.id);
133
120
  if (commentElement) {
134
- element.childNodes[0].appendChild(commentElement);
121
+ element.appendChild(commentElement);
135
122
  }
136
123
  const dataTracked = dataTrackedMap.get(element.id);
137
124
  if (dataTracked) {
@@ -140,16 +127,17 @@ export class BibliographyElementBlockView extends BlockView {
140
127
  decoration.style && element.setAttribute('style', decoration.style);
141
128
  if (dataTracked.status === CHANGE_STATUS.pending &&
142
129
  dataTracked.operation === CHANGE_OPERATION.set_node_attributes) {
143
- element.childNodes[0].appendChild(getAttrsTrackingButton(dataTracked.id));
130
+ element.appendChild(getAttrsTrackingButton(dataTracked.id));
144
131
  }
145
132
  }
146
- });
133
+ wrapper.append(element);
134
+ }
147
135
  const oldContent = this.container.querySelector('.contents');
148
136
  if (oldContent) {
149
- this.container.replaceChild(bibliographyFragment, oldContent);
137
+ this.container.replaceChild(wrapper, oldContent);
150
138
  }
151
139
  else {
152
- this.container.appendChild(bibliographyFragment);
140
+ this.container.appendChild(wrapper);
153
141
  }
154
142
  });
155
143
  this.createElement = () => {
@@ -158,12 +146,6 @@ export class BibliographyElementBlockView extends BlockView {
158
146
  this.container.contentEditable = 'false';
159
147
  this.dom.setAttribute('contenteditable', 'false');
160
148
  this.dom.appendChild(this.container);
161
- this.contentDOM = document.createElement('div');
162
- this.contentDOM.classList.add('block');
163
- this.contentDOM.setAttribute('id', this.node.attrs.id);
164
- this.contentDOM.setAttribute('contenteditable', 'false');
165
- this.contentDOM.hidden = true;
166
- this.container.appendChild(this.contentDOM);
167
149
  };
168
150
  }
169
151
  }
@@ -13,34 +13,23 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { ObjectTypes, } from '@manuscripts/json-schema';
16
+ import { ObjectTypes } from '@manuscripts/json-schema';
17
17
  import { DOMSerializer } from 'prosemirror-model';
18
18
  import React, { createElement } from 'react';
19
19
  import ReactDOM from 'react-dom';
20
20
  import { TrackChangesReview } from '../components/track-changes/TrackChangesReview';
21
21
  import { sanitize } from '../lib/dompurify';
22
22
  import { getChangeClasses, isDeleted, isPendingSetAttrs, } from '../lib/track-changes-utils';
23
- import { getNodeModel } from '../plugins/bibliography/bibliography-utils';
23
+ import { getBibliographyPluginState } from '../plugins/bibliography';
24
+ import { getCitation } from '../plugins/bibliography/bibliography-utils';
24
25
  import { BaseNodeView } from './base_node_view';
25
26
  import { createNodeView } from './creators';
26
27
  export class CitationView extends BaseNodeView {
27
28
  constructor() {
28
29
  super(...arguments);
29
30
  this.showPopper = () => {
30
- const { components: { CitationViewer }, getLibraryItem, projectID, renderReactComponent, } = this.props;
31
- const citation = this.getCitation();
32
- const items = citation.embeddedCitationItems.map((citationItem) => {
33
- const libraryItem = getLibraryItem(citationItem.bibliographyItem);
34
- if (!libraryItem) {
35
- const placeholderItem = {
36
- _id: citationItem.bibliographyItem,
37
- objectType: ObjectTypes.BibliographyItem,
38
- title: '[missing library item]',
39
- };
40
- return placeholderItem;
41
- }
42
- return libraryItem;
43
- });
31
+ const { components: { CitationViewer }, projectID, renderReactComponent, } = this.props;
32
+ const items = this.getBibliographyItems();
44
33
  if (!this.popperContainer) {
45
34
  this.popperContainer = document.createElement('div');
46
35
  this.popperContainer.className = 'citation-editor';
@@ -82,27 +71,25 @@ export class CitationView extends BaseNodeView {
82
71
  return this;
83
72
  };
84
73
  this.updateContents = () => {
74
+ const bib = getBibliographyPluginState(this.view.state);
85
75
  const citation = this.getCitation();
86
- const nodeClasses = ['citation', ...getChangeClasses(this.node)];
87
- const citationElement = document.createElement('span');
88
- citationElement.className = nodeClasses.join(' ');
89
- const citeprocCitations = this.props.getCiteprocCitations();
90
- const citeprocContent = citeprocCitations === null || citeprocCitations === void 0 ? void 0 : citeprocCitations.get(this.node.attrs.rid);
91
- const fragment = sanitize(citeprocContent && citeprocContent !== '[NO_PRINTED_FORM]'
92
- ? citeprocContent
93
- : ' ', {
76
+ const classes = ['citation', ...getChangeClasses(this.node)];
77
+ const element = document.createElement('span');
78
+ element.className = classes.join(' ');
79
+ const text = bib.renderedCitations.get(citation._id);
80
+ const fragment = sanitize(text && text !== '[NO_PRINTED_FORM]' ? text : ' ', {
94
81
  ALLOWED_TAGS: ['i', 'b', 'span', 'sup', 'sub', '#text'],
95
82
  });
96
- citationElement.appendChild(fragment);
83
+ element.appendChild(fragment);
97
84
  this.dom.className = 'citation-wrapper';
98
85
  this.dom.innerHTML = '';
99
- this.dom.appendChild(citationElement);
86
+ this.dom.appendChild(element);
100
87
  if (isPendingSetAttrs(this.node) &&
101
88
  !isDeleted(this.node) &&
102
89
  citation.embeddedCitationItems.length) {
103
90
  this.dom.appendChild(this.renderTrackChangesReview());
104
91
  }
105
- this.setDomAttrs(this.node, this.dom, ['rid', 'contents', 'selectedText']);
92
+ this.setDomAttrs(this.node, this.dom, ['rids', 'contents', 'selectedText']);
106
93
  };
107
94
  this.renderTrackChangesReview = () => {
108
95
  const { popper } = this.props;
@@ -116,12 +103,28 @@ export class CitationView extends BaseNodeView {
116
103
  return el;
117
104
  };
118
105
  this.getCitation = () => {
119
- const citation = getNodeModel(this.node);
106
+ const citation = getCitation(this.node);
120
107
  if (!citation) {
121
108
  throw new Error('Citation not found');
122
109
  }
123
110
  return citation;
124
111
  };
112
+ this.getBibliographyItems = () => {
113
+ const bib = getBibliographyPluginState(this.view.state);
114
+ const citation = this.node;
115
+ return citation.attrs.rids.map((rid) => {
116
+ const item = bib.bibliographyItems.get(rid);
117
+ if (!item) {
118
+ const placeholder = {
119
+ _id: rid,
120
+ objectType: ObjectTypes.BibliographyItem,
121
+ title: '[missing library item]',
122
+ };
123
+ return placeholder;
124
+ }
125
+ return item;
126
+ });
127
+ };
125
128
  }
126
129
  }
127
130
  export default createNodeView(CitationView);
@@ -34,12 +34,11 @@ var __rest = (this && this.__rest) || function (s, e) {
34
34
  return t;
35
35
  };
36
36
  import { ObjectTypes, } from '@manuscripts/json-schema';
37
- import { matchLibraryItemByIdentifier } from '@manuscripts/library';
38
- import { buildEmbeddedCitationItem, schema, } from '@manuscripts/transform';
37
+ import { findMatchingBibliographyItem } from '@manuscripts/library';
38
+ import { schema } from '@manuscripts/transform';
39
39
  import { TextSelection } from 'prosemirror-state';
40
40
  import React from 'react';
41
- import { bibliographyKey } from '../plugins/bibliography';
42
- import { getReferencesModelMap } from '../plugins/bibliography/bibliography-utils';
41
+ import { getBibliographyPluginState } from '../plugins/bibliography';
43
42
  import { CitationView } from './citation';
44
43
  import { createEditableNodeView } from './creators';
45
44
  const createBibliographySection = (bibItem) => schema.nodes.bibliography_section.createAndFill({}, [
@@ -53,20 +52,9 @@ export class CitationEditableView extends CitationView {
53
52
  const { components: { CitationEditor, CitationViewer }, getCapabilities, projectID, renderReactComponent, } = this.props;
54
53
  const capabilities = getCapabilities();
55
54
  const citation = this.getCitation();
56
- const items = citation.embeddedCitationItems.map((citationItem) => {
57
- const libraryItem = getReferencesModelMap(this.view.state.doc).get(citationItem.bibliographyItem);
58
- if (!libraryItem) {
59
- const placeholderItem = {
60
- _id: citationItem.bibliographyItem,
61
- objectType: ObjectTypes.BibliographyItem,
62
- title: '[missing library item]',
63
- };
64
- return placeholderItem;
65
- }
66
- return libraryItem;
67
- });
55
+ const items = this.getBibliographyItems();
68
56
  const updateCitation = (data) => __awaiter(this, void 0, void 0, function* () {
69
- this.updateInlineNode(Object.assign(Object.assign({}, citation), data));
57
+ this.updateNode(Object.assign(Object.assign({}, citation), data));
70
58
  this.props.popper.update();
71
59
  });
72
60
  const findPosition = (doc, id) => {
@@ -93,7 +81,8 @@ export class CitationEditableView extends CitationView {
93
81
  this.popperContainer = document.createElement('div');
94
82
  this.popperContainer.className = 'citation-editor';
95
83
  }
96
- const component = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.editArticle) ? (React.createElement(CitationEditor, { items: items, saveModel: handleSave, deleteModel: this.deleteNode, modelMap: getReferencesModelMap(this.view.state.doc, true), insertBibliographyNode: (item) => this.insertBibliographyNode(this.view, item), importItems: this.importItems, selectedText: this.node.attrs.selectedText, setComment: this.props.setComment, handleCancel: this.handleCancel, handleClose: this.handleClose, handleRemove: this.handleRemove, updatePopper: this.updatePopper, handleCite: this.handleCite, canEdit: capabilities.editCitationsAndRefs, citation: citation, updateCitation: updateCitation, projectID: projectID, scheduleUpdate: this.props.popper.update })) : (React.createElement(CitationViewer, { items: items, setComment: this.props.setComment, scheduleUpdate: this.props.popper.update }));
84
+ const bib = getBibliographyPluginState(this.view.state);
85
+ const component = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.editArticle) ? (React.createElement(CitationEditor, { items: items, saveModel: handleSave, deleteModel: this.deleteNode, insertBibliographyNode: (item) => this.insertBibliographyNode(this.view, item), modelMap: bib.bibliographyItems, importItems: this.importItems, selectedText: this.node.attrs.selectedText, setComment: this.props.setComment, handleCancel: this.handleCancel, handleClose: this.handleClose, handleRemove: this.handleRemove, updatePopper: this.updatePopper, handleCite: this.handleCite, canEdit: capabilities.editCitationsAndRefs, citation: citation, updateCitation: updateCitation, projectID: projectID, scheduleUpdate: this.props.popper.update })) : (React.createElement(CitationViewer, { items: items, setComment: this.props.setComment, scheduleUpdate: this.props.popper.update }));
97
86
  renderReactComponent(component, this.popperContainer);
98
87
  this.props.popper.show(this.dom, this.popperContainer, 'right');
99
88
  };
@@ -111,10 +100,10 @@ export class CitationEditableView extends CitationView {
111
100
  };
112
101
  this.handleRemove = (id) => __awaiter(this, void 0, void 0, function* () {
113
102
  const citation = this.getCitation();
114
- const embeddedCitationItems = citation.embeddedCitationItems.filter((item) => item.bibliographyItem !== id);
115
- if (embeddedCitationItems.length > 0) {
116
- citation.embeddedCitationItems = embeddedCitationItems;
117
- this.updateInlineNode(citation);
103
+ const items = citation.embeddedCitationItems.filter((i) => i.bibliographyItem !== id);
104
+ if (items.length > 0) {
105
+ citation.embeddedCitationItems = items;
106
+ this.updateNode(citation);
118
107
  window.setTimeout(() => {
119
108
  this.showPopper();
120
109
  }, 100);
@@ -125,9 +114,6 @@ export class CitationEditableView extends CitationView {
125
114
  tr.delete(pos, pos + 1);
126
115
  this.view.dispatch(tr);
127
116
  }
128
- this.view.dispatch(this.view.state.tr.setMeta(bibliographyKey, {
129
- bibliographyInserted: true,
130
- }));
131
117
  this.props.popper.destroy();
132
118
  });
133
119
  this.updatePopper = () => {
@@ -137,46 +123,43 @@ export class CitationEditableView extends CitationView {
137
123
  }, 100);
138
124
  };
139
125
  this.handleCite = (items) => __awaiter(this, void 0, void 0, function* () {
126
+ const bib = getBibliographyPluginState(this.view.state);
140
127
  const citation = this.getCitation();
141
- let triggerUpdate = false;
142
128
  for (const item of items) {
143
- const existingItem = matchLibraryItemByIdentifier(item, getReferencesModelMap(this.view.state.doc));
129
+ const existingItem = findMatchingBibliographyItem(item, bib.bibliographyItems);
144
130
  if (existingItem) {
145
131
  item._id = existingItem._id;
146
132
  }
147
133
  else {
148
- triggerUpdate = true;
149
- yield this.insertBibliographyNode(this.view, item);
134
+ this.insertBibliographyNode(this.view, item);
150
135
  }
151
- citation.embeddedCitationItems.push(buildEmbeddedCitationItem(item._id));
152
- }
153
- this.updateInlineNode(citation);
154
- if (triggerUpdate) {
155
- this.view.dispatch(this.view.state.tr.setMeta(bibliographyKey, {
156
- bibliographyInserted: true,
157
- }));
136
+ citation.embeddedCitationItems.push({
137
+ _id: '_',
138
+ objectType: ObjectTypes.CitationItem,
139
+ bibliographyItem: item._id,
140
+ });
158
141
  }
142
+ this.updateNode(citation);
159
143
  this.handleClose();
160
144
  });
161
145
  this.importItems = (items) => __awaiter(this, void 0, void 0, function* () {
146
+ const bib = getBibliographyPluginState(this.view.state);
162
147
  const newItems = [];
163
148
  for (const item of items) {
164
- const existingItem = matchLibraryItemByIdentifier(item, getReferencesModelMap(this.view.state.doc));
149
+ const existingItem = findMatchingBibliographyItem(item, bib.bibliographyItems);
165
150
  if (!existingItem) {
166
- yield this.insertBibliographyNode(this.view, item);
151
+ this.insertBibliographyNode(this.view, item);
167
152
  newItems.push(item);
168
153
  }
169
154
  }
170
155
  return newItems;
171
156
  });
172
- this.updateInlineNode = (citation) => {
157
+ this.updateNode = (citation) => {
158
+ const rids = citation.embeddedCitationItems.map((i) => i.bibliographyItem);
173
159
  const { tr } = this.view.state;
174
160
  this.view.dispatch(tr.setNodeMarkup(this.getPos(), undefined, {
175
- rid: citation._id,
176
- embeddedCitationItems: citation.embeddedCitationItems.map((item) => ({
177
- id: item._id,
178
- bibliographyItem: item.bibliographyItem,
179
- })),
161
+ id: citation._id,
162
+ rids,
180
163
  }));
181
164
  };
182
165
  }
@@ -198,9 +181,7 @@ export class CitationEditableView extends CitationView {
198
181
  newTr = tr.insert(pos + 1, bibItem);
199
182
  }
200
183
  else {
201
- newTr = tr
202
- .insert(tr.doc.content.size, createBibliographySection(bibItem))
203
- .setMeta(bibliographyKey, { bibliographyInserted: true });
184
+ newTr = tr.insert(tr.doc.content.size, createBibliographySection(bibItem));
204
185
  }
205
186
  view.dispatch(newTr);
206
187
  return false;
@@ -1,7 +1,7 @@
1
1
  import { BaseNodeView } from './base_node_view';
2
2
  import { createNodeView } from './creators';
3
3
  import ReactSubView from './ReactSubView';
4
- export class ContributorsSectionView extends BaseNodeView {
4
+ export class ContributorsView extends BaseNodeView {
5
5
  constructor() {
6
6
  super(...arguments);
7
7
  this.initialise = () => {
@@ -25,4 +25,4 @@ export class ContributorsSectionView extends BaseNodeView {
25
25
  this.stopEvent = () => true;
26
26
  }
27
27
  }
28
- export default createNodeView(ContributorsSectionView);
28
+ export default createNodeView(ContributorsView);
@@ -13,9 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import React from 'react';
17
16
  import { getChangeClasses } from '../lib/track-changes-utils';
18
- import { objectsKey } from '../plugins/objects';
19
17
  import { BaseNodeView } from './base_node_view';
20
18
  import { createNodeView } from './creators';
21
19
  export class CrossReferenceView extends BaseNodeView {
@@ -24,38 +22,15 @@ export class CrossReferenceView extends BaseNodeView {
24
22
  this.selectNode = () => {
25
23
  };
26
24
  this.handleClick = () => {
27
- const auxiliaryObjectReference = this.getAuxiliaryObjectReference(this.node.attrs.rid);
28
- if (auxiliaryObjectReference) {
29
- if (auxiliaryObjectReference.referencedObjects) {
30
- this.showPopper(auxiliaryObjectReference.referencedObjects);
31
- }
32
- else {
33
- this.props.history.push({
34
- pathname: this.props.history.location.pathname,
35
- hash: '#' + auxiliaryObjectReference.referencedObject,
36
- });
37
- }
25
+ const xref = this.node;
26
+ const rids = xref.attrs.rids;
27
+ if (!rids.length) {
28
+ return;
38
29
  }
39
- };
40
- this.showPopper = (referencedObjects) => {
41
- const { components: { ReferencesViewer }, renderReactComponent, } = this.props;
42
- if (!this.popperContainer) {
43
- this.popperContainer = document.createElement('div');
44
- this.popperContainer.className = 'citation-references';
45
- }
46
- const targets = objectsKey.getState(this.view.state);
47
- const items = [];
48
- referencedObjects.map((referencedObject) => {
49
- const target = targets.get(referencedObject);
50
- if (target && target.label) {
51
- items.push({
52
- label: target.label,
53
- referencedObject,
54
- });
55
- }
30
+ this.props.history.push({
31
+ pathname: this.props.history.location.pathname,
32
+ hash: '#' + rids[0],
56
33
  });
57
- renderReactComponent(React.createElement(ReferencesViewer, { items: items, history: this.props.history }), this.popperContainer);
58
- this.props.popper.show(this.dom, this.popperContainer, 'right');
59
34
  };
60
35
  this.updateContents = () => {
61
36
  const nodeClasses = ['cross-reference', ...getChangeClasses(this.node)];
@@ -68,7 +43,6 @@ export class CrossReferenceView extends BaseNodeView {
68
43
  this.updateContents();
69
44
  };
70
45
  this.ignoreMutation = () => true;
71
- this.getAuxiliaryObjectReference = (id) => this.props.getModelMap().get(id);
72
46
  this.createDOM = () => {
73
47
  this.dom = document.createElement('span');
74
48
  this.dom.className = 'cross-reference';
@@ -23,7 +23,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
23
  });
24
24
  };
25
25
  import { skipTracking } from '@manuscripts/track-changes-plugin';
26
- import { buildAuxiliaryObjectReference } from '@manuscripts/transform';
27
26
  import { TextSelection } from 'prosemirror-state';
28
27
  import React from 'react';
29
28
  import { CrossReferenceItems } from '../components/views/CrossReferenceItems';
@@ -35,21 +34,17 @@ export class CrossReferenceEditableView extends CrossReferenceView {
35
34
  super(...arguments);
36
35
  this.selectNode = () => {
37
36
  const { getCapabilities, renderReactComponent } = this.props;
37
+ const xref = this.node;
38
+ const rids = xref.attrs.rids;
38
39
  const can = getCapabilities();
39
- const { rid } = this.node.attrs;
40
- const auxiliaryObjectReference = rid
41
- ? this.getAuxiliaryObjectReference(rid)
42
- : null;
43
- if (!(can === null || can === void 0 ? void 0 : can.editArticle) ||
44
- (auxiliaryObjectReference === null || auxiliaryObjectReference === void 0 ? void 0 : auxiliaryObjectReference.referencedObject) ||
45
- (auxiliaryObjectReference === null || auxiliaryObjectReference === void 0 ? void 0 : auxiliaryObjectReference.referencedObjects)) {
40
+ if (!(can === null || can === void 0 ? void 0 : can.editArticle) || rids.length) {
46
41
  return;
47
42
  }
48
43
  if (!this.popperContainer) {
49
44
  this.popperContainer = document.createElement('div');
50
45
  this.popperContainer.className = 'cross-reference-editor';
51
46
  }
52
- renderReactComponent(React.createElement(CrossReferenceItems, { handleSelect: this.handleSelect, targets: this.getTargets(), handleCancel: this.handleCancel, currentTargetId: auxiliaryObjectReference === null || auxiliaryObjectReference === void 0 ? void 0 : auxiliaryObjectReference.referencedObject, currentCustomLabel: this.node.attrs.customLabel }), this.popperContainer);
47
+ renderReactComponent(React.createElement(CrossReferenceItems, { handleSelect: this.handleSelect, targets: this.getTargets(), handleCancel: this.handleCancel, currentTargetId: rids[0], currentCustomLabel: this.node.attrs.customLabel }), this.popperContainer);
53
48
  this.props.popper.show(this.dom, this.popperContainer, 'right');
54
49
  };
55
50
  this.destroy = () => {
@@ -66,7 +61,7 @@ export class CrossReferenceEditableView extends CrossReferenceView {
66
61
  return Array.from(targets.values());
67
62
  };
68
63
  this.handleCancel = () => {
69
- if (!this.node.attrs.rid) {
64
+ if (!this.node.attrs.rids.length) {
70
65
  const { state } = this.view;
71
66
  const pos = this.getPos();
72
67
  const tr = state.tr.delete(pos, pos + this.node.nodeSize);
@@ -81,10 +76,7 @@ export class CrossReferenceEditableView extends CrossReferenceView {
81
76
  this.handleSelect = (rid, customLabel) => __awaiter(this, void 0, void 0, function* () {
82
77
  const { state } = this.view;
83
78
  const pos = this.getPos();
84
- const $pos = state.doc.resolve(pos);
85
- const rids = rid.trim().split(/\s+/);
86
- const auxiliaryObjectReference = buildAuxiliaryObjectReference($pos.parent.attrs.id, rids);
87
- const tr = state.tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { customLabel: customLabel || '', rid: auxiliaryObjectReference._id }));
79
+ const tr = state.tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), { customLabel: customLabel || '', rids: [rid] }));
88
80
  const selection = TextSelection.create(tr.doc, pos);
89
81
  this.view.dispatch(tr.setSelection(selection));
90
82
  this.destroy();
@@ -22,7 +22,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  step((generator = generator.apply(thisArg, _arguments || [])).next());
23
23
  });
24
24
  };
25
- import { nodeNames } from '@manuscripts/transform';
25
+ import { nodeNames, schema } from '@manuscripts/transform';
26
26
  import { ContextMenu } from '../lib/context-menu';
27
27
  const isNotNull = (a) => a !== null;
28
28
  export const EditableBlock = (Base) => {
@@ -68,8 +68,8 @@ export const EditableBlock = (Base) => {
68
68
  this.createAddButton = (after) => {
69
69
  var _a;
70
70
  const $pos = this.view.state.doc.resolve(this.getPos());
71
- if (!((_a = this.props.getCapabilities()) === null || _a === void 0 ? void 0 : _a.editArticle) ||
72
- $pos.parent.type === this.node.type.schema.nodes.keywords_section) {
71
+ const hasAccess = (_a = this.props.getCapabilities()) === null || _a === void 0 ? void 0 : _a.editArticle;
72
+ if (!hasAccess || $pos.parent.type === schema.nodes.keywords) {
73
73
  return null;
74
74
  }
75
75
  const button = document.createElement('a');
@@ -13,9 +13,9 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export default () => {
17
- const dom = document.createElement('section');
18
- dom.setAttribute('data-type', 'meta');
16
+ export default (type) => () => {
17
+ const dom = document.createElement('div');
18
+ dom.setAttribute('data-type', type);
19
19
  dom.setAttribute('contenteditable', 'false');
20
20
  dom.style.display = 'inline';
21
21
  return { dom };
@@ -13,29 +13,15 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { isSectionNode } from '@manuscripts/transform';
17
16
  import { sectionLevel } from '../lib/context-menu';
18
17
  import BlockView from './block_view';
19
18
  import { createNodeView } from './creators';
20
- export const isSpecialSection = (node) => {
21
- if (isSectionNode(node)) {
22
- const { attrs } = node;
23
- return (attrs.category === 'MPSectionCategory:abstracts' ||
24
- attrs.category === 'MPSectionCategory:body' ||
25
- attrs.category === 'MPSectionCategory:backmatter');
26
- }
27
- };
28
19
  export class SectionTitleView extends BlockView {
29
20
  constructor() {
30
21
  super(...arguments);
31
22
  this.elementType = 'h1';
32
23
  this.updateContents = () => {
33
24
  const $pos = this.view.state.doc.resolve(this.getPos());
34
- if (isSpecialSection($pos.parent)) {
35
- this.dom = document.createElement('div');
36
- this.dom.classList.add('no-title');
37
- return;
38
- }
39
25
  if (this.node.childCount) {
40
26
  this.contentDOM.classList.remove('empty-node');
41
27
  }
@@ -32,13 +32,12 @@ export declare const deleteBlock: (typeToDelete: string) => (state: ManuscriptEd
32
32
  export declare const insertBreak: EditorAction;
33
33
  export declare const insertSectionLabel: (state: ManuscriptEditorState, dispatch?: Dispatch, currentTr?: Transaction) => boolean;
34
34
  export declare const insertLink: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
35
- export declare const insertInlineCitation: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: ManuscriptEditorView, embeddedCitationItems?: string[]) => boolean;
35
+ export declare const insertInlineCitation: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: ManuscriptEditorView) => boolean;
36
36
  export declare const insertCrossReference: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
37
37
  export declare const insertInlineEquation: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
38
38
  export declare const insertInlineFootnote: (kind: 'footnote' | 'endnote') => (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
39
39
  export declare const insertGraphicalAbstract: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
40
40
  export declare const insertSection: (subsection?: boolean) => (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
41
- export declare const insertFootnotesSection: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
42
41
  export declare const insertBibliographySection: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
43
42
  export declare const insertTOCSection: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
44
43
  export declare const ifInTableBody: (command: (state: ManuscriptEditorState) => boolean) => (state: ManuscriptEditorState) => boolean;
@@ -1,5 +1,4 @@
1
1
  import { ManuscriptEditorView, ManuscriptNode, Selected } from '@manuscripts/transform';
2
- import { Node as ProsemirrorNode } from 'prosemirror-model';
3
2
  import * as React from 'react';
4
3
  import { ConnectDragPreview, ConnectDragSource, ConnectDropTarget } from 'react-dnd';
5
4
  export type DropSide = 'before' | 'after' | null;
@@ -25,7 +24,7 @@ export interface TreeItem {
25
24
  index: number;
26
25
  isSelected: boolean;
27
26
  items: TreeItem[];
28
- node: ManuscriptNode | ProsemirrorNode;
27
+ node: ManuscriptNode;
29
28
  pos: number;
30
29
  endPos: number;
31
30
  parent?: ManuscriptNode;