first commit
This commit is contained in:
6
frontend/node_modules/@rc-component/tour/es/hooks/useClosable.d.ts
generated
vendored
Normal file
6
frontend/node_modules/@rc-component/tour/es/hooks/useClosable.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import * as React from 'react';
|
||||
import type { TourProps } from '../interface';
|
||||
import type { TourStepInfo } from '../TourStep';
|
||||
export declare function useClosable(stepClosable: TourStepInfo['closable'], stepCloseIcon: TourStepInfo['closeIcon'], closable: TourProps['closable'], closeIcon: TourProps['closeIcon']): {
|
||||
closeIcon?: React.ReactNode;
|
||||
} & React.AriaAttributes;
|
||||
37
frontend/node_modules/@rc-component/tour/es/hooks/useClosable.js
generated
vendored
Normal file
37
frontend/node_modules/@rc-component/tour/es/hooks/useClosable.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
||||
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
||||
import * as React from 'react';
|
||||
function isConfigObj(closable) {
|
||||
return closable !== null && _typeof(closable) === 'object';
|
||||
}
|
||||
/**
|
||||
* Convert `closable` to ClosableConfig.
|
||||
* When `preset` is true, will auto fill ClosableConfig with default value.
|
||||
*/
|
||||
function getClosableConfig(closable, closeIcon, preset) {
|
||||
if (closable === false || closeIcon === false && (!isConfigObj(closable) || !closable.closeIcon)) {
|
||||
return null;
|
||||
}
|
||||
var mergedCloseIcon = typeof closeIcon !== 'boolean' ? closeIcon : undefined;
|
||||
if (isConfigObj(closable)) {
|
||||
var _closable$closeIcon;
|
||||
return _objectSpread(_objectSpread({}, closable), {}, {
|
||||
closeIcon: (_closable$closeIcon = closable.closeIcon) !== null && _closable$closeIcon !== void 0 ? _closable$closeIcon : mergedCloseIcon
|
||||
});
|
||||
}
|
||||
|
||||
// When StepClosable no need auto fill, but RootClosable need this.
|
||||
return preset || closable || closeIcon ? {
|
||||
closeIcon: mergedCloseIcon
|
||||
} : 'empty';
|
||||
}
|
||||
export function useClosable(stepClosable, stepCloseIcon, closable, closeIcon) {
|
||||
return React.useMemo(function () {
|
||||
var stepClosableConfig = getClosableConfig(stepClosable, stepCloseIcon, false);
|
||||
var rootClosableConfig = getClosableConfig(closable, closeIcon, true);
|
||||
if (stepClosableConfig !== 'empty') {
|
||||
return stepClosableConfig;
|
||||
}
|
||||
return rootClosableConfig;
|
||||
}, [closable, closeIcon, stepClosable, stepCloseIcon]);
|
||||
}
|
||||
13
frontend/node_modules/@rc-component/tour/es/hooks/useTarget.d.ts
generated
vendored
Normal file
13
frontend/node_modules/@rc-component/tour/es/hooks/useTarget.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { TourStepInfo } from '..';
|
||||
export interface Gap {
|
||||
offset?: number | [number, number];
|
||||
radius?: number;
|
||||
}
|
||||
export interface PosInfo {
|
||||
left: number;
|
||||
top: number;
|
||||
height: number;
|
||||
width: number;
|
||||
radius: number;
|
||||
}
|
||||
export default function useTarget(target: TourStepInfo['target'], open: boolean, gap?: Gap, scrollIntoViewOptions?: boolean | ScrollIntoViewOptions): [PosInfo, HTMLElement];
|
||||
86
frontend/node_modules/@rc-component/tour/es/hooks/useTarget.js
generated
vendored
Normal file
86
frontend/node_modules/@rc-component/tour/es/hooks/useTarget.js
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
||||
import useEvent from "rc-util/es/hooks/useEvent";
|
||||
import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
|
||||
import { useMemo, useState } from 'react';
|
||||
import { isInViewPort } from "../util";
|
||||
function isValidNumber(val) {
|
||||
return typeof val === 'number' && !Number.isNaN(val);
|
||||
}
|
||||
export default function useTarget(target, open, gap, scrollIntoViewOptions) {
|
||||
// ========================= Target =========================
|
||||
// We trade `undefined` as not get target by function yet.
|
||||
// `null` as empty target.
|
||||
var _useState = useState(undefined),
|
||||
_useState2 = _slicedToArray(_useState, 2),
|
||||
targetElement = _useState2[0],
|
||||
setTargetElement = _useState2[1];
|
||||
useLayoutEffect(function () {
|
||||
var nextElement = typeof target === 'function' ? target() : target;
|
||||
setTargetElement(nextElement || null);
|
||||
});
|
||||
|
||||
// ========================= Align ==========================
|
||||
var _useState3 = useState(null),
|
||||
_useState4 = _slicedToArray(_useState3, 2),
|
||||
posInfo = _useState4[0],
|
||||
setPosInfo = _useState4[1];
|
||||
var updatePos = useEvent(function () {
|
||||
if (targetElement) {
|
||||
// Exist target element. We should scroll and get target position
|
||||
if (!isInViewPort(targetElement) && open) {
|
||||
targetElement.scrollIntoView(scrollIntoViewOptions);
|
||||
}
|
||||
var _targetElement$getBou = targetElement.getBoundingClientRect(),
|
||||
left = _targetElement$getBou.left,
|
||||
top = _targetElement$getBou.top,
|
||||
width = _targetElement$getBou.width,
|
||||
height = _targetElement$getBou.height;
|
||||
var nextPosInfo = {
|
||||
left: left,
|
||||
top: top,
|
||||
width: width,
|
||||
height: height,
|
||||
radius: 0
|
||||
};
|
||||
setPosInfo(function (origin) {
|
||||
if (JSON.stringify(origin) !== JSON.stringify(nextPosInfo)) {
|
||||
return nextPosInfo;
|
||||
}
|
||||
return origin;
|
||||
});
|
||||
} else {
|
||||
// Not exist target which means we just show in center
|
||||
setPosInfo(null);
|
||||
}
|
||||
});
|
||||
var getGapOffset = function getGapOffset(index) {
|
||||
var _ref;
|
||||
return (_ref = Array.isArray(gap === null || gap === void 0 ? void 0 : gap.offset) ? gap === null || gap === void 0 ? void 0 : gap.offset[index] : gap === null || gap === void 0 ? void 0 : gap.offset) !== null && _ref !== void 0 ? _ref : 6;
|
||||
};
|
||||
useLayoutEffect(function () {
|
||||
updatePos();
|
||||
// update when window resize
|
||||
window.addEventListener('resize', updatePos);
|
||||
return function () {
|
||||
window.removeEventListener('resize', updatePos);
|
||||
};
|
||||
}, [targetElement, open, updatePos]);
|
||||
|
||||
// ======================== PosInfo =========================
|
||||
var mergedPosInfo = useMemo(function () {
|
||||
if (!posInfo) {
|
||||
return posInfo;
|
||||
}
|
||||
var gapOffsetX = getGapOffset(0);
|
||||
var gapOffsetY = getGapOffset(1);
|
||||
var gapRadius = isValidNumber(gap === null || gap === void 0 ? void 0 : gap.radius) ? gap === null || gap === void 0 ? void 0 : gap.radius : 2;
|
||||
return {
|
||||
left: posInfo.left - gapOffsetX,
|
||||
top: posInfo.top - gapOffsetY,
|
||||
width: posInfo.width + gapOffsetX * 2,
|
||||
height: posInfo.height + gapOffsetY * 2,
|
||||
radius: gapRadius
|
||||
};
|
||||
}, [posInfo, gap]);
|
||||
return [mergedPosInfo, targetElement];
|
||||
}
|
||||
Reference in New Issue
Block a user