@manuscripts/style-guide 1.5.0-LEAN-3083 → 1.5.0-LEAN-2992

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/cjs/components/AffiliationsList.js +43 -0
  2. package/dist/cjs/components/AuthorsContainer.js +71 -0
  3. package/dist/cjs/components/AuthorsList/Author.js +99 -0
  4. package/dist/cjs/components/AuthorsList/AuthorsList.js +52 -0
  5. package/dist/cjs/components/AuthorsList/index.js +32 -0
  6. package/dist/cjs/components/Menus/Menus.js +62 -0
  7. package/dist/cjs/components/Menus/Shortcut.js +64 -0
  8. package/dist/cjs/components/Menus/Submenu.js +119 -0
  9. package/dist/cjs/components/Menus/index.js +17 -0
  10. package/dist/cjs/hooks/use-menus.js +89 -0
  11. package/dist/cjs/index.js +6 -0
  12. package/dist/cjs/lib/menus.js +22 -0
  13. package/dist/es/components/AffiliationsList.js +36 -0
  14. package/dist/es/components/AuthorsContainer.js +41 -0
  15. package/dist/es/components/AuthorsList/Author.js +69 -0
  16. package/dist/es/components/AuthorsList/AuthorsList.js +45 -0
  17. package/dist/es/components/AuthorsList/index.js +16 -0
  18. package/dist/es/components/Menus/Menus.js +55 -0
  19. package/dist/es/components/Menus/Shortcut.js +57 -0
  20. package/dist/es/components/Menus/Submenu.js +112 -0
  21. package/dist/es/components/Menus/index.js +1 -0
  22. package/dist/es/hooks/use-menus.js +85 -0
  23. package/dist/es/index.js +6 -0
  24. package/dist/es/lib/menus.js +18 -0
  25. package/dist/types/components/AffiliationsList.d.ts +22 -0
  26. package/dist/types/components/AuthorsContainer.d.ts +25 -0
  27. package/dist/types/components/AuthorsList/Author.d.ts +29 -0
  28. package/dist/types/components/AuthorsList/AuthorsList.d.ts +28 -0
  29. package/dist/types/components/AuthorsList/index.d.ts +16 -0
  30. package/dist/types/components/Menus/Menus.d.ts +24 -0
  31. package/dist/types/components/Menus/Shortcut.d.ts +23 -0
  32. package/dist/types/components/Menus/Submenu.d.ts +25 -0
  33. package/dist/types/components/Menus/index.d.ts +1 -0
  34. package/dist/types/hooks/use-menus.d.ts +7 -0
  35. package/dist/types/index.d.ts +6 -0
  36. package/dist/types/lib/menus.d.ts +38 -0
  37. package/package.json +1 -1
package/dist/cjs/index.js CHANGED
@@ -34,9 +34,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.errorsDecoder = exports.useDeepCompareCallback = exports.useDeepCompareMemo = void 0;
36
36
  __exportStar(require("./components/AffiliationsEditor"), exports);
37
+ __exportStar(require("./components/AffiliationsList"), exports);
37
38
  __exportStar(require("./components/AuthorForm"), exports);
38
39
  __exportStar(require("./components/AuthorName"), exports);
40
+ __exportStar(require("./components/AuthorsList"), exports);
39
41
  __exportStar(require("./components/AuthorsDND"), exports);
42
+ __exportStar(require("./components/AuthorsContainer"), exports);
40
43
  __exportStar(require("./components/AlertMessage"), exports);
41
44
  __exportStar(require("./components/Button"), exports);
42
45
  __exportStar(require("./components/ColorField"), exports);
@@ -70,8 +73,10 @@ __exportStar(require("./components/Text"), exports);
70
73
  __exportStar(require("./components/ManuscriptNoteList"), exports);
71
74
  __exportStar(require("./components/Comments"), exports);
72
75
  __exportStar(require("./components/RelativeDate"), exports);
76
+ __exportStar(require("./components/Menus"), exports);
73
77
  __exportStar(require("./hooks/use-dropdown"), exports);
74
78
  __exportStar(require("./hooks/use-files"), exports);
79
+ __exportStar(require("./hooks/use-menus"), exports);
75
80
  var use_deep_compare_1 = require("./hooks/use-deep-compare");
76
81
  Object.defineProperty(exports, "useDeepCompareMemo", { enumerable: true, get: function () { return use_deep_compare_1.useDeepCompareMemo; } });
