@manuscripts/body-editor 2.0.10 → 2.0.11

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.
@@ -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 = '2.0.10';
4
+ exports.VERSION = '2.0.11';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -73,7 +73,7 @@ class BibliographyElementBlockView extends block_view_1.default {
73
73
  componentProps.actions.push({
74
74
  label: 'Edit',
75
75
  action: () => this.handleEdit(element.id),
76
- icon: 'EditIcon',
76
+ icon: 'Edit',
77
77
  });
78
78
  }
79
79
  componentProps.actions.push({
@@ -77,11 +77,15 @@ class CitationEditableView extends citation_1.CitationView {
77
77
  };
78
78
  this.showContextMenu = () => {
79
79
  this.props.popper.destroy();
80
+ const can = this.props.getCapabilities();
81
+ const actions = [
82
+ { label: 'Comment', action: this.handleComment, icon: 'AddComment' },
83
+ ];
84
+ if (can.editArticle) {
85
+ actions.unshift({ label: 'Edit', action: this.handleEdit, icon: 'Edit' });
86
+ }
80
87
  const componentProps = {
81
- actions: [
82
- { label: 'Edit', action: this.handleEdit, icon: 'EditIcon' },
83
- { label: 'Comment', action: this.handleComment, icon: 'AddComment' },
84
- ],
88
+ actions,
85
89
  };
86
90
  this.contextMenu = (0, ReactSubView_1.default)(this.props, style_guide_1.ContextMenu, componentProps, this.node, this.getPos, this.view, 'context-menu');
87
91
  this.props.popper.show(this.dom, this.contextMenu, 'right-start', false);
@@ -205,7 +205,7 @@ class ContributorsView extends block_view_1.default {
205
205
  {
206
206
  label: 'Edit',
207
207
  action: () => this.handleEdit(element.id),
208
- icon: 'EditIcon',
208
+ icon: 'Edit',
209
209
  },
210
210
  ],
211
211
  };
@@ -34,8 +34,23 @@ class InlineFootnoteView extends base_node_view_1.BaseNodeView {
34
34
  constructor() {
35
35
  super(...arguments);
36
36
  this.findParentTableElement = () => (0, prosemirror_utils_1.findParentNodeClosestToPos)(this.view.state.doc.resolve(this.getPos()), (node) => node.type === transform_1.schema.nodes.table_element);
37
+ this.showContextMenu = () => {
38
+ this.props.popper.destroy();
39
+ const componentProps = {
40
+ actions: [
41
+ {
42
+ label: 'Edit',
43
+ action: () => {
44
+ this.props.popper.destroy();
45
+ this.activateGenericFnModal();
46
+ },
47
+ icon: 'Edit',
48
+ },
49
+ ],
50
+ };
51
+ this.props.popper.show(this.dom, (0, ReactSubView_1.default)(this.props, style_guide_1.ContextMenu, componentProps, this.node, this.getPos, this.view, 'context-menu'), 'right-start', false);
52
+ };
37
53
  this.handleClick = () => {
38
- var _a;
39
54
  if ((0, track_changes_utils_1.isDeleted)(this.node)) {
40
55
  return;
41
56
  }
@@ -46,21 +61,59 @@ class InlineFootnoteView extends base_node_view_1.BaseNodeView {
46
61
  onAdd: this.onAdd,
47
62
  });
48
63
  }
49
- else if (!this.activateGenericFnModal()) {
50
- if ((_a = this.node.attrs.rids) === null || _a === void 0 ? void 0 : _a.length) {
51
- let nodePos = undefined;
52
- this.view.state.doc.descendants((node, pos) => {
53
- if (node.attrs.id === this.node.attrs.rids[0]) {
54
- nodePos = pos;
55
- }
56
- });
57
- if (nodePos && this.props.dispatch) {
58
- const sel = prosemirror_state_1.TextSelection.near(this.view.state.doc.resolve(nodePos + 1));
59
- this.props.dispatch(this.view.state.tr.setSelection(sel).scrollIntoView());
64
+ else {
65
+ this.showContextMenu();
66
+ }
67
+ };
68
+ this.scrollToReferenced = () => {
69
+ var _a;
70
+ if ((_a = this.node.attrs.rids) === null || _a === void 0 ? void 0 : _a.length) {
71
+ let nodePos = undefined;
72
+ this.view.state.doc.descendants((node, pos) => {
73
+ if (node.attrs.id === this.node.attrs.rids[0]) {
74
+ nodePos = pos;
60
75
  }
76
+ });
77
+ if (nodePos && this.props.dispatch) {
78
+ const sel = prosemirror_state_1.TextSelection.near(this.view.state.doc.resolve(nodePos + 1));
79
+ this.props.dispatch(this.view.state.tr.setSelection(sel).scrollIntoView());
61
80
  }
62
81
  }
63
82
  };
83
+ this.activateGenericFnModal = () => {
84
+ if (!this.props.getCapabilities().editArticle) {
85
+ return;
86
+ }
87
+ const fnState = footnotes_1.footnotesKey.getState(this.view.state);
88
+ console.log(fnState);
89
+ if (fnState) {
90
+ this.activateModal({
91
+ notes: Array.from(fnState.unusedFootnotes.values()).map((n) => ({
92
+ node: n[0],
93
+ })),
94
+ onCancel: () => {
95
+ const { tr } = this.view.state;
96
+ if (!this.node.attrs.rids.length) {
97
+ this.view.dispatch(tr.delete(this.getPos(), this.getPos() + this.node.nodeSize));
98
+ }
99
+ this.destroy();
100
+ },
101
+ onAdd: () => {
102
+ const footnote = (0, commands_1.createFootnote)(this.view.state, 'footnote');
103
+ const tr = (0, commands_1.insertFootnote)(this.view.state, this.view.state.tr, footnote);
104
+ tr.setNodeAttribute(tr.mapping.map(this.getPos()), 'rids', [
105
+ footnote.attrs.id,
106
+ ]);
107
+ this.view.dispatch(tr);
108
+ this.view.focus();
109
+ this.destroy();
110
+ },
111
+ addNewLabel: 'Replace with new footnote',
112
+ });
113
+ return true;
114
+ }
115
+ return false;
116
+ };
64
117
  this.updateContents = () => {
65
118
  const attrs = this.node.attrs;
66
119
  this.dom.setAttribute('rids', attrs.rids.join(','));
@@ -154,39 +207,6 @@ class InlineFootnoteView extends base_node_view_1.BaseNodeView {
154
207
  this.popperContainer = (0, ReactSubView_1.default)(Object.assign(Object.assign({}, this.props), { dispatch: this.view.dispatch }), style_guide_1.FootnotesSelector, Object.assign(Object.assign({}, defaultModal), modalProps), this.node, this.getPos, this.view, 'footnote-editor');
155
208
  this.props.popper.show(this.dom, this.popperContainer, 'auto', false);
156
209
  }
157
- activateGenericFnModal() {
158
- if (!this.props.getCapabilities().editArticle) {
159
- return;
160
- }
161
- const fnState = footnotes_1.footnotesKey.getState(this.view.state);
162
- if (fnState && fnState.unusedFootnotes.size > 0) {
163
- this.activateModal({
164
- notes: Array.from(fnState.unusedFootnotes.values()).map((n) => ({
165
- node: n[0],
166
- })),
167
- onCancel: () => {
168
- const { tr } = this.view.state;
169
- if (!this.node.attrs.rids.length) {
170
- this.view.dispatch(tr.delete(this.getPos(), this.getPos() + this.node.nodeSize));
171
- }
172
- this.destroy();
173
- },
174
- onAdd: () => {
175
- const footnote = (0, commands_1.createFootnote)(this.view.state, 'footnote');
176
- const tr = (0, commands_1.insertFootnote)(this.view.state, this.view.state.tr, footnote);
177
- tr.setNodeAttribute(tr.mapping.map(this.getPos()), 'rids', [
178
- footnote.attrs.id,
179
- ]);
180
- this.view.dispatch(tr);
181
- this.view.focus();
182
- this.destroy();
183
- },
184
- addNewLabel: 'Replace with new footnote',
185
- });
186
- return true;
187
- }
188
- return false;
189
- }
190
210
  }
191
211
  exports.InlineFootnoteView = InlineFootnoteView;
192
212
  exports.default = (0, creators_1.createNodeView)(InlineFootnoteView);
@@ -1,2 +1,2 @@
1
- export const VERSION = '2.0.10';
1
+ export const VERSION = '2.0.11';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -67,7 +67,7 @@ export class BibliographyElementBlockView extends BlockView {
67
67
  componentProps.actions.push({
68
68
  label: 'Edit',
69
69
  action: () => this.handleEdit(element.id),
70
- icon: 'EditIcon',
70
+ icon: 'Edit',
71
71
  });
72
72
  }
73
73
  componentProps.actions.push({
@@ -71,11 +71,15 @@ export class CitationEditableView extends CitationView {
71
71
  };
72
72
  this.showContextMenu = () => {
73
73
  this.props.popper.destroy();
74
+ const can = this.props.getCapabilities();
75
+ const actions = [
76
+ { label: 'Comment', action: this.handleComment, icon: 'AddComment' },
77
+ ];
78
+ if (can.editArticle) {
79
+ actions.unshift({ label: 'Edit', action: this.handleEdit, icon: 'Edit' });
80
+ }
74
81
  const componentProps = {
75
- actions: [
76
- { label: 'Edit', action: this.handleEdit, icon: 'EditIcon' },
77
- { label: 'Comment', action: this.handleComment, icon: 'AddComment' },
78
- ],
82
+ actions,
79
83
  };
80
84
  this.contextMenu = ReactSubView(this.props, ContextMenu, componentProps, this.node, this.getPos, this.view, 'context-menu');
81
85
  this.props.popper.show(this.dom, this.contextMenu, 'right-start', false);
@@ -199,7 +199,7 @@ export class ContributorsView extends BlockView {
199
199
  {
200
200
  label: 'Edit',
201
201
  action: () => this.handleEdit(element.id),
202
- icon: 'EditIcon',
202
+ icon: 'Edit',
203
203
  },
204
204
  ],
205
205
  };
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { FootnotesSelector } from '@manuscripts/style-guide';
16
+ import { ContextMenu, FootnotesSelector, } from '@manuscripts/style-guide';
17
17
  import { schema, } from '@manuscripts/transform';
18
18
  import { NodeSelection, TextSelection } from 'prosemirror-state';
19
19
  import { findChildrenByType, findParentNodeClosestToPos, } from 'prosemirror-utils';
@@ -28,8 +28,23 @@ export class InlineFootnoteView extends BaseNodeView {
28
28
  constructor() {
29
29
  super(...arguments);
30
30
  this.findParentTableElement = () => findParentNodeClosestToPos(this.view.state.doc.resolve(this.getPos()), (node) => node.type === schema.nodes.table_element);
31
+ this.showContextMenu = () => {
32
+ this.props.popper.destroy();
33
+ const componentProps = {
34
+ actions: [
35
+ {
36
+ label: 'Edit',
37
+ action: () => {
38
+ this.props.popper.destroy();
39
+ this.activateGenericFnModal();
40
+ },
41
+ icon: 'Edit',
42
+ },
43
+ ],
44
+ };
45
+ this.props.popper.show(this.dom, ReactSubView(this.props, ContextMenu, componentProps, this.node, this.getPos, this.view, 'context-menu'), 'right-start', false);
46
+ };
31
47
  this.handleClick = () => {
32
- var _a;
33
48
  if (isDeleted(this.node)) {
34
49
  return;
35
50
  }
@@ -40,21 +55,59 @@ export class InlineFootnoteView extends BaseNodeView {
40
55
  onAdd: this.onAdd,
41
56
  });
42
57
  }
43
- else if (!this.activateGenericFnModal()) {
44
- if ((_a = this.node.attrs.rids) === null || _a === void 0 ? void 0 : _a.length) {
45
- let nodePos = undefined;
46
- this.view.state.doc.descendants((node, pos) => {
47
- if (node.attrs.id === this.node.attrs.rids[0]) {
48
- nodePos = pos;
49
- }
50
- });
51
- if (nodePos && this.props.dispatch) {
52
- const sel = TextSelection.near(this.view.state.doc.resolve(nodePos + 1));
53
- this.props.dispatch(this.view.state.tr.setSelection(sel).scrollIntoView());
58
+ else {
59
+ this.showContextMenu();
60
+ }
61
+ };
62
+ this.scrollToReferenced = () => {
63
+ var _a;
64
+ if ((_a = this.node.attrs.rids) === null || _a === void 0 ? void 0 : _a.length) {
65
+ let nodePos = undefined;
66
+ this.view.state.doc.descendants((node, pos) => {
67
+ if (node.attrs.id === this.node.attrs.rids[0]) {
68
+ nodePos = pos;
54
69
  }
70
+ });
71
+ if (nodePos && this.props.dispatch) {
72
+ const sel = TextSelection.near(this.view.state.doc.resolve(nodePos + 1));
73
+ this.props.dispatch(this.view.state.tr.setSelection(sel).scrollIntoView());
55
74
  }
56
75
  }
57
76
  };
77
+ this.activateGenericFnModal = () => {
78
+ if (!this.props.getCapabilities().editArticle) {
79
+ return;
80
+ }
81
+ const fnState = footnotesKey.getState(this.view.state);
82
+ console.log(fnState);
83
+ if (fnState) {
84
+ this.activateModal({
85
+ notes: Array.from(fnState.unusedFootnotes.values()).map((n) => ({
86
+ node: n[0],
87
+ })),
88
+ onCancel: () => {
89
+ const { tr } = this.view.state;
90
+ if (!this.node.attrs.rids.length) {
91
+ this.view.dispatch(tr.delete(this.getPos(), this.getPos() + this.node.nodeSize));
92
+ }
93
+ this.destroy();
94
+ },
95
+ onAdd: () => {
96
+ const footnote = createFootnote(this.view.state, 'footnote');
97
+ const tr = insertFootnote(this.view.state, this.view.state.tr, footnote);
98
+ tr.setNodeAttribute(tr.mapping.map(this.getPos()), 'rids', [
99
+ footnote.attrs.id,
100
+ ]);
101
+ this.view.dispatch(tr);
102
+ this.view.focus();
103
+ this.destroy();
104
+ },
105
+ addNewLabel: 'Replace with new footnote',
106
+ });
107
+ return true;
108
+ }
109
+ return false;
110
+ };
58
111
  this.updateContents = () => {
59
112
  const attrs = this.node.attrs;
60
113
  this.dom.setAttribute('rids', attrs.rids.join(','));
@@ -148,38 +201,5 @@ export class InlineFootnoteView extends BaseNodeView {
148
201
  this.popperContainer = ReactSubView(Object.assign(Object.assign({}, this.props), { dispatch: this.view.dispatch }), FootnotesSelector, Object.assign(Object.assign({}, defaultModal), modalProps), this.node, this.getPos, this.view, 'footnote-editor');
149
202
  this.props.popper.show(this.dom, this.popperContainer, 'auto', false);
150
203
  }
151
- activateGenericFnModal() {
152
- if (!this.props.getCapabilities().editArticle) {
153
- return;
154
- }
155
- const fnState = footnotesKey.getState(this.view.state);
156
- if (fnState && fnState.unusedFootnotes.size > 0) {
157
- this.activateModal({
158
- notes: Array.from(fnState.unusedFootnotes.values()).map((n) => ({
159
- node: n[0],
160
- })),
161
- onCancel: () => {
162
- const { tr } = this.view.state;
163
- if (!this.node.attrs.rids.length) {
164
- this.view.dispatch(tr.delete(this.getPos(), this.getPos() + this.node.nodeSize));
165
- }
166
- this.destroy();
167
- },
168
- onAdd: () => {
169
- const footnote = createFootnote(this.view.state, 'footnote');
170
- const tr = insertFootnote(this.view.state, this.view.state.tr, footnote);
171
- tr.setNodeAttribute(tr.mapping.map(this.getPos()), 'rids', [
172
- footnote.attrs.id,
173
- ]);
174
- this.view.dispatch(tr);
175
- this.view.focus();
176
- this.destroy();
177
- },
178
- addNewLabel: 'Replace with new footnote',
179
- });
180
- return true;
181
- }
182
- return false;
183
- }
184
204
  }
185
205
  export default createNodeView(InlineFootnoteView);
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "2.0.10";
1
+ export declare const VERSION = "2.0.11";
2
2
  export declare const MATHJAX_VERSION = "3.2.2";
@@ -27,9 +27,11 @@ export declare class InlineFootnoteView<PropsType extends InlineFootnoteProps &
27
27
  protected popperContainer: HTMLDivElement;
28
28
  isSelected(): boolean;
29
29
  findParentTableElement: () => ContentNodeWithPos | undefined;
30
+ showContextMenu: () => void;
30
31
  handleClick: () => void;
32
+ scrollToReferenced: () => void;
31
33
  activateModal(modalProps: Partial<ModalProps>): void;
32
- activateGenericFnModal(): boolean | undefined;
34
+ activateGenericFnModal: () => boolean | undefined;
33
35
  updateContents: () => void;
34
36
  initialise: () => void;
35
37
  ignoreMutation: () => boolean;
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.0.10",
4
+ "version": "2.0.11",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -32,7 +32,7 @@
32
32
  "@iarna/word-count": "^1.1.2",
33
33
  "@manuscripts/json-schema": "2.2.10",
34
34
  "@manuscripts/library": "1.3.10",
35
- "@manuscripts/style-guide": "2.0.1",
35
+ "@manuscripts/style-guide": "2.0.2",
36
36
  "@manuscripts/track-changes-plugin": "1.7.17",
37
37
  "@manuscripts/transform": "2.3.21",
38
38
  "@popperjs/core": "^2.11.8",
@@ -116,4 +116,4 @@
116
116
  "engines": {
117
117
  "node": ">=20.16.0"
118
118
  }
119
- }
119
+ }