@manuscripts/body-editor 3.12.19 → 3.12.22

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.
@@ -185,7 +185,7 @@ const createBlock = (nodeType, position, state, dispatch, attrs) => {
185
185
  case transform_1.schema.nodes.listing_element:
186
186
  node = transform_1.schema.nodes.listing_element.create({}, [
187
187
  transform_1.schema.nodes.listing.create(),
188
- createAndFillFigcaptionElement(),
188
+ ...createAndFillCaption(),
189
189
  ]);
190
190
  break;
191
191
  case transform_1.schema.nodes.equation_element:
@@ -256,10 +256,7 @@ const insertFigure = (file, state, dispatch) => {
256
256
  });
257
257
  const element = state.schema.nodes.figure_element.createAndFill({}, [
258
258
  figure,
259
- state.schema.nodes.figcaption.create({}, [
260
- state.schema.nodes.caption_title.create(),
261
- state.schema.nodes.caption.create(),
262
- ]),
259
+ transform_1.schema.nodes.caption.create(undefined, transform_1.schema.nodes.text_block.create()),
263
260
  ]);
264
261
  const tr = state.tr.insert(position, element);
265
262
  dispatch(tr);
@@ -275,7 +272,7 @@ const insertEmbed = (state, dispatch, attrs) => {
275
272
  ...attrs,
276
273
  id: (0, transform_1.generateNodeID)(transform_1.schema.nodes.embed),
277
274
  }, [
278
- createAndFillFigcaptionElement(),
275
+ ...createAndFillCaption(),
279
276
  transform_1.schema.nodes.alt_text.create(),
280
277
  transform_1.schema.nodes.long_desc.create(),
281
278
  ]);
@@ -301,12 +298,7 @@ const insertSupplement = (file, view) => {
301
298
  const supplement = transform_1.schema.nodes.supplement.createAndFill({
302
299
  id: (0, transform_1.generateNodeID)(transform_1.schema.nodes.supplement),
303
300
  href: file.id,
304
- }, [
305
- transform_1.schema.nodes.figcaption.create({}, [
306
- transform_1.schema.nodes.caption_title.create(),
307
- transform_1.schema.nodes.caption.create(),
308
- ]),
309
- ]);
301
+ }, createAndFillCaption());
310
302
  const tr = view.state.tr;
311
303
  const { pos } = (0, doc_1.upsertSupplementsSection)(tr, supplement);
312
304
  tr.setSelection(prosemirror_state_1.NodeSelection.create(tr.doc, pos));
@@ -589,7 +581,7 @@ const insertBoxElement = (state, dispatch) => {
589
581
  paragraph,
590
582
  ]);
591
583
  const node = nodes.box_element.createAndFill({}, [
592
- nodes.figcaption.create({}, [nodes.caption_title.create()]),
584
+ nodes.caption_title.create(),
593
585
  section,
594
586
  ]);
595
587
  if (position && dispatch) {
@@ -1123,7 +1115,7 @@ const createAndFillTableElement = (attrs, config = DEFAULT_TABLE_CONFIG) => {
1123
1115
  ...attrs,
1124
1116
  id: (0, transform_1.generateNodeID)(transform_1.schema.nodes.table_element),
1125
1117
  }, [
1126
- createAndFillFigcaptionElement(),
1118
+ transform_1.schema.nodes.caption_title.create(),
1127
1119
  transform_1.schema.nodes.table.create({}, tableRows),
1128
1120
  transform_1.schema.nodes.alt_text.create(),
1129
1121
  transform_1.schema.nodes.long_desc.create(),
@@ -1135,21 +1127,22 @@ const createAndFillFigureElement = (attrs) => transform_1.schema.nodes.figure_el
1135
1127
  ...attrs,
1136
1128
  id: (0, transform_1.generateNodeID)(transform_1.schema.nodes.figure_element),
1137
1129
  }, [
1138
- transform_1.schema.nodes.figure.create({}, [transform_1.schema.nodes.figcaption.create()]),
1139
- createAndFillFigcaptionElement(),
1130
+ transform_1.schema.nodes.figure.create(),
1131
+ transform_1.schema.nodes.caption.create(undefined, transform_1.schema.nodes.text_block.create()),
1140
1132
  transform_1.schema.nodes.alt_text.create(),
1141
1133
  transform_1.schema.nodes.long_desc.create(),
1142
1134
  transform_1.schema.nodes.listing.create(),
1143
1135
  ]);
1144
- const createAndFillFigcaptionElement = () => transform_1.schema.nodes.figcaption.create({}, [
1136
+ const createAndFillCaption = () => [
1145
1137
  transform_1.schema.nodes.caption_title.create(),
1146
- transform_1.schema.nodes.caption.create(),
1147
- ]);
1138
+ transform_1.schema.nodes.caption.create(undefined, transform_1.schema.nodes.text_block.create()),
1139
+ ];
1148
1140
  const createImageElement = (attrs) => transform_1.schema.nodes.image_element.create({
1149
1141
  ...attrs,
1150
1142
  id: (0, transform_1.generateNodeID)(transform_1.schema.nodes.image_element),
1151
1143
  }, [
1152
1144
  transform_1.schema.nodes.figure.create(),
1145
+ transform_1.schema.nodes.caption.create(undefined, transform_1.schema.nodes.text_block.create()),
1153
1146
  transform_1.schema.nodes.alt_text.create(),
1154
1147
  transform_1.schema.nodes.long_desc.create(),
1155
1148
  ]);
