@economic/taco 2.4.3 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Icon/components/ChartArea.d.ts +3 -0
- package/dist/components/Icon/components/ChartBar.d.ts +3 -0
- package/dist/components/Icon/components/ChartLine.d.ts +3 -0
- package/dist/components/Icon/components/ChartPie.d.ts +3 -0
- package/dist/components/Icon/components/ChartTable.d.ts +3 -0
- package/dist/components/Icon/components/index.d.ts +1 -1
- package/dist/components/Input/Input.d.ts +1 -1
- package/dist/components/Menu/components/Item.d.ts +1 -1
- package/dist/components/Menu/components/Link.d.ts +1 -1
- package/dist/components/Navigation2/components/Link.d.ts +1 -1
- package/dist/components/Select2/components/Option.d.ts +1 -1
- package/dist/components/Select2/components/Search.d.ts +1 -1
- package/dist/components/Table3/hooks/features/useSettings.d.ts +1 -0
- package/dist/components/Table3/hooks/useTable.d.ts +1 -0
- package/dist/components/Table3/types.d.ts +1 -0
- package/dist/components/Tag/Tag.d.ts +1 -1
- package/dist/esm/index.css +5 -0
- package/dist/esm/packages/taco/src/components/Icon/components/ChartArea.js +19 -0
- package/dist/esm/packages/taco/src/components/Icon/components/ChartArea.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Icon/components/ChartBar.js +19 -0
- package/dist/esm/packages/taco/src/components/Icon/components/ChartBar.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Icon/components/ChartLine.js +19 -0
- package/dist/esm/packages/taco/src/components/Icon/components/ChartLine.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Icon/components/ChartPie.js +17 -0
- package/dist/esm/packages/taco/src/components/Icon/components/ChartPie.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Icon/components/ChartTable.js +19 -0
- package/dist/esm/packages/taco/src/components/Icon/components/ChartTable.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Icon/components/index.js +10 -0
- package/dist/esm/packages/taco/src/components/Icon/components/index.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table2/components/column/Cell.js +7 -2
- package/dist/esm/packages/taco/src/components/Table2/components/column/Cell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table2/components/row/Row.js +2 -1
- package/dist/esm/packages/taco/src/components/Table2/components/row/Row.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/Table3.js +3 -1
- package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Drag.js +2 -2
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Drag.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Selection.js +3 -3
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Selection.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/rows/Row.js +2 -1
- package/dist/esm/packages/taco/src/components/Table3/components/rows/Row.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintButton.js +2 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintButton.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintIFrame.js +3 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintIFrame.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useColumnFreezing.js +14 -5
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useColumnFreezing.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useSettings.js +10 -4
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useSettings.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useConvertChildrenToColumns.js +82 -78
- package/dist/esm/packages/taco/src/components/Table3/hooks/useConvertChildrenToColumns.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useCssGrid.js +7 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useCssGrid.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js +1 -0
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTablePreset.js +5 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTablePreset.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/types.js.map +1 -1
- package/dist/esm/packages/taco/src/hooks/useLocalStorage.js +11 -1
- package/dist/esm/packages/taco/src/hooks/useLocalStorage.js.map +1 -1
- package/dist/esm/packages/taco/src/utils/hooks/useDropTarget.js +1 -1
- package/dist/esm/packages/taco/src/utils/hooks/useDropTarget.js.map +1 -1
- package/dist/hooks/useLocalStorage.d.ts +1 -1
- package/dist/index.css +5 -0
- package/dist/taco.cjs.development.js +232 -102
- 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 +21765 -11931
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Row.js","sources":["../../../../../../../../../src/components/Table3/components/rows/Row.tsx"],"sourcesContent":["import React from 'react';\nimport { Row as RTRow, Table as RTable, TableMeta } from '@tanstack/react-table';\nimport cn from 'classnames';\nimport { RowContext, useRowContext } from './RowContext';\nimport { useDropTarget } from '../../../../utils/hooks/useDropTarget';\nimport { Table3RowClickHandler, Table3RowDropHandler } from '../../types';\nimport { useFocusManager } from '@react-aria/focus';\nimport { focusableSelector } from '../../util/editing';\n\ntype RowProps<TType = unknown> = Omit<React.HTMLAttributes<HTMLDivElement>, 'onClick' | 'onDrop'> & {\n index: number;\n isLastRow: boolean;\n measureRef: (el: HTMLElement | null) => void;\n onClick?: Table3RowClickHandler<TType>;\n onDrop?: Table3RowDropHandler<TType>;\n row: RTRow<TType>;\n table: RTable<TType>;\n tableRef: React.RefObject<HTMLDivElement>;\n};\n\nexport function Row<TType = unknown>(props: RowProps<TType>) {\n const tableMeta = props.table.options.meta as TableMeta<TType>;\n const isCurrentRow = tableMeta.currentRow.currentRowIndex === props.index;\n const isDraggingRow = tableMeta.rowDrag.dragging[props.row.id];\n // we use non-css hovered state to determine whether to render actions or not, for performance\n const [isHovered, setIsHovered] = React.useState(false);\n\n // rows are heavily memoized because performance in our table is critical\n // be careful and selective about props that you pass to the row\n const memoedProps = {\n // aria-grabbed is being deprecated but there is no current alternative api, we use it until there is\n 'aria-grabbed': isDraggingRow ? true : tableMeta.rowDrag.isEnabled ? false : undefined,\n 'data-current': isCurrentRow,\n 'data-selected': props.row.getIsSelected(),\n draggable: tableMeta.rowDrag.isEnabled,\n index: props.index,\n onClick: tableMeta.rowClick.handleClick,\n onDrop: tableMeta.rowDrop.isEnabled ? tableMeta.rowDrop.handleDrop : undefined,\n };\n\n let output = <MemoedRow<TType> {...props} {...memoedProps} />;\n\n if (tableMeta.editing.isEditing && (isCurrentRow || (isHovered && !tableMeta.hoverState.isPaused))) {\n output = (\n <EditingRow\n {...props}\n {...memoedProps}\n isLastRow={props.isLastRow}\n setCurrentRowIndex={tableMeta.currentRow.setCurrentRowIndex}\n />\n );\n }\n\n // we store the row index in context because in a virtualised table the row index and the\n // react table row index do not match when, for example, sorting is applied\n const contextValue = React.useMemo(() => ({ isHovered, setIsHovered, rowIndex: props.index }), [isHovered, props.index]);\n\n return <RowContext.Provider value={contextValue}>{output}</RowContext.Provider>;\n}\n\n// turns out we might need some kind of \"state\" for the focused column, but it doesn't need to be react state that re-renders\nlet lastIndex;\n\nfunction getColumnIndex(focusedElement: Element) {\n if (focusedElement) {\n return focusedElement.closest('[role=cell]')?.getAttribute('data-column-index');\n }\n\n return null;\n}\n\n// This code is needed to avoid multiple rows being hovered at the same time (it happens since we use non-css hovering)\nlet previouslyHoveredIndex: number | undefined;\nconst unhoverPreviousRow = (tableRef: React.RefObject<HTMLDivElement>) => {\n if (previouslyHoveredIndex !== undefined) {\n const mouseoutEvent = new MouseEvent('mouseout', { view: window, bubbles: true, cancelable: true });\n const previouslyHovered = tableRef?.current?.querySelector(`[data-row-index=\"${previouslyHoveredIndex}\"]`);\n previouslyHovered?.dispatchEvent(mouseoutEvent);\n }\n};\n\nfunction EditingRow(props) {\n const { isLastRow, setCurrentRowIndex, virtualiser, ...attributes } = props;\n const focusManager = useFocusManager();\n const focusManagerOptions = { tabbable: true };\n const tableMeta = props.table.options.meta as TableMeta<unknown>;\n\n const handleClickCapture = (event: React.FocusEvent) => {\n lastIndex = getColumnIndex(event.target);\n };\n\n const handleArrowLeftKey = event => {\n let focusedElement: Element;\n if (event.key === 'ArrowLeft' || (event.key === 'Tab' && event.shiftKey)) {\n // Need to stop propagation because \"Tab\" will be handled twice(default browser and programmatic one)\n // and will lead to looping focus. Also we still need to perform special behaviour when focus reaches the end of the row,\n // so we don't need default browser behaviour.\n event.stopPropagation();\n event.preventDefault();\n\n // \"CTRL + ArrowLeft\" or \"META + ArrowLeft\" should focus first focusable element of the row\n if (event.ctrlKey || event.metaKey) {\n event.target.blur();\n focusedElement = focusManager.focusFirst(focusManagerOptions);\n lastIndex = getColumnIndex(focusedElement);\n } else {\n // Should focus previous focusable element, if there is one\n focusedElement = focusManager.focusPrevious(focusManagerOptions);\n\n // Should move to prevoius row and select last focusable element in that row,\n // if there is no previous focusable element in current row\n if (props.index !== 0 && (!focusedElement || !event.currentTarget.contains(focusedElement))) {\n tableMeta.hoverState.pause(true);\n setCurrentRowIndex(props.index - 1);\n setTimeout(() => {\n focusedElement = focusManager.focusLast(focusManagerOptions);\n // Need to update lastIndex when row got changed and last element got selected.\n lastIndex = getColumnIndex(focusedElement);\n }, 1);\n } else {\n lastIndex = getColumnIndex(focusedElement);\n }\n }\n }\n };\n\n const handleArrowRightKey = event => {\n let focusedElement: Element;\n if (event.key === 'ArrowRight' || (event.key === 'Tab' && !event.shiftKey)) {\n // Need to stop propagation because \"Tab\" will be handled twice(default browser and programmatic one)\n // and will lead to looping focus. Also we still need to perform special behaviour when focus reaches the end of the row,\n // so we don't need default browser behaviour.\n event.stopPropagation();\n event.preventDefault();\n\n // \"CTRL + ArrowRight\" or \"META + ArrowRight\" should focus last focusable element of the row\n if (event.ctrlKey || event.metaKey) {\n event.target.blur();\n focusedElement = focusManager.focusLast(focusManagerOptions);\n lastIndex = getColumnIndex(focusedElement);\n } else {\n // Should focus next focusable element, if there is one\n focusedElement = focusManager.focusNext(focusManagerOptions);\n\n // Should move to next row and select first focusable element in that row,\n // if there is no next focusable element in current row\n if (!isLastRow && (!focusedElement || !event.currentTarget.contains(focusedElement))) {\n tableMeta.hoverState.pause(true);\n setCurrentRowIndex(props.index + 1);\n setTimeout(() => {\n focusedElement = focusManager.focusFirst(focusManagerOptions);\n // Need to update lastIndex when row got changed and first element got selected.\n\n lastIndex = getColumnIndex(focusedElement);\n }, 1);\n } else {\n lastIndex = getColumnIndex(focusedElement);\n }\n }\n }\n };\n\n React.useEffect(() => {\n // if some row stuck in hovered state, we heed to unhover it when hover state is paused\n if (tableMeta.hoverState.isPaused) {\n unhoverPreviousRow(props.tableRef);\n }\n }, [tableMeta.hoverState.isPaused]);\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (event.isDefaultPrevented() || event.isPropagationStopped() || tableMeta.editing.detailModeEditing) {\n return;\n }\n\n handleArrowLeftKey(event);\n handleArrowRightKey(event);\n };\n\n // this ensures we focus either on a field or on the same column when keyboard navigating up/down\n React.useEffect(() => {\n if (tableMeta.currentRow.currentRowIndex === props.index) {\n if (lastIndex !== undefined) {\n const lastIndexCell = props.tableRef.current?.querySelector(\n `[role=\"row\"][data-current=\"true\"] [data-column-index=\"${lastIndex}\"]`\n );\n lastIndexCell?.querySelector(focusableSelector)?.focus();\n } else {\n focusManager.focusFirst(focusManagerOptions);\n }\n }\n // Need to subscribe to current row index and check is it a current row,\n // for a situation where hovered row is the next row after current row...\n // In this case row will not be re-rendered if user switch to next row, because hovered row also renders EditingRow.\n }, [tableMeta.currentRow.currentRowIndex]);\n\n return <MemoedRow {...attributes} onClickCapture={handleClickCapture} onKeyDown={handleKeyDown} />;\n}\n\n// Memoization\n\nexport type MemoedRowProps<TType = unknown> = RowProps<TType> & {\n 'aria-grabbed'?: boolean;\n 'data-current': boolean;\n 'data-selected': boolean;\n draggable: boolean;\n index: number;\n};\n\nconst clickableElements = ['input', 'button', 'a', 'select', 'option', 'label', 'textarea'];\n\nconst MemoedRow = React.memo(function MemoedRow<TType = unknown>(props: MemoedRowProps<TType>) {\n const { index, isLastRow: _1, measureRef, onClick, onClickCapture, onDrop, row, table, tableRef, ...attributes } = props;\n const ref = React.useRef<HTMLDivElement | null>(null);\n const tableMeta = table.options.meta as TableMeta<TType>;\n const { setIsHovered } = useRowContext();\n\n // we measure the first cell (since the row has display: contents) so that the virtualiser height is correct\n React.useEffect(() => {\n const firstCell = ref.current?.querySelector('[role=cell]:first-child');\n\n if (firstCell) {\n measureRef(firstCell as HTMLElement);\n }\n }, [ref.current]);\n\n // we use capture because it also picks up clicks on e.g. select checkboxes\n const handleClickCapture = (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n if (typeof onClickCapture === 'function') {\n onClickCapture(event);\n }\n\n // do this in the next frame, otherwise it remounts the row and prevents row actions on hover from being clickable\n requestAnimationFrame(() => tableMeta.currentRow.setCurrentRowIndex(index));\n };\n\n const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {\n if (typeof onClick === 'function') {\n const clickedElement = event.target as HTMLElement;\n\n if (\n !ref.current?.contains(event.target as HTMLElement) ||\n clickableElements.includes(clickedElement.tagName.toLowerCase()) ||\n clickedElement.closest(clickableElements.map(tag => `[role=row] ${tag}`).join(','))\n ) {\n return;\n }\n\n onClick(row.original);\n }\n };\n\n const handleMouseEnter = () => {\n // When user moving mouse to fast, then some of the rows are getting stuck in hover state,\n // because mouseleave event never got triggered, to avoid this to happen we're saving the index of last hovered row,\n // so that we can unhover it when new row got hovered, and saving it in a variable outside of react to save in performance,\n // since it would be very performance heavy to use state which is bound to mouse events.\n if (previouslyHoveredIndex !== undefined) {\n if (previouslyHoveredIndex !== index) {\n unhoverPreviousRow(tableRef);\n previouslyHoveredIndex = index;\n }\n } else {\n previouslyHoveredIndex = index;\n }\n setIsHovered(true);\n };\n const handleMouseLeave = () => {\n if (previouslyHoveredIndex === index) {\n previouslyHoveredIndex = undefined;\n }\n setIsHovered(false);\n };\n\n const [, dropTargetProps] = useDropTarget(event => onDrop?.(event, row.original));\n\n const className = cn(\n 'group/row contents',\n // resizing column requires dragging, which means the mouse might (on rare occasions) move over rows and trigger hover state\n // that in turn triggers rendering of e.g. row actions, which could cause janky ui - so don't allow mouse interaction when resizing\n '[[role=\"table\"][data-resizing=\"true\"]_&]:pointer-events-none',\n {\n 'hover:cursor-pointer': typeof onClick === 'function',\n }\n );\n\n return (\n <div\n {...attributes}\n {...(onDrop ? dropTargetProps : undefined)}\n className={className}\n data-row-index={index}\n onClick={handleClick}\n onClickCapture={handleClickCapture}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n role=\"row\"\n ref={ref}\n />\n );\n}) as <TType = unknown>(props: MemoedRowProps<TType>) => JSX.Element;\n"],"names":["Row","props","tableMeta","table","options","meta","isCurrentRow","currentRow","currentRowIndex","index","isDraggingRow","rowDrag","dragging","row","id","isHovered","setIsHovered","React","useState","memoedProps","isEnabled","undefined","getIsSelected","draggable","onClick","rowClick","handleClick","onDrop","rowDrop","handleDrop","output","MemoedRow","editing","isEditing","hoverState","isPaused","EditingRow","isLastRow","setCurrentRowIndex","contextValue","useMemo","rowIndex","RowContext","Provider","value","lastIndex","getColumnIndex","focusedElement","_focusedElement$close","closest","getAttribute","previouslyHoveredIndex","unhoverPreviousRow","tableRef","_tableRef$current","mouseoutEvent","MouseEvent","view","window","bubbles","cancelable","previouslyHovered","current","querySelector","dispatchEvent","virtualiser","attributes","focusManager","useFocusManager","focusManagerOptions","tabbable","handleClickCapture","event","target","handleArrowLeftKey","key","shiftKey","stopPropagation","preventDefault","ctrlKey","metaKey","blur","focusFirst","focusPrevious","currentTarget","contains","pause","setTimeout","focusLast","handleArrowRightKey","focusNext","useEffect","handleKeyDown","isDefaultPrevented","isPropagationStopped","detailModeEditing","_props$tableRef$curre","_lastIndexCell$queryS","lastIndexCell","focusableSelector","focus","onClickCapture","onKeyDown","clickableElements","memo","_1","measureRef","ref","useRef","useRowContext","firstCell","_ref$current","requestAnimationFrame","_ref$current2","clickedElement","includes","tagName","toLowerCase","map","tag","join","original","handleMouseEnter","handleMouseLeave","dropTargetProps","useDropTarget","className","cn","onMouseEnter","onMouseLeave","role"],"mappings":";;;;;;;SAoBgBA,GAAGA,CAAkBC,KAAsB;EACvD,MAAMC,SAAS,GAAGD,KAAK,CAACE,KAAK,CAACC,OAAO,CAACC,IAAwB;EAC9D,MAAMC,YAAY,GAAGJ,SAAS,CAACK,UAAU,CAACC,eAAe,KAAKP,KAAK,CAACQ,KAAK;EACzE,MAAMC,aAAa,GAAGR,SAAS,CAACS,OAAO,CAACC,QAAQ,CAACX,KAAK,CAACY,GAAG,CAACC,EAAE,CAAC;;EAE9D,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;;;EAIvD,MAAMC,WAAW,GAAG;;IAEhB,cAAc,EAAET,aAAa,GAAG,IAAI,GAAGR,SAAS,CAACS,OAAO,CAACS,SAAS,GAAG,KAAK,GAAGC,SAAS;IACtF,cAAc,EAAEf,YAAY;IAC5B,eAAe,EAAEL,KAAK,CAACY,GAAG,CAACS,aAAa,EAAE;IAC1CC,SAAS,EAAErB,SAAS,CAACS,OAAO,CAACS,SAAS;IACtCX,KAAK,EAAER,KAAK,CAACQ,KAAK;IAClBe,OAAO,EAAEtB,SAAS,CAACuB,QAAQ,CAACC,WAAW;IACvCC,MAAM,EAAEzB,SAAS,CAAC0B,OAAO,CAACR,SAAS,GAAGlB,SAAS,CAAC0B,OAAO,CAACC,UAAU,GAAGR;GACxE;EAED,IAAIS,MAAM,gBAAGb,6BAACc,SAAS,oBAAY9B,KAAK,EAAMkB,WAAW,EAAI;EAE7D,IAAIjB,SAAS,CAAC8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AAkB;IAClCyD,YAAY,EAAEN,gBAAgB;IAC9BO,YAAY,EAAEN,gBAAgB;IAC9BO,IAAI,EAAC,KAAK;IACVvB,GAAG,EAAEA;KACP;AAEV,CAAC,CAAmE;;;;"}
|
1
|
+
{"version":3,"file":"Row.js","sources":["../../../../../../../../../src/components/Table3/components/rows/Row.tsx"],"sourcesContent":["import React from 'react';\nimport { Row as RTRow, Table as RTable, TableMeta } from '@tanstack/react-table';\nimport cn from 'classnames';\nimport { RowContext, useRowContext } from './RowContext';\nimport { useDropTarget } from '../../../../utils/hooks/useDropTarget';\nimport { Table3RowClickHandler, Table3RowDropHandler } from '../../types';\nimport { useFocusManager } from '@react-aria/focus';\nimport { focusableSelector } from '../../util/editing';\n\ntype RowProps<TType = unknown> = Omit<React.HTMLAttributes<HTMLDivElement>, 'onClick' | 'onDrop'> & {\n index: number;\n isLastRow: boolean;\n measureRef: (el: HTMLElement | null) => void;\n onClick?: Table3RowClickHandler<TType>;\n onDrop?: Table3RowDropHandler<TType>;\n row: RTRow<TType>;\n table: RTable<TType>;\n tableRef: React.RefObject<HTMLDivElement>;\n};\n\nexport function Row<TType = unknown>(props: RowProps<TType>) {\n const tableMeta = props.table.options.meta as TableMeta<TType>;\n const isCurrentRow = tableMeta.currentRow.currentRowIndex === props.index;\n const isDraggingRow = tableMeta.rowDrag.dragging[props.row.id];\n // we use non-css hovered state to determine whether to render actions or not, for performance\n const [isHovered, setIsHovered] = React.useState(false);\n\n // rows are heavily memoized because performance in our table is critical\n // be careful and selective about props that you pass to the row\n const memoedProps = {\n // aria-grabbed is being deprecated but there is no current alternative api, we use it until there is\n 'aria-grabbed': isDraggingRow ? true : tableMeta.rowDrag.isEnabled ? false : undefined,\n 'data-current': isCurrentRow,\n 'data-selected': props.row.getIsSelected(),\n draggable: tableMeta.rowDrag.isEnabled,\n index: props.index,\n onClick: tableMeta.rowClick.handleClick,\n onDrop: tableMeta.rowDrop.isEnabled ? tableMeta.rowDrop.handleDrop : undefined,\n };\n\n let output = <MemoedRow<TType> {...props} {...memoedProps} />;\n\n if (tableMeta.editing.isEditing && (isCurrentRow || (isHovered && !tableMeta.hoverState.isPaused))) {\n output = (\n <EditingRow\n {...props}\n {...memoedProps}\n isLastRow={props.isLastRow}\n setCurrentRowIndex={tableMeta.currentRow.setCurrentRowIndex}\n />\n );\n }\n\n // we store the row index in context because in a virtualised table the row index and the\n // react table row index do not match when, for example, sorting is applied\n const contextValue = React.useMemo(() => ({ isHovered, setIsHovered, rowIndex: props.index }), [isHovered, props.index]);\n\n return <RowContext.Provider value={contextValue}>{output}</RowContext.Provider>;\n}\n\n// turns out we might need some kind of \"state\" for the focused column, but it doesn't need to be react state that re-renders\nlet lastIndex;\n\nfunction getColumnIndex(focusedElement: Element) {\n if (focusedElement) {\n return focusedElement.closest('[role=cell]')?.getAttribute('data-column-index');\n }\n\n return null;\n}\n\n// This code is needed to avoid multiple rows being hovered at the same time (it happens since we use non-css hovering)\nlet previouslyHoveredIndex: number | undefined;\nconst unhoverPreviousRow = (tableRef: React.RefObject<HTMLDivElement>) => {\n if (previouslyHoveredIndex !== undefined) {\n const mouseoutEvent = new MouseEvent('mouseout', { view: window, bubbles: true, cancelable: true });\n const previouslyHovered = tableRef?.current?.querySelector(`[data-row-index=\"${previouslyHoveredIndex}\"]`);\n previouslyHovered?.dispatchEvent(mouseoutEvent);\n }\n};\n\nfunction EditingRow(props) {\n const { isLastRow, setCurrentRowIndex, virtualiser, ...attributes } = props;\n const focusManager = useFocusManager();\n const focusManagerOptions = { tabbable: true };\n const tableMeta = props.table.options.meta as TableMeta<unknown>;\n\n const handleClickCapture = (event: React.FocusEvent) => {\n lastIndex = getColumnIndex(event.target);\n };\n\n const handleArrowLeftKey = event => {\n let focusedElement: Element;\n if (event.key === 'ArrowLeft' || (event.key === 'Tab' && event.shiftKey)) {\n // Need to stop propagation because \"Tab\" will be handled twice(default browser and programmatic one)\n // and will lead to looping focus. Also we still need to perform special behaviour when focus reaches the end of the row,\n // so we don't need default browser behaviour.\n event.stopPropagation();\n event.preventDefault();\n\n // \"CTRL + ArrowLeft\" or \"META + ArrowLeft\" should focus first focusable element of the row\n if (event.ctrlKey || event.metaKey) {\n event.target.blur();\n focusedElement = focusManager.focusFirst(focusManagerOptions);\n lastIndex = getColumnIndex(focusedElement);\n } else {\n // Should focus previous focusable element, if there is one\n focusedElement = focusManager.focusPrevious(focusManagerOptions);\n\n // Should move to prevoius row and select last focusable element in that row,\n // if there is no previous focusable element in current row\n if (props.index !== 0 && (!focusedElement || !event.currentTarget.contains(focusedElement))) {\n tableMeta.hoverState.pause(true);\n setCurrentRowIndex(props.index - 1);\n setTimeout(() => {\n focusedElement = focusManager.focusLast(focusManagerOptions);\n // Need to update lastIndex when row got changed and last element got selected.\n lastIndex = getColumnIndex(focusedElement);\n }, 1);\n } else {\n lastIndex = getColumnIndex(focusedElement);\n }\n }\n }\n };\n\n const handleArrowRightKey = event => {\n let focusedElement: Element;\n if (event.key === 'ArrowRight' || (event.key === 'Tab' && !event.shiftKey)) {\n // Need to stop propagation because \"Tab\" will be handled twice(default browser and programmatic one)\n // and will lead to looping focus. Also we still need to perform special behaviour when focus reaches the end of the row,\n // so we don't need default browser behaviour.\n event.stopPropagation();\n event.preventDefault();\n\n // \"CTRL + ArrowRight\" or \"META + ArrowRight\" should focus last focusable element of the row\n if (event.ctrlKey || event.metaKey) {\n event.target.blur();\n focusedElement = focusManager.focusLast(focusManagerOptions);\n lastIndex = getColumnIndex(focusedElement);\n } else {\n // Should focus next focusable element, if there is one\n focusedElement = focusManager.focusNext(focusManagerOptions);\n\n // Should move to next row and select first focusable element in that row,\n // if there is no next focusable element in current row\n if (!isLastRow && (!focusedElement || !event.currentTarget.contains(focusedElement))) {\n tableMeta.hoverState.pause(true);\n setCurrentRowIndex(props.index + 1);\n setTimeout(() => {\n focusedElement = focusManager.focusFirst(focusManagerOptions);\n // Need to update lastIndex when row got changed and first element got selected.\n\n lastIndex = getColumnIndex(focusedElement);\n }, 1);\n } else {\n lastIndex = getColumnIndex(focusedElement);\n }\n }\n }\n };\n\n React.useEffect(() => {\n // if some row stuck in hovered state, we heed to unhover it when hover state is paused\n if (tableMeta.hoverState.isPaused) {\n unhoverPreviousRow(props.tableRef);\n }\n }, [tableMeta.hoverState.isPaused]);\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (event.isDefaultPrevented() || event.isPropagationStopped() || tableMeta.editing.detailModeEditing) {\n return;\n }\n\n handleArrowLeftKey(event);\n handleArrowRightKey(event);\n };\n\n // this ensures we focus either on a field or on the same column when keyboard navigating up/down\n React.useEffect(() => {\n if (tableMeta.currentRow.currentRowIndex === props.index) {\n if (lastIndex !== undefined) {\n const lastIndexCell = props.tableRef.current?.querySelector(\n `[role=\"row\"][data-current=\"true\"] [data-column-index=\"${lastIndex}\"]`\n );\n lastIndexCell?.querySelector(focusableSelector)?.focus();\n } else {\n focusManager.focusFirst(focusManagerOptions);\n }\n }\n // Need to subscribe to current row index and check is it a current row,\n // for a situation where hovered row is the next row after current row...\n // In this case row will not be re-rendered if user switch to next row, because hovered row also renders EditingRow.\n }, [tableMeta.currentRow.currentRowIndex]);\n\n return <MemoedRow {...attributes} onClickCapture={handleClickCapture} onKeyDown={handleKeyDown} />;\n}\n\n// Memoization\n\nexport type MemoedRowProps<TType = unknown> = RowProps<TType> & {\n 'aria-grabbed'?: boolean;\n 'data-current': boolean;\n 'data-selected': boolean;\n draggable: boolean;\n index: number;\n};\n\nconst clickableElements = ['input', 'button', 'a', 'select', 'option', 'label', 'textarea'];\n\nconst MemoedRow = React.memo(function MemoedRow<TType = unknown>(props: MemoedRowProps<TType>) {\n const { index, isLastRow: _1, measureRef, onClick, onClickCapture, onDrop, row, table, tableRef, ...attributes } = props;\n const ref = React.useRef<HTMLDivElement | null>(null);\n const tableMeta = table.options.meta as TableMeta<TType>;\n const { setIsHovered } = useRowContext();\n\n // we measure the first cell (since the row has display: contents) so that the virtualiser height is correct\n React.useEffect(() => {\n const firstCell = ref.current?.querySelector('[role=cell]:first-child');\n\n if (firstCell) {\n measureRef(firstCell as HTMLElement);\n }\n }, [ref.current]);\n\n // we use capture because it also picks up clicks on e.g. select checkboxes\n const handleClickCapture = (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n if (typeof onClickCapture === 'function') {\n onClickCapture(event);\n }\n\n // do this in the next frame, otherwise it remounts the row and prevents row actions on hover from being clickable\n requestAnimationFrame(() => tableMeta.currentRow.setCurrentRowIndex(index));\n };\n\n const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {\n if (typeof onClick === 'function') {\n const clickedElement = event.target as HTMLElement;\n\n if (\n !ref.current?.contains(event.target as HTMLElement) ||\n clickableElements.includes(clickedElement.tagName.toLowerCase()) ||\n clickedElement.closest(clickableElements.map(tag => `[role=row] ${tag}`).join(','))\n ) {\n return;\n }\n\n onClick(row.original);\n }\n };\n\n const handleMouseEnter = () => {\n // When user moving mouse to fast, then some of the rows are getting stuck in hover state,\n // because mouseleave event never got triggered, to avoid this to happen we're saving the index of last hovered row,\n // so that we can unhover it when new row got hovered, and saving it in a variable outside of react to save in performance,\n // since it would be very performance heavy to use state which is bound to mouse events.\n if (previouslyHoveredIndex !== undefined) {\n if (previouslyHoveredIndex !== index) {\n unhoverPreviousRow(tableRef);\n previouslyHoveredIndex = index;\n }\n } else {\n previouslyHoveredIndex = index;\n }\n setIsHovered(true);\n };\n const handleMouseLeave = () => {\n if (previouslyHoveredIndex === index) {\n previouslyHoveredIndex = undefined;\n }\n setIsHovered(false);\n };\n\n const [isDraggedOver, dropTargetProps] = useDropTarget(event => onDrop?.(event, row.original));\n\n const className = cn(\n 'group/row contents',\n // resizing column requires dragging, which means the mouse might (on rare occasions) move over rows and trigger hover state\n // that in turn triggers rendering of e.g. row actions, which could cause janky ui - so don't allow mouse interaction when resizing\n '[[role=\"table\"][data-resizing=\"true\"]_&]:pointer-events-none',\n {\n 'hover:cursor-pointer': typeof onClick === 'function',\n }\n );\n\n return (\n <div\n {...attributes}\n {...(onDrop ? dropTargetProps : undefined)}\n className={className}\n data-row-index={index}\n data-dragged-over={isDraggedOver}\n onClick={handleClick}\n onClickCapture={handleClickCapture}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n role=\"row\"\n ref={ref}\n />\n );\n}) as <TType = unknown>(props: MemoedRowProps<TType>) => JSX.Element;\n"],"names":["Row","props","tableMeta","table","options","meta","isCurrentRow","currentRow","currentRowIndex","index","isDraggingRow","rowDrag","dragging","row","id","isHovered","setIsHovered","React","useState","memoedProps","isEnabled","undefined","getIsSelected","draggable","onClick","rowClick","handleClick","onDrop","rowDrop","handleDrop","output","MemoedRow","editing","isEditing","hoverState","isPaused","EditingRow","isLastRow","setCurrentRowIndex","contextValue","useMemo","rowIndex","RowContext","Provider","value","lastIndex","getColumnIndex","focusedElement","_focusedElement$close","closest","getAttribute","previouslyHoveredIndex","unhoverPreviousRow","tableRef","_tableRef$current","mouseoutEvent","MouseEvent","view","window","bubbles","cancelable","previouslyHovered","current","querySelector","dispatchEvent","virtualiser","attributes","focusManager","useFocusManager","focusManagerOptions","tabbable","handleClickCapture","event","target","handleArrowLeftKey","key","shiftKey","stopPropagation","preventDefault","ctrlKey","metaKey","blur","focusFirst","focusPrevious","currentTarget","contains","pause","setTimeout","focusLast","handleArrowRightKey","focusNext","useEffect","handleKeyDown","isDefaultPrevented","isPropagationStopped","detailModeEditing","_props$tableRef$curre","_lastIndexCell$queryS","lastIndexCell","focusableSelector","focus","onClickCapture","onKeyDown","clickableElements","memo","_1","measureRef","ref","useRef","useRowContext","firstCell","_ref$current","requestAnimationFrame","_ref$current2","clickedElement","includes","tagName","toLowerCase","map","tag","join","original","handleMouseEnter","handleMouseLeave","isDraggedOver","dropTargetProps","useDropTarget","className","cn","onMouseEnter","onMouseLeave","role"],"mappings":";;;;;;;SAoBgBA,GAAGA,CAAkBC,KAAsB;EACvD,MAAMC,SAAS,GAAGD,KAAK,CAACE,KAAK,CAACC,OAAO,CAACC,IAAwB;EAC9D,MAA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AGA;;;;;IAKrB,IAAIvE,sBAAsB,KAAK9B,SAAS,EAAE;MACtC,IAAI8B,sBAAsB,KAAK1C,KAAK,EAAE;QAClC2C,kBAAkB,CAACC,QAAQ,CAAC;QAC5BF,sBAAsB,GAAG1C,KAAK;;KAErC,MAAM;MACH0C,sBAAsB,GAAG1C,KAAK;;IAElCO,YAAY,CAAC,IAAI,CAAC;GACrB;EACD,MAAM2G,gBAAgB,GAAGA;IACrB,IAAIxE,sBAAsB,KAAK1C,KAAK,EAAE;MAClC0C,sBAAsB,GAAG9B,SAAS;;IAEtCL,YAAY,CAAC,KAAK,CAAC;GACtB;EAED,MAAM,CAAC4G,aAAa,EAAEC,eAAe,CAAC,GAAGC,aAAa,CAACtD,KAAK,IAAI7C,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAG6C,KAAK,EAAE3D,GAAG,CAAC4G,QAAQ,CAAC,CAAC;EAE9F,MAAMM,SAAS,GAAGC,EAAE,CAChB,oBAAoB;;;EAGpB,8DAA8D,EAC9D;IACI,sBAAsB,EAAE,OAAOxG,OAAO,KAAK;GAC9C,CACJ;EAED,oBACIP,sDACQiD,UAAU,EACTvC,MAAM,GAAGkG,eAAe,GAAGxG,SAAS;IACzC0G,SAAS,EAAEA,SAAS;sBACJtH,KAAK;yBACFmH,aAAa;IAChCpG,OAAO,EAAEE,WAAW;IACpB2E,cAAc,EAAE9B,kBAAkB;IAClC0D,YAAY,EAAEP,gBAAgB;IAC9BQ,YAAY,EAAEP,gBAAgB;IAC9BQ,IAAI,EAAC,KAAK;IACVxB,GAAG,EAAEA;KACP;AAEV,CAAC,CAAmE;;;;"}
|
package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintButton.js
CHANGED
@@ -26,6 +26,7 @@ function PrintButton(props) {
|
|
26
26
|
const {
|
27
27
|
printWarningDialogVisibility
|
28
28
|
} = tableMeta.printing;
|
29
|
+
const printTableId = `${tableProps.id}_print`;
|
29
30
|
const defaultSettings = React__default.useMemo(() => ({
|
30
31
|
columnFreezingIndex: tableMeta.columnFreezing.frozenColumnIndex,
|
31
32
|
columnOrder: state.columnOrder,
|
@@ -42,7 +43,7 @@ function PrintButton(props) {
|
|
42
43
|
const iframeTableProps = {
|
43
44
|
...tableProps,
|
44
45
|
defaultSettings,
|
45
|
-
id:
|
46
|
+
id: printTableId
|
46
47
|
};
|
47
48
|
useGlobalKeyDown({
|
48
49
|
key: 'p',
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PrintButton.js","sources":["../../../../../../../../../../src/components/Table3/components/toolbar/PrintButton/PrintButton.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as RTable, TableMeta } from '@tanstack/react-table';\n\nimport { IconButton } from '../../../../IconButton/IconButton';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { ToastReference, useToast } from '../../../../Toast/Toaster';\nimport { PrintIFrame } from './PrintIFrame';\nimport { Table3Props } from '../../../types';\nimport { useGlobalKeyDown } from '../../../../../hooks/useGlobalKeyDown';\nimport { WarningDialog } from './WarningDialog';\n\nconst SAFE_PRINT_CELL_COUNT = 10000;\n\nexport type PrintButtonProps<TType = unknown> = React.HTMLAttributes<HTMLButtonElement> & {\n table: RTable<TType>;\n tableProps: Table3Props<TType>;\n};\n\nexport function PrintButton<TType = unknown>(props: PrintButtonProps<TType>) {\n const { table, tableProps } = props;\n const { texts } = useLocalization();\n const toast = useToast();\n\n const [isPrinting, setIsPrinting] = React.useState(false);\n const [showWarningDialog, setShowWarningDialog] = React.useState(false);\n const loadingToastRef = React.useRef<ToastReference | null>(null);\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n\n const tableMeta = table.options.meta as TableMeta<TType>;\n const state = table.getState();\n const { printWarningDialogVisibility } = tableMeta.printing;\n\n const defaultSettings = React.useMemo(\n () => ({\n columnFreezingIndex: tableMeta.columnFreezing.frozenColumnIndex,\n columnOrder: state.columnOrder,\n columnSizing: state.columnSizing,\n columnVisibility: state.columnVisibility,\n excludeUnmatchedRecordsInSearch: tableMeta.search.excludeUnmatchedResults,\n fontSize: tableMeta.fontSize.size,\n rowHeight: tableMeta.rowHeight.height,\n sorting: state.sorting,\n // we don't save these, but we must pass them to print\n columnFilters: state.columnFilters,\n globalFilter: state.globalFilter,\n }),\n [\n tableMeta.columnFreezing.frozenColumnIndex,\n state.columnOrder,\n state.columnSizing,\n state.columnVisibility,\n tableMeta.search.excludeUnmatchedResults,\n tableMeta.fontSize.size,\n tableMeta.rowHeight.height,\n state.sorting,\n state.columnFilters,\n state.globalFilter,\n ]\n );\n\n const iframeTableProps = { ...tableProps, defaultSettings, id: `${tableProps.id}_print` };\n\n useGlobalKeyDown({ key: 'p', meta: true, shift: false }, (event: KeyboardEvent) => {\n event.preventDefault();\n // Starts custom printing\n buttonRef.current?.click();\n });\n\n const handleAfterPrint = () => {\n setIsPrinting(false);\n loadingToastRef.current?.close();\n };\n\n const handleBeforePrint = () => {\n loadingToastRef.current?.close();\n };\n\n const handlePrint = async () => {\n loadingToastRef.current = toast.loading(texts.table3.print.loading as any);\n\n const getCellCount = (data: TType[]) => (data.length ? data.length * Object.keys(data[0]).length : 0);\n let hasNonSafeCellCount = false;\n\n // if loadAll is not defined, just print with what we've got\n // don't compare length to data.length because the api might be choosing not to return all for performance\n if (!tableMeta.printing.loadAll) {\n const { data } = tableProps;\n const cellCount = getCellCount(data);\n\n hasNonSafeCellCount = cellCount > SAFE_PRINT_CELL_COUNT;\n } else {\n try {\n await tableMeta.printing.loadAll(\n table.getState().sorting,\n table.getState().columnFilters,\n tableMeta.search.query\n );\n\n // After the loadAll call above, the data changes. Hence, it becomes essential to acquire the data after\n // this call rather than before it.\n const { data } = tableProps;\n const cellCount = getCellCount(data);\n\n hasNonSafeCellCount = cellCount > SAFE_PRINT_CELL_COUNT;\n } catch (error) {\n const errorMessage = `${texts.table3.print.error}: ${error}`;\n\n console.error(errorMessage);\n loadingToastRef.current?.error(errorMessage);\n\n // in case of error, we return early\n return;\n }\n }\n\n if (hasNonSafeCellCount && printWarningDialogVisibility) {\n setShowWarningDialog(true);\n } else {\n // only set printing (mount the iframe) when the data has loaded, it prevents repaint performance slow downs\n setIsPrinting(true);\n }\n };\n\n const handleWarningDialogAccept = () => {\n setIsPrinting(true);\n };\n\n const handleWarningDialogClose = () => {\n loadingToastRef.current?.close();\n setShowWarningDialog(false);\n };\n\n return (\n <>\n <IconButton\n disabled={isPrinting}\n icon=\"print\"\n onClick={handlePrint}\n aria-label={texts.table3.print.tooltip}\n tooltip={texts.table3.print.tooltip}\n ref={buttonRef}\n />\n {isPrinting && iframeTableProps.data !== null && (\n <PrintIFrame\n onAfterPrint={handleAfterPrint}\n onBeforePrint={handleBeforePrint}\n tableProps={iframeTableProps as Table3Props<TType>}\n />\n )}\n <WarningDialog\n open={showWarningDialog}\n onAccept={handleWarningDialogAccept}\n onClose={handleWarningDialogClose}\n onVisibilityChange={tableMeta.printing.setPrintWarningDialogVisibility}\n />\n </>\n );\n}\n"],"names":["SAFE_PRINT_CELL_COUNT","PrintButton","props","table","tableProps","texts","useLocalization","toast","useToast","isPrinting","setIsPrinting","React","useState","showWarningDialog","setShowWarningDialog","loadingToastRef","useRef","buttonRef","tableMeta","options","meta","state","getState","printWarningDialogVisibility","printing","defaultSettings","useMemo","columnFreezingIndex","columnFreezing","frozenColumnIndex","columnOrder","columnSizing","columnVisibility","excludeUnmatchedRecordsInSearch","search","excludeUnmatchedResults","fontSize","size","rowHeight","height","sorting","columnFilters","globalFilter","iframeTableProps","id","useGlobalKeyDown","key","shift","event","preventDefault","_buttonRef$current","current","click","handleAfterPrint","_loadingToastRef$curr","close","handleBeforePrint","_loadingToastRef$curr2","handlePrint","hasNonSafeCellCount","loading","table3","print","getCellCount","data","length","Object","keys","_temp2","loadAll","cellCount","_temp","_catch","Promise","resolve","query","then","error","_loadingToastRef$curr3","errorMessage","console","_exit","_temp3","e","reject","handleWarningDialogAccept","handleWarningDialogClose","_loadingToastRef$curr4","IconButton","disabled","icon","onClick","tooltip","ref","PrintIFrame","onAfterPrint","onBeforePrint","WarningDialog","open","onAccept","onClose","onVisibilityChange","setPrintWarningDialogVisibility"],"mappings":";;;;;;;;;AAWA,MAAMA,qBAAqB,GAAG,KAAK;SAOnBC,WAAWA,CAAkBC,KAA8B;EACvE,MAAM;IAAEC,KAAK;IAAEC;GAAY,GAAGF,KAAK;EACnC,MAAM;IAAEG;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,KAAK,GAAGC,QAAQ,EAAE;EAExB,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;EACzD,MAAM,CAACC,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGH,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;EACvE,MAAMG,eAAe,GAAGJ,cAAK,CAACK,MAAM,CAAwB,IAAI,CAAC;EACjE,MAAMC,SAAS,GAAGN,cAAK,CAACK,MAAM,CAAoB,IAAI,CAAC;EAEvD,MAAME,SAAS,GAAGf,KAAK,CAACgB,OAAO,CAACC,IAAwB;EACxD,MAAMC,KAAK,GAAGlB,KAAK,CAACmB,QAAQ,EAAE;EAC9B,MAAM;IAAEC;GAA8B,GAAGL,SAAS,CAACM,QAAQ;EAE3D,MAAMC,eAAe,GAAGd,cAAK,CAACe,OAAO,CACjC,OAAO;IACHC,mBAAmB,EAAET,SAAS,CAACU,cAAc,CAACC,iBAAiB;IAC/DC,WAAW,EAAET,KAAK,CAACS,WAAW;IAC9BC,YAAY,EAAEV,KAAK,CAACU,YAAY;IAChCC,gBAAgB,EAAEX,KAAK,CAACW,gBAAgB;IACxCC,+BAA+B,EAAEf,SAAS,CAACgB,MAAM,CAACC,uBAAuB;IACzEC,QAAQ,EAAElB,SAAS,CAACkB,QAAQ,CAACC,IAAI;IACjCC,SAAS,EAAEpB,SAAS,CAACoB,SAAS,CAACC,MAAM;IACrCC,OAAO,EAAEnB,KAAK,CAACmB,OAAO;;IAEtBC,aAAa,EAAEpB,KAAK,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UAAA,IAAAV,KAAA,IAAAA,KAAA,CAAAK,IAAA,SAAAL,KAAA,CAAAK,IAAA;;;MAAA,OAAAH,OAAA,CAAAC,OAAA,CAAAN,MAAA,IAAAA,MAAA,CAAAQ,IAAA,GAAAR,MAAA,CAAAQ,IAAA,CAAAM,MAAA,IAAAA,MAAA,CAAAd,MAAA;KASR,QAAAe,CAAA;MAAA,OAAAV,OAAA,CAAAW,MAAA,CAAAD,CAAA;;;EAED,MAAME,yBAAyB,GAAGA;IAC9B3E,aAAa,CAAC,IAAI,CAAC;GACtB;EAED,MAAM4E,wBAAwB,GAAGA;;IAC7B,CAAAC,sBAAA,GAAAxE,eAAe,CAACoC,OAAO,cAAAoC,sBAAA,uBAAvBA,sBAAA,CAAyBhC,KAAK,EAAE;IAChCzC,oBAAoB,CAAC,KAAK,CAAC;GAC9B;EAED,oBACIH,yEACIA,6BAAC6E,UAAU;IACPC,QAAQ,EAAEhF,UAAU;IACpBiF,IAAI,EAAC,OAAO;IACZC,OAAO,EAAEjC,WAAW;kBACRrD,KAAK,CAACwD,MAAM,CAACC,KAAK,CAAC8B,OAAO;IACtCA,OAAO,EAAEvF,KAAK,CAACwD,MAAM,CAACC,KAAK,CAAC8B,OAAO;IACnCC,GAAG,EAAE5E;IACP,EACDR,UAAU,IAAIkC,gBAAgB,CAACqB,IAAI,KAAK,IAAI,iBACzCrD,6BAACmF,WAAW;IACRC,YAAY,EAAE1C,gBAAgB;IAC9B2C,aAAa,EAAExC,iBAAiB;IAChCpD,UAAU,EAAEuC;IAEnB,eACDhC,6BAACsF,aAAa;IACVC,IAAI,EAAErF,iBAAiB;IACvBsF,QAAQ,EAAEd,yBAAyB;IACnCe,OAAO,EAAEd,wBAAwB;IACjCe,kBAAkB,EAAEnF,SAAS,CAACM,QAAQ,CAAC8E;IACzC,CACH;AAEX;;;;"}
|
1
|
+
{"version":3,"file":"PrintButton.js","sources":["../../../../../../../../../../src/components/Table3/components/toolbar/PrintButton/PrintButton.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as RTable, TableMeta } from '@tanstack/react-table';\n\nimport { IconButton } from '../../../../IconButton/IconButton';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { ToastReference, useToast } from '../../../../Toast/Toaster';\nimport { PrintIFrame } from './PrintIFrame';\nimport { Table3Props } from '../../../types';\nimport { useGlobalKeyDown } from '../../../../../hooks/useGlobalKeyDown';\nimport { WarningDialog } from './WarningDialog';\n\nconst SAFE_PRINT_CELL_COUNT = 10000;\n\nexport type PrintButtonProps<TType = unknown> = React.HTMLAttributes<HTMLButtonElement> & {\n table: RTable<TType>;\n tableProps: Table3Props<TType>;\n};\n\nexport function PrintButton<TType = unknown>(props: PrintButtonProps<TType>) {\n const { table, tableProps } = props;\n const { texts } = useLocalization();\n const toast = useToast();\n\n const [isPrinting, setIsPrinting] = React.useState(false);\n const [showWarningDialog, setShowWarningDialog] = React.useState(false);\n const loadingToastRef = React.useRef<ToastReference | null>(null);\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n\n const tableMeta = table.options.meta as TableMeta<TType>;\n const state = table.getState();\n const { printWarningDialogVisibility } = tableMeta.printing;\n\n const printTableId = `${tableProps.id}_print`;\n\n const defaultSettings = React.useMemo(\n () => ({\n columnFreezingIndex: tableMeta.columnFreezing.frozenColumnIndex,\n columnOrder: state.columnOrder,\n columnSizing: state.columnSizing,\n columnVisibility: state.columnVisibility,\n excludeUnmatchedRecordsInSearch: tableMeta.search.excludeUnmatchedResults,\n fontSize: tableMeta.fontSize.size,\n rowHeight: tableMeta.rowHeight.height,\n sorting: state.sorting,\n // we don't save these, but we must pass them to print\n columnFilters: state.columnFilters,\n globalFilter: state.globalFilter,\n }),\n [\n tableMeta.columnFreezing.frozenColumnIndex,\n state.columnOrder,\n state.columnSizing,\n state.columnVisibility,\n tableMeta.search.excludeUnmatchedResults,\n tableMeta.fontSize.size,\n tableMeta.rowHeight.height,\n state.sorting,\n state.columnFilters,\n state.globalFilter,\n ]\n );\n\n const iframeTableProps = { ...tableProps, defaultSettings, id: printTableId };\n\n useGlobalKeyDown({ key: 'p', meta: true, shift: false }, (event: KeyboardEvent) => {\n event.preventDefault();\n // Starts custom printing\n buttonRef.current?.click();\n });\n\n const handleAfterPrint = () => {\n setIsPrinting(false);\n loadingToastRef.current?.close();\n };\n\n const handleBeforePrint = () => {\n loadingToastRef.current?.close();\n };\n\n const handlePrint = async () => {\n loadingToastRef.current = toast.loading(texts.table3.print.loading as any);\n\n const getCellCount = (data: TType[]) => (data.length ? data.length * Object.keys(data[0]).length : 0);\n let hasNonSafeCellCount = false;\n\n // if loadAll is not defined, just print with what we've got\n // don't compare length to data.length because the api might be choosing not to return all for performance\n if (!tableMeta.printing.loadAll) {\n const { data } = tableProps;\n const cellCount = getCellCount(data);\n\n hasNonSafeCellCount = cellCount > SAFE_PRINT_CELL_COUNT;\n } else {\n try {\n await tableMeta.printing.loadAll(\n table.getState().sorting,\n table.getState().columnFilters,\n tableMeta.search.query\n );\n\n // After the loadAll call above, the data changes. Hence, it becomes essential to acquire the data after\n // this call rather than before it.\n const { data } = tableProps;\n const cellCount = getCellCount(data);\n\n hasNonSafeCellCount = cellCount > SAFE_PRINT_CELL_COUNT;\n } catch (error) {\n const errorMessage = `${texts.table3.print.error}: ${error}`;\n\n console.error(errorMessage);\n loadingToastRef.current?.error(errorMessage);\n\n // in case of error, we return early\n return;\n }\n }\n\n if (hasNonSafeCellCount && printWarningDialogVisibility) {\n setShowWarningDialog(true);\n } else {\n // only set printing (mount the iframe) when the data has loaded, it prevents repaint performance slow downs\n setIsPrinting(true);\n }\n };\n\n const handleWarningDialogAccept = () => {\n setIsPrinting(true);\n };\n\n const handleWarningDialogClose = () => {\n loadingToastRef.current?.close();\n setShowWarningDialog(false);\n };\n\n return (\n <>\n <IconButton\n disabled={isPrinting}\n icon=\"print\"\n onClick={handlePrint}\n aria-label={texts.table3.print.tooltip}\n tooltip={texts.table3.print.tooltip}\n ref={buttonRef}\n />\n {isPrinting && iframeTableProps.data !== null && (\n <PrintIFrame\n onAfterPrint={handleAfterPrint}\n onBeforePrint={handleBeforePrint}\n tableProps={iframeTableProps as Table3Props<TType>}\n />\n )}\n <WarningDialog\n open={showWarningDialog}\n onAccept={handleWarningDialogAccept}\n onClose={handleWarningDialogClose}\n onVisibilityChange={tableMeta.printing.setPrintWarningDialogVisibility}\n />\n </>\n );\n}\n"],"names":["SAFE_PRINT_CELL_COUNT","PrintButton","props","table","tableProps","texts","useLocalization","toast","useToast","isPrinting","setIsPrinting","React","useState","showWarningDialog","setShowWarningDialog","loadingToastRef","useRef","buttonRef","tableMeta","options","meta","state","getState","printWarningDialogVisibility","printing","printTableId","id","defaultSettings","useMemo","columnFreezingIndex","columnFreezing","frozenColumnIndex","columnOrder","columnSizing","columnVisibility","excludeUnmatchedRecordsInSearch","search","excludeUnmatchedResults","fontSize","size","rowHeight","height","sorting","columnFilters","globalFilter","iframeTableProps","useGlobalKeyDown","key","shift","event","preventDefault","_buttonRef$current","current","click","handleAfterPrint","_loadingToastRef$curr","close","handleBeforePrint","_loadingToastRef$curr2","handlePrint","hasNonSafeCellCount","loading","table3","print","getCellCount","data","length","Object","keys","_temp2","loadAll","cellCount","_temp","_catch","Promise","resolve","query","then","error","_loadingToastRef$curr3","errorMessage","console","_exit","_temp3","e","reject","handleWarningDialogAccept","handleWarningDialogClose","_loadingToastRef$curr4","IconButton","disabled","icon","onClick","tooltip","ref","PrintIFrame","onAfterPrint","onBeforePrint","WarningDialog","open","onAccept","onClose","onVisibilityChange","setPrintWarningDialogVisibility"],"mappings":";;;;;;;;;AAWA,MAAMA,qBAAqB,GAAG,KAAK;SAOnBC,WAAWA,CAAkBC,KAA8B;EACvE,MAAM;IAAEC,KAAK;IAAEC;GAAY,GAAGF,KAAK;EACnC,MAAM;IAAEG;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,KAAK,GAAGC,QAAQ,EAAE;EAExB,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGC,cAAK,CAACC,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AC9B5E,aAAa,CAAC,IAAI,CAAC;GACtB;EAED,MAAM6E,wBAAwB,GAAGA;;IAC7B,CAAAC,sBAAA,GAAAzE,eAAe,CAACqC,OAAO,cAAAoC,sBAAA,uBAAvBA,sBAAA,CAAyBhC,KAAK,EAAE;IAChC1C,oBAAoB,CAAC,KAAK,CAAC;GAC9B;EAED,oBACIH,yEACIA,6BAAC8E,UAAU;IACPC,QAAQ,EAAEjF,UAAU;IACpBkF,IAAI,EAAC,OAAO;IACZC,OAAO,EAAEjC,WAAW;kBACRtD,KAAK,CAACyD,MAAM,CAACC,KAAK,CAAC8B,OAAO;IACtCA,OAAO,EAAExF,KAAK,CAACyD,MAAM,CAACC,KAAK,CAAC8B,OAAO;IACnCC,GAAG,EAAE7E;IACP,EACDR,UAAU,IAAIoC,gBAAgB,CAACoB,IAAI,KAAK,IAAI,iBACzCtD,6BAACoF,WAAW;IACRC,YAAY,EAAE1C,gBAAgB;IAC9B2C,aAAa,EAAExC,iBAAiB;IAChCrD,UAAU,EAAEyC;IAEnB,eACDlC,6BAACuF,aAAa;IACVC,IAAI,EAAEtF,iBAAiB;IACvBuF,QAAQ,EAAEd,yBAAyB;IACnCe,OAAO,EAAEd,wBAAwB;IACjCe,kBAAkB,EAAEpF,SAAS,CAACM,QAAQ,CAAC+E;IACzC,CACH;AAEX;;;;"}
|
package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintIFrame.js
CHANGED
@@ -200,7 +200,9 @@ function PrintIFrame({
|
|
200
200
|
enableRowDrag: false,
|
201
201
|
enableRowDrop: false,
|
202
202
|
enableRowSelectionSingle: false,
|
203
|
-
preset: undefined
|
203
|
+
preset: undefined,
|
204
|
+
// The presence of the onChangeSettings prop ensures that settings won't be stored in local storage.
|
205
|
+
onChangeSettings: () => undefined
|
204
206
|
};
|
205
207
|
// -top-60 -left-60 styles make sure that iframe is added outside of the viewport
|
206
208
|
return /*#__PURE__*/React__default.createElement("iframe", {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PrintIFrame.js","sources":["../../../../../../../../../../src/components/Table3/components/toolbar/PrintButton/PrintIFrame.tsx"],"sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\n\nimport { Table3 } from '../../../../..';\nimport { Table3Props } from '../../../types';\nimport { useParentStylesheets } from './hooks/useParentStylesheets';\n\nexport type PrintIFrameProps<TType = unknown> = {\n onAfterPrint?: () => void;\n onBeforePrint?: () => void;\n tableProps: Table3Props<TType>;\n};\n\nexport function PrintIFrame<TType = unknown>({ onAfterPrint, onBeforePrint, tableProps }: PrintIFrameProps<TType>) {\n const [contentRef, setContentRef] = React.useState<HTMLIFrameElement | null>(null);\n const [mountNode, setMountNode] = React.useState<HTMLElement | null>(null);\n\n const isFirefoxBrowser = React.useMemo(() => navigator.userAgent.toLowerCase().includes('firefox'), []);\n\n const iframeWindow = contentRef?.contentWindow;\n\n const stylesReady = useParentStylesheets(iframeWindow);\n\n // Calls print method when table has loaded in the iframe.\n React.useEffect(() => {\n let intervalId: NodeJS.Timer;\n let timeoutId: NodeJS.Timer;\n\n // Invoke the print functionality on the window once the table has finished rendering and all print styles are\n // added.\n if (mountNode && stylesReady) {\n intervalId = setInterval(async () => {\n const tableWrapper = mountNode;\n const table = tableWrapper.querySelector('[role=\"table\"]') as HTMLElement;\n const hasTableRendered = !!table;\n\n if (hasTableRendered && intervalId) {\n clearInterval(intervalId);\n\n // Calling the onBeforePrint method here as a fallback because certain browsers, like Safari,\n // do not call the beforeprint event.\n // Bug - Even though onBeforePrint is called before printing, the execution doesn't finish before\n // the print dialog shows up, which results into having a visible loading toast.\n onBeforePrint?.();\n\n // By adding height to the tableWrapper, we make sure the content below absolutely positioned table\n // doesn't hide\n if (isFirefoxBrowser) {\n const tableHeight = `${table.offsetHeight}px`;\n tableWrapper.style.height = tableHeight;\n }\n\n contentRef?.contentWindow?.print();\n\n // Calling the onAfterPrint method here as a fallback to do the cleanup, as certain browsers,\n // like Safari, do not trigger the beforeprint or afterprint events when a confirmation dialog\n // asking if the user wants to print the document, is cancelled.\n\n // Added a setTimeout to prevent calling onAfterPrint immediately after the print function\n // to ensure that the print dialog doesn't close abruptly. Although this behavior is uncommon,\n // there are cases where the print function may not run synchronously, causing onAfterPrint to be\n // invoked right after it.\n timeoutId = setTimeout(() => {\n onAfterPrint?.();\n }, 0);\n }\n }, 1000);\n }\n\n return () => {\n clearInterval(intervalId);\n clearTimeout(timeoutId);\n };\n }, [mountNode, stylesReady]);\n\n React.useEffect(() => {\n if (!iframeWindow || !stylesReady) {\n return;\n }\n\n const iframeDocument = iframeWindow.document;\n // Only the content inside the main element will get printed along with the table.\n const parentDocumentContent =\n iframeWindow.parent.document.querySelector('main')?.innerHTML || iframeWindow.parent.document.body?.innerHTML || '';\n\n iframeDocument.body.innerHTML = parentDocumentContent;\n\n const tableElement = iframeDocument.querySelector('[role=\"table\"]');\n const tableColumnFreezingStyles = iframeDocument.querySelector('[data-taco=\"table3-column-freezing-styles\"]');\n const tableWrapper = iframeDocument.createElement('div');\n\n tableWrapper.setAttribute('data-role', 'table-wrapper');\n // Adding h-fit class makes sure that table is rendered with the whole content.\n tableWrapper.classList.add('h-fit');\n tableWrapper.classList.add('[&>[role=\"table\"]]:!h-fit');\n\n if (isFirefoxBrowser) {\n // Fix for firefox bug which adds page-long whitespace between page's top content and table\n tableWrapper.classList.add('[&>[role=\"table\"]]:!absolute');\n }\n\n // Safari print preview assigns no width to the table when w-screen class is used.\n // By assigning table a big static width and hiding the horizontal scrollbar, the table on chrome\n // and safari will always take full page width.\n tableWrapper.classList.add('w-[10000px]');\n\n if (tableElement) {\n tableElement.parentNode?.insertBefore(tableWrapper, tableElement);\n tableElement.remove();\n } else {\n iframeDocument.body.append(tableWrapper);\n }\n\n // Remove the already existing column freezing styles.\n if (tableColumnFreezingStyles) {\n tableColumnFreezingStyles.remove();\n }\n\n let currentNode = tableWrapper.parentNode as HTMLElement | null;\n\n while (currentNode !== null && currentNode !== iframeDocument.body) {\n // Add the 'h-fit' class to the 'table-wrapper' element's parent chain.\n // This ensures that the table is not cropped and fits within its container.\n currentNode?.classList.add('!h-fit');\n currentNode = currentNode.parentNode as HTMLElement | null;\n }\n\n setMountNode(tableWrapper);\n }, [iframeWindow, stylesReady]);\n\n const printTableProps: Table3Props<TType> = {\n ...tableProps,\n actionsForRow: undefined,\n // Not the best way to remove the active/current row styles, but a temporary solution for now\n defaultCurrentRowIndex: -1,\n defaultSettings: {\n ...tableProps?.defaultSettings,\n rowHeight: 'short',\n },\n enableColumnFreezing: false,\n enableRowHeight: true,\n enableRowSelection: false,\n enableEditing: false,\n enablePrinting: false,\n enableRowDrag: false,\n enableRowDrop: false,\n enableRowSelectionSingle: false,\n preset: undefined,\n };\n\n // -top-60 -left-60 styles make sure that iframe is added outside of the viewport\n return (\n <iframe\n className=\"fixed -left-60 -top-60 !h-0 !w-0\"\n ref={setContentRef}\n // Temporary fix to support printing in firefox: Find another solution while upgrading React\n src=\"javascript:void(0);\">\n {mountNode && stylesReady ? ReactDOM.createPortal(<Table3 {...printTableProps} />, mountNode) : null}\n </iframe>\n );\n}\n"],"names":["PrintIFrame","onAfterPrint","onBeforePrint","tableProps","contentRef","setContentRef","React","useState","mountNode","setMountNode","isFirefoxBrowser","useMemo","navigator","userAgent","toLowerCase","includes","iframeWindow","contentWindow","stylesReady","useParentStylesheets","useEffect","intervalId","timeoutId","setInterval","tableWrapper","table","querySelector","hasTableRendered","_contentRef$contentWi","clearInterval","tableHeight","offsetHeight","style","height","print","setTimeout","Promise","resolve","e","reject","clearTimeout","iframeDocument","document","parentDocumentContent","_iframeWindow$parent$","parent","innerHTML","_iframeWindow$parent$2","body","tableElement","tableColumnFreezingStyles","createElement","setAttribute","classList","add","_tableElement$parentN","parentNode","insertBefore","remove","append","currentNode","_currentNode","printTableProps","actionsForRow","undefined","defaultCurrentRowIndex","defaultSettings","rowHeight","enableColumnFreezing","enableRowHeight","enableRowSelection","enableEditing","enablePrinting","enableRowDrag","enableRowDrop","enableRowS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E;KACd;IACDC,oBAAoB,EAAE,KAAK;IAC3BC,eAAe,EAAE,IAAI;IACrBC,kBAAkB,EAAE,KAAK;IACzBC,aAAa,EAAE,KAAK;IACpBC,cAAc,EAAE,KAAK;IACrBC,aAAa,EAAE,KAAK;IACpBC,aAAa,EAAE,KAAK;IACpBC,wBAAwB,EAAE,KAAK;IAC/BC,MAAM,EAAEZ;GACX;;EAGD,oBACI1D;IACIuE,SAAS,EAAC,kCAAkC;IAC5CC,GAAG,EAAEzE,aAAa;;IAElB0E,GAAG,EAAC;KACHvE,SAAS,IAAIU,WAAW,gBAAG8D,QAAQ,CAACC,YAAY,eAAC3E,6BAAC4E,MAAM,oBAAKpB,eAAe,EAAI,EAAEtD,SAAS,CAAC,GAAG,IAAI,CAC/F;AAEjB;;;;"}
|
1
|
+
{"version":3,"file":"PrintIFrame.js","sources":["../../../../../../../../../../src/components/Table3/components/toolbar/PrintButton/PrintIFrame.tsx"],"sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\n\nimport { Table3 } from '../../../../..';\nimport { Table3Props } from '../../../types';\nimport { useParentStylesheets } from './hooks/useParentStylesheets';\n\nexport type PrintIFrameProps<TType = unknown> = {\n onAfterPrint?: () => void;\n onBeforePrint?: () => void;\n tableProps: Table3Props<TType>;\n};\n\nexport function PrintIFrame<TType = unknown>({ onAfterPrint, onBeforePrint, tableProps }: PrintIFrameProps<TType>) {\n const [contentRef, setContentRef] = React.useState<HTMLIFrameElement | null>(null);\n const [mountNode, setMountNode] = React.useState<HTMLElement | null>(null);\n\n const isFirefoxBrowser = React.useMemo(() => navigator.userAgent.toLowerCase().includes('firefox'), []);\n\n const iframeWindow = contentRef?.contentWindow;\n\n const stylesReady = useParentStylesheets(iframeWindow);\n\n // Calls print method when table has loaded in the iframe.\n React.useEffect(() => {\n let intervalId: NodeJS.Timer;\n let timeoutId: NodeJS.Timer;\n\n // Invoke the print functionality on the window once the table has finished rendering and all print styles are\n // added.\n if (mountNode && stylesReady) {\n intervalId = setInterval(async () => {\n const tableWrapper = mountNode;\n const table = tableWrapper.querySelector('[role=\"table\"]') as HTMLElement;\n const hasTableRendered = !!table;\n\n if (hasTableRendered && intervalId) {\n clearInterval(intervalId);\n\n // Calling the onBeforePrint method here as a fallback because certain browsers, like Safari,\n // do not call the beforeprint event.\n // Bug - Even though onBeforePrint is called before printing, the execution doesn't finish before\n // the print dialog shows up, which results into having a visible loading toast.\n onBeforePrint?.();\n\n // By adding height to the tableWrapper, we make sure the content below absolutely positioned table\n // doesn't hide\n if (isFirefoxBrowser) {\n const tableHeight = `${table.offsetHeight}px`;\n tableWrapper.style.height = tableHeight;\n }\n\n contentRef?.contentWindow?.print();\n\n // Calling the onAfterPrint method here as a fallback to do the cleanup, as certain browsers,\n // like Safari, do not trigger the beforeprint or afterprint events when a confirmation dialog\n // asking if the user wants to print the document, is cancelled.\n\n // Added a setTimeout to prevent calling onAfterPrint immediately after the print function\n // to ensure that the print dialog doesn't close abruptly. Although this behavior is uncommon,\n // there are cases where the print function may not run synchronously, causing onAfterPrint to be\n // invoked right after it.\n timeoutId = setTimeout(() => {\n onAfterPrint?.();\n }, 0);\n }\n }, 1000);\n }\n\n return () => {\n clearInterval(intervalId);\n clearTimeout(timeoutId);\n };\n }, [mountNode, stylesReady]);\n\n React.useEffect(() => {\n if (!iframeWindow || !stylesReady) {\n return;\n }\n\n const iframeDocument = iframeWindow.document;\n // Only the content inside the main element will get printed along with the table.\n const parentDocumentContent =\n iframeWindow.parent.document.querySelector('main')?.innerHTML || iframeWindow.parent.document.body?.innerHTML || '';\n\n iframeDocument.body.innerHTML = parentDocumentContent;\n\n const tableElement = iframeDocument.querySelector('[role=\"table\"]');\n const tableColumnFreezingStyles = iframeDocument.querySelector('[data-taco=\"table3-column-freezing-styles\"]');\n const tableWrapper = iframeDocument.createElement('div');\n\n tableWrapper.setAttribute('data-role', 'table-wrapper');\n // Adding h-fit class makes sure that table is rendered with the whole content.\n tableWrapper.classList.add('h-fit');\n tableWrapper.classList.add('[&>[role=\"table\"]]:!h-fit');\n\n if (isFirefoxBrowser) {\n // Fix for firefox bug which adds page-long whitespace between page's top content and table\n tableWrapper.classList.add('[&>[role=\"table\"]]:!absolute');\n }\n\n // Safari print preview assigns no width to the table when w-screen class is used.\n // By assigning table a big static width and hiding the horizontal scrollbar, the table on chrome\n // and safari will always take full page width.\n tableWrapper.classList.add('w-[10000px]');\n\n if (tableElement) {\n tableElement.parentNode?.insertBefore(tableWrapper, tableElement);\n tableElement.remove();\n } else {\n iframeDocument.body.append(tableWrapper);\n }\n\n // Remove the already existing column freezing styles.\n if (tableColumnFreezingStyles) {\n tableColumnFreezingStyles.remove();\n }\n\n let currentNode = tableWrapper.parentNode as HTMLElement | null;\n\n while (currentNode !== null && currentNode !== iframeDocument.body) {\n // Add the 'h-fit' class to the 'table-wrapper' element's parent chain.\n // This ensures that the table is not cropped and fits within its container.\n currentNode?.classList.add('!h-fit');\n currentNode = currentNode.parentNode as HTMLElement | null;\n }\n\n setMountNode(tableWrapper);\n }, [iframeWindow, stylesReady]);\n\n const printTableProps: Table3Props<TType> = {\n ...tableProps,\n actionsForRow: undefined,\n // Not the best way to remove the active/current row styles, but a temporary solution for now\n defaultCurrentRowIndex: -1,\n defaultSettings: {\n ...tableProps?.defaultSettings,\n rowHeight: 'short',\n },\n enableColumnFreezing: false,\n enableRowHeight: true,\n enableRowSelection: false,\n enableEditing: false,\n enablePrinting: false,\n enableRowDrag: false,\n enableRowDrop: false,\n enableRowSelectionSingle: false,\n preset: undefined,\n // The presence of the onChangeSettings prop ensures that settings won't be stored in local storage.\n onChangeSettings: () => undefined,\n };\n\n // -top-60 -left-60 styles make sure that iframe is added outside of the viewport\n return (\n <iframe\n className=\"fixed -left-60 -top-60 !h-0 !w-0\"\n ref={setContentRef}\n // Temporary fix to support printing in firefox: Find another solution while upgrading React\n src=\"javascript:void(0);\">\n {mountNode && stylesReady ? ReactDOM.createPortal(<Table3 {...printTableProps} />, mountNode) : null}\n </iframe>\n );\n}\n"],"names":["PrintIFrame","onAfterPrint","onBeforePrint","tableProps","contentRef","setContentRef","React","useState","mountNode","setMountNode","isFirefoxBrowser","useMemo","navigator","userAgent","toLowerCase","includes","iframeWindow","contentWindow","stylesReady","useParentStylesheets","useEffect","intervalId","timeoutId","setInterval","tableWrapper","table","querySelector","hasTableRendered","_contentRef$contentWi","clearInterval","tableHeight","offsetHeight","style","height","print","setTimeout","Promise","resolve","e","reject","clearTimeout","iframeDocument","document","parentDocumentContent","_iframeWindow$parent$","parent","innerHTML","_iframeWindow$parent$2","body","tableElement","tableColumnFreezingStyles","createElement","setAttribute","classList","add","_tableElement$parentN","parentNode","insertBefore","remove","append","currentNode","_currentNode","printTableProps","actionsForRow","undefined","defaultCurrentRowIndex","defaultSettings","rowHeight","enableColumnFreezing","enableRowHeight","enableRowSelection","enableEditing","enablePrinting","enableRowDrag","enableRowDrop","enableRowSelectionSingle","preset","onChangeSettings","className","ref","src","ReactDOM","createPortal","Table3"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAagBA,WAAWA,CAAkB;EAAEC,YAAY;EAAEC,aAAa;EAAEC;CAAqC;EAC7G,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAA2B,IAAI,CAAC;EAClF,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGH,cAAK,CAACC,QAAQ,CAAqB,IAAI,CAAC;EAE1E,MAAMG,gBAAgB,GAAGJ,cAAK,CAACK,OAAO,CAAC,MAAMC,SAAS,CAACC,SAAS,CAACC,WAAW,EAAE,CAACC,QAAQ,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC;EAEvG,MAAMC,YAAY,GAAGZ,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEa,aAAa;EAE9C,MAAMC,WAAW,GAAGC,oBAAoB,CAACH,YAAY,CAAC;;EAG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YAAY,CAACgC,UAAgC;IAE/D,OAAOI,WAAW,KAAK,IAAI,IAAIA,WAAW,KAAKnB,cAAc,CAACO,IAAI,EAAE;MAAA,IAAAa,YAAA;;;MAGhE,CAAAA,YAAA,GAAAD,WAAW,cAAAC,YAAA,uBAAXA,YAAA,CAAaR,SAAS,CAACC,GAAG,CAAC,QAAQ,CAAC;MACpCM,WAAW,GAAGA,WAAW,CAACJ,UAAgC;;IAG9D/C,YAAY,CAACe,YAAY,CAAC;GAC7B,EAAE,CAACR,YAAY,EAAEE,WAAW,CAAC,CAAC;EAE/B,MAAM4C,eAAe,GAAuB;IACxC,GAAG3D,UAAU;IACb4D,aAAa,EAAEC,SAAS;;IAExBC,sBAAsB,EAAE,CAAC,CAAC;IAC1BC,eAAe,EAAE;MACb,IAAG/D,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAE+D,eAAe;MAC9BC,SAAS,EAAE;KACd;IACDC,oBAAoB,EAAE,KAAK;IAC3BC,eAAe,EAAE,IAAI;IACrBC,kBAAkB,EAAE,KAAK;IACzBC,aAAa,EAAE,KAAK;IACpBC,cAAc,EAAE,KAAK;IACrBC,aAAa,EAAE,KAAK;IACpBC,aAAa,EAAE,KAAK;IACpBC,wBAAwB,EAAE,KAAK;IAC/BC,MAAM,EAAEZ,SAAS;;IAEjBa,gBAAgB,EAAEA,MAAMb;GAC3B;;EAGD,oBACI1D;IACIwE,SAAS,EAAC,kCAAkC;IAC5CC,GAAG,EAAE1E,aAAa;;IAElB2E,GAAG,EAAC;KACHxE,SAAS,IAAIU,WAAW,gBAAG+D,QAAQ,CAACC,YAAY,eAAC5E,6BAAC6E,MAAM,oBAAKrB,eAAe,EAAI,EAAEtD,SAAS,CAAC,GAAG,IAAI,CAC/F;AAEjB;;;;"}
|
@@ -51,17 +51,26 @@ function useColumnFreezingStyle(tableId, table) {
|
|
51
51
|
columnVisibility
|
52
52
|
} = table.getState();
|
53
53
|
const tableMeta = table.options.meta;
|
54
|
-
const frozenColumnIndex =
|
54
|
+
const frozenColumnIndex =
|
55
|
+
// If column freezing is not enabled then only internal frozen column should be frozen.
|
56
|
+
(tableMeta.columnFreezing.isEnabled ? (_tableMeta$columnFree = tableMeta.columnFreezing.frozenColumnIndex) !== null && _tableMeta$columnFree !== void 0 ? _tableMeta$columnFree : -1 : -1) + tableMeta.columnFreezing.frozenInternalColumnCount;
|
55
57
|
const style = React__default.useMemo(() => {
|
56
58
|
if (tableMeta.columnFreezing.frozenInternalColumnCount > 0 || tableMeta.columnFreezing.isEnabled && frozenColumnIndex !== undefined) {
|
57
|
-
|
59
|
+
var _visibleFrozenColumns;
|
60
|
+
const visibleFrozenColumns = table.getVisibleLeafColumns().slice(0, frozenColumnIndex + 1);
|
58
61
|
// if all frozen columns haven't had their size set yet, then abort
|
59
|
-
if (visibleFrozenColumns.every(
|
62
|
+
if (visibleFrozenColumns.every(column => columnSizing[column.id] === undefined)) {
|
60
63
|
return undefined;
|
61
64
|
}
|
62
65
|
const offsets = {};
|
63
|
-
visibleFrozenColumns.reduce((offset,
|
66
|
+
visibleFrozenColumns.reduce((offset, column) => {
|
67
|
+
const columnId = column.id;
|
64
68
|
offsets[columnId] = offset;
|
69
|
+
if (isInternalColumn(columnId)) {
|
70
|
+
// getSize method is used instead of columnSizing state because columnSizing state doesn't have
|
71
|
+
// sizes of internal columns.
|
72
|
+
return offset + column.getSize();
|
73
|
+
}
|
65
74
|
return offset + columnSizing[columnId];
|
66
75
|
}, 0);
|
67
76
|
const styles = [Object.values(offsets).map((offset, index) => `#${tableId} [role="row"] > :nth-child(${index + 1}) { left: ${offset}px }`).join('\n'), `#${tableId} [role="row"] > :not(:nth-child(n+${frozenColumnIndex + 2})) {
|
@@ -70,7 +79,7 @@ function useColumnFreezingStyle(tableId, table) {
|
|
70
79
|
}`, `#${tableId}[data-horizontally-scrolled="true"] [role="row"] > :nth-child(${frozenColumnIndex + 1}) {
|
71
80
|
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), 6px 0px 6px rgb(0 0 0/8%), 1px 0px 0px #DDDDDD;
|
72
81
|
}`];
|
73
|
-
const columnId = visibleFrozenColumns[frozenColumnIndex];
|
82
|
+
const columnId = (_visibleFrozenColumns = visibleFrozenColumns[frozenColumnIndex]) === null || _visibleFrozenColumns === void 0 ? void 0 : _visibleFrozenColumns.id;
|
74
83
|
// frozenColumnIndex could not be in the visible frozen column so it is important to check if columnId
|
75
84
|
// exists before checking if it is internal.
|
76
85
|
//
|
package/dist/esm/packages/taco/src/components/Table3/hooks/features/useColumnFreezing.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useColumnFreezing.js","sources":["../../../../../../../../../src/components/Table3/hooks/features/useColumnFreezing.ts"],"sourcesContent":["import { Table, TableMeta } from '@tanstack/react-table';\nimport React from 'react';\nimport { Table3Options } from '../../types';\nimport { isInternalColumn } from '../../util/columns';\n\nexport function getFrozenInternalColumnCount(options: Table3Options) {\n let index = 0;\n\n if (options.enableRowDrag) {\n index++;\n }\n\n if (options.enableRowSelection) {\n index++;\n }\n\n if (options.enableRowExpansion) {\n index++;\n }\n\n return index;\n}\n\n/*\nBecause of the desired behaviour of column freezing we use custom state and just an index.\nIf a frozen column is, for example, hidden, then the desired behaviour is that the next available column gets frozen.\nIf this behaviour were different we would just use the native column pinning functionality\n*/\nexport function useColumnFreezing(defaultFrozenIndex: number | undefined, options: Table3Options) {\n const [frozenColumnIndex, _setFrozenColumnIndex] = React.useState<number | undefined>(() => defaultFrozenIndex);\n const [horizontallyScrolled, setHorizontallyScrolled] = React.useState(false);\n\n const onScroll = (event: React.MouseEvent<HTMLDivElement>) => {\n if (event.currentTarget.scrollLeft > 0 && !horizontallyScrolled) {\n setHorizontallyScrolled(true);\n } else if (event.currentTarget.scrollLeft === 0 && horizontallyScrolled) {\n setHorizontallyScrolled(false);\n }\n };\n\n const frozenInternalColumnCount = React.useMemo(() => getFrozenInternalColumnCount(options), []);\n // we must set a value when undefined is explicitly set, otherwise nothing is saved to settings\n // and the next time the table loads it will fall back to the initial value even though the user changed it\n const setFrozenColumnIndex = (index: number | undefined) => _setFrozenColumnIndex(index ?? -1);\n\n return {\n isEnabled: options.enableColumnFreezing,\n frozenInternalColumnCount,\n frozenColumnIndex,\n setFrozenColumnIndex,\n horizontallyScrolled,\n handleScroll: onScroll,\n };\n}\n\nexport function useColumnFreezingStyle<TType = unknown>(tableId: string, table: Table<TType>) {\n const { columnOrder, columnSizing, columnSizingInfo, columnVisibility } = table.getState();\n const tableMeta = table.options.meta as TableMeta<TType>;\n const frozenColumnIndex =\n (tableMeta.columnFreezing.frozenColumnIndex ?? -1)
|
1
|
+
{"version":3,"file":"useColumnFreezing.js","sources":["../../../../../../../../../src/components/Table3/hooks/features/useColumnFreezing.ts"],"sourcesContent":["import { Table, TableMeta } from '@tanstack/react-table';\nimport React from 'react';\nimport { Table3Options } from '../../types';\nimport { isInternalColumn } from '../../util/columns';\n\nexport function getFrozenInternalColumnCount(options: Table3Options) {\n let index = 0;\n\n if (options.enableRowDrag) {\n index++;\n }\n\n if (options.enableRowSelection) {\n index++;\n }\n\n if (options.enableRowExpansion) {\n index++;\n }\n\n return index;\n}\n\n/*\nBecause of the desired behaviour of column freezing we use custom state and just an index.\nIf a frozen column is, for example, hidden, then the desired behaviour is that the next available column gets frozen.\nIf this behaviour were different we would just use the native column pinning functionality\n*/\nexport function useColumnFreezing(defaultFrozenIndex: number | undefined, options: Table3Options) {\n const [frozenColumnIndex, _setFrozenColumnIndex] = React.useState<number | undefined>(() => defaultFrozenIndex);\n const [horizontallyScrolled, setHorizontallyScrolled] = React.useState(false);\n\n const onScroll = (event: React.MouseEvent<HTMLDivElement>) => {\n if (event.currentTarget.scrollLeft > 0 && !horizontallyScrolled) {\n setHorizontallyScrolled(true);\n } else if (event.currentTarget.scrollLeft === 0 && horizontallyScrolled) {\n setHorizontallyScrolled(false);\n }\n };\n\n const frozenInternalColumnCount = React.useMemo(() => getFrozenInternalColumnCount(options), []);\n // we must set a value when undefined is explicitly set, otherwise nothing is saved to settings\n // and the next time the table loads it will fall back to the initial value even though the user changed it\n const setFrozenColumnIndex = (index: number | undefined) => _setFrozenColumnIndex(index ?? -1);\n\n return {\n isEnabled: options.enableColumnFreezing,\n frozenInternalColumnCount,\n frozenColumnIndex,\n setFrozenColumnIndex,\n horizontallyScrolled,\n handleScroll: onScroll,\n };\n}\n\nexport function useColumnFreezingStyle<TType = unknown>(tableId: string, table: Table<TType>) {\n const { columnOrder, columnSizing, columnSizingInfo, columnVisibility } = table.getState();\n const tableMeta = table.options.meta as TableMeta<TType>;\n const frozenColumnIndex =\n // If column freezing is not enabled then only internal frozen column should be frozen.\n (tableMeta.columnFreezing.isEnabled ? tableMeta.columnFreezing.frozenColumnIndex ?? -1 : -1) +\n tableMeta.columnFreezing.frozenInternalColumnCount;\n\n const style = React.useMemo(() => {\n if (\n tableMeta.columnFreezing.frozenInternalColumnCount > 0 ||\n (tableMeta.columnFreezing.isEnabled && frozenColumnIndex !== undefined)\n ) {\n const visibleFrozenColumns = table.getVisibleLeafColumns().slice(0, frozenColumnIndex + 1);\n\n // if all frozen columns haven't had their size set yet, then abort\n if (visibleFrozenColumns.every(column => columnSizing[column.id] === undefined)) {\n return undefined;\n }\n\n const offsets = {};\n\n visibleFrozenColumns.reduce((offset, column) => {\n const columnId = column.id;\n\n offsets[columnId] = offset;\n\n if (isInternalColumn(columnId)) {\n // getSize method is used instead of columnSizing state because columnSizing state doesn't have\n // sizes of internal columns.\n return offset + column.getSize();\n }\n\n return offset + columnSizing[columnId];\n }, 0);\n\n const styles = [\n Object.values(offsets)\n .map((offset, index) => `#${tableId} [role=\"row\"] > :nth-child(${index + 1}) { left: ${offset}px }`)\n .join('\\n'),\n `#${tableId} [role=\"row\"] > :not(:nth-child(n+${frozenColumnIndex + 2})) {\n position: sticky;\n z-index: 20;\n }`,\n `#${tableId}[data-horizontally-scrolled=\"true\"] [role=\"row\"] > :nth-child(${frozenColumnIndex + 1}) {\n box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), 6px 0px 6px rgb(0 0 0/8%), 1px 0px 0px #DDDDDD;\n }`,\n ];\n\n const columnId = visibleFrozenColumns[frozenColumnIndex]?.id;\n\n // frozenColumnIndex could not be in the visible frozen column so it is important to check if columnId\n // exists before checking if it is internal.\n //\n // only add a border to the edge column if it isn't an internal column\n if (columnId && !isInternalColumn(columnId)) {\n styles.push(`#${tableId}[data-horizontally-scrolled=\"false\"] [role=\"row\"] > :nth-child(${frozenColumnIndex + 1}) {\n box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), 1px 0px 0px #DDDDDD;\n }`);\n }\n\n return styles.join('\\n');\n }\n\n return undefined;\n }, [columnOrder, columnSizing, columnSizingInfo, columnVisibility, tableMeta.columnFreezing.isEnabled, frozenColumnIndex]);\n\n return style;\n}\n"],"names":["getFrozenInternalColumnCount","options","index","enableRowDrag","enableRowSelection","enableRowExpansion","useColumnFreezing","defaultFrozenIndex","frozenColumnIndex","_setFrozenColumnIndex","React","useState","horizontallyScrolled","setHorizontallyScrolled","onScroll","event","currentTarget","scrollLeft","frozenInternalColumnCount","useMemo","setFrozenColumnIndex","isEnabled","enableColumnFreezing","handleScroll","useColumnFreezingStyle","tableId","table","columnOrder","columnSizing","columnSizingInfo","columnVisibility","getState","tableMeta","meta","columnFreezing","_tableMeta$columnFree","style","undefined","_visibleFrozenColumns","visibleFrozenColumns","getVisibleLeafColumns","slice","every","column","id","offsets","reduce","offset","columnId","isInternalColumn","getSize","styles","Object","values","map","join","push"],"mappings":";;;SAKgBA,4BAA4BA,CAACC,OAAsB;EAC/D,IAAIC,KAAK,GAAG,CAAC;EAEb,IAAID,OAAO,CAACE,aAAa,EAAE;IACvBD,KAAK,EAAE;;EAGX,IAAID,OAAO,CAACG,kBAAkB,EAAE;IAC5BF,KAAK,EAAE;;EAGX,IAAID,OAAO,CAACI,kBAAkB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;;kBAGlE,MACEiB,wEAAwEjB,iBAAiB,GAAG;;kBAE9F,CACL;MAED,MAAMwC,QAAQ,IAAAV,qBAAA,GAAGC,oBAAoB,CAAC/B,iBAAiB,CAAC,cAAA8B,qBAAA,uBAAvCA,qBAAA,CAAyCM,EAAE;;;;;MAM5D,IAAII,QAAQ,IAAI,CAACC,gBAAgB,CAACD,QAAQ,CAAC,EAAE;QACzCG,MAAM,CAACK,IAAI,KAAK/B,yEAAyEjB,iBAAiB,GAAG;;kBAE3G,CAAC;;MAGP,OAAO2C,MAAM,CAACI,IAAI,CAAC,IAAI,CAAC;;IAG5B,OAAOlB,SAAS;GACnB,EAAE,CAACV,WAAW,EAAEC,YAAY,EAAEC,gBAAgB,EAAEC,gBAAgB,EAAEE,SAAS,CAACE,cAAc,CAACb,SAAS,EAAEb,iBAAiB,CAAC,CAAC;EAE1H,OAAO4B,KAAK;AAChB;;;;"}
|
@@ -2,10 +2,16 @@ import React__default from 'react';
|
|
2
2
|
import { useLocalStorage } from '../../../../hooks/useLocalStorage.js';
|
3
3
|
import { useTacoSettings } from '../../../../hooks/useTacoSettings.js';
|
4
4
|
|
5
|
-
function
|
5
|
+
function useUniqueTableId(tableId) {
|
6
6
|
const tacoSettings = useTacoSettings();
|
7
|
-
|
8
|
-
|
7
|
+
return `taco.${tacoSettings.uniqueUserIdentifier}.table3.${tableId}.settings`;
|
8
|
+
}
|
9
|
+
function useSettings(id, defaultSettings = {}, onChangeSettings) {
|
10
|
+
const uniqueId = useUniqueTableId(id);
|
11
|
+
// If the onChangeSettings prop is provided, we intend to handle settings changes externally rather than saving them
|
12
|
+
// to local storage.
|
13
|
+
const key = !onChangeSettings ? uniqueId : undefined;
|
14
|
+
const [persistedSettings, setPersistedSettings] = useLocalStorage(key, defaultSettings);
|
9
15
|
return React__default.useMemo(() => {
|
10
16
|
if (onChangeSettings) {
|
11
17
|
return [defaultSettings, onChangeSettings];
|
@@ -14,5 +20,5 @@ function useSettings(id, defaultSettings = {}, onChangeSettings) {
|
|
14
20
|
}, []);
|
15
21
|
}
|
16
22
|
|
17
|
-
export { useSettings };
|
23
|
+
export { useSettings, useUniqueTableId };
|
18
24
|
//# sourceMappingURL=useSettings.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useSettings.js","sources":["../../../../../../../../../src/components/Table3/hooks/features/useSettings.ts"],"sourcesContent":["import React from 'react';\nimport { useLocalStorage } from '../../../../hooks/useLocalStorage';\nimport { useTacoSettings } from '../../../../hooks/useTacoSettings';\nimport { Table3Settings, Table3SettingsHandler } from '../../types';\n\nexport function useSettings(\n id: string,\n defaultSettings: Table3Settings | undefined = {},\n onChangeSettings: Table3SettingsHandler | undefined\n): [Table3Settings, Table3SettingsHandler] {\n const
|
1
|
+
{"version":3,"file":"useSettings.js","sources":["../../../../../../../../../src/components/Table3/hooks/features/useSettings.ts"],"sourcesContent":["import React from 'react';\nimport { useLocalStorage } from '../../../../hooks/useLocalStorage';\nimport { useTacoSettings } from '../../../../hooks/useTacoSettings';\nimport { Table3Settings, Table3SettingsHandler } from '../../types';\n\nexport function useUniqueTableId(tableId: string) {\n const tacoSettings = useTacoSettings();\n\n return `taco.${tacoSettings.uniqueUserIdentifier}.table3.${tableId}.settings`;\n}\n\nexport function useSettings(\n id: string,\n defaultSettings: Table3Settings | undefined = {},\n onChangeSettings: Table3SettingsHandler | undefined\n): [Table3Settings, Table3SettingsHandler] {\n const uniqueId = useUniqueTableId(id);\n // If the onChangeSettings prop is provided, we intend to handle settings changes externally rather than saving them\n // to local storage.\n const key = !onChangeSettings ? uniqueId : undefined;\n const [persistedSettings, setPersistedSettings] = useLocalStorage<Table3Settings>(key, defaultSettings);\n\n return React.useMemo(() => {\n if (onChangeSettings) {\n return [defaultSettings, onChangeSettings];\n }\n\n return [persistedSettings, setPersistedSettings];\n }, []);\n}\n"],"names":["useUniqueTableId","tableId","tacoSettings","useTacoSettings","uniqueUserIdentifier","useSettings","id","defaultSettings","onChangeSettings","uniqueId","key","undefined","persistedSettings","setPersistedSettings","useLocalStorage","React","useMemo"],"mappings":";;;;SAKgBA,gBAAgBA,CAACC,OAAe;EAC5C,MAAMC,YAAY,GAAGC,eAAe,EAAE;EAEtC,eAAeD,YAAY,CAACE,+BAA+BH,kBAAkB;AACjF;SAEgBI,WAAWA,CACvBC,EAAU,EACVC,kBAA8C,EAAE,EAChDC,gBAAmD;EAEnD,MAAMC,QAAQ,GAAGT,gBAAgB,CAACM,EAAE,CAAC;;;EAGrC,MAAMI,GAAG,GAAG,CAACF,gBAAgB,GAAGC,QAAQ,GAAGE,SAAS;EACpD,MAAM,CAACC,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGC,eAAe,CAAiBJ,GAAG,EAAEH,eAAe,CAAC;EAEvG,OAAOQ,cAAK,CAACC,OAAO,CAAC;IACjB,IAAIR,gBAAgB,EAAE;MAClB,OAAO,CAACD,eAAe,EAAEC,gBAAgB,CAAC;;IAG9C,OAAO,CAACI,iBAAiB,EAAEC,oBAAoB,CAAC;GACnD,EAAE,EAAE,CAAC;AACV;;;;"}
|
@@ -26,88 +26,92 @@ function getSortingFn(dataType, customFnOrBuiltIn) {
|
|
26
26
|
return 'auto';
|
27
27
|
}
|
28
28
|
function useConvertChildrenToColumns(props, options, editing) {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
29
|
+
// It's important to memoise column definitions, because it prevents columns like "Drag column" to re-render on every state change,
|
30
|
+
// and break dragging at the moment it happens.
|
31
|
+
return React__default.useMemo(() => {
|
32
|
+
var _props$actionsForRow;
|
33
|
+
const columnHelper = createColumnHelper();
|
34
|
+
const columns = [];
|
35
|
+
const defaultColumnSizing = {};
|
36
|
+
const defaultColumnVisibility = {};
|
37
|
+
const defaultSorting = [];
|
38
|
+
React__default.Children.toArray(props.children).filter(child => !!child) // remove falsey children
|
39
|
+
.forEach(child => {
|
40
|
+
if ( /*#__PURE__*/React__default.isValidElement(child) && child.props.accessor) {
|
41
|
+
var _child$props$enableRe, _child$props$enableFi, _child$props$enableSo, _child$props$enableHi, _child$props$enableOr, _child$props$enableSe, _child$props$enableTr;
|
42
|
+
if (child.props.defaultWidth) {
|
43
|
+
defaultColumnSizing[child.props.accessor] = child.props.defaultWidth === 'grow' ? '1fr' : child.props.defaultWidth;
|
44
|
+
}
|
45
|
+
if (child.props.defaultHidden && options.enableColumnHiding) {
|
46
|
+
defaultColumnVisibility[child.props.accessor] = false;
|
47
|
+
}
|
48
|
+
if (child.props.sort !== undefined) {
|
49
|
+
defaultSorting.push({
|
50
|
+
id: child.props.accessor,
|
51
|
+
desc: child.props.sort === 'desc'
|
52
|
+
});
|
53
|
+
}
|
54
|
+
columns.push({
|
55
|
+
accessorKey: child.props.accessor,
|
47
56
|
id: child.props.accessor,
|
48
|
-
|
57
|
+
header: Header,
|
58
|
+
cell: Cell,
|
59
|
+
footer: Footer,
|
60
|
+
// sizing
|
61
|
+
minSize: MIN_COLUMN_SIZE,
|
62
|
+
enableResizing: (_child$props$enableRe = child.props.enableResizing) !== null && _child$props$enableRe !== void 0 ? _child$props$enableRe : true,
|
63
|
+
// filtering
|
64
|
+
enableColumnFilter: (_child$props$enableFi = child.props.enableFiltering) !== null && _child$props$enableFi !== void 0 ? _child$props$enableFi : true,
|
65
|
+
filterFn: 'tacoFilter',
|
66
|
+
// sorting
|
67
|
+
enableSorting: (_child$props$enableSo = child.props.enableSorting) !== null && _child$props$enableSo !== void 0 ? _child$props$enableSo : true,
|
68
|
+
sortingFn: getSortingFn(child.props.dataType, child.props.sortFn),
|
69
|
+
sortDescFirst: false,
|
70
|
+
sortUndefined: 1,
|
71
|
+
// visibility
|
72
|
+
enableHiding: (_child$props$enableHi = child.props.enableHiding) !== null && _child$props$enableHi !== void 0 ? _child$props$enableHi : true,
|
73
|
+
// custom options
|
74
|
+
meta: {
|
75
|
+
align: child.props.align,
|
76
|
+
className: child.props.className,
|
77
|
+
control: child.props.control,
|
78
|
+
dataType: child.props.dataType,
|
79
|
+
enableOrdering: (_child$props$enableOr = child.props.enableOrdering) !== null && _child$props$enableOr !== void 0 ? _child$props$enableOr : true,
|
80
|
+
enableSearch: (_child$props$enableSe = child.props.enableSearch) !== null && _child$props$enableSe !== void 0 ? _child$props$enableSe : true,
|
81
|
+
enableTruncate: (_child$props$enableTr = child.props.enableTruncate) !== null && _child$props$enableTr !== void 0 ? _child$props$enableTr : false,
|
82
|
+
filters: child.props.filters,
|
83
|
+
footer: child.props.footer,
|
84
|
+
header: child.props.header,
|
85
|
+
headerClassName: child.props.headerClassName,
|
86
|
+
menu: child.props.menu,
|
87
|
+
renderer: child.props.renderer,
|
88
|
+
tooltip: child.props.tooltip
|
89
|
+
}
|
49
90
|
});
|
50
91
|
}
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
header: Header,
|
55
|
-
cell: Cell,
|
56
|
-
footer: Footer,
|
57
|
-
// sizing
|
58
|
-
minSize: MIN_COLUMN_SIZE,
|
59
|
-
enableResizing: (_child$props$enableRe = child.props.enableResizing) !== null && _child$props$enableRe !== void 0 ? _child$props$enableRe : true,
|
60
|
-
// filtering
|
61
|
-
enableColumnFilter: (_child$props$enableFi = child.props.enableFiltering) !== null && _child$props$enableFi !== void 0 ? _child$props$enableFi : true,
|
62
|
-
filterFn: 'tacoFilter',
|
63
|
-
// sorting
|
64
|
-
enableSorting: (_child$props$enableSo = child.props.enableSorting) !== null && _child$props$enableSo !== void 0 ? _child$props$enableSo : true,
|
65
|
-
sortingFn: getSortingFn(child.props.dataType, child.props.sortFn),
|
66
|
-
sortDescFirst: false,
|
67
|
-
sortUndefined: 1,
|
68
|
-
// visibility
|
69
|
-
enableHiding: (_child$props$enableHi = child.props.enableHiding) !== null && _child$props$enableHi !== void 0 ? _child$props$enableHi : true,
|
70
|
-
// custom options
|
71
|
-
meta: {
|
72
|
-
align: child.props.align,
|
73
|
-
className: child.props.className,
|
74
|
-
control: child.props.control,
|
75
|
-
dataType: child.props.dataType,
|
76
|
-
enableOrdering: (_child$props$enableOr = child.props.enableOrdering) !== null && _child$props$enableOr !== void 0 ? _child$props$enableOr : true,
|
77
|
-
enableSearch: (_child$props$enableSe = child.props.enableSearch) !== null && _child$props$enableSe !== void 0 ? _child$props$enableSe : true,
|
78
|
-
enableTruncate: (_child$props$enableTr = child.props.enableTruncate) !== null && _child$props$enableTr !== void 0 ? _child$props$enableTr : false,
|
79
|
-
filters: child.props.filters,
|
80
|
-
footer: child.props.footer,
|
81
|
-
header: child.props.header,
|
82
|
-
headerClassName: child.props.headerClassName,
|
83
|
-
menu: child.props.menu,
|
84
|
-
renderer: child.props.renderer,
|
85
|
-
tooltip: child.props.tooltip
|
86
|
-
}
|
87
|
-
});
|
92
|
+
});
|
93
|
+
if (options.enableRowExpansion && props.expandedRowRenderer) {
|
94
|
+
columns.unshift(columnHelper.display(createRowExpansionColumn(props.expandedRowRenderer)));
|
88
95
|
}
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
defaultColumnVisibility,
|
109
|
-
defaultSorting
|
110
|
-
};
|
96
|
+
if (options.enableRowSelection) {
|
97
|
+
columns.unshift(columnHelper.display(createRowSelectionColumn(!!(options.enableRowDrag && props.onRowDrag), !!props.expandedRowRenderer)));
|
98
|
+
}
|
99
|
+
if (options.enableRowDrag && props.onRowDrag) {
|
100
|
+
columns.unshift(columnHelper.display(createRowDragColumn(props.onRowDrag)));
|
101
|
+
}
|
102
|
+
if ((_props$actionsForRow = props.actionsForRow) !== null && _props$actionsForRow !== void 0 && _props$actionsForRow.length) {
|
103
|
+
columns.push(columnHelper.display(createRowActionsColumn()));
|
104
|
+
}
|
105
|
+
if (editing.isEnabled && editing.isEditing) {
|
106
|
+
columns.push(columnHelper.display(createRowEditingActionsColumn()));
|
107
|
+
}
|
108
|
+
return {
|
109
|
+
columns,
|
110
|
+
defaultColumnSizing,
|
111
|
+
defaultColumnVisibility,
|
112
|
+
defaultSorting
|
113
|
+
};
|
114
|
+
}, [props.children]);
|
111
115
|
}
|
112
116
|
|
113
117
|
export { useConvertChildrenToColumns };
|