@manuscripts/body-editor 3.20.1 → 3.20.2
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/plugins/accessibility_element.js +25 -0
- package/dist/cjs/versions.js +1 -1
- package/dist/es/plugins/accessibility_element.js +25 -0
- package/dist/es/versions.js +1 -1
- package/dist/types/plugins/accessibility_element.d.ts +1 -0
- package/dist/types/versions.d.ts +1 -1
- package/package.json +1 -1
- package/src/plugins/accessibility_element.ts +33 -0
- package/src/versions.ts +1 -1
|
@@ -45,6 +45,27 @@ const buildExpandButtonDecorations = (doc) => {
|
|
|
45
45
|
});
|
|
46
46
|
return decorations;
|
|
47
47
|
};
|
|
48
|
+
const ariaLabels = new Map([
|
|
49
|
+
[
|
|
50
|
+
transform_1.schema.nodes.headshot_element,
|
|
51
|
+
{ caption: 'Headshot Summary', caption_title: 'Headshot Name' },
|
|
52
|
+
],
|
|
53
|
+
]);
|
|
54
|
+
const isCaptionNode = (node) => node.type === transform_1.schema.nodes.caption_title || node.type === transform_1.schema.nodes.caption;
|
|
55
|
+
const buildAriaLabelsDecorations = (doc) => {
|
|
56
|
+
const decorations = [];
|
|
57
|
+
doc.descendants((node, pos, parent) => {
|
|
58
|
+
if (isCaptionNode(node) && parent && ariaLabels.has(parent.type)) {
|
|
59
|
+
const arialLabel = ariaLabels.get(parent.type);
|
|
60
|
+
if (arialLabel) {
|
|
61
|
+
decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
|
|
62
|
+
'aria-label': arialLabel[node.type.name],
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return decorations;
|
|
68
|
+
};
|
|
48
69
|
const buildExpandedElementsDecorations = (doc, expandedElementIDs, selection) => {
|
|
49
70
|
const decorations = [];
|
|
50
71
|
doc.descendants((node, pos) => {
|
|
@@ -64,6 +85,7 @@ exports.default = () => {
|
|
|
64
85
|
init(config, instance) {
|
|
65
86
|
return {
|
|
66
87
|
expandButtonDecorations: buildExpandButtonDecorations(instance.doc),
|
|
88
|
+
ariaLabelsDecorations: buildAriaLabelsDecorations(instance.doc),
|
|
67
89
|
expandedElementDecorations: [],
|
|
68
90
|
expandedElementIDs: new Set(),
|
|
69
91
|
};
|
|
@@ -71,11 +93,13 @@ exports.default = () => {
|
|
|
71
93
|
apply(tr, value, oldState, newState) {
|
|
72
94
|
const s = {
|
|
73
95
|
expandButtonDecorations: value.expandButtonDecorations,
|
|
96
|
+
ariaLabelsDecorations: value.ariaLabelsDecorations,
|
|
74
97
|
expandedElementDecorations: value.expandedElementDecorations,
|
|
75
98
|
expandedElementIDs: new Set(value.expandedElementIDs),
|
|
76
99
|
};
|
|
77
100
|
if (tr.docChanged) {
|
|
78
101
|
s.expandButtonDecorations = buildExpandButtonDecorations(newState.doc);
|
|
102
|
+
s.ariaLabelsDecorations = buildAriaLabelsDecorations(newState.doc);
|
|
79
103
|
}
|
|
80
104
|
let expandedElementIDsChanged = false;
|
|
81
105
|
const meta = tr.getMeta(exports.accessibilityElementKey);
|
|
@@ -115,6 +139,7 @@ exports.default = () => {
|
|
|
115
139
|
if (pluginState) {
|
|
116
140
|
return prosemirror_view_1.DecorationSet.create(state.doc, [
|
|
117
141
|
...pluginState.expandButtonDecorations,
|
|
142
|
+
...pluginState.ariaLabelsDecorations,
|
|
118
143
|
...pluginState.expandedElementDecorations,
|
|
119
144
|
]);
|
|
120
145
|
}
|
package/dist/cjs/versions.js
CHANGED
|
@@ -42,6 +42,27 @@ const buildExpandButtonDecorations = (doc) => {
|
|
|
42
42
|
});
|
|
43
43
|
return decorations;
|
|
44
44
|
};
|
|
45
|
+
const ariaLabels = new Map([
|
|
46
|
+
[
|
|
47
|
+
schema.nodes.headshot_element,
|
|
48
|
+
{ caption: 'Headshot Summary', caption_title: 'Headshot Name' },
|
|
49
|
+
],
|
|
50
|
+
]);
|
|
51
|
+
const isCaptionNode = (node) => node.type === schema.nodes.caption_title || node.type === schema.nodes.caption;
|
|
52
|
+
const buildAriaLabelsDecorations = (doc) => {
|
|
53
|
+
const decorations = [];
|
|
54
|
+
doc.descendants((node, pos, parent) => {
|
|
55
|
+
if (isCaptionNode(node) && parent && ariaLabels.has(parent.type)) {
|
|
56
|
+
const arialLabel = ariaLabels.get(parent.type);
|
|
57
|
+
if (arialLabel) {
|
|
58
|
+
decorations.push(Decoration.node(pos, pos + node.nodeSize, {
|
|
59
|
+
'aria-label': arialLabel[node.type.name],
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return decorations;
|
|
65
|
+
};
|
|
45
66
|
const buildExpandedElementsDecorations = (doc, expandedElementIDs, selection) => {
|
|
46
67
|
const decorations = [];
|
|
47
68
|
doc.descendants((node, pos) => {
|
|
@@ -61,6 +82,7 @@ export default () => {
|
|
|
61
82
|
init(config, instance) {
|
|
62
83
|
return {
|
|
63
84
|
expandButtonDecorations: buildExpandButtonDecorations(instance.doc),
|
|
85
|
+
ariaLabelsDecorations: buildAriaLabelsDecorations(instance.doc),
|
|
64
86
|
expandedElementDecorations: [],
|
|
65
87
|
expandedElementIDs: new Set(),
|
|
66
88
|
};
|
|
@@ -68,11 +90,13 @@ export default () => {
|
|
|
68
90
|
apply(tr, value, oldState, newState) {
|
|
69
91
|
const s = {
|
|
70
92
|
expandButtonDecorations: value.expandButtonDecorations,
|
|
93
|
+
ariaLabelsDecorations: value.ariaLabelsDecorations,
|
|
71
94
|
expandedElementDecorations: value.expandedElementDecorations,
|
|
72
95
|
expandedElementIDs: new Set(value.expandedElementIDs),
|
|
73
96
|
};
|
|
74
97
|
if (tr.docChanged) {
|
|
75
98
|
s.expandButtonDecorations = buildExpandButtonDecorations(newState.doc);
|
|
99
|
+
s.ariaLabelsDecorations = buildAriaLabelsDecorations(newState.doc);
|
|
76
100
|
}
|
|
77
101
|
let expandedElementIDsChanged = false;
|
|
78
102
|
const meta = tr.getMeta(accessibilityElementKey);
|
|
@@ -112,6 +136,7 @@ export default () => {
|
|
|
112
136
|
if (pluginState) {
|
|
113
137
|
return DecorationSet.create(state.doc, [
|
|
114
138
|
...pluginState.expandButtonDecorations,
|
|
139
|
+
...pluginState.ariaLabelsDecorations,
|
|
115
140
|
...pluginState.expandedElementDecorations,
|
|
116
141
|
]);
|
|
117
142
|
}
|
package/dist/es/versions.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '3.20.
|
|
1
|
+
export const VERSION = '3.20.2';
|
|
2
2
|
export const MATHJAX_VERSION = '3.2.2';
|
|
@@ -3,6 +3,7 @@ import { Plugin, PluginKey } from 'prosemirror-state';
|
|
|
3
3
|
import { Decoration } from 'prosemirror-view';
|
|
4
4
|
export interface PluginState {
|
|
5
5
|
expandButtonDecorations: Decoration[];
|
|
6
|
+
ariaLabelsDecorations: Decoration[];
|
|
6
7
|
expandedElementDecorations: Decoration[];
|
|
7
8
|
expandedElementIDs: Set<string>;
|
|
8
9
|
}
|
package/dist/types/versions.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "3.20.
|
|
1
|
+
export declare const VERSION = "3.20.2";
|
|
2
2
|
export declare const MATHJAX_VERSION = "3.2.2";
|
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": "3.20.
|
|
4
|
+
"version": "3.20.2",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import {
|
|
17
17
|
ManuscriptNode,
|
|
18
|
+
ManuscriptNodeType,
|
|
18
19
|
ManuscriptTransaction,
|
|
19
20
|
schema,
|
|
20
21
|
} from '@manuscripts/transform'
|
|
@@ -25,6 +26,7 @@ import { createToggleButton } from '../lib/utils'
|
|
|
25
26
|
|
|
26
27
|
export interface PluginState {
|
|
27
28
|
expandButtonDecorations: Decoration[]
|
|
29
|
+
ariaLabelsDecorations: Decoration[]
|
|
28
30
|
expandedElementDecorations: Decoration[]
|
|
29
31
|
expandedElementIDs: Set<string>
|
|
30
32
|
}
|
|
@@ -101,6 +103,33 @@ const buildExpandButtonDecorations = (doc: ManuscriptNode) => {
|
|
|
101
103
|
return decorations
|
|
102
104
|
}
|
|
103
105
|
|
|
106
|
+
const ariaLabels: Map<ManuscriptNodeType, Record<string, string>> = new Map([
|
|
107
|
+
[
|
|
108
|
+
schema.nodes.headshot_element,
|
|
109
|
+
{ caption: 'Headshot Summary', caption_title: 'Headshot Name' },
|
|
110
|
+
],
|
|
111
|
+
])
|
|
112
|
+
|
|
113
|
+
const isCaptionNode = (node: ManuscriptNode) =>
|
|
114
|
+
node.type === schema.nodes.caption_title || node.type === schema.nodes.caption
|
|
115
|
+
|
|
116
|
+
const buildAriaLabelsDecorations = (doc: ManuscriptNode) => {
|
|
117
|
+
const decorations: Decoration[] = []
|
|
118
|
+
doc.descendants((node, pos, parent) => {
|
|
119
|
+
if (isCaptionNode(node) && parent && ariaLabels.has(parent.type)) {
|
|
120
|
+
const arialLabel = ariaLabels.get(parent.type)
|
|
121
|
+
if (arialLabel) {
|
|
122
|
+
decorations.push(
|
|
123
|
+
Decoration.node(pos, pos + node.nodeSize, {
|
|
124
|
+
'aria-label': arialLabel[node.type.name],
|
|
125
|
+
})
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
return decorations
|
|
131
|
+
}
|
|
132
|
+
|
|
104
133
|
const buildExpandedElementsDecorations = (
|
|
105
134
|
doc: ManuscriptNode,
|
|
106
135
|
expandedElementIDs: Set<string>,
|
|
@@ -130,6 +159,7 @@ export default () => {
|
|
|
130
159
|
init(config, instance) {
|
|
131
160
|
return {
|
|
132
161
|
expandButtonDecorations: buildExpandButtonDecorations(instance.doc),
|
|
162
|
+
ariaLabelsDecorations: buildAriaLabelsDecorations(instance.doc),
|
|
133
163
|
expandedElementDecorations: [],
|
|
134
164
|
expandedElementIDs: new Set(),
|
|
135
165
|
}
|
|
@@ -137,12 +167,14 @@ export default () => {
|
|
|
137
167
|
apply(tr, value, oldState, newState) {
|
|
138
168
|
const s = {
|
|
139
169
|
expandButtonDecorations: value.expandButtonDecorations,
|
|
170
|
+
ariaLabelsDecorations: value.ariaLabelsDecorations,
|
|
140
171
|
expandedElementDecorations: value.expandedElementDecorations,
|
|
141
172
|
expandedElementIDs: new Set(value.expandedElementIDs),
|
|
142
173
|
}
|
|
143
174
|
|
|
144
175
|
if (tr.docChanged) {
|
|
145
176
|
s.expandButtonDecorations = buildExpandButtonDecorations(newState.doc)
|
|
177
|
+
s.ariaLabelsDecorations = buildAriaLabelsDecorations(newState.doc)
|
|
146
178
|
}
|
|
147
179
|
|
|
148
180
|
let expandedElementIDsChanged = false
|
|
@@ -191,6 +223,7 @@ export default () => {
|
|
|
191
223
|
if (pluginState) {
|
|
192
224
|
return DecorationSet.create(state.doc, [
|
|
193
225
|
...pluginState.expandButtonDecorations,
|
|
226
|
+
...pluginState.ariaLabelsDecorations,
|
|
194
227
|
...pluginState.expandedElementDecorations,
|
|
195
228
|
])
|
|
196
229
|
}
|
package/src/versions.ts
CHANGED