@manuscripts/body-editor 1.11.5 → 1.11.6-LEAN-3307.4

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.
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.insertTableFootnote = exports.addInlineComment = exports.addNodeComment = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreMetaNodeBackspaceCommand = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.ifInTableBody = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertSection = exports.insertGraphicalAbstract = exports.insertInlineFootnote = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertFileAsFigure = exports.insertGeneralFootnote = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = void 0;
18
+ exports.insertTableFootnote = exports.addInlineComment = exports.addNodeComment = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreMetaNodeBackspaceCommand = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.ifInTableBody = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertKeywords = exports.insertContributors = exports.insertAbstract = exports.insertBackMatterSection = exports.insertSection = exports.insertGraphicalAbstract = exports.insertInlineFootnote = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertFileAsFigure = exports.insertGeneralFootnote = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = void 0;
19
19
  const json_schema_1 = require("@manuscripts/json-schema");
20
20
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
21
21
  const transform_1 = require("@manuscripts/transform");
@@ -96,7 +96,7 @@ const createSelection = (nodeType, position, doc) => {
96
96
  }
97
97
  };
98
98
  exports.createSelection = createSelection;
99
- const createBlock = (nodeType, position, state, dispatch) => {
99
+ const createBlock = (nodeType, position, state, dispatch, attrs) => {
100
100
  let node;
101
101
  switch (nodeType) {
102
102
  case state.schema.nodes.table_element:
@@ -117,7 +117,7 @@ const createBlock = (nodeType, position, state, dispatch) => {
117
117
  ]);
118
118
  break;
119
119
  default:
120
- node = nodeType.createAndFill();
120
+ node = nodeType.createAndFill(attrs);
121
121
  }
122
122
  const tr = state.tr.insert(position, node);
123
123
  if (dispatch) {
@@ -129,9 +129,12 @@ exports.createBlock = createBlock;
129
129
  const insertGeneralFootnote = (tableNode, position, view, tableElementFooter) => {
130
130
  var _a;
131
131
  const { state, dispatch } = view;
132
- const generalNote = state.schema.nodes.paragraph.create({
132
+ const paragraph = state.schema.nodes.paragraph.create({
133
133
  placeholder: 'Add general note here',
134
134
  });
135
+ const generalNote = state.schema.nodes.general_table_footnote.create({}, [
136
+ paragraph,
137
+ ]);
135
138
  const tableColGroup = (0, prosemirror_utils_1.findChildrenByType)(tableNode, transform_1.schema.nodes.table_colgroup)[0];
136
139
  const tr = state.tr;
137
140
  const pos = (tableElementFooter === null || tableElementFooter === void 0 ? void 0 : tableElementFooter.length)
@@ -362,7 +365,7 @@ const insertInlineFootnote = (kind) => (state, dispatch) => {
362
365
  return true;
363
366
  };
364
367
  exports.insertInlineFootnote = insertInlineFootnote;
365
- const insertGraphicalAbstract = (state, dispatch) => {
368
+ const insertGraphicalAbstract = (state, dispatch, view) => {
366
369
  if ((0, utils_1.getChildOfType)(state.doc, transform_1.schema.nodes.graphical_abstract_section, true)) {
367
370
  return false;
368
371
  }
@@ -375,29 +378,137 @@ const insertGraphicalAbstract = (state, dispatch) => {
375
378
  const tr = state.tr.insert(pos, section);
376
379
  if (dispatch) {
377
380
  const selection = prosemirror_state_1.TextSelection.create(tr.doc, pos + 1);
381
+ if (view) {
382
+ view.focus();
383
+ }
378
384
  dispatch(tr.setSelection(selection).scrollIntoView());
379
385
  }
380
386
  return true;
381
387
  };
382
388
  exports.insertGraphicalAbstract = insertGraphicalAbstract;
383
- const insertSection = (subsection = false) => (state, dispatch) => {
384
- const pos = findPosAfterParentSection(state.selection.$from);
385
- if (pos === null || (0, transform_1.isInBibliographySection)(state.selection.$from)) {
389
+ const insertSection = (subsection = false) => (state, dispatch, view) => {
390
+ let pos = findPosAfterParentSection(state.selection.$from);
391
+ const body = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.body)[0];
392
+ if ((0, transform_1.isInBibliographySection)(state.selection.$from)) {
386
393
  return false;
387
394
  }
395
+ if (pos === null) {
396
+ pos = body.pos + body.node.content.size + 1;
397
+ }
388
398
  const adjustment = subsection ? -1 : 0;
389
399
  const tr = state.tr.insert(pos + adjustment, state.schema.nodes.section.createAndFill());
390
400
  if (dispatch) {
391
401
  const selection = prosemirror_state_1.TextSelection.create(tr.doc, pos + adjustment + 2);
402
+ if (view) {
403
+ view.focus();
404
+ }
392
405
  dispatch(tr.setSelection(selection).scrollIntoView());
393
406
  }
394
407
  return true;
395
408
  };
396
409
  exports.insertSection = insertSection;
397
- const findSelectedList = (0, prosemirror_utils_1.findParentNodeOfType)([
398
- transform_1.schema.nodes.ordered_list,
399
- transform_1.schema.nodes.bullet_list,
400
- ]);
410
+ const insertBackMatterSection = (category) => (state, dispatch, view) => {
411
+ const bibliographySection = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.bibliography_section)[0];
412
+ const backmatter = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.backmatter)[0];
413
+ let pos;
414
+ if (bibliographySection) {
415
+ pos = bibliographySection.pos;
416
+ }
417
+ else {
418
+ pos = backmatter.pos + backmatter.node.content.size + 1;
419
+ }
420
+ const tr = state.tr.insert(pos, state.schema.nodes.section.createAndFill({
421
+ category: category,
422
+ }));
423
+ if (dispatch) {
424
+ const selection = prosemirror_state_1.TextSelection.create(tr.doc, pos);
425
+ if (view) {
426
+ view.focus();
427
+ }
428
+ dispatch(tr.setSelection(selection).scrollIntoView());
429
+ }
430
+ return true;
431
+ };
432
+ exports.insertBackMatterSection = insertBackMatterSection;
433
+ const findSelectedList = (0, prosemirror_utils_1.findParentNodeOfType)([transform_1.schema.nodes.list]);
434
+ const insertAbstract = (state, dispatch, view) => {
435
+ if ((0, utils_1.getMatchingChild)(state.doc, (node) => node.attrs.category === 'MPSectionCategory:abstract', true)) {
436
+ return false;
437
+ }
438
+ const abstracts = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.abstracts)[0];
439
+ const pos = abstracts.pos + 1;
440
+ const section = transform_1.schema.nodes.section.createAndFill({ category: 'MPSectionCategory:abstract' }, [
441
+ transform_1.schema.nodes.section_title.create({}, transform_1.schema.text('Abstract')),
442
+ transform_1.schema.nodes.paragraph.create({ placeholder: 'Type abstract here...' }),
443
+ ]);
444
+ const tr = state.tr.insert(pos, section);
445
+ if (dispatch) {
446
+ const sectionStart = tr.doc.resolve(pos);
447
+ const sectionNode = sectionStart.nodeAfter;
448
+ if (sectionNode && sectionNode.firstChild) {
449
+ const paragraphPos = pos + sectionNode.firstChild.nodeSize + 2;
450
+ const selection = prosemirror_state_1.TextSelection.create(tr.doc, paragraphPos);
451
+ if (view) {
452
+ view.focus();
453
+ }
454
+ dispatch(tr.setSelection(selection).scrollIntoView());
455
+ }
456
+ }
457
+ return true;
458
+ };
459
+ exports.insertAbstract = insertAbstract;
460
+ const insertContributors = (state, dispatch, view) => {
461
+ if ((0, utils_1.getChildOfType)(state.doc, transform_1.schema.nodes.contributors, true)) {
462
+ return false;
463
+ }
464
+ const title = (0, prosemirror_utils_1.findChildrenByType)(state.doc, state.schema.nodes.title)[0];
465
+ const pos = title.pos + title.node.nodeSize;
466
+ const contributors = state.schema.nodes.contributors.create({
467
+ id: '',
468
+ });
469
+ const affiliations = state.schema.nodes.affiliations.create({ id: '' });
470
+ const fragment = prosemirror_model_1.Fragment.fromArray([contributors, affiliations]);
471
+ const tr = state.tr.insert(pos, fragment);
472
+ if (dispatch) {
473
+ const selection = prosemirror_state_1.NodeSelection.create(tr.doc, pos);
474
+ if (view) {
475
+ view.focus();
476
+ }
477
+ dispatch(tr.setSelection(selection).scrollIntoView());
478
+ }
479
+ return true;
480
+ };
481
+ exports.insertContributors = insertContributors;
482
+ const insertKeywords = (state, dispatch, view) => {
483
+ if ((0, utils_1.getChildOfType)(state.doc, transform_1.schema.nodes.keywords, true)) {
484
+ return false;
485
+ }
486
+ const supplements = (0, prosemirror_utils_1.findChildrenByType)(state.doc, state.schema.nodes.supplements)[0];
487
+ const abstracts = (0, prosemirror_utils_1.findChildrenByType)(state.doc, state.schema.nodes.abstracts)[0];
488
+ let pos;
489
+ if (supplements) {
490
+ pos = supplements.pos + supplements.node.nodeSize;
491
+ }
492
+ else {
493
+ pos = abstracts.pos;
494
+ }
495
+ const keywords = transform_1.schema.nodes.keywords.createAndFill({}, [
496
+ transform_1.schema.nodes.section_title.create({}, transform_1.schema.text('Keywords')),
497
+ transform_1.schema.nodes.keywords_element.create({}, [
498
+ transform_1.schema.nodes.keyword_group.create({}, []),
499
+ ]),
500
+ ]);
501
+ const tr = state.tr.insert(pos, keywords);
502
+ if (dispatch) {
503
+ const selection = prosemirror_state_1.NodeSelection.create(tr.doc, pos);
504
+ if (view) {
505
+ view.focus();
506
+ }
507
+ dispatch(tr.setSelection(selection).scrollIntoView());
508
+ }
509
+ return true;
510
+ };
511
+ exports.insertKeywords = insertKeywords;
401
512
  const findRootList = ($pos) => {
402
513
  for (let i = 0; i < $pos.depth; i++) {
403
514
  const node = $pos.node(i);
@@ -464,7 +575,7 @@ const insertList = (type, style) => (state, dispatch, view) => {
464
575
  for (const { node, pos } of nodes) {
465
576
  tr.setNodeMarkup(pos, type, Object.assign(Object.assign({}, node.attrs), { listStyleType: style }), node.marks);
466
577
  }
467
- dispatch((0, track_changes_plugin_1.skipTracking)(tr));
578
+ dispatch(tr);
468
579
  return true;
469
580
  }
470
581
  else {
@@ -692,14 +803,17 @@ const addNodeComment = (node, state, dispatch) => {
692
803
  };
693
804
  const comment = transform_1.schema.nodes.comment.create(attrs);
694
805
  const comments = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.comments)[0];
695
- const pos = comments.pos + 1;
696
- const tr = state.tr.insert(pos, comment);
697
- const key = (0, comments_1.getCommentKey)(attrs, undefined, node);
698
- (0, comments_2.setCommentSelection)(tr, key, attrs.id, true);
699
- if (dispatch) {
700
- dispatch(tr);
806
+ if (comments) {
807
+ const pos = comments.pos + 1;
808
+ const tr = state.tr.insert(pos, comment);
809
+ const key = (0, comments_1.getCommentKey)(attrs, undefined, node);
810
+ (0, comments_2.setCommentSelection)(tr, key, attrs.id, true);
811
+ if (dispatch) {
812
+ dispatch(tr);
813
+ }
814
+ return true;
701
815
  }
702
- return true;
816
+ return false;
703
817
  };
704
818
  exports.addNodeComment = addNodeComment;
705
819
  const addInlineComment = (state, dispatch) => {
@@ -725,36 +839,39 @@ const addInlineComment = (state, dispatch) => {
725
839
  };
726
840
  const comment = transform_1.schema.nodes.comment.create(attrs);
727
841
  const comments = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.comments)[0];
728
- const pos = comments.pos + 1;
729
- const tr = state.tr.insert(pos, comment);
730
- if (from === to) {
731
- const point = transform_1.schema.nodes.highlight_marker.create({
732
- id: comment.attrs.id,
733
- tid: node.attrs.id,
734
- position: 'point',
735
- });
736
- tr.insert(from, point);
737
- }
738
- else {
739
- const start = transform_1.schema.nodes.highlight_marker.create({
740
- id: comment.attrs.id,
741
- tid: node.attrs.id,
742
- position: 'start',
743
- });
744
- const end = transform_1.schema.nodes.highlight_marker.create({
745
- id: comment.attrs.id,
746
- tid: node.attrs.id,
747
- position: 'end',
748
- });
749
- tr.insert(from, start).insert(to + 1, end);
750
- }
751
- const range = (0, comments_1.getCommentRange)(attrs);
752
- const key = (0, comments_1.getCommentKey)(attrs, range, node);
753
- (0, comments_2.setCommentSelection)(tr, key, attrs.id, true);
754
- if (dispatch) {
755
- dispatch(tr);
842
+ if (comments) {
843
+ const pos = comments.pos + 1;
844
+ const tr = state.tr.insert(pos, comment);
845
+ if (from === to) {
846
+ const point = transform_1.schema.nodes.highlight_marker.create({
847
+ id: comment.attrs.id,
848
+ tid: node.attrs.id,
849
+ position: 'point',
850
+ });
851
+ tr.insert(from, point);
852
+ }
853
+ else {
854
+ const start = transform_1.schema.nodes.highlight_marker.create({
855
+ id: comment.attrs.id,
856
+ tid: node.attrs.id,
857
+ position: 'start',
858
+ });
859
+ const end = transform_1.schema.nodes.highlight_marker.create({
860
+ id: comment.attrs.id,
861
+ tid: node.attrs.id,
862
+ position: 'end',
863
+ });
864
+ tr.insert(from, start).insert(to + 1, end);
865
+ }
866
+ const range = (0, comments_1.getCommentRange)(attrs);
867
+ const key = (0, comments_1.getCommentKey)(attrs, range, node);
868
+ (0, comments_2.setCommentSelection)(tr, key, attrs.id, true);
869
+ if (dispatch) {
870
+ dispatch(tr);
871
+ }
872
+ return true;
756
873
  }
757
- return true;
874
+ return false;
758
875
  };
759
876
  exports.addInlineComment = addInlineComment;
760
877
  const insertTableFootnote = (node, position, view, inlineFootnote) => {
@@ -27,16 +27,18 @@ const react_select_1 = __importDefault(require("react-select"));
27
27
  const styled_components_1 = __importDefault(require("styled-components"));
28
28
  const hierarchy_1 = require("../../lib/hierarchy");
29
29
  const node_type_icons_1 = require("../../node-type-icons");
30
- const optionName = (nodeType, depth) => {
30
+ const optionName = (nodeType, depth, listType) => {
31
31
  switch (nodeType) {
32
32
  case nodeType.schema.nodes.section:
33
33
  return (depth > 0 ? 'sub'.repeat(depth - 1) : '') + 'section heading';
34
+ case nodeType.schema.nodes.list:
35
+ return listType === 'order' ? 'Ordered List' : 'Bullet List';
34
36
  default:
35
37
  return transform_1.nodeNames.get(nodeType) || nodeType.name;
36
38
  }
37
39
  };
38
40
  const titleCase = (text) => text.replace(/\b([a-z])/g, (match) => match.toUpperCase());
39
- const buildOption = (props) => (Object.assign(Object.assign({}, props), { icon: (0, node_type_icons_1.nodeTypeIcon)(props.nodeType), label: titleCase(optionName(props.nodeType, props.depth)), isDisabled: Boolean(props.isDisabled), isSelected: Boolean(props.isSelected), isFocused: Boolean(props.isFocused) }));
41
+ const buildOption = (props) => (Object.assign(Object.assign({}, props), { icon: (0, node_type_icons_1.nodeTypeIcon)(props.nodeType, props.listType), label: titleCase(optionName(props.nodeType, props.depth, props.listType)), isDisabled: Boolean(props.isDisabled), isSelected: Boolean(props.isSelected), isFocused: Boolean(props.isFocused) }));
40
42
  const buildOptions = (state, dispatch, view) => {
41
43
  const { doc, selection: { $from, $to }, schema, tr, } = state;
42
44
  const { nodes } = schema;
@@ -189,12 +191,13 @@ const buildOptions = (state, dispatch, view) => {
189
191
  dispatch(tr.scrollIntoView());
190
192
  view && view.focus();
191
193
  };
192
- const convertParagraphToList = (nodeType) => () => {
194
+ const convertParagraphToList = (nodeType, listType) => () => {
193
195
  const paragraph = $from.node($from.depth);
194
196
  const beforeParagraph = $from.before($from.depth);
195
197
  const afterParagraph = $from.after($from.depth);
196
198
  const list = nodeType.create({
197
199
  id: (0, transform_1.generateNodeID)(nodeType),
200
+ listStyleType: listType,
198
201
  }, nodes.list_item.create({}, schema.nodes.paragraph.create({}, paragraph.content)));
199
202
  tr.replaceWith(beforeParagraph, afterParagraph, list);
200
203
  const anchor = beforeParagraph + 3;
@@ -202,8 +205,8 @@ const buildOptions = (state, dispatch, view) => {
202
205
  dispatch(tr.scrollIntoView());
203
206
  view && view.focus();
204
207
  };
205
- const convertListType = (nodeType, list) => () => {
206
- tr.setNodeMarkup(list.before, nodeType, list.node.attrs);
208
+ const convertListType = (nodeType, list, listType) => () => {
209
+ tr.setNodeMarkup(list.before, nodeType, Object.assign(Object.assign({}, list.node.attrs), { listStyleType: listType }));
207
210
  dispatch(tr.scrollIntoView());
208
211
  view && view.focus();
209
212
  };
@@ -225,16 +228,18 @@ const buildOptions = (state, dispatch, view) => {
225
228
  isDisabled: sectionDepth <= 1 && sectionOffset <= 1,
226
229
  }),
227
230
  buildOption({
228
- nodeType: nodes.ordered_list,
231
+ nodeType: nodes.list,
229
232
  value: -3,
230
233
  depth: 1,
231
234
  isDisabled: true,
235
+ listType: 'order',
232
236
  }),
233
237
  buildOption({
234
- nodeType: nodes.bullet_list,
238
+ nodeType: nodes.list,
235
239
  value: -2,
236
240
  depth: 1,
237
241
  isDisabled: true,
242
+ listType: 'bullet',
238
243
  }),
239
244
  ];
240
245
  const sectionOptions = [];
@@ -291,16 +296,18 @@ const buildOptions = (state, dispatch, view) => {
291
296
  isSelected: true,
292
297
  }),
293
298
  buildOption({
294
- nodeType: nodes.ordered_list,
299
+ nodeType: nodes.list,
295
300
  value: -3,
296
301
  depth: 1,
297
- action: convertParagraphToList(nodes.ordered_list),
302
+ action: convertParagraphToList(nodes.list, 'order'),
303
+ listType: 'order',
298
304
  }),
299
305
  buildOption({
300
- nodeType: nodes.bullet_list,
306
+ nodeType: nodes.list,
301
307
  value: -2,
302
308
  depth: 1,
303
- action: convertParagraphToList(nodes.bullet_list),
309
+ action: convertParagraphToList(nodes.list, 'bullet'),
310
+ listType: 'bullet',
304
311
  }),
305
312
  ];
306
313
  const sectionOptions = [];
@@ -326,7 +333,8 @@ const buildOptions = (state, dispatch, view) => {
326
333
  }));
327
334
  return [{ options: typeOptions }, { options: sectionOptions }];
328
335
  }
329
- case schema.nodes.bullet_list: {
336
+ case schema.nodes.list: {
337
+ const { style } = (0, transform_1.getListType)(parentElement.node.attrs.listStyleType);
330
338
  return [
331
339
  {
332
340
  options: [
@@ -342,35 +350,11 @@ const buildOptions = (state, dispatch, view) => {
342
350
  {
343
351
  options: [
344
352
  buildOption({
345
- nodeType: nodes.ordered_list,
353
+ nodeType: nodes.list,
346
354
  value: -3,
347
355
  depth: 1,
348
- action: convertListType(nodes.ordered_list, parentElement),
349
- }),
350
- ],
351
- },
352
- ];
353
- }
354
- case parentElementType.schema.nodes.ordered_list: {
355
- return [
356
- {
357
- options: [
358
- buildOption({
359
- nodeType: parentElementType,
360
- value: -4,
361
- depth: 1,
362
- isDisabled: true,
363
- isSelected: true,
364
- }),
365
- ],
366
- },
367
- {
368
- options: [
369
- buildOption({
370
- nodeType: nodes.bullet_list,
371
- value: -3,
372
- depth: 1,
373
- action: convertListType(nodes.bullet_list, parentElement),
356
+ action: convertListType(nodes.list, parentElement, style),
357
+ listType: style === 'none' || style === 'disc' ? 'bullet' : 'order',
374
358
  }),
375
359
  ],
376
360
  },
@@ -458,7 +442,7 @@ const LevelSelector = ({ state, dispatch, view }) => {
458
442
  style.opacity = 0.4;
459
443
  }
460
444
  return (react_1.default.createElement(OptionContainer, Object.assign({}, props.innerProps, { ref: null, style: style }),
461
- react_1.default.createElement(OptionIcon, null, (0, node_type_icons_1.nodeTypeIcon)(data.nodeType)),
445
+ react_1.default.createElement(OptionIcon, null, (0, node_type_icons_1.nodeTypeIcon)(data.nodeType, data.listType)),
462
446
  react_1.default.createElement(OptionLabel, null, data.label)));
463
447
  },
464
448
  }, onChange: (value) => {
@@ -21,7 +21,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  const affiliations_1 = __importDefault(require("../views/affiliations"));
22
22
  const bibliography_element_editable_1 = __importDefault(require("../views/bibliography_element_editable"));
23
23
  const blockquote_element_editable_1 = __importDefault(require("../views/blockquote_element_editable"));
24
- const bullet_list_editable_1 = __importDefault(require("../views/bullet_list_editable"));
25
24
  const citation_editable_1 = __importDefault(require("../views/citation_editable"));
26
25
  const contributors_1 = __importDefault(require("../views/contributors"));
27
26
  const cross_reference_editable_1 = __importDefault(require("../views/cross_reference_editable"));
@@ -37,10 +36,10 @@ const inline_footnote_editable_1 = __importDefault(require("../views/inline_foot
37
36
  const keyword_1 = __importDefault(require("../views/keyword"));
38
37
  const keyword_group_1 = __importDefault(require("../views/keyword_group"));
39
38
  const link_editable_1 = __importDefault(require("../views/link_editable"));
39
+ const list_1 = __importDefault(require("../views/list"));
40
40
  const list_item_1 = __importDefault(require("../views/list_item"));
41
41
  const listing_editable_1 = __importDefault(require("../views/listing_editable"));
42
42
  const listing_element_editable_1 = __importDefault(require("../views/listing_element_editable"));
43
- const ordered_list_editable_1 = __importDefault(require("../views/ordered_list_editable"));
44
43
  const paragraph_editable_1 = __importDefault(require("../views/paragraph_editable"));
45
44
  const placeholder_1 = __importDefault(require("../views/placeholder"));
46
45
  const placeholder_element_editable_1 = __importDefault(require("../views/placeholder_element_editable"));
@@ -56,7 +55,7 @@ exports.default = (props, dispatch) => {
56
55
  title: (0, title_editable_1.default)(props, dispatch),
57
56
  bibliography_element: (0, bibliography_element_editable_1.default)(props, dispatch),
58
57
  blockquote_element: (0, blockquote_element_editable_1.default)(props),
59
- bullet_list: (0, bullet_list_editable_1.default)(props),
58
+ list: (0, list_1.default)(props),
60
59
  citation: (0, citation_editable_1.default)(props, dispatch),
61
60
  cross_reference: (0, cross_reference_editable_1.default)(props, dispatch),
62
61
  contributors: (0, contributors_1.default)(props, dispatch),
@@ -75,7 +74,6 @@ exports.default = (props, dispatch) => {
75
74
  listing: (0, listing_editable_1.default)(props),
76
75
  listing_element: (0, listing_element_editable_1.default)(props),
77
76
  list_item: (0, list_item_1.default)(props),
78
- ordered_list: (0, ordered_list_editable_1.default)(props),
79
77
  paragraph: (0, paragraph_editable_1.default)(props),
80
78
  placeholder: (0, placeholder_1.default)(props),
81
79
  placeholder_element: (0, placeholder_element_editable_1.default)(props),
@@ -15,12 +15,15 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.skipCommandTracking = void 0;
18
+ exports.sinkListItem = exports.skipCommandTracking = void 0;
19
19
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
20
20
  const transform_1 = require("@manuscripts/transform");
21
21
  const prosemirror_commands_1 = require("prosemirror-commands");
22
+ const prosemirror_model_1 = require("prosemirror-model");
22
23
  const prosemirror_schema_list_1 = require("prosemirror-schema-list");
24
+ const prosemirror_transform_1 = require("prosemirror-transform");
23
25
  const prosemirror_utils_1 = require("prosemirror-utils");
26
+ const track_changes_utils_1 = require("../lib/track-changes-utils");
24
27
  const skipCommandTracking = (command) => (state, dispatch) => {
25
28
  return command(state, (tr) => {
26
29
  if (dispatch) {
@@ -56,14 +59,44 @@ const liftToOuterList = (itemType) => {
56
59
  }
57
60
  };
58
61
  };
62
+ function sinkListItem(itemType) {
63
+ return function (state, dispatch) {
64
+ const { $from, $to } = state.selection;
65
+ const range = $from.blockRange($to, (node) => { var _a; return node.childCount > 0 && ((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.type) == itemType; });
66
+ if (!range) {
67
+ return false;
68
+ }
69
+ const startIndex = range.startIndex;
70
+ if (startIndex == 0) {
71
+ return false;
72
+ }
73
+ const parent = range.parent, nodeBefore = parent.child(startIndex - 1);
74
+ if (nodeBefore.type != itemType) {
75
+ return false;
76
+ }
77
+ if (dispatch) {
78
+ const nestedBefore = nodeBefore.lastChild && nodeBefore.lastChild.type == parent.type;
79
+ const actualAttrs = (0, track_changes_utils_1.getActualAttrs)(parent);
80
+ const listType = actualAttrs.listStyleType;
81
+ const inner = prosemirror_model_1.Fragment.from(nestedBefore ? itemType.create() : null);
82
+ const slice = new prosemirror_model_1.Slice(prosemirror_model_1.Fragment.from(itemType.create(null, prosemirror_model_1.Fragment.from(parent.type.create({ listStyleType: listType }, inner)))), nestedBefore ? 3 : 1, 0);
83
+ const before = range.start, after = range.end;
84
+ dispatch(state.tr
85
+ .step(new prosemirror_transform_1.ReplaceAroundStep(before - (nestedBefore ? 3 : 1), after, before, after, slice, 1, true))
86
+ .scrollIntoView());
87
+ }
88
+ return true;
89
+ };
90
+ }
91
+ exports.sinkListItem = sinkListItem;
59
92
  const listKeymap = {
60
93
  Enter: (0, prosemirror_schema_list_1.splitListItem)(transform_1.schema.nodes.list_item),
61
94
  'Mod-[': (0, exports.skipCommandTracking)(liftToOuterList(transform_1.schema.nodes.list_item)),
62
- 'Mod-]': (0, exports.skipCommandTracking)((0, prosemirror_schema_list_1.sinkListItem)(transform_1.schema.nodes.list_item)),
63
- 'Mod-Alt-o': (0, exports.skipCommandTracking)((0, prosemirror_schema_list_1.wrapInList)(transform_1.schema.nodes.ordered_list)),
64
- 'Mod-Alt-k': (0, exports.skipCommandTracking)((0, prosemirror_schema_list_1.wrapInList)(transform_1.schema.nodes.bullet_list)),
95
+ 'Mod-]': (0, exports.skipCommandTracking)(sinkListItem(transform_1.schema.nodes.list_item)),
96
+ 'Mod-Alt-o': (0, exports.skipCommandTracking)((0, prosemirror_schema_list_1.wrapInList)(transform_1.schema.nodes.list, { listStyleType: 'order' })),
97
+ 'Mod-Alt-k': (0, exports.skipCommandTracking)((0, prosemirror_schema_list_1.wrapInList)(transform_1.schema.nodes.list, { listStyleType: 'bullet' })),
65
98
  'Shift-Tab': (0, exports.skipCommandTracking)(liftToOuterList(transform_1.schema.nodes.list_item)),
66
- Tab: (0, exports.skipCommandTracking)((0, prosemirror_schema_list_1.sinkListItem)(transform_1.schema.nodes.list_item)),
99
+ Tab: (0, exports.skipCommandTracking)(sinkListItem(transform_1.schema.nodes.list_item)),
67
100
  Backspace: (0, exports.skipCommandTracking)(listItemBackward),
68
101
  };
69
102
  exports.default = listKeymap;