@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.
- package/dist/cjs/commands.js +57 -1
- package/dist/cjs/components/toolbar/LevelSelector.js +2 -2
- package/dist/cjs/index.js +4 -9
- package/dist/cjs/keys/list.js +9 -9
- package/dist/cjs/lib/context-menu.js +81 -163
- package/dist/cjs/menus.js +353 -405
- package/dist/cjs/toolbar.js +30 -34
- package/dist/cjs/views/editable_block.js +12 -4
- package/dist/es/commands.js +57 -2
- package/dist/es/components/toolbar/LevelSelector.js +2 -2
- package/dist/es/index.js +2 -4
- package/dist/es/keys/list.js +7 -7
- package/dist/es/lib/context-menu.js +81 -163
- package/dist/es/menus.js +353 -405
- package/dist/es/toolbar.js +31 -35
- package/dist/es/views/editable_block.js +13 -5
- package/dist/types/commands.d.ts +1 -0
- package/dist/types/components/toolbar/LevelSelector.d.ts +2 -2
- package/dist/types/configs/editor-views.d.ts +14 -14
- package/dist/types/index.d.ts +2 -4
- package/dist/types/keys/list.d.ts +1 -1
- package/dist/types/lib/context-menu.d.ts +0 -7
- package/dist/types/menus.d.ts +2 -3
- package/dist/types/toolbar.d.ts +18 -1
- package/dist/types/views/bibliography_element_editable.d.ts +1 -1
- package/dist/types/views/blockquote_element_editable.d.ts +1 -1
- package/dist/types/views/bullet_list_editable.d.ts +1 -1
- package/dist/types/views/editable_block.d.ts +1 -1
- package/dist/types/views/equation_element_editable.d.ts +1 -1
- package/dist/types/views/figure_element_editable.d.ts +1 -1
- package/dist/types/views/footnote_editable.d.ts +1 -1
- package/dist/types/views/footnotes_element_editable.d.ts +1 -1
- package/dist/types/views/listing_element_editable.d.ts +1 -1
- package/dist/types/views/ordered_list_editable.d.ts +1 -1
- package/dist/types/views/paragraph_editable.d.ts +1 -1
- package/dist/types/views/placeholder_element_editable.d.ts +1 -1
- package/dist/types/views/pullquote_element_editable.d.ts +1 -1
- package/dist/types/views/section_title_editable.d.ts +1 -1
- package/dist/types/views/table_element_editable.d.ts +1 -1
- package/dist/types/views/toc_element_editable.d.ts +1 -1
- package/package.json +2 -4
- package/dist/cjs/components/application-menu/ApplicationMenu.js +0 -63
- package/dist/cjs/components/application-menu/MenuItemContainer.js +0 -127
- package/dist/cjs/components/application-menu/Shortcut.js +0 -63
- package/dist/cjs/components/application-menu/index.js +0 -22
- package/dist/cjs/components/application-menu/menuState.js +0 -49
- package/dist/cjs/components/application-menu/types.js +0 -17
- package/dist/cjs/components/application-menu/useApplicationMenus.js +0 -154
- package/dist/cjs/components/dialog/TableCellBorderOptions.js +0 -64
- package/dist/cjs/components/dialog/TableCellOptions.js +0 -50
- package/dist/cjs/components/dialog/TableOptions.js +0 -31
- package/dist/cjs/components/dialog/commands.js +0 -185
- package/dist/cjs/components/dialog/index.js +0 -26
- package/dist/cjs/components/dialog/shared.js +0 -48
- package/dist/cjs/components/dialog/types.js +0 -9
- package/dist/cjs/components/toolbar/ListStyleSelector.js +0 -150
- package/dist/cjs/components/toolbar/ManuscriptToolbar.js +0 -104
- package/dist/cjs/components/toolbar/OrderListSelector.js +0 -103
- package/dist/cjs/views/EditableBlock.js +0 -37
- package/dist/es/components/application-menu/ApplicationMenu.js +0 -56
- package/dist/es/components/application-menu/MenuItemContainer.js +0 -120
- package/dist/es/components/application-menu/Shortcut.js +0 -56
- package/dist/es/components/application-menu/index.js +0 -17
- package/dist/es/components/application-menu/menuState.js +0 -44
- package/dist/es/components/application-menu/types.js +0 -16
- package/dist/es/components/application-menu/useApplicationMenus.js +0 -148
- package/dist/es/components/dialog/TableCellBorderOptions.js +0 -36
- package/dist/es/components/dialog/TableCellOptions.js +0 -22
- package/dist/es/components/dialog/TableOptions.js +0 -26
- package/dist/es/components/dialog/commands.js +0 -177
- package/dist/es/components/dialog/index.js +0 -18
- package/dist/es/components/dialog/shared.js +0 -21
- package/dist/es/components/dialog/types.js +0 -6
- package/dist/es/components/toolbar/ListStyleSelector.js +0 -120
- package/dist/es/components/toolbar/ManuscriptToolbar.js +0 -97
- package/dist/es/components/toolbar/OrderListSelector.js +0 -72
- package/dist/es/views/EditableBlock.js +0 -29
- package/dist/types/components/application-menu/ApplicationMenu.d.ts +0 -24
- package/dist/types/components/application-menu/MenuItemContainer.d.ts +0 -27
- package/dist/types/components/application-menu/Shortcut.d.ts +0 -26
- package/dist/types/components/application-menu/index.d.ts +0 -18
- package/dist/types/components/application-menu/menuState.d.ts +0 -18
- package/dist/types/components/application-menu/types.d.ts +0 -47
- package/dist/types/components/application-menu/useApplicationMenus.d.ts +0 -12
- package/dist/types/components/dialog/TableCellBorderOptions.d.ts +0 -9
- package/dist/types/components/dialog/TableCellOptions.d.ts +0 -4
- package/dist/types/components/dialog/TableOptions.d.ts +0 -4
- package/dist/types/components/dialog/commands.d.ts +0 -28
- package/dist/types/components/dialog/index.d.ts +0 -4
- package/dist/types/components/dialog/shared.d.ts +0 -16
- package/dist/types/components/dialog/types.d.ts +0 -16
- package/dist/types/components/toolbar/ListStyleSelector.d.ts +0 -36
- package/dist/types/components/toolbar/ManuscriptToolbar.d.ts +0 -50
- package/dist/types/components/toolbar/OrderListSelector.d.ts +0 -14
- package/dist/types/views/EditableBlock.d.ts +0 -19
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* © 2019 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 React from 'react';
|
|
17
|
-
import Modal from 'react-modal';
|
|
18
|
-
import styled from 'styled-components';
|
|
19
|
-
import { MenuItemContainer, MenuList, Text } from './MenuItemContainer';
|
|
20
|
-
Modal.setAppElement('#root');
|
|
21
|
-
const ApplicationMenuContainer = styled.div `
|
|
22
|
-
display: flex;
|
|
23
|
-
font-size: 14px;
|
|
24
|
-
`;
|
|
25
|
-
const MenuHeading = styled.div `
|
|
26
|
-
padding: 4px 8px;
|
|
27
|
-
cursor: pointer;
|
|
28
|
-
border: 1px solid transparent;
|
|
29
|
-
border-bottom: none;
|
|
30
|
-
`;
|
|
31
|
-
const MenuContainer = styled.div `
|
|
32
|
-
position: relative;
|
|
33
|
-
|
|
34
|
-
& ${MenuHeading} {
|
|
35
|
-
background-color: #fff;
|
|
36
|
-
color: ${(props) => (props.isEnabled ? '#353535' : '#e2e2e2')};
|
|
37
|
-
|
|
38
|
-
&:hover {
|
|
39
|
-
background-color: ${(props) => (props.isEnabled ? '#f2fbfc' : '#fff')};
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
`;
|
|
43
|
-
export const ApplicationMenus = ({ menuState, wrapperRef, handleItemClick, }) => {
|
|
44
|
-
return (React.createElement(ApplicationMenuContainer, { ref: wrapperRef }, menuState.map((menu, index) => {
|
|
45
|
-
return (React.createElement(MenuContainer, { key: `menu-${index}`, isEnabled: menu.enable },
|
|
46
|
-
React.createElement(MenuHeading, { onMouseDown: (e) => {
|
|
47
|
-
e.preventDefault();
|
|
48
|
-
handleItemClick([index]);
|
|
49
|
-
}, isOpen: menu.isOpen },
|
|
50
|
-
React.createElement(Text, null, menu.label)),
|
|
51
|
-
menu.enable && menu.isOpen && (React.createElement(MenuList, null, menu.submenu &&
|
|
52
|
-
menu.submenu.map((submenu, menuIndex) => {
|
|
53
|
-
return (React.createElement(MenuItemContainer, { key: `menu-${menuIndex}`, item: submenu, depth: 1, handleMenuItemClick: () => handleItemClick([index, menuIndex]), handleSubmenuItemClick: (submenuIndex) => handleItemClick([index, menuIndex, submenuIndex]) }));
|
|
54
|
-
})))));
|
|
55
|
-
})));
|
|
56
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* © 2019 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 TriangleCollapsed from '@manuscripts/assets/react/TriangleCollapsed';
|
|
17
|
-
import React from 'react';
|
|
18
|
-
import styled from 'styled-components';
|
|
19
|
-
import { Shortcut } from './Shortcut';
|
|
20
|
-
export const Text = styled.div `
|
|
21
|
-
flex: 1 0 auto;
|
|
22
|
-
`;
|
|
23
|
-
export const MenuList = styled.div `
|
|
24
|
-
background: #fff;
|
|
25
|
-
border: 1px solid #e2e2e2;
|
|
26
|
-
border-radius: 4px;
|
|
27
|
-
box-shadow: 0 4px 9px 0 rgba(84, 83, 83, 0.3);
|
|
28
|
-
color: #353535;
|
|
29
|
-
min-width: 150px;
|
|
30
|
-
max-height: 70vh;
|
|
31
|
-
overflow-y: auto;
|
|
32
|
-
padding: 4px 0;
|
|
33
|
-
white-space: nowrap;
|
|
34
|
-
width: auto;
|
|
35
|
-
z-index: 10;
|
|
36
|
-
|
|
37
|
-
position: absolute;
|
|
38
|
-
|
|
39
|
-
&[data-placement='bottom-start'] {
|
|
40
|
-
border-top-left-radius: 0;
|
|
41
|
-
border-top-right-radius: 0;
|
|
42
|
-
}
|
|
43
|
-
closeMenu={closeMenu}
|
|
44
|
-
|
|
45
|
-
&[data-placement='right-start'] {
|
|
46
|
-
top: 8px;
|
|
47
|
-
}
|
|
48
|
-
`;
|
|
49
|
-
const SubmenuContainer = styled.div `
|
|
50
|
-
position: relative;
|
|
51
|
-
`;
|
|
52
|
-
const SubmenuList = styled(MenuList) `
|
|
53
|
-
top: 0;
|
|
54
|
-
left: 100%;
|
|
55
|
-
`;
|
|
56
|
-
const Separator = styled.div `
|
|
57
|
-
height: 0;
|
|
58
|
-
border-bottom: 1px solid #e2e2e2;
|
|
59
|
-
margin: 4px 0;
|
|
60
|
-
`;
|
|
61
|
-
const Active = styled.div `
|
|
62
|
-
width: 16px;
|
|
63
|
-
display: inline-flex;
|
|
64
|
-
flex-shrink: 0;
|
|
65
|
-
justify-content: center;
|
|
66
|
-
align-items: center;
|
|
67
|
-
`;
|
|
68
|
-
const Arrow = styled(TriangleCollapsed) `
|
|
69
|
-
margin-left: 8px;
|
|
70
|
-
`;
|
|
71
|
-
const Container = styled.div `
|
|
72
|
-
align-items: center;
|
|
73
|
-
cursor: pointer;
|
|
74
|
-
display: flex;
|
|
75
|
-
padding: 8px 16px 8px 4px;
|
|
76
|
-
position: relative;
|
|
77
|
-
${(props) => props.isOpen && 'background: #f2fbfc;'}
|
|
78
|
-
|
|
79
|
-
&:hover {
|
|
80
|
-
background: #f2fbfc;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
&.disabled {
|
|
84
|
-
cursor: default;
|
|
85
|
-
opacity: 0.4;
|
|
86
|
-
}
|
|
87
|
-
`;
|
|
88
|
-
const classNameFromState = (item) => (item.enable ? '' : 'disabled');
|
|
89
|
-
const activeContent = (item) => (item.active ? '✓' : '');
|
|
90
|
-
const isSeparator = (item) => item.role === 'separator';
|
|
91
|
-
export const MenuItemContainer = ({ item, handleMenuItemClick, handleSubmenuItemClick, depth, }) => {
|
|
92
|
-
if (isSeparator(item)) {
|
|
93
|
-
return React.createElement(Separator, null);
|
|
94
|
-
}
|
|
95
|
-
if (!item.submenu) {
|
|
96
|
-
return (React.createElement(Container, { isOpen: item.isOpen, className: classNameFromState(item), onMouseDown: (e) => {
|
|
97
|
-
e.preventDefault();
|
|
98
|
-
handleMenuItemClick();
|
|
99
|
-
} },
|
|
100
|
-
React.createElement(Active, null, activeContent(item)),
|
|
101
|
-
React.createElement(Text, null, item.label),
|
|
102
|
-
item.accelerator && React.createElement(Shortcut, { accelerator: item.accelerator })));
|
|
103
|
-
}
|
|
104
|
-
return (React.createElement(SubmenuContainer, null,
|
|
105
|
-
React.createElement(Container, { onMouseDown: (e) => {
|
|
106
|
-
e.preventDefault();
|
|
107
|
-
handleMenuItemClick();
|
|
108
|
-
}, isOpen: item.isOpen, className: classNameFromState(item) },
|
|
109
|
-
React.createElement(Active, null, activeContent(item)),
|
|
110
|
-
React.createElement(Text, null, item.label),
|
|
111
|
-
item.submenu && React.createElement(Arrow, null),
|
|
112
|
-
item.accelerator && React.createElement(Shortcut, { accelerator: item.accelerator })),
|
|
113
|
-
item.isOpen && (React.createElement(SubmenuList, null, item.submenu &&
|
|
114
|
-
item.submenu.map((menu, index) => (React.createElement(MenuItemContainer, { key: `menu-${index}`, item: menu, handleMenuItemClick: () => {
|
|
115
|
-
if (!handleSubmenuItemClick) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
handleSubmenuItemClick(index);
|
|
119
|
-
}, depth: depth + 1 })))))));
|
|
120
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* © 2019 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 React from 'react';
|
|
17
|
-
import styled from 'styled-components';
|
|
18
|
-
import { isMac } from '../../lib/platform';
|
|
19
|
-
export const ShortcutContainer = styled.div `
|
|
20
|
-
display: inline-flex;
|
|
21
|
-
color: #6e6e6e;
|
|
22
|
-
margin-left: 16px;
|
|
23
|
-
flex-shrink: 0;
|
|
24
|
-
justify-content: flex-end;
|
|
25
|
-
`;
|
|
26
|
-
const modifiers = isMac
|
|
27
|
-
? {
|
|
28
|
-
Option: '⌥',
|
|
29
|
-
CommandOrControl: '⌘',
|
|
30
|
-
Shift: '⇧',
|
|
31
|
-
}
|
|
32
|
-
: {
|
|
33
|
-
Option: 'Alt',
|
|
34
|
-
CommandOrControl: 'Ctrl',
|
|
35
|
-
Shift: 'Shift',
|
|
36
|
-
};
|
|
37
|
-
const system = isMac ? 'mac' : 'pc';
|
|
38
|
-
const separator = isMac ? '' : '-';
|
|
39
|
-
const Character = styled.span `
|
|
40
|
-
display: inline-block;
|
|
41
|
-
min-width: 1ch;
|
|
42
|
-
`;
|
|
43
|
-
const acceleratorParts = (accelerator) => {
|
|
44
|
-
const parts = [];
|
|
45
|
-
for (const part of accelerator[system].split('+')) {
|
|
46
|
-
if (part in modifiers) {
|
|
47
|
-
parts.push(modifiers[part]);
|
|
48
|
-
parts.push(separator);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
parts.push(React.createElement(Character, { key: part }, part));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return parts;
|
|
55
|
-
};
|
|
56
|
-
export const Shortcut = ({ accelerator, }) => React.createElement(ShortcutContainer, null, acceleratorParts(accelerator));
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* © 2019 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
|
-
export { ApplicationMenus } from './ApplicationMenu';
|
|
17
|
-
export { useApplicationMenus } from './useApplicationMenus';
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* © 2019 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
|
-
export const getMenuState = (spec, pointer, depth = 0) => {
|
|
17
|
-
const pointerPart = pointer[depth];
|
|
18
|
-
return spec.map((itemSpec, index) => {
|
|
19
|
-
return {
|
|
20
|
-
id: itemSpec.id || '',
|
|
21
|
-
role: itemSpec.role || '',
|
|
22
|
-
accelerator: itemSpec.accelerator || null,
|
|
23
|
-
label: itemSpec.label || '',
|
|
24
|
-
active: itemSpec.active || false,
|
|
25
|
-
enable: typeof itemSpec.enable === 'boolean' ? itemSpec.enable : true,
|
|
26
|
-
run: itemSpec.run || null,
|
|
27
|
-
submenu: itemSpec.submenu
|
|
28
|
-
? getMenuState(itemSpec.submenu, pointer, depth + 1)
|
|
29
|
-
: null,
|
|
30
|
-
isOpen: index === pointerPart,
|
|
31
|
-
};
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
export const getMenuItem = (menuState, indices) => {
|
|
35
|
-
const [head, ...tail] = indices.filter((item) => item !== -1);
|
|
36
|
-
const item = menuState[head];
|
|
37
|
-
if (!tail.length) {
|
|
38
|
-
return item;
|
|
39
|
-
}
|
|
40
|
-
else if (item.submenu) {
|
|
41
|
-
return getMenuItem(item.submenu, tail);
|
|
42
|
-
}
|
|
43
|
-
return null;
|
|
44
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* © 2019 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
|
-
export {};
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { getMenuItem, getMenuState } from './menuState';
|
|
3
|
-
const initialPointer = [-1, -1, -1];
|
|
4
|
-
const transformPointer = (depth, index) => (pointer) => pointer.map((pointerPart, i) => {
|
|
5
|
-
if (i === depth) {
|
|
6
|
-
return index;
|
|
7
|
-
}
|
|
8
|
-
if (i > depth) {
|
|
9
|
-
return -1;
|
|
10
|
-
}
|
|
11
|
-
return pointerPart;
|
|
12
|
-
});
|
|
13
|
-
export const prevValidItem = (menu, current) => {
|
|
14
|
-
const prevIndex = current - 1;
|
|
15
|
-
if (prevIndex <= -1) {
|
|
16
|
-
return -1;
|
|
17
|
-
}
|
|
18
|
-
const prevItem = menu[prevIndex];
|
|
19
|
-
if (prevItem.role !== 'separator' && prevItem.enable) {
|
|
20
|
-
return prevIndex;
|
|
21
|
-
}
|
|
22
|
-
return prevValidItem(menu, prevIndex);
|
|
23
|
-
};
|
|
24
|
-
export const nextValidItem = (menu, current) => {
|
|
25
|
-
const nextIndex = current + 1;
|
|
26
|
-
if (nextIndex >= menu.length) {
|
|
27
|
-
return 0;
|
|
28
|
-
}
|
|
29
|
-
const nextItem = menu[nextIndex];
|
|
30
|
-
if (nextItem.role !== 'separator' && nextItem.enable) {
|
|
31
|
-
return nextIndex;
|
|
32
|
-
}
|
|
33
|
-
return nextValidItem(menu, nextIndex);
|
|
34
|
-
};
|
|
35
|
-
export const useApplicationMenus = (menuSpec) => {
|
|
36
|
-
const [pointer, setPointer] = useState(initialPointer);
|
|
37
|
-
const menuState = getMenuState(menuSpec, pointer);
|
|
38
|
-
const toggleMenus = useCallback(() => {
|
|
39
|
-
setPointer(pointer[0] === -1 ? [0, -1, -1] : [-1, -1, -1]);
|
|
40
|
-
}, [pointer]);
|
|
41
|
-
const handleItemClick = useCallback((indices) => {
|
|
42
|
-
const item = getMenuItem(menuState, indices);
|
|
43
|
-
if (!item || !item.enable) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if (item.run) {
|
|
47
|
-
item.run();
|
|
48
|
-
setPointer([-1, -1, -1]);
|
|
49
|
-
}
|
|
50
|
-
else if (item.submenu) {
|
|
51
|
-
const depth = indices.length - 1;
|
|
52
|
-
const index = indices[depth];
|
|
53
|
-
setPointer(transformPointer(depth, index));
|
|
54
|
-
}
|
|
55
|
-
}, [menuState]);
|
|
56
|
-
const wrapperRef = useRef(null);
|
|
57
|
-
const handleKeydown = useCallback((e) => {
|
|
58
|
-
const { key } = e;
|
|
59
|
-
const [menuI, itemI, submenuItemI] = pointer;
|
|
60
|
-
if (key === 'Escape') {
|
|
61
|
-
toggleMenus();
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
else if (menuI === -1) {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
e.preventDefault();
|
|
68
|
-
let menuItem;
|
|
69
|
-
let items;
|
|
70
|
-
switch (key) {
|
|
71
|
-
case 'ArrowLeft':
|
|
72
|
-
if (submenuItemI !== -1) {
|
|
73
|
-
setPointer([menuI, itemI, -1]);
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
setPointer(transformPointer(0, prevValidItem(menuState, menuI)));
|
|
77
|
-
return false;
|
|
78
|
-
case 'ArrowRight':
|
|
79
|
-
if (itemI !== -1 && submenuItemI === -1) {
|
|
80
|
-
menuItem = getMenuItem(menuState, pointer);
|
|
81
|
-
if (!menuItem || !menuItem.submenu) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
setPointer(transformPointer(2, nextValidItem(menuItem.submenu, -1)));
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
setPointer(transformPointer(0, nextValidItem(menuState, menuI)));
|
|
88
|
-
return false;
|
|
89
|
-
case 'ArrowUp':
|
|
90
|
-
if (submenuItemI !== -1) {
|
|
91
|
-
menuItem = getMenuItem(menuState, [menuI, itemI]);
|
|
92
|
-
items = menuItem && menuItem.submenu;
|
|
93
|
-
if (!items) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
setPointer(transformPointer(2, prevValidItem(items, submenuItemI)));
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
items = menuState[menuI].submenu;
|
|
100
|
-
if (!items) {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
setPointer(transformPointer(1, prevValidItem(items, itemI)));
|
|
104
|
-
return false;
|
|
105
|
-
case 'ArrowDown':
|
|
106
|
-
if (submenuItemI !== -1) {
|
|
107
|
-
menuItem = getMenuItem(menuState, [menuI, itemI]);
|
|
108
|
-
items = menuItem && menuItem.submenu;
|
|
109
|
-
if (!items) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
setPointer(transformPointer(2, nextValidItem(items, submenuItemI)));
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
items = menuState[menuI].submenu;
|
|
116
|
-
if (!items) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
setPointer(transformPointer(1, nextValidItem(items, itemI)));
|
|
120
|
-
return false;
|
|
121
|
-
case 'Enter':
|
|
122
|
-
case 'Space':
|
|
123
|
-
handleItemClick(pointer);
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
return false;
|
|
127
|
-
}, [menuState, handleItemClick, pointer, toggleMenus]);
|
|
128
|
-
useEffect(() => {
|
|
129
|
-
const handleClickOutside = (event) => {
|
|
130
|
-
if (wrapperRef.current &&
|
|
131
|
-
!wrapperRef.current.contains(event.target)) {
|
|
132
|
-
setPointer([-1, -1, -1]);
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
document.addEventListener('click', handleClickOutside);
|
|
136
|
-
return () => {
|
|
137
|
-
document.removeEventListener('click', handleClickOutside);
|
|
138
|
-
};
|
|
139
|
-
}, []);
|
|
140
|
-
return {
|
|
141
|
-
handleKeydown,
|
|
142
|
-
toggleMenus,
|
|
143
|
-
menuState,
|
|
144
|
-
handleItemClick,
|
|
145
|
-
isMenuOpen: pointer[0] > -1,
|
|
146
|
-
wrapperRef,
|
|
147
|
-
};
|
|
148
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ColorField } from '@manuscripts/style-guide';
|
|
2
|
-
import React, { useCallback } from 'react';
|
|
3
|
-
import styled from 'styled-components';
|
|
4
|
-
import { setTableCellBorderStyles } from './commands';
|
|
5
|
-
import { Modal } from './shared';
|
|
6
|
-
const LabelStyled = styled.label `
|
|
7
|
-
font-weight: bold;
|
|
8
|
-
display: block;
|
|
9
|
-
`;
|
|
10
|
-
const initialState = () => ({
|
|
11
|
-
direction: 'all',
|
|
12
|
-
width: 1,
|
|
13
|
-
color: '#000',
|
|
14
|
-
});
|
|
15
|
-
const TableCellBorderOptions = ({ editorState, handleCloseDialog, dispatch, colors, handleAddColor, }) => {
|
|
16
|
-
const setColors = colors.filter((color) => color.value);
|
|
17
|
-
const colorExists = useCallback((hex) => setColors.find((color) => color.value === hex), [setColors]);
|
|
18
|
-
return (React.createElement(Modal, { handleCloseDialog: handleCloseDialog, selector: initialState, command: setTableCellBorderStyles, editorState: editorState, dispatch: dispatch, header: "Configure the Cell Borders" }, ({ state, handleChange }) => (React.createElement("form", null,
|
|
19
|
-
React.createElement(LabelStyled, { htmlFor: "direction" }, "Apply to"),
|
|
20
|
-
React.createElement("select", { id: "direction", value: state.direction, onChange: (e) => handleChange('direction', e.target.value) },
|
|
21
|
-
React.createElement("option", { value: "all" }, "All"),
|
|
22
|
-
React.createElement("option", { value: "top" }, "Top"),
|
|
23
|
-
React.createElement("option", { value: "bottom" }, "Bottom"),
|
|
24
|
-
React.createElement("option", { value: "left" }, "Left"),
|
|
25
|
-
React.createElement("option", { value: "right" }, "Right")),
|
|
26
|
-
React.createElement(LabelStyled, { htmlFor: "width" }, "Width (px)"),
|
|
27
|
-
React.createElement("input", { id: "width", type: "number", min: "0", max: "5", value: state.width, onChange: (e) => handleChange('width', e.target.value) }),
|
|
28
|
-
React.createElement(LabelStyled, { htmlFor: "backgroundColor" }, "Border Color"),
|
|
29
|
-
React.createElement(ColorField, { options: setColors, value: state.color, handleChange: (hex) => {
|
|
30
|
-
handleChange('color', hex || '');
|
|
31
|
-
if (hex && !colorExists(hex)) {
|
|
32
|
-
handleAddColor(hex);
|
|
33
|
-
}
|
|
34
|
-
} })))));
|
|
35
|
-
};
|
|
36
|
-
export default TableCellBorderOptions;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ColorField } from '@manuscripts/style-guide';
|
|
2
|
-
import React, { useCallback } from 'react';
|
|
3
|
-
import styled from 'styled-components';
|
|
4
|
-
import { getSelectedTableCellStyles, setTableCellStyles } from './commands';
|
|
5
|
-
import { Modal } from './shared';
|
|
6
|
-
const LabelStyled = styled.label `
|
|
7
|
-
font-weight: bold;
|
|
8
|
-
display: block;
|
|
9
|
-
`;
|
|
10
|
-
const TableCellOptions = ({ editorState, handleCloseDialog, dispatch, colors, handleAddColor, }) => {
|
|
11
|
-
const setColors = colors.filter((color) => color.value);
|
|
12
|
-
const colorExists = useCallback((hex) => setColors.find((color) => color.value === hex), [setColors]);
|
|
13
|
-
return (React.createElement(Modal, { handleCloseDialog: handleCloseDialog, selector: getSelectedTableCellStyles, command: setTableCellStyles, editorState: editorState, dispatch: dispatch, header: "Configure the Selected Table Cells" }, ({ state, handleChange }) => (React.createElement("form", null,
|
|
14
|
-
React.createElement(LabelStyled, { htmlFor: "backgroundColor" }, "Background Color"),
|
|
15
|
-
React.createElement(ColorField, { options: setColors, value: state.backgroundColor || '', handleChange: (hex) => {
|
|
16
|
-
handleChange('backgroundColor', hex || '');
|
|
17
|
-
if (hex && !colorExists(hex)) {
|
|
18
|
-
handleAddColor(hex);
|
|
19
|
-
}
|
|
20
|
-
} })))));
|
|
21
|
-
};
|
|
22
|
-
export default TableCellOptions;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import styled from 'styled-components';
|
|
3
|
-
import { getSelectedTableAttr, setTableAttrs } from './commands';
|
|
4
|
-
import { Modal } from './shared';
|
|
5
|
-
const FormStyled = styled.form `
|
|
6
|
-
display: flex;
|
|
7
|
-
flex-direction: row;
|
|
8
|
-
`;
|
|
9
|
-
const Field = styled.div `
|
|
10
|
-
flex: 1 0 auto;
|
|
11
|
-
width: 50%;
|
|
12
|
-
`;
|
|
13
|
-
const LabelStyled = styled.label `
|
|
14
|
-
font-weight: bold;
|
|
15
|
-
display: block;
|
|
16
|
-
`;
|
|
17
|
-
const TableOptions = ({ editorState, handleCloseDialog, dispatch, }) => {
|
|
18
|
-
return (React.createElement(Modal, { handleCloseDialog: handleCloseDialog, editorState: editorState, dispatch: dispatch, selector: getSelectedTableAttr, command: setTableAttrs, header: "Configure the Selected Table" }, ({ state, handleChange }) => (React.createElement(FormStyled, null,
|
|
19
|
-
React.createElement(Field, null,
|
|
20
|
-
React.createElement(LabelStyled, { htmlFor: "headerRows" }, "Num Header Rows"),
|
|
21
|
-
React.createElement("input", { id: "headerRows", type: "number", min: "0", max: "5", value: state.headerRows, onChange: (e) => handleChange('headerRows', e.target.value) })),
|
|
22
|
-
React.createElement(Field, null,
|
|
23
|
-
React.createElement(LabelStyled, { htmlFor: "footerRows" }, "Num Footer Rows"),
|
|
24
|
-
React.createElement("input", { id: "footerRows", type: "number", min: "0", max: "5", value: state.footerRows, onChange: (e) => handleChange('footerRows', e.target.value) }))))));
|
|
25
|
-
};
|
|
26
|
-
export default TableOptions;
|