@manuscripts/transform 1.1.2 → 1.1.3-LEAN-2066
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 +24 -0
- package/dist/cjs/schema/nodes/comment.js +3 -0
- package/dist/cjs/transformer/decode.js +3 -0
- package/dist/cjs/transformer/encode.js +4 -2
- package/dist/cjs/transformer/object-types.js +2 -1
- package/dist/es/jats/importer/jats-comments.js +25 -1
- package/dist/es/schema/nodes/comment.js +3 -0
- package/dist/es/transformer/decode.js +3 -0
- package/dist/es/transformer/encode.js +4 -2
- package/dist/es/transformer/object-types.js +1 -0
- package/dist/types/schema/nodes/comment.d.ts +4 -0
- package/dist/types/transformer/object-types.d.ts +2 -1
- package/package.json +1 -1
|
@@ -63,6 +63,21 @@ const insertToken = (doc, processingInstructionNode, authorQueriesMap) => {
|
|
|
63
63
|
return parentElement.insertBefore(tokenNode, processingInstructionNode);
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
|
+
const extractCommentsFromKeywords = (tokens, model, authorQueriesMap) => {
|
|
67
|
+
var _a;
|
|
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)((_a = model.containedGroup) !== null && _a !== void 0 ? _a : (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
|
+
};
|
|
66
81
|
const createComments = (authorQueriesMap, manuscriptModels) => {
|
|
67
82
|
const tokens = [...authorQueriesMap.keys()];
|
|
68
83
|
const commentAnnotations = [];
|
|
@@ -71,10 +86,19 @@ const createComments = (authorQueriesMap, manuscriptModels) => {
|
|
|
71
86
|
const comments = addCommentsFromMarkedProcessingInstructions(tokens, model, authorQueriesMap);
|
|
72
87
|
commentAnnotations.push(...comments);
|
|
73
88
|
}
|
|
89
|
+
else if ((0, transformer_1.isKeyword)(model)) {
|
|
90
|
+
const comments = extractCommentsFromKeywords(tokens, model, authorQueriesMap);
|
|
91
|
+
commentAnnotations.push(...comments);
|
|
92
|
+
}
|
|
74
93
|
}
|
|
75
94
|
return commentAnnotations;
|
|
76
95
|
};
|
|
77
96
|
exports.createComments = createComments;
|
|
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
|
+
}
|
|
78
102
|
const addCommentsFromMarkedProcessingInstructions = (tokens, model, authorQueriesMap) => {
|
|
79
103
|
const commentAnnotations = [];
|
|
80
104
|
for (const field of ['contents', 'caption', 'title']) {
|
|
@@ -362,6 +362,9 @@ const encoders = {
|
|
|
362
362
|
selector: node.attrs.selector,
|
|
363
363
|
target: node.attrs.target,
|
|
364
364
|
contents: node.attrs.contents,
|
|
365
|
+
resolved: node.attrs.resolved,
|
|
366
|
+
contributions: node.attrs.contributions,
|
|
367
|
+
originalText: node.attrs.originalText,
|
|
365
368
|
}),
|
|
366
369
|
footnote: (node, parent) => ({
|
|
367
370
|
containingObject: parent.attrs.id,
|
|
@@ -532,12 +535,11 @@ const encode = (node) => {
|
|
|
532
535
|
if (placeholders.includes(child.type.name)) {
|
|
533
536
|
return;
|
|
534
537
|
}
|
|
535
|
-
const { model
|
|
538
|
+
const { model } = (0, exports.modelFromNode)(child, parent, path, priority);
|
|
536
539
|
if (models.has(model._id)) {
|
|
537
540
|
throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
|
|
538
541
|
}
|
|
539
542
|
models.set(model._id, model);
|
|
540
|
-
commentAnnotationsMap.forEach((val, key) => models.set(key, val));
|
|
541
543
|
child.forEach(addModel(path.concat(child.attrs.id), child));
|
|
542
544
|
};
|
|
543
545
|
node.forEach((cNode) => {
|
|
@@ -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);
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { v4 as uuidv4 } from 'uuid';
|
|
17
|
-
import { buildComment, buildContribution, isCommentAnnotation, isHighlightableModel, } from '../../transformer';
|
|
17
|
+
import { buildComment, buildContribution, isCommentAnnotation, isHighlightableModel, isKeyword, } from '../../transformer';
|
|
18
18
|
const DEFAULT_ANNOTATION_COLOR = 'rgb(250, 224, 150)';
|
|
19
19
|
const DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
|
|
20
20
|
export const parseProcessingInstruction = (node) => {
|
|
@@ -58,6 +58,21 @@ const insertToken = (doc, processingInstructionNode, authorQueriesMap) => {
|
|
|
58
58
|
return parentElement.insertBefore(tokenNode, processingInstructionNode);
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
|
+
const extractCommentsFromKeywords = (tokens, model, authorQueriesMap) => {
|
|
62
|
+
var _a;
|
|
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((_a = model.containedGroup) !== null && _a !== void 0 ? _a : uuidv4(), `${query}`, undefined, [buildContribution(DEFAULT_PROFILE_ID)], DEFAULT_ANNOTATION_COLOR);
|
|
71
|
+
model['name'] = content;
|
|
72
|
+
commentAnnotations.push(commentAnnotation);
|
|
73
|
+
}
|
|
74
|
+
return commentAnnotations;
|
|
75
|
+
};
|
|
61
76
|
export const createComments = (authorQueriesMap, manuscriptModels) => {
|
|
62
77
|
const tokens = [...authorQueriesMap.keys()];
|
|
63
78
|
const commentAnnotations = [];
|
|
@@ -66,9 +81,18 @@ export const createComments = (authorQueriesMap, manuscriptModels) => {
|
|
|
66
81
|
const comments = addCommentsFromMarkedProcessingInstructions(tokens, model, authorQueriesMap);
|
|
67
82
|
commentAnnotations.push(...comments);
|
|
68
83
|
}
|
|
84
|
+
else if (isKeyword(model)) {
|
|
85
|
+
const comments = extractCommentsFromKeywords(tokens, model, authorQueriesMap);
|
|
86
|
+
commentAnnotations.push(...comments);
|
|
87
|
+
}
|
|
69
88
|
}
|
|
70
89
|
return commentAnnotations;
|
|
71
90
|
};
|
|
91
|
+
function filterAndSortTokens(tokens, content) {
|
|
92
|
+
return tokens
|
|
93
|
+
.filter((token) => content.indexOf(token) >= 0)
|
|
94
|
+
.sort((a, b) => content.indexOf(a) - content.indexOf(b));
|
|
95
|
+
}
|
|
72
96
|
const addCommentsFromMarkedProcessingInstructions = (tokens, model, authorQueriesMap) => {
|
|
73
97
|
const commentAnnotations = [];
|
|
74
98
|
for (const field of ['contents', 'caption', 'title']) {
|
|
@@ -354,6 +354,9 @@ const encoders = {
|
|
|
354
354
|
selector: node.attrs.selector,
|
|
355
355
|
target: node.attrs.target,
|
|
356
356
|
contents: node.attrs.contents,
|
|
357
|
+
resolved: node.attrs.resolved,
|
|
358
|
+
contributions: node.attrs.contributions,
|
|
359
|
+
originalText: node.attrs.originalText,
|
|
357
360
|
}),
|
|
358
361
|
footnote: (node, parent) => ({
|
|
359
362
|
containingObject: parent.attrs.id,
|
|
@@ -523,12 +526,11 @@ export const encode = (node) => {
|
|
|
523
526
|
if (placeholders.includes(child.type.name)) {
|
|
524
527
|
return;
|
|
525
528
|
}
|
|
526
|
-
const { model
|
|
529
|
+
const { model } = modelFromNode(child, parent, path, priority);
|
|
527
530
|
if (models.has(model._id)) {
|
|
528
531
|
throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
|
|
529
532
|
}
|
|
530
533
|
models.set(model._id, model);
|
|
531
|
-
commentAnnotationsMap.forEach((val, key) => models.set(key, val));
|
|
532
534
|
child.forEach(addModel(path.concat(child.attrs.id), child));
|
|
533
535
|
};
|
|
534
536
|
node.forEach((cNode) => {
|
|
@@ -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,6 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { Contribution } from '@manuscripts/json-schema';
|
|
16
17
|
import { NodeSpec } from 'prosemirror-model';
|
|
17
18
|
import { ManuscriptNode } from '../types';
|
|
18
19
|
interface Attrs {
|
|
@@ -23,6 +24,9 @@ interface Attrs {
|
|
|
23
24
|
from: number;
|
|
24
25
|
to: number;
|
|
25
26
|
};
|
|
27
|
+
resolved?: boolean;
|
|
28
|
+
contributions?: Contribution[];
|
|
29
|
+
originalText?: string;
|
|
26
30
|
}
|
|
27
31
|
export interface CommentNode extends ManuscriptNode {
|
|
28
32
|
attrs: Attrs;
|
|
@@ -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.3-LEAN-2066",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|