@manuscripts/body-editor 1.7.6 → 1.7.7

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 (31) hide show
  1. package/dist/cjs/components/views/FigureDropdown.js +4 -4
  2. package/dist/cjs/configs/editor-plugins.js +1 -1
  3. package/dist/cjs/lib/build-file-models.js +41 -0
  4. package/dist/cjs/plugins/bibliography/bibliography-utils.js +9 -7
  5. package/dist/cjs/plugins/bibliography/index.js +4 -4
  6. package/dist/cjs/plugins/toc.js +6 -40
  7. package/dist/cjs/testing/default-editor-data.js +0 -5
  8. package/dist/cjs/views/figure_editable.js +2 -1
  9. package/dist/cjs/views/figure_element.js +16 -5
  10. package/dist/es/components/views/FigureDropdown.js +4 -4
  11. package/dist/es/configs/editor-plugins.js +1 -1
  12. package/dist/es/lib/build-file-models.js +37 -0
  13. package/dist/es/plugins/bibliography/bibliography-utils.js +5 -5
  14. package/dist/es/plugins/bibliography/index.js +4 -4
  15. package/dist/es/plugins/toc.js +9 -43
  16. package/dist/es/testing/default-editor-data.js +0 -5
  17. package/dist/es/views/figure_editable.js +2 -1
  18. package/dist/es/views/figure_element.js +16 -5
  19. package/dist/types/components/views/FigureDropdown.d.ts +1 -1
  20. package/dist/types/configs/ManuscriptsEditor.d.ts +1 -3
  21. package/dist/types/configs/editor-plugins.d.ts +1 -3
  22. package/dist/types/lib/build-file-models.d.ts +2 -0
  23. package/dist/types/plugins/bibliography/bibliography-utils.d.ts +4 -0
  24. package/dist/types/plugins/toc.d.ts +1 -5
  25. package/dist/types/views/base_node_view.d.ts +0 -2
  26. package/dist/types/views/figure_editable.d.ts +0 -2
  27. package/dist/types/views/figure_element.d.ts +1 -3
  28. package/package.json +3 -3
  29. package/dist/cjs/plugins/styles.js +0 -120
  30. package/dist/es/plugins/styles.js +0 -118
  31. package/dist/types/plugins/styles.d.ts +0 -24
