iglooform 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,7 +30,7 @@ export default function DumiContextWrapper() {
30
30
 
31
31
  return (
32
32
  <SiteContext.Provider value={{
33
- pkg: {"name":"iglooform","version":"3.0.0-alpha.9","license":"MIT"},
33
+ pkg: {"name":"iglooform","version":"3.0.1","license":"MIT"},
34
34
  historyType: "browser",
35
35
  entryExports,
36
36
  demos,
@@ -231,6 +231,7 @@ var Element = function Element(_ref) {
231
231
  },
232
232
  ref: ref,
233
233
  children: /*#__PURE__*/_jsx(Component, _objectSpread(_objectSpread({}, otherElementProps), {}, {
234
+ label: formItemProps.label,
234
235
  disabled: elementProps.disabled || disabled,
235
236
  containerRef: ref,
236
237
  setFieldError: setFieldError,
@@ -1,6 +1,10 @@
1
1
  import * as BlinkIDSDK from '@microblink/blinkid-in-browser-sdk';
2
2
  declare const useMicroBlink: () => (licenseKey: string) => {
3
- recognize: (file: File) => Promise<BlinkIDSDK.BlinkIdSingleSideRecognizerResult | null>;
3
+ initResult: {
4
+ error: undefined;
5
+ failed: boolean;
6
+ };
7
+ recognize: ((file: File) => Promise<BlinkIDSDK.BlinkIdSingleSideRecognizerResult | null>) | null;
4
8
  loading: boolean;
5
9
  };
6
10
  export default useMicroBlink;
@@ -17,11 +17,11 @@ function getWorkerLocation(_x) {
17
17
  return _getWorkerLocation.apply(this, arguments);
18
18
  }
19
19
  function _getWorkerLocation() {
20
- _getWorkerLocation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(path) {
21
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
22
- while (1) switch (_context5.prev = _context5.next) {
20
+ _getWorkerLocation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(path) {
21
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
22
+ while (1) switch (_context4.prev = _context4.next) {
23
23
  case 0:
24
- return _context5.abrupt("return", new Promise(function (resolve) {
24
+ return _context4.abrupt("return", new Promise(function (resolve) {
25
25
  window.fetch(path).then(function (response) {
26
26
  return response.text();
27
27
  }).then(function (data) {
@@ -34,31 +34,36 @@ function _getWorkerLocation() {
34
34
  }));
35
35
  case 1:
36
36
  case "end":
37
- return _context5.stop();
37
+ return _context4.stop();
38
38
  }
39
- }, _callee5);
39
+ }, _callee4);
40
40
  }));
41
41
  return _getWorkerLocation.apply(this, arguments);
42
42
  }
43
43
  var useMicroBlink = function useMicroBlink() {
44
44
  var _useContext = useContext(LocaleContext),
45
45
  formatMessage = _useContext.formatMessage;
46
- var _useState = useState(false),
46
+ // 对于init的错误不直接展示message.error,等用户实际使用的时候才提示
47
+ var _useState = useState(undefined),
47
48
  _useState2 = _slicedToArray(_useState, 2),
48
- initLoading = _useState2[0],
49
- setInitLoading = _useState2[1];
50
- var _useState3 = useState(''),
49
+ initError = _useState2[0],
50
+ setInitError = _useState2[1];
51
+ var _useState3 = useState(false),
51
52
  _useState4 = _slicedToArray(_useState3, 2),
52
- currentKey = _useState4[0],
53
- setCurrentKey = _useState4[1];
54
- var _useState5 = useState(null),
53
+ initLoading = _useState4[0],
54
+ setInitLoading = _useState4[1];
55
+ var _useState5 = useState(''),
55
56
  _useState6 = _slicedToArray(_useState5, 2),
56
- recognizer = _useState6[0],
57
- setRecognizer = _useState6[1];
57
+ currentKey = _useState6[0],
58
+ setCurrentKey = _useState6[1];
58
59
  var _useState7 = useState(null),
59
60
  _useState8 = _slicedToArray(_useState7, 2),
60
- recognizerRunner = _useState8[0],
61
- setRecognizerRunner = _useState8[1];
61
+ recognizer = _useState8[0],
62
+ setRecognizer = _useState8[1];
63
+ var _useState9 = useState(null),
64
+ _useState10 = _slicedToArray(_useState9, 2),
65
+ recognizerRunner = _useState10[0],
66
+ setRecognizerRunner = _useState10[1];
62
67
  var initSdk = /*#__PURE__*/function () {
63
68
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(licenseKey) {
64
69
  var loadSettings;
@@ -104,12 +109,7 @@ var useMicroBlink = function useMicroBlink() {
104
109
  };
105
110
  }(), function (error) {
106
111
  setInitLoading(false);
107
- message.error(formatMessage({
108
- id: 'Error during the initialization of the SDK! {error}',
109
- values: {
110
- error: error.message || error
111
- }
112
- }));
112
+ setInitError(error.message || error);
113
113
  });
114
114
  _context2.next = 11;
115
115
  break;
@@ -155,11 +155,8 @@ var useMicroBlink = function useMicroBlink() {
155
155
  recognitionResult = _context3.sent;
156
156
  return _context3.abrupt("return", recognitionResult);
157
157
  case 15:
158
- message.error(formatMessage({
159
- id: 'Recognition was not successful!'
160
- }));
161
158
  return _context3.abrupt("return", null);
162
- case 17:
159
+ case 16:
163
160
  case "end":
164
161
  return _context3.stop();
165
162
  }
@@ -170,22 +167,7 @@ var useMicroBlink = function useMicroBlink() {
170
167
  };
171
168
  }();
172
169
  } else {
173
- return /*#__PURE__*/function () {
174
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(file) {
175
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
176
- while (1) switch (_context4.prev = _context4.next) {
177
- case 0:
178
- return _context4.abrupt("return", null);
179
- case 1:
180
- case "end":
181
- return _context4.stop();
182
- }
183
- }, _callee4);
184
- }));
185
- return function (_x5) {
186
- return _ref4.apply(this, arguments);
187
- };
188
- }();
170
+ return null;
189
171
  }
190
172
  }, [recognizer, recognizerRunner]);
191
173
  var dealRepeatSendRequest = function dealRepeatSendRequest(licenseKey) {
@@ -199,6 +181,10 @@ var useMicroBlink = function useMicroBlink() {
199
181
  return function (licenseKey) {
200
182
  dealRepeatSendRequest(licenseKey);
201
183
  return {
184
+ initResult: {
185
+ error: initError,
186
+ failed: !!initError
187
+ },
202
188
  recognize: recognize(),
203
189
  loading: initLoading
204
190
  };
@@ -44,6 +44,7 @@ var PhoneNumber = function PhoneNumber(_ref) {
44
44
  number = _useState4[0],
45
45
  setNumber = _useState4[1];
46
46
  useEffect(function () {
47
+ if (!value) return;
47
48
  if ((value === null || value === void 0 ? void 0 : value.areaCode) === selectedCode && (value === null || value === void 0 ? void 0 : value.phoneNumber) === number) {
48
49
  return;
49
50
  }
@@ -54,10 +55,12 @@ var PhoneNumber = function PhoneNumber(_ref) {
54
55
  disabled: disabled,
55
56
  onChange: function onChange(e) {
56
57
  changeCode(e);
57
- formChangeProps(number && e ? {
58
- areaCode: e,
59
- phoneNumber: number
60
- } : undefined);
58
+ if (number) {
59
+ formChangeProps({
60
+ areaCode: e,
61
+ phoneNumber: number
62
+ });
63
+ }
61
64
  },
62
65
  className: classnames('igloo-phone-number-select'),
63
66
  defaultValue: selectedCode,
@@ -6,9 +6,9 @@ import { useContext } from 'react';
6
6
  import { UploadOutlined } from 'iglooicon';
7
7
  import { colors } from 'iglootheme';
8
8
  import { Upload, Spin } from 'antd';
9
- import invariant from 'invariant';
10
9
  import * as lodash from 'lodash';
11
10
  import moment from 'moment';
11
+ import invariant from 'invariant';
12
12
  import fromContext from "../../form-context";
13
13
  import Typography from "../../typography";
14
14
  import { LocaleContext } from "../../locale";
@@ -29,7 +29,8 @@ function getOcrDate(result, format) {
29
29
  }
30
30
  var MicroBlink = function MicroBlink(props) {
31
31
  var outputMap = props.outputMap,
32
- disabled = props.disabled;
32
+ disabled = props.disabled,
33
+ label = props.label;
33
34
  var Dragger = Upload.Dragger;
34
35
  var _useContext = useContext(fromContext),
35
36
  ocrHooks = _useContext.ocrHooks,
@@ -40,8 +41,9 @@ var MicroBlink = function MicroBlink(props) {
40
41
  microBlink = _ref.microBlink;
41
42
  var _ref2 = microBlink || {},
42
43
  recognize = _ref2.recognize,
43
- loading = _ref2.loading;
44
- invariant(Boolean(microBlink) && Boolean(recognize), 'Must Config Micro Blink licenseKey');
44
+ loading = _ref2.loading,
45
+ initResult = _ref2.initResult;
46
+ invariant(microBlink, 'Form Must Has MicroBlink Config');
45
47
  var onUpload = /*#__PURE__*/function () {
46
48
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file) {
47
49
  var microBlinkResult, state, formSet;
@@ -57,23 +59,24 @@ var MicroBlink = function MicroBlink(props) {
57
59
  case 3:
58
60
  microBlinkResult = _context.sent;
59
61
  if (microBlinkResult) {
60
- _context.next = 6;
62
+ _context.next = 7;
61
63
  break;
62
64
  }
65
+ message.error(formatMessage({
66
+ id: 'Recognition was not successful!'
67
+ }));
63
68
  return _context.abrupt("return");
64
- case 6:
69
+ case 7:
65
70
  state = microBlinkResult.state;
66
- _context.t0 = state;
67
- _context.next = _context.t0 === 0 ? 10 : 12;
68
- break;
69
- case 10:
71
+ if (!(state === 0)) {
72
+ _context.next = 11;
73
+ break;
74
+ }
70
75
  message.error(formatMessage({
71
76
  id: 'Nothing has been recognized.'
72
77
  }));
73
78
  return _context.abrupt("return");
74
- case 12:
75
- return _context.abrupt("break", 13);
76
- case 13:
79
+ case 11:
77
80
  formSet = (outputMap || []).reduce(function (pre, cur) {
78
81
  var field = cur.field,
79
82
  source = cur.source,
@@ -90,7 +93,7 @@ var MicroBlink = function MicroBlink(props) {
90
93
  default:
91
94
  pre.push({
92
95
  name: field,
93
- value: lodash.get(microBlinkResult || {}, source),
96
+ value: lodash.get(microBlinkResult, source),
94
97
  errors: []
95
98
  });
96
99
  break;
@@ -98,7 +101,11 @@ var MicroBlink = function MicroBlink(props) {
98
101
  return pre;
99
102
  }, []);
100
103
  form === null || form === void 0 ? void 0 : form.setFields(formSet);
104
+ _context.next = 16;
105
+ break;
101
106
  case 15:
107
+ message.error(initResult === null || initResult === void 0 ? void 0 : initResult.error);
108
+ case 16:
102
109
  case "end":
103
110
  return _context.stop();
104
111
  }
@@ -108,9 +115,14 @@ var MicroBlink = function MicroBlink(props) {
108
115
  return _ref3.apply(this, arguments);
109
116
  };
110
117
  }();
111
- return /*#__PURE__*/_jsx(Spin, {
118
+ return /*#__PURE__*/_jsxs(Spin, {
112
119
  spinning: loading,
113
- children: /*#__PURE__*/_jsx("div", {
120
+ children: [label && /*#__PURE__*/_jsx("div", {
121
+ style: {
122
+ marginBottom: 8
123
+ },
124
+ children: label
125
+ }), /*#__PURE__*/_jsx("div", {
114
126
  className: 'igloo-micro-blink',
115
127
  children: /*#__PURE__*/_jsx(Dragger, {
116
128
  action: function action(file) {
@@ -122,7 +134,7 @@ var MicroBlink = function MicroBlink(props) {
122
134
  customRequest: function customRequest() {}
123
135
  // @ts-ignore
124
136
  ,
125
- disabled: disabled,
137
+ disabled: disabled || (initResult === null || initResult === void 0 ? void 0 : initResult.failed),
126
138
  multiple: true,
127
139
  children: /*#__PURE__*/_jsxs("div", {
128
140
  className: "igloo-upload-box-center",
@@ -160,7 +172,7 @@ var MicroBlink = function MicroBlink(props) {
160
172
  })]
161
173
  })
162
174
  })
163
- })
175
+ })]
164
176
  });
165
177
  };
166
178
  export default MicroBlink;
package/es/types.d.ts CHANGED
@@ -8,6 +8,10 @@ import { BlinkIdSingleSideRecognizerResult } from '@microblink/blinkid-in-browse
8
8
  export { Rule } from 'rc-field-form/lib/interface';
9
9
  export interface OCRHooks {
10
10
  microBlink?: {
11
+ initResult: {
12
+ error?: string;
13
+ failed: boolean;
14
+ };
11
15
  recognize: ((file: File) => Promise<BlinkIdSingleSideRecognizerResult | null>) | null;
12
16
  loading?: boolean;
13
17
  };
@@ -237,6 +237,7 @@ var Element = function Element(_ref) {
237
237
  },
238
238
  ref: ref,
239
239
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, _objectSpread(_objectSpread({}, otherElementProps), {}, {
240
+ label: formItemProps.label,
240
241
  disabled: elementProps.disabled || disabled,
241
242
  containerRef: ref,
242
243
  setFieldError: setFieldError,
@@ -1,6 +1,10 @@
1
1
  import * as BlinkIDSDK from '@microblink/blinkid-in-browser-sdk';
2
2
  declare const useMicroBlink: () => (licenseKey: string) => {
3
- recognize: (file: File) => Promise<BlinkIDSDK.BlinkIdSingleSideRecognizerResult | null>;
3
+ initResult: {
4
+ error: undefined;
5
+ failed: boolean;
6
+ };
7
+ recognize: ((file: File) => Promise<BlinkIDSDK.BlinkIdSingleSideRecognizerResult | null>) | null;
4
8
  loading: boolean;
5
9
  };
6
10
  export default useMicroBlink;
@@ -26,11 +26,11 @@ function getWorkerLocation(_x) {
26
26
  return _getWorkerLocation.apply(this, arguments);
27
27
  }
28
28
  function _getWorkerLocation() {
29
- _getWorkerLocation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(path) {
30
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
31
- while (1) switch (_context5.prev = _context5.next) {
29
+ _getWorkerLocation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(path) {
30
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
31
+ while (1) switch (_context4.prev = _context4.next) {
32
32
  case 0:
33
- return _context5.abrupt("return", new Promise(function (resolve) {
33
+ return _context4.abrupt("return", new Promise(function (resolve) {
34
34
  window.fetch(path).then(function (response) {
35
35
  return response.text();
36
36
  }).then(function (data) {
@@ -43,31 +43,36 @@ function _getWorkerLocation() {
43
43
  }));
44
44
  case 1:
45
45
  case "end":
46
- return _context5.stop();
46
+ return _context4.stop();
47
47
  }
48
- }, _callee5);
48
+ }, _callee4);
49
49
  }));
50
50
  return _getWorkerLocation.apply(this, arguments);
51
51
  }
52
52
  var useMicroBlink = function useMicroBlink() {
53
53
  var _useContext = (0, _react.useContext)(_locale.LocaleContext),
54
54
  formatMessage = _useContext.formatMessage;
55
- var _useState = (0, _react.useState)(false),
55
+ // 对于init的错误不直接展示message.error,等用户实际使用的时候才提示
56
+ var _useState = (0, _react.useState)(undefined),
56
57
  _useState2 = _slicedToArray(_useState, 2),
57
- initLoading = _useState2[0],
58
- setInitLoading = _useState2[1];
59
- var _useState3 = (0, _react.useState)(''),
58
+ initError = _useState2[0],
59
+ setInitError = _useState2[1];
60
+ var _useState3 = (0, _react.useState)(false),
60
61
  _useState4 = _slicedToArray(_useState3, 2),
61
- currentKey = _useState4[0],
62
- setCurrentKey = _useState4[1];
63
- var _useState5 = (0, _react.useState)(null),
62
+ initLoading = _useState4[0],
63
+ setInitLoading = _useState4[1];
64
+ var _useState5 = (0, _react.useState)(''),
64
65
  _useState6 = _slicedToArray(_useState5, 2),
65
- recognizer = _useState6[0],
66
- setRecognizer = _useState6[1];
66
+ currentKey = _useState6[0],
67
+ setCurrentKey = _useState6[1];
67
68
  var _useState7 = (0, _react.useState)(null),
68
69
  _useState8 = _slicedToArray(_useState7, 2),
69
- recognizerRunner = _useState8[0],
70
- setRecognizerRunner = _useState8[1];
70
+ recognizer = _useState8[0],
71
+ setRecognizer = _useState8[1];
72
+ var _useState9 = (0, _react.useState)(null),
73
+ _useState10 = _slicedToArray(_useState9, 2),
74
+ recognizerRunner = _useState10[0],
75
+ setRecognizerRunner = _useState10[1];
71
76
  var initSdk = /*#__PURE__*/function () {
72
77
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(licenseKey) {
73
78
  var loadSettings;
@@ -113,12 +118,7 @@ var useMicroBlink = function useMicroBlink() {
113
118
  };
114
119
  }(), function (error) {
115
120
  setInitLoading(false);
116
- _message.default.error(formatMessage({
117
- id: 'Error during the initialization of the SDK! {error}',
118
- values: {
119
- error: error.message || error
120
- }
121
- }));
121
+ setInitError(error.message || error);
122
122
  });
123
123
  _context2.next = 11;
124
124
  break;
@@ -164,11 +164,8 @@ var useMicroBlink = function useMicroBlink() {
164
164
  recognitionResult = _context3.sent;
165
165
  return _context3.abrupt("return", recognitionResult);
166
166
  case 15:
167
- _message.default.error(formatMessage({
168
- id: 'Recognition was not successful!'
169
- }));
170
167
  return _context3.abrupt("return", null);
171
- case 17:
168
+ case 16:
172
169
  case "end":
173
170
  return _context3.stop();
174
171
  }
@@ -179,22 +176,7 @@ var useMicroBlink = function useMicroBlink() {
179
176
  };
180
177
  }();
181
178
  } else {
182
- return /*#__PURE__*/function () {
183
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(file) {
184
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
185
- while (1) switch (_context4.prev = _context4.next) {
186
- case 0:
187
- return _context4.abrupt("return", null);
188
- case 1:
189
- case "end":
190
- return _context4.stop();
191
- }
192
- }, _callee4);
193
- }));
194
- return function (_x5) {
195
- return _ref4.apply(this, arguments);
196
- };
197
- }();
179
+ return null;
198
180
  }
199
181
  }, [recognizer, recognizerRunner]);
200
182
  var dealRepeatSendRequest = function dealRepeatSendRequest(licenseKey) {
@@ -208,6 +190,10 @@ var useMicroBlink = function useMicroBlink() {
208
190
  return function (licenseKey) {
209
191
  dealRepeatSendRequest(licenseKey);
210
192
  return {
193
+ initResult: {
194
+ error: initError,
195
+ failed: !!initError
196
+ },
211
197
  recognize: recognize(),
212
198
  loading: initLoading
213
199
  };
@@ -50,6 +50,7 @@ var PhoneNumber = function PhoneNumber(_ref) {
50
50
  number = _useState4[0],
51
51
  setNumber = _useState4[1];
52
52
  (0, _react.useEffect)(function () {
53
+ if (!value) return;
53
54
  if ((value === null || value === void 0 ? void 0 : value.areaCode) === selectedCode && (value === null || value === void 0 ? void 0 : value.phoneNumber) === number) {
54
55
  return;
55
56
  }
@@ -60,10 +61,12 @@ var PhoneNumber = function PhoneNumber(_ref) {
60
61
  disabled: disabled,
61
62
  onChange: function onChange(e) {
62
63
  changeCode(e);
63
- formChangeProps(number && e ? {
64
- areaCode: e,
65
- phoneNumber: number
66
- } : undefined);
64
+ if (number) {
65
+ formChangeProps({
66
+ areaCode: e,
67
+ phoneNumber: number
68
+ });
69
+ }
67
70
  },
68
71
  className: (0, _classnames.default)('igloo-phone-number-select'),
69
72
  defaultValue: selectedCode,
@@ -9,18 +9,18 @@ var _react = require("react");
9
9
  var _iglooicon = require("iglooicon");
10
10
  var _iglootheme = require("iglootheme");
11
11
  var _antd = require("antd");
12
- var _invariant = _interopRequireDefault(require("invariant"));
13
12
  var lodash = _interopRequireWildcard(require("lodash"));
14
13
  var _moment = _interopRequireDefault(require("moment"));
14
+ var _invariant = _interopRequireDefault(require("invariant"));
15
15
  var _formContext = _interopRequireDefault(require("../../form-context"));
16
16
  var _typography = _interopRequireDefault(require("../../typography"));
17
17
  var _locale = require("../../locale");
18
18
  var _message = _interopRequireDefault(require("../../message"));
19
19
  require("./style");
20
20
  var _jsxRuntime = require("react/jsx-runtime");
21
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
22
23
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
24
  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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
25
25
  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); } }
26
26
  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); }); }; }
@@ -37,7 +37,8 @@ function getOcrDate(result, format) {
37
37
  }
38
38
  var MicroBlink = function MicroBlink(props) {
39
39
  var outputMap = props.outputMap,
40
- disabled = props.disabled;
40
+ disabled = props.disabled,
41
+ label = props.label;
41
42
  var Dragger = _antd.Upload.Dragger;
42
43
  var _useContext = (0, _react.useContext)(_formContext.default),
43
44
  ocrHooks = _useContext.ocrHooks,
@@ -48,8 +49,9 @@ var MicroBlink = function MicroBlink(props) {
48
49
  microBlink = _ref.microBlink;
49
50
  var _ref2 = microBlink || {},
50
51
  recognize = _ref2.recognize,
51
- loading = _ref2.loading;
52
- (0, _invariant.default)(Boolean(microBlink) && Boolean(recognize), 'Must Config Micro Blink licenseKey');
52
+ loading = _ref2.loading,
53
+ initResult = _ref2.initResult;
54
+ (0, _invariant.default)(microBlink, 'Form Must Has MicroBlink Config');
53
55
  var onUpload = /*#__PURE__*/function () {
54
56
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file) {
55
57
  var microBlinkResult, state, formSet;
@@ -65,23 +67,24 @@ var MicroBlink = function MicroBlink(props) {
65
67
  case 3:
66
68
  microBlinkResult = _context.sent;
67
69
  if (microBlinkResult) {
68
- _context.next = 6;
70
+ _context.next = 7;
69
71
  break;
70
72
  }
73
+ _message.default.error(formatMessage({
74
+ id: 'Recognition was not successful!'
75
+ }));
71
76
  return _context.abrupt("return");
72
- case 6:
77
+ case 7:
73
78
  state = microBlinkResult.state;
74
- _context.t0 = state;
75
- _context.next = _context.t0 === 0 ? 10 : 12;
76
- break;
77
- case 10:
79
+ if (!(state === 0)) {
80
+ _context.next = 11;
81
+ break;
82
+ }
78
83
  _message.default.error(formatMessage({
79
84
  id: 'Nothing has been recognized.'
80
85
  }));
81
86
  return _context.abrupt("return");
82
- case 12:
83
- return _context.abrupt("break", 13);
84
- case 13:
87
+ case 11:
85
88
  formSet = (outputMap || []).reduce(function (pre, cur) {
86
89
  var field = cur.field,
87
90
  source = cur.source,
@@ -98,7 +101,7 @@ var MicroBlink = function MicroBlink(props) {
98
101
  default:
99
102
  pre.push({
100
103
  name: field,
101
- value: lodash.get(microBlinkResult || {}, source),
104
+ value: lodash.get(microBlinkResult, source),
102
105
  errors: []
103
106
  });
104
107
  break;
@@ -106,7 +109,11 @@ var MicroBlink = function MicroBlink(props) {
106
109
  return pre;
107
110
  }, []);
108
111
  form === null || form === void 0 ? void 0 : form.setFields(formSet);
112
+ _context.next = 16;
113
+ break;
109
114
  case 15:
115
+ _message.default.error(initResult === null || initResult === void 0 ? void 0 : initResult.error);
116
+ case 16:
110
117
  case "end":
111
118
  return _context.stop();
112
119
  }
@@ -116,9 +123,14 @@ var MicroBlink = function MicroBlink(props) {
116
123
  return _ref3.apply(this, arguments);
117
124
  };
118
125
  }();
119
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_antd.Spin, {
126
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_antd.Spin, {
120
127
  spinning: loading,
121
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
128
+ children: [label && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
129
+ style: {
130
+ marginBottom: 8
131
+ },
132
+ children: label
133
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
122
134
  className: 'igloo-micro-blink',
123
135
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Dragger, {
124
136
  action: function action(file) {
@@ -130,7 +142,7 @@ var MicroBlink = function MicroBlink(props) {
130
142
  customRequest: function customRequest() {}
131
143
  // @ts-ignore
132
144
  ,
133
- disabled: disabled,
145
+ disabled: disabled || (initResult === null || initResult === void 0 ? void 0 : initResult.failed),
134
146
  multiple: true,
135
147
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
136
148
  className: "igloo-upload-box-center",
@@ -168,7 +180,7 @@ var MicroBlink = function MicroBlink(props) {
168
180
  })]
169
181
  })
170
182
  })
171
- })
183
+ })]
172
184
  });
173
185
  };
174
186
  var _default = MicroBlink;
package/lib/types.d.ts CHANGED
@@ -8,6 +8,10 @@ import { BlinkIdSingleSideRecognizerResult } from '@microblink/blinkid-in-browse
8
8
  export { Rule } from 'rc-field-form/lib/interface';
9
9
  export interface OCRHooks {
10
10
  microBlink?: {
11
+ initResult: {
12
+ error?: string;
13
+ failed: boolean;
14
+ };
11
15
  recognize: ((file: File) => Promise<BlinkIdSingleSideRecognizerResult | null>) | null;
12
16
  loading?: boolean;
13
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iglooform",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "build-dev": "dumi build",