@jswork/antd-components 1.0.222 → 1.0.223

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 (49) hide show
  1. package/dist/main.cjs.js +1 -1
  2. package/dist/main.cjs.js.map +1 -1
  3. package/dist/main.d.mts +324 -493
  4. package/dist/main.d.ts +324 -493
  5. package/dist/main.esm.js +1 -1
  6. package/dist/main.esm.js.map +1 -1
  7. package/package.json +2 -3
  8. package/src/lib/_abstract-upload.tsx +1 -5
  9. package/src/lib/alert.tsx +16 -28
  10. package/src/lib/breadcrumb.tsx +1 -2
  11. package/src/lib/button.tsx +18 -20
  12. package/src/lib/card-extras.tsx +3 -8
  13. package/src/lib/checkable-dropdown.tsx +2 -3
  14. package/src/lib/checkable-tag-list.tsx +2 -3
  15. package/src/lib/checkable-tag.tsx +1 -2
  16. package/src/lib/checkbox-group.tsx +1 -3
  17. package/src/lib/checkbox.tsx +1 -2
  18. package/src/lib/color-picker.tsx +2 -3
  19. package/src/lib/confirm-button.tsx +2 -1
  20. package/src/lib/date-picker.tsx +2 -3
  21. package/src/lib/editable-tag-group.tsx +1 -2
  22. package/src/lib/extra-search.tsx +2 -8
  23. package/src/lib/form-actions.tsx +2 -1
  24. package/src/lib/input-number.tsx +1 -2
  25. package/src/lib/input-tags.tsx +1 -2
  26. package/src/lib/input-token.tsx +1 -2
  27. package/src/lib/input.tsx +1 -2
  28. package/src/lib/interactive-list.tsx +1 -7
  29. package/src/lib/markdown-editor.tsx +1 -2
  30. package/src/lib/radio-group.tsx +1 -3
  31. package/src/lib/range-picker.tsx +1 -3
  32. package/src/lib/rate.tsx +1 -2
  33. package/src/lib/search.tsx +1 -4
  34. package/src/lib/select.tsx +1 -4
  35. package/src/lib/slider-range.tsx +1 -2
  36. package/src/lib/slider.tsx +1 -2
  37. package/src/lib/switch.tsx +1 -2
  38. package/src/lib/table-links.tsx +4 -9
  39. package/src/lib/table-status-switcher.tsx +0 -6
  40. package/src/lib/table-toggle-switcher.tsx +0 -6
  41. package/src/lib/table.tsx +3 -16
  42. package/src/lib/textarea.tsx +1 -2
  43. package/src/lib/time-picker.tsx +1 -2
  44. package/src/lib/transfer.tsx +2 -4
  45. package/src/lib/tree-select.tsx +1 -2
  46. package/src/lib/types.ts +136 -0
  47. package/src/lib/upload-dragger.tsx +1 -2
  48. package/src/lib/upload.tsx +1 -3
  49. package/src/lib/use-table-command.ts +4 -3
@@ -8,12 +8,7 @@ import nx from '@jswork/next';
8
8
  import { Space } from 'antd';
9
9
  import React, { FC } from 'react';
10
10
  import { AcConfirmButton } from './confirm-button';
11
-
12
- declare global {
13
- interface NxStatic {
14
- $event: any;
15
- }
16
- }
11
+ import type { AppLocale } from './types';
17
12
 
