@manuscripts/body-editor 1.7.32 → 1.7.34
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/lib/track-changes-utils.js +12 -1
- package/dist/cjs/lib/view.js +6 -8
- package/dist/cjs/views/bibliography_element.js +8 -3
- package/dist/cjs/views/contributors.js +2 -4
- package/dist/es/lib/track-changes-utils.js +10 -0
- package/dist/es/lib/view.js +6 -7
- package/dist/es/views/bibliography_element.js +9 -4
- package/dist/es/views/contributors.js +2 -4
- package/dist/types/lib/track-changes-utils.d.ts +1 -0
- package/dist/types/lib/view.d.ts +2 -3
- package/package.json +2 -2
- package/styles/Editor.css +1 -0
|
@@ -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;
|
package/dist/cjs/lib/view.js
CHANGED
|
@@ -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.
|
|
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,
|
|
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) => {
|
|
@@ -31,6 +31,7 @@ exports.BibliographyElementBlockView = void 0;
|
|
|
31
31
|
const style_guide_1 = require("@manuscripts/style-guide");
|
|
32
32
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
33
33
|
const transform_1 = require("@manuscripts/transform");
|
|
34
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
34
35
|
const dompurify_1 = require("../lib/dompurify");
|
|
35
36
|
const track_changes_utils_1 = require("../lib/track-changes-utils");
|
|
36
37
|
const view_1 = require("../lib/view");
|
|
@@ -95,19 +96,23 @@ class BibliographyElementBlockView extends block_view_1.default {
|
|
|
95
96
|
this.clickedElementId = elementId;
|
|
96
97
|
const isSelectedSuggestion = !!((_a = selected_suggestion_ui_1.selectedSuggestionKey
|
|
97
98
|
.getState(this.view.state)) === null || _a === void 0 ? void 0 : _a.find(this.getPos(), this.getPos() + this.node.nodeSize).length);
|
|
99
|
+
const { tr, doc } = this.view.state;
|
|
100
|
+
tr.setSelection(prosemirror_state_1.NodeSelection.create(doc, this.getPos()));
|
|
98
101
|
if (dataTracked && dataTracked.status !== track_changes_plugin_1.CHANGE_STATUS.rejected) {
|
|
99
|
-
|
|
102
|
+
tr.setMeta(selected_suggestion_ui_1.SET_SUGGESTION_ID, dataTracked.id);
|
|
100
103
|
}
|
|
101
104
|
else {
|
|
102
105
|
if (isSelectedSuggestion) {
|
|
103
|
-
|
|
106
|
+
tr.setMeta(selected_suggestion_ui_1.CLEAR_SUGGESTION_ID, true);
|
|
104
107
|
}
|
|
105
108
|
else {
|
|
106
109
|
this.showContextMenu(elementId);
|
|
107
110
|
}
|
|
108
111
|
}
|
|
112
|
+
this.view.dispatch(tr);
|
|
109
113
|
};
|
|
110
114
|
this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
this.props.popper.destroy();
|
|
111
116
|
const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
|
|
112
117
|
const commentsDecorationSet = comment_annotation_1.commentAnnotation.getState(this.view.state);
|
|
113
118
|
const selectedSuggestion = selected_suggestion_ui_1.selectedSuggestionKey.getState(this.view.state);
|
|
@@ -178,7 +183,7 @@ class BibliographyElementBlockView extends block_view_1.default {
|
|
|
178
183
|
};
|
|
179
184
|
this.handleSave = (item) => {
|
|
180
185
|
const node = this.decoder.decode(item);
|
|
181
|
-
(0, view_1.
|
|
186
|
+
(0, view_1.updateNodeAttrs)(this.view, node.type, node.attrs);
|
|
182
187
|
};
|
|
183
188
|
this.handleDelete = (item) => {
|
|
184
189
|
(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
|
-
|
|
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
|
+
}
|
package/dist/es/lib/view.js
CHANGED
|
@@ -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,
|
|
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);
|
|
@@ -25,9 +25,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
25
25
|
import { ContextMenu } from '@manuscripts/style-guide';
|
|
26
26
|
import { CHANGE_STATUS } from '@manuscripts/track-changes-plugin';
|
|
27
27
|
import { buildComment, Decoder, } from '@manuscripts/transform';
|
|
28
|
+
import { NodeSelection } from 'prosemirror-state';
|
|
28
29
|
import { sanitize } from '../lib/dompurify';
|
|
29
30
|
import { getChangeClasses } from '../lib/track-changes-utils';
|
|
30
|
-
import { deleteNode,
|
|
31
|
+
import { deleteNode, updateNodeAttrs } from '../lib/view';
|
|
31
32
|
import { getBibliographyPluginState } from '../plugins/bibliography';
|
|
32
33
|
import { commentAnnotation } from '../plugins/comment_annotation';
|
|
33
34
|
import { CLEAR_SUGGESTION_ID, selectedSuggestionKey, SET_SUGGESTION_ID, } from '../plugins/selected-suggestion-ui';
|
|
@@ -89,19 +90,23 @@ export class BibliographyElementBlockView extends BlockView {
|
|
|
89
90
|
this.clickedElementId = elementId;
|
|
90
91
|
const isSelectedSuggestion = !!((_a = selectedSuggestionKey
|
|
91
92
|
.getState(this.view.state)) === null || _a === void 0 ? void 0 : _a.find(this.getPos(), this.getPos() + this.node.nodeSize).length);
|
|
93
|
+
const { tr, doc } = this.view.state;
|
|
94
|
+
tr.setSelection(NodeSelection.create(doc, this.getPos()));
|
|
92
95
|
if (dataTracked && dataTracked.status !== CHANGE_STATUS.rejected) {
|
|
93
|
-
|
|
96
|
+
tr.setMeta(SET_SUGGESTION_ID, dataTracked.id);
|
|
94
97
|
}
|
|
95
98
|
else {
|
|
96
99
|
if (isSelectedSuggestion) {
|
|
97
|
-
|
|
100
|
+
tr.setMeta(CLEAR_SUGGESTION_ID, true);
|
|
98
101
|
}
|
|
99
102
|
else {
|
|
100
103
|
this.showContextMenu(elementId);
|
|
101
104
|
}
|
|
102
105
|
}
|
|
106
|
+
this.view.dispatch(tr);
|
|
103
107
|
};
|
|
104
108
|
this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
this.props.popper.destroy();
|
|
105
110
|
const bib = getBibliographyPluginState(this.view.state);
|
|
106
111
|
const commentsDecorationSet = commentAnnotation.getState(this.view.state);
|
|
107
112
|
const selectedSuggestion = selectedSuggestionKey.getState(this.view.state);
|
|
@@ -172,7 +177,7 @@ export class BibliographyElementBlockView extends BlockView {
|
|
|
172
177
|
};
|
|
173
178
|
this.handleSave = (item) => {
|
|
174
179
|
const node = this.decoder.decode(item);
|
|
175
|
-
|
|
180
|
+
updateNodeAttrs(this.view, node.type, node.attrs);
|
|
176
181
|
};
|
|
177
182
|
this.handleDelete = (item) => {
|
|
178
183
|
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
|
-
|
|
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"];
|
package/dist/types/lib/view.d.ts
CHANGED
|
@@ -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,
|
|
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
|
|
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.
|
|
4
|
+
"version": "1.7.34",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -112,4 +112,4 @@
|
|
|
112
112
|
"@types/react": "^17.0.2",
|
|
113
113
|
"prosemirror-tables": "^1.3.5"
|
|
114
114
|
}
|
|
115
|
-
}
|
|
115
|
+
}
|
package/styles/Editor.css
CHANGED