@manuscripts/body-editor 3.1.2-LEAN-4616.0 → 3.2.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.
@@ -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, context: window },
40
+ return (react_1.default.createElement(react_dnd_1.DndProvider, { backend: react_dnd_html5_backend_1.HTML5Backend },
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,17 +51,20 @@ 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) => {
54
+ this.showAddMenu = (target, after) => {
55
55
  const menu = document.createElement('div');
56
56
  menu.className = 'menu';
57
57
  const $pos = this.resolvePos();
58
- const insertPos = $pos.after($pos.depth);
58
+ if ((0, transform_1.isInBibliographySection)($pos)) {
59
+ after = false;
60
+ }
61
+ const insertPos = after ? $pos.after($pos.depth) : $pos.before($pos.depth);
59
62
  const endPos = $pos.end();
60
- const types = this.insertableTypes(insertPos, endPos);
63
+ const types = this.insertableTypes(after, insertPos, endPos);
61
64
  const insertNode = (type, pos, attrs) => {
62
65
  const { state, dispatch } = this.view;
63
66
  if (pos === undefined) {
64
- pos = this.getPos() + this.node.nodeSize;
67
+ pos = after ? this.getPos() + this.node.nodeSize : this.getPos();
65
68
  }
66
69
  (0, commands_1.createBlock)(type, pos, state, dispatch, attrs);
67
70
  };
@@ -76,7 +79,7 @@ class ContextMenu {
76
79
  transform_1.schema.nodes.abstracts,
77
80
  transform_1.schema.nodes.backmatter,
78
81
  ])) {
79
- const labelPosition = 'After';
82
+ const labelPosition = after ? 'After' : 'Before';
80
83
  const level = (0, exports.sectionLevel)($pos.depth - 1);
81
84
  const label = `New ${level} ${labelPosition} ${itemTitle}`;
82
85
  section.appendChild(this.createMenuItem(label, () => {
@@ -322,13 +325,13 @@ class ContextMenu {
322
325
  }, true));
323
326
  return submenu;
324
327
  };
325
- this.insertableTypes = (insertPos, endPos) => {
328
+ this.insertableTypes = (after, insertPos, endPos) => {
326
329
  const { nodes } = transform_1.schema;
327
330
  const insertable = new Set();
328
331
  const doc = this.view.state.doc;
329
332
  const getPos = (pos) => {
330
333
  if (pos === undefined) {
331
- pos = this.getPos() + this.node.nodeSize;
334
+ pos = after ? this.getPos() + this.node.nodeSize : this.getPos();
332
335
  }
333
336
  return pos;
334
337
  };
@@ -105,9 +105,6 @@ 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
- }
111
108
  return !!(0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)($pos, type);
112
109
  };
113
110
  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.1.2-LEAN-4616.0';
4
+ exports.VERSION = '3.2.0';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -39,24 +39,19 @@ const EditableBlock = (Base) => {
39
39
  return null;
40
40
  }
41
41
  const $pos = this.view.state.doc.resolve(this.getPos());
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
- ])) {
42
+ if ((0, utils_1.hasParent)($pos, transform_1.schema.nodes.keywords)) {
49
43
  return null;
50
44
  }
45
+ const after = !(0, utils_1.hasParent)($pos, transform_1.schema.nodes.bibliography_section);
51
46
  const button = document.createElement('a');
52
47
  button.classList.add('add-block', context_menu_1.contextMenuBtnClass);
53
- button.classList.add('add-block-after');
54
- button.setAttribute('aria-label', `Add an element below`);
48
+ button.classList.add(after ? 'add-block-after' : 'add-block-before');
49
+ button.setAttribute('aria-label', `Add an element ${after ? 'below' : 'above'}`);
55
50
  button.setAttribute('data-balloon-pos', 'down-left');
56
51
  button.addEventListener('mousedown', (event) => {
57
52
  event.preventDefault();
58
53
  const menu = this.createMenu();
59
- menu.showAddMenu(event.currentTarget);
54
+ menu.showAddMenu(event.currentTarget, after);
60
55
  });
61
56
  return button;
62
57
  }
