@jetbrains/ring-ui 5.0.138 → 5.0.139

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.
Files changed (37) hide show
  1. package/components/auth/auth__core.js +10 -10
  2. package/components/header/profile.d.ts +2 -53
  3. package/components/header/profile.js +8 -8
  4. package/components/i18n/README.md +43 -0
  5. package/components/i18n/i18n-context.d.ts +12 -53
  6. package/components/i18n/i18n-context.js +14 -3
  7. package/components/i18n/i18n.d.ts +6 -3
  8. package/components/i18n/i18n.js +18 -0
  9. package/components/input/input.js +2 -2
  10. package/components/message/message.js +5 -3
  11. package/components/pager/pager.d.ts +2 -53
  12. package/components/pager/pager.js +9 -8
  13. package/components/query-assist/query-assist.js +5 -5
  14. package/components/select/select.js +3 -3
  15. package/components/select/select__filter.js +1 -1
  16. package/components/user-agreement/user-agreement.js +8 -8
  17. package/components/user-card/card.d.ts +2 -53
  18. package/components/user-card/card.js +13 -11
  19. package/dist/_helpers/card.js +15 -11
  20. package/dist/_helpers/select__filter.js +5 -2
  21. package/dist/auth/auth__core.js +10 -11
  22. package/dist/header/profile.d.ts +2 -53
  23. package/dist/header/profile.js +13 -8
  24. package/dist/i18n/i18n-context.d.ts +12 -53
  25. package/dist/i18n/i18n-context.js +22 -4
  26. package/dist/i18n/i18n.d.ts +6 -3
  27. package/dist/i18n/i18n.js +23 -1
  28. package/dist/input/input.js +32 -26
  29. package/dist/link/link.js +1 -1
  30. package/dist/message/message.js +39 -31
  31. package/dist/pager/pager.d.ts +2 -53
  32. package/dist/pager/pager.js +14 -8
  33. package/dist/query-assist/query-assist.js +90 -81
  34. package/dist/select/select.js +8 -5
  35. package/dist/user-agreement/user-agreement.js +39 -33
  36. package/dist/user-card/card.d.ts +2 -53
  37. package/package.json +14 -14
@@ -63,59 +63,8 @@ export default class UserCard extends PureComponent<UserCardProps> {
63
63
  unverified: PropTypes.Requireable<string>;
64
64
  }>>;
65
65
  };
66
- static contextType: React.Context<{
67
- login: string;
68
- logout: string;
69
- loginTo: string;
70
- ok: string;
71
- cancel: string;
72
- tryAgainLabel: string;
73
- postpone: string;
74
- youHaveLoggedInAs: string;
75
- applyChange: string;
76
- backendIsNotAvailable: string;
77
- checkAgain: string;
78
- nothingHappensLink: string;
79
- errorMessage: string;
80
- applyChangedUser: string;
81
- profile: string;
82
- switchUser: string;
83
- addFirstDate: string;
84
- addSecondDate: string;
85
- addTime: string;
86
- selectName: string;
87
- setDate: string;
88
- setDateTime: string;
89
- setPeriod: string;
90
- clear: string;
91
- gotIt: string;
92
- dismiss: string;
93
- perPage: string;
94
- firstPage: string;
95
- lastPage: string;
96
- nextPage: string;
97
- previousPage: string;
98
- searchTitle: string;
99
- clearTitle: string;
100
- userAgreement: string;
101
- accept: string;
102
- decline: string;
103
- close: string;
104
- scrollToAccept: string;
105
- remindLater: string;
106
- filterItems: string;
107
- selectOption: string;
108
- progress: string;
109
- loading: string;
110
- noOptionsFound: string;
111
- banned: string;
112
- online: string;
113
- offline: string;
114
- copyToClipboard: string;
115
- copiedToClipboard: string;
116
- copingToClipboardError: string;
117
- unverified: string;
118
- }>;
66
+ static contextType: React.Context<import("../i18n/i18n-context").I18nContextProps>;
67
+ context: React.ContextType<typeof UserCard.contextType>;
119
68
  copyEmail: () => void;
120
69
  render(): JSX.Element;
121
70
  }
@@ -39,16 +39,14 @@ class UserCard extends PureComponent {
39
39
  };
