@manuscripts/body-editor 1.6.13 → 1.6.14-LEAN-3094

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 (70) hide show
  1. package/dist/cjs/citation-sources/crossref.js +27 -54
  2. package/dist/cjs/commands.js +5 -6
  3. package/dist/cjs/configs/editor-views.js +4 -4
  4. package/dist/cjs/lib/array-reducer.js +45 -0
  5. package/dist/cjs/lib/mathml-to-svg.js +70 -0
  6. package/dist/cjs/lib/tex-to-svg.js +60 -0
  7. package/dist/cjs/plugins/bibliography/index.js +11 -1
  8. package/dist/cjs/testing/default-editor-data.js +0 -22
  9. package/dist/cjs/views/CitationEditorWrapper.js +65 -0
  10. package/dist/cjs/views/ReferencesEditor.js +50 -0
  11. package/dist/cjs/views/base_node_view.js +1 -1
  12. package/dist/cjs/views/bibliography_element.js +20 -27
  13. package/dist/cjs/views/citation.js +1 -72
  14. package/dist/cjs/views/citation_editable.js +91 -106
  15. package/dist/cjs/views/cross_reference_editable.js +12 -10
  16. package/dist/cjs/views/equation.js +8 -3
  17. package/dist/cjs/views/equation_editable.js +3 -9
  18. package/dist/cjs/views/equation_element.js +6 -3
  19. package/dist/cjs/views/inline_equation.js +8 -3
  20. package/dist/cjs/views/inline_equation_editable.js +3 -9
  21. package/dist/cjs/views/link_editable.js +42 -34
  22. package/dist/es/citation-sources/crossref.js +27 -54
  23. package/dist/es/commands.js +6 -7
  24. package/dist/es/configs/editor-views.js +4 -4
  25. package/dist/es/lib/array-reducer.js +41 -0
  26. package/dist/es/lib/mathml-to-svg.js +66 -0
  27. package/dist/es/lib/tex-to-svg.js +56 -0
  28. package/dist/es/plugins/bibliography/index.js +11 -1
  29. package/dist/es/testing/default-editor-data.js +0 -22
  30. package/dist/es/views/CitationEditorWrapper.js +38 -0
  31. package/dist/es/views/ReferencesEditor.js +23 -0
  32. package/dist/es/views/base_node_view.js +1 -1
  33. package/dist/es/views/bibliography_element.js +21 -28
  34. package/dist/es/views/citation.js +1 -49
  35. package/dist/es/views/citation_editable.js +92 -107
  36. package/dist/es/views/cross_reference_editable.js +12 -10
  37. package/dist/es/views/editable_block.js +1 -1
  38. package/dist/es/views/equation.js +8 -3
  39. package/dist/es/views/equation_editable.js +3 -9
  40. package/dist/es/views/equation_element.js +6 -3
  41. package/dist/es/views/inline_equation.js +8 -3
  42. package/dist/es/views/inline_equation_editable.js +3 -9
  43. package/dist/es/views/link_editable.js +42 -34
  44. package/dist/types/citation-sources/crossref.d.ts +2 -11
  45. package/dist/types/commands.d.ts +3 -3
  46. package/dist/types/components/views/LinkForm.d.ts +2 -2
  47. package/dist/types/configs/ManuscriptsEditor.d.ts +1 -6
  48. package/dist/types/configs/editor-plugins.d.ts +1 -2
  49. package/dist/types/configs/editor-views.d.ts +1 -3
  50. package/dist/types/lib/array-reducer.d.ts +25 -0
  51. package/dist/types/lib/context-menu.d.ts +1 -1
  52. package/dist/types/{plugins/models.d.ts → lib/mathml-to-svg.d.ts} +2 -13
  53. package/dist/types/lib/tex-to-svg.d.ts +18 -0
  54. package/dist/types/plugins/bibliography/index.d.ts +1 -1
  55. package/dist/types/views/CitationEditorWrapper.d.ts +3 -0
  56. package/dist/types/views/ReferencesEditor.d.ts +4 -0
  57. package/dist/types/views/base_node_view.d.ts +0 -3
  58. package/dist/types/views/bibliography_element.d.ts +6 -5
  59. package/dist/types/views/citation.d.ts +2 -14
  60. package/dist/types/views/citation_editable.d.ts +12 -6
  61. package/dist/types/views/cross_reference.d.ts +0 -1
  62. package/dist/types/views/editable_block.d.ts +2 -4
  63. package/dist/types/views/keyword_group.d.ts +3 -15
  64. package/dist/types/views/link_editable.d.ts +3 -0
  65. package/package.json +6 -5
  66. package/dist/cjs/plugins/models.js +0 -48
  67. package/dist/cjs/views/ReactView.js +0 -94
  68. package/dist/es/plugins/models.js +0 -45
  69. package/dist/es/views/ReactView.js +0 -66
  70. 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
