@manuscripts/body-editor 2.6.40 → 2.6.41-LEAN-4077.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.
Files changed (41) hide show
  1. package/dist/cjs/commands.js +16 -1
  2. package/dist/cjs/components/{authors/ChangeHandlingForm.js → ChangeHandlingForm.js} +12 -2
  3. package/dist/cjs/components/authors/AffiliationForm.js +1 -1
  4. package/dist/cjs/components/authors/AuthorDetailsForm.js +1 -1
  5. package/dist/cjs/components/awards/AwardForm.js +145 -0
  6. package/dist/cjs/components/awards/AwardModal.js +80 -0
  7. package/dist/cjs/components/awards/DeleteAwardDiaolog.js +45 -0
  8. package/dist/cjs/components/references/ReferenceForm.js +3 -16
  9. package/dist/cjs/icons.js +2 -1
  10. package/dist/cjs/lib/doc.js +29 -1
  11. package/dist/cjs/menus.js +6 -0
  12. package/dist/cjs/versions.js +1 -1
  13. package/dist/cjs/views/award.js +108 -16
  14. package/dist/cjs/views/awards.js +13 -12
  15. package/dist/es/commands.js +14 -1
  16. package/dist/es/components/{authors/ChangeHandlingForm.js → ChangeHandlingForm.js} +8 -1
  17. package/dist/es/components/authors/AffiliationForm.js +1 -1
  18. package/dist/es/components/authors/AuthorDetailsForm.js +1 -1
  19. package/dist/es/components/awards/AwardForm.js +115 -0
  20. package/dist/es/components/awards/AwardModal.js +50 -0
  21. package/dist/es/components/awards/DeleteAwardDiaolog.js +18 -0
  22. package/dist/es/components/references/ReferenceForm.js +3 -16
  23. package/dist/es/icons.js +2 -1
  24. package/dist/es/lib/doc.js +27 -0
  25. package/dist/es/menus.js +7 -1
  26. package/dist/es/versions.js +1 -1
  27. package/dist/es/views/award.js +108 -16
  28. package/dist/es/views/awards.js +13 -9
  29. package/dist/types/commands.d.ts +1 -0
  30. package/dist/types/components/{authors/ChangeHandlingForm.d.ts → ChangeHandlingForm.d.ts} +1 -0
  31. package/dist/types/components/awards/AwardForm.d.ts +24 -0
  32. package/dist/types/components/awards/AwardModal.d.ts +14 -0
  33. package/dist/types/components/awards/DeleteAwardDiaolog.d.ts +5 -0
  34. package/dist/types/components/references/ReferenceForm.d.ts +0 -1
  35. package/dist/types/icons.d.ts +1 -0
  36. package/dist/types/lib/doc.d.ts +1 -0
  37. package/dist/types/versions.d.ts +1 -1
  38. package/dist/types/views/award.d.ts +12 -3
  39. package/dist/types/views/awards.d.ts +5 -3
  40. package/package.json +3 -3
  41. package/styles/AdvancedEditor.css +25 -27
@@ -14,39 +14,40 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
17
  Object.defineProperty(exports, "__esModule", { value: true });
21
18
  exports.AwardsView = void 0;
22
19
  const utils_1 = require("../lib/utils");
23
- const block_view_1 = __importDefault(require("./block_view"));
20
+ const base_node_view_1 = require("./base_node_view");
24
21
  const creators_1 = require("./creators");
