@pisell/utils 1.0.72 → 1.0.73

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 (202) hide show
  1. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
  2. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
  3. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
  4. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
  5. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
  6. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +11 -0
  7. package/es/arrayUtils.d.ts +4 -1
  8. package/es/arrayUtils.js +15 -24
  9. package/es/common/stateHelper.d.ts +6 -2
  10. package/es/common/stateHelper.js +22 -24
  11. package/es/common/types.d.ts +13 -10
  12. package/es/componentStorage.d.ts +27 -25
  13. package/es/componentStorage.js +94 -130
  14. package/es/constants/index.js +7 -9
  15. package/es/date.d.ts +6 -3
  16. package/es/date.js +36 -53
  17. package/es/document.d.ts +6 -3
  18. package/es/document.js +43 -67
  19. package/es/escPosPrinter/EscPosPrinter.js +353 -490
  20. package/es/escPosPrinter/index.d.ts +9 -9
  21. package/es/escPosPrinter/index.js +37 -52
  22. package/es/format.d.ts +29 -0
  23. package/es/format.js +90 -116
  24. package/es/image.d.ts +13 -10
  25. package/es/image.js +48 -60
  26. package/es/index.d.ts +38 -23
  27. package/es/index.js +39 -34
  28. package/es/jsBridge/index.d.ts +26 -0
  29. package/es/jsBridge/index.js +57 -56
  30. package/es/jsBridge/regDeviceApi.js +107 -149
  31. package/es/jsBridge/types.d.ts +129 -0
  32. package/es/locales.d.ts +12 -0
  33. package/es/locales.js +77 -96
  34. package/es/log.d.ts +11 -6
  35. package/es/log.js +37 -59
  36. package/es/miniRedux.d.ts +23 -0
  37. package/es/miniRedux.js +42 -78
  38. package/es/number-input/hooks/useNumberInputState.d.ts +6 -2
  39. package/es/number-input/hooks/useNumberInputState.js +71 -128
  40. package/es/number-input/types.d.ts +88 -88
  41. package/es/number-input/utils/formatter.d.ts +13 -10
  42. package/es/number-input/utils/formatter.js +51 -77
  43. package/es/number-input/utils/validation.d.ts +7 -2
  44. package/es/number-input/utils/validation.js +51 -66
  45. package/es/otherUtils.d.ts +12 -9
  46. package/es/otherUtils.js +71 -129
  47. package/es/platform.d.ts +17 -9
  48. package/es/platform.js +78 -85
  49. package/es/select/hooks/useDebouncedSearch.d.ts +4 -1
  50. package/es/select/hooks/useDebouncedSearch.js +39 -53
  51. package/es/select/hooks/useSelectState.d.ts +7 -7
  52. package/es/select/hooks/useSelectState.js +56 -113
  53. package/es/select/index.d.ts +7 -8
  54. package/es/select/types.d.ts +211 -211
  55. package/es/select/utils/filterOptions.d.ts +7 -6
  56. package/es/select/utils/filterOptions.js +26 -31
  57. package/es/select/utils/helpers.d.ts +10 -9
  58. package/es/select/utils/helpers.js +42 -52
  59. package/es/select/utils/index.d.ts +4 -7
  60. package/es/select/utils/sortOptions.d.ts +6 -5
  61. package/es/select/utils/sortOptions.js +19 -31
  62. package/es/select/utils/tagAggregation.d.ts +6 -6
  63. package/es/select/utils/tagAggregation.js +34 -47
  64. package/es/text-input/hooks/useTextInputState.d.ts +6 -2
  65. package/es/text-input/hooks/useTextInputState.js +69 -126
  66. package/es/text-input/types.d.ts +48 -48
  67. package/es/text-input/utils/validation.d.ts +7 -2
  68. package/es/text-input/utils/validation.js +50 -70
  69. package/es/typeUtils.d.ts +11 -8
  70. package/es/typeUtils.js +61 -84
  71. package/es/walletValidity.d.ts +36 -34
  72. package/es/walletValidity.js +332 -456
  73. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
  74. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
  75. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
  76. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
  77. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
  78. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +16 -0
  79. package/lib/_virtual/_rolldown/runtime.js +23 -0
  80. package/lib/arrayUtils.d.ts +4 -1
  81. package/lib/arrayUtils.js +14 -39
  82. package/lib/common/stateHelper.d.ts +6 -2
  83. package/lib/common/stateHelper.js +21 -32
  84. package/lib/common/types.d.ts +13 -10
  85. package/lib/componentStorage.d.ts +27 -25
  86. package/lib/componentStorage.js +96 -126
  87. package/lib/constants/index.js +7 -36
  88. package/lib/date.d.ts +6 -3
  89. package/lib/date.js +43 -65
  90. package/lib/document.d.ts +6 -3
  91. package/lib/document.js +46 -62
  92. package/lib/escPosPrinter/EscPosPrinter.js +327 -403
  93. package/lib/escPosPrinter/index.d.ts +9 -9
  94. package/lib/escPosPrinter/index.js +38 -84
  95. package/lib/format.d.ts +29 -0
  96. package/lib/format.js +91 -99
  97. package/lib/image.d.ts +13 -10
  98. package/lib/image.js +48 -74
  99. package/lib/index.d.ts +38 -23
  100. package/lib/index.js +115 -78
  101. package/lib/jsBridge/index.d.ts +26 -0
  102. package/lib/jsBridge/index.js +58 -77
  103. package/lib/jsBridge/regDeviceApi.js +106 -153
  104. package/lib/jsBridge/types.d.ts +129 -0
  105. package/lib/locales.d.ts +12 -0
  106. package/lib/locales.js +79 -90
  107. package/lib/log.d.ts +11 -6
  108. package/lib/log.js +37 -61
  109. package/lib/miniRedux.d.ts +23 -0
  110. package/lib/miniRedux.js +43 -92
  111. package/lib/number-input/hooks/useNumberInputState.d.ts +6 -2
  112. package/lib/number-input/hooks/useNumberInputState.js +71 -81
  113. package/lib/number-input/types.d.ts +88 -88
  114. package/lib/number-input/utils/formatter.d.ts +13 -10
  115. package/lib/number-input/utils/formatter.js +52 -49
  116. package/lib/number-input/utils/validation.d.ts +7 -2
  117. package/lib/number-input/utils/validation.js +50 -52
  118. package/lib/otherUtils.d.ts +12 -9
  119. package/lib/otherUtils.js +86 -98
  120. package/lib/platform.d.ts +17 -9
  121. package/lib/platform.js +85 -122
  122. package/lib/select/hooks/useDebouncedSearch.d.ts +4 -1
  123. package/lib/select/hooks/useDebouncedSearch.js +40 -41
  124. package/lib/select/hooks/useSelectState.d.ts +7 -7
  125. package/lib/select/hooks/useSelectState.js +58 -93
  126. package/lib/select/index.d.ts +7 -8
  127. package/lib/select/types.d.ts +211 -211
  128. package/lib/select/utils/filterOptions.d.ts +7 -6
  129. package/lib/select/utils/filterOptions.js +26 -37
  130. package/lib/select/utils/helpers.d.ts +10 -9
  131. package/lib/select/utils/helpers.js +45 -41
  132. package/lib/select/utils/index.d.ts +4 -7
  133. package/lib/select/utils/sortOptions.d.ts +6 -5
  134. package/lib/select/utils/sortOptions.js +18 -39
  135. package/lib/select/utils/tagAggregation.d.ts +6 -6
  136. package/lib/select/utils/tagAggregation.js +33 -41
  137. package/lib/text-input/hooks/useTextInputState.d.ts +6 -2
  138. package/lib/text-input/hooks/useTextInputState.js +69 -79
  139. package/lib/text-input/types.d.ts +48 -48
  140. package/lib/text-input/utils/validation.d.ts +7 -2
  141. package/lib/text-input/utils/validation.js +49 -58
  142. package/lib/typeUtils.d.ts +11 -8
  143. package/lib/typeUtils.js +68 -73
  144. package/lib/walletValidity.d.ts +36 -34
  145. package/lib/walletValidity.js +345 -317
  146. package/package.json +1 -2
  147. package/es/common/index.d.ts +0 -5
  148. package/es/common/index.js +0 -5
  149. package/es/common/types.js +0 -1
  150. package/es/constants/index.d.ts +0 -7
  151. package/es/firebase/config/index.d.ts +0 -13
  152. package/es/firebase/config/index.js +0 -54
  153. package/es/firebase/index.d.ts +0 -28
  154. package/es/firebase/index.js +0 -232
  155. package/es/jsBridge/types.js +0 -1
  156. package/es/number-input/hooks/index.d.ts +0 -4
  157. package/es/number-input/hooks/index.js +0 -5
  158. package/es/number-input/index.d.ts +0 -14
  159. package/es/number-input/index.js +0 -21
  160. package/es/number-input/types.js +0 -1
  161. package/es/number-input/utils/index.d.ts +0 -7
  162. package/es/number-input/utils/index.js +0 -8
  163. package/es/select/hooks/index.d.ts +0 -5
  164. package/es/select/hooks/index.js +0 -6
  165. package/es/select/index.js +0 -13
  166. package/es/select/types.js +0 -1
  167. package/es/select/utils/index.js +0 -8
  168. package/es/text-input/hooks/index.d.ts +0 -4
  169. package/es/text-input/hooks/index.js +0 -5
  170. package/es/text-input/index.d.ts +0 -14
  171. package/es/text-input/index.js +0 -20
  172. package/es/text-input/types.js +0 -1
  173. package/es/text-input/utils/index.d.ts +0 -5
  174. package/es/text-input/utils/index.js +0 -7
  175. package/lib/common/index.d.ts +0 -5
  176. package/lib/common/index.js +0 -29
  177. package/lib/common/types.js +0 -17
  178. package/lib/constants/index.d.ts +0 -7
  179. package/lib/firebase/config/index.d.ts +0 -13
  180. package/lib/firebase/config/index.js +0 -79
  181. package/lib/firebase/index.d.ts +0 -28
  182. package/lib/firebase/index.js +0 -180
  183. package/lib/jsBridge/types.js +0 -17
  184. package/lib/number-input/hooks/index.d.ts +0 -4
  185. package/lib/number-input/hooks/index.js +0 -29
  186. package/lib/number-input/index.d.ts +0 -14
  187. package/lib/number-input/index.js +0 -41
  188. package/lib/number-input/types.js +0 -17
  189. package/lib/number-input/utils/index.d.ts +0 -7
  190. package/lib/number-input/utils/index.js +0 -39
  191. package/lib/select/hooks/index.d.ts +0 -5
  192. package/lib/select/hooks/index.js +0 -34
  193. package/lib/select/index.js +0 -53
  194. package/lib/select/types.js +0 -17
  195. package/lib/select/utils/index.js +0 -48
  196. package/lib/text-input/hooks/index.d.ts +0 -4
  197. package/lib/text-input/hooks/index.js +0 -29
  198. package/lib/text-input/index.d.ts +0 -14
  199. package/lib/text-input/index.js +0 -35
  200. package/lib/text-input/types.js +0 -17
  201. package/lib/text-input/utils/index.d.ts +0 -5
  202. package/lib/text-input/utils/index.js +0 -32
