@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.
Files changed (150) hide show
  1. package/lib/core-types/Component.d.ts +79 -33
  2. package/lib/core-types/Component.js +46 -14
  3. package/lib/core-types/Component.js.map +1 -1
  4. package/lib/core-types/Component.mjs +7 -11
  5. package/lib/core-types/Component.mjs.map +1 -1
  6. package/lib/core-types/symbols.mjs +9 -9
  7. package/lib/coreFactory.d.ts +23 -6
  8. package/lib/coreFactory.js +22 -53
  9. package/lib/coreFactory.js.map +1 -1
  10. package/lib/coreFactory.mjs +35 -54
  11. package/lib/coreFactory.mjs.map +1 -1
  12. package/lib/enhancement/Children.mjs +1 -1
  13. package/lib/enhancement/bindHandler.d.ts +5 -0
  14. package/lib/enhancement/bindHandler.js +53 -0
  15. package/lib/enhancement/bindHandler.js.map +1 -0
  16. package/lib/enhancement/bindHandler.mjs +48 -0
  17. package/lib/enhancement/bindHandler.mjs.map +1 -0
  18. package/lib/enhancement/hoistProps.d.ts +10 -0
  19. package/lib/enhancement/hoistProps.js +95 -0
  20. package/lib/enhancement/hoistProps.js.map +1 -0
  21. package/lib/enhancement/hoistProps.mjs +78 -0
  22. package/lib/enhancement/hoistProps.mjs.map +1 -0
  23. package/lib/enhancement/staticChildren.mjs +3 -3
  24. package/lib/enhancement/style.mjs +2 -2
  25. package/lib/esm/core-types/Component.mjs +7 -11
  26. package/lib/esm/core-types/symbols.mjs +9 -9
  27. package/lib/esm/coreFactory.mjs +35 -54
  28. package/lib/esm/enhancement/Children.mjs +1 -1
  29. package/lib/esm/enhancement/bindHandler.mjs +48 -0
  30. package/lib/esm/enhancement/hoistProps.mjs +78 -0
  31. package/lib/esm/enhancement/staticChildren.mjs +3 -3
  32. package/lib/esm/enhancement/style.mjs +2 -2
  33. package/lib/esm/styled/sstyled.mjs +1 -1
  34. package/lib/esm/utils/createHoc.mjs +42 -0
  35. package/lib/esm/utils/enhances/WithI18n.mjs +46 -1
  36. package/lib/esm/utils/getDisplayName.mjs +6 -0
  37. package/lib/esm/utils/ref.mjs +14 -0
  38. package/lib/index.d.ts +3 -3
  39. package/lib/index.js.map +1 -1
  40. package/lib/index.mjs.map +1 -1
  41. package/lib/styled/index.d.ts +5 -1
  42. package/lib/styled/index.js.map +1 -1
  43. package/lib/styled/index.mjs.map +1 -1
  44. package/lib/styled/sstyled.mjs +1 -1
  45. package/lib/utils/ScreenReaderOnly.d.ts +8 -0
  46. package/lib/utils/ScreenReaderOnly.js +30 -0
  47. package/lib/utils/ScreenReaderOnly.js.map +1 -0
  48. package/lib/utils/ScreenReaderOnly.mjs +24 -0
  49. package/lib/utils/ScreenReaderOnly.mjs.map +1 -0
  50. package/lib/utils/createHoc.d.ts +3 -0
  51. package/lib/utils/createHoc.js +52 -0
  52. package/lib/utils/createHoc.js.map +1 -0
  53. package/lib/utils/createHoc.mjs +42 -0
  54. package/lib/utils/createHoc.mjs.map +1 -0
  55. package/lib/utils/enhances/WithAutoFocus.d.ts +14 -0
  56. package/lib/utils/enhances/WithAutoFocus.js +72 -0
  57. package/lib/utils/enhances/WithAutoFocus.js.map +1 -0
  58. package/lib/utils/enhances/WithAutoFocus.mjs +66 -0
  59. package/lib/utils/enhances/WithAutoFocus.mjs.map +1 -0
  60. package/lib/utils/enhances/WithCSS.d.ts +30 -2
  61. package/lib/utils/enhances/WithCSS.js +57 -4
  62. package/lib/utils/enhances/WithCSS.js.map +1 -1
  63. package/lib/utils/enhances/WithCSS.mjs +53 -2
  64. package/lib/utils/enhances/WithCSS.mjs.map +1 -1
  65. package/lib/utils/enhances/WithI18n.d.ts +30 -1
  66. package/lib/utils/enhances/WithI18n.js +57 -1
  67. package/lib/utils/enhances/WithI18n.js.map +1 -1
  68. package/lib/utils/enhances/WithI18n.mjs +46 -1
  69. package/lib/utils/enhances/WithI18n.mjs.map +1 -1
  70. package/lib/utils/enhances/WithKeyboardFocus.d.ts +46 -0
  71. package/lib/utils/enhances/WithKeyboardFocus.js +94 -0
  72. package/lib/utils/enhances/WithKeyboardFocus.js.map +1 -0
  73. package/lib/utils/enhances/WithKeyboardFocus.mjs +88 -0
  74. package/lib/utils/enhances/WithKeyboardFocus.mjs.map +1 -0
  75. package/lib/utils/enhances/WithRef.d.ts +3 -0
  76. package/lib/utils/enhances/WithRef.js +25 -0
  77. package/lib/utils/enhances/WithRef.js.map +1 -0
  78. package/lib/utils/enhances/WithRef.mjs +18 -0
  79. package/lib/utils/enhances/WithRef.mjs.map +1 -0
  80. package/lib/utils/enhances/animatedSizeEnhance.d.ts +4 -0
  81. package/lib/utils/enhances/animatedSizeEnhance.js +2 -0
  82. package/lib/utils/enhances/animatedSizeEnhance.js.map +1 -1
  83. package/lib/utils/enhances/animatedSizeEnhance.mjs +3 -0
  84. package/lib/utils/enhances/animatedSizeEnhance.mjs.map +1 -1
  85. package/lib/utils/enhances/autoFocusEnhance.d.ts +10 -0
  86. package/lib/utils/enhances/autoFocusEnhance.js +45 -0
  87. package/lib/utils/enhances/autoFocusEnhance.js.map +1 -0
  88. package/lib/utils/enhances/autoFocusEnhance.mjs +38 -0
  89. package/lib/utils/enhances/autoFocusEnhance.mjs.map +1 -0
  90. package/lib/utils/enhances/i18nEnhance.d.ts +4 -0
  91. package/lib/utils/enhances/i18nEnhance.js +2 -0
  92. package/lib/utils/enhances/i18nEnhance.js.map +1 -1
  93. package/lib/utils/enhances/i18nEnhance.mjs.map +1 -1
  94. package/lib/utils/enhances/keyboardFocusEnhance.d.ts +27 -0
  95. package/lib/utils/enhances/keyboardFocusEnhance.js +63 -0
  96. package/lib/utils/enhances/keyboardFocusEnhance.js.map +1 -0
  97. package/lib/utils/enhances/keyboardFocusEnhance.mjs +57 -0
  98. package/lib/utils/enhances/keyboardFocusEnhance.mjs.map +1 -0
  99. package/lib/utils/eventEmitter.d.ts +6 -10
  100. package/lib/utils/eventEmitter.js +27 -55
  101. package/lib/utils/eventEmitter.js.map +1 -1
  102. package/lib/utils/eventEmitter.mjs +27 -55
  103. package/lib/utils/eventEmitter.mjs.map +1 -1
  104. package/lib/utils/getDisplayName.mjs +5 -3
  105. package/lib/utils/if.d.ts +11 -0
  106. package/lib/utils/if.js +15 -0
  107. package/lib/utils/if.js.map +1 -0
  108. package/lib/utils/if.mjs +9 -0
  109. package/lib/utils/if.mjs.map +1 -0
  110. package/lib/utils/injectStyle.js +1 -1
  111. package/lib/utils/injectStyle.mjs +1 -1
  112. package/lib/utils/ref.d.ts +3 -1
  113. package/lib/utils/ref.js +14 -0
  114. package/lib/utils/ref.js.map +1 -1
  115. package/lib/utils/ref.mjs +14 -0
  116. package/lib/utils/ref.mjs.map +1 -1
  117. package/lib/utils/uniqueID.d.ts +4 -0
  118. package/lib/utils/uniqueID.js +3 -1
  119. package/lib/utils/uniqueID.js.map +1 -1
  120. package/lib/utils/uniqueID.mjs +4 -1
  121. package/lib/utils/uniqueID.mjs.map +1 -1
  122. package/lib/utils/use/useColorResolver.js +1 -1
  123. package/lib/utils/use/useColorResolver.js.map +1 -1
  124. package/lib/utils/use/useColorResolver.mjs +1 -1
  125. package/lib/utils/use/useColorResolver.mjs.map +1 -1
  126. package/lib/utils/use/useCss.d.ts +4 -0
  127. package/lib/utils/use/useCss.js +19 -0
  128. package/lib/utils/use/useCss.js.map +1 -0
  129. package/lib/utils/use/useCss.mjs +12 -0
  130. package/lib/utils/use/useCss.mjs.map +1 -0
  131. package/lib/utils/use/useEnhancedEffect.d.ts +1 -1
  132. package/lib/utils/zIndexStacking.d.ts +1 -3
  133. package/lib/utils/zIndexStacking.js.map +1 -1
  134. package/lib/utils/zIndexStacking.mjs.map +1 -1
  135. package/package.json +1 -1
  136. package/lib/decorators/propsObserver.d.ts +0 -11
  137. package/lib/decorators/propsObserver.js +0 -77
  138. package/lib/decorators/propsObserver.js.map +0 -1
  139. package/lib/decorators/propsObserver.mjs +0 -70
  140. package/lib/decorators/propsObserver.mjs.map +0 -1
  141. package/lib/decorators/reactive.d.ts +0 -11
  142. package/lib/decorators/reactive.js +0 -51
  143. package/lib/decorators/reactive.js.map +0 -1
  144. package/lib/decorators/reactive.mjs +0 -45
  145. package/lib/decorators/reactive.mjs.map +0 -1
  146. package/lib/utils/indentStyles.d.ts +0 -3
  147. package/lib/utils/indentStyles.js +0 -45
  148. package/lib/utils/indentStyles.js.map +0 -1
  149. package/lib/utils/indentStyles.mjs +0 -36
  150. package/lib/utils/indentStyles.mjs.map +0 -1
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import type { UnknownProperties } from '../../core-types/UnknownProperties';
3
+ /** @deprecated */
4
+ export interface IKeyboardFocusProps extends KeyboardFocusProps, UnknownProperties {
5
+ }
6
+ export type KeyboardFocusProps = {
7
+ keyboardFocused?: boolean;
8
+ /**
9
+ * Makes component to catch browser focus on component mount
10
+ * @default false
11
+ */
12
+ autoFocus?: boolean;
13
+ };
14
+ export declare const enforcedKeyboardFocusEnhanceContext: React.Context<boolean>;
15
+ export type KeyboardFocusEnhanceHook = (props: {
16
+ tabIndex?: number;
17
+ disabled?: boolean;
18
+ loading?: boolean;
19
+ autoFocus?: boolean;
20
+ }) => {
21
+ tabIndex: number;
22
+ keyboardFocused: boolean;
23
+ onFocus: (e: React.FocusEvent) => void;
24
+ onBlur: () => void;
25
+ };
26
+ declare const keyboardFocusEnhance: (makeFocusable?: boolean) => KeyboardFocusEnhanceHook;
27
+ export default keyboardFocusEnhance;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.enforcedKeyboardFocusEnhanceContext = exports["default"] = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = _interopRequireDefault(require("react"));
10
+ var _LastInteractionType = require("../../LastInteractionType");
11
+ var _assignProps = _interopRequireDefault(require("../assignProps"));
12
+ /** @deprecated */
13
+
14
+ var enforcedKeyboardFocusEnhanceContext = exports.enforcedKeyboardFocusEnhanceContext = /*#__PURE__*/_react["default"].createContext(false);
15
+ var keyboardFocusEnhance = function keyboardFocusEnhance() {
16
+ var makeFocusable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
17
+ return function (props) {
18
+ var _props$tabIndex;
19
+ var autoFocus = props.autoFocus;
20
+ var disabled = props.disabled || props.loading;
21
+ var tabIndex = (_props$tabIndex = props.tabIndex) !== null && _props$tabIndex !== void 0 ? _props$tabIndex : makeFocusable ? 0 : undefined;
22
+ var _React$useState = _react["default"].useState(false),
23
+ _React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
24
+ keyboardFocused = _React$useState2[0],
25
+ setKeyboardFocused = _React$useState2[1];
26
+ var ref = _react["default"].useRef(null);
27
+ var handleFocus = _react["default"].useCallback(function (event) {
28
+ if (event.isTrusted === true) {
29
+ if (!_LastInteractionType.lastInteraction.isKeyboard()) return;
30
+ }
31
+ setKeyboardFocused(true);
32
+ }, []);
33
+ var handlerBlur = _react["default"].useCallback(function () {
34
+ return setKeyboardFocused(false);
35
+ }, []);
36
+ _react["default"].useEffect(function () {
37
+ if (typeof autoFocus !== 'number' && !autoFocus) return;
38
+ var timer = setTimeout(function () {
39
+ var _ref$current;
40
+ (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.focus();
41
+ setKeyboardFocused(true);
42
+ }, 0);
43
+ return function () {
44
+ clearTimeout(timer);
45
+ };
46
+ }, [autoFocus]);
47
+ _react["default"].useEffect(function () {
48
+ if (disabled) {
49
+ setKeyboardFocused(false);
50
+ }
51
+ }, [disabled]);
52
+ var enforcedKeyboardFocus = _react["default"].useContext(enforcedKeyboardFocusEnhanceContext);
53
+ return (0, _assignProps["default"])(props, {
54
+ tabIndex: disabled ? -1 : tabIndex,
55
+ keyboardFocused: (keyboardFocused || enforcedKeyboardFocus) && !disabled,
56
+ onFocus: handleFocus,
57
+ onBlur: handlerBlur,
58
+ ref: ref
59
+ });
60
+ };
61
+ };
62
+ var _default = exports["default"] = keyboardFocusEnhance;
63
+ //# sourceMappingURL=keyboardFocusEnhance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyboardFocusEnhance.js","names":["_react","_interopRequireDefault","require","_LastInteractionType","_assignProps","enforcedKeyboardFocusEnhanceContext","exports","React","createContext","keyboardFocusEnhance","makeFocusable","arguments","length","undefined","props","_props$tabIndex","autoFocus","disabled","loading","tabIndex","_React$useState","useState","_React$useState2","_slicedToArray2","keyboardFocused","setKeyboardFocused","ref","useRef","handleFocus","useCallback","event","isTrusted","lastInteraction","isKeyboard","handlerBlur","useEffect","timer","setTimeout","_ref$current","current","focus","clearTimeout","enforcedKeyboardFocus","useContext","assignProps","onFocus","onBlur","_default"],"sources":["../../../src/utils/enhances/keyboardFocusEnhance.tsx"],"sourcesContent":["import React from 'react';\n\nimport type { UnknownProperties } from '../../core-types/UnknownProperties';\nimport { lastInteraction } from '../../LastInteractionType';\nimport assignProps from '../assignProps';\n\n/** @deprecated */\nexport interface IKeyboardFocusProps extends KeyboardFocusProps, UnknownProperties {}\nexport type KeyboardFocusProps = {\n /* Property responsible for displaying \"keyboard\" focus */\n keyboardFocused?: boolean;\n /**\n * Makes component to catch browser focus on component mount\n * @default false\n */\n autoFocus?: boolean;\n};\n\nexport const enforcedKeyboardFocusEnhanceContext = React.createContext(false);\n\nexport type KeyboardFocusEnhanceHook = (props: {\n tabIndex?: number;\n disabled?: boolean;\n loading?: boolean;\n autoFocus?: boolean;\n}) => {\n tabIndex: number;\n keyboardFocused: boolean;\n onFocus: (e: React.FocusEvent) => void;\n onBlur: () => void;\n};\n\nconst keyboardFocusEnhance = (makeFocusable = true): KeyboardFocusEnhanceHook => {\n return (props) => {\n const { autoFocus } = props;\n const disabled = props.disabled || props.loading;\n const tabIndex = props.tabIndex ?? (makeFocusable ? 0 : undefined);\n const [keyboardFocused, setKeyboardFocused] = React.useState(false);\n const ref = React.useRef<HTMLElement>(null);\n\n const handleFocus = React.useCallback((event: React.FocusEvent) => {\n if (event.isTrusted === true) {\n if (!lastInteraction.isKeyboard()) return;\n }\n setKeyboardFocused(true);\n }, []);\n const handlerBlur = React.useCallback(() => setKeyboardFocused(false), []);\n React.useEffect(() => {\n if (typeof autoFocus !== 'number' && !autoFocus) return;\n const timer = setTimeout(() => {\n ref.current?.focus();\n setKeyboardFocused(true);\n }, 0);\n return () => {\n clearTimeout(timer);\n };\n }, [autoFocus]);\n React.useEffect(() => {\n if (disabled) {\n setKeyboardFocused(false);\n }\n }, [disabled]);\n\n const enforcedKeyboardFocus = React.useContext(enforcedKeyboardFocusEnhanceContext);\n\n return assignProps(props, {\n tabIndex: disabled ? -1 : tabIndex,\n keyboardFocused: (keyboardFocused || enforcedKeyboardFocus) && !disabled,\n onFocus: handleFocus,\n onBlur: handlerBlur,\n ref,\n });\n };\n};\n\nexport default keyboardFocusEnhance;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,oBAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA;;AAYO,IAAMG,mCAAmC,GAAAC,OAAA,CAAAD,mCAAA,gBAAGE,iBAAK,CAACC,aAAa,CAAC,KAAK,CAAC;AAc7E,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAoBA,CAAA,EAAuD;EAAA,IAAnDC,aAAa,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;EAChD,OAAO,UAACG,KAAK,EAAK;IAAA,IAAAC,eAAA;IAChB,IAAQC,SAAS,GAAKF,KAAK,CAAnBE,SAAS;IACjB,IAAMC,QAAQ,GAAGH,KAAK,CAACG,QAAQ,IAAIH,KAAK,CAACI,OAAO;IAChD,IAAMC,QAAQ,IAAAJ,eAAA,GAAGD,KAAK,CAACK,QAAQ,cAAAJ,eAAA,cAAAA,eAAA,GAAKL,aA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B,qBAAqB,GAAGnC,iBAAK,CAACoC,UAAU,CAACtC,mCAAmC,CAAC;IAEnF,OAAO,IAAAuC,uBAAW,EAAC9B,KAAK,EAAE;MACxBK,QAAQ,EAAEF,QAAQ,GAAG,CAAC,CAAC,GAAGE,QAAQ;MAClCK,eAAe,EAAE,CAACA,eAAe,IAAIkB,qBAAqB,KAAK,CAACzB,QAAQ;MACxE4B,OAAO,EAAEjB,WAAW;MACpBkB,MAAM,EAAEZ,WAAW;MACnBR,GAAG,EAAHA;IACF,CAAC,CAAC;EACJ,CAAC;AACH,CAAC;AAAC,IAAAqB,QAAA,GAAAzC,OAAA,cAEaG,oBAAoB","ignoreList":[]}
@@ -0,0 +1,57 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React from 'react';
3
+ import { lastInteraction } from "../../LastInteractionType.mjs";
4
+ import assignProps from "../assignProps.mjs";
5
+
6
+ /** @deprecated */
7
+
8
+ export var enforcedKeyboardFocusEnhanceContext = /*#__PURE__*/React.createContext(false);
9
+ var keyboardFocusEnhance = function keyboardFocusEnhance() {
10
+ var makeFocusable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
11
+ return function (props) {
12
+ var _props$tabIndex;
13
+ var autoFocus = props.autoFocus;
14
+ var disabled = props.disabled || props.loading;
15
+ var tabIndex = (_props$tabIndex = props.tabIndex) !== null && _props$tabIndex !== void 0 ? _props$tabIndex : makeFocusable ? 0 : undefined;
16
+ var _React$useState = React.useState(false),
17
+ _React$useState2 = _slicedToArray(_React$useState, 2),
18
+ keyboardFocused = _React$useState2[0],
19
+ setKeyboardFocused = _React$useState2[1];
20
+ var ref = React.useRef(null);
21
+ var handleFocus = React.useCallback(function (event) {
22
+ if (event.isTrusted === true) {
23
+ if (!lastInteraction.isKeyboard()) return;
24
+ }
25
+ setKeyboardFocused(true);
26
+ }, []);
27
+ var handlerBlur = React.useCallback(function () {
28
+ return setKeyboardFocused(false);
29
+ }, []);
30
+ React.useEffect(function () {
31
+ if (typeof autoFocus !== 'number' && !autoFocus) return;
32
+ var timer = setTimeout(function () {
33
+ var _ref$current;
34
+ (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.focus();
35
+ setKeyboardFocused(true);
36
+ }, 0);
37
+ return function () {
38
+ clearTimeout(timer);
39
+ };
40
+ }, [autoFocus]);
41
+ React.useEffect(function () {
42
+ if (disabled) {
43
+ setKeyboardFocused(false);
44
+ }
45
+ }, [disabled]);
46
+ var enforcedKeyboardFocus = React.useContext(enforcedKeyboardFocusEnhanceContext);
47
+ return assignProps(props, {
48
+ tabIndex: disabled ? -1 : tabIndex,
49
+ keyboardFocused: (keyboardFocused || enforcedKeyboardFocus) && !disabled,
50
+ onFocus: handleFocus,
51
+ onBlur: handlerBlur,
52
+ ref: ref
53
+ });
54
+ };
55
+ };
56
+ export default keyboardFocusEnhance;
57
+ //# sourceMappingURL=keyboardFocusEnhance.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyboardFocusEnhance.mjs","names":["React","lastInteraction","assignProps","enforcedKeyboardFocusEnhanceContext","createContext","keyboardFocusEnhance","makeFocusable","arguments","length","undefined","props","_props$tabIndex","autoFocus","disabled","loading","tabIndex","_React$useState","useState","_React$useState2","_slicedToArray","keyboardFocused","setKeyboardFocused","ref","useRef","handleFocus","useCallback","event","isTrusted","isKeyboard","handlerBlur","useEffect","timer","setTimeout","_ref$current","current","focus","clearTimeout","enforcedKeyboardFocus","useContext","onFocus","onBlur"],"sources":["../../../src/utils/enhances/keyboardFocusEnhance.tsx"],"sourcesContent":["import React from 'react';\n\nimport type { UnknownProperties } from '../../core-types/UnknownProperties';\nimport { lastInteraction } from '../../LastInteractionType';\nimport assignProps from '../assignProps';\n\n/** @deprecated */\nexport interface IKeyboardFocusProps extends KeyboardFocusProps, UnknownProperties {}\nexport type KeyboardFocusProps = {\n /* Property responsible for displaying \"keyboard\" focus */\n keyboardFocused?: boolean;\n /**\n * Makes component to catch browser focus on component mount\n * @default false\n */\n autoFocus?: boolean;\n};\n\nexport const enforcedKeyboardFocusEnhanceContext = React.createContext(false);\n\nexport type KeyboardFocusEnhanceHook = (props: {\n tabIndex?: number;\n disabled?: boolean;\n loading?: boolean;\n autoFocus?: boolean;\n}) => {\n tabIndex: number;\n keyboardFocused: boolean;\n onFocus: (e: React.FocusEvent) => void;\n onBlur: () => void;\n};\n\nconst keyboardFocusEnhance = (makeFocusable = true): KeyboardFocusEnhanceHook => {\n return (props) => {\n const { autoFocus } = props;\n const disabled = props.disabled || props.loading;\n const tabIndex = props.tabIndex ?? (makeFocusable ? 0 : undefined);\n const [keyboardFocused, setKeyboardFocused] = React.useState(false);\n const ref = React.useRef<HTMLElement>(null);\n\n const handleFocus = React.useCallback((event: React.FocusEvent) => {\n if (event.isTrusted === true) {\n if (!lastInteraction.isKeyboard()) return;\n }\n setKeyboardFocused(true);\n }, []);\n const handlerBlur = React.useCallback(() => setKeyboardFocused(false), []);\n React.useEffect(() => {\n if (typeof autoFocus !== 'number' && !autoFocus) return;\n const timer = setTimeout(() => {\n ref.current?.focus();\n setKeyboardFocused(true);\n }, 0);\n return () => {\n clearTimeout(timer);\n };\n }, [autoFocus]);\n React.useEffect(() => {\n if (disabled) {\n setKeyboardFocused(false);\n }\n }, [disabled]);\n\n const enforcedKeyboardFocus = React.useContext(enforcedKeyboardFocusEnhanceContext);\n\n return assignProps(props, {\n tabIndex: disabled ? -1 : tabIndex,\n keyboardFocused: (keyboardFocused || enforcedKeyboardFocus) && !disabled,\n onFocus: handleFocus,\n onBlur: handlerBlur,\n ref,\n });\n };\n};\n\nexport default keyboardFocusEnhance;\n"],"mappings":";AAAA,OAAOA,KAAK,MAAM,OAAO;AAGzB,SAASC,eAAe,QAAQ,+BAA2B;AAC3D,OAAOC,WAAW,MAAM,oBAAgB;;AAExC;;AAYA,OAAO,IAAMC,mCAAmC,gBAAGH,KAAK,CAACI,aAAa,CAAC,KAAK,CAAC;AAc7E,IAAMC,oBAAoB,GAAG,SAAvBA,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OAAO,cAAAD,YAAA,eAAXA,YAAA,CAAaE,KAAK,CAAC,CAAC;QACpBd,kBAAkB,CAAC,IAAI,CAAC;MAC1B,CAAC,EAAE,CAAC,CAAC;MACL,OAAO,YAAM;QACXe,YAAY,CAACL,KAAK,CAAC;MACrB,CAAC;IACH,CAAC,EAAE,CAACnB,SAAS,CAAC,CAAC;IACfZ,KAAK,CAAC8B,SAAS,CAAC,YAAM;MACpB,IAAIjB,QAAQ,EAAE;QACZQ,kBAAkB,CAAC,KAAK,CAAC;MAC3B;IACF,CAAC,EAAE,CAACR,QAAQ,CAAC,CAAC;IAEd,IAAMwB,qBAAqB,GAAGrC,KAAK,CAACsC,UAAU,CAACnC,mCAAmC,CAAC;IAEnF,OAAOD,WAAW,CAACQ,KAAK,EAAE;MACxBK,QAAQ,EAAEF,QAAQ,GAAG,CAAC,CAAC,GAAGE,QAAQ;MAClCK,eAAe,EAAE,CAACA,eAAe,IAAIiB,qBAAqB,KAAK,CAACxB,QAAQ;MACxE0B,OAAO,EAAEf,WAAW;MACpBgB,MAAM,EAAEX,WAAW;MACnBP,GAAG,EAAHA;IACF,CAAC,CAAC;EACJ,CAAC;AACH,CAAC;AAED,eAAejB,oBAAoB","ignoreList":[]}
@@ -1,13 +1,9 @@
1
- type Events = Record<string, (...args: any[]) => void>;
2
- type Cleanup = () => void;
3
- export default class EventEmitter<E extends Events, K extends keyof E = keyof E, H extends E[K] = E[K]> {
1
+ type DefaultEmit = (eventName: string, ...args: any[]) => void;
2
+ type DefaultSubscribe = (eventName: string, fn: any) => () => void;
3
+ export default class EventEmitter<Emit = DefaultEmit, Subscribe = DefaultSubscribe> {
4
4
  private events;
5
- on(eventName: K, fn: H): Cleanup;
6
- off(eventName: K, fn: H): void;
7
- emit(eventName: K, ...args: Parameters<H>): void;
8
- /**
9
- * @deprecated. Fallback to the `on` method for backward compatibility.
10
- */
11
- subscribe(eventName: K, fn: H): Cleanup;
5
+ constructor();
6
+ emit: Emit;
7
+ subscribe: Subscribe;
12
8
  }
13
9
  export {};
@@ -5,64 +5,36 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports["default"] = void 0;
8
- var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
8
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
9
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
- var EventEmitter = exports["default"] = /*#__PURE__*/function () {
13
- function EventEmitter() {
14
- (0, _classCallCheck2["default"])(this, EventEmitter);
15
- (0, _defineProperty2["default"])(this, "events", new Map());
16
- }
17
- return (0, _createClass2["default"])(EventEmitter, [{
18
- key: "on",
19
- value: function on(eventName, fn) {
20
- var _this$events$get,
21
- _this = this;
22
- var handlers = (_this$events$get = this.events.get(eventName)) !== null && _this$events$get !== void 0 ? _this$events$get : new Set();
23
- handlers.add(fn);
24
- this.events.set(eventName, handlers);
25
- return function () {
26
- _this.off(eventName, fn);
27
- };
11
+ var EventEmitter = exports["default"] = /*#__PURE__*/(0, _createClass2["default"])(function EventEmitter() {
12
+ var _this = this;
13
+ (0, _classCallCheck2["default"])(this, EventEmitter);
14
+ (0, _defineProperty2["default"])(this, "events", {});
15
+ (0, _defineProperty2["default"])(this, "emit", void 0);
16
+ (0, _defineProperty2["default"])(this, "subscribe", void 0);
17
+ this.emit = function (eventName) {
18
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
19
+ args[_key - 1] = arguments[_key];
28
20
  }
29
- }, {
30
- key: "off",
31
- value: function off(eventName, fn) {
32
- var _this$events$get2;
33
- (_this$events$get2 = this.events.get(eventName)) === null || _this$events$get2 === void 0 || _this$events$get2["delete"](fn);
21
+ var event = _this.events[eventName];
22
+ if (event) {
23
+ event.forEach(function (fn) {
24
+ fn.call.apply(fn, [null].concat(args));
25
+ });
34
26
  }
35
- }, {
36
- key: "emit",
37
- value: function emit(eventName) {
38
- var handlers = this.events.get(eventName);
39
- if (handlers) {
40
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
41
- args[_key - 1] = arguments[_key];
42
- }
43
- var _iterator = (0, _createForOfIteratorHelper2["default"])(handlers),
44
- _step;
45
- try {
46
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
47
- var handler = _step.value;
48
- handler.call.apply(handler, [null].concat(args));
49
- }
50
- } catch (err) {
51
- _iterator.e(err);
52
- } finally {
53
- _iterator.f();
54
- }
55
- }
27
+ };
28
+ this.subscribe = function (eventName, fn) {
29
+ if (!_this.events[eventName]) {
30
+ _this.events[eventName] = [];
56
31
  }
57
-
58
- /**
59
- * @deprecated. Fallback to the `on` method for backward compatibility.
60
- */
61
- }, {
62
- key: "subscribe",
63
- value: function subscribe(eventName, fn) {
64
- return this.on(eventName, fn);
65
- }
66
- }]);
67
- }();
32
+ _this.events[eventName].push(fn);
33
+ return function () {
34
+ _this.events[eventName] = _this.events[eventName].filter(function (eventFn) {
35
+ return fn !== eventFn;
36
+ });
37
+ };
38
+ };
39
+ });
68
40
  //# sourceMappingURL=eventEmitter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"eventEmitter.js","names":["EventEmitter","exports","_classCallCheck2","_defineProperty2","Map","_createClass2","key","value","on","eventName","fn","_this$events$get","_this","handlers","events","get","Set","add","set","off","_this$events$get2","emit","_len","arguments","length","args","Array","_key","_iterator","_createForOfIteratorHelper2","_step","s","n","done","handler","call","apply","concat","err","e","f","subscribe"],"sources":["../../src/utils/eventEmitter.ts"],"sourcesContent":["type Events = Record<string, (...args: any[]) => void>;\ntype Cleanup = () => void;\n\nexport default class EventEmitter<E extends Events, K extends keyof E = keyof E, H extends E[K] = E[K]> {\n private events = new Map<K, Set<H>>();\n\n public on(eventName: K, fn: H): Cleanup {\n const handlers = this.events.get(eventName) ?? new Set<H>();\n\n handlers.add(fn);\n\n this.events.set(eventName, handlers);\n\n return () => {\n this.off(eventName, fn);\n };\n }\n\n public off(eventName: K, fn: H): void {\n this.events.get(eventName)?.delete(fn);\n }\n\n public emit(eventName: K, ...args: Parameters<H>) {\n const handlers = this.events.get(eventName);\n\n if (handlers) {\n for (const handler of handlers) {\n handler.call(null, ...args);\n }\n }\n }\n\n /**\n * @deprecated. Fallback to the `on` method for backward compatibility.\n */\n public subscribe(eventName: K, fn: H): Cleanup {\n return this.on(eventName, fn);\n }\n}\n"],"mappings":";;;;;;;;;;;IAGqBA,YAAY,GAAAC,OAAA;EAAA,SAAAD,aAAA;IAAA,IAAAE,gBAAA,mBAAAF,YAAA;IAAA,IAAAG,gBAAA,6BACd,IAAIC,GAAG,CAAY,CAAC;EAAA;EAAA,WAAAC,aAAA,aAAAL,YAAA;IAAAM,GAAA;IAAAC,KAAA,EAErC,SAAOC,EAAEA,CAACC,SAAY,EAAEC,EAAK,EAAW;MAAA,IAAAC,gBAAA;QAAAC,KAAA;MACtC,IAAMC,QAAQ,IAAAF,gBAAA,GAAG,IAAI,CAACG,MAAM,CAACC,GAAG,CAACN,SAAS,CAAC,cAAAE,gBAAA,cAAAA,gBAAA,GAAI,IAAIK,GAAG,CAAI,CAAC;MAE3DH,QAAQ,CAACI,GAAG,CAACP,EAAE,CAAC;MAEhB,IAAI,CAACI,MAAM,CAACI,GAAG,CAACT,SAAS,EAAEI,QAAQ,CAAC;MAEpC,OAAO,YAAM;QACXD,KAAI,CAACO,GAAG,CAACV,SAAS,EAAEC,EAAE,CAAC;MACzB,CAAC;IACH;EAAC;IAAAJ,GAAA;IAAAC,KAAA,EAED,SAAOY,GAAGA,CAACV,SAAY,EAAEC,EAAK,EAAQ;MAAA,IAAAU,iBAAA;MACpC,CAAAA,iBAAA,OAAI,CAACN,MAAM,CAACC,GAAG,CAACN,SAAS,CAAC,cAAAW,iBAAA,eAA1BA,iBAAA,UAAkC,CAACV,EAAE,CAAC;IACxC;EAAC;IAAAJ,GAAA;IAAAC,KAAA,EAED,SAAOc,IAAIA,CAACZ,SAAY,EAA0B;MAChD,IAAMI,QAAQ,GAAG,IAAI,CAACC,MAAM,CAACC,GAAG,CAACN,SAAS,CAAC;MAE3C,IAAII,QAAQ,EAAE;QAAA,SAAAS,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAHaC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;UAAJF,IAAI,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;QAAA;QAAA,IAAAC,SAAA,OAAAC,2BAAA,aAIPhB,QAAQ;UAAAiB,KAAA;QAAA;UAA9B,KAAAF,SAAA,CAAAG,CAAA,MAAAD,KAAA,GAAAF,SAAA,CAAAI,CAAA,IAAAC,IAAA,GAAgC;YAAA,IAArBC,OAAO,GAAAJ,KAAA,CAAAvB,KAAA;YAChB2B,OAAO,CAACC,IAAI,CAAAC,KAAA,CAAZF,OAAO,GAAM,IAAI,EAAAG,MAAA,CAAKZ,IAAI,EAAC;UAC7B;QAAC,SAAAa,GAAA;UAAAV,SAAA,CAAAW,CAAA,CAAAD,GAAA;QAAA;UAAAV,SAAA,CAAAY,CAAA;QAAA;MACH;IACF;;IAEA;AACF;AACA;EAFE;IAAAlC,GAAA;IAAAC,KAAA,EAGA,SAAOkC,SAASA,CAAChC,SAAY,EAAEC,EAAK,EAAW;MAC7C,OAAO,IAAI,CAACF,EAAE,CAACC,SAAS,EAAEC,EAAE,CAAC;IAC/B;EAAC;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"eventEmitter.js","names":["EventEmitter","exports","_createClass2","_this","_classCallCheck2","_defineProperty2","emit","eventName","_len","arguments","length","args","Array","_key","event","events","forEach","fn","call","apply","concat","subscribe","push","filter","eventFn"],"sources":["../../src/utils/eventEmitter.ts"],"sourcesContent":["type DefaultEmit = (eventName: string, ...args: any[]) => void;\ntype DefaultSubscribe = (eventName: string, fn: any) => () => void;\n\nexport default class EventEmitter<Emit = DefaultEmit, Subscribe = DefaultSubscribe> {\n private events: any = {};\n constructor() {\n this.emit = ((eventName: string, ...args: any[]) => {\n const event = this.events[eventName];\n if (event) {\n event.forEach((fn: any) => {\n fn.call(null, ...args);\n });\n }\n }) as any;\n this.subscribe = ((eventName: string, fn: any) => {\n if (!this.events[eventName]) {\n this.events[eventName] = [];\n }\n\n this.events[eventName].push(fn);\n return () => {\n this.events[eventName] = this.events[eventName].filter((eventFn: any) => fn !== eventFn);\n };\n }) as any;\n }\n\n emit: Emit;\n\n subscribe: Subscribe;\n}\n"],"mappings":";;;;;;;;;;IAGqBA,YAAY,GAAAC,OAAA,+BAAAC,aAAA,aAE/B,SAAAF,aAAA,EAAc;EAAA,IAAAG,KAAA;EAAA,IAAAC,gBAAA,mBAAAJ,YAAA;EAAA,IAAAK,gBAAA,6BADQ,CAAC,CAAC;EAAA,IAAAA,gBAAA;EAAA,IAAAA,gBAAA;EAEtB,IAAI,CAACC,IAAI,GAAI,UAACC,SAAiB,EAAqB;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAhBC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAJF,IAAI,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;IAAA;IACtC,IAAMC,KAAK,GAAGX,KAAI,CAACY,MAAM,CAACR,SAAS,CAAC;IACpC,IAAIO,KAAK,EAAE;MACTA,KAAK,CAACE,OAAO,CAAC,UAACC,EAAO,EAAK;QACzBA,EAAE,CAACC,IAAI,CAAAC,KAAA,CAAPF,EAAE,GAAM,IAAI,EAAAG,MAAA,CAAKT,IAAI,EAAC;MACxB,CAAC,CAAC;IACJ;EACF,CAAS;EACT,IAAI,CAACU,SAAS,GAAI,UAACd,SAAiB,EAAEU,EAAO,EAAK;IAChD,IAAI,CAACd,KAAI,CAACY,MAAM,CAACR,SAAS,CAAC,EAAE;MAC3BJ,KAAI,CAACY,MAAM,CAACR,SAAS,CAAC,GAAG,EAAE;IAC7B;IAEAJ,KAAI,CAACY,MAAM,CAACR,SAAS,CAAC,CAACe,IAAI,CAACL,EAAE,CAAC;IAC/B,OAAO,YAAM;MACXd,KAAI,CAACY,MAAM,CAACR,SAAS,CAAC,GAAGJ,KAAI,CAACY,MAAM,CAACR,SAAS,CAAC,CAACgB,MAAM,CAAC,UAACC,OAAY;QAAA,OAAKP,EAAE,KAAKO,OAAO;MAAA,EAAC;IAC1F,CAAC;EACH,CAAS;AACX,CAAC","ignoreList":[]}
@@ -1,62 +1,34 @@
1
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
1
  import _createClass from "@babel/runtime/helpers/esm/createClass";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
3
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
- var EventEmitter = /*#__PURE__*/function () {
6
- function EventEmitter() {
7
- _classCallCheck(this, EventEmitter);
8
- _defineProperty(this, "events", new Map());
9
- }
10
- return _createClass(EventEmitter, [{
11
- key: "on",
12
- value: function on(eventName, fn) {
13
- var _this$events$get,
14
- _this = this;
15
- var handlers = (_this$events$get = this.events.get(eventName)) !== null && _this$events$get !== void 0 ? _this$events$get : new Set();
16
- handlers.add(fn);
17
- this.events.set(eventName, handlers);
18
- return function () {
19
- _this.off(eventName, fn);
20
- };
21
- }
22
- }, {
23
- key: "off",
24
- value: function off(eventName, fn) {
25
- var _this$events$get2;
26
- (_this$events$get2 = this.events.get(eventName)) === null || _this$events$get2 === void 0 || _this$events$get2["delete"](fn);
4
+ var EventEmitter = /*#__PURE__*/_createClass(function EventEmitter() {
5
+ var _this = this;
6
+ _classCallCheck(this, EventEmitter);
7
+ _defineProperty(this, "events", {});
8
+ _defineProperty(this, "emit", void 0);
9
+ _defineProperty(this, "subscribe", void 0);
10
+ this.emit = function (eventName) {
11
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
12
+ args[_key - 1] = arguments[_key];
27
13
  }
28
- }, {
29
- key: "emit",
30
- value: function emit(eventName) {
31
- var handlers = this.events.get(eventName);
32
- if (handlers) {
33
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
34
- args[_key - 1] = arguments[_key];
35
- }
36
- var _iterator = _createForOfIteratorHelper(handlers),
37
- _step;
38
- try {
39
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
40
- var handler = _step.value;
41
- handler.call.apply(handler, [null].concat(args));
42
- }
43
- } catch (err) {
44
- _iterator.e(err);
45
- } finally {
46
- _iterator.f();
47
- }
48
- }
14
+ var event = _this.events[eventName];
15
+ if (event) {
16
+ event.forEach(function (fn) {
17
+ fn.call.apply(fn, [null].concat(args));
18
+ });
49
19
  }
50
-
51
- /**
52
- * @deprecated. Fallback to the `on` method for backward compatibility.
53
- */
54
- }, {
55
- key: "subscribe",
56
- value: function subscribe(eventName, fn) {
57
- return this.on(eventName, fn);
20
+ };
21
+ this.subscribe = function (eventName, fn) {
22
+ if (!_this.events[eventName]) {
23
+ _this.events[eventName] = [];
58
24
  }
59
- }]);
60
- }();
25
+ _this.events[eventName].push(fn);
26
+ return function () {
27
+ _this.events[eventName] = _this.events[eventName].filter(function (eventFn) {
28
+ return fn !== eventFn;
29
+ });
30
+ };
31
+ };
32
+ });
61
33
  export { EventEmitter as default };
62
34
  //# sourceMappingURL=eventEmitter.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"eventEmitter.mjs","names":["EventEmitter","_classCallCheck","_defineProperty","Map","_createClass","key","value","on","eventName","fn","_this$events$get","_this","handlers","events","get","Set","add","set","off","_this$events$get2","emit","_len","arguments","length","args","Array","_key","_iterator","_createForOfIteratorHelper","_step","s","n","done","handler","call","apply","concat","err","e","f","subscribe","default"],"sources":["../../src/utils/eventEmitter.ts"],"sourcesContent":["type Events = Record<string, (...args: any[]) => void>;\ntype Cleanup = () => void;\n\nexport default class EventEmitter<E extends Events, K extends keyof E = keyof E, H extends E[K] = E[K]> {\n private events = new Map<K, Set<H>>();\n\n public on(eventName: K, fn: H): Cleanup {\n const handlers = this.events.get(eventName) ?? new Set<H>();\n\n handlers.add(fn);\n\n this.events.set(eventName, handlers);\n\n return () => {\n this.off(eventName, fn);\n };\n }\n\n public off(eventName: K, fn: H): void {\n this.events.get(eventName)?.delete(fn);\n }\n\n public emit(eventName: K, ...args: Parameters<H>) {\n const handlers = this.events.get(eventName);\n\n if (handlers) {\n for (const handler of handlers) {\n handler.call(null, ...args);\n }\n }\n }\n\n /**\n * @deprecated. Fallback to the `on` method for backward compatibility.\n */\n public subscribe(eventName: K, fn: H): Cleanup {\n return this.on(eventName, fn);\n }\n}\n"],"mappings":";;;;IAGqBA,YAAY;EAAA,SAAAA,aAAA;IAAAC,eAAA,OAAAD,YAAA;IAAAE,eAAA,iBACd,IAAIC,GAAG,CAAY,CAAC;EAAA;EAAA,OAAAC,YAAA,CAAAJ,YAAA;IAAAK,GAAA;IAAAC,KAAA,EAErC,SAAOC,EAAEA,CAACC,SAAY,EAAEC,EAAK,EAAW;MAAA,IAAAC,gBAAA;QAAAC,KAAA;MACtC,IAAMC,QAAQ,IAAAF,gBAAA,GAAG,IAAI,CAACG,MAAM,CAACC,GAAG,CAACN,SAAS,CAAC,cAAAE,gBAAA,cAAAA,gBAAA,GAAI,IAAIK,GAAG,CAAI,CAAC;MAE3DH,QAAQ,CAACI,GAAG,CAACP,EAAE,CAAC;MAEhB,IAAI,CAACI,MAAM,CAACI,GAAG,CAACT,SAAS,EAAEI,QAAQ,CAAC;MAEpC,OAAO,YAAM;QACXD,KAAI,CAACO,GAAG,CAACV,S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AS,EAAEC,EAAE,CAAC;IAC/B;EAAC;AAAA;AAAA,SAlCkBT,YAAY,IAAAyC,OAAA","ignoreList":[]}
1
+ {"version":3,"file":"eventEmitter.mjs","names":["EventEmitter","_createClass","_this","_classCallCheck","_defineProperty","emit","eventName","_len","arguments","length","args","Array","_key","event","events","forEach","fn","call","apply","concat","subscribe","push","filter","eventFn","default"],"sources":["../../src/utils/eventEmitter.ts"],"sourcesContent":["type DefaultEmit = (eventName: string, ...args: any[]) => void;\ntype DefaultSubscribe = (eventName: string, fn: any) => () => void;\n\nexport default class EventEmitter<Emit = DefaultEmit, Subscribe = DefaultSubscribe> {\n private events: any = {};\n constructor() {\n this.emit = ((eventName: string, ...args: any[]) => {\n const event = this.events[eventName];\n if (event) {\n event.forEach((fn: any) => {\n fn.call(null, ...args);\n });\n }\n }) as any;\n this.subscribe = ((eventName: string, fn: any) => {\n if (!this.events[eventName]) {\n this.events[eventName] = [];\n }\n\n this.events[eventName].push(fn);\n return () => {\n this.events[eventName] = this.events[eventName].filter((eventFn: any) => fn !== eventFn);\n };\n }) as any;\n }\n\n emit: Emit;\n\n subscribe: Subscribe;\n}\n"],"mappings":";;;IAGqBA,YAAY,gBAAAC,YAAA,CAE/B,SAAAD,aAAA,EAAc;EAAA,IAAAE,KAAA;EAAAC,eAAA,OAAAH,YAAA;EAAAI,eAAA,iBADQ,CAAC,CAAC;EAAAA,eAAA;EAAAA,eAAA;EAEtB,IAAI,CAACC,IAAI,GAAI,UAACC,SAAiB,EAAqB;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAhBC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAJF,IAAI,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;IAAA;IACtC,IAAMC,KAAK,GAAGX,KAAI,CAACY,MAAM,CAACR,SAAS,CAAC;IACpC,IAAIO,KAAK,EAAE;MACTA,KAAK,CAACE,OAAO,CAAC,UAACC,EAAO,EAAK;QACzBA,EAAE,CAACC,IAAI,CAAAC,KAAA,CAAPF,EAAE,GAAM,IAAI,EAAAG,MAAA,CAAKT,IAAI,EAAC;MACxB,CAAC,CAAC;IACJ;EACF,CAAS;EACT,IAAI,CAACU,SAAS,GAAI,UAACd,SAAiB,EAAEU,EAAO,EAAK;IAChD,IAAI,CAACd,KAAI,CAACY,MAAM,CAACR,SAAS,CAAC,EAAE;MAC3BJ,KAAI,CAACY,MAAM,CAACR,SAAS,CAAC,GAAG,EAAE;IAC7B;IAEAJ,KAAI,CAACY,MAAM,CAACR,SAAS,CAAC,CAACe,IAAI,CAACL,EAAE,CAAC;IAC/B,OAAO,YAAM;MACXd,KAAI,CAACY,MAAM,CAACR,SAAS,CAAC,GAAGJ,KAAI,CAACY,MAAM,CAACR,SAAS,CAAC,CAACgB,MAAM,CAAC,UAACC,OAAY;QAAA,OAAKP,EAAE,KAAKO,OAAO;MAAA,EAAC;IAC1F,CAAC;EACH,CAAS;AACX,CAAC;AAAA,SArBkBvB,YAAY,IAAAwB,OAAA","ignoreList":[]}
@@ -1,4 +1,6 @@
1
- export default function getDisplayName(WrappedComponent) {
2
- return WrappedComponent.displayName || WrappedComponent.name || 'Component';
1
+ function getDisplayName(WrappedComponent) {
2
+ return WrappedComponent.displayName || WrappedComponent.name || "Component";
3
3
  }
4
- //# sourceMappingURL=getDisplayName.mjs.map
4
+ export {
5
+ getDisplayName as default
6
+ };
@@ -0,0 +1,11 @@
1
+ import type { FC, ReactNode } from 'react';
2
+ import type { UnknownProperties } from '../core-types/UnknownProperties';
3
+ /** @deprecated */
4
+ export interface IIfProps extends IfProps, UnknownProperties {
5
+ }
6
+ export type IfProps = {
7
+ condition: boolean;
8
+ children?: ReactNode;
9
+ };
10
+ declare const If: FC<IIfProps>;
11
+ export default If;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ /** @deprecated */
8
+
9
+ var If = function If(props) {
10
+ var condition = props.condition,
11
+ children = props.children;
12
+ return condition ? children : null;
13
+ };
14
+ var _default = exports["default"] = If;
15
+ //# sourceMappingURL=if.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"if.js","names":["If","props","condition","children","_default","exports"],"sources":["../../src/utils/if.tsx"],"sourcesContent":["import type { FC, ReactNode } from 'react';\n\nimport type { UnknownProperties } from '../core-types/UnknownProperties';\n\n/** @deprecated */\nexport interface IIfProps extends IfProps, UnknownProperties {}\nexport type IfProps = {\n condition: boolean;\n children?: ReactNode;\n};\n\nconst If: FC<IIfProps> = (props) => {\n const { condition, children } = props;\n return (condition ? children : null) as ReturnType<FC>;\n};\n\nexport default If;\n"],"mappings":";;;;;;AAIA;;AAOA,IAAMA,EAAgB,GAAG,SAAnBA,EAAgBA,CAAIC,KAAK,EAAK;EAClC,IAAQC,SAAS,GAAeD,KAAK,CAA7BC,SAAS;IAAEC,QAAQ,GAAKF,KAAK,CAAlBE,QAAQ;EAC3B,OAAQD,SAAS,GAAGC,QAAQ,GAAG,IAAI;AACrC,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,cAEaL,EAAE","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ /** @deprecated */
2
+
3
+ var If = function If(props) {
4
+ var condition = props.condition,
5
+ children = props.children;
6
+ return condition ? children : null;
7
+ };
8
+ export default If;
9
+ //# sourceMappingURL=if.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"if.mjs","names":["If","props","condition","children"],"sources":["../../src/utils/if.tsx"],"sourcesContent":["import type { FC, ReactNode } from 'react';\n\nimport type { UnknownProperties } from '../core-types/UnknownProperties';\n\n/** @deprecated */\nexport interface IIfProps extends IfProps, UnknownProperties {}\nexport type IfProps = {\n condition: boolean;\n children?: ReactNode;\n};\n\nconst If: FC<IIfProps> = (props) => {\n const { condition, children } = props;\n return (condition ? children : null) as ReturnType<FC>;\n};\n\nexport default If;\n"],"mappings":"AAIA;;AAOA,IAAMA,EAAgB,GAAG,SAAnBA,EAAgBA,CAAIC,KAAK,EAAK;EAClC,IAAQC,SAAS,GAAeD,KAAK,CAA7BC,SAAS;IAAEC,QAAQ,GAAKF,KAAK,CAAlBE,QAAQ;EAC3B,OAAQD,SAAS,GAAGC,QAAQ,GAAG,IAAI;AACrC,CAAC;AAED,eAAeH,EAAE","ignoreList":[]}
@@ -29,7 +29,7 @@ function injectStyle(css) {
29
29
  sh = prevSh;
30
30
  } else {
31
31
  // @ts-ignore
32
- var version = "17.0.1";
32
+ var version = "16.6.0";
33
33
  sh = document.createElement('style');
34
34
  sh.setAttribute('data-ui-v', version);
35
35
  sh.classList.add(selectorClass);
@@ -22,7 +22,7 @@ function injectStyle(css) {
22
22
  sh = prevSh;
23
23
  } else {
24
24
  // @ts-ignore
25
- var version = "17.0.1";
25
+ var version = "16.6.0";
26
26
  sh = document.createElement('style');
27
27
  sh.setAttribute('data-ui-v', version);
28
28
  sh.classList.add(selectorClass);
@@ -1,8 +1,10 @@
1
- import React, { type MutableRefObject, type Ref } from 'react';
1
+ import React, { type MutableRefObject, type Ref, type RefObject } from 'react';
2
2
  export declare function setRef<T>(ref: Ref<T>, value: T): void;
3
3
  type Refs = React.ReactInstance | React.RefObject<React.ReactInstance>;
4
4
  export declare function getRef(ref: Refs): React.ReactInstance | null;
5
5
  export declare function useCallbackRef<T>(initialValue: T | null, callback: (newValue: T | null, lastValue: T | null) => void): MutableRefObject<T | null>;
6
6
  export declare function useForkRef<T>(...refs: Ref<T>[]): Ref<T>;
7
7
  export declare function forkRef<T>(...refs: Ref<T>[]): Ref<T>;
8
+ export type NodeByRef = RefObject<Element> | Element | (() => RefObject<Element> | Element);
9
+ export declare function getNodeByRef(ref: NodeByRef): Element | null;
8
10
  export {};
package/lib/utils/ref.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.forkRef = forkRef;
8
+ exports.getNodeByRef = getNodeByRef;
8
9
  exports.getRef = getRef;
9
10
  exports.setRef = setRef;
10
11
  exports.useCallbackRef = useCallbackRef;
@@ -12,6 +13,7 @@ exports.useForkRef = useForkRef;
12
13
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
14
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
14
15
  var _react = _interopRequireDefault(require("react"));
16
+ var _reactDom = require("react-dom");
15
17
  function setRef(ref, value) {
16
18
  if (typeof ref === 'function') {
17
19
  ref(value);
@@ -79,4 +81,16 @@ function forkRef() {
79
81
  });
80
82
  };
81
83
  }
84
+ function getNodeByRef(ref) {
85
+ if (typeof ref === 'function') {
86
+ ref = ref();
87
+ }
88
+ if (!ref) return null;
89
+ var node = getRef(ref);
90
+ if (!node) return null;
91
+ if ('nodeType' in node && node.nodeType === 1) return node;
92
+ if (Object.keys(node).length === 1 && 'getBoundingClientRect' in node) return null;
93
+ if (! /*#__PURE__*/_react["default"].isValidElement(node) && !(node instanceof _react["default"].Component)) return null;
94
+ return (0, _reactDom.findDOMNode)(node);
95
+ }
82
96
  //# sourceMappingURL=ref.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ref.js","names":["_react","_interopRequireDefault","require","setRef","ref","value","hasOwnProperty","getRef","current","useCallbackRef","initialValue","callback","_React$useState","React","useState","facade","last","_React$useState2","_slicedToArray2","useForkRef","_len","arguments","length","refs","Array","_key","useCallback","refValue","uniqueRefs","_toConsumableArray2","Set","forEach","forkRef","_len2","_key2","every"],"sources":["../../src/utils/ref.ts"],"sourcesContent":["import React, { type MutableRefObject, type Ref } from 'react';\n\nexport function setRef<T>(ref: Ref<T>, value: T) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref?.hasOwnProperty('current')) {\n // @ts-ignore\n ref['current'] = value;\n }\n}\n\ntype Refs = React.ReactInstance | React.RefObject<React.ReactInstance>;\n\nexport function getRef(ref: Refs): React.ReactInstance | null {\n if (!ref) return null;\n return 'current' in ref ? ref.current : ref;\n}\n\nexport function useCallbackRef<T>(\n initialValue: T | null,\n callback: (newValue: T | null, lastValue: T | null) => void,\n): MutableRefObject<T | null> {\n const [ref] = React.useState(() => ({\n // value\n value: initialValue,\n // last callback\n callback,\n // \"memoized\" public interface\n facade: {\n get current() {\n return ref.value;\n },\n set current(value) {\n const last = ref.value;\n if (last !== value) {\n ref.value = value;\n ref.callback(value, last);\n }\n },\n },\n }));\n // update callback\n ref.callback = callback;\n\n return ref.facade;\n}\n\nexport function useForkRef<T>(...refs: Ref<T>[]): Ref<T> {\n return React.useCallback((refValue: any) => {\n const uniqueRefs = [...new Set(refs)];\n uniqueRefs.forEach((ref) => setRef(ref, refValue));\n }, refs);\n}\n\nexport function forkRef<T>(...refs: Ref<T>[]): Ref<T> {\n if (refs.every((ref) => ref == null)) {\n return null;\n }\n return (refValue) => {\n const uniqueRefs = [...new Set(refs)];\n uniqueRefs.forEach((ref) => setRef(ref, refValue));\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEO,SAASC,MAAMA,CAAIC,GAAW,EAAEC,KAAQ,EAAE;EAC/C,IAAI,OAAOD,GAAG,KAAK,UAAU,EAAE;IAC7BA,GAAG,CAACC,KAAK,CAAC;EACZ,CAAC,MAAM,IAAID,GAAG,aAAHA,GAAG,eAAHA,GAAG,CAAEE,cAAc,CAAC,SAAS,CAAC,EAAE;IACzC;IACAF,GAAG,CAAC,SAAS,CAAC,GAAGC,KAAK;EACxB;AACF;AAIO,SAASE,MAAMA,CAACH,GAAS,EAA8B;EAC5D,IAAI,CAACA,GAAG,EAAE,OAAO,IAAI;EACrB,OAAO,SAAS,IAAIA,GAAG,GAAGA,GAAG,CAACI,OAAO,GAAGJ,GAAG;AAC7C;AAEO,SAASK,cAAcA,CAC5BC,YAAsB,EACtBC,QAA2D,EAC/B;EAC5B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MAAA,EAAxBC,IAAI,OAAAC,KAAA,CAAAS,KAAA,GAAAC,KAAA,MAAAA,KAAA,GAAAD,KAAA,EAAAC,KAAA;IAAJX,IAAI,CAAAW,KAAA,IAAAb,SAAA,CAAAa,KAAA;EAAA;EAChC,IAAIX,IAAI,CAACY,KAAK,CAAC,UAAC/B,GAAG;IAAA,OAAKA,GAAG,IAAI,IAAI;EAAA,EAAC,EAAE;IACpC,OAAO,IAAI;EACb;EACA,OAAO,UAACuB,QAAQ,EAAK;IACnB,IAAMC,UAAU,OAAAC,mBAAA,aAAO,IAAIC,GAAG,CAACP,IAAI,CAAC,CAAC;IACrCK,UAAU,CAACG,OAAO,CAAC,UAAC3B,GAAG;MAAA,OAAKD,MAAM,CAACC,GAAG,EAAEuB,QAAQ,CAAC;IAAA,EAAC;EACpD,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"ref.js","names":["_react","_interopRequireDefault","require","_reactDom","setRef","ref","value","hasOwnProperty","getRef","current","useCallbackRef","initialValue","callback","_React$useState","React","useState","facade","last","_React$useState2","_slicedToArray2","useForkRef","_len","arguments","length","refs","Array","_key","useCallback","refValue","uniqueRefs","_toConsumableArray2","Set","forEach","forkRef","_len2","_key2","every","getNodeByRef","node","nodeType","Object","keys","isValidElement","Component","findDOMNode"],"sources":["../../src/utils/ref.ts"],"sourcesContent":["import React, { type MutableRefObject, type Ref, type RefObject } from 'react';\nimport { findDOMNode } from 'react-dom';\n\nexport function setRef<T>(ref: Ref<T>, value: T) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref?.hasOwnProperty('current')) {\n // @ts-ignore\n ref['current'] = value;\n }\n}\n\ntype Refs = React.ReactInstance | React.RefObject<React.ReactInstance>;\n\nexport function getRef(ref: Refs): React.ReactInstance | null {\n if (!ref) return null;\n return 'current' in ref ? ref.current : ref;\n}\n\nexport function useCallbackRef<T>(\n initialValue: T | null,\n callback: (newValue: T | null, lastValue: T | null) => void,\n): MutableRefObject<T | null> {\n const [ref] = React.useState(() => ({\n // value\n value: initialValue,\n // last callback\n callback,\n // \"memoized\" public interface\n facade: {\n get current() {\n return ref.value;\n },\n set current(value) {\n const last = ref.value;\n if (last !== value) {\n ref.value = value;\n ref.callback(value, last);\n }\n },\n },\n }));\n // update callback\n ref.callback = callback;\n\n return ref.facade;\n}\n\nexport function useForkRef<T>(...refs: Ref<T>[]): Ref<T> {\n return React.useCallback((refValue: any) => {\n const uniqueRefs = [...new Set(refs)];\n uniqueRefs.forEach((ref) => setRef(ref, refValue));\n }, refs);\n}\n\nexport function forkRef<T>(...refs: Ref<T>[]): Ref<T> {\n if (refs.every((ref) => ref == null)) {\n return null;\n }\n return (refValue) => {\n const uniqueRefs = [...new Set(refs)];\n uniqueRefs.forEach((ref) => setRef(ref, refValue));\n };\n}\n\nexport type NodeByRef = RefObject<Element> | Element | (() => RefObject<Element> | Element);\n\nexport function getNodeByRef(ref: NodeByRef): Element | null {\n if (typeof ref === 'function') {\n ref = ref();\n }\n if (!ref) return null;\n\n const node = getRef(ref);\n if (!node) return null;\n if ('nodeType' in node && node.nodeType === 1) return node;\n if (Object.keys(node).length === 1 && 'getBoundingClientRect' in node) return null;\n if (!React.isValidElement(node) && !(node instanceof React.Component)) return null;\n\n return findDOMNode(node) as Element;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAEO,SAASE,MAAMA,CAAIC,GAAW,EAAEC,KAAQ,EAAE;EAC/C,IAAI,OAAOD,GAAG,KAAK,UAAU,EAAE;IAC7BA,GAAG,CAACC,KAAK,CAAC;EACZ,CAAC,MAAM,IAAID,GAAG,aAAHA,GAAG,eAAHA,GAAG,CAAEE,cAAc,CAAC,SAAS,CAAC,EAAE;IACzC;IACAF,GAAG,CAAC,SAAS,CAAC,GAAGC,KAAK;EACxB;AACF;AAIO,SAASE,MAAMA,CAACH,GAAS,EAA8B;EAC5D,IAAI,CAACA,G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AAI,YAAYxB,iBAAK,CAAC6B,SAAS,CAAC,EAAE,OAAO,IAAI;EAElF,OAAO,IAAAC,qBAAW,EAACN,IAAI,CAAC;AAC1B","ignoreList":[]}
package/lib/utils/ref.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import React from "react";
4
+ import { findDOMNode } from "react-dom";
4
5
  function setRef(ref, value) {
5
6
  if (typeof ref === "function") {
6
7
  ref(value);
@@ -64,8 +65,21 @@ function forkRef() {
64
65
  });
65
66
  };
66
67
  }
68
+ function getNodeByRef(ref) {
69
+ if (typeof ref === "function") {
70
+ ref = ref();
71
+ }
72
+ if (!ref) return null;
73
+ var node = getRef(ref);
74
+ if (!node) return null;
75
+ if ("nodeType" in node && node.nodeType === 1) return node;
76
+ if (Object.keys(node).length === 1 && "getBoundingClientRect" in node) return null;
77
+ if (!/* @__PURE__ */ React.isValidElement(node) && !(node instanceof React.Component)) return null;
78
+ return findDOMNode(node);
79
+ }
67
80
  export {
68
81
  forkRef,
82
+ getNodeByRef,
69
83
  getRef,
70
84
  setRef,
71
85
  useCallbackRef,