40
40
  static contextType = I18nContext;
41
41
  copyEmail = () => {
42
- const messages = this.context;
43
- const messageOverrides = this.props.wording || this.props.translations;
44
- const wording = messageOverrides ?? messages;
45
- clipboard.copyText(this.props.user.email || '', wording.copiedToClipboard, wording.copingToClipboardError);
42
+ const { translate } = this.context;
43
+ const wording = this.props.translations || this.props.wording;
44
+ clipboard.copyText(this.props.user.email || '', wording?.copiedToClipboard ?? translate('copyToClipboard'), wording?.copingToClipboardError ?? translate('copingToClipboardError'));
46
45
  };
47
46
  render() {
48
47
  const { children, info, className, user, avatarInfo, ...restProps } = this.props;
49
- const messages = this.context;
50
- const messageOverrides = this.props.wording || this.props.translations;
51
- const wording = messageOverrides ?? messages;
48
+ const { translate } = this.context;
49
+ const wording = this.props.translations || this.props.wording;
52
50
  const classes = classNames(className, {});
53
51
  const userActiveStatusClasses = classNames(styles.userActiveStatus, user.online ? styles.online : '');
54
52
  return (<div className={classes} {...restProps}>
@@ -65,18 +63,22 @@ class UserCard extends PureComponent {
65
63
  </Link>)}
66
64
  {!user.href && <span className={styles.userName}>{user.name}</span>}
67
65
  {typeof user.online === 'boolean' &&
68
- (<span className={userActiveStatusClasses} title={user.online ? wording.online : wording.offline}/>)}
66
+ (<span className={userActiveStatusClasses} title={user.online
67
+ ? (wording?.online ?? translate('online'))
68
+ : (wording?.offline ?? translate('offline'))}/>)}
69
69
  {!!info && <span className={styles.userNameInfo}>{info}</span>}
70
70
  {user.banned &&
71
- (<span className={classNames(badgeStyles.badge, badgeStyles.invalid)} title={user.banReason}>{wording.banned}</span>)}
71
+ (<span className={classNames(badgeStyles.badge, badgeStyles.invalid)} title={user.banReason}>{wording?.banned ?? translate('banned')}</span>)}
72
72
  </div>
73
73
  <div className={styles.userLogin}>{user.login}</div>
74
74
  {user.email && (<span className={styles.userEmailWrapper}>
75
75
  <Link href={`mailto:${user.email}`} title={`mailto:${user.email}`} target="_blank" className={styles.userEmail}>
76
76
  {user.email}
77
77
  </Link>
78
- {user.unverifiedEmail && (<span className={styles.unverifiedLabel}>{wording.unverified}</span>)}
79
- <Icon title={wording.copyToClipboard} className={styles.userCopyIcon} onClick={this.copyEmail} glyph={copyIcon} size={IconSize.Size14} suppressSizeWarning/>
78
+ {user.unverifiedEmail && (<span className={styles.unverifiedLabel}>
79
+ {wording?.unverified ?? translate('unverified')}
80
+ </span>)}
81
+ <Icon title={wording?.copyToClipboard ?? translate('copyToClipboard')} className={styles.userCopyIcon} onClick={this.copyEmail} glyph={copyIcon} size={IconSize.Size14} suppressSizeWarning/>
80
82
  </span>)}
81
83
  </div>
82
84
  {children}
@@ -43,12 +43,15 @@ class UserCard extends PureComponent {
43
43
  };
44
44
  static contextType = I18nContext;
45
45
  copyEmail = () => {
46
- const messages = this.context;
47
- const messageOverrides = this.props.wording || this.props.translations;
48
- const wording = messageOverrides !== null && messageOverrides !== void 0 ? messageOverrides : messages;
49
- clipboard.copyText(this.props.user.email || '', wording.copiedToClipboard, wording.copingToClipboardError);
46
+ var _wording$copiedToClip, _wording$copingToClip;
47
+ const {
48
+ translate
49
+ } = this.context;
50
+ const wording = this.props.translations || this.props.wording;
51
+ clipboard.copyText(this.props.user.email || '', (_wording$copiedToClip = wording?.copiedToClipboard) !== null && _wording$copiedToClip !== void 0 ? _wording$copiedToClip : translate('copyToClipboard'), (_wording$copingToClip = wording?.copingToClipboardError) !== null && _wording$copingToClip !== void 0 ? _wording$copingToClip : translate('copingToClipboardError'));
50
52
  };
