Initial commit with Advoware proxy

This commit is contained in:
root
2025-10-19 14:57:07 +00:00
commit 273aa8b549
45771 changed files with 5534555 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
# React Resizable Hook
A lightweight (1.3kB gzipped!), hooks-based, easy-to-use alternative to [react-resizable](https://www.npmjs.com/package/react-resizable).
Check out the **[demo](https://mikkelwestermann.github.io/react-use-resizable/)**
## Installation
```
npm i react-use-resizable
```
## How to use
The hook returns an object with the following properties:
- `rootRef`: A ref to the root element of the resizable component
- `getRootProps`: A function that returns the props to be spread on the root element
- `getHandleProps`: A function that returns the props to be spread on the handle element
The hooks behavior can be customized by passing an options object to the hook. The options object can have the following properties:
| Property | Type | Description | Optional | Default |
| --- | --- | --- | --- | --- |
| `maxHeight` | `number` | The maximum height of the component | Yes | `Infinity` |
| `maxWidth` | `number` | The maximum width of the component | Yes | `Infinity` |
| `minHeight` | `number` | The minimum height of the component | Yes | `0` |
| `minWidth` | `number` | The minimum width of the component | Yes | `0` |
| `lockHorizontal` | `boolean` | Whether the component should be horizontally resizable | Yes | `false` |
| `lockVertical` | `boolean` | Whether the component should be vertically resizable | Yes | `false` |
| `onResize` | `function` | A callback function that is called when the component is resized | Yes | `() => {}` |
| `onDragEnd` | `function` | A callback function that is called when the component is done resizing | Yes | `() => {}` |
| `onDragStart` | `function` | A callback function that is called when the component starts resizing | Yes | `() => {}` |
| `disabled` | `boolean` | Whether the component should be resizable | Yes | `false` |
| `interval` | `number` | The interval at which the resize will occur (i.e. which sizes the component will snap to) | Yes | `1` |
| `initialHeight` | `number` | The initial height of the component | Yes | `100` |
| `initialWidth` | `number` | The initial width of the component | Yes | `100` |
| `maintainAspectRatio` | `boolean` | Whether the component should maintain its aspect ratio (ratio between `initialHeight` and `initialWidth`) when resizing | Yes | `false` |
Most of these properties can be overridden for each handle by passing passing an options object to the `getHandleProps` function. The options object can have the following properties:
| Property | Type | Description | Optional | Default |
| --- | --- | --- | --- | --- |
| `maxHeight` | `number` | The maximum height of the component | Yes | `Infinity` |
| `maxWidth` | `number` | The maximum width of the component | Yes | `Infinity` |
| `minHeight` | `number` | The minimum height of the component | Yes | `0` |
| `minWidth` | `number` | The minimum width of the component | Yes | `0` |
| `lockHorizontal` | `boolean` | Whether the component should be horizontally resizable | Yes | `false` |
| `lockVertical` | `boolean` | Whether the component should be vertically resizable | Yes | `false` |
| `onResize` | `function` | A callback function that is called when the component is resized | Yes | `() => {}` |
| `onDragEnd` | `function` | A callback function that is called when the component is done resizing | Yes | `() => {}` |
| `onDragStart` | `function` | A callback function that is called when the component starts resizing | Yes | `() => {}` |
| `disabled` | `boolean` | Whether the component should be resizable | Yes | `false` |
| `interval` | `number` | The interval at which the resize will occur (i.e. which sizes the component will snap to) | Yes | `1` |
| `maintainAspectRatio` | `boolean` | Whether the component should maintain its aspect ratio (ratio between `initialHeight` and `initialWidth`) when resizing | Yes | `false` |
| `parent` | `RefObject<HTMLElement>` | A ref to the parent element of the handle | Yes | `null` |
| `reverse` | `boolean` | Whether the handle should be reversed | Yes | `false` |
Passing the same property to both the hook and the `getHandleProps` function will override the hook's property with the `getHandleProps` property.
The `onResize`, `onDragEnd` and `onDragStart` functions will be invoked with an object containing the following properties:
| Property | Type | Description |
| --- | --- | --- |
`newHeight` | `number` | The new height of the component |
`heightDiff` | `number` | The difference in height between the previous and the new height |
`newWidth` | `number` | The new width of the component |
`widthDiff` | `number` | The difference in width between the previous and the new width |
## Example
A simple example of how to use the hook:
```jsx
import React from 'react';
import { useResizable } from 'react-use-resizable';
const FreeMoving = () => {
const { getRootProps, getHandleProps } = useResizable({
initialWidth: 150,
initialHeight: 150
});
return (
<div>
<div
className="bg-blue-500 relative rounded flex justify-center items-center"
{...getRootProps()}
>
<div className="text-white text-center">Free moving</div>
<div
className="bg-blue-700 absolute bottom-0 right-0 p-2 rounded-tl-lg rounded-br text-white"
{...getHandleProps()}
>
Handle
</div>
</div>
</div>
);
};
```
Many more examples can be found in the [demo](https://mikkelwestermann.github.io/react-use-resizable/).

View File

@@ -0,0 +1,48 @@
import React from 'react';
declare type SharedProps = {
maxHeight?: number;
maxWidth?: number;
minHeight?: number;
minWidth?: number;
lockHorizontal?: boolean;
lockVertical?: boolean;
onResize?: (values: MoveValues) => void;
onDragEnd?: (values: MoveValues) => void;
onDragStart?: (values: MoveValues) => void;
disabled?: boolean;
maintainAspectRatio?: boolean;
};
export interface ResizableProps extends SharedProps {
interval?: number;
initialHeight?: number | string;
initialWidth?: number | string;
}
export interface ResizeHandleProps extends SharedProps {
parent?: React.RefObject<HTMLElement>;
interval?: number;
reverse?: boolean;
}
export declare type MoveValues = {
newHeight: number;
heightDiff: number;
newWidth: number;
widthDiff: number;
};
export declare const useResizable: (options: ResizableProps) => {
rootRef: React.RefObject<HTMLDivElement>;
getRootProps: () => {
ref: React.RefObject<HTMLDivElement>;
style: {
height: string | number | undefined;
width: string | number | undefined;
};
};
getHandleProps: (handleProps?: ResizeHandleProps) => {
onMouseDown: (e: React.MouseEvent | React.TouchEvent) => void;
onTouchStart: (e: React.MouseEvent | React.TouchEvent) => void;
style: {
cursor: string;
};
};
};
export {};

View File

@@ -0,0 +1,216 @@
"use strict";
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useResizable = void 0;
var react_1 = require("react");
var MoveEvent;
(function (MoveEvent) {
MoveEvent["MouseMove"] = "mousemove";
MoveEvent["TouchMove"] = "touchmove";
})(MoveEvent || (MoveEvent = {}));
var EndEvent;
(function (EndEvent) {
EndEvent["MouseUp"] = "mouseup";
EndEvent["TouchEnd"] = "touchend";
})(EndEvent || (EndEvent = {}));
var defaultProps = {
interval: 1,
initialHeight: 100,
initialWidth: 100,
lockHorizontal: false,
lockVertical: false,
};
var useResizable = function (options) {
var props = __assign(__assign({}, defaultProps), options);
var parentRef = (0, react_1.useRef)(null);
var getRootProps = function () {
var initialHeight = props.initialHeight, initialWidth = props.initialWidth;
return {
ref: parentRef,
style: {
height: initialHeight,
width: initialWidth,
},
};
};
var getHandleProps = function (handleProps) {
if (!handleProps) {
handleProps = {};
}
var _a = __assign(__assign({}, props), handleProps), _b = _a.parent, parent = _b === void 0 ? parentRef : _b, _c = _a.interval, interval = _c === void 0 ? 1 : _c, _d = _a.maxHeight, maxHeight = _d === void 0 ? Number.MAX_SAFE_INTEGER : _d, _e = _a.maxWidth, maxWidth = _e === void 0 ? Number.MAX_SAFE_INTEGER : _e, reverse = _a.reverse, lockHorizontal = _a.lockHorizontal, lockVertical = _a.lockVertical, onResize = _a.onResize, onDragEnd = _a.onDragEnd, onDragStart = _a.onDragStart, _f = _a.minHeight, minHeight = _f === void 0 ? 0 : _f, _g = _a.minWidth, minWidth = _g === void 0 ? 0 : _g, _h = _a.disabled, disabled = _h === void 0 ? false : _h, _j = _a.maintainAspectRatio, maintainAspectRatio = _j === void 0 ? false : _j;
var handleMove = function (clientY, startHeight, startY, clientX, startWidth, startX) {
var _a, _b;
if (disabled)
return;
var currentWidth = ((_a = parent === null || parent === void 0 ? void 0 : parent.current) === null || _a === void 0 ? void 0 : _a.clientWidth) || 0;
var currentHeight = ((_b = parent === null || parent === void 0 ? void 0 : parent.current) === null || _b === void 0 ? void 0 : _b.clientHeight) || 0;
var roundedHeight = currentHeight;
var roundedWidth = currentWidth;
if (!lockVertical) {
var newHeight = startHeight + (clientY - startY) * (reverse ? -1 : 1);
// Round height to nearest interval
roundedHeight = Math.round(newHeight / interval) * interval;
if (roundedHeight <= 0) {
roundedHeight = interval;
}
if (roundedHeight >= maxHeight) {
roundedHeight = maxHeight;
}
if (roundedHeight <= minHeight) {
roundedHeight = minHeight;
}
if (parent === null || parent === void 0 ? void 0 : parent.current) {
parent.current.style.height = "".concat(roundedHeight, "px");
}
}
if (!lockHorizontal) {
var newWidth = startWidth + (clientX - startX) * (reverse ? -1 : 1);
// Round height to nearest interval
roundedWidth = Math.round(newWidth / interval) * interval;
if (roundedWidth <= 0) {
roundedWidth = interval;
}
if (roundedWidth >= maxWidth) {
roundedWidth = maxWidth;
}
if (roundedWidth <= minWidth) {
roundedWidth = minWidth;
}
if (parent === null || parent === void 0 ? void 0 : parent.current) {
parent.current.style.width = "".concat(roundedWidth, "px");
}
}
if (maintainAspectRatio) {
var aspectRatio = currentWidth / currentHeight;
var newAspectRatio = roundedWidth / roundedHeight;
if (newAspectRatio > aspectRatio) {
roundedWidth = roundedHeight * aspectRatio;
if (parent === null || parent === void 0 ? void 0 : parent.current) {
parent.current.style.width = "".concat(roundedWidth, "px");
}
}
else {
roundedHeight = roundedWidth / aspectRatio;
if (parent === null || parent === void 0 ? void 0 : parent.current) {
parent.current.style.height = "".concat(roundedHeight, "px");
}
}
}
if (onResize) {
onResize({
newHeight: roundedHeight,
heightDiff: roundedHeight - currentHeight,
newWidth: roundedWidth,
widthDiff: roundedWidth - currentWidth,
});
}
};
var handleMouseMove = function (startHeight, startY, startWidth, startX) { return function (e) {
if (!(e instanceof MouseEvent))
return;
handleMove(e.clientY, startHeight, startY, e.clientX, startWidth, startX);
}; };
var handleTouchMove = function (startHeight, startY, startWidth, startX) { return function (e) {
e.preventDefault();
if (!(e instanceof TouchEvent))
return;
handleMove(e.touches[0].clientY, startHeight, startY, e.touches[0].clientX, startWidth, startX);
}; };
var handleDragEnd = function (handleMoveInstance, moveEvent, endEvent, startHeight, startWidth) {
function dragHandler() {
var _a, _b;
document.removeEventListener(moveEvent, handleMoveInstance);
document.removeEventListener(endEvent, dragHandler);
if (onDragEnd) {
var currentWidth = ((_a = parent === null || parent === void 0 ? void 0 : parent.current) === null || _a === void 0 ? void 0 : _a.clientWidth) || 0;
var currentHeight = ((_b = parent === null || parent === void 0 ? void 0 : parent.current) === null || _b === void 0 ? void 0 : _b.clientHeight) || 0;
onDragEnd({
newHeight: currentHeight,
heightDiff: currentHeight - startHeight,
newWidth: currentWidth,
widthDiff: currentWidth - startWidth,
});
}
}
return dragHandler;
};
var handleDown = function (e) {
var _a, _b;
if (disabled)
return;
var startHeight = ((_a = parent === null || parent === void 0 ? void 0 : parent.current) === null || _a === void 0 ? void 0 : _a.clientHeight) || 0;
var startWidth = ((_b = parent === null || parent === void 0 ? void 0 : parent.current) === null || _b === void 0 ? void 0 : _b.clientWidth) || 0;
var moveHandler = null;
var moveEvent = null;
var endEvent = null;
if (e.type === 'mousedown') {
var _c = e, clientY = _c.clientY, clientX = _c.clientX;
moveHandler = handleMouseMove(startHeight, clientY, startWidth, clientX);
moveEvent = MoveEvent.MouseMove;
endEvent = EndEvent.MouseUp;
}
else if (e.type === 'touchstart') {
var touches = e.touches;
var _d = touches[0], clientY = _d.clientY, clientX = _d.clientX;
moveHandler = handleTouchMove(startHeight, clientY, startWidth, clientX);
moveEvent = MoveEvent.TouchMove;
endEvent = EndEvent.TouchEnd;
}
if (!moveHandler || !moveEvent || !endEvent)
return;
if (onDragStart) {
onDragStart({
newHeight: startHeight,
heightDiff: 0,
newWidth: startWidth,
widthDiff: 0,
});
}
var dragEndHandler = handleDragEnd(moveHandler, moveEvent, endEvent, startHeight, startWidth);
// Attach the mousemove/mouseup/touchmove/touchend listeners to the document
// so that we can handle the case where the user drags outside of the element
document.addEventListener(moveEvent, moveHandler, { passive: false });
document.addEventListener(endEvent, dragEndHandler);
};
var cursor;
if (disabled) {
cursor = 'not-allowed';
}
else if (lockHorizontal && lockVertical) {
cursor = 'default';
}
else if (lockHorizontal) {
cursor = 'row-resize';
}
else if (lockVertical) {
cursor = 'col-resize';
}
else {
cursor = 'nwse-resize';
}
var style = {
cursor: cursor,
};
return {
onMouseDown: handleDown,
onTouchStart: handleDown,
style: style,
};
};
return {
rootRef: parentRef,
getRootProps: getRootProps,
getHandleProps: getHandleProps,
};
};
exports.useResizable = useResizable;

View File

@@ -0,0 +1,47 @@
{
"name": "react-use-resizable",
"version": "0.2.0",
"description": "A react hook for creating resizable elements",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"test": "jest --config jestconfig.json",
"build": "tsc",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/MikkelWestermann/react-use-resizable.git"
},
"author": "Mikkel Westermann",
"license": "ISC",
"bugs": {
"url": "https://github.com/MikkelWestermann/react-use-resizable/issues"
},
"files": [
"lib/**/*"
],
"homepage": "https://github.com/MikkelWestermann/react-use-resizable#readme",
"keywords": [
"react",
"hook",
"resizable",
"resize",
"element"
],
"devDependencies": {
"@types/jest": "^29.1.1",
"@types/react": "^18.0.21",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"eslint": "^8.24.0",
"eslint-plugin-react": "^7.31.8",
"jest": "^29.1.2",
"prettier": "^2.7.1",
"ts-jest": "^29.0.3",
"typescript": "^4.8.4"
},
"peerDependencies": {
"react": ">=16.8.0"
}
}