@manuscripts/transform 1.1.4 → 1.1.5-LEAN-2066-41002a3
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/jats/importer/jats-comments.js +30 -0
- package/dist/cjs/schema/nodes/keyword.js +1 -1
- package/dist/cjs/schema/nodes/keywords_section.js +1 -0
- package/dist/cjs/transformer/object-types.js +2 -1
- package/dist/es/jats/importer/jats-comments.js +31 -1
- package/dist/es/schema/nodes/keyword.js +1 -1
- package/dist/es/schema/nodes/keywords_section.js +1 -0
- package/dist/es/transformer/object-types.js +1 -0
- package/dist/types/transformer/object-types.d.ts +2 -1
- package/package.json +1 -1
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.createReferenceComments = exports.createComments = exports.markProcessingInstructions = exports.parseProcessingInstruction = void 0;
|
|
19
|
+
const json_schema_1 = require("@manuscripts/json-schema");
|
|
19
20
|
const uuid_1 = require("uuid");
|
|
20
21
|
const transformer_1 = require("../../transformer");
|
|
21
22
|
const DEFAULT_ANNOTATION_COLOR = 'rgb(250, 224, 150)';
|
|
@@ -63,6 +64,25 @@ const insertToken = (doc, processingInstructionNode, authorQueriesMap) => {
|
|
|
63
64
|
return parentElement.insertBefore(tokenNode, processingInstructionNode);
|
|
64
65
|
}
|
|
65
66
|
};
|
|
67
|
+
const extractCommentsFromKeywords = (tokens, model, authorQueriesMap, keywordSectionID) => {
|
|
68
|
+
const commentAnnotations = [];
|
|
69
|
+
const name = model.name;
|
|
70
|
+
const filteredTokens = filterAndSortTokens(tokens, name);
|
|
71
|
+
let content = name;
|
|
72
|
+
for (const token of filteredTokens) {
|
|
73
|
+
content = name.replace(token, '');
|
|
74
|
+
const query = authorQueriesMap.get(token);
|
|
75
|
+
const commentAnnotation = (0, transformer_1.buildComment)(keywordSectionID !== null && keywordSectionID !== void 0 ? keywordSectionID : (0, uuid_1.v4)(), `${query}`, undefined, [(0, transformer_1.buildContribution)(DEFAULT_PROFILE_ID)], DEFAULT_ANNOTATION_COLOR);
|
|
76
|
+
model['name'] = content;
|
|
77
|
+
commentAnnotations.push(commentAnnotation);
|
|
78
|
+
}
|
|
79
|
+
return commentAnnotations;
|
|
80
|
+
};
|
|
81
|
+
function getKeywordSectionID(manuscriptModels) {
|
|
82
|
+
const sections = manuscriptModels.filter((model) => model.objectType === json_schema_1.ObjectTypes.Section);
|
|
83
|
+
const keywordSection = sections.find((section) => section.category === 'MPSectionCategory:keywords');
|
|
84
|
+
return keywordSection ? keywordSection._id : undefined;
|
|
85
|
+
}
|
|
66
86
|
const createComments = (authorQueriesMap, manuscriptModels) => {
|
|
67
87
|
const tokens = [...authorQueriesMap.keys()];
|
|
68
88
|
const commentAnnotations = [];
|
|
@@ -71,10 +91,20 @@ const createComments = (authorQueriesMap, manuscriptModels) => {
|
|
|
71
91
|
const comments = addCommentsFromMarkedProcessingInstructions(tokens, model, authorQueriesMap);
|
|
72
92
|
commentAnnotations.push(...comments);
|
|
73
93
|
}
|
|
94
|
+
else if ((0, transformer_1.isKeyword)(model)) {
|
|
95
|
+
const keywordSectionID = getKeywordSectionID(manuscriptModels);
|
|
96
|
+
const comments = extractCommentsFromKeywords(tokens, model, authorQueriesMap, keywordSectionID);
|
|
97
|
+
commentAnnotations.push(...comments);
|
|
98
|
+
}
|
|
74
99
|
}
|
|
75
100
|
return commentAnnotations;
|
|
76
101
|
};
|
|
77
102
|
exports.createComments = createComments;
|
|
103
|
+
function filterAndSortTokens(tokens, content) {
|
|
104
|
+
return tokens
|
|
105
|
+
.filter((token) => content.indexOf(token) >= 0)
|
|
106
|
+
.sort((a, b) => content.indexOf(a) - content.indexOf(b));
|
|
107
|
+
}
|
|
78
108
|
const addCommentsFromMarkedProcessingInstructions = (tokens, model, authorQueriesMap) => {
|
|
79
109
|
const commentAnnotations = [];
|
|
80
110
|
for (const field of ['contents', 'caption', 'title']) {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.isCommentAnnotation = exports.isUserProfile = exports.isTable = exports.isManuscript = exports.isFigure = exports.hasObjectType = exports.isManuscriptModel = exports.manuscriptObjects = exports.elementObjects = exports.ExtraObjectTypes = void 0;
|
|
18
|
+
exports.isKeyword = exports.isCommentAnnotation = exports.isUserProfile = exports.isTable = exports.isManuscript = exports.isFigure = exports.hasObjectType = exports.isManuscriptModel = exports.manuscriptObjects = exports.elementObjects = exports.ExtraObjectTypes = void 0;
|
|
19
19
|
const json_schema_1 = require("@manuscripts/json-schema");
|
|
20
20
|
var ExtraObjectTypes;
|
|
21
21
|
(function (ExtraObjectTypes) {
|
|
@@ -55,3 +55,4 @@ exports.isManuscript = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Manu
|
|
|
55
55
|
exports.isTable = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Table);
|
|
56
56
|
exports.isUserProfile = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.UserProfile);
|
|
57
57
|
exports.isCommentAnnotation = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.CommentAnnotation);
|
|
58
|
+
exports.isKeyword = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Keyword);
|
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { ObjectTypes, } from '@manuscripts/json-schema';
|
|
16
17
|
import { v4 as uuidv4 } from 'uuid';
|
|
17
|
-
import { buildComment, buildContribution, isCommentAnnotation, isHighlightableModel, } from '../../transformer';
|
|
18
|
+
import { buildComment, buildContribution, isCommentAnnotation, isHighlightableModel, isKeyword, } from '../../transformer';
|
|
18
19
|
const DEFAULT_ANNOTATION_COLOR = 'rgb(250, 224, 150)';
|
|
19
20
|
const DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
|
|
20
21
|
export const parseProcessingInstruction = (node) => {
|
|
@@ -58,6 +59,25 @@ const insertToken = (doc, processingInstructionNode, authorQueriesMap) => {
|
|
|
58
59
|
return parentElement.insertBefore(tokenNode, processingInstructionNode);
|
|
59
60
|
}
|
|
60
61
|
};
|
|
62
|
+
const extractCommentsFromKeywords = (tokens, model, authorQueriesMap, keywordSectionID) => {
|
|
63
|
+
const commentAnnotations = [];
|
|
64
|
+
const name = model.name;
|
|
65
|
+
const filteredTokens = filterAndSortTokens(tokens, name);
|
|
66
|
+
let content = name;
|
|
67
|
+
for (const token of filteredTokens) {
|
|
68
|
+
content = name.replace(token, '');
|
|
69
|
+
const query = authorQueriesMap.get(token);
|
|
70
|
+
const commentAnnotation = buildComment(keywordSectionID !== null && keywordSectionID !== void 0 ? keywordSectionID : uuidv4(), `${query}`, undefined, [buildContribution(DEFAULT_PROFILE_ID)], DEFAULT_ANNOTATION_COLOR);
|
|
71
|
+
model['name'] = content;
|
|
72
|
+
commentAnnotations.push(commentAnnotation);
|
|
73
|
+
}
|
|
74
|
+
return commentAnnotations;
|
|
75
|
+
};
|
|
76
|
+
function getKeywordSectionID(manuscriptModels) {
|
|
77
|
+
const sections = manuscriptModels.filter((model) => model.objectType === ObjectTypes.Section);
|
|
78
|
+
const keywordSection = sections.find((section) => section.category === 'MPSectionCategory:keywords');
|
|
79
|
+
return keywordSection ? keywordSection._id : undefined;
|
|
80
|
+
}
|
|
61
81
|
export const createComments = (authorQueriesMap, manuscriptModels) => {
|
|
62
82
|
const tokens = [...authorQueriesMap.keys()];
|
|
63
83
|
const commentAnnotations = [];
|
|
@@ -66,9 +86,19 @@ export const createComments = (authorQueriesMap, manuscriptModels) => {
|
|
|
66
86
|
const comments = addCommentsFromMarkedProcessingInstructions(tokens, model, authorQueriesMap);
|
|
67
87
|
commentAnnotations.push(...comments);
|
|
68
88
|
}
|
|
89
|
+
else if (isKeyword(model)) {
|
|
90
|
+
const keywordSectionID = getKeywordSectionID(manuscriptModels);
|
|
91
|
+
const comments = extractCommentsFromKeywords(tokens, model, authorQueriesMap, keywordSectionID);
|
|
92
|
+
commentAnnotations.push(...comments);
|
|
93
|
+
}
|
|
69
94
|
}
|
|
70
95
|
return commentAnnotations;
|
|
71
96
|
};
|
|
97
|
+
function filterAndSortTokens(tokens, content) {
|
|
98
|
+
return tokens
|
|
99
|
+
.filter((token) => content.indexOf(token) >= 0)
|
|
100
|
+
.sort((a, b) => content.indexOf(a) - content.indexOf(b));
|
|
101
|
+
}
|
|
72
102
|
const addCommentsFromMarkedProcessingInstructions = (tokens, model, authorQueriesMap) => {
|
|
73
103
|
const commentAnnotations = [];
|
|
74
104
|
for (const field of ['contents', 'caption', 'title']) {
|
|
@@ -50,3 +50,4 @@ export const isManuscript = hasObjectType(ObjectTypes.Manuscript);
|
|
|
50
50
|
export const isTable = hasObjectType(ObjectTypes.Table);
|
|
51
51
|
export const isUserProfile = hasObjectType(ObjectTypes.UserProfile);
|
|
52
52
|
export const isCommentAnnotation = hasObjectType(ObjectTypes.CommentAnnotation);
|
|
53
|
+
export const isKeyword = hasObjectType(ObjectTypes.Keyword);
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { CommentAnnotation, Figure, Manuscript, Model, ObjectTypes, Table } from '@manuscripts/json-schema';
|
|
16
|
+
import { CommentAnnotation, Figure, Keyword, Manuscript, Model, ObjectTypes, Table } from '@manuscripts/json-schema';
|
|
17
17
|
import { ManuscriptModel, UserProfileWithAvatar } from './models';
|
|
18
18
|
export declare enum ExtraObjectTypes {
|
|
19
19
|
PlaceholderElement = "MPPlaceholderElement"
|
|
@@ -27,3 +27,4 @@ export declare const isManuscript: (model: Model) => model is Manuscript;
|
|
|
27
27
|
export declare const isTable: (model: Model) => model is Table;
|
|
28
28
|
export declare const isUserProfile: (model: Model) => model is UserProfileWithAvatar;
|
|
29
29
|
export declare const isCommentAnnotation: (model: Model) => model is CommentAnnotation;
|
|
30
|
+
export declare const isKeyword: (model: Model) => model is Keyword;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/transform",
|
|
3
3
|
"description": "ProseMirror transformer for Manuscripts applications",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.5-LEAN-2066-41002a3",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|