@manuscripts/body-editor 1.13.25 → 1.13.26
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 +15 -4
- package/dist/cjs/components/views/TableCellContextMenu.js +23 -13
- package/dist/cjs/views/table_cell.js +15 -6
- package/dist/es/commands.js +14 -4
- package/dist/es/components/views/TableCellContextMenu.js +25 -15
- package/dist/es/views/table_cell.js +15 -6
- package/dist/types/commands.d.ts +1 -0
- package/dist/types/views/table_cell.d.ts +2 -0
- package/package.json +1 -1
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.addRows = exports.insertTableFootnote = 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.insertContributors = exports.insertAbstract = exports.insertBackMatterSection = exports.insertSection = exports.insertGraphicalAbstract = exports.insertInlineFootnote = exports.insertFootnote = exports.createFootnote = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertSupplement = exports.insertFigure = exports.insertGeneralFootnote = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = void 0;
|
|
18
|
+
exports.addColumns = exports.addRows = exports.insertTableFootnote = 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.insertContributors = exports.insertAbstract = exports.insertBackMatterSection = exports.insertSection = exports.insertGraphicalAbstract = exports.insertInlineFootnote = exports.insertFootnote = exports.createFootnote = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertSupplement = exports.insertFigure = exports.insertGeneralFootnote = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = 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");
|
|
@@ -982,9 +982,6 @@ const insertTableFootnote = (node, position, view, inlineFootnote) => {
|
|
|
982
982
|
};
|
|
983
983
|
exports.insertTableFootnote = insertTableFootnote;
|
|
984
984
|
const addRows = (direction) => (state, dispatch) => {
|
|
985
|
-
if (!(0, prosemirror_tables_1.isInTable)(state)) {
|
|
986
|
-
return false;
|
|
987
|
-
}
|
|
988
985
|
if (dispatch) {
|
|
989
986
|
const { tr } = state;
|
|
990
987
|
const rect = (0, prosemirror_tables_1.selectedRect)(state);
|
|
@@ -997,3 +994,17 @@ const addRows = (direction) => (state, dispatch) => {
|
|
|
997
994
|
return true;
|
|
998
995
|
};
|
|
999
996
|
exports.addRows = addRows;
|
|
997
|
+
const addColumns = (direction) => (state, dispatch) => {
|
|
998
|
+
if (dispatch) {
|
|
999
|
+
const { tr } = state;
|
|
1000
|
+
const rect = (0, prosemirror_tables_1.selectedRect)(state.apply(tr));
|
|
1001
|
+
const selectedRows = rect.right - rect.left;
|
|
1002
|
+
for (let i = 0; i < selectedRows; i++) {
|
|
1003
|
+
const command = direction === 'right' ? prosemirror_tables_1.addColumnAfter : prosemirror_tables_1.addColumnBefore;
|
|
1004
|
+
command(state.apply(tr), (t) => t.steps.map((s) => tr.step(s)));
|
|
1005
|
+
}
|
|
1006
|
+
dispatch(tr);
|
|
1007
|
+
}
|
|
1008
|
+
return true;
|
|
1009
|
+
};
|
|
1010
|
+
exports.addColumns = addColumns;
|
|
@@ -33,14 +33,19 @@ const prosemirror_tables_1 = require("prosemirror-tables");
|
|
|
33
33
|
const react_1 = __importStar(require("react"));
|
|
34
34
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
35
35
|
const commands_1 = require("../../commands");
|
|
36
|
-
const
|
|
36
|
+
const getSelectedCellsCount = (state) => {
|
|
37
37
|
const { selection } = state;
|
|
38
|
-
const selectedCells = { rows: 1 };
|
|
38
|
+
const selectedCells = { rows: 1, columns: 1 };
|
|
39
39
|
if (selection instanceof prosemirror_tables_1.CellSelection) {
|
|
40
40
|
const rect = (0, prosemirror_tables_1.selectedRect)(state);
|
|
41
41
|
selectedCells.rows = rect.bottom - rect.top;
|
|
42
|
+
selectedCells.columns = rect.right - rect.left;
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
+
const { rows, columns } = selectedCells;
|
|
45
|
+
return {
|
|
46
|
+
rows: rows > 1 ? `${rows} rows` : `row`,
|
|
47
|
+
columns: columns > 1 ? `${columns} columns` : `column`,
|
|
48
|
+
};
|
|
44
49
|
};
|
|
45
50
|
const ContextMenu = ({ view, close, }) => {
|
|
46
51
|
const runCommand = (command, noTracking) => {
|
|
@@ -48,30 +53,35 @@ const ContextMenu = ({ view, close, }) => {
|
|
|
48
53
|
close();
|
|
49
54
|
};
|
|
50
55
|
const [columnAction, setColumnAction] = (0, react_1.useState)(undefined);
|
|
51
|
-
const { rows } =
|
|
56
|
+
const { rows, columns } = getSelectedCellsCount(view.state);
|
|
52
57
|
return (react_1.default.createElement(MenuDropdownList, null,
|
|
53
58
|
react_1.default.createElement(ActionButton, { onClick: () => runCommand((0, commands_1.addRows)('top')) },
|
|
54
59
|
react_1.default.createElement(style_guide_1.PlusIcon, null),
|
|
55
60
|
" Insert row above ",
|
|
56
|
-
rows
|
|
61
|
+
rows),
|
|
57
62
|
react_1.default.createElement(ActionButton, { onClick: () => runCommand((0, commands_1.addRows)('bottom')) },
|
|
58
63
|
react_1.default.createElement(style_guide_1.PlusIcon, null),
|
|
59
64
|
" Insert row below ",
|
|
60
|
-
rows
|
|
61
|
-
react_1.default.createElement(ActionButton, { onClick: () => setColumnAction(() =>
|
|
65
|
+
rows),
|
|
66
|
+
react_1.default.createElement(ActionButton, { onClick: () => setColumnAction(() => (0, commands_1.addColumns)('left')) },
|
|
62
67
|
react_1.default.createElement(style_guide_1.PlusIcon, null),
|
|
63
|
-
" Insert
|
|
64
|
-
|
|
68
|
+
" Insert ",
|
|
69
|
+
columns,
|
|
70
|
+
" to the left"),
|
|
71
|
+
react_1.default.createElement(ActionButton, { onClick: () => setColumnAction(() => (0, commands_1.addColumns)('right')) },
|
|
65
72
|
react_1.default.createElement(style_guide_1.PlusIcon, null),
|
|
66
|
-
" Insert
|
|
73
|
+
" Insert ",
|
|
74
|
+
columns,
|
|
75
|
+
" to the right"),
|
|
67
76
|
react_1.default.createElement(Separator, null),
|
|
68
77
|
react_1.default.createElement(ActionButton, { onClick: () => runCommand(prosemirror_tables_1.deleteRow) },
|
|
69
78
|
react_1.default.createElement(GrayDeleteIcon, null),
|
|
70
|
-
" Delete
|
|
71
|
-
rows
|
|
79
|
+
" Delete ",
|
|
80
|
+
rows),
|
|
72
81
|
react_1.default.createElement(ActionButton, { onClick: () => setColumnAction(() => prosemirror_tables_1.deleteColumn) },
|
|
73
82
|
react_1.default.createElement(GrayDeleteIcon, null),
|
|
74
|
-
" Delete
|
|
83
|
+
" Delete ",
|
|
84
|
+
columns),
|
|
75
85
|
react_1.default.createElement(style_guide_1.ColumnChangeWarningDialog, { isOpen: !!columnAction, primaryAction: () => {
|
|
76
86
|
if (columnAction) {
|
|
77
87
|
runCommand(columnAction, true);
|
|
@@ -19,6 +19,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.TableCellView = void 0;
|
|
22
|
+
const transform_1 = require("@manuscripts/transform");
|
|
22
23
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
23
24
|
const prosemirror_state_1 = require("prosemirror-state");
|
|
24
25
|
const prosemirror_tables_1 = require("prosemirror-tables");
|
|
@@ -31,12 +32,7 @@ class TableCellView extends block_view_1.default {
|
|
|
31
32
|
constructor() {
|
|
32
33
|
super(...arguments);
|
|
33
34
|
this.initialise = () => {
|
|
34
|
-
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const outputSpec = this.node.type.spec.toDOM(this.node);
|
|
38
|
-
const { dom } = prosemirror_model_1.DOMSerializer.renderSpec(document, outputSpec);
|
|
39
|
-
this.dom = dom;
|
|
35
|
+
this.dom = this.toDom();
|
|
40
36
|
this.contentDOM = document.createElement('span');
|
|
41
37
|
this.dom.appendChild(this.contentDOM);
|
|
42
38
|
const can = this.props.getCapabilities();
|
|
@@ -44,6 +40,10 @@ class TableCellView extends block_view_1.default {
|
|
|
44
40
|
this.createContextMenu();
|
|
45
41
|
}
|
|
46
42
|
};
|
|
43
|
+
this.updateContents = () => {
|
|
44
|
+
this.dom.getAttributeNames().map((attr) => this.dom.removeAttribute(attr));
|
|
45
|
+
Array.from(this.toDom().attributes).map((attr) => attr.nodeValue && this.dom.setAttribute(attr.nodeName, attr.nodeValue));
|
|
46
|
+
};
|
|
47
47
|
}
|
|
48
48
|
ignoreMutation(mutation) {
|
|
49
49
|
return mutation.type === 'attributes' && mutation.attributeName === 'class';
|
|
@@ -78,6 +78,15 @@ class TableCellView extends block_view_1.default {
|
|
|
78
78
|
});
|
|
79
79
|
this.dom.appendChild(contextMenuButton);
|
|
80
80
|
}
|
|
81
|
+
toDom() {
|
|
82
|
+
if (!this.node.type.spec.toDOM) {
|
|
83
|
+
return this.node.type === transform_1.schema.nodes.table_cell
|
|
84
|
+
? document.createElement('td')
|
|
85
|
+
: document.createElement('th');
|
|
86
|
+
}
|
|
87
|
+
const outputSpec = this.node.type.spec.toDOM(this.node);
|
|
88
|
+
return prosemirror_model_1.DOMSerializer.renderSpec(document, outputSpec).dom;
|
|
89
|
+
}
|
|
81
90
|
}
|
|
82
91
|
exports.TableCellView = TableCellView;
|
|
83
92
|
exports.default = (0, creators_1.createNodeView)(TableCellView);
|
package/dist/es/commands.js
CHANGED
|
@@ -19,7 +19,7 @@ import { generateID, generateNodeID, isElementNodeType, isFootnoteNode, isInBibl
|
|
|
19
19
|
import { Fragment, NodeRange, } 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, } from 'prosemirror-transform';
|
|
24
24
|
import { findChildrenByType, findParentNodeOfType, findParentNodeOfTypeClosestToPos, } from 'prosemirror-utils';
|
|
25
25
|
import { getCommentKey, getCommentRange } from './lib/comments';
|
|
@@ -939,9 +939,6 @@ export const insertTableFootnote = (node, position, view, inlineFootnote) => {
|
|
|
939
939
|
dispatch(view.state.tr.setSelection(textSelection).scrollIntoView());
|
|
940
940
|
};
|
|
941
941
|
export const addRows = (direction) => (state, dispatch) => {
|
|
942
|
-
if (!isInTable(state)) {
|
|
943
|
-
return false;
|
|
944
|
-
}
|
|
945
942
|
if (dispatch) {
|
|
946
943
|
const { tr } = state;
|
|
947
944
|
const rect = selectedRect(state);
|
|
@@ -953,3 +950,16 @@ export const addRows = (direction) => (state, dispatch) => {
|
|
|
953
950
|
}
|
|
954
951
|
return true;
|
|
955
952
|
};
|
|
953
|
+
export const addColumns = (direction) => (state, dispatch) => {
|
|
954
|
+
if (dispatch) {
|
|
955
|
+
const { tr } = state;
|
|
956
|
+
const rect = selectedRect(state.apply(tr));
|
|
957
|
+
const selectedRows = rect.right - rect.left;
|
|
958
|
+
for (let i = 0; i < selectedRows; i++) {
|
|
959
|
+
const command = direction === 'right' ? addColumnAfter : addColumnBefore;
|
|
960
|
+
command(state.apply(tr), (t) => t.steps.map((s) => tr.step(s)));
|
|
961
|
+
}
|
|
962
|
+
dispatch(tr);
|
|
963
|
+
}
|
|
964
|
+
return true;
|
|
965
|
+
};
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { ColumnChangeWarningDialog, DeleteIcon, IconTextButton, PlusIcon, } from '@manuscripts/style-guide';
|
|
2
2
|
import { skipTracking } from '@manuscripts/track-changes-plugin';
|
|
3
|
-
import {
|
|
3
|
+
import { CellSelection, deleteColumn, deleteRow, selectedRect, } from 'prosemirror-tables';
|
|
4
4
|
import React, { useState } from 'react';
|
|
5
5
|
import styled from 'styled-components';
|
|
6
|
-
import { addRows } from '../../commands';
|
|
7
|
-
const
|
|
6
|
+
import { addColumns, addRows } from '../../commands';
|
|
7
|
+
const getSelectedCellsCount = (state) => {
|
|
8
8
|
const { selection } = state;
|
|
9
|
-
const selectedCells = { rows: 1 };
|
|
9
|
+
const selectedCells = { rows: 1, columns: 1 };
|
|
10
10
|
if (selection instanceof CellSelection) {
|
|
11
11
|
const rect = selectedRect(state);
|
|
12
12
|
selectedCells.rows = rect.bottom - rect.top;
|
|
13
|
+
selectedCells.columns = rect.right - rect.left;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
const { rows, columns } = selectedCells;
|
|
16
|
+
return {
|
|
17
|
+
rows: rows > 1 ? `${rows} rows` : `row`,
|
|
18
|
+
columns: columns > 1 ? `${columns} columns` : `column`,
|
|
19
|
+
};
|
|
15
20
|
};
|
|
16
21
|
export const ContextMenu = ({ view, close, }) => {
|
|
17
22
|
const runCommand = (command, noTracking) => {
|
|
@@ -19,30 +24,35 @@ export const ContextMenu = ({ view, close, }) => {
|
|
|
19
24
|
close();
|
|
20
25
|
};
|
|
21
26
|
const [columnAction, setColumnAction] = useState(undefined);
|
|
22
|
-
const { rows } =
|
|
27
|
+
const { rows, columns } = getSelectedCellsCount(view.state);
|
|
23
28
|
return (React.createElement(MenuDropdownList, null,
|
|
24
29
|
React.createElement(ActionButton, { onClick: () => runCommand(addRows('top')) },
|
|
25
30
|
React.createElement(PlusIcon, null),
|
|
26
31
|
" Insert row above ",
|
|
27
|
-
rows
|
|
32
|
+
rows),
|
|
28
33
|
React.createElement(ActionButton, { onClick: () => runCommand(addRows('bottom')) },
|
|
29
34
|
React.createElement(PlusIcon, null),
|
|
30
35
|
" Insert row below ",
|
|
31
|
-
rows
|
|
32
|
-
React.createElement(ActionButton, { onClick: () => setColumnAction(() =>
|
|
36
|
+
rows),
|
|
37
|
+
React.createElement(ActionButton, { onClick: () => setColumnAction(() => addColumns('left')) },
|
|
33
38
|
React.createElement(PlusIcon, null),
|
|
34
|
-
" Insert
|
|
35
|
-
|
|
39
|
+
" Insert ",
|
|
40
|
+
columns,
|
|
41
|
+
" to the left"),
|
|
42
|
+
React.createElement(ActionButton, { onClick: () => setColumnAction(() => addColumns('right')) },
|
|
36
43
|
React.createElement(PlusIcon, null),
|
|
37
|
-
" Insert
|
|
44
|
+
" Insert ",
|
|
45
|
+
columns,
|
|
46
|
+
" to the right"),
|
|
38
47
|
React.createElement(Separator, null),
|
|
39
48
|
React.createElement(ActionButton, { onClick: () => runCommand(deleteRow) },
|
|
40
49
|
React.createElement(GrayDeleteIcon, null),
|
|
41
|
-
" Delete
|
|
42
|
-
rows
|
|
50
|
+
" Delete ",
|
|
51
|
+
rows),
|
|
43
52
|
React.createElement(ActionButton, { onClick: () => setColumnAction(() => deleteColumn) },
|
|
44
53
|
React.createElement(GrayDeleteIcon, null),
|
|
45
|
-
" Delete
|
|
54
|
+
" Delete ",
|
|
55
|
+
columns),
|
|
46
56
|
React.createElement(ColumnChangeWarningDialog, { isOpen: !!columnAction, primaryAction: () => {
|
|
47
57
|
if (columnAction) {
|
|
48
58
|
runCommand(columnAction, true);
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { schema } from '@manuscripts/transform';
|
|
16
17
|
import { DOMSerializer } from 'prosemirror-model';
|
|
17
18
|
import { TextSelection } from 'prosemirror-state';
|
|
18
19
|
import { CellSelection } from 'prosemirror-tables';
|
|
@@ -25,12 +26,7 @@ export class TableCellView extends BlockView {
|
|
|
25
26
|
constructor() {
|
|
26
27
|
super(...arguments);
|
|
27
28
|
this.initialise = () => {
|
|
28
|
-
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const outputSpec = this.node.type.spec.toDOM(this.node);
|
|
32
|
-
const { dom } = DOMSerializer.renderSpec(document, outputSpec);
|
|
33
|
-
this.dom = dom;
|
|
29
|
+
this.dom = this.toDom();
|
|
34
30
|
this.contentDOM = document.createElement('span');
|
|
35
31
|
this.dom.appendChild(this.contentDOM);
|
|
36
32
|
const can = this.props.getCapabilities();
|
|
@@ -38,6 +34,10 @@ export class TableCellView extends BlockView {
|
|
|
38
34
|
this.createContextMenu();
|
|
39
35
|
}
|
|
40
36
|
};
|
|
37
|
+
this.updateContents = () => {
|
|
38
|
+
this.dom.getAttributeNames().map((attr) => this.dom.removeAttribute(attr));
|
|
39
|
+
Array.from(this.toDom().attributes).map((attr) => attr.nodeValue && this.dom.setAttribute(attr.nodeName, attr.nodeValue));
|
|
40
|
+
};
|
|
41
41
|
}
|
|
42
42
|
ignoreMutation(mutation) {
|
|
43
43
|
return mutation.type === 'attributes' && mutation.attributeName === 'class';
|
|
@@ -72,5 +72,14 @@ export class TableCellView extends BlockView {
|
|
|
72
72
|
});
|
|
73
73
|
this.dom.appendChild(contextMenuButton);
|
|
74
74
|
}
|
|
75
|
+
toDom() {
|
|
76
|
+
if (!this.node.type.spec.toDOM) {
|
|
77
|
+
return this.node.type === schema.nodes.table_cell
|
|
78
|
+
? document.createElement('td')
|
|
79
|
+
: document.createElement('th');
|
|
80
|
+
}
|
|
81
|
+
const outputSpec = this.node.type.spec.toDOM(this.node);
|
|
82
|
+
return DOMSerializer.renderSpec(document, outputSpec).dom;
|
|
83
|
+
}
|
|
75
84
|
}
|
|
76
85
|
export default createNodeView(TableCellView);
|
package/dist/types/commands.d.ts
CHANGED
|
@@ -67,4 +67,5 @@ interface NodeWithPosition {
|
|
|
67
67
|
}
|
|
68
68
|
export declare const insertTableFootnote: (node: ManuscriptNode, position: number, view: EditorView, inlineFootnote?: NodeWithPosition) => void;
|
|
69
69
|
export declare const addRows: (direction: 'top' | 'bottom') => (state: EditorState, dispatch?: ((tr: Transaction) => void) | undefined) => boolean;
|
|
70
|
+
export declare const addColumns: (direction: 'right' | 'left') => (state: EditorState, dispatch?: ((tr: Transaction) => void) | undefined) => boolean;
|
|
70
71
|
export {};
|
|
@@ -19,7 +19,9 @@ export declare class TableCellView extends BlockView<EditableBlockProps> {
|
|
|
19
19
|
contentDOM: HTMLElement;
|
|
20
20
|
ignoreMutation(mutation: MutationRecord): boolean;
|
|
21
21
|
initialise: () => void;
|
|
22
|
+
updateContents: () => void;
|
|
22
23
|
private createContextMenu;
|
|
24
|
+
private toDom;
|
|
23
25
|
}
|
|
24
26
|
declare const _default: (props: import("./base_node_view").BaseNodeProps, dispatch?: import("..").Dispatch | undefined) => import("../types").NodeViewCreator<TableCellView>;
|
|
25
27
|
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.13.
|
|
4
|
+
"version": "1.13.26",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-body-editor",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|