@eeacms/volto-slate-footnote 4.0.5 → 5.0.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.
- package/CHANGELOG.md +7 -1
- package/package.json +1 -1
- package/src/editor/FootnoteEditor.jsx +19 -10
- package/src/editor/utils.js +45 -31
- package/src/index.js +10 -5
package/CHANGELOG.md
CHANGED
|
@@ -4,9 +4,15 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
+
#### [5.0.0](https://github.com/eea/volto-slate-footnote/compare/4.0.5...5.0.0)
|
|
8
|
+
|
|
9
|
+
- feat(footnotes): Add blocksWithFootnotesSupport config settings [`ed3de55`](https://github.com/eea/volto-slate-footnote/commit/ed3de5546b409c7c9f149a28407110959d198f68)
|
|
10
|
+
|
|
7
11
|
#### [4.0.5](https://github.com/eea/volto-slate-footnote/compare/4.0.4...4.0.5)
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
> 17 May 2022
|
|
14
|
+
|
|
15
|
+
- Allow other block types to define footnotes - refs #148688 [`#31`](https://github.com/eea/volto-slate-footnote/pull/31)
|
|
10
16
|
|
|
11
17
|
#### [4.0.4](https://github.com/eea/volto-slate-footnote/compare/4.0.3...4.0.4)
|
|
12
18
|
|
package/package.json
CHANGED
|
@@ -67,18 +67,27 @@ const FootnoteEditor = (props) => {
|
|
|
67
67
|
// add label and value for the multi search widget
|
|
68
68
|
// flatten blocks to add all extra in the list
|
|
69
69
|
flatAllBlocks
|
|
70
|
-
.filter((b) =>
|
|
71
|
-
.forEach((
|
|
72
|
-
|
|
70
|
+
.filter((b) => b['@type'] in config.settings.blocksWithFootnotesSupport)
|
|
71
|
+
.forEach((element) => {
|
|
72
|
+
const mapping = config.settings.blocksWithFootnotesSupport[
|
|
73
|
+
element['@type']
|
|
74
|
+
] || ['value'];
|
|
73
75
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
mapping.forEach((key) => {
|
|
77
|
+
const value = element[key];
|
|
78
|
+
if (!value) return;
|
|
79
|
+
|
|
80
|
+
value.forEach((item) => {
|
|
81
|
+
Array.from(Node.elements(item)).forEach(([block]) => {
|
|
82
|
+
block.children.forEach((node) => {
|
|
83
|
+
if (node.data && node.type === 'footnote') {
|
|
84
|
+
manageAddBlockToUniqueBlocks(uniqueFootnoteBlocks, node.data);
|
|
85
|
+
(node.data.extra || []).forEach((ftitem) => {
|
|
86
|
+
manageAddBlockToUniqueBlocks(uniqueFootnoteBlocks, ftitem);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
80
89
|
});
|
|
81
|
-
}
|
|
90
|
+
});
|
|
82
91
|
});
|
|
83
92
|
});
|
|
84
93
|
});
|
package/src/editor/utils.js
CHANGED
|
@@ -118,38 +118,52 @@ export const makeFootnoteListOfUniqueItems = (blocks) => {
|
|
|
118
118
|
let notesObjResult = {};
|
|
119
119
|
|
|
120
120
|
blocks
|
|
121
|
-
.filter((b) =>
|
|
122
|
-
.forEach((
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
)
|
|
121
|
+
.filter((b) => b['@type'] in config.settings.blocksWithFootnotesSupport)
|
|
122
|
+
.forEach((element) => {
|
|
123
|
+
const mapping = config.settings.blocksWithFootnotesSupport[
|
|
124
|
+
element['@type']
|
|
125
|
+
] || ['value'];
|
|
126
|
+
|
|
127
|
+
mapping.forEach((key) => {
|
|
128
|
+
const value = element[key];
|
|
129
|
+
if (!value) return;
|
|
130
|
+
|
|
131
|
+
value.forEach((item) => {
|
|
132
|
+
// Node.elements(item) returns an iterable generator of nodes
|
|
133
|
+
Array.from(Node.elements(item)).forEach(([node]) => {
|
|
134
|
+
if (footnotes.includes(node.type) && node.data) {
|
|
135
|
+
// for citations (Zotero items) create refs for same zoteroId
|
|
136
|
+
if (node.data.zoteroId) {
|
|
137
|
+
iterateZoteroObj(notesObjResult, node.data);
|
|
138
|
+
// itereate the extra obj for multiple citations
|
|
139
|
+
if (node.data.extra) {
|
|
140
|
+
node.data.extra.forEach((zoteroObjItem) =>
|
|
141
|
+
// send the uid of the parent
|
|
142
|
+
// of the word the will have the reference indice
|
|
143
|
+
iterateZoteroObj(
|
|
144
|
+
notesObjResult,
|
|
145
|
+
zoteroObjItem,
|
|
146
|
+
node.data.uid,
|
|
147
|
+
),
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
// for footnotes - create refs, on identical text
|
|
151
|
+
} else {
|
|
152
|
+
iterateFootnoteObj(notesObjResult, node.data);
|
|
153
|
+
if (node.data.extra) {
|
|
154
|
+
node.data.extra.forEach((footnoteObjItem) =>
|
|
155
|
+
// since is called in case of extra, the parent is needed
|
|
156
|
+
iterateFootnoteObj(
|
|
157
|
+
notesObjResult,
|
|
158
|
+
footnoteObjItem,
|
|
159
|
+
node.data.uid,
|
|
160
|
+
),
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
137
164
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
iterateFootnoteObj(notesObjResult, node.data);
|
|
141
|
-
if (node.data.extra) {
|
|
142
|
-
node.data.extra.forEach((footnoteObjItem) =>
|
|
143
|
-
// since is called in case of extra, the parent is needed
|
|
144
|
-
iterateFootnoteObj(
|
|
145
|
-
notesObjResult,
|
|
146
|
-
footnoteObjItem,
|
|
147
|
-
node.data.uid,
|
|
148
|
-
),
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
153
167
|
});
|
|
154
168
|
});
|
|
155
169
|
|
package/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import codeSVG from '@plone/volto/icons/blog-entry.svg';
|
|
|
3
3
|
import FootnotesBlockView from './Blocks/Footnote/FootnotesBlockView';
|
|
4
4
|
import FootnotesBlockEdit from './Blocks/Footnote/FootnotesBlockEdit';
|
|
5
5
|
import FootnotesBlockSchema from './Blocks/Footnote/FootnotesBlockSchema';
|
|
6
|
-
import { FOOTNOTE
|
|
6
|
+
import { FOOTNOTE } from './constants';
|
|
7
7
|
import installFootnoteEditor from './editor';
|
|
8
8
|
import SearchWidget from '@eeacms/volto-slate-footnote/editor/MultiSelectSearchWidget';
|
|
9
9
|
|
|
@@ -36,10 +36,15 @@ export default function install(config) {
|
|
|
36
36
|
config.widgets.widget.searchInput = SearchWidget;
|
|
37
37
|
config = installFootnoteEditor(config);
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
]
|
|
39
|
+
// Some blocks may have multiple slate fields,
|
|
40
|
+
// thus provide these fields per block type in order to lookup for footnotes:
|
|
41
|
+
//
|
|
42
|
+
// 'my-custom-block-type': ['value', 'field1', 'field2']
|
|
43
|
+
//
|
|
44
|
+
config.settings.blocksWithFootnotesSupport = {
|
|
45
|
+
...(config.settings.blocksWithFootnotesSupport || {}),
|
|
46
|
+
slate: ['value'],
|
|
47
|
+
};
|
|
43
48
|
|
|
44
49
|
return config;
|
|
45
50
|
}
|