@manuscripts/body-editor 1.6.8 → 1.6.10-LEAN-3180

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 (75) hide show
  1. package/dist/cjs/citation-sources/crossref.js +27 -54
  2. package/dist/cjs/commands.js +4 -4
  3. package/dist/cjs/components/keywords/DeleteKeywordDialog.js +46 -0
  4. package/dist/cjs/configs/editor-plugins.js +0 -2
  5. package/dist/cjs/configs/editor-views.js +7 -7
  6. package/dist/cjs/index.js +0 -1
  7. package/dist/cjs/lib/context-menu.js +4 -2
  8. package/dist/cjs/plugins/bibliography/index.js +11 -1
  9. package/dist/cjs/plugins/sections.js +4 -1
  10. package/dist/cjs/testing/default-editor-data.js +0 -22
  11. package/dist/cjs/views/CitationEditorWrapper.js +51 -0
  12. package/dist/cjs/views/ReferencesEditor.js +52 -0
  13. package/dist/cjs/views/base_node_view.js +1 -1
  14. package/dist/cjs/views/bibliography_element.js +20 -27
  15. package/dist/cjs/views/citation.js +1 -72
  16. package/dist/cjs/views/citation_editable.js +91 -106
  17. package/dist/cjs/views/cross_reference_editable.js +12 -10
  18. package/dist/cjs/views/keyword.js +58 -2
  19. package/dist/cjs/views/{keywords_element.js → keyword_group.js} +10 -13
  20. package/dist/cjs/views/link_editable.js +42 -34
  21. package/dist/es/citation-sources/crossref.js +27 -54
  22. package/dist/es/commands.js +4 -4
  23. package/dist/es/components/keywords/DeleteKeywordDialog.js +19 -0
  24. package/dist/es/configs/editor-plugins.js +0 -2
  25. package/dist/es/configs/editor-views.js +7 -7
  26. package/dist/es/index.js +0 -1
  27. package/dist/es/lib/context-menu.js +4 -2
  28. package/dist/es/plugins/bibliography/index.js +11 -1
  29. package/dist/es/plugins/sections.js +4 -1
  30. package/dist/es/testing/default-editor-data.js +0 -22
  31. package/dist/es/views/CitationEditorWrapper.js +24 -0
  32. package/dist/es/views/ReferencesEditor.js +25 -0
  33. package/dist/es/views/base_node_view.js +1 -1
  34. package/dist/es/views/bibliography_element.js +21 -28
  35. package/dist/es/views/citation.js +1 -49
  36. package/dist/es/views/citation_editable.js +92 -107
  37. package/dist/es/views/cross_reference_editable.js +12 -10
  38. package/dist/es/views/keyword.js +55 -2
  39. package/dist/es/views/{keywords_element.js → keyword_group.js} +8 -11
  40. package/dist/es/views/link_editable.js +42 -34
  41. package/dist/types/citation-sources/crossref.d.ts +2 -11
  42. package/dist/types/commands.d.ts +3 -3
  43. package/dist/types/components/keywords/DeleteKeywordDialog.d.ts +6 -0
  44. package/dist/types/components/views/LinkForm.d.ts +2 -2
  45. package/dist/types/configs/ManuscriptsEditor.d.ts +1 -6
  46. package/dist/types/configs/editor-plugins.d.ts +1 -2
  47. package/dist/types/configs/editor-views.d.ts +3 -5
  48. package/dist/types/index.d.ts +0 -1
  49. package/dist/types/lib/context-menu.d.ts +1 -1
  50. package/dist/types/plugins/bibliography/index.d.ts +1 -1
  51. package/dist/types/views/CitationEditorWrapper.d.ts +3 -0
  52. package/dist/types/views/ReferencesEditor.d.ts +4 -0
  53. package/dist/types/views/base_node_view.d.ts +0 -3
  54. package/dist/types/views/bibliography_element.d.ts +6 -5
  55. package/dist/types/views/citation.d.ts +2 -14
  56. package/dist/types/views/citation_editable.d.ts +12 -6
  57. package/dist/types/views/cross_reference.d.ts +0 -1
  58. package/dist/types/views/editable_block.d.ts +2 -4
  59. package/dist/types/views/keyword.d.ts +9 -9
  60. package/dist/types/{plugins/keywords.d.ts → views/keyword_group.d.ts} +9 -11
  61. package/dist/types/views/link_editable.d.ts +3 -0
  62. package/package.json +2 -2
  63. package/styles/AdvancedEditor.css +40 -35
  64. package/dist/cjs/components/keywords/DeleteKeyword.js +0 -92
  65. package/dist/cjs/plugins/keywords.js +0 -121
  66. package/dist/cjs/plugins/models.js +0 -48
  67. package/dist/cjs/views/ReactView.js +0 -94
  68. package/dist/es/components/keywords/DeleteKeyword.js +0 -65
  69. package/dist/es/plugins/keywords.js +0 -115
  70. package/dist/es/plugins/models.js +0 -45
  71. package/dist/es/views/ReactView.js +0 -66
  72. package/dist/types/components/keywords/DeleteKeyword.d.ts +0 -10
  73. package/dist/types/plugins/models.d.ts +0 -28
  74. package/dist/types/views/ReactView.d.ts +0 -33
  75. package/dist/types/views/keywords_element.d.ts +0 -39