@@ -10,9 +10,9 @@ const TriangleCollapsed_1 = __importDefault(require("@manuscripts/assets/react/T
10
10
  const style_guide_1 = require("@manuscripts/style-guide");
11
11
  const react_1 = __importDefault(require("react"));
12
12
  const styled_components_1 = __importDefault(require("styled-components"));
13
- const FigureElementOptions = ({ can, files, modelMap, handleAdd, handleUpload, }) => {
13
+ const FigureElementOptions = ({ can, files, getFilesMap, handleAdd, handleUpload, }) => {
14
14
  const { isOpen, toggleOpen, wrapperRef } = (0, style_guide_1.useDropdown)();
15
- let { supplements, otherFiles } = (0, style_guide_1.useFiles)(modelMap, files);
15
+ let { supplements, otherFiles } = (0, style_guide_1.useFiles)(getFilesMap(), files);
16
16
  supplements = supplements.filter(style_guide_1.isImageFile);
17
17
  otherFiles = otherFiles.filter(style_guide_1.isImageFile);
18
18
  return (react_1.default.createElement(FilesDropdownWrapper, { onClick: toggleOpen, ref: wrapperRef },
@@ -30,9 +30,9 @@ const FigureElementOptions = ({ can, files, modelMap, handleAdd, handleUpload, }
30
30
  " New file...")))));
31
31
  };
32
32
  exports.FigureElementOptions = FigureElementOptions;
33
- const FigureOptions = ({ can, files, modelMap, handleDownload, handleUpload, handleDetach, handleReplace, }) => {
33
+ const FigureOptions = ({ can, files, getFilesMap, handleDownload, handleUpload, handleDetach, handleReplace, }) => {
34
34
  const { isOpen, toggleOpen, wrapperRef } = (0, style_guide_1.useDropdown)();
35
- const otherFiles = (0, style_guide_1.useFiles)(modelMap, files).otherFiles.filter(style_guide_1.isImageFile);
35
+ const otherFiles = (0, style_guide_1.useFiles)(getFilesMap(), files).otherFiles.filter(style_guide_1.isImageFile);
36
36
  const showDownload = handleDownload && can.downloadFiles;
37
37
  const showUpload = handleUpload && can.uploadFile;
38
38
  const showDetach = handleDetach && can.editArticle;
@@ -52,7 +52,7 @@ exports.default = (props) => {
52
52
  (0, elements_1.default)(),
53
53
  (0, persist_1.default)(),
54
54
  (0, sections_1.default)(),
55
- (0, toc_1.default)(props),
55
+ (0, toc_1.default)(),
56
56
  (0, bibliography_1.default)(props),
57
57
  (0, objects_1.default)(props),
58
58
  (0, affiliations_1.default)(),
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildFileMap = void 0;
4
+ const json_schema_1 = require("@manuscripts/json-schema");
5
+ const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
6
+ const transform_1 = require("@manuscripts/transform");
7
+ const bibliography_utils_1 = require("../plugins/bibliography/bibliography-utils");
8
+ const buildFileMap = (doc) => {
9
+ const figures = [];
10
+ const supplements = [];
11
+ const sections = [];
12
+ const buildNode = (node, group) => {
13
+ var _a;
14
+ const attrs = (0, bibliography_utils_1.getEffectiveAttrs)(node, true);
15
+ if (attrs) {
16
+ const nodeChange = (_a = node.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.reduce(bibliography_utils_1.getLatest);
17
+ if (nodeChange &&
18
+ nodeChange.operation === track_changes_plugin_1.CHANGE_OPERATION.insert &&
19
+ nodeChange.status === track_changes_plugin_1.CHANGE_STATUS.rejected) {
20
+ return false;
21
+ }
22
+ group.push(node.type.create(Object.assign({}, attrs), node.content));
23
+ }
24
+ return false;
25
+ };
26
+ doc.descendants((node) => {
27
+ if (node.type === transform_1.schema.nodes.section &&
28
+ node.attrs.category === 'MPSectionCategory:abstract-graphical') {
29
+ return buildNode(node, sections);
30
+ }
31
+ if (node.type === transform_1.schema.nodes.figure_element) {
32
+ return buildNode(node, figures);
33
+ }
34
+ if (node.type === transform_1.schema.nodes.supplement) {
35
+ buildNode(node, supplements);
36
+ }
37
+ });
38
+ sections.push(transform_1.schema.nodes.section.create({ id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.Section) }, figures), transform_1.schema.nodes.supplements.create({ id: (0, transform_1.generateID)(json_schema_1.ObjectTypes.Supplement) }, supplements));
39
+ return (0, transform_1.encode)(transform_1.schema.nodes.manuscript.create({}, sections));
40
+ };
41
+ exports.buildFileMap = buildFileMap;
@@ -26,7 +26,7 @@ var __rest = (this && this.__rest) || function (s, e) {
26
26
  return t;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.buildCitations = exports.getBibliographyItemModelMap = exports.getBibliographyItem = exports.getCitation = exports.buildDecorations = exports.isBibliographyElement = void 0;
29
+ exports.buildCitations = exports.getBibliographyItemModelMap = exports.getEffectiveAttrs = exports.getLatest = exports.getBibliographyItem = exports.getCitation = exports.buildDecorations = exports.isBibliographyElement = void 0;
30
30
  const json_schema_1 = require("@manuscripts/json-schema");
31
31
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
32
32
  const transform_1 = require("@manuscripts/transform");
@@ -85,7 +85,7 @@ const buildDecorations = (state, doc) => {
85
85
  };
86
86
  exports.buildDecorations = buildDecorations;
87
87
  const getCitation = (node) => {
88
- const attrs = getEffectiveAttrs(node);
88
+ const attrs = (0, exports.getEffectiveAttrs)(node);
89
89
  if (!attrs) {
90
90
  return undefined;
91
91
  }
@@ -103,7 +103,7 @@ const getCitation = (node) => {
103
103
  };
104
104
  exports.getCitation = getCitation;
105
105
  const getBibliographyItem = (node) => {
106
- const attrs = getEffectiveAttrs(node, true);
106
+ const attrs = (0, exports.getEffectiveAttrs)(node, true);
107
107
  if (!attrs) {
108
108
  return undefined;
109
109
  }
@@ -113,9 +113,10 @@ const getBibliographyItem = (node) => {
113
113
  };
114
114
  exports.getBibliographyItem = getBibliographyItem;
115
115
  const getLatest = (a, b) => a.updatedAt > b.updatedAt ? a : b;
116
+ exports.getLatest = getLatest;
116
117
  const getEffectiveAttrs = (node, excludeDeletedNode) => {
117
118
  const _a = node.attrs, { dataTracked } = _a, attrs = __rest(_a, ["dataTracked"]);
118
- const nodeChange = dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.reduce(getLatest);
119
+ const nodeChange = dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.reduce(exports.getLatest);
119
120
  const isDeleted = nodeChange &&
120
121
  nodeChange.operation === track_changes_plugin_1.CHANGE_OPERATION.delete &&
121
122
  nodeChange.status !== track_changes_plugin_1.CHANGE_STATUS.rejected;
@@ -127,17 +128,18 @@ const getEffectiveAttrs = (node, excludeDeletedNode) => {
127
128
  nodeChange.status === track_changes_plugin_1.CHANGE_STATUS.rejected;
128
129
  return isRejected ? nodeChange === null || nodeChange === void 0 ? void 0 : nodeChange.oldAttrs : attrs;
129
130
  };
131
+ exports.getEffectiveAttrs = getEffectiveAttrs;
130
132
  const getBibliographyItemModelMap = (doc) => {
131
- const modelMap = new Map();
133
+ const bibliographyItemMap = new Map();
132
134
  doc.descendants((node) => {
133
135
  if (node.type === transform_1.schema.nodes.bibliography_item) {
134
136
  const model = (0, exports.getBibliographyItem)(node);
135
137
  if (model) {
136
- modelMap.set(model._id, model);
138
+ bibliographyItemMap.set(model._id, model);
137
139
  }
138
140
  }
139
141
  });
140
- return modelMap;
142
+ return bibliographyItemMap;
141
143
  };
142
144
  exports.getBibliographyItemModelMap = getBibliographyItemModelMap;
143
145
  const buildCitations = (citations) => citations.map((citation) => ({
@@ -53,19 +53,19 @@ const buildBibliographyPluginState = (doc, csl, $old) => {
53
53
  nodes.push([node, pos]);
54
54
  }
55
55
  });
56
- const modelMap = (0, bibliography_utils_1.getBibliographyItemModelMap)(doc);
56
+ const bibliographyItemMap = (0, bibliography_utils_1.getBibliographyItemModelMap)(doc);
57
57
  const citations = (0, bibliography_utils_1.buildCitations)(nodes);
58
58
  const $new = {
59
59
  citationNodes: nodes,
60
60
  citations,
61
- bibliographyItems: modelMap,
61
+ bibliographyItems: bibliographyItemMap,
62
62
  };
63
63
  if (!csl.style) {
64
64
  return $new;
65
65
  }
66
66
  if ($old &&
67
67
  (0, lodash_1.isEqual)(citations, $old.citations) &&
68
- (0, lodash_1.isEqual)(modelMap, $old.bibliographyItems)) {
68
+ (0, lodash_1.isEqual)(bibliographyItemMap, $old.bibliographyItems)) {
69
69
  $new.citationCounts = $old.citationCounts;
70
70
  $new.provider = $old.provider;
71
71
  $new.renderedCitations = $old.renderedCitations;
@@ -78,7 +78,7 @@ const buildBibliographyPluginState = (doc, csl, $old) => {
78
78
  citationCounts.set(rid, count + 1);
79
79
  });
80
80
  const provider = new library_1.CitationProvider({
81
- getLibraryItem: (id) => modelMap.get(id),
81
+ getLibraryItem: (id) => bibliographyItemMap.get(id),
82
82
  citationStyle: csl.style || '',
83
83
  locale: csl.locale,
84
84
  });
@@ -21,27 +21,17 @@ const transform_1 = require("@manuscripts/transform");
21
21
  const prosemirror_state_1 = require("prosemirror-state");
22
22
  const utils_1 = require("../lib/utils");
23
23
  exports.tocKey = new prosemirror_state_1.PluginKey('toc');
24
- const buildTOCList = (headingStyles, list, node, depth = 1, prefix = '') => {
24
+ const buildTOCList = (list, node, depth = 1, prefix = '') => {
25
25
  list.classList.add('manuscript-toc-list');
26
26
  if (depth > 1) {
27
27
  list.classList.add('manuscript-toc-inner-list');
28
28
  }
29
- const paragraphStyle = headingStyles.get(`heading${depth}`);
30
- const sectionNumberingStyle = paragraphStyle
31
- ? paragraphStyle.sectionNumberingStyle
32
- : undefined;
33
- const numberingScheme = sectionNumberingStyle && sectionNumberingStyle.numberingScheme
34
- ? sectionNumberingStyle.numberingScheme
35
- : 'decimal';
36
- const suffix = sectionNumberingStyle && sectionNumberingStyle.suffix !== undefined
37
- ? sectionNumberingStyle.suffix
38
- : '.';
39
- let index = sectionNumberingStyle ? sectionNumberingStyle.startIndex : 1;
29
+ let index = 1;
40
30
  node.forEach((child) => {
41
31
  if (child.type === transform_1.schema.nodes.body) {
42
32
  for (const childNode of (0, utils_1.iterateChildren)(child)) {
43
33
  if ((0, transform_1.isSectionNodeType)(childNode.type) && !(0, transform_1.isTOCSectionNode)(childNode)) {
44
- const numbering = numberingScheme === 'none' ? '' : `${prefix}${index}`;
34
+ const numbering = `${prefix}${index}`;
45
35
  const firstChildNode = childNode.child(0);
46
36
  if (firstChildNode.type ===
47
37
  firstChildNode.type.schema.nodes.section_title) {
@@ -49,39 +39,16 @@ const buildTOCList = (headingStyles, list, node, depth = 1, prefix = '') => {
49
39
  item.classList.add('manuscript-toc-list-item');
50
40
  item.setAttribute('data-referenced-section', childNode.attrs.id);
51
41
  item.setAttribute('data-referenced-section-path-length', String(depth));
52
- item.textContent = `${numbering ? `${numbering}${suffix}` : ''} ${firstChildNode.textContent || 'Untitled Section'}`;
42
+ item.textContent = `${numbering ? `${numbering}.` : ''} ${firstChildNode.textContent || 'Untitled Section'}`;
53
43
  list.appendChild(item);
54
44
  }
55
- const childSection = (0, utils_1.getMatchingChild)(childNode, (node) => (0, transform_1.isSectionNodeType)(node.type));
56
- if (childSection) {
57
- const paragraphStyle = headingStyles.get(`heading${depth + 1}`);
58
- if (!paragraphStyle || paragraphStyle.partOfTOC) {
59
- const sublist = document.createElement('ul');
60
- buildTOCList(headingStyles, sublist, childNode, depth + 1, numbering ? `${numbering}.` : '');
61
- const item = document.createElement('li');
62
- item.appendChild(sublist);
63
- list.appendChild(item);
64
- }
65
- }
66
45
  index++;
67
46
  }
68
47
  }
69
48
  }
70
49
  });
71
50
  };
72
- const isParagraphStyle = (0, transform_1.hasObjectType)(json_schema_1.ObjectTypes.ParagraphStyle);
73
- const buildHeadingStyles = (modelMap) => {
74
- const styles = new Map();
75
- for (const model of modelMap.values()) {
76
- if (isParagraphStyle(model)) {
77
- if (model.name && /^heading\d+$/.test(model.name)) {
78
- styles.set(model.name, model);
79
- }
80
- }
81
- }
82
- return styles;
83
- };
84
- exports.default = (props) => {
51
+ exports.default = () => {
85
52
  return new prosemirror_state_1.Plugin({
86
53
  key: exports.tocKey,
87
54
  appendTransaction(transactions, oldState, newState) {
@@ -94,8 +61,7 @@ exports.default = (props) => {
94
61
  if (node.type === node.type.schema.nodes.toc_element) {
95
62
  const list = document.createElement('ul');
96
63
  list.setAttribute('data-paragraph-style', node.attrs.paragraphStyle);
97
- const headingStyles = buildHeadingStyles(props.getModelMap());
98
- buildTOCList(headingStyles, list, newState.doc);
64
+ buildTOCList(list, newState.doc);
99
65
  const contents = list.outerHTML;
100
66
  if (contents !== node.attrs.contents) {
101
67
  nodesToUpdate.push({
@@ -75,7 +75,6 @@ exports.defaultEditorProps = {
75
75
  download: () => { },
76
76
  },
77
77
  getCapabilities: () => (0, style_guide_1.getAllPermitted)(),
78
- getModelMap: () => exports.TEST_DATA.MODEL_MAP,
79
78
  getManuscript: () => exports.TEST_DATA.MANUSCRIPT,
80
79
  cslProps: {
81
80
  style: '',
@@ -83,10 +82,6 @@ exports.defaultEditorProps = {
83
82
  },
84
83
  getCitationProvider: () => undefined,
85
84
  plugins: [],
86
- deleteModel: (id) => {
87
- exports.TEST_DATA.MODEL_MAP.delete(id);
88
- return Promise.resolve(id);
89
- },
90
85
  retrySync: () => Promise.resolve(),
91
86
  setComment: () => undefined,
92
87
  setSelectedComment: () => undefined,
@@ -32,6 +32,7 @@ const style_guide_1 = require("@manuscripts/style-guide");
32
32
  const react_1 = require("react");
33
33
  const react_dom_1 = __importDefault(require("react-dom"));
34
34
  const FigureDropdown_1 = require("../components/views/FigureDropdown");
35
+ const build_file_models_1 = require("../lib/build-file-models");
35
36
  const track_changes_utils_1 = require("../lib/track-changes-utils");
36
37
  const creators_1 = require("./creators");
37
38
  const figure_1 = require("./figure");
@@ -134,7 +135,7 @@ class FigureEditableView extends figure_1.FigureView {
134
135
  const componentProps = {
135
136
  can,
136
137
  files,
137
- modelMap: this.props.getModelMap(),
138
+ getFilesMap: () => (0, build_file_models_1.buildFileMap)(this.view.state.doc),
138
139
  handleDownload,
139
140
  handleUpload,
140
141
  handleDetach,
@@ -28,8 +28,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.FigureElementView = void 0;
31
- const style_guide_1 = require("@manuscripts/style-guide");
31
+ const transform_1 = require("@manuscripts/transform");
32
32
  const FigureDropdown_1 = require("../components/views/FigureDropdown");
33
+ const build_file_models_1 = require("../lib/build-file-models");
33
34
  const utils_1 = require("../lib/utils");
34
35
  const block_view_1 = __importDefault(require("./block_view"));
35
36
  const creators_1 = require("./creators");
@@ -96,9 +97,7 @@ class FigureElementView extends block_view_1.default {
96
97
  tr.setNodeMarkup(this.getPos() + 1, undefined, Object.assign(Object.assign({}, figure.attrs), { src })).setSelection(selection.map(tr.doc, tr.mapping));
97
98
  dispatch(tr);
98
99
  }
99
- if ((0, style_guide_1.isModelFile)(file)) {
100
- yield this.props.deleteModel(file.modelId);
101
- }
100
+ this.deleteSupplementNode(file);
102
101
  });
103
102
  if (can.uploadFile) {
104
103
  const upload = (file) => __awaiter(this, void 0, void 0, function* () {
@@ -111,7 +110,7 @@ class FigureElementView extends block_view_1.default {
111
110
  const componentProps = {
112
111
  can: can,
113
112
  files: this.props.getFiles(),
114
- modelMap: this.props.getModelMap(),
113
+ getFilesMap: () => (0, build_file_models_1.buildFileMap)(this.view.state.doc),
115
114
  handleUpload,
116
115
  handleAdd,
117
116
  };
@@ -121,6 +120,18 @@ class FigureElementView extends block_view_1.default {
121
120
  }
122
121
  };
123
122
  }
123
+ deleteSupplementNode(file) {
124
+ if (file.type.id === 'supplementary') {
125
+ const tr = this.view.state.tr;
126
+ this.view.state.doc.descendants((node, pos) => {
127
+ if (node.type === transform_1.schema.nodes.supplement &&
128
+ node.attrs.href === file.id) {
129
+ tr.delete(pos, pos + node.nodeSize);
130
+ }
131
+ });
132
+ this.view.dispatch(tr);
133
+ }
134
+ }
124
135
  }
125
136
  exports.FigureElementView = FigureElementView;
126
137
  exports.default = (0, creators_1.createNodeView)(FigureElementView);
@@ -4,9 +4,9 @@ import TriangleCollapsed from '@manuscripts/assets/react/TriangleCollapsed';
4
4
  import { AttachIcon, DropdownList, getFileIcon, IconButton, IconTextButton, isImageFile, RoundIconButton, UploadIcon, useDropdown, useFiles, } from '@manuscripts/style-guide';
5
5
  import React from 'react';
6
6
  import styled from 'styled-components';
7
- export const FigureElementOptions = ({ can, files, modelMap, handleAdd, handleUpload, }) => {
7
+ export const FigureElementOptions = ({ can, files, getFilesMap, handleAdd, handleUpload, }) => {
8
8
  const { isOpen, toggleOpen, wrapperRef } = useDropdown();
9
- let { supplements, otherFiles } = useFiles(modelMap, files);
9
+ let { supplements, otherFiles } = useFiles(getFilesMap(), files);
10
10
  supplements = supplements.filter(isImageFile);
11
11
  otherFiles = otherFiles.filter(isImageFile);
12
12
  return (React.createElement(FilesDropdownWrapper, { onClick: toggleOpen, ref: wrapperRef },
@@ -23,9 +23,9 @@ export const FigureElementOptions = ({ can, files, modelMap, handleAdd, handleUp
23
23
  React.createElement(AddIconHighlight, null),
24
24
  " New file...")))));
25
25
  };
26
- export const FigureOptions = ({ can, files, modelMap, handleDownload, handleUpload, handleDetach, handleReplace, }) => {
26
+ export const FigureOptions = ({ can, files, getFilesMap, handleDownload, handleUpload, handleDetach, handleReplace, }) => {
27
27
  const { isOpen, toggleOpen, wrapperRef } = useDropdown();
28
- const otherFiles = useFiles(modelMap, files).otherFiles.filter(isImageFile);
28
+ const otherFiles = useFiles(getFilesMap(), files).otherFiles.filter(isImageFile);
29
29
  const showDownload = handleDownload && can.downloadFiles;
30
30
  const showUpload = handleUpload && can.uploadFile;
31
31
  const showDetach = handleDetach && can.editArticle;
@@ -47,7 +47,7 @@ export default (props) => {
47
47
  elements(),
48
48
  persist(),
49
49
  sections(),
50
- toc(props),
50
+ toc(),
51
51
  bibliography(props),
52
52
  objects(props),
53
53
  affiliations(),
@@ -0,0 +1,37 @@
1
+ import { ObjectTypes } from '@manuscripts/json-schema';
2
+ import { CHANGE_OPERATION, CHANGE_STATUS, } from '@manuscripts/track-changes-plugin';
3
+ import { encode, generateID, schema, } from '@manuscripts/transform';
4
+ import { getEffectiveAttrs, getLatest, } from '../plugins/bibliography/bibliography-utils';
5
+ export const buildFileMap = (doc) => {
6
+ const figures = [];
7
+ const supplements = [];
8
+ const sections = [];
9
+ const buildNode = (node, group) => {
10
+ var _a;
11
+ const attrs = getEffectiveAttrs(node, true);
12
+ if (attrs) {
13
+ const nodeChange = (_a = node.attrs.dataTracked) === null || _a === void 0 ? void 0 : _a.reduce(getLatest);
14
+ if (nodeChange &&
15
+ nodeChange.operation === CHANGE_OPERATION.insert &&
16
+ nodeChange.status === CHANGE_STATUS.rejected) {
17
+ return false;
18
+ }
19
+ group.push(node.type.create(Object.assign({}, attrs), node.content));
20
+ }
21
+ return false;
22
+ };
23
+ doc.descendants((node) => {
24
+ if (node.type === schema.nodes.section &&
25
+ node.attrs.category === 'MPSectionCategory:abstract-graphical') {
26
+ return buildNode(node, sections);
27
+ }
28
+ if (node.type === schema.nodes.figure_element) {
29
+ return buildNode(node, figures);
30
+ }
31
+ if (node.type === schema.nodes.supplement) {
32
+ buildNode(node, supplements);
33
+ }
34
+ });
35
+ sections.push(schema.nodes.section.create({ id: generateID(ObjectTypes.Section) }, figures), schema.nodes.supplements.create({ id: generateID(ObjectTypes.Supplement) }, supplements));
36
+ return encode(schema.nodes.manuscript.create({}, sections));
37
+ };
@@ -105,8 +105,8 @@ export const getBibliographyItem = (node) => {
105
105
  const item = Object.assign({ _id: id, objectType: ObjectTypes.BibliographyItem, 'container-title': containerTitle, DOI: doi }, rest);
106
106
  return pickBy(item, (v) => v !== undefined);
107
107
  };
108
- const getLatest = (a, b) => a.updatedAt > b.updatedAt ? a : b;
109
- const getEffectiveAttrs = (node, excludeDeletedNode) => {
108
+ export const getLatest = (a, b) => a.updatedAt > b.updatedAt ? a : b;
109
+ export const getEffectiveAttrs = (node, excludeDeletedNode) => {
110
110
  const _a = node.attrs, { dataTracked } = _a, attrs = __rest(_a, ["dataTracked"]);
111
111
  const nodeChange = dataTracked === null || dataTracked === void 0 ? void 0 : dataTracked.reduce(getLatest);
112
112
  const isDeleted = nodeChange &&
@@ -121,16 +121,16 @@ const getEffectiveAttrs = (node, excludeDeletedNode) => {
121
121
  return isRejected ? nodeChange === null || nodeChange === void 0 ? void 0 : nodeChange.oldAttrs : attrs;
122
122
  };
123
123
  export const getBibliographyItemModelMap = (doc) => {
124
- const modelMap = new Map();
124
+ const bibliographyItemMap = new Map();
125
125
  doc.descendants((node) => {
126
126
  if (node.type === schema.nodes.bibliography_item) {
127
127
  const model = getBibliographyItem(node);
128
128
  if (model) {
129
- modelMap.set(model._id, model);
129
+ bibliographyItemMap.set(model._id, model);
130
130
  }
131
131
  }
132
132
  });
133
- return modelMap;
133
+ return bibliographyItemMap;
134
134
  };
135
135
  export const buildCitations = (citations) => citations.map((citation) => ({
136
136
  citationID: citation[0].attrs.id,
@@ -50,19 +50,19 @@ const buildBibliographyPluginState = (doc, csl, $old) => {
50
50
  nodes.push([node, pos]);
51
51
  }
52
52
  });
53
- const modelMap = getBibliographyItemModelMap(doc);
53
+ const bibliographyItemMap = getBibliographyItemModelMap(doc);
54
54
  const citations = buildCitations(nodes);
55
55
  const $new = {
56
56
  citationNodes: nodes,
57
57
  citations,
58
- bibliographyItems: modelMap,
58
+ bibliographyItems: bibliographyItemMap,
59
59
  };
60
60
  if (!csl.style) {
61
61
  return $new;
62
62
  }
63
63
  if ($old &&
64
64
  isEqual(citations, $old.citations) &&
65
- isEqual(modelMap, $old.bibliographyItems)) {
65
+ isEqual(bibliographyItemMap, $old.bibliographyItems)) {
66
66
  $new.citationCounts = $old.citationCounts;
67
67
  $new.provider = $old.provider;
68
68
  $new.renderedCitations = $old.renderedCitations;
@@ -75,7 +75,7 @@ const buildBibliographyPluginState = (doc, csl, $old) => {
75
75
  citationCounts.set(rid, count + 1);
76
76
  });
77
77
  const provider = new CitationProvider({
78
- getLibraryItem: (id) => modelMap.get(id),
78
+ getLibraryItem: (id) => bibliographyItemMap.get(id),
79
79
  citationStyle: csl.style || '',
80
80
  locale: csl.locale,
81
81
  });
@@ -13,32 +13,22 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { ObjectTypes, } from '@manuscripts/json-schema';
17
- import { generateID, hasObjectType, isSectionNodeType, isTOCSectionNode, schema, } from '@manuscripts/transform';
16
+ import { ObjectTypes } from '@manuscripts/json-schema';
17
+ import { generateID, isSectionNodeType, isTOCSectionNode, schema, } from '@manuscripts/transform';
18
18
  import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
19
- import { getMatchingChild, iterateChildren } from '../lib/utils';
19
+ import { iterateChildren } from '../lib/utils';
20
20
  export const tocKey = new PluginKey('toc');
21
- const buildTOCList = (headingStyles, list, node, depth = 1, prefix = '') => {
21
+ const buildTOCList = (list, node, depth = 1, prefix = '') => {
22
22
  list.classList.add('manuscript-toc-list');
23
23
  if (depth > 1) {
24
24
  list.classList.add('manuscript-toc-inner-list');
25
25
  }
26
- const paragraphStyle = headingStyles.get(`heading${depth}`);
27
- const sectionNumberingStyle = paragraphStyle
28
- ? paragraphStyle.sectionNumberingStyle
29
- : undefined;
30
- const numberingScheme = sectionNumberingStyle && sectionNumberingStyle.numberingScheme
31
- ? sectionNumberingStyle.numberingScheme
32
- : 'decimal';
33
- const suffix = sectionNumberingStyle && sectionNumberingStyle.suffix !== undefined
34
- ? sectionNumberingStyle.suffix
35
- : '.';
36
- let index = sectionNumberingStyle ? sectionNumberingStyle.startIndex : 1;
26
+ let index = 1;
37
27
  node.forEach((child) => {
38
28
  if (child.type === schema.nodes.body) {
39
29
  for (const childNode of iterateChildren(child)) {
40
30
  if (isSectionNodeType(childNode.type) && !isTOCSectionNode(childNode)) {
41
- const numbering = numberingScheme === 'none' ? '' : `${prefix}${index}`;
31
+ const numbering = `${prefix}${index}`;
42
32
  const firstChildNode = childNode.child(0);
43
33
  if (firstChildNode.type ===
44
34
  firstChildNode.type.schema.nodes.section_title) {
@@ -46,39 +36,16 @@ const buildTOCList = (headingStyles, list, node, depth = 1, prefix = '') => {
46
36
  item.classList.add('manuscript-toc-list-item');
47
37
  item.setAttribute('data-referenced-section', childNode.attrs.id);
48
38
  item.setAttribute('data-referenced-section-path-length', String(depth));
49
- item.textContent = `${numbering ? `${numbering}${suffix}` : ''} ${firstChildNode.textContent || 'Untitled Section'}`;
39
+ item.textContent = `${numbering ? `${numbering}.` : ''} ${firstChildNode.textContent || 'Untitled Section'}`;
50
40
  list.appendChild(item);
51
41
  }
52
- const childSection = getMatchingChild(childNode, (node) => isSectionNodeType(node.type));
53
- if (childSection) {
54
- const paragraphStyle = headingStyles.get(`heading${depth + 1}`);
55
- if (!paragraphStyle || paragraphStyle.partOfTOC) {
56
- const sublist = document.createElement('ul');
57
- buildTOCList(headingStyles, sublist, childNode, depth + 1, numbering ? `${numbering}.` : '');
58
- const item = document.createElement('li');
59
- item.appendChild(sublist);
60
- list.appendChild(item);
61
- }
62
- }
63
42
  index++;
64
43
  }
65
44
  }
66
45
  }
67
46
  });
68
47
  };
69
- const isParagraphStyle = hasObjectType(ObjectTypes.ParagraphStyle);
70
- const buildHeadingStyles = (modelMap) => {
71
- const styles = new Map();
72
- for (const model of modelMap.values()) {
73
- if (isParagraphStyle(model)) {
74
- if (model.name && /^heading\d+$/.test(model.name)) {
75
- styles.set(model.name, model);
76
- }
77
- }
78
- }
79
- return styles;
80
- };
81
- export default (props) => {
48
+ export default () => {
82
49
  return new Plugin({
83
50
  key: tocKey,
84
51
  appendTransaction(transactions, oldState, newState) {
@@ -91,8 +58,7 @@ export default (props) => {
91
58
  if (node.type === node.type.schema.nodes.toc_element) {
92
59
  const list = document.createElement('ul');
93
60
  list.setAttribute('data-paragraph-style', node.attrs.paragraphStyle);
94
- const headingStyles = buildHeadingStyles(props.getModelMap());
95
- buildTOCList(headingStyles, list, newState.doc);
61
+ buildTOCList(list, newState.doc);
96
62
  const contents = list.outerHTML;
97
63
  if (contents !== node.attrs.contents) {
98
64
  nodesToUpdate.push({
@@ -69,7 +69,6 @@ export const defaultEditorProps = {
69
69
  download: () => { },
70
70
  },
71
71
  getCapabilities: () => getAllPermitted(),
72
- getModelMap: () => TEST_DATA.MODEL_MAP,
73
72
  getManuscript: () => TEST_DATA.MANUSCRIPT,
74
73
  cslProps: {
75
74
  style: '',
@@ -77,10 +76,6 @@ export const defaultEditorProps = {
77
76
  },
78
77
  getCitationProvider: () => undefined,
79
78
  plugins: [],
80
- deleteModel: (id) => {
81
- TEST_DATA.MODEL_MAP.delete(id);
82
- return Promise.resolve(id);
83
- },
84
79
  retrySync: () => Promise.resolve(),
85
80
  setComment: () => undefined,
86
81
  setSelectedComment: () => undefined,
@@ -26,6 +26,7 @@ import { UnsupportedFormatFileIcon, } from '@manuscripts/style-guide';
26
26
  import { createElement } from 'react';
27
27
  import ReactDOM from 'react-dom';
28
28
  import { FigureOptions, } from '../components/views/FigureDropdown';
29
+ import { buildFileMap } from '../lib/build-file-models';
29
30
  import { getActualAttrs } from '../lib/track-changes-utils';
30
31
  import { createEditableNodeView } from './creators';
31
32
  import { FigureView } from './figure';
@@ -128,7 +129,7 @@ export class FigureEditableView extends FigureView {
128
129
  const componentProps = {
129
130
  can,
130
131
  files,
131
- modelMap: this.props.getModelMap(),
132
+ getFilesMap: () => buildFileMap(this.view.state.doc),
132
133
  handleDownload,
133
134
  handleUpload,
134
135
  handleDetach,
@@ -22,8 +22,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  step((generator = generator.apply(thisArg, _arguments || [])).next());
23
23
  });
24
24
  };
25
- import { isModelFile, } from '@manuscripts/style-guide';
25
+ import { schema } from '@manuscripts/transform';
26
26
  import { FigureElementOptions, } from '../components/views/FigureDropdown';
27
+ import { buildFileMap } from '../lib/build-file-models';
27
28
  import { getMatchingChild } from '../lib/utils';
28
29
  import BlockView from './block_view';
29
30
  import { createNodeView } from './creators';
@@ -90,9 +91,7 @@ export class FigureElementView extends BlockView {
90
91
  tr.setNodeMarkup(this.getPos() + 1, undefined, Object.assign(Object.assign({}, figure.attrs), { src })).setSelection(selection.map(tr.doc, tr.mapping));
91
92
  dispatch(tr);
92
93
  }
93
- if (isModelFile(file)) {
94
- yield this.props.deleteModel(file.modelId);
95
- }
94
+ this.deleteSupplementNode(file);
96
95
  });
97
96
  if (can.uploadFile) {
98
97
  const upload = (file) => __awaiter(this, void 0, void 0, function* () {
@@ -105,7 +104,7 @@ export class FigureElementView extends BlockView {
105
104
  const componentProps = {
106
105
  can: can,
107
106
  files: this.props.getFiles(),
108
- modelMap: this.props.getModelMap(),
107
+ getFilesMap: () => buildFileMap(this.view.state.doc),
109
108
  handleUpload,
110
109
  handleAdd,
111
110
  };
@@ -115,5 +114,17 @@ export class FigureElementView extends BlockView {
115
114
  }
116
115
  };
117
116
  }
117
+ deleteSupplementNode(file) {
118
+ if (file.type.id === 'supplementary') {
119
+ const tr = this.view.state.tr;
120
+ this.view.state.doc.descendants((node, pos) => {
121
+ if (node.type === schema.nodes.supplement &&
122
+ node.attrs.href === file.id) {
123
+ tr.delete(pos, pos + node.nodeSize);
124
+ }
125
+ });
126
+ this.view.dispatch(tr);
127
+ }
128
+ }
118
129
  }
119
130
  export default createNodeView(FigureElementView);
@@ -4,7 +4,7 @@ import React from 'react';
4
4
  export interface FigureDropdownProps {
5
5
  can: Capabilities;
6
6
  files: FileAttachment[];
7
- modelMap: Map<string, Model>;
7
+ getFilesMap: () => Map<string, Model>;
8
8
  }
9
9
  export interface FigureOptionsProps extends FigureDropdownProps {
10
10
  handleDownload?: () => void;
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import 'prosemirror-view/style/prosemirror.css';
17
- import { CommentAnnotation, Manuscript, Model, UserProfile } from '@manuscripts/json-schema';
17
+ import { CommentAnnotation, Manuscript, UserProfile } from '@manuscripts/json-schema';
18
18
  import { Capabilities, FileAttachment, FileManagement } from '@manuscripts/style-guide';
19
19
  import { ManuscriptNode } from '@manuscripts/transform';
20
20
  import { History } from 'history';
@@ -38,9 +38,7 @@ export interface EditorProps {
38
38
  getCurrentUser: () => UserProfile;
39
39
  projectID: string;
40
40
  doc: ManuscriptNode;
41
- getModelMap: () => Map<string, Model>;
42
41
  getManuscript: () => Manuscript;
43
- deleteModel: (id: string) => Promise<string>;
44
42
  getFiles: () => FileAttachment[];
45
43
  fileManagement: FileManagement;
46
44
  popper: PopperManager;
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import 'prosemirror-gapcursor/style/gapcursor.css';
17
17
  import 'prosemirror-tables/style/tables.css';
18
- import { CommentAnnotation, Manuscript, Model } from '@manuscripts/json-schema';
18
+ import { CommentAnnotation, Manuscript } from '@manuscripts/json-schema';
19
19
  import { Capabilities } from '@manuscripts/style-guide';
20
20
  import { ManuscriptSchema } from '@manuscripts/transform';
21
21
  import { Plugin } from 'prosemirror-state';
@@ -23,9 +23,7 @@ import { CollabProvider } from '../classes/collabProvider';
23
23
  import { PopperManager } from '../lib/popper';
24
24
  import { CSLProps } from './ManuscriptsEditor';
25
25
  interface PluginProps {
26
- getModelMap: () => Map<string, Model>;
27
26
  getManuscript: () => Manuscript;
28
- deleteModel: (id: string) => Promise<string>;
29
27
  setComment: (comment?: CommentAnnotation) => void;
30
28
  setSelectedComment: (id?: string) => void;
31
29
  setEditorSelectedSuggestion: (id?: string) => void;
@@ -0,0 +1,2 @@
1
+ import { ManuscriptNode } from '@manuscripts/transform';
2
+ export declare const buildFileMap: (doc: ManuscriptNode) => Map<string, import("@manuscripts/json-schema").Model>;
@@ -14,8 +14,10 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { BibliographyItem, Citation } from '@manuscripts/json-schema';
17
+ import { TrackedAttrs } from '@manuscripts/track-changes-plugin';
17
18
  import { BibliographyItemNode, CitationNode, ManuscriptNode } from '@manuscripts/transform';
18
19
  import CiteProc from 'citeproc';
20
+ import { Attrs } from 'prosemirror-model';
19
21
  import { Decoration } from 'prosemirror-view';
20
22
  import { PluginState } from './index';
21
23
  export declare const isBibliographyElement: (node: ManuscriptNode) => boolean;
@@ -23,5 +25,7 @@ export type CitationNodes = [CitationNode, number][];
23
25
  export declare const buildDecorations: (state: PluginState, doc: ManuscriptNode) => Decoration[];
24
26
  export declare const getCitation: (node: CitationNode) => Citation | undefined;
25
27
  export declare const getBibliographyItem: (node: BibliographyItemNode) => BibliographyItem | undefined;
28
+ export declare const getLatest: (a: TrackedAttrs, b: TrackedAttrs) => TrackedAttrs;
29
+ export declare const getEffectiveAttrs: (node: ManuscriptNode, excludeDeletedNode?: boolean) => Attrs | undefined;
26
30
  export declare const getBibliographyItemModelMap: (doc: ManuscriptNode) => Map<string, BibliographyItem>;
27
31
  export declare const buildCitations: (citations: CitationNodes) => CiteProc.Citation[];
@@ -13,11 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Model } from '@manuscripts/json-schema';
17
16
  import { Plugin, PluginKey } from 'prosemirror-state';
18
17
  export declare const tocKey: PluginKey<any>;
19
- interface Props {
20
- getModelMap: () => Map<string, Model>;
21
- }
22
- declare const _default: (props: Props) => Plugin<null>;
18
+ declare const _default: () => Plugin<null>;
23
19
  export default _default;
@@ -13,7 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Model } from '@manuscripts/json-schema';
17
16
  import { ManuscriptEditorView, ManuscriptNode } from '@manuscripts/transform';
18
17
  import { Attrs, Node } from 'prosemirror-model';
19
18
  import { Decoration, NodeView } from 'prosemirror-view';
@@ -21,7 +20,6 @@ import { CSLProps } from '../configs/ManuscriptsEditor';
21
20
  import { PopperManager } from '../lib/popper';
22
21
  import { SyncError } from '../types';
23
22
  export interface BaseNodeProps {
24
- getModelMap: () => Map<string, Model>;
25
23
  popper: PopperManager;
26
24
  cslProps: CSLProps;
27
25
  setEditorSelectedSuggestion: (id?: string) => void;
@@ -13,7 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Model } from '@manuscripts/json-schema';
17
16
  import { Capabilities, FileAttachment, FileManagement } from '@manuscripts/style-guide';
18
17
  import { ManuscriptEditorView, ManuscriptNode } from '@manuscripts/transform';
19
18
  import { EditableBlockProps } from './editable_block';
@@ -21,7 +20,6 @@ import { FigureView } from './figure';
21
20
  export interface FigureProps {
22
21
  fileManagement: FileManagement;
23
22
  getFiles: () => FileAttachment[];
24
- getModelMap: () => Map<string, Model>;
25
23
  getCapabilities: () => Capabilities;
26
24
  isInGraphicalAbstract?: boolean;
27
25
  }
@@ -13,16 +13,13 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Model } from '@manuscripts/json-schema';
17
16
  import { Capabilities, FileAttachment, FileManagement } from '@manuscripts/style-guide';
18
17
  import BlockView from './block_view';
19
18
  import { EditableBlockProps } from './editable_block';
20
19
  interface FigureElementProps {
21
20
  fileManagement: FileManagement;
22
21
  getFiles: () => FileAttachment[];
23
- getModelMap: () => Map<string, Model>;
24
22
  getCapabilities: () => Capabilities;
25
- deleteModel: (id: string) => Promise<string>;
26
23
  }
27
24
  export declare class FigureElementView extends BlockView<EditableBlockProps & FigureElementProps> {
28
25
  private container;
@@ -30,6 +27,7 @@ export declare class FigureElementView extends BlockView<EditableBlockProps & Fi
30
27
  ignoreMutation: () => boolean;
31
28
  createElement: () => void;
32
29
  updateContents: () => void;
30
+ private deleteSupplementNode;
33
31
  }
34
32
  declare const _default: (props: import("./base_node_view").BaseNodeProps, dispatch?: import("..").Dispatch | undefined) => import("../types").NodeViewCreator<FigureElementView>;
35
33
  export default _default;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@manuscripts/body-editor",
3
3
  "description": "Prosemirror components for editing and viewing manuscripts",
4
- "version": "1.7.6",
4
+ "version": "1.7.7",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -31,7 +31,7 @@
31
31
  "@manuscripts/assets": "^0.6.4",
32
32
  "@manuscripts/json-schema": "^2.2.2",
33
33
  "@manuscripts/library": "1.3.2",
34
- "@manuscripts/style-guide": "1.7.4",
34
+ "@manuscripts/style-guide": "1.7.4-LEAN-3181-1",
35
35
  "@manuscripts/track-changes-plugin": "^1.7.5",
36
36
  "@manuscripts/transform": "2.1.1",
37
37
  "astrocite-eutils": "^0.16.4",
@@ -109,4 +109,4 @@
109
109
  "resolutions": {
110
110
  "@types/react": "^17.0.2"
111
111
  }
112
- }
112
+ }
@@ -1,120 +0,0 @@
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
- const json_schema_1 = require("@manuscripts/json-schema");
19
- const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
20
- const transform_1 = require("@manuscripts/transform");
21
- const prosemirror_state_1 = require("prosemirror-state");
22
- const isParagraphStyle = (0, transform_1.hasObjectType)(json_schema_1.ObjectTypes.ParagraphStyle);
23
- const isFigureStyle = (0, transform_1.hasObjectType)(json_schema_1.ObjectTypes.FigureStyle);
24
- const isTableStyle = (0, transform_1.hasObjectType)(json_schema_1.ObjectTypes.TableStyle);
25
- const isFigureLayout = (0, transform_1.hasObjectType)(json_schema_1.ObjectTypes.FigureLayout);
26
- exports.default = (props) => {
27
- const chooseDefaultFigureStyle = () => {
28
- for (const model of props.getModelMap().values()) {
29
- if (isFigureStyle(model) && model.prototype === 'MPFigureStyle:default') {
30
- return model._id;
31
- }
32
- }
33
- };
34
- const chooseDefaultFigureLayout = () => {
35
- for (const model of props.getModelMap().values()) {
36
- if (isFigureLayout(model) &&
37
- model.prototype === 'MPFigureLayout:default') {
38
- return model._id;
39
- }
40
- }
41
- };
42
- const chooseDefaultTableStyle = () => {
43
- for (const model of props.getModelMap().values()) {
44
- if (isTableStyle(model) && model.prototype === 'MPTableStyle:default') {
45
- return model._id;
46
- }
47
- }
48
- };
49
- const chooseDefaultTOCStyle = () => {
50
- for (const model of props.getModelMap().values()) {
51
- if (isParagraphStyle(model) &&
52
- model.prototype === 'MPParagraphStyle:toc') {
53
- return model._id;
54
- }
55
- }
56
- };
57
- const chooseDefaultParagraphStyle = (node) => {
58
- switch (node.type) {
59
- case node.type.schema.nodes.toc_element:
60
- return chooseDefaultTOCStyle();
61
- default: {
62
- const manuscript = props.getManuscript();
63
- if (!manuscript.pageLayout) {
64
- return undefined;
65
- }
66
- const pageLayout = props.getModel(manuscript.pageLayout);
67
- if (!pageLayout) {
68
- return undefined;
69
- }
70
- return pageLayout.defaultParagraphStyle;
71
- }
72
- }
73
- };
74
- return new prosemirror_state_1.Plugin({
75
- appendTransaction: (transactions, oldState, newState) => {
76
- const tr = newState.tr;
77
- if (!transactions.some((transaction) => transaction.docChanged)) {
78
- return null;
79
- }
80
- const nodesNeedingStyle = [];
81
- newState.doc.descendants((node, pos) => {
82
- if ('paragraphStyle' in node.attrs && !node.attrs.paragraphStyle) {
83
- const paragraphStyle = chooseDefaultParagraphStyle(node);
84
- if (paragraphStyle) {
85
- nodesNeedingStyle.push({ node, pos, attrs: { paragraphStyle } });
86
- }
87
- }
88
- if ('figureStyle' in node.attrs && !node.attrs.figureStyle) {
89
- const figureStyle = chooseDefaultFigureStyle();
90
- if (figureStyle) {
91
- nodesNeedingStyle.push({ node, pos, attrs: { figureStyle } });
92
- }
93
- }
94
- if ('figureLayout' in node.attrs && !node.attrs.figureLayout) {
95
- const figureLayout = chooseDefaultFigureLayout();
96
- if (figureLayout) {
97
- nodesNeedingStyle.push({ node, pos, attrs: { figureLayout } });
98
- }
99
- }
100
- if ('tableStyle' in node.attrs && !node.attrs.tableStyle) {
101
- const tableStyle = chooseDefaultTableStyle();
102
- if (tableStyle) {
103
- nodesNeedingStyle.push({ node, pos, attrs: { tableStyle } });
104
- }
105
- }
106
- if ((0, transform_1.isElementNodeType)(node.type)) {
107
- return false;
108
- }
109
- });
110
- if (nodesNeedingStyle.length) {
111
- for (const { node, pos, attrs } of nodesNeedingStyle) {
112
- tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, node.attrs), attrs));
113
- }
114
- (0, track_changes_plugin_1.skipTracking)(tr);
115
- tr.setMeta('origin', 'styles');
116
- return tr.setSelection(newState.selection.map(tr.doc, tr.mapping));
117
- }
118
- },
119
- });
120
- };
@@ -1,118 +0,0 @@
1
- /*!
2
- * © 2019 Atypon Systems LLC
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { ObjectTypes, } from '@manuscripts/json-schema';
17
- import { skipTracking } from '@manuscripts/track-changes-plugin';
18
- import { hasObjectType, isElementNodeType, } from '@manuscripts/transform';
19
- import { Plugin } from 'prosemirror-state';
20
- const isParagraphStyle = hasObjectType(ObjectTypes.ParagraphStyle);
21
- const isFigureStyle = hasObjectType(ObjectTypes.FigureStyle);
22
- const isTableStyle = hasObjectType(ObjectTypes.TableStyle);
23
- const isFigureLayout = hasObjectType(ObjectTypes.FigureLayout);
24
- export default (props) => {
25
- const chooseDefaultFigureStyle = () => {
26
- for (const model of props.getModelMap().values()) {
27
- if (isFigureStyle(model) && model.prototype === 'MPFigureStyle:default') {
28
- return model._id;
29
- }
30
- }
31
- };
32
- const chooseDefaultFigureLayout = () => {
33
- for (const model of props.getModelMap().values()) {
34
- if (isFigureLayout(model) &&
35
- model.prototype === 'MPFigureLayout:default') {
36
- return model._id;
37
- }
38
- }
39
- };
40
- const chooseDefaultTableStyle = () => {
41
- for (const model of props.getModelMap().values()) {
42
- if (isTableStyle(model) && model.prototype === 'MPTableStyle:default') {
43
- return model._id;
44
- }
45
- }
46
- };
47
- const chooseDefaultTOCStyle = () => {
48
- for (const model of props.getModelMap().values()) {
49
- if (isParagraphStyle(model) &&
50
- model.prototype === 'MPParagraphStyle:toc') {
51
- return model._id;
52
- }
53
- }
54
- };
55
- const chooseDefaultParagraphStyle = (node) => {
56
- switch (node.type) {
57
- case node.type.schema.nodes.toc_element:
58
- return chooseDefaultTOCStyle();
59
- default: {
60
- const manuscript = props.getManuscript();
61
- if (!manuscript.pageLayout) {
62
- return undefined;
63
- }
64
- const pageLayout = props.getModel(manuscript.pageLayout);
65
- if (!pageLayout) {
66
- return undefined;
67
- }
68
- return pageLayout.defaultParagraphStyle;
69
- }
70
- }
71
- };
72
- return new Plugin({
73
- appendTransaction: (transactions, oldState, newState) => {
74
- const tr = newState.tr;
75
- if (!transactions.some((transaction) => transaction.docChanged)) {
76
- return null;
77
- }
78
- const nodesNeedingStyle = [];
79
- newState.doc.descendants((node, pos) => {
80
- if ('paragraphStyle' in node.attrs && !node.attrs.paragraphStyle) {
81
- const paragraphStyle = chooseDefaultParagraphStyle(node);
82
- if (paragraphStyle) {
83
- nodesNeedingStyle.push({ node, pos, attrs: { paragraphStyle } });
84
- }
85
- }
86
- if ('figureStyle' in node.attrs && !node.attrs.figureStyle) {
87
- const figureStyle = chooseDefaultFigureStyle();
88
- if (figureStyle) {
89
- nodesNeedingStyle.push({ node, pos, attrs: { figureStyle } });
90
- }
91
- }
92
- if ('figureLayout' in node.attrs && !node.attrs.figureLayout) {
93
- const figureLayout = chooseDefaultFigureLayout();
94
- if (figureLayout) {
95
- nodesNeedingStyle.push({ node, pos, attrs: { figureLayout } });
96
- }
97
- }
98
- if ('tableStyle' in node.attrs && !node.attrs.tableStyle) {
99
- const tableStyle = chooseDefaultTableStyle();
100
- if (tableStyle) {
101
- nodesNeedingStyle.push({ node, pos, attrs: { tableStyle } });
102
- }
103
- }
104
- if (isElementNodeType(node.type)) {
105
- return false;
106
- }
107
- });
108
- if (nodesNeedingStyle.length) {
109
- for (const { node, pos, attrs } of nodesNeedingStyle) {
110
- tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, node.attrs), attrs));
111
- }
112
- skipTracking(tr);
113
- tr.setMeta('origin', 'styles');
114
- return tr.setSelection(newState.selection.map(tr.doc, tr.mapping));
115
- }
116
- },
117
- });
118
- };
@@ -1,24 +0,0 @@
1
- /*!
2
- * © 2019 Atypon Systems LLC
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { Manuscript, Model } from '@manuscripts/json-schema';
17
- import { Plugin } from 'prosemirror-state';
18
- interface Props {
19
- getModel: <T extends Model>(id: string) => T | undefined;
20
- getManuscript: () => Manuscript;
21
- getModelMap: () => Map<string, Model>;
22
- }
23
- declare const _default: (props: Props) => Plugin<null>;
24
- export default _default;