@fluentui/react-table 9.18.4 → 9.18.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -2
- package/dist/index.d.ts +18 -21
- package/lib/components/DataGridBody/renderDataGridBody.js.map +1 -1
- package/lib/components/DataGridCell/renderDataGridCell.js.map +1 -1
- package/lib/components/DataGridHeader/renderDataGridHeader.js.map +1 -1
- package/lib/components/DataGridHeaderCell/renderDataGridHeaderCell.js.map +1 -1
- package/lib/components/DataGridRow/renderDataGridRow.js.map +1 -1
- package/lib/components/DataGridRow/useDataGridRow.js +1 -6
- package/lib/components/DataGridRow/useDataGridRow.js.map +1 -1
- package/lib/components/DataGridRow/useDataGridRowStyles.styles.js +3 -10
- package/lib/components/DataGridRow/useDataGridRowStyles.styles.js.map +1 -1
- package/lib/components/DataGridRow/useDataGridRowStyles.styles.raw.js +1 -18
- package/lib/components/DataGridRow/useDataGridRowStyles.styles.raw.js.map +1 -1
- package/lib/components/DataGridSelectionCell/renderDataGridSelectionCell.js.map +1 -1
- package/lib/components/DataGridSelectionCell/useDataGridSelectionCell.js +1 -0
- package/lib/components/DataGridSelectionCell/useDataGridSelectionCell.js.map +1 -1
- package/lib/components/Table/renderTable.js.map +1 -1
- package/lib/components/TableBody/renderTableBody.js.map +1 -1
- package/lib/components/TableCell/renderTableCell.js.map +1 -1
- package/lib/components/TableCellActions/renderTableCellActions.js.map +1 -1
- package/lib/components/TableCellLayout/renderTableCellLayout.js.map +1 -1
- package/lib/components/TableHeader/renderTableHeader.js.map +1 -1
- package/lib/components/TableHeaderCell/renderTableHeaderCell.js.map +1 -1
- package/lib/components/TableResizeHandle/renderTableResizeHandle.js.map +1 -1
- package/lib/components/TableRow/renderTableRow.js.map +1 -1
- package/lib/components/TableSelectionCell/renderTableSelectionCell.js.map +1 -1
- package/lib/contexts/columnIdContext.js.map +1 -1
- package/lib/contexts/dataGridContext.js.map +1 -1
- package/lib/contexts/rowIdContext.js.map +1 -1
- package/lib/contexts/tableContext.js.map +1 -1
- package/lib/contexts/tableHeaderContext.js.map +1 -1
- package/lib/hooks/createColumn.js +1 -0
- package/lib/hooks/createColumn.js.map +1 -1
- package/lib/hooks/useKeyboardResizing.js +1 -1
- package/lib/hooks/useKeyboardResizing.js.map +1 -1
- package/lib/hooks/useMeasureElement.js.map +1 -1
- package/lib/hooks/useTableColumnResizeMouseHandler.js.map +1 -1
- package/lib/hooks/useTableColumnSizing.js.map +1 -1
- package/lib/hooks/useTableCompositeNavigation.js +8 -2
- package/lib/hooks/useTableCompositeNavigation.js.map +1 -1
- package/lib/hooks/useTableSelection.js.map +1 -1
- package/lib/hooks/useTableSort.js.map +1 -1
- package/lib/utils/columnResizeUtils.js +10 -1
- package/lib/utils/columnResizeUtils.js.map +1 -1
- package/lib/utils/isColumnSortable.js.map +1 -1
- package/lib-commonjs/components/DataGridBody/renderDataGridBody.js.map +1 -1
- package/lib-commonjs/components/DataGridCell/renderDataGridCell.js.map +1 -1
- package/lib-commonjs/components/DataGridHeader/renderDataGridHeader.js.map +1 -1
- package/lib-commonjs/components/DataGridHeaderCell/renderDataGridHeaderCell.js.map +1 -1
- package/lib-commonjs/components/DataGridRow/renderDataGridRow.js.map +1 -1
- package/lib-commonjs/components/DataGridRow/useDataGridRow.js +1 -6
- package/lib-commonjs/components/DataGridRow/useDataGridRow.js.map +1 -1
- package/lib-commonjs/components/DataGridRow/useDataGridRowStyles.styles.js +1 -10
- package/lib-commonjs/components/DataGridRow/useDataGridRowStyles.styles.js.map +1 -1
- package/lib-commonjs/components/DataGridRow/useDataGridRowStyles.styles.raw.js +1 -18
- package/lib-commonjs/components/DataGridRow/useDataGridRowStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/DataGridSelectionCell/renderDataGridSelectionCell.js.map +1 -1
- package/lib-commonjs/components/DataGridSelectionCell/useDataGridSelectionCell.js +1 -0
- package/lib-commonjs/components/DataGridSelectionCell/useDataGridSelectionCell.js.map +1 -1
- package/lib-commonjs/components/Table/renderTable.js.map +1 -1
- package/lib-commonjs/components/TableBody/renderTableBody.js.map +1 -1
- package/lib-commonjs/components/TableCell/renderTableCell.js.map +1 -1
- package/lib-commonjs/components/TableCellActions/renderTableCellActions.js.map +1 -1
- package/lib-commonjs/components/TableCellLayout/renderTableCellLayout.js.map +1 -1
- package/lib-commonjs/components/TableHeader/renderTableHeader.js.map +1 -1
- package/lib-commonjs/components/TableHeaderCell/renderTableHeaderCell.js.map +1 -1
- package/lib-commonjs/components/TableResizeHandle/renderTableResizeHandle.js.map +1 -1
- package/lib-commonjs/components/TableRow/renderTableRow.js.map +1 -1
- package/lib-commonjs/components/TableSelectionCell/renderTableSelectionCell.js.map +1 -1
- package/lib-commonjs/contexts/columnIdContext.js.map +1 -1
- package/lib-commonjs/contexts/dataGridContext.js.map +1 -1
- package/lib-commonjs/contexts/rowIdContext.js.map +1 -1
- package/lib-commonjs/contexts/tableContext.js.map +1 -1
- package/lib-commonjs/contexts/tableHeaderContext.js.map +1 -1
- package/lib-commonjs/hooks/createColumn.js +2 -0
- package/lib-commonjs/hooks/createColumn.js.map +1 -1
- package/lib-commonjs/hooks/useKeyboardResizing.js +1 -1
- package/lib-commonjs/hooks/useKeyboardResizing.js.map +1 -1
- package/lib-commonjs/hooks/useMeasureElement.js.map +1 -1
- package/lib-commonjs/hooks/useTableColumnResizeMouseHandler.js.map +1 -1
- package/lib-commonjs/hooks/useTableColumnSizing.js.map +1 -1
- package/lib-commonjs/hooks/useTableCompositeNavigation.js +7 -1
- package/lib-commonjs/hooks/useTableCompositeNavigation.js.map +1 -1
- package/lib-commonjs/hooks/useTableSelection.js.map +1 -1
- package/lib-commonjs/hooks/useTableSort.js.map +1 -1
- package/lib-commonjs/utils/columnResizeUtils.js +10 -1
- package/lib-commonjs/utils/columnResizeUtils.js.map +1 -1
- package/lib-commonjs/utils/isColumnSortable.js.map +1 -1
- package/package.json +14 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/contexts/tableHeaderContext.ts"],"sourcesContent":["import * as React from 'react';\n\nconst tableHeaderContext = React.createContext<string | undefined>(undefined);\n\nconst tableHeaderContextDefaultValue = '';\n\nexport const TableHeaderContextProvider = tableHeaderContext.Provider;\nexport const useIsInTableHeader = ()
|
|
1
|
+
{"version":3,"sources":["../src/contexts/tableHeaderContext.ts"],"sourcesContent":["import * as React from 'react';\n\nconst tableHeaderContext = React.createContext<string | undefined>(undefined);\n\nconst tableHeaderContextDefaultValue = '';\n\nexport const TableHeaderContextProvider = tableHeaderContext.Provider;\nexport const useIsInTableHeader = (): boolean =>\n React.useContext(tableHeaderContext) === tableHeaderContextDefaultValue;\n"],"names":["React","tableHeaderContext","createContext","undefined","tableHeaderContextDefaultValue","TableHeaderContextProvider","Provider","useIsInTableHeader","useContext"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,MAAMC,qBAAqBD,MAAME,aAAa,CAAqBC;AAEnE,MAAMC,iCAAiC;AAEvC,OAAO,MAAMC,6BAA6BJ,mBAAmBK,QAAQ,CAAC;AACtE,OAAO,MAAMC,qBAAqB,IAChCP,MAAMQ,UAAU,CAACP,wBAAwBG,+BAA+B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/createColumn.ts"],"sourcesContent":["import { CreateTableColumnOptions } from './types';\n\nconst defaultCompare = () => 0;\n\nconst defaultRenderCell = () => {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn('@fluentui/react-table: You are using the default column renderCell function that renders null');\n }\n\n return null;\n};\n\nconst defaultRenderHeaderCell = () => {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn('@fluentui/react-table: You are using the default column renderHeaderCell function that renders null');\n }\n\n return null;\n};\n\n/**\n * Helper function to create column definition with defaults\n * @param options - column definition options\n * @returns - column definition with defaults\n */\nexport function createTableColumn<TItem>(options: CreateTableColumnOptions<TItem>) {\n const {\n columnId,\n renderCell = defaultRenderCell,\n renderHeaderCell = defaultRenderHeaderCell,\n compare = defaultCompare,\n } = options;\n\n return {\n columnId,\n renderCell,\n renderHeaderCell,\n compare,\n };\n}\n"],"names":["defaultCompare","defaultRenderCell","process","env","NODE_ENV","console","warn","defaultRenderHeaderCell","createTableColumn","options","columnId","renderCell","renderHeaderCell","compare"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/hooks/createColumn.ts"],"sourcesContent":["import * as React from 'react';\nimport { CreateTableColumnOptions, TableColumnId } from './types';\n\nconst defaultCompare = () => 0;\n\nconst defaultRenderCell = () => {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn('@fluentui/react-table: You are using the default column renderCell function that renders null');\n }\n\n return null;\n};\n\nconst defaultRenderHeaderCell = () => {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn('@fluentui/react-table: You are using the default column renderHeaderCell function that renders null');\n }\n\n return null;\n};\n\n/**\n * Helper function to create column definition with defaults\n * @param options - column definition options\n * @returns - column definition with defaults\n */\nexport function createTableColumn<TItem>(options: CreateTableColumnOptions<TItem>): {\n columnId: TableColumnId;\n renderCell: (item: TItem) => React.ReactNode;\n renderHeaderCell: (data?: unknown) => React.ReactNode;\n compare: (a: TItem, b: TItem) => number;\n} {\n const {\n columnId,\n renderCell = defaultRenderCell,\n renderHeaderCell = defaultRenderHeaderCell,\n compare = defaultCompare,\n } = options;\n\n return {\n columnId,\n renderCell,\n renderHeaderCell,\n compare,\n };\n}\n"],"names":["React","defaultCompare","defaultRenderCell","process","env","NODE_ENV","console","warn","defaultRenderHeaderCell","createTableColumn","options","columnId","renderCell","renderHeaderCell","compare"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAG/B,MAAMC,iBAAiB,IAAM;AAE7B,MAAMC,oBAAoB;IACxB,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,sCAAsC;QACtCC,QAAQC,IAAI,CAAC;IACf;IAEA,OAAO;AACT;AAEA,MAAMC,0BAA0B;IAC9B,IAAIL,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,sCAAsC;QACtCC,QAAQC,IAAI,CAAC;IACf;IAEA,OAAO;AACT;AAEA;;;;CAIC,GACD,OAAO,SAASE,kBAAyBC,OAAwC;IAM/E,MAAM,EACJC,QAAQ,EACRC,aAAaV,iBAAiB,EAC9BW,mBAAmBL,uBAAuB,EAC1CM,UAAUb,cAAc,EACzB,GAAGS;IAEJ,OAAO;QACLC;QACAC;QACAC;QACAC;IACF;AACF"}
|
|
@@ -7,7 +7,7 @@ const PRECISION_MODIFIER = Shift;
|
|
|
7
7
|
const PRECISION_FACTOR = 1 / 4;
|
|
8
8
|
export function useKeyboardResizing(columnResizeState) {
|
|
9
9
|
const [columnId, setColumnId] = React.useState();
|
|
10
|
-
const onChangeRef = React.useRef();
|
|
10
|
+
const onChangeRef = React.useRef(undefined);
|
|
11
11
|
const { findPrevFocusable } = useFocusFinders();
|
|
12
12
|
const columnResizeStateRef = React.useRef(columnResizeState);
|
|
13
13
|
React.useEffect(()=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useKeyboardResizing.ts"],"sourcesContent":["import * as React from 'react';\nimport { ArrowLeft, ArrowRight, Enter, Escape, Shift, Space } from '@fluentui/keyboard-keys';\nimport { useEventCallback } from '@fluentui/react-utilities';\nimport { ColumnResizeState, EnableKeyboardModeOnChangeCallback, TableColumnId } from './types';\nimport { useFocusFinders, useTabsterAttributes } from '@fluentui/react-tabster';\n\nconst STEP = 20;\nconst PRECISION_MODIFIER = Shift;\nconst PRECISION_FACTOR = 1 / 4;\n\nexport function useKeyboardResizing(columnResizeState: ColumnResizeState) {\n const [columnId, setColumnId] = React.useState<TableColumnId>();\n const onChangeRef = React.useRef<EnableKeyboardModeOnChangeCallback>();\n const { findPrevFocusable } = useFocusFinders();\n\n const columnResizeStateRef = React.useRef<ColumnResizeState>(columnResizeState);\n React.useEffect(() => {\n columnResizeStateRef.current = columnResizeState;\n }, [columnResizeState]);\n\n const [resizeHandleRefs] = React.useState(() => new Map<TableColumnId, React.RefObject<HTMLDivElement>>());\n\n const keyboardHandler = useEventCallback((event: React.KeyboardEvent) => {\n if (!columnId) {\n return;\n }\n\n const width = columnResizeStateRef.current.getColumnWidth(columnId);\n const precisionModifier = event.getModifierState(PRECISION_MODIFIER);\n\n const stopEvent = () => {\n event.preventDefault();\n event.stopPropagation();\n };\n\n switch (event.key) {\n case ArrowLeft:\n stopEvent();\n columnResizeStateRef.current.setColumnWidth(event.nativeEvent, {\n columnId,\n width: width - (precisionModifier ? STEP * PRECISION_FACTOR : STEP),\n });\n return;\n\n case ArrowRight:\n stopEvent();\n columnResizeStateRef.current.setColumnWidth(event.nativeEvent, {\n columnId,\n width: width + (precisionModifier ? STEP * PRECISION_FACTOR : STEP),\n });\n return;\n\n case Space:\n case Enter:\n case Escape:\n stopEvent();\n // Just blur here, the onBlur handler will take care of the rest (disableInteractiveMode).\n resizeHandleRefs.get(columnId)?.current?.blur();\n break;\n }\n });\n\n const enableInteractiveMode = React.useCallback(\n (colId: TableColumnId) => {\n setColumnId(colId);\n onChangeRef.current?.(colId, true);\n\n const handle = resizeHandleRefs.get(colId)?.current;\n if (handle) {\n handle.setAttribute('tabindex', '-1');\n handle.tabIndex = -1;\n handle.focus();\n }\n },\n [resizeHandleRefs],\n );\n\n const disableInteractiveMode = React.useCallback(() => {\n if (!columnId) {\n return;\n }\n // Notify the onChange listener that we are disabling interactive mode.\n onChangeRef.current?.(columnId, false);\n // Find the previous focusable element (table header button) and focus it.\n const el = resizeHandleRefs.get(columnId)?.current;\n if (el) {\n findPrevFocusable(el)?.focus(); // Focus the previous focusable element (header button).\n el.removeAttribute('tabindex');\n }\n\n setColumnId(undefined);\n }, [columnId, findPrevFocusable, resizeHandleRefs]);\n\n const toggleInteractiveMode = (colId: TableColumnId, onChange?: EnableKeyboardModeOnChangeCallback) => {\n onChangeRef.current = onChange;\n if (!columnId) {\n enableInteractiveMode(colId);\n } else if (colId && columnId !== colId) {\n enableInteractiveMode(colId);\n setColumnId(colId);\n } else {\n disableInteractiveMode();\n }\n };\n\n const getKeyboardResizingRef = React.useCallback(\n (colId: TableColumnId) => {\n const ref = resizeHandleRefs.get(colId) || React.createRef<HTMLDivElement>();\n resizeHandleRefs.set(colId, ref);\n return ref;\n },\n [resizeHandleRefs],\n );\n\n // This makes sure the left and right arrow keys are ignored in tabster,\n // so that they can be used for resizing.\n const tabsterAttrs = useTabsterAttributes({\n focusable: {\n ignoreKeydown: {\n ArrowLeft: true,\n ArrowRight: true,\n },\n },\n });\n\n return {\n toggleInteractiveMode,\n columnId,\n getKeyboardResizingProps: React.useCallback(\n (colId: TableColumnId, currentWidth: number) => ({\n onKeyDown: keyboardHandler,\n onBlur: disableInteractiveMode,\n ref: getKeyboardResizingRef(colId)
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useKeyboardResizing.ts"],"sourcesContent":["import * as React from 'react';\nimport { ArrowLeft, ArrowRight, Enter, Escape, Shift, Space } from '@fluentui/keyboard-keys';\nimport { useEventCallback } from '@fluentui/react-utilities';\nimport { ColumnResizeState, EnableKeyboardModeOnChangeCallback, TableColumnId } from './types';\nimport { useFocusFinders, useTabsterAttributes } from '@fluentui/react-tabster';\n\nconst STEP = 20;\nconst PRECISION_MODIFIER = Shift;\nconst PRECISION_FACTOR = 1 / 4;\n\nexport function useKeyboardResizing(columnResizeState: ColumnResizeState): {\n toggleInteractiveMode: (colId: TableColumnId, onChange?: EnableKeyboardModeOnChangeCallback) => void;\n columnId: TableColumnId | undefined;\n getKeyboardResizingProps: (\n colId: TableColumnId,\n currentWidth: number,\n ) => {\n onKeyDown: (event: React.KeyboardEvent) => void;\n onBlur: () => void;\n ref: React.RefObject<HTMLDivElement>;\n role: string;\n 'aria-label': string;\n 'aria-valuetext': string;\n 'aria-hidden': boolean;\n tabIndex?: number;\n };\n} {\n const [columnId, setColumnId] = React.useState<TableColumnId>();\n const onChangeRef = React.useRef<EnableKeyboardModeOnChangeCallback>(undefined);\n const { findPrevFocusable } = useFocusFinders();\n\n const columnResizeStateRef = React.useRef<ColumnResizeState>(columnResizeState);\n React.useEffect(() => {\n columnResizeStateRef.current = columnResizeState;\n }, [columnResizeState]);\n\n const [resizeHandleRefs] = React.useState(() => new Map<TableColumnId, React.RefObject<HTMLDivElement | null>>());\n\n const keyboardHandler = useEventCallback((event: React.KeyboardEvent) => {\n if (!columnId) {\n return;\n }\n\n const width = columnResizeStateRef.current.getColumnWidth(columnId);\n const precisionModifier = event.getModifierState(PRECISION_MODIFIER);\n\n const stopEvent = () => {\n event.preventDefault();\n event.stopPropagation();\n };\n\n switch (event.key) {\n case ArrowLeft:\n stopEvent();\n columnResizeStateRef.current.setColumnWidth(event.nativeEvent, {\n columnId,\n width: width - (precisionModifier ? STEP * PRECISION_FACTOR : STEP),\n });\n return;\n\n case ArrowRight:\n stopEvent();\n columnResizeStateRef.current.setColumnWidth(event.nativeEvent, {\n columnId,\n width: width + (precisionModifier ? STEP * PRECISION_FACTOR : STEP),\n });\n return;\n\n case Space:\n case Enter:\n case Escape:\n stopEvent();\n // Just blur here, the onBlur handler will take care of the rest (disableInteractiveMode).\n resizeHandleRefs.get(columnId)?.current?.blur();\n break;\n }\n });\n\n const enableInteractiveMode = React.useCallback(\n (colId: TableColumnId) => {\n setColumnId(colId);\n onChangeRef.current?.(colId, true);\n\n const handle = resizeHandleRefs.get(colId)?.current;\n if (handle) {\n handle.setAttribute('tabindex', '-1');\n handle.tabIndex = -1;\n handle.focus();\n }\n },\n [resizeHandleRefs],\n );\n\n const disableInteractiveMode = React.useCallback(() => {\n if (!columnId) {\n return;\n }\n // Notify the onChange listener that we are disabling interactive mode.\n onChangeRef.current?.(columnId, false);\n // Find the previous focusable element (table header button) and focus it.\n const el = resizeHandleRefs.get(columnId)?.current;\n if (el) {\n findPrevFocusable(el)?.focus(); // Focus the previous focusable element (header button).\n el.removeAttribute('tabindex');\n }\n\n setColumnId(undefined);\n }, [columnId, findPrevFocusable, resizeHandleRefs]);\n\n const toggleInteractiveMode = (colId: TableColumnId, onChange?: EnableKeyboardModeOnChangeCallback) => {\n onChangeRef.current = onChange;\n if (!columnId) {\n enableInteractiveMode(colId);\n } else if (colId && columnId !== colId) {\n enableInteractiveMode(colId);\n setColumnId(colId);\n } else {\n disableInteractiveMode();\n }\n };\n\n const getKeyboardResizingRef = React.useCallback(\n (colId: TableColumnId) => {\n const ref = resizeHandleRefs.get(colId) || React.createRef<HTMLDivElement>();\n resizeHandleRefs.set(colId, ref);\n return ref;\n },\n [resizeHandleRefs],\n );\n\n // This makes sure the left and right arrow keys are ignored in tabster,\n // so that they can be used for resizing.\n const tabsterAttrs = useTabsterAttributes({\n focusable: {\n ignoreKeydown: {\n ArrowLeft: true,\n ArrowRight: true,\n },\n },\n });\n\n return {\n toggleInteractiveMode,\n columnId,\n getKeyboardResizingProps: React.useCallback(\n (colId: TableColumnId, currentWidth: number) => ({\n onKeyDown: keyboardHandler,\n onBlur: disableInteractiveMode,\n ref: getKeyboardResizingRef(colId) as React.RefObject<HTMLDivElement>,\n role: 'separator',\n 'aria-label': 'Resize column',\n 'aria-valuetext': `${currentWidth} pixels`,\n 'aria-hidden': colId === columnId ? false : true,\n tabIndex: colId === columnId ? 0 : undefined,\n ...tabsterAttrs,\n }),\n [columnId, disableInteractiveMode, getKeyboardResizingRef, keyboardHandler, tabsterAttrs],\n ),\n };\n}\n"],"names":["React","ArrowLeft","ArrowRight","Enter","Escape","Shift","Space","useEventCallback","useFocusFinders","useTabsterAttributes","STEP","PRECISION_MODIFIER","PRECISION_FACTOR","useKeyboardResizing","columnResizeState","columnId","setColumnId","useState","onChangeRef","useRef","undefined","findPrevFocusable","columnResizeStateRef","useEffect","current","resizeHandleRefs","Map","keyboardHandler","event","width","getColumnWidth","precisionModifier","getModifierState","stopEvent","preventDefault","stopPropagation","key","setColumnWidth","nativeEvent","get","blur","enableInteractiveMode","useCallback","colId","handle","setAttribute","tabIndex","focus","disableInteractiveMode","el","removeAttribute","toggleInteractiveMode","onChange","getKeyboardResizingRef","ref","createRef","set","tabsterAttrs","focusable","ignoreKeydown","getKeyboardResizingProps","currentWidth","onKeyDown","onBlur","role"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,SAAS,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,KAAK,EAAEC,KAAK,QAAQ,0BAA0B;AAC7F,SAASC,gBAAgB,QAAQ,4BAA4B;AAE7D,SAASC,eAAe,EAAEC,oBAAoB,QAAQ,0BAA0B;AAEhF,MAAMC,OAAO;AACb,MAAMC,qBAAqBN;AAC3B,MAAMO,mBAAmB,IAAI;AAE7B,OAAO,SAASC,oBAAoBC,iBAAoC;IAiBtE,MAAM,CAACC,UAAUC,YAAY,GAAGhB,MAAMiB,QAAQ;IAC9C,MAAMC,cAAclB,MAAMmB,MAAM,CAAqCC;IACrE,MAAM,EAAEC,iBAAiB,EAAE,GAAGb;IAE9B,MAAMc,uBAAuBtB,MAAMmB,MAAM,CAAoBL;IAC7Dd,MAAMuB,SAAS,CAAC;QACdD,qBAAqBE,OAAO,GAAGV;IACjC,GAAG;QAACA;KAAkB;IAEtB,MAAM,CAACW,iBAAiB,GAAGzB,MAAMiB,QAAQ,CAAC,IAAM,IAAIS;IAEpD,MAAMC,kBAAkBpB,iBAAiB,CAACqB;QACxC,IAAI,CAACb,UAAU;YACb;QACF;QAEA,MAAMc,QAAQP,qBAAqBE,OAAO,CAACM,cAAc,CAACf;QAC1D,MAAMgB,oBAAoBH,MAAMI,gBAAgB,CAACrB;QAEjD,MAAMsB,YAAY;YAChBL,MAAMM,cAAc;YACpBN,MAAMO,eAAe;QACvB;QAEA,OAAQP,MAAMQ,GAAG;YACf,KAAKnC;gBACHgC;gBACAX,qBAAqBE,OAAO,CAACa,cAAc,CAACT,MAAMU,WAAW,EAAE;oBAC7DvB;oBACAc,OAAOA,QAASE,C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AlC,YAAYI;IACd,GAAG;QAACL;QAAUM;QAAmBI;KAAiB;IAElD,MAAM0B,wBAAwB,CAACR,OAAsBS;QACnDlC,YAAYM,OAAO,GAAG4B;QACtB,IAAI,CAACrC,UAAU;YACb0B,sBAAsBE;QACxB,OAAO,IAAIA,SAAS5B,aAAa4B,OAAO;YACtCF,sBAAsBE;YACtB3B,YAAY2B;QACd,OAAO;YACLK;QACF;IACF;IAEA,MAAMK,yBAAyBrD,MAAM0C,WAAW,CAC9C,CAACC;QACC,MAAMW,MAAM7B,iBAAiBc,GAAG,CAACI,UAAU3C,MAAMuD,SAAS;QAC1D9B,iBAAiB+B,GAAG,CAACb,OAAOW;QAC5B,OAAOA;IACT,GACA;QAAC7B;KAAiB;IAGpB,wEAAwE;IACxE,yCAAyC;IACzC,MAAMgC,eAAehD,qBAAqB;QACxCiD,WAAW;YACTC,eAAe;gBACb1D,WAAW;gBACXC,YAAY;YACd;QACF;IACF;IAEA,OAAO;QACLiD;QACApC;QACA6C,0BAA0B5D,MAAM0C,WAAW,CACzC,CAACC,OAAsBkB,eAA0B,CAAA;gBAC/CC,WAAWnC;gBACXoC,QAAQf;gBACRM,KAAKD,uBAAuBV;gBAC5BqB,MAAM;gBACN,cAAc;gBACd,kBAAkB,GAAGH,aAAa,OAAO,CAAC;gBAC1C,eAAelB,UAAU5B,WAAW,QAAQ;gBAC5C+B,UAAUH,UAAU5B,WAAW,IAAIK;gBACnC,GAAGqC,YAAY;YACjB,CAAA,GACA;YAAC1C;YAAUiC;YAAwBK;YAAwB1B;YAAiB8B;SAAa;IAE7F;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useMeasureElement.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\n/**\n * Provides a way of reporting element width.\n * Returns\n * `width` - current element width (0 by default),\n * `measureElementRef` - a ref function to be passed as `ref` to the element you want to measure\n */\nexport function useMeasureElement<TElement extends HTMLElement = HTMLElement>() {\n const [width, setWidth] = React.useState(0);\n\n const container = React.useRef<HTMLElement | undefined>(undefined);\n\n const resizeObserverRef = React.useRef<ResizeObserver | null>(null);\n\n const { targetDocument } = useFluent();\n\n // the handler for resize observer\n const handleResize = React.useCallback(() => {\n const containerWidth = container.current?.getBoundingClientRect().width;\n setWidth(containerWidth || 0);\n }, []);\n\n const measureElementRef = React.useCallback(\n (el: TElement | null) => {\n if (!targetDocument) {\n return;\n }\n\n // if the element is removed, stop observing it\n if (!el && resizeObserverRef.current && container.current) {\n resizeObserverRef.current.unobserve(container.current);\n }\n\n container.current = undefined;\n\n if (el?.parentElement) {\n container.current = el.parentElement;\n handleResize();\n resizeObserverRef.current?.observe(container.current);\n }\n },\n [targetDocument, handleResize],\n );\n\n React.useEffect(() => {\n resizeObserverRef.current = createResizeObserverFromDocument(targetDocument, handleResize);\n\n if (!container.current || !resizeObserverRef.current) {\n return;\n }\n\n resizeObserverRef.current.observe(container.current);\n\n return () => {\n resizeObserverRef.current?.disconnect();\n };\n }, [handleResize, targetDocument]);\n\n return { width, measureElementRef };\n}\n\n/**\n * FIXME - TS 3.8/3.9 don't have ResizeObserver types by default, move this to a shared utility once we bump the minbar\n * A utility method that creates a ResizeObserver from a target document\n * @param targetDocument - document to use to create the ResizeObserver\n * @param callback - https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback\n * @returns a ResizeObserver instance or null if the global does not exist on the document\n */\nexport function createResizeObserverFromDocument(\n targetDocument: Document | null | undefined,\n callback: ResizeObserverCallback,\n) {\n if (!targetDocument?.defaultView?.ResizeObserver) {\n return null;\n }\n\n return new targetDocument.defaultView.ResizeObserver(callback);\n}\n"],"names":["React","useFluent_unstable","useFluent","useMeasureElement","width","setWidth","useState","container","useRef","undefined","resizeObserverRef","targetDocument","handleResize","useCallback","containerWidth","current","getBoundingClientRect","measureElementRef","el","unobserve","parentElement","observe","useEffect","createResizeObserverFromDocument","disconnect","callback","defaultView","ResizeObserver"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAElF;;;;;CAKC,GACD,OAAO,SAASC;
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useMeasureElement.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\n/**\n * Provides a way of reporting element width.\n * Returns\n * `width` - current element width (0 by default),\n * `measureElementRef` - a ref function to be passed as `ref` to the element you want to measure\n */\nexport function useMeasureElement<TElement extends HTMLElement = HTMLElement>(): {\n width: number;\n measureElementRef: (el: TElement | null) => void;\n} {\n const [width, setWidth] = React.useState(0);\n\n const container = React.useRef<HTMLElement | undefined>(undefined);\n\n const resizeObserverRef = React.useRef<ResizeObserver | null>(null);\n\n const { targetDocument } = useFluent();\n\n // the handler for resize observer\n const handleResize = React.useCallback(() => {\n const containerWidth = container.current?.getBoundingClientRect().width;\n setWidth(containerWidth || 0);\n }, []);\n\n const measureElementRef = React.useCallback(\n (el: TElement | null) => {\n if (!targetDocument) {\n return;\n }\n\n // if the element is removed, stop observing it\n if (!el && resizeObserverRef.current && container.current) {\n resizeObserverRef.current.unobserve(container.current);\n }\n\n container.current = undefined;\n\n if (el?.parentElement) {\n container.current = el.parentElement;\n handleResize();\n resizeObserverRef.current?.observe(container.current);\n }\n },\n [targetDocument, handleResize],\n );\n\n React.useEffect(() => {\n resizeObserverRef.current = createResizeObserverFromDocument(targetDocument, handleResize);\n\n if (!container.current || !resizeObserverRef.current) {\n return;\n }\n\n resizeObserverRef.current.observe(container.current);\n\n return () => {\n resizeObserverRef.current?.disconnect();\n };\n }, [handleResize, targetDocument]);\n\n return { width, measureElementRef };\n}\n\n/**\n * FIXME - TS 3.8/3.9 don't have ResizeObserver types by default, move this to a shared utility once we bump the minbar\n * A utility method that creates a ResizeObserver from a target document\n * @param targetDocument - document to use to create the ResizeObserver\n * @param callback - https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback\n * @returns a ResizeObserver instance or null if the global does not exist on the document\n */\nexport function createResizeObserverFromDocument(\n targetDocument: Document | null | undefined,\n callback: ResizeObserverCallback,\n): ResizeObserver | null {\n if (!targetDocument?.defaultView?.ResizeObserver) {\n return null;\n }\n\n return new targetDocument.defaultView.ResizeObserver(callback);\n}\n"],"names":["React","useFluent_unstable","useFluent","useMeasureElement","width","setWidth","useState","container","useRef","undefined","resizeObserverRef","targetDocument","handleResize","useCallback","containerWidth","current","getBoundingClientRect","measureElementRef","el","unobserve","parentElement","observe","useEffect","createResizeObserverFromDocument","disconnect","callback","defaultView","ResizeObserver"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAElF;;;;;CAKC,GACD,OAAO,SAASC;IAId,MAAM,CAACC,OAAOC,SAAS,GAAGL,MAAMM,QAAQ,CAAC;IAEzC,MAAMC,YAAYP,MAAMQ,MAAM,CAA0BC;IAExD,MAAMC,oBAAoBV,MAAMQ,MAAM,CAAwB;IAE9D,MAAM,EAAEG,cAAc,EAAE,GAAGT;IAE3B,kCAAkC;IAClC,MAAMU,eAAeZ,MAAMa,WAAW,CAAC;YACdN;QAAvB,MAAMO,kBAAiBP,qBAAAA,UAAUQ,OAAO,cAAjBR,yCAAAA,mBAAmBS,qBAAqB,GAAGZ,KAAK;QACvEC,SAASS,kBAAkB;IAC7B,GAAG,EAAE;IAEL,MAAMG,oBAAoBjB,MAAMa,WAAW,CACzC,CAACK;QACC,IAAI,CAACP,gBAAgB;YACnB;QACF;QAEA,+CAA+C;QAC/C,IAAI,CAACO,MAAMR,kBAAkBK,OAAO,IAAIR,UAAUQ,OAAO,EAAE;YACzDL,kBAAkBK,OAAO,CAACI,SAAS,CAACZ,UAAUQ,OAAO;QACvD;QAEAR,UAAUQ,OAAO,GAAGN;QAEpB,IAAIS,eAAAA,yBAAAA,GAAIE,aAAa,EAAE;gBAGrBV;YAFAH,UAAUQ,OAAO,GAAGG,GAAGE,aAAa;YACpCR;aACAF,6BAAAA,kBAAkBK,OAAO,cAAzBL,iDAAAA,2BAA2BW,OAAO,CAACd,UAAUQ,OAAO;QACtD;IACF,GACA;QAACJ;QAAgBC;KAAa;IAGhCZ,MAAMsB,SAAS,CAAC;QACdZ,kBAAkBK,OAAO,GAAGQ,iCAAiCZ,gBAAgBC;QAE7E,IAAI,CAACL,UAAUQ,OAAO,IAAI,CAACL,kBAAkBK,OAAO,EAAE;YACpD;QACF;QAEAL,kBAAkBK,OAAO,CAACM,OAAO,CAACd,UAAUQ,OAAO;QAEnD,OAAO;gBACLL;aAAAA,6BAAAA,kBAAkBK,OAAO,cAAzBL,iDAAAA,2BAA2Bc,UAAU;QACvC;IACF,GAAG;QAACZ;QAAcD;KAAe;IAEjC,OAAO;QAAEP;QAAOa;IAAkB;AACpC;AAEA;;;;;;CAMC,GACD,OAAO,SAASM,iCACdZ,cAA2C,EAC3Cc,QAAgC;QAE3Bd;IAAL,IAAI,EAACA,2BAAAA,sCAAAA,8BAAAA,eAAgBe,WAAW,cAA3Bf,kDAAAA,4BAA6BgB,cAAc,GAAE;QAChD,OAAO;IACT;IAEA,OAAO,IAAIhB,eAAee,WAAW,CAACC,cAAc,CAACF;AACvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useTableColumnResizeMouseHandler.ts"],"sourcesContent":["import * as React from 'react';\nimport { TableColumnId, ColumnResizeState } from './types';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport {\n NativeTouchOrMouseEvent,\n ReactTouchOrMouseEvent,\n getEventClientCoords,\n isMouseEvent,\n isTouchEvent,\n useAnimationFrame,\n} from '@fluentui/react-utilities';\n\nexport function useTableColumnResizeMouseHandler(columnResizeState: ColumnResizeState) {\n const mouseX = React.useRef(0);\n const currentWidth = React.useRef(0);\n const colId = React.useRef<TableColumnId | undefined>(undefined);\n const [dragging, setDragging] = React.useState<boolean>(false);\n\n const { targetDocument } = useFluent();\n\n const { getColumnWidth, setColumnWidth } = columnResizeState;\n\n const recalculatePosition = React.useCallback(\n (e: NativeTouchOrMouseEvent) => {\n const { clientX } = getEventClientCoords(e);\n const dx = clientX - mouseX.current;\n\n // Update the local width for the column and set it\n currentWidth.current += dx;\n colId.current && setColumnWidth(e, { columnId: colId.current, width: currentWidth.current });\n mouseX.current = clientX;\n },\n [setColumnWidth],\n );\n\n const [requestRecalcFrame] = useAnimationFrame();\n\n const onDrag = React.useCallback(\n (e: NativeTouchOrMouseEvent) => {\n // Using requestAnimationFrame here drastically improves resizing experience on slower CPUs\n requestRecalcFrame(() => recalculatePosition(e));\n },\n [requestRecalcFrame, recalculatePosition],\n );\n\n const onDragEnd = React.useCallback(\n (event: NativeTouchOrMouseEvent) => {\n if (isMouseEvent(event)) {\n targetDocument?.removeEventListener('mouseup', onDragEnd);\n targetDocument?.removeEventListener('mousemove', onDrag);\n }\n if (isTouchEvent(event)) {\n targetDocument?.removeEventListener('touchend', onDragEnd);\n targetDocument?.removeEventListener('touchmove', onDrag);\n }\n setDragging(false);\n },\n [onDrag, targetDocument],\n );\n\n const getOnMouseDown = React.useCallback(\n (columnId: TableColumnId) => (event: ReactTouchOrMouseEvent) => {\n // Keep the width locally so that we decouple the calculation of the next with from rendering.\n // This makes the whole experience much faster and more precise\n currentWidth.current = getColumnWidth(columnId);\n mouseX.current = getEventClientCoords(event).clientX;\n colId.current = columnId;\n\n if (isMouseEvent(event)) {\n // ignore other buttons than primary mouse button\n if (event.target !== event.currentTarget || event.button !== 0) {\n return;\n }\n targetDocument?.addEventListener('mouseup', onDragEnd);\n targetDocument?.addEventListener('mousemove', onDrag);\n setDragging(true);\n }\n\n if (isTouchEvent(event)) {\n targetDocument?.addEventListener('touchend', onDragEnd);\n targetDocument?.addEventListener('touchmove', onDrag);\n setDragging(true);\n }\n },\n [getColumnWidth, onDrag, onDragEnd, targetDocument],\n );\n\n return {\n getOnMouseDown,\n dragging,\n };\n}\n"],"names":["React","useFluent_unstable","useFluent","getEventClientCoords","isMouseEvent","isTouchEvent","useAnimationFrame","useTableColumnResizeMouseHandler","columnResizeState","mouseX","useRef","currentWidth","colId","undefined","dragging","setDragging","useState","targetDocument","getColumnWidth","setColumnWidth","recalculatePosition","useCallback","e","clientX","dx","current","columnId","width","requestRecalcFrame","onDrag","onDragEnd","event","removeEventListener","getOnMouseDown","target","currentTarget","button","addEventListener"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAGEC,oBAAoB,EACpBC,YAAY,EACZC,YAAY,EACZC,iBAAiB,QACZ,4BAA4B;AAEnC,OAAO,SAASC,iCAAiCC,iBAAoC;
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useTableColumnResizeMouseHandler.ts"],"sourcesContent":["import * as React from 'react';\nimport { TableColumnId, ColumnResizeState } from './types';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport {\n NativeTouchOrMouseEvent,\n ReactTouchOrMouseEvent,\n getEventClientCoords,\n isMouseEvent,\n isTouchEvent,\n useAnimationFrame,\n} from '@fluentui/react-utilities';\n\nexport function useTableColumnResizeMouseHandler(columnResizeState: ColumnResizeState): {\n getOnMouseDown: (columnId: TableColumnId) => (event: ReactTouchOrMouseEvent) => void;\n dragging: boolean;\n} {\n const mouseX = React.useRef(0);\n const currentWidth = React.useRef(0);\n const colId = React.useRef<TableColumnId | undefined>(undefined);\n const [dragging, setDragging] = React.useState<boolean>(false);\n\n const { targetDocument } = useFluent();\n\n const { getColumnWidth, setColumnWidth } = columnResizeState;\n\n const recalculatePosition = React.useCallback(\n (e: NativeTouchOrMouseEvent) => {\n const { clientX } = getEventClientCoords(e);\n const dx = clientX - mouseX.current;\n\n // Update the local width for the column and set it\n currentWidth.current += dx;\n colId.current && setColumnWidth(e, { columnId: colId.current, width: currentWidth.current });\n mouseX.current = clientX;\n },\n [setColumnWidth],\n );\n\n const [requestRecalcFrame] = useAnimationFrame();\n\n const onDrag = React.useCallback(\n (e: NativeTouchOrMouseEvent) => {\n // Using requestAnimationFrame here drastically improves resizing experience on slower CPUs\n requestRecalcFrame(() => recalculatePosition(e));\n },\n [requestRecalcFrame, recalculatePosition],\n );\n\n const onDragEnd = React.useCallback(\n (event: NativeTouchOrMouseEvent) => {\n if (isMouseEvent(event)) {\n targetDocument?.removeEventListener('mouseup', onDragEnd);\n targetDocument?.removeEventListener('mousemove', onDrag);\n }\n if (isTouchEvent(event)) {\n targetDocument?.removeEventListener('touchend', onDragEnd);\n targetDocument?.removeEventListener('touchmove', onDrag);\n }\n setDragging(false);\n },\n [onDrag, targetDocument],\n );\n\n const getOnMouseDown = React.useCallback(\n (columnId: TableColumnId) => (event: ReactTouchOrMouseEvent) => {\n // Keep the width locally so that we decouple the calculation of the next with from rendering.\n // This makes the whole experience much faster and more precise\n currentWidth.current = getColumnWidth(columnId);\n mouseX.current = getEventClientCoords(event).clientX;\n colId.current = columnId;\n\n if (isMouseEvent(event)) {\n // ignore other buttons than primary mouse button\n if (event.target !== event.currentTarget || event.button !== 0) {\n return;\n }\n targetDocument?.addEventListener('mouseup', onDragEnd);\n targetDocument?.addEventListener('mousemove', onDrag);\n setDragging(true);\n }\n\n if (isTouchEvent(event)) {\n targetDocument?.addEventListener('touchend', onDragEnd);\n targetDocument?.addEventListener('touchmove', onDrag);\n setDragging(true);\n }\n },\n [getColumnWidth, onDrag, onDragEnd, targetDocument],\n );\n\n return {\n getOnMouseDown,\n dragging,\n };\n}\n"],"names":["React","useFluent_unstable","useFluent","getEventClientCoords","isMouseEvent","isTouchEvent","useAnimationFrame","useTableColumnResizeMouseHandler","columnResizeState","mouseX","useRef","currentWidth","colId","undefined","dragging","setDragging","useState","targetDocument","getColumnWidth","setColumnWidth","recalculatePosition","useCallback","e","clientX","dx","current","columnId","width","requestRecalcFrame","onDrag","onDragEnd","event","removeEventListener","getOnMouseDown","target","currentTarget","button","addEvent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AgBe,mBAAmB,CAAC,YAAYF;YAChDb,2BAAAA,qCAAAA,eAAgBe,mBAAmB,CAAC,aAAaH;QACnD;QACAd,YAAY;IACd,GACA;QAACc;QAAQZ;KAAe;IAG1B,MAAMgB,iBAAiBjC,MAAMqB,WAAW,CACtC,CAACK,WAA4B,CAACK;YAC5B,8FAA8F;YAC9F,+DAA+D;YAC/DpB,aAAac,OAAO,GAAGP,eAAeQ;YACtCjB,OAAOgB,OAAO,GAAGtB,qBAAqB4B,OAAOR,OAAO;YACpDX,MAAMa,OAAO,GAAGC;YAEhB,IAAItB,aAAa2B,QAAQ;gBACvB,iDAAiD;gBACjD,IAAIA,MAAMG,MAAM,KAAKH,MAAMI,aAAa,IAAIJ,MAAMK,MAAM,KAAK,GAAG;oBAC9D;gBACF;gBACAnB,2BAAAA,qCAAAA,eAAgBoB,gBAAgB,CAAC,WAAWP;gBAC5Cb,2BAAAA,qCAAAA,eAAgBoB,gBAAgB,CAAC,aAAaR;gBAC9Cd,YAAY;YACd;YAEA,IAAIV,aAAa0B,QAAQ;gBACvBd,2BAAAA,qCAAAA,eAAgBoB,gBAAgB,CAAC,YAAYP;gBAC7Cb,2BAAAA,qCAAAA,eAAgBoB,gBAAgB,CAAC,aAAaR;gBAC9Cd,YAAY;YACd;QACF,GACA;QAACG;QAAgBW;QAAQC;QAAWb;KAAe;IAGrD,OAAO;QACLgB;QACAnB;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useTableColumnSizing.tsx"],"sourcesContent":["import * as React from 'react';\nimport { TableResizeHandle } from '../TableResizeHandle';\nimport {\n ColumnWidthState,\n EnableKeyboardModeOnChangeCallback,\n TableColumnId,\n TableColumnSizingState,\n TableFeaturesState,\n UseTableColumnSizingParams,\n} from './types';\n\nimport { useMeasureElement } from './useMeasureElement';\nimport { useTableColumnResizeMouseHandler } from './useTableColumnResizeMouseHandler';\nimport { useTableColumnResizeState } from './useTableColumnResizeState';\nimport { useKeyboardResizing } from './useKeyboardResizing';\n\nexport const defaultColumnSizingState: TableColumnSizingState = {\n getColumnWidths: () => [],\n getOnMouseDown: () => () => null,\n setColumnWidth: () => null,\n getTableProps: () => ({}),\n getTableHeaderCellProps: () => ({ style: {}, columnId: '' }),\n getTableCellProps: () => ({ style: {}, columnId: '' }),\n enableKeyboardMode: () => () => null,\n};\n\nexport function useTableColumnSizing_unstable<TItem>(params?: UseTableColumnSizingParams) {\n 'use no memo';\n\n // False positive, these plugin hooks are intended to be run on every render\n\n return (tableState: TableFeaturesState<TItem>) =>\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useTableColumnSizingState(tableState, { autoFitColumns: true, ...params });\n}\n\nfunction getColumnStyles(column: ColumnWidthState, dragging?: boolean): React.CSSProperties {\n const width = column.width;\n\n return {\n // native styles\n width,\n // non-native element styles (flex layout)\n minWidth: width,\n maxWidth: width,\n // Fixed the unwanted sort: https://github.com/microsoft/fluentui/issues/27803\n ...(dragging ? { pointerEvents: 'none' } : {}),\n };\n}\n\nfunction useTableColumnSizingState<TItem>(\n tableState: TableFeaturesState<TItem>,\n params: UseTableColumnSizingParams = {},\n): TableFeaturesState<TItem> {\n const { columns } = tableState;\n\n // Gets the container width\n const { width, measureElementRef } = useMeasureElement();\n // Creates the state based on columns and available containerWidth\n const columnResizeState = useTableColumnResizeState(columns, width + (params?.containerWidthOffset || 0), params);\n // Creates the mouse handler and attaches the state to it\n const mouseHandler = useTableColumnResizeMouseHandler(columnResizeState);\n // Creates the keyboard handler for resizing columns\n const { toggleInteractiveMode, getKeyboardResizingProps } = useKeyboardResizing(columnResizeState);\n\n const { autoFitColumns } = params;\n\n const enableKeyboardMode = React.useCallback(\n (columnId: TableColumnId, onChange?: EnableKeyboardModeOnChangeCallback) =>\n (e: React.MouseEvent | React.TouchEvent) => {\n e.preventDefault();\n e.nativeEvent.stopPropagation();\n toggleInteractiveMode(columnId, onChange);\n },\n [toggleInteractiveMode],\n );\n\n const { getColumnById, setColumnWidth, getColumns } = columnResizeState;\n const { getOnMouseDown, dragging } = mouseHandler;\n return {\n ...tableState,\n tableRef: measureElementRef,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n columnSizing_unstable: {\n getOnMouseDown,\n setColumnWidth: (columnId: TableColumnId, w: number) => setColumnWidth(undefined, { columnId, width: w }),\n getColumnWidths: getColumns,\n getTableProps: (props = {}) => {\n return {\n ...props,\n style: {\n minWidth: 'fit-content',\n ...(props.style || {}),\n },\n };\n },\n getTableHeaderCellProps: React.useCallback(\n (columnId: TableColumnId) => {\n const col = getColumnById(columnId);\n const isLastColumn = columns[columns.length - 1]?.columnId === columnId;\n\n const aside =\n isLastColumn && autoFitColumns ? null : (\n <TableResizeHandle\n onMouseDown={getOnMouseDown(columnId)}\n onTouchStart={getOnMouseDown(columnId)}\n {...getKeyboardResizingProps(columnId, col?.width || 0)}\n />\n );\n\n return col\n ? {\n style: getColumnStyles(col, dragging),\n aside,\n }\n : {};\n },\n [getColumnById, columns, dragging, getKeyboardResizingProps, getOnMouseDown, autoFitColumns],\n ),\n getTableCellProps: React.useCallback(\n (columnId: TableColumnId) => {\n const col = getColumnById(columnId);\n return col ? { style: getColumnStyles(col) } : {};\n },\n [getColumnById],\n ),\n enableKeyboardMode,\n },\n };\n}\n"],"names":["React","TableResizeHandle","useMeasureElement","useTableColumnResizeMouseHandler","useTableColumnResizeState","useKeyboardResizing","defaultColumnSizingState","getColumnWidths","getOnMouseDown","setColumnWidth","getTableProps","getTableHeaderCellProps","style","columnId","getTableCellProps","enableKeyboardMode","useTableColumnSizing_unstable","params","tableState","useTableColumnSizingState","autoFitColumns","getColumnStyles","column","dragging","width","minWidth","maxWidth","pointerEvents","columns","measureElementRef","columnResizeState","containerWidthOffset","mouseHandler","toggleInteractiveMode","getKeyboardResizingProps","useCallback","onChange","e","preventDefault","nativeEvent","stopPropagation","getColumnById","getColumns","tableRef","columnSizing_unstable","w","undefined","props","col","isLastColumn","length","aside","onMouseDown","onTouchStart"],"mappings":"AA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OwB,MACH;oBACEpC,OAAOS,gBAAgB2B,KAAKzB;oBAC5B4B;gBACF,IACA,CAAC;YACP,GACA;gBAACV;gBAAeb;gBAASL;gBAAUW;gBAA0B1B;gBAAgBY;aAAe;YAE9FN,mBAAmBd,MAAMmC,WAAW,CAClC,CAACtB;gBACC,MAAMmC,MAAMP,cAAc5B;gBAC1B,OAAOmC,MAAM;oBAAEpC,OAAOS,gBAAgB2B;gBAAK,IAAI,CAAC;YAClD,GACA;gBAACP;aAAc;YAEjB1B;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useTableColumnSizing.tsx"],"sourcesContent":["import * as React from 'react';\nimport { TableResizeHandle } from '../TableResizeHandle';\nimport {\n ColumnWidthState,\n EnableKeyboardModeOnChangeCallback,\n TableColumnId,\n TableColumnSizingState,\n TableFeaturesState,\n UseTableColumnSizingParams,\n} from './types';\n\nimport { useMeasureElement } from './useMeasureElement';\nimport { useTableColumnResizeMouseHandler } from './useTableColumnResizeMouseHandler';\nimport { useTableColumnResizeState } from './useTableColumnResizeState';\nimport { useKeyboardResizing } from './useKeyboardResizing';\n\nexport const defaultColumnSizingState: TableColumnSizingState = {\n getColumnWidths: () => [],\n getOnMouseDown: () => () => null,\n setColumnWidth: () => null,\n getTableProps: () => ({}),\n getTableHeaderCellProps: () => ({ style: {}, columnId: '' }),\n getTableCellProps: () => ({ style: {}, columnId: '' }),\n enableKeyboardMode: () => () => null,\n};\n\nexport function useTableColumnSizing_unstable<TItem>(params?: UseTableColumnSizingParams) {\n 'use no memo';\n\n // False positive, these plugin hooks are intended to be run on every render\n\n return (tableState: TableFeaturesState<TItem>): TableFeaturesState<TItem> =>\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useTableColumnSizingState(tableState, { autoFitColumns: true, ...params });\n}\n\nfunction getColumnStyles(column: ColumnWidthState, dragging?: boolean): React.CSSProperties {\n const width = column.width;\n\n return {\n // native styles\n width,\n // non-native element styles (flex layout)\n minWidth: width,\n maxWidth: width,\n // Fixed the unwanted sort: https://github.com/microsoft/fluentui/issues/27803\n ...(dragging ? { pointerEvents: 'none' } : {}),\n };\n}\n\nfunction useTableColumnSizingState<TItem>(\n tableState: TableFeaturesState<TItem>,\n params: UseTableColumnSizingParams = {},\n): TableFeaturesState<TItem> {\n const { columns } = tableState;\n\n // Gets the container width\n const { width, measureElementRef } = useMeasureElement();\n // Creates the state based on columns and available containerWidth\n const columnResizeState = useTableColumnResizeState(columns, width + (params?.containerWidthOffset || 0), params);\n // Creates the mouse handler and attaches the state to it\n const mouseHandler = useTableColumnResizeMouseHandler(columnResizeState);\n // Creates the keyboard handler for resizing columns\n const { toggleInteractiveMode, getKeyboardResizingProps } = useKeyboardResizing(columnResizeState);\n\n const { autoFitColumns } = params;\n\n const enableKeyboardMode = React.useCallback(\n (columnId: TableColumnId, onChange?: EnableKeyboardModeOnChangeCallback) =>\n (e: React.MouseEvent | React.TouchEvent) => {\n e.preventDefault();\n e.nativeEvent.stopPropagation();\n toggleInteractiveMode(columnId, onChange);\n },\n [toggleInteractiveMode],\n );\n\n const { getColumnById, setColumnWidth, getColumns } = columnResizeState;\n const { getOnMouseDown, dragging } = mouseHandler;\n return {\n ...tableState,\n tableRef: measureElementRef,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n columnSizing_unstable: {\n getOnMouseDown,\n setColumnWidth: (columnId: TableColumnId, w: number) => setColumnWidth(undefined, { columnId, width: w }),\n getColumnWidths: getColumns,\n getTableProps: (props = {}) => {\n return {\n ...props,\n style: {\n minWidth: 'fit-content',\n ...(props.style || {}),\n },\n };\n },\n getTableHeaderCellProps: React.useCallback(\n (columnId: TableColumnId) => {\n const col = getColumnById(columnId);\n const isLastColumn = columns[columns.length - 1]?.columnId === columnId;\n\n const aside =\n isLastColumn && autoFitColumns ? null : (\n <TableResizeHandle\n onMouseDown={getOnMouseDown(columnId)}\n onTouchStart={getOnMouseDown(columnId)}\n {...getKeyboardResizingProps(columnId, col?.width || 0)}\n />\n );\n\n return col\n ? {\n style: getColumnStyles(col, dragging),\n aside,\n }\n : {};\n },\n [getColumnById, columns, dragging, getKeyboardResizingProps, getOnMouseDown, autoFitColumns],\n ),\n getTableCellProps: React.useCallback(\n (columnId: TableColumnId) => {\n const col = getColumnById(columnId);\n return col ? { style: getColumnStyles(col) } : {};\n },\n [getColumnById],\n ),\n enableKeyboardMode,\n },\n };\n}\n"],"names":["React","TableResizeHandle","useMeasureElement","useTableColumnResizeMouseHandler","useTableColumnResizeState","useKeyboardResizing","defaultColumnSizingState","getColumnWidths","getOnMouseDown","setColumnWidth","getTableProps","getTableHeaderCellProps","style","columnId","getTableCellProps","enableKeyboardMode","useTableColumnSizing_unstable","params","tableState","useTableColumnSizingState","autoFitColumns","getColumnStyles","column","dragging","width","minWidth","maxWidth","pointerEvents","columns","measureElementRef","columnResizeState","containerWidthOffset","mouseHandler","toggleInteractiveMode","getKeyboardResizingProps","useCallback","onChange","e","preventDefault","nativeEvent","stopPropagation","getColumnById","getColumns","tableRef","columnSizing_unstable","w","undefined","props","col","isLastColumn","length","aside","onMouseDown","onTouchStart"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,iBAAiB,QAAQ,uBAAuB;AAUzD,SAASC,iBAAiB,QAAQ,sBAAsB;AACxD,SAASC,gCAAgC,QAAQ,qCAAqC;AACtF,SAASC,yBAAyB,QAAQ,8BAA8B;AACxE,SAASC,mBAAmB,QAAQ,wBAAwB;AAE5D,OAAO,MAAMC,2BAAmD;IAC9DC,iBAAiB,IAAM,EAAE;IACzBC,gBAAgB,IAAM,IAAM;IAC5BC,gBAAgB,IAAM;IACtBC,eAAe,IAAO,CAAA,CAAC,CAAA;IACvBC,yBAAyB,IAAO,CAAA;YAAEC,OAAO,CAAC;YAAGC,UAAU;QAAG,CAAA;IAC1DC,mBAAmB,IAAO,CAAA;YAAEF,OAAO,CAAC;YAAGC,UAAU;QAAG,CAAA;IACpDE,oBAAoB,IAAM,IAAM;AAClC,EAAE;AAEF,OAA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YACAC,gBAAgB,CAACI,UAAyBgC,IAAcpC,eAAeqC,WAAW;oBAAEjC;oBAAUW,OAAOqB;gBAAE;YACvGtC,iBAAiBmC;YACjBhC,eAAe,CAACqC,QAAQ,CAAC,CAAC;gBACxB,OAAO;oBACL,GAAGA,KAAK;oBACRnC,OAAO;wBACLa,UAAU;wBACV,GAAIsB,MAAMnC,KAAK,IAAI,CAAC,CAAC;oBACvB;gBACF;YACF;YACAD,yBAAyBX,MAAMmC,WAAW,CACxC,CAACtB;oBAEsBe;gBADrB,MAAMoB,MAAMP,cAAc5B;gBAC1B,MAAMoC,eAAerB,EAAAA,YAAAA,OAAO,CAACA,QAAQsB,MAAM,GAAG,EAAE,cAA3BtB,gCAAAA,UAA6Bf,QAAQ,MAAKA;gBAE/D,MAAMsC,QACJF,gBAAgB7B,iBAAiB,qBAC/B,oBAACnB;oBACCmD,aAAa5C,eAAeK;oBAC5BwC,cAAc7C,eAAeK;oBAC5B,GAAGqB,yBAAyBrB,UAAUmC,CAAAA,gBAAAA,0BAAAA,IAAKxB,KAAK,KAAI,EAAE;;gBAI7D,OAAOwB,MACH;oBACEpC,OAAOS,gBAAgB2B,KAAKzB;oBAC5B4B;gBACF,IACA,CAAC;YACP,GACA;gBAACV;gBAAeb;gBAASL;gBAAUW;gBAA0B1B;gBAAgBY;aAAe;YAE9FN,mBAAmBd,MAAMmC,WAAW,CAClC,CAACtB;gBACC,MAAMmC,MAAMP,cAAc5B;gBAC1B,OAAOmC,MAAM;oBAAEpC,OAAOS,gBAAgB2B;gBAAK,IAAI,CAAC;YAClD,GACA;gBAACP;aAAc;YAEjB1B;QACF;IACF;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
|
3
|
-
import { ArrowDown, ArrowRight, ArrowUp } from '@fluentui/keyboard-keys';
|
|
3
|
+
import { ArrowDown, ArrowRight, ArrowUp, ArrowLeft } from '@fluentui/keyboard-keys';
|
|
4
4
|
import { useArrowNavigationGroup, useFocusableGroup, useMergedTabsterAttributes_unstable, useFocusFinders, GroupperMoveFocusEvent, MoverMoveFocusEvent, GroupperMoveFocusActions, MoverKeys } from '@fluentui/react-tabster';
|
|
5
5
|
import { isHTMLElement } from '@fluentui/react-utilities';
|
|
6
6
|
export function useTableCompositeNavigation() {
|
|
@@ -44,7 +44,13 @@ export function useTableCompositeNavigation() {
|
|
|
44
44
|
}
|
|
45
45
|
return false;
|
|
46
46
|
})();
|
|
47
|
-
// Escape groupper focus trap before arrow down
|
|
47
|
+
// Escape groupper focus trap before arrow left, arrow down or arrow up
|
|
48
|
+
if (e.key === ArrowLeft && isInCell) {
|
|
49
|
+
activeElement.dispatchEvent(new GroupperMoveFocusEvent({
|
|
50
|
+
action: GroupperMoveFocusActions.Escape
|
|
51
|
+
}));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
48
54
|
if ((e.key === ArrowDown || e.key === ArrowUp) && isInCell) {
|
|
49
55
|
activeElement.dispatchEvent(new GroupperMoveFocusEvent({
|
|
50
56
|
action: GroupperMoveFocusActions.Escape
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useTableCompositeNavigation.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { ArrowDown, ArrowRight, ArrowUp } from '@fluentui/keyboard-keys';\nimport {\n useArrowNavigationGroup,\n useFocusableGroup,\n useMergedTabsterAttributes_unstable,\n TabsterDOMAttribute,\n useFocusFinders,\n GroupperMoveFocusEvent,\n MoverMoveFocusEvent,\n GroupperMoveFocusActions,\n MoverKeys,\n} from '@fluentui/react-tabster';\nimport { isHTMLElement } from '@fluentui/react-utilities';\n\nexport function useTableCompositeNavigation(): {\n onTableKeyDown: React.KeyboardEventHandler;\n tableTabsterAttribute: TabsterDOMAttribute;\n tableRowTabsterAttribute: TabsterDOMAttribute;\n} {\n const horizontalAttr = useArrowNavigationGroup({ axis: 'horizontal' });\n const gridAttr = useArrowNavigationGroup({ axis: 'grid' });\n const groupperAttr = useFocusableGroup({ tabBehavior: 'limited-trap-focus' });\n const { findFirstFocusable } = useFocusFinders();\n const { targetDocument } = useFluent();\n\n const rowAttr = useMergedTabsterAttributes_unstable(horizontalAttr, groupperAttr);\n\n const onKeyDown: React.KeyboardEventHandler = React.useCallback(\n e => {\n if (!targetDocument) {\n return;\n }\n\n let activeElement = targetDocument.activeElement;\n if (!activeElement || !e.currentTarget.contains(activeElement)) {\n return;\n }\n const activeElementRole = activeElement.getAttribute('role');\n\n // Enter groupper when in row focus mode to navigate cells\n if (e.key === ArrowRight && activeElementRole === 'row' && isHTMLElement(activeElement)) {\n findFirstFocusable(activeElement)?.focus();\n }\n\n if (activeElementRole === 'row') {\n return;\n }\n\n const isInCell = (() => {\n let cur = isHTMLElement(activeElement) ? activeElement : null;\n while (cur) {\n const curRole = cur.getAttribute('role');\n if (curRole === 'cell' || curRole === 'gridcell') {\n return true;\n }\n\n cur = cur.parentElement;\n }\n\n return false;\n })();\n\n // Escape groupper focus trap before arrow down\n if ((e.key === ArrowDown || e.key === ArrowUp) && isInCell) {\n activeElement.dispatchEvent(new GroupperMoveFocusEvent({ action: GroupperMoveFocusActions.Escape }));\n\n activeElement = targetDocument.activeElement;\n\n if (activeElement) {\n activeElement.dispatchEvent(new MoverMoveFocusEvent({ key: MoverKeys[e.key] }));\n }\n }\n },\n [targetDocument, findFirstFocusable],\n );\n\n return {\n onTableKeyDown: onKeyDown,\n tableTabsterAttribute: gridAttr,\n tableRowTabsterAttribute: rowAttr,\n };\n}\n"],"names":["React","useFluent_unstable","useFluent","ArrowDown","ArrowRight","ArrowUp","useArrowNavigationGroup","useFocusableGroup","useMergedTabsterAttributes_unstable","useFocusFinders","GroupperMoveFocusEvent","MoverMoveFocusEvent","GroupperMoveFocusActions","MoverKeys","isHTMLElement","useTableCompositeNavigation","horizontalAttr","axis","gridAttr","groupperAttr","tabBehavior","findFirstFocusable","targetDocument","rowAttr","onKeyDown","useCallback","e","activeElement","currentTarget","contains","activeElementRole","getAttribute","key","focus","isInCell","cur","curRole","parentElement","dispatchEvent","action","Escape","onTableKeyDown","tableTabsterAttribute","tableRowTabsterAttribute"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,SAAS,EAAEC,UAAU,EAAEC,OAAO,QAAQ,0BAA0B;
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useTableCompositeNavigation.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { ArrowDown, ArrowRight, ArrowUp, ArrowLeft } from '@fluentui/keyboard-keys';\nimport {\n useArrowNavigationGroup,\n useFocusableGroup,\n useMergedTabsterAttributes_unstable,\n TabsterDOMAttribute,\n useFocusFinders,\n GroupperMoveFocusEvent,\n MoverMoveFocusEvent,\n GroupperMoveFocusActions,\n MoverKeys,\n} from '@fluentui/react-tabster';\nimport { isHTMLElement } from '@fluentui/react-utilities';\n\nexport function useTableCompositeNavigation(): {\n onTableKeyDown: React.KeyboardEventHandler;\n tableTabsterAttribute: TabsterDOMAttribute;\n tableRowTabsterAttribute: TabsterDOMAttribute;\n} {\n const horizontalAttr = useArrowNavigationGroup({ axis: 'horizontal' });\n const gridAttr = useArrowNavigationGroup({ axis: 'grid' });\n const groupperAttr = useFocusableGroup({ tabBehavior: 'limited-trap-focus' });\n const { findFirstFocusable } = useFocusFinders();\n const { targetDocument } = useFluent();\n\n const rowAttr = useMergedTabsterAttributes_unstable(horizontalAttr, groupperAttr);\n\n const onKeyDown: React.KeyboardEventHandler = React.useCallback(\n e => {\n if (!targetDocument) {\n return;\n }\n\n let activeElement = targetDocument.activeElement;\n if (!activeElement || !e.currentTarget.contains(activeElement)) {\n return;\n }\n const activeElementRole = activeElement.getAttribute('role');\n\n // Enter groupper when in row focus mode to navigate cells\n if (e.key === ArrowRight && activeElementRole === 'row' && isHTMLElement(activeElement)) {\n findFirstFocusable(activeElement)?.focus();\n }\n\n if (activeElementRole === 'row') {\n return;\n }\n\n const isInCell = (() => {\n let cur = isHTMLElement(activeElement) ? activeElement : null;\n while (cur) {\n const curRole = cur.getAttribute('role');\n if (curRole === 'cell' || curRole === 'gridcell') {\n return true;\n }\n\n cur = cur.parentElement;\n }\n\n return false;\n })();\n\n // Escape groupper focus trap before arrow left, arrow down or arrow up\n if (e.key === ArrowLeft && isInCell) {\n activeElement.dispatchEvent(new GroupperMoveFocusEvent({ action: GroupperMoveFocusActions.Escape }));\n return;\n }\n if ((e.key === ArrowDown || e.key === ArrowUp) && isInCell) {\n activeElement.dispatchEvent(new GroupperMoveFocusEvent({ action: GroupperMoveFocusActions.Escape }));\n\n activeElement = targetDocument.activeElement;\n\n if (activeElement) {\n activeElement.dispatchEvent(new MoverMoveFocusEvent({ key: MoverKeys[e.key] }));\n }\n }\n },\n [targetDocument, findFirstFocusable],\n );\n\n return {\n onTableKeyDown: onKeyDown,\n tableTabsterAttribute: gridAttr,\n tableRowTabsterAttribute: rowAttr,\n };\n}\n"],"names":["React","useFluent_unstable","useFluent","ArrowDown","ArrowRight","ArrowUp","ArrowLeft","useArrowNavigationGroup","useFocusableGroup","useMergedTabsterAttributes_unstable","useFocusFinders","GroupperMoveFocusEvent","MoverMoveFocusEvent","GroupperMoveFocusActions","MoverKeys","isHTMLElement","useTableCompositeNavigation","horizontalAttr","axis","gridAttr","groupperAttr","tabBehavior","findFirstFocusable","targetDocument","rowAttr","onKeyDown","useCallback","e","activeElement","currentTarget","contains","activeElementRole","getAttribute","key","focus","isInCell","cur","curRole","parentElement","dispatchEvent","action","Escape","onTableKeyDown","tableTabsterAttribute","tableRowTabsterAttribute"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,SAAS,EAAEC,UAAU,EAAEC,OAA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,IAAIX,EAAEM,GAAG,KAAK3B,aAAa6B,UAAU;YACnCP,cAAcW,aAAa,CAAC,IAAI5B,uBAAuB;gBAAE6B,QAAQ3B,yBAAyB4B,MAAM;YAAC;YACjG;QACF;QACA,IAAI,AAACd,CAAAA,EAAEM,GAAG,KAAK9B,aAAawB,EAAEM,GAAG,KAAK5B,OAAM,KAAM8B,UAAU;YAC1DP,cAAcW,aAAa,CAAC,IAAI5B,uBAAuB;gBAAE6B,QAAQ3B,yBAAyB4B,MAAM;YAAC;YAEjGb,gBAAgBL,eAAeK,aAAa;YAE5C,IAAIA,eAAe;gBACjBA,cAAcW,aAAa,CAAC,IAAI3B,oBAAoB;oBAAEqB,KAAKnB,SAAS,CAACa,EAAEM,GAAG,CAAC;gBAAC;YAC9E;QACF;IACF,GACA;QAACV;QAAgBD;KAAmB;IAGtC,OAAO;QACLoB,gBAAgBjB;QAChBkB,uBAAuBxB;QACvByB,0BAA0BpB;IAC5B;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useTableSelection.ts"],"sourcesContent":["import * as React from 'react';\nimport { SelectionHookParams, useEventCallback, useSelection } from '@fluentui/react-utilities';\nimport type { TableRowId, TableSelectionState, TableFeaturesState } from './types';\n\nconst noop = () => undefined;\n\nexport const defaultTableSelectionState: TableSelectionState = {\n allRowsSelected: false,\n clearRows: noop,\n deselectRow: noop,\n isRowSelected: () => false,\n selectRow: noop,\n selectedRows: new Set(),\n someRowsSelected: false,\n toggleAllRows: noop,\n toggleRow: noop,\n selectionMode: 'multiselect',\n};\n\nexport function useTableSelection<TItem>(options: SelectionHookParams) {\n 'use no memo';\n\n // False positive, these plugin hooks are intended to be run on every render\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return (tableState: TableFeaturesState<TItem>) => useTableSelectionState(tableState, options);\n}\n\nexport function useTableSelectionState<TItem>(\n tableState: TableFeaturesState<TItem>,\n options: SelectionHookParams,\n): TableFeaturesState<TItem> {\n const { items, getRowId } = tableState;\n const { selectionMode: selectionMode, defaultSelectedItems, selectedItems, onSelectionChange } = options;\n\n const [selected, selectionMethods] = useSelection({\n selectionMode,\n defaultSelectedItems,\n selectedItems,\n onSelectionChange,\n });\n\n // Selection state can contain obselete items (i.e. rows that are removed)\n const selectableRowIds = React.useMemo(() => {\n const rowIds = new Set<TableRowId>();\n for (let i = 0; i < items.length; i++) {\n rowIds.add(getRowId?.(items[i]) ?? i);\n }\n\n return rowIds;\n }, [items, getRowId]);\n\n const allRowsSelected = React.useMemo(() => {\n if (selectionMode === 'single') {\n const selectedRow = Array.from(selected)[0];\n return selectableRowIds.has(selectedRow);\n }\n\n // multiselect case\n if (selected.size < selectableRowIds.size) {\n return false;\n }\n\n if (selectableRowIds.size === 0) {\n return false;\n }\n\n let res = true;\n selectableRowIds.forEach(selectableRowId => {\n if (!selected.has(selectableRowId)) {\n res = false;\n }\n });\n\n return res;\n }, [selectableRowIds, selected, selectionMode]);\n\n const someRowsSelected = React.useMemo(() => {\n if (selected.size <= 0) {\n return false;\n }\n\n let res = false;\n selectableRowIds.forEach(selectableRowId => {\n if (selected.has(selectableRowId)) {\n res = true;\n }\n });\n\n return res;\n }, [selectableRowIds, selected]);\n\n const toggleAllRows: TableSelectionState['toggleAllRows'] = useEventCallback(e => {\n selectionMethods.toggleAllItems(\n e,\n items.map((item, i) => getRowId?.(item) ?? i),\n );\n });\n\n const toggleRow: TableSelectionState['toggleRow'] = useEventCallback((e, rowId: TableRowId) =>\n selectionMethods.toggleItem(e, rowId),\n );\n\n const deselectRow: TableSelectionState['deselectRow'] = useEventCallback((e, rowId: TableRowId) =>\n selectionMethods.deselectItem(e, rowId),\n );\n\n const selectRow: TableSelectionState['selectRow'] = useEventCallback((e, rowId: TableRowId) =>\n selectionMethods.selectItem(e, rowId),\n );\n\n const isRowSelected: TableSelectionState['isRowSelected'] = (rowId: TableRowId) => selectionMethods.isSelected(rowId);\n\n const clearRows: TableSelectionState['clearRows'] = useEventCallback(e => selectionMethods.clearItems(e));\n\n return {\n ...tableState,\n selection: {\n selectionMode,\n someRowsSelected,\n allRowsSelected,\n selectedRows: selected,\n toggleRow,\n toggleAllRows,\n clearRows,\n deselectRow,\n selectRow,\n isRowSelected,\n },\n };\n}\n"],"names":["React","useEventCallback","useSelection","noop","undefined","defaultTableSelectionState","allRowsSelected","clearRows","deselectRow","isRowSelected","selectRow","selectedRows","Set","someRowsSelected","toggleAllRows","toggleRow","selectionMode","useTableSelection","options","tableState","useTableSelectionState","items","getRowId","defaultSelectedItems","selectedItems","onSelectionChange","selected","selectionMethods","selectableRowIds","useMemo","rowIds","i","length","add","selectedRow","Array","from","has","size","res","forEach","selectableRowId","e","toggleAllItems","map","item","rowId","toggleItem","deselectItem","selectItem","isSelected","clearItems","selection"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAA8BC,gBAAgB,EAAEC,YAAY,QAAQ,4BAA4B;AAGhG,MAAMC,OAAO,
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useTableSelection.ts"],"sourcesContent":["import * as React from 'react';\nimport { SelectionHookParams, useEventCallback, useSelection } from '@fluentui/react-utilities';\nimport type { TableRowId, TableSelectionState, TableFeaturesState } from './types';\n\nconst noop = (): void => undefined;\n\nexport const defaultTableSelectionState: TableSelectionState = {\n allRowsSelected: false,\n clearRows: noop,\n deselectRow: noop,\n isRowSelected: () => false,\n selectRow: noop,\n selectedRows: new Set(),\n someRowsSelected: false,\n toggleAllRows: noop,\n toggleRow: noop,\n selectionMode: 'multiselect',\n};\n\nexport function useTableSelection<TItem>(\n options: SelectionHookParams,\n): (tableState: TableFeaturesState<TItem>) => TableFeaturesState<TItem> {\n 'use no memo';\n\n // False positive, these plugin hooks are intended to be run on every render\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return (tableState: TableFeaturesState<TItem>) => useTableSelectionState(tableState, options);\n}\n\nexport function useTableSelectionState<TItem>(\n tableState: TableFeaturesState<TItem>,\n options: SelectionHookParams,\n): TableFeaturesState<TItem> {\n const { items, getRowId } = tableState;\n const { selectionMode: selectionMode, defaultSelectedItems, selectedItems, onSelectionChange } = options;\n\n const [selected, selectionMethods] = useSelection({\n selectionMode,\n defaultSelectedItems,\n selectedItems,\n onSelectionChange,\n });\n\n // Selection state can contain obselete items (i.e. rows that are removed)\n const selectableRowIds = React.useMemo(() => {\n const rowIds = new Set<TableRowId>();\n for (let i = 0; i < items.length; i++) {\n rowIds.add(getRowId?.(items[i]) ?? i);\n }\n\n return rowIds;\n }, [items, getRowId]);\n\n const allRowsSelected = React.useMemo(() => {\n if (selectionMode === 'single') {\n const selectedRow = Array.from(selected)[0];\n return selectableRowIds.has(selectedRow);\n }\n\n // multiselect case\n if (selected.size < selectableRowIds.size) {\n return false;\n }\n\n if (selectableRowIds.size === 0) {\n return false;\n }\n\n let res = true;\n selectableRowIds.forEach(selectableRowId => {\n if (!selected.has(selectableRowId)) {\n res = false;\n }\n });\n\n return res;\n }, [selectableRowIds, selected, selectionMode]);\n\n const someRowsSelected = React.useMemo(() => {\n if (selected.size <= 0) {\n return false;\n }\n\n let res = false;\n selectableRowIds.forEach(selectableRowId => {\n if (selected.has(selectableRowId)) {\n res = true;\n }\n });\n\n return res;\n }, [selectableRowIds, selected]);\n\n const toggleAllRows: TableSelectionState['toggleAllRows'] = useEventCallback(e => {\n selectionMethods.toggleAllItems(\n e,\n items.map((item, i) => getRowId?.(item) ?? i),\n );\n });\n\n const toggleRow: TableSelectionState['toggleRow'] = useEventCallback((e, rowId: TableRowId) =>\n selectionMethods.toggleItem(e, rowId),\n );\n\n const deselectRow: TableSelectionState['deselectRow'] = useEventCallback((e, rowId: TableRowId) =>\n selectionMethods.deselectItem(e, rowId),\n );\n\n const selectRow: TableSelectionState['selectRow'] = useEventCallback((e, rowId: TableRowId) =>\n selectionMethods.selectItem(e, rowId),\n );\n\n const isRowSelected: TableSelectionState['isRowSelected'] = (rowId: TableRowId) => selectionMethods.isSelected(rowId);\n\n const clearRows: TableSelectionState['clearRows'] = useEventCallback(e => selectionMethods.clearItems(e));\n\n return {\n ...tableState,\n selection: {\n selectionMode,\n someRowsSelected,\n allRowsSelected,\n selectedRows: selected,\n toggleRow,\n toggleAllRows,\n clearRows,\n deselectRow,\n selectRow,\n isRowSelected,\n },\n };\n}\n"],"names":["React","useEventCallback","useSelection","noop","undefined","defaultTableSelectionState","allRowsSelected","clearRows","deselectRow","isRowSelected","selectRow","selectedRows","Set","someRowsSelected","toggleAllRows","toggleRow","selectionMode","useTableSelection","options","tableState","useTableSelectionState","items","getRowId","defaultSelectedItems","selectedItems","onSelectionChange","selected","selectionMethods","selectableRowIds","useMemo","rowIds","i","length","add","selectedRow","Array","from","has","size","res","forEach","selectableRowId","e","toggleAllItems","map","item","rowId","toggleItem","deselectItem","selectItem","isSelected","clearItems","selection"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAA8BC,gBAAgB,EAAEC,YAAY,QAAQ,4BAA4B;AAGhG,MAAMC,OAAO,IAAYC;AAEzB,OAAO,MAAMC,6BAAkD;IAC7DC,iBAAiB;IACjBC,WAAWJ;IACXK,aAAaL;IACbM,eAAe,IAAM;IACrBC,WAAWP;IACXQ,cAAc,IAAIC;IAClBC,kBAAkB;IAClBC,eAAeX;IACfY,WAAWZ;IACXa,eAAe;AACjB,EAAE;AAEF,OAAO,SAASC,kBACdC,OAA4B;IAE5B;IAEA,4EAA4E;IAC5E,sDAAsD;IACtD,OAAO,CAACC,aAA0CC,uBAAuBD,YAAYD;AACvF;AAEA,OAAO,SAASE,uBACdD,UAAqC,EACrCD,OAA4B;IAE5B,MAAM,EAAEG,KAAK,EAAEC,QAAQ,EAAE,GAAGH;IAC5B,MAAM,EAAEH,eAAeA,aAAa,EAAEO,oBAAoB,EAAEC,aAAa,EAAEC,iBAAiB,EAAE,GAAGP;IAEjG,MAAM,CAACQ,UAAUC,iBAAiB,GAAGzB,aAAa;QAChDc;QACAO;QACAC;QACAC;IACF;IAEA,0EAA0E;IAC1E,MAAMG,mBAAmB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,YAAoBS;;IAE/C;IAEA,MAAMhB,YAA8Cd,iBAAiB,CAACyC,GAAGI,QACvEnB,iBAAiBoB,UAAU,CAACL,GAAGI;IAGjC,MAAMtC,cAAkDP,iBAAiB,CAACyC,GAAGI,QAC3EnB,iBAAiBqB,YAAY,CAACN,GAAGI;IAGnC,MAAMpC,YAA8CT,iBAAiB,CAACyC,GAAGI,QACvEnB,iBAAiBsB,UAAU,CAACP,GAAGI;IAGjC,MAAMrC,gBAAsD,CAACqC,QAAsBnB,iBAAiBuB,UAAU,CAACJ;IAE/G,MAAMvC,YAA8CN,iBAAiByC,CAAAA,IAAKf,iBAAiBwB,UAAU,CAACT;IAEtG,OAAO;QACL,GAAGvB,UAAU;QACbiC,WAAW;YACTpC;YACAH;YACAP;YACAK,cAAce;YACdX;YACAD;YACAP;YACAC;YACAE;YACAD;QACF;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useTableSort.ts"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState, useEventCallback } from '@fluentui/react-utilities';\nimport type {\n TableColumnId,\n TableRowData,\n SortState,\n TableSortState,\n TableFeaturesState,\n UseTableSortOptions,\n} from './types';\n\nconst noop = () => undefined;\n\nexport const defaultTableSortState: TableSortState<unknown> = {\n getSortDirection: () => 'ascending',\n setColumnSort: noop,\n sort: <TRowState extends TableRowData<unknown>>(rows: TRowState[]) => [...rows],\n sortColumn: undefined,\n sortDirection: 'ascending',\n toggleColumnSort: noop,\n};\n\nexport function useTableSort<TItem>(options: UseTableSortOptions) {\n 'use no memo';\n\n // False positive, these plugin hooks are intended to be run on every render\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return (tableState: TableFeaturesState<TItem>) => useTableSortState(tableState, options);\n}\n\nexport function useTableSortState<TItem>(\n tableState: TableFeaturesState<TItem>,\n options: UseTableSortOptions,\n): TableFeaturesState<TItem> {\n const { columns } = tableState;\n const { sortState, defaultSortState, onSortChange: onSortChangeProp = noop } = options;\n\n const [sorted, setSorted] = useControllableState<SortState>({\n initialState: {\n sortDirection: 'ascending' as const,\n sortColumn: undefined,\n },\n defaultState: defaultSortState,\n state: sortState,\n });\n\n const { sortColumn, sortDirection } = sorted;\n\n const onSortChange = useEventCallback(onSortChangeProp);\n\n const toggleColumnSort = React.useCallback(\n (e: React.SyntheticEvent, columnId: TableColumnId | undefined) => {\n setSorted(s => {\n const newState = { ...s, sortColumn: columnId };\n if (s.sortColumn === columnId) {\n newState.sortDirection = s.sortDirection === 'ascending' ? 'descending' : 'ascending';\n } else {\n newState.sortDirection = 'ascending';\n }\n\n onSortChange?.(e, newState);\n return newState;\n });\n },\n [onSortChange, setSorted],\n );\n\n const setColumnSort: TableSortState<TItem>['setColumnSort'] = (e, nextSortColumn, nextSortDirection) => {\n const newState = { sortColumn: nextSortColumn, sortDirection: nextSortDirection };\n onSortChange?.(e, newState);\n setSorted(newState);\n };\n\n const sort = React.useCallback(\n <TRowState extends TableRowData<TItem>>(rows: TRowState[]) => {\n return rows.slice().sort((a, b) => {\n const sortColumnDef = columns.find(column => column.columnId === sortColumn);\n if (!sortColumnDef?.compare) {\n return 0;\n }\n\n const mod = sortDirection === 'ascending' ? 1 : -1;\n return sortColumnDef.compare(a.item, b.item) * mod;\n });\n },\n [columns, sortColumn, sortDirection],\n );\n\n const getSortDirection: TableSortState<TItem>['getSortDirection'] = (columnId: TableColumnId) => {\n return sortColumn === columnId ? sortDirection : undefined;\n };\n\n return {\n ...tableState,\n sort: {\n sort,\n sortColumn,\n sortDirection,\n setColumnSort,\n toggleColumnSort,\n getSortDirection,\n },\n };\n}\n"],"names":["React","useControllableState","useEventCallback","noop","undefined","defaultTableSortState","getSortDirection","setColumnSort","sort","rows","sortColumn","sortDirection","toggleColumnSort","useTableSort","options","tableState","useTableSortState","columns","sortState","defaultSortState","onSortChange","onSortChangeProp","sorted","setSorted","initialState","defaultState","state","useCallback","e","columnId","s","newState","nextSortColumn","nextSortDirection","slice","a","b","sortColumnDef","find","column","compare","mod","item"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,oBAAoB,EAAEC,gBAAgB,QAAQ,4BAA4B;AAUnF,MAAMC,OAAO,
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useTableSort.ts"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState, useEventCallback } from '@fluentui/react-utilities';\nimport type {\n TableColumnId,\n TableRowData,\n SortState,\n TableSortState,\n TableFeaturesState,\n UseTableSortOptions,\n} from './types';\n\nconst noop = (): void => undefined;\n\nexport const defaultTableSortState: TableSortState<unknown> = {\n getSortDirection: () => 'ascending',\n setColumnSort: noop,\n sort: <TRowState extends TableRowData<unknown>>(rows: TRowState[]) => [...rows],\n sortColumn: undefined,\n sortDirection: 'ascending',\n toggleColumnSort: noop,\n};\n\nexport function useTableSort<TItem>(options: UseTableSortOptions) {\n 'use no memo';\n\n // False positive, these plugin hooks are intended to be run on every render\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return (tableState: TableFeaturesState<TItem>): TableFeaturesState<TItem> => useTableSortState(tableState, options);\n}\n\nexport function useTableSortState<TItem>(\n tableState: TableFeaturesState<TItem>,\n options: UseTableSortOptions,\n): TableFeaturesState<TItem> {\n const { columns } = tableState;\n const { sortState, defaultSortState, onSortChange: onSortChangeProp = noop } = options;\n\n const [sorted, setSorted] = useControllableState<SortState>({\n initialState: {\n sortDirection: 'ascending' as const,\n sortColumn: undefined,\n },\n defaultState: defaultSortState,\n state: sortState,\n });\n\n const { sortColumn, sortDirection } = sorted;\n\n const onSortChange = useEventCallback(onSortChangeProp);\n\n const toggleColumnSort = React.useCallback(\n (e: React.SyntheticEvent, columnId: TableColumnId | undefined) => {\n setSorted(s => {\n const newState = { ...s, sortColumn: columnId };\n if (s.sortColumn === columnId) {\n newState.sortDirection = s.sortDirection === 'ascending' ? 'descending' : 'ascending';\n } else {\n newState.sortDirection = 'ascending';\n }\n\n onSortChange?.(e, newState);\n return newState;\n });\n },\n [onSortChange, setSorted],\n );\n\n const setColumnSort: TableSortState<TItem>['setColumnSort'] = (e, nextSortColumn, nextSortDirection) => {\n const newState = { sortColumn: nextSortColumn, sortDirection: nextSortDirection };\n onSortChange?.(e, newState);\n setSorted(newState);\n };\n\n const sort = React.useCallback(\n <TRowState extends TableRowData<TItem>>(rows: TRowState[]) => {\n return rows.slice().sort((a, b) => {\n const sortColumnDef = columns.find(column => column.columnId === sortColumn);\n if (!sortColumnDef?.compare) {\n return 0;\n }\n\n const mod = sortDirection === 'ascending' ? 1 : -1;\n return sortColumnDef.compare(a.item, b.item) * mod;\n });\n },\n [columns, sortColumn, sortDirection],\n );\n\n const getSortDirection: TableSortState<TItem>['getSortDirection'] = (columnId: TableColumnId) => {\n return sortColumn === columnId ? sortDirection : undefined;\n };\n\n return {\n ...tableState,\n sort: {\n sort,\n sortColumn,\n sortDirection,\n setColumnSort,\n toggleColumnSort,\n getSortDirection,\n },\n };\n}\n"],"names":["React","useControllableState","useEventCallback","noop","undefined","defaultTableSortState","getSortDirection","setColumnSort","sort","rows","sortColumn","sortDirection","toggleColumnSort","useTableSort","options","tableState","useTableSortState","columns","sortState","defaultSortState","onSortChange","onSortChangeProp","sorted","setSorted","initialState","defaultState","state","useCallback","e","columnId","s","newState","nextSortColumn","nextSortDirection","slice","a","b","sortColumnDef","find","column","compare","mod","item"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,oBAAoB,EAAEC,gBAAgB,QAAQ,4BAA4B;AAUnF,MAAMC,OAAO,IAAYC;AAEzB,OAAO,MAAMC,wBAAiD;IAC5DC,kBAAkB,IAAM;IACxBC,eAAeJ;IACfK,MAAM,CAA0CC,OAAsB;eAAIA;SAAK;IAC/EC,YAAYN;IACZO,eAAe;IACfC,kBAAkBT;AACpB,EAAE;AAEF,OAAO,SAASU,aAAoBC,OAA4B;IAC9D;IAEA,4EAA4E;IAC5E,sDAAsD;IACtD,OAAO,CAACC,aAAqEC,kBAAkBD,YAAYD;AAC7G;AAEA,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AkB,cAAc,IAAI,CAAC;YACjD,OAAO0B,cAAcG,OAAO,CAACL,EAAEO,IAAI,EAAEN,EAAEM,IAAI,IAAID;QACjD;IACF,GACA;QAACxB;QAASP;QAAYC;KAAc;IAGtC,MAAML,mBAA8D,CAACuB;QACnE,OAAOnB,eAAemB,WAAWlB,gBAAgBP;IACnD;IAEA,OAAO;QACL,GAAGW,UAAU;QACbP,MAAM;YACJA;YACAE;YACAC;YACAJ;YACAK;YACAN;QACF;IACF;AACF"}
|
|
@@ -125,13 +125,18 @@ export function getColumnWidth(state, columnId) {
|
|
|
125
125
|
// We start at the beginning and assign the columns their ideal width
|
|
126
126
|
while(i < newState.length && difference > 0){
|
|
127
127
|
const currentCol = getColumnByIndex(newState, i);
|
|
128
|
+
if (!currentCol) {
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
128
131
|
const colAdjustment = Math.min(currentCol.idealWidth - currentCol.width, difference);
|
|
129
132
|
newState = setColumnProperty(newState, currentCol.columnId, 'width', currentCol.width + colAdjustment);
|
|
130
133
|
difference -= colAdjustment;
|
|
131
134
|
// if there is still empty space, after all columns are their ideal sizes, assign it to the last column
|
|
132
135
|
if (i === newState.length - 1 && difference !== 0) {
|
|
133
136
|
const lastCol = getColumnByIndex(newState, i);
|
|
134
|
-
|
|
137
|
+
if (lastCol) {
|
|
138
|
+
newState = setColumnProperty(newState, lastCol.columnId, 'width', lastCol.width + difference);
|
|
139
|
+
}
|
|
135
140
|
}
|
|
136
141
|
i++;
|
|
137
142
|
}
|
|
@@ -141,6 +146,10 @@ export function getColumnWidth(state, columnId) {
|
|
|
141
146
|
let j = newState.length - 1;
|
|
142
147
|
while(j >= 0 && difference > 0){
|
|
143
148
|
const currentCol = getColumnByIndex(newState, j);
|
|
149
|
+
if (!currentCol) {
|
|
150
|
+
j--;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
144
153
|
if (currentCol.width > currentCol.minWidth) {
|
|
145
154
|
const colAdjustment = Math.min(currentCol.width - currentCol.minWidth, difference);
|
|
146
155
|
difference -= colAdjustment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/columnResizeUtils.ts"],"sourcesContent":["import { TableColumnDefinition, ColumnWidthState, TableColumnId, TableColumnSizingOptions } from '../hooks';\n\nconst DEFAULT_WIDTH = 150;\nconst DEFAULT_MIN_WIDTH = 100;\n\n/**\n * This function takes the column definitions and the curent ColumnWidthState and returns new state.\n * - It uses existing state for existing columns.\n * - It removes any state for columns no longer present.\n * - It checks if any column has been replaced and returns updated state if so\n * - It returns old state if no changes in the state have been made (so that react doesn't call effects)\n * @param columns\n * @param state\n * @returns\n */\n\nexport function columnDefinitionsToState<T>(\n columns: TableColumnDefinition<T>[],\n state: ColumnWidthState[] = [],\n columnSizingOptions: TableColumnSizingOptions = {},\n): ColumnWidthState[] {\n let updated = false;\n const stateMap = new Map(state.map(s => [s.columnId, s]));\n\n const updatedState = columns.map(column => {\n const existingColumnState = stateMap.get(column.columnId);\n\n if (existingColumnState) {\n const {\n idealWidth = existingColumnState.idealWidth,\n minWidth = existingColumnState.minWidth,\n padding = existingColumnState.padding,\n } = columnSizingOptions[column.columnId] ?? {};\n\n if (\n idealWidth !== existingColumnState.idealWidth ||\n minWidth !== existingColumnState.minWidth ||\n padding !== existingColumnState.padding\n ) {\n updated = true;\n return {\n ...existingColumnState,\n idealWidth,\n width: idealWidth,\n minWidth,\n padding,\n };\n }\n return existingColumnState;\n }\n\n const {\n defaultWidth,\n idealWidth = DEFAULT_WIDTH,\n minWidth = DEFAULT_MIN_WIDTH,\n padding,\n } = columnSizingOptions[column.columnId] ?? {};\n\n updated = true;\n return {\n columnId: column.columnId,\n width: Math.max(defaultWidth ?? idealWidth, minWidth),\n minWidth,\n idealWidth: Math.max(defaultWidth ?? idealWidth, minWidth),\n padding: padding ?? 16,\n };\n });\n\n // If the length of the new state changed (column was added or removed) or any of\n // the individual states has a new reference (column was replaced),\n // we have to reset the column widths to their ideal width (because the column which was last may not be last now).\n // Then the adjustColumnWidthsToFitContainer can do its job and properly stretch the last column.\n if (updatedState.length !== state.length || updated) {\n const column = updatedState.find(col => col.width > col.idealWidth);\n if (column) {\n column.width = column.idealWidth;\n }\n\n updated = true;\n }\n\n return updated ? updatedState : state;\n}\n\nexport function getColumnById(state: ColumnWidthState[], columnId: TableColumnId) {\n return state.find(c => c.columnId === columnId);\n}\n\nexport function getColumnByIndex(state: ColumnWidthState[], index: number) {\n return state[index];\n}\n\nexport function getTotalWidth(state: ColumnWidthState[]): number {\n return state.reduce((sum, column) => sum + column.width + column.padding, 0);\n}\n\nexport function getLength(state: ColumnWidthState[]) {\n return state.length;\n}\n\nexport function getColumnWidth(state: ColumnWidthState[], columnId: TableColumnId): number {\n const column = getColumnById(state, columnId);\n return column?.width ?? 0;\n}\n\n/**\n * This function takes the current state and returns an updated state, so that it can be set.\n * The reason for this is that we can update the state multiple times before commiting to render.\n * This is an optimization and also prevents flickering.\n * It also returns new copy of the state only if the value is different than the one currently in\n * the state, further preventing unnecessary updates.\n * @param localState\n * @param columnId\n * @param property\n * @param value\n * @returns\n */\nexport function setColumnProperty(\n localState: ColumnWidthState[],\n columnId: TableColumnId,\n property: keyof ColumnWidthState,\n value: number,\n) {\n const currentColumn = getColumnById(localState, columnId);\n\n if (!currentColumn || currentColumn?.[property] === value) {\n return localState;\n }\n\n const updatedColumn = { ...currentColumn, [property]: value };\n\n const newState = localState.reduce((acc, current) => {\n if (current.columnId === updatedColumn.columnId) {\n return [...acc, updatedColumn];\n }\n return [...acc, current];\n }, [] as ColumnWidthState[]);\n\n return newState;\n}\n\n/**\n * This function takes the state and container width and makes sure the each column in the state\n * is its optimal width, and that the columns\n * a) fit to the container\n * b) always fill the whole container\n * @param state\n * @param containerWidth\n * @returns\n */\nexport function adjustColumnWidthsToFitContainer(state: ColumnWidthState[], containerWidth: number) {\n let newState = state;\n const totalWidth = getTotalWidth(newState);\n\n // The total width is smaller, we are expanding columns\n if (totalWidth < containerWidth) {\n let difference = containerWidth - totalWidth;\n let i = 0;\n // We start at the beginning and assign the columns their ideal width\n while (i < newState.length && difference > 0) {\n const currentCol = getColumnByIndex(newState, i);\n const colAdjustment = Math.min(currentCol.idealWidth - currentCol.width, difference);\n newState = setColumnProperty(newState, currentCol.columnId, 'width', currentCol.width + colAdjustment);\n difference -= colAdjustment;\n\n // if there is still empty space, after all columns are their ideal sizes, assign it to the last column\n if (i === newState.length - 1 && difference !== 0) {\n const lastCol = getColumnByIndex(newState, i);\n newState = setColumnProperty(newState, lastCol.columnId, 'width', lastCol.width + difference);\n }\n\n i++;\n }\n }\n\n // The total width is larger than container, we need to squash the columns\n else if (totalWidth >= containerWidth) {\n let difference = totalWidth - containerWidth;\n // We start with the last column\n let j = newState.length - 1;\n while (j >= 0 && difference > 0) {\n const currentCol = getColumnByIndex(newState, j);\n if (currentCol.width > currentCol.minWidth) {\n const colAdjustment = Math.min(currentCol.width - currentCol.minWidth, difference);\n difference -= colAdjustment;\n newState = setColumnProperty(newState, currentCol.columnId, 'width', currentCol.width - colAdjustment);\n }\n j--;\n }\n }\n\n return newState;\n}\n"],"names":["DEFAULT_WIDTH","DEFAULT_MIN_WIDTH","columnDefinitionsToState","columns","state","columnSizingOptions","updated","stateMap","Map","map","s","columnId","updatedState","column","existingColumnState","get","idealWidth","minWidth","padding","width","defaultWidth","Math","max","length","find","col","getColumnById","c","getColumnByIndex","index","getTotalWidth","reduce","sum","getLength","getColumnWidth","setColumnProperty","localState","property","value","currentColumn","updatedColumn","newState","acc","current","adjustColumnWidthsToFitContainer","containerWidth","totalWidth","difference","i","currentCol","colAdjustment","min","lastCol","j"],"mappings":"AAEA,MAAMA,gBAAgB;AACtB,MAAMC,oBAAoB;AAE1B;;;;;;;;;CASC,GAED,OAAO,SAASC,yBACdC,OAAmC,EACnCC,QAA4B,EAAE,EAC9BC,sBAAgD,CAAC,CAAC;IAElD,IAAIC,UAAU;IACd,MAAMC,WAAW,IAAIC,IAAIJ,MAAMK,GAAG,CAACC,CAAAA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YACAG;QACF;IACF;IAEA,OAAOZ;AACT"}
|
|
1
|
+
{"version":3,"sources":["../src/utils/columnResizeUtils.ts"],"sourcesContent":["import { TableColumnDefinition, ColumnWidthState, TableColumnId, TableColumnSizingOptions } from '../hooks';\n\nconst DEFAULT_WIDTH = 150;\nconst DEFAULT_MIN_WIDTH = 100;\n\n/**\n * This function takes the column definitions and the curent ColumnWidthState and returns new state.\n * - It uses existing state for existing columns.\n * - It removes any state for columns no longer present.\n * - It checks if any column has been replaced and returns updated state if so\n * - It returns old state if no changes in the state have been made (so that react doesn't call effects)\n * @param columns\n * @param state\n * @returns\n */\n\nexport function columnDefinitionsToState<T>(\n columns: TableColumnDefinition<T>[],\n state: ColumnWidthState[] = [],\n columnSizingOptions: TableColumnSizingOptions = {},\n): ColumnWidthState[] {\n let updated = false;\n const stateMap = new Map(state.map(s => [s.columnId, s]));\n\n const updatedState = columns.map(column => {\n const existingColumnState = stateMap.get(column.columnId);\n\n if (existingColumnState) {\n const {\n idealWidth = existingColumnState.idealWidth,\n minWidth = existingColumnState.minWidth,\n padding = existingColumnState.padding,\n } = columnSizingOptions[column.columnId] ?? {};\n\n if (\n idealWidth !== existingColumnState.idealWidth ||\n minWidth !== existingColumnState.minWidth ||\n padding !== existingColumnState.padding\n ) {\n updated = true;\n return {\n ...existingColumnState,\n idealWidth,\n width: idealWidth,\n minWidth,\n padding,\n };\n }\n return existingColumnState;\n }\n\n const {\n defaultWidth,\n idealWidth = DEFAULT_WIDTH,\n minWidth = DEFAULT_MIN_WIDTH,\n padding,\n } = columnSizingOptions[column.columnId] ?? {};\n\n updated = true;\n return {\n columnId: column.columnId,\n width: Math.max(defaultWidth ?? idealWidth, minWidth),\n minWidth,\n idealWidth: Math.max(defaultWidth ?? idealWidth, minWidth),\n padding: padding ?? 16,\n };\n });\n\n // If the length of the new state changed (column was added or removed) or any of\n // the individual states has a new reference (column was replaced),\n // we have to reset the column widths to their ideal width (because the column which was last may not be last now).\n // Then the adjustColumnWidthsToFitContainer can do its job and properly stretch the last column.\n if (updatedState.length !== state.length || updated) {\n const column = updatedState.find(col => col.width > col.idealWidth);\n if (column) {\n column.width = column.idealWidth;\n }\n\n updated = true;\n }\n\n return updated ? updatedState : state;\n}\n\nexport function getColumnById(state: ColumnWidthState[], columnId: TableColumnId): ColumnWidthState | undefined {\n return state.find(c => c.columnId === columnId);\n}\n\nexport function getColumnByIndex(state: ColumnWidthState[], index: number): ColumnWidthState | undefined {\n return state[index];\n}\n\nexport function getTotalWidth(state: ColumnWidthState[]): number {\n return state.reduce((sum, column) => sum + column.width + column.padding, 0);\n}\n\nexport function getLength(state: ColumnWidthState[]): number {\n return state.length;\n}\n\nexport function getColumnWidth(state: ColumnWidthState[], columnId: TableColumnId): number {\n const column = getColumnById(state, columnId);\n return column?.width ?? 0;\n}\n\n/**\n * This function takes the current state and returns an updated state, so that it can be set.\n * The reason for this is that we can update the state multiple times before commiting to render.\n * This is an optimization and also prevents flickering.\n * It also returns new copy of the state only if the value is different than the one currently in\n * the state, further preventing unnecessary updates.\n * @param localState\n * @param columnId\n * @param property\n * @param value\n * @returns\n */\nexport function setColumnProperty(\n localState: ColumnWidthState[],\n columnId: TableColumnId,\n property: keyof ColumnWidthState,\n value: number,\n): ColumnWidthState[] {\n const currentColumn = getColumnById(localState, columnId);\n\n if (!currentColumn || currentColumn?.[property] === value) {\n return localState;\n }\n\n const updatedColumn = { ...currentColumn, [property]: value };\n\n const newState = localState.reduce((acc, current) => {\n if (current.columnId === updatedColumn.columnId) {\n return [...acc, updatedColumn];\n }\n return [...acc, current];\n }, [] as ColumnWidthState[]);\n\n return newState;\n}\n\n/**\n * This function takes the state and container width and makes sure the each column in the state\n * is its optimal width, and that the columns\n * a) fit to the container\n * b) always fill the whole container\n * @param state\n * @param containerWidth\n * @returns\n */\nexport function adjustColumnWidthsToFitContainer(\n state: ColumnWidthState[],\n containerWidth: number,\n): ColumnWidthState[] {\n let newState = state;\n const totalWidth = getTotalWidth(newState);\n\n // The total width is smaller, we are expanding columns\n if (totalWidth < containerWidth) {\n let difference = containerWidth - totalWidth;\n let i = 0;\n // We start at the beginning and assign the columns their ideal width\n while (i < newState.length && difference > 0) {\n const currentCol = getColumnByIndex(newState, i);\n if (!currentCol) {\n break;\n }\n const colAdjustment = Math.min(currentCol.idealWidth - currentCol.width, difference);\n newState = setColumnProperty(newState, currentCol.columnId, 'width', currentCol.width + colAdjustment);\n difference -= colAdjustment;\n\n // if there is still empty space, after all columns are their ideal sizes, assign it to the last column\n if (i === newState.length - 1 && difference !== 0) {\n const lastCol = getColumnByIndex(newState, i);\n if (lastCol) {\n newState = setColumnProperty(newState, lastCol.columnId, 'width', lastCol.width + difference);\n }\n }\n\n i++;\n }\n }\n\n // The total width is larger than container, we need to squash the columns\n else if (totalWidth >= containerWidth) {\n let difference = totalWidth - containerWidth;\n // We start with the last column\n let j = newState.length - 1;\n while (j >= 0 && difference > 0) {\n const currentCol = getColumnByIndex(newState, j);\n if (!currentCol) {\n j--;\n continue;\n }\n if (currentCol.width > currentCol.minWidth) {\n const colAdjustment = Math.min(currentCol.width - currentCol.minWidth, difference);\n difference -= colAdjustment;\n newState = setColumnProperty(newState, currentCol.columnId, 'width', currentCol.width - colAdjustment);\n }\n j--;\n }\n }\n\n return newState;\n}\n"],"names":["DEFAULT_WIDTH","DEFAULT_MIN_WIDTH","columnDefinitionsToState","columns","state","columnSizingOptions","updated","stateMap","Map","map","s","columnId","updatedState","column","existingColumnState","get","idealWidth","minWidth","padding","width","defaultWidth","Math","max","length","find","col","getColumnById","c","getColumnByIndex","index","getTotalWidth","reduce","sum","getLength","getColumnWidth","setColumnProperty","localState","property","value","currentColumn","updatedColumn","newState","acc","current","adjustColumnWidthsToFitContainer","containerWidth","totalWidth","difference","i","currentCol","colAdjustment","min","lastCol","j"],"mappings":"AAEA,MAAMA,gBAAgB;AACtB,MAAMC,oBAAoB;AAE1B;;;;;;;;;CASC,GAED,OAAO,SAASC,yBACdC,OAAmC,EACnCC,QAA4B,EAAE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AAE;gBAC1C,MAAMiC,gBAAgB7B,KAAK8B,GAAG,CAACF,WAAW9B,KAAK,GAAG8B,WAAWhC,QAAQ,EAAE8B;gBACvEA,cAAcG;gBACdT,WAAWN,kBAAkBM,UAAUQ,WAAWtC,QAAQ,EAAE,SAASsC,WAAW9B,KAAK,GAAG+B;YAC1F;YACAG;QACF;IACF;IAEA,OAAOZ;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/isColumnSortable.ts"],"sourcesContent":["import { TableColumnDefinition } from '../hooks/types';\n\nexport function isColumnSortable(column: TableColumnDefinition<unknown>) {\n return column.compare.length > 0;\n}\n"],"names":["isColumnSortable","column","compare","length"],"mappings":"AAEA,OAAO,SAASA,iBAAiBC,MAAsC;IACrE,OAAOA,OAAOC,OAAO,CAACC,MAAM,GAAG;AACjC"}
|
|
1
|
+
{"version":3,"sources":["../src/utils/isColumnSortable.ts"],"sourcesContent":["import { TableColumnDefinition } from '../hooks/types';\n\nexport function isColumnSortable(column: TableColumnDefinition<unknown>): boolean {\n return column.compare.length > 0;\n}\n"],"names":["isColumnSortable","column","compare","length"],"mappings":"AAEA,OAAO,SAASA,iBAAiBC,MAAsC;IACrE,OAAOA,OAAOC,OAAO,CAACC,MAAM,GAAG;AACjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/DataGridBody/renderDataGridBody.tsx"],"sourcesContent":["/** @jsxRuntime automatic */\n/** @jsxImportSource @fluentui/react-jsx-runtime */\nimport { assertSlots } from '@fluentui/react-utilities';\nimport type { DataGridBodyState, DataGridBodySlots } from './DataGridBody.types';\nimport { TableRowIdContextProvider } from '../../contexts/rowIdContext';\n\n/**\n * Render the final JSX of DataGridBody\n */\nexport const renderDataGridBody_unstable = (state: DataGridBodyState) => {\n assertSlots<DataGridBodySlots>(state);\n\n return (\n <state.root>\n {state.rows.map(row => (\n <TableRowIdContextProvider key={row.rowId} value={row.rowId}>\n {state.renderRow(row)}\n </TableRowIdContextProvider>\n ))}\n </state.root>\n );\n};\n"],"names":["assertSlots","TableRowIdContextProvider","renderDataGridBody_unstable","state","root","rows","map","row","value","rowId","renderRow"],"mappings":";;;;+
|
|
1
|
+
{"version":3,"sources":["../src/components/DataGridBody/renderDataGridBody.tsx"],"sourcesContent":["/** @jsxRuntime automatic */\n/** @jsxImportSource @fluentui/react-jsx-runtime */\nimport { assertSlots } from '@fluentui/react-utilities';\nimport type { JSXElement } from '@fluentui/react-utilities';\nimport type { DataGridBodyState, DataGridBodySlots } from './DataGridBody.types';\nimport { TableRowIdContextProvider } from '../../contexts/rowIdContext';\n\n/**\n * Render the final JSX of DataGridBody\n */\nexport const renderDataGridBody_unstable = (state: DataGridBodyState): JSXElement => {\n assertSlots<DataGridBodySlots>(state);\n\n return (\n <state.root>\n {state.rows.map(row => (\n <TableRowIdContextProvider key={row.rowId} value={row.rowId}>\n {state.renderRow(row)}\n </TableRowIdContextProvider>\n ))}\n </state.root>\n );\n};\n"],"names":["assertSlots","TableRowIdContextProvider","renderDataGridBody_unstable","state","root","rows","map","row","value","rowId","renderRow"],"mappings":";;;;+BAUaE;;;;;;4BATb,gDAAiD;gCACrB,4BAA4B;8BAGd,8BAA8B;AAKjE,oCAAoC,CAACC;QAC1CH,2BAAAA,EAA+BG;IAE/B,OAAA,WAAA,OACE,eAAA,EAACA,MAAMC,IAAI,EAAA;kBACRD,MAAME,IAAI,CAACC,GAAG,CAACC,CAAAA,MAAAA,WAAAA,OACd,eAAA,EAACN,uCAAAA,EAAAA;gBAA0CO,OAAOD,IAAIE,KAAK;0BACxDN,MAAMO,SAAS,CAACH;eADaA,IAAIE,KAAK;;AAMjD,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/DataGridCell/renderDataGridCell.tsx"],"sourcesContent":["import type { DataGridCellState } from './DataGridCell.types';\nimport { renderTableCell_unstable } from '../TableCell/renderTableCell';\n\n/**\n * Render the final JSX of DataGridCell\n */\nexport const renderDataGridCell_unstable = (state: DataGridCellState) => {\n return renderTableCell_unstable(state);\n};\n"],"names":["renderTableCell_unstable","renderDataGridCell_unstable","state"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/components/DataGridCell/renderDataGridCell.tsx"],"sourcesContent":["import type { JSXElement } from '@fluentui/react-utilities';\nimport type { DataGridCellState } from './DataGridCell.types';\nimport { renderTableCell_unstable } from '../TableCell/renderTableCell';\n\n/**\n * Render the final JSX of DataGridCell\n */\nexport const renderDataGridCell_unstable = (state: DataGridCellState): JSXElement => {\n return renderTableCell_unstable(state);\n};\n"],"names":["renderTableCell_unstable","renderDataGridCell_unstable","state"],"mappings":";;;;;;;;;;iCAEyC,+BAA+B;AAKjE,MAAMC,8BAA8B,CAACC;IAC1C,WAAOF,yCAAAA,EAAyBE;AAClC,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/DataGridHeader/renderDataGridHeader.tsx"],"sourcesContent":["import { renderTableHeader_unstable } from '../TableHeader/renderTableHeader';\nimport type { DataGridHeaderState } from './DataGridHeader.types';\n\n/**\n * Render the final JSX of DataGridHeader\n */\nexport const renderDataGridHeader_unstable = (state: DataGridHeaderState) => {\n return renderTableHeader_unstable(state);\n};\n"],"names":["renderTableHeader_unstable","renderDataGridHeader_unstable","state"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/components/DataGridHeader/renderDataGridHeader.tsx"],"sourcesContent":["import type { JSXElement } from '@fluentui/react-utilities';\nimport { renderTableHeader_unstable } from '../TableHeader/renderTableHeader';\nimport type { DataGridHeaderState } from './DataGridHeader.types';\n\n/**\n * Render the final JSX of DataGridHeader\n */\nexport const renderDataGridHeader_unstable = (state: DataGridHeaderState): JSXElement => {\n return renderTableHeader_unstable(state);\n};\n"],"names":["renderTableHeader_unstable","renderDataGridHeader_unstable","state"],"mappings":";;;;;;;;;;mCAC2C,mCAAmC;AAMvE,MAAMC,gCAAgC,CAACC;IAC5C,WAAOF,6CAAAA,EAA2BE;AACpC,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/DataGridHeaderCell/renderDataGridHeaderCell.tsx"],"sourcesContent":["import type { DataGridHeaderCellState } from './DataGridHeaderCell.types';\nimport { renderTableHeaderCell_unstable } from '../TableHeaderCell/renderTableHeaderCell';\n\n/**\n * Render the final JSX of DataGridHeaderCell\n */\nexport const renderDataGridHeaderCell_unstable = (state: DataGridHeaderCellState) => {\n return renderTableHeaderCell_unstable(state);\n};\n"],"names":["renderTableHeaderCell_unstable","renderDataGridHeaderCell_unstable","state"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/components/DataGridHeaderCell/renderDataGridHeaderCell.tsx"],"sourcesContent":["import type { JSXElement } from '@fluentui/react-utilities';\nimport type { DataGridHeaderCellState } from './DataGridHeaderCell.types';\nimport { renderTableHeaderCell_unstable } from '../TableHeaderCell/renderTableHeaderCell';\n\n/**\n * Render the final JSX of DataGridHeaderCell\n */\nexport const renderDataGridHeaderCell_unstable = (state: DataGridHeaderCellState): JSXElement => {\n return renderTableHeaderCell_unstable(state);\n};\n"],"names":["renderTableHeaderCell_unstable","renderDataGridHeaderCell_unstable","state"],"mappings":";;;;;;;;;;uCAE+C,2CAA2C;AAKnF,MAAMC,oCAAoC,CAACC;IAChD,WAAOF,qDAAAA,EAA+BE;AACxC,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/DataGridRow/renderDataGridRow.tsx"],"sourcesContent":["/** @jsxRuntime automatic */\n/** @jsxImportSource @fluentui/react-jsx-runtime */\nimport { assertSlots } from '@fluentui/react-utilities';\nimport type { DataGridRowState, DataGridRowSlots } from './DataGridRow.types';\nimport { ColumnIdContextProvider } from '../../contexts/columnIdContext';\n\n/**\n * Render the final JSX of DataGridRow\n */\nexport const renderDataGridRow_unstable = (state: DataGridRowState) => {\n assertSlots<DataGridRowSlots>(state);\n\n return (\n <state.root>\n {state.selectionCell && <state.selectionCell />}\n {state.columnDefs.map(columnDef => (\n <ColumnIdContextProvider value={columnDef.columnId} key={columnDef.columnId}>\n {state.renderCell(columnDef, state.dataGridContextValue)}\n </ColumnIdContextProvider>\n ))}\n </state.root>\n );\n};\n"],"names":["assertSlots","ColumnIdContextProvider","renderDataGridRow_unstable","state","root","selectionCell","columnDefs","map","columnDef","value","columnId","renderCell","dataGridContextValue"],"mappings":";;;;+
|
|
1
|
+
{"version":3,"sources":["../src/components/DataGridRow/renderDataGridRow.tsx"],"sourcesContent":["/** @jsxRuntime automatic */\n/** @jsxImportSource @fluentui/react-jsx-runtime */\nimport { assertSlots } from '@fluentui/react-utilities';\nimport type { JSXElement } from '@fluentui/react-utilities';\nimport type { DataGridRowState, DataGridRowSlots } from './DataGridRow.types';\nimport { ColumnIdContextProvider } from '../../contexts/columnIdContext';\n\n/**\n * Render the final JSX of DataGridRow\n */\nexport const renderDataGridRow_unstable = (state: DataGridRowState): JSXElement => {\n assertSlots<DataGridRowSlots>(state);\n\n return (\n <state.root>\n {state.selectionCell && <state.selectionCell />}\n {state.columnDefs.map(columnDef => (\n <ColumnIdContextProvider value={columnDef.columnId} key={columnDef.columnId}>\n {state.renderCell(columnDef, state.dataGridContextValue)}\n </ColumnIdContextProvider>\n ))}\n </state.root>\n );\n};\n"],"names":["assertSlots","ColumnIdContextProvider","renderDataGridRow_unstable","state","root","selectionCell","columnDefs","map","columnDef","value","columnId","renderCell","dataGridContextValue"],"mappings":";;;;+BAUaE;;;;;;4BATb,iCAAiD;gCACrB,4BAA4B;iCAGhB,iCAAiC;AAKlE,mCAAmC,CAACC;QACzCH,2BAAAA,EAA8BG;IAE9B,OAAA,WAAA,OACE,gBAAA,EAACA,MAAMC,IAAI,EAAA;;YACRD,MAAME,aAAa,IAAA,WAAA,OAAI,eAAA,EAACF,MAAME,aAAa,EAAA,CAAA;YAC3CF,MAAMG,UAAU,CAACC,GAAG,CAACC,CAAAA,YAAAA,WAAAA,OACpB,eAAA,EAACP,wCAAAA,EAAAA;oBAAwBQ,OAAOD,UAAUE,QAAQ;8BAC/CP,MAAMQ,UAAU,CAACH,WAAWL,MAAMS,oBAAoB;mBADAJ,UAAUE,QAAQ;;;AAMnF,EAAE"}
|
|
@@ -69,12 +69,7 @@ const useDataGridRow_unstable = (props, ref)=>{
|
|
|
69
69
|
},
|
|
70
70
|
selectionCell: _reactutilities.slot.optional(props.selectionCell, {
|
|
71
71
|
renderByDefault: selectable,
|
|
72
|
-
elementType: _DataGridSelectionCell.DataGridSelectionCell
|
|
73
|
-
defaultProps: {
|
|
74
|
-
radioIndicator: {
|
|
75
|
-
disabled: isHeader
|
|
76
|
-
}
|
|
77
|
-
}
|
|
72
|
+
elementType: _DataGridSelectionCell.DataGridSelectionCell
|
|
78
73
|
}),
|
|
79
74
|
renderCell: props.children,
|
|
80
75
|
columnDefs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/DataGridRow/useDataGridRow.tsx"],"sourcesContent":["import * as React from 'react';\nimport { isInteractiveHTMLElement, useEventCallback, slot } from '@fluentui/react-utilities';\nimport { Space } from '@fluentui/keyboard-keys';\nimport type { DataGridRowProps, DataGridRowState } from './DataGridRow.types';\nimport { useTableRow_unstable } from '../TableRow/useTableRow';\nimport { dataGridContextDefaultValue, useDataGridContext_unstable } from '../../contexts/dataGridContext';\nimport { DataGridSelectionCell } from '../DataGridSelectionCell/DataGridSelectionCell';\nimport { useTableRowIdContext } from '../../contexts/rowIdContext';\nimport { useIsInTableHeader } from '../../contexts/tableHeaderContext';\n\n/**\n * Create the state required to render DataGridRow.\n *\n * The returned state can be modified with hooks such as useDataGridRowStyles_unstable,\n * before being passed to renderDataGridRow_unstable.\n *\n * @param props - props from this instance of DataGridRow\n * @param ref - reference to root HTMLElement of DataGridRow\n */\nexport const useDataGridRow_unstable = (props: DataGridRowProps, ref: React.Ref<HTMLElement>): DataGridRowState => {\n const rowId = useTableRowIdContext();\n const isHeader = useIsInTableHeader();\n const columnDefs = useDataGridContext_unstable(ctx => ctx.columns);\n const selectable = useDataGridContext_unstable(ctx => ctx.selectableRows);\n const selected = useDataGridContext_unstable(ctx => ctx.selection.isRowSelected(rowId));\n const focusMode = useDataGridContext_unstable(ctx => ctx.focusMode);\n const compositeRowTabsterAttribute = useDataGridContext_unstable(ctx => ctx.compositeRowTabsterAttribute);\n\n const tabbable = focusMode === 'row_unstable' || focusMode === 'composite';\n const appearance = useDataGridContext_unstable(ctx => {\n if (!isHeader && selectable && ctx.selection.isRowSelected(rowId)) {\n return ctx.selectionAppearance;\n }\n\n return 'none';\n });\n const toggleRow = useDataGridContext_unstable(ctx => ctx.selection.toggleRow);\n\n const onClick = useEventCallback((e: React.MouseEvent<HTMLTableRowElement>) => {\n if (selectable && !isHeader) {\n toggleRow(e, rowId);\n }\n\n props.onClick?.(e);\n });\n\n const onKeyDown = useEventCallback((e: React.KeyboardEvent<HTMLTableRowElement>) => {\n if (selectable && !isHeader && e.key === Space && !isInteractiveHTMLElement(e.target as HTMLElement)) {\n // stop scrolling\n e.preventDefault();\n toggleRow(e, rowId);\n }\n\n props.onKeyDown?.(e);\n });\n\n const baseState = useTableRow_unstable(\n {\n appearance,\n 'aria-selected': selectable ? selected : undefined,\n tabIndex: tabbable && !isHeader ? 0 : undefined,\n ...(focusMode === 'composite' && !isHeader && compositeRowTabsterAttribute),\n ...props,\n onClick,\n onKeyDown,\n children: null,\n as: 'div',\n },\n ref,\n );\n\n return {\n ...baseState,\n components: {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n ...baseState.components,\n selectionCell: DataGridSelectionCell,\n },\n selectionCell: slot.optional(props.selectionCell, {\n renderByDefault: selectable,\n elementType: DataGridSelectionCell,\n
|
|
1
|
+
{"version":3,"sources":["../src/components/DataGridRow/useDataGridRow.tsx"],"sourcesContent":["import * as React from 'react';\nimport { isInteractiveHTMLElement, useEventCallback, slot } from '@fluentui/react-utilities';\nimport { Space } from '@fluentui/keyboard-keys';\nimport type { DataGridRowProps, DataGridRowState } from './DataGridRow.types';\nimport { useTableRow_unstable } from '../TableRow/useTableRow';\nimport { dataGridContextDefaultValue, useDataGridContext_unstable } from '../../contexts/dataGridContext';\nimport { DataGridSelectionCell } from '../DataGridSelectionCell/DataGridSelectionCell';\nimport { useTableRowIdContext } from '../../contexts/rowIdContext';\nimport { useIsInTableHeader } from '../../contexts/tableHeaderContext';\n\n/**\n * Create the state required to render DataGridRow.\n *\n * The returned state can be modified with hooks such as useDataGridRowStyles_unstable,\n * before being passed to renderDataGridRow_unstable.\n *\n * @param props - props from this instance of DataGridRow\n * @param ref - reference to root HTMLElement of DataGridRow\n */\nexport const useDataGridRow_unstable = (props: DataGridRowProps, ref: React.Ref<HTMLElement>): DataGridRowState => {\n const rowId = useTableRowIdContext();\n const isHeader = useIsInTableHeader();\n const columnDefs = useDataGridContext_unstable(ctx => ctx.columns);\n const selectable = useDataGridContext_unstable(ctx => ctx.selectableRows);\n const selected = useDataGridContext_unstable(ctx => ctx.selection.isRowSelected(rowId));\n const focusMode = useDataGridContext_unstable(ctx => ctx.focusMode);\n const compositeRowTabsterAttribute = useDataGridContext_unstable(ctx => ctx.compositeRowTabsterAttribute);\n\n const tabbable = focusMode === 'row_unstable' || focusMode === 'composite';\n const appearance = useDataGridContext_unstable(ctx => {\n if (!isHeader && selectable && ctx.selection.isRowSelected(rowId)) {\n return ctx.selectionAppearance;\n }\n\n return 'none';\n });\n const toggleRow = useDataGridContext_unstable(ctx => ctx.selection.toggleRow);\n\n const onClick = useEventCallback((e: React.MouseEvent<HTMLTableRowElement>) => {\n if (selectable && !isHeader) {\n toggleRow(e, rowId);\n }\n\n props.onClick?.(e);\n });\n\n const onKeyDown = useEventCallback((e: React.KeyboardEvent<HTMLTableRowElement>) => {\n if (selectable && !isHeader && e.key === Space && !isInteractiveHTMLElement(e.target as HTMLElement)) {\n // stop scrolling\n e.preventDefault();\n toggleRow(e, rowId);\n }\n\n props.onKeyDown?.(e);\n });\n\n const baseState = useTableRow_unstable(\n {\n appearance,\n 'aria-selected': selectable ? selected : undefined,\n tabIndex: tabbable && !isHeader ? 0 : undefined,\n ...(focusMode === 'composite' && !isHeader && compositeRowTabsterAttribute),\n ...props,\n onClick,\n onKeyDown,\n children: null,\n as: 'div',\n },\n ref,\n );\n\n return {\n ...baseState,\n components: {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n ...baseState.components,\n selectionCell: DataGridSelectionCell,\n },\n selectionCell: slot.optional(props.selectionCell, {\n renderByDefault: selectable,\n elementType: DataGridSelectionCell,\n }),\n renderCell: props.children,\n columnDefs,\n // This context value should not be used internally\n // It's intended to help power user render functions\n dataGridContextValue: useStableDataGridContextValue(),\n };\n};\n\nfunction useStableDataGridContextValue() {\n const ref = React.useRef(dataGridContextDefaultValue);\n\n // Heads up!\n // We will not re-render when the context value changes, but we will have the latest value of the context when we do\n // render for other reasons.\n //\n // This relies on a context selector that always returns the same value:\n // - we will not re-render when the context value changes\n // - we will store the context value in a ref\n useDataGridContext_unstable(ctx => {\n ref.current = ctx;\n return null;\n });\n\n return ref.current!;\n}\n"],"names":["React","isInteractiveHTMLElement","useEventCallback","slot","Space","useTableRow_unstable","dataGridContextDefaultValue","useDataGridContext_unstable","DataGridSelectionCell","useTableRowIdContext","useIsInTableHeader","useDataGridRow_unstable","props","ref","rowId","isHeader","columnDefs","ctx","columns","selectable","selectableRows","selected","selection","isRowSelected","focusMode","compositeRowTabsterAttribute","tabbable","appearance","selectionAppearance","toggleRow","onClick","e","onKeyDown","key","target","preventDefault","baseState","undefined","tabIndex","children","as","components","selectionCell","optional","renderByDefault","elementType","renderCell","dataGridContextValue","useStableDataGridContextValue","useRef","current"],"mappings":";;;;+BAmBaW;;;;;;;iEAnBU,QAAQ;gCACkC,4BAA4B;8BACvE,0BAA0B;6BAEX,0BAA0B;iCACU,iCAAiC;uCACpE,iDAAiD;8BAClD,8BAA8B;oCAChC,oCAAoC;AAWhE,gCAAgC,CAACC,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A,QAAfpB,qBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,iBAAAA,IAAAA,CAAAA,OAAkBmB;IACpB;IAEA,MAAMK,gBAAY/B,iCAAAA,EAChB;QACEsB;QACA,iBAAiBR,aAAaE,WAAWgB;QACzCC,UAAUZ,YAAY,CAACX,WAAW,IAAIsB;QACtC,GAAIb,cAAc,eAAe,CAACT,YAAYU,4BAA4B;QAC1E,GAAGb,KAAK;QACRkB;QACAE;QACAO,UAAU;QACVC,IAAI;IACN,GACA3B;IAGF,OAAO;QACL,GAAGuB,SAAS;QACZK,YAAY;YACV,4DAA4D;YAC5D,GAAGL,UAAUK,UAAU;YACvBC,eAAelC,4CAAAA;QACjB;QACAkC,eAAevC,oBAAAA,CAAKwC,QAAQ,CAAC/B,MAAM8B,aAAa,EAAE;YAChDE,iBAAiBzB;YACjB0B,aAAarC,4CAAAA;QACf;QACAsC,YAAYlC,MAAM2B,QAAQ;QAC1BvB;QACA,mDAAmD;QACnD,oDAAoD;QACpD+B,sBAAsBC;IACxB;AACF,EAAE;AAEF,SAASA;IACP,MAAMnC,MAAMb,OAAMiD,MAAM,CAAC3C,4CAAAA;IAEzB,YAAY;IACZ,oHAAoH;IACpH,4BAA4B;IAC5B,EAAE;IACF,wEAAwE;IACxE,yDAAyD;IACzD,6CAA6C;QAC7CC,4CAAAA,EAA4BU,CAAAA;QAC1BJ,IAAIqC,OAAO,GAAGjC;QACd,OAAO;IACT;IAEA,OAAOJ,IAAIqC,OAAO;AACpB"}
|
|
@@ -18,39 +18,30 @@ _export(exports, {
|
|
|
18
18
|
});
|
|
19
19
|
const _react = require("@griffel/react");
|
|
20
20
|
const _useTableRowStylesstyles = require("../TableRow/useTableRowStyles.styles");
|
|
21
|
-
const _tableHeaderContext = require("../../contexts/tableHeaderContext");
|
|
22
21
|
const _dataGridContext = require("../../contexts/dataGridContext");
|
|
23
22
|
const dataGridRowClassNames = {
|
|
24
23
|
root: 'fui-DataGridRow',
|
|
25
24
|
selectionCell: 'fui-DataGridRow__selectionCell'
|
|
26
25
|
};
|
|
27
26
|
const useStyles = /*#__PURE__*/ (0, _react.__styles)({
|
|
28
|
-
singleSelectHeader: {
|
|
29
|
-
Bconypa: "f6fspww",
|
|
30
|
-
ff6mpl: "fqzoyx6"
|
|
31
|
-
},
|
|
32
27
|
subtleSelection: {
|
|
33
28
|
Bconypa: "f1jazu75",
|
|
34
29
|
ff6mpl: "fw60kww"
|
|
35
30
|
}
|
|
36
31
|
}, {
|
|
37
32
|
d: [
|
|
38
|
-
".f6fspww[data-fui-focus-within]:focus-within .fui-TableSelectionCell{opacity:0;}",
|
|
39
33
|
".f1jazu75[data-fui-focus-within]:focus-within .fui-TableSelectionCell{opacity:1;}"
|
|
40
34
|
],
|
|
41
35
|
h: [
|
|
42
|
-
".fqzoyx6:hover .fui-TableSelectionCell{opacity:0;}",
|
|
43
36
|
".fw60kww:hover .fui-TableSelectionCell{opacity:1;}"
|
|
44
37
|
]
|
|
45
38
|
});
|
|
46
39
|
const useDataGridRowStyles_unstable = (state)=>{
|
|
47
40
|
'use no memo';
|
|
48
|
-
const isHeader = (0, _tableHeaderContext.useIsInTableHeader)();
|
|
49
|
-
const isSingleSelect = (0, _dataGridContext.useDataGridContext_unstable)((ctx)=>ctx.selection.selectionMode === 'single');
|
|
50
41
|
const isSubtle = (0, _dataGridContext.useDataGridContext_unstable)((ctx)=>ctx.subtleSelection);
|
|
51
42
|
const styles = useStyles();
|
|
52
43
|
(0, _useTableRowStylesstyles.useTableRowStyles_unstable)(state);
|
|
53
|
-
state.root.className = (0, _react.mergeClasses)(dataGridRowClassNames.root, state.root.className, isSubtle && styles.subtleSelection
|
|
44
|
+
state.root.className = (0, _react.mergeClasses)(dataGridRowClassNames.root, state.root.className, isSubtle && styles.subtleSelection);
|
|
54
45
|
if (state.selectionCell) {
|
|
55
46
|
state.selectionCell.className = (0, _react.mergeClasses)(dataGridRowClassNames.selectionCell, state.selectionCell.className);
|
|
56
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useDataGridRowStyles.styles.js"],"sourcesContent":["import { makeStyles, mergeClasses } from '@griffel/react';\nimport { createCustomFocusIndicatorStyle } from '@fluentui/react-tabster';\nimport { useTableRowStyles_unstable } from '../TableRow/useTableRowStyles.styles';\nimport {
|
|
1
|
+
{"version":3,"sources":["useDataGridRowStyles.styles.js"],"sourcesContent":["import { makeStyles, mergeClasses } from '@griffel/react';\nimport { createCustomFocusIndicatorStyle } from '@fluentui/react-tabster';\nimport { useTableRowStyles_unstable } from '../TableRow/useTableRowStyles.styles';\nimport { useDataGridContext_unstable } from '../../contexts/dataGridContext';\nimport { tableSelectionCellClassNames } from '../TableSelectionCell/useTableSelectionCellStyles.styles';\nexport const dataGridRowClassNames = {\n root: 'fui-DataGridRow',\n selectionCell: 'fui-DataGridRow__selectionCell'\n};\nconst useStyles = makeStyles({\n subtleSelection: {\n ...createCustomFocusIndicatorStyle({\n [`& .${tableSelectionCellClassNames.root}`]: {\n opacity: 1\n }\n }, {\n selector: 'focus-within'\n }),\n ':hover': {\n [`& .${tableSelectionCellClassNames.root}`]: {\n opacity: 1\n }\n }\n }\n});\n/**\n * Apply styling to the DataGridRow slots based on the state\n */ export const useDataGridRowStyles_unstable = (state)=>{\n 'use no memo';\n const isSubtle = useDataGridContext_unstable((ctx)=>ctx.subtleSelection);\n const styles = useStyles();\n useTableRowStyles_unstable(state);\n state.root.className = mergeClasses(dataGridRowClassNames.root, state.root.className, isSubtle && styles.subtleSelection);\n if (state.selectionCell) {\n state.selectionCell.className = mergeClasses(dataGridRowClassNames.selectionCell, state.selectionCell.className);\n }\n return state;\n};\n"],"names":["__styles","mergeClasses","createCustomFocusIndicatorStyle","useTableRowStyles_unstable","useDataGridContext_unstable","tableSelectionCellClassNames","dataGridRowClassNames","root","selectionCell","useStyles","subtleSelection","Bconypa","ff6mpl","d","h","useDataGridRowStyles_unstable","state","isSubtle","ctx","styles","className"],"mappings":";;;;;;;;;;;IAKaM,qBAAqB;;;IAsBjBS,6BAA6B;;;;uBA3BL,gBAAgB;yCAEd,sCAAsC;iCACrC,gCAAgC;AAErE,8BAA8B;IACjCR,IAAI,EAAE,iBAAiB;IACvBC,aAAa,EAAE;AACnB,CAAC;AACD,MAAMC,SAAS,GAAA,WAAA,OAAGT,eAAA,EAAA;IAAAU,eAAA,EAAA;QAAAC,OAAA,EAAA;QAAAC,MAAA,EAAA;IAAA;AAAA,GAAA;IAAAC,CAAA,EAAA;QAAA;KAAA;IAAAC,CAAA,EAAA;QAAA;KAAA;AAAA,CAejB,CAAC;AAGS,uCAAuCE,KAAK,IAAG;IACtD,aAAa;IACb,MAAMC,QAAQ,OAAGb,4CAA2B,GAAEc,GAAG,GAAGA,GAAG,CAACR,eAAe,CAAC;IACxE,MAAMS,MAAM,GAAGV,SAAS,CAAC,CAAC;QAC1BN,mDAA0B,EAACa,KAAK,CAAC;IACjCA,KAAK,CAACT,IAAI,CAACa,SAAS,OAAGnB,mBAAY,EAACK,qBAAqB,CAACC,IAAI,EAAES,KAAK,CAACT,IAAI,CAACa,SAAS,EAAEH,QAAQ,IAAIE,MAAM,CAACT,eAAe,CAAC;IACzH,IAAIM,KAAK,CAACR,aAAa,EAAE;QACrBQ,KAAK,CAACR,aAAa,CAACY,SAAS,OAAGnB,mBAAY,EAACK,qBAAqB,CAACE,aAAa,EAAEQ,KAAK,CAACR,aAAa,CAACY,SAAS,CAAC;IACpH;IACA,OAAOJ,KAAK;AAChB,CAAC"}
|