adou-ui
Version:
feat:修复了TagInput无法清空的问题
1,325 lines (1,273 loc) • 265 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"));
else if(typeof define === 'function' && define.amd)
define(["react"], factory);
else if(typeof exports === 'object')
exports["RPB"] = factory(require("react"));
else
root["RPB"] = factory(root["React"]);
})(this, (__WEBPACK_EXTERNAL_MODULE__442__) => {
return /******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ 191:
/***/ ((module) => {
"use strict";
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
module.exports = function (cssWithMappingToString) {
var list = [];
// return the list of modules as css string
list.toString = function toString() {
return this.map(function (item) {
var content = "";
var needLayer = typeof item[5] !== "undefined";
if (item[4]) {
content += "@supports (".concat(item[4], ") {");
}
if (item[2]) {
content += "@media ".concat(item[2], " {");
}
if (needLayer) {
content += "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {");
}
content += cssWithMappingToString(item);
if (needLayer) {
content += "}";
}
if (item[2]) {
content += "}";
}
if (item[4]) {
content += "}";
}
return content;
}).join("");
};
// import a list of modules into the list
list.i = function i(modules, media, dedupe, supports, layer) {
if (typeof modules === "string") {
modules = [[null, modules, undefined]];
}
var alreadyImportedModules = {};
if (dedupe) {
for (var k = 0; k < this.length; k++) {
var id = this[k][0];
if (id != null) {
alreadyImportedModules[id] = true;
}
}
}
for (var _k = 0; _k < modules.length; _k++) {
var item = [].concat(modules[_k]);
if (dedupe && alreadyImportedModules[item[0]]) {
continue;
}
if (typeof layer !== "undefined") {
if (typeof item[5] === "undefined") {
item[5] = layer;
} else {
item[1] = "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {").concat(item[1], "}");
item[5] = layer;
}
}
if (media) {
if (!item[2]) {
item[2] = media;
} else {
item[1] = "@media ".concat(item[2], " {").concat(item[1], "}");
item[2] = media;
}
}
if (supports) {
if (!item[4]) {
item[4] = "".concat(supports);
} else {
item[1] = "@supports (".concat(item[4], ") {").concat(item[1], "}");
item[4] = supports;
}
}
list.push(item);
}
};
return list;
};
/***/ }),
/***/ 73:
/***/ ((module) => {
"use strict";
module.exports = function (item) {
var content = item[1];
var cssMapping = item[3];
if (!cssMapping) {
return content;
}
if (typeof btoa === "function") {
var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(cssMapping))));
var data = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(base64);
var sourceMapping = "/*# ".concat(data, " */");
return [content].concat([sourceMapping]).join("\n");
}
return [content].join("\n");
};
/***/ }),
/***/ 511:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
(function webpackUniversalModuleDefinition(root, factory) {
if (true) module.exports = factory(__webpack_require__(442));else {}
})(this, __WEBPACK_EXTERNAL_MODULE__442__ => {
return /******/(() => {
// webpackBootstrap
/******/
"use strict";
/******/
var __webpack_modules__ = {
/***/442: ( /***/module => {
module.exports = __WEBPACK_EXTERNAL_MODULE__442__;
/***/
})
/******/
};
/************************************************************************/
/******/ // The module cache
/******/
var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/
function __nested_webpack_require_918__(moduleId) {
/******/ // Check if module is in cache
/******/var cachedModule = __webpack_module_cache__[moduleId];
/******/
if (cachedModule !== undefined) {
/******/return cachedModule.exports;
/******/
}
/******/ // Create a new module (and put it into the cache)
/******/
var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/exports: {}
/******/
};
/******/
/******/ // Execute the module function
/******/
__webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_918__);
/******/
/******/ // Return the exports of the module
/******/
return module.exports;
/******/
}
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/
(() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/__nested_webpack_require_918__.n = module => {
/******/var getter = module && module.__esModule ? /******/() => module['default'] : /******/() => module;
/******/
__nested_webpack_require_918__.d(getter, {
a: getter
});
/******/
return getter;
/******/
};
/******/
})();
/******/
/******/ /* webpack/runtime/define property getters */
/******/
(() => {
/******/ // define getter functions for harmony exports
/******/__nested_webpack_require_918__.d = (exports, definition) => {
/******/for (var key in definition) {
/******/if (__nested_webpack_require_918__.o(definition, key) && !__nested_webpack_require_918__.o(exports, key)) {
/******/Object.defineProperty(exports, key, {
enumerable: true,
get: definition[key]
});
/******/
}
/******/
}
/******/
};
/******/
})();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/
(() => {
/******/__nested_webpack_require_918__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
/******/
})();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/
(() => {
/******/ // define __esModule on exports
/******/__nested_webpack_require_918__.r = exports => {
/******/if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/Object.defineProperty(exports, Symbol.toStringTag, {
value: 'Module'
});
/******/
}
/******/
Object.defineProperty(exports, '__esModule', {
value: true
});
/******/
};
/******/
})();
/******/
/************************************************************************/
var __nested_webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
__nested_webpack_require_918__.r(__nested_webpack_exports__);
/* harmony export */
__nested_webpack_require_918__.d(__nested_webpack_exports__, {
/* harmony export */"default": () => __WEBPACK_DEFAULT_EXPORT__
/* harmony export */
});
/* harmony import */
var react__WEBPACK_IMPORTED_MODULE_0__ = __nested_webpack_require_918__(442);
/* harmony import */
var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nested_webpack_require_918__.n(react__WEBPACK_IMPORTED_MODULE_0__);
const Button = props => {
const {
fontSize,
spinerType = "border",
spinerColor,
loading,
suffixIcon,
prefixIcon,
children,
type,
size = "md",
externalClassName,
round,
textColor,
disabled,
outlineColor,
onClickOK
} = props;
const handleOnClick = () => {
onClickOK && onClickOK();
};
const renderPrefixIcon = () => {
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("i", {
className: "".concat(prefixIcon)
});
};
const rendersuffixIcon = () => {
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("i", {
className: "".concat(suffixIcon)
});
};
/* const renderLoading = () => {
return React.Children.map(children, (child: any) => {
if (!React.isValidElement(child)) {
child = <span className="m-1">{child}</span>
const enhancedChild = React.cloneElement(child!, {
style: {
}
} as React.Attributes);
return enhancedChild;
}
});
}; */
const renderLabel = () => {
return react__WEBPACK_IMPORTED_MODULE_0___default().Children.map(children, child => {
if (! /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().isValidElement(child)) {
child = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("span", null, child);
const enhancedChild = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().cloneElement(child, {
style: {
fontSize
}
});
return enhancedChild;
}
});
};
const renderLoadingIcon = () => {
let hasLoader = false;
react__WEBPACK_IMPORTED_MODULE_0___default().Children.map(children, child => {
var _child$props;
if ((_child$props = child.props) !== null && _child$props !== void 0 && (_child$props = _child$props.className) !== null && _child$props !== void 0 && _child$props.includes("loader")) {
hasLoader = true;
}
});
if (hasLoader) {
return react__WEBPACK_IMPORTED_MODULE_0___default().Children.map(children, child => {
var _child$props2;
if ((_child$props2 = child.props) !== null && _child$props2 !== void 0 && _child$props2.className.includes("loader")) {
return child;
}
});
} else {
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(react__WEBPACK_IMPORTED_MODULE_0___default().Fragment, null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
className: "me-2 spinner-".concat(spinerType, " spinner-").concat(spinerType, "-sm text-").concat(spinerColor),
role: "status"
}));
}
};
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("span", {
className: "button-wrapper"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("button", {
style: {
cursor: "pointer",
height: "100%"
},
onClick: handleOnClick,
className: "btn btn-".concat(type, " btn-").concat(size, " ").concat(round ? "rounded-pill" : "", " ").concat(textColor ? "text-".concat(textColor) : "", " ").concat(outlineColor ? "btn-outline-".concat(outlineColor) : "", " ").concat(disabled ? "disabled" : "", " ").concat(externalClassName),
disabled: loading
}, loading ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
className: "loading-btn"
}, renderLoadingIcon(), renderLabel()) : /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(react__WEBPACK_IMPORTED_MODULE_0___default().Fragment, null, prefixIcon && renderPrefixIcon(), renderLabel(), suffixIcon && rendersuffixIcon())));
};
/* harmony default export */
const __WEBPACK_DEFAULT_EXPORT__ = Button;
})();
/******/
return __nested_webpack_exports__;
/******/
})();
});
/***/ }),
/***/ 36:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
(function webpackUniversalModuleDefinition(root, factory) {
if (true) module.exports = factory(__webpack_require__(442));else {}
})(this, __WEBPACK_EXTERNAL_MODULE__442__ => {
return /******/(() => {
// webpackBootstrap
/******/
"use strict";
/******/
var __webpack_modules__ = {
/***/442: ( /***/module => {
module.exports = __WEBPACK_EXTERNAL_MODULE__442__;
/***/
})
/******/
};
/************************************************************************/
/******/ // The module cache
/******/
var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/
function __nested_webpack_require_918__(moduleId) {
/******/ // Check if module is in cache
/******/var cachedModule = __webpack_module_cache__[moduleId];
/******/
if (cachedModule !== undefined) {
/******/return cachedModule.exports;
/******/
}
/******/ // Create a new module (and put it into the cache)
/******/
var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/exports: {}
/******/
};
/******/
/******/ // Execute the module function
/******/
__webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_918__);
/******/
/******/ // Return the exports of the module
/******/
return module.exports;
/******/
}
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/
(() => {
/******/ // define getter functions for harmony exports
/******/__nested_webpack_require_918__.d = (exports, definition) => {
/******/for (var key in definition) {
/******/if (__nested_webpack_require_918__.o(definition, key) && !__nested_webpack_require_918__.o(exports, key)) {
/******/Object.defineProperty(exports, key, {
enumerable: true,
get: definition[key]
});
/******/
}
/******/
}
/******/
};
/******/
})();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/
(() => {
/******/__nested_webpack_require_918__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
/******/
})();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/
(() => {
/******/ // define __esModule on exports
/******/__nested_webpack_require_918__.r = exports => {
/******/if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/Object.defineProperty(exports, Symbol.toStringTag, {
value: 'Module'
});
/******/
}
/******/
Object.defineProperty(exports, '__esModule', {
value: true
});
/******/
};
/******/
})();
/******/
/************************************************************************/
var __nested_webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
// ESM COMPAT FLAG
__nested_webpack_require_918__.r(__nested_webpack_exports__);
// EXPORTS
__nested_webpack_require_918__.d(__nested_webpack_exports__, {
convertArrayKeysToCamelCase: () => ( /* reexport */libs_convertArrayKeysToCamelCase),
convertArrayKeysToSnakeCase: () => ( /* reexport */libs_convertArrayKeysToSnakeCase),
convertListToTree: () => ( /* reexport */libs_convertListToTree),
convertToTag: () => ( /* reexport */libs_convertToTag),
flattenDataWithoutNesting: () => ( /* reexport */libs_flattenDataWithoutNesting),
getAbsolutePosition: () => ( /* reexport */libs_getAbsolutePositionOfStage),
getContentWidth: () => ( /* reexport */libs_getContentWidth),
isEmptyO: () => ( /* reexport */libs_isEmptyO),
splitFilesIntoColumns: () => ( /* reexport */libs_splitFilesIntoColumns),
timeFormatter: () => ( /* reexport */time_formatter_namespaceObject),
useClickOutside: () => ( /* reexport */hooks_useClickOutside),
useDrag: () => ( /* reexport */hooks_useDrag),
useNavigateTo: () => ( /* reexport */hooks_useNavigateTo),
useThrottle: () => ( /* reexport */hooks_useThrottle)
});
// NAMESPACE OBJECT: ./src/libs/time-formatter.js
var time_formatter_namespaceObject = {};
__nested_webpack_require_918__.r(time_formatter_namespaceObject);
__nested_webpack_require_918__.d(time_formatter_namespaceObject, {
"default": () => time_formatter
});
; // CONCATENATED MODULE: ./src/libs/getAbsolutePositionOfStage.js
function getAbsolutePositionOfStage(domElement) {
let left = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
let top = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
if (!parseInt(left)) {
left = 0;
} else {
left = parseInt(left);
}
if (!parseInt(top)) {
top = 0;
} else {
top = parseInt(top);
}
if (!domElement) {
return {
x: 0,
y: 0,
width: 0,
height: 0
};
}
const box = domElement === null || domElement === void 0 ? void 0 : domElement.getBoundingClientRect();
const body = document.body;
const docElem = document.documentElement;
const scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop;
const scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft;
const clientTop = docElem.clientTop || body.clientTop || 0;
const clientLeft = docElem.clientLeft || body.clientLeft || 0;
const attr = {};
attr.y = box.top + scrollTop - clientTop + top;
attr.x = box.left + scrollLeft - clientLeft + left;
attr.width = box.width;
attr.height = box.height;
return attr;
}
/* harmony default export */
const libs_getAbsolutePositionOfStage = getAbsolutePositionOfStage;
; // CONCATENATED MODULE: ./src/libs/convertToTag.js
const convertToTag = str => {
let tags = [];
const regex = /\[(.*?)\]/g;
const temp = str === null || str === void 0 ? void 0 : str.match(regex);
temp && (tags = temp.map(match => match === null || match === void 0 ? void 0 : match.slice(1, -1)));
return tags;
};
/* harmony default export */
const libs_convertToTag = convertToTag;
; // CONCATENATED MODULE: ./src/libs/time-formatter.js
function formatDateTime(dateString, format) {
const date = new Date(dateString);
switch (format) {
case "MM-DD HH:mm":
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
const hours = String(date.getHours()).padStart(2, "0");
const minutes = String(date.getMinutes()).padStart(2, "0");
return "".concat(month, "-").concat(day, " ").concat(hours, ":").concat(minutes);
case "YYYY-MM-DD HH:mm:ss":
const year = date.getFullYear();
const month2 = String(date.getMonth() + 1).padStart(2, "0");
const day2 = String(date.getDate()).padStart(2, "0");
const hours2 = String(date.getHours()).padStart(2, "0");
const minutes2 = String(date.getMinutes()).padStart(2, "0");
const seconds2 = String(date.getSeconds()).padStart(2, "0");
return "".concat(year, "-").concat(month2, "-").concat(day2, " ").concat(hours2, ":").concat(minutes2, ":").concat(seconds2);
case "YYYY-MM-DD":
const year2 = date.getFullYear();
const month3 = String(date.getMonth() + 1).padStart(2, "0");
const day3 = String(date.getDate()).padStart(2, "0");
return "".concat(year2, "-").concat(month3, "-").concat(day3);
case "HH:mm:ss":
const hours3 = String(date.getHours()).padStart(2, "0");
const minutes3 = String(date.getMinutes()).padStart(2, "0");
const seconds3 = String(date.getSeconds()).padStart(2, "0");
return "".concat(hours3, ":").concat(minutes3, ":").concat(seconds3);
default:
break;
}
}
/* harmony default export */
const time_formatter = formatDateTime;
; // CONCATENATED MODULE: ./src/libs/isEmptyO.js
function isEmptyO(obj) {
return Object.keys(obj !== null && obj !== void 0 ? obj : {}).length === 0;
}
/* harmony default export */
const libs_isEmptyO = isEmptyO;
; // CONCATENATED MODULE: ./src/libs/convertArrayKeysToCamelCase.js
function snakeToCamel(name) {
return name.replace(/_([a-z])/g, (match, letter) => letter.toUpperCase());
}
function convertKeysToCamelCase(obj) {
return Object.fromEntries(Object.entries(obj).map(_ref => {
let [key, value] = _ref;
return [snakeToCamel(key), value || ""];
}));
}
function convertArrayKeysToCamelCase(arr) {
return arr.map(item => convertKeysToCamelCase(item));
}
/* harmony default export */
const libs_convertArrayKeysToCamelCase = convertArrayKeysToCamelCase;
; // CONCATENATED MODULE: ./src/libs/convertArrayKeysToSnakeCase.js
function camelToSnake(name) {
return name.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
}
function convertKeysToSnakeCase(obj) {
return Object.fromEntries(Object.entries(obj).map(_ref => {
let [key, value] = _ref;
return [camelToSnake(key), value];
}));
}
function convertArrayKeysToSnakeCase(arr) {
return arr.map(item => convertKeysToSnakeCase(item));
}
/* harmony default export */
const libs_convertArrayKeysToSnakeCase = convertArrayKeysToSnakeCase;
; // CONCATENATED MODULE: ./src/libs/convertListToTree.ts
const convertListToTree = (list, pid) => {
let level = 0;
// 递归辅助函数,用于处理每个节点及其子节点
const buildTree = (items, parentId, currentLevel) => {
const children = [];
items.forEach(item => {
if (item.pid === parentId) {
item.level = currentLevel;
children.push(item);
// 递归调用自身处理子节点,层级加1
item.children = buildTree(list, item.id, currentLevel + 1);
}
});
return children;
};
const data = buildTree(list, pid, level);
return data;
};
/* harmony default export */
const libs_convertListToTree = convertListToTree;
; // CONCATENATED MODULE: ./src/libs/flattenDataWithoutNesting.ts
function flattenDataWithoutNesting(data) {
let flattened = [];
function flattenRecursive(node, parentId) {
const {
id,
name,
isExpanded
} = node;
flattened.push({
...node,
id,
name,
isExpanded,
pid: parentId
});
if (node.children && node.children.length > 0) {
node.children.forEach(child => {
flattenRecursive(child, id);
});
}
}
data.forEach(rootNode => {
flattenRecursive(rootNode, null);
});
return flattened;
}
/* harmony default export */
const libs_flattenDataWithoutNesting = flattenDataWithoutNesting;
; // CONCATENATED MODULE: ./src/libs/splitFilesIntoColumns.ts
// 根据列数和每列展示的文件数量来分割文件
const splitFilesIntoColumns = (files, filesPerColumn) => {
const result = [];
let currentColumn = [];
files.forEach((file, index) => {
currentColumn.push(file);
if ((index + 1) % filesPerColumn === 0 || index === files.length - 1) {
result.push(currentColumn);
currentColumn = [];
}
});
return result;
};
/* harmony default export */
const libs_splitFilesIntoColumns = splitFilesIntoColumns;
; // CONCATENATED MODULE: ./src/libs/getContentWidth.ts
function getContentWidth(element) {
const computedStyle = window.getComputedStyle(element);
const offsetWidth = element.offsetWidth;
const borderWidthLeftRight = parseInt(computedStyle.borderLeftWidth) + parseInt(computedStyle.borderRightWidth);
const paddingWidthLeftRight = parseInt(computedStyle.paddingLeft) + parseInt(computedStyle.paddingRight);
return offsetWidth - borderWidthLeftRight - paddingWidthLeftRight;
}
/* harmony default export */
const libs_getContentWidth = getContentWidth;
; // CONCATENATED MODULE: ../../node_modules/@remix-run/router/dist/router.js
/**
* @remix-run/router v1.5.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
*/
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);
}
////////////////////////////////////////////////////////////////////////////////
//#region Types and Constants
////////////////////////////////////////////////////////////////////////////////
/**
* Actions represent the type of change to a location value.
*/
var router_Action;
(function (Action) {
/**
* 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.
*
* Note: This is the default action for newly created history objects.
*/
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";
})(router_Action || (router_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 router_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 = router_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" ? router_parsePath(to) : to;
return {
pathname: path.pathname || "",
search: path.search || "",
hash: path.hash || ""
};
},
push(to, state) {
action = router_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 = router_Action.Replace;
let nextLocation = createMemoryLocation(to, state);
entries[index] = nextLocation;
if (v5Compat && listener) {
listener({
action,
location: nextLocation,
delta: 0
});
}
},
go(delta) {
action = router_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;
};
}
};
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 = ""
} = router_parsePath(window.location.hash.substr(1));
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);
}
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" ? router_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 router_parsePath(path) {
let parsedPath = {};
if (path) {
let hashIndex = path.indexOf("#");
if (hashIndex >= 0) {
parsedPath.hash = path.substr(hashIndex);
path = path.substr(0, hashIndex);
}
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 = router_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 = router_Action.Pop;
let nextIndex = getIndex();
let delta = nextIndex == null ? null : nextIndex - index;
index = nextIndex;
if (listener) {
listener({
action,
location: history.location,
delta
});
}
}
function push(to, state) {
action = router_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) {
// 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
});
}
}
function replace(to, state) {
action = router_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
});
}
}
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);
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, detectErrorBoundary, parentPath, manifest) {
if (parentPath === void 0) {
parentPath = [];
}
if (manifest === void 0) {
manifest = {};
}
return routes.map((route, index) => {
let treePath = [...parentPath, 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, {
hasErrorBoundary: detectErrorBoundary(route),
id
});
manifest[id] = indexRoute;
return indexRoute;
} else {
let pathOrLayoutRoute = _extends({}, route, {
id,
hasErrorBoundary: detectErrorBoundary(route),
children: undefined
});
manifest[id] = pathOrLayoutRoute;
if (route.children) {
pathOrLayoutRoute.children = convertRoutesToDataRoutes(route.children, detectErrorBoundary, treePath, manifest);
}
return pathOrLayoutRoute;
}
});
}
/**
* Matches the given routes to a location and returns the match data.
*
* @see https://reactrouter.com/utils/match-routes
*/
function router_matchRoutes(routes, locationArg, basename) {
if (basename === void 0) {
basename = "/";
}
let location = typeof locationArg === "string" ? router_parsePath(locationArg) : locationArg;
let pathname = router_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) {
matches = matchRouteBranch(branches[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.
safelyDecodeURI(pathname));
}
return matches;
}
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 = router_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 explodes _earlier_
// then /:one. By always including the parent as required _for all children_
// first, we avoid this issue
result.push(...restExpl