@manuscripts/body-editor 1.6.11 → 1.6.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/cjs/commands.js +57 -1
  2. package/dist/cjs/components/toolbar/LevelSelector.js +2 -2
  3. package/dist/cjs/index.js +4 -9
  4. package/dist/cjs/keys/list.js +9 -9
  5. package/dist/cjs/lib/context-menu.js +81 -163
  6. package/dist/cjs/menus.js +353 -405
  7. package/dist/cjs/toolbar.js +30 -34
  8. package/dist/cjs/views/editable_block.js +12 -4
  9. package/dist/es/commands.js +57 -2
  10. package/dist/es/components/toolbar/LevelSelector.js +2 -2
  11. package/dist/es/index.js +2 -4
  12. package/dist/es/keys/list.js +7 -7
  13. package/dist/es/lib/context-menu.js +81 -163
  14. package/dist/es/menus.js +353 -405
  15. package/dist/es/toolbar.js +31 -35
  16. package/dist/es/views/editable_block.js +13 -5
  17. package/dist/types/commands.d.ts +1 -0
  18. package/dist/types/components/toolbar/LevelSelector.d.ts +2 -2
  19. package/dist/types/configs/editor-views.d.ts +14 -14
  20. package/dist/types/index.d.ts +2 -4
  21. package/dist/types/keys/list.d.ts +1 -1
  22. package/dist/types/lib/context-menu.d.ts +0 -7
  23. package/dist/types/menus.d.ts +2 -3
  24. package/dist/types/toolbar.d.ts +18 -1
  25. package/dist/types/views/bibliography_element_editable.d.ts +1 -1
  26. package/dist/types/views/blockquote_element_editable.d.ts +1 -1
  27. package/dist/types/views/bullet_list_editable.d.ts +1 -1
  28. package/dist/types/views/editable_block.d.ts +1 -1
  29. package/dist/types/views/equation_element_editable.d.ts +1 -1
  30. package/dist/types/views/figure_element_editable.d.ts +1 -1
  31. package/dist/types/views/footnote_editable.d.ts +1 -1
  32. package/dist/types/views/footnotes_element_editable.d.ts +1 -1
  33. package/dist/types/views/listing_element_editable.d.ts +1 -1
  34. package/dist/types/views/ordered_list_editable.d.ts +1 -1
  35. package/dist/types/views/paragraph_editable.d.ts +1 -1
  36. package/dist/types/views/placeholder_element_editable.d.ts +1 -1
  37. package/dist/types/views/pullquote_element_editable.d.ts +1 -1
  38. package/dist/types/views/section_title_editable.d.ts +1 -1
  39. package/dist/types/views/table_element_editable.d.ts +1 -1
  40. package/dist/types/views/toc_element_editable.d.ts +1 -1
  41. package/package.json +2 -4
  42. package/dist/cjs/components/application-menu/ApplicationMenu.js +0 -63
  43. package/dist/cjs/components/application-menu/MenuItemContainer.js +0 -127
  44. package/dist/cjs/components/application-menu/Shortcut.js +0 -63
  45. package/dist/cjs/components/application-menu/index.js +0 -22
  46. package/dist/cjs/components/application-menu/menuState.js +0 -49
  47. package/dist/cjs/components/application-menu/types.js +0 -17
  48. package/dist/cjs/components/application-menu/useApplicationMenus.js +0 -154
  49. package/dist/cjs/components/dialog/TableCellBorderOptions.js +0 -64
  50. package/dist/cjs/components/dialog/TableCellOptions.js +0 -50
  51. package/dist/cjs/components/dialog/TableOptions.js +0 -31
  52. package/dist/cjs/components/dialog/commands.js +0 -185
  53. package/dist/cjs/components/dialog/index.js +0 -26
  54. package/dist/cjs/components/dialog/shared.js +0 -48
  55. package/dist/cjs/components/dialog/types.js +0 -9
  56. package/dist/cjs/components/toolbar/ListStyleSelector.js +0 -150
  57. package/dist/cjs/components/toolbar/ManuscriptToolbar.js +0 -104
  58. package/dist/cjs/components/toolbar/OrderListSelector.js +0 -103
  59. package/dist/cjs/views/EditableBlock.js +0 -37
  60. package/dist/es/components/application-menu/ApplicationMenu.js +0 -56
  61. package/dist/es/components/application-menu/MenuItemContainer.js +0 -120
  62. package/dist/es/components/application-menu/Shortcut.js +0 -56
  63. package/dist/es/components/application-menu/index.js +0 -17
  64. package/dist/es/components/application-menu/menuState.js +0 -44
  65. package/dist/es/components/application-menu/types.js +0 -16
  66. package/dist/es/components/application-menu/useApplicationMenus.js +0 -148
  67. package/dist/es/components/dialog/TableCellBorderOptions.js +0 -36
  68. package/dist/es/components/dialog/TableCellOptions.js +0 -22
  69. package/dist/es/components/dialog/TableOptions.js +0 -26
  70. package/dist/es/components/dialog/commands.js +0 -177
  71. package/dist/es/components/dialog/index.js +0 -18
  72. package/dist/es/components/dialog/shared.js +0 -21
  73. package/dist/es/components/dialog/types.js +0 -6
  74. package/dist/es/components/toolbar/ListStyleSelector.js +0 -120
  75. package/dist/es/components/toolbar/ManuscriptToolbar.js +0 -97
  76. package/dist/es/components/toolbar/OrderListSelector.js +0 -72
  77. package/dist/es/views/EditableBlock.js +0 -29
  78. package/dist/types/components/application-menu/ApplicationMenu.d.ts +0 -24
  79. package/dist/types/components/application-menu/MenuItemContainer.d.ts +0 -27
  80. package/dist/types/components/application-menu/Shortcut.d.ts +0 -26
  81. package/dist/types/components/application-menu/index.d.ts +0 -18
  82. package/dist/types/components/application-menu/menuState.d.ts +0 -18
  83. package/dist/types/components/application-menu/types.d.ts +0 -47
  84. package/dist/types/components/application-menu/useApplicationMenus.d.ts +0 -12
  85. package/dist/types/components/dialog/TableCellBorderOptions.d.ts +0 -9
  86. package/dist/types/components/dialog/TableCellOptions.d.ts +0 -4
  87. package/dist/types/components/dialog/TableOptions.d.ts +0 -4
  88. package/dist/types/components/dialog/commands.d.ts +0 -28
  89. package/dist/types/components/dialog/index.d.ts +0 -4
  90. package/dist/types/components/dialog/shared.d.ts +0 -16
  91. package/dist/types/components/dialog/types.d.ts +0 -16
  92. package/dist/types/components/toolbar/ListStyleSelector.d.ts +0 -36
  93. package/dist/types/components/toolbar/ManuscriptToolbar.d.ts +0 -50
  94. package/dist/types/components/toolbar/OrderListSelector.d.ts +0 -14
  95. package/dist/types/views/EditableBlock.d.ts +0 -19
