@manuscripts/body-editor 3.12.34 → 3.12.36
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 -1
- package/dist/cjs/lib/helpers.js +28 -1
- package/dist/cjs/plugins/paragraphs.js +17 -2
- package/dist/cjs/plugins/placeholder.js +3 -2
- package/dist/cjs/useEditor.js +7 -4
- package/dist/cjs/versions.js +1 -1
- package/dist/es/commands.js +1 -1
- package/dist/es/lib/helpers.js +27 -1
- package/dist/es/plugins/paragraphs.js +17 -2
- package/dist/es/plugins/placeholder.js +3 -2
- package/dist/es/useEditor.js +8 -5
- package/dist/es/versions.js +1 -1
- package/dist/types/lib/helpers.d.ts +2 -0
- package/dist/types/versions.d.ts +1 -1
- package/package.json +3 -3
- package/styles/Editor.css +4 -0
package/dist/cjs/commands.js
CHANGED
|
@@ -198,7 +198,7 @@ const createBlock = (nodeType, position, state, dispatch, attrs) => {
|
|
|
198
198
|
break;
|
|
199
199
|
case state.schema.nodes.pullquote_element:
|
|
200
200
|
node = state.schema.nodes.pullquote_element.create(attrs, [
|
|
201
|
-
state.schema.nodes.
|
|
201
|
+
state.schema.nodes.text_block.create({}),
|
|
202
202
|
state.schema.nodes.attribution.create({}),
|
|
203
203
|
]);
|
|
204
204
|
break;
|
package/dist/cjs/lib/helpers.js
CHANGED
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.findWordBoundaries = exports.handleScrollToSelectedTarget = exports.mergeSimilarItems = exports.nearestAncestor = exports.isNodeOfType = void 0;
|
|
18
|
+
exports.findWordBoundaries = exports.handleScrollToSelectedTarget = exports.selectionForOutlineNavigation = exports.mergeSimilarItems = exports.nearestAncestor = exports.isNodeOfType = void 0;
|
|
19
19
|
const transform_1 = require("@manuscripts/transform");
|
|
20
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
20
21
|
const isNodeOfType = (...type) => (node) => {
|
|
21
22
|
const [head, ...tail] = type;
|
|
22
23
|
if (node.type === node.type.schema.nodes[head]) {
|
|
@@ -51,6 +52,32 @@ const mergeSimilarItems = (compareFunc, mergeFunc) => (items) => {
|
|
|
51
52
|
}, []);
|
|
52
53
|
};
|
|
53
54
|
exports.mergeSimilarItems = mergeSimilarItems;
|
|
55
|
+
const selectionForOutlineNavigation = (doc, pos) => {
|
|
56
|
+
const node = doc.nodeAt(pos);
|
|
57
|
+
if (!node || (0, transform_1.isExecutableNodeType)(node.type)) {
|
|
58
|
+
return prosemirror_state_1.NodeSelection.create(doc, pos);
|
|
59
|
+
}
|
|
60
|
+
if (node.isTextblock) {
|
|
61
|
+
return prosemirror_state_1.TextSelection.create(doc, pos + 1);
|
|
62
|
+
}
|
|
63
|
+
if (node.type === transform_1.schema.nodes.section) {
|
|
64
|
+
let textPos = null;
|
|
65
|
+
node.forEach((child, offset) => {
|
|
66
|
+
if (textPos !== null) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (child.type === transform_1.schema.nodes.section_title ||
|
|
70
|
+
child.type === transform_1.schema.nodes.section_title_plain) {
|
|
71
|
+
textPos = pos + 1 + offset + 1;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
if (textPos !== null) {
|
|
75
|
+
return prosemirror_state_1.TextSelection.create(doc, textPos);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return prosemirror_state_1.NodeSelection.create(doc, pos);
|
|
79
|
+
};
|
|
80
|
+
exports.selectionForOutlineNavigation = selectionForOutlineNavigation;
|
|
54
81
|
const handleScrollToSelectedTarget = (view) => {
|
|
55
82
|
const selection = view.state.selection;
|
|
56
83
|
if (selection.empty) {
|
|
@@ -17,6 +17,17 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
const transform_1 = require("@manuscripts/transform");
|
|
19
19
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
20
|
+
const isTextBlock = (node) => {
|
|
21
|
+
return node.type === node.type.schema.nodes.text_block;
|
|
22
|
+
};
|
|
23
|
+
const isTextBlockOrParagraph = (node) => {
|
|
24
|
+
return (0, transform_1.isParagraphNode)(node) || isTextBlock(node);
|
|
25
|
+
};
|
|
26
|
+
const isTableCell = (node) => {
|
|
27
|
+
const { schema } = node.type;
|
|
28
|
+
return (node.type === schema.nodes.table_cell ||
|
|
29
|
+
node.type === schema.nodes.table_header);
|
|
30
|
+
};
|
|
20
31
|
exports.default = () => {
|
|
21
32
|
return new prosemirror_state_1.Plugin({
|
|
22
33
|
appendTransaction: (transactions, oldState, newState) => {
|
|
@@ -27,11 +38,15 @@ exports.default = () => {
|
|
|
27
38
|
}
|
|
28
39
|
const joinAdjacentParagraphs = (parent, pos) => (node, offset, index) => {
|
|
29
40
|
const nodePos = pos + offset;
|
|
30
|
-
if ((
|
|
41
|
+
if (isTableCell(parent)) {
|
|
42
|
+
node.forEach(joinAdjacentParagraphs(node, nodePos + 1));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (isTextBlockOrParagraph(node) &&
|
|
31
46
|
node.childCount === 0 &&
|
|
32
47
|
index < parent.childCount - 1) {
|
|
33
48
|
const nextNode = parent.child(index + 1);
|
|
34
|
-
if ((
|
|
49
|
+
if (isTextBlockOrParagraph(nextNode) && nextNode.childCount === 0) {
|
|
35
50
|
positionsToJoin.push(nodePos + node.nodeSize);
|
|
36
51
|
}
|
|
37
52
|
}
|
|
@@ -50,7 +50,7 @@ const getParagraphPlaceholderText = (parent, node) => {
|
|
|
50
50
|
if ((0, transform_1.isPullquoteElement)(parent) && !node.textContent.length) {
|
|
51
51
|
let otherParagraphHasContent = false;
|
|
52
52
|
parent.descendants((child) => {
|
|
53
|
-
if (child !== node && child.type === child.type.schema.nodes.
|
|
53
|
+
if (child !== node && child.type === child.type.schema.nodes.text_block) {
|
|
54
54
|
otherParagraphHasContent = true;
|
|
55
55
|
}
|
|
56
56
|
});
|
|
@@ -81,7 +81,8 @@ exports.default = () => new prosemirror_state_1.Plugin({
|
|
|
81
81
|
if (node.type === node.type.schema.nodes.attribution) {
|
|
82
82
|
decorations.push(prosemirror_view_1.Decoration.widget(pos + 1, placeholderWidget('Insert reference here')));
|
|
83
83
|
}
|
|
84
|
-
if (node.type === node.type.schema.nodes.paragraph
|
|
84
|
+
if (node.type === node.type.schema.nodes.paragraph ||
|
|
85
|
+
node.type === node.type.schema.nodes.text_block) {
|
|
85
86
|
const text = getParagraphPlaceholderText(parent, node);
|
|
86
87
|
if (text) {
|
|
87
88
|
decorations.push(prosemirror_view_1.Decoration.widget(pos + 1, placeholderWidget(text)));
|
package/dist/cjs/useEditor.js
CHANGED
|
@@ -24,6 +24,7 @@ const react_router_dom_1 = require("react-router-dom");
|
|
|
24
24
|
const ManuscriptsEditor_1 = require("./configs/ManuscriptsEditor");
|
|
25
25
|
const popper_1 = require("./lib/popper");
|
|
26
26
|
const use_do_with_debounce_1 = require("./lib/use-do-with-debounce");
|
|
27
|
+
const helpers_1 = require("./lib/helpers");
|
|
27
28
|
const search_replace_1 = require("./plugins/search-replace");
|
|
28
29
|
const useEditor = (externalProps) => {
|
|
29
30
|
const view = (0, react_1.useRef)(undefined);
|
|
@@ -109,12 +110,14 @@ const useEditor = (externalProps) => {
|
|
|
109
110
|
if (!id || !currentView || !state) {
|
|
110
111
|
return;
|
|
111
112
|
}
|
|
112
|
-
|
|
113
|
+
const viewState = currentView.state;
|
|
114
|
+
viewState.doc.descendants((node, pos) => {
|
|
113
115
|
if (node.attrs.id === id) {
|
|
114
116
|
currentView.focus();
|
|
115
|
-
const selection =
|
|
116
|
-
currentView.dispatch(
|
|
117
|
-
const
|
|
117
|
+
const selection = (0, helpers_1.selectionForOutlineNavigation)(viewState.doc, pos);
|
|
118
|
+
currentView.dispatch(viewState.tr.setSelection(selection));
|
|
119
|
+
const scrollPos = selection instanceof prosemirror_state_1.TextSelection ? selection.from : pos + 1;
|
|
120
|
+
const dom = currentView.domAtPos(scrollPos);
|
|
118
121
|
if (dom.node instanceof Element) {
|
|
119
122
|
dom.node.scrollIntoView({
|
|
120
123
|
behavior: 'smooth',
|
package/dist/cjs/versions.js
CHANGED
package/dist/es/commands.js
CHANGED
|
@@ -188,7 +188,7 @@ export const createBlock = (nodeType, position, state, dispatch, attrs) => {
|
|
|
188
188
|
break;
|
|
189
189
|
case state.schema.nodes.pullquote_element:
|
|
190
190
|
node = state.schema.nodes.pullquote_element.create(attrs, [
|
|
191
|
-
state.schema.nodes.
|
|
191
|
+
state.schema.nodes.text_block.create({}),
|
|
192
192
|
state.schema.nodes.attribution.create({}),
|
|
193
193
|
]);
|
|
194
194
|
break;
|
package/dist/es/lib/helpers.js
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { schema, } from '@manuscripts/transform';
|
|
16
|
+
import { isExecutableNodeType, schema, } from '@manuscripts/transform';
|
|
17
|
+
import { NodeSelection, TextSelection } from 'prosemirror-state';
|
|
17
18
|
export const isNodeOfType = (...type) => (node) => {
|
|
18
19
|
const [head, ...tail] = type;
|
|
19
20
|
if (node.type === node.type.schema.nodes[head]) {
|
|
@@ -45,6 +46,31 @@ export const mergeSimilarItems = (compareFunc, mergeFunc) => (items) => {
|
|
|
45
46
|
];
|
|
46
47
|
}, []);
|
|
47
48
|
};
|
|
49
|
+
export const selectionForOutlineNavigation = (doc, pos) => {
|
|
50
|
+
const node = doc.nodeAt(pos);
|
|
51
|
+
if (!node || isExecutableNodeType(node.type)) {
|
|
52
|
+
return NodeSelection.create(doc, pos);
|
|
53
|
+
}
|
|
54
|
+
if (node.isTextblock) {
|
|
55
|
+
return TextSelection.create(doc, pos + 1);
|
|
56
|
+
}
|
|
57
|
+
if (node.type === schema.nodes.section) {
|
|
58
|
+
let textPos = null;
|
|
59
|
+
node.forEach((child, offset) => {
|
|
60
|
+
if (textPos !== null) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (child.type === schema.nodes.section_title ||
|
|
64
|
+
child.type === schema.nodes.section_title_plain) {
|
|
65
|
+
textPos = pos + 1 + offset + 1;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
if (textPos !== null) {
|
|
69
|
+
return TextSelection.create(doc, textPos);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return NodeSelection.create(doc, pos);
|
|
73
|
+
};
|
|
48
74
|
export const handleScrollToSelectedTarget = (view) => {
|
|
49
75
|
const selection = view.state.selection;
|
|
50
76
|
if (selection.empty) {
|
|
@@ -15,6 +15,17 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { isParagraphNode } from '@manuscripts/transform';
|
|
17
17
|
import { Plugin } from 'prosemirror-state';
|
|
18
|
+
const isTextBlock = (node) => {
|
|
19
|
+
return node.type === node.type.schema.nodes.text_block;
|
|
20
|
+
};
|
|
21
|
+
const isTextBlockOrParagraph = (node) => {
|
|
22
|
+
return isParagraphNode(node) || isTextBlock(node);
|
|
23
|
+
};
|
|
24
|
+
const isTableCell = (node) => {
|
|
25
|
+
const { schema } = node.type;
|
|
26
|
+
return (node.type === schema.nodes.table_cell ||
|
|
27
|
+
node.type === schema.nodes.table_header);
|
|
28
|
+
};
|
|
18
29
|
export default () => {
|
|
19
30
|
return new Plugin({
|
|
20
31
|
appendTransaction: (transactions, oldState, newState) => {
|
|
@@ -25,11 +36,15 @@ export default () => {
|
|
|
25
36
|
}
|
|
26
37
|
const joinAdjacentParagraphs = (parent, pos) => (node, offset, index) => {
|
|
27
38
|
const nodePos = pos + offset;
|
|
28
|
-
if (
|
|
39
|
+
if (isTableCell(parent)) {
|
|
40
|
+
node.forEach(joinAdjacentParagraphs(node, nodePos + 1));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (isTextBlockOrParagraph(node) &&
|
|
29
44
|
node.childCount === 0 &&
|
|
30
45
|
index < parent.childCount - 1) {
|
|
31
46
|
const nextNode = parent.child(index + 1);
|
|
32
|
-
if (
|
|
47
|
+
if (isTextBlockOrParagraph(nextNode) && nextNode.childCount === 0) {
|
|
33
48
|
positionsToJoin.push(nodePos + node.nodeSize);
|
|
34
49
|
}
|
|
35
50
|
}
|
|
@@ -48,7 +48,7 @@ const getParagraphPlaceholderText = (parent, node) => {
|
|
|
48
48
|
if (isPullquoteElement(parent) && !node.textContent.length) {
|
|
49
49
|
let otherParagraphHasContent = false;
|
|
50
50
|
parent.descendants((child) => {
|
|
51
|
-
if (child !== node && child.type === child.type.schema.nodes.
|
|
51
|
+
if (child !== node && child.type === child.type.schema.nodes.text_block) {
|
|
52
52
|
otherParagraphHasContent = true;
|
|
53
53
|
}
|
|
54
54
|
});
|
|
@@ -79,7 +79,8 @@ export default () => new Plugin({
|
|
|
79
79
|
if (node.type === node.type.schema.nodes.attribution) {
|
|
80
80
|
decorations.push(Decoration.widget(pos + 1, placeholderWidget('Insert reference here')));
|
|
81
81
|
}
|
|
82
|
-
if (node.type === node.type.schema.nodes.paragraph
|
|
82
|
+
if (node.type === node.type.schema.nodes.paragraph ||
|
|
83
|
+
node.type === node.type.schema.nodes.text_block) {
|
|
83
84
|
const text = getParagraphPlaceholderText(parent, node);
|
|
84
85
|
if (text) {
|
|
85
86
|
decorations.push(Decoration.widget(pos + 1, placeholderWidget(text)));
|
package/dist/es/useEditor.js
CHANGED
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { trackChangesPluginKey, TrackChangesStatus, } from '@manuscripts/track-changes-plugin';
|
|
17
17
|
import { getVersion, receiveTransaction, sendableSteps, } from 'prosemirror-collab';
|
|
18
|
-
import {
|
|
18
|
+
import { TextSelection, } from 'prosemirror-state';
|
|
19
19
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
20
20
|
import { useLocation } from 'react-router-dom';
|
|
21
21
|
import { createEditorState, createEditorView, } from './configs/ManuscriptsEditor';
|
|
22
22
|
import { PopperManager } from './lib/popper';
|
|
23
23
|
import { useDoWithDebounce } from './lib/use-do-with-debounce';
|
|
24
|
+
import { selectionForOutlineNavigation } from './lib/helpers';
|
|
24
25
|
import { searchReplaceKey } from './plugins/search-replace';
|
|
25
26
|
export const useEditor = (externalProps) => {
|
|
26
27
|
const view = useRef(undefined);
|
|
@@ -106,12 +107,14 @@ export const useEditor = (externalProps) => {
|
|
|
106
107
|
if (!id || !currentView || !state) {
|
|
107
108
|
return;
|
|
108
109
|
}
|
|
109
|
-
|
|
110
|
+
const viewState = currentView.state;
|
|
111
|
+
viewState.doc.descendants((node, pos) => {
|
|
110
112
|
if (node.attrs.id === id) {
|
|
111
113
|
currentView.focus();
|
|
112
|
-
const selection =
|
|
113
|
-
currentView.dispatch(
|
|
114
|
-
const
|
|
114
|
+
const selection = selectionForOutlineNavigation(viewState.doc, pos);
|
|
115
|
+
currentView.dispatch(viewState.tr.setSelection(selection));
|
|
116
|
+
const scrollPos = selection instanceof TextSelection ? selection.from : pos + 1;
|
|
117
|
+
const dom = currentView.domAtPos(scrollPos);
|
|
115
118
|
if (dom.node instanceof Element) {
|
|
116
119
|
dom.node.scrollIntoView({
|
|
117
120
|
behavior: 'smooth',
|
package/dist/es/versions.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '3.12.
|
|
1
|
+
export const VERSION = '3.12.36';
|
|
2
2
|
export const MATHJAX_VERSION = '3.2.2';
|
|
@@ -15,10 +15,12 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { ManuscriptEditorState, ManuscriptNode } from '@manuscripts/transform';
|
|
17
17
|
import { Node, ResolvedPos } from 'prosemirror-model';
|
|
18
|
+
import { NodeSelection, TextSelection } from 'prosemirror-state';
|
|
18
19
|
import { EditorView } from 'prosemirror-view';
|
|
19
20
|
export declare const isNodeOfType: (...type: string[]) => (node: Node) => boolean;
|
|
20
21
|
export declare const nearestAncestor: (func: (node: ManuscriptNode) => boolean) => ($pos: ResolvedPos) => number | null;
|
|
21
22
|
export declare const mergeSimilarItems: <T>(compareFunc: (a: T, b: T) => boolean, mergeFunc: (a: T, b: T) => T) => (items: T[]) => T[];
|
|
23
|
+
export declare const selectionForOutlineNavigation: (doc: Node, pos: number) => NodeSelection | TextSelection;
|
|
22
24
|
export declare const handleScrollToSelectedTarget: (view: EditorView) => boolean;
|
|
23
25
|
export declare const findWordBoundaries: (state: ManuscriptEditorState, position: number) => {
|
|
24
26
|
from: number;
|
package/dist/types/versions.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "3.12.
|
|
1
|
+
export declare const VERSION = "3.12.36";
|
|
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.12.
|
|
4
|
+
"version": "3.12.36",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"@citation-js/plugin-pubmed": "0.3.0",
|
|
38
38
|
"@citation-js/plugin-ris": "0.7.18",
|
|
39
39
|
"@iarna/word-count": "1.1.2",
|
|
40
|
-
"@manuscripts/style-guide": "3.5.
|
|
40
|
+
"@manuscripts/style-guide": "3.5.13",
|
|
41
41
|
"@manuscripts/track-changes-plugin": "2.3.10",
|
|
42
|
-
"@manuscripts/transform": "4.3.
|
|
42
|
+
"@manuscripts/transform": "4.3.39",
|
|
43
43
|
"@popperjs/core": "2.11.8",
|
|
44
44
|
"citeproc": "2.4.63",
|
|
45
45
|
"codemirror": "5.65.19",
|
package/styles/Editor.css
CHANGED
|
@@ -92,6 +92,9 @@
|
|
|
92
92
|
line-height: 2;
|
|
93
93
|
font-size: 16px;
|
|
94
94
|
}
|
|
95
|
+
.ProseMirror .pullquote p {
|
|
96
|
+
display: flow-root;
|
|
97
|
+
}
|
|
95
98
|
.ProseMirror .pullquote p i {
|
|
96
99
|
font-style: normal;
|
|
97
100
|
}
|
|
@@ -128,6 +131,7 @@
|
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
.ProseMirror .pullquote footer {
|
|
134
|
+
display: flow-root;
|
|
131
135
|
padding-left: 1em;
|
|
132
136
|
color: #777;
|
|
133
137
|
position: relative;
|