@manuscripts/style-guide 2.0.16 → 2.0.17

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.
@@ -14,38 +14,13 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
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
17
  var __importDefault = (this && this.__importDefault) || function (mod) {
41
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
42
19
  };
43
20
  Object.defineProperty(exports, "__esModule", { value: true });
44
- exports.ColumnChangeWarningDialog = exports.Label = exports.Block = exports.BlockItem = exports.StyleBlock = exports.ListContainer = exports.bulletListContextMenu = exports.orderedListContextMenu = exports.Menus = void 0;
45
- const react_1 = __importStar(require("react"));
21
+ exports.Menus = void 0;
22
+ const react_1 = __importDefault(require("react"));
46
23
  const styled_components_1 = __importDefault(require("styled-components"));
47
- const Dialog_1 = require("../Dialog");
48
- const InsertTableDialog_1 = require("../InsertTableDialog");
49
24
  const Submenu_1 = require("./Submenu");
50
25
  const MenusContainer = styled_components_1.default.div `
51
26
  display: flex;
@@ -69,104 +44,16 @@ const MenuContainer = styled_components_1.default.div `
69
44
  }
70
45
  `;
71
46
  const Menus = ({ menus, innerRef, handleClick, }) => {
72
- const [columnMenu, setColumnMenu] = (0, react_1.useState)(undefined);
73
- const [openDialog, setOpenDialog] = (0, react_1.useState)(false);
74
- const [indices, setIndices] = (0, react_1.useState)([]);
75
- const toggleDialog = () => {
76
- setOpenDialog(!openDialog);
77
- };
78
- return (react_1.default.createElement(MenusContainer, { ref: innerRef },
79
- menus.map((menu, index) => {
80
- return (react_1.default.createElement(MenuContainer, { key: `menu-${index}`, isEnabled: menu.isEnabled },
81
- react_1.default.createElement(MenuHeading, { onMouseDown: (e) => {
82
- e.preventDefault();
83
- handleClick([index]);
84
- }, isOpen: menu.isOpen },
85
- react_1.default.createElement(Submenu_1.Text, null, menu.label)),
86
- menu.isEnabled && menu.isOpen && menu.submenu && (react_1.default.createElement(Submenu_1.SubmenusContainer, null, menu.submenu.map((submenu, sindex) => {
87
- return (react_1.default.createElement(Submenu_1.Submenu, { key: `${index}-${sindex}`, menu: submenu, handleClick: (i) => {
88
- const indices = [index, sindex, ...i];
89
- if ('id' in submenu &&
90
- submenu.id === 'insert-table-element') {
91
- setIndices(indices);
92
- toggleDialog();
93
- }
94
- else {
95
- handleClick(indices);
96
- }
97
- }, setColumnMenu: setColumnMenu }));
98
- })))));
99
- }),
100
- react_1.default.createElement(exports.ColumnChangeWarningDialog, { isOpen: !!columnMenu, primaryAction: () => {
101
- if (columnMenu === null || columnMenu === void 0 ? void 0 : columnMenu.run) {
102
- columnMenu.run();
103
- setColumnMenu(undefined);
104
- }
105
- }, secondaryAction: () => setColumnMenu(undefined) }),
106
- openDialog && (react_1.default.createElement(InsertTableDialog_1.InsertTableDialog, { run: (tableConfig) => handleClick(indices, tableConfig), open: openDialog, onClose: toggleDialog }))));
47
+ return (react_1.default.createElement(MenusContainer, { ref: innerRef }, menus.map((menu, index) => {
48
+ return (react_1.default.createElement(MenuContainer, { key: `menu-${index}`, isEnabled: menu.isEnabled },
49
+ react_1.default.createElement(MenuHeading, { onMouseDown: (e) => {
50
+ e.preventDefault();
51
+ handleClick([index]);
52
+ }, isOpen: menu.isOpen },
53
+ react_1.default.createElement(Submenu_1.Text, null, menu.label)),
54
+ menu.isEnabled && menu.isOpen && menu.submenu && (react_1.default.createElement(Submenu_1.SubmenusContainer, null, menu.submenu.map((submenu, sindex) => {
55
+ return (react_1.default.createElement(Submenu_1.Submenu, { key: `${index}-${sindex}`, menu: submenu, handleClick: (i) => handleClick([index, sindex, ...i]) }));
56
+ })))));
57
+ })));
107
58
  };
108
59
  exports.Menus = Menus;
109
- exports.orderedListContextMenu = [
110
- { items: ['1.', '2.', '3.'], type: 'order' },
111
- { items: ['A.', 'B.', 'C.'], type: 'alpha-upper' },
112
- { items: ['a.', 'b.', 'c.'], type: 'alpha-lower' },
113
- { items: ['I.', 'II.', 'III.'], type: 'roman-upper' },
114
- { items: ['i.', 'ii.', 'iii.'], type: 'roman-lower' },
115
- ];
116
- exports.bulletListContextMenu = [
117
- { items: ['•', '•', '•'], type: 'bullet' },
118
- { items: ['-', '-', '-'], type: 'simple' },
119
- ];
120
- exports.ListContainer = styled_components_1.default.div `
121
- padding: ${(props) => props.theme.grid.unit * 4}px;
122
- display: grid;
123
- grid-template-columns:
124
- ${(props) => props.theme.grid.unit * 21}px
125
- ${(props) => props.theme.grid.unit * 21}px;
126
- gap: 6px;
127
- `;
128
- exports.StyleBlock = styled_components_1.default.div `
129
- border: 1px solid ${(props) => props.theme.colors.border.tertiary};
130
- padding: ${(props) => props.theme.grid.unit * 2}px;
131
- cursor: pointer;
132
- display: flex;
133
- flex-direction: column;
134
- row-gap: ${(props) => props.theme.grid.unit * 2}px;
135
-
136
- &:hover {
137
- background: ${(props) => props.theme.colors.button.default.border.hover};
138
- }
139
-
140
- &:active {
141
- border-color: ${(props) => props.theme.colors.border.primary};
142
- }
143
- `;
144
- exports.BlockItem = styled_components_1.default.div `
145
- display: flex;
146
- align-items: center;
147
- gap: 6px;
148
- `;
149
- exports.Block = styled_components_1.default.div `
150
- height: 3px;
151
- width: ${(props) => props.theme.grid.unit * 14}px;
152
- background: ${(props) => props.theme.colors.border.tertiary};
153
- `;
154
- exports.Label = styled_components_1.default.div `
155
- font-family: Lato, serif;
156
- font-size: ${(props) => props.theme.font.size.small};
157
- font-weight: ${(props) => props.theme.font.weight.normal};
158
- line-height: ${(props) => props.theme.font.lineHeight.small};
159
- font-style: normal;
160
- color: ${(props) => (props.hide && 'white') || 'initial'};
161
- `;
162
- const ColumnChangeWarningDialog = ({ isOpen, primaryAction, secondaryAction }) => (react_1.default.createElement(Dialog_1.Dialog, { isOpen: isOpen, category: Dialog_1.Category.confirmation, header: "This change can't be tracked", message: "This column action won't be marked as chnage. Do you want to continue?", actions: {
163
- primary: {
164
- action: primaryAction,
165
- title: 'Ok',
166
- },
167
- secondary: {
168
- action: secondaryAction,
169
- title: 'Cancel',
170
- },
171
- } }));
172
- exports.ColumnChangeWarningDialog = ColumnChangeWarningDialog;
@@ -18,17 +18,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.Submenu = exports.SubmenusContainer = exports.Text = void 0;
21
+ exports.Submenu = exports.SubmenuLabel = exports.NestedSubmenusContainer = exports.SubmenusContainer = exports.SubmenuContainer = exports.Text = void 0;
22
22
  const react_1 = __importDefault(require("react"));
23
23
  const styled_components_1 = __importDefault(require("styled-components"));
24
24
  const menus_1 = require("../../lib/menus");
25
25
  const icons_1 = require("../icons");
26
- const Menus_1 = require("./Menus");
27
26
  const Shortcut_1 = require("./Shortcut");
28
27
  exports.Text = styled_components_1.default.div `
