cozy-ui 105.1.0 → 105.2.1
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 +14 -0
- package/package.json +1 -1
- package/react/ActionsMenu/Actions/helpers.js +7 -7
- package/react/ActionsMenu/ActionsItems.jsx +8 -0
- package/react/ActionsMenu/Readme.md +31 -19
- package/react/Viewer/Readme.md +10 -3
- package/react/Viewer/ViewerContainer.jsx +27 -31
- package/react/Viewer/components/PrintButton.jsx +47 -30
- package/transpiled/react/ActionsMenu/Actions/helpers.js +7 -7
- package/transpiled/react/ActionsMenu/ActionsItems.js +7 -0
- package/transpiled/react/Viewer/ViewerContainer.js +2 -3
- package/transpiled/react/Viewer/components/PrintButton.js +69 -79
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [105.2.1](https://github.com/cozy/cozy-ui/compare/v105.2.0...v105.2.1) (2024-03-26)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **Viewer:** Remove WebviewIntentProvider ([edfdc1d](https://github.com/cozy/cozy-ui/commit/edfdc1d))
|
|
7
|
+
|
|
8
|
+
# [105.2.0](https://github.com/cozy/cozy-ui/compare/v105.1.0...v105.2.0) (2024-03-21)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **Viewer:** Refactor PrintButton and use `ActionsItems` ([8b7a068](https://github.com/cozy/cozy-ui/commit/8b7a068))
|
|
14
|
+
|
|
1
15
|
# [105.1.0](https://github.com/cozy/cozy-ui/compare/v105.0.2...v105.1.0) (2024-03-21)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -5,18 +5,18 @@ import { fetchBlobFileById } from 'cozy-client/dist/models/file'
|
|
|
5
5
|
const MAX_RESIZE_IMAGE_SIZE = 3840
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Make array of actions
|
|
8
|
+
* Make array of actions and hydrate actions with options
|
|
9
9
|
*
|
|
10
|
-
* @param {Function[]} actions - Array of actions
|
|
10
|
+
* @param {Function[]} actions - Array of actions with associated actions and conditions
|
|
11
11
|
* @param {object} actionOptions - Options that need to be passed on actions
|
|
12
12
|
* @returns {object[]} Array of actions
|
|
13
13
|
*/
|
|
14
14
|
export const makeActions = (actions = [], options = {}) => {
|
|
15
|
-
return actions.filter(Boolean).map(
|
|
16
|
-
const
|
|
17
|
-
const name =
|
|
15
|
+
return actions.filter(Boolean).map(actionFn => {
|
|
16
|
+
const action = actionFn(options)
|
|
17
|
+
const name = action.name || actionFn.name
|
|
18
18
|
|
|
19
|
-
return { [name]:
|
|
19
|
+
return { [name]: action }
|
|
20
20
|
})
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -58,7 +58,7 @@ export const getOnlyNeededActions = (actions, docs) => {
|
|
|
58
58
|
return actionObject
|
|
59
59
|
})
|
|
60
60
|
.filter(Boolean)
|
|
61
|
-
// We don't want to have an hr as the latest actions available
|
|
61
|
+
// We don't want to have an hr/divider as the latest actions available
|
|
62
62
|
.filter((cleanedAction, idx, cleanedActions) => {
|
|
63
63
|
return !(
|
|
64
64
|
(getActionName(cleanedAction) === 'hr' ||
|
|
@@ -74,4 +74,12 @@ ActionsItems.propTypes = {
|
|
|
74
74
|
onClick: PropTypes.func
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
export const actionsItemsComponentPropTypes = {
|
|
78
|
+
docs: PropTypes.array,
|
|
79
|
+
action: PropTypes.object,
|
|
80
|
+
autoFocus: PropTypes.bool,
|
|
81
|
+
disabled: PropTypes.bool,
|
|
82
|
+
onClick: PropTypes.func
|
|
83
|
+
}
|
|
84
|
+
|
|
77
85
|
export default ActionsItems
|
|
@@ -4,23 +4,7 @@ You can pass a reference to a custom DOM element through the `ref` prop to attac
|
|
|
4
4
|
|
|
5
5
|
A header `ActionsMenuMobileHeader` can be used to provide context on the menu actions. Since on desktop, we display a popper and not a `BottomSheet`, context for the user is not lost, so the header would be redundant. This is why it is not rendered unless we are on mobile.
|
|
6
6
|
|
|
7
|
-
###
|
|
8
|
-
|
|
9
|
-
Use `makeActions` method and create (or use the predefined actions) to build the actions to pass to `ActionsMenu` high level component. The method `makeActions` takes `actions` array as first argument, and `options` as second argument. `options` are then passed to the `actions` component as `props`.
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
const action1 = ({ option1, option2 }) => ({
|
|
13
|
-
name: action1,
|
|
14
|
-
action: (doc, { option3, option4 }) => {}
|
|
15
|
-
Component: ({ onClick, ...props }) => <SomeComponent {...props} onClick={() => onClick({ option3 })}} />
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
const actions = makeActions([action1, action2], { option1, option2 })
|
|
19
|
-
|
|
20
|
-
<ActionsMenu actions={actions} componentsProps={{ actionsItems: { actionOptions: { option4 }} }}
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
#### How to create actions
|
|
7
|
+
### How to create and use actions
|
|
24
8
|
|
|
25
9
|
An action is a simple function that returns an object with specific keys:
|
|
26
10
|
|
|
@@ -33,7 +17,7 @@ An action is a simple function that returns an object with specific keys:
|
|
|
33
17
|
* **Component** : `<func>` – The returned component that manages the display
|
|
34
18
|
|
|
35
19
|
```bash
|
|
36
|
-
const
|
|
20
|
+
const actionExpl = options => ({
|
|
37
21
|
name: 'expl',
|
|
38
22
|
action: () => {},
|
|
39
23
|
disabled: false,
|
|
@@ -43,6 +27,32 @@ const expl = makeActionOptions => ({
|
|
|
43
27
|
})
|
|
44
28
|
```
|
|
45
29
|
|
|
30
|
+
The method `makeActions` takes `actions` array as first argument, and `options` as second argument. `options` are then passed to the `actions` component as `props`.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
const action1 = ({ option1, option2, option5 }) => ({
|
|
34
|
+
name: action1,
|
|
35
|
+
action: (doc, { option3, option4 }) => {}
|
|
36
|
+
Component: ({ onClick, ...props }) => <SomeComponent {...props} onClick={() => onClick({ option3 })}} />
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const actions = makeActions([action1, action2], { option1, option2 })
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then you can use `ActionsItems` to render the actions, and pass options (as simple props) and component (in `component` prop) to be used for rendering.
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
<ActionsItems actions={actions} docs={[file]} component={ActionComponent} option5="" />
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### ActionsMenu with an automatic creation of actions
|
|
49
|
+
|
|
50
|
+
Use `makeActions` method and create (or use the predefined actions) to build the actions to pass to `ActionsMenu`. You can pass options to actions with `componentsProps.actionsItems.actionOptions` prop.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
<ActionsMenu actions={actions} componentsProps={{ actionsItems: { actionOptions: { option4 }} }} />
|
|
54
|
+
```
|
|
55
|
+
|
|
46
56
|
```jsx
|
|
47
57
|
import DemoProvider from 'cozy-ui/docs/components/DemoProvider'
|
|
48
58
|
import DropdownButton from 'cozy-ui/transpiled/react/DropdownButton'
|
|
@@ -125,7 +135,9 @@ const actions = makeActions([ modify, viewInContacts, divider, call, smsTo, emai
|
|
|
125
135
|
</DemoProvider>
|
|
126
136
|
```
|
|
127
137
|
|
|
128
|
-
###
|
|
138
|
+
### ActionsMenu with a manual creation of the actions
|
|
139
|
+
|
|
140
|
+
We don't use `makeActions` here, all actions are created "by hand". This is not the recommanded choice.
|
|
129
141
|
|
|
130
142
|
```jsx
|
|
131
143
|
import DemoProvider from 'cozy-ui/docs/components/DemoProvider'
|
package/react/Viewer/Readme.md
CHANGED
|
@@ -4,12 +4,11 @@ Once rendered, the `Viewer` will take up all the available space in it's contain
|
|
|
4
4
|
|
|
5
5
|
The `Viewer` can display an **information panel** to show additional information about the current file (e.g. whether a file is certified).
|
|
6
6
|
|
|
7
|
-
### ⚠️
|
|
7
|
+
### ⚠️ Requirement
|
|
8
8
|
|
|
9
|
+
* You must have [WebviewIntent Provider](https://github.com/cozy/cozy-libs/blob/b1ad6f5933b463878f641d9fbb63eddd4c45b0d0/packages/cozy-intent/src/view/components/WebviewIntentProvider.tsx#L89) & [CozySharing Provider](https://github.com/cozy/cozy-libs/tree/master/packages/cozy-sharing)
|
|
9
10
|
* In order to download and display the files, it will need a `cozy-client` instance in the React context.
|
|
10
11
|
* To have the panels, the app need to have [cozy-harvest-lib](https://github.com/cozy/cozy-libs/tree/master/packages/cozy-harvest-lib) installed
|
|
11
|
-
* To have a working footer, the app need to have a [CozySharing Provider](https://github.com/cozy/cozy-libs/tree/master/packages/cozy-sharing).
|
|
12
|
-
* If the footer will be used on MobileApp, the app should have this Cordova plugin [4db7f8f#diff-8c7901258747b81ed60cc2d9cbb254344fae11f8a602e56c1ae42d9eef11d318R50](https://github.com/cozy/cozy-ui/commit/4db7f8fba866bffe04d81d42c716a8dea5c50157#diff-8c7901258747b81ed60cc2d9cbb254344fae11f8a602e56c1ae42d9eef11d318R50)
|
|
13
12
|
|
|
14
13
|
### Props
|
|
15
14
|
|
|
@@ -68,6 +67,7 @@ const files = [
|
|
|
68
67
|
{
|
|
69
68
|
_id: 'audio',
|
|
70
69
|
class: 'audio',
|
|
70
|
+
type: 'file',
|
|
71
71
|
name: 'Sample.mp3',
|
|
72
72
|
mime: 'audio/mp3',
|
|
73
73
|
dir_id: 'parent_folder'
|
|
@@ -75,6 +75,7 @@ const files = [
|
|
|
75
75
|
{
|
|
76
76
|
_id: 'slide',
|
|
77
77
|
class: 'slide',
|
|
78
|
+
type: 'file',
|
|
78
79
|
name: 'Slide.pptx',
|
|
79
80
|
mime: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
80
81
|
dir_id: 'parent_folder'
|
|
@@ -82,6 +83,7 @@ const files = [
|
|
|
82
83
|
{
|
|
83
84
|
_id: 'pdf',
|
|
84
85
|
class: 'pdf',
|
|
86
|
+
type: 'file',
|
|
85
87
|
name: 'My vehicle registration.pdf',
|
|
86
88
|
mime: 'application/pdf',
|
|
87
89
|
metadata: {
|
|
@@ -107,6 +109,7 @@ const files = [
|
|
|
107
109
|
{
|
|
108
110
|
_id: 'text',
|
|
109
111
|
class: 'text',
|
|
112
|
+
type: 'file',
|
|
110
113
|
name: 'LoremipsumdolorsitametconsecteturadipiscingelitSednonrisusSuspendisselectustortordignissimsitametadipiscingnecultriciesseddolorCraselementumultricesdiamMaecenasligulamassavariusasempercongueeuismodnonmiProinporttitororcinecnonummymolestieenimesteleifendminonfermentumdiamnislsitameteratDuissemperDuisarcumassascelerisquevitaeconsequatinpretiumaenimPellentesquecongueUtinrisusvolutpatliberopharetratemporCrasvestibulumbibendumauguePraesentegestasleoinpedePraesentblanditodioeuenimPellentesquesedduiutaugueblanditsodalesVestibulumanteipsumprimisinfaucibusorciluctusetultricesposuerecubiliaCuraeAliquamnibhMaurisacmaurissedpedepellentesquefermentumMaecenasadipiscingantenondiamsodaleshendrerit.txt',
|
|
111
114
|
mime: 'text/plain',
|
|
112
115
|
metadata: {
|
|
@@ -120,6 +123,7 @@ const files = [
|
|
|
120
123
|
{
|
|
121
124
|
_id: 'text',
|
|
122
125
|
class: 'text',
|
|
126
|
+
type: 'file',
|
|
123
127
|
name: 'encrypted-example.txt',
|
|
124
128
|
mime: 'text/plain',
|
|
125
129
|
encrypted: true
|
|
@@ -128,6 +132,7 @@ const files = [
|
|
|
128
132
|
{
|
|
129
133
|
_id: 'image',
|
|
130
134
|
class: 'image',
|
|
135
|
+
type: 'file',
|
|
131
136
|
name: 'Demo.jpg',
|
|
132
137
|
mime: 'image/jpg',
|
|
133
138
|
metadata: {
|
|
@@ -143,12 +148,14 @@ const files = [
|
|
|
143
148
|
{
|
|
144
149
|
_id: 'none',
|
|
145
150
|
class: 'unknown',
|
|
151
|
+
type: 'file',
|
|
146
152
|
name: 'Unsupported file type',
|
|
147
153
|
mime: '???/???'
|
|
148
154
|
},
|
|
149
155
|
{
|
|
150
156
|
_id: 'none',
|
|
151
157
|
class: 'unknown',
|
|
158
|
+
type: 'file',
|
|
152
159
|
name: 'Unsupported file type',
|
|
153
160
|
mime: '???/???',
|
|
154
161
|
metadata: {
|
|
@@ -2,8 +2,6 @@ import React, { createRef } from 'react'
|
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import cx from 'classnames'
|
|
4
4
|
|
|
5
|
-
import { WebviewIntentProvider } from 'cozy-intent'
|
|
6
|
-
|
|
7
5
|
import useBreakpoints from '../providers/Breakpoints'
|
|
8
6
|
import { FileDoctype } from '../proptypes'
|
|
9
7
|
import { useExtendI18n } from '../providers/I18n'
|
|
@@ -52,39 +50,37 @@ const ViewerContainer = props => {
|
|
|
52
50
|
}
|
|
53
51
|
|
|
54
52
|
return (
|
|
55
|
-
<
|
|
56
|
-
<
|
|
57
|
-
<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
>
|
|
62
|
-
<
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
componentsProps={componentsPropsWithDefault}
|
|
66
|
-
currentFile={currentFile}
|
|
67
|
-
hasPrevious={hasPrevious}
|
|
68
|
-
hasNext={hasNext}
|
|
69
|
-
validForPanel={validForPanel}
|
|
70
|
-
toolbarRef={toolbarRef}
|
|
71
|
-
>
|
|
72
|
-
{children}
|
|
73
|
-
</Viewer>
|
|
74
|
-
</EncryptedProvider>
|
|
75
|
-
<ViewerInformationsWrapper
|
|
76
|
-
isPublic={isPublic}
|
|
77
|
-
disableFooter={disableFooter}
|
|
78
|
-
validForPanel={validForPanel}
|
|
53
|
+
<AlertProvider>
|
|
54
|
+
<ActionMenuProvider editPathByModelProps={editPathByModelProps}>
|
|
55
|
+
<div
|
|
56
|
+
id="viewer-wrapper"
|
|
57
|
+
className={cx(styles['viewer-wrapper'], className)}
|
|
58
|
+
>
|
|
59
|
+
<EncryptedProvider url={currentURL}>
|
|
60
|
+
<Viewer
|
|
61
|
+
{...rest}
|
|
62
|
+
componentsProps={componentsPropsWithDefault}
|
|
79
63
|
currentFile={currentFile}
|
|
64
|
+
hasPrevious={hasPrevious}
|
|
65
|
+
hasNext={hasNext}
|
|
66
|
+
validForPanel={validForPanel}
|
|
80
67
|
toolbarRef={toolbarRef}
|
|
81
68
|
>
|
|
82
69
|
{children}
|
|
83
|
-
</
|
|
84
|
-
</
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
70
|
+
</Viewer>
|
|
71
|
+
</EncryptedProvider>
|
|
72
|
+
<ViewerInformationsWrapper
|
|
73
|
+
isPublic={isPublic}
|
|
74
|
+
disableFooter={disableFooter}
|
|
75
|
+
validForPanel={validForPanel}
|
|
76
|
+
currentFile={currentFile}
|
|
77
|
+
toolbarRef={toolbarRef}
|
|
78
|
+
>
|
|
79
|
+
{children}
|
|
80
|
+
</ViewerInformationsWrapper>
|
|
81
|
+
</div>
|
|
82
|
+
</ActionMenuProvider>
|
|
83
|
+
</AlertProvider>
|
|
88
84
|
)
|
|
89
85
|
}
|
|
90
86
|
|
|
@@ -1,30 +1,57 @@
|
|
|
1
|
-
import React, { useState, useEffect } from 'react'
|
|
1
|
+
import React, { useState, useEffect, forwardRef } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
|
|
4
|
-
import { useClient } from 'cozy-client'
|
|
5
4
|
import { useWebviewIntent } from 'cozy-intent'
|
|
6
5
|
|
|
7
6
|
import Button from '../../Buttons'
|
|
8
7
|
import IconButton from '../../IconButton'
|
|
9
8
|
import Icon from '../../Icon'
|
|
9
|
+
import ActionsItems, {
|
|
10
|
+
actionsItemsComponentPropTypes
|
|
11
|
+
} from '../../ActionsMenu/ActionsItems'
|
|
10
12
|
import { print } from '../../ActionsMenu/Actions/print'
|
|
13
|
+
import { makeActions } from '../../ActionsMenu/Actions/helpers'
|
|
14
|
+
|
|
15
|
+
const ActionComponent = forwardRef(({ action, variant, onClick }, ref) => {
|
|
16
|
+
const { label, icon } = action
|
|
17
|
+
|
|
18
|
+
if (variant === 'button') {
|
|
19
|
+
return (
|
|
20
|
+
<Button
|
|
21
|
+
ref={ref}
|
|
22
|
+
variant="secondary"
|
|
23
|
+
aria-label={label}
|
|
24
|
+
label={<Icon icon={icon} />}
|
|
25
|
+
onClick={onClick}
|
|
26
|
+
/>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<IconButton
|
|
32
|
+
ref={ref}
|
|
33
|
+
className="u-white"
|
|
34
|
+
aria-label={label}
|
|
35
|
+
onClick={onClick}
|
|
36
|
+
>
|
|
37
|
+
<Icon icon={icon} />
|
|
38
|
+
</IconButton>
|
|
39
|
+
)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
ActionComponent.displayName = 'ActionComponent'
|
|
43
|
+
|
|
44
|
+
ActionComponent.propTypes = {
|
|
45
|
+
...actionsItemsComponentPropTypes,
|
|
46
|
+
variant: PropTypes.oneOf(['default', 'button'])
|
|
47
|
+
}
|
|
11
48
|
|
|
12
49
|
const PrintButton = ({ file, variant }) => {
|
|
13
50
|
const [isPrintAvailable, setIsPrintAvailable] = useState(false)
|
|
14
|
-
const client = useClient()
|
|
15
51
|
const webviewIntent = useWebviewIntent()
|
|
16
|
-
const {
|
|
17
|
-
icon: printIcon,
|
|
18
|
-
label: printLabel,
|
|
19
|
-
action: printAction,
|
|
20
|
-
displayCondition: printDisplayCondition
|
|
21
|
-
} = print()
|
|
22
52
|
|
|
23
53
|
const isPDFDoc = file.mime === 'application/pdf'
|
|
24
|
-
const showPrintButton =
|
|
25
|
-
|
|
26
|
-
const handleClick = async () =>
|
|
27
|
-
await printAction([file], { client, webviewIntent })
|
|
54
|
+
const showPrintButton = isPDFDoc && isPrintAvailable
|
|
28
55
|
|
|
29
56
|
useEffect(() => {
|
|
30
57
|
const init = async () => {
|
|
@@ -39,25 +66,15 @@ const PrintButton = ({ file, variant }) => {
|
|
|
39
66
|
|
|
40
67
|
if (!showPrintButton) return null
|
|
41
68
|
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<Button
|
|
45
|
-
variant="secondary"
|
|
46
|
-
aria-label={printLabel}
|
|
47
|
-
label={<Icon icon={printIcon} />}
|
|
48
|
-
onClick={handleClick}
|
|
49
|
-
/>
|
|
50
|
-
)
|
|
51
|
-
}
|
|
69
|
+
const actions = makeActions([print])
|
|
52
70
|
|
|
53
71
|
return (
|
|
54
|
-
<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
</IconButton>
|
|
72
|
+
<ActionsItems
|
|
73
|
+
docs={[file]}
|
|
74
|
+
actions={actions}
|
|
75
|
+
component={ActionComponent}
|
|
76
|
+
variant={variant}
|
|
77
|
+
/>
|
|
61
78
|
)
|
|
62
79
|
}
|
|
63
80
|
|
|
@@ -13,9 +13,9 @@ import { fetchBlobFileById } from 'cozy-client/dist/models/file'; // Should guar
|
|
|
13
13
|
|
|
14
14
|
var MAX_RESIZE_IMAGE_SIZE = 3840;
|
|
15
15
|
/**
|
|
16
|
-
* Make array of actions
|
|
16
|
+
* Make array of actions and hydrate actions with options
|
|
17
17
|
*
|
|
18
|
-
* @param {Function[]} actions - Array of actions
|
|
18
|
+
* @param {Function[]} actions - Array of actions with associated actions and conditions
|
|
19
19
|
* @param {object} actionOptions - Options that need to be passed on actions
|
|
20
20
|
* @returns {object[]} Array of actions
|
|
21
21
|
*/
|
|
@@ -23,10 +23,10 @@ var MAX_RESIZE_IMAGE_SIZE = 3840;
|
|
|
23
23
|
export var makeActions = function makeActions() {
|
|
24
24
|
var actions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
25
25
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
26
|
-
return actions.filter(Boolean).map(function (
|
|
27
|
-
var
|
|
28
|
-
var name =
|
|
29
|
-
return _defineProperty({}, name,
|
|
26
|
+
return actions.filter(Boolean).map(function (actionFn) {
|
|
27
|
+
var action = actionFn(options);
|
|
28
|
+
var name = action.name || actionFn.name;
|
|
29
|
+
return _defineProperty({}, name, action);
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
32
|
export var getActionName = function getActionName(actionObject) {
|
|
@@ -57,7 +57,7 @@ export var getOnlyNeededActions = function getOnlyNeededActions(actions, docs) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
return actionObject;
|
|
60
|
-
}).filter(Boolean) // We don't want to have an hr as the latest actions available
|
|
60
|
+
}).filter(Boolean) // We don't want to have an hr/divider as the latest actions available
|
|
61
61
|
.filter(function (cleanedAction, idx, cleanedActions) {
|
|
62
62
|
return !((getActionName(cleanedAction) === 'hr' || getActionName(cleanedAction) === 'divider') && idx === cleanedActions.length - 1);
|
|
63
63
|
});
|
|
@@ -71,4 +71,11 @@ ActionsItems.propTypes = {
|
|
|
71
71
|
/** The overrideClick function from ActionsMenuWrapper */
|
|
72
72
|
onClick: PropTypes.func
|
|
73
73
|
};
|
|
74
|
+
export var actionsItemsComponentPropTypes = {
|
|
75
|
+
docs: PropTypes.array,
|
|
76
|
+
action: PropTypes.object,
|
|
77
|
+
autoFocus: PropTypes.bool,
|
|
78
|
+
disabled: PropTypes.bool,
|
|
79
|
+
onClick: PropTypes.func
|
|
80
|
+
};
|
|
74
81
|
export default ActionsItems;
|
|
@@ -11,7 +11,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
11
11
|
import React, { createRef } from 'react';
|
|
12
12
|
import PropTypes from 'prop-types';
|
|
13
13
|
import cx from 'classnames';
|
|
14
|
-
import { WebviewIntentProvider } from 'cozy-intent';
|
|
15
14
|
import useBreakpoints from "cozy-ui/transpiled/react/providers/Breakpoints";
|
|
16
15
|
import { FileDoctype } from "cozy-ui/transpiled/react/proptypes";
|
|
17
16
|
import { useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n";
|
|
@@ -64,7 +63,7 @@ var ViewerContainer = function ViewerContainer(props) {
|
|
|
64
63
|
}, componentsProps === null || componentsProps === void 0 ? void 0 : componentsProps.toolbarProps)
|
|
65
64
|
});
|
|
66
65
|
|
|
67
|
-
return /*#__PURE__*/React.createElement(
|
|
66
|
+
return /*#__PURE__*/React.createElement(AlertProvider, null, /*#__PURE__*/React.createElement(ActionMenuProvider, {
|
|
68
67
|
editPathByModelProps: editPathByModelProps
|
|
69
68
|
}, /*#__PURE__*/React.createElement("div", {
|
|
70
69
|
id: "viewer-wrapper",
|
|
@@ -84,7 +83,7 @@ var ViewerContainer = function ViewerContainer(props) {
|
|
|
84
83
|
validForPanel: validForPanel,
|
|
85
84
|
currentFile: currentFile,
|
|
86
85
|
toolbarRef: toolbarRef
|
|
87
|
-
}, children))))
|
|
86
|
+
}, children))));
|
|
88
87
|
};
|
|
89
88
|
|
|
90
89
|
ViewerContainer.propTypes = {
|
|
@@ -1,111 +1,113 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
-
|
|
5
|
+
|
|
6
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
+
|
|
8
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
9
|
+
|
|
10
|
+
import React, { useState, useEffect, forwardRef } from 'react';
|
|
5
11
|
import PropTypes from 'prop-types';
|
|
6
|
-
import { useClient } from 'cozy-client';
|
|
7
12
|
import { useWebviewIntent } from 'cozy-intent';
|
|
8
13
|
import Button from "cozy-ui/transpiled/react/Buttons";
|
|
9
14
|
import IconButton from "cozy-ui/transpiled/react/IconButton";
|
|
10
15
|
import Icon from "cozy-ui/transpiled/react/Icon";
|
|
16
|
+
import ActionsItems, { actionsItemsComponentPropTypes } from "cozy-ui/transpiled/react/ActionsMenu/ActionsItems";
|
|
11
17
|
import { print } from "cozy-ui/transpiled/react/ActionsMenu/Actions/print";
|
|
18
|
+
import { makeActions } from "cozy-ui/transpiled/react/ActionsMenu/Actions/helpers";
|
|
19
|
+
var ActionComponent = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
20
|
+
var action = _ref.action,
|
|
21
|
+
variant = _ref.variant,
|
|
22
|
+
onClick = _ref.onClick;
|
|
23
|
+
var label = action.label,
|
|
24
|
+
icon = action.icon;
|
|
25
|
+
|
|
26
|
+
if (variant === 'button') {
|
|
27
|
+
return /*#__PURE__*/React.createElement(Button, {
|
|
28
|
+
ref: ref,
|
|
29
|
+
variant: "secondary",
|
|
30
|
+
"aria-label": label,
|
|
31
|
+
label: /*#__PURE__*/React.createElement(Icon, {
|
|
32
|
+
icon: icon
|
|
33
|
+
}),
|
|
34
|
+
onClick: onClick
|
|
35
|
+
});
|
|
36
|
+
}
|
|
12
37
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
38
|
+
return /*#__PURE__*/React.createElement(IconButton, {
|
|
39
|
+
ref: ref,
|
|
40
|
+
className: "u-white",
|
|
41
|
+
"aria-label": label,
|
|
42
|
+
onClick: onClick
|
|
43
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
44
|
+
icon: icon
|
|
45
|
+
}));
|
|
46
|
+
});
|
|
47
|
+
ActionComponent.displayName = 'ActionComponent';
|
|
48
|
+
ActionComponent.propTypes = _objectSpread(_objectSpread({}, actionsItemsComponentPropTypes), {}, {
|
|
49
|
+
variant: PropTypes.oneOf(['default', 'button'])
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
var PrintButton = function PrintButton(_ref2) {
|
|
53
|
+
var file = _ref2.file,
|
|
54
|
+
variant = _ref2.variant;
|
|
16
55
|
|
|
17
56
|
var _useState = useState(false),
|
|
18
57
|
_useState2 = _slicedToArray(_useState, 2),
|
|
19
58
|
isPrintAvailable = _useState2[0],
|
|
20
59
|
setIsPrintAvailable = _useState2[1];
|
|
21
60
|
|
|
22
|
-
var client = useClient();
|
|
23
61
|
var webviewIntent = useWebviewIntent();
|
|
24
|
-
|
|
25
|
-
var _print = print(),
|
|
26
|
-
printIcon = _print.icon,
|
|
27
|
-
printLabel = _print.label,
|
|
28
|
-
printAction = _print.action,
|
|
29
|
-
printDisplayCondition = _print.displayCondition;
|
|
30
|
-
|
|
31
62
|
var isPDFDoc = file.mime === 'application/pdf';
|
|
32
|
-
var showPrintButton =
|
|
33
|
-
|
|
34
|
-
var handleClick = /*#__PURE__*/function () {
|
|
35
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
36
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
37
|
-
while (1) {
|
|
38
|
-
switch (_context.prev = _context.next) {
|
|
39
|
-
case 0:
|
|
40
|
-
_context.next = 2;
|
|
41
|
-
return printAction([file], {
|
|
42
|
-
client: client,
|
|
43
|
-
webviewIntent: webviewIntent
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
case 2:
|
|
47
|
-
return _context.abrupt("return", _context.sent);
|
|
48
|
-
|
|
49
|
-
case 3:
|
|
50
|
-
case "end":
|
|
51
|
-
return _context.stop();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}, _callee);
|
|
55
|
-
}));
|
|
56
|
-
|
|
57
|
-
return function handleClick() {
|
|
58
|
-
return _ref2.apply(this, arguments);
|
|
59
|
-
};
|
|
60
|
-
}();
|
|
61
|
-
|
|
63
|
+
var showPrintButton = isPDFDoc && isPrintAvailable;
|
|
62
64
|
useEffect(function () {
|
|
63
65
|
var init = /*#__PURE__*/function () {
|
|
64
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
66
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
65
67
|
var _yield$webviewIntent$;
|
|
66
68
|
|
|
67
69
|
var isAvailable;
|
|
68
|
-
return _regeneratorRuntime.wrap(function
|
|
70
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
69
71
|
while (1) {
|
|
70
|
-
switch (
|
|
72
|
+
switch (_context.prev = _context.next) {
|
|
71
73
|
case 0:
|
|
72
|
-
|
|
74
|
+
_context.next = 2;
|
|
73
75
|
return webviewIntent === null || webviewIntent === void 0 ? void 0 : webviewIntent.call('isAvailable', 'print');
|
|
74
76
|
|
|
75
77
|
case 2:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
_context.t1 = _yield$webviewIntent$ = _context.sent;
|
|
79
|
+
_context.t0 = _context.t1 !== null;
|
|
78
80
|
|
|
79
|
-
if (!
|
|
80
|
-
|
|
81
|
+
if (!_context.t0) {
|
|
82
|
+
_context.next = 6;
|
|
81
83
|
break;
|
|
82
84
|
}
|
|
83
85
|
|
|
84
|
-
|
|
86
|
+
_context.t0 = _yield$webviewIntent$ !== void 0;
|
|
85
87
|
|
|
86
88
|
case 6:
|
|
87
|
-
if (!
|
|
88
|
-
|
|
89
|
+
if (!_context.t0) {
|
|
90
|
+
_context.next = 10;
|
|
89
91
|
break;
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
_context.t2 = _yield$webviewIntent$;
|
|
95
|
+
_context.next = 11;
|
|
94
96
|
break;
|
|
95
97
|
|
|
96
98
|
case 10:
|
|
97
|
-
|
|
99
|
+
_context.t2 = true;
|
|
98
100
|
|
|
99
101
|
case 11:
|
|
100
|
-
isAvailable =
|
|
102
|
+
isAvailable = _context.t2;
|
|
101
103
|
setIsPrintAvailable(isAvailable);
|
|
102
104
|
|
|
103
105
|
case 13:
|
|
104
106
|
case "end":
|
|
105
|
-
return
|
|
107
|
+
return _context.stop();
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
|
-
},
|
|
110
|
+
}, _callee);
|
|
109
111
|
}));
|
|
110
112
|
|
|
111
113
|
return function init() {
|
|
@@ -116,25 +118,13 @@ var PrintButton = function PrintButton(_ref) {
|
|
|
116
118
|
init();
|
|
117
119
|
}, [webviewIntent]);
|
|
118
120
|
if (!showPrintButton) return null;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}),
|
|
127
|
-
onClick: handleClick
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return /*#__PURE__*/React.createElement(IconButton, {
|
|
132
|
-
className: "u-white",
|
|
133
|
-
"aria-label": printLabel,
|
|
134
|
-
onClick: handleClick
|
|
135
|
-
}, /*#__PURE__*/React.createElement(Icon, {
|
|
136
|
-
icon: printIcon
|
|
137
|
-
}));
|
|
121
|
+
var actions = makeActions([print]);
|
|
122
|
+
return /*#__PURE__*/React.createElement(ActionsItems, {
|
|
123
|
+
docs: [file],
|
|
124
|
+
actions: actions,
|
|
125
|
+
component: ActionComponent,
|
|
126
|
+
variant: variant
|
|
127
|
+
});
|
|
138
128
|
};
|
|
139
129
|
|
|
140
130
|
PrintButton.propTypes = {
|