@yugu-ui/shared 0.0.0-stage → 0.1.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.
Files changed (66) hide show
  1. package/bin.ts +4 -0
  2. package/dist/bin.d.ts +0 -0
  3. package/dist/hooks/index.d.ts +8 -0
  4. package/dist/hooks/use-boolean.d.ts +12 -0
  5. package/dist/hooks/use-context.d.ts +15 -0
  6. package/dist/hooks/use-count-down.d.ts +12 -0
  7. package/dist/hooks/use-loading.d.ts +10 -0
  8. package/dist/hooks/use-request.d.ts +23 -0
  9. package/dist/hooks/use-svg-icon-render.d.ts +19 -0
  10. package/dist/hooks/use-table.d.ts +63 -0
  11. package/dist/hooks.d.ts +2 -0
  12. package/dist/hooks.js +205 -0
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.js +3110 -0
  15. package/dist/nanoid-CQE6QAZJ.js +2 -0
  16. package/dist/request/constant.d.ts +6 -0
  17. package/dist/request/index.d.ts +22 -0
  18. package/dist/request/options.d.ts +6 -0
  19. package/dist/request/shared.d.ts +17 -0
  20. package/dist/request/type.d.ts +94 -0
  21. package/dist/request.d.ts +2 -0
  22. package/dist/request.js +182 -0
  23. package/dist/scripts/src/commands/changelog.d.ts +2 -0
  24. package/dist/scripts/src/commands/cleanup.d.ts +1 -0
  25. package/dist/scripts/src/commands/git-commit.d.ts +9 -0
  26. package/dist/scripts/src/commands/index.d.ts +6 -0
  27. package/dist/scripts/src/commands/release.d.ts +1 -0
  28. package/dist/scripts/src/commands/router.d.ts +2 -0
  29. package/dist/scripts/src/commands/update-pkg.d.ts +1 -0
  30. package/dist/scripts/src/config/index.d.ts +2 -0
  31. package/dist/scripts/src/index.d.ts +1 -0
  32. package/dist/scripts/src/locales/index.d.ts +25 -0
  33. package/dist/scripts/src/shared/index.d.ts +2 -0
  34. package/dist/scripts/src/types/index.d.ts +30 -0
  35. package/dist/uno-preset/index.d.ts +4 -0
  36. package/dist/uno-preset.d.ts +6 -0
  37. package/dist/uno-preset.js +49 -0
  38. package/dist/utils/color/constant/index.d.ts +2 -0
  39. package/dist/utils/color/constant/name.d.ts +8 -0
  40. package/dist/utils/color/constant/palette.d.ts +2 -0
  41. package/dist/utils/color/index.d.ts +5 -0
  42. package/dist/utils/color/palette/antd.d.ts +18 -0
  43. package/dist/utils/color/palette/index.d.ts +17 -0
  44. package/dist/utils/color/palette/recommend.d.ts +20 -0
  45. package/dist/utils/color/shared/colord.d.ts +38 -0
  46. package/dist/utils/color/shared/index.d.ts +2 -0
  47. package/dist/utils/color/shared/name.d.ts +6 -0
  48. package/dist/utils/color/types/index.d.ts +52 -0
  49. package/dist/utils/index.d.ts +4 -0
  50. package/dist/utils/klona.d.ts +2 -0
  51. package/dist/utils/nanoid.d.ts +1 -0
  52. package/dist/utils/storage.d.ts +28 -0
  53. package/package.json +84 -4
  54. package/scripts/src/commands/changelog.ts +10 -0
  55. package/scripts/src/commands/cleanup.ts +5 -0
  56. package/scripts/src/commands/git-commit.ts +107 -0
  57. package/scripts/src/commands/index.ts +6 -0
  58. package/scripts/src/commands/release.ts +12 -0
  59. package/scripts/src/commands/router.ts +90 -0
  60. package/scripts/src/commands/update-pkg.ts +5 -0
  61. package/scripts/src/config/index.ts +39 -0
  62. package/scripts/src/index.ts +110 -0
  63. package/scripts/src/locales/index.ts +84 -0
  64. package/scripts/src/shared/index.ts +7 -0
  65. package/scripts/src/types/index.ts +31 -0
  66. package/README.md +0 -3
