@vue-ui-kit/ant 2.4.2 → 2.4.4

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 (32) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/index.js +5 -5
  3. package/dist/es/index.js +11094 -12211
  4. package/dist/index.d.ts +3080 -23
  5. package/dist/style.css +419 -1
  6. package/dist/style.scss +22 -1
  7. package/package.json +8 -8
  8. package/src/declarations/antProxy.ts +21 -6
  9. package/src/index.ts +1 -0
  10. package/src/packages/components/PGrid.vue +201 -98
  11. package/src/packages/components/RenderAntCell.tsx +29 -29
  12. package/src/packages/components/RenderDefaultSlots.tsx +6 -2
  13. package/src/packages/store/renderStore.tsx +1 -1
  14. package/src/packages/styles/index.scss +22 -1
  15. package/src/packages/utils/autoViewportBox.ts +156 -0
  16. package/src/packages/utils/config.ts +109 -105
  17. package/dist/declarations/antProxy.d.ts +0 -373
  18. package/dist/declarations/type.d.ts +0 -1
  19. package/dist/packages/components/RenderAntCell.d.ts +0 -28
  20. package/dist/packages/components/RenderAntItem.d.ts +0 -18
  21. package/dist/packages/components/RenderDefaultSlots.d.ts +0 -34
  22. package/dist/packages/components/RenderEditCell.d.ts +0 -25
  23. package/dist/packages/components/RenderItemSlots.d.ts +0 -25
  24. package/dist/packages/components/RenderTitleSlots.d.ts +0 -16
  25. package/dist/packages/hooks/useMessage.d.ts +0 -8
  26. package/dist/packages/renders/Icon.d.ts +0 -4
  27. package/dist/packages/store/renderStore.d.ts +0 -16
  28. package/dist/packages/utils/AFormatters.d.ts +0 -9
  29. package/dist/packages/utils/config.d.ts +0 -30
  30. package/dist/packages/utils/core.d.ts +0 -10
  31. package/dist/packages/utils/is.d.ts +0 -4
  32. package/dist/packages/utils/treeHelper.d.ts +0 -19
