@instructure/ui-i18n 8.33.1 → 8.33.2-snapshot-5
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 +8 -0
- package/es/ApplyLocale/ApplyLocaleContext.js +1 -0
- package/es/ApplyLocale/index.js +3 -3
- package/es/ApplyTextDirection/index.js +1 -2
- package/es/DateTime.js +10 -20
- package/es/I18nPropTypes.js +1 -6
- package/es/Locale.js +2 -3
- package/es/TextDirectionContext.js +2 -1
- package/es/bidirectional.js +10 -15
- package/es/getTextDirection.js +3 -12
- package/es/index.js +1 -0
- package/es/textDirectionContextConsumer.js +2 -1
- package/lib/ApplyLocale/ApplyLocaleContext.js +1 -2
- package/lib/ApplyLocale/index.js +2 -8
- package/lib/ApplyTextDirection/index.js +0 -6
- package/lib/DateTime.js +8 -22
- package/lib/I18nPropTypes.js +0 -7
- package/lib/Locale.js +2 -5
- package/lib/TextDirectionContext.js +0 -3
- package/lib/bidirectional.js +7 -21
- package/lib/getTextDirection.js +3 -15
- package/lib/index.js +0 -10
- package/lib/textDirectionContextConsumer.js +0 -2
- package/package.json +9 -9
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [8.33.2-snapshot-5](https://github.com/instructure/instructure-ui/compare/v8.33.1...v8.33.2-snapshot-5) (2023-01-23)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-i18n
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [8.33.1](https://github.com/instructure/instructure-ui/compare/v8.33.0...v8.33.1) (2023-01-06)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @instructure/ui-i18n
|
package/es/ApplyLocale/index.js
CHANGED
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import React from 'react';
|
|
25
26
|
import { ensureSingleChild } from '@instructure/ui-react-utils';
|
|
26
27
|
import { ApplyLocaleContext } from './ApplyLocaleContext';
|
|
27
|
-
|
|
28
28
|
/**
|
|
29
29
|
---
|
|
30
30
|
category: components/utilities
|
|
@@ -33,8 +33,8 @@ category: components/utilities
|
|
|
33
33
|
**/
|
|
34
34
|
export const ApplyLocale = _ref => {
|
|
35
35
|
let children = _ref.children,
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
locale = _ref.locale,
|
|
37
|
+
timezone = _ref.timezone;
|
|
38
38
|
return /*#__PURE__*/React.createElement(ApplyLocaleContext.Provider, {
|
|
39
39
|
value: {
|
|
40
40
|
locale,
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import React, { useContext } from 'react';
|
|
25
26
|
import { getElementType } from '@instructure/ui-react-utils';
|
|
26
27
|
import { DIRECTION, TextDirectionContext } from '../TextDirectionContext';
|
|
27
|
-
|
|
28
28
|
/**
|
|
29
29
|
---
|
|
30
30
|
category: components/utilities
|
|
@@ -42,7 +42,6 @@ const ApplyTextDirection = props => {
|
|
|
42
42
|
dir: dir
|
|
43
43
|
}, typeof props.children === 'function' ? props.children(dir, dir === DIRECTION.rtl) : props.children));
|
|
44
44
|
};
|
|
45
|
-
|
|
46
45
|
ApplyTextDirection.defaultProps = {
|
|
47
46
|
dir: void 0,
|
|
48
47
|
as: 'span',
|
package/es/DateTime.js
CHANGED
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import moment from 'moment-timezone';
|
|
26
|
+
|
|
25
27
|
/**
|
|
26
28
|
* ---
|
|
27
29
|
* category: utilities/i18n
|
|
@@ -39,12 +41,11 @@ import moment from 'moment-timezone';
|
|
|
39
41
|
* @param {String} timezone
|
|
40
42
|
* @returns {Object} an instance of a moment.
|
|
41
43
|
*/
|
|
42
|
-
|
|
43
44
|
function now(locale, timezone) {
|
|
44
45
|
_checkParams(locale, timezone);
|
|
45
|
-
|
|
46
46
|
return moment().locale(locale).tz(timezone);
|
|
47
47
|
}
|
|
48
|
+
|
|
48
49
|
/**
|
|
49
50
|
* Parses a string into a localized ISO 8601 string with timezone
|
|
50
51
|
* @param {String} dateString
|
|
@@ -52,34 +53,30 @@ function now(locale, timezone) {
|
|
|
52
53
|
* @param {String} timezone
|
|
53
54
|
* @returns {String} ISO 8601 string
|
|
54
55
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
56
|
function parse(dateString, locale, timezone) {
|
|
58
|
-
_checkParams(locale, timezone);
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
_checkParams(locale, timezone);
|
|
58
|
+
// list all available localized formats, from most specific to least
|
|
61
59
|
return moment.tz(dateString, [moment.ISO_8601, 'llll', 'LLLL', 'lll', 'LLL', 'll', 'LL', 'l', 'L'], locale, timezone);
|
|
62
60
|
}
|
|
61
|
+
|
|
63
62
|
/**
|
|
64
63
|
* Determines if a string is a valid ISO 8601 string
|
|
65
64
|
* @param {String} dateString
|
|
66
65
|
* @returns {Boolean} true if dateString is a valid ISO 8601 string
|
|
67
66
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
67
|
function isValid(dateString) {
|
|
71
68
|
return moment(dateString, [moment.ISO_8601]).isValid();
|
|
72
69
|
}
|
|
70
|
+
|
|
73
71
|
/**
|
|
74
72
|
* Get the user's time zone (or guess)
|
|
75
73
|
* see https://momentjs.com/timezone/docs/#/using-timezones/guessing-user-timezone/
|
|
76
74
|
* @returns {String} a time zone identifier (see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
|
|
77
75
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
76
|
function browserTimeZone() {
|
|
81
77
|
return moment.tz.guess();
|
|
82
78
|
}
|
|
79
|
+
|
|
83
80
|
/**
|
|
84
81
|
* Returns the days of the week in the given locale,
|
|
85
82
|
* for example ["Monday", "Tuesday",..]. It always begins with Monday.
|
|
@@ -87,13 +84,10 @@ function browserTimeZone() {
|
|
|
87
84
|
* @param format If set to 'short' it will be maximum 3 letters long,
|
|
88
85
|
* if set to 'long' it will be the full word.
|
|
89
86
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
87
|
function getLocalDayNamesOfTheWeek(locale, format) {
|
|
93
88
|
const ret = [];
|
|
94
89
|
const toFormat = format === 'short' ? 'dd' : 'dddd';
|
|
95
90
|
let currentDay = getFirstDayOfWeek(now(locale, browserTimeZone()));
|
|
96
|
-
|
|
97
91
|
for (let i = 0; i < 7; i++) {
|
|
98
92
|
ret.push(currentDay.format(toFormat));
|
|
99
93
|
currentDay = currentDay.add(1, 'day'); // TODO this is mutable
|
|
@@ -101,17 +95,17 @@ function getLocalDayNamesOfTheWeek(locale, format) {
|
|
|
101
95
|
|
|
102
96
|
return ret;
|
|
103
97
|
}
|
|
98
|
+
|
|
104
99
|
/**
|
|
105
100
|
* Returns the first day of the week in the given locale.
|
|
106
101
|
* The locale decides what is the first day, e.g. Sunday in the US, Monday in
|
|
107
102
|
* the EU.
|
|
108
103
|
* @param date A Moment Datetime object
|
|
109
104
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
105
|
function getFirstDayOfWeek(date) {
|
|
113
106
|
return date.clone().weekday(0);
|
|
114
107
|
}
|
|
108
|
+
|
|
115
109
|
/**
|
|
116
110
|
* Return a localized date + time with timezone as a ISO 8601 string
|
|
117
111
|
* @param {String} dateString
|
|
@@ -120,19 +114,15 @@ function getFirstDayOfWeek(date) {
|
|
|
120
114
|
* @param {String} format the format to use. Defaults to YYYY-MM-DDTHH:mm:ss.SSSZ
|
|
121
115
|
* @returns {String} Localized ISO 8601 string
|
|
122
116
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
117
|
function toLocaleString(dateString, locale, timezone, format) {
|
|
126
118
|
const d = parse(dateString, locale, timezone);
|
|
127
119
|
const iso8601format = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
|
|
128
120
|
return format ? d.format(format) : d.format(iso8601format);
|
|
129
121
|
}
|
|
130
|
-
|
|
131
122
|
function _checkParams(locale, timezone) {
|
|
132
123
|
if (locale == null) throw Error('locale must be specified');
|
|
133
124
|
if (timezone == null) throw Error('timezone must be specified');
|
|
134
125
|
}
|
|
135
|
-
|
|
136
126
|
const DateTime = {
|
|
137
127
|
now,
|
|
138
128
|
parse,
|
package/es/I18nPropTypes.js
CHANGED
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import { makeRequirable } from '@instructure/ui-prop-types';
|
|
25
24
|
|
|
25
|
+
import { makeRequirable } from '@instructure/ui-prop-types';
|
|
26
26
|
/**
|
|
27
27
|
*
|
|
28
28
|
* Verify that the given prop is a correctly formatted ISO 8601 formatted string.
|
|
@@ -37,20 +37,15 @@ const iso8601 = function (props, propName, componentName, location) {
|
|
|
37
37
|
const propValue = props[propName];
|
|
38
38
|
if (typeof propValue === 'undefined' || propValue === '') return null;
|
|
39
39
|
const propValueType = typeof propValue;
|
|
40
|
-
|
|
41
40
|
if (typeof propValueType !== 'string') {
|
|
42
41
|
return new Error(`Invalid ${location} \`${propName}\` of type \`${propValueType}\` supplied to \`${componentName}\`, expected ` + `an ISO 8601 formatted string.`);
|
|
43
42
|
}
|
|
44
|
-
|
|
45
43
|
const iso8601regex = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
|
|
46
|
-
|
|
47
44
|
if (typeof propValue === 'string' && !propValue.match(iso8601regex)) {
|
|
48
45
|
return new Error(`Invalid ${location} \`${propName}\` \`${propValue}\` supplied to \`${componentName}\`, expected ` + `an ISO 8601 formatted string.`);
|
|
49
46
|
}
|
|
50
|
-
|
|
51
47
|
return null;
|
|
52
48
|
};
|
|
53
|
-
|
|
54
49
|
iso8601.isRequired = makeRequirable(iso8601);
|
|
55
50
|
const I18nPropTypes = {
|
|
56
51
|
iso8601: iso8601
|
package/es/Locale.js
CHANGED
|
@@ -21,8 +21,10 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import { canUseDOM } from '@instructure/ui-dom-utils';
|
|
25
26
|
const defaultLocale = 'en-US';
|
|
27
|
+
|
|
26
28
|
/**
|
|
27
29
|
* ---
|
|
28
30
|
* category: utilities/i18n
|
|
@@ -30,10 +32,8 @@ const defaultLocale = 'en-US';
|
|
|
30
32
|
* Localization utilities
|
|
31
33
|
* @module Locale
|
|
32
34
|
*/
|
|
33
|
-
|
|
34
35
|
const Locale = {
|
|
35
36
|
defaultLocale,
|
|
36
|
-
|
|
37
37
|
/**
|
|
38
38
|
* Return the locale from the browser
|
|
39
39
|
* @returns {String} locale (defaults to 'en-US' if DOM cannot be accessed)
|
|
@@ -50,7 +50,6 @@ const Locale = {
|
|
|
50
50
|
if (hasNavigatorLanguage) return window.navigator.language;
|
|
51
51
|
return defaultLocale;
|
|
52
52
|
}
|
|
53
|
-
|
|
54
53
|
};
|
|
55
54
|
export default Locale;
|
|
56
55
|
export { Locale };
|
|
@@ -21,8 +21,10 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import { createContext } from 'react';
|
|
25
26
|
import { getTextDirection } from './getTextDirection';
|
|
27
|
+
|
|
26
28
|
/**
|
|
27
29
|
* ---
|
|
28
30
|
* category: utilities/i18n
|
|
@@ -37,7 +39,6 @@ import { getTextDirection } from './getTextDirection';
|
|
|
37
39
|
*
|
|
38
40
|
* @module TextDirectionContext
|
|
39
41
|
*/
|
|
40
|
-
|
|
41
42
|
const TextDirectionContext = /*#__PURE__*/createContext(getTextDirection() || 'ltr');
|
|
42
43
|
const DIRECTION = {
|
|
43
44
|
ltr: 'ltr',
|
package/es/bidirectional.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
2
|
const _excluded = ["forwardedRef"];
|
|
3
|
-
|
|
4
3
|
/*
|
|
5
4
|
* The MIT License (MIT)
|
|
6
5
|
*
|
|
@@ -27,7 +26,9 @@ const _excluded = ["forwardedRef"];
|
|
|
27
26
|
import React, { forwardRef } from 'react';
|
|
28
27
|
import { decorator } from '@instructure/ui-decorator';
|
|
29
28
|
import { DIRECTION, TextDirectionContext } from './TextDirectionContext';
|
|
30
|
-
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
29
|
+
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
30
|
+
|
|
31
|
+
// This is a workaround because TS cannot take type information from
|
|
31
32
|
// decorators into account. This type needs to be added to every component,
|
|
32
33
|
// that uses the bidirectional decorator.
|
|
33
34
|
// see https://github.com/microsoft/TypeScript/issues/4881
|
|
@@ -68,43 +69,37 @@ const bidirectional = decorator(ComposedComponent => {
|
|
|
68
69
|
class BidirectionalComponent extends React.Component {
|
|
69
70
|
render() {
|
|
70
71
|
const _this$props = this.props,
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
forwardedRef = _this$props.forwardedRef,
|
|
73
|
+
rest = _objectWithoutProperties(_this$props, _excluded);
|
|
74
|
+
// Quite complex code, this is the priority order of applying the `dir` prop:
|
|
73
75
|
// 1. The highest priority is adding it via a prop
|
|
74
76
|
// 2. If there is a <TextDirectionContext.Provider> (or <ApplyTextDirection>
|
|
75
77
|
// which uses it) above the @bidirectional in the DOM, use its value.
|
|
76
78
|
// 3. If TextDirectionContext.Provider was called without params
|
|
77
79
|
// TextDirectionContext calls getTextDirection() which returns
|
|
78
80
|
// the 'dir' prop of the HTML document element.
|
|
79
|
-
|
|
80
|
-
|
|
81
81
|
return /*#__PURE__*/React.createElement(TextDirectionContext.Consumer, null, dir => {
|
|
82
82
|
if (process.env.NODE_ENV !== 'production' && dir === 'auto') {}
|
|
83
|
-
|
|
84
83
|
return /*#__PURE__*/React.createElement(ComposedComponent, Object.assign({
|
|
85
84
|
ref: forwardedRef,
|
|
86
85
|
dir: dir
|
|
87
86
|
}, rest));
|
|
88
87
|
});
|
|
89
88
|
}
|
|
90
|
-
|
|
91
89
|
}
|
|
92
|
-
|
|
93
90
|
BidirectionalComponent.displayName = "BidirectionalComponent";
|
|
94
91
|
const BidirectionalForwardingRef = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/React.createElement(BidirectionalComponent, Object.assign({}, props, {
|
|
95
92
|
forwardedRef: ref
|
|
96
93
|
})));
|
|
97
|
-
|
|
98
94
|
if (process.env.NODE_ENV !== 'production') {
|
|
99
95
|
const displayName = ComposedComponent.displayName || ComposedComponent.name;
|
|
100
96
|
BidirectionalForwardingRef.displayName = `BidirectionalForwardingRef(${displayName})`;
|
|
101
97
|
}
|
|
102
|
-
|
|
103
98
|
hoistNonReactStatics(BidirectionalForwardingRef, ComposedComponent);
|
|
104
|
-
BidirectionalForwardingRef.defaultProps = ComposedComponent.defaultProps;
|
|
105
|
-
|
|
106
|
-
BidirectionalForwardingRef.propTypes = ComposedComponent.propTypes;
|
|
107
|
-
|
|
99
|
+
BidirectionalForwardingRef.defaultProps = ComposedComponent.defaultProps;
|
|
100
|
+
// eslint-disable-next-line react/forbid-foreign-prop-types
|
|
101
|
+
BidirectionalForwardingRef.propTypes = ComposedComponent.propTypes;
|
|
102
|
+
// @ts-expect-error These static fields exist on InstUI components
|
|
108
103
|
BidirectionalForwardingRef.allowedProps = ComposedComponent.allowedProps;
|
|
109
104
|
return BidirectionalForwardingRef;
|
|
110
105
|
});
|
package/es/getTextDirection.js
CHANGED
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import { canUseDOM, getComputedStyle } from '@instructure/ui-dom-utils';
|
|
25
26
|
let defaultDir;
|
|
26
27
|
let dirAttribute;
|
|
27
28
|
let observer;
|
|
28
|
-
|
|
29
29
|
const getDefaultDir = () => {
|
|
30
30
|
/**
|
|
31
31
|
* use a cached value for the default of <html> element's "dir" so we don't
|
|
@@ -34,18 +34,15 @@ const getDefaultDir = () => {
|
|
|
34
34
|
if (defaultDir) {
|
|
35
35
|
return defaultDir;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
37
|
if (canUseDOM) {
|
|
39
38
|
const htmlEl = document.documentElement;
|
|
40
|
-
dirAttribute = htmlEl.getAttribute('dir');
|
|
41
|
-
|
|
39
|
+
dirAttribute = htmlEl.getAttribute('dir');
|
|
40
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/direction
|
|
42
41
|
defaultDir = dirAttribute || getComputedStyle(htmlEl).direction;
|
|
43
|
-
|
|
44
42
|
if (!observer) {
|
|
45
43
|
observer = new MutationObserver(() => {
|
|
46
44
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir
|
|
47
45
|
const attr = htmlEl.getAttribute('dir');
|
|
48
|
-
|
|
49
46
|
if (attr && attr !== dirAttribute) {
|
|
50
47
|
dirAttribute = defaultDir = attr;
|
|
51
48
|
}
|
|
@@ -54,10 +51,8 @@ const getDefaultDir = () => {
|
|
|
54
51
|
attributes: true
|
|
55
52
|
});
|
|
56
53
|
}
|
|
57
|
-
|
|
58
54
|
return defaultDir;
|
|
59
55
|
}
|
|
60
|
-
|
|
61
56
|
return void 0;
|
|
62
57
|
};
|
|
63
58
|
/**
|
|
@@ -71,16 +66,12 @@ const getDefaultDir = () => {
|
|
|
71
66
|
* @param {Element} element will use the <html> element by default
|
|
72
67
|
* @returns {String} 'ltr' or 'rtl' or 'auto' (or `undefined` if no DOM is present)
|
|
73
68
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
69
|
function getTextDirection(element) {
|
|
77
70
|
if (canUseDOM) {
|
|
78
71
|
if (typeof element === 'undefined' || element === document.documentElement) return getDefaultDir();
|
|
79
72
|
return element.getAttribute('dir') || getComputedStyle(element).direction;
|
|
80
73
|
}
|
|
81
|
-
|
|
82
74
|
return void 0;
|
|
83
75
|
}
|
|
84
|
-
|
|
85
76
|
export default getTextDirection;
|
|
86
77
|
export { getTextDirection };
|
package/es/index.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
export { ApplyLocale } from './ApplyLocale';
|
|
25
26
|
export { ApplyLocaleContext } from './ApplyLocale/ApplyLocaleContext';
|
|
26
27
|
export { bidirectional } from './bidirectional';
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import { bidirectional } from './bidirectional';
|
|
26
|
+
|
|
25
27
|
/**
|
|
26
28
|
* ---
|
|
27
29
|
* category: utilities/i18n
|
|
@@ -53,7 +55,6 @@ import { bidirectional } from './bidirectional';
|
|
|
53
55
|
* @module textDirectionContextConsumer
|
|
54
56
|
* @return The decorator that composes the bidirectional component.
|
|
55
57
|
*/
|
|
56
|
-
|
|
57
58
|
const textDirectionContextConsumer = bidirectional;
|
|
58
59
|
export default textDirectionContextConsumer;
|
|
59
60
|
export { textDirectionContextConsumer };
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.ApplyLocaleContext = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
/*
|
|
11
9
|
* The MIT License (MIT)
|
|
12
10
|
*
|
|
@@ -30,6 +28,7 @@ var _react = require("react");
|
|
|
30
28
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
29
|
* SOFTWARE.
|
|
32
30
|
*/
|
|
31
|
+
|
|
33
32
|
const ApplyLocaleContext = /*#__PURE__*/(0, _react.createContext)({
|
|
34
33
|
locale: void 0,
|
|
35
34
|
timezone: void 0
|
package/lib/ApplyLocale/index.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = exports.ApplyLocale = void 0;
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
9
|
var _ensureSingleChild = require("@instructure/ui-react-utils/lib/ensureSingleChild.js");
|
|
13
|
-
|
|
14
10
|
var _ApplyLocaleContext = require("./ApplyLocaleContext");
|
|
15
|
-
|
|
16
11
|
/*
|
|
17
12
|
* The MIT License (MIT)
|
|
18
13
|
*
|
|
@@ -45,8 +40,8 @@ category: components/utilities
|
|
|
45
40
|
**/
|
|
46
41
|
const ApplyLocale = _ref => {
|
|
47
42
|
let children = _ref.children,
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
locale = _ref.locale,
|
|
44
|
+
timezone = _ref.timezone;
|
|
50
45
|
return /*#__PURE__*/_react.default.createElement(_ApplyLocaleContext.ApplyLocaleContext.Provider, {
|
|
51
46
|
value: {
|
|
52
47
|
locale,
|
|
@@ -54,7 +49,6 @@ const ApplyLocale = _ref => {
|
|
|
54
49
|
}
|
|
55
50
|
}, (0, _ensureSingleChild.ensureSingleChild)(children));
|
|
56
51
|
};
|
|
57
|
-
|
|
58
52
|
exports.ApplyLocale = ApplyLocale;
|
|
59
53
|
ApplyLocale.defaultProps = {
|
|
60
54
|
locale: void 0,
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.ApplyTextDirection = void 0;
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
-
|
|
12
9
|
var _getElementType = require("@instructure/ui-react-utils/lib/getElementType.js");
|
|
13
|
-
|
|
14
10
|
var _TextDirectionContext = require("../TextDirectionContext");
|
|
15
|
-
|
|
16
11
|
/*
|
|
17
12
|
* The MIT License (MIT)
|
|
18
13
|
*
|
|
@@ -54,7 +49,6 @@ const ApplyTextDirection = props => {
|
|
|
54
49
|
dir: dir
|
|
55
50
|
}, typeof props.children === 'function' ? props.children(dir, dir === _TextDirectionContext.DIRECTION.rtl) : props.children));
|
|
56
51
|
};
|
|
57
|
-
|
|
58
52
|
exports.ApplyTextDirection = ApplyTextDirection;
|
|
59
53
|
ApplyTextDirection.defaultProps = {
|
|
60
54
|
dir: void 0,
|
package/lib/DateTime.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = exports.DateTime = void 0;
|
|
9
|
-
|
|
10
8
|
var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
11
|
-
|
|
12
9
|
/*
|
|
13
10
|
* The MIT License (MIT)
|
|
14
11
|
*
|
|
@@ -52,9 +49,9 @@ var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
|
52
49
|
*/
|
|
53
50
|
function now(locale, timezone) {
|
|
54
51
|
_checkParams(locale, timezone);
|
|
55
|
-
|
|
56
52
|
return (0, _momentTimezone.default)().locale(locale).tz(timezone);
|
|
57
53
|
}
|
|
54
|
+
|
|
58
55
|
/**
|
|
59
56
|
* Parses a string into a localized ISO 8601 string with timezone
|
|
60
57
|
* @param {String} dateString
|
|
@@ -62,34 +59,30 @@ function now(locale, timezone) {
|
|
|
62
59
|
* @param {String} timezone
|
|
63
60
|
* @returns {String} ISO 8601 string
|
|
64
61
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
62
|
function parse(dateString, locale, timezone) {
|
|
68
|
-
_checkParams(locale, timezone);
|
|
69
|
-
|
|
70
|
-
|
|
63
|
+
_checkParams(locale, timezone);
|
|
64
|
+
// list all available localized formats, from most specific to least
|
|
71
65
|
return _momentTimezone.default.tz(dateString, [_momentTimezone.default.ISO_8601, 'llll', 'LLLL', 'lll', 'LLL', 'll', 'LL', 'l', 'L'], locale, timezone);
|
|
72
66
|
}
|
|
67
|
+
|
|
73
68
|
/**
|
|
74
69
|
* Determines if a string is a valid ISO 8601 string
|
|
75
70
|
* @param {String} dateString
|
|
76
71
|
* @returns {Boolean} true if dateString is a valid ISO 8601 string
|
|
77
72
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
73
|
function isValid(dateString) {
|
|
81
74
|
return (0, _momentTimezone.default)(dateString, [_momentTimezone.default.ISO_8601]).isValid();
|
|
82
75
|
}
|
|
76
|
+
|
|
83
77
|
/**
|
|
84
78
|
* Get the user's time zone (or guess)
|
|
85
79
|
* see https://momentjs.com/timezone/docs/#/using-timezones/guessing-user-timezone/
|
|
86
80
|
* @returns {String} a time zone identifier (see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
|
|
87
81
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
82
|
function browserTimeZone() {
|
|
91
83
|
return _momentTimezone.default.tz.guess();
|
|
92
84
|
}
|
|
85
|
+
|
|
93
86
|
/**
|
|
94
87
|
* Returns the days of the week in the given locale,
|
|
95
88
|
* for example ["Monday", "Tuesday",..]. It always begins with Monday.
|
|
@@ -97,13 +90,10 @@ function browserTimeZone() {
|
|
|
97
90
|
* @param format If set to 'short' it will be maximum 3 letters long,
|
|
98
91
|
* if set to 'long' it will be the full word.
|
|
99
92
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
93
|
function getLocalDayNamesOfTheWeek(locale, format) {
|
|
103
94
|
const ret = [];
|
|
104
95
|
const toFormat = format === 'short' ? 'dd' : 'dddd';
|
|
105
96
|
let currentDay = getFirstDayOfWeek(now(locale, browserTimeZone()));
|
|
106
|
-
|
|
107
97
|
for (let i = 0; i < 7; i++) {
|
|
108
98
|
ret.push(currentDay.format(toFormat));
|
|
109
99
|
currentDay = currentDay.add(1, 'day'); // TODO this is mutable
|
|
@@ -111,17 +101,17 @@ function getLocalDayNamesOfTheWeek(locale, format) {
|
|
|
111
101
|
|
|
112
102
|
return ret;
|
|
113
103
|
}
|
|
104
|
+
|
|
114
105
|
/**
|
|
115
106
|
* Returns the first day of the week in the given locale.
|
|
116
107
|
* The locale decides what is the first day, e.g. Sunday in the US, Monday in
|
|
117
108
|
* the EU.
|
|
118
109
|
* @param date A Moment Datetime object
|
|
119
110
|
*/
|
|
120
|
-
|
|
121
|
-
|
|
122
111
|
function getFirstDayOfWeek(date) {
|
|
123
112
|
return date.clone().weekday(0);
|
|
124
113
|
}
|
|
114
|
+
|
|
125
115
|
/**
|
|
126
116
|
* Return a localized date + time with timezone as a ISO 8601 string
|
|
127
117
|
* @param {String} dateString
|
|
@@ -130,19 +120,15 @@ function getFirstDayOfWeek(date) {
|
|
|
130
120
|
* @param {String} format the format to use. Defaults to YYYY-MM-DDTHH:mm:ss.SSSZ
|
|
131
121
|
* @returns {String} Localized ISO 8601 string
|
|
132
122
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
123
|
function toLocaleString(dateString, locale, timezone, format) {
|
|
136
124
|
const d = parse(dateString, locale, timezone);
|
|
137
125
|
const iso8601format = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
|
|
138
126
|
return format ? d.format(format) : d.format(iso8601format);
|
|
139
127
|
}
|
|
140
|
-
|
|
141
128
|
function _checkParams(locale, timezone) {
|
|
142
129
|
if (locale == null) throw Error('locale must be specified');
|
|
143
130
|
if (timezone == null) throw Error('timezone must be specified');
|
|
144
131
|
}
|
|
145
|
-
|
|
146
132
|
const DateTime = {
|
|
147
133
|
now,
|
|
148
134
|
parse,
|
package/lib/I18nPropTypes.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.I18nPropTypes = void 0;
|
|
7
|
-
|
|
8
7
|
var _makeRequirable = require("@instructure/ui-prop-types/lib/makeRequirable.js");
|
|
9
|
-
|
|
10
8
|
/*
|
|
11
9
|
* The MIT License (MIT)
|
|
12
10
|
*
|
|
@@ -45,20 +43,15 @@ const iso8601 = function (props, propName, componentName, location) {
|
|
|
45
43
|
const propValue = props[propName];
|
|
46
44
|
if (typeof propValue === 'undefined' || propValue === '') return null;
|
|
47
45
|
const propValueType = typeof propValue;
|
|
48
|
-
|
|
49
46
|
if (typeof propValueType !== 'string') {
|
|
50
47
|
return new Error(`Invalid ${location} \`${propName}\` of type \`${propValueType}\` supplied to \`${componentName}\`, expected ` + `an ISO 8601 formatted string.`);
|
|
51
48
|
}
|
|
52
|
-
|
|
53
49
|
const iso8601regex = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
|
|
54
|
-
|
|
55
50
|
if (typeof propValue === 'string' && !propValue.match(iso8601regex)) {
|
|
56
51
|
return new Error(`Invalid ${location} \`${propName}\` \`${propValue}\` supplied to \`${componentName}\`, expected ` + `an ISO 8601 formatted string.`);
|
|
57
52
|
}
|
|
58
|
-
|
|
59
53
|
return null;
|
|
60
54
|
};
|
|
61
|
-
|
|
62
55
|
iso8601.isRequired = (0, _makeRequirable.makeRequirable)(iso8601);
|
|
63
56
|
const I18nPropTypes = {
|
|
64
57
|
iso8601: iso8601
|