cozy-sharing 16.17.0 → 17.0.0
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/CHANGELOG.md +17 -0
- package/dist/actions/shareNative.js +50 -0
- package/dist/index.js +3 -1
- package/dist/providers/NativeFileSharingProvider.js +95 -0
- package/locales/en.json +2 -1
- package/locales/fr.json +2 -1
- package/package.json +4 -2
- package/src/actions/shareNative.js +52 -0
- package/src/index.jsx +5 -0
- package/src/providers/NativeFileSharingProvider.jsx +47 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,23 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [17.0.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@16.17.0...cozy-sharing@17.0.0) (2024-12-18)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add NativeFileSharingProvider and shareNative action ([71ba4e1](https://github.com/cozy/cozy-libs/commit/71ba4e120a5518534867cd1f1541502652f9b979))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### BREAKING CHANGES
|
|
15
|
+
|
|
16
|
+
* you now need cozy-intent >=2.29.1
|
|
17
|
+
and cozy-device-helper >= 3.7.1 with cozy-sharing
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
6
23
|
# [16.17.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@16.16.0...cozy-sharing@16.17.0) (2024-12-12)
|
|
7
24
|
|
|
8
25
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React, { forwardRef } from 'react';
|
|
3
|
+
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem';
|
|
4
|
+
import Icon from 'cozy-ui/transpiled/react/Icon';
|
|
5
|
+
import ReplyIcon from 'cozy-ui/transpiled/react/Icons/Reply';
|
|
6
|
+
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
|
|
7
|
+
import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
|
|
8
|
+
import { getActionsI18n } from '../hoc/withLocales';
|
|
9
|
+
|
|
10
|
+
var makeComponent = function makeComponent(label, icon) {
|
|
11
|
+
var Component = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
12
|
+
return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
|
|
13
|
+
ref: ref
|
|
14
|
+
}), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
|
|
15
|
+
icon: icon
|
|
16
|
+
})), /*#__PURE__*/React.createElement(ListItemText, {
|
|
17
|
+
primary: label
|
|
18
|
+
}));
|
|
19
|
+
});
|
|
20
|
+
Component.displayName = 'ShareNative';
|
|
21
|
+
return Component;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export var shareNative = function shareNative(_ref) {
|
|
25
|
+
var shareFilesNative = _ref.shareFilesNative,
|
|
26
|
+
isNativeFileSharingAvailable = _ref.isNativeFileSharingAvailable;
|
|
27
|
+
|
|
28
|
+
var _getActionsI18n = getActionsI18n(),
|
|
29
|
+
t = _getActionsI18n.t;
|
|
30
|
+
|
|
31
|
+
var label = t('Share.send');
|
|
32
|
+
var icon = ReplyIcon;
|
|
33
|
+
return {
|
|
34
|
+
name: 'shareNative',
|
|
35
|
+
label: label,
|
|
36
|
+
icon: icon,
|
|
37
|
+
displayCondition: function displayCondition(selectedFiles) {
|
|
38
|
+
return isNativeFileSharingAvailable && selectedFiles.every(function (selectedFile) {
|
|
39
|
+
return selectedFile.type === 'file';
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
action: function action(data) {
|
|
43
|
+
var idsToShare = data.map(function (d) {
|
|
44
|
+
return d._id;
|
|
45
|
+
});
|
|
46
|
+
shareFilesNative(idsToShare);
|
|
47
|
+
},
|
|
48
|
+
Component: makeComponent(label, icon)
|
|
49
|
+
};
|
|
50
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -25,4 +25,6 @@ export { ShareButtonWithRecipients } from './ShareButtonWithRecipients';
|
|
|
25
25
|
export { DOCUMENT_TYPE } from './helpers/documentType';
|
|
26
26
|
export { default as OpenSharingLinkButton } from './OpenSharingLinkButton';
|
|
27
27
|
export { default as OpenSharingLinkFabButton } from './OpenSharingLinkFabButton';
|
|
28
|
-
export {
|
|
28
|
+
export { NativeFileSharingProvider, useNativeFileSharing } from './providers/NativeFileSharingProvider';
|
|
29
|
+
export { openSharingLink } from './actions/openSharingLink';
|
|
30
|
+
export { shareNative } from './actions/shareNative';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
import React, { useState, useEffect, createContext, useContext } from 'react';
|
|
5
|
+
import { isFlagshipApp } from 'cozy-device-helper';
|
|
6
|
+
import { useWebviewIntent } from 'cozy-intent';
|
|
7
|
+
var NativeFileSharingContext = /*#__PURE__*/createContext();
|
|
8
|
+
export var useNativeFileSharing = function useNativeFileSharing() {
|
|
9
|
+
var context = useContext(NativeFileSharingContext);
|
|
10
|
+
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error('useFileSharing must be used within a FileSharingProvider');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return context;
|
|
16
|
+
};
|
|
17
|
+
export var NativeFileSharingProvider = function NativeFileSharingProvider(_ref) {
|
|
18
|
+
var children = _ref.children;
|
|
19
|
+
var webviewIntent = useWebviewIntent();
|
|
20
|
+
|
|
21
|
+
var _useState = useState(false),
|
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
23
|
+
isNativeFileSharingAvailable = _useState2[0],
|
|
24
|
+
setIsNativeFileSharingAvailable = _useState2[1];
|
|
25
|
+
|
|
26
|
+
useEffect(function () {
|
|
27
|
+
var checkNativeFileSharingAvailability = /*#__PURE__*/function () {
|
|
28
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
29
|
+
var availability;
|
|
30
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
31
|
+
while (1) switch (_context.prev = _context.next) {
|
|
32
|
+
case 0:
|
|
33
|
+
_context.t0 = isFlagshipApp();
|
|
34
|
+
|
|
35
|
+
if (!_context.t0) {
|
|
36
|
+
_context.next = 5;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
_context.next = 4;
|
|
41
|
+
return webviewIntent.call('isAvailable', 'shareFiles');
|
|
42
|
+
|
|
43
|
+
case 4:
|
|
44
|
+
_context.t0 = _context.sent;
|
|
45
|
+
|
|
46
|
+
case 5:
|
|
47
|
+
availability = _context.t0;
|
|
48
|
+
setIsNativeFileSharingAvailable(availability);
|
|
49
|
+
|
|
50
|
+
case 7:
|
|
51
|
+
case "end":
|
|
52
|
+
return _context.stop();
|
|
53
|
+
}
|
|
54
|
+
}, _callee);
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
return function checkNativeFileSharingAvailability() {
|
|
58
|
+
return _ref2.apply(this, arguments);
|
|
59
|
+
};
|
|
60
|
+
}();
|
|
61
|
+
|
|
62
|
+
checkNativeFileSharingAvailability();
|
|
63
|
+
}, [webviewIntent]);
|
|
64
|
+
|
|
65
|
+
var shareFilesNative = /*#__PURE__*/function () {
|
|
66
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(filesIds) {
|
|
67
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
68
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
69
|
+
case 0:
|
|
70
|
+
_context2.next = 2;
|
|
71
|
+
return webviewIntent.call('shareFiles', filesIds);
|
|
72
|
+
|
|
73
|
+
case 2:
|
|
74
|
+
return _context2.abrupt("return", _context2.sent);
|
|
75
|
+
|
|
76
|
+
case 3:
|
|
77
|
+
case "end":
|
|
78
|
+
return _context2.stop();
|
|
79
|
+
}
|
|
80
|
+
}, _callee2);
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
return function shareFilesNative(_x) {
|
|
84
|
+
return _ref3.apply(this, arguments);
|
|
85
|
+
};
|
|
86
|
+
}();
|
|
87
|
+
|
|
88
|
+
return /*#__PURE__*/React.createElement(NativeFileSharingContext.Provider, {
|
|
89
|
+
value: {
|
|
90
|
+
isNativeFileSharingAvailable: isNativeFileSharingAvailable,
|
|
91
|
+
shareFilesNative: shareFilesNative
|
|
92
|
+
}
|
|
93
|
+
}, children);
|
|
94
|
+
};
|
|
95
|
+
export default NativeFileSharingProvider;
|
package/locales/en.json
CHANGED
package/locales/fr.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-sharing",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.0",
|
|
4
4
|
"description": "Provides sharing login for React applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Cozy",
|
|
@@ -65,6 +65,8 @@
|
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"cozy-client": ">=51.4.0",
|
|
68
|
+
"cozy-device-helper": ">=3.7.1",
|
|
69
|
+
"cozy-intent": ">=2.29.1",
|
|
68
70
|
"cozy-realtime": "^3.11.0",
|
|
69
71
|
"cozy-ui": ">=113.5.0",
|
|
70
72
|
"prop-types": "^15.7.2",
|
|
@@ -74,5 +76,5 @@
|
|
|
74
76
|
"sideEffects": [
|
|
75
77
|
"*.css"
|
|
76
78
|
],
|
|
77
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "e119955a4934470d07c763ac51e95149f469f55f"
|
|
78
80
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
|
|
3
|
+
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
|
|
4
|
+
import Icon from 'cozy-ui/transpiled/react/Icon'
|
|
5
|
+
import ReplyIcon from 'cozy-ui/transpiled/react/Icons/Reply'
|
|
6
|
+
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
|
|
7
|
+
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
|
|
8
|
+
|
|
9
|
+
import { getActionsI18n } from '../hoc/withLocales'
|
|
10
|
+
|
|
11
|
+
const makeComponent = (label, icon) => {
|
|
12
|
+
const Component = forwardRef((props, ref) => {
|
|
13
|
+
return (
|
|
14
|
+
<ActionsMenuItem {...props} ref={ref}>
|
|
15
|
+
<ListItemIcon>
|
|
16
|
+
<Icon icon={icon} />
|
|
17
|
+
</ListItemIcon>
|
|
18
|
+
<ListItemText primary={label} />
|
|
19
|
+
</ActionsMenuItem>
|
|
20
|
+
)
|
|
21
|
+
})
|
|
22
|
+
Component.displayName = 'ShareNative'
|
|
23
|
+
|
|
24
|
+
return Component
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const shareNative = ({
|
|
28
|
+
shareFilesNative,
|
|
29
|
+
isNativeFileSharingAvailable
|
|
30
|
+
}) => {
|
|
31
|
+
const { t } = getActionsI18n()
|
|
32
|
+
|
|
33
|
+
const label = t('Share.send')
|
|
34
|
+
const icon = ReplyIcon
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
name: 'shareNative',
|
|
38
|
+
label,
|
|
39
|
+
icon,
|
|
40
|
+
displayCondition: selectedFiles => {
|
|
41
|
+
return (
|
|
42
|
+
isNativeFileSharingAvailable &&
|
|
43
|
+
selectedFiles.every(selectedFile => selectedFile.type === 'file')
|
|
44
|
+
)
|
|
45
|
+
},
|
|
46
|
+
action: data => {
|
|
47
|
+
const idsToShare = data.map(d => d._id)
|
|
48
|
+
shareFilesNative(idsToShare)
|
|
49
|
+
},
|
|
50
|
+
Component: makeComponent(label, icon)
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/index.jsx
CHANGED
|
@@ -29,4 +29,9 @@ export { ShareButtonWithRecipients } from './ShareButtonWithRecipients'
|
|
|
29
29
|
export { DOCUMENT_TYPE } from './helpers/documentType'
|
|
30
30
|
export { default as OpenSharingLinkButton } from './OpenSharingLinkButton'
|
|
31
31
|
export { default as OpenSharingLinkFabButton } from './OpenSharingLinkFabButton'
|
|
32
|
+
export {
|
|
33
|
+
NativeFileSharingProvider,
|
|
34
|
+
useNativeFileSharing
|
|
35
|
+
} from './providers/NativeFileSharingProvider'
|
|
32
36
|
export { openSharingLink } from './actions/openSharingLink'
|
|
37
|
+
export { shareNative } from './actions/shareNative'
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React, { useState, useEffect, createContext, useContext } from 'react'
|
|
2
|
+
|
|
3
|
+
import { isFlagshipApp } from 'cozy-device-helper'
|
|
4
|
+
import { useWebviewIntent } from 'cozy-intent'
|
|
5
|
+
|
|
6
|
+
const NativeFileSharingContext = createContext()
|
|
7
|
+
|
|
8
|
+
export const useNativeFileSharing = () => {
|
|
9
|
+
const context = useContext(NativeFileSharingContext)
|
|
10
|
+
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error('useFileSharing must be used within a FileSharingProvider')
|
|
13
|
+
}
|
|
14
|
+
return context
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const NativeFileSharingProvider = ({ children }) => {
|
|
18
|
+
const webviewIntent = useWebviewIntent()
|
|
19
|
+
|
|
20
|
+
const [isNativeFileSharingAvailable, setIsNativeFileSharingAvailable] =
|
|
21
|
+
useState(false)
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const checkNativeFileSharingAvailability = async () => {
|
|
25
|
+
const availability =
|
|
26
|
+
isFlagshipApp() &&
|
|
27
|
+
(await webviewIntent.call('isAvailable', 'shareFiles'))
|
|
28
|
+
|
|
29
|
+
setIsNativeFileSharingAvailable(availability)
|
|
30
|
+
}
|
|
31
|
+
checkNativeFileSharingAvailability()
|
|
32
|
+
}, [webviewIntent])
|
|
33
|
+
|
|
34
|
+
const shareFilesNative = async filesIds => {
|
|
35
|
+
return await webviewIntent.call('shareFiles', filesIds)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<NativeFileSharingContext.Provider
|
|
40
|
+
value={{ isNativeFileSharingAvailable, shareFilesNative }}
|
|
41
|
+
>
|
|
42
|
+
{children}
|
|
43
|
+
</NativeFileSharingContext.Provider>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default NativeFileSharingProvider
|