@manuscripts/body-editor 1.6.13 → 1.6.14

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 (55) hide show
  1. package/dist/cjs/citation-sources/crossref.js +27 -54
  2. package/dist/cjs/commands.js +3 -3
  3. package/dist/cjs/configs/editor-views.js +4 -4
  4. package/dist/cjs/lib/array-reducer.js +45 -0
  5. package/dist/cjs/plugins/bibliography/index.js +11 -1
  6. package/dist/cjs/testing/default-editor-data.js +0 -22
  7. package/dist/cjs/views/CitationEditorWrapper.js +65 -0
  8. package/dist/cjs/views/ReferencesEditor.js +50 -0
  9. package/dist/cjs/views/base_node_view.js +1 -1
  10. package/dist/cjs/views/bibliography_element.js +20 -27
  11. package/dist/cjs/views/citation.js +1 -72
  12. package/dist/cjs/views/citation_editable.js +91 -106
  13. package/dist/cjs/views/cross_reference_editable.js +12 -10
  14. package/dist/cjs/views/link_editable.js +42 -34
  15. package/dist/es/citation-sources/crossref.js +27 -54
  16. package/dist/es/commands.js +3 -3
  17. package/dist/es/configs/editor-views.js +4 -4
  18. package/dist/es/lib/array-reducer.js +41 -0
  19. package/dist/es/plugins/bibliography/index.js +11 -1
  20. package/dist/es/testing/default-editor-data.js +0 -22
  21. package/dist/es/views/CitationEditorWrapper.js +38 -0
  22. package/dist/es/views/ReferencesEditor.js +23 -0
  23. package/dist/es/views/base_node_view.js +1 -1
  24. package/dist/es/views/bibliography_element.js +21 -28
  25. package/dist/es/views/citation.js +1 -49
  26. package/dist/es/views/citation_editable.js +92 -107
  27. package/dist/es/views/cross_reference_editable.js +12 -10
  28. package/dist/es/views/editable_block.js +1 -1
  29. package/dist/es/views/link_editable.js +42 -34
  30. package/dist/types/citation-sources/crossref.d.ts +2 -11
  31. package/dist/types/commands.d.ts +3 -3
  32. package/dist/types/components/views/LinkForm.d.ts +2 -2
  33. package/dist/types/configs/ManuscriptsEditor.d.ts +1 -6
  34. package/dist/types/configs/editor-plugins.d.ts +1 -2
  35. package/dist/types/configs/editor-views.d.ts +1 -3
  36. package/dist/types/lib/array-reducer.d.ts +25 -0
  37. package/dist/types/lib/context-menu.d.ts +1 -1
  38. package/dist/types/plugins/bibliography/index.d.ts +1 -1
  39. package/dist/types/views/CitationEditorWrapper.d.ts +3 -0
  40. package/dist/types/views/ReferencesEditor.d.ts +4 -0
  41. package/dist/types/views/base_node_view.d.ts +0 -3
  42. package/dist/types/views/bibliography_element.d.ts +6 -5
  43. package/dist/types/views/citation.d.ts +2 -14
  44. package/dist/types/views/citation_editable.d.ts +12 -6
  45. package/dist/types/views/cross_reference.d.ts +0 -1
  46. package/dist/types/views/editable_block.d.ts +2 -4
  47. package/dist/types/views/keyword_group.d.ts +3 -15
  48. package/dist/types/views/link_editable.d.ts +3 -0
  49. package/package.json +3 -3
  50. package/dist/cjs/plugins/models.js +0 -48
  51. package/dist/cjs/views/ReactView.js +0 -94
  52. package/dist/es/plugins/models.js +0 -45
  53. package/dist/es/views/ReactView.js +0 -66
  54. package/dist/types/plugins/models.d.ts +0 -28
  55. package/dist/types/views/ReactView.d.ts +0 -33
@@ -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
+ };
@@ -234,7 +234,7 @@ const insertLink = (state, dispatch) => {
234
234
  return true;
235
235
  };
236
236
  exports.insertLink = insertLink;