+ };
@@ -109,7 +109,6 @@ const createBlock = (nodeType, position, state, dispatch) => {
109
109
  case state.schema.nodes.equation_element:
110
110
  node = state.schema.nodes.equation_element.create({}, [
111
111
  state.schema.nodes.equation.create(),
112
- createAndFillFigcaptionElement(state),
113
112
  ]);
114
113
  break;
115
114
  default:
@@ -234,7 +233,7 @@ const insertLink = (state, dispatch) => {
234
233
  return true;
235
234
  };
236
235
  exports.insertLink = insertLink;
237
- const insertInlineCitation = (state, dispatch, view) => {
236
+ const insertInlineCitation = (state, dispatch) => {
238
237
  const node = state.schema.nodes.citation.create({
239
238
  id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.Citation),
240
239
  rids: [],
@@ -264,10 +263,10 @@ const insertCrossReference = (state, dispatch) => {
264
263
  };
265
264
  exports.insertCrossReference = insertCrossReference;
266
265
  const insertInlineEquation = (state, dispatch) => {
267
- const inlineMathFragment = (0, transform_1.buildInlineMathFragment)(state.selection.$anchor.parent.attrs.id, selectedText().replace(/^\$/, '').replace(/\$$/, ''));
268
266
  const sourcePos = state.selection.from - 1;
269
267
  const tr = state.tr.replaceSelectionWith(state.schema.nodes.inline_equation.create({
270
- id: inlineMathFragment._id,
268
+ format: 'tex',
269
+ contents: selectedText().replace(/^\$/, '').replace(/\$$/, ''),
271
270
  }));
272
271
  if (dispatch) {
273
272
  const selection = prosemirror_state_1.NodeSelection.create(tr.doc, tr.mapping.map(sourcePos) + 1);
@@ -396,11 +395,11 @@ const insertList = (type, style) => (state, dispatch) => {
396
395
  }
397
396
  };
398
397
  exports.insertList = insertList;
399
- const insertBibliographySection = (state, dispatch) => {
398
+ const insertBibliographySection = () => {
400
399
  return false;
401
400
  };
402
401
  exports.insertBibliographySection = insertBibliographySection;
403
- const insertTOCSection = (state, dispatch) => {
402
+ const insertTOCSection = () => {
404
403
  return false;
405
404
  };
406
405
  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;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 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.convertMathMLToSVG = void 0;
19
+ require("mathjax-full/js/util/entities/all");
20
+ const transform_1 = require("@manuscripts/transform");
21
+ const HTMLAdaptor_1 = require("mathjax-full/js/adaptors/HTMLAdaptor");
22
+ const MmlFactory_1 = require("mathjax-full/js/core/MmlTree/MmlFactory");
23
+ const HTMLDocument_1 = require("mathjax-full/js/handlers/html/HTMLDocument");
24
+ const mathml_1 = require("mathjax-full/js/input/mathml");
25
+ const svg_1 = require("mathjax-full/js/output/svg");
26
+ class ManuscriptsMmlFactory extends MmlFactory_1.MmlFactory {
27
+ constructor() {
28
+ super();
29
+ this.nodeMap.set('image', this.nodeMap.get('none'));
30
+ }
31
+ create(kind, properties = {}, children = []) {
32
+ if (kind === 'image') {
33
+ return this.node['none'](properties, children);
34
+ }
35
+ return this.node[kind](properties, children);
36
+ }
37
+ }
38
+ class ManuscriptsHTMLAdaptor extends HTMLAdaptor_1.HTMLAdaptor {
39
+ setAttribute(node, name, value, ns) {
40
+ if (name !== 'xmlns') {
41
+ ns ? node.setAttributeNS(ns, name, value) : node.setAttribute(name, value);
42
+ }
43
+ }
44
+ }
45
+ const InputJax = new mathml_1.MathML();
46
+ const OutputJax = new svg_1.SVG({
47
+ fontCache: 'none',
48
+ });
49
+ const adaptor = new ManuscriptsHTMLAdaptor(window);
50
+ const doc = new HTMLDocument_1.HTMLDocument(document, adaptor, {
51
+ InputJax,
52
+ OutputJax,
53
+ MmlFactory: new ManuscriptsMmlFactory(),
54
+ });
55
+ doc.addStyleSheet();
56
+ const convertMathMLToSVG = (mathml, display) => {
57
+ const item = doc.convert(mathml, {
58
+ display,
59
+ em: 16,
60
+ ex: 8,
61
+ containerWidth: 1000000,
62
+ lineWidth: 1000000,
63
+ scale: 1,
64
+ });
65
+ if (!item || !item.firstChild) {
66
+ return null;
67
+ }
68
+ return transform_1.xmlSerializer.serializeToString(item.firstChild);
69
+ };
70
+ exports.convertMathMLToSVG = convertMathMLToSVG;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 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.convertTeXToSVG = exports.packages = void 0;
19
+ require("mathjax-full/js/util/entities/all");
20
+ const transform_1 = require("@manuscripts/transform");
21
+ const HTMLAdaptor_1 = require("mathjax-full/js/adaptors/HTMLAdaptor");
22
+ const HTMLDocument_1 = require("mathjax-full/js/handlers/html/HTMLDocument");
23
+ const tex_1 = require("mathjax-full/js/input/tex");
24
+ const AllPackages_1 = require("mathjax-full/js/input/tex/AllPackages");
25
+ const svg_1 = require("mathjax-full/js/output/svg");
26
+ exports.packages = AllPackages_1.AllPackages.filter((name) => name !== 'html' && name !== 'bussproofs');
27
+ class ManuscriptsHTMLAdaptor extends HTMLAdaptor_1.HTMLAdaptor {
28
+ setAttribute(node, name, value, ns) {
29
+ if (name !== 'xmlns') {
30
+ ns ? node.setAttributeNS(ns, name, value) : node.setAttribute(name, value);
31
+ }
32
+ }
33
+ }
34
+ const InputJax = new tex_1.TeX({
35
+ packages: exports.packages,
36
+ });
37
+ const OutputJax = new svg_1.SVG({
38
+ fontCache: 'none',
39
+ });
40
+ const adaptor = new ManuscriptsHTMLAdaptor(window);
41
+ const doc = new HTMLDocument_1.HTMLDocument(document, adaptor, {
42
+ InputJax,
43
+ OutputJax,
44
+ });
45
+ doc.addStyleSheet();
46
+ const convertTeXToSVG = (tex, display) => {
47
+ const item = doc.convert(tex, {
48
+ display,
49
+ em: 16,
50
+ ex: 8,
51
+ containerWidth: 1000000,
52
+ lineWidth: 1000000,
53
+ scale: 1,
54
+ });
55
+ if (!item || !item.firstChild) {
56
+ return null;
57
+ }
58
+ return transform_1.xmlSerializer.serializeToString(item.firstChild);
59
+ };
60
+ exports.convertTeXToSVG = convertTeXToSVG;
@@ -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;