@manuscripts/body-editor 2.7.3-LEAN-4218.0 → 2.7.3

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 (41) hide show
  1. package/dist/cjs/commands.js +6 -98
  2. package/dist/cjs/components/views/LinkForm.js +7 -7
  3. package/dist/cjs/components/views/TableCellContextMenu.js +1 -1
  4. package/dist/cjs/configs/ManuscriptsEditor.js +1 -0
  5. package/dist/cjs/configs/editor-views.js +0 -2
  6. package/dist/cjs/lib/copy.js +7 -45
  7. package/dist/cjs/lib/paste.js +20 -13
  8. package/dist/cjs/menus.js +0 -8
  9. package/dist/cjs/plugins/tables-cursor-fix.js +56 -0
  10. package/dist/cjs/versions.js +1 -1
  11. package/dist/es/commands.js +6 -95
  12. package/dist/es/components/views/LinkForm.js +2 -2
  13. package/dist/es/components/views/TableCellContextMenu.js +2 -2
  14. package/dist/es/configs/ManuscriptsEditor.js +2 -1
  15. package/dist/es/configs/editor-views.js +0 -2
  16. package/dist/es/lib/copy.js +8 -46
  17. package/dist/es/lib/paste.js +18 -12
  18. package/dist/es/menus.js +0 -8
  19. package/dist/es/plugins/tables-cursor-fix.js +56 -0
  20. package/dist/es/versions.js +1 -1
  21. package/dist/types/commands.d.ts +0 -2
  22. package/dist/types/components/views/LinkForm.d.ts +0 -2
  23. package/dist/types/configs/editor-views.d.ts +0 -1
  24. package/dist/types/lib/copy.d.ts +1 -2
  25. package/dist/types/lib/paste.d.ts +1 -0
  26. package/dist/types/versions.d.ts +1 -1
  27. package/package.json +3 -4
  28. package/styles/AdvancedEditor.css +1 -22
  29. package/styles/Editor.css +4 -0
  30. package/dist/cjs/components/toolbar/InsertEmbedDialog.js +0 -145
  31. package/dist/cjs/lib/oembed.js +0 -93
  32. package/dist/cjs/lib/table.js +0 -55
  33. package/dist/cjs/views/embed.js +0 -84
  34. package/dist/es/components/toolbar/InsertEmbedDialog.js +0 -113
  35. package/dist/es/lib/oembed.js +0 -85
  36. package/dist/es/lib/table.js +0 -48
  37. package/dist/es/views/embed.js +0 -77
  38. package/dist/types/components/toolbar/InsertEmbedDialog.d.ts +0 -27
  39. package/dist/types/lib/oembed.d.ts +0 -8
  40. package/dist/types/lib/table.d.ts +0 -9
  41. package/dist/types/views/embed.d.ts +0 -30
@@ -15,8 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.mergeCellsWithSpace = exports.addColumns = exports.addHeaderRow = exports.addRows = exports.addInlineComment = exports.addNodeComment = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreMetaNodeBackspaceCommand = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertKeywords = exports.insertAffiliation = exports.insertContributors = exports.insertAbstract = exports.insertBackmatterSection = exports.insertSection = exports.insertGraphicalAbstract = exports.insertBoxElement = exports.insertInlineFootnote = exports.insertFootnotesElement = exports.insertTableElementFooter = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.findPosBeforeFirstSubsection = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertSupplement = exports.insertTable = exports.insertFigure = exports.insertGeneralTableFootnote = exports.insertInlineTableFootnote = exports.insertEmbed = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = exports.addToStart = void 0;
19
- exports.autoComplete = void 0;
18
+ exports.autoComplete = exports.addColumns = exports.addHeaderRow = exports.addRows = exports.addInlineComment = exports.addNodeComment = exports.createAndFillTableElement = exports.selectAllIsolating = exports.ignoreAtomBlockNodeForward = exports.isAtEndOfTextBlock = exports.ignoreMetaNodeBackspaceCommand = exports.ignoreAtomBlockNodeBackward = exports.isTextSelection = exports.isAtStartOfTextBlock = exports.insertTOCSection = exports.insertBibliographySection = exports.insertList = exports.insertKeywords = exports.insertAffiliation = exports.insertContributors = exports.insertAbstract = exports.insertBackmatterSection = exports.insertSection = exports.insertGraphicalAbstract = exports.insertBoxElement = exports.insertInlineFootnote = exports.insertFootnotesElement = exports.insertTableElementFooter = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.findPosBeforeFirstSubsection = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertSupplement = exports.insertTable = exports.insertFigure = exports.insertGeneralTableFootnote = exports.insertInlineTableFootnote = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = exports.addToStart = void 0;
20
19
  const json_schema_1 = require("@manuscripts/json-schema");
21
20
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
22
21
  const transform_1 = require("@manuscripts/transform");
