@manuscripts/body-editor 3.6.0 → 3.6.2
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.
- package/dist/cjs/commands.js +4 -12
- package/dist/cjs/lib/doc.js +4 -18
- package/dist/cjs/lib/utils.js +11 -1
- package/dist/cjs/plugins/add-subtitle.js +4 -2
- package/dist/cjs/plugins/alt-titles.js +3 -4
- package/dist/cjs/versions.js +1 -1
- package/dist/cjs/views/contributors.js +6 -11
- package/dist/es/commands.js +5 -13
- package/dist/es/lib/doc.js +4 -18
- package/dist/es/lib/utils.js +9 -0
- package/dist/es/plugins/add-subtitle.js +4 -2
- package/dist/es/plugins/alt-titles.js +4 -5
- package/dist/es/versions.js +1 -1
- package/dist/es/views/contributors.js +6 -11
- package/dist/types/lib/utils.d.ts +1 -0
- package/dist/types/versions.d.ts +1 -1
- package/package.json +2 -2
package/dist/cjs/commands.js
CHANGED
|
@@ -725,8 +725,7 @@ const insertContributors = (state, dispatch, view) => {
|
|
|
725
725
|
if ((0, utils_1.getChildOfType)(state.doc, transform_1.schema.nodes.contributors, true)) {
|
|
726
726
|
return false;
|
|
727
727
|
}
|
|
728
|
-
const
|
|
729
|
-
const pos = title.pos + title.node.nodeSize;
|
|
728
|
+
const pos = (0, utils_1.findInsertionPosition)(transform_1.schema.nodes.contributors, state.doc);
|
|
730
729
|
const contributors = state.schema.nodes.contributors.create({
|
|
731
730
|
id: '',
|
|
732
731
|
});
|
|
@@ -745,12 +744,7 @@ const insertAffiliation = (state, dispatch, view) => {
|
|
|
745
744
|
if ((0, utils_1.getChildOfType)(state.doc, transform_1.schema.nodes.affiliations, true)) {
|
|
746
745
|
return false;
|
|
747
746
|
}
|
|
748
|
-
const
|
|
749
|
-
let pos = title.pos + title.node.nodeSize;
|
|
750
|
-
const contributors = (0, prosemirror_utils_1.findChildrenByType)(state.doc, state.schema.nodes.contributors)[0];
|
|
751
|
-
if (contributors) {
|
|
752
|
-
pos = contributors.pos + contributors.node.nodeSize;
|
|
753
|
-
}
|
|
747
|
+
const pos = (0, utils_1.findInsertionPosition)(transform_1.schema.nodes.affiliations, state.doc);
|
|
754
748
|
const affiliations = state.schema.nodes.affiliations.create({
|
|
755
749
|
id: '',
|
|
756
750
|
});
|
|
@@ -783,8 +777,7 @@ const insertKeywords = (state, dispatch, view) => {
|
|
|
783
777
|
if ((0, utils_1.getChildOfType)(state.doc, transform_1.schema.nodes.keywords, true)) {
|
|
784
778
|
return false;
|
|
785
779
|
}
|
|
786
|
-
const
|
|
787
|
-
const pos = abstracts.pos;
|
|
780
|
+
const pos = (0, utils_1.findInsertionPosition)(transform_1.schema.nodes.keywords, state.doc);
|
|
788
781
|
const keywords = transform_1.schema.nodes.keywords.createAndFill({}, [
|
|
789
782
|
transform_1.schema.nodes.section_title.create({}, transform_1.schema.text('Keywords')),
|
|
790
783
|
transform_1.schema.nodes.keywords_element.create({}, [
|
|
@@ -1300,8 +1293,7 @@ const createHeroImage = (attrs) => transform_1.schema.nodes.hero_image.create({
|
|
|
1300
1293
|
transform_1.schema.nodes.long_desc.create(),
|
|
1301
1294
|
]);
|
|
1302
1295
|
const insertHeroImage = () => (state, dispatch, view) => {
|
|
1303
|
-
const
|
|
1304
|
-
const position = comments.pos;
|
|
1296
|
+
const position = (0, utils_1.findInsertionPosition)(transform_1.schema.nodes.hero_image, state.doc);
|
|
1305
1297
|
view?.focus();
|
|
1306
1298
|
(0, exports.createBlock)(transform_1.schema.nodes.hero_image, position, state, dispatch);
|
|
1307
1299
|
return true;
|
package/dist/cjs/lib/doc.js
CHANGED
|
@@ -3,26 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.findNodeByID = exports.findGraphicalAbstractFigureElement = exports.findFootnotesSection = exports.findBibliographySection = exports.findBackmatter = exports.findBody = exports.findAbstractsNode = exports.insertFootnotesSection = exports.insertAttachmentsNode = exports.insertSupplementsNode = exports.insertAwardsNode = void 0;
|
|
4
4
|
const transform_1 = require("@manuscripts/transform");
|
|
5
5
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
6
7
|
const insertAwardsNode = (tr) => {
|
|
7
8
|
const doc = tr.doc;
|
|
8
9
|
const awards = (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.awards)[0];
|
|
9
10
|
if (awards) {
|
|
10
11
|
return awards;
|
|
11
12
|
}
|
|
12
|
-
const
|
|
13
|
-
const possibleNodesTypes = [
|
|
14
|
-
'doi',
|
|
15
|
-
'keywords',
|
|
16
|
-
'supplements',
|
|
17
|
-
'abstracts',
|
|
18
|
-
'body',
|
|
19
|
-
];
|
|
20
|
-
doc.descendants((node, pos) => {
|
|
21
|
-
if (possibleNodesTypes.includes(node.type.name)) {
|
|
22
|
-
positions.push(pos);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
const pos = positions.length === 0 ? 0 : Math.min(...positions);
|
|
13
|
+
const pos = (0, utils_1.findInsertionPosition)(transform_1.schema.nodes.awards, doc);
|
|
26
14
|
const node = transform_1.schema.nodes.awards.createAndFill();
|
|
27
15
|
tr.insert(pos, node);
|
|
28
16
|
return {
|
|
@@ -37,8 +25,7 @@ const insertSupplementsNode = (tr) => {
|
|
|
37
25
|
if (supplements) {
|
|
38
26
|
return supplements;
|
|
39
27
|
}
|
|
40
|
-
const
|
|
41
|
-
const pos = backmatter.pos + backmatter.node.content.size + 1;
|
|
28
|
+
const pos = (0, utils_1.findInsertionPosition)(transform_1.schema.nodes.supplements, doc);
|
|
42
29
|
const node = transform_1.schema.nodes.supplements.createAndFill();
|
|
43
30
|
tr.insert(pos, node);
|
|
44
31
|
return {
|
|
@@ -55,8 +42,7 @@ const insertAttachmentsNode = (tr) => {
|
|
|
55
42
|
pos: attachmentsNodes[0].pos,
|
|
56
43
|
};
|
|
57
44
|
}
|
|
58
|
-
const
|
|
59
|
-
const pos = comments.pos + comments.node.content.size;
|
|
45
|
+
const pos = (0, utils_1.findInsertionPosition)(transform_1.schema.nodes.attachments, tr.doc);
|
|
60
46
|
const node = transform_1.schema.nodes.attachments.create({
|
|
61
47
|
id: (0, transform_1.generateNodeID)(transform_1.schema.nodes.attachments),
|
|
62
48
|
});
|
package/dist/cjs/lib/utils.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.getLastTitleNode = exports.filterBlockNodes = exports.getInsertPos = exports.createToggleButton = exports.isEditAllowed = exports.isBodyLocked = exports.cleanItemValues = exports.shouldRenderField = exports.hasParent = exports.isNotNull = exports.createHeader = exports.isSelectionInBody = exports.isSelectionInNode = exports.isChildOfNodeTypes = exports.findParentElement = exports.findParentSection = exports.findParentNodeWithIdValue = exports.findParentNodeWithId = exports.getChildOfType = exports.getMatchingDescendant = exports.getMatchingChild = void 0;
|
|
18
|
+
exports.getLastTitleNode = exports.filterBlockNodes = exports.findInsertionPosition = exports.getInsertPos = exports.createToggleButton = exports.isEditAllowed = exports.isBodyLocked = exports.cleanItemValues = exports.shouldRenderField = exports.hasParent = exports.isNotNull = exports.createHeader = exports.isSelectionInBody = exports.isSelectionInNode = exports.isChildOfNodeTypes = exports.findParentElement = exports.findParentSection = exports.findParentNodeWithIdValue = exports.findParentNodeWithId = exports.getChildOfType = exports.getMatchingDescendant = exports.getMatchingChild = void 0;
|
|
19
19
|
exports.iterateChildren = iterateChildren;
|
|
20
20
|
const transform_1 = require("@manuscripts/transform");
|
|
21
21
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
@@ -174,6 +174,16 @@ const getInsertPos = (type, parent, pos) => {
|
|
|
174
174
|
return insertPos;
|
|
175
175
|
};
|
|
176
176
|
exports.getInsertPos = getInsertPos;
|
|
177
|
+
const findInsertionPosition = (type, doc) => {
|
|
178
|
+
let insertPos = 0;
|
|
179
|
+
doc.forEach((child, offset, index) => {
|
|
180
|
+
if (doc.canReplaceWith(index, index, type)) {
|
|
181
|
+
insertPos = offset;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
return insertPos;
|
|
185
|
+
};
|
|
186
|
+
exports.findInsertionPosition = findInsertionPosition;
|
|
177
187
|
const filterBlockNodes = (fragment, predicate) => {
|
|
178
188
|
const updatedNodes = [];
|
|
179
189
|
fragment.forEach((child) => {
|
|
@@ -20,6 +20,7 @@ const prosemirror_state_1 = require("prosemirror-state");
|
|
|
20
20
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
21
21
|
const uuid_1 = require("uuid");
|
|
22
22
|
const icons_1 = require("../icons");
|
|
23
|
+
const utils_1 = require("../lib/utils");
|
|
23
24
|
const createAddSubtitleButton = (handler) => {
|
|
24
25
|
const button = document.createElement('span');
|
|
25
26
|
button.className = 'add-subtitle';
|
|
@@ -54,8 +55,9 @@ exports.default = () => new prosemirror_state_1.Plugin({
|
|
|
54
55
|
prosemirror_view_1.Decoration.widget(titleEndPos, (view) => {
|
|
55
56
|
return createAddSubtitleButton(() => {
|
|
56
57
|
const subtitlesNode = transform_1.schema.nodes.subtitles.create({ id: (0, uuid_1.v4)() }, [transform_1.schema.nodes.subtitle.create({ id: (0, uuid_1.v4)() })]);
|
|
57
|
-
const
|
|
58
|
-
const
|
|
58
|
+
const pos = (0, utils_1.findInsertionPosition)(transform_1.schema.nodes.subtitles, state.doc);
|
|
59
|
+
const tr = view.state.tr.insert(pos, subtitlesNode);
|
|
60
|
+
const subtitlePos = pos + 1;
|
|
59
61
|
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, subtitlePos));
|
|
60
62
|
view.dispatch(tr);
|
|
61
63
|
view.focus();
|
|
@@ -79,21 +79,20 @@ exports.default = () => {
|
|
|
79
79
|
!exports.altTitlesKey.getState(newState)) {
|
|
80
80
|
return null;
|
|
81
81
|
}
|
|
82
|
-
const { title,
|
|
82
|
+
const { title, runningTitle, shortTitle, altTitlesSection } = exports.altTitlesKey.getState(newState);
|
|
83
83
|
const schema = newState.schema;
|
|
84
84
|
if (!title) {
|
|
85
85
|
return null;
|
|
86
86
|
}
|
|
87
87
|
if (!altTitlesSection) {
|
|
88
|
-
const
|
|
89
|
-
const titleEnd = prev[0].nodeSize + prev[1];
|
|
88
|
+
const pos = (0, utils_1.findInsertionPosition)(schema.nodes.alt_titles, tr.doc);
|
|
90
89
|
const section = schema.nodes.alt_titles.create({}, [
|
|
91
90
|
schema.nodes.alt_title.create({
|
|
92
91
|
type: 'running',
|
|
93
92
|
}),
|
|
94
93
|
schema.nodes.alt_title.create({ type: 'short' }),
|
|
95
94
|
]);
|
|
96
|
-
tr.insert(
|
|
95
|
+
tr.insert(pos, section);
|
|
97
96
|
}
|
|
98
97
|
else {
|
|
99
98
|
const endPos = altTitlesSection[1] + altTitlesSection[0].nodeSize - 1;
|
package/dist/cjs/versions.js
CHANGED
|
@@ -26,6 +26,7 @@ const AuthorsModal_1 = require("../components/authors/AuthorsModal");
|
|
|
26
26
|
const authors_1 = require("../lib/authors");
|
|
27
27
|
const comments_1 = require("../lib/comments");
|
|
28
28
|
const track_changes_utils_1 = require("../lib/track-changes-utils");
|
|
29
|
+
const utils_1 = require("../lib/utils");
|
|
29
30
|
const view_1 = require("../lib/view");
|
|
30
31
|
const affiliations_1 = require("../plugins/affiliations");
|
|
31
32
|
const selected_suggestion_1 = require("../plugins/selected-suggestion");
|
|
@@ -235,22 +236,16 @@ class ContributorsView extends block_view_1.default {
|
|
|
235
236
|
const { view } = this;
|
|
236
237
|
const { dispatch } = view;
|
|
237
238
|
const affiliationsNodeType = transform_1.schema.nodes.affiliations;
|
|
238
|
-
const contributorsNodeType = transform_1.schema.nodes.contributors;
|
|
239
|
-
const affiliationNodeType = transform_1.schema.nodes.affiliation;
|
|
240
239
|
let affiliations = (0, view_1.findChildByType)(view, affiliationsNodeType);
|
|
241
240
|
if (!affiliations) {
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const insertPos = contributors.pos + contributors.node.nodeSize;
|
|
247
|
-
dispatch(tr.insert(insertPos, affiliationsNode));
|
|
248
|
-
affiliations = (0, view_1.findChildByType)(view, affiliationsNodeType);
|
|
249
|
-
}
|
|
241
|
+
const { tr } = this.view.state;
|
|
242
|
+
const insertPos = (0, utils_1.findInsertionPosition)(transform_1.schema.nodes.affiliations, view.state.doc);
|
|
243
|
+
dispatch(tr.insert(insertPos, transform_1.schema.nodes.affiliations.create()));
|
|
244
|
+
affiliations = (0, view_1.findChildByType)(view, affiliationsNodeType);
|
|
250
245
|
}
|
|
251
246
|
if (affiliations) {
|
|
252
247
|
const { tr } = this.view.state;
|
|
253
|
-
const affiliationNode =
|
|
248
|
+
const affiliationNode = transform_1.schema.nodes.affiliation.create(attrs);
|
|
254
249
|
dispatch(tr.insert(affiliations.pos + 1, affiliationNode));
|
|
255
250
|
}
|
|
256
251
|
};
|
package/dist/es/commands.js
CHANGED
|
@@ -28,7 +28,7 @@ import { createFootnote, findFootnotesContainerNode, getFootnotesElementState, }
|
|
|
28
28
|
import { findWordBoundaries, isNodeOfType, nearestAncestor, } from './lib/helpers';
|
|
29
29
|
import { templateAllows } from './lib/template';
|
|
30
30
|
import { isDeleted } from './lib/track-changes-utils';
|
|
31
|
-
import { findParentNodeWithId, getChildOfType, getInsertPos,
|
|
31
|
+
import { findInsertionPosition, findParentNodeWithId, getChildOfType, getInsertPos, isBodyLocked, } from './lib/utils';
|
|
32
32
|
import { expandAccessibilitySection } from './plugins/accessibility_element';
|
|
33
33
|
import { setCommentSelection } from './plugins/comments';
|
|
34
34
|
import { getEditorProps } from './plugins/editor-props';
|
|
@@ -690,8 +690,7 @@ export const insertContributors = (state, dispatch, view) => {
|
|
|
690
690
|
if (getChildOfType(state.doc, schema.nodes.contributors, true)) {
|
|
691
691
|
return false;
|
|
692
692
|
}
|
|
693
|
-
const
|
|
694
|
-
const pos = title.pos + title.node.nodeSize;
|
|
693
|
+
const pos = findInsertionPosition(schema.nodes.contributors, state.doc);
|
|
695
694
|
const contributors = state.schema.nodes.contributors.create({
|
|
696
695
|
id: '',
|
|
697
696
|
});
|
|
@@ -709,12 +708,7 @@ export const insertAffiliation = (state, dispatch, view) => {
|
|
|
709
708
|
if (getChildOfType(state.doc, schema.nodes.affiliations, true)) {
|
|
710
709
|
return false;
|
|
711
710
|
}
|
|
712
|
-
const
|
|
713
|
-
let pos = title.pos + title.node.nodeSize;
|
|
714
|
-
const contributors = findChildrenByType(state.doc, state.schema.nodes.contributors)[0];
|
|
715
|
-
if (contributors) {
|
|
716
|
-
pos = contributors.pos + contributors.node.nodeSize;
|
|
717
|
-
}
|
|
711
|
+
const pos = findInsertionPosition(schema.nodes.affiliations, state.doc);
|
|
718
712
|
const affiliations = state.schema.nodes.affiliations.create({
|
|
719
713
|
id: '',
|
|
720
714
|
});
|
|
@@ -745,8 +739,7 @@ export const insertKeywords = (state, dispatch, view) => {
|
|
|
745
739
|
if (getChildOfType(state.doc, schema.nodes.keywords, true)) {
|
|
746
740
|
return false;
|
|
747
741
|
}
|
|
748
|
-
const
|
|
749
|
-
const pos = abstracts.pos;
|
|
742
|
+
const pos = findInsertionPosition(schema.nodes.keywords, state.doc);
|
|
750
743
|
const keywords = schema.nodes.keywords.createAndFill({}, [
|
|
751
744
|
schema.nodes.section_title.create({}, schema.text('Keywords')),
|
|
752
745
|
schema.nodes.keywords_element.create({}, [
|
|
@@ -1241,8 +1234,7 @@ const createHeroImage = (attrs) => schema.nodes.hero_image.create({
|
|
|
1241
1234
|
schema.nodes.long_desc.create(),
|
|
1242
1235
|
]);
|
|
1243
1236
|
export const insertHeroImage = () => (state, dispatch, view) => {
|
|
1244
|
-
const
|
|
1245
|
-
const position = comments.pos;
|
|
1237
|
+
const position = findInsertionPosition(schema.nodes.hero_image, state.doc);
|
|
1246
1238
|
view?.focus();
|
|
1247
1239
|
createBlock(schema.nodes.hero_image, position, state, dispatch);
|
|
1248
1240
|
return true;
|
package/dist/es/lib/doc.js
CHANGED
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
import { generateNodeID, schema, } from '@manuscripts/transform';
|
|
2
2
|
import { findChildren, findChildrenByType } from 'prosemirror-utils';
|
|
3
|
+
import { findInsertionPosition } from './utils';
|
|
3
4
|
export const insertAwardsNode = (tr) => {
|
|
4
5
|
const doc = tr.doc;
|
|
5
6
|
const awards = findChildrenByType(doc, schema.nodes.awards)[0];
|
|
6
7
|
if (awards) {
|
|
7
8
|
return awards;
|
|
8
9
|
}
|
|
9
|
-
const
|
|
10
|
-
const possibleNodesTypes = [
|
|
11
|
-
'doi',
|
|
12
|
-
'keywords',
|
|
13
|
-
'supplements',
|
|
14
|
-
'abstracts',
|
|
15
|
-
'body',
|
|
16
|
-
];
|
|
17
|
-
doc.descendants((node, pos) => {
|
|
18
|
-
if (possibleNodesTypes.includes(node.type.name)) {
|
|
19
|
-
positions.push(pos);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const pos = positions.length === 0 ? 0 : Math.min(...positions);
|
|
10
|
+
const pos = findInsertionPosition(schema.nodes.awards, doc);
|
|
23
11
|
const node = schema.nodes.awards.createAndFill();
|
|
24
12
|
tr.insert(pos, node);
|
|
25
13
|
return {
|
|
@@ -33,8 +21,7 @@ export const insertSupplementsNode = (tr) => {
|
|
|
33
21
|
if (supplements) {
|
|
34
22
|
return supplements;
|
|
35
23
|
}
|
|
36
|
-
const
|
|
37
|
-
const pos = backmatter.pos + backmatter.node.content.size + 1;
|
|
24
|
+
const pos = findInsertionPosition(schema.nodes.supplements, doc);
|
|
38
25
|
const node = schema.nodes.supplements.createAndFill();
|
|
39
26
|
tr.insert(pos, node);
|
|
40
27
|
return {
|
|
@@ -50,8 +37,7 @@ export const insertAttachmentsNode = (tr) => {
|
|
|
50
37
|
pos: attachmentsNodes[0].pos,
|
|
51
38
|
};
|
|
52
39
|
}
|
|
53
|
-
const
|
|
54
|
-
const pos = comments.pos + comments.node.content.size;
|
|
40
|
+
const pos = findInsertionPosition(schema.nodes.attachments, tr.doc);
|
|
55
41
|
const node = schema.nodes.attachments.create({
|
|
56
42
|
id: generateNodeID(schema.nodes.attachments),
|
|
57
43
|
});
|
package/dist/es/lib/utils.js
CHANGED
|
@@ -154,6 +154,15 @@ export const getInsertPos = (type, parent, pos) => {
|
|
|
154
154
|
});
|
|
155
155
|
return insertPos;
|
|
156
156
|
};
|
|
157
|
+
export const findInsertionPosition = (type, doc) => {
|
|
158
|
+
let insertPos = 0;
|
|
159
|
+
doc.forEach((child, offset, index) => {
|
|
160
|
+
if (doc.canReplaceWith(index, index, type)) {
|
|
161
|
+
insertPos = offset;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return insertPos;
|
|
165
|
+
};
|
|
157
166
|
export const filterBlockNodes = (fragment, predicate) => {
|
|
158
167
|
const updatedNodes = [];
|
|
159
168
|
fragment.forEach((child) => {
|
|
@@ -18,6 +18,7 @@ import { Plugin, TextSelection } from 'prosemirror-state';
|
|
|
18
18
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
19
19
|
import { v4 as uuidv4 } from 'uuid';
|
|
20
20
|
import { addAuthorIcon } from '../icons';
|
|
21
|
+
import { findInsertionPosition } from '../lib/utils';
|
|
21
22
|
const createAddSubtitleButton = (handler) => {
|
|
22
23
|
const button = document.createElement('span');
|
|
23
24
|
button.className = 'add-subtitle';
|
|
@@ -52,8 +53,9 @@ export default () => new Plugin({
|
|
|
52
53
|
Decoration.widget(titleEndPos, (view) => {
|
|
53
54
|
return createAddSubtitleButton(() => {
|
|
54
55
|
const subtitlesNode = schema.nodes.subtitles.create({ id: uuidv4() }, [schema.nodes.subtitle.create({ id: uuidv4() })]);
|
|
55
|
-
const
|
|
56
|
-
const
|
|
56
|
+
const pos = findInsertionPosition(schema.nodes.subtitles, state.doc);
|
|
57
|
+
const tr = view.state.tr.insert(pos, subtitlesNode);
|
|
58
|
+
const subtitlePos = pos + 1;
|
|
57
59
|
tr.setSelection(TextSelection.create(tr.doc, subtitlePos));
|
|
58
60
|
view.dispatch(tr);
|
|
59
61
|
view.focus();
|
|
@@ -2,7 +2,7 @@ import { skipTracking } from '@manuscripts/track-changes-plugin';
|
|
|
2
2
|
import { schema, } from '@manuscripts/transform';
|
|
3
3
|
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
4
4
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
5
|
-
import { createToggleButton } from '../lib/utils';
|
|
5
|
+
import { createToggleButton, findInsertionPosition } from '../lib/utils';
|
|
6
6
|
function getTitlesData(doc) {
|
|
7
7
|
let title;
|
|
8
8
|
let subtitles;
|
|
@@ -76,21 +76,20 @@ export default () => {
|
|
|
76
76
|
!altTitlesKey.getState(newState)) {
|
|
77
77
|
return null;
|
|
78
78
|
}
|
|
79
|
-
const { title,
|
|
79
|
+
const { title, runningTitle, shortTitle, altTitlesSection } = altTitlesKey.getState(newState);
|
|
80
80
|
const schema = newState.schema;
|
|
81
81
|
if (!title) {
|
|
82
82
|
return null;
|
|
83
83
|
}
|
|
84
84
|
if (!altTitlesSection) {
|
|
85
|
-
const
|
|
86
|
-
const titleEnd = prev[0].nodeSize + prev[1];
|
|
85
|
+
const pos = findInsertionPosition(schema.nodes.alt_titles, tr.doc);
|
|
87
86
|
const section = schema.nodes.alt_titles.create({}, [
|
|
88
87
|
schema.nodes.alt_title.create({
|
|
89
88
|
type: 'running',
|
|
90
89
|
}),
|
|
91
90
|
schema.nodes.alt_title.create({ type: 'short' }),
|
|
92
91
|
]);
|
|
93
|
-
tr.insert(
|
|
92
|
+
tr.insert(pos, section);
|
|
94
93
|
}
|
|
95
94
|
else {
|
|
96
95
|
const endPos = altTitlesSection[1] + altTitlesSection[0].nodeSize - 1;
|
package/dist/es/versions.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '3.6.
|
|
1
|
+
export const VERSION = '3.6.2';
|
|
2
2
|
export const MATHJAX_VERSION = '3.2.2';
|
|
@@ -20,6 +20,7 @@ import { AuthorsModal, } from '../components/authors/AuthorsModal';
|
|
|
20
20
|
import { authorComparator, authorLabel, } from '../lib/authors';
|
|
21
21
|
import { handleComment } from '../lib/comments';
|
|
22
22
|
import { addTrackChangesAttributes, isDeleted, } from '../lib/track-changes-utils';
|
|
23
|
+
import { findInsertionPosition } from '../lib/utils';
|
|
23
24
|
import { deleteNode, findChildByID, findChildByType, findChildrenAttrsByType, updateNodeAttrs, } from '../lib/view';
|
|
24
25
|
import { affiliationsKey } from '../plugins/affiliations';
|
|
25
26
|
import { selectedSuggestionKey } from '../plugins/selected-suggestion';
|
|
@@ -229,22 +230,16 @@ export class ContributorsView extends BlockView {
|
|
|
229
230
|
const { view } = this;
|
|
230
231
|
const { dispatch } = view;
|
|
231
232
|
const affiliationsNodeType = schema.nodes.affiliations;
|
|
232
|
-
const contributorsNodeType = schema.nodes.contributors;
|
|
233
|
-
const affiliationNodeType = schema.nodes.affiliation;
|
|
234
233
|
let affiliations = findChildByType(view, affiliationsNodeType);
|
|
235
234
|
if (!affiliations) {
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const insertPos = contributors.pos + contributors.node.nodeSize;
|
|
241
|
-
dispatch(tr.insert(insertPos, affiliationsNode));
|
|
242
|
-
affiliations = findChildByType(view, affiliationsNodeType);
|
|
243
|
-
}
|
|
235
|
+
const { tr } = this.view.state;
|
|
236
|
+
const insertPos = findInsertionPosition(schema.nodes.affiliations, view.state.doc);
|
|
237
|
+
dispatch(tr.insert(insertPos, schema.nodes.affiliations.create()));
|
|
238
|
+
affiliations = findChildByType(view, affiliationsNodeType);
|
|
244
239
|
}
|
|
245
240
|
if (affiliations) {
|
|
246
241
|
const { tr } = this.view.state;
|
|
247
|
-
const affiliationNode =
|
|
242
|
+
const affiliationNode = schema.nodes.affiliation.create(attrs);
|
|
248
243
|
dispatch(tr.insert(affiliations.pos + 1, affiliationNode));
|
|
249
244
|
}
|
|
250
245
|
};
|
|
@@ -36,6 +36,7 @@ export declare const isBodyLocked: (state: EditorState) => boolean;
|
|
|
36
36
|
export declare const isEditAllowed: (state: EditorState) => boolean;
|
|
37
37
|
export declare const createToggleButton: (listener: () => void) => HTMLButtonElement;
|
|
38
38
|
export declare const getInsertPos: (type: ManuscriptNodeType, parent: ManuscriptNode, pos: number) => number;
|
|
39
|
+
export declare const findInsertionPosition: (type: ManuscriptNodeType, doc: ManuscriptNode) => number;
|
|
39
40
|
export declare const filterBlockNodes: (fragment: Fragment, predicate: (node: ProseMirrorNode) => boolean) => Fragment;
|
|
40
41
|
export declare const getLastTitleNode: (state: ManuscriptEditorState) => {
|
|
41
42
|
node: ProseMirrorNode;
|
package/dist/types/versions.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "3.6.
|
|
1
|
+
export declare const VERSION = "3.6.2";
|
|
2
2
|
export declare const MATHJAX_VERSION = "3.2.2";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/body-editor",
|
|
3
3
|
"description": "Prosemirror components for editing and viewing manuscripts",
|
|
4
|
-
"version": "3.6.
|
|
4
|
+
"version": "3.6.2",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@manuscripts/json-schema": "2.2.12",
|
|
42
42
|
"@manuscripts/style-guide": "3.3.2",
|
|
43
43
|
"@manuscripts/track-changes-plugin": "2.1.0",
|
|
44
|
-
"@manuscripts/transform": "4.3.
|
|
44
|
+
"@manuscripts/transform": "4.3.2",
|
|
45
45
|
"@popperjs/core": "2.11.8",
|
|
46
46
|
"citeproc": "2.4.63",
|
|
47
47
|
"codemirror": "5.65.19",
|