@manuscripts/body-editor 2.0.9 → 2.0.11-JSR

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 (36) hide show
  1. package/dist/cjs/configs/editor-plugins.js +3 -1
  2. package/dist/cjs/configs/editor-views.js +2 -0
  3. package/dist/cjs/plugins/objects.js +3 -3
  4. package/dist/cjs/plugins/section_title.js +50 -0
  5. package/dist/cjs/testing/default-editor-data.js +0 -1
  6. package/dist/cjs/versions.js +1 -1
  7. package/dist/cjs/views/bibliography_element.js +1 -1
  8. package/dist/cjs/views/citation_editable.js +8 -4
  9. package/dist/cjs/views/contributors.js +1 -1
  10. package/dist/cjs/views/inline_footnote.js +65 -45
  11. package/dist/cjs/views/section.js +79 -0
  12. package/dist/cjs/views/section_title.js +12 -2
  13. package/dist/es/configs/editor-plugins.js +3 -1
  14. package/dist/es/configs/editor-views.js +2 -0
  15. package/dist/es/plugins/objects.js +3 -3
  16. package/dist/es/plugins/section_title.js +47 -0
  17. package/dist/es/testing/default-editor-data.js +0 -1
  18. package/dist/es/versions.js +1 -1
  19. package/dist/es/views/bibliography_element.js +1 -1
  20. package/dist/es/views/citation_editable.js +8 -4
  21. package/dist/es/views/contributors.js +1 -1
  22. package/dist/es/views/inline_footnote.js +66 -46
  23. package/dist/es/views/section.js +71 -0
  24. package/dist/es/views/section_title.js +12 -2
  25. package/dist/types/components/outline/ManuscriptOutline.d.ts +0 -2
  26. package/dist/types/configs/ManuscriptsEditor.d.ts +1 -2
  27. package/dist/types/configs/editor-views.d.ts +1 -0
  28. package/dist/types/plugins/objects.d.ts +1 -5
  29. package/dist/types/plugins/section_title.d.ts +5 -0
  30. package/dist/types/versions.d.ts +1 -1
  31. package/dist/types/views/inline_footnote.d.ts +3 -1
  32. package/dist/types/views/section.d.ts +28 -0
  33. package/dist/types/views/section_title.d.ts +1 -1
  34. package/package.json +4 -4
  35. package/styles/AdvancedEditor.css +20 -272
  36. package/styles/Editor.css +7 -2
@@ -37,6 +37,7 @@ const objects_1 = __importDefault(require("../plugins/objects"));
37
37
  const paragraphs_1 = __importDefault(require("../plugins/paragraphs"));
38
38
  const persist_1 = __importDefault(require("../plugins/persist"));
39
39
  const placeholder_1 = __importDefault(require("../plugins/placeholder"));
40
+ const section_title_1 = __importDefault(require("../plugins/section_title"));
40
41
  const sections_1 = __importDefault(require("../plugins/sections"));
41
42
  const selected_suggestion_1 = __importDefault(require("../plugins/selected-suggestion"));
42
43
  const table_footnote_1 = __importDefault(require("../plugins/table-footnote"));
@@ -56,13 +57,14 @@ exports.default = (props) => {
56
57
  ? track_changes_plugin_1.TrackChangesStatus.disabled
57
58
  : track_changes_plugin_1.TrackChangesStatus.enabled,
58
59
  }),
60
+ (0, section_title_1.default)(),
59
61
  (0, tables_cursor_fix_1.default)(),
60
62
  (0, elements_1.default)(),
61
63
  (0, persist_1.default)(),
62
64
  (0, sections_1.default)(),
63
65
  (0, toc_1.default)(),
64
66
  (0, bibliography_1.default)(props),
65
- (0, objects_1.default)(props),
67
+ (0, objects_1.default)(),
66
68
  (0, affiliations_1.default)(),
67
69
  (0, comments_1.default)(),
68
70
  (0, paragraphs_1.default)(),