@@ -0,0 +1,156 @@
1
+ /**
2
+ * 按视口从元素左上角铺满宽高(与 storybook 中 v-rest / v-height / v-width 同源思路),
3
+ * 用于外层未声明高度、需由根节点自行占满可视区域的场景。
4
+ */
5
+
6
+ export type AutoViewportBoxOffsetInput =
7
+ | number
8
+ | string
9
+ | { right?: number; bottom?: number }
10
+ | undefined;
11
+
12
+ export interface AutoViewportBoxOffset {
13
+ right: number;
14
+ bottom: number;
15
+ }
16
+
17
+ function parseSingle(value: unknown): number {
18
+ if (typeof value === 'number' && !Number.isNaN(value)) {
19
+ return value;
20
+ }
21
+ if (typeof value === 'string') {
22
+ const match = value.match(/^(-?\d+(?:\.\d+)?)(px)?$/i);
23
+ if (match) {
24
+ return Number.parseFloat(match[1]);
25
+ }
26
+ }
27
+ return 0;
28
+ }
29
+
30
+ /** 解析与 v-rest 一致的偏移:数字/字符串同时作用于 right+bottom;对象可单独指定 */
31
+ export function parseAutoViewportBoxOffset(
32
+ value: AutoViewportBoxOffsetInput,
33
+ ): AutoViewportBoxOffset {
34
+ if (value === undefined || value === null || value === '') {
35
+ return { right: 0, bottom: 0 };
36
+ }
37
+ if (typeof value === 'object' && !Array.isArray(value)) {
38
+ const o = value as { right?: number; bottom?: number };
39
+ return {
40
+ right: typeof o.right === 'number' ? o.right : 0,
41
+ bottom: typeof o.bottom === 'number' ? o.bottom : 0,
42
+ };
43
+ }
44
+ const single = parseSingle(value);
45
+ return { right: single, bottom: single };
46
+ }
47
+
48
+ function findResizeAncestor(start: Element | null): Element {
49
+ let el: Element | null = start?.parentElement ?? null;
50
+ while (el && el !== document.body) {
51
+ const overflow = window.getComputedStyle(el).overflow;
52
+ if (overflow === 'auto' || overflow === 'scroll' || overflow === 'hidden') {
53
+ return el;
54
+ }
55
+ el = el.parentElement;
56
+ }
57
+ return document.body;
58
+ }
59
+
60
+ /**
61
+ * 宽/高先按「视口内从元素左上角到右/下边缘」计算,再与**直接父元素**布局框取较小值,
62
+ * 避免嵌套在侧栏 + flex 列等窄容器里仍按整屏宽度赋值,从而撑出页面级横向滚动条。
63
+ */
64
+ export function applyViewportRestSize(el: HTMLElement, offset: AutoViewportBoxOffset): void {
65
+ const rect = el.getBoundingClientRect();
66
+ const vw = window.innerWidth;
67
+ const vh = window.innerHeight;
68
+
69
+ let targetW = Math.max(0, vw - rect.left - offset.right);
70
+ let targetH = Math.max(0, vh - rect.top - offset.bottom);
71
+
72
+ const parent = el.parentElement;
73
+ if (parent) {
74
+ const pr = parent.getBoundingClientRect();
75
+ if (pr.width > 0) {
76
+ targetW = Math.min(targetW, pr.width);
77
+ }
78
+ if (pr.height > 0) {
79
+ targetH = Math.min(targetH, pr.height);
80
+ }
81
+ }
82
+
83
+ el.style.width = `${targetW}px`;
84
+ el.style.height = `${targetH}px`;
85
+ }
86
+
87
+ function clearViewportBoxSize(el: HTMLElement): void {
88
+ el.style.width = '';
89
+ el.style.height = '';
90
+ }
91
+
92
+ export interface AutoViewportBoxControllerOptions {
93
+ /** 每次尺寸写回后回调(例如触发内部表格 resize) */
94
+ onLayout?: () => void;
95
+ }
96
+
97
+ export interface AutoViewportBoxController {
98
+ attach: () => void;
99
+ update: () => void;
100
+ destroy: () => void;
101
+ }
102
+
103
+ export function createAutoViewportBoxController(
104
+ getEl: () => HTMLElement | null | undefined,
105
+ getOffset: () => AutoViewportBoxOffset,
106
+ options?: AutoViewportBoxControllerOptions,
107
+ ): AutoViewportBoxController {
108
+ let resizeObserver: ResizeObserver | null = null;
109
+ let onWinResize: (() => void) | null = null;
110
+
111
+ const disconnect = () => {
112
+ if (resizeObserver) {
113
+ resizeObserver.disconnect();
114
+ resizeObserver = null;
115
+ }
116
+ if (onWinResize) {
117
+ window.removeEventListener('resize', onWinResize);
118
+ onWinResize = null;
119
+ }
120
+ };
121
+
122
+ const update = () => {
123
+ const el = getEl();
124
+ if (!el) return;
125
+ applyViewportRestSize(el, getOffset());
126
+ options?.onLayout?.();
127
+ };
128
+
129
+ const attach = () => {
130
+ disconnect();
131
+ const el = getEl();
132
+ if (!el) return;
133
+
134
+ onWinResize = () => update();
135
+ window.addEventListener('resize', onWinResize);
136
+
137
+ const scrollAncestor = findResizeAncestor(el);
138
+ resizeObserver = new ResizeObserver(() => update());
139
+ resizeObserver.observe(scrollAncestor);
140
+ if (el.parentElement) {
141
+ resizeObserver.observe(el.parentElement);
142
+ }
143
+
144
+ update();
145
+ };
146
+
147
+ return {
148
+ attach,
149
+ update,
150
+ destroy: () => {
151
+ disconnect();
152
+ const el = getEl();
153
+ if (el) clearViewportBoxSize(el);
154
+ },
155
+ };
156
+ }
@@ -1,105 +1,109 @@
1
- import { PFormProps, PGridProps } from '#/antProxy';
2
- import { ConfigType } from 'e-virt-table';
3
- import { clone } from 'xe-utils';
4
- import type { VNode } from 'vue';
5
-
6
- // 全局配置接口
7
- export interface UIKitConfig {
8
- form?: {
9
- labelCol?: any;
10
- wrapperCol?: any;
11
- };
12
- grid?: {
13
- align?: 'left' | 'right' | 'center';
14
- lazyReset?: boolean;
15
- fitHeight?: number;
16
- fitCanvasHeight?: number;
17
- striped?: boolean;
18
- };
19
- canvasTable?: ConfigType;
20
- /**
21
- * 自定义 tooltip 渲染函数,替换全局所有 a-tooltip。
22
- * @param defaultSlot 原 tooltip 触发元素(图标等)
23
- * @param content tooltip 内容,字符串或返回 VNode 的函数
24
- */
25
- renderTooltip?: (defaultSlot: () => VNode, content: string | (() => VNode)) => VNode;
26
- }
27
-
28
- // 默认配置
29
- const defaultConfig: UIKitConfig = {
30
- form: {
31
- labelCol: { span: 6 },
32
- wrapperCol: { span: 16 },
33
- },
34
- grid: {
35
- align: 'left',
36
- lazyReset: false,
37
- fitHeight: 170,
38
- striped: false,
39
- },
40
- canvasTable: {
41
- DISABLED: true,
42
- ENABLE_FINDER: true,
43
- AUTO_ROW_HEIGHT: true,
44
- },
45
- };
46
-
47
- // 当前配置(可被修改)
48
- let currentConfig: UIKitConfig = clone(defaultConfig, true);
49
-
50
- // 设置配置
51
- export function setUIKitConfig(config: Partial<UIKitConfig>): void {
52
- currentConfig = {
53
- form: {
54
- ...currentConfig.form,
55
- ...config.form,
56
- },
57
- grid: {
58
- ...currentConfig.grid,
59
- ...config.grid,
60
- },
61
- canvasTable: {
62
- ...currentConfig.canvasTable,
63
- ...config.canvasTable,
64
- },
65
- renderTooltip: config.renderTooltip ?? currentConfig.renderTooltip,
66
- };
67
- }
68
-
69
- // 获取自定义 tooltip 渲染函数
70
- export function getTooltipRenderer(): UIKitConfig['renderTooltip'] {
71
- return currentConfig.renderTooltip;
72
- }
73
-
74
- // 获取配置
75
- export function getUIKitConfig(): UIKitConfig {
76
- return currentConfig;
77
- }
78
-
79
- // 获取表单默认配置
80
- export function getFormDefaults(): Partial<PFormProps> {
81
- return {
82
- labelCol: currentConfig.form?.labelCol,
83
- wrapperCol: currentConfig.form?.wrapperCol,
84
- };
85
- }
86
-
87
- // 获取Grid默认配置
88
- export function getGridDefaults(): Partial<PGridProps> {
89
- return {
90
- align: currentConfig.grid?.align,
91
- lazyReset: currentConfig.grid?.lazyReset,
92
- fitHeight: currentConfig.grid?.fitHeight,
93
- striped: currentConfig.grid?.striped,
94
- };
95
- }
96
-
97
- // 获取CanvasTable默认配置
98
- export function getCanvasTableDefaults(): ConfigType {
99
- return currentConfig.canvasTable || ({} as ConfigType);
100
- }
101
-
102
- // 重置为默认配置
103
- export function resetUIKitConfig(): void {
104
- currentConfig = JSON.parse(JSON.stringify(defaultConfig));
105
- }
1
+ import { PFormProps, PGridProps } from '#/antProxy';
2
+ import type { AutoViewportBoxOffsetInput } from '@/utils/autoViewportBox';
3
+ import { ConfigType } from 'e-virt-table';
4
+ import { clone } from 'xe-utils';
5
+ import type { VNode } from 'vue';
6
+
7
+ // 全局配置接口
8
+ export interface UIKitConfig {
9
+ form?: {
10
+ labelCol?: any;
11
+ wrapperCol?: any;
12
+ };
13
+ grid?: {
14
+ align?: 'left' | 'right' | 'center';
15
+ lazyReset?: boolean;
16
+ fitHeight?: number;
17
+ fitCanvasHeight?: number;
18
+ striped?: boolean;
19
+ /** `PGrid` 开启 `autoBoxSize` 且未传 `autoBoxSizeOffset` 时的视口边距,与 props 类型一致 */
20
+ autoBoxSizeOffset?: AutoViewportBoxOffsetInput;
21
+ };
22
+ canvasTable?: ConfigType;
23
+ /**
24
+ * 自定义 tooltip 渲染函数,替换全局所有 a-tooltip。
25
+ * @param defaultSlot tooltip 触发元素(图标等)
26
+ * @param content tooltip 内容,字符串或返回 VNode 的函数
27
+ */
28
+ renderTooltip?: (defaultSlot: () => VNode, content: string | (() => VNode)) => VNode;
29
+ }
30
+
31
+ // 默认配置
32
+ const defaultConfig: UIKitConfig = {
33
+ form: {
34
+ labelCol: { span: 6 },
35
+ wrapperCol: { span: 16 },
36
+ },
37
+ grid: {
38
+ align: 'left',
39
+ lazyReset: false,
40
+ fitHeight: 30,
41
+ striped: false,
42
+ },
43
+ canvasTable: {
44
+ DISABLED: true,
45
+ ENABLE_FINDER: true,
46
+ AUTO_ROW_HEIGHT: true,
47
+ },
48
+ };
49
+
50
+ // 当前配置(可被修改)
51
+ let currentConfig: UIKitConfig = clone(defaultConfig, true);
52
+
53
+ // 设置配置
54
+ export function setUIKitConfig(config: Partial<UIKitConfig>): void {
55
+ currentConfig = {
56
+ form: {
57
+ ...currentConfig.form,
58
+ ...config.form,
59
+ },
60
+ grid: {
61
+ ...currentConfig.grid,
62
+ ...config.grid,
63
+ },
64
+ canvasTable: {
65
+ ...currentConfig.canvasTable,
66
+ ...config.canvasTable,
67
+ },
68
+ renderTooltip: config.renderTooltip ?? currentConfig.renderTooltip,
69
+ };
70
+ }
71
+
72
+ // 获取自定义 tooltip 渲染函数
73
+ export function getTooltipRenderer(): UIKitConfig['renderTooltip'] {
74
+ return currentConfig.renderTooltip;
75
+ }
76
+
77
+ // 获取配置
78
+ export function getUIKitConfig(): UIKitConfig {
79
+ return currentConfig;
80
+ }
81
+
82
+ // 获取表单默认配置
83
+ export function getFormDefaults(): Partial<PFormProps> {
84
+ return {
85
+ labelCol: currentConfig.form?.labelCol,
86
+ wrapperCol: currentConfig.form?.wrapperCol,
87
+ };
88
+ }
89
+
90
+ // 获取Grid默认配置
91
+ export function getGridDefaults(): Partial<PGridProps> {
92
+ return {
93
+ align: currentConfig.grid?.align,
94
+ lazyReset: currentConfig.grid?.lazyReset,
95
+ fitHeight: currentConfig.grid?.fitHeight,
96
+ striped: currentConfig.grid?.striped,
97
+ autoBoxSizeOffset: currentConfig.grid?.autoBoxSizeOffset,
98
+ };
99
+ }
100
+
101
+ // 获取CanvasTable默认配置
102
+ export function getCanvasTableDefaults(): ConfigType {
103
+ return currentConfig.canvasTable || ({} as ConfigType);
104
+ }
105
+
106
+ // 重置为默认配置
107
+ export function resetUIKitConfig(): void {
108
+ currentConfig = JSON.parse(JSON.stringify(defaultConfig));
109
+ }