@kine-design/core 0.0.1-beta.1 → 0.0.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/style/global.css +1 -0
- package/assets/style/var/Wuxing.css +71 -0
- package/assets/style/var.css +23 -0
- package/components/base/affix/api.ts +16 -0
- package/components/base/affix/index.ts +15 -0
- package/components/base/affix/props.d.ts +34 -0
- package/components/base/affix/useAffix.ts +123 -0
- package/components/base/alert/api.ts +18 -0
- package/components/base/alert/index.ts +15 -0
- package/components/base/alert/props.d.ts +50 -0
- package/components/base/anchor/api.ts +20 -0
- package/components/base/anchor/index.ts +16 -0
- package/components/base/anchor/props.d.ts +46 -0
- package/components/base/anchor/useAnchor.ts +83 -0
- package/components/base/autoComplete/api.ts +24 -0
- package/components/base/autoComplete/index.ts +17 -0
- package/components/base/autoComplete/props.d.ts +75 -0
- package/components/base/autoComplete/useAutoComplete.ts +149 -0
- package/components/base/avatar/api.ts +17 -0
- package/components/base/avatar/avatar.css +61 -0
- package/components/base/avatar/index.ts +14 -0
- package/components/base/avatar/props.d.ts +37 -0
- package/components/base/backTop/api.ts +17 -0
- package/components/base/backTop/index.ts +15 -0
- package/components/base/backTop/props.d.ts +38 -0
- package/components/base/backTop/useBackTop.ts +62 -0
- package/components/base/badge/api.ts +22 -0
- package/components/base/badge/index.ts +15 -0
- package/components/base/badge/props.d.ts +50 -0
- package/components/base/button/api.ts +28 -0
- package/components/base/button/button.css +34 -0
- package/components/base/button/index.ts +16 -0
- package/components/base/button/props.d.ts +64 -0
- package/components/base/button/useButton.ts +37 -0
- package/components/base/card/api.ts +17 -0
- package/components/base/card/index.ts +15 -0
- package/components/base/card/props.d.ts +37 -0
- package/components/base/carousel/api.ts +28 -0
- package/components/base/carousel/index.ts +17 -0
- package/components/base/carousel/props.d.ts +72 -0
- package/components/base/carousel/useCarousel.ts +151 -0
- package/components/base/cascader/api.ts +23 -0
- package/components/base/cascader/index.ts +18 -0
- package/components/base/cascader/props.d.ts +103 -0
- package/components/base/cascader/useCascader.ts +334 -0
- package/components/base/checkbox/api.ts +24 -0
- package/components/base/checkbox/checkbox.css +0 -0
- package/components/base/checkbox/index.ts +16 -0
- package/components/base/checkbox/props.d.ts +77 -0
- package/components/base/checkbox/useCheckbox.ts +42 -0
- package/components/base/collapse/api.ts +21 -0
- package/components/base/collapse/index.ts +16 -0
- package/components/base/collapse/props.d.ts +45 -0
- package/components/base/collapse/useCollapse.ts +80 -0
- package/components/base/datePicker/api.ts +18 -0
- package/components/base/datePicker/index.ts +19 -0
- package/components/base/datePicker/props.d.ts +60 -0
- package/components/base/datePicker/useDatePicker.ts +392 -0
- package/components/base/divider/api.ts +15 -0
- package/components/base/divider/divider.css +11 -0
- package/components/base/divider/index.ts +15 -0
- package/components/base/divider/props.d.ts +30 -0
- package/components/base/dropdown/api.ts +33 -0
- package/components/base/dropdown/index.ts +16 -0
- package/components/base/dropdown/props.d.ts +60 -0
- package/components/base/dropdown/useDropdown.ts +123 -0
- package/components/base/empty/api.ts +15 -0
- package/components/base/empty/index.ts +15 -0
- package/components/base/empty/props.d.ts +26 -0
- package/components/base/image/api.ts +25 -0
- package/components/base/image/index.ts +18 -0
- package/components/base/image/props.d.ts +67 -0
- package/components/base/image/useImage.ts +119 -0
- package/components/base/input/api.ts +19 -0
- package/components/base/input/index.ts +16 -0
- package/components/base/input/input.css +19 -0
- package/components/base/input/props.d.ts +60 -0
- package/components/base/input/useInput.ts +53 -0
- package/components/base/inputNumber/api.ts +21 -0
- package/components/base/inputNumber/index.ts +15 -0
- package/components/base/inputNumber/props.d.ts +64 -0
- package/components/base/inputNumber/useInputNumber.ts +140 -0
- package/components/base/li/api.ts +15 -0
- package/components/base/li/index.ts +13 -0
- package/components/base/li/props.d.ts +30 -0
- package/components/base/list/api.ts +16 -0
- package/components/base/list/index.ts +15 -0
- package/components/base/list/props.d.ts +33 -0
- package/components/base/list/useList.ts +36 -0
- package/components/base/loading/api.ts +17 -0
- package/components/base/loading/index.ts +15 -0
- package/components/base/loading/props.d.ts +38 -0
- package/components/base/popover/api.ts +28 -0
- package/components/base/popover/index.ts +15 -0
- package/components/base/popover/props.d.ts +73 -0
- package/components/base/popover/usePopover.ts +188 -0
- package/components/base/progress/api.ts +18 -0
- package/components/base/progress/index.ts +15 -0
- package/components/base/progress/props.d.ts +53 -0
- package/components/base/progress/useProgress.ts +28 -0
- package/components/base/radio/api.ts +19 -0
- package/components/base/radio/index.ts +19 -0
- package/components/base/radio/props.d.ts +59 -0
- package/components/base/radio/useRadio.ts +11 -0
- package/components/base/rate/api.ts +18 -0
- package/components/base/rate/index.ts +15 -0
- package/components/base/rate/props.d.ts +49 -0
- package/components/base/rate/useRate.ts +75 -0
- package/components/base/result/api.ts +20 -0
- package/components/base/result/index.ts +15 -0
- package/components/base/result/props.d.ts +36 -0
- package/components/base/select/api.ts +31 -0
- package/components/base/select/index.ts +18 -0
- package/components/base/select/props.d.ts +132 -0
- package/components/base/select/select.css +7 -0
- package/components/base/select/useSelect.ts +280 -0
- package/components/base/select/useSelectTools.ts +60 -0
- package/components/base/skeleton/api.ts +18 -0
- package/components/base/skeleton/index.ts +15 -0
- package/components/base/skeleton/props.d.ts +41 -0
- package/components/base/slider/api.ts +20 -0
- package/components/base/slider/index.ts +15 -0
- package/components/base/slider/props.d.ts +65 -0
- package/components/base/slider/useSlider.ts +83 -0
- package/components/base/space/api.ts +17 -0
- package/components/base/space/index.ts +15 -0
- package/components/base/space/props.d.ts +39 -0
- package/components/base/steps/api.ts +30 -0
- package/components/base/steps/index.ts +22 -0
- package/components/base/steps/props.d.ts +88 -0
- package/components/base/steps/useSteps.ts +101 -0
- package/components/base/switch/api.ts +22 -0
- package/components/base/switch/index.ts +17 -0
- package/components/base/switch/props.d.ts +66 -0
- package/components/base/switch/useSwitch.tsx +79 -0
- package/components/base/tabs/api.ts +23 -0
- package/components/base/tabs/index.ts +18 -0
- package/components/base/tabs/props.d.ts +41 -0
- package/components/base/tabs/useTabs.ts +66 -0
- package/components/base/tag/api.ts +17 -0
- package/components/base/tag/index.ts +13 -0
- package/components/base/tag/props.d.ts +49 -0
- package/components/base/timePicker/api.ts +21 -0
- package/components/base/timePicker/index.ts +18 -0
- package/components/base/timePicker/props.d.ts +66 -0
- package/components/base/timePicker/useTimePicker.ts +161 -0
- package/components/base/timeline/api.ts +24 -0
- package/components/base/timeline/index.ts +16 -0
- package/components/base/timeline/props.d.ts +60 -0
- package/components/base/tooltip/api.ts +19 -0
- package/components/base/tooltip/index.ts +17 -0
- package/components/base/tooltip/props.d.ts +34 -0
- package/components/base/tooltip/useTooltip.ts +89 -0
- package/components/base/transfer/api.ts +18 -0
- package/components/base/transfer/index.ts +17 -0
- package/components/base/transfer/props.d.ts +63 -0
- package/components/base/transfer/useTransfer.ts +207 -0
- package/components/base/tree/api.ts +47 -0
- package/components/base/tree/index.ts +29 -0
- package/components/base/tree/props.d.ts +108 -0
- package/components/base/tree/tree.ts +263 -0
- package/components/base/tree/useTree.ts +114 -0
- package/components/message/confirm/api.ts +21 -0
- package/components/message/confirm/index.ts +15 -0
- package/components/message/confirm/props.d.ts +69 -0
- package/components/message/dialog/api.ts +19 -0
- package/components/message/dialog/index.ts +15 -0
- package/components/message/dialog/props.d.ts +55 -0
- package/components/message/drawer/api.ts +32 -0
- package/components/message/drawer/index.ts +15 -0
- package/components/message/drawer/props.d.ts +73 -0
- package/components/message/message/api.ts +27 -0
- package/components/message/message/index.ts +20 -0
- package/components/message/message/props.d.ts +54 -0
- package/components/message/message/useMessage.ts +61 -0
- package/components/message/notification/api.ts +23 -0
- package/components/message/notification/index.ts +19 -0
- package/components/message/notification/props.d.ts +64 -0
- package/components/message/notification/useNotification.ts +79 -0
- package/components/message/popover/MPopover.tsx +94 -0
- package/components/message/popover/api.ts +54 -0
- package/components/message/popover/index.ts +17 -0
- package/components/message/popover/popover.css +21 -0
- package/components/message/popover/props.d.ts +76 -0
- package/components/message/popover/usePopover.ts +230 -0
- package/components/other/darkMode/api.ts +17 -0
- package/components/other/darkMode/index.ts +17 -0
- package/components/other/darkMode/props.d.ts +37 -0
- package/components/other/darkMode/useDarkMode.ts +129 -0
- package/components/template/border/api.ts +18 -0
- package/components/template/border/index.ts +15 -0
- package/components/template/border/props.d.ts +41 -0
- package/components/template/breadcrumb/api.ts +15 -0
- package/components/template/breadcrumb/index.ts +15 -0
- package/components/template/breadcrumb/props.d.ts +45 -0
- package/components/template/descriptions/api.ts +23 -0
- package/components/template/descriptions/index.ts +16 -0
- package/components/template/descriptions/props.d.ts +54 -0
- package/components/template/form/api.ts +23 -0
- package/components/template/form/index.ts +20 -0
- package/components/template/form/props.d.ts +60 -0
- package/components/template/grid/api.ts +20 -0
- package/components/template/grid/index.ts +15 -0
- package/components/template/grid/props.d.ts +48 -0
- package/components/template/menu/api.ts +26 -0
- package/components/template/menu/index.ts +19 -0
- package/components/template/menu/props.d.ts +93 -0
- package/components/template/menu/useMenu.ts +155 -0
- package/components/template/pagination/api.ts +22 -0
- package/components/template/pagination/index.ts +18 -0
- package/components/template/pagination/props.d.ts +65 -0
- package/components/template/pagination/usePagination.ts +186 -0
- package/components/template/table/api.ts +18 -0
- package/components/template/table/index.ts +18 -0
- package/components/template/table/props.d.ts +36 -0
- package/components/template/table/useTable.ts +138 -0
- package/components/template/tableColumn/api.ts +17 -0
- package/components/template/tableColumn/index.ts +15 -0
- package/components/template/tableColumn/props.d.ts +32 -0
- package/components/template/virtualList/api.ts +16 -0
- package/components/template/virtualList/index.ts +18 -0
- package/components/template/virtualList/props.d.ts +25 -0
- package/components/template/virtualList/useVirtualList.ts +237 -0
- package/components/types/hook.d.ts +13 -0
- package/components/types/props.d.ts +52 -0
- package/components/types/template.d.ts +59 -0
- package/compositions/common/defineCore.ts +55 -0
- package/compositions/common/useDebounceFn.ts +27 -0
- package/compositions/common/useDrag.ts +65 -0
- package/compositions/common/useElementSize.ts +37 -0
- package/compositions/common/useEventListener.ts +48 -0
- package/compositions/common/usePopover.ts +45 -0
- package/compositions/common/useResizeObserver.ts +43 -0
- package/compositions/common/useTeleport.ts +24 -0
- package/compositions/input/useBooleanInput.ts +52 -0
- package/compositions/modal/useModal.ts +72 -0
- package/compositions/popper/useClickAway.ts +41 -0
- package/compositions/popper/usePopper.ts +63 -0
- package/compositions/utils/filters.ts +135 -0
- package/compositions/virtualList/enums.ts +52 -0
- package/compositions/virtualList/useContainerObserver.ts +82 -0
- package/compositions/virtualList/useEntries.ts +248 -0
- package/compositions/virtualList/useHeightCache.ts +83 -0
- package/compositions/virtualList/useSentinelObserver.ts +81 -0
- package/dist/components/base/affix/useAffix.d.ts +5 -4
- package/dist/components/base/anchor/useAnchor.d.ts +1 -1
- package/dist/components/base/autoComplete/useAutoComplete.d.ts +12 -4
- package/dist/components/base/backTop/useBackTop.d.ts +1 -1
- package/dist/components/base/button/index.d.ts +11 -2
- package/dist/components/base/button/useButton.d.ts +11 -2
- package/dist/components/base/carousel/useCarousel.d.ts +6 -3
- package/dist/components/base/cascader/useCascader.d.ts +23 -11
- package/dist/components/base/checkbox/useCheckbox.d.ts +4 -3
- package/dist/components/base/collapse/useCollapse.d.ts +2 -2
- package/dist/components/base/datePicker/useDatePicker.d.ts +140 -8
- package/dist/components/base/dropdown/useDropdown.d.ts +11 -5
- package/dist/components/base/image/useImage.d.ts +5 -5
- package/dist/components/base/input/useInput.d.ts +1 -2
- package/dist/components/base/inputNumber/useInputNumber.d.ts +2 -2
- package/dist/components/base/popover/usePopover.d.ts +8 -8
- package/dist/components/base/progress/useProgress.d.ts +1 -1
- package/dist/components/base/rate/useRate.d.ts +1 -1
- package/dist/components/base/select/useSelect.d.ts +8 -8
- package/dist/components/base/slider/useSlider.d.ts +3 -3
- package/dist/components/base/steps/index.d.ts +1 -1
- package/dist/components/base/steps/useSteps.d.ts +5 -5
- package/dist/components/base/switch/useSwitch.d.ts +8 -3
- package/dist/components/base/tabs/useTabs.d.ts +2 -2
- package/dist/components/base/timePicker/useTimePicker.d.ts +14 -6
- package/dist/components/base/tooltip/useTooltip.d.ts +14 -4
- package/dist/components/base/transfer/useTransfer.d.ts +15 -15
- package/dist/components/base/tree/index.d.ts +1 -1
- package/dist/components/base/tree/useTree.d.ts +2 -1
- package/dist/components/message/message/useMessage.d.ts +11 -1
- package/dist/components/message/notification/useNotification.d.ts +17 -1
- package/dist/components/message/popover/MPopover.d.ts +6 -1
- package/dist/components/message/popover/usePopover.d.ts +6 -6
- package/dist/components/other/darkMode/useDarkMode.d.ts +1 -1
- package/dist/components/template/menu/useMenu.d.ts +1 -0
- package/dist/components/template/virtualList/useVirtualList.d.ts +10 -7
- package/dist/compositions/common/useDrag.d.ts +1 -1
- package/dist/compositions/common/useElementSize.d.ts +2 -2
- package/dist/compositions/common/useTeleport.d.ts +4 -2
- package/dist/compositions/modal/useModal.d.ts +1 -1
- package/dist/core.js +6137 -4186
- package/dist/runtime/defineHook.d.ts +1 -1
- package/index.css +1 -0
- package/index.ts +71 -0
- package/package.json +19 -16
- package/runtime/defineHook.ts +21 -0
- package/tools/empty.ts +81 -0
- package/tools/index.ts +15 -0
- package/tools/types.ts +11 -0
- package/tsconfig.json +8 -0
- package/types/common/common.d.ts +25 -0
- package/types/common/model.d.ts +25 -0
- package/types/index.d.ts +11 -0
- package/types/props.d.ts +13 -0
- package/vite.config.build.ts +41 -0
- package/dist/vite.config.build.d.ts +0 -2
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description 防抖hook
|
|
3
|
+
* @author youus
|
|
4
|
+
* @date 2022/8/19 23:47
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* Hello, humor
|
|
8
|
+
*/
|
|
9
|
+
import type { DebounceFilterOptions, FunctionArgs } from '../utils/filters';
|
|
10
|
+
import { createFilterWrapper, debounceFilter } from '../utils/filters';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Debounce execution of a function.
|
|
14
|
+
*
|
|
15
|
+
* @see https://vueuse.org/useDebounceFn
|
|
16
|
+
* @param fn A function to be executed after delay milliseconds debounced.
|
|
17
|
+
* @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
|
|
18
|
+
* @param opts options
|
|
19
|
+
*
|
|
20
|
+
* @return A new, debounce, function.
|
|
21
|
+
*/
|
|
22
|
+
export default function useDebounceFn<T extends FunctionArgs>(fn: T, ms: number = 200, options: DebounceFilterOptions = {}): T {
|
|
23
|
+
return createFilterWrapper(
|
|
24
|
+
debounceFilter(ms, options),
|
|
25
|
+
fn,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description drag hook
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2023/5/23 16:42
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*/
|
|
9
|
+
import * as _interactjsModule from 'interactjs';
|
|
10
|
+
// interactjs 是 UMD 格式,Vite ESM 不提供 default export,需兼容处理
|
|
11
|
+
const interactjs = (_interactjsModule as any).default ?? _interactjsModule;
|
|
12
|
+
import { Ref, ref } from 'vue';
|
|
13
|
+
|
|
14
|
+
// 方向类型,内联定义避免引用 lib 的 MessageDirectionType
|
|
15
|
+
export type DragDirectionType = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | string;
|
|
16
|
+
export type InteractEvent = any;
|
|
17
|
+
export type DragPosition = { x: number, y: number };
|
|
18
|
+
export type DragOption = { startAxis: 'x' | 'y', lockAxis: 'x' | 'y' };
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export default function useDrag(config: {
|
|
22
|
+
direction: DragDirectionType,
|
|
23
|
+
value?: {
|
|
24
|
+
domRef?: Ref<HTMLElement | null>
|
|
25
|
+
},
|
|
26
|
+
event?: {
|
|
27
|
+
getOption?: () => DragOption,
|
|
28
|
+
movePositionHandler?: (event: InteractEvent, position: DragPosition) => DragPosition,
|
|
29
|
+
onDragLeave?: (event: InteractEvent) => void
|
|
30
|
+
}
|
|
31
|
+
}) {
|
|
32
|
+
const domRef = config.value?.domRef ?? ref();
|
|
33
|
+
|
|
34
|
+
const init = (basePosition?: { x?: number, y?: number }) => {
|
|
35
|
+
if (!domRef.value) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const position: DragPosition = { x: basePosition?.x ?? 0, y: basePosition?.y ?? 0 };
|
|
39
|
+
return interactjs(domRef.value)
|
|
40
|
+
.styleCursor(false)
|
|
41
|
+
.draggable({
|
|
42
|
+
...config.event?.getOption?.(),
|
|
43
|
+
listeners: {
|
|
44
|
+
end: (event: InteractEvent) => {
|
|
45
|
+
config.event?.onDragLeave?.(event);
|
|
46
|
+
},
|
|
47
|
+
move: (event: InteractEvent) => {
|
|
48
|
+
const { x, y } = config.event?.movePositionHandler?.(event, position) ?? {
|
|
49
|
+
x: position.x + event.dx, y: position.y + event.dy,
|
|
50
|
+
};
|
|
51
|
+
position.x = x;
|
|
52
|
+
position.y = y;
|
|
53
|
+
event.target.style.transform = `translate(${position.x}px, ${position.y}px)`;
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
domRef,
|
|
62
|
+
init,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description element size hook
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2023/6/24 16:17
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*
|
|
9
|
+
* Learn from vueuse useElementSize
|
|
10
|
+
*/
|
|
11
|
+
import { Ref, ref } from 'vue';
|
|
12
|
+
import { useResizeObserver } from './useResizeObserver';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export function useElementSize(
|
|
16
|
+
target: Ref<HTMLElement | null>,
|
|
17
|
+
// initialSize = { w: 0, h: 0 },
|
|
18
|
+
// options: ResizeObserverOptions = {},
|
|
19
|
+
) {
|
|
20
|
+
|
|
21
|
+
const w = ref(0);
|
|
22
|
+
const h = ref(0);
|
|
23
|
+
|
|
24
|
+
useResizeObserver(target, () => {
|
|
25
|
+
const ele = target.value;
|
|
26
|
+
if (window && ele) {
|
|
27
|
+
const styles = window.getComputedStyle(ele);
|
|
28
|
+
w.value = Number.parseFloat(styles.width);
|
|
29
|
+
h.value = Number.parseFloat(styles.height);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
w, h,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description event listener hook
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2023/5/12 00:57
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export type EventListenerOptions = {
|
|
12
|
+
target: any,
|
|
13
|
+
event: string,
|
|
14
|
+
handler: EventListenerOrEventListenerObject,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default function useEventListener(options: EventListenerOptions) {
|
|
18
|
+
|
|
19
|
+
const getTarget = () => {
|
|
20
|
+
if (typeof options.target === 'function') {
|
|
21
|
+
return options.target();
|
|
22
|
+
}
|
|
23
|
+
return options.target;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const add = () => {
|
|
27
|
+
getTarget().addEventListener(options.event, options.handler);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const remove = () => {
|
|
31
|
+
getTarget().removeEventListener(options.event, options.handler);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const onMounted = () => {
|
|
35
|
+
add();
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const onBeforeDestroy = () => {
|
|
39
|
+
remove();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
add, remove,
|
|
44
|
+
onMounted,
|
|
45
|
+
onBeforeDestroy,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description popover hook, for component like select, datepicker, etc.
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2023/5/19 00:12
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*/
|
|
9
|
+
import { PopoverProps } from '../../components/message/popover/props';
|
|
10
|
+
import { arrow, flip, offset, type OffsetOptions, shift } from '@floating-ui/dom';
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
flip,
|
|
14
|
+
offset,
|
|
15
|
+
shift,
|
|
16
|
+
arrow,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default function usePopover(
|
|
20
|
+
props?: Partial<PopoverProps>,
|
|
21
|
+
middleware?: {
|
|
22
|
+
offset?: OffsetOptions
|
|
23
|
+
extends?: any[]
|
|
24
|
+
},
|
|
25
|
+
) {
|
|
26
|
+
|
|
27
|
+
const offsetOptions = middleware?.offset ?? { crossAxis: 3 };
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
const popoverOptions: PopoverProps = {
|
|
31
|
+
placement: props?.placement ?? 'bottom-start',
|
|
32
|
+
popper: {
|
|
33
|
+
middleware: [
|
|
34
|
+
offset(offsetOptions),
|
|
35
|
+
flip(),
|
|
36
|
+
shift(),
|
|
37
|
+
...middleware?.extends ?? [],
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
popoverOptions,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description resizeObserver hook
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2023/6/24 16:08
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*
|
|
9
|
+
* Learn from vueuse useResizeObserver
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { Ref, watch } from 'vue';
|
|
13
|
+
|
|
14
|
+
export function useResizeObserver(
|
|
15
|
+
target: Ref<HTMLElement | null>,
|
|
16
|
+
callback: ResizeObserverCallback,
|
|
17
|
+
options: ResizeObserverOptions = {},
|
|
18
|
+
) {
|
|
19
|
+
|
|
20
|
+
let observer: ResizeObserver | undefined;
|
|
21
|
+
|
|
22
|
+
const cleanup = () => {
|
|
23
|
+
if (observer) {
|
|
24
|
+
observer.disconnect();
|
|
25
|
+
observer = undefined;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// vueuse used watch
|
|
30
|
+
watch(target, () => {
|
|
31
|
+
if (target.value) {
|
|
32
|
+
cleanup();
|
|
33
|
+
observer = new ResizeObserver(callback);
|
|
34
|
+
observer.observe(target.value, options);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
cleanup,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description teleport hook
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2023/5/5 10:40
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*/
|
|
9
|
+
import { h, Teleport, TeleportProps, VNode } from 'vue';
|
|
10
|
+
import { MTeleportProps } from '../../types/common/common';
|
|
11
|
+
|
|
12
|
+
export default function useTeleport(options: {
|
|
13
|
+
teleportProps?: MTeleportProps | true,
|
|
14
|
+
slot: VNode | VNode[]
|
|
15
|
+
}) {
|
|
16
|
+
return h(Teleport, initTeleportOptions(options.teleportProps as TeleportProps), options.slot);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const initTeleportOptions = (options: TeleportProps | true | undefined) => {
|
|
20
|
+
if (options === true || options === undefined) {
|
|
21
|
+
return { to: 'body' };
|
|
22
|
+
}
|
|
23
|
+
return options;
|
|
24
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description boolean input like checkbox/radio... hooks
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2023/4/23 15:22
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*/
|
|
9
|
+
import { isBoolean, notEmpty } from '../../tools';
|
|
10
|
+
|
|
11
|
+
export const initChecked = (props: {
|
|
12
|
+
checked: boolean | null | undefined,
|
|
13
|
+
modelValue: any,
|
|
14
|
+
value: any
|
|
15
|
+
}) => {
|
|
16
|
+
if (props.checked) {
|
|
17
|
+
return props.checked;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (notEmpty(props.modelValue)) {
|
|
21
|
+
if (notEmpty(props.value)) {
|
|
22
|
+
if (Array.isArray(props.modelValue)) {
|
|
23
|
+
return props.modelValue.includes(props.value);
|
|
24
|
+
}
|
|
25
|
+
return props.value === props.modelValue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (isBoolean(props.modelValue)) {
|
|
29
|
+
return props.modelValue;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
export const getNewModelValue = (props: { value: any, modelValue?: any }, checked: boolean) => {
|
|
38
|
+
if (props.value) {
|
|
39
|
+
if (Array.isArray(props.modelValue)) {
|
|
40
|
+
const arr = [...props.modelValue];
|
|
41
|
+
if (checked) {
|
|
42
|
+
if (!arr.includes(props.value)) arr.push(props.value);
|
|
43
|
+
} else {
|
|
44
|
+
const idx = arr.indexOf(props.value);
|
|
45
|
+
if (idx !== -1) arr.splice(idx, 1);
|
|
46
|
+
}
|
|
47
|
+
return arr;
|
|
48
|
+
}
|
|
49
|
+
return checked ? props.value : undefined;
|
|
50
|
+
}
|
|
51
|
+
return checked;
|
|
52
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description 模态框公共 composable(dialog / drawer / confirm 共用)
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2026/2/25 16:00
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*
|
|
9
|
+
* 处理 visible 状态、遮罩层点击关闭、emit 同步
|
|
10
|
+
*/
|
|
11
|
+
import { ref, watch } from 'vue';
|
|
12
|
+
import { ModelMask } from '../../types/common/model';
|
|
13
|
+
|
|
14
|
+
export interface UseModalProps {
|
|
15
|
+
visible?: boolean;
|
|
16
|
+
mask?: ModelMask;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
export function useModal(props: UseModalProps, emit: (...args: any[]) => void) {
|
|
21
|
+
const visible = ref(props.visible ?? false);
|
|
22
|
+
|
|
23
|
+
watch(() => props.visible, (val) => {
|
|
24
|
+
visible.value = val ?? false;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/** 打开 */
|
|
28
|
+
const open = () => {
|
|
29
|
+
visible.value = true;
|
|
30
|
+
emit('update:visible', true);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** 关闭 */
|
|
34
|
+
const close = () => {
|
|
35
|
+
visible.value = false;
|
|
36
|
+
emit('update:visible', false);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** 切换 */
|
|
40
|
+
const toggle = () => {
|
|
41
|
+
if (visible.value) { close(); } else { open(); }
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** 遮罩层点击 */
|
|
45
|
+
const onMaskClick = () => {
|
|
46
|
+
const mask = props.mask;
|
|
47
|
+
const clickClose = mask?.clickClose ?? true;
|
|
48
|
+
if (clickClose) {
|
|
49
|
+
close();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** 是否显示遮罩 */
|
|
54
|
+
const showMask = () => {
|
|
55
|
+
return props.mask?.show ?? true;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** 阻止内容区域点击冒泡到遮罩 */
|
|
59
|
+
const onContentClick = (e: MouseEvent) => {
|
|
60
|
+
e.stopPropagation();
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
visible,
|
|
65
|
+
open,
|
|
66
|
+
close,
|
|
67
|
+
toggle,
|
|
68
|
+
onMaskClick,
|
|
69
|
+
showMask,
|
|
70
|
+
onContentClick,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description click away hook
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2023/5/12 01:02
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*/
|
|
9
|
+
import useEventListener from '../common/useEventListener';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const event = 'pointerdown';
|
|
13
|
+
export default function useClickAway(options: {
|
|
14
|
+
target: any,
|
|
15
|
+
handler: (event: any) => void
|
|
16
|
+
}) {
|
|
17
|
+
if (typeof window === 'undefined' || !window) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const listener = (event: any) => {
|
|
22
|
+
const el = typeof options.target === 'function' ? options.target() : options.target;
|
|
23
|
+
if (!el) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (el === event.target || event.composedPath().includes(el)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
options.handler(event);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return useEventListener({
|
|
35
|
+
target: window,
|
|
36
|
+
event,
|
|
37
|
+
handler: listener,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description popper hook
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2023/1/29 10:21
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*/
|
|
9
|
+
import { arrow, autoUpdate, computePosition, ComputePositionConfig } from '@floating-ui/dom';
|
|
10
|
+
|
|
11
|
+
export type Placement =
|
|
12
|
+
| 'top' | 'top-start' | 'top-end'
|
|
13
|
+
| 'right' | 'right-start' | 'right-end'
|
|
14
|
+
| 'bottom' | 'bottom-start' | 'bottom-end'
|
|
15
|
+
| 'left' | 'left-start' | 'left-end';
|
|
16
|
+
export type PopperConfig = Partial<ComputePositionConfig>;
|
|
17
|
+
|
|
18
|
+
type DomStyle = { left: string; top: string; display: string; position: string };
|
|
19
|
+
export type PositionStyle = { style: DomStyle; arrowStyle: DomStyle, placement: Placement };
|
|
20
|
+
|
|
21
|
+
export const usePopper = (
|
|
22
|
+
triggerNode: HTMLElement,
|
|
23
|
+
popperNode: HTMLElement,
|
|
24
|
+
update: (data: PositionStyle) => void,
|
|
25
|
+
arrowNode?: HTMLElement,
|
|
26
|
+
config?: PopperConfig,
|
|
27
|
+
) => {
|
|
28
|
+
|
|
29
|
+
const getPositionStyle = async () => {
|
|
30
|
+
if (arrowNode && config?.middleware) {
|
|
31
|
+
config.middleware.push(arrow({ element: arrowNode }));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
const { x, y, placement, middlewareData } = await computePosition(triggerNode, popperNode, config);
|
|
36
|
+
const res: PositionStyle = {
|
|
37
|
+
style: {
|
|
38
|
+
left: `${x}px`,
|
|
39
|
+
top: `${y}px`,
|
|
40
|
+
display: 'block',
|
|
41
|
+
position: 'absolute',
|
|
42
|
+
},
|
|
43
|
+
arrowStyle: {
|
|
44
|
+
left: `${middlewareData.arrow?.x ?? 0}px`,
|
|
45
|
+
top: `${middlewareData.arrow?.y ?? 0}px`,
|
|
46
|
+
display: 'block',
|
|
47
|
+
position: 'absolute',
|
|
48
|
+
},
|
|
49
|
+
placement,
|
|
50
|
+
};
|
|
51
|
+
update(res);
|
|
52
|
+
|
|
53
|
+
return res;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const clear = autoUpdate(triggerNode, popperNode, getPositionStyle);
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
getPositionStyle,
|
|
61
|
+
clear,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description event filter(防抖、节流)
|
|
3
|
+
* @author youus
|
|
4
|
+
* @date 2022/8/20 00:17
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* Hello, humor
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export type FunctionArgs<Args extends any[] = any[], Return = void> = (...args: Args) => Return;
|
|
12
|
+
|
|
13
|
+
export interface FunctionWrapperOptions<Args extends any[] = any[], This = any> {
|
|
14
|
+
fn: FunctionArgs<Args, This>,
|
|
15
|
+
args: Args,
|
|
16
|
+
thisArg: This
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type EventFilter<Args extends any[] = any[], This = any> = (
|
|
20
|
+
invoke: () => void,
|
|
21
|
+
options: FunctionWrapperOptions<Args, This>,
|
|
22
|
+
) => void;
|
|
23
|
+
|
|
24
|
+
export interface DebounceFilterOptions {
|
|
25
|
+
/**
|
|
26
|
+
* The maximum time allowed to be delayed before it's invoked.
|
|
27
|
+
* In milliseconds.
|
|
28
|
+
*/
|
|
29
|
+
maxWait?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export function createFilterWrapper<T extends FunctionArgs>(filter: EventFilter, fn: T) {
|
|
36
|
+
function wrapper(this: any, ...args: any[]) {
|
|
37
|
+
filter(() => fn.apply(this, args), { fn, thisArg: this, args });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return wrapper as any as T;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create an EventFilter that debounce the events
|
|
45
|
+
*
|
|
46
|
+
* @param ms
|
|
47
|
+
* @param options
|
|
48
|
+
*/
|
|
49
|
+
export function debounceFilter(ms: number, options: DebounceFilterOptions = {}) {
|
|
50
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
51
|
+
let maxTimer: ReturnType<typeof setTimeout> | undefined | null;
|
|
52
|
+
|
|
53
|
+
const filter: EventFilter = invoke => {
|
|
54
|
+
const duration = ms;
|
|
55
|
+
const maxDuration = options.maxWait;
|
|
56
|
+
|
|
57
|
+
if (timer) clearTimeout(timer);
|
|
58
|
+
|
|
59
|
+
if (duration <= 0 || (maxDuration !== undefined && maxDuration <= 0)) {
|
|
60
|
+
if (maxTimer) {
|
|
61
|
+
clearTimeout(maxTimer);
|
|
62
|
+
maxTimer = null;
|
|
63
|
+
}
|
|
64
|
+
return invoke();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Create the maxTimer. Clears the regular timer on invoke
|
|
68
|
+
if (maxDuration && !maxTimer) {
|
|
69
|
+
maxTimer = setTimeout(() => {
|
|
70
|
+
if (timer) clearTimeout(timer);
|
|
71
|
+
maxTimer = null;
|
|
72
|
+
invoke();
|
|
73
|
+
}, maxDuration);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Create the regular timer. Clears the max timer on invoke
|
|
77
|
+
timer = setTimeout(() => {
|
|
78
|
+
if (maxTimer) clearTimeout(maxTimer);
|
|
79
|
+
maxTimer = null;
|
|
80
|
+
invoke();
|
|
81
|
+
}, duration);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return filter;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Create an EventFilter that throttle the events
|
|
89
|
+
*
|
|
90
|
+
* @param ms
|
|
91
|
+
* @param [trailing=true]
|
|
92
|
+
* @param [leading=true]
|
|
93
|
+
*/
|
|
94
|
+
export function throttleFilter(ms: number, trailing = true, leading = true) {
|
|
95
|
+
let lastExec = 0;
|
|
96
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
97
|
+
let isLeading = true;
|
|
98
|
+
|
|
99
|
+
const clear = () => {
|
|
100
|
+
if (timer) {
|
|
101
|
+
clearTimeout(timer);
|
|
102
|
+
timer = undefined;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const filter: EventFilter = invoke => {
|
|
107
|
+
const duration = ms;
|
|
108
|
+
const elapsed = Date.now() - lastExec;
|
|
109
|
+
|
|
110
|
+
clear();
|
|
111
|
+
|
|
112
|
+
if (duration <= 0) {
|
|
113
|
+
lastExec = Date.now();
|
|
114
|
+
return invoke();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (elapsed > duration && (leading || !isLeading)) {
|
|
118
|
+
lastExec = Date.now();
|
|
119
|
+
invoke();
|
|
120
|
+
} else if (trailing) {
|
|
121
|
+
timer = setTimeout(() => {
|
|
122
|
+
lastExec = Date.now();
|
|
123
|
+
isLeading = true;
|
|
124
|
+
clear();
|
|
125
|
+
invoke();
|
|
126
|
+
}, duration);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!leading && !timer) timer = setTimeout(() => (isLeading = true), duration);
|
|
130
|
+
|
|
131
|
+
isLeading = false;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return filter;
|
|
135
|
+
}
|