@gx-design-vue/pro-utils 0.2.0-beta.86 → 0.2.0-beta.88

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.
Files changed (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -2
  3. package/dist/array/index.d.ts +5 -0
  4. package/dist/array/index.js +6 -0
  5. package/dist/array/slice.d.ts +4 -0
  6. package/dist/array/slice.js +28 -0
  7. package/dist/array/sort.d.ts +7 -0
  8. package/dist/array/sort.js +65 -0
  9. package/dist/array/tree.d.ts +25 -0
  10. package/dist/array/tree.js +157 -0
  11. package/dist/array/unique.d.ts +6 -0
  12. package/dist/array/unique.js +14 -0
  13. package/dist/base64/index.d.ts +10 -19
  14. package/dist/base64/index.js +106 -0
  15. package/dist/class/index.d.ts +2 -0
  16. package/dist/class/index.js +3 -0
  17. package/dist/class/prefix.d.ts +15 -0
  18. package/dist/class/prefix.js +15 -0
  19. package/dist/clone/cloneDeep.d.ts +4 -0
  20. package/dist/clone/cloneDeep.js +35 -0
  21. package/dist/clone/cloneDeepWith.d.ts +6 -0
  22. package/dist/clone/cloneDeepWith.js +150 -0
  23. package/dist/clone/getTag.d.ts +4 -0
  24. package/dist/clone/getTag.js +13 -0
  25. package/dist/clone/index.d.ts +3 -0
  26. package/dist/clone/index.js +4 -0
  27. package/dist/clone/symbols.d.ts +4 -0
  28. package/dist/clone/symbols.js +13 -0
  29. package/dist/clone/tags.d.ts +25 -0
  30. package/dist/clone/tags.js +48 -0
  31. package/dist/dom/event.d.ts +5 -0
  32. package/dist/dom/event.js +26 -0
  33. package/dist/dom/index.d.ts +5 -0
  34. package/dist/dom/index.js +6 -0
  35. package/dist/dom/measure.d.ts +12 -0
  36. package/dist/dom/measure.js +42 -0
  37. package/dist/dom/raf.d.ts +7 -0
  38. package/dist/dom/raf.js +44 -0
  39. package/dist/dom/scroll.d.ts +10 -0
  40. package/dist/dom/scroll.js +74 -0
  41. package/dist/file/config.d.ts +10 -0
  42. package/dist/file/config.js +81 -0
  43. package/dist/file/convert.d.ts +8 -0
  44. package/dist/file/convert.js +69 -0
  45. package/dist/file/index.d.ts +5 -0
  46. package/dist/file/index.js +6 -0
  47. package/dist/file/media.d.ts +16 -0
  48. package/dist/file/media.js +161 -0
  49. package/dist/file/type.d.ts +6 -0
  50. package/dist/file/type.js +58 -0
  51. package/dist/function/copy.d.ts +6 -0
  52. package/dist/function/copy.js +13 -0
  53. package/dist/function/getValue.d.ts +5 -0
  54. package/dist/function/getValue.js +19 -0
  55. package/dist/function/index.d.ts +5 -0
  56. package/dist/function/index.js +6 -0
  57. package/dist/function/object.d.ts +6 -0
  58. package/dist/function/object.js +33 -0
  59. package/dist/function/run.d.ts +4 -0
  60. package/dist/function/run.js +15 -0
  61. package/dist/index.d.ts +58 -26
  62. package/dist/index.js +60 -0
  63. package/dist/is/base64.d.ts +5 -0
  64. package/dist/is/base64.js +27 -0
  65. package/dist/is/browser.d.ts +4 -0
  66. package/dist/is/browser.js +14 -0
  67. package/dist/is/deepEqual.d.ts +4 -0
  68. package/dist/is/deepEqual.js +62 -0
  69. package/dist/is/device.d.ts +6 -0
  70. package/dist/is/device.js +37 -0
  71. package/dist/is/equal.d.ts +4 -0
  72. package/dist/is/equal.js +34 -0
  73. package/dist/is/img.d.ts +4 -0
  74. package/dist/is/img.js +13 -0
  75. package/dist/is/index.d.ts +16 -0
  76. package/dist/is/index.js +17 -0
  77. package/dist/is/nil.d.ts +5 -0
  78. package/dist/is/nil.js +22 -0
  79. package/dist/is/plainObject.d.ts +5 -0
  80. package/dist/is/plainObject.js +30 -0
  81. package/dist/is/primitive.d.ts +4 -0
  82. package/dist/is/primitive.js +13 -0
  83. package/dist/is/server.d.ts +4 -0
  84. package/dist/is/server.js +10 -0
  85. package/dist/is/type.d.ts +11 -0
  86. package/dist/is/type.js +84 -0
  87. package/dist/is/typedArray.d.ts +4 -0
  88. package/dist/is/typedArray.js +33 -0
  89. package/dist/is/unsafeProperty.d.ts +4 -0
  90. package/dist/is/unsafeProperty.js +18 -0
  91. package/dist/is/url.d.ts +4 -0
  92. package/dist/is/url.js +20 -0
  93. package/dist/is/valid.d.ts +5 -0
  94. package/dist/is/valid.js +23 -0
  95. package/dist/merge/index.d.ts +6 -49
  96. package/dist/merge/index.js +41 -0
  97. package/dist/merge/mergeWith.d.ts +4 -49
  98. package/dist/merge/mergeWith.js +31 -0
  99. package/dist/number/chinese.d.ts +4 -0
  100. package/dist/number/chinese.js +46 -0
  101. package/dist/number/format.d.ts +13 -0
  102. package/dist/number/format.js +72 -0
  103. package/dist/number/index.d.ts +3 -0
  104. package/dist/number/index.js +4 -0
  105. package/dist/object/classNames.d.ts +4 -0
  106. package/dist/object/classNames.js +30 -0
  107. package/dist/object/index.d.ts +5 -0
  108. package/dist/object/index.js +6 -0
  109. package/dist/object/omitBoolean.d.ts +4 -0
  110. package/dist/object/omitBoolean.js +13 -0
  111. package/dist/object/omitUndefined.d.ts +6 -0
  112. package/dist/object/omitUndefined.js +18 -0
  113. package/dist/object/omitUndefinedAndEmptyArr.d.ts +4 -0
  114. package/dist/object/omitUndefinedAndEmptyArr.js +19 -0
  115. package/dist/pro-utils.js +1 -1166
  116. package/dist/string/duration.d.ts +4 -0
  117. package/dist/string/duration.js +25 -0
  118. package/dist/string/empty.d.ts +7 -0
  119. package/dist/string/empty.js +26 -0
  120. package/dist/string/index.d.ts +5 -0
  121. package/dist/string/index.js +6 -0
  122. package/dist/string/nanoid.d.ts +4 -0
  123. package/dist/string/nanoid.js +32 -0
  124. package/dist/string/uuid.d.ts +9 -0
  125. package/dist/string/uuid.js +57 -0
  126. package/dist/table/column.d.ts +13 -0
  127. package/dist/table/column.js +42 -0
  128. package/dist/table/index.d.ts +3 -0
  129. package/dist/table/index.js +4 -0
  130. package/dist/table/page.d.ts +6 -0
  131. package/dist/table/page.js +23 -0
  132. package/dist/typing.d.ts +37 -0
  133. package/dist/typing.js +1 -0
  134. package/dist/vue/index.d.ts +2 -0
  135. package/dist/vue/index.js +3 -0
  136. package/dist/vue/slots.d.ts +56 -0
  137. package/dist/vue/slots.js +89 -0
  138. package/package.json +48 -23
  139. package/dist/classNames/index.d.ts +0 -2
  140. package/dist/cloneDeep/cloneDeepWith.d.ts +0 -43
  141. package/dist/cloneDeep/index.d.ts +0 -47
  142. package/dist/getValueFromObjectByKey/index.d.ts +0 -3
  143. package/dist/isBrowser/index.d.ts +0 -1
  144. package/dist/isDeepEqualReact/index.d.ts +0 -1
  145. package/dist/isImg/index.d.ts +0 -2
  146. package/dist/isNil/index.d.ts +0 -1
  147. package/dist/isServer.d.ts +0 -2
  148. package/dist/isUrl/index.d.ts +0 -6
  149. package/dist/merge/useDeepMege.d.ts +0 -43
  150. package/dist/nanoid/index.d.ts +0 -6
  151. package/dist/omitBoolean/index.d.ts +0 -6
  152. package/dist/omitUndefined/index.d.ts +0 -2
  153. package/dist/omitUndefinedAndEmptyArr/index.d.ts +0 -1
  154. package/dist/pro-utils.umd.cjs +0 -13
  155. package/dist/scroll/easings.d.ts +0 -1
  156. package/dist/scroll/getScroll.d.ts +0 -2
  157. package/dist/scroll/index.d.ts +0 -4
  158. package/dist/scroll/scrollTo.d.ts +0 -10
  159. package/dist/scroll/throttleByAnimationFrame.d.ts +0 -5
  160. package/dist/slots/index.d.ts +0 -68
  161. package/dist/typings/index.d.ts +0 -40
  162. package/dist/utils/config.d.ts +0 -7
  163. package/dist/utils/getSymbols.d.ts +0 -1
  164. package/dist/utils/getTag.d.ts +0 -8
  165. package/dist/utils/index.d.ts +0 -333
  166. package/dist/utils/isEqual.d.ts +0 -9
  167. package/dist/utils/isNotNil.d.ts +0 -1
  168. package/dist/utils/isPlainObject.d.ts +0 -43
  169. package/dist/utils/isPrimitive.d.ts +0 -29
  170. package/dist/utils/isTypedArray.d.ts +0 -27
  171. package/dist/utils/isUnsafeProperty.d.ts +0 -11
  172. package/dist/utils/isValid.d.ts +0 -2
  173. package/dist/utils/raf.d.ts +0 -5
  174. package/dist/utils/tags.d.ts +0 -26
  175. package/dist/utils/validate.d.ts +0 -28
@@ -0,0 +1,4 @@
1
+ //#region src/string/duration.d.ts
2
+ declare function formatDuration(time: number): string;
3
+ //#endregion
4
+ export { formatDuration };
@@ -0,0 +1,25 @@
1
+ //#region src/string/duration.ts
2
+ /**
3
+ * 时长格式转换(秒转 HH:MM:SS)
4
+ *
5
+ * @param time - 秒数
6
+ * @returns 格式化后的时长字符串
7
+ */
8
+ function formatDuration(time) {
9
+ let newTime = "";
10
+ if (time > -1) {
11
+ const hour = Math.floor(time / 3600);
12
+ const min = Math.floor(time / 60) % 60;
13
+ const sec = Number.parseInt(String(time % 60));
14
+ if (hour < 10) newTime = `0${hour}:`;
15
+ else newTime = `${hour}:`;
16
+ if (min < 10) newTime += "0";
17
+ newTime += `${min}:`;
18
+ if (sec < 10) newTime += "0";
19
+ newTime += sec;
20
+ }
21
+ return newTime.split(":")[0] === "00" ? `${newTime.split(":")[1]}:${newTime.split(":")[2]}` : newTime;
22
+ }
23
+
24
+ //#endregion
25
+ export { formatDuration };
@@ -0,0 +1,7 @@
1
+ //#region src/string/empty.d.ts
2
+ declare function handleEmptyField(str: any, customize: any): {
3
+ success: boolean;
4
+ value: any;
5
+ };
6
+ //#endregion
7
+ export { handleEmptyField };
@@ -0,0 +1,26 @@
1
+ //#region src/string/empty.ts
2
+ /**
3
+ * 处理字段为空的情况
4
+ *
5
+ * @param str - 要处理的值
6
+ * @param customize - 自定义空值显示
7
+ * @returns 处理结果
8
+ */
9
+ function handleEmptyField(str, customize) {
10
+ const stringNull = ["null", "undefined"];
11
+ let success = true;
12
+ if (str === 0) success = true;
13
+ else if (stringNull.includes(str)) success = false;
14
+ else if (!str) success = false;
15
+ if (success) return {
16
+ value: str,
17
+ success
18
+ };
19
+ return {
20
+ value: customize === "" ? customize : customize || "-",
21
+ success
22
+ };
23
+ }
24
+
25
+ //#endregion
26
+ export { handleEmptyField };
@@ -0,0 +1,5 @@
1
+ import { formatDuration } from "./duration.js";
2
+ import { handleEmptyField } from "./empty.js";
3
+ import { nanoid } from "./nanoid.js";
4
+ import { getRandomNumber } from "./uuid.js";
5
+ export { formatDuration, getRandomNumber, handleEmptyField, nanoid };
@@ -0,0 +1,6 @@
1
+ import { formatDuration } from "./duration.js";
2
+ import { handleEmptyField } from "./empty.js";
3
+ import { nanoid } from "./nanoid.js";
4
+ import { getRandomNumber } from "./uuid.js";
5
+
6
+ export { formatDuration, getRandomNumber, handleEmptyField, nanoid };
@@ -0,0 +1,4 @@
1
+ //#region src/string/nanoid.d.ts
2
+ declare function nanoid(): string;
3
+ //#endregion
4
+ export { nanoid };
@@ -0,0 +1,32 @@
1
+ //#region src/string/nanoid.ts
2
+ let index = 0;
3
+ /**
4
+ * 生成 nanoid
5
+ *
6
+ * @param t - 长度
7
+ * @returns nanoid 字符串
8
+ */
9
+ function genNanoid(t = 21) {
10
+ if (typeof window === "undefined") return (index += 1).toFixed(0);
11
+ if (!window.crypto) return (index += 1).toFixed(0);
12
+ let e = "";
13
+ const r = crypto.getRandomValues(new Uint8Array(t));
14
+ for (; t--;) {
15
+ const n = 63 & r[t];
16
+ e += n < 36 ? n.toString(36) : n < 62 ? (n - 26).toString(36).toUpperCase() : n < 63 ? "_" : "-";
17
+ }
18
+ return e;
19
+ }
20
+ /**
21
+ * 生成 uuid,如果不支持 randomUUID,就用 genNanoid
22
+ *
23
+ * @returns uuid 字符串
24
+ */
25
+ function nanoid() {
26
+ if (typeof window === "undefined") return genNanoid();
27
+ if (window.crypto && window.crypto.randomUUID && typeof crypto.randomUUID == "function") return crypto.randomUUID();
28
+ return genNanoid();
29
+ }
30
+
31
+ //#endregion
32
+ export { nanoid };
@@ -0,0 +1,9 @@
1
+ //#region src/string/uuid.d.ts
2
+ declare function getRandomNumber(): {
3
+ uuid(len?: number, rad?: number): any;
4
+ uuidFast(): string;
5
+ uuidString(): string;
6
+ uuidCompact(): string;
7
+ };
8
+ //#endregion
9
+ export { getRandomNumber };
@@ -0,0 +1,57 @@
1
+ //#region src/string/uuid.ts
2
+ /**
3
+ * 随机 UUID 生成器
4
+ */
5
+ function getRandomNumber() {
6
+ const CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
7
+ return {
8
+ uuid(len, rad) {
9
+ const chars = CHARS;
10
+ const uuid = [];
11
+ const radix = rad || chars.length;
12
+ let i;
13
+ let r;
14
+ if (len) for (i = 0; i < len; i += 1) uuid[i] = chars[Number.parseInt(String(Math.random() * radix))];
15
+ else {
16
+ uuid[8] = "-";
17
+ uuid[13] = "-";
18
+ uuid[18] = "-";
19
+ uuid[23] = "-";
20
+ uuid[14] = "4";
21
+ for (i = 0; i < 36; i += 1) if (!uuid[i]) {
22
+ r = Math.random() * 16;
23
+ uuid[i] = chars[i === 19 ? r && 3 || 8 : r];
24
+ }
25
+ }
26
+ return uuid.join("");
27
+ },
28
+ uuidFast() {
29
+ const chars = CHARS;
30
+ const uuid = Array.from({ length: 36 });
31
+ let rnd = 0;
32
+ let r;
33
+ let i;
34
+ for (i = 0; i < 36; i += 1) if (i === 8 || i === 13 || i === 18 || i === 23) uuid[i] = "-";
35
+ else if (i === 14) uuid[i] = "4";
36
+ else {
37
+ if (rnd <= 2) rnd = 33554432 + Math.random() * 16777216 || 0;
38
+ r = rnd && 15;
39
+ rnd = rnd > 4;
40
+ uuid[i] = chars[i === 19 ? r && 3 || 8 : r];
41
+ }
42
+ return uuid.join("");
43
+ },
44
+ uuidString() {
45
+ return this.uuidFast().replace(/-/g, "");
46
+ },
47
+ uuidCompact() {
48
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
49
+ const r = Math.random() * 16 || 0;
50
+ return (c === "x" ? r : r && 3 || 8).toString(16);
51
+ });
52
+ }
53
+ };
54
+ }
55
+
56
+ //#endregion
57
+ export { getRandomNumber };
@@ -0,0 +1,13 @@
1
+ import { AlignType } from "../typing.js";
2
+
3
+ //#region src/table/column.d.ts
4
+ declare function genColumnKey(key: string[] | number | string | undefined, index?: number): string;
5
+ declare function handleShowIndex<T extends object>(columns: T[], {
6
+ align,
7
+ showIndex
8
+ }: {
9
+ align: AlignType;
10
+ showIndex: boolean;
11
+ }): T[];
12
+ //#endregion
13
+ export { genColumnKey, handleShowIndex };
@@ -0,0 +1,42 @@
1
+ import { isArray } from "../is/type.js";
2
+ import "../is/index.js";
3
+ import { getRandomNumber } from "../string/uuid.js";
4
+
5
+ //#region src/table/column.ts
6
+ /**
7
+ * 根据 key 和 dataIndex 生成唯一 id
8
+ *
9
+ * @param key - 用户设置的 key
10
+ * @param index - 序列号
11
+ * @returns 唯一 key
12
+ */
13
+ function genColumnKey(key, index) {
14
+ if (key) return isArray(key) ? key.join("-") : key.toString();
15
+ return `${index || 0}`;
16
+ }
17
+ /**
18
+ * 处理表格序号列
19
+ *
20
+ * @param columns - 列配置
21
+ * @param options - 配置选项
22
+ * @returns 处理后的列
23
+ */
24
+ function handleShowIndex(columns, { align, showIndex }) {
25
+ const columnsList = structuredClone(columns);
26
+ if (showIndex && columns.length && columns.every((column) => column.dataIndex !== "sortIndex")) {
27
+ const firstColumnsItem = columns[0];
28
+ columnsList.unshift({
29
+ title: "序号",
30
+ align,
31
+ fixed: firstColumnsItem.fixed,
32
+ width: 60,
33
+ uuid: getRandomNumber().uuid(15),
34
+ dataIndex: "sortIndex",
35
+ key: "sortIndex"
36
+ });
37
+ } else columnsList.filter((item) => item.dataIndex !== "sortIndex");
38
+ return columnsList;
39
+ }
40
+
41
+ //#endregion
42
+ export { genColumnKey, handleShowIndex };
@@ -0,0 +1,3 @@
1
+ import { genColumnKey, handleShowIndex } from "./column.js";
2
+ import { handleCurrentPage } from "./page.js";
3
+ export { genColumnKey, handleCurrentPage, handleShowIndex };
@@ -0,0 +1,4 @@
1
+ import { genColumnKey, handleShowIndex } from "./column.js";
2
+ import { handleCurrentPage } from "./page.js";
3
+
4
+ export { genColumnKey, handleCurrentPage, handleShowIndex };
@@ -0,0 +1,6 @@
1
+ import { BasicTablePageConfig } from "../typing.js";
2
+
3
+ //#region src/table/page.d.ts
4
+ declare function handleCurrentPage(pageConfig: BasicTablePageConfig, currentPage: number): number;
5
+ //#endregion
6
+ export { handleCurrentPage };
@@ -0,0 +1,23 @@
1
+ import { isObject } from "../is/type.js";
2
+ import "../is/index.js";
3
+
4
+ //#region src/table/page.ts
5
+ /**
6
+ * 处理删除后的当前页码
7
+ *
8
+ * @param pageConfig - 分页配置
9
+ * @param currentPage - 当前页数据条数
10
+ * @returns 处理后的页码
11
+ */
12
+ function handleCurrentPage(pageConfig, currentPage) {
13
+ if (isObject(pageConfig)) {
14
+ const { pageSize = 10, total = 0 } = pageConfig;
15
+ let { current = 1 } = pageConfig;
16
+ if (total - currentPage <= pageSize * (current - 1)) current = current - 1;
17
+ return current === 0 ? 1 : current;
18
+ }
19
+ return 1;
20
+ }
21
+
22
+ //#endregion
23
+ export { handleCurrentPage };
@@ -0,0 +1,37 @@
1
+ import { CSSProperties, Slot, VNode, VNodeChild } from "vue";
2
+
3
+ //#region src/typing.d.ts
4
+ type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T;
5
+ type LimitDeepPartial<T, Depth extends number = 5> = Depth extends 0 ? Partial<T> : T extends object ? { [P in keyof T]?: LimitDeepPartial<T[P], Prev[Depth]> } : T;
6
+ type Prev = [0, 0, 1, 2, 3, 4, 5];
7
+ interface Fn<T = any, R = T> {
8
+ (...arg: T[]): R;
9
+ }
10
+ type Nullable<T> = T | null;
11
+ type WithFalse<T> = T | false;
12
+ type RecordType = Record<string, any>;
13
+ type WithIfDefault<T, R = undefined> = R extends undefined ? T : R;
14
+ type ExtendIfDefined<T, R = undefined> = R extends undefined ? T : T & R;
15
+ type WithRequired<T, Keys extends keyof T> = Required<Pick<T, Keys>> & Partial<Omit<T, Keys>>;
16
+ type VueNode = VNodeChild | JSX.Element;
17
+ type CustomRender = Slot | VNodeChild | VNode | ((...props: any[]) => VNode) | ((...props: any[]) => VNode[]) | VNode[] | JSX.Element | string | null | undefined;
18
+ type Breakpoint = 'xxl' | 'xl' | 'lg' | 'md' | 'sm' | 'xs';
19
+ type SizeType = 'small' | 'middle' | 'large' | undefined;
20
+ type AlignType = 'left' | 'center' | 'right';
21
+ type BasicTablePageConfig<T = object> = {
22
+ current: number;
23
+ pageSize: number;
24
+ total?: number;
25
+ } & T | boolean;
26
+ type MediaOptions<T = object> = {
27
+ play: boolean;
28
+ width: number;
29
+ height: number;
30
+ duration: number;
31
+ size?: number | string;
32
+ } & T;
33
+ type OmitUndefined<T> = { [P in keyof T]: NonNullable<T[P]> };
34
+ type SemanticClassNames<Name extends string> = Partial<Record<Name, string>>;
35
+ type SemanticStyles<Name extends string> = Partial<Record<Name, CSSProperties>>;
36
+ //#endregion
37
+ export { AlignType, BasicTablePageConfig, Breakpoint, CustomRender, DeepPartial, ExtendIfDefined, Fn, LimitDeepPartial, MediaOptions, Nullable, OmitUndefined, RecordType, SemanticClassNames, SemanticStyles, SizeType, VueNode, WithFalse, WithIfDefault, WithRequired };
package/dist/typing.js ADDED
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,2 @@
1
+ import { RenderResult, SlotsPropsResult, filterEmpty, getKeys, getSlot, getSlotVNode, getSlotsChildren, getSlotsProps, isEmptyElement, slotRender } from "./slots.js";
2
+ export { RenderResult, SlotsPropsResult, filterEmpty, getKeys, getSlot, getSlotVNode, getSlotsChildren, getSlotsProps, isEmptyElement, slotRender };
@@ -0,0 +1,3 @@
1
+ import { filterEmpty, getKeys, getSlot, getSlotVNode, getSlotsChildren, getSlotsProps, isEmptyElement, slotRender } from "./slots.js";
2
+
3
+ export { filterEmpty, getKeys, getSlot, getSlotVNode, getSlotsChildren, getSlotsProps, isEmptyElement, slotRender };
@@ -0,0 +1,56 @@
1
+ import { CustomRender, WithFalse } from "../typing.js";
2
+ import * as vue0 from "vue";
3
+ import { VNode } from "vue";
4
+
5
+ //#region src/vue/slots.d.ts
6
+ type SlotsPropsResult<S extends object, K extends keyof S, R extends boolean, D = any> = { [P in K]: R extends true ? D extends undefined ? WithFalse<CustomRender> : CustomRender : D extends undefined ? (S[P] | false) : CustomRender };
7
+ type RenderResult<S extends object, K extends keyof S, R extends boolean, D = any> = R extends true ? D extends undefined ? WithFalse<CustomRender> : CustomRender : D extends undefined ? (S[K] | false) : CustomRender;
8
+ declare function getKeys(keys: string | string[]): string | undefined;
9
+ declare function isEmptyElement(c: any): any;
10
+ declare function getSlotsChildren<T extends object = Record<string, any>>(slots: T, key: keyof T): VNode[];
11
+ declare function filterEmpty(vnode?: any, isEmpty?: boolean): VNode<vue0.RendererNode, vue0.RendererElement, {
12
+ [key: string]: any;
13
+ }>[];
14
+ declare function slotRender({
15
+ vnode,
16
+ defaultVNode
17
+ }: {
18
+ vnode: any;
19
+ defaultVNode?: any;
20
+ }, ...arg: any): any;
21
+ declare function getSlot<S extends object, K extends keyof S = keyof S, R extends boolean = false>(options: {
22
+ slots: S;
23
+ props: Record<string, any>;
24
+ key: K;
25
+ render?: R;
26
+ defaultChildren?: undefined;
27
+ }, ...arg: any): RenderResult<S, K, R, undefined>;
28
+ declare function getSlot<S extends object, K extends keyof S = keyof S, R extends boolean = false>(options: {
29
+ slots: S;
30
+ props: Record<string, any>;
31
+ key: K;
32
+ render?: R;
33
+ defaultChildren: any;
34
+ }, ...arg: any): RenderResult<S, K, R>;
35
+ declare function getSlotVNode<S extends object, K extends keyof S = keyof S>(options: {
36
+ slots: S;
37
+ props: Record<string, any>;
38
+ key: K;
39
+ defaultChildren?: any;
40
+ }, ...arg: any): WithFalse<CustomRender>;
41
+ declare function getSlotsProps<S extends object, K extends keyof S = keyof S, R extends boolean = false>(options: {
42
+ slots: S;
43
+ props: Record<string, any>;
44
+ keys: K[];
45
+ render?: R;
46
+ defaultVNodes?: undefined;
47
+ }, ...arg: any): SlotsPropsResult<S, K, R, undefined>;
48
+ declare function getSlotsProps<S extends object, K extends keyof S = keyof S, R extends boolean = false>(options: {
49
+ slots: S;
50
+ props: Record<string, any>;
51
+ keys: K[];
52
+ render?: R;
53
+ defaultVNodes?: any;
54
+ }, ...arg: any): SlotsPropsResult<S, K, R>;
55
+ //#endregion
56
+ export { RenderResult, SlotsPropsResult, filterEmpty, getKeys, getSlot, getSlotVNode, getSlotsChildren, getSlotsProps, isEmptyElement, slotRender };
@@ -0,0 +1,89 @@
1
+ import { isBoolean, isObject } from "../is/type.js";
2
+ import { isValid } from "../is/valid.js";
3
+ import "../is/index.js";
4
+ import { Comment, Fragment, isVNode } from "vue";
5
+
6
+ //#region src/vue/slots.ts
7
+ function getKeys(keys) {
8
+ if (typeof keys !== "string" && !Array.isArray(keys)) return;
9
+ return Array.isArray(keys) ? keys[keys.length - 1] : keys.split(":")?.slice(-1)[0];
10
+ }
11
+ function isEmptyElement(c) {
12
+ return c && (c.type === Comment || c.type === Fragment && c.children.length === 0 || c.type === Text && c.children.trim() === "");
13
+ }
14
+ function getSlotsChildren(slots, key) {
15
+ return filterEmpty(typeof slots[key] === "function" ? slots[key]?.() : []);
16
+ }
17
+ function filterEmpty(vnode = [], isEmpty = true) {
18
+ const temp = Array.isArray(vnode) ? vnode : [vnode];
19
+ const children = [];
20
+ temp.forEach((child) => {
21
+ if (Array.isArray(child)) children.push(...filterEmpty(child, isEmpty));
22
+ else if (child?.type === Fragment || child?.type === "template") children.push(...filterEmpty(child.children, isEmpty));
23
+ else if (child && isVNode(child)) {
24
+ if (isEmpty && !isEmptyElement(child)) children.push(child);
25
+ else if (!isEmpty) children.push(child);
26
+ } else if (isValid(child)) children.push(child);
27
+ });
28
+ return children;
29
+ }
30
+ function slotRender({ vnode, defaultVNode }, ...arg) {
31
+ return vnode === false ? null : typeof vnode === "function" ? vnode?.(...arg) : vnode || defaultVNode;
32
+ }
33
+ function getSlot(options, ...arg) {
34
+ const { slots, key = "default", render, props, defaultChildren } = options;
35
+ let result;
36
+ const value = props[key];
37
+ const slotsValue = slots?.[key];
38
+ const defaultVNode = typeof defaultChildren === "function" ? defaultChildren?.() : defaultChildren;
39
+ if (value === false) result = false;
40
+ else if (value === true) result = slotsValue ?? defaultVNode;
41
+ else if (isObject(value)) if (render) if (isVNode(value)) result = value;
42
+ else result = slotsValue;
43
+ else result = value || slotsValue;
44
+ else result = value || slotsValue;
45
+ return result === false ? false : render ? slotRender({
46
+ vnode: result,
47
+ defaultVNode
48
+ }, ...arg) : result;
49
+ }
50
+ function getSlotVNode(options, ...arg) {
51
+ const { slots, key = "default", props, defaultChildren } = options;
52
+ let result;
53
+ const value = props[key];
54
+ const slotsValue = slots?.[key]?.(...arg);
55
+ const defaultVNode = typeof defaultChildren === "function" ? defaultChildren?.() : defaultChildren;
56
+ if (value === false) result = false;
57
+ else if (value === true) result = slotsValue ?? defaultVNode;
58
+ else if (isObject(value)) if (isVNode(value)) result = value;
59
+ else result = slotsValue;
60
+ else result = value || slotsValue;
61
+ return result === false ? false : slotRender({
62
+ vnode: result,
63
+ defaultVNode
64
+ }, ...arg);
65
+ }
66
+ function getSlotsProps(options, ...arg) {
67
+ const { slots, props, keys, render, defaultVNodes } = options;
68
+ const renderMap = {};
69
+ keys.forEach((key, index) => {
70
+ const defaultChildren = defaultVNodes ? defaultVNodes[index] : null;
71
+ const slotComponents = render ? getSlotVNode({
72
+ slots,
73
+ props,
74
+ key,
75
+ defaultChildren
76
+ }, ...arg) : getSlot({
77
+ slots,
78
+ props,
79
+ key,
80
+ render: false,
81
+ defaultChildren
82
+ }, ...arg);
83
+ if (isBoolean(slotComponents) || slotComponents) renderMap[key] = slotComponents;
84
+ });
85
+ return renderMap;
86
+ }
87
+
88
+ //#endregion
89
+ export { filterEmpty, getKeys, getSlot, getSlotVNode, getSlotsChildren, getSlotsProps, isEmptyElement, slotRender };
package/package.json CHANGED
@@ -1,37 +1,62 @@
1
1
  {
2
2
  "name": "@gx-design-vue/pro-utils",
3
3
  "type": "module",
4
- "version": "0.2.0-beta.86",
4
+ "version": "0.2.0-beta.88",
5
5
  "description": "Gx Design Pro Utils",
6
+ "author": {
7
+ "name": "gx12358",
8
+ "email": "gx12358@gmail.com",
9
+ "url": "https://github.com/gx12358"
10
+ },
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/gx12358/pro-components-next.git",
15
+ "directory": "packages/pro-utils"
16
+ },
6
17
  "exports": {
7
18
  ".": {
8
19
  "types": "./dist/index.d.ts",
9
- "import": "./dist/pro-utils.js",
10
- "require": "./dist/pro-utils.umd.cjs"
11
- }
20
+ "import": "./dist/index.js",
21
+ "default": "./dist/index.js"
22
+ },
23
+ "./dist/*": {
24
+ "types": "./dist/*.d.ts",
25
+ "import": "./dist/*.js",
26
+ "default": "./dist/*.js"
27
+ },
28
+ "./package.json": "./package.json"
12
29
  },
