cozy-ui 90.1.0 → 90.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
+ # [90.2.0](https://github.com/cozy/cozy-ui/compare/v90.1.0...v90.2.0) (2023-07-31)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **Viewer:** Success alert for copied item is now with a success style ([f934e3c](https://github.com/cozy/cozy-ui/commit/f934e3c))
7
+
8
+
9
+ ### Features
10
+
11
+ * Add copy-text-to-clipboard 3.2.0 package ([c79456f](https://github.com/cozy/cozy-ui/commit/c79456f))
12
+ * Replace navigator.clipboard by copy-text-to-clipboard ([2884a37](https://github.com/cozy/cozy-ui/commit/2884a37))
13
+
1
14
  # [90.1.0](https://github.com/cozy/cozy-ui/compare/v90.0.0...v90.1.0) (2023-07-26)
2
15
 
3
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "90.1.0",
3
+ "version": "90.2.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -161,6 +161,7 @@
161
161
  "bundlemon": "^1.3.2",
162
162
  "chart.js": "3.7.1",
163
163
  "classnames": "^2.2.5",
164
+ "copy-text-to-clipboard": "3.2.0",
164
165
  "cozy-interapp": "^0.5.4",
165
166
  "date-fns": "^1.28.5",
166
167
  "filesize": "8.0.7",
@@ -279,116 +279,3 @@ import FiletypeTextIcon from 'cozy-ui/transpiled/react/Icons/FileTypeText'
279
279
  </ListItem>
280
280
  </List>
281
281
  ```
282
-
283
- ### Contextualized item
284
-
285
- ```jsx
286
- import { BreakpointsProvider } from 'cozy-ui/transpiled/react/hooks/useBreakpoints'
287
- import List from 'cozy-ui/transpiled/react/List'
288
- import ListItemByDoc from 'cozy-ui/transpiled/react/ListItem/ListItemByDoc'
289
- import ListItem from 'cozy-ui/transpiled/react/ListItem'
290
- import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
291
- import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
292
- import Icon from 'cozy-ui/transpiled/react/Icon'
293
- import Divider from 'cozy-ui/transpiled/react/Divider'
294
- import FiletypeTextIcon from 'cozy-ui/transpiled/react/Icons/FileTypeText'
295
- import DemoProvider from 'cozy-ui/docs/components/DemoProvider'
296
-
297
- const mockClient = {
298
- plugins: {
299
- realtime: {
300
- subscribe: () => {},
301
- unsubscribe: () => {},
302
- unsubscribeAll: () => {}
303
- }
304
- },
305
- getStackClient: () => ({
306
- uri: 'https://cozy.io/'
307
- }),
308
- getInstanceOptions: () => ({
309
- subdomain: ''
310
- })
311
- }
312
-
313
- const contacts = [
314
- {
315
- _id: 'id01',
316
- _type: 'io.cozy.contacts',
317
- displayName: 'John Doe',
318
- birthday: '25/10/2022',
319
- email: [{ address: 'johndoe@cozy.cc', primary: true }],
320
- phone: [{ number: '0102030405', primary: true }]
321
- },
322
- {
323
- _id: 'id02',
324
- _type: 'io.cozy.contacts',
325
- displayName: 'Jason Bourne',
326
- birthday: '01/01/2020',
327
- email: [{ address: 'jbourne@cozy.cc', primary: true }]
328
- }
329
- ]
330
-
331
- const files = [
332
- {
333
- _type: 'io.cozy.files',
334
- name: 'File01.pdf',
335
- metadata: {
336
- number: 12345,
337
- qualification: {
338
- label: 'driver_license'
339
- }
340
- }
341
- },
342
- {
343
- _type: 'io.cozy.files',
344
- type: 'file',
345
- name: 'Note01.cozy-note',
346
- metadata: {
347
- title: 'note title',
348
- version: 0
349
- }
350
- }
351
- ]
352
-
353
- ;
354
-
355
- <DemoProvider client={mockClient}>
356
- <List>
357
- <ListItem button>
358
- <ListItemIcon>
359
- <Icon icon={FiletypeTextIcon} width="32" height="32" />
360
- </ListItemIcon>
361
- <ListItemText primary="I'm a standard item" />
362
- </ListItem>
363
- <Divider variant="inset" />
364
- <ListItemByDoc
365
- doc={contacts[0]}
366
- expandedAttributesProps={{ isExpandedAttributesActive: true, expandedAttributes: ['email', 'birthday'] }}
367
- onClick={() => {}}
368
- />
369
- <Divider variant="inset" />
370
- <ListItemByDoc
371
- doc={contacts[1]}
372
- onClick={() => {}}
373
- />
374
- <Divider variant="inset" />
375
- <ListItemByDoc
376
- doc={files[0]}
377
- expandedAttributesProps={{ isExpandedAttributesActive: true, expandedAttributes: ['metadata.number'] }}
378
- onClick={() => {}}
379
- />
380
- <Divider variant="inset" />
381
- <ListItemByDoc
382
- doc={files[1]}
383
- onClick={() => {}}
384
- />
385
- <Divider variant="inset" />
386
- <ListItem button>
387
- <ListItemIcon>
388
- <Icon icon={FiletypeTextIcon} width="32" height="32" />
389
- </ListItemIcon>
390
- <ListItemText primary="I'm a standard item" />
391
- </ListItem>
392
- </List>
393
- </DemoProvider>
394
- ```
@@ -1,4 +1,5 @@
1
1
  import get from 'lodash/get'
2
+ import copy from 'copy-text-to-clipboard'
2
3
 
3
4
  import { formatDate } from '../../Viewer/helpers'
4
5
 
@@ -67,9 +68,8 @@ export const makeDefaultExpandedAttributes = (doc, expandedAttributes) => {
67
68
  }
68
69
 
69
70
  export const copyToClipboard = ({ value, setAlertProps, t }) => () => {
70
- if (navigator?.clipboard) {
71
- navigator.clipboard.writeText(value)
72
-
71
+ const hasCopied = copy(value)
72
+ if (hasCopied) {
73
73
  setAlertProps({
74
74
  open: true,
75
75
  severity: 'success',
@@ -7,6 +7,8 @@ import {
7
7
  import { I18nContext } from '../../jestLib/I18n'
8
8
  import en from '../locales/en'
9
9
 
10
+ jest.mock('copy-text-to-clipboard', () => ({ copy: jest.fn() }))
11
+
10
12
  const i18nContext = I18nContext({
11
13
  locale: en
12
14
  })
@@ -97,3 +97,103 @@ const initialVariants = [{
97
97
  }}
98
98
  </Variants>
99
99
  ```
100
+
101
+ ### Contextualized items
102
+
103
+ ```jsx
104
+ import { BreakpointsProvider } from 'cozy-ui/transpiled/react/hooks/useBreakpoints'
105
+ import List from 'cozy-ui/transpiled/react/List'
106
+ import ListItemByDoc from 'cozy-ui/transpiled/react/ListItem/ListItemByDoc'
107
+ import ListItem from 'cozy-ui/transpiled/react/ListItem'
108
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
109
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
110
+ import Icon from 'cozy-ui/transpiled/react/Icon'
111
+ import Divider from 'cozy-ui/transpiled/react/Divider'
112
+ import FiletypeTextIcon from 'cozy-ui/transpiled/react/Icons/FileTypeText'
113
+ import DemoProvider from 'cozy-ui/docs/components/DemoProvider'
114
+
115
+ const mockClient = {
116
+ plugins: {
117
+ realtime: {
118
+ subscribe: () => {},
119
+ unsubscribe: () => {},
120
+ unsubscribeAll: () => {}
121
+ }
122
+ },
123
+ getStackClient: () => ({
124
+ uri: 'https://cozy.io/'
125
+ }),
126
+ getInstanceOptions: () => ({
127
+ subdomain: ''
128
+ })
129
+ }
130
+
131
+ const contacts = [
132
+ {
133
+ _id: 'id01',
134
+ _type: 'io.cozy.contacts',
135
+ displayName: 'John Doe',
136
+ birthday: '25/10/2022',
137
+ email: [{ address: 'johndoe@cozy.cc', primary: true }],
138
+ phone: [{ number: '0102030405', primary: true }]
139
+ },
140
+ {
141
+ _id: 'id02',
142
+ _type: 'io.cozy.contacts',
143
+ displayName: 'Jason Bourne',
144
+ birthday: '01/01/2020',
145
+ email: [{ address: 'jbourne@cozy.cc', primary: true }]
146
+ }
147
+ ]
148
+
149
+ const files = [
150
+ {
151
+ _type: 'io.cozy.files',
152
+ name: 'File01.pdf',
153
+ metadata: {
154
+ number: 12345,
155
+ qualification: {
156
+ label: 'driver_license'
157
+ }
158
+ }
159
+ },
160
+ {
161
+ _type: 'io.cozy.files',
162
+ type: 'file',
163
+ name: 'Note01.cozy-note',
164
+ metadata: {
165
+ title: 'note title',
166
+ version: 0
167
+ }
168
+ }
169
+ ]
170
+
171
+ ;
172
+
173
+ <DemoProvider client={mockClient}>
174
+ <List>
175
+ <ListItemByDoc
176
+ doc={contacts[0]}
177
+ expandedAttributesProps={{
178
+ isExpandedAttributesActive: true,
179
+ expandedAttributes: ['email', 'birthday']
180
+ }}
181
+ onClick={() => {}}
182
+ />
183
+ <Divider variant="inset" />
184
+ <ListItemByDoc
185
+ doc={files[0]}
186
+ expandedAttributesProps={{
187
+ isExpandedAttributesActive: true,
188
+ expandedAttributes: ['metadata.number']
189
+ }}
190
+ onClick={() => {}}
191
+ />
192
+ <Divider variant="inset" />
193
+ <ListItemByDoc
194
+ doc={files[1]}
195
+ onClick={() => {}}
196
+ />
197
+ </List>
198
+ </DemoProvider>
199
+ ```
@@ -1,5 +1,6 @@
1
1
  import React, { forwardRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
+ import copy from 'copy-text-to-clipboard'
3
4
 
4
5
  import { useAppLinkWithStoreFallback, useClient } from 'cozy-client'
5
6
 
@@ -40,10 +41,10 @@ const ActionMenuWrapper = forwardRef(({ onClose, file, optionFile }, ref) => {
40
41
  const isAppLinkLoaded = fetchStatus === 'loaded'
41
42
 
42
43
  const handleCopy = () => {
43
- if (navigator?.clipboard) {
44
- navigator.clipboard.writeText(value)
44
+ const hasCopied = copy(value)
45
+ if (hasCopied) {
45
46
  showViewerSnackbar(
46
- 'secondary',
47
+ 'success',
47
48
  t(`Viewer.snackbar.copiedToClipboard.success`)
48
49
  )
49
50
  } else {
@@ -4,6 +4,8 @@ jest.mock('cozy-harvest-lib/dist/components/KonnectorBlock', () => jest.fn())
4
4
  const block1Component = jest.fn()
5
5
  const block2Component = jest.fn()
6
6
 
7
+ jest.mock('copy-text-to-clipboard', () => ({ copy: jest.fn() }))
8
+
7
9
  describe('getPanelBlocks', () => {
8
10
  it('should return only blocks with truthy condition', () => {
9
11
  // with two truthy component
@@ -1,4 +1,5 @@
1
1
  import get from 'lodash/get';
2
+ import copy from 'copy-text-to-clipboard';
2
3
  import { formatDate } from "cozy-ui/transpiled/react/Viewer/helpers";
3
4
  export var normalizeExpandedAttribute = function normalizeExpandedAttribute(attr) {
4
5
  return attr.replaceAll(':', '.').replace('flexsearchProps.', '').replace('translated.', '');
@@ -38,10 +39,9 @@ export var copyToClipboard = function copyToClipboard(_ref) {
38
39
  setAlertProps = _ref.setAlertProps,
39
40
  t = _ref.t;
40
41
  return function () {
41
- var _navigator;
42
+ var hasCopied = copy(value);
42
43
 
43
- if ((_navigator = navigator) !== null && _navigator !== void 0 && _navigator.clipboard) {
44
- navigator.clipboard.writeText(value);
44
+ if (hasCopied) {
45
45
  setAlertProps({
46
46
  open: true,
47
47
  severity: 'success',
@@ -1,5 +1,6 @@
1
1
  import React, { forwardRef } from 'react';
2
2
  import PropTypes from 'prop-types';
3
+ import copy from 'copy-text-to-clipboard';
3
4
  import { useAppLinkWithStoreFallback, useClient } from 'cozy-client';
4
5
  import useBreakpoints from "cozy-ui/transpiled/react/hooks/useBreakpoints";
5
6
  import { useI18n } from "cozy-ui/transpiled/react/I18n";
@@ -37,11 +38,10 @@ var ActionMenuWrapper = /*#__PURE__*/forwardRef(function (_ref, ref) {
37
38
  var isAppLinkLoaded = fetchStatus === 'loaded';
38
39
 
39
40
  var handleCopy = function handleCopy() {
40
- var _navigator;
41
+ var hasCopied = copy(value);
41
42
 
42
- if ((_navigator = navigator) !== null && _navigator !== void 0 && _navigator.clipboard) {
43
- navigator.clipboard.writeText(value);
44
- showViewerSnackbar('secondary', t("Viewer.snackbar.copiedToClipboard.success"));
43
+ if (hasCopied) {
44
+ showViewerSnackbar('success', t("Viewer.snackbar.copiedToClipboard.success"));
45
45
  } else {
46
46
  showViewerSnackbar('error', t("Viewer.snackbar.copiedToClipboard.error"));
47
47
  }