@manuscripts/body-editor 1.11.8 → 1.13.0

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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCommentMarker = exports.getCommentRange = exports.getCommentKey = exports.isNodeComment = void 0;
4
- const isNodeComment = (comment) => !comment.range;
4
+ const isNodeComment = (c) => !c.range;
5
5
  exports.isNodeComment = isNodeComment;
6
6
  const getCommentKey = (comment, range, target) => {
7
7
  if (!range) {
@@ -90,13 +90,12 @@ const findCommentRanges = (doc) => {
90
90
  return ranges;
91
91
  };
92
92
  const findComments = (doc) => {
93
- const nodes = (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.comment);
93
+ const comments = (0, prosemirror_utils_1.findChildrenByType)(doc, transform_1.schema.nodes.comment);
94
94
  const commentsByTarget = new Map();
95
- for (const { node } of nodes) {
96
- const attrs = node.attrs;
97
- const targetID = attrs.target;
98
- const comments = commentsByTarget.get(targetID) || [];
99
- commentsByTarget.set(targetID, [...comments, attrs]);
95
+ for (const comment of comments) {
96
+ const targetID = comment.node.attrs.target;
97
+ const list = commentsByTarget.get(targetID) || [];
98
+ commentsByTarget.set(targetID, [...list, comment]);
100
99
  }
101
100
  return commentsByTarget;
102
101
  };
@@ -118,27 +117,32 @@ const buildPluginState = (doc, selection) => {
118
117
  const nodeComments = [];
119
118
  const highlightComments = [];
120
119
  const pointComments = [];
121
- for (const attrs of comments) {
120
+ comments
121
+ .map((c) => {
122
+ const attrs = c.node.attrs;
122
123
  const id = attrs.id;
123
124
  const range = ranges.get(id);
124
125
  const key = (0, comments_1.getCommentKey)(attrs, range, node);
125
- const comment = {
126
+ return {
126
127
  key,
127
- attrs,
128
+ node: c.node,
129
+ pos: c.pos,
128
130
  target,
129
131
  range,
130
132
  };
131
- allComments.push(comment);
132
- if (!comment.range) {
133
- nodeComments.push(comment);
133
+ })
134
+ .forEach((c) => {
135
+ allComments.push(c);
136
+ if (!c.range) {
137
+ nodeComments.push(c);
134
138
  }
135
- else if (comment.range.size) {
136
- highlightComments.push(comment);
139
+ else if (c.range.size) {
140
+ highlightComments.push(c);
137
141
  }
138
142
  else {
139
- pointComments.push(comment);
143
+ pointComments.push(c);
140
144
  }
141
- }
145
+ });
142
146
  for (const comment of highlightComments) {
143
147
  const key = comment.key;
144
148
  const range = comment.range;
@@ -161,7 +165,7 @@ const buildPluginState = (doc, selection) => {
161
165
  });
162
166
  return {
163
167
  decorations: prosemirror_view_1.DecorationSet.create(doc, decorations),
164
- comments: new Map(allComments.map((c) => [c.attrs.id, c])),
168
+ comments: new Map(allComments.map((c) => [c.node.attrs.id, c])),
165
169
  commentsByKey: groupByKey(allComments),
166
170
  selection,
167
171
  };
@@ -1,4 +1,4 @@
1
- export const isNodeComment = (comment) => !comment.range;
1
+ export const isNodeComment = (c) => !c.range;
2
2
  export const getCommentKey = (comment, range, target) => {
3
3
  if (!range) {
4
4
  return target.attrs.id;
@@ -85,13 +85,12 @@ const findCommentRanges = (doc) => {
85
85
  return ranges;
86
86
  };
87
87
  const findComments = (doc) => {
88
- const nodes = findChildrenByType(doc, schema.nodes.comment);
88
+ const comments = findChildrenByType(doc, schema.nodes.comment);
89
89
  const commentsByTarget = new Map();
90
- for (const { node } of nodes) {
91
- const attrs = node.attrs;
92
- const targetID = attrs.target;
93
- const comments = commentsByTarget.get(targetID) || [];
94
- commentsByTarget.set(targetID, [...comments, attrs]);
90
+ for (const comment of comments) {
91
+ const targetID = comment.node.attrs.target;
92
+ const list = commentsByTarget.get(targetID) || [];
93
+ commentsByTarget.set(targetID, [...list, comment]);
95
94
  }
96
95
  return commentsByTarget;
97
96
  };
@@ -113,27 +112,32 @@ const buildPluginState = (doc, selection) => {
113
112
  const nodeComments = [];
114
113
  const highlightComments = [];
115
114
  const pointComments = [];
116
- for (const attrs of comments) {
115
+ comments
116
+ .map((c) => {
117
+ const attrs = c.node.attrs;
117
118
  const id = attrs.id;
118
119
  const range = ranges.get(id);
119
120
  const key = getCommentKey(attrs, range, node);
120
- const comment = {
121
+ return {
121
122
  key,
122
- attrs,
123
+ node: c.node,
124
+ pos: c.pos,
123
125
  target,
124
126
  range,
125
127
  };
126
- allComments.push(comment);
127
- if (!comment.range) {
128
- nodeComments.push(comment);
128
+ })
129
+ .forEach((c) => {
130
+ allComments.push(c);
131
+ if (!c.range) {
132
+ nodeComments.push(c);
129
133
  }
130
- else if (comment.range.size) {
131
- highlightComments.push(comment);
134
+ else if (c.range.size) {
135
+ highlightComments.push(c);
132
136
  }
133
137
  else {
134
- pointComments.push(comment);
138
+ pointComments.push(c);
135
139
  }
136
- }
140
+ });
137
141
  for (const comment of highlightComments) {
138
142
  const key = comment.key;
139
143
  const range = comment.range;
@@ -156,7 +160,7 @@ const buildPluginState = (doc, selection) => {
156
160
  });
157
161
  return {
158
162
  decorations: DecorationSet.create(doc, decorations),
159
- comments: new Map(allComments.map((c) => [c.attrs.id, c])),
163
+ comments: new Map(allComments.map((c) => [c.node.attrs.id, c])),
160
164
  commentsByKey: groupByKey(allComments),
161
165
  selection,
162
166
  };
@@ -5,12 +5,14 @@ export type HighlightMarkerAttrs = HighlightMarkerNode['attrs'];
5
5
  export type Comment = NodeComment | InlineComment;
6
6
  export type NodeComment = {
7
7
  key: CommentKey;
8
- attrs: CommentAttrs;
8
+ node: CommentNode;
9
+ pos: number;
9
10
  target: NodeWithPos;
10
11
  };
11
12
  export type InlineComment = {
12
13
  key: CommentKey;
13
- attrs: CommentAttrs;
14
+ node: CommentNode;
15
+ pos: number;
14
16
  target: NodeWithPos;
15
17
  range: CommentRange;
16
18
  };
@@ -24,7 +26,7 @@ export type CommentSelection = {
24
26
  id: string;
25
27
  isNew: boolean;
26
28
  };
27
- export declare const isNodeComment: (comment: any) => comment is NodeComment;
29
+ export declare const isNodeComment: (c: any) => c is NodeComment;
28
30
  export declare const getCommentKey: (comment: CommentAttrs, range: CommentRange | undefined, target: ManuscriptNode) => CommentKey;
29
31
  export declare const getCommentRange: (comment: CommentAttrs) => {
30
32
  pos: number;
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": "1.11.8",
4
+ "version": "1.13.0",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -30,7 +30,7 @@
30
30
  "@iarna/word-count": "^1.1.2",
31
31
  "@manuscripts/json-schema": "2.2.8",
32
32
  "@manuscripts/library": "1.3.7",
33
- "@manuscripts/style-guide": "1.12.16",
33
+ "@manuscripts/style-guide": "1.13.0",
34
34
  "@manuscripts/track-changes-plugin": "1.7.13",
35
35
  "@manuscripts/transform": "2.3.9",
36
36
  "astrocite-eutils": "^0.16.4",