@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,17 +26,19 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
26
26
|
};
|
|
27
27
|
import { ObjectTypes, } from '@manuscripts/json-schema';
|
|
28
28
|
import { CHANGE_OPERATION, CHANGE_STATUS, } from '@manuscripts/track-changes-plugin';
|
|
29
|
-
import { schema } from '@manuscripts/transform';
|
|
30
|
-
import { pickBy } from 'lodash
|
|
29
|
+
import { schema, } from '@manuscripts/transform';
|
|
30
|
+
import { pickBy } from 'lodash';
|
|
31
31
|
import { Decoration } from 'prosemirror-view';
|
|
32
32
|
export const isBibliographyElement = (node) => node.type === node.type.schema.nodes.bibliography_element;
|
|
33
|
-
|
|
33
|
+
let count = 0;
|
|
34
|
+
export const buildDecorations = (state, doc) => {
|
|
34
35
|
const decorations = [];
|
|
35
36
|
let hasMissingItems = false;
|
|
36
|
-
for (const [node, pos
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
for (const [node, pos] of state.citationNodes) {
|
|
38
|
+
const rids = node.attrs.rids;
|
|
39
|
+
if (rids.length) {
|
|
40
|
+
for (const rid of rids) {
|
|
41
|
+
if (!state.bibliographyItems.has(rid)) {
|
|
40
42
|
decorations.push(Decoration.node(pos, pos + node.nodeSize, {
|
|
41
43
|
class: 'citation-missing',
|
|
42
44
|
}));
|
|
@@ -68,55 +70,55 @@ export const buildDecorations = (doc, citationNodes, popper, referencesModelMap,
|
|
|
68
70
|
}
|
|
69
71
|
});
|
|
70
72
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
});
|
|
79
|
-
}
|
|
73
|
+
doc.descendants((node, pos) => {
|
|
74
|
+
if (isBibliographyElement(node)) {
|
|
75
|
+
decorations.push(Decoration.node(pos, pos + node.nodeSize, {}, {
|
|
76
|
+
refresh: count++,
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
80
|
return decorations;
|
|
81
81
|
};
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}))) || [],
|
|
98
|
-
objectType: ObjectTypes.Citation,
|
|
99
|
-
};
|
|
82
|
+
export const getCitation = (node) => {
|
|
83
|
+
const attrs = getEffectiveAttrs(node);
|
|
84
|
+
if (!attrs) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
const rids = attrs.rids;
|
|
88
|
+
const items = rids.map((i) => ({
|
|
89
|
+
_id: '_',
|
|
90
|
+
objectType: ObjectTypes.CitationItem,
|
|
91
|
+
bibliographyItem: i,
|
|
92
|
+
}));
|
|
93
|
+
return {
|
|
94
|
+
_id: attrs.id,
|
|
95
|
+
objectType: ObjectTypes.Citation,
|
|
96
|
+
embeddedCitationItems: items,
|
|
100
97
|
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
nodeChange.operation === CHANGE_OPERATION.delete &&
|
|
106
|
-
nodeChange.status !== CHANGE_STATUS.rejected) {
|
|
98
|
+
};
|
|
99
|
+
export const getBibliographyItem = (node) => {
|
|
100
|
+
const attrs = getEffectiveAttrs(node);
|
|
101
|
+
if (!attrs) {
|
|
107
102
|
return undefined;
|
|
108
103
|
}
|
|
104
|
+
const { id, containerTitle, doi } = attrs, rest = __rest(attrs, ["id", "containerTitle", "doi"]);
|
|
105
|
+
const item = Object.assign({ _id: id, objectType: ObjectTypes.BibliographyItem, 'container-title': containerTitle, DOI: doi }, rest);
|
|
106
|
+
return pickBy(item, (v) => v !== undefined);
|
|
107
|
+
};
|
|
108
|
+
const getLatest = (a, b) => a.updatedAt > b.updatedAt ? a : b;
|
|
109
|
+
const getEffectiveAttrs = (node) => {
|
|
110
|
+
const _a = node.attrs, { dataTracked } = _a, attrs = __rest(_a, ["dataTracked"]);
|
|
111
|
+
const nodeChange = dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.reduce(getLatest);
|
|
109
112
|
const isRejected = nodeChange &&
|
|
110
113
|
nodeChange.operation === CHANGE_OPERATION.set_node_attributes &&
|
|
111
114
|
nodeChange.status === CHANGE_STATUS.rejected;
|
|
112
|
-
return
|
|
115
|
+
return isRejected ? nodeChange === null || nodeChange === void 0 ? void 0 : nodeChange.oldAttrs : attrs;
|
|
113
116
|
};
|
|
114
|
-
export const
|
|
117
|
+
export const getBibliographyItemModelMap = (doc) => {
|
|
115
118
|
const modelMap = new Map();
|
|
116
119
|
doc.descendants((node) => {
|
|
117
|
-
if (node.type === schema.nodes.bibliography_item
|
|
118
|
-
|
|
119
|
-
const model = getNodeModel(node, excludeDeletedNode);
|
|
120
|
+
if (node.type === schema.nodes.bibliography_item) {
|
|
121
|
+
const model = getBibliographyItem(node);
|
|
120
122
|
if (model) {
|
|
121
123
|
modelMap.set(model._id, model);
|
|
122
124
|
}
|
|
@@ -124,3 +126,12 @@ export const getReferencesModelMap = (doc, excludeDeletedNode) => {
|
|
|
124
126
|
});
|
|
125
127
|
return modelMap;
|
|
126
128
|
};
|
|
129
|
+
export const buildCitations = (citations) => citations.map((citation) => ({
|
|
130
|
+
citationID: citation[0].attrs.id,
|
|
131
|
+
citationItems: citation[0].attrs.rids.map((rid) => ({
|
|
132
|
+
id: rid,
|
|
133
|
+
})),
|
|
134
|
+
properties: {
|
|
135
|
+
noteIndex: 0,
|
|
136
|
+
},
|
|
137
|
+
}));
|
|
@@ -13,85 +13,69 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
16
|
+
import { CitationProvider } from '@manuscripts/library';
|
|
17
|
+
import { isCitationNode } from '@manuscripts/transform';
|
|
18
|
+
import { isEqual } from 'lodash';
|
|
19
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
19
20
|
import { DecorationSet } from 'prosemirror-view';
|
|
20
21
|
import { isRejectedInsert } from '../../lib/track-changes-utils';
|
|
21
|
-
import { buildDecorations,
|
|
22
|
+
import { buildCitations, buildDecorations, getBibliographyItemModelMap, } from './bibliography-utils';
|
|
22
23
|
export const bibliographyKey = new PluginKey('bibliography');
|
|
23
24
|
export default (props) => {
|
|
24
|
-
const { style, locale } = props.cslProps;
|
|
25
25
|
return new Plugin({
|
|
26
26
|
key: bibliographyKey,
|
|
27
27
|
state: {
|
|
28
28
|
init(config, instance) {
|
|
29
|
-
|
|
30
|
-
const citationNodes = buildCitationNodes(instance.doc, referencesModelMap);
|
|
31
|
-
const filteredCitationNodes = citationNodes.filter((node) => !isRejectedInsert(node[0]));
|
|
32
|
-
const citations = buildCitations(filteredCitationNodes, (id) => referencesModelMap.get(id));
|
|
33
|
-
const bibliographyItems = buildBibliographyItems(filteredCitationNodes, (id) => referencesModelMap.get(id));
|
|
34
|
-
return {
|
|
35
|
-
citationNodes,
|
|
36
|
-
citations,
|
|
37
|
-
bibliographyItems,
|
|
38
|
-
};
|
|
29
|
+
return buildBibliographyPluginState(instance.doc, props.cslProps);
|
|
39
30
|
},
|
|
40
|
-
apply(tr, value
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const filteredCitationNodes = citationNodes.filter((node) => !isRejectedInsert(node[0]));
|
|
44
|
-
const citations = buildCitations(filteredCitationNodes, (id) => referencesModelMap.get(id));
|
|
45
|
-
const bibliographyItems = buildBibliographyItems(filteredCitationNodes, (id) => referencesModelMap.get(id));
|
|
46
|
-
const meta = tr.getMeta(bibliographyKey);
|
|
47
|
-
const triggerUpdate = meta && meta.triggerUpdate;
|
|
48
|
-
return {
|
|
49
|
-
citationNodes,
|
|
50
|
-
citations,
|
|
51
|
-
bibliographyItems,
|
|
52
|
-
triggerUpdate,
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
appendTransaction(transactions, oldState, newState) {
|
|
57
|
-
const { citations: oldCitations } = bibliographyKey.getState(oldState);
|
|
58
|
-
const { citations, bibliographyItems } = bibliographyKey.getState(newState);
|
|
59
|
-
const bibliographyInserted = transactions.some((tr) => {
|
|
60
|
-
const meta = tr.getMeta(bibliographyKey);
|
|
61
|
-
return meta && meta.bibliographyInserted;
|
|
62
|
-
});
|
|
63
|
-
const initCitations = transactions.some((tr) => {
|
|
64
|
-
const meta = tr.getMeta(bibliographyKey);
|
|
65
|
-
return meta && meta.initCitations;
|
|
66
|
-
});
|
|
67
|
-
if (isEqual(citations, oldCitations) &&
|
|
68
|
-
!bibliographyInserted &&
|
|
69
|
-
!initCitations) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
const { tr } = newState;
|
|
73
|
-
const { selection } = tr;
|
|
74
|
-
try {
|
|
75
|
-
const generatedCitations = new Map(CitationProvider.rebuildProcessorState(citations, bibliographyItems, style || '', locale, 'html').map((item) => [item[0], item[2]]));
|
|
76
|
-
props.setCiteprocCitations(generatedCitations);
|
|
77
|
-
if (selection instanceof NodeSelection) {
|
|
78
|
-
tr.setSelection(NodeSelection.create(tr.doc, selection.from));
|
|
31
|
+
apply(tr, value) {
|
|
32
|
+
if (!tr.steps.length) {
|
|
33
|
+
return value;
|
|
79
34
|
}
|
|
80
|
-
tr.
|
|
81
|
-
|
|
82
|
-
});
|
|
83
|
-
tr.setMeta('origin', bibliographyKey);
|
|
84
|
-
return tr;
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
console.error(error);
|
|
88
|
-
}
|
|
35
|
+
return buildBibliographyPluginState(tr.doc, props.cslProps, value);
|
|
36
|
+
},
|
|
89
37
|
},
|
|
90
38
|
props: {
|
|
91
39
|
decorations(state) {
|
|
92
|
-
const
|
|
93
|
-
return DecorationSet.create(state.doc, buildDecorations(
|
|
40
|
+
const bib = getBibliographyPluginState(state);
|
|
41
|
+
return DecorationSet.create(state.doc, buildDecorations(bib, state.doc));
|
|
94
42
|
},
|
|
95
43
|
},
|
|
96
44
|
});
|
|
97
45
|
};
|
|
46
|
+
const buildBibliographyPluginState = (doc, csl, $old) => {
|
|
47
|
+
const nodes = [];
|
|
48
|
+
doc.descendants((node, pos) => {
|
|
49
|
+
if (isCitationNode(node) && !isRejectedInsert(node)) {
|
|
50
|
+
nodes.push([node, pos]);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const modelMap = getBibliographyItemModelMap(doc);
|
|
54
|
+
const citations = buildCitations(nodes);
|
|
55
|
+
const $new = {
|
|
56
|
+
citationNodes: nodes,
|
|
57
|
+
citations,
|
|
58
|
+
bibliographyItems: modelMap,
|
|
59
|
+
};
|
|
60
|
+
if (!csl.style) {
|
|
61
|
+
return $new;
|
|
62
|
+
}
|
|
63
|
+
if ($old && isEqual(citations, $old.citations)) {
|
|
64
|
+
$new.provider = $old.provider;
|
|
65
|
+
$new.renderedCitations = $old.renderedCitations;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const provider = new CitationProvider({
|
|
69
|
+
getLibraryItem: (id) => modelMap.get(id),
|
|
70
|
+
citationStyle: csl.style || '',
|
|
71
|
+
locale: csl.locale,
|
|
72
|
+
});
|
|
73
|
+
const citationTexts = provider.rebuildState(buildCitations(nodes));
|
|
74
|
+
$new.provider = provider;
|
|
75
|
+
$new.renderedCitations = new Map(citationTexts.map((i) => [i[0], i[2]]));
|
|
76
|
+
}
|
|
77
|
+
return $new;
|
|
78
|
+
};
|
|
79
|
+
export const getBibliographyPluginState = (state) => {
|
|
80
|
+
return bibliographyKey.getState(state);
|
|
81
|
+
};
|
|
@@ -59,7 +59,7 @@ export default (props) => {
|
|
|
59
59
|
};
|
|
60
60
|
const getNodePosition = (node, pos) => {
|
|
61
61
|
switch (node.type) {
|
|
62
|
-
case
|
|
62
|
+
case schema.nodes.keywords:
|
|
63
63
|
return pos + 2;
|
|
64
64
|
default:
|
|
65
65
|
return pos + 1;
|
|
@@ -68,7 +68,7 @@ const getNodePosition = (node, pos) => {
|
|
|
68
68
|
const commentsState = (setSelectedComment, doc) => {
|
|
69
69
|
const comments = [];
|
|
70
70
|
doc.descendants((node) => {
|
|
71
|
-
if (node.type === schema.nodes.
|
|
71
|
+
if (node.type === schema.nodes.comments) {
|
|
72
72
|
node.descendants((comment) => {
|
|
73
73
|
comments.push(comment.attrs);
|
|
74
74
|
});
|
|
@@ -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 { isInlineFootnoteNode, } from '@manuscripts/transform';
|
|
16
|
+
import { isFootnoteNode, isInlineFootnoteNode, } from '@manuscripts/transform';
|
|
17
17
|
import { isEqual } from 'lodash-es';
|
|
18
18
|
import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
|
|
19
19
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
@@ -25,14 +25,17 @@ export const buildPluginState = (doc) => {
|
|
|
25
25
|
doc.descendants((node, pos) => {
|
|
26
26
|
if (isInlineFootnoteNode(node)) {
|
|
27
27
|
nodes.push([node, pos]);
|
|
28
|
-
|
|
28
|
+
node.attrs.rids.forEach((rid) => {
|
|
29
|
+
labels.set(rid, String(++index));
|
|
30
|
+
});
|
|
29
31
|
}
|
|
30
32
|
});
|
|
31
33
|
return { nodes, labels };
|
|
32
34
|
};
|
|
33
35
|
const scrollToInlineFootnote = (rid, view) => {
|
|
34
36
|
view.state.doc.descendants((node, pos) => {
|
|
35
|
-
|
|
37
|
+
const footnote = node;
|
|
38
|
+
if (footnote.attrs.rids.includes(rid)) {
|
|
36
39
|
const selection = NodeSelection.create(view.state.doc, pos);
|
|
37
40
|
view.dispatch(view.state.tr.setSelection(selection).scrollIntoView());
|
|
38
41
|
}
|
|
@@ -66,9 +69,12 @@ export default () => {
|
|
|
66
69
|
}
|
|
67
70
|
const { tr } = newState;
|
|
68
71
|
inlineFootnoteNodes.forEach(([node, pos]) => {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
const footnote = node;
|
|
73
|
+
const contents = footnote.attrs.rids
|
|
74
|
+
.map((rid) => labels.get(rid))
|
|
75
|
+
.join('');
|
|
76
|
+
if (footnote.attrs.contents !== contents) {
|
|
77
|
+
tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, footnote.attrs), { rids: footnote.attrs.rids, contents }));
|
|
72
78
|
}
|
|
73
79
|
});
|
|
74
80
|
return tr;
|
|
@@ -79,11 +85,14 @@ export default () => {
|
|
|
79
85
|
const { labels } = footnotesKey.getState(state);
|
|
80
86
|
if (labels) {
|
|
81
87
|
state.doc.descendants((node, pos) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
if (isFootnoteNode(node)) {
|
|
89
|
+
const id = node.attrs.id;
|
|
90
|
+
const label = labels.get(id);
|
|
91
|
+
if (label) {
|
|
92
|
+
decorations.push(Decoration.widget(pos + 2, labelWidget(label, id), {
|
|
93
|
+
side: -1,
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
87
96
|
}
|
|
88
97
|
});
|
|
89
98
|
}
|
|
@@ -1,43 +1,33 @@
|
|
|
1
1
|
import { skipTracking } from '@manuscripts/track-changes-plugin';
|
|
2
|
-
import { generateNodeID,
|
|
2
|
+
import { generateNodeID, schema } from '@manuscripts/transform';
|
|
3
3
|
import { Plugin } from 'prosemirror-state';
|
|
4
|
+
const isManuscriptNode = (node) => {
|
|
5
|
+
return node && node.type === schema.nodes.manuscript;
|
|
6
|
+
};
|
|
4
7
|
export default () => {
|
|
5
8
|
return new Plugin({
|
|
6
9
|
appendTransaction(transactions, oldState, newState) {
|
|
7
|
-
if (!transactions.some((
|
|
10
|
+
if (!transactions.some((tr) => tr.docChanged)) {
|
|
8
11
|
return null;
|
|
9
12
|
}
|
|
10
|
-
const newTr = newState.tr;
|
|
11
|
-
const diffStart = oldState.doc.content.findDiffStart(newState.doc.content);
|
|
12
|
-
const diffEnd = oldState.doc.content.findDiffEnd(newState.doc.content);
|
|
13
13
|
const ids = new Set();
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const updatedAttrs = Object.assign(Object.assign({}, node.attrs), { id: newId });
|
|
32
|
-
newTr.setNodeMarkup(pos, undefined, updatedAttrs, node.marks);
|
|
33
|
-
ids.add(newId);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
skipTracking(newTr);
|
|
37
|
-
newTr.setMeta('origin', 'persist');
|
|
38
|
-
return newTr;
|
|
39
|
-
}
|
|
40
|
-
return null;
|
|
14
|
+
const tr = newState.tr;
|
|
15
|
+
newState.doc.descendants((node, pos, parent) => {
|
|
16
|
+
if (node.isInline ||
|
|
17
|
+
isManuscriptNode(node) ||
|
|
18
|
+
isManuscriptNode(parent)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
let id = node.attrs.id;
|
|
22
|
+
if (!id || ids.has(id)) {
|
|
23
|
+
id = generateNodeID(node.type);
|
|
24
|
+
tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, node.attrs), { id }), node.marks);
|
|
25
|
+
}
|
|
26
|
+
ids.add(id);
|
|
27
|
+
});
|
|
28
|
+
skipTracking(tr);
|
|
29
|
+
tr.setMeta('origin', 'persist');
|
|
30
|
+
return tr;
|
|
41
31
|
},
|
|
42
32
|
});
|
|
43
33
|
};
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { trackChangesPluginKey } from '@manuscripts/track-changes-plugin';
|
|
17
|
-
import { isGraphicalAbstractSectionNode,
|
|
17
|
+
import { isGraphicalAbstractSectionNode, isKeywordsNode, isSectionTitleNode, } from '@manuscripts/transform';
|
|
18
18
|
import { Plugin } from 'prosemirror-state';
|
|
19
19
|
import { ReplaceAroundStep, ReplaceStep } from 'prosemirror-transform';
|
|
20
20
|
import { highlightKey, SET_COMMENT } from './highlight';
|
|
@@ -38,8 +38,7 @@ const preventTitleEdit = (tr) => {
|
|
|
38
38
|
const currentDoc = tr.docs[i];
|
|
39
39
|
step.getMap().forEach((fromA, toA) => {
|
|
40
40
|
currentDoc.nodesBetween(fromA, toA, (node, nodePos) => {
|
|
41
|
-
if (isGraphicalAbstractSectionNode(node) ||
|
|
42
|
-
isKeywordsSectionNode(node)) {
|
|
41
|
+
if (isGraphicalAbstractSectionNode(node) || isKeywordsNode(node)) {
|
|
43
42
|
node.descendants((childNode, childPos) => {
|
|
44
43
|
const inDocPos = nodePos + childPos;
|
|
45
44
|
if (isSectionTitleNode(childNode) &&
|
package/dist/es/plugins/toc.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { ObjectTypes, } from '@manuscripts/json-schema';
|
|
17
|
-
import { generateID, hasObjectType, isSectionNodeType, isTOCSectionNode, } from '@manuscripts/transform';
|
|
17
|
+
import { generateID, hasObjectType, isSectionNodeType, isTOCSectionNode, schema, } from '@manuscripts/transform';
|
|
18
18
|
import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
|
|
19
19
|
import { getMatchingChild, iterateChildren } from '../lib/utils';
|
|
20
20
|
export const tocKey = new PluginKey('toc');
|
|
@@ -34,32 +34,37 @@ const buildTOCList = (headingStyles, list, node, depth = 1, prefix = '') => {
|
|
|
34
34
|
? sectionNumberingStyle.suffix
|
|
35
35
|
: '.';
|
|
36
36
|
let index = sectionNumberingStyle ? sectionNumberingStyle.startIndex : 1;
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
37
|
+
node.forEach((child) => {
|
|
38
|
+
if (child.type === schema.nodes.body) {
|
|
39
|
+
for (const childNode of iterateChildren(child)) {
|
|
40
|
+
if (isSectionNodeType(childNode.type) && !isTOCSectionNode(childNode)) {
|
|
41
|
+
const numbering = numberingScheme === 'none' ? '' : `${prefix}${index}`;
|
|
42
|
+
const firstChildNode = childNode.child(0);
|
|
43
|
+
if (firstChildNode.type ===
|
|
44
|
+
firstChildNode.type.schema.nodes.section_title) {
|
|
45
|
+
const item = document.createElement('li');
|
|
46
|
+
item.classList.add('manuscript-toc-list-item');
|
|
47
|
+
item.setAttribute('data-referenced-section', childNode.attrs.id);
|
|
48
|
+
item.setAttribute('data-referenced-section-path-length', String(depth));
|
|
49
|
+
item.textContent = `${numbering ? `${numbering}${suffix}` : ''} ${firstChildNode.textContent || 'Untitled Section'}`;
|
|
50
|
+
list.appendChild(item);
|
|
51
|
+
}
|
|
52
|
+
const childSection = getMatchingChild(childNode, (node) => isSectionNodeType(node.type));
|
|
53
|
+
if (childSection) {
|
|
54
|
+
const paragraphStyle = headingStyles.get(`heading${depth + 1}`);
|
|
55
|
+
if (!paragraphStyle || paragraphStyle.partOfTOC) {
|
|
56
|
+
const sublist = document.createElement('ul');
|
|
57
|
+
buildTOCList(headingStyles, sublist, childNode, depth + 1, numbering ? `${numbering}.` : '');
|
|
58
|
+
const item = document.createElement('li');
|
|
59
|
+
item.appendChild(sublist);
|
|
60
|
+
list.appendChild(item);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
index++;
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
|
-
index++;
|
|
61
66
|
}
|
|
62
|
-
}
|
|
67
|
+
});
|
|
63
68
|
};
|
|
64
69
|
const isParagraphStyle = hasObjectType(ObjectTypes.ParagraphStyle);
|
|
65
70
|
const buildHeadingStyles = (modelMap) => {
|
package/dist/es/useEditor.js
CHANGED
|
@@ -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 { NodeSelection,
|
|
16
|
+
import { NodeSelection, } from 'prosemirror-state';
|
|
17
17
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
18
18
|
import { useHistory } from 'react-router-dom';
|
|
19
19
|
import { bibliographyKey } from './plugins/bibliography';
|
|
@@ -66,9 +66,7 @@ const useEditor = (initialState, createView) => {
|
|
|
66
66
|
state.doc.descendants((node, pos) => {
|
|
67
67
|
if (node.attrs.id === id) {
|
|
68
68
|
currentView.focus();
|
|
69
|
-
const selection =
|
|
70
|
-
? NodeSelection.create(state.tr.doc, pos)
|
|
71
|
-
: TextSelection.near(state.tr.doc.resolve(pos + 1));
|
|
69
|
+
const selection = NodeSelection.create(state.tr.doc, pos);
|
|
72
70
|
currentView.dispatch(state.tr.setSelection(selection));
|
|
73
71
|
const dom = currentView.domAtPos(pos + 1);
|
|
74
72
|
if (dom.node instanceof Element) {
|