@economic/taco 2.17.1 → 2.17.2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Table3/components/columns/cell/EditingCell.d.ts +1 -0
- package/dist/components/Table3/components/columns/cell/Indicator.d.ts +5 -0
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/Cell.js +12 -7
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/Cell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/DisplayCell.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/DisplayCell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingCell.js +11 -6
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingCell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/Indicator.js +15 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/Indicator.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Actions.js +6 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Actions.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/EditingActions.js +10 -4
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/EditingActions.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintIFrame.js +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/listeners/useTableRowSelectionListener.js +7 -2
- package/dist/esm/packages/taco/src/primitives/Table/useTable/listeners/useTableRowSelectionListener.js.map +1 -1
- package/dist/taco.cjs.development.js +121 -85
- package/dist/taco.cjs.development.js.map +1 -1
- package/dist/taco.cjs.production.min.js +1 -1
- package/dist/taco.cjs.production.min.js.map +1 -1
- package/package.json +2 -2
- package/types.json +3083 -2937
@@ -4,6 +4,7 @@ export declare type EditingCellProps<TType = unknown> = CellContext<TType, unkno
|
|
4
4
|
highlighted?: boolean;
|
5
5
|
highlightedAsCurrent?: boolean;
|
6
6
|
children?: string | JSX.Element;
|
7
|
+
className?: string;
|
7
8
|
};
|
8
9
|
export declare function EditingCell<TType = unknown>(props: EditingCellProps<TType>): JSX.Element;
|
9
10
|
export declare type MemoedEditingCellProps<TType = unknown> = EditingCellProps<TType> & {
|
@@ -15,3 +15,8 @@ export declare type IndicatorProps = {
|
|
15
15
|
validationErrors: any;
|
16
16
|
};
|
17
17
|
export declare const Indicator: ({ reason, columnName, mountNode, validationErrors }: IndicatorProps) => React.ReactPortal;
|
18
|
+
/**
|
19
|
+
* Generates class names needed to highlight row cells, used when row has a move indicator
|
20
|
+
*/
|
21
|
+
export declare function getIndicatorCellClassName(columnIndex: number, lastColumnIndex: number): string;
|
22
|
+
export declare function isIndicatorVisible(rowIndex: any, rowActiveIndex: any, rowMoveReason: any): any;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import React__default from 'react';
|
2
|
-
import { useRowContext
|
2
|
+
import { useRowContext } from '../../rows/RowContext.js';
|
3
3
|
import { DisplayCell } from './DisplayCell.js';
|
4
|
+
import { isIndicatorVisible, getIndicatorCellClassName } from './Indicator.js';
|
4
5
|
import { isCellHighlighted } from '../../../util/columns.js';
|
5
6
|
import { EditingCell } from './EditingCell.js';
|
6
7
|
|
@@ -16,7 +17,8 @@ function Cell(props) {
|
|
16
17
|
} = props;
|
17
18
|
const {
|
18
19
|
isHovered: isHoveredRow,
|
19
|
-
hasError
|
20
|
+
hasError,
|
21
|
+
rowIndex
|
20
22
|
} = useRowContext();
|
21
23
|
const rows = table.getRowModel().rows;
|
22
24
|
const tableMeta = table.options.meta;
|
@@ -26,15 +28,15 @@ function Cell(props) {
|
|
26
28
|
const rowActiveIndex = tableMeta.rowActive.rowActiveIndex;
|
27
29
|
const isActiveRow = rowActiveIndex !== undefined && ((_rows$rowActiveIndex = rows[rowActiveIndex]) === null || _rows$rowActiveIndex === void 0 ? void 0 : _rows$rowActiveIndex.id) === row.id;
|
28
30
|
let value = getValue();
|
31
|
+
const allVisibleColumns = table.getVisibleLeafColumns();
|
32
|
+
const lastColumnIndex = allVisibleColumns.length > 0 ? allVisibleColumns.length - 1 : 0;
|
33
|
+
const className = isIndicatorVisible(rowIndex, rowActiveIndex, tableMeta.editing.rowMoveReason) ? getIndicatorCellClassName(index, lastColumnIndex) : undefined;
|
29
34
|
// When row has changes we always need to show the editing state value, end revert it to original value only when row got saved successfully.
|
30
35
|
// Otherwise it might confuse user because it will look like display value is getting reverted everytime user leaves the row.
|
31
36
|
if (tableMeta.editing.isEditing) {
|
32
37
|
const editingValue = tableMeta.editing.getCellValue(cell);
|
33
38
|
value = editingValue !== null && editingValue !== void 0 ? editingValue : value;
|
34
39
|
}
|
35
|
-
const {
|
36
|
-
rowIndex
|
37
|
-
} = React__default.useContext(RowContext);
|
38
40
|
const memoedHighlight = React__default.useMemo(() => {
|
39
41
|
var _tableMeta$search$que;
|
40
42
|
if (!tableMeta.search.isHighlightingEnabled || !columnMeta.enableSearch) {
|
@@ -62,10 +64,13 @@ function Cell(props) {
|
|
62
64
|
if (tableMeta.editing.isEditing && columnMeta.control && (isActiveRow || isHoveredRow && !tableMeta.rowActive.isHoverStatePaused ||
|
63
65
|
// When cell has error, we renderimg it in edit mode (UX reqirement)
|
64
66
|
isColumnError)) {
|
65
|
-
return /*#__PURE__*/React__default.createElement(EditingCell, Object.assign({}, props, highlightProps
|
67
|
+
return /*#__PURE__*/React__default.createElement(EditingCell, Object.assign({}, props, highlightProps, {
|
68
|
+
className: className
|
69
|
+
}));
|
66
70
|
}
|
67
71
|
return /*#__PURE__*/React__default.createElement(DisplayCell, Object.assign({}, props, highlightProps, {
|
68
|
-
value: value
|
72
|
+
value: value,
|
73
|
+
className: className
|
69
74
|
}));
|
70
75
|
}
|
71
76
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Cell.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/cell/Cell.tsx"],"sourcesContent":["import React from 'react';\nimport { CellContext, ColumnMeta, TableMeta } from '@tanstack/react-table';\nimport { DisplayCell } from './DisplayCell';\nimport { EditingCell } from './EditingCell';\nimport {
|
1
|
+
{"version":3,"file":"Cell.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/cell/Cell.tsx"],"sourcesContent":["import React from 'react';\nimport { CellContext, ColumnMeta, TableMeta } from '@tanstack/react-table';\nimport { DisplayCell } from './DisplayCell';\nimport { EditingCell } from './EditingCell';\nimport { useRowContext } from '../../rows/RowContext';\nimport { isCellHighlighted } from '../../../util/columns';\nimport { getIndicatorCellClassName, isIndicatorVisible } from './Indicator';\n\nexport type CellProps<TType = unknown> = CellContext<TType, unknown> & {\n children?: string | JSX.Element;\n};\n\nexport function Cell<TType = unknown>(props: CellProps<TType>) {\n const { column, row, table, index, getValue, cell } = props;\n const { isHovered: isHoveredRow, hasError, rowIndex } = useRowContext();\n const rows = table.getRowModel().rows;\n const tableMeta = table.options.meta as TableMeta<unknown>;\n const columnMeta = column.columnDef.meta as ColumnMeta<TType, unknown>;\n const rowErrors = tableMeta.validation.errors ? tableMeta.validation.errors[row.id] : null;\n const isColumnError = hasError && rowErrors && !!rowErrors[column.id];\n\n const rowActiveIndex = tableMeta.rowActive.rowActiveIndex;\n const isActiveRow = rowActiveIndex !== undefined && rows[rowActiveIndex]?.id === row.id;\n let value = getValue();\n\n const allVisibleColumns = table.getVisibleLeafColumns();\n const lastColumnIndex = allVisibleColumns.length > 0 ? allVisibleColumns.length - 1 : 0;\n const className = isIndicatorVisible(rowIndex, rowActiveIndex, tableMeta.editing.rowMoveReason)\n ? getIndicatorCellClassName(index, lastColumnIndex)\n : undefined;\n\n // When row has changes we always need to show the editing state value, end revert it to original value only when row got saved successfully.\n // Otherwise it might confuse user because it will look like display value is getting reverted everytime user leaves the row.\n if (tableMeta.editing.isEditing) {\n const editingValue = tableMeta.editing.getCellValue(cell);\n value = editingValue ?? value;\n }\n\n const memoedHighlight = React.useMemo(() => {\n if (!tableMeta.search.isHighlightingEnabled || !columnMeta.enableSearch) {\n return false;\n }\n\n if (tableMeta.search.query?.length) {\n return isCellHighlighted(tableMeta.search.query, value, columnMeta.dataType);\n }\n\n return false;\n }, [value, tableMeta.search.isHighlightingEnabled, tableMeta.search.excludeUnmatchedResults, tableMeta.search.query]);\n\n const memoedHighlightCurrent = React.useMemo(() => {\n if (\n !tableMeta.search.isHighlightingEnabled ||\n !memoedHighlight ||\n tableMeta.search.currentHighlightColumnIndex === undefined\n ) {\n return false;\n }\n\n const [rowActiveIndex, currentColumnIndex] =\n tableMeta.search.highlightedColumnIndexes[tableMeta.search.currentHighlightColumnIndex];\n\n if (rowActiveIndex === rowIndex && currentColumnIndex === index) {\n return true;\n }\n\n return false;\n }, [memoedHighlight, tableMeta.search.highlightedColumnIndexes.length, tableMeta.search.currentHighlightColumnIndex]);\n\n const highlightProps = {\n highlighted: memoedHighlight,\n highlightedAsCurrent: memoedHighlightCurrent,\n };\n\n if (\n tableMeta.editing.isEditing &&\n columnMeta.control &&\n (isActiveRow ||\n (isHoveredRow && !tableMeta.rowActive.isHoverStatePaused) ||\n // When cell has error, we renderimg it in edit mode (UX reqirement)\n isColumnError)\n ) {\n return <EditingCell {...props} {...highlightProps} className={className} />;\n }\n\n return <DisplayCell {...props} {...highlightProps} value={value} className={className} />;\n}\n"],"names":["Cell","props","column","row","table","index","getValue","cell","isHovered","isHoveredRow","hasError","rowIndex","useRowContext","rows","getRowModel","tableMeta","options","meta","columnMeta","columnDef","rowErrors","validation","errors","id","isColumnError","rowActiveIndex","rowActive","isActiveRow","undefined","_rows$rowActiveIndex","value","allVisibleColumns","getVisibleLeafColumns","lastColumnIndex","length","className","isIndicatorVisible","editing","rowMoveReason","getIndicatorCellClassName","isEditing","editingValue","getCellValue","memoedHighlight","React","useMemo","search","isHighlightingEnabled","enableSearch","_tableMeta$search$que","query","isCellHighlighted","dataType","excludeUnmatchedResults","memoedHighlightCurrent","currentHighlightColumnIndex","currentColumnIndex","highlightedColumnIndexes","highlightProps","highlighted","highlightedAsCurrent","control","isHoverStatePaused","EditingCell","Displ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,KAAK,EAAE;MAC7D,OAAO,IAAI;;IAGf,OAAO,KAAK;GACf,EAAE,CAACsC,eAAe,EAAE5B,SAAS,CAAC+B,MAAM,CAACW,wBAAwB,CAACvB,MAAM,EAAEnB,SAAS,CAAC+B,MAAM,CAACS,2BAA2B,CAAC,CAAC;EAErH,MAAMG,cAAc,GAAG;IACnBC,WAAW,EAAEhB,eAAe;IAC5BiB,oBAAoB,EAAEN;GACzB;EAED,IACIvC,SAAS,CAACsB,OAAO,CAACG,SAAS,IAC3BtB,UAAU,CAAC2C,OAAO,KACjBlC,WAAW,IACPlB,YAAY,IAAI,CAACM,SAAS,CAACW,SAAS,CAACoC,kBAAmB;;EAEzDtC,aAAa,CAAC,EACpB;IACE,oBAAOoB,6BAACmB,WAAW,oBAAK9D,KAAK,EAAMyD,cAAc;MAAEvB,SAAS,EAAEA;OAAa;;EAG/E,oBAAOS,6BAACoB,WAAW,oBAAK/D,KAAK,EAAMyD,cAAc;IAAE5B,KAAK,EAAEA,KAAK;IAAEK,SAAS,EAAEA;KAAa;AAC7F;;;;"}
|
@@ -33,7 +33,7 @@ function DisplayCell(props) {
|
|
33
33
|
index,
|
34
34
|
tableRef
|
35
35
|
};
|
36
|
-
}, [row.original, props.children, value, tableMeta.columnFreezing.frozenColumnIndex]);
|
36
|
+
}, [row.original, props.children, value, tableMeta.columnFreezing.frozenColumnIndex, className]);
|
37
37
|
return /*#__PURE__*/React__default.createElement(MemoedDisplayCell, Object.assign({}, memoedProps, {
|
38
38
|
highlighted: highlighted,
|
39
39
|
highlightedAsCurrent: highlightedAsCurrent
|
package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/DisplayCell.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"DisplayCell.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/cell/DisplayCell.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { ColumnMeta, CellContext, TableMeta } from '@tanstack/react-table';\nimport { Table3ColumnAlignment } from '../../../types';\nimport { Highlight } from './Highlight';\n\nexport type DisplayCellProps<TType = unknown> = CellContext<TType, unknown> & {\n highlighted?: boolean;\n highlightedAsCurrent?: boolean;\n children?: string | JSX.Element;\n className?: string;\n value?: any;\n};\n\nexport function DisplayCell<TType = unknown>(props: DisplayCellProps<TType>) {\n const { cell, className, column, value, index, row, table, tableRef, highlighted, highlightedAsCurrent } = props;\n const columnMeta = React.useMemo(() => column.columnDef.meta as ColumnMeta<TType, unknown>, []);\n const tableMeta = table.options.meta as TableMeta<TType>;\n\n // cells are heavily memoized because performance in our table is critical\n // be careful and selective about props that you pass to the cell\n const memoedProps = React.useMemo(() => {\n return {\n align: columnMeta.align,\n children: (props.children ?? columnMeta.renderer?.(value, row.original) ?? value ?? null) as\n | JSX.Element\n | string\n | null,\n className: cn(\n className,\n typeof columnMeta.className === 'function' ? columnMeta.className(row.original) : columnMeta.className\n ),\n data: row.original,\n debug: table.options.debugAll,\n enableTruncate: columnMeta.enableTruncate,\n frozenColumnIndex: tableMeta.columnFreezing.frozenColumnIndex,\n id: cell.id,\n index,\n tableRef,\n };\n }, [row.original, props.children, value, tableMeta.columnFreezing.frozenColumnIndex]);\n\n return <MemoedDisplayCell<TType> {...memoedProps} highlighted={highlighted} highlightedAsCurrent={highlightedAsCurrent} />;\n}\n\n// Memoization\nexport type MemoedDisplayCellProps<TType = unknown> = {\n align?: Table3ColumnAlignment;\n children: JSX.Element | string | null;\n className?: string;\n data: TType;\n debug?: boolean;\n enableTruncate?: boolean;\n frozenColumnIndex?: number;\n highlighted?: boolean;\n highlightedAsCurrent?: boolean;\n id: string;\n index: number;\n tableRef: React.RefObject<HTMLDivElement>;\n};\n\nconst MemoedDisplayCell = React.memo(function MemoedDisplayCell<TType = unknown>(props: MemoedDisplayCellProps<TType>) {\n const {\n align = 'left',\n children,\n className: customClassName,\n debug,\n enableTruncate,\n frozenColumnIndex,\n highlighted,\n highlightedAsCurrent = false,\n id,\n index,\n tableRef,\n } = props;\n\n const layoutClassName = cn(\n 'py-[var(--table3-cell-padding-y)] px-[var(--table3-cell-padding-x)] focus:outline-none break-word hyphens-auto',\n customClassName\n );\n\n const className = highlighted ? undefined : layoutClassName;\n const content = enableTruncate ? <span className=\"truncate\">{children}</span> : children;\n\n if (debug) {\n console.log('cell render', id);\n }\n\n return (\n <div\n className={className}\n data-align={align}\n data-column-index={index}\n data-highlighted={highlighted}\n role=\"cell\"\n // cells must be focusable (but not included in tabbing - hence -1)\n tabIndex={-1}>\n {highlighted ? (\n <Highlight\n className={layoutClassName}\n current={highlightedAsCurrent}\n frozenColumnIndex={frozenColumnIndex}\n index={index}\n tableRef={tableRef}>\n {content}\n </Highlight>\n ) : (\n content\n )}\n </div>\n );\n}) as <TType = unknown>(props: MemoedDisplayCellProps<TType>) => JSX.Element;\n"],"names":["DisplayCell","props","cell","className","column","value","index","row","table","tableRef","highlighted","highlightedAsCurrent","columnMeta","React","useMemo","columnDef","meta","tableMeta","options","memoedProps","align","children","_ref","_ref2","_props$children","_columnMeta$renderer","renderer","call","original","cn","data","debug","debugAll","enableTruncate","frozenColumnIndex","columnFreezing","id","MemoedDisplayCell","memo","customClassName","layoutClassName","undefined","content","console","log","role","tabIndex","Highlight","current"],"mappings":";;;;SAcgBA,WAAWA,CAAkBC,KAA8B;EACvE,MAAM;IAAEC,IAAI;IAAEC,SAAS;IAAEC,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEC,GAAG;IAAEC,KAAK;IAAEC,QAAQ;IAAEC,WAAW;IAAEC;GAAsB,GAAGV,KAAK;EAChH,MAAMW,UAAU,GAAGC,cAAK,CAACC,OAAO,CAAC,MAAMV,MAAM,CAACW,SAAS,CAACC,IAAkC,EAAE,EAAE,CAAC;EAC/F,MAAMC,SAAS,GAAGT,KAAK,CAACU,OAAO,CAACF,IAAwB;;;EAIxD,MAAMG,WAAW,GAAGN,cAAK,CAACC,OAAO,CAAC;;IAC9B,OAAO;MACHM,KAAK,EAAER,UAAU,CAACQ,KAAK;MACvBC,QAAQ,GAAAC,IAAA,IAAAC,KAAA,IAAAC,eAAA,GAAGvB,KAAK,CAACoB,QAAQ,cAAAG,eAAA,cAAAA,eAAA,IAAAC,oBAAA,GAAIb,UAAU,CAACc,QAAQ,cAAAD,oBAAA,uBAAnBA,oBAAA,CAAAE,IAAA,CAAAf,UAAU,EAAYP,KAAK,EAAEE,GAAG,CAACqB,QAAQ,CAAC,cAAAL,KAAA,cAAAA,KAAA,GAAIlB,KAAK,cAAAiB,IAAA,cAAAA,IAAA,GAAI,IAG1E;MACVnB,SAAS,EAAE0B,EAAE,CACT1B,SAAS,EACT,OAAOS,UAAU,CAACT,SAAS,KAAK,UAAU,GAAGS,UAAU,CAACT,SAAS,CAACI,GAAG,CAACqB,QAAQ,CAAC,GAAGhB,UAAU,CAACT,SAAS,CACzG;MACD2B,IAAI,EAAEvB,GAAG,CAACqB,QAAQ;MAClBG,KAAK,EAAEvB,KAAK,CAACU,OAAO,CAACc,QAAQ;MAC7BC,cAAc,EAAErB,UAAU,CAACqB,cAAc;MACzCC,iBAAiB,EAAEjB,SAAS,CAACkB,cAAc,CAACD,iBAAiB;MAC7DE,EAAE,EAAElC,IAAI,CAACkC,EAAE;MACX9B,KAAK;MACLG;KACH;GACJ,EAAE,CAACF,GAAG,CAACqB,QAAQ,EAAE3B,KAAK,CAACoB,QAAQ,EAAEhB,KAAK,EAAEY,SAAS,CAACkB,cAAc,CAACD,iBAAiB,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"DisplayCell.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/cell/DisplayCell.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport { ColumnMeta, CellContext, TableMeta } from '@tanstack/react-table';\nimport { Table3ColumnAlignment } from '../../../types';\nimport { Highlight } from './Highlight';\n\nexport type DisplayCellProps<TType = unknown> = CellContext<TType, unknown> & {\n highlighted?: boolean;\n highlightedAsCurrent?: boolean;\n children?: string | JSX.Element;\n className?: string;\n value?: any;\n};\n\nexport function DisplayCell<TType = unknown>(props: DisplayCellProps<TType>) {\n const { cell, className, column, value, index, row, table, tableRef, highlighted, highlightedAsCurrent } = props;\n const columnMeta = React.useMemo(() => column.columnDef.meta as ColumnMeta<TType, unknown>, []);\n const tableMeta = table.options.meta as TableMeta<TType>;\n\n // cells are heavily memoized because performance in our table is critical\n // be careful and selective about props that you pass to the cell\n const memoedProps = React.useMemo(() => {\n return {\n align: columnMeta.align,\n children: (props.children ?? columnMeta.renderer?.(value, row.original) ?? value ?? null) as\n | JSX.Element\n | string\n | null,\n className: cn(\n className,\n typeof columnMeta.className === 'function' ? columnMeta.className(row.original) : columnMeta.className\n ),\n data: row.original,\n debug: table.options.debugAll,\n enableTruncate: columnMeta.enableTruncate,\n frozenColumnIndex: tableMeta.columnFreezing.frozenColumnIndex,\n id: cell.id,\n index,\n tableRef,\n };\n }, [row.original, props.children, value, tableMeta.columnFreezing.frozenColumnIndex, className]);\n\n return <MemoedDisplayCell<TType> {...memoedProps} highlighted={highlighted} highlightedAsCurrent={highlightedAsCurrent} />;\n}\n\n// Memoization\nexport type MemoedDisplayCellProps<TType = unknown> = {\n align?: Table3ColumnAlignment;\n children: JSX.Element | string | null;\n className?: string;\n data: TType;\n debug?: boolean;\n enableTruncate?: boolean;\n frozenColumnIndex?: number;\n highlighted?: boolean;\n highlightedAsCurrent?: boolean;\n id: string;\n index: number;\n tableRef: React.RefObject<HTMLDivElement>;\n};\n\nconst MemoedDisplayCell = React.memo(function MemoedDisplayCell<TType = unknown>(props: MemoedDisplayCellProps<TType>) {\n const {\n align = 'left',\n children,\n className: customClassName,\n debug,\n enableTruncate,\n frozenColumnIndex,\n highlighted,\n highlightedAsCurrent = false,\n id,\n index,\n tableRef,\n } = props;\n\n const layoutClassName = cn(\n 'py-[var(--table3-cell-padding-y)] px-[var(--table3-cell-padding-x)] focus:outline-none break-word hyphens-auto',\n customClassName\n );\n\n const className = highlighted ? undefined : layoutClassName;\n const content = enableTruncate ? <span className=\"truncate\">{children}</span> : children;\n\n if (debug) {\n console.log('cell render', id);\n }\n\n return (\n <div\n className={className}\n data-align={align}\n data-column-index={index}\n data-highlighted={highlighted}\n role=\"cell\"\n // cells must be focusable (but not included in tabbing - hence -1)\n tabIndex={-1}>\n {highlighted ? (\n <Highlight\n className={layoutClassName}\n current={highlightedAsCurrent}\n frozenColumnIndex={frozenColumnIndex}\n index={index}\n tableRef={tableRef}>\n {content}\n </Highlight>\n ) : (\n content\n )}\n </div>\n );\n}) as <TType = unknown>(props: MemoedDisplayCellProps<TType>) => JSX.Element;\n"],"names":["DisplayCell","props","cell","className","column","value","index","row","table","tableRef","highlighted","highlightedAsCurrent","columnMeta","React","useMemo","columnDef","meta","tableMeta","options","memoedProps","align","children","_ref","_ref2","_props$children","_columnMeta$renderer","renderer","call","original","cn","data","debug","debugAll","enableTruncate","frozenColumnIndex","columnFreezing","id","MemoedDisplayCell","memo","customClassName","layoutClassName","undefined","content","console","log","role","tabIndex","Highlight","current"],"mappings":";;;;SAcgBA,WAAWA,CAAkBC,KAA8B;EACvE,MAAM;IAAEC,IAAI;IAAEC,SAAS;IAAEC,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEC,GAAG;IAAEC,KAAK;IAAEC,QAAQ;IAAEC,WAAW;IAAEC;GAAsB,GAAGV,KAAK;EAChH,MAAMW,UAAU,GAAGC,cAAK,CAACC,OAAO,CAAC,MAAMV,MAAM,CAACW,SAAS,CAACC,IAAkC,EAAE,EAAE,CAAC;EAC/F,MAAMC,SAAS,GAAGT,KAAK,CAACU,OAAO,CAACF,IAAwB;;;EAIxD,MAAMG,WAAW,GAAGN,cAAK,CAACC,OAAO,CAAC;;IAC9B,OAAO;MACHM,KAAK,EAAER,UAAU,CAACQ,KAAK;MACvBC,QAAQ,GAAAC,IAAA,IAAAC,KAAA,IAAAC,eAAA,GAAGvB,KAAK,CAACoB,QAAQ,cAAAG,eAAA,cAAAA,eAAA,IAAAC,oBAAA,GAAIb,UAAU,CAACc,QAA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,EAChHU,eAAe,CAClB;EAED,MAAMpC,SAAS,GAAGO,WAAW,GAAG+B,SAAS,GAAGD,eAAe;EAC3D,MAAME,OAAO,GAAGT,cAAc,gBAAGpB;IAAMV,SAAS,EAAC;KAAYkB,QAAQ,CAAQ,GAAGA,QAAQ;EAExF,IAAIU,KAAK,EAAE;IACPY,OAAO,CAACC,GAAG,CAAC,aAAa,EAAER,EAAE,CAAC;;EAGlC,oBACIvB;IACIV,SAAS,EAAEA,SAAS;kBACRiB,KAAK;yBACEd,KAAK;wBACNI,WAAW;IAC7BmC,IAAI,EAAC,MAAM;;IAEXC,QAAQ,EAAE,CAAC;KACVpC,WAAW,kBACRG,6BAACkC,SAAS;IACN5C,SAAS,EAAEqC,eAAe;IAC1BQ,OAAO,EAAErC,oBAAoB;IAC7BuB,iBAAiB,EAAEA,iBAAiB;IACpC5B,KAAK,EAAEA,KAAK;IACZG,QAAQ,EAAEA;KACTiC,OAAO,CACA,IAEZA,OACH,CACC;AAEd,CAAC,CAA2E;;;;"}
|
@@ -3,9 +3,9 @@ import cn from 'classnames';
|
|
3
3
|
import { Field } from '../../../../Field/Field.js';
|
4
4
|
import { useRowContext, RowContext } from '../../rows/RowContext.js';
|
5
5
|
import { Highlight } from './Highlight.js';
|
6
|
+
import { Indicator, IndicatorReason } from './Indicator.js';
|
6
7
|
import { getCurrentRowCellElement } from '../../../util/columns.js';
|
7
8
|
import { globalFilterFn, columnFilterFn } from '../../../util/filtering.js';
|
8
|
-
import { Indicator, IndicatorReason } from './Indicator.js';
|
9
9
|
import { hasChanged, willRowMoveAfterSorting } from '../../../util/editing.js';
|
10
10
|
import { EDITING_ACTIONS_WIDTH } from '../internal/EditingActions.js';
|
11
11
|
import { EditingControl } from './EditingControl.js';
|
@@ -103,7 +103,10 @@ const MemoedEditingCell = /*#__PURE__*/React__default.memo(function MemoedEditin
|
|
103
103
|
React__default.useEffect(() => {
|
104
104
|
// To avoid reseting move reason on another row hover,
|
105
105
|
// we need to check for changes only if value got changed in the current row.
|
106
|
-
if (!isActiveRow
|
106
|
+
if (!isActiveRow) {
|
107
|
+
return;
|
108
|
+
}
|
109
|
+
if (error) {
|
107
110
|
if (tableMeta.editing.rowMoveReason) {
|
108
111
|
removeMoveReason();
|
109
112
|
}
|
@@ -113,9 +116,11 @@ const MemoedEditingCell = /*#__PURE__*/React__default.memo(function MemoedEditin
|
|
113
116
|
const moveReason = getRowMoveReason(table, rowIndex,
|
114
117
|
// cannot use row.index, as this is not kept in sync once a column is sorted.
|
115
118
|
row.original, cell, value, tableMeta.search.excludeUnmatchedResults);
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
+
if (moveReason) {
|
120
|
+
tableMeta.editing.setRowMoveReason({
|
121
|
+
[cell.column.id]: moveReason
|
122
|
+
});
|
123
|
+
}
|
119
124
|
} else {
|
120
125
|
removeMoveReason();
|
121
126
|
}
|
@@ -125,7 +130,7 @@ const MemoedEditingCell = /*#__PURE__*/React__default.memo(function MemoedEditin
|
|
125
130
|
const className = cn('py-[calc(var(--table3-cell-padding-y)_-_0.06rem)]', {
|
126
131
|
// Textarea control is positioned absolute, when column is in enableTruncate mode, so the cell need to be positioned relative
|
127
132
|
relative: controlRenderer === 'textarea' && columnMeta.enableTruncate
|
128
|
-
}, typeof columnMeta.className === 'function' ? columnMeta.className(row.original) : columnMeta.className);
|
133
|
+
}, props.className, typeof columnMeta.className === 'function' ? columnMeta.className(row.original) : columnMeta.className);
|
129
134
|
const fieldClassName = cn('!min-h-0 w-full !pb-0', {
|
130
135
|
'!pb-3': !!error
|
131
136
|
});
|
package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingCell.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"EditingCell.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/cell/EditingCell.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport _ from 'lodash';\nimport { TableMeta, CellContext, ColumnMeta, Cell as RTCell, Table as RTTable } from '@tanstack/react-table';\nimport { Indicator, IndicatorReason } from './Indicator';\nimport { columnFilterFn, globalFilterFn } from '../../../util/filtering';\nimport { Table3ColumnControlRenderer, Table3FilterValue } from '../../../types';\nimport { hasChanged, willRowMoveAfterSorting } from '../../../util/editing';\nimport { getCurrentRowCellElement } from '../../../util/columns';\nimport { EDITING_ACTIONS_WIDTH } from '../internal/EditingActions';\nimport { EditingControl } from './EditingControl';\nimport { RowContext, useRowContext } from '../../rows/RowContext';\nimport { Field } from '../../../../Field/Field';\nimport { Highlight } from './Highlight';\n\nexport type EditingCellProps<TType = unknown> = CellContext<TType, unknown> & {\n highlighted?: boolean;\n highlightedAsCurrent?: boolean;\n children?: string | JSX.Element;\n};\n\nexport function EditingCell<TType = unknown>(props: EditingCellProps<TType>) {\n const { cell, table } = props;\n const { isHovered } = useRowContext();\n // Need to explicitly pass tableMeta, because just passing the table object will not trigger editing change since table object is not mutatable.\n const tableMeta = table.options.meta as TableMeta<TType>;\n const error = tableMeta.validation.getCellError(cell);\n return <MemoedEditingCell<TType> {...props} error={error} isHovered={isHovered} tableMeta={tableMeta} />;\n}\n\n// Memoization\nexport type MemoedEditingCellProps<TType = unknown> = EditingCellProps<TType> & {\n isHovered: boolean;\n tableMeta: TableMeta<TType>;\n error?: string;\n};\n\nconst MemoedEditingCell = React.memo(function MemoedEditingCell<TType = unknown>(props: MemoedEditingCellProps<TType>) {\n const { cell, column, index, getValue, table, tableRef, row, tableMeta, error, highlighted, highlightedAsCurrent } = props;\n const { rowIndex } = React.useContext(RowContext);\n\n const columnMeta = column.columnDef.meta as ColumnMeta<TType, unknown>;\n\n const cellRef = React.useRef<HTMLDivElement>(null);\n const controlRef = React.useRef<HTMLElement>(null);\n\n const handleChange = (value: unknown) => tableMeta.editing.setCellValue(cell, value);\n const value = tableMeta.editing.getCellValue(cell) ?? getValue();\n\n const handleFocus = event => {\n // Check if cell is hidden behind pinned columns or edititng actions, and scroll to it.\n const frozenColumnIndex = tableMeta.columnFreezing.frozenColumnIndex;\n const tableElement = tableRef.current;\n\n if (tableElement && frozenColumnIndex !== undefined && index > frozenColumnIndex) {\n const lastFrozenColumnElement = getCurrentRowCellElement(frozenColumnIndex, tableElement);\n const cellRect = cellRef.current?.getBoundingClientRect();\n const lastFrozenRect = lastFrozenColumnElement?.getBoundingClientRect();\n const tableRect = tableElement.getBoundingClientRect();\n\n // Check for pinned columns overlap\n if (cellRect && lastFrozenRect && cellRect.left < lastFrozenRect.left + lastFrozenRect.width) {\n const pinnedColumnsWidth = lastFrozenRect.left + lastFrozenRect.width;\n tableElement.scrollTo(cellRect.left - pinnedColumnsWidth, tableElement.scrollTop);\n // Check for editing actions overlap\n } else if (cellRect && tableRect && cellRect.right > tableRect.right - EDITING_ACTIONS_WIDTH) {\n const spaceBetweenCellAndEditingActions = 10;\n tableElement.scrollTo(\n // Need to take into account if table has been already scrolled.\n tableElement.scrollLeft + EDITING_ACTIONS_WIDTH + spaceBetweenCellAndEditingActions,\n tableElement.scrollTop\n );\n }\n }\n\n if (event.target?.select) {\n requestAnimationFrame(() => {\n event.target.select();\n });\n }\n };\n\n const handleBlur = () => {\n tableMeta.editing.setDetailModeEditing(false);\n if (tableMeta.editing.changes?.[cell.row.id]) {\n tableMeta.validation.validate(cell.row.id, tableMeta.editing.changes[cell.row.id] as TType, cell.column.id);\n }\n };\n\n // row move indicator\n const moveReason = tableMeta.editing.rowMoveReason?.[cell.column.id] || null;\n const rows = table.getRowModel().rows;\n const isActiveRow =\n tableMeta.rowActive.rowActiveIndex !== undefined && rows[tableMeta.rowActive.rowActiveIndex]?.id === row.id;\n const mountNode = React.useMemo(() => {\n if (moveReason !== null && isActiveRow && !error) {\n return cellRef.current?.parentElement?.firstChild as Element | null;\n }\n return null;\n }, [moveReason, isActiveRow, error, cellRef]);\n\n const removeMoveReason = () => {\n tableMeta.editing.removeRowMoveReason();\n };\n\n React.useEffect(() => {\n // To avoid reseting move reason on another row hover,\n // we need to check for changes only if value got changed in the current row.\n if (!isActiveRow || error) {\n if (tableMeta.editing.rowMoveReason) {\n removeMoveReason();\n }\n return;\n }\n\n if (hasChanged(getValue(), value)) {\n const moveReason = getRowMoveReason(\n table,\n rowIndex, // cannot use row.index, as this is not kept in sync once a column is sorted.\n row.original,\n cell,\n value,\n tableMeta.search.excludeUnmatchedResults\n );\n tableMeta.editing.setRowMoveReason({ [cell.column.id]: moveReason });\n } else {\n removeMoveReason();\n }\n return removeMoveReason;\n }, [value, tableMeta.rowActive.rowActiveIndex, tableMeta.search.excludeUnmatchedResults, error]);\n\n const controlRenderer = column.columnDef.meta?.control as Table3ColumnControlRenderer;\n\n const className = cn(\n 'py-[calc(var(--table3-cell-padding-y)_-_0.06rem)]',\n {\n // Textarea control is positioned absolute, when column is in enableTruncate mode, so the cell need to be positioned relative\n relative: controlRenderer === 'textarea' && columnMeta.enableTruncate,\n },\n typeof columnMeta.className === 'function' ? columnMeta.className(row.original) : columnMeta.className\n );\n\n const fieldClassName = cn('!min-h-0 w-full !pb-0', {\n '!pb-3': !!error,\n });\n\n const content = (\n <Field message={error} invalid={!!error} className={fieldClassName}>\n <EditingControl\n align={columnMeta.align}\n column={cell.column}\n data={cell.row.original}\n initialValue={getValue()}\n onBlur={handleBlur}\n onFocus={handleFocus}\n onChange={handleChange}\n ref={controlRef}\n table={table}\n tableRef={tableRef}\n value={value}\n cell={cell}\n error={error}\n tabIndex={isActiveRow ? 0 : -1}\n isActiveRow={isActiveRow}\n />\n </Field>\n );\n\n return (\n <>\n {moveReason !== null && mountNode && !error ? (\n <Indicator\n reason={moveReason}\n columnName={String(cell.column.columnDef.header)}\n mountNode={mountNode}\n validationErrors={[]}\n />\n ) : null}\n <div\n className={!highlighted ? className : undefined}\n data-align={columnMeta.align}\n data-column-index={index}\n role=\"cell\"\n data-editable\n ref={cellRef}\n data-invalid={!!error}\n data-highlighted={highlighted}>\n {highlighted ? (\n <Highlight\n current={highlightedAsCurrent}\n className={className}\n frozenColumnIndex={tableMeta.columnFreezing.frozenColumnIndex}\n index={index}\n tableRef={tableRef}>\n {content}\n </Highlight>\n ) : (\n content\n )}\n </div>\n </>\n );\n}) as <TType = unknown>(props: MemoedEditingCellProps<TType>) => JSX.Element;\n\nfunction getRowMoveReason<TType>(\n table: RTTable<any>,\n rowIndex: number,\n rowValues: TType,\n cell: RTCell<any, unknown>,\n newValue: any,\n excludeUnmatchedResults: boolean\n) {\n let rowMoveReason: IndicatorReason | null = null;\n const { globalFilter } = table.getState();\n\n const isFilteredByGlobalFilter = excludeUnmatchedResults\n ? Object.values<unknown>({ ...rowValues, [cell.id]: newValue }).some(() => {\n // Global filter can be undefined when there is no text being searched so we pass an empty string to\n // globalFilterFn as query in that case.\n return globalFilterFn(String(newValue), globalFilter ? String(globalFilter) : '');\n })\n : true;\n\n if (!isFilteredByGlobalFilter) {\n rowMoveReason = IndicatorReason.SEARCH;\n } else if (cell.column.getIsFiltered() && !columnFilterFn(newValue, cell.column.getFilterValue() as Table3FilterValue)) {\n rowMoveReason = IndicatorReason.FILTER;\n } else if (\n !rowMoveReason &&\n cell.column.getIsSorted() &&\n willRowMoveAfterSorting(\n newValue,\n cell,\n rowIndex,\n table.getRowModel().rows,\n !!table.getState().sorting.find(s => s.id === cell.column.id)?.desc\n )\n ) {\n rowMoveReason = IndicatorReason.SORTING;\n }\n\n return rowMoveReason;\n}\n"],"names":["EditingCell","props","cell","table","isHovered","useRowContext","tableMeta","options","meta","error","validation","getCellError","React","MemoedEditingCell","memo","column","index","getValue","tableRef","row","highlighted","highlightedAsCurrent","rowIndex","useContext","RowContext","columnMeta","columnDef","cellRef","useRef","controlRef","handleChange","value","editing","setCellValue","_tableMeta$editing$ge","getCellValue","handleFocus","event","frozenColumnIndex","columnFreezing","tableElement","current","undefined","_cellRef$current","lastFrozenColumnElement","getCurrentRowCellElement","cellRect","getBoundingClientRect","lastFrozenRect","tableRect","left","width","pinnedColumnsWidth","scrollTo","scrollTop","right","EDITING_ACTIONS_WIDTH","spaceBetweenCellAndEditingActions","scrollLeft","_event$target","target","select","requestAnimationFrame","handleBlur","setDetailModeEditing","_tableMeta$editing$ch","changes","id","validate","moveReason","_tableMeta$editing$ro","rowMoveReason","rows","getRowModel","isActiveRow","rowActive","rowActiveIndex","_rows$tableMeta$rowAc","mountNode","useMemo","_cellRef$current2","_cellRef$current2$par","parentElement","firstChild","removeMoveReason","removeRowMoveReason","useEffect","hasChanged","getRowMoveReason","original","search","excludeUnmatchedResults","setRowMoveReason","controlRenderer","_column$columnDef$met","control","className","cn","relative","enableTruncate","fieldClassName","content","Field","message","invalid","EditingControl","align","data","initialValue","onBlur","onFocus","onChange","ref","tabIndex","Indicator","reason","columnName","String","header","validationErrors","role","Highlight","rowValues","newValue","globalFilter","getState","isFilteredByGlobalFilter","Object","values","some","globalFilterFn","IndicatorReason","SEARCH","getIsFiltered","columnFilterFn","getFilterValue","FILTER","getIsSorted","willRowMoveAfterSorting","_table$getState$sorti","sorting","find","s","desc","SORTING"],"mappings":";;;;;;;;;;;;SAqBgBA,WAAWA,CAAkBC,KAA8B;EACvE,MAAM;IAAEC,IAAI;IAAEC;GAAO,GAAGF,KAAK;EAC7B,MAAM;IAAEG;GAAW,GAAGC,aAAa,EAAE;;EAErC,MAAMC,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAAwB;EACxD,MAAMC,KAAK,GAAGH,SAAS,CAACI,UAAU,CAACC,YAAY,CAACT,IAAI,CAAC;EACrD,oBAAOU,6BAACC,iBAAiB,oBAAYZ,KAAK;IAAEQ,KAAK,EAAEA,KAAK;IAAEL,SAAS,EAAEA,SAAS;IAAEE,SAAS,EAAEA;KAAa;AAC5G;AASA,MAAMO,iBAAiB,gBAAGD,cAAK,CAACE,IAAI,CAAC,SAASD,iBAAiBA,CAAkBZ,KAAoC;;EACjH,MAAM;IAAEC,IAAI;IAAEa,MAAM;IAAEC,KAAK;IAAEC,QAAQ;IAAEd,KAAK;IAAEe,QAAQ;IAAEC,GAAG;IAAEb,SAAS;IAAEG,KAAK;IAAEW,WAAW;IAAE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,CAACC,MAAM,CAAU;IAAE,GAAGN,SAAS;IAAE,CAACxH,IAAI,CAACiE,EAAE,GAAGwD;GAAU,CAAC,CAACM,IAAI,CAAC;;;IAG/D,OAAOC,cAAc,CAACb,MAAM,CAACM,QAAQ,CAAC,EAAEC,YAAY,GAAGP,MAAM,CAACO,YAAY,CAAC,GAAG,EAAE,CAAC;GACpF,CAAC,GACF,IAAI;EAEV,IAAI,CAACE,wBAAwB,EAAE;IAC3BvD,aAAa,GAAG4D,eAAe,CAACC,MAAM;GACzC,MAAM,IAAIlI,IAAI,CAACa,MAAM,CAACsH,aAAa,EAAE,IAAI,CAACC,cAAc,CAACX,QAAQ,EAAEzH,IAAI,CAACa,MAAM,CAACwH,cAAc,EAAuB,CAAC,EAAE;IACpHhE,aAAa,GAAG4D,eAAe,CAACK,MAAM;GACzC,MAAM,IACH,CAACjE,aAAa,IACdrE,IAAI,CAACa,MAAM,CAAC0H,WAAW,EAAE,IACzBC,uBAAuB,CACnBf,QAAQ,EACRzH,IAAI,EACJoB,QAAQ,EACRnB,KAAK,CAACsE,WAAW,EAAE,CAACD,IAAI,EACxB,CAAC,GAAAmE,qBAAA,GAACxI,KAAK,CAAC0H,QAAQ,EAAE,CAACe,OAAO,CAACC,IAAI,CAACC,CAAC,IAAIA,CAAC,CAAC3E,EAAE,KAAKjE,IAAI,CAACa,MAAM,CAACoD,EAAE,CAAC,cAAAwE,qBAAA,eAA3DA,qBAAA,CAA6DI,IAAI,EACtE,EACH;IACExE,aAAa,GAAG4D,eAAe,CAACa,OAAO;;EAG3C,OAAOzE,aAAa;AACxB;;;;"}
|
1
|
+
{"version":3,"file":"EditingCell.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/cell/EditingCell.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport _ from 'lodash';\nimport { TableMeta, CellContext, ColumnMeta, Cell as RTCell, Table as RTTable } from '@tanstack/react-table';\nimport { Indicator, IndicatorReason } from './Indicator';\nimport { columnFilterFn, globalFilterFn } from '../../../util/filtering';\nimport { Table3ColumnControlRenderer, Table3FilterValue } from '../../../types';\nimport { hasChanged, willRowMoveAfterSorting } from '../../../util/editing';\nimport { getCurrentRowCellElement } from '../../../util/columns';\nimport { EDITING_ACTIONS_WIDTH } from '../internal/EditingActions';\nimport { EditingControl } from './EditingControl';\nimport { RowContext, useRowContext } from '../../rows/RowContext';\nimport { Field } from '../../../../Field/Field';\nimport { Highlight } from './Highlight';\n\nexport type EditingCellProps<TType = unknown> = CellContext<TType, unknown> & {\n highlighted?: boolean;\n highlightedAsCurrent?: boolean;\n children?: string | JSX.Element;\n className?: string;\n};\n\nexport function EditingCell<TType = unknown>(props: EditingCellProps<TType>) {\n const { cell, table } = props;\n const { isHovered } = useRowContext();\n // Need to explicitly pass tableMeta, because just passing the table object will not trigger editing change since table object is not mutatable.\n const tableMeta = table.options.meta as TableMeta<TType>;\n const error = tableMeta.validation.getCellError(cell);\n return <MemoedEditingCell<TType> {...props} error={error} isHovered={isHovered} tableMeta={tableMeta} />;\n}\n\n// Memoization\nexport type MemoedEditingCellProps<TType = unknown> = EditingCellProps<TType> & {\n isHovered: boolean;\n tableMeta: TableMeta<TType>;\n error?: string;\n};\n\nconst MemoedEditingCell = React.memo(function MemoedEditingCell<TType = unknown>(props: MemoedEditingCellProps<TType>) {\n const { cell, column, index, getValue, table, tableRef, row, tableMeta, error, highlighted, highlightedAsCurrent } = props;\n const { rowIndex } = React.useContext(RowContext);\n\n const columnMeta = column.columnDef.meta as ColumnMeta<TType, unknown>;\n\n const cellRef = React.useRef<HTMLDivElement>(null);\n const controlRef = React.useRef<HTMLElement>(null);\n\n const handleChange = (value: unknown) => tableMeta.editing.setCellValue(cell, value);\n const value = tableMeta.editing.getCellValue(cell) ?? getValue();\n\n const handleFocus = event => {\n // Check if cell is hidden behind pinned columns or edititng actions, and scroll to it.\n const frozenColumnIndex = tableMeta.columnFreezing.frozenColumnIndex;\n const tableElement = tableRef.current;\n\n if (tableElement && frozenColumnIndex !== undefined && index > frozenColumnIndex) {\n const lastFrozenColumnElement = getCurrentRowCellElement(frozenColumnIndex, tableElement);\n const cellRect = cellRef.current?.getBoundingClientRect();\n const lastFrozenRect = lastFrozenColumnElement?.getBoundingClientRect();\n const tableRect = tableElement.getBoundingClientRect();\n\n // Check for pinned columns overlap\n if (cellRect && lastFrozenRect && cellRect.left < lastFrozenRect.left + lastFrozenRect.width) {\n const pinnedColumnsWidth = lastFrozenRect.left + lastFrozenRect.width;\n tableElement.scrollTo(cellRect.left - pinnedColumnsWidth, tableElement.scrollTop);\n // Check for editing actions overlap\n } else if (cellRect && tableRect && cellRect.right > tableRect.right - EDITING_ACTIONS_WIDTH) {\n const spaceBetweenCellAndEditingActions = 10;\n tableElement.scrollTo(\n // Need to take into account if table has been already scrolled.\n tableElement.scrollLeft + EDITING_ACTIONS_WIDTH + spaceBetweenCellAndEditingActions,\n tableElement.scrollTop\n );\n }\n }\n\n if (event.target?.select) {\n requestAnimationFrame(() => {\n event.target.select();\n });\n }\n };\n\n const handleBlur = () => {\n tableMeta.editing.setDetailModeEditing(false);\n if (tableMeta.editing.changes?.[cell.row.id]) {\n tableMeta.validation.validate(cell.row.id, tableMeta.editing.changes[cell.row.id] as TType, cell.column.id);\n }\n };\n\n // row move indicator\n const moveReason = tableMeta.editing.rowMoveReason?.[cell.column.id] || null;\n const rows = table.getRowModel().rows;\n const isActiveRow =\n tableMeta.rowActive.rowActiveIndex !== undefined && rows[tableMeta.rowActive.rowActiveIndex]?.id === row.id;\n const mountNode = React.useMemo(() => {\n if (moveReason !== null && isActiveRow && !error) {\n return cellRef.current?.parentElement?.firstChild as Element | null;\n }\n return null;\n }, [moveReason, isActiveRow, error, cellRef]);\n\n const removeMoveReason = () => {\n tableMeta.editing.removeRowMoveReason();\n };\n\n React.useEffect(() => {\n // To avoid reseting move reason on another row hover,\n // we need to check for changes only if value got changed in the current row.\n if (!isActiveRow) {\n return;\n }\n\n if (error) {\n if (tableMeta.editing.rowMoveReason) {\n removeMoveReason();\n }\n return;\n }\n\n if (hasChanged(getValue(), value)) {\n const moveReason = getRowMoveReason(\n table,\n rowIndex, // cannot use row.index, as this is not kept in sync once a column is sorted.\n row.original,\n cell,\n value,\n tableMeta.search.excludeUnmatchedResults\n );\n if (moveReason) {\n tableMeta.editing.setRowMoveReason({ [cell.column.id]: moveReason });\n }\n } else {\n removeMoveReason();\n }\n return removeMoveReason;\n }, [value, tableMeta.rowActive.rowActiveIndex, tableMeta.search.excludeUnmatchedResults, error]);\n\n const controlRenderer = column.columnDef.meta?.control as Table3ColumnControlRenderer;\n\n const className = cn(\n 'py-[calc(var(--table3-cell-padding-y)_-_0.06rem)]',\n {\n // Textarea control is positioned absolute, when column is in enableTruncate mode, so the cell need to be positioned relative\n relative: controlRenderer === 'textarea' && columnMeta.enableTruncate,\n },\n props.className,\n typeof columnMeta.className === 'function' ? columnMeta.className(row.original) : columnMeta.className\n );\n\n const fieldClassName = cn('!min-h-0 w-full !pb-0', {\n '!pb-3': !!error,\n });\n\n const content = (\n <Field message={error} invalid={!!error} className={fieldClassName}>\n <EditingControl\n align={columnMeta.align}\n column={cell.column}\n data={cell.row.original}\n initialValue={getValue()}\n onBlur={handleBlur}\n onFocus={handleFocus}\n onChange={handleChange}\n ref={controlRef}\n table={table}\n tableRef={tableRef}\n value={value}\n cell={cell}\n error={error}\n tabIndex={isActiveRow ? 0 : -1}\n isActiveRow={isActiveRow}\n />\n </Field>\n );\n\n return (\n <>\n {moveReason !== null && mountNode && !error ? (\n <Indicator\n reason={moveReason}\n columnName={String(cell.column.columnDef.header)}\n mountNode={mountNode}\n validationErrors={[]}\n />\n ) : null}\n <div\n className={!highlighted ? className : undefined}\n data-align={columnMeta.align}\n data-column-index={index}\n role=\"cell\"\n data-editable\n ref={cellRef}\n data-invalid={!!error}\n data-highlighted={highlighted}>\n {highlighted ? (\n <Highlight\n current={highlightedAsCurrent}\n className={className}\n frozenColumnIndex={tableMeta.columnFreezing.frozenColumnIndex}\n index={index}\n tableRef={tableRef}>\n {content}\n </Highlight>\n ) : (\n content\n )}\n </div>\n </>\n );\n}) as <TType = unknown>(props: MemoedEditingCellProps<TType>) => JSX.Element;\n\nfunction getRowMoveReason<TType>(\n table: RTTable<any>,\n rowIndex: number,\n rowValues: TType,\n cell: RTCell<any, unknown>,\n newValue: any,\n excludeUnmatchedResults: boolean\n) {\n let rowMoveReason: IndicatorReason | null = null;\n const { globalFilter } = table.getState();\n\n const isFilteredByGlobalFilter = excludeUnmatchedResults\n ? Object.values<unknown>({ ...rowValues, [cell.id]: newValue }).some(() => {\n // Global filter can be undefined when there is no text being searched so we pass an empty string to\n // globalFilterFn as query in that case.\n return globalFilterFn(String(newValue), globalFilter ? String(globalFilter) : '');\n })\n : true;\n\n if (!isFilteredByGlobalFilter) {\n rowMoveReason = IndicatorReason.SEARCH;\n } else if (cell.column.getIsFiltered() && !columnFilterFn(newValue, cell.column.getFilterValue() as Table3FilterValue)) {\n rowMoveReason = IndicatorReason.FILTER;\n } else if (\n !rowMoveReason &&\n cell.column.getIsSorted() &&\n willRowMoveAfterSorting(\n newValue,\n cell,\n rowIndex,\n table.getRowModel().rows,\n !!table.getState().sorting.find(s => s.id === cell.column.id)?.desc\n )\n ) {\n rowMoveReason = IndicatorReason.SORTING;\n }\n\n return rowMoveReason;\n}\n"],"names":["EditingCell","props","cell","table","isHovered","useRowContext","tableMeta","options","meta","error","validation","getCellError","React","MemoedEditingCell","memo","column","index","getValue","tableRef","row","highlighted","highlightedAsCurrent","rowIndex","useContext","RowContext","columnMeta","columnDef","cellRef","useRef","controlRef","handleChange","value","editing","setCellValue","_tableMeta$editing$ge","getCellValue","handleFocus","event","frozenColumnIndex","columnFreezing","tableElement","current","undefined","_cellRef$current","lastFrozenColumnElement","getCurrentRowCellElement","cellRect","getBoundingClientRect","lastFrozenRect","tableRect","left","width","pinnedColumnsWidth","scrollTo","scrollTop","right","EDITING_ACTIONS_WIDTH","spaceBetweenCellAndEditingActions","scrollLeft","_event$target","target","select","requestAnimationFrame","handleBlur","setDetailModeEditing","_tableMeta$editing$ch","changes","id","validate","moveReason","_tableMeta$editing$ro","rowMoveReason","rows","getRowModel","isActiveRow","rowActive","rowActiveIndex","_rows$tableMeta$rowAc","mountNode","useMemo","_cellRef$current2","_cellRef$current2$par","parentElement","firstChild","removeMoveReason","removeRowMoveReason","useEffect","hasChanged","getRowMoveReason","original","search","excludeUnmatchedResults","setRowMoveReason","controlRenderer","_column$columnDef$met","control","className","cn","relative","enableTruncate","fieldClassName","content","Field","message","invalid","EditingControl","align","data","initialValue","onBlur","onFocus","onChange","ref","tabIndex","Indicator","reason","columnName","String","header","validationErrors","role","Highlight","rowValues","newValue","globalFilter","getState","isFilteredByGlobalFilter","Object","values","some","globalFilterFn","IndicatorReason","SEARCH","getIsFiltered","columnFilterFn","getFilterValue","FILTER","getIsSorted","willRowMoveAfterSorting","_table$getState$sorti","sorting","find","s","desc","SORTING"],"mappings":";;;;;;;;;;;;SAsBgBA,WAAWA,CAAkBC,KAA8B;EACvE,MAAM;IAAEC,IAAI;IAAEC;GAAO,GAAGF,KAAK;EAC7B,MAAM;IAAEG;GAAW,GAAGC,aAAa,EAAE;;EAErC,MAAMC,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAAwB;EACxD,MAAMC,KAAK,GAAGH,SAAS,CAACI,UAAU,CAACC,YAAY,CAACT,IAAI,CAAC;EACrD,oBAAOU,6BAACC,iBAAiB,oBAAYZ,KAAK;IAAEQ,KAAK,EAAEA,KAAK;IAAEL,SAAS,EAAEA,SAAS;IAAEE,SAAS,EAAEA;KAAa;AAC5G;AASA,MAAMO,iBAAiB,gBAAGD,cAAK,CAACE,IAAI,CAAC,SAASD,iBAAiBA,CAAkBZ,KAAoC;;EACjH,MAAM;IAAEC,IAAI;IAAEa,MAAM;IAAEC,KAAK;IAAEC,QAAQ;IAAEd,KAAK;IAAEe,QAAQ;IAAEC,GAAG;IAAEb,SAAS;IAAEG,KAAK;IAAEW,WAAW;IAAEC;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C0H,QAAQ,EAAE;EAEzC,MAAMC,wBAAwB,GAAGnC,uBAAuB,GAClDoC,MAAM,CAACC,MAAM,CAAU;IAAE,GAAGN,SAAS;IAAE,CAACxH,IAAI,CAACiE,EAAE,GAAGwD;GAAU,CAAC,CAACM,IAAI,CAAC;;;IAG/D,OAAOC,cAAc,CAACb,MAAM,CAACM,QAAQ,CAAC,EAAEC,YAAY,GAAGP,MAAM,CAACO,YAAY,CAAC,GAAG,EAAE,CAAC;GACpF,CAAC,GACF,IAAI;EAEV,IAAI,CAACE,wBAAwB,EAAE;IAC3BvD,aAAa,GAAG4D,eAAe,CAACC,MAAM;GACzC,MAAM,IAAIlI,IAAI,CAACa,MAAM,CAACsH,aAAa,EAAE,IAAI,CAACC,cAAc,CAACX,QAAQ,EAAEzH,IAAI,CAACa,MAAM,CAACwH,cAAc,EAAuB,CAAC,EAAE;IACpHhE,aAAa,GAAG4D,eAAe,CAACK,MAAM;GACzC,MAAM,IACH,CAACjE,aAAa,IACdrE,IAAI,CAACa,MAAM,CAAC0H,WAAW,EAAE,IACzBC,uBAAuB,CACnBf,QAAQ,EACRzH,IAAI,EACJoB,QAAQ,EACRnB,KAAK,CAACsE,WAAW,EAAE,CAACD,IAAI,EACxB,CAAC,GAAAmE,qBAAA,GAACxI,KAAK,CAAC0H,QAAQ,EAAE,CAACe,OAAO,CAACC,IAAI,CAACC,CAAC,IAAIA,CAAC,CAAC3E,EAAE,KAAKjE,IAAI,CAACa,MAAM,CAACoD,EAAE,CAAC,cAAAwE,qBAAA,eAA3DA,qBAAA,CAA6DI,IAAI,EACtE,EACH;IACExE,aAAa,GAAG4D,eAAe,CAACa,OAAO;;EAG3C,OAAOzE,aAAa;AACxB;;;;"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import React__default from 'react';
|
2
|
+
import cn from 'classnames';
|
2
3
|
import { Icon } from '../../../../Icon/Icon.js';
|
3
4
|
import { Tooltip } from '../../../../Tooltip/Tooltip.js';
|
4
5
|
import { useLocalization } from '../../../../Provider/Localization.js';
|
@@ -69,6 +70,19 @@ const Indicator = ({
|
|
69
70
|
className: "!h-4 !w-4 rounded-full bg-white !p-0 text-blue-500"
|
70
71
|
}), indicatorText.title)), container);
|
71
72
|
};
|
73
|
+
/**
|
74
|
+
* Generates class names needed to highlight row cells, used when row has a move indicator
|
75
|
+
*/
|
76
|
+
function getIndicatorCellClassName(columnIndex, lastColumnIndex) {
|
77
|
+
return cn('!border-blue !border-y-2 border-x-0', {
|
78
|
+
'border-l-2 rounded-l': columnIndex === 0,
|
79
|
+
'border-r-2 rounded-r': columnIndex === lastColumnIndex
|
80
|
+
});
|
81
|
+
}
|
82
|
+
function isIndicatorVisible(rowIndex, rowActiveIndex, rowMoveReason) {
|
83
|
+
const isActiveRow = rowActiveIndex === rowIndex;
|
84
|
+
return isActiveRow && rowMoveReason;
|
85
|
+
}
|
72
86
|
|
73
|
-
export { Indicator, IndicatorReason, useIndicatorText };
|
87
|
+
export { Indicator, IndicatorReason, getIndicatorCellClassName, isIndicatorVisible, useIndicatorText };
|
74
88
|
//# sourceMappingURL=Indicator.js.map
|
package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/Indicator.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Indicator.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/cell/Indicator.tsx"],"sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { Tooltip } from '../../../../Tooltip/Tooltip';\nimport { Icon } from '../../../../Icon/Icon';\n\nexport enum IndicatorReason {\n SEARCH = 'SEARCH',\n SORTING = 'SORTING',\n FILTER = 'FILTER',\n}\n\nexport const useIndicatorText = reason => {\n let title = '';\n let description = '';\n\n const { texts } = useLocalization();\n\n switch (reason) {\n case IndicatorReason.FILTER:\n title = texts.table3.editing.rowIndicator.rowWillBeHidden;\n description = texts.table3.editing.rowIndicator.rowWillMoveReasonFilter;\n break;\n case IndicatorReason.SEARCH:\n title = texts.table3.editing.rowIndicator.rowWillBeHidden;\n description = texts.table3.editing.rowIndicator.rowWillMoveReasonSearch;\n break;\n case IndicatorReason.SORTING:\n title = texts.table3.editing.rowIndicator.rowWillMove;\n description = texts.table3.editing.rowIndicator.rowWillMoveReasonSorting;\n break;\n }\n\n return { title, description };\n};\n\nexport type IndicatorProps = {\n reason: IndicatorReason;\n columnName: string;\n mountNode: Element | null;\n validationErrors: any;\n};\nexport const Indicator = ({ reason, columnName, mountNode, validationErrors }: IndicatorProps) => {\n const container = React.useMemo(() => {\n const element = document.createElement('div');\n element.className +=\n 'rounded-b-md items-center wcag-blue-500 absolute left-0 top-full ml-1 whitespace-nowrap px-1 py-0.5 text-xs font-bold shadow-sm';\n\n return element;\n }, []);\n\n const indicatorText = useIndicatorText(reason);\n\n const hasValidationErrorsInRow = !!validationErrors;\n\n React.useEffect(() => {\n // mountNode could be null when rows are filtered\n // Pinned columns has z-20 class assigned, which overlaps indicator element, need to add z-21 to overlap pinned columns.\n mountNode?.classList.add('!z-[21]', 'relative');\n mountNode?.appendChild(container);\n\n return () => {\n mountNode?.classList.remove('!z-[21]', 'relative');\n mountNode?.removeChild(container);\n };\n }, [hasValidationErrorsInRow, mountNode]);\n\n // Using react portal inside a react tree component is an unorthodox way, but in order to avoid much code refactoring\n // and being able to use Taco Tooltip component in side the visual indicator, portal is used.\n return ReactDOM.createPortal(\n <Tooltip title={indicatorText.description.replace('[COLUMN]', columnName)}>\n <span className=\"flex gap-1 hover:cursor-pointer\">\n <Icon name=\"info\" className=\"!h-4 !w-4 rounded-full bg-white !p-0 text-blue-500\" />\n {indicatorText.title}\n </span>\n </Tooltip>,\n container\n );\n};\n"],"names":["IndicatorReason","useIndicatorText","reason","title","description","texts","useLocalization","FILTER","table3","editing","rowIndicator","rowWillBeHidden","rowWillMoveReasonFilter","SEARCH","rowWillMoveReasonSearch","SORTING","rowWillMove","rowWillMoveReasonSorting","Indicator","columnName","mountNode","validationErrors","container","React","useMemo","element","document","createElement","className","indicatorText","hasValidationErrorsInRow","useEffect","classList","add","appendChild","remove","removeChild","ReactDOM","createPortal","Tooltip","replace","Icon","name"],"mappings":"
|
1
|
+
{"version":3,"file":"Indicator.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/cell/Indicator.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'classnames';\nimport ReactDOM from 'react-dom';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { Tooltip } from '../../../../Tooltip/Tooltip';\nimport { Icon } from '../../../../Icon/Icon';\n\nexport enum IndicatorReason {\n SEARCH = 'SEARCH',\n SORTING = 'SORTING',\n FILTER = 'FILTER',\n}\n\nexport const useIndicatorText = reason => {\n let title = '';\n let description = '';\n\n const { texts } = useLocalization();\n\n switch (reason) {\n case IndicatorReason.FILTER:\n title = texts.table3.editing.rowIndicator.rowWillBeHidden;\n description = texts.table3.editing.rowIndicator.rowWillMoveReasonFilter;\n break;\n case IndicatorReason.SEARCH:\n title = texts.table3.editing.rowIndicator.rowWillBeHidden;\n description = texts.table3.editing.rowIndicator.rowWillMoveReasonSearch;\n break;\n case IndicatorReason.SORTING:\n title = texts.table3.editing.rowIndicator.rowWillMove;\n description = texts.table3.editing.rowIndicator.rowWillMoveReasonSorting;\n break;\n }\n\n return { title, description };\n};\n\nexport type IndicatorProps = {\n reason: IndicatorReason;\n columnName: string;\n mountNode: Element | null;\n validationErrors: any;\n};\nexport const Indicator = ({ reason, columnName, mountNode, validationErrors }: IndicatorProps) => {\n const container = React.useMemo(() => {\n const element = document.createElement('div');\n element.className +=\n 'rounded-b-md items-center wcag-blue-500 absolute left-0 top-full ml-1 whitespace-nowrap px-1 py-0.5 text-xs font-bold shadow-sm';\n\n return element;\n }, []);\n\n const indicatorText = useIndicatorText(reason);\n\n const hasValidationErrorsInRow = !!validationErrors;\n\n React.useEffect(() => {\n // mountNode could be null when rows are filtered\n // Pinned columns has z-20 class assigned, which overlaps indicator element, need to add z-21 to overlap pinned columns.\n mountNode?.classList.add('!z-[21]', 'relative');\n mountNode?.appendChild(container);\n\n return () => {\n mountNode?.classList.remove('!z-[21]', 'relative');\n mountNode?.removeChild(container);\n };\n }, [hasValidationErrorsInRow, mountNode]);\n\n // Using react portal inside a react tree component is an unorthodox way, but in order to avoid much code refactoring\n // and being able to use Taco Tooltip component in side the visual indicator, portal is used.\n return ReactDOM.createPortal(\n <Tooltip title={indicatorText.description.replace('[COLUMN]', columnName)}>\n <span className=\"flex gap-1 hover:cursor-pointer\">\n <Icon name=\"info\" className=\"!h-4 !w-4 rounded-full bg-white !p-0 text-blue-500\" />\n {indicatorText.title}\n </span>\n </Tooltip>,\n container\n );\n};\n\n/**\n * Generates class names needed to highlight row cells, used when row has a move indicator\n */\nexport function getIndicatorCellClassName(columnIndex: number, lastColumnIndex: number) {\n return cn('!border-blue !border-y-2 border-x-0', {\n 'border-l-2 rounded-l': columnIndex === 0,\n 'border-r-2 rounded-r': columnIndex === lastColumnIndex,\n });\n}\n\nexport function isIndicatorVisible(rowIndex, rowActiveIndex, rowMoveReason) {\n const isActiveRow = rowActiveIndex === rowIndex;\n return isActiveRow && rowMoveReason;\n}\n"],"names":["IndicatorReason","useIndicatorText","reason","title","description","texts","useLocalization","FILTER","table3","editing","rowIndicator","rowWillBeHidden","rowWillMoveReasonFilter","SEARCH","rowWillMoveReasonSearch","SORTING","rowWillMove","rowWillMoveReasonSorting","Indicator","columnName","mountNode","validationErrors","container","React","useMemo","element","document","createElement","className","indicatorText","hasValidationErrorsInRow","useEffect","classList","add","appendChild","remove","removeChild","ReactDOM","createPortal","Tooltip","replace","Icon","name","getIndicatorCellClassName","columnIndex","lastColumnIndex","cn","isIndicatorVisible","rowIndex","rowActiveIndex","rowMoveReason","isActiveRow"],"mappings":";;;;;;;IAOYA;AAAZ,WAAYA,eAAe;EACvBA,oCAAiB;EACjBA,sCAAmB;EACnBA,oCAAiB;AACrB,CAAC,EAJWA,eAAe,KAAfA,eAAe;MAMdC,gBAAgB,GAAGC,MAAM;E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C,SAAS,EAAE,UAAU,CAAC;IAC/Cb,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEc,WAAW,CAACZ,SAAS,CAAC;IAEjC,OAAO;MACHF,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEY,SAAS,CAACG,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC;MAClDf,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEgB,WAAW,CAACd,SAAS,CAAC;KACpC;GACJ,EAAE,CAACQ,wBAAwB,EAAEV,SAAS,CAAC,CAAC;;;EAIzC,oBAAOiB,QAAQ,CAACC,YAAY,eACxBf,6BAACgB,OAAO;IAACpC,KAAK,EAAE0B,aAAa,CAACzB,WAAW,CAACoC,OAAO,CAAC,UAAU,EAAErB,UAAU;kBACpEI;IAAMK,SAAS,EAAC;kBACZL,6BAACkB,IAAI;IAACC,IAAI,EAAC,MAAM;IAACd,SAAS,EAAC;IAAuD,EAClFC,aAAa,CAAC1B,KAAK,CACjB,CACD,EACVmB,SAAS,CACZ;AACL;AAEA;;;SAGgBqB,yBAAyBA,CAACC,WAAmB,EAAEC,eAAuB;EAClF,OAAOC,EAAE,CAAC,qCAAqC,EAAE;IAC7C,sBAAsB,EAAEF,WAAW,KAAK,CAAC;IACzC,sBAAsB,EAAEA,WAAW,KAAKC;GAC3C,CAAC;AACN;SAEgBE,kBAAkBA,CAACC,QAAQ,EAAEC,cAAc,EAAEC,aAAa;EACtE,MAAMC,WAAW,GAAGF,cAAc,KAAKD,QAAQ;EAC/C,OAAOG,WAAW,IAAID,aAAa;AACvC;;;;"}
|
@@ -9,6 +9,7 @@ import { RowContext } from '../../rows/RowContext.js';
|
|
9
9
|
import { DisplayCell } from '../cell/DisplayCell.js';
|
10
10
|
import { Footer } from '../footer/Footer.js';
|
11
11
|
import { FONT_SIZE } from '../../toolbar/FontSize.js';
|
12
|
+
import { isIndicatorVisible, getIndicatorCellClassName } from '../cell/Indicator.js';
|
12
13
|
|
13
14
|
const COLUMN_ID = '__actions';
|
14
15
|
const MemoedCell = /*#__PURE__*/React__default.memo(function MemoedCell(props) {
|
@@ -54,7 +55,7 @@ const MemoedCell = /*#__PURE__*/React__default.memo(function MemoedCell(props) {
|
|
54
55
|
// Adjust negative margin on row actions cell to ensure that the cell aligns vertically.
|
55
56
|
'-mt-2': fontSize === FONT_SIZE.small,
|
56
57
|
'-mt-1.5': fontSize !== FONT_SIZE.small
|
57
|
-
});
|
58
|
+
}, props.className);
|
58
59
|
content = /*#__PURE__*/React__default.createElement("span", {
|
59
60
|
className: className,
|
60
61
|
ref: ref
|
@@ -89,9 +90,13 @@ function Cell(context) {
|
|
89
90
|
rowIndex
|
90
91
|
} = React__default.useContext(RowContext);
|
91
92
|
const tableMeta = context.table.options.meta;
|
93
|
+
const allVisibleColumns = context.table.getVisibleLeafColumns();
|
94
|
+
const lastColumnIndex = allVisibleColumns.length > 0 ? allVisibleColumns.length - 1 : 0;
|
95
|
+
const className = isIndicatorVisible(rowIndex, tableMeta.rowActive.rowActiveIndex, tableMeta.editing.rowMoveReason) ? getIndicatorCellClassName(context.index, lastColumnIndex) : undefined;
|
92
96
|
return /*#__PURE__*/React__default.createElement(MemoedCell, Object.assign({}, context, {
|
93
97
|
actions: tableMeta.rowActions.actionsForRow,
|
94
98
|
actionsLength: tableMeta.rowActions.actionsForRowLength,
|
99
|
+
className: className,
|
95
100
|
fontSize: tableMeta.fontSize.size,
|
96
101
|
isActiveRow: tableMeta.rowActive.rowActiveIndex === rowIndex,
|
97
102
|
isEditing: tableMeta.editing.isEditing,
|
package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Actions.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Actions.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/internal/Actions.tsx"],"sourcesContent":["import React from 'react';\nimport { CellContext, DisplayColumnDef, TableMeta } from '@tanstack/react-table';\nimport cn from 'classnames';\nimport { Header as ColumnHeader } from '../header/Header';\nimport { DisplayCell } from '../cell/DisplayCell';\nimport { Table3FontSize, Table3RowActionRenderer } from '../../../types';\nimport { RowContext } from '../../rows/RowContext';\nimport { IconButton } from '../../../../IconButton/IconButton';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { Menu } from '../../../../Menu/Menu';\nimport { Shortcut } from '../../../../Shortcut/Shortcut';\nimport { Footer } from '../footer/Footer';\nimport { FONT_SIZE } from '../../toolbar/FontSize';\n\nexport const COLUMN_ID = '__actions';\n\ntype MemoedCellProps<TType = unknown> = CellContext<TType, unknown> & {\n actions?: Table3RowActionRenderer<TType>[];\n actionsLength: number;\n fontSize: Table3FontSize;\n isActiveRow: boolean;\n isEditing: boolean;\n isResizingColumn: boolean;\n isHoverStatePaused: boolean;\n};\n\nconst MemoedCell = React.memo(function MemoedCell<TType = unknown>(props: MemoedCellProps<TType>) {\n const { actions, actionsLength, fontSize, isActiveRow, isEditing, isResizingColumn, isHoverStatePaused, row } = props;\n const { isHovered } = React.useContext(RowContext);\n const { texts } = useLocalization();\n const ref = React.useRef<HTMLSpanElement | null>(null);\n /*\n const size = table.getState().columnSizing[COLUMN_ID];\n\n // the actions column needs to set its size based on its content, not the actual column\n // so we do this here instead of in the header\n React.useLayoutEffect(() => {\n if (ref.current && !size) {\n const width = ref.current.getBoundingClientRect().width;\n\n table.setColumnSizing(sizes => ({\n ...sizes,\n [COLUMN_ID]: width,\n }));\n }\n }, [ref.current]);\n */\n\n let content;\n\n // We don't want to show actions in edit mode, since we have editing actions,\n // which is shown in edit mode instead.\n if (actions?.length && !isEditing && (isActiveRow || (isHovered && !isHoverStatePaused && !isResizingColumn))) {\n const visibleActions = actions.map(action => action(row.original)).filter(action => !!action) as JSX.Element[];\n\n const actionsOnRow =\n visibleActions.length === actionsLength ? visibleActions : visibleActions.slice(0, actionsLength - 1);\n const actionsInMenu = visibleActions.slice(visibleActions.length === actionsLength ? actionsLength : actionsLength - 1);\n\n const className = cn('-mb-2 flex justify-end pl-2 text-right', {\n // Adjust negative margin on row actions cell to ensure that the cell aligns vertically.\n '-mt-2': fontSize === FONT_SIZE.small,\n '-mt-1.5': fontSize !== FONT_SIZE.small,\n });\n\n content = (\n <span className={className} ref={ref}>\n {actionsOnRow.map((button, index) => {\n const tooltip = String(button.props.tooltip ?? button.props['aria-label'] ?? '');\n\n return React.cloneElement(button, {\n appearance: 'transparent',\n key: index,\n tabIndex: isActiveRow ? 0 : -1,\n tooltip: button.props.shortcut ? (\n <>\n {tooltip}\n <Shortcut className=\"ml-2\" keys={button.props.shortcut} />\n </>\n ) : (\n tooltip\n ),\n });\n })}\n {actionsInMenu.length ? (\n <IconButton\n appearance=\"transparent\"\n aria-label={texts.table3.columns.actions.tooltip}\n icon=\"more\"\n tabIndex={isActiveRow ? 0 : -1}\n menu={menuProps => (\n <Menu {...menuProps}>\n <Menu.Content>\n {actionsInMenu.map((action, i) => (\n <Menu.Item key={i} {...action.props} shortcut={action.props.shortcut}>\n {action.props['aria-label']}\n </Menu.Item>\n ))}\n </Menu.Content>\n </Menu>\n )}\n />\n ) : null}\n </span>\n );\n }\n\n return <DisplayCell {...props}>{content}</DisplayCell>;\n}) as <TType = unknown>(props: MemoedCellProps<TType>) => JSX.Element;\n\ntype CellProps<TType = unknown> = CellContext<TType, unknown>;\n\nfunction Cell<TType = unknown>(context: CellProps<TType>) {\n const { rowIndex } = React.useContext(RowContext);\n const tableMeta = context.table.options.meta as TableMeta<TType>;\n\n return (\n <MemoedCell<TType>\n {...context}\n actions={tableMeta.rowActions.actionsForRow}\n actionsLength={tableMeta.rowActions.actionsForRowLength}\n fontSize={tableMeta.fontSize.size}\n isActiveRow={tableMeta.rowActive.rowActiveIndex === rowIndex}\n isEditing={tableMeta.editing.isEditing}\n isResizingColumn={!!context.table.getState().columnSizingInfo.isResizingColumn}\n isHoverStatePaused={!!tableMeta.rowActive.isHoverStatePaused}\n />\n );\n}\n\nexport function createRowActionsColumn<TType = unknown>(): DisplayColumnDef<TType, unknown> {\n return {\n id: COLUMN_ID,\n header: ColumnHeader,\n cell: Cell,\n footer: Footer,\n meta: {\n align: 'right',\n className: cn(\n '!pt-[var(--table3-cell-padding-y)] print:opacity-0 [[role=\"table\"][data-editing=\"false\"]_&]:group-[[data-current=\"true\"]]/row:sticky [[role=\"table\"][data-pause-hover=\"false\"][data-editing=\"false\"]_&]:group-hover/row:sticky right-0 !pl-1 !pr-1',\n 'shadow-[-6px_0px_6px_var(--table3-row-actions-shadow)]',\n 'group-[[data-current=\"true\"][data-selected=\"false\"]]/row:text-grey-200',\n 'group-[[data-selected=\"true\"]]/row:text-blue-100',\n 'group-[[data-selected=\"false\"]:hover]/row:text-grey-100'\n ),\n enableOrdering: false,\n enableSearch: false,\n enableTruncate: false,\n header: '',\n headerClassName: 'items-center !p-0',\n },\n // options\n enableResizing: false,\n };\n}\n"],"names":["COLUMN_ID","MemoedCell","React","memo","props","actions","actionsLength","fontSize","isActiveRow","isEditing","isResizingColumn","isHoverStatePaused","row","isHovered","useContext","RowContext","texts","useLocalization","ref","useRef","content","length","visibleActions","map","action","original","filter","actionsOnRow","slice","actionsInMenu","className","cn","FONT_SIZE","small","button","index","tooltip","String","_ref","_button$props$tooltip","cloneElement","appearance","key","tabIndex","shortcut","Shortcut","keys","IconButton","table3","columns","icon","menu","menuProps","Menu","Content","i","Item","DisplayCell","Cell","context","rowIndex","tableMeta","table","options","meta","rowActions","actionsForRow","actionsForRowLength","size","rowActive","rowActiveIndex","editing","getState","columnSizingInfo","createRowActionsColumn","id","header","ColumnHeader","cell","footer","Footer","align","enableOrdering","enableSearch","enableTruncate","headerClassName","enableResizing"],"mappings":";;;;;;;;;;;;MAcaA,SAAS,GAAG;AAYzB,MAAMC,UAAU,gBAAGC,cAAK,CAACC,IAAI,CAAC,SAASF,UAAUA,CAAkBG,KAA6B;EAC5F,MAAM;IAAEC,OAAO;IAAEC,aAAa;IAAEC,QAAQ;IAAEC,WAAW;IAAEC,SAAS;IAAEC,gBAAgB;IAAEC,kBAAkB;IAAEC;GAAK,GAAGR,KAAK;EACrH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,MAAM;IAAEC;GAAU,GAAG1D,cAAK,CAACY,UAAU,CAACC,UAAU,CAAC;EACjD,MAAM8C,SAAS,GAAGF,OAAO,CAACG,KAAK,CAACC,OAAO,CAACC,IAAwB;EAEhE,oBACI9D,6BAACD,UAAU,oBACH0D,OAAO;IACXtD,OAAO,EAAEwD,SAAS,CAACI,UAAU,CAACC,aAAa;IAC3C5D,aAAa,EAAEuD,SAAS,CAACI,UAAU,CAACE,mBAAmB;IACvD5D,QAAQ,EAAEsD,SAAS,CAACtD,QAAQ,CAAC6D,IAAI;IACjC5D,WAAW,EAAEqD,SAAS,CAACQ,SAAS,CAACC,cAAc,KAAKV,QAAQ;IAC5DnD,SAAS,EAAEoD,SAAS,CAACU,OAAO,CAAC9D,SAAS;IACtCC,gBAAgB,EAAE,CAAC,CAACiD,OAAO,CAACG,KAAK,CAACU,QAAQ,EAAE,CAACC,gBAAgB,CAAC/D,gBAAgB;IAC9EC,kBAAkB,EAAE,CAAC,CAACkD,SAAS,CAACQ,SAAS,CAAC1D;KAC5C;AAEV;SAEgB+D,sBAAsBA;EAClC,OAAO;IACHC,EAAE,EAAE3E,SAAS;IACb4E,MAAM,EAAEC,MAAY;IACpBC,IAAI,EAAEpB,IAAI;IACVqB,MAAM,EAAEC,MAAM;IACdhB,IAAI,EAAE;MACFiB,KAAK,EAAE,OAAO;MACdnD,SAAS,EAAEC,EAAE,CACT,oPAAoP,EACpP,wDAAwD,EACxD,wEAAwE,EACxE,kDAAkD,EAClD,yDAAyD,CAC5D;MACDmD,cAAc,EAAE,KAAK;MACrBC,YAAY,EAAE,KAAK;MACnBC,cAAc,EAAE,KAAK;MACrBR,MAAM,EAAE,EAAE;MACVS,eAAe,EAAE;KACpB;;IAEDC,cAAc,EAAE;GACnB;AACL;;;;"}
|
1
|
+
{"version":3,"file":"Actions.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/internal/Actions.tsx"],"sourcesContent":["import React from 'react';\nimport { CellContext, DisplayColumnDef, TableMeta } from '@tanstack/react-table';\nimport cn from 'classnames';\nimport { Header as ColumnHeader } from '../header/Header';\nimport { DisplayCell } from '../cell/DisplayCell';\nimport { Table3FontSize, Table3RowActionRenderer } from '../../../types';\nimport { RowContext } from '../../rows/RowContext';\nimport { IconButton } from '../../../../IconButton/IconButton';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { Menu } from '../../../../Menu/Menu';\nimport { Shortcut } from '../../../../Shortcut/Shortcut';\nimport { Footer } from '../footer/Footer';\nimport { FONT_SIZE } from '../../toolbar/FontSize';\nimport { getIndicatorCellClassName, isIndicatorVisible } from '../cell/Indicator';\n\nexport const COLUMN_ID = '__actions';\n\ntype MemoedCellProps<TType = unknown> = CellContext<TType, unknown> & {\n actions?: Table3RowActionRenderer<TType>[];\n actionsLength: number;\n className?: string;\n fontSize: Table3FontSize;\n isActiveRow: boolean;\n isEditing: boolean;\n isResizingColumn: boolean;\n isHoverStatePaused: boolean;\n};\n\nconst MemoedCell = React.memo(function MemoedCell<TType = unknown>(props: MemoedCellProps<TType>) {\n const { actions, actionsLength, fontSize, isActiveRow, isEditing, isResizingColumn, isHoverStatePaused, row } = props;\n const { isHovered } = React.useContext(RowContext);\n const { texts } = useLocalization();\n const ref = React.useRef<HTMLSpanElement | null>(null);\n /*\n const size = table.getState().columnSizing[COLUMN_ID];\n\n // the actions column needs to set its size based on its content, not the actual column\n // so we do this here instead of in the header\n React.useLayoutEffect(() => {\n if (ref.current && !size) {\n const width = ref.current.getBoundingClientRect().width;\n\n table.setColumnSizing(sizes => ({\n ...sizes,\n [COLUMN_ID]: width,\n }));\n }\n }, [ref.current]);\n */\n\n let content;\n\n // We don't want to show actions in edit mode, since we have editing actions,\n // which is shown in edit mode instead.\n if (actions?.length && !isEditing && (isActiveRow || (isHovered && !isHoverStatePaused && !isResizingColumn))) {\n const visibleActions = actions.map(action => action(row.original)).filter(action => !!action) as JSX.Element[];\n\n const actionsOnRow =\n visibleActions.length === actionsLength ? visibleActions : visibleActions.slice(0, actionsLength - 1);\n const actionsInMenu = visibleActions.slice(visibleActions.length === actionsLength ? actionsLength : actionsLength - 1);\n\n const className = cn(\n '-mb-2 flex justify-end pl-2 text-right',\n {\n // Adjust negative margin on row actions cell to ensure that the cell aligns vertically.\n '-mt-2': fontSize === FONT_SIZE.small,\n '-mt-1.5': fontSize !== FONT_SIZE.small,\n },\n props.className\n );\n\n content = (\n <span className={className} ref={ref}>\n {actionsOnRow.map((button, index) => {\n const tooltip = String(button.props.tooltip ?? button.props['aria-label'] ?? '');\n\n return React.cloneElement(button, {\n appearance: 'transparent',\n key: index,\n tabIndex: isActiveRow ? 0 : -1,\n tooltip: button.props.shortcut ? (\n <>\n {tooltip}\n <Shortcut className=\"ml-2\" keys={button.props.shortcut} />\n </>\n ) : (\n tooltip\n ),\n });\n })}\n {actionsInMenu.length ? (\n <IconButton\n appearance=\"transparent\"\n aria-label={texts.table3.columns.actions.tooltip}\n icon=\"more\"\n tabIndex={isActiveRow ? 0 : -1}\n menu={menuProps => (\n <Menu {...menuProps}>\n <Menu.Content>\n {actionsInMenu.map((action, i) => (\n <Menu.Item key={i} {...action.props} shortcut={action.props.shortcut}>\n {action.props['aria-label']}\n </Menu.Item>\n ))}\n </Menu.Content>\n </Menu>\n )}\n />\n ) : null}\n </span>\n );\n }\n\n return <DisplayCell {...props}>{content}</DisplayCell>;\n}) as <TType = unknown>(props: MemoedCellProps<TType>) => JSX.Element;\n\ntype CellProps<TType = unknown> = CellContext<TType, unknown>;\n\nfunction Cell<TType = unknown>(context: CellProps<TType>) {\n const { rowIndex } = React.useContext(RowContext);\n const tableMeta = context.table.options.meta as TableMeta<TType>;\n const allVisibleColumns = context.table.getVisibleLeafColumns();\n const lastColumnIndex = allVisibleColumns.length > 0 ? allVisibleColumns.length - 1 : 0;\n const className = isIndicatorVisible(rowIndex, tableMeta.rowActive.rowActiveIndex, tableMeta.editing.rowMoveReason)\n ? getIndicatorCellClassName(context.index, lastColumnIndex)\n : undefined;\n\n return (\n <MemoedCell<TType>\n {...context}\n actions={tableMeta.rowActions.actionsForRow}\n actionsLength={tableMeta.rowActions.actionsForRowLength}\n className={className}\n fontSize={tableMeta.fontSize.size}\n isActiveRow={tableMeta.rowActive.rowActiveIndex === rowIndex}\n isEditing={tableMeta.editing.isEditing}\n isResizingColumn={!!context.table.getState().columnSizingInfo.isResizingColumn}\n isHoverStatePaused={!!tableMeta.rowActive.isHoverStatePaused}\n />\n );\n}\n\nexport function createRowActionsColumn<TType = unknown>(): DisplayColumnDef<TType, unknown> {\n return {\n id: COLUMN_ID,\n header: ColumnHeader,\n cell: Cell,\n footer: Footer,\n meta: {\n align: 'right',\n className: cn(\n '!pt-[var(--table3-cell-padding-y)] print:opacity-0 [[role=\"table\"][data-editing=\"false\"]_&]:group-[[data-current=\"true\"]]/row:sticky [[role=\"table\"][data-pause-hover=\"false\"][data-editing=\"false\"]_&]:group-hover/row:sticky right-0 !pl-1 !pr-1',\n 'shadow-[-6px_0px_6px_var(--table3-row-actions-shadow)]',\n 'group-[[data-current=\"true\"][data-selected=\"false\"]]/row:text-grey-200',\n 'group-[[data-selected=\"true\"]]/row:text-blue-100',\n 'group-[[data-selected=\"false\"]:hover]/row:text-grey-100'\n ),\n enableOrdering: false,\n enableSearch: false,\n enableTruncate: false,\n header: '',\n headerClassName: 'items-center !p-0',\n },\n // options\n enableResizing: false,\n };\n}\n"],"names":["COLUMN_ID","MemoedCell","React","memo","props","actions","actionsLength","fontSize","isActiveRow","isEditing","isResizingColumn","isHoverStatePaused","row","isHovered","useContext","RowContext","texts","useLocalization","ref","useRef","content","length","visibleActions","map","action","original","filter","actionsOnRow","slice","actionsInMenu","className","cn","FONT_SIZE","small","button","index","tooltip","String","_ref","_button$props$tooltip","cloneElement","appearance","key","tabIndex","shortcut","Shortcut","keys","IconButton","table3","columns","icon","menu","menuProps","Menu","Content","i","Item","DisplayCell","Cell","context","rowIndex","tableMeta","table","options","meta","allVisibleColumns","getVisibleLeafColumns","lastColumnIndex","isIndicatorVisible","rowActive","rowActiveIndex","editing","rowMoveReason","getIndicatorCellClassName","undefined","rowActions","actionsForRow","actionsForRowLength","size","getState","columnSizingInfo","createRowActionsColumn","id","header","ColumnHeader","cell","footer","Footer","align","enableOrdering","enableSearch","enableTruncate","headerClassName","enableResizing"],"mappings":";;;;;;;;;;;;;MAeaA,SAAS,GAAG;AAazB,MAAMC,UAAU,gBAAGC,cAAK,CAACC,IAAI,CAAC,SAASF,UAAUA,CAAkBG,KAA6B;EAC5F,MAAM;IAAEC,OAAO;IAAEC,aAAa;IAAEC,QAAQ;IAAEC,WAAW;IAAEC,SAAS;IAAEC,gBAAgB;IAAEC,kBAAkB;IAAEC;GAAK,GAAGR,KAAK;EACrH,MAAM;IAAES;GAAW,GAAGX,cAAK,CAACY,UAAU,CAACC,UAAU,CAAC;EAClD,MAAM;IAAEC;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,GAAG,GAAGhB,cAAK,CAACiB,MAAM,CAAyB,IAAI,CAAC;;;;;;;;;;;;;;;EAkBtD,IAAIC,OAAO;;;EAIX,IAAIf,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEgB,MAAM,IAAI,CAACZ,SAAS,KAAKD,WAAW,IAAKK,SAAS,IAAI,CAACF,kBAAkB,IAAI,CAACD,gBAAiB,CAAC,EAAE;IAC3G,MAAMY,cAAc,GAAGjB,OAAO,CAACkB,GAAG,CAACC,MAAM,IAAIA,MAAM,CAACZ,GAAG,CAACa,QAAQ,CAAC,CAAC,CAACC,MAAM,CAACF,MAAM,IAAI,CAAC,CAACA,MAAM,CAAkB;IAE9G,MAAMG,YAAY,GACdL,cAAc,CAACD,MAAM,KAAKf,aAAa,GAAGgB,cAAc,GAAGA,cAAc,CAACM,KAAK,CAAC,CAAC,EAAEtB,aAAa,GAAG,CAAC,CAAC;IACzG,MAAMuB,aAAa,GAAGP,cAAc,CAACM,KAAK,CAACN,cAAc,CAACD,MAAM,KAAKf,aAAa,GAAGA,aAAa,GAAGA,aAAa,GAAG,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WAAW,EAAEqD,SAAS,CAACQ,SAAS,CAACC,cAAc,KAAKV,QAAQ;IAC5DnD,SAAS,EAAEoD,SAAS,CAACU,OAAO,CAAC9D,SAAS;IACtCC,gBAAgB,EAAE,CAAC,CAACiD,OAAO,CAACG,KAAK,CAACiB,QAAQ,EAAE,CAACC,gBAAgB,CAACtE,gBAAgB;IAC9EC,kBAAkB,EAAE,CAAC,CAACkD,SAAS,CAACQ,SAAS,CAAC1D;KAC5C;AAEV;SAEgBsE,sBAAsBA;EAClC,OAAO;IACHC,EAAE,EAAElF,SAAS;IACbmF,MAAM,EAAEC,MAAY;IACpBC,IAAI,EAAE3B,IAAI;IACV4B,MAAM,EAAEC,MAAM;IACdvB,IAAI,EAAE;MACFwB,KAAK,EAAE,OAAO;MACd1D,SAAS,EAAEC,EAAE,CACT,oPAAoP,EACpP,wDAAwD,EACxD,wEAAwE,EACxE,kDAAkD,EAClD,yDAAyD,CAC5D;MACD0D,cAAc,EAAE,KAAK;MACrBC,YAAY,EAAE,KAAK;MACnBC,cAAc,EAAE,KAAK;MACrBR,MAAM,EAAE,EAAE;MACVS,eAAe,EAAE;KACpB;;IAEDC,cAAc,EAAE;GACnB;AACL;;;;"}
|
package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/EditingActions.js
CHANGED
@@ -14,6 +14,7 @@ import { Header } from '../header/Header.js';
|
|
14
14
|
import { RowContext } from '../../rows/RowContext.js';
|
15
15
|
import { DisplayCell } from '../cell/DisplayCell.js';
|
16
16
|
import { Footer } from '../footer/Footer.js';
|
17
|
+
import { isIndicatorVisible, getIndicatorCellClassName } from '../cell/Indicator.js';
|
17
18
|
import { getColumnIndex } from '../../../util/editing.js';
|
18
19
|
import { lastCellIndex } from '../../rows/Row.js';
|
19
20
|
import { SavingStatusValue } from '../../../hooks/features/useEditing.js';
|
@@ -23,10 +24,11 @@ const COLUMN_ID = '__editing_actions';
|
|
23
24
|
const MemoedCell = /*#__PURE__*/React__default.memo(function MemoedCell(props) {
|
24
25
|
var _column$columnDef$met;
|
25
26
|
const {
|
27
|
+
className,
|
28
|
+
editing,
|
26
29
|
hasChanges,
|
27
30
|
isActiveRow,
|
28
31
|
row,
|
29
|
-
editing,
|
30
32
|
rowIdentifier,
|
31
33
|
table
|
32
34
|
} = props;
|
@@ -120,7 +122,7 @@ const MemoedCell = /*#__PURE__*/React__default.memo(function MemoedCell(props) {
|
|
120
122
|
'-mb-2 -mt-2': isActiveRow
|
121
123
|
});
|
122
124
|
return /*#__PURE__*/React__default.createElement(DisplayCell, Object.assign({}, props, {
|
123
|
-
className: cn({
|
125
|
+
className: cn(className, {
|
124
126
|
'!sticky': !!content
|
125
127
|
})
|
126
128
|
}), content ? /*#__PURE__*/React__default.createElement("span", {
|
@@ -133,10 +135,14 @@ function Cell(props) {
|
|
133
135
|
} = React__default.useContext(RowContext);
|
134
136
|
const tableMeta = props.table.options.meta;
|
135
137
|
const changeset = tableMeta.editing.changes ? Object.keys(tableMeta.editing.changes) : [];
|
138
|
+
const allVisibleColumns = props.table.getVisibleLeafColumns();
|
139
|
+
const lastColumnIndex = allVisibleColumns.length > 0 ? allVisibleColumns.length - 1 : 0;
|
140
|
+
const className = isIndicatorVisible(rowIndex, tableMeta.rowActive.rowActiveIndex, tableMeta.editing.rowMoveReason) ? getIndicatorCellClassName(props.index, lastColumnIndex) : undefined;
|
136
141
|
return /*#__PURE__*/React__default.createElement(MemoedCell, Object.assign({}, props, {
|
142
|
+
className: className,
|
143
|
+
editing: tableMeta.editing,
|
137
144
|
hasChanges: changeset.indexOf(props.row.id) >= 0,
|
138
|
-
isActiveRow: tableMeta.rowActive.rowActiveIndex === rowIndex
|
139
|
-
editing: tableMeta.editing
|
145
|
+
isActiveRow: tableMeta.rowActive.rowActiveIndex === rowIndex
|
140
146
|
}));
|
141
147
|
}
|
142
148
|
const EDITING_ACTIONS_WIDTH = 60;
|