@manuscripts/body-editor 1.5.16 → 1.6.1
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/commands.js +53 -132
- package/dist/cjs/components/outline/DraggableTree.js +33 -25
- package/dist/cjs/components/toolbar/OrderListSelector.js +3 -11
- package/dist/cjs/configs/editor-plugins.js +2 -2
- package/dist/cjs/configs/editor-views.js +4 -6
- package/dist/cjs/lib/context-menu.js +6 -5
- package/dist/cjs/node-type-icons.js +0 -1
- package/dist/cjs/plugins/bibliography/bibliography-utils.js +60 -47
- package/dist/cjs/plugins/bibliography/index.js +48 -63
- package/dist/cjs/plugins/comment_annotation.js +2 -2
- package/dist/cjs/plugins/footnotes/index.js +19 -10
- package/dist/cjs/plugins/persist.js +21 -31
- package/dist/cjs/plugins/sections.js +1 -2
- package/dist/cjs/plugins/toc.js +28 -23
- package/dist/cjs/useEditor.js +1 -3
- package/dist/cjs/views/bibliography_element.js +20 -38
- package/dist/cjs/views/citation.js +29 -26
- package/dist/cjs/views/citation_editable.js +25 -44
- package/dist/cjs/views/{contributors_section.js → contributors.js} +4 -4
- package/dist/cjs/views/cross_reference.js +7 -36
- package/dist/cjs/views/cross_reference_editable.js +6 -14
- package/dist/cjs/views/editable_block.js +2 -2
- package/dist/cjs/views/{meta_section.js → empty.js} +3 -3
- package/dist/cjs/views/section_title.js +1 -16
- package/dist/es/commands.js +55 -110
- package/dist/es/components/outline/DraggableTree.js +33 -25
- package/dist/es/components/toolbar/OrderListSelector.js +4 -12
- package/dist/es/configs/editor-plugins.js +2 -2
- package/dist/es/configs/editor-views.js +4 -6
- package/dist/es/lib/context-menu.js +7 -6
- package/dist/es/node-type-icons.js +0 -1
- package/dist/es/plugins/bibliography/bibliography-utils.js +56 -45
- package/dist/es/plugins/bibliography/index.js +49 -65
- package/dist/es/plugins/comment_annotation.js +2 -2
- package/dist/es/plugins/footnotes/index.js +20 -11
- package/dist/es/plugins/persist.js +22 -32
- package/dist/es/plugins/sections.js +2 -3
- package/dist/es/plugins/toc.js +29 -24
- package/dist/es/useEditor.js +2 -4
- package/dist/es/views/bibliography_element.js +21 -39
- package/dist/es/views/citation.js +31 -28
- package/dist/es/views/citation_editable.js +28 -47
- package/dist/es/views/{contributors_section.js → contributors.js} +2 -2
- package/dist/es/views/cross_reference.js +7 -33
- package/dist/es/views/cross_reference_editable.js +6 -14
- package/dist/es/views/editable_block.js +3 -3
- package/dist/es/views/{meta_section.js → empty.js} +3 -3
- package/dist/es/views/section_title.js +0 -14
- package/dist/types/commands.d.ts +1 -2
- package/dist/types/components/outline/DraggableTree.d.ts +1 -2
- package/dist/types/configs/ManuscriptsEditor.d.ts +1 -10
- package/dist/types/configs/editor-plugins.d.ts +1 -5
- package/dist/types/configs/editor-views.d.ts +5 -6
- package/dist/types/lib/context-menu.d.ts +0 -1
- package/dist/types/plugins/bibliography/bibliography-utils.d.ts +10 -7
- package/dist/types/plugins/bibliography/index.d.ts +21 -3
- package/dist/types/views/bibliography_element.d.ts +1 -0
- package/dist/types/views/citation.d.ts +3 -4
- package/dist/types/views/citation_editable.d.ts +2 -8
- package/dist/types/views/{contributors_section.d.ts → contributors.d.ts} +3 -3
- package/dist/types/views/cross_reference.d.ts +0 -5
- package/dist/types/views/{meta_section.d.ts → empty.d.ts} +2 -2
- package/dist/types/views/section_title.d.ts +0 -2
- package/package.json +4 -22
- package/styles/AdvancedEditor.css +30 -34
- package/dist/cjs/plugins/auxiliary_object_order.js +0 -49
- package/dist/cjs/plugins/bibliography/types.js +0 -17
- package/dist/cjs/plugins/footnotes/footnotes-utils.js +0 -52
- package/dist/cjs/views/bibliography_item.js +0 -138
- package/dist/cjs/views/bibliography_item_editable.js +0 -20
- package/dist/es/plugins/auxiliary_object_order.js +0 -46
- package/dist/es/plugins/bibliography/types.js +0 -16
- package/dist/es/plugins/footnotes/footnotes-utils.js +0 -46
- package/dist/es/views/bibliography_item.js +0 -131
- package/dist/es/views/bibliography_item_editable.js +0 -18
- package/dist/types/plugins/auxiliary_object_order.d.ts +0 -12
- package/dist/types/plugins/bibliography/types.d.ts +0 -40
- package/dist/types/plugins/footnotes/footnotes-utils.d.ts +0 -25
- package/dist/types/views/bibliography_item.d.ts +0 -34
- package/dist/types/views/bibliography_item_editable.d.ts +0 -18
|
@@ -26,21 +26,23 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
26
26
|
return t;
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.buildCitations = exports.getBibliographyItemModelMap = exports.getBibliographyItem = exports.getCitation = exports.buildDecorations = exports.isBibliographyElement = void 0;
|
|
30
30
|
const json_schema_1 = require("@manuscripts/json-schema");
|
|
31
31
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
32
32
|
const transform_1 = require("@manuscripts/transform");
|
|
33
|
-
const
|
|
33
|
+
const lodash_1 = require("lodash");
|
|
34
34
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
35
35
|
const isBibliographyElement = (node) => node.type === node.type.schema.nodes.bibliography_element;
|
|
36
36
|
exports.isBibliographyElement = isBibliographyElement;
|
|
37
|
-
|
|
37
|
+
let count = 0;
|
|
38
|
+
const buildDecorations = (state, doc) => {
|
|
38
39
|
const decorations = [];
|
|
39
40
|
let hasMissingItems = false;
|
|
40
|
-
for (const [node, pos
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
for (const [node, pos] of state.citationNodes) {
|
|
42
|
+
const rids = node.attrs.rids;
|
|
43
|
+
if (rids.length) {
|
|
44
|
+
for (const rid of rids) {
|
|
45
|
+
if (!state.bibliographyItems.has(rid)) {
|
|
44
46
|
decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
|
|
45
47
|
class: 'citation-missing',
|
|
46
48
|
}));
|
|
@@ -72,57 +74,58 @@ const buildDecorations = (doc, citationNodes, popper, referencesModelMap, trigge
|
|
|
72
74
|
}
|
|
73
75
|
});
|
|
74
76
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
});
|
|
83
|
-
}
|
|
77
|
+
doc.descendants((node, pos) => {
|
|
78
|
+
if ((0, exports.isBibliographyElement)(node)) {
|
|
79
|
+
decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {}, {
|
|
80
|
+
refresh: count++,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
84
|
return decorations;
|
|
85
85
|
};
|
|
86
86
|
exports.buildDecorations = buildDecorations;
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}))) || [],
|
|
103
|
-
objectType: json_schema_1.ObjectTypes.Citation,
|
|
104
|
-
};
|
|
87
|
+
const getCitation = (node) => {
|
|
88
|
+
const attrs = getEffectiveAttrs(node);
|
|
89
|
+
if (!attrs) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
const rids = attrs.rids;
|
|
93
|
+
const items = rids.map((i) => ({
|
|
94
|
+
_id: '_',
|
|
95
|
+
objectType: json_schema_1.ObjectTypes.CitationItem,
|
|
96
|
+
bibliographyItem: i,
|
|
97
|
+
}));
|
|
98
|
+
return {
|
|
99
|
+
_id: attrs.id,
|
|
100
|
+
objectType: json_schema_1.ObjectTypes.Citation,
|
|
101
|
+
embeddedCitationItems: items,
|
|
105
102
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
nodeChange.status !== track_changes_plugin_1.CHANGE_STATUS.rejected) {
|
|
103
|
+
};
|
|
104
|
+
exports.getCitation = getCitation;
|
|
105
|
+
const getBibliographyItem = (node) => {
|
|
106
|
+
const attrs = getEffectiveAttrs(node);
|
|
107
|
+
if (!attrs) {
|
|
112
108
|
return undefined;
|
|
113
109
|
}
|
|
110
|
+
const { id, containerTitle, doi } = attrs, rest = __rest(attrs, ["id", "containerTitle", "doi"]);
|
|
111
|
+
const item = Object.assign({ _id: id, objectType: json_schema_1.ObjectTypes.BibliographyItem, 'container-title': containerTitle, DOI: doi }, rest);
|
|
112
|
+
return (0, lodash_1.pickBy)(item, (v) => v !== undefined);
|
|
113
|
+
};
|
|
114
|
+
exports.getBibliographyItem = getBibliographyItem;
|
|
115
|
+
const getLatest = (a, b) => a.updatedAt > b.updatedAt ? a : b;
|
|
116
|
+
const getEffectiveAttrs = (node) => {
|
|
117
|
+
const _a = node.attrs, { dataTracked } = _a, attrs = __rest(_a, ["dataTracked"]);
|
|
118
|
+
const nodeChange = dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.reduce(getLatest);
|
|
114
119
|
const isRejected = nodeChange &&
|
|
115
120
|
nodeChange.operation === track_changes_plugin_1.CHANGE_OPERATION.set_node_attributes &&
|
|
116
121
|
nodeChange.status === track_changes_plugin_1.CHANGE_STATUS.rejected;
|
|
117
|
-
return
|
|
122
|
+
return isRejected ? nodeChange === null || nodeChange === void 0 ? void 0 : nodeChange.oldAttrs : attrs;
|
|
118
123
|
};
|
|
119
|
-
|
|
120
|
-
const getReferencesModelMap = (doc, excludeDeletedNode) => {
|
|
124
|
+
const getBibliographyItemModelMap = (doc) => {
|
|
121
125
|
const modelMap = new Map();
|
|
122
126
|
doc.descendants((node) => {
|
|
123
|
-
if (node.type === transform_1.schema.nodes.bibliography_item
|
|
124
|
-
|
|
125
|
-
const model = (0, exports.getNodeModel)(node, excludeDeletedNode);
|
|
127
|
+
if (node.type === transform_1.schema.nodes.bibliography_item) {
|
|
128
|
+
const model = (0, exports.getBibliographyItem)(node);
|
|
126
129
|
if (model) {
|
|
127
130
|
modelMap.set(model._id, model);
|
|
128
131
|
}
|
|
@@ -130,4 +133,14 @@ const getReferencesModelMap = (doc, excludeDeletedNode) => {
|
|
|
130
133
|
});
|
|
131
134
|
return modelMap;
|
|
132
135
|
};
|
|
133
|
-
exports.
|
|
136
|
+
exports.getBibliographyItemModelMap = getBibliographyItemModelMap;
|
|
137
|
+
const buildCitations = (citations) => citations.map((citation) => ({
|
|
138
|
+
citationID: citation[0].attrs.id,
|
|
139
|
+
citationItems: citation[0].attrs.rids.map((rid) => ({
|
|
140
|
+
id: rid,
|
|
141
|
+
})),
|
|
142
|
+
properties: {
|
|
143
|
+
noteIndex: 0,
|
|
144
|
+
},
|
|
145
|
+
}));
|
|
146
|
+
exports.buildCitations = buildCitations;
|
|
@@ -15,86 +15,71 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.bibliographyKey = void 0;
|
|
18
|
+
exports.getBibliographyPluginState = exports.bibliographyKey = void 0;
|
|
19
19
|
const library_1 = require("@manuscripts/library");
|
|
20
|
-
const
|
|
20
|
+
const transform_1 = require("@manuscripts/transform");
|
|
21
|
+
const lodash_1 = require("lodash");
|
|
21
22
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
22
23
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
23
24
|
const track_changes_utils_1 = require("../../lib/track-changes-utils");
|
|
24
25
|
const bibliography_utils_1 = require("./bibliography-utils");
|
|
25
26
|
exports.bibliographyKey = new prosemirror_state_1.PluginKey('bibliography');
|
|
26
27
|
exports.default = (props) => {
|
|
27
|
-
const { style, locale } = props.cslProps;
|
|
28
28
|
return new prosemirror_state_1.Plugin({
|
|
29
29
|
key: exports.bibliographyKey,
|
|
30
30
|
state: {
|
|
31
31
|
init(config, instance) {
|
|
32
|
-
|
|
33
|
-
const citationNodes = (0, library_1.buildCitationNodes)(instance.doc, referencesModelMap);
|
|
34
|
-
const filteredCitationNodes = citationNodes.filter((node) => !(0, track_changes_utils_1.isRejectedInsert)(node[0]));
|
|
35
|
-
const citations = (0, library_1.buildCitations)(filteredCitationNodes, (id) => referencesModelMap.get(id));
|
|
36
|
-
const bibliographyItems = (0, library_1.buildBibliographyItems)(filteredCitationNodes, (id) => referencesModelMap.get(id));
|
|
37
|
-
return {
|
|
38
|
-
citationNodes,
|
|
39
|
-
citations,
|
|
40
|
-
bibliographyItems,
|
|
41
|
-
};
|
|
32
|
+
return buildBibliographyPluginState(instance.doc, props.cslProps);
|
|
42
33
|
},
|
|
43
|
-
apply(tr, value
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const filteredCitationNodes = citationNodes.filter((node) => !(0, track_changes_utils_1.isRejectedInsert)(node[0]));
|
|
47
|
-
const citations = (0, library_1.buildCitations)(filteredCitationNodes, (id) => referencesModelMap.get(id));
|
|
48
|
-
const bibliographyItems = (0, library_1.buildBibliographyItems)(filteredCitationNodes, (id) => referencesModelMap.get(id));
|
|
49
|
-
const meta = tr.getMeta(exports.bibliographyKey);
|
|
50
|
-
const triggerUpdate = meta && meta.triggerUpdate;
|
|
51
|
-
return {
|
|
52
|
-
citationNodes,
|
|
53
|
-
citations,
|
|
54
|
-
bibliographyItems,
|
|
55
|
-
triggerUpdate,
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
appendTransaction(transactions, oldState, newState) {
|
|
60
|
-
const { citations: oldCitations } = exports.bibliographyKey.getState(oldState);
|
|
61
|
-
const { citations, bibliographyItems } = exports.bibliographyKey.getState(newState);
|
|
62
|
-
const bibliographyInserted = transactions.some((tr) => {
|
|
63
|
-
const meta = tr.getMeta(exports.bibliographyKey);
|
|
64
|
-
return meta && meta.bibliographyInserted;
|
|
65
|
-
});
|
|
66
|
-
const initCitations = transactions.some((tr) => {
|
|
67
|
-
const meta = tr.getMeta(exports.bibliographyKey);
|
|
68
|
-
return meta && meta.initCitations;
|
|
69
|
-
});
|
|
70
|
-
if ((0, lodash_es_1.isEqual)(citations, oldCitations) &&
|
|
71
|
-
!bibliographyInserted &&
|
|
72
|
-
!initCitations) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
const { tr } = newState;
|
|
76
|
-
const { selection } = tr;
|
|
77
|
-
try {
|
|
78
|
-
const generatedCitations = new Map(library_1.CitationProvider.rebuildProcessorState(citations, bibliographyItems, style || '', locale, 'html').map((item) => [item[0], item[2]]));
|
|
79
|
-
props.setCiteprocCitations(generatedCitations);
|
|
80
|
-
if (selection instanceof prosemirror_state_1.NodeSelection) {
|
|
81
|
-
tr.setSelection(prosemirror_state_1.NodeSelection.create(tr.doc, selection.from));
|
|
34
|
+
apply(tr, value) {
|
|
35
|
+
if (!tr.steps.length) {
|
|
36
|
+
return value;
|
|
82
37
|
}
|
|
83
|
-
tr.
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
tr.setMeta('origin', exports.bibliographyKey);
|
|
87
|
-
return tr;
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
console.error(error);
|
|
91
|
-
}
|
|
38
|
+
return buildBibliographyPluginState(tr.doc, props.cslProps, value);
|
|
39
|
+
},
|
|
92
40
|
},
|
|
93
41
|
props: {
|
|
94
42
|
decorations(state) {
|
|
95
|
-
const
|
|
96
|
-
return prosemirror_view_1.DecorationSet.create(state.doc, (0, bibliography_utils_1.buildDecorations)(
|
|
43
|
+
const bib = (0, exports.getBibliographyPluginState)(state);
|
|
44
|
+
return prosemirror_view_1.DecorationSet.create(state.doc, (0, bibliography_utils_1.buildDecorations)(bib, state.doc));
|
|
97
45
|
},
|
|
98
46
|
},
|
|
99
47
|
});
|
|
100
48
|
};
|
|
49
|
+
const buildBibliographyPluginState = (doc, csl, $old) => {
|
|
50
|
+
const nodes = [];
|
|
51
|
+
doc.descendants((node, pos) => {
|
|
52
|
+
if ((0, transform_1.isCitationNode)(node) && !(0, track_changes_utils_1.isRejectedInsert)(node)) {
|
|
53
|
+
nodes.push([node, pos]);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const modelMap = (0, bibliography_utils_1.getBibliographyItemModelMap)(doc);
|
|
57
|
+
const citations = (0, bibliography_utils_1.buildCitations)(nodes);
|
|
58
|
+
const $new = {
|
|
59
|
+
citationNodes: nodes,
|
|
60
|
+
citations,
|
|
61
|
+
bibliographyItems: modelMap,
|
|
62
|
+
};
|
|
63
|
+
if (!csl.style) {
|
|
64
|
+
return $new;
|
|
65
|
+
}
|
|
66
|
+
if ($old && (0, lodash_1.isEqual)(citations, $old.citations)) {
|
|
67
|
+
$new.provider = $old.provider;
|
|
68
|
+
$new.renderedCitations = $old.renderedCitations;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const provider = new library_1.CitationProvider({
|
|
72
|
+
getLibraryItem: (id) => modelMap.get(id),
|
|
73
|
+
citationStyle: csl.style || '',
|
|
74
|
+
locale: csl.locale,
|
|
75
|
+
});
|
|
76
|
+
const citationTexts = provider.rebuildState((0, bibliography_utils_1.buildCitations)(nodes));
|
|
77
|
+
$new.provider = provider;
|
|
78
|
+
$new.renderedCitations = new Map(citationTexts.map((i) => [i[0], i[2]]));
|
|
79
|
+
}
|
|
80
|
+
return $new;
|
|
81
|
+
};
|
|
82
|
+
const getBibliographyPluginState = (state) => {
|
|
83
|
+
return exports.bibliographyKey.getState(state);
|
|
84
|
+
};
|
|
85
|
+
exports.getBibliographyPluginState = getBibliographyPluginState;
|
|
@@ -65,7 +65,7 @@ exports.default = (props) => {
|
|
|
65
65
|
};
|
|
66
66
|
const getNodePosition = (node, pos) => {
|
|
67
67
|
switch (node.type) {
|
|
68
|
-
case
|
|
68
|
+
case transform_1.schema.nodes.keywords:
|
|
69
69
|
return pos + 2;
|
|
70
70
|
default:
|
|
71
71
|
return pos + 1;
|
|
@@ -74,7 +74,7 @@ const getNodePosition = (node, pos) => {
|
|
|
74
74
|
const commentsState = (setSelectedComment, doc) => {
|
|
75
75
|
const comments = [];
|
|
76
76
|
doc.descendants((node) => {
|
|
77
|
-
if (node.type === transform_1.schema.nodes.
|
|
77
|
+
if (node.type === transform_1.schema.nodes.comments) {
|
|
78
78
|
node.descendants((comment) => {
|
|
79
79
|
comments.push(comment.attrs);
|
|
80
80
|
});
|
|
@@ -28,7 +28,9 @@ const buildPluginState = (doc) => {
|
|
|
28
28
|
doc.descendants((node, pos) => {
|
|
29
29
|
if ((0, transform_1.isInlineFootnoteNode)(node)) {
|
|
30
30
|
nodes.push([node, pos]);
|
|
31
|
-
|
|
31
|
+
node.attrs.rids.forEach((rid) => {
|
|
32
|
+
labels.set(rid, String(++index));
|
|
33
|
+
});
|
|
32
34
|
}
|
|
33
35
|
});
|
|
34
36
|
return { nodes, labels };
|
|
@@ -36,7 +38,8 @@ const buildPluginState = (doc) => {
|
|
|
36
38
|
exports.buildPluginState = buildPluginState;
|
|
37
39
|
const scrollToInlineFootnote = (rid, view) => {
|
|
38
40
|
view.state.doc.descendants((node, pos) => {
|
|
39
|
-
|
|
41
|
+
const footnote = node;
|
|
42
|
+
if (footnote.attrs.rids.includes(rid)) {
|
|
40
43
|
const selection = prosemirror_state_1.NodeSelection.create(view.state.doc, pos);
|
|
41
44
|
view.dispatch(view.state.tr.setSelection(selection).scrollIntoView());
|
|
42
45
|
}
|
|
@@ -70,9 +73,12 @@ exports.default = () => {
|
|
|
70
73
|
}
|
|
71
74
|
const { tr } = newState;
|
|
72
75
|
inlineFootnoteNodes.forEach(([node, pos]) => {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
const footnote = node;
|
|
77
|
+
const contents = footnote.attrs.rids
|
|
78
|
+
.map((rid) => labels.get(rid))
|
|
79
|
+
.join('');
|
|
80
|
+
if (footnote.attrs.contents !== contents) {
|
|
81
|
+
tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, footnote.attrs), { rids: footnote.attrs.rids, contents }));
|
|
76
82
|
}
|
|
77
83
|
});
|
|
78
84
|
return tr;
|
|
@@ -83,11 +89,14 @@ exports.default = () => {
|
|
|
83
89
|
const { labels } = exports.footnotesKey.getState(state);
|
|
84
90
|
if (labels) {
|
|
85
91
|
state.doc.descendants((node, pos) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
if ((0, transform_1.isFootnoteNode)(node)) {
|
|
93
|
+
const id = node.attrs.id;
|
|
94
|
+
const label = labels.get(id);
|
|
95
|
+
if (label) {
|
|
96
|
+
decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, labelWidget(label, id), {
|
|
97
|
+
side: -1,
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
91
100
|
}
|
|
92
101
|
});
|
|
93
102
|
}
|
|
@@ -3,43 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
4
4
|
const transform_1 = require("@manuscripts/transform");
|
|
5
5
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
6
|
+
const isManuscriptNode = (node) => {
|
|
7
|
+
return node && node.type === transform_1.schema.nodes.manuscript;
|
|
8
|
+
};
|
|
6
9
|
exports.default = () => {
|
|
7
10
|
return new prosemirror_state_1.Plugin({
|
|
8
11
|
appendTransaction(transactions, oldState, newState) {
|
|
9
|
-
if (!transactions.some((
|
|
12
|
+
if (!transactions.some((tr) => tr.docChanged)) {
|
|
10
13
|
return null;
|
|
11
14
|
}
|
|
12
|
-
const newTr = newState.tr;
|
|
13
|
-
const diffStart = oldState.doc.content.findDiffStart(newState.doc.content);
|
|
14
|
-
const diffEnd = oldState.doc.content.findDiffEnd(newState.doc.content);
|
|
15
15
|
const ids = new Set();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const updatedAttrs = Object.assign(Object.assign({}, node.attrs), { id: newId });
|
|
34
|
-
newTr.setNodeMarkup(pos, undefined, updatedAttrs, node.marks);
|
|
35
|
-
ids.add(newId);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
(0, track_changes_plugin_1.skipTracking)(newTr);
|
|
39
|
-
newTr.setMeta('origin', 'persist');
|
|
40
|
-
return newTr;
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
16
|
+
const tr = newState.tr;
|
|
17
|
+
newState.doc.descendants((node, pos, parent) => {
|
|
18
|
+
if (node.isInline ||
|
|
19
|
+
isManuscriptNode(node) ||
|
|
20
|
+
isManuscriptNode(parent)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
let id = node.attrs.id;
|
|
24
|
+
if (!id || ids.has(id)) {
|
|
25
|
+
id = (0, transform_1.generateNodeID)(node.type);
|
|
26
|
+
tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, node.attrs), { id }), node.marks);
|
|
27
|
+
}
|
|
28
|
+
ids.add(id);
|
|
29
|
+
});
|
|
30
|
+
(0, track_changes_plugin_1.skipTracking)(tr);
|
|
31
|
+
tr.setMeta('origin', 'persist');
|
|
32
|
+
return tr;
|
|
43
33
|
},
|
|
44
34
|
});
|
|
45
35
|
};
|
|
@@ -40,8 +40,7 @@ const preventTitleEdit = (tr) => {
|
|
|
40
40
|
const currentDoc = tr.docs[i];
|
|
41
41
|
step.getMap().forEach((fromA, toA) => {
|
|
42
42
|
currentDoc.nodesBetween(fromA, toA, (node, nodePos) => {
|
|
43
|
-
if ((0, transform_1.isGraphicalAbstractSectionNode)(node) ||
|
|
44
|
-
(0, transform_1.isKeywordsSectionNode)(node)) {
|
|
43
|
+
if ((0, transform_1.isGraphicalAbstractSectionNode)(node) || (0, transform_1.isKeywordsNode)(node)) {
|
|
45
44
|
node.descendants((childNode, childPos) => {
|
|
46
45
|
const inDocPos = nodePos + childPos;
|
|
47
46
|
if ((0, transform_1.isSectionTitleNode)(childNode) &&
|
package/dist/cjs/plugins/toc.js
CHANGED
|
@@ -37,32 +37,37 @@ const buildTOCList = (headingStyles, list, node, depth = 1, prefix = '') => {
|
|
|
37
37
|
? sectionNumberingStyle.suffix
|
|
38
38
|
: '.';
|
|
39
39
|
let index = sectionNumberingStyle ? sectionNumberingStyle.startIndex : 1;
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
40
|
+
node.forEach((child) => {
|
|
41
|
+
if (child.type === transform_1.schema.nodes.body) {
|
|
42
|
+
for (const childNode of (0, utils_1.iterateChildren)(child)) {
|
|
43
|
+
if ((0, transform_1.isSectionNodeType)(childNode.type) && !(0, transform_1.isTOCSectionNode)(childNode)) {
|
|
44
|
+
const numbering = numberingScheme === 'none' ? '' : `${prefix}${index}`;
|
|
45
|
+
const firstChildNode = childNode.child(0);
|
|
46
|
+
if (firstChildNode.type ===
|
|
47
|
+
firstChildNode.type.schema.nodes.section_title) {
|
|
48
|
+
const item = document.createElement('li');
|
|
49
|
+
item.classList.add('manuscript-toc-list-item');
|
|
50
|
+
item.setAttribute('data-referenced-section', childNode.attrs.id);
|
|
51
|
+
item.setAttribute('data-referenced-section-path-length', String(depth));
|
|
52
|
+
item.textContent = `${numbering ? `${numbering}${suffix}` : ''} ${firstChildNode.textContent || 'Untitled Section'}`;
|
|
53
|
+
list.appendChild(item);
|
|
54
|
+
}
|
|
55
|
+
const childSection = (0, utils_1.getMatchingChild)(childNode, (node) => (0, transform_1.isSectionNodeType)(node.type));
|
|
56
|
+
if (childSection) {
|
|
57
|
+
const paragraphStyle = headingStyles.get(`heading${depth + 1}`);
|
|
58
|
+
if (!paragraphStyle || paragraphStyle.partOfTOC) {
|
|
59
|
+
const sublist = document.createElement('ul');
|
|
60
|
+
buildTOCList(headingStyles, sublist, childNode, depth + 1, numbering ? `${numbering}.` : '');
|
|
61
|
+
const item = document.createElement('li');
|
|
62
|
+
item.appendChild(sublist);
|
|
63
|
+
list.appendChild(item);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
index++;
|
|
61
67
|
}
|
|
62
68
|
}
|
|
63
|
-
index++;
|
|
64
69
|
}
|
|
65
|
-
}
|
|
70
|
+
});
|
|
66
71
|
};
|
|
67
72
|
const isParagraphStyle = (0, transform_1.hasObjectType)(json_schema_1.ObjectTypes.ParagraphStyle);
|
|
68
73
|
const buildHeadingStyles = (modelMap) => {
|
package/dist/cjs/useEditor.js
CHANGED
|
@@ -68,9 +68,7 @@ const useEditor = (initialState, createView) => {
|
|
|
68
68
|
state.doc.descendants((node, pos) => {
|
|
69
69
|
if (node.attrs.id === id) {
|
|
70
70
|
currentView.focus();
|
|
71
|
-
const selection =
|
|
72
|
-
? prosemirror_state_1.NodeSelection.create(state.tr.doc, pos)
|
|
73
|
-
: prosemirror_state_1.TextSelection.near(state.tr.doc.resolve(pos + 1));
|
|
71
|
+
const selection = prosemirror_state_1.NodeSelection.create(state.tr.doc, pos);
|
|
74
72
|
currentView.dispatch(state.tr.setSelection(selection));
|
|
75
73
|
const dom = currentView.domAtPos(pos + 1);
|
|
76
74
|
if (dom.node instanceof Element) {
|
|
@@ -39,39 +39,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
};
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
41
|
exports.BibliographyElementBlockView = void 0;
|
|
42
|
-
const library_1 = require("@manuscripts/library");
|
|
43
42
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
44
43
|
const transform_1 = require("@manuscripts/transform");
|
|
45
44
|
const react_1 = __importDefault(require("react"));
|
|
46
45
|
const assets_1 = require("../assets");
|
|
47
46
|
const dompurify_1 = require("../lib/dompurify");
|
|
48
47
|
const bibliography_1 = require("../plugins/bibliography");
|
|
49
|
-
const bibliography_utils_1 = require("../plugins/bibliography/bibliography-utils");
|
|
50
48
|
const comment_annotation_1 = require("../plugins/comment_annotation");
|
|
51
49
|
const tracking_mark_1 = require("../plugins/tracking-mark");
|
|
52
50
|
const block_view_1 = __importDefault(require("./block_view"));
|
|
53
51
|
const creators_1 = require("./creators");
|
|
54
|
-
const createBibliography = (bibliographyItems, cslProps) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
-
const bibliographyItemsMap = new Map(bibliographyItems.map((item) => [item._id, item]));
|
|
56
|
-
const getLibraryItem = (id) => bibliographyItemsMap.get(id);
|
|
57
|
-
const { style = '', locale } = cslProps;
|
|
58
|
-
const provider = new library_1.CitationProvider({
|
|
59
|
-
getLibraryItem,
|
|
60
|
-
citationStyle: style,
|
|
61
|
-
locale,
|
|
62
|
-
});
|
|
63
|
-
const [bibmeta, generatedBibliographyItems] = provider.makeBibliography(bibliographyItems);
|
|
64
|
-
if (bibmeta.bibliography_errors.length) {
|
|
65
|
-
console.error(bibmeta.bibliography_errors);
|
|
66
|
-
}
|
|
67
|
-
const bibliographyFragment = generatedBibliographyItems
|
|
68
|
-
.map((item, i) => `<div id=${bibmeta.entry_ids[i]} class="bib-item"><div><div class="csl-bib-body">${item}</div></div></div>`)
|
|
69
|
-
.join('');
|
|
70
|
-
return (0, dompurify_1.sanitize)(`<div class="contents">${bibliographyFragment}</div>`);
|
|
71
|
-
});
|
|
72
52
|
class BibliographyElementBlockView extends block_view_1.default {
|
|
73
53
|
constructor() {
|
|
74
54
|
super(...arguments);
|
|
55
|
+
this.gutterButtons = () => [];
|
|
75
56
|
this.showPopper = (referenceID) => {
|
|
76
57
|
const { renderReactComponent, components: { ReferencesEditor }, } = this.props;
|
|
77
58
|
const handleSave = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -84,13 +65,14 @@ class BibliographyElementBlockView extends block_view_1.default {
|
|
|
84
65
|
this.popperContainer = document.createElement('div');
|
|
85
66
|
this.popperContainer.className = 'references';
|
|
86
67
|
}
|
|
87
|
-
|
|
68
|
+
const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
|
|
69
|
+
renderReactComponent(react_1.default.createElement(ReferencesEditor, { saveModel: handleSave, deleteModel: this.deleteNode, modelMap: bib.bibliographyItems, referenceID: referenceID }), this.popperContainer);
|
|
88
70
|
this.props.popper.show(this.dom, this.popperContainer, 'right');
|
|
89
71
|
};
|
|
90
72
|
this.stopEvent = () => true;
|
|
91
73
|
this.ignoreMutation = () => true;
|
|
92
74
|
this.updateContents = () => __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const
|
|
75
|
+
const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
|
|
94
76
|
const commentsDecorationSet = comment_annotation_1.commentAnnotation.getState(this.view.state);
|
|
95
77
|
const commentElementMap = new Map();
|
|
96
78
|
const dataTrackedMap = new Map();
|
|
@@ -109,9 +91,14 @@ class BibliographyElementBlockView extends block_view_1.default {
|
|
|
109
91
|
dataTrackedMap.set(node.attrs.id, lastChange);
|
|
110
92
|
}
|
|
111
93
|
});
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
|
|
94
|
+
const can = this.props.getCapabilities();
|
|
95
|
+
const wrapper = document.createElement('div');
|
|
96
|
+
wrapper.classList.add('contents');
|
|
97
|
+
const [meta, bibliography] = bib.provider.makeBibliography();
|
|
98
|
+
for (let i = 0; i < bibliography.length; i++) {
|
|
99
|
+
const id = meta.entry_ids[i];
|
|
100
|
+
const fragment = bibliography[i];
|
|
101
|
+
const element = (0, dompurify_1.sanitize)(`<div id="${id}" class="bib-item"><div class="csl-bib-body">${fragment}</div></div>`).firstElementChild;
|
|
115
102
|
const doubleButton = document.createElement('div');
|
|
116
103
|
const editButton = document.createElement('button');
|
|
117
104
|
const commentButton = document.createElement('button');
|
|
@@ -130,14 +117,14 @@ class BibliographyElementBlockView extends block_view_1.default {
|
|
|
130
117
|
editButton.innerHTML = assets_1.editIcon;
|
|
131
118
|
commentButton.innerHTML = assets_1.commentIcon;
|
|
132
119
|
doubleButton.append(editButton, commentButton);
|
|
133
|
-
if (
|
|
120
|
+
if (can.seeReferencesButtons &&
|
|
134
121
|
!element.querySelector('.bibliography-double-button')) {
|
|
135
122
|
element.appendChild(doubleButton);
|
|
136
123
|
}
|
|
137
|
-
editButton.disabled = !
|
|
124
|
+
editButton.disabled = !can.editCitationsAndRefs;
|
|
138
125
|
const commentElement = commentElementMap.get(element.id);
|
|
139
126
|
if (commentElement) {
|
|
140
|
-
element.
|
|
127
|
+
element.appendChild(commentElement);
|
|
141
128
|
}
|
|
142
129
|
const dataTracked = dataTrackedMap.get(element.id);
|
|
143
130
|
if (dataTracked) {
|
|
@@ -146,16 +133,17 @@ class BibliographyElementBlockView extends block_view_1.default {
|
|
|
146
133
|
decoration.style && element.setAttribute('style', decoration.style);
|
|
147
134
|
if (dataTracked.status === track_changes_plugin_1.CHANGE_STATUS.pending &&
|
|
148
135
|
dataTracked.operation === track_changes_plugin_1.CHANGE_OPERATION.set_node_attributes) {
|
|
149
|
-
element.
|
|
136
|
+
element.appendChild((0, tracking_mark_1.getAttrsTrackingButton)(dataTracked.id));
|
|
150
137
|
}
|
|
151
138
|
}
|
|
152
|
-
|
|
139
|
+
wrapper.append(element);
|
|
140
|
+
}
|
|
153
141
|
const oldContent = this.container.querySelector('.contents');
|
|
154
142
|
if (oldContent) {
|
|
155
|
-
this.container.replaceChild(
|
|
143
|
+
this.container.replaceChild(wrapper, oldContent);
|
|
156
144
|
}
|
|
157
145
|
else {
|
|
158
|
-
this.container.appendChild(
|
|
146
|
+
this.container.appendChild(wrapper);
|
|
159
147
|
}
|
|
160
148
|
});
|
|
161
149
|
this.createElement = () => {
|
|
@@ -164,12 +152,6 @@ class BibliographyElementBlockView extends block_view_1.default {
|
|
|
164
152
|
this.container.contentEditable = 'false';
|
|
165
153
|
this.dom.setAttribute('contenteditable', 'false');
|
|
166
154
|
this.dom.appendChild(this.container);
|
|
167
|
-
this.contentDOM = document.createElement('div');
|
|
168
|
-
this.contentDOM.classList.add('block');
|
|
169
|
-
this.contentDOM.setAttribute('id', this.node.attrs.id);
|
|
170
|
-
this.contentDOM.setAttribute('contenteditable', 'false');
|
|
171
|
-
this.contentDOM.hidden = true;
|
|
172
|
-
this.container.appendChild(this.contentDOM);
|
|
173
155
|
};
|
|
174
156
|
}
|
|
175
157
|
}
|