@manuscripts/body-editor 1.7.32 → 1.7.33

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.
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.isHidden = exports.getAttrsTrackingButton = exports.getActualAttrs = exports.isTracked = exports.getChangeClasses = exports.isPendingSetAttrs = exports.isPending = exports.isPendingInsert = exports.isDeleted = exports.isRejectedInsert = void 0;
18
+ exports.sanitizeAttrsChange = exports.isHidden = exports.getAttrsTrackingButton = exports.getActualAttrs = exports.isTracked = exports.getChangeClasses = exports.isPendingSetAttrs = exports.isPending = exports.isPendingInsert = exports.isDeleted = exports.isRejectedInsert = void 0;
19
19
  const assets_1 = require("../assets");
20
20
  function isRejectedInsert(node) {
21
21
  if (node.attrs.dataTracked) {
@@ -103,3 +103,14 @@ function isHidden(node) {
103
103
  return isDeleted(node) || isRejectedInsert(node);
104
104
  }
105
105
  exports.isHidden = isHidden;
106
+ function sanitizeAttrsChange(newAttr, currentAttrs) {
107
+ return Object.keys(newAttr).reduce((acc, attr) => {
108
+ const key = attr;
109
+ if (!currentAttrs[key] && currentAttrs[key] !== 0 && !newAttr[key]) {
110
+ return acc;
111
+ }
112
+ acc[key] = newAttr[key];
113
+ return acc;
114
+ }, {});
115
+ }
116
+ exports.sanitizeAttrsChange = sanitizeAttrsChange;
@@ -38,7 +38,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
38
38
  return result;
39
39
  };
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.deleteNode = exports.updateNodeAttrs = exports.updateNode = exports.findChildrenAttrsByType = exports.findChildrenByType = exports.findChildByType = exports.findChildByID = void 0;
41
+ exports.deleteNode = exports.updateNodeAttrs = exports.findChildrenAttrsByType = exports.findChildrenByType = exports.findChildByType = exports.findChildByID = void 0;
42
42
  const transform_1 = require("@manuscripts/transform");
43
43
  const utils = __importStar(require("prosemirror-utils"));
44
44
  const track_changes_utils_1 = require("./track-changes-utils");
@@ -68,22 +68,20 @@ const findChildrenAttrsByType = (view, type) => {
68
68
  return (0, exports.findChildrenByType)(view, type).map((n) => (0, track_changes_utils_1.getActualAttrs)(n.node));
69
69
  };
70
70
  exports.findChildrenAttrsByType = findChildrenAttrsByType;
71
- const updateNode = (view, node) => {
72
- (0, exports.updateNodeAttrs)(view, node.type, node.attrs);
73
- };
74
- exports.updateNode = updateNode;
75
71
  const updateNodeAttrs = (view, type, attrs) => {
76
- const copy = Object.assign({}, attrs);
77
- delete copy.dataTracked;
78
72
  const child = (0, exports.findChildByID)(view, attrs.id);
79
73
  if (child) {
74
+ const copy = (0, track_changes_utils_1.sanitizeAttrsChange)(attrs, child.node.attrs);
75
+ delete copy.dataTracked;
80
76
  const pos = child.pos;
81
- const tr = view.state.tr.setNodeMarkup(pos, undefined, attrs);
77
+ const tr = view.state.tr.setNodeMarkup(pos, undefined, copy);
82
78
  if (metaNodeTypes.includes(type)) {
83
79
  tr.setMeta(updateMetaNode, true);
84
80
  }
85
81
  view.dispatch(tr);
82
+ return true;
86
83
  }
84
+ return false;
87
85
  };
88
86
  exports.updateNodeAttrs = updateNodeAttrs;
89
87
  const deleteNode = (view, id) => {
@@ -178,7 +178,7 @@ class BibliographyElementBlockView extends block_view_1.default {
178
178
  };
179
179
  this.handleSave = (item) => {
180
180
  const node = this.decoder.decode(item);
181
- (0, view_1.updateNode)(this.view, node);
181
+ (0, view_1.updateNodeAttrs)(this.view, node.type, node.attrs);
182
182
  };
183
183
  this.handleDelete = (item) => {
184
184
  (0, view_1.deleteNode)(this.view, item._id);
@@ -191,12 +191,10 @@ class ContributorsView extends block_view_1.default {
191
191
  this.container.appendChild(this.popper);
192
192
  };
193
193
  this.handleSaveAuthor = (author) => {
194
- if (!(0, view_1.findChildByID)(this.view, author.id)) {
194
+ const update = (0, view_1.updateNodeAttrs)(this.view, transform_1.schema.nodes.contributor, author);
195
+ if (!update) {
195
196
  this.insertAuthorNode(author);
196
197
  }
197
- else {
198
- (0, view_1.updateNodeAttrs)(this.view, transform_1.schema.nodes.contributor, author);
199
- }
200
198
  };
201
199
  this.handleDeleteAuthor = (author) => {
202
200
  (0, view_1.deleteNode)(this.view, author.id);
@@ -90,3 +90,13 @@ export const getAttrsTrackingButton = (changeID) => {
90
90
  export function isHidden(node) {
91
91
  return isDeleted(node) || isRejectedInsert(node);
92
92
  }
93
+ export function sanitizeAttrsChange(newAttr, currentAttrs) {
94
+ return Object.keys(newAttr).reduce((acc, attr) => {
95
+ const key = attr;
96
+ if (!currentAttrs[key] && currentAttrs[key] !== 0 && !newAttr[key]) {
97
+ return acc;
98
+ }
99
+ acc[key] = newAttr[key];
100
+ return acc;
101
+ }, {});
102
+ }
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { schema, } from '@manuscripts/transform';
17
17
  import * as utils from 'prosemirror-utils';
18
- import { getActualAttrs, isHidden } from './track-changes-utils';
18
+ import { getActualAttrs, isHidden, sanitizeAttrsChange, } from './track-changes-utils';
19
19
  const metaNodeTypes = [
20
20
  schema.nodes.bibliography_item,
21
21
  schema.nodes.affiliation,
@@ -38,21 +38,20 @@ export const findChildrenByType = (view, type) => {
38
38
  export const findChildrenAttrsByType = (view, type) => {
39
39
  return findChildrenByType(view, type).map((n) => getActualAttrs(n.node));
40
40
  };
41
- export const updateNode = (view, node) => {
42
- updateNodeAttrs(view, node.type, node.attrs);
43
- };
44
41
  export const updateNodeAttrs = (view, type, attrs) => {
45
- const copy = Object.assign({}, attrs);
46
- delete copy.dataTracked;
47
42
  const child = findChildByID(view, attrs.id);
48
43
  if (child) {
44
+ const copy = sanitizeAttrsChange(attrs, child.node.attrs);
45
+ delete copy.dataTracked;
49
46
  const pos = child.pos;
50
- const tr = view.state.tr.setNodeMarkup(pos, undefined, attrs);
47
+ const tr = view.state.tr.setNodeMarkup(pos, undefined, copy);
51
48
  if (metaNodeTypes.includes(type)) {
52
49
  tr.setMeta(updateMetaNode, true);
53
50
  }
54
51
  view.dispatch(tr);
52
+ return true;
55
53
  }
54
+ return false;
56
55
  };
57
56
  export const deleteNode = (view, id) => {
58
57
  const child = findChildByID(view, id);
@@ -27,7 +27,7 @@ import { CHANGE_STATUS } from '@manuscripts/track-changes-plugin';
27
27
  import { buildComment, Decoder, } from '@manuscripts/transform';
28
28
  import { sanitize } from '../lib/dompurify';
29
29
  import { getChangeClasses } from '../lib/track-changes-utils';
30
- import { deleteNode, updateNode } from '../lib/view';
30
+ import { deleteNode, updateNodeAttrs } from '../lib/view';
31
31
  import { getBibliographyPluginState } from '../plugins/bibliography';
32
32
  import { commentAnnotation } from '../plugins/comment_annotation';
33
33
  import { CLEAR_SUGGESTION_ID, selectedSuggestionKey, SET_SUGGESTION_ID, } from '../plugins/selected-suggestion-ui';
@@ -172,7 +172,7 @@ export class BibliographyElementBlockView extends BlockView {
172
172
  };
173
173
  this.handleSave = (item) => {
174
174
  const node = this.decoder.decode(item);
175
- updateNode(this.view, node);
175
+ updateNodeAttrs(this.view, node.type, node.attrs);
176
176
  };
177
177
  this.handleDelete = (item) => {
178
178
  deleteNode(this.view, item._id);
@@ -185,12 +185,10 @@ export class ContributorsView extends BlockView {
185
185
  this.container.appendChild(this.popper);
186
186
  };
187
187
  this.handleSaveAuthor = (author) => {
188
- if (!findChildByID(this.view, author.id)) {
188
+ const update = updateNodeAttrs(this.view, schema.nodes.contributor, author);
189
+ if (!update) {
189
190
  this.insertAuthorNode(author);
190
191
  }
191
- else {
192
- updateNodeAttrs(this.view, schema.nodes.contributor, author);
193
- }
194
192
  };
195
193
  this.handleDeleteAuthor = (author) => {
196
194
  deleteNode(this.view, author.id);
@@ -26,3 +26,4 @@ export declare function isTracked(node: ProsemirrorNode): boolean;
26
26
  export declare function getActualAttrs<T extends ManuscriptNode>(node: T): T["attrs"];
27
27
  export declare const getAttrsTrackingButton: (changeID: string) => HTMLButtonElement;
28
28
  export declare function isHidden(node: ProsemirrorNode): boolean;
29
+ export declare function sanitizeAttrsChange<T extends ProsemirrorNode>(newAttr: T['attrs'], currentAttrs: T['attrs']): T["attrs"];
@@ -13,13 +13,12 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { ManuscriptEditorView, ManuscriptNode, ManuscriptNodeType } from '@manuscripts/transform';
16
+ import { ManuscriptEditorView, ManuscriptNodeType } from '@manuscripts/transform';
17
17
  import { Attrs } from 'prosemirror-model';
18
18
  import * as utils from 'prosemirror-utils';
19
19
  export declare const findChildByID: (view: ManuscriptEditorView, id: string) => utils.NodeWithPos | undefined;
20
20
  export declare const findChildByType: (view: ManuscriptEditorView, type: ManuscriptNodeType) => utils.NodeWithPos | undefined;
21
21
  export declare const findChildrenByType: (view: ManuscriptEditorView, type: ManuscriptNodeType) => utils.NodeWithPos[];
22
22
  export declare const findChildrenAttrsByType: <T extends Attrs>(view: ManuscriptEditorView, type: ManuscriptNodeType) => T[];
23
- export declare const updateNode: (view: ManuscriptEditorView, node: ManuscriptNode) => void;
24
- export declare const updateNodeAttrs: (view: ManuscriptEditorView, type: ManuscriptNodeType, attrs: Attrs) => void;
23
+ export declare const updateNodeAttrs: (view: ManuscriptEditorView, type: ManuscriptNodeType, attrs: Attrs) => boolean;
25
24
  export declare const deleteNode: (view: ManuscriptEditorView, id: string) => void;
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.7.32",
4
+ "version": "1.7.33",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",