cozy-sharing 4.4.1 → 4.5.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 CHANGED
@@ -3,6 +3,17 @@
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
+ # [4.5.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@4.4.1...cozy-sharing@4.5.0) (2022-07-13)
7
+
8
+
9
+ ### Features
10
+
11
+ * Allow sharemodal to use Location ([032f963](https://github.com/cozy/cozy-libs/commit/032f963c7296dcd296c5ef21a8814407ef9cf2cf))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [4.4.1](https://github.com/cozy/cozy-libs/compare/cozy-sharing@4.4.0...cozy-sharing@4.4.1) (2022-07-11)
7
18
 
8
19
  **Note:** Version bump only for package cozy-sharing
@@ -1,12 +1,13 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["document"],
4
- _excluded2 = ["document"];
3
+ var _excluded = ["document"];
5
4
  import React from 'react';
5
+ import omit from 'lodash/omit';
6
+ import { useLocation } from 'react-router';
7
+ import EditableSharingModal from './components/EditableSharingModal';
6
8
  import SharingContext from './context';
7
9
  import withLocales from './withLocales';
8
10
  import { SharingDetailsModal } from './SharingDetailsModal';
9
- import EditableSharingModal from './components/EditableSharingModal';
10
11
 
11
12
  var SharingModal = function SharingModal(_ref) {
12
13
  var document = _ref.document,
@@ -29,14 +30,17 @@ var SharingModal = function SharingModal(_ref) {
29
30
  });
30
31
  };
31
32
 
32
- export var ShareModal = withLocales(function (_ref3) {
33
- var document = _ref3.document,
34
- rest = _objectWithoutProperties(_ref3, _excluded2);
33
+ export var ShareModal = withLocales(function (props) {
34
+ var _location$state;
35
35
 
36
- return /*#__PURE__*/React.createElement(SharingContext.Consumer, null, function (_ref4) {
37
- var byDocId = _ref4.byDocId,
38
- isOwner = _ref4.isOwner,
39
- canReshare = _ref4.canReshare;
36
+ var location = useLocation();
37
+ var locationProps = (_location$state = location.state) === null || _location$state === void 0 ? void 0 : _location$state.modalProps;
38
+ var document = (locationProps === null || locationProps === void 0 ? void 0 : locationProps.document) || props.document;
39
+ var rest = omit(locationProps || props, 'document');
40
+ return /*#__PURE__*/React.createElement(SharingContext.Consumer, null, function (_ref3) {
41
+ var byDocId = _ref3.byDocId,
42
+ isOwner = _ref3.isOwner,
43
+ canReshare = _ref3.canReshare;
40
44
  return !byDocId[document.id] || isOwner(document.id) || canReshare(document.id) ? /*#__PURE__*/React.createElement(EditableSharingModal, _extends({
41
45
  document: document
42
46
  }, rest)) : /*#__PURE__*/React.createElement(SharingModal, _extends({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-sharing",
3
- "version": "4.4.1",
3
+ "version": "4.5.0",
4
4
  "description": "Provides sharing login for React applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -63,5 +63,5 @@
63
63
  "sideEffects": [
64
64
  "*.css"
65
65
  ],
66
- "gitHead": "cde54ed59980a5a87d267afa2a3b2ac695893fa9"
66
+ "gitHead": "cae03c6aa378bb8a476ce4d598f894db5a93f595"
67
67
  }
@@ -1,9 +1,11 @@
1
1
  import React from 'react'
2
+ import omit from 'lodash/omit'
3
+ import { useLocation } from 'react-router'
2
4
 
5
+ import EditableSharingModal from './components/EditableSharingModal'
3
6
  import SharingContext from './context'
4
7
  import withLocales from './withLocales'
5
8
  import { SharingDetailsModal } from './SharingDetailsModal'
6
- import EditableSharingModal from './components/EditableSharingModal'
7
9
 
8
10
  const SharingModal = ({ document, ...rest }) => (
9
11
  <SharingContext.Consumer>
@@ -27,16 +29,23 @@ const SharingModal = ({ document, ...rest }) => (
27
29
  </SharingContext.Consumer>
28
30
  )
29
31
 
30
- export const ShareModal = withLocales(({ document, ...rest }) => (
31
- <SharingContext.Consumer>
32
- {({ byDocId, isOwner, canReshare }) =>
33
- !byDocId[document.id] ||
34
- isOwner(document.id) ||
35
- canReshare(document.id) ? (
36
- <EditableSharingModal document={document} {...rest} />
37
- ) : (
38
- <SharingModal document={document} {...rest} />
39
- )
40
- }
41
- </SharingContext.Consumer>
42
- ))
32
+ export const ShareModal = withLocales(props => {
33
+ const location = useLocation()
34
+ const locationProps = location.state?.modalProps
35
+ const document = locationProps?.document || props.document
36
+ const rest = omit(locationProps || props, 'document')
37
+
38
+ return (
39
+ <SharingContext.Consumer>
40
+ {({ byDocId, isOwner, canReshare }) =>
41
+ !byDocId[document.id] ||
42
+ isOwner(document.id) ||
43
+ canReshare(document.id) ? (
44
+ <EditableSharingModal document={document} {...rest} />
45
+ ) : (
46
+ <SharingModal document={document} {...rest} />
47
+ )
48
+ }
49
+ </SharingContext.Consumer>
50
+ )
51
+ })