{"version":3,"file":"createAsyncComponent2.mjs","sources":["../../../../../../packages/utils/factory/createAsyncComponent.tsx"],"sourcesContent":["import {\n  defineAsyncComponent,\n  // FunctionalComponent, CSSProperties\n} from 'vue'\nimport { Spin } from 'ant-design-vue'\nimport { noop } from '../basic'\n\n// const Loading: FunctionalComponent<{ size: 'small' | 'default' | 'large' }> = (props) => {\n//   const style: CSSProperties = {\n//     position: 'absolute',\n//     display: 'flex',\n//     justifyContent: 'center',\n//     alignItems: 'center',\n//   };\n//   return (\n//     <div style={style}>\n//       <Spin spinning={true} size={props.size} />\n//     </div>\n//   );\n// };\n\ninterface Options {\n  size?: 'default' | 'small' | 'large'\n  delay?: number\n  timeout?: number\n  loading?: boolean\n  retry?: boolean\n}\ninterface Fn<T = any, R = T> {\n  (...arg: T[]): R\n}\nexport function createAsyncComponent(loader: Fn, options: Options = {}) {\n  const { size = 'small', delay = 100, timeout = 30000, loading = false, retry = true } = options\n  return defineAsyncComponent({\n    loader,\n    loadingComponent: loading ? (\n      <div style=\"height:100%;height:100%;display:flex;justify-content:center;align-items:center\">\n        <Spin spinning={true} size={size} />\n      </div>\n    ) : undefined,\n    // The error component will be displayed if a timeout is\n    // provided and exceeded. Default: Infinity.\n    // TODO\n    timeout,\n    // errorComponent\n    // Defining if component is suspensible. Default: true.\n    // suspensible: false,\n    delay,\n    /**\n     *\n     * @param {*} error Error message object\n     * @param {*} retry A function that indicating whether the async component should retry when the loader promise rejects\n     * @param {*} fail  End of failure\n     * @param {*} attempts Maximum allowed retries number\n     */\n    onError: !retry\n      ? noop\n      : (error, retry, fail, attempts) => {\n          if (error.message.match(/fetch/) && attempts <= 3) {\n            // retry on fetch errors, 3 max attempts\n            retry()\n          } else {\n            // Note that retry/fail are like resolve/reject of a promise:\n            // one of them must be called for the error handling to continue.\n            fail()\n          }\n        },\n  })\n}\n"],"names":["_createVNode","size","delay","timeout","loading","retry","options","loadingComponent"],"mappings":";;;;AASA,SAAA,oBAAA,CAAA,MAAA,EAAA,OAAA,GAAA,EAAA,EAAA;AACA,EAAA,MAAA;AACA,IAAA,IAAA,GAAA,OAAA;AACA,IAAA,KAAA,GAAA,GAAA;AACA,IAAA,OAAA,GAAA,GAAA;AACA,IAAA,OAAA,GAAA,KAAA;AACA,IAAA,KAAA,GAAA,IAAA;AACA,GAAA,GAAA,OAAA,CAAA;AACA,EAAA,OAAA,oBAAA,CAAA;AACA,IAAA,MAAA;AACA,IAAA,gBAAA,EAAA,OAAA,GAAAA,WAAA,CAAA,KAAA,EAAA;;AAYA,KAAO,EAAA,CAAAA;MACC,UAAA,EAAA,IAAA;AAAEC,MAAAA,MAAF,EAAA,IAAA;AAAkBC,KAAAA,EAAAA,KAAQ,CAA1B,CAAA,GAAA,KAAA,CAAA;AAA+BC,IAAAA,OAAO;AAAUC,IAAAA,KAAAA;AAAiBC,IAAAA,OAAQ,EAAA,CAAA,KAAA,GAAA,IAAA,GAAA,CAAA,KAAA,EAAA,MAAA,EAAA,IAAA,EAAA,QAAA,KAAA;AAAzE,MAAkFC,IAAxF,KAAA,CAAA,OAAA,CAAA,KAAA,CAAA,OAAA,CAAA,IAAA,QAAA,IAAA,CAAA,EAAA;AACA,QAAA;OAA4B,MAAA;AAE1BC,QAAAA,IAAAA,EAAAA,CAAAA;OACa;AADY,KAAA;AAAA,GAAA,CAAA,CAAA;;;;;"}