@instructure/ui-i18n 8.33.2-snapshot-0 → 8.33.2
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 +1 -5
- 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/lib/Locale.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.Locale = void 0;
|
|
7
|
-
|
|
8
7
|
var _canUseDOM = require("@instructure/ui-dom-utils/lib/canUseDOM.js");
|
|
9
|
-
|
|
10
8
|
/*
|
|
11
9
|
* The MIT License (MIT)
|
|
12
10
|
*
|
|
@@ -30,7 +28,9 @@ var _canUseDOM = require("@instructure/ui-dom-utils/lib/canUseDOM.js");
|
|
|
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 defaultLocale = 'en-US';
|
|
33
|
+
|
|
34
34
|
/**
|
|
35
35
|
* ---
|
|
36
36
|
* category: utilities/i18n
|
|
@@ -38,10 +38,8 @@ const defaultLocale = 'en-US';
|
|
|
38
38
|
* Localization utilities
|
|
39
39
|
* @module Locale
|
|
40
40
|
*/
|
|
41
|
-
|
|
42
41
|
const Locale = {
|
|
43
42
|
defaultLocale,
|
|
44
|
-
|
|
45
43
|
/**
|
|
46
44
|
* Return the locale from the browser
|
|
47
45
|
* @returns {String} locale (defaults to 'en-US' if DOM cannot be accessed)
|
|
@@ -58,7 +56,6 @@ const Locale = {
|
|
|
58
56
|
if (hasNavigatorLanguage) return window.navigator.language;
|
|
59
57
|
return defaultLocale;
|
|
60
58
|
}
|
|
61
|
-
|
|
62
59
|
};
|
|
63
60
|
exports.Locale = Locale;
|
|
64
61
|
var _default = Locale;
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.TextDirectionContext = exports.DIRECTION = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _getTextDirection = require("./getTextDirection");
|
|
11
|
-
|
|
12
9
|
/*
|
|
13
10
|
* The MIT License (MIT)
|
|
14
11
|
*
|
package/lib/bidirectional.js
CHANGED
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.default = exports.bidirectional = void 0;
|
|
11
|
-
|
|
12
9
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
-
|
|
14
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
15
|
-
|
|
16
11
|
var _decorator = require("@instructure/ui-decorator/lib/decorator.js");
|
|
17
|
-
|
|
18
12
|
var _TextDirectionContext = require("./TextDirectionContext");
|
|
19
|
-
|
|
20
13
|
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
|
|
21
|
-
|
|
22
14
|
const _excluded = ["forwardedRef"];
|
|
23
|
-
|
|
24
15
|
/**
|
|
25
16
|
* ---
|
|
26
17
|
* category: utilities/i18n
|
|
@@ -57,42 +48,37 @@ const bidirectional = (0, _decorator.decorator)(ComposedComponent => {
|
|
|
57
48
|
class BidirectionalComponent extends _react.default.Component {
|
|
58
49
|
render() {
|
|
59
50
|
const _this$props = this.props,
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
forwardedRef = _this$props.forwardedRef,
|
|
52
|
+
rest = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
|
|
53
|
+
// Quite complex code, this is the priority order of applying the `dir` prop:
|
|
62
54
|
// 1. The highest priority is adding it via a prop
|
|
63
55
|
// 2. If there is a <TextDirectionContext.Provider> (or <ApplyTextDirection>
|
|
64
56
|
// which uses it) above the @bidirectional in the DOM, use its value.
|
|
65
57
|
// 3. If TextDirectionContext.Provider was called without params
|
|
66
58
|
// TextDirectionContext calls getTextDirection() which returns
|
|
67
59
|
// the 'dir' prop of the HTML document element.
|
|
68
|
-
|
|
69
60
|
return /*#__PURE__*/_react.default.createElement(_TextDirectionContext.TextDirectionContext.Consumer, null, dir => {
|
|
70
61
|
if (process.env.NODE_ENV !== 'production' && dir === 'auto') {}
|
|
71
|
-
|
|
72
62
|
return /*#__PURE__*/_react.default.createElement(ComposedComponent, Object.assign({
|
|
73
63
|
ref: forwardedRef,
|
|
74
64
|
dir: dir
|
|
75
65
|
}, rest));
|
|
76
66
|
});
|
|
77
67
|
}
|
|
78
|
-
|
|
79
68
|
}
|
|
80
|
-
|
|
81
69
|
BidirectionalComponent.displayName = "BidirectionalComponent";
|
|
82
70
|
const BidirectionalForwardingRef = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => /*#__PURE__*/_react.default.createElement(BidirectionalComponent, Object.assign({}, props, {
|
|
83
71
|
forwardedRef: ref
|
|
84
72
|
})));
|
|
85
|
-
|
|
86
73
|
if (process.env.NODE_ENV !== 'production') {
|
|
87
74
|
const displayName = ComposedComponent.displayName || ComposedComponent.name;
|
|
88
75
|
BidirectionalForwardingRef.displayName = `BidirectionalForwardingRef(${displayName})`;
|
|
89
76
|
}
|
|
90
|
-
|
|
91
77
|
(0, _hoistNonReactStatics.default)(BidirectionalForwardingRef, ComposedComponent);
|
|
92
|
-
BidirectionalForwardingRef.defaultProps = ComposedComponent.defaultProps;
|
|
93
|
-
|
|
94
|
-
BidirectionalForwardingRef.propTypes = ComposedComponent.propTypes;
|
|
95
|
-
|
|
78
|
+
BidirectionalForwardingRef.defaultProps = ComposedComponent.defaultProps;
|
|
79
|
+
// eslint-disable-next-line react/forbid-foreign-prop-types
|
|
80
|
+
BidirectionalForwardingRef.propTypes = ComposedComponent.propTypes;
|
|
81
|
+
// @ts-expect-error These static fields exist on InstUI components
|
|
96
82
|
BidirectionalForwardingRef.allowedProps = ComposedComponent.allowedProps;
|
|
97
83
|
return BidirectionalForwardingRef;
|
|
98
84
|
});
|
package/lib/getTextDirection.js
CHANGED
|
@@ -5,11 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.getTextDirection = getTextDirection;
|
|
8
|
-
|
|
9
8
|
var _canUseDOM = require("@instructure/ui-dom-utils/lib/canUseDOM.js");
|
|
10
|
-
|
|
11
9
|
var _getComputedStyle = require("@instructure/ui-dom-utils/lib/getComputedStyle.js");
|
|
12
|
-
|
|
13
10
|
/*
|
|
14
11
|
* The MIT License (MIT)
|
|
15
12
|
*
|
|
@@ -33,10 +30,10 @@ var _getComputedStyle = require("@instructure/ui-dom-utils/lib/getComputedStyle.
|
|
|
33
30
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
34
31
|
* SOFTWARE.
|
|
35
32
|
*/
|
|
33
|
+
|
|
36
34
|
let defaultDir;
|
|
37
35
|
let dirAttribute;
|
|
38
36
|
let observer;
|
|
39
|
-
|
|
40
37
|
const getDefaultDir = () => {
|
|
41
38
|
/**
|
|
42
39
|
* use a cached value for the default of <html> element's "dir" so we don't
|
|
@@ -45,18 +42,15 @@ const getDefaultDir = () => {
|
|
|
45
42
|
if (defaultDir) {
|
|
46
43
|
return defaultDir;
|
|
47
44
|
}
|
|
48
|
-
|
|
49
45
|
if (_canUseDOM.canUseDOM) {
|
|
50
46
|
const htmlEl = document.documentElement;
|
|
51
|
-
dirAttribute = htmlEl.getAttribute('dir');
|
|
52
|
-
|
|
47
|
+
dirAttribute = htmlEl.getAttribute('dir');
|
|
48
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/direction
|
|
53
49
|
defaultDir = dirAttribute || (0, _getComputedStyle.getComputedStyle)(htmlEl).direction;
|
|
54
|
-
|
|
55
50
|
if (!observer) {
|
|
56
51
|
observer = new MutationObserver(() => {
|
|
57
52
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir
|
|
58
53
|
const attr = htmlEl.getAttribute('dir');
|
|
59
|
-
|
|
60
54
|
if (attr && attr !== dirAttribute) {
|
|
61
55
|
dirAttribute = defaultDir = attr;
|
|
62
56
|
}
|
|
@@ -65,10 +59,8 @@ const getDefaultDir = () => {
|
|
|
65
59
|
attributes: true
|
|
66
60
|
});
|
|
67
61
|
}
|
|
68
|
-
|
|
69
62
|
return defaultDir;
|
|
70
63
|
}
|
|
71
|
-
|
|
72
64
|
return void 0;
|
|
73
65
|
};
|
|
74
66
|
/**
|
|
@@ -82,16 +74,12 @@ const getDefaultDir = () => {
|
|
|
82
74
|
* @param {Element} element will use the <html> element by default
|
|
83
75
|
* @returns {String} 'ltr' or 'rtl' or 'auto' (or `undefined` if no DOM is present)
|
|
84
76
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
77
|
function getTextDirection(element) {
|
|
88
78
|
if (_canUseDOM.canUseDOM) {
|
|
89
79
|
if (typeof element === 'undefined' || element === document.documentElement) return getDefaultDir();
|
|
90
80
|
return element.getAttribute('dir') || (0, _getComputedStyle.getComputedStyle)(element).direction;
|
|
91
81
|
}
|
|
92
|
-
|
|
93
82
|
return void 0;
|
|
94
83
|
}
|
|
95
|
-
|
|
96
84
|
var _default = getTextDirection;
|
|
97
85
|
exports.default = _default;
|
package/lib/index.js
CHANGED
|
@@ -69,23 +69,13 @@ Object.defineProperty(exports, "textDirectionContextConsumer", {
|
|
|
69
69
|
return _textDirectionContextConsumer.textDirectionContextConsumer;
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
|
-
|
|
73
72
|
var _ApplyLocale = require("./ApplyLocale");
|
|
74
|
-
|
|
75
73
|
var _ApplyLocaleContext = require("./ApplyLocale/ApplyLocaleContext");
|
|
76
|
-
|
|
77
74
|
var _bidirectional = require("./bidirectional");
|
|
78
|
-
|
|
79
75
|
var _textDirectionContextConsumer = require("./textDirectionContextConsumer");
|
|
80
|
-
|
|
81
76
|
var _DateTime = require("./DateTime");
|
|
82
|
-
|
|
83
77
|
var _getTextDirection = require("./getTextDirection");
|
|
84
|
-
|
|
85
78
|
var _I18nPropTypes = require("./I18nPropTypes");
|
|
86
|
-
|
|
87
79
|
var _Locale = require("./Locale");
|
|
88
|
-
|
|
89
80
|
var _TextDirectionContext = require("./TextDirectionContext");
|
|
90
|
-
|
|
91
81
|
var _ApplyTextDirection = require("./ApplyTextDirection");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-i18n",
|
|
3
|
-
"version": "8.33.2
|
|
3
|
+
"version": "8.33.2",
|
|
4
4
|
"description": "Helper components and utilities for internationalization.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,18 +23,18 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-babel-preset": "8.33.2
|
|
27
|
-
"@instructure/ui-test-utils": "8.33.2
|
|
26
|
+
"@instructure/ui-babel-preset": "8.33.2",
|
|
27
|
+
"@instructure/ui-test-utils": "8.33.2",
|
|
28
28
|
"@types/hoist-non-react-statics": "^3.3.1"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "^7.13.10",
|
|
32
|
-
"@instructure/shared-types": "8.33.2
|
|
33
|
-
"@instructure/ui-decorator": "8.33.2
|
|
34
|
-
"@instructure/ui-dom-utils": "8.33.2
|
|
35
|
-
"@instructure/ui-prop-types": "8.33.2
|
|
36
|
-
"@instructure/ui-react-utils": "8.33.2
|
|
37
|
-
"@instructure/ui-utils": "8.33.2
|
|
32
|
+
"@instructure/shared-types": "8.33.2",
|
|
33
|
+
"@instructure/ui-decorator": "8.33.2",
|
|
34
|
+
"@instructure/ui-dom-utils": "8.33.2",
|
|
35
|
+
"@instructure/ui-prop-types": "8.33.2",
|
|
36
|
+
"@instructure/ui-react-utils": "8.33.2",
|
|
37
|
+
"@instructure/ui-utils": "8.33.2",
|
|
38
38
|
"hoist-non-react-statics": "^3.3.2",
|
|
39
39
|
"moment-timezone": "^0.5",
|
|
40
40
|
"prop-types": "^15"
|