@manuscripts/body-editor 3.10.8 → 3.10.9

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.
@@ -778,16 +778,16 @@ const insertAffiliation = (state, dispatch, view) => {
778
778
  return true;
779
779
  };
780
780
  exports.insertAffiliation = insertAffiliation;
781
- const insertAward = (state, dispatch, view) => {
782
- const award = transform_1.schema.nodes.award.create();
781
+ const insertAward = (attrs) => (state, dispatch, view) => {
782
+ const award = transform_1.schema.nodes.award.create(attrs);
783
783
  const tr = state.tr;
784
784
  const awards = (0, doc_1.insertAwardsNode)(tr);
785
785
  const pos = awards.pos + awards.node.nodeSize - 1;
786
786
  tr.insert(pos, award);
787
787
  const selection = prosemirror_state_1.NodeSelection.create(tr.doc, pos);
788
- view && view.focus();
789
- if (dispatch) {
788
+ if (dispatch && view) {
790
789
  dispatch(tr.setSelection(selection).scrollIntoView());
790
+ view.focus();
791
791
  }
792
792
  return true;
793
793
  };
@@ -32,18 +32,25 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.AwardModal = void 0;
39
+ exports.openInsertAwardModal = exports.AwardModal = void 0;
37
40
  const style_guide_1 = require("@manuscripts/style-guide");
38
41
  const react_1 = __importStar(require("react"));
42
+ const transform_1 = require("@manuscripts/transform");
43
+ const ReactSubView_1 = __importDefault(require("../../views/ReactSubView"));
44
+ const editor_props_1 = require("../../plugins/editor-props");
39
45
  const AwardForm_1 = require("./AwardForm");
46
+ const commands_1 = require("../../commands");
40
47
  const normalizeData = (award) => ({
41
48
  id: award.id || '',
42
49
  source: award.source || '',
43
50
  code: award.code || '',
44
51
  recipient: award.recipient || '',
45
52
  });
46
- const AwardModal = ({ initialData, onSaveAward, onCancelAward, }) => {
53
+ const AwardModal = ({ initialData, onSaveAward, }) => {
47
54
  const [isOpen, setOpen] = (0, react_1.useState)(true);
48
55
  const valuesRef = (0, react_1.useRef)(undefined);
49
56
  const handleSave = () => {
@@ -53,19 +60,29 @@ const AwardModal = ({ initialData, onSaveAward, onCancelAward, }) => {
53
60
  handleClose();
54
61
  }
55
62
  };
56
- const handleCancel = () => {
57
- onCancelAward && onCancelAward();
58
- handleClose();
59
- };
60
63
  const handleClose = () => setOpen(false);
61
64
  const handleChange = (values) => (valuesRef.current = values);
62
65
  const normalizedValues = react_1.default.useMemo(() => normalizeData(initialData), [initialData]);
63
- return (react_1.default.createElement(style_guide_1.StyledModal, { isOpen: isOpen, onRequestClose: handleCancel, shouldCloseOnOverlayClick: true },
66
+ return (react_1.default.createElement(style_guide_1.StyledModal, { isOpen: isOpen, onRequestClose: handleClose, shouldCloseOnOverlayClick: true },
64
67
  react_1.default.createElement(style_guide_1.ModalContainer, { "data-cy": "award-modal" },
65
68
  react_1.default.createElement(style_guide_1.ModalHeader, null,
66
- react_1.default.createElement(style_guide_1.CloseButton, { onClick: handleCancel, "data-cy": "modal-close-button" })),
69
+ react_1.default.createElement(style_guide_1.CloseButton, { onClick: handleClose, "data-cy": "modal-close-button" })),
67
70
  react_1.default.createElement(style_guide_1.ModalCardBody, { width: 480 },
68
71
  react_1.default.createElement(style_guide_1.ModalTitle, null, "Add Funder information"),
69
- react_1.default.createElement(AwardForm_1.AwardForm, { values: normalizedValues, onSave: handleSave, onCancel: handleCancel, onChange: handleChange })))));
72
+ react_1.default.createElement(AwardForm_1.AwardForm, { values: normalizedValues, onSave: handleSave, onCancel: handleClose, onChange: handleChange })))));
70
73
  };
71
74
  exports.AwardModal = AwardModal;
