{"ast":null,"code":"\"use strict\";\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }\n\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\nexports.__esModule = true;\nexports.default = void 0;\n\nvar _react = _interopRequireDefault(require(\"react\"));\n\nvar _useSubscription = require(\"use-subscription\");\n\nvar _loadableContext = require(\"./loadable-context\");\n\nfunction _interopRequireDefault(obj) {\n return obj && obj.__esModule ? obj : {\n default: obj\n };\n}\n/**\n@copyright (c) 2017-present James Kyle <
[email protected]>\nMIT License\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE\n*/\n// https://github.com/jamiebuilds/react-loadable/blob/v5.5.0/src/index.js\n// Modified to be compatible with webpack 4 / Next.js\n\n\nconst ALL_INITIALIZERS = [];\nconst READY_INITIALIZERS = [];\nlet initialized = false;\n\nfunction load(loader) {\n let promise = loader();\n let state = {\n loading: true,\n loaded: null,\n error: null\n };\n state.promise = promise.then(loaded => {\n state.loading = false;\n state.loaded = loaded;\n return loaded;\n }).catch(err => {\n state.loading = false;\n state.error = err;\n throw err;\n });\n return state;\n}\n\nfunction loadMap(obj) {\n let state = {\n loading: false,\n loaded: {},\n error: null\n };\n let promises = [];\n\n try {\n Object.keys(obj).forEach(key => {\n let result = load(obj[key]);\n\n if (!result.loading) {\n state.loaded[key] = result.loaded;\n state.error = result.error;\n } else {\n state.loading = true;\n }\n\n promises.push(result.promise);\n result.promise.then(res => {\n state.loaded[key] = res;\n }).catch(err => {\n state.error = err;\n });\n });\n } catch (err) {\n state.error = err;\n }\n\n state.promise = Promise.all(promises).then(res => {\n state.loading = false;\n return res;\n }).catch(err => {\n state.loading = false;\n throw err;\n });\n return state;\n}\n\nfunction resolve(obj) {\n return obj && obj.__esModule ? obj.default : obj;\n}\n\nfunction render(loaded, props) {\n return /*#__PURE__*/_react.default.createElement(resolve(loaded), props);\n}\n\nfunction createLoadableComponent(loadFn, options) {\n let opts = Object.assign({\n loader: null,\n loading: null,\n delay: 200,\n timeout: null,\n render: render,\n webpack: null,\n modules: null\n }, options);\n let subscription = null;\n\n function init() {\n if (!subscription) {\n const sub = new LoadableSubscription(loadFn, opts);\n subscription = {\n getCurrentValue: sub.getCurrentValue.bind(sub),\n subscribe: sub.subscribe.bind(sub),\n retry: sub.retry.bind(sub),\n promise: sub.promise.bind(sub)\n };\n }\n\n return subscription.promise();\n } // Server only\n\n\n if (true) {\n ALL_INITIALIZERS.push(init);\n } // Client only\n\n\n if (!initialized && false && typeof opts.webpack === 'function') {\n const moduleIds = opts.webpack();\n READY_INITIALIZERS.push(ids => {\n for (const moduleId of moduleIds) {\n if (ids.indexOf(moduleId) !== -1) {\n return init();\n }\n }\n });\n }\n\n const LoadableComponent = (props, ref) => {\n init();\n\n const context = _react.default.useContext(_loadableContext.LoadableContext);\n\n const state = (0, _useSubscription.useSubscription)(subscription);\n\n _react.default.useImperativeHandle(ref, () => ({\n retry: subscription.retry\n }), []);\n\n if (context && Array.isArray(opts.modules)) {\n opts.modules.forEach(moduleName => {\n context(moduleName);\n });\n }\n\n return _react.default.useMemo(() => {\n if (state.loading || state.error) {\n return /*#__PURE__*/_react.default.createElement(opts.loading, {\n isLoading: state.loading,\n pastDelay: state.pastDelay,\n timedOut: state.timedOut,\n error: state.error,\n retry: subscription.retry\n });\n } else if (state.loaded) {\n return opts.render(state.loaded, props);\n } else {\n return null;\n }\n }, [props, state]);\n };\n\n LoadableComponent.preload = () => init();\n\n LoadableComponent.displayName = 'LoadableComponent';\n return /*#__PURE__*/_react.default.forwardRef(LoadableComponent);\n}\n\nclass LoadableSubscription {\n constructor(loadFn, opts) {\n this._loadFn = loadFn;\n this._opts = opts;\n this._callbacks = new Set();\n this._delay = null;\n this._timeout = null;\n this.retry();\n }\n\n promise() {\n return this._res.promise;\n }\n\n retry() {\n this._clearTimeouts();\n\n this._res = this._loadFn(this._opts.loader);\n this._state = {\n pastDelay: false,\n timedOut: false\n };\n const {\n _res: res,\n _opts: opts\n } = this;\n\n if (res.loading) {\n if (typeof opts.delay === 'number') {\n if (opts.delay === 0) {\n this._state.pastDelay = true;\n } else {\n this._delay = setTimeout(() => {\n this._update({\n pastDelay: true\n });\n }, opts.delay);\n }\n }\n\n if (typeof opts.timeout === 'number') {\n this._timeout = setTimeout(() => {\n this._update({\n timedOut: true\n });\n }, opts.timeout);\n }\n }\n\n this._res.promise.then(() => {\n this._update({});\n\n this._clearTimeouts();\n }).catch(_err => {\n this._update({});\n\n this._clearTimeouts();\n });\n\n this._update({});\n }\n\n _update(partial) {\n this._state = _objectSpread(_objectSpread({}, this._state), {}, {\n error: this._res.error,\n loaded: this._res.loaded,\n loading: this._res.loading\n }, partial);\n\n this._callbacks.forEach(callback => callback());\n }\n\n _clearTimeouts() {\n clearTimeout(this._delay);\n clearTimeout(this._timeout);\n }\n\n getCurrentValue() {\n return this._state;\n }\n\n subscribe(callback) {\n this._callbacks.add(callback);\n\n return () => {\n this._callbacks.delete(callback);\n };\n }\n\n}\n\nfunction Loadable(opts) {\n return createLoadableComponent(load, opts);\n}\n\nfunction LoadableMap(opts) {\n if (typeof opts.render !== 'function') {\n throw new Error('LoadableMap requires a `render(loaded, props)` function');\n }\n\n return createLoadableComponent(loadMap, opts);\n}\n\nLoadable.Map = LoadableMap;\n\nfunction flushInitializers(initializers, ids) {\n let promises = [];\n\n while (initializers.length) {\n let init = initializers.pop();\n promises.push(init(ids));\n }\n\n return Promise.all(promises).then(() => {\n if (initializers.length) {\n return flushInitializers(initializers, ids);\n }\n });\n}\n\nLoadable.preloadAll = () => {\n return new Promise((resolveInitializers, reject) => {\n flushInitializers(ALL_INITIALIZERS).then(resolveInitializers, reject);\n });\n};\n\nLoadable.preloadReady = (ids = []) => {\n return new Promise(resolvePreload => {\n const res = () => {\n initialized = true;\n return resolvePreload();\n }; // We always will resolve, errors should be handled within loading UIs.\n\n\n flushInitializers(READY_INITIALIZERS, ids).then(res, res);\n });\n};\n\nif (false) {\n window.__NEXT_PRELOADREADY = Loadable.preloadReady;\n}\n\nvar _default = Loadable;\nexports.default = _default;","map":null,"metadata":{},"sourceType":"script"}
0 commit comments