es-grid-template 1.9.57 → 1.9.59

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,9 +1,9 @@
1
1
  import type * as React from "react";
2
2
  import dayjs from "dayjs";
3
- import type { EditType, IColumnType, TypeFilter } from "rc-master-ui";
3
+ import type { TypeFilter } from "rc-master-ui";
4
4
  import type { Key } from "react";
5
5
  import type { ColumnsTable } from "./../index";
6
- import type { AnyObject, ColumnTable, GetRowKey, IFormat } from "../type";
6
+ import type { AnyObject, ColumnTable, EditType, GetRowKey, IColumnType, IFormat } from "../type";
7
7
  export declare const newGuid: () => any;
8
8
  export declare const sumDataByField: (data: any[], field: string) => any;
9
9
  export declare const checkThousandSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
@@ -1,18 +1,10 @@
1
1
  import dayjs from "dayjs";
2
- // import type {ColumnTable, GetRowKey, IFormat, Presets} from "./../ type"
3
2
  import moment from "moment/moment";
4
- // import type {SelectionSettings} from "../type"
5
- // import type {AnyObject} from "../type"
6
3
  import { v4 as uuidv4 } from 'uuid';
7
4
  import { presetPalettes } from "@ant-design/colors";
8
- // import {Table} from "rc-master-ui"
9
- // import {flatColumns2} from "./columns"
10
- // import {SELECTION_COLUMN} from "./useColumns"
11
-
12
5
  export const newGuid = () => {
13
6
  for (let i = 0; i < 20; i++) {
14
7
  // @ts-ignore
15
- // const id = crypto.randomUUID()
16
8
  return uuidv4();
17
9
  }
18
10
  };
@@ -94,10 +94,10 @@ export type IFormat = {
94
94
  yearFormat?: string;
95
95
  };
96
96
  export type RowSelectMethod = 'all' | 'none' | 'invert' | 'single' | 'multiple';
97
- export type EditType = 'text' | 'numeric' | 'asyncSelect' | 'date' | 'datetime' | 'time' | 'week' | 'month' | 'quarter' | 'year' | 'select' | 'checkbox' | 'currency' | 'image' | 'selectTable' | 'customSelect' | 'form' | 'color' | 'treeSelect' | 'file';
97
+ export type EditType = 'text' | 'numeric' | 'asyncSelect' | 'date' | 'datetime' | 'time' | 'week' | 'month' | 'quarter' | 'year' | 'select' | 'checkbox' | 'currency' | 'image' | 'selectTable' | 'customSelect' | 'form' | 'color' | 'link' | 'treeSelect' | 'file';
98
98
  export type ITextAlign = 'center' | 'left' | 'right';
99
99
  export type TypeFilter = 'Text' | 'Date' | 'Time' | 'Datetime' | 'DateRange' | 'Month' | 'Quarter' | 'Year' | 'Week' | 'Number' | 'NumberRange' | 'Dropdown' | 'DropTree' | 'Checkbox' | 'CheckboxTree' | 'CheckboxDropdown';
100
- export type IColumnType = 'number' | 'time' | 'date' | 'week' | 'month' | 'file' | 'quarter' | 'year' | 'datetime' | 'string' | 'boolean' | 'checkbox' | 'color' | null | undefined;
100
+ export type IColumnType = 'number' | 'time' | 'date' | 'week' | 'month' | 'file' | 'quarter' | 'year' | 'datetime' | 'string' | 'boolean' | 'checkbox' | 'color' | 'link' | null | undefined;
101
101
  export type FilterOperator = 'equal' | 'notequal' | 'greaterthan' | 'greaterthanorequal' | 'lessthan' | 'lessthanorequal' | 'startswith' | 'endswith' | 'contains';
102
102
  export type FixedType = 'left' | 'right' | boolean;
103
103
  export type SelectMode = 'checkbox' | 'radio' | undefined;
