@pisell/utils 3.0.6 → 3.0.7

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 (200) hide show
  1. package/es/arrayUtils.d.ts +23 -26
  2. package/es/arrayUtils.js +157 -97
  3. package/es/common/index.d.ts +5 -0
  4. package/es/common/index.js +5 -0
  5. package/es/common/stateHelper.d.ts +2 -6
  6. package/es/common/stateHelper.js +24 -22
  7. package/es/common/types.d.ts +10 -13
  8. package/es/common/types.js +1 -0
  9. package/es/componentStorage.d.ts +25 -27
  10. package/es/componentStorage.js +130 -94
  11. package/es/constants/index.js +9 -7
  12. package/es/date.js +53 -36
  13. package/es/document.js +67 -43
  14. package/es/escPosPrinter/EscPosPrinter.js +490 -353
  15. package/es/escPosPrinter/index.d.ts +9 -9
  16. package/es/escPosPrinter/index.js +52 -37
  17. package/es/firebase/config/index.js +54 -0
  18. package/es/firebase/index.js +232 -0
  19. package/es/format.d.ts +15 -12
  20. package/es/format.js +156 -89
  21. package/es/image.js +60 -48
  22. package/es/index.d.ts +24 -39
  23. package/es/index.js +35 -40
  24. package/es/jsBridge/index.d.ts +4 -8
  25. package/es/jsBridge/index.js +55 -56
  26. package/es/jsBridge/regDeviceApi.js +126 -87
  27. package/es/jsBridge/types.d.ts +115 -95
  28. package/es/jsBridge/types.js +1 -0
  29. package/es/locales.d.ts +8 -11
  30. package/es/locales.js +96 -77
  31. package/es/log.d.ts +6 -11
  32. package/es/log.js +59 -37
  33. package/es/miniRedux.d.ts +13 -20
  34. package/es/miniRedux.js +76 -42
  35. package/es/number-input/hooks/index.d.ts +4 -0
  36. package/es/number-input/hooks/index.js +5 -0
  37. package/es/number-input/hooks/useNumberInputState.d.ts +2 -6
  38. package/es/number-input/hooks/useNumberInputState.js +128 -71
  39. package/es/number-input/index.d.ts +14 -0
  40. package/es/number-input/index.js +21 -0
  41. package/es/number-input/types.d.ts +88 -88
  42. package/es/number-input/types.js +1 -0
  43. package/es/number-input/utils/formatter.d.ts +10 -13
  44. package/es/number-input/utils/formatter.js +77 -51
  45. package/es/number-input/utils/index.d.ts +7 -0
  46. package/es/number-input/utils/index.js +8 -0
  47. package/es/number-input/utils/validation.d.ts +2 -7
  48. package/es/number-input/utils/validation.js +66 -51
  49. package/es/otherUtils.d.ts +9 -12
  50. package/es/otherUtils.js +129 -71
  51. package/es/platform.d.ts +9 -12
  52. package/es/platform.js +85 -61
  53. package/es/select/hooks/index.d.ts +5 -0
  54. package/es/select/hooks/index.js +6 -0
  55. package/es/select/hooks/useDebouncedSearch.d.ts +1 -4
  56. package/es/select/hooks/useDebouncedSearch.js +53 -39
  57. package/es/select/hooks/useSelectState.d.ts +7 -7
  58. package/es/select/hooks/useSelectState.js +113 -56
  59. package/es/select/index.d.ts +8 -7
  60. package/es/select/index.js +13 -0
  61. package/es/select/types.d.ts +211 -211
  62. package/es/select/types.js +1 -0
  63. package/es/select/utils/filterOptions.d.ts +6 -7
  64. package/es/select/utils/filterOptions.js +31 -26
  65. package/es/select/utils/helpers.d.ts +9 -10
  66. package/es/select/utils/helpers.js +52 -42
  67. package/es/select/utils/index.d.ts +7 -4
  68. package/es/select/utils/index.js +8 -0
  69. package/es/select/utils/sortOptions.d.ts +5 -6
  70. package/es/select/utils/sortOptions.js +31 -19
  71. package/es/select/utils/tagAggregation.d.ts +6 -6
  72. package/es/select/utils/tagAggregation.js +47 -34
  73. package/es/text-input/hooks/index.d.ts +4 -0
  74. package/es/text-input/hooks/index.js +5 -0
  75. package/es/text-input/hooks/useTextInputState.d.ts +2 -6
  76. package/es/text-input/hooks/useTextInputState.js +126 -69
  77. package/es/text-input/index.d.ts +14 -0
  78. package/es/text-input/index.js +20 -0
  79. package/es/text-input/types.d.ts +48 -48
  80. package/es/text-input/types.js +1 -0
  81. package/es/text-input/utils/index.d.ts +5 -0
  82. package/es/text-input/utils/index.js +7 -0
  83. package/es/text-input/utils/validation.d.ts +2 -7
  84. package/es/text-input/utils/validation.js +70 -50
  85. package/es/typeUtils.js +84 -61
  86. package/es/walletValidity.d.ts +42 -44
  87. package/es/walletValidity.js +557 -396
  88. package/es/weighing.d.ts +45 -48
  89. package/es/weighing.js +106 -83
  90. package/lib/arrayUtils.d.ts +23 -26
  91. package/lib/arrayUtils.js +111 -101
  92. package/lib/common/index.d.ts +5 -0
  93. package/lib/common/index.js +29 -0
  94. package/lib/common/stateHelper.d.ts +2 -6
  95. package/lib/common/stateHelper.js +32 -21
  96. package/lib/common/types.d.ts +10 -13
  97. package/lib/common/types.js +17 -0
  98. package/lib/componentStorage.d.ts +25 -27
  99. package/lib/componentStorage.js +126 -96
  100. package/lib/constants/index.js +36 -7
  101. package/lib/date.js +65 -43
  102. package/lib/document.js +62 -46
  103. package/lib/escPosPrinter/EscPosPrinter.js +403 -327
  104. package/lib/escPosPrinter/index.d.ts +9 -9
  105. package/lib/escPosPrinter/index.js +84 -38
  106. package/lib/firebase/config/index.js +79 -0
  107. package/lib/firebase/index.js +180 -0
  108. package/lib/format.d.ts +15 -12
  109. package/lib/format.js +133 -91
  110. package/lib/image.js +74 -48
  111. package/lib/index.d.ts +24 -39
  112. package/lib/index.js +80 -137
  113. package/lib/jsBridge/index.d.ts +4 -8
  114. package/lib/jsBridge/index.js +76 -57
  115. package/lib/jsBridge/regDeviceApi.js +133 -86
  116. package/lib/jsBridge/types.d.ts +115 -95
  117. package/lib/jsBridge/types.js +17 -0
  118. package/lib/locales.d.ts +8 -11
  119. package/lib/locales.js +90 -79
  120. package/lib/log.d.ts +6 -11
  121. package/lib/log.js +61 -37
  122. package/lib/miniRedux.d.ts +13 -20
  123. package/lib/miniRedux.js +89 -43
  124. package/lib/number-input/hooks/index.d.ts +4 -0
  125. package/lib/number-input/hooks/index.js +29 -0
  126. package/lib/number-input/hooks/useNumberInputState.d.ts +2 -6
  127. package/lib/number-input/hooks/useNumberInputState.js +81 -71
  128. package/lib/number-input/index.d.ts +14 -0
  129. package/lib/number-input/index.js +41 -0
  130. package/lib/number-input/types.d.ts +88 -88
  131. package/lib/number-input/types.js +17 -0
  132. package/lib/number-input/utils/formatter.d.ts +10 -13
  133. package/lib/number-input/utils/formatter.js +49 -52
  134. package/lib/number-input/utils/index.d.ts +7 -0
  135. package/lib/number-input/utils/index.js +39 -0
  136. package/lib/number-input/utils/validation.d.ts +2 -7
  137. package/lib/number-input/utils/validation.js +52 -50
  138. package/lib/otherUtils.d.ts +9 -12
  139. package/lib/otherUtils.js +98 -86
  140. package/lib/platform.d.ts +9 -12
  141. package/lib/platform.js +123 -68
  142. package/lib/select/hooks/index.d.ts +5 -0
  143. package/lib/select/hooks/index.js +34 -0
  144. package/lib/select/hooks/useDebouncedSearch.d.ts +1 -4
  145. package/lib/select/hooks/useDebouncedSearch.js +41 -40
  146. package/lib/select/hooks/useSelectState.d.ts +7 -7
  147. package/lib/select/hooks/useSelectState.js +93 -58
  148. package/lib/select/index.d.ts +8 -7
  149. package/lib/select/index.js +53 -0
  150. package/lib/select/types.d.ts +211 -211
  151. package/lib/select/types.js +17 -0
  152. package/lib/select/utils/filterOptions.d.ts +6 -7
  153. package/lib/select/utils/filterOptions.js +37 -26
  154. package/lib/select/utils/helpers.d.ts +9 -10
  155. package/lib/select/utils/helpers.js +41 -45
  156. package/lib/select/utils/index.d.ts +7 -4
  157. package/lib/select/utils/index.js +48 -0
  158. package/lib/select/utils/sortOptions.d.ts +5 -6
  159. package/lib/select/utils/sortOptions.js +39 -18
  160. package/lib/select/utils/tagAggregation.d.ts +6 -6
  161. package/lib/select/utils/tagAggregation.js +41 -33
  162. package/lib/text-input/hooks/index.d.ts +4 -0
  163. package/lib/text-input/hooks/index.js +29 -0
  164. package/lib/text-input/hooks/useTextInputState.d.ts +2 -6
  165. package/lib/text-input/hooks/useTextInputState.js +79 -69
  166. package/lib/text-input/index.d.ts +14 -0
  167. package/lib/text-input/index.js +35 -0
  168. package/lib/text-input/types.d.ts +48 -48
  169. package/lib/text-input/types.js +17 -0
  170. package/lib/text-input/utils/index.d.ts +5 -0
  171. package/lib/text-input/utils/index.js +32 -0
  172. package/lib/text-input/utils/validation.d.ts +2 -7
  173. package/lib/text-input/utils/validation.js +58 -49
  174. package/lib/typeUtils.js +73 -68
  175. package/lib/walletValidity.d.ts +42 -44
  176. package/lib/walletValidity.js +393 -410
  177. package/lib/weighing.d.ts +45 -48
  178. package/lib/weighing.js +149 -104
  179. package/package.json +1 -1
  180. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +0 -27
  181. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +0 -12
  182. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +0 -25
  183. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +0 -14
  184. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +0 -9
  185. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +0 -11
  186. package/es/date.d.ts +0 -31
  187. package/es/document.d.ts +0 -16
  188. package/es/image.d.ts +0 -14
  189. package/es/typeUtils.d.ts +0 -45
  190. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +0 -27
  191. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +0 -12
  192. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +0 -25
  193. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +0 -14
  194. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +0 -9
  195. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +0 -16
  196. package/lib/_virtual/_rolldown/runtime.js +0 -23
  197. package/lib/date.d.ts +0 -31
  198. package/lib/document.d.ts +0 -16
  199. package/lib/image.d.ts +0 -14
  200. package/lib/typeUtils.d.ts +0 -45