@@ -14,71 +14,44 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
17
  var __importDefault = (this && this.__importDefault) || function (mod) {
27
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
28
19
  };
29
20
  Object.defineProperty(exports, "__esModule", { value: true });
30
21
  exports.crossref = void 0;
31
22
  const library_1 = require("@manuscripts/library");
23
+ const transform_1 = require("@manuscripts/transform");
32
24
  const axios_1 = __importDefault(require("axios"));
33
- const search = (query, rows, mailto, tokenSource) => __awaiter(void 0, void 0, void 0, function* () {
34
- if (query.trim().match(/^10\.\S+\/\S+$/)) {
35
- return searchByDOI(query.trim(), mailto);
36
- }
37
- const response = yield axios_1.default.get(`https://api.crossref.org/works?mailto=${mailto}`, {
25
+ const search = (query, limit) => {
26
+ const controller = new AbortController();
27
+ const response = axios_1.default
28
+ .get(`https://api.crossref.org/works`, {
38
29
  params: {
39
30
  filter: 'type:journal-article',
40
31
  query,
41
- rows,
32
+ rows: limit,
42
33
  },
43
- cancelToken: tokenSource,
34
+ signal: controller.signal,
35
+ })
36
+ .then((r) => {
37
+ if (r.status !== 200) {
38
+ throw new Error('There was a problem searching for this query.');
39
+ }
40
+ const items = r.data.message.items;
41
+ const total = r.data.message['total-results'];
42
+ return {
43
+ items: items.map((i) => (0, transform_1.buildBibliographyItem)((0, library_1.convertCSLToBibliographyItem)(i))),
44
+ total,
45
+ };
44
46
  });
45
- if (response.status !== 200) {
46
- throw new Error('There was a problem searching for this query.');
47
- }
48
- const { message: { items, 'total-results': total }, } = response.data;
49
- return {
50
- items: items.map(library_1.convertCSLToBibliographyItem),
51
- total,
52
- };
53
- });
54
- const searchByDOI = (doi, mailto) => __awaiter(void 0, void 0, void 0, function* () {
55
- const response = yield axios_1.default.get(`https://api.crossref.org/works/${encodeURIComponent(doi)}?mailto=${mailto}`);
56
- if (response.status === 404) {
57
- throw new Error('An item with this DOI could not be found.');
58
- }
59
- if (response.status !== 200) {
60
- throw new Error('There was a problem searching for this DOI.');
61
- }
62
- const { message } = response.data;
63
- const item = (0, library_1.convertCSLToBibliographyItem)(message);
64
47
  return {
65
- items: [item],
66
- total: 1,
48
+ response: response,
49
+ cancel: () => controller.abort(),
50
+ isCancelled: controller.signal.aborted,
67
51
  };
68
- });
69
- const fetch = (item) => __awaiter(void 0, void 0, void 0, function* () {
70
- if (!item.DOI) {
71
- throw new Error('The item does not have a DOI');
72
- }
73
- const response = yield axios_1.default.get(`https://api.crossref.org/works/${encodeURIComponent(item.DOI)}/transform/application/vnd.citationstyles.csl+json`, {
74
- headers: {},
75
- });
76
- if (response.status === 404) {
77
- throw new Error('An item with this DOI could not be found.');
78
- }
79
- if (response.status !== 200) {
80
- throw new Error('There was a problem fetching this DOI.');
81
- }
82
- return (0, library_1.convertCSLToBibliographyItem)(response.data);
83
- });
84
- exports.crossref = { fetch, search };
52
+ };
53
+ exports.crossref = {
54
+ id: 'crossref',
55
+ label: 'External sources',
56
+ search,
57
+ };
@@ -231,7 +231,7 @@ const insertLink = (state, dispatch) => {
231
231
  return true;
232
232
  };
233
233
  exports.insertLink = insertLink;
234
- const insertInlineCitation = (state, dispatch, view) => {
234
+ const insertInlineCitation = (state, dispatch) => {
235
235
  const node = state.schema.nodes.citation.create({
236
236
  id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.Citation),
237
237
  rids: [],
@@ -313,11 +313,11 @@ const insertGraphicalAbstract = (state, dispatch) => {
313
313
  return false;
314
314
  }
315
315
  const abstracts = (0, prosemirror_utils_1.findChildrenByType)(state.doc, transform_1.schema.nodes.abstracts)[0];
316
+ const pos = abstracts.pos + abstracts.node.content.size + 1;
316
317
  const section = transform_1.schema.nodes.graphical_abstract_section.createAndFill({ category: 'MPSectionCategory:abstract-graphical' }, [
317
318
  transform_1.schema.nodes.section_title.create({}, transform_1.schema.text('Graphical Abstract')),
318
319
  createAndFillFigureElement(state),
319
320
  ]);
320
- const pos = abstracts.pos + abstracts.node.nodeSize + 1;
321
321
  const tr = state.tr.insert(pos, section);
322
322
  if (dispatch) {
323
323
  const selection = prosemirror_state_1.TextSelection.create(tr.doc, pos + 1);
@@ -340,11 +340,11 @@ const insertSection = (subsection = false) => (state, dispatch) => {
340
340
  return true;
341
341
  };
342
342
  exports.insertSection = insertSection;
343
- const insertBibliographySection = (state, dispatch) => {
343
+ const insertBibliographySection = () => {
344
344
  return false;
345
345
  };
346
346
  exports.insertBibliographySection = insertBibliographySection;
347
- const insertTOCSection = (state, dispatch) => {
347
+ const insertTOCSection = () => {
348
348
  return false;
349
349
  };
350
350
  exports.insertTOCSection = insertTOCSection;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.DeleteKeywordDialog = void 0;
27
+ const style_guide_1 = require("@manuscripts/style-guide");
28
+ const react_1 = __importStar(require("react"));
29
+ const DeleteKeywordDialog = ({ keyword, handleDelete, }) => {
30
+ const [isOpen, setOpen] = (0, react_1.useState)(true);
31
+ return (react_1.default.createElement(style_guide_1.Dialog, { isOpen: isOpen, actions: {
32
+ primary: {
33
+ action: () => setOpen(false),
34
+ title: 'Cancel',
35
+ },
36
+ secondary: {
37
+ action: () => {
38
+ setOpen(false);
39
+ handleDelete();
40
+ },
41
+ title: 'Delete',
42
+ },
43
+ }, category: style_guide_1.Category.confirmation, header: 'Delete Keyword', message: `Are you sure you want to delete "${keyword}" keyword?
44
+ ` }));
45
+ };
46
+ exports.DeleteKeywordDialog = DeleteKeywordDialog;
@@ -30,7 +30,6 @@ const comment_annotation_1 = __importDefault(require("../plugins/comment_annotat
30
30
  const elements_1 = __importDefault(require("../plugins/elements"));
31
31
  const footnotes_1 = __importDefault(require("../plugins/footnotes"));
32
32
  const highlight_1 = __importDefault(require("../plugins/highlight"));
33
- const keywords_1 = __importDefault(require("../plugins/keywords"));
34
33
  const objects_1 = __importDefault(require("../plugins/objects"));
35
34
  const paragraphs_1 = __importDefault(require("../plugins/paragraphs"));
36
35
  const persist_1 = __importDefault(require("../plugins/persist"));
@@ -54,7 +53,6 @@ exports.default = (props) => {
54
53
  (0, persist_1.default)(),
55
54
  (0, sections_1.default)(),
56
55
  (0, toc_1.default)(props),
57
- (0, keywords_1.default)(props),
58
56
  (0, bibliography_1.default)(props),
59
57
  (0, objects_1.default)(props),
60
58
  (0, comment_annotation_1.default)(props),
@@ -34,7 +34,7 @@ const footnotes_element_1 = __importDefault(require("../views/footnotes_element"
34
34
  const inline_equation_editable_1 = __importDefault(require("../views/inline_equation_editable"));
35
35
  const inline_footnote_editable_1 = __importDefault(require("../views/inline_footnote_editable"));
36
36
  const keyword_1 = __importDefault(require("../views/keyword"));
37
- const keywords_element_1 = __importDefault(require("../views/keywords_element"));
37
+ const keyword_group_1 = __importDefault(require("../views/keyword_group"));
38
38
  const link_editable_1 = __importDefault(require("../views/link_editable"));
39
39
  const listing_editable_1 = __importDefault(require("../views/listing_editable"));
40
40
  const listing_element_editable_1 = __importDefault(require("../views/listing_element_editable"));
@@ -51,11 +51,11 @@ const toc_element_editable_1 = __importDefault(require("../views/toc_element_edi
51
51
  exports.default = (props, dispatch) => {
52
52
  return {
53
53
  title: (0, title_editable_1.default)(props, dispatch),
54
- bibliography_element: (0, bibliography_element_editable_1.default)(props),
54
+ bibliography_element: (0, bibliography_element_editable_1.default)(props, dispatch),
55
55
  blockquote_element: (0, blockquote_element_editable_1.default)(props),
56
56
  bullet_list: (0, bullet_list_editable_1.default)(props),
57
- citation: (0, citation_editable_1.default)(props),
58
- cross_reference: (0, cross_reference_editable_1.default)(props),
57
+ citation: (0, citation_editable_1.default)(props, dispatch),
58
+ cross_reference: (0, cross_reference_editable_1.default)(props, dispatch),
59
59
  contributors: (0, contributors_1.default)(props, dispatch),
60
60
  equation: (0, equation_editable_1.default)(props),
61
61
  equation_element: (0, equation_element_editable_1.default)(props),
@@ -65,9 +65,9 @@ exports.default = (props, dispatch) => {
65
65
  footnotes_element: (0, footnotes_element_1.default)(props),
66
66
  inline_equation: (0, inline_equation_editable_1.default)(props),
67
67
  inline_footnote: (0, inline_footnote_editable_1.default)(props),
68
- keyword: (0, keyword_1.default)(props),
69
- keywords_element: (0, keywords_element_1.default)(props, dispatch),
70
- link: (0, link_editable_1.default)(props),
68
+ keyword: (0, keyword_1.default)(props, dispatch),
69
+ keyword_group: (0, keyword_group_1.default)(props, dispatch),
70
+ link: (0, link_editable_1.default)(props, dispatch),
71
71
  listing: (0, listing_editable_1.default)(props),
72
72
  listing_element: (0, listing_element_editable_1.default)(props),
73
73
  ordered_list: (0, ordered_list_editable_1.default)(props),
package/dist/cjs/index.js CHANGED
@@ -56,6 +56,5 @@ var comment_annotation_1 = require("./plugins/comment_annotation");
56
56
  Object.defineProperty(exports, "commentScroll", { enumerable: true, get: function () { return comment_annotation_1.commentScroll; } });
57
57
  Object.defineProperty(exports, "isThereSelector", { enumerable: true, get: function () { return comment_annotation_1.isThereSelector; } });
58
58
  Object.defineProperty(exports, "isHighlightComment", { enumerable: true, get: function () { return comment_annotation_1.isHighlightComment; } });
59
- __exportStar(require("./plugins/keywords"), exports);
60
59
  __exportStar(require("./lib/utils"), exports);
61
60
  __exportStar(require("./useEditor"), exports);
@@ -286,7 +286,9 @@ class ContextMenu {
286
286
  switch (nodeType.name) {
287
287
  case 'section_title': {
288
288
  const $pos = this.resolvePos();
289
- this.view.dispatch(this.view.state.tr.delete($pos.before(), $pos.after()));
289
+ this.view.dispatch(this.view.state.tr
290
+ .setMeta('fromContextMenu', true)
291
+ .delete($pos.before(), $pos.after()));
290
292
  break;
291
293
  }
292
294
  case 'bibliography_element': {
@@ -354,7 +356,7 @@ class ContextMenu {
354
356
  window.addEventListener('keydown', keyListener);
355
357
  };
356
358
  this.trimTitle = (title, max) => {
357
- return title.length > max ? title.substr(0, max) + '…' : title;
359
+ return title.length > max ? title.substring(0, max) + '…' : title;
358
360
  };
359
361
  this.node = node;
360
362
  this.view = view;
@@ -63,17 +63,27 @@ const buildBibliographyPluginState = (doc, csl, $old) => {
63
63
  if (!csl.style) {
64
64
  return $new;
65
65
  }
66
- if ($old && (0, lodash_1.isEqual)(citations, $old.citations)) {
66
+ if ($old &&
67
+ (0, lodash_1.isEqual)(citations, $old.citations) &&
68
+ (0, lodash_1.isEqual)(modelMap, $old.bibliographyItems)) {
69
+ $new.citationCounts = $old.citationCounts;
67
70
  $new.provider = $old.provider;
68
71
  $new.renderedCitations = $old.renderedCitations;
69
72
  }
70
73
  else {
74
+ const citationCounts = new Map();
75
+ const rids = nodes.flatMap((e) => e[0].attrs.rids);
76
+ rids.forEach((rid) => {
77
+ const count = citationCounts.get(rid) || 0;
78
+ citationCounts.set(rid, count + 1);
79
+ });
71
80
  const provider = new library_1.CitationProvider({
72
81
  getLibraryItem: (id) => modelMap.get(id),
73
82
  citationStyle: csl.style || '',
74
83
  locale: csl.locale,
75
84
  });
76
85
  const citationTexts = provider.rebuildState((0, bibliography_utils_1.buildCitations)(nodes));
86
+ $new.citationCounts = citationCounts;
77
87
  $new.provider = provider;
78
88
  $new.renderedCitations = new Map(citationTexts.map((i) => [i[0], i[2]]));
79
89
  }
@@ -23,6 +23,9 @@ const highlight_1 = require("./highlight");
23
23
  const preventTitleEdit = (tr) => {
24
24
  let dontPrevent = true;
25
25
  const isInRange = (start, end, position) => position >= start && position <= end;
26
+ if (tr.getMeta('fromContextMenu')) {
27
+ return dontPrevent;
28
+ }
26
29
  if (tr.getMeta('origin') === track_changes_plugin_1.trackChangesPluginKey) {
27
30
  return dontPrevent;
28
31
  }
@@ -47,7 +50,7 @@ const preventTitleEdit = (tr) => {
47
50
  (isInRange(inDocPos, inDocPos + childNode.nodeSize, toA) ||
48
51
  isInRange(inDocPos, inDocPos + childNode.nodeSize, fromA))) {
49
52
  dontPrevent = false;
50
- return false;
53
+ return dontPrevent;
51
54
  }
52
55
  });
53
56
  }
@@ -22,8 +22,6 @@ exports.defaultEditorProps = exports.TEST_DATA = void 0;
22
22
  const style_guide_1 = require("@manuscripts/style-guide");
23
23
  const transform_1 = require("@manuscripts/transform");
24
24
  const history_1 = require("history");
25
- const lodash_1 = require("lodash");
26
- const react_dom_1 = __importDefault(require("react-dom"));
27
25
  const popper_1 = require("../lib/popper");
28
26
  const empty_editor_doc_json_1 = __importDefault(require("./empty-editor-doc.json"));
29
27
  const theme = {};
@@ -70,10 +68,6 @@ exports.defaultEditorProps = {
70
68
  projectID: 'test-project-id',
71
69
  getCurrentUser: () => exports.TEST_DATA.USER,
72
70
  history: (0, history_1.createBrowserHistory)(),
73
- renderReactComponent: (child, container) => {
74
- react_dom_1.default.render(child, container);
75
- },
76
- unmountReactComponent: react_dom_1.default.unmountComponentAtNode,
77
71
  theme,
78
72
  getFiles: () => [],
79
73
  fileManagement: {
@@ -89,29 +83,13 @@ exports.defaultEditorProps = {
89
83
  },
90
84
  getCitationProvider: () => undefined,
91
85
  plugins: [],
92
- saveModel: (model) => {
93
- var _a, _b;
94
- const id = (_a = model._id) !== null && _a !== void 0 ? _a : '';
95
- const oldModel = (_b = exports.TEST_DATA.MODEL_MAP.get(id)) !== null && _b !== void 0 ? _b : {};
96
- const updatedModel = Object.assign(Object.assign({ createdAt: Date.now() / 1000, updatedAt: Date.now() / 1000, _id: (0, lodash_1.uniqueId)() }, oldModel), model);
97
- exports.TEST_DATA.MODEL_MAP.set(id, updatedModel);
98
- return Promise.resolve(updatedModel);
99
- },
100
86
  deleteModel: (id) => {
101
87
  exports.TEST_DATA.MODEL_MAP.delete(id);
102
88
  return Promise.resolve(id);
103
89
  },
104
- getLibraryItem: () => undefined,
105
- setLibraryItem: () => undefined,
106
- matchLibraryItemByIdentifier: () => undefined,
107
- filterLibraryItems: () => Promise.resolve([]),
108
- removeLibraryItem: () => undefined,
109
90
  retrySync: () => Promise.resolve(),
110
91
  setComment: () => undefined,
111
92
  setSelectedComment: () => undefined,
112
93
  setEditorSelectedSuggestion: () => undefined,
113
- components: {},
114
94
  environment: undefined,
115
- setCiteprocCitations: () => undefined,
116
- getCiteprocCitations: () => new Map(),
117
95
  };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.CitationEditorWrapper = void 0;
27
+ const style_guide_1 = require("@manuscripts/style-guide");
28
+ const react_1 = __importStar(require("react"));
29
+ const CitationEditorWrapper = (props) => {
30
+ const [items, setItems] = (0, react_1.useState)(props.items);
31
+ const handleSave = (item) => {
32
+ props.onSave(item);
33
+ setItems((s) => {
34
+ const copy = [...s];
35
+ const index = copy.findIndex((i) => i._id === item._id);
36
+ if (index >= 0) {
37
+ copy[index] = item;
38
+ }
39
+ else {
40
+ copy.push(item);
41
+ }
42
+ return copy;
43
+ });
44
+ };
45
+ const handleDelete = (item) => {
46
+ props.onDelete(item);
47
+ setItems((s) => s.filter((i) => i._id !== item._id));
48
+ };
49
+ return (react_1.default.createElement(style_guide_1.CitationEditor, Object.assign({}, props, { items: items, onSave: handleSave, onDelete: handleDelete })));
50
+ };
51
+ exports.CitationEditorWrapper = CitationEditorWrapper;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ReferencesEditor = void 0;
27
+ const style_guide_1 = require("@manuscripts/style-guide");
28
+ const react_1 = __importStar(require("react"));
29
+ const ReferencesEditor = (props) => {
30
+ const [isOpen, setOpen] = (0, react_1.useState)(true);
31
+ const [items, setItems] = (0, react_1.useState)(props.items);
32
+ const handleSave = (item) => {
33
+ props.onSave(item);
34
+ setItems((s) => {
35
+ const copy = [...s];
36
+ const index = copy.findIndex((i) => i._id === item._id);
37
+ if (index >= 0) {
38
+ copy[index] = item;
39
+ }
40
+ else {
41
+ copy.push(item);
42
+ }
43
+ return copy;
44
+ });
45
+ };
46
+ const handleDelete = (item) => {
47
+ props.onDelete(item);
48
+ setItems((s) => s.filter((i) => i._id !== item._id));
49
+ };
50
+ return (react_1.default.createElement(style_guide_1.ReferencesModal, Object.assign({}, props, { isOpen: isOpen, onCancel: () => setOpen(false), items: items, onSave: handleSave, onDelete: handleDelete })));
51
+ };
52
+ exports.ReferencesEditor = ReferencesEditor;
@@ -75,7 +75,7 @@ class BaseNodeView {
75
75
  };
76
76
  this.deleteNode = (id) => {
77
77
  this.view.state.doc.descendants((node, pos) => {
78
- if ((node.attrs.id || node.attrs.rid) === id) {
78
+ if (node.attrs.id === id) {
79
79
  this.view.dispatch(this.view.state.tr.delete(pos, pos + node.nodeSize));
80
80
  }
81
81
  });
@@ -23,17 +23,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
23
  step((generator = generator.apply(thisArg, _arguments || [])).next());
24
24
  });
25
25
  };
26
- var __rest = (this && this.__rest) || function (s, e) {
27
- var t = {};
28
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
29
- t[p] = s[p];
30
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
31
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
32
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
33
- t[p[i]] = s[p[i]];
34
- }
35
- return t;
36
- };
37
26
  var __importDefault = (this && this.__importDefault) || function (mod) {
38
27
  return (mod && mod.__esModule) ? mod : { "default": mod };
39
28
  };
@@ -41,7 +30,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
41
30
  exports.BibliographyElementBlockView = void 0;
42
31
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
43
32
  const transform_1 = require("@manuscripts/transform");
44
- const react_1 = __importDefault(require("react"));
45
33
  const assets_1 = require("../assets");
46
34
  const dompurify_1 = require("../lib/dompurify");
47
35
  const bibliography_1 = require("../plugins/bibliography");
@@ -49,25 +37,24 @@ const comment_annotation_1 = require("../plugins/comment_annotation");
49
37
  const tracking_mark_1 = require("../plugins/tracking-mark");
50
38
  const block_view_1 = __importDefault(require("./block_view"));
51
39
  const creators_1 = require("./creators");
40
+ const ReactSubView_1 = __importDefault(require("./ReactSubView"));
41
+ const ReferencesEditor_1 = require("./ReferencesEditor");
52
42
  class BibliographyElementBlockView extends block_view_1.default {
53
43
  constructor() {
54
44
  super(...arguments);
45
+ this.decoder = new transform_1.Decoder(new Map());
55
46
  this.gutterButtons = () => [];
56
- this.showPopper = (referenceID) => {
57
- const { renderReactComponent, components: { ReferencesEditor }, } = this.props;
58
- const handleSave = (data) => __awaiter(this, void 0, void 0, function* () {
59
- const _a = data, { _id: id, 'container-title': containerTitle, DOI: doi } = _a, rest = __rest(_a, ["_id", 'container-title', "DOI"]);
60
- this.updateNodeAttrs(Object.assign({ id,
61
- containerTitle,
62
- doi }, rest));
63
- });
64
- if (!this.popperContainer) {
65
- this.popperContainer = document.createElement('div');
66
- this.popperContainer.className = 'references';
67
- }
47
+ this.showPopper = (id) => {
68
48
  const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
69
- renderReactComponent(react_1.default.createElement(ReferencesEditor, { saveModel: handleSave, deleteModel: this.deleteNode, modelMap: bib.bibliographyItems, referenceID: referenceID }), this.popperContainer);
70
- this.props.popper.show(this.dom, this.popperContainer, 'right');
49
+ const componentProps = {
50
+ items: Array.from(bib.bibliographyItems.values()),
51
+ citationCounts: bib.citationCounts,
52
+ item: bib.bibliographyItems.get(id),
53
+ onSave: this.handleSave,
54
+ onDelete: this.handleDelete,
55
+ };
56
+ this.editor = (0, ReactSubView_1.default)(this.props, ReferencesEditor_1.ReferencesEditor, componentProps, this.node, this.getPos, this.view, 'references-modal');
57
+ this.props.popper.show(this.dom, this.editor, 'right');
71
58
  };
72
59
  this.stopEvent = () => true;
73
60
  this.ignoreMutation = () => true;
@@ -112,7 +99,6 @@ class BibliographyElementBlockView extends block_view_1.default {
112
99
  editButton.addEventListener('click', (e) => {
113
100
  e.preventDefault();
114
101
  this.showPopper(element.id);
115
- this.popperContainer = undefined;
116
102
  });
117
103
  editButton.innerHTML = assets_1.editIcon;
118
104
  commentButton.innerHTML = assets_1.commentIcon;
@@ -153,6 +139,13 @@ class BibliographyElementBlockView extends block_view_1.default {
153
139
  this.dom.setAttribute('contenteditable', 'false');
154
140
  this.dom.appendChild(this.container);
155
141
  };
142
+ this.handleSave = (item) => {
143
+ const node = this.decoder.decode(item);
144
+ this.updateNodeAttrs(node.attrs);
145
+ };
146
+ this.handleDelete = (item) => {
147
+ return this.deleteNode(item._id);
148
+ };
156
149
  }
157
150
  }
158
151
  exports.BibliographyElementBlockView = BibliographyElementBlockView;