@canlooks/can-ui 0.0.80 → 0.0.82

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CascadePanel = CascadePanel;
4
+ const react_1 = require("@emotion/react");
4
5
  const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
6
  const loading_1 = require("../loading");
6
7
  const loadingIndicator_1 = require("../loadingIndicator");
@@ -39,9 +40,8 @@ function CascadePanel({ options, index = 0 }) {
39
40
  const status = selectionStatus?.get(optVal);
40
41
  const opened = openedPanels[index] === optVal;
41
42
  const hasChildren = !!opt[childrenKey]?.length;
42
- return ((0, jsx_runtime_1.jsx)(menuItem_1.MenuItem, { ...(0, utils_1.mergeComponentProps)({
43
- showCheckbox,
44
- key: optVal
43
+ return ((0, react_1.createElement)(menuItem_1.MenuItem, { ...(0, utils_1.mergeComponentProps)({
44
+ showCheckbox
45
45
  }, opt, {
46
46
  checkboxProps: (0, utils_1.mergeComponentProps)(opt?.checkboxProps, showCheckbox
47
47
  ? {
@@ -62,7 +62,7 @@ function CascadePanel({ options, index = 0 }) {
62
62
  ? (0, jsx_runtime_1.jsx)(loadingIndicator_1.LoadingIndicator, {})
63
63
  : hasChildren && (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: faChevronRight_1.faChevronRight }),
64
64
  children: null
65
- }) }));
65
+ }), key: optVal }));
66
66
  });
67
67
  };
68
68
  const nextOptions = optionsMap.get(openedPanels[index])?.[childrenKey];
@@ -1,5 +1,5 @@
1
1
  import React, { ComponentProps, ReactElement, ReactNode } from 'react';
2
- import { DivProps, Id, Obj, ToRequired } from '../../types';
2
+ import { DivProps, Id, Obj, SlotsAndProps, ToRequired } from '../../types';
3
3
  import { SelectionContextProps } from '../selectionContext';
4
4
  import { PaginationProps } from '../pagination';
5
5
  import { TableProps } from '../table';
@@ -35,7 +35,9 @@ export interface ColumnType<R extends RowType = RowType> extends Omit<ComponentP
35
35
  /** @private 内部使用,在{@link DataGridHead}内计算 */
36
36
  _negativeRowSpan?: number;
37
37
  }
