@cozeloop/components 0.0.3 → 0.0.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 (165) hide show
  1. package/package.json +9 -3
  2. package/.eslintcache +0 -1
  3. package/.rush/temp/shrinkwrap-deps.json +0 -770
  4. package/OWNERS +0 -5
  5. package/config/rush-project.json +0 -8
  6. package/eslint.config.js +0 -7
  7. package/rslib.config.js +0 -7
  8. package/script/publish.js +0 -146
  9. package/src/base-search-select/base-search-form-select.tsx +0 -10
  10. package/src/base-search-select/base-search-select.tsx +0 -200
  11. package/src/base-search-select/index.module.less +0 -16
  12. package/src/base-search-select/index.tsx +0 -3
  13. package/src/base-search-select/types.ts +0 -16
  14. package/src/base-search-select/utils.ts +0 -78
  15. package/src/basic-card/index.tsx +0 -23
  16. package/src/card-pane/index.module.less +0 -14
  17. package/src/card-pane/index.tsx +0 -25
  18. package/src/chip-select/index.module.less +0 -17
  19. package/src/chip-select/index.tsx +0 -7
  20. package/src/code-editor/index.tsx +0 -9
  21. package/src/code-usage/code-item.module.less +0 -32
  22. package/src/code-usage/index.tsx +0 -91
  23. package/src/codemirror-editor/code-editor.tsx +0 -139
  24. package/src/codemirror-editor/index.ts +0 -4
  25. package/src/codemirror-editor/json-editor.tsx +0 -183
  26. package/src/codemirror-editor/raw-text-editor.tsx +0 -68
  27. package/src/codemirror-editor/text-editor.tsx +0 -58
  28. package/src/codemirror-editor/themes/coze-dark.ts +0 -116
  29. package/src/codemirror-editor/themes/coze-light.ts +0 -122
  30. package/src/collapse-card/index.module.less +0 -27
  31. package/src/collapse-card/index.tsx +0 -93
  32. package/src/collapsible-card/index.module.less +0 -63
  33. package/src/collapsible-card/index.tsx +0 -57
  34. package/src/column-manage-storage/index.tsx +0 -64
  35. package/src/columns-select/index.tsx +0 -244
  36. package/src/edit-icon-button/index.tsx +0 -36
  37. package/src/footer-actions/index.tsx +0 -33
  38. package/src/hooks/use-infinite-scroll.ts +0 -183
  39. package/src/hooks/use-mouse-down-offset.ts +0 -50
  40. package/src/hooks/use-unsave-leave-warning.ts +0 -49
  41. package/src/id-render/icon-button-container.tsx +0 -37
  42. package/src/id-render/index.tsx +0 -64
  43. package/src/index-controller/record-navigation.tsx +0 -57
  44. package/src/index-controller/use-item-index-controller.ts +0 -197
  45. package/src/index.ts +0 -208
  46. package/src/infinite-scroll-table/index.tsx +0 -99
  47. package/src/info-tooltip/index.tsx +0 -41
  48. package/src/input-components/radio-button.tsx +0 -63
  49. package/src/input-slider/index.module.less +0 -30
  50. package/src/input-slider/index.tsx +0 -161
  51. package/src/input-with-count/index.tsx +0 -31
  52. package/src/jump-button/jump-icon-button.tsx +0 -12
  53. package/src/large-txt-render/index.tsx +0 -46
  54. package/src/layout/content.tsx +0 -28
  55. package/src/layout/header.tsx +0 -15
  56. package/src/layout/index.module.less +0 -28
  57. package/src/layout/index.tsx +0 -9
  58. package/src/layout/tabs.tsx +0 -11
  59. package/src/lazy-load-component/index.tsx +0 -55
  60. package/src/logic-editor/index.ts +0 -3
  61. package/src/logic-editor/logic-editor.module.less +0 -13
  62. package/src/logic-editor/logic-editor.tsx +0 -200
  63. package/src/logic-editor/logic-left-render.tsx +0 -100
  64. package/src/logic-editor/logic-operator-render.tsx +0 -54
  65. package/src/logic-editor/logic-right-render.tsx +0 -51
  66. package/src/logic-editor/logic-types.tsx +0 -238
  67. package/src/logic-editor/utils.ts +0 -22
  68. package/src/logic-expr/assets/select.svg +0 -1
  69. package/src/logic-expr/consts.ts +0 -6
  70. package/src/logic-expr/expr-group-render.tsx +0 -238
  71. package/src/logic-expr/expr-render.tsx +0 -226
  72. package/src/logic-expr/index.module.less +0 -252
  73. package/src/logic-expr/index.ts +0 -13
  74. package/src/logic-expr/logic-expr.tsx +0 -261
  75. package/src/logic-expr/logic-not.tsx +0 -46
  76. package/src/logic-expr/logic-toggle.tsx +0 -96
  77. package/src/logic-expr/types.ts +0 -95
  78. package/src/loop-radio-group/index.tsx +0 -16
  79. package/src/multi-part-editor/components/image-item-renderer.tsx +0 -134
  80. package/src/multi-part-editor/components/index.module.less +0 -21
  81. package/src/multi-part-editor/components/multipart-item-renderer.tsx +0 -74
  82. package/src/multi-part-editor/components/url-input-modal.tsx +0 -317
  83. package/src/multi-part-editor/components/video-item-renderer.tsx +0 -145
  84. package/src/multi-part-editor/index.module.less +0 -8
  85. package/src/multi-part-editor/index.tsx +0 -571
  86. package/src/multi-part-editor/multi-part-render.tsx +0 -87
  87. package/src/multi-part-editor/type.tsx +0 -103
  88. package/src/multi-part-editor/upload-button.tsx +0 -256
  89. package/src/multi-part-editor/utils.ts +0 -64
  90. package/src/open-detail-button/index.tsx +0 -30
  91. package/src/page-content/index.tsx +0 -99
  92. package/src/primary-page/index.tsx +0 -1
  93. package/src/primary-page/primary-header.tsx +0 -64
  94. package/src/primary-title/index.module.less +0 -14
  95. package/src/primary-title/index.tsx +0 -18
  96. package/src/provider/index.tsx +0 -89
  97. package/src/resizable-side-sheet/index.tsx +0 -69
  98. package/src/resize-sidesheet/index.module.less +0 -14
  99. package/src/resize-sidesheet/index.tsx +0 -68
  100. package/src/resize-sidesheet/use-drag.ts +0 -43
  101. package/src/schema-editor/index.tsx +0 -52
  102. package/src/search-form/index.tsx +0 -134
  103. package/src/semi-schema-form/components/tmpls/array-field-item.tsx +0 -97
  104. package/src/semi-schema-form/components/tmpls/array-field.tsx +0 -127
  105. package/src/semi-schema-form/components/tmpls/base-input.tsx +0 -126
  106. package/src/semi-schema-form/components/tmpls/description-field.tsx +0 -23
  107. package/src/semi-schema-form/components/tmpls/error-list.tsx +0 -44
  108. package/src/semi-schema-form/components/tmpls/field-error.tsx +0 -33
  109. package/src/semi-schema-form/components/tmpls/field.tsx +0 -54
  110. package/src/semi-schema-form/components/tmpls/icon-button.tsx +0 -112
  111. package/src/semi-schema-form/components/tmpls/index.ts +0 -39
  112. package/src/semi-schema-form/components/tmpls/object-field.tsx +0 -173
  113. package/src/semi-schema-form/components/tmpls/submit.tsx +0 -31
  114. package/src/semi-schema-form/components/tmpls/title-field.tsx +0 -30
  115. package/src/semi-schema-form/components/widgets/checkbox.tsx +0 -67
  116. package/src/semi-schema-form/components/widgets/checkboxs.tsx +0 -100
  117. package/src/semi-schema-form/components/widgets/index.ts +0 -17
  118. package/src/semi-schema-form/components/widgets/radio.tsx +0 -105
  119. package/src/semi-schema-form/components/widgets/range.tsx +0 -73
  120. package/src/semi-schema-form/components/widgets/select.tsx +0 -108
  121. package/src/semi-schema-form/components/widgets/textarea.tsx +0 -63
  122. package/src/semi-schema-form/index.tsx +0 -14
  123. package/src/sentinel-form/enum.ts +0 -16
  124. package/src/sentinel-form/index.tsx +0 -382
  125. package/src/step-nav/index.module.less +0 -45
  126. package/src/step-nav/index.tsx +0 -53
  127. package/src/table/index.module.less +0 -144
  128. package/src/table/index.tsx +0 -18
  129. package/src/table/sort-icon.tsx +0 -73
  130. package/src/table/table-with-pagination.tsx +0 -150
  131. package/src/table/table-without-pagniation.tsx +0 -66
  132. package/src/table-batch-operate/table-batch-operation.tsx +0 -47
  133. package/src/table-batch-operate/use-batch-operate.ts +0 -111
  134. package/src/table-col-actions/index.module.less +0 -8
  135. package/src/table-col-actions/index.tsx +0 -149
  136. package/src/table-cols-config/index.module.less +0 -34
  137. package/src/table-cols-config/index.tsx +0 -171
  138. package/src/table-cols-config/type.ts +0 -12
  139. package/src/table-cols-config/use-hidden-col-keys.ts +0 -53
  140. package/src/table-cols-config/util.ts +0 -56
  141. package/src/table-empty/index.tsx +0 -23
  142. package/src/table-header/index.module.less +0 -7
  143. package/src/table-header/index.tsx +0 -70
  144. package/src/tabs/index.module.less +0 -48
  145. package/src/tabs/index.tsx +0 -9
  146. package/src/text-area-pro/index.module.less +0 -5
  147. package/src/text-area-pro/index.tsx +0 -49
  148. package/src/text-with-copy/index.tsx +0 -95
  149. package/src/title-with-sub/index.tsx +0 -27
  150. package/src/tooltip-when-disabled/index.tsx +0 -23
  151. package/src/tooltip-with-disabled/index.tsx +0 -17
  152. package/src/types.d.ts +0 -24
  153. package/src/upload/index.ts +0 -39
  154. package/src/user-profile/index.tsx +0 -49
  155. package/src/utils/basic.ts +0 -29
  156. package/src/version-list/index.module.less +0 -16
  157. package/src/version-list/version-descriptions.tsx +0 -80
  158. package/src/version-list/version-item.tsx +0 -30
  159. package/src/version-list/version-list.tsx +0 -59
  160. package/src/version-list/version-switch-panel.tsx +0 -31
  161. package/tailwind.config.ts +0 -6
  162. package/tsconfig.build.json +0 -44
  163. package/tsconfig.json +0 -17
  164. package/tsconfig.misc.json +0 -28
  165. package/vitest.config.mts +0 -7
