@manuscripts/body-editor 2.0.41-LEAN-3918.0 → 2.0.41

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.
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.mergeCellsWithSpace = 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.findPosBeforeFirstSubsection = 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.mergeCellsWithSpace = 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.findPosBeforeFirstSubsection = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertSupplement = exports.insertTable = 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");
@@ -99,14 +99,11 @@ const createSelection = (nodeType, position, doc) => {
99
99
  }
100
100
  };
101
101
  exports.createSelection = createSelection;
102
- const createBlock = (nodeType, position, state, dispatch, attrs, tableConfig) => {
102
+ const createBlock = (nodeType, position, state, dispatch, attrs) => {
103
103
  let node;
104
104
  switch (nodeType) {
105
105
  case state.schema.nodes.table_element:
106
- if (!tableConfig) {
107
- throw new Error('Table configuration is required for creating a table element');
108
- }
109
- node = (0, exports.createAndFillTableElement)(state, tableConfig);
106
+ node = (0, exports.createAndFillTableElement)(state);
110
107
  break;
111
108
  case state.schema.nodes.figure_element:
112
109
  node = createAndFillFigureElement(state);
@@ -186,6 +183,18 @@ const insertFigure = (file, state, dispatch) => {
186
183
  return true;
187
184
  };
188
185
  exports.insertFigure = insertFigure;
186
+ const insertTable = (config, state, dispatch) => {
187
+ const pos = findBlockInsertPosition(state);
188
+ if (!pos) {
189
+ return false;
190
+ }
191
+ const node = (0, exports.createAndFillTableElement)(state, config);
192
+ const tr = state.tr.insert(pos, node);
193
+ tr.setSelection(prosemirror_state_1.NodeSelection.create(tr.doc, pos)).scrollIntoView();
194
+ dispatch && dispatch(tr);
195
+ return true;
196
+ };
197
+ exports.insertTable = insertTable;
189
198
  const insertSupplement = (file, state, dispatch) => {
190
199
  const supplement = transform_1.schema.nodes.supplement.create({
191
200
  id: (0, transform_1.generateNodeID)(transform_1.schema.nodes.supplement),
@@ -201,12 +210,12 @@ const insertSupplement = (file, state, dispatch) => {
201
210
  return true;
202
211
  };
203
212
  exports.insertSupplement = insertSupplement;
204
- const insertBlock = (nodeType) => (state, dispatch, view, tableConfig) => {
213
+ const insertBlock = (nodeType) => (state, dispatch) => {
205
214
  const position = findBlockInsertPosition(state);
206
215
  if (position === null) {
207
216
  return false;
208
217
  }
209
- (0, exports.createBlock)(nodeType, position, state, dispatch, undefined, tableConfig);
218
+ (0, exports.createBlock)(nodeType, position, state, dispatch, undefined);
210
219
  return true;
211
220
  };
212
221
  exports.insertBlock = insertBlock;
@@ -826,21 +835,25 @@ const selectAllIsolating = (state, dispatch) => {
826
835
  return true;
827
836
  };
828
837
  exports.selectAllIsolating = selectAllIsolating;
829
- const createAndFillTableElement = (state, tableConfig) => {
830
- const { nodes } = state.schema;
831
- const { numberOfColumns, numberOfRows, includeHeader } = tableConfig;
838
+ const DEFAULT_TABLE_CONFIG = {
839
+ numberOfColumns: 2,
840
+ numberOfRows: 2,
841
+ includeHeader: true,
842
+ };
843
+ const createAndFillTableElement = (state, config = DEFAULT_TABLE_CONFIG) => {
844
+ const { numberOfColumns, numberOfRows, includeHeader } = config;
832
845
  const createRow = (cellType) => {
833
- const cells = Array.from({ length: numberOfColumns }, () => nodes[cellType].create());
834
- return nodes.table_row.create({}, cells);
846
+ const cells = Array.from({ length: numberOfColumns }, () => cellType.create());
847
+ return transform_1.schema.nodes.table_row.create({}, cells);
835
848
  };
836
- const tableRows = includeHeader ? [createRow('table_header')] : [];
849
+ const tableRows = includeHeader ? [createRow(transform_1.schema.nodes.table_header)] : [];
837
850
  for (let i = 0; i < numberOfRows; i++) {
838
- tableRows.push(createRow('table_cell'));
851
+ tableRows.push(createRow(transform_1.schema.nodes.table_cell));
839
852
  }
840
- return nodes.table_element.createChecked({}, [
853
+ return transform_1.schema.nodes.table_element.createChecked({}, [
841
854
  createAndFillFigcaptionElement(state),
842
- nodes.table.create({}, tableRows),
843
- nodes.listing.create(),
855
+ transform_1.schema.nodes.table.create({}, tableRows),
856
+ transform_1.schema.nodes.listing.create(),
844
857
  ]);
845
858
  };
846
859
  exports.createAndFillTableElement = createAndFillTableElement;
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2024 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ var __importDefault = (this && this.__importDefault) || function (mod) {
41
+ return (mod && mod.__esModule) ? mod : { "default": mod };
42
+ };
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.openInsertTableDialog = exports.InsertTableDialog = void 0;
45
+ const style_guide_1 = require("@manuscripts/style-guide");
46
+ const react_1 = __importStar(require("react"));
47
+ const react_select_1 = __importDefault(require("react-select"));
48
+ const styled_components_1 = __importDefault(require("styled-components"));
49
+ const commands_1 = require("../../commands");
50
+ const editor_props_1 = require("../../plugins/editor-props");
51
+ const ReactSubView_1 = __importDefault(require("../../views/ReactSubView"));
52
+ const Label = styled_components_1.default.div `
53
+ padding-right: 16px;
54
+ width: 150px;
55
+ `;
56
+ const SelectContainer = styled_components_1.default.div `
57
+ width: 182px;
58
+ height: 30px;
59
+ `;
60
+ const Container = styled_components_1.default.div `
61
+ display: flex;
62
+ align-items: center;
63
+ padding-bottom: 16px;
64
+ `;
65
+ const OptionWrapper = styled_components_1.default.div `
66
+ padding-left: ${(props) => props.theme.grid.unit * 4}px;
67
+ padding-top: ${(props) => props.theme.grid.unit * 2}px;
68
+ padding-bottom: ${(props) => props.theme.grid.unit * 2}px;
69
+
70
+ background-color: ${(props) => props.focused ? props.theme.colors.background.fifth : 'transparent'};
71
+
72
+ &:hover {
73
+ background-color: ${(props) => props.theme.colors.background.fifth};
74
+ }
75
+ `;
76
+ const InsertTableDialog = ({ state, dispatch, }) => {
77
+ const [isOpen, setOpen] = (0, react_1.useState)(true);
78
+ const [numberOfColumns, setNumColumns] = (0, react_1.useState)({ value: 4, label: `4` });
79
+ const [numberOfRows, setNumRows] = (0, react_1.useState)({ value: 4, label: `4` });
80
+ const [includeHeader, setIncludeHeader] = (0, react_1.useState)(true);
81
+ const handleColumnChange = (newValue) => {
82
+ setNumColumns(newValue);
83
+ };
84
+ const handleRowChange = (newValue) => {
85
+ setNumRows(newValue);
86
+ };
87
+ const options = Array.from({ length: 20 }, (_, index) => ({
88
+ value: index + 1,
89
+ label: `${index + 1}`,
90
+ }));
91
+ const OptionComponent = ({ innerProps, data, }) => {
92
+ return (react_1.default.createElement(OptionWrapper, Object.assign({}, innerProps, { ref: null }), data.label));
93
+ };
94
+ const actions = {
95
+ primary: {
96
+ action: () => {
97
+ const config = {
98
+ numberOfColumns: numberOfColumns.value,
99
+ numberOfRows: numberOfRows.value,
100
+ includeHeader,
101
+ };
102
+ (0, commands_1.insertTable)(config, state, dispatch);
103
+ setOpen(false);
104
+ },
105
+ title: 'Create table',
106
+ },
107
+ secondary: {
108
+ action: () => setOpen(false),
109
+ title: 'Cancel',
110
+ },
111
+ };
112
+ return (react_1.default.createElement(style_guide_1.Dialog, { isOpen: isOpen, actions: actions, category: style_guide_1.Category.confirmation, header: 'Insert table', message: '' },
113
+ react_1.default.createElement(Container, null,
114
+ react_1.default.createElement(Label, null, "Number of columns:"),
115
+ react_1.default.createElement(SelectContainer, null,
116
+ react_1.default.createElement(react_select_1.default, { onChange: (v) => handleColumnChange(v), value: numberOfColumns, options: options, components: {
117
+ Option: OptionComponent,
118
+ }, menuPosition: "fixed", maxMenuHeight: 150 }))),
119
+ react_1.default.createElement(Container, null,
120
+ react_1.default.createElement(Label, null, "Number of rows:"),
121
+ react_1.default.createElement(SelectContainer, null,
122
+ react_1.default.createElement(react_select_1.default, { onChange: (v) => handleRowChange(v), value: numberOfRows, options: options, components: {
123
+ Option: OptionComponent,
124
+ }, menuPosition: "fixed", maxMenuHeight: 150 }))),
125
+ react_1.default.createElement(style_guide_1.CheckboxLabel, null,
126
+ react_1.default.createElement(style_guide_1.CheckboxField, { name: 'include-header', checked: includeHeader, onChange: (e) => {
127
+ setIncludeHeader(e.target.checked);
128
+ } }),
129
+ react_1.default.createElement("div", null, "Include header row"))));
130
+ };
131
+ exports.InsertTableDialog = InsertTableDialog;
132
+ const openInsertTableDialog = (state, dispatch) => {
133
+ const props = (0, editor_props_1.getEditorProps)(state);
134
+ const componentProps = {
135
+ state,
136
+ dispatch,
137
+ };
138
+ const dialog = (0, ReactSubView_1.default)(props, exports.InsertTableDialog, componentProps, state.doc, null, null);
139
+ document.body.appendChild(dialog);
140
+ };
141
+ exports.openInsertTableDialog = openInsertTableDialog;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Label = exports.Block = exports.BlockItem = exports.StyleBlock = exports.ListContainer = exports.ListStyles = exports.ListMenuItem = void 0;
7
+ const style_guide_1 = require("@manuscripts/style-guide");
8
+ const react_1 = __importDefault(require("react"));
9
+ const styled_components_1 = __importDefault(require("styled-components"));
10
+ const ListMenuItem = ({ menu, handleClick, }) => {
11
+ if (!menu.submenu) {
12
+ return null;
13
+ }
14
+ const styles = menu.submenu.map((m) => m.id);
15
+ return (react_1.default.createElement(style_guide_1.SubmenuContainer, null,
16
+ react_1.default.createElement(style_guide_1.SubmenuLabel, { menu: menu, handleClick: handleClick }),
17
+ menu.isOpen && (react_1.default.createElement(style_guide_1.NestedSubmenusContainer, null,
18
+ react_1.default.createElement(exports.ListStyles, { styles: styles, onClick: (s, i) => handleClick([i]) })))));
19
+ };
20
+ exports.ListMenuItem = ListMenuItem;
21
+ const ListStyles = ({ styles, onClick, }) => {
22
+ return (react_1.default.createElement(exports.ListContainer, null, styles.map((style, index) => (react_1.default.createElement(exports.StyleBlock, { key: index, onClick: () => onClick(style, index) }, styleItems[style].map((item, index) => (react_1.default.createElement(exports.BlockItem, { key: index },
23
+ react_1.default.createElement(exports.Label, { hide: item === '-' }, item),
24
+ react_1.default.createElement(exports.Block, null)))))))));
25
+ };
26
+ exports.ListStyles = ListStyles;
27
+ const styleItems = {
28
+ order: ['1.', '2.', '3.'],
29
+ 'alpha-upper': ['A.', 'B.', 'C.'],
30
+ 'alpha-lower': ['a.', 'b.', 'c.'],
31
+ 'roman-upper': ['I.', 'II.', 'III.'],
32
+ 'roman-lower': ['i.', 'ii.', 'iii.'],
33
+ bullet: ['•', '•', '•'],
34
+ simple: ['-', '-', '-'],
35
+ };
36
+ exports.ListContainer = styled_components_1.default.div `
37
+ padding: ${(props) => props.theme.grid.unit * 4}px;
38
+ display: grid;
39
+ grid-template-columns:
40
+ ${(props) => props.theme.grid.unit * 21}px
41
+ ${(props) => props.theme.grid.unit * 21}px;
42
+ gap: 6px;
43
+ `;
44
+ exports.StyleBlock = styled_components_1.default.div `
45
+ border: 1px solid ${(props) => props.theme.colors.border.tertiary};
46
+ padding: ${(props) => props.theme.grid.unit * 2}px;
47
+ cursor: pointer;
48
+ display: flex;
49
+ flex-direction: column;
50
+ row-gap: ${(props) => props.theme.grid.unit * 2}px;
51
+
52
+ &:hover {
53
+ background: ${(props) => props.theme.colors.button.default.border.hover};
54
+ }
55
+
56
+ &:active {
57
+ border-color: ${(props) => props.theme.colors.border.primary};
58
+ }
59
+ `;
60
+ exports.BlockItem = styled_components_1.default.div `
61
+ display: flex;
62
+ align-items: center;
63
+ gap: 6px;
64
+ `;
65
+ exports.Block = styled_components_1.default.div `
66
+ height: 3px;
67
+ width: ${(props) => props.theme.grid.unit * 14}px;
68
+ background: ${(props) => props.theme.colors.border.tertiary};
69
+ `;
70
+ exports.Label = styled_components_1.default.div `
71
+ font-family: Lato, serif;
72
+ font-size: ${(props) => props.theme.font.size.small};
73
+ font-weight: ${(props) => props.theme.font.weight.normal};
74
+ line-height: ${(props) => props.theme.font.lineHeight.small};
75
+ font-style: normal;
76
+ color: ${(props) => (props.hide && 'white') || 'initial'};
77
+ `;
@@ -47,12 +47,22 @@ const getSelectedCellsCount = (state) => {
47
47
  columns: columns > 1 ? `${columns} columns` : `column`,
48
48
  };
49
49
  };
50
+ const ColumnChangeWarningDialog = ({ isOpen, primaryAction, secondaryAction }) => (react_1.default.createElement(style_guide_1.Dialog, { isOpen: isOpen, category: style_guide_1.Category.confirmation, header: "This change can't be tracked", message: "This column action won't be marked as chnage. Do you want to continue?", actions: {
51
+ primary: {
52
+ action: primaryAction,
53
+ title: 'Ok',
54
+ },
55
+ secondary: {
56
+ action: secondaryAction,
57
+ title: 'Cancel',
58
+ },
59
+ } }));
50
60
  const ContextMenu = ({ view, close, }) => {
51
61
  const runCommand = (command, noTracking) => {
52
62
  command(view.state, (tr) => view.dispatch((noTracking && (0, track_changes_plugin_1.skipTracking)(tr)) || tr));
53
63
  close();
54
64
  };
55
- const [columnAction, setColumnAction] = (0, react_1.useState)(undefined);
65
+ const [columnAction, setColumnAction] = (0, react_1.useState)();
56
66
  const isCellSelectionMerged = (0, prosemirror_tables_1.mergeCells)(view.state);
57
67
  const isCellSelectionSplittable = (0, prosemirror_tables_1.splitCell)(view.state);
58
68
  const { rows, columns } = getSelectedCellsCount(view.state);
@@ -89,7 +99,7 @@ const ContextMenu = ({ view, close, }) => {
89
99
  (isCellSelectionMerged || isCellSelectionSplittable) && react_1.default.createElement(Separator, null),
90
100
  isCellSelectionMerged && (react_1.default.createElement(ActionButton, { onClick: () => runCommand(commands_1.mergeCellsWithSpace, true) }, "Merge cells")),
91
101
  isCellSelectionSplittable && (react_1.default.createElement(ActionButton, { onClick: () => runCommand(prosemirror_tables_1.splitCell, true) }, "Split cells")),
92
- react_1.default.createElement(style_guide_1.ColumnChangeWarningDialog, { isOpen: !!columnAction, primaryAction: () => {
102
+ react_1.default.createElement(ColumnChangeWarningDialog, { isOpen: !!columnAction, primaryAction: () => {
93
103
  if (columnAction) {
94
104
  runCommand(columnAction, true);
95
105
  setColumnAction(undefined);
package/dist/cjs/index.js CHANGED
@@ -37,6 +37,8 @@ var Outline_1 = require("./components/outline/Outline");
37
37
  Object.defineProperty(exports, "OutlineItemIcon", { enumerable: true, get: function () { return Outline_1.OutlineItemIcon; } });
38
38
  var LevelSelector_1 = require("./components/toolbar/LevelSelector");
39
39
  Object.defineProperty(exports, "LevelSelector", { enumerable: true, get: function () { return LevelSelector_1.LevelSelector; } });
40
+ __exportStar(require("./components/toolbar/ListMenuItem"), exports);
41
+ __exportStar(require("./components/toolbar/InsertTableDialog"), exports);
40
42
  __exportStar(require("./menus"), exports);
41
43
  var collabProvider_1 = require("./classes/collabProvider");
42
44
  Object.defineProperty(exports, "CollabProvider", { enumerable: true, get: function () { return collabProvider_1.CollabProvider; } });
package/dist/cjs/menus.js CHANGED
@@ -20,17 +20,12 @@ 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 InsertTableDialog_1 = require("./components/toolbar/InsertTableDialog");
24
+ const ListMenuItem_1 = require("./components/toolbar/ListMenuItem");
23
25
  const hierarchy_1 = require("./lib/hierarchy");
24
26
  const getEditorMenus = (editor) => {
25
27
  const { isCommandValid, state } = editor;
26
28
  const doCommand = (command) => () => editor.doCommand(command);
27
- const wrappedDoCommand = (command, tableConfig) => {
28
- return () => {
29
- doCommand((state, dispatch, view) => {
30
- return command(state, dispatch, view, tableConfig);
31
- })();
32
- };
33
- };
34
29
  const edit = {
35
30
  id: 'edit',
36
31
  label: 'Edit',
@@ -226,9 +221,7 @@ const getEditorMenus = (editor) => {
226
221
  pc: 'CommandOrControl+Option+T',
227
222
  },
228
223
  isEnabled: isCommandValid((0, commands_1.canInsert)(transform_1.schema.nodes.table_element)),
229
- run: (tableConfig) => {
230
- wrappedDoCommand((0, commands_1.insertBlock)(transform_1.schema.nodes.table_element), tableConfig)();
231
- },
224
+ run: () => (0, InsertTableDialog_1.openInsertTableDialog)(editor.state, editor.dispatch),
232
225
  },
233
226
  {
234
227
  role: 'separator',
@@ -388,35 +381,58 @@ const getEditorMenus = (editor) => {
388
381
  {
389
382
  id: 'insert-bullet-list',
390
383
  label: 'Bullet List',
384
+ component: ListMenuItem_1.ListMenuItem,
391
385
  isEnabled: isCommandValid((0, commands_1.insertList)(transform_1.schema.nodes.list, 'bullet')),
392
386
  submenu: [
393
387
  {
394
- id: 'bullet-list-context-menu',
395
- label: '',
388
+ id: 'bullet',
389
+ label: 'Bullet',
390
+ isEnabled: true,
391
+ run: doCommand((0, commands_1.insertList)(transform_1.schema.nodes.list, 'bullet')),
392
+ },
393
+ {
394
+ id: 'simple',
395
+ label: 'Simple',
396
396
  isEnabled: true,
397
- options: {
398
- bullet: doCommand((0, commands_1.insertList)(transform_1.schema.nodes.list, 'bullet')),
399
- simple: doCommand((0, commands_1.insertList)(transform_1.schema.nodes.list, 'simple')),
400
- },
397
+ run: doCommand((0, commands_1.insertList)(transform_1.schema.nodes.list, 'simple')),
401
398
  },
402
399
  ],
403
400
  },
404
401
  {
405
402
  id: 'insert-ordered-list',
406
403
  label: 'Ordered List',
404
+ component: ListMenuItem_1.ListMenuItem,
407
405
  isEnabled: isCommandValid((0, commands_1.insertList)(transform_1.schema.nodes.list, 'order')),
408
406
  submenu: [
409
407
  {
410
- id: 'ordered-list-context-menu',
411
- label: '',
408
+ id: 'order',
409
+ label: 'Order',
410
+ isEnabled: true,
411
+ run: doCommand((0, commands_1.insertList)(transform_1.schema.nodes.list, 'order')),
412
+ },
413
+ {
414
+ id: 'alpha-upper',
415
+ label: 'Alpha upper',
416
+ isEnabled: true,
417
+ run: doCommand((0, commands_1.insertList)(transform_1.schema.nodes.list, 'alpha-upper')),
418
+ },
419
+ {
420
+ id: 'alpha-lower',
421
+ label: 'Alpha lower',
422
+ isEnabled: true,
423
+ run: doCommand((0, commands_1.insertList)(transform_1.schema.nodes.list, 'alpha-lower')),
424
+ },
425
+ {
426
+ id: 'roman-upper',
427
+ label: 'Roman upper',
428
+ isEnabled: true,
429
+ run: doCommand((0, commands_1.insertList)(transform_1.schema.nodes.list, 'roman-upper')),
430
+ },
431
+ {
432
+ id: 'roman-lower',
433
+ label: 'Roman lower',
412
434
  isEnabled: true,
413
- options: {
414
- order: doCommand((0, commands_1.insertList)(transform_1.schema.nodes.list, 'order')),
415
- 'alpha-upper': doCommand((0, commands_1.insertList)(transform_1.schema.nodes.list, 'alpha-upper')),
416
- 'alpha-lower': doCommand((0, commands_1.insertList)(transform_1.schema.nodes.list, 'alpha-lower')),
417
- 'roman-upper': doCommand((0, commands_1.insertList)(transform_1.schema.nodes.list, 'roman-upper')),
418
- 'roman-lower': doCommand((0, commands_1.insertList)(transform_1.schema.nodes.list, 'roman-lower')),
419
- },
435
+ run: doCommand((0, commands_1.insertList)(transform_1.schema.nodes.list, 'roman-lower')),
420
436
  },
421
437
  ],
422
438
  },
@@ -24,6 +24,7 @@ const transform_1 = require("@manuscripts/transform");
24
24
  const prosemirror_commands_1 = require("prosemirror-commands");
25
25
  const react_1 = __importDefault(require("react"));
26
26
  const commands_1 = require("./commands");
27
+ const InsertTableDialog_1 = require("./components/toolbar/InsertTableDialog");
27
28
  exports.toolbar = {
28
29
  style: {
29
30
  bold: {
@@ -116,7 +117,7 @@ exports.toolbar = {
116
117
  title: 'Insert table',
117
118
  content: react_1.default.createElement(style_guide_1.ToolbarTableIcon, null),
118
119
  isEnabled: (0, commands_1.canInsert)(transform_1.schema.nodes.table_element),
119
- run: (0, commands_1.insertBlock)(transform_1.schema.nodes.table_element),
120
+ run: InsertTableDialog_1.openInsertTableDialog,
120
121
  },
121
122
  equation_element: {
122
123
  title: 'Insert equation',
@@ -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.0.41-LEAN-3918.0';
4
+ exports.VERSION = '2.0.41';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -34,9 +34,6 @@ exports.default = (props, Component, componentProps, node, getPos, view, classNa
34
34
  tr.setNodeMarkup(getPos(), undefined, Object.assign(Object.assign({}, node.attrs), nextAttrs)).setSelection(selection.map(tr.doc, tr.mapping));
35
35
  view.dispatch(tr);
36
36
  };
37
- if (!node.attrs || !props.dispatch) {
38
- return null;
39
- }
40
37
  return (react_1.default.createElement(styled_components_1.ThemeProvider, { theme: props.theme },
41
38
  react_1.default.createElement(Component, Object.assign({ nodeAttrs: node.attrs, setNodeAttrs: setNodeAttrs, viewProps: { node, view, getPos } }, props, componentProps))));
42
39
  };
@@ -91,14 +91,11 @@ export const createSelection = (nodeType, position, doc) => {
91
91
  : TextSelection.near(doc.resolve(position + 1));
92
92
  }
93
93
  };
94
- export const createBlock = (nodeType, position, state, dispatch, attrs, tableConfig) => {
94
+ export const createBlock = (nodeType, position, state, dispatch, attrs) => {
95
95
  let node;
96
96
  switch (nodeType) {
97
97
  case state.schema.nodes.table_element:
98
- if (!tableConfig) {
99
- throw new Error('Table configuration is required for creating a table element');
100
- }
101
- node = createAndFillTableElement(state, tableConfig);
98
+ node = createAndFillTableElement(state);
102
99
  break;
103
100
  case state.schema.nodes.figure_element:
104
101
  node = createAndFillFigureElement(state);
@@ -175,6 +172,17 @@ export const insertFigure = (file, state, dispatch) => {
175
172
  dispatch(tr);
176
173
  return true;
177
174
  };
175
+ export const insertTable = (config, state, dispatch) => {
176
+ const pos = findBlockInsertPosition(state);
177
+ if (!pos) {
178
+ return false;
179
+ }
180
+ const node = createAndFillTableElement(state, config);
181
+ const tr = state.tr.insert(pos, node);
182
+ tr.setSelection(NodeSelection.create(tr.doc, pos)).scrollIntoView();
183
+ dispatch && dispatch(tr);
184
+ return true;
185
+ };
178
186
  export const insertSupplement = (file, state, dispatch) => {
179
187
  const supplement = schema.nodes.supplement.create({
180
188
  id: generateNodeID(schema.nodes.supplement),
@@ -189,12 +197,12 @@ export const insertSupplement = (file, state, dispatch) => {
189
197
  }
190
198
  return true;
191
199
  };
192
- export const insertBlock = (nodeType) => (state, dispatch, view, tableConfig) => {
200
+ export const insertBlock = (nodeType) => (state, dispatch) => {
193
201
  const position = findBlockInsertPosition(state);
194
202
  if (position === null) {
195
203
  return false;
196
204
  }
197
- createBlock(nodeType, position, state, dispatch, undefined, tableConfig);
205
+ createBlock(nodeType, position, state, dispatch, undefined);
198
206
  return true;
199
207
  };
200
208
  export const deleteBlock = (typeToDelete) => (state, dispatch) => {
@@ -786,21 +794,25 @@ export const selectAllIsolating = (state, dispatch) => {
786
794
  }
787
795
  return true;
788
796
  };
789
- export const createAndFillTableElement = (state, tableConfig) => {
790
- const { nodes } = state.schema;
791
- const { numberOfColumns, numberOfRows, includeHeader } = tableConfig;
797
+ const DEFAULT_TABLE_CONFIG = {
798
+ numberOfColumns: 2,
799
+ numberOfRows: 2,
800
+ includeHeader: true,
801
+ };
802
+ export const createAndFillTableElement = (state, config = DEFAULT_TABLE_CONFIG) => {
803
+ const { numberOfColumns, numberOfRows, includeHeader } = config;
792
804
  const createRow = (cellType) => {
793
- const cells = Array.from({ length: numberOfColumns }, () => nodes[cellType].create());
794
- return nodes.table_row.create({}, cells);
805
+ const cells = Array.from({ length: numberOfColumns }, () => cellType.create());
806
+ return schema.nodes.table_row.create({}, cells);
795
807
  };
796
- const tableRows = includeHeader ? [createRow('table_header')] : [];
808
+ const tableRows = includeHeader ? [createRow(schema.nodes.table_header)] : [];
797
809
  for (let i = 0; i < numberOfRows; i++) {
798
- tableRows.push(createRow('table_cell'));
810
+ tableRows.push(createRow(schema.nodes.table_cell));
799
811
  }
800
- return nodes.table_element.createChecked({}, [
812
+ return schema.nodes.table_element.createChecked({}, [
801
813
  createAndFillFigcaptionElement(state),
802
- nodes.table.create({}, tableRows),
803
- nodes.listing.create(),
814
+ schema.nodes.table.create({}, tableRows),
815
+ schema.nodes.listing.create(),
804
816
  ]);
805
817
  };
806
818
  const createAndFillFigureElement = (state) => state.schema.nodes.figure_element.create({}, [
@@ -0,0 +1,110 @@
1
+ /*!
2
+ * © 2024 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Category, CheckboxField, CheckboxLabel, Dialog, } from '@manuscripts/style-guide';
17
+ import React, { useState } from 'react';
18
+ import Select from 'react-select';
19
+ import styled from 'styled-components';
20
+ import { insertTable } from '../../commands';
21
+ import { getEditorProps } from '../../plugins/editor-props';
22
+ import ReactSubView from '../../views/ReactSubView';
23
+ const Label = styled.div `
24
+ padding-right: 16px;
25
+ width: 150px;
26
+ `;
27
+ const SelectContainer = styled.div `
28
+ width: 182px;
29
+ height: 30px;
30
+ `;
31
+ const Container = styled.div `
32
+ display: flex;
33
+ align-items: center;
34
+ padding-bottom: 16px;
35
+ `;
36
+ const OptionWrapper = styled.div `
37
+ padding-left: ${(props) => props.theme.grid.unit * 4}px;
38
+ padding-top: ${(props) => props.theme.grid.unit * 2}px;
39
+ padding-bottom: ${(props) => props.theme.grid.unit * 2}px;
40
+
41
+ background-color: ${(props) => props.focused ? props.theme.colors.background.fifth : 'transparent'};
42
+
43
+ &:hover {
44
+ background-color: ${(props) => props.theme.colors.background.fifth};
45
+ }
46
+ `;
47
+ export const InsertTableDialog = ({ state, dispatch, }) => {
48
+ const [isOpen, setOpen] = useState(true);
49
+ const [numberOfColumns, setNumColumns] = useState({ value: 4, label: `4` });
50
+ const [numberOfRows, setNumRows] = useState({ value: 4, label: `4` });
51
+ const [includeHeader, setIncludeHeader] = useState(true);
52
+ const handleColumnChange = (newValue) => {
53
+ setNumColumns(newValue);
54
+ };
55
+ const handleRowChange = (newValue) => {
56
+ setNumRows(newValue);
57
+ };
58
+ const options = Array.from({ length: 20 }, (_, index) => ({
59
+ value: index + 1,
60
+ label: `${index + 1}`,
61
+ }));
62
+ const OptionComponent = ({ innerProps, data, }) => {
63
+ return (React.createElement(OptionWrapper, Object.assign({}, innerProps, { ref: null }), data.label));
64
+ };
65
+ const actions = {
66
+ primary: {
67
+ action: () => {
68
+ const config = {
69
+ numberOfColumns: numberOfColumns.value,
70
+ numberOfRows: numberOfRows.value,
71
+ includeHeader,
72
+ };
73
+ insertTable(config, state, dispatch);
74
+ setOpen(false);
75
+ },
76
+ title: 'Create table',
77
+ },
78
+ secondary: {
79
+ action: () => setOpen(false),
80
+ title: 'Cancel',
81
+ },
82
+ };
83
+ return (React.createElement(Dialog, { isOpen: isOpen, actions: actions, category: Category.confirmation, header: 'Insert table', message: '' },
84
+ React.createElement(Container, null,
85
+ React.createElement(Label, null, "Number of columns:"),
86
+ React.createElement(SelectContainer, null,
87
+ React.createElement(Select, { onChange: (v) => handleColumnChange(v), value: numberOfColumns, options: options, components: {
88
+ Option: OptionComponent,
89
+ }, menuPosition: "fixed", maxMenuHeight: 150 }))),
90
+ React.createElement(Container, null,
91
+ React.createElement(Label, null, "Number of rows:"),
92
+ React.createElement(SelectContainer, null,
93
+ React.createElement(Select, { onChange: (v) => handleRowChange(v), value: numberOfRows, options: options, components: {
94
+ Option: OptionComponent,
95
+ }, menuPosition: "fixed", maxMenuHeight: 150 }))),
96
+ React.createElement(CheckboxLabel, null,
97
+ React.createElement(CheckboxField, { name: 'include-header', checked: includeHeader, onChange: (e) => {
98
+ setIncludeHeader(e.target.checked);
99
+ } }),
100
+ React.createElement("div", null, "Include header row"))));
101
+ };
102
+ export const openInsertTableDialog = (state, dispatch) => {
103
+ const props = getEditorProps(state);
104
+ const componentProps = {
105
+ state,
106
+ dispatch,
107
+ };
108
+ const dialog = ReactSubView(props, InsertTableDialog, componentProps, state.doc, null, null);
109
+ document.body.appendChild(dialog);
110
+ };
@@ -0,0 +1,69 @@
1
+ import { NestedSubmenusContainer, SubmenuContainer, SubmenuLabel, } from '@manuscripts/style-guide';
2
+ import React from 'react';
3
+ import styled from 'styled-components';
4
+ export const ListMenuItem = ({ menu, handleClick, }) => {
5
+ if (!menu.submenu) {
6
+ return null;
7
+ }
8
+ const styles = menu.submenu.map((m) => m.id);
9
+ return (React.createElement(SubmenuContainer, null,
10
+ React.createElement(SubmenuLabel, { menu: menu, handleClick: handleClick }),
11
+ menu.isOpen && (React.createElement(NestedSubmenusContainer, null,
12
+ React.createElement(ListStyles, { styles: styles, onClick: (s, i) => handleClick([i]) })))));
13
+ };
14
+ export const ListStyles = ({ styles, onClick, }) => {
15
+ return (React.createElement(ListContainer, null, styles.map((style, index) => (React.createElement(StyleBlock, { key: index, onClick: () => onClick(style, index) }, styleItems[style].map((item, index) => (React.createElement(BlockItem, { key: index },
16
+ React.createElement(Label, { hide: item === '-' }, item),
17
+ React.createElement(Block, null)))))))));
18
+ };
19
+ const styleItems = {
20
+ order: ['1.', '2.', '3.'],
21
+ 'alpha-upper': ['A.', 'B.', 'C.'],
22
+ 'alpha-lower': ['a.', 'b.', 'c.'],
23
+ 'roman-upper': ['I.', 'II.', 'III.'],
24
+ 'roman-lower': ['i.', 'ii.', 'iii.'],
25
+ bullet: ['•', '•', '•'],
26
+ simple: ['-', '-', '-'],
27
+ };
28
+ export const ListContainer = styled.div `
29
+ padding: ${(props) => props.theme.grid.unit * 4}px;
30
+ display: grid;
31
+ grid-template-columns:
32
+ ${(props) => props.theme.grid.unit * 21}px
33
+ ${(props) => props.theme.grid.unit * 21}px;
34
+ gap: 6px;
35
+ `;
36
+ export const StyleBlock = styled.div `
37
+ border: 1px solid ${(props) => props.theme.colors.border.tertiary};
38
+ padding: ${(props) => props.theme.grid.unit * 2}px;
39
+ cursor: pointer;
40
+ display: flex;
41
+ flex-direction: column;
42
+ row-gap: ${(props) => props.theme.grid.unit * 2}px;
43
+
44
+ &:hover {
45
+ background: ${(props) => props.theme.colors.button.default.border.hover};
46
+ }
47
+
48
+ &:active {
49
+ border-color: ${(props) => props.theme.colors.border.primary};
50
+ }
51
+ `;
52
+ export const BlockItem = styled.div `
53
+ display: flex;
54
+ align-items: center;
55
+ gap: 6px;
56
+ `;
57
+ export const Block = styled.div `
58
+ height: 3px;
59
+ width: ${(props) => props.theme.grid.unit * 14}px;
60
+ background: ${(props) => props.theme.colors.border.tertiary};
61
+ `;
62
+ export const Label = styled.div `
63
+ font-family: Lato, serif;
64
+ font-size: ${(props) => props.theme.font.size.small};
65
+ font-weight: ${(props) => props.theme.font.weight.normal};
66
+ line-height: ${(props) => props.theme.font.lineHeight.small};
67
+ font-style: normal;
68
+ color: ${(props) => (props.hide && 'white') || 'initial'};
69
+ `;
@@ -1,4 +1,4 @@
1
- import { ColumnChangeWarningDialog, DeleteIcon, IconTextButton, PlusIcon, } from '@manuscripts/style-guide';
1
+ import { Category, DeleteIcon, Dialog, IconTextButton, PlusIcon, } from '@manuscripts/style-guide';
2
2
  import { skipTracking } from '@manuscripts/track-changes-plugin';
3
3
  import { CellSelection, deleteColumn, deleteRow, mergeCells, selectedRect, splitCell, } from 'prosemirror-tables';
4
4
  import React, { useState } from 'react';
@@ -18,12 +18,22 @@ const getSelectedCellsCount = (state) => {
18
18
  columns: columns > 1 ? `${columns} columns` : `column`,
19
19
  };
20
20
  };
21
+ const ColumnChangeWarningDialog = ({ isOpen, primaryAction, secondaryAction }) => (React.createElement(Dialog, { isOpen: isOpen, category: Category.confirmation, header: "This change can't be tracked", message: "This column action won't be marked as chnage. Do you want to continue?", actions: {
22
+ primary: {
23
+ action: primaryAction,
24
+ title: 'Ok',
25
+ },
26
+ secondary: {
27
+ action: secondaryAction,
28
+ title: 'Cancel',
29
+ },
30
+ } }));
21
31
  export const ContextMenu = ({ view, close, }) => {
22
32
  const runCommand = (command, noTracking) => {
23
33
  command(view.state, (tr) => view.dispatch((noTracking && skipTracking(tr)) || tr));
24
34
  close();
25
35
  };
26
- const [columnAction, setColumnAction] = useState(undefined);
36
+ const [columnAction, setColumnAction] = useState();
27
37
  const isCellSelectionMerged = mergeCells(view.state);
28
38
  const isCellSelectionSplittable = splitCell(view.state);
29
39
  const { rows, columns } = getSelectedCellsCount(view.state);
package/dist/es/index.js CHANGED
@@ -17,6 +17,8 @@ export * from './commands';
17
17
  export { ManuscriptOutline } from './components/outline/ManuscriptOutline';
18
18
  export { OutlineItemIcon } from './components/outline/Outline';
19
19
  export { LevelSelector } from './components/toolbar/LevelSelector';
20
+ export * from './components/toolbar/ListMenuItem';
21
+ export * from './components/toolbar/InsertTableDialog';
20
22
  export * from './menus';
21
23
  export { CollabProvider } from './classes/collabProvider';
22
24
  export { PopperManager } from './lib/popper';
package/dist/es/menus.js CHANGED
@@ -17,17 +17,12 @@ import { schema } from '@manuscripts/transform';
17
17
  import { toggleMark } from 'prosemirror-commands';
18
18
  import { redo, undo } from 'prosemirror-history';
19
19
  import { addInlineComment, blockActive, canInsert, insertAbstract, insertBackMatterSection, insertBlock, insertContributors, insertCrossReference, insertGraphicalAbstract, insertInlineCitation, insertInlineEquation, insertInlineFootnote, insertKeywords, insertLink, insertList, insertSection, markActive, } from './commands';
20
+ import { openInsertTableDialog } from './components/toolbar/InsertTableDialog';
21
+ import { ListMenuItem } from './components/toolbar/ListMenuItem';
20
22
  import { deleteClosestParentElement, findClosestParentElementNodeName, } from './lib/hierarchy';
21
23
  export const getEditorMenus = (editor) => {
22
24
  const { isCommandValid, state } = editor;
23
25
  const doCommand = (command) => () => editor.doCommand(command);
24
- const wrappedDoCommand = (command, tableConfig) => {
25
- return () => {
26
- doCommand((state, dispatch, view) => {
27
- return command(state, dispatch, view, tableConfig);
28
- })();
29
- };
30
- };
31
26
  const edit = {
32
27
  id: 'edit',
33
28
  label: 'Edit',
@@ -223,9 +218,7 @@ export const getEditorMenus = (editor) => {
223
218
  pc: 'CommandOrControl+Option+T',
224
219
  },
225
220
  isEnabled: isCommandValid(canInsert(schema.nodes.table_element)),
226
- run: (tableConfig) => {
227
- wrappedDoCommand(insertBlock(schema.nodes.table_element), tableConfig)();
228
- },
221
+ run: () => openInsertTableDialog(editor.state, editor.dispatch),
229
222
  },
230
223
  {
231
224
  role: 'separator',
@@ -385,35 +378,58 @@ export const getEditorMenus = (editor) => {
385
378
  {
386
379
  id: 'insert-bullet-list',
387
380
  label: 'Bullet List',
381
+ component: ListMenuItem,
388
382
  isEnabled: isCommandValid(insertList(schema.nodes.list, 'bullet')),
389
383
  submenu: [
390
384
  {
391
- id: 'bullet-list-context-menu',
392
- label: '',
385
+ id: 'bullet',
386
+ label: 'Bullet',
387
+ isEnabled: true,
388
+ run: doCommand(insertList(schema.nodes.list, 'bullet')),
389
+ },
390
+ {
391
+ id: 'simple',
392
+ label: 'Simple',
393
393
  isEnabled: true,
394
- options: {
395
- bullet: doCommand(insertList(schema.nodes.list, 'bullet')),
396
- simple: doCommand(insertList(schema.nodes.list, 'simple')),
397
- },
394
+ run: doCommand(insertList(schema.nodes.list, 'simple')),
398
395
  },
399
396
  ],
400
397
  },
401
398
  {
402
399
  id: 'insert-ordered-list',
403
400
  label: 'Ordered List',
401
+ component: ListMenuItem,
404
402
  isEnabled: isCommandValid(insertList(schema.nodes.list, 'order')),
405
403
  submenu: [
406
404
  {
407
- id: 'ordered-list-context-menu',
408
- label: '',
405
+ id: 'order',
406
+ label: 'Order',
407
+ isEnabled: true,
408
+ run: doCommand(insertList(schema.nodes.list, 'order')),
409
+ },
410
+ {
411
+ id: 'alpha-upper',
412
+ label: 'Alpha upper',
413
+ isEnabled: true,
414
+ run: doCommand(insertList(schema.nodes.list, 'alpha-upper')),
415
+ },
416
+ {
417
+ id: 'alpha-lower',
418
+ label: 'Alpha lower',
419
+ isEnabled: true,
420
+ run: doCommand(insertList(schema.nodes.list, 'alpha-lower')),
421
+ },
422
+ {
423
+ id: 'roman-upper',
424
+ label: 'Roman upper',
425
+ isEnabled: true,
426
+ run: doCommand(insertList(schema.nodes.list, 'roman-upper')),
427
+ },
428
+ {
429
+ id: 'roman-lower',
430
+ label: 'Roman lower',
409
431
  isEnabled: true,
410
- options: {
411
- order: doCommand(insertList(schema.nodes.list, 'order')),
412
- 'alpha-upper': doCommand(insertList(schema.nodes.list, 'alpha-upper')),
413
- 'alpha-lower': doCommand(insertList(schema.nodes.list, 'alpha-lower')),
414
- 'roman-upper': doCommand(insertList(schema.nodes.list, 'roman-upper')),
415
- 'roman-lower': doCommand(insertList(schema.nodes.list, 'roman-lower')),
416
- },
432
+ run: doCommand(insertList(schema.nodes.list, 'roman-lower')),
417
433
  },
418
434
  ],
419
435
  },
@@ -18,6 +18,7 @@ import { schema } from '@manuscripts/transform';
18
18
  import { toggleMark } from 'prosemirror-commands';
19
19
  import React from 'react';
20
20
  import { addInlineComment, blockActive, canInsert, insertBlock, insertInlineCitation, insertList, markActive, } from './commands';
21
+ import { openInsertTableDialog } from './components/toolbar/InsertTableDialog';
21
22
  export const toolbar = {
22
23
  style: {
23
24
  bold: {
@@ -110,7 +111,7 @@ export const toolbar = {
110
111
  title: 'Insert table',
111
112
  content: React.createElement(ToolbarTableIcon, null),
112
113
  isEnabled: canInsert(schema.nodes.table_element),
113
- run: insertBlock(schema.nodes.table_element),
114
+ run: openInsertTableDialog,
114
115
  },
115
116
  equation_element: {
116
117
  title: 'Insert equation',
@@ -1,2 +1,2 @@
1
- export const VERSION = '2.0.41-LEAN-3918.0';
1
+ export const VERSION = '2.0.41';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -29,9 +29,6 @@ export default (props, Component, componentProps, node, getPos, view, classNames
29
29
  tr.setNodeMarkup(getPos(), undefined, Object.assign(Object.assign({}, node.attrs), nextAttrs)).setSelection(selection.map(tr.doc, tr.mapping));
30
30
  view.dispatch(tr);
31
31
  };
32
- if (!node.attrs || !props.dispatch) {
33
- return null;
34
- }
35
32
  return (React.createElement(ThemeProvider, { theme: props.theme },
36
33
  React.createElement(Component, Object.assign({ nodeAttrs: node.attrs, setNodeAttrs: setNodeAttrs, viewProps: { node, view, getPos } }, props, componentProps))));
37
34
  };
@@ -13,7 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { TableConfig } from '@manuscripts/style-guide';
17
16
  import { FootnoteNode, InlineFootnoteNode, ManuscriptEditorState, ManuscriptEditorView, ManuscriptMarkType, ManuscriptNode, ManuscriptNodeType, ManuscriptResolvedPos, ManuscriptTransaction, SectionCategory } from '@manuscripts/transform';
18
17
  import { Attrs, ResolvedPos } from 'prosemirror-model';
19
18
  import { EditorState, NodeSelection, Selection, TextSelection, Transaction } from 'prosemirror-state';
@@ -27,11 +26,12 @@ export declare const isNodeSelection: (selection: Selection) => selection is Nod
27
26
  export declare const blockActive: (type: ManuscriptNodeType) => (state: ManuscriptEditorState) => boolean;
28
27
  export declare const canInsert: (type: ManuscriptNodeType) => (state: ManuscriptEditorState) => boolean;
29
28
  export declare const createSelection: (nodeType: ManuscriptNodeType, position: number, doc: ManuscriptNode) => Selection;
30
- export declare const createBlock: (nodeType: ManuscriptNodeType, position: number, state: ManuscriptEditorState, dispatch?: Dispatch, attrs?: Attrs, tableConfig?: TableConfig) => void;
29
+ export declare const createBlock: (nodeType: ManuscriptNodeType, position: number, state: ManuscriptEditorState, dispatch?: Dispatch, attrs?: Attrs) => void;
31
30
  export declare const insertGeneralFootnote: (tableElementNode: ManuscriptNode, position: number, view: ManuscriptEditorView, tableElementFooter?: NodeWithPos[]) => void;
32
31
  export declare const insertFigure: (file: FileAttachment, state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
32
+ export declare const insertTable: (config: TableConfig, state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
33
33
  export declare const insertSupplement: (file: FileAttachment, state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
34
- export declare const insertBlock: (nodeType: ManuscriptNodeType) => (state: ManuscriptEditorState, dispatch?: Dispatch, view?: EditorView, tableConfig?: TableConfig) => boolean;
34
+ export declare const insertBlock: (nodeType: ManuscriptNodeType) => (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
35
35
  export declare const deleteBlock: (typeToDelete: string) => (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
36
36
  export declare const insertBreak: EditorAction;
37
37
  export declare const findPosBeforeFirstSubsection: ($pos: ManuscriptResolvedPos) => number | null;
@@ -59,7 +59,12 @@ export declare const ignoreMetaNodeBackspaceCommand: (state: ManuscriptEditorSta
59
59
  export declare const isAtEndOfTextBlock: (state: ManuscriptEditorState, $cursor: ResolvedPos, view?: ManuscriptEditorView) => boolean;
60
60
  export declare const ignoreAtomBlockNodeForward: (state: ManuscriptEditorState, dispatch?: Dispatch, view?: ManuscriptEditorView) => boolean;
61
61
  export declare const selectAllIsolating: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
62
- export declare const createAndFillTableElement: (state: ManuscriptEditorState, tableConfig: TableConfig) => import("prosemirror-model").Node;
62
+ export type TableConfig = {
63
+ numberOfColumns: number;
64
+ numberOfRows: number;
65
+ includeHeader: boolean;
66
+ };
67
+ export declare const createAndFillTableElement: (state: ManuscriptEditorState, config?: TableConfig) => import("prosemirror-model").Node;
63
68
  export declare const addNodeComment: (node: ManuscriptNode, state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
64
69
  export declare const addInlineComment: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
65
70
  interface NodeWithPosition {
@@ -0,0 +1,24 @@
1
+ /*!
2
+ * © 2024 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { ManuscriptEditorState } from '@manuscripts/transform';
17
+ import React from 'react';
18
+ import { Dispatch } from '../../commands';
19
+ export type InsertTableDialogProps = {
20
+ state: ManuscriptEditorState;
21
+ dispatch?: Dispatch;
22
+ };
23
+ export declare const InsertTableDialog: React.FC<InsertTableDialogProps>;
24
+ export declare const openInsertTableDialog: (state: ManuscriptEditorState, dispatch?: Dispatch) => void;
@@ -0,0 +1,15 @@
1
+ import { MenuComponentProps } from '@manuscripts/style-guide';
2
+ import React from 'react';
3
+ export declare const ListMenuItem: React.FC<MenuComponentProps>;
4
+ export interface ListSubmenuItemsProps {
5
+ styles: string[];
6
+ onClick: (style: string, index: number) => void;
7
+ }
8
+ export declare const ListStyles: React.FC<ListSubmenuItemsProps>;
9
+ export declare const ListContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
10
+ export declare const StyleBlock: import("styled-components").StyledComponent<"div", any, {}, never>;
11
+ export declare const BlockItem: import("styled-components").StyledComponent<"div", any, {}, never>;
12
+ export declare const Block: import("styled-components").StyledComponent<"div", any, {}, never>;
13
+ export declare const Label: import("styled-components").StyledComponent<"div", any, {
14
+ hide?: boolean | undefined;
15
+ }, never>;
@@ -17,6 +17,8 @@ export * from './commands';
17
17
  export { ManuscriptOutline } from './components/outline/ManuscriptOutline';
18
18
  export { OutlineItemIcon } from './components/outline/Outline';
19
19
  export { LevelSelector } from './components/toolbar/LevelSelector';
20
+ export * from './components/toolbar/ListMenuItem';
21
+ export * from './components/toolbar/InsertTableDialog';
20
22
  export * from './menus';
21
23
  export { ChangeReceiver } from './types';
22
24
  export { CollabProvider } from './classes/collabProvider';
@@ -13,7 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { TableConfig } from '@manuscripts/style-guide';
17
16
  import { EditorState } from 'prosemirror-state';
18
17
  import { EditorView } from 'prosemirror-view';
19
18
  import { ReactNode } from 'react';
@@ -22,7 +21,7 @@ export interface ToolbarButtonConfig {
22
21
  title: string;
23
22
  content: ReactNode;
24
23
  isActive?: (state: EditorState) => boolean;
25
- run: (state: EditorState, dispatch: Dispatch, view?: EditorView, tableConfig?: TableConfig) => void;
24
+ run: (state: EditorState, dispatch: Dispatch, view?: EditorView) => void;
26
25
  isEnabled: (state: EditorState) => boolean;
27
26
  options?: {
28
27
  [key: string]: (state: EditorState, dispatch: Dispatch, view?: EditorView) => void;
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "2.0.41-LEAN-3918.0";
1
+ export declare const VERSION = "2.0.41";
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.0.41-LEAN-3918.0",
4
+ "version": "2.0.41",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-body-editor",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -32,7 +32,7 @@
32
32
  "@iarna/word-count": "^1.1.2",
33
33
  "@manuscripts/json-schema": "2.2.11",
34
34
  "@manuscripts/library": "1.3.11",
35
- "@manuscripts/style-guide": "2.0.16",
35
+ "@manuscripts/style-guide": "2.0.17",
36
36
  "@manuscripts/track-changes-plugin": "1.7.17",
37
37
  "@manuscripts/transform": "2.3.31",
38
38
  "@popperjs/core": "^2.11.8",
@@ -53,7 +53,7 @@
53
53
  "prosemirror-model": "^1.18.3",
54
54
  "prosemirror-schema-list": "^1.2.2",
55
55
  "prosemirror-state": "^1.4.2",
56
- "prosemirror-tables": "^1.5.0",
56
+ "prosemirror-tables": "^1.3.5",
57
57
  "prosemirror-transform": "^1.7.0",
58
58
  "prosemirror-utils": "^0.9.6",
59
59
  "prosemirror-view": "^1.29.1",
@@ -111,7 +111,7 @@
111
111
  },
112
112
  "resolutions": {
113
113
  "@types/react": "^18.3.1",
114
- "prosemirror-tables": "^1.5.0"
114
+ "prosemirror-tables": "^1.3.5"
115
115
  },
116
116
  "engines": {
117
117
  "node": ">=20.16.0"