18
13
  const locales = {
19
14
  'zh-CN': {
@@ -31,7 +26,7 @@ const locales = {
31
26
  export type AcTableLinksProps = {
32
27
  name: string;
33
28
  model?: any;
34
- lang?: string;
29
+ lang?: AppLocale;
35
30
  extraBefore?: React.ReactNode;
36
31
  extraAfter?: React.ReactNode;
37
32
  as?: React.ComponentType<any>;
@@ -41,12 +36,12 @@ export type AcTableLinksProps = {
41
36
 
42
37
  export type TableActionArgs = {
43
38
  name: string;
44
- lang?: string;
39
+ lang?: AppLocale;
45
40
  [key: string]: any;
46
41
  }
47
42
 
48
43
  const defaultProps = {
49
- lang: 'zh-CN',
44
+ lang: 'zh-CN' as const,
50
45
  actions: ['edit', 'destroy'],
51
46
  };
52
47
 
@@ -9,12 +9,6 @@ import React, { FC } from 'react';
9
9
  import { ReactAntStatusSwitchProps } from '@jswork/react-ant-status-switch/dist/components';
10
10
  import nx from '@jswork/next';
11
11
 
12
- declare global {
13
- interface NxStatic {
14
- $api: Record<string, any>;
15
- }
16
- }
17
-
18
12
  export type AcTableStatusSwitcherProps = ReactAntStatusSwitchProps & {
19
13
  name: string;
20
14
  items: any[];
@@ -8,12 +8,6 @@ import React, { FC } from 'react';
8
8
  import nx from '@jswork/next';
9
9
  import { Switch, SwitchProps } from 'antd';
10
10
 
11
- declare global {
12
- interface NxStatic {
13
- $api: Record<string, any>;
14
- }
15
- }
16
-
17
11
  export type AcTableToggleSwitcherProps = SwitchProps & {
18
12
  name: string;
19
13
  model: any;
package/src/lib/table.tsx CHANGED
@@ -20,18 +20,9 @@ import { ColumnsType } from 'antd/es/table';
20
20
  import cx from 'classnames';
21
21
  import deepEqual from 'fast-deep-equal';
22
22
  import React from 'react';
23
+ import type { AppLocale, FetcherParams, FetcherResponse } from './types';
23
24
  import { tableAction } from './table-links';
24
25
 
25
- type NavigateFunction = import('react-router-dom').NavigateFunction;
26
-
27
- declare global {
28
- interface NxStatic {
29
- $event: any;
30
- $nav: NavigateFunction;
31
- $api: Record<string, any>;
32
- }
33
- }
34
-
35
26
  const CLASS_NAME = 'ac-table';
36
27
 
37
28
  export type AcTableProps = TableProps & {
@@ -44,7 +35,7 @@ export type AcTableProps = TableProps & {
44
35
  * The language.
45
36
  * @default 'zh-CN'
46
37
  */
47
- lang?: string;
38
+ lang?: AppLocale;
48
39
  /**
49
40
  * The platform module name.
50
41
  * @default admin
@@ -81,11 +72,7 @@ export type AcTableProps = TableProps & {
81
72
  * @param params { current: number; pageSize: number }
82
73
  * @returns Promise<{ data: any[]; total: number }>
83
74
  */
84
- fetcher?: (params: {
85
- current: number;
86
- pageSize: number;
87
- params?: Record<string, any>;
88
- }) => Promise<{ data: any[]; total: number }>;
75
+ fetcher?: (params: FetcherParams) => FetcherResponse;
89
76
  /**
90
77
  * @param page
91
78
  * @param size
@@ -2,11 +2,10 @@ import { Input } from 'antd';
2
2
  import { TextAreaProps } from 'antd/es/input';
3
3
  import cx from 'classnames';
4
4
  import React from 'react';
5
+ import type { StdCallback } from './types';
5
6
 
6
7
  const CLASS_NAME = 'ac-textarea';
7
8
  const TextArea = Input.TextArea;
8
- type StdEventTarget = { target: { value: any } };
9
- type StdCallback = (inEvent: StdEventTarget) => void;
10
9
 
11
10
  export type AcTextareaProps = {
12
11
  className?: string;
@@ -2,11 +2,10 @@ import { TimePicker, TimePickerProps } from 'antd';
2
2
  import cx from 'classnames';
3
3
  import dayjs from 'dayjs';
4
4
  import React from 'react';
5
+ import type { StdCallback } from './types';
5
6
 
6
7
  const CLASS_NAME = 'ac-time-picker';
7
8
  const STD_FORMAT = 'HH:mm:ss';
8
- type StdEventTarget = { target: { value: any } };
9
- type StdCallback = (inEvent: StdEventTarget) => void;
10
9
 
11
10
  export type AcTimePickerProps = {
12
11
  className?: string;
@@ -2,11 +2,9 @@ import { Transfer, TransferProps } from 'antd';
2
2
  import cx from 'classnames';
3
3
  import React from 'react';
4
4
  import { transferLabel } from '../tpls/transfer';
5
+ import type { StdCallback, TemplateCallback } from './types';
5
6
 
6
7
  const CLASS_NAME = 'ac-transfer';
7
- type StdEventTarget = { target: { value: any } };
8
- type StdCallback = (inEvent: StdEventTarget) => void;
9
- type TemplateCallback = (item: { item: any }, options?: any) => React.ReactNode;
10
8
 
11
9
  export type AcTransferProps = {
12
10
  className?: string;
@@ -26,7 +24,7 @@ export class AcTransfer extends React.Component<AcTransferProps> {
26
24
 
27
25
  get templateCallback(): any {
28
26
  const { template } = this.props;
29
- return (item: any) => template({ item });
27
+ return (item: any) => template({ item, index: -1 });
30
28
  }
31
29
 
32
30
  state = {
@@ -3,10 +3,9 @@ import { TreeSelect, TreeSelectProps } from 'antd';
3
3
  import cx from 'classnames';
4
4
  import React from 'react';
5
5
  import { treeSelectKv } from '../tpls/kv';
6
+ import type { StdCallback } from './types';
6
7
 
7
8
  const CLASS_NAME = 'ac-tree-select';
8
- type StdEventTarget = { target: { value: any } };
9
- type StdCallback = (inEvent: StdEventTarget) => void;
10
9
 
11
10
  // @see: https://github.com/afeiship/react-ant-tree-select
12
11
 
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Common TypeScript types for antd-components
3
+ * Shared types used across multiple components
4
+ */
5
+
6
+ import { InputProps } from 'antd';
7
+ import { NavigateFunction } from 'react-router-dom';
8
+
9
+ /**
10
+ * Supported locale languages
11
+ * @example
12
+ * lang?: AppLocale;
13
+ */
14
+ export type AppLocale = 'zh-CN' | 'en-US';
15
+
16
+ /**
17
+ * Custom event target for input components
18
+ * @description This is a custom type that wraps onChange values in a standard format.
19
+ * Antd components don't always return standard React events, so we normalize
20
+ * all onChange callbacks to use this consistent { target: { value } } structure.
21
+ * @example
22
+ * const handleChange = (event: StdEventTarget) => {
23
+ * console.log(event.target.value);
24
+ * };
25
+ * @template T The type of the value
26
+ */
27
+ export type StdEventTarget<T = any> = { target: { value: T } };
28
+
29
+ /**
30
+ * Standard callback function for value changes
31
+ * @description Normalized onChange callback that accepts our custom event format.
32
+ * @example
33
+ * onChange?: (inEvent: StdEventTarget) => void;
34
+ * @template T The type of the value
35
+ */
36
+ export type StdCallback<T = any> = (inEvent: StdEventTarget<T>) => void;
37
+
38
+ /**
39
+ * Template callback for rendering items
40
+ * @example
41
+ * renderItem?: (item: { item: any; index: number }) => React.ReactNode;
42
+ */
43
+ export type TemplateCallback<T = any> = (
44
+ item: { item: T; index: number },
45
+ options?: any
46
+ ) => React.ReactNode;
47
+
48
+ /**
49
+ * Template callback with items array
50
+ * @example
51
+ * renderItem?: (item: { item: any; index: number; items: any[] }, cb: any) => React.ReactNode;
52
+ */
53
+ export type TemplateCallbackWithItems<T = any> = (
54
+ item: { item: T; index: number; items: T[] },
55
+ cb: any
56
+ ) => React.ReactNode;
57
+
58
+ /**
59
+ * Template callback with options
60
+ * @example
61
+ * renderItem?: (item: { item: any; index: number }, options?: any) => React.ReactNode;
62
+ */
63
+ export type TemplateCallbackWithOptions<T = any> = (
64
+ item: { item: T; index: number },
65
+ options?: any
66
+ ) => React.ReactNode;
67
+
68
+ /**
69
+ * Base form props interface
70
+ */
71
+ export interface BaseFormProps {
72
+ className?: string;
73
+ disabled?: boolean;
74
+ readOnly?: boolean;
75
+ }
76
+
77
+ /**
78
+ * Form props with onChange handler
79
+ */
80
+ export interface FormWithOnChangeProps<T = any> extends BaseFormProps {
81
+ value?: T;
82
+ onChange?: StdCallback;
83
+ }
84
+
85
+ /**
86
+ * Form props with items array
87
+ */
88
+ export interface FormWithItemsProps<T = any> extends FormWithOnChangeProps<T> {
89
+ items?: T[];
90
+ }
91
+
92
+ /**
93
+ * API fetcher parameters
94
+ */
95
+ export interface FetcherParams {
96
+ current: number;
97
+ pageSize: number;
98
+ params?: Record<string, any>;
99
+ }
100
+
101
+ /**
102
+ * API fetcher response
103
+ */
104
+ export type FetcherResponse<T = any> = Promise<{
105
+ data: T[];
106
+ total: number;
107
+ }>;
108
+
109
+ /**
110
+ * Table action configuration
111
+ */
112
+ export interface TableActionProps {
113
+ name: string;
114
+ module?: string;
115
+ params?: Record<string, any>;
116
+ paramsAdd?: Record<string, any>;
117
+ paramsEdit?: Record<string, any>;
118
+ paramsReset?: Record<string, any>;
119
+ pathAdd?: string;
120
+ pathEdit?: string;
121
+ }
122
+
123
+ declare global {
124
+ interface NxStatic {
125
+ $event: any;
126
+ $api: Record<string, any>;
127
+ $nav: NavigateFunction;
128
+
129
+ err: (msg: string) => any;
130
+ msg: (msg: string) => any;
131
+ info: (msg: string) => any;
132
+ alert: (msg: string, title?: String) => any;
133
+ confirm: (msg: string, title?: String) => any;
134
+ prompt: (msg: string, options?: InputProps) => any;
135
+ }
136
+ }
@@ -3,11 +3,10 @@ import { Upload } from 'antd';
3
3
  import { DraggerProps } from 'antd/es/upload';
4
4
  import cx from 'classnames';
5
5
  import React from 'react';
6
+ import type { StdCallback } from './types';
6
7
 
7
8
  const CLASS_NAME = 'ac-upload-dragger';
8
9
  const { Dragger } = Upload;
9
- type StdEventTarget = { target: { value: any } };
10
- type StdCallback = (inEvent: StdEventTarget) => void;
11
10
  type CustomRequest = (inEvent: any) => Promise<any>;
12
11
 
13
12
  export type AcUploadDraggerProps = {
@@ -2,12 +2,10 @@ import { UploadOutlined } from '@ant-design/icons';
2
2
  import type { ButtonProps, UploadProps } from 'antd';
3
3
  import { Button, Upload } from 'antd';
4
4
  import React from 'react';
5
-
6
5
  import cx from 'classnames';
6
+ import type { StdCallback } from './types';
7
7
 
8
8
  const CLASS_NAME = 'ac-upload';
9
- type StdEventTarget = { target: { value: any } };
10
- type StdCallback = (inEvent: StdEventTarget) => void;
11
9
  type CustomRequest = (inEvent: any) => Promise<any>;
12
10
 
13
11
  export type AcUploadProps = {
@@ -6,7 +6,8 @@ type Payload = Record<string, any>;
6
6
 
7
7
  const useCommand = (inName?: string) => {
8
8
  const name = inName || '@';
9
- const execute: ExecuteFn = (command, ...args) => AcTable.event?.emit(`${name}:${command}`, ...args);
9
+ const execute: ExecuteFn = (command, ...args) =>
10
+ AcTable.event?.emit(`${name}:${command}`, ...args);
10
11
  const listen: ListenFn = (cmd, callback) => AcTable.event?.on(`${name}:${cmd}`, callback);
11
12
 
12
13
  // the command repository:
@@ -14,8 +15,8 @@ const useCommand = (inName?: string) => {
14
15
  const refetch = () => execute('refetch');
15
16
  const reset = () => execute('reset');
16
17
  const add = () => execute('add');
17
- const edit = () => execute('edit');
18
- const destroy = () => execute('destroy');
18
+ const edit = (payload: Payload) => execute('edit', payload);
19
+ const destroy = (payload: Payload) => execute('destroy', payload);
19
20
  const draft = (payload: Payload) => execute('draft', payload);
20
21
 
21
22
  return {