@manuscripts/style-guide 3.3.3 → 3.3.5
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/components/ToggleHeader.js +1 -2
- package/dist/cjs/index.js +0 -1
- package/dist/es/components/ToggleHeader.js +1 -2
- package/dist/es/index.js +0 -1
- package/dist/types/index.d.ts +0 -1
- package/package.json +1 -1
- package/dist/cjs/lib/capabilities.js +0 -77
- package/dist/es/lib/capabilities.js +0 -66
- package/dist/types/lib/capabilities.d.ts +0 -41
package/dist/cjs/index.js
CHANGED
|
@@ -75,6 +75,5 @@ __exportStar(require("./hooks/use-scroll-detection"), exports);
|
|
|
75
75
|
var use_deep_compare_1 = require("./hooks/use-deep-compare");
|
|
76
76
|
Object.defineProperty(exports, "useDeepCompareMemo", { enumerable: true, get: function () { return use_deep_compare_1.useDeepCompareMemo; } });
|
|
77
77
|
Object.defineProperty(exports, "useDeepCompareCallback", { enumerable: true, get: function () { return use_deep_compare_1.useDeepCompareCallback; } });
|
|
78
|
-
__exportStar(require("./lib/capabilities"), exports);
|
|
79
78
|
__exportStar(require("./lib/files"), exports);
|
|
80
79
|
__exportStar(require("./lib/menus"), exports);
|
package/dist/es/index.js
CHANGED
|
@@ -54,6 +54,5 @@ export * from './hooks/use-dropdown';
|
|
|
54
54
|
export * from './hooks/use-menus';
|
|
55
55
|
export * from './hooks/use-scroll-detection';
|
|
56
56
|
export { useDeepCompareMemo, useDeepCompareCallback, } from './hooks/use-deep-compare';
|
|
57
|
-
export * from './lib/capabilities';
|
|
58
57
|
export * from './lib/files';
|
|
59
58
|
export * from './lib/menus';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -55,6 +55,5 @@ export * from './hooks/use-dropdown';
|
|
|
55
55
|
export * from './hooks/use-menus';
|
|
56
56
|
export * from './hooks/use-scroll-detection';
|
|
57
57
|
export { useDeepCompareMemo, useDeepCompareCallback, } from './hooks/use-deep-compare';
|
|
58
|
-
export * from './lib/capabilities';
|
|
59
58
|
export * from './lib/files';
|
|
60
59
|
export * from './lib/menus';
|
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": "3.3.
|
|
4
|
+
"version": "3.3.5",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-style-guide",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CapabilitiesProvider = exports.useCalcPermission = exports.usePermissions = exports.getAllPermitted = exports.getCapabilities = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
var Actions;
|
|
9
|
-
(function (Actions) {
|
|
10
|
-
Actions["updateAttachment"] = "update-attachment";
|
|
11
|
-
Actions["updateDueDate"] = "update-due-date";
|
|
12
|
-
Actions["addNote"] = "add-note";
|
|
13
|
-
Actions["setMainManuscript"] = "set-main-manuscript";
|
|
14
|
-
Actions["editWithoutTracking"] = "edit-without-tracking";
|
|
15
|
-
})(Actions || (Actions = {}));
|
|
16
|
-
const getCapabilities = (project, profile, role, actions, isViewingMode) => {
|
|
17
|
-
const userID = profile?.userID;
|
|
18
|
-
const isMemberOf = (group) => group?.includes(userID ?? '') ?? false;
|
|
19
|
-
const isOwner = isMemberOf(project?.owners);
|
|
20
|
-
const isEditor = isMemberOf(project?.editors);
|
|
21
|
-
const isWriter = isMemberOf(project?.writers);
|
|
22
|
-
const isAnnotator = isMemberOf(project?.annotators);
|
|
23
|
-
const isViewer = isMemberOf(project?.viewers) || isViewingMode;
|
|
24
|
-
const allowed = (action) => !!actions?.includes(action);
|
|
25
|
-
const canEditWithoutTracking = allowed(Actions.editWithoutTracking);
|
|
26
|
-
const isPrivileged = isOwner || isEditor || isWriter;
|
|
27
|
-
const canEditFiles = (isPrivileged || isAnnotator) && !isViewingMode;
|
|
28
|
-
const canUpdateAttachments = canEditFiles && allowed(Actions.updateAttachment);
|
|
29
|
-
return {
|
|
30
|
-
handleSuggestion: isPrivileged,
|
|
31
|
-
editWithoutTracking: canEditWithoutTracking,
|
|
32
|
-
rejectOwnSuggestion: !isViewer,
|
|
33
|
-
handleOwnComments: !isViewer,
|
|
34
|
-
handleOthersComments: isOwner,
|
|
35
|
-
resolveOwnComment: !isViewer,
|
|
36
|
-
resolveOthersComment: isOwner || isEditor,
|
|
37
|
-
createComment: !isViewer,
|
|
38
|
-
downloadFiles: true,
|
|
39
|
-
changeDesignation: canUpdateAttachments,
|
|
40
|
-
moveFile: canEditFiles,
|
|
41
|
-
replaceFile: canUpdateAttachments,
|
|
42
|
-
uploadFile: canUpdateAttachments,
|
|
43
|
-
detachFile: canEditFiles,
|
|
44
|
-
setMainManuscript: allowed(Actions.setMainManuscript),
|
|
45
|
-
editArticle: !isViewer,
|
|
46
|
-
formatArticle: !isViewer,
|
|
47
|
-
editMetadata: !isViewer,
|
|
48
|
-
editCitationsAndRefs: !isViewer,
|
|
49
|
-
seeEditorToolbar: !isViewer,
|
|
50
|
-
seeReferencesButtons: !isViewer,
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
exports.getCapabilities = getCapabilities;
|
|
54
|
-
const getAllPermitted = () => {
|
|
55
|
-
const capabilities = (0, exports.getCapabilities)();
|
|
56
|
-
const allAllowed = Object.keys(capabilities).reduce((caps, item) => {
|
|
57
|
-
caps[item] = true;
|
|
58
|
-
return caps;
|
|
59
|
-
}, {});
|
|
60
|
-
return allAllowed;
|
|
61
|
-
};
|
|
62
|
-
exports.getAllPermitted = getAllPermitted;
|
|
63
|
-
const CapabilitiesContext = react_1.default.createContext((0, exports.getCapabilities)());
|
|
64
|
-
CapabilitiesContext.displayName = 'CapabilitiesContext';
|
|
65
|
-
const usePermissions = () => {
|
|
66
|
-
return react_1.default.useContext(CapabilitiesContext);
|
|
67
|
-
};
|
|
68
|
-
exports.usePermissions = usePermissions;
|
|
69
|
-
const useCalcPermission = ({ project, profile, role, permittedActions, isViewingMode, }) => {
|
|
70
|
-
return (0, exports.getCapabilities)(project, profile, role, permittedActions, isViewingMode);
|
|
71
|
-
};
|
|
72
|
-
exports.useCalcPermission = useCalcPermission;
|
|
73
|
-
const CapabilitiesProvider = (props) => {
|
|
74
|
-
const { can } = props;
|
|
75
|
-
return (react_1.default.createElement(CapabilitiesContext.Provider, { value: can }, props?.children));
|
|
76
|
-
};
|
|
77
|
-
exports.CapabilitiesProvider = CapabilitiesProvider;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
var Actions;
|
|
3
|
-
(function (Actions) {
|
|
4
|
-
Actions["updateAttachment"] = "update-attachment";
|
|
5
|
-
Actions["updateDueDate"] = "update-due-date";
|
|
6
|
-
Actions["addNote"] = "add-note";
|
|
7
|
-
Actions["setMainManuscript"] = "set-main-manuscript";
|
|
8
|
-
Actions["editWithoutTracking"] = "edit-without-tracking";
|
|
9
|
-
})(Actions || (Actions = {}));
|
|
10
|
-
export const getCapabilities = (project, profile, role, actions, isViewingMode) => {
|
|
11
|
-
const userID = profile?.userID;
|
|
12
|
-
const isMemberOf = (group) => group?.includes(userID ?? '') ?? false;
|
|
13
|
-
const isOwner = isMemberOf(project?.owners);
|
|
14
|
-
const isEditor = isMemberOf(project?.editors);
|
|
15
|
-
const isWriter = isMemberOf(project?.writers);
|
|
16
|
-
const isAnnotator = isMemberOf(project?.annotators);
|
|
17
|
-
const isViewer = isMemberOf(project?.viewers) || isViewingMode;
|
|
18
|
-
const allowed = (action) => !!actions?.includes(action);
|
|
19
|
-
const canEditWithoutTracking = allowed(Actions.editWithoutTracking);
|
|
20
|
-
const isPrivileged = isOwner || isEditor || isWriter;
|
|
21
|
-
const canEditFiles = (isPrivileged || isAnnotator) && !isViewingMode;
|
|
22
|
-
const canUpdateAttachments = canEditFiles && allowed(Actions.updateAttachment);
|
|
23
|
-
return {
|
|
24
|
-
handleSuggestion: isPrivileged,
|
|
25
|
-
editWithoutTracking: canEditWithoutTracking,
|
|
26
|
-
rejectOwnSuggestion: !isViewer,
|
|
27
|
-
handleOwnComments: !isViewer,
|
|
28
|
-
handleOthersComments: isOwner,
|
|
29
|
-
resolveOwnComment: !isViewer,
|
|
30
|
-
resolveOthersComment: isOwner || isEditor,
|
|
31
|
-
createComment: !isViewer,
|
|
32
|
-
downloadFiles: true,
|
|
33
|
-
changeDesignation: canUpdateAttachments,
|
|
34
|
-
moveFile: canEditFiles,
|
|
35
|
-
replaceFile: canUpdateAttachments,
|
|
36
|
-
uploadFile: canUpdateAttachments,
|
|
37
|
-
detachFile: canEditFiles,
|
|
38
|
-
setMainManuscript: allowed(Actions.setMainManuscript),
|
|
39
|
-
editArticle: !isViewer,
|
|
40
|
-
formatArticle: !isViewer,
|
|
41
|
-
editMetadata: !isViewer,
|
|
42
|
-
editCitationsAndRefs: !isViewer,
|
|
43
|
-
seeEditorToolbar: !isViewer,
|
|
44
|
-
seeReferencesButtons: !isViewer,
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
export const getAllPermitted = () => {
|
|
48
|
-
const capabilities = getCapabilities();
|
|
49
|
-
const allAllowed = Object.keys(capabilities).reduce((caps, item) => {
|
|
50
|
-
caps[item] = true;
|
|
51
|
-
return caps;
|
|
52
|
-
}, {});
|
|
53
|
-
return allAllowed;
|
|
54
|
-
};
|
|
55
|
-
const CapabilitiesContext = React.createContext(getCapabilities());
|
|
56
|
-
CapabilitiesContext.displayName = 'CapabilitiesContext';
|
|
57
|
-
export const usePermissions = () => {
|
|
58
|
-
return React.useContext(CapabilitiesContext);
|
|
59
|
-
};
|
|
60
|
-
export const useCalcPermission = ({ project, profile, role, permittedActions, isViewingMode, }) => {
|
|
61
|
-
return getCapabilities(project, profile, role, permittedActions, isViewingMode);
|
|
62
|
-
};
|
|
63
|
-
export const CapabilitiesProvider = (props) => {
|
|
64
|
-
const { can } = props;
|
|
65
|
-
return (React.createElement(CapabilitiesContext.Provider, { value: can }, props?.children));
|
|
66
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Project, UserProfile } from '@manuscripts/json-schema';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
export type Capabilities = {
|
|
4
|
-
handleSuggestion: boolean;
|
|
5
|
-
editWithoutTracking: boolean;
|
|
6
|
-
rejectOwnSuggestion: boolean;
|
|
7
|
-
handleOwnComments: boolean;
|
|
8
|
-
resolveOwnComment: boolean;
|
|
9
|
-
handleOthersComments: boolean;
|
|
10
|
-
resolveOthersComment: boolean;
|
|
11
|
-
createComment: boolean;
|
|
12
|
-
downloadFiles: boolean;
|
|
13
|
-
changeDesignation: boolean;
|
|
14
|
-
moveFile: boolean;
|
|
15
|
-
replaceFile: boolean;
|
|
16
|
-
uploadFile: boolean;
|
|
17
|
-
detachFile: boolean;
|
|
18
|
-
setMainManuscript: boolean;
|
|
19
|
-
formatArticle: boolean;
|
|
20
|
-
editArticle: boolean;
|
|
21
|
-
editMetadata: boolean;
|
|
22
|
-
editCitationsAndRefs: boolean;
|
|
23
|
-
seeEditorToolbar: boolean;
|
|
24
|
-
seeReferencesButtons: boolean;
|
|
25
|
-
};
|
|
26
|
-
export interface ProviderProps {
|
|
27
|
-
project?: Project;
|
|
28
|
-
profile?: UserProfile;
|
|
29
|
-
role?: string;
|
|
30
|
-
permittedActions?: string[];
|
|
31
|
-
children?: React.ReactNode;
|
|
32
|
-
isViewingMode?: boolean;
|
|
33
|
-
}
|
|
34
|
-
export declare const getCapabilities: (project?: Project, profile?: UserProfile, role?: ProviderProps["role"], actions?: string[], isViewingMode?: boolean) => Capabilities;
|
|
35
|
-
export declare const getAllPermitted: () => Capabilities;
|
|
36
|
-
export declare const usePermissions: () => Capabilities;
|
|
37
|
-
export declare const useCalcPermission: ({ project, profile, role, permittedActions, isViewingMode, }: ProviderProps) => Capabilities;
|
|
38
|
-
export declare const CapabilitiesProvider: React.FC<{
|
|
39
|
-
can: Capabilities;
|
|
40
|
-
children: React.ReactNode;
|
|
41
|
-
}>;
|