@@ -241,6 +241,7 @@ export type ColumnTable<RecordType = AnyObject> = {
241
241
  textAlign?: ITextAlign;
242
242
  /** Template custom render cell */
243
243
  template?: ReactNode | ReactElement | ((args: ColumnTemplate<RecordType>) => ReactNode | ReactElement);
244
+ linkTemplate?: ReactNode | ReactElement | ((args: ColumnTemplate<RecordType>) => ReactNode | ReactElement);
244
245
  /** Hiển thị tooltip cell */
245
246
  showTooltip?: boolean;
246
247
  /** Nội dung tooltip của cell */
@@ -811,6 +812,7 @@ export type RangeState = {
811
812
  endColIndex: number | undefined;
812
813
  rowIds: string[];
813
814
  colIds: string[];
815
+ type?: any;
814
816
  };
815
817
  export type Sorter = {
816
818
  columnKey: string;
@@ -1,6 +1,5 @@
1
1
  import React from "react";
2
- import type { EditType } from "rc-master-ui";
3
- import type { ColumnTable, IFormat } from "../../grid-component/type";
2
+ import type { ColumnTable, EditType, IFormat } from "../../grid-component/type";
4
3
  interface EditableCellProps<DataType> extends React.HTMLAttributes<HTMLElement> {
5
4
  t?: any;
6
5
  dataIndex: string;
@@ -189,15 +189,16 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
189
189
  align?: import("./../../grid-component/type").ITextAlign;
190
190
  textAlign?: import("./../../grid-component/type").ITextAlign;
191
191
  template?: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode | ((args: import("./../../grid-component/type").ColumnTemplate<RecordType>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
192
+ linkTemplate?: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode | ((args: import("./../../grid-component/type").ColumnTemplate<RecordType>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
192
193
  showTooltip?: boolean;
193
194
  tooltipDescription?: string | ((args: {
194
195
  value: any;
195
196
  rowData: RecordType;
196
197
  }) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
197
- onCellStyles?: Omit<CSSProperties, "position" | "left" | "right" | "width" | "display" | "minWidth"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "position" | "left" | "right" | "width" | "display" | "minWidth">);
198
- onCellHeaderStyles?: Omit<CSSProperties, "position" | "left" | "right" | "width" | "display" | "minWidth"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "position" | "left" | "right" | "width" | "display" | "minWidth">);
198
+ onCellStyles?: Omit<CSSProperties, "position" | "left" | "right" | "display" | "width" | "minWidth"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "position" | "left" | "right" | "display" | "width" | "minWidth">);
199
+ onCellHeaderStyles?: Omit<CSSProperties, "position" | "left" | "right" | "display" | "width" | "minWidth"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "position" | "left" | "right" | "display" | "width" | "minWidth">);
199
200
  onCell?: (rowData: RecordType, index: number) => import("react").TdHTMLAttributes<HTMLTableCellElement>;
200
- onCellFooterStyles?: Omit<CSSProperties, "position" | "left" | "right" | "width" | "display" | "minWidth"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "position" | "left" | "right" | "width" | "display" | "minWidth">);
201
+ onCellFooterStyles?: Omit<CSSProperties, "position" | "left" | "right" | "display" | "width" | "minWidth"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "position" | "left" | "right" | "display" | "width" | "minWidth">);
201
202
  getValue?: (row: any, rowIndex: number) => any;
202
203
  getCellProps?: (value: any, row: any, rowIndex: number) => import("./../../grid-component/type").CellProps;
203
204
  headerCellProps?: import("./../../grid-component/type").CellProps;
@@ -1,6 +1,5 @@
1
1
  import React from "react";
2
- import type { EditType } from "rc-master-ui";
3
- import type { ColumnTable, IFormat } from "../../grid-component/type";
2
+ import type { ColumnTable, EditType, IFormat } from "../../grid-component/type";
4
3
  import type { Column } from "@tanstack/react-table";
5
4
  interface EditableCellProps<DataType> extends React.HTMLAttributes<HTMLElement> {
6
5
  t?: any;
@@ -2,6 +2,8 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import React, { useContext } from "react";
3
3
  import { DatePicker, TimePicker, ColorPicker, Input } from "rc-master-ui";
4
4
  import { Divider, Row, Col, Button } from "rc-master-ui";
5
+ // import type { EditType } from "rc-master-ui"
6
+
5
7
  import { checkDecimalSeparator, checkThousandSeparator, checkFieldKey, convertArrayWithIndent, convertDateToDayjs, convertLabelToTitle, getDatepickerFormat, isDisable, isEmpty, isNullOrUndefined, customWeekStartEndFormat, convertDayjsToDate, parseBooleanToValue, isColor, genPresets, getFormat, removeVietnameseTones, getDateValueType } from "../hook/utils";
6
8
  import classNames from "classnames";
7
9
  import { NumericFormat } from "react-numeric-component";
@@ -483,7 +485,7 @@ const EditableCell = props => {
483
485
  const formState = getValues();
484
486
  const formNewState = {
485
487
  ...getValues(),
486
- [dataIndex]: formState[dataIndex] || undefined
488
+ [dataIndex]: !isNullOrUndefined(formState[dataIndex]) ? formState[dataIndex] : undefined
487
489
  };
488
490
  // @ts-ignore
489
491
  const prevState = record[dataIndex] ?? undefined;
@@ -629,7 +631,7 @@ const EditableCell = props => {
629
631
  const formState = getValues();
630
632
  const formNewState = {
631
633
  ...getValues(),
632
- [dataIndex]: formState[dataIndex] || undefined
634
+ [dataIndex]: !isNullOrUndefined(formState[dataIndex]) ? formState[dataIndex] : undefined
633
635
  };
634
636
  // @ts-ignore
635
637
  const prevState = record[dataIndex] ?? undefined;
@@ -773,7 +775,7 @@ const EditableCell = props => {
773
775
  const formState = getValues();
774
776
  const formNewState = {
775
777
  ...getValues(),
776
- [dataIndex]: formState[dataIndex] || undefined
778
+ [dataIndex]: !isNullOrUndefined(formState[dataIndex]) ? formState[dataIndex] : undefined
777
779
  };
778
780
  // @ts-ignore
779
781
  const prevState = record[dataIndex] ?? undefined;
@@ -6,6 +6,7 @@ import classNames from "classnames";
6
6
  import React from "react";
7
7
  import { TableContext } from "../useContext";
8
8
  import { getValueCellString, renderValueCell, toggleRowSelection } from "../hook/useColumns";
9
+ import { Dropdown } from "rc-master-ui";
9
10
  const renderCellIndex = props => {
10
11
  const {
11
12
  parrents,
@@ -213,6 +214,18 @@ const TableBodyCell = props => {
213
214
  const colFormat = typeof columnMeta?.format === 'function' ? columnMeta?.format(record) : columnMeta?.format;
214
215
  const cellFormat = getFormat(colFormat, format);
215
216
  const fomatedValue = renderValueCell(columnMeta, cellValue, record, rowIndex, colIndex, cellFormat, true);
217
+ const cellContent = columnMeta?.template ? typeof columnMeta.template === 'function' ? columnMeta.template({
218
+ field: columnMeta.field,
219
+ index: cell.row.index,
220
+ rowData: cell.row.original,
221
+ value: cell.getValue()
222
+ }) : columnMeta.template : fomatedValue;
223
+ const linkContent = columnMeta?.linkTemplate ? typeof columnMeta.linkTemplate === 'function' ? columnMeta.linkTemplate({
224
+ field: columnMeta.field,
225
+ index: cell.row.index,
226
+ rowData: cell.row.original,
227
+ value: cell.getValue()
228
+ }) : columnMeta.linkTemplate : cellContent;
216
229
  const valueCellString = getValueCellString(columnMeta, cellValue, record, rowIndex, colIndex, format);
217
230
  const tooltipContent = React.useMemo(() => {
218
231
  if (isOpenTooltip === false) {
@@ -375,7 +388,7 @@ const TableBodyCell = props => {
375
388
  "data-row-index": rowNumber,
376
389
  "data-col-key": cell.column.id,
377
390
  "data-tooltip-id": `${id}-tooltip-content`,
378
- "data-tooltip-content": tooltipContent
391
+ "data-tooltip-content": columnMeta?.type === 'link' ? '' : tooltipContent
379
392
  // data-tooltip-delay-show={500}
380
393
  ,
381
394
 
@@ -389,7 +402,8 @@ const TableBodyCell = props => {
389
402
  [`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
390
403
  [`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn,
391
404
  [`${prefix}-grid-cell-text-center`]: columnMeta?.textAlign === 'center',
392
- [`${prefix}-grid-cell-text-right`]: columnMeta?.textAlign === 'right' || columnMeta.type === 'number'
405
+ [`${prefix}-grid-cell-text-right`]: columnMeta?.textAlign === 'right' || columnMeta?.type === 'number',
406
+ [`${prefix}-grid-cell-link`]: columnMeta?.type === 'link'
393
407
  }),
394
408
  style: {
395
409
  ...cellStyles,
@@ -487,6 +501,30 @@ const TableBodyCell = props => {
487
501
  }
488
502
  }
489
503
  }
504
+ }, cellContent && columnMeta?.type === 'link' ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Dropdown, {
505
+ trigger: ['hover'],
506
+ menu: {
507
+ items: [{
508
+ key: '1',
509
+ label: ''
510
+ }]
511
+ },
512
+ dropdownRender: () => /*#__PURE__*/React.createElement("div", {
513
+ style: {
514
+ padding: '1rem',
515
+ backgroundColor: '#ffffff',
516
+ borderRadius: 6,
517
+ boxShadow: '0 6px 16px 0 rgba(0, 0, 0, 0.08),0 3px 6px -4px rgba(0, 0, 0, 0.12),0 9px 28px 8px rgba(0, 0, 0, 0.05)'
518
+ }
519
+ }, linkContent && typeof linkContent === 'string' ? /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("a", {
520
+ href: linkContent,
521
+ target: "_blank",
522
+ rel: "noreferrer"
523
+ }, linkContent)) : linkContent ? linkContent : /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("a", {
524
+ href: typeof cellContent === 'string' ? cellContent : '',
525
+ target: "_blank",
526
+ rel: "noreferrer"
527
+ }, cellContent)))
490
528
  }, /*#__PURE__*/React.createElement("div", {
491
529
  className: classNames('ui-rc_cell-content', {})
492
530
  }, cell.column.getIndex() === expandIconColumnIndex && isDataTree && /*#__PURE__*/React.createElement("div", {
@@ -535,11 +573,42 @@ const TableBodyCell = props => {
535
573
  className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-collapsed"
536
574
  })) : /*#__PURE__*/React.createElement("span", {
537
575
  className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced"
538
- }))), columnMeta.template ? typeof columnMeta.template === 'function' ? columnMeta.template({
539
- field: columnMeta.field,
540
- index: cell.row.index,
541
- rowData: cell.row.original,
542
- value: cell.getValue()
543
- }) : columnMeta.template : fomatedValue));
576
+ }))), cellContent))) : /*#__PURE__*/React.createElement("div", {
577
+ className: classNames('ui-rc_cell-content', {})
578
+ }, cell.column.getIndex() === expandIconColumnIndex && isDataTree && /*#__PURE__*/React.createElement("div", {
579
+ className: "ui-rc-table-row-expand-trigger",
580
+ style: {
581
+ paddingLeft: `${cell.row.depth * 25}px`
582
+ }
583
+ }, /*#__PURE__*/React.createElement("div", null, cell.row.getCanExpand() ? /*#__PURE__*/React.createElement("button", {
584
+ // onClick: row.getToggleExpandedHandler(),
585
+ onClick: e => {
586
+ e.stopPropagation();
587
+ const keys = Object.keys(expanded);
588
+ // @ts-ignore
589
+ const tmp = {
590
+ ...expanded
591
+ };
592
+ if (keys.includes(cell.row.id)) {
593
+ delete tmp[cell.row.id];
594
+ setExpanded(tmp);
595
+ } else {
596
+ setExpanded(old => ({
597
+ ...old,
598
+ [cell.row.id]: true
599
+ }));
600
+ }
601
+ },
602
+ style: {
603
+ cursor: "pointer"
604
+ },
605
+ className: "ui-rc-table-row-expand"
606
+ }, cell.row.getIsExpanded() ? /*#__PURE__*/React.createElement("span", {
607
+ className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-expanded"
608
+ }) : /*#__PURE__*/React.createElement("span", {
609
+ className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-collapsed"
610
+ })) : /*#__PURE__*/React.createElement("span", {
611
+ className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced"
612
+ }))), cellContent));
544
613
  };
545
614
  export default TableBodyCell;