38
- type DataGridSharedProps<R extends RowType = RowType> = {
38
+ interface DataGridSharedProps<R extends RowType = RowType> extends SlotsAndProps<{
39
+ tr: ComponentProps<'tr'>;
40
+ }> {
39
41
  rowProps?(row: R, index: number, rows: R[]): ComponentProps<'tr'>;
40
42
  /** 数据的主键名,默认为`id` */
41
43
  primaryKey?: keyof R;
@@ -50,7 +52,7 @@ type DataGridSharedProps<R extends RowType = RowType> = {
50
52
  /** 子行缩进,默认为`24` */
51
53
  indent?: number;
52
54
  renderExpandIcon?(key: Id, isExpand: boolean, expanded: Id[]): ReactNode;
53
- };
55
+ }
54
56
  export type OrderType = 'ascend' | 'descend';
55
57
  export interface DataGridBaseProps<R extends RowType = RowType> extends DataGridSharedProps<R>, Omit<DivProps, 'defaultValue' | 'onChange'> {
56
58
  columns?: (ColumnType<R> | symbol)[];
@@ -19,7 +19,7 @@ const DataGridContext = (0, react_1.createContext)({});
19
19
  function useDataGridContext() {
20
20
  return (0, react_1.useContext)(DataGridContext);
21
21
  }
22
- exports.DataGrid = (0, react_1.memo)(({ columns, rows, rowProps, primaryKey = 'id', childrenKey = null, filterProps, initialFilterValue, onFilter, onFilterClick, filterPredicate, defaultOrderColumn, orderColumn, defaultOrderType = 'descend', orderType, onOrderChange, selectable, relation = 'dependent', integration = 'shallowest', allowSelectAll = true, clickRowToSelect = true, selectorProps, indent = 24, renderExpandIcon, defaultExpanded, expanded, onExpandedChange, paginatable = true, paginationProps, renderPagination, loading, emptyPlaceholder, columnResizable = false, size, bordered, striped, tableProps, multiple, defaultValue, value, onChange, ...props }) => {
22
+ exports.DataGrid = (0, react_1.memo)(({ slots, slotProps, columns, rows, rowProps, primaryKey = 'id', childrenKey = null, filterProps, initialFilterValue, onFilter, onFilterClick, filterPredicate, defaultOrderColumn, orderColumn, defaultOrderType = 'descend', orderType, onOrderChange, selectable, relation = 'dependent', integration = 'shallowest', allowSelectAll = true, clickRowToSelect = true, selectorProps, indent = 24, renderExpandIcon, defaultExpanded, expanded, onExpandedChange, paginatable = true, paginationProps, renderPagination, loading, emptyPlaceholder, columnResizable = false, size, bordered, striped, tableProps, multiple, defaultValue, value, onChange, ...props }) => {
23
23
  /**
24
24
  * ---------------------------------------------------------------
25
25
  * 选择行
@@ -137,9 +137,11 @@ exports.DataGrid = (0, react_1.memo)(({ columns, rows, rowProps, primaryKey = 'i
137
137
  className: dataGrid_style_1.classes.filterForm,
138
138
  onFinish: filterHandler
139
139
  }), children: (0, jsx_runtime_1.jsx)(columnResize_1.ColumnResizeContext, { columnResizable: columnResizable, children: ({ scrollerRef, tableRef }) => (0, jsx_runtime_1.jsxs)(table_1.TableContainer, { ref: scrollerRef, className: dataGrid_style_1.classes.container, children: [(0, jsx_runtime_1.jsx)(table_1.Table, { size: size, bordered: bordered, striped: striped, ...tableProps, ref: (0, utils_1.cloneRef)(tableProps?.ref, tableRef), children: (0, jsx_runtime_1.jsxs)(selectionContext_1.SelectionContext, { options: rows, primaryKey: primaryKey, childrenKey: childrenKey !== null ? childrenKey : void 0, relation: relation, integration: integration, disabled: !selectable, multiple: multiple, defaultValue: defaultValue, value: value, onChange: onChange, children: [(0, jsx_runtime_1.jsx)(dataGridHead_1.DataGridHead, { rows: rows, flattedColumns: flattedColumns, completedColumns: completedColumns, primaryKey: primaryKey, allowSelectAll: allowSelectAll, columnResizable: columnResizable, orderColumn: innerOrderColumn.current, orderType: innerOrderType.current, onOrderChange: orderChangeHandler, onFilterClick: onFilterClick }), (0, jsx_runtime_1.jsx)("tbody", { children: (0, jsx_runtime_1.jsx)(DataGridContext, { value: (0, react_1.useMemo)(() => ({
140
+ slots, slotProps,
140
141
  rowProps, primaryKey, childrenKey, clickRowToSelect, indent, renderExpandIcon,
141
142
  expandedSet, flattedColumns, toggleExpanded
142
143
  }), [
144
+ slots, slotProps,
143
145
  rowProps, primaryKey, childrenKey, clickRowToSelect, indent, renderExpandIcon,
144
146
  expandedSet, flattedColumns
145
147
  ]), children: !!paginatedRows?.length &&
@@ -18,7 +18,9 @@ const faPlusSquare_1 = require("@fortawesome/free-regular-svg-icons/faPlusSquare
18
18
  const dataGrid_style_1 = require("./dataGrid.style");
19
19
  exports.DataGridRows = (0, react_2.memo)(({ rows, _level = 0 }) => {
20
20
  const { multiple, toggleSelected, selectionStatus } = (0, selectionContext_1.useSelectionContext)();
21
- const { rowProps, primaryKey, childrenKey, clickRowToSelect, indent, renderExpandIcon, expandedSet, flattedColumns, toggleExpanded } = (0, dataGrid_1.useDataGridContext)();
21
+ const { slots, slotProps, rowProps, primaryKey, childrenKey, clickRowToSelect, indent, renderExpandIcon, expandedSet, flattedColumns, toggleExpanded } = (0, dataGrid_1.useDataGridContext)();
22
+ const { tr: Tr = 'tr' } = slots || {};
23
+ const { tr: TrProps } = slotProps || {};
22
24
  return rows?.flatMap((row, i, arr) => {
23
25
  const trKey = row[primaryKey];
24
26
  if ((0, utils_1.isUnset)(trKey)) {
@@ -31,10 +33,12 @@ exports.DataGridRows = (0, react_2.memo)(({ rows, _level = 0 }) => {
31
33
  const currentExpanded = expandable && expandedSet.has(trKey);
32
34
  let expandableIndex = -2;
33
35
  const ret = [
34
- (0, react_1.createElement)("tr", { ..._rowProps, key: trKey, className: (0, utils_1.clsx)(_rowProps, _level > 0 && dataGrid_style_1.classes.sub), onClick: e => {
35
- _rowProps?.onClick?.(e);
36
- clickRowToSelect && toggleSelected(trKey, row);
37
- }, "data-selected": status === 2 }, flattedColumns?.flatMap((col, j) => {
36
+ (0, react_1.createElement)(Tr, { ...(0, utils_1.mergeComponentProps)(TrProps, _rowProps, {
37
+ className: (0, utils_1.clsx)(_rowProps, _level > 0 && dataGrid_style_1.classes.sub),
38
+ onClick() {
39
+ clickRowToSelect && toggleSelected(trKey, row);
40
+ }
41
+ }), key: trKey, "data-selected": status === 2 }, flattedColumns?.flatMap((col, j) => {
38
42
  if (typeof col === 'symbol') {
39
43
  if (col === dataGrid_1.DataGrid.EXPAND_COLUMN) {
40
44
  expandableIndex = j;
@@ -60,7 +60,7 @@ min, max, step, precision, placeholder, disabled, readOnly, autoFocus, defaultVa
60
60
  if (!clearable || disabled || readOnly) {
61
61
  return false;
62
62
  }
63
- return (0, utils_1.isNoValue)(innerValue.current);
63
+ return !(0, utils_1.isNoValue)(innerValue.current);
64
64
  };
65
65
  return ((0, jsx_runtime_1.jsxs)("div", { ...(0, utils_1.mergeComponentProps)(props, {
66
66
  ref: innerRef,
@@ -1,3 +1,4 @@
1
+ import { createElement as _createElement } from "@emotion/react";
1
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
3
  import { Loading } from '../loading';
3
4
  import { LoadingIndicator } from '../loadingIndicator';
@@ -36,9 +37,8 @@ export function CascadePanel({ options, index = 0 }) {
36
37
  const status = selectionStatus?.get(optVal);
37
38
  const opened = openedPanels[index] === optVal;
38
39
  const hasChildren = !!opt[childrenKey]?.length;
39
- return (_jsx(MenuItem, { ...mergeComponentProps({
40
- showCheckbox,
41
- key: optVal
40
+ return (_createElement(MenuItem, { ...mergeComponentProps({
41
+ showCheckbox
42
42
  }, opt, {
43
43
  checkboxProps: mergeComponentProps(opt?.checkboxProps, showCheckbox
44
44
  ? {
@@ -59,7 +59,7 @@ export function CascadePanel({ options, index = 0 }) {
59
59
  ? _jsx(LoadingIndicator, {})
60
60
  : hasChildren && _jsx(Icon, { icon: faChevronRight }),
61
61
  children: null
62
- }) }));
62
+ }), key: optVal }));
63
63
  });
64
64
  };
65
65
  const nextOptions = optionsMap.get(openedPanels[index])?.[childrenKey];
@@ -1,5 +1,5 @@
1
1
  import React, { ComponentProps, ReactElement, ReactNode } from 'react';
2
- import { DivProps, Id, Obj, ToRequired } from '../../types';
2
+ import { DivProps, Id, Obj, SlotsAndProps, ToRequired } from '../../types';
3
3
  import { SelectionContextProps } from '../selectionContext';
4
4
  import { PaginationProps } from '../pagination';
5
5
  import { TableProps } from '../table';
@@ -35,7 +35,9 @@ export interface ColumnType<R extends RowType = RowType> extends Omit<ComponentP
35
35
  /** @private 内部使用,在{@link DataGridHead}内计算 */
36
36
  _negativeRowSpan?: number;
37
37
  }
38
- type DataGridSharedProps<R extends RowType = RowType> = {
38
+ interface DataGridSharedProps<R extends RowType = RowType> extends SlotsAndProps<{
39
+ tr: ComponentProps<'tr'>;
40
+ }> {
39
41
  rowProps?(row: R, index: number, rows: R[]): ComponentProps<'tr'>;
40
42
  /** 数据的主键名,默认为`id` */
41
43
  primaryKey?: keyof R;
@@ -50,7 +52,7 @@ type DataGridSharedProps<R extends RowType = RowType> = {
50
52
  /** 子行缩进,默认为`24` */
51
53
  indent?: number;
52
54
  renderExpandIcon?(key: Id, isExpand: boolean, expanded: Id[]): ReactNode;
53
- };
55
+ }
54
56
  export type OrderType = 'ascend' | 'descend';
55
57
  export interface DataGridBaseProps<R extends RowType = RowType> extends DataGridSharedProps<R>, Omit<DivProps, 'defaultValue' | 'onChange'> {
56
58
  columns?: (ColumnType<R> | symbol)[];
@@ -15,7 +15,7 @@ const DataGridContext = createContext({});
15
15
  export function useDataGridContext() {
16
16
  return useContext(DataGridContext);
17
17
  }
18
- export const DataGrid = memo(({ columns, rows, rowProps, primaryKey = 'id', childrenKey = null, filterProps, initialFilterValue, onFilter, onFilterClick, filterPredicate, defaultOrderColumn, orderColumn, defaultOrderType = 'descend', orderType, onOrderChange, selectable, relation = 'dependent', integration = 'shallowest', allowSelectAll = true, clickRowToSelect = true, selectorProps, indent = 24, renderExpandIcon, defaultExpanded, expanded, onExpandedChange, paginatable = true, paginationProps, renderPagination, loading, emptyPlaceholder, columnResizable = false, size, bordered, striped, tableProps, multiple, defaultValue, value, onChange, ...props }) => {
18
+ export const DataGrid = memo(({ slots, slotProps, columns, rows, rowProps, primaryKey = 'id', childrenKey = null, filterProps, initialFilterValue, onFilter, onFilterClick, filterPredicate, defaultOrderColumn, orderColumn, defaultOrderType = 'descend', orderType, onOrderChange, selectable, relation = 'dependent', integration = 'shallowest', allowSelectAll = true, clickRowToSelect = true, selectorProps, indent = 24, renderExpandIcon, defaultExpanded, expanded, onExpandedChange, paginatable = true, paginationProps, renderPagination, loading, emptyPlaceholder, columnResizable = false, size, bordered, striped, tableProps, multiple, defaultValue, value, onChange, ...props }) => {
19
19
  /**
20
20
  * ---------------------------------------------------------------
21
21
  * 选择行
@@ -133,9 +133,11 @@ export const DataGrid = memo(({ columns, rows, rowProps, primaryKey = 'id', chil
133
133
  className: classes.filterForm,
134
134
  onFinish: filterHandler
135
135
  }), children: _jsx(ColumnResizeContext, { columnResizable: columnResizable, children: ({ scrollerRef, tableRef }) => _jsxs(TableContainer, { ref: scrollerRef, className: classes.container, children: [_jsx(Table, { size: size, bordered: bordered, striped: striped, ...tableProps, ref: cloneRef(tableProps?.ref, tableRef), children: _jsxs(SelectionContext, { options: rows, primaryKey: primaryKey, childrenKey: childrenKey !== null ? childrenKey : void 0, relation: relation, integration: integration, disabled: !selectable, multiple: multiple, defaultValue: defaultValue, value: value, onChange: onChange, children: [_jsx(DataGridHead, { rows: rows, flattedColumns: flattedColumns, completedColumns: completedColumns, primaryKey: primaryKey, allowSelectAll: allowSelectAll, columnResizable: columnResizable, orderColumn: innerOrderColumn.current, orderType: innerOrderType.current, onOrderChange: orderChangeHandler, onFilterClick: onFilterClick }), _jsx("tbody", { children: _jsx(DataGridContext, { value: useMemo(() => ({
136
+ slots, slotProps,
136
137
  rowProps, primaryKey, childrenKey, clickRowToSelect, indent, renderExpandIcon,
137
138
  expandedSet, flattedColumns, toggleExpanded
138
139
  }), [
140
+ slots, slotProps,
139
141
  rowProps, primaryKey, childrenKey, clickRowToSelect, indent, renderExpandIcon,
140
142
  expandedSet, flattedColumns
141
143
  ]), children: !!paginatedRows?.length &&
@@ -3,7 +3,7 @@ import { createElement as _createElement } from "@emotion/react";
3
3
  import { memo } from 'react';
4
4
  import { DataGrid, useDataGridContext } from './dataGrid';
5
5
  import { useSelectionContext } from '../selectionContext';
6
- import { clsx, isUnset, renderCell } from '../../utils';
6
+ import { clsx, isUnset, mergeComponentProps, renderCell } from '../../utils';
7
7
  import { Checkbox } from '../checkbox';
8
8
  import { Radio } from '../radio';
9
9
  import { TdCell } from '../table';
@@ -15,7 +15,9 @@ import { faPlusSquare } from '@fortawesome/free-regular-svg-icons/faPlusSquare';
15
15
  import { classes } from './dataGrid.style';
16
16
  export const DataGridRows = memo(({ rows, _level = 0 }) => {
17
17
  const { multiple, toggleSelected, selectionStatus } = useSelectionContext();
18
- const { rowProps, primaryKey, childrenKey, clickRowToSelect, indent, renderExpandIcon, expandedSet, flattedColumns, toggleExpanded } = useDataGridContext();
18
+ const { slots, slotProps, rowProps, primaryKey, childrenKey, clickRowToSelect, indent, renderExpandIcon, expandedSet, flattedColumns, toggleExpanded } = useDataGridContext();
19
+ const { tr: Tr = 'tr' } = slots || {};
20
+ const { tr: TrProps } = slotProps || {};
19
21
  return rows?.flatMap((row, i, arr) => {
20
22
  const trKey = row[primaryKey];
21
23
  if (isUnset(trKey)) {
@@ -28,10 +30,12 @@ export const DataGridRows = memo(({ rows, _level = 0 }) => {
28
30
  const currentExpanded = expandable && expandedSet.has(trKey);
29
31
  let expandableIndex = -2;
30
32
  const ret = [
31
- _createElement("tr", { ..._rowProps, key: trKey, className: clsx(_rowProps, _level > 0 && classes.sub), onClick: e => {
32
- _rowProps?.onClick?.(e);
33
- clickRowToSelect && toggleSelected(trKey, row);
34
- }, "data-selected": status === 2 }, flattedColumns?.flatMap((col, j) => {
33
+ _createElement(Tr, { ...mergeComponentProps(TrProps, _rowProps, {
34
+ className: clsx(_rowProps, _level > 0 && classes.sub),
35
+ onClick() {
36
+ clickRowToSelect && toggleSelected(trKey, row);
37
+ }
38
+ }), key: trKey, "data-selected": status === 2 }, flattedColumns?.flatMap((col, j) => {
35
39
  if (typeof col === 'symbol') {
36
40
  if (col === DataGrid.EXPAND_COLUMN) {
37
41
  expandableIndex = j;
@@ -57,7 +57,7 @@ min, max, step, precision, placeholder, disabled, readOnly, autoFocus, defaultVa
57
57
  if (!clearable || disabled || readOnly) {
58
58
  return false;
59
59
  }
60
- return isNoValue(innerValue.current);
60
+ return !isNoValue(innerValue.current);
61
61
  };
62
62
  return (_jsxs("div", { ...mergeComponentProps(props, {
63
63
  ref: innerRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canlooks/can-ui",
3
- "version": "0.0.80",
3
+ "version": "0.0.82",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",