75
+ const openInsertAwardModal = (view) => {
76
+ if (!view) {
77
+ return;
78
+ }
79
+ const { state, dispatch } = view;
80
+ const props = (0, editor_props_1.getEditorProps)(state);
81
+ const onSaveAward = (attrs) => {
82
+ (0, commands_1.insertAward)(attrs)(state, dispatch, view);
83
+ };
84
+ const initialData = transform_1.schema.nodes.award.create().attrs;
85
+ const dialog = (0, ReactSubView_1.default)(props, exports.AwardModal, { initialData, onSaveAward }, state.doc, () => 0, view);
86
+ document.body.appendChild(dialog);
87
+ };
88
+ exports.openInsertAwardModal = openInsertAwardModal;
package/dist/cjs/menus.js CHANGED
@@ -27,6 +27,7 @@ const hierarchy_1 = require("./lib/hierarchy");
27
27
  const template_1 = require("./lib/template");
28
28
  const utils_1 = require("./lib/utils");
29
29
  const editor_props_1 = require("./plugins/editor-props");
30
+ const AwardModal_1 = require("./components/awards/AwardModal");
30
31
  const getEditorMenus = (editor) => {
31
32
  const { isCommandValid, state, view } = editor;
32
33
  const doCommand = (command) => () => editor.doCommand(command);
@@ -562,8 +563,8 @@ const getEditorMenus = (editor) => {
562
563
  {
563
564
  id: 'insert-awards',
564
565
  label: 'Funder Information',
565
- isEnabled: isCommandValid(commands_1.insertAward),
566
- run: doCommand(commands_1.insertAward),
566
+ isEnabled: (0, utils_1.isEditAllowed)(state) && isCommandValid((0, commands_1.insertAward)()),
567
+ run: () => (0, AwardModal_1.openInsertAwardModal)(view),
567
568
  isHidden: !(0, template_1.templateAllows)(state, transform_1.schema.nodes.awards),
568
569
  },
569
570
  {
@@ -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.10.8';
4
+ exports.VERSION = '3.10.9';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -31,7 +31,6 @@ const ReactSubView_1 = __importDefault(require("./ReactSubView"));
31
31
  class AwardView extends block_view_1.default {
32
32
  constructor() {
33
33
  super(...arguments);
34
- this.newAward = false;
35
34
  this.ignoreMutation = () => true;
36
35
  this.stopEvent = () => true;
37
36
  this.createAwardFragment = (className, title, content) => {
@@ -89,7 +88,6 @@ class AwardView extends block_view_1.default {
89
88
  const componentProps = {
90
89
  initialData: award?.attrs || {},
91
90
  onSaveAward: this.handleSaveAward,
92
- onCancelAward: this.handleCancelAward,
93
91
  };
94
92
  this.popperContainer = (0, ReactSubView_1.default)(this.props, AwardModal_1.AwardModal, componentProps, this.node, this.getPos, this.view, ['award-editor']);
95
93
  this.props.popper.show(this.dom, this.popperContainer, 'auto', false);
@@ -105,11 +103,6 @@ class AwardView extends block_view_1.default {
105
103
  this.handleSaveAward = (award) => {
106
104
  (0, view_1.updateNodeAttrs)(this.view, transform_1.schema.nodes.award, award);
107
105
  };
108
- this.handleCancelAward = () => {
109
- if (this.newAward) {
110
- this.handleDeleteAward();
111
- }
112
- };
113
106
  this.handleDeleteAward = () => {
114
107
  const award = this.node;
115
108
  const pos = this.getPos();
@@ -139,13 +132,6 @@ class AwardView extends block_view_1.default {
139
132
  this.contentDOM.appendChild(fragment);
140
133
  this.updateClasses();
141
134
  }
142
- selectNode() {
143
- super.selectNode();
144
- if (!this.node.attrs.source) {
145
- this.newAward = true;
146
- this.showAwardModal(this.node);
147
- }
148
- }
149
135
  }
150
136
  exports.AwardView = AwardView;
151
137
  exports.default = (0, creators_1.createNodeView)(AwardView);
@@ -741,16 +741,16 @@ export const insertAffiliation = (state, dispatch, view) => {
741
741
  }
742
742
  return true;
743
743
  };
744
- export const insertAward = (state, dispatch, view) => {
745
- const award = schema.nodes.award.create();
744
+ export const insertAward = (attrs) => (state, dispatch, view) => {
745
+ const award = schema.nodes.award.create(attrs);
746
746
  const tr = state.tr;
747
747
  const awards = insertAwardsNode(tr);
748
748
  const pos = awards.pos + awards.node.nodeSize - 1;
749
749
  tr.insert(pos, award);
750
750
  const selection = NodeSelection.create(tr.doc, pos);
751
- view && view.focus();
752
- if (dispatch) {
751
+ if (dispatch && view) {
753
752
  dispatch(tr.setSelection(selection).scrollIntoView());
753
+ view.focus();
754
754
  }
755
755
  return true;
756
756
  };
@@ -1,13 +1,17 @@
1
1
  import { CloseButton, ModalCardBody, ModalContainer, ModalHeader, ModalTitle, StyledModal, } from '@manuscripts/style-guide';
2
2
  import React, { useRef, useState } from 'react';
3
+ import { schema } from '@manuscripts/transform';
4
+ import ReactSubView from '../../views/ReactSubView';
5
+ import { getEditorProps } from '../../plugins/editor-props';
3
6
  import { AwardForm } from './AwardForm';
7
+ import { insertAward } from '../../commands';
4
8
  const normalizeData = (award) => ({
5
9
  id: award.id || '',
6
10
  source: award.source || '',
7
11
  code: award.code || '',
8
12
  recipient: award.recipient || '',
9
13
  });
10
- export const AwardModal = ({ initialData, onSaveAward, onCancelAward, }) => {
14
+ export const AwardModal = ({ initialData, onSaveAward, }) => {
11
15
  const [isOpen, setOpen] = useState(true);
12
16
  const valuesRef = useRef(undefined);
13
17
  const handleSave = () => {
@@ -17,18 +21,27 @@ export const AwardModal = ({ initialData, onSaveAward, onCancelAward, }) => {
17
21
  handleClose();
18
22
  }
19
23
  };
20
- const handleCancel = () => {
21
- onCancelAward && onCancelAward();
22
- handleClose();
23
- };
24
24
  const handleClose = () => setOpen(false);
25
25
  const handleChange = (values) => (valuesRef.current = values);
26
26
  const normalizedValues = React.useMemo(() => normalizeData(initialData), [initialData]);
27
- return (React.createElement(StyledModal, { isOpen: isOpen, onRequestClose: handleCancel, shouldCloseOnOverlayClick: true },
27
+ return (React.createElement(StyledModal, { isOpen: isOpen, onRequestClose: handleClose, shouldCloseOnOverlayClick: true },
28
28
  React.createElement(ModalContainer, { "data-cy": "award-modal" },
29
29
  React.createElement(ModalHeader, null,
30
- React.createElement(CloseButton, { onClick: handleCancel, "data-cy": "modal-close-button" })),
30
+ React.createElement(CloseButton, { onClick: handleClose, "data-cy": "modal-close-button" })),
31
31
  React.createElement(ModalCardBody, { width: 480 },
32
32
  React.createElement(ModalTitle, null, "Add Funder information"),
33
- React.createElement(AwardForm, { values: normalizedValues, onSave: handleSave, onCancel: handleCancel, onChange: handleChange })))));
33
+ React.createElement(AwardForm, { values: normalizedValues, onSave: handleSave, onCancel: handleClose, onChange: handleChange })))));
34
+ };
35
+ export const openInsertAwardModal = (view) => {
36
+ if (!view) {
37
+ return;
38
+ }
39
+ const { state, dispatch } = view;
40
+ const props = getEditorProps(state);
41
+ const onSaveAward = (attrs) => {
42
+ insertAward(attrs)(state, dispatch, view);
43
+ };
44
+ const initialData = schema.nodes.award.create().attrs;
45
+ const dialog = ReactSubView(props, AwardModal, { initialData, onSaveAward }, state.doc, () => 0, view);
46
+ document.body.appendChild(dialog);
34
47
  };
package/dist/es/menus.js CHANGED
@@ -24,6 +24,7 @@ import { deleteClosestParentElement, findClosestParentElementNodeName, } from '.
24
24
  import { templateAllows } from './lib/template';
25
25
  import { isEditAllowed } from './lib/utils';
26
26
  import { getEditorProps } from './plugins/editor-props';
27
+ import { openInsertAwardModal } from './components/awards/AwardModal';
27
28
  export const getEditorMenus = (editor) => {
28
29
  const { isCommandValid, state, view } = editor;
29
30
  const doCommand = (command) => () => editor.doCommand(command);
@@ -559,8 +560,8 @@ export const getEditorMenus = (editor) => {
559
560
  {
560
561
  id: 'insert-awards',
561
562
  label: 'Funder Information',
562
- isEnabled: isCommandValid(insertAward),
563
- run: doCommand(insertAward),
563
+ isEnabled: isEditAllowed(state) && isCommandValid(insertAward()),
564
+ run: () => openInsertAwardModal(view),
564
565
  isHidden: !templateAllows(state, schema.nodes.awards),
565
566
  },
566
567
  {
@@ -1,2 +1,2 @@
1
- export const VERSION = '3.10.8';
1
+ export const VERSION = '3.10.9';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -25,7 +25,6 @@ import ReactSubView from './ReactSubView';
25
25
  export class AwardView extends BlockView {
26
26
  constructor() {
27
27
  super(...arguments);
28
- this.newAward = false;
29
28
  this.ignoreMutation = () => true;
30
29
  this.stopEvent = () => true;
31
30
  this.createAwardFragment = (className, title, content) => {
@@ -83,7 +82,6 @@ export class AwardView extends BlockView {
83
82
  const componentProps = {
84
83
  initialData: award?.attrs || {},
85
84
  onSaveAward: this.handleSaveAward,
86
- onCancelAward: this.handleCancelAward,
87
85
  };
88
86
  this.popperContainer = ReactSubView(this.props, AwardModal, componentProps, this.node, this.getPos, this.view, ['award-editor']);
89
87
  this.props.popper.show(this.dom, this.popperContainer, 'auto', false);
@@ -99,11 +97,6 @@ export class AwardView extends BlockView {
99
97
  this.handleSaveAward = (award) => {
100
98
  updateNodeAttrs(this.view, schema.nodes.award, award);
101
99
  };
102
- this.handleCancelAward = () => {
103
- if (this.newAward) {
104
- this.handleDeleteAward();
105
- }
106
- };
107
100
  this.handleDeleteAward = () => {
108
101
  const award = this.node;
109
102
  const pos = this.getPos();
@@ -133,12 +126,5 @@ export class AwardView extends BlockView {
133
126
  this.contentDOM.appendChild(fragment);
134
127
  this.updateClasses();
135
128
  }
136
- selectNode() {
137
- super.selectNode();
138
- if (!this.node.attrs.source) {
139
- this.newAward = true;
140
- this.showAwardModal(this.node);
141
- }
142
- }
143
129
  }
144
130
  export default createNodeView(AwardView);
@@ -19,6 +19,7 @@ import { EditorState, Selection, Transaction } from 'prosemirror-state';
19
19
  import { EditorView } from 'prosemirror-view';
20
20
  import { FileAttachment } from './lib/files';
21
21
  import { EditorAction } from './types';
22
+ import { AwardAttrs } from './views/award';
22
23
  export type Dispatch = (tr: ManuscriptTransaction) => void;
23
24
  export declare const addToStart: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
24
25
  export declare const markActive: (type: ManuscriptMarkType) => (state: ManuscriptEditorState) => boolean;
@@ -56,7 +57,7 @@ export declare const insertBackmatterSection: (category: SectionCategory) => (st
56
57
  export declare const insertGraphicalAbstract: (category?: SectionCategory) => (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
57
58
  export declare const insertContributors: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
58
59
  export declare const insertAffiliation: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
59
- export declare const insertAward: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
60
+ export declare const insertAward: (attrs?: AwardAttrs) => (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
60
61
  export declare const insertKeywords: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
61
62
  export declare const insertList: (type: ManuscriptNodeType, style?: string) => (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
62
63
  export declare const insertBibliographySection: () => boolean;
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { EditorView } from 'prosemirror-view';
2
3
  import { AwardAttrs } from '../../views/award';
3
4
  export interface AwardFormData {
4
5
  id: string;
@@ -9,6 +10,6 @@ export interface AwardFormData {
9
10
  export interface AwardModalProps {
10
11
  initialData: AwardAttrs;
11
12
  onSaveAward: (data: AwardFormData) => void;
12
- onCancelAward?: () => void;
13
13
  }
14
14
  export declare const AwardModal: React.FC<AwardModalProps>;
15
+ export declare const openInsertAwardModal: (view?: EditorView) => void;
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "3.10.8";
1
+ export declare const VERSION = "3.10.9";
2
2
  export declare const MATHJAX_VERSION = "3.2.2";
@@ -21,18 +21,15 @@ export declare class AwardView extends BlockView<Trackable<AwardNode>> {
21
21
  protected popperContainer: HTMLDivElement;
22
22
  private dialog;
23
23
  contextMenu: HTMLElement;
24
- newAward: boolean;
25
24
  ignoreMutation: () => boolean;
26
25
  stopEvent: () => boolean;
27
26
  updateContents(): void;
28
- selectNode(): void;
29
27
  private createAwardFragment;
30
28
  awardContextMenu: () => HTMLElement | undefined;
31
29
  actionGutterButtons: () => HTMLElement[];
32
30
  showAwardModal: (award: AwardNode) => void;
33
31
  showDeleteAwardDialog: () => void;
34
32
  handleSaveAward: (award: AwardAttrs) => void;
35
- handleCancelAward: () => void;
36
33
  handleDeleteAward: () => void;
37
34
  }
38
35
  declare const _default: (props: import("../configs/ManuscriptsEditor").EditorProps, dispatch?: import("..").Dispatch) => import("../types").NodeViewCreator<AwardView>;
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.10.8",
4
+ "version": "3.10.9",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",