@manuscripts/body-editor 1.8.7-LEAN-3140.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -94,9 +94,9 @@ const updateTableInlineFootnoteLabels = (tr, table) => {
94
94
  return tr;
95
95
  };
96
96
  exports.updateTableInlineFootnoteLabels = updateTableInlineFootnoteLabels;
97
- const getInlineFootnotes = (id, targetNode) => {
97
+ const getInlineFootnotes = (id, tableElement) => {
98
98
  const inlineFootnotes = [];
99
- targetNode.descendants((node, pos) => {
99
+ tableElement.node.content.descendants((node, pos) => {
100
100
  var _a;
101
101
  if (node.type === transform_1.schema.nodes.inline_footnote) {
102
102
  const footnote = node;
@@ -73,20 +73,11 @@ const uncitedFootnoteWidget = () => () => {
73
73
  return element;
74
74
  };
75
75
  exports.uncitedFootnoteWidget = uncitedFootnoteWidget;
76
- const deleteFootnoteWidget = (node, props, id, tableElement) => (view, getPos) => {
76
+ const deleteFootnoteWidget = (node, props, footnoteType, footnoteMessage, id, tableElement) => (view, getPos) => {
77
77
  const deleteBtn = document.createElement('span');
78
78
  deleteBtn.className = 'delete-icon';
79
79
  deleteBtn.innerHTML = assets_1.deleteIcon;
80
- const parentType = tableElement ? 'table ' : '';
81
- const footnote = {
82
- type: node.type === transform_1.schema.nodes.footnote
83
- ? `${parentType}footnote`
84
- : 'table general note',
85
- message: node.type === transform_1.schema.nodes.footnote
86
- ? `This action will entirely remove the ${parentType}footnote from the list because it will no longer be used.`
87
- : 'This action will entirely remove the table general note.',
88
- };
89
- deleteBtn.addEventListener('mousedown', () => {
80
+ deleteBtn.addEventListener('click', () => {
90
81
  const handleDelete = () => {
91
82
  let tr = view.state.tr;
92
83
  const pos = getPos();
@@ -104,8 +95,7 @@ const deleteFootnoteWidget = (node, props, id, tableElement) => (view, getPos) =
104
95
  }
105
96
  }
106
97
  if (node.type === transform_1.schema.nodes.footnote && pos) {
107
- const targetNode = tableElement ? tableElement.node : view.state.doc;
108
- const inlineFootnotes = (0, footnotes_utils_1.getInlineFootnotes)(id, targetNode);
98
+ const inlineFootnotes = (0, footnotes_utils_1.getInlineFootnotes)(id, tableElement);
109
99
  const nodeWithPos = (0, prosemirror_utils_1.findParentNodeClosestToPos)(tr.doc.resolve(pos), (node) => node.type === transform_1.schema.nodes.footnote);
110
100
  if (nodeWithPos) {
111
101
  const { pos: fnPos, node: fnNode } = nodeWithPos;
@@ -114,13 +104,13 @@ const deleteFootnoteWidget = (node, props, id, tableElement) => (view, getPos) =
114
104
  if (inlineFootnotes) {
115
105
  tr = view.state.tr;
116
106
  inlineFootnotes.forEach((footnote) => {
117
- const pos = footnote.pos + (tableElement ? tableElement.pos + 1 : 0);
107
+ const pos = footnote.pos + tableElement.pos;
118
108
  if (footnote.node.attrs.rids.length > 1) {
119
109
  const updatedRids = footnote.node.attrs.rids.filter((rid) => rid !== id);
120
110
  tr.setNodeMarkup(tr.mapping.map(pos + 1), undefined, Object.assign(Object.assign({}, node.attrs), { rids: updatedRids }));
121
111
  }
122
112
  else {
123
- tr.delete(tr.mapping.map(pos), tr.mapping.map(pos + footnote.node.nodeSize));
113
+ tr.delete(tr.mapping.map(pos + 1), tr.mapping.map(pos + footnote.node.nodeSize + 1));
124
114
  }
125
115
  });
126
116
  }
@@ -128,8 +118,8 @@ const deleteFootnoteWidget = (node, props, id, tableElement) => (view, getPos) =
128
118
  view.dispatch(tr);
129
119
  };
130
120
  const componentProps = {
131
- footnoteType: footnote.type,
132
- footnoteMessage: footnote.message,
121
+ footnoteType: footnoteType,
122
+ footnoteMessage: footnoteMessage,
133
123
  handleDelete: handleDelete,
134
124
  };
135
125
  (0, ReactSubView_1.default)(Object.assign(Object.assign({}, props), { dispatch: view.dispatch }), DeleteFootnoteDialog_1.DeleteFootnoteDialog, componentProps, node, () => getPos(), view);
@@ -168,30 +158,19 @@ exports.default = (props) => {
168
158
  props: {
169
159
  decorations: (state) => {
170
160
  const decorations = [];
171
- const tableElementFooter = (0, prosemirror_utils_1.findParentNodeOfType)(transform_1.schema.nodes.table_element_footer)(state.selection);
161
+ const isInTableElementFooter = (0, prosemirror_utils_1.hasParentNodeOfType)(transform_1.schema.nodes.table_element_footer)(state.selection);
172
162
  const tableElement = (0, prosemirror_utils_1.findParentNodeOfType)(transform_1.schema.nodes.table_element)(state.selection);
173
- const footnote = (0, prosemirror_utils_1.findParentNodeOfType)(transform_1.schema.nodes.footnote)(state.selection);
174
- let targetNode;
175
- if (footnote) {
176
- targetNode = footnote;
177
- }
178
- else if (tableElementFooter) {
179
- targetNode = tableElementFooter;
180
- }
181
- const can = props.getCapabilities();
182
- if (targetNode && can.editArticle) {
163
+ if (isInTableElementFooter) {
183
164
  const parent = (0, utils_1.findParentNodeWithIdValue)(state.selection);
184
165
  if (parent) {
185
166
  decorations.push(prosemirror_view_1.Decoration.node(parent.pos, parent.pos + parent.node.nodeSize, {
186
167
  class: 'footnote-selected',
187
168
  }));
188
- decorations.push(prosemirror_view_1.Decoration.widget(targetNode.pos + 2, deleteFootnoteWidget(targetNode.node, props, targetNode.node.attrs.id, tableElement), {
189
- key: targetNode.node.attrs.id,
190
- }));
191
169
  }
192
170
  }
193
171
  const { labels } = exports.footnotesKey.getState(state);
194
172
  let tableInlineFootnoteIds = undefined;
173
+ const can = props.getCapabilities();
195
174
  state.doc.descendants((node, pos, parent) => {
196
175
  var _a;
197
176
  if ((0, transform_1.isFootnoteNode)(node)) {
@@ -212,6 +191,35 @@ exports.default = (props) => {
212
191
  decorations.push(prosemirror_view_1.Decoration.widget(pos + node.nodeSize - 1, (0, exports.uncitedFootnoteWidget)()));
213
192
  }
214
193
  }
194
+ if (can.editArticle) {
195
+ if (tableElement) {
196
+ const footnote = (() => {
197
+ switch (node.type) {
198
+ case transform_1.schema.nodes.footnote:
199
+ return {
200
+ type: 'table footnote',
201
+ message: 'This action will entirely remove the table footnote from the list because it will no longer be used.',
202
+ };
203
+ default:
204
+ return {
205
+ type: 'table general note',
206
+ message: 'This action will entirely remove the table general note.',
207
+ };
208
+ }
209
+ })();
210
+ if (node.type === transform_1.schema.nodes.footnote) {
211
+ decorations.push(prosemirror_view_1.Decoration.widget(pos + 2, deleteFootnoteWidget(node, props, footnote.type, footnote.message, node.attrs.id, tableElement), {
212
+ key: node.attrs.id,
213
+ }));
214
+ }
215
+ else if (node.type === transform_1.schema.nodes.paragraph &&
216
+ (parent === null || parent === void 0 ? void 0 : parent.type) === transform_1.schema.nodes.table_element_footer) {
217
+ decorations.push(prosemirror_view_1.Decoration.widget(pos + 1, deleteFootnoteWidget(parent, props, footnote.type, footnote.message, parent.attrs.id, tableElement), {
218
+ key: parent.attrs.id,
219
+ }));
220
+ }
221
+ }
222
+ }
215
223
  if (node.type === transform_1.schema.nodes.footnotes_element) {
216
224
  if ((parent === null || parent === void 0 ? void 0 : parent.type) === transform_1.schema.nodes.table_element_footer) {
217
225
  decorations.push(prosemirror_view_1.Decoration.node(pos, pos + node.nodeSize, {
@@ -86,9 +86,9 @@ export const updateTableInlineFootnoteLabels = (tr, table) => {
86
86
  });
87
87
  return tr;
88
88
  };
89
- export const getInlineFootnotes = (id, targetNode) => {
89
+ export const getInlineFootnotes = (id, tableElement) => {
90
90
  const inlineFootnotes = [];
91
- targetNode.descendants((node, pos) => {
91
+ tableElement.node.content.descendants((node, pos) => {
92
92
  var _a;
93
93
  if (node.type === schema.nodes.inline_footnote) {
94
94
  const footnote = node;
@@ -16,7 +16,7 @@
16
16
  import { isFootnoteNode, isInlineFootnoteNode, schema, } from '@manuscripts/transform';
17
17
  import { isEqual } from 'lodash';
18
18
  import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
19
- import { findParentNodeClosestToPos, findParentNodeOfType, } from 'prosemirror-utils';
19
+ import { findParentNodeClosestToPos, findParentNodeOfType, hasParentNodeOfType, } from 'prosemirror-utils';
20
20
  import { Decoration, DecorationSet } from 'prosemirror-view';
21
21
  import { alertIcon, deleteIcon } from '../../assets';
22
22
  import { DeleteFootnoteDialog, } from '../../components/views/DeleteFootnoteDialog';
@@ -65,20 +65,11 @@ export const uncitedFootnoteWidget = () => () => {
65
65
  element.innerHTML = alertIcon;
66
66
  return element;
67
67
  };
68
- const deleteFootnoteWidget = (node, props, id, tableElement) => (view, getPos) => {
68
+ const deleteFootnoteWidget = (node, props, footnoteType, footnoteMessage, id, tableElement) => (view, getPos) => {
69
69
  const deleteBtn = document.createElement('span');
70
70
  deleteBtn.className = 'delete-icon';
71
71
  deleteBtn.innerHTML = deleteIcon;
72
- const parentType = tableElement ? 'table ' : '';
73
- const footnote = {
74
- type: node.type === schema.nodes.footnote
75
- ? `${parentType}footnote`
76
- : 'table general note',
77
- message: node.type === schema.nodes.footnote
78
- ? `This action will entirely remove the ${parentType}footnote from the list because it will no longer be used.`
79
- : 'This action will entirely remove the table general note.',
80
- };
81
- deleteBtn.addEventListener('mousedown', () => {
72
+ deleteBtn.addEventListener('click', () => {
82
73
  const handleDelete = () => {
83
74
  let tr = view.state.tr;
84
75
  const pos = getPos();
@@ -96,8 +87,7 @@ const deleteFootnoteWidget = (node, props, id, tableElement) => (view, getPos) =
96
87
  }
97
88
  }
98
89
  if (node.type === schema.nodes.footnote && pos) {
99
- const targetNode = tableElement ? tableElement.node : view.state.doc;
100
- const inlineFootnotes = getInlineFootnotes(id, targetNode);
90
+ const inlineFootnotes = getInlineFootnotes(id, tableElement);
101
91
  const nodeWithPos = findParentNodeClosestToPos(tr.doc.resolve(pos), (node) => node.type === schema.nodes.footnote);
102
92
  if (nodeWithPos) {
103
93
  const { pos: fnPos, node: fnNode } = nodeWithPos;
@@ -106,13 +96,13 @@ const deleteFootnoteWidget = (node, props, id, tableElement) => (view, getPos) =
106
96
  if (inlineFootnotes) {
107
97
  tr = view.state.tr;
108
98
  inlineFootnotes.forEach((footnote) => {
109
- const pos = footnote.pos + (tableElement ? tableElement.pos + 1 : 0);
99
+ const pos = footnote.pos + tableElement.pos;
110
100
  if (footnote.node.attrs.rids.length > 1) {
111
101
  const updatedRids = footnote.node.attrs.rids.filter((rid) => rid !== id);
112
102
  tr.setNodeMarkup(tr.mapping.map(pos + 1), undefined, Object.assign(Object.assign({}, node.attrs), { rids: updatedRids }));
113
103
  }
114
104
  else {
115
- tr.delete(tr.mapping.map(pos), tr.mapping.map(pos + footnote.node.nodeSize));
105
+ tr.delete(tr.mapping.map(pos + 1), tr.mapping.map(pos + footnote.node.nodeSize + 1));
116
106
  }
117
107
  });
118
108
  }
@@ -120,8 +110,8 @@ const deleteFootnoteWidget = (node, props, id, tableElement) => (view, getPos) =
120
110
  view.dispatch(tr);
121
111
  };
122
112
  const componentProps = {
123
- footnoteType: footnote.type,
124
- footnoteMessage: footnote.message,
113
+ footnoteType: footnoteType,
114
+ footnoteMessage: footnoteMessage,
125
115
  handleDelete: handleDelete,
126
116
  };
127
117
  ReactSubView(Object.assign(Object.assign({}, props), { dispatch: view.dispatch }), DeleteFootnoteDialog, componentProps, node, () => getPos(), view);
@@ -160,30 +150,19 @@ export default (props) => {
160
150
  props: {
161
151
  decorations: (state) => {
162
152
  const decorations = [];
163
- const tableElementFooter = findParentNodeOfType(schema.nodes.table_element_footer)(state.selection);
153
+ const isInTableElementFooter = hasParentNodeOfType(schema.nodes.table_element_footer)(state.selection);
164
154
  const tableElement = findParentNodeOfType(schema.nodes.table_element)(state.selection);
165
- const footnote = findParentNodeOfType(schema.nodes.footnote)(state.selection);
166
- let targetNode;
167
- if (footnote) {
168
- targetNode = footnote;
169
- }
170
- else if (tableElementFooter) {
171
- targetNode = tableElementFooter;
172
- }
173
- const can = props.getCapabilities();
174
- if (targetNode && can.editArticle) {
155
+ if (isInTableElementFooter) {
175
156
  const parent = findParentNodeWithIdValue(state.selection);
176
157
  if (parent) {
177
158
  decorations.push(Decoration.node(parent.pos, parent.pos + parent.node.nodeSize, {
178
159
  class: 'footnote-selected',
179
160
  }));
180
- decorations.push(Decoration.widget(targetNode.pos + 2, deleteFootnoteWidget(targetNode.node, props, targetNode.node.attrs.id, tableElement), {
181
- key: targetNode.node.attrs.id,
182
- }));
183
161
  }
184
162
  }
185
163
  const { labels } = footnotesKey.getState(state);
186
164
  let tableInlineFootnoteIds = undefined;
165
+ const can = props.getCapabilities();
187
166
  state.doc.descendants((node, pos, parent) => {
188
167
  var _a;
189
168
  if (isFootnoteNode(node)) {
@@ -204,6 +183,35 @@ export default (props) => {
204
183
  decorations.push(Decoration.widget(pos + node.nodeSize - 1, uncitedFootnoteWidget()));
205
184
  }
206
185
  }
186
+ if (can.editArticle) {
187
+ if (tableElement) {
188
+ const footnote = (() => {
189
+ switch (node.type) {
190
+ case schema.nodes.footnote:
191
+ return {
192
+ type: 'table footnote',
193
+ message: 'This action will entirely remove the table footnote from the list because it will no longer be used.',
194
+ };
195
+ default:
196
+ return {
197
+ type: 'table general note',
198
+ message: 'This action will entirely remove the table general note.',
199
+ };
200
+ }
201
+ })();
202
+ if (node.type === schema.nodes.footnote) {
203
+ decorations.push(Decoration.widget(pos + 2, deleteFootnoteWidget(node, props, footnote.type, footnote.message, node.attrs.id, tableElement), {
204
+ key: node.attrs.id,
205
+ }));
206
+ }
207
+ else if (node.type === schema.nodes.paragraph &&
208
+ (parent === null || parent === void 0 ? void 0 : parent.type) === schema.nodes.table_element_footer) {
209
+ decorations.push(Decoration.widget(pos + 1, deleteFootnoteWidget(parent, props, footnote.type, footnote.message, parent.attrs.id, tableElement), {
210
+ key: parent.attrs.id,
211
+ }));
212
+ }
213
+ }
214
+ }
207
215
  if (node.type === schema.nodes.footnotes_element) {
208
216
  if ((parent === null || parent === void 0 ? void 0 : parent.type) === schema.nodes.table_element_footer) {
209
217
  decorations.push(Decoration.node(pos, pos + node.nodeSize, {
@@ -26,5 +26,5 @@ interface InlineFootnote {
26
26
  node: InlineFootnoteNode;
27
27
  pos: number;
28
28
  }
29
- export declare const getInlineFootnotes: (id: string, targetNode: ManuscriptNode) => InlineFootnote[];
29
+ export declare const getInlineFootnotes: (id: string, tableElement: NodeWithPos) => InlineFootnote[];
30
30
  export {};
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": "1.8.7-LEAN-3140.1",
4
+ "version": "1.9.0",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -31,9 +31,9 @@
31
31
  "@manuscripts/assets": "^0.6.4",
32
32
  "@manuscripts/json-schema": "^2.2.7",
33
33
  "@manuscripts/library": "^1.3.6",
34
- "@manuscripts/style-guide": "^1.11.2",
34
+ "@manuscripts/style-guide": "1.12.0",
35
35
  "@manuscripts/track-changes-plugin": "1.7.10",
36
- "@manuscripts/transform": "^2.2.1",
36
+ "@manuscripts/transform": "2.3.0",
37
37
  "astrocite-eutils": "^0.16.4",
38
38
  "axios": "^1.6.7",
39
39
  "mathjax-full": "^3.2.2",
package/styles/Editor.css CHANGED
@@ -959,19 +959,18 @@
959
959
  .ProseMirror .table-footnotes-element {
960
960
  counter-reset: table_footnote;
961
961
  }
962
- .delete-icon {
962
+ .table-footer .delete-icon {
963
+ display: none;
963
964
  position: absolute;
964
965
  right: -20px;
965
966
  top: -13px;
966
967
  cursor: pointer;
967
968
  z-index: 1;
968
969
  }
969
- .delete-icon:hover svg path {
970
+ .table-footer .delete-icon:hover svg path {
970
971
  fill: #353535;
971
972
  }
972
- .ProseMirror .table-footnotes-element > div,
973
- .ProseMirror .block-footnotes_element > .block > div
974
- {
973
+ .ProseMirror .table-footnotes-element > div {
975
974
  position: relative;
976
975
  }
977
976
 
@@ -991,25 +990,29 @@
991
990
  margin-top: 0px;
992
991
  }
993
992
 
994
- .ProseMirror .footnote-selected, .table-footer > div:has(> p.footnote-selected) > p {
993
+ .ProseMirror .table-footer .footnote-selected, .table-footer > div:has(> p.footnote-selected) > p {
995
994
  background-color: #f2fbfc;
996
995
  padding: 4px;
997
996
  }
998
997
 
998
+ .ProseMirror .table-footer .footnote-selected .delete-icon ,.ProseMirror .table-footer .footnote-selected .deleted.rejected .delete-icon {
999
+ display: block;
1000
+ }
999
1001
  .table-footer > div > p {
1000
1002
  padding-bottom: 10px;
1001
1003
  }
1002
1004
 
1003
- .ProseMirror .table-footnotes-element .footnote-selected,
1004
- .ProseMirror .block-footnotes_element .footnote-selected
1005
- {
1005
+ .ProseMirror .table-footnotes-element .footnote-selected {
1006
1006
  border: 1px solid #bce7f6;
1007
1007
  }
1008
1008
  .table-footer > div:has(> p.footnote-selected) > p {
1009
1009
  border-left: 1px solid #bce7f6;
1010
1010
  border-right: 1px solid #bce7f6;
1011
1011
  }
1012
-
1012
+ .table-footer > div:has(> p.footnote-selected) > p:first-child .delete-icon {
1013
+ z-index: 2;
1014
+ display: block;
1015
+ }
1013
1016
  .table-footer > div:has(> p.footnote-selected) > p:first-child {
1014
1017
  border-top: 1px solid #bce7f6;
1015
1018
  position: relative;