@canlooks/can-ui 0.0.159 → 0.0.160

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.
@@ -2,11 +2,10 @@ import { Dispatch, ReactElement, SetStateAction } from 'react';
2
2
  import { CurdColumn } from './curd';
3
3
  import { RowType } from '../dataGrid';
4
4
  import { Id } from '../../types';
5
- type CurdColumnConfigProps<R extends RowType> = {
5
+ export type CurdColumnConfigProps<R extends RowType> = {
6
6
  columns?: CurdColumn<R>[];
7
7
  innerVisible: Id[];
8
8
  setInnerVisible: Dispatch<SetStateAction<Id[]>>;
9
9
  setInnerOrder: Dispatch<SetStateAction<Id[]>>;
10
10
  };
11
11
  export declare const CurdColumnConfig: <R extends RowType>(props: CurdColumnConfigProps<R>) => ReactElement;
12
- export {};
@@ -14,7 +14,7 @@ const sortable_1 = require("@dnd-kit/sortable");
14
14
  const utils_1 = require("../../utils");
15
15
  const icon_1 = require("../icon");
16
16
  const faGear_1 = require("@fortawesome/free-solid-svg-icons/faGear");
17
- exports.CurdColumnConfig = (0, react_1.memo)(({ columns, innerVisible, setInnerVisible, setInnerOrder, }) => {
17
+ exports.CurdColumnConfig = (0, react_1.memo)(({ columns, innerVisible, setInnerVisible, setInnerOrder }) => {
18
18
  columns ||= [];
19
19
  const dragEndHandler = (e) => {
20
20
  const newColumns = (0, utils_1.onDndDragEnd)(e, columns, '_key');
@@ -24,9 +24,16 @@ exports.CurdColumnConfig = (0, react_1.memo)(({ columns, innerVisible, setInnerV
24
24
  return new Set(innerVisible);
25
25
  }, [innerVisible]);
26
26
  const toggleVisible = (key, checked) => {
27
- setInnerVisible(o => checked
27
+ !(0, utils_1.isUnset)(key) && setInnerVisible(o => checked
28
28
  ? [...o, key]
29
29
  : o.filter(k => k !== key));
30
30
  };
31
- return ((0, jsx_runtime_1.jsx)(bubble_1.Bubble, { css: curdColumnConfig_style_1.style, placement: "bottomRight", content: (0, jsx_runtime_1.jsx)(core_1.DndContext, { sensors: (0, utils_1.useDndSensors)(), onDragEnd: dragEndHandler, children: (0, jsx_runtime_1.jsx)(sortable_1.SortableContext, { items: columns?.map((col, i) => col._key ?? i), children: (0, jsx_runtime_1.jsxs)("div", { className: curdColumnConfig_style_1.classes.content, children: [(0, jsx_runtime_1.jsxs)("div", { className: curdColumnConfig_style_1.classes.title, children: [(0, jsx_runtime_1.jsx)("div", { className: curdColumnConfig_style_1.classes.titleText, children: "\u5217\u8BBE\u7F6E" }), (0, jsx_runtime_1.jsx)("div", { className: curdColumnConfig_style_1.classes.description, children: "\u62D6\u62FD\u8C03\u6574\u987A\u5E8F" })] }), columns?.map((col, i) => (0, jsx_runtime_1.jsx)(sortableItem_1.SortableItem, { id: col._key ?? i, component: menuItem_1.MenuItem, className: curdColumnConfig_style_1.classes.item, prefix: (0, jsx_runtime_1.jsx)(checkbox_1.Checkbox, { className: curdColumnConfig_style_1.classes.checkbox, checked: !(0, utils_1.isUnset)(col._key) && visibleSet.has(col._key), onChange: e => !(0, utils_1.isUnset)(col._key) && toggleVisible(col._key, e.target.checked) }), label: col.title }, col._key ?? i))] }) }) }), autoClose: false, children: (0, jsx_runtime_1.jsx)(button_1.Button, { shape: "circular", variant: "text", color: "text.secondary", children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: faGear_1.faGear }) }) }));
31
+ return ((0, jsx_runtime_1.jsx)(bubble_1.Bubble, { css: curdColumnConfig_style_1.style, placement: "bottomRight", content: (0, jsx_runtime_1.jsx)(core_1.DndContext, { sensors: (0, utils_1.useDndSensors)(), onDragEnd: dragEndHandler, children: (0, jsx_runtime_1.jsx)(sortable_1.SortableContext, { items: columns?.map((col, i) => col._key ?? i), children: (0, jsx_runtime_1.jsxs)("div", { className: curdColumnConfig_style_1.classes.content, children: [(0, jsx_runtime_1.jsxs)("div", { className: curdColumnConfig_style_1.classes.title, children: [(0, jsx_runtime_1.jsx)("div", { className: curdColumnConfig_style_1.classes.titleText, children: "\u5217\u8BBE\u7F6E" }), (0, jsx_runtime_1.jsx)("div", { className: curdColumnConfig_style_1.classes.description, children: "\u62D6\u62FD\u8C03\u6574\u987A\u5E8F" })] }), columns?.map((col, i) => {
32
+ const id = col._key;
33
+ const checked = !(0, utils_1.isUnset)(id) && visibleSet.has(id);
34
+ return ((0, jsx_runtime_1.jsx)(sortableItem_1.SortableItem, { id: id ?? i, component: menuItem_1.MenuItem, className: curdColumnConfig_style_1.classes.item, prefix: (0, jsx_runtime_1.jsx)(checkbox_1.Checkbox, { className: curdColumnConfig_style_1.classes.checkbox, checked: checked, onChange: e => {
35
+ e.stopPropagation();
36
+ toggleVisible(id, e.target.checked);
37
+ } }), onClick: () => toggleVisible(id, !checked), label: col.titleText ?? col.title, noStyle: true }, id ?? i));
38
+ })] }) }) }), autoClose: false, children: (0, jsx_runtime_1.jsx)(button_1.Button, { shape: "circular", variant: "text", color: "text.secondary", children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: faGear_1.faGear }) }) }));
32
39
  });
@@ -32,8 +32,8 @@ exports.style = (0, utils_1.defineCss)(({ spacing, text }) => (0, react_1.css) `
32
32
  }
33
33
 
34
34
  .${exports.classes.item} {
35
- cursor: move;
36
-
35
+ cursor: pointer;
36
+
37
37
  &[data-dragging=true] {
38
38
  position: relative;
39
39
  z-index: 1;
@@ -12,6 +12,8 @@ import { BubbleProps } from '../bubble';
12
12
  export type RowType = Obj;
13
13
  export interface ColumnType<R extends RowType = RowType> extends Omit<ComponentProps<'td'>, 'key' | 'ref' | 'title' | 'children'>, Omit<ComponentProps<'th'>, 'key' | 'ref' | 'title' | 'children'> {
14
14
  title?: ReactNode;
15
+ /** 当`title`非字符串时,可指定该属性,用于渲染在 “列设置” 中 */
16
+ titleText?: string;
15
17
  /** 若不指定key,默认使用{@link field}作为key */
16
18
  key?: string | number;
17
19
  children?: ColumnType<R>[];
@@ -26,7 +28,7 @@ export interface ColumnType<R extends RowType = RowType> extends Omit<ComponentP
26
28
  */
27
29
  sorter?: boolean | ((a: R, b: R) => number);
28
30
  /**
29
- * @enum true 不会弹出气泡框,需配合{@link DataGridBaseProps.onFilterClick}实现筛选逻辑
31
+ * @enum true 不会弹出气泡框,需配合{@link DataGridBaseProp['onFilterClick']}实现筛选逻辑
30
32
  * @enum FilterOptionsProps 传递至`OptionsBase`组件
31
33
  * @example FilterOptionsProps
32
34
  * {
@@ -82,7 +82,7 @@ exports.DataGridHead = (0, react_2.memo)(({ allowSelectAll, columnResizable, fla
82
82
  }
83
83
  const {
84
84
  // 排除无需加入dom节点的属性
85
- title, key, children, field, render, sorter, filter, _key, _negativeRowSpan = 0, ...colProps } = col;
85
+ title, titleText, key, children, field, render, sorter, filter, _key, _negativeRowSpan = 0, ...colProps } = col;
86
86
  const sortable = sorter && !children?.length;
87
87
  const isOrderingColumn = orderColumn === _key;
88
88
  const currentOrderType = isOrderingColumn ? orderType : 'descend';
@@ -56,7 +56,7 @@ exports.DataGridRows = (0, react_2.memo)(({ rows, _level = 0 }) => {
56
56
  // 排除无需加入dom节点的属性
57
57
  // width属性只需加入thead列中,普通列需排除
58
58
  // rowSpan与colSpan需排除
59
- title, key, children, field, render, sorter, filter, width, _key, _negativeRowSpan, rowSpan, colSpan, ..._colProps } = col;
59
+ title, titleText, key, children, field, render, sorter, filter, width, _key, _negativeRowSpan, rowSpan, colSpan, ..._colProps } = col;
60
60
  const renderedContent = (0, utils_1.renderCell)({ render, field }, row, i, arr);
61
61
  const shouldRenderExpand = expandableIndex === j - 1;
62
62
  return ((0, react_1.createElement)(table_1.TdCell, { ..._colProps, key: _key, className: (0, utils_1.clsx)(_colProps.className, shouldRenderExpand && dataGrid_style_1.classes.expandable) }, shouldRenderExpand
@@ -5,6 +5,7 @@ export type SortableItemOwnProps = {
5
5
  id: Id;
6
6
  disabled?: boolean;
7
7
  sortableArguments?: Arguments;
8
+ noStyle?: boolean;
8
9
  };
9
10
  export type SortableItemProps<C extends ElementType = 'div'> = OverridableProps<SortableItemOwnProps, C>;
10
11
  export declare const SortableItem: OverridableComponent<SortableItemOwnProps>;
@@ -8,7 +8,7 @@ const utilities_1 = require("@dnd-kit/utilities");
8
8
  const utils_1 = require("../../utils");
9
9
  const react_2 = require("@emotion/react");
10
10
  const sortableItem_style_1 = require("./sortableItem.style");
11
- exports.SortableItem = (({ component: Component = 'div', id, disabled, sortableArguments, ...props }) => {
11
+ exports.SortableItem = (({ component: Component = 'div', id, disabled, sortableArguments, noStyle, ...props }) => {
12
12
  const { attributes, isDragging, listeners, setNodeRef, transform, transition } = (0, sortable_1.useSortable)({
13
13
  ...sortableArguments,
14
14
  disabled,
@@ -36,5 +36,5 @@ exports.SortableItem = (({ component: Component = 'div', id, disabled, sortableA
36
36
  transform: utilities_1.CSS.Transform.toString(transform),
37
37
  transition,
38
38
  ...props.style
39
- }, onTouchStart: disabled ? void 0 : onTouchStart, "data-dragging": isDragging, "data-draggable": !disabled }), isDragging && (0, jsx_runtime_1.jsx)(react_2.Global, { styles: sortableItem_style_1.globalGrabbingStyle })] }));
39
+ }, onTouchStart: disabled ? void 0 : onTouchStart, "data-no-style": noStyle, "data-dragging": isDragging, "data-draggable": !disabled }), !noStyle && isDragging && (0, jsx_runtime_1.jsx)(react_2.Global, { styles: sortableItem_style_1.globalGrabbingStyle })] }));
40
40
  });
@@ -5,11 +5,15 @@ const react_1 = require("@emotion/react");
5
5
  const utils_1 = require("../../utils");
6
6
  exports.classes = (0, utils_1.defineInnerClasses)('sortable-item');
7
7
  exports.style = (0, react_1.css) `
8
- &[data-draggable=true] {
9
- cursor: grab;
8
+ @layer reset {
9
+ &:not([data-no-style=true]) {
10
+ &[data-draggable=true] {
11
+ cursor: grab;
10
12
 
11
- &:active {
12
- cursor: grabbing;
13
+ &:active {
14
+ cursor: grabbing;
15
+ }
16
+ }
13
17
  }
14
18
  }
15
19
  `;
@@ -84,7 +84,7 @@ function useEscapeClosable({ escapeClosable, close }, onEscape) {
84
84
  if (escapeClosable) {
85
85
  const keydown = (e) => {
86
86
  if (e.key === 'Escape') {
87
- const { nextSibling } = overlayRef.current;
87
+ const nextSibling = overlayRef.current?.nextSibling;
88
88
  if (!nextSibling || nextSibling.dataset.open !== 'true') {
89
89
  // 后面无元素,或后一个元素已关闭,才能关闭当前
90
90
  e.preventDefault();
@@ -2,11 +2,10 @@ import { Dispatch, ReactElement, SetStateAction } from 'react';
2
2
  import { CurdColumn } from './curd';
3
3
  import { RowType } from '../dataGrid';
4
4
  import { Id } from '../../types';
5
- type CurdColumnConfigProps<R extends RowType> = {
5
+ export type CurdColumnConfigProps<R extends RowType> = {
6
6
  columns?: CurdColumn<R>[];
7
7
  innerVisible: Id[];
8
8
  setInnerVisible: Dispatch<SetStateAction<Id[]>>;
9
9
  setInnerOrder: Dispatch<SetStateAction<Id[]>>;
10
10
  };
11
11
  export declare const CurdColumnConfig: <R extends RowType>(props: CurdColumnConfigProps<R>) => ReactElement;
12
- export {};
@@ -11,7 +11,7 @@ import { SortableContext } from '@dnd-kit/sortable';
11
11
  import { isUnset, onDndDragEnd, useDndSensors } from '../../utils';
12
12
  import { Icon } from '../icon';
13
13
  import { faGear } from '@fortawesome/free-solid-svg-icons/faGear';
14
- export const CurdColumnConfig = memo(({ columns, innerVisible, setInnerVisible, setInnerOrder, }) => {
14
+ export const CurdColumnConfig = memo(({ columns, innerVisible, setInnerVisible, setInnerOrder }) => {
15
15
  columns ||= [];
16
16
  const dragEndHandler = (e) => {
17
17
  const newColumns = onDndDragEnd(e, columns, '_key');
@@ -21,9 +21,16 @@ export const CurdColumnConfig = memo(({ columns, innerVisible, setInnerVisible,
21
21
  return new Set(innerVisible);
22
22
  }, [innerVisible]);
23
23
  const toggleVisible = (key, checked) => {
24
- setInnerVisible(o => checked
24
+ !isUnset(key) && setInnerVisible(o => checked
25
25
  ? [...o, key]
26
26
  : o.filter(k => k !== key));
27
27
  };
28
- return (_jsx(Bubble, { css: style, placement: "bottomRight", content: _jsx(DndContext, { sensors: useDndSensors(), onDragEnd: dragEndHandler, children: _jsx(SortableContext, { items: columns?.map((col, i) => col._key ?? i), children: _jsxs("div", { className: classes.content, children: [_jsxs("div", { className: classes.title, children: [_jsx("div", { className: classes.titleText, children: "\u5217\u8BBE\u7F6E" }), _jsx("div", { className: classes.description, children: "\u62D6\u62FD\u8C03\u6574\u987A\u5E8F" })] }), columns?.map((col, i) => _jsx(SortableItem, { id: col._key ?? i, component: MenuItem, className: classes.item, prefix: _jsx(Checkbox, { className: classes.checkbox, checked: !isUnset(col._key) && visibleSet.has(col._key), onChange: e => !isUnset(col._key) && toggleVisible(col._key, e.target.checked) }), label: col.title }, col._key ?? i))] }) }) }), autoClose: false, children: _jsx(Button, { shape: "circular", variant: "text", color: "text.secondary", children: _jsx(Icon, { icon: faGear }) }) }));
28
+ return (_jsx(Bubble, { css: style, placement: "bottomRight", content: _jsx(DndContext, { sensors: useDndSensors(), onDragEnd: dragEndHandler, children: _jsx(SortableContext, { items: columns?.map((col, i) => col._key ?? i), children: _jsxs("div", { className: classes.content, children: [_jsxs("div", { className: classes.title, children: [_jsx("div", { className: classes.titleText, children: "\u5217\u8BBE\u7F6E" }), _jsx("div", { className: classes.description, children: "\u62D6\u62FD\u8C03\u6574\u987A\u5E8F" })] }), columns?.map((col, i) => {
29
+ const id = col._key;
30
+ const checked = !isUnset(id) && visibleSet.has(id);
31
+ return (_jsx(SortableItem, { id: id ?? i, component: MenuItem, className: classes.item, prefix: _jsx(Checkbox, { className: classes.checkbox, checked: checked, onChange: e => {
32
+ e.stopPropagation();
33
+ toggleVisible(id, e.target.checked);
34
+ } }), onClick: () => toggleVisible(id, !checked), label: col.titleText ?? col.title, noStyle: true }, id ?? i));
35
+ })] }) }) }), autoClose: false, children: _jsx(Button, { shape: "circular", variant: "text", color: "text.secondary", children: _jsx(Icon, { icon: faGear }) }) }));
29
36
  });
@@ -29,8 +29,8 @@ export const style = defineCss(({ spacing, text }) => css `
29
29
  }
30
30
 
31
31
  .${classes.item} {
32
- cursor: move;
33
-
32
+ cursor: pointer;
33
+
34
34
  &[data-dragging=true] {
35
35
  position: relative;
36
36
  z-index: 1;
@@ -12,6 +12,8 @@ import { BubbleProps } from '../bubble';
12
12
  export type RowType = Obj;
13
13
  export interface ColumnType<R extends RowType = RowType> extends Omit<ComponentProps<'td'>, 'key' | 'ref' | 'title' | 'children'>, Omit<ComponentProps<'th'>, 'key' | 'ref' | 'title' | 'children'> {
14
14
  title?: ReactNode;
15
+ /** 当`title`非字符串时,可指定该属性,用于渲染在 “列设置” 中 */
16
+ titleText?: string;
15
17
  /** 若不指定key,默认使用{@link field}作为key */
16
18
  key?: string | number;
17
19
  children?: ColumnType<R>[];
@@ -26,7 +28,7 @@ export interface ColumnType<R extends RowType = RowType> extends Omit<ComponentP
26
28
  */
27
29
  sorter?: boolean | ((a: R, b: R) => number);
28
30
  /**
29
- * @enum true 不会弹出气泡框,需配合{@link DataGridBaseProps.onFilterClick}实现筛选逻辑
31
+ * @enum true 不会弹出气泡框,需配合{@link DataGridBaseProp['onFilterClick']}实现筛选逻辑
30
32
  * @enum FilterOptionsProps 传递至`OptionsBase`组件
31
33
  * @example FilterOptionsProps
32
34
  * {
@@ -79,7 +79,7 @@ export const DataGridHead = memo(({ allowSelectAll, columnResizable, flattedColu
79
79
  }
80
80
  const {
81
81
  // 排除无需加入dom节点的属性
82
- title, key, children, field, render, sorter, filter, _key, _negativeRowSpan = 0, ...colProps } = col;
82
+ title, titleText, key, children, field, render, sorter, filter, _key, _negativeRowSpan = 0, ...colProps } = col;
83
83
  const sortable = sorter && !children?.length;
84
84
  const isOrderingColumn = orderColumn === _key;
85
85
  const currentOrderType = isOrderingColumn ? orderType : 'descend';
@@ -53,7 +53,7 @@ export const DataGridRows = memo(({ rows, _level = 0 }) => {
53
53
  // 排除无需加入dom节点的属性
54
54
  // width属性只需加入thead列中,普通列需排除
55
55
  // rowSpan与colSpan需排除
56
- title, key, children, field, render, sorter, filter, width, _key, _negativeRowSpan, rowSpan, colSpan, ..._colProps } = col;
56
+ title, titleText, key, children, field, render, sorter, filter, width, _key, _negativeRowSpan, rowSpan, colSpan, ..._colProps } = col;
57
57
  const renderedContent = renderCell({ render, field }, row, i, arr);
58
58
  const shouldRenderExpand = expandableIndex === j - 1;
59
59
  return (_createElement(TdCell, { ..._colProps, key: _key, className: clsx(_colProps.className, shouldRenderExpand && classes.expandable) }, shouldRenderExpand
@@ -5,6 +5,7 @@ export type SortableItemOwnProps = {
5
5
  id: Id;
6
6
  disabled?: boolean;
7
7
  sortableArguments?: Arguments;
8
+ noStyle?: boolean;
8
9
  };
9
10
  export type SortableItemProps<C extends ElementType = 'div'> = OverridableProps<SortableItemOwnProps, C>;
10
11
  export declare const SortableItem: OverridableComponent<SortableItemOwnProps>;
@@ -5,7 +5,7 @@ import { CSS } from '@dnd-kit/utilities';
5
5
  import { cloneRef, clsx, useSync } from '../../utils';
6
6
  import { Global } from '@emotion/react';
7
7
  import { classes, globalGrabbingStyle, style } from './sortableItem.style';
8
- export const SortableItem = (({ component: Component = 'div', id, disabled, sortableArguments, ...props }) => {
8
+ export const SortableItem = (({ component: Component = 'div', id, disabled, sortableArguments, noStyle, ...props }) => {
9
9
  const { attributes, isDragging, listeners, setNodeRef, transform, transition } = useSortable({
10
10
  ...sortableArguments,
11
11
  disabled,
@@ -33,5 +33,5 @@ export const SortableItem = (({ component: Component = 'div', id, disabled, sort
33
33
  transform: CSS.Transform.toString(transform),
34
34
  transition,
35
35
  ...props.style
36
- }, onTouchStart: disabled ? void 0 : onTouchStart, "data-dragging": isDragging, "data-draggable": !disabled }), isDragging && _jsx(Global, { styles: globalGrabbingStyle })] }));
36
+ }, onTouchStart: disabled ? void 0 : onTouchStart, "data-no-style": noStyle, "data-dragging": isDragging, "data-draggable": !disabled }), !noStyle && isDragging && _jsx(Global, { styles: globalGrabbingStyle })] }));
37
37
  });
@@ -2,11 +2,15 @@ import { css } from '@emotion/react';
2
2
  import { defineInnerClasses } from '../../utils';
3
3
  export const classes = defineInnerClasses('sortable-item');
4
4
  export const style = css `
5
- &[data-draggable=true] {
6
- cursor: grab;
5
+ @layer reset {
6
+ &:not([data-no-style=true]) {
7
+ &[data-draggable=true] {
8
+ cursor: grab;
7
9
 
8
- &:active {
9
- cursor: grabbing;
10
+ &:active {
11
+ cursor: grabbing;
12
+ }
13
+ }
10
14
  }
11
15
  }
12
16
  `;
@@ -80,7 +80,7 @@ export function useEscapeClosable({ escapeClosable, close }, onEscape) {
80
80
  if (escapeClosable) {
81
81
  const keydown = (e) => {
82
82
  if (e.key === 'Escape') {
83
- const { nextSibling } = overlayRef.current;
83
+ const nextSibling = overlayRef.current?.nextSibling;
84
84
  if (!nextSibling || nextSibling.dataset.open !== 'true') {
85
85
  // 后面无元素,或后一个元素已关闭,才能关闭当前
86
86
  e.preventDefault();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canlooks/can-ui",
3
- "version": "0.0.159",
3
+ "version": "0.0.160",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",