@zextras/carbonio-ui-preview 0.1.1 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/lib/index.d.ts +6 -0
- package/lib/index.js +28 -0
- package/lib/index.js.map +1 -0
- package/lib/preview/ContainerWithGap.d.ts +1 -0
- package/lib/preview/ContainerWithGap.js +23 -0
- package/lib/preview/ContainerWithGap.js.map +1 -0
- package/lib/preview/FocusWithin.d.ts +7 -0
- package/lib/preview/FocusWithin.js +87 -0
- package/lib/preview/FocusWithin.js.map +1 -0
- package/lib/preview/Header.d.ts +29 -0
- package/lib/preview/Header.js +44 -0
- package/lib/preview/Header.js.map +1 -0
- package/lib/preview/ImagePreview.d.ts +37 -0
- package/lib/preview/ImagePreview.js +99 -0
- package/lib/preview/ImagePreview.js.map +1 -0
- package/lib/preview/PdfPreview.d.ts +58 -0
- package/lib/preview/PdfPreview.js +204 -0
- package/lib/preview/PdfPreview.js.map +1 -0
- package/lib/preview/PreviewCriteriaAlternativeContent.d.ts +12 -0
- package/lib/preview/PreviewCriteriaAlternativeContent.js +73 -0
- package/lib/preview/PreviewCriteriaAlternativeContent.js.map +1 -0
- package/lib/preview/PreviewManager.d.ts +12 -0
- package/lib/preview/PreviewManager.js +102 -0
- package/lib/preview/PreviewManager.js.map +1 -0
- package/lib/preview/PreviewWrapper.d.ts +9 -0
- package/lib/preview/PreviewWrapper.js +42 -0
- package/lib/preview/PreviewWrapper.js.map +1 -0
- package/lib/utils.d.ts +3 -0
- package/{src/utils.ts → lib/utils.js} +3 -2
- package/lib/utils.js.map +1 -0
- package/lib-esm/index.d.ts +6 -0
- package/{src/index.ts → lib-esm/index.js} +1 -1
- package/lib-esm/index.js.map +1 -0
- package/lib-esm/preview/ContainerWithGap.d.ts +1 -0
- package/lib-esm/preview/ContainerWithGap.js +17 -0
- package/lib-esm/preview/ContainerWithGap.js.map +1 -0
- package/lib-esm/preview/FocusWithin.d.ts +7 -0
- package/lib-esm/preview/FocusWithin.js +59 -0
- package/lib-esm/preview/FocusWithin.js.map +1 -0
- package/lib-esm/preview/Header.d.ts +29 -0
- package/lib-esm/preview/Header.js +39 -0
- package/lib-esm/preview/Header.js.map +1 -0
- package/lib-esm/preview/ImagePreview.d.ts +37 -0
- package/lib-esm/preview/ImagePreview.js +70 -0
- package/lib-esm/preview/ImagePreview.js.map +1 -0
- package/lib-esm/preview/PdfPreview.d.ts +58 -0
- package/lib-esm/preview/PdfPreview.js +175 -0
- package/lib-esm/preview/PdfPreview.js.map +1 -0
- package/lib-esm/preview/PreviewCriteriaAlternativeContent.d.ts +12 -0
- package/lib-esm/preview/PreviewCriteriaAlternativeContent.js +43 -0
- package/lib-esm/preview/PreviewCriteriaAlternativeContent.js.map +1 -0
- package/lib-esm/preview/PreviewManager.d.ts +12 -0
- package/lib-esm/preview/PreviewManager.js +75 -0
- package/lib-esm/preview/PreviewManager.js.map +1 -0
- package/lib-esm/preview/PreviewWrapper.d.ts +9 -0
- package/lib-esm/preview/PreviewWrapper.js +36 -0
- package/lib-esm/preview/PreviewWrapper.js.map +1 -0
- package/lib-esm/utils.d.ts +3 -0
- package/{src/types/carbonio-design-system.d.ts → lib-esm/utils.js} +2 -2
- package/lib-esm/utils.js.map +1 -0
- package/package.json +22 -6
- package/src/preview/ContainerWithGap.tsx +0 -11
- package/src/preview/FocusWithin.tsx +0 -76
- package/src/preview/Header.tsx +0 -122
- package/src/preview/ImagePreview.tsx +0 -194
- package/src/preview/PdfPreview.tsx +0 -398
- package/src/preview/PreviewCriteriaAlternativeContent.tsx +0 -94
- package/src/preview/PreviewManager.tsx +0 -75
- package/src/preview/PreviewWrapper.tsx +0 -20
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-FileCopyrightText: 2021 Zextras <https://www.zextras.com>
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-only
|
|
5
|
+
*/
|
|
6
|
+
var __assign = (this && this.__assign) || function () {
|
|
7
|
+
__assign = Object.assign || function(t) {
|
|
8
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
9
|
+
s = arguments[i];
|
|
10
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11
|
+
t[p] = s[p];
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
};
|
|
15
|
+
return __assign.apply(this, arguments);
|
|
16
|
+
};
|
|
17
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
18
|
+
var t = {};
|
|
19
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
20
|
+
t[p] = s[p];
|
|
21
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
22
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
23
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
24
|
+
t[p[i]] = s[p[i]];
|
|
25
|
+
}
|
|
26
|
+
return t;
|
|
27
|
+
};
|
|
28
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
29
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
30
|
+
if (ar || !(i in from)) {
|
|
31
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
32
|
+
ar[i] = from[i];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
|
+
};
|
|
37
|
+
import React, { useCallback, createContext, useReducer } from 'react';
|
|
38
|
+
import { PreviewWrapper } from './PreviewWrapper';
|
|
39
|
+
var PreviewsManagerContext = createContext({
|
|
40
|
+
createPreview: function () { return undefined; }
|
|
41
|
+
});
|
|
42
|
+
var PreviewManager = function (_a) {
|
|
43
|
+
var children = _a.children;
|
|
44
|
+
var _b = useReducer(function (state, action) {
|
|
45
|
+
switch (action.type) {
|
|
46
|
+
case 'set': {
|
|
47
|
+
return __spreadArray(__spreadArray([], state, true), [action.value], false);
|
|
48
|
+
}
|
|
49
|
+
case 'empty': {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
default: {
|
|
53
|
+
return state;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, []), previews = _b[0], dispatchPreviews = _b[1];
|
|
57
|
+
var createPreview = useCallback(function (_a) {
|
|
58
|
+
var onClose = _a.onClose, props = __rest(_a, ["onClose"]);
|
|
59
|
+
var closePreview = function (ev) {
|
|
60
|
+
if (onClose)
|
|
61
|
+
onClose(ev);
|
|
62
|
+
dispatchPreviews({ type: 'empty' });
|
|
63
|
+
};
|
|
64
|
+
var preview = React.createElement(PreviewWrapper, __assign({ key: props.src }, props, { show: true, onClose: closePreview }));
|
|
65
|
+
dispatchPreviews({
|
|
66
|
+
type: 'set',
|
|
67
|
+
value: preview
|
|
68
|
+
});
|
|
69
|
+
}, [dispatchPreviews]);
|
|
70
|
+
return (React.createElement(React.Fragment, null,
|
|
71
|
+
React.createElement(PreviewsManagerContext.Provider, { value: { createPreview: createPreview } }, children),
|
|
72
|
+
previews));
|
|
73
|
+
};
|
|
74
|
+
export { PreviewsManagerContext, PreviewManager };
|
|
75
|
+
//# sourceMappingURL=PreviewManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PreviewManager.js","sourceRoot":"","sources":["../../src/preview/PreviewManager.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAItE,OAAO,EAAE,cAAc,EAAuB,MAAM,kBAAkB,CAAC;AAUvE,IAAM,sBAAsB,GAAG,aAAa,CAEzC;IACF,aAAa,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;CAC9B,CAAC,CAAC;AAEH,IAAM,cAAc,GAAa,UAAC,EAAY;QAAV,QAAQ,cAAA;IACrC,IAAA,KAA+B,UAAU,CAC9C,UACC,KAAgC,EAChC,MAAsE;QAEtE,QAAQ,MAAM,CAAC,IAAI,EAAE;YACpB,KAAK,KAAK,CAAC,CAAC;gBACX,uCAAW,KAAK,UAAE,MAAM,CAAC,KAAK,UAAE;aAChC;YACD,KAAK,OAAO,CAAC,CAAC;gBACb,OAAO,EAAE,CAAC;aACV;YACD,OAAO,CAAC,CAAC;gBACR,OAAO,KAAK,CAAC;aACb;SACD;IACF,CAAC,EACD,EAAE,CACF,EAlBM,QAAQ,QAAA,EAAE,gBAAgB,QAkBhC,CAAC;IAEF,IAAM,aAAa,GAAG,WAAW,CAChC,UAAC,EAAqB;QAAnB,IAAA,OAAO,aAAA,EAAK,KAAK,cAAnB,WAAqB,CAAF;QACnB,IAAM,YAAY,GAAmC,UAAC,EAAE;YACvD,IAAI,OAAO;gBAAE,OAAO,CAAC,EAAE,CAAC,CAAC;YACzB,gBAAgB,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;QACrC,CAAC,CAAC;QAEF,IAAM,OAAO,GAAG,oBAAC,cAAc,aAAC,GAAG,EAAE,KAAK,CAAC,GAAG,IAAM,KAAK,IAAE,IAAI,QAAC,OAAO,EAAE,YAAY,IAAI,CAAC;QAE1F,gBAAgB,CAAC;YAChB,IAAI,EAAE,KAAK;YACX,KAAK,EAAE,OAAO;SACd,CAAC,CAAC;IACJ,CAAC,EACD,CAAC,gBAAgB,CAAC,CAClB,CAAC;IAEF,OAAO,CACN;QACC,oBAAC,sBAAsB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,aAAa,eAAA,EAAE,IACvD,QAAQ,CACwB;QACjC,QAAQ,CACP,CACH,CAAC;AACH,CAAC,CAAC;AAEF,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ImagePreviewProps } from './ImagePreview';
|
|
3
|
+
import { PdfPreviewProps } from './PdfPreview';
|
|
4
|
+
declare type PreviewsProps = ImagePreviewProps | PdfPreviewProps;
|
|
5
|
+
declare type PreviewWrapperProps = PreviewsProps & {
|
|
6
|
+
previewType: 'pdf' | 'image';
|
|
7
|
+
};
|
|
8
|
+
declare const PreviewWrapper: React.VFC<PreviewWrapperProps>;
|
|
9
|
+
export { PreviewWrapper, PreviewWrapperProps };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
/*
|
|
24
|
+
* SPDX-FileCopyrightText: 2022 Zextras <https://www.zextras.com>
|
|
25
|
+
*
|
|
26
|
+
* SPDX-License-Identifier: AGPL-3.0-only
|
|
27
|
+
*/
|
|
28
|
+
import React from 'react';
|
|
29
|
+
import { ImagePreview } from './ImagePreview';
|
|
30
|
+
import { PdfPreview } from './PdfPreview';
|
|
31
|
+
var PreviewWrapper = function (_a) {
|
|
32
|
+
var previewType = _a.previewType, props = __rest(_a, ["previewType"]);
|
|
33
|
+
return previewType === 'pdf' ? React.createElement(PdfPreview, __assign({}, props)) : React.createElement(ImagePreview, __assign({}, props));
|
|
34
|
+
};
|
|
35
|
+
export { PreviewWrapper };
|
|
36
|
+
//# sourceMappingURL=PreviewWrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PreviewWrapper.js","sourceRoot":"","sources":["../../src/preview/PreviewWrapper.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,YAAY,EAAqB,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,UAAU,EAAmB,MAAM,cAAc,CAAC;AAQ3D,IAAM,cAAc,GAAmC,UAAC,EAAyB;IAAvB,IAAA,WAAW,iBAAA,EAAK,KAAK,cAAvB,eAAyB,CAAF;IAC9E,OAAA,WAAW,KAAK,KAAK,CAAC,CAAC,CAAC,oBAAC,UAAU,eAAK,KAAK,EAAI,CAAC,CAAC,CAAC,oBAAC,YAAY,eAAK,KAAK,EAAI,CAAA;CAAA,CAAC;AAEjF,OAAO,EAAE,cAAc,EAAuB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zextras/carbonio-ui-preview",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Preview utility for Zextras Carbonio",
|
|
5
|
-
"main": "
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "Preview ui utility for Zextras Carbonio",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"module": "lib-esm/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
6
8
|
"files": [
|
|
7
|
-
"
|
|
9
|
+
"/lib",
|
|
10
|
+
"/lib-esm"
|
|
8
11
|
],
|
|
9
12
|
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"build-esm": "tsc -m es6 --outDir lib-esm",
|
|
15
|
+
"clean": "rm -rf lib",
|
|
16
|
+
"build-all": "npm run clean && npm run build && npm run build-esm",
|
|
10
17
|
"_postinstall": "is-ci || husky install",
|
|
11
|
-
"prepublishOnly": "pinst --disable",
|
|
18
|
+
"prepublishOnly": "pinst --disable && npm run build-all",
|
|
12
19
|
"postpublish": "pinst --enable",
|
|
13
20
|
"type-check": "tsc --noEmit",
|
|
14
21
|
"type-check:watch": "npm run type-check -- --watch",
|
|
@@ -19,6 +26,12 @@
|
|
|
19
26
|
"author": "Zextras SF Team <https://www.zextras.com/carbonio/>",
|
|
20
27
|
"license": "AGPL-3.0-only",
|
|
21
28
|
"devDependencies": {
|
|
29
|
+
"@babel/core": "7.16.0",
|
|
30
|
+
"@babel/plugin-proposal-class-properties": "7.16.0",
|
|
31
|
+
"@babel/plugin-transform-runtime": "7.16.4",
|
|
32
|
+
"@babel/preset-env": "7.16.4",
|
|
33
|
+
"@babel/preset-react": "7.16.0",
|
|
34
|
+
"@babel/preset-typescript": "7.16.0",
|
|
22
35
|
"@commitlint/cli": "14.1.0",
|
|
23
36
|
"@commitlint/config-conventional": "14.1.0",
|
|
24
37
|
"@types/lodash": "^4.14.181",
|
|
@@ -27,6 +40,9 @@
|
|
|
27
40
|
"@types/react-pdf": "^5.0.9",
|
|
28
41
|
"@types/styled-components": "^5.1.15",
|
|
29
42
|
"@zextras/carbonio-ui-configs": "^0.1.11",
|
|
43
|
+
"babel-jest": "27.3.1",
|
|
44
|
+
"babel-plugin-i18next-extract": "0.8.3",
|
|
45
|
+
"babel-plugin-styled-components": "2.0.1",
|
|
30
46
|
"eslint-plugin-notice": "^0.9.10",
|
|
31
47
|
"husky": "^5.2.0",
|
|
32
48
|
"is-ci": "3.0.1",
|
|
@@ -37,7 +53,7 @@
|
|
|
37
53
|
"react-pdf": "^5.7.1"
|
|
38
54
|
},
|
|
39
55
|
"peerDependencies": {
|
|
40
|
-
"@zextras/carbonio-design-system": "^0.
|
|
56
|
+
"@zextras/carbonio-design-system": "^0.3.0",
|
|
41
57
|
"lodash": "^4.17.21",
|
|
42
58
|
"react": "^17.0.2",
|
|
43
59
|
"react-dom": "^17.0.2",
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* SPDX-FileCopyrightText: 2022 Zextras <https://www.zextras.com>
|
|
3
|
-
*
|
|
4
|
-
* SPDX-License-Identifier: AGPL-3.0-only
|
|
5
|
-
*/
|
|
6
|
-
import { Container } from '@zextras/carbonio-design-system';
|
|
7
|
-
import styled from 'styled-components';
|
|
8
|
-
|
|
9
|
-
export const ContainerWithGap = styled(Container)`
|
|
10
|
-
gap: ${({ gap }): string => gap};
|
|
11
|
-
`;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/* eslint-disable jsx-a11y/no-noninteractive-tabindex */
|
|
2
|
-
/*
|
|
3
|
-
* SPDX-FileCopyrightText: 2022 Zextras <https://www.zextras.com>
|
|
4
|
-
*
|
|
5
|
-
* SPDX-License-Identifier: AGPL-3.0-only
|
|
6
|
-
*/
|
|
7
|
-
import React, { useCallback, useEffect, useRef } from 'react';
|
|
8
|
-
|
|
9
|
-
import last from 'lodash/last';
|
|
10
|
-
import styled from 'styled-components';
|
|
11
|
-
|
|
12
|
-
const FocusContainer = styled.span`
|
|
13
|
-
outline: none;
|
|
14
|
-
& > * {
|
|
15
|
-
outline: none;
|
|
16
|
-
}
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
|
-
interface FocusContainerProps {
|
|
20
|
-
returnFocus?: boolean;
|
|
21
|
-
children: React.ReactChild | React.ReactChildren;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const FocusWithin = ({ children, returnFocus = true }: FocusContainerProps): JSX.Element => {
|
|
25
|
-
const contentRef = useRef<HTMLDivElement | null>(null);
|
|
26
|
-
const startSentinelRef = useRef<HTMLDivElement | null>(null);
|
|
27
|
-
const endSentinelRef = useRef<HTMLDivElement | null>(null);
|
|
28
|
-
|
|
29
|
-
const onStartSentinelFocus = useCallback(() => {
|
|
30
|
-
if (contentRef.current) {
|
|
31
|
-
const node = last(contentRef.current.querySelectorAll<HTMLElement>('[tabindex]'));
|
|
32
|
-
node && node.focus();
|
|
33
|
-
}
|
|
34
|
-
}, []);
|
|
35
|
-
|
|
36
|
-
const onEndSentinelFocus = useCallback(() => {
|
|
37
|
-
if (contentRef.current) {
|
|
38
|
-
const node = contentRef.current.querySelector<HTMLElement>('[tabindex]');
|
|
39
|
-
node && node.focus();
|
|
40
|
-
}
|
|
41
|
-
}, []);
|
|
42
|
-
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
const documentElement = window.top?.document || document;
|
|
45
|
-
const focusedElement = documentElement.activeElement as HTMLElement;
|
|
46
|
-
|
|
47
|
-
contentRef.current && contentRef.current.focus();
|
|
48
|
-
startSentinelRef.current &&
|
|
49
|
-
startSentinelRef.current.addEventListener('focus', onStartSentinelFocus);
|
|
50
|
-
endSentinelRef.current && endSentinelRef.current.addEventListener('focus', onEndSentinelFocus);
|
|
51
|
-
const startSentinelRefSave = startSentinelRef.current;
|
|
52
|
-
const endSentinelRefSave = endSentinelRef.current;
|
|
53
|
-
|
|
54
|
-
return (): void => {
|
|
55
|
-
startSentinelRefSave &&
|
|
56
|
-
startSentinelRefSave.removeEventListener('focus', onStartSentinelFocus);
|
|
57
|
-
endSentinelRefSave && endSentinelRefSave.removeEventListener('focus', onEndSentinelFocus);
|
|
58
|
-
// return focus to previous initial element
|
|
59
|
-
if (focusedElement && returnFocus) {
|
|
60
|
-
focusedElement.focus();
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}, [onStartSentinelFocus, onEndSentinelFocus, returnFocus]);
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
<FocusContainer>
|
|
67
|
-
<span tabIndex={0} ref={startSentinelRef} />
|
|
68
|
-
<div tabIndex={-1} ref={contentRef}>
|
|
69
|
-
{children}
|
|
70
|
-
</div>
|
|
71
|
-
<span tabIndex={0} ref={endSentinelRef} />
|
|
72
|
-
</FocusContainer>
|
|
73
|
-
);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export default FocusWithin;
|
package/src/preview/Header.tsx
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* SPDX-FileCopyrightText: 2022 Zextras <https://www.zextras.com>
|
|
3
|
-
*
|
|
4
|
-
* SPDX-License-Identifier: AGPL-3.0-only
|
|
5
|
-
*/
|
|
6
|
-
import React from 'react';
|
|
7
|
-
|
|
8
|
-
import { IconButton, Text, Tooltip } from '@zextras/carbonio-design-system';
|
|
9
|
-
import map from 'lodash/map';
|
|
10
|
-
import styled from 'styled-components';
|
|
11
|
-
|
|
12
|
-
const HeaderContainer = styled.div`
|
|
13
|
-
display: flex;
|
|
14
|
-
justify-content: space-between;
|
|
15
|
-
padding: 16px;
|
|
16
|
-
`;
|
|
17
|
-
|
|
18
|
-
const LeftContainer = styled.div`
|
|
19
|
-
display: flex;
|
|
20
|
-
justify-content: flex-start;
|
|
21
|
-
align-items: center;
|
|
22
|
-
gap: 8px;
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
const RightContainer = styled.div`
|
|
26
|
-
display: flex;
|
|
27
|
-
justify-content: flex-end;
|
|
28
|
-
align-items: center;
|
|
29
|
-
gap: 8px;
|
|
30
|
-
`;
|
|
31
|
-
|
|
32
|
-
const InfoContainer = styled.div`
|
|
33
|
-
width: fit-content;
|
|
34
|
-
& div {
|
|
35
|
-
line-height: 1.5;
|
|
36
|
-
}
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
const UpperCaseText = styled(Text)`
|
|
40
|
-
text-transform: uppercase;
|
|
41
|
-
`;
|
|
42
|
-
|
|
43
|
-
interface HeaderAction {
|
|
44
|
-
/** id used as key */
|
|
45
|
-
id: string;
|
|
46
|
-
/** Action called on click */
|
|
47
|
-
onClick?: React.ReactEventHandler;
|
|
48
|
-
/** Icon from the theme */
|
|
49
|
-
icon: string;
|
|
50
|
-
/** Label to show as tooltip for the action */
|
|
51
|
-
tooltipLabel?: string;
|
|
52
|
-
tooltipPlacement?: React.ComponentPropsWithRef<typeof Tooltip>['placement'];
|
|
53
|
-
/** Disabled status for the action */
|
|
54
|
-
disabled?: boolean;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface HeaderProps {
|
|
58
|
-
/** Left Action for the preview */
|
|
59
|
-
closeAction?: HeaderAction;
|
|
60
|
-
/** Actions for the preview */
|
|
61
|
-
actions: HeaderAction[];
|
|
62
|
-
/** Extension of the file, shown as info */
|
|
63
|
-
extension: string;
|
|
64
|
-
/** Name of the file, shown as info */
|
|
65
|
-
filename: string;
|
|
66
|
-
/** Size of the file, shown as info */
|
|
67
|
-
size: string;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const Header: React.VFC<HeaderProps> = ({ closeAction, actions, filename, extension, size }) => (
|
|
71
|
-
<HeaderContainer>
|
|
72
|
-
<LeftContainer>
|
|
73
|
-
{closeAction && (
|
|
74
|
-
<Tooltip
|
|
75
|
-
label={closeAction.tooltipLabel}
|
|
76
|
-
disabled={!closeAction.tooltipLabel}
|
|
77
|
-
key={closeAction.id}
|
|
78
|
-
placement={closeAction.tooltipPlacement}
|
|
79
|
-
>
|
|
80
|
-
<IconButton
|
|
81
|
-
onClick={closeAction.onClick}
|
|
82
|
-
icon={closeAction.icon}
|
|
83
|
-
size="medium"
|
|
84
|
-
backgroundColor="transparent"
|
|
85
|
-
iconColor="gray6"
|
|
86
|
-
/>
|
|
87
|
-
</Tooltip>
|
|
88
|
-
)}
|
|
89
|
-
<InfoContainer>
|
|
90
|
-
<Text size="small" color="gray6">
|
|
91
|
-
{filename}
|
|
92
|
-
</Text>
|
|
93
|
-
<UpperCaseText size="small" color="gray6">
|
|
94
|
-
{extension}
|
|
95
|
-
{extension && size && <> · </>}
|
|
96
|
-
{size}
|
|
97
|
-
</UpperCaseText>
|
|
98
|
-
</InfoContainer>
|
|
99
|
-
</LeftContainer>
|
|
100
|
-
<RightContainer>
|
|
101
|
-
{map(actions, ({ id, onClick, disabled, icon, tooltipLabel, tooltipPlacement }) => (
|
|
102
|
-
<Tooltip
|
|
103
|
-
label={tooltipLabel}
|
|
104
|
-
disabled={!tooltipLabel}
|
|
105
|
-
key={id}
|
|
106
|
-
placement={tooltipPlacement}
|
|
107
|
-
>
|
|
108
|
-
<IconButton
|
|
109
|
-
onClick={onClick}
|
|
110
|
-
disabled={disabled}
|
|
111
|
-
icon={icon}
|
|
112
|
-
size="medium"
|
|
113
|
-
backgroundColor="transparent"
|
|
114
|
-
iconColor="gray6"
|
|
115
|
-
/>
|
|
116
|
-
</Tooltip>
|
|
117
|
-
))}
|
|
118
|
-
</RightContainer>
|
|
119
|
-
</HeaderContainer>
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
export default Header;
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* SPDX-FileCopyrightText: 2022 Zextras <https://www.zextras.com>
|
|
3
|
-
*
|
|
4
|
-
* SPDX-License-Identifier: AGPL-3.0-only
|
|
5
|
-
*/
|
|
6
|
-
import React, { useCallback, useEffect, useRef } from 'react';
|
|
7
|
-
|
|
8
|
-
import { Container, Portal, useCombinedRefs } from '@zextras/carbonio-design-system';
|
|
9
|
-
import styled from 'styled-components';
|
|
10
|
-
|
|
11
|
-
import FocusWithin from './FocusWithin';
|
|
12
|
-
import Header, { HeaderProps } from './Header';
|
|
13
|
-
|
|
14
|
-
const Overlay = styled.div`
|
|
15
|
-
height: 100vh;
|
|
16
|
-
max-height: 100vh;
|
|
17
|
-
width: 100%;
|
|
18
|
-
max-width: 100%;
|
|
19
|
-
position: fixed;
|
|
20
|
-
top: 0;
|
|
21
|
-
left: 0;
|
|
22
|
-
background-color: rgba(0, 0, 0, 0.8);
|
|
23
|
-
display: flex;
|
|
24
|
-
justify-content: center;
|
|
25
|
-
align-items: center;
|
|
26
|
-
z-index: 1003;
|
|
27
|
-
`;
|
|
28
|
-
|
|
29
|
-
const ExternalContainer = styled.div`
|
|
30
|
-
height: 100vh;
|
|
31
|
-
max-height: 100vh;
|
|
32
|
-
width: 100vw;
|
|
33
|
-
max-width: 100vw;
|
|
34
|
-
display: flex;
|
|
35
|
-
flex-direction: column;
|
|
36
|
-
position: relative;
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
const MiddleContainer = styled(Container)`
|
|
40
|
-
flex-grow: 1;
|
|
41
|
-
`;
|
|
42
|
-
|
|
43
|
-
const Image = styled.img`
|
|
44
|
-
max-height: 100%;
|
|
45
|
-
max-width: 100%;
|
|
46
|
-
min-height: 0;
|
|
47
|
-
min-width: 0;
|
|
48
|
-
align-self: center;
|
|
49
|
-
filter: drop-shadow(0px 5px 14px rgba(0, 0, 0, 0.35));
|
|
50
|
-
border-radius: 4px;
|
|
51
|
-
`;
|
|
52
|
-
|
|
53
|
-
const PreviewContainer = styled.div.attrs({
|
|
54
|
-
$paddingVertical: '32px',
|
|
55
|
-
$paddingHorizontal: '16px',
|
|
56
|
-
$gap: '8px'
|
|
57
|
-
})`
|
|
58
|
-
display: flex;
|
|
59
|
-
max-width: 100%;
|
|
60
|
-
max-height: calc(100vh - ${({ $paddingVertical }): string => $paddingVertical} * 2);
|
|
61
|
-
flex-direction: column;
|
|
62
|
-
gap: ${({ $gap }): string => $gap};
|
|
63
|
-
justify-content: center;
|
|
64
|
-
align-items: center;
|
|
65
|
-
overflow: hidden;
|
|
66
|
-
padding: ${({ $paddingVertical, $paddingHorizontal }): string =>
|
|
67
|
-
`${$paddingVertical} ${$paddingHorizontal}`};
|
|
68
|
-
outline: none;
|
|
69
|
-
flex-grow: 1;
|
|
70
|
-
`;
|
|
71
|
-
|
|
72
|
-
type ImagePreviewProps = Partial<HeaderProps> & {
|
|
73
|
-
/**
|
|
74
|
-
* HTML node where to insert the Portal's children.
|
|
75
|
-
* The default value is 'window.top.document'.
|
|
76
|
-
* */
|
|
77
|
-
container?: React.RefObject<HTMLElement>;
|
|
78
|
-
/** Flag to disable the Portal implementation */
|
|
79
|
-
disablePortal?: boolean;
|
|
80
|
-
/** Flag to show or hide Portal's content */
|
|
81
|
-
show: boolean;
|
|
82
|
-
/** preview img source */
|
|
83
|
-
src: string;
|
|
84
|
-
/** Callback to hide the preview */
|
|
85
|
-
onClose: (e: React.SyntheticEvent | KeyboardEvent) => void;
|
|
86
|
-
/** Alternative text for image */
|
|
87
|
-
alt?: string;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const ImagePreview = React.forwardRef<HTMLDivElement, ImagePreviewProps>(function PreviewFn(
|
|
91
|
-
{
|
|
92
|
-
src,
|
|
93
|
-
show,
|
|
94
|
-
container,
|
|
95
|
-
disablePortal,
|
|
96
|
-
extension = '',
|
|
97
|
-
filename = '',
|
|
98
|
-
size = '',
|
|
99
|
-
actions = [],
|
|
100
|
-
closeAction,
|
|
101
|
-
onClose,
|
|
102
|
-
alt
|
|
103
|
-
},
|
|
104
|
-
ref
|
|
105
|
-
) {
|
|
106
|
-
const previewRef: React.MutableRefObject<HTMLDivElement | null> = useCombinedRefs(ref);
|
|
107
|
-
const imageRef = useRef<HTMLImageElement | null>(null);
|
|
108
|
-
|
|
109
|
-
const escapeEvent = useCallback<(e: KeyboardEvent) => void>(
|
|
110
|
-
(event) => {
|
|
111
|
-
if (event.key === 'Escape') {
|
|
112
|
-
onClose(event);
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
[onClose]
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
useEffect(() => {
|
|
119
|
-
if (show) {
|
|
120
|
-
document.addEventListener('keyup', escapeEvent);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return (): void => {
|
|
124
|
-
document.removeEventListener('keyup', escapeEvent);
|
|
125
|
-
};
|
|
126
|
-
}, [escapeEvent, show]);
|
|
127
|
-
|
|
128
|
-
const onOverlayClick = useCallback<React.ReactEventHandler>(
|
|
129
|
-
(event) => {
|
|
130
|
-
// TODO: stop propagation or not?
|
|
131
|
-
event.stopPropagation();
|
|
132
|
-
previewRef.current &&
|
|
133
|
-
!event.isDefaultPrevented() &&
|
|
134
|
-
(previewRef.current === event.target ||
|
|
135
|
-
!previewRef.current.contains(event.target as Node)) &&
|
|
136
|
-
onClose(event);
|
|
137
|
-
},
|
|
138
|
-
[onClose, previewRef]
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
return (
|
|
142
|
-
<Portal show={show} disablePortal={disablePortal} container={container}>
|
|
143
|
-
<Overlay onClick={onOverlayClick}>
|
|
144
|
-
<FocusWithin>
|
|
145
|
-
<ExternalContainer>
|
|
146
|
-
<Header
|
|
147
|
-
actions={actions}
|
|
148
|
-
filename={filename}
|
|
149
|
-
extension={extension}
|
|
150
|
-
size={size}
|
|
151
|
-
closeAction={closeAction}
|
|
152
|
-
/>
|
|
153
|
-
<MiddleContainer orientation="horizontal" crossAlignment="unset" minHeight={0}>
|
|
154
|
-
{/* TODO: uncomment when navigation between items will be implemented */}
|
|
155
|
-
{/* <Container width="fit"> */}
|
|
156
|
-
{/* <Padding left="small" right="small"> */}
|
|
157
|
-
{/* <IconButton */}
|
|
158
|
-
{/* icon="ArrowBackOutline" */}
|
|
159
|
-
{/* size="medium" */}
|
|
160
|
-
{/* backgroundColor="gray0" */}
|
|
161
|
-
{/* iconColor="gray6" */}
|
|
162
|
-
{/* borderRadius="round" */}
|
|
163
|
-
{/* /> */}
|
|
164
|
-
{/* </Padding> */}
|
|
165
|
-
{/* </Container> */}
|
|
166
|
-
<PreviewContainer ref={previewRef}>
|
|
167
|
-
<Image
|
|
168
|
-
alt={alt ?? filename}
|
|
169
|
-
src={src}
|
|
170
|
-
onError={(): void => console.log('TODO handle error')}
|
|
171
|
-
ref={imageRef}
|
|
172
|
-
/>
|
|
173
|
-
</PreviewContainer>
|
|
174
|
-
{/* TODO: uncomment when navigation between items will be implemented */}
|
|
175
|
-
{/* <Container width="fit"> */}
|
|
176
|
-
{/* <Padding left="small" right="small"> */}
|
|
177
|
-
{/* <IconButton */}
|
|
178
|
-
{/* icon="ArrowForwardOutline" */}
|
|
179
|
-
{/* size="medium" */}
|
|
180
|
-
{/* backgroundColor="gray0" */}
|
|
181
|
-
{/* iconColor="gray6" */}
|
|
182
|
-
{/* borderRadius="round" */}
|
|
183
|
-
{/* /> */}
|
|
184
|
-
{/* </Padding> */}
|
|
185
|
-
{/* </Container> */}
|
|
186
|
-
</MiddleContainer>
|
|
187
|
-
</ExternalContainer>
|
|
188
|
-
</FocusWithin>
|
|
189
|
-
</Overlay>
|
|
190
|
-
</Portal>
|
|
191
|
-
);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
export { ImagePreview, ImagePreviewProps };
|