51
53
  render() {
54
+ var _wording$online, _wording$offline, _wording$banned, _wording$unverified, _wording$copyToClipbo;
52
55
  const {
53
56
  children,
54
57
  info,
@@ -57,9 +60,10 @@ class UserCard extends PureComponent {
57
60
  avatarInfo,
58
61
  ...restProps
59
62
  } = this.props;
60
- const messages = this.context;
61
- const messageOverrides = this.props.wording || this.props.translations;
62
- const wording = messageOverrides !== null && messageOverrides !== void 0 ? messageOverrides : messages;
63
+ const {
64
+ translate
65
+ } = this.context;
66
+ const wording = this.props.translations || this.props.wording;
63
67
  const classes = classNames(className, {});
64
68
  const userActiveStatusClasses = classNames(modules_a4196c17.userActiveStatus, user.online ? modules_a4196c17.online : '');
65
69
  return /*#__PURE__*/React.createElement("div", _extends({
@@ -85,13 +89,13 @@ class UserCard extends PureComponent {
85
89
  className: modules_a4196c17.userName
86
90
  }, user.name), typeof user.online === 'boolean' && /*#__PURE__*/React.createElement("span", {
87
91
  className: userActiveStatusClasses,
88
- title: user.online ? wording.online : wording.offline
92
+ title: user.online ? (_wording$online = wording?.online) !== null && _wording$online !== void 0 ? _wording$online : translate('online') : (_wording$offline = wording?.offline) !== null && _wording$offline !== void 0 ? _wording$offline : translate('offline')
89
93
  }), !!info && /*#__PURE__*/React.createElement("span", {
90
94
  className: modules_a4196c17.userNameInfo
91
95
  }, info), user.banned && /*#__PURE__*/React.createElement("span", {
92
96
  className: classNames(modules_6c9187df.badge, modules_6c9187df.invalid),
93
97
  title: user.banReason
94
- }, wording.banned)), /*#__PURE__*/React.createElement("div", {
98
+ }, (_wording$banned = wording?.banned) !== null && _wording$banned !== void 0 ? _wording$banned : translate('banned'))), /*#__PURE__*/React.createElement("div", {
95
99
  className: modules_a4196c17.userLogin
96
100
  }, user.login), user.email && /*#__PURE__*/React.createElement("span", {
97
101
  className: modules_a4196c17.userEmailWrapper
@@ -102,8 +106,8 @@ class UserCard extends PureComponent {
102
106
  className: modules_a4196c17.userEmail
103
107
  }, user.email), user.unverifiedEmail && /*#__PURE__*/React.createElement("span", {
104
108
  className: modules_a4196c17.unverifiedLabel
105
- }, wording.unverified), /*#__PURE__*/React.createElement(Icon, {
106
- title: wording.copyToClipboard,
109
+ }, (_wording$unverified = wording?.unverified) !== null && _wording$unverified !== void 0 ? _wording$unverified : translate('unverified')), /*#__PURE__*/React.createElement(Icon, {
110
+ title: (_wording$copyToClipbo = wording?.copyToClipboard) !== null && _wording$copyToClipbo !== void 0 ? _wording$copyToClipbo : translate('copyToClipboard'),
107
111
  className: modules_a4196c17.userCopyIcon,
108
112
  onClick: this.copyEmail,
109
113
  glyph: copyIcon,
@@ -42,10 +42,13 @@ class SelectFilter extends Component {
42
42
  ...restProps
43
43
  } = this.props;
44
44
  const classes = classNames(modules_b607bec2.filter, className);
45
- return /*#__PURE__*/React.createElement(ActiveItemContext.ValueContext.Consumer, null, activeItemId => /*#__PURE__*/React.createElement(I18nContext.Consumer, null, messages => {
45
+ return /*#__PURE__*/React.createElement(ActiveItemContext.ValueContext.Consumer, null, activeItemId => /*#__PURE__*/React.createElement(I18nContext.Consumer, null, _ref => {
46
46
  var _restProps$placeholde;
47
+ let {
48
+ translate
49
+ } = _ref;
47
50
  return /*#__PURE__*/React.createElement(Input, _extends({}, restProps, {
48
- placeholder: (_restProps$placeholde = restProps.placeholder) !== null && _restProps$placeholde !== void 0 ? _restProps$placeholde : messages.filterItems,
51
+ placeholder: (_restProps$placeholde = restProps.placeholder) !== null && _restProps$placeholde !== void 0 ? _restProps$placeholde : translate('filterItems'),
49
52
  "aria-owns": listId,
50
53
  "aria-activedescendant": activeItemId,
51
54
  autoComplete: "off",
@@ -2,7 +2,7 @@ import { getAbsoluteBaseURL, fixUrl } from '../global/url.js';
2
2
  import Listeners from '../global/listeners.js';
3
3
  import HTTP from '../http/http.js';
4
4
  import promiseWithTimeout from '../global/promise-with-timeout.js';
5
- import { getTranslations } from '../i18n/i18n.js';
5
+ import { getTranslationsWithFallback, translate, getTranslations } from '../i18n/i18n.js';
6
6
  import AuthStorage from './storage.js';
7
7
  import AuthResponseParser from './response-parser.js';
8
8
  import AuthRequestBuilder from './request-builder.js';
@@ -180,7 +180,7 @@ class Auth {
180
180
  this._backgroundFlow = new BackgroundFlow(this._requestBuilder, this._storage, backgroundRefreshTimeout);
181
181
  if (this.config.EmbeddedLoginFlow) {
182
182
  var _this$config$translat;
183
- this._embeddedFlow = new this.config.EmbeddedLoginFlow(this._requestBuilder, this._storage, (_this$config$translat = this.config.translations) !== null && _this$config$translat !== void 0 ? _this$config$translat : getTranslations());
183
+ this._embeddedFlow = new this.config.EmbeddedLoginFlow(this._requestBuilder, this._storage, (_this$config$translat = this.config.translations) !== null && _this$config$translat !== void 0 ? _this$config$translat : getTranslationsWithFallback());
184
184
  }
185
185
  const API_BASE = this.config.serverUri + Auth.API_PATH;
186
186
  const fetchConfig = config.fetchCredentials ? {
@@ -616,7 +616,7 @@ class Auth {
616
616
  const stopMessageListening = this._storage?.onMessage(Auth.CLOSE_WINDOW_MESSAGE, () => this._embeddedFlow?.stop());
617
617
  }
618
618
  _showUserChangedDialog(_ref) {
619
- var _newUser$name, _newUser$name2;
619
+ var _translations$youHave, _newUser$name, _newUser$name2, _translations$login, _translations$loginTo, _translations$applyCh, _translations$tryAgai, _translations$postpon;
620
620
  let {
621
621
  newUser,
622
622
  onApply,
@@ -625,7 +625,6 @@ class Auth {
625
625
  const {
626
626
  translations
627
627
  } = this.config;
628
- const actualTranslations = translations !== null && translations !== void 0 ? translations : getTranslations();
629
628
  this._createInitDeferred();
630
629
  const done = () => {
631
630
  this._initDeferred?.resolve?.();
@@ -634,12 +633,12 @@ class Auth {
634
633
  };
635
634
  const hide = this._authDialogService?.({
636
635
  ...this._service,
637
- title: actualTranslations.youHaveLoggedInAs.replace('%userName%', (_newUser$name = newUser.name) !== null && _newUser$name !== void 0 ? _newUser$name : '').replace('{{userName}}', (_newUser$name2 = newUser.name) !== null && _newUser$name2 !== void 0 ? _newUser$name2 : ''),
638
- loginCaption: actualTranslations.login,
639
- loginToCaption: actualTranslations.loginTo,
640
- confirmLabel: actualTranslations.applyChange,
641
- tryAgainLabel: actualTranslations.tryAgainLabel,
642
- cancelLabel: actualTranslations.postpone,
636
+ title: (_translations$youHave = translations?.youHaveLoggedInAs) !== null && _translations$youHave !== void 0 ? _translations$youHave : translate('youHaveLoggedInAs').replace('%userName%', (_newUser$name = newUser.name) !== null && _newUser$name !== void 0 ? _newUser$name : '').replace('{{userName}}', (_newUser$name2 = newUser.name) !== null && _newUser$name2 !== void 0 ? _newUser$name2 : ''),
637
+ loginCaption: (_translations$login = translations?.login) !== null && _translations$login !== void 0 ? _translations$login : translate('login'),
638
+ loginToCaption: (_translations$loginTo = translations?.loginTo) !== null && _translations$loginTo !== void 0 ? _translations$loginTo : translate('loginTo'),
639
+ confirmLabel: (_translations$applyCh = translations?.applyChange) !== null && _translations$applyCh !== void 0 ? _translations$applyCh : translate('applyChange'),
640
+ tryAgainLabel: (_translations$tryAgai = translations?.tryAgainLabel) !== null && _translations$tryAgai !== void 0 ? _translations$tryAgai : translate('tryAgainLabel'),
641
+ cancelLabel: (_translations$postpon = translations?.postpone) !== null && _translations$postpon !== void 0 ? _translations$postpon : translate('postpone'),
643
642
  onConfirm: () => {
644
643
  done();
645
644
  onApply();
@@ -706,7 +705,7 @@ class Auth {
706
705
  onCheckAgain,
707
706
  onPostpone,
708
707
  backendError,
709
- translations: translations !== null && translations !== void 0 ? translations : getTranslations()
708
+ translations: translations !== null && translations !== void 0 ? translations : getTranslationsWithFallback()
710
709
  });
711
710
  window.addEventListener('online', onCheckAgain);
712
711
  function networkWatchdog() {
@@ -67,59 +67,8 @@ export default class Profile extends PureComponent<ProfileProps> {
67
67
  renderGuest: PropTypes.Requireable<(...args: any[]) => any>;
68
68
  };
69
69
  static defaultProps: ProfileProps;
70
- static contextType: React.Context<{
71
- login: string;
72
- logout: string;
73
- loginTo: string;
74
- ok: string;
75
- cancel: string;
76
- tryAgainLabel: string;
77
- postpone: string;
78
- youHaveLoggedInAs: string;
79
- applyChange: string;
80
- backendIsNotAvailable: string;
81
- checkAgain: string;
82
- nothingHappensLink: string;
83
- errorMessage: string;
84
- applyChangedUser: string;
85
- profile: string;
86
- switchUser: string;
87
- addFirstDate: string;
88
- addSecondDate: string;
89
- addTime: string;
90
- selectName: string;
91
- setDate: string;
92
- setDateTime: string;
93
- setPeriod: string;
94
- clear: string;
95
- gotIt: string;
96
- dismiss: string;
97
- perPage: string;
98
- firstPage: string;
99
- lastPage: string;
100
- nextPage: string;
101
- previousPage: string;
102
- searchTitle: string;
103
- clearTitle: string;
104
- userAgreement: string;
105
- accept: string;
106
- decline: string;
107
- close: string;
108
- scrollToAccept: string;
109
- remindLater: string;
110
- filterItems: string;
111
- selectOption: string;
112
- progress: string;
113
- loading: string;
114
- noOptionsFound: string;
115
- banned: string;
116
- online: string;
117
- offline: string;
118
- copyToClipboard: string;
119
- copiedToClipboard: string;
120
- copingToClipboardError: string;
121
- unverified: string;
122
- }>;
70
+ static contextType: React.Context<import("../i18n/i18n-context").I18nContextProps>;
71
+ context: React.ContextType<typeof Profile.contextType>;
123
72
  static Size: typeof Size;
124
73
  render(): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
125
74
  }
@@ -109,8 +109,11 @@ class Profile extends PureComponent {
109
109
  className,
110
110
  translations
111
111
  } = _ref;
112
- return /*#__PURE__*/React.createElement(I18nContext.Consumer, null, messages => {
112
+ return /*#__PURE__*/React.createElement(I18nContext.Consumer, null, _ref2 => {
113
113
  var _translations$login;
114
+ let {
115
+ translate
116
+ } = _ref2;
114
117
  return /*#__PURE__*/React.createElement("div", {
115
118
  className: classNames(modules_47759f5e.profileEmpty, className)
116
119
  }, /*#__PURE__*/React.createElement(Button, {
@@ -119,7 +122,7 @@ class Profile extends PureComponent {
119
122
  disabled: loading,
120
123
  loader: loading,
121
124
  onClick: onLogin
122
- }, (_translations$login = translations?.login) !== null && _translations$login !== void 0 ? _translations$login : messages.login));
125
+ }, (_translations$login = translations?.login) !== null && _translations$login !== void 0 ? _translations$login : translate('login')));
123
126
  });
124
127
  }
125
128
  };
@@ -150,7 +153,9 @@ class Profile extends PureComponent {
150
153
  onLogin,
151
154
  ...props
152
155
  } = this.props;
153
- const messages = this.context;
156
+ const {
157
+ translate
158
+ } = this.context;
154
159
  if (!user) {
155
160
  return /*#__PURE__*/React.createElement("div", _extends({}, props, {
156
161
  className: classNames(modules_47759f5e.profileEmpty, className)
@@ -175,28 +180,28 @@ class Profile extends PureComponent {
175
180
  }));
176
181
  const items = [showApplyChangedUser && {
177
182
  rgItemType,
178
- label: (_translations$applyCh = translations?.applyChangedUser) !== null && _translations$applyCh !== void 0 ? _translations$applyCh : messages.applyChangedUser,
183
+ label: (_translations$applyCh = translations?.applyChangedUser) !== null && _translations$applyCh !== void 0 ? _translations$applyCh : translate('applyChangedUser'),
179
184
  className: modules_47759f5e.profileMenuItem,
180
185
  onClick: onRevertPostponement
181
186
  }, showLogIn && {
182
187
  rgItemType,
183
- label: (_translations$login2 = translations?.login) !== null && _translations$login2 !== void 0 ? _translations$login2 : messages.login,
188
+ label: (_translations$login2 = translations?.login) !== null && _translations$login2 !== void 0 ? _translations$login2 : translate('login'),
184
189
  className: modules_47759f5e.profileMenuItem,
185
190
  onClick: onRevertPostponement
186
191
  }, {
187
192
  rgItemType: PopupMenu.ListProps.Type.LINK,
188
- label: (_translations$profile = translations?.profile) !== null && _translations$profile !== void 0 ? _translations$profile : messages.profile,
193
+ label: (_translations$profile = translations?.profile) !== null && _translations$profile !== void 0 ? _translations$profile : translate('profile'),
189
194
  target: '_self',
190
195
  href: profileUrl,
191
196
  LinkComponent
192
197
  }, showSwitchUser && {
193
198
  rgItemType,
194
- label: (_translations$switchU = translations?.switchUser) !== null && _translations$switchU !== void 0 ? _translations$switchU : messages.switchUser,
199
+ label: (_translations$switchU = translations?.switchUser) !== null && _translations$switchU !== void 0 ? _translations$switchU : translate('switchUser'),
195
200
  className: modules_47759f5e.profileMenuItem,
196
201
  onClick: onSwitchUser
197
202
  }, showLogOut && {
198
203
  rgItemType,
199
- label: (_translations$logout = translations?.logout) !== null && _translations$logout !== void 0 ? _translations$logout : messages.logout,
204
+ label: (_translations$logout = translations?.logout) !== null && _translations$logout !== void 0 ? _translations$logout : translate('logout'),
200
205
  onClick: onLogout
201
206
  }].filter(isTruthy);
202
207
  return /*#__PURE__*/React.createElement(DropdownMenu, _extends({}, props, {
@@ -1,54 +1,13 @@
1
1
  import React from 'react';
2
- export declare const I18nContext: React.Context<{
3
- login: string;
4
- logout: string;
5
- loginTo: string;
6
- ok: string;
7
- cancel: string;
8
- tryAgainLabel: string;
9
- postpone: string;
10
- youHaveLoggedInAs: string;
11
- applyChange: string;
12
- backendIsNotAvailable: string;
13
- checkAgain: string;
14
- nothingHappensLink: string;
15
- errorMessage: string;
16
- applyChangedUser: string;
17
- profile: string;
18
- switchUser: string;
19
- addFirstDate: string;
20
- addSecondDate: string;
21
- addTime: string;
22
- selectName: string;
23
- setDate: string;
24
- setDateTime: string;
25
- setPeriod: string;
26
- clear: string;
27
- gotIt: string;
28
- dismiss: string;
29
- perPage: string;
30
- firstPage: string;
31
- lastPage: string;
32
- nextPage: string;
33
- previousPage: string;
34
- searchTitle: string;
35
- clearTitle: string;
36
- userAgreement: string;
37
- accept: string;
38
- decline: string;
39
- close: string;
40
- scrollToAccept: string;
41
- remindLater: string;
42
- filterItems: string;
43
- selectOption: string;
44
- progress: string;
45
- loading: string;
46
- noOptionsFound: string;
47
- banned: string;
48
- online: string;
49
- offline: string;
50
- copyToClipboard: string;
51
- copiedToClipboard: string;
52
- copingToClipboardError: string;
53
- unverified: string;
54
- }>;
2
+ import { type Messages } from './i18n';
3
+ export interface I18nContextProps {
4
+ translate(key: keyof Messages): string;
5
+ messages: Messages;
6
+ }
7
+ export declare const I18nContext: React.Context<I18nContextProps>;
8
+ interface I18nContextHolderProps {
9
+ messages: Messages;
10
+ children?: React.ReactNode;
11
+ }
12
+ export declare const I18nContextHolder: React.FC<I18nContextHolderProps>;
13
+ export {};
@@ -1,6 +1,24 @@
1
- import React from 'react';
2
- import { getTranslations } from './i18n.js';
1
+ import React, { useEffect } from 'react';
2
+ import { getTranslations, translate, setTranslations } from './i18n.js';
3
3
 
4
- const I18nContext = /*#__PURE__*/React.createContext(getTranslations());
4
+ const I18nContext = /*#__PURE__*/React.createContext({
5
+ messages: getTranslations(),
6
+ translate
7
+ });
8
+ const I18nContextHolder = _ref => {
9
+ let {
10
+ children,
11
+ messages
12
+ } = _ref;
13
+ useEffect(() => {
14
+ setTranslations(messages);
15
+ }, [messages]);
16
+ return /*#__PURE__*/React.createElement(I18nContext.Provider, {
17
+ value: {
18
+ messages,
19
+ translate
20
+ }
21
+ }, children);
22
+ };
5
23
 
6
- export { I18nContext };
24
+ export { I18nContext, I18nContextHolder };
@@ -1,7 +1,8 @@
1
1
  import defaultMessages from './messages.json';
2
- export type Messages = typeof defaultMessages;
2
+ export type MessagesStrict = typeof defaultMessages;
3
+ export type Messages = Partial<MessagesStrict>;
3
4
  export declare function setTranslations(newMessages: Messages): void;
4
- export declare function getTranslations(): {
5
+ export declare function getTranslations(): Partial<{
5
6
  login: string;
6
7
  logout: string;
7
8
  loginTo: string;
@@ -53,4 +54,6 @@ export declare function getTranslations(): {
53
54
  copiedToClipboard: string;
54
55
  copingToClipboardError: string;
55
56
  unverified: string;
56
- };
57
+ }>;
58
+ export declare function getTranslationsWithFallback(): MessagesStrict;
59
+ export declare function translate(key: keyof MessagesStrict): string;
package/dist/i18n/i18n.js CHANGED
@@ -104,11 +104,33 @@ var defaultMessages = {
104
104
  };
105
105
 
106
106
  let messages = defaultMessages;
107
+ const warned = new Set();
108
+ function warnMissedKeyOnce(key) {
109
+ if (warned.has(key)) {
110
+ return;
111
+ }
112
+ warned.add(key);
113
+ // eslint-disable-next-line no-console
114
+ console.warn(`Missing localisation for key "${key}"`);
115
+ }
107
116
  function setTranslations(newMessages) {
108
117
  messages = newMessages;
109
118
  }
110
119
  function getTranslations() {
111
120
  return messages;
112
121
  }
122
+ function getTranslationsWithFallback() {
123
+ return {
124
+ ...defaultMessages,
125
+ ...messages
126
+ };
127
+ }
128
+ function translate(key) {
129
+ var _messages$key;
130
+ if (!(key in messages)) {
131
+ warnMissedKeyOnce(key);
132
+ }
133
+ return (_messages$key = messages[key]) !== null && _messages$key !== void 0 ? _messages$key : defaultMessages[key];
134
+ }
113
135
 
114
- export { getTranslations, setTranslations };
136
+ export { getTranslations, getTranslationsWithFallback, setTranslations, translate };
@@ -151,32 +151,38 @@ class Input extends PureComponent {
151
151
  'aria-label': typeof label === 'string' && label ? label : placeholder,
152
152
  'data-enabled-shortcuts': Array.isArray(enableShortcuts) ? enableShortcuts.join(',') : null
153
153
  };
154
- return /*#__PURE__*/React.createElement(I18nContext.Consumer, null, messages => /*#__PURE__*/React.createElement("div", {
155
- className: classes,
156
- "data-test": "ring-input"
157
- }, label && /*#__PURE__*/React.createElement(InputLabel, {
158
- htmlFor: this.getId(),
159
- disabled: disabled,
160
- label: label
161
- }), /*#__PURE__*/React.createElement("div", {
162
- className: modules_88cfaf40.container
163
- }, icon && /*#__PURE__*/React.createElement(Icon, {
164
- glyph: icon,
165
- className: modules_88cfaf40.icon
166
- }), multiline ? /*#__PURE__*/React.createElement("textarea", _extends({
167
- onChange: this.handleTextareaChange,
168
- rows: 1
169
- }, commonProps, restProps)) : /*#__PURE__*/React.createElement("input", _extends({
170
- onChange: this.handleInputChange
171
- }, commonProps, restProps)), clearable && !disabled && /*#__PURE__*/React.createElement(Button, {
172
- title: (translations !== null && translations !== void 0 ? translations : messages).clear,
173
- "data-test": "ring-input-clear",
174
- className: modules_88cfaf40.clear,
175
- icon: closeIcon,
176
- onClick: this.clear
177
- }), afterInput), error && /*#__PURE__*/React.createElement("div", {
178
- className: modules_88cfaf40.errorText
179
- }, error)));
154
+ return /*#__PURE__*/React.createElement(I18nContext.Consumer, null, _ref => {
155
+ var _translations$clear;
156
+ let {
157
+ translate
158
+ } = _ref;
159
+ return /*#__PURE__*/React.createElement("div", {
160
+ className: classes,
161
+ "data-test": "ring-input"
162
+ }, label && /*#__PURE__*/React.createElement(InputLabel, {
163
+ htmlFor: this.getId(),
164
+ disabled: disabled,
165
+ label: label
166
+ }), /*#__PURE__*/React.createElement("div", {
167
+ className: modules_88cfaf40.container
168
+ }, icon && /*#__PURE__*/React.createElement(Icon, {
169
+ glyph: icon,
170
+ className: modules_88cfaf40.icon
171
+ }), multiline ? /*#__PURE__*/React.createElement("textarea", _extends({
172
+ onChange: this.handleTextareaChange,
173
+ rows: 1
174
+ }, commonProps, restProps)) : /*#__PURE__*/React.createElement("input", _extends({
175
+ onChange: this.handleInputChange
176
+ }, commonProps, restProps)), clearable && !disabled && /*#__PURE__*/React.createElement(Button, {
177
+ title: (_translations$clear = translations?.clear) !== null && _translations$clear !== void 0 ? _translations$clear : translate('clear'),
178
+ "data-test": "ring-input-clear",
179
+ className: modules_88cfaf40.clear,
180
+ icon: closeIcon,
181
+ onClick: this.clear
182
+ }), afterInput), error && /*#__PURE__*/React.createElement("div", {
183
+ className: modules_88cfaf40.errorText
184
+ }, error));
185
+ });
180
186
  }
181
187
  }
182
188
  Input.propTypes = {
package/dist/link/link.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { _ as _extends } from '../_helpers/_rollupPluginBabelHelpers.js';
2
- import React, { PureComponent, memo } from 'react';
2
+ import React, { memo, PureComponent } from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import classNames from 'classnames';
5
5
  import memoize from '../global/memoize.js';