@@ -1157,7 +1150,7 @@ const createEmbedElement = (attrs) => transform_1.schema.nodes.embed.create({
1157
1150
  ...attrs,
1158
1151
  id: (0, transform_1.generateNodeID)(transform_1.schema.nodes.embed),
1159
1152
  }, [
1160
- createAndFillFigcaptionElement(),
1153
+ ...createAndFillCaption(),
1161
1154
  transform_1.schema.nodes.alt_text.create(),
1162
1155
  transform_1.schema.nodes.long_desc.create(),
1163
1156
  ]);
@@ -65,9 +65,11 @@ const leaveTitle = (state, dispatch, view) => {
65
65
  }
66
66
  return true;
67
67
  };
68
- const leaveFigcaption = (state) => {
68
+ const leaveCaption = (state) => {
69
69
  const { selection: { $anchor }, } = state;
70
- return $anchor.parent.type === $anchor.parent.type.schema.nodes.caption_title;
70
+ return ($anchor.parent.type === $anchor.parent.type.schema.nodes.caption_title ||
71
+ $anchor.node($anchor.depth - 1)?.type ===
72
+ $anchor.parent.type.schema.nodes.caption);
71
73
  };
72
74
  const protectTitles = (state, dispatch, view) => {
73
75
  const { selection } = state;
@@ -99,25 +101,37 @@ const protectReferencesTitle = (state) => {
99
101
  exports.protectReferencesTitle = protectReferencesTitle;
100
102
  const protectCaption = (state, dispatch) => {
101
103
  const { selection: { $anchor }, } = state;
102
- if (dispatch &&
103
- ($anchor.parent.type === $anchor.parent.type.schema.nodes.caption_title ||
104
- $anchor.parent.type === $anchor.parent.type.schema.nodes.caption) &&
104
+ let nodeType = undefined;
105
+ if ($anchor.node($anchor.depth - 1)?.type ===
106
+ $anchor.parent.type.schema.nodes.caption &&
107
+ $anchor.node($anchor.depth).content.size === 1) {
108
+ nodeType = $anchor.node($anchor.depth - 1).type;
109
+ }
110
+ else if ($anchor.parent.type === $anchor.parent.type.schema.nodes.caption_title &&
105
111
  $anchor.parent.content.size === 1) {
106
- const slice = new prosemirror_model_1.Slice(prosemirror_model_1.Fragment.from([state.schema.nodes.caption_title.create()]), 1, 1);
112
+ nodeType = $anchor.parent.type;
113
+ }
114
+ if (dispatch && nodeType) {
115
+ const slice = new prosemirror_model_1.Slice(prosemirror_model_1.Fragment.from([nodeType.create()]), 1, 1);
107
116
  const tr = state.tr.replace($anchor.pos - 1, $anchor.pos, slice);
108
117
  dispatch(tr);
109
118
  return true;
110
119
  }
111
120
  return false;
112
121
  };
113
- const keepCaption = (state) => {
122
+ const keepCaption = (state, dispatch) => {
114
123
  const { selection: { $anchor }, } = state;
115
- return ($anchor.parent.type === $anchor.parent.type.schema.nodes.caption_title &&
116
- $anchor.parent.content.size === 0);
124
+ if (dispatch &&
125
+ $anchor.parent.type === $anchor.parent.type.schema.nodes.caption_title &&
126
+ $anchor.parent.content.size === 1) {
127
+ dispatch(state.tr.delete($anchor.pos, $anchor.pos + 1));
128
+ return true;
129
+ }
130
+ return false;
117
131
  };
118
132
  const titleKeymap = {
119
133
  Backspace: (0, prosemirror_commands_1.chainCommands)(protectTitles, exports.protectReferencesTitle, protectCaption),
120
- Enter: (0, prosemirror_commands_1.chainCommands)(commands_1.autoComplete, leaveTitle, leaveFigcaption),
134
+ Enter: (0, prosemirror_commands_1.chainCommands)(commands_1.autoComplete, leaveTitle, leaveCaption),
121
135
  Delete: (0, prosemirror_commands_1.chainCommands)(keepCaption, exports.protectReferencesTitle),
122
136
  };
123
137
  exports.default = titleKeymap;
@@ -99,7 +99,7 @@ describe('editor view', () => {
99
99
  expect(figureElement.childCount).toBe(5);
100
100
  expect(figureElement.type).toBe(transform_1.schema.nodes.figure_element);
101
101
  expect(figureElement.content.child(0).type).toBe(transform_1.schema.nodes.figure);
102
- expect(figureElement.content.child(1).type).toBe(transform_1.schema.nodes.figcaption);
102
+ expect(figureElement.content.child(1).type).toBe(transform_1.schema.nodes.caption);
103
103
  const sectionWithTable = view.state.doc.child(2).child(8);
104
104
  expect(sectionWithTable.attrs.id).toBe('section-with-table');
105
105
  expect(sectionWithTable.childCount).toBe(2);
@@ -107,7 +107,7 @@ describe('editor view', () => {
107
107
  const tableElement = sectionWithTable.content.child(1);
108
108
  expect(tableElement.childCount).toBe(5);
109
109
  expect(tableElement.type).toBe(tableElement.type.schema.nodes.table_element);
110
- expect(tableElement.content.child(0).type).toBe(tableElement.type.schema.nodes.figcaption);
110
+ expect(tableElement.content.child(0).type).toBe(tableElement.type.schema.nodes.caption_title);
111
111
  expect(tableElement.content.child(1).type).toBe(tableElement.type.schema.nodes.table);
112
112
  });
113
113
  });
@@ -258,19 +258,18 @@ class ContextMenu {
258
258
  const tr = this.view.state.tr;
259
259
  const boxElementNode = $pos.node($pos.depth - 1);
260
260
  const boxStartPos = $pos.start($pos.depth - 1);
261
- const figcaptions = (0, prosemirror_utils_1.findChildrenByType)(boxElementNode, transform_1.schema.nodes.figcaption);
262
- const hasLabel = figcaptions.length > 0;
261
+ const captionTitle = (0, prosemirror_utils_1.findChildrenByType)(boxElementNode, transform_1.schema.nodes.caption_title, false)[0];
262
+ const caption = (0, prosemirror_utils_1.findChildrenByType)(boxElementNode, transform_1.schema.nodes.caption, false)[0];
263
+ const hasLabel = captionTitle;
263
264
  menu.insertBefore(this.createMenuItem(hasLabel ? 'Delete Label' : 'Add Label', () => {
264
265
  if (hasLabel) {
265
- const figcaptionNode = figcaptions[0].node;
266
- const figcaptionPos = boxStartPos + figcaptions[0].pos;
267
- tr.delete(figcaptionPos, figcaptionPos + figcaptionNode.nodeSize);
266
+ const captionNode = captionTitle.node;
267
+ const captionPos = boxStartPos + captionTitle.pos;
268
+ tr.delete(captionPos, captionPos + captionNode.nodeSize + (caption?.node.nodeSize || 0));
268
269
  }
269
270
  else {
270
- const newFigcaption = transform_1.schema.nodes.figcaption.create({}, [
271
- transform_1.schema.nodes.caption_title.create(),
272
- ]);
273
- tr.insert(boxStartPos, newFigcaption);
271
+ const captionTitle = transform_1.schema.nodes.caption_title.create();
272
+ tr.insert(boxStartPos, captionTitle);
274
273
  }
275
274
  this.view.dispatch(tr);
276
275
  popper.destroy();
@@ -19,6 +19,7 @@ exports.objectsKey = void 0;
19
19
  const transform_1 = require("@manuscripts/transform");
20
20
  const prosemirror_state_1 = require("prosemirror-state");
21
21
  const prosemirror_view_1 = require("prosemirror-view");
22
+ const prosemirror_utils_1 = require("prosemirror-utils");
22
23
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
23
24
  exports.objectsKey = new prosemirror_state_1.PluginKey('objects');
24
25
  exports.default = () => {
@@ -41,26 +42,19 @@ exports.default = () => {
41
42
  const { id } = node.attrs;
42
43
  if (id) {
43
44
  const target = targets.get(id);
44
- const resolvedPos = state.doc.resolve(pos);
45
- const isInGraphicalAbstract = (0, transform_1.isInGraphicalAbstractSection)(resolvedPos);
46
- if (target && !isInGraphicalAbstract) {
45
+ if (target) {
47
46
  const labelNode = document.createElement('span');
48
- labelNode.className = 'figure-label';
49
- if (node.type.name === 'image_element') {
50
- labelNode.textContent = target.label;
51
- decorations.push(prosemirror_view_1.Decoration.widget(pos + (node.firstChild?.nodeSize || 0) + 1, labelNode));
52
- }
53
- else {
54
- labelNode.textContent = target.label + ':';
55
- node.forEach((child, offset) => {
56
- if (child.type.name === 'figcaption') {
57
- decorations.push(prosemirror_view_1.Decoration.widget(pos + 1 + offset + 1, labelNode, {
58
- side: -1,
59
- key: `figure-label-${id}-${target.label}`,
60
- }));
61
- }
62
- });
63
- }
47
+ labelNode.className = 'element-label';
48
+ const caption = (0, prosemirror_utils_1.findChildren)(node, (node) => node.type === transform_1.schema.nodes.caption ||
49
+ node.type === transform_1.schema.nodes.caption_title, false)[0];
50
+ const labelPos = getDecorationPos(target, state.doc, pos, caption);
51
+ labelNode.textContent = caption
52
+ ? target.label + ':'
53
+ : target.label;
54
+ decorations.push(prosemirror_view_1.Decoration.widget(labelPos, labelNode, {
55
+ side: -1,
56
+ key: `element-label-${id}-${target.label}`,
57
+ }));
64
58
  }
65
59
  }
66
60
  });
@@ -70,3 +64,14 @@ exports.default = () => {
70
64
  },
71
65
  });
72
66
  };
67
+ const getDecorationPos = (target, doc, pos, caption) => {
68
+ const $pos = doc.resolve(pos + (caption?.pos || 1) + 1);
69
+ let targetPos = $pos.pos;
70
+ if (!caption) {
71
+ targetPos = $pos.end();
72
+ }
73
+ else if (!$pos.nodeBefore) {
74
+ targetPos -= 1;
75
+ }
76
+ return targetPos;
77
+ };
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MATHJAX_VERSION = exports.VERSION = void 0;
4
- exports.VERSION = '3.12.19';
4
+ exports.VERSION = '3.12.22';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -26,7 +26,7 @@ class CaptionView extends base_node_view_1.BaseNodeView {
26
26
  };
27
27
  }
28
28
  createDOM() {
29
- this.dom = document.createElement('p');
29
+ this.dom = document.createElement('caption');
30
30
  this.dom.className = 'caption-description placeholder';
31
31
  this.dom.contentEditable = 'true';
32
32
  this.contentDOM = this.dom;
@@ -60,7 +60,6 @@ class FigureView extends base_node_view_1.BaseNodeView {
60
60
  this.container.contentEditable = 'false';
61
61
  this.dom.appendChild(this.container);
62
62
  this.contentDOM = document.createElement('div');
63
- this.contentDOM.className = 'figure-caption';
64
63
  this.contentDOM.setAttribute('tabindex', '1337');
65
64
  this.dom.appendChild(this.contentDOM);
66
65
  }
@@ -175,7 +175,7 @@ export const createBlock = (nodeType, position, state, dispatch, attrs) => {
175
175
  case schema.nodes.listing_element:
176
176
  node = schema.nodes.listing_element.create({}, [
177
177
  schema.nodes.listing.create(),
178
- createAndFillFigcaptionElement(),
178
+ ...createAndFillCaption(),
179
179
  ]);
180
180
  break;
181
181
  case schema.nodes.equation_element:
@@ -243,10 +243,7 @@ export const insertFigure = (file, state, dispatch) => {
243
243
  });
244
244
  const element = state.schema.nodes.figure_element.createAndFill({}, [
245
245
  figure,
246
- state.schema.nodes.figcaption.create({}, [
247
- state.schema.nodes.caption_title.create(),
248
- state.schema.nodes.caption.create(),
249
- ]),
246
+ schema.nodes.caption.create(undefined, schema.nodes.text_block.create()),
250
247
  ]);
251
248
  const tr = state.tr.insert(position, element);
252
249
  dispatch(tr);
@@ -261,7 +258,7 @@ export const insertEmbed = (state, dispatch, attrs) => {
261
258
  ...attrs,
262
259
  id: generateNodeID(schema.nodes.embed),
263
260
  }, [
264
- createAndFillFigcaptionElement(),
261
+ ...createAndFillCaption(),
265
262
  schema.nodes.alt_text.create(),
266
263
  schema.nodes.long_desc.create(),
267
264
  ]);
@@ -285,12 +282,7 @@ export const insertSupplement = (file, view) => {
285
282
  const supplement = schema.nodes.supplement.createAndFill({
286
283
  id: generateNodeID(schema.nodes.supplement),
287
284
  href: file.id,
288
- }, [
289
- schema.nodes.figcaption.create({}, [
290
- schema.nodes.caption_title.create(),
291
- schema.nodes.caption.create(),
292
- ]),
293
- ]);
285
+ }, createAndFillCaption());
294
286
  const tr = view.state.tr;
295
287
  const { pos } = upsertSupplementsSection(tr, supplement);
296
288
  tr.setSelection(NodeSelection.create(tr.doc, pos));
@@ -559,7 +551,7 @@ export const insertBoxElement = (state, dispatch) => {
559
551
  paragraph,
560
552
  ]);
561
553
  const node = nodes.box_element.createAndFill({}, [
562
- nodes.figcaption.create({}, [nodes.caption_title.create()]),
554
+ nodes.caption_title.create(),
563
555
  section,
564
556
  ]);
565
557
  if (position && dispatch) {
@@ -1072,7 +1064,7 @@ export const createAndFillTableElement = (attrs, config = DEFAULT_TABLE_CONFIG)
1072
1064
  ...attrs,
1073
1065
  id: generateNodeID(schema.nodes.table_element),
1074
1066
  }, [
1075
- createAndFillFigcaptionElement(),
1067
+ schema.nodes.caption_title.create(),
1076
1068
  schema.nodes.table.create({}, tableRows),
1077
1069
  schema.nodes.alt_text.create(),
1078
1070
  schema.nodes.long_desc.create(),
@@ -1083,21 +1075,22 @@ const createAndFillFigureElement = (attrs) => schema.nodes.figure_element.create
1083
1075
  ...attrs,
1084
1076
  id: generateNodeID(schema.nodes.figure_element),
1085
1077
  }, [
1086
- schema.nodes.figure.create({}, [schema.nodes.figcaption.create()]),
1087
- createAndFillFigcaptionElement(),
1078
+ schema.nodes.figure.create(),
1079
+ schema.nodes.caption.create(undefined, schema.nodes.text_block.create()),
1088
1080
  schema.nodes.alt_text.create(),
1089
1081
  schema.nodes.long_desc.create(),
1090
1082
  schema.nodes.listing.create(),
1091
1083
  ]);
1092
- const createAndFillFigcaptionElement = () => schema.nodes.figcaption.create({}, [
1084
+ const createAndFillCaption = () => [
1093
1085
  schema.nodes.caption_title.create(),
1094
- schema.nodes.caption.create(),
1095
- ]);
1086
+ schema.nodes.caption.create(undefined, schema.nodes.text_block.create()),
1087
+ ];
1096
1088
  const createImageElement = (attrs) => schema.nodes.image_element.create({
1097
1089
  ...attrs,
1098
1090
  id: generateNodeID(schema.nodes.image_element),
1099
1091
  }, [
1100
1092
  schema.nodes.figure.create(),
1093
+ schema.nodes.caption.create(undefined, schema.nodes.text_block.create()),
1101
1094
  schema.nodes.alt_text.create(),
1102
1095
  schema.nodes.long_desc.create(),
1103
1096
  ]);
@@ -1105,7 +1098,7 @@ const createEmbedElement = (attrs) => schema.nodes.embed.create({
1105
1098
  ...attrs,
1106
1099
  id: generateNodeID(schema.nodes.embed),
1107
1100
  }, [
1108
- createAndFillFigcaptionElement(),
1101
+ ...createAndFillCaption(),
1109
1102
  schema.nodes.alt_text.create(),
1110
1103
  schema.nodes.long_desc.create(),
1111
1104
  ]);
@@ -62,9 +62,11 @@ const leaveTitle = (state, dispatch, view) => {
62
62
  }
63
63
  return true;
64
64
  };
65
- const leaveFigcaption = (state) => {
65
+ const leaveCaption = (state) => {
66
66
  const { selection: { $anchor }, } = state;
67
- return $anchor.parent.type === $anchor.parent.type.schema.nodes.caption_title;
67
+ return ($anchor.parent.type === $anchor.parent.type.schema.nodes.caption_title ||
68
+ $anchor.node($anchor.depth - 1)?.type ===
69
+ $anchor.parent.type.schema.nodes.caption);
68
70
  };
69
71
  const protectTitles = (state, dispatch, view) => {
70
72
  const { selection } = state;
@@ -95,25 +97,37 @@ export const protectReferencesTitle = (state) => {
95
97
  };
96
98
  const protectCaption = (state, dispatch) => {
97
99
  const { selection: { $anchor }, } = state;
98
- if (dispatch &&
99
- ($anchor.parent.type === $anchor.parent.type.schema.nodes.caption_title ||
100
- $anchor.parent.type === $anchor.parent.type.schema.nodes.caption) &&
100
+ let nodeType = undefined;
101
+ if ($anchor.node($anchor.depth - 1)?.type ===
102
+ $anchor.parent.type.schema.nodes.caption &&
103
+ $anchor.node($anchor.depth).content.size === 1) {
104
+ nodeType = $anchor.node($anchor.depth - 1).type;
105
+ }
106
+ else if ($anchor.parent.type === $anchor.parent.type.schema.nodes.caption_title &&
101
107
  $anchor.parent.content.size === 1) {
102
- const slice = new Slice(Fragment.from([state.schema.nodes.caption_title.create()]), 1, 1);
108
+ nodeType = $anchor.parent.type;
109
+ }
110
+ if (dispatch && nodeType) {
111
+ const slice = new Slice(Fragment.from([nodeType.create()]), 1, 1);
103
112
  const tr = state.tr.replace($anchor.pos - 1, $anchor.pos, slice);
104
113
  dispatch(tr);
105
114
  return true;
106
115
  }
107
116
  return false;
108
117
  };
109
- const keepCaption = (state) => {
118
+ const keepCaption = (state, dispatch) => {
110
119
  const { selection: { $anchor }, } = state;
111
- return ($anchor.parent.type === $anchor.parent.type.schema.nodes.caption_title &&
112
- $anchor.parent.content.size === 0);
120
+ if (dispatch &&
121
+ $anchor.parent.type === $anchor.parent.type.schema.nodes.caption_title &&
122
+ $anchor.parent.content.size === 1) {
123
+ dispatch(state.tr.delete($anchor.pos, $anchor.pos + 1));
124
+ return true;
125
+ }
126
+ return false;
113
127
  };
114
128
  const titleKeymap = {
115
129
  Backspace: chainCommands(protectTitles, protectReferencesTitle, protectCaption),
116
- Enter: chainCommands(autoComplete, leaveTitle, leaveFigcaption),
130
+ Enter: chainCommands(autoComplete, leaveTitle, leaveCaption),
117
131
  Delete: chainCommands(keepCaption, protectReferencesTitle),
118
132
  };
119
133
  export default titleKeymap;
@@ -94,7 +94,7 @@ describe('editor view', () => {
94
94
  expect(figureElement.childCount).toBe(5);
95
95
  expect(figureElement.type).toBe(schema.nodes.figure_element);
96
96
  expect(figureElement.content.child(0).type).toBe(schema.nodes.figure);
97
- expect(figureElement.content.child(1).type).toBe(schema.nodes.figcaption);
97
+ expect(figureElement.content.child(1).type).toBe(schema.nodes.caption);
98
98
  const sectionWithTable = view.state.doc.child(2).child(8);
99
99
  expect(sectionWithTable.attrs.id).toBe('section-with-table');
100
100
  expect(sectionWithTable.childCount).toBe(2);
@@ -102,7 +102,7 @@ describe('editor view', () => {
102
102
  const tableElement = sectionWithTable.content.child(1);
103
103
  expect(tableElement.childCount).toBe(5);
104
104
  expect(tableElement.type).toBe(tableElement.type.schema.nodes.table_element);
105
- expect(tableElement.content.child(0).type).toBe(tableElement.type.schema.nodes.figcaption);
105
+ expect(tableElement.content.child(0).type).toBe(tableElement.type.schema.nodes.caption_title);
106
106
  expect(tableElement.content.child(1).type).toBe(tableElement.type.schema.nodes.table);
107
107
  });
108
108
  });
@@ -254,19 +254,18 @@ export class ContextMenu {
254
254
  const tr = this.view.state.tr;
255
255
  const boxElementNode = $pos.node($pos.depth - 1);
256
256
  const boxStartPos = $pos.start($pos.depth - 1);
257
- const figcaptions = findChildrenByType(boxElementNode, schema.nodes.figcaption);
258
- const hasLabel = figcaptions.length > 0;
257
+ const captionTitle = findChildrenByType(boxElementNode, schema.nodes.caption_title, false)[0];
258
+ const caption = findChildrenByType(boxElementNode, schema.nodes.caption, false)[0];
259
+ const hasLabel = captionTitle;
259
260
  menu.insertBefore(this.createMenuItem(hasLabel ? 'Delete Label' : 'Add Label', () => {
260
261
  if (hasLabel) {
261
- const figcaptionNode = figcaptions[0].node;
262
- const figcaptionPos = boxStartPos + figcaptions[0].pos;
263
- tr.delete(figcaptionPos, figcaptionPos + figcaptionNode.nodeSize);
262
+ const captionNode = captionTitle.node;
263
+ const captionPos = boxStartPos + captionTitle.pos;
264
+ tr.delete(captionPos, captionPos + captionNode.nodeSize + (caption?.node.nodeSize || 0));
264
265
  }
265
266
  else {
266
- const newFigcaption = schema.nodes.figcaption.create({}, [
267
- schema.nodes.caption_title.create(),
268
- ]);
269
- tr.insert(boxStartPos, newFigcaption);
267
+ const captionTitle = schema.nodes.caption_title.create();
268
+ tr.insert(boxStartPos, captionTitle);
270
269
  }
271
270
  this.view.dispatch(tr);
272
271
  popper.destroy();
@@ -13,9 +13,10 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { buildTargets, isInGraphicalAbstractSection, } from '@manuscripts/transform';
16
+ import { buildTargets, schema, } from '@manuscripts/transform';
17
17
  import { Plugin, PluginKey } from 'prosemirror-state';
18
18
  import { Decoration, DecorationSet } from 'prosemirror-view';
19
+ import { findChildren } from 'prosemirror-utils';
19
20
  import { clear } from '@manuscripts/track-changes-plugin';
20
21
  export const objectsKey = new PluginKey('objects');
21
22
  export default () => {
@@ -38,26 +39,19 @@ export default () => {
38
39
  const { id } = node.attrs;
39
40
  if (id) {
40
41
  const target = targets.get(id);
41
- const resolvedPos = state.doc.resolve(pos);
42
- const isInGraphicalAbstract = isInGraphicalAbstractSection(resolvedPos);
43
- if (target && !isInGraphicalAbstract) {
42
+ if (target) {
44
43
  const labelNode = document.createElement('span');
45
- labelNode.className = 'figure-label';
46
- if (node.type.name === 'image_element') {
47
- labelNode.textContent = target.label;
48
- decorations.push(Decoration.widget(pos + (node.firstChild?.nodeSize || 0) + 1, labelNode));
49
- }
50
- else {
51
- labelNode.textContent = target.label + ':';
52
- node.forEach((child, offset) => {
53
- if (child.type.name === 'figcaption') {
54
- decorations.push(Decoration.widget(pos + 1 + offset + 1, labelNode, {
55
- side: -1,
56
- key: `figure-label-${id}-${target.label}`,
57
- }));
58
- }
59
- });
60
- }
44
+ labelNode.className = 'element-label';
45
+ const caption = findChildren(node, (node) => node.type === schema.nodes.caption ||
46
+ node.type === schema.nodes.caption_title, false)[0];
47
+ const labelPos = getDecorationPos(target, state.doc, pos, caption);
48
+ labelNode.textContent = caption
49
+ ? target.label + ':'
50
+ : target.label;
51
+ decorations.push(Decoration.widget(labelPos, labelNode, {
52
+ side: -1,
53
+ key: `element-label-${id}-${target.label}`,
54
+ }));
61
55
  }
62
56
  }
63
57
  });
@@ -67,3 +61,14 @@ export default () => {
67
61
  },
68
62
  });
69
63
  };
64
+ const getDecorationPos = (target, doc, pos, caption) => {
65
+ const $pos = doc.resolve(pos + (caption?.pos || 1) + 1);
66
+ let targetPos = $pos.pos;
67
+ if (!caption) {
68
+ targetPos = $pos.end();
69
+ }
70
+ else if (!$pos.nodeBefore) {
71
+ targetPos -= 1;
72
+ }
73
+ return targetPos;
74
+ };
@@ -1,2 +1,2 @@
1
- export const VERSION = '3.12.19';
1
+ export const VERSION = '3.12.22';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -23,7 +23,7 @@ export class CaptionView extends BaseNodeView {
23
23
  };
24
24
  }
25
25
  createDOM() {
26
- this.dom = document.createElement('p');
26
+ this.dom = document.createElement('caption');
27
27
  this.dom.className = 'caption-description placeholder';
28
28
  this.dom.contentEditable = 'true';
29
29
  this.contentDOM = this.dom;
@@ -57,7 +57,6 @@ export class FigureView extends BaseNodeView {
57
57
  this.container.contentEditable = 'false';
58
58
  this.dom.appendChild(this.container);
59
59
  this.contentDOM = document.createElement('div');
60
- this.contentDOM.className = 'figure-caption';
61
60
  this.contentDOM.setAttribute('tabindex', '1337');
62
61
  this.dom.appendChild(this.contentDOM);
63
62
  }
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "3.12.19";
1
+ export declare const VERSION = "3.12.22";
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.12.19",
4
+ "version": "3.12.22",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -38,8 +38,8 @@
38
38
  "@citation-js/plugin-ris": "0.7.18",
39
39
  "@iarna/word-count": "1.1.2",
40
40
  "@manuscripts/style-guide": "3.5.7",
41
- "@manuscripts/track-changes-plugin": "2.3.9",
42
- "@manuscripts/transform": "4.3.33",
41
+ "@manuscripts/track-changes-plugin": "2.3.10",
42
+ "@manuscripts/transform": "4.3.35",
43
43
  "@popperjs/core": "2.11.8",
44
44
  "citeproc": "2.4.63",
45
45
  "codemirror": "5.65.19",
@@ -162,6 +162,10 @@
162
162
  [caption listing] auto !important;
163
163
  }
164
164
 
165
+ .ProseMirror .figure-block {
166
+ text-align: center;
167
+ }
168
+
165
169
  .ProseMirror .figure-block-group .figure-block {
166
170
  border: none;
167
171
  border-radius: 0;
@@ -254,16 +258,6 @@
254
258
  padding-bottom: 20px;
255
259
  }
256
260
 
257
- .ProseMirror .figure-block > figcaption {
258
- grid-column-start: 1;
259
- grid-column-end: -1;
260
- margin-top: 30px;
261
- }
262
-
263
- .ProseMirror .figure-caption {
264
- display: none;
265
- }
266
-
267
261
  .ProseMirror .figure.placeholder {
268
262
  align-items: center;
269
263
  border-radius: 16px;
@@ -319,22 +313,6 @@
319
313
  border: none;
320
314
  }
321
315
 
322
- .ProseMirror figcaption {
323
- background: white;
324
- font-size: 14px;
325
- margin-top: 1em;
326
- text-align: center;
327
- word-wrap: break-word;
328
- }
329
-
330
- .ProseMirror .block-table_element figcaption {
331
- text-align: left;
332
- }
333
-
334
- .ProseMirror .figure-block > figcaption .figure-label {
335
- display: initial !important;
336
- }
337
-
338
316
  .ProseMirror .figure-block[id^='MPTable'] {
339
317
  border-collapse: collapse;
340
318
  empty-cells: show;
@@ -365,11 +343,6 @@
365
343
  border-bottom-width: 1pt !important;
366
344
  }
367
345
 
368
- .ProseMirror .figure-block[id^='MPTable'] > figcaption {
369
- grid-row: 2 !important;
370
- text-align: center !important;
371
- }
372
-
373
346
  .position-menu-button:focus-visible {
374
347
  outline: none;
375
348
  }
@@ -449,11 +422,6 @@ ProseMirror .block-embed .position-menu {
449
422
  .ProseMirror .block-affiliations {
450
423
  grid-template-columns: 52px auto 100px;
451
424
  }
452
- .ProseMirror .block-container.block-box_element > .block.box-element {
453
- position: relative;
454
- display: grid;
455
- grid-template-columns: auto;
456
- }
457
425
 
458
426
  .ProseMirror .box-element .block-container .block {
459
427
  background: var(--box-element-bg-color);
@@ -462,8 +430,8 @@ ProseMirror .block-embed .position-menu {
462
430
  border-right: 2px solid #e2e2e2;
463
431
  }
464
432
 
465
- .ProseMirror .box-element::after,
466
- .box-element > .block-section::before {
433
+ .ProseMirror .box-element > .block-section::before,
434
+ .ProseMirror .box-element > .block-section::after {
467
435
  content: ' ';
468
436
  margin-left: 52px;
469
437
  margin-right: 52px;
@@ -471,11 +439,16 @@ ProseMirror .block-embed .position-menu {
471
439
  height: 0;
472
440
  }
473
441
 
474
- .box-element > figcaption {
475
- margin-left: 54px;
476
- margin-right: 54px;
477
- padding-bottom: 6px;
478
- text-align: left;
442
+ .ProseMirror .box-element > .block-section {
443
+ padding-top: 6px;
444
+ }
445
+
446
+ .ProseMirror .box-element > .element-label {
447
+ margin-left: 52px;
448
+ }
449
+
450
+ .ProseMirror .box-element > .caption-title {
451
+ margin-right: 52px;
479
452
  }
480
453
 
481
454
  .ProseMirror
@@ -496,9 +469,7 @@ ProseMirror .block-embed .position-menu {
496
469
  > h1.empty-node[data-placeholder]::before {
497
470
  font-size: 16pt;
498
471
  }
499
- .box-element section figcaption {
500
- background: var(--box-element-bg-color);
501
- }
472
+
502
473
  .unsupported-format-label {
503
474
  font-size: 140%;
504
475
  line-height: 1.3;
@@ -1854,8 +1825,7 @@ th:hover > .table-context-menu-button,
1854
1825
 
1855
1826
  .ProseMirror .block-image_element .block:focus-visible,
1856
1827
  .ProseMirror .block-figure_element .block:focus-visible,
1857
- .ProseMirror .block-embed .block:focus-visible,
1858
- .ProseMirror .supplement-caption:focus-visible {
1828
+ .ProseMirror .block-embed .block:focus-visible {
1859
1829
  outline: none;
1860
1830
  }
1861
1831
 
package/styles/Editor.css CHANGED
@@ -308,82 +308,55 @@
308
308
  padding-top: 1em;
309
309
  }
310
310
 
311
- .ProseMirror .caption-title:not(.empty-node) {
311
+ /* Caption and Element Label */
312
+
313
+ .ProseMirror .caption-title:not(.empty-node), .ProseMirror .element-label {
312
314
  font-weight: bold;
313
315
  }
314
316
 
315
- .ProseMirror .caption-description {
317
+ .ProseMirror .element-label, .ProseMirror .caption-description, .ProseMirror .caption-title {
318
+ font-size: 14px;
319
+ outline: none;
316
320
  margin: 0;
317
- outline: none !important;
321
+ display: inline;
318
322
  }
319
323
 
320
- .ProseMirror .suppress-title .caption-description {
324
+ .ProseMirror .element-label + .caption-description > p:first-child {
321
325
  display: inline;
322
- outline: none !important;
323
- }
324
- .ProseMirror .caption-title {
325
- outline: none !important;
326
326
  }
327
327
 
328
- .ProseMirror .caption-title.empty-node::before {
329
- content: 'Caption Title...';
330
- color: #000;
331
- cursor: text;
328
+ .ProseMirror .caption-description > p {
329
+ margin: 0;
332
330
  }
333
331
 
334
- .ProseMirror .block-box_element .caption-title.empty-node::before {
335
- content: none;
332
+ .ProseMirror .element-label {
333
+ margin-right: 5px;
336
334
  }
337
335
 
338
- .ProseMirror .block-box_element label.caption-title.placeholder.empty-node {
339
- display: inline-flex;
336
+ .ProseMirror .block-equation_element .element-label {
337
+ display: block;
338
+ text-align: center;
340
339
  }
341
340
 
342
- .ProseMirror .block-box_element .caption-title.empty-node::after {
341
+ .ProseMirror .caption-title.empty-node::before {
343
342
  content: 'Caption Title...';
344
- color: #999;
345
- font-style: italic;
346
- pointer-events: none;
343
+ color: #000;
344
+ cursor: text;
347
345
  }
348
346
 
349
- .ProseMirror .caption-description.empty-node::before {
347
+ .ProseMirror .caption-description > p.empty-node::before {
350
348
  content: 'Caption...';
351
349
  color: #000;
352
350
  cursor: text;
353
351
  }
354
352
 
355
- .ProseMirror .block-table_element .caption-description.empty-node::before {
356
- content: 'Table caption';
357
- }
358
-
359
353
  .ProseMirror .block-table_element .caption-title.empty-node::before {
360
354
  content: 'Table title';
361
355
  }
362
356
 
363
- .ProseMirror .suppress-caption .caption-description {
364
- display: none;
365
- }
366
-
367
- .ProseMirror .suppress-caption figcaption > .figure-label {
368
- display: none !important;
369
- }
370
-
371
- .ProseMirror .suppress-title .caption-title {
372
- display: none;
373
- }
374
-
375
- .ProseMirror .figure-label {
376
- font-weight: bold;
377
- font-size: 14px;
378
- margin-right: 5px;
379
- white-space: nowrap;
380
- }
381
-
382
- .block-image_element .figure-label {
383
- display: block;
384
- text-align: center;
385
- grid-column-start: 1;
386
- grid-column-end: -1;
357
+ .ProseMirror .box-element > .caption-title.empty-node::before {
358
+ color: #999;
359
+ font-style: italic;
387
360
  }
388
361
 
389
362
  .ProseMirror .executable-container {
@@ -860,21 +833,18 @@
860
833
  max-width: 100%;
861
834
  }
862
835
 
863
- .ProseMirror figcaption .equation,
864
836
  .ProseMirror p .equation {
865
837
  display: inline;
866
838
  vertical-align: baseline;
867
839
  padding: 0 5px;
868
840
  }
869
841
 
870
- .ProseMirror figcaption .equation-placeholder,
871
842
  .ProseMirror p .equation-placeholder {
872
843
  display: inline;
873
844
  }
874
845
 
875
846
  .ProseMirror .code-placeholder,
876
- .ProseMirror .equation-placeholder,
877
- .ProseMirror .caption-placeholder {
847
+ .ProseMirror .equation-placeholder {
878
848
  color: #c9c9c9;
879
849
  }
880
850
 
@@ -1229,23 +1199,22 @@
1229
1199
  border-bottom: none;
1230
1200
  }
1231
1201
 
1232
- .ProseMirror .supplement-item figcaption {
1233
- text-align: left;
1234
- margin-top: 0;
1235
- }
1236
-
1237
1202
  .ProseMirror .supplement-item .caption-title.empty-node::before {
1238
1203
  content: 'Insert caption title...';
1239
1204
  color: #c9c9c9;
1240
1205
  font-style: italic;
1241
1206
  }
1242
1207
 
1243
- .ProseMirror .supplement-item .caption-description.empty-node::before {
1208
+ .ProseMirror .supplement-item .caption-description > p.empty-node::before {
1244
1209
  content: 'Insert caption...';
1245
1210
  color: #c9c9c9;
1246
1211
  font-style: italic;
1247
1212
  }
1248
1213
 
1214
+ .ProseMirror .supplement-item .caption-description > p {
1215
+ text-align: start;
1216
+ }
1217
+
1249
1218
  .ProseMirror .supplement-file-info {
1250
1219
  display: flex;
1251
1220
  align-items: center;
@@ -1341,10 +1310,6 @@
1341
1310
  cursor: move;
1342
1311
  }
1343
1312
 
1344
- .ProseMirror .supplement-item:hover figcaption {
1345
- background-color: #f2f2f2 !important;
1346
- }
1347
-
1348
1313
  .ProseMirror .supplement-item .drag-icon {
1349
1314
  position: absolute;
1350
1315
  top: 50%;