@@ -39,7 +38,8 @@ const addToStart = (state, dispatch) => {
39
38
  const { selection } = state;
40
39
  if (!dispatch ||
41
40
  !(selection instanceof prosemirror_state_1.TextSelection) ||
42
- selection.$from.node().type !== transform_1.schema.nodes.paragraph) {
41
+ (selection.$from.node().type !== transform_1.schema.nodes.paragraph &&
42
+ selection.$from.node().type !== transform_1.schema.nodes.text_block)) {
43
43
  return false;
44
44
  }
45
45
  const { $anchor: { parentOffset: startOffset }, $head: { parentOffset: endOffset }, $from, $to, } = selection;
@@ -53,10 +53,9 @@ const addToStart = (state, dispatch) => {
53
53
  const from = $from.node().type.createAndFill();
54
54
  if (from) {
55
55
  tr.insert(side, from);
56
+ dispatch(tr.scrollIntoView());
57
+ return true;
56
58
  }
57
- tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, side + 1));
58
- dispatch(tr.scrollIntoView());
59
- return true;
60
59
  }
61
60
  return false;
62
61
  };
@@ -151,11 +150,6 @@ const createBlock = (nodeType, position, state, dispatch, attrs) => {
151
150
  state.schema.nodes.equation.create(),
152
151
  ]);
153
152
  break;
154
- case state.schema.nodes.embed:
155
- node = state.schema.nodes.embed.create(attrs, [
156
- createAndFillFigcaptionElement(state),
157
- ]);
158
- break;
159
153
  default:
160
154
  node = nodeType.createAndFill(attrs);
161
155
  }
@@ -166,15 +160,6 @@ const createBlock = (nodeType, position, state, dispatch, attrs) => {
166
160
  }
167
161
  };
168
162
  exports.createBlock = createBlock;