25
- class AwardsView extends block_view_1.default {
22
+ class AwardsView extends base_node_view_1.BaseNodeView {
26
23
  constructor() {
27
24
  super(...arguments);
28
25
  this.elementType = 'div';
29
26
  this.createElement = () => {
30
- this.wrapper = document.createElement(this.elementType);
31
- this.wrapper.classList.add('block');
32
27
  this.contentDOM = document.createElement(this.elementType);
33
28
  this.contentDOM.className = 'block';
34
- this.wrapper.appendChild(this.contentDOM);
35
- this.dom.appendChild(this.wrapper);
36
29
  };
37
30
  }
31
+ initialise() {
32
+ this.createDOM();
33
+ this.createElement();
34
+ this.updateContents();
35
+ }
36
+ createDOM() {
37
+ this.dom = document.createElement(this.elementType);
38
+ this.dom.classList.add(`block-${this.node.type.name}`);
39
+ }
38
40
  updateContents() {
39
41
  super.updateContents();
40
42
  if (!this.contentDOM) {
41
43
  return;
42
44
  }
45
+ this.dom.innerHTML = '';
43
46
  this.dom.setAttribute('contenteditable', 'false');
44
47
  this.contentDOM.setAttribute('contenteditable', 'false');
45
48
  if (this.node.content.size !== 0) {
46
- this.wrapper.innerHTML = '';
47
- this.wrapper.setAttribute('contenteditable', 'false');
48
49
  const header = (0, utils_1.createHeader)(this.node.type.name, 'Funder Information');
49
- this.wrapper.append(header, this.contentDOM);
50
+ this.dom.append(header, this.contentDOM);
50
51
  }
51
52
  }
52
53
  }
@@ -23,7 +23,7 @@ import { addColSpan, addColumnAfter, addColumnBefore, addRow, CellSelection, sel
23
23
  import { findWrapping, liftTarget, ReplaceAroundStep, ReplaceStep, } from 'prosemirror-transform';
24
24
  import { findChildrenByType, findParentNodeOfType, findParentNodeOfTypeClosestToPos, flatten, hasParentNodeOfType, } from 'prosemirror-utils';
25
25
  import { getCommentKey, getCommentRange } from './lib/comments';
26
- import { findBackmatter, findBibliographySection, findBody, insertFootnotesSection, insertSupplementsNode, } from './lib/doc';
26
+ import { findBackmatter, findBibliographySection, findBody, insertAwardsNode, insertFootnotesSection, insertSupplementsNode, } from './lib/doc';
27
27
  import { createFootnote, findFootnotesContainerNode, getFootnotesElementState, } from './lib/footnotes';
28
28
  import { findWordBoundaries, isNodeOfType, nearestAncestor, } from './lib/helpers';
29
29
  import { isDeleted } from './lib/track-changes-utils';
@@ -620,6 +620,19 @@ export const insertAffiliation = (state, dispatch, view) => {
620
620
  }
621
621
  return true;
622
622
  };
623
+ export const insertAward = (state, dispatch, view) => {
624
+ const award = schema.nodes.award.create();
625
+ const tr = state.tr;
626
+ const awards = insertAwardsNode(tr);
627
+ const pos = awards.pos + awards.node.nodeSize - 1;
628
+ tr.insert(pos, award);
629
+ const selection = NodeSelection.create(tr.doc, pos);
630
+ view && view.focus();
631
+ if (dispatch) {
632
+ dispatch(tr.setSelection(selection).scrollIntoView());
633
+ }
634
+ return true;
635
+ };
623
636
  export const insertKeywords = (state, dispatch, view) => {
624
637
  if (getChildOfType(state.doc, schema.nodes.keywords, true)) {
625
638
  return false;
@@ -1,10 +1,17 @@
1
1
  import { Form, useFormikContext } from 'formik';
2
2
  import React, { useEffect } from 'react';
3
+ import styled from 'styled-components';
3
4
  export const ChangeHandlingForm = (props) => {
4
5
  const { values } = useFormikContext();
5
6
  useEffect(() => {
6
7
  var _a;
7
8
  (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, values);
8
9
  }, [props.onChange, values]);
9
- return React.createElement(Form, null, props.children);
10
+ return React.createElement(FlexForm, null, props.children);
10
11
  };
12
+ export const FlexForm = styled(Form) `
13
+ height: 100%;
14
+ display: flex;
15
+ flex-direction: column;
16
+ overflow: hidden;
17
+ `;
@@ -2,7 +2,7 @@ import { TextField } from '@manuscripts/style-guide';
2
2
  import { Field, Formik } from 'formik';
3
3
  import React from 'react';
4
4
  import styled from 'styled-components';
5
- import { ChangeHandlingForm } from './ChangeHandlingForm';
5
+ import { ChangeHandlingForm } from '../ChangeHandlingForm';
6
6
  const Row = styled.div `
7
7
  display: flex;
8
8
  border-top: 1px solid ${(props) => props.theme.colors.border.field.default};
@@ -17,7 +17,7 @@ import { CheckboxField, CheckboxLabel, TextField, TextFieldGroupContainer, TextF
17
17
  import { Field, Formik } from 'formik';
18
18
  import React, { useRef } from 'react';
19
19
  import styled from 'styled-components';
20
- import { ChangeHandlingForm } from './ChangeHandlingForm';
20
+ import { ChangeHandlingForm } from '../ChangeHandlingForm';
21
21
  export const LabelText = styled.div `
22
22
  font: ${(props) => props.theme.font.weight.normal}
23
23
  ${(props) => props.theme.font.size.normal} / 1
@@ -0,0 +1,115 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ import { MultiValueInput, PrimaryButton, SecondaryButton, SelectField, TextField, } from '@manuscripts/style-guide';
26
+ import { Field, Formik } from 'formik';
27
+ import React, { useEffect, useRef, useState } from 'react';
28
+ import styled from 'styled-components';
29
+ import { ChangeHandlingForm } from '../ChangeHandlingForm';
30
+ export const AwardForm = ({ values, onSave, onCancel, onChange, }) => {
31
+ const [funders, setFunders] = useState([]);
32
+ const formRef = useRef(null);
33
+ const primaryButtonText = values.id ? 'Save funder' : 'Add funder';
34
+ useEffect(() => {
35
+ const fetchFunders = () => __awaiter(void 0, void 0, void 0, function* () {
36
+ try {
37
+ const response = yield fetch('https://api.crossref.org/funders');
38
+ if (!response.ok) {
39
+ throw new Error(`HTTP error! status: ${response.status}`);
40
+ }
41
+ const data = yield response.json();
42
+ const funderOptions = data.message.items.map((funder) => ({
43
+ value: funder.name,
44
+ label: funder.name,
45
+ }));
46
+ funderOptions.sort((a, b) => a.label.localeCompare(b.label));
47
+ sessionStorage.setItem('funders', JSON.stringify(funderOptions));
48
+ setFunders(funderOptions);
49
+ }
50
+ catch (error) {
51
+ console.error('Error fetching funders:', error);
52
+ }
53
+ });
54
+ const storedFunders = sessionStorage.getItem('funders');
55
+ if (storedFunders) {
56
+ setFunders(JSON.parse(storedFunders));
57
+ }
58
+ else {
59
+ fetchFunders();
60
+ }
61
+ }, []);
62
+ const handleCancel = () => {
63
+ var _a;
64
+ (_a = formRef.current) === null || _a === void 0 ? void 0 : _a.resetForm();
65
+ onCancel();
66
+ };
67
+ const validate = (values) => {
68
+ const errors = {};
69
+ if (!values.source) {
70
+ errors.source = 'Funder name is required';
71
+ }
72
+ return errors;
73
+ };
74
+ return (React.createElement(Formik, { initialValues: values, onSubmit: (values, { setSubmitting }) => {
75
+ onSave(values);
76
+ setSubmitting(false);
77
+ }, enableReinitialize: true, validate: validate, validateOnChange: false, innerRef: formRef }, (formik) => {
78
+ return (React.createElement(ChangeHandlingForm, { onChange: onChange },
79
+ React.createElement(Field, { type: "hidden", name: "id" }),
80
+ React.createElement(LabelContainer, null,
81
+ React.createElement(Label, { htmlFor: 'source' }, "Funder name")),
82
+ React.createElement(Field, { name: "source", component: SelectField, options: funders, value: funders.find((funder) => funder.value === formik.values.source) || null }),
83
+ formik.errors.source && formik.touched.source && (React.createElement("div", { style: { color: 'red' } }, formik.errors.source)),
84
+ React.createElement(LabelContainer, null,
85
+ React.createElement(Label, { htmlFor: 'code' }, "Grant number")),
86
+ React.createElement(MultiValueInput, { inputType: "text", initialValues: values.code ? values.code.split(';') : [], onChange: (newValues) => {
87
+ formik.setFieldValue('code', newValues.join(';'));
88
+ } }),
89
+ React.createElement(LabelContainer, null,
90
+ React.createElement(Label, { htmlFor: 'recipient' }, "Recipient name")),
91
+ React.createElement(Field, { name: "recipient" }, (props) => (React.createElement(TextField, Object.assign({ id: "recipient", placeholder: "Enter full name " }, props.field)))),
92
+ React.createElement(ButtonContainer, null,
93
+ React.createElement(SecondaryButton, { onClick: handleCancel }, "Cancel"),
94
+ React.createElement(PrimaryButton, { type: "submit", disabled: !formik.dirty || formik.isSubmitting }, primaryButtonText))));
95
+ }));
96
+ };
97
+ const LabelContainer = styled.div `
98
+ display: flex;
99
+ justify-content: space-between;
100
+ align-items: center;
101
+ margin-top: ${(props) => 4 * props.theme.grid.unit}px;
102
+ margin-bottom: ${(props) => props.theme.grid.unit}px;
103
+ `;
104
+ const Label = styled.label `
105
+ font-family: ${(props) => props.theme.font.family.sans};
106
+ font-size: ${(props) => props.theme.font.size.large};
107
+ display: block;
108
+ color: ${(props) => props.theme.colors.text.secondary};
109
+ `;
110
+ const ButtonContainer = styled.div `
111
+ display: flex;
112
+ justify-content: flex-end;
113
+ margin-top: 16px;
114
+ gap: 8px;
115
+ `;
@@ -0,0 +1,50 @@
1
+ import { CloseButton, ModalContainer, ModalHeader, StyledModal, } from '@manuscripts/style-guide';
2
+ import React, { useRef, useState } from 'react';
3
+ import styled from 'styled-components';
4
+ import { AwardForm } from './AwardForm';
5
+ const ModalBody = styled.div `
6
+ box-sizing: border-box;
7
+ padding: ${(props) => 6 * props.theme.grid.unit}px;
8
+ background-color: ${(props) => props.theme.colors.background.primary};
9
+ width: 480px;
10
+ max-width: 60vw;
11
+ max-height: 80vh;
12
+ `;
13
+ const ModalTitle = styled.h2 `
14
+ font-family: ${(props) => props.theme.font.family.sans};
15
+ font-size: ${(props) => props.theme.font.size.medium};
16
+ font-weight: ${(props) => props.theme.font.weight.bold};
17
+ color: ${(props) => props.theme.colors.text.primary};
18
+ margin: 0;
19
+ `;
20
+ const normalizeData = (award) => ({
21
+ id: award.id || '',
22
+ source: award.source || '',
23
+ code: award.code || '',
24
+ recipient: award.recipient || '',
25
+ });
26
+ export const AwardModal = ({ initialData, onSaveAward, onCancelAward, }) => {
27
+ const [isOpen, setOpen] = useState(true);
28
+ const valuesRef = useRef();
29
+ const handleSave = () => {
30
+ const updatedValues = valuesRef.current;
31
+ if (updatedValues) {
32
+ onSaveAward(updatedValues);
33
+ handleClose();
34
+ }
35
+ };
36
+ const handleCancel = () => {
37
+ onCancelAward && onCancelAward();
38
+ handleClose();
39
+ };
40
+ const handleClose = () => setOpen(false);
41
+ const handleChange = (values) => (valuesRef.current = values);
42
+ const normalizedValues = React.useMemo(() => normalizeData(initialData), [initialData]);
43
+ return (React.createElement(StyledModal, { isOpen: isOpen, onRequestClose: () => handleClose(), shouldCloseOnOverlayClick: true },
44
+ React.createElement(ModalContainer, { "data-cy": "award-modal" },
45
+ React.createElement(ModalHeader, null,
46
+ React.createElement(CloseButton, { onClick: () => handleClose(), "data-cy": "modal-close-button" })),
47
+ React.createElement(ModalBody, null,
48
+ React.createElement(ModalTitle, null, "Add Funder information"),
49
+ React.createElement(AwardForm, { values: normalizedValues, onSave: handleSave, onCancel: handleCancel, onChange: handleChange })))));
50
+ };
@@ -0,0 +1,18 @@
1
+ import { Category, Dialog } from '@manuscripts/style-guide';
2
+ import React, { useState } from 'react';
3
+ export const DeleteAwardDialog = ({ handleDelete, }) => {
4
+ const [isOpen, setOpen] = useState(true);
5
+ return (React.createElement(Dialog, { isOpen: isOpen, actions: {
6
+ primary: {
7
+ action: () => {
8
+ setOpen(false);
9
+ handleDelete();
10
+ },
11
+ title: 'Delete',
12
+ },
13
+ secondary: {
14
+ action: () => setOpen(false),
15
+ title: 'Cancel',
16
+ },
17
+ }, category: Category.warning, header: 'Delete Funder Info', message: `Do you want to continue?` }));
18
+ };
@@ -15,9 +15,10 @@
15
15
  */
16
16
  import { buildBibliographicDate, buildBibliographicName, } from '@manuscripts/json-schema';
17
17
  import { AddAuthorIcon, ArrowDownIcon, ButtonGroup, Category, DeleteIcon, Dialog, IconButton, LinkIcon, PrimaryButton, SecondaryButton, SelectField, TextArea, TextField, Tooltip, } from '@manuscripts/style-guide';
18
- import { Field, FieldArray, Form, Formik, useFormikContext, } from 'formik';
19
- import React, { useEffect, useRef, useState, } from 'react';
18
+ import { Field, FieldArray, Formik } from 'formik';
19
+ import React, { useEffect, useRef, useState } from 'react';
20
20
  import styled from 'styled-components';
21
+ import { ChangeHandlingForm } from '../ChangeHandlingForm';
21
22
  export const LabelContainer = styled.div `
22
23
  display: flex;
23
24
  justify-content: space-between;
@@ -113,12 +114,6 @@ export const ReferenceTextArea = styled(TextArea) `
113
114
  height: ${(props) => props.theme.grid.unit * 20}px;
114
115
  resize: none;
115
116
  `;
116
- export const FlexForm = styled(Form) `
117
- height: 100%;
118
- display: flex;
119
- flex-direction: column;
120
- overflow: hidden;
121
- `;
122
117
  export const FormFields = styled.div `
123
118
  flex: 1;
124
119
  overflow-y: auto;
@@ -183,14 +178,6 @@ const bibliographyItemTypeOptions = bibliographyItemTypes.map((i) => ({
183
178
  label: i[1],
184
179
  value: i[0],
185
180
  }));
186
- const ChangeHandlingForm = (props) => {
187
- const { values } = useFormikContext();
188
- useEffect(() => {
189
- var _a;
190
- (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, values);
191
- }, [props.onChange, values]);
192
- return React.createElement(FlexForm, null, props.children);
193
- };
194
181
  export const ReferenceForm = ({ values, showDelete, onChange, onDelete, onCancel, onSave, actionsRef, }) => {
195
182
  const fieldsRef = useRef(null);
196
183
  useEffect(() => {
package/dist/es/icons.js CHANGED
@@ -1,8 +1,9 @@
1
- import { AlertIcon, DeleteIcon, ScrollIcon, SectionCategoryIcon, } from '@manuscripts/style-guide';
1
+ import { AlertIcon, DeleteIcon, EditIcon, ScrollIcon, SectionCategoryIcon, } from '@manuscripts/style-guide';
2
2
  import { createElement } from 'react';
3
3
  import { renderToStaticMarkup } from 'react-dom/server';
4
4
  const renderIcon = (c) => renderToStaticMarkup(createElement(c));
5
5
  export const alertIcon = renderIcon(AlertIcon);
6
6
  export const deleteIcon = renderIcon(DeleteIcon);
7
+ export const editIcon = renderToStaticMarkup(createElement(EditIcon));
7
8
  export const sectionCategoryIcon = renderIcon(SectionCategoryIcon);
8
9
  export const scrollIcon = renderToStaticMarkup(createElement(ScrollIcon));
@@ -1,5 +1,32 @@
1
1
  import { schema, } from '@manuscripts/transform';
2
2
  import { findChildren, findChildrenByType } from 'prosemirror-utils';
3
+ export const insertAwardsNode = (tr) => {
4
+ const doc = tr.doc;
5
+ const awards = findChildrenByType(doc, schema.nodes.awards)[0];
6
+ if (awards) {
7
+ return awards;
8
+ }
9
+ const positions = [];
10
+ const possibleNodesTypes = [
11
+ 'doi',
12
+ 'keywords',
13
+ 'supplements',
14
+ 'abstracts',
15
+ 'body',
16
+ ];
17
+ doc.descendants((node, pos) => {
18
+ if (possibleNodesTypes.includes(node.type.name)) {
19
+ positions.push(pos);
20
+ }
21
+ });
22
+ const pos = positions.length === 0 ? 0 : Math.min(...positions);
23
+ const node = schema.nodes.awards.createAndFill();
24
+ tr.insert(pos, node);
25
+ return {
26
+ node,
27
+ pos,
28
+ };
29
+ };
3
30
  export const insertSupplementsNode = (tr) => {
4
31
  const doc = tr.doc;
5
32
  const supplements = findChildrenByType(doc, schema.nodes.supplements)[0];
package/dist/es/menus.js CHANGED
@@ -16,7 +16,7 @@
16
16
  import { getGroupCateogries, schema, } from '@manuscripts/transform';
17
17
  import { toggleMark } from 'prosemirror-commands';
18
18
  import { redo, undo } from 'prosemirror-history';
19
- import { addInlineComment, blockActive, canInsert, insertAbstract, insertAffiliation, insertBackmatterSection, insertBlock, insertBoxElement, insertContributors, insertCrossReference, insertGraphicalAbstract, insertInlineCitation, insertInlineEquation, insertInlineFootnote, insertKeywords, insertLink, insertList, insertSection, markActive, } from './commands';
19
+ import { addInlineComment, blockActive, canInsert, insertAbstract, insertAffiliation, insertAward, insertBackmatterSection, insertBlock, insertBoxElement, insertContributors, insertCrossReference, insertGraphicalAbstract, insertInlineCitation, insertInlineEquation, insertInlineFootnote, insertKeywords, insertLink, insertList, insertSection, markActive, } from './commands';
20
20
  import { openInsertTableDialog } from './components/toolbar/InsertTableDialog';
21
21
  import { ListMenuItem } from './components/toolbar/ListMenuItem';
22
22
  import { deleteClosestParentElement, findClosestParentElementNodeName, } from './lib/hierarchy';
@@ -111,6 +111,12 @@ export const getEditorMenus = (editor) => {
111
111
  isEnabled: isCommandValid(insertAffiliation),
112
112
  run: doCommand(insertAffiliation),
113
113
  },
114
+ {
115
+ id: 'insert-awards',
116
+ label: 'Funder Information',
117
+ isEnabled: isCommandValid(insertAward),
118
+ run: doCommand(insertAward),
119
+ },
114
120
  {
115
121
  id: 'insert-keywords',
116
122
  label: 'Keywords',
@@ -1,2 +1,2 @@
1
- export const VERSION = '2.6.40';
1
+ export const VERSION = '2.6.41-LEAN-4077.0';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -13,39 +13,131 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { ContextMenu } from '@manuscripts/style-guide';
17
+ import { schema } from '@manuscripts/transform';
18
+ import { AwardModal } from '../components/awards/AwardModal';
19
+ import { DeleteAwardDialog, } from '../components/awards/DeleteAwardDiaolog';
20
+ import { isDeleted } from '../lib/track-changes-utils';
21
+ import { updateNodeAttrs } from '../lib/view';
16
22
  import BlockView from './block_view';
17
23
  import { createNodeView } from './creators';
24
+ import ReactSubView from './ReactSubView';
18
25
  export class AwardView extends BlockView {
19
26
  constructor() {
20
27
  super(...arguments);
21
- this.createAwardElement = (className, textContent) => {
22
- const element = document.createElement('div');
23
- element.classList.add(className);
24
- element.textContent = textContent;
25
- return element;
28
+ this.createAwardFragment = (className, title, content) => {
29
+ const awardFragment = document.createElement('div');
30
+ awardFragment.classList.add(className);
31
+ if (title) {
32
+ const titleElement = document.createElement('span');
33
+ titleElement.classList.add('title');
34
+ titleElement.textContent = title;
35
+ awardFragment.appendChild(titleElement);
36
+ }
37
+ if (content) {
38
+ const contentElement = document.createElement('span');
39
+ contentElement.classList.add('content');
40
+ contentElement.textContent = content;
41
+ awardFragment.appendChild(contentElement);
42
+ }
43
+ return awardFragment;
44
+ };
45
+ this.handleClick = () => {
46
+ if (isDeleted(this.node) || !this.props.getCapabilities().editArticle) {
47
+ return;
48
+ }
49
+ this.showContextMenu();
50
+ };
51
+ this.showContextMenu = () => {
52
+ this.props.popper.destroy();
53
+ if (!this.contentDOM) {
54
+ return;
55
+ }
56
+ const componentProps = {
57
+ actions: [
58
+ {
59
+ label: 'Edit',
60
+ action: () => {
61
+ this.props.popper.destroy();
62
+ this.showAwardModal(this.node);
63
+ },
64
+ icon: 'Edit',
65
+ },
66
+ {
67
+ label: 'Delete',
68
+ action: () => {
69
+ this.props.popper.destroy();
70
+ this.showDeleteAwardDialog();
71
+ },
72
+ icon: 'Delete',
73
+ },
74
+ ],
75
+ };
76
+ this.props.popper.show(this.contentDOM, ReactSubView(this.props, ContextMenu, componentProps, this.node, this.getPos, this.view, 'context-menu'), 'right-start', false);
77
+ };
78
+ this.showAwardModal = (award) => {
79
+ var _a, _b;
80
+ (_a = this.dialog) === null || _a === void 0 ? void 0 : _a.remove();
81
+ (_b = this.popperContainer) === null || _b === void 0 ? void 0 : _b.remove();
82
+ const componentProps = {
83
+ initialData: (award === null || award === void 0 ? void 0 : award.attrs) || {},
84
+ onSaveAward: this.handleSaveAward,
85
+ onCancelAward: this.handleCancelAward,
86
+ };
87
+ this.popperContainer = ReactSubView(this.props, AwardModal, componentProps, this.node, this.getPos, this.view, 'award-editor');
88
+ this.props.popper.show(this.dom, this.popperContainer, 'auto', false);
89
+ };
90
+ this.handleSaveAward = (award) => {
91
+ updateNodeAttrs(this.view, schema.nodes.award, award);
92
+ };
93
+ this.handleCancelAward = () => {
94
+ };
95
+ this.showDeleteAwardDialog = () => {
96
+ var _a;
97
+ (_a = this.dialog) === null || _a === void 0 ? void 0 : _a.remove();
98
+ const award = this.node;
99
+ const pos = this.getPos();
100
+ const handleDelete = () => {
101
+ if (award) {
102
+ const tr = this.view.state.tr;
103
+ const from = pos;
104
+ const to = pos + award.nodeSize;
105
+ this.view.dispatch(tr.delete(from, to));
106
+ }
107
+ };
108
+ const componentProps = {
109
+ handleDelete: handleDelete,
110
+ };
111
+ this.popperContainer = ReactSubView(this.props, DeleteAwardDialog, componentProps, this.node, this.getPos, this.view, 'award-editor');
112
+ this.props.popper.show(this.dom, this.popperContainer, 'auto', false);
26
113
  };
27
- }
28
- initialise() {
29
- this.createDOM();
30
- this.contentDOM = this.dom;
31
- this.updateContents();
32
114
  }
33
115
  updateContents() {
116
+ super.updateContents();
34
117
  if (!this.contentDOM) {
35
118
  return;
36
119
  }
37
- this.contentDOM.innerHTML = '';
38
- this.contentDOM.classList.remove('block-container');
39
- const notAvailable = 'N/A';
40
120
  const { recipient, code, source } = this.node.attrs;
41
121
  if (!source) {
42
122
  return;
43
123
  }
124
+ this.contentDOM.innerHTML = '';
125
+ const notAvailable = 'N/A';
44
126
  const fragment = document.createDocumentFragment();
45
- fragment.appendChild(this.createAwardElement('award-source', source));
46
- fragment.appendChild(this.createAwardElement('award-code', `Grant Number(s): ${code ? code.split(';').join(', ') : notAvailable}`));
47
- fragment.appendChild(this.createAwardElement('award-recipient', `Recipient: ${recipient ? recipient : notAvailable}`));
127
+ fragment.appendChild(this.createAwardFragment('award-source', '', source));
128
+ fragment.appendChild(this.createAwardFragment('award-code', 'Grant Number(s): ', code ? code.split(';').join(', ') : notAvailable));
129
+ fragment.appendChild(this.createAwardFragment('award-recipient', 'Recipient: ', recipient ? recipient : notAvailable));
130
+ if (this.props.getCapabilities().editArticle) {
131
+ this.dom.addEventListener('mouseup', this.handleClick);
132
+ }
48
133
  this.contentDOM.appendChild(fragment);
134
+ this.updateClasses();
135
+ }
136
+ selectNode() {
137
+ super.selectNode();
138
+ if (!this.node.attrs.source) {
139
+ this.showAwardModal(this.node);
140
+ }
49
141
  }
50
142
  }
51
143
  export default createNodeView(AwardView);
@@ -14,33 +14,37 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { createHeader } from '../lib/utils';
17
- import BlockView from './block_view';
17
+ import { BaseNodeView } from './base_node_view';
18
18
  import { createNodeView } from './creators';
19
- export class AwardsView extends BlockView {
19
+ export class AwardsView extends BaseNodeView {
20
20
  constructor() {
21
21
  super(...arguments);
22
22
  this.elementType = 'div';
23
23
  this.createElement = () => {
24
- this.wrapper = document.createElement(this.elementType);
25
- this.wrapper.classList.add('block');
26
24
  this.contentDOM = document.createElement(this.elementType);
27
25
  this.contentDOM.className = 'block';
28
- this.wrapper.appendChild(this.contentDOM);
29
- this.dom.appendChild(this.wrapper);
30
26
  };
31
27
  }
28
+ initialise() {
29
+ this.createDOM();
30
+ this.createElement();
31
+ this.updateContents();
32
+ }
33
+ createDOM() {
34
+ this.dom = document.createElement(this.elementType);
35
+ this.dom.classList.add(`block-${this.node.type.name}`);
36
+ }
32
37
  updateContents() {
33
38
  super.updateContents();
34
39
  if (!this.contentDOM) {
35
40
  return;
36
41
  }
42
+ this.dom.innerHTML = '';
37
43
  this.dom.setAttribute('contenteditable', 'false');
38
44
  this.contentDOM.setAttribute('contenteditable', 'false');
39
45
  if (this.node.content.size !== 0) {
40
- this.wrapper.innerHTML = '';
41
- this.wrapper.setAttribute('contenteditable', 'false');
42
46
  const header = createHeader(this.node.type.name, 'Funder Information');
43
- this.wrapper.append(header, this.contentDOM);
47
+ this.dom.append(header, this.contentDOM);
44
48
  }
45
49
  }
46
50
  }
@@ -54,6 +54,7 @@ export declare const insertBackmatterSection: (category: SectionCategory) => (st
54
54
  export declare const insertAbstract: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
55
55
  export declare const insertContributors: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
56
56
  export declare const insertAffiliation: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
57
+ export declare const insertAward: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
57
58
  export declare const insertKeywords: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
58
59
  export declare const insertList: (type: ManuscriptNodeType, style?: string) => (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView) => boolean;
59
60
  export declare const insertBibliographySection: () => boolean;
@@ -3,3 +3,4 @@ export interface ChangeHandlingFormProps<Values> {
3
3
  onChange: (values: Values) => void;
4
4
  }
5
5
  export declare const ChangeHandlingForm: <Values>(props: React.PropsWithChildren<ChangeHandlingFormProps<Values>>) => React.JSX.Element;
6
+ export declare const FlexForm: import("styled-components").StyledComponent<React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "ref"> & React.RefAttributes<HTMLFormElement>>, any, {}, never>;
@@ -0,0 +1,24 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import React from 'react';
17
+ import { AwardAttrs } from '../../views/award';
18
+ export interface AwardFormProps {
19
+ values: AwardAttrs;
20
+ onSave: (values: AwardAttrs) => void;
21
+ onCancel: () => void;
22
+ onChange: (values: AwardAttrs) => void;
23
+ }
24
+ export declare const AwardForm: ({ values, onSave, onCancel, onChange, }: AwardFormProps) => React.JSX.Element;