@manuscripts/transform 1.1.4 → 1.1.5-LEAN-2066-90da5e5

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.
@@ -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']) {
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.keyword = void 0;
19
19
  exports.keyword = {
20
20
  atom: true,
21
- content: 'text*',
21
+ content: 'inline*',
22
22
  attrs: {
23
23
  id: { default: '' },
24
24
  contents: { default: '' },
@@ -37,6 +37,7 @@ exports.keywordsSection = {
37
37
  id: keywordsSectionNode.attrs.id,
38
38
  class: 'keywords',
39
39
  spellcheck: 'false',
40
+ contenteditable: false,
40
41
  },
41
42
  0,
42
43
  ];
@@ -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']) {
@@ -15,7 +15,7 @@
15
15
  */
16
16
  export const keyword = {
17
17
  atom: true,
18
- content: 'text*',
18
+ content: 'inline*',
19
19
  attrs: {
20
20
  id: { default: '' },
21
21
  contents: { default: '' },
@@ -34,6 +34,7 @@ export const keywordsSection = {
34
34
  id: keywordsSectionNode.attrs.id,
35
35
  class: 'keywords',
36
36
  spellcheck: 'false',
37
+ contenteditable: false,
37
38
  },
38
39
  0,
39
40
  ];
@@ -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",
4
+ "version": "1.1.5-LEAN-2066-90da5e5",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",