29
28
  flex: 1 0 auto;
30
29
  `;
31
- const SubmenuContainer = styled_components_1.default.div `
30
+ exports.SubmenuContainer = styled_components_1.default.div `
32
31
  position: relative;
33
32
  `;
34
33
  exports.SubmenusContainer = styled_components_1.default.div `
@@ -54,7 +53,7 @@ exports.SubmenusContainer = styled_components_1.default.div `
54
53
  top: 8px;
55
54
  }
56
55
  `;
57
- const NestedSubmenusContainer = (0, styled_components_1.default)(exports.SubmenusContainer) `
56
+ exports.NestedSubmenusContainer = (0, styled_components_1.default)(exports.SubmenusContainer) `
58
57
  top: 0;
59
58
  left: 100%;
60
59
  `;
@@ -91,45 +90,32 @@ const Container = styled_components_1.default.div `
91
90
  }
92
91
  `;
93
92
  const activeContent = (menu) => (menu.isActive ? '✓' : '');
94
- const isColumnMenu = (menu) => (menu.role !== 'separator' &&
95
- menu.id === 'format-table-add-column-before') ||
96
- menu.id === 'format-table-add-column-after' ||
97
- menu.id === 'format-table-delete-column';
98
- const Submenu = ({ menu, handleClick, setColumnMenu, }) => {
93
+ const SubmenuLabel = ({ menu, handleClick }) => {
94
+ if ((0, menus_1.isMenuSeparator)(menu)) {
95
+ return null;
96
+ }
97
+ return (react_1.default.createElement(Container, { isOpen: menu.isOpen, className: menu.isEnabled ? '' : 'disabled', onMouseDown: (e) => {
98
+ e.preventDefault();
99
+ handleClick([]);
100
+ } },
101
+ react_1.default.createElement(Active, null, activeContent(menu)),
102
+ react_1.default.createElement(exports.Text, null, menu.label),
103
+ menu.submenu && react_1.default.createElement(Arrow, null),
104
+ menu.shortcut && react_1.default.createElement(Shortcut_1.Shortcut, { shortcut: menu.shortcut })));
105
+ };
106
+ exports.SubmenuLabel = SubmenuLabel;
107
+ const Submenu = ({ menu, handleClick }) => {
99
108
  if ((0, menus_1.isMenuSeparator)(menu)) {
100
109
  return react_1.default.createElement(Separator, null);
101
110
  }
102
- if (!menu.submenu && !menu.options) {
103
- return (react_1.default.createElement(Container, { isOpen: menu.isOpen, className: menu.isEnabled ? '' : 'disabled', onMouseDown: (e) => {
104
- e.preventDefault();
105
- handleClick([]);
106
- } },
107
- react_1.default.createElement(Active, null, activeContent(menu)),
108
- react_1.default.createElement(exports.Text, null, menu.label),
109
- menu.shortcut && react_1.default.createElement(Shortcut_1.Shortcut, { shortcut: menu.shortcut })));
111
+ if (menu.component) {
112
+ return react_1.default.createElement(menu.component, { menu: menu, handleClick: handleClick });
110
113
  }
111
- if (menu.options) {
112
- const styles = menu.id === 'bullet-list-context-menu'
113
- ? Menus_1.bulletListContextMenu
114
- : Menus_1.orderedListContextMenu;
115
- return (react_1.default.createElement(Menus_1.ListContainer, null, styles.map((style, index) => (react_1.default.createElement(Menus_1.StyleBlock, { key: index, onClick: () => {
116
- menu.options && menu.options[style.type]();
117
- handleClick([-1, -1]);
118
- } }, style.items.map((style, index) => (react_1.default.createElement(Menus_1.BlockItem, { key: index },
119
- react_1.default.createElement(Menus_1.Label, { hide: style === '-' }, style),
120
- react_1.default.createElement(Menus_1.Block, null)))))))));
114
+ if (!menu.submenu) {
115
+ return react_1.default.createElement(exports.SubmenuLabel, { menu: menu, handleClick: handleClick });
121
116
  }
122
- return (react_1.default.createElement(SubmenuContainer, null,
123
- react_1.default.createElement(Container, { onMouseDown: (e) => {
124
- e.preventDefault();
125
- handleClick([]);
126
- }, isOpen: menu.isOpen, className: menu.isEnabled ? '' : 'disabled' },
127
- react_1.default.createElement(Active, null, activeContent(menu)),
128
- react_1.default.createElement(exports.Text, null, menu.label),
129
- menu.submenu && react_1.default.createElement(Arrow, null),
130
- menu.shortcut && react_1.default.createElement(Shortcut_1.Shortcut, { shortcut: menu.shortcut })),
131
- menu.submenu && menu.isOpen && (react_1.default.createElement(NestedSubmenusContainer, null, menu.submenu.map((submenu, index) => (react_1.default.createElement(exports.Submenu, { key: `menu-${index}`, menu: submenu, handleClick: (i) => isColumnMenu(submenu) && setColumnMenu
132
- ? setColumnMenu(submenu)
133
- : handleClick([index, ...i]) })))))));
117
+ return (react_1.default.createElement(exports.SubmenuContainer, null,
118
+ react_1.default.createElement(exports.SubmenuLabel, { menu: menu, handleClick: handleClick }),
119
+ menu.submenu && menu.isOpen && (react_1.default.createElement(exports.NestedSubmenusContainer, null, menu.submenu.map((submenu, index) => (react_1.default.createElement(exports.Submenu, { key: `menu-${index}`, menu: submenu, handleClick: (i) => handleClick([index, ...i]) })))))));
134
120
  };
135
121
  exports.Submenu = Submenu;
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./Menus"), exports);
18
+ __exportStar(require("./Submenu"), exports);
@@ -53,13 +53,13 @@ const getMenuAt = (state, position) => {
53
53
  const useMenus = (menus) => {
54
54
  const [pointer, setPointer] = (0, react_1.useState)(initialPointer);
55
55
  const state = getMenuState(menus, pointer);
56
- const handleClick = (0, react_1.useCallback)((indices, tableConfig) => {
56
+ const handleClick = (0, react_1.useCallback)((indices) => {
57
57
  const menu = getMenuAt(state, indices);
58
58
  if (!menu || !menu.isEnabled) {
59
59
  return;
60
60
  }
61
61
  if (menu.run) {
62
- menu.run(tableConfig);
62
+ menu.run();
63
63
  setPointer([-1, -1, -1]);
64
64
  }
65
65
  else if (menu.submenu) {
@@ -67,9 +67,6 @@ const useMenus = (menus) => {
67
67
  const index = indices[depth];
68
68
  setPointer(transformPointer(depth, index));
69
69
  }
70
- if (menu.options) {
71
- setPointer([-1, -1, -1]);
72
- }
73
70
  }, [state]);
74
71
  const ref = (0, react_1.useRef)(null);
75
72
  (0, react_1.useEffect)(() => {
package/dist/cjs/index.js CHANGED
@@ -40,7 +40,6 @@ __exportStar(require("./components/RadioButton"), exports);
40
40
  __exportStar(require("./components/AutoSaveInput"), exports);
41
41
  __exportStar(require("./components/Avatar"), exports);
42
42
  __exportStar(require("./components/Dialog"), exports);
43
- __exportStar(require("./components/InsertTableDialog"), exports);
44
43
  __exportStar(require("./components/Checkbox"), exports);
45
44
  __exportStar(require("./components/Form"), exports);
46
45
  __exportStar(require("./components/Resizer"), exports);
@@ -13,10 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import React, { useState } from 'react';
16
+ import React from 'react';
17
17
  import styled from 'styled-components';
18
- import { Category, Dialog } from '../Dialog';
19
- import { InsertTableDialog } from '../InsertTableDialog';
20
18
  import { Submenu, SubmenusContainer, Text } from './Submenu';
21
19
  const MenusContainer = styled.div `
22
20
  display: flex;
@@ -40,102 +38,15 @@ const MenuContainer = styled.div `
40
38
  }
41
39
  `;
42
40
  export const Menus = ({ menus, innerRef, handleClick, }) => {
43
- const [columnMenu, setColumnMenu] = useState(undefined);
44
- const [openDialog, setOpenDialog] = useState(false);
45
- const [indices, setIndices] = useState([]);
46
- const toggleDialog = () => {
47
- setOpenDialog(!openDialog);
48
- };
49
- return (React.createElement(MenusContainer, { ref: innerRef },
50
- menus.map((menu, index) => {
51
- return (React.createElement(MenuContainer, { key: `menu-${index}`, isEnabled: menu.isEnabled },
52
- React.createElement(MenuHeading, { onMouseDown: (e) => {
53
- e.preventDefault();
54
- handleClick([index]);
55
- }, isOpen: menu.isOpen },
56
- React.createElement(Text, null, menu.label)),
57
- menu.isEnabled && menu.isOpen && menu.submenu && (React.createElement(SubmenusContainer, null, menu.submenu.map((submenu, sindex) => {
58
- return (React.createElement(Submenu, { key: `${index}-${sindex}`, menu: submenu, handleClick: (i) => {
59
- const indices = [index, sindex, ...i];
60
- if ('id' in submenu &&
61
- submenu.id === 'insert-table-element') {
62
- setIndices(indices);
63
- toggleDialog();
64
- }
65
- else {
66
- handleClick(indices);
67
- }
68
- }, setColumnMenu: setColumnMenu }));
69
- })))));
70
- }),
71
- React.createElement(ColumnChangeWarningDialog, { isOpen: !!columnMenu, primaryAction: () => {
72
- if (columnMenu === null || columnMenu === void 0 ? void 0 : columnMenu.run) {
73
- columnMenu.run();
74
- setColumnMenu(undefined);
75
- }
76
- }, secondaryAction: () => setColumnMenu(undefined) }),
77
- openDialog && (React.createElement(InsertTableDialog, { run: (tableConfig) => handleClick(indices, tableConfig), open: openDialog, onClose: toggleDialog }))));
41
+ return (React.createElement(MenusContainer, { ref: innerRef }, menus.map((menu, index) => {
42
+ return (React.createElement(MenuContainer, { key: `menu-${index}`, isEnabled: menu.isEnabled },
43
+ React.createElement(MenuHeading, { onMouseDown: (e) => {
44
+ e.preventDefault();
45
+ handleClick([index]);
46
+ }, isOpen: menu.isOpen },
47
+ React.createElement(Text, null, menu.label)),
48
+ menu.isEnabled && menu.isOpen && menu.submenu && (React.createElement(SubmenusContainer, null, menu.submenu.map((submenu, sindex) => {
49
+ return (React.createElement(Submenu, { key: `${index}-${sindex}`, menu: submenu, handleClick: (i) => handleClick([index, sindex, ...i]) }));
50
+ })))));
51
+ })));
78
52
  };
79
- export const orderedListContextMenu = [
80
- { items: ['1.', '2.', '3.'], type: 'order' },
81
- { items: ['A.', 'B.', 'C.'], type: 'alpha-upper' },
82
- { items: ['a.', 'b.', 'c.'], type: 'alpha-lower' },
83
- { items: ['I.', 'II.', 'III.'], type: 'roman-upper' },
84
- { items: ['i.', 'ii.', 'iii.'], type: 'roman-lower' },
85
- ];
86
- export const bulletListContextMenu = [
87
- { items: ['•', '•', '•'], type: 'bullet' },
88
- { items: ['-', '-', '-'], type: 'simple' },
89
- ];
90
- export const ListContainer = styled.div `
91
- padding: ${(props) => props.theme.grid.unit * 4}px;
92
- display: grid;
93
- grid-template-columns:
94
- ${(props) => props.theme.grid.unit * 21}px
95
- ${(props) => props.theme.grid.unit * 21}px;
96
- gap: 6px;
97
- `;
98
- export const StyleBlock = styled.div `
99
- border: 1px solid ${(props) => props.theme.colors.border.tertiary};
100
- padding: ${(props) => props.theme.grid.unit * 2}px;
101
- cursor: pointer;
102
- display: flex;
103
- flex-direction: column;
104
- row-gap: ${(props) => props.theme.grid.unit * 2}px;
105
-
106
- &:hover {
107
- background: ${(props) => props.theme.colors.button.default.border.hover};
108
- }
109
-
110
- &:active {
111
- border-color: ${(props) => props.theme.colors.border.primary};
112
- }
113
- `;
114
- export const BlockItem = styled.div `
115
- display: flex;
116
- align-items: center;
117
- gap: 6px;
118
- `;
119
- export const Block = styled.div `
120
- height: 3px;
121
- width: ${(props) => props.theme.grid.unit * 14}px;
122
- background: ${(props) => props.theme.colors.border.tertiary};
123
- `;
124
- export const Label = styled.div `
125
- font-family: Lato, serif;
126
- font-size: ${(props) => props.theme.font.size.small};
127
- font-weight: ${(props) => props.theme.font.weight.normal};
128
- line-height: ${(props) => props.theme.font.lineHeight.small};
129
- font-style: normal;
130
- color: ${(props) => (props.hide && 'white') || 'initial'};
131
- `;
132
- export const ColumnChangeWarningDialog = ({ isOpen, primaryAction, secondaryAction }) => (React.createElement(Dialog, { isOpen: isOpen, category: Category.confirmation, header: "This change can't be tracked", message: "This column action won't be marked as chnage. Do you want to continue?", actions: {
133
- primary: {
134
- action: primaryAction,
135
- title: 'Ok',
136
- },
137
- secondary: {
138
- action: secondaryAction,
139
- title: 'Cancel',
140
- },
141
- } }));
@@ -17,12 +17,11 @@ import React from 'react';
17
17
  import styled from 'styled-components';
18
18
  import { isMenuSeparator } from '../../lib/menus';
19
19
  import { TriangleCollapsedIcon } from '../icons';
20
- import { Block, BlockItem, bulletListContextMenu, Label, ListContainer, orderedListContextMenu, StyleBlock, } from './Menus';
21
20
  import { Shortcut } from './Shortcut';
22
21
  export const Text = styled.div `
23
22
  flex: 1 0 auto;
24
23
  `;
25
- const SubmenuContainer = styled.div `
24
+ export const SubmenuContainer = styled.div `
26
25
  position: relative;
27
26
  `;
28
27
  export const SubmenusContainer = styled.div `
@@ -48,7 +47,7 @@ export const SubmenusContainer = styled.div `
48
47
  top: 8px;
49
48
  }
50
49
  `;
51
- const NestedSubmenusContainer = styled(SubmenusContainer) `
50
+ export const NestedSubmenusContainer = styled(SubmenusContainer) `
52
51
  top: 0;
53
52
  left: 100%;
54
53
  `;
@@ -85,44 +84,30 @@ const Container = styled.div `
85
84
  }
86
85
  `;
87
86
  const activeContent = (menu) => (menu.isActive ? '✓' : '');
88
- const isColumnMenu = (menu) => (menu.role !== 'separator' &&
89
- menu.id === 'format-table-add-column-before') ||
90
- menu.id === 'format-table-add-column-after' ||
91
- menu.id === 'format-table-delete-column';
92
- export const Submenu = ({ menu, handleClick, setColumnMenu, }) => {
87
+ export const SubmenuLabel = ({ menu, handleClick }) => {
88
+ if (isMenuSeparator(menu)) {
89
+ return null;
90
+ }
91
+ return (React.createElement(Container, { isOpen: menu.isOpen, className: menu.isEnabled ? '' : 'disabled', onMouseDown: (e) => {
92
+ e.preventDefault();
93
+ handleClick([]);
94
+ } },
95
+ React.createElement(Active, null, activeContent(menu)),
96
+ React.createElement(Text, null, menu.label),
97
+ menu.submenu && React.createElement(Arrow, null),
98
+ menu.shortcut && React.createElement(Shortcut, { shortcut: menu.shortcut })));
99
+ };
100
+ export const Submenu = ({ menu, handleClick }) => {
93
101
  if (isMenuSeparator(menu)) {
94
102
  return React.createElement(Separator, null);
95
103
  }
96
- if (!menu.submenu && !menu.options) {
97
- return (React.createElement(Container, { isOpen: menu.isOpen, className: menu.isEnabled ? '' : 'disabled', onMouseDown: (e) => {
98
- e.preventDefault();
99
- handleClick([]);
100
- } },
101
- React.createElement(Active, null, activeContent(menu)),
102
- React.createElement(Text, null, menu.label),
103
- menu.shortcut && React.createElement(Shortcut, { shortcut: menu.shortcut })));
104
+ if (menu.component) {
105
+ return React.createElement(menu.component, { menu: menu, handleClick: handleClick });
104
106
  }
105
- if (menu.options) {
106
- const styles = menu.id === 'bullet-list-context-menu'
107
- ? bulletListContextMenu
108
- : orderedListContextMenu;
109
- return (React.createElement(ListContainer, null, styles.map((style, index) => (React.createElement(StyleBlock, { key: index, onClick: () => {
110
- menu.options && menu.options[style.type]();
111
- handleClick([-1, -1]);
112
- } }, style.items.map((style, index) => (React.createElement(BlockItem, { key: index },
113
- React.createElement(Label, { hide: style === '-' }, style),
114
- React.createElement(Block, null)))))))));
107
+ if (!menu.submenu) {
108
+ return React.createElement(SubmenuLabel, { menu: menu, handleClick: handleClick });
115
109
  }
116
110
  return (React.createElement(SubmenuContainer, null,
117
- React.createElement(Container, { onMouseDown: (e) => {
118
- e.preventDefault();
119
- handleClick([]);
120
- }, isOpen: menu.isOpen, className: menu.isEnabled ? '' : 'disabled' },
121
- React.createElement(Active, null, activeContent(menu)),
122
- React.createElement(Text, null, menu.label),
123
- menu.submenu && React.createElement(Arrow, null),
124
- menu.shortcut && React.createElement(Shortcut, { shortcut: menu.shortcut })),
125
- menu.submenu && menu.isOpen && (React.createElement(NestedSubmenusContainer, null, menu.submenu.map((submenu, index) => (React.createElement(Submenu, { key: `menu-${index}`, menu: submenu, handleClick: (i) => isColumnMenu(submenu) && setColumnMenu
126
- ? setColumnMenu(submenu)
127
- : handleClick([index, ...i]) })))))));
111
+ React.createElement(SubmenuLabel, { menu: menu, handleClick: handleClick }),
112
+ menu.submenu && menu.isOpen && (React.createElement(NestedSubmenusContainer, null, menu.submenu.map((submenu, index) => (React.createElement(Submenu, { key: `menu-${index}`, menu: submenu, handleClick: (i) => handleClick([index, ...i]) })))))));
128
113
  };
@@ -1 +1,2 @@
1
1
  export * from './Menus';
2
+ export * from './Submenu';
@@ -50,13 +50,13 @@ const getMenuAt = (state, position) => {
50
50
  export const useMenus = (menus) => {
51
51
  const [pointer, setPointer] = useState(initialPointer);
52
52
  const state = getMenuState(menus, pointer);
53
- const handleClick = useCallback((indices, tableConfig) => {
53
+ const handleClick = useCallback((indices) => {
54
54
  const menu = getMenuAt(state, indices);
55
55
  if (!menu || !menu.isEnabled) {
56
56
  return;
57
57
  }
58
58
  if (menu.run) {
59
- menu.run(tableConfig);
59
+ menu.run();
60
60
  setPointer([-1, -1, -1]);
61
61
  }
62
62
  else if (menu.submenu) {
@@ -64,9 +64,6 @@ export const useMenus = (menus) => {
64
64
  const index = indices[depth];
65
65
  setPointer(transformPointer(depth, index));
66
66
  }
67
- if (menu.options) {
68
- setPointer([-1, -1, -1]);
69
- }
70
67
  }, [state]);
71
68
  const ref = useRef(null);
72
69
  useEffect(() => {
package/dist/es/index.js CHANGED
@@ -20,7 +20,6 @@ export * from './components/RadioButton';
20
20
  export * from './components/AutoSaveInput';
21
21
  export * from './components/Avatar';
22
22
  export * from './components/Dialog';
23
- export * from './components/InsertTableDialog';
24
23
  export * from './components/Checkbox';
25
24
  export * from './components/Form';
26
25
  export * from './components/Resizer';
@@ -14,31 +14,11 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import React, { Ref } from 'react';
17
- import { Menu, TableConfig } from '../../lib/menus';
17
+ import { Menu } from '../../lib/menus';
18
18
  interface MenusProps {
19
19
  menus: Menu[];
20
20
  innerRef: Ref<HTMLDivElement>;
21
- handleClick: (position: number[], tableConfig?: TableConfig) => void;
21
+ handleClick: (position: number[]) => void;
22
22
  }
23
23
  export declare const Menus: React.FC<MenusProps>;
24
- export declare const orderedListContextMenu: {
25
- items: string[];
26
- type: string;
27
- }[];
28
- export declare const bulletListContextMenu: {
29
- items: string[];
30
- type: string;
31
- }[];
32
- export declare const ListContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
33
- export declare const StyleBlock: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
34
- export declare const BlockItem: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
35
- export declare const Block: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
36
- export declare const Label: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {
37
- hide?: boolean | undefined;
38
- }, never>;
39
- export declare const ColumnChangeWarningDialog: React.FC<{
40
- isOpen: boolean;
41
- primaryAction: () => void;
42
- secondaryAction: () => void;
43
- }>;
44
24
  export {};
@@ -16,11 +16,12 @@
16
16
  import React from 'react';
17
17
  import { Menu, MenuSeparator } from '../../lib/menus';
18
18
  export declare const Text: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
19
+ export declare const SubmenuContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
19
20
  export declare const SubmenusContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
20
- interface SubmenuProps {
21
+ export declare const NestedSubmenusContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
22
+ export interface SubmenuProps {
21
23
  menu: Menu | MenuSeparator;
22
24
  handleClick: (position: number[]) => void;
23
- setColumnMenu?: React.Dispatch<React.SetStateAction<undefined | Menu>>;
24
25
  }
26
+ export declare const SubmenuLabel: React.FC<SubmenuProps>;
25
27
  export declare const Submenu: React.FC<SubmenuProps>;
26
- export {};
@@ -1 +1,2 @@
1
1
  export * from './Menus';
2
+ export * from './Submenu';
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
- import { Menu, MenuSpec, TableConfig } from '../lib/menus';
2
+ import { Menu, MenuSpec } from '../lib/menus';
3
3
  export declare const useMenus: (menus: MenuSpec[]) => {
4
4
  menus: Menu[];
5
- handleClick: (indices: number[], tableConfig?: TableConfig) => void;
5
+ handleClick: (indices: number[]) => void;
6
6
  ref: import("react").RefObject<HTMLDivElement>;
7
7
  };
@@ -21,7 +21,6 @@ export * from './components/RadioButton';
21
21
  export * from './components/AutoSaveInput';
22
22
  export * from './components/Avatar';
23
23
  export * from './components/Dialog';
24
- export * from './components/InsertTableDialog';
25
24
  export * from './components/Checkbox';
26
25
  export * from './components/Form';
27
26
  export * from './components/Resizer';
@@ -13,29 +13,25 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { ManuscriptTransaction } from '@manuscripts/transform';
17
- export type Dispatch = (tr: ManuscriptTransaction) => void;
16
+ import React from 'react';
18
17
  export interface MenuShortcut {
19
18
  mac: string;
20
19
  pc: string;
21
20
  }
22
- export type TableConfig = {
23
- numberOfColumns: number;
24
- numberOfRows: number;
25
- includeHeader: boolean;
26
- };
21
+ export interface MenuComponentProps {
22
+ menu: Menu;
23
+ handleClick: (position: number[]) => void;
24
+ }
27
25
  export interface MenuSpec {
28
26
  id: string;
29
27
  label: string;
30
28
  role?: string;
31
29
  shortcut?: MenuShortcut;
30
+ component?: React.FC<MenuComponentProps>;
32
31
  isActive?: boolean;
33
32
  isEnabled: boolean;
34
- run?: (tableConfig?: TableConfig) => void;
33
+ run?: () => void;
35
34
  submenu?: (MenuSpec | MenuSeparator)[];
36
- options?: {
37
- [key: string]: () => void;
38
- };
39
35
  }
40
36
  export interface Menu extends MenuSpec {
41
37
  isOpen: boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@manuscripts/style-guide",
3
3
  "description": "Shared components for Manuscripts applications",
4
- "version": "2.0.16",
4
+ "version": "2.0.17",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-style-guide",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -1,130 +0,0 @@
1
- "use strict";
2
- /*!
3
- * © 2024 Atypon Systems LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- var desc = Object.getOwnPropertyDescriptor(m, k);
20
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
- desc = { enumerable: true, get: function() { return m[k]; } };
22
- }
23
- Object.defineProperty(o, k2, desc);
24
- }) : (function(o, m, k, k2) {
25
- if (k2 === undefined) k2 = k;
26
- o[k2] = m[k];
27
- }));
28
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }) : function(o, v) {
31
- o["default"] = v;
32
- });
33
- var __importStar = (this && this.__importStar) || function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
- var __importDefault = (this && this.__importDefault) || function (mod) {
41
- return (mod && mod.__esModule) ? mod : { "default": mod };
42
- };
43
- Object.defineProperty(exports, "__esModule", { value: true });
44
- exports.InsertTableDialog = void 0;
45
- const react_1 = __importStar(require("react"));
46
- const react_select_1 = __importDefault(require("react-select"));
47
- const styled_components_1 = __importDefault(require("styled-components"));
48
- const Checkbox_1 = require("./Checkbox");
49
- const Dialog_1 = require("./Dialog");
50
- const Label = styled_components_1.default.div `
51
- padding-right: 16px;
52
- width: 150px;
53
- `;
54
- const SelectContainer = styled_components_1.default.div `
55
- width: 182px;
56
- height: 30px;
57
- `;
58
- const Container = styled_components_1.default.div `
59
- display: flex;
60
- align-items: center;
61
- padding-bottom: 16px;
62
- `;
63
- const OptionWrapper = styled_components_1.default.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 InsertTableDialog = ({ run, open, onClose }) => {
75
- const [numberOfColumns, setNumColumns] = (0, react_1.useState)({ value: 4, label: `4` });
76
- const [numberOfRows, setNumRows] = (0, react_1.useState)({ value: 4, label: `4` });
77
- const [includeHeader, setIncludeHeader] = (0, react_1.useState)(true);
78
- const handleColumnChange = (newValue) => {
79
- setNumColumns(newValue);
80
- };
81
- const handleRowChange = (newValue) => {
82
- setNumRows(newValue);
83
- };
84
- const options = Array.from({ length: 20 }, (_, index) => ({
85
- value: index + 1,
86
- label: `${index + 1}`,
87
- }));
88
- const OptionComponent = ({ innerProps, data, }) => {
89
- return (react_1.default.createElement(OptionWrapper, Object.assign({}, innerProps, { ref: null }), data.label));
90
- };
91
- const insertTableDialogActions = {
92
- primary: {
93
- action: () => {
94
- const tableConfig = {
95
- numberOfColumns: numberOfColumns.value,
96
- numberOfRows: numberOfRows.value,
97
- includeHeader,
98
- };
99
- run(tableConfig);
100
- onClose();
101
- },
102
- title: 'Create table',
103
- },
104
- secondary: {
105
- action: onClose,
106
- title: 'Cancel',
107
- },
108
- };
109
- return (react_1.default.createElement(Dialog_1.Dialog, { isOpen: open, actions: insertTableDialogActions, category: Dialog_1.Category.confirmation, header: 'Insert table', message: '' },
110
- react_1.default.createElement(react_1.default.Fragment, null,
111
- react_1.default.createElement(react_1.default.Fragment, null,
112
- react_1.default.createElement(Container, null,
113
- react_1.default.createElement(Label, null, "Number of columns:"),
114
- react_1.default.createElement(SelectContainer, null,
115
- react_1.default.createElement(react_select_1.default, { onChange: (newValue) => handleColumnChange(newValue), value: numberOfColumns, options: options, components: {
116
- Option: OptionComponent,
117
- }, menuPosition: "fixed", maxMenuHeight: 150 }))),
118
- react_1.default.createElement(Container, null,
119
- react_1.default.createElement(Label, null, "Number of rows:"),
120
- react_1.default.createElement(SelectContainer, null,
121
- react_1.default.createElement(react_select_1.default, { onChange: (newValue) => handleRowChange(newValue), value: numberOfRows, options: options, components: {
122
- Option: OptionComponent,
123
- }, menuPosition: "fixed", maxMenuHeight: 150 })))),
124
- react_1.default.createElement(Checkbox_1.CheckboxLabel, null,
125
- react_1.default.createElement(Checkbox_1.CheckboxField, { name: 'include-header', checked: includeHeader, onChange: (e) => {
126
- setIncludeHeader(e.target.checked);
127
- } }),
128
- react_1.default.createElement("div", null, "Include header row")))));
129
- };
130
- exports.InsertTableDialog = InsertTableDialog;
@@ -1,100 +0,0 @@
1
- /*!
2
- * © 2024 Atypon Systems LLC
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import React, { useState } from 'react';
17
- import Select from 'react-select';
18
- import styled from 'styled-components';
19
- import { CheckboxField, CheckboxLabel } from './Checkbox';
20
- import { Category, Dialog } from './Dialog';
21
- const Label = styled.div `
22
- padding-right: 16px;
23
- width: 150px;
24
- `;
25
- const SelectContainer = styled.div `
26
- width: 182px;
27
- height: 30px;
28
- `;
29
- const Container = styled.div `
30
- display: flex;
31
- align-items: center;
32
- padding-bottom: 16px;
33
- `;
34
- const OptionWrapper = styled.div `
35
- padding-left: ${(props) => props.theme.grid.unit * 4}px;
36
- padding-top: ${(props) => props.theme.grid.unit * 2}px;
37
- padding-bottom: ${(props) => props.theme.grid.unit * 2}px;
38
-
39
- background-color: ${(props) => props.focused ? props.theme.colors.background.fifth : 'transparent'};
40
-
41
- &:hover {
42
- background-color: ${(props) => props.theme.colors.background.fifth};
43
- }
44
- `;
45
- export const InsertTableDialog = ({ run, open, onClose }) => {
46
- const [numberOfColumns, setNumColumns] = useState({ value: 4, label: `4` });
47
- const [numberOfRows, setNumRows] = useState({ value: 4, label: `4` });
48
- const [includeHeader, setIncludeHeader] = useState(true);
49
- const handleColumnChange = (newValue) => {
50
- setNumColumns(newValue);
51
- };
52
- const handleRowChange = (newValue) => {
53
- setNumRows(newValue);
54
- };
55
- const options = Array.from({ length: 20 }, (_, index) => ({
56
- value: index + 1,
57
- label: `${index + 1}`,
58
- }));
59
- const OptionComponent = ({ innerProps, data, }) => {
60
- return (React.createElement(OptionWrapper, Object.assign({}, innerProps, { ref: null }), data.label));
61
- };
62
- const insertTableDialogActions = {
63
- primary: {
64
- action: () => {
65
- const tableConfig = {
66
- numberOfColumns: numberOfColumns.value,
67
- numberOfRows: numberOfRows.value,
68
- includeHeader,
69
- };
70
- run(tableConfig);
71
- onClose();
72
- },
73
- title: 'Create table',
74
- },
75
- secondary: {
76
- action: onClose,
77
- title: 'Cancel',
78
- },
79
- };
80
- return (React.createElement(Dialog, { isOpen: open, actions: insertTableDialogActions, category: Category.confirmation, header: 'Insert table', message: '' },
81
- React.createElement(React.Fragment, null,
82
- React.createElement(React.Fragment, null,
83
- React.createElement(Container, null,
84
- React.createElement(Label, null, "Number of columns:"),
85
- React.createElement(SelectContainer, null,
86
- React.createElement(Select, { onChange: (newValue) => handleColumnChange(newValue), value: numberOfColumns, options: options, components: {
87
- Option: OptionComponent,
88
- }, menuPosition: "fixed", maxMenuHeight: 150 }))),
89
- React.createElement(Container, null,
90
- React.createElement(Label, null, "Number of rows:"),
91
- React.createElement(SelectContainer, null,
92
- React.createElement(Select, { onChange: (newValue) => handleRowChange(newValue), value: numberOfRows, options: options, components: {
93
- Option: OptionComponent,
94
- }, menuPosition: "fixed", maxMenuHeight: 150 })))),
95
- React.createElement(CheckboxLabel, null,
96
- React.createElement(CheckboxField, { name: 'include-header', checked: includeHeader, onChange: (e) => {
97
- setIncludeHeader(e.target.checked);
98
- } }),
99
- React.createElement("div", null, "Include header row")))));
100
- };
@@ -1,22 +0,0 @@
1
- /*!
2
- * © 2024 Atypon Systems LLC
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import React from 'react';
17
- import { TableConfig } from '../lib/menus';
18
- export declare const InsertTableDialog: React.FC<{
19
- run: (tableConfig: TableConfig) => void;
20
- open: boolean;
21
- onClose: () => void;
22
- }>;