@@ -44,6 +44,7 @@ const paragraph_editable_1 = __importDefault(require("../views/paragraph_editabl
44
44
  const placeholder_1 = __importDefault(require("../views/placeholder"));
45
45
  const placeholder_element_editable_1 = __importDefault(require("../views/placeholder_element_editable"));
46
46
  const pullquote_element_editable_1 = __importDefault(require("../views/pullquote_element_editable"));
47
+ const section_1 = __importDefault(require("../views/section"));
47
48
  const section_label_1 = __importDefault(require("../views/section_label"));
48
49
  const section_title_editable_1 = __importDefault(require("../views/section_title_editable"));
49
50
  const table_cell_1 = __importDefault(require("../views/table_cell"));
@@ -76,6 +77,7 @@ exports.default = (props, dispatch) => {
76
77
  paragraph: (0, paragraph_editable_1.default)(props),
77
78
  placeholder: (0, placeholder_1.default)(props),
78
79
  placeholder_element: (0, placeholder_element_editable_1.default)(props),
80
+ section: (0, section_1.default)(props),
79
81
  pullquote_element: (0, pullquote_element_editable_1.default)(props),
80
82
  section_title: (0, section_title_editable_1.default)(props),
81
83
  section_label: (0, section_label_1.default)(props),
@@ -21,15 +21,15 @@ const prosemirror_model_1 = require("prosemirror-model");
21
21
  const prosemirror_state_1 = require("prosemirror-state");
22
22
  const prosemirror_view_1 = require("prosemirror-view");
23
23
  exports.objectsKey = new prosemirror_state_1.PluginKey('objects');
24
- exports.default = (props) => {
24
+ exports.default = () => {
25
25
  return new prosemirror_state_1.Plugin({
26
26
  key: exports.objectsKey,
27
27
  state: {
28
28
  init: (config, state) => {
29
- return (0, transform_1.buildTargets)(prosemirror_model_1.Fragment.from(state.doc.content), props.getManuscript());
29
+ return (0, transform_1.buildTargets)(prosemirror_model_1.Fragment.from(state.doc.content));
30
30
  },
31
31
  apply: (tr) => {
32
- return (0, transform_1.buildTargets)(prosemirror_model_1.Fragment.from(tr.doc.content), props.getManuscript());
32
+ return (0, transform_1.buildTargets)(prosemirror_model_1.Fragment.from(tr.doc.content));
33
33
  },
34
34
  },
35
35
  props: {
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sectionTitleKey = void 0;
4
+ const transform_1 = require("@manuscripts/transform");
5
+ const prosemirror_state_1 = require("prosemirror-state");
6
+ const prosemirror_utils_1 = require("prosemirror-utils");
7
+ const track_changes_utils_1 = require("../lib/track-changes-utils");
8
+ exports.sectionTitleKey = new prosemirror_state_1.PluginKey('sectionNumbering');
9
+ const calculateSectionLevels = (node, startPos, sectionNumberMap, numbering = [0]) => {
10
+ node.forEach((childNode, offset) => {
11
+ if (childNode.type === transform_1.schema.nodes.section &&
12
+ !(0, track_changes_utils_1.isRejectedInsert)(childNode)) {
13
+ numbering[numbering.length - 1] += 1;
14
+ const sectionNumber = numbering.join('.');
15
+ const sectionStartPos = startPos + offset + 1;
16
+ childNode.forEach((innerChildNode) => {
17
+ if (innerChildNode.type === transform_1.schema.nodes.section_title) {
18
+ sectionNumberMap.set(childNode.attrs.id, sectionNumber);
19
+ }
20
+ });
21
+ calculateSectionLevels(childNode, sectionStartPos, sectionNumberMap, [
22
+ ...numbering,
23
+ 0,
24
+ ]);
25
+ }
26
+ });
27
+ };
28
+ const getPluginState = (doc) => {
29
+ const bodyNodes = (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.body);
30
+ const bodyNode = bodyNodes[0];
31
+ const sectionNumberMap = new Map();
32
+ calculateSectionLevels(bodyNode.node, bodyNode.pos, sectionNumberMap);
33
+ return sectionNumberMap;
34
+ };
35
+ exports.default = () => {
36
+ return new prosemirror_state_1.Plugin({
37
+ key: exports.sectionTitleKey,
38
+ state: {
39
+ init: (_, state) => {
40
+ return getPluginState(state.doc);
41
+ },
42
+ apply: (tr, oldSectionNumberMap, oldState, newState) => {
43
+ if (tr.docChanged) {
44
+ return getPluginState(newState.doc);
45
+ }
46
+ return oldSectionNumberMap;
47
+ },
48
+ },
49
+ });
50
+ };
@@ -75,7 +75,6 @@ exports.defaultEditorProps = {
75
75
  download: () => { },
76
76
  },
77
77
  getCapabilities: () => (0, style_guide_1.getAllPermitted)(),
78
- getManuscript: () => exports.TEST_DATA.MANUSCRIPT,
79
78
  cslProps: {
80
79
  style: '',
81
80
  locale: '',
@@ -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.9';
4
+ exports.VERSION = '2.0.11-JSR';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -73,7 +73,7 @@ class BibliographyElementBlockView extends block_view_1.default {
73
73
  componentProps.actions.push({
74
74
  label: 'Edit',
75
75
  action: () => this.handleEdit(element.id),
76
- icon: 'EditIcon',
76
+ icon: 'Edit',
77
77
  });
78
78
  }
79
79
  componentProps.actions.push({
@@ -77,11 +77,15 @@ class CitationEditableView extends citation_1.CitationView {
77
77
  };
78
78
  this.showContextMenu = () => {
79
79
  this.props.popper.destroy();
80
+ const can = this.props.getCapabilities();
81
+ const actions = [
82
+ { label: 'Comment', action: this.handleComment, icon: 'AddComment' },
83
+ ];
84
+ if (can.editArticle) {
85
+ actions.unshift({ label: 'Edit', action: this.handleEdit, icon: 'Edit' });
86
+ }
80
87
  const componentProps = {
81
- actions: [
82
- { label: 'Edit', action: this.handleEdit, icon: 'EditIcon' },
83
- { label: 'Comment', action: this.handleComment, icon: 'AddComment' },
84
- ],
88
+ actions,
85
89
  };
86
90
  this.contextMenu = (0, ReactSubView_1.default)(this.props, style_guide_1.ContextMenu, componentProps, this.node, this.getPos, this.view, 'context-menu');
87
91
  this.props.popper.show(this.dom, this.contextMenu, 'right-start', false);
@@ -205,7 +205,7 @@ class ContributorsView extends block_view_1.default {
205
205
  {
206
206
  label: 'Edit',
207
207
  action: () => this.handleEdit(element.id),
208
- icon: 'EditIcon',
208
+ icon: 'Edit',
209
209
  },
210
210
  ],
211
211
  };
@@ -34,8 +34,23 @@ class InlineFootnoteView extends base_node_view_1.BaseNodeView {
34
34
  constructor() {
35
35
  super(...arguments);
36
36
  this.findParentTableElement = () => (0, prosemirror_utils_1.findParentNodeClosestToPos)(this.view.state.doc.resolve(this.getPos()), (node) => node.type === transform_1.schema.nodes.table_element);
37
+ this.showContextMenu = () => {
38
+ this.props.popper.destroy();
39
+ const componentProps = {
40
+ actions: [
41
+ {
42
+ label: 'Edit',
43
+ action: () => {
44
+ this.props.popper.destroy();
45
+ this.activateGenericFnModal();
46
+ },
47
+ icon: 'Edit',
48
+ },
49
+ ],
50
+ };
51
+ this.props.popper.show(this.dom, (0, ReactSubView_1.default)(this.props, style_guide_1.ContextMenu, componentProps, this.node, this.getPos, this.view, 'context-menu'), 'right-start', false);
52
+ };
37
53
  this.handleClick = () => {
38
- var _a;
39
54
  if ((0, track_changes_utils_1.isDeleted)(this.node)) {
40
55
  return;
41
56
  }
@@ -46,21 +61,59 @@ class InlineFootnoteView extends base_node_view_1.BaseNodeView {
46
61
  onAdd: this.onAdd,
47
62
  });
48
63
  }
49
- else if (!this.activateGenericFnModal()) {
50
- if ((_a = this.node.attrs.rids) === null || _a === void 0 ? void 0 : _a.length) {
51
- let nodePos = undefined;
52
- this.view.state.doc.descendants((node, pos) => {
53
- if (node.attrs.id === this.node.attrs.rids[0]) {
54
- nodePos = pos;
55
- }
56
- });
57
- if (nodePos && this.props.dispatch) {
58
- const sel = prosemirror_state_1.TextSelection.near(this.view.state.doc.resolve(nodePos + 1));
59
- this.props.dispatch(this.view.state.tr.setSelection(sel).scrollIntoView());
64
+ else {
65
+ this.showContextMenu();
66
+ }
67
+ };
68
+ this.scrollToReferenced = () => {
69
+ var _a;
70
+ if ((_a = this.node.attrs.rids) === null || _a === void 0 ? void 0 : _a.length) {
71
+ let nodePos = undefined;
72
+ this.view.state.doc.descendants((node, pos) => {
73
+ if (node.attrs.id === this.node.attrs.rids[0]) {
74
+ nodePos = pos;
60
75
  }
76
+ });
77
+ if (nodePos && this.props.dispatch) {
78
+ const sel = prosemirror_state_1.TextSelection.near(this.view.state.doc.resolve(nodePos + 1));
79
+ this.props.dispatch(this.view.state.tr.setSelection(sel).scrollIntoView());
61
80
  }
62
81
  }
63
82
  };
83
+ this.activateGenericFnModal = () => {
84
+ if (!this.props.getCapabilities().editArticle) {
85
+ return;
86
+ }
87
+ const fnState = footnotes_1.footnotesKey.getState(this.view.state);
88
+ console.log(fnState);
89
+ if (fnState) {
90
+ this.activateModal({
91
+ notes: Array.from(fnState.unusedFootnotes.values()).map((n) => ({
92
+ node: n[0],
93
+ })),
94
+ onCancel: () => {
95
+ const { tr } = this.view.state;
96
+ if (!this.node.attrs.rids.length) {
97
+ this.view.dispatch(tr.delete(this.getPos(), this.getPos() + this.node.nodeSize));
98
+ }
99
+ this.destroy();
100
+ },
101
+ onAdd: () => {
102
+ const footnote = (0, commands_1.createFootnote)(this.view.state, 'footnote');
103
+ const tr = (0, commands_1.insertFootnote)(this.view.state, this.view.state.tr, footnote);
104
+ tr.setNodeAttribute(tr.mapping.map(this.getPos()), 'rids', [
105
+ footnote.attrs.id,
106
+ ]);
107
+ this.view.dispatch(tr);
108
+ this.view.focus();
109
+ this.destroy();
110
+ },
111
+ addNewLabel: 'Replace with new footnote',
112
+ });
113
+ return true;
114
+ }
115
+ return false;
116
+ };
64
117
  this.updateContents = () => {
65
118
  const attrs = this.node.attrs;
66
119
  this.dom.setAttribute('rids', attrs.rids.join(','));
@@ -154,39 +207,6 @@ class InlineFootnoteView extends base_node_view_1.BaseNodeView {
154
207
  this.popperContainer = (0, ReactSubView_1.default)(Object.assign(Object.assign({}, this.props), { dispatch: this.view.dispatch }), style_guide_1.FootnotesSelector, Object.assign(Object.assign({}, defaultModal), modalProps), this.node, this.getPos, this.view, 'footnote-editor');
155
208
  this.props.popper.show(this.dom, this.popperContainer, 'auto', false);
156
209
  }
157
- activateGenericFnModal() {
158
- if (!this.props.getCapabilities().editArticle) {
159
- return;
160
- }
161
- const fnState = footnotes_1.footnotesKey.getState(this.view.state);
162
- if (fnState && fnState.unusedFootnotes.size > 0) {
163
- this.activateModal({
164
- notes: Array.from(fnState.unusedFootnotes.values()).map((n) => ({
165
- node: n[0],
166
- })),
167
- onCancel: () => {
168
- const { tr } = this.view.state;
169
- if (!this.node.attrs.rids.length) {
170
- this.view.dispatch(tr.delete(this.getPos(), this.getPos() + this.node.nodeSize));
171
- }
172
- this.destroy();
173
- },
174
- onAdd: () => {
175
- const footnote = (0, commands_1.createFootnote)(this.view.state, 'footnote');
176
- const tr = (0, commands_1.insertFootnote)(this.view.state, this.view.state.tr, footnote);
177
- tr.setNodeAttribute(tr.mapping.map(this.getPos()), 'rids', [
178
- footnote.attrs.id,
179
- ]);
180
- this.view.dispatch(tr);
181
- this.view.focus();
182
- this.destroy();
183
- },
184
- addNewLabel: 'Replace with new footnote',
185
- });
186
- return true;
187
- }
188
- return false;
189
- }
190
210
  }
191
211
  exports.InlineFootnoteView = InlineFootnoteView;
192
212
  exports.default = (0, creators_1.createNodeView)(InlineFootnoteView);
@@ -0,0 +1,79 @@
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.SectionView = exports.handleSectionNumbering = void 0;
22
+ const transform_1 = require("@manuscripts/transform");
23
+ const section_title_1 = require("../plugins/section_title");
24
+ const block_view_1 = __importDefault(require("./block_view"));
25
+ const creators_1 = require("./creators");
26
+ const handleSectionNumbering = (sections) => {
27
+ sections.forEach((sectionNumber, sectionId) => {
28
+ const section = document.getElementById(sectionId);
29
+ const sectionTitle = section === null || section === void 0 ? void 0 : section.querySelector('h1');
30
+ if (sectionTitle) {
31
+ sectionTitle.dataset.sectionNumber = sectionNumber;
32
+ }
33
+ });
34
+ };
35
+ exports.handleSectionNumbering = handleSectionNumbering;
36
+ class SectionView extends block_view_1.default {
37
+ constructor() {
38
+ super(...arguments);
39
+ this.elementType = 'section';
40
+ this.initialise = () => {
41
+ this.createDOM();
42
+ this.createElement();
43
+ this.updateContents();
44
+ };
45
+ this.createElement = () => {
46
+ this.contentDOM = document.createElement(this.elementType);
47
+ this.dom.appendChild(this.contentDOM);
48
+ };
49
+ this.onUpdateContent = () => {
50
+ const sectionTitleState = section_title_1.sectionTitleKey.getState(this.view.state);
51
+ const { titleSuppressed, generatedLabel, pageBreakStyle, id, category } = this.node.attrs;
52
+ const classNames = [];
53
+ if (titleSuppressed) {
54
+ classNames.push('title-suppressed');
55
+ }
56
+ if (typeof generatedLabel === 'undefined' || generatedLabel) {
57
+ classNames.push('generated-label');
58
+ }
59
+ if (pageBreakStyle === transform_1.PAGE_BREAK_BEFORE ||
60
+ pageBreakStyle === transform_1.PAGE_BREAK_BEFORE_AND_AFTER) {
61
+ classNames.push('page-break-before');
62
+ }
63
+ if (pageBreakStyle === transform_1.PAGE_BREAK_AFTER ||
64
+ pageBreakStyle === transform_1.PAGE_BREAK_BEFORE_AND_AFTER) {
65
+ classNames.push('page-break-after');
66
+ }
67
+ if (this.contentDOM) {
68
+ this.contentDOM.id = id;
69
+ this.contentDOM.classList.add(...classNames);
70
+ category && this.contentDOM.setAttribute('data-category', category);
71
+ }
72
+ if (sectionTitleState) {
73
+ (0, exports.handleSectionNumbering)(sectionTitleState);
74
+ }
75
+ };
76
+ }
77
+ }
78
+ exports.SectionView = SectionView;
79
+ exports.default = (0, creators_1.createNodeView)(SectionView);
@@ -19,23 +19,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.SectionTitleView = void 0;
22
+ const transform_1 = require("@manuscripts/transform");
23
+ const prosemirror_utils_1 = require("prosemirror-utils");
22
24
  const context_menu_1 = require("../lib/context-menu");
25
+ const section_title_1 = require("../plugins/section_title");
23
26
  const block_view_1 = __importDefault(require("./block_view"));
24
27
  const creators_1 = require("./creators");
25
28
  class SectionTitleView extends block_view_1.default {
26
29
  constructor() {
27
30
  super(...arguments);
28
31
  this.elementType = 'h1';
29
- this.updateContents = () => {
32
+ this.onUpdateContent = () => {
30
33
  const $pos = this.view.state.doc.resolve(this.getPos());
34
+ const sectionTitleState = section_title_1.sectionTitleKey.getState(this.view.state);
35
+ const parentSection = (0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)($pos, transform_1.schema.nodes.section);
36
+ const sectionNumber = sectionTitleState === null || sectionTitleState === void 0 ? void 0 : sectionTitleState.get(parentSection === null || parentSection === void 0 ? void 0 : parentSection.node.attrs.id);
37
+ const level = $pos.depth > 1 ? $pos.depth - 1 : $pos.depth;
31
38
  if (this.node.childCount) {
32
39
  this.contentDOM.classList.remove('empty-node');
33
40
  }
34
41
  else {
35
42
  this.contentDOM.classList.add('empty-node');
36
- const level = $pos.depth > 1 ? $pos.depth - 1 : $pos.depth;
37
43
  this.contentDOM.setAttribute('data-placeholder', `${(0, context_menu_1.sectionLevel)(level)} heading`);
38
44
  }
45
+ if (sectionTitleState) {
46
+ this.contentDOM.dataset.sectionNumber = sectionNumber;
47
+ this.contentDOM.dataset.titleLevel = level.toString();
48
+ }
39
49
  };
40
50
  }
41
51
  }
@@ -32,6 +32,7 @@ import objects from '../plugins/objects';
32
32
  import paragraphs from '../plugins/paragraphs';
33
33
  import persist from '../plugins/persist';
34
34
  import placeholder from '../plugins/placeholder';
35
+ import section_title from '../plugins/section_title';
35
36
  import sections from '../plugins/sections';
36
37
  import selected_suggestion from '../plugins/selected-suggestion';
37
38
  import table_footnote from '../plugins/table-footnote';
@@ -51,13 +52,14 @@ export default (props) => {
51
52
  ? TrackChangesStatus.disabled
52
53
  : TrackChangesStatus.enabled,
53
54
  }),
55
+ section_title(),
54
56
  table_editing_fix(),
55
57
  elements(),
56
58
  persist(),
57
59
  sections(),
58
60
  toc(),
59
61
  bibliography(props),
60
- objects(props),
62
+ objects(),
61
63
  affiliations(),
62
64
  comments(),
63
65
  paragraphs(),
@@ -39,6 +39,7 @@ import paragraph from '../views/paragraph_editable';
39
39
  import placeholder from '../views/placeholder';
40
40
  import placeholderElement from '../views/placeholder_element_editable';
41
41
  import pullquoteElement from '../views/pullquote_element_editable';
42
+ import section from '../views/section';
42
43
  import sectionLabel from '../views/section_label';
43
44
  import sectionTitle from '../views/section_title_editable';
44
45
  import tableCell from '../views/table_cell';
@@ -71,6 +72,7 @@ export default (props, dispatch) => {
71
72
  paragraph: paragraph(props),
72
73
  placeholder: placeholder(props),
73
74
  placeholder_element: placeholderElement(props),
75
+ section: section(props),
74
76
  pullquote_element: pullquoteElement(props),
75
77
  section_title: sectionTitle(props),
76
78
  section_label: sectionLabel(props),
@@ -18,15 +18,15 @@ import { Fragment } from 'prosemirror-model';
18
18
  import { Plugin, PluginKey } from 'prosemirror-state';
19
19
  import { Decoration, DecorationSet } from 'prosemirror-view';
20
20
  export const objectsKey = new PluginKey('objects');
21
- export default (props) => {
21
+ export default () => {
22
22
  return new Plugin({
23
23
  key: objectsKey,
24
24
  state: {
25
25
  init: (config, state) => {
26
- return buildTargets(Fragment.from(state.doc.content), props.getManuscript());
26
+ return buildTargets(Fragment.from(state.doc.content));
27
27
  },
28
28
  apply: (tr) => {
29
- return buildTargets(Fragment.from(tr.doc.content), props.getManuscript());
29
+ return buildTargets(Fragment.from(tr.doc.content));
30
30
  },
31
31
  },
32
32
  props: {
@@ -0,0 +1,47 @@
1
+ import { schema } from '@manuscripts/transform';
2
+ import { Plugin, PluginKey } from 'prosemirror-state';
3
+ import { findChildrenByType } from 'prosemirror-utils';
4
+ import { isRejectedInsert } from '../lib/track-changes-utils';
5
+ export const sectionTitleKey = new PluginKey('sectionNumbering');
6
+ const calculateSectionLevels = (node, startPos, sectionNumberMap, numbering = [0]) => {
7
+ node.forEach((childNode, offset) => {
8
+ if (childNode.type === schema.nodes.section &&
9
+ !isRejectedInsert(childNode)) {
10
+ numbering[numbering.length - 1] += 1;
11
+ const sectionNumber = numbering.join('.');
12
+ const sectionStartPos = startPos + offset + 1;
13
+ childNode.forEach((innerChildNode) => {
14
+ if (innerChildNode.type === schema.nodes.section_title) {
15
+ sectionNumberMap.set(childNode.attrs.id, sectionNumber);
16
+ }
17
+ });
18
+ calculateSectionLevels(childNode, sectionStartPos, sectionNumberMap, [
19
+ ...numbering,
20
+ 0,
21
+ ]);
22
+ }
23
+ });
24
+ };
25
+ const getPluginState = (doc) => {
26
+ const bodyNodes = findChildrenByType(doc, schema.nodes.body);
27
+ const bodyNode = bodyNodes[0];
28
+ const sectionNumberMap = new Map();
29
+ calculateSectionLevels(bodyNode.node, bodyNode.pos, sectionNumberMap);
30
+ return sectionNumberMap;
31
+ };
32
+ export default () => {
33
+ return new Plugin({
34
+ key: sectionTitleKey,
35
+ state: {
36
+ init: (_, state) => {
37
+ return getPluginState(state.doc);
38
+ },
39
+ apply: (tr, oldSectionNumberMap, oldState, newState) => {
40
+ if (tr.docChanged) {
41
+ return getPluginState(newState.doc);
42
+ }
43
+ return oldSectionNumberMap;
44
+ },
45
+ },
46
+ });
47
+ };
@@ -69,7 +69,6 @@ export const defaultEditorProps = {
69
69
  download: () => { },
70
70
  },
71
71
  getCapabilities: () => getAllPermitted(),
72
- getManuscript: () => TEST_DATA.MANUSCRIPT,
73
72
  cslProps: {
74
73
  style: '',
75
74
  locale: '',
@@ -1,2 +1,2 @@
1
- export const VERSION = '2.0.9';
1
+ export const VERSION = '2.0.11-JSR';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -67,7 +67,7 @@ export class BibliographyElementBlockView extends BlockView {
67
67
  componentProps.actions.push({
68
68
  label: 'Edit',
69
69
  action: () => this.handleEdit(element.id),
70
- icon: 'EditIcon',
70
+ icon: 'Edit',
71
71
  });
72
72
  }
73
73
  componentProps.actions.push({
@@ -71,11 +71,15 @@ export class CitationEditableView extends CitationView {
71
71
  };
72
72
  this.showContextMenu = () => {
73
73
  this.props.popper.destroy();
74
+ const can = this.props.getCapabilities();
75
+ const actions = [
76
+ { label: 'Comment', action: this.handleComment, icon: 'AddComment' },
77
+ ];
78
+ if (can.editArticle) {
79
+ actions.unshift({ label: 'Edit', action: this.handleEdit, icon: 'Edit' });
80
+ }
74
81
  const componentProps = {
75
- actions: [
76
- { label: 'Edit', action: this.handleEdit, icon: 'EditIcon' },
77
- { label: 'Comment', action: this.handleComment, icon: 'AddComment' },
78
- ],
82
+ actions,
79
83
  };
80
84
  this.contextMenu = ReactSubView(this.props, ContextMenu, componentProps, this.node, this.getPos, this.view, 'context-menu');
81
85
  this.props.popper.show(this.dom, this.contextMenu, 'right-start', false);
@@ -199,7 +199,7 @@ export class ContributorsView extends BlockView {
199
199
  {
200
200
  label: 'Edit',
201
201
  action: () => this.handleEdit(element.id),
202
- icon: 'EditIcon',
202
+ icon: 'Edit',
203
203
  },
204
204
  ],
205
205
  };