@@ -1,122 +0,0 @@
1
- import { createTheme, tags as t } from '@coze-editor/editor/preset-code';
2
- import { EditorView } from '@codemirror/view';
3
-
4
- const colors = {
5
- background: '#fff',
6
- // syntax
7
- comment: '#000A298A',
8
- key: '#00818C',
9
- string: '#D1009D',
10
- number: '#C74200',
11
- boolean: '#2B57D9',
12
- null: '#2B57D9',
13
- separator: '#0F1529D1',
14
- };
15
-
16
- export const cozeLight = [
17
- EditorView.theme({
18
- '.cm-completionIcon-property': {
19
- backgroundImage:
20
- 'url("' +
21
- 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMWVtIiBoZWlnaHQ9IjFlbSIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xMi4zNTc2IDguMTAzNTVDMTIuMTYyMyA3LjkwODI5IDExLjg0NTcgNy45MDgyOSAxMS42NTA1IDguMTAzNTVMOC4xMDM1NSAxMS42NTA1QzcuOTA4MjkgMTEuODQ1NyA3LjkwODI5IDEyLjE2MjMgOC4xMDM1NSAxMi4zNTc2TDExLjY1MDUgMTUuOTA0NUMxMS44NDU3IDE2LjA5OTggMTIuMTYyMyAxNi4wOTk4IDEyLjM1NzYgMTUuOTA0NUwxNS45MDQ1IDEyLjM1NzZDMTYuMDk5OCAxMi4xNjIzIDE2LjA5OTggMTEuODQ1NyAxNS45MDQ1IDExLjY1MDVMMTIuMzU3NiA4LjEwMzU1WiIgZmlsbD0iIzA2MDcwOUNDIi8+PHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xMS4wMDI2IDEuNDU1NDVDMTEuNjIxNCAxLjA5ODE4IDEyLjM4MzggMS4wOTgxOCAxMy4wMDI2IDEuNDU1NDVMMjAuNjM4IDUuODYzNzRDMjEuMjU2OCA2LjIyMSAyMS42MzggNi44ODEyNiAyMS42MzggNy41OTU3OVYxNi40MTI0QzIxLjYzOCAxNy4xMjY5IDIxLjI1NjggMTcuNzg3MiAyMC42MzggMTguMTQ0NEwxMy4wMDI2IDIyLjU1MjdDMTIuMzgzOCAyMi45MSAxMS42MjE0IDIyLjkxIDExLjAwMjYgMjIuNTUyN0wzLjM2NzE5IDE4LjE0NDRDMi43NDgzOSAxNy43ODcyIDIuMzY3MTkgMTcuMTI2OSAyLjM2NzE5IDE2LjQxMjRWNy41OTU3OUMyLjM2NzE5IDYuODgxMjYgMi43NDgzOSA2LjIyMTAxIDMuMzY3MTkgNS44NjM3NEwxMS4wMDI2IDEuNDU1NDVaTTEyLjAwMjYgMy4xODc1TDE5LjYzOCA3LjU5NTc5VjE2LjQxMjRMMTIuMDAyNiAyMC44MjA3TDQuMzY3MTkgMTYuNDEyNEw0LjM2NzE5IDcuNTk1NzlMMTIuMDAyNiAzLjE4NzVaIiBmaWxsPSIjMDYwNzA5Q0MiLz48L3N2Zz4=' +
22
- '")',
23
- backgroundSize: '11px 11px',
24
- backgroundRepeat: 'no-repeat',
25
- width: '11px',
26
- height: '11px',
27
- },
28
- '.cm-completionIcon-property::after': {
29
- content: '""',
30
- },
31
- }),
32
- createTheme({
33
- variant: 'light',
34
- settings: {
35
- background: colors.background,
36
- foreground: '#4D4D4C',
37
- caret: '#AEAFAD',
38
- selection: '#52649A21',
39
- gutterBackground: colors.background,
40
- gutterForeground: '#000A298A',
41
- gutterBorderColor: 'transparent',
42
- gutterBorderWidth: 0,
43
- lineHighlight: '#efefef78',
44
- bracketColors: ['#E4D129', '#AC05FF', '#2B57D9'],
45
- tooltip: {
46
- backgroundColor: 'var(--coz-bg-max)',
47
- color: 'var(--coz-fg-primary)',
48
- border: 'solid 1px var(--coz-stroke-plus)',
49
- boxShadow: 'var(--coz-shadow-default)',
50
- borderRadius: '8px',
51
- },
52
- tooltipCompletion: {
53
- backgroundColor: '#FFFFFF',
54
- color: '#060709CC',
55
- },
56
- completionItemHover: {
57
- backgroundColor: '#5768A114',
58
- },
59
- completionItemSelected: {
60
- backgroundColor: '#52649A21',
61
- },
62
- completionItemIcon: {
63
- color: '#060709CC',
64
- },
65
- completionItemLabel: {
66
- color: '#060709CC',
67
- },
68
- completionItemDetail: {
69
- color: '#2029459E',
70
- },
71
- },
72
- styles: [
73
- // JSON
74
- {
75
- tag: t.comment,
76
- color: colors.comment,
77
- },
78
- {
79
- tag: [t.propertyName],
80
- color: colors.key,
81
- },
82
- {
83
- tag: [t.string],
84
- color: colors.string,
85
- },
86
- {
87
- tag: [t.number],
88
- color: colors.number,
89
- },
90
- {
91
- tag: [t.bool],
92
- color: colors.boolean,
93
- },
94
- {
95
- tag: [t.null],
96
- color: colors.null,
97
- },
98
- {
99
- tag: [t.separator],
100
- color: colors.separator,
101
- },
102
-
103
- // shell
104
- // curl
105
- {
106
- tag: [t.standard(t.variableName)],
107
- color: '#00804A',
108
- },
109
- // -X
110
- {
111
- tag: [t.attributeName],
112
- color: '#C74200',
113
- },
114
- // cp-disable-next-line
115
- // url in string (includes quotes), e.g. "https://..."
116
- {
117
- tag: [t.special(t.string)],
118
- color: '#2B57D9',
119
- },
120
- ],
121
- }),
122
- ];
@@ -1,27 +0,0 @@
1
- .coze-up-panel{
2
- :global {
3
- .semi-collapse-header,
4
- .semi-collapse-content{
5
- margin: 0;
6
- padding: 0;
7
- }
8
-
9
- .semi-collapse-content{
10
- padding-top: 0px;
11
- padding-bottom: 0;
12
- }
13
- }
14
-
15
- .chevron-icon {
16
- cursor: pointer;
17
- transition: transform 0.3s;
18
-
19
- &.chevron-icon-close {
20
- transform: rotate(-90deg);
21
- }
22
- }
23
- }
24
-
25
- .coze-up-panel-hidden{
26
- border:0
27
- }
@@ -1,93 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
-
3
- import cn from 'classnames';
4
- import { IconCozArrowDown } from '@coze-arch/coze-design/icons';
5
- import { Collapse } from '@coze-arch/coze-design';
6
-
7
- import styles from './index.module.less';
8
-
9
- interface CollapseCardProps
10
- extends Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> {
11
- className?: string;
12
- title: React.ReactNode;
13
- children: React.ReactNode;
14
- subInfo?: React.ReactNode;
15
- extra?: React.ReactNode;
16
- defaultVisible?: boolean;
17
- visible?: boolean;
18
- disableCollapse?: boolean;
19
- onVisibleChange?: (visible: boolean) => void;
20
- }
21
-
22
- export const CollapseCard = ({
23
- className,
24
- title,
25
- children,
26
- subInfo,
27
- extra,
28
- defaultVisible,
29
- visible,
30
- onVisibleChange,
31
- disableCollapse,
32
- ...props
33
- }: CollapseCardProps) => {
34
- const [activeKey, setActiveKey] = useState(defaultVisible ? ['1'] : []);
35
-
36
- // 处理受控模式
37
- useEffect(() => {
38
- if (visible !== undefined) {
39
- setActiveKey(visible ? ['1'] : []);
40
- }
41
- }, [visible]);
42
-
43
- const customHeader = (
44
- <div className="flex items-center justify-between flex-1">
45
- <div className="flex items-center gap-2">
46
- {title}
47
- <IconCozArrowDown
48
- className={cn(styles['chevron-icon'], {
49
- [styles['chevron-icon-close']]: !activeKey.length,
50
- })}
51
- />
52
- {subInfo}
53
- </div>
54
- {extra}
55
- </div>
56
- );
57
-
58
- const handleChange = (keys: string[]) => {
59
- if (visible === undefined) {
60
- setActiveKey(keys);
61
- }
62
- onVisibleChange?.(keys.length > 0);
63
- };
64
-
65
- if (disableCollapse) {
66
- return (
67
- <div className={cn('flex flex-col gap-4', className)}>
68
- {title}
69
- {children}
70
- </div>
71
- );
72
- }
73
-
74
- return (
75
- <Collapse
76
- {...props}
77
- activeKey={activeKey}
78
- onChange={v => handleChange(v as string[])}
79
- >
80
- <Collapse.Panel
81
- className={cn(styles['coze-up-panel'], styles['coze-up-panel-hidden'], {
82
- className,
83
- })}
84
- header={customHeader}
85
- itemKey="1"
86
- showArrow={false}
87
- extra={extra}
88
- >
89
- {children}
90
- </Collapse.Panel>
91
- </Collapse>
92
- );
93
- };
@@ -1,63 +0,0 @@
1
- /* stylelint-disable declaration-no-important */
2
- .card {
3
- background: transparent !important;
4
- border-radius: 0 !important;
5
-
6
- // flex flex-col px-4 pt-2 pb-4 bg-semi-bg-0 gap-3 rounded-md
7
- :global {
8
- .semi-card-body {
9
- display: flex;
10
- flex-direction: column;
11
- gap: 8px;
12
-
13
- box-sizing: border-box;
14
- height: 100%;
15
- padding: 0;
16
- }
17
- }
18
-
19
- .card-header{
20
- display: flex;
21
- align-items: center;
22
- justify-content: space-between;
23
-
24
- height: 24px;
25
- min-height: 24px;
26
- padding: 10px 20px 0;
27
- }
28
-
29
- .card-title {
30
- position: relative;
31
-
32
- display: flex;
33
- gap: 4px;
34
- align-items: center;
35
-
36
- font-weight: 600;
37
-
38
- .chevron-icon {
39
- cursor: pointer;
40
- transition: transform 0.3s;
41
-
42
- &.chevron-icon-close {
43
- transform: rotate(180deg);
44
- }
45
-
46
- &:hover {
47
- color: var(--semi-color-primary);
48
- }
49
- }
50
- }
51
-
52
- .card-content {
53
- height: 0;
54
- opacity: 0;
55
- transition: height 0.2s, opacity 0.2s;
56
-
57
- &.active {
58
- overflow: hidden;
59
- height: 100%;
60
- opacity: 1;
61
- }
62
- }
63
- }
@@ -1,57 +0,0 @@
1
- import { type CSSProperties, type ReactNode } from 'react';
2
-
3
- import cn from 'classnames';
4
- import { IconCozArrowUpFill } from '@coze-arch/coze-design/icons';
5
- import { Card, Typography } from '@coze-arch/coze-design';
6
-
7
- import styles from './index.module.less';
8
-
9
- interface Props {
10
- title?: ReactNode;
11
- children?: ReactNode;
12
- actionBtns?: ReactNode;
13
- className?: string;
14
- style?: CSSProperties;
15
- hideExpand?: boolean;
16
- isExpand?: boolean;
17
- setIsExpand?: (isExpand: boolean) => void;
18
- }
19
-
20
- export function CollapsibleCard({
21
- title,
22
- children,
23
- actionBtns,
24
- className,
25
- style,
26
- isExpand,
27
- setIsExpand,
28
- hideExpand,
29
- }: Props) {
30
- return (
31
- <Card className={cn(styles.card, className)} style={style} bordered={false}>
32
- {title || actionBtns ? (
33
- <div className={styles['card-header']}>
34
- <Typography.Text className={styles['card-title']}>
35
- {title}
36
- {children && !hideExpand ? (
37
- <IconCozArrowUpFill
38
- className={cn(styles['chevron-icon'], {
39
- [styles['chevron-icon-close']]: !isExpand,
40
- })}
41
- onClick={() => setIsExpand?.(!isExpand)}
42
- />
43
- ) : null}
44
- </Typography.Text>
45
- <div>{actionBtns}</div>
46
- </div>
47
- ) : null}
48
- <div
49
- className={cn(styles['card-content'], {
50
- [styles.active]: isExpand,
51
- })}
52
- >
53
- {children}
54
- </div>
55
- </Card>
56
- );
57
- }
@@ -1,64 +0,0 @@
1
- import { isEmpty } from 'lodash-es';
2
- import { safeJsonParse } from '@cozeloop/toolkit';
3
-
4
- import { type ColumnItem } from '../columns-select';
5
-
6
- export const DATASET_COLUMN_STORAGE_KEY = 'dataset-column';
7
-
8
- export const getColumnManageStorage = (storageKey: string) => {
9
- const storage = localStorage.getItem(storageKey);
10
- return safeJsonParse(storage || '{}') || {};
11
- };
12
- export interface ColumnSort {
13
- [key: string]: {
14
- index: number;
15
- checked: boolean;
16
- };
17
- }
18
- export const setColumnsManageStorage = (
19
- storageKey: string,
20
- columns: ColumnItem[],
21
- ) => {
22
- if (!storageKey) {
23
- return;
24
- }
25
- const data: ColumnSort = {};
26
- columns.forEach((column, index) => {
27
- data[column.key] = {
28
- index,
29
- checked: column.checked ?? true,
30
- };
31
- });
32
- localStorage.setItem(storageKey, JSON.stringify(data));
33
- };
34
-
35
- export const dealColumnsWithStorage = (
36
- storageKey: string,
37
- columns: ColumnItem[],
38
- ): ColumnItem[] => {
39
- const sort = getColumnManageStorage(storageKey);
40
- if (!sort || isEmpty(sort)) {
41
- return columns;
42
- }
43
- const newColumns = [...(columns || [])].sort((a, b) => {
44
- const indexA = sort[a.key]?.index ?? Infinity;
45
- const indexB = sort[b.key]?.index ?? Infinity;
46
- // 如果两个元素都在 arrayB 中,按照 arrayB 的顺序排序
47
- if (indexA !== Infinity && indexB !== Infinity) {
48
- return indexA - indexB;
49
- }
50
- // 如果只有一个元素在 arrayB 中,将其排在前面
51
- if (indexA !== Infinity) {
52
- return -1;
53
- }
54
- if (indexB !== Infinity) {
55
- return 1;
56
- }
57
- // 如果两个元素都不在 arrayB 中,保持原有顺序
58
- return 0;
59
- });
60
- return newColumns.map(column => ({
61
- ...column,
62
- checked: sort[column.key]?.checked ?? true,
63
- }));
64
- };
@@ -1,244 +0,0 @@
1
- /* eslint-disable @coze-arch/max-line-per-function */
2
- /* eslint-disable @coze-arch/no-batch-import-or-export */
3
- import * as sort from 'react-sortable-hoc';
4
- import { Fragment, useEffect, useMemo, useState } from 'react';
5
-
6
- import {
7
- IconCozHandle,
8
- IconCozTableSetting,
9
- } from '@coze-arch/coze-design/icons';
10
- import {
11
- Button,
12
- Checkbox,
13
- Dropdown,
14
- Typography,
15
- Divider,
16
- Tooltip,
17
- type ColumnProps,
18
- } from '@coze-arch/coze-design';
19
- // @ts-expect-error react-sortable-hoc ts type issue
20
- const { sortableContainer, sortableElement, sortableHandle } = sort;
21
- const { arrayMove } = sort;
22
-
23
- const SortableContainer = sortableContainer(
24
- ({ children }: { children: React.ReactNode }) => (
25
- <div className="max-w-[200px] w-fit rounded-[6px] py-2 px-1 max-h-[372px] overflow-y-auto flex gap-y-1 flex-col">
26
- {children}
27
- </div>
28
- ),
29
- );
30
-
31
- const DragHandle = sortableHandle(() => (
32
- <IconCozHandle className="cursor-grab" aria-label="拖动排序" role="button" />
33
- ));
34
- export interface ColumnItem extends ColumnProps {
35
- key: string;
36
- value: string;
37
- disabled?: boolean;
38
- checked?: boolean;
39
- }
40
-
41
- export interface ColumnSelectorProps {
42
- columns: ColumnItem[];
43
- onChange?: (items: ColumnItem[]) => void;
44
- buttonText?: string;
45
- resetButtonText?: string;
46
- className?: string;
47
- sortable?: boolean;
48
- defaultColumns?: ColumnItem[];
49
- itemRender?: (item: ColumnItem) => React.ReactNode;
50
- footerRender?: (item: ColumnItem[]) => React.ReactNode;
51
- }
52
-
53
- export const ColumnSelector = ({
54
- columns,
55
- defaultColumns = columns,
56
- onChange,
57
- buttonText,
58
- resetButtonText = '重置为默认',
59
- className,
60
- sortable = true,
61
- itemRender,
62
- footerRender,
63
- }: ColumnSelectorProps) => {
64
- const [list, setList] = useState<ColumnItem[]>(() => [...columns]);
65
- const selectedKeys = useMemo(
66
- () => list.filter(item => item.checked).map(item => item.key),
67
- [list],
68
- );
69
- const disabledKeys = useMemo(
70
- () => list.filter(item => item.disabled).map(item => item.key),
71
- [list],
72
- );
73
-
74
- const RenderItem = (value: ColumnItem, slot?: React.ReactNode) => {
75
- const render = itemRender ? itemRender(value) : null;
76
- if (render) {
77
- return render;
78
- }
79
- return (
80
- <span
81
- // ref={spanRef}
82
- className="group flex items-center justify-between py-1 px-2 text-[var(--coz-fg-primary)] z-[99999] select-none hover:bg-[var(--coz-mg-secondary)] rounded-[6px] cursor-pointer bg-white"
83
- style={{
84
- zIndex: 99999,
85
- }}
86
- >
87
- <div
88
- className="flex items-center gap-x-2 max-w-full w-full"
89
- onClick={() => {
90
- if (disabledKeys.includes(value.key ?? '') || value.disabled) {
91
- return;
92
- }
93
- const newKeys = selectedKeys.includes(value.key ?? '')
94
- ? selectedKeys.filter(key => key !== value.key)
95
- : [...selectedKeys, value.key];
96
-
97
- const newColumns = list.map(item => {
98
- if (newKeys.includes(item.key)) {
99
- return {
100
- ...item,
101
- checked: true,
102
- };
103
- }
104
-
105
- return {
106
- ...item,
107
- checked: false,
108
- };
109
- });
110
-
111
- setList(newColumns);
112
- onChange?.(newColumns);
113
- }}
114
- >
115
- <Checkbox
116
- disabled={disabledKeys.includes(value.key ?? '') || value.disabled}
117
- checked={selectedKeys.includes(value.key ?? '')}
118
- aria-label={`选择${value.value}`}
119
- />
120
- <Typography.Text
121
- ellipsis={{
122
- showTooltip: {
123
- opts: {
124
- content: value.value,
125
- theme: 'dark',
126
- },
127
- },
128
- }}
129
- className="text-[13px] text-[var(--coz-fg-primary)] flex-1 overflow-hidden w-full"
130
- style={{
131
- color:
132
- disabledKeys.includes(value.key ?? '') || value.disabled
133
- ? 'var(--coz-fg-dim)'
134
- : '',
135
- }}
136
- >
137
- {value.value}
138
- </Typography.Text>
139
- <div className="opacity-0 group-hover:opacity-100 transition-opacity flex items-center coz-fg-secondary">
140
- {slot}
141
- </div>
142
- </div>
143
- </span>
144
- );
145
- };
146
-
147
- const SortableItem = sortableElement(({ value }: { value: ColumnItem }) =>
148
- RenderItem(value, <DragHandle />),
149
- );
150
-
151
- const handleSortEnd = ({
152
- oldIndex,
153
- newIndex,
154
- }: {
155
- oldIndex: number;
156
- newIndex: number;
157
- }) => {
158
- const newList = arrayMove(list, oldIndex, newIndex);
159
- setList(newList);
160
- onChange?.(newList);
161
- };
162
-
163
- const handleReset = () => {
164
- setList(defaultColumns);
165
- onChange?.(defaultColumns);
166
- };
167
-
168
- useEffect(() => {
169
- setList(columns);
170
- }, [columns]);
171
-
172
- return (
173
- <div className={className}>
174
- <Dropdown
175
- position="bottomRight"
176
- render={
177
- <div
178
- onClick={event => {
179
- event.stopPropagation();
180
- }}
181
- >
182
- <SortableContainer onSortEnd={handleSortEnd} useDragHandle>
183
- <>
184
- {list.map((value, index) =>
185
- value?.disabled || !sortable ? (
186
- <Fragment key={`item-${value.key}`}>
187
- {RenderItem(value)}
188
- </Fragment>
189
- ) : (
190
- <SortableItem
191
- key={`item-${value.key}`}
192
- index={index}
193
- value={value}
194
- />
195
- ),
196
- )}
197
- </>
198
- </SortableContainer>
199
- <Divider />
200
- {footerRender ? (
201
- <div className="flex items-center">
202
- {footerRender(list)}
203
- <Button
204
- color="secondary"
205
- type="secondary"
206
- className="text-center flex-1"
207
- onClick={handleReset}
208
- >
209
- <span className="text-brand font-medium text-[13px]">
210
- {resetButtonText}
211
- </span>
212
- </Button>
213
- </div>
214
- ) : (
215
- <Button
216
- color="secondary"
217
- type="secondary"
218
- className="w-full text-center"
219
- onClick={handleReset}
220
- >
221
- <span className="text-brand font-medium text-[13px]">
222
- {resetButtonText}
223
- </span>
224
- </Button>
225
- )}
226
- </div>
227
- }
228
- trigger="click"
229
- >
230
- <div>
231
- <Tooltip content="列管理" theme="dark" position="top">
232
- <Button
233
- icon={<IconCozTableSetting />}
234
- type="primary"
235
- color="primary"
236
- className="flex items-center justify-center"
237
- aria-label={buttonText}
238
- />
239
- </Tooltip>
240
- </div>
241
- </Dropdown>
242
- </div>
243
- );
244
- };
@@ -1,36 +0,0 @@
1
- import { type MouseEvent } from 'react';
2
-
3
- import classNames from 'classnames';
4
- import { IconCozPencil } from '@coze-arch/coze-design/icons';
5
-
6
- interface Props extends React.HTMLAttributes<SVGElement> {
7
- className?: string;
8
- disabled?: boolean;
9
- onClick?: (e: MouseEvent<SVGElement>) => void;
10
- }
11
-
12
- export function EditIconButton({
13
- disabled,
14
- className,
15
- onClick,
16
- ...rest
17
- }: Props) {
18
- return (
19
- <IconCozPencil
20
- {...rest}
21
- fontSize={14}
22
- className={classNames(
23
- 'text-[var(--coz-fg-dim)]',
24
- disabled
25
- ? 'cursor-not-allowed'
26
- : 'cursor-pointer hover:text-[rgba(var(--coze-up-brand-9))]',
27
- className,
28
- )}
29
- onClick={e => {
30
- if (!disabled) {
31
- onClick?.(e);
32
- }
33
- }}
34
- />
35
- );
36
- }