iglooform 2.5.54 → 2.5.56

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 (122) hide show
  1. package/.dumi/tmp/core/EmptyRoute.tsx +9 -0
  2. package/.dumi/tmp/core/defineApp.ts +17 -0
  3. package/.dumi/tmp/core/exportStaticRuntimePlugin.ts +11 -0
  4. package/.dumi/tmp/core/helmet.ts +10 -0
  5. package/.dumi/tmp/core/helmetContext.ts +4 -0
  6. package/.dumi/tmp/core/history.ts +66 -0
  7. package/.dumi/tmp/core/historyIntelli.ts +132 -0
  8. package/.dumi/tmp/core/plugin.ts +60 -0
  9. package/.dumi/tmp/core/pluginConfig.ts +292 -0
  10. package/.dumi/tmp/core/pluginConfigJoi.d.ts +55 -0
  11. package/.dumi/tmp/core/polyfill.ts +201 -0
  12. package/.dumi/tmp/core/route.tsx +50 -0
  13. package/.dumi/tmp/core/terminal.ts +37 -0
  14. package/.dumi/tmp/dumi/exports.ts +5 -0
  15. package/.dumi/tmp/dumi/locales/config.ts +95 -0
  16. package/.dumi/tmp/dumi/locales/runtime.tsx +43 -0
  17. package/.dumi/tmp/dumi/meta/atoms.ts +4 -0
  18. package/.dumi/tmp/dumi/meta/index.ts +255 -0
  19. package/.dumi/tmp/dumi/meta/runtime.ts +31 -0
  20. package/.dumi/tmp/dumi/meta/tabs.ts +5 -0
  21. package/.dumi/tmp/dumi/theme/ContextWrapper.tsx +48 -0
  22. package/.dumi/tmp/dumi/theme/builtins/API.ts +4 -0
  23. package/.dumi/tmp/dumi/theme/builtins/Badge.ts +4 -0
  24. package/.dumi/tmp/dumi/theme/builtins/Container.ts +4 -0
  25. package/.dumi/tmp/dumi/theme/builtins/Previewer.ts +4 -0
  26. package/.dumi/tmp/dumi/theme/builtins/SourceCode.ts +4 -0
  27. package/.dumi/tmp/dumi/theme/builtins/Table.ts +4 -0
  28. package/.dumi/tmp/dumi/theme/builtins/Tree.ts +4 -0
  29. package/.dumi/tmp/dumi/theme/layouts/DocLayout.ts +4 -0
  30. package/.dumi/tmp/dumi/theme/loading.tsx +25 -0
  31. package/.dumi/tmp/dumi/theme/nprogress.css +59 -0
  32. package/.dumi/tmp/dumi/theme/slots/ColorSwitch.ts +4 -0
  33. package/.dumi/tmp/dumi/theme/slots/Content.ts +4 -0
  34. package/.dumi/tmp/dumi/theme/slots/ContentFooter.ts +4 -0
  35. package/.dumi/tmp/dumi/theme/slots/ContentTabs.ts +4 -0
  36. package/.dumi/tmp/dumi/theme/slots/Features.ts +4 -0
  37. package/.dumi/tmp/dumi/theme/slots/Footer.ts +4 -0
  38. package/.dumi/tmp/dumi/theme/slots/Header.ts +4 -0
  39. package/.dumi/tmp/dumi/theme/slots/HeaderExtra.ts +4 -0
  40. package/.dumi/tmp/dumi/theme/slots/Hero.ts +4 -0
  41. package/.dumi/tmp/dumi/theme/slots/HeroTitle.ts +4 -0
  42. package/.dumi/tmp/dumi/theme/slots/LangSwitch.ts +4 -0
  43. package/.dumi/tmp/dumi/theme/slots/Logo.ts +4 -0
  44. package/.dumi/tmp/dumi/theme/slots/Navbar.ts +4 -0
  45. package/.dumi/tmp/dumi/theme/slots/NavbarExtra.ts +4 -0
  46. package/.dumi/tmp/dumi/theme/slots/NotFound.ts +4 -0
  47. package/.dumi/tmp/dumi/theme/slots/PreviewerActions.ts +4 -0
  48. package/.dumi/tmp/dumi/theme/slots/PreviewerActionsExtra.ts +4 -0
  49. package/.dumi/tmp/dumi/theme/slots/RtlSwitch.ts +4 -0
  50. package/.dumi/tmp/dumi/theme/slots/SearchBar.ts +5 -0
  51. package/.dumi/tmp/dumi/theme/slots/SearchResult.ts +4 -0
  52. package/.dumi/tmp/dumi/theme/slots/Sidebar.ts +4 -0
  53. package/.dumi/tmp/dumi/theme/slots/SocialIcon.ts +4 -0
  54. package/.dumi/tmp/dumi/theme/slots/Toc.ts +4 -0
  55. package/.dumi/tmp/exports.ts +18 -0
  56. package/.dumi/tmp/plugin-antd/runtime.tsx +65 -0
  57. package/.dumi/tmp/plugin-antd/runtimeConfig.d.ts +6 -0
  58. package/.dumi/tmp/plugin-antd/types.d.ts +14 -0
  59. package/.dumi/tmp/plugin-html2sketch/index.ts +35 -0
  60. package/.dumi/tmp/testBrowser.tsx +90 -0
  61. package/.dumi/tmp/umi.ts +108 -0
  62. package/es/form/elements.js +3 -1
  63. package/es/form/index.js +12 -2
  64. package/es/form-context.d.ts +2 -1
  65. package/es/form-context.js +2 -1
  66. package/es/hooks/index.d.ts +1 -0
  67. package/es/hooks/index.js +1 -0
  68. package/es/hooks/ocr/index.d.ts +3 -0
  69. package/es/hooks/ocr/index.js +25 -0
  70. package/es/hooks/ocr/micro-blink.d.ts +3 -0
  71. package/es/hooks/ocr/micro-blink.js +231 -0
  72. package/es/input/input-date.js +40 -28
  73. package/es/input/phone-number.d.ts +1 -1
  74. package/es/input/phone-number.js +38 -15
  75. package/es/locale/en-US/messages.json +3 -0
  76. package/es/locale/id-ID/messages.json +3 -0
  77. package/es/locale/th-TH/messages.json +3 -0
  78. package/es/locale/vi-VN/messages.json +3 -0
  79. package/es/locale/zh-CN/messages.json +3 -0
  80. package/es/locale/zh-TW/messages.json +3 -0
  81. package/es/ocr/index.d.ts +15 -0
  82. package/es/ocr/index.js +38 -0
  83. package/es/ocr/micro-blink/index.d.ts +8 -0
  84. package/es/ocr/micro-blink/index.js +189 -0
  85. package/es/ocr/micro-blink/style/index.d.ts +1 -0
  86. package/es/ocr/micro-blink/style/index.js +1 -0
  87. package/es/ocr/micro-blink/style/index.less +30 -0
  88. package/es/types.d.ts +12 -0
  89. package/es/upload/index.js +46 -22
  90. package/es/upload-photo/index.js +24 -4
  91. package/es/utils/form-utils.js +1 -1
  92. package/lib/form/elements.js +4 -1
  93. package/lib/form/index.js +13 -2
  94. package/lib/form-context.d.ts +2 -1
  95. package/lib/form-context.js +2 -1
  96. package/lib/hooks/index.d.ts +1 -0
  97. package/lib/hooks/index.js +1 -0
  98. package/lib/hooks/ocr/index.d.ts +3 -0
  99. package/lib/hooks/ocr/index.js +36 -0
  100. package/lib/hooks/ocr/micro-blink.d.ts +3 -0
  101. package/lib/hooks/ocr/micro-blink.js +251 -0
  102. package/lib/input/input-date.js +40 -28
  103. package/lib/input/phone-number.d.ts +1 -1
  104. package/lib/input/phone-number.js +42 -17
  105. package/lib/locale/en-US/messages.json +3 -0
  106. package/lib/locale/id-ID/messages.json +3 -0
  107. package/lib/locale/th-TH/messages.json +3 -0
  108. package/lib/locale/vi-VN/messages.json +3 -0
  109. package/lib/locale/zh-CN/messages.json +3 -0
  110. package/lib/locale/zh-TW/messages.json +3 -0
  111. package/lib/ocr/index.d.ts +15 -0
  112. package/lib/ocr/index.js +49 -0
  113. package/lib/ocr/micro-blink/index.d.ts +8 -0
  114. package/lib/ocr/micro-blink/index.js +218 -0
  115. package/lib/ocr/micro-blink/style/index.d.ts +1 -0
  116. package/lib/ocr/micro-blink/style/index.js +3 -0
  117. package/lib/ocr/micro-blink/style/index.less +30 -0
  118. package/lib/types.d.ts +12 -0
  119. package/lib/upload/index.js +45 -22
  120. package/lib/upload-photo/index.js +23 -4
  121. package/lib/utils/form-utils.js +1 -1
  122. package/package.json +2 -1