@@ -1,185 +0,0 @@
1
- "use strict";
2
- /*!
3
- * © 2019 Atypon Systems LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.setTableCellBorderStyles = exports.setTableCellStyles = exports.getSelectedTableCellStyles = exports.setTableAttrs = exports.getSelectedTableAttr = void 0;
19
- const transform_1 = require("@manuscripts/transform");
20
- const lodash_es_1 = require("lodash-es");
21
- const prosemirror_tables_1 = require("prosemirror-tables");
22
- const commands_1 = require("../../commands");
23
- const helpers_1 = require("../../lib/helpers");
24
- const getSelectedTableAttr = (state) => {
25
- const { $head } = state.selection;
26
- const tableDepth = (0, helpers_1.nearestAncestor)((0, helpers_1.isNodeOfType)('table'))($head);
27
- if (!tableDepth) {
28
- return {
29
- id: '',
30
- headerRows: 1,
31
- footerRows: 1,
32
- };
33
- }
34
- const tableEl = $head.node(tableDepth);
35
- return tableEl.attrs;
36
- };
37
- exports.getSelectedTableAttr = getSelectedTableAttr;
38
- const setTableAttrs = (attrs) => (state, dispatch) => {
39
- const { selection, tr } = state;
40
- const { $head } = selection;
41
- const tableDepth = (0, helpers_1.nearestAncestor)((0, helpers_1.isNodeOfType)('table'))($head);
42
- if (!tableDepth) {
43
- return false;
44
- }
45
- const tableEl = $head.node(tableDepth);
46
- const start = $head.start(tableDepth);
47
- if (dispatch) {
48
- tr.setNodeMarkup(start - 1, tableEl.type, attrs, tableEl.marks);
49
- dispatch(tr);
50
- }
51
- return true;
52
- };
53
- exports.setTableAttrs = setTableAttrs;
54
- const getTableCellSelection = (selection) => {
55
- if (selection instanceof prosemirror_tables_1.CellSelection) {
56
- const nodes = [];
57
- selection.ranges.map((range) => {
58
- const { parent, pos } = range.$from;
59
- if (!(0, helpers_1.isNodeOfType)('table_cell')) {
60
- return true;
61
- }
62
- nodes.push([parent, pos]);
63
- return true;
64
- });
65
- return nodes;
66
- }
67
- if (!(0, commands_1.isTextSelection)(selection)) {
68
- return [];
69
- }
70
- const depth = (0, helpers_1.nearestAncestor)((0, helpers_1.isNodeOfType)('table_cell'))(selection.$anchor);
71
- if (!depth) {
72
- return [];
73
- }
74
- const { $anchor } = selection;
75
- const node = $anchor.node(depth);
76
- return [[node, $anchor.start(depth)]];
77
- };
78
- const getNeighbouringCells = (state, cells) => {
79
- if (!cells.length) {
80
- return () => [];
81
- }
82
- const $firstCell = state.doc.resolve(cells[0][1]);
83
- const tableDepth = (0, helpers_1.nearestAncestor)((0, helpers_1.isNodeOfType)('table'))($firstCell);
84
- if (!tableDepth) {
85
- throw new Error('Attempting to resolve cell not in table');
86
- }
87
- const table = $firstCell.node(tableDepth);
88
- const map = prosemirror_tables_1.TableMap.get(table);
89
- const offset = $firstCell.start(tableDepth) + 1;
90
- return (direction) => {
91
- const getNeighbourPosition = (pos) => {
92
- const axis = ['top', 'bottom'].includes(direction) ? 'vert' : 'horiz';
93
- const dir = ['bottom', 'right'].includes(direction) ? 1 : -1;
94
- return (map.nextCell(pos - offset, axis, dir) || 0) + offset;
95
- };
96
- return cells
97
- .map(([, pos]) => {
98
- const neighbourPos = getNeighbourPosition(pos);
99
- if (neighbourPos <= offset) {
100
- return null;
101
- }
102
- const $neighbour = state.doc.resolve(neighbourPos);
103
- const neighbour = $neighbour.parent;
104
- if (neighbour.type !== state.schema.nodes.table_cell) {
105
- return null;
106
- }
107
- return [neighbour, neighbourPos];
108
- })
109
- .filter(Boolean);
110
- };
111
- };
112
- const everyNodeAttr = (nodes, attr) => {
113
- const value = (0, lodash_es_1.get)(nodes[0].attrs, attr, null);
114
- return nodes.every((node) => (0, lodash_es_1.get)(node.attrs, attr, null) === value)
115
- ? value
116
- : null;
117
- };
118
- const getSelectedTableCellStyles = (state) => {
119
- const { selection } = state;
120
- const nodes = getTableCellSelection(selection);
121
- const empty = {};
122
- if (!nodes.length) {
123
- return empty;
124
- }
125
- const styles = transform_1.TABLE_CELL_STYLES.reduce((acc, key) => {
126
- const value = everyNodeAttr(nodes.map((node) => node[0]), `styles.${key}`);
127
- acc[key] = value;
128
- return acc;
129
- }, empty);
130
- return styles;
131
- };
132
- exports.getSelectedTableCellStyles = getSelectedTableCellStyles;
133
- const reshapeStyleCommands = (0, helpers_1.mergeSimilarItems)((a, b) => a[1] === b[1], (a, b) => {
134
- return [a[0], a[1], Object.assign(Object.assign({}, a[2]), b[2])];
135
- });
136
- const mapStylesToNodes = (nodes, style) => {
137
- return nodes.map((node) => [node[0], node[1], style]);
138
- };
139
- const applyStylesToTableCells = (commands) => (state, dispatch) => {
140
- const { tr } = state;
141
- if (!commands.length) {
142
- return false;
143
- }
144
- const reshaped = reshapeStyleCommands(commands);
145
- reshaped.map(([node, pos, styles]) => {
146
- tr.setNodeMarkup(pos - 1, undefined, Object.assign(Object.assign({}, node.attrs), { styles: Object.assign(Object.assign({}, node.attrs.styles), styles) }), node.marks);
147
- });
148
- dispatch && dispatch(tr);
149
- return true;
150
- };
151
- const setTableCellStyles = (styles) => (state, dispatch) => {
152
- const { selection } = state;
153
- const nodes = getTableCellSelection(selection);
154
- if (!nodes.length) {
155
- return false;
156
- }
157
- return applyStylesToTableCells(mapStylesToNodes(nodes, styles))(state, dispatch);
158
- };
159
- exports.setTableCellStyles = setTableCellStyles;
160
- const setTableCellBorderStyles = ({ direction, width, color }) => (state, dispatch) => {
161
- const { selection } = state;
162
- const nodes = getTableCellSelection(selection);
163
- if (!nodes.length) {
164
- return false;
165
- }
166
- const neighbours = getNeighbouringCells(state, nodes);
167
- const value = Number(width)
168
- ? `${width}px solid ${color}`
169
- : `1px solid transparent`;
170
- let commands = [];
171
- if (['all', 'top'].includes(direction)) {
172
- commands = commands.concat(mapStylesToNodes(nodes, { 'border-top': value }), mapStylesToNodes(neighbours('top'), { 'border-bottom': value }));
173
- }
174
- if (['all', 'bottom'].includes(direction)) {
175
- commands = commands.concat(mapStylesToNodes(nodes, { 'border-bottom': value }), mapStylesToNodes(neighbours('bottom'), { 'border-top': value }));
176
- }
177
- if (['all', 'left'].includes(direction)) {
178
- commands = commands.concat(mapStylesToNodes(nodes, { 'border-left': value }), mapStylesToNodes(neighbours('left'), { 'border-right': value }));
179
- }
180
- if (['all', 'right'].includes(direction)) {
181
- commands = commands.concat(mapStylesToNodes(nodes, { 'border-right': value }), mapStylesToNodes(neighbours('right'), { 'border-left': value }));
182
- }
183
- return applyStylesToTableCells(commands)(state, dispatch);
184
- };
185
- exports.setTableCellBorderStyles = setTableCellBorderStyles;
@@ -1,26 +0,0 @@
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.DialogController = exports.DialogNames = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const TableCellBorderOptions_1 = __importDefault(require("./TableCellBorderOptions"));
9
- const TableCellOptions_1 = __importDefault(require("./TableCellOptions"));
10
- const TableOptions_1 = __importDefault(require("./TableOptions"));
11
- var types_1 = require("./types");
12
- Object.defineProperty(exports, "DialogNames", { enumerable: true, get: function () { return types_1.DialogNames; } });
13
- const Lookup = {
14
- TableOptions: TableOptions_1.default,
15
- TableCellOptions: TableCellOptions_1.default,
16
- TableCellBorderOptions: TableCellBorderOptions_1.default,
17
- };
18
- const DialogController = (props) => {
19
- const { currentDialog } = props;
20
- if (!currentDialog) {
21
- return null;
22
- }
23
- const Component = Lookup[currentDialog];
24
- return react_1.default.createElement(Component, Object.assign({}, props));
25
- };
26
- exports.DialogController = DialogController;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Modal = void 0;
27
- const style_guide_1 = require("@manuscripts/style-guide");
28
- const react_1 = __importStar(require("react"));
29
- function Modal({ handleCloseDialog, editorState, dispatch, selector, command, header, children, }) {
30
- const [state, setState] = (0, react_1.useState)(selector(editorState));
31
- const handleChange = (0, react_1.useCallback)((key, value) => setState((prevState) => (Object.assign(Object.assign({}, prevState), { [key]: value }))), []);
32
- const handleOK = (0, react_1.useCallback)(() => {
33
- command(state)(editorState, dispatch);
34
- handleCloseDialog();
35
- }, [state, editorState, dispatch, command, handleCloseDialog]);
36
- return (react_1.default.createElement(style_guide_1.Dialog, { category: style_guide_1.Category.confirmation, header: header, isOpen: true, actions: {
37
- primary: {
38
- action: handleOK,
39
- title: 'OK',
40
- isDestructive: false,
41
- },
42
- secondary: {
43
- action: handleCloseDialog,
44
- title: 'Cancel',
45
- },
46
- }, message: children({ state, handleChange }) }));
47
- }
48
- exports.Modal = Modal;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DialogNames = void 0;
4
- var DialogNames;
5
- (function (DialogNames) {
6
- DialogNames["TableOptions"] = "TableOptions";
7
- DialogNames["TableCellOptions"] = "TableCellOptions";
8
- DialogNames["TableCellBorderOptions"] = "TableCellBorderOptions";
9
- })(DialogNames = exports.DialogNames || (exports.DialogNames = {}));
@@ -1,150 +0,0 @@
1
- "use strict";
2
- /*!
3
- * © 2023 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.ListStyleSelector = exports.ListStyleButton = exports.ListButton = void 0;
45
- const ArrowDownBlack_1 = __importDefault(require("@manuscripts/assets/react/ArrowDownBlack"));
46
- const style_guide_1 = require("@manuscripts/style-guide");
47
- const react_1 = __importDefault(require("react"));
48
- const styled_components_1 = __importStar(require("styled-components"));
49
- const buttonCss = (0, styled_components_1.css) `
50
- background-color: ${(props) => props['data-active'] ? '#eee' : props.theme.colors.background.primary};
51
- border: 1px solid ${(props) => props.theme.colors.border.secondary};
52
- cursor: pointer;
53
- display: inline-flex;
54
- align-items: center;
55
- transition: 0.2s all;
56
-
57
- &:hover {
58
- background: ${(props) => props['data-active'] ? '#eee' : props.theme.colors.background.secondary};
59
- z-index: 2;
60
- }
61
-
62
- &:active {
63
- background: #ddd;
64
- }
65
-
66
- &:disabled {
67
- opacity: 0.2;
68
- }
69
- `;
70
- exports.ListButton = styled_components_1.default.button.attrs({
71
- type: 'button',
72
- }) `
73
- ${buttonCss};
74
- padding: 2px ${(props) => props.theme.grid.unit * 1}px 2px
75
- ${(props) => props.theme.grid.unit * 3}px;
76
- border-top-right-radius: 0 !important;
77
- border-bottom-right-radius: 0 !important;
78
- `;
79
- exports.ListStyleButton = styled_components_1.default.button.attrs({
80
- type: 'button',
81
- }) `
82
- ${buttonCss};
83
- border-left: 0;
84
- svg {
85
- width: 8px;
86
- }
87
- path {
88
- stroke: #c9c9c9;
89
- }
90
-
91
- &:hover path {
92
- stroke: #6e6e6e;
93
- }
94
- `;
95
- const ListStyleSelector = ({ disabled, onClickListType, list }) => {
96
- const { isOpen, toggleOpen, wrapperRef } = (0, style_guide_1.useDropdown)();
97
- return (react_1.default.createElement(Container, { onClick: (e) => !disabled && toggleOpen(e), ref: wrapperRef },
98
- react_1.default.createElement(exports.ListStyleButton, { disabled: disabled },
99
- react_1.default.createElement(ArrowDownBlack_1.default, null)),
100
- isOpen && (react_1.default.createElement(style_guide_1.DropdownList, { direction: 'right', top: 6, onClick: toggleOpen },
101
- react_1.default.createElement(ListContainer, null, list.map((style, index) => (react_1.default.createElement(StylesBlock, { onClick: onClickListType, key: index, style: style }))))))));
102
- };
103
- exports.ListStyleSelector = ListStyleSelector;
104
- const Container = styled_components_1.default.div `
105
- display: flex;
106
- `;
107
- const ListContainer = styled_components_1.default.div `
108
- padding: ${(props) => props.theme.grid.unit * 4}px;
109
- display: grid;
110
- grid-template-columns:
111
- ${(props) => props.theme.grid.unit * 21}px
112
- ${(props) => props.theme.grid.unit * 21}px;
113
- gap: 6px;
114
- `;
115
- const StylesBlock = ({ style, onClick }) => (react_1.default.createElement(StyleBlock, { onClick: () => onClick(style.type) }, style.items.map((style, index) => (react_1.default.createElement(BlockItem, { key: index },
116
- react_1.default.createElement(Label, null, style),
117
- react_1.default.createElement(Block, null))))));
118
- const StyleBlock = styled_components_1.default.div `
119
- border: 1px solid ${(props) => props.theme.colors.border.tertiary};
120
- padding: ${(props) => props.theme.grid.unit * 2}px;
121
- cursor: pointer;
122
- display: flex;
123
- flex-direction: column;
124
- row-gap: ${(props) => props.theme.grid.unit * 2}px;
125
-
126
- &:hover {
127
- background: ${(props) => props.theme.colors.button.default.border.hover};
128
- }
129
-
130
- &:active {
131
- border-color: ${(props) => props.theme.colors.border.primary};
132
- }
133
- `;
134
- const BlockItem = styled_components_1.default.div `
135
- display: flex;
136
- align-items: center;
137
- gap: 6px;
138
- `;
139
- const Block = styled_components_1.default.div `
140
- height: 3px;
141
- width: ${(props) => props.theme.grid.unit * 14}px;
142
- background: ${(props) => props.theme.colors.border.tertiary};
143
- `;
144
- const Label = styled_components_1.default.div `
145
- font-family: Lato, serif;
146
- font-size: ${(props) => props.theme.font.size.small};
147
- font-weight: ${(props) => props.theme.font.weight.normal};
148
- line-height: ${(props) => props.theme.font.lineHeight.small};
149
- font-style: normal;
150
- `;
@@ -1,104 +0,0 @@
1
- "use strict";
2
- /*!
3
- * © 2019 Atypon Systems LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.ManuscriptToolbar = exports.ToolbarGroup = exports.ToolbarContainer = exports.ToolbarItem = void 0;
22
- const react_1 = __importDefault(require("react"));
23
- const styled_components_1 = __importDefault(require("styled-components"));
24
- const toolbar_1 = require("../../toolbar");
25
- const LevelSelector_1 = require("./LevelSelector");
26
- exports.ToolbarItem = styled_components_1.default.div `
27
- display: inline-flex;
28
- position: relative;
29
- `;
30
- const ToolbarButton = styled_components_1.default.button.attrs({
31
- type: 'button',
32
- }) `
33
- background-color: ${(props) => props['data-active'] ? '#eee' : props.theme.colors.background.primary};
34
- border: 1px solid ${(props) => props.theme.colors.border.secondary};
35
- cursor: pointer;
36
- padding: 2px ${(props) => props.theme.grid.unit * 3}px;
37
- display: inline-flex;
38
- align-items: center;
39
- transition: 0.2s all;
40
-
41
- &:hover {
42
- background: ${(props) => props['data-active'] ? '#eee' : props.theme.colors.background.secondary};
43
- z-index: 2;
44
- }
45
-
46
- &:active {
47
- background: #ddd;
48
- }
49
-
50
- &:disabled {
51
- opacity: 0.2;
52
- }
53
- `;
54
- exports.ToolbarContainer = styled_components_1.default.div `
55
- margin: ${(props) => props.theme.grid.unit}px;
56
- display: flex;
57
- flex-wrap: wrap;
58
- `;
59
- exports.ToolbarGroup = styled_components_1.default.div `
60
- margin-right: ${(props) => props.theme.grid.unit * 2}px;
61
- margin-bottom: ${(props) => props.theme.grid.unit * 2}px;
62
- white-space: nowrap;
63
-
64
- & ${exports.ToolbarItem} button {
65
- margin-right: 0;
66
- }
67
-
68
- & ${exports.ToolbarItem}:not(:first-of-type) button {
69
- margin-left: -1px;
70
- }
71
-
72
- & ${exports.ToolbarItem}:first-of-type button {
73
- border-top-left-radius: ${(props) => props.theme.grid.radius.small};
74
- border-bottom-left-radius: ${(props) => props.theme.grid.radius.small};
75
- }
76
-
77
- & ${exports.ToolbarItem}:last-of-type button {
78
- border-top-right-radius: ${(props) => props.theme.grid.radius.small};
79
- border-bottom-right-radius: ${(props) => props.theme.grid.radius.small};
80
- }
81
- `;
82
- const ManuscriptToolbar = ({ state, dispatch, view, footnotesEnabled, can }) => {
83
- return (react_1.default.createElement(exports.ToolbarContainer, null,
84
- react_1.default.createElement(exports.ToolbarGroup, null,
85
- react_1.default.createElement(LevelSelector_1.LevelSelector, { state: state, dispatch: dispatch, view: view })),
86
- Object.entries(toolbar_1.toolbar).map(([groupKey, toolbarGroup]) => (react_1.default.createElement(exports.ToolbarGroup, { key: groupKey }, Object.entries(toolbarGroup)
87
- .filter(([itemKey]) => {
88
- switch (itemKey) {
89
- case 'footnotes':
90
- return footnotesEnabled;
91
- case 'highlight':
92
- return can.handleOwnComments;
93
- default:
94
- return true;
95
- }
96
- })
97
- .map(([itemKey, item]) => item.Component ? (react_1.default.createElement(item.Component, Object.assign({ key: itemKey, state: state, dispatch: dispatch, view: view }, item))) : (react_1.default.createElement(exports.ToolbarItem, { key: itemKey },
98
- react_1.default.createElement(ToolbarButton, { title: item.title, "data-active": item.active && item.active(state), disabled: item.enable && !item.enable(state), onMouseDown: (event) => {
99
- event.preventDefault();
100
- item.run(state, dispatch);
101
- view && view.focus();
102
- } }, item.content)))))))));
103
- };
104
- exports.ManuscriptToolbar = ManuscriptToolbar;
@@ -1,103 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.updateListStyle = exports.OrderListSelector = void 0;
30
- const ToolbarIconOrderedList_1 = __importDefault(require("@manuscripts/assets/react/ToolbarIconOrderedList"));
31
- const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
32
- const transform_1 = require("@manuscripts/transform");
33
- const prosemirror_schema_list_1 = require("prosemirror-schema-list");
34
- const prosemirror_state_1 = require("prosemirror-state");
35
- const react_1 = __importStar(require("react"));
36
- const list_1 = require("../../keys/list");
37
- const ListStyleSelector_1 = require("./ListStyleSelector");
38
- const ManuscriptToolbar_1 = require("./ManuscriptToolbar");
39
- const OrderListSelector = ({ state, dispatch, view, title, active, run, enable }) => {
40
- const isEnabled = !enable || enable(state);
41
- const onClickListType = (0, react_1.useCallback)((type) => {
42
- if (!dispatch) {
43
- return;
44
- }
45
- const { $from, $to } = state.selection;
46
- const range = $from.blockRange($to);
47
- const isListNode = range &&
48
- transform_1.schema.nodes.ordered_list.compatibleContent($from.node(range.depth - 1).type);
49
- if (!isListNode) {
50
- (0, list_1.skipTrackingChanges)((0, prosemirror_schema_list_1.wrapInList)(transform_1.schema.nodes.ordered_list, { listStyleType: type }))(state, dispatch);
51
- view && view.focus();
52
- }
53
- else {
54
- (0, exports.updateListStyle)(state, dispatch, range, type);
55
- }
56
- }, [dispatch, state, view]);
57
- return (react_1.default.createElement(ManuscriptToolbar_1.ToolbarItem, null,
58
- react_1.default.createElement(ListStyleSelector_1.ListButton, { title: title, "data-active": active && active(state), disabled: !isEnabled, onMouseDown: (event) => {
59
- event.preventDefault();
60
- run(state, dispatch);
61
- view && view.focus();
62
- } },
63
- react_1.default.createElement(ToolbarIconOrderedList_1.default, null)),
64
- react_1.default.createElement(ListStyleSelector_1.ListStyleSelector, { disabled: !isEnabled, onClickListType: onClickListType, list: [
65
- { items: ['1.', '2.', '3.'], type: 'order' },
66
- { items: ['A.', 'B.', 'C.'], type: 'alpha-upper' },
67
- { items: ['a.', 'b.', 'c.'], type: 'alpha-lower' },
68
- { items: ['I.', 'II.', 'III.'], type: 'roman-upper' },
69
- { items: ['i.', 'ii.', 'iii.'], type: 'roman-lower' },
70
- ] })));
71
- };
72
- exports.OrderListSelector = OrderListSelector;
73
- const updateListStyle = (state, dispatch, range, type) => {
74
- const { $from } = state.selection;
75
- const tr = state.tr;
76
- const targetLevel = range.depth - 1;
77
- const selectionDepth = $from.sharedDepth(state.selection.to);
78
- const parentListDepth = [...Array(selectionDepth)].findIndex((_, index) => {
79
- const node = $from.node(index + 1);
80
- return (node.type === transform_1.schema.nodes.ordered_list ||
81
- node.type === transform_1.schema.nodes.bullet_list);
82
- }) + 1;
83
- const parentListNode = $from.node(parentListDepth);
84
- const parentListPos = $from.before(parentListDepth);
85
- if (parentListDepth === targetLevel) {
86
- replaceToOrderList(parentListPos, parentListPos + parentListNode.nodeSize, parentListNode);
87
- }
88
- else {
89
- parentListNode.descendants((node, pos) => {
90
- if ((node.type === transform_1.schema.nodes.ordered_list ||
91
- node.type === transform_1.schema.nodes.bullet_list) &&
92
- state.doc.resolve(parentListPos + pos + node.nodeSize).depth ===
93
- targetLevel) {
94
- replaceToOrderList(parentListPos + pos, parentListPos + pos + node.nodeSize, node);
95
- }
96
- });
97
- }
98
- function replaceToOrderList(from, to, node) {
99
- tr.replaceRangeWith(from, to, transform_1.schema.nodes.ordered_list.create(Object.assign(Object.assign({}, node.attrs), { listStyleType: type }), node.content, node.marks));
100
- }
101
- dispatch((0, track_changes_plugin_1.skipTracking)(tr).setSelection(prosemirror_state_1.Selection.near(tr.doc.resolve($from.pos))));
102
- };
103
- exports.updateListStyle = updateListStyle;
@@ -1,37 +0,0 @@
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.MenuButton = exports.openMenu = exports.Menus = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const styled_components_1 = __importDefault(require("styled-components"));
9
- const context_menu_1 = require("../lib/context-menu");
10
- const Menus = ({ openAddMenu, openEditMenu }) => {
11
- return (react_1.default.createElement(react_1.default.Fragment, null,
12
- react_1.default.createElement(exports.MenuButton, { href: "#", onClick: openAddMenu, className: "add-block add-block-after", "aria-label": "Open menu", "data-balloon-pos": "down-left" }),
13
- react_1.default.createElement(exports.MenuButton, { href: "#", onClick: openEditMenu, className: "edit-block", "aria-label": "Open menu", "data-balloon-pos": "down-left" })));
14
- };
15
- exports.Menus = Menus;
16
- const openMenu = (viewProps, edit = false) => (e) => {
17
- e.preventDefault();
18
- e.stopPropagation();
19
- const menu = new context_menu_1.ContextMenu(viewProps.node, viewProps.view, viewProps.getPos);
20
- if (edit) {
21
- menu.showEditMenu(e.currentTarget);
22
- }
23
- else {
24
- menu.showAddMenu(e.currentTarget, true);
25
- }
26
- };
27
- exports.openMenu = openMenu;
28
- const EditableBlock = ({ children, canWrite, viewProps, }) => {
29
- return (react_1.default.createElement("div", { className: "block-container" },
30
- react_1.default.createElement("div", { className: "block-gutter", contentEditable: false }, canWrite && (react_1.default.createElement(exports.Menus, { openAddMenu: (0, exports.openMenu)(viewProps), openEditMenu: (0, exports.openMenu)(viewProps, true) }))),
31
- react_1.default.createElement("div", { className: "block" }, children),
32
- react_1.default.createElement("div", { className: "block-gutter", contentEditable: false })));
33
- };
34
- exports.default = EditableBlock;
35
- exports.MenuButton = styled_components_1.default.a `
36
- position: relative;
37
- `;