@@ -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, context: window },
34
+ return (React.createElement(DndProvider, { backend: HTML5Backend },
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 { isSectionTitleNode, nodeNames, schema, } from '@manuscripts/transform';
17
+ import { isInBibliographySection, 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,17 +47,20 @@ 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) => {
50
+ this.showAddMenu = (target, after) => {
51
51
  const menu = document.createElement('div');
52
52
  menu.className = 'menu';
53
53
  const $pos = this.resolvePos();
54
- const insertPos = $pos.after($pos.depth);
54
+ if (isInBibliographySection($pos)) {
55
+ after = false;
56
+ }
57
+ const insertPos = after ? $pos.after($pos.depth) : $pos.before($pos.depth);
55
58
  const endPos = $pos.end();
56
- const types = this.insertableTypes(insertPos, endPos);
59
+ const types = this.insertableTypes(after, insertPos, endPos);
57
60
  const insertNode = (type, pos, attrs) => {
58
61
  const { state, dispatch } = this.view;
59
62
  if (pos === undefined) {
60
- pos = this.getPos() + this.node.nodeSize;
63
+ pos = after ? this.getPos() + this.node.nodeSize : this.getPos();
61
64
  }
62
65
  createBlock(type, pos, state, dispatch, attrs);
63
66
  };
@@ -72,7 +75,7 @@ export class ContextMenu {
72
75
  schema.nodes.abstracts,
73
76
  schema.nodes.backmatter,
74
77
  ])) {
75
- const labelPosition = 'After';
78
+ const labelPosition = after ? 'After' : 'Before';
76
79
  const level = sectionLevel($pos.depth - 1);
77
80
  const label = `New ${level} ${labelPosition} ${itemTitle}`;
78
81
  section.appendChild(this.createMenuItem(label, () => {
@@ -318,13 +321,13 @@ export class ContextMenu {
318
321
  }, true));
319
322
  return submenu;
320
323
  };
321
- this.insertableTypes = (insertPos, endPos) => {
324
+ this.insertableTypes = (after, insertPos, endPos) => {
322
325
  const { nodes } = schema;
323
326
  const insertable = new Set();
324
327
  const doc = this.view.state.doc;
325
328
  const getPos = (pos) => {
326
329
  if (pos === undefined) {
327
- pos = this.getPos() + this.node.nodeSize;
330
+ pos = after ? this.getPos() + this.node.nodeSize : this.getPos();
328
331
  }
329
332
  return pos;
330
333
  };
@@ -92,9 +92,6 @@ 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
- }
98
95
  return !!findParentNodeOfTypeClosestToPos($pos, type);
99
96
  };
100
97
  export const shouldRenderField = (field, type) => {
@@ -1,2 +1,2 @@
1
- export const VERSION = '3.1.2-LEAN-4616.0';
1
+ export const VERSION = '3.2.0';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -36,24 +36,19 @@ export const EditableBlock = (Base) => {
36
36
  return null;
37
37
  }
38
38
  const $pos = this.view.state.doc.resolve(this.getPos());
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
- ])) {
39
+ if (hasParent($pos, schema.nodes.keywords)) {
46
40
  return null;
47
41
  }
42
+ const after = !hasParent($pos, schema.nodes.bibliography_section);
48
43
  const button = document.createElement('a');
49
44
  button.classList.add('add-block', contextMenuBtnClass);
50
- button.classList.add('add-block-after');
51
- button.setAttribute('aria-label', `Add an element below`);
45
+ button.classList.add(after ? 'add-block-after' : 'add-block-before');
46
+ button.setAttribute('aria-label', `Add an element ${after ? 'below' : 'above'}`);
52
47
  button.setAttribute('data-balloon-pos', 'down-left');
53
48
  button.addEventListener('mousedown', (event) => {
54
49
  event.preventDefault();
55
50
  const menu = this.createMenu();
56
- menu.showAddMenu(event.currentTarget);
51
+ menu.showAddMenu(event.currentTarget, after);
57
52
  });
58
53
  return button;
59
54
  }
@@ -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) => void;
24
+ showAddMenu: (target: Element, after: boolean) => 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 | ManuscriptNodeType[]) => boolean;
32
+ export declare const hasParent: ($pos: ResolvedPos, type: 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.1.2-LEAN-4616.0";
1
+ export declare const VERSION = "3.2.0";
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.1.2-LEAN-4616.0",
4
+ "version": "3.2.0",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -39,7 +39,7 @@
39
39
  "@manuscripts/json-schema": "2.2.12",
40
40
  "@manuscripts/style-guide": "3.1.0",
41
41
  "@manuscripts/track-changes-plugin": "2.0.1",
42
- "@manuscripts/transform": "4.1.1",
42
+ "@manuscripts/transform": "4.2.0",
43
43
  "@popperjs/core": "2.11.8",
44
44
  "citeproc": "2.4.63",
45
45
  "codemirror": "5.65.19",
package/styles/Editor.css CHANGED
@@ -780,8 +780,6 @@
780
780
  cursor: ns-resize;
781
781
  opacity: 0;
782
782
  transition: 0.2s all;
783
- display: flex;
784
- justify-content: flex-end;
785
783
  }
786
784
 
787
785
  .ProseMirror .action-gutter {