@manuscripts/body-editor 3.19.0 → 3.19.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.
- package/dist/cjs/components/cross-ref-check-modal/CrossRefWarningModal.js +202 -52
- package/dist/cjs/components/cross-ref-check-modal/openModal.js +8 -2
- package/dist/cjs/components/references/ReferenceForm/ReferenceForm.js +22 -40
- package/dist/cjs/components/references/ReferenceForm/styled-components.js +1 -13
- package/dist/cjs/components/references/ReferencesEditor.js +26 -1
- package/dist/cjs/components/references/ReferencesModal.js +71 -7
- package/dist/cjs/lib/utils.js +12 -1
- package/dist/cjs/menus.js +12 -0
- package/dist/cjs/plugins/cross-references.js +37 -14
- package/dist/cjs/versions.js +1 -1
- package/dist/cjs/views/ReactSubView.js +1 -0
- package/dist/cjs/views/cross_reference.js +13 -2
- package/dist/cjs/views/cross_reference_editable.js +1 -4
- package/dist/es/components/cross-ref-check-modal/CrossRefWarningModal.js +202 -52
- package/dist/es/components/cross-ref-check-modal/openModal.js +9 -3
- package/dist/es/components/references/ReferenceForm/ReferenceForm.js +21 -40
- package/dist/es/components/references/ReferenceForm/styled-components.js +0 -12
- package/dist/es/components/references/ReferencesEditor.js +21 -0
- package/dist/es/components/references/ReferencesModal.js +73 -9
- package/dist/es/lib/utils.js +11 -1
- package/dist/es/menus.js +12 -0
- package/dist/es/plugins/cross-references.js +37 -15
- package/dist/es/versions.js +1 -1
- package/dist/es/views/ReactSubView.js +1 -0
- package/dist/es/views/cross_reference.js +13 -2
- package/dist/es/views/cross_reference_editable.js +1 -4
- package/dist/types/components/authors-affiliations/AuthorsAndAffiliationsModals.d.ts +1 -1
- package/dist/types/components/cross-ref-check-modal/CrossRefWarningModal.d.ts +4 -2
- package/dist/types/components/cross-ref-check-modal/openModal.d.ts +2 -2
- package/dist/types/components/references/ReferenceForm/ReferenceForm.d.ts +3 -3
- package/dist/types/components/references/ReferenceForm/styled-components.d.ts +0 -1
- package/dist/types/components/references/ReferencesEditor.d.ts +3 -0
- package/dist/types/lib/utils.d.ts +4 -0
- package/dist/types/plugins/cross-references.d.ts +2 -0
- package/dist/types/versions.d.ts +1 -1
- package/dist/types/views/ReactSubView.d.ts +5 -2
- package/dist/types/views/cross_reference.d.ts +1 -0
- package/package.json +2 -2
- package/src/components/cross-ref-check-modal/CrossRefWarningModal.tsx +315 -83
- package/src/components/cross-ref-check-modal/openModal.ts +14 -4
- package/src/components/references/ReferenceForm/ReferenceForm.tsx +21 -82
- package/src/components/references/ReferenceForm/styled-components.ts +0 -13
- package/src/components/references/ReferencesEditor.tsx +38 -0
- package/src/components/references/ReferencesModal.tsx +116 -14
- package/src/lib/utils.ts +24 -0
- package/src/lib/view.ts +1 -0
- package/src/menus.tsx +12 -0
- package/src/plugins/cross-references.ts +41 -13
- package/src/versions.ts +1 -1
- package/src/views/ReactSubView.tsx +6 -3
- package/src/views/cross_reference.ts +14 -2
- package/src/views/cross_reference_editable.ts +1 -4
- package/styles/Editor.css +12 -0
|
@@ -52,53 +52,112 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
52
52
|
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
54
|
exports.CrossRefWarningModal = void 0;
|
|
55
|
-
const react_1 = __importStar(require("react"));
|
|
56
55
|
const style_guide_1 = require("@manuscripts/style-guide");
|
|
57
|
-
const
|
|
56
|
+
const transform_1 = require("@manuscripts/transform");
|
|
57
|
+
const react_1 = __importStar(require("react"));
|
|
58
|
+
const utils_1 = require("../../lib/utils");
|
|
59
|
+
const node_type_icons_1 = require("../../node-type-icons");
|
|
58
60
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
59
61
|
const CrossRefWarningModal = ({ onClose, xrefs, onConfirm, selectAndScrollTo }) => {
|
|
60
62
|
const [isOpen, setIsOpen] = (0, react_1.useState)(true);
|
|
63
|
+
const [deleteOption, setDeleteOption] = (0, react_1.useState)('delete-without-ref');
|
|
61
64
|
const handleClose = () => {
|
|
62
65
|
setIsOpen(false);
|
|
63
66
|
onClose();
|
|
64
67
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
const [showRef, setShowRef] = (0, react_1.useState)(false);
|
|
69
|
+
const [isScrolling, setIsScrolling] = (0, react_1.useState)(false);
|
|
70
|
+
const handleSelectAndScrollTo = ($pos) => {
|
|
71
|
+
setIsScrolling(true);
|
|
72
|
+
selectAndScrollTo($pos);
|
|
73
|
+
};
|
|
74
|
+
const toggleReferenceList = () => setShowRef(!showRef);
|
|
75
|
+
const onChangeDeleteOption = (e) => {
|
|
76
|
+
const { value } = e.target;
|
|
77
|
+
setDeleteOption(value);
|
|
78
|
+
};
|
|
79
|
+
const references = xrefs.flatMap((xrefGroup) => xrefGroup.xrefs.map((xref) => [...xref]));
|
|
80
|
+
const elementLabel = xrefs.length === 1 ? xrefs[0].label : `${xrefs.length} elements`;
|
|
81
|
+
const locationWord = references.length === 1 ? 'location' : 'locations';
|
|
82
|
+
const pronoun = xrefs.length === 1 ? 'it' : 'them';
|
|
83
|
+
return (react_1.default.createElement(Modal, { isOpen: isOpen, "$isScrolling": isScrolling, onRequestClose: () => handleClose(), shouldCloseOnOverlayClick: false, hideOverlay: true },
|
|
84
|
+
react_1.default.createElement(Container, { "$isScrolling": isScrolling, "data-cy": "cross-reference-warning-modal" },
|
|
69
85
|
react_1.default.createElement(Body, null,
|
|
70
86
|
react_1.default.createElement(Title, null,
|
|
71
|
-
react_1.default.createElement(style_guide_1.
|
|
72
|
-
"
|
|
73
|
-
react_1.default.createElement("p", null,
|
|
74
|
-
|
|
75
|
-
|
|
87
|
+
react_1.default.createElement(style_guide_1.AttentionRedIcon, { width: 24, height: 24 }),
|
|
88
|
+
"Confirm Deletion"),
|
|
89
|
+
react_1.default.createElement("p", null,
|
|
90
|
+
react_1.default.createElement("b", null, elementLabel),
|
|
91
|
+
" ",
|
|
92
|
+
xrefs.length === 1 ? 'is' : 'are',
|
|
93
|
+
" actively referenced in",
|
|
94
|
+
' ',
|
|
95
|
+
react_1.default.createElement("b", null,
|
|
96
|
+
references.length,
|
|
97
|
+
" ",
|
|
98
|
+
locationWord),
|
|
99
|
+
' ',
|
|
100
|
+
"in your document. Deleting ",
|
|
101
|
+
pronoun,
|
|
102
|
+
" will break the following cross-references:"),
|
|
103
|
+
react_1.default.createElement("div", null,
|
|
104
|
+
react_1.default.createElement(ToggleHeader, null,
|
|
105
|
+
react_1.default.createElement(SecondaryBoldHeading, null, showRef
|
|
106
|
+
? 'Hide locations'
|
|
107
|
+
: `Show ${references.length} location`),
|
|
108
|
+
react_1.default.createElement(ToggleButton, { onClick: toggleReferenceList }, showRef ? react_1.default.createElement(style_guide_1.ArrowUpIcon, null) : react_1.default.createElement(ArrowDownIcon, null))),
|
|
109
|
+
showRef && (react_1.default.createElement(ListWrapper, null, xrefs.length === 1 ? (react_1.default.createElement(XrefGroupDisplay, { label: xrefs[0].label, xrefs: xrefs[0].xrefs, selectAndScrollTo: handleSelectAndScrollTo })) : (react_1.default.createElement(XrefGroupsDisplay, { xrefsGroup: xrefs, selectAndScrollTo: handleSelectAndScrollTo }))))),
|
|
110
|
+
react_1.default.createElement(SelectorContainer, null,
|
|
111
|
+
react_1.default.createElement(style_guide_1.RadioButton, { name: 'delete-option', id: 'delete-without-ref-option', value: 'delete-without-ref', label: 'Delete but keep referenced text', checked: deleteOption === 'delete-without-ref', onChange: onChangeDeleteOption }),
|
|
112
|
+
react_1.default.createElement(style_guide_1.RadioButton, { name: 'delete-option', id: 'delete-with-ref-option', value: 'delete-with-ref', label: 'Delete & remove references', checked: deleteOption === 'delete-with-ref', onChange: onChangeDeleteOption })),
|
|
113
|
+
react_1.default.createElement(style_guide_1.ButtonGroup, null,
|
|
76
114
|
react_1.default.createElement(style_guide_1.TertiaryButton, { type: "button", onClick: () => handleClose() }, "Cancel"),
|
|
77
115
|
react_1.default.createElement(style_guide_1.PrimaryButton, { "$danger": true, type: "button", onClick: () => {
|
|
78
|
-
onConfirm();
|
|
116
|
+
onConfirm(deleteOption);
|
|
79
117
|
setIsOpen(false);
|
|
80
|
-
} }, "Delete
|
|
118
|
+
} }, "Delete"))))));
|
|
81
119
|
};
|
|
82
120
|
exports.CrossRefWarningModal = CrossRefWarningModal;
|
|
83
|
-
const XrefGroupDisplay = ({
|
|
84
|
-
return (react_1.default.createElement(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
121
|
+
const XrefGroupDisplay = ({ label, xrefs, selectAndScrollTo }) => {
|
|
122
|
+
return (react_1.default.createElement(ReferencesList, null, xrefs.map(([xrefNode, pos], i) => {
|
|
123
|
+
const { leftHandText, rightHandText } = (0, utils_1.getSurroundingText)(pos, xrefNode);
|
|
124
|
+
const derivedLabel = xrefNode.attrs.label || label || '[cross-ref]';
|
|
125
|
+
return (react_1.default.createElement(ListItem, { key: i },
|
|
126
|
+
react_1.default.createElement(XRefTextContainer, null,
|
|
127
|
+
react_1.default.createElement(XRefAdjacentText, { "$direction": 'rtl' }, leftHandText),
|
|
128
|
+
react_1.default.createElement(XRefLabel, null, derivedLabel),
|
|
129
|
+
react_1.default.createElement(XRefAdjacentText, { "$direction": 'ltr' }, rightHandText)),
|
|
130
|
+
react_1.default.createElement(ScrollButton, { "$mini": true, onClick: () => selectAndScrollTo(pos) }, "Show")));
|
|
131
|
+
})));
|
|
132
|
+
};
|
|
133
|
+
const XrefGroupsDisplay = ({ xrefsGroup, selectAndScrollTo }) => {
|
|
134
|
+
return (react_1.default.createElement(ReferencesList, null, xrefsGroup.map(({ referenced, label, caption, xrefs }, i) => {
|
|
135
|
+
const icon = getReferencedIcon(referenced.type);
|
|
136
|
+
return (react_1.default.createElement("div", { key: i },
|
|
137
|
+
react_1.default.createElement(DarkSecondaryBoldHeading, null,
|
|
138
|
+
icon ? react_1.default.createElement(ItemIcon, null, icon) : null,
|
|
139
|
+
`${label}:`,
|
|
140
|
+
react_1.default.createElement(CaptionTitle, { "$direction": 'ltr' }, caption)),
|
|
141
|
+
react_1.default.createElement(XrefGroupDisplay, { label: label, xrefs: xrefs, selectAndScrollTo: selectAndScrollTo })));
|
|
142
|
+
})));
|
|
143
|
+
};
|
|
144
|
+
const getReferencedIcon = (type) => {
|
|
145
|
+
if (type === transform_1.schema.nodes.supplement) {
|
|
146
|
+
return react_1.default.createElement(style_guide_1.WebLinkIcon, { className: "file-icon" });
|
|
147
|
+
}
|
|
148
|
+
return (0, node_type_icons_1.nodeTypeIcon)(transform_1.schema.nodes[type.name]);
|
|
90
149
|
};
|
|
91
150
|
const Container = (0, styled_components_1.default)(style_guide_1.ModalContainer) `
|
|
92
151
|
position: absolute;
|
|
93
|
-
top: 1rem;
|
|
94
|
-
left: 50
|
|
95
|
-
|
|
96
|
-
max-height: calc(50vh - 2rem);
|
|
152
|
+
top: ${({ $isScrolling }) => ($isScrolling ? '1rem' : '30%')};
|
|
153
|
+
left: ${({ $isScrolling }) => $isScrolling ? 'calc(100% - 556px - 0rem)' : '50%'};
|
|
154
|
+
max-height: calc(60vh - 2rem);
|
|
97
155
|
min-height: 280px;
|
|
98
|
-
transform: translate(-50%, 0);
|
|
99
|
-
max-width:
|
|
156
|
+
transform: ${({ $isScrolling }) => $isScrolling ? 'translate(0, 0)' : 'translate(-50%, 0)'};
|
|
157
|
+
max-width: 556px;
|
|
100
158
|
transition:
|
|
101
159
|
top 0.2s,
|
|
160
|
+
left 0.2s,
|
|
102
161
|
transform 0.2s;
|
|
103
162
|
`;
|
|
104
163
|
const Modal = (0, styled_components_1.default)(style_guide_1.StyledModal) `
|
|
@@ -126,6 +185,8 @@ const Modal = (0, styled_components_1.default)(style_guide_1.StyledModal) `
|
|
|
126
185
|
right: 0;
|
|
127
186
|
bottom: 0;
|
|
128
187
|
background: rgba(0, 0, 0, 0.2);
|
|
188
|
+
opacity: ${({ $isScrolling }) => ($isScrolling ? 0.15 : 1)};
|
|
189
|
+
transform: opacity 0.2s;
|
|
129
190
|
}
|
|
130
191
|
h3 {
|
|
131
192
|
font-size: 16px;
|
|
@@ -135,11 +196,11 @@ const Modal = (0, styled_components_1.default)(style_guide_1.StyledModal) `
|
|
|
135
196
|
margin: 0.5em 0;
|
|
136
197
|
}
|
|
137
198
|
`;
|
|
138
|
-
const Body = styled_components_1.default.div `
|
|
199
|
+
const Body = (0, style_guide_1.withFocusTrap)(styled_components_1.default.div `
|
|
139
200
|
margin: 1.5rem;
|
|
140
201
|
display: flex;
|
|
141
202
|
flex-flow: column;
|
|
142
|
-
|
|
203
|
+
`);
|
|
143
204
|
const Title = styled_components_1.default.h2 `
|
|
144
205
|
font-size: 18px;
|
|
145
206
|
font-weight: 700;
|
|
@@ -148,35 +209,124 @@ const Title = styled_components_1.default.h2 `
|
|
|
148
209
|
color: #353535;
|
|
149
210
|
svg {
|
|
150
211
|
vertical-align: text-top;
|
|
212
|
+
margin-right: 8px;
|
|
151
213
|
}
|
|
152
214
|
`;
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
215
|
+
const ToggleHeader = styled_components_1.default.div `
|
|
216
|
+
display: flex;
|
|
217
|
+
justify-content: space-between;
|
|
218
|
+
align-items: center;
|
|
219
|
+
padding: 6px 3px 6px 8px;
|
|
220
|
+
border-radius: 4px 4px 0 0;
|
|
221
|
+
border: 1px solid #e2e2e2;
|
|
157
222
|
background: #f2f2f2;
|
|
223
|
+
`;
|
|
224
|
+
const ListWrapper = styled_components_1.default.div `
|
|
158
225
|
border: 1px solid #e2e2e2;
|
|
159
|
-
border-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
226
|
+
border-top: none;
|
|
227
|
+
max-height: 21vh;
|
|
228
|
+
min-height: 100px;
|
|
229
|
+
overflow-y: auto;
|
|
230
|
+
padding: 12px;
|
|
231
|
+
`;
|
|
232
|
+
const ToggleButton = (0, styled_components_1.default)(style_guide_1.IconButton) `
|
|
233
|
+
height: 24px;
|
|
234
|
+
&&:not([disabled]):focus-visible {
|
|
235
|
+
outline: 2px solid ${(props) => props.theme.colors.outline.focus};
|
|
236
|
+
outline-offset: 2px;
|
|
237
|
+
}
|
|
238
|
+
svg {
|
|
239
|
+
width: 12px;
|
|
240
|
+
height: 7px;
|
|
172
241
|
}
|
|
173
242
|
`;
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
243
|
+
const SecondaryHeading = styled_components_1.default.div `
|
|
244
|
+
font-size: 14px;
|
|
245
|
+
font-style: normal;
|
|
246
|
+
font-weight: 700;
|
|
247
|
+
line-height: 24px;
|
|
248
|
+
color: #6e6e6e;
|
|
249
|
+
user-select: none;
|
|
177
250
|
`;
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
251
|
+
const SecondaryBoldHeading = (0, styled_components_1.default)(SecondaryHeading) `
|
|
252
|
+
font-weight: 700;
|
|
253
|
+
color: #6e6e6e;
|
|
254
|
+
`;
|
|
255
|
+
const DarkSecondaryBoldHeading = (0, styled_components_1.default)(SecondaryBoldHeading) `
|
|
256
|
+
display: flex;
|
|
257
|
+
padding: 0 4px;
|
|
258
|
+
margin-bottom: 10px;
|
|
259
|
+
border-radius: 4px;
|
|
260
|
+
color: #353535;
|
|
261
|
+
background: #f2f2f2;
|
|
262
|
+
`;
|
|
263
|
+
const ItemIcon = styled_components_1.default.span `
|
|
264
|
+
display: flex;
|
|
265
|
+
padding-right: 8px;
|
|
266
|
+
svg {
|
|
267
|
+
align-self: center;
|
|
268
|
+
}
|
|
269
|
+
`;
|
|
270
|
+
const ReferencesList = styled_components_1.default.ul `
|
|
271
|
+
display: flex;
|
|
272
|
+
gap: 10px;
|
|
273
|
+
flex-direction: column;
|
|
274
|
+
padding: 0;
|
|
275
|
+
margin: 0;
|
|
276
|
+
list-style: none;
|
|
277
|
+
`;
|
|
278
|
+
const ListItem = styled_components_1.default.li `
|
|
279
|
+
display: flex;
|
|
280
|
+
justify-content: space-between;
|
|
281
|
+
align-items: center;
|
|
282
|
+
border-bottom: solid 1px #e2e2e2;
|
|
283
|
+
&:last-child {
|
|
284
|
+
border-bottom: none;
|
|
285
|
+
padding: 0;
|
|
286
|
+
}
|
|
287
|
+
`;
|
|
288
|
+
const ScrollButton = (0, styled_components_1.default)(style_guide_1.TertiaryButton) `
|
|
289
|
+
margin: 0;
|
|
290
|
+
padding: 4px;
|
|
291
|
+
font-size: 14px;
|
|
292
|
+
line-height: 24px;
|
|
293
|
+
text-decoration-line: underline;
|
|
294
|
+
`;
|
|
295
|
+
const XRefTextContainer = styled_components_1.default.div `
|
|
296
|
+
display: flex;
|
|
297
|
+
color: #6e6e6e;
|
|
298
|
+
font-size: 12px;
|
|
299
|
+
font-style: normal;
|
|
300
|
+
font-weight: 400;
|
|
301
|
+
line-height: 16px;
|
|
302
|
+
`;
|
|
303
|
+
const XRefLabel = styled_components_1.default.span `
|
|
304
|
+
border-radius: 4px;
|
|
305
|
+
border: 1px solid #fe8f1f;
|
|
306
|
+
background: #fff9e5;
|
|
307
|
+
mix-blend-mode: darken;
|
|
308
|
+
`;
|
|
309
|
+
const XRefAdjacentText = styled_components_1.default.span `
|
|
310
|
+
display: block;
|
|
311
|
+
max-width: 150px;
|
|
312
|
+
white-space: nowrap;
|
|
313
|
+
overflow: hidden;
|
|
314
|
+
text-overflow: ellipsis;
|
|
315
|
+
direction: ${(props) => props.$direction};
|
|
316
|
+
`;
|
|
317
|
+
const CaptionTitle = (0, styled_components_1.default)(XRefAdjacentText) `
|
|
318
|
+
max-width: 120px;
|
|
319
|
+
margin-left: 4px;
|
|
320
|
+
`;
|
|
321
|
+
const SelectorContainer = styled_components_1.default.div `
|
|
322
|
+
display: flex;
|
|
323
|
+
gap: 24px;
|
|
324
|
+
padding: 8px 12px 4px 12px;
|
|
325
|
+
margin: 24px 0;
|
|
326
|
+
border-radius: 4px;
|
|
327
|
+
border: 1px solid #fe8f1f;
|
|
328
|
+
background: #fff9e5;
|
|
329
|
+
`;
|
|
330
|
+
const ArrowDownIcon = (0, styled_components_1.default)(style_guide_1.ArrowUpIcon) `
|
|
331
|
+
transform: rotate(180deg);
|
|
182
332
|
`;
|
|
@@ -27,8 +27,14 @@ const openCrossRefWarningModal = (view, xrefGroups, onConfirm, onClose, selectAn
|
|
|
27
27
|
const props = (0, editor_props_1.getEditorProps)(state);
|
|
28
28
|
const componentProps = {
|
|
29
29
|
xrefs: xrefGroups,
|
|
30
|
-
onConfirm
|
|
31
|
-
|
|
30
|
+
onConfirm: (deleteOption) => {
|
|
31
|
+
dialog.unmount();
|
|
32
|
+
onConfirm(deleteOption);
|
|
33
|
+
},
|
|
34
|
+
onClose: () => {
|
|
35
|
+
dialog.unmount();
|
|
36
|
+
onClose();
|
|
37
|
+
},
|
|
32
38
|
selectAndScrollTo,
|
|
33
39
|
};
|
|
34
40
|
const dialog = (0, ReactSubView_1.default)(props, CrossRefWarningModal_1.CrossRefWarningModal, componentProps, state.doc, () => 0, view);
|
|
@@ -48,7 +48,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
48
48
|
};
|
|
49
49
|
})();
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
exports.ReferenceForm = void 0;
|
|
51
|
+
exports.ReferenceForm = exports.validateReference = void 0;
|
|
52
52
|
const style_guide_1 = require("@manuscripts/style-guide");
|
|
53
53
|
const formik_1 = require("formik");
|
|
54
54
|
const react_1 = __importStar(require("react"));
|
|
@@ -61,7 +61,22 @@ const bibliographyItemTypeOptions = references_1.bibliographyItemTypes.map((i) =
|
|
|
61
61
|
label: i[1],
|
|
62
62
|
value: i[0],
|
|
63
63
|
}));
|
|
64
|
-
const
|
|
64
|
+
const validateReference = (values) => {
|
|
65
|
+
const errors = {};
|
|
66
|
+
if (values.type === 'literal') {
|
|
67
|
+
if (!values.literal?.trim()) {
|
|
68
|
+
errors.literal = 'Literal is required for unstructured references';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
if (!values.title?.trim()) {
|
|
73
|
+
errors.title = 'Title is required';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return errors;
|
|
77
|
+
};
|
|
78
|
+
exports.validateReference = validateReference;
|
|
79
|
+
const ReferenceForm = ({ values, onChange, onSave, actionsRef, }) => {
|
|
65
80
|
const fieldsRef = (0, react_1.useRef)(null);
|
|
66
81
|
const formRef = (0, react_1.useRef)(null);
|
|
67
82
|
const [newAuthorIndex, setNewAuthorIndex] = (0, react_1.useState)();
|
|
@@ -71,52 +86,19 @@ const ReferenceForm = ({ values, showDelete, onChange, onDelete, onCancel, onSav
|
|
|
71
86
|
fieldsRef.current.scrollTop = 0;
|
|
72
87
|
}
|
|
73
88
|
}, [values]);
|
|
74
|
-
const [showDeleteDialog, setShowDeleteDialog] = (0, react_1.useState)(false);
|
|
75
|
-
const validateReference = (values) => {
|
|
76
|
-
const errors = {};
|
|
77
|
-
if (values.type === 'literal') {
|
|
78
|
-
if (!values.literal?.trim()) {
|
|
79
|
-
errors.literal = 'Literal is required for unstructured references';
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
if (!values.title?.trim()) {
|
|
84
|
-
errors.title = 'Title is required';
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return errors;
|
|
88
|
-
};
|
|
89
89
|
if (actionsRef && !actionsRef.current) {
|
|
90
90
|
actionsRef.current = {
|
|
91
91
|
reset: () => {
|
|
92
92
|
formRef.current?.resetForm();
|
|
93
93
|
},
|
|
94
|
+
submit: () => {
|
|
95
|
+
formRef.current?.submitForm();
|
|
96
|
+
},
|
|
97
|
+
isDirty: () => formRef.current?.dirty ?? false,
|
|
94
98
|
};
|
|
95
99
|
}
|
|
96
|
-
return (react_1.default.createElement(formik_1.Formik, { initialValues: values, onSubmit: onSave, enableReinitialize: true, innerRef: formRef, validate: validateReference }, (formik) => {
|
|
100
|
+
return (react_1.default.createElement(formik_1.Formik, { initialValues: values, onSubmit: onSave, enableReinitialize: true, innerRef: formRef, validate: exports.validateReference }, (formik) => {
|
|
97
101
|
return (react_1.default.createElement(ChangeHandlingForm_1.ChangeHandlingForm, { onChange: onChange },
|
|
98
|
-
react_1.default.createElement(style_guide_1.Dialog, { isOpen: showDeleteDialog, category: style_guide_1.Category.confirmation, header: "Delete Reference", message: "Are you sure you want to delete this reference from the list?", actions: {
|
|
99
|
-
secondary: {
|
|
100
|
-
action: () => {
|
|
101
|
-
onDelete();
|
|
102
|
-
setShowDeleteDialog(false);
|
|
103
|
-
},
|
|
104
|
-
title: 'Delete',
|
|
105
|
-
},
|
|
106
|
-
primary: {
|
|
107
|
-
action: () => setShowDeleteDialog(false),
|
|
108
|
-
title: 'Cancel',
|
|
109
|
-
},
|
|
110
|
-
} }),
|
|
111
|
-
react_1.default.createElement(styled_components_1.Actions, null,
|
|
112
|
-
react_1.default.createElement(style_guide_1.ButtonGroup, null,
|
|
113
|
-
react_1.default.createElement(style_guide_1.IconButton, { as: "a", href: `https://doi.org/${formik.values.DOI}`, target: '_blank' },
|
|
114
|
-
react_1.default.createElement(style_guide_1.LinkIcon, null)),
|
|
115
|
-
react_1.default.createElement(styled_components_1.DeleteButton, { "$defaultColor": true, disabled: !showDelete, "data-tooltip-content": "Unable to delete because the item is used in the document", "data-tooltip-hidden": showDelete, onClick: () => setShowDeleteDialog(true) },
|
|
116
|
-
react_1.default.createElement(style_guide_1.DeleteIcon, null))),
|
|
117
|
-
react_1.default.createElement(style_guide_1.ButtonGroup, null,
|
|
118
|
-
react_1.default.createElement(style_guide_1.SecondaryButton, { onClick: onCancel }, "Cancel"),
|
|
119
|
-
react_1.default.createElement(style_guide_1.PrimaryButton, { type: "submit", disabled: !formik.isValid || !formik.dirty }, "Save"))),
|
|
120
102
|
react_1.default.createElement(styled_components_1.FormFields, { ref: fieldsRef },
|
|
121
103
|
react_1.default.createElement(style_guide_1.FormRow, null,
|
|
122
104
|
react_1.default.createElement(style_guide_1.Label, { htmlFor: 'citation-item-type' }, "Type"),
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.RemoveButton = exports.ToggleButton = exports.DropdownIndicator = exports.Title = exports.PersonForm = exports.Section = exports.DeleteButton = exports.FormFields = exports.ReferenceTextArea = exports.ReferenceTextField = exports.
|
|
6
|
+
exports.RemoveButton = exports.ToggleButton = exports.DropdownIndicator = exports.Title = exports.PersonForm = exports.Section = exports.DeleteButton = exports.FormFields = exports.ReferenceTextArea = exports.ReferenceTextField = exports.Button = void 0;
|
|
7
7
|
const style_guide_1 = require("@manuscripts/style-guide");
|
|
8
8
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
9
9
|
exports.Button = (0, styled_components_1.default)(style_guide_1.IconButton).attrs({
|
|
@@ -19,18 +19,6 @@ exports.Button = (0, styled_components_1.default)(style_guide_1.IconButton).attr
|
|
|
19
19
|
mask: none;
|
|
20
20
|
}
|
|
21
21
|
`;
|
|
22
|
-
exports.Actions = styled_components_1.default.div `
|
|
23
|
-
flex-shrink: 1;
|
|
24
|
-
display: flex;
|
|
25
|
-
justify-content: space-between;
|
|
26
|
-
align-items: center;
|
|
27
|
-
|
|
28
|
-
.tooltip {
|
|
29
|
-
max-width: ${(props) => props.theme.grid.unit * 39}px;
|
|
30
|
-
padding: ${(props) => props.theme.grid.unit * 2}px;
|
|
31
|
-
border-radius: 6px;
|
|
32
|
-
}
|
|
33
|
-
`;
|
|
34
22
|
exports.ReferenceTextField = (0, styled_components_1.default)(style_guide_1.TextField) `
|
|
35
23
|
padding: ${(props) => props.theme.grid.unit * 2}px
|
|
36
24
|
${(props) => props.theme.grid.unit * 3}px;
|
|
@@ -32,13 +32,20 @@ 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.ReferencesEditor = void 0;
|
|
39
|
+
exports.openReferencesEditor = exports.ReferencesEditor = void 0;
|
|
37
40
|
const transform_1 = require("@manuscripts/transform");
|
|
38
41
|
const react_1 = __importStar(require("react"));
|
|
39
42
|
const array_reducer_1 = require("../../lib/array-reducer");
|
|
40
43
|
const utils_1 = require("../../lib/utils");
|
|
41
44
|
const ReferencesModal_1 = require("./ReferencesModal");
|
|
45
|
+
const editor_props_1 = require("../../plugins/editor-props");
|
|
46
|
+
const view_1 = require("../../lib/view");
|
|
47
|
+
const ReactSubView_1 = __importDefault(require("../../views/ReactSubView"));
|
|
48
|
+
const bibliography_1 = require("../../plugins/bibliography");
|
|
42
49
|
const itemsReducer = (0, array_reducer_1.attrsReducer)();
|
|
43
50
|
const ReferencesEditor = (props) => {
|
|
44
51
|
const [isOpen, setOpen] = (0, react_1.useState)(true);
|
|
@@ -76,3 +83,21 @@ const ReferencesEditor = (props) => {
|
|
|
76
83
|
return (react_1.default.createElement(ReferencesModal_1.ReferencesModal, { isOpen: isOpen, onCancel: () => setOpen(false), items: items, item: selectedItem, citationCounts: props.citationCounts, onSave: handleSave, onDelete: handleDelete, handleImport: handleImport }));
|
|
77
84
|
};
|
|
78
85
|
exports.ReferencesEditor = ReferencesEditor;
|
|
86
|
+
const openReferencesEditor = (state, _, view) => {
|
|
87
|
+
if (!view) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const props = (0, editor_props_1.getEditorProps)(state);
|
|
91
|
+
const bib = (0, bibliography_1.getBibliographyPluginState)(view.state);
|
|
92
|
+
const componentProps = {
|
|
93
|
+
items: bib ? Array.from(bib.bibliographyItems.values()) : [],
|
|
94
|
+
citationCounts: new Map(bib?.citationCounts),
|
|
95
|
+
onDelete: (item) => (0, view_1.deleteNode)(view, item.id),
|
|
96
|
+
onSave: (item) => (0, view_1.saveBibliographyItem)(view, item),
|
|
97
|
+
};
|
|
98
|
+
const referencesEditor = (0, ReactSubView_1.default)(props, exports.ReferencesEditor, componentProps, state.doc, () => 0, view);
|
|
99
|
+
view.focus();
|
|
100
|
+
document.body.appendChild(referencesEditor);
|
|
101
|
+
return true;
|
|
102
|
+
};
|
|
103
|
+
exports.openReferencesEditor = openReferencesEditor;
|