Update from Vibe Studio

This commit is contained in:
Vibe Studio
2026-01-09 14:52:46 +00:00
parent 42a0efe70b
commit 47fa6d98b2
28661 changed files with 2421771 additions and 0 deletions

21
node_modules/@umijs/use-params/License generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Rudy Huynh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

131
node_modules/@umijs/use-params/README.md generated vendored Normal file
View File

@@ -0,0 +1,131 @@
# `useUrlSearchParams()`
[![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/rudyhuynh/use-url-search-params/blob/master/License)
A React Hook to use [URL query string](https://en.wikipedia.org/wiki/Query_string) as a state management
[Demo](https://rudyhuynh.github.io/use-url-search-params)
## Why you need this
- Your app need to persist its state after user refresh the page (used for simple, non-sensitive data).
- Some page settings (ex: table filter, sorting, paging, etc.) should be saved in the URL so that user can easily pass to others. e.g. Tester can easily send a URL of a page to developer with very least reproduce steps.
- You want to do something (request new data, etc.) every time some URL query value changes.
- Combine all of the above with a URL query as a single source of truth.
## Installation
```
npm install use-url-search-params
```
or
```
yarn add use-url-search-params
```
## How to use
For most of the time you will do something like this:
```js
import React from "react";
import { useUrlSearchParams } from "use-url-search-params";
function App() {
// Your page URL will be like this by default: http://my.page?checked=true
const [params, setParams] = useUrlSearchParams({ checked: true });
React.useEffect(() => {
// do something when `params.checked` is updated.
}, [params.checked]);
return (
<div>
<input
type="checkbox"
checked={params.checked}
onChange={e => setParams({ checked: e.target.checked })}
/>
</div>
);
}
```
## How to control the value parsed from URL query
By default, all values parsed from URL query are string. In case you want to get boolean or number value, pass a second argument to `useUrlSearchParams()` to specify data type you want to get from `params` object. Here is an example:
```js
const initial = {
y: "option1"
};
const types = {
x: Number,
y: Boolean,
z: Date,
t: ["option1", "option2", "option3"]
};
const [params, setParams] = useUrlSearchParams(initial, types);
// `params.x` will be number (or NaN)
// `params.y` will be one of [undefined, true, false]
// `params.z` will be instance of Date (can be Invalid Date)
// `params.t` will be one of ["option1", "option2", "option3"] (can be `undefined` if not specified in `initial`)
```
## Complex data structure
Although you can use `JSON.parse()` and `JSON.stringify()` to get/set arbitrary serializable data to URL query, it is not recommended. URL query is a good place to store and persist page settings as key/value pairs such as table filter, sorting, paging, etc. We should keep it that way for simplicity. **For complex data structure, you should consider using other state management for better performance, security and flexibility.**
> **WARNING**: Be aware of XSS attack. Be careful to validate values from URL query before using it by either using `types` - the second parameter passed to `useUrlSearchParams()` or validate them yourself if neccessary.
But if you still insist, here is an example:
```js
function App() {
const [params, setParams] = useUrlSearchParams(
{},
{
complexData: dataString => {
try {
return JSON.parse(dataString);
} catch (e) {
return {};
}
}
}
);
const onSetParams = data => {
setParams({ complexData: JSON.stringify(data) });
};
return <div>{/*...*/}</div>;
}
```
## React Router
Should just work with React Router or any routing system. Just make sure that your component re-render whenever route changes.
## API
- **useUrlSearchParams([initial, types])**
- `initial` (optional | Object): To set default values for URL query string.
- `types` (optional | Object): Has similar shape with `initial`, help to resolve values from URL query string. Supported types:
- `String` (default)
- `Number`
- `Bool`
- `Date` - [`Date.prototype.toISOString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) is used to parse date to string, e.g date string in your URL query is zero UTC offset
- Array of available string values (like enum)
- A custom resolver function
## Read more (for maintainers)
This library is built base on [URLSearchParams interface](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
## License
MIT

3
node_modules/@umijs/use-params/es/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
export declare function useUrlSearchParams(initial?: Record<string, string | number>, config?: {
disabled?: boolean;
}): [Record<string, string | number>, (value: Record<string, string | number>) => void];

162
node_modules/@umijs/use-params/es/index.js generated vendored Normal file
View File

@@ -0,0 +1,162 @@
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
/* eslint-disable no-restricted-syntax */
import { useEffect, useMemo, useState } from 'react';
/**
*
* @param {object} params
* @returns {URL}
*/
function setQueryToCurrentUrl(params) {
var _a;
var URL = (typeof window !== 'undefined' ? window : {}).URL;
var url = new URL((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.href);
Object.keys(params).forEach(function (key) {
var value = params[key];
if (value !== null && value !== undefined) {
if (Array.isArray(value)) {
url.searchParams.delete(key);
value.forEach(function (valueItem) {
url.searchParams.append(key, valueItem);
});
}
else if (value instanceof Date) {
if (!Number.isNaN(value.getTime())) {
url.searchParams.set(key, value.toISOString());
}
}
else if (typeof value === 'object') {
url.searchParams.set(key, JSON.stringify(value));
}
else {
url.searchParams.set(key, value);
}
}
else {
url.searchParams.delete(key);
}
});
return url;
}
export function useUrlSearchParams(initial, config) {
var _a;
if (initial === void 0) { initial = {}; }
if (config === void 0) { config = { disabled: false }; }
/**
* The main idea of this hook is to make things response to change of `window.location.search`,
* so no need for introducing new state (in the mean time).
* Whenever `window.location.search` is changed but not cause re-render, call `forceUpdate()`.
* Whenever the component - user of this hook - re-render, this hook should return
* the query object that corresponse to the current `window.location.search`
*/
var _b = useState(), forceUpdate = _b[1];
var locationSearch = typeof window !== 'undefined' && ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.search);
/**
* @type {URLSearchParams}
*/
var urlSearchParams = useMemo(function () {
if (config.disabled)
return {};
return new URLSearchParams(locationSearch || {});
}, [config.disabled, locationSearch]);
var params = useMemo(function () {
if (config.disabled)
return {};
if (typeof window === 'undefined' || !window.URL)
return {};
var result = [];
// @ts-ignore
urlSearchParams.forEach(function (value, key) {
result.push({
key: key,
value: value,
});
});
// group by key
result = result.reduce(function (acc, val) {
(acc[val.key] = acc[val.key] || []).push(val);
return acc;
}, {});
result = Object.keys(result).map(function (key) {
var valueGroup = result[key];
if (valueGroup.length === 1) {
return [key, valueGroup[0].value];
}
return [key, valueGroup.map(function (_a) {
var value = _a.value;
return value;
})];
});
var newParams = __assign({}, initial);
result.forEach(function (_a) {
var key = _a[0], value = _a[1];
newParams[key] = parseValue(key, value, {}, initial);
});
return newParams;
}, [config.disabled, initial, urlSearchParams]);
function redirectToNewSearchParams(newParams) {
if (typeof window === 'undefined' || !window.URL)
return;
var url = setQueryToCurrentUrl(newParams);
if (window.location.search !== url.search) {
window.history.replaceState({}, '', url.toString());
}
if (urlSearchParams.toString() !== url.searchParams.toString()) {
forceUpdate({});
}
}
useEffect(function () {
if (config.disabled)
return;
if (typeof window === 'undefined' || !window.URL)
return;
redirectToNewSearchParams(__assign(__assign({}, initial), params));
}, [config.disabled, params]);
var setParams = function (newParams) {
redirectToNewSearchParams(newParams);
};
useEffect(function () {
if (config.disabled)
return function () { };
if (typeof window === 'undefined' || !window.URL)
return function () { };
var onPopState = function () {
forceUpdate({});
};
window.addEventListener('popstate', onPopState);
return function () {
window.removeEventListener('popstate', onPopState);
};
}, [config.disabled]);
return [params, setParams];
}
var booleanValues = {
true: true,
false: false,
};
function parseValue(key, _value, types, defaultParams) {
if (!types)
return _value;
var type = types[key];
var value = _value === undefined ? defaultParams[key] : _value;
if (type === Number) {
return Number(value);
}
if (type === Boolean || _value === 'true' || _value === 'false') {
return booleanValues[value];
}
if (Array.isArray(type)) {
// eslint-disable-next-line eqeqeq
return type.find(function (item) { return item == value; }) || defaultParams[key];
}
return value;
}

3
node_modules/@umijs/use-params/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
export declare function useUrlSearchParams(initial?: Record<string, string | number>, config?: {
disabled?: boolean;
}): [Record<string, string | number>, (value: Record<string, string | number>) => void];

202
node_modules/@umijs/use-params/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,202 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useUrlSearchParams = useUrlSearchParams;
var _react = require("react");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var __assign = void 0 && (void 0).__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
}
return t;
};
return __assign.apply(this, arguments);
};
/* eslint-disable no-restricted-syntax */
/**
*
* @param {object} params
* @returns {URL}
*/
function setQueryToCurrentUrl(params) {
var _a;
var URL = (typeof window !== 'undefined' ? window : {}).URL;
var url = new URL((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.href);
Object.keys(params).forEach(function (key) {
var value = params[key];
if (value !== null && value !== undefined) {
if (Array.isArray(value)) {
url.searchParams.delete(key);
value.forEach(function (valueItem) {
url.searchParams.append(key, valueItem);
});
} else if (value instanceof Date) {
if (!Number.isNaN(value.getTime())) {
url.searchParams.set(key, value.toISOString());
}
} else if (_typeof(value) === 'object') {
url.searchParams.set(key, JSON.stringify(value));
} else {
url.searchParams.set(key, value);
}
} else {
url.searchParams.delete(key);
}
});
return url;
}
function useUrlSearchParams(initial, config) {
var _a;
if (initial === void 0) {
initial = {};
}
if (config === void 0) {
config = {
disabled: false
};
}
/**
* The main idea of this hook is to make things response to change of `window.location.search`,
* so no need for introducing new state (in the mean time).
* Whenever `window.location.search` is changed but not cause re-render, call `forceUpdate()`.
* Whenever the component - user of this hook - re-render, this hook should return
* the query object that corresponse to the current `window.location.search`
*/
var _b = (0, _react.useState)(),
forceUpdate = _b[1];
var locationSearch = typeof window !== 'undefined' && ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.search);
/**
* @type {URLSearchParams}
*/
var urlSearchParams = (0, _react.useMemo)(function () {
if (config.disabled) return {};
return new URLSearchParams(locationSearch || {});
}, [config.disabled, locationSearch]);
var params = (0, _react.useMemo)(function () {
if (config.disabled) return {};
if (typeof window === 'undefined' || !window.URL) return {};
var result = []; // @ts-ignore
urlSearchParams.forEach(function (value, key) {
result.push({
key: key,
value: value
});
}); // group by key
result = result.reduce(function (acc, val) {
(acc[val.key] = acc[val.key] || []).push(val);
return acc;
}, {});
result = Object.keys(result).map(function (key) {
var valueGroup = result[key];
if (valueGroup.length === 1) {
return [key, valueGroup[0].value];
}
return [key, valueGroup.map(function (_a) {
var value = _a.value;
return value;
})];
});
var newParams = __assign({}, initial);
result.forEach(function (_a) {
var key = _a[0],
value = _a[1];
newParams[key] = parseValue(key, value, {}, initial);
});
return newParams;
}, [config.disabled, initial, urlSearchParams]);
function redirectToNewSearchParams(newParams) {
if (typeof window === 'undefined' || !window.URL) return;
var url = setQueryToCurrentUrl(newParams);
if (window.location.search !== url.search) {
window.history.replaceState({}, '', url.toString());
}
if (urlSearchParams.toString() !== url.searchParams.toString()) {
forceUpdate({});
}
}
(0, _react.useEffect)(function () {
if (config.disabled) return;
if (typeof window === 'undefined' || !window.URL) return;
redirectToNewSearchParams(__assign(__assign({}, initial), params));
}, [config.disabled, params]);
var setParams = function setParams(newParams) {
redirectToNewSearchParams(newParams);
};
(0, _react.useEffect)(function () {
if (config.disabled) return function () {};
if (typeof window === 'undefined' || !window.URL) return function () {};
var onPopState = function onPopState() {
forceUpdate({});
};
window.addEventListener('popstate', onPopState);
return function () {
window.removeEventListener('popstate', onPopState);
};
}, [config.disabled]);
return [params, setParams];
}
var booleanValues = {
true: true,
false: false
};
function parseValue(key, _value, types, defaultParams) {
if (!types) return _value;
var type = types[key];
var value = _value === undefined ? defaultParams[key] : _value;
if (type === Number) {
return Number(value);
}
if (type === Boolean || _value === 'true' || _value === 'false') {
return booleanValues[value];
}
if (Array.isArray(type)) {
// eslint-disable-next-line eqeqeq
return type.find(function (item) {
return item == value;
}) || defaultParams[key];
}
return value;
}

37
node_modules/@umijs/use-params/package.json generated vendored Normal file
View File

@@ -0,0 +1,37 @@
{
"name": "@umijs/use-params",
"version": "1.0.9",
"keywords": [
"react",
"react-hooks",
"urlsearchparams",
"url-query",
"url",
"state"
],
"bugs": "https://github.com/chenshuai2144/use-params/issues",
"repository": "https://github.com/chenshuai2144/use-params",
"license": "MIT",
"author": "rudyhuynh <rudyhuynh@>",
"main": "lib/index.js",
"module": "es/index.js",
"types": "es/index.d.ts",
"files": [
"es",
"lib"
],
"scripts": {
"prepublish": "npm run build",
"build": "tsc && father-build"
},
"devDependencies": {
"@types/react": "^17.0.1",
"@umijs/fabric": "^2.5.6",
"father-build": "^1.19.1",
"np": "^5.2.1",
"typescript": "^4.0.0"
},
"peerDependencies": {
"react": "*"
}
}