13
- "main": "./dist/pro-utils.umd.cjs",
14
- "module": "./dist/pro-utils.js",
15
- "types": "./dist",
30
+ "unpkg": "dist/pro-utils.js",
31
+ "jsdelivr": "dist/pro-utils.js",
16
32
  "files": [
17
- "dist"
33
+ "dist",
34
+ "package.json"
18
35
  ],
19
- "scripts": {
20
- "dev": "vite",
21
- "build": "vite build",
22
- "types": "vue-tsc --declaration --emitDeclarationOnly",
23
- "preview": "vite preview --port 5050",
24
- "test:unit": "vitest --environment jsdom",
25
- "typecheck": "vue-tsc --noEmit && vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
26
- "lint": "TIMING=1 eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
36
+ "contributes": {
37
+ "html": {
38
+ "customData": [
39
+ "./web-tags.json"
40
+ ]
41
+ }
27
42
  },
28
43
  "peerDependencies": {
29
- "vue": ">=3.0.0"
44
+ "vue": ">=3.2.0"
30
45
  },
31
- "devDependencies": {
32
- "typescript": "^5.3.3"
46
+ "dependencies": {
47
+ "dayjs": "^1.11.19"
33
48
  },
34
- "authors": [
35
- "gx12358 <gx12358@gmail.com> (https://github.com/gx12358)"
36
- ]
37
- }
49
+ "web-types": "web-types.json",
50
+ "browserslist": [
51
+ "> 1%",
52
+ "not ie 11",
53
+ "not op_mini all"
54
+ ],
55
+ "scripts": {
56
+ "test": "vitest run",
57
+ "build": "run-s build:esm build:umd",
58
+ "build:esm": "tsdown",
59
+ "build:umd": "vite build",
60
+ "prepublish": "pnpm build"
61
+ }
62
+ }
@@ -1,2 +0,0 @@
1
- declare function classNames(...args: any[]): string;
2
- export default classNames;
@@ -1,43 +0,0 @@
1
- /**
2
- * Deeply clones the given object.
3
- *
4
- * You can customize the deep cloning process using the `cloneValue` function.
5
- * The function takes the current value `value`, the property name `key`, and the entire object `obj` as arguments.
6
- * If the function returns a value, that value is used;
7
- * if it returns `undefined`, the default cloning method is used.
8
- *
9
- * @template T - The type of the object.
10
- * @param {T} obj - The object to clone.
11
- * @param {Function} [cloneValue] - A function to customize the cloning process.
12
- * @returns {T} - A deep clone of the given object.
13
- *
14
- * @example
15
- * // Clone a primitive value
16
- * const num = 29;
17
- * const clonedNum = cloneDeepWith(num);
18
- * console.log(clonedNum); // 29
19
- * console.log(clonedNum === num); // true
20
- *
21
- * @example
22
- * // Clone an object with a customizer
23
- * const obj = { a: 1, b: 2 };
24
- * const clonedObj = cloneDeepWith(obj, (value) => {
25
- * if (typeof value === 'number') {
26
- * return value * 2; // Double the number
27
- * }
28
- * });
29
- * console.log(clonedObj); // { a: 2, b: 4 }
30
- * console.log(clonedObj === obj); // false
31
- *
32
- * @example
33
- * // Clone an array with a customizer
34
- * const arr = [1, 2, 3];
35
- * const clonedArr = cloneDeepWith(arr, (value) => {
36
- * return value + 1; // Increment each value
37
- * });
38
- * console.log(clonedArr); // [2, 3, 4]
39
- * console.log(clonedArr === arr); // false
40
- */
41
- export declare function cloneDeepWith<T>(obj: T, cloneValue: (value: any, key: PropertyKey | undefined, obj: T, stack: Map<any, any>) => any): T;
42
- export declare function cloneDeepWithImpl<T>(valueToClone: any, keyToClone: PropertyKey | undefined, objectToClone: T, stack?: Map<any, any>, cloneValue?: ((value: any, key: PropertyKey | undefined, obj: T, stack: Map<any, any>) => any) | undefined): T;
43
- export declare function copyProperties<T>(target: any, source: any, objectToClone?: T, stack?: Map<any, any> | undefined, cloneValue?: ((value: any, key: PropertyKey | undefined, obj: T, stack: Map<any, any>) => any) | undefined): void;