@manuscripts/body-editor 2.7.0 → 2.7.1-LEAN-3837.0
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.
- package/dist/cjs/commands.js +2 -79
- package/dist/cjs/components/views/TableCellContextMenu.js +1 -1
- package/dist/cjs/configs/ManuscriptsEditor.js +1 -0
- package/dist/cjs/lib/copy.js +7 -45
- package/dist/cjs/lib/paste.js +21 -13
- package/dist/cjs/plugins/tables-cursor-fix.js +56 -0
- package/dist/cjs/versions.js +1 -1
- package/dist/es/commands.js +2 -78
- package/dist/es/components/views/TableCellContextMenu.js +2 -2
- package/dist/es/configs/ManuscriptsEditor.js +2 -1
- package/dist/es/lib/copy.js +8 -46
- package/dist/es/lib/paste.js +19 -12
- package/dist/es/plugins/tables-cursor-fix.js +56 -0
- package/dist/es/versions.js +1 -1
- package/dist/types/commands.d.ts +0 -1
- package/dist/types/lib/copy.d.ts +1 -2
- package/dist/types/lib/paste.d.ts +1 -0
- package/dist/types/versions.d.ts +1 -1
- package/package.json +3 -3
- package/styles/Editor.css +4 -0
- package/dist/cjs/lib/table.js +0 -55
- package/dist/es/lib/table.js +0 -48
- package/dist/types/lib/table.d.ts +0 -9
package/dist/cjs/commands.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.autoComplete = exports.
|
|
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;
|
|
19
19
|
const json_schema_1 = require("@manuscripts/json-schema");
|
|
20
20
|
const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
|
|
21
21
|
const transform_1 = require("@manuscripts/transform");
|
|
@@ -931,7 +931,7 @@ const DEFAULT_TABLE_CONFIG = {
|
|
|
931
931
|
const createAndFillTableElement = (state, config = DEFAULT_TABLE_CONFIG) => {
|
|
932
932
|
const { numberOfColumns, numberOfRows, includeHeader } = config;
|
|
933
933
|
const createRow = (cellType) => {
|
|
934
|
-
const cells = Array.from({ length: numberOfColumns }, () => cellType.create());
|
|
934
|
+
const cells = Array.from({ length: numberOfColumns }, () => cellType.create({}, transform_1.schema.nodes.paragraph.create()));
|
|
935
935
|
return transform_1.schema.nodes.table_row.create({}, cells);
|
|
936
936
|
};
|
|
937
937
|
const tableRows = includeHeader ? [createRow(transform_1.schema.nodes.table_header)] : [];
|
|
@@ -1101,83 +1101,6 @@ const addColumns = (direction) => (state, dispatch) => {
|
|
|
1101
1101
|
return true;
|
|
1102
1102
|
};
|
|
1103
1103
|
exports.addColumns = addColumns;
|
|
1104
|
-
function isEmpty(cell) {
|
|
1105
|
-
const c = cell.content;
|
|
1106
|
-
return (c.childCount == 1 && c.child(0).isTextblock && c.child(0).childCount == 0);
|
|
1107
|
-
}
|
|
1108
|
-
function cellsOverlapRectangle({ width, height, map }, rect) {
|
|
1109
|
-
let indexTop = rect.top * width + rect.left, indexLeft = indexTop;
|
|
1110
|
-
let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);
|
|
1111
|
-
for (let i = rect.top; i < rect.bottom; i++) {
|
|
1112
|
-
if ((rect.left > 0 && map[indexLeft] == map[indexLeft - 1]) ||
|
|
1113
|
-
(rect.right < width && map[indexRight] == map[indexRight + 1])) {
|
|
1114
|
-
return true;
|
|
1115
|
-
}
|
|
1116
|
-
indexLeft += width;
|
|
1117
|
-
indexRight += width;
|
|
1118
|
-
}
|
|
1119
|
-
for (let i = rect.left; i < rect.right; i++) {
|
|
1120
|
-
if ((rect.top > 0 && map[indexTop] == map[indexTop - width]) ||
|
|
1121
|
-
(rect.bottom < height && map[indexBottom] == map[indexBottom + width])) {
|
|
1122
|
-
return true;
|
|
1123
|
-
}
|
|
1124
|
-
indexTop++;
|
|
1125
|
-
indexBottom++;
|
|
1126
|
-
}
|
|
1127
|
-
return false;
|
|
1128
|
-
}
|
|
1129
|
-
function mergeCellsWithSpace(state, dispatch) {
|
|
1130
|
-
const sel = state.selection;
|
|
1131
|
-
if (!(sel instanceof prosemirror_tables_1.CellSelection) ||
|
|
1132
|
-
sel.$anchorCell.pos == sel.$headCell.pos) {
|
|
1133
|
-
return false;
|
|
1134
|
-
}
|
|
1135
|
-
const rect = (0, prosemirror_tables_1.selectedRect)(state), { map } = rect;
|
|
1136
|
-
if (cellsOverlapRectangle(map, rect)) {
|
|
1137
|
-
return false;
|
|
1138
|
-
}
|
|
1139
|
-
if (dispatch) {
|
|
1140
|
-
const tr = state.tr;
|
|
1141
|
-
const seen = {};
|
|
1142
|
-
let content = prosemirror_model_1.Fragment.empty;
|
|
1143
|
-
let mergedPos;
|
|
1144
|
-
let mergedCell;
|
|
1145
|
-
for (let row = rect.top; row < rect.bottom; row++) {
|
|
1146
|
-
for (let col = rect.left; col < rect.right; col++) {
|
|
1147
|
-
const cellPos = map.map[row * map.width + col];
|
|
1148
|
-
const cell = rect.table.nodeAt(cellPos);
|
|
1149
|
-
if (seen[cellPos] || !cell) {
|
|
1150
|
-
continue;
|
|
1151
|
-
}
|
|
1152
|
-
seen[cellPos] = true;
|
|
1153
|
-
if (mergedPos == null) {
|
|
1154
|
-
mergedPos = cellPos;
|
|
1155
|
-
mergedCell = cell;
|
|
1156
|
-
}
|
|
1157
|
-
else {
|
|
1158
|
-
if (!isEmpty(cell)) {
|
|
1159
|
-
content = content.append(cell.content.addToStart(cell.type.schema.text(' ')));
|
|
1160
|
-
}
|
|
1161
|
-
const mapped = tr.mapping.map(cellPos + rect.tableStart);
|
|
1162
|
-
tr.delete(mapped, mapped + cell.nodeSize);
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
if (mergedPos == null || mergedCell == null) {
|
|
1167
|
-
return true;
|
|
1168
|
-
}
|
|
1169
|
-
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 }));
|
|
1170
|
-
if (content.size) {
|
|
1171
|
-
const end = mergedPos + 1 + mergedCell.content.size;
|
|
1172
|
-
const start = isEmpty(mergedCell) ? mergedPos + 1 : end;
|
|
1173
|
-
tr.replaceWith(start + rect.tableStart, end + rect.tableStart, content);
|
|
1174
|
-
}
|
|
1175
|
-
tr.setSelection(new prosemirror_tables_1.CellSelection(tr.doc.resolve(mergedPos + rect.tableStart)));
|
|
1176
|
-
dispatch(tr);
|
|
1177
|
-
}
|
|
1178
|
-
return true;
|
|
1179
|
-
}
|
|
1180
|
-
exports.mergeCellsWithSpace = mergeCellsWithSpace;
|
|
1181
1104
|
const autoComplete = (state, dispatch) => {
|
|
1182
1105
|
const complete = (0, autocompletion_1.checkForCompletion)(state);
|
|
1183
1106
|
if (complete) {
|
|
@@ -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(
|
|
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,
|
package/dist/cjs/lib/copy.js
CHANGED
|
@@ -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
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
};
|
package/dist/cjs/lib/paste.js
CHANGED
|
@@ -15,12 +15,12 @@
|
|
|
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
|
|
23
|
+
const prosemirror_transform_1 = require("prosemirror-transform");
|
|
24
24
|
const removeFirstParagraphIfEmpty = (slice) => {
|
|
25
25
|
const firstChild = slice.content.firstChild;
|
|
26
26
|
if (firstChild &&
|
|
@@ -49,6 +49,24 @@ const transformPasted = (slice) => {
|
|
|
49
49
|
return slice;
|
|
50
50
|
};
|
|
51
51
|
exports.transformPasted = transformPasted;
|
|
52
|
+
const transformPastedHTML = (html) => {
|
|
53
|
+
if (html.includes('table')) {
|
|
54
|
+
const doc = new DOMParser().parseFromString(html, 'text/html');
|
|
55
|
+
doc.querySelectorAll('table').forEach((table) => {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
if (((_a = table.parentElement) === null || _a === void 0 ? void 0 : _a.tagName) !== 'figure') {
|
|
58
|
+
const tableElement = document.createElement('figure');
|
|
59
|
+
tableElement.className = 'table';
|
|
60
|
+
table.removeAttribute('data-pm-slice');
|
|
61
|
+
(_b = table.parentElement) === null || _b === void 0 ? void 0 : _b.insertBefore(tableElement, table);
|
|
62
|
+
tableElement.append(table);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return doc.body.innerHTML;
|
|
66
|
+
}
|
|
67
|
+
return html;
|
|
68
|
+
};
|
|
69
|
+
exports.transformPastedHTML = transformPastedHTML;
|
|
52
70
|
const handlePaste = (view, event, slice) => {
|
|
53
71
|
var _a;
|
|
54
72
|
if (event.type !== 'paste') {
|
|
@@ -65,16 +83,6 @@ const handlePaste = (view, event, slice) => {
|
|
|
65
83
|
dispatch(tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, insertPos)).scrollIntoView());
|
|
66
84
|
return true;
|
|
67
85
|
}
|
|
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
86
|
if (selection instanceof prosemirror_state_1.TextSelection &&
|
|
79
87
|
selection.$anchor.parentOffset === 0 &&
|
|
80
88
|
selection.$head.parentOffset === 0 &&
|
|
@@ -82,7 +90,7 @@ const handlePaste = (view, event, slice) => {
|
|
|
82
90
|
const { $from, $to } = selection;
|
|
83
91
|
const side = (!$from.parentOffset && $to.index() < $to.parent.childCount ? $from : $to)
|
|
84
92
|
.pos - 1;
|
|
85
|
-
tr.
|
|
93
|
+
tr.step(new prosemirror_transform_1.ReplaceStep(side, side, slice));
|
|
86
94
|
dispatch(tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, side + 1)).scrollIntoView());
|
|
87
95
|
return true;
|
|
88
96
|
}
|
|
@@ -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
|
+
};
|
package/dist/cjs/versions.js
CHANGED
package/dist/es/commands.js
CHANGED
|
@@ -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 {
|
|
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';
|
|
@@ -886,7 +886,7 @@ const DEFAULT_TABLE_CONFIG = {
|
|
|
886
886
|
export const createAndFillTableElement = (state, config = DEFAULT_TABLE_CONFIG) => {
|
|
887
887
|
const { numberOfColumns, numberOfRows, includeHeader } = config;
|
|
888
888
|
const createRow = (cellType) => {
|
|
889
|
-
const cells = Array.from({ length: numberOfColumns }, () => cellType.create());
|
|
889
|
+
const cells = Array.from({ length: numberOfColumns }, () => cellType.create({}, schema.nodes.paragraph.create()));
|
|
890
890
|
return schema.nodes.table_row.create({}, cells);
|
|
891
891
|
};
|
|
892
892
|
const tableRows = includeHeader ? [createRow(schema.nodes.table_header)] : [];
|
|
@@ -1050,82 +1050,6 @@ export const addColumns = (direction) => (state, dispatch) => {
|
|
|
1050
1050
|
}
|
|
1051
1051
|
return true;
|
|
1052
1052
|
};
|
|
1053
|
-
function isEmpty(cell) {
|
|
1054
|
-
const c = cell.content;
|
|
1055
|
-
return (c.childCount == 1 && c.child(0).isTextblock && c.child(0).childCount == 0);
|
|
1056
|
-
}
|
|
1057
|
-
function cellsOverlapRectangle({ width, height, map }, rect) {
|
|
1058
|
-
let indexTop = rect.top * width + rect.left, indexLeft = indexTop;
|
|
1059
|
-
let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);
|
|
1060
|
-
for (let i = rect.top; i < rect.bottom; i++) {
|
|
1061
|
-
if ((rect.left > 0 && map[indexLeft] == map[indexLeft - 1]) ||
|
|
1062
|
-
(rect.right < width && map[indexRight] == map[indexRight + 1])) {
|
|
1063
|
-
return true;
|
|
1064
|
-
}
|
|
1065
|
-
indexLeft += width;
|
|
1066
|
-
indexRight += width;
|
|
1067
|
-
}
|
|
1068
|
-
for (let i = rect.left; i < rect.right; i++) {
|
|
1069
|
-
if ((rect.top > 0 && map[indexTop] == map[indexTop - width]) ||
|
|
1070
|
-
(rect.bottom < height && map[indexBottom] == map[indexBottom + width])) {
|
|
1071
|
-
return true;
|
|
1072
|
-
}
|
|
1073
|
-
indexTop++;
|
|
1074
|
-
indexBottom++;
|
|
1075
|
-
}
|
|
1076
|
-
return false;
|
|
1077
|
-
}
|
|
1078
|
-
export function mergeCellsWithSpace(state, dispatch) {
|
|
1079
|
-
const sel = state.selection;
|
|
1080
|
-
if (!(sel instanceof CellSelection) ||
|
|
1081
|
-
sel.$anchorCell.pos == sel.$headCell.pos) {
|
|
1082
|
-
return false;
|
|
1083
|
-
}
|
|
1084
|
-
const rect = selectedRect(state), { map } = rect;
|
|
1085
|
-
if (cellsOverlapRectangle(map, rect)) {
|
|
1086
|
-
return false;
|
|
1087
|
-
}
|
|
1088
|
-
if (dispatch) {
|
|
1089
|
-
const tr = state.tr;
|
|
1090
|
-
const seen = {};
|
|
1091
|
-
let content = Fragment.empty;
|
|
1092
|
-
let mergedPos;
|
|
1093
|
-
let mergedCell;
|
|
1094
|
-
for (let row = rect.top; row < rect.bottom; row++) {
|
|
1095
|
-
for (let col = rect.left; col < rect.right; col++) {
|
|
1096
|
-
const cellPos = map.map[row * map.width + col];
|
|
1097
|
-
const cell = rect.table.nodeAt(cellPos);
|
|
1098
|
-
if (seen[cellPos] || !cell) {
|
|
1099
|
-
continue;
|
|
1100
|
-
}
|
|
1101
|
-
seen[cellPos] = true;
|
|
1102
|
-
if (mergedPos == null) {
|
|
1103
|
-
mergedPos = cellPos;
|
|
1104
|
-
mergedCell = cell;
|
|
1105
|
-
}
|
|
1106
|
-
else {
|
|
1107
|
-
if (!isEmpty(cell)) {
|
|
1108
|
-
content = content.append(cell.content.addToStart(cell.type.schema.text(' ')));
|
|
1109
|
-
}
|
|
1110
|
-
const mapped = tr.mapping.map(cellPos + rect.tableStart);
|
|
1111
|
-
tr.delete(mapped, mapped + cell.nodeSize);
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
if (mergedPos == null || mergedCell == null) {
|
|
1116
|
-
return true;
|
|
1117
|
-
}
|
|
1118
|
-
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 }));
|
|
1119
|
-
if (content.size) {
|
|
1120
|
-
const end = mergedPos + 1 + mergedCell.content.size;
|
|
1121
|
-
const start = isEmpty(mergedCell) ? mergedPos + 1 : end;
|
|
1122
|
-
tr.replaceWith(start + rect.tableStart, end + rect.tableStart, content);
|
|
1123
|
-
}
|
|
1124
|
-
tr.setSelection(new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart)));
|
|
1125
|
-
dispatch(tr);
|
|
1126
|
-
}
|
|
1127
|
-
return true;
|
|
1128
|
-
}
|
|
1129
1053
|
export const autoComplete = (state, dispatch) => {
|
|
1130
1054
|
const complete = checkForCompletion(state);
|
|
1131
1055
|
if (complete) {
|
|
@@ -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
|
|
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(
|
|
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) {
|
|
@@ -20,7 +20,7 @@ import { EditorView } from 'prosemirror-view';
|
|
|
20
20
|
import { clipboardParser } from '../clipboard';
|
|
21
21
|
import { transformCopied } from '../lib/copy';
|
|
22
22
|
import { handleScrollToSelectedTarget } from '../lib/helpers';
|
|
23
|
-
import { handlePaste, transformPasted } from '../lib/paste';
|
|
23
|
+
import { handlePaste, transformPasted, transformPastedHTML } from '../lib/paste';
|
|
24
24
|
import { INIT_META } from '../lib/plugins';
|
|
25
25
|
import plugins from './editor-plugins';
|
|
26
26
|
import views from './editor-views';
|
|
@@ -42,6 +42,7 @@ export const createEditorView = (props, root, state, dispatch) => {
|
|
|
42
42
|
dispatchTransaction: dispatch,
|
|
43
43
|
nodeViews: views(props, dispatch),
|
|
44
44
|
attributes: props.attributes,
|
|
45
|
+
transformPastedHTML,
|
|
45
46
|
transformPasted,
|
|
46
47
|
handlePaste,
|
|
47
48
|
clipboardParser,
|
package/dist/es/lib/copy.js
CHANGED
|
@@ -1,49 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { findParentNodeOfType } from 'prosemirror-utils';
|
|
4
|
-
import { handleTableSlice, updateSliceWithFullTableContent } from './table';
|
|
5
|
-
export const transformCopied = (slice, view) => {
|
|
6
|
-
var _a, _b, _c;
|
|
7
|
-
const { state } = view;
|
|
8
|
-
const cutDepth = Math.min(slice.openStart, slice.openEnd);
|
|
9
|
-
const tableSlice = handleTableSelection(slice, view, cutDepth);
|
|
10
|
-
if (tableSlice) {
|
|
11
|
-
return tableSlice;
|
|
12
|
-
}
|
|
13
|
-
if (((_a = slice.content.firstChild) === null || _a === void 0 ? void 0 : _a.type.isBlock) ||
|
|
14
|
-
((_b = slice.content.lastChild) === null || _b === void 0 ? void 0 : _b.type.isBlock)) {
|
|
15
|
-
let newSliceContent = [];
|
|
16
|
-
(_c = slice.content.firstChild) === null || _c === void 0 ? void 0 : _c.descendants((node) => {
|
|
17
|
-
var _a, _b;
|
|
18
|
-
if (node.childCount > 1 ||
|
|
19
|
-
(((_a = node.content.firstChild) === null || _a === void 0 ? void 0 : _a.type) === schema.nodes.table_element &&
|
|
20
|
-
((_b = node.content.lastChild) === null || _b === void 0 ? void 0 : _b.type) === schema.nodes.table_element)) {
|
|
21
|
-
newSliceContent = updateSliceWithFullTableContent(state, node.content);
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
return true;
|
|
25
|
-
});
|
|
26
|
-
if (newSliceContent.length > 1) {
|
|
27
|
-
return new Slice(Fragment.from(newSliceContent), 0, 0);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
const updateSelection = handleTableSelection(new Slice(Fragment.from(newSliceContent), slice.openStart, slice.openEnd), view, 0);
|
|
31
|
-
if (updateSelection) {
|
|
32
|
-
return updateSelection;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return slice;
|
|
37
|
-
};
|
|
38
|
-
const handleTableSelection = (slice, view, cutDepth) => {
|
|
1
|
+
import { Slice } from 'prosemirror-model';
|
|
2
|
+
export const transformCopied = (slice) => {
|
|
39
3
|
var _a, _b;
|
|
40
|
-
if (
|
|
41
|
-
(((_a = slice.content.firstChild) === null || _a === void 0 ? void 0 : _a.type)
|
|
42
|
-
((_b = slice.content.
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
return handleTableSlice(view, cutDepth, tableElement);
|
|
46
|
-
}
|
|
4
|
+
if (slice.openStart !== slice.openEnd &&
|
|
5
|
+
(((_a = slice.content.firstChild) === null || _a === void 0 ? void 0 : _a.type.isBlock) ||
|
|
6
|
+
((_b = slice.content.lastChild) === null || _b === void 0 ? void 0 : _b.type.isBlock))) {
|
|
7
|
+
const cutDepth = Math.min(slice.openStart, slice.openEnd);
|
|
8
|
+
return new Slice(slice.content, cutDepth, cutDepth);
|
|
47
9
|
}
|
|
48
|
-
return
|
|
10
|
+
return slice;
|
|
49
11
|
};
|
package/dist/es/lib/paste.js
CHANGED
|
@@ -17,7 +17,7 @@ import { schema, } from '@manuscripts/transform';
|
|
|
17
17
|
import { Fragment } from 'prosemirror-model';
|
|
18
18
|
import { TextSelection } from 'prosemirror-state';
|
|
19
19
|
import { findParentNode } from 'prosemirror-utils';
|
|
20
|
-
import {
|
|
20
|
+
import { ReplaceStep } from "prosemirror-transform";
|
|
21
21
|
const removeFirstParagraphIfEmpty = (slice) => {
|
|
22
22
|
const firstChild = slice.content.firstChild;
|
|
23
23
|
if (firstChild &&
|
|
@@ -45,6 +45,23 @@ export const transformPasted = (slice) => {
|
|
|
45
45
|
removeIDs(slice);
|
|
46
46
|
return slice;
|
|
47
47
|
};
|
|
48
|
+
export const transformPastedHTML = (html) => {
|
|
49
|
+
if (html.includes('table')) {
|
|
50
|
+
const doc = new DOMParser().parseFromString(html, 'text/html');
|
|
51
|
+
doc.querySelectorAll('table').forEach((table) => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
if (((_a = table.parentElement) === null || _a === void 0 ? void 0 : _a.tagName) !== 'figure') {
|
|
54
|
+
const tableElement = document.createElement('figure');
|
|
55
|
+
tableElement.className = 'table';
|
|
56
|
+
table.removeAttribute('data-pm-slice');
|
|
57
|
+
(_b = table.parentElement) === null || _b === void 0 ? void 0 : _b.insertBefore(tableElement, table);
|
|
58
|
+
tableElement.append(table);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return doc.body.innerHTML;
|
|
62
|
+
}
|
|
63
|
+
return html;
|
|
64
|
+
};
|
|
48
65
|
export const handlePaste = (view, event, slice) => {
|
|
49
66
|
var _a;
|
|
50
67
|
if (event.type !== 'paste') {
|
|
@@ -61,16 +78,6 @@ export const handlePaste = (view, event, slice) => {
|
|
|
61
78
|
dispatch(tr.setSelection(TextSelection.create(tr.doc, insertPos)).scrollIntoView());
|
|
62
79
|
return true;
|
|
63
80
|
}
|
|
64
|
-
if (slice.content.firstChild &&
|
|
65
|
-
(slice.content.firstChild.type == schema.nodes.table_row ||
|
|
66
|
-
slice.content.firstChild.type == schema.nodes.table_cell)) {
|
|
67
|
-
const newTable = createTableFromSlice(slice, view.state.schema);
|
|
68
|
-
if (newTable) {
|
|
69
|
-
const tr = view.state.tr.insert(view.state.selection.$anchor.pos, newTable);
|
|
70
|
-
view.dispatch(tr);
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
81
|
if (selection instanceof TextSelection &&
|
|
75
82
|
selection.$anchor.parentOffset === 0 &&
|
|
76
83
|
selection.$head.parentOffset === 0 &&
|
|
@@ -78,7 +85,7 @@ export const handlePaste = (view, event, slice) => {
|
|
|
78
85
|
const { $from, $to } = selection;
|
|
79
86
|
const side = (!$from.parentOffset && $to.index() < $to.parent.childCount ? $from : $to)
|
|
80
87
|
.pos - 1;
|
|
81
|
-
tr.
|
|
88
|
+
tr.step(new ReplaceStep(side, side, slice));
|
|
82
89
|
dispatch(tr.setSelection(TextSelection.create(tr.doc, side + 1)).scrollIntoView());
|
|
83
90
|
return true;
|
|
84
91
|
}
|
|
@@ -1,8 +1,32 @@
|
|
|
1
1
|
import { skipTracking } from '@manuscripts/track-changes-plugin';
|
|
2
|
+
import { schema } from '@manuscripts/transform';
|
|
2
3
|
import { Plugin, TextSelection } from 'prosemirror-state';
|
|
4
|
+
import { CellSelection, selectedRect } from 'prosemirror-tables';
|
|
5
|
+
import { findParentNodeOfTypeClosestToPos } from 'prosemirror-utils';
|
|
6
|
+
import { isTextSelection } from '../commands';
|
|
3
7
|
export default () => {
|
|
4
8
|
return new Plugin({
|
|
5
9
|
appendTransaction: (transactions, oldState, newState) => {
|
|
10
|
+
if (isTextSelection(newState.selection) &&
|
|
11
|
+
!oldState.selection.eq(newState.selection)) {
|
|
12
|
+
const slice = newState.selection.$from.doc.slice(newState.selection.from, newState.selection.to);
|
|
13
|
+
const selectionTable = getTable(slice.content);
|
|
14
|
+
const selection = addTableElementToSelection(newState, selectionTable);
|
|
15
|
+
if (selection) {
|
|
16
|
+
const newTr = newState.tr;
|
|
17
|
+
newTr.setSelection(selection);
|
|
18
|
+
return newTr;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (isTableShapeSelected(newState) &&
|
|
22
|
+
!oldState.selection.eq(newState.selection)) {
|
|
23
|
+
const contentNode = findParentNodeOfTypeClosestToPos(newState.selection.$from, schema.nodes.table_element);
|
|
24
|
+
if (contentNode) {
|
|
25
|
+
const newTr = newState.tr;
|
|
26
|
+
newTr.setSelection(TextSelection.create(newState.doc, contentNode.pos, contentNode.pos + contentNode.node.nodeSize));
|
|
27
|
+
return newTr;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
6
30
|
const tablesFixedTr = transactions.find((tr) => tr.getMeta('fix-tables$'));
|
|
7
31
|
if (!tablesFixedTr) {
|
|
8
32
|
return null;
|
|
@@ -15,3 +39,35 @@ export default () => {
|
|
|
15
39
|
},
|
|
16
40
|
});
|
|
17
41
|
};
|
|
42
|
+
const isTableShapeSelected = (state) => {
|
|
43
|
+
if (state.selection instanceof CellSelection) {
|
|
44
|
+
const rect = selectedRect(state);
|
|
45
|
+
return rect.bottom === rect.map.height && rect.right === rect.map.width;
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
};
|
|
49
|
+
const getTable = (fragment) => {
|
|
50
|
+
let table;
|
|
51
|
+
fragment === null || fragment === void 0 ? void 0 : fragment.descendants((node) => {
|
|
52
|
+
if ((node === null || node === void 0 ? void 0 : node.type) === schema.nodes.table) {
|
|
53
|
+
table = node;
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return table;
|
|
58
|
+
};
|
|
59
|
+
const addTableElementToSelection = (state, selectedTable) => {
|
|
60
|
+
var _a;
|
|
61
|
+
const { doc, selection } = state;
|
|
62
|
+
const fromContentNode = findParentNodeOfTypeClosestToPos(selection.$from, schema.nodes.table_element);
|
|
63
|
+
const toContentNode = findParentNodeOfTypeClosestToPos(selection.$to, schema.nodes.table_element);
|
|
64
|
+
const docTableElement = (fromContentNode === null || fromContentNode === void 0 ? void 0 : fromContentNode.node) || (toContentNode === null || toContentNode === void 0 ? void 0 : toContentNode.node);
|
|
65
|
+
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)) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
const from = ((fromContentNode && toContentNode) || fromContentNode) &&
|
|
69
|
+
fromContentNode.pos;
|
|
70
|
+
const to = ((fromContentNode && toContentNode) || toContentNode) &&
|
|
71
|
+
toContentNode.pos + toContentNode.node.nodeSize;
|
|
72
|
+
return TextSelection.create(doc, from || selection.from, to || selection.to);
|
|
73
|
+
};
|
package/dist/es/versions.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '2.7.0';
|
|
1
|
+
export const VERSION = '2.7.1-LEAN-3837.0';
|
|
2
2
|
export const MATHJAX_VERSION = '3.2.2';
|
package/dist/types/commands.d.ts
CHANGED
|
@@ -76,5 +76,4 @@ export declare const addInlineComment: (state: ManuscriptEditorState, dispatch?:
|
|
|
76
76
|
export declare const addRows: (direction: 'top' | 'bottom') => (state: EditorState, dispatch?: ((tr: Transaction) => void) | undefined) => boolean;
|
|
77
77
|
export declare const addHeaderRow: (direction: 'above' | 'below') => (state: EditorState, dispatch?: ((tr: Transaction) => void) | undefined) => boolean;
|
|
78
78
|
export declare const addColumns: (direction: 'right' | 'left') => (state: EditorState, dispatch?: ((tr: Transaction) => void) | undefined) => boolean;
|
|
79
|
-
export declare function mergeCellsWithSpace(state: EditorState, dispatch?: (tr: Transaction) => void): boolean;
|
|
80
79
|
export declare const autoComplete: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
|
package/dist/types/lib/copy.d.ts
CHANGED
|
@@ -16,4 +16,5 @@
|
|
|
16
16
|
import { ManuscriptEditorView, ManuscriptSlice } from '@manuscripts/transform';
|
|
17
17
|
import { Slice } from 'prosemirror-model';
|
|
18
18
|
export declare const transformPasted: (slice: ManuscriptSlice) => ManuscriptSlice;
|
|
19
|
+
export declare const transformPastedHTML: (html: string) => string;
|
|
19
20
|
export declare const handlePaste: (view: ManuscriptEditorView, event: ClipboardEvent, slice: Slice) => boolean;
|
package/dist/types/versions.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "2.7.0";
|
|
1
|
+
export declare const VERSION = "2.7.1-LEAN-3837.0";
|
|
2
2
|
export declare const MATHJAX_VERSION = "3.2.2";
|
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": "2.7.0",
|
|
4
|
+
"version": "2.7.1-LEAN-3837.0",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"@manuscripts/json-schema": "2.2.11",
|
|
34
34
|
"@manuscripts/library": "1.3.11",
|
|
35
35
|
"@manuscripts/style-guide": "2.0.28",
|
|
36
|
-
"@manuscripts/track-changes-plugin": "1.9.0",
|
|
37
|
-
"@manuscripts/transform": "3.0.
|
|
36
|
+
"@manuscripts/track-changes-plugin": "1.9.1-LEAN-3837.0",
|
|
37
|
+
"@manuscripts/transform": "3.0.29-LEAN-3837.1",
|
|
38
38
|
"@popperjs/core": "^2.11.8",
|
|
39
39
|
"astrocite-eutils": "^0.16.4",
|
|
40
40
|
"codemirror": "^5.58.1",
|
package/styles/Editor.css
CHANGED
package/dist/cjs/lib/table.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateSliceWithFullTableContent = exports.findTableElement = exports.handleTableSlice = exports.createTableFromSlice = void 0;
|
|
4
|
-
const transform_1 = require("@manuscripts/transform");
|
|
5
|
-
const prosemirror_model_1 = require("prosemirror-model");
|
|
6
|
-
const prosemirror_state_1 = require("prosemirror-state");
|
|
7
|
-
const createTableFromSlice = (slice, schema) => {
|
|
8
|
-
const rows = [];
|
|
9
|
-
slice.content.forEach((node) => {
|
|
10
|
-
if (node.type === schema.nodes.table_row) {
|
|
11
|
-
rows.push(node);
|
|
12
|
-
}
|
|
13
|
-
else if (node.type === schema.nodes.table_cell) {
|
|
14
|
-
rows.push(schema.nodes.table_row.create(null, prosemirror_model_1.Fragment.from(node)));
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
if (rows.length > 0) {
|
|
18
|
-
return schema.nodes.table.create(null, rows);
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
21
|
-
};
|
|
22
|
-
exports.createTableFromSlice = createTableFromSlice;
|
|
23
|
-
const handleTableSlice = (view, cutDepth, tableElement) => {
|
|
24
|
-
const { node, pos } = tableElement;
|
|
25
|
-
view.dispatch(view.state.tr.setSelection(prosemirror_state_1.TextSelection.create(view.state.doc, pos, pos + node.nodeSize)));
|
|
26
|
-
return new prosemirror_model_1.Slice(prosemirror_model_1.Fragment.from(node), cutDepth, cutDepth);
|
|
27
|
-
};
|
|
28
|
-
exports.handleTableSlice = handleTableSlice;
|
|
29
|
-
const findTableElement = (state) => {
|
|
30
|
-
const { from, to } = state.selection;
|
|
31
|
-
let tableNode = null;
|
|
32
|
-
state.doc.nodesBetween(from, to, (node) => {
|
|
33
|
-
if (node.type === transform_1.schema.nodes.table_element) {
|
|
34
|
-
tableNode = node;
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
return true;
|
|
38
|
-
});
|
|
39
|
-
return { tableNode };
|
|
40
|
-
};
|
|
41
|
-
exports.findTableElement = findTableElement;
|
|
42
|
-
const updateSliceWithFullTableContent = (state, slice) => {
|
|
43
|
-
const newSliceContent = [];
|
|
44
|
-
slice.forEach((node) => {
|
|
45
|
-
if (node.type === transform_1.schema.nodes.table_element) {
|
|
46
|
-
const { tableNode } = (0, exports.findTableElement)(state);
|
|
47
|
-
tableNode && newSliceContent.push(tableNode);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
newSliceContent.push(node);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
return newSliceContent;
|
|
54
|
-
};
|
|
55
|
-
exports.updateSliceWithFullTableContent = updateSliceWithFullTableContent;
|
package/dist/es/lib/table.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { schema, } from '@manuscripts/transform';
|
|
2
|
-
import { Fragment, Slice } from 'prosemirror-model';
|
|
3
|
-
import { TextSelection } from 'prosemirror-state';
|
|
4
|
-
export const createTableFromSlice = (slice, schema) => {
|
|
5
|
-
const rows = [];
|
|
6
|
-
slice.content.forEach((node) => {
|
|
7
|
-
if (node.type === schema.nodes.table_row) {
|
|
8
|
-
rows.push(node);
|
|
9
|
-
}
|
|
10
|
-
else if (node.type === schema.nodes.table_cell) {
|
|
11
|
-
rows.push(schema.nodes.table_row.create(null, Fragment.from(node)));
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
if (rows.length > 0) {
|
|
15
|
-
return schema.nodes.table.create(null, rows);
|
|
16
|
-
}
|
|
17
|
-
return null;
|
|
18
|
-
};
|
|
19
|
-
export const handleTableSlice = (view, cutDepth, tableElement) => {
|
|
20
|
-
const { node, pos } = tableElement;
|
|
21
|
-
view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, pos, pos + node.nodeSize)));
|
|
22
|
-
return new Slice(Fragment.from(node), cutDepth, cutDepth);
|
|
23
|
-
};
|
|
24
|
-
export const findTableElement = (state) => {
|
|
25
|
-
const { from, to } = state.selection;
|
|
26
|
-
let tableNode = null;
|
|
27
|
-
state.doc.nodesBetween(from, to, (node) => {
|
|
28
|
-
if (node.type === schema.nodes.table_element) {
|
|
29
|
-
tableNode = node;
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
return true;
|
|
33
|
-
});
|
|
34
|
-
return { tableNode };
|
|
35
|
-
};
|
|
36
|
-
export const updateSliceWithFullTableContent = (state, slice) => {
|
|
37
|
-
const newSliceContent = [];
|
|
38
|
-
slice.forEach((node) => {
|
|
39
|
-
if (node.type === schema.nodes.table_element) {
|
|
40
|
-
const { tableNode } = findTableElement(state);
|
|
41
|
-
tableNode && newSliceContent.push(tableNode);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
newSliceContent.push(node);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
return newSliceContent;
|
|
48
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ManuscriptEditorState, ManuscriptEditorView } from '@manuscripts/transform';
|
|
2
|
-
import { Fragment, Node, Schema, Slice } from 'prosemirror-model';
|
|
3
|
-
import { ContentNodeWithPos } from 'prosemirror-utils';
|
|
4
|
-
export declare const createTableFromSlice: (slice: Slice, schema: Schema) => Node | null;
|
|
5
|
-
export declare const handleTableSlice: (view: ManuscriptEditorView, cutDepth: number, tableElement: ContentNodeWithPos) => Slice;
|
|
6
|
-
export declare const findTableElement: (state: ManuscriptEditorState) => {
|
|
7
|
-
tableNode: null;
|
|
8
|
-
};
|
|
9
|
-
export declare const updateSliceWithFullTableContent: (state: ManuscriptEditorState, slice: Fragment) => Node[];
|