237
- const insertInlineCitation = (state, dispatch, view) => {
237
+ const insertInlineCitation = (state, dispatch) => {
238
238
  const node = state.schema.nodes.citation.create({
239
239
  id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.Citation),
240
240
  rids: [],
@@ -396,11 +396,11 @@ const insertList = (type, style) => (state, dispatch) => {
396
396
  }
397
397
  };
398
398
  exports.insertList = insertList;
399
- const insertBibliographySection = (state, dispatch) => {
399
+ const insertBibliographySection = () => {
400
400
  return false;
401
401
  };
402
402
  exports.insertBibliographySection = insertBibliographySection;
403
- const insertTOCSection = (state, dispatch) => {
403
+ const insertTOCSection = () => {
404
404
  return false;
405
405
  };
406
406
  exports.insertTOCSection = insertTOCSection;
@@ -52,11 +52,11 @@ const toc_element_editable_1 = __importDefault(require("../views/toc_element_edi
52
52
  exports.default = (props, dispatch) => {
53
53
  return {
54
54
  title: (0, title_editable_1.default)(props, dispatch),
55
- bibliography_element: (0, bibliography_element_editable_1.default)(props),
55
+ bibliography_element: (0, bibliography_element_editable_1.default)(props, dispatch),
56
56
  blockquote_element: (0, blockquote_element_editable_1.default)(props),
57
57
  bullet_list: (0, bullet_list_editable_1.default)(props),
58
- citation: (0, citation_editable_1.default)(props),
59
- cross_reference: (0, cross_reference_editable_1.default)(props),
58
+ citation: (0, citation_editable_1.default)(props, dispatch),
59
+ cross_reference: (0, cross_reference_editable_1.default)(props, dispatch),
60
60
  contributors: (0, contributors_1.default)(props, dispatch),
61
61
  equation: (0, equation_editable_1.default)(props),
62
62
  equation_element: (0, equation_element_editable_1.default)(props),
@@ -68,7 +68,7 @@ exports.default = (props, dispatch) => {
68
68
  inline_footnote: (0, inline_footnote_editable_1.default)(props),
69
69
  keyword: (0, keyword_1.default)(props, dispatch),
70
70
  keyword_group: (0, keyword_group_1.default)(props, dispatch),
71
- link: (0, link_editable_1.default)(props),
71
+ link: (0, link_editable_1.default)(props, dispatch),
72
72
  listing: (0, listing_editable_1.default)(props),
73
73
  listing_element: (0, listing_element_editable_1.default)(props),
74
74
  ordered_list: (0, ordered_list_editable_1.default)(props),
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2024 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.arrayReducer = void 0;
19
+ const arrayReducer = (isEqual = (a, b) => a === b) => {
20
+ return (state, action) => {
21
+ const handleUpdate = (state, items) => {
22
+ const copy = [...state];
23
+ items.forEach((item) => {
24
+ const index = copy.findIndex((i) => isEqual(item, i));
25
+ if (index >= 0) {
26
+ copy[index] = item;
27
+ }
28
+ else {
29
+ copy.push(item);
30
+ }
31
+ });
32
+ return copy;
33
+ };
34
+ const handleDelete = (state, item) => {
35
+ return state.filter((i) => !isEqual(item, i));
36
+ };
37
+ switch (action.type) {
38
+ case 'update':
39
+ return handleUpdate(state, action.items);
40
+ case 'delete':
41
+ return handleDelete(state, action.item);
42
+ }
43
+ };
44
+ };
45
+ exports.arrayReducer = arrayReducer;
@@ -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
  }
@@ -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,65 @@
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 array_reducer_1 = require("../lib/array-reducer");
30
+ const itemsReducer = (0, array_reducer_1.arrayReducer)((a, b) => a._id === b._id);
31
+ const ridsReducer = (0, array_reducer_1.arrayReducer)();
32
+ const CitationEditorWrapper = (props) => {
33
+ const [items, dispatchItems] = (0, react_1.useReducer)(itemsReducer, props.items);
34
+ const [rids, dispatchRids] = (0, react_1.useReducer)(ridsReducer, props.rids);
35
+ const handleSave = (item) => {
36
+ props.onSave(item);
37
+ dispatchItems({
38
+ type: 'update',
39
+ items: [item],
40
+ });
41
+ };
42
+ const handleDelete = (item) => {
43
+ props.onDelete(item);
44
+ dispatchItems({
45
+ type: 'delete',
46
+ item,
47
+ });
48
+ };
49
+ const handleCite = (items) => {
50
+ props.onCite(items);
51
+ dispatchRids({
52
+ type: 'update',
53
+ items: items.map((i) => i._id),
54
+ });
55
+ };
56
+ const handleUncite = (rid) => {
57
+ props.onUncite(rid);
58
+ dispatchRids({
59
+ type: 'delete',
60
+ item: rid,
61
+ });
62
+ };
63
+ return (react_1.default.createElement(style_guide_1.CitationEditor, Object.assign({}, props, { rids: rids, items: items, onCite: handleCite, onUncite: handleUncite, onSave: handleSave, onDelete: handleDelete })));
64
+ };
65
+ exports.CitationEditorWrapper = CitationEditorWrapper;
@@ -0,0 +1,50 @@
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 array_reducer_1 = require("../lib/array-reducer");
30
+ const itemsReducer = (0, array_reducer_1.arrayReducer)((a, b) => a._id === b._id);
31
+ const ReferencesEditor = (props) => {
32
+ const [isOpen, setOpen] = (0, react_1.useState)(true);
33
+ const [items, dispatch] = (0, react_1.useReducer)(itemsReducer, props.items);
34
+ const handleSave = (item) => {
35
+ props.onSave(item);
36
+ dispatch({
37
+ type: 'update',
38
+ items: [item],
39
+ });
40
+ };
41
+ const handleDelete = (item) => {
42
+ props.onDelete(item);
43
+ dispatch({
44
+ type: 'delete',
45
+ item: item,
46
+ });
47
+ };
48
+ return (react_1.default.createElement(style_guide_1.ReferencesModal, Object.assign({}, props, { isOpen: isOpen, onCancel: () => setOpen(false), items: items, onSave: handleSave, onDelete: handleDelete })));
49
+ };
50
+ 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;
@@ -14,37 +14,13 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- var desc = Object.getOwnPropertyDescriptor(m, k);
20
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
- desc = { enumerable: true, get: function() { return m[k]; } };
22
- }
23
- Object.defineProperty(o, k2, desc);
24
- }) : (function(o, m, k, k2) {
25
- if (k2 === undefined) k2 = k;
26
- o[k2] = m[k];
27
- }));
28
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }) : function(o, v) {
31
- o["default"] = v;
32
- });
33
- var __importStar = (this && this.__importStar) || function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
17
  var __importDefault = (this && this.__importDefault) || function (mod) {
41
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
42
19
  };
43
20
  Object.defineProperty(exports, "__esModule", { value: true });
44
21
  exports.CitationView = void 0;
45
- const json_schema_1 = require("@manuscripts/json-schema");
46
22
  const prosemirror_model_1 = require("prosemirror-model");
47
- const react_1 = __importStar(require("react"));
23
+ const react_1 = require("react");
48
24
  const react_dom_1 = __importDefault(require("react-dom"));
49
25
  const TrackChangesReview_1 = require("../components/track-changes/TrackChangesReview");
50
26
  const dompurify_1 = require("../lib/dompurify");
@@ -56,38 +32,7 @@ const creators_1 = require("./creators");
56
32
  class CitationView extends base_node_view_1.BaseNodeView {
57
33
  constructor() {
58
34
  super(...arguments);
59
- this.showPopper = () => {
60
- const { components: { CitationViewer }, projectID, renderReactComponent, } = this.props;
61
- const items = this.getBibliographyItems();
62
- if (!this.popperContainer) {
63
- this.popperContainer = document.createElement('div');
64
- this.popperContainer.className = 'citation-editor';
65
- }
66
- renderReactComponent(react_1.default.createElement(CitationViewer, { items: items, projectID: projectID, scheduleUpdate: this.props.popper.update }), this.popperContainer);
67
- this.props.popper.show(this.dom, this.popperContainer, 'right');
68
- };
69
35
  this.ignoreMutation = () => true;
70
- this.selectNode = () => {
71
- var _a;
72
- const isDeleted = !!((_a = this.node.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.find(({ operation, status }) => operation === 'delete' && status !== 'rejected'));
73
- if (!isDeleted) {
74
- this.showPopper();
75
- this.dom.classList.add('ProseMirror-selectednode');
76
- }
77
- };
78
- this.deselectNode = () => {
79
- this.dom.classList.remove('ProseMirror-selectednode');
80
- this.props.popper.destroy();
81
- if (this.popperContainer) {
82
- this.props.unmountReactComponent(this.popperContainer);
83
- }
84
- };
85
- this.destroy = () => {
86
- this.props.popper.destroy();
87
- if (this.popperContainer) {
88
- this.props.unmountReactComponent(this.popperContainer);
89
- }
90
- };
91
36
  this.initialise = () => {
92
37
  if (!this.node.type.spec.toDOM) {
93
38
  throw Error(`Node view ${this.node.type} doesn't have toDOM method`);
@@ -138,22 +83,6 @@ class CitationView extends base_node_view_1.BaseNodeView {
138
83
  }
139
84
  return citation;
140
85
  };
141
- this.getBibliographyItems = () => {
142
- const bib = (0, bibliography_1.getBibliographyPluginState)(this.view.state);
143
- const citation = this.node;
144
- return citation.attrs.rids.map((rid) => {
145
- const item = bib.bibliographyItems.get(rid);
146
- if (!item) {
147
- const placeholder = {
148
- _id: rid,
149
- objectType: json_schema_1.ObjectTypes.BibliographyItem,
150
- title: '[missing library item]',
151
- };
152
- return placeholder;
153
- }
154
- return item;
155
- });
156
- };
157
86
  }
158
87
  }
159
88
  exports.CitationView = CitationView;