@@ -0,0 +1,65 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ import React from 'react';
5
+ import {
6
+ Modal,
7
+ ConfigProvider,
8
+ message,
9
+ notification,
10
+ } from 'antd';
11
+ import { ApplyPluginsType } from 'umi';
12
+ import { getPluginManager } from '../core/plugin';
13
+
14
+ let cacheAntdConfig = null;
15
+
16
+ const getAntdConfig = () => {
17
+ if(!cacheAntdConfig){
18
+ cacheAntdConfig = getPluginManager().applyPlugins({
19
+ key: 'antd',
20
+ type: ApplyPluginsType.modify,
21
+ initialValue: {
22
+ ...{"theme":{"token":{"colorPrimary":"#5858FF","colorError":"#F52209","colorSuccess":"#108043","colorInfo":"#1E90FF","colorWarning":"#CF8909","controlHeight":48,"controlHeightSM":24,"controlOutlineWidth":0,"borderRadius":3,"fontSize":16,"lineHeight":1.2857,"fontFamily":"Roboto"},"components":{"Radio":{"radioSize":22,"dotSize":8,"buttonCheckedBgDisabled":"rgba(0, 0, 0, 0.04)"},"Pagination":{"itemSizeSM":40},"DatePicker":{"pickerPanelCellWidth":36}}}},
23
+ },
24
+ });
25
+ }
26
+ return cacheAntdConfig;
27
+ }
28
+
29
+ export function rootContainer(rawContainer) {
30
+ const {
31
+ appConfig,
32
+ ...finalConfigProvider
33
+ } = getAntdConfig();
34
+ let container = rawContainer;
35
+ if (finalConfigProvider.prefixCls) {
36
+ Modal.config({
37
+ rootPrefixCls: finalConfigProvider.prefixCls
38
+ });
39
+ message.config({
40
+ prefixCls: `${finalConfigProvider.prefixCls}-message`
41
+ });
42
+ notification.config({
43
+ prefixCls: `${finalConfigProvider.prefixCls}-notification`
44
+ });
45
+ }
46
+
47
+ if (finalConfigProvider.iconPrefixCls) {
48
+ // Icons in message need to set iconPrefixCls via ConfigProvider.config()
49
+ ConfigProvider.config({
50
+ iconPrefixCls: finalConfigProvider.iconPrefixCls,
51
+ });
52
+ };
53
+
54
+ if (finalConfigProvider.theme) {
55
+ // Pass config theme to static method
56
+ ConfigProvider.config({
57
+ theme: finalConfigProvider.theme,
58
+ });
59
+ }
60
+
61
+ container = <ConfigProvider {...finalConfigProvider}>{container}</ConfigProvider>;
62
+
63
+
64
+ return container;
65
+ }
@@ -0,0 +1,6 @@
1
+ // This file is generated by Umi automatically
2
+ // DO NOT CHANGE IT MANUALLY!
3
+ import type { RuntimeAntdConfig } from './types.d';
4
+ export type IRuntimeConfig = {
5
+ antd?: RuntimeAntdConfig
6
+ };
@@ -0,0 +1,14 @@
1
+ // This file is generated by Umi automatically
2
+ // DO NOT CHANGE IT MANUALLY!
3
+ import type { ConfigProviderProps } from 'antd/es/config-provider';
4
+
5
+ type Prettify<T> = {
6
+ [K in keyof T]: T[K];
7
+ } & {};
8
+
9
+ type AntdConfig = Prettify<{}
10
+ & ConfigProviderProps
11
+
12
+ >;
13
+
14
+ export type RuntimeAntdConfig = (memo: AntdConfig) => AntdConfig;
@@ -0,0 +1,35 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ import type { nodeToGroup, nodeToSymbol, SketchFormat } from 'html2sketch';
5
+ import { ApplyPluginsType } from 'dumi';
6
+ import { getPluginManager } from '@@/core/plugin';
7
+
8
+ const html2sketch = typeof window !== 'undefined' ? window.html2sketch as {
9
+ nodeToGroup: typeof nodeToGroup;
10
+ nodeToSymbol: typeof nodeToSymbol;
11
+ } : null;
12
+
13
+ async function toSketchJSON(
14
+ node: HTMLElement,
15
+ opts: { type: 'group' | 'symbol' },
16
+ ) {
17
+ return opts.type === 'group'
18
+ ? (await html2sketch.nodeToGroup(node)).toSketchJSON()
19
+ : (await html2sketch.nodeToSymbol(node)).toSketchJSON();
20
+ }
21
+
22
+ function runtimeToSketchJSON(
23
+ target: HTMLElement | Document,
24
+ opts: Parameters<typeof toSketchJSON>[1],
25
+ ): ReturnType<typeof toSketchJSON> | Promise<null> {
26
+ return getPluginManager().applyPlugins({
27
+ key: 'toSketchJSON',
28
+ type: ApplyPluginsType.modify,
29
+ initialValue: null,
30
+ args: { target, opts },
31
+ async: true,
32
+ });
33
+ }
34
+
35
+ export const getSketchJSON = null;
@@ -0,0 +1,90 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ import React, { useEffect, useState } from 'react';
5
+ import { ApplyPluginsType } from 'umi';
6
+ import { renderClient, RenderClientOpts } from '/Users/lei/iglooform/node_modules/@umijs/renderer-react';
7
+ import { createHistory } from './core/history';
8
+ import { createPluginManager } from './core/plugin';
9
+ import { getRoutes } from './core/route';
10
+ import type { Location } from 'history';
11
+
12
+ import '/Users/lei/iglooform/.dumi/global.less';
13
+ import { getPluginManager as getDumiPluginManager } from './core/plugin';
14
+ import { setPluginManager as setDumiPluginManager } from '/Users/lei/iglooform/node_modules/dumi/dist/client/theme-api/utils.js';
15
+ import 'antd/dist/reset.css';
16
+ const publicPath = '/';
17
+ const runtimePublicPath = false;
18
+
19
+ type TestBrowserProps = {
20
+ location?: Partial<Location>;
21
+ historyRef?: React.MutableRefObject<Location>;
22
+ };
23
+
24
+ export function TestBrowser(props: TestBrowserProps) {
25
+ const pluginManager = createPluginManager();
26
+ const [context, setContext] = useState<RenderClientOpts | undefined>(
27
+ undefined
28
+ );
29
+ useEffect(() => {
30
+ const genContext = async () => {
31
+ const { routes, routeComponents } = await getRoutes(pluginManager);
32
+ // allow user to extend routes
33
+ await pluginManager.applyPlugins({
34
+ key: 'patchRoutes',
35
+ type: ApplyPluginsType.event,
36
+ args: {
37
+ routes,
38
+ routeComponents,
39
+ },
40
+ });
41
+ const contextOpts = pluginManager.applyPlugins({
42
+ key: 'modifyContextOpts',
43
+ type: ApplyPluginsType.modify,
44
+ initialValue: {},
45
+ });
46
+ const basename = contextOpts.basename || '/';
47
+ const history = createHistory({
48
+ type: 'memory',
49
+ basename,
50
+ });
51
+ const context = {
52
+ routes,
53
+ routeComponents,
54
+ pluginManager,
55
+ rootElement: contextOpts.rootElement || document.getElementById('root'),
56
+ publicPath,
57
+ runtimePublicPath,
58
+ history,
59
+ basename,
60
+ components: true,
61
+ };
62
+ const modifiedContext = pluginManager.applyPlugins({
63
+ key: 'modifyClientRenderOpts',
64
+ type: ApplyPluginsType.modify,
65
+ initialValue: context,
66
+ });
67
+ return modifiedContext;
68
+ };
69
+ genContext().then((context) => {
70
+ setContext(context);
71
+ if (props.location) {
72
+ context?.history?.push(props.location);
73
+ }
74
+ if (props.historyRef) {
75
+ props.historyRef.current = context?.history;
76
+ }
77
+ });
78
+ }, []);
79
+
80
+ if (context === undefined) {
81
+ return <div id="loading" />;
82
+ }
83
+
84
+ const Children = renderClient(context);
85
+ return (
86
+ <React.Fragment>
87
+ <Children />
88
+ </React.Fragment>
89
+ );
90
+ }
@@ -0,0 +1,108 @@
1
+ // @ts-nocheck
2
+ // This file is generated by Umi automatically
3
+ // DO NOT CHANGE IT MANUALLY!
4
+ import './core/polyfill';
5
+ import '/Users/lei/iglooform/.dumi/global.less';
6
+ import { getPluginManager as getDumiPluginManager } from './core/plugin';
7
+ import { setPluginManager as setDumiPluginManager } from '/Users/lei/iglooform/node_modules/dumi/dist/client/theme-api/utils.js';
8
+ import 'antd/dist/reset.css';
9
+ import { renderClient } from '/Users/lei/iglooform/node_modules/@umijs/renderer-react';
10
+ import { getRoutes } from './core/route';
11
+ import { createPluginManager } from './core/plugin';
12
+ import { createHistory } from './core/history';
13
+ import Loading from '@@/dumi/theme/loading';
14
+ import { ApplyPluginsType } from 'umi';
15
+ import '/Users/lei/iglooform/.dumi/overrides.less';
16
+
17
+ const publicPath = "/";
18
+ const runtimePublicPath = false;
19
+
20
+ async function render() {
21
+ const pluginManager = createPluginManager();
22
+ const { routes, routeComponents } = await getRoutes(pluginManager);
23
+
24
+ // allow user to extend routes
25
+ await pluginManager.applyPlugins({
26
+ key: 'patchRoutes',
27
+ type: ApplyPluginsType.event,
28
+ args: {
29
+ routes,
30
+ routeComponents,
31
+ },
32
+ });
33
+
34
+ const contextOpts = pluginManager.applyPlugins({
35
+ key: 'modifyContextOpts',
36
+ type: ApplyPluginsType.modify,
37
+ initialValue: {},
38
+ });
39
+
40
+ const basename = contextOpts.basename || '/';
41
+ const historyType = contextOpts.historyType || 'browser';
42
+
43
+ const history = createHistory({
44
+ type: historyType,
45
+ basename,
46
+ ...contextOpts.historyOpts,
47
+ });
48
+
49
+ return (pluginManager.applyPlugins({
50
+ key: 'render',
51
+ type: ApplyPluginsType.compose,
52
+ initialValue() {
53
+ const context = {
54
+ routes,
55
+ routeComponents,
56
+ pluginManager,
57
+ rootElement: contextOpts.rootElement || document.getElementById('root'),
58
+ loadingComponent: Loading,
59
+ publicPath,
60
+ runtimePublicPath,
61
+ history,
62
+ historyType,
63
+ basename,
64
+ callback: contextOpts.callback,
65
+ };
66
+ const modifiedContext = pluginManager.applyPlugins({
67
+ key: 'modifyClientRenderOpts',
68
+ type: ApplyPluginsType.modify,
69
+ initialValue: context,
70
+ });
71
+ return renderClient(modifiedContext);
72
+ },
73
+ }))();
74
+ }
75
+
76
+
77
+ // always remove trailing slash from location.pathname
78
+ if (
79
+ typeof history !== 'undefined' &&
80
+ location.pathname.length > 1 &&
81
+ location.pathname.endsWith('/')
82
+ ) {
83
+ history.replaceState(
84
+ {},
85
+ '',
86
+ location.pathname.slice(0, -1) + location.search + location.hash,
87
+ );
88
+ }
89
+
90
+ (function () {
91
+ var cache = typeof navigator !== 'undefined' && navigator.cookieEnabled && typeof window.localStorage !== 'undefined' && localStorage.getItem('dumi:prefers-color') || 'light';
92
+ var isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
93
+ var enums = ['light', 'dark', 'auto'];
94
+
95
+ document.documentElement.setAttribute(
96
+ 'data-prefers-color',
97
+ cache === enums[2]
98
+ ? (isDark ? enums[1] : enums[0])
99
+ : (enums.indexOf(cache) > -1 ? cache : enums[0])
100
+ );
101
+ })();
102
+ render();
103
+
104
+ window.g_umi = {
105
+ version: '4.0.75',
106
+ };
107
+
108
+ setDumiPluginManager(getDumiPluginManager());
@@ -13,6 +13,7 @@ import UploadPhoto from '../upload-photo';
13
13
  import RenderElement from './render';
