@manuscripts/body-editor 2.8.4-LEAN-4358.0 → 2.8.4

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.
@@ -16,7 +16,7 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.addHeaderRow = exports.addRows = exports.addInlineComment = exports.addNodeComment = exports.isCommentingAllowed = 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.insertAward = exports.insertAffiliation = exports.insertContributors = exports.insertGraphicalAbstract = exports.insertBackmatterSection = exports.insertAbstractSection = exports.insertSection = exports.insertBoxElement = exports.insertInlineFootnote = exports.insertFootnotesElement = exports.insertTableElementFooter = exports.insertInlineEquation = exports.insertCrossReference = exports.insertInlineCitation = exports.insertLink = exports.insertSectionLabel = exports.findPosBeforeFirstSubsection = exports.insertBreak = exports.deleteBlock = exports.insertBlock = exports.insertSupplement = exports.insertTable = exports.insertFigure = exports.insertGeneralTableFootnote = exports.insertInlineTableFootnote = exports.insertEmbed = exports.createBlock = exports.createSelection = exports.canInsert = exports.blockActive = exports.isNodeSelection = exports.markActive = exports.addToStart = void 0;
19
- exports.activateSearchReplace = exports.activateSearch = exports.autoComplete = exports.addColumns = void 0;
19
+ exports.activateSearchReplace = exports.activateSearch = exports.indentParagraph = exports.indent = exports.canIndent = exports.autoComplete = exports.addColumns = void 0;
20
20
  const json_schema_1 = require("@manuscripts/json-schema");
21
21
  const track_changes_plugin_1 = require("@manuscripts/track-changes-plugin");
22
22
  const transform_1 = require("@manuscripts/transform");
