@manuscripts/body-editor 2.8.41 → 2.8.47
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 +47 -37
- package/dist/cjs/configs/editor-plugins.js +2 -0
- package/dist/cjs/configs/editor-views.js +3 -2
- package/dist/cjs/lib/utils.js +23 -1
- package/dist/cjs/plugins/accessibility_element.js +133 -0
- package/dist/cjs/plugins/alt-titles.js +2 -12
- package/dist/cjs/plugins/objects.js +2 -1
- package/dist/cjs/versions.js +1 -1
- package/dist/cjs/views/accessibility_element.js +33 -0
- package/dist/cjs/views/table_element.js +1 -0
- package/dist/es/commands.js +48 -38
- package/dist/es/configs/editor-plugins.js +2 -0
- package/dist/es/configs/editor-views.js +3 -2
- package/dist/es/lib/utils.js +20 -0
- package/dist/es/plugins/accessibility_element.js +128 -0
- package/dist/es/plugins/alt-titles.js +2 -12
- package/dist/es/plugins/objects.js +2 -1
- package/dist/es/versions.js +1 -1
- package/dist/es/views/accessibility_element.js +26 -0
- package/dist/es/views/table_element.js +1 -0
- package/dist/types/commands.d.ts +1 -1
- package/dist/types/lib/utils.d.ts +2 -0
- package/dist/types/plugins/accessibility_element.d.ts +13 -0
- package/dist/types/versions.d.ts +1 -1
- package/dist/types/views/accessibility_element.d.ts +10 -0
- package/dist/types/views/table_element.d.ts +1 -0
- package/package.json +3 -3
- package/styles/AdvancedEditor.css +62 -7
package/dist/cjs/commands.js
CHANGED
|
@@ -32,6 +32,7 @@ const footnotes_1 = require("./lib/footnotes");
|
|
|
32
32
|
const helpers_1 = require("./lib/helpers");
|
|
33
33
|
const track_changes_utils_1 = require("./lib/track-changes-utils");
|
|
34
34
|
const utils_1 = require("./lib/utils");
|
|
35
|
+
const accessibility_element_1 = require("./plugins/accessibility_element");
|
|
35
36
|
const comments_2 = require("./plugins/comments");
|
|
36
37
|
const editor_props_1 = require("./plugins/editor-props");
|
|
37
38
|
const search_replace_1 = require("./plugins/search-replace");
|
|
@@ -145,30 +146,28 @@ exports.createSelection = createSelection;
|
|
|
145
146
|
const createBlock = (nodeType, position, state, dispatch, attrs) => {
|
|
146
147
|
let node;
|
|
147
148
|
switch (nodeType) {
|
|
148
|
-
case
|
|
149
|
-
node = (0, exports.createAndFillTableElement)(
|
|
149
|
+
case transform_1.schema.nodes.table_element:
|
|
150
|
+
node = (0, exports.createAndFillTableElement)(attrs);
|
|
150
151
|
break;
|
|
151
|
-
case
|
|
152
|
-
node = createAndFillFigureElement(
|
|
152
|
+
case transform_1.schema.nodes.figure_element:
|
|
153
|
+
node = createAndFillFigureElement(attrs);
|
|
153
154
|
break;
|
|
154
|
-
case
|
|
155
|
-
node = createImageElement(
|
|
155
|
+
case transform_1.schema.nodes.image_element:
|
|
156
|
+
node = createImageElement(attrs);
|
|
156
157
|
break;
|
|
157
|
-
case
|
|
158
|
-
node =
|
|
159
|
-
|
|
160
|
-
createAndFillFigcaptionElement(
|
|
158
|
+
case transform_1.schema.nodes.listing_element:
|
|
159
|
+
node = transform_1.schema.nodes.listing_element.create({}, [
|
|
160
|
+
transform_1.schema.nodes.listing.create(),
|
|
161
|
+
createAndFillFigcaptionElement(),
|
|
161
162
|
]);
|
|
162
163
|
break;
|
|
163
|
-
case
|
|
164
|
-
node =
|
|
165
|
-
|
|
164
|
+
case transform_1.schema.nodes.equation_element:
|
|
165
|
+
node = transform_1.schema.nodes.equation_element.create({}, [
|
|
166
|
+
transform_1.schema.nodes.equation.create(),
|
|
166
167
|
]);
|
|
167
168
|
break;
|
|
168
|
-
case
|
|
169
|
-
node =
|
|
170
|
-
createAndFillFigcaptionElement(state),
|
|
171
|
-
]);
|
|
169
|
+
case transform_1.schema.nodes.embed:
|
|
170
|
+
node = createEmbedElement(attrs);
|
|
172
171
|
break;
|
|
173
172
|
default:
|
|
174
173
|
node = nodeType.createAndFill(attrs);
|
|
@@ -176,6 +175,7 @@ const createBlock = (nodeType, position, state, dispatch, attrs) => {
|
|
|
176
175
|
const tr = state.tr.insert(position, node);
|
|
177
176
|
if (dispatch) {
|
|
178
177
|
const selection = (0, exports.createSelection)(nodeType, position, tr.doc);
|
|
178
|
+
(0, accessibility_element_1.expandAccessibilitySection)(tr, node);
|
|
179
179
|
dispatch(tr.setSelection(selection).scrollIntoView());
|
|
180
180
|
}
|
|
181
181
|
};
|
|
@@ -211,7 +211,7 @@ const insertGeneralTableFootnote = (element, state, dispatch) => {
|
|
|
211
211
|
}
|
|
212
212
|
const tr = state.tr;
|
|
213
213
|
const footer = (0, exports.insertTableElementFooter)(tr, element);
|
|
214
|
-
const pos = footer.pos +
|
|
214
|
+
const pos = footer.pos + 2;
|
|
215
215
|
const node = transform_1.schema.nodes.general_table_footnote.create({}, [
|
|
216
216
|
transform_1.schema.nodes.paragraph.create(),
|
|
217
217
|
]);
|
|
@@ -247,8 +247,9 @@ const insertTable = (config, state, dispatch) => {
|
|
|
247
247
|
if (!pos) {
|
|
248
248
|
return false;
|
|
249
249
|
}
|
|
250
|
-
const node = (0, exports.createAndFillTableElement)(
|
|
250
|
+
const node = (0, exports.createAndFillTableElement)(config);
|
|
251
251
|
const tr = state.tr.insert(pos, node);
|
|
252
|
+
(0, accessibility_element_1.expandAccessibilitySection)(tr, node);
|
|
252
253
|
tr.setSelection(prosemirror_state_1.NodeSelection.create(tr.doc, pos)).scrollIntoView();
|
|
253
254
|
dispatch && dispatch(tr);
|
|
254
255
|
return true;
|
|
@@ -447,7 +448,7 @@ exports.insertInlineEquation = insertInlineEquation;
|
|
|
447
448
|
const insertTableElementFooter = (tr, table) => {
|
|
448
449
|
const footer = (0, prosemirror_utils_1.findChildrenByType)(table[0], transform_1.schema.nodes.table_element_footer)[0];
|
|
449
450
|
if (footer) {
|
|
450
|
-
const pos = tr.mapping.map(table[1] + footer.pos
|
|
451
|
+
const pos = tr.mapping.map(table[1] + footer.pos);
|
|
451
452
|
if ((0, track_changes_utils_1.isDeleted)(footer.node)) {
|
|
452
453
|
reinstateNode(tr, footer.node, pos);
|
|
453
454
|
}
|
|
@@ -456,7 +457,7 @@ const insertTableElementFooter = (tr, table) => {
|
|
|
456
457
|
pos,
|
|
457
458
|
};
|
|
458
459
|
}
|
|
459
|
-
const pos = tr.mapping.map(table[
|
|
460
|
+
const pos = tr.mapping.map((0, utils_1.getInsertPos)(transform_1.schema.nodes.table_element_footer, table[0], table[1]));
|
|
460
461
|
const node = transform_1.schema.nodes.table_element_footer.create();
|
|
461
462
|
tr.insert(pos, node);
|
|
462
463
|
return {
|
|
@@ -467,6 +468,7 @@ const insertTableElementFooter = (tr, table) => {
|
|
|
467
468
|
exports.insertTableElementFooter = insertTableElementFooter;
|
|
468
469
|
const insertFootnotesElement = (tr, container) => {
|
|
469
470
|
let pos;
|
|
471
|
+
const node = transform_1.schema.nodes.footnotes_element.create();
|
|
470
472
|
if ((0, transform_1.isTableElementNode)(container[0])) {
|
|
471
473
|
const footer = (0, exports.insertTableElementFooter)(tr, container);
|
|
472
474
|
pos = footer.pos + footer.node.nodeSize - 1;
|
|
@@ -474,9 +476,8 @@ const insertFootnotesElement = (tr, container) => {
|
|
|
474
476
|
else {
|
|
475
477
|
const section = (0, doc_1.insertFootnotesSection)(tr);
|
|
476
478
|
pos = section.pos + section.node.nodeSize - 1;
|
|
479
|
+
tr.insert(pos, node);
|
|
477
480
|
}
|
|
478
|
-
const node = transform_1.schema.nodes.footnotes_element.create();
|
|
479
|
-
tr.insert(pos, node);
|
|
480
481
|
return [node, pos];
|
|
481
482
|
};
|
|
482
483
|
exports.insertFootnotesElement = insertFootnotesElement;
|
|
@@ -999,7 +1000,7 @@ const DEFAULT_TABLE_CONFIG = {
|
|
|
999
1000
|
numberOfRows: 2,
|
|
1000
1001
|
includeHeader: true,
|
|
1001
1002
|
};
|
|
1002
|
-
const createAndFillTableElement = (
|
|
1003
|
+
const createAndFillTableElement = (attrs, config = DEFAULT_TABLE_CONFIG) => {
|
|
1003
1004
|
const { numberOfColumns, numberOfRows, includeHeader } = config;
|
|
1004
1005
|
const createRow = (cellType) => {
|
|
1005
1006
|
const cells = Array.from({ length: numberOfColumns }, () => cellType.create({}, transform_1.schema.nodes.text_block.create()));
|
|
@@ -1009,26 +1010,35 @@ const createAndFillTableElement = (state, config = DEFAULT_TABLE_CONFIG) => {
|
|
|
1009
1010
|
for (let i = 0; i < numberOfRows; i++) {
|
|
1010
1011
|
tableRows.push(createRow(transform_1.schema.nodes.table_cell));
|
|
1011
1012
|
}
|
|
1012
|
-
return transform_1.schema.nodes.table_element.createChecked({}, [
|
|
1013
|
-
createAndFillFigcaptionElement(
|
|
1013
|
+
return transform_1.schema.nodes.table_element.createChecked(Object.assign(Object.assign({}, attrs), { id: (0, transform_1.generateNodeID)(transform_1.schema.nodes.table_element) }), [
|
|
1014
|
+
createAndFillFigcaptionElement(),
|
|
1014
1015
|
transform_1.schema.nodes.table.create({}, tableRows),
|
|
1016
|
+
transform_1.schema.nodes.alt_text.create(),
|
|
1017
|
+
transform_1.schema.nodes.long_desc.create(),
|
|
1015
1018
|
transform_1.schema.nodes.listing.create(),
|
|
1016
1019
|
]);
|
|
1017
1020
|
};
|
|
1018
1021
|
exports.createAndFillTableElement = createAndFillTableElement;
|
|
1019
|
-
const createAndFillFigureElement = (
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1022
|
+
const createAndFillFigureElement = (attrs) => transform_1.schema.nodes.figure_element.create(Object.assign(Object.assign({}, attrs), { id: (0, transform_1.generateNodeID)(transform_1.schema.nodes.figure_element) }), [
|
|
1023
|
+
transform_1.schema.nodes.figure.create({}, [transform_1.schema.nodes.figcaption.create()]),
|
|
1024
|
+
createAndFillFigcaptionElement(),
|
|
1025
|
+
transform_1.schema.nodes.alt_text.create(),
|
|
1026
|
+
transform_1.schema.nodes.long_desc.create(),
|
|
1027
|
+
transform_1.schema.nodes.listing.create(),
|
|
1028
|
+
]);
|
|
1029
|
+
const createAndFillFigcaptionElement = () => transform_1.schema.nodes.figcaption.create({}, [
|
|
1030
|
+
transform_1.schema.nodes.caption_title.create(),
|
|
1031
|
+
transform_1.schema.nodes.caption.create(),
|
|
1025
1032
|
]);
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1028
|
-
|
|
1033
|
+
const createImageElement = (attrs) => transform_1.schema.nodes.image_element.create(Object.assign(Object.assign({}, attrs), { id: (0, transform_1.generateNodeID)(transform_1.schema.nodes.image_element) }), [
|
|
1034
|
+
transform_1.schema.nodes.figure.create(),
|
|
1035
|
+
transform_1.schema.nodes.alt_text.create(),
|
|
1036
|
+
transform_1.schema.nodes.long_desc.create(),
|
|
1029
1037
|
]);
|
|
1030
|
-
const
|
|
1031
|
-
|
|
1038
|
+
const createEmbedElement = (attrs) => transform_1.schema.nodes.embed.create(Object.assign(Object.assign({}, attrs), { id: (0, transform_1.generateNodeID)(transform_1.schema.nodes.embed) }), [
|
|
1039
|
+
createAndFillFigcaptionElement(),
|
|
1040
|
+
transform_1.schema.nodes.alt_text.create(),
|
|
1041
|
+
transform_1.schema.nodes.long_desc.create(),
|
|
1032
1042
|
]);
|
|
1033
1043
|
const getParentNode = (selection) => {
|
|
1034
1044
|
var _a;
|
|
@@ -26,6 +26,7 @@ const prosemirror_dropcursor_1 = require("prosemirror-dropcursor");
|
|
|
26
26
|
const prosemirror_history_1 = require("prosemirror-history");
|
|
27
27
|
const prosemirror_tables_1 = require("prosemirror-tables");
|
|
28
28
|
const keys_1 = __importDefault(require("../keys"));
|
|
29
|
+
const accessibility_element_1 = __importDefault(require("../plugins/accessibility_element"));
|
|
29
30
|
const affiliations_1 = __importDefault(require("../plugins/affiliations"));
|
|
30
31
|
const alt_titles_1 = __importDefault(require("../plugins/alt-titles"));
|
|
31
32
|
const bibliography_1 = __importDefault(require("../plugins/bibliography"));
|
|
@@ -79,6 +80,7 @@ exports.default = (props) => {
|
|
|
79
80
|
(0, search_replace_1.default)(),
|
|
80
81
|
(0, lock_body_1.default)(),
|
|
81
82
|
(0, alt_titles_1.default)(),
|
|
83
|
+
(0, accessibility_element_1.default)(),
|
|
82
84
|
];
|
|
83
85
|
if (props.collabProvider) {
|
|
84
86
|
allPlugins.push((0, prosemirror_collab_1.collab)({ version: props.collabProvider.currentVersion }));
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const accessibility_element_1 = __importDefault(require("../views/accessibility_element"));
|
|
6
7
|
const affiliations_1 = __importDefault(require("../views/affiliations"));
|
|
7
8
|
const alt_title_1 = __importDefault(require("../views/alt_title"));
|
|
8
9
|
const alt_titles_section_1 = __importDefault(require("../views/alt_titles_section"));
|
|
@@ -87,7 +88,7 @@ exports.default = (props, dispatch) => {
|
|
|
87
88
|
author_notes: (0, author_notes_1.default)(props, dispatch),
|
|
88
89
|
awards: (0, awards_1.default)(props, dispatch),
|
|
89
90
|
award: (0, award_1.default)(props, dispatch),
|
|
90
|
-
long_desc: (0,
|
|
91
|
-
alt_text: (0,
|
|
91
|
+
long_desc: (0, accessibility_element_1.default)(props, dispatch),
|
|
92
|
+
alt_text: (0, accessibility_element_1.default)(props, dispatch),
|
|
92
93
|
};
|
|
93
94
|
};
|
package/dist/cjs/lib/utils.js
CHANGED
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.isEditAllowed = exports.isBodyLocked = exports.createHeader = exports.isSelectionInBody = exports.isSelectionInNode = exports.isChildOfNodeTypes = exports.findParentElement = exports.findParentSection = exports.findParentNodeWithIdValue = exports.findParentNodeWithId = exports.getChildOfType = exports.getMatchingDescendant = exports.getMatchingChild = exports.iterateChildren = void 0;
|
|
18
|
+
exports.getInsertPos = exports.createToggleButton = exports.isEditAllowed = exports.isBodyLocked = exports.createHeader = exports.isSelectionInBody = exports.isSelectionInNode = exports.isChildOfNodeTypes = exports.findParentElement = exports.findParentSection = exports.findParentNodeWithIdValue = exports.findParentNodeWithId = exports.getChildOfType = exports.getMatchingDescendant = exports.getMatchingChild = exports.iterateChildren = void 0;
|
|
19
19
|
const transform_1 = require("@manuscripts/transform");
|
|
20
20
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
21
|
+
const icons_1 = require("../icons");
|
|
21
22
|
const editor_props_1 = require("../plugins/editor-props");
|
|
22
23
|
function* iterateChildren(node, recurse = false) {
|
|
23
24
|
for (let i = 0; i < node.childCount; i++) {
|
|
@@ -110,3 +111,24 @@ const isEditAllowed = (state) => {
|
|
|
110
111
|
return !((0, exports.isBodyLocked)(state) && (0, exports.isSelectionInBody)(state));
|
|
111
112
|
};
|
|
112
113
|
exports.isEditAllowed = isEditAllowed;
|
|
114
|
+
const createToggleButton = (listener) => {
|
|
115
|
+
const altTitlesButton = document.createElement('button');
|
|
116
|
+
altTitlesButton.classList.add('toggle-button-open', 'button-reset');
|
|
117
|
+
altTitlesButton.innerHTML = icons_1.arrowDown;
|
|
118
|
+
altTitlesButton.addEventListener('click', (e) => {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
listener();
|
|
121
|
+
});
|
|
122
|
+
return altTitlesButton;
|
|
123
|
+
};
|
|
124
|
+
exports.createToggleButton = createToggleButton;
|
|
125
|
+
const getInsertPos = (type, parent, pos) => {
|
|
126
|
+
let insertPos = pos + parent.nodeSize - 1;
|
|
127
|
+
parent.forEach((child, offset, index) => {
|
|
128
|
+
if (parent.canReplaceWith(index, index, type)) {
|
|
129
|
+
insertPos = pos + offset;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return insertPos;
|
|
133
|
+
};
|
|
134
|
+
exports.getInsertPos = getInsertPos;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toggleAccessibilitySection = exports.expandAccessibilitySection = exports.accessibilityElementKey = void 0;
|
|
4
|
+
const transform_1 = require("@manuscripts/transform");
|
|
5
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
6
|
+
const prosemirror_view_1 = require("prosemirror-view");
|
|
7
|
+
const utils_1 = require("../lib/utils");
|
|
8
|
+
exports.accessibilityElementKey = new prosemirror_state_1.PluginKey('accessibility-element');
|
|
9
|
+
const nodeTypes = [transform_1.schema.nodes.alt_text, transform_1.schema.nodes.long_desc];
|
|
10
|
+
const handleExpandButtonClick = (view, node) => {
|
|
11
|
+
const tr = view.state.tr;
|
|
12
|
+
(0, exports.toggleAccessibilitySection)(tr, node);
|
|
13
|
+
view.dispatch(tr);
|
|
14
|
+
};
|
|
15
|
+
const isSelectionWithin = (node, pos, selection) => {
|
|
16
|
+
if (!selection || !nodeTypes.includes(node.type)) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const to = pos + node.nodeSize;
|
|
20
|
+
return selection.from >= pos && selection.to <= to;
|
|
21
|
+
};
|
|
22
|
+
const buildExpandButtonDecorations = (doc) => {
|
|
23
|
+
const decorations = [];
|
|
24
|
+
doc.descendants((node, pos) => {
|
|
25
|
+
var _a;
|
|
26
|
+
if ((_a = node.type.spec.content) === null || _a === void 0 ? void 0 : _a.includes('alt_text')) {
|
|
27
|
+
decorations.push(prosemirror_view_1.Decoration.widget(pos + node.nodeSize - 1, (view) => {
|
|
28
|
+
const container = document.createElement('div');
|
|
29
|
+
container.className =
|
|
30
|
+
'accessibility_element_expander_button_container';
|
|
31
|
+
container.appendChild((0, utils_1.createToggleButton)(() => handleExpandButtonClick(view, node)));
|
|
32
|
+
return container;
|
|
33
|
+
}, {
|
|
34
|
+
key: node.attrs.id,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return decorations;
|
|
39
|
+
};
|
|
40
|
+
const buildExpandedElementsDecorations = (doc, expandedElementIDs, selection) => {
|
|
41
|
+
const decorations = [];
|
|
42
|
+
doc.descendants((node, pos) => {
|
|
43
|
+
if (expandedElementIDs.has(node.attrs.id) ||
|
|
44
|
+
isSelectionWithin(node, pos, selection)) {
|
|
45
|
+
decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
|
|
46
|
+
class: 'show_accessibility_element',
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return decorations;
|
|
51
|
+
};
|
|
52
|
+
exports.default = () => {
|
|
53
|
+
return new prosemirror_state_1.Plugin({
|
|
54
|
+
key: exports.accessibilityElementKey,
|
|
55
|
+
state: {
|
|
56
|
+
init(config, instance) {
|
|
57
|
+
return {
|
|
58
|
+
expandButtonDecorations: buildExpandButtonDecorations(instance.doc),
|
|
59
|
+
expandedElementDecorations: [],
|
|
60
|
+
expandedElementIDs: new Set(),
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
apply(tr, value, oldState, newState) {
|
|
64
|
+
const s = {
|
|
65
|
+
expandButtonDecorations: value.expandButtonDecorations,
|
|
66
|
+
expandedElementDecorations: value.expandedElementDecorations,
|
|
67
|
+
expandedElementIDs: new Set(value.expandedElementIDs),
|
|
68
|
+
};
|
|
69
|
+
if (tr.docChanged) {
|
|
70
|
+
s.expandButtonDecorations = buildExpandButtonDecorations(newState.doc);
|
|
71
|
+
}
|
|
72
|
+
let expandedElementIDsChanged = false;
|
|
73
|
+
const meta = tr.getMeta(exports.accessibilityElementKey);
|
|
74
|
+
if (meta) {
|
|
75
|
+
expandedElementIDsChanged = true;
|
|
76
|
+
const isExpanded = s.expandedElementIDs.has(meta.id);
|
|
77
|
+
if (meta.action === 'add' ||
|
|
78
|
+
(meta.action === 'toggle' && !isExpanded)) {
|
|
79
|
+
s.expandedElementIDs.add(meta.id);
|
|
80
|
+
}
|
|
81
|
+
else if (meta.action === 'remove' ||
|
|
82
|
+
(meta.action === 'toggle' && isExpanded)) {
|
|
83
|
+
s.expandedElementIDs.delete(meta.id);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (tr.selectionSet) {
|
|
87
|
+
const $pos = tr.selection.$from;
|
|
88
|
+
for (let i = $pos.depth; i >= 0; i--) {
|
|
89
|
+
const node = $pos.node(i);
|
|
90
|
+
if (nodeTypes.includes(node.type)) {
|
|
91
|
+
const parent = $pos.node(i - 1);
|
|
92
|
+
s.expandedElementIDs.add(parent.attrs.id);
|
|
93
|
+
expandedElementIDsChanged = true;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (expandedElementIDsChanged || tr.docChanged) {
|
|
99
|
+
s.expandedElementDecorations = buildExpandedElementsDecorations(newState.doc, s.expandedElementIDs);
|
|
100
|
+
}
|
|
101
|
+
return s;
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
props: {
|
|
105
|
+
decorations: (state) => {
|
|
106
|
+
const pluginState = exports.accessibilityElementKey.getState(state);
|
|
107
|
+
if (pluginState) {
|
|
108
|
+
return prosemirror_view_1.DecorationSet.create(state.doc, [
|
|
109
|
+
...pluginState.expandButtonDecorations,
|
|
110
|
+
...pluginState.expandedElementDecorations,
|
|
111
|
+
]);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
const expandAccessibilitySection = (tr, node) => {
|
|
118
|
+
var _a;
|
|
119
|
+
if (node.attrs.id && ((_a = node.type.spec.content) === null || _a === void 0 ? void 0 : _a.includes('alt_text'))) {
|
|
120
|
+
tr.setMeta(exports.accessibilityElementKey, {
|
|
121
|
+
action: 'add',
|
|
122
|
+
id: node.attrs.id,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
exports.expandAccessibilitySection = expandAccessibilitySection;
|
|
127
|
+
const toggleAccessibilitySection = (tr, node) => {
|
|
128
|
+
tr.setMeta(exports.accessibilityElementKey, {
|
|
129
|
+
action: 'toggle',
|
|
130
|
+
id: node.attrs.id,
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
exports.toggleAccessibilitySection = toggleAccessibilitySection;
|
|
@@ -5,7 +5,7 @@ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
|
5
5
|
const transform_1 = require("@manuscripts/transform");
|
|
6
6
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
7
7
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
8
|
-
const
|
|
8
|
+
const utils_1 = require("../lib/utils");
|
|
9
9
|
function getTitlesData(doc) {
|
|
10
10
|
let title;
|
|
11
11
|
let runningTitle;
|
|
@@ -32,16 +32,6 @@ function getTitlesData(doc) {
|
|
|
32
32
|
});
|
|
33
33
|
return { title, runningTitle, shortTitle, altTitlesSection };
|
|
34
34
|
}
|
|
35
|
-
function createAltTitlesButton(listener) {
|
|
36
|
-
const altTitlesButton = document.createElement('button');
|
|
37
|
-
altTitlesButton.classList.add('alt-titles-open', 'button-reset');
|
|
38
|
-
altTitlesButton.innerHTML = icons_1.arrowDown;
|
|
39
|
-
altTitlesButton.addEventListener('click', (e) => {
|
|
40
|
-
e.preventDefault();
|
|
41
|
-
listener();
|
|
42
|
-
});
|
|
43
|
-
return altTitlesButton;
|
|
44
|
-
}
|
|
45
35
|
function selectionInAltTitles(from, to, state) {
|
|
46
36
|
if (state.runningTitle && state.shortTitle) {
|
|
47
37
|
const range = {
|
|
@@ -136,7 +126,7 @@ exports.default = () => {
|
|
|
136
126
|
else if (pState.title[0].textContent.length) {
|
|
137
127
|
const titleEnd = pState.title[0].nodeSize + pState.title[1];
|
|
138
128
|
decorations.push(prosemirror_view_1.Decoration.widget(titleEnd - 1, (view) => {
|
|
139
|
-
return
|
|
129
|
+
return (0, utils_1.createToggleButton)(() => {
|
|
140
130
|
const tr = view.state.tr.setMeta(exports.altTitlesKey, {
|
|
141
131
|
collapsed: false,
|
|
142
132
|
});
|
|
@@ -38,6 +38,7 @@ exports.default = () => {
|
|
|
38
38
|
const targets = exports.objectsKey.getState(state);
|
|
39
39
|
if (targets) {
|
|
40
40
|
state.doc.descendants((node, pos) => {
|
|
41
|
+
var _a;
|
|
41
42
|
const { id } = node.attrs;
|
|
42
43
|
if (id) {
|
|
43
44
|
const target = targets.get(id);
|
|
@@ -48,7 +49,7 @@ exports.default = () => {
|
|
|
48
49
|
labelNode.className = 'figure-label';
|
|
49
50
|
if (node.type.name === 'image_element') {
|
|
50
51
|
labelNode.textContent = target.label;
|
|
51
|
-
decorations.push(prosemirror_view_1.Decoration.widget(pos + node.nodeSize
|
|
52
|
+
decorations.push(prosemirror_view_1.Decoration.widget(pos + (((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize) || 0) + 1, labelNode));
|
|
52
53
|
}
|
|
53
54
|
else {
|
|
54
55
|
labelNode.textContent = target.label + ':';
|
package/dist/cjs/versions.js
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AccessibilityElementView = void 0;
|
|
7
|
+
const transform_1 = require("@manuscripts/transform");
|
|
8
|
+
const block_view_1 = __importDefault(require("./block_view"));
|
|
9
|
+
const creators_1 = require("./creators");
|
|
10
|
+
class AccessibilityElementView extends block_view_1.default {
|
|
11
|
+
initialise() {
|
|
12
|
+
this.createDOM();
|
|
13
|
+
this.createElement();
|
|
14
|
+
this.updateContents();
|
|
15
|
+
}
|
|
16
|
+
createDOM() {
|
|
17
|
+
this.dom = document.createElement('div');
|
|
18
|
+
this.dom.classList.add('accessibility_element');
|
|
19
|
+
const label = document.createElement('label');
|
|
20
|
+
label.className = 'accessibility_element_label';
|
|
21
|
+
label.innerText =
|
|
22
|
+
this.node.type === transform_1.schema.nodes.long_desc
|
|
23
|
+
? 'Long description'
|
|
24
|
+
: 'Alt text';
|
|
25
|
+
this.dom.appendChild(label);
|
|
26
|
+
}
|
|
27
|
+
createElement() {
|
|
28
|
+
super.createElement();
|
|
29
|
+
this.contentDOM.className = 'accessibility_element_input';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.AccessibilityElementView = AccessibilityElementView;
|
|
33
|
+
exports.default = (0, creators_1.createNodeView)(AccessibilityElementView);
|
|
@@ -25,6 +25,7 @@ class TableElementView extends block_view_1.default {
|
|
|
25
25
|
constructor() {
|
|
26
26
|
super(...arguments);
|
|
27
27
|
this.elementType = 'figure';
|
|
28
|
+
this.ignoreMutation = () => true;
|
|
28
29
|
this.createElement = () => {
|
|
29
30
|
this.contentDOM = document.createElement('figure');
|
|
30
31
|
this.contentDOM.classList.add('block');
|
package/dist/es/commands.js
CHANGED
|
@@ -27,7 +27,8 @@ import { findAbstractsNode, findBackmatter, findBibliographySection, findBody, f
|
|
|
27
27
|
import { createFootnote, findFootnotesContainerNode, getFootnotesElementState, } from './lib/footnotes';
|
|
28
28
|
import { findWordBoundaries, isNodeOfType, nearestAncestor, } from './lib/helpers';
|
|
29
29
|
import { isDeleted } from './lib/track-changes-utils';
|
|
30
|
-
import { findParentNodeWithId, getChildOfType, isBodyLocked } from './lib/utils';
|
|
30
|
+
import { findParentNodeWithId, getChildOfType, getInsertPos, isBodyLocked, } from './lib/utils';
|
|
31
|
+
import { expandAccessibilitySection } from './plugins/accessibility_element';
|
|
31
32
|
import { setCommentSelection } from './plugins/comments';
|
|
32
33
|
import { getEditorProps } from './plugins/editor-props';
|
|
33
34
|
import { searchReplaceKey } from './plugins/search-replace';
|
|
@@ -135,30 +136,28 @@ export const createSelection = (nodeType, position, doc) => {
|
|
|
135
136
|
export const createBlock = (nodeType, position, state, dispatch, attrs) => {
|
|
136
137
|
let node;
|
|
137
138
|
switch (nodeType) {
|
|
138
|
-
case
|
|
139
|
-
node = createAndFillTableElement(
|
|
139
|
+
case schema.nodes.table_element:
|
|
140
|
+
node = createAndFillTableElement(attrs);
|
|
140
141
|
break;
|
|
141
|
-
case
|
|
142
|
-
node = createAndFillFigureElement(
|
|
142
|
+
case schema.nodes.figure_element:
|
|
143
|
+
node = createAndFillFigureElement(attrs);
|
|
143
144
|
break;
|
|
144
|
-
case
|
|
145
|
-
node = createImageElement(
|
|
145
|
+
case schema.nodes.image_element:
|
|
146
|
+
node = createImageElement(attrs);
|
|
146
147
|
break;
|
|
147
|
-
case
|
|
148
|
-
node =
|
|
149
|
-
|
|
150
|
-
createAndFillFigcaptionElement(
|
|
148
|
+
case schema.nodes.listing_element:
|
|
149
|
+
node = schema.nodes.listing_element.create({}, [
|
|
150
|
+
schema.nodes.listing.create(),
|
|
151
|
+
createAndFillFigcaptionElement(),
|
|
151
152
|
]);
|
|
152
153
|
break;
|
|
153
|
-
case
|
|
154
|
-
node =
|
|
155
|
-
|
|
154
|
+
case schema.nodes.equation_element:
|
|
155
|
+
node = schema.nodes.equation_element.create({}, [
|
|
156
|
+
schema.nodes.equation.create(),
|
|
156
157
|
]);
|
|
157
158
|
break;
|
|
158
|
-
case
|
|
159
|
-
node =
|
|
160
|
-
createAndFillFigcaptionElement(state),
|
|
161
|
-
]);
|
|
159
|
+
case schema.nodes.embed:
|
|
160
|
+
node = createEmbedElement(attrs);
|
|
162
161
|
break;
|
|
163
162
|
default:
|
|
164
163
|
node = nodeType.createAndFill(attrs);
|
|
@@ -166,6 +165,7 @@ export const createBlock = (nodeType, position, state, dispatch, attrs) => {
|
|
|
166
165
|
const tr = state.tr.insert(position, node);
|
|
167
166
|
if (dispatch) {
|
|
168
167
|
const selection = createSelection(nodeType, position, tr.doc);
|
|
168
|
+
expandAccessibilitySection(tr, node);
|
|
169
169
|
dispatch(tr.setSelection(selection).scrollIntoView());
|
|
170
170
|
}
|
|
171
171
|
};
|
|
@@ -198,7 +198,7 @@ export const insertGeneralTableFootnote = (element, state, dispatch) => {
|
|
|
198
198
|
}
|
|
199
199
|
const tr = state.tr;
|
|
200
200
|
const footer = insertTableElementFooter(tr, element);
|
|
201
|
-
const pos = footer.pos +
|
|
201
|
+
const pos = footer.pos + 2;
|
|
202
202
|
const node = schema.nodes.general_table_footnote.create({}, [
|
|
203
203
|
schema.nodes.paragraph.create(),
|
|
204
204
|
]);
|
|
@@ -232,8 +232,9 @@ export const insertTable = (config, state, dispatch) => {
|
|
|
232
232
|
if (!pos) {
|
|
233
233
|
return false;
|
|
234
234
|
}
|
|
235
|
-
const node = createAndFillTableElement(
|
|
235
|
+
const node = createAndFillTableElement(config);
|
|
236
236
|
const tr = state.tr.insert(pos, node);
|
|
237
|
+
expandAccessibilitySection(tr, node);
|
|
237
238
|
tr.setSelection(NodeSelection.create(tr.doc, pos)).scrollIntoView();
|
|
238
239
|
dispatch && dispatch(tr);
|
|
239
240
|
return true;
|
|
@@ -420,7 +421,7 @@ export const insertInlineEquation = (state, dispatch) => {
|
|
|
420
421
|
export const insertTableElementFooter = (tr, table) => {
|
|
421
422
|
const footer = findChildrenByType(table[0], schema.nodes.table_element_footer)[0];
|
|
422
423
|
if (footer) {
|
|
423
|
-
const pos = tr.mapping.map(table[1] + footer.pos
|
|
424
|
+
const pos = tr.mapping.map(table[1] + footer.pos);
|
|
424
425
|
if (isDeleted(footer.node)) {
|
|
425
426
|
reinstateNode(tr, footer.node, pos);
|
|
426
427
|
}
|
|
@@ -429,7 +430,7 @@ export const insertTableElementFooter = (tr, table) => {
|
|
|
429
430
|
pos,
|
|
430
431
|
};
|
|
431
432
|
}
|
|
432
|
-
const pos = tr.mapping.map(table[
|
|
433
|
+
const pos = tr.mapping.map(getInsertPos(schema.nodes.table_element_footer, table[0], table[1]));
|
|
433
434
|
const node = schema.nodes.table_element_footer.create();
|
|
434
435
|
tr.insert(pos, node);
|
|
435
436
|
return {
|
|
@@ -439,6 +440,7 @@ export const insertTableElementFooter = (tr, table) => {
|
|
|
439
440
|
};
|
|
440
441
|
export const insertFootnotesElement = (tr, container) => {
|
|
441
442
|
let pos;
|
|
443
|
+
const node = schema.nodes.footnotes_element.create();
|
|
442
444
|
if (isTableElementNode(container[0])) {
|
|
443
445
|
const footer = insertTableElementFooter(tr, container);
|
|
444
446
|
pos = footer.pos + footer.node.nodeSize - 1;
|
|
@@ -446,9 +448,8 @@ export const insertFootnotesElement = (tr, container) => {
|
|
|
446
448
|
else {
|
|
447
449
|
const section = insertFootnotesSection(tr);
|
|
448
450
|
pos = section.pos + section.node.nodeSize - 1;
|
|
451
|
+
tr.insert(pos, node);
|
|
449
452
|
}
|
|
450
|
-
const node = schema.nodes.footnotes_element.create();
|
|
451
|
-
tr.insert(pos, node);
|
|
452
453
|
return [node, pos];
|
|
453
454
|
};
|
|
454
455
|
export const insertInlineFootnote = (state, dispatch) => {
|
|
@@ -950,7 +951,7 @@ const DEFAULT_TABLE_CONFIG = {
|
|
|
950
951
|
numberOfRows: 2,
|
|
951
952
|
includeHeader: true,
|
|
952
953
|
};
|
|
953
|
-
export const createAndFillTableElement = (
|
|
954
|
+
export const createAndFillTableElement = (attrs, config = DEFAULT_TABLE_CONFIG) => {
|
|
954
955
|
const { numberOfColumns, numberOfRows, includeHeader } = config;
|
|
955
956
|
const createRow = (cellType) => {
|
|
956
957
|
const cells = Array.from({ length: numberOfColumns }, () => cellType.create({}, schema.nodes.text_block.create()));
|
|
@@ -960,25 +961,34 @@ export const createAndFillTableElement = (state, config = DEFAULT_TABLE_CONFIG)
|
|
|
960
961
|
for (let i = 0; i < numberOfRows; i++) {
|
|
961
962
|
tableRows.push(createRow(schema.nodes.table_cell));
|
|
962
963
|
}
|
|
963
|
-
return schema.nodes.table_element.createChecked({}, [
|
|
964
|
-
createAndFillFigcaptionElement(
|
|
964
|
+
return schema.nodes.table_element.createChecked(Object.assign(Object.assign({}, attrs), { id: generateNodeID(schema.nodes.table_element) }), [
|
|
965
|
+
createAndFillFigcaptionElement(),
|
|
965
966
|
schema.nodes.table.create({}, tableRows),
|
|
967
|
+
schema.nodes.alt_text.create(),
|
|
968
|
+
schema.nodes.long_desc.create(),
|
|
966
969
|
schema.nodes.listing.create(),
|
|
967
970
|
]);
|
|
968
971
|
};
|
|
969
|
-
const createAndFillFigureElement = (
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
972
|
+
const createAndFillFigureElement = (attrs) => schema.nodes.figure_element.create(Object.assign(Object.assign({}, attrs), { id: generateNodeID(schema.nodes.figure_element) }), [
|
|
973
|
+
schema.nodes.figure.create({}, [schema.nodes.figcaption.create()]),
|
|
974
|
+
createAndFillFigcaptionElement(),
|
|
975
|
+
schema.nodes.alt_text.create(),
|
|
976
|
+
schema.nodes.long_desc.create(),
|
|
977
|
+
schema.nodes.listing.create(),
|
|
978
|
+
]);
|
|
979
|
+
const createAndFillFigcaptionElement = () => schema.nodes.figcaption.create({}, [
|
|
980
|
+
schema.nodes.caption_title.create(),
|
|
981
|
+
schema.nodes.caption.create(),
|
|
975
982
|
]);
|
|
976
|
-
const
|
|
977
|
-
|
|
978
|
-
|
|
983
|
+
const createImageElement = (attrs) => schema.nodes.image_element.create(Object.assign(Object.assign({}, attrs), { id: generateNodeID(schema.nodes.image_element) }), [
|
|
984
|
+
schema.nodes.figure.create(),
|
|
985
|
+
schema.nodes.alt_text.create(),
|
|
986
|
+
schema.nodes.long_desc.create(),
|
|
979
987
|
]);
|
|
980
|
-
const
|
|
981
|
-
|
|
988
|
+
const createEmbedElement = (attrs) => schema.nodes.embed.create(Object.assign(Object.assign({}, attrs), { id: generateNodeID(schema.nodes.embed) }), [
|
|
989
|
+
createAndFillFigcaptionElement(),
|
|
990
|
+
schema.nodes.alt_text.create(),
|
|
991
|
+
schema.nodes.long_desc.create(),
|
|
982
992
|
]);
|
|
983
993
|
const getParentNode = (selection) => {
|
|
984
994
|
var _a;
|
|
@@ -21,6 +21,7 @@ import { dropCursor } from 'prosemirror-dropcursor';
|
|
|
21
21
|
import { history } from 'prosemirror-history';
|
|
22
22
|
import { tableEditing } from 'prosemirror-tables';
|
|
23
23
|
import keys from '../keys';
|
|
24
|
+
import accessibility_element from '../plugins/accessibility_element';
|
|
24
25
|
import affiliations from '../plugins/affiliations';
|
|
25
26
|
import alt_titles from '../plugins/alt-titles';
|
|
26
27
|
import bibliography from '../plugins/bibliography';
|
|
@@ -74,6 +75,7 @@ export default (props) => {
|
|
|
74
75
|
search_replace(),
|
|
75
76
|
lock_body(),
|
|
76
77
|
alt_titles(),
|
|
78
|
+
accessibility_element(),
|
|
77
79
|
];
|
|
78
80
|
if (props.collabProvider) {
|
|
79
81
|
allPlugins.push(collab({ version: props.collabProvider.currentVersion }));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import accessibilityElement from '../views/accessibility_element';
|
|
1
2
|
import affiliations from '../views/affiliations';
|
|
2
3
|
import alt_title from '../views/alt_title';
|
|
3
4
|
import alt_titles_section from '../views/alt_titles_section';
|
|
@@ -82,7 +83,7 @@ export default (props, dispatch) => {
|
|
|
82
83
|
author_notes: authorNotes(props, dispatch),
|
|
83
84
|
awards: awards(props, dispatch),
|
|
84
85
|
award: award(props, dispatch),
|
|
85
|
-
long_desc:
|
|
86
|
-
alt_text:
|
|
86
|
+
long_desc: accessibilityElement(props, dispatch),
|
|
87
|
+
alt_text: accessibilityElement(props, dispatch),
|
|
87
88
|
};
|
|
88
89
|
};
|
package/dist/es/lib/utils.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { isElementNodeType, isSectionNodeType, schema, } from '@manuscripts/transform';
|
|
17
17
|
import { findChildrenByType, findParentNode } from 'prosemirror-utils';
|
|
18
|
+
import { arrowDown } from '../icons';
|
|
18
19
|
import { getEditorProps } from '../plugins/editor-props';
|
|
19
20
|
export function* iterateChildren(node, recurse = false) {
|
|
20
21
|
for (let i = 0; i < node.childCount; i++) {
|
|
@@ -96,3 +97,22 @@ export const isBodyLocked = (state) => {
|
|
|
96
97
|
export const isEditAllowed = (state) => {
|
|
97
98
|
return !(isBodyLocked(state) && isSelectionInBody(state));
|
|
98
99
|
};
|
|
100
|
+
export const createToggleButton = (listener) => {
|
|
101
|
+
const altTitlesButton = document.createElement('button');
|
|
102
|
+
altTitlesButton.classList.add('toggle-button-open', 'button-reset');
|
|
103
|
+
altTitlesButton.innerHTML = arrowDown;
|
|
104
|
+
altTitlesButton.addEventListener('click', (e) => {
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
listener();
|
|
107
|
+
});
|
|
108
|
+
return altTitlesButton;
|
|
109
|
+
};
|
|
110
|
+
export const getInsertPos = (type, parent, pos) => {
|
|
111
|
+
let insertPos = pos + parent.nodeSize - 1;
|
|
112
|
+
parent.forEach((child, offset, index) => {
|
|
113
|
+
if (parent.canReplaceWith(index, index, type)) {
|
|
114
|
+
insertPos = pos + offset;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return insertPos;
|
|
118
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { schema, } from '@manuscripts/transform';
|
|
2
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
3
|
+
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
4
|
+
import { createToggleButton } from '../lib/utils';
|
|
5
|
+
export const accessibilityElementKey = new PluginKey('accessibility-element');
|
|
6
|
+
const nodeTypes = [schema.nodes.alt_text, schema.nodes.long_desc];
|
|
7
|
+
const handleExpandButtonClick = (view, node) => {
|
|
8
|
+
const tr = view.state.tr;
|
|
9
|
+
toggleAccessibilitySection(tr, node);
|
|
10
|
+
view.dispatch(tr);
|
|
11
|
+
};
|
|
12
|
+
const isSelectionWithin = (node, pos, selection) => {
|
|
13
|
+
if (!selection || !nodeTypes.includes(node.type)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const to = pos + node.nodeSize;
|
|
17
|
+
return selection.from >= pos && selection.to <= to;
|
|
18
|
+
};
|
|
19
|
+
const buildExpandButtonDecorations = (doc) => {
|
|
20
|
+
const decorations = [];
|
|
21
|
+
doc.descendants((node, pos) => {
|
|
22
|
+
var _a;
|
|
23
|
+
if ((_a = node.type.spec.content) === null || _a === void 0 ? void 0 : _a.includes('alt_text')) {
|
|
24
|
+
decorations.push(Decoration.widget(pos + node.nodeSize - 1, (view) => {
|
|
25
|
+
const container = document.createElement('div');
|
|
26
|
+
container.className =
|
|
27
|
+
'accessibility_element_expander_button_container';
|
|
28
|
+
container.appendChild(createToggleButton(() => handleExpandButtonClick(view, node)));
|
|
29
|
+
return container;
|
|
30
|
+
}, {
|
|
31
|
+
key: node.attrs.id,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return decorations;
|
|
36
|
+
};
|
|
37
|
+
const buildExpandedElementsDecorations = (doc, expandedElementIDs, selection) => {
|
|
38
|
+
const decorations = [];
|
|
39
|
+
doc.descendants((node, pos) => {
|
|
40
|
+
if (expandedElementIDs.has(node.attrs.id) ||
|
|
41
|
+
isSelectionWithin(node, pos, selection)) {
|
|
42
|
+
decorations.push(Decoration.node(pos, pos + node.nodeSize, {
|
|
43
|
+
class: 'show_accessibility_element',
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return decorations;
|
|
48
|
+
};
|
|
49
|
+
export default () => {
|
|
50
|
+
return new Plugin({
|
|
51
|
+
key: accessibilityElementKey,
|
|
52
|
+
state: {
|
|
53
|
+
init(config, instance) {
|
|
54
|
+
return {
|
|
55
|
+
expandButtonDecorations: buildExpandButtonDecorations(instance.doc),
|
|
56
|
+
expandedElementDecorations: [],
|
|
57
|
+
expandedElementIDs: new Set(),
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
apply(tr, value, oldState, newState) {
|
|
61
|
+
const s = {
|
|
62
|
+
expandButtonDecorations: value.expandButtonDecorations,
|
|
63
|
+
expandedElementDecorations: value.expandedElementDecorations,
|
|
64
|
+
expandedElementIDs: new Set(value.expandedElementIDs),
|
|
65
|
+
};
|
|
66
|
+
if (tr.docChanged) {
|
|
67
|
+
s.expandButtonDecorations = buildExpandButtonDecorations(newState.doc);
|
|
68
|
+
}
|
|
69
|
+
let expandedElementIDsChanged = false;
|
|
70
|
+
const meta = tr.getMeta(accessibilityElementKey);
|
|
71
|
+
if (meta) {
|
|
72
|
+
expandedElementIDsChanged = true;
|
|
73
|
+
const isExpanded = s.expandedElementIDs.has(meta.id);
|
|
74
|
+
if (meta.action === 'add' ||
|
|
75
|
+
(meta.action === 'toggle' && !isExpanded)) {
|
|
76
|
+
s.expandedElementIDs.add(meta.id);
|
|
77
|
+
}
|
|
78
|
+
else if (meta.action === 'remove' ||
|
|
79
|
+
(meta.action === 'toggle' && isExpanded)) {
|
|
80
|
+
s.expandedElementIDs.delete(meta.id);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (tr.selectionSet) {
|
|
84
|
+
const $pos = tr.selection.$from;
|
|
85
|
+
for (let i = $pos.depth; i >= 0; i--) {
|
|
86
|
+
const node = $pos.node(i);
|
|
87
|
+
if (nodeTypes.includes(node.type)) {
|
|
88
|
+
const parent = $pos.node(i - 1);
|
|
89
|
+
s.expandedElementIDs.add(parent.attrs.id);
|
|
90
|
+
expandedElementIDsChanged = true;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (expandedElementIDsChanged || tr.docChanged) {
|
|
96
|
+
s.expandedElementDecorations = buildExpandedElementsDecorations(newState.doc, s.expandedElementIDs);
|
|
97
|
+
}
|
|
98
|
+
return s;
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
props: {
|
|
102
|
+
decorations: (state) => {
|
|
103
|
+
const pluginState = accessibilityElementKey.getState(state);
|
|
104
|
+
if (pluginState) {
|
|
105
|
+
return DecorationSet.create(state.doc, [
|
|
106
|
+
...pluginState.expandButtonDecorations,
|
|
107
|
+
...pluginState.expandedElementDecorations,
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
export const expandAccessibilitySection = (tr, node) => {
|
|
115
|
+
var _a;
|
|
116
|
+
if (node.attrs.id && ((_a = node.type.spec.content) === null || _a === void 0 ? void 0 : _a.includes('alt_text'))) {
|
|
117
|
+
tr.setMeta(accessibilityElementKey, {
|
|
118
|
+
action: 'add',
|
|
119
|
+
id: node.attrs.id,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
export const toggleAccessibilitySection = (tr, node) => {
|
|
124
|
+
tr.setMeta(accessibilityElementKey, {
|
|
125
|
+
action: 'toggle',
|
|
126
|
+
id: node.attrs.id,
|
|
127
|
+
});
|
|
128
|
+
};
|
|
@@ -2,7 +2,7 @@ import { skipTracking } from '@manuscripts/track-changes-plugin';
|
|
|
2
2
|
import { schema, } from '@manuscripts/transform';
|
|
3
3
|
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
4
4
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
5
|
-
import {
|
|
5
|
+
import { createToggleButton } from '../lib/utils';
|
|
6
6
|
function getTitlesData(doc) {
|
|
7
7
|
let title;
|
|
8
8
|
let runningTitle;
|
|
@@ -29,16 +29,6 @@ function getTitlesData(doc) {
|
|
|
29
29
|
});
|
|
30
30
|
return { title, runningTitle, shortTitle, altTitlesSection };
|
|
31
31
|
}
|
|
32
|
-
function createAltTitlesButton(listener) {
|
|
33
|
-
const altTitlesButton = document.createElement('button');
|
|
34
|
-
altTitlesButton.classList.add('alt-titles-open', 'button-reset');
|
|
35
|
-
altTitlesButton.innerHTML = arrowDown;
|
|
36
|
-
altTitlesButton.addEventListener('click', (e) => {
|
|
37
|
-
e.preventDefault();
|
|
38
|
-
listener();
|
|
39
|
-
});
|
|
40
|
-
return altTitlesButton;
|
|
41
|
-
}
|
|
42
32
|
function selectionInAltTitles(from, to, state) {
|
|
43
33
|
if (state.runningTitle && state.shortTitle) {
|
|
44
34
|
const range = {
|
|
@@ -133,7 +123,7 @@ export default () => {
|
|
|
133
123
|
else if (pState.title[0].textContent.length) {
|
|
134
124
|
const titleEnd = pState.title[0].nodeSize + pState.title[1];
|
|
135
125
|
decorations.push(Decoration.widget(titleEnd - 1, (view) => {
|
|
136
|
-
return
|
|
126
|
+
return createToggleButton(() => {
|
|
137
127
|
const tr = view.state.tr.setMeta(altTitlesKey, {
|
|
138
128
|
collapsed: false,
|
|
139
129
|
});
|
|
@@ -35,6 +35,7 @@ export default () => {
|
|
|
35
35
|
const targets = objectsKey.getState(state);
|
|
36
36
|
if (targets) {
|
|
37
37
|
state.doc.descendants((node, pos) => {
|
|
38
|
+
var _a;
|
|
38
39
|
const { id } = node.attrs;
|
|
39
40
|
if (id) {
|
|
40
41
|
const target = targets.get(id);
|
|
@@ -45,7 +46,7 @@ export default () => {
|
|
|
45
46
|
labelNode.className = 'figure-label';
|
|
46
47
|
if (node.type.name === 'image_element') {
|
|
47
48
|
labelNode.textContent = target.label;
|
|
48
|
-
decorations.push(Decoration.widget(pos + node.nodeSize
|
|
49
|
+
decorations.push(Decoration.widget(pos + (((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.nodeSize) || 0) + 1, labelNode));
|
|
49
50
|
}
|
|
50
51
|
else {
|
|
51
52
|
labelNode.textContent = target.label + ':';
|
package/dist/es/versions.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '2.8.
|
|
1
|
+
export const VERSION = '2.8.47';
|
|
2
2
|
export const MATHJAX_VERSION = '3.2.2';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { schema } from '@manuscripts/transform';
|
|
2
|
+
import BlockView from './block_view';
|
|
3
|
+
import { createNodeView } from './creators';
|
|
4
|
+
export class AccessibilityElementView extends BlockView {
|
|
5
|
+
initialise() {
|
|
6
|
+
this.createDOM();
|
|
7
|
+
this.createElement();
|
|
8
|
+
this.updateContents();
|
|
9
|
+
}
|
|
10
|
+
createDOM() {
|
|
11
|
+
this.dom = document.createElement('div');
|
|
12
|
+
this.dom.classList.add('accessibility_element');
|
|
13
|
+
const label = document.createElement('label');
|
|
14
|
+
label.className = 'accessibility_element_label';
|
|
15
|
+
label.innerText =
|
|
16
|
+
this.node.type === schema.nodes.long_desc
|
|
17
|
+
? 'Long description'
|
|
18
|
+
: 'Alt text';
|
|
19
|
+
this.dom.appendChild(label);
|
|
20
|
+
}
|
|
21
|
+
createElement() {
|
|
22
|
+
super.createElement();
|
|
23
|
+
this.contentDOM.className = 'accessibility_element_input';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export default createNodeView(AccessibilityElementView);
|
|
@@ -19,6 +19,7 @@ export class TableElementView extends BlockView {
|
|
|
19
19
|
constructor() {
|
|
20
20
|
super(...arguments);
|
|
21
21
|
this.elementType = 'figure';
|
|
22
|
+
this.ignoreMutation = () => true;
|
|
22
23
|
this.createElement = () => {
|
|
23
24
|
this.contentDOM = document.createElement('figure');
|
|
24
25
|
this.contentDOM.classList.add('block');
|
package/dist/types/commands.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ export type TableConfig = {
|
|
|
73
73
|
numberOfRows: number;
|
|
74
74
|
includeHeader: boolean;
|
|
75
75
|
};
|
|
76
|
-
export declare const createAndFillTableElement: (
|
|
76
|
+
export declare const createAndFillTableElement: (attrs?: Attrs, config?: TableConfig) => import("prosemirror-model").Node;
|
|
77
77
|
export declare const isCommentingAllowed: (type: NodeType) => boolean;
|
|
78
78
|
export declare const addNodeComment: (node: ManuscriptNode, state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
|
|
79
79
|
export declare const addInlineComment: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
|
|
@@ -30,3 +30,5 @@ export declare const isSelectionInBody: (state: EditorState) => boolean;
|
|
|
30
30
|
export declare const createHeader: (typeName: string, text: string) => HTMLHeadingElement;
|
|
31
31
|
export declare const isBodyLocked: (state: EditorState) => boolean;
|
|
32
32
|
export declare const isEditAllowed: (state: EditorState) => boolean;
|
|
33
|
+
export declare const createToggleButton: (listener: () => void) => HTMLButtonElement;
|
|
34
|
+
export declare const getInsertPos: (type: ManuscriptNodeType, parent: ManuscriptNode, pos: number) => number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ManuscriptNode, ManuscriptTransaction } from '@manuscripts/transform';
|
|
2
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
3
|
+
import { Decoration } from 'prosemirror-view';
|
|
4
|
+
export interface PluginState {
|
|
5
|
+
expandButtonDecorations: Decoration[];
|
|
6
|
+
expandedElementDecorations: Decoration[];
|
|
7
|
+
expandedElementIDs: Set<string>;
|
|
8
|
+
}
|
|
9
|
+
export declare const accessibilityElementKey: PluginKey<PluginState>;
|
|
10
|
+
declare const _default: () => Plugin<PluginState>;
|
|
11
|
+
export default _default;
|
|
12
|
+
export declare const expandAccessibilitySection: (tr: ManuscriptTransaction, node: ManuscriptNode) => void;
|
|
13
|
+
export declare const toggleAccessibilitySection: (tr: ManuscriptTransaction, node: ManuscriptNode) => void;
|
package/dist/types/versions.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "2.8.
|
|
1
|
+
export declare const VERSION = "2.8.47";
|
|
2
2
|
export declare const MATHJAX_VERSION = "3.2.2";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LongDescNode } from '@manuscripts/transform';
|
|
2
|
+
import BlockView from './block_view';
|
|
3
|
+
export declare class AccessibilityElementView extends BlockView<LongDescNode> {
|
|
4
|
+
contentDOM: HTMLElement;
|
|
5
|
+
initialise(): void;
|
|
6
|
+
createDOM(): void;
|
|
7
|
+
createElement(): void;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: (props: import("../configs/ManuscriptsEditor").EditorProps, dispatch?: import("..").Dispatch | undefined) => import("../types").NodeViewCreator<AccessibilityElementView>;
|
|
10
|
+
export default _default;
|
|
@@ -17,6 +17,7 @@ import { TableElementNode } from '@manuscripts/transform';
|
|
|
17
17
|
import BlockView from './block_view';
|
|
18
18
|
export declare class TableElementView extends BlockView<TableElementNode> {
|
|
19
19
|
elementType: string;
|
|
20
|
+
ignoreMutation: () => boolean;
|
|
20
21
|
createElement: () => void;
|
|
21
22
|
}
|
|
22
23
|
declare const _default: (props: import("../configs/ManuscriptsEditor").EditorProps, dispatch?: import("..").Dispatch | undefined) => import("../types").NodeViewCreator<TableElementView>;
|
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": "2.8.
|
|
4
|
+
"version": "2.8.47",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"@iarna/word-count": "^1.1.2",
|
|
33
33
|
"@manuscripts/json-schema": "2.2.11",
|
|
34
34
|
"@manuscripts/library": "1.3.13",
|
|
35
|
-
"@manuscripts/style-guide": "2.1.
|
|
35
|
+
"@manuscripts/style-guide": "2.1.9",
|
|
36
36
|
"@manuscripts/track-changes-plugin": "1.10.4",
|
|
37
|
-
"@manuscripts/transform": "3.0.
|
|
37
|
+
"@manuscripts/transform": "3.0.56",
|
|
38
38
|
"@popperjs/core": "^2.11.8",
|
|
39
39
|
"astrocite-eutils": "^0.16.4",
|
|
40
40
|
"codemirror": "^5.58.1",
|
|
@@ -124,9 +124,8 @@
|
|
|
124
124
|
|
|
125
125
|
.ProseMirror .figure-block {
|
|
126
126
|
width: 100%;
|
|
127
|
-
border
|
|
128
|
-
border-
|
|
129
|
-
border-width: 0pt !important;
|
|
127
|
+
border: 1px solid #f2f2f2;
|
|
128
|
+
border-radius: 4px;
|
|
130
129
|
|
|
131
130
|
padding: 4pt !important;
|
|
132
131
|
gap: 4pt !important;
|
|
@@ -143,8 +142,6 @@
|
|
|
143
142
|
|
|
144
143
|
.ProseMirror .figure-block > figure {
|
|
145
144
|
width: 100%;
|
|
146
|
-
border: 1px solid #f2f2f2;
|
|
147
|
-
border-radius: 4px;
|
|
148
145
|
position: relative;
|
|
149
146
|
grid-column: 1/-1;
|
|
150
147
|
}
|
|
@@ -1070,7 +1067,7 @@ figure.block:has(.equation.selected-suggestion) {
|
|
|
1070
1067
|
color: #6e6e6e;
|
|
1071
1068
|
line-height: 1.3;
|
|
1072
1069
|
}
|
|
1073
|
-
.
|
|
1070
|
+
.toggle-button-open {
|
|
1074
1071
|
position: absolute;
|
|
1075
1072
|
right: var(--body-side-margin);
|
|
1076
1073
|
transform: translateX(100%);
|
|
@@ -1206,9 +1203,12 @@ th:hover > .table-context-menu-button,
|
|
|
1206
1203
|
> * {
|
|
1207
1204
|
opacity: 0.3;
|
|
1208
1205
|
}
|
|
1206
|
+
|
|
1209
1207
|
.ProseMirror .block-embed .tools-panel {
|
|
1210
1208
|
position: relative;
|
|
1209
|
+
right: 0;
|
|
1211
1210
|
}
|
|
1211
|
+
|
|
1212
1212
|
.ProseMirror .block-embed .block-gutter,
|
|
1213
1213
|
.block-embed .action-gutter {
|
|
1214
1214
|
display: none;
|
|
@@ -1247,7 +1247,7 @@ th:hover > .table-context-menu-button,
|
|
|
1247
1247
|
|
|
1248
1248
|
.ProseMirror .non-editable {
|
|
1249
1249
|
position: relative;
|
|
1250
|
-
pointer-events: none;
|
|
1250
|
+
pointer-events: none;
|
|
1251
1251
|
user-select: none;
|
|
1252
1252
|
box-shadow: inset 49px 0 0 white, inset 53px 0 0 #6E6E6E;
|
|
1253
1253
|
}
|
|
@@ -1280,3 +1280,58 @@ th:hover > .table-context-menu-button,
|
|
|
1280
1280
|
.embed-media-preview .tools-panel {
|
|
1281
1281
|
right: 6px;
|
|
1282
1282
|
}
|
|
1283
|
+
|
|
1284
|
+
.ProseMirror .accessibility_element {
|
|
1285
|
+
margin-top: 12px;
|
|
1286
|
+
grid-column-start: 1;
|
|
1287
|
+
grid-column-end: -1;
|
|
1288
|
+
text-align: start;
|
|
1289
|
+
display: none;
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
.ProseMirror .show_accessibility_element .accessibility_element {
|
|
1293
|
+
display: block;
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
.ProseMirror .accessibility_element_label {
|
|
1297
|
+
color: var(--label-color);
|
|
1298
|
+
font-size: 18px;
|
|
1299
|
+
font-style: normal;
|
|
1300
|
+
font-weight: 400;
|
|
1301
|
+
line-height: 24px;
|
|
1302
|
+
letter-spacing: -0.369px;
|
|
1303
|
+
margin-top: 12px;
|
|
1304
|
+
cursor: pointer;
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
.ProseMirror .accessibility_element_input {
|
|
1308
|
+
border-radius: 4px;
|
|
1309
|
+
border: 1px solid var(--accepted-bg-color);
|
|
1310
|
+
background: #fff;
|
|
1311
|
+
margin-top: 4px;
|
|
1312
|
+
padding: 12px 8px;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
.ProseMirror .accessibility_element_expander_button_container {
|
|
1316
|
+
position: absolute;
|
|
1317
|
+
left: 100%;
|
|
1318
|
+
bottom: 0;
|
|
1319
|
+
justify-self: self-end;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
.ProseMirror .show_accessibility_element .toggle-button-open svg {
|
|
1323
|
+
transform: rotate(180deg);
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
.ProseMirror .accessibility_element_expander_button_container .toggle-button-open {
|
|
1327
|
+
right: calc(100% - 6px);
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
.ProseMirror .block-embed .accessibility_element_expander_button_container {
|
|
1331
|
+
right: 36px;
|
|
1332
|
+
bottom: 36px;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
.ProseMirror .block-table_element .accessibility_element_expander_button_container {
|
|
1336
|
+
left: 93%;
|
|
1337
|
+
}
|