@manuscripts/body-editor 3.19.1 → 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/lib/utils.js +12 -1
- 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/lib/utils.js +11 -1
- 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/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 +1 -1
- package/src/components/cross-ref-check-modal/CrossRefWarningModal.tsx +315 -83
- package/src/components/cross-ref-check-modal/openModal.ts +14 -4
- package/src/lib/utils.ts +24 -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);
|
package/dist/cjs/lib/utils.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.getLastTitleNode = exports.filterBlockNodes = exports.findInsertionPosition = exports.getInsertPos = exports.createToggleButton = exports.isEditAllowed = exports.isBodyLocked = exports.cleanItemValues = exports.shouldRenderField = exports.hasParent = exports.isNotNull = exports.createHeader = exports.isSelectionInBody = exports.isSelectionInNode = exports.isChildOfNodeTypes = exports.findParentElement = exports.findParentSection = exports.findParentNodeWithIdValue = exports.findParentNodeWithId = exports.getChildOfType = exports.getMatchingDescendant = exports.getMatchingChild = void 0;
|
|
18
|
+
exports.getSurroundingText = exports.getLastTitleNode = exports.filterBlockNodes = exports.findInsertionPosition = exports.getInsertPos = exports.createToggleButton = exports.isEditAllowed = exports.isBodyLocked = exports.cleanItemValues = exports.shouldRenderField = exports.hasParent = exports.isNotNull = exports.createHeader = exports.isSelectionInBody = exports.isSelectionInNode = exports.isChildOfNodeTypes = exports.findParentElement = exports.findParentSection = exports.findParentNodeWithIdValue = exports.findParentNodeWithId = exports.getChildOfType = exports.getMatchingDescendant = exports.getMatchingChild = void 0;
|
|
19
19
|
exports.iterateChildren = iterateChildren;
|
|
20
20
|
const transform_1 = require("@manuscripts/transform");
|
|
21
21
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
@@ -220,3 +220,14 @@ const getLastTitleNode = (state) => {
|
|
|
220
220
|
return titleNode;
|
|
221
221
|
};
|
|
222
222
|
exports.getLastTitleNode = getLastTitleNode;
|
|
223
|
+
const getSurroundingText = (pos, node) => {
|
|
224
|
+
const nodeContent = (0, prosemirror_utils_1.findChildren)(pos.node(), (child) => child.attrs.id === node.attrs.id)[0];
|
|
225
|
+
const content = pos.node().content;
|
|
226
|
+
const MAX_LENGTH = 40;
|
|
227
|
+
const nodeStart = nodeContent.pos;
|
|
228
|
+
const nodeEnd = nodeContent.pos + node.nodeSize;
|
|
229
|
+
const leftHandText = content.textBetween(nodeStart > MAX_LENGTH ? nodeStart - MAX_LENGTH : 0, nodeStart);
|
|
230
|
+
const rightHandText = content.textBetween(nodeEnd, Math.min(nodeEnd + MAX_LENGTH, content.size));
|
|
231
|
+
return { leftHandText, rightHandText };
|
|
232
|
+
};
|
|
233
|
+
exports.getSurroundingText = getSurroundingText;
|
|
@@ -18,6 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.SELECTED_CROSS_REF_CLASS = exports.DELETE_WITHOUT_REF = void 0;
|
|
21
22
|
const transform_1 = require("@manuscripts/transform");
|
|
22
23
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
23
24
|
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
@@ -25,8 +26,11 @@ const prosemirror_state_1 = require("prosemirror-state");
|
|
|
25
26
|
const prosemirror_view_1 = require("prosemirror-view");
|
|
26
27
|
const openModal_1 = require("../components/cross-ref-check-modal/openModal");
|
|
27
28
|
const objects_1 = require("./objects");
|
|
29
|
+
exports.DELETE_WITHOUT_REF = 'delete-without-ref';
|
|
30
|
+
exports.SELECTED_CROSS_REF_CLASS = 'selected-cross-reference';
|
|
28
31
|
let modalActive = false;
|
|
29
32
|
let modalElement = null;
|
|
33
|
+
let scrollTargetEl = null;
|
|
30
34
|
exports.default = () => {
|
|
31
35
|
let view = null;
|
|
32
36
|
return new prosemirror_state_1.Plugin({
|
|
@@ -45,7 +49,10 @@ exports.default = () => {
|
|
|
45
49
|
if (!view ||
|
|
46
50
|
!tr.docChanged ||
|
|
47
51
|
tr.getMeta(track_changes_plugin_1.trackChangesPluginKey) ||
|
|
48
|
-
tr.getMeta(
|
|
52
|
+
tr.getMeta(track_changes_plugin_1.TrackChangesAction.refreshChanges) ||
|
|
53
|
+
tr.getMeta('addToHistory') === false ||
|
|
54
|
+
tr.getMeta('collab$') ||
|
|
55
|
+
tr.getMeta(exports.DELETE_WITHOUT_REF)) {
|
|
49
56
|
return true;
|
|
50
57
|
}
|
|
51
58
|
if (modalActive) {
|
|
@@ -64,6 +71,9 @@ exports.default = () => {
|
|
|
64
71
|
modalElement.remove();
|
|
65
72
|
modalElement = null;
|
|
66
73
|
}
|
|
74
|
+
if (scrollTargetEl) {
|
|
75
|
+
scrollTargetEl.classList.remove(exports.SELECTED_CROSS_REF_CLASS);
|
|
76
|
+
}
|
|
67
77
|
};
|
|
68
78
|
const deletedIds = new Set(xrefGroups.map((g) => g.referenced.attrs.id));
|
|
69
79
|
const onClose = () => {
|
|
@@ -154,12 +164,13 @@ function createXrefGroups(targets, stateDoc, resultDoc) {
|
|
|
154
164
|
const xrefs = xrefsByRid.get(id);
|
|
155
165
|
if (xrefs?.length) {
|
|
156
166
|
const label = targets.get(referenced.attrs.id)?.label || '';
|
|
157
|
-
|
|
167
|
+
const caption = targets.get(referenced.attrs.id)?.caption || '';
|
|
168
|
+
xrefGroups.push({ referenced, label, caption, xrefs });
|
|
158
169
|
}
|
|
159
170
|
}
|
|
160
171
|
return xrefGroups;
|
|
161
172
|
}
|
|
162
|
-
const onConfirmCreator = (view, cleanup, deletedIds, tr) => () => {
|
|
173
|
+
const onConfirmCreator = (view, cleanup, deletedIds, tr) => (deleteOption) => {
|
|
163
174
|
cleanup();
|
|
164
175
|
if (!view) {
|
|
165
176
|
return;
|
|
@@ -173,18 +184,23 @@ const onConfirmCreator = (view, cleanup, deletedIds, tr) => () => {
|
|
|
173
184
|
}
|
|
174
185
|
newTr.step(step);
|
|
175
186
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
187
|
+
if (deleteOption === 'delete-with-ref') {
|
|
188
|
+
const xrefPositions = [];
|
|
189
|
+
newTr.doc.descendants((node, pos) => {
|
|
190
|
+
if (node.type === transform_1.schema.nodes.cross_reference) {
|
|
191
|
+
const rids = node.attrs.rids;
|
|
192
|
+
if (rids.some((rid) => deletedIds.has(rid))) {
|
|
193
|
+
xrefPositions.push({ from: pos, to: pos + node.nodeSize });
|
|
194
|
+
}
|
|
182
195
|
}
|
|
196
|
+
});
|
|
197
|
+
for (let i = xrefPositions.length - 1; i >= 0; i--) {
|
|
198
|
+
const { from, to } = xrefPositions[i];
|
|
199
|
+
newTr.delete(from, to);
|
|
183
200
|
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
newTr.delete(from, to);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
newTr.setMeta(exports.DELETE_WITHOUT_REF, true);
|
|
188
204
|
}
|
|
189
205
|
view.dispatch(newTr);
|
|
190
206
|
};
|
|
@@ -194,7 +210,6 @@ const selectAndScrollToCreator = (view) => ($pos) => {
|
|
|
194
210
|
}
|
|
195
211
|
const selTr = view.state.tr;
|
|
196
212
|
selTr.setSelection(prosemirror_state_1.NodeSelection.create(view.state.doc, $pos.pos));
|
|
197
|
-
view.focus();
|
|
198
213
|
view.dispatch(selTr);
|
|
199
214
|
let scrollable = view.dom.parentElement;
|
|
200
215
|
while (scrollable != null &&
|
|
@@ -217,4 +232,12 @@ const selectAndScrollToCreator = (view) => ($pos) => {
|
|
|
217
232
|
modalElement?.classList.remove('modal-bottom');
|
|
218
233
|
scrollable.scrollTo({ top: scrollTo, behavior: 'smooth' });
|
|
219
234
|
}
|
|
235
|
+
const dom = view.nodeDOM($pos.pos);
|
|
236
|
+
if (dom && dom instanceof HTMLElement) {
|
|
237
|
+
dom.classList.add(exports.SELECTED_CROSS_REF_CLASS);
|
|
238
|
+
if (scrollTargetEl && scrollTargetEl !== dom) {
|
|
239
|
+
scrollTargetEl?.classList.remove(exports.SELECTED_CROSS_REF_CLASS);
|
|
240
|
+
}
|
|
241
|
+
scrollTargetEl = dom;
|
|
242
|
+
}
|
|
220
243
|
};
|
package/dist/cjs/versions.js
CHANGED
|
@@ -26,6 +26,7 @@ const client_1 = require("react-dom/client");
|
|
|
26
26
|
const styled_components_1 = require("styled-components");
|
|
27
27
|
function createSubView(props, Component, componentProps, node, getPos, view, classNames = []) {
|
|
28
28
|
const container = document.createElement('div');
|
|
29
|
+
container.unmount = () => root.unmount();
|
|
29
30
|
const Wrapped = createView(props, Component, componentProps, node, getPos, view, classNames, container);
|
|
30
31
|
const root = (0, client_1.createRoot)(container);
|
|
31
32
|
root.render(react_1.default.createElement(Wrapped, null));
|
|
@@ -53,10 +53,21 @@ class CrossReferenceView extends base_node_view_1.BaseNodeView {
|
|
|
53
53
|
const target = attrs.rids.length ? targets.get(attrs.rids[0]) : undefined;
|
|
54
54
|
const isSupplement = target?.type === transform_1.schema.nodes.supplement.name;
|
|
55
55
|
const derivedLabel = isSupplement
|
|
56
|
-
? target?.caption || target?.label || ''
|
|
57
|
-
: target?.label || '';
|
|
56
|
+
? target?.caption || target?.label || '[cross-ref]'
|
|
57
|
+
: target?.label || '[cross-ref]';
|
|
58
58
|
this.dom.textContent = attrs.label || derivedLabel;
|
|
59
59
|
this.dom.addEventListener('click', this.handleClick);
|
|
60
|
+
if (this.isOrphaned()) {
|
|
61
|
+
this.dom.classList.add('orphaned-cross-reference');
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
this.dom.classList.remove('orphaned-cross-reference');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
isOrphaned() {
|
|
68
|
+
const targets = objects_1.objectsKey.getState(this.view.state);
|
|
69
|
+
const rid = this.node.attrs.rids[0];
|
|
70
|
+
return !targets?.get(rid);
|
|
60
71
|
}
|
|
61
72
|
}
|
|
62
73
|
exports.CrossReferenceView = CrossReferenceView;
|
|
@@ -117,9 +117,7 @@ class CrossReferenceEditableView extends cross_reference_1.CrossReferenceView {
|
|
|
117
117
|
this.showContextMenu = () => {
|
|
118
118
|
this.props.popper.destroy();
|
|
119
119
|
const can = this.props.getCapabilities();
|
|
120
|
-
const
|
|
121
|
-
const rid = this.node.attrs.rids[0];
|
|
122
|
-
const isOrphaned = !targets?.get(rid);
|
|
120
|
+
const isOrphaned = this.isOrphaned();
|
|
123
121
|
const actions = [
|
|
124
122
|
{
|
|
125
123
|
label: 'Comment',
|
|
@@ -141,7 +139,6 @@ class CrossReferenceEditableView extends cross_reference_1.CrossReferenceView {
|
|
|
141
139
|
label: 'Edit',
|
|
142
140
|
icon: 'Edit',
|
|
143
141
|
action: () => this.handleEdit(),
|
|
144
|
-
disabled: isOrphaned,
|
|
145
142
|
});
|
|
146
143
|
}
|
|
147
144
|
this.contextMenu = (0, ReactSubView_1.default)(this.props, style_guide_1.ContextMenu, { actions }, this.node, this.getPos, this.view, ['context-menu']);
|