@manuscripts/body-editor 2.0.26-LEAN-3884.1 → 2.0.26
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 +1 -23
- package/dist/cjs/lib/context-menu.js +5 -1
- package/dist/cjs/lib/utils.js +11 -1
- package/dist/cjs/versions.js +1 -1
- package/dist/es/commands.js +1 -23
- package/dist/es/lib/context-menu.js +6 -2
- package/dist/es/lib/utils.js +9 -0
- package/dist/es/versions.js +1 -1
- package/dist/types/lib/utils.d.ts +2 -0
- package/dist/types/versions.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/commands.js
CHANGED
|
@@ -236,25 +236,6 @@ const insertBreak = (state, dispatch) => {
|
|
|
236
236
|
};
|
|
237
237
|
exports.insertBreak = insertBreak;
|
|
238
238
|
const selectedText = () => (window.getSelection() || '').toString();
|
|
239
|
-
const findPosBeforeFirstSubsection = ($pos) => {
|
|
240
|
-
let posBeforeFirstSubsection = null;
|
|
241
|
-
for (let d = $pos.depth; d >= 0; d--) {
|
|
242
|
-
const parentNode = $pos.node(d);
|
|
243
|
-
if ((0, transform_1.isSectionNodeType)(parentNode.type)) {
|
|
244
|
-
const parentStartPos = $pos.start(d);
|
|
245
|
-
parentNode.descendants((node, pos) => {
|
|
246
|
-
if (node.type === transform_1.schema.nodes.section &&
|
|
247
|
-
posBeforeFirstSubsection === null) {
|
|
248
|
-
posBeforeFirstSubsection = parentStartPos + pos;
|
|
249
|
-
return false;
|
|
250
|
-
}
|
|
251
|
-
return true;
|
|
252
|
-
});
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return posBeforeFirstSubsection;
|
|
257
|
-
};
|
|
258
239
|
const findPosAfterParentSection = ($pos) => {
|
|
259
240
|
for (let d = $pos.depth; d >= 0; d--) {
|
|
260
241
|
const node = $pos.node(d);
|
|
@@ -449,10 +430,7 @@ const insertSection = (subsection = false) => (state, dispatch, view) => {
|
|
|
449
430
|
}
|
|
450
431
|
let pos;
|
|
451
432
|
if ((0, prosemirror_utils_1.hasParentNodeOfType)(transform_1.schema.nodes.body)(selection) || subsection) {
|
|
452
|
-
pos =
|
|
453
|
-
? findPosBeforeFirstSubsection(state.selection.$from) ||
|
|
454
|
-
findPosAfterParentSection(state.selection.$from)
|
|
455
|
-
: findPosAfterParentSection(state.selection.$from);
|
|
433
|
+
pos = findPosAfterParentSection(state.selection.$from);
|
|
456
434
|
}
|
|
457
435
|
else {
|
|
458
436
|
const body = (0, doc_1.findBody)(state.doc);
|
|
@@ -68,7 +68,11 @@ class ContextMenu {
|
|
|
68
68
|
const itemTitle = sectionTitle
|
|
69
69
|
? `“${this.trimTitle(sectionTitle, 30)}”`
|
|
70
70
|
: 'This Section';
|
|
71
|
-
if (types.has('section')
|
|
71
|
+
if (types.has('section') &&
|
|
72
|
+
!(0, utils_1.isChildOfNodeTypes)(this.view.state.doc, $pos.pos, [
|
|
73
|
+
transform_1.schema.nodes.abstracts,
|
|
74
|
+
transform_1.schema.nodes.backmatter,
|
|
75
|
+
])) {
|
|
72
76
|
const labelPosition = after ? 'After' : 'Before';
|
|
73
77
|
const level = (0, exports.sectionLevel)($pos.depth - 1);
|
|
74
78
|
const label = `New ${level} ${labelPosition} ${itemTitle}`;
|
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.findParentElement = exports.findParentSection = exports.findParentNodeWithIdValue = exports.findParentNodeWithId = exports.getChildOfType = exports.getMatchingDescendant = exports.getMatchingChild = exports.iterateChildren = void 0;
|
|
18
|
+
exports.isChildOfNodeTypes = exports.findParentElement = exports.findParentSection = exports.findParentNodeWithIdValue = exports.findParentNodeWithId = exports.getChildOfType = exports.getMatchingDescendant = exports.getMatchingChild = exports.iterateChildren = void 0;
|
|
19
19
|
const transform_1 = require("@manuscripts/transform");
|
|
20
20
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
21
21
|
function* iterateChildren(node, recurse = false) {
|
|
@@ -58,3 +58,13 @@ const findParentElement = (selection, validIds) => (0, prosemirror_utils_1.findP
|
|
|
58
58
|
return (0, transform_1.isElementNodeType)(node.type) && node.attrs.id;
|
|
59
59
|
})(selection);
|
|
60
60
|
exports.findParentElement = findParentElement;
|
|
61
|
+
const isChildOfNodeTypes = (doc, pos, parentNodeTypes) => {
|
|
62
|
+
const resolvedPos = doc.resolve(pos);
|
|
63
|
+
for (let depth = resolvedPos.depth - 1; depth >= 0; depth--) {
|
|
64
|
+
if (parentNodeTypes.includes(resolvedPos.node(depth).type)) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
};
|
|
70
|
+
exports.isChildOfNodeTypes = isChildOfNodeTypes;
|
package/dist/cjs/versions.js
CHANGED
package/dist/es/commands.js
CHANGED
|
@@ -221,25 +221,6 @@ export const insertBreak = (state, dispatch) => {
|
|
|
221
221
|
return true;
|
|
222
222
|
};
|
|
223
223
|
const selectedText = () => (window.getSelection() || '').toString();
|
|
224
|
-
const findPosBeforeFirstSubsection = ($pos) => {
|
|
225
|
-
let posBeforeFirstSubsection = null;
|
|
226
|
-
for (let d = $pos.depth; d >= 0; d--) {
|
|
227
|
-
const parentNode = $pos.node(d);
|
|
228
|
-
if (isSectionNodeType(parentNode.type)) {
|
|
229
|
-
const parentStartPos = $pos.start(d);
|
|
230
|
-
parentNode.descendants((node, pos) => {
|
|
231
|
-
if (node.type === schema.nodes.section &&
|
|
232
|
-
posBeforeFirstSubsection === null) {
|
|
233
|
-
posBeforeFirstSubsection = parentStartPos + pos;
|
|
234
|
-
return false;
|
|
235
|
-
}
|
|
236
|
-
return true;
|
|
237
|
-
});
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return posBeforeFirstSubsection;
|
|
242
|
-
};
|
|
243
224
|
const findPosAfterParentSection = ($pos) => {
|
|
244
225
|
for (let d = $pos.depth; d >= 0; d--) {
|
|
245
226
|
const node = $pos.node(d);
|
|
@@ -425,10 +406,7 @@ export const insertSection = (subsection = false) => (state, dispatch, view) =>
|
|
|
425
406
|
}
|
|
426
407
|
let pos;
|
|
427
408
|
if (hasParentNodeOfType(schema.nodes.body)(selection) || subsection) {
|
|
428
|
-
pos =
|
|
429
|
-
? findPosBeforeFirstSubsection(state.selection.$from) ||
|
|
430
|
-
findPosAfterParentSection(state.selection.$from)
|
|
431
|
-
: findPosAfterParentSection(state.selection.$from);
|
|
409
|
+
pos = findPosAfterParentSection(state.selection.$from);
|
|
432
410
|
}
|
|
433
411
|
else {
|
|
434
412
|
const body = findBody(state.doc);
|
|
@@ -21,7 +21,7 @@ import { buildTableFootnoteLabels } from '../plugins/footnotes/footnotes-utils';
|
|
|
21
21
|
import ReactSubView from '../views/ReactSubView';
|
|
22
22
|
import { PopperManager } from './popper';
|
|
23
23
|
import { getActualAttrs, isDeleted, isRejectedInsert, } from './track-changes-utils';
|
|
24
|
-
import { getChildOfType } from './utils';
|
|
24
|
+
import { getChildOfType, isChildOfNodeTypes } from './utils';
|
|
25
25
|
const popper = new PopperManager();
|
|
26
26
|
const readonlyTypes = [schema.nodes.keywords, schema.nodes.bibliography_element];
|
|
27
27
|
export const sectionLevel = (depth) => {
|
|
@@ -61,7 +61,11 @@ export class ContextMenu {
|
|
|
61
61
|
const itemTitle = sectionTitle
|
|
62
62
|
? `“${this.trimTitle(sectionTitle, 30)}”`
|
|
63
63
|
: 'This Section';
|
|
64
|
-
if (types.has('section')
|
|
64
|
+
if (types.has('section') &&
|
|
65
|
+
!isChildOfNodeTypes(this.view.state.doc, $pos.pos, [
|
|
66
|
+
schema.nodes.abstracts,
|
|
67
|
+
schema.nodes.backmatter,
|
|
68
|
+
])) {
|
|
65
69
|
const labelPosition = after ? 'After' : 'Before';
|
|
66
70
|
const level = sectionLevel($pos.depth - 1);
|
|
67
71
|
const label = `New ${level} ${labelPosition} ${itemTitle}`;
|
package/dist/es/lib/utils.js
CHANGED
|
@@ -50,3 +50,12 @@ export const findParentElement = (selection, validIds) => findParentNode((node)
|
|
|
50
50
|
}
|
|
51
51
|
return isElementNodeType(node.type) && node.attrs.id;
|
|
52
52
|
})(selection);
|
|
53
|
+
export const isChildOfNodeTypes = (doc, pos, parentNodeTypes) => {
|
|
54
|
+
const resolvedPos = doc.resolve(pos);
|
|
55
|
+
for (let depth = resolvedPos.depth - 1; depth >= 0; depth--) {
|
|
56
|
+
if (parentNodeTypes.includes(resolvedPos.node(depth).type)) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
};
|
package/dist/es/versions.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '2.0.26
|
|
1
|
+
export const VERSION = '2.0.26';
|
|
2
2
|
export const MATHJAX_VERSION = '3.2.2';
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { ManuscriptNode, ManuscriptNodeType } from '@manuscripts/transform';
|
|
17
|
+
import { NodeType } from 'prosemirror-model';
|
|
17
18
|
import { Selection } from 'prosemirror-state';
|
|
18
19
|
export declare function iterateChildren(node: ManuscriptNode, recurse?: boolean): Iterable<ManuscriptNode>;
|
|
19
20
|
export declare const getMatchingChild: (parent: ManuscriptNode, matcher: (node: ManuscriptNode) => boolean, deep?: boolean) => ManuscriptNode | undefined;
|
|
@@ -23,3 +24,4 @@ export declare const findParentNodeWithId: (selection: Selection) => import("pro
|
|
|
23
24
|
export declare const findParentNodeWithIdValue: (selection: Selection) => import("prosemirror-utils").ContentNodeWithPos | undefined;
|
|
24
25
|
export declare const findParentSection: (selection: Selection) => import("prosemirror-utils").ContentNodeWithPos | undefined;
|
|
25
26
|
export declare const findParentElement: (selection: Selection, validIds?: string[]) => import("prosemirror-utils").ContentNodeWithPos | undefined;
|
|
27
|
+
export declare const isChildOfNodeTypes: (doc: ManuscriptNode, pos: number, parentNodeTypes: NodeType[]) => boolean;
|
package/dist/types/versions.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.26
|
|
1
|
+
export declare const VERSION = "2.0.26";
|
|
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": "2.0.26
|
|
4
|
+
"version": "2.0.26",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|