@homecode/ui 5.20.16 → 5.20.17

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/dist/esm/index.js CHANGED
@@ -15,7 +15,7 @@ export { getDisplayContent, getDisplayParts, isPlanMessageContent, parseSystemEv
15
15
  export { Container } from './src/components/Container/Container.js';
16
16
  export { DatePicker } from './src/components/DatePicker/DatePicker.js';
17
17
  export { DatePickerInput } from './src/components/DatePickerInput/DatePickerInput.js';
18
- export { DateTime, formatDate } from './src/components/DateTime/DateTime.js';
18
+ export { DateTime, formatDate, toMomentLocale } from './src/components/DateTime/DateTime.js';
19
19
  export { Dialogue } from './src/components/Dialogue/Dialogue.js';
20
20
  export { Draggable } from './src/components/Draggable/Draggable.js';
21
21
  export { DropZone } from './src/components/DropZone/DropZone.js';
@@ -45,6 +45,7 @@ import '../Chat/ChatView.styl.js';
45
45
  import '../Container/Container.js';
46
46
  import '../DatePicker/DatePicker.styl.js';
47
47
  import 'moment';
48
+ import '../../services/i18n.js';
48
49
  import '../DatePickerInput/DatePickerInput.styl.js';
49
50
  import '../Dialogue/Dialogue.js';
50
51
  import '../../tools/queryParams.js';
@@ -70,7 +71,6 @@ import '@tiptap/extension-mention';
70
71
  import '@tiptap/pm/state';
71
72
  import '@tiptap/react';
72
73
  import '../../tiptap/slash-mention/SlashSuggestionList.styl.js';
73
- import '../../services/i18n.js';
74
74
  import '../LightBox/LightBox.styl.js';
75
75
  import '../NestedMenu/NestedMenu.js';
76
76
  import '../Notifications/store.js';
@@ -1,8 +1,25 @@
1
1
  import { jsx, Fragment } from 'react/jsx-runtime';
2
2
  import moment from 'moment';
3
+ import { useStore } from 'justorm/react';
4
+ import { store } from '../../services/i18n.js';
3
5
 
4
- function formatDate({ value, format, locale = 'en' }) {
5
- const d = moment(value).locale(locale);
6
+ // Only app language codes that differ from moment's locale ids. Any other
7
+ // code (de, fr, ar, th, ...) already is a moment id and is passed through.
8
+ const MOMENT_LOCALE_ALIASES = {
9
+ ua: 'uk',
10
+ jp: 'ja',
11
+ zh: 'zh-cn',
12
+ };
13
+ /** Moment locale id for an app language code ("ua" -> "uk"). */
14
+ function toMomentLocale(lang) {
15
+ if (!lang)
16
+ return 'en';
17
+ const code = lang.toLowerCase();
18
+ return MOMENT_LOCALE_ALIASES[code] ?? code;
19
+ }
20
+ function formatDate({ value, format, locale, }) {
21
+ // Moment keeps English when the locale's data isn't loaded by the app.
22
+ const d = moment(value).locale(locale ?? toMomentLocale(store.lang));
6
23
  if (format) {
7
24
  if (d[format])
8
25
  return d[format]();
@@ -11,7 +28,9 @@ function formatDate({ value, format, locale = 'en' }) {
11
28
  return d.toString();
12
29
  }
13
30
  function DateTime({ value = new Date(), format, locale }) {
31
+ // Re-render on a language switch when no explicit locale is given.
32
+ useStore({ i18n: ['lang'] });
14
33
  return jsx(Fragment, { children: formatDate({ value, format, locale }) });
15
34
  }
16
35
 
17
- export { DateTime, formatDate };
36
+ export { DateTime, formatDate, toMomentLocale };
@@ -48,6 +48,7 @@ import '../Chat/ChatView.styl.js';
48
48
  import '../Container/Container.js';
49
49
  import '../DatePicker/DatePicker.styl.js';
50
50
  import 'moment';
51
+ import '../../services/i18n.js';
51
52
  import '../DatePickerInput/DatePickerInput.styl.js';
52
53
  import '../Dialogue/Dialogue.js';
53
54
  import { Draggable } from '../Draggable/Draggable.js';
@@ -65,7 +66,6 @@ import '../VideoPlayer/VideoPlayer.styl.js';
65
66
  import '../Gallery/Gallery.styl.js';
66
67
  import '../GridLayout/GridLayout.styl.js';
67
68
  import '../Heading/Heading.js';
68
- import '../../services/i18n.js';
69
69
  import '../LightBox/LightBox.styl.js';
70
70
  import '../NestedMenu/NestedMenu.js';
71
71
  import '../Notifications/store.js';
@@ -1,5 +1,5 @@
1
1
  import { jsx, Fragment } from 'react/jsx-runtime';
2
- import { useContext, useEffect, useMemo } from 'react';
2
+ import { useContext, useEffect, useMemo, Children, isValidElement } from 'react';
3
3
  import { useStore } from 'justorm/react';
4
4
  import { parseQueryParams } from '../../tools/queryParams.js';
5
5
  import STORE from './store.js';
@@ -29,8 +29,8 @@ const Router = (props) => {
29
29
  const childs = [];
30
30
  let noMatchRoute;
31
31
  let isRouteMatched = false;
32
- for (const child of React.Children.toArray(children)) {
33
- if (!React.isValidElement(child)) {
32
+ for (const child of Children.toArray(children)) {
33
+ if (!isValidElement(child)) {
34
34
  childs.push(child);
35
35
  continue;
36
36
  }
@@ -1,7 +1,9 @@
1
1
  import * as T from './DateTime.types';
2
- export declare function formatDate({ value, format, locale }: {
3
- value: any;
4
- format: any;
2
+ /** Moment locale id for an app language code ("ua" -> "uk"). */
3
+ export declare function toMomentLocale(lang?: string | null | void): string;
4
+ export declare function formatDate({ value, format, locale, }: {
5
+ value?: T.Props['value'];
6
+ format?: string;
5
7
  locale?: string;
6
8
  }): any;
7
9
  export declare function DateTime({ value, format, locale }: T.Props): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ import 'moment/locale/uk';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homecode/ui",
3
- "version": "5.20.16",
3
+ "version": "5.20.17",
4
4
  "description": "React UI components library",
5
5
  "scripts": {
6
6
  "tests": "jest",