package/es/index.js CHANGED
@@ -1,35 +1,40 @@
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
- export * from "./otherUtils";
8
- export * from "./typeUtils";
9
- export * from "./componentStorage";
10
- export * from "./document";
11
- export * from "./date";
12
- export * from "./platform";
13
- export * from "./log";
14
- export * from "./format";
15
- export * from "./escPosPrinter";
16
- export * from "./miniRedux";
17
- export * from "./jsBridge";
18
- export * from "./image";
19
- export * from "./locales";
20
- export * from "./arrayUtils";
21
- export * from "./walletValidity";
22
- export * from "./common";
23
- export * from "./text-input";
24
- export * from "./number-input";
25
- export * from "./select";
26
- // export { default as firebase } from './firebase';
27
-
28
- export var setPisellUtilsConfig = function setPisellUtilsConfig(config) {
29
- globalThis.pisellUtilsConfig = _objectSpread(_objectSpread({}, globalThis.pisellUtilsConfig || {}), config || {});
30
- console.log('PisellUtilsConfig_set>>>>', config, globalThis);
1
+ import { _objectSpread2 } from "./_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
2
+ import { changeArray, createArray, detectIncognito, generateUniqueIdByObj, getItemByArray, getUniqueId } from "./otherUtils.js";
3
+ import { isArr, isBoolean, isFunction, isJson, isNumber, isPlainObject, isString, isUndefined } from "./typeUtils.js";
4
+ import { clearColumnSettingFromLocal, clearColumnVisibilityFromLocal, getColumnSettingFromLocal, getColumnVisibilityFromLocal, getComponentStorageKey, getRecordBoardColumnSettingFromLocal, getStorageKeySuffix, saveColumnSettingToLocal, saveColumnVisibilityToLocal } from "./componentStorage.js";
5
+ import { copyToClipboard, setTheme } from "./document.js";
6
+ import { excelDateToJSDate, formatDate, jsDateToExcelDate } from "./date.js";
7
+ import { checkEnv, isAndroid, isIOS, isIos, isIpad, isMobile, isSafari, isWebposOsServerEnv, isWx, isWxApp } from "./platform.js";
8
+ import { sendWarningLog } from "./log.js";
9
+ import { formatAmount, formatAmountWithOptions } from "./format.js";
10
+ import EscPosPrinter, { ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, columnWidthWithAlignment } from "./escPosPrinter/EscPosPrinter.js";
11
+ import { preparing } from "./escPosPrinter/index.js";
12
+ import { miniRedux } from "./miniRedux.js";
13
+ import { dataManager, webPayment, webPrint } from "./jsBridge/index.js";
14
+ import { image } from "./image.js";
15
+ import { locales } from "./locales.js";
16
+ import { uniqueByKey } from "./arrayUtils.js";
17
+ import { getScheduleSummary } from "./walletValidity.js";
18
+ import { getDisplayState } from "./common/stateHelper.js";
19
+ import { validateValue as validateValue$1 } from "./text-input/utils/validation.js";
20
+ import { useTextInputState } from "./text-input/hooks/useTextInputState.js";
21
+ import { validateValue } from "./number-input/utils/validation.js";
22
+ import { useNumberInputState } from "./number-input/hooks/useNumberInputState.js";
23
+ import { addThousandsSeparator, formatNumber, formatPrecision } from "./number-input/utils/formatter.js";
24
+ import { useMultipleSelectState, useSelectState } from "./select/hooks/useSelectState.js";
25
+ import { useDebouncedSearch } from "./select/hooks/useDebouncedSearch.js";
26
+ import { calculateTagDisplay } from "./select/utils/tagAggregation.js";
27
+ import { defaultFilterOption, filterOptions } from "./select/utils/filterOptions.js";
28
+ import { sortOptions } from "./select/utils/sortOptions.js";
29
+ import { findOptionByValue, findOptionsByValues, generateId, isOptionSelected, isOptionSelectedInMultiple } from "./select/utils/helpers.js";
30
+ //#region src/index.ts
31
+ const setPisellUtilsConfig = (config) => {
32
+ globalThis.pisellUtilsConfig = _objectSpread2(_objectSpread2({}, globalThis.pisellUtilsConfig || {}), config || {});
33
+ console.log("PisellUtilsConfig_set>>>>", config, globalThis);
31
34
  };
32
- export var getPisellUtilsConfig = function getPisellUtilsConfig() {
33
- console.log('PisellUtilsConfig_get>>>>', globalThis);
34
- return globalThis.pisellUtilsConfig || {};
35
- };
35
+ const getPisellUtilsConfig = () => {
36
+ console.log("PisellUtilsConfig_get>>>>", globalThis);
37
+ return globalThis.pisellUtilsConfig || {};
38
+ };
39
+ //#endregion
40
+ export { ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, EscPosPrinter, addThousandsSeparator, calculateTagDisplay, changeArray, checkEnv, clearColumnSettingFromLocal, clearColumnVisibilityFromLocal, columnWidthWithAlignment, copyToClipboard, createArray, dataManager, defaultFilterOption, detectIncognito, excelDateToJSDate, filterOptions, findOptionByValue, findOptionsByValues, formatAmount, formatAmountWithOptions, formatDate, formatNumber, formatPrecision, generateId, generateUniqueIdByObj, getColumnSettingFromLocal, getColumnVisibilityFromLocal, getComponentStorageKey, getDisplayState, getItemByArray, getPisellUtilsConfig, getRecordBoardColumnSettingFromLocal, getScheduleSummary, getStorageKeySuffix, getUniqueId, image, isAndroid, isArr, isBoolean, isFunction, isIOS, isIos, isIpad, isJson, isMobile, isNumber, isOptionSelected, isOptionSelectedInMultiple, isPlainObject, isSafari, isString, isUndefined, isWebposOsServerEnv, isWx, isWxApp, jsDateToExcelDate, locales, miniRedux, preparing, saveColumnSettingToLocal, saveColumnVisibilityToLocal, sendWarningLog, setPisellUtilsConfig, setTheme, sortOptions, uniqueByKey, useDebouncedSearch, useMultipleSelectState, useNumberInputState, useSelectState, useTextInputState, validateValue as validateNumberValue, validateValue$1 as validateTextValue, webPayment, webPrint };
@@ -0,0 +1,26 @@
1
+ import { DataManagerParams, WebPaymentParams, WebPrintParams } from "./types.js";
2
+
3
+ //#region src/jsBridge/index.d.ts
4
+ /**
5
+ * webView页面中调用打印机打印
6
+ * 此api暂时只支持native app平台下ios手机
7
+ * @param params
8
+ * @param callback
9
+ */
10
+ declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
11
+ /**
12
+ * webView页面中调用APP内的数据
13
+ * 此api暂时只支持native app平台下ios手机
14
+ * @param params
15
+ * @param callback
16
+ */
17
+ declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void, onError: () => void): void;
18
+ /**
19
+ * webView页面中调用APP内的支付
20
+ * 此api暂时只支持native app平台下ios
21
+ * @param params
22
+ * @param callback
23
+ */
24
+ declare function webPayment(params: WebPaymentParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
25
+ //#endregion
26
+ export { dataManager, webPayment, webPrint };
@@ -1,61 +1,62 @@
1
- import regDeviceApi from "./regDeviceApi";
1
+ import regDeviceApi from "./regDeviceApi.js";
2
+ //#region src/jsBridge/index.ts
2
3
  /**
3
- * webView页面中调用打印机打印
4
- * 此api暂时只支持native app平台下ios手机
5
- * @param params
6
- * @param callback
7
- */
8
- export function webPrint(params, _callback, onError) {
9
- regDeviceApi().then(function (jsBridge) {
10
- jsBridge.callDeviceApi({
11
- apiName: 'webPrint',
12
- params: params,
13
- callback: function callback() {
14
- _callback && _callback.apply(void 0, arguments);
15
- }
16
- });
17
- }).catch(function (err) {
18
- onError === null || onError === void 0 || onError(err);
19
- console.error('webPrint', err);
20
- });
4
+ * webView页面中调用打印机打印
5
+ * 此api暂时只支持native app平台下ios手机
6
+ * @param params
7
+ * @param callback
8
+ */
9
+ function webPrint(params, callback, onError) {
10
+ regDeviceApi().then((jsBridge) => {
11
+ jsBridge.callDeviceApi({
12
+ apiName: "webPrint",
13
+ params,
14
+ callback: (...arg) => {
15
+ callback && callback(...arg);
16
+ }
17
+ });
18
+ }).catch((err) => {
19
+ onError === null || onError === void 0 || onError(err);
20
+ console.error("webPrint", err);
21
+ });
21
22
  }
22
-
23
23
  /**
24
- * webView页面中调用APP内的数据
25
- * 此api暂时只支持native app平台下ios手机
26
- * @param params
27
- * @param callback
28
- */
29
- export function dataManager(params, _callback2, onError) {
30
- regDeviceApi().then(function (jsBridge) {
31
- jsBridge.callDeviceApi({
32
- apiName: 'dataManager',
33
- params: params,
34
- callback: function callback() {
35
- _callback2 && _callback2.apply(void 0, arguments);
36
- },
37
- onError: onError
38
- });
39
- }).catch(onError);
24
+ * webView页面中调用APP内的数据
25
+ * 此api暂时只支持native app平台下ios手机
26
+ * @param params
27
+ * @param callback
28
+ */
29
+ function dataManager(params, callback, onError) {
30
+ regDeviceApi().then((jsBridge) => {
31
+ jsBridge.callDeviceApi({
32
+ apiName: "dataManager",
33
+ params,
34
+ callback: (...arg) => {
35
+ callback && callback(...arg);
36
+ },
37
+ onError
38
+ });
39
+ }).catch(onError);
40
40
  }
41
-
42
41
  /**
43
- * webView页面中调用APP内的支付
44
- * 此api暂时只支持native app平台下ios
45
- * @param params
46
- * @param callback
47
- */
48
- export function webPayment(params, _callback3, onError) {
49
- regDeviceApi().then(function (jsBridge) {
50
- jsBridge.callDeviceApi({
51
- apiName: 'webPayment',
52
- params: params,
53
- callback: function callback() {
54
- _callback3 && _callback3.apply(void 0, arguments);
55
- }
56
- });
57
- }).catch(function (err) {
58
- onError === null || onError === void 0 || onError(err);
59
- console.error('webPayment', err);
60
- });
61
- }
42
+ * webView页面中调用APP内的支付
43
+ * 此api暂时只支持native app平台下ios
44
+ * @param params
45
+ * @param callback
46
+ */
47
+ function webPayment(params, callback, onError) {
48
+ regDeviceApi().then((jsBridge) => {
49
+ jsBridge.callDeviceApi({
50
+ apiName: "webPayment",
51
+ params,
52
+ callback: (...arg) => {
53
+ callback && callback(...arg);
54
+ }
55
+ });
56
+ }).catch((err) => {
57
+ onError === null || onError === void 0 || onError(err);
58
+ console.error("webPayment", err);
59
+ });
60
+ }
61
+ //#endregion
62
+ export { dataManager, webPayment, webPrint };
@@ -1,158 +1,116 @@
1
- import { isAndroid, isIos } from "../platform";
2
- var androidRegStatus = false;
3
- var iosRegStatus = false;
4
- var androidBridge;
5
- var iosBridge;
6
- var composedBridge;
1
+ import { isAndroid, isIos } from "../platform.js";
2
+ //#region src/jsBridge/regDeviceApi.js
3
+ let androidRegStatus = false;
4
+ let iosRegStatus = false;
5
+ let androidBridge;
6
+ let iosBridge;
7
+ let composedBridge;
7
8
  function regIosJsBridge(callback, reject) {
8
- if (window.WebViewJavascriptBridge) {
9
- callback(window.WebViewJavascriptBridge);
10
- return;
11
- } else {
12
- reject();
13
- }
14
- if (window.WVJBCallbacks) {
15
- window.WVJBCallbacks.push(callback);
16
- return;
17
- }
18
- window.WVJBCallbacks = [callback];
19
- var WVJBIframe = document.createElement('iframe');
20
- WVJBIframe.style.display = 'none';
21
- WVJBIframe.src = 'https://__bridge_loaded__';
22
- document.documentElement && document.documentElement.appendChild(WVJBIframe);
23
- setTimeout(function () {
24
- try {
25
- document.documentElement && document.documentElement.removeChild(WVJBIframe);
26
- } catch (e) {
27
- console.log(e);
28
- }
29
- }, 0);
9
+ if (window.WebViewJavascriptBridge) {
10
+ callback(window.WebViewJavascriptBridge);
11
+ return;
12
+ } else reject();
13
+ if (window.WVJBCallbacks) {
14
+ window.WVJBCallbacks.push(callback);
15
+ return;
16
+ }
17
+ window.WVJBCallbacks = [callback];
18
+ const WVJBIframe = document.createElement("iframe");
19
+ WVJBIframe.style.display = "none";
20
+ WVJBIframe.src = "https://__bridge_loaded__";
21
+ document.documentElement && document.documentElement.appendChild(WVJBIframe);
22
+ setTimeout(() => {
23
+ try {
24
+ document.documentElement && document.documentElement.removeChild(WVJBIframe);
25
+ } catch (e) {
26
+ console.log(e);
27
+ }
28
+ }, 0);
30
29
  }
31
30
  function regAndroidJsBridge(extraInit) {
32
- if (window._jsBridge) {
33
- extraInit(window._jsBridge);
34
- return;
35
- }
36
- document.addEventListener('WebViewJavascriptBridgeReady', function (event) {
37
- var bridge = event.bridge;
38
- window._jsBridge = bridge;
39
- if (!bridge) return;
40
- // 这段代码不能删除
41
- bridge.init(function (message, responseCallback) {
42
- if (responseCallback) {
43
- responseCallback('init responseCallback');
44
- }
45
- });
46
- extraInit(bridge);
47
- }, false);
31
+ if (window._jsBridge) {
32
+ extraInit(window._jsBridge);
33
+ return;
34
+ }
35
+ document.addEventListener("WebViewJavascriptBridgeReady", (event) => {
36
+ const { bridge } = event;
37
+ window._jsBridge = bridge;
38
+ if (!bridge) return;
39
+ bridge.init((message, responseCallback) => {
40
+ if (responseCallback) responseCallback("init responseCallback");
41
+ });
42
+ extraInit(bridge);
43
+ }, false);
48
44
  }
49
45
  function checkApiName(apiNames, apiName) {
50
- var _apiNames = apiNames || ['webPrint'];
51
- return _apiNames.includes(apiName);
46
+ return (apiNames || ["webPrint"]).includes(apiName);
52
47
  }
53
-
54
48
  /**
55
- * 通用jsBridge
56
- * @param deviceType
57
- */
49
+ * 通用jsBridge
50
+ * @param deviceType
51
+ */
58
52
  function getComposedBridge(deviceType) {
59
- if (composedBridge) {
60
- return composedBridge;
61
- }
62
- composedBridge = {
63
- // 主动调用设备的方法
64
- callDeviceApi: function callDeviceApi(_ref) {
65
- var apiName = _ref.apiName,
66
- inCb = _ref.callback,
67
- _ref$params = _ref.params,
68
- params = _ref$params === void 0 ? {} : _ref$params,
69
- onError = _ref.onError;
70
- var callback = function callback(res) {
71
- var result = res;
72
- try {
73
- result = JSON.parse(res);
74
- } catch (error) {
75
- console.log("error ".concat(apiName), error);
76
- }
77
- // if (result.code || result.code === 0) {
78
- // // 强转字符串,兼容安卓的number
79
- // result.code = `${result.code}`;
80
- // }
81
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
82
- args[_key - 1] = arguments[_key];
83
- }
84
- inCb.apply(void 0, [result].concat(args));
85
- };
86
- if (deviceType === 'iphone') {
87
- var _iosBridge;
88
- if (!checkApiName((_iosBridge = iosBridge) === null || _iosBridge === void 0 ? void 0 : _iosBridge.apiNames, apiName)) {
89
- onError === null || onError === void 0 || onError();
90
- return;
91
- }
92
- iosBridge.callHandler(apiName, params, callback, function (e) {
93
- console.log(e, '--- 调用ios api报错:', apiName);
94
- if (onError) {
95
- onError === null || onError === void 0 || onError(e);
96
- }
97
- });
98
- } else if (deviceType === 'android') {
99
- var _androidBridge;
100
- if (!checkApiName((_androidBridge = androidBridge) === null || _androidBridge === void 0 ? void 0 : _androidBridge.apiNames, apiName)) {
101
- onError === null || onError === void 0 || onError();
102
- return;
103
- }
104
- var res = androidBridge.callHandler(apiName, JSON.stringify(params));
105
- callback(res);
106
- } else {
107
- onError === null || onError === void 0 || onError();
108
- console.log('--- 没获取到js bridge ---');
109
- }
110
- },
111
- // 被设备调用的方法
112
- calledByDevice: function calledByDevice(_ref2) {
113
- var apiName = _ref2.apiName,
114
- callback = _ref2.callback;
115
- if (deviceType === 'iphone') {
116
- iosBridge.registerHandler(apiName, callback);
117
- } else if (deviceType === 'android') {
118
- androidBridge.registerHandler(apiName, callback);
119
- }
120
- }
121
- };
122
- return composedBridge;
53
+ if (composedBridge) return composedBridge;
54
+ composedBridge = {
55
+ callDeviceApi: ({ apiName, callback: inCb, params = {}, onError }) => {
56
+ const callback = (res, ...args) => {
57
+ let result = res;
58
+ try {
59
+ result = JSON.parse(res);
60
+ } catch (error) {
61
+ console.log(`error ${apiName}`, error);
62
+ }
63
+ inCb(result, ...args);
64
+ };
65
+ if (deviceType === "iphone") {
66
+ if (!checkApiName(iosBridge === null || iosBridge === void 0 ? void 0 : iosBridge.apiNames, apiName)) {
67
+ onError === null || onError === void 0 || onError();
68
+ return;
69
+ }
70
+ iosBridge.callHandler(apiName, params, callback, (e) => {
71
+ console.log(e, "--- 调用ios api报错:", apiName);
72
+ if (onError) onError === null || onError === void 0 || onError(e);
73
+ });
74
+ } else if (deviceType === "android") {
75
+ if (!checkApiName(androidBridge === null || androidBridge === void 0 ? void 0 : androidBridge.apiNames, apiName)) {
76
+ onError === null || onError === void 0 || onError();
77
+ return;
78
+ }
79
+ callback(androidBridge.callHandler(apiName, JSON.stringify(params)));
80
+ } else {
81
+ onError === null || onError === void 0 || onError();
82
+ console.log("--- 没获取到js bridge ---");
83
+ }
84
+ },
85
+ calledByDevice: ({ apiName, callback }) => {
86
+ if (deviceType === "iphone") iosBridge.registerHandler(apiName, callback);
87
+ else if (deviceType === "android") androidBridge.registerHandler(apiName, callback);
88
+ }
89
+ };
90
+ return composedBridge;
123
91
  }
124
- export default function regDeviceApi(isWebPrint) {
125
- return new Promise(function (resolve, reject) {
126
- // 旧版本只能用WebPrint
127
- var isOld = !navigator.userAgent.includes('jsBridge');
128
- if (isOld) {
129
- if (!isWebPrint) {
130
- reject();
131
- return;
132
- }
133
- }
134
- if (isIos() && !iosRegStatus) {
135
- regIosJsBridge(function (bridge) {
136
- iosRegStatus = true;
137
- iosBridge = bridge;
138
- var realBridge = getComposedBridge('iphone');
139
- resolve(realBridge);
140
- }, reject);
141
- } else if (isIos() && iosRegStatus) {
142
- var realBridge = getComposedBridge('iphone');
143
- resolve(realBridge);
144
- } else if (isAndroid() && !androidRegStatus) {
145
- regAndroidJsBridge(function (bridge) {
146
- androidBridge = bridge;
147
- androidRegStatus = true;
148
- var realBridge = getComposedBridge('android');
149
- resolve(realBridge);
150
- });
151
- } else if (isAndroid() && androidRegStatus) {
152
- var _realBridge = getComposedBridge('android');
153
- resolve(_realBridge);
154
- } else {
155
- reject();
156
- }
157
- });
158
- }
92
+ function regDeviceApi(isWebPrint) {
93
+ return new Promise((resolve, reject) => {
94
+ if (!navigator.userAgent.includes("jsBridge")) {
95
+ if (!isWebPrint) {
96
+ reject();
97
+ return;
98
+ }
99
+ }
100
+ if (isIos() && !iosRegStatus) regIosJsBridge((bridge) => {
101
+ iosRegStatus = true;
102
+ iosBridge = bridge;
103
+ resolve(getComposedBridge("iphone"));
104
+ }, reject);
105
+ else if (isIos() && iosRegStatus) resolve(getComposedBridge("iphone"));
106
+ else if (isAndroid() && !androidRegStatus) regAndroidJsBridge((bridge) => {
107
+ androidBridge = bridge;
108
+ androidRegStatus = true;
109
+ resolve(getComposedBridge("android"));
110
+ });
111
+ else if (isAndroid() && androidRegStatus) resolve(getComposedBridge("android"));
112
+ else reject();
113
+ });
114
+ }
115
+ //#endregion
116
+ export { regDeviceApi as default };
@@ -0,0 +1,129 @@
1
+ //#region src/jsBridge/types.d.ts
2
+ type LanguageNumber = {
3
+ en: number;
4
+ zh_CN: number;
5
+ zh_HK: number;
6
+ };
7
+ type LanguageString = {
8
+ en: string;
9
+ zh_CN: string;
10
+ zh_HK: string;
11
+ } | string;
12
+ /**
13
+ * 打印小票
14
+ */
15
+ type WebPrint0 = {
16
+ /**
17
+ * 打印类型
18
+ * 0: 小票
19
+ * 1:ITS备货单/划菜单
20
+ * 2:手环
21
+ */
22
+ type: '0';
23
+ data: {
24
+ /** 订单ID */order_id: string;
25
+ }; /** 打印语言对应的数量 */
26
+ language: LanguageNumber;
27
+ };
28
+ /**
29
+ * 打印ITS备货单/划菜单
30
+ */
31
+ type WebPrint1 = {
32
+ /**
33
+ * 打印类型
34
+ * 0: 小票
35
+ * 1:ITS备货单/划菜单
36
+ * 2:手环
37
+ */
38
+ type: '1';
39
+ data: {
40
+ /** 0:备货 1:划单 */mode: '0' | '1';
41
+ resource: LanguageString; /** 订单备注 */
42
+ order_note: string; /** 订单时间或商品下单时间 */
43
+ time: string; /** 订单编号 */
44
+ order_number?: string; /** 商品 */
45
+ products: {
46
+ /** 商品名称 */product_title: LanguageString; /** 商品规格 */
47
+ product_option_string: LanguageString; /** 商品备注 */
48
+ product_note: string; /** 商品数量 */
49
+ product_quantity: number; /** 加菜标识 待定 */
50
+ is_append?: boolean; /** 退菜标识 待定 */
51
+ is_removed?: boolean;
52
+ }[];
53
+ }; /** 打印语言对应的数量 */
54
+ language: LanguageNumber;
55
+ };
56
+ /**
57
+ * 打印手环
58
+ */
59
+ type WebPrint2 = {
60
+ /**
61
+ * 打印类型
62
+ * 0: 小票
63
+ * 1:ITS备货单/划菜单
64
+ * 2:手环
65
+ */
66
+ type: '2';
67
+ data: {
68
+ /** 0: 普通票 1:成人票 2:免费成人票 */type: '0' | '1' | '2'; /** 发行编码 */
69
+ encoded: string; /** 编码 */
70
+ code: string; /** 到期时间 */
71
+ expire_date: string;
72
+ areas: {
73
+ /** 区域名字 */area_name: string; /** 区域代码 */
74
+ area_code: string; /** 可用次数 */
75
+ limit_num: number; /** 已用次数 */
76
+ used_num: number;
77
+ }[];
78
+ };
79
+ };
80
+ /**
81
+ * 打印充值卡
82
+ */
83
+ type WebPrint4 = {
84
+ type: '4';
85
+ data: {
86
+ order_id: string;
87
+ };
88
+ };
89
+ /**
90
+ * 打印订单中所有
91
+ */
92
+ type WebPrint99 = {
93
+ type: '99';
94
+ data: {
95
+ order_id: string;
96
+ machine_code_print_info: {
97
+ [key: string]: any;
98
+ }[];
99
+ small_ticket_data: {
100
+ [key: string]: any;
101
+ };
102
+ };
103
+ };
104
+ /**
105
+ * 打印
106
+ */
107
+ type WebPrintParams = WebPrint0 | WebPrint1 | WebPrint2 | WebPrint4 | WebPrint99;
108
+ /**
109
+ * 数据管理
110
+ */
111
+ type DataManagerParams = {
112
+ module: 'set' | 'get';
113
+ key: string;
114
+ data?: any;
115
+ };
116
+ /**
117
+ * 支付
118
+ */
119
+ type WebPaymentParams = {
120
+ module: 'payment' | 'refund' | string;
121
+ key: 'mx51' | string;
122
+ data?: {
123
+ order_id: string | number;
124
+ amount: string | number;
125
+ surcharge?: string | number;
126
+ };
127
+ };
128
+ //#endregion
129
+ export { DataManagerParams, WebPaymentParams, WebPrintParams };
@@ -0,0 +1,12 @@
1
+ //#region src/locales.d.ts
2
+ declare const locales: {
3
+ init: (_localeMaps: any, _locale: string) => void;
4
+ getText: (id: string) => any;
5
+ getLocale: () => string;
6
+ locale: string;
7
+ localeMap: any;
8
+ localeMaps: any;
9
+ formatLocale: (_locale: string) => string;
10
+ };
11
+ //#endregion
12
+ export { locales };