cozy-ui 80.1.1 → 80.2.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
@@ -1,3 +1,16 @@
1
+ # [80.2.0](https://github.com/cozy/cozy-ui/compare/v80.1.1...v80.2.0) (2023-02-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **Viewer:** Add default value to calc to avoid undefined ([fd13e45](https://github.com/cozy/cozy-ui/commit/fd13e45))
7
+
8
+
9
+ ### Features
10
+
11
+ * **Viewer:** Add componentsProps and support OnlyOfficeViewer inside ([bf205e1](https://github.com/cozy/cozy-ui/commit/bf205e1))
12
+ * **Viewer:** Display content top when file from konnector ([070ab58](https://github.com/cozy/cozy-ui/commit/070ab58))
13
+
1
14
  ## [80.1.1](https://github.com/cozy/cozy-ui/compare/v80.1.0...v80.1.1) (2023-01-27)
2
15
 
3
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "80.1.1",
3
+ "version": "80.2.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -23,7 +23,7 @@ The `Viewer` can display an **information panel** to show additional information
23
23
  * **showClose** : `<boolean>` – Whether to show close button in toolbar
24
24
  * **showNavigation** : `<boolean>` – Whether to show left and right arrows to navigate between files
25
25
  * **renderFallbackExtraContent** : `<function>` – A render prop that is called when a file can't be displayed
26
- * **onlyOfficeProps** : `<object>` – Used to open an Only Office file
26
+ * **onlyOfficeProps** : `<object>` – Used to open an Only Office file (deprecated)
27
27
  * **disablePanel** : `<boolean>` – Show/Hide the panel containing more information about the file only on Desktop
28
28
  * **disableFooter** : `<boolean>` – Show/Hide the panel containing more information about the file only on Phone & Tablet devices
29
29
  * **editPathByModelProps** : `<object>` – Edit path by model properties
@@ -31,6 +31,10 @@ The `Viewer` can display an **information panel** to show additional information
31
31
  * **page** : `<string>` – URL used to edit the file when editing a `page` type metadata (side of the document)
32
32
  * **onChangeRequest** : `<function>` - Called with (nextFile, nextIndex) when the user requests to navigate to another file
33
33
  * **onCloseRequest** : `<function>` - Called when the user wants to leave the Viewer
34
+ * **componentsProps** : `<object>` – Props passed to components with the same name
35
+ * **OnlyOfficeViewer** : `<object>` – Used to open an Only Office file
36
+ * **isEnabled** : `<boolean>` – Whether Only Office is enabled on the server
37
+ * **opener** : `<function>` – To open the Only Office file
34
38
 
35
39
  ### Demo
36
40
 
@@ -209,16 +213,18 @@ const editPathByModelProps = {
209
213
  currentURL={state.currentURL}
210
214
  showNavigation={variant.navigation}
211
215
  editPathByModelProps={editPathByModelProps}
212
- onlyOfficeProps={{
213
- isEnabled: variant.onlyOfficeEnabled,
214
- opener: () => alert('This is a demo, no Only Office opener here')
215
- }}
216
216
  toolbarProps={{
217
217
  showToolbar: variant.toolbar,
218
218
  showClose: state.showToolbarCloseButton
219
219
  }}
220
220
  onCloseRequest={toggleViewer}
221
221
  onChangeRequest={onFileChange}
222
+ componentsProps={{
223
+ OnlyOfficeViewer: {
224
+ isEnabled: variant.onlyOfficeEnabled,
225
+ opener: () => alert('This is a demo, no Only Office opener here')
226
+ }
227
+ }}
222
228
  >
223
229
  <FooterActionButtons>
224
230
  <ShareButtonFake />
@@ -71,7 +71,8 @@ class Viewer extends Component {
71
71
  showNavigation,
72
72
  renderFallbackExtraContent,
73
73
  validForPanel,
74
- onlyOfficeProps
74
+ onlyOfficeProps,
75
+ componentsProps
75
76
  } = this.props
76
77
 
77
78
  // this `expanded` property makes the next/previous controls cover the displayed image
@@ -96,6 +97,7 @@ class Viewer extends Component {
96
97
  onClose={this.onClose}
97
98
  renderFallbackExtraContent={renderFallbackExtraContent}
98
99
  onlyOfficeProps={onlyOfficeProps}
100
+ componentsProps={componentsProps}
99
101
  />
100
102
  </ViewerControls>
101
103
  </>
@@ -125,7 +127,17 @@ Viewer.propTypes = {
125
127
  /** To open the Only Office file */
126
128
  opener: PropTypes.func
127
129
  }),
128
- validForPanel: PropTypes.bool
130
+ validForPanel: PropTypes.bool,
131
+ /* Props passed to components with the same name */
132
+ componentsProps: PropTypes.shape({
133
+ /** Used to open an Only Office file */
134
+ OnlyOfficeViewer: PropTypes.shape({
135
+ /** Whether Only Office is enabled on the server */
136
+ isEnabled: PropTypes.bool,
137
+ /** To open the Only Office file */
138
+ opener: PropTypes.func
139
+ })
140
+ })
129
141
  }
130
142
 
131
143
  export default Viewer
@@ -102,7 +102,17 @@ ViewerContainer.propTypes = {
102
102
  /** Show/Hide the panel containing more information about the file only on Desktop */
103
103
  disablePanel: PropTypes.bool,
104
104
  /** Show/Hide the panel containing more information about the file only on Phone & Tablet devices */
105
- disableFooter: PropTypes.bool
105
+ disableFooter: PropTypes.bool,
106
+ /* Props passed to components with the same name */
107
+ componentsProps: PropTypes.shape({
108
+ /** Used to open an Only Office file */
109
+ OnlyOfficeViewer: PropTypes.shape({
110
+ /** Whether Only Office is enabled on the server */
111
+ isEnabled: PropTypes.bool,
112
+ /** To open the Only Office file */
113
+ opener: PropTypes.func
114
+ })
115
+ })
106
116
  }
107
117
 
108
118
  ViewerContainer.defaultProps = {
@@ -83,7 +83,7 @@
83
83
  .viewer-pdfMobile
84
84
  width 100%
85
85
  height 'calc(100% - %s - var(--flagship-top-height))' % $viewerHeightMedium
86
- margin-top 'calc(var(--flagship-top-height) + %s)' % $viewerMarginTopMedium
86
+ margin-top 'calc(var(--flagship-top-height, 0rem) + %s)' % $viewerMarginTopMedium
87
87
 
88
88
  &--image
89
89
  width 100%
@@ -19,6 +19,10 @@ import OnlyOfficeViewer from '../ViewersByFile/OnlyOfficeViewer'
19
19
 
20
20
  import { useEncrypted } from '../providers/EncryptedProvider'
21
21
 
22
+ import createDepreciationLogger from '../../helpers/createDepreciationLogger'
23
+
24
+ const logDepecratedOnlyOfficeProps = createDepreciationLogger()
25
+
22
26
  const { isPlainText } = models.file
23
27
 
24
28
  export const getViewerComponentName = ({
@@ -60,10 +64,19 @@ const ViewerByFile = ({
60
64
  gesturesRef,
61
65
  onSwipe,
62
66
  onlyOfficeProps,
63
- breakpoints: { isDesktop }
67
+ breakpoints: { isDesktop },
68
+ componentsProps
64
69
  }) => {
65
- const isOnlyOfficeEnabled = onlyOfficeProps && onlyOfficeProps.isEnabled
66
- const onlyOfficeOpener = onlyOfficeProps && onlyOfficeProps.opener
70
+ if (onlyOfficeProps) {
71
+ logDepecratedOnlyOfficeProps(
72
+ 'onlyOfficeProps in Viewer is deprecated. Please use componentsProps.OnlyOfficeViewer instead.'
73
+ )
74
+ }
75
+
76
+ const isOnlyOfficeEnabled =
77
+ componentsProps?.OnlyOfficeViewer?.isEnabled || onlyOfficeProps?.isEnabled
78
+ const onlyOfficeOpener =
79
+ componentsProps?.OnlyOfficeViewer?.opener || onlyOfficeProps?.opener
67
80
 
68
81
  const { url } = useEncrypted()
69
82
 
@@ -99,7 +112,8 @@ ViewerByFile.propTypes = {
99
112
  // gestures, gesturesRef and onSwipe are got from ViewerControls
100
113
  gestures: PropTypes.object,
101
114
  gesturesRef: PropTypes.object,
102
- onSwipe: PropTypes.func
115
+ onSwipe: PropTypes.func,
116
+ componentsProps: PropTypes.object
103
117
  }
104
118
 
105
119
  export default withBreakpoints()(ViewerByFile)
@@ -7,6 +7,7 @@ import Hammer from 'hammerjs'
7
7
  import { withStyles } from '../../styles'
8
8
  import withBreakpoints from '../../helpers/withBreakpoints'
9
9
 
10
+ import { isValidForPanel } from '../helpers'
10
11
  import { toolbarPropsPropType } from '../index'
11
12
  import { infoWidth } from './InformationPanel'
12
13
  import Toolbar from './Toolbar'
@@ -116,10 +117,16 @@ class ViewerControls extends Component {
116
117
  } = this.props
117
118
  const { showToolbar, showClose, toolbarRef } = toolbarProps
118
119
  const { hidden } = this.state
120
+
121
+ const shouldDisplayContentTop = isValidForPanel({ file })
122
+
119
123
  return (
120
124
  <div
121
125
  className={cx(styles['viewer-controls'], {
122
126
  [styles['viewer-controls--expanded']]: expanded,
127
+ [styles[
128
+ 'viewer-controls--display-content-top'
129
+ ]]: shouldDisplayContentTop,
123
130
  [classes.viewerControlsWithInfo]: showInfoPanel
124
131
  })}
125
132
  ref={wrapped => {
@@ -56,6 +56,11 @@
56
56
  margin-top 0
57
57
  width 40%
58
58
 
59
+ .viewer-controls--display-content-top
60
+ +medium-screen()
61
+ justify-content flex-start
62
+ padding-top $toolbarHeightMedium - $viewerMarginTopMedium
63
+
59
64
  .viewer-toolbar
60
65
  position absolute
61
66
  top 0
@@ -108,7 +108,8 @@ var Viewer = /*#__PURE__*/function (_Component) {
108
108
  showNavigation = _this$props3.showNavigation,
109
109
  renderFallbackExtraContent = _this$props3.renderFallbackExtraContent,
110
110
  validForPanel = _this$props3.validForPanel,
111
- onlyOfficeProps = _this$props3.onlyOfficeProps; // this `expanded` property makes the next/previous controls cover the displayed image
111
+ onlyOfficeProps = _this$props3.onlyOfficeProps,
112
+ componentsProps = _this$props3.componentsProps; // this `expanded` property makes the next/previous controls cover the displayed image
112
113
 
113
114
  var expanded = currentFile && currentFile.class === 'image';
114
115
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ViewerControls, {
@@ -128,7 +129,8 @@ var Viewer = /*#__PURE__*/function (_Component) {
128
129
  file: currentFile,
129
130
  onClose: this.onClose,
130
131
  renderFallbackExtraContent: renderFallbackExtraContent,
131
- onlyOfficeProps: onlyOfficeProps
132
+ onlyOfficeProps: onlyOfficeProps,
133
+ componentsProps: componentsProps
132
134
  })));
133
135
  }
134
136
  }]);
@@ -164,6 +166,18 @@ Viewer.propTypes = {
164
166
  /** To open the Only Office file */
165
167
  opener: PropTypes.func
166
168
  }),
167
- validForPanel: PropTypes.bool
169
+ validForPanel: PropTypes.bool,
170
+
171
+ /* Props passed to components with the same name */
172
+ componentsProps: PropTypes.shape({
173
+ /** Used to open an Only Office file */
174
+ OnlyOfficeViewer: PropTypes.shape({
175
+ /** Whether Only Office is enabled on the server */
176
+ isEnabled: PropTypes.bool,
177
+
178
+ /** To open the Only Office file */
179
+ opener: PropTypes.func
180
+ })
181
+ })
168
182
  };
169
183
  export default Viewer;
@@ -113,7 +113,19 @@ ViewerContainer.propTypes = {
113
113
  disablePanel: PropTypes.bool,
114
114
 
115
115
  /** Show/Hide the panel containing more information about the file only on Phone & Tablet devices */
116
- disableFooter: PropTypes.bool
116
+ disableFooter: PropTypes.bool,
117
+
118
+ /* Props passed to components with the same name */
119
+ componentsProps: PropTypes.shape({
120
+ /** Used to open an Only Office file */
121
+ OnlyOfficeViewer: PropTypes.shape({
122
+ /** Whether Only Office is enabled on the server */
123
+ isEnabled: PropTypes.bool,
124
+
125
+ /** To open the Only Office file */
126
+ opener: PropTypes.func
127
+ })
128
+ })
117
129
  };
118
130
  ViewerContainer.defaultProps = {
119
131
  currentIndex: 0,
@@ -10,6 +10,7 @@ var styles = {
10
10
  "viewer-nav--next": "styles__viewer-nav--next___1ah-4",
11
11
  "viewer-controls": "styles__viewer-controls___1BYEX",
12
12
  "--expanded": "styles__--expanded___2NoA-",
13
+ "viewer-controls--display-content-top": "styles__viewer-controls--display-content-top___3I1xq",
13
14
  "viewer-toolbar": "styles__viewer-toolbar___2zPR7",
14
15
  "viewer-toolbar--hidden": "styles__viewer-toolbar--hidden___3r3Sj",
15
16
  "viewer-footer": "styles__viewer-footer___2ieQS"
@@ -14,6 +14,7 @@ var styles = {
14
14
  "viewer-nav--next": "styles__viewer-nav--next___1ah-4",
15
15
  "viewer-controls": "styles__viewer-controls___1BYEX",
16
16
  "--expanded": "styles__--expanded___2NoA-",
17
+ "viewer-controls--display-content-top": "styles__viewer-controls--display-content-top___3I1xq",
17
18
  "viewer-toolbar": "styles__viewer-toolbar___2zPR7",
18
19
  "viewer-toolbar--hidden": "styles__viewer-toolbar--hidden___3r3Sj",
19
20
  "viewer-footer": "styles__viewer-footer___2ieQS"
@@ -25,6 +25,7 @@ var styles = {
25
25
  "viewer-nav--next": "styles__viewer-nav--next___1ah-4",
26
26
  "viewer-controls": "styles__viewer-controls___1BYEX",
27
27
  "--expanded": "styles__--expanded___2NoA-",
28
+ "viewer-controls--display-content-top": "styles__viewer-controls--display-content-top___3I1xq",
28
29
  "viewer-toolbar": "styles__viewer-toolbar___2zPR7",
29
30
  "viewer-toolbar--hidden": "styles__viewer-toolbar--hidden___3r3Sj",
30
31
  "viewer-footer": "styles__viewer-footer___2ieQS"
@@ -14,6 +14,8 @@ import NoViewer from "cozy-ui/transpiled/react/Viewer/NoViewer";
14
14
  import ShortcutViewer from "cozy-ui/transpiled/react/Viewer/ViewersByFile/ShortcutViewer";
15
15
  import OnlyOfficeViewer from "cozy-ui/transpiled/react/Viewer/ViewersByFile/OnlyOfficeViewer";
16
16
  import { useEncrypted } from "cozy-ui/transpiled/react/Viewer/providers/EncryptedProvider";
17
+ import createDepreciationLogger from "cozy-ui/transpiled/react/helpers/createDepreciationLogger";
18
+ var logDepecratedOnlyOfficeProps = createDepreciationLogger();
17
19
  var isPlainText = models.file.isPlainText;
18
20
  export var getViewerComponentName = function getViewerComponentName(_ref) {
19
21
  var file = _ref.file,
@@ -51,6 +53,8 @@ export var getViewerComponentName = function getViewerComponentName(_ref) {
51
53
  };
52
54
 
53
55
  var ViewerByFile = function ViewerByFile(_ref2) {
56
+ var _componentsProps$Only, _componentsProps$Only2;
57
+
54
58
  var file = _ref2.file,
55
59
  onClose = _ref2.onClose,
56
60
  renderFallbackExtraContent = _ref2.renderFallbackExtraContent,
@@ -58,9 +62,15 @@ var ViewerByFile = function ViewerByFile(_ref2) {
58
62
  gesturesRef = _ref2.gesturesRef,
59
63
  onSwipe = _ref2.onSwipe,
60
64
  onlyOfficeProps = _ref2.onlyOfficeProps,
61
- isDesktop = _ref2.breakpoints.isDesktop;
62
- var isOnlyOfficeEnabled = onlyOfficeProps && onlyOfficeProps.isEnabled;
63
- var onlyOfficeOpener = onlyOfficeProps && onlyOfficeProps.opener;
65
+ isDesktop = _ref2.breakpoints.isDesktop,
66
+ componentsProps = _ref2.componentsProps;
67
+
68
+ if (onlyOfficeProps) {
69
+ logDepecratedOnlyOfficeProps('onlyOfficeProps in Viewer is deprecated. Please use componentsProps.OnlyOfficeViewer instead.');
70
+ }
71
+
72
+ var isOnlyOfficeEnabled = (componentsProps === null || componentsProps === void 0 ? void 0 : (_componentsProps$Only = componentsProps.OnlyOfficeViewer) === null || _componentsProps$Only === void 0 ? void 0 : _componentsProps$Only.isEnabled) || (onlyOfficeProps === null || onlyOfficeProps === void 0 ? void 0 : onlyOfficeProps.isEnabled);
73
+ var onlyOfficeOpener = (componentsProps === null || componentsProps === void 0 ? void 0 : (_componentsProps$Only2 = componentsProps.OnlyOfficeViewer) === null || _componentsProps$Only2 === void 0 ? void 0 : _componentsProps$Only2.opener) || (onlyOfficeProps === null || onlyOfficeProps === void 0 ? void 0 : onlyOfficeProps.opener);
64
74
 
65
75
  var _useEncrypted = useEncrypted(),
66
76
  url = _useEncrypted.url;
@@ -92,6 +102,7 @@ ViewerByFile.propTypes = {
92
102
  // gestures, gesturesRef and onSwipe are got from ViewerControls
93
103
  gestures: PropTypes.object,
94
104
  gesturesRef: PropTypes.object,
95
- onSwipe: PropTypes.func
105
+ onSwipe: PropTypes.func,
106
+ componentsProps: PropTypes.object
96
107
  };
97
108
  export default withBreakpoints()(ViewerByFile);
@@ -17,6 +17,7 @@ import cx from 'classnames';
17
17
  import Hammer from 'hammerjs';
18
18
  import { withStyles } from "cozy-ui/transpiled/react/styles";
19
19
  import withBreakpoints from "cozy-ui/transpiled/react/helpers/withBreakpoints";
20
+ import { isValidForPanel } from "cozy-ui/transpiled/react/Viewer/helpers";
20
21
  import { toolbarPropsPropType } from "cozy-ui/transpiled/react/Viewer/index";
21
22
  import { infoWidth } from "cozy-ui/transpiled/react/Viewer/components/InformationPanel";
22
23
  import Toolbar from "cozy-ui/transpiled/react/Viewer/components/Toolbar";
@@ -31,6 +32,7 @@ var styles = {
31
32
  "viewer-nav--next": "styles__viewer-nav--next___1ah-4",
32
33
  "viewer-controls": "styles__viewer-controls___1BYEX",
33
34
  "--expanded": "styles__--expanded___2NoA-",
35
+ "viewer-controls--display-content-top": "styles__viewer-controls--display-content-top___3I1xq",
34
36
  "viewer-toolbar": "styles__viewer-toolbar___2zPR7",
35
37
  "viewer-toolbar--hidden": "styles__viewer-toolbar--hidden___3r3Sj",
36
38
  "viewer-footer": "styles__viewer-footer___2ieQS"
@@ -168,8 +170,11 @@ var ViewerControls = /*#__PURE__*/function (_Component) {
168
170
  showClose = toolbarProps.showClose,
169
171
  toolbarRef = toolbarProps.toolbarRef;
170
172
  var hidden = this.state.hidden;
173
+ var shouldDisplayContentTop = isValidForPanel({
174
+ file: file
175
+ });
171
176
  return /*#__PURE__*/React.createElement("div", {
172
- className: cx(styles['viewer-controls'], (_cx = {}, _defineProperty(_cx, styles['viewer-controls--expanded'], expanded), _defineProperty(_cx, classes.viewerControlsWithInfo, showInfoPanel), _cx)),
177
+ className: cx(styles['viewer-controls'], (_cx = {}, _defineProperty(_cx, styles['viewer-controls--expanded'], expanded), _defineProperty(_cx, styles['viewer-controls--display-content-top'], shouldDisplayContentTop), _defineProperty(_cx, classes.viewerControlsWithInfo, showInfoPanel), _cx)),
173
178
  ref: function ref(wrapped) {
174
179
  _this2.wrapped = wrapped;
175
180
  }