package/es/locales.js CHANGED
@@ -1,85 +1,104 @@
1
- import { _objectSpread2 } from "./_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
2
- //#region src/locales.ts
3
- let localeMaps = {
4
- en: {},
5
- "zh-CN": {},
6
- "zh-HK": {},
7
- "ja": {},
8
- "pt": {}
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ // 所有多语言储存
8
+ var localeMaps = {
9
+ en: {},
10
+ 'zh-CN': {},
11
+ 'zh-HK': {},
12
+ 'ja': {},
13
+ 'pt': {}
9
14
  };
10
- let locale = "en";
11
- let localeMap = {};
12
- const formatLocale = (_locale) => {
13
- const obj = {
14
- en: "en",
15
- "en-US": "en",
16
- "en-us": "en",
17
- "zh-CN": "zh-CN",
18
- "zh-cn": "zh-CN",
19
- "zh-HK": "zh-HK",
20
- "zh-hk": "zh-HK",
21
- "zh-TW": "zh-HK",
22
- "zh-tw": "zh-HK",
23
- ja: "ja",
24
- "ja-JP": "ja",
25
- "ja-jp": "ja",
26
- pt: "pt",
27
- "pt-BR": "pt",
28
- "pt-br": "pt",
29
- "pt-PT": "pt",
30
- "pt-pt": "pt"
31
- };
32
- const direct = obj[_locale];
33
- if (direct) return direct;
34
- const norm = String(_locale || "").trim().replace(/_/g, "-").toLowerCase();
35
- if (obj[norm]) return obj[norm];
36
- if (norm.startsWith("ja")) return "ja";
37
- if (norm.startsWith("pt")) return "pt";
38
- if (norm.startsWith("zh-hk") || norm.startsWith("zh-tw")) return "zh-HK";
39
- if (norm.startsWith("zh-cn")) return "zh-CN";
40
- if (norm.startsWith("en")) return "en";
41
- return "en";
15
+
16
+ // 当前语言
17
+ var locale = 'en';
18
+
19
+ // 当前语言对应的多语言
20
+ var localeMap = {};
21
+
22
+ // 语言格式化(兼容 BCP 47,如 ja-JP、pt-BR)
23
+ var formatLocale = function formatLocale(_locale) {
24
+ var obj = {
25
+ en: 'en',
26
+ 'en-US': 'en',
27
+ 'en-us': 'en',
28
+ 'zh-CN': 'zh-CN',
29
+ 'zh-cn': 'zh-CN',
30
+ 'zh-HK': 'zh-HK',
31
+ 'zh-hk': 'zh-HK',
32
+ 'zh-TW': 'zh-HK',
33
+ 'zh-tw': 'zh-HK',
34
+ ja: 'ja',
35
+ 'ja-JP': 'ja',
36
+ 'ja-jp': 'ja',
37
+ pt: 'pt',
38
+ 'pt-BR': 'pt',
39
+ 'pt-br': 'pt',
40
+ 'pt-PT': 'pt',
41
+ 'pt-pt': 'pt'
42
+ };
43
+ var direct = obj[_locale];
44
+ if (direct) return direct;
45
+ var norm = String(_locale || '').trim().replace(/_/g, '-').toLowerCase();
46
+ if (obj[norm]) return obj[norm];
47
+ if (norm.startsWith('ja')) return 'ja';
48
+ if (norm.startsWith('pt')) return 'pt';
49
+ if (norm.startsWith('zh-hk') || norm.startsWith('zh-tw')) return 'zh-HK';
50
+ if (norm.startsWith('zh-cn')) return 'zh-CN';
51
+ if (norm.startsWith('en')) return 'en';
52
+ return 'en';
42
53
  };
54
+
43
55
  /**
44
- * @title: 初始化多语言
45
- * @description:
46
- * @param {any} _localeMaps
47
- * @param {string} _locale
48
- * @return {*}
49
- * @Author: zhiwei.Wang
50
- * @Date: 2024-01-17 21:38
51
- */
52
- const init = (_localeMaps, _locale) => {
53
- locale = formatLocale(_locale);
54
- let allLocales = {};
55
- for (let key in localeMaps) allLocales[key] = _objectSpread2(_objectSpread2({}, localeMaps[key]), _localeMaps[key]);
56
- localeMaps = allLocales;
57
- localeMap = localeMaps[locale];
56
+ * @title: 初始化多语言
57
+ * @description:
58
+ * @param {any} _localeMaps
59
+ * @param {string} _locale
60
+ * @return {*}
61
+ * @Author: zhiwei.Wang
62
+ * @Date: 2024-01-17 21:38
63
+ */
64
+ var init = function init(_localeMaps, _locale) {
65
+ // 设置语言
66
+ locale = formatLocale(_locale);
67
+ var allLocales = {};
68
+ for (var key in localeMaps) {
69
+ allLocales[key] = _objectSpread(_objectSpread({}, localeMaps[key]), _localeMaps[key]);
70
+ }
71
+
72
+ // 更新语言
73
+ localeMaps = allLocales;
74
+
75
+ // 更新当前语言对应的多语言
76
+ localeMap = localeMaps[locale];
58
77
  };
78
+
59
79
  /**
60
- * @title: 获取语言
61
- * @description:
62
- * @param {string} id
63
- * @return {*}
64
- * @Author: zhiwei.Wang
65
- * @Date: 2024-01-17 21:39
66
- */
67
- const getText = (id) => {
68
- var _localeMaps$en;
69
- return localeMap[id] || (localeMaps === null || localeMaps === void 0 || (_localeMaps$en = localeMaps["en"]) === null || _localeMaps$en === void 0 ? void 0 : _localeMaps$en[id]) || id;
80
+ * @title: 获取语言
81
+ * @description:
82
+ * @param {string} id
83
+ * @return {*}
84
+ * @Author: zhiwei.Wang
85
+ * @Date: 2024-01-17 21:39
86
+ */
87
+ var getText = function getText(id) {
88
+ var _localeMaps2;
89
+ return localeMap[id] || ((_localeMaps2 = localeMaps) === null || _localeMaps2 === void 0 || (_localeMaps2 = _localeMaps2['en']) === null || _localeMaps2 === void 0 ? void 0 : _localeMaps2[id]) || id;
70
90
  };
91
+
71
92
  /** 获取当前语言(与 getText 同源,供 datetime 等组件与 getText 语言一致) */
72
- const getLocale = () => {
73
- return locale;
93
+ var getLocale = function getLocale() {
94
+ return locale;
74
95
  };
75
- const locales = {
76
- init,
77
- getText,
78
- getLocale,
79
- locale,
80
- localeMap,
81
- localeMaps,
82
- formatLocale
83
- };
84
- //#endregion
85
- export { locales };
96
+ export var locales = {
97
+ init: init,
98
+ getText: getText,
99
+ getLocale: getLocale,
100
+ locale: locale,
101
+ localeMap: localeMap,
102
+ localeMaps: localeMaps,
103
+ formatLocale: formatLocale
104
+ };
package/es/log.d.ts CHANGED
@@ -1,15 +1,10 @@
1
- //#region src/log.d.ts
2
1
  interface contentItem {
3
- key: string;
4
- value: string;
2
+ key: string;
3
+ value: string;
5
4
  }
6
5
  interface sendWebhookProps {
7
- title: string;
8
- content: contentItem[];
6
+ title: string;
7
+ content: contentItem[];
9
8
  }
10
- declare const sendWarningLog: ({
11
- title,
12
- content
13
- }: sendWebhookProps) => Promise<any>;
14
- //#endregion
15
- export { sendWarningLog };
9
+ export declare const sendWarningLog: ({ title, content }: sendWebhookProps) => Promise<any>;
10
+ export {};
package/es/log.js CHANGED
@@ -1,38 +1,60 @@
1
- import { _asyncToGenerator } from "./_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
2
- import { webHookApi } from "./constants/index.js";
3
- import { getPisellUtilsConfig } from "./index.js";
4
- //#region src/log.ts
5
- const createFeishuMessageContent = (contentArr) => {
6
- return JSON.stringify(contentArr.map((item) => {
7
- return [{
8
- tag: "text",
9
- text: `${item.key}: `
10
- }, {
11
- tag: "text",
12
- text: `${item.value}`
13
- }];
14
- }));
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ import { getPisellUtilsConfig } from "./index";
6
+ import { webHookApi } from "./constants";
7
+ var createFeishuMessageContent = function createFeishuMessageContent(contentArr) {
8
+ return JSON.stringify(contentArr.map(function (item) {
9
+ return [{
10
+ tag: 'text',
11
+ text: "".concat(item.key, ": ")
12
+ }, {
13
+ tag: 'text',
14
+ text: "".concat(item.value)
15
+ }];
16
+ }));
15
17
  };
16
- const sendWarningLog = function() {
17
- var _ref = _asyncToGenerator(function* ({ title, content }) {
18
- const contentStr = createFeishuMessageContent(content);
19
- let apiUrl = "";
20
- const config = getPisellUtilsConfig();
21
- console.log("PISELL_UTILS_CONFIG>>>>", config);
22
- if ((config === null || config === void 0 ? void 0 : config.env) === "dev" || (config === null || config === void 0 ? void 0 : config.env) === "pre" || (config === null || config === void 0 ? void 0 : config.env) === "release") apiUrl = webHookApi.warning_log.test;
23
- else apiUrl = webHookApi.warning_log.prod;
24
- return yield (yield fetch(apiUrl, {
25
- headers: { "Content-Type": "application/json" },
26
- method: "POST",
27
- body: JSON.stringify({
28
- msg_type: "post",
29
- content: `{"post":{"zh_cn":{"title":"${title}","content":${contentStr}}}}`
30
- })
31
- })).json();
32
- });
33
- return function sendWarningLog(_x) {
34
- return _ref.apply(this, arguments);
35
- };
36
- }();
37
- //#endregion
38
- export { sendWarningLog };
18
+ export var sendWarningLog = /*#__PURE__*/function () {
19
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
20
+ var title, content, contentStr, apiUrl, config, response;
21
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
22
+ while (1) switch (_context.prev = _context.next) {
23
+ case 0:
24
+ title = _ref.title, content = _ref.content;
25
+ contentStr = createFeishuMessageContent(content);
26
+ apiUrl = '';
27
+ config = getPisellUtilsConfig();
28
+ console.log('PISELL_UTILS_CONFIG>>>>', config);
29
+ if ((config === null || config === void 0 ? void 0 : config.env) === 'dev' || (config === null || config === void 0 ? void 0 : config.env) === 'pre' || (config === null || config === void 0 ? void 0 : config.env) === 'release') {
30
+ apiUrl = webHookApi.warning_log.test;
31
+ } else {
32
+ apiUrl = webHookApi.warning_log.prod;
33
+ }
34
+ _context.next = 8;
35
+ return fetch(apiUrl, {
36
+ headers: {
37
+ 'Content-Type': 'application/json'
38
+ },
39
+ method: 'POST',
40
+ body: JSON.stringify({
41
+ msg_type: 'post',
42
+ content: "{\"post\":{\"zh_cn\":{\"title\":\"".concat(title, "\",\"content\":").concat(contentStr, "}}}")
43
+ })
44
+ });
45
+ case 8:
46
+ response = _context.sent;
47
+ _context.next = 11;
48
+ return response.json();
49
+ case 11:
50
+ return _context.abrupt("return", _context.sent);
51
+ case 12:
52
+ case "end":
53
+ return _context.stop();
54
+ }
55
+ }, _callee);
56
+ }));
57
+ return function sendWarningLog(_x) {
58
+ return _ref2.apply(this, arguments);
59
+ };
60
+ }();
package/es/miniRedux.d.ts CHANGED
@@ -1,23 +1,16 @@
1
- //#region src/miniRedux.d.ts
2
1
  interface MiniReduxProps<State, Namespace> {
3
- namespace?: Namespace;
4
- state?: State;
5
- reducers?: any;
6
- effects?: any;
2
+ namespace?: Namespace;
3
+ state?: State;
4
+ reducers?: any;
5
+ effects?: any;
7
6
  }
8
- declare const miniRedux: <State extends Record<string, any>, Namespace extends string>({
9
- namespace,
10
- state,
11
- reducers,
12
- effects
13
- }: MiniReduxProps<State, Namespace>) => {
14
- Context: React.Context<{ [K in Namespace]: State } & {
15
- dispatch: (params: {
16
- type: string;
17
- payload: any;
18
- }) => void;
19
- }>;
20
- Provider: (ComponentUi: any) => any;
7
+ export declare const miniRedux: <State extends Record<string, any>, Namespace extends string>({ namespace, state, reducers, effects, }: MiniReduxProps<State, Namespace>) => {
8
+ Context: React.Context<{ [K in Namespace]: State; } & {
9
+ dispatch: (params: {
10
+ type: string;
11
+ payload: any;
12
+ }) => void;
13
+ }>;
14
+ Provider: (ComponentUi: any) => any;
21
15
  };
22
- //#endregion
23
- export { miniRedux };
16
+ export {};
package/es/miniRedux.js CHANGED
@@ -1,42 +1,76 @@
1
- import { _objectSpread2 } from "./_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
2
- import React, { createContext, forwardRef, useCallback, useMemo, useReducer, useRef } from "react";
3
- //#region src/miniRedux.tsx
4
- const miniRedux = ({ namespace = "state", state, reducers = {}, effects = {} }) => {
5
- const Context = createContext({});
6
- const Provider = (ComponentUi) => {
7
- return forwardRef((props, ref) => {
8
- const stateRef = useRef();
9
- const [providerState, dispatch] = useReducer((state, { type, payload }) => {
10
- if (reducers[type]) return reducers[type](state, payload) || state;
11
- else return state;
12
- }, state);
13
- stateRef.current = providerState;
14
- const _dispatch = useCallback(({ type, payload }) => {
15
- if (effects[type]) effects[type].call(null, stateRef.current, payload, dispatch);
16
- else if (reducers[type]) dispatch({
17
- type,
18
- payload
19
- });
20
- }, []);
21
- const contextValue = useMemo(() => ({
22
- [namespace]: providerState,
23
- dispatch: _dispatch
24
- }), [providerState, _dispatch]);
25
- let _props = _objectSpread2(_objectSpread2({}, props), {}, {
26
- [namespace]: providerState,
27
- dispatch: _dispatch
28
- });
29
- if (_props.forwardedRef) {
30
- _props.forwardedRef;
31
- delete _props.forwardedRef;
32
- }
33
- return /* @__PURE__ */ React.createElement(Context.Provider, { value: contextValue }, /* @__PURE__ */ React.createElement(ComponentUi, _objectSpread2(_objectSpread2({}, _props), {}, { ref })));
34
- });
35
- };
36
- return {
37
- Context,
38
- Provider
39
- };
40
- };
41
- //#endregion
42
- export { miniRedux };
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ import React, { createContext, useCallback, useMemo, useReducer, forwardRef, useRef } from 'react';
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ export var miniRedux = function miniRedux(_ref2) {
16
+ var _ref2$namespace = _ref2.namespace,
17
+ namespace = _ref2$namespace === void 0 ? 'state' : _ref2$namespace,
18
+ state = _ref2.state,
19
+ _ref2$reducers = _ref2.reducers,
20
+ reducers = _ref2$reducers === void 0 ? {} : _ref2$reducers,
21
+ _ref2$effects = _ref2.effects,
22
+ effects = _ref2$effects === void 0 ? {} : _ref2$effects;
23
+ var Context = /*#__PURE__*/createContext({});
24
+ var Provider = function Provider(ComponentUi) {
25
+ var Components = /*#__PURE__*/forwardRef(function (props, ref) {
26
+ var stateRef = useRef();
27
+ var _useReducer = useReducer(function (state, _ref3) {
28
+ var type = _ref3.type,
29
+ payload = _ref3.payload;
30
+ if (reducers[type]) {
31
+ return reducers[type](state, payload) || state;
32
+ } else {
33
+ return state;
34
+ }
35
+ }, state),
36
+ _useReducer2 = _slicedToArray(_useReducer, 2),
37
+ providerState = _useReducer2[0],
38
+ dispatch = _useReducer2[1];
39
+ stateRef.current = providerState;
40
+ var _dispatch = useCallback(function (_ref4) {
41
+ var type = _ref4.type,
42
+ payload = _ref4.payload;
43
+ if (effects[type]) {
44
+ effects[type].call(null, stateRef.current, payload, dispatch);
45
+ } else if (reducers[type]) {
46
+ dispatch({
47
+ type: type,
48
+ payload: payload
49
+ });
50
+ }
51
+ }, []);
52
+
53
+ // 缓存Context value,避免不必要的重新渲染
54
+ var contextValue = useMemo(function () {
55
+ return _defineProperty(_defineProperty({}, namespace, providerState), "dispatch", _dispatch);
56
+ }, [providerState, _dispatch]);
57
+ var _props = _objectSpread(_objectSpread({}, props), {}, _defineProperty(_defineProperty({}, namespace, providerState), "dispatch", _dispatch));
58
+ var _ref = null;
59
+ if (_props.forwardedRef) {
60
+ _ref = _props.forwardedRef;
61
+ delete _props.forwardedRef;
62
+ }
63
+ return /*#__PURE__*/_jsx(Context.Provider, {
64
+ value: contextValue,
65
+ children: /*#__PURE__*/_jsx(ComponentUi, _objectSpread(_objectSpread({}, _props), {}, {
66
+ ref: ref
67
+ }))
68
+ });
69
+ });
70
+ return Components;
71
+ };
72
+ return {
73
+ Context: Context,
74
+ Provider: Provider
75
+ };
76
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 数值输入 Hooks 导出
3
+ */
4
+ export { useNumberInputState } from './useNumberInputState';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 数值输入 Hooks 导出
3
+ */
4
+
5
+ export { useNumberInputState } from "./useNumberInputState";
@@ -1,6 +1,4 @@
1
- import { BaseNumberInputProps, NumberInputState } from "../types.js";
2
-
3
- //#region src/number-input/hooks/useNumberInputState.d.ts
1
+ import type { BaseNumberInputProps, NumberInputState } from '../types';
4
2
  /**
5
3
  * 数值输入状态管理 Hook
6
4
  *
@@ -24,6 +22,4 @@ import { BaseNumberInputProps, NumberInputState } from "../types.js";
24
22
  * // 非受控模式
25
23
  * const state = useNumberInputState({ defaultValue: 10, min: 0, max: 100 });
26
24
  */
27
- declare function useNumberInputState(props: BaseNumberInputProps): NumberInputState;
28
- //#endregion
29
- export { useNumberInputState };
25
+ export declare function useNumberInputState(props: BaseNumberInputProps): NumberInputState;