@manuscripts/body-editor 3.4.0 → 3.4.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/configs/editor-plugins.js +1 -1
- package/dist/cjs/plugins/detect-inconsistency/detect-inconsistency-utils.js +2 -1
- package/dist/cjs/plugins/detect-inconsistency/index.js +3 -3
- package/dist/cjs/plugins/detect-inconsistency/validators.js +45 -1
- package/dist/cjs/versions.js +1 -1
- package/dist/es/configs/editor-plugins.js +1 -1
- package/dist/es/plugins/detect-inconsistency/detect-inconsistency-utils.js +2 -1
- package/dist/es/plugins/detect-inconsistency/index.js +3 -3
- package/dist/es/plugins/detect-inconsistency/validators.js +45 -1
- package/dist/es/versions.js +1 -1
- package/dist/types/plugins/detect-inconsistency/detect-inconsistency-utils.d.ts +2 -1
- package/dist/types/plugins/detect-inconsistency/index.d.ts +2 -1
- package/dist/types/plugins/detect-inconsistency/validators.d.ts +2 -0
- package/dist/types/versions.d.ts +1 -1
- package/package.json +2 -2
|
@@ -82,7 +82,7 @@ exports.default = (props) => {
|
|
|
82
82
|
(0, doi_1.default)(),
|
|
83
83
|
(0, section_category_1.default)(props),
|
|
84
84
|
(0, cross_references_1.default)(),
|
|
85
|
-
(0, detect_inconsistency_1.default)(),
|
|
85
|
+
(0, detect_inconsistency_1.default)(props),
|
|
86
86
|
(0, search_replace_1.default)(),
|
|
87
87
|
(0, lock_body_1.default)(),
|
|
88
88
|
(0, alt_titles_1.default)(),
|
|
@@ -33,7 +33,7 @@ const createDecoration = (node, pos, selectedPos) => {
|
|
|
33
33
|
});
|
|
34
34
|
};
|
|
35
35
|
exports.createDecoration = createDecoration;
|
|
36
|
-
const buildPluginState = (state, showDecorations) => {
|
|
36
|
+
const buildPluginState = (state, props, showDecorations) => {
|
|
37
37
|
const inconsistencies = [];
|
|
38
38
|
const decorations = [];
|
|
39
39
|
const selection = state.selection;
|
|
@@ -50,6 +50,7 @@ const buildPluginState = (state, showDecorations) => {
|
|
|
50
50
|
showDecorations,
|
|
51
51
|
selectedPos,
|
|
52
52
|
decorations,
|
|
53
|
+
props,
|
|
53
54
|
};
|
|
54
55
|
state.doc.descendants((node, pos) => {
|
|
55
56
|
const validator = validators_1.validators[node.type.name];
|
|
@@ -20,16 +20,16 @@ const prosemirror_state_1 = require("prosemirror-state");
|
|
|
20
20
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
21
21
|
const detect_inconsistency_utils_1 = require("./detect-inconsistency-utils");
|
|
22
22
|
exports.detectInconsistencyKey = new prosemirror_state_1.PluginKey('detectInconsistency');
|
|
23
|
-
exports.default = () => {
|
|
23
|
+
exports.default = (props) => {
|
|
24
24
|
return new prosemirror_state_1.Plugin({
|
|
25
25
|
key: exports.detectInconsistencyKey,
|
|
26
26
|
state: {
|
|
27
|
-
init: (_, state) => (0, detect_inconsistency_utils_1.buildPluginState)(state, false),
|
|
27
|
+
init: (_, state) => (0, detect_inconsistency_utils_1.buildPluginState)(state, props, false),
|
|
28
28
|
apply: (tr, value, newState) => {
|
|
29
29
|
const showDecorations = tr.getMeta(exports.detectInconsistencyKey) !== undefined
|
|
30
30
|
? tr.getMeta(exports.detectInconsistencyKey)
|
|
31
31
|
: value.showDecorations;
|
|
32
|
-
return (0, detect_inconsistency_utils_1.buildPluginState)(newState, showDecorations);
|
|
32
|
+
return (0, detect_inconsistency_utils_1.buildPluginState)(newState, props, showDecorations);
|
|
33
33
|
},
|
|
34
34
|
},
|
|
35
35
|
props: {
|
|
@@ -17,13 +17,28 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.validators = void 0;
|
|
19
19
|
const transform_1 = require("@manuscripts/transform");
|
|
20
|
+
const url_1 = require("../../lib/url");
|
|
20
21
|
const detect_inconsistency_utils_1 = require("./detect-inconsistency-utils");
|
|
21
22
|
const getNodeDescription = (node) => {
|
|
22
23
|
return transform_1.nodeNames.get(node.type) || node.type?.name || 'node';
|
|
23
24
|
};
|
|
24
25
|
const createWarning = (node, pos, category, severity) => {
|
|
25
26
|
const nodeDescription = getNodeDescription(node);
|
|
26
|
-
const message =
|
|
27
|
+
const message = (() => {
|
|
28
|
+
switch (node.type) {
|
|
29
|
+
case transform_1.schema.nodes.figure_element:
|
|
30
|
+
case transform_1.schema.nodes.image_element:
|
|
31
|
+
return 'Has no uploaded file';
|
|
32
|
+
case transform_1.schema.nodes.embed:
|
|
33
|
+
return 'Has no link or uploaded file';
|
|
34
|
+
case transform_1.schema.nodes.link:
|
|
35
|
+
return 'Url is empty';
|
|
36
|
+
default:
|
|
37
|
+
return category === 'empty-content'
|
|
38
|
+
? `Is empty`
|
|
39
|
+
: `Has no linked reference`;
|
|
40
|
+
}
|
|
41
|
+
})();
|
|
27
42
|
return {
|
|
28
43
|
type: 'warning',
|
|
29
44
|
category,
|
|
@@ -87,9 +102,38 @@ const validateInlineFootnote = (node, pos, context) => {
|
|
|
87
102
|
}
|
|
88
103
|
return inconsistencies;
|
|
89
104
|
};
|
|
105
|
+
const validateFigure = (node, pos, context) => {
|
|
106
|
+
const inconsistencies = [];
|
|
107
|
+
const files = new Set(context.props.getFiles().map((f) => f.id));
|
|
108
|
+
if (!files.has(node.attrs.src)) {
|
|
109
|
+
const inconsistency = createWarning(node, pos, 'missing-reference', 'error');
|
|
110
|
+
inconsistencies.push(inconsistency);
|
|
111
|
+
}
|
|
112
|
+
return inconsistencies;
|
|
113
|
+
};
|
|
114
|
+
const validateMedia = (node, pos, context) => {
|
|
115
|
+
const inconsistencies = [];
|
|
116
|
+
const files = new Set(context.props.getFiles().map((f) => f.id));
|
|
117
|
+
if (!(files.has(node.attrs.href) || (0, url_1.allowedHref)(node.attrs.href))) {
|
|
118
|
+
const inconsistency = createWarning(node, pos, 'missing-reference', 'error');
|
|
119
|
+
inconsistencies.push(inconsistency);
|
|
120
|
+
}
|
|
121
|
+
return inconsistencies;
|
|
122
|
+
};
|
|
123
|
+
const validateLink = (node, pos) => {
|
|
124
|
+
const inconsistencies = [];
|
|
125
|
+
if (!(0, url_1.allowedHref)(node.attrs.href)) {
|
|
126
|
+
const inconsistency = createWarning(node, pos, 'missing-reference', 'error');
|
|
127
|
+
inconsistencies.push(inconsistency);
|
|
128
|
+
}
|
|
129
|
+
return inconsistencies;
|
|
130
|
+
};
|
|
90
131
|
exports.validators = {
|
|
91
132
|
[transform_1.schema.nodes.title.name]: validateTitle,
|
|
92
133
|
[transform_1.schema.nodes.cross_reference.name]: validateCrossReference,
|
|
93
134
|
[transform_1.schema.nodes.citation.name]: validateCitation,
|
|
94
135
|
[transform_1.schema.nodes.inline_footnote.name]: validateInlineFootnote,
|
|
136
|
+
[transform_1.schema.nodes.figure.name]: validateFigure,
|
|
137
|
+
[transform_1.schema.nodes.embed.name]: validateMedia,
|
|
138
|
+
[transform_1.schema.nodes.link.name]: validateLink,
|
|
95
139
|
};
|
package/dist/cjs/versions.js
CHANGED
|
@@ -29,7 +29,7 @@ export const createDecoration = (node, pos, selectedPos) => {
|
|
|
29
29
|
'data-inconsistency-type': 'warning',
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
|
-
export const buildPluginState = (state, showDecorations) => {
|
|
32
|
+
export const buildPluginState = (state, props, showDecorations) => {
|
|
33
33
|
const inconsistencies = [];
|
|
34
34
|
const decorations = [];
|
|
35
35
|
const selection = state.selection;
|
|
@@ -46,6 +46,7 @@ export const buildPluginState = (state, showDecorations) => {
|
|
|
46
46
|
showDecorations,
|
|
47
47
|
selectedPos,
|
|
48
48
|
decorations,
|
|
49
|
+
props,
|
|
49
50
|
};
|
|
50
51
|
state.doc.descendants((node, pos) => {
|
|
51
52
|
const validator = validators[node.type.name];
|
|
@@ -17,16 +17,16 @@ import { Plugin, PluginKey } from 'prosemirror-state';
|
|
|
17
17
|
import { DecorationSet } from 'prosemirror-view';
|
|
18
18
|
import { buildPluginState } from './detect-inconsistency-utils';
|
|
19
19
|
export const detectInconsistencyKey = new PluginKey('detectInconsistency');
|
|
20
|
-
export default () => {
|
|
20
|
+
export default (props) => {
|
|
21
21
|
return new Plugin({
|
|
22
22
|
key: detectInconsistencyKey,
|
|
23
23
|
state: {
|
|
24
|
-
init: (_, state) => buildPluginState(state, false),
|
|
24
|
+
init: (_, state) => buildPluginState(state, props, false),
|
|
25
25
|
apply: (tr, value, newState) => {
|
|
26
26
|
const showDecorations = tr.getMeta(detectInconsistencyKey) !== undefined
|
|
27
27
|
? tr.getMeta(detectInconsistencyKey)
|
|
28
28
|
: value.showDecorations;
|
|
29
|
-
return buildPluginState(newState, showDecorations);
|
|
29
|
+
return buildPluginState(newState, props, showDecorations);
|
|
30
30
|
},
|
|
31
31
|
},
|
|
32
32
|
props: {
|
|
@@ -14,13 +14,28 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { nodeNames, schema, } from '@manuscripts/transform';
|
|
17
|
+
import { allowedHref } from '../../lib/url';
|
|
17
18
|
import { createDecoration } from './detect-inconsistency-utils';
|
|
18
19
|
const getNodeDescription = (node) => {
|
|
19
20
|
return nodeNames.get(node.type) || node.type?.name || 'node';
|
|
20
21
|
};
|
|
21
22
|
const createWarning = (node, pos, category, severity) => {
|
|
22
23
|
const nodeDescription = getNodeDescription(node);
|
|
23
|
-
const message =
|
|
24
|
+
const message = (() => {
|
|
25
|
+
switch (node.type) {
|
|
26
|
+
case schema.nodes.figure_element:
|
|
27
|
+
case schema.nodes.image_element:
|
|
28
|
+
return 'Has no uploaded file';
|
|
29
|
+
case schema.nodes.embed:
|
|
30
|
+
return 'Has no link or uploaded file';
|
|
31
|
+
case schema.nodes.link:
|
|
32
|
+
return 'Url is empty';
|
|
33
|
+
default:
|
|
34
|
+
return category === 'empty-content'
|
|
35
|
+
? `Is empty`
|
|
36
|
+
: `Has no linked reference`;
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
24
39
|
return {
|
|
25
40
|
type: 'warning',
|
|
26
41
|
category,
|
|
@@ -84,9 +99,38 @@ const validateInlineFootnote = (node, pos, context) => {
|
|
|
84
99
|
}
|
|
85
100
|
return inconsistencies;
|
|
86
101
|
};
|
|
102
|
+
const validateFigure = (node, pos, context) => {
|
|
103
|
+
const inconsistencies = [];
|
|
104
|
+
const files = new Set(context.props.getFiles().map((f) => f.id));
|
|
105
|
+
if (!files.has(node.attrs.src)) {
|
|
106
|
+
const inconsistency = createWarning(node, pos, 'missing-reference', 'error');
|
|
107
|
+
inconsistencies.push(inconsistency);
|
|
108
|
+
}
|
|
109
|
+
return inconsistencies;
|
|
110
|
+
};
|
|
111
|
+
const validateMedia = (node, pos, context) => {
|
|
112
|
+
const inconsistencies = [];
|
|
113
|
+
const files = new Set(context.props.getFiles().map((f) => f.id));
|
|
114
|
+
if (!(files.has(node.attrs.href) || allowedHref(node.attrs.href))) {
|
|
115
|
+
const inconsistency = createWarning(node, pos, 'missing-reference', 'error');
|
|
116
|
+
inconsistencies.push(inconsistency);
|
|
117
|
+
}
|
|
118
|
+
return inconsistencies;
|
|
119
|
+
};
|
|
120
|
+
const validateLink = (node, pos) => {
|
|
121
|
+
const inconsistencies = [];
|
|
122
|
+
if (!allowedHref(node.attrs.href)) {
|
|
123
|
+
const inconsistency = createWarning(node, pos, 'missing-reference', 'error');
|
|
124
|
+
inconsistencies.push(inconsistency);
|
|
125
|
+
}
|
|
126
|
+
return inconsistencies;
|
|
127
|
+
};
|
|
87
128
|
export const validators = {
|
|
88
129
|
[schema.nodes.title.name]: validateTitle,
|
|
89
130
|
[schema.nodes.cross_reference.name]: validateCrossReference,
|
|
90
131
|
[schema.nodes.citation.name]: validateCitation,
|
|
91
132
|
[schema.nodes.inline_footnote.name]: validateInlineFootnote,
|
|
133
|
+
[schema.nodes.figure.name]: validateFigure,
|
|
134
|
+
[schema.nodes.embed.name]: validateMedia,
|
|
135
|
+
[schema.nodes.link.name]: validateLink,
|
|
92
136
|
};
|
package/dist/es/versions.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '3.4.
|
|
1
|
+
export const VERSION = '3.4.2';
|
|
2
2
|
export const MATHJAX_VERSION = '3.2.2';
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { ManuscriptEditorState, ManuscriptNode } from '@manuscripts/transform';
|
|
17
17
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
18
|
+
import { EditorProps } from '../../configs/ManuscriptsEditor';
|
|
18
19
|
export type Inconsistency = {
|
|
19
20
|
type: 'warning';
|
|
20
21
|
category: 'missing-reference' | 'empty-content';
|
|
@@ -30,4 +31,4 @@ export type PluginState = {
|
|
|
30
31
|
showDecorations: boolean;
|
|
31
32
|
};
|
|
32
33
|
export declare const createDecoration: (node: ManuscriptNode, pos: number, selectedPos: number | null) => Decoration;
|
|
33
|
-
export declare const buildPluginState: (state: ManuscriptEditorState, showDecorations: boolean) => PluginState;
|
|
34
|
+
export declare const buildPluginState: (state: ManuscriptEditorState, props: EditorProps, showDecorations: boolean) => PluginState;
|
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
17
|
+
import { EditorProps } from '../../configs/ManuscriptsEditor';
|
|
17
18
|
import { PluginState } from './detect-inconsistency-utils';
|
|
18
19
|
export { Inconsistency } from './detect-inconsistency-utils';
|
|
19
20
|
export declare const detectInconsistencyKey: PluginKey<PluginState>;
|
|
20
|
-
declare const _default: () => Plugin<PluginState>;
|
|
21
|
+
declare const _default: (props: EditorProps) => Plugin<PluginState>;
|
|
21
22
|
export default _default;
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { BibliographyItemAttrs, ManuscriptNode, Target } from '@manuscripts/transform';
|
|
17
17
|
import { Decoration } from 'prosemirror-view';
|
|
18
|
+
import { EditorProps } from '../../configs/ManuscriptsEditor';
|
|
18
19
|
import { Inconsistency } from './detect-inconsistency-utils';
|
|
19
20
|
export type ValidatorContext = {
|
|
20
21
|
pluginStates: {
|
|
@@ -25,6 +26,7 @@ export type ValidatorContext = {
|
|
|
25
26
|
showDecorations: boolean;
|
|
26
27
|
selectedPos: number | null;
|
|
27
28
|
decorations: Decoration[];
|
|
29
|
+
props: EditorProps;
|
|
28
30
|
};
|
|
29
31
|
export type NodeValidator = (node: ManuscriptNode, pos: number, context: ValidatorContext) => Inconsistency[];
|
|
30
32
|
export declare const validators: Record<string, NodeValidator>;
|
package/dist/types/versions.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "3.4.
|
|
1
|
+
export declare const VERSION = "3.4.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.4.
|
|
4
|
+
"version": "3.4.2",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@citation-js/plugin-ris": "0.7.18",
|
|
39
39
|
"@iarna/word-count": "1.1.2",
|
|
40
40
|
"@manuscripts/json-schema": "2.2.12",
|
|
41
|
-
"@manuscripts/style-guide": "3.2.
|
|
41
|
+
"@manuscripts/style-guide": "3.2.2",
|
|
42
42
|
"@manuscripts/track-changes-plugin": "2.0.10",
|
|
43
43
|
"@manuscripts/transform": "4.2.13",
|
|
44
44
|
"@popperjs/core": "2.11.8",
|