@semcore/core 16.6.0 → 16.6.1
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/lib/core-types/Component.d.ts +79 -33
- package/lib/core-types/Component.js +46 -14
- package/lib/core-types/Component.js.map +1 -1
- package/lib/core-types/Component.mjs +7 -11
- package/lib/core-types/Component.mjs.map +1 -1
- package/lib/core-types/symbols.mjs +9 -9
- package/lib/coreFactory.d.ts +23 -6
- package/lib/coreFactory.js +22 -53
- package/lib/coreFactory.js.map +1 -1
- package/lib/coreFactory.mjs +35 -54
- package/lib/coreFactory.mjs.map +1 -1
- package/lib/enhancement/Children.mjs +1 -1
- package/lib/enhancement/bindHandler.d.ts +5 -0
- package/lib/enhancement/bindHandler.js +53 -0
- package/lib/enhancement/bindHandler.js.map +1 -0
- package/lib/enhancement/bindHandler.mjs +48 -0
- package/lib/enhancement/bindHandler.mjs.map +1 -0
- package/lib/enhancement/hoistProps.d.ts +10 -0
- package/lib/enhancement/hoistProps.js +95 -0
- package/lib/enhancement/hoistProps.js.map +1 -0
- package/lib/enhancement/hoistProps.mjs +78 -0
- package/lib/enhancement/hoistProps.mjs.map +1 -0
- package/lib/enhancement/staticChildren.mjs +3 -3
- package/lib/enhancement/style.mjs +2 -2
- package/lib/esm/core-types/Component.mjs +7 -11
- package/lib/esm/core-types/symbols.mjs +9 -9
- package/lib/esm/coreFactory.mjs +35 -54
- package/lib/esm/enhancement/Children.mjs +1 -1
- package/lib/esm/enhancement/bindHandler.mjs +48 -0
- package/lib/esm/enhancement/hoistProps.mjs +78 -0
- package/lib/esm/enhancement/staticChildren.mjs +3 -3
- package/lib/esm/enhancement/style.mjs +2 -2
- package/lib/esm/styled/sstyled.mjs +1 -1
- package/lib/esm/utils/createHoc.mjs +42 -0
- package/lib/esm/utils/enhances/WithI18n.mjs +46 -1
- package/lib/esm/utils/getDisplayName.mjs +6 -0
- package/lib/esm/utils/ref.mjs +14 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.js.map +1 -1
- package/lib/index.mjs.map +1 -1
- package/lib/styled/index.d.ts +5 -1
- package/lib/styled/index.js.map +1 -1
- package/lib/styled/index.mjs.map +1 -1
- package/lib/styled/sstyled.mjs +1 -1
- package/lib/utils/ScreenReaderOnly.d.ts +8 -0
- package/lib/utils/ScreenReaderOnly.js +30 -0
- package/lib/utils/ScreenReaderOnly.js.map +1 -0
- package/lib/utils/ScreenReaderOnly.mjs +24 -0
- package/lib/utils/ScreenReaderOnly.mjs.map +1 -0
- package/lib/utils/createHoc.d.ts +3 -0
- package/lib/utils/createHoc.js +52 -0
- package/lib/utils/createHoc.js.map +1 -0
- package/lib/utils/createHoc.mjs +42 -0
- package/lib/utils/createHoc.mjs.map +1 -0
- package/lib/utils/enhances/WithAutoFocus.d.ts +14 -0
- package/lib/utils/enhances/WithAutoFocus.js +72 -0
- package/lib/utils/enhances/WithAutoFocus.js.map +1 -0
- package/lib/utils/enhances/WithAutoFocus.mjs +66 -0
- package/lib/utils/enhances/WithAutoFocus.mjs.map +1 -0
- package/lib/utils/enhances/WithCSS.d.ts +30 -2
- package/lib/utils/enhances/WithCSS.js +57 -4
- package/lib/utils/enhances/WithCSS.js.map +1 -1
- package/lib/utils/enhances/WithCSS.mjs +53 -2
- package/lib/utils/enhances/WithCSS.mjs.map +1 -1
- package/lib/utils/enhances/WithI18n.d.ts +30 -1
- package/lib/utils/enhances/WithI18n.js +57 -1
- package/lib/utils/enhances/WithI18n.js.map +1 -1
- package/lib/utils/enhances/WithI18n.mjs +46 -1
- package/lib/utils/enhances/WithI18n.mjs.map +1 -1
- package/lib/utils/enhances/WithKeyboardFocus.d.ts +46 -0
- package/lib/utils/enhances/WithKeyboardFocus.js +94 -0
- package/lib/utils/enhances/WithKeyboardFocus.js.map +1 -0
- package/lib/utils/enhances/WithKeyboardFocus.mjs +88 -0
- package/lib/utils/enhances/WithKeyboardFocus.mjs.map +1 -0
- package/lib/utils/enhances/WithRef.d.ts +3 -0
- package/lib/utils/enhances/WithRef.js +25 -0
- package/lib/utils/enhances/WithRef.js.map +1 -0
- package/lib/utils/enhances/WithRef.mjs +18 -0
- package/lib/utils/enhances/WithRef.mjs.map +1 -0
- package/lib/utils/enhances/animatedSizeEnhance.d.ts +4 -0
- package/lib/utils/enhances/animatedSizeEnhance.js +2 -0
- package/lib/utils/enhances/animatedSizeEnhance.js.map +1 -1
- package/lib/utils/enhances/animatedSizeEnhance.mjs +3 -0
- package/lib/utils/enhances/animatedSizeEnhance.mjs.map +1 -1
- package/lib/utils/enhances/autoFocusEnhance.d.ts +10 -0
- package/lib/utils/enhances/autoFocusEnhance.js +45 -0
- package/lib/utils/enhances/autoFocusEnhance.js.map +1 -0
- package/lib/utils/enhances/autoFocusEnhance.mjs +38 -0
- package/lib/utils/enhances/autoFocusEnhance.mjs.map +1 -0
- package/lib/utils/enhances/i18nEnhance.d.ts +4 -0
- package/lib/utils/enhances/i18nEnhance.js +2 -0
- package/lib/utils/enhances/i18nEnhance.js.map +1 -1
- package/lib/utils/enhances/i18nEnhance.mjs.map +1 -1
- package/lib/utils/enhances/keyboardFocusEnhance.d.ts +27 -0
- package/lib/utils/enhances/keyboardFocusEnhance.js +63 -0
- package/lib/utils/enhances/keyboardFocusEnhance.js.map +1 -0
- package/lib/utils/enhances/keyboardFocusEnhance.mjs +57 -0
- package/lib/utils/enhances/keyboardFocusEnhance.mjs.map +1 -0
- package/lib/utils/eventEmitter.d.ts +6 -10
- package/lib/utils/eventEmitter.js +27 -55
- package/lib/utils/eventEmitter.js.map +1 -1
- package/lib/utils/eventEmitter.mjs +27 -55
- package/lib/utils/eventEmitter.mjs.map +1 -1
- package/lib/utils/getDisplayName.mjs +5 -3
- package/lib/utils/if.d.ts +11 -0
- package/lib/utils/if.js +15 -0
- package/lib/utils/if.js.map +1 -0
- package/lib/utils/if.mjs +9 -0
- package/lib/utils/if.mjs.map +1 -0
- package/lib/utils/injectStyle.js +1 -1
- package/lib/utils/injectStyle.mjs +1 -1
- package/lib/utils/ref.d.ts +3 -1
- package/lib/utils/ref.js +14 -0
- package/lib/utils/ref.js.map +1 -1
- package/lib/utils/ref.mjs +14 -0
- package/lib/utils/ref.mjs.map +1 -1
- package/lib/utils/uniqueID.d.ts +4 -0
- package/lib/utils/uniqueID.js +3 -1
- package/lib/utils/uniqueID.js.map +1 -1
- package/lib/utils/uniqueID.mjs +4 -1
- package/lib/utils/uniqueID.mjs.map +1 -1
- package/lib/utils/use/useColorResolver.js +1 -1
- package/lib/utils/use/useColorResolver.js.map +1 -1
- package/lib/utils/use/useColorResolver.mjs +1 -1
- package/lib/utils/use/useColorResolver.mjs.map +1 -1
- package/lib/utils/use/useCss.d.ts +4 -0
- package/lib/utils/use/useCss.js +19 -0
- package/lib/utils/use/useCss.js.map +1 -0
- package/lib/utils/use/useCss.mjs +12 -0
- package/lib/utils/use/useCss.mjs.map +1 -0
- package/lib/utils/use/useEnhancedEffect.d.ts +1 -1
- package/lib/utils/zIndexStacking.d.ts +1 -3
- package/lib/utils/zIndexStacking.js.map +1 -1
- package/lib/utils/zIndexStacking.mjs.map +1 -1
- package/package.json +1 -1
- package/lib/decorators/propsObserver.d.ts +0 -11
- package/lib/decorators/propsObserver.js +0 -77
- package/lib/decorators/propsObserver.js.map +0 -1
- package/lib/decorators/propsObserver.mjs +0 -70
- package/lib/decorators/propsObserver.mjs.map +0 -1
- package/lib/decorators/reactive.d.ts +0 -11
- package/lib/decorators/reactive.js +0 -51
- package/lib/decorators/reactive.js.map +0 -1
- package/lib/decorators/reactive.mjs +0 -45
- package/lib/decorators/reactive.mjs.map +0 -1
- package/lib/utils/indentStyles.d.ts +0 -3
- package/lib/utils/indentStyles.js +0 -45
- package/lib/utils/indentStyles.js.map +0 -1
- package/lib/utils/indentStyles.mjs +0 -36
- package/lib/utils/indentStyles.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WithAutoFocus.js","names":["_react","require","_reactDom","_createHoc","_interopRequireDefault","EnhancedWithAutoFocus","_PureComponent","_this","_classCallCheck2","_len","arguments","length","args","Array","_key","_callSuper2","concat","_defineProperty2","_inherits2","_createClass2","key","value","notUsingNativeAutoFocus","autoFocus","props","componentDidMount","node","findDOMNode","timer","setTimeout","focus","componentWillUnmount","clearTimeout","render","_ref","children","undefined","PureComponent","_default","exports","createHoc"],"sources":["../../../src/utils/enhances/WithAutoFocus.tsx"],"sourcesContent":["import type React from 'react';\nimport { PureComponent } from 'react';\nimport { findDOMNode } from 'react-dom';\n\nimport type { UnknownProperties } from '../../core-types/UnknownProperties';\nimport createHoc from '../createHoc';\n\n/** @deprecated */\nexport interface IEnhancedWithAutoFocusProps\n extends EnhancedWithAutoFocusProps,\n UnknownProperties {}\nexport type EnhancedWithAutoFocusProps = {\n /**\n * @default undefined\n */\n autoFocus?: string | number | boolean;\n children?: (props: IEnhancedWithAutoFocusProps) => React.ReactNode;\n};\n\nclass EnhancedWithAutoFocus extends PureComponent<IEnhancedWithAutoFocusProps> {\n static displayName = 'EnhancedWithAutoFocus';\n\n static defaultProps = {\n autoFocus: undefined,\n };\n\n private timer: ReturnType<typeof setTimeout> | undefined;\n\n notUsingNativeAutoFocus() {\n const { autoFocus } = this.props;\n return typeof autoFocus === 'boolean' || typeof autoFocus === 'number';\n }\n\n componentDidMount() {\n if (this.notUsingNativeAutoFocus()) {\n const { autoFocus } = this.props;\n if (autoFocus === false) return;\n const node = findDOMNode(this);\n if (!node) return;\n // @ts-ignore\n this.timer = setTimeout(() => node.focus(), (autoFocus as number) || 0);\n }\n }\n\n componentWillUnmount() {\n clearTimeout(this.timer);\n }\n\n render() {\n const { children } = this.props as any;\n const props = {} as IEnhancedWithAutoFocusProps;\n if (this.notUsingNativeAutoFocus()) {\n props.autoFocus = undefined;\n }\n return children(props);\n }\n}\n\nexport default createHoc(EnhancedWithAutoFocus);\n"],"mappings":";;;;;;;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAGA,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AA,EAED,SAAAU,oBAAoBA,CAAA,EAAG;MACrBC,YAAY,CAAC,IAAI,CAACJ,KAAK,CAAC;IAC1B;EAAC;IAAAR,GAAA;IAAAC,KAAA,EAED,SAAAY,MAAMA,CAAA,EAAG;MACP,IAAAC,IAAA,GAAqB,IAAI,CAACV,KAAK;QAAvBW,QAAQ,GAAAD,IAAA,CAARC,QAAQ;MAChB,IAAMX,KAAK,GAAG,CAAC,CAAgC;MAC/C,IAAI,IAAI,CAACF,uBAAuB,CAAC,CAAC,EAAE;QAClCE,KAAK,CAACD,SAAS,GAAGa,SAAS;MAC7B;MACA,OAAOD,QAAQ,CAACX,KAAK,CAAC;IACxB;EAAC;AAAA,EApCiCa,oBAAa;AAAA,IAAApB,gBAAA,aAA3CZ,qBAAqB,iBACJ,uBAAuB;AAAA,IAAAY,gBAAA,aADxCZ,qBAAqB,kBAGH;EACpBkB,SAAS,EAAEa;AACb,CAAC;AAAA,IAAAE,QAAA,GAAAC,OAAA,cAkCY,IAAAC,qBAAS,EAACnC,qBAAqB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _callSuper from "@babel/runtime/helpers/esm/callSuper";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
6
|
+
import { PureComponent } from 'react';
|
|
7
|
+
import { findDOMNode } from 'react-dom';
|
|
8
|
+
import createHoc from "../createHoc.mjs";
|
|
9
|
+
|
|
10
|
+
/** @deprecated */
|
|
11
|
+
var EnhancedWithAutoFocus = /*#__PURE__*/function (_PureComponent) {
|
|
12
|
+
function EnhancedWithAutoFocus() {
|
|
13
|
+
var _this;
|
|
14
|
+
_classCallCheck(this, EnhancedWithAutoFocus);
|
|
15
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
16
|
+
args[_key] = arguments[_key];
|
|
17
|
+
}
|
|
18
|
+
_this = _callSuper(this, EnhancedWithAutoFocus, [].concat(args));
|
|
19
|
+
_defineProperty(_this, "timer", void 0);
|
|
20
|
+
return _this;
|
|
21
|
+
}
|
|
22
|
+
_inherits(EnhancedWithAutoFocus, _PureComponent);
|
|
23
|
+
return _createClass(EnhancedWithAutoFocus, [{
|
|
24
|
+
key: "notUsingNativeAutoFocus",
|
|
25
|
+
value: function notUsingNativeAutoFocus() {
|
|
26
|
+
var autoFocus = this.props.autoFocus;
|
|
27
|
+
return typeof autoFocus === 'boolean' || typeof autoFocus === 'number';
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
key: "componentDidMount",
|
|
31
|
+
value: function componentDidMount() {
|
|
32
|
+
if (this.notUsingNativeAutoFocus()) {
|
|
33
|
+
var autoFocus = this.props.autoFocus;
|
|
34
|
+
if (autoFocus === false) return;
|
|
35
|
+
var node = findDOMNode(this);
|
|
36
|
+
if (!node) return;
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
this.timer = setTimeout(function () {
|
|
39
|
+
return node.focus();
|
|
40
|
+
}, autoFocus || 0);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
key: "componentWillUnmount",
|
|
45
|
+
value: function componentWillUnmount() {
|
|
46
|
+
clearTimeout(this.timer);
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
key: "render",
|
|
50
|
+
value: function render() {
|
|
51
|
+
var _ref = this.props,
|
|
52
|
+
children = _ref.children;
|
|
53
|
+
var props = {};
|
|
54
|
+
if (this.notUsingNativeAutoFocus()) {
|
|
55
|
+
props.autoFocus = undefined;
|
|
56
|
+
}
|
|
57
|
+
return children(props);
|
|
58
|
+
}
|
|
59
|
+
}]);
|
|
60
|
+
}(PureComponent);
|
|
61
|
+
_defineProperty(EnhancedWithAutoFocus, "displayName", 'EnhancedWithAutoFocus');
|
|
62
|
+
_defineProperty(EnhancedWithAutoFocus, "defaultProps", {
|
|
63
|
+
autoFocus: undefined
|
|
64
|
+
});
|
|
65
|
+
export default createHoc(EnhancedWithAutoFocus);
|
|
66
|
+
//# sourceMappingURL=WithAutoFocus.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WithAutoFocus.mjs","names":["PureComponent","findDOMNode","createHoc","EnhancedWithAutoFocus","_PureComponent","_this","_classCallCheck","_len","arguments","length","args","Array","_key","_callSuper","concat","_defineProperty","_inherits","_createClass","key","value","notUsingNativeAutoFocus","autoFocus","props","componentDidMount","node","timer","setTimeout","focus","componentWillUnmount","clearTimeout","render","_ref","children","undefined"],"sources":["../../../src/utils/enhances/WithAutoFocus.tsx"],"sourcesContent":["import type React from 'react';\nimport { PureComponent } from 'react';\nimport { findDOMNode } from 'react-dom';\n\nimport type { UnknownProperties } from '../../core-types/UnknownProperties';\nimport createHoc from '../createHoc';\n\n/** @deprecated */\nexport interface IEnhancedWithAutoFocusProps\n extends EnhancedWithAutoFocusProps,\n UnknownProperties {}\nexport type EnhancedWithAutoFocusProps = {\n /**\n * @default undefined\n */\n autoFocus?: string | number | boolean;\n children?: (props: IEnhancedWithAutoFocusProps) => React.ReactNode;\n};\n\nclass EnhancedWithAutoFocus extends PureComponent<IEnhancedWithAutoFocusProps> {\n static displayName = 'EnhancedWithAutoFocus';\n\n static defaultProps = {\n autoFocus: undefined,\n };\n\n private timer: ReturnType<typeof setTimeout> | undefined;\n\n notUsingNativeAutoFocus() {\n const { autoFocus } = this.props;\n return typeof autoFocus === 'boolean' || typeof autoFocus === 'number';\n }\n\n componentDidMount() {\n if (this.notUsingNativeAutoFocus()) {\n const { autoFocus } = this.props;\n if (autoFocus === false) return;\n const node = findDOMNode(this);\n if (!node) return;\n // @ts-ignore\n this.timer = setTimeout(() => node.focus(), (autoFocus as number) || 0);\n }\n }\n\n componentWillUnmount() {\n clearTimeout(this.timer);\n }\n\n render() {\n const { children } = this.props as any;\n const props = {} as IEnhancedWithAutoFocusProps;\n if (this.notUsingNativeAutoFocus()) {\n props.autoFocus = undefined;\n }\n return children(props);\n }\n}\n\nexport default createHoc(EnhancedWithAutoFocus);\n"],"mappings":";;;;;AACA,SAASA,aAAa,QAAQ,OAAO;AACrC,SAASC,WAAW,QAAQ,WAAW;AAGvC,OAAOC,SAAS,MAAM,kBAAc;;AAEpC;AAAA,IAYMC,qBAAqB,0BAAAC,cAAA;EAAA,SAAAD,sBAAA;IAAA,IAAAE,KAAA;IAAAC,eAAA,OAAAH,qBAAA;IAAA,SAAAI,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAC,IAAA,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAAF,IAAA,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IAAA;IAAAP,KAAA,GAAAQ,UAAA,OAAAV,qBAAA,KAAAW,MAAA,CAAAJ,IAAA;IAAAK,eAAA,CAAAV,KAAA;IAAA,OAAAA,KAAA;EAAA;EAAAW,SAAA,CAAAb,qBAAA,EAAAC,cAAA;EAAA,OAAAa,YAAA,CAAAd,qBAAA;IAAAe,GAAA;IAAAC,KAAA,EASzB,SAAAC,uBAAuBA,CAAA,EAAG;MACxB,IAAQC,SAAS,GAAK,IAAI,CAACC,KAAK,CAAxBD,SAAS;MACjB,OAAO,OAAOA,SAAS,KAAK,SAAS,IAAI,OAAOA,SAAS,KAAK,QAAQ;IACxE;EAAC;IAAAH,GAAA;IAAAC,KAAA,EAED,SAAAI,iBAAiBA,CAAA,EAAG;MAClB,IAAI,IAAI,CAACH,uBAAuB,CAAC,CAAC,EAAE;QAClC,IAAQC,SAAS,GAAK,IAAI,CAACC,KAAK,CAAxBD,SAAS;QACjB,IAAIA,SAAS,KAAK,KAAK,EAAE;QACzB,IAAMG,IAAI,GAAGvB,WAAW,CAAC,IAAI,CAAC;QAC9B,IAAI,CAACuB,IAAI,EAAE;QACX;QACA,IAAI,CAACC,KAAK,GAAGC,UAAU,CAAC;UAAA,OAAMF,IAAI,CAACG,KAAK,CAAC,CAAC;QAAA,GAAGN,SAAS,IAAe,CAAC,CAAC;MACzE;IACF;EAAC;IAAAH,GAAA;IAAAC,KAAA,EAED,SAAAS,oBAAoBA,CAAA,EAAG;MACrBC,YAAY,CAAC,IAAI,CAACJ,KAAK,CAAC;IAC1B;EAAC;IAAAP,GAAA;IAAAC,KAAA,EAED,SAAAW,MAAMA,CAAA,EAAG;MACP,IAAAC,IAAA,GAAqB,IAAI,CAACT,KAAK;QAAvBU,QAAQ,GAAAD,IAAA,CAARC,QAAQ;MAChB,IAAMV,KAAK,GAAG,CAAC,CAAgC;MAC/C,IAAI,IAAI,CAACF,uBAAuB,CAAC,CAAC,EAAE;QAClCE,KAAK,CAACD,SAAS,GAAGY,SAAS;MAC7B;MACA,OAAOD,QAAQ,CAACV,KAAK,CAAC;IACxB;EAAC;AAAA,EApCiCtB,aAAa;AAAAe,eAAA,CAA3CZ,qBAAqB,iBACJ,uBAAuB;AAAAY,eAAA,CADxCZ,qBAAqB,kBAGH;EACpBkB,SAAS,EAAEY;AACb,CAAC;AAkCH,eAAe/B,SAAS,CAACC,qBAAqB,CAAC","ignoreList":[]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { NanoOptions } from '@phytonmk/nano-css';
|
|
2
2
|
import type { CssLikeObject } from '@phytonmk/nano-css/types/common';
|
|
3
|
-
import React from 'react';
|
|
3
|
+
import React, { PureComponent } from 'react';
|
|
4
|
+
import type { UnknownProperties } from '../../core-types/UnknownProperties';
|
|
5
|
+
declare const getStylesheet: () => string;
|
|
4
6
|
/**
|
|
5
7
|
* Function to clear the nano CSS styles object from keys with undefined value
|
|
6
8
|
* @param {Object} obj - nano CSS styles object
|
|
@@ -10,4 +12,30 @@ declare function normaliseCss(obj: CssLikeObject): any;
|
|
|
10
12
|
declare const WithCssContext: React.Context<NanoOptions>;
|
|
11
13
|
declare const Provider: React.Provider<NanoOptions>;
|
|
12
14
|
declare function initNanoCss(options?: NanoOptions): import("@phytonmk/nano-css").NanoRenderer;
|
|
13
|
-
|
|
15
|
+
/** @deprecated */
|
|
16
|
+
export interface IEnhancedWithCSSProps extends EnhancedWithCSSProps, UnknownProperties {
|
|
17
|
+
}
|
|
18
|
+
export type EnhancedWithCSSProps = {
|
|
19
|
+
className?: string;
|
|
20
|
+
css?: {};
|
|
21
|
+
children(props: {
|
|
22
|
+
className: string | undefined;
|
|
23
|
+
}): React.ReactNode;
|
|
24
|
+
};
|
|
25
|
+
declare class EnhancedWithCSS extends PureComponent<IEnhancedWithCSSProps> {
|
|
26
|
+
static contextType: React.Context<NanoOptions>;
|
|
27
|
+
static defaultProps: {
|
|
28
|
+
css: {};
|
|
29
|
+
};
|
|
30
|
+
state: {
|
|
31
|
+
dynamicClassName: string;
|
|
32
|
+
};
|
|
33
|
+
static getDerivedStateFromProps(props: any): {
|
|
34
|
+
dynamicClassName: string | undefined;
|
|
35
|
+
};
|
|
36
|
+
constructor(props: any, context: any);
|
|
37
|
+
render(): React.ReactNode;
|
|
38
|
+
}
|
|
39
|
+
export { getStylesheet, EnhancedWithCSS, Provider, WithCssContext, initNanoCss, normaliseCss };
|
|
40
|
+
declare const _default: (options?: {}) => (WrappedComponent: React.ComponentType) => React.ComponentClass;
|
|
41
|
+
export default _default;
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
|
|
3
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
|
-
exports.WithCssContext = exports.Provider = void 0;
|
|
8
|
+
exports.getStylesheet = exports["default"] = exports.WithCssContext = exports.Provider = exports.EnhancedWithCSS = void 0;
|
|
8
9
|
exports.initNanoCss = initNanoCss;
|
|
9
10
|
exports.normaliseCss = normaliseCss;
|
|
10
|
-
var
|
|
11
|
-
var
|
|
11
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
var _callSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/callSuper"));
|
|
14
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
17
|
+
var _createHoc = _interopRequireDefault(require("../createHoc"));
|
|
18
|
+
var _CSSinJS2 = _interopRequireDefault(require("../CSSinJS"));
|
|
19
|
+
var getStylesheet = exports.getStylesheet = function getStylesheet() {
|
|
20
|
+
return (0, _CSSinJS2["default"])().raw;
|
|
21
|
+
};
|
|
22
|
+
|
|
12
23
|
/**
|
|
13
24
|
* Function to clear the nano CSS styles object from keys with undefined value
|
|
14
25
|
* @param {Object} obj - nano CSS styles object
|
|
@@ -27,6 +38,48 @@ var WithCssContext = exports.WithCssContext = /*#__PURE__*/_react["default"].cre
|
|
|
27
38
|
var Provider = exports.Provider = WithCssContext.Provider;
|
|
28
39
|
function initNanoCss() {
|
|
29
40
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
30
|
-
return (0,
|
|
41
|
+
return (0, _CSSinJS2["default"])(options);
|
|
31
42
|
}
|
|
43
|
+
|
|
44
|
+
/** @deprecated */
|
|
45
|
+
var EnhancedWithCSS = exports.EnhancedWithCSS = /*#__PURE__*/function (_PureComponent) {
|
|
46
|
+
function EnhancedWithCSS(props, context) {
|
|
47
|
+
var _this;
|
|
48
|
+
(0, _classCallCheck2["default"])(this, EnhancedWithCSS);
|
|
49
|
+
_this = (0, _callSuper2["default"])(this, EnhancedWithCSS, [props, context]);
|
|
50
|
+
(0, _defineProperty2["default"])(_this, "state", {
|
|
51
|
+
dynamicClassName: ''
|
|
52
|
+
});
|
|
53
|
+
initNanoCss(context);
|
|
54
|
+
return _this;
|
|
55
|
+
}
|
|
56
|
+
(0, _inherits2["default"])(EnhancedWithCSS, _PureComponent);
|
|
57
|
+
return (0, _createClass2["default"])(EnhancedWithCSS, [{
|
|
58
|
+
key: "render",
|
|
59
|
+
value: function render() {
|
|
60
|
+
var _this$props = this.props,
|
|
61
|
+
children = _this$props.children,
|
|
62
|
+
_this$props$className = _this$props.className,
|
|
63
|
+
className = _this$props$className === void 0 ? '' : _this$props$className;
|
|
64
|
+
var dynamicClassName = this.state.dynamicClassName;
|
|
65
|
+
return children({
|
|
66
|
+
className: className + dynamicClassName || undefined
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}], [{
|
|
70
|
+
key: "getDerivedStateFromProps",
|
|
71
|
+
value: function getDerivedStateFromProps(props) {
|
|
72
|
+
var _CSSinJS$cache, _CSSinJS;
|
|
73
|
+
var cleanCss = normaliseCss(props.css);
|
|
74
|
+
return {
|
|
75
|
+
dynamicClassName: Object.keys(cleanCss).length ? (_CSSinJS$cache = (_CSSinJS = (0, _CSSinJS2["default"])()).cache) === null || _CSSinJS$cache === void 0 ? void 0 : _CSSinJS$cache.call(_CSSinJS, cleanCss) : ''
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}]);
|
|
79
|
+
}(_react.PureComponent);
|
|
80
|
+
(0, _defineProperty2["default"])(EnhancedWithCSS, "contextType", WithCssContext);
|
|
81
|
+
(0, _defineProperty2["default"])(EnhancedWithCSS, "defaultProps", {
|
|
82
|
+
css: {}
|
|
83
|
+
});
|
|
84
|
+
var _default = exports["default"] = (0, _createHoc["default"])(EnhancedWithCSS);
|
|
32
85
|
//# sourceMappingURL=WithCSS.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WithCSS.js","names":["_react","
|
|
1
|
+
{"version":3,"file":"WithCSS.js","names":["_react","_interopRequireWildcard","require","_createHoc","_interopRequireDefault","_CSSinJS2","getStylesheet","exports","CSSinJS","raw","normaliseCss","obj","Object","keys","reduce","acc","key","result","undefined","WithCssContext","React","createContext","Provider","initNanoCss","options","arguments","length","EnhancedWithCSS","_PureComponent","props","context","_this","_classCallCheck2","_callSuper2","_defineProperty2","dynamicClassName","_inherits2","_createClass2","value","render","_this$props","children","_this$props$className","className","state","getDerivedStateFromProps","_CSSinJS$cache","_CSSinJS","cleanCss","css","cache","call","PureComponent","_default","createHoc"],"sources":["../../../src/utils/enhances/WithCSS.tsx"],"sourcesContent":["import type { NanoOptions } from '@phytonmk/nano-css';\nimport type { CssLikeObject } from '@phytonmk/nano-css/types/common';\nimport React, { PureComponent } from 'react';\n\nimport type { UnknownProperties } from '../../core-types/UnknownProperties';\nimport createHoc from '../createHoc';\nimport CSSinJS from '../CSSinJS';\n\nconst getStylesheet = () => CSSinJS().raw;\n\n/**\n * Function to clear the nano CSS styles object from keys with undefined value\n * @param {Object} obj - nano CSS styles object\n * @returns {Object}\n */\nfunction normaliseCss(obj: CssLikeObject) {\n return Object.keys(obj).reduce((acc: any, key) => {\n const result = acc;\n if (obj[key] !== undefined) {\n result[key] = obj[key];\n }\n return result;\n }, {});\n}\n\nconst WithCssContext = React.createContext<NanoOptions>({});\nconst { Provider } = WithCssContext;\n\nfunction initNanoCss(options: NanoOptions = {}) {\n return CSSinJS(options);\n}\n\n/** @deprecated */\nexport interface IEnhancedWithCSSProps extends EnhancedWithCSSProps, UnknownProperties {}\nexport type EnhancedWithCSSProps = {\n className?: string;\n css?: {};\n\n children(props: { className: string | undefined }): React.ReactNode;\n};\n\nclass EnhancedWithCSS extends PureComponent<IEnhancedWithCSSProps> {\n static contextType = WithCssContext;\n\n static defaultProps = {\n css: {},\n };\n\n state = {\n dynamicClassName: '',\n };\n\n static getDerivedStateFromProps(props: any) {\n const cleanCss = normaliseCss(props.css);\n return {\n dynamicClassName: Object.keys(cleanCss).length ? CSSinJS().cache?.(cleanCss) : '',\n };\n }\n\n constructor(props: any, context: any) {\n super(props, context);\n\n initNanoCss(context);\n }\n\n render() {\n const { children, className = '' } = this.props;\n const { dynamicClassName } = this.state;\n return children({\n className: className + dynamicClassName || undefined,\n });\n }\n}\n\nexport { getStylesheet, EnhancedWithCSS, Provider, WithCssContext, initNanoCss, normaliseCss };\nexport default createHoc(EnhancedWithCSS);\n"],"mappings":";;;;;;;;;;;;;;;AAEA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,SAAA,GAAAD,sBAAA,CAAAF,OAAA;AAEA,IAAMI,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG,SAAhBA,aAAaA,CAAA;EAAA,OAAS,IAAAE,oBAAO,EAAC,CAAC,CAACC,GAAG;AAAA;;AAEzC;AACA;AACA;AACA;AACA;AACA,SAASC,YAAYA,CAACC,GAAkB,EAAE;EACxC,OAAOC,MAAM,CAACC,IAAI,CAACF,GAAG,CAAC,CAACG,MAAM,CAAC,UAACC,GAAQ,EAAEC,GAAG,EAAK;IAChD,IAAMC,MAAM,GAAGF,GAAG;IAClB,IAAIJ,GAAG,CAACK,GAAG,CAAC,KAAKE,SAAS,EAAE;MAC1BD,MAAM,CAACD,GAAG,CAAC,GAAGL,GAAG,CAACK,GAAG,CAAC;IACxB;IACA,OAAOC,MAAM;EACf,CAAC,EAAE,CAAC,CAAC,CAAC;AACR;AAEA,IAAME,cAAc,GAAAZ,OAAA,CAAAY,cAAA,gBAAGC,iBAAK,CAACC,aAAa,CAAc,CAAC,CAAC,CAAC;AAC3D,IAAQC,QAAQ,GAAAf,OAAA,CAAAe,QAAA,GAAKH,cAAc,CAA3BG,QAAQ;AAEhB,SAASC,WAAWA,CAAA,EAA4B;EAAA,IAA3BC,OAAoB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,S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GAAG,CAAAC,QAAA,OAAAvC,oBAAO,EAAC,CAAC,EAAC0C,KAAK,cAAAJ,cAAA,uBAAfA,cAAA,CAAAK,IAAA,CAAAJ,QAAA,EAAkBC,QAAQ,CAAC,GAAG;MACjF,CAAC;IACH;EAAC;AAAA,EAhB2BI,oBAAa;AAAA,IAAAlB,gBAAA,aAArCP,eAAe,iBACER,cAAc;AAAA,IAAAe,gBAAA,aAD/BP,eAAe,kBAGG;EACpBsB,GAAG,EAAE,CAAC;AACR,CAAC;AAAA,IAAAI,QAAA,GAAA9C,OAAA,cA6BY,IAAA+C,qBAAS,EAAC3B,eAAe,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _callSuper from "@babel/runtime/helpers/esm/callSuper";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
6
|
+
import React, { PureComponent } from 'react';
|
|
7
|
+
import createHoc from "../createHoc.mjs";
|
|
2
8
|
import CSSinJS from "../CSSinJS.mjs";
|
|
9
|
+
var getStylesheet = function getStylesheet() {
|
|
10
|
+
return CSSinJS().raw;
|
|
11
|
+
};
|
|
3
12
|
|
|
4
13
|
/**
|
|
5
14
|
* Function to clear the nano CSS styles object from keys with undefined value
|
|
@@ -21,5 +30,47 @@ function initNanoCss() {
|
|
|
21
30
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
22
31
|
return CSSinJS(options);
|
|
23
32
|
}
|
|
24
|
-
|
|
33
|
+
|
|
34
|
+
/** @deprecated */
|
|
35
|
+
var EnhancedWithCSS = /*#__PURE__*/function (_PureComponent) {
|
|
36
|
+
function EnhancedWithCSS(props, context) {
|
|
37
|
+
var _this;
|
|
38
|
+
_classCallCheck(this, EnhancedWithCSS);
|
|
39
|
+
_this = _callSuper(this, EnhancedWithCSS, [props, context]);
|
|
40
|
+
_defineProperty(_this, "state", {
|
|
41
|
+
dynamicClassName: ''
|
|
42
|
+
});
|
|
43
|
+
initNanoCss(context);
|
|
44
|
+
return _this;
|
|
45
|
+
}
|
|
46
|
+
_inherits(EnhancedWithCSS, _PureComponent);
|
|
47
|
+
return _createClass(EnhancedWithCSS, [{
|
|
48
|
+
key: "render",
|
|
49
|
+
value: function render() {
|
|
50
|
+
var _this$props = this.props,
|
|
51
|
+
children = _this$props.children,
|
|
52
|
+
_this$props$className = _this$props.className,
|
|
53
|
+
className = _this$props$className === void 0 ? '' : _this$props$className;
|
|
54
|
+
var dynamicClassName = this.state.dynamicClassName;
|
|
55
|
+
return children({
|
|
56
|
+
className: className + dynamicClassName || undefined
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}], [{
|
|
60
|
+
key: "getDerivedStateFromProps",
|
|
61
|
+
value: function getDerivedStateFromProps(props) {
|
|
62
|
+
var _CSSinJS$cache, _CSSinJS;
|
|
63
|
+
var cleanCss = normaliseCss(props.css);
|
|
64
|
+
return {
|
|
65
|
+
dynamicClassName: Object.keys(cleanCss).length ? (_CSSinJS$cache = (_CSSinJS = CSSinJS()).cache) === null || _CSSinJS$cache === void 0 ? void 0 : _CSSinJS$cache.call(_CSSinJS, cleanCss) : ''
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}]);
|
|
69
|
+
}(PureComponent);
|
|
70
|
+
_defineProperty(EnhancedWithCSS, "contextType", WithCssContext);
|
|
71
|
+
_defineProperty(EnhancedWithCSS, "defaultProps", {
|
|
72
|
+
css: {}
|
|
73
|
+
});
|
|
74
|
+
export { getStylesheet, EnhancedWithCSS, Provider, WithCssContext, initNanoCss, normaliseCss };
|
|
75
|
+
export default createHoc(EnhancedWithCSS);
|
|
25
76
|
//# sourceMappingURL=WithCSS.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WithCSS.mjs","names":["React","CSSinJS","normaliseCss","obj","Object","keys","reduce","acc","key","result","undefined","WithCssContext","createContext","Provider","initNanoCss","options","arguments","length"],"sources":["../../../src/utils/enhances/WithCSS.tsx"],"sourcesContent":["import type { NanoOptions } from '@phytonmk/nano-css';\nimport type { CssLikeObject } from '@phytonmk/nano-css/types/common';\nimport React from 'react';\n\nimport CSSinJS from '../CSSinJS';\n\n/**\n * Function to clear the nano CSS styles object from keys with undefined value\n * @param {Object} obj - nano CSS styles object\n * @returns {Object}\n */\nfunction normaliseCss(obj: CssLikeObject) {\n return Object.keys(obj).reduce((acc: any, key) => {\n const result = acc;\n if (obj[key] !== undefined) {\n result[key] = obj[key];\n }\n return result;\n }, {});\n}\n\nconst WithCssContext = React.createContext<NanoOptions>({});\nconst { Provider } = WithCssContext;\n\nfunction initNanoCss(options: NanoOptions = {}) {\n return CSSinJS(options);\n}\n\nexport { Provider, WithCssContext, initNanoCss, normaliseCss };\n"],"mappings":"AAEA,OAAOA,KAAK,
|
|
1
|
+
{"version":3,"file":"WithCSS.mjs","names":["React","PureComponent","createHoc","CSSinJS","getStylesheet","raw","normaliseCss","obj","Object","keys","reduce","acc","key","result","undefined","WithCssContext","createContext","Provider","initNanoCss","options","arguments","length","EnhancedWithCSS","_PureComponent","props","context","_this","_classCallCheck","_callSuper","_defineProperty","dynamicClassName","_inherits","_createClass","value","render","_this$props","children","_this$props$className","className","state","getDerivedStateFromProps","_CSSinJS$cache","_CSSinJS","cleanCss","css","cache","call"],"sources":["../../../src/utils/enhances/WithCSS.tsx"],"sourcesContent":["import type { NanoOptions } from '@phytonmk/nano-css';\nimport type { CssLikeObject } from '@phytonmk/nano-css/types/common';\nimport React, { PureComponent } from 'react';\n\nimport type { UnknownProperties } from '../../core-types/UnknownProperties';\nimport createHoc from '../createHoc';\nimport CSSinJS from '../CSSinJS';\n\nconst getStylesheet = () => CSSinJS().raw;\n\n/**\n * Function to clear the nano CSS styles object from keys with undefined value\n * @param {Object} obj - nano CSS styles object\n * @returns {Object}\n */\nfunction normaliseCss(obj: CssLikeObject) {\n return Object.keys(obj).reduce((acc: any, key) => {\n const result = acc;\n if (obj[key] !== undefined) {\n result[key] = obj[key];\n }\n return result;\n }, {});\n}\n\nconst WithCssContext = React.createContext<NanoOptions>({});\nconst { Provider } = WithCssContext;\n\nfunction initNanoCss(options: NanoOptions = {}) {\n return CSSinJS(options);\n}\n\n/** @deprecated */\nexport interface IEnhancedWithCSSProps extends EnhancedWithCSSProps, UnknownProperties {}\nexport type EnhancedWithCSSProps = {\n className?: string;\n css?: {};\n\n children(props: { className: string | undefined }): React.ReactNode;\n};\n\nclass EnhancedWithCSS extends PureComponent<IEnhancedWithCSSProps> {\n static contextType = WithCssContext;\n\n static defaultProps = {\n css: {},\n };\n\n state = {\n dynamicClassName: '',\n };\n\n static getDerivedStateFromProps(props: any) {\n const cleanCss = normaliseCss(props.css);\n return {\n dynamicClassName: Object.keys(cleanCss).length ? CSSinJS().cache?.(cleanCss) : '',\n };\n }\n\n constructor(props: any, context: any) {\n super(props, context);\n\n initNanoCss(context);\n }\n\n render() {\n const { children, className = '' } = this.props;\n const { dynamicClassName } = this.state;\n return children({\n className: className + dynamicClassName || undefined,\n });\n }\n}\n\nexport { getStylesheet, EnhancedWithCSS, Provider, WithCssContext, initNanoCss, normaliseCss };\nexport default createHoc(EnhancedWithCSS);\n"],"mappings":";;;;;AAEA,OAAOA,KAAK,IAAIC,aAAa,QAAQ,OAAO;AAG5C,OAAOC,SAAS,MAAM,kBAAc;AACpC,OAAOC,OAAO,MAAM,gBAAY;AAEhC,IAAMC,aAAa,GAAG,SAAhBA,aAAaA,CAAA;EAAA,OAASD,OAAO,CAAC,CAAC,CAACE,GAAG;AAAA;;AAEzC;AACA;AACA;AACA;AACA;AACA,SAASC,YAAYA,CAACC,GAAkB,EAAE;EACxC,OAAOC,MAAM,CAACC,IAAI,CAACF,GAAG,CAAC,CAACG,MAAM,CAAC,UAACC,GAA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T,gBAAgB;MACxB,OAAOM,QAAQ,CAAC;QACdE,SAAS,EAAEA,SAAS,GAAGR,gBAAgB,IAAIhB;MAC7C,CAAC,CAAC;IACJ;EAAC;IAAAF,GAAA;IAAAqB,KAAA,EAnBD,SAAOO,wBAAwBA,CAAChB,KAAU,EAAE;MAAA,IAAAiB,cAAA,EAAAC,QAAA;MAC1C,IAAMC,QAAQ,GAAGrC,YAAY,CAACkB,KAAK,CAACoB,GAAG,CAAC;MACxC,OAAO;QACLd,gBAAgB,EAAEtB,MAAM,CAACC,IAAI,CAACkC,QAAQ,CAAC,CAACtB,MAAM,IAAAoB,cAAA,GAAG,CAAAC,QAAA,GAAAvC,OAAO,CAAC,CAAC,EAAC0C,KAAK,cAAAJ,cAAA,uBAAfA,cAAA,CAAAK,IAAA,CAAAJ,QAAA,EAAkBC,QAAQ,CAAC,GAAG;MACjF,CAAC;IACH;EAAC;AAAA,EAhB2B1C,aAAa;AAAA4B,eAAA,CAArCP,eAAe,iBACEP,cAAc;AAAAc,eAAA,CAD/BP,eAAe,kBAGG;EACpBsB,GAAG,EAAE,CAAC;AACR,CAAC;AA4BH,SAASxC,aAAa,EAAEkB,eAAe,EAAEL,QAAQ,EAAEF,cAAc,EAAEG,WAAW,EAAEZ,YAAY;AAC5F,eAAeJ,SAAS,CAACoB,eAAe,CAAC","ignoreList":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import type { UnknownProperties } from '../../core-types/UnknownProperties';
|
|
2
3
|
export type LocaleKeys = string;
|
|
3
4
|
export type DictionaryItem = {
|
|
4
5
|
[key: string]: string;
|
|
@@ -8,7 +9,35 @@ export type Dictionary = {
|
|
|
8
9
|
};
|
|
9
10
|
export declare const Context: React.Context<string | undefined>;
|
|
10
11
|
declare const I18nProvider: React.Provider<string | undefined>, I18nConsumer: React.Consumer<string | undefined>;
|
|
12
|
+
declare function getText(dictionaries: Dictionary, locale: LocaleKeys): (key: keyof DictionaryItem) => any;
|
|
13
|
+
/** @deprecated */
|
|
14
|
+
export interface IWithI18nInjectedProps extends WithI18nInjectedProps, UnknownProperties {
|
|
15
|
+
}
|
|
16
|
+
export type WithI18nInjectedProps = {
|
|
17
|
+
getText: WithI18n['getText'];
|
|
18
|
+
};
|
|
19
|
+
/** @deprecated */
|
|
20
|
+
export interface IWithI18nProps extends WithI18nProps, UnknownProperties {
|
|
21
|
+
}
|
|
22
|
+
export type WithI18nProps = WithI18nInjectedProps & {
|
|
23
|
+
locale?: LocaleKeys;
|
|
24
|
+
children?(props: IWithI18nInjectedProps): React.ReactNode;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated use `useI18n` instead
|
|
28
|
+
*/
|
|
29
|
+
declare class WithI18n extends Component<IWithI18nProps> {
|
|
30
|
+
context: LocaleKeys;
|
|
31
|
+
static contextType: React.Context<string | undefined>;
|
|
32
|
+
static defaultProps: {
|
|
33
|
+
getText: typeof getText;
|
|
34
|
+
};
|
|
35
|
+
getText: (dictionary: Dictionary, selfLocale?: string) => string;
|
|
36
|
+
render(): any;
|
|
37
|
+
}
|
|
11
38
|
declare const useI18n: (dictionary: Dictionary, locale?: LocaleKeys, fallbackDictionary?: Dictionary) => (messageId: string, variables?: {
|
|
12
39
|
[key: string]: string | number | undefined;
|
|
13
40
|
}) => string;
|
|
41
|
+
declare const _default: (options?: {}) => (WrappedComponent: React.ComponentType) => React.ComponentClass;
|
|
42
|
+
export default _default;
|
|
14
43
|
export { useI18n, I18nProvider, I18nConsumer };
|
|
@@ -1,17 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
|
-
exports.useI18n = exports.I18nProvider = exports.I18nConsumer = exports.Context = void 0;
|
|
8
|
+
exports.useI18n = exports["default"] = exports.I18nProvider = exports.I18nConsumer = exports.Context = void 0;
|
|
9
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
+
var _callSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/callSuper"));
|
|
12
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
13
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
8
14
|
var _intl = require("@formatjs/intl");
|
|
9
15
|
var _react = _interopRequireWildcard(require("react"));
|
|
16
|
+
var _createHoc = _interopRequireDefault(require("../createHoc"));
|
|
10
17
|
var _i18nEnhance = require("./i18nEnhance");
|
|
11
18
|
var Context = exports.Context = /*#__PURE__*/(0, _react.createContext)(undefined);
|
|
12
19
|
var I18nProvider = exports.I18nProvider = Context.Provider,
|
|
13
20
|
I18nConsumer = exports.I18nConsumer = Context.Consumer;
|
|
14
21
|
var messagesCache = (0, _intl.createIntlCache)();
|
|
22
|
+
function getText(dictionaries, locale) {
|
|
23
|
+
return function (key) {
|
|
24
|
+
var dictionary = dictionaries[locale];
|
|
25
|
+
return dictionary ? dictionary[key] : dictionaries['en'][key];
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @deprecated */
|
|
30
|
+
|
|
31
|
+
/** @deprecated */
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated use `useI18n` instead
|
|
34
|
+
*/
|
|
35
|
+
var WithI18n = /*#__PURE__*/function (_Component) {
|
|
36
|
+
function WithI18n() {
|
|
37
|
+
var _this;
|
|
38
|
+
(0, _classCallCheck2["default"])(this, WithI18n);
|
|
39
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
40
|
+
args[_key] = arguments[_key];
|
|
41
|
+
}
|
|
42
|
+
_this = (0, _callSuper2["default"])(this, WithI18n, [].concat(args));
|
|
43
|
+
/* @ts-ignore */
|
|
44
|
+
(0, _defineProperty2["default"])(_this, "context", void 0);
|
|
45
|
+
(0, _defineProperty2["default"])(_this, "getText", function (dictionary, selfLocale) {
|
|
46
|
+
var _this$props = _this.props,
|
|
47
|
+
locale = _this$props.locale,
|
|
48
|
+
getText = _this$props.getText;
|
|
49
|
+
var contextLocale = _this.context;
|
|
50
|
+
return getText(dictionary, selfLocale || locale || contextLocale);
|
|
51
|
+
});
|
|
52
|
+
return _this;
|
|
53
|
+
}
|
|
54
|
+
(0, _inherits2["default"])(WithI18n, _Component);
|
|
55
|
+
return (0, _createClass2["default"])(WithI18n, [{
|
|
56
|
+
key: "render",
|
|
57
|
+
value: function render() {
|
|
58
|
+
var _ref = this.props,
|
|
59
|
+
children = _ref.children;
|
|
60
|
+
return children({
|
|
61
|
+
getText: this.getText
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}]);
|
|
65
|
+
}(_react.Component);
|
|
66
|
+
(0, _defineProperty2["default"])(WithI18n, "contextType", Context);
|
|
67
|
+
(0, _defineProperty2["default"])(WithI18n, "defaultProps", {
|
|
68
|
+
getText: getText
|
|
69
|
+
});
|
|
15
70
|
var useI18n = exports.useI18n = function useI18n(dictionary) {
|
|
16
71
|
var _React$useContext;
|
|
17
72
|
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en';
|
|
@@ -30,4 +85,5 @@ var useI18n = exports.useI18n = function useI18n(dictionary) {
|
|
|
30
85
|
}, variables);
|
|
31
86
|
}, [intl]);
|
|
32
87
|
};
|
|
88
|
+
var _default = exports["default"] = (0, _createHoc["default"])(WithI18n);
|
|
33
89
|
//# sourceMappingURL=WithI18n.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WithI18n.js","names":["_intl","require","_react","_interopRequireWildcard","_i18nEnhance","Context","exports","createContext","undefined","I18nProvider","Provider","I18nConsumer","Consumer","messagesCache","createIntlCache","
|
|
1
|
+
{"version":3,"file":"WithI18n.js","names":["_intl","require","_react","_interopRequireWildcard","_createHoc","_interopRequireDefault","_i18nEnhance","Context","exports","createContext","undefined","I18nProvider","Provider","I18nConsumer","Consumer","messagesCache","createIntlCache","getText","dictionaries","locale","key","dictionary","WithI18n","_Component","_this","_classCallCheck2","_len","arguments","length","args","Array","_key","_callSuper2","concat","_defineProperty2","selfLocale","_this$props","props","contextLocale","context","_inherits2","_createClass2","value","render","_ref","children","Component","useI18n","_React$useContext","fallbackDictionary","lang","React","useContext","resolvedDictionary","useAsyncI18nMessages","intl","useMemo","createIntl","messages","useCallback","messageId","variables","formatMessage","id","_default","createHoc"],"sources":["../../../src/utils/enhances/WithI18n.tsx"],"sourcesContent":["import { createIntl, createIntlCache } from '@formatjs/intl';\nimport React, { Component, createContext } from 'react';\n\nimport createHoc from '../createHoc';\nimport { useAsyncI18nMessages } from './i18nEnhance';\nimport type { UnknownProperties } from '../../core-types/UnknownProperties';\n\nexport type LocaleKeys = string;\nexport type DictionaryItem = { [key: string]: string };\nexport type Dictionary = { [locale: string]: DictionaryItem | (() => Promise<DictionaryItem>) };\nexport const Context = createContext<LocaleKeys | undefined>(undefined);\nconst { Provider: I18nProvider, Consumer: I18nConsumer } = Context;\nconst messagesCache = createIntlCache();\n\nfunction getText(dictionaries: Dictionary, locale: LocaleKeys) {\n return function (key: keyof DictionaryItem) {\n const dictionary = dictionaries[locale];\n return dictionary ? (dictionary as any)[key] : (dictionaries as any)['en'][key];\n };\n}\n\n/** @deprecated */\nexport interface IWithI18nInjectedProps extends WithI18nInjectedProps, UnknownProperties {}\nexport type WithI18nInjectedProps = {\n getText: WithI18n['getText'];\n};\n\n/** @deprecated */\nexport interface IWithI18nProps extends WithI18nProps, UnknownProperties {}\nexport type WithI18nProps = WithI18nInjectedProps & {\n locale?: LocaleKeys;\n\n children?(props: IWithI18nInjectedProps): React.ReactNode;\n};\n\n/**\n * @deprecated use `useI18n` instead\n */\nclass WithI18n extends Component<IWithI18nProps> {\n /* @ts-ignore */\n context: LocaleKeys;\n\n static contextType = Context;\n static defaultProps = {\n getText,\n };\n\n getText = (dictionary: Dictionary, selfLocale?: string): string => {\n const { locale, getText } = this.props;\n const contextLocale = this.context;\n return getText(dictionary, selfLocale || locale || contextLocale);\n };\n\n render() {\n const { children } = this.props as any;\n return children({\n getText: this.getText,\n });\n }\n}\n\nconst useI18n = (\n dictionary: Dictionary,\n locale: LocaleKeys = 'en',\n fallbackDictionary?: Dictionary,\n) => {\n const lang = React.useContext(Context) ?? locale;\n const resolvedDictionary = useAsyncI18nMessages(dictionary, lang, fallbackDictionary);\n const intl = React.useMemo(\n () => createIntl({ locale: lang, messages: resolvedDictionary }, messagesCache),\n [resolvedDictionary, lang],\n );\n\n return React.useCallback(\n (messageId: string, variables?: { [key: string]: string | number | undefined }) => {\n return intl.formatMessage({ id: messageId ?? '' }, variables);\n },\n [intl],\n );\n};\n\nexport default createHoc(WithI18n);\nexport { useI18n, I18nProvider, I18nConsumer };\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AAMO,IAAMM,OAAO,GAAAC,OAAA,CAAAD,OAAA,gBAAG,IAAAE,oBAAa,EAAyBC,SAAS,CAAC;AACvE,IAAkBC,YAAY,GAAAH,OAAA,CAAAG,YAAA,GAA6BJ,OAAO,CAA1DK,QAAQ;EAA0BC,YAAY,GAAAL,OAAA,CAAAK,YAAA,GAAKN,OAAO,CAAlCO,QAAQ;AACxC,IAAMC,aAAa,GAAG,IAAAC,qBAAe,EAAC,CAAC;AAEvC,SAASC,OAAOA,CAACC,YAAwB,EAAEC,MAAkB,EAAE;EAC7D,OAAO,UAAU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,IAAAS,QAAA,GAAAxD,OAAA,cAEa,IAAAyD,qBAAS,EAAC3C,QAAQ,CAAC","ignoreList":[]}
|
|
@@ -1,9 +1,52 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _callSuper from "@babel/runtime/helpers/esm/callSuper";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
1
6
|
import { createIntlCache, createIntl } from "@formatjs/intl";
|
|
2
|
-
import React, { createContext } from "react";
|
|
7
|
+
import React, { createContext, Component } from "react";
|
|
8
|
+
import createHoc from "../createHoc.mjs";
|
|
3
9
|
import { useAsyncI18nMessages } from "./i18nEnhance.mjs";
|
|
4
10
|
var Context = /* @__PURE__ */ createContext(void 0);
|
|
5
11
|
var I18nProvider = Context.Provider, I18nConsumer = Context.Consumer;
|
|
6
12
|
var messagesCache = createIntlCache();
|
|
13
|
+
function getText(dictionaries, locale) {
|
|
14
|
+
return function(key) {
|
|
15
|
+
var dictionary = dictionaries[locale];
|
|
16
|
+
return dictionary ? dictionary[key] : dictionaries["en"][key];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
var WithI18n = /* @__PURE__ */ (function(_Component) {
|
|
20
|
+
function WithI18n2() {
|
|
21
|
+
var _this;
|
|
22
|
+
_classCallCheck(this, WithI18n2);
|
|
23
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
24
|
+
args[_key] = arguments[_key];
|
|
25
|
+
}
|
|
26
|
+
_this = _callSuper(this, WithI18n2, [].concat(args));
|
|
27
|
+
_defineProperty(_this, "context", void 0);
|
|
28
|
+
_defineProperty(_this, "getText", function(dictionary, selfLocale) {
|
|
29
|
+
var _this$props = _this.props, locale = _this$props.locale, getText2 = _this$props.getText;
|
|
30
|
+
var contextLocale = _this.context;
|
|
31
|
+
return getText2(dictionary, selfLocale || locale || contextLocale);
|
|
32
|
+
});
|
|
33
|
+
return _this;
|
|
34
|
+
}
|
|
35
|
+
_inherits(WithI18n2, _Component);
|
|
36
|
+
return _createClass(WithI18n2, [{
|
|
37
|
+
key: "render",
|
|
38
|
+
value: function render() {
|
|
39
|
+
var _ref = this.props, children = _ref.children;
|
|
40
|
+
return children({
|
|
41
|
+
getText: this.getText
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}]);
|
|
45
|
+
})(Component);
|
|
46
|
+
_defineProperty(WithI18n, "contextType", Context);
|
|
47
|
+
_defineProperty(WithI18n, "defaultProps", {
|
|
48
|
+
getText
|
|
49
|
+
});
|
|
7
50
|
var useI18n = function useI18n2(dictionary) {
|
|
8
51
|
var _React$useContext;
|
|
9
52
|
var locale = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "en";
|
|
@@ -22,9 +65,11 @@ var useI18n = function useI18n2(dictionary) {
|
|
|
22
65
|
}, variables);
|
|
23
66
|
}, [intl]);
|
|
24
67
|
};
|
|
68
|
+
const WithI18n_default = createHoc(WithI18n);
|
|
25
69
|
export {
|
|
26
70
|
Context,
|
|
27
71
|
I18nConsumer,
|
|
28
72
|
I18nProvider,
|
|
73
|
+
WithI18n_default as default,
|
|
29
74
|
useI18n
|
|
30
75
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WithI18n.mjs","names":["createIntl","createIntlCache","React","createContext","useAsyncI18nMessages","Context","undefined","I18nProvider","Provider","I18nConsumer","Consumer","messagesCache","
|
|
1
|
+
{"version":3,"file":"WithI18n.mjs","names":["createIntl","createIntlCache","React","Component","createContext","createHoc","useAsyncI18nMessages","Context","undefined","I18nProvider","Provider","I18nConsumer","Consumer","messagesCache","getText","dictionaries","locale","key","dictionary","WithI18n","_Component","_this","_classCallCheck","_len","arguments","length","args","Array","_key","_callSuper","concat","_defineProperty","selfLocale","_this$props","props","contextLocale","context","_inherits","_createClass","value","render","_ref","children","useI18n","_React$useContext","fallbackDictionary","lang","useContext","resolvedDictionary","intl","useMemo","messages","useCallback","messageId","variables","formatMessage","id"],"sources":["../../../src/utils/enhances/WithI18n.tsx"],"sourcesContent":["import { createIntl, createIntlCache } from '@formatjs/intl';\nimport React, { Component, createContext } from 'react';\n\nimport createHoc from '../createHoc';\nimport { useAsyncI18nMessages } from './i18nEnhance';\nimport type { UnknownProperties } from '../../core-types/UnknownProperties';\n\nexport type LocaleKeys = string;\nexport type DictionaryItem = { [key: string]: string };\nexport type Dictionary = { [locale: string]: DictionaryItem | (() => Promise<DictionaryItem>) };\nexport const Context = createContext<LocaleKeys | undefined>(undefined);\nconst { Provider: I18nProvider, Consumer: I18nConsumer } = Context;\nconst messagesCache = createIntlCache();\n\nfunction getText(dictionaries: Dictionary, locale: LocaleKeys) {\n return function (key: keyof DictionaryItem) {\n const dictionary = dictionaries[locale];\n return dictionary ? (dictionary as any)[key] : (dictionaries as any)['en'][key];\n };\n}\n\n/** @deprecated */\nexport interface IWithI18nInjectedProps extends WithI18nInjectedProps, UnknownProperties {}\nexport type WithI18nInjectedProps = {\n getText: WithI18n['getText'];\n};\n\n/** @deprecated */\nexport interface IWithI18nProps extends WithI18nProps, UnknownProperties {}\nexport type WithI18nProps = WithI18nInjectedProps & {\n locale?: LocaleKeys;\n\n children?(props: IWithI18nInjectedProps): React.ReactNode;\n};\n\n/**\n * @deprecated use `useI18n` instead\n */\nclass WithI18n extends Component<IWithI18nProps> {\n /* @ts-ignore */\n context: LocaleKeys;\n\n static contextType = Context;\n static defaultProps = {\n getText,\n };\n\n getText = (dictionary: Dictionary, selfLocale?: string): string => {\n const { locale, getText } = this.props;\n const contextLocale = this.context;\n return getText(dictionary, selfLocale || locale || contextLocale);\n };\n\n render() {\n const { children } = this.props as any;\n return children({\n getText: this.getText,\n });\n }\n}\n\nconst useI18n = (\n dictionary: Dictionary,\n locale: LocaleKeys = 'en',\n fallbackDictionary?: Dictionary,\n) => {\n const lang = React.useContext(Context) ?? locale;\n const resolvedDictionary = useAsyncI18nMessages(dictionary, lang, fallbackDictionary);\n const intl = React.useMemo(\n () => createIntl({ locale: lang, messages: resolvedDictionary }, messagesCache),\n [resolvedDictionary, lang],\n );\n\n return React.useCallback(\n (messageId: string, variables?: { [key: string]: string | number | undefined }) => {\n return intl.formatMessage({ id: messageId ?? '' }, variables);\n },\n [intl],\n );\n};\n\nexport default createHoc(WithI18n);\nexport { useI18n, I18nProvider, I18nConsumer };\n"],"mappings":";;;;;AAAA,SAASA,UAAU,EAAEC,eAAe,QAAQ,gBAAgB;AAC5D,OAAOC,KAAK,IAAIC,SAAS,EAAEC,aAAa,QAAQ,OAAO;AAEvD,OAAOC,SAAS,MAAM,kBAAc;AACpC,SAASC,oBAAoB,QAAQ,mBAAe;AAMpD,OAAO,IAAMC,OAAO,gBAAGH,aAAa,CAAyBI,SAAS,CAAC;AACvE,IAAkBC,YAAY,GAA6BF,OAAO,CAA1DG,QAAQ;EAA0BC,YAAY,GAAKJ,OAAO,CAAlCK,QAAQ;AACxC,IAAMC,aAAa,GAAGZ,eAAe,CAAC,CAAC;AAEvC,SAASa,OAAOA,CAACC,YAAwB,EAAEC,MAAkB,EAAE;EAC7D,OAAO,UAAUC,GAAyB,EAAE;IAC1C,IAAMC,UAAU,GAAGH,YAAY,CAACC,MAAM,CAAC;IACvC,OAAOE,UAAU,GAAIA,UAAU,CAASD,GAAG,CAAC,GAAIF,YAAY,CAAS,IAAI,CAAC,CAACE,GAAG,CAAC;EACjF,CAAC;AACH;;AAEA;;AAMA;AAQA;AACA;AACA;AAFA,IAGME,QAAQ,0BAAAC,UAAA;EAAA,SAAAD,SAAA;IAAA,IAAAE,KAAA;IAAAC,eAAA,OAAAH,QAAA;IAAA,SAAAI,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAC,IAAA,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAAF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AE/B,IAAMsC,IAAI,IAAAF,iBAAA,GAAG1C,KAAK,CAAC6C,UAAU,CAACxC,OAAO,CAAC,cAAAqC,iBAAA,cAAAA,iBAAA,GAAI5B,MAAM;EAChD,IAAMgC,kBAAkB,GAAG1C,oBAAoB,CAACY,UAAU,EAAE4B,IAAI,EAAED,kBAAkB,CAAC;EACrF,IAAMI,IAAI,GAAG/C,KAAK,CAACgD,OAAO,CACxB;IAAA,OAAMlD,UAAU,CAAC;MAAEgB,MAAM,EAAE8B,IAAI;MAAEK,QAAQ,EAAEH;IAAmB,CAAC,EAAEnC,aAAa,CAAC;EAAA,GAC/E,CAACmC,kBAAkB,EAAEF,IAAI,CAC3B,CAAC;EAED,OAAO5C,KAAK,CAACkD,WAAW,CACtB,UAACC,SAAiB,EAAEC,SAA0D,EAAK;IACjF,OAAOL,IAAI,CAACM,aAAa,CAAC;MAAEC,EAAE,EAAEH,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI;IAAG,CAAC,EAAEC,SAAS,CAAC;EAC/D,CAAC,EACD,CAACL,IAAI,CACP,CAAC;AACH,CAAC;AAED,eAAe5C,SAAS,CAACc,QAAQ,CAAC;AAClC,SAASwB,OAAO,EAAElC,YAAY,EAAEE,YAAY","ignoreList":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { PureComponent } from 'react';
|
|
3
|
+
import type { UnknownProperties } from '../../core-types/UnknownProperties';
|
|
4
|
+
/** @deprecated */
|
|
5
|
+
export interface IEnhancedWithKeyboardFocusInjectedProps extends EnhancedWithKeyboardFocusInjectedProps {
|
|
6
|
+
}
|
|
7
|
+
export type EnhancedWithKeyboardFocusInjectedProps = {
|
|
8
|
+
tabIndex: number;
|
|
9
|
+
keyboardFocused: boolean;
|
|
10
|
+
onFocus(e: FocusEvent): void;
|
|
11
|
+
onBlur(e: FocusEvent): void;
|
|
12
|
+
onKeyDown(e: KeyboardEvent): void;
|
|
13
|
+
onMouseDown(e: MouseEvent): void;
|
|
14
|
+
};
|
|
15
|
+
/** @deprecated */
|
|
16
|
+
export interface IEnhancedWithKeyboardFocusProps extends EnhancedWithKeyboardFocusProps, UnknownProperties {
|
|
17
|
+
}
|
|
18
|
+
export type EnhancedWithKeyboardFocusProps = {
|
|
19
|
+
keyboardFocused?: boolean;
|
|
20
|
+
tabIndex?: number;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
children(props: IEnhancedWithKeyboardFocusInjectedProps): React.ReactNode;
|
|
23
|
+
};
|
|
24
|
+
/** @deprecated */
|
|
25
|
+
export interface IEnhancedWithKeyboardFocusState extends EnhancedWithKeyboardFocusState, UnknownProperties {
|
|
26
|
+
}
|
|
27
|
+
export type EnhancedWithKeyboardFocusState = {
|
|
28
|
+
keyboardFocused: boolean;
|
|
29
|
+
};
|
|
30
|
+
export declare class EnhancedWithKeyboardFocus extends PureComponent<IEnhancedWithKeyboardFocusProps, IEnhancedWithKeyboardFocusState> {
|
|
31
|
+
static displayName: string;
|
|
32
|
+
static defaultProps: {
|
|
33
|
+
tabIndex: number;
|
|
34
|
+
};
|
|
35
|
+
static getDerivedStateFromProps(props: any, state: any): any;
|
|
36
|
+
state: {
|
|
37
|
+
keyboardFocused: boolean;
|
|
38
|
+
};
|
|
39
|
+
handlerFocus: (e: FocusEvent) => void;
|
|
40
|
+
handlerBlur: (e: FocusEvent) => void;
|
|
41
|
+
handlerKeyDown: (e: KeyboardEvent) => void;
|
|
42
|
+
handlerMouseDown: (e: MouseEvent) => void;
|
|
43
|
+
render(): React.ReactNode;
|
|
44
|
+
}
|
|
45
|
+
declare const _default: (options?: {}) => (WrappedComponent: React.ComponentType) => React.ComponentClass;
|
|
46
|
+
export default _default;
|