cozy-ui 117.3.0 → 118.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 CHANGED
@@ -1,3 +1,17 @@
1
+ # [118.0.0](https://github.com/cozy/cozy-ui/compare/v117.3.0...v118.0.0) (2025-03-07)
2
+
3
+
4
+ ### Features
5
+
6
+ * Migrate date formatting to es module ([9d4ab11](https://github.com/cozy/cozy-ui/commit/9d4ab11))
7
+ * Migrate to es module ([b677678](https://github.com/cozy/cozy-ui/commit/b677678))
8
+ * Remove tracking API ([a2dade9](https://github.com/cozy/cozy-ui/commit/a2dade9))
9
+
10
+
11
+ ### BREAKING CHANGES
12
+
13
+ * 'cozy-ui/transpiled/react/helpers/tracker' endpoint has been removed. It was unused since we removed Piwik. You can safely delete the code.
14
+
1
15
  # [117.3.0](https://github.com/cozy/cozy-ui/compare/v117.2.2...v117.3.0) (2025-02-20)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "117.3.0",
3
+ "version": "118.0.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -173,7 +173,6 @@
173
173
  "node-polyglot": "^2.5.0",
174
174
  "normalize.css": "^8.0.0",
175
175
  "pdf-lib": "1.17.1",
176
- "piwik-react-router": "0.12.1",
177
176
  "react-chartjs-2": "4.1.0",
178
177
  "react-markdown": "^4.0.8",
179
178
  "react-popper": "^2.2.3",
@@ -1,5 +1,2 @@
1
- module.exports = () => {
2
- return (
3
- navigator && navigator.userAgent && navigator.userAgent.includes('Argos')
4
- )
5
- }
1
+ export default () =>
2
+ navigator && navigator.userAgent && navigator.userAgent.includes('Argos')
package/react/palette.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // GENERATED AUTOMATICALLY FROM stylus/settings/palette.json
2
- module.exports = {
2
+ export default {
3
3
  black: 'var(--black)',
4
4
  white: 'var(--white)',
5
5
  paleGrey: 'var(--paleGrey)',
@@ -1,50 +1,47 @@
1
1
  import format from 'date-fns/format'
2
2
  import formatDistanceToNow from 'date-fns/formatDistanceToNow'
3
+ import {
4
+ enGB as enLocale,
5
+ fr as frLocale,
6
+ es as esLocale
7
+ } from 'date-fns/locale'
3
8
 
4
9
  import { DEFAULT_LANG } from '.'
5
10
 
6
- const locales = {}
7
- let lang = DEFAULT_LANG
11
+ let currentLocale
8
12
 
9
- /**
10
- * Ensure that the locale is in the correct format for date-fns (see 2.0.0 BC https://github.com/date-fns/date-fns/blob/main/CHANGELOG.md#200---2019-08-20)
11
- * @param {string} lang
12
- */
13
- const ensureLocaleFormat = lang => {
13
+ const getDateFnsLocale = lang => {
14
14
  switch (lang) {
15
15
  case 'en':
16
- return 'en-US'
17
- case 'zh_cn':
18
- return 'zh-CN'
19
- case 'zh_tw':
20
- return 'zh-TW'
16
+ return enLocale
17
+ case 'fr':
18
+ return frLocale
19
+ case 'es':
20
+ return esLocale
21
21
  default:
22
- return lang
22
+ throw new Error('Locale not found')
23
23
  }
24
24
  }
25
25
 
26
26
  const getWarningMessage = lang =>
27
- `The "${lang}" locale isn't supported by date-fns. or has not been included in the build. Check if you have configured a ContextReplacementPlugin that is too restrictive.`
27
+ `The "${lang}" locale isn't supported by date-fns or has not been included in the build. Check if you have configured a ContextReplacementPlugin that is too restrictive.`
28
28
 
29
29
  export const provideDateFnsLocale = (userLang, defaultLang = DEFAULT_LANG) => {
30
- lang = ensureLocaleFormat(userLang)
31
- const ensureDefaultLang = ensureLocaleFormat(defaultLang)
32
30
  try {
33
- locales[
34
- ensureDefaultLang
35
- ] = require(`date-fns/locale/${ensureDefaultLang}/index.js`)
36
- } catch (err) {
37
- console.warn(getWarningMessage(ensureDefaultLang))
31
+ const userLocale = getDateFnsLocale(userLang)
32
+ currentLocale = userLocale
33
+ return userLocale
34
+ } catch (e) {
35
+ console.warn(getWarningMessage(userLang))
38
36
  }
39
37
 
40
- if (lang && lang !== ensureDefaultLang) {
41
- try {
42
- locales[lang] = require(`date-fns/locale/${lang}/index.js`)
43
- } catch (e) {
44
- console.warn(getWarningMessage(lang))
45
- }
38
+ try {
39
+ const defaultLocale = getDateFnsLocale(defaultLang)
40
+ currentLocale = defaultLocale
41
+ return defaultLocale
42
+ } catch (err) {
43
+ console.warn(getWarningMessage(defaultLang))
46
44
  }
47
- return locales[lang]
48
45
  }
49
46
 
50
47
  export const initFormat =
@@ -61,5 +58,5 @@ export const initFormat =
61
58
  }
62
59
 
63
60
  export const formatLocallyDistanceToNow = date => {
64
- return formatDistanceToNow(date, { locale: locales[lang] })
61
+ return formatDistanceToNow(date, { locale: currentLocale })
65
62
  }
@@ -4,9 +4,11 @@ describe('initFormat', () => {
4
4
  beforeEach(() => {
5
5
  jest.spyOn(console, 'warn').mockImplementation(() => {})
6
6
  })
7
+
7
8
  afterEach(() => {
8
9
  console.warn.mockRestore()
9
10
  })
11
+
10
12
  it('should not throw if a date-fns locale can not be found', () => {
11
13
  expect(() => initFormat('unknown-lang', 'unknown-default')).not.toThrow()
12
14
  })
@@ -17,7 +19,13 @@ describe('initFormat', () => {
17
19
  expect(date).toBe('1970-janvier-01')
18
20
  })
19
21
 
20
- it('should fallback english if a date-fns locale can not be found', () => {
22
+ it('should use the correct default locale if user locale can not be found', () => {
23
+ const f = initFormat('it', 'fr')
24
+ const date = f(0, 'yyyy-LLLL-dd')
25
+ expect(date).toBe('1970-janvier-01')
26
+ })
27
+
28
+ it('should fallback english if user locale and default locale can not be found', () => {
21
29
  const f = initFormat('unknown-lang', 'unknown-default')
22
30
  const date = f(0, 'yyyy-LLLL-dd')
23
31
  expect(date).toBe('1970-January-01')
@@ -25,6 +33,12 @@ describe('initFormat', () => {
25
33
  })
26
34
 
27
35
  describe('formatLocallyDistanceToNow', () => {
36
+ beforeEach(() => {
37
+ // To avoid currentLocale set to 'fr' because of previous tests
38
+ const f = initFormat('en')
39
+ f(0, 'yyyy-LLLL-dd')
40
+ })
41
+
28
42
  it('should formatDistanceToNow with small value', () => {
29
43
  const date = Date.now() + 29 * 1000 // 29s
30
44
 
@@ -10,4 +10,4 @@ echo "Making icon sprite, output file : ${outfile}..."
10
10
  echo $icons | xargs yarn svgstore --inline -o /tmp/icons-sprite.svg
11
11
  echo "// GENERATED FILE, DO NOT EDIT THIS FILE BY HAND" > $outfile
12
12
  echo "// Use yarn sprite to regenerate" >> $outfile
13
- echo "module.exports = \``cat /tmp/icons-sprite.svg`\`" >> $outfile
13
+ echo "export default \``cat /tmp/icons-sprite.svg`\`" >> $outfile
@@ -7,5 +7,5 @@ JS_PALETTE='react/palette.js'
7
7
 
8
8
  echo "Making palette, output file : ${JS_PALETTE}..."
9
9
  echo "// GENERATED AUTOMATICALLY FROM stylus/settings/palette.json" > $JS_PALETTE
10
- echo "module.exports = `cat stylus/settings/palette.json`" >> $JS_PALETTE
10
+ echo "export default `cat stylus/settings/palette.json`" >> $JS_PALETTE
11
11
  node_modules/.bin/eslint --fix $JS_PALETTE