@@ -94,8 +94,7 @@ const canInsert = (type) => (state) => {
94
94
  const { $from, $to } = state.selection;
95
95
  if (($from.node().type === transform_1.schema.nodes.title ||
96
96
  $from.node().type === transform_1.schema.nodes.section_title) &&
97
- $from.pos === $to.pos &&
98
- type !== transform_1.schema.nodes.text) {
97
+ $from.pos === $to.pos) {
99
98
  return false;
100
99
  }
101
100
  if ((0, transform_1.isElementNodeType)(type) &&
@@ -1157,6 +1156,54 @@ const autoComplete = (state, dispatch) => {
1157
1156
  return false;
1158
1157
  };
1159
1158
  exports.autoComplete = autoComplete;
1159
+ const canIndent = (state) => {
1160
+ const { $from } = state.selection;
1161
+ const node = $from.node($from.depth);
1162
+ const allowedNodeTypes = [transform_1.schema.nodes.paragraph];
1163
+ if (!allowedNodeTypes.includes(node.type)) {
1164
+ return false;
1165
+ }
1166
+ const isBody = (0, prosemirror_utils_1.hasParentNodeOfType)(transform_1.schema.nodes.body)(state.selection);
1167
+ if (!isBody || (0, track_changes_utils_1.isDeleted)(node)) {
1168
+ return false;
1169
+ }
1170
+ if (node.type === transform_1.schema.nodes.paragraph) {
1171
+ const parentNode = $from.node($from.depth - 1);
1172
+ if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.type) !== transform_1.schema.nodes.section &&
1173
+ (parentNode === null || parentNode === void 0 ? void 0 : parentNode.type) !== transform_1.schema.nodes.body) {
1174
+ return false;
1175
+ }
1176
+ }
1177
+ return true;
1178
+ };
1179
+ exports.canIndent = canIndent;
1180
+ const indent = () => (state, dispatch, view) => {
1181
+ const { $from } = state.selection;
1182
+ const nodeType = $from.node().type;
1183
+ if (nodeType === transform_1.schema.nodes.paragraph) {
1184
+ (0, exports.indentParagraph)()(state, dispatch, view);
1185
+ }
1186
+ };
1187
+ exports.indent = indent;
1188
+ const indentParagraph = () => (state, dispatch, view) => {
1189
+ const { $from } = state.selection;
1190
+ const { schema, tr } = state;
1191
+ const beforeParagraph = $from.before($from.depth);
1192
+ const sectionDepth = $from.depth - 1;
1193
+ const parentSection = $from.node(sectionDepth);
1194
+ const sectionStart = $from.start(sectionDepth);
1195
+ const sectionEnd = $from.end(sectionDepth);
1196
+ const sectionTitle = schema.nodes.section_title.create();
1197
+ const sectionContent = prosemirror_model_1.Fragment.from(sectionTitle).append(parentSection.content.cut(beforeParagraph - sectionStart));
1198
+ const newSection = schema.nodes.section.create({ id: (0, transform_1.generateNodeID)(schema.nodes.section) }, sectionContent);
1199
+ tr.replaceWith(beforeParagraph, sectionEnd, newSection);
1200
+ tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, beforeParagraph + 2));
1201
+ if (dispatch) {
1202
+ dispatch((0, track_changes_plugin_1.skipTracking)(tr));
1203
+ view === null || view === void 0 ? void 0 : view.focus();
1204
+ }
1205
+ };
1206
+ exports.indentParagraph = indentParagraph;
1160
1207
  const activateSearch = (state, dispatch) => {
1161
1208
  const pluginState = search_replace_1.searchReplaceKey.getState(state);
1162
1209
  const tr = state.tr.setMeta(search_replace_1.searchReplaceKey, {
package/dist/cjs/menus.js CHANGED
@@ -23,7 +23,6 @@ const commands_1 = require("./commands");
23
23
  const InsertEmbedDialog_1 = require("./components/toolbar/InsertEmbedDialog");
24
24
  const InsertTableDialog_1 = require("./components/toolbar/InsertTableDialog");
25
25
  const ListMenuItem_1 = require("./components/toolbar/ListMenuItem");
26
- const InsertSpecialCharacter_1 = require("./components/views/InsertSpecialCharacter");
27
26
  const hierarchy_1 = require("./lib/hierarchy");
28
27
  const editor_props_1 = require("./plugins/editor-props");
29
28
  const getEditorMenus = (editor) => {
@@ -318,12 +317,6 @@ const getEditorMenus = (editor) => {
318
317
  isEnabled: isCommandValid((0, commands_1.canInsert)(transform_1.schema.nodes.inline_footnote)),
319
318
  run: doCommand(commands_1.insertInlineFootnote),
320
319
  },
321
- {
322
- id: 'insert-special-character',
323
- label: 'Special Characters',
324
- isEnabled: isCommandValid((0, commands_1.canInsert)(transform_1.schema.nodes.text)),
325
- run: () => (0, InsertSpecialCharacter_1.openInsertSpecialCharacterDialog)(editor.view),
326
- },
327
320
  {
328
321
  id: 'insert-comment',
329
322
  label: 'Comment',
@@ -26,6 +26,14 @@ const react_1 = __importDefault(require("react"));
26
26
  const commands_1 = require("./commands");
27
27
  const InsertTableDialog_1 = require("./components/toolbar/InsertTableDialog");
28
28
  exports.toolbar = {
29
+ indentation: {
30
+ indent: {
31
+ title: 'Indent',
32
+ content: react_1.default.createElement(style_guide_1.ToolbarIndentIcon, null),
33
+ isEnabled: (state) => (0, commands_1.canIndent)(state),
34
+ run: (0, commands_1.indent)(),
35
+ },
36
+ },
29
37
  style: {
30
38
  bold: {
31
39
  title: 'Toggle bold',
@@ -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.8.4-LEAN-4358.0';
4
+ exports.VERSION = '2.8.4';
5
5
  exports.MATHJAX_VERSION = '3.2.2';
@@ -86,8 +86,7 @@ export const canInsert = (type) => (state) => {
86
86
  const { $from, $to } = state.selection;
87
87
  if (($from.node().type === schema.nodes.title ||
88
88
  $from.node().type === schema.nodes.section_title) &&
89
- $from.pos === $to.pos &&
90
- type !== schema.nodes.text) {
89
+ $from.pos === $to.pos) {
91
90
  return false;
92
91
  }
93
92
  if (isElementNodeType(type) &&
@@ -1101,6 +1100,51 @@ export const autoComplete = (state, dispatch) => {
1101
1100
  }
1102
1101
  return false;
1103
1102
  };
1103
+ export const canIndent = (state) => {
1104
+ const { $from } = state.selection;
1105
+ const node = $from.node($from.depth);
1106
+ const allowedNodeTypes = [schema.nodes.paragraph];
1107
+ if (!allowedNodeTypes.includes(node.type)) {
1108
+ return false;
1109
+ }
1110
+ const isBody = hasParentNodeOfType(schema.nodes.body)(state.selection);
1111
+ if (!isBody || isDeleted(node)) {
1112
+ return false;
1113
+ }
1114
+ if (node.type === schema.nodes.paragraph) {
1115
+ const parentNode = $from.node($from.depth - 1);
1116
+ if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.type) !== schema.nodes.section &&
1117
+ (parentNode === null || parentNode === void 0 ? void 0 : parentNode.type) !== schema.nodes.body) {
1118
+ return false;
1119
+ }
1120
+ }
1121
+ return true;
1122
+ };
1123
+ export const indent = () => (state, dispatch, view) => {
1124
+ const { $from } = state.selection;
1125
+ const nodeType = $from.node().type;
1126
+ if (nodeType === schema.nodes.paragraph) {
1127
+ indentParagraph()(state, dispatch, view);
1128
+ }
1129
+ };
1130
+ export const indentParagraph = () => (state, dispatch, view) => {
1131
+ const { $from } = state.selection;
1132
+ const { schema, tr } = state;
1133
+ const beforeParagraph = $from.before($from.depth);
1134
+ const sectionDepth = $from.depth - 1;
1135
+ const parentSection = $from.node(sectionDepth);
1136
+ const sectionStart = $from.start(sectionDepth);
1137
+ const sectionEnd = $from.end(sectionDepth);
1138
+ const sectionTitle = schema.nodes.section_title.create();
1139
+ const sectionContent = Fragment.from(sectionTitle).append(parentSection.content.cut(beforeParagraph - sectionStart));
1140
+ const newSection = schema.nodes.section.create({ id: generateNodeID(schema.nodes.section) }, sectionContent);
1141
+ tr.replaceWith(beforeParagraph, sectionEnd, newSection);
1142
+ tr.setSelection(TextSelection.create(tr.doc, beforeParagraph + 2));
1143
+ if (dispatch) {
1144
+ dispatch(skipTracking(tr));
1145
+ view === null || view === void 0 ? void 0 : view.focus();
1146
+ }
1147
+ };
1104
1148
  export const activateSearch = (state, dispatch) => {
1105
1149
  const pluginState = searchReplaceKey.getState(state);
1106
1150
  const tr = state.tr.setMeta(searchReplaceKey, {
package/dist/es/menus.js CHANGED
@@ -20,7 +20,6 @@ import { activateSearchReplace, addInlineComment, blockActive, canInsert, insert
20
20
  import { openEmbedDialog } from './components/toolbar/InsertEmbedDialog';
21
21
  import { openInsertTableDialog } from './components/toolbar/InsertTableDialog';
22
22
  import { ListMenuItem } from './components/toolbar/ListMenuItem';
23
- import { openInsertSpecialCharacterDialog } from './components/views/InsertSpecialCharacter';
24
23
  import { deleteClosestParentElement, findClosestParentElementNodeName, } from './lib/hierarchy';
25
24
  import { getEditorProps } from './plugins/editor-props';
26
25
  export const getEditorMenus = (editor) => {
@@ -315,12 +314,6 @@ export const getEditorMenus = (editor) => {
315
314
  isEnabled: isCommandValid(canInsert(schema.nodes.inline_footnote)),
316
315
  run: doCommand(insertInlineFootnote),
317
316
  },
318
- {
319
- id: 'insert-special-character',
320
- label: 'Special Characters',
321
- isEnabled: isCommandValid(canInsert(schema.nodes.text)),
322
- run: () => openInsertSpecialCharacterDialog(editor.view),
323
- },
324
317
  {
325
318
  id: 'insert-comment',
326
319
  label: 'Comment',
@@ -13,13 +13,21 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { AddCommentIcon, ToolbarBoldIcon, ToolbarCitationIcon, ToolbarEquationIcon, ToolbarFigureIcon, ToolbarItalicIcon, ToolbarOrderedListIcon, ToolbarSubscriptIcon, ToolbarSuperscriptIcon, ToolbarTableIcon, ToolbarUnderlineIcon, ToolbarUnorderedListIcon, } from '@manuscripts/style-guide';
16
+ import { AddCommentIcon, ToolbarBoldIcon, ToolbarCitationIcon, ToolbarEquationIcon, ToolbarFigureIcon, ToolbarIndentIcon, ToolbarItalicIcon, ToolbarOrderedListIcon, ToolbarSubscriptIcon, ToolbarSuperscriptIcon, ToolbarTableIcon, ToolbarUnderlineIcon, ToolbarUnorderedListIcon, } from '@manuscripts/style-guide';
17
17
  import { schema } from '@manuscripts/transform';
18
18
  import { toggleMark } from 'prosemirror-commands';
19
19
  import React from 'react';
20
- import { addInlineComment, blockActive, canInsert, insertBlock, insertInlineCitation, insertList, markActive, } from './commands';
20
+ import { addInlineComment, blockActive, canIndent, canInsert, indent, insertBlock, insertInlineCitation, insertList, markActive, } from './commands';
21
21
  import { openInsertTableDialog } from './components/toolbar/InsertTableDialog';
22
22
  export const toolbar = {
23
+ indentation: {
24
+ indent: {
25
+ title: 'Indent',
26
+ content: React.createElement(ToolbarIndentIcon, null),
27
+ isEnabled: (state) => canIndent(state),
28
+ run: indent(),
29
+ },
30
+ },
23
31
  style: {
24
32
  bold: {
25
33
  title: 'Toggle bold',
@@ -1,2 +1,2 @@
1
- export const VERSION = '2.8.4-LEAN-4358.0';
1
+ export const VERSION = '2.8.4';
2
2
  export const MATHJAX_VERSION = '3.2.2';
@@ -80,5 +80,8 @@ export declare const addRows: (direction: 'top' | 'bottom') => (state: EditorSta
80
80
  export declare const addHeaderRow: (direction: 'above' | 'below') => (state: EditorState, dispatch?: ((tr: Transaction) => void) | undefined) => boolean;
81
81
  export declare const addColumns: (direction: 'right' | 'left') => (state: EditorState, dispatch?: ((tr: Transaction) => void) | undefined) => boolean;
82
82
  export declare const autoComplete: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
83
+ export declare const canIndent: (state: ManuscriptEditorState) => boolean;
84
+ export declare const indent: () => (state: EditorState, dispatch: Dispatch, view?: EditorView) => void;
85
+ export declare const indentParagraph: () => (state: ManuscriptEditorState, dispatch?: Dispatch, view?: ManuscriptEditorView) => void;
83
86
  export declare const activateSearch: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
84
87
  export declare const activateSearchReplace: (state: ManuscriptEditorState, dispatch?: Dispatch) => boolean;
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "2.8.4-LEAN-4358.0";
1
+ export declare const VERSION = "2.8.4";
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.8.4-LEAN-4358.0",
4
+ "version": "2.8.4",
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.1.2",
35
+ "@manuscripts/style-guide": "2.1.3",
36
36
  "@manuscripts/track-changes-plugin": "1.10.0",
37
37
  "@manuscripts/transform": "3.0.45",
38
38
  "@popperjs/core": "^2.11.8",
@@ -1173,11 +1173,3 @@ th:hover > .table-context-menu-button,
1173
1173
  .search-result.search-result-selected {
1174
1174
  background-color: #ffbdf8;
1175
1175
  }
1176
-
1177
- .special-characters-ranges-select__control {
1178
- width: fit-content;
1179
- }
1180
-
1181
- .special-characters-ranges-select__menu {
1182
- min-width: 220px;
1183
- }
@@ -1,139 +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.openInsertSpecialCharacterDialog = void 0;
30
- const style_guide_1 = require("@manuscripts/style-guide");
31
- const react_1 = __importStar(require("react"));
32
- const react_select_1 = __importDefault(require("react-select"));
33
- const styled_components_1 = __importDefault(require("styled-components"));
34
- const editor_props_1 = require("../../plugins/editor-props");
35
- const ReactSubView_1 = __importDefault(require("../../views/ReactSubView"));
36
- const unicodeRanges = [
37
- { label: 'Latin', value: [0x0100, 0x024f] },
38
- { label: 'Greek and Coptic', value: [0x0370, 0x03ff] },
39
- { label: 'Mathematical Operators', value: [0x2200, 0x22ff] },
40
- { label: 'Specials', value: [0xfffc, 0xfffd] },
41
- { label: 'Arrows', value: [0x2190, 0x21ff] },
42
- ];
43
- const reservedCharacters = new Set([
44
- 0x0380, 0x0381, 0x0382, 0x0383, 0x03a2, 0x0378, 0x0379, 0x038b, 0x038d,
45
- ]);
46
- const generateCharacters = (start, end) => Array.from({ length: end - start + 1 }, (_, i) => start + i)
47
- .filter((c) => !reservedCharacters.has(c))
48
- .map((c) => String.fromCharCode(c));
49
- const InsertSpecialCharacterDialog = ({ view, }) => {
50
- const [isOpen, setOpen] = (0, react_1.useState)(true);
51
- const [range, setRange] = (0, react_1.useState)(unicodeRanges[0].value);
52
- const handleRangeChange = (range) => range && setRange(range.value);
53
- const handleClose = () => setOpen(false);
54
- const addCharacter = (event) => view.dispatch(view.state.tr.insertText(event.currentTarget.value, view.state.selection.from));
55
- return (react_1.default.createElement(style_guide_1.StyledModal, { isOpen: isOpen, onRequestClose: handleClose, shouldCloseOnOverlayClick: true },
56
- react_1.default.createElement(Container, { "data-cy": "special-characters-modal" },
57
- react_1.default.createElement(style_guide_1.ModalHeader, null,
58
- react_1.default.createElement(style_guide_1.CloseButton, { onClick: handleClose, "data-cy": "modal-close-button" })),
59
- react_1.default.createElement(StyledModalBody, null,
60
- react_1.default.createElement(StyledModalSidebar, null,
61
- react_1.default.createElement(style_guide_1.ModalSidebarHeader, null,
62
- react_1.default.createElement(style_guide_1.ModalSidebarTitle, null, "Insert special characters")),
63
- react_1.default.createElement(StyledSidebarContent, null,
64
- react_1.default.createElement(react_select_1.default, { onChange: handleRangeChange, classNamePrefix: 'special-characters-ranges-select', defaultValue: unicodeRanges[0], options: unicodeRanges, components: {
65
- Option: OptionComponent,
66
- }, menuPosition: "fixed" }),
67
- react_1.default.createElement(CharactersSetContainer, null,
68
- react_1.default.createElement(CharactersSet, null, generateCharacters(range[0], range[1]).map((character) => (react_1.default.createElement(Character, { key: character, value: character, onClick: addCharacter, "data-cy": "special-character" }, character)))))),
69
- react_1.default.createElement(ButtonsContainer, null,
70
- react_1.default.createElement(style_guide_1.PrimaryButton, { onClick: handleClose }, "Close")))))));
71
- };
72
- const OptionComponent = ({ innerProps, data, }) => {
73
- return (react_1.default.createElement(OptionWrapper, Object.assign({}, innerProps, { ref: null }), data.label));
74
- };
75
- const Container = (0, styled_components_1.default)(style_guide_1.ModalContainer) `
76
- padding: 8px;
77
- `;
78
- const StyledModalSidebar = (0, styled_components_1.default)(style_guide_1.ModalSidebar) `
79
- background: white;
80
- width: 30vw;
81
- `;
82
- const StyledModalBody = (0, styled_components_1.default)(style_guide_1.ModalBody) `
83
- height: 60vh;
84
- `;
85
- const StyledSidebarContent = (0, styled_components_1.default)(style_guide_1.SidebarContent) `
86
- display: flex;
87
- flex-direction: column;
88
- `;
89
- const ButtonsContainer = (0, styled_components_1.default)(style_guide_1.ButtonGroup) `
90
- padding-top: ${(props) => props.theme.grid.unit * 5}px;
91
- `;
92
- const OptionWrapper = styled_components_1.default.div `
93
- padding-left: ${(props) => props.theme.grid.unit * 4}px;
94
- padding-top: ${(props) => props.theme.grid.unit * 2}px;
95
- padding-bottom: ${(props) => props.theme.grid.unit * 2}px;
96
-
97
- background-color: ${(props) => props.focused ? props.theme.colors.background.fifth : 'transparent'};
98
-
99
- &:hover {
100
- background-color: ${(props) => props.theme.colors.background.fifth};
101
- }
102
- `;
103
- const CharactersSetContainer = styled_components_1.default.div `
104
- flex: 1;
105
- overflow-y: scroll;
106
- margin: 18px 0;
107
- border: 1px solid #ddd;
108
- `;
109
- const CharactersSet = (0, styled_components_1.default)(style_guide_1.IconButtonGroup) `
110
- display: grid;
111
- grid-template-columns: repeat(auto-fit, minmax(28px, max-content));
112
- height: ${(props) => props.theme.grid.unit * 8}px;
113
- `;
114
- const Character = (0, styled_components_1.default)(style_guide_1.IconButton) `
115
- border-bottom: 1px solid #ddd;
116
- border-right: 1px solid #ddd;
117
- border-radius: unset;
118
-
119
- :hover {
120
- background-color: #f0f0f0 !important;
121
- }
122
-
123
- :active,
124
- :focus {
125
- color: inherit !important;
126
- border-bottom: 1px solid #ddd !important;
127
- border-right: 1px solid #ddd !important;
128
- }
129
- `;
130
- const openInsertSpecialCharacterDialog = (view) => {
131
- if (!view) {
132
- return;
133
- }
134
- const { state } = view;
135
- const props = (0, editor_props_1.getEditorProps)(state);
136
- const dialog = (0, ReactSubView_1.default)(props, InsertSpecialCharacterDialog, { view }, state.doc, () => 0, view);
137
- document.body.appendChild(dialog);
138
- };
139
- exports.openInsertSpecialCharacterDialog = openInsertSpecialCharacterDialog;
@@ -1,109 +0,0 @@
1
- import { ButtonGroup, CloseButton, IconButton, IconButtonGroup, ModalBody, ModalContainer, ModalHeader, ModalSidebar, ModalSidebarHeader, ModalSidebarTitle, PrimaryButton, SidebarContent, StyledModal, } from '@manuscripts/style-guide';
2
- import React, { useState } from 'react';
3
- import Select from 'react-select';
4
- import styled from 'styled-components';
5
- import { getEditorProps } from '../../plugins/editor-props';
6
- import ReactSubView from '../../views/ReactSubView';
7
- const unicodeRanges = [
8
- { label: 'Latin', value: [0x0100, 0x024f] },
9
- { label: 'Greek and Coptic', value: [0x0370, 0x03ff] },
10
- { label: 'Mathematical Operators', value: [0x2200, 0x22ff] },
11
- { label: 'Specials', value: [0xfffc, 0xfffd] },
12
- { label: 'Arrows', value: [0x2190, 0x21ff] },
13
- ];
14
- const reservedCharacters = new Set([
15
- 0x0380, 0x0381, 0x0382, 0x0383, 0x03a2, 0x0378, 0x0379, 0x038b, 0x038d,
16
- ]);
17
- const generateCharacters = (start, end) => Array.from({ length: end - start + 1 }, (_, i) => start + i)
18
- .filter((c) => !reservedCharacters.has(c))
19
- .map((c) => String.fromCharCode(c));
20
- const InsertSpecialCharacterDialog = ({ view, }) => {
21
- const [isOpen, setOpen] = useState(true);
22
- const [range, setRange] = useState(unicodeRanges[0].value);
23
- const handleRangeChange = (range) => range && setRange(range.value);
24
- const handleClose = () => setOpen(false);
25
- const addCharacter = (event) => view.dispatch(view.state.tr.insertText(event.currentTarget.value, view.state.selection.from));
26
- return (React.createElement(StyledModal, { isOpen: isOpen, onRequestClose: handleClose, shouldCloseOnOverlayClick: true },
27
- React.createElement(Container, { "data-cy": "special-characters-modal" },
28
- React.createElement(ModalHeader, null,
29
- React.createElement(CloseButton, { onClick: handleClose, "data-cy": "modal-close-button" })),
30
- React.createElement(StyledModalBody, null,
31
- React.createElement(StyledModalSidebar, null,
32
- React.createElement(ModalSidebarHeader, null,
33
- React.createElement(ModalSidebarTitle, null, "Insert special characters")),
34
- React.createElement(StyledSidebarContent, null,
35
- React.createElement(Select, { onChange: handleRangeChange, classNamePrefix: 'special-characters-ranges-select', defaultValue: unicodeRanges[0], options: unicodeRanges, components: {
36
- Option: OptionComponent,
37
- }, menuPosition: "fixed" }),
38
- React.createElement(CharactersSetContainer, null,
39
- React.createElement(CharactersSet, null, generateCharacters(range[0], range[1]).map((character) => (React.createElement(Character, { key: character, value: character, onClick: addCharacter, "data-cy": "special-character" }, character)))))),
40
- React.createElement(ButtonsContainer, null,
41
- React.createElement(PrimaryButton, { onClick: handleClose }, "Close")))))));
42
- };
43
- const OptionComponent = ({ innerProps, data, }) => {
44
- return (React.createElement(OptionWrapper, Object.assign({}, innerProps, { ref: null }), data.label));
45
- };
46
- const Container = styled(ModalContainer) `
47
- padding: 8px;
48
- `;
49
- const StyledModalSidebar = styled(ModalSidebar) `
50
- background: white;
51
- width: 30vw;
52
- `;
53
- const StyledModalBody = styled(ModalBody) `
54
- height: 60vh;
55
- `;
56
- const StyledSidebarContent = styled(SidebarContent) `
57
- display: flex;
58
- flex-direction: column;
59
- `;
60
- const ButtonsContainer = styled(ButtonGroup) `
61
- padding-top: ${(props) => props.theme.grid.unit * 5}px;
62
- `;
63
- const OptionWrapper = styled.div `
64
- padding-left: ${(props) => props.theme.grid.unit * 4}px;
65
- padding-top: ${(props) => props.theme.grid.unit * 2}px;
66
- padding-bottom: ${(props) => props.theme.grid.unit * 2}px;
67
-
68
- background-color: ${(props) => props.focused ? props.theme.colors.background.fifth : 'transparent'};
69
-
70
- &:hover {
71
- background-color: ${(props) => props.theme.colors.background.fifth};
72
- }
73
- `;
74
- const CharactersSetContainer = styled.div `
75
- flex: 1;
76
- overflow-y: scroll;
77
- margin: 18px 0;
78
- border: 1px solid #ddd;
79
- `;
80
- const CharactersSet = styled(IconButtonGroup) `
81
- display: grid;
82
- grid-template-columns: repeat(auto-fit, minmax(28px, max-content));
83
- height: ${(props) => props.theme.grid.unit * 8}px;
84
- `;
85
- const Character = styled(IconButton) `
86
- border-bottom: 1px solid #ddd;
87
- border-right: 1px solid #ddd;
88
- border-radius: unset;
89
-
90
- :hover {
91
- background-color: #f0f0f0 !important;
92
- }
93
-
94
- :active,
95
- :focus {
96
- color: inherit !important;
97
- border-bottom: 1px solid #ddd !important;
98
- border-right: 1px solid #ddd !important;
99
- }
100
- `;
101
- export const openInsertSpecialCharacterDialog = (view) => {
102
- if (!view) {
103
- return;
104
- }
105
- const { state } = view;
106
- const props = getEditorProps(state);
107
- const dialog = ReactSubView(props, InsertSpecialCharacterDialog, { view }, state.doc, () => 0, view);
108
- document.body.appendChild(dialog);
109
- };
@@ -1,2 +0,0 @@
1
- import { EditorView } from 'prosemirror-view';
2
- export declare const openInsertSpecialCharacterDialog: (view?: EditorView) => void;