@veltra/compositions 1.0.0
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/dist/index.d.ts +14 -0
- package/dist/index.js +14 -0
- package/dist/use-component-props/index.d.ts +12 -0
- package/dist/use-component-props/index.js +52 -0
- package/dist/use-component-props/index.js.map +1 -0
- package/dist/use-config/index.d.ts +25 -0
- package/dist/use-config/index.js +51 -0
- package/dist/use-config/index.js.map +1 -0
- package/dist/use-drag/index.d.ts +47 -0
- package/dist/use-drag/index.js +87 -0
- package/dist/use-drag/index.js.map +1 -0
- package/dist/use-fallback-props/index.d.ts +31 -0
- package/dist/use-fallback-props/index.js +35 -0
- package/dist/use-fallback-props/index.js.map +1 -0
- package/dist/use-focus/index.d.ts +16 -0
- package/dist/use-focus/index.js +27 -0
- package/dist/use-focus/index.js.map +1 -0
- package/dist/use-form-component/index.d.ts +22 -0
- package/dist/use-form-component/index.js +15 -0
- package/dist/use-form-component/index.js.map +1 -0
- package/dist/use-lock/index.d.ts +28 -0
- package/dist/use-lock/index.js +36 -0
- package/dist/use-lock/index.js.map +1 -0
- package/dist/use-model/index.d.ts +35 -0
- package/dist/use-model/index.js +46 -0
- package/dist/use-model/index.js.map +1 -0
- package/dist/use-pop/index.d.ts +53 -0
- package/dist/use-pop/index.js +121 -0
- package/dist/use-pop/index.js.map +1 -0
- package/dist/use-reactive-size/index.d.ts +17 -0
- package/dist/use-reactive-size/index.js +40 -0
- package/dist/use-reactive-size/index.js.map +1 -0
- package/dist/use-resize-observer/index.d.ts +33 -0
- package/dist/use-resize-observer/index.js +92 -0
- package/dist/use-resize-observer/index.js.map +1 -0
- package/dist/use-transition/index.d.ts +18 -0
- package/dist/use-transition/index.js +11 -0
- package/dist/use-transition/index.js.map +1 -0
- package/dist/use-transition/type.d.ts +47 -0
- package/dist/use-transition/use-css-transition.js +129 -0
- package/dist/use-transition/use-css-transition.js.map +1 -0
- package/dist/use-transition/use-style-transition.js +127 -0
- package/dist/use-transition/use-style-transition.js.map +1 -0
- package/dist/use-transition/utils.js +41 -0
- package/dist/use-transition/utils.js.map +1 -0
- package/dist/use-virtual/index.d.ts +30 -0
- package/dist/use-virtual/index.js +67 -0
- package/dist/use-virtual/index.js.map +1 -0
- package/package.json +32 -0
- package/src/index.ts +25 -0
- package/src/use-component-props/index.ts +63 -0
- package/src/use-config/index.ts +77 -0
- package/src/use-drag/index.ts +151 -0
- package/src/use-fallback-props/index.ts +76 -0
- package/src/use-focus/index.ts +26 -0
- package/src/use-form-component/index.ts +31 -0
- package/src/use-lock/index.ts +50 -0
- package/src/use-model/index.ts +96 -0
- package/src/use-pop/index.ts +206 -0
- package/src/use-reactive-size/index.ts +53 -0
- package/src/use-resize-observer/index.ts +148 -0
- package/src/use-transition/index.ts +22 -0
- package/src/use-transition/type.ts +50 -0
- package/src/use-transition/use-css-transition.ts +186 -0
- package/src/use-transition/use-style-transition.ts +182 -0
- package/src/use-transition/utils.ts +56 -0
- package/src/use-virtual/index.ts +130 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useComponentProps } from "./use-component-props/index.js";
|
|
2
|
+
import { setDocumentSize, useConfig } from "./use-config/index.js";
|
|
3
|
+
import { useDrag } from "./use-drag/index.js";
|
|
4
|
+
import { useFallbackProps, useFormFallbackProps } from "./use-fallback-props/index.js";
|
|
5
|
+
import { useFocus } from "./use-focus/index.js";
|
|
6
|
+
import { useFormComponent } from "./use-form-component/index.js";
|
|
7
|
+
import { Updater, useUpdateLock } from "./use-lock/index.js";
|
|
8
|
+
import { useModel } from "./use-model/index.js";
|
|
9
|
+
import { usePop } from "./use-pop/index.js";
|
|
10
|
+
import { RefElement, ResizeObserverReturn, useObserverCallback, useResizeObserver } from "./use-resize-observer/index.js";
|
|
11
|
+
import { useReactiveSize } from "./use-reactive-size/index.js";
|
|
12
|
+
import { useTransition } from "./use-transition/index.js";
|
|
13
|
+
import { VirtualReturned, useVirtual } from "./use-virtual/index.js";
|
|
14
|
+
export { RefElement, ResizeObserverReturn, Updater, VirtualReturned, setDocumentSize, useComponentProps, useConfig, useDrag, useFallbackProps, useFocus, useFormComponent, useFormFallbackProps, useModel, useObserverCallback, usePop, useReactiveSize, useResizeObserver, useTransition, useUpdateLock, useVirtual };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useComponentProps } from "./use-component-props/index.js";
|
|
2
|
+
import { setDocumentSize, useConfig } from "./use-config/index.js";
|
|
3
|
+
import { useDrag } from "./use-drag/index.js";
|
|
4
|
+
import { useFallbackProps, useFormFallbackProps } from "./use-fallback-props/index.js";
|
|
5
|
+
import { useFocus } from "./use-focus/index.js";
|
|
6
|
+
import { useFormComponent } from "./use-form-component/index.js";
|
|
7
|
+
import { useUpdateLock } from "./use-lock/index.js";
|
|
8
|
+
import { useModel } from "./use-model/index.js";
|
|
9
|
+
import { usePop } from "./use-pop/index.js";
|
|
10
|
+
import { useObserverCallback, useResizeObserver } from "./use-resize-observer/index.js";
|
|
11
|
+
import { useReactiveSize } from "./use-reactive-size/index.js";
|
|
12
|
+
import { useTransition } from "./use-transition/index.js";
|
|
13
|
+
import { useVirtual } from "./use-virtual/index.js";
|
|
14
|
+
export { setDocumentSize, useComponentProps, useConfig, useDrag, useFallbackProps, useFocus, useFormComponent, useFormFallbackProps, useModel, useObserverCallback, usePop, useReactiveSize, useResizeObserver, useTransition, useUpdateLock, useVirtual };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Component, MaybeRef } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/use-component-props/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* 生成一个用于设置组件通用属性的组件
|
|
6
|
+
* @param props 组件通用的属性
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
declare function useComponentProps<T extends Record<string, any>>(props: MaybeRef<T & Record<string, any>>): Component;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { useComponentProps };
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { extractNormalVNodes } from "@veltra/utils";
|
|
2
|
+
import { cloneVNode, createVNode, defineComponent, isRef } from "vue";
|
|
3
|
+
//#region src/use-component-props/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* 生成一个用于设置组件通用属性的组件
|
|
6
|
+
* @param props 组件通用的属性
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
function useComponentProps(props) {
|
|
10
|
+
return defineComponent({
|
|
11
|
+
name: "ComponentCommonProps",
|
|
12
|
+
inheritAttrs: false,
|
|
13
|
+
props: { tag: { type: String } },
|
|
14
|
+
setup(componentProps, { slots, attrs }) {
|
|
15
|
+
const isPropsRef = isRef(props);
|
|
16
|
+
const staticKeys = isPropsRef ? null : Object.keys(props);
|
|
17
|
+
const mergeNodesProps = (commonProps) => {
|
|
18
|
+
const nodes = extractNormalVNodes(slots.default?.() ?? []);
|
|
19
|
+
if (!nodes?.length) return void 0;
|
|
20
|
+
const keys = staticKeys ?? Object.keys(commonProps);
|
|
21
|
+
return nodes.map((node) => {
|
|
22
|
+
const mergedProps = {};
|
|
23
|
+
let count = 0;
|
|
24
|
+
for (let i = 0; i < keys.length; i++) {
|
|
25
|
+
const key = keys[i];
|
|
26
|
+
if (node.props?.[key] !== void 0) continue;
|
|
27
|
+
mergedProps[key] = attrs[key] !== void 0 ? attrs[key] : commonProps[key];
|
|
28
|
+
count++;
|
|
29
|
+
}
|
|
30
|
+
return count > 0 ? cloneVNode(node, mergedProps) : node;
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
return () => {
|
|
34
|
+
const _props = isPropsRef ? props.value : props;
|
|
35
|
+
const nodes = mergeNodesProps(_props);
|
|
36
|
+
if (componentProps.tag) {
|
|
37
|
+
if (!nodes) return void 0;
|
|
38
|
+
const tagProps = Object.keys(attrs).reduce((acc, cur) => {
|
|
39
|
+
if (!(cur in _props)) acc[cur] = attrs[cur];
|
|
40
|
+
return acc;
|
|
41
|
+
}, {});
|
|
42
|
+
return createVNode(componentProps.tag, tagProps, nodes);
|
|
43
|
+
}
|
|
44
|
+
return nodes;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { useComponentProps };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/use-component-props/index.ts"],"sourcesContent":["import { extractNormalVNodes } from '@veltra/utils'\nimport { defineComponent, isRef, type MaybeRef, createVNode, cloneVNode, type Component } from 'vue'\n\n/**\n * 生成一个用于设置组件通用属性的组件\n * @param props 组件通用的属性\n * @returns\n */\nexport function useComponentProps<T extends Record<string, any>>(\n props: MaybeRef<T & Record<string, any>>\n): Component {\n return defineComponent({\n name: 'ComponentCommonProps',\n inheritAttrs: false,\n\n props: {\n /** 渲染一个标准html5标签 */\n tag: { type: String }\n },\n\n setup(componentProps, { slots, attrs }) {\n const isPropsRef = isRef(props)\n // 非 ref 时 keys 固定,缓存避免每次 render 重复计算\n const staticKeys = isPropsRef ? null : Object.keys(props)\n\n const mergeNodesProps = (commonProps: Record<string, any>) => {\n const nodes = extractNormalVNodes(slots.default?.() ?? [])\n if (!nodes?.length) return undefined\n\n const keys = staticKeys ?? Object.keys(commonProps)\n return nodes.map((node) => {\n const mergedProps: Record<string, any> = {}\n let count = 0\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!\n // node中已定义的属性优先\n if (node.props?.[key] !== undefined) continue\n mergedProps[key] = attrs[key] !== undefined ? attrs[key] : commonProps[key]\n count++\n }\n return count > 0 ? cloneVNode(node, mergedProps) : node\n })\n }\n\n return () => {\n const _props = isPropsRef ? props.value : props\n const nodes = mergeNodesProps(_props)\n\n if (componentProps.tag) {\n if (!nodes) return undefined\n const tagProps = Object.keys(attrs).reduce<Record<string, any>>((acc, cur) => {\n if (!(cur in _props)) {\n acc[cur] = attrs[cur]\n }\n return acc\n }, {})\n return createVNode(componentProps.tag, tagProps, nodes)\n }\n return nodes\n }\n }\n })\n}\n"],"mappings":";;;;;;;;AAQA,SAAgB,kBACd,OACW;AACX,QAAO,gBAAgB;EACrB,MAAM;EACN,cAAc;EAEd,OAAO,EAEL,KAAK,EAAE,MAAM,QAAQ,EACtB;EAED,MAAM,gBAAgB,EAAE,OAAO,SAAS;GACtC,MAAM,aAAa,MAAM,MAAM;GAE/B,MAAM,aAAa,aAAa,OAAO,OAAO,KAAK,MAAM;GAEzD,MAAM,mBAAmB,gBAAqC;IAC5D,MAAM,QAAQ,oBAAoB,MAAM,WAAW,IAAI,EAAE,CAAC;AAC1D,QAAI,CAAC,OAAO,OAAQ,QAAO,KAAA;IAE3B,MAAM,OAAO,cAAc,OAAO,KAAK,YAAY;AACnD,WAAO,MAAM,KAAK,SAAS;KACzB,MAAM,cAAmC,EAAE;KAC3C,IAAI,QAAQ;AACZ,UAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;MACpC,MAAM,MAAM,KAAK;AAEjB,UAAI,KAAK,QAAQ,SAAS,KAAA,EAAW;AACrC,kBAAY,OAAO,MAAM,SAAS,KAAA,IAAY,MAAM,OAAO,YAAY;AACvE;;AAEF,YAAO,QAAQ,IAAI,WAAW,MAAM,YAAY,GAAG;MACnD;;AAGJ,gBAAa;IACX,MAAM,SAAS,aAAa,MAAM,QAAQ;IAC1C,MAAM,QAAQ,gBAAgB,OAAO;AAErC,QAAI,eAAe,KAAK;AACtB,SAAI,CAAC,MAAO,QAAO,KAAA;KACnB,MAAM,WAAW,OAAO,KAAK,MAAM,CAAC,QAA6B,KAAK,QAAQ;AAC5E,UAAI,EAAE,OAAO,QACX,KAAI,OAAO,MAAM;AAEnB,aAAO;QACN,EAAE,CAAC;AACN,YAAO,YAAY,eAAe,KAAK,UAAU,MAAM;;AAEzD,WAAO;;;EAGZ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ComponentSize } from "@veltra/utils/types";
|
|
2
|
+
|
|
3
|
+
//#region src/use-config/index.d.ts
|
|
4
|
+
interface State {
|
|
5
|
+
/** 是否开启动画,机器老可以关闭动画来获得性能 */
|
|
6
|
+
animation: boolean;
|
|
7
|
+
/** 组件尺寸大小 */
|
|
8
|
+
size: ComponentSize;
|
|
9
|
+
/** 表单 */
|
|
10
|
+
form: {
|
|
11
|
+
/** 标签宽度 */labelWidth?: number | number;
|
|
12
|
+
};
|
|
13
|
+
paginator: {
|
|
14
|
+
pageSize: number;
|
|
15
|
+
pageSizeOptions: number[];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
declare function setDocumentSize(size: ComponentSize, oldSize?: ComponentSize): void;
|
|
19
|
+
declare function useConfig(): {
|
|
20
|
+
config: Readonly<State>;
|
|
21
|
+
setConfig: (conf: Partial<State>) => void;
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { setDocumentSize, useConfig };
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { reactive, readonly, watch } from "vue";
|
|
2
|
+
import { isObj } from "@cat-kit/core";
|
|
3
|
+
//#region src/use-config/index.ts
|
|
4
|
+
const state = reactive({
|
|
5
|
+
animation: true,
|
|
6
|
+
size: "default",
|
|
7
|
+
form: { labelWidth: 80 },
|
|
8
|
+
paginator: {
|
|
9
|
+
pageSize: 40,
|
|
10
|
+
pageSizeOptions: [
|
|
11
|
+
40,
|
|
12
|
+
100,
|
|
13
|
+
200,
|
|
14
|
+
500,
|
|
15
|
+
1e3
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
function setDocumentSize(size, oldSize) {
|
|
20
|
+
if (typeof document === "undefined") return;
|
|
21
|
+
if (oldSize) document.documentElement.classList.remove(oldSize);
|
|
22
|
+
document.documentElement.classList.add(size);
|
|
23
|
+
}
|
|
24
|
+
let stopDocumentSizeSync = null;
|
|
25
|
+
function ensureDocumentSizeSync() {
|
|
26
|
+
if (stopDocumentSizeSync) return;
|
|
27
|
+
if (typeof document === "undefined") return;
|
|
28
|
+
stopDocumentSizeSync = watch(() => state.size, (size, oldSize) => setDocumentSize(size, oldSize));
|
|
29
|
+
}
|
|
30
|
+
function deepSet(original, extend) {
|
|
31
|
+
Object.keys(extend).forEach((key) => {
|
|
32
|
+
const val = original[key];
|
|
33
|
+
const targetVal = extend[key];
|
|
34
|
+
if (isObj(val)) if (isObj(targetVal)) deepSet(val, targetVal);
|
|
35
|
+
else console.warn(`extend['${key}']应该是一个对象`);
|
|
36
|
+
else original[key] = targetVal;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function useConfig() {
|
|
40
|
+
ensureDocumentSizeSync();
|
|
41
|
+
return {
|
|
42
|
+
config: readonly(state),
|
|
43
|
+
setConfig(conf) {
|
|
44
|
+
deepSet(state, conf);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { setDocumentSize, useConfig };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/use-config/index.ts"],"sourcesContent":["import { isObj } from '@cat-kit/core'\nimport type { ComponentSize } from '@veltra/utils/types'\nimport { reactive, readonly, watch } from 'vue'\n\ninterface State {\n /** 是否开启动画,机器老可以关闭动画来获得性能 */\n animation: boolean\n /** 组件尺寸大小 */\n size: ComponentSize\n /** 表单 */\n form: {\n /** 标签宽度 */\n labelWidth?: number | number\n }\n paginator: { pageSize: number; pageSizeOptions: number[] }\n}\n\nconst state = reactive<State>({\n animation: true,\n size: 'default',\n form: { labelWidth: 80 },\n paginator: { pageSize: 40, pageSizeOptions: [40, 100, 200, 500, 1000] }\n})\n\nexport function setDocumentSize(size: ComponentSize, oldSize?: ComponentSize): void {\n if (typeof document === 'undefined') return\n if (oldSize) {\n document.documentElement.classList.remove(oldSize)\n }\n document.documentElement.classList.add(size)\n}\n\nlet stopDocumentSizeSync: (() => void) | null = null\n\nfunction ensureDocumentSizeSync(): void {\n if (stopDocumentSizeSync) return\n if (typeof document === 'undefined') return\n\n stopDocumentSizeSync = watch(\n () => state.size,\n (size, oldSize) => setDocumentSize(size, oldSize)\n )\n}\n\nfunction deepSet(original: Record<string, any>, extend: Record<string, any>) {\n Object.keys(extend).forEach((key) => {\n const val = original[key]\n const targetVal = extend[key]\n if (isObj(val)) {\n if (isObj(targetVal)) {\n deepSet(val, targetVal)\n } else {\n console.warn(`extend['${key}']应该是一个对象`)\n }\n } else {\n original[key] = targetVal\n }\n })\n}\n\nexport function useConfig(): {\n config: Readonly<State>\n setConfig: (conf: Partial<State>) => void\n} {\n ensureDocumentSizeSync()\n return {\n /** 全局配置 */\n config: readonly(state) as Readonly<State>,\n /**\n * 设置全局配置项\n * @param conf\n */\n setConfig(conf: Partial<State>) {\n deepSet(state, conf)\n }\n }\n}\n"],"mappings":";;;AAiBA,MAAM,QAAQ,SAAgB;CAC5B,WAAW;CACX,MAAM;CACN,MAAM,EAAE,YAAY,IAAI;CACxB,WAAW;EAAE,UAAU;EAAI,iBAAiB;GAAC;GAAI;GAAK;GAAK;GAAK;GAAK;EAAE;CACxE,CAAC;AAEF,SAAgB,gBAAgB,MAAqB,SAA+B;AAClF,KAAI,OAAO,aAAa,YAAa;AACrC,KAAI,QACF,UAAS,gBAAgB,UAAU,OAAO,QAAQ;AAEpD,UAAS,gBAAgB,UAAU,IAAI,KAAK;;AAG9C,IAAI,uBAA4C;AAEhD,SAAS,yBAA+B;AACtC,KAAI,qBAAsB;AAC1B,KAAI,OAAO,aAAa,YAAa;AAErC,wBAAuB,YACf,MAAM,OACX,MAAM,YAAY,gBAAgB,MAAM,QAAQ,CAClD;;AAGH,SAAS,QAAQ,UAA+B,QAA6B;AAC3E,QAAO,KAAK,OAAO,CAAC,SAAS,QAAQ;EACnC,MAAM,MAAM,SAAS;EACrB,MAAM,YAAY,OAAO;AACzB,MAAI,MAAM,IAAI,CACZ,KAAI,MAAM,UAAU,CAClB,SAAQ,KAAK,UAAU;MAEvB,SAAQ,KAAK,WAAW,IAAI,WAAW;MAGzC,UAAS,OAAO;GAElB;;AAGJ,SAAgB,YAGd;AACA,yBAAwB;AACxB,QAAO;EAEL,QAAQ,SAAS,MAAM;EAKvB,UAAU,MAAsB;AAC9B,WAAQ,OAAO,KAAK;;EAEvB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Ref, ShallowRef } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/use-drag/index.d.ts
|
|
4
|
+
interface DragParams {
|
|
5
|
+
/** 本次拖动水平距离 */
|
|
6
|
+
x: number;
|
|
7
|
+
/** 本次拖动垂直距离 */
|
|
8
|
+
y: number;
|
|
9
|
+
/** 拖拽目标水平偏移量 */
|
|
10
|
+
offsetX: number;
|
|
11
|
+
/** 拖拽目标垂直偏移量 */
|
|
12
|
+
offsetY: number;
|
|
13
|
+
/** 鼠标事件 */
|
|
14
|
+
e: MouseEvent;
|
|
15
|
+
}
|
|
16
|
+
interface DragOptions {
|
|
17
|
+
/** 拖动目标 */
|
|
18
|
+
target: ShallowRef<HTMLElement | undefined | null> | Ref<HTMLElement | undefined | null>;
|
|
19
|
+
/** 拖动开始 */
|
|
20
|
+
onDragStart?(e: MouseEvent): void;
|
|
21
|
+
/** 拖动结束 */
|
|
22
|
+
onDragEnd?(params: DragParams): void;
|
|
23
|
+
/** 拖动时 */
|
|
24
|
+
onDrag?(params: DragParams): void;
|
|
25
|
+
/** 水平拖动范围 */
|
|
26
|
+
rangeX?: [number, number];
|
|
27
|
+
/** 垂直拖动范围 */
|
|
28
|
+
rangeY?: [number, number];
|
|
29
|
+
/** 初始偏移量 */
|
|
30
|
+
initial?: {
|
|
31
|
+
offsetX?: number;
|
|
32
|
+
offsetY?: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 拖动组合式方法
|
|
37
|
+
* @param options 拖动选项
|
|
38
|
+
*/
|
|
39
|
+
declare function useDrag(options: DragOptions): {
|
|
40
|
+
update: (options: {
|
|
41
|
+
offsetX?: number;
|
|
42
|
+
offsetY?: number;
|
|
43
|
+
}) => void;
|
|
44
|
+
};
|
|
45
|
+
//#endregion
|
|
46
|
+
export { useDrag };
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { onBeforeUnmount, watch } from "vue";
|
|
2
|
+
//#region src/use-drag/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* 拖动组合式方法
|
|
5
|
+
* @param options 拖动选项
|
|
6
|
+
*/
|
|
7
|
+
function useDrag(options) {
|
|
8
|
+
const { target, onDragStart, onDrag, onDragEnd, rangeX, rangeY, initial } = options;
|
|
9
|
+
let originX = 0;
|
|
10
|
+
let originY = 0;
|
|
11
|
+
let offsetX = initial?.offsetX ?? 0;
|
|
12
|
+
let offsetY = initial?.offsetY ?? 0;
|
|
13
|
+
const dragParams = {
|
|
14
|
+
x: 0,
|
|
15
|
+
y: 0,
|
|
16
|
+
offsetX: 0,
|
|
17
|
+
offsetY: 0,
|
|
18
|
+
e: null
|
|
19
|
+
};
|
|
20
|
+
const onselectstart = document.onselectstart;
|
|
21
|
+
const handleMousedown = (e) => {
|
|
22
|
+
e.stopPropagation();
|
|
23
|
+
if (e.button !== 0) return;
|
|
24
|
+
window.getSelection()?.removeAllRanges();
|
|
25
|
+
e.stopImmediatePropagation();
|
|
26
|
+
originX = e.x;
|
|
27
|
+
originY = e.y;
|
|
28
|
+
onDragStart?.(e);
|
|
29
|
+
document.onselectstart = () => false;
|
|
30
|
+
document.addEventListener("mousemove", handleMousemove, { passive: true });
|
|
31
|
+
document.addEventListener("mouseup", handleMouseup);
|
|
32
|
+
};
|
|
33
|
+
const getOffsetXWithRange = (deltaX) => {
|
|
34
|
+
return Math.max(rangeX[0], Math.min(rangeX[1], offsetX + deltaX));
|
|
35
|
+
};
|
|
36
|
+
const getOffsetXWithoutRange = (deltaX) => {
|
|
37
|
+
return offsetX + deltaX;
|
|
38
|
+
};
|
|
39
|
+
const getOffsetYWithRange = (deltaY) => {
|
|
40
|
+
return Math.max(rangeY[0], Math.min(rangeY[1], offsetY + deltaY));
|
|
41
|
+
};
|
|
42
|
+
const getOffsetYWithoutRange = (deltaY) => {
|
|
43
|
+
return offsetY + deltaY;
|
|
44
|
+
};
|
|
45
|
+
const getOffsetX = rangeX ? getOffsetXWithRange : getOffsetXWithoutRange;
|
|
46
|
+
const getOffsetY = rangeY ? getOffsetYWithRange : getOffsetYWithoutRange;
|
|
47
|
+
const setDragParam = (e) => {
|
|
48
|
+
dragParams.x = e.x - originX;
|
|
49
|
+
dragParams.y = e.y - originY;
|
|
50
|
+
dragParams.offsetX = getOffsetX(dragParams.x);
|
|
51
|
+
dragParams.offsetY = getOffsetY(dragParams.y);
|
|
52
|
+
dragParams.e = e;
|
|
53
|
+
};
|
|
54
|
+
const handleMousemove = (e) => {
|
|
55
|
+
setDragParam(e);
|
|
56
|
+
onDrag?.(dragParams);
|
|
57
|
+
};
|
|
58
|
+
const handleMouseup = (e) => {
|
|
59
|
+
setDragParam(e);
|
|
60
|
+
offsetX = dragParams.offsetX;
|
|
61
|
+
offsetY = dragParams.offsetY;
|
|
62
|
+
onDragEnd?.(dragParams);
|
|
63
|
+
document.onselectstart = onselectstart;
|
|
64
|
+
cleanup();
|
|
65
|
+
};
|
|
66
|
+
const cleanup = () => {
|
|
67
|
+
document.removeEventListener("mousemove", handleMousemove);
|
|
68
|
+
document.removeEventListener("mouseup", handleMouseup);
|
|
69
|
+
};
|
|
70
|
+
watch(target, (dom, oldDom) => {
|
|
71
|
+
oldDom?.removeEventListener("mousedown", handleMousedown);
|
|
72
|
+
if (!dom) return;
|
|
73
|
+
dom.addEventListener("mousedown", handleMousedown);
|
|
74
|
+
}, { immediate: true });
|
|
75
|
+
onBeforeUnmount(() => {
|
|
76
|
+
target.value?.removeEventListener("mousedown", handleMousedown);
|
|
77
|
+
cleanup();
|
|
78
|
+
});
|
|
79
|
+
return { update(options) {
|
|
80
|
+
if (options.offsetX !== void 0) offsetX = options.offsetX;
|
|
81
|
+
if (options.offsetY !== void 0) offsetY = options.offsetY;
|
|
82
|
+
} };
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { useDrag };
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/use-drag/index.ts"],"sourcesContent":["import { type Ref, type ShallowRef, watch, onBeforeUnmount } from 'vue'\n\ninterface DragParams {\n /** 本次拖动水平距离 */\n x: number\n /** 本次拖动垂直距离 */\n y: number\n /** 拖拽目标水平偏移量 */\n offsetX: number\n /** 拖拽目标垂直偏移量 */\n offsetY: number\n /** 鼠标事件 */\n e: MouseEvent\n}\n\ninterface DragOptions {\n /** 拖动目标 */\n target: ShallowRef<HTMLElement | undefined | null> | Ref<HTMLElement | undefined | null>\n /** 拖动开始 */\n onDragStart?(e: MouseEvent): void\n /** 拖动结束 */\n onDragEnd?(params: DragParams): void\n /** 拖动时 */\n onDrag?(params: DragParams): void\n /** 水平拖动范围 */\n rangeX?: [number, number]\n /** 垂直拖动范围 */\n rangeY?: [number, number]\n /** 初始偏移量 */\n initial?: { offsetX?: number; offsetY?: number }\n}\n\n/**\n * 拖动组合式方法\n * @param options 拖动选项\n */\nexport function useDrag(options: DragOptions): {\n update: (options: { offsetX?: number; offsetY?: number }) => void\n} {\n const { target, onDragStart, onDrag, onDragEnd, rangeX, rangeY, initial } = options\n\n // 鼠标拖拽前的坐标\n let originX = 0\n let originY = 0\n\n let offsetX = initial?.offsetX ?? 0\n let offsetY = initial?.offsetY ?? 0\n\n // 拖拽参数\n const dragParams: DragParams = { x: 0, y: 0, offsetX: 0, offsetY: 0, e: null as any }\n\n // 先取\n const onselectstart = document.onselectstart\n\n const handleMousedown = (e: MouseEvent) => {\n // 阻止事件冒泡\n e.stopPropagation()\n // 鼠标左键按下有效\n if (e.button !== 0) return\n // 放置拖拽时选择内容\n window.getSelection()?.removeAllRanges()\n // 阻止后续的事件监听器被执行\n e.stopImmediatePropagation()\n\n originX = e.x\n originY = e.y\n\n onDragStart?.(e)\n\n // 禁止浏览器的选中事件, 直到mouseup事件触发时还原\n document.onselectstart = () => false\n document.addEventListener('mousemove', handleMousemove, { passive: true })\n document.addEventListener('mouseup', handleMouseup)\n }\n\n const getOffsetXWithRange = (deltaX: number) => {\n return Math.max(rangeX![0], Math.min(rangeX![1], offsetX + deltaX))\n }\n\n const getOffsetXWithoutRange = (deltaX: number) => {\n return offsetX + deltaX\n }\n\n const getOffsetYWithRange = (deltaY: number) => {\n return Math.max(rangeY![0], Math.min(rangeY![1], offsetY + deltaY))\n }\n\n const getOffsetYWithoutRange = (deltaY: number) => {\n return offsetY + deltaY\n }\n\n const getOffsetX = rangeX ? getOffsetXWithRange : getOffsetXWithoutRange\n const getOffsetY = rangeY ? getOffsetYWithRange : getOffsetYWithoutRange\n\n // 避免重复创建对象影响内存占用\n const setDragParam = (e: MouseEvent) => {\n dragParams.x = e.x - originX\n dragParams.y = e.y - originY\n dragParams.offsetX = getOffsetX(dragParams.x)\n dragParams.offsetY = getOffsetY(dragParams.y)\n dragParams.e = e\n }\n\n const handleMousemove = (e: MouseEvent) => {\n setDragParam(e)\n onDrag?.(dragParams)\n }\n\n const handleMouseup = (e: MouseEvent) => {\n setDragParam(e)\n offsetX = dragParams.offsetX\n offsetY = dragParams.offsetY\n\n onDragEnd?.(dragParams)\n document.onselectstart = onselectstart\n\n cleanup()\n }\n\n // 统一的清理函数\n const cleanup = () => {\n document.removeEventListener('mousemove', handleMousemove)\n document.removeEventListener('mouseup', handleMouseup)\n }\n\n watch(\n target,\n (dom, oldDom) => {\n oldDom?.removeEventListener('mousedown', handleMousedown)\n if (!dom) return\n dom.addEventListener('mousedown', handleMousedown)\n },\n { immediate: true }\n )\n\n onBeforeUnmount(() => {\n target.value?.removeEventListener('mousedown', handleMousedown)\n cleanup()\n })\n\n return {\n update(options: { offsetX?: number; offsetY?: number }) {\n if (options.offsetX !== undefined) {\n offsetX = options.offsetX\n }\n if (options.offsetY !== undefined) {\n offsetY = options.offsetY\n }\n }\n }\n}\n"],"mappings":";;;;;;AAoCA,SAAgB,QAAQ,SAEtB;CACA,MAAM,EAAE,QAAQ,aAAa,QAAQ,WAAW,QAAQ,QAAQ,YAAY;CAG5E,IAAI,UAAU;CACd,IAAI,UAAU;CAEd,IAAI,UAAU,SAAS,WAAW;CAClC,IAAI,UAAU,SAAS,WAAW;CAGlC,MAAM,aAAyB;EAAE,GAAG;EAAG,GAAG;EAAG,SAAS;EAAG,SAAS;EAAG,GAAG;EAAa;CAGrF,MAAM,gBAAgB,SAAS;CAE/B,MAAM,mBAAmB,MAAkB;AAEzC,IAAE,iBAAiB;AAEnB,MAAI,EAAE,WAAW,EAAG;AAEpB,SAAO,cAAc,EAAE,iBAAiB;AAExC,IAAE,0BAA0B;AAE5B,YAAU,EAAE;AACZ,YAAU,EAAE;AAEZ,gBAAc,EAAE;AAGhB,WAAS,sBAAsB;AAC/B,WAAS,iBAAiB,aAAa,iBAAiB,EAAE,SAAS,MAAM,CAAC;AAC1E,WAAS,iBAAiB,WAAW,cAAc;;CAGrD,MAAM,uBAAuB,WAAmB;AAC9C,SAAO,KAAK,IAAI,OAAQ,IAAI,KAAK,IAAI,OAAQ,IAAI,UAAU,OAAO,CAAC;;CAGrE,MAAM,0BAA0B,WAAmB;AACjD,SAAO,UAAU;;CAGnB,MAAM,uBAAuB,WAAmB;AAC9C,SAAO,KAAK,IAAI,OAAQ,IAAI,KAAK,IAAI,OAAQ,IAAI,UAAU,OAAO,CAAC;;CAGrE,MAAM,0BAA0B,WAAmB;AACjD,SAAO,UAAU;;CAGnB,MAAM,aAAa,SAAS,sBAAsB;CAClD,MAAM,aAAa,SAAS,sBAAsB;CAGlD,MAAM,gBAAgB,MAAkB;AACtC,aAAW,IAAI,EAAE,IAAI;AACrB,aAAW,IAAI,EAAE,IAAI;AACrB,aAAW,UAAU,WAAW,WAAW,EAAE;AAC7C,aAAW,UAAU,WAAW,WAAW,EAAE;AAC7C,aAAW,IAAI;;CAGjB,MAAM,mBAAmB,MAAkB;AACzC,eAAa,EAAE;AACf,WAAS,WAAW;;CAGtB,MAAM,iBAAiB,MAAkB;AACvC,eAAa,EAAE;AACf,YAAU,WAAW;AACrB,YAAU,WAAW;AAErB,cAAY,WAAW;AACvB,WAAS,gBAAgB;AAEzB,WAAS;;CAIX,MAAM,gBAAgB;AACpB,WAAS,oBAAoB,aAAa,gBAAgB;AAC1D,WAAS,oBAAoB,WAAW,cAAc;;AAGxD,OACE,SACC,KAAK,WAAW;AACf,UAAQ,oBAAoB,aAAa,gBAAgB;AACzD,MAAI,CAAC,IAAK;AACV,MAAI,iBAAiB,aAAa,gBAAgB;IAEpD,EAAE,WAAW,MAAM,CACpB;AAED,uBAAsB;AACpB,SAAO,OAAO,oBAAoB,aAAa,gBAAgB;AAC/D,WAAS;GACT;AAEF,QAAO,EACL,OAAO,SAAiD;AACtD,MAAI,QAAQ,YAAY,KAAA,EACtB,WAAU,QAAQ;AAEpB,MAAI,QAAQ,YAAY,KAAA,EACtB,WAAU,QAAQ;IAGvB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ComputedRef } from "vue";
|
|
2
|
+
import { ComponentSize } from "@veltra/utils/types";
|
|
3
|
+
|
|
4
|
+
//#region src/use-fallback-props/index.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* 使用回滚属性,用于控制多级属性的使用优先级,如果多级属性中不存在该值,则使用全局配置中的属性,如再不存在则为undefined
|
|
7
|
+
* @param propsList 属性列表,最右边的属性优先级最高
|
|
8
|
+
* @param fallbackProps 要回滚的属性和默认值
|
|
9
|
+
*/
|
|
10
|
+
declare function useFallbackProps<F extends Record<string, any>, R extends { [key in keyof F]: ComputedRef<F[key]> }>(propsList: Record<string, any>[], fallbackProps: F): R;
|
|
11
|
+
type FormFallbackProps = {
|
|
12
|
+
size: ComponentSize;
|
|
13
|
+
disabled: boolean;
|
|
14
|
+
readonly: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* 表单组件的回滚属性
|
|
18
|
+
* @param propsList props列表
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
declare function useFormFallbackProps(propsList: Record<string, any>[]): { [key in keyof FormFallbackProps]: ComputedRef<FormFallbackProps[key]> };
|
|
22
|
+
/**
|
|
23
|
+
* 表单组件的回滚属性
|
|
24
|
+
* @param propsList props列表
|
|
25
|
+
* @param fallbackProps 回滚属性,可以只指定部分表单属性
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
declare function useFormFallbackProps<F extends Partial<FormFallbackProps>>(propsList: Record<string, any>[], fallbackProps: F): { [key in keyof F]: key extends keyof FormFallbackProps ? ComputedRef<FormFallbackProps[key]> : never };
|
|
29
|
+
//#endregion
|
|
30
|
+
export { useFallbackProps, useFormFallbackProps };
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useConfig } from "../use-config/index.js";
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
//#region src/use-fallback-props/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* 使用回滚属性,用于控制多级属性的使用优先级,如果多级属性中不存在该值,则使用全局配置中的属性,如再不存在则为undefined
|
|
6
|
+
* @param propsList 属性列表,最右边的属性优先级最高
|
|
7
|
+
* @param fallbackProps 要回滚的属性和默认值
|
|
8
|
+
*/
|
|
9
|
+
function useFallbackProps(propsList, fallbackProps) {
|
|
10
|
+
const { config } = useConfig();
|
|
11
|
+
let result = {};
|
|
12
|
+
for (const key in fallbackProps) if (fallbackProps.hasOwnProperty(key)) {
|
|
13
|
+
const defaultValue = fallbackProps[key];
|
|
14
|
+
result[key] = computed(() => {
|
|
15
|
+
for (let i = propsList.length - 1; i > -1; --i) {
|
|
16
|
+
const props = propsList[i];
|
|
17
|
+
if (props[key] !== void 0) return props[key];
|
|
18
|
+
}
|
|
19
|
+
return config[key] ?? defaultValue;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
function useFormFallbackProps(propsList, fallbackProps) {
|
|
25
|
+
if (!fallbackProps) fallbackProps = {
|
|
26
|
+
size: "default",
|
|
27
|
+
disabled: false,
|
|
28
|
+
readonly: false
|
|
29
|
+
};
|
|
30
|
+
return useFallbackProps(propsList, fallbackProps);
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { useFallbackProps, useFormFallbackProps };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/use-fallback-props/index.ts"],"sourcesContent":["import type { ComponentSize } from '@veltra/utils/types'\nimport { computed, type ComputedRef } from 'vue'\n\nimport { useConfig } from '../use-config'\n\n/**\n * 使用回滚属性,用于控制多级属性的使用优先级,如果多级属性中不存在该值,则使用全局配置中的属性,如再不存在则为undefined\n * @param propsList 属性列表,最右边的属性优先级最高\n * @param fallbackProps 要回滚的属性和默认值\n */\nexport function useFallbackProps<\n F extends Record<string, any>,\n R extends {\n [key in keyof F]: ComputedRef<F[key]>\n }\n>(propsList: Record<string, any>[], fallbackProps: F): R {\n const { config } = useConfig()\n\n let result = {} as R\n\n for (const key in fallbackProps) {\n if (fallbackProps.hasOwnProperty(key)) {\n const defaultValue = fallbackProps[key]\n const ref = computed<any>(() => {\n for (let i = propsList.length - 1; i > -1; --i) {\n const props = propsList[i]!\n\n if (props[key] !== undefined) {\n return props[key]\n }\n }\n\n return config[key as string] ?? defaultValue\n })\n\n result[key as keyof F] = ref as R[keyof F]\n }\n }\n\n return result\n}\n\ntype FormFallbackProps = { size: ComponentSize; disabled: boolean; readonly: boolean }\n\n/**\n * 表单组件的回滚属性\n * @param propsList props列表\n * @returns\n */\nexport function useFormFallbackProps(propsList: Record<string, any>[]): {\n [key in keyof FormFallbackProps]: ComputedRef<FormFallbackProps[key]>\n}\n\n/**\n * 表单组件的回滚属性\n * @param propsList props列表\n * @param fallbackProps 回滚属性,可以只指定部分表单属性\n * @returns\n */\nexport function useFormFallbackProps<F extends Partial<FormFallbackProps>>(\n propsList: Record<string, any>[],\n fallbackProps: F\n): {\n [key in keyof F]: key extends keyof FormFallbackProps\n ? ComputedRef<FormFallbackProps[key]>\n : never\n}\nexport function useFormFallbackProps(\n propsList: Record<string, any>[],\n fallbackProps?: Record<string, any>\n): any {\n if (!fallbackProps) {\n fallbackProps = { size: 'default', disabled: false, readonly: false }\n }\n return useFallbackProps(propsList, fallbackProps)\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,iBAKd,WAAkC,eAAqB;CACvD,MAAM,EAAE,WAAW,WAAW;CAE9B,IAAI,SAAS,EAAE;AAEf,MAAK,MAAM,OAAO,cAChB,KAAI,cAAc,eAAe,IAAI,EAAE;EACrC,MAAM,eAAe,cAAc;AAanC,SAAO,OAZK,eAAoB;AAC9B,QAAK,IAAI,IAAI,UAAU,SAAS,GAAG,IAAI,IAAI,EAAE,GAAG;IAC9C,MAAM,QAAQ,UAAU;AAExB,QAAI,MAAM,SAAS,KAAA,EACjB,QAAO,MAAM;;AAIjB,UAAO,OAAO,QAAkB;IAChC;;AAMN,QAAO;;AA4BT,SAAgB,qBACd,WACA,eACK;AACL,KAAI,CAAC,cACH,iBAAgB;EAAE,MAAM;EAAW,UAAU;EAAO,UAAU;EAAO;AAEvE,QAAO,iBAAiB,WAAW,cAAc"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Ref } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/use-focus/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* 聚焦
|
|
6
|
+
* @param cb 回调
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
declare function useFocus(cb?: (focused: boolean) => void): {
|
|
10
|
+
focus: Ref<boolean>;
|
|
11
|
+
handleBlur: () => void;
|
|
12
|
+
handleFocus: () => void;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { useFocus };
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
//#region src/use-focus/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* 聚焦
|
|
5
|
+
* @param cb 回调
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
function useFocus(cb) {
|
|
9
|
+
const focus = ref(false);
|
|
10
|
+
const handleFocus = () => {
|
|
11
|
+
focus.value = true;
|
|
12
|
+
cb?.(focus.value);
|
|
13
|
+
};
|
|
14
|
+
const handleBlur = () => {
|
|
15
|
+
focus.value = false;
|
|
16
|
+
cb?.(focus.value);
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
focus,
|
|
20
|
+
handleBlur,
|
|
21
|
+
handleFocus
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { useFocus };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/use-focus/index.ts"],"sourcesContent":["import { ref, type Ref } from 'vue'\n\n/**\n * 聚焦\n * @param cb 回调\n * @returns\n */\nexport function useFocus(cb?: (focused: boolean) => void): {\n focus: Ref<boolean>\n handleBlur: () => void\n handleFocus: () => void\n} {\n const focus = ref(false)\n\n const handleFocus = () => {\n focus.value = true\n cb?.(focus.value)\n }\n\n const handleBlur = () => {\n focus.value = false\n cb?.(focus.value)\n }\n\n return { focus, handleBlur, handleFocus }\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,SAAS,IAIvB;CACA,MAAM,QAAQ,IAAI,MAAM;CAExB,MAAM,oBAAoB;AACxB,QAAM,QAAQ;AACd,OAAK,MAAM,MAAM;;CAGnB,MAAM,mBAAmB;AACvB,QAAM,QAAQ;AACd,OAAK,MAAM,MAAM;;AAGnB,QAAO;EAAE;EAAO;EAAY;EAAa"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FormContextInjectProps } from "@veltra/utils/types";
|
|
2
|
+
|
|
3
|
+
//#region src/use-form-component/index.d.ts
|
|
4
|
+
type DIContext = {
|
|
5
|
+
/** 表单属性 */formProps: FormContextInjectProps;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* 表单组件本身的组合式方法
|
|
9
|
+
* @param props 表单属性
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
declare function useFormComponent(props: FormContextInjectProps): void;
|
|
13
|
+
/**
|
|
14
|
+
* 表单内的组件的组合式方法
|
|
15
|
+
* @returns 提供一个form的上下文
|
|
16
|
+
*/
|
|
17
|
+
declare function useFormComponent(): {
|
|
18
|
+
/** 是否在表单中 */inForm: boolean;
|
|
19
|
+
} & Partial<DIContext>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { useFormComponent };
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { inject, provide } from "vue";
|
|
2
|
+
//#region src/use-form-component/index.ts
|
|
3
|
+
const FormComponentDIKey = Symbol("FormComponentDIKey");
|
|
4
|
+
function useFormComponent(props) {
|
|
5
|
+
if (props) return provide(FormComponentDIKey, { formProps: props });
|
|
6
|
+
const context = inject(FormComponentDIKey, void 0) || {};
|
|
7
|
+
return {
|
|
8
|
+
inForm: !!context,
|
|
9
|
+
...context
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { useFormComponent };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/use-form-component/index.ts"],"sourcesContent":["import type { FormContextInjectProps } from '@veltra/utils/types'\nimport { type InjectionKey, inject, provide } from 'vue'\n\ntype DIContext = {\n /** 表单属性 */\n formProps: FormContextInjectProps\n}\n\nconst FormComponentDIKey: InjectionKey<DIContext> = Symbol('FormComponentDIKey')\n\n/**\n * 表单组件本身的组合式方法\n * @param props 表单属性\n * @returns\n */\nexport function useFormComponent(props: FormContextInjectProps): void\n/**\n * 表单内的组件的组合式方法\n * @returns 提供一个form的上下文\n */\nexport function useFormComponent(): {\n /** 是否在表单中 */\n inForm: boolean\n} & Partial<DIContext>\nexport function useFormComponent(props?: any): any {\n if (props) {\n return provide(FormComponentDIKey, { formProps: props })\n }\n const context = inject(FormComponentDIKey, undefined) || {}\n return { inForm: !!context, ...context }\n}\n"],"mappings":";;AAQA,MAAM,qBAA8C,OAAO,qBAAqB;AAgBhF,SAAgB,iBAAiB,OAAkB;AACjD,KAAI,MACF,QAAO,QAAQ,oBAAoB,EAAE,WAAW,OAAO,CAAC;CAE1D,MAAM,UAAU,OAAO,oBAAoB,KAAA,EAAU,IAAI,EAAE;AAC3D,QAAO;EAAE,QAAQ,CAAC,CAAC;EAAS,GAAG;EAAS"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/use-lock/index.d.ts
|
|
2
|
+
type Update = (fn: Function) => any;
|
|
3
|
+
type Lock = (fn: Function) => Promise<void>;
|
|
4
|
+
interface Updater {
|
|
5
|
+
/**
|
|
6
|
+
* 更新
|
|
7
|
+
* @description 在非锁定时执行传入的函数
|
|
8
|
+
*/
|
|
9
|
+
update: Update;
|
|
10
|
+
/**
|
|
11
|
+
* 更新并锁定
|
|
12
|
+
* @description 执行传入的函数,并锁定更新操作,直到函数执行完成
|
|
13
|
+
*/
|
|
14
|
+
updateAndLock: Lock;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 数据更新锁
|
|
18
|
+
* @description
|
|
19
|
+
* 更新锁主要用于防止组件数据更新时,循环触发更新。
|
|
20
|
+
*
|
|
21
|
+
* @returns 该函数返回两个函数:
|
|
22
|
+
* 1. update: 更新函数,在非锁定时执行传入的函数
|
|
23
|
+
* 2. lock: 锁定函数,执行时会锁定更新操作,直到锁定操作结束
|
|
24
|
+
*/
|
|
25
|
+
declare function useUpdateLock(): Updater;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { Updater, useUpdateLock };
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { nextTick } from "vue";
|
|
2
|
+
//#region src/use-lock/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* 数据更新锁
|
|
5
|
+
* @description
|
|
6
|
+
* 更新锁主要用于防止组件数据更新时,循环触发更新。
|
|
7
|
+
*
|
|
8
|
+
* @returns 该函数返回两个函数:
|
|
9
|
+
* 1. update: 更新函数,在非锁定时执行传入的函数
|
|
10
|
+
* 2. lock: 锁定函数,执行时会锁定更新操作,直到锁定操作结束
|
|
11
|
+
*/
|
|
12
|
+
function useUpdateLock() {
|
|
13
|
+
let lockedCount = 0;
|
|
14
|
+
function update(fn) {
|
|
15
|
+
if (lockedCount > 0) return;
|
|
16
|
+
return fn();
|
|
17
|
+
}
|
|
18
|
+
async function updateAndLock(fn) {
|
|
19
|
+
lockedCount++;
|
|
20
|
+
try {
|
|
21
|
+
await fn();
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error(error);
|
|
24
|
+
}
|
|
25
|
+
await nextTick();
|
|
26
|
+
lockedCount--;
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
updateAndLock,
|
|
30
|
+
update
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { useUpdateLock };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/use-lock/index.ts"],"sourcesContent":["import { nextTick } from 'vue'\n\ntype Update = (fn: Function) => any\ntype Lock = (fn: Function) => Promise<void>\n\nexport interface Updater {\n /**\n * 更新\n * @description 在非锁定时执行传入的函数\n */\n update: Update\n /**\n * 更新并锁定\n * @description 执行传入的函数,并锁定更新操作,直到函数执行完成\n */\n updateAndLock: Lock\n}\n\n/**\n * 数据更新锁\n * @description\n * 更新锁主要用于防止组件数据更新时,循环触发更新。\n *\n * @returns 该函数返回两个函数:\n * 1. update: 更新函数,在非锁定时执行传入的函数\n * 2. lock: 锁定函数,执行时会锁定更新操作,直到锁定操作结束\n */\nexport function useUpdateLock(): Updater {\n let lockedCount = 0\n\n function update(fn: Function) {\n if (lockedCount > 0) return\n return fn()\n }\n\n async function updateAndLock(fn: Function) {\n lockedCount++\n\n try {\n await fn()\n } catch (error) {\n console.error(error)\n }\n await nextTick()\n\n lockedCount--\n }\n\n return { updateAndLock, update }\n}\n"],"mappings":";;;;;;;;;;;AA2BA,SAAgB,gBAAyB;CACvC,IAAI,cAAc;CAElB,SAAS,OAAO,IAAc;AAC5B,MAAI,cAAc,EAAG;AACrB,SAAO,IAAI;;CAGb,eAAe,cAAc,IAAc;AACzC;AAEA,MAAI;AACF,SAAM,IAAI;WACH,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,QAAM,UAAU;AAEhB;;AAGF,QAAO;EAAE;EAAe;EAAQ"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Ref } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/use-model/index.d.ts
|
|
4
|
+
interface ModelOptions<Props extends Record<string, unknown>, Name extends keyof Props> {
|
|
5
|
+
/** 组件定义的属性 */
|
|
6
|
+
props: Props;
|
|
7
|
+
/** 属性名称 */
|
|
8
|
+
propName?: Name;
|
|
9
|
+
/** 事件触发函数 */
|
|
10
|
+
emit: (...args: any[]) => void;
|
|
11
|
+
/** 是否为本地模式, 默认为true, 本地模式允许组件不受控来触发视图更新 */
|
|
12
|
+
local?: boolean | (() => boolean);
|
|
13
|
+
/** 默认值 */
|
|
14
|
+
defaultValue?: Props[Name];
|
|
15
|
+
/**
|
|
16
|
+
* 是否浅层响应
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
shallow?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 返回一个基于提供的选项的响应式模型值。
|
|
23
|
+
* 该方法在将来可能会被替代, 目前使用是为了类型提示可用
|
|
24
|
+
* 如果 local 选项为true, 模型值将是响应式的,并与属性值同步。
|
|
25
|
+
* 如果 local 选项为 false,则模型值将是一个代理对象,具有 getter 和 setter。当值发生更改时,它会触发一个更新事件。
|
|
26
|
+
* @param options - 选项
|
|
27
|
+
* @returns - 一个模型值
|
|
28
|
+
*/
|
|
29
|
+
declare function useModel<Props extends Record<string, any>, Name extends keyof Props = 'modelValue'>(options: ModelOptions<Props, Name>): Ref<Props[Name] | undefined> | {
|
|
30
|
+
__v_isRef: boolean;
|
|
31
|
+
value: Props[Name];
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { useModel };
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|