fix: prevent asset conflicts between React and Grid.js versions

Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-04-18 17:02:14 +07:00
parent bd9cdac02e
commit e8fbfb14c1
74973 changed files with 6658406 additions and 71 deletions

21
node_modules/re-resizable/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2018 @bokuweb
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.

336
node_modules/re-resizable/README.md generated vendored Normal file
View File

@@ -0,0 +1,336 @@
<p align="center"><img src ="https://github.com/bokuweb/re-resizable/blob/master/logo.png?raw=true" /></p>
<p align="center">📏 A resizable component for React.</p>
<p align="center"><img src="https://github.com/bokuweb/re-resizable/workflows/Continuous%20Integration/badge.svg" alt="Build Status" />
<a href="https://www.npmjs.com/package/re-resizable">
<img src="https://img.shields.io/npm/v/re-resizable.svg" alt="Build Status" /></a>
<a href="https://www.npmjs.com/package/re-resizable">
<img src="https://img.shields.io/npm/dm/re-resizable.svg" /></a>
<a href="https://renovatebot.com/">
<img src="https://img.shields.io/badge/renovate-enabled-brightgreen.svg" /></a>
<a href="https://github.com/prettier/prettier">
<img src="https://img.shields.io/badge/styled_with-prettier-ff69b4.svg" /></a>
</p>
## Table of Contents
- [Screenshot](#Screenshot)
- [Live Demo](#live-demo)
- [Storybook](#storybook)
- [CodeSandbox](#codesandbox)
- [Install](#install)
- [Usage](#usage)
- [Props](#props)
- [Instance API](#instance-api)
- [updateSize(size: { width: number | string, height: number | string }): void](#updateSize-void)
- [Test](#test)
- [Related](#related)
## Screenshot
![screenshot](https://github.com/bokuweb/re-resizable/blob/master/docs/screenshot.gif?raw=true)
## Live Demo
### Storybook
[Storybook](http://bokuweb.github.io/re-resizable/)
### CodeSandbox
[![Edit xp9p7272m4](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/xp9p7272m4)
[CodeSandbox](https://codesandbox.io/s/xp9p7272m4)
[CodeSandbox(TypeScript)](https://codesandbox.io/s/1vwo2p4l64)
[CodeSandbox(With hooks)](https://codesandbox.io/s/blissful-joliot-d3unx)
## Install
```sh
$ npm install --save re-resizable
```
## Usage
### Example with `defaultSize`
```javascript
import { Resizable } from 're-resizable';
<Resizable
defaultSize={{
width: 320,
height: 200,
}}
>
Sample with default size
</Resizable>
```
If you only want to set the width, you can do so by providing just the width property.
The height property will automatically be set to auto, which means it will adjust 100% of its parent's height:
```javascript
import { Resizable } from 're-resizable';
<Resizable
defaultSize={{
width: 320
}}
>
Sample with default size
</Resizable>
```
### Example with `size`
If you use `size` props, please manage state by yourself.
```javascript
import { Resizable } from 're-resizable';
<Resizable
size={{ width: this.state.width, height: this.state.height }}
onResizeStop={(e, direction, ref, d) => {
this.setState({
width: this.state.width + d.width,
height: this.state.height + d.height,
});
}}
>
Sample with size
</Resizable>
```
## Props
#### `defaultSize?: { width?: (number | string), height?: (number | string) };`
Specifies the `width` and `height` that the dragged item should start at.
For example, you can set `300`, `'300px'`, `50%`.
If both `defaultSize` and `size` omitted, set `'auto'`.
`defaultSize` will be ignored when `size` set.
#### `size?: { width?: (number | string), height?: (number | string) };`
The `size` property is used to set the size of the component.
For example, you can set `300`, `'300px'`, `50%`.
Use `size` if you need to control size state by yourself.
#### `className?: string;`
The `className` property is used to set the custom `className` of a resizable component.
#### `style?: { [key: string]: string };`
The `style` property is used to set the custom `style` of a resizable component.
#### `minWidth?: number | string;`
The `minWidth` property is used to set the minimum width of a resizable component. Defaults to 10px.
It accepts viewport as well as parent relative units. For example, you can set `300`, `50%`, `50vw` or `50vh`.
Same type of values can be applied to `minHeight`, `maxWidth` and `maxHeight`.
#### `minHeight?: number | string;`
The `minHeight` property is used to set the minimum height of a resizable component. Defaults to 10px.
#### `maxWidth?: number | string;`
The `maxWidth` property is used to set the maximum width of a resizable component.
#### `maxHeight?: number | string`;
The `maxHeight` property is used to set the maximum height of a resizable component.
#### `grid?: [number, number];`
The `grid` property is used to specify the increments that resizing should snap to. Defaults to `[1, 1]`.
#### `gridGap?: [number, number];`
The `gridGap` property is used to specify any gaps between your grid cells that should be accounted for when resizing. Defaults to `[0, 0]`.
The value provided for each axis will always add the grid gap amount times grid cells spanned minus one.
#### `snap?: { x?: Array<number>, y?: Array<number> };`
The `snap` property is used to specify absolute pixel values that resizing should snap to. `x` and `y` are both optional, allowing you to only include the axis you want to define. Defaults to `null`.
#### `snapGap?: number`
The `snapGap` property is used to specify the minimum gap required in order to move to the next snapping target. Defaults to `0` which means that snap targets are always used.
#### `resizeRatio?: number | [number, number];`
The `resizeRatio` property is used to set the number of pixels the resizable component scales by compared to the number of pixels the mouse/touch moves. Defaults to `1` (for a 1:1 ratio). The number set is the left side of the ratio, `2` will give a 2:1 ratio.
For [number, number] means [resizeRatioX, resizeRatioY], more precise control.
#### `lockAspectRatio?: boolean | number;`
The `lockAspectRatio` property is used to lock aspect ratio.
Set to `true` to lock the aspect ratio based on the initial size.
Set to a numeric value to lock a specific aspect ratio (such as `16/9`).
If set to numeric, make sure to set initial height/width to values with correct aspect ratio.
If omitted, set `false`.
#### `lockAspectRatioExtraWidth?: number;`
The `lockAspectRatioExtraWidth` property enables a resizable component to maintain an aspect ratio plus extra width.
For instance, a video could be displayed 16:9 with a 50px side bar.
If omitted, set `0`.
#### `lockAspectRatioExtraHeight?: number;`
The `lockAspectRatioExtraHeight` property enables a resizable component to maintain an aspect ratio plus extra height.
For instance, a video could be displayed 16:9 with a 50px header bar.
If omitted, set `0`.
#### `bounds?: ('window' | 'parent' | HTMLElement);`
Specifies resize boundaries.
#### `boundsByDirection?: boolean;`
By default max dimensions based on left and top element position.
Width grow to right side, height grow to bottom side.
Set `true` for detect max dimensions by direction.
For example: enable `boundsByDirection` when resizable component stick on right side of screen and you want resize by left handler;
`false` by default.
#### `handleStyles?: HandleStyles;`
The `handleStyles` property is used to override the style of one or more resize handles.
Only the axis you specify will have its handle style replaced.
If you specify a value for `right` it will completely replace the styles for the `right` resize handle,
but other handle will still use the default styles.
#### `handleClasses?: HandleClassName;`
The `handleClasses` property is used to set the className of one or more resize handles.
#### `handleComponent?: HandleComponent;`
The `handleComponent` property is used to pass a React Component to be rendered as one or more resize handle. For example, this could be used to use an arrow icon as a handle..
#### `handleWrapperStyle?: { [key: string]: string };`
The `handleWrapperStyle` property is used to override the style of resize handles wrapper.
#### `handleWrapperClass?: string;`
The `handleWrapperClass` property is used to override the className of resize handles wrapper.
#### `enable?: ?Enable | false;`
The `enable` property is used to set the resizable permission of a resizable component.
The permission of `top`, `right`, `bottom`, `left`, `topRight`, `bottomRight`, `bottomLeft`, `topLeft` direction resizing.
If omitted, all resizer are enabled.
If you want to permit only right direction resizing, set `{ top:false, right:true, bottom:false, left:false, topRight:false, bottomRight:false, bottomLeft:false, topLeft:false }`.
#### `onResizeStart?: ResizeStartCallBack;`
`ResizeStartCallBack` type is below.
```javascript
type ResizeStartCallback = (
e: SyntheticMouseEvent<HTMLDivElement> | SyntheticTouchEvent<HTMLDivElement>,
dir: ResizableDirection,
refToElement: HTMLDivElement,
) => void;
```
Calls when resizable component resize start.
#### `onResize?: ResizeCallback;`
#### `scale?: number`;
The `scale` property is used in the scenario where the resizable element is a descendent of an element using css scaling (e.g. - `transform: scale(0.5)`).
#### `as?: string | React.ComponentType`;
By default the `Resizable` component will render a `div` as a wrapper. The `as` property is used to change the element used.
### Basic
`ResizeCallback` type is below.
```javascript
type ResizeCallback = (
event: MouseEvent | TouchEvent,
direction: ResizableDirection,
refToElement: HTMLDivElement,
delta: NumberSize,
) => void;
```
Calls when resizable component resizing.
#### `onResizeStop?: ResizeCallback;`
`ResizeCallback` type is below.
```javascript
type ResizeCallback = (
event: MouseEvent | TouchEvent,
direction: ResizableDirection,
refToElement: HTMLDivElement,
delta: NumberSize,
) => void;
```
Calls when resizable component resize stop.
## Instance API
#### * `updateSize(size: { width: number | string, height: number | string }): void`
Update component size.
`grid`, `snap`, `max/minWidth`, `max/minHeight` props is ignored, when this method called.
- for example
```javascript
class YourComponent extends Component {
// ...
update() {
this.resizable.updateSize({ width: 200, height: 300 });
}
render() {
return (
<Resizable ref={c => { this.resizable = c; }}>
example
</Resizable>
);
}
// ...
}
```
## Contribute
If you have a feature request, please add it as an issue or make a pull request.
If you have a bug to report, please reproduce the bug in [CodeSandbox](https://codesandbox.io/s/ll587k677z) to help us easily isolate it.
## Test
``` sh
npm test
```
## Related
- [react-rnd](https://github.com/bokuweb/react-rnd)
- [react-sortable-pane](https://github.com/bokuweb/react-sortable-pane)

0
node_modules/re-resizable/lib/.keep generated vendored Normal file
View File

196
node_modules/re-resizable/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,196 @@
import { PureComponent } from 'react';
import { Direction } from './resizer';
export type ResizeDirection = Direction;
export interface Enable {
top?: boolean;
right?: boolean;
bottom?: boolean;
left?: boolean;
topRight?: boolean;
bottomRight?: boolean;
bottomLeft?: boolean;
topLeft?: boolean;
}
export interface HandleStyles {
top?: React.CSSProperties;
right?: React.CSSProperties;
bottom?: React.CSSProperties;
left?: React.CSSProperties;
topRight?: React.CSSProperties;
bottomRight?: React.CSSProperties;
bottomLeft?: React.CSSProperties;
topLeft?: React.CSSProperties;
}
export interface HandleClassName {
top?: string;
right?: string;
bottom?: string;
left?: string;
topRight?: string;
bottomRight?: string;
bottomLeft?: string;
topLeft?: string;
}
export interface Size {
width?: string | number;
height?: string | number;
}
export interface NumberSize {
width: number;
height: number;
}
export interface HandleComponent {
top?: React.ReactElement<any>;
right?: React.ReactElement<any>;
bottom?: React.ReactElement<any>;
left?: React.ReactElement<any>;
topRight?: React.ReactElement<any>;
bottomRight?: React.ReactElement<any>;
bottomLeft?: React.ReactElement<any>;
topLeft?: React.ReactElement<any>;
}
export type ResizeCallback = (event: MouseEvent | TouchEvent, direction: Direction, elementRef: HTMLElement, delta: NumberSize) => void;
export type ResizeStartCallback = (e: React.MouseEvent<HTMLElement> | React.TouchEvent<HTMLElement>, dir: Direction, elementRef: HTMLElement) => void | boolean;
export interface ResizableProps {
as?: string | React.ComponentType<any>;
style?: React.CSSProperties;
className?: string;
grid?: [number, number];
gridGap?: [number, number];
snap?: {
x?: number[];
y?: number[];
};
snapGap?: number;
bounds?: 'parent' | 'window' | HTMLElement;
boundsByDirection?: boolean;
size?: Size;
minWidth?: string | number;
minHeight?: string | number;
maxWidth?: string | number;
maxHeight?: string | number;
lockAspectRatio?: boolean | number;
lockAspectRatioExtraWidth?: number;
lockAspectRatioExtraHeight?: number;
enable?: Enable | false;
handleStyles?: HandleStyles;
handleClasses?: HandleClassName;
handleWrapperStyle?: React.CSSProperties;
handleWrapperClass?: string;
handleComponent?: HandleComponent;
children?: React.ReactNode;
onResizeStart?: ResizeStartCallback;
onResize?: ResizeCallback;
onResizeStop?: ResizeCallback;
defaultSize?: Size;
scale?: number;
resizeRatio?: number | [number, number];
}
interface State {
isResizing: boolean;
direction: Direction;
original: {
x: number;
y: number;
width: number;
height: number;
};
width: number | string;
height: number | string;
backgroundStyle: React.CSSProperties;
flexBasis?: string | number;
}
declare global {
interface Window {
MouseEvent: typeof MouseEvent;
TouchEvent: typeof TouchEvent;
}
}
export declare class Resizable extends PureComponent<ResizableProps, State> {
flexDir?: 'row' | 'column';
get parentNode(): HTMLElement | null;
get window(): Window | null;
get propsSize(): Size;
get size(): NumberSize;
get sizeStyle(): {
width: string;
height: string;
};
static defaultProps: {
as: string;
onResizeStart: () => void;
onResize: () => void;
onResizeStop: () => void;
enable: {
top: boolean;
right: boolean;
bottom: boolean;
left: boolean;
topRight: boolean;
bottomRight: boolean;
bottomLeft: boolean;
topLeft: boolean;
};
style: {};
grid: number[];
gridGap: number[];
lockAspectRatio: boolean;
lockAspectRatioExtraWidth: number;
lockAspectRatioExtraHeight: number;
scale: number;
resizeRatio: number;
snapGap: number;
};
ratio: number;
resizable: HTMLElement | null;
parentLeft: number;
parentTop: number;
resizableLeft: number;
resizableRight: number;
resizableTop: number;
resizableBottom: number;
targetLeft: number;
targetTop: number;
delta: {
width: number;
height: number;
};
constructor(props: ResizableProps);
getParentSize(): {
width: number;
height: number;
};
bindEvents(): void;
unbindEvents(): void;
componentDidMount(): void;
appendBase: () => HTMLDivElement | null;
removeBase: (base: HTMLElement) => void;
componentWillUnmount(): void;
createSizeForCssProperty(newSize: number | string, kind: 'width' | 'height'): number | string;
calculateNewMaxFromBoundary(maxWidth?: number, maxHeight?: number): {
maxWidth: number | undefined;
maxHeight: number | undefined;
};
calculateNewSizeFromDirection(clientX: number, clientY: number): {
newWidth: number;
newHeight: number;
};
calculateNewSizeFromAspectRatio(newWidth: number, newHeight: number, max: {
width?: number;
height?: number;
}, min: {
width?: number;
height?: number;
}): {
newWidth: number;
newHeight: number;
};
setBoundingClientRect(): void;
onResizeStart(event: React.MouseEvent<HTMLElement> | React.TouchEvent<HTMLElement>, direction: Direction): void;
onMouseMove(event: MouseEvent | TouchEvent): void;
onMouseUp(event: MouseEvent | TouchEvent): void;
updateSize(size: Size): void;
renderResizer(): import("react/jsx-runtime").JSX.Element | null;
render(): import("react/jsx-runtime").JSX.Element;
}
export {};

846
node_modules/re-resizable/lib/index.es5.js generated vendored Normal file
View File

@@ -0,0 +1,846 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var jsxRuntime = require('react/jsx-runtime');
var react = require('react');
var reactDom = require('react-dom');
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(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);
};
var rowSizeBase = {
width: '100%',
height: '10px',
top: '0px',
left: '0px',
cursor: 'row-resize',
};
var colSizeBase = {
width: '10px',
height: '100%',
top: '0px',
left: '0px',
cursor: 'col-resize',
};
var edgeBase = {
width: '20px',
height: '20px',
position: 'absolute',
zIndex: 1,
};
var styles = {
top: __assign(__assign({}, rowSizeBase), { top: '-5px' }),
right: __assign(__assign({}, colSizeBase), { left: undefined, right: '-5px' }),
bottom: __assign(__assign({}, rowSizeBase), { top: undefined, bottom: '-5px' }),
left: __assign(__assign({}, colSizeBase), { left: '-5px' }),
topRight: __assign(__assign({}, edgeBase), { right: '-10px', top: '-10px', cursor: 'ne-resize' }),
bottomRight: __assign(__assign({}, edgeBase), { right: '-10px', bottom: '-10px', cursor: 'se-resize' }),
bottomLeft: __assign(__assign({}, edgeBase), { left: '-10px', bottom: '-10px', cursor: 'sw-resize' }),
topLeft: __assign(__assign({}, edgeBase), { left: '-10px', top: '-10px', cursor: 'nw-resize' }),
};
var Resizer = react.memo(function (props) {
var onResizeStart = props.onResizeStart, direction = props.direction, children = props.children, replaceStyles = props.replaceStyles, className = props.className;
var onMouseDown = react.useCallback(function (e) {
onResizeStart(e, direction);
}, [onResizeStart, direction]);
var onTouchStart = react.useCallback(function (e) {
onResizeStart(e, direction);
}, [onResizeStart, direction]);
var style = react.useMemo(function () {
return __assign(__assign({ position: 'absolute', userSelect: 'none' }, styles[direction]), (replaceStyles !== null && replaceStyles !== void 0 ? replaceStyles : {}));
}, [replaceStyles, direction]);
return (jsxRuntime.jsx("div", { className: className || undefined, style: style, onMouseDown: onMouseDown, onTouchStart: onTouchStart, children: children }));
});
var DEFAULT_SIZE = {
width: 'auto',
height: 'auto',
};
var clamp = function (n, min, max) { return Math.max(Math.min(n, max), min); };
var snap = function (n, size, gridGap) {
var v = Math.round(n / size);
return v * size + gridGap * (v - 1);
};
var hasDirection = function (dir, target) {
return new RegExp(dir, 'i').test(target);
};
// INFO: In case of window is a Proxy and does not porxy Events correctly, use isTouchEvent & isMouseEvent to distinguish event type instead of `instanceof`.
var isTouchEvent = function (event) {
return Boolean(event.touches && event.touches.length);
};
var isMouseEvent = function (event) {
return Boolean((event.clientX || event.clientX === 0) &&
(event.clientY || event.clientY === 0));
};
var findClosestSnap = function (n, snapArray, snapGap) {
if (snapGap === void 0) { snapGap = 0; }
var closestGapIndex = snapArray.reduce(function (prev, curr, index) { return (Math.abs(curr - n) < Math.abs(snapArray[prev] - n) ? index : prev); }, 0);
var gap = Math.abs(snapArray[closestGapIndex] - n);
return snapGap === 0 || gap < snapGap ? snapArray[closestGapIndex] : n;
};
var getStringSize = function (n) {
n = n.toString();
if (n === 'auto') {
return n;
}
if (n.endsWith('px')) {
return n;
}
if (n.endsWith('%')) {
return n;
}
if (n.endsWith('vh')) {
return n;
}
if (n.endsWith('vw')) {
return n;
}
if (n.endsWith('vmax')) {
return n;
}
if (n.endsWith('vmin')) {
return n;
}
return "".concat(n, "px");
};
var getPixelSize = function (size, parentSize, innerWidth, innerHeight) {
if (size && typeof size === 'string') {
if (size.endsWith('px')) {
return Number(size.replace('px', ''));
}
if (size.endsWith('%')) {
var ratio = Number(size.replace('%', '')) / 100;
return parentSize * ratio;
}
if (size.endsWith('vw')) {
var ratio = Number(size.replace('vw', '')) / 100;
return innerWidth * ratio;
}
if (size.endsWith('vh')) {
var ratio = Number(size.replace('vh', '')) / 100;
return innerHeight * ratio;
}
}
return size;
};
var calculateNewMax = function (parentSize, innerWidth, innerHeight, maxWidth, maxHeight, minWidth, minHeight) {
maxWidth = getPixelSize(maxWidth, parentSize.width, innerWidth, innerHeight);
maxHeight = getPixelSize(maxHeight, parentSize.height, innerWidth, innerHeight);
minWidth = getPixelSize(minWidth, parentSize.width, innerWidth, innerHeight);
minHeight = getPixelSize(minHeight, parentSize.height, innerWidth, innerHeight);
return {
maxWidth: typeof maxWidth === 'undefined' ? undefined : Number(maxWidth),
maxHeight: typeof maxHeight === 'undefined' ? undefined : Number(maxHeight),
minWidth: typeof minWidth === 'undefined' ? undefined : Number(minWidth),
minHeight: typeof minHeight === 'undefined' ? undefined : Number(minHeight),
};
};
/**
* transform T | [T, T] to [T, T]
* @param val
* @returns
*/
// tslint:disable-next-line
var normalizeToPair = function (val) { return (Array.isArray(val) ? val : [val, val]); };
var definedProps = [
'as',
'ref',
'style',
'className',
'grid',
'gridGap',
'snap',
'bounds',
'boundsByDirection',
'size',
'defaultSize',
'minWidth',
'minHeight',
'maxWidth',
'maxHeight',
'lockAspectRatio',
'lockAspectRatioExtraWidth',
'lockAspectRatioExtraHeight',
'enable',
'handleStyles',
'handleClasses',
'handleWrapperStyle',
'handleWrapperClass',
'children',
'onResizeStart',
'onResize',
'onResizeStop',
'handleComponent',
'scale',
'resizeRatio',
'snapGap',
];
// HACK: This class is used to calculate % size.
var baseClassName = '__resizable_base__';
var Resizable = /** @class */ (function (_super) {
__extends(Resizable, _super);
function Resizable(props) {
var _a, _b, _c, _d;
var _this = _super.call(this, props) || this;
_this.ratio = 1;
_this.resizable = null;
// For parent boundary
_this.parentLeft = 0;
_this.parentTop = 0;
// For boundary
_this.resizableLeft = 0;
_this.resizableRight = 0;
_this.resizableTop = 0;
_this.resizableBottom = 0;
// For target boundary
_this.targetLeft = 0;
_this.targetTop = 0;
_this.delta = {
width: 0,
height: 0,
};
_this.appendBase = function () {
if (!_this.resizable || !_this.window) {
return null;
}
var parent = _this.parentNode;
if (!parent) {
return null;
}
var element = _this.window.document.createElement('div');
element.style.width = '100%';
element.style.height = '100%';
element.style.position = 'absolute';
element.style.transform = 'scale(0, 0)';
element.style.left = '0';
element.style.flex = '0 0 100%';
if (element.classList) {
element.classList.add(baseClassName);
}
else {
element.className += baseClassName;
}
parent.appendChild(element);
return element;
};
_this.removeBase = function (base) {
var parent = _this.parentNode;
if (!parent) {
return;
}
parent.removeChild(base);
};
_this.state = {
isResizing: false,
width: (_b = (_a = _this.propsSize) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 'auto',
height: (_d = (_c = _this.propsSize) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 'auto',
direction: 'right',
original: {
x: 0,
y: 0,
width: 0,
height: 0,
},
backgroundStyle: {
height: '100%',
width: '100%',
backgroundColor: 'rgba(0,0,0,0)',
cursor: 'auto',
opacity: 0,
position: 'fixed',
zIndex: 9999,
top: '0',
left: '0',
bottom: '0',
right: '0',
},
flexBasis: undefined,
};
_this.onResizeStart = _this.onResizeStart.bind(_this);
_this.onMouseMove = _this.onMouseMove.bind(_this);
_this.onMouseUp = _this.onMouseUp.bind(_this);
return _this;
}
Object.defineProperty(Resizable.prototype, "parentNode", {
get: function () {
if (!this.resizable) {
return null;
}
return this.resizable.parentNode;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Resizable.prototype, "window", {
get: function () {
if (!this.resizable) {
return null;
}
if (!this.resizable.ownerDocument) {
return null;
}
return this.resizable.ownerDocument.defaultView;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Resizable.prototype, "propsSize", {
get: function () {
return this.props.size || this.props.defaultSize || DEFAULT_SIZE;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Resizable.prototype, "size", {
get: function () {
var width = 0;
var height = 0;
if (this.resizable && this.window) {
var orgWidth = this.resizable.offsetWidth;
var orgHeight = this.resizable.offsetHeight;
// HACK: Set position `relative` to get parent size.
// This is because when re-resizable set `absolute`, I can not get base width correctly.
var orgPosition = this.resizable.style.position;
if (orgPosition !== 'relative') {
this.resizable.style.position = 'relative';
}
// INFO: Use original width or height if set auto.
width = this.resizable.style.width !== 'auto' ? this.resizable.offsetWidth : orgWidth;
height = this.resizable.style.height !== 'auto' ? this.resizable.offsetHeight : orgHeight;
// Restore original position
this.resizable.style.position = orgPosition;
}
return { width: width, height: height };
},
enumerable: false,
configurable: true
});
Object.defineProperty(Resizable.prototype, "sizeStyle", {
get: function () {
var _this = this;
var size = this.props.size;
var getSize = function (key) {
var _a;
if (typeof _this.state[key] === 'undefined' || _this.state[key] === 'auto') {
return 'auto';
}
if (_this.propsSize && _this.propsSize[key] && ((_a = _this.propsSize[key]) === null || _a === void 0 ? void 0 : _a.toString().endsWith('%'))) {
if (_this.state[key].toString().endsWith('%')) {
return _this.state[key].toString();
}
var parentSize = _this.getParentSize();
var value = Number(_this.state[key].toString().replace('px', ''));
var percent = (value / parentSize[key]) * 100;
return "".concat(percent, "%");
}
return getStringSize(_this.state[key]);
};
var width = size && typeof size.width !== 'undefined' && !this.state.isResizing
? getStringSize(size.width)
: getSize('width');
var height = size && typeof size.height !== 'undefined' && !this.state.isResizing
? getStringSize(size.height)
: getSize('height');
return { width: width, height: height };
},
enumerable: false,
configurable: true
});
Resizable.prototype.getParentSize = function () {
if (!this.parentNode) {
if (!this.window) {
return { width: 0, height: 0 };
}
return { width: this.window.innerWidth, height: this.window.innerHeight };
}
var base = this.appendBase();
if (!base) {
return { width: 0, height: 0 };
}
// INFO: To calculate parent width with flex layout
var wrapChanged = false;
var wrap = this.parentNode.style.flexWrap;
if (wrap !== 'wrap') {
wrapChanged = true;
this.parentNode.style.flexWrap = 'wrap';
// HACK: Use relative to get parent padding size
}
base.style.position = 'relative';
base.style.minWidth = '100%';
base.style.minHeight = '100%';
var size = {
width: base.offsetWidth,
height: base.offsetHeight,
};
if (wrapChanged) {
this.parentNode.style.flexWrap = wrap;
}
this.removeBase(base);
return size;
};
Resizable.prototype.bindEvents = function () {
if (this.window) {
this.window.addEventListener('mouseup', this.onMouseUp);
this.window.addEventListener('mousemove', this.onMouseMove);
this.window.addEventListener('mouseleave', this.onMouseUp);
this.window.addEventListener('touchmove', this.onMouseMove, {
capture: true,
passive: false,
});
this.window.addEventListener('touchend', this.onMouseUp);
}
};
Resizable.prototype.unbindEvents = function () {
if (this.window) {
this.window.removeEventListener('mouseup', this.onMouseUp);
this.window.removeEventListener('mousemove', this.onMouseMove);
this.window.removeEventListener('mouseleave', this.onMouseUp);
this.window.removeEventListener('touchmove', this.onMouseMove, true);
this.window.removeEventListener('touchend', this.onMouseUp);
}
};
Resizable.prototype.componentDidMount = function () {
if (!this.resizable || !this.window) {
return;
}
var computedStyle = this.window.getComputedStyle(this.resizable);
this.setState({
width: this.state.width || this.size.width,
height: this.state.height || this.size.height,
flexBasis: computedStyle.flexBasis !== 'auto' ? computedStyle.flexBasis : undefined,
});
};
Resizable.prototype.componentWillUnmount = function () {
if (this.window) {
this.unbindEvents();
}
};
Resizable.prototype.createSizeForCssProperty = function (newSize, kind) {
var propsSize = this.propsSize && this.propsSize[kind];
return this.state[kind] === 'auto' &&
this.state.original[kind] === newSize &&
(typeof propsSize === 'undefined' || propsSize === 'auto')
? 'auto'
: newSize;
};
Resizable.prototype.calculateNewMaxFromBoundary = function (maxWidth, maxHeight) {
var boundsByDirection = this.props.boundsByDirection;
var direction = this.state.direction;
var widthByDirection = boundsByDirection && hasDirection('left', direction);
var heightByDirection = boundsByDirection && hasDirection('top', direction);
var boundWidth;
var boundHeight;
if (this.props.bounds === 'parent') {
var parent_1 = this.parentNode;
if (parent_1) {
boundWidth = widthByDirection
? this.resizableRight - this.parentLeft
: parent_1.offsetWidth + (this.parentLeft - this.resizableLeft);
boundHeight = heightByDirection
? this.resizableBottom - this.parentTop
: parent_1.offsetHeight + (this.parentTop - this.resizableTop);
}
}
else if (this.props.bounds === 'window') {
if (this.window) {
boundWidth = widthByDirection ? this.resizableRight : this.window.innerWidth - this.resizableLeft;
boundHeight = heightByDirection ? this.resizableBottom : this.window.innerHeight - this.resizableTop;
}
}
else if (this.props.bounds) {
boundWidth = widthByDirection
? this.resizableRight - this.targetLeft
: this.props.bounds.offsetWidth + (this.targetLeft - this.resizableLeft);
boundHeight = heightByDirection
? this.resizableBottom - this.targetTop
: this.props.bounds.offsetHeight + (this.targetTop - this.resizableTop);
}
if (boundWidth && Number.isFinite(boundWidth)) {
maxWidth = maxWidth && maxWidth < boundWidth ? maxWidth : boundWidth;
}
if (boundHeight && Number.isFinite(boundHeight)) {
maxHeight = maxHeight && maxHeight < boundHeight ? maxHeight : boundHeight;
}
return { maxWidth: maxWidth, maxHeight: maxHeight };
};
Resizable.prototype.calculateNewSizeFromDirection = function (clientX, clientY) {
var scale = this.props.scale || 1;
var _a = normalizeToPair(this.props.resizeRatio || 1), resizeRatioX = _a[0], resizeRatioY = _a[1];
var _b = this.state, direction = _b.direction, original = _b.original;
var _c = this.props, lockAspectRatio = _c.lockAspectRatio, lockAspectRatioExtraHeight = _c.lockAspectRatioExtraHeight, lockAspectRatioExtraWidth = _c.lockAspectRatioExtraWidth;
var newWidth = original.width;
var newHeight = original.height;
var extraHeight = lockAspectRatioExtraHeight || 0;
var extraWidth = lockAspectRatioExtraWidth || 0;
if (hasDirection('right', direction)) {
newWidth = original.width + ((clientX - original.x) * resizeRatioX) / scale;
if (lockAspectRatio) {
newHeight = (newWidth - extraWidth) / this.ratio + extraHeight;
}
}
if (hasDirection('left', direction)) {
newWidth = original.width - ((clientX - original.x) * resizeRatioX) / scale;
if (lockAspectRatio) {
newHeight = (newWidth - extraWidth) / this.ratio + extraHeight;
}
}
if (hasDirection('bottom', direction)) {
newHeight = original.height + ((clientY - original.y) * resizeRatioY) / scale;
if (lockAspectRatio) {
newWidth = (newHeight - extraHeight) * this.ratio + extraWidth;
}
}
if (hasDirection('top', direction)) {
newHeight = original.height - ((clientY - original.y) * resizeRatioY) / scale;
if (lockAspectRatio) {
newWidth = (newHeight - extraHeight) * this.ratio + extraWidth;
}
}
return { newWidth: newWidth, newHeight: newHeight };
};
Resizable.prototype.calculateNewSizeFromAspectRatio = function (newWidth, newHeight, max, min) {
var _a = this.props, lockAspectRatio = _a.lockAspectRatio, lockAspectRatioExtraHeight = _a.lockAspectRatioExtraHeight, lockAspectRatioExtraWidth = _a.lockAspectRatioExtraWidth;
var computedMinWidth = typeof min.width === 'undefined' ? 10 : min.width;
var computedMaxWidth = typeof max.width === 'undefined' || max.width < 0 ? newWidth : max.width;
var computedMinHeight = typeof min.height === 'undefined' ? 10 : min.height;
var computedMaxHeight = typeof max.height === 'undefined' || max.height < 0 ? newHeight : max.height;
var extraHeight = lockAspectRatioExtraHeight || 0;
var extraWidth = lockAspectRatioExtraWidth || 0;
if (lockAspectRatio) {
var extraMinWidth = (computedMinHeight - extraHeight) * this.ratio + extraWidth;
var extraMaxWidth = (computedMaxHeight - extraHeight) * this.ratio + extraWidth;
var extraMinHeight = (computedMinWidth - extraWidth) / this.ratio + extraHeight;
var extraMaxHeight = (computedMaxWidth - extraWidth) / this.ratio + extraHeight;
var lockedMinWidth = Math.max(computedMinWidth, extraMinWidth);
var lockedMaxWidth = Math.min(computedMaxWidth, extraMaxWidth);
var lockedMinHeight = Math.max(computedMinHeight, extraMinHeight);
var lockedMaxHeight = Math.min(computedMaxHeight, extraMaxHeight);
newWidth = clamp(newWidth, lockedMinWidth, lockedMaxWidth);
newHeight = clamp(newHeight, lockedMinHeight, lockedMaxHeight);
}
else {
newWidth = clamp(newWidth, computedMinWidth, computedMaxWidth);
newHeight = clamp(newHeight, computedMinHeight, computedMaxHeight);
}
return { newWidth: newWidth, newHeight: newHeight };
};
Resizable.prototype.setBoundingClientRect = function () {
var adjustedScale = 1 / (this.props.scale || 1);
// For parent boundary
if (this.props.bounds === 'parent') {
var parent_2 = this.parentNode;
if (parent_2) {
var parentRect = parent_2.getBoundingClientRect();
this.parentLeft = parentRect.left * adjustedScale;
this.parentTop = parentRect.top * adjustedScale;
}
}
// For target(html element) boundary
if (this.props.bounds && typeof this.props.bounds !== 'string') {
var targetRect = this.props.bounds.getBoundingClientRect();
this.targetLeft = targetRect.left * adjustedScale;
this.targetTop = targetRect.top * adjustedScale;
}
// For boundary
if (this.resizable) {
var _a = this.resizable.getBoundingClientRect(), left = _a.left, top_1 = _a.top, right = _a.right, bottom = _a.bottom;
this.resizableLeft = left * adjustedScale;
this.resizableRight = right * adjustedScale;
this.resizableTop = top_1 * adjustedScale;
this.resizableBottom = bottom * adjustedScale;
}
};
Resizable.prototype.onResizeStart = function (event, direction) {
if (!this.resizable || !this.window) {
return;
}
var clientX = 0;
var clientY = 0;
if (event.nativeEvent && isMouseEvent(event.nativeEvent)) {
clientX = event.nativeEvent.clientX;
clientY = event.nativeEvent.clientY;
}
else if (event.nativeEvent && isTouchEvent(event.nativeEvent)) {
clientX = event.nativeEvent.touches[0].clientX;
clientY = event.nativeEvent.touches[0].clientY;
}
if (this.props.onResizeStart) {
if (this.resizable) {
var startResize = this.props.onResizeStart(event, direction, this.resizable);
if (startResize === false) {
return;
}
}
}
// Fix #168
if (this.props.size) {
if (typeof this.props.size.height !== 'undefined' && this.props.size.height !== this.state.height) {
this.setState({ height: this.props.size.height });
}
if (typeof this.props.size.width !== 'undefined' && this.props.size.width !== this.state.width) {
this.setState({ width: this.props.size.width });
}
}
// For lockAspectRatio case
this.ratio =
typeof this.props.lockAspectRatio === 'number' ? this.props.lockAspectRatio : this.size.width / this.size.height;
var flexBasis;
var computedStyle = this.window.getComputedStyle(this.resizable);
if (computedStyle.flexBasis !== 'auto') {
var parent_3 = this.parentNode;
if (parent_3) {
var dir = this.window.getComputedStyle(parent_3).flexDirection;
this.flexDir = dir.startsWith('row') ? 'row' : 'column';
flexBasis = computedStyle.flexBasis;
}
}
// For boundary
this.setBoundingClientRect();
this.bindEvents();
var state = {
original: {
x: clientX,
y: clientY,
width: this.size.width,
height: this.size.height,
},
isResizing: true,
backgroundStyle: __assign(__assign({}, this.state.backgroundStyle), { cursor: this.window.getComputedStyle(event.target).cursor || 'auto' }),
direction: direction,
flexBasis: flexBasis,
};
this.setState(state);
};
Resizable.prototype.onMouseMove = function (event) {
var _this = this;
if (!this.state.isResizing || !this.resizable || !this.window) {
return;
}
if (this.window.TouchEvent && isTouchEvent(event)) {
try {
event.preventDefault();
event.stopPropagation();
}
catch (e) {
// Ignore on fail
}
}
var _a = this.props, maxWidth = _a.maxWidth, maxHeight = _a.maxHeight, minWidth = _a.minWidth, minHeight = _a.minHeight;
var clientX = isTouchEvent(event) ? event.touches[0].clientX : event.clientX;
var clientY = isTouchEvent(event) ? event.touches[0].clientY : event.clientY;
var _b = this.state, direction = _b.direction, original = _b.original, width = _b.width, height = _b.height;
var parentSize = this.getParentSize();
var max = calculateNewMax(parentSize, this.window.innerWidth, this.window.innerHeight, maxWidth, maxHeight, minWidth, minHeight);
maxWidth = max.maxWidth;
maxHeight = max.maxHeight;
minWidth = max.minWidth;
minHeight = max.minHeight;
// Calculate new size
var _c = this.calculateNewSizeFromDirection(clientX, clientY), newHeight = _c.newHeight, newWidth = _c.newWidth;
// Calculate max size from boundary settings
var boundaryMax = this.calculateNewMaxFromBoundary(maxWidth, maxHeight);
if (this.props.snap && this.props.snap.x) {
newWidth = findClosestSnap(newWidth, this.props.snap.x, this.props.snapGap);
}
if (this.props.snap && this.props.snap.y) {
newHeight = findClosestSnap(newHeight, this.props.snap.y, this.props.snapGap);
}
// Calculate new size from aspect ratio
var newSize = this.calculateNewSizeFromAspectRatio(newWidth, newHeight, { width: boundaryMax.maxWidth, height: boundaryMax.maxHeight }, { width: minWidth, height: minHeight });
newWidth = newSize.newWidth;
newHeight = newSize.newHeight;
if (this.props.grid) {
var newGridWidth = snap(newWidth, this.props.grid[0], this.props.gridGap ? this.props.gridGap[0] : 0);
var newGridHeight = snap(newHeight, this.props.grid[1], this.props.gridGap ? this.props.gridGap[1] : 0);
var gap = this.props.snapGap || 0;
var w = gap === 0 || Math.abs(newGridWidth - newWidth) <= gap ? newGridWidth : newWidth;
var h = gap === 0 || Math.abs(newGridHeight - newHeight) <= gap ? newGridHeight : newHeight;
newWidth = w;
newHeight = h;
}
var delta = {
width: newWidth - original.width,
height: newHeight - original.height,
};
this.delta = delta;
if (width && typeof width === 'string') {
if (width.endsWith('%')) {
var percent = (newWidth / parentSize.width) * 100;
newWidth = "".concat(percent, "%");
}
else if (width.endsWith('vw')) {
var vw = (newWidth / this.window.innerWidth) * 100;
newWidth = "".concat(vw, "vw");
}
else if (width.endsWith('vh')) {
var vh = (newWidth / this.window.innerHeight) * 100;
newWidth = "".concat(vh, "vh");
}
}
if (height && typeof height === 'string') {
if (height.endsWith('%')) {
var percent = (newHeight / parentSize.height) * 100;
newHeight = "".concat(percent, "%");
}
else if (height.endsWith('vw')) {
var vw = (newHeight / this.window.innerWidth) * 100;
newHeight = "".concat(vw, "vw");
}
else if (height.endsWith('vh')) {
var vh = (newHeight / this.window.innerHeight) * 100;
newHeight = "".concat(vh, "vh");
}
}
var newState = {
width: this.createSizeForCssProperty(newWidth, 'width'),
height: this.createSizeForCssProperty(newHeight, 'height'),
};
if (this.flexDir === 'row') {
newState.flexBasis = newState.width;
}
else if (this.flexDir === 'column') {
newState.flexBasis = newState.height;
}
var widthChanged = this.state.width !== newState.width;
var heightChanged = this.state.height !== newState.height;
var flexBaseChanged = this.state.flexBasis !== newState.flexBasis;
var changed = widthChanged || heightChanged || flexBaseChanged;
if (changed) {
// For v18, update state sync
reactDom.flushSync(function () {
_this.setState(newState);
});
}
if (this.props.onResize) {
if (changed) {
this.props.onResize(event, direction, this.resizable, delta);
}
}
};
Resizable.prototype.onMouseUp = function (event) {
var _a, _b;
var _c = this.state, isResizing = _c.isResizing, direction = _c.direction, original = _c.original;
if (!isResizing || !this.resizable) {
return;
}
if (this.props.onResizeStop) {
this.props.onResizeStop(event, direction, this.resizable, this.delta);
}
if (this.props.size) {
this.setState({ width: (_a = this.props.size.width) !== null && _a !== void 0 ? _a : 'auto', height: (_b = this.props.size.height) !== null && _b !== void 0 ? _b : 'auto' });
}
this.unbindEvents();
this.setState({
isResizing: false,
backgroundStyle: __assign(__assign({}, this.state.backgroundStyle), { cursor: 'auto' }),
});
};
Resizable.prototype.updateSize = function (size) {
var _a, _b;
this.setState({ width: (_a = size.width) !== null && _a !== void 0 ? _a : 'auto', height: (_b = size.height) !== null && _b !== void 0 ? _b : 'auto' });
};
Resizable.prototype.renderResizer = function () {
var _this = this;
var _a = this.props, enable = _a.enable, handleStyles = _a.handleStyles, handleClasses = _a.handleClasses, handleWrapperStyle = _a.handleWrapperStyle, handleWrapperClass = _a.handleWrapperClass, handleComponent = _a.handleComponent;
if (!enable) {
return null;
}
var resizers = Object.keys(enable).map(function (dir) {
if (enable[dir] !== false) {
return (jsxRuntime.jsx(Resizer, { direction: dir, onResizeStart: _this.onResizeStart, replaceStyles: handleStyles && handleStyles[dir], className: handleClasses && handleClasses[dir], children: handleComponent && handleComponent[dir] ? handleComponent[dir] : null }, dir));
}
return null;
});
// #93 Wrap the resize box in span (will not break 100% width/height)
return (jsxRuntime.jsx("div", { className: handleWrapperClass, style: handleWrapperStyle, children: resizers }));
};
Resizable.prototype.render = function () {
var _this = this;
var extendsProps = Object.keys(this.props).reduce(function (acc, key) {
if (definedProps.indexOf(key) !== -1) {
return acc;
}
acc[key] = _this.props[key];
return acc;
}, {});
var style = __assign(__assign(__assign({ position: 'relative', userSelect: this.state.isResizing ? 'none' : 'auto' }, this.props.style), this.sizeStyle), { maxWidth: this.props.maxWidth, maxHeight: this.props.maxHeight, minWidth: this.props.minWidth, minHeight: this.props.minHeight, boxSizing: 'border-box', flexShrink: 0 });
if (this.state.flexBasis) {
style.flexBasis = this.state.flexBasis;
}
var Wrapper = this.props.as || 'div';
return (jsxRuntime.jsxs(Wrapper, __assign({ style: style, className: this.props.className }, extendsProps, {
// `ref` is after `extendsProps` to ensure this one wins over a version
// passed in
ref: function (c) {
if (c) {
_this.resizable = c;
}
}, children: [this.state.isResizing && jsxRuntime.jsx("div", { style: this.state.backgroundStyle }), this.props.children, this.renderResizer()] })));
};
Resizable.defaultProps = {
as: 'div',
onResizeStart: function () { },
onResize: function () { },
onResizeStop: function () { },
enable: {
top: true,
right: true,
bottom: true,
left: true,
topRight: true,
bottomRight: true,
bottomLeft: true,
topLeft: true,
},
style: {},
grid: [1, 1],
gridGap: [0, 0],
lockAspectRatio: false,
lockAspectRatioExtraWidth: 0,
lockAspectRatioExtraHeight: 0,
scale: 1,
resizeRatio: 1,
snapGap: 0,
};
return Resizable;
}(react.PureComponent));
exports.Resizable = Resizable;

783
node_modules/re-resizable/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,783 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
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);
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { PureComponent } from 'react';
import { flushSync } from 'react-dom';
import { Resizer } from './resizer';
var DEFAULT_SIZE = {
width: 'auto',
height: 'auto',
};
var clamp = function (n, min, max) { return Math.max(Math.min(n, max), min); };
var snap = function (n, size, gridGap) {
var v = Math.round(n / size);
return v * size + gridGap * (v - 1);
};
var hasDirection = function (dir, target) {
return new RegExp(dir, 'i').test(target);
};
// INFO: In case of window is a Proxy and does not porxy Events correctly, use isTouchEvent & isMouseEvent to distinguish event type instead of `instanceof`.
var isTouchEvent = function (event) {
return Boolean(event.touches && event.touches.length);
};
var isMouseEvent = function (event) {
return Boolean((event.clientX || event.clientX === 0) &&
(event.clientY || event.clientY === 0));
};
var findClosestSnap = function (n, snapArray, snapGap) {
if (snapGap === void 0) { snapGap = 0; }
var closestGapIndex = snapArray.reduce(function (prev, curr, index) { return (Math.abs(curr - n) < Math.abs(snapArray[prev] - n) ? index : prev); }, 0);
var gap = Math.abs(snapArray[closestGapIndex] - n);
return snapGap === 0 || gap < snapGap ? snapArray[closestGapIndex] : n;
};
var getStringSize = function (n) {
n = n.toString();
if (n === 'auto') {
return n;
}
if (n.endsWith('px')) {
return n;
}
if (n.endsWith('%')) {
return n;
}
if (n.endsWith('vh')) {
return n;
}
if (n.endsWith('vw')) {
return n;
}
if (n.endsWith('vmax')) {
return n;
}
if (n.endsWith('vmin')) {
return n;
}
return "".concat(n, "px");
};
var getPixelSize = function (size, parentSize, innerWidth, innerHeight) {
if (size && typeof size === 'string') {
if (size.endsWith('px')) {
return Number(size.replace('px', ''));
}
if (size.endsWith('%')) {
var ratio = Number(size.replace('%', '')) / 100;
return parentSize * ratio;
}
if (size.endsWith('vw')) {
var ratio = Number(size.replace('vw', '')) / 100;
return innerWidth * ratio;
}
if (size.endsWith('vh')) {
var ratio = Number(size.replace('vh', '')) / 100;
return innerHeight * ratio;
}
}
return size;
};
var calculateNewMax = function (parentSize, innerWidth, innerHeight, maxWidth, maxHeight, minWidth, minHeight) {
maxWidth = getPixelSize(maxWidth, parentSize.width, innerWidth, innerHeight);
maxHeight = getPixelSize(maxHeight, parentSize.height, innerWidth, innerHeight);
minWidth = getPixelSize(minWidth, parentSize.width, innerWidth, innerHeight);
minHeight = getPixelSize(minHeight, parentSize.height, innerWidth, innerHeight);
return {
maxWidth: typeof maxWidth === 'undefined' ? undefined : Number(maxWidth),
maxHeight: typeof maxHeight === 'undefined' ? undefined : Number(maxHeight),
minWidth: typeof minWidth === 'undefined' ? undefined : Number(minWidth),
minHeight: typeof minHeight === 'undefined' ? undefined : Number(minHeight),
};
};
/**
* transform T | [T, T] to [T, T]
* @param val
* @returns
*/
// tslint:disable-next-line
var normalizeToPair = function (val) { return (Array.isArray(val) ? val : [val, val]); };
var definedProps = [
'as',
'ref',
'style',
'className',
'grid',
'gridGap',
'snap',
'bounds',
'boundsByDirection',
'size',
'defaultSize',
'minWidth',
'minHeight',
'maxWidth',
'maxHeight',
'lockAspectRatio',
'lockAspectRatioExtraWidth',
'lockAspectRatioExtraHeight',
'enable',
'handleStyles',
'handleClasses',
'handleWrapperStyle',
'handleWrapperClass',
'children',
'onResizeStart',
'onResize',
'onResizeStop',
'handleComponent',
'scale',
'resizeRatio',
'snapGap',
];
// HACK: This class is used to calculate % size.
var baseClassName = '__resizable_base__';
var Resizable = /** @class */ (function (_super) {
__extends(Resizable, _super);
function Resizable(props) {
var _a, _b, _c, _d;
var _this = _super.call(this, props) || this;
_this.ratio = 1;
_this.resizable = null;
// For parent boundary
_this.parentLeft = 0;
_this.parentTop = 0;
// For boundary
_this.resizableLeft = 0;
_this.resizableRight = 0;
_this.resizableTop = 0;
_this.resizableBottom = 0;
// For target boundary
_this.targetLeft = 0;
_this.targetTop = 0;
_this.delta = {
width: 0,
height: 0,
};
_this.appendBase = function () {
if (!_this.resizable || !_this.window) {
return null;
}
var parent = _this.parentNode;
if (!parent) {
return null;
}
var element = _this.window.document.createElement('div');
element.style.width = '100%';
element.style.height = '100%';
element.style.position = 'absolute';
element.style.transform = 'scale(0, 0)';
element.style.left = '0';
element.style.flex = '0 0 100%';
if (element.classList) {
element.classList.add(baseClassName);
}
else {
element.className += baseClassName;
}
parent.appendChild(element);
return element;
};
_this.removeBase = function (base) {
var parent = _this.parentNode;
if (!parent) {
return;
}
parent.removeChild(base);
};
_this.state = {
isResizing: false,
width: (_b = (_a = _this.propsSize) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 'auto',
height: (_d = (_c = _this.propsSize) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 'auto',
direction: 'right',
original: {
x: 0,
y: 0,
width: 0,
height: 0,
},
backgroundStyle: {
height: '100%',
width: '100%',
backgroundColor: 'rgba(0,0,0,0)',
cursor: 'auto',
opacity: 0,
position: 'fixed',
zIndex: 9999,
top: '0',
left: '0',
bottom: '0',
right: '0',
},
flexBasis: undefined,
};
_this.onResizeStart = _this.onResizeStart.bind(_this);
_this.onMouseMove = _this.onMouseMove.bind(_this);
_this.onMouseUp = _this.onMouseUp.bind(_this);
return _this;
}
Object.defineProperty(Resizable.prototype, "parentNode", {
get: function () {
if (!this.resizable) {
return null;
}
return this.resizable.parentNode;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Resizable.prototype, "window", {
get: function () {
if (!this.resizable) {
return null;
}
if (!this.resizable.ownerDocument) {
return null;
}
return this.resizable.ownerDocument.defaultView;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Resizable.prototype, "propsSize", {
get: function () {
return this.props.size || this.props.defaultSize || DEFAULT_SIZE;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Resizable.prototype, "size", {
get: function () {
var width = 0;
var height = 0;
if (this.resizable && this.window) {
var orgWidth = this.resizable.offsetWidth;
var orgHeight = this.resizable.offsetHeight;
// HACK: Set position `relative` to get parent size.
// This is because when re-resizable set `absolute`, I can not get base width correctly.
var orgPosition = this.resizable.style.position;
if (orgPosition !== 'relative') {
this.resizable.style.position = 'relative';
}
// INFO: Use original width or height if set auto.
width = this.resizable.style.width !== 'auto' ? this.resizable.offsetWidth : orgWidth;
height = this.resizable.style.height !== 'auto' ? this.resizable.offsetHeight : orgHeight;
// Restore original position
this.resizable.style.position = orgPosition;
}
return { width: width, height: height };
},
enumerable: false,
configurable: true
});
Object.defineProperty(Resizable.prototype, "sizeStyle", {
get: function () {
var _this = this;
var size = this.props.size;
var getSize = function (key) {
var _a;
if (typeof _this.state[key] === 'undefined' || _this.state[key] === 'auto') {
return 'auto';
}
if (_this.propsSize && _this.propsSize[key] && ((_a = _this.propsSize[key]) === null || _a === void 0 ? void 0 : _a.toString().endsWith('%'))) {
if (_this.state[key].toString().endsWith('%')) {
return _this.state[key].toString();
}
var parentSize = _this.getParentSize();
var value = Number(_this.state[key].toString().replace('px', ''));
var percent = (value / parentSize[key]) * 100;
return "".concat(percent, "%");
}
return getStringSize(_this.state[key]);
};
var width = size && typeof size.width !== 'undefined' && !this.state.isResizing
? getStringSize(size.width)
: getSize('width');
var height = size && typeof size.height !== 'undefined' && !this.state.isResizing
? getStringSize(size.height)
: getSize('height');
return { width: width, height: height };
},
enumerable: false,
configurable: true
});
Resizable.prototype.getParentSize = function () {
if (!this.parentNode) {
if (!this.window) {
return { width: 0, height: 0 };
}
return { width: this.window.innerWidth, height: this.window.innerHeight };
}
var base = this.appendBase();
if (!base) {
return { width: 0, height: 0 };
}
// INFO: To calculate parent width with flex layout
var wrapChanged = false;
var wrap = this.parentNode.style.flexWrap;
if (wrap !== 'wrap') {
wrapChanged = true;
this.parentNode.style.flexWrap = 'wrap';
// HACK: Use relative to get parent padding size
}
base.style.position = 'relative';
base.style.minWidth = '100%';
base.style.minHeight = '100%';
var size = {
width: base.offsetWidth,
height: base.offsetHeight,
};
if (wrapChanged) {
this.parentNode.style.flexWrap = wrap;
}
this.removeBase(base);
return size;
};
Resizable.prototype.bindEvents = function () {
if (this.window) {
this.window.addEventListener('mouseup', this.onMouseUp);
this.window.addEventListener('mousemove', this.onMouseMove);
this.window.addEventListener('mouseleave', this.onMouseUp);
this.window.addEventListener('touchmove', this.onMouseMove, {
capture: true,
passive: false,
});
this.window.addEventListener('touchend', this.onMouseUp);
}
};
Resizable.prototype.unbindEvents = function () {
if (this.window) {
this.window.removeEventListener('mouseup', this.onMouseUp);
this.window.removeEventListener('mousemove', this.onMouseMove);
this.window.removeEventListener('mouseleave', this.onMouseUp);
this.window.removeEventListener('touchmove', this.onMouseMove, true);
this.window.removeEventListener('touchend', this.onMouseUp);
}
};
Resizable.prototype.componentDidMount = function () {
if (!this.resizable || !this.window) {
return;
}
var computedStyle = this.window.getComputedStyle(this.resizable);
this.setState({
width: this.state.width || this.size.width,
height: this.state.height || this.size.height,
flexBasis: computedStyle.flexBasis !== 'auto' ? computedStyle.flexBasis : undefined,
});
};
Resizable.prototype.componentWillUnmount = function () {
if (this.window) {
this.unbindEvents();
}
};
Resizable.prototype.createSizeForCssProperty = function (newSize, kind) {
var propsSize = this.propsSize && this.propsSize[kind];
return this.state[kind] === 'auto' &&
this.state.original[kind] === newSize &&
(typeof propsSize === 'undefined' || propsSize === 'auto')
? 'auto'
: newSize;
};
Resizable.prototype.calculateNewMaxFromBoundary = function (maxWidth, maxHeight) {
var boundsByDirection = this.props.boundsByDirection;
var direction = this.state.direction;
var widthByDirection = boundsByDirection && hasDirection('left', direction);
var heightByDirection = boundsByDirection && hasDirection('top', direction);
var boundWidth;
var boundHeight;
if (this.props.bounds === 'parent') {
var parent_1 = this.parentNode;
if (parent_1) {
boundWidth = widthByDirection
? this.resizableRight - this.parentLeft
: parent_1.offsetWidth + (this.parentLeft - this.resizableLeft);
boundHeight = heightByDirection
? this.resizableBottom - this.parentTop
: parent_1.offsetHeight + (this.parentTop - this.resizableTop);
}
}
else if (this.props.bounds === 'window') {
if (this.window) {
boundWidth = widthByDirection ? this.resizableRight : this.window.innerWidth - this.resizableLeft;
boundHeight = heightByDirection ? this.resizableBottom : this.window.innerHeight - this.resizableTop;
}
}
else if (this.props.bounds) {
boundWidth = widthByDirection
? this.resizableRight - this.targetLeft
: this.props.bounds.offsetWidth + (this.targetLeft - this.resizableLeft);
boundHeight = heightByDirection
? this.resizableBottom - this.targetTop
: this.props.bounds.offsetHeight + (this.targetTop - this.resizableTop);
}
if (boundWidth && Number.isFinite(boundWidth)) {
maxWidth = maxWidth && maxWidth < boundWidth ? maxWidth : boundWidth;
}
if (boundHeight && Number.isFinite(boundHeight)) {
maxHeight = maxHeight && maxHeight < boundHeight ? maxHeight : boundHeight;
}
return { maxWidth: maxWidth, maxHeight: maxHeight };
};
Resizable.prototype.calculateNewSizeFromDirection = function (clientX, clientY) {
var scale = this.props.scale || 1;
var _a = normalizeToPair(this.props.resizeRatio || 1), resizeRatioX = _a[0], resizeRatioY = _a[1];
var _b = this.state, direction = _b.direction, original = _b.original;
var _c = this.props, lockAspectRatio = _c.lockAspectRatio, lockAspectRatioExtraHeight = _c.lockAspectRatioExtraHeight, lockAspectRatioExtraWidth = _c.lockAspectRatioExtraWidth;
var newWidth = original.width;
var newHeight = original.height;
var extraHeight = lockAspectRatioExtraHeight || 0;
var extraWidth = lockAspectRatioExtraWidth || 0;
if (hasDirection('right', direction)) {
newWidth = original.width + ((clientX - original.x) * resizeRatioX) / scale;
if (lockAspectRatio) {
newHeight = (newWidth - extraWidth) / this.ratio + extraHeight;
}
}
if (hasDirection('left', direction)) {
newWidth = original.width - ((clientX - original.x) * resizeRatioX) / scale;
if (lockAspectRatio) {
newHeight = (newWidth - extraWidth) / this.ratio + extraHeight;
}
}
if (hasDirection('bottom', direction)) {
newHeight = original.height + ((clientY - original.y) * resizeRatioY) / scale;
if (lockAspectRatio) {
newWidth = (newHeight - extraHeight) * this.ratio + extraWidth;
}
}
if (hasDirection('top', direction)) {
newHeight = original.height - ((clientY - original.y) * resizeRatioY) / scale;
if (lockAspectRatio) {
newWidth = (newHeight - extraHeight) * this.ratio + extraWidth;
}
}
return { newWidth: newWidth, newHeight: newHeight };
};
Resizable.prototype.calculateNewSizeFromAspectRatio = function (newWidth, newHeight, max, min) {
var _a = this.props, lockAspectRatio = _a.lockAspectRatio, lockAspectRatioExtraHeight = _a.lockAspectRatioExtraHeight, lockAspectRatioExtraWidth = _a.lockAspectRatioExtraWidth;
var computedMinWidth = typeof min.width === 'undefined' ? 10 : min.width;
var computedMaxWidth = typeof max.width === 'undefined' || max.width < 0 ? newWidth : max.width;
var computedMinHeight = typeof min.height === 'undefined' ? 10 : min.height;
var computedMaxHeight = typeof max.height === 'undefined' || max.height < 0 ? newHeight : max.height;
var extraHeight = lockAspectRatioExtraHeight || 0;
var extraWidth = lockAspectRatioExtraWidth || 0;
if (lockAspectRatio) {
var extraMinWidth = (computedMinHeight - extraHeight) * this.ratio + extraWidth;
var extraMaxWidth = (computedMaxHeight - extraHeight) * this.ratio + extraWidth;
var extraMinHeight = (computedMinWidth - extraWidth) / this.ratio + extraHeight;
var extraMaxHeight = (computedMaxWidth - extraWidth) / this.ratio + extraHeight;
var lockedMinWidth = Math.max(computedMinWidth, extraMinWidth);
var lockedMaxWidth = Math.min(computedMaxWidth, extraMaxWidth);
var lockedMinHeight = Math.max(computedMinHeight, extraMinHeight);
var lockedMaxHeight = Math.min(computedMaxHeight, extraMaxHeight);
newWidth = clamp(newWidth, lockedMinWidth, lockedMaxWidth);
newHeight = clamp(newHeight, lockedMinHeight, lockedMaxHeight);
}
else {
newWidth = clamp(newWidth, computedMinWidth, computedMaxWidth);
newHeight = clamp(newHeight, computedMinHeight, computedMaxHeight);
}
return { newWidth: newWidth, newHeight: newHeight };
};
Resizable.prototype.setBoundingClientRect = function () {
var adjustedScale = 1 / (this.props.scale || 1);
// For parent boundary
if (this.props.bounds === 'parent') {
var parent_2 = this.parentNode;
if (parent_2) {
var parentRect = parent_2.getBoundingClientRect();
this.parentLeft = parentRect.left * adjustedScale;
this.parentTop = parentRect.top * adjustedScale;
}
}
// For target(html element) boundary
if (this.props.bounds && typeof this.props.bounds !== 'string') {
var targetRect = this.props.bounds.getBoundingClientRect();
this.targetLeft = targetRect.left * adjustedScale;
this.targetTop = targetRect.top * adjustedScale;
}
// For boundary
if (this.resizable) {
var _a = this.resizable.getBoundingClientRect(), left = _a.left, top_1 = _a.top, right = _a.right, bottom = _a.bottom;
this.resizableLeft = left * adjustedScale;
this.resizableRight = right * adjustedScale;
this.resizableTop = top_1 * adjustedScale;
this.resizableBottom = bottom * adjustedScale;
}
};
Resizable.prototype.onResizeStart = function (event, direction) {
if (!this.resizable || !this.window) {
return;
}
var clientX = 0;
var clientY = 0;
if (event.nativeEvent && isMouseEvent(event.nativeEvent)) {
clientX = event.nativeEvent.clientX;
clientY = event.nativeEvent.clientY;
}
else if (event.nativeEvent && isTouchEvent(event.nativeEvent)) {
clientX = event.nativeEvent.touches[0].clientX;
clientY = event.nativeEvent.touches[0].clientY;
}
if (this.props.onResizeStart) {
if (this.resizable) {
var startResize = this.props.onResizeStart(event, direction, this.resizable);
if (startResize === false) {
return;
}
}
}
// Fix #168
if (this.props.size) {
if (typeof this.props.size.height !== 'undefined' && this.props.size.height !== this.state.height) {
this.setState({ height: this.props.size.height });
}
if (typeof this.props.size.width !== 'undefined' && this.props.size.width !== this.state.width) {
this.setState({ width: this.props.size.width });
}
}
// For lockAspectRatio case
this.ratio =
typeof this.props.lockAspectRatio === 'number' ? this.props.lockAspectRatio : this.size.width / this.size.height;
var flexBasis;
var computedStyle = this.window.getComputedStyle(this.resizable);
if (computedStyle.flexBasis !== 'auto') {
var parent_3 = this.parentNode;
if (parent_3) {
var dir = this.window.getComputedStyle(parent_3).flexDirection;
this.flexDir = dir.startsWith('row') ? 'row' : 'column';
flexBasis = computedStyle.flexBasis;
}
}
// For boundary
this.setBoundingClientRect();
this.bindEvents();
var state = {
original: {
x: clientX,
y: clientY,
width: this.size.width,
height: this.size.height,
},
isResizing: true,
backgroundStyle: __assign(__assign({}, this.state.backgroundStyle), { cursor: this.window.getComputedStyle(event.target).cursor || 'auto' }),
direction: direction,
flexBasis: flexBasis,
};
this.setState(state);
};
Resizable.prototype.onMouseMove = function (event) {
var _this = this;
if (!this.state.isResizing || !this.resizable || !this.window) {
return;
}
if (this.window.TouchEvent && isTouchEvent(event)) {
try {
event.preventDefault();
event.stopPropagation();
}
catch (e) {
// Ignore on fail
}
}
var _a = this.props, maxWidth = _a.maxWidth, maxHeight = _a.maxHeight, minWidth = _a.minWidth, minHeight = _a.minHeight;
var clientX = isTouchEvent(event) ? event.touches[0].clientX : event.clientX;
var clientY = isTouchEvent(event) ? event.touches[0].clientY : event.clientY;
var _b = this.state, direction = _b.direction, original = _b.original, width = _b.width, height = _b.height;
var parentSize = this.getParentSize();
var max = calculateNewMax(parentSize, this.window.innerWidth, this.window.innerHeight, maxWidth, maxHeight, minWidth, minHeight);
maxWidth = max.maxWidth;
maxHeight = max.maxHeight;
minWidth = max.minWidth;
minHeight = max.minHeight;
// Calculate new size
var _c = this.calculateNewSizeFromDirection(clientX, clientY), newHeight = _c.newHeight, newWidth = _c.newWidth;
// Calculate max size from boundary settings
var boundaryMax = this.calculateNewMaxFromBoundary(maxWidth, maxHeight);
if (this.props.snap && this.props.snap.x) {
newWidth = findClosestSnap(newWidth, this.props.snap.x, this.props.snapGap);
}
if (this.props.snap && this.props.snap.y) {
newHeight = findClosestSnap(newHeight, this.props.snap.y, this.props.snapGap);
}
// Calculate new size from aspect ratio
var newSize = this.calculateNewSizeFromAspectRatio(newWidth, newHeight, { width: boundaryMax.maxWidth, height: boundaryMax.maxHeight }, { width: minWidth, height: minHeight });
newWidth = newSize.newWidth;
newHeight = newSize.newHeight;
if (this.props.grid) {
var newGridWidth = snap(newWidth, this.props.grid[0], this.props.gridGap ? this.props.gridGap[0] : 0);
var newGridHeight = snap(newHeight, this.props.grid[1], this.props.gridGap ? this.props.gridGap[1] : 0);
var gap = this.props.snapGap || 0;
var w = gap === 0 || Math.abs(newGridWidth - newWidth) <= gap ? newGridWidth : newWidth;
var h = gap === 0 || Math.abs(newGridHeight - newHeight) <= gap ? newGridHeight : newHeight;
newWidth = w;
newHeight = h;
}
var delta = {
width: newWidth - original.width,
height: newHeight - original.height,
};
this.delta = delta;
if (width && typeof width === 'string') {
if (width.endsWith('%')) {
var percent = (newWidth / parentSize.width) * 100;
newWidth = "".concat(percent, "%");
}
else if (width.endsWith('vw')) {
var vw = (newWidth / this.window.innerWidth) * 100;
newWidth = "".concat(vw, "vw");
}
else if (width.endsWith('vh')) {
var vh = (newWidth / this.window.innerHeight) * 100;
newWidth = "".concat(vh, "vh");
}
}
if (height && typeof height === 'string') {
if (height.endsWith('%')) {
var percent = (newHeight / parentSize.height) * 100;
newHeight = "".concat(percent, "%");
}
else if (height.endsWith('vw')) {
var vw = (newHeight / this.window.innerWidth) * 100;
newHeight = "".concat(vw, "vw");
}
else if (height.endsWith('vh')) {
var vh = (newHeight / this.window.innerHeight) * 100;
newHeight = "".concat(vh, "vh");
}
}
var newState = {
width: this.createSizeForCssProperty(newWidth, 'width'),
height: this.createSizeForCssProperty(newHeight, 'height'),
};
if (this.flexDir === 'row') {
newState.flexBasis = newState.width;
}
else if (this.flexDir === 'column') {
newState.flexBasis = newState.height;
}
var widthChanged = this.state.width !== newState.width;
var heightChanged = this.state.height !== newState.height;
var flexBaseChanged = this.state.flexBasis !== newState.flexBasis;
var changed = widthChanged || heightChanged || flexBaseChanged;
if (changed) {
// For v18, update state sync
flushSync(function () {
_this.setState(newState);
});
}
if (this.props.onResize) {
if (changed) {
this.props.onResize(event, direction, this.resizable, delta);
}
}
};
Resizable.prototype.onMouseUp = function (event) {
var _a, _b;
var _c = this.state, isResizing = _c.isResizing, direction = _c.direction, original = _c.original;
if (!isResizing || !this.resizable) {
return;
}
if (this.props.onResizeStop) {
this.props.onResizeStop(event, direction, this.resizable, this.delta);
}
if (this.props.size) {
this.setState({ width: (_a = this.props.size.width) !== null && _a !== void 0 ? _a : 'auto', height: (_b = this.props.size.height) !== null && _b !== void 0 ? _b : 'auto' });
}
this.unbindEvents();
this.setState({
isResizing: false,
backgroundStyle: __assign(__assign({}, this.state.backgroundStyle), { cursor: 'auto' }),
});
};
Resizable.prototype.updateSize = function (size) {
var _a, _b;
this.setState({ width: (_a = size.width) !== null && _a !== void 0 ? _a : 'auto', height: (_b = size.height) !== null && _b !== void 0 ? _b : 'auto' });
};
Resizable.prototype.renderResizer = function () {
var _this = this;
var _a = this.props, enable = _a.enable, handleStyles = _a.handleStyles, handleClasses = _a.handleClasses, handleWrapperStyle = _a.handleWrapperStyle, handleWrapperClass = _a.handleWrapperClass, handleComponent = _a.handleComponent;
if (!enable) {
return null;
}
var resizers = Object.keys(enable).map(function (dir) {
if (enable[dir] !== false) {
return (_jsx(Resizer, { direction: dir, onResizeStart: _this.onResizeStart, replaceStyles: handleStyles && handleStyles[dir], className: handleClasses && handleClasses[dir], children: handleComponent && handleComponent[dir] ? handleComponent[dir] : null }, dir));
}
return null;
});
// #93 Wrap the resize box in span (will not break 100% width/height)
return (_jsx("div", { className: handleWrapperClass, style: handleWrapperStyle, children: resizers }));
};
Resizable.prototype.render = function () {
var _this = this;
var extendsProps = Object.keys(this.props).reduce(function (acc, key) {
if (definedProps.indexOf(key) !== -1) {
return acc;
}
acc[key] = _this.props[key];
return acc;
}, {});
var style = __assign(__assign(__assign({ position: 'relative', userSelect: this.state.isResizing ? 'none' : 'auto' }, this.props.style), this.sizeStyle), { maxWidth: this.props.maxWidth, maxHeight: this.props.maxHeight, minWidth: this.props.minWidth, minHeight: this.props.minHeight, boxSizing: 'border-box', flexShrink: 0 });
if (this.state.flexBasis) {
style.flexBasis = this.state.flexBasis;
}
var Wrapper = this.props.as || 'div';
return (_jsxs(Wrapper, __assign({ style: style, className: this.props.className }, extendsProps, {
// `ref` is after `extendsProps` to ensure this one wins over a version
// passed in
ref: function (c) {
if (c) {
_this.resizable = c;
}
}, children: [this.state.isResizing && _jsx("div", { style: this.state.backgroundStyle }), this.props.children, this.renderResizer()] })));
};
Resizable.defaultProps = {
as: 'div',
onResizeStart: function () { },
onResize: function () { },
onResizeStop: function () { },
enable: {
top: true,
right: true,
bottom: true,
left: true,
topRight: true,
bottomRight: true,
bottomLeft: true,
topLeft: true,
},
style: {},
grid: [1, 1],
gridGap: [0, 0],
lockAspectRatio: false,
lockAspectRatioExtraWidth: 0,
lockAspectRatioExtraHeight: 0,
scale: 1,
resizeRatio: 1,
snapGap: 0,
};
return Resizable;
}(PureComponent));
export { Resizable };

1
node_modules/re-resizable/lib/index.test.d.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export {};

1092
node_modules/re-resizable/lib/index.test.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

10
node_modules/re-resizable/lib/resizer.d.ts generated vendored Normal file
View File

@@ -0,0 +1,10 @@
export type Direction = 'top' | 'right' | 'bottom' | 'left' | 'topRight' | 'bottomRight' | 'bottomLeft' | 'topLeft';
export type OnStartCallback = (e: React.MouseEvent<HTMLDivElement> | React.TouchEvent<HTMLDivElement>, dir: Direction) => void;
export interface Props {
direction: Direction;
className?: string;
replaceStyles?: React.CSSProperties;
onResizeStart: OnStartCallback;
children: React.ReactNode;
}
export declare const Resizer: import("react").MemoExoticComponent<(props: Props) => import("react/jsx-runtime").JSX.Element>;

56
node_modules/re-resizable/lib/resizer.js generated vendored Normal file
View File

@@ -0,0 +1,56 @@
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);
};
import { jsx as _jsx } from "react/jsx-runtime";
import { memo, useCallback, useMemo } from 'react';
var rowSizeBase = {
width: '100%',
height: '10px',
top: '0px',
left: '0px',
cursor: 'row-resize',
};
var colSizeBase = {
width: '10px',
height: '100%',
top: '0px',
left: '0px',
cursor: 'col-resize',
};
var edgeBase = {
width: '20px',
height: '20px',
position: 'absolute',
zIndex: 1,
};
var styles = {
top: __assign(__assign({}, rowSizeBase), { top: '-5px' }),
right: __assign(__assign({}, colSizeBase), { left: undefined, right: '-5px' }),
bottom: __assign(__assign({}, rowSizeBase), { top: undefined, bottom: '-5px' }),
left: __assign(__assign({}, colSizeBase), { left: '-5px' }),
topRight: __assign(__assign({}, edgeBase), { right: '-10px', top: '-10px', cursor: 'ne-resize' }),
bottomRight: __assign(__assign({}, edgeBase), { right: '-10px', bottom: '-10px', cursor: 'se-resize' }),
bottomLeft: __assign(__assign({}, edgeBase), { left: '-10px', bottom: '-10px', cursor: 'sw-resize' }),
topLeft: __assign(__assign({}, edgeBase), { left: '-10px', top: '-10px', cursor: 'nw-resize' }),
};
export var Resizer = memo(function (props) {
var onResizeStart = props.onResizeStart, direction = props.direction, children = props.children, replaceStyles = props.replaceStyles, className = props.className;
var onMouseDown = useCallback(function (e) {
onResizeStart(e, direction);
}, [onResizeStart, direction]);
var onTouchStart = useCallback(function (e) {
onResizeStart(e, direction);
}, [onResizeStart, direction]);
var style = useMemo(function () {
return __assign(__assign({ position: 'absolute', userSelect: 'none' }, styles[direction]), (replaceStyles !== null && replaceStyles !== void 0 ? replaceStyles : {}));
}, [replaceStyles, direction]);
return (_jsx("div", { className: className || undefined, style: style, onMouseDown: onMouseDown, onTouchStart: onTouchStart, children: children }));
});

104
node_modules/re-resizable/package.json generated vendored Normal file
View File

@@ -0,0 +1,104 @@
{
"name": "re-resizable",
"version": "6.11.2",
"description": "Resizable component for React.",
"title": "re-resizable",
"main": "./lib/index.es5.js",
"module": "./lib/index.js",
"jsnext:main": "./lib/index.js",
"keywords": [
"react",
"resize",
"resizable",
"component"
],
"scripts": {
"lint": "tslint -c tslint.json src/index.tsx",
"tsc": "tsc -p tsconfig.json --skipLibCheck",
"build:prod:main": "rollup -c scripts/prod.js",
"build:prod:es5": "rollup -c scripts/prod.es5.js",
"build": "npm-run-all --serial build:prod:* && tsc",
"start": "npm-run-all --parallel storybook",
"test": "npm run test-ct",
"test:ci": "npm run flow && npm run build",
"prepublish": "npm run build",
"format": "prettier --write '**/*.{tsx,ts}'",
"format:ci": "prettier '**/*.{tsx,ts}'",
"storybook": "start-storybook -p 6066",
"build-storybook": "build-storybook",
"deploy": "npm run build-storybook && gh-pages -d storybook-static",
"test-ct": "playwright test -c playwright-ct.config.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/bokuweb/react-resizable-box.git"
},
"author": "bokuweb",
"license": "MIT",
"bugs": {
"url": "https://github.com/bokuweb/react-resizable-box/issues"
},
"homepage": "https://github.com/bokuweb/react-resizable-box",
"devDependencies": {
"@babel/cli": "7.11.6",
"@babel/core": "7.11.6",
"@babel/eslint-parser": "7.11.0",
"@babel/plugin-proposal-class-properties": "7.10.4",
"@babel/plugin-transform-modules-commonjs": "7.10.4",
"@babel/preset-react": "7.10.4",
"@babel/preset-typescript": "7.10.4",
"@babel/traverse": "7.23.2",
"@babel/types": "7.11.5",
"@emotion/core": "10.0.35",
"@playwright/experimental-ct-react": "^1.43.1",
"@storybook/addon-info": "5.3.21",
"@storybook/addon-options": "5.3.21",
"@storybook/react": "8.5.8",
"@types/node": "22.13.5",
"@types/react": "19.0.10",
"@types/react-dom": "19.0.4",
"@types/sinon": "17.0.4",
"babel-core": "7.0.0-bridge.0",
"babel-loader": "9.2.1",
"babel-plugin-external-helpers": "6.22.0",
"babel-plugin-transform-class-properties": "6.24.1",
"babel-plugin-transform-object-assign": "6.22.0",
"babel-plugin-transform-object-rest-spread": "6.26.0",
"babel-polyfill": "6.26.0",
"babel-preset-env": "1.7.0",
"babel-preset-es2015": "6.24.1",
"babel-preset-flow": "6.23.0",
"babel-preset-react": "6.24.1",
"babel-register": "6.26.0",
"cross-env": "7.0.3",
"gh-pages": "5.0.0",
"npm-run-all2": "5.0.2",
"playwright-core": "^1.43.1",
"prettier": "1.19.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"rollup": "1.32.1",
"rollup-plugin-babel": "4.4.0",
"rollup-plugin-commonjs": "10.1.0",
"rollup-plugin-node-globals": "1.4.0",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-replace": "2.2.0",
"rollup-plugin-typescript2": "0.27.3",
"rollup-watch": "4.3.1",
"sinon": "9.0.3",
"tslint": "6.1.3",
"tslint-config-google": "1.0.1",
"tslint-config-prettier": "1.18.0",
"tslint-plugin-prettier": "2.3.0",
"typescript": "5.7.3"
},
"typings": "./lib/index.d.ts",
"types": "./lib/index.d.ts",
"files": [
"lib"
],
"peerDependencies": {
"react": "^16.13.1 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"react-dom": "^16.13.1 || ^17.0.0 || ^18.0.0 || ^19.0.0"
}
}