package/bin.ts ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env tsx
2
+
3
+ // Developed collaboratively with vscode - 改动代码行数: 1行(阶段 1 五包合一:scripts 源码移至 scripts/,修正入口相对路径)
4
+ import './scripts/src/index';
package/dist/bin.d.ts ADDED
File without changes
@@ -0,0 +1,8 @@
1
+ import { default as useBoolean } from './use-boolean';
2
+ import { default as useLoading } from './use-loading';
3
+ import { default as useCountDown } from './use-count-down';
4
+ import { default as useContext } from './use-context';
5
+ import { default as useSvgIconRender } from './use-svg-icon-render';
6
+ import { default as useTable } from './use-table';
7
+ export { useBoolean, useLoading, useCountDown, useContext, useSvgIconRender, useTable };
8
+ export type * from './use-table';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Boolean
3
+ *
4
+ * @param initValue Init value
5
+ */
6
+ export default function useBoolean(initValue?: boolean): {
7
+ bool: import('vue').Ref<boolean, boolean>;
8
+ setBool: (value: boolean) => void;
9
+ setTrue: () => void;
10
+ setFalse: () => void;
11
+ toggle: () => void;
12
+ };
@@ -0,0 +1,15 @@
1
+ type ContextName = string | {
2
+ name: string;
3
+ key: string | symbol;
4
+ };
5
+ type ContextValue<T> = T extends (...args: any[]) => any ? ReturnType<T> : T;
6
+ type ContextProvider<T> = T extends (...args: any[]) => any ? T : (arg: T) => T;
7
+ type ContextConsumer<Context> = <N extends string | null | undefined = undefined>(consumerName?: N, defaultValue?: Context) => N extends null | undefined ? Context | null : Context;
8
+ /**
9
+ * Creates a context provider and consumer pair.
10
+ *
11
+ * @param contextName - The name of the context. This can be a string or an object with a `name` and `key` property.
12
+ * @param composable - An optional composable function that returns the context value. If not provided, the context value will be the first argument passed to the provider.
13
+ */
14
+ export default function useContext<T>(contextName: ContextName, composable?: T extends (...args: any[]) => any ? T : never): [ContextProvider<T>, ContextConsumer<ContextValue<T>>];
15
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A hook for implementing a countdown timer. It uses `requestAnimationFrame` for smooth and accurate timing,
3
+ * independent of the screen refresh rate.
4
+ *
5
+ * @param initialSeconds - The total number of seconds for the countdown.
6
+ */
7
+ export default function useCountDown(initialSeconds: number): {
8
+ count: import('vue').ComputedRef<number>;
9
+ isCounting: import('vue').ComputedRef<boolean>;
10
+ start: (updatedSeconds?: number) => void;
11
+ stop: () => void;
12
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Loading
3
+ *
4
+ * @param initValue Init value
5
+ */
6
+ export default function useLoading(initValue?: boolean): {
7
+ loading: import('vue').Ref<boolean, boolean>;
8
+ startLoading: () => void;
9
+ endLoading: () => void;
10
+ };
@@ -0,0 +1,23 @@
1
+ import { Ref } from 'vue';
2
+ import { AxiosError, CreateAxiosDefaults, CustomAxiosRequestConfig, MappedType, RequestInstanceCommon, RequestOption, ResponseType } from '../request/index';
3
+ export type HookRequestInstanceResponseSuccessData<ApiData> = {
4
+ data: Ref<ApiData>;
5
+ error: Ref<null>;
6
+ };
7
+ export type HookRequestInstanceResponseFailData<ResponseData> = {
8
+ data: Ref<null>;
9
+ error: Ref<AxiosError<ResponseData>>;
10
+ };
11
+ export type HookRequestInstanceResponseData<ResponseData, ApiData> = {
12
+ loading: Ref<boolean>;
13
+ } & (HookRequestInstanceResponseSuccessData<ApiData> | HookRequestInstanceResponseFailData<ResponseData>);
14
+ export interface HookRequestInstance<ResponseData, ApiData, State extends Record<string, unknown>> extends RequestInstanceCommon<State> {
15
+ <T extends ApiData = ApiData, R extends ResponseType = 'json'>(config: CustomAxiosRequestConfig): HookRequestInstanceResponseData<ResponseData, MappedType<R, T>>;
16
+ }
17
+ /**
18
+ * create a hook request instance
19
+ *
20
+ * @param axiosConfig
21
+ * @param options
22
+ */
23
+ export default function createHookRequest<ResponseData, ApiData, State extends Record<string, unknown>>(axiosConfig?: CreateAxiosDefaults, options?: Partial<RequestOption<ResponseData, ApiData, State>>): HookRequestInstance<ResponseData, ApiData, State>;
@@ -0,0 +1,19 @@
1
+ import { Component } from 'vue';
2
+ /**
3
+ * Svg icon render hook
4
+ *
5
+ * @param SvgIcon Svg icon component
6
+ */
7
+ export interface IconConfig {
8
+ /** Local icon name */
9
+ localIcon?: string;
10
+ /** Icon color */
11
+ color?: string;
12
+ /** Icon size */
13
+ fontSize?: number;
14
+ }
15
+ export default function useSvgIconRender(SvgIcon: Component): {
16
+ SvgIconVNode: (config: IconConfig) => (() => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
17
+ [key: string]: any;
18
+ }>) | undefined;
19
+ };
@@ -0,0 +1,63 @@
1
+ import { Ref, VNodeChild } from 'vue';
2
+ export interface PaginationData<T> {
3
+ data: T[];
4
+ pageNum: number;
5
+ total: number;
6
+ }
7
+ type GetApiData<ApiData, Pagination extends boolean> = Pagination extends true ? PaginationData<ApiData> : ApiData[];
8
+ type Transform<ResponseData, ApiData, Pagination extends boolean> = (response: ResponseData) => GetApiData<ApiData, Pagination>;
9
+ export type TableColumnCheckTitle = string | ((...args: any) => VNodeChild);
10
+ export type TableColumnCheck = {
11
+ titleText?: string;
12
+ key: string;
13
+ title: TableColumnCheckTitle;
14
+ checked: boolean;
15
+ visible: boolean;
16
+ fixed: 'left' | 'right' | 'unFixed';
17
+ };
18
+ export interface UseTableOptions<ResponseData, ApiData, Column, Pagination extends boolean> {
19
+ /**
20
+ * api function to get table data
21
+ */
22
+ api: () => Promise<ResponseData>;
23
+ /**
24
+ * whether to enable pagination
25
+ */
26
+ pagination?: Pagination;
27
+ /**
28
+ * transform api response to table data
29
+ */
30
+ transform: Transform<ResponseData, ApiData, Pagination>;
31
+ /**
32
+ * columns factory
33
+ */
34
+ columns: () => Column[];
35
+ /**
36
+ * get column checks
37
+ */
38
+ getColumnChecks: (columns: Column[]) => TableColumnCheck[];
39
+ /**
40
+ * get columns
41
+ */
42
+ getColumns: (columns: Column[], checks: TableColumnCheck[]) => Column[];
43
+ /**
44
+ * callback when response fetched
45
+ */
46
+ onFetched?: (data: GetApiData<ApiData, Pagination>) => void | Promise<void>;
47
+ /**
48
+ * whether to get data immediately
49
+ *
50
+ * @default true
51
+ */
52
+ immediate?: boolean;
53
+ }
54
+ export default function useTable<ResponseData, ApiData, Column, Pagination extends boolean>(options: UseTableOptions<ResponseData, ApiData, Column, Pagination>): {
55
+ loading: Ref<boolean, boolean>;
56
+ empty: Ref<boolean, boolean>;
57
+ data: Ref<ApiData[], ApiData[]>;
58
+ columns: import('vue').ComputedRef<Column[]>;
59
+ columnChecks: Ref<TableColumnCheck[], TableColumnCheck[]>;
60
+ reloadColumns: () => void;
61
+ getData: () => Promise<void>;
62
+ };
63
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './hooks/index.js'
2
+ export {}
package/dist/hooks.js ADDED
@@ -0,0 +1,205 @@
1
+ import { computed, h, inject, onScopeDispose, provide, ref } from "vue";
2
+ import { useRafFn } from "@vueuse/core";
3
+ //#region src/hooks/use-boolean.ts
4
+ /**
5
+ * Boolean
6
+ *
7
+ * @param initValue Init value
8
+ */
9
+ function useBoolean(initValue = false) {
10
+ const bool = ref(initValue);
11
+ function setBool(value) {
12
+ bool.value = value;
13
+ }
14
+ function setTrue() {
15
+ setBool(true);
16
+ }
17
+ function setFalse() {
18
+ setBool(false);
19
+ }
20
+ function toggle() {
21
+ setBool(!bool.value);
22
+ }
23
+ return {
24
+ bool,
25
+ setBool,
26
+ setTrue,
27
+ setFalse,
28
+ toggle
29
+ };
30
+ }
31
+ //#endregion
32
+ //#region src/hooks/use-loading.ts
33
+ /**
34
+ * Loading
35
+ *
36
+ * @param initValue Init value
37
+ */
38
+ function useLoading(initValue = false) {
39
+ const { bool: loading, setTrue: startLoading, setFalse: endLoading } = useBoolean(initValue);
40
+ return {
41
+ loading,
42
+ startLoading,
43
+ endLoading
44
+ };
45
+ }
46
+ //#endregion
47
+ //#region src/hooks/use-count-down.ts
48
+ /**
49
+ * A hook for implementing a countdown timer. It uses `requestAnimationFrame` for smooth and accurate timing,
50
+ * independent of the screen refresh rate.
51
+ *
52
+ * @param initialSeconds - The total number of seconds for the countdown.
53
+ */
54
+ function useCountDown(initialSeconds) {
55
+ const remainingSeconds = ref(0);
56
+ const count = computed(() => Math.ceil(remainingSeconds.value));
57
+ const isCounting = computed(() => remainingSeconds.value > 0);
58
+ const { pause, resume } = useRafFn(({ delta }) => {
59
+ if (remainingSeconds.value <= 0) {
60
+ remainingSeconds.value = 0;
61
+ pause();
62
+ return;
63
+ }
64
+ const secondsPassed = delta / 1e3;
65
+ remainingSeconds.value -= secondsPassed;
66
+ if (remainingSeconds.value <= 0) {
67
+ remainingSeconds.value = 0;
68
+ pause();
69
+ }
70
+ }, { immediate: false });
71
+ /**
72
+ * Starts the countdown.
73
+ *
74
+ * @param [updatedSeconds=initialSeconds] - Optionally, start with a new duration. Default is `initialSeconds`
75
+ */
76
+ function start(updatedSeconds = initialSeconds) {
77
+ remainingSeconds.value = updatedSeconds;
78
+ resume();
79
+ }
80
+ /** Stops the countdown and resets the remaining time to 0. */
81
+ function stop() {
82
+ remainingSeconds.value = 0;
83
+ pause();
84
+ }
85
+ onScopeDispose(() => {
86
+ pause();
87
+ });
88
+ return {
89
+ count,
90
+ isCounting,
91
+ start,
92
+ stop
93
+ };
94
+ }
95
+ //#endregion
96
+ //#region src/hooks/use-context.ts
97
+ /**
98
+ * Creates a context provider and consumer pair.
99
+ *
100
+ * @param contextName - The name of the context. This can be a string or an object with a `name` and `key` property.
101
+ * @param composable - An optional composable function that returns the context value. If not provided, the context value will be the first argument passed to the provider.
102
+ */
103
+ function useContext(contextName, composable) {
104
+ const name = typeof contextName === "string" ? contextName : contextName.name;
105
+ const key = typeof contextName === "string" ? Symbol(contextName) : contextName.key;
106
+ /**
107
+ * Injects the context value.
108
+ *
109
+ * @param consumerName - The name of the component that is consuming the context. If provided, the component must be
110
+ * used within the context provider.
111
+ * @param defaultValue - The default value to return if the context is not provided.
112
+ * @returns The context value.
113
+ */
114
+ const useInject = (consumerName, defaultValue) => {
115
+ const value = inject(key, defaultValue) ?? null;
116
+ if (consumerName != null && value === null) throw new Error(`\`${consumerName}\` must be used within \`${name}\``);
117
+ return value;
118
+ };
119
+ const useProvide = (...args) => {
120
+ const value = composable?.(...args) ?? args[0];
121
+ provide(key, value);
122
+ return value;
123
+ };
124
+ return [useProvide, useInject];
125
+ }
126
+ //#endregion
127
+ //#region src/hooks/use-svg-icon-render.ts
128
+ function useSvgIconRender(SvgIcon) {
129
+ /**
130
+ * Svg icon VNode
131
+ *
132
+ * @param config
133
+ */
134
+ const SvgIconVNode = (config) => {
135
+ const { color, fontSize, localIcon } = config;
136
+ const style = {};
137
+ if (color) style.color = color;
138
+ if (fontSize) style.fontSize = `${fontSize}px`;
139
+ if (!localIcon) return;
140
+ return () => h(SvgIcon, {
141
+ localIcon,
142
+ style
143
+ });
144
+ };
145
+ return { SvgIconVNode };
146
+ }
147
+ //#endregion
148
+ //#region src/hooks/use-table.ts
149
+ function useTable(options) {
150
+ const { loading, startLoading, endLoading } = useLoading();
151
+ const { bool: empty, setBool: setEmpty } = useBoolean();
152
+ const { api, pagination, transform, columns, getColumnChecks, getColumns, onFetched, immediate = true } = options;
153
+ const data = ref([]);
154
+ const columnChecks = ref(getColumnChecks(columns()));
155
+ const $columns = computed(() => getColumns(columns(), columnChecks.value));
156
+ function reloadColumns() {
157
+ const currentChecks = columnChecks.value;
158
+ const checkMap = new Map(currentChecks.map((col) => [col.key, col.checked]));
159
+ const fixedMap = new Map(currentChecks.map((col) => [col.key, col.fixed]));
160
+ const defaultChecks = getColumnChecks(columns());
161
+ const defaultMap = new Map(defaultChecks.map((col) => [col.key, col]));
162
+ const result = [];
163
+ const usedKeys = /* @__PURE__ */ new Set();
164
+ for (const col of currentChecks) {
165
+ const defaultCol = defaultMap.get(col.key);
166
+ if (defaultCol) {
167
+ result.push({
168
+ ...defaultCol,
169
+ checked: checkMap.get(col.key) ?? defaultCol.checked,
170
+ fixed: (fixedMap.get(col.key) !== "unFixed" ? fixedMap.get(col.key) : void 0) ?? defaultCol.fixed
171
+ });
172
+ usedKeys.add(col.key);
173
+ }
174
+ }
175
+ for (const col of defaultChecks) if (!usedKeys.has(col.key)) result.push(col);
176
+ columnChecks.value = result;
177
+ }
178
+ async function getData() {
179
+ try {
180
+ startLoading();
181
+ const transformed = transform(await api());
182
+ data.value = getTableData(transformed, pagination);
183
+ setEmpty(data.value.length === 0);
184
+ await onFetched?.(transformed);
185
+ } finally {
186
+ endLoading();
187
+ }
188
+ }
189
+ if (immediate) getData();
190
+ return {
191
+ loading,
192
+ empty,
193
+ data,
194
+ columns: $columns,
195
+ columnChecks,
196
+ reloadColumns,
197
+ getData
198
+ };
199
+ }
200
+ function getTableData(data, pagination) {
201
+ if (pagination) return data.data;
202
+ return data;
203
+ }
204
+ //#endregion
205
+ export { useBoolean, useContext, useCountDown, useLoading, useSvgIconRender, useTable };
@@ -0,0 +1,2 @@
1
+ export * from './utils/index.js'
2
+ export {}