From 4602e2d2b00d0b171afd3428806b44321a0d13fd Mon Sep 17 00:00:00 2001 From: Rida Abou-Haidar Date: Mon, 2 Dec 2024 05:03:52 -0500 Subject: [PATCH] trying to fix lint after adjustements --- modules/biobank/js/biobankIndex.js | 44962 +++++++++------- modules/biobank/js/components/BiobankIndex.js | 32390 ----------- .../biobank/js/components/BiobankIndex.js.map | 1 - modules/biobank/jsx/processForm.js | 6 +- modules/biobank/php/.condition.class.inc.swp | Bin 0 -> 12288 bytes modules/biobank/php/barcodes.class.inc | 4 +- modules/biobank/php/condition.class.inc | 33 + modules/biobank/php/endpoint.class.inc | 52 +- modules/biobank/php/logicaloperator.class.inc | 16 + modules/biobank/php/operator.class.inc | 42 + modules/biobank/php/queryparams.class.inc | 13 - .../biobank/php/queryparamshandler.class.inc | 65 +- modules/biobank/php/specimendao.class.inc | 12 +- 13 files changed, 25041 insertions(+), 52555 deletions(-) delete mode 100644 modules/biobank/js/components/BiobankIndex.js delete mode 100644 modules/biobank/js/components/BiobankIndex.js.map create mode 100644 modules/biobank/php/.condition.class.inc.swp create mode 100644 modules/biobank/php/condition.class.inc create mode 100644 modules/biobank/php/logicaloperator.class.inc create mode 100644 modules/biobank/php/operator.class.inc diff --git a/modules/biobank/js/biobankIndex.js b/modules/biobank/js/biobankIndex.js index 9fbd6c66805..585e21c13d3 100644 --- a/modules/biobank/js/biobankIndex.js +++ b/modules/biobank/js/biobankIndex.js @@ -1,2516 +1,5532 @@ /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ -/***/ "./jsx/DataTable.js": -/*!**************************!*\ - !*** ./jsx/DataTable.js ***! - \**************************/ -/***/ ((__unused_webpack_module, exports, __webpack_require__) => { +/***/ "./node_modules/@remix-run/router/dist/router.js": +/*!*******************************************************!*\ + !*** ./node_modules/@remix-run/router/dist/router.js ***! + \*******************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; - - -var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js"); -var _typeof3 = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js"); -Object.defineProperty(exports, "__esModule", ({ - value: true -})); -exports["default"] = void 0; -var _typeof2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js")); -var _classCallCheck2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "./node_modules/@babel/runtime/helpers/classCallCheck.js")); -var _createClass2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/createClass */ "./node_modules/@babel/runtime/helpers/createClass.js")); -var _possibleConstructorReturn2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "./node_modules/@babel/runtime/helpers/possibleConstructorReturn.js")); -var _getPrototypeOf2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "./node_modules/@babel/runtime/helpers/getPrototypeOf.js")); -var _inherits2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/inherits */ "./node_modules/@babel/runtime/helpers/inherits.js")); -var _react = _interopRequireWildcard(__webpack_require__(/*! react */ "react")); -var _propTypes = _interopRequireDefault(__webpack_require__(/*! prop-types */ "./node_modules/prop-types/index.js")); -var _PaginationLinks = _interopRequireDefault(__webpack_require__(/*! jsx/PaginationLinks */ "./jsx/PaginationLinks.js")); -var _reactAddonsCreateFragment = _interopRequireDefault(__webpack_require__(/*! react-addons-create-fragment */ "./node_modules/react-addons-create-fragment/index.js")); -var _Form = __webpack_require__(/*! jsx/Form */ "./jsx/Form.js"); -function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } -function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } -function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); } -function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ AbortedDeferredError: () => (/* binding */ AbortedDeferredError), +/* harmony export */ Action: () => (/* binding */ Action), +/* harmony export */ IDLE_BLOCKER: () => (/* binding */ IDLE_BLOCKER), +/* harmony export */ IDLE_FETCHER: () => (/* binding */ IDLE_FETCHER), +/* harmony export */ IDLE_NAVIGATION: () => (/* binding */ IDLE_NAVIGATION), +/* harmony export */ UNSAFE_DEFERRED_SYMBOL: () => (/* binding */ UNSAFE_DEFERRED_SYMBOL), +/* harmony export */ UNSAFE_DeferredData: () => (/* binding */ DeferredData), +/* harmony export */ UNSAFE_ErrorResponseImpl: () => (/* binding */ ErrorResponseImpl), +/* harmony export */ UNSAFE_convertRouteMatchToUiMatch: () => (/* binding */ convertRouteMatchToUiMatch), +/* harmony export */ UNSAFE_convertRoutesToDataRoutes: () => (/* binding */ convertRoutesToDataRoutes), +/* harmony export */ UNSAFE_decodePath: () => (/* binding */ decodePath), +/* harmony export */ UNSAFE_getResolveToMatches: () => (/* binding */ getResolveToMatches), +/* harmony export */ UNSAFE_invariant: () => (/* binding */ invariant), +/* harmony export */ UNSAFE_warning: () => (/* binding */ warning), +/* harmony export */ createBrowserHistory: () => (/* binding */ createBrowserHistory), +/* harmony export */ createHashHistory: () => (/* binding */ createHashHistory), +/* harmony export */ createMemoryHistory: () => (/* binding */ createMemoryHistory), +/* harmony export */ createPath: () => (/* binding */ createPath), +/* harmony export */ createRouter: () => (/* binding */ createRouter), +/* harmony export */ createStaticHandler: () => (/* binding */ createStaticHandler), +/* harmony export */ data: () => (/* binding */ data), +/* harmony export */ defer: () => (/* binding */ defer), +/* harmony export */ generatePath: () => (/* binding */ generatePath), +/* harmony export */ getStaticContextFromError: () => (/* binding */ getStaticContextFromError), +/* harmony export */ getToPathname: () => (/* binding */ getToPathname), +/* harmony export */ isDataWithResponseInit: () => (/* binding */ isDataWithResponseInit), +/* harmony export */ isDeferredData: () => (/* binding */ isDeferredData), +/* harmony export */ isRouteErrorResponse: () => (/* binding */ isRouteErrorResponse), +/* harmony export */ joinPaths: () => (/* binding */ joinPaths), +/* harmony export */ json: () => (/* binding */ json), +/* harmony export */ matchPath: () => (/* binding */ matchPath), +/* harmony export */ matchRoutes: () => (/* binding */ matchRoutes), +/* harmony export */ normalizePathname: () => (/* binding */ normalizePathname), +/* harmony export */ parsePath: () => (/* binding */ parsePath), +/* harmony export */ redirect: () => (/* binding */ redirect), +/* harmony export */ redirectDocument: () => (/* binding */ redirectDocument), +/* harmony export */ replace: () => (/* binding */ replace), +/* harmony export */ resolvePath: () => (/* binding */ resolvePath), +/* harmony export */ resolveTo: () => (/* binding */ resolveTo), +/* harmony export */ stripBasename: () => (/* binding */ stripBasename) +/* harmony export */ }); /** - * Data Table component - * Displays a set of data that is receives via props. + * @remix-run/router v1.21.0 + * + * Copyright (c) Remix Software Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE.md file in the root directory of this source tree. + * + * @license MIT */ -var DataTable = /*#__PURE__*/function (_Component) { - /** - * @constructor - * @param {object} props - React Component properties - */ - function DataTable(props) { - var _this; - (0, _classCallCheck2["default"])(this, DataTable); - _this = _callSuper(this, DataTable, [props]); - _this.state = { - page: { - number: 1, - rows: 20 - }, - sort: { - column: -1, - ascending: true +function _extends() { + _extends = Object.assign ? Object.assign.bind() : function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i]; + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } } - }; - _this.changePage = _this.changePage.bind(_this); - _this.setSortColumn = _this.setSortColumn.bind(_this); - _this.updateSortColumn = _this.updateSortColumn.bind(_this); - _this.toggleSortOrder = _this.toggleSortOrder.bind(_this); - _this.updatePageNumber = _this.updatePageNumber.bind(_this); - _this.updatePageRows = _this.updatePageRows.bind(_this); - _this.downloadCSV = _this.downloadCSV.bind(_this); - _this.getFilteredRowIndexes = _this.getFilteredRowIndexes.bind(_this); - _this.sortRows = _this.sortRows.bind(_this); - _this.hasFilterKeyword = _this.hasFilterKeyword.bind(_this); - _this.renderActions = _this.renderActions.bind(_this); - return _this; - } + } + return target; + }; + return _extends.apply(this, arguments); +} +//////////////////////////////////////////////////////////////////////////////// +//#region Types and Constants +//////////////////////////////////////////////////////////////////////////////// +/** + * Actions represent the type of change to a location value. + */ +var Action; +(function (Action) { /** - * Set the component page variable - * to a new value + * A POP indicates a change to an arbitrary index in the history stack, such + * as a back or forward navigation. It does not describe the direction of the + * navigation, only that the current index changed. * - * @param {number} i - Page index + * Note: This is the default action for newly created history objects. */ - (0, _inherits2["default"])(DataTable, _Component); - return (0, _createClass2["default"])(DataTable, [{ - key: "changePage", - value: function changePage(i) { - var page = this.state.page; - page.number = i; - this.setState({ - page: page - }); - } - - /** - * Update the sort column - * If component sort.column is already set to column - * Toggle sort.ascending - * - * @param {number} column - The column index - */ - }, { - key: "setSortColumn", - value: function setSortColumn(column) { - if (this.state.sort.column === column) { - this.toggleSortOrder(); - } else { - this.updateSortColumn(column); + Action["Pop"] = "POP"; + /** + * A PUSH indicates a new entry being added to the history stack, such as when + * a link is clicked and a new page loads. When this happens, all subsequent + * entries in the stack are lost. + */ + Action["Push"] = "PUSH"; + /** + * A REPLACE indicates the entry at the current index in the history stack + * being replaced by a new one. + */ + Action["Replace"] = "REPLACE"; +})(Action || (Action = {})); +const PopStateEventType = "popstate"; +/** + * Memory history stores the current location in memory. It is designed for use + * in stateful non-browser environments like tests and React Native. + */ +function createMemoryHistory(options) { + if (options === void 0) { + options = {}; + } + let { + initialEntries = ["/"], + initialIndex, + v5Compat = false + } = options; + let entries; // Declare so we can access from createMemoryLocation + entries = initialEntries.map((entry, index) => createMemoryLocation(entry, typeof entry === "string" ? null : entry.state, index === 0 ? "default" : undefined)); + let index = clampIndex(initialIndex == null ? entries.length - 1 : initialIndex); + let action = Action.Pop; + let listener = null; + function clampIndex(n) { + return Math.min(Math.max(n, 0), entries.length - 1); + } + function getCurrentLocation() { + return entries[index]; + } + function createMemoryLocation(to, state, key) { + if (state === void 0) { + state = null; + } + let location = createLocation(entries ? getCurrentLocation().pathname : "/", to, state, key); + warning(location.pathname.charAt(0) === "/", "relative pathnames are not supported in memory history: " + JSON.stringify(to)); + return location; + } + function createHref(to) { + return typeof to === "string" ? to : createPath(to); + } + let history = { + get index() { + return index; + }, + get action() { + return action; + }, + get location() { + return getCurrentLocation(); + }, + createHref, + createURL(to) { + return new URL(createHref(to), "http://localhost"); + }, + encodeLocation(to) { + let path = typeof to === "string" ? parsePath(to) : to; + return { + pathname: path.pathname || "", + search: path.search || "", + hash: path.hash || "" + }; + }, + push(to, state) { + action = Action.Push; + let nextLocation = createMemoryLocation(to, state); + index += 1; + entries.splice(index, entries.length, nextLocation); + if (v5Compat && listener) { + listener({ + action, + location: nextLocation, + delta: 1 + }); + } + }, + replace(to, state) { + action = Action.Replace; + let nextLocation = createMemoryLocation(to, state); + entries[index] = nextLocation; + if (v5Compat && listener) { + listener({ + action, + location: nextLocation, + delta: 0 + }); } + }, + go(delta) { + action = Action.Pop; + let nextIndex = clampIndex(index + delta); + let nextLocation = entries[nextIndex]; + index = nextIndex; + if (listener) { + listener({ + action, + location: nextLocation, + delta + }); + } + }, + listen(fn) { + listener = fn; + return () => { + listener = null; + }; } - - /** - * Update the sort column - * - * @param {number} column - The column index - */ - }, { - key: "updateSortColumn", - value: function updateSortColumn(column) { - var sort = this.state.sort; - sort.column = column; - this.setState({ - sort: sort - }); + }; + return history; +} +/** + * Browser history stores the location in regular URLs. This is the standard for + * most web apps, but it requires some configuration on the server to ensure you + * serve the same app at multiple URLs. + * + * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory + */ +function createBrowserHistory(options) { + if (options === void 0) { + options = {}; + } + function createBrowserLocation(window, globalHistory) { + let { + pathname, + search, + hash + } = window.location; + return createLocation("", { + pathname, + search, + hash + }, + // state defaults to `null` because `window.history.state` does + globalHistory.state && globalHistory.state.usr || null, globalHistory.state && globalHistory.state.key || "default"); + } + function createBrowserHref(window, to) { + return typeof to === "string" ? to : createPath(to); + } + return getUrlBasedHistory(createBrowserLocation, createBrowserHref, null, options); +} +/** + * Hash history stores the location in window.location.hash. This makes it ideal + * for situations where you don't want to send the location to the server for + * some reason, either because you do cannot configure it or the URL space is + * reserved for something else. + * + * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory + */ +function createHashHistory(options) { + if (options === void 0) { + options = {}; + } + function createHashLocation(window, globalHistory) { + let { + pathname = "/", + search = "", + hash = "" + } = parsePath(window.location.hash.substr(1)); + // Hash URL should always have a leading / just like window.location.pathname + // does, so if an app ends up at a route like /#something then we add a + // leading slash so all of our path-matching behaves the same as if it would + // in a browser router. This is particularly important when there exists a + // root splat route () since that matches internally against + // "/*" and we'd expect /#something to 404 in a hash router app. + if (!pathname.startsWith("/") && !pathname.startsWith(".")) { + pathname = "/" + pathname; + } + return createLocation("", { + pathname, + search, + hash + }, + // state defaults to `null` because `window.history.state` does + globalHistory.state && globalHistory.state.usr || null, globalHistory.state && globalHistory.state.key || "default"); + } + function createHashHref(window, to) { + let base = window.document.querySelector("base"); + let href = ""; + if (base && base.getAttribute("href")) { + let url = window.location.href; + let hashIndex = url.indexOf("#"); + href = hashIndex === -1 ? url : url.slice(0, hashIndex); } - - /** - * Toggle sort.ascending - */ - }, { - key: "toggleSortOrder", - value: function toggleSortOrder() { - var sort = this.state.sort; - sort.ascending = !sort.ascending; - this.setState({ - sort: sort - }); + return href + "#" + (typeof to === "string" ? to : createPath(to)); + } + function validateHashLocation(location, to) { + warning(location.pathname.charAt(0) === "/", "relative pathnames are not supported in hash history.push(" + JSON.stringify(to) + ")"); + } + return getUrlBasedHistory(createHashLocation, createHashHref, validateHashLocation, options); +} +function invariant(value, message) { + if (value === false || value === null || typeof value === "undefined") { + throw new Error(message); + } +} +function warning(cond, message) { + if (!cond) { + // eslint-disable-next-line no-console + if (typeof console !== "undefined") console.warn(message); + try { + // Welcome to debugging history! + // + // This error is thrown as a convenience, so you can more easily + // find the source for a warning that appears in the console by + // enabling "pause on exceptions" in your JavaScript debugger. + throw new Error(message); + // eslint-disable-next-line no-empty + } catch (e) {} + } +} +function createKey() { + return Math.random().toString(36).substr(2, 8); +} +/** + * For browser-based histories, we combine the state and key into an object + */ +function getHistoryState(location, index) { + return { + usr: location.state, + key: location.key, + idx: index + }; +} +/** + * Creates a Location object with a unique key from the given Path + */ +function createLocation(current, to, state, key) { + if (state === void 0) { + state = null; + } + let location = _extends({ + pathname: typeof current === "string" ? current : current.pathname, + search: "", + hash: "" + }, typeof to === "string" ? parsePath(to) : to, { + state, + // TODO: This could be cleaned up. push/replace should probably just take + // full Locations now and avoid the need to run through this flow at all + // But that's a pretty big refactor to the current test suite so going to + // keep as is for the time being and just let any incoming keys take precedence + key: to && to.key || key || createKey() + }); + return location; +} +/** + * Creates a string URL path from the given pathname, search, and hash components. + */ +function createPath(_ref) { + let { + pathname = "/", + search = "", + hash = "" + } = _ref; + if (search && search !== "?") pathname += search.charAt(0) === "?" ? search : "?" + search; + if (hash && hash !== "#") pathname += hash.charAt(0) === "#" ? hash : "#" + hash; + return pathname; +} +/** + * Parses a string URL path into its separate pathname, search, and hash components. + */ +function parsePath(path) { + let parsedPath = {}; + if (path) { + let hashIndex = path.indexOf("#"); + if (hashIndex >= 0) { + parsedPath.hash = path.substr(hashIndex); + path = path.substr(0, hashIndex); } - - /** - * Updates page state - * - * @param {number} number - Number of page - */ - }, { - key: "updatePageNumber", - value: function updatePageNumber(number) { - var page = this.state.page; - page.number = number; - this.setState({ - page: page + let searchIndex = path.indexOf("?"); + if (searchIndex >= 0) { + parsedPath.search = path.substr(searchIndex); + path = path.substr(0, searchIndex); + } + if (path) { + parsedPath.pathname = path; + } + } + return parsedPath; +} +function getUrlBasedHistory(getLocation, createHref, validateLocation, options) { + if (options === void 0) { + options = {}; + } + let { + window = document.defaultView, + v5Compat = false + } = options; + let globalHistory = window.history; + let action = Action.Pop; + let listener = null; + let index = getIndex(); + // Index should only be null when we initialize. If not, it's because the + // user called history.pushState or history.replaceState directly, in which + // case we should log a warning as it will result in bugs. + if (index == null) { + index = 0; + globalHistory.replaceState(_extends({}, globalHistory.state, { + idx: index + }), ""); + } + function getIndex() { + let state = globalHistory.state || { + idx: null + }; + return state.idx; + } + function handlePop() { + action = Action.Pop; + let nextIndex = getIndex(); + let delta = nextIndex == null ? null : nextIndex - index; + index = nextIndex; + if (listener) { + listener({ + action, + location: history.location, + delta }); } - - /** - * Update number of rows per page - * - * @param {object} e - Event from which to abstract value - */ - }, { - key: "updatePageRows", - value: function updatePageRows(e) { - var page = Object.assign({}, this.state.page); - page.rows = e.target.value; - page.number = 1; - this.setState({ - page: page + } + function push(to, state) { + action = Action.Push; + let location = createLocation(history.location, to, state); + if (validateLocation) validateLocation(location, to); + index = getIndex() + 1; + let historyState = getHistoryState(location, index); + let url = history.createHref(location); + // try...catch because iOS limits us to 100 pushState calls :/ + try { + globalHistory.pushState(historyState, "", url); + } catch (error) { + // If the exception is because `state` can't be serialized, let that throw + // outwards just like a replace call would so the dev knows the cause + // https://html.spec.whatwg.org/multipage/nav-history-apis.html#shared-history-push/replace-state-steps + // https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeinternal + if (error instanceof DOMException && error.name === "DataCloneError") { + throw error; + } + // They are going to lose state here, but there is no real + // way to warn them about it since the page will refresh... + window.location.assign(url); + } + if (v5Compat && listener) { + listener({ + action, + location: history.location, + delta: 1 }); } - - /** - * Export the filtered rows and columns into a csv - * - * @param {number[]} filteredRowIndexes - The filtered Row Indexes - */ - }, { - key: "downloadCSV", - value: function downloadCSV(filteredRowIndexes) { - var _this2 = this; - var csvData = filteredRowIndexes.map(function (id) { - return _this2.props.data[id]; + } + function replace(to, state) { + action = Action.Replace; + let location = createLocation(history.location, to, state); + if (validateLocation) validateLocation(location, to); + index = getIndex(); + let historyState = getHistoryState(location, index); + let url = history.createHref(location); + globalHistory.replaceState(historyState, "", url); + if (v5Compat && listener) { + listener({ + action, + location: history.location, + delta: 0 }); - // Map cell data to proper values if applicable. - if (this.props.getMappedCell) { - csvData = csvData.map(function (row, i) { - return _this2.props.fields.flatMap(function (field, j) { - return _this2.props.getMappedCell(field.label, row[j], row, _this2.props.fields.map(function (val) { - return val.label; - }), j); - }); - }); + } + } + function createURL(to) { + // window.location.origin is "null" (the literal string value) in Firefox + // under certain conditions, notably when serving from a local HTML file + // See https://bugzilla.mozilla.org/show_bug.cgi?id=878297 + let base = window.location.origin !== "null" ? window.location.origin : window.location.href; + let href = typeof to === "string" ? to : createPath(to); + // Treating this as a full URL will strip any trailing spaces so we need to + // pre-encode them since they might be part of a matching splat param from + // an ancestor route + href = href.replace(/ $/, "%20"); + invariant(base, "No window.location.(origin|href) available to create URL for href: " + href); + return new URL(href, base); + } + let history = { + get action() { + return action; + }, + get location() { + return getLocation(window, globalHistory); + }, + listen(fn) { + if (listener) { + throw new Error("A history only accepts one active listener"); + } + window.addEventListener(PopStateEventType, handlePop); + listener = fn; + return () => { + window.removeEventListener(PopStateEventType, handlePop); + listener = null; + }; + }, + createHref(to) { + return createHref(window, to); + }, + createURL, + encodeLocation(to) { + // Encode a Location the same way window.location would + let url = createURL(to); + return { + pathname: url.pathname, + search: url.search, + hash: url.hash + }; + }, + push, + replace, + go(n) { + return globalHistory.go(n); + } + }; + return history; +} +//#endregion + +var ResultType; +(function (ResultType) { + ResultType["data"] = "data"; + ResultType["deferred"] = "deferred"; + ResultType["redirect"] = "redirect"; + ResultType["error"] = "error"; +})(ResultType || (ResultType = {})); +const immutableRouteKeys = new Set(["lazy", "caseSensitive", "path", "id", "index", "children"]); +function isIndexRoute(route) { + return route.index === true; +} +// Walk the route tree generating unique IDs where necessary, so we are working +// solely with AgnosticDataRouteObject's within the Router +function convertRoutesToDataRoutes(routes, mapRouteProperties, parentPath, manifest) { + if (parentPath === void 0) { + parentPath = []; + } + if (manifest === void 0) { + manifest = {}; + } + return routes.map((route, index) => { + let treePath = [...parentPath, String(index)]; + let id = typeof route.id === "string" ? route.id : treePath.join("-"); + invariant(route.index !== true || !route.children, "Cannot specify children on an index route"); + invariant(!manifest[id], "Found a route id collision on id \"" + id + "\". Route " + "id's must be globally unique within Data Router usages"); + if (isIndexRoute(route)) { + let indexRoute = _extends({}, route, mapRouteProperties(route), { + id + }); + manifest[id] = indexRoute; + return indexRoute; + } else { + let pathOrLayoutRoute = _extends({}, route, mapRouteProperties(route), { + id, + children: undefined + }); + manifest[id] = pathOrLayoutRoute; + if (route.children) { + pathOrLayoutRoute.children = convertRoutesToDataRoutes(route.children, mapRouteProperties, treePath, manifest); } - var csvworker = new Worker(loris.BaseURL + '/js/workers/savecsv.js'); - csvworker.addEventListener('message', function (e) { - var dataURL; - var dataDate; - var link; - if (e.data.cmd === 'SaveCSV') { - dataDate = new Date().toISOString(); - dataURL = window.URL.createObjectURL(e.data.message); - link = document.createElement('a'); - link.download = 'data-' + dataDate + '.csv'; - link.type = 'text/csv'; - link.href = dataURL; - document.body.appendChild(link); - $(link)[0].click(); - document.body.removeChild(link); - } + return pathOrLayoutRoute; + } + }); +} +/** + * Matches the given routes to a location and returns the match data. + * + * @see https://reactrouter.com/v6/utils/match-routes + */ +function matchRoutes(routes, locationArg, basename) { + if (basename === void 0) { + basename = "/"; + } + return matchRoutesImpl(routes, locationArg, basename, false); +} +function matchRoutesImpl(routes, locationArg, basename, allowPartial) { + let location = typeof locationArg === "string" ? parsePath(locationArg) : locationArg; + let pathname = stripBasename(location.pathname || "/", basename); + if (pathname == null) { + return null; + } + let branches = flattenRoutes(routes); + rankRouteBranches(branches); + let matches = null; + for (let i = 0; matches == null && i < branches.length; ++i) { + // Incoming pathnames are generally encoded from either window.location + // or from router.navigate, but we want to match against the unencoded + // paths in the route definitions. Memory router locations won't be + // encoded here but there also shouldn't be anything to decode so this + // should be a safe operation. This avoids needing matchRoutes to be + // history-aware. + let decoded = decodePath(pathname); + matches = matchRouteBranch(branches[i], decoded, allowPartial); + } + return matches; +} +function convertRouteMatchToUiMatch(match, loaderData) { + let { + route, + pathname, + params + } = match; + return { + id: route.id, + pathname, + params, + data: loaderData[route.id], + handle: route.handle + }; +} +function flattenRoutes(routes, branches, parentsMeta, parentPath) { + if (branches === void 0) { + branches = []; + } + if (parentsMeta === void 0) { + parentsMeta = []; + } + if (parentPath === void 0) { + parentPath = ""; + } + let flattenRoute = (route, index, relativePath) => { + let meta = { + relativePath: relativePath === undefined ? route.path || "" : relativePath, + caseSensitive: route.caseSensitive === true, + childrenIndex: index, + route + }; + if (meta.relativePath.startsWith("/")) { + invariant(meta.relativePath.startsWith(parentPath), "Absolute route path \"" + meta.relativePath + "\" nested under path " + ("\"" + parentPath + "\" is not valid. An absolute child route path ") + "must start with the combined path of all its parent routes."); + meta.relativePath = meta.relativePath.slice(parentPath.length); + } + let path = joinPaths([parentPath, meta.relativePath]); + let routesMeta = parentsMeta.concat(meta); + // Add the children before adding this route to the array, so we traverse the + // route tree depth-first and child routes appear before their parents in + // the "flattened" version. + if (route.children && route.children.length > 0) { + invariant( + // Our types know better, but runtime JS may not! + // @ts-expect-error + route.index !== true, "Index routes must not have child routes. Please remove " + ("all child routes from route path \"" + path + "\".")); + flattenRoutes(route.children, branches, routesMeta, path); + } + // Routes without a path shouldn't ever match by themselves unless they are + // index routes, so don't add them to the list of possible branches. + if (route.path == null && !route.index) { + return; + } + branches.push({ + path, + score: computeScore(path, route.index), + routesMeta + }); + }; + routes.forEach((route, index) => { + var _route$path; + // coarse-grain check for optional params + if (route.path === "" || !((_route$path = route.path) != null && _route$path.includes("?"))) { + flattenRoute(route, index); + } else { + for (let exploded of explodeOptionalSegments(route.path)) { + flattenRoute(route, index, exploded); + } + } + }); + return branches; +} +/** + * Computes all combinations of optional path segments for a given path, + * excluding combinations that are ambiguous and of lower priority. + * + * For example, `/one/:two?/three/:four?/:five?` explodes to: + * - `/one/three` + * - `/one/:two/three` + * - `/one/three/:four` + * - `/one/three/:five` + * - `/one/:two/three/:four` + * - `/one/:two/three/:five` + * - `/one/three/:four/:five` + * - `/one/:two/three/:four/:five` + */ +function explodeOptionalSegments(path) { + let segments = path.split("/"); + if (segments.length === 0) return []; + let [first, ...rest] = segments; + // Optional path segments are denoted by a trailing `?` + let isOptional = first.endsWith("?"); + // Compute the corresponding required segment: `foo?` -> `foo` + let required = first.replace(/\?$/, ""); + if (rest.length === 0) { + // Intepret empty string as omitting an optional segment + // `["one", "", "three"]` corresponds to omitting `:two` from `/one/:two?/three` -> `/one/three` + return isOptional ? [required, ""] : [required]; + } + let restExploded = explodeOptionalSegments(rest.join("/")); + let result = []; + // All child paths with the prefix. Do this for all children before the + // optional version for all children, so we get consistent ordering where the + // parent optional aspect is preferred as required. Otherwise, we can get + // child sections interspersed where deeper optional segments are higher than + // parent optional segments, where for example, /:two would explode _earlier_ + // then /:one. By always including the parent as required _for all children_ + // first, we avoid this issue + result.push(...restExploded.map(subpath => subpath === "" ? required : [required, subpath].join("/"))); + // Then, if this is an optional value, add all child versions without + if (isOptional) { + result.push(...restExploded); + } + // for absolute paths, ensure `/` instead of empty segment + return result.map(exploded => path.startsWith("/") && exploded === "" ? "/" : exploded); +} +function rankRouteBranches(branches) { + branches.sort((a, b) => a.score !== b.score ? b.score - a.score // Higher score first + : compareIndexes(a.routesMeta.map(meta => meta.childrenIndex), b.routesMeta.map(meta => meta.childrenIndex))); +} +const paramRe = /^:[\w-]+$/; +const dynamicSegmentValue = 3; +const indexRouteValue = 2; +const emptySegmentValue = 1; +const staticSegmentValue = 10; +const splatPenalty = -2; +const isSplat = s => s === "*"; +function computeScore(path, index) { + let segments = path.split("/"); + let initialScore = segments.length; + if (segments.some(isSplat)) { + initialScore += splatPenalty; + } + if (index) { + initialScore += indexRouteValue; + } + return segments.filter(s => !isSplat(s)).reduce((score, segment) => score + (paramRe.test(segment) ? dynamicSegmentValue : segment === "" ? emptySegmentValue : staticSegmentValue), initialScore); +} +function compareIndexes(a, b) { + let siblings = a.length === b.length && a.slice(0, -1).every((n, i) => n === b[i]); + return siblings ? + // If two routes are siblings, we should try to match the earlier sibling + // first. This allows people to have fine-grained control over the matching + // behavior by simply putting routes with identical paths in the order they + // want them tried. + a[a.length - 1] - b[b.length - 1] : + // Otherwise, it doesn't really make sense to rank non-siblings by index, + // so they sort equally. + 0; +} +function matchRouteBranch(branch, pathname, allowPartial) { + if (allowPartial === void 0) { + allowPartial = false; + } + let { + routesMeta + } = branch; + let matchedParams = {}; + let matchedPathname = "/"; + let matches = []; + for (let i = 0; i < routesMeta.length; ++i) { + let meta = routesMeta[i]; + let end = i === routesMeta.length - 1; + let remainingPathname = matchedPathname === "/" ? pathname : pathname.slice(matchedPathname.length) || "/"; + let match = matchPath({ + path: meta.relativePath, + caseSensitive: meta.caseSensitive, + end + }, remainingPathname); + let route = meta.route; + if (!match && end && allowPartial && !routesMeta[routesMeta.length - 1].route.index) { + match = matchPath({ + path: meta.relativePath, + caseSensitive: meta.caseSensitive, + end: false + }, remainingPathname); + } + if (!match) { + return null; + } + Object.assign(matchedParams, match.params); + matches.push({ + // TODO: Can this as be avoided? + params: matchedParams, + pathname: joinPaths([matchedPathname, match.pathname]), + pathnameBase: normalizePathname(joinPaths([matchedPathname, match.pathnameBase])), + route + }); + if (match.pathnameBase !== "/") { + matchedPathname = joinPaths([matchedPathname, match.pathnameBase]); + } + } + return matches; +} +/** + * Returns a path with params interpolated. + * + * @see https://reactrouter.com/v6/utils/generate-path + */ +function generatePath(originalPath, params) { + if (params === void 0) { + params = {}; + } + let path = originalPath; + if (path.endsWith("*") && path !== "*" && !path.endsWith("/*")) { + warning(false, "Route path \"" + path + "\" will be treated as if it were " + ("\"" + path.replace(/\*$/, "/*") + "\" because the `*` character must ") + "always follow a `/` in the pattern. To get rid of this warning, " + ("please change the route path to \"" + path.replace(/\*$/, "/*") + "\".")); + path = path.replace(/\*$/, "/*"); + } + // ensure `/` is added at the beginning if the path is absolute + const prefix = path.startsWith("/") ? "/" : ""; + const stringify = p => p == null ? "" : typeof p === "string" ? p : String(p); + const segments = path.split(/\/+/).map((segment, index, array) => { + const isLastSegment = index === array.length - 1; + // only apply the splat if it's the last segment + if (isLastSegment && segment === "*") { + const star = "*"; + // Apply the splat + return stringify(params[star]); + } + const keyMatch = segment.match(/^:([\w-]+)(\??)$/); + if (keyMatch) { + const [, key, optional] = keyMatch; + let param = params[key]; + invariant(optional === "?" || param != null, "Missing \":" + key + "\" param"); + return stringify(param); + } + // Remove any optional markers from optional static segments + return segment.replace(/\?$/g, ""); + }) + // Remove empty segments + .filter(segment => !!segment); + return prefix + segments.join("/"); +} +/** + * Performs pattern matching on a URL pathname and returns information about + * the match. + * + * @see https://reactrouter.com/v6/utils/match-path + */ +function matchPath(pattern, pathname) { + if (typeof pattern === "string") { + pattern = { + path: pattern, + caseSensitive: false, + end: true + }; + } + let [matcher, compiledParams] = compilePath(pattern.path, pattern.caseSensitive, pattern.end); + let match = pathname.match(matcher); + if (!match) return null; + let matchedPathname = match[0]; + let pathnameBase = matchedPathname.replace(/(.)\/+$/, "$1"); + let captureGroups = match.slice(1); + let params = compiledParams.reduce((memo, _ref, index) => { + let { + paramName, + isOptional + } = _ref; + // We need to compute the pathnameBase here using the raw splat value + // instead of using params["*"] later because it will be decoded then + if (paramName === "*") { + let splatValue = captureGroups[index] || ""; + pathnameBase = matchedPathname.slice(0, matchedPathname.length - splatValue.length).replace(/(.)\/+$/, "$1"); + } + const value = captureGroups[index]; + if (isOptional && !value) { + memo[paramName] = undefined; + } else { + memo[paramName] = (value || "").replace(/%2F/g, "/"); + } + return memo; + }, {}); + return { + params, + pathname: matchedPathname, + pathnameBase, + pattern + }; +} +function compilePath(path, caseSensitive, end) { + if (caseSensitive === void 0) { + caseSensitive = false; + } + if (end === void 0) { + end = true; + } + warning(path === "*" || !path.endsWith("*") || path.endsWith("/*"), "Route path \"" + path + "\" will be treated as if it were " + ("\"" + path.replace(/\*$/, "/*") + "\" because the `*` character must ") + "always follow a `/` in the pattern. To get rid of this warning, " + ("please change the route path to \"" + path.replace(/\*$/, "/*") + "\".")); + let params = []; + let regexpSource = "^" + path.replace(/\/*\*?$/, "") // Ignore trailing / and /*, we'll handle it below + .replace(/^\/*/, "/") // Make sure it has a leading / + .replace(/[\\.*+^${}|()[\]]/g, "\\$&") // Escape special regex chars + .replace(/\/:([\w-]+)(\?)?/g, (_, paramName, isOptional) => { + params.push({ + paramName, + isOptional: isOptional != null + }); + return isOptional ? "/?([^\\/]+)?" : "/([^\\/]+)"; + }); + if (path.endsWith("*")) { + params.push({ + paramName: "*" + }); + regexpSource += path === "*" || path === "/*" ? "(.*)$" // Already matched the initial /, just match the rest + : "(?:\\/(.+)|\\/*)$"; // Don't include the / in params["*"] + } else if (end) { + // When matching to the end, ignore trailing slashes + regexpSource += "\\/*$"; + } else if (path !== "" && path !== "/") { + // If our path is non-empty and contains anything beyond an initial slash, + // then we have _some_ form of path in our regex, so we should expect to + // match only if we find the end of this path segment. Look for an optional + // non-captured trailing slash (to match a portion of the URL) or the end + // of the path (if we've matched to the end). We used to do this with a + // word boundary but that gives false positives on routes like + // /user-preferences since `-` counts as a word boundary. + regexpSource += "(?:(?=\\/|$))"; + } else ; + let matcher = new RegExp(regexpSource, caseSensitive ? undefined : "i"); + return [matcher, params]; +} +function decodePath(value) { + try { + return value.split("/").map(v => decodeURIComponent(v).replace(/\//g, "%2F")).join("/"); + } catch (error) { + warning(false, "The URL path \"" + value + "\" could not be decoded because it is is a " + "malformed URL segment. This is probably due to a bad percent " + ("encoding (" + error + ").")); + return value; + } +} +/** + * @private + */ +function stripBasename(pathname, basename) { + if (basename === "/") return pathname; + if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) { + return null; + } + // We want to leave trailing slash behavior in the user's control, so if they + // specify a basename with a trailing slash, we should support it + let startIndex = basename.endsWith("/") ? basename.length - 1 : basename.length; + let nextChar = pathname.charAt(startIndex); + if (nextChar && nextChar !== "/") { + // pathname does not start with basename/ + return null; + } + return pathname.slice(startIndex) || "/"; +} +/** + * Returns a resolved path object relative to the given pathname. + * + * @see https://reactrouter.com/v6/utils/resolve-path + */ +function resolvePath(to, fromPathname) { + if (fromPathname === void 0) { + fromPathname = "/"; + } + let { + pathname: toPathname, + search = "", + hash = "" + } = typeof to === "string" ? parsePath(to) : to; + let pathname = toPathname ? toPathname.startsWith("/") ? toPathname : resolvePathname(toPathname, fromPathname) : fromPathname; + return { + pathname, + search: normalizeSearch(search), + hash: normalizeHash(hash) + }; +} +function resolvePathname(relativePath, fromPathname) { + let segments = fromPathname.replace(/\/+$/, "").split("/"); + let relativeSegments = relativePath.split("/"); + relativeSegments.forEach(segment => { + if (segment === "..") { + // Keep the root "" segment so the pathname starts at / + if (segments.length > 1) segments.pop(); + } else if (segment !== ".") { + segments.push(segment); + } + }); + return segments.length > 1 ? segments.join("/") : "/"; +} +function getInvalidPathError(char, field, dest, path) { + return "Cannot include a '" + char + "' character in a manually specified " + ("`to." + field + "` field [" + JSON.stringify(path) + "]. Please separate it out to the ") + ("`to." + dest + "` field. Alternatively you may provide the full path as ") + "a string in and the router will parse it for you."; +} +/** + * @private + * + * When processing relative navigation we want to ignore ancestor routes that + * do not contribute to the path, such that index/pathless layout routes don't + * interfere. + * + * For example, when moving a route element into an index route and/or a + * pathless layout route, relative link behavior contained within should stay + * the same. Both of the following examples should link back to the root: + * + * + * + * + * + * + * + * }> // <-- Does not contribute + * // <-- Does not contribute + * + * + */ +function getPathContributingMatches(matches) { + return matches.filter((match, index) => index === 0 || match.route.path && match.route.path.length > 0); +} +// Return the array of pathnames for the current route matches - used to +// generate the routePathnames input for resolveTo() +function getResolveToMatches(matches, v7_relativeSplatPath) { + let pathMatches = getPathContributingMatches(matches); + // When v7_relativeSplatPath is enabled, use the full pathname for the leaf + // match so we include splat values for "." links. See: + // https://github.com/remix-run/react-router/issues/11052#issuecomment-1836589329 + if (v7_relativeSplatPath) { + return pathMatches.map((match, idx) => idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase); + } + return pathMatches.map(match => match.pathnameBase); +} +/** + * @private + */ +function resolveTo(toArg, routePathnames, locationPathname, isPathRelative) { + if (isPathRelative === void 0) { + isPathRelative = false; + } + let to; + if (typeof toArg === "string") { + to = parsePath(toArg); + } else { + to = _extends({}, toArg); + invariant(!to.pathname || !to.pathname.includes("?"), getInvalidPathError("?", "pathname", "search", to)); + invariant(!to.pathname || !to.pathname.includes("#"), getInvalidPathError("#", "pathname", "hash", to)); + invariant(!to.search || !to.search.includes("#"), getInvalidPathError("#", "search", "hash", to)); + } + let isEmptyPath = toArg === "" || to.pathname === ""; + let toPathname = isEmptyPath ? "/" : to.pathname; + let from; + // Routing is relative to the current pathname if explicitly requested. + // + // If a pathname is explicitly provided in `to`, it should be relative to the + // route context. This is explained in `Note on `` values` in our + // migration guide from v5 as a means of disambiguation between `to` values + // that begin with `/` and those that do not. However, this is problematic for + // `to` values that do not provide a pathname. `to` can simply be a search or + // hash string, in which case we should assume that the navigation is relative + // to the current location's pathname and *not* the route pathname. + if (toPathname == null) { + from = locationPathname; + } else { + let routePathnameIndex = routePathnames.length - 1; + // With relative="route" (the default), each leading .. segment means + // "go up one route" instead of "go up one URL segment". This is a key + // difference from how works and a major reason we call this a + // "to" value instead of a "href". + if (!isPathRelative && toPathname.startsWith("..")) { + let toSegments = toPathname.split("/"); + while (toSegments[0] === "..") { + toSegments.shift(); + routePathnameIndex -= 1; + } + to.pathname = toSegments.join("/"); + } + from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/"; + } + let path = resolvePath(to, from); + // Ensure the pathname has a trailing slash if the original "to" had one + let hasExplicitTrailingSlash = toPathname && toPathname !== "/" && toPathname.endsWith("/"); + // Or if this was a link to the current path which has a trailing slash + let hasCurrentTrailingSlash = (isEmptyPath || toPathname === ".") && locationPathname.endsWith("/"); + if (!path.pathname.endsWith("/") && (hasExplicitTrailingSlash || hasCurrentTrailingSlash)) { + path.pathname += "/"; + } + return path; +} +/** + * @private + */ +function getToPathname(to) { + // Empty strings should be treated the same as / paths + return to === "" || to.pathname === "" ? "/" : typeof to === "string" ? parsePath(to).pathname : to.pathname; +} +/** + * @private + */ +const joinPaths = paths => paths.join("/").replace(/\/\/+/g, "/"); +/** + * @private + */ +const normalizePathname = pathname => pathname.replace(/\/+$/, "").replace(/^\/*/, "/"); +/** + * @private + */ +const normalizeSearch = search => !search || search === "?" ? "" : search.startsWith("?") ? search : "?" + search; +/** + * @private + */ +const normalizeHash = hash => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash; +/** + * This is a shortcut for creating `application/json` responses. Converts `data` + * to JSON and sets the `Content-Type` header. + * + * @deprecated The `json` method is deprecated in favor of returning raw objects. + * This method will be removed in v7. + */ +const json = function json(data, init) { + if (init === void 0) { + init = {}; + } + let responseInit = typeof init === "number" ? { + status: init + } : init; + let headers = new Headers(responseInit.headers); + if (!headers.has("Content-Type")) { + headers.set("Content-Type", "application/json; charset=utf-8"); + } + return new Response(JSON.stringify(data), _extends({}, responseInit, { + headers + })); +}; +class DataWithResponseInit { + constructor(data, init) { + this.type = "DataWithResponseInit"; + this.data = data; + this.init = init || null; + } +} +/** + * Create "responses" that contain `status`/`headers` without forcing + * serialization into an actual `Response` - used by Remix single fetch + */ +function data(data, init) { + return new DataWithResponseInit(data, typeof init === "number" ? { + status: init + } : init); +} +class AbortedDeferredError extends Error {} +class DeferredData { + constructor(data, responseInit) { + this.pendingKeysSet = new Set(); + this.subscribers = new Set(); + this.deferredKeys = []; + invariant(data && typeof data === "object" && !Array.isArray(data), "defer() only accepts plain objects"); + // Set up an AbortController + Promise we can race against to exit early + // cancellation + let reject; + this.abortPromise = new Promise((_, r) => reject = r); + this.controller = new AbortController(); + let onAbort = () => reject(new AbortedDeferredError("Deferred data aborted")); + this.unlistenAbortSignal = () => this.controller.signal.removeEventListener("abort", onAbort); + this.controller.signal.addEventListener("abort", onAbort); + this.data = Object.entries(data).reduce((acc, _ref2) => { + let [key, value] = _ref2; + return Object.assign(acc, { + [key]: this.trackPromise(key, value) }); - var headerList = this.props.fields.map(function (field) { - return field.label; + }, {}); + if (this.done) { + // All incoming values were resolved + this.unlistenAbortSignal(); + } + this.init = responseInit; + } + trackPromise(key, value) { + if (!(value instanceof Promise)) { + return value; + } + this.deferredKeys.push(key); + this.pendingKeysSet.add(key); + // We store a little wrapper promise that will be extended with + // _data/_error props upon resolve/reject + let promise = Promise.race([value, this.abortPromise]).then(data => this.onSettle(promise, key, undefined, data), error => this.onSettle(promise, key, error)); + // Register rejection listeners to avoid uncaught promise rejections on + // errors or aborted deferred values + promise.catch(() => {}); + Object.defineProperty(promise, "_tracked", { + get: () => true + }); + return promise; + } + onSettle(promise, key, error, data) { + if (this.controller.signal.aborted && error instanceof AbortedDeferredError) { + this.unlistenAbortSignal(); + Object.defineProperty(promise, "_error", { + get: () => error }); - csvworker.postMessage({ - cmd: 'SaveFile', - data: csvData, - headers: headerList, - identifiers: this.props.RowNameMap + return Promise.reject(error); + } + this.pendingKeysSet.delete(key); + if (this.done) { + // Nothing left to abort! + this.unlistenAbortSignal(); + } + // If the promise was resolved/rejected with undefined, we'll throw an error as you + // should always resolve with a value or null + if (error === undefined && data === undefined) { + let undefinedError = new Error("Deferred data for key \"" + key + "\" resolved/rejected with `undefined`, " + "you must resolve/reject with a value or `null`."); + Object.defineProperty(promise, "_error", { + get: () => undefinedError }); + this.emit(false, key); + return Promise.reject(undefinedError); } - - /** - * Get the Filtered Row Indexes - */ - }, { - key: "getFilteredRowIndexes", - value: function getFilteredRowIndexes() { - var useKeyword = false; - var filterValuesCount = Object.keys(this.props.filters).length; - var tableData = this.props.data; - var fieldData = this.props.fields; - var filteredIndexes = []; - - // If there are no filters set, use all the data. - var hasFilters = filterValuesCount !== 0; - if (hasFilters === false) { - for (var i = 0; i < tableData.length; i++) { - filteredIndexes.push(i); - } - return filteredIndexes; - } - if (this.props.filters.keyword) { - useKeyword = true; - } - if (useKeyword) { - filterValuesCount -= 1; - } - for (var _i = 0; _i < tableData.length; _i++) { - var headerCount = 0; - var keywordMatch = 0; - for (var j = 0; j < fieldData.length; j++) { - var data = tableData[_i] ? tableData[_i][j] : null; - if (this.hasFilterKeyword((fieldData[j].filter || {}).name, data)) { - headerCount++; - } - if (useKeyword) { - if (this.hasFilterKeyword('keyword', data)) { - keywordMatch++; - } + if (data === undefined) { + Object.defineProperty(promise, "_error", { + get: () => error + }); + this.emit(false, key); + return Promise.reject(error); + } + Object.defineProperty(promise, "_data", { + get: () => data + }); + this.emit(false, key); + return data; + } + emit(aborted, settledKey) { + this.subscribers.forEach(subscriber => subscriber(aborted, settledKey)); + } + subscribe(fn) { + this.subscribers.add(fn); + return () => this.subscribers.delete(fn); + } + cancel() { + this.controller.abort(); + this.pendingKeysSet.forEach((v, k) => this.pendingKeysSet.delete(k)); + this.emit(true); + } + async resolveData(signal) { + let aborted = false; + if (!this.done) { + let onAbort = () => this.cancel(); + signal.addEventListener("abort", onAbort); + aborted = await new Promise(resolve => { + this.subscribe(aborted => { + signal.removeEventListener("abort", onAbort); + if (aborted || this.done) { + resolve(aborted); } - } - if (headerCount === filterValuesCount && (useKeyword === true && keywordMatch > 0 || useKeyword === false && keywordMatch === 0)) { - filteredIndexes.push(_i); - } - } - return filteredIndexes; + }); + }); } - - /** - * Sort the given rows according to the sort configuration - * - * @param {number[]} rowIndexes - The row indexes - * @return {object[]} - */ - }, { - key: "sortRows", - value: function sortRows(rowIndexes) { - var _this3 = this; - var index = []; - for (var i = 0; i < rowIndexes.length; i++) { - var idx = rowIndexes[i]; - var val = this.props.data[idx][this.state.sort.column] || undefined; - - // If sortColumn is equal to default No. column, set value to be - // index + 1 - if (this.state.sort.column === -1) { - val = idx + 1; - } - var isString = typeof val === 'string' || val instanceof String; - var isNumber = !isNaN(val) && (0, _typeof2["default"])(val) !== 'object'; - if (val === '.') { - // hack to handle non-existent items in DQT - val = null; - } else if (isNumber) { - // perform type conversion (from string to int/float) - val = Number(val); - } else if (isString) { - // if string with text convert to lowercase - val = val.toLowerCase(); - } else if (Array.isArray(val)) { - val = val.join(', '); - } else { - val = undefined; - } - if (this.props.RowNameMap) { - index.push({ - RowIdx: idx, - Value: val, - Content: this.props.RowNameMap[idx] - }); - } else { - index.push({ - RowIdx: idx, - Value: val, - Content: idx + 1 - }); - } + return aborted; + } + get done() { + return this.pendingKeysSet.size === 0; + } + get unwrappedData() { + invariant(this.data !== null && this.done, "Can only unwrap data on initialized and settled deferreds"); + return Object.entries(this.data).reduce((acc, _ref3) => { + let [key, value] = _ref3; + return Object.assign(acc, { + [key]: unwrapTrackedPromise(value) + }); + }, {}); + } + get pendingKeys() { + return Array.from(this.pendingKeysSet); + } +} +function isTrackedPromise(value) { + return value instanceof Promise && value._tracked === true; +} +function unwrapTrackedPromise(value) { + if (!isTrackedPromise(value)) { + return value; + } + if (value._error) { + throw value._error; + } + return value._data; +} +/** + * @deprecated The `defer` method is deprecated in favor of returning raw + * objects. This method will be removed in v7. + */ +const defer = function defer(data, init) { + if (init === void 0) { + init = {}; + } + let responseInit = typeof init === "number" ? { + status: init + } : init; + return new DeferredData(data, responseInit); +}; +/** + * A redirect response. Sets the status code and the `Location` header. + * Defaults to "302 Found". + */ +const redirect = function redirect(url, init) { + if (init === void 0) { + init = 302; + } + let responseInit = init; + if (typeof responseInit === "number") { + responseInit = { + status: responseInit + }; + } else if (typeof responseInit.status === "undefined") { + responseInit.status = 302; + } + let headers = new Headers(responseInit.headers); + headers.set("Location", url); + return new Response(null, _extends({}, responseInit, { + headers + })); +}; +/** + * A redirect response that will force a document reload to the new location. + * Sets the status code and the `Location` header. + * Defaults to "302 Found". + */ +const redirectDocument = (url, init) => { + let response = redirect(url, init); + response.headers.set("X-Remix-Reload-Document", "true"); + return response; +}; +/** + * A redirect response that will perform a `history.replaceState` instead of a + * `history.pushState` for client-side navigation redirects. + * Sets the status code and the `Location` header. + * Defaults to "302 Found". + */ +const replace = (url, init) => { + let response = redirect(url, init); + response.headers.set("X-Remix-Replace", "true"); + return response; +}; +/** + * @private + * Utility class we use to hold auto-unwrapped 4xx/5xx Response bodies + * + * We don't export the class for public use since it's an implementation + * detail, but we export the interface above so folks can build their own + * abstractions around instances via isRouteErrorResponse() + */ +class ErrorResponseImpl { + constructor(status, statusText, data, internal) { + if (internal === void 0) { + internal = false; + } + this.status = status; + this.statusText = statusText || ""; + this.internal = internal; + if (data instanceof Error) { + this.data = data.toString(); + this.error = data; + } else { + this.data = data; + } + } +} +/** + * Check if the given error is an ErrorResponse generated from a 4xx/5xx + * Response thrown from an action/loader + */ +function isRouteErrorResponse(error) { + return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error; +} + +const validMutationMethodsArr = ["post", "put", "patch", "delete"]; +const validMutationMethods = new Set(validMutationMethodsArr); +const validRequestMethodsArr = ["get", ...validMutationMethodsArr]; +const validRequestMethods = new Set(validRequestMethodsArr); +const redirectStatusCodes = new Set([301, 302, 303, 307, 308]); +const redirectPreserveMethodStatusCodes = new Set([307, 308]); +const IDLE_NAVIGATION = { + state: "idle", + location: undefined, + formMethod: undefined, + formAction: undefined, + formEncType: undefined, + formData: undefined, + json: undefined, + text: undefined +}; +const IDLE_FETCHER = { + state: "idle", + data: undefined, + formMethod: undefined, + formAction: undefined, + formEncType: undefined, + formData: undefined, + json: undefined, + text: undefined +}; +const IDLE_BLOCKER = { + state: "unblocked", + proceed: undefined, + reset: undefined, + location: undefined +}; +const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i; +const defaultMapRouteProperties = route => ({ + hasErrorBoundary: Boolean(route.hasErrorBoundary) +}); +const TRANSITIONS_STORAGE_KEY = "remix-router-transitions"; +//#endregion +//////////////////////////////////////////////////////////////////////////////// +//#region createRouter +//////////////////////////////////////////////////////////////////////////////// +/** + * Create a router and listen to history POP navigations + */ +function createRouter(init) { + const routerWindow = init.window ? init.window : typeof window !== "undefined" ? window : undefined; + const isBrowser = typeof routerWindow !== "undefined" && typeof routerWindow.document !== "undefined" && typeof routerWindow.document.createElement !== "undefined"; + const isServer = !isBrowser; + invariant(init.routes.length > 0, "You must provide a non-empty routes array to createRouter"); + let mapRouteProperties; + if (init.mapRouteProperties) { + mapRouteProperties = init.mapRouteProperties; + } else if (init.detectErrorBoundary) { + // If they are still using the deprecated version, wrap it with the new API + let detectErrorBoundary = init.detectErrorBoundary; + mapRouteProperties = route => ({ + hasErrorBoundary: detectErrorBoundary(route) + }); + } else { + mapRouteProperties = defaultMapRouteProperties; + } + // Routes keyed by ID + let manifest = {}; + // Routes in tree format for matching + let dataRoutes = convertRoutesToDataRoutes(init.routes, mapRouteProperties, undefined, manifest); + let inFlightDataRoutes; + let basename = init.basename || "/"; + let dataStrategyImpl = init.dataStrategy || defaultDataStrategy; + let patchRoutesOnNavigationImpl = init.patchRoutesOnNavigation; + // Config driven behavior flags + let future = _extends({ + v7_fetcherPersist: false, + v7_normalizeFormMethod: false, + v7_partialHydration: false, + v7_prependBasename: false, + v7_relativeSplatPath: false, + v7_skipActionErrorRevalidation: false + }, init.future); + // Cleanup function for history + let unlistenHistory = null; + // Externally-provided functions to call on all state changes + let subscribers = new Set(); + // Externally-provided object to hold scroll restoration locations during routing + let savedScrollPositions = null; + // Externally-provided function to get scroll restoration keys + let getScrollRestorationKey = null; + // Externally-provided function to get current scroll position + let getScrollPosition = null; + // One-time flag to control the initial hydration scroll restoration. Because + // we don't get the saved positions from until _after_ + // the initial render, we need to manually trigger a separate updateState to + // send along the restoreScrollPosition + // Set to true if we have `hydrationData` since we assume we were SSR'd and that + // SSR did the initial scroll restoration. + let initialScrollRestored = init.hydrationData != null; + let initialMatches = matchRoutes(dataRoutes, init.history.location, basename); + let initialErrors = null; + if (initialMatches == null && !patchRoutesOnNavigationImpl) { + // If we do not match a user-provided-route, fall back to the root + // to allow the error boundary to take over + let error = getInternalRouterError(404, { + pathname: init.history.location.pathname + }); + let { + matches, + route + } = getShortCircuitMatches(dataRoutes); + initialMatches = matches; + initialErrors = { + [route.id]: error + }; + } + // In SPA apps, if the user provided a patchRoutesOnNavigation implementation and + // our initial match is a splat route, clear them out so we run through lazy + // discovery on hydration in case there's a more accurate lazy route match. + // In SSR apps (with `hydrationData`), we expect that the server will send + // up the proper matched routes so we don't want to run lazy discovery on + // initial hydration and want to hydrate into the splat route. + if (initialMatches && !init.hydrationData) { + let fogOfWar = checkFogOfWar(initialMatches, dataRoutes, init.history.location.pathname); + if (fogOfWar.active) { + initialMatches = null; + } + } + let initialized; + if (!initialMatches) { + initialized = false; + initialMatches = []; + // If partial hydration and fog of war is enabled, we will be running + // `patchRoutesOnNavigation` during hydration so include any partial matches as + // the initial matches so we can properly render `HydrateFallback`'s + if (future.v7_partialHydration) { + let fogOfWar = checkFogOfWar(null, dataRoutes, init.history.location.pathname); + if (fogOfWar.active && fogOfWar.matches) { + initialMatches = fogOfWar.matches; + } + } + } else if (initialMatches.some(m => m.route.lazy)) { + // All initialMatches need to be loaded before we're ready. If we have lazy + // functions around still then we'll need to run them in initialize() + initialized = false; + } else if (!initialMatches.some(m => m.route.loader)) { + // If we've got no loaders to run, then we're good to go + initialized = true; + } else if (future.v7_partialHydration) { + // If partial hydration is enabled, we're initialized so long as we were + // provided with hydrationData for every route with a loader, and no loaders + // were marked for explicit hydration + let loaderData = init.hydrationData ? init.hydrationData.loaderData : null; + let errors = init.hydrationData ? init.hydrationData.errors : null; + // If errors exist, don't consider routes below the boundary + if (errors) { + let idx = initialMatches.findIndex(m => errors[m.route.id] !== undefined); + initialized = initialMatches.slice(0, idx + 1).every(m => !shouldLoadRouteOnHydration(m.route, loaderData, errors)); + } else { + initialized = initialMatches.every(m => !shouldLoadRouteOnHydration(m.route, loaderData, errors)); + } + } else { + // Without partial hydration - we're initialized if we were provided any + // hydrationData - which is expected to be complete + initialized = init.hydrationData != null; + } + let router; + let state = { + historyAction: init.history.action, + location: init.history.location, + matches: initialMatches, + initialized, + navigation: IDLE_NAVIGATION, + // Don't restore on initial updateState() if we were SSR'd + restoreScrollPosition: init.hydrationData != null ? false : null, + preventScrollReset: false, + revalidation: "idle", + loaderData: init.hydrationData && init.hydrationData.loaderData || {}, + actionData: init.hydrationData && init.hydrationData.actionData || null, + errors: init.hydrationData && init.hydrationData.errors || initialErrors, + fetchers: new Map(), + blockers: new Map() + }; + // -- Stateful internal variables to manage navigations -- + // Current navigation in progress (to be committed in completeNavigation) + let pendingAction = Action.Pop; + // Should the current navigation prevent the scroll reset if scroll cannot + // be restored? + let pendingPreventScrollReset = false; + // AbortController for the active navigation + let pendingNavigationController; + // Should the current navigation enable document.startViewTransition? + let pendingViewTransitionEnabled = false; + // Store applied view transitions so we can apply them on POP + let appliedViewTransitions = new Map(); + // Cleanup function for persisting applied transitions to sessionStorage + let removePageHideEventListener = null; + // We use this to avoid touching history in completeNavigation if a + // revalidation is entirely uninterrupted + let isUninterruptedRevalidation = false; + // Use this internal flag to force revalidation of all loaders: + // - submissions (completed or interrupted) + // - useRevalidator() + // - X-Remix-Revalidate (from redirect) + let isRevalidationRequired = false; + // Use this internal array to capture routes that require revalidation due + // to a cancelled deferred on action submission + let cancelledDeferredRoutes = []; + // Use this internal array to capture fetcher loads that were cancelled by an + // action navigation and require revalidation + let cancelledFetcherLoads = new Set(); + // AbortControllers for any in-flight fetchers + let fetchControllers = new Map(); + // Track loads based on the order in which they started + let incrementingLoadId = 0; + // Track the outstanding pending navigation data load to be compared against + // the globally incrementing load when a fetcher load lands after a completed + // navigation + let pendingNavigationLoadId = -1; + // Fetchers that triggered data reloads as a result of their actions + let fetchReloadIds = new Map(); + // Fetchers that triggered redirect navigations + let fetchRedirectIds = new Set(); + // Most recent href/match for fetcher.load calls for fetchers + let fetchLoadMatches = new Map(); + // Ref-count mounted fetchers so we know when it's ok to clean them up + let activeFetchers = new Map(); + // Fetchers that have requested a delete when using v7_fetcherPersist, + // they'll be officially removed after they return to idle + let deletedFetchers = new Set(); + // Store DeferredData instances for active route matches. When a + // route loader returns defer() we stick one in here. Then, when a nested + // promise resolves we update loaderData. If a new navigation starts we + // cancel active deferreds for eliminated routes. + let activeDeferreds = new Map(); + // Store blocker functions in a separate Map outside of router state since + // we don't need to update UI state if they change + let blockerFunctions = new Map(); + // Flag to ignore the next history update, so we can revert the URL change on + // a POP navigation that was blocked by the user without touching router state + let unblockBlockerHistoryUpdate = undefined; + // Initialize the router, all side effects should be kicked off from here. + // Implemented as a Fluent API for ease of: + // let router = createRouter(init).initialize(); + function initialize() { + // If history informs us of a POP navigation, start the navigation but do not update + // state. We'll update our own state once the navigation completes + unlistenHistory = init.history.listen(_ref => { + let { + action: historyAction, + location, + delta + } = _ref; + // Ignore this event if it was just us resetting the URL from a + // blocked POP navigation + if (unblockBlockerHistoryUpdate) { + unblockBlockerHistoryUpdate(); + unblockBlockerHistoryUpdate = undefined; + return; } - index.sort(function (a, b) { - if (_this3.state.sort.ascending) { - if (a.Value === b.Value) { - // If all values are equal, sort by rownum - if (a.RowIdx < b.RowIdx) return -1; - if (a.RowIdx > b.RowIdx) return 1; + warning(blockerFunctions.size === 0 || delta != null, "You are trying to use a blocker on a POP navigation to a location " + "that was not created by @remix-run/router. This will fail silently in " + "production. This can happen if you are navigating outside the router " + "via `window.history.pushState`/`window.location.hash` instead of using " + "router navigation APIs. This can also happen if you are using " + "createHashRouter and the user manually changes the URL."); + let blockerKey = shouldBlockNavigation({ + currentLocation: state.location, + nextLocation: location, + historyAction + }); + if (blockerKey && delta != null) { + // Restore the URL to match the current UI, but don't update router state + let nextHistoryUpdatePromise = new Promise(resolve => { + unblockBlockerHistoryUpdate = resolve; + }); + init.history.go(delta * -1); + // Put the blocker into a blocked state + updateBlocker(blockerKey, { + state: "blocked", + location, + proceed() { + updateBlocker(blockerKey, { + state: "proceeding", + proceed: undefined, + reset: undefined, + location + }); + // Re-do the same POP navigation we just blocked, after the url + // restoration is also complete. See: + // https://github.com/remix-run/react-router/issues/11613 + nextHistoryUpdatePromise.then(() => init.history.go(delta)); + }, + reset() { + let blockers = new Map(state.blockers); + blockers.set(blockerKey, IDLE_BLOCKER); + updateState({ + blockers + }); } - // Check if null values - if (a.Value === null || typeof a.Value === 'undefined') return -1; - if (b.Value === null || typeof b.Value === 'undefined') return 1; - - // Sort by value - if (a.Value < b.Value) return -1; - if (a.Value > b.Value) return 1; - } else { - if (a.Value === b.Value) { - // If all values are equal, sort by rownum - if (a.RowIdx < b.RowIdx) return 1; - if (a.RowIdx > b.RowIdx) return -1; + }); + return; + } + return startNavigation(historyAction, location); + }); + if (isBrowser) { + // FIXME: This feels gross. How can we cleanup the lines between + // scrollRestoration/appliedTransitions persistance? + restoreAppliedTransitions(routerWindow, appliedViewTransitions); + let _saveAppliedTransitions = () => persistAppliedTransitions(routerWindow, appliedViewTransitions); + routerWindow.addEventListener("pagehide", _saveAppliedTransitions); + removePageHideEventListener = () => routerWindow.removeEventListener("pagehide", _saveAppliedTransitions); + } + // Kick off initial data load if needed. Use Pop to avoid modifying history + // Note we don't do any handling of lazy here. For SPA's it'll get handled + // in the normal navigation flow. For SSR it's expected that lazy modules are + // resolved prior to router creation since we can't go into a fallbackElement + // UI for SSR'd apps + if (!state.initialized) { + startNavigation(Action.Pop, state.location, { + initialHydration: true + }); + } + return router; + } + // Clean up a router and it's side effects + function dispose() { + if (unlistenHistory) { + unlistenHistory(); + } + if (removePageHideEventListener) { + removePageHideEventListener(); + } + subscribers.clear(); + pendingNavigationController && pendingNavigationController.abort(); + state.fetchers.forEach((_, key) => deleteFetcher(key)); + state.blockers.forEach((_, key) => deleteBlocker(key)); + } + // Subscribe to state updates for the router + function subscribe(fn) { + subscribers.add(fn); + return () => subscribers.delete(fn); + } + // Update our state and notify the calling context of the change + function updateState(newState, opts) { + if (opts === void 0) { + opts = {}; + } + state = _extends({}, state, newState); + // Prep fetcher cleanup so we can tell the UI which fetcher data entries + // can be removed + let completedFetchers = []; + let deletedFetchersKeys = []; + if (future.v7_fetcherPersist) { + state.fetchers.forEach((fetcher, key) => { + if (fetcher.state === "idle") { + if (deletedFetchers.has(key)) { + // Unmounted from the UI and can be totally removed + deletedFetchersKeys.push(key); + } else { + // Returned to idle but still mounted in the UI, so semi-remains for + // revalidations and such + completedFetchers.push(key); } - // Check if null values - if (a.Value === null || typeof a.Value === 'undefined') return 1; - if (b.Value === null || typeof b.Value === 'undefined') return -1; - - // Sort by value - if (a.Value < b.Value) return 1; - if (a.Value > b.Value) return -1; } - // They're equal.. - return 0; }); - return index; } - - /** - * Searches for the filter keyword in the column cell - * - * Note: Search is case-insensitive. - * - * @param {string} name field name - * @param {string} data search string - * @return {boolean} true, if filter value is found to be a substring - * of one of the column values, false otherwise. - */ - }, { - key: "hasFilterKeyword", - value: function hasFilterKeyword(name, data) { - var filterData = null; - var exactMatch = false; - var opposite = false; - var result = false; - var searchKey = null; - var searchString = null; - if (this.props.filters[name]) { - filterData = this.props.filters[name].value; - exactMatch = this.props.filters[name].exactMatch; - opposite = this.props.filters[name].opposite; + // Iterate over a local copy so that if flushSync is used and we end up + // removing and adding a new subscriber due to the useCallback dependencies, + // we don't get ourselves into a loop calling the new subscriber immediately + [...subscribers].forEach(subscriber => subscriber(state, { + deletedFetchers: deletedFetchersKeys, + viewTransitionOpts: opts.viewTransitionOpts, + flushSync: opts.flushSync === true + })); + // Remove idle fetchers from state since we only care about in-flight fetchers. + if (future.v7_fetcherPersist) { + completedFetchers.forEach(key => state.fetchers.delete(key)); + deletedFetchersKeys.forEach(key => deleteFetcher(key)); + } + } + // Complete a navigation returning the state.navigation back to the IDLE_NAVIGATION + // and setting state.[historyAction/location/matches] to the new route. + // - Location is a required param + // - Navigation will always be set to IDLE_NAVIGATION + // - Can pass any other state in newState + function completeNavigation(location, newState, _temp) { + var _location$state, _location$state2; + let { + flushSync + } = _temp === void 0 ? {} : _temp; + // Deduce if we're in a loading/actionReload state: + // - We have committed actionData in the store + // - The current navigation was a mutation submission + // - We're past the submitting state and into the loading state + // - The location being loaded is not the result of a redirect + let isActionReload = state.actionData != null && state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && state.navigation.state === "loading" && ((_location$state = location.state) == null ? void 0 : _location$state._isRedirect) !== true; + let actionData; + if (newState.actionData) { + if (Object.keys(newState.actionData).length > 0) { + actionData = newState.actionData; + } else { + // Empty actionData -> clear prior actionData due to an action error + actionData = null; } - - // Handle null inputs - if (filterData === null || data === null) { - return false; + } else if (isActionReload) { + // Keep the current data if we're wrapping up the action reload + actionData = state.actionData; + } else { + // Clear actionData on any other completed navigations + actionData = null; + } + // Always preserve any existing loaderData from re-used routes + let loaderData = newState.loaderData ? mergeLoaderData(state.loaderData, newState.loaderData, newState.matches || [], newState.errors) : state.loaderData; + // On a successful navigation we can assume we got through all blockers + // so we can start fresh + let blockers = state.blockers; + if (blockers.size > 0) { + blockers = new Map(blockers); + blockers.forEach((_, k) => blockers.set(k, IDLE_BLOCKER)); + } + // Always respect the user flag. Otherwise don't reset on mutation + // submission navigations unless they redirect + let preventScrollReset = pendingPreventScrollReset === true || state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && ((_location$state2 = location.state) == null ? void 0 : _location$state2._isRedirect) !== true; + // Commit any in-flight routes at the end of the HMR revalidation "navigation" + if (inFlightDataRoutes) { + dataRoutes = inFlightDataRoutes; + inFlightDataRoutes = undefined; + } + if (isUninterruptedRevalidation) ; else if (pendingAction === Action.Pop) ; else if (pendingAction === Action.Push) { + init.history.push(location, location.state); + } else if (pendingAction === Action.Replace) { + init.history.replace(location, location.state); + } + let viewTransitionOpts; + // On POP, enable transitions if they were enabled on the original navigation + if (pendingAction === Action.Pop) { + // Forward takes precedence so they behave like the original navigation + let priorPaths = appliedViewTransitions.get(state.location.pathname); + if (priorPaths && priorPaths.has(location.pathname)) { + viewTransitionOpts = { + currentLocation: state.location, + nextLocation: location + }; + } else if (appliedViewTransitions.has(location.pathname)) { + // If we don't have a previous forward nav, assume we're popping back to + // the new location and enable if that location previously enabled + viewTransitionOpts = { + currentLocation: location, + nextLocation: state.location + }; } - - // Handle numeric inputs - if (typeof filterData === 'number') { - var intData = Number.parseInt(data, 10); - result = filterData === intData; + } else if (pendingViewTransitionEnabled) { + // Store the applied transition on PUSH/REPLACE + let toPaths = appliedViewTransitions.get(state.location.pathname); + if (toPaths) { + toPaths.add(location.pathname); + } else { + toPaths = new Set([location.pathname]); + appliedViewTransitions.set(state.location.pathname, toPaths); } - - // Handle string inputs - if (typeof filterData === 'string') { - searchKey = filterData.toLowerCase(); - switch ((0, _typeof2["default"])(data)) { - case 'object': - // Handles the case where the data is an array (typeof 'object') - // and you want to search through it for - // the string you are filtering by - var searchArray = data.map(function (e) { - return e.toLowerCase(); - }); - if (exactMatch) { - result = searchArray.includes(searchKey); - } else { - result = searchArray.find(function (e) { - return e.indexOf(searchKey) > -1; - }) !== undefined; - } - break; - default: - searchString = data ? data.toString().toLowerCase() : ''; - if (exactMatch) { - result = searchString === searchKey; - } else if (opposite) { - result = searchString !== searchKey; - } else { - result = searchString.indexOf(searchKey) > -1; - } - break; + viewTransitionOpts = { + currentLocation: state.location, + nextLocation: location + }; + } + updateState(_extends({}, newState, { + actionData, + loaderData, + historyAction: pendingAction, + location, + initialized: true, + navigation: IDLE_NAVIGATION, + revalidation: "idle", + restoreScrollPosition: getSavedScrollPosition(location, newState.matches || state.matches), + preventScrollReset, + blockers + }), { + viewTransitionOpts, + flushSync: flushSync === true + }); + // Reset stateful navigation vars + pendingAction = Action.Pop; + pendingPreventScrollReset = false; + pendingViewTransitionEnabled = false; + isUninterruptedRevalidation = false; + isRevalidationRequired = false; + cancelledDeferredRoutes = []; + } + // Trigger a navigation event, which can either be a numerical POP or a PUSH + // replace with an optional submission + async function navigate(to, opts) { + if (typeof to === "number") { + init.history.go(to); + return; + } + let normalizedPath = normalizeTo(state.location, state.matches, basename, future.v7_prependBasename, to, future.v7_relativeSplatPath, opts == null ? void 0 : opts.fromRouteId, opts == null ? void 0 : opts.relative); + let { + path, + submission, + error + } = normalizeNavigateOptions(future.v7_normalizeFormMethod, false, normalizedPath, opts); + let currentLocation = state.location; + let nextLocation = createLocation(state.location, path, opts && opts.state); + // When using navigate as a PUSH/REPLACE we aren't reading an already-encoded + // URL from window.location, so we need to encode it here so the behavior + // remains the same as POP and non-data-router usages. new URL() does all + // the same encoding we'd get from a history.pushState/window.location read + // without having to touch history + nextLocation = _extends({}, nextLocation, init.history.encodeLocation(nextLocation)); + let userReplace = opts && opts.replace != null ? opts.replace : undefined; + let historyAction = Action.Push; + if (userReplace === true) { + historyAction = Action.Replace; + } else if (userReplace === false) ; else if (submission != null && isMutationMethod(submission.formMethod) && submission.formAction === state.location.pathname + state.location.search) { + // By default on submissions to the current location we REPLACE so that + // users don't have to double-click the back button to get to the prior + // location. If the user redirects to a different location from the + // action/loader this will be ignored and the redirect will be a PUSH + historyAction = Action.Replace; + } + let preventScrollReset = opts && "preventScrollReset" in opts ? opts.preventScrollReset === true : undefined; + let flushSync = (opts && opts.flushSync) === true; + let blockerKey = shouldBlockNavigation({ + currentLocation, + nextLocation, + historyAction + }); + if (blockerKey) { + // Put the blocker into a blocked state + updateBlocker(blockerKey, { + state: "blocked", + location: nextLocation, + proceed() { + updateBlocker(blockerKey, { + state: "proceeding", + proceed: undefined, + reset: undefined, + location: nextLocation + }); + // Send the same navigation through + navigate(to, opts); + }, + reset() { + let blockers = new Map(state.blockers); + blockers.set(blockerKey, IDLE_BLOCKER); + updateState({ + blockers + }); } - } - - // Handle boolean inputs - if (typeof filterData === 'boolean') { - result = filterData === data; - } - - // Handle array inputs for multiselects - if ((0, _typeof2["default"])(filterData) === 'object') { - var match = false; - for (var i = 0; i < filterData.length; i += 1) { - searchKey = filterData[i].toLowerCase(); - searchString = data ? data.toString().toLowerCase() : ''; - var _searchArray = searchString.split(','); - match = _searchArray.includes(searchKey); - if (match) { - result = true; - } + }); + return; + } + return await startNavigation(historyAction, nextLocation, { + submission, + // Send through the formData serialization error if we have one so we can + // render at the right error boundary after we match routes + pendingError: error, + preventScrollReset, + replace: opts && opts.replace, + enableViewTransition: opts && opts.viewTransition, + flushSync + }); + } + // Revalidate all current loaders. If a navigation is in progress or if this + // is interrupted by a navigation, allow this to "succeed" by calling all + // loaders during the next loader round + function revalidate() { + interruptActiveLoads(); + updateState({ + revalidation: "loading" + }); + // If we're currently submitting an action, we don't need to start a new + // navigation, we'll just let the follow up loader execution call all loaders + if (state.navigation.state === "submitting") { + return; + } + // If we're currently in an idle state, start a new navigation for the current + // action/location and mark it as uninterrupted, which will skip the history + // update in completeNavigation + if (state.navigation.state === "idle") { + startNavigation(state.historyAction, state.location, { + startUninterruptedRevalidation: true + }); + return; + } + // Otherwise, if we're currently in a loading state, just start a new + // navigation to the navigation.location but do not trigger an uninterrupted + // revalidation so that history correctly updates once the navigation completes + startNavigation(pendingAction || state.historyAction, state.navigation.location, { + overrideNavigation: state.navigation, + // Proxy through any rending view transition + enableViewTransition: pendingViewTransitionEnabled === true + }); + } + // Start a navigation to the given action/location. Can optionally provide a + // overrideNavigation which will override the normalLoad in the case of a redirect + // navigation + async function startNavigation(historyAction, location, opts) { + // Abort any in-progress navigations and start a new one. Unset any ongoing + // uninterrupted revalidations unless told otherwise, since we want this + // new navigation to update history normally + pendingNavigationController && pendingNavigationController.abort(); + pendingNavigationController = null; + pendingAction = historyAction; + isUninterruptedRevalidation = (opts && opts.startUninterruptedRevalidation) === true; + // Save the current scroll position every time we start a new navigation, + // and track whether we should reset scroll on completion + saveScrollPosition(state.location, state.matches); + pendingPreventScrollReset = (opts && opts.preventScrollReset) === true; + pendingViewTransitionEnabled = (opts && opts.enableViewTransition) === true; + let routesToUse = inFlightDataRoutes || dataRoutes; + let loadingNavigation = opts && opts.overrideNavigation; + let matches = matchRoutes(routesToUse, location, basename); + let flushSync = (opts && opts.flushSync) === true; + let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname); + if (fogOfWar.active && fogOfWar.matches) { + matches = fogOfWar.matches; + } + // Short circuit with a 404 on the root error boundary if we match nothing + if (!matches) { + let { + error, + notFoundMatches, + route + } = handleNavigational404(location.pathname); + completeNavigation(location, { + matches: notFoundMatches, + loaderData: {}, + errors: { + [route.id]: error } - } - return result; + }, { + flushSync + }); + return; } - - /** - * Called by React when the component has been rendered on the page. - */ - }, { - key: "componentDidMount", - value: function componentDidMount() { - if (!this.props.noDynamicTable) { - $('.dynamictable').DynamicTable(); + // Short circuit if it's only a hash change and not a revalidation or + // mutation submission. + // + // Ignore on initial page loads because since the initial hydration will always + // be "same hash". For example, on /page#hash and submit a
+ // which will default to a navigation to /page + if (state.initialized && !isRevalidationRequired && isHashChangeOnly(state.location, location) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) { + completeNavigation(location, { + matches + }, { + flushSync + }); + return; + } + // Create a controller/Request for this navigation + pendingNavigationController = new AbortController(); + let request = createClientSideRequest(init.history, location, pendingNavigationController.signal, opts && opts.submission); + let pendingActionResult; + if (opts && opts.pendingError) { + // If we have a pendingError, it means the user attempted a GET submission + // with binary FormData so assign here and skip to handleLoaders. That + // way we handle calling loaders above the boundary etc. It's not really + // different from an actionError in that sense. + pendingActionResult = [findNearestBoundary(matches).route.id, { + type: ResultType.error, + error: opts.pendingError + }]; + } else if (opts && opts.submission && isMutationMethod(opts.submission.formMethod)) { + // Call action if we received an action submission + let actionResult = await handleAction(request, location, opts.submission, matches, fogOfWar.active, { + replace: opts.replace, + flushSync + }); + if (actionResult.shortCircuited) { + return; + } + // If we received a 404 from handleAction, it's because we couldn't lazily + // discover the destination route so we don't want to call loaders + if (actionResult.pendingActionResult) { + let [routeId, result] = actionResult.pendingActionResult; + if (isErrorResult(result) && isRouteErrorResponse(result.error) && result.error.status === 404) { + pendingNavigationController = null; + completeNavigation(location, { + matches: actionResult.matches, + loaderData: {}, + errors: { + [routeId]: result.error + } + }); + return; + } } + matches = actionResult.matches || matches; + pendingActionResult = actionResult.pendingActionResult; + loadingNavigation = getLoadingNavigation(location, opts.submission); + flushSync = false; + // No need to do fog of war matching again on loader execution + fogOfWar.active = false; + // Create a GET request for the loaders + request = createClientSideRequest(init.history, request.url, request.signal); + } + // Call loaders + let { + shortCircuited, + matches: updatedMatches, + loaderData, + errors + } = await handleLoaders(request, location, matches, fogOfWar.active, loadingNavigation, opts && opts.submission, opts && opts.fetcherSubmission, opts && opts.replace, opts && opts.initialHydration === true, flushSync, pendingActionResult); + if (shortCircuited) { + return; } - - /** - * Renders the Actions buttons. - * - * @return {string[]|void} - Array of React Elements - */ - }, { - key: "renderActions", - value: function renderActions() { - if (this.props.actions) { - return this.props.actions.map(function (action, key) { - if (action.show !== false) { - return /*#__PURE__*/_react["default"].createElement(_Form.CTA, { - key: key, - label: action.label, - onUserInput: action.action - }); - } - }); + // Clean up now that the action/loaders have completed. Don't clean up if + // we short circuited because pendingNavigationController will have already + // been assigned to a new controller for the next navigation + pendingNavigationController = null; + completeNavigation(location, _extends({ + matches: updatedMatches || matches + }, getActionDataForCommit(pendingActionResult), { + loaderData, + errors + })); + } + // Call the action matched by the leaf route for this navigation and handle + // redirects/errors + async function handleAction(request, location, submission, matches, isFogOfWar, opts) { + if (opts === void 0) { + opts = {}; + } + interruptActiveLoads(); + // Put us in a submitting state + let navigation = getSubmittingNavigation(location, submission); + updateState({ + navigation + }, { + flushSync: opts.flushSync === true + }); + if (isFogOfWar) { + let discoverResult = await discoverRoutes(matches, location.pathname, request.signal); + if (discoverResult.type === "aborted") { + return { + shortCircuited: true + }; + } else if (discoverResult.type === "error") { + let boundaryId = findNearestBoundary(discoverResult.partialMatches).route.id; + return { + matches: discoverResult.partialMatches, + pendingActionResult: [boundaryId, { + type: ResultType.error, + error: discoverResult.error + }] + }; + } else if (!discoverResult.matches) { + let { + notFoundMatches, + error, + route + } = handleNavigational404(location.pathname); + return { + matches: notFoundMatches, + pendingActionResult: [route.id, { + type: ResultType.error, + error + }] + }; + } else { + matches = discoverResult.matches; + } + } + // Call our action and get the result + let result; + let actionMatch = getTargetMatch(matches, location); + if (!actionMatch.route.action && !actionMatch.route.lazy) { + result = { + type: ResultType.error, + error: getInternalRouterError(405, { + method: request.method, + pathname: location.pathname, + routeId: actionMatch.route.id + }) + }; + } else { + let results = await callDataStrategy("action", state, request, [actionMatch], matches, null); + result = results[actionMatch.route.id]; + if (request.signal.aborted) { + return { + shortCircuited: true + }; } } - - /** - * Renders the React component. - * - * @return {JSX} - React markup for the component - */ - }, { - key: "render", - value: function render() { - var _this4 = this; - if ((this.props.data === null || this.props.data.length === 0) && !this.props.nullTableShow) { - return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", { - className: "row" - }, /*#__PURE__*/_react["default"].createElement("div", { - className: "col-xs-12" - }, /*#__PURE__*/_react["default"].createElement("div", { - className: "pull-right", - style: { - marginRight: '10px' - } - }, this.renderActions()))), /*#__PURE__*/_react["default"].createElement("div", { - className: "alert alert-info no-result-found-panel" - }, /*#__PURE__*/_react["default"].createElement("strong", null, "No result found."))); + if (isRedirectResult(result)) { + let replace; + if (opts && opts.replace != null) { + replace = opts.replace; + } else { + // If the user didn't explicity indicate replace behavior, replace if + // we redirected to the exact same location we're currently at to avoid + // double back-buttons + let location = normalizeRedirectLocation(result.response.headers.get("Location"), new URL(request.url), basename); + replace = location === state.location.pathname + state.location.search; + } + await startRedirectNavigation(request, result, true, { + submission, + replace + }); + return { + shortCircuited: true + }; + } + if (isDeferredResult(result)) { + throw getInternalRouterError(400, { + type: "defer-action" + }); + } + if (isErrorResult(result)) { + // Store off the pending error - we use it to determine which loaders + // to call and will commit it when we complete the navigation + let boundaryMatch = findNearestBoundary(matches, actionMatch.route.id); + // By default, all submissions to the current location are REPLACE + // navigations, but if the action threw an error that'll be rendered in + // an errorElement, we fall back to PUSH so that the user can use the + // back button to get back to the pre-submission form location to try + // again + if ((opts && opts.replace) !== true) { + pendingAction = Action.Push; } - var rowsPerPage = this.state.page.rows; - var headers = this.props.hide.defaultColumn === true ? [] : [/*#__PURE__*/_react["default"].createElement("th", { - key: "th_col_0", - onClick: function onClick() { - _this4.setSortColumn(-1); - } - }, this.props.rowNumLabel)]; - var _loop = function _loop(i) { - if (_this4.props.fields[i].show === true) { - var colIndex = i + 1; - if (_this4.props.fields[i].freezeColumn === true) { - headers.push(/*#__PURE__*/_react["default"].createElement("th", { - key: 'th_col_' + colIndex, - id: _this4.props.freezeColumn, - onClick: function onClick() { - _this4.setSortColumn(i); - } - }, _this4.props.fields[i].label)); - } else { - headers.push(/*#__PURE__*/_react["default"].createElement("th", { - key: 'th_col_' + colIndex, - onClick: function onClick() { - _this4.setSortColumn(i); - } - }, _this4.props.fields[i].label)); - } - } + return { + matches, + pendingActionResult: [boundaryMatch.route.id, result] }; - for (var i = 0; i < this.props.fields.length; i += 1) { - _loop(i); + } + return { + matches, + pendingActionResult: [actionMatch.route.id, result] + }; + } + // Call all applicable loaders for the given matches, handling redirects, + // errors, etc. + async function handleLoaders(request, location, matches, isFogOfWar, overrideNavigation, submission, fetcherSubmission, replace, initialHydration, flushSync, pendingActionResult) { + // Figure out the right navigation we want to use for data loading + let loadingNavigation = overrideNavigation || getLoadingNavigation(location, submission); + // If this was a redirect from an action we don't have a "submission" but + // we have it on the loading navigation so use that if available + let activeSubmission = submission || fetcherSubmission || getSubmissionFromNavigation(loadingNavigation); + // If this is an uninterrupted revalidation, we remain in our current idle + // state. If not, we need to switch to our loading state and load data, + // preserving any new action data or existing action data (in the case of + // a revalidation interrupting an actionReload) + // If we have partialHydration enabled, then don't update the state for the + // initial data load since it's not a "navigation" + let shouldUpdateNavigationState = !isUninterruptedRevalidation && (!future.v7_partialHydration || !initialHydration); + // When fog of war is enabled, we enter our `loading` state earlier so we + // can discover new routes during the `loading` state. We skip this if + // we've already run actions since we would have done our matching already. + // If the children() function threw then, we want to proceed with the + // partial matches it discovered. + if (isFogOfWar) { + if (shouldUpdateNavigationState) { + let actionData = getUpdatedActionData(pendingActionResult); + updateState(_extends({ + navigation: loadingNavigation + }, actionData !== undefined ? { + actionData + } : {}), { + flushSync + }); } - var rows = []; - var filteredRowIndexes = this.getFilteredRowIndexes(); - var filteredCount = filteredRowIndexes.length; - var index = this.sortRows(filteredRowIndexes); - var currentPageRow = rowsPerPage * (this.state.page.number - 1); - - // Format each cell for the data table. - var _loop2 = function _loop2() { - var rowIndex = index[_i2].RowIdx; - var rowData = _this4.props.data[rowIndex]; - var curRow = []; - - // Iterates through headers to populate row columns - // with corresponding data - var _loop3 = function _loop3() { - if (_this4.props.fields[j].show === false) { - return 1; // continue - } - var celldata = rowData[j]; - var cell = null; - var row = {}; - _this4.props.fields.forEach(function (field, k) { - return row[field.label] = rowData[k]; - }); - var headers = _this4.props.fields.map(function (val) { - return val.label; - }); - - // Get custom cell formatting if available - if (_this4.props.getFormattedCell) { - cell = _this4.props.getFormattedCell(_this4.props.fields[j].label, celldata, row, headers, j); - } else { - cell = /*#__PURE__*/_react["default"].createElement("td", null, celldata); + let discoverResult = await discoverRoutes(matches, location.pathname, request.signal); + if (discoverResult.type === "aborted") { + return { + shortCircuited: true + }; + } else if (discoverResult.type === "error") { + let boundaryId = findNearestBoundary(discoverResult.partialMatches).route.id; + return { + matches: discoverResult.partialMatches, + loaderData: {}, + errors: { + [boundaryId]: discoverResult.error } - if (cell !== null) { - curRow.push(/*#__PURE__*/_react["default"].cloneElement(cell, { - key: 'td_col_' + j - })); - } else { - curRow.push((0, _reactAddonsCreateFragment["default"])({ - celldata: celldata - })); + }; + } else if (!discoverResult.matches) { + let { + error, + notFoundMatches, + route + } = handleNavigational404(location.pathname); + return { + matches: notFoundMatches, + loaderData: {}, + errors: { + [route.id]: error } }; - for (var j = 0; j < _this4.props.fields.length; j += 1) { - if (_loop3()) continue; - } - var rowIndexDisplay = index[_i2].Content; - rows.push(/*#__PURE__*/_react["default"].createElement("tr", { - key: 'tr_' + rowIndex, - colSpan: headers.length - }, _this4.props.hide.defaultColumn === true ? null : /*#__PURE__*/_react["default"].createElement("td", { - key: 'td_' + rowIndex - }, rowIndexDisplay), curRow)); + } else { + matches = discoverResult.matches; + } + } + let routesToUse = inFlightDataRoutes || dataRoutes; + let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, activeSubmission, location, future.v7_partialHydration && initialHydration === true, future.v7_skipActionErrorRevalidation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionResult); + // Cancel pending deferreds for no-longer-matched routes or routes we're + // about to reload. Note that if this is an action reload we would have + // already cancelled all pending deferreds so this would be a no-op + cancelActiveDeferreds(routeId => !(matches && matches.some(m => m.route.id === routeId)) || matchesToLoad && matchesToLoad.some(m => m.route.id === routeId)); + pendingNavigationLoadId = ++incrementingLoadId; + // Short circuit if we have no loaders to run + if (matchesToLoad.length === 0 && revalidatingFetchers.length === 0) { + let updatedFetchers = markFetchRedirectsDone(); + completeNavigation(location, _extends({ + matches, + loaderData: {}, + // Commit pending error if we're short circuiting + errors: pendingActionResult && isErrorResult(pendingActionResult[1]) ? { + [pendingActionResult[0]]: pendingActionResult[1].error + } : null + }, getActionDataForCommit(pendingActionResult), updatedFetchers ? { + fetchers: new Map(state.fetchers) + } : {}), { + flushSync + }); + return { + shortCircuited: true }; - for (var _i2 = currentPageRow; _i2 < filteredCount && rows.length < rowsPerPage; _i2++) { - _loop2(); + } + if (shouldUpdateNavigationState) { + let updates = {}; + if (!isFogOfWar) { + // Only update navigation/actionNData if we didn't already do it above + updates.navigation = loadingNavigation; + let actionData = getUpdatedActionData(pendingActionResult); + if (actionData !== undefined) { + updates.actionData = actionData; + } } - var rowsPerPageDropdown = /*#__PURE__*/_react["default"].createElement("select", { - className: "input-sm perPage", - onChange: this.updatePageRows, - value: this.state.page.rows - }, /*#__PURE__*/_react["default"].createElement("option", null, "20"), /*#__PURE__*/_react["default"].createElement("option", null, "50"), /*#__PURE__*/_react["default"].createElement("option", null, "100"), /*#__PURE__*/_react["default"].createElement("option", null, "1000"), /*#__PURE__*/_react["default"].createElement("option", null, "5000"), /*#__PURE__*/_react["default"].createElement("option", null, "10000")); - var loading = this.props.loading ? 'Loading...' : ''; - var header = this.props.hide.rowsPerPage === true ? '' : /*#__PURE__*/_react["default"].createElement("div", { - className: "table-header" - }, /*#__PURE__*/_react["default"].createElement("div", { - className: "row" - }, /*#__PURE__*/_react["default"].createElement("div", { - style: { - display: 'flex', - justifyContent: 'space-between', - alignItems: 'center', - flexWrap: 'wrap', - padding: '5px 15px' + if (revalidatingFetchers.length > 0) { + updates.fetchers = getUpdatedRevalidatingFetchers(revalidatingFetchers); + } + updateState(updates, { + flushSync + }); + } + revalidatingFetchers.forEach(rf => { + abortFetcher(rf.key); + if (rf.controller) { + // Fetchers use an independent AbortController so that aborting a fetcher + // (via deleteFetcher) does not abort the triggering navigation that + // triggered the revalidation + fetchControllers.set(rf.key, rf.controller); + } + }); + // Proxy navigation abort through to revalidation fetchers + let abortPendingFetchRevalidations = () => revalidatingFetchers.forEach(f => abortFetcher(f.key)); + if (pendingNavigationController) { + pendingNavigationController.signal.addEventListener("abort", abortPendingFetchRevalidations); + } + let { + loaderResults, + fetcherResults + } = await callLoadersAndMaybeResolveData(state, matches, matchesToLoad, revalidatingFetchers, request); + if (request.signal.aborted) { + return { + shortCircuited: true + }; + } + // Clean up _after_ loaders have completed. Don't clean up if we short + // circuited because fetchControllers would have been aborted and + // reassigned to new controllers for the next navigation + if (pendingNavigationController) { + pendingNavigationController.signal.removeEventListener("abort", abortPendingFetchRevalidations); + } + revalidatingFetchers.forEach(rf => fetchControllers.delete(rf.key)); + // If any loaders returned a redirect Response, start a new REPLACE navigation + let redirect = findRedirect(loaderResults); + if (redirect) { + await startRedirectNavigation(request, redirect.result, true, { + replace + }); + return { + shortCircuited: true + }; + } + redirect = findRedirect(fetcherResults); + if (redirect) { + // If this redirect came from a fetcher make sure we mark it in + // fetchRedirectIds so it doesn't get revalidated on the next set of + // loader executions + fetchRedirectIds.add(redirect.key); + await startRedirectNavigation(request, redirect.result, true, { + replace + }); + return { + shortCircuited: true + }; + } + // Process and commit output from loaders + let { + loaderData, + errors + } = processLoaderData(state, matches, loaderResults, pendingActionResult, revalidatingFetchers, fetcherResults, activeDeferreds); + // Wire up subscribers to update loaderData as promises settle + activeDeferreds.forEach((deferredData, routeId) => { + deferredData.subscribe(aborted => { + // Note: No need to updateState here since the TrackedPromise on + // loaderData is stable across resolve/reject + // Remove this instance if we were aborted or if promises have settled + if (aborted || deferredData.done) { + activeDeferreds.delete(routeId); } - }, /*#__PURE__*/_react["default"].createElement("div", { - style: { - order: '1', - padding: '5px 0' + }); + }); + // Preserve SSR errors during partial hydration + if (future.v7_partialHydration && initialHydration && state.errors) { + errors = _extends({}, state.errors, errors); + } + let updatedFetchers = markFetchRedirectsDone(); + let didAbortFetchLoads = abortStaleFetchLoads(pendingNavigationLoadId); + let shouldUpdateFetchers = updatedFetchers || didAbortFetchLoads || revalidatingFetchers.length > 0; + return _extends({ + matches, + loaderData, + errors + }, shouldUpdateFetchers ? { + fetchers: new Map(state.fetchers) + } : {}); + } + function getUpdatedActionData(pendingActionResult) { + if (pendingActionResult && !isErrorResult(pendingActionResult[1])) { + // This is cast to `any` currently because `RouteData`uses any and it + // would be a breaking change to use any. + // TODO: v7 - change `RouteData` to use `unknown` instead of `any` + return { + [pendingActionResult[0]]: pendingActionResult[1].data + }; + } else if (state.actionData) { + if (Object.keys(state.actionData).length === 0) { + return null; + } else { + return state.actionData; + } + } + } + function getUpdatedRevalidatingFetchers(revalidatingFetchers) { + revalidatingFetchers.forEach(rf => { + let fetcher = state.fetchers.get(rf.key); + let revalidatingFetcher = getLoadingFetcher(undefined, fetcher ? fetcher.data : undefined); + state.fetchers.set(rf.key, revalidatingFetcher); + }); + return new Map(state.fetchers); + } + // Trigger a fetcher load/submit for the given fetcher key + function fetch(key, routeId, href, opts) { + if (isServer) { + throw new Error("router.fetch() was called during the server render, but it shouldn't be. " + "You are likely calling a useFetcher() method in the body of your component. " + "Try moving it to a useEffect or a callback."); + } + abortFetcher(key); + let flushSync = (opts && opts.flushSync) === true; + let routesToUse = inFlightDataRoutes || dataRoutes; + let normalizedPath = normalizeTo(state.location, state.matches, basename, future.v7_prependBasename, href, future.v7_relativeSplatPath, routeId, opts == null ? void 0 : opts.relative); + let matches = matchRoutes(routesToUse, normalizedPath, basename); + let fogOfWar = checkFogOfWar(matches, routesToUse, normalizedPath); + if (fogOfWar.active && fogOfWar.matches) { + matches = fogOfWar.matches; + } + if (!matches) { + setFetcherError(key, routeId, getInternalRouterError(404, { + pathname: normalizedPath + }), { + flushSync + }); + return; + } + let { + path, + submission, + error + } = normalizeNavigateOptions(future.v7_normalizeFormMethod, true, normalizedPath, opts); + if (error) { + setFetcherError(key, routeId, error, { + flushSync + }); + return; + } + let match = getTargetMatch(matches, path); + let preventScrollReset = (opts && opts.preventScrollReset) === true; + if (submission && isMutationMethod(submission.formMethod)) { + handleFetcherAction(key, routeId, path, match, matches, fogOfWar.active, flushSync, preventScrollReset, submission); + return; + } + // Store off the match so we can call it's shouldRevalidate on subsequent + // revalidations + fetchLoadMatches.set(key, { + routeId, + path + }); + handleFetcherLoader(key, routeId, path, match, matches, fogOfWar.active, flushSync, preventScrollReset, submission); + } + // Call the action for the matched fetcher.submit(), and then handle redirects, + // errors, and revalidation + async function handleFetcherAction(key, routeId, path, match, requestMatches, isFogOfWar, flushSync, preventScrollReset, submission) { + interruptActiveLoads(); + fetchLoadMatches.delete(key); + function detectAndHandle405Error(m) { + if (!m.route.action && !m.route.lazy) { + let error = getInternalRouterError(405, { + method: submission.formMethod, + pathname: path, + routeId: routeId + }); + setFetcherError(key, routeId, error, { + flushSync + }); + return true; + } + return false; + } + if (!isFogOfWar && detectAndHandle405Error(match)) { + return; + } + // Put this fetcher into it's submitting state + let existingFetcher = state.fetchers.get(key); + updateFetcherState(key, getSubmittingFetcher(submission, existingFetcher), { + flushSync + }); + let abortController = new AbortController(); + let fetchRequest = createClientSideRequest(init.history, path, abortController.signal, submission); + if (isFogOfWar) { + let discoverResult = await discoverRoutes(requestMatches, path, fetchRequest.signal); + if (discoverResult.type === "aborted") { + return; + } else if (discoverResult.type === "error") { + setFetcherError(key, routeId, discoverResult.error, { + flushSync + }); + return; + } else if (!discoverResult.matches) { + setFetcherError(key, routeId, getInternalRouterError(404, { + pathname: path + }), { + flushSync + }); + return; + } else { + requestMatches = discoverResult.matches; + match = getTargetMatch(requestMatches, path); + if (detectAndHandle405Error(match)) { + return; } - }, rows.length, " rows displayed of ", filteredCount, ". (Maximum rows per page: ", rowsPerPageDropdown, ")", loading), /*#__PURE__*/_react["default"].createElement("div", { - style: { - order: '2', - display: 'flex', - justifyContent: 'flex-end', - alignItems: 'center', - flexWrap: 'wrap', - padding: '5px 0', - marginLeft: 'auto' + } + } + // Call the action for the fetcher + fetchControllers.set(key, abortController); + let originatingLoadId = incrementingLoadId; + let actionResults = await callDataStrategy("action", state, fetchRequest, [match], requestMatches, key); + let actionResult = actionResults[match.route.id]; + if (fetchRequest.signal.aborted) { + // We can delete this so long as we weren't aborted by our own fetcher + // re-submit which would have put _new_ controller is in fetchControllers + if (fetchControllers.get(key) === abortController) { + fetchControllers.delete(key); + } + return; + } + // When using v7_fetcherPersist, we don't want errors bubbling up to the UI + // or redirects processed for unmounted fetchers so we just revert them to + // idle + if (future.v7_fetcherPersist && deletedFetchers.has(key)) { + if (isRedirectResult(actionResult) || isErrorResult(actionResult)) { + updateFetcherState(key, getDoneFetcher(undefined)); + return; + } + // Let SuccessResult's fall through for revalidation + } else { + if (isRedirectResult(actionResult)) { + fetchControllers.delete(key); + if (pendingNavigationLoadId > originatingLoadId) { + // A new navigation was kicked off after our action started, so that + // should take precedence over this redirect navigation. We already + // set isRevalidationRequired so all loaders for the new route should + // fire unless opted out via shouldRevalidate + updateFetcherState(key, getDoneFetcher(undefined)); + return; + } else { + fetchRedirectIds.add(key); + updateFetcherState(key, getLoadingFetcher(submission)); + return startRedirectNavigation(fetchRequest, actionResult, false, { + fetcherSubmission: submission, + preventScrollReset + }); } - }, this.renderActions(), this.props.hide.downloadCSV === true ? '' : /*#__PURE__*/_react["default"].createElement("button", { - className: "btn btn-primary", - onClick: this.downloadCSV.bind(null, filteredRowIndexes) - }, "Download Table as CSV"), /*#__PURE__*/_react["default"].createElement(_PaginationLinks["default"], { - Total: filteredCount, - onChangePage: this.changePage, - RowsPerPage: rowsPerPage, - Active: this.state.page.number - }))))); - var footer = /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", { - className: "row" - }, /*#__PURE__*/_react["default"].createElement("div", { - style: { - display: 'flex', - justifyContent: 'space-between', - alignItems: 'center', - flexWrap: 'wrap', - padding: '5px 15px' - } - }, /*#__PURE__*/_react["default"].createElement("div", { - style: { - order: '1', - padding: '5px 0' - } - }, rows.length, " rows displayed of ", filteredCount, ". (Maximum rows per page: ", rowsPerPageDropdown, ")"), /*#__PURE__*/_react["default"].createElement("div", { - style: { - order: '2', - padding: '5px 0', - marginLeft: 'auto' - } - }, /*#__PURE__*/_react["default"].createElement(_PaginationLinks["default"], { - Total: filteredCount, - onChangePage: this.changePage, - RowsPerPage: rowsPerPage, - Active: this.state.page.number - }))))); - return /*#__PURE__*/_react["default"].createElement("div", { - style: { - margin: '14px' - } - }, header, /*#__PURE__*/_react["default"].createElement("table", { - className: "table table-hover table-primary table-bordered dynamictable", - id: "dynamictable" - }, /*#__PURE__*/_react["default"].createElement("thead", null, /*#__PURE__*/_react["default"].createElement("tr", { - className: "info" - }, headers)), this.props.folder, /*#__PURE__*/_react["default"].createElement("tbody", null, rows)), footer); + } + // Process any non-redirect errors thrown + if (isErrorResult(actionResult)) { + setFetcherError(key, routeId, actionResult.error); + return; + } } - }]); -}(_react.Component); -DataTable.propTypes = { - data: _propTypes["default"].array.isRequired, - rowNumLabel: _propTypes["default"].string, - // Function of which returns a JSX element for a table cell, takes - // parameters of the form: func(ColumnName, CellData, EntireRowData) - getFormattedCell: _propTypes["default"].func, - onSort: _propTypes["default"].func, - actions: _propTypes["default"].array, - hide: _propTypes["default"].object, - nullTableShow: _propTypes["default"].bool, - noDynamicTable: _propTypes["default"].bool, - getMappedCell: _propTypes["default"].func, - fields: _propTypes["default"].array, - RowNameMap: _propTypes["default"].array, - filters: _propTypes["default"].object, - freezeColumn: _propTypes["default"].string, - loading: _propTypes["default"].element, - folder: _propTypes["default"].element -}; -DataTable.defaultProps = { - headers: [], - data: {}, - rowNumLabel: 'No.', - filters: {}, - hide: { - rowsPerPage: false, - downloadCSV: false, - defaultColumn: false - }, - nullTableShow: false, - noDynamicTable: false -}; -var _default = exports["default"] = DataTable; - -/***/ }), - -/***/ "./jsx/Filter.js": -/*!***********************!*\ - !*** ./jsx/Filter.js ***! - \***********************/ -/***/ ((__unused_webpack_module, exports, __webpack_require__) => { - -"use strict"; - - -var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js"); -var _typeof = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js"); -Object.defineProperty(exports, "__esModule", ({ - value: true -})); -exports["default"] = void 0; -var _react = _interopRequireWildcard(__webpack_require__(/*! react */ "react")); -var _propTypes = _interopRequireDefault(__webpack_require__(/*! prop-types */ "./node_modules/prop-types/index.js")); -var _Form = __webpack_require__(/*! jsx/Form */ "./jsx/Form.js"); -var _DateTimePartialElement = _interopRequireDefault(__webpack_require__(/*! jsx/form/DateTimePartialElement */ "./jsx/form/DateTimePartialElement.tsx")); -function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } -function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } -/** - * Filter component - * A wrapper for form elements inside a selection filter. - * - * Constructs filter fields based on this.props.fields configuration object - * - * Alters the filter object and sends it to parent on every update. - * - * @param {props} props - * @return {JSX} - */ -function Filter(props) { - /** - * Takes query params from url and triggers an update of the fields that are - * associated with those params, if they exist. - */ - (0, _react.useEffect)(function () { - var searchParams = new URLSearchParams(location.search); - searchParams.forEach(function (value, name) { - // This checks to make sure the filter actually exists - if (props.fields.find(function (field) { - return (field.filter || {}).name == name; - })) { - onFieldUpdate(name, searchParams.getAll(name)); + if (isDeferredResult(actionResult)) { + throw getInternalRouterError(400, { + type: "defer-action" + }); + } + // Start the data load for current matches, or the next location if we're + // in the middle of a navigation + let nextLocation = state.navigation.location || state.location; + let revalidationRequest = createClientSideRequest(init.history, nextLocation, abortController.signal); + let routesToUse = inFlightDataRoutes || dataRoutes; + let matches = state.navigation.state !== "idle" ? matchRoutes(routesToUse, state.navigation.location, basename) : state.matches; + invariant(matches, "Didn't find any matches after fetcher action"); + let loadId = ++incrementingLoadId; + fetchReloadIds.set(key, loadId); + let loadFetcher = getLoadingFetcher(submission, actionResult.data); + state.fetchers.set(key, loadFetcher); + let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, submission, nextLocation, false, future.v7_skipActionErrorRevalidation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, [match.route.id, actionResult]); + // Put all revalidating fetchers into the loading state, except for the + // current fetcher which we want to keep in it's current loading state which + // contains it's action submission info + action data + revalidatingFetchers.filter(rf => rf.key !== key).forEach(rf => { + let staleKey = rf.key; + let existingFetcher = state.fetchers.get(staleKey); + let revalidatingFetcher = getLoadingFetcher(undefined, existingFetcher ? existingFetcher.data : undefined); + state.fetchers.set(staleKey, revalidatingFetcher); + abortFetcher(staleKey); + if (rf.controller) { + fetchControllers.set(staleKey, rf.controller); } }); - }, []); - - /** - * Sets filter object to reflect values of input fields. - * - * @param {string} name - form element type (i.e component name) - * @param {string} value - the name of the form element - */ - var onFieldUpdate = function onFieldUpdate(name, value) { - var _JSON$parse = JSON.parse(JSON.stringify(props)), - fields = _JSON$parse.fields; - var type = fields.find(function (field) { - return (field.filter || {}).name == name; - }).filter.type; - var exactMatch = !(type === 'text' || type === 'date' || type === 'datetime' || type === 'multiselect'); - if (value === null || value === '' || value.constructor === Array && value.length === 0 || type === 'checkbox' && value === false) { - props.removeFilter(name); + updateState({ + fetchers: new Map(state.fetchers) + }); + let abortPendingFetchRevalidations = () => revalidatingFetchers.forEach(rf => abortFetcher(rf.key)); + abortController.signal.addEventListener("abort", abortPendingFetchRevalidations); + let { + loaderResults, + fetcherResults + } = await callLoadersAndMaybeResolveData(state, matches, matchesToLoad, revalidatingFetchers, revalidationRequest); + if (abortController.signal.aborted) { + return; + } + abortController.signal.removeEventListener("abort", abortPendingFetchRevalidations); + fetchReloadIds.delete(key); + fetchControllers.delete(key); + revalidatingFetchers.forEach(r => fetchControllers.delete(r.key)); + let redirect = findRedirect(loaderResults); + if (redirect) { + return startRedirectNavigation(revalidationRequest, redirect.result, false, { + preventScrollReset + }); + } + redirect = findRedirect(fetcherResults); + if (redirect) { + // If this redirect came from a fetcher make sure we mark it in + // fetchRedirectIds so it doesn't get revalidated on the next set of + // loader executions + fetchRedirectIds.add(redirect.key); + return startRedirectNavigation(revalidationRequest, redirect.result, false, { + preventScrollReset + }); + } + // Process and commit output from loaders + let { + loaderData, + errors + } = processLoaderData(state, matches, loaderResults, undefined, revalidatingFetchers, fetcherResults, activeDeferreds); + // Since we let revalidations complete even if the submitting fetcher was + // deleted, only put it back to idle if it hasn't been deleted + if (state.fetchers.has(key)) { + let doneFetcher = getDoneFetcher(actionResult.data); + state.fetchers.set(key, doneFetcher); + } + abortStaleFetchLoads(loadId); + // If we are currently in a navigation loading state and this fetcher is + // more recent than the navigation, we want the newer data so abort the + // navigation and complete it with the fetcher data + if (state.navigation.state === "loading" && loadId > pendingNavigationLoadId) { + invariant(pendingAction, "Expected pending action"); + pendingNavigationController && pendingNavigationController.abort(); + completeNavigation(state.navigation.location, { + matches, + loaderData, + errors, + fetchers: new Map(state.fetchers) + }); } else { - props.addFilter(name, value, exactMatch); + // otherwise just update with the fetcher data, preserving any existing + // loaderData for loaders that did not need to reload. We have to + // manually merge here since we aren't going through completeNavigation + updateState({ + errors, + loaderData: mergeLoaderData(state.loaderData, loaderData, matches, errors), + fetchers: new Map(state.fetchers) + }); + isRevalidationRequired = false; } - }; - + } + // Call the matched loader for fetcher.load(), handling redirects, errors, etc. + async function handleFetcherLoader(key, routeId, path, match, matches, isFogOfWar, flushSync, preventScrollReset, submission) { + let existingFetcher = state.fetchers.get(key); + updateFetcherState(key, getLoadingFetcher(submission, existingFetcher ? existingFetcher.data : undefined), { + flushSync + }); + let abortController = new AbortController(); + let fetchRequest = createClientSideRequest(init.history, path, abortController.signal); + if (isFogOfWar) { + let discoverResult = await discoverRoutes(matches, path, fetchRequest.signal); + if (discoverResult.type === "aborted") { + return; + } else if (discoverResult.type === "error") { + setFetcherError(key, routeId, discoverResult.error, { + flushSync + }); + return; + } else if (!discoverResult.matches) { + setFetcherError(key, routeId, getInternalRouterError(404, { + pathname: path + }), { + flushSync + }); + return; + } else { + matches = discoverResult.matches; + match = getTargetMatch(matches, path); + } + } + // Call the loader for this fetcher route match + fetchControllers.set(key, abortController); + let originatingLoadId = incrementingLoadId; + let results = await callDataStrategy("loader", state, fetchRequest, [match], matches, key); + let result = results[match.route.id]; + // Deferred isn't supported for fetcher loads, await everything and treat it + // as a normal load. resolveDeferredData will return undefined if this + // fetcher gets aborted, so we just leave result untouched and short circuit + // below if that happens + if (isDeferredResult(result)) { + result = (await resolveDeferredData(result, fetchRequest.signal, true)) || result; + } + // We can delete this so long as we weren't aborted by our our own fetcher + // re-load which would have put _new_ controller is in fetchControllers + if (fetchControllers.get(key) === abortController) { + fetchControllers.delete(key); + } + if (fetchRequest.signal.aborted) { + return; + } + // We don't want errors bubbling up or redirects followed for unmounted + // fetchers, so short circuit here if it was removed from the UI + if (deletedFetchers.has(key)) { + updateFetcherState(key, getDoneFetcher(undefined)); + return; + } + // If the loader threw a redirect Response, start a new REPLACE navigation + if (isRedirectResult(result)) { + if (pendingNavigationLoadId > originatingLoadId) { + // A new navigation was kicked off after our loader started, so that + // should take precedence over this redirect navigation + updateFetcherState(key, getDoneFetcher(undefined)); + return; + } else { + fetchRedirectIds.add(key); + await startRedirectNavigation(fetchRequest, result, false, { + preventScrollReset + }); + return; + } + } + // Process any non-redirect errors thrown + if (isErrorResult(result)) { + setFetcherError(key, routeId, result.error); + return; + } + invariant(!isDeferredResult(result), "Unhandled fetcher deferred data"); + // Put the fetcher back into an idle state + updateFetcherState(key, getDoneFetcher(result.data)); + } /** - * Renders the filters based on the defined fields. + * Utility function to handle redirects returned from an action or loader. + * Normally, a redirect "replaces" the navigation that triggered it. So, for + * example: * - * @return {array} + * - user is on /a + * - user clicks a link to /b + * - loader for /b redirects to /c + * + * In a non-JS app the browser would track the in-flight navigation to /b and + * then replace it with /c when it encountered the redirect response. In + * the end it would only ever update the URL bar with /c. + * + * In client-side routing using pushState/replaceState, we aim to emulate + * this behavior and we also do not update history until the end of the + * navigation (including processed redirects). This means that we never + * actually touch history until we've processed redirects, so we just use + * the history action from the original navigation (PUSH or REPLACE). */ - var renderFilterFields = function renderFilterFields() { - return props.fields.reduce(function (result, field) { - var filter = field.filter; - if (filter && filter.hide !== true) { - var element; - switch (filter.type) { - case 'text': - element = /*#__PURE__*/_react["default"].createElement(_Form.TextboxElement, null); - break; - case 'select': - element = /*#__PURE__*/_react["default"].createElement(_Form.SelectElement, { - options: filter.options, - sortByValue: filter.sortByValue, - autoSelect: false - }); - break; - case 'multiselect': - element = /*#__PURE__*/_react["default"].createElement(_Form.SelectElement, { - options: filter.options, - sortByValue: filter.sortByValue, - multiple: true, - emptyOption: false - }); - break; - case 'numeric': - element = /*#__PURE__*/_react["default"].createElement(_Form.NumericElement, { - options: filter.options - }); - break; - case 'date': - element = /*#__PURE__*/_react["default"].createElement(_Form.DateElement, null); - break; - case 'datetime': - element = /*#__PURE__*/_react["default"].createElement(_DateTimePartialElement["default"], null); - break; - case 'checkbox': - element = /*#__PURE__*/_react["default"].createElement(_Form.CheckboxElement, null); - break; - case 'time': - element = /*#__PURE__*/_react["default"].createElement(_Form.TimeElement, null); - break; - default: - element = /*#__PURE__*/_react["default"].createElement(_Form.TextboxElement, null); + async function startRedirectNavigation(request, redirect, isNavigation, _temp2) { + let { + submission, + fetcherSubmission, + preventScrollReset, + replace + } = _temp2 === void 0 ? {} : _temp2; + if (redirect.response.headers.has("X-Remix-Revalidate")) { + isRevalidationRequired = true; + } + let location = redirect.response.headers.get("Location"); + invariant(location, "Expected a Location header on the redirect Response"); + location = normalizeRedirectLocation(location, new URL(request.url), basename); + let redirectLocation = createLocation(state.location, location, { + _isRedirect: true + }); + if (isBrowser) { + let isDocumentReload = false; + if (redirect.response.headers.has("X-Remix-Reload-Document")) { + // Hard reload if the response contained X-Remix-Reload-Document + isDocumentReload = true; + } else if (ABSOLUTE_URL_REGEX.test(location)) { + const url = init.history.createURL(location); + isDocumentReload = + // Hard reload if it's an absolute URL to a new origin + url.origin !== routerWindow.location.origin || + // Hard reload if it's an absolute URL that does not match our basename + stripBasename(url.pathname, basename) == null; + } + if (isDocumentReload) { + if (replace) { + routerWindow.location.replace(location); + } else { + routerWindow.location.assign(location); } - - // The value prop has to default to false if the first two options - // are undefined so that the checkbox component is a controlled input - // element with a starting default value - result.push(/*#__PURE__*/_react["default"].cloneElement(element, { - key: filter.name, - name: filter.name, - label: field.label, - value: (props.filters[filter.name] || {}).value || null, - onUserInput: onFieldUpdate - })); + return; } - return result; - }, []); - }; - var filterPresets = function filterPresets() { - if (props.filterPresets) { - var presets = props.filterPresets.map(function (preset) { - var handleClick = function handleClick() { - return props.updateFilters(preset.filter); - }; - return /*#__PURE__*/_react["default"].createElement("li", null, /*#__PURE__*/_react["default"].createElement("a", { - onClick: handleClick - }, preset.label)); + } + // There's no need to abort on redirects, since we don't detect the + // redirect until the action/loaders have settled + pendingNavigationController = null; + let redirectHistoryAction = replace === true || redirect.response.headers.has("X-Remix-Replace") ? Action.Replace : Action.Push; + // Use the incoming submission if provided, fallback on the active one in + // state.navigation + let { + formMethod, + formAction, + formEncType + } = state.navigation; + if (!submission && !fetcherSubmission && formMethod && formAction && formEncType) { + submission = getSubmissionFromNavigation(state.navigation); + } + // If this was a 307/308 submission we want to preserve the HTTP method and + // re-submit the GET/POST/PUT/PATCH/DELETE as a submission navigation to the + // redirected location + let activeSubmission = submission || fetcherSubmission; + if (redirectPreserveMethodStatusCodes.has(redirect.response.status) && activeSubmission && isMutationMethod(activeSubmission.formMethod)) { + await startNavigation(redirectHistoryAction, redirectLocation, { + submission: _extends({}, activeSubmission, { + formAction: location + }), + // Preserve these flags across redirects + preventScrollReset: preventScrollReset || pendingPreventScrollReset, + enableViewTransition: isNavigation ? pendingViewTransitionEnabled : undefined + }); + } else { + // If we have a navigation submission, we will preserve it through the + // redirect navigation + let overrideNavigation = getLoadingNavigation(redirectLocation, submission); + await startNavigation(redirectHistoryAction, redirectLocation, { + overrideNavigation, + // Send fetcher submissions through for shouldRevalidate + fetcherSubmission, + // Preserve these flags across redirects + preventScrollReset: preventScrollReset || pendingPreventScrollReset, + enableViewTransition: isNavigation ? pendingViewTransitionEnabled : undefined }); - return /*#__PURE__*/_react["default"].createElement("li", { - className: "dropdown" - }, /*#__PURE__*/_react["default"].createElement("a", { - className: "dropdown-toggle", - "data-toggle": "dropdown", - role: "button" - }, "Load Filter Preset ", /*#__PURE__*/_react["default"].createElement("span", { - className: "caret" - })), /*#__PURE__*/_react["default"].createElement("ul", { - className: "dropdown-menu", - role: "menu" - }, presets)); } - }; - var filterActions = /*#__PURE__*/_react["default"].createElement("ul", { - className: "nav nav-tabs navbar-right", - style: { - borderBottom: 'none' + } + // Utility wrapper for calling dataStrategy client-side without having to + // pass around the manifest, mapRouteProperties, etc. + async function callDataStrategy(type, state, request, matchesToLoad, matches, fetcherKey) { + let results; + let dataResults = {}; + try { + results = await callDataStrategyImpl(dataStrategyImpl, type, state, request, matchesToLoad, matches, fetcherKey, manifest, mapRouteProperties); + } catch (e) { + // If the outer dataStrategy method throws, just return the error for all + // matches - and it'll naturally bubble to the root + matchesToLoad.forEach(m => { + dataResults[m.route.id] = { + type: ResultType.error, + error: e + }; + }); + return dataResults; + } + for (let [routeId, result] of Object.entries(results)) { + if (isRedirectDataStrategyResultResult(result)) { + let response = result.result; + dataResults[routeId] = { + type: ResultType.redirect, + response: normalizeRelativeRoutingRedirectResponse(response, request, routeId, matches, basename, future.v7_relativeSplatPath) + }; + } else { + dataResults[routeId] = await convertDataStrategyResultToDataResult(result); + } } - }, filterPresets(), /*#__PURE__*/_react["default"].createElement("li", null, /*#__PURE__*/_react["default"].createElement("a", { - role: "button", - name: "reset", - onClick: props.clearFilters - }, "Clear Filter"))); - return /*#__PURE__*/_react["default"].createElement(_Form.FormElement, { - id: props.id, - name: props.name - }, /*#__PURE__*/_react["default"].createElement(_Form.FieldsetElement, { - columns: props.columns, - legend: props.title - }, filterActions, renderFilterFields())); -} -Filter.defaultProps = { - id: null, - clearFilter: function clearFilter() { - console.warn('onUpdate() callback is not set!'); - }, - columns: 1 -}; -Filter.propTypes = { - filters: _propTypes["default"].object.isRequired, - clearFilter: _propTypes["default"].func.isRequired, - id: _propTypes["default"].string, - name: _propTypes["default"].string, - columns: _propTypes["default"].number, - title: _propTypes["default"].string, - fields: _propTypes["default"].array.isRequired, - removeFilter: _propTypes["default"].func, - addFilter: _propTypes["default"].func, - filterPresets: _propTypes["default"].array, - updateFilters: _propTypes["default"].func, - clearFilters: _propTypes["default"].func -}; -var _default = exports["default"] = Filter; - -/***/ }), - -/***/ "./jsx/FilterableDataTable.js": -/*!************************************!*\ - !*** ./jsx/FilterableDataTable.js ***! - \************************************/ -/***/ ((__unused_webpack_module, exports, __webpack_require__) => { - -"use strict"; - - -var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js"); -var _typeof = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js"); -Object.defineProperty(exports, "__esModule", ({ - value: true -})); -exports["default"] = void 0; -var _slicedToArray2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/slicedToArray */ "./node_modules/@babel/runtime/helpers/slicedToArray.js")); -var _classCallCheck2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "./node_modules/@babel/runtime/helpers/classCallCheck.js")); -var _createClass2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/createClass */ "./node_modules/@babel/runtime/helpers/createClass.js")); -var _possibleConstructorReturn2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "./node_modules/@babel/runtime/helpers/possibleConstructorReturn.js")); -var _getPrototypeOf2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "./node_modules/@babel/runtime/helpers/getPrototypeOf.js")); -var _inherits2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/inherits */ "./node_modules/@babel/runtime/helpers/inherits.js")); -var _react = _interopRequireWildcard(__webpack_require__(/*! react */ "react")); -var _propTypes = _interopRequireDefault(__webpack_require__(/*! prop-types */ "./node_modules/prop-types/index.js")); -var _Panel = _interopRequireDefault(__webpack_require__(/*! jsx/Panel */ "./jsx/Panel.js")); -var _DataTable = _interopRequireDefault(__webpack_require__(/*! jsx/DataTable */ "./jsx/DataTable.js")); -var _Filter = _interopRequireDefault(__webpack_require__(/*! jsx/Filter */ "./jsx/Filter.js")); -var _ProgressBar = _interopRequireDefault(__webpack_require__(/*! jsx/ProgressBar */ "./jsx/ProgressBar.js")); -function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } -function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } -function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); } -function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } -/** - * FilterableDataTable component. - * A wrapper for all datatables that handles filtering. - * - * Handles the updating and clearing of the filter state based on changes sent - * from the FitlerForm. - * - * Passes the Filter to the Datatable. - * - * Deprecates Filter Form. - */ -var FilterableDataTable = /*#__PURE__*/function (_Component) { - /** - * @constructor - * @param {object} props - React Component properties - */ - function FilterableDataTable(props) { - var _this; - (0, _classCallCheck2["default"])(this, FilterableDataTable); - _this = _callSuper(this, FilterableDataTable, [props]); - _this.state = { - filters: {} + return dataResults; + } + async function callLoadersAndMaybeResolveData(state, matches, matchesToLoad, fetchersToLoad, request) { + let currentMatches = state.matches; + // Kick off loaders and fetchers in parallel + let loaderResultsPromise = callDataStrategy("loader", state, request, matchesToLoad, matches, null); + let fetcherResultsPromise = Promise.all(fetchersToLoad.map(async f => { + if (f.matches && f.match && f.controller) { + let results = await callDataStrategy("loader", state, createClientSideRequest(init.history, f.path, f.controller.signal), [f.match], f.matches, f.key); + let result = results[f.match.route.id]; + // Fetcher results are keyed by fetcher key from here on out, not routeId + return { + [f.key]: result + }; + } else { + return Promise.resolve({ + [f.key]: { + type: ResultType.error, + error: getInternalRouterError(404, { + pathname: f.path + }) + } + }); + } + })); + let loaderResults = await loaderResultsPromise; + let fetcherResults = (await fetcherResultsPromise).reduce((acc, r) => Object.assign(acc, r), {}); + await Promise.all([resolveNavigationDeferredResults(matches, loaderResults, request.signal, currentMatches, state.loaderData), resolveFetcherDeferredResults(matches, fetcherResults, fetchersToLoad)]); + return { + loaderResults, + fetcherResults }; - _this.updateFilters = _this.updateFilters.bind(_this); - _this.clearFilters = _this.clearFilters.bind(_this); - _this.validFilters = _this.validFilters.bind(_this); - _this.addFilter = _this.addFilter.bind(_this); - _this.removeFilter = _this.removeFilter.bind(_this); - return _this; } - - /** - * Updates filter state - * - * @param {object} filters - */ - (0, _inherits2["default"])(FilterableDataTable, _Component); - return (0, _createClass2["default"])(FilterableDataTable, [{ - key: "updateFilters", - value: function updateFilters(filters) { - this.updateQueryParams(filters); - this.setState({ - filters: filters - }); - if (this.props.updateFilterCallback) { - this.props.updateFilterCallback(filters); + function interruptActiveLoads() { + // Every interruption triggers a revalidation + isRevalidationRequired = true; + // Cancel pending route-level deferreds and mark cancelled routes for + // revalidation + cancelledDeferredRoutes.push(...cancelActiveDeferreds()); + // Abort in-flight fetcher loads + fetchLoadMatches.forEach((_, key) => { + if (fetchControllers.has(key)) { + cancelledFetcherLoads.add(key); + } + abortFetcher(key); + }); + } + function updateFetcherState(key, fetcher, opts) { + if (opts === void 0) { + opts = {}; + } + state.fetchers.set(key, fetcher); + updateState({ + fetchers: new Map(state.fetchers) + }, { + flushSync: (opts && opts.flushSync) === true + }); + } + function setFetcherError(key, routeId, error, opts) { + if (opts === void 0) { + opts = {}; + } + let boundaryMatch = findNearestBoundary(state.matches, routeId); + deleteFetcher(key); + updateState({ + errors: { + [boundaryMatch.route.id]: error + }, + fetchers: new Map(state.fetchers) + }, { + flushSync: (opts && opts.flushSync) === true + }); + } + function getFetcher(key) { + if (future.v7_fetcherPersist) { + activeFetchers.set(key, (activeFetchers.get(key) || 0) + 1); + // If this fetcher was previously marked for deletion, unmark it since we + // have a new instance + if (deletedFetchers.has(key)) { + deletedFetchers.delete(key); + } + } + return state.fetchers.get(key) || IDLE_FETCHER; + } + function deleteFetcher(key) { + let fetcher = state.fetchers.get(key); + // Don't abort the controller if this is a deletion of a fetcher.submit() + // in it's loading phase since - we don't want to abort the corresponding + // revalidation and want them to complete and land + if (fetchControllers.has(key) && !(fetcher && fetcher.state === "loading" && fetchReloadIds.has(key))) { + abortFetcher(key); + } + fetchLoadMatches.delete(key); + fetchReloadIds.delete(key); + fetchRedirectIds.delete(key); + deletedFetchers.delete(key); + cancelledFetcherLoads.delete(key); + state.fetchers.delete(key); + } + function deleteFetcherAndUpdateState(key) { + if (future.v7_fetcherPersist) { + let count = (activeFetchers.get(key) || 0) - 1; + if (count <= 0) { + activeFetchers.delete(key); + deletedFetchers.add(key); + } else { + activeFetchers.set(key, count); } + } else { + deleteFetcher(key); } - - /** - * Updates URL Query Params - * - * @param {object} filters - */ - }, { - key: "updateQueryParams", - value: function updateQueryParams(filters) { - var searchParams = new URLSearchParams(); - Object.entries(filters).forEach(function (_ref) { - var _ref2 = (0, _slicedToArray2["default"])(_ref, 2), - name = _ref2[0], - filter = _ref2[1]; - if (filter.value.constructor === Array) { - filter.value.forEach(function (v) { - return searchParams.append(name, v); - }); - } else { - searchParams.set(name, filter.value); + updateState({ + fetchers: new Map(state.fetchers) + }); + } + function abortFetcher(key) { + let controller = fetchControllers.get(key); + if (controller) { + controller.abort(); + fetchControllers.delete(key); + } + } + function markFetchersDone(keys) { + for (let key of keys) { + let fetcher = getFetcher(key); + let doneFetcher = getDoneFetcher(fetcher.data); + state.fetchers.set(key, doneFetcher); + } + } + function markFetchRedirectsDone() { + let doneKeys = []; + let updatedFetchers = false; + for (let key of fetchRedirectIds) { + let fetcher = state.fetchers.get(key); + invariant(fetcher, "Expected fetcher: " + key); + if (fetcher.state === "loading") { + fetchRedirectIds.delete(key); + doneKeys.push(key); + updatedFetchers = true; + } + } + markFetchersDone(doneKeys); + return updatedFetchers; + } + function abortStaleFetchLoads(landedId) { + let yeetedKeys = []; + for (let [key, id] of fetchReloadIds) { + if (id < landedId) { + let fetcher = state.fetchers.get(key); + invariant(fetcher, "Expected fetcher: " + key); + if (fetcher.state === "loading") { + abortFetcher(key); + fetchReloadIds.delete(key); + yeetedKeys.push(key); } - }); - history.replaceState({}, '', "?".concat(searchParams.toString())); + } } - - /** - * Add new filter to the filter object - * - * @param {string} name - * @param {*} value - * @param {boolean} exactMatch - */ - }, { - key: "addFilter", - value: function addFilter(name, value, exactMatch) { - var filters = this.state.filters; - filters[name] = { - value: value, - exactMatch: exactMatch - }; - this.updateFilters(filters); + markFetchersDone(yeetedKeys); + return yeetedKeys.length > 0; + } + function getBlocker(key, fn) { + let blocker = state.blockers.get(key) || IDLE_BLOCKER; + if (blockerFunctions.get(key) !== fn) { + blockerFunctions.set(key, fn); } - - /** - * Remove filter from the filter object - * - * @param {string} name - */ - }, { - key: "removeFilter", - value: function removeFilter(name) { - var filters = this.state.filters; - delete filters[name]; - this.updateFilters(filters); + return blocker; + } + function deleteBlocker(key) { + state.blockers.delete(key); + blockerFunctions.delete(key); + } + // Utility function to update blockers, ensuring valid state transitions + function updateBlocker(key, newBlocker) { + let blocker = state.blockers.get(key) || IDLE_BLOCKER; + // Poor mans state machine :) + // https://mermaid.live/edit#pako:eNqVkc9OwzAMxl8l8nnjAYrEtDIOHEBIgwvKJTReGy3_lDpIqO27k6awMG0XcrLlnz87nwdonESogKXXBuE79rq75XZO3-yHds0RJVuv70YrPlUrCEe2HfrORS3rubqZfuhtpg5C9wk5tZ4VKcRUq88q9Z8RS0-48cE1iHJkL0ugbHuFLus9L6spZy8nX9MP2CNdomVaposqu3fGayT8T8-jJQwhepo_UtpgBQaDEUom04dZhAN1aJBDlUKJBxE1ceB2Smj0Mln-IBW5AFU2dwUiktt_2Qaq2dBfaKdEup85UV7Yd-dKjlnkabl2Pvr0DTkTreM + invariant(blocker.state === "unblocked" && newBlocker.state === "blocked" || blocker.state === "blocked" && newBlocker.state === "blocked" || blocker.state === "blocked" && newBlocker.state === "proceeding" || blocker.state === "blocked" && newBlocker.state === "unblocked" || blocker.state === "proceeding" && newBlocker.state === "unblocked", "Invalid blocker state transition: " + blocker.state + " -> " + newBlocker.state); + let blockers = new Map(state.blockers); + blockers.set(key, newBlocker); + updateState({ + blockers + }); + } + function shouldBlockNavigation(_ref2) { + let { + currentLocation, + nextLocation, + historyAction + } = _ref2; + if (blockerFunctions.size === 0) { + return; } - - /** - * Sets Filter to empty object - */ - }, { - key: "clearFilters", - value: function clearFilters() { - this.updateFilters({}); + // We ony support a single active blocker at the moment since we don't have + // any compelling use cases for multi-blocker yet + if (blockerFunctions.size > 1) { + warning(false, "A router only supports one blocker at a time"); + } + let entries = Array.from(blockerFunctions.entries()); + let [blockerKey, blockerFunction] = entries[entries.length - 1]; + let blocker = state.blockers.get(blockerKey); + if (blocker && blocker.state === "proceeding") { + // If the blocker is currently proceeding, we don't need to re-check + // it and can let this navigation continue + return; } - - /** - * Returns the filter state, with filters that are - * set to an invalid option removed from the returned - * filters - * - * @return {object} - */ - }, { - key: "validFilters", - value: function validFilters() { - var _this2 = this; - var filters = {}; - this.props.fields.forEach(function (field) { - if (!field.filter) { - return; - } - var filtername = field.filter.name; - var filterval = _this2.state.filters[filtername]; - if (!filterval) { - return; - } - if (field.filter.type !== 'select') { - filters[filtername] = filterval; - return; - } - if (!(filterval.value in field.filter.options)) { - return; - } - filters[filtername] = filterval; - }); - return filters; + // At this point, we know we're unblocked/blocked so we need to check the + // user-provided blocker function + if (blockerFunction({ + currentLocation, + nextLocation, + historyAction + })) { + return blockerKey; } - - /** - * Renders the React component. - * - * @return {JSX} - React markup for the component - */ - }, { - key: "render", - value: function render() { - var filters = this.validFilters(); - var filter = /*#__PURE__*/_react["default"].createElement(_Filter["default"], { - name: this.props.name + '_filter', - id: this.props.name + '_filter', - columns: this.props.columns, - filters: filters, - filterPresets: this.props.filterPresets, - fields: this.props.fields, - addFilter: this.addFilter, - updateFilters: this.updateFilters, - removeFilter: this.removeFilter, - clearFilters: this.clearFilters - }); - var progress = this.props.progress; - var dataTable = !isNaN(progress) && progress < 100 ? /*#__PURE__*/_react["default"].createElement(_ProgressBar["default"], { - value: progress - }) : /*#__PURE__*/_react["default"].createElement(_DataTable["default"], { - data: this.props.data, - fields: this.props.fields, - filters: filters, - actions: this.props.actions, - loading: this.props.loading, - getFormattedCell: this.props.getFormattedCell, - getMappedCell: this.props.getMappedCell, - folder: this.props.folder, - nullTableShow: this.props.nullTableShow, - noDynamicTable: this.props.noDynamicTable - }); - return /*#__PURE__*/_react["default"].createElement(_Panel["default"], { - title: this.props.title - }, filter, this.props.children, dataTable); + } + function handleNavigational404(pathname) { + let error = getInternalRouterError(404, { + pathname + }); + let routesToUse = inFlightDataRoutes || dataRoutes; + let { + matches, + route + } = getShortCircuitMatches(routesToUse); + // Cancel all pending deferred on 404s since we don't keep any routes + cancelActiveDeferreds(); + return { + notFoundMatches: matches, + route, + error + }; + } + function cancelActiveDeferreds(predicate) { + let cancelledRouteIds = []; + activeDeferreds.forEach((dfd, routeId) => { + if (!predicate || predicate(routeId)) { + // Cancel the deferred - but do not remove from activeDeferreds here - + // we rely on the subscribers to do that so our tests can assert proper + // cleanup via _internalActiveDeferreds + dfd.cancel(); + cancelledRouteIds.push(routeId); + activeDeferreds.delete(routeId); + } + }); + return cancelledRouteIds; + } + // Opt in to capturing and reporting scroll positions during navigations, + // used by the component + function enableScrollRestoration(positions, getPosition, getKey) { + savedScrollPositions = positions; + getScrollPosition = getPosition; + getScrollRestorationKey = getKey || null; + // Perform initial hydration scroll restoration, since we miss the boat on + // the initial updateState() because we've not yet rendered + // and therefore have no savedScrollPositions available + if (!initialScrollRestored && state.navigation === IDLE_NAVIGATION) { + initialScrollRestored = true; + let y = getSavedScrollPosition(state.location, state.matches); + if (y != null) { + updateState({ + restoreScrollPosition: y + }); + } } - }]); -}(_react.Component); -FilterableDataTable.defaultProps = { - columns: 3, - noDynamicTable: false -}; -FilterableDataTable.propTypes = { - name: _propTypes["default"].string.isRequired, - title: _propTypes["default"].string, - data: _propTypes["default"].array.isRequired, - filterPresets: _propTypes["default"].object, - fields: _propTypes["default"].array.isRequired, - columns: _propTypes["default"].number, - getFormattedCell: _propTypes["default"].func, - actions: _propTypes["default"].array, - updateFilterCallback: _propTypes["default"].func, - noDynamicTable: _propTypes["default"].bool, - loading: _propTypes["default"].element, - progress: _propTypes["default"].number, - getMappedCell: _propTypes["default"].func, - folder: _propTypes["default"].element, - nullTableShow: _propTypes["default"].element, - children: _propTypes["default"].node -}; -var _default = exports["default"] = FilterableDataTable; - -/***/ }), - -/***/ "./jsx/Form.js": -/*!*********************!*\ - !*** ./jsx/Form.js ***! - \*********************/ -/***/ ((__unused_webpack_module, exports, __webpack_require__) => { - -"use strict"; - - -var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js"); -var _typeof3 = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js"); -Object.defineProperty(exports, "__esModule", ({ - value: true -})); -exports["default"] = exports.TimeElement = exports.TextboxElement = exports.TextareaElement = exports.TagsElement = exports.StaticElement = exports.SliderElement = exports.SelectElement = exports.SearchableDropdown = exports.RadioElement = exports.PasswordElement = exports.NumericElement = exports.LorisElement = exports.LinkElement = exports.HeaderElement = exports.FormElement = exports.FileElement = exports.FieldsetElement = exports.EmailElement = exports.DateTimeElement = exports.DateElement = exports.CheckboxElement = exports.CTA = exports.ButtonElement = void 0; -var _defineProperty2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js")); -var _typeof2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js")); -var _classCallCheck2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "./node_modules/@babel/runtime/helpers/classCallCheck.js")); -var _createClass2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/createClass */ "./node_modules/@babel/runtime/helpers/createClass.js")); -var _possibleConstructorReturn2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "./node_modules/@babel/runtime/helpers/possibleConstructorReturn.js")); -var _getPrototypeOf2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "./node_modules/@babel/runtime/helpers/getPrototypeOf.js")); -var _inherits2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/inherits */ "./node_modules/@babel/runtime/helpers/inherits.js")); -var _react = _interopRequireWildcard(__webpack_require__(/*! react */ "react")); -var _propTypes = _interopRequireDefault(__webpack_require__(/*! prop-types */ "./node_modules/prop-types/index.js")); -var _InputLabel = _interopRequireDefault(__webpack_require__(/*! jsx/form/InputLabel */ "./jsx/form/InputLabel.tsx")); -function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } -function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } -function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); } -function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /** - * This file contains React components for Loris form elements. - * - * @author Loris Team - * @version 1.0.0 - */ -/** - * Form Component. - * React wrapper for element that accepts children react components - * - * The form elements can be passed in two ways: - * 1. A `this.props.formElements` JSON object - * 2. Form components nested directly inside - * - * Note that if both are passed `this.props.formElements` is displayed first. - * - */ -var FormElement = exports.FormElement = /*#__PURE__*/function (_Component) { + return () => { + savedScrollPositions = null; + getScrollPosition = null; + getScrollRestorationKey = null; + }; + } + function getScrollKey(location, matches) { + if (getScrollRestorationKey) { + let key = getScrollRestorationKey(location, matches.map(m => convertRouteMatchToUiMatch(m, state.loaderData))); + return key || location.key; + } + return location.key; + } + function saveScrollPosition(location, matches) { + if (savedScrollPositions && getScrollPosition) { + let key = getScrollKey(location, matches); + savedScrollPositions[key] = getScrollPosition(); + } + } + function getSavedScrollPosition(location, matches) { + if (savedScrollPositions) { + let key = getScrollKey(location, matches); + let y = savedScrollPositions[key]; + if (typeof y === "number") { + return y; + } + } + return null; + } + function checkFogOfWar(matches, routesToUse, pathname) { + if (patchRoutesOnNavigationImpl) { + if (!matches) { + let fogMatches = matchRoutesImpl(routesToUse, pathname, basename, true); + return { + active: true, + matches: fogMatches || [] + }; + } else { + if (Object.keys(matches[0].params).length > 0) { + // If we matched a dynamic param or a splat, it might only be because + // we haven't yet discovered other routes that would match with a + // higher score. Call patchRoutesOnNavigation just to be sure + let partialMatches = matchRoutesImpl(routesToUse, pathname, basename, true); + return { + active: true, + matches: partialMatches + }; + } + } + } + return { + active: false, + matches: null + }; + } + async function discoverRoutes(matches, pathname, signal) { + if (!patchRoutesOnNavigationImpl) { + return { + type: "success", + matches + }; + } + let partialMatches = matches; + while (true) { + let isNonHMR = inFlightDataRoutes == null; + let routesToUse = inFlightDataRoutes || dataRoutes; + let localManifest = manifest; + try { + await patchRoutesOnNavigationImpl({ + path: pathname, + matches: partialMatches, + patch: (routeId, children) => { + if (signal.aborted) return; + patchRoutesImpl(routeId, children, routesToUse, localManifest, mapRouteProperties); + } + }); + } catch (e) { + return { + type: "error", + error: e, + partialMatches + }; + } finally { + // If we are not in the middle of an HMR revalidation and we changed the + // routes, provide a new identity so when we `updateState` at the end of + // this navigation/fetch `router.routes` will be a new identity and + // trigger a re-run of memoized `router.routes` dependencies. + // HMR will already update the identity and reflow when it lands + // `inFlightDataRoutes` in `completeNavigation` + if (isNonHMR && !signal.aborted) { + dataRoutes = [...dataRoutes]; + } + } + if (signal.aborted) { + return { + type: "aborted" + }; + } + let newMatches = matchRoutes(routesToUse, pathname, basename); + if (newMatches) { + return { + type: "success", + matches: newMatches + }; + } + let newPartialMatches = matchRoutesImpl(routesToUse, pathname, basename, true); + // Avoid loops if the second pass results in the same partial matches + if (!newPartialMatches || partialMatches.length === newPartialMatches.length && partialMatches.every((m, i) => m.route.id === newPartialMatches[i].route.id)) { + return { + type: "success", + matches: null + }; + } + partialMatches = newPartialMatches; + } + } + function _internalSetRoutes(newRoutes) { + manifest = {}; + inFlightDataRoutes = convertRoutesToDataRoutes(newRoutes, mapRouteProperties, undefined, manifest); + } + function patchRoutes(routeId, children) { + let isNonHMR = inFlightDataRoutes == null; + let routesToUse = inFlightDataRoutes || dataRoutes; + patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties); + // If we are not in the middle of an HMR revalidation and we changed the + // routes, provide a new identity and trigger a reflow via `updateState` + // to re-run memoized `router.routes` dependencies. + // HMR will already update the identity and reflow when it lands + // `inFlightDataRoutes` in `completeNavigation` + if (isNonHMR) { + dataRoutes = [...dataRoutes]; + updateState({}); + } + } + router = { + get basename() { + return basename; + }, + get future() { + return future; + }, + get state() { + return state; + }, + get routes() { + return dataRoutes; + }, + get window() { + return routerWindow; + }, + initialize, + subscribe, + enableScrollRestoration, + navigate, + fetch, + revalidate, + // Passthrough to history-aware createHref used by useHref so we get proper + // hash-aware URLs in DOM paths + createHref: to => init.history.createHref(to), + encodeLocation: to => init.history.encodeLocation(to), + getFetcher, + deleteFetcher: deleteFetcherAndUpdateState, + dispose, + getBlocker, + deleteBlocker, + patchRoutes, + _internalFetchControllers: fetchControllers, + _internalActiveDeferreds: activeDeferreds, + // TODO: Remove setRoutes, it's temporary to avoid dealing with + // updating the tree while validating the update algorithm. + _internalSetRoutes + }; + return router; +} +//#endregion +//////////////////////////////////////////////////////////////////////////////// +//#region createStaticHandler +//////////////////////////////////////////////////////////////////////////////// +const UNSAFE_DEFERRED_SYMBOL = Symbol("deferred"); +function createStaticHandler(routes, opts) { + invariant(routes.length > 0, "You must provide a non-empty routes array to createStaticHandler"); + let manifest = {}; + let basename = (opts ? opts.basename : null) || "/"; + let mapRouteProperties; + if (opts != null && opts.mapRouteProperties) { + mapRouteProperties = opts.mapRouteProperties; + } else if (opts != null && opts.detectErrorBoundary) { + // If they are still using the deprecated version, wrap it with the new API + let detectErrorBoundary = opts.detectErrorBoundary; + mapRouteProperties = route => ({ + hasErrorBoundary: detectErrorBoundary(route) + }); + } else { + mapRouteProperties = defaultMapRouteProperties; + } + // Config driven behavior flags + let future = _extends({ + v7_relativeSplatPath: false, + v7_throwAbortReason: false + }, opts ? opts.future : null); + let dataRoutes = convertRoutesToDataRoutes(routes, mapRouteProperties, undefined, manifest); /** - * @constructor - * @param {object} props - React Component properties + * The query() method is intended for document requests, in which we want to + * call an optional action and potentially multiple loaders for all nested + * routes. It returns a StaticHandlerContext object, which is very similar + * to the router state (location, loaderData, actionData, errors, etc.) and + * also adds SSR-specific information such as the statusCode and headers + * from action/loaders Responses. + * + * It _should_ never throw and should report all errors through the + * returned context.errors object, properly associating errors to their error + * boundary. Additionally, it tracks _deepestRenderedBoundaryId which can be + * used to emulate React error boundaries during SSr by performing a second + * pass only down to the boundaryId. + * + * The one exception where we do not return a StaticHandlerContext is when a + * redirect response is returned or thrown from any action/loader. We + * propagate that out and return the raw Response so the HTTP server can + * return it directly. + * + * - `opts.requestContext` is an optional server context that will be passed + * to actions/loaders in the `context` parameter + * - `opts.skipLoaderErrorBubbling` is an optional parameter that will prevent + * the bubbling of errors which allows single-fetch-type implementations + * where the client will handle the bubbling and we may need to return data + * for the handling route */ - function FormElement(props) { - var _this; - (0, _classCallCheck2["default"])(this, FormElement); - _this = _callSuper(this, FormElement, [props]); - _this.getFormElements = _this.getFormElements.bind(_this); - _this.handleSubmit = _this.handleSubmit.bind(_this); - return _this; + async function query(request, _temp3) { + let { + requestContext, + skipLoaderErrorBubbling, + dataStrategy + } = _temp3 === void 0 ? {} : _temp3; + let url = new URL(request.url); + let method = request.method; + let location = createLocation("", createPath(url), null, "default"); + let matches = matchRoutes(dataRoutes, location, basename); + // SSR supports HEAD requests while SPA doesn't + if (!isValidMethod(method) && method !== "HEAD") { + let error = getInternalRouterError(405, { + method + }); + let { + matches: methodNotAllowedMatches, + route + } = getShortCircuitMatches(dataRoutes); + return { + basename, + location, + matches: methodNotAllowedMatches, + loaderData: {}, + actionData: null, + errors: { + [route.id]: error + }, + statusCode: error.status, + loaderHeaders: {}, + actionHeaders: {}, + activeDeferreds: null + }; + } else if (!matches) { + let error = getInternalRouterError(404, { + pathname: location.pathname + }); + let { + matches: notFoundMatches, + route + } = getShortCircuitMatches(dataRoutes); + return { + basename, + location, + matches: notFoundMatches, + loaderData: {}, + actionData: null, + errors: { + [route.id]: error + }, + statusCode: error.status, + loaderHeaders: {}, + actionHeaders: {}, + activeDeferreds: null + }; + } + let result = await queryImpl(request, location, matches, requestContext, dataStrategy || null, skipLoaderErrorBubbling === true, null); + if (isResponse(result)) { + return result; + } + // When returning StaticHandlerContext, we patch back in the location here + // since we need it for React Context. But this helps keep our submit and + // loadRouteData operating on a Request instead of a Location + return _extends({ + location, + basename + }, result); } - /** - * Get form elements + * The queryRoute() method is intended for targeted route requests, either + * for fetch ?_data requests or resource route requests. In this case, we + * are only ever calling a single action or loader, and we are returning the + * returned value directly. In most cases, this will be a Response returned + * from the action/loader, but it may be a primitive or other value as well - + * and in such cases the calling context should handle that accordingly. * - * @return {JSX[]} - An array of element React markup + * We do respect the throw/return differentiation, so if an action/loader + * throws, then this method will throw the value. This is important so we + * can do proper boundary identification in Remix where a thrown Response + * must go to the Catch Boundary but a returned Response is happy-path. + * + * One thing to note is that any Router-initiated Errors that make sense + * to associate with a status code will be thrown as an ErrorResponse + * instance which include the raw Error, such that the calling context can + * serialize the error as they see fit while including the proper response + * code. Examples here are 404 and 405 errors that occur prior to reaching + * any user-defined loaders. + * + * - `opts.routeId` allows you to specify the specific route handler to call. + * If not provided the handler will determine the proper route by matching + * against `request.url` + * - `opts.requestContext` is an optional server context that will be passed + * to actions/loaders in the `context` parameter */ - (0, _inherits2["default"])(FormElement, _Component); - return (0, _createClass2["default"])(FormElement, [{ - key: "getFormElements", - value: function getFormElements() { - var formElementsHTML = []; - var columns = this.props.columns; - var maxColumnSize = 12; - var colSize = Math.floor(maxColumnSize / columns); - var colClass = 'col-xs-12 col-sm-' + colSize + ' col-md-' + colSize; - - // Render elements from JSON - var filter = this.props.formElements; - Object.keys(filter).forEach(function (objKey, index) { - var userInput = this.props.onUserInput ? this.props.onUserInput : filter[objKey].onUserInput; - var value = filter[objKey].value ? filter[objKey].value : ''; - formElementsHTML.push(/*#__PURE__*/_react["default"].createElement("div", { - key: 'el_' + index, - className: colClass - }, /*#__PURE__*/_react["default"].createElement(LorisElement, { - element: filter[objKey], - onUserInput: userInput, - value: value - }))); - }.bind(this)); - - // Render elements from React - _react["default"].Children.forEach(this.props.children, function (child, key) { - // If child is plain HTML, insert it as full size. - // Useful for inserting
to split form sections - var elementClass = 'col-xs-12 col-sm-12 col-md-12'; - - // If child is form element use appropriate size - if (/*#__PURE__*/_react["default"].isValidElement(child) && typeof child.type === 'function') { - elementClass = colClass; + async function queryRoute(request, _temp4) { + let { + routeId, + requestContext, + dataStrategy + } = _temp4 === void 0 ? {} : _temp4; + let url = new URL(request.url); + let method = request.method; + let location = createLocation("", createPath(url), null, "default"); + let matches = matchRoutes(dataRoutes, location, basename); + // SSR supports HEAD requests while SPA doesn't + if (!isValidMethod(method) && method !== "HEAD" && method !== "OPTIONS") { + throw getInternalRouterError(405, { + method + }); + } else if (!matches) { + throw getInternalRouterError(404, { + pathname: location.pathname + }); + } + let match = routeId ? matches.find(m => m.route.id === routeId) : getTargetMatch(matches, location); + if (routeId && !match) { + throw getInternalRouterError(403, { + pathname: location.pathname, + routeId + }); + } else if (!match) { + // This should never hit I don't think? + throw getInternalRouterError(404, { + pathname: location.pathname + }); + } + let result = await queryImpl(request, location, matches, requestContext, dataStrategy || null, false, match); + if (isResponse(result)) { + return result; + } + let error = result.errors ? Object.values(result.errors)[0] : undefined; + if (error !== undefined) { + // If we got back result.errors, that means the loader/action threw + // _something_ that wasn't a Response, but it's not guaranteed/required + // to be an `instanceof Error` either, so we have to use throw here to + // preserve the "error" state outside of queryImpl. + throw error; + } + // Pick off the right state value to return + if (result.actionData) { + return Object.values(result.actionData)[0]; + } + if (result.loaderData) { + var _result$activeDeferre; + let data = Object.values(result.loaderData)[0]; + if ((_result$activeDeferre = result.activeDeferreds) != null && _result$activeDeferre[match.route.id]) { + data[UNSAFE_DEFERRED_SYMBOL] = result.activeDeferreds[match.route.id]; + } + return data; + } + return undefined; + } + async function queryImpl(request, location, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch) { + invariant(request.signal, "query()/queryRoute() requests must contain an AbortController signal"); + try { + if (isMutationMethod(request.method.toLowerCase())) { + let result = await submit(request, matches, routeMatch || getTargetMatch(matches, location), requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch != null); + return result; + } + let result = await loadRouteData(request, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch); + return isResponse(result) ? result : _extends({}, result, { + actionData: null, + actionHeaders: {} + }); + } catch (e) { + // If the user threw/returned a Response in callLoaderOrAction for a + // `queryRoute` call, we throw the `DataStrategyResult` to bail out early + // and then return or throw the raw Response here accordingly + if (isDataStrategyResult(e) && isResponse(e.result)) { + if (e.type === ResultType.error) { + throw e.result; + } + return e.result; + } + // Redirects are always returned since they don't propagate to catch + // boundaries + if (isRedirectResponse(e)) { + return e; + } + throw e; + } + } + async function submit(request, matches, actionMatch, requestContext, dataStrategy, skipLoaderErrorBubbling, isRouteRequest) { + let result; + if (!actionMatch.route.action && !actionMatch.route.lazy) { + let error = getInternalRouterError(405, { + method: request.method, + pathname: new URL(request.url).pathname, + routeId: actionMatch.route.id + }); + if (isRouteRequest) { + throw error; + } + result = { + type: ResultType.error, + error + }; + } else { + let results = await callDataStrategy("action", request, [actionMatch], matches, isRouteRequest, requestContext, dataStrategy); + result = results[actionMatch.route.id]; + if (request.signal.aborted) { + throwStaticHandlerAbortedError(request, isRouteRequest, future); + } + } + if (isRedirectResult(result)) { + // Uhhhh - this should never happen, we should always throw these from + // callLoaderOrAction, but the type narrowing here keeps TS happy and we + // can get back on the "throw all redirect responses" train here should + // this ever happen :/ + throw new Response(null, { + status: result.response.status, + headers: { + Location: result.response.headers.get("Location") } - formElementsHTML.push(/*#__PURE__*/_react["default"].createElement("div", { - key: 'el_child_' + key, - className: elementClass - }, child)); }); - return formElementsHTML; } - - /** - * Execute onSubmit - * - * @param {object} e - Event - */ - }, { - key: "handleSubmit", - value: function handleSubmit(e) { - // Override default submit if property is set - if (this.props.onSubmit) { - e.preventDefault(); - this.props.onSubmit(e); + if (isDeferredResult(result)) { + let error = getInternalRouterError(400, { + type: "defer-action" + }); + if (isRouteRequest) { + throw error; } + result = { + type: ResultType.error, + error + }; } - - /** - * Renders the React component. - * - * @return {JSX} - React markup for the component - */ - }, { - key: "render", - value: function render() { - var encType = this.props.fileUpload ? 'multipart/form-data' : null; - - // Generate form elements - var formElements = this.getFormElements(); - - // Flexbox is set to ensure that columns of different heights - // are displayed proportionally on the screen - var rowStyles = { - display: 'flex', - flexWrap: 'wrap' + if (isRouteRequest) { + // Note: This should only be non-Response values if we get here, since + // isRouteRequest should throw any Response received in callLoaderOrAction + if (isErrorResult(result)) { + throw result.error; + } + return { + matches: [actionMatch], + loaderData: {}, + actionData: { + [actionMatch.route.id]: result.data + }, + errors: null, + // Note: statusCode + headers are unused here since queryRoute will + // return the raw Response or value + statusCode: 200, + loaderHeaders: {}, + actionHeaders: {}, + activeDeferreds: null }; - return /*#__PURE__*/_react["default"].createElement("form", { - name: this.props.name, - id: this.props.id, - className: this.props["class"], - method: this.props.method, - action: this.props.action, - encType: encType, - onSubmit: this.handleSubmit - }, /*#__PURE__*/_react["default"].createElement("div", { - className: "row", - style: rowStyles - }, formElements)); } - }]); -}(_react.Component); -FormElement.propTypes = { - name: _propTypes["default"].string.isRequired, - id: _propTypes["default"].string, - method: _propTypes["default"].oneOf(['POST', 'GET']), - action: _propTypes["default"].string, - "class": _propTypes["default"].string, - columns: _propTypes["default"].number, - formElements: _propTypes["default"].shape({ - elementName: _propTypes["default"].shape({ - name: _propTypes["default"].string, - type: _propTypes["default"].string - }) - }), - onSubmit: _propTypes["default"].func, - onUserInput: _propTypes["default"].func, - children: _propTypes["default"].node, - fileUpload: _propTypes["default"].bool -}; -FormElement.defaultProps = { - name: null, - id: null, - method: 'POST', - action: undefined, - "class": 'form-horizontal', - columns: 1, - fileUpload: false, - formElements: {}, - onSubmit: function onSubmit() { - console.warn('onSubmit() callback is not set!'); - } -}; - -/** - * FieldsetElement Component. - * React wrapper for
element that is nested inside , - * and accepts child react components. A fieldset groups related elements in a form. - * - * The form elements can be passed by nesting Form components directly inside . - * - */ -var FieldsetElement = exports.FieldsetElement = /*#__PURE__*/function (_Component2) { - /** - * @constructor - * @param {object} props - React Component properties - */ - function FieldsetElement(props) { - var _this2; - (0, _classCallCheck2["default"])(this, FieldsetElement); - _this2 = _callSuper(this, FieldsetElement, [props]); - _this2.getFormElements = _this2.getFormElements.bind(_this2); - return _this2; + // Create a GET request for the loaders + let loaderRequest = new Request(request.url, { + headers: request.headers, + redirect: request.redirect, + signal: request.signal + }); + if (isErrorResult(result)) { + // Store off the pending error - we use it to determine which loaders + // to call and will commit it when we complete the navigation + let boundaryMatch = skipLoaderErrorBubbling ? actionMatch : findNearestBoundary(matches, actionMatch.route.id); + let context = await loadRouteData(loaderRequest, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, null, [boundaryMatch.route.id, result]); + // action status codes take precedence over loader status codes + return _extends({}, context, { + statusCode: isRouteErrorResponse(result.error) ? result.error.status : result.statusCode != null ? result.statusCode : 500, + actionData: null, + actionHeaders: _extends({}, result.headers ? { + [actionMatch.route.id]: result.headers + } : {}) + }); + } + let context = await loadRouteData(loaderRequest, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, null); + return _extends({}, context, { + actionData: { + [actionMatch.route.id]: result.data + } + }, result.statusCode ? { + statusCode: result.statusCode + } : {}, { + actionHeaders: result.headers ? { + [actionMatch.route.id]: result.headers + } : {} + }); } - - /** - * Get form elements - * - * @return {JSX[]} - An array of element React markup - */ - (0, _inherits2["default"])(FieldsetElement, _Component2); - return (0, _createClass2["default"])(FieldsetElement, [{ - key: "getFormElements", - value: function getFormElements() { - var formElementsHTML = []; - var columns = this.props.columns; - var maxColumnSize = 12; - var colSize = Math.floor(maxColumnSize / columns); - var colClass = 'col-xs-12 col-sm-' + colSize + ' col-md-' + colSize; - - // Render elements from React - _react["default"].Children.forEach(this.props.children, function (child, key) { - // If child is plain HTML, insert it as full size. - // Useful for inserting
to split form sections - var elementClass = 'col-xs-12 col-sm-12 col-md-12'; - - // If child is form element use appropriate size - if (/*#__PURE__*/_react["default"].isValidElement(child) && typeof child.type === 'function') { - elementClass = colClass; - } - formElementsHTML.push(/*#__PURE__*/_react["default"].createElement("div", { - key: 'el_child_' + key, - className: elementClass - }, child)); + async function loadRouteData(request, matches, requestContext, dataStrategy, skipLoaderErrorBubbling, routeMatch, pendingActionResult) { + let isRouteRequest = routeMatch != null; + // Short circuit if we have no loaders to run (queryRoute()) + if (isRouteRequest && !(routeMatch != null && routeMatch.route.loader) && !(routeMatch != null && routeMatch.route.lazy)) { + throw getInternalRouterError(400, { + method: request.method, + pathname: new URL(request.url).pathname, + routeId: routeMatch == null ? void 0 : routeMatch.route.id }); - return formElementsHTML; } - - /** - * Renders the React component. - * - * @return {JSX} - React markup for the component - */ - }, { - key: "render", - value: function render() { - // Generate form elements - var formElements = this.getFormElements(); - return /*#__PURE__*/_react["default"].createElement("fieldset", { - name: this.props.name - }, /*#__PURE__*/_react["default"].createElement("legend", null, this.props.legend), formElements); + let requestMatches = routeMatch ? [routeMatch] : pendingActionResult && isErrorResult(pendingActionResult[1]) ? getLoaderMatchesUntilBoundary(matches, pendingActionResult[0]) : matches; + let matchesToLoad = requestMatches.filter(m => m.route.loader || m.route.lazy); + // Short circuit if we have no loaders to run (query()) + if (matchesToLoad.length === 0) { + return { + matches, + // Add a null for all matched routes for proper revalidation on the client + loaderData: matches.reduce((acc, m) => Object.assign(acc, { + [m.route.id]: null + }), {}), + errors: pendingActionResult && isErrorResult(pendingActionResult[1]) ? { + [pendingActionResult[0]]: pendingActionResult[1].error + } : null, + statusCode: 200, + loaderHeaders: {}, + activeDeferreds: null + }; } - }]); -}(_react.Component); -FieldsetElement.propTypes = { - columns: _propTypes["default"].number, - name: _propTypes["default"].string, - legend: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].node]), - children: _propTypes["default"].node -}; -FieldsetElement.defaultProps = { - columns: 1, - legend: 'Selection Filter' -}; - + let results = await callDataStrategy("loader", request, matchesToLoad, matches, isRouteRequest, requestContext, dataStrategy); + if (request.signal.aborted) { + throwStaticHandlerAbortedError(request, isRouteRequest, future); + } + // Process and commit output from loaders + let activeDeferreds = new Map(); + let context = processRouteLoaderData(matches, results, pendingActionResult, activeDeferreds, skipLoaderErrorBubbling); + // Add a null for any non-loader matches for proper revalidation on the client + let executedLoaders = new Set(matchesToLoad.map(match => match.route.id)); + matches.forEach(match => { + if (!executedLoaders.has(match.route.id)) { + context.loaderData[match.route.id] = null; + } + }); + return _extends({}, context, { + matches, + activeDeferreds: activeDeferreds.size > 0 ? Object.fromEntries(activeDeferreds.entries()) : null + }); + } + // Utility wrapper for calling dataStrategy server-side without having to + // pass around the manifest, mapRouteProperties, etc. + async function callDataStrategy(type, request, matchesToLoad, matches, isRouteRequest, requestContext, dataStrategy) { + let results = await callDataStrategyImpl(dataStrategy || defaultDataStrategy, type, null, request, matchesToLoad, matches, null, manifest, mapRouteProperties, requestContext); + let dataResults = {}; + await Promise.all(matches.map(async match => { + if (!(match.route.id in results)) { + return; + } + let result = results[match.route.id]; + if (isRedirectDataStrategyResultResult(result)) { + let response = result.result; + // Throw redirects and let the server handle them with an HTTP redirect + throw normalizeRelativeRoutingRedirectResponse(response, request, match.route.id, matches, basename, future.v7_relativeSplatPath); + } + if (isResponse(result.result) && isRouteRequest) { + // For SSR single-route requests, we want to hand Responses back + // directly without unwrapping + throw result; + } + dataResults[match.route.id] = await convertDataStrategyResultToDataResult(result); + })); + return dataResults; + } + return { + dataRoutes, + query, + queryRoute + }; +} +//#endregion +//////////////////////////////////////////////////////////////////////////////// +//#region Helpers +//////////////////////////////////////////////////////////////////////////////// /** - * Search Component - * React wrapper for a searchable dropdown + * Given an existing StaticHandlerContext and an error thrown at render time, + * provide an updated StaticHandlerContext suitable for a second SSR render */ -var SearchableDropdown = exports.SearchableDropdown = /*#__PURE__*/function (_Component3) { - /** - * @constructor - * @param {object} props - React Component properties - */ - function SearchableDropdown(props) { - var _this3; - (0, _classCallCheck2["default"])(this, SearchableDropdown); - _this3 = _callSuper(this, SearchableDropdown, [props]); - _this3.state = { - currentInput: '' - }; - _this3.getKeyFromValue = _this3.getKeyFromValue.bind(_this3); - _this3.handleChange = _this3.handleChange.bind(_this3); - _this3.handleBlur = _this3.handleBlur.bind(_this3); - return _this3; - } - - /** - * Get key from value - * - * @param {string} value - * @return {string} - */ - (0, _inherits2["default"])(SearchableDropdown, _Component3); - return (0, _createClass2["default"])(SearchableDropdown, [{ - key: "getKeyFromValue", - value: function getKeyFromValue(value) { - var options = this.props.options; - return Object.keys(options).find(function (o) { - return options[o] === value; - }); +function getStaticContextFromError(routes, context, error) { + let newContext = _extends({}, context, { + statusCode: isRouteErrorResponse(error) ? error.status : 500, + errors: { + [context._deepestRenderedBoundaryId || routes[0].id]: error } - - /** - * Handle change - * - * @param {object} e - Event - */ - }, { - key: "handleChange", - value: function handleChange(e) { - var value = this.getKeyFromValue(e.target.value); - // if not in strict mode and key value is undefined (i.e., not in options prop) - // set value equal to e.target.value - if (!this.props.strictSearch && value === undefined) { - value = e.target.value; + }); + return newContext; +} +function throwStaticHandlerAbortedError(request, isRouteRequest, future) { + if (future.v7_throwAbortReason && request.signal.reason !== undefined) { + throw request.signal.reason; + } + let method = isRouteRequest ? "queryRoute" : "query"; + throw new Error(method + "() call aborted: " + request.method + " " + request.url); +} +function isSubmissionNavigation(opts) { + return opts != null && ("formData" in opts && opts.formData != null || "body" in opts && opts.body !== undefined); +} +function normalizeTo(location, matches, basename, prependBasename, to, v7_relativeSplatPath, fromRouteId, relative) { + let contextualMatches; + let activeRouteMatch; + if (fromRouteId) { + // Grab matches up to the calling route so our route-relative logic is + // relative to the correct source route + contextualMatches = []; + for (let match of matches) { + contextualMatches.push(match); + if (match.route.id === fromRouteId) { + activeRouteMatch = match; + break; } - this.setState({ - currentInput: e.target.value - }); - this.props.onUserInput(this.props.name, value); } - - /** - * Handle blur - * - * @param {object} e - Event - */ - }, { - key: "handleBlur", - value: function handleBlur(e) { - // null out entry if not present in options in strict mode - if (this.props.strictSearch) { - var value = e.target.value; - var options = this.props.options; - if (Object.values(options).indexOf(value) === -1) { - // empty string out both the hidden value as well as the input text - this.setState({ - currentInput: '' - }); - this.props.onUserInput(this.props.name, ''); + } else { + contextualMatches = matches; + activeRouteMatch = matches[matches.length - 1]; + } + // Resolve the relative path + let path = resolveTo(to ? to : ".", getResolveToMatches(contextualMatches, v7_relativeSplatPath), stripBasename(location.pathname, basename) || location.pathname, relative === "path"); + // When `to` is not specified we inherit search/hash from the current + // location, unlike when to="." and we just inherit the path. + // See https://github.com/remix-run/remix/issues/927 + if (to == null) { + path.search = location.search; + path.hash = location.hash; + } + // Account for `?index` params when routing to the current location + if ((to == null || to === "" || to === ".") && activeRouteMatch) { + let nakedIndex = hasNakedIndexQuery(path.search); + if (activeRouteMatch.route.index && !nakedIndex) { + // Add one when we're targeting an index route + path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index"; + } else if (!activeRouteMatch.route.index && nakedIndex) { + // Remove existing ones when we're not + let params = new URLSearchParams(path.search); + let indexValues = params.getAll("index"); + params.delete("index"); + indexValues.filter(v => v).forEach(v => params.append("index", v)); + let qs = params.toString(); + path.search = qs ? "?" + qs : ""; + } + } + // If we're operating within a basename, prepend it to the pathname. If + // this is a root navigation, then just use the raw basename which allows + // the basename to have full control over the presence of a trailing slash + // on root actions + if (prependBasename && basename !== "/") { + path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]); + } + return createPath(path); +} +// Normalize navigation options by converting formMethod=GET formData objects to +// URLSearchParams so they behave identically to links with query params +function normalizeNavigateOptions(normalizeFormMethod, isFetcher, path, opts) { + // Return location verbatim on non-submission navigations + if (!opts || !isSubmissionNavigation(opts)) { + return { + path + }; + } + if (opts.formMethod && !isValidMethod(opts.formMethod)) { + return { + path, + error: getInternalRouterError(405, { + method: opts.formMethod + }) + }; + } + let getInvalidBodyError = () => ({ + path, + error: getInternalRouterError(400, { + type: "invalid-body" + }) + }); + // Create a Submission on non-GET navigations + let rawFormMethod = opts.formMethod || "get"; + let formMethod = normalizeFormMethod ? rawFormMethod.toUpperCase() : rawFormMethod.toLowerCase(); + let formAction = stripHashFromPath(path); + if (opts.body !== undefined) { + if (opts.formEncType === "text/plain") { + // text only support POST/PUT/PATCH/DELETE submissions + if (!isMutationMethod(formMethod)) { + return getInvalidBodyError(); + } + let text = typeof opts.body === "string" ? opts.body : opts.body instanceof FormData || opts.body instanceof URLSearchParams ? + // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#plain-text-form-data + Array.from(opts.body.entries()).reduce((acc, _ref3) => { + let [name, value] = _ref3; + return "" + acc + name + "=" + value + "\n"; + }, "") : String(opts.body); + return { + path, + submission: { + formMethod, + formAction, + formEncType: opts.formEncType, + formData: undefined, + json: undefined, + text } + }; + } else if (opts.formEncType === "application/json") { + // json only supports POST/PUT/PATCH/DELETE submissions + if (!isMutationMethod(formMethod)) { + return getInvalidBodyError(); } + try { + let json = typeof opts.body === "string" ? JSON.parse(opts.body) : opts.body; + return { + path, + submission: { + formMethod, + formAction, + formEncType: opts.formEncType, + formData: undefined, + json, + text: undefined + } + }; + } catch (e) { + return getInvalidBodyError(); + } + } + } + invariant(typeof FormData === "function", "FormData is not available in this environment"); + let searchParams; + let formData; + if (opts.formData) { + searchParams = convertFormDataToSearchParams(opts.formData); + formData = opts.formData; + } else if (opts.body instanceof FormData) { + searchParams = convertFormDataToSearchParams(opts.body); + formData = opts.body; + } else if (opts.body instanceof URLSearchParams) { + searchParams = opts.body; + formData = convertSearchParamsToFormData(searchParams); + } else if (opts.body == null) { + searchParams = new URLSearchParams(); + formData = new FormData(); + } else { + try { + searchParams = new URLSearchParams(opts.body); + formData = convertSearchParamsToFormData(searchParams); + } catch (e) { + return getInvalidBodyError(); } - - /** - * Called by React when the component is updated. - * - * @param {object} prevProps - Previous React Component properties - */ - }, { - key: "componentDidUpdate", - value: function componentDidUpdate(prevProps) { - // need to clear out currentInput for when props.value gets wiped - // if the previous value prop contained data and the current one doesn't - // clear currentInput - if (prevProps.value && !this.props.value) { - this.setState({ - currentInput: '' - }); - } + } + let submission = { + formMethod, + formAction, + formEncType: opts && opts.formEncType || "application/x-www-form-urlencoded", + formData, + json: undefined, + text: undefined + }; + if (isMutationMethod(submission.formMethod)) { + return { + path, + submission + }; + } + // Flatten submission onto URLSearchParams for GET submissions + let parsedPath = parsePath(path); + // On GET navigation submissions we can drop the ?index param from the + // resulting location since all loaders will run. But fetcher GET submissions + // only run a single loader so we need to preserve any incoming ?index params + if (isFetcher && parsedPath.search && hasNakedIndexQuery(parsedPath.search)) { + searchParams.append("index", ""); + } + parsedPath.search = "?" + searchParams; + return { + path: createPath(parsedPath), + submission + }; +} +// Filter out all routes at/below any caught error as they aren't going to +// render so we don't need to load them +function getLoaderMatchesUntilBoundary(matches, boundaryId, includeBoundary) { + if (includeBoundary === void 0) { + includeBoundary = false; + } + let index = matches.findIndex(m => m.route.id === boundaryId); + if (index >= 0) { + return matches.slice(0, includeBoundary ? index + 1 : index); + } + return matches; +} +function getMatchesToLoad(history, state, matches, submission, location, initialHydration, skipActionErrorRevalidation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionResult) { + let actionResult = pendingActionResult ? isErrorResult(pendingActionResult[1]) ? pendingActionResult[1].error : pendingActionResult[1].data : undefined; + let currentUrl = history.createURL(state.location); + let nextUrl = history.createURL(location); + // Pick navigation matches that are net-new or qualify for revalidation + let boundaryMatches = matches; + if (initialHydration && state.errors) { + // On initial hydration, only consider matches up to _and including_ the boundary. + // This is inclusive to handle cases where a server loader ran successfully, + // a child server loader bubbled up to this route, but this route has + // `clientLoader.hydrate` so we want to still run the `clientLoader` so that + // we have a complete version of `loaderData` + boundaryMatches = getLoaderMatchesUntilBoundary(matches, Object.keys(state.errors)[0], true); + } else if (pendingActionResult && isErrorResult(pendingActionResult[1])) { + // If an action threw an error, we call loaders up to, but not including the + // boundary + boundaryMatches = getLoaderMatchesUntilBoundary(matches, pendingActionResult[0]); + } + // Don't revalidate loaders by default after action 4xx/5xx responses + // when the flag is enabled. They can still opt-into revalidation via + // `shouldRevalidate` via `actionResult` + let actionStatus = pendingActionResult ? pendingActionResult[1].statusCode : undefined; + let shouldSkipRevalidation = skipActionErrorRevalidation && actionStatus && actionStatus >= 400; + let navigationMatches = boundaryMatches.filter((match, index) => { + let { + route + } = match; + if (route.lazy) { + // We haven't loaded this route yet so we don't know if it's got a loader! + return true; } - - /** - * Renders the React component. - * - * @return {JSX} - React markup for the component - */ - }, { - key: "render", - value: function render() { - var sortByValue = this.props.sortByValue; - var options = this.props.options; - var strictMessage = 'Entry must be included in provided list of options.'; - var errorMessage = null; - var elementClass = 'row form-group'; - - // Add error message - if (this.props.errorMessage) { - errorMessage = /*#__PURE__*/_react["default"].createElement("span", null, this.props.errorMessage); - elementClass = 'row form-group has-error'; - } else if (this.props.required && this.props.value === '') { - var msg = 'This field is required!'; - msg += this.props.strictSearch ? ' ' + strictMessage : ''; - errorMessage = /*#__PURE__*/_react["default"].createElement("span", null, msg); - elementClass = 'row form-group has-error'; - } else if (this.props.strictSearch && this.props.value === '') { - errorMessage = /*#__PURE__*/_react["default"].createElement("span", null, strictMessage); - elementClass = 'row form-group has-error'; - } - - // determine value to place into text input - var value = ''; - // use value in options if valid - if (this.props.value !== undefined && Object.keys(options).indexOf(this.props.value) > -1) { - value = options[this.props.value]; - // else, use input text value - } else if (this.state.currentInput) { - value = this.state.currentInput; + if (route.loader == null) { + return false; + } + if (initialHydration) { + return shouldLoadRouteOnHydration(route, state.loaderData, state.errors); + } + // Always call the loader on new route instances and pending defer cancellations + if (isNewLoader(state.loaderData, state.matches[index], match) || cancelledDeferredRoutes.some(id => id === match.route.id)) { + return true; + } + // This is the default implementation for when we revalidate. If the route + // provides it's own implementation, then we give them full control but + // provide this value so they can leverage it if needed after they check + // their own specific use cases + let currentRouteMatch = state.matches[index]; + let nextRouteMatch = match; + return shouldRevalidateLoader(match, _extends({ + currentUrl, + currentParams: currentRouteMatch.params, + nextUrl, + nextParams: nextRouteMatch.params + }, submission, { + actionResult, + actionStatus, + defaultShouldRevalidate: shouldSkipRevalidation ? false : + // Forced revalidation due to submission, useRevalidator, or X-Remix-Revalidate + isRevalidationRequired || currentUrl.pathname + currentUrl.search === nextUrl.pathname + nextUrl.search || + // Search params affect all loaders + currentUrl.search !== nextUrl.search || isNewRouteInstance(currentRouteMatch, nextRouteMatch) + })); + }); + // Pick fetcher.loads that need to be revalidated + let revalidatingFetchers = []; + fetchLoadMatches.forEach((f, key) => { + // Don't revalidate: + // - on initial hydration (shouldn't be any fetchers then anyway) + // - if fetcher won't be present in the subsequent render + // - no longer matches the URL (v7_fetcherPersist=false) + // - was unmounted but persisted due to v7_fetcherPersist=true + if (initialHydration || !matches.some(m => m.route.id === f.routeId) || deletedFetchers.has(key)) { + return; + } + let fetcherMatches = matchRoutes(routesToUse, f.path, basename); + // If the fetcher path no longer matches, push it in with null matches so + // we can trigger a 404 in callLoadersAndMaybeResolveData. Note this is + // currently only a use-case for Remix HMR where the route tree can change + // at runtime and remove a route previously loaded via a fetcher + if (!fetcherMatches) { + revalidatingFetchers.push({ + key, + routeId: f.routeId, + path: f.path, + matches: null, + match: null, + controller: null + }); + return; + } + // Revalidating fetchers are decoupled from the route matches since they + // load from a static href. They revalidate based on explicit revalidation + // (submission, useRevalidator, or X-Remix-Revalidate) + let fetcher = state.fetchers.get(key); + let fetcherMatch = getTargetMatch(fetcherMatches, f.path); + let shouldRevalidate = false; + if (fetchRedirectIds.has(key)) { + // Never trigger a revalidation of an actively redirecting fetcher + shouldRevalidate = false; + } else if (cancelledFetcherLoads.has(key)) { + // Always mark for revalidation if the fetcher was cancelled + cancelledFetcherLoads.delete(key); + shouldRevalidate = true; + } else if (fetcher && fetcher.state !== "idle" && fetcher.data === undefined) { + // If the fetcher hasn't ever completed loading yet, then this isn't a + // revalidation, it would just be a brand new load if an explicit + // revalidation is required + shouldRevalidate = isRevalidationRequired; + } else { + // Otherwise fall back on any user-defined shouldRevalidate, defaulting + // to explicit revalidations only + shouldRevalidate = shouldRevalidateLoader(fetcherMatch, _extends({ + currentUrl, + currentParams: state.matches[state.matches.length - 1].params, + nextUrl, + nextParams: matches[matches.length - 1].params + }, submission, { + actionResult, + actionStatus, + defaultShouldRevalidate: shouldSkipRevalidation ? false : isRevalidationRequired + })); + } + if (shouldRevalidate) { + revalidatingFetchers.push({ + key, + routeId: f.routeId, + path: f.path, + matches: fetcherMatches, + match: fetcherMatch, + controller: new AbortController() + }); + } + }); + return [navigationMatches, revalidatingFetchers]; +} +function shouldLoadRouteOnHydration(route, loaderData, errors) { + // We dunno if we have a loader - gotta find out! + if (route.lazy) { + return true; + } + // No loader, nothing to initialize + if (!route.loader) { + return false; + } + let hasData = loaderData != null && loaderData[route.id] !== undefined; + let hasError = errors != null && errors[route.id] !== undefined; + // Don't run if we error'd during SSR + if (!hasData && hasError) { + return false; + } + // Explicitly opting-in to running on hydration + if (typeof route.loader === "function" && route.loader.hydrate === true) { + return true; + } + // Otherwise, run if we're not yet initialized with anything + return !hasData && !hasError; +} +function isNewLoader(currentLoaderData, currentMatch, match) { + let isNew = + // [a] -> [a, b] + !currentMatch || + // [a, b] -> [a, c] + match.route.id !== currentMatch.route.id; + // Handle the case that we don't have data for a re-used route, potentially + // from a prior error or from a cancelled pending deferred + let isMissingData = currentLoaderData[match.route.id] === undefined; + // Always load if this is a net-new route or we don't yet have data + return isNew || isMissingData; +} +function isNewRouteInstance(currentMatch, match) { + let currentPath = currentMatch.route.path; + return ( + // param change for this match, /users/123 -> /users/456 + currentMatch.pathname !== match.pathname || + // splat param changed, which is not present in match.path + // e.g. /files/images/avatar.jpg -> files/finances.xls + currentPath != null && currentPath.endsWith("*") && currentMatch.params["*"] !== match.params["*"] + ); +} +function shouldRevalidateLoader(loaderMatch, arg) { + if (loaderMatch.route.shouldRevalidate) { + let routeChoice = loaderMatch.route.shouldRevalidate(arg); + if (typeof routeChoice === "boolean") { + return routeChoice; + } + } + return arg.defaultShouldRevalidate; +} +function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties) { + var _childrenToPatch; + let childrenToPatch; + if (routeId) { + let route = manifest[routeId]; + invariant(route, "No route found to patch children into: routeId = " + routeId); + if (!route.children) { + route.children = []; + } + childrenToPatch = route.children; + } else { + childrenToPatch = routesToUse; + } + // Don't patch in routes we already know about so that `patch` is idempotent + // to simplify user-land code. This is useful because we re-call the + // `patchRoutesOnNavigation` function for matched routes with params. + let uniqueChildren = children.filter(newRoute => !childrenToPatch.some(existingRoute => isSameRoute(newRoute, existingRoute))); + let newRoutes = convertRoutesToDataRoutes(uniqueChildren, mapRouteProperties, [routeId || "_", "patch", String(((_childrenToPatch = childrenToPatch) == null ? void 0 : _childrenToPatch.length) || "0")], manifest); + childrenToPatch.push(...newRoutes); +} +function isSameRoute(newRoute, existingRoute) { + // Most optimal check is by id + if ("id" in newRoute && "id" in existingRoute && newRoute.id === existingRoute.id) { + return true; + } + // Second is by pathing differences + if (!(newRoute.index === existingRoute.index && newRoute.path === existingRoute.path && newRoute.caseSensitive === existingRoute.caseSensitive)) { + return false; + } + // Pathless layout routes are trickier since we need to check children. + // If they have no children then they're the same as far as we can tell + if ((!newRoute.children || newRoute.children.length === 0) && (!existingRoute.children || existingRoute.children.length === 0)) { + return true; + } + // Otherwise, we look to see if every child in the new route is already + // represented in the existing route's children + return newRoute.children.every((aChild, i) => { + var _existingRoute$childr; + return (_existingRoute$childr = existingRoute.children) == null ? void 0 : _existingRoute$childr.some(bChild => isSameRoute(aChild, bChild)); + }); +} +/** + * Execute route.lazy() methods to lazily load route modules (loader, action, + * shouldRevalidate) and update the routeManifest in place which shares objects + * with dataRoutes so those get updated as well. + */ +async function loadLazyRouteModule(route, mapRouteProperties, manifest) { + if (!route.lazy) { + return; + } + let lazyRoute = await route.lazy(); + // If the lazy route function was executed and removed by another parallel + // call then we can return - first lazy() to finish wins because the return + // value of lazy is expected to be static + if (!route.lazy) { + return; + } + let routeToUpdate = manifest[route.id]; + invariant(routeToUpdate, "No route found in manifest"); + // Update the route in place. This should be safe because there's no way + // we could yet be sitting on this route as we can't get there without + // resolving lazy() first. + // + // This is different than the HMR "update" use-case where we may actively be + // on the route being updated. The main concern boils down to "does this + // mutation affect any ongoing navigations or any current state.matches + // values?". If not, it should be safe to update in place. + let routeUpdates = {}; + for (let lazyRouteProperty in lazyRoute) { + let staticRouteValue = routeToUpdate[lazyRouteProperty]; + let isPropertyStaticallyDefined = staticRouteValue !== undefined && + // This property isn't static since it should always be updated based + // on the route updates + lazyRouteProperty !== "hasErrorBoundary"; + warning(!isPropertyStaticallyDefined, "Route \"" + routeToUpdate.id + "\" has a static property \"" + lazyRouteProperty + "\" " + "defined but its lazy function is also returning a value for this property. " + ("The lazy route property \"" + lazyRouteProperty + "\" will be ignored.")); + if (!isPropertyStaticallyDefined && !immutableRouteKeys.has(lazyRouteProperty)) { + routeUpdates[lazyRouteProperty] = lazyRoute[lazyRouteProperty]; + } + } + // Mutate the route with the provided updates. Do this first so we pass + // the updated version to mapRouteProperties + Object.assign(routeToUpdate, routeUpdates); + // Mutate the `hasErrorBoundary` property on the route based on the route + // updates and remove the `lazy` function so we don't resolve the lazy + // route again. + Object.assign(routeToUpdate, _extends({}, mapRouteProperties(routeToUpdate), { + lazy: undefined + })); +} +// Default implementation of `dataStrategy` which fetches all loaders in parallel +async function defaultDataStrategy(_ref4) { + let { + matches + } = _ref4; + let matchesToLoad = matches.filter(m => m.shouldLoad); + let results = await Promise.all(matchesToLoad.map(m => m.resolve())); + return results.reduce((acc, result, i) => Object.assign(acc, { + [matchesToLoad[i].route.id]: result + }), {}); +} +async function callDataStrategyImpl(dataStrategyImpl, type, state, request, matchesToLoad, matches, fetcherKey, manifest, mapRouteProperties, requestContext) { + let loadRouteDefinitionsPromises = matches.map(m => m.route.lazy ? loadLazyRouteModule(m.route, mapRouteProperties, manifest) : undefined); + let dsMatches = matches.map((match, i) => { + let loadRoutePromise = loadRouteDefinitionsPromises[i]; + let shouldLoad = matchesToLoad.some(m => m.route.id === match.route.id); + // `resolve` encapsulates route.lazy(), executing the loader/action, + // and mapping return values/thrown errors to a `DataStrategyResult`. Users + // can pass a callback to take fine-grained control over the execution + // of the loader/action + let resolve = async handlerOverride => { + if (handlerOverride && request.method === "GET" && (match.route.lazy || match.route.loader)) { + shouldLoad = true; + } + return shouldLoad ? callLoaderOrAction(type, request, match, loadRoutePromise, handlerOverride, requestContext) : Promise.resolve({ + type: ResultType.data, + result: undefined + }); + }; + return _extends({}, match, { + shouldLoad, + resolve + }); + }); + // Send all matches here to allow for a middleware-type implementation. + // handler will be a no-op for unneeded routes and we filter those results + // back out below. + let results = await dataStrategyImpl({ + matches: dsMatches, + request, + params: matches[0].params, + fetcherKey, + context: requestContext + }); + // Wait for all routes to load here but 'swallow the error since we want + // it to bubble up from the `await loadRoutePromise` in `callLoaderOrAction` - + // called from `match.resolve()` + try { + await Promise.all(loadRouteDefinitionsPromises); + } catch (e) { + // No-op + } + return results; +} +// Default logic for calling a loader/action is the user has no specified a dataStrategy +async function callLoaderOrAction(type, request, match, loadRoutePromise, handlerOverride, staticContext) { + let result; + let onReject; + let runHandler = handler => { + // Setup a promise we can race against so that abort signals short circuit + let reject; + // This will never resolve so safe to type it as Promise to + // satisfy the function return value + let abortPromise = new Promise((_, r) => reject = r); + onReject = () => reject(); + request.signal.addEventListener("abort", onReject); + let actualHandler = ctx => { + if (typeof handler !== "function") { + return Promise.reject(new Error("You cannot call the handler for a route which defines a boolean " + ("\"" + type + "\" [routeId: " + match.route.id + "]"))); + } + return handler({ + request, + params: match.params, + context: staticContext + }, ...(ctx !== undefined ? [ctx] : [])); + }; + let handlerPromise = (async () => { + try { + let val = await (handlerOverride ? handlerOverride(ctx => actualHandler(ctx)) : actualHandler()); + return { + type: "data", + result: val + }; + } catch (e) { + return { + type: "error", + result: e + }; } - var newOptions = {}; - var optionList = []; - if (sortByValue) { - for (var key in options) { - if (options.hasOwnProperty(key)) { - newOptions[options[key]] = key; - } + })(); + return Promise.race([handlerPromise, abortPromise]); + }; + try { + let handler = match.route[type]; + // If we have a route.lazy promise, await that first + if (loadRoutePromise) { + if (handler) { + // Run statically defined handler in parallel with lazy() + let handlerError; + let [value] = await Promise.all([ + // If the handler throws, don't let it immediately bubble out, + // since we need to let the lazy() execution finish so we know if this + // route has a boundary that can handle the error + runHandler(handler).catch(e => { + handlerError = e; + }), loadRoutePromise]); + if (handlerError !== undefined) { + throw handlerError; } - optionList = Object.keys(newOptions).sort().map(function (option) { - return /*#__PURE__*/_react["default"].createElement("option", { - value: option, - key: newOptions[option] - }); - }); + result = value; } else { - optionList = Object.keys(options).map(function (option) { - return /*#__PURE__*/_react["default"].createElement("option", { - value: options[option], - key: option + // Load lazy route module, then run any returned handler + await loadRoutePromise; + handler = match.route[type]; + if (handler) { + // Handler still runs even if we got interrupted to maintain consistency + // with un-abortable behavior of handler execution on non-lazy or + // previously-lazy-loaded routes + result = await runHandler(handler); + } else if (type === "action") { + let url = new URL(request.url); + let pathname = url.pathname + url.search; + throw getInternalRouterError(405, { + method: request.method, + pathname, + routeId: match.route.id }); - }); + } else { + // lazy() route has no loader to run. Short circuit here so we don't + // hit the invariant below that errors on returning undefined. + return { + type: ResultType.data, + result: undefined + }; + } } - return /*#__PURE__*/_react["default"].createElement("div", { - className: elementClass - }, /*#__PURE__*/_react["default"].createElement(_InputLabel["default"], { - label: this.props.label, - required: this.props.required - }), /*#__PURE__*/_react["default"].createElement("div", { - className: "col-sm-9" - }, /*#__PURE__*/_react["default"].createElement("input", { - type: "text", - name: this.props.name + '_input', - value: value, - id: this.props.id, - list: this.props.name + '_list', - className: "form-control", - placeholder: this.props.placeHolder, - onChange: this.handleChange, - onBlur: this.handleBlur, - disabled: this.props.disabled, - required: this.props.required - }), /*#__PURE__*/_react["default"].createElement("datalist", { - id: this.props.name + '_list' - }, optionList), errorMessage)); + } else if (!handler) { + let url = new URL(request.url); + let pathname = url.pathname + url.search; + throw getInternalRouterError(404, { + pathname + }); + } else { + result = await runHandler(handler); + } + invariant(result.result !== undefined, "You defined " + (type === "action" ? "an action" : "a loader") + " for route " + ("\"" + match.route.id + "\" but didn't return anything from your `" + type + "` ") + "function. Please return a value or `null`."); + } catch (e) { + // We should already be catching and converting normal handler executions to + // DataStrategyResults and returning them, so anything that throws here is an + // unexpected error we still need to wrap + return { + type: ResultType.error, + result: e + }; + } finally { + if (onReject) { + request.signal.removeEventListener("abort", onReject); } - }]); -}(_react.Component); -SearchableDropdown.propTypes = { - name: _propTypes["default"].string.isRequired, - options: _propTypes["default"].object.isRequired, - id: _propTypes["default"].string, - // strictSearch, if set to true, will require that only options - // provided in the options prop can be submitted - strictSearch: _propTypes["default"].bool, - label: _propTypes["default"].string, - value: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].array]), - "class": _propTypes["default"].string, - disabled: _propTypes["default"].bool, - required: _propTypes["default"].bool, - errorMessage: _propTypes["default"].string, - placeHolder: _propTypes["default"].string, - onUserInput: _propTypes["default"].func, - sortByValue: _propTypes["default"].bool -}; -SearchableDropdown.defaultProps = { - name: '', - options: {}, - strictSearch: true, - label: '', - value: undefined, - id: null, - "class": '', - disabled: false, - required: false, - sortByValue: true, - errorMessage: null, - placeHolder: '', - onUserInput: function onUserInput() { - console.warn('onUserInput() callback is not set'); } -}; - -/** - * Select Component - * React wrapper for a simple or 'multiple' \n
\n \n
\n \n \n
\n
\n
\n \n").replace(/(^|\n)\s*/g, ''); - -var resetOldContainer = function resetOldContainer() { - var oldContainer = getContainer(); - - if (!oldContainer) { - return; - } - - oldContainer.parentNode.removeChild(oldContainer); - removeClass([document.documentElement, document.body], [swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['has-column']]); -}; - -var oldInputVal; // IE11 workaround, see #1109 for details - -var resetValidationMessage = function resetValidationMessage(e) { - if (Swal.isVisible() && oldInputVal !== e.target.value) { - Swal.resetValidationMessage(); - } - - oldInputVal = e.target.value; -}; - -var addInputChangeListeners = function addInputChangeListeners() { - var content = getContent(); - var input = getChildByClass(content, swalClasses.input); - var file = getChildByClass(content, swalClasses.file); - var range = content.querySelector(".".concat(swalClasses.range, " input")); - var rangeOutput = content.querySelector(".".concat(swalClasses.range, " output")); - var select = getChildByClass(content, swalClasses.select); - var checkbox = content.querySelector(".".concat(swalClasses.checkbox, " input")); - var textarea = getChildByClass(content, swalClasses.textarea); - input.oninput = resetValidationMessage; - file.onchange = resetValidationMessage; - select.onchange = resetValidationMessage; - checkbox.onchange = resetValidationMessage; - textarea.oninput = resetValidationMessage; - - range.oninput = function (e) { - resetValidationMessage(e); - rangeOutput.value = range.value; - }; - - range.onchange = function (e) { - resetValidationMessage(e); - range.nextSibling.value = range.value; - }; -}; - -var getTarget = function getTarget(target) { - return typeof target === 'string' ? document.querySelector(target) : target; -}; - -var setupAccessibility = function setupAccessibility(params) { - var popup = getPopup(); - popup.setAttribute('role', params.toast ? 'alert' : 'dialog'); - popup.setAttribute('aria-live', params.toast ? 'polite' : 'assertive'); - - if (!params.toast) { - popup.setAttribute('aria-modal', 'true'); - } -}; - -var setupRTL = function setupRTL(targetElement) { - if (window.getComputedStyle(targetElement).direction === 'rtl') { - addClass(getContainer(), swalClasses.rtl); - } -}; -/* - * Add modal + backdrop to DOM - */ - - -var init = function init(params) { - // Clean up the old popup container if it exists - resetOldContainer(); - /* istanbul ignore if */ - - if (isNodeEnv()) { - error('SweetAlert2 requires document to initialize'); - return; - } - - var container = document.createElement('div'); - container.className = swalClasses.container; - container.innerHTML = sweetHTML; - var targetElement = getTarget(params.target); - targetElement.appendChild(container); - setupAccessibility(params); - setupRTL(targetElement); - addInputChangeListeners(); -}; - -var parseHtmlToContainer = function parseHtmlToContainer(param, target) { - // DOM element - if (param instanceof HTMLElement) { - target.appendChild(param); // JQuery element(s) - } else if (_typeof(param) === 'object') { - handleJqueryElem(target, param); // Plain string - } else if (param) { - target.innerHTML = param; - } -}; - -var handleJqueryElem = function handleJqueryElem(target, elem) { - target.innerHTML = ''; - - if (0 in elem) { - for (var i = 0; i in elem; i++) { - target.appendChild(elem[i].cloneNode(true)); - } - } else { - target.appendChild(elem.cloneNode(true)); - } -}; - -var animationEndEvent = function () { - // Prevent run in Node env - - /* istanbul ignore if */ - if (isNodeEnv()) { - return false; - } - - var testEl = document.createElement('div'); - var transEndEventNames = { - WebkitAnimation: 'webkitAnimationEnd', - OAnimation: 'oAnimationEnd oanimationend', - animation: 'animationend' - }; - - for (var i in transEndEventNames) { - if (Object.prototype.hasOwnProperty.call(transEndEventNames, i) && typeof testEl.style[i] !== 'undefined') { - return transEndEventNames[i]; - } - } - - return false; -}(); - -// Measure width of scrollbar -// https://github.com/twbs/bootstrap/blob/master/js/modal.js#L279-L286 -var measureScrollbar = function measureScrollbar() { - var supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints; - - if (supportsTouch) { - return 0; - } - - var scrollDiv = document.createElement('div'); - scrollDiv.style.width = '50px'; - scrollDiv.style.height = '50px'; - scrollDiv.style.overflow = 'scroll'; - document.body.appendChild(scrollDiv); - var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; - document.body.removeChild(scrollDiv); - return scrollbarWidth; -}; - -var renderActions = function renderActions(instance, params) { - var actions = getActions(); - var confirmButton = getConfirmButton(); - var cancelButton = getCancelButton(); // Actions (buttons) wrapper - - if (!params.showConfirmButton && !params.showCancelButton) { - hide(actions); - } // Custom class - - - applyCustomClass(actions, params.customClass, 'actions'); // Render confirm button - - renderButton(confirmButton, 'confirm', params); // render Cancel Button - - renderButton(cancelButton, 'cancel', params); - - if (params.buttonsStyling) { - handleButtonsStyling(confirmButton, cancelButton, params); - } else { - removeClass([confirmButton, cancelButton], swalClasses.styled); - confirmButton.style.backgroundColor = confirmButton.style.borderLeftColor = confirmButton.style.borderRightColor = ''; - cancelButton.style.backgroundColor = cancelButton.style.borderLeftColor = cancelButton.style.borderRightColor = ''; - } - - if (params.reverseButtons) { - confirmButton.parentNode.insertBefore(cancelButton, confirmButton); - } -}; - -function handleButtonsStyling(confirmButton, cancelButton, params) { - addClass([confirmButton, cancelButton], swalClasses.styled); // Buttons background colors - - if (params.confirmButtonColor) { - confirmButton.style.backgroundColor = params.confirmButtonColor; - } - - if (params.cancelButtonColor) { - cancelButton.style.backgroundColor = params.cancelButtonColor; - } // Loading state - - - var confirmButtonBackgroundColor = window.getComputedStyle(confirmButton).getPropertyValue('background-color'); - confirmButton.style.borderLeftColor = confirmButtonBackgroundColor; - confirmButton.style.borderRightColor = confirmButtonBackgroundColor; -} - -function renderButton(button, buttonType, params) { - toggle(button, params['showC' + buttonType.substring(1) + 'Button'], 'inline-block'); - button.innerHTML = params[buttonType + 'ButtonText']; // Set caption text - - button.setAttribute('aria-label', params[buttonType + 'ButtonAriaLabel']); // ARIA label - // Add buttons custom classes - - button.className = swalClasses[buttonType]; - applyCustomClass(button, params.customClass, buttonType + 'Button'); - addClass(button, params[buttonType + 'ButtonClass']); -} - -function handleBackdropParam(container, backdrop) { - if (typeof backdrop === 'string') { - container.style.background = backdrop; - } else if (!backdrop) { - addClass([document.documentElement, document.body], swalClasses['no-backdrop']); - } -} - -function handlePositionParam(container, position) { - if (position in swalClasses) { - addClass(container, swalClasses[position]); - } else { - warn('The "position" parameter is not valid, defaulting to "center"'); - addClass(container, swalClasses.center); - } -} - -function handleGrowParam(container, grow) { - if (grow && typeof grow === 'string') { - var growClass = 'grow-' + grow; - - if (growClass in swalClasses) { - addClass(container, swalClasses[growClass]); - } - } -} - -var renderContainer = function renderContainer(instance, params) { - var container = getContainer(); - - if (!container) { - return; - } - - handleBackdropParam(container, params.backdrop); - - if (!params.backdrop && params.allowOutsideClick) { - warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`'); - } - - handlePositionParam(container, params.position); - handleGrowParam(container, params.grow); // Custom class - - applyCustomClass(container, params.customClass, 'container'); - - if (params.customContainerClass) { - // @deprecated - addClass(container, params.customContainerClass); - } -}; - -/** - * This module containts `WeakMap`s for each effectively-"private property" that a `Swal` has. - * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')` - * This is the approach that Babel will probably take to implement private methods/fields - * https://github.com/tc39/proposal-private-methods - * https://github.com/babel/babel/pull/7555 - * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module* - * then we can use that language feature. - */ -var privateProps = { - promise: new WeakMap(), - innerParams: new WeakMap(), - domCache: new WeakMap() -}; - -var inputTypes = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea']; -var renderInput = function renderInput(instance, params) { - var content = getContent(); - var innerParams = privateProps.innerParams.get(instance); - var rerender = !innerParams || params.input !== innerParams.input; - inputTypes.forEach(function (inputType) { - var inputClass = swalClasses[inputType]; - var inputContainer = getChildByClass(content, inputClass); // set attributes - - setAttributes(inputType, params.inputAttributes); // set class - - inputContainer.className = inputClass; - - if (rerender) { - hide(inputContainer); - } - }); - - if (params.input) { - if (rerender) { - showInput(params); - } // set custom class - - - setCustomClass(params); - } -}; - -var showInput = function showInput(params) { - if (!renderInputType[params.input]) { - return error("Unexpected type of input! Expected \"text\", \"email\", \"password\", \"number\", \"tel\", \"select\", \"radio\", \"checkbox\", \"textarea\", \"file\" or \"url\", got \"".concat(params.input, "\"")); - } - - var inputContainer = getInputContainer(params.input); - var input = renderInputType[params.input](inputContainer, params); - show(input); // input autofocus - - setTimeout(function () { - focusInput(input); - }); -}; - -var removeAttributes = function removeAttributes(input) { - for (var i = 0; i < input.attributes.length; i++) { - var attrName = input.attributes[i].name; - - if (!(['type', 'value', 'style'].indexOf(attrName) !== -1)) { - input.removeAttribute(attrName); - } - } -}; - -var setAttributes = function setAttributes(inputType, inputAttributes) { - var input = getInput(getContent(), inputType); - - if (!input) { - return; - } - - removeAttributes(input); - - for (var attr in inputAttributes) { - // Do not set a placeholder for - // it'll crash Edge, #1298 - if (inputType === 'range' && attr === 'placeholder') { - continue; + var fields = [{ + label: 'Barcode', + show: true, + filter: { + name: 'barcode', + type: 'text' + } + }, { + label: 'Type', + show: true, + filter: { + name: 'type', + type: 'select', + options: specimenTypes + } + }, { + label: 'Container Type', + show: true, + filter: { + name: 'containerType', + type: 'select', + options: containerTypesPrimary + } + }, { + label: 'Quantity', + show: true + }, { + label: 'F/T Cycle', + show: false, + filter: { + name: 'fTCycle', + type: 'text', + hide: true + } + }, { + label: 'Parent Specimen(s)', + show: false, + filter: { + name: 'parentSpecimens', + type: 'text', + hide: true + } + }, { + label: 'PSCID', + show: true, + filter: { + name: 'pscid', + type: 'text' + } + }, { + label: 'Sex', + show: true, + filter: { + name: 'sex', + type: 'select', + options: { + Male: 'Male', + Female: 'Female' + } + } + }, { + label: 'Age at Collection', + show: true, + filter: { + name: 'age', + type: 'number' + } + }, { + label: 'Diagnosis', + show: true, + filter: { + name: 'diagnosis', + type: 'multiselect', + options: diagnoses + } + }, { + label: 'Visit Label', + show: true, + filter: { + name: 'session', + type: 'text' + } + }, { + label: 'Pool', + show: false, + filter: { + name: 'pool', + type: 'text', + hide: true + } + }, { + label: 'Status', + show: true, + filter: { + name: 'status', + type: 'select', + options: stati + } + }, { + label: 'Projects', + show: true, + filter: { + name: 'projects', + type: 'multiselect', + options: options.projects + } + }, { + label: 'Current Site', + show: true, + filter: { + name: 'currentSite', + type: 'select', + options: options.centers + } + }, { + label: 'Draw Site', + show: true, + filter: { + name: 'drawSite', + type: 'select', + options: options.centers + } + }, { + label: 'Collection Date', + show: true, + filter: { + name: 'collectionDate', + type: 'date' + } + }, { + label: 'Collection Time', + show: true, + filter: { + name: 'collectionTime', + type: 'text' + } + }, { + label: 'Preparation Time', + show: true, + filter: { + name: 'preparationTime', + type: 'text' + } + }, { + label: 'Container Barcode', + show: true, + filter: { + name: 'containerBarcode', + type: 'text' + } + }, { + label: 'Coordinate', + show: true + }].concat(specimenAttributeFields); + var openSearchSpecimen = function openSearchSpecimen() { + return _this3.edit('searchSpecimen'); + }; + var openSpecimenForm = function openSpecimenForm() { + return _this3.edit('specimenForm'); + }; + var openPoolForm = function openPoolForm() { + return _this3.edit('poolSpecimenForm'); + }; + var openBatchProcessForm = function openBatchProcessForm() { + return _this3.edit('batchProcessForm'); + }; + var openBatchEditForm = function openBatchEditForm() { + return _this3.edit('batchEditForm'); + }; + var actions = [{ + name: 'goToSpecimen', + label: 'Go To Specimen', + action: openSearchSpecimen + }, { + name: 'addSpecimen', + label: 'Add Specimen', + action: openSpecimenForm + }, { + name: 'poolSpecimen', + label: 'Pool Specimens', + action: openPoolForm + }, { + name: 'batchProcess', + label: 'Process Specimens', + action: openBatchProcessForm + }, { + name: 'batchEdit', + label: 'Edit Specimens', + action: openBatchEditForm + }]; + return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_FilterableDataTable["default"], { + name: "specimen", + data: specimenData, + fields: fields, + actions: actions, + getFormattedCell: this.formatSpecimenColumns, + getMappedCell: this.mapSpecimenColumns, + progress: this.props.loading + }), /*#__PURE__*/_react["default"].createElement(_search["default"], { + title: "Go To Specimen", + show: editable.searchSpecimen, + onClose: this.clearEditable, + barcodes: barcodesPrimary, + history: this.props.history + }), loris.userHasPermission('biobank_specimen_create') ? /*#__PURE__*/_react["default"].createElement(_specimenForm["default"], { + title: "Add New Specimen", + options: options, + data: data, + increaseCoordinate: this.props.increaseCoordinate, + show: editable.specimenForm, + onClose: this.clearEditable, + onSubmit: this.props.createSpecimens + }) : null, loris.userHasPermission('biobank_pool_create') ? /*#__PURE__*/_react["default"].createElement(_poolSpecimenForm["default"], { + options: this.props.options, + data: this.props.data, + show: editable.poolSpecimenForm, + onClose: this.clearEditable, + onSubmit: this.props.createPool + }) : null, loris.userHasPermission('biobank_specimen_edit') ? /*#__PURE__*/_react["default"].createElement(_batchProcessForm["default"], { + show: editable.batchProcessForm, + onClose: this.clearEditable, + onSubmit: this.props.updateSpecimens, + options: this.props.options, + data: this.props.data + }) : null, loris.userHasPermission('biobank_specimen_edit') ? /*#__PURE__*/_react["default"].createElement(_batchEditForm["default"], { + show: editable.batchEditForm, + onClose: this.clearEditable, + onSubmit: this.props.editSpecimens, + options: this.props.options, + data: this.props.data + }) : null); } - - input.setAttribute(attr, inputAttributes[attr]); - } -}; - -var setCustomClass = function setCustomClass(params) { - var inputContainer = getInputContainer(params.input); - - if (params.inputClass) { - addClass(inputContainer, params.inputClass); - } - - if (params.customClass) { - addClass(inputContainer, params.customClass.input); - } -}; - -var setInputPlaceholder = function setInputPlaceholder(input, params) { - if (!input.placeholder || params.inputPlaceholder) { - input.placeholder = params.inputPlaceholder; - } -}; - -var getInputContainer = function getInputContainer(inputType) { - var inputClass = swalClasses[inputType] ? swalClasses[inputType] : swalClasses.input; - return getChildByClass(getContent(), inputClass); -}; - -var renderInputType = {}; - -renderInputType.text = renderInputType.email = renderInputType.password = renderInputType.number = renderInputType.tel = renderInputType.url = function (input, params) { - if (typeof params.inputValue === 'string' || typeof params.inputValue === 'number') { - input.value = params.inputValue; - } else if (!isPromise(params.inputValue)) { - warn("Unexpected type of inputValue! Expected \"string\", \"number\" or \"Promise\", got \"".concat(_typeof(params.inputValue), "\"")); - } - - setInputPlaceholder(input, params); - input.type = params.input; - return input; -}; - -renderInputType.file = function (input, params) { - setInputPlaceholder(input, params); - return input; -}; - -renderInputType.range = function (range, params) { - var rangeInput = range.querySelector('input'); - var rangeOutput = range.querySelector('output'); - rangeInput.value = params.inputValue; - rangeInput.type = params.input; - rangeOutput.value = params.inputValue; - return range; -}; - -renderInputType.select = function (select, params) { - select.innerHTML = ''; - - if (params.inputPlaceholder) { - var placeholder = document.createElement('option'); - placeholder.innerHTML = params.inputPlaceholder; - placeholder.value = ''; - placeholder.disabled = true; - placeholder.selected = true; - select.appendChild(placeholder); - } - - return select; -}; - -renderInputType.radio = function (radio) { - radio.innerHTML = ''; - return radio; -}; - -renderInputType.checkbox = function (checkboxContainer, params) { - var checkbox = getInput(getContent(), 'checkbox'); - checkbox.value = 1; - checkbox.id = swalClasses.checkbox; - checkbox.checked = Boolean(params.inputValue); - var label = checkboxContainer.querySelector('span'); - label.innerHTML = params.inputPlaceholder; - return checkboxContainer; -}; - -renderInputType.textarea = function (textarea, params) { - textarea.value = params.inputValue; - setInputPlaceholder(textarea, params); - - if ('MutationObserver' in window) { - // #1699 - var initialPopupWidth = parseInt(window.getComputedStyle(getPopup()).width); - var popupPadding = parseInt(window.getComputedStyle(getPopup()).paddingLeft) + parseInt(window.getComputedStyle(getPopup()).paddingRight); - - var outputsize = function outputsize() { - var contentWidth = textarea.offsetWidth + popupPadding; - - if (contentWidth > initialPopupWidth) { - getPopup().style.width = contentWidth + 'px'; - } else { - getPopup().style.width = null; - } - }; - - new MutationObserver(outputsize).observe(textarea, { - attributes: true, - attributeFilter: ['style'] - }); - } - - return textarea; -}; - -var renderContent = function renderContent(instance, params) { - var content = getContent().querySelector('#' + swalClasses.content); // Content as HTML - - if (params.html) { - parseHtmlToContainer(params.html, content); - show(content, 'block'); // Content as plain text - } else if (params.text) { - content.textContent = params.text; - show(content, 'block'); // No content - } else { - hide(content); - } - - renderInput(instance, params); // Custom class - - applyCustomClass(getContent(), params.customClass, 'content'); -}; - -var renderFooter = function renderFooter(instance, params) { - var footer = getFooter(); - toggle(footer, params.footer); - - if (params.footer) { - parseHtmlToContainer(params.footer, footer); - } // Custom class - - - applyCustomClass(footer, params.customClass, 'footer'); -}; - -var renderCloseButton = function renderCloseButton(instance, params) { - var closeButton = getCloseButton(); - closeButton.innerHTML = params.closeButtonHtml; // Custom class - - applyCustomClass(closeButton, params.customClass, 'closeButton'); - toggle(closeButton, params.showCloseButton); - closeButton.setAttribute('aria-label', params.closeButtonAriaLabel); -}; - -var renderIcon = function renderIcon(instance, params) { - var innerParams = privateProps.innerParams.get(instance); // if the icon with the given type already rendered, - // apply the custom class without re-rendering the icon - - if (innerParams && params.type === innerParams.type && getIcon()) { - applyCustomClass(getIcon(), params.customClass, 'icon'); - return; - } - - hideAllIcons(); - - if (!params.type) { - return; - } - - adjustSuccessIconBackgoundColor(); - - if (Object.keys(iconTypes).indexOf(params.type) !== -1) { - var icon = elementBySelector(".".concat(swalClasses.icon, ".").concat(iconTypes[params.type])); - show(icon); // Custom class - - applyCustomClass(icon, params.customClass, 'icon'); // Animate icon - - toggleClass(icon, "swal2-animate-".concat(params.type, "-icon"), params.animation); - } else { - error("Unknown type! Expected \"success\", \"error\", \"warning\", \"info\" or \"question\", got \"".concat(params.type, "\"")); - } + }]); + return SpecimenTab; +}(_react.Component); +SpecimenTab.propTypes = { + options: _propTypes["default"].shape({ + specimen: _propTypes["default"].shape({ + attributes: _propTypes["default"].arrayOf(_propTypes["default"].shape({ + label: _propTypes["default"].string.isRequired + })), + units: _propTypes["default"].string, + // Added based on errors + types: _propTypes["default"].arrayOf(_propTypes["default"].shape({ + label: _propTypes["default"].string.isRequired + })).isRequired, + processes: _propTypes["default"].arrayOf(_propTypes["default"].shape({ + label: _propTypes["default"].string.isRequired + })), + processAttributes: _propTypes["default"].arrayOf(_propTypes["default"].arrayOf(_propTypes["default"].shape({ + protocolIds: _propTypes["default"].arrayOf(_propTypes["default"].number) + }))), + typeContainerTypes: _propTypes["default"].arrayOf(_propTypes["default"].string).isRequired // Added based on previous propTypes + }).isRequired, + container: _propTypes["default"].shape({ + types: _propTypes["default"].obj, + typesPrimary: _propTypes["default"].arrayOf(_propTypes["default"].shape({ + label: _propTypes["default"].string.isRequired + })).isRequired, + stati: _propTypes["default"].arrayOf(_propTypes["default"].shape({ + label: _propTypes["default"].string.isRequired + })).isRequired + }).isRequired, + diagnoses: _propTypes["default"].arrayOf(_propTypes["default"].shape({ + label: _propTypes["default"].string.isRequired + })), + centers: _propTypes["default"].arrayOf(_propTypes["default"].string).isRequired, + projects: _propTypes["default"].arrayOf(_propTypes["default"].string).isRequired, + candidates: _propTypes["default"].arrayOf(_propTypes["default"].string).isRequired, + sessions: _propTypes["default"].arrayOf(_propTypes["default"].string).isRequired, + sessionCenters: _propTypes["default"].arrayOf(_propTypes["default"].shape({ + centerId: _propTypes["default"].number.isRequired + })), + candidateSessions: _propTypes["default"].arrayOf(_propTypes["default"].string).isRequired + }).isRequired, + // Data prop: Contains containers, specimens, and pools data + data: _propTypes["default"].shape({ + containers: _propTypes["default"].arrayOf(_propTypes["default"].shape({ + specimenId: _propTypes["default"].number.isRequired, + statusId: _propTypes["default"].number, + // Added based on error + temperature: _propTypes["default"].number, + // Added based on error + comments: _propTypes["default"].string // Added based on error + // Add other container-specific properties if necessary + })).isRequired, + specimens: _propTypes["default"].arrayOf(_propTypes["default"].shape({ + specimenId: _propTypes["default"].number.isRequired + // Add other specimen-specific properties if necessary + })).isRequired, + pools: _propTypes["default"].array.isRequired + }).isRequired, + // Functional props + onSubmit: _propTypes["default"].func.isRequired, + increaseCoordinate: _propTypes["default"].func.isRequired, + createSpecimens: _propTypes["default"].func.isRequired, + createPool: _propTypes["default"].func.isRequired, + updateSpecimens: _propTypes["default"].func.isRequired, + editSpecimens: _propTypes["default"].func.isRequired, + // UI Control props + title: _propTypes["default"].string.isRequired, + show: _propTypes["default"].bool.isRequired, + // History prop: For navigation + history: _propTypes["default"].shape({ + push: _propTypes["default"].func.isRequired + }).isRequired, + // Current state props + current: _propTypes["default"].shape({ + specimen: _propTypes["default"].shape({ + quantity: _propTypes["default"].number, + unitId: _propTypes["default"].number + // Add other specimen-specific properties if necessary + }).isRequired, + container: _propTypes["default"].shape({ + statusId: _propTypes["default"].number.isRequired, + temperature: _propTypes["default"].number, + comments: _propTypes["default"].string + // Add other container-specific properties if necessary + }).isRequired + }).isRequired, + // Errors prop: Handles validation errors + errors: _propTypes["default"].shape({ + container: _propTypes["default"].shape({ + typeId: _propTypes["default"].string, + temperature: _propTypes["default"].string, + statusId: _propTypes["default"].string, + comments: _propTypes["default"].string + }), + specimen: _propTypes["default"].shape({ + quantity: _propTypes["default"].string, + unitId: _propTypes["default"].string + // Add other specimen-specific error properties if necessary + }) + }).isRequired, + // Additional props based on errors + loading: _propTypes["default"].bool.isRequired }; +var _default = exports["default"] = SpecimenTab; -var hideAllIcons = function hideAllIcons() { - var icons = getIcons(); +/***/ }), - for (var i = 0; i < icons.length; i++) { - hide(icons[i]); - } -}; // Adjust success icon background color to match the popup background color +/***/ "./jsx/Loader.tsx": +/*!************************!*\ + !*** ./jsx/Loader.tsx ***! + \************************/ +/***/ ((__unused_webpack_module, exports) => { +"use strict"; -var adjustSuccessIconBackgoundColor = function adjustSuccessIconBackgoundColor() { - var popup = getPopup(); - var popupBackgroundColor = window.getComputedStyle(popup).getPropertyValue('background-color'); - var successIconParts = popup.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix'); - for (var i = 0; i < successIconParts.length; i++) { - successIconParts[i].style.backgroundColor = popupBackgroundColor; - } +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +/** + * Loader component renders a spinner wheel of a specified size. + * + * @param {LoaderProps} props - The properties for the Loader component + * @returns {JSX.Element} A div representing the loading spinner + */ +var Loader = function Loader(_a) { + var _b = _a.size, + size = _b === void 0 ? 120 : _b; + var loaderStyle = { + width: size, + height: size, + borderWidth: size / 15 + }; + return /*#__PURE__*/React.createElement("div", { + className: "loader", + style: loaderStyle + }); }; +exports["default"] = Loader; -var renderImage = function renderImage(instance, params) { - var image = getImage(); - - if (!params.imageUrl) { - return hide(image); - } - - show(image); // Src, alt +/***/ }), - image.setAttribute('src', params.imageUrl); - image.setAttribute('alt', params.imageAlt); // Width, height +/***/ "./jsx/Modal.tsx": +/*!***********************!*\ + !*** ./jsx/Modal.tsx ***! + \***********************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { - applyNumericalStyle(image, 'width', params.imageWidth); - applyNumericalStyle(image, 'height', params.imageHeight); // Class +"use strict"; - image.className = swalClasses.image; - applyCustomClass(image, params.customClass, 'image'); - if (params.imageClass) { - addClass(image, params.imageClass); +var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function (resolve) { + resolve(value); + }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); }; - -var createStepElement = function createStepElement(step) { - var stepEl = document.createElement('li'); - addClass(stepEl, swalClasses['progress-step']); - stepEl.innerHTML = step; - return stepEl; -}; - -var createLineElement = function createLineElement(params) { - var lineEl = document.createElement('li'); - addClass(lineEl, swalClasses['progress-step-line']); - - if (params.progressStepsDistance) { - lineEl.style.width = params.progressStepsDistance; +var __generator = void 0 && (void 0).__generator || function (thisArg, body) { + var _ = { + label: 0, + sent: function sent() { + if (t[0] & 1) throw t[1]; + return t[1]; + }, + trys: [], + ops: [] + }, + f, + y, + t, + g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); + return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () { + return this; + }), g; + function verb(n) { + return function (v) { + return step([n, v]); + }; } - - return lineEl; -}; - -var renderProgressSteps = function renderProgressSteps(instance, params) { - var progressStepsContainer = getProgressSteps(); - - if (!params.progressSteps || params.progressSteps.length === 0) { - return hide(progressStepsContainer); + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) { + try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: + case 1: + t = op; + break; + case 4: + _.label++; + return { + value: op[1], + done: false + }; + case 5: + _.label++; + y = op[1]; + op = [0]; + continue; + case 7: + op = _.ops.pop(); + _.trys.pop(); + continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { + _ = 0; + continue; + } + if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) { + _.label = op[1]; + break; + } + if (op[0] === 6 && _.label < t[1]) { + _.label = t[1]; + t = op; + break; + } + if (t && _.label < t[2]) { + _.label = t[2]; + _.ops.push(op); + break; + } + if (t[2]) _.ops.pop(); + _.trys.pop(); + continue; + } + op = body.call(thisArg, _); + } catch (e) { + op = [6, e]; + y = 0; + } finally { + f = t = 0; + } + } + if (op[0] & 5) throw op[1]; + return { + value: op[0] ? op[1] : void 0, + done: true + }; } - - show(progressStepsContainer); - progressStepsContainer.innerHTML = ''; - var currentProgressStep = parseInt(params.currentProgressStep === null ? Swal.getQueueStep() : params.currentProgressStep); - - if (currentProgressStep >= params.progressSteps.length) { - warn('Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)'); +}; +var __read = void 0 && (void 0).__read || function (o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), + r, + ar = [], + e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) { + ar.push(r.value); + } + } catch (error) { + e = { + error: error + }; + } finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } finally { + if (e) throw e.error; + } } - - params.progressSteps.forEach(function (step, index) { - var stepEl = createStepElement(step); - progressStepsContainer.appendChild(stepEl); - - if (index === currentProgressStep) { - addClass(stepEl, swalClasses['active-progress-step']); + return ar; +}; +var __importDefault = void 0 && (void 0).__importDefault || function (mod) { + return mod && mod.__esModule ? mod : { + "default": mod + }; +}; +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +var react_1 = __webpack_require__(/*! react */ "react"); +var sweetalert2_1 = __importDefault(__webpack_require__(/*! sweetalert2 */ "./node_modules/sweetalert2/dist/sweetalert2.all.js")); +var Loader_1 = __importDefault(__webpack_require__(/*! ./Loader */ "./jsx/Loader.tsx")); +var Form_1 = __webpack_require__(/*! jsx/Form */ "./jsx/Form.js"); +/** + * Modal Component + * + * A React functional component that renders a modal dialog with optional + * form submission and loading indicators. Supports asynchronous form submission + * with loading and success feedback. + * + * @param {ModalProps} props - Properties for the modal component + * @returns {JSX.Element} - A modal dialog box w/ optional submit functionality + */ +var Modal = function Modal(_a) { + var _b = _a.throwWarning, + throwWarning = _b === void 0 ? false : _b, + _c = _a.show, + show = _c === void 0 ? false : _c, + onClose = _a.onClose, + onSubmit = _a.onSubmit, + onSuccess = _a.onSuccess, + title = _a.title, + children = _a.children; + var _d = __read((0, react_1.useState)(false), 2), + loading = _d[0], + setLoading = _d[1]; // Tracks loading during submit + var _e = __read((0, react_1.useState)(false), 2), + success = _e[0], + setSuccess = _e[1]; // Tracks success after submit + /** + * Handles modal close event. Shows a confirmation if `throwWarning` is true. + */ + var handleClose = function handleClose() { + if (throwWarning) { + // Display warning if enabled + sweetalert2_1["default"].fire({ + title: 'Are You Sure?', + text: 'Leaving the form will result in the loss of any information ' + 'entered.', + type: 'warning', + showCancelButton: true, + confirmButtonText: 'Proceed', + cancelButtonText: 'Cancel' + }).then(function (result) { + return result.value && onClose(); + }); + } else { + onClose(); // Close immediately if no warning + } + }; + /** + * Manages form submission with loading and success states, calling + * `onSubmit` and handling modal state based on success or failure. + */ + var handleSubmit = function handleSubmit() { + return __awaiter(void 0, void 0, void 0, function () { + var data, _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + if (!onSubmit) return [2 /*return*/]; // Ensure onSubmit exists + setLoading(true); // Show loader + _b.label = 1; + case 1: + _b.trys.push([1, 4,, 5]); + return [4 /*yield*/, onSubmit()]; + case 2: + data = _b.sent(); + setLoading(false); + setSuccess(true); // Show success + return [4 /*yield*/, new Promise(function (resolve) { + return setTimeout(resolve, 2000); + })]; + case 3: + _b.sent(); // Close delay + setSuccess(false); // Reset success state + onClose(); // Close modal + onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data); // call onSuccess if defined + return [3 /*break*/, 5]; + case 4: + _a = _b.sent(); + setLoading(false); + return [3 /*break*/, 5]; + case 5: + return [2 /*return*/]; + } + }); + }); + }; + /** + * Renders submit button if `onSubmit` is provided and no loading or success. + * + * @returns {JSX.Element | undefined} - The submit button if conditions are met + */ + var submitButton = function submitButton() { + if (onSubmit && !(loading || success)) { + // Show button if conditions met + return /*#__PURE__*/React.createElement("div", { + style: submitStyle + }, /*#__PURE__*/React.createElement(Form_1.ButtonElement, { + onUserInput: handleSubmit + })); } - - if (index !== params.progressSteps.length - 1) { - var lineEl = createLineElement(step); - progressStepsContainer.appendChild(lineEl); + }; + var headerStyle = { + display: 'flex', + flexDirection: 'row', + alignItems: 'center', + height: '40px', + borderTopRightRadius: '10', + fontSize: 24, + padding: 35, + borderBottom: '1px solid #DDDDDD' + }; + var glyphStyle = { + marginLeft: 'auto', + cursor: 'pointer' + }; + var bodyStyle = { + padding: success ? 0 : '15px 15px', + maxHeight: success ? 0 : '75vh', + overflow: 'scroll', + opacity: success ? 0 : 1, + transition: '1s ease, opacity 0.3s' + }; + var modalContainer = { + display: 'block', + position: 'fixed', + zIndex: 9999, + paddingTop: '100px', + paddingBottom: '100px', + left: 0, + top: 0, + width: '100%', + height: '100%', + overflow: 'auto', + backgroundColor: 'rgba(0,0,0,0.7)', + visibility: show ? 'visible' : 'hidden' + }; + var modalContent = { + opacity: show ? 1 : 0, + top: show ? 0 : '-300px', + position: 'relative', + backgroundColor: '#fefefe', + borderRadius: '7px', + margin: 'auto', + padding: 0, + border: '1px solid #888', + width: '700px', + boxShadow: '0 4px 8px 0 rbga(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19)', + transition: '0.4s ease' + }; + var footerStyle = { + borderTop: '1px solid #DDDDDD', + display: 'flex', + flexDirection: 'row', + alignItems: 'center', + height: '40px', + padding: '35px', + backgroundColor: success ? '#e0ffec' : undefined + }; + var submitStyle = { + marginLeft: 'auto', + marginRight: '20px' + }; + var processStyle = { + display: 'flex', + alignItems: 'center', + justifyContent: 'space-evenly', + margin: '0px auto', + width: '90px' + }; + /** + * Loader element displayed during form submission. + */ + var loader = loading && /*#__PURE__*/React.createElement("div", { + style: processStyle + }, /*#__PURE__*/React.createElement(Loader_1["default"], { + size: 20 + }), /*#__PURE__*/React.createElement("h5", { + className: "animate-flicker" + }, "Saving")); + /** + * Success display element shown after successful form submission. + */ + var successDisplay = success && /*#__PURE__*/React.createElement("div", { + style: processStyle + }, /*#__PURE__*/React.createElement("span", { + style: { + color: 'green', + marginBottom: '2px' + }, + className: "glyphicon glyphicon-ok-circle" + }), /*#__PURE__*/React.createElement("h5", null, "Success!")); + return /*#__PURE__*/React.createElement("div", { + style: modalContainer, + onClick: handleClose + }, /*#__PURE__*/React.createElement("div", { + style: modalContent, + onClick: function onClick(e) { + return e.stopPropagation(); } - }); -}; - -var renderTitle = function renderTitle(instance, params) { - var title = getTitle(); - toggle(title, params.title || params.titleText); - - if (params.title) { - parseHtmlToContainer(params.title, title); - } - - if (params.titleText) { - title.innerText = params.titleText; - } // Custom class - - - applyCustomClass(title, params.customClass, 'title'); -}; - -var renderHeader = function renderHeader(instance, params) { - var header = getHeader(); // Custom class - - applyCustomClass(header, params.customClass, 'header'); // Progress steps - - renderProgressSteps(instance, params); // Icon - - renderIcon(instance, params); // Image - - renderImage(instance, params); // Title - - renderTitle(instance, params); // Close button - - renderCloseButton(instance, params); + }, /*#__PURE__*/React.createElement("div", { + style: headerStyle + }, title, /*#__PURE__*/React.createElement("span", { + style: glyphStyle, + onClick: handleClose + }, "\xD7")), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", { + style: bodyStyle + }, show && children), /*#__PURE__*/React.createElement("div", { + style: footerStyle + }, loader, successDisplay, submitButton())))); }; +exports["default"] = Modal; -var renderPopup = function renderPopup(instance, params) { - var popup = getPopup(); // Width - - applyNumericalStyle(popup, 'width', params.width); // Padding - - applyNumericalStyle(popup, 'padding', params.padding); // Background - - if (params.background) { - popup.style.background = params.background; - } // Default Class - - - popup.className = swalClasses.popup; - - if (params.toast) { - addClass([document.documentElement, document.body], swalClasses['toast-shown']); - addClass(popup, swalClasses.toast); - } else { - addClass(popup, swalClasses.modal); - } // Custom class - - - applyCustomClass(popup, params.customClass, 'popup'); - - if (typeof params.customClass === 'string') { - addClass(popup, params.customClass); - } // CSS animation +/***/ }), +/***/ "./jsx/form/DateTimePartialElement.tsx": +/*!*********************************************!*\ + !*** ./jsx/form/DateTimePartialElement.tsx ***! + \*********************************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { - toggleClass(popup, swalClasses.noanimation, !params.animation); -}; +"use strict"; -var render = function render(instance, params) { - renderPopup(instance, params); - renderContainer(instance, params); - renderHeader(instance, params); - renderContent(instance, params); - renderActions(instance, params); - renderFooter(instance, params); - if (typeof params.onRender === 'function') { - params.onRender(getPopup()); +var __read = void 0 && (void 0).__read || function (o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), + r, + ar = [], + e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) { + ar.push(r.value); + } + } catch (error) { + e = { + error: error + }; + } finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } finally { + if (e) throw e.error; + } } + return ar; }; - -/* - * Global function to determine if SweetAlert2 popup is shown - */ - -var isVisible$1 = function isVisible$$1() { - return isVisible(getPopup()); -}; -/* - * Global function to click 'Confirm' button - */ - -var clickConfirm = function clickConfirm() { - return getConfirmButton() && getConfirmButton().click(); +var __importDefault = void 0 && (void 0).__importDefault || function (mod) { + return mod && mod.__esModule ? mod : { + "default": mod + }; }; -/* - * Global function to click 'Cancel' button +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +var react_1 = __webpack_require__(/*! react */ "react"); +var InputLabel_1 = __importDefault(__webpack_require__(/*! jsx/form/InputLabel */ "./jsx/form/InputLabel.tsx")); +var format = 'YYYY-MM-DD hh:mm:ss'; +/** + * Check if a character is a digit. + * + * @param character The character to check + * @returns The result of the check */ - -var clickCancel = function clickCancel() { - return getCancelButton() && getCancelButton().click(); -}; - -function fire() { - var Swal = this; - - for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - return _construct(Swal, args); +function isDigit(character) { + return character >= '0' && character <= '9'; } - /** - * Returns an extended version of `Swal` containing `params` as defaults. - * Useful for reusing Swal configuration. - * - * For example: + * Check if a character is a letter. * - * Before: - * const textPromptOptions = { input: 'text', showCancelButton: true } - * const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' }) - * const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' }) + * @param character A character to check + * @returns The result of the check + */ +function isLetter(character) { + return character >= 'A' && character <= 'Z' || character >= 'a' && character <= 'z'; +} +/** + * Insert a string inside another string at a given index. * - * After: - * const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true }) - * const {value: firstName} = await TextPrompt('What is your first name?') - * const {value: lastName} = await TextPrompt('What is your last name?') + * @param string The string in which the substring is to be inserted + * @param index The index at which to insert the substring + * @param other The substring to insert + * @returns The new string + */ +function stringInsert(string, index, other) { + return string.slice(0, index) + other + string.slice(index); +} +/** + * Checks if a value matches the datetime format, formatting it if necessary. * - * @param mixinParams + * @param oldDateTime The old value of the input (which is valid) + * @param newDateTime The new value of the input (which may be invalid) + * @returns The formatted new value, or `null` if the new value is invalid */ -function mixin(mixinParams) { - var MixinSwal = - /*#__PURE__*/ - function (_this) { - _inherits(MixinSwal, _this); - - function MixinSwal() { - _classCallCheck(this, MixinSwal); - - return _possibleConstructorReturn(this, _getPrototypeOf(MixinSwal).apply(this, arguments)); +function formatDatetime(oldDateTime, newDateTime) { + for (var i = 0; i < newDateTime.length; i++) { + // Check that the new value is no longer than the format. + // This check is done inside the loop because the value might grow during + // formatting. + if (i >= format.length) { + return null; } - - _createClass(MixinSwal, [{ - key: "_main", - value: function _main(params) { - return _get(_getPrototypeOf(MixinSwal.prototype), "_main", this).call(this, _extends({}, mixinParams, params)); + // Check that each new value character matches that expected from the + // format. + var valueChar = newDateTime[i]; + var formatChar = format[i]; + if (isLetter(formatChar)) { + if (!isDigit(valueChar)) { + return null; } - }]); - - return MixinSwal; - }(this); - - return MixinSwal; -} - -// private global state for the queue feature -var currentSteps = []; -/* - * Global function for chaining sweetAlert popups - */ - -var queue = function queue(steps) { - var Swal = this; - currentSteps = steps; - - var resetAndResolve = function resetAndResolve(resolve, value) { - currentSteps = []; - document.body.removeAttribute('data-swal2-queue-step'); - resolve(value); - }; - - var queueResult = []; - return new Promise(function (resolve) { - (function step(i, callback) { - if (i < currentSteps.length) { - document.body.setAttribute('data-swal2-queue-step', i); - Swal.fire(currentSteps[i]).then(function (result) { - if (typeof result.value !== 'undefined') { - queueResult.push(result.value); - step(i + 1, callback); - } else { - resetAndResolve(resolve, { - dismiss: result.dismiss - }); - } - }); - } else { - resetAndResolve(resolve, { - value: queueResult - }); + } else { + if (isDigit(valueChar)) { + newDateTime = stringInsert(newDateTime, i, formatChar); + } else if (valueChar !== formatChar) { + return null; } - })(0); - }); -}; -/* - * Global function for getting the index of current popup in queue + } + } + // If a character was added, add a special character if it is expected from + // the format. + if (newDateTime.length > oldDateTime.length && newDateTime.length < format.length) { + var nextChar = format[newDateTime.length]; + if (!isLetter(nextChar)) { + newDateTime += nextChar; + } + } + // If a character was removed, remove a special character if it is expected + // from the format. + if (newDateTime.length < oldDateTime.length && newDateTime.length > 0) { + var prevChar = format[newDateTime.length - 1]; + if (!isLetter(prevChar)) { + newDateTime = newDateTime.slice(0, -1); + } + } + return newDateTime; +} +/** + * React component for an input datetime mask. + * + * @param props The props of the component + * @param props.value + * @param props.children + * @returns The corresponding React element */ - -var getQueueStep = function getQueueStep() { - return document.body.getAttribute('data-swal2-queue-step'); +var Mask = function Mask(_a) { + var value = _a.value, + children = _a.children; + return /*#__PURE__*/React.createElement("div", { + style: { + position: 'relative' + } + }, children, /*#__PURE__*/React.createElement("div", { + className: "form-control", + style: { + position: 'absolute', + top: 0, + left: 0, + backgroundColor: 'transparent', + borderColor: 'transparent', + boxShadow: 'none', + pointerEvents: 'none' + } + }, /*#__PURE__*/React.createElement("div", { + style: { + fontFamily: 'monospace', + color: '#777777', + overflow: 'hidden', + whiteSpace: 'nowrap' + } + }, "\xA0".repeat(value.length), format.slice(value.length)))); }; -/* - * Global function for inserting a popup to the queue +/** + * Datetime input (down to the second) React component + * Compared to the standard HTML input, this input accepts incomplete datetimes + * (useful for filtering). + * + * @param props The props of the component + * @returns The corresponding React element */ - -var insertQueueStep = function insertQueueStep(step, index) { - if (index && index < currentSteps.length) { - return currentSteps.splice(index, 0, step); +var DateTimePartialElement = function DateTimePartialElement(props) { + var _a; + var onUserInput = props.onUserInput !== undefined ? props.onUserInput : function () { + return console.warn('onUserInput() callback is not set'); + }; + var _b = __read((0, react_1.useState)((_a = props.value) !== null && _a !== void 0 ? _a : ''), 2), + value = _b[0], + setValue = _b[1]; + /** + * Handle a change in the input. + * + * @param e The React event. + */ + function handleChange(e) { + var rawValue = e.target.value.replace(/[- :]/g, ''); + var newValue = formatDatetime(value, rawValue); + if (newValue === null) { + return; + } + setValue(newValue); + onUserInput(props.name, newValue); } - - return currentSteps.push(step); + var errorMessage = null; + var elementClass = 'row form-group'; + if (props.required && value == '') { + errorMessage = /*#__PURE__*/React.createElement("span", null, "This field is required"); + elementClass += ' has-error'; + } else if (props.errorMessage) { + errorMessage = /*#__PURE__*/React.createElement("span", null, props.errorMessage); + elementClass += ' has-error'; + } + var wrapperClass = props.label ? 'col-sm-9' : 'col-sm-12'; + return /*#__PURE__*/React.createElement("div", { + className: elementClass + }, props.label && /*#__PURE__*/React.createElement(InputLabel_1["default"], { + label: props.label, + required: props.required + }), /*#__PURE__*/React.createElement("div", { + className: wrapperClass + }, /*#__PURE__*/React.createElement(Mask, { + value: value + }, /*#__PURE__*/React.createElement("input", { + className: "form-control", + name: props.name, + id: props.id, + onChange: handleChange, + value: value, + required: props.required, + disabled: props.disabled, + style: { + fontFamily: 'monospace' + } + })), errorMessage)); }; -/* - * Global function for deleting a popup from the queue - */ +exports["default"] = DateTimePartialElement; -var deleteQueueStep = function deleteQueueStep(index) { - if (typeof currentSteps[index] !== 'undefined') { - currentSteps.splice(index, 1); - } -}; +/***/ }), -/** - * Show spinner instead of Confirm button and disable Cancel button - */ +/***/ "./jsx/form/InputLabel.tsx": +/*!*********************************!*\ + !*** ./jsx/form/InputLabel.tsx ***! + \*********************************/ +/***/ ((__unused_webpack_module, exports) => { -var showLoading = function showLoading() { - var popup = getPopup(); +"use strict"; - if (!popup) { - Swal.fire(''); - } - popup = getPopup(); - var actions = getActions(); - var confirmButton = getConfirmButton(); - var cancelButton = getCancelButton(); - show(actions); - show(confirmButton); - addClass([popup, actions], swalClasses.loading); - confirmButton.disabled = true; - cancelButton.disabled = true; - popup.setAttribute('data-loading', true); - popup.setAttribute('aria-busy', true); - popup.focus(); +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +/** + * Input label React component + * + * @param props The props of the component + * @param props.label + * @param props.required + * @returns The corresponding React element + */ +var InputLabel = function InputLabel(_a) { + var label = _a.label, + required = _a.required; + return /*#__PURE__*/React.createElement("label", { + className: "col-sm-3 control-label", + htmlFor: label + }, label, required && /*#__PURE__*/React.createElement("span", { + className: "text-danger" + }, "*")); }; +exports["default"] = InputLabel; -var RESTORE_FOCUS_TIMEOUT = 100; - -var globalState = {}; -var focusPreviousActiveElement = function focusPreviousActiveElement() { - if (globalState.previousActiveElement && globalState.previousActiveElement.focus) { - globalState.previousActiveElement.focus(); - globalState.previousActiveElement = null; - } else if (document.body) { - document.body.focus(); - } -}; // Restore previous active (focused) element - +/***/ }), -var restoreActiveElement = function restoreActiveElement() { - return new Promise(function (resolve) { - var x = window.scrollX; - var y = window.scrollY; - globalState.restoreFocusTimeout = setTimeout(function () { - focusPreviousActiveElement(); - resolve(); - }, RESTORE_FOCUS_TIMEOUT); // issues/900 +/***/ "./node_modules/fbjs/lib/emptyFunction.js": +/*!************************************************!*\ + !*** ./node_modules/fbjs/lib/emptyFunction.js ***! + \************************************************/ +/***/ ((module) => { - if (typeof x !== 'undefined' && typeof y !== 'undefined') { - // IE doesn't have scrollX/scrollY support - window.scrollTo(x, y); - } - }); -}; +"use strict"; -/** - * If `timer` parameter is set, returns number of milliseconds of timer remained. - * Otherwise, returns undefined. - */ -var getTimerLeft = function getTimerLeft() { - return globalState.timeout && globalState.timeout.getTimerLeft(); -}; /** - * Stop timer. Returns number of milliseconds of timer remained. - * If `timer` parameter isn't set, returns undefined. + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * */ -var stopTimer = function stopTimer() { - return globalState.timeout && globalState.timeout.stop(); -}; -/** - * Resume timer. Returns number of milliseconds of timer remained. - * If `timer` parameter isn't set, returns undefined. - */ +function makeEmptyFunction(arg) { + return function () { + return arg; + }; +} -var resumeTimer = function resumeTimer() { - return globalState.timeout && globalState.timeout.start(); -}; /** - * Resume timer. Returns number of milliseconds of timer remained. - * If `timer` parameter isn't set, returns undefined. + * This function accepts and discards inputs; it has no side effects. This is + * primarily useful idiomatically for overridable function endpoints which + * always need to be callable, since JS lacks a null-call idiom ala Cocoa. */ +var emptyFunction = function emptyFunction() {}; -var toggleTimer = function toggleTimer() { - var timer = globalState.timeout; - return timer && (timer.running ? timer.stop() : timer.start()); +emptyFunction.thatReturns = makeEmptyFunction; +emptyFunction.thatReturnsFalse = makeEmptyFunction(false); +emptyFunction.thatReturnsTrue = makeEmptyFunction(true); +emptyFunction.thatReturnsNull = makeEmptyFunction(null); +emptyFunction.thatReturnsThis = function () { + return this; }; -/** - * Increase timer. Returns number of milliseconds of an updated timer. - * If `timer` parameter isn't set, returns undefined. - */ - -var increaseTimer = function increaseTimer(n) { - return globalState.timeout && globalState.timeout.increase(n); +emptyFunction.thatReturnsArgument = function (arg) { + return arg; }; -/** - * Check if timer is running. Returns true if timer is running - * or false if timer is paused or stopped. - * If `timer` parameter isn't set, returns undefined - */ -var isTimerRunning = function isTimerRunning() { - return globalState.timeout && globalState.timeout.isRunning(); -}; +module.exports = emptyFunction; -var defaultParams = { - title: '', - titleText: '', - text: '', - html: '', - footer: '', - type: null, - toast: false, - customClass: '', - customContainerClass: '', - target: 'body', - backdrop: true, - animation: true, - heightAuto: true, - allowOutsideClick: true, - allowEscapeKey: true, - allowEnterKey: true, - stopKeydownPropagation: true, - keydownListenerCapture: false, - showConfirmButton: true, - showCancelButton: false, - preConfirm: null, - confirmButtonText: 'OK', - confirmButtonAriaLabel: '', - confirmButtonColor: null, - confirmButtonClass: '', - cancelButtonText: 'Cancel', - cancelButtonAriaLabel: '', - cancelButtonColor: null, - cancelButtonClass: '', - buttonsStyling: true, - reverseButtons: false, - focusConfirm: true, - focusCancel: false, - showCloseButton: false, - closeButtonHtml: '×', - closeButtonAriaLabel: 'Close this dialog', - showLoaderOnConfirm: false, - imageUrl: null, - imageWidth: null, - imageHeight: null, - imageAlt: '', - imageClass: '', - timer: null, - width: null, - padding: null, - background: null, - input: null, - inputPlaceholder: '', - inputValue: '', - inputOptions: {}, - inputAutoTrim: true, - inputClass: '', - inputAttributes: {}, - inputValidator: null, - validationMessage: null, - grow: false, - position: 'center', - progressSteps: [], - currentProgressStep: null, - progressStepsDistance: null, - onBeforeOpen: null, - onOpen: null, - onRender: null, - onClose: null, - onAfterClose: null, - scrollbarPadding: true -}; -var updatableParams = ['title', 'titleText', 'text', 'html', 'type', 'customClass', 'showConfirmButton', 'showCancelButton', 'confirmButtonText', 'confirmButtonAriaLabel', 'confirmButtonColor', 'confirmButtonClass', 'cancelButtonText', 'cancelButtonAriaLabel', 'cancelButtonColor', 'cancelButtonClass', 'buttonsStyling', 'reverseButtons', 'imageUrl', 'imageWidth', 'imageHeigth', 'imageAlt', 'imageClass', 'progressSteps', 'currentProgressStep']; -var deprecatedParams = { - customContainerClass: 'customClass', - confirmButtonClass: 'customClass', - cancelButtonClass: 'customClass', - imageClass: 'customClass', - inputClass: 'customClass' -}; -var toastIncompatibleParams = ['allowOutsideClick', 'allowEnterKey', 'backdrop', 'focusConfirm', 'focusCancel', 'heightAuto', 'keydownListenerCapture']; -/** - * Is valid parameter - * @param {String} paramName - */ +/***/ }), -var isValidParameter = function isValidParameter(paramName) { - return Object.prototype.hasOwnProperty.call(defaultParams, paramName); -}; -/** - * Is valid parameter for Swal.update() method - * @param {String} paramName - */ +/***/ "./node_modules/fbjs/lib/invariant.js": +/*!********************************************!*\ + !*** ./node_modules/fbjs/lib/invariant.js ***! + \********************************************/ +/***/ ((module) => { -var isUpdatableParameter = function isUpdatableParameter(paramName) { - return updatableParams.indexOf(paramName) !== -1; -}; +"use strict"; /** - * Is deprecated parameter - * @param {String} paramName + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * */ -var isDeprecatedParameter = function isDeprecatedParameter(paramName) { - return deprecatedParams[paramName]; -}; - -var checkIfParamIsValid = function checkIfParamIsValid(param) { - if (!isValidParameter(param)) { - warn("Unknown parameter \"".concat(param, "\"")); - } -}; -var checkIfToastParamIsValid = function checkIfToastParamIsValid(param) { - if (toastIncompatibleParams.indexOf(param) !== -1) { - warn("The parameter \"".concat(param, "\" is incompatible with toasts")); - } -}; -var checkIfParamIsDeprecated = function checkIfParamIsDeprecated(param) { - if (isDeprecatedParameter(param)) { - warnAboutDepreation(param, isDeprecatedParameter(param)); - } -}; /** - * Show relevant warnings for given params + * Use invariant() to assert state which your program assumes to be true. * - * @param params + * Provide sprintf-style format (only %s is supported) and arguments + * to provide information about what broke and what you were + * expecting. + * + * The invariant message will be stripped in production, but the invariant + * will remain to ensure logic does not differ in production. */ +var validateFormat = function validateFormat(format) {}; -var showWarningsForParams = function showWarningsForParams(params) { - for (var param in params) { - checkIfParamIsValid(param); +if (true) { + validateFormat = function validateFormat(format) { + if (format === undefined) { + throw new Error('invariant requires an error message argument'); + } + }; +} - if (params.toast) { - checkIfToastParamIsValid(param); +function invariant(condition, format, a, b, c, d, e, f) { + validateFormat(format); + + if (!condition) { + var error; + if (format === undefined) { + error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.'); + } else { + var args = [a, b, c, d, e, f]; + var argIndex = 0; + error = new Error(format.replace(/%s/g, function () { + return args[argIndex++]; + })); + error.name = 'Invariant Violation'; } - checkIfParamIsDeprecated(); + error.framesToPop = 1; // we don't care about invariant's own frame + throw error; } -}; +} +module.exports = invariant; +/***/ }), -var staticMethods = Object.freeze({ - isValidParameter: isValidParameter, - isUpdatableParameter: isUpdatableParameter, - isDeprecatedParameter: isDeprecatedParameter, - argsToParams: argsToParams, - isVisible: isVisible$1, - clickConfirm: clickConfirm, - clickCancel: clickCancel, - getContainer: getContainer, - getPopup: getPopup, - getTitle: getTitle, - getContent: getContent, - getImage: getImage, - getIcon: getIcon, - getIcons: getIcons, - getCloseButton: getCloseButton, - getActions: getActions, - getConfirmButton: getConfirmButton, - getCancelButton: getCancelButton, - getHeader: getHeader, - getFooter: getFooter, - getFocusableElements: getFocusableElements, - getValidationMessage: getValidationMessage, - isLoading: isLoading, - fire: fire, - mixin: mixin, - queue: queue, - getQueueStep: getQueueStep, - insertQueueStep: insertQueueStep, - deleteQueueStep: deleteQueueStep, - showLoading: showLoading, - enableLoading: showLoading, - getTimerLeft: getTimerLeft, - stopTimer: stopTimer, - resumeTimer: resumeTimer, - toggleTimer: toggleTimer, - increaseTimer: increaseTimer, - isTimerRunning: isTimerRunning -}); +/***/ "./node_modules/fbjs/lib/warning.js": +/*!******************************************!*\ + !*** ./node_modules/fbjs/lib/warning.js ***! + \******************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { +"use strict"; /** - * Enables buttons and hide loader. + * Copyright (c) 2014-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * */ -function hideLoading() { - var innerParams = privateProps.innerParams.get(this); - var domCache = privateProps.domCache.get(this); - if (!innerParams.showConfirmButton) { - hide(domCache.confirmButton); - if (!innerParams.showCancelButton) { - hide(domCache.actions); +var emptyFunction = __webpack_require__(/*! ./emptyFunction */ "./node_modules/fbjs/lib/emptyFunction.js"); + +/** + * Similar to invariant but only logs a warning if the condition is not met. + * This can be used to log issues in development environments in critical + * paths. Removing the logging code for production environments will keep the + * same logic and follow the same code paths. + */ + +var warning = emptyFunction; + +if (true) { + var printWarning = function printWarning(format) { + for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; } - } - removeClass([domCache.popup, domCache.actions], swalClasses.loading); - domCache.popup.removeAttribute('aria-busy'); - domCache.popup.removeAttribute('data-loading'); - domCache.confirmButton.disabled = false; - domCache.cancelButton.disabled = false; + var argIndex = 0; + var message = 'Warning: ' + format.replace(/%s/g, function () { + return args[argIndex++]; + }); + if (typeof console !== 'undefined') { + console.error(message); + } + try { + // --- Welcome to debugging React --- + // This error was thrown as a convenience so that you can use this stack + // to find the callsite that caused this warning to fire. + throw new Error(message); + } catch (x) {} + }; + + warning = function warning(condition, format) { + if (format === undefined) { + throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); + } + + if (format.indexOf('Failed Composite propType: ') === 0) { + return; // Ignore CompositeComponent proptype check. + } + + if (!condition) { + for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { + args[_key2 - 2] = arguments[_key2]; + } + + printWarning.apply(undefined, [format].concat(args)); + } + }; } -function getInput$1(instance) { - var innerParams = privateProps.innerParams.get(instance || this); - var domCache = privateProps.domCache.get(instance || this); +module.exports = warning; - if (!domCache) { - return null; - } +/***/ }), - return getInput(domCache.content, innerParams.input); +/***/ "./node_modules/object-assign/index.js": +/*!*********************************************!*\ + !*** ./node_modules/object-assign/index.js ***! + \*********************************************/ +/***/ ((module) => { + +"use strict"; +/* +object-assign +(c) Sindre Sorhus +@license MIT +*/ + + +/* eslint-disable no-unused-vars */ +var getOwnPropertySymbols = Object.getOwnPropertySymbols; +var hasOwnProperty = Object.prototype.hasOwnProperty; +var propIsEnumerable = Object.prototype.propertyIsEnumerable; + +function toObject(val) { + if (val === null || val === undefined) { + throw new TypeError('Object.assign cannot be called with null or undefined'); + } + + return Object(val); } -var fixScrollbar = function fixScrollbar() { - // for queues, do not do this more than once - if (states.previousBodyPadding !== null) { - return; - } // if the body has overflow +function shouldUseNative() { + try { + if (!Object.assign) { + return false; + } + + // Detect buggy property enumeration order in older V8 versions. + + // https://bugs.chromium.org/p/v8/issues/detail?id=4118 + var test1 = new String('abc'); // eslint-disable-line no-new-wrappers + test1[5] = 'de'; + if (Object.getOwnPropertyNames(test1)[0] === '5') { + return false; + } + + // https://bugs.chromium.org/p/v8/issues/detail?id=3056 + var test2 = {}; + for (var i = 0; i < 10; i++) { + test2['_' + String.fromCharCode(i)] = i; + } + var order2 = Object.getOwnPropertyNames(test2).map(function (n) { + return test2[n]; + }); + if (order2.join('') !== '0123456789') { + return false; + } + + // https://bugs.chromium.org/p/v8/issues/detail?id=3056 + var test3 = {}; + 'abcdefghijklmnopqrst'.split('').forEach(function (letter) { + test3[letter] = letter; + }); + if (Object.keys(Object.assign({}, test3)).join('') !== + 'abcdefghijklmnopqrst') { + return false; + } + + return true; + } catch (err) { + // We don't expect any of the above to throw, but better to be safe. + return false; + } +} +module.exports = shouldUseNative() ? Object.assign : function (target, source) { + var from; + var to = toObject(target); + var symbols; - if (document.body.scrollHeight > window.innerHeight) { - // add padding so the content doesn't shift after removal of scrollbar - states.previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right')); - document.body.style.paddingRight = states.previousBodyPadding + measureScrollbar() + 'px'; - } -}; -var undoScrollbar = function undoScrollbar() { - if (states.previousBodyPadding !== null) { - document.body.style.paddingRight = states.previousBodyPadding + 'px'; - states.previousBodyPadding = null; - } -}; + for (var s = 1; s < arguments.length; s++) { + from = Object(arguments[s]); -/* istanbul ignore next */ + for (var key in from) { + if (hasOwnProperty.call(from, key)) { + to[key] = from[key]; + } + } -var iOSfix = function iOSfix() { - var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream || navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1; + if (getOwnPropertySymbols) { + symbols = getOwnPropertySymbols(from); + for (var i = 0; i < symbols.length; i++) { + if (propIsEnumerable.call(from, symbols[i])) { + to[symbols[i]] = from[symbols[i]]; + } + } + } + } - if (iOS && !hasClass(document.body, swalClasses.iosfix)) { - var offset = document.body.scrollTop; - document.body.style.top = offset * -1 + 'px'; - addClass(document.body, swalClasses.iosfix); - lockBodyScroll(); - } + return to; }; -var lockBodyScroll = function lockBodyScroll() { - // #1246 - var container = getContainer(); - var preventTouchMove; - container.ontouchstart = function (e) { - preventTouchMove = e.target === container || !isScrollable(container) && e.target.tagName !== 'INPUT' // #1603 - ; - }; +/***/ }), - container.ontouchmove = function (e) { - if (preventTouchMove) { - e.preventDefault(); - e.stopPropagation(); - } - }; -}; -/* istanbul ignore next */ +/***/ "./node_modules/prop-types/checkPropTypes.js": +/*!***************************************************!*\ + !*** ./node_modules/prop-types/checkPropTypes.js ***! + \***************************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { +"use strict"; +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ -var undoIOSfix = function undoIOSfix() { - if (hasClass(document.body, swalClasses.iosfix)) { - var offset = parseInt(document.body.style.top, 10); - removeClass(document.body, swalClasses.iosfix); - document.body.style.top = ''; - document.body.scrollTop = offset * -1; - } -}; -var isIE11 = function isIE11() { - return !!window.MSInputMethodContext && !!document.documentMode; -}; // Fix IE11 centering sweetalert2/issues/933 -/* istanbul ignore next */ +var printWarning = function() {}; +if (true) { + var ReactPropTypesSecret = __webpack_require__(/*! ./lib/ReactPropTypesSecret */ "./node_modules/prop-types/lib/ReactPropTypesSecret.js"); + var loggedTypeFailures = {}; + var has = __webpack_require__(/*! ./lib/has */ "./node_modules/prop-types/lib/has.js"); -var fixVerticalPositionIE = function fixVerticalPositionIE() { - var container = getContainer(); - var popup = getPopup(); - container.style.removeProperty('align-items'); + printWarning = function(text) { + var message = 'Warning: ' + text; + if (typeof console !== 'undefined') { + console.error(message); + } + try { + // --- Welcome to debugging React --- + // This error was thrown as a convenience so that you can use this stack + // to find the callsite that caused this warning to fire. + throw new Error(message); + } catch (x) { /**/ } + }; +} - if (popup.offsetTop < 0) { - container.style.alignItems = 'flex-start'; - } -}; -/* istanbul ignore next */ +/** + * Assert that the values match with the type specs. + * Error messages are memorized and will only be shown once. + * + * @param {object} typeSpecs Map of name to a ReactPropType + * @param {object} values Runtime values that need to be type-checked + * @param {string} location e.g. "prop", "context", "child context" + * @param {string} componentName Name of the component for error messages. + * @param {?Function} getStack Returns the component stack. + * @private + */ +function checkPropTypes(typeSpecs, values, location, componentName, getStack) { + if (true) { + for (var typeSpecName in typeSpecs) { + if (has(typeSpecs, typeSpecName)) { + var error; + // Prop type validation may throw. In case they do, we don't want to + // fail the render phase where it didn't fail before. So we log it. + // After these have been cleaned up, we'll let them throw. + try { + // This is intentionally an invariant that gets caught. It's the same + // behavior as without this statement except with a better message. + if (typeof typeSpecs[typeSpecName] !== 'function') { + var err = Error( + (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + + 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' + + 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.' + ); + err.name = 'Invariant Violation'; + throw err; + } + error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret); + } catch (ex) { + error = ex; + } + if (error && !(error instanceof Error)) { + printWarning( + (componentName || 'React class') + ': type specification of ' + + location + ' `' + typeSpecName + '` is invalid; the type checker ' + + 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' + + 'You may have forgotten to pass an argument to the type checker ' + + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + + 'shape all require an argument).' + ); + } + if (error instanceof Error && !(error.message in loggedTypeFailures)) { + // Only monitor this failure once because there tends to be a lot of the + // same error. + loggedTypeFailures[error.message] = true; + var stack = getStack ? getStack() : ''; -var IEfix = function IEfix() { - if (typeof window !== 'undefined' && isIE11()) { - fixVerticalPositionIE(); - window.addEventListener('resize', fixVerticalPositionIE); + printWarning( + 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '') + ); + } + } + } } -}; -/* istanbul ignore next */ +} -var undoIEfix = function undoIEfix() { - if (typeof window !== 'undefined' && isIE11()) { - window.removeEventListener('resize', fixVerticalPositionIE); +/** + * Resets warning cache when testing. + * + * @private + */ +checkPropTypes.resetWarningCache = function() { + if (true) { + loggedTypeFailures = {}; } -}; +} -// Adding aria-hidden="true" to elements outside of the active modal dialog ensures that -// elements not within the active modal dialog will not be surfaced if a user opens a screen -// reader’s list of elements (headings, form controls, landmarks, etc.) in the document. +module.exports = checkPropTypes; -var setAriaHidden = function setAriaHidden() { - var bodyChildren = toArray(document.body.children); - bodyChildren.forEach(function (el) { - if (el === getContainer() || contains(el, getContainer())) { - return; - } - if (el.hasAttribute('aria-hidden')) { - el.setAttribute('data-previous-aria-hidden', el.getAttribute('aria-hidden')); - } +/***/ }), - el.setAttribute('aria-hidden', 'true'); - }); -}; -var unsetAriaHidden = function unsetAriaHidden() { - var bodyChildren = toArray(document.body.children); - bodyChildren.forEach(function (el) { - if (el.hasAttribute('data-previous-aria-hidden')) { - el.setAttribute('aria-hidden', el.getAttribute('data-previous-aria-hidden')); - el.removeAttribute('data-previous-aria-hidden'); - } else { - el.removeAttribute('aria-hidden'); - } - }); -}; +/***/ "./node_modules/prop-types/factoryWithTypeCheckers.js": +/*!************************************************************!*\ + !*** ./node_modules/prop-types/factoryWithTypeCheckers.js ***! + \************************************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { +"use strict"; /** - * This module containts `WeakMap`s for each effectively-"private property" that a `Swal` has. - * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')` - * This is the approach that Babel will probably take to implement private methods/fields - * https://github.com/tc39/proposal-private-methods - * https://github.com/babel/babel/pull/7555 - * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module* - * then we can use that language feature. - */ -var privateMethods = { - swalPromiseResolve: new WeakMap() -}; - -/* - * Instance method to close sweetAlert - */ - -function removePopupAndResetState(instance, container, isToast, onAfterClose) { - if (isToast) { - triggerOnAfterCloseAndDispose(instance, onAfterClose); - } else { - restoreActiveElement().then(function () { - return triggerOnAfterCloseAndDispose(instance, onAfterClose); - }); - globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, { - capture: globalState.keydownListenerCapture - }); - globalState.keydownHandlerAdded = false; - } + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ - if (container.parentNode) { - container.parentNode.removeChild(container); - } - if (isModal()) { - undoScrollbar(); - undoIOSfix(); - undoIEfix(); - unsetAriaHidden(); - } - removeBodyClasses(); -} +var ReactIs = __webpack_require__(/*! react-is */ "./node_modules/react-is/index.js"); +var assign = __webpack_require__(/*! object-assign */ "./node_modules/object-assign/index.js"); -function removeBodyClasses() { - removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['toast-column']]); -} +var ReactPropTypesSecret = __webpack_require__(/*! ./lib/ReactPropTypesSecret */ "./node_modules/prop-types/lib/ReactPropTypesSecret.js"); +var has = __webpack_require__(/*! ./lib/has */ "./node_modules/prop-types/lib/has.js"); +var checkPropTypes = __webpack_require__(/*! ./checkPropTypes */ "./node_modules/prop-types/checkPropTypes.js"); -function disposeSwal(instance) { - // Unset this.params so GC will dispose it (#1569) - delete instance.params; // Unset globalState props so GC will dispose globalState (#1569) +var printWarning = function() {}; - delete globalState.keydownHandler; - delete globalState.keydownTarget; // Unset WeakMaps so GC will be able to dispose them (#1569) +if (true) { + printWarning = function(text) { + var message = 'Warning: ' + text; + if (typeof console !== 'undefined') { + console.error(message); + } + try { + // --- Welcome to debugging React --- + // This error was thrown as a convenience so that you can use this stack + // to find the callsite that caused this warning to fire. + throw new Error(message); + } catch (x) {} + }; +} - unsetWeakMaps(privateProps); - unsetWeakMaps(privateMethods); +function emptyFunctionThatReturnsNull() { + return null; } -function close(resolveValue) { - var popup = getPopup(); +module.exports = function(isValidElement, throwOnDirectAccess) { + /* global Symbol */ + var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; + var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. - if (!popup || hasClass(popup, swalClasses.hide)) { - return; + /** + * Returns the iterator method function contained on the iterable object. + * + * Be sure to invoke the function with the iterable as context: + * + * var iteratorFn = getIteratorFn(myIterable); + * if (iteratorFn) { + * var iterator = iteratorFn.call(myIterable); + * ... + * } + * + * @param {?object} maybeIterable + * @return {?function} + */ + function getIteratorFn(maybeIterable) { + var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]); + if (typeof iteratorFn === 'function') { + return iteratorFn; + } } - var innerParams = privateProps.innerParams.get(this); + /** + * Collection of methods that allow declaration and validation of props that are + * supplied to React components. Example usage: + * + * var Props = require('ReactPropTypes'); + * var MyArticle = React.createClass({ + * propTypes: { + * // An optional string prop named "description". + * description: Props.string, + * + * // A required enum prop named "category". + * category: Props.oneOf(['News','Photos']).isRequired, + * + * // A prop named "dialog" that requires an instance of Dialog. + * dialog: Props.instanceOf(Dialog).isRequired + * }, + * render: function() { ... } + * }); + * + * A more formal specification of how these methods are used: + * + * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) + * decl := ReactPropTypes.{type}(.isRequired)? + * + * Each and every declaration produces a function with the same signature. This + * allows the creation of custom validation functions. For example: + * + * var MyLink = React.createClass({ + * propTypes: { + * // An optional string or URI prop named "href". + * href: function(props, propName, componentName) { + * var propValue = props[propName]; + * if (propValue != null && typeof propValue !== 'string' && + * !(propValue instanceof URI)) { + * return new Error( + * 'Expected a string or an URI for ' + propName + ' in ' + + * componentName + * ); + * } + * } + * }, + * render: function() {...} + * }); + * + * @internal + */ - if (!innerParams) { - return; + var ANONYMOUS = '<>'; + + // Important! + // Keep this list in sync with production version in `./factoryWithThrowingShims.js`. + var ReactPropTypes = { + array: createPrimitiveTypeChecker('array'), + bigint: createPrimitiveTypeChecker('bigint'), + bool: createPrimitiveTypeChecker('boolean'), + func: createPrimitiveTypeChecker('function'), + number: createPrimitiveTypeChecker('number'), + object: createPrimitiveTypeChecker('object'), + string: createPrimitiveTypeChecker('string'), + symbol: createPrimitiveTypeChecker('symbol'), + + any: createAnyTypeChecker(), + arrayOf: createArrayOfTypeChecker, + element: createElementTypeChecker(), + elementType: createElementTypeTypeChecker(), + instanceOf: createInstanceTypeChecker, + node: createNodeChecker(), + objectOf: createObjectOfTypeChecker, + oneOf: createEnumTypeChecker, + oneOfType: createUnionTypeChecker, + shape: createShapeTypeChecker, + exact: createStrictShapeTypeChecker, + }; + + /** + * inlined Object.is polyfill to avoid requiring consumers ship their own + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is + */ + /*eslint-disable no-self-compare*/ + function is(x, y) { + // SameValue algorithm + if (x === y) { + // Steps 1-5, 7-10 + // Steps 6.b-6.e: +0 != -0 + return x !== 0 || 1 / x === 1 / y; + } else { + // Step 6.a: NaN == NaN + return x !== x && y !== y; + } } + /*eslint-enable no-self-compare*/ - var swalPromiseResolve = privateMethods.swalPromiseResolve.get(this); - removeClass(popup, swalClasses.show); - addClass(popup, swalClasses.hide); - handlePopupAnimation(this, popup, innerParams); // Resolve Swal promise + /** + * We use an Error-like object for backward compatibility as people may call + * PropTypes directly and inspect their output. However, we don't use real + * Errors anymore. We don't inspect their stack anyway, and creating them + * is prohibitively expensive if they are created too often, such as what + * happens in oneOfType() for any type before the one that matched. + */ + function PropTypeError(message, data) { + this.message = message; + this.data = data && typeof data === 'object' ? data: {}; + this.stack = ''; + } + // Make `instanceof Error` still work for returned errors. + PropTypeError.prototype = Error.prototype; - swalPromiseResolve(resolveValue || {}); -} + function createChainableTypeChecker(validate) { + if (true) { + var manualPropTypeCallCache = {}; + var manualPropTypeWarningCount = 0; + } + function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { + componentName = componentName || ANONYMOUS; + propFullName = propFullName || propName; -var handlePopupAnimation = function handlePopupAnimation(instance, popup, innerParams) { - var container = getContainer(); // If animation is supported, animate + if (secret !== ReactPropTypesSecret) { + if (throwOnDirectAccess) { + // New behavior only for users of `prop-types` package + var err = new Error( + 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + + 'Use `PropTypes.checkPropTypes()` to call them. ' + + 'Read more at http://fb.me/use-check-prop-types' + ); + err.name = 'Invariant Violation'; + throw err; + } else if ( true && typeof console !== 'undefined') { + // Old behavior for people using React.PropTypes + var cacheKey = componentName + ':' + propName; + if ( + !manualPropTypeCallCache[cacheKey] && + // Avoid spamming the console because they are often not actionable except for lib authors + manualPropTypeWarningCount < 3 + ) { + printWarning( + 'You are manually calling a React.PropTypes validation ' + + 'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' + + 'and will throw in the standalone `prop-types` package. ' + + 'You may be seeing this warning due to a third-party PropTypes ' + + 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.' + ); + manualPropTypeCallCache[cacheKey] = true; + manualPropTypeWarningCount++; + } + } + } + if (props[propName] == null) { + if (isRequired) { + if (props[propName] === null) { + return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); + } + return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); + } + return null; + } else { + return validate(props, propName, componentName, location, propFullName); + } + } - var animationIsSupported = animationEndEvent && hasCssAnimation(popup); - var onClose = innerParams.onClose, - onAfterClose = innerParams.onAfterClose; + var chainedCheckType = checkType.bind(null, false); + chainedCheckType.isRequired = checkType.bind(null, true); + + return chainedCheckType; + } + + function createPrimitiveTypeChecker(expectedType) { + function validate(props, propName, componentName, location, propFullName, secret) { + var propValue = props[propName]; + var propType = getPropType(propValue); + if (propType !== expectedType) { + // `propValue` being instance of, say, date/regexp, pass the 'object' + // check, but we can offer a more precise error message here rather than + // 'of type `object`'. + var preciseType = getPreciseType(propValue); + + return new PropTypeError( + 'Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'), + {expectedType: expectedType} + ); + } + return null; + } + return createChainableTypeChecker(validate); + } - if (onClose !== null && typeof onClose === 'function') { - onClose(popup); + function createAnyTypeChecker() { + return createChainableTypeChecker(emptyFunctionThatReturnsNull); } - if (animationIsSupported) { - animatePopup(instance, popup, container, onAfterClose); - } else { - // Otherwise, remove immediately - removePopupAndResetState(instance, container, isToast(), onAfterClose); + function createArrayOfTypeChecker(typeChecker) { + function validate(props, propName, componentName, location, propFullName) { + if (typeof typeChecker !== 'function') { + return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); + } + var propValue = props[propName]; + if (!Array.isArray(propValue)) { + var propType = getPropType(propValue); + return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); + } + for (var i = 0; i < propValue.length; i++) { + var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret); + if (error instanceof Error) { + return error; + } + } + return null; + } + return createChainableTypeChecker(validate); } -}; -var animatePopup = function animatePopup(instance, popup, container, onAfterClose) { - globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, isToast(), onAfterClose); - popup.addEventListener(animationEndEvent, function (e) { - if (e.target === popup) { - globalState.swalCloseEventFinishedCallback(); - delete globalState.swalCloseEventFinishedCallback; + function createElementTypeChecker() { + function validate(props, propName, componentName, location, propFullName) { + var propValue = props[propName]; + if (!isValidElement(propValue)) { + var propType = getPropType(propValue); + return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); + } + return null; } - }); -}; + return createChainableTypeChecker(validate); + } -var unsetWeakMaps = function unsetWeakMaps(obj) { - for (var i in obj) { - obj[i] = new WeakMap(); + function createElementTypeTypeChecker() { + function validate(props, propName, componentName, location, propFullName) { + var propValue = props[propName]; + if (!ReactIs.isValidElementType(propValue)) { + var propType = getPropType(propValue); + return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.')); + } + return null; + } + return createChainableTypeChecker(validate); } -}; -var triggerOnAfterCloseAndDispose = function triggerOnAfterCloseAndDispose(instance, onAfterClose) { - setTimeout(function () { - if (onAfterClose !== null && typeof onAfterClose === 'function') { - onAfterClose(); + function createInstanceTypeChecker(expectedClass) { + function validate(props, propName, componentName, location, propFullName) { + if (!(props[propName] instanceof expectedClass)) { + var expectedClassName = expectedClass.name || ANONYMOUS; + var actualClassName = getClassName(props[propName]); + return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); + } + return null; } + return createChainableTypeChecker(validate); + } - if (!getPopup()) { - disposeSwal(instance); + function createEnumTypeChecker(expectedValues) { + if (!Array.isArray(expectedValues)) { + if (true) { + if (arguments.length > 1) { + printWarning( + 'Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' + + 'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).' + ); + } else { + printWarning('Invalid argument supplied to oneOf, expected an array.'); + } + } + return emptyFunctionThatReturnsNull; } - }); -}; -function setButtonsDisabled(instance, buttons, disabled) { - var domCache = privateProps.domCache.get(instance); - buttons.forEach(function (button) { - domCache[button].disabled = disabled; - }); -} + function validate(props, propName, componentName, location, propFullName) { + var propValue = props[propName]; + for (var i = 0; i < expectedValues.length; i++) { + if (is(propValue, expectedValues[i])) { + return null; + } + } -function setInputDisabled(input, disabled) { - if (!input) { - return false; + var valuesString = JSON.stringify(expectedValues, function replacer(key, value) { + var type = getPreciseType(value); + if (type === 'symbol') { + return String(value); + } + return value; + }); + return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); + } + return createChainableTypeChecker(validate); } - if (input.type === 'radio') { - var radiosContainer = input.parentNode.parentNode; - var radios = radiosContainer.querySelectorAll('input'); - - for (var i = 0; i < radios.length; i++) { - radios[i].disabled = disabled; + function createObjectOfTypeChecker(typeChecker) { + function validate(props, propName, componentName, location, propFullName) { + if (typeof typeChecker !== 'function') { + return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.'); + } + var propValue = props[propName]; + var propType = getPropType(propValue); + if (propType !== 'object') { + return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); + } + for (var key in propValue) { + if (has(propValue, key)) { + var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret); + if (error instanceof Error) { + return error; + } + } + } + return null; } - } else { - input.disabled = disabled; + return createChainableTypeChecker(validate); } -} - -function enableButtons() { - setButtonsDisabled(this, ['confirmButton', 'cancelButton'], false); -} -function disableButtons() { - setButtonsDisabled(this, ['confirmButton', 'cancelButton'], true); -} // @deprecated -function enableConfirmButton() { - warnAboutDepreation('Swal.enableConfirmButton()', "Swal.getConfirmButton().removeAttribute('disabled')"); - setButtonsDisabled(this, ['confirmButton'], false); -} // @deprecated + function createUnionTypeChecker(arrayOfTypeCheckers) { + if (!Array.isArray(arrayOfTypeCheckers)) { + true ? printWarning('Invalid argument supplied to oneOfType, expected an instance of array.') : 0; + return emptyFunctionThatReturnsNull; + } -function disableConfirmButton() { - warnAboutDepreation('Swal.disableConfirmButton()', "Swal.getConfirmButton().setAttribute('disabled', '')"); - setButtonsDisabled(this, ['confirmButton'], true); -} -function enableInput() { - return setInputDisabled(this.getInput(), false); -} -function disableInput() { - return setInputDisabled(this.getInput(), true); -} + for (var i = 0; i < arrayOfTypeCheckers.length; i++) { + var checker = arrayOfTypeCheckers[i]; + if (typeof checker !== 'function') { + printWarning( + 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + + 'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.' + ); + return emptyFunctionThatReturnsNull; + } + } -function showValidationMessage(error) { - var domCache = privateProps.domCache.get(this); - domCache.validationMessage.innerHTML = error; - var popupComputedStyle = window.getComputedStyle(domCache.popup); - domCache.validationMessage.style.marginLeft = "-".concat(popupComputedStyle.getPropertyValue('padding-left')); - domCache.validationMessage.style.marginRight = "-".concat(popupComputedStyle.getPropertyValue('padding-right')); - show(domCache.validationMessage); - var input = this.getInput(); + function validate(props, propName, componentName, location, propFullName) { + var expectedTypes = []; + for (var i = 0; i < arrayOfTypeCheckers.length; i++) { + var checker = arrayOfTypeCheckers[i]; + var checkerResult = checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret); + if (checkerResult == null) { + return null; + } + if (checkerResult.data && has(checkerResult.data, 'expectedType')) { + expectedTypes.push(checkerResult.data.expectedType); + } + } + var expectedTypesMessage = (expectedTypes.length > 0) ? ', expected one of type [' + expectedTypes.join(', ') + ']': ''; + return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`' + expectedTypesMessage + '.')); + } + return createChainableTypeChecker(validate); + } - if (input) { - input.setAttribute('aria-invalid', true); - input.setAttribute('aria-describedBy', swalClasses['validation-message']); - focusInput(input); - addClass(input, swalClasses.inputerror); + function createNodeChecker() { + function validate(props, propName, componentName, location, propFullName) { + if (!isNode(props[propName])) { + return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); + } + return null; + } + return createChainableTypeChecker(validate); } -} // Hide block with validation message -function resetValidationMessage$1() { - var domCache = privateProps.domCache.get(this); + function invalidValidatorError(componentName, location, propFullName, key, type) { + return new PropTypeError( + (componentName || 'React class') + ': ' + location + ' type `' + propFullName + '.' + key + '` is invalid; ' + + 'it must be a function, usually from the `prop-types` package, but received `' + type + '`.' + ); + } - if (domCache.validationMessage) { - hide(domCache.validationMessage); + function createShapeTypeChecker(shapeTypes) { + function validate(props, propName, componentName, location, propFullName) { + var propValue = props[propName]; + var propType = getPropType(propValue); + if (propType !== 'object') { + return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); + } + for (var key in shapeTypes) { + var checker = shapeTypes[key]; + if (typeof checker !== 'function') { + return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker)); + } + var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret); + if (error) { + return error; + } + } + return null; + } + return createChainableTypeChecker(validate); } - var input = this.getInput(); + function createStrictShapeTypeChecker(shapeTypes) { + function validate(props, propName, componentName, location, propFullName) { + var propValue = props[propName]; + var propType = getPropType(propValue); + if (propType !== 'object') { + return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); + } + // We need to check all keys in case some are required but missing from props. + var allKeys = assign({}, props[propName], shapeTypes); + for (var key in allKeys) { + var checker = shapeTypes[key]; + if (has(shapeTypes, key) && typeof checker !== 'function') { + return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker)); + } + if (!checker) { + return new PropTypeError( + 'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + + '\nBad object: ' + JSON.stringify(props[propName], null, ' ') + + '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ') + ); + } + var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret); + if (error) { + return error; + } + } + return null; + } - if (input) { - input.removeAttribute('aria-invalid'); - input.removeAttribute('aria-describedBy'); - removeClass(input, swalClasses.inputerror); + return createChainableTypeChecker(validate); } -} - -function getProgressSteps$1() { - warnAboutDepreation('Swal.getProgressSteps()', "const swalInstance = Swal.fire({progressSteps: ['1', '2', '3']}); const progressSteps = swalInstance.params.progressSteps"); - var innerParams = privateProps.innerParams.get(this); - return innerParams.progressSteps; -} -function setProgressSteps(progressSteps) { - warnAboutDepreation('Swal.setProgressSteps()', 'Swal.update()'); - var innerParams = privateProps.innerParams.get(this); - - var updatedParams = _extends({}, innerParams, { - progressSteps: progressSteps - }); - renderProgressSteps(this, updatedParams); - privateProps.innerParams.set(this, updatedParams); -} -function showProgressSteps() { - var domCache = privateProps.domCache.get(this); - show(domCache.progressSteps); -} -function hideProgressSteps() { - var domCache = privateProps.domCache.get(this); - hide(domCache.progressSteps); -} + function isNode(propValue) { + switch (typeof propValue) { + case 'number': + case 'string': + case 'undefined': + return true; + case 'boolean': + return !propValue; + case 'object': + if (Array.isArray(propValue)) { + return propValue.every(isNode); + } + if (propValue === null || isValidElement(propValue)) { + return true; + } -var Timer = -/*#__PURE__*/ -function () { - function Timer(callback, delay) { - _classCallCheck(this, Timer); + var iteratorFn = getIteratorFn(propValue); + if (iteratorFn) { + var iterator = iteratorFn.call(propValue); + var step; + if (iteratorFn !== propValue.entries) { + while (!(step = iterator.next()).done) { + if (!isNode(step.value)) { + return false; + } + } + } else { + // Iterator will provide entry [k,v] tuples rather than values. + while (!(step = iterator.next()).done) { + var entry = step.value; + if (entry) { + if (!isNode(entry[1])) { + return false; + } + } + } + } + } else { + return false; + } - this.callback = callback; - this.remaining = delay; - this.running = false; - this.start(); + return true; + default: + return false; + } } - _createClass(Timer, [{ - key: "start", - value: function start() { - if (!this.running) { - this.running = true; - this.started = new Date(); - this.id = setTimeout(this.callback, this.remaining); - } + function isSymbol(propType, propValue) { + // Native Symbol. + if (propType === 'symbol') { + return true; + } - return this.remaining; + // falsy value can't be a Symbol + if (!propValue) { + return false; } - }, { - key: "stop", - value: function stop() { - if (this.running) { - this.running = false; - clearTimeout(this.id); - this.remaining -= new Date() - this.started; - } - return this.remaining; + // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' + if (propValue['@@toStringTag'] === 'Symbol') { + return true; } - }, { - key: "increase", - value: function increase(n) { - var running = this.running; - if (running) { - this.stop(); - } + // Fallback for non-spec compliant Symbols which are polyfilled. + if (typeof Symbol === 'function' && propValue instanceof Symbol) { + return true; + } - this.remaining += n; + return false; + } - if (running) { - this.start(); - } + // Equivalent of `typeof` but with special handling for array and regexp. + function getPropType(propValue) { + var propType = typeof propValue; + if (Array.isArray(propValue)) { + return 'array'; + } + if (propValue instanceof RegExp) { + // Old webkits (at least until Android 4.0) return 'function' rather than + // 'object' for typeof a RegExp. We'll normalize this here so that /bla/ + // passes PropTypes.object. + return 'object'; + } + if (isSymbol(propType, propValue)) { + return 'symbol'; + } + return propType; + } - return this.remaining; + // This handles more types than `getPropType`. Only used for error messages. + // See `createPrimitiveTypeChecker`. + function getPreciseType(propValue) { + if (typeof propValue === 'undefined' || propValue === null) { + return '' + propValue; } - }, { - key: "getTimerLeft", - value: function getTimerLeft() { - if (this.running) { - this.stop(); - this.start(); + var propType = getPropType(propValue); + if (propType === 'object') { + if (propValue instanceof Date) { + return 'date'; + } else if (propValue instanceof RegExp) { + return 'regexp'; } + } + return propType; + } - return this.remaining; + // Returns a string that is postfixed to a warning about an invalid type. + // For example, "undefined" or "of type array" + function getPostfixForTypeWarning(value) { + var type = getPreciseType(value); + switch (type) { + case 'array': + case 'object': + return 'an ' + type; + case 'boolean': + case 'date': + case 'regexp': + return 'a ' + type; + default: + return type; } - }, { - key: "isRunning", - value: function isRunning() { - return this.running; + } + + // Returns class name of the object, if any. + function getClassName(propValue) { + if (!propValue.constructor || !propValue.constructor.name) { + return ANONYMOUS; } - }]); + return propValue.constructor.name; + } - return Timer; -}(); + ReactPropTypes.checkPropTypes = checkPropTypes; + ReactPropTypes.resetWarningCache = checkPropTypes.resetWarningCache; + ReactPropTypes.PropTypes = ReactPropTypes; -var defaultInputValidators = { - email: function email(string, validationMessage) { - return /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,24}$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage || 'Invalid email address'); - }, - url: function url(string, validationMessage) { - // taken from https://stackoverflow.com/a/3809435 with a small change from #1306 - return /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage || 'Invalid URL'); - } + return ReactPropTypes; }; -function setDefaultInputValidators(params) { - // Use default `inputValidator` for supported input types if not provided - if (!params.inputValidator) { - Object.keys(defaultInputValidators).forEach(function (key) { - if (params.input === key) { - params.inputValidator = defaultInputValidators[key]; - } - }); - } -} -function validateCustomTargetElement(params) { - // Determine if the custom target element is valid - if (!params.target || typeof params.target === 'string' && !document.querySelector(params.target) || typeof params.target !== 'string' && !params.target.appendChild) { - warn('Target parameter is not valid, defaulting to "body"'); - params.target = 'body'; - } -} +/***/ }), + +/***/ "./node_modules/prop-types/index.js": +/*!******************************************!*\ + !*** ./node_modules/prop-types/index.js ***! + \******************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { + /** - * Set type, text and actions on popup + * Copyright (c) 2013-present, Facebook, Inc. * - * @param params - * @returns {boolean} + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ +if (true) { + var ReactIs = __webpack_require__(/*! react-is */ "./node_modules/react-is/index.js"); -function setParameters(params) { - setDefaultInputValidators(params); // showLoaderOnConfirm && preConfirm - - if (params.showLoaderOnConfirm && !params.preConfirm) { - warn('showLoaderOnConfirm is set to true, but preConfirm is not defined.\n' + 'showLoaderOnConfirm should be used together with preConfirm, see usage example:\n' + 'https://sweetalert2.github.io/#ajax-request'); - } // params.animation will be actually used in renderPopup.js - // but in case when params.animation is a function, we need to call that function - // before popup (re)initialization, so it'll be possible to check Swal.isVisible() - // inside the params.animation function - + // By explicitly using `prop-types` you are opting into new development behavior. + // http://fb.me/prop-types-in-prod + var throwOnDirectAccess = true; + module.exports = __webpack_require__(/*! ./factoryWithTypeCheckers */ "./node_modules/prop-types/factoryWithTypeCheckers.js")(ReactIs.isElement, throwOnDirectAccess); +} else {} - params.animation = callIfFunction(params.animation); - validateCustomTargetElement(params); // Replace newlines with
in title - if (typeof params.title === 'string') { - params.title = params.title.split('\n').join('
'); - } +/***/ }), - init(params); -} +/***/ "./node_modules/prop-types/lib/ReactPropTypesSecret.js": +/*!*************************************************************!*\ + !*** ./node_modules/prop-types/lib/ReactPropTypesSecret.js ***! + \*************************************************************/ +/***/ ((module) => { -function swalOpenAnimationFinished(popup, container) { - popup.removeEventListener(animationEndEvent, swalOpenAnimationFinished); - container.style.overflowY = 'auto'; -} +"use strict"; /** - * Open popup, add necessary classes and styles, fix scrollbar + * Copyright (c) 2013-present, Facebook, Inc. * - * @param {Array} params + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ -var openPopup = function openPopup(params) { - var container = getContainer(); - var popup = getPopup(); - - if (typeof params.onBeforeOpen === 'function') { - params.onBeforeOpen(popup); - } - addClasses(container, popup, params); // scrolling is 'hidden' until animation is done, after that 'auto' +var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; - setScrollingVisibility(container, popup); +module.exports = ReactPropTypesSecret; - if (isModal()) { - fixScrollContainer(container, params.scrollbarPadding); - } - if (!isToast() && !globalState.previousActiveElement) { - globalState.previousActiveElement = document.activeElement; - } +/***/ }), - if (typeof params.onOpen === 'function') { - setTimeout(function () { - return params.onOpen(popup); - }); - } -}; +/***/ "./node_modules/prop-types/lib/has.js": +/*!********************************************!*\ + !*** ./node_modules/prop-types/lib/has.js ***! + \********************************************/ +/***/ ((module) => { -var setScrollingVisibility = function setScrollingVisibility(container, popup) { - if (animationEndEvent && hasCssAnimation(popup)) { - container.style.overflowY = 'hidden'; - popup.addEventListener(animationEndEvent, swalOpenAnimationFinished.bind(null, popup, container)); - } else { - container.style.overflowY = 'auto'; - } -}; +module.exports = Function.call.bind(Object.prototype.hasOwnProperty); -var fixScrollContainer = function fixScrollContainer(container, scrollbarPadding) { - iOSfix(); - IEfix(); - setAriaHidden(); - if (scrollbarPadding) { - fixScrollbar(); - } // sweetalert2/issues/1247 +/***/ }), +/***/ "./node_modules/react-addons-create-fragment/index.js": +/*!************************************************************!*\ + !*** ./node_modules/react-addons-create-fragment/index.js ***! + \************************************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { - setTimeout(function () { - container.scrollTop = 0; - }); -}; +"use strict"; +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ -var addClasses = function addClasses(container, popup, params) { - if (params.animation) { - addClass(popup, swalClasses.show); - } - show(popup); - addClass([document.documentElement, document.body, container], swalClasses.shown); - if (params.heightAuto && params.backdrop && !params.toast) { - addClass([document.documentElement, document.body], swalClasses['height-auto']); - } -}; +var React = __webpack_require__(/*! react */ "react"); -var handleInputOptionsAndValue = function handleInputOptionsAndValue(instance, params) { - if (params.input === 'select' || params.input === 'radio') { - handleInputOptions(instance, params); - } else if (['text', 'email', 'number', 'tel', 'textarea'].indexOf(params.input) !== -1 && isPromise(params.inputValue)) { - handleInputValue(instance, params); - } -}; -var getInputValue = function getInputValue(instance, innerParams) { - var input = instance.getInput(); +var REACT_ELEMENT_TYPE = + (typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element')) || + 0xeac7; - if (!input) { - return null; - } +var emptyFunction = __webpack_require__(/*! fbjs/lib/emptyFunction */ "./node_modules/fbjs/lib/emptyFunction.js"); +var invariant = __webpack_require__(/*! fbjs/lib/invariant */ "./node_modules/fbjs/lib/invariant.js"); +var warning = __webpack_require__(/*! fbjs/lib/warning */ "./node_modules/fbjs/lib/warning.js"); - switch (innerParams.input) { - case 'checkbox': - return getCheckboxValue(input); +var SEPARATOR = '.'; +var SUBSEPARATOR = ':'; - case 'radio': - return getRadioValue(input); +var didWarnAboutMaps = false; - case 'file': - return getFileValue(input); +var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; +var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. - default: - return innerParams.inputAutoTrim ? input.value.trim() : input.value; +function getIteratorFn(maybeIterable) { + var iteratorFn = + maybeIterable && + ((ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL]) || + maybeIterable[FAUX_ITERATOR_SYMBOL]); + if (typeof iteratorFn === 'function') { + return iteratorFn; } -}; - -var getCheckboxValue = function getCheckboxValue(input) { - return input.checked ? 1 : 0; -}; +} -var getRadioValue = function getRadioValue(input) { - return input.checked ? input.value : null; -}; +function escape(key) { + var escapeRegex = /[=:]/g; + var escaperLookup = { + '=': '=0', + ':': '=2' + }; + var escapedString = ('' + key).replace(escapeRegex, function(match) { + return escaperLookup[match]; + }); -var getFileValue = function getFileValue(input) { - return input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null; -}; + return '$' + escapedString; +} -var handleInputOptions = function handleInputOptions(instance, params) { - var content = getContent(); +function getComponentKey(component, index) { + // Do some typechecking here since we call this blindly. We want to ensure + // that we don't block potential future ES APIs. + if (component && typeof component === 'object' && component.key != null) { + // Explicit key + return escape(component.key); + } + // Implicit key determined by the index in the set + return index.toString(36); +} - var processInputOptions = function processInputOptions(inputOptions) { - return populateInputOptions[params.input](content, formatInputOptions(inputOptions), params); - }; +function traverseAllChildrenImpl( + children, + nameSoFar, + callback, + traverseContext +) { + var type = typeof children; - if (isPromise(params.inputOptions)) { - showLoading(); - params.inputOptions.then(function (inputOptions) { - instance.hideLoading(); - processInputOptions(inputOptions); - }); - } else if (_typeof(params.inputOptions) === 'object') { - processInputOptions(params.inputOptions); - } else { - error("Unexpected type of inputOptions! Expected object, Map or Promise, got ".concat(_typeof(params.inputOptions))); + if (type === 'undefined' || type === 'boolean') { + // All of the above are perceived as null. + children = null; } -}; -var handleInputValue = function handleInputValue(instance, params) { - var input = instance.getInput(); - hide(input); - params.inputValue.then(function (inputValue) { - input.value = params.input === 'number' ? parseFloat(inputValue) || 0 : inputValue + ''; - show(input); - input.focus(); - instance.hideLoading(); - })["catch"](function (err) { - error('Error in inputValue promise: ' + err); - input.value = ''; - show(input); - input.focus(); - instance.hideLoading(); - }); -}; + if ( + children === null || + type === 'string' || + type === 'number' || + // The following is inlined from ReactElement. This means we can optimize + // some checks. React Fiber also inlines this logic for similar purposes. + (type === 'object' && children.$$typeof === REACT_ELEMENT_TYPE) + ) { + callback( + traverseContext, + children, + // If it's the only child, treat the name as if it was wrapped in an array + // so that it's consistent if the number of children grows. + nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar + ); + return 1; + } -var populateInputOptions = { - select: function select(content, inputOptions, params) { - var select = getChildByClass(content, swalClasses.select); - inputOptions.forEach(function (inputOption) { - var optionValue = inputOption[0]; - var optionLabel = inputOption[1]; - var option = document.createElement('option'); - option.value = optionValue; - option.innerHTML = optionLabel; + var child; + var nextName; + var subtreeCount = 0; // Count of children found in the current subtree. + var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR; - if (params.inputValue.toString() === optionValue.toString()) { - option.selected = true; + if (Array.isArray(children)) { + for (var i = 0; i < children.length; i++) { + child = children[i]; + nextName = nextNamePrefix + getComponentKey(child, i); + subtreeCount += traverseAllChildrenImpl( + child, + nextName, + callback, + traverseContext + ); + } + } else { + var iteratorFn = getIteratorFn(children); + if (iteratorFn) { + if (true) { + // Warn about using Maps as children + if (iteratorFn === children.entries) { + warning( + didWarnAboutMaps, + 'Using Maps as children is unsupported and will likely yield ' + + 'unexpected results. Convert it to a sequence/iterable of keyed ' + + 'ReactElements instead.' + ); + didWarnAboutMaps = true; + } } - select.appendChild(option); - }); - select.focus(); - }, - radio: function radio(content, inputOptions, params) { - var radio = getChildByClass(content, swalClasses.radio); - inputOptions.forEach(function (inputOption) { - var radioValue = inputOption[0]; - var radioLabel = inputOption[1]; - var radioInput = document.createElement('input'); - var radioLabelElement = document.createElement('label'); - radioInput.type = 'radio'; - radioInput.name = swalClasses.radio; - radioInput.value = radioValue; - - if (params.inputValue.toString() === radioValue.toString()) { - radioInput.checked = true; + var iterator = iteratorFn.call(children); + var step; + var ii = 0; + while (!(step = iterator.next()).done) { + child = step.value; + nextName = nextNamePrefix + getComponentKey(child, ii++); + subtreeCount += traverseAllChildrenImpl( + child, + nextName, + callback, + traverseContext + ); } - - var label = document.createElement('span'); - label.innerHTML = radioLabel; - label.className = swalClasses.label; - radioLabelElement.appendChild(radioInput); - radioLabelElement.appendChild(label); - radio.appendChild(radioLabelElement); - }); - var radios = radio.querySelectorAll('input'); - - if (radios.length) { - radios[0].focus(); + } else if (type === 'object') { + var addendum = ''; + if (true) { + addendum = + ' If you meant to render a collection of children, use an array ' + + 'instead or wrap the object using createFragment(object) from the ' + + 'React add-ons.'; + } + var childrenString = '' + children; + invariant( + false, + 'Objects are not valid as a React child (found: %s).%s', + childrenString === '[object Object]' + ? 'object with keys {' + Object.keys(children).join(', ') + '}' + : childrenString, + addendum + ); } } -}; -/** - * Converts `inputOptions` into an array of `[value, label]`s - * @param inputOptions - */ -var formatInputOptions = function formatInputOptions(inputOptions) { - var result = []; + return subtreeCount; +} - if (typeof Map !== 'undefined' && inputOptions instanceof Map) { - inputOptions.forEach(function (value, key) { - result.push([key, value]); - }); - } else { - Object.keys(inputOptions).forEach(function (key) { - result.push([key, inputOptions[key]]); - }); +function traverseAllChildren(children, callback, traverseContext) { + if (children == null) { + return 0; } - return result; -}; + return traverseAllChildrenImpl(children, '', callback, traverseContext); +} -var handleConfirmButtonClick = function handleConfirmButtonClick(instance, innerParams) { - instance.disableButtons(); +var userProvidedKeyEscapeRegex = /\/+/g; +function escapeUserProvidedKey(text) { + return ('' + text).replace(userProvidedKeyEscapeRegex, '$&/'); +} - if (innerParams.input) { - handleConfirmWithInput(instance, innerParams); +function cloneAndReplaceKey(oldElement, newKey) { + return React.cloneElement( + oldElement, + {key: newKey}, + oldElement.props !== undefined ? oldElement.props.children : undefined + ); +} + +var DEFAULT_POOL_SIZE = 10; +var DEFAULT_POOLER = oneArgumentPooler; + +var oneArgumentPooler = function(copyFieldsFrom) { + var Klass = this; + if (Klass.instancePool.length) { + var instance = Klass.instancePool.pop(); + Klass.call(instance, copyFieldsFrom); + return instance; } else { - confirm(instance, innerParams, true); + return new Klass(copyFieldsFrom); } }; -var handleCancelButtonClick = function handleCancelButtonClick(instance, dismissWith) { - instance.disableButtons(); - dismissWith(DismissReason.cancel); -}; -var handleConfirmWithInput = function handleConfirmWithInput(instance, innerParams) { - var inputValue = getInputValue(instance, innerParams); +var addPoolingTo = function addPoolingTo(CopyConstructor, pooler) { + // Casting as any so that flow ignores the actual implementation and trusts + // it to match the type we declared + var NewKlass = CopyConstructor; + NewKlass.instancePool = []; + NewKlass.getPooled = pooler || DEFAULT_POOLER; + if (!NewKlass.poolSize) { + NewKlass.poolSize = DEFAULT_POOL_SIZE; + } + NewKlass.release = standardReleaser; + return NewKlass; +}; - if (innerParams.inputValidator) { - instance.disableInput(); - var validationPromise = Promise.resolve().then(function () { - return innerParams.inputValidator(inputValue, innerParams.validationMessage); - }); - validationPromise.then(function (validationMessage) { - instance.enableButtons(); - instance.enableInput(); +var standardReleaser = function standardReleaser(instance) { + var Klass = this; + invariant( + instance instanceof Klass, + 'Trying to release an instance into a pool of a different type.' + ); + instance.destructor(); + if (Klass.instancePool.length < Klass.poolSize) { + Klass.instancePool.push(instance); + } +}; - if (validationMessage) { - instance.showValidationMessage(validationMessage); - } else { - confirm(instance, innerParams, inputValue); - } - }); - } else if (!instance.getInput().checkValidity()) { - instance.enableButtons(); - instance.showValidationMessage(innerParams.validationMessage); +var fourArgumentPooler = function fourArgumentPooler(a1, a2, a3, a4) { + var Klass = this; + if (Klass.instancePool.length) { + var instance = Klass.instancePool.pop(); + Klass.call(instance, a1, a2, a3, a4); + return instance; } else { - confirm(instance, innerParams, inputValue); + return new Klass(a1, a2, a3, a4); } }; -var succeedWith = function succeedWith(instance, value) { - instance.closePopup({ - value: value - }); +function MapBookKeeping(mapResult, keyPrefix, mapFunction, mapContext) { + this.result = mapResult; + this.keyPrefix = keyPrefix; + this.func = mapFunction; + this.context = mapContext; + this.count = 0; +} +MapBookKeeping.prototype.destructor = function() { + this.result = null; + this.keyPrefix = null; + this.func = null; + this.context = null; + this.count = 0; }; +addPoolingTo(MapBookKeeping, fourArgumentPooler); -var confirm = function confirm(instance, innerParams, value) { - if (innerParams.showLoaderOnConfirm) { - showLoading(); // TODO: make showLoading an *instance* method - } +function mapSingleChildIntoContext(bookKeeping, child, childKey) { + var result = bookKeeping.result; + var keyPrefix = bookKeeping.keyPrefix; + var func = bookKeeping.func; + var context = bookKeeping.context; - if (innerParams.preConfirm) { - instance.resetValidationMessage(); - var preConfirmPromise = Promise.resolve().then(function () { - return innerParams.preConfirm(value, innerParams.validationMessage); - }); - preConfirmPromise.then(function (preConfirmValue) { - if (isVisible(getValidationMessage()) || preConfirmValue === false) { - instance.hideLoading(); - } else { - succeedWith(instance, typeof preConfirmValue === 'undefined' ? value : preConfirmValue); - } - }); - } else { - succeedWith(instance, value); + var mappedChild = func.call(context, child, bookKeeping.count++); + if (Array.isArray(mappedChild)) { + mapIntoWithKeyPrefixInternal( + mappedChild, + result, + childKey, + emptyFunction.thatReturnsArgument + ); + } else if (mappedChild != null) { + if (React.isValidElement(mappedChild)) { + mappedChild = cloneAndReplaceKey( + mappedChild, + // Keep both the (mapped) and old keys if they differ, just as + // traverseAllChildren used to do for objects as children + keyPrefix + + (mappedChild.key && (!child || child.key !== mappedChild.key) + ? escapeUserProvidedKey(mappedChild.key) + '/' + : '') + + childKey + ); + } + result.push(mappedChild); } -}; +} -var addKeydownHandler = function addKeydownHandler(instance, globalState, innerParams, dismissWith) { - if (globalState.keydownTarget && globalState.keydownHandlerAdded) { - globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, { - capture: globalState.keydownListenerCapture - }); - globalState.keydownHandlerAdded = false; +function mapIntoWithKeyPrefixInternal(children, array, prefix, func, context) { + var escapedPrefix = ''; + if (prefix != null) { + escapedPrefix = escapeUserProvidedKey(prefix) + '/'; } + var traverseContext = MapBookKeeping.getPooled( + array, + escapedPrefix, + func, + context + ); + traverseAllChildren(children, mapSingleChildIntoContext, traverseContext); + MapBookKeeping.release(traverseContext); +} - if (!innerParams.toast) { - globalState.keydownHandler = function (e) { - return keydownHandler(instance, e, innerParams, dismissWith); - }; +var numericPropertyRegex = /^\d+$/; - globalState.keydownTarget = innerParams.keydownListenerCapture ? window : getPopup(); - globalState.keydownListenerCapture = innerParams.keydownListenerCapture; - globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, { - capture: globalState.keydownListenerCapture - }); - globalState.keydownHandlerAdded = true; +var warnedAboutNumeric = false; + +function createReactFragment(object) { + if (typeof object !== 'object' || !object || Array.isArray(object)) { + warning( + false, + 'React.addons.createFragment only accepts a single object. Got: %s', + object + ); + return object; + } + if (React.isValidElement(object)) { + warning( + false, + 'React.addons.createFragment does not accept a ReactElement ' + + 'without a wrapper object.' + ); + return object; } -}; // Focus handling -var setFocus = function setFocus(innerParams, index, increment) { - var focusableElements = getFocusableElements(); // search for visible elements and select the next possible match + invariant( + object.nodeType !== 1, + 'React.addons.createFragment(...): Encountered an invalid child; DOM ' + + 'elements are not valid children of React components.' + ); - for (var i = 0; i < focusableElements.length; i++) { - index = index + increment; // rollover to first item + var result = []; - if (index === focusableElements.length) { - index = 0; // go to last item - } else if (index === -1) { - index = focusableElements.length - 1; + for (var key in object) { + if (true) { + if (!warnedAboutNumeric && numericPropertyRegex.test(key)) { + warning( + false, + 'React.addons.createFragment(...): Child objects should have ' + + 'non-numeric keys so ordering is preserved.' + ); + warnedAboutNumeric = true; + } } + mapIntoWithKeyPrefixInternal( + object[key], + result, + key, + emptyFunction.thatReturnsArgument + ); + } - return focusableElements[index].focus(); - } // no visible focusable elements, focus the popup + return result; +} +module.exports = createReactFragment; - getPopup().focus(); -}; -var arrowKeys = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Left', 'Right', 'Up', 'Down' // IE11 -]; -var escKeys = ['Escape', 'Esc' // IE11 -]; -var keydownHandler = function keydownHandler(instance, e, innerParams, dismissWith) { - if (innerParams.stopKeydownPropagation) { - e.stopPropagation(); - } // ENTER +/***/ }), +/***/ "./node_modules/react-is/cjs/react-is.development.js": +/*!***********************************************************!*\ + !*** ./node_modules/react-is/cjs/react-is.development.js ***! + \***********************************************************/ +/***/ ((__unused_webpack_module, exports) => { - if (e.key === 'Enter') { - handleEnter(instance, e, innerParams); // TAB - } else if (e.key === 'Tab') { - handleTab(e, innerParams); // ARROWS - switch focus between buttons - } else if (arrowKeys.indexOf(e.key) !== -1) { - handleArrows(); // ESC - } else if (escKeys.indexOf(e.key) !== -1) { - handleEsc(e, innerParams, dismissWith); - } -}; +"use strict"; +/** @license React v16.13.1 + * react-is.development.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ -var handleEnter = function handleEnter(instance, e, innerParams) { - // #720 #721 - if (e.isComposing) { - return; - } - if (e.target && instance.getInput() && e.target.outerHTML === instance.getInput().outerHTML) { - if (['textarea', 'file'].indexOf(innerParams.input) !== -1) { - return; // do not submit - } - clickConfirm(); - e.preventDefault(); - } -}; -var handleTab = function handleTab(e, innerParams) { - var targetElement = e.target; - var focusableElements = getFocusableElements(); - var btnIndex = -1; - for (var i = 0; i < focusableElements.length; i++) { - if (targetElement === focusableElements[i]) { - btnIndex = i; - break; - } - } +if (true) { + (function() { +'use strict'; - if (!e.shiftKey) { - // Cycle to the next button - setFocus(innerParams, btnIndex, 1); - } else { - // Cycle to the prev button - setFocus(innerParams, btnIndex, -1); - } +// The Symbol used to tag the ReactElement-like types. If there is no native Symbol +// nor polyfill, then a plain number is used for performance. +var hasSymbol = typeof Symbol === 'function' && Symbol.for; +var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7; +var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca; +var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb; +var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc; +var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2; +var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd; +var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary +// (unstable) APIs that have been removed. Can we remove the symbols? - e.stopPropagation(); - e.preventDefault(); -}; +var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf; +var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf; +var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0; +var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1; +var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8; +var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3; +var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4; +var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9; +var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5; +var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6; +var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7; -var handleArrows = function handleArrows() { - var confirmButton = getConfirmButton(); - var cancelButton = getCancelButton(); // focus Cancel button if Confirm button is currently focused +function isValidElementType(type) { + return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill. + type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE || type.$$typeof === REACT_BLOCK_TYPE); +} - if (document.activeElement === confirmButton && isVisible(cancelButton)) { - cancelButton.focus(); // and vice versa - } else if (document.activeElement === cancelButton && isVisible(confirmButton)) { - confirmButton.focus(); - } -}; +function typeOf(object) { + if (typeof object === 'object' && object !== null) { + var $$typeof = object.$$typeof; -var handleEsc = function handleEsc(e, innerParams, dismissWith) { - if (callIfFunction(innerParams.allowEscapeKey)) { - e.preventDefault(); - dismissWith(DismissReason.esc); - } -}; + switch ($$typeof) { + case REACT_ELEMENT_TYPE: + var type = object.type; -var handlePopupClick = function handlePopupClick(domCache, innerParams, dismissWith) { - if (innerParams.toast) { - handleToastClick(domCache, innerParams, dismissWith); - } else { - // Ignore click events that had mousedown on the popup but mouseup on the container - // This can happen when the user drags a slider - handleModalMousedown(domCache); // Ignore click events that had mousedown on the container but mouseup on the popup + switch (type) { + case REACT_ASYNC_MODE_TYPE: + case REACT_CONCURRENT_MODE_TYPE: + case REACT_FRAGMENT_TYPE: + case REACT_PROFILER_TYPE: + case REACT_STRICT_MODE_TYPE: + case REACT_SUSPENSE_TYPE: + return type; - handleContainerMousedown(domCache); - handleModalClick(domCache, innerParams, dismissWith); - } -}; + default: + var $$typeofType = type && type.$$typeof; -var handleToastClick = function handleToastClick(domCache, innerParams, dismissWith) { - // Closing toast by internal click - domCache.popup.onclick = function () { - if (innerParams.showConfirmButton || innerParams.showCancelButton || innerParams.showCloseButton || innerParams.input) { - return; + switch ($$typeofType) { + case REACT_CONTEXT_TYPE: + case REACT_FORWARD_REF_TYPE: + case REACT_LAZY_TYPE: + case REACT_MEMO_TYPE: + case REACT_PROVIDER_TYPE: + return $$typeofType; + + default: + return $$typeof; + } + + } + + case REACT_PORTAL_TYPE: + return $$typeof; } + } - dismissWith(DismissReason.close); - }; -}; + return undefined; +} // AsyncMode is deprecated along with isAsyncMode -var ignoreOutsideClick = false; +var AsyncMode = REACT_ASYNC_MODE_TYPE; +var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE; +var ContextConsumer = REACT_CONTEXT_TYPE; +var ContextProvider = REACT_PROVIDER_TYPE; +var Element = REACT_ELEMENT_TYPE; +var ForwardRef = REACT_FORWARD_REF_TYPE; +var Fragment = REACT_FRAGMENT_TYPE; +var Lazy = REACT_LAZY_TYPE; +var Memo = REACT_MEMO_TYPE; +var Portal = REACT_PORTAL_TYPE; +var Profiler = REACT_PROFILER_TYPE; +var StrictMode = REACT_STRICT_MODE_TYPE; +var Suspense = REACT_SUSPENSE_TYPE; +var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated -var handleModalMousedown = function handleModalMousedown(domCache) { - domCache.popup.onmousedown = function () { - domCache.container.onmouseup = function (e) { - domCache.container.onmouseup = undefined; // We only check if the mouseup target is the container because usually it doesn't - // have any other direct children aside of the popup +function isAsyncMode(object) { + { + if (!hasWarnedAboutDeprecatedIsAsyncMode) { + hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint - if (e.target === domCache.container) { - ignoreOutsideClick = true; - } - }; - }; -}; + console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.'); + } + } -var handleContainerMousedown = function handleContainerMousedown(domCache) { - domCache.container.onmousedown = function () { - domCache.popup.onmouseup = function (e) { - domCache.popup.onmouseup = undefined; // We also need to check if the mouseup target is a child of the popup + return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE; +} +function isConcurrentMode(object) { + return typeOf(object) === REACT_CONCURRENT_MODE_TYPE; +} +function isContextConsumer(object) { + return typeOf(object) === REACT_CONTEXT_TYPE; +} +function isContextProvider(object) { + return typeOf(object) === REACT_PROVIDER_TYPE; +} +function isElement(object) { + return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE; +} +function isForwardRef(object) { + return typeOf(object) === REACT_FORWARD_REF_TYPE; +} +function isFragment(object) { + return typeOf(object) === REACT_FRAGMENT_TYPE; +} +function isLazy(object) { + return typeOf(object) === REACT_LAZY_TYPE; +} +function isMemo(object) { + return typeOf(object) === REACT_MEMO_TYPE; +} +function isPortal(object) { + return typeOf(object) === REACT_PORTAL_TYPE; +} +function isProfiler(object) { + return typeOf(object) === REACT_PROFILER_TYPE; +} +function isStrictMode(object) { + return typeOf(object) === REACT_STRICT_MODE_TYPE; +} +function isSuspense(object) { + return typeOf(object) === REACT_SUSPENSE_TYPE; +} - if (e.target === domCache.popup || domCache.popup.contains(e.target)) { - ignoreOutsideClick = true; - } - }; - }; -}; +exports.AsyncMode = AsyncMode; +exports.ConcurrentMode = ConcurrentMode; +exports.ContextConsumer = ContextConsumer; +exports.ContextProvider = ContextProvider; +exports.Element = Element; +exports.ForwardRef = ForwardRef; +exports.Fragment = Fragment; +exports.Lazy = Lazy; +exports.Memo = Memo; +exports.Portal = Portal; +exports.Profiler = Profiler; +exports.StrictMode = StrictMode; +exports.Suspense = Suspense; +exports.isAsyncMode = isAsyncMode; +exports.isConcurrentMode = isConcurrentMode; +exports.isContextConsumer = isContextConsumer; +exports.isContextProvider = isContextProvider; +exports.isElement = isElement; +exports.isForwardRef = isForwardRef; +exports.isFragment = isFragment; +exports.isLazy = isLazy; +exports.isMemo = isMemo; +exports.isPortal = isPortal; +exports.isProfiler = isProfiler; +exports.isStrictMode = isStrictMode; +exports.isSuspense = isSuspense; +exports.isValidElementType = isValidElementType; +exports.typeOf = typeOf; + })(); +} -var handleModalClick = function handleModalClick(domCache, innerParams, dismissWith) { - domCache.container.onclick = function (e) { - if (ignoreOutsideClick) { - ignoreOutsideClick = false; - return; - } - if (e.target === domCache.container && callIfFunction(innerParams.allowOutsideClick)) { - dismissWith(DismissReason.backdrop); - } - }; -}; +/***/ }), -function _main(userParams) { - showWarningsForParams(userParams); // Check if there is another Swal closing +/***/ "./node_modules/react-is/index.js": +/*!****************************************!*\ + !*** ./node_modules/react-is/index.js ***! + \****************************************/ +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { - if (getPopup() && globalState.swalCloseEventFinishedCallback) { - globalState.swalCloseEventFinishedCallback(); - delete globalState.swalCloseEventFinishedCallback; - } // Check if there is a swal disposal defer timer +"use strict"; - if (globalState.deferDisposalTimer) { - clearTimeout(globalState.deferDisposalTimer); - delete globalState.deferDisposalTimer; - } +if (false) {} else { + module.exports = __webpack_require__(/*! ./cjs/react-is.development.js */ "./node_modules/react-is/cjs/react-is.development.js"); +} - var innerParams = _extends({}, defaultParams, userParams); - setParameters(innerParams); - Object.freeze(innerParams); // clear the previous timer +/***/ }), - if (globalState.timeout) { - globalState.timeout.stop(); - delete globalState.timeout; - } // clear the restore focus timeout +/***/ "./node_modules/react-router-dom/dist/index.js": +/*!*****************************************************!*\ + !*** ./node_modules/react-router-dom/dist/index.js ***! + \*****************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ AbortedDeferredError: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.AbortedDeferredError), +/* harmony export */ Await: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.Await), +/* harmony export */ BrowserRouter: () => (/* binding */ BrowserRouter), +/* harmony export */ Form: () => (/* binding */ Form), +/* harmony export */ HashRouter: () => (/* binding */ HashRouter), +/* harmony export */ Link: () => (/* binding */ Link), +/* harmony export */ MemoryRouter: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.MemoryRouter), +/* harmony export */ NavLink: () => (/* binding */ NavLink), +/* harmony export */ Navigate: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.Navigate), +/* harmony export */ NavigationType: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.Action), +/* harmony export */ Outlet: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.Outlet), +/* harmony export */ Route: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.Route), +/* harmony export */ Router: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.Router), +/* harmony export */ RouterProvider: () => (/* binding */ RouterProvider), +/* harmony export */ Routes: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.Routes), +/* harmony export */ ScrollRestoration: () => (/* binding */ ScrollRestoration), +/* harmony export */ UNSAFE_DataRouterContext: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.UNSAFE_DataRouterContext), +/* harmony export */ UNSAFE_DataRouterStateContext: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.UNSAFE_DataRouterStateContext), +/* harmony export */ UNSAFE_ErrorResponseImpl: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.UNSAFE_ErrorResponseImpl), +/* harmony export */ UNSAFE_FetchersContext: () => (/* binding */ FetchersContext), +/* harmony export */ UNSAFE_LocationContext: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.UNSAFE_LocationContext), +/* harmony export */ UNSAFE_NavigationContext: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.UNSAFE_NavigationContext), +/* harmony export */ UNSAFE_RouteContext: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.UNSAFE_RouteContext), +/* harmony export */ UNSAFE_ViewTransitionContext: () => (/* binding */ ViewTransitionContext), +/* harmony export */ UNSAFE_useRouteId: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.UNSAFE_useRouteId), +/* harmony export */ UNSAFE_useScrollRestoration: () => (/* binding */ useScrollRestoration), +/* harmony export */ createBrowserRouter: () => (/* binding */ createBrowserRouter), +/* harmony export */ createHashRouter: () => (/* binding */ createHashRouter), +/* harmony export */ createMemoryRouter: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.createMemoryRouter), +/* harmony export */ createPath: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.createPath), +/* harmony export */ createRoutesFromChildren: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.createRoutesFromChildren), +/* harmony export */ createRoutesFromElements: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.createRoutesFromElements), +/* harmony export */ createSearchParams: () => (/* binding */ createSearchParams), +/* harmony export */ defer: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.defer), +/* harmony export */ generatePath: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.generatePath), +/* harmony export */ isRouteErrorResponse: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.isRouteErrorResponse), +/* harmony export */ json: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.json), +/* harmony export */ matchPath: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.matchPath), +/* harmony export */ matchRoutes: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.matchRoutes), +/* harmony export */ parsePath: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.parsePath), +/* harmony export */ redirect: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.redirect), +/* harmony export */ redirectDocument: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.redirectDocument), +/* harmony export */ renderMatches: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.renderMatches), +/* harmony export */ replace: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.replace), +/* harmony export */ resolvePath: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_2__.resolvePath), +/* harmony export */ unstable_HistoryRouter: () => (/* binding */ HistoryRouter), +/* harmony export */ unstable_usePrompt: () => (/* binding */ usePrompt), +/* harmony export */ useActionData: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useActionData), +/* harmony export */ useAsyncError: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useAsyncError), +/* harmony export */ useAsyncValue: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useAsyncValue), +/* harmony export */ useBeforeUnload: () => (/* binding */ useBeforeUnload), +/* harmony export */ useBlocker: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useBlocker), +/* harmony export */ useFetcher: () => (/* binding */ useFetcher), +/* harmony export */ useFetchers: () => (/* binding */ useFetchers), +/* harmony export */ useFormAction: () => (/* binding */ useFormAction), +/* harmony export */ useHref: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useHref), +/* harmony export */ useInRouterContext: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useInRouterContext), +/* harmony export */ useLinkClickHandler: () => (/* binding */ useLinkClickHandler), +/* harmony export */ useLoaderData: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useLoaderData), +/* harmony export */ useLocation: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useLocation), +/* harmony export */ useMatch: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useMatch), +/* harmony export */ useMatches: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useMatches), +/* harmony export */ useNavigate: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useNavigate), +/* harmony export */ useNavigation: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useNavigation), +/* harmony export */ useNavigationType: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useNavigationType), +/* harmony export */ useOutlet: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useOutlet), +/* harmony export */ useOutletContext: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useOutletContext), +/* harmony export */ useParams: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useParams), +/* harmony export */ useResolvedPath: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useResolvedPath), +/* harmony export */ useRevalidator: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useRevalidator), +/* harmony export */ useRouteError: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useRouteError), +/* harmony export */ useRouteLoaderData: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useRouteLoaderData), +/* harmony export */ useRoutes: () => (/* reexport safe */ react_router__WEBPACK_IMPORTED_MODULE_3__.useRoutes), +/* harmony export */ useSearchParams: () => (/* binding */ useSearchParams), +/* harmony export */ useSubmit: () => (/* binding */ useSubmit), +/* harmony export */ useViewTransitionState: () => (/* binding */ useViewTransitionState) +/* harmony export */ }); +/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); +/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var react_dom__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react-dom */ "react-dom"); +/* harmony import */ var react_dom__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react_dom__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var react_router__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! react-router */ "./node_modules/react-router/dist/index.js"); +/* harmony import */ var react_router__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @remix-run/router */ "./node_modules/@remix-run/router/dist/router.js"); +/** + * React Router DOM v6.28.0 + * + * Copyright (c) Remix Software Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE.md file in the root directory of this source tree. + * + * @license MIT + */ - clearTimeout(globalState.restoreFocusTimeout); - var domCache = populateDomCache(this); - render(this, innerParams); - privateProps.innerParams.set(this, innerParams); - return swalPromise(this, domCache, innerParams); -} -var swalPromise = function swalPromise(instance, domCache, innerParams) { - return new Promise(function (resolve) { - // functions to handle all closings/dismissals - var dismissWith = function dismissWith(dismiss) { - instance.closePopup({ - dismiss: dismiss - }); - }; - privateMethods.swalPromiseResolve.set(instance, resolve); - setupTimer(globalState, innerParams, dismissWith); - domCache.confirmButton.onclick = function () { - return handleConfirmButtonClick(instance, innerParams); - }; - domCache.cancelButton.onclick = function () { - return handleCancelButtonClick(instance, dismissWith); - }; - domCache.closeButton.onclick = function () { - return dismissWith(DismissReason.close); - }; - handlePopupClick(domCache, innerParams, dismissWith); - addKeydownHandler(instance, globalState, innerParams, dismissWith); +function _extends() { + _extends = Object.assign ? Object.assign.bind() : function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i]; + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } + return target; + }; + return _extends.apply(this, arguments); +} +function _objectWithoutPropertiesLoose(source, excluded) { + if (source == null) return {}; + var target = {}; + var sourceKeys = Object.keys(source); + var key, i; + for (i = 0; i < sourceKeys.length; i++) { + key = sourceKeys[i]; + if (excluded.indexOf(key) >= 0) continue; + target[key] = source[key]; + } + return target; +} - if (innerParams.toast && (innerParams.input || innerParams.footer || innerParams.showCloseButton)) { - addClass(document.body, swalClasses['toast-column']); - } else { - removeClass(document.body, swalClasses['toast-column']); +const defaultMethod = "get"; +const defaultEncType = "application/x-www-form-urlencoded"; +function isHtmlElement(object) { + return object != null && typeof object.tagName === "string"; +} +function isButtonElement(object) { + return isHtmlElement(object) && object.tagName.toLowerCase() === "button"; +} +function isFormElement(object) { + return isHtmlElement(object) && object.tagName.toLowerCase() === "form"; +} +function isInputElement(object) { + return isHtmlElement(object) && object.tagName.toLowerCase() === "input"; +} +function isModifiedEvent(event) { + return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey); +} +function shouldProcessLinkClick(event, target) { + return event.button === 0 && ( + // Ignore everything but left clicks + !target || target === "_self") && + // Let browser handle "target=_blank" etc. + !isModifiedEvent(event) // Ignore clicks with modifier keys + ; +} +/** + * Creates a URLSearchParams object using the given initializer. + * + * This is identical to `new URLSearchParams(init)` except it also + * supports arrays as values in the object form of the initializer + * instead of just strings. This is convenient when you need multiple + * values for a given key, but don't want to use an array initializer. + * + * For example, instead of: + * + * let searchParams = new URLSearchParams([ + * ['sort', 'name'], + * ['sort', 'price'] + * ]); + * + * you can do: + * + * let searchParams = createSearchParams({ + * sort: ['name', 'price'] + * }); + */ +function createSearchParams(init) { + if (init === void 0) { + init = ""; + } + return new URLSearchParams(typeof init === "string" || Array.isArray(init) || init instanceof URLSearchParams ? init : Object.keys(init).reduce((memo, key) => { + let value = init[key]; + return memo.concat(Array.isArray(value) ? value.map(v => [key, v]) : [[key, value]]); + }, [])); +} +function getSearchParamsForLocation(locationSearch, defaultSearchParams) { + let searchParams = createSearchParams(locationSearch); + if (defaultSearchParams) { + // Use `defaultSearchParams.forEach(...)` here instead of iterating of + // `defaultSearchParams.keys()` to work-around a bug in Firefox related to + // web extensions. Relevant Bugzilla tickets: + // https://bugzilla.mozilla.org/show_bug.cgi?id=1414602 + // https://bugzilla.mozilla.org/show_bug.cgi?id=1023984 + defaultSearchParams.forEach((_, key) => { + if (!searchParams.has(key)) { + defaultSearchParams.getAll(key).forEach(value => { + searchParams.append(key, value); + }); + } + }); + } + return searchParams; +} +// One-time check for submitter support +let _formDataSupportsSubmitter = null; +function isFormDataSubmitterSupported() { + if (_formDataSupportsSubmitter === null) { + try { + new FormData(document.createElement("form"), + // @ts-expect-error if FormData supports the submitter parameter, this will throw + 0); + _formDataSupportsSubmitter = false; + } catch (e) { + _formDataSupportsSubmitter = true; } - - handleInputOptionsAndValue(instance, innerParams); - openPopup(innerParams); - initFocus(domCache, innerParams); // Scroll container to top on open (#1247) - - domCache.container.scrollTop = 0; - }); -}; - -var populateDomCache = function populateDomCache(instance) { - var domCache = { - popup: getPopup(), - container: getContainer(), - content: getContent(), - actions: getActions(), - confirmButton: getConfirmButton(), - cancelButton: getCancelButton(), - closeButton: getCloseButton(), - validationMessage: getValidationMessage(), - progressSteps: getProgressSteps() + } + return _formDataSupportsSubmitter; +} +const supportedFormEncTypes = new Set(["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"]); +function getFormEncType(encType) { + if (encType != null && !supportedFormEncTypes.has(encType)) { + true ? (0,react_router__WEBPACK_IMPORTED_MODULE_2__.UNSAFE_warning)(false, "\"" + encType + "\" is not a valid `encType` for ``/`` " + ("and will default to \"" + defaultEncType + "\"")) : 0; + return null; + } + return encType; +} +function getFormSubmissionInfo(target, basename) { + let method; + let action; + let encType; + let formData; + let body; + if (isFormElement(target)) { + // When grabbing the action from the element, it will have had the basename + // prefixed to ensure non-JS scenarios work, so strip it since we'll + // re-prefix in the router + let attr = target.getAttribute("action"); + action = attr ? (0,react_router__WEBPACK_IMPORTED_MODULE_2__.stripBasename)(attr, basename) : null; + method = target.getAttribute("method") || defaultMethod; + encType = getFormEncType(target.getAttribute("enctype")) || defaultEncType; + formData = new FormData(target); + } else if (isButtonElement(target) || isInputElement(target) && (target.type === "submit" || target.type === "image")) { + let form = target.form; + if (form == null) { + throw new Error("Cannot submit a