169
- const insertEmbed = (state, dispatch, attrs) => {
170
- const position = findBlockInsertPosition(state);
171
- if (position === null) {
172
- return false;
173
- }
174
- (0, exports.createBlock)(transform_1.schema.nodes.embed, position, state, dispatch, attrs);
175
- return true;
176
- };
177
- exports.insertEmbed = insertEmbed;
178
163
  const insertInlineTableFootnote = (state, dispatch) => {
179
164
  const $pos = state.selection.$to;
180
165
  const table = (0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)($pos, transform_1.schema.nodes.table);
@@ -946,7 +931,7 @@ const DEFAULT_TABLE_CONFIG = {
946
931
  const createAndFillTableElement = (state, config = DEFAULT_TABLE_CONFIG) => {
947
932
  const { numberOfColumns, numberOfRows, includeHeader } = config;
948
933
  const createRow = (cellType) => {
949
- const cells = Array.from({ length: numberOfColumns }, () => cellType.create());
934
+ const cells = Array.from({ length: numberOfColumns }, () => cellType.create({}, transform_1.schema.nodes.text_block.create()));
950
935
  return transform_1.schema.nodes.table_row.create({}, cells);
951
936
  };
952
937
  const tableRows = includeHeader ? [createRow(transform_1.schema.nodes.table_header)] : [];
@@ -1116,83 +1101,6 @@ const addColumns = (direction) => (state, dispatch) => {
1116
1101
  return true;
1117
1102
  };
1118
1103
  exports.addColumns = addColumns;
1119
- function isEmpty(cell) {
1120
- const c = cell.content;
1121
- return (c.childCount == 1 && c.child(0).isTextblock && c.child(0).childCount == 0);
1122
- }
1123
- function cellsOverlapRectangle({ width, height, map }, rect) {
1124
- let indexTop = rect.top * width + rect.left, indexLeft = indexTop;
1125
- let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);
1126
- for (let i = rect.top; i < rect.bottom; i++) {
1127
- if ((rect.left > 0 && map[indexLeft] == map[indexLeft - 1]) ||
1128
- (rect.right < width && map[indexRight] == map[indexRight + 1])) {
1129
- return true;
1130
- }
1131
- indexLeft += width;
1132
- indexRight += width;
1133
- }
1134
- for (let i = rect.left; i < rect.right; i++) {
1135
- if ((rect.top > 0 && map[indexTop] == map[indexTop - width]) ||
1136
- (rect.bottom < height && map[indexBottom] == map[indexBottom + width])) {
1137
- return true;
1138
- }
1139
- indexTop++;
1140
- indexBottom++;
1141
- }
1142
- return false;
1143
- }
1144
- function mergeCellsWithSpace(state, dispatch) {
1145
- const sel = state.selection;
1146
- if (!(sel instanceof prosemirror_tables_1.CellSelection) ||
1147
- sel.$anchorCell.pos == sel.$headCell.pos) {
1148
- return false;
1149
- }
1150
- const rect = (0, prosemirror_tables_1.selectedRect)(state), { map } = rect;
1151
- if (cellsOverlapRectangle(map, rect)) {
1152
- return false;
1153
- }
1154
- if (dispatch) {
1155
- const tr = state.tr;
1156
- const seen = {};
1157
- let content = prosemirror_model_1.Fragment.empty;
1158
- let mergedPos;
1159
- let mergedCell;
1160
- for (let row = rect.top; row < rect.bottom; row++) {
1161
- for (let col = rect.left; col < rect.right; col++) {
1162
- const cellPos = map.map[row * map.width + col];
1163
- const cell = rect.table.nodeAt(cellPos);
1164
- if (seen[cellPos] || !cell) {
1165
- continue;
1166
- }
1167
- seen[cellPos] = true;
1168
- if (mergedPos == null) {
1169
- mergedPos = cellPos;
1170
- mergedCell = cell;
1171
- }
1172
- else {
1173
- if (!isEmpty(cell)) {
1174
- content = content.append(cell.content.addToStart(cell.type.schema.text(' ')));
1175
- }
1176
- const mapped = tr.mapping.map(cellPos + rect.tableStart);
1177
- tr.delete(mapped, mapped + cell.nodeSize);
1178
- }
1179
- }
1180
- }
1181
- if (mergedPos == null || mergedCell == null) {
1182
- return true;
1183
- }
1184
- tr.setNodeMarkup(mergedPos + rect.tableStart, null, Object.assign(Object.assign({}, (0, prosemirror_tables_1.addColSpan)(mergedCell.attrs, mergedCell.attrs.colspan, rect.right - rect.left - mergedCell.attrs.colspan)), { rowspan: rect.bottom - rect.top }));
1185
- if (content.size) {
1186
- const end = mergedPos + 1 + mergedCell.content.size;
1187
- const start = isEmpty(mergedCell) ? mergedPos + 1 : end;
1188
- tr.replaceWith(start + rect.tableStart, end + rect.tableStart, content);
1189
- }
1190
- tr.setSelection(new prosemirror_tables_1.CellSelection(tr.doc.resolve(mergedPos + rect.tableStart)));
1191
- dispatch(tr);
1192
- }
1193
- return true;
1194
- }
1195
- exports.mergeCellsWithSpace = mergeCellsWithSpace;
1196
1104
  const autoComplete = (state, dispatch) => {
1197
1105
  const complete = (0, autocompletion_1.checkForCompletion)(state);
1198
1106
  if (complete) {
@@ -41,7 +41,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  return (mod && mod.__esModule) ? mod : { "default": mod };
42
42
  };
43
43
  Object.defineProperty(exports, "__esModule", { value: true });
44
- exports.LinkForm = exports.Open = exports.FieldHeading = void 0;
44
+ exports.LinkForm = void 0;
45
45
  const style_guide_1 = require("@manuscripts/style-guide");
46
46
  const react_1 = __importStar(require("react"));
47
47
  const styled_components_1 = __importDefault(require("styled-components"));
@@ -66,7 +66,7 @@ const ActionGroup = styled_components_1.default.span `
66
66
  const Field = styled_components_1.default.div `
67
67
  margin-bottom: ${(props) => props.theme.grid.unit * 4}px;
68
68
  `;
69
- exports.FieldHeading = styled_components_1.default.div `
69
+ const FieldHeading = styled_components_1.default.div `
70
70
  display: flex;
71
71
  align-items: center;
72
72
  justify-content: space-between;
@@ -78,7 +78,7 @@ const Label = styled_components_1.default.label `
78
78
  color: ${(props) => props.theme.colors.text.tertiary};
79
79
  font-size: ${(props) => props.theme.font.size.normal};
80
80
  `;
81
- exports.Open = styled_components_1.default.a `
81
+ const Open = styled_components_1.default.a `
82
82
  display: inline-block;
83
83
  margin-left: ${(props) => props.theme.grid.unit * 2}px;
84
84
  text-transform: uppercase;
@@ -101,16 +101,16 @@ const LinkForm = ({ onCancel, onRemove, onSave, value, }) => {
101
101
  }, [href, text, title, onSave]);
102
102
  return (react_1.default.createElement(Form, { onSubmit: handleSubmit },
103
103
  react_1.default.createElement(Field, null,
104
- react_1.default.createElement(exports.FieldHeading, null,
104
+ react_1.default.createElement(FieldHeading, null,
105
105
  react_1.default.createElement(Label, null, "URL"),
106
- href && (0, url_1.allowedHref)(href) && (react_1.default.createElement(exports.Open, { href: href, target: '_blank', rel: 'noopener' }))),
106
+ href && (0, url_1.allowedHref)(href) && (react_1.default.createElement(Open, { href: href, target: '_blank', rel: 'noopener' }))),
107
107
  react_1.default.createElement(style_guide_1.TextField, { type: 'url', name: 'href', value: href, autoComplete: 'off', autoFocus: true, required: true, onChange: (e) => setHref(e.target.value) })),
108
108
  react_1.default.createElement(Field, null,
109
- react_1.default.createElement(exports.FieldHeading, null,
109
+ react_1.default.createElement(FieldHeading, null,
110
110
  react_1.default.createElement(Label, null, "Text")),
111
111
  react_1.default.createElement(style_guide_1.TextField, { type: 'text', name: 'text', value: text, autoComplete: 'off', required: true, onChange: (e) => setText(e.target.value) })),
112
112
  react_1.default.createElement(Field, null,
113
- react_1.default.createElement(exports.FieldHeading, null,
113
+ react_1.default.createElement(FieldHeading, null,
114
114
  react_1.default.createElement(Label, null, "Title (optional)")),
115
115
  react_1.default.createElement(style_guide_1.TextField, { type: 'text', name: 'title', value: title, autoComplete: 'off', required: false, onChange: (e) => setTitle(e.target.value) })),
116
116
  react_1.default.createElement(Actions, null,
@@ -114,7 +114,7 @@ const ContextMenu = ({ view, close, onCancelColumnDialog }) => {
114
114
  " Delete ",
115
115
  columns),
116
116
  (isCellSelectionMerged || isCellSelectionSplittable) && react_1.default.createElement(Separator, null),
117
- isCellSelectionMerged && (react_1.default.createElement(ActionButton, { onClick: () => runCommand(commands_1.mergeCellsWithSpace, true) }, "Merge cells")),
117
+ isCellSelectionMerged && (react_1.default.createElement(ActionButton, { onClick: () => runCommand(prosemirror_tables_1.mergeCells, true) }, "Merge cells")),
118
118
  isCellSelectionSplittable && (react_1.default.createElement(ActionButton, { onClick: () => runCommand(prosemirror_tables_1.splitCell, true) }, "Split cells")),
119
119
  react_1.default.createElement(ColumnChangeWarningDialog, { isOpen: !!columnAction, primaryAction: () => {
120
120
  if (columnAction) {
@@ -49,6 +49,7 @@ const createEditorView = (props, root, state, dispatch) => {
49
49
  dispatchTransaction: dispatch,
50
50
  nodeViews: (0, editor_views_1.default)(props, dispatch),
51
51
  attributes: props.attributes,
52
+ transformPastedHTML: paste_1.transformPastedHTML,
52
53
  transformPasted: paste_1.transformPasted,
53
54
  handlePaste: paste_1.handlePaste,
54
55
  clipboardParser: clipboard_1.clipboardParser,
@@ -28,7 +28,6 @@ const box_element_1 = __importDefault(require("../views/box_element"));
28
28
  const citation_editable_1 = __importDefault(require("../views/citation_editable"));
29
29
  const contributors_1 = __importDefault(require("../views/contributors"));
30
30
  const cross_reference_editable_1 = __importDefault(require("../views/cross_reference_editable"));
31
- const embed_1 = __importDefault(require("../views/embed"));
32
31
  const empty_1 = __importDefault(require("../views/empty"));
33
32
  const equation_editable_1 = __importDefault(require("../views/equation_editable"));
34
33
  const equation_element_editable_1 = __importDefault(require("../views/equation_element_editable"));
@@ -65,7 +64,6 @@ exports.default = (props, dispatch) => {
65
64
  cross_reference: (0, cross_reference_editable_1.default)(props, dispatch),
66
65
  contributors: (0, contributors_1.default)(props, dispatch),
67
66
  affiliations: (0, affiliations_1.default)(props, dispatch),
68
- embed: (0, embed_1.default)(props),
69
67
  equation: (0, equation_editable_1.default)(props),
70
68
  equation_element: (0, equation_element_editable_1.default)(props),
71
69
  figure: (0, figure_editable_1.default)(props, dispatch),
@@ -1,53 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformCopied = void 0;
4
- const transform_1 = require("@manuscripts/transform");
5
4
  const prosemirror_model_1 = require("prosemirror-model");
6
- const prosemirror_utils_1 = require("prosemirror-utils");
7
- const table_1 = require("./table");
8
- const transformCopied = (slice, view) => {
9
- var _a, _b, _c;
10
- const { state } = view;
11
- const cutDepth = Math.min(slice.openStart, slice.openEnd);
12
- const tableSlice = handleTableSelection(slice, view, cutDepth);
13
- if (tableSlice) {
14
- return tableSlice;
15
- }
16
- if (((_a = slice.content.firstChild) === null || _a === void 0 ? void 0 : _a.type.isBlock) ||
17
- ((_b = slice.content.lastChild) === null || _b === void 0 ? void 0 : _b.type.isBlock)) {
18
- let newSliceContent = [];
19
- (_c = slice.content.firstChild) === null || _c === void 0 ? void 0 : _c.descendants((node) => {
20
- var _a, _b;
21
- if (node.childCount > 1 ||
22
- (((_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.type) === transform_1.schema.nodes.table_element &&
23
- ((_b = node.content.lastChild) === null || _b === void 0 ? void 0 : _b.type) === transform_1.schema.nodes.table_element)) {
24
- newSliceContent = (0, table_1.updateSliceWithFullTableContent)(state, node.content);
25
- return false;
26
- }
27
- return true;
28
- });
29
- if (newSliceContent.length > 1) {
30
- return new prosemirror_model_1.Slice(prosemirror_model_1.Fragment.from(newSliceContent), 0, 0);
31
- }
32
- else {
33
- const updateSelection = handleTableSelection(new prosemirror_model_1.Slice(prosemirror_model_1.Fragment.from(newSliceContent), slice.openStart, slice.openEnd), view, 0);
34
- if (updateSelection) {
35
- return updateSelection;
36
- }
37
- }
5
+ const transformCopied = (slice) => {
6
+ var _a, _b;
7
+ if (slice.openStart !== slice.openEnd &&
8
+ (((_a = slice.content.firstChild) === null || _a === void 0 ? void 0 : _a.type.isBlock) ||
9
+ ((_b = slice.content.lastChild) === null || _b === void 0 ? void 0 : _b.type.isBlock))) {
10
+ const cutDepth = Math.min(slice.openStart, slice.openEnd);
11
+ return new prosemirror_model_1.Slice(slice.content, cutDepth, cutDepth);
38
12
  }
39
13
  return slice;
40
14
  };
41
15
  exports.transformCopied = transformCopied;
42
- const handleTableSelection = (slice, view, cutDepth) => {
43
- var _a, _b;
44
- if ((!view.props.handleKeyDown || !view.state.selection.empty) &&
45
- (((_a = slice.content.firstChild) === null || _a === void 0 ? void 0 : _a.type) === transform_1.schema.nodes.table ||
46
- ((_b = slice.content.firstChild) === null || _b === void 0 ? void 0 : _b.type) === transform_1.schema.nodes.table_element)) {
47
- const tableElement = (0, prosemirror_utils_1.findParentNodeOfType)(transform_1.schema.nodes.table_element)(view.state.selection);
48
- if (tableElement) {
49
- return (0, table_1.handleTableSlice)(view, cutDepth, tableElement);
50
- }
51
- }
52
- return null;
53
- };
@@ -15,12 +15,11 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.handlePaste = exports.transformPasted = void 0;
18
+ exports.handlePaste = exports.transformPastedHTML = exports.transformPasted = void 0;
19
19
  const transform_1 = require("@manuscripts/transform");
20
20
  const prosemirror_model_1 = require("prosemirror-model");
21
21
  const prosemirror_state_1 = require("prosemirror-state");
22
22
  const prosemirror_utils_1 = require("prosemirror-utils");
23
- const table_1 = require("./table");
24
23
  const removeFirstParagraphIfEmpty = (slice) => {
25
24
  const firstChild = slice.content.firstChild;
26
25
  if (firstChild &&
@@ -49,6 +48,24 @@ const transformPasted = (slice) => {
49
48
  return slice;
50
49
  };
51
50
  exports.transformPasted = transformPasted;
51
+ const transformPastedHTML = (html) => {
52
+ if (html.includes('table')) {
53
+ const doc = new DOMParser().parseFromString(html, 'text/html');
54
+ doc.querySelectorAll('table').forEach((table) => {
55
+ var _a, _b;
56
+ if (((_a = table.parentElement) === null || _a === void 0 ? void 0 : _a.tagName) !== 'figure') {
57
+ const tableElement = document.createElement('figure');
58
+ tableElement.className = 'table';
59
+ table.removeAttribute('data-pm-slice');
60
+ (_b = table.parentElement) === null || _b === void 0 ? void 0 : _b.insertBefore(tableElement, table);
61
+ tableElement.append(table);
62
+ }
63
+ });
64
+ return doc.body.innerHTML;
65
+ }
66
+ return html;
67
+ };
68
+ exports.transformPastedHTML = transformPastedHTML;
52
69
  const handlePaste = (view, event, slice) => {
53
70
  var _a;
54
71
  if (event.type !== 'paste') {
@@ -65,16 +82,6 @@ const handlePaste = (view, event, slice) => {
65
82
  dispatch(tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, insertPos)).scrollIntoView());
66
83
  return true;
67
84
  }
68
- if (slice.content.firstChild &&
69
- (slice.content.firstChild.type == transform_1.schema.nodes.table_row ||
70
- slice.content.firstChild.type == transform_1.schema.nodes.table_cell)) {
71
- const newTable = (0, table_1.createTableFromSlice)(slice, view.state.schema);
72
- if (newTable) {
73
- const tr = view.state.tr.insert(view.state.selection.$anchor.pos, newTable);
74
- view.dispatch(tr);
75
- return true;
76
- }
77
- }
78
85
  if (selection instanceof prosemirror_state_1.TextSelection &&
79
86
  selection.$anchor.parentOffset === 0 &&
80
87
  selection.$head.parentOffset === 0 &&
@@ -82,7 +89,7 @@ const handlePaste = (view, event, slice) => {
82
89
  const { $from, $to } = selection;
83
90
  const side = (!$from.parentOffset && $to.index() < $to.parent.childCount ? $from : $to)
84
91
  .pos - 1;
85
- tr.insert(side, slice.content);
92
+ tr.replace(side, side, slice);
86
93
  dispatch(tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, side + 1)).scrollIntoView());
87
94
  return true;
88
95
  }
package/dist/cjs/menus.js CHANGED
@@ -20,7 +20,6 @@ const transform_1 = require("@manuscripts/transform");
20
20
  const prosemirror_commands_1 = require("prosemirror-commands");
21
21
  const prosemirror_history_1 = require("prosemirror-history");
22
22
  const commands_1 = require("./commands");
23
- const InsertEmbedDialog_1 = require("./components/toolbar/InsertEmbedDialog");
24
23
  const InsertTableDialog_1 = require("./components/toolbar/InsertTableDialog");
25
24
  const ListMenuItem_1 = require("./components/toolbar/ListMenuItem");
26
25
  const hierarchy_1 = require("./lib/hierarchy");
@@ -206,13 +205,6 @@ const getEditorMenus = (editor) => {
206
205
  {
207
206
  role: 'separator',
208
207
  },
209
- {
210
- id: 'insert-embed-media',
211
- label: 'Embedded Media',
212
- isActive: (0, commands_1.blockActive)(transform_1.schema.nodes.embed)(state),
213
- isEnabled: isCommandValid((0, commands_1.canInsert)(transform_1.schema.nodes.embed)),
214
- run: () => (0, InsertEmbedDialog_1.openEmbedDialog)(editor.view),
215
- },
216
208
  {
217
209
  id: 'insert-link',
218
210
  label: 'Link',
@@ -1,10 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
4
+ const transform_1 = require("@manuscripts/transform");
4
5
  const prosemirror_state_1 = require("prosemirror-state");
6
+ const prosemirror_tables_1 = require("prosemirror-tables");
7
+ const prosemirror_utils_1 = require("prosemirror-utils");
8
+ const commands_1 = require("../commands");
5
9
  exports.default = () => {
6
10
  return new prosemirror_state_1.Plugin({
7
11
  appendTransaction: (transactions, oldState, newState) => {
12
+ if ((0, commands_1.isTextSelection)(newState.selection) &&
13
+ !oldState.selection.eq(newState.selection)) {
14
+ const slice = newState.selection.$from.doc.slice(newState.selection.from, newState.selection.to);
15
+ const selectionTable = getTable(slice.content);
16
+ const selection = addTableElementToSelection(newState, selectionTable);
17
+ if (selection) {
18
+ const newTr = newState.tr;
19
+ newTr.setSelection(selection);
20
+ return newTr;
21
+ }
22
+ }
23
+ if (isTableShapeSelected(newState) &&
24
+ !oldState.selection.eq(newState.selection)) {
25
+ const contentNode = (0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)(newState.selection.$from, transform_1.schema.nodes.table_element);
26
+ if (contentNode) {
27
+ const newTr = newState.tr;
28
+ newTr.setSelection(prosemirror_state_1.TextSelection.create(newState.doc, contentNode.pos, contentNode.pos + contentNode.node.nodeSize));
29
+ return newTr;
30
+ }
31
+ }
8
32
  const tablesFixedTr = transactions.find((tr) => tr.getMeta('fix-tables$'));
9
33
  if (!tablesFixedTr) {
10
34
  return null;
@@ -17,3 +41,35 @@ exports.default = () => {
17
41
  },
18
42
  });
19
43
  };
44
+ const isTableShapeSelected = (state) => {
45
+ if (state.selection instanceof prosemirror_tables_1.CellSelection) {
46
+ const rect = (0, prosemirror_tables_1.selectedRect)(state);
47
+ return rect.bottom === rect.map.height && rect.right === rect.map.width;
48
+ }
49
+ return false;
50
+ };
51
+ const getTable = (fragment) => {
52
+ let table;
53
+ fragment === null || fragment === void 0 ? void 0 : fragment.descendants((node) => {
54
+ if ((node === null || node === void 0 ? void 0 : node.type) === transform_1.schema.nodes.table) {
55
+ table = node;
56
+ return false;
57
+ }
58
+ });
59
+ return table;
60
+ };
61
+ const addTableElementToSelection = (state, selectedTable) => {
62
+ var _a;
63
+ const { doc, selection } = state;
64
+ const fromContentNode = (0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)(selection.$from, transform_1.schema.nodes.table_element);
65
+ const toContentNode = (0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)(selection.$to, transform_1.schema.nodes.table_element);
66
+ const docTableElement = (fromContentNode === null || fromContentNode === void 0 ? void 0 : fromContentNode.node) || (toContentNode === null || toContentNode === void 0 ? void 0 : toContentNode.node);
67
+ if ((selectedTable === null || selectedTable === void 0 ? void 0 : selectedTable.nodeSize) !== ((_a = getTable(docTableElement === null || docTableElement === void 0 ? void 0 : docTableElement.content)) === null || _a === void 0 ? void 0 : _a.nodeSize)) {
68
+ return undefined;
69
+ }
70
+ const from = ((fromContentNode && toContentNode) || fromContentNode) &&
71
+ fromContentNode.pos;
72
+ const to = ((fromContentNode && toContentNode) || toContentNode) &&
73
+ toContentNode.pos + toContentNode.node.nodeSize;
74
+ return prosemirror_state_1.TextSelection.create(doc, from || selection.from, to || selection.to);
75
+ };
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MATHJAX_VERSION = exports.VERSION = void 0;
4
- exports.VERSION = '2.7.3-LEAN-4218.0';
4
+ exports.VERSION = '2.7.3';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -19,7 +19,7 @@ import { generateNodeID, isElementNodeType, isListNode, isSectionNodeType, isTab
19
19
  import { Fragment, NodeRange, Slice, } from 'prosemirror-model';
20
20
  import { wrapInList } from 'prosemirror-schema-list';
21
21
  import { NodeSelection, TextSelection, } from 'prosemirror-state';
22
- import { addColSpan, addColumnAfter, addColumnBefore, addRow, CellSelection, selectedRect, } from 'prosemirror-tables';
22
+ import { addColumnAfter, addColumnBefore, addRow, selectedRect, } from 'prosemirror-tables';
23
23
  import { findWrapping, liftTarget, ReplaceAroundStep, ReplaceStep, } from 'prosemirror-transform';
24
24
  import { findChildrenByType, findParentNodeOfType, findParentNodeOfTypeClosestToPos, flatten, hasParentNodeOfType, } from 'prosemirror-utils';
25
25
  import { getCommentKey, getCommentRange } from './lib/comments';
@@ -35,7 +35,8 @@ export const addToStart = (state, dispatch) => {
35
35
  const { selection } = state;
36
36
  if (!dispatch ||
37
37
  !(selection instanceof TextSelection) ||
38
- selection.$from.node().type !== schema.nodes.paragraph) {
38
+ (selection.$from.node().type !== schema.nodes.paragraph &&
39
+ selection.$from.node().type !== schema.nodes.text_block)) {
39
40
  return false;
40
41
  }
41
42
  const { $anchor: { parentOffset: startOffset }, $head: { parentOffset: endOffset }, $from, $to, } = selection;
@@ -49,10 +50,9 @@ export const addToStart = (state, dispatch) => {
49
50
  const from = $from.node().type.createAndFill();
50
51
  if (from) {
51
52
  tr.insert(side, from);
53
+ dispatch(tr.scrollIntoView());
54
+ return true;
52
55
  }
53
- tr.setSelection(TextSelection.create(tr.doc, side + 1));
54
- dispatch(tr.scrollIntoView());
55
- return true;
56
56
  }
57
57
  return false;
58
58
  };
@@ -141,11 +141,6 @@ export const createBlock = (nodeType, position, state, dispatch, attrs) => {
141
141
  state.schema.nodes.equation.create(),
142
142
  ]);
143
143
  break;
144
- case state.schema.nodes.embed:
145
- node = state.schema.nodes.embed.create(attrs, [
146
- createAndFillFigcaptionElement(state),
147
- ]);
148
- break;
149
144
  default:
150
145
  node = nodeType.createAndFill(attrs);
151
146
  }
@@ -155,14 +150,6 @@ export const createBlock = (nodeType, position, state, dispatch, attrs) => {
155
150
  dispatch(tr.setSelection(selection).scrollIntoView());
156
151
  }
157
152
  };
158
- export const insertEmbed = (state, dispatch, attrs) => {
159
- const position = findBlockInsertPosition(state);
160
- if (position === null) {
161
- return false;
162
- }
163
- createBlock(schema.nodes.embed, position, state, dispatch, attrs);
164
- return true;
165
- };
166
153
  export const insertInlineTableFootnote = (state, dispatch) => {
167
154
  const $pos = state.selection.$to;
168
155
  const table = findParentNodeOfTypeClosestToPos($pos, schema.nodes.table);
@@ -899,7 +886,7 @@ const DEFAULT_TABLE_CONFIG = {
899
886
  export const createAndFillTableElement = (state, config = DEFAULT_TABLE_CONFIG) => {
900
887
  const { numberOfColumns, numberOfRows, includeHeader } = config;
901
888
  const createRow = (cellType) => {
902
- const cells = Array.from({ length: numberOfColumns }, () => cellType.create());
889
+ const cells = Array.from({ length: numberOfColumns }, () => cellType.create({}, schema.nodes.text_block.create()));
903
890
  return schema.nodes.table_row.create({}, cells);
904
891
  };
905
892
  const tableRows = includeHeader ? [createRow(schema.nodes.table_header)] : [];
@@ -1063,82 +1050,6 @@ export const addColumns = (direction) => (state, dispatch) => {
1063
1050
  }
1064
1051
  return true;
1065
1052
  };
1066
- function isEmpty(cell) {
1067
- const c = cell.content;
1068
- return (c.childCount == 1 && c.child(0).isTextblock && c.child(0).childCount == 0);
1069
- }
1070
- function cellsOverlapRectangle({ width, height, map }, rect) {
1071
- let indexTop = rect.top * width + rect.left, indexLeft = indexTop;
1072
- let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);
1073
- for (let i = rect.top; i < rect.bottom; i++) {
1074
- if ((rect.left > 0 && map[indexLeft] == map[indexLeft - 1]) ||
1075
- (rect.right < width && map[indexRight] == map[indexRight + 1])) {
1076
- return true;
1077
- }
1078
- indexLeft += width;
1079
- indexRight += width;
1080
- }
1081
- for (let i = rect.left; i < rect.right; i++) {
1082
- if ((rect.top > 0 && map[indexTop] == map[indexTop - width]) ||
1083
- (rect.bottom < height && map[indexBottom] == map[indexBottom + width])) {
1084
- return true;
1085
- }
1086
- indexTop++;
1087
- indexBottom++;
1088
- }
1089
- return false;
1090
- }
1091
- export function mergeCellsWithSpace(state, dispatch) {
1092
- const sel = state.selection;
1093
- if (!(sel instanceof CellSelection) ||
1094
- sel.$anchorCell.pos == sel.$headCell.pos) {
1095
- return false;
1096
- }
1097
- const rect = selectedRect(state), { map } = rect;
1098
- if (cellsOverlapRectangle(map, rect)) {
1099
- return false;
1100
- }
1101
- if (dispatch) {
1102
- const tr = state.tr;
1103
- const seen = {};
1104
- let content = Fragment.empty;
1105
- let mergedPos;
1106
- let mergedCell;
1107
- for (let row = rect.top; row < rect.bottom; row++) {
1108
- for (let col = rect.left; col < rect.right; col++) {
1109
- const cellPos = map.map[row * map.width + col];
1110
- const cell = rect.table.nodeAt(cellPos);
1111
- if (seen[cellPos] || !cell) {
1112
- continue;
1113
- }
1114
- seen[cellPos] = true;
1115
- if (mergedPos == null) {
1116
- mergedPos = cellPos;
1117
- mergedCell = cell;
1118
- }
1119
- else {
1120
- if (!isEmpty(cell)) {
1121
- content = content.append(cell.content.addToStart(cell.type.schema.text(' ')));
1122
- }
1123
- const mapped = tr.mapping.map(cellPos + rect.tableStart);
1124
- tr.delete(mapped, mapped + cell.nodeSize);
1125
- }
1126
- }
1127
- }
1128
- if (mergedPos == null || mergedCell == null) {
1129
- return true;
1130
- }
1131
- tr.setNodeMarkup(mergedPos + rect.tableStart, null, Object.assign(Object.assign({}, addColSpan(mergedCell.attrs, mergedCell.attrs.colspan, rect.right - rect.left - mergedCell.attrs.colspan)), { rowspan: rect.bottom - rect.top }));
1132
- if (content.size) {
1133
- const end = mergedPos + 1 + mergedCell.content.size;
1134
- const start = isEmpty(mergedCell) ? mergedPos + 1 : end;
1135
- tr.replaceWith(start + rect.tableStart, end + rect.tableStart, content);
1136
- }
1137
- tr.setSelection(new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart)));
1138
- dispatch(tr);
1139
- }
1140
- return true;
1141
- }
1142
1053
  export const autoComplete = (state, dispatch) => {
1143
1054
  const complete = checkForCompletion(state);
1144
1055
  if (complete) {
@@ -37,7 +37,7 @@ const ActionGroup = styled.span `
37
37
  const Field = styled.div `
38
38
  margin-bottom: ${(props) => props.theme.grid.unit * 4}px;
39
39
  `;
40
- export const FieldHeading = styled.div `
40
+ const FieldHeading = styled.div `
41
41
  display: flex;
42
42
  align-items: center;
43
43
  justify-content: space-between;
@@ -49,7 +49,7 @@ const Label = styled.label `
49
49
  color: ${(props) => props.theme.colors.text.tertiary};
50
50
  font-size: ${(props) => props.theme.font.size.normal};
51
51
  `;
52
- export const Open = styled.a `
52
+ const Open = styled.a `
53
53
  display: inline-block;
54
54
  margin-left: ${(props) => props.theme.grid.unit * 2}px;
55
55
  text-transform: uppercase;
@@ -4,7 +4,7 @@ import { schema } from '@manuscripts/transform';
4
4
  import { CellSelection, deleteColumn, deleteRow, mergeCells, selectedRect, splitCell, } from 'prosemirror-tables';
5
5
  import React, { useState } from 'react';
6
6
  import styled from 'styled-components';
7
- import { addColumns, addHeaderRow, addRows, mergeCellsWithSpace, } from '../../commands';
7
+ import { addColumns, addHeaderRow, addRows } from '../../commands';
8
8
  const getSelectedCellsCount = (state) => {
9
9
  const { selection } = state;
10
10
  const selectedCells = { rows: 1, columns: 1 };
@@ -85,7 +85,7 @@ export const ContextMenu = ({ view, close, onCancelColumnDialog }) => {
85
85
  " Delete ",
86
86
  columns),
87
87
  (isCellSelectionMerged || isCellSelectionSplittable) && React.createElement(Separator, null),
88
- isCellSelectionMerged && (React.createElement(ActionButton, { onClick: () => runCommand(mergeCellsWithSpace, true) }, "Merge cells")),
88
+ isCellSelectionMerged && (React.createElement(ActionButton, { onClick: () => runCommand(mergeCells, true) }, "Merge cells")),
89
89
  isCellSelectionSplittable && (React.createElement(ActionButton, { onClick: () => runCommand(splitCell, true) }, "Split cells")),
90
90
  React.createElement(ColumnChangeWarningDialog, { isOpen: !!columnAction, primaryAction: () => {
91
91
  if (columnAction) {