14
14
  import Typography from '../typography';
15
15
  import SearchBox from '../search-box';
16
+ import OCR from '../ocr';
16
17
  var elementMap = {
17
18
  Input: Input,
18
19
  PhoneNumber: PhoneNumber,
@@ -45,7 +46,8 @@ var elementMap = {
45
46
  Confirmation: Confirmation,
46
47
  ExpiryDate: ExpiryDate,
47
48
  Typography: Typography,
48
- SearchBox: SearchBox
49
+ SearchBox: SearchBox,
50
+ OCR: OCR
49
51
  };
50
52
 
51
53
  var Unknown = function Unknown() {
package/es/form/index.js CHANGED
@@ -42,6 +42,7 @@ import classNames from 'classnames';
42
42
  import invariant from 'invariant';
43
43
  import { LocaleContext } from '../locale';
44
44
  import { getRuleValidation } from './../utils/form-utils';
45
+ import useOCR from '../hooks/ocr';
45
46
 
46
47
  var IglooForm = function IglooForm(props, ref) {
47
48
  var config = props.config,
@@ -67,7 +68,8 @@ var IglooForm = function IglooForm(props, ref) {
67
68
  selectDatasourceApi = props.selectDatasourceApi,
68
69
  getRuleValidationApi = props.getRuleValidationApi,
69
70
  _props$stepDirection = props.stepDirection,
70
- stepDirection = _props$stepDirection === void 0 ? 'vertical' : _props$stepDirection;
71
+ stepDirection = _props$stepDirection === void 0 ? 'vertical' : _props$stepDirection,
72
+ ocr = props.ocr;
71
73
 
72
74
  var _Form$useForm = _Form.useForm(),
73
75
  _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
@@ -95,6 +97,13 @@ var IglooForm = function IglooForm(props, ref) {
95
97
  currentLang = _useContext.currentLang;
96
98
 
97
99
  var validationRule = props.validationRule || config.validationRule;
100
+ var createHooks = useOCR();
101
+ var ocrHooks = undefined;
102
+
103
+ if (ocr) {
104
+ ocrHooks = createHooks(ocr);
105
+ }
106
+
98
107
  invariant(type, "Contianer type should be one of ['Pages', 'Page', 'Steps', 'Login']");
99
108
  invariant(!validationRule || getRuleValidationApi, 'Please provide getRuleValidationApi in Form props');
100
109
 
@@ -278,7 +287,8 @@ var IglooForm = function IglooForm(props, ref) {
278
287
  uploadApi: uploadApi,
279
288
  selectDatasourceApi: selectDatasourceApi,
280
289
  getRuleValidationApi: getRuleValidationApi,
281
- handleValuesChange: handleValuesChange
290
+ handleValuesChange: handleValuesChange,
291
+ ocrHooks: ocrHooks
282
292
  }, locales),
283
293
  children: _jsxs(_Form, {
284
294
  form: form,
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { FormInstance } from 'antd/es/form';
3
- import { FormItemName } from '@/types';
3
+ import { FormItemName, OCRHooks } from './types';
4
4
  declare const _default: React.Context<{
5
5
  form?: FormInstance<any> | undefined;
6
6
  onCancel?(): void;
@@ -19,5 +19,6 @@ declare const _default: React.Context<{
19
19
  selectDatasourceApi?: string | undefined;
20
20
  getRuleValidationApi?: string | undefined;
21
21
  handleValuesChange(changedFields: any): any;
22
+ ocrHooks?: OCRHooks | undefined;
22
23
  }>;
23
24
  export default _default;
@@ -4,5 +4,6 @@ export default /*#__PURE__*/React.createContext({
4
4
  return window;
5
5
  },
6
6
  registerDependencies: function registerDependencies() {},
7
- handleValuesChange: function handleValuesChange() {}
7
+ handleValuesChange: function handleValuesChange() {},
8
+ ocrHooks: {}
8
9
  });
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,3 @@
1
+ import { OCRConfig, OCRHooks } from '../../types';
2
+ declare const useOCR: () => (config: OCRConfig) => OCRHooks;
3
+ export default useOCR;
@@ -0,0 +1,25 @@
1
+ import invariant from 'invariant';
2
+ import useMicroBlink from './micro-blink';
3
+
4
+ var useOCR = function useOCR() {
5
+ var createRecognize = useMicroBlink();
6
+ return function (config) {
7
+ var microBlink = config.microBlink;
8
+
9
+ var _ref = microBlink || {},
10
+ licenseKey = _ref.licenseKey;
11
+
12
+ var hooks = {};
13
+ invariant(Boolean(microBlink) === Boolean(licenseKey), 'Must Config licenseKey of Micro Blink');
14
+
15
+ if (microBlink && licenseKey) {
16
+ hooks['microBlink'] = {
17
+ recognize: createRecognize(licenseKey)
18
+ };
19
+ }
20
+
21
+ return hooks;
22
+ };
23
+ };
24
+
25
+ export default useOCR;
@@ -0,0 +1,3 @@
1
+ import * as BlinkIDSDK from '@microblink/blinkid-in-browser-sdk';
2
+ declare const useMicroBlink: () => (licenseKey: string) => (file: File) => Promise<BlinkIDSDK.BlinkIdSingleSideRecognizerResult | null>;
3
+ export default useMicroBlink;
@@ -0,0 +1,231 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+
3
+ 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."); }
4
+
5
+ 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); }
6
+
7
+ 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; }
8
+
9
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
10
+
11
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
+
13
+ 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); } }
14
+
15
+ 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); }); }; }
16
+
17
+ import { useState, useCallback } from 'react';
18
+ import * as BlinkIDSDK from '@microblink/blinkid-in-browser-sdk';
19
+ import message from '../../global-message';
20
+ var MICRO_BLINK_SERVICE_PATH = 'https://static.iglooinsure.com/microblink/in-browser';
21
+
22
+ function getWorkerLocation(_x) {
23
+ return _getWorkerLocation.apply(this, arguments);
24
+ }
25
+
26
+ function _getWorkerLocation() {
27
+ _getWorkerLocation = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(path) {
28
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
29
+ while (1) {
30
+ switch (_context5.prev = _context5.next) {
31
+ case 0:
32
+ return _context5.abrupt("return", new Promise(function (resolve) {
33
+ window.fetch(path).then(function (response) {
34
+ return response.text();
35
+ }).then(function (data) {
36
+ var blob = new Blob([data], {
37
+ type: 'application/javascript'
38
+ });
39
+ var url = URL.createObjectURL(blob);
40
+ resolve(url);
41
+ });
42
+ }));
43
+
44
+ case 1:
45
+ case "end":
46
+ return _context5.stop();
47
+ }
48
+ }
49
+ }, _callee5);
50
+ }));
51
+ return _getWorkerLocation.apply(this, arguments);
52
+ }
53
+
54
+ var useMicroBlink = function useMicroBlink() {
55
+ var _useState = useState(''),
56
+ _useState2 = _slicedToArray(_useState, 2),
57
+ currentKey = _useState2[0],
58
+ setCurrentKey = _useState2[1];
59
+
60
+ var _useState3 = useState(null),
61
+ _useState4 = _slicedToArray(_useState3, 2),
62
+ recognizer = _useState4[0],
63
+ setRecognizer = _useState4[1];
64
+
65
+ var _useState5 = useState(null),
66
+ _useState6 = _slicedToArray(_useState5, 2),
67
+ recognizerRunner = _useState6[0],
68
+ setRecognizerRunner = _useState6[1];
69
+
70
+ var initSdk = /*#__PURE__*/function () {
71
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(licenseKey) {
72
+ var loadSettings;
73
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
74
+ while (1) {
75
+ switch (_context2.prev = _context2.next) {
76
+ case 0:
77
+ if (!BlinkIDSDK.isBrowserSupported()) {
78
+ _context2.next = 9;
79
+ break;
80
+ }
81
+
82
+ loadSettings = new BlinkIDSDK.WasmSDKLoadSettings(licenseKey);
83
+ loadSettings.engineLocation = MICRO_BLINK_SERVICE_PATH;
84
+ _context2.next = 5;
85
+ return getWorkerLocation("".concat(MICRO_BLINK_SERVICE_PATH, "/BlinkIDWasmSDK.worker.min.js"));
86
+
87
+ case 5:
88
+ loadSettings.workerLocation = _context2.sent;
89
+ BlinkIDSDK.loadWasmModule(loadSettings).then( /*#__PURE__*/function () {
90
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(wasmSDK) {
91
+ var recognizer, recognizerRunner;
92
+ return regeneratorRuntime.wrap(function _callee$(_context) {
93
+ while (1) {
94
+ switch (_context.prev = _context.next) {
95
+ case 0:
96
+ _context.next = 2;
97
+ return BlinkIDSDK.createBlinkIdSingleSideRecognizer(wasmSDK);
98
+
99
+ case 2:
100
+ recognizer = _context.sent;
101
+ _context.next = 5;
102
+ return BlinkIDSDK.createRecognizerRunner(wasmSDK, [recognizer], true);
103
+
104
+ case 5:
105
+ recognizerRunner = _context.sent;
106
+ setRecognizer(recognizer);
107
+ setRecognizerRunner(recognizerRunner);
108
+
109
+ case 8:
110
+ case "end":
111
+ return _context.stop();
112
+ }
113
+ }
114
+ }, _callee);
115
+ }));
116
+
117
+ return function (_x3) {
118
+ return _ref2.apply(this, arguments);
119
+ };
120
+ }(), function (error) {
121
+ console.log('Error during the initialization of the SDK!', error);
122
+ });
123
+ _context2.next = 10;
124
+ break;
125
+
126
+ case 9:
127
+ message.error('This browser is not supported by the SDK!');
128
+
129
+ case 10:
130
+ case "end":
131
+ return _context2.stop();
132
+ }
133
+ }
134
+ }, _callee2);
135
+ }));
136
+
137
+ return function initSdk(_x2) {
138
+ return _ref.apply(this, arguments);
139
+ };
140
+ }();
141
+
142
+ var recognize = useCallback(function () {
143
+ if (recognizer && recognizerRunner) {
144
+ return /*#__PURE__*/function () {
145
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(file) {
146
+ var ele, frame, processResult, recognitionResult;
147
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
148
+ while (1) {
149
+ switch (_context3.prev = _context3.next) {
150
+ case 0:
151
+ ele = document.createElement('img');
152
+ ele.src = URL.createObjectURL(file);
153
+ _context3.next = 4;
154
+ return ele.decode();
155
+
156
+ case 4:
157
+ frame = BlinkIDSDK.captureFrame(ele);
158
+ _context3.next = 7;
159
+ return recognizerRunner.processImage(frame);
160
+
161
+ case 7:
162
+ processResult = _context3.sent;
163
+
164
+ if (!(processResult !== BlinkIDSDK.RecognizerResultState.Empty)) {
165
+ _context3.next = 15;
166
+ break;
167
+ }
168
+
169
+ _context3.next = 11;
170
+ return recognizer.getResult();
171
+
172
+ case 11:
173
+ recognitionResult = _context3.sent;
174
+ return _context3.abrupt("return", recognitionResult);
175
+
176
+ case 15:
177
+ message.error('Recognition was not successful!');
178
+ return _context3.abrupt("return", null);
179
+
180
+ case 17:
181
+ case "end":
182
+ return _context3.stop();
183
+ }
184
+ }
185
+ }, _callee3);
186
+ }));
187
+
188
+ return function (_x4) {
189
+ return _ref3.apply(this, arguments);
190
+ };
191
+ }();
192
+ } else {
193
+ return /*#__PURE__*/function () {
194
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(file) {
195
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
196
+ while (1) {
197
+ switch (_context4.prev = _context4.next) {
198
+ case 0:
199
+ return _context4.abrupt("return", null);
200
+
201
+ case 1:
202
+ case "end":
203
+ return _context4.stop();
204
+ }
205
+ }
206
+ }, _callee4);
207
+ }));
208
+
209
+ return function (_x5) {
210
+ return _ref4.apply(this, arguments);
211
+ };
212
+ }();
213
+ }
214
+ }, [recognizer, recognizerRunner]);
215
+
216
+ var dealRepeatSendRequest = function dealRepeatSendRequest(licenseKey) {
217
+ if (currentKey !== '' && currentKey === licenseKey) {
218
+ return;
219
+ } else {
220
+ setCurrentKey(licenseKey);
221
+ initSdk(licenseKey);
222
+ }
223
+ };
224
+
225
+ return function (licenseKey) {
226
+ dealRepeatSendRequest(licenseKey);
227
+ return recognize();
228
+ };
229
+ };
230
+
231
+ export default useMicroBlink;