77
82
  Object.defineProperty(exports, "useDeepCompareCallback", { enumerable: true, get: function () { return use_deep_compare_1.useDeepCompareCallback; } });
@@ -79,6 +84,7 @@ __exportStar(require("./lib/authors"), exports);
79
84
  __exportStar(require("./lib/capabilities"), exports);
80
85
  __exportStar(require("./lib/files"), exports);
81
86
  __exportStar(require("./lib/comments"), exports);
87
+ __exportStar(require("./lib/menus"), exports);
82
88
  var errors_decoder_1 = require("./lib/errors-decoder");
83
89
  Object.defineProperty(exports, "errorsDecoder", { enumerable: true, get: function () { return __importDefault(errors_decoder_1).default; } });
84
90
  __exportStar(require("./types"), exports);
@@ -0,0 +1,22 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.isMenuSeparator = void 0;
19
+ const isMenuSeparator = (menu) => {
20
+ return (menu === null || menu === void 0 ? void 0 : menu.role) === 'separator';
21
+ };
22
+ exports.isMenuSeparator = isMenuSeparator;
@@ -0,0 +1,36 @@
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 formatAddress from '../lib/formatAddress';
19
+ const Container = styled.table `
20
+ border-collapse: collapse;
21
+ font: inherit;
22
+ color: ${(props) => props.theme.colors.text.secondary};
23
+ margin-top: ${(props) => props.theme.grid.unit * 4}px;
24
+ `;
25
+ const Header = styled.th `
26
+ font-weight: ${(props) => props.theme.font.weight.normal}
27
+ padding: 0 4px 0 0;
28
+ vertical-align: top;
29
+ `;
30
+ const Body = styled.td `
31
+ padding: 0;
32
+ `;
33
+ export const AffiliationsList = ({ affiliations, }) => (React.createElement(Container, null,
34
+ React.createElement("tbody", null, Array.from(affiliations.values()).map((affiliation, index) => (React.createElement("tr", { key: affiliation._id },
35
+ React.createElement(Header, null, index + 1),
36
+ React.createElement(Body, null, formatAddress(affiliation))))))));
@@ -0,0 +1,41 @@
1
+ /*!
2
+ * © 2021 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, { useMemo } from 'react';
17
+ import styled from 'styled-components';
18
+ import { AffiliationsList } from './AffiliationsList';
19
+ import { AuthorsList } from './AuthorsList';
20
+ export const AuthorsContainer = ({ authorData, showEditButton, startEditing, selectAuthor, disableEditButton, }) => {
21
+ const authorAffiliations = useMemo(() => authorData.authors.filter((author) => author.role === 'author'), [authorData.authors]);
22
+ const isThereJointContributor = useMemo(() => authorData.authors.find((contributor) => contributor.isJointContributor), [authorData.authors]);
23
+ return (React.createElement(Container, { "data-cy": 'author-container' },
24
+ React.createElement(AuthorsList, { authors: authorAffiliations, authorAffiliations: authorData.authorAffiliations, startEditing: startEditing, showEditButton: showEditButton, selectAuthor: selectAuthor, disableEditButton: disableEditButton }),
25
+ React.createElement(AffiliationsList, { affiliations: authorData.affiliations }),
26
+ isThereJointContributor && (React.createElement(LegendWrapper, null,
27
+ React.createElement(Legend, null, "\u2020"),
28
+ "These authors contributed equally to this work."))));
29
+ };
30
+ const Container = styled.div `
31
+ margin-top: ${(props) => props.theme.grid.unit * 4}px;
32
+ `;
33
+ const LegendWrapper = styled.p `
34
+ margin: ${(props) => props.theme.grid.unit * 4}px 0 0 0;
35
+ `;
36
+ const Legend = styled.span `
37
+ display: inline-block;
38
+ font-size: 0.75em;
39
+ line-height: 1;
40
+ vertical-align: top;
41
+ `;
@@ -0,0 +1,69 @@
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, { css } from 'styled-components';
18
+ import { AuthorName } from '../AuthorName';
19
+ const AuthorNotes = styled.span `
20
+ display: inline-block;
21
+ font-size: 0.75em;
22
+ line-height: 1;
23
+ vertical-align: top;
24
+ `;
25
+ const LinkSharedStyles = css `
26
+ text-decoration: none;
27
+ color: inherit;
28
+ outline: none;
29
+
30
+ &:not(:disabled) {
31
+ &:hover,
32
+ &:focus {
33
+ &,
34
+ span {
35
+ color: ${(props) => props.theme.colors.text.tertiary};
36
+ }
37
+ }
38
+ }
39
+ `;
40
+ const AuthorAffiliation = styled.span `
41
+ ${LinkSharedStyles}
42
+ `;
43
+ const AuthorsContainer = styled.button `
44
+ display: inline-flex;
45
+ background: transparent;
46
+ border: 0;
47
+ font-size: 1rem;
48
+ ${LinkSharedStyles}
49
+
50
+ &:not(:disabled) {
51
+ &:hover {
52
+ text-decoration: underline;
53
+ cursor: pointer !important;
54
+ }
55
+ }
56
+ `;
57
+ export const Author = ({ author, affiliations, jointFirstAuthor, startEditing, selectAuthor, showEditButton, disableEditButton, }) => (React.createElement("span", { key: author._id },
58
+ showEditButton ? (React.createElement(AuthorsContainer, { disabled: disableEditButton, onClick: (e) => {
59
+ e.preventDefault();
60
+ startEditing && startEditing();
61
+ selectAuthor && selectAuthor(author);
62
+ } },
63
+ React.createElement(AuthorName, { name: author.bibliographicName, email: (author.isCorresponding && author.email) || undefined }))) : (React.createElement(AuthorName, { name: author.bibliographicName, email: (author.isCorresponding && author.email) || undefined })),
64
+ affiliations && (React.createElement(AuthorNotes, null, affiliations.map((affiliation, index) => (React.createElement(React.Fragment, { key: affiliation.data._id },
65
+ !!index && ',',
66
+ React.createElement(AuthorAffiliation, null, affiliation.ordinal)))))),
67
+ author.isCorresponding && (React.createElement(AuthorNotes, { title: 'Corresponding author' }, "*")),
68
+ jointFirstAuthor && (React.createElement(AuthorNotes, { title: 'Joint contributor' }, "\u2020"))));
69
+ export default Author;
@@ -0,0 +1,45 @@
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 { isJointFirstAuthor } from '../../lib/authors';
19
+ import { PrimaryButton } from '../Button';
20
+ import { Author } from './Author';
21
+ const AuthorsContainer = styled.div `
22
+ align-items: center;
23
+ display: flex;
24
+
25
+ @media (min-width: 768px) {
26
+ & ${PrimaryButton} {
27
+ display: ${(props) => (props.isEmpty ? 'initial' : 'none')};
28
+ }
29
+
30
+ &:hover ${PrimaryButton} {
31
+ display: initial;
32
+ }
33
+ }
34
+ `;
35
+ const AuthorsActions = styled.div `
36
+ align-items: center;
37
+ display: flex;
38
+ margin-left: ${(props) => props.theme.grid.unit * 2}px;
39
+ `;
40
+ export const AuthorsList = ({ authors, authorAffiliations, startEditing, showEditButton, disableEditButton, selectAuthor, }) => (React.createElement(AuthorsContainer, { isEmpty: !authors.length },
41
+ React.createElement("div", null, authors.map((author, index) => (React.createElement(React.Fragment, { key: author._id },
42
+ !!index && ', ',
43
+ React.createElement(Author, { author: author, jointFirstAuthor: isJointFirstAuthor(authors, index), affiliations: authorAffiliations.get(author._id), selectAuthor: selectAuthor, startEditing: startEditing, showEditButton: showEditButton, disableEditButton: disableEditButton }))))),
44
+ showEditButton && startEditing && (React.createElement(AuthorsActions, null,
45
+ React.createElement(PrimaryButton, { mini: true, onClick: startEditing, className: 'edit_authors_button', disabled: disableEditButton }, "Edit Authors")))));
@@ -0,0 +1,16 @@
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 * from './AuthorsList';
@@ -0,0 +1,55 @@
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 { Submenu, SubmenusContainer, Text } from './Submenu';
20
+ Modal.setAppElement('#root');
21
+ const MenusContainer = 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 Menus = ({ menus, innerRef, handleClick, }) => {
44
+ return (React.createElement(MenusContainer, { ref: innerRef }, menus.map((menu, index) => {
45
+ return (React.createElement(MenuContainer, { key: `menu-${index}`, isEnabled: menu.isEnabled },
46
+ React.createElement(MenuHeading, { onMouseDown: (e) => {
47
+ e.preventDefault();
48
+ handleClick([index]);
49
+ }, isOpen: menu.isOpen },
50
+ React.createElement(Text, null, menu.label)),
51
+ menu.isEnabled && menu.isOpen && menu.submenu && (React.createElement(SubmenusContainer, null, menu.submenu.map((submenu, sindex) => {
52
+ return (React.createElement(Submenu, { key: `${index}-${sindex}`, menu: submenu, handleClick: (i) => handleClick([index, sindex, ...i]) }));
53
+ })))));
54
+ })));
55
+ };
@@ -0,0 +1,57 @@
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
+ const isMac = /Mac/.test(window.navigator.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 macModifiers = {
27
+ Option: '⌥',
28
+ CommandOrControl: '⌘',
29
+ Shift: '⇧',
30
+ };
31
+ const pcModifiers = {
32
+ Option: 'Alt',
33
+ CommandOrControl: 'Ctrl',
34
+ Shift: 'Shift',
35
+ };
36
+ const modifiers = isMac ? macModifiers : pcModifiers;
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 parts = (shortcut) => {
44
+ const nodes = [];
45
+ for (const part of shortcut[system].split('+')) {
46
+ const modifier = modifiers[part];
47
+ if (modifier) {
48
+ nodes.push(modifier);
49
+ nodes.push(separator);
50
+ }
51
+ else {
52
+ nodes.push(React.createElement(Character, { key: part }, part));
53
+ }
54
+ }
55
+ return nodes;
56
+ };
57
+ export const Shortcut = ({ shortcut }) => (React.createElement(ShortcutContainer, null, parts(shortcut)));
@@ -0,0 +1,112 @@
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 { isMenuSeparator } from '../../lib/menus';
20
+ import { Shortcut } from './Shortcut';
21
+ export const Text = styled.div `
22
+ flex: 1 0 auto;
23
+ `;
24
+ const SubmenuContainer = styled.div `
25
+ position: relative;
26
+ `;
27
+ export const SubmenusContainer = styled.div `
28
+ background: #fff;
29
+ border: 1px solid #e2e2e2;
30
+ border-radius: 4px;
31
+ box-shadow: 0 4px 9px 0 rgba(84, 83, 83, 0.3);
32
+ color: #353535;
33
+ min-width: 150px;
34
+ max-height: 70vh;
35
+ overflow-y: auto;
36
+ padding: 4px 0;
37
+ white-space: nowrap;
38
+ width: auto;
39
+ z-index: 10;
40
+
41
+ position: absolute;
42
+
43
+ &[data-placement='bottom-start'] {
44
+ border-top-left-radius: 0;
45
+ border-top-right-radius: 0;
46
+ }
47
+
48
+ &[data-placement='right-start'] {
49
+ top: 8px;
50
+ }
51
+ `;
52
+ const NestedSubmenusContainer = styled(SubmenusContainer) `
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 activeContent = (menu) => (menu.isActive ? '✓' : '');
89
+ export const Submenu = ({ menu, handleClick }) => {
90
+ if (isMenuSeparator(menu)) {
91
+ return React.createElement(Separator, null);
92
+ }
93
+ if (!menu.submenu) {
94
+ return (React.createElement(Container, { isOpen: menu.isOpen, className: menu.isEnabled ? '' : 'disabled', onMouseDown: (e) => {
95
+ e.preventDefault();
96
+ handleClick([]);
97
+ } },
98
+ React.createElement(Active, null, activeContent(menu)),
99
+ React.createElement(Text, null, menu.label),
100
+ menu.shortcut && React.createElement(Shortcut, { shortcut: menu.shortcut })));
101
+ }
102
+ return (React.createElement(SubmenuContainer, null,
103
+ React.createElement(Container, { onMouseDown: (e) => {
104
+ e.preventDefault();
105
+ handleClick([]);
106
+ }, isOpen: menu.isOpen, className: menu.isEnabled ? '' : 'disabled' },
107
+ React.createElement(Active, null, activeContent(menu)),
108
+ React.createElement(Text, null, menu.label),
109
+ menu.submenu && React.createElement(Arrow, null),
110
+ menu.shortcut && React.createElement(Shortcut, { shortcut: menu.shortcut })),
111
+ 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]) })))))));
112
+ };
@@ -0,0 +1 @@
1
+ export * from './Menus';
@@ -0,0 +1,85 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { isMenuSeparator, } from '../lib/menus';
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
+ const isPart = (pointer, position) => {
14
+ const limit = position.length < 3 ? position.length : 3;
15
+ for (let i = 0; i < limit; i++) {
16
+ if (position[i] !== pointer[i]) {
17
+ return false;
18
+ }
19
+ }
20
+ return true;
21
+ };
22
+ const getSubmenuState = (specs, pointer, position) => {
23
+ return specs.map((spec, index) => {
24
+ if (isMenuSeparator(spec)) {
25
+ return spec;
26
+ }
27
+ const current = [...position, index];
28
+ return Object.assign(Object.assign({}, spec), { submenu: spec.submenu && getSubmenuState(spec.submenu, pointer, current), isOpen: isPart(pointer, current) });
29
+ });
30
+ };
31
+ const getMenuState = (specs, pointer) => {
32
+ return specs.map((spec, index) => {
33
+ const position = [index];
34
+ return Object.assign(Object.assign({}, spec), { submenu: spec.submenu && getSubmenuState(spec.submenu, pointer, position), isOpen: isPart(pointer, position) });
35
+ });
36
+ };
37
+ const getMenuAt = (state, position) => {
38
+ const [head, ...tail] = position.filter((i) => i !== -1);
39
+ const menu = state[head];
40
+ if (isMenuSeparator(menu)) {
41
+ return;
42
+ }
43
+ if (!tail.length) {
44
+ return menu;
45
+ }
46
+ else if (menu.submenu) {
47
+ return getMenuAt(menu.submenu, tail);
48
+ }
49
+ };
50
+ export const useMenus = (menus) => {
51
+ const [pointer, setPointer] = useState(initialPointer);
52
+ const state = getMenuState(menus, pointer);
53
+ const handleClick = useCallback((indices) => {
54
+ const menu = getMenuAt(state, indices);
55
+ if (!menu || !menu.isEnabled) {
56
+ return;
57
+ }
58
+ if (menu.run) {
59
+ menu.run();
60
+ setPointer([-1, -1, -1]);
61
+ }
62
+ else if (menu.submenu) {
63
+ const depth = indices.length - 1;
64
+ const index = indices[depth];
65
+ setPointer(transformPointer(depth, index));
66
+ }
67
+ }, [state]);
68
+ const ref = useRef(null);
69
+ useEffect(() => {
70
+ const handleClickOutside = (event) => {
71
+ if (ref.current && !ref.current.contains(event.target)) {
72
+ setPointer([-1, -1, -1]);
73
+ }
74
+ };
75
+ document.addEventListener('click', handleClickOutside);
76
+ return () => {
77
+ document.removeEventListener('click', handleClickOutside);
78
+ };
79
+ }, []);
80
+ return {
81
+ menus: state,
82
+ handleClick,
83
+ ref,
84
+ };
85
+ };
package/dist/es/index.js CHANGED
@@ -14,9 +14,12 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export * from './components/AffiliationsEditor';
17
+ export * from './components/AffiliationsList';
17
18
  export * from './components/AuthorForm';
18
19
  export * from './components/AuthorName';
20
+ export * from './components/AuthorsList';
19
21
  export * from './components/AuthorsDND';
22
+ export * from './components/AuthorsContainer';
20
23
  export * from './components/AlertMessage';
21
24
  export * from './components/Button';
22
25
  export * from './components/ColorField';
@@ -50,12 +53,15 @@ export * from './components/Text';
50
53
  export * from './components/ManuscriptNoteList';
51
54
  export * from './components/Comments';
52
55
  export * from './components/RelativeDate';
56
+ export * from './components/Menus';
53
57
  export * from './hooks/use-dropdown';
54
58
  export * from './hooks/use-files';
59
+ export * from './hooks/use-menus';
55
60
  export { useDeepCompareMemo, useDeepCompareCallback, } from './hooks/use-deep-compare';
56
61
  export * from './lib/authors';
57
62
  export * from './lib/capabilities';
58
63
  export * from './lib/files';
59
64
  export * from './lib/comments';
65
+ export * from './lib/menus';
60
66
  export { default as errorsDecoder } from './lib/errors-decoder';
61
67
  export * from './types';
@@ -0,0 +1,18 @@
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
+ export const isMenuSeparator = (menu) => {
17
+ return (menu === null || menu === void 0 ? void 0 : menu.role) === 'separator';
18
+ };
@@ -0,0 +1,22 @@
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 { AffiliationMap } from '../types';
18
+ interface Props {
19
+ affiliations: AffiliationMap;
20
+ }
21
+ export declare const AffiliationsList: React.FunctionComponent<Props>;
22
+ export {};