@manuscripts/body-editor 3.2.0 → 3.2.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.
@@ -37,7 +37,7 @@ const AuthorListTitle = styled_components_1.default.h2 `
37
37
  margin-top: 20px;
38
38
  `;
39
39
  const AuthorList = ({ author, authors, onSelect, onDelete, moveAuthor, lastSavedAuthor, }) => {
40
- return (react_1.default.createElement(react_dnd_1.DndProvider, { backend: react_dnd_html5_backend_1.HTML5Backend },
40
+ return (react_1.default.createElement(react_dnd_1.DndProvider, { backend: react_dnd_html5_backend_1.HTML5Backend, context: window },
41
41
  react_1.default.createElement(AuthorListTitle, null, "Existing Authors"),
42
42
  react_1.default.createElement(AuthorListContainer, { "data-cy": "authors-list" }, authors.map((a) => {
43
43
  return (react_1.default.createElement(DraggableAuthor_1.DraggableAuthor, { key: a.id, author: a, isSelected: a.id === author?.id, onClick: () => onSelect(a), onDelete: () => onDelete(), moveAuthor: moveAuthor, showSuccessIcon: lastSavedAuthor === a.id }));
@@ -51,20 +51,17 @@ exports.contextMenuBtnClass = 'btn-context-menu';
51
51
  const contextSubmenuBtnClass = 'context-submenu-trigger';
52
52
  class ContextMenu {
53
53
  constructor(node, view, getPos) {
54
- this.showAddMenu = (target, after) => {
54
+ this.showAddMenu = (target) => {
55
55
  const menu = document.createElement('div');
56
56
  menu.className = 'menu';
57
57
  const $pos = this.resolvePos();
58
- if ((0, transform_1.isInBibliographySection)($pos)) {
59
- after = false;
60
- }
61
- const insertPos = after ? $pos.after($pos.depth) : $pos.before($pos.depth);
58
+ const insertPos = $pos.after($pos.depth);
62
59
  const endPos = $pos.end();
63
- const types = this.insertableTypes(after, insertPos, endPos);
60
+ const types = this.insertableTypes(insertPos, endPos);
64
61
  const insertNode = (type, pos, attrs) => {
65
62
  const { state, dispatch } = this.view;
66
63
  if (pos === undefined) {
67
- pos = after ? this.getPos() + this.node.nodeSize : this.getPos();
64
+ pos = this.getPos() + this.node.nodeSize;
68
65
  }
69
66
  (0, commands_1.createBlock)(type, pos, state, dispatch, attrs);
70
67
  };
@@ -79,7 +76,7 @@ class ContextMenu {
79
76
  transform_1.schema.nodes.abstracts,
80
77
  transform_1.schema.nodes.backmatter,
81
78
  ])) {
82
- const labelPosition = after ? 'After' : 'Before';
79
+ const labelPosition = 'After';
83
80
  const level = (0, exports.sectionLevel)($pos.depth - 1);
84
81
  const label = `New ${level} ${labelPosition} ${itemTitle}`;
85
82
  section.appendChild(this.createMenuItem(label, () => {
@@ -267,7 +264,9 @@ class ContextMenu {
267
264
  menu.append(this.createMenuSection((e) => e.append(...items)));
268
265
  }
269
266
  }
270
- if (!readonlyTypes.includes(type) &&
267
+ if (!(type === transform_1.schema.nodes.figure_element &&
268
+ (0, transform_1.isInGraphicalAbstractSection)($pos)) &&
269
+ !readonlyTypes.includes(type) &&
271
270
  !readonlyTypes.includes($pos.parent.type)) {
272
271
  menu.appendChild(this.createMenuSection((section) => {
273
272
  let nodeName = transform_1.nodeNames.get(type) || '';
@@ -325,13 +324,13 @@ class ContextMenu {
325
324
  }, true));
326
325
  return submenu;
327
326
  };
328
- this.insertableTypes = (after, insertPos, endPos) => {
327
+ this.insertableTypes = (insertPos, endPos) => {
329
328
  const { nodes } = transform_1.schema;
330
329
  const insertable = new Set();
331
330
  const doc = this.view.state.doc;
332
331
  const getPos = (pos) => {
333
332
  if (pos === undefined) {
334
- pos = after ? this.getPos() + this.node.nodeSize : this.getPos();
333
+ pos = this.getPos() + this.node.nodeSize;
335
334
  }
336
335
  return pos;
337
336
  };
@@ -105,6 +105,9 @@ exports.createHeader = createHeader;
105
105
  const isNotNull = (a) => a !== null;
106
106
  exports.isNotNull = isNotNull;
107
107
  const hasParent = ($pos, type) => {
108
+ if (Array.isArray(type)) {
109
+ return type.some((nodeType) => !!(0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)($pos, nodeType));
110
+ }
108
111
  return !!(0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)($pos, type);
109
112
  };
110
113
  exports.hasParent = hasParent;
@@ -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.2.0';
4
+ exports.VERSION = '3.2.2';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -39,19 +39,24 @@ const EditableBlock = (Base) => {
39
39
  return null;
40
40
  }
41
41
  const $pos = this.view.state.doc.resolve(this.getPos());
42
- if ((0, utils_1.hasParent)($pos, transform_1.schema.nodes.keywords)) {
42
+ const nodeType = this.node.type;
43
+ if (nodeType === transform_1.schema.nodes.hero_image ||
44
+ (0, utils_1.hasParent)($pos, [
45
+ transform_1.schema.nodes.keywords,
46
+ transform_1.schema.nodes.bibliography_section,
47
+ transform_1.schema.nodes.footnotes_section,
48
+ ])) {
43
49
  return null;
44
50
  }
45
- const after = !(0, utils_1.hasParent)($pos, transform_1.schema.nodes.bibliography_section);
46
51
  const button = document.createElement('a');
47
52
  button.classList.add('add-block', context_menu_1.contextMenuBtnClass);
48
- button.classList.add(after ? 'add-block-after' : 'add-block-before');
49
- button.setAttribute('aria-label', `Add an element ${after ? 'below' : 'above'}`);
53
+ button.classList.add('add-block-after');
54
+ button.setAttribute('aria-label', `Add an element below`);
50
55
  button.setAttribute('data-balloon-pos', 'down-left');
51
56
  button.addEventListener('mousedown', (event) => {
52
57
  event.preventDefault();
53
58
  const menu = this.createMenu();
54
- menu.showAddMenu(event.currentTarget, after);
59
+ menu.showAddMenu(event.currentTarget);
55
60
  });
56
61
  return button;
57
62
  }
@@ -31,7 +31,7 @@ const AuthorListTitle = styled.h2 `
31
31
  margin-top: 20px;
32
32
  `;
33
33
  export const AuthorList = ({ author, authors, onSelect, onDelete, moveAuthor, lastSavedAuthor, }) => {
34
- return (React.createElement(DndProvider, { backend: HTML5Backend },
34
+ return (React.createElement(DndProvider, { backend: HTML5Backend, context: window },
35
35
  React.createElement(AuthorListTitle, null, "Existing Authors"),
36
36
  React.createElement(AuthorListContainer, { "data-cy": "authors-list" }, authors.map((a) => {
37
37
  return (React.createElement(DraggableAuthor, { key: a.id, author: a, isSelected: a.id === author?.id, onClick: () => onSelect(a), onDelete: () => onDelete(), moveAuthor: moveAuthor, showSuccessIcon: lastSavedAuthor === a.id }));
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { ImageDefaultIcon, ImageLeftIcon, ImageRightIcon, TriangleCollapsedIcon, } from '@manuscripts/style-guide';
17
- import { isInBibliographySection, isSectionTitleNode, nodeNames, schema, } from '@manuscripts/transform';
17
+ import { isInGraphicalAbstractSection, isSectionTitleNode, nodeNames, schema, } from '@manuscripts/transform';
18
18
  import { findChildrenByType } from 'prosemirror-utils';
19
19
  import { createElement } from 'react';
20
20
  import { renderToStaticMarkup } from 'react-dom/server';
@@ -47,20 +47,17 @@ export const contextMenuBtnClass = 'btn-context-menu';
47
47
  const contextSubmenuBtnClass = 'context-submenu-trigger';
48
48
  export class ContextMenu {
49
49
  constructor(node, view, getPos) {
50
- this.showAddMenu = (target, after) => {
50
+ this.showAddMenu = (target) => {
51
51
  const menu = document.createElement('div');
52
52
  menu.className = 'menu';
53
53
  const $pos = this.resolvePos();
54
- if (isInBibliographySection($pos)) {
55
- after = false;
56
- }
57
- const insertPos = after ? $pos.after($pos.depth) : $pos.before($pos.depth);
54
+ const insertPos = $pos.after($pos.depth);
58
55
  const endPos = $pos.end();
59
- const types = this.insertableTypes(after, insertPos, endPos);
56
+ const types = this.insertableTypes(insertPos, endPos);
60
57
  const insertNode = (type, pos, attrs) => {
61
58
  const { state, dispatch } = this.view;
62
59
  if (pos === undefined) {
63
- pos = after ? this.getPos() + this.node.nodeSize : this.getPos();
60
+ pos = this.getPos() + this.node.nodeSize;
64
61
  }
65
62
  createBlock(type, pos, state, dispatch, attrs);
66
63
  };
@@ -75,7 +72,7 @@ export class ContextMenu {
75
72
  schema.nodes.abstracts,
76
73
  schema.nodes.backmatter,
77
74
  ])) {
78
- const labelPosition = after ? 'After' : 'Before';
75
+ const labelPosition = 'After';
79
76
  const level = sectionLevel($pos.depth - 1);
80
77
  const label = `New ${level} ${labelPosition} ${itemTitle}`;
81
78
  section.appendChild(this.createMenuItem(label, () => {
@@ -263,7 +260,9 @@ export class ContextMenu {
263
260
  menu.append(this.createMenuSection((e) => e.append(...items)));
264
261
  }
265
262
  }
266
- if (!readonlyTypes.includes(type) &&
263
+ if (!(type === schema.nodes.figure_element &&
264
+ isInGraphicalAbstractSection($pos)) &&
265
+ !readonlyTypes.includes(type) &&
267
266
  !readonlyTypes.includes($pos.parent.type)) {
268
267
  menu.appendChild(this.createMenuSection((section) => {
269
268
  let nodeName = nodeNames.get(type) || '';
@@ -321,13 +320,13 @@ export class ContextMenu {
321
320
  }, true));
322
321
  return submenu;
323
322
  };
324
- this.insertableTypes = (after, insertPos, endPos) => {
323
+ this.insertableTypes = (insertPos, endPos) => {
325
324
  const { nodes } = schema;
326
325
  const insertable = new Set();
327
326
  const doc = this.view.state.doc;
328
327
  const getPos = (pos) => {
329
328
  if (pos === undefined) {
330
- pos = after ? this.getPos() + this.node.nodeSize : this.getPos();
329
+ pos = this.getPos() + this.node.nodeSize;
331
330
  }
332
331
  return pos;
333
332
  };
@@ -92,6 +92,9 @@ export const createHeader = (typeName, text) => {
92
92
  };
93
93
  export const isNotNull = (a) => a !== null;
94
94
  export const hasParent = ($pos, type) => {
95
+ if (Array.isArray(type)) {
96
+ return type.some((nodeType) => !!findParentNodeOfTypeClosestToPos($pos, nodeType));
97
+ }
95
98
  return !!findParentNodeOfTypeClosestToPos($pos, type);
96
99
  };
97
100
  export const shouldRenderField = (field, type) => {
@@ -1,2 +1,2 @@
1
- export const VERSION = '3.2.0';
1
+ export const VERSION = '3.2.2';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -36,19 +36,24 @@ export const EditableBlock = (Base) => {
36
36
  return null;
37
37
  }
38
38
  const $pos = this.view.state.doc.resolve(this.getPos());
39
- if (hasParent($pos, schema.nodes.keywords)) {
39
+ const nodeType = this.node.type;
40
+ if (nodeType === schema.nodes.hero_image ||
41
+ hasParent($pos, [
42
+ schema.nodes.keywords,
43
+ schema.nodes.bibliography_section,
44
+ schema.nodes.footnotes_section,
45
+ ])) {
40
46
  return null;
41
47
  }
42
- const after = !hasParent($pos, schema.nodes.bibliography_section);
43
48
  const button = document.createElement('a');
44
49
  button.classList.add('add-block', contextMenuBtnClass);
45
- button.classList.add(after ? 'add-block-after' : 'add-block-before');
46
- button.setAttribute('aria-label', `Add an element ${after ? 'below' : 'above'}`);
50
+ button.classList.add('add-block-after');
51
+ button.setAttribute('aria-label', `Add an element below`);
47
52
  button.setAttribute('data-balloon-pos', 'down-left');
48
53
  button.addEventListener('mousedown', (event) => {
49
54
  event.preventDefault();
50
55
  const menu = this.createMenu();
51
- menu.showAddMenu(event.currentTarget, after);
56
+ menu.showAddMenu(event.currentTarget);
52
57
  });
53
58
  return button;
54
59
  }
@@ -21,7 +21,7 @@ export declare class ContextMenu {
21
21
  private readonly view;
22
22
  private readonly getPos;
23
23
  constructor(node: ManuscriptNode, view: ManuscriptEditorView, getPos: () => number);
24
- showAddMenu: (target: Element, after: boolean) => void;
24
+ showAddMenu: (target: Element) => void;
25
25
  showEditMenu: (target: Element) => void;
26
26
  private createSubmenuTrigger;
27
27
  private createMenuItem;
@@ -29,7 +29,7 @@ export declare const isSelectionInNode: (state: EditorState, targetNode: ProseMi
29
29
  export declare const isSelectionInBody: (state: EditorState) => boolean;
30
30
  export declare const createHeader: (typeName: string, text: string) => HTMLHeadingElement;
31
31
  export declare const isNotNull: <T>(a: T | null) => a is T;
32
- export declare const hasParent: ($pos: ResolvedPos, type: ManuscriptNodeType) => boolean;
32
+ export declare const hasParent: ($pos: ResolvedPos, type: ManuscriptNodeType | ManuscriptNodeType[]) => boolean;
33
33
  export declare const shouldRenderField: (field: string, type: BibliographyItemType) => boolean;
34
34
  export declare const cleanItemValues: (item: BibliographyItemAttrs) => BibliographyItemAttrs;
35
35
  export declare const isBodyLocked: (state: EditorState) => boolean;
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "3.2.0";
1
+ export declare const VERSION = "3.2.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.2.0",
4
+ "version": "3.2.2",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
package/styles/Editor.css CHANGED
@@ -780,6 +780,8 @@
780
780
  cursor: ns-resize;
781
781
  opacity: 0;
782
782
  transition: 0.2s all;
783
+ display: flex;
784
+ justify-content: flex-end;
783
785
  }
784
786
 
785
787
  .ProseMirror .action-gutter {