package.build.lib.features.Visibility.js.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of table-core Show documentation
Show all versions of table-core Show documentation
Headless UI for building powerful tables & datagrids for TS/JS.
The newest version!
{"version":3,"file":"Visibility.js","sources":["../../../src/features/Visibility.ts"],"sourcesContent":["import { TableFeature } from '../core/table'\nimport {\n Cell,\n Column,\n OnChangeFn,\n Table,\n Updater,\n Row,\n RowData,\n} from '../types'\nimport { makeStateUpdater, memo } from '../utils'\n\nexport type VisibilityState = Record\n\nexport interface VisibilityTableState {\n columnVisibility: VisibilityState\n}\n\nexport interface VisibilityOptions {\n onColumnVisibilityChange?: OnChangeFn\n enableHiding?: boolean\n}\n\nexport interface VisibilityDefaultOptions {\n onColumnVisibilityChange: OnChangeFn\n}\n\nexport interface VisibilityInstance {\n getVisibleFlatColumns: () => Column[]\n getVisibleLeafColumns: () => Column[]\n getLeftVisibleLeafColumns: () => Column[]\n getRightVisibleLeafColumns: () => Column[]\n getCenterVisibleLeafColumns: () => Column[]\n setColumnVisibility: (updater: Updater) => void\n resetColumnVisibility: (defaultState?: boolean) => void\n toggleAllColumnsVisible: (value?: boolean) => void\n getIsAllColumnsVisible: () => boolean\n getIsSomeColumnsVisible: () => boolean\n getToggleAllColumnsVisibilityHandler: () => (event: unknown) => void\n}\n\nexport interface VisibilityColumnDef {\n enableHiding?: boolean\n}\n\nexport interface VisibilityRow {\n _getAllVisibleCells: () => Cell[]\n getVisibleCells: () => Cell[]\n}\n\nexport interface VisibilityColumn {\n getCanHide: () => boolean\n getIsVisible: () => boolean\n toggleVisibility: (value?: boolean) => void\n getToggleVisibilityHandler: () => (event: unknown) => void\n}\n\n//\n\nexport const Visibility: TableFeature = {\n getInitialState: (state): VisibilityTableState => {\n return {\n columnVisibility: {},\n ...state,\n }\n },\n\n getDefaultOptions: (\n table: Table\n ): VisibilityDefaultOptions => {\n return {\n onColumnVisibilityChange: makeStateUpdater('columnVisibility', table),\n }\n },\n\n createColumn: (\n column: Column,\n table: Table\n ): VisibilityColumn => {\n return {\n toggleVisibility: value => {\n if (column.getCanHide()) {\n table.setColumnVisibility(old => ({\n ...old,\n [column.id]: value ?? !column.getIsVisible(),\n }))\n }\n },\n getIsVisible: () => {\n return table.getState().columnVisibility?.[column.id] ?? true\n },\n\n getCanHide: () => {\n return (\n (column.columnDef.enableHiding ?? true) &&\n (table.options.enableHiding ?? true)\n )\n },\n getToggleVisibilityHandler: () => {\n return (e: unknown) => {\n column.toggleVisibility?.(\n ((e as MouseEvent).target as HTMLInputElement).checked\n )\n }\n },\n }\n },\n\n createRow: (\n row: Row,\n table: Table\n ): VisibilityRow => {\n return {\n _getAllVisibleCells: memo(\n () => [row.getAllCells(), table.getState().columnVisibility],\n cells => {\n return cells.filter(cell => cell.column.getIsVisible())\n },\n {\n key:\n process.env.NODE_ENV === 'production' && 'row._getAllVisibleCells',\n debug: () => table.options.debugAll ?? table.options.debugRows,\n }\n ),\n getVisibleCells: memo(\n () => [\n row.getLeftVisibleCells(),\n row.getCenterVisibleCells(),\n row.getRightVisibleCells(),\n ],\n (left, center, right) => [...left, ...center, ...right],\n {\n key: process.env.NODE_ENV === 'development' && 'row.getVisibleCells',\n debug: () => table.options.debugAll ?? table.options.debugRows,\n }\n ),\n }\n },\n\n createTable: (\n table: Table\n ): VisibilityInstance => {\n const makeVisibleColumnsMethod = (\n key: string,\n getColumns: () => Column[]\n ): (() => Column[]) => {\n return memo(\n () => [\n getColumns(),\n getColumns()\n .filter(d => d.getIsVisible())\n .map(d => d.id)\n .join('_'),\n ],\n columns => {\n return columns.filter(d => d.getIsVisible?.())\n },\n {\n key,\n debug: () => table.options.debugAll ?? table.options.debugColumns,\n }\n )\n }\n\n return {\n getVisibleFlatColumns: makeVisibleColumnsMethod(\n 'getVisibleFlatColumns',\n () => table.getAllFlatColumns()\n ),\n getVisibleLeafColumns: makeVisibleColumnsMethod(\n 'getVisibleLeafColumns',\n () => table.getAllLeafColumns()\n ),\n getLeftVisibleLeafColumns: makeVisibleColumnsMethod(\n 'getLeftVisibleLeafColumns',\n () => table.getLeftLeafColumns()\n ),\n getRightVisibleLeafColumns: makeVisibleColumnsMethod(\n 'getRightVisibleLeafColumns',\n () => table.getRightLeafColumns()\n ),\n getCenterVisibleLeafColumns: makeVisibleColumnsMethod(\n 'getCenterVisibleLeafColumns',\n () => table.getCenterLeafColumns()\n ),\n\n setColumnVisibility: updater =>\n table.options.onColumnVisibilityChange?.(updater),\n\n resetColumnVisibility: defaultState => {\n table.setColumnVisibility(\n defaultState ? {} : table.initialState.columnVisibility ?? {}\n )\n },\n\n toggleAllColumnsVisible: value => {\n value = value ?? !table.getIsAllColumnsVisible()\n\n table.setColumnVisibility(\n table.getAllLeafColumns().reduce(\n (obj, column) => ({\n ...obj,\n [column.id]: !value ? !column.getCanHide?.() : value,\n }),\n {}\n )\n )\n },\n\n getIsAllColumnsVisible: () =>\n !table.getAllLeafColumns().some(column => !column.getIsVisible?.()),\n\n getIsSomeColumnsVisible: () =>\n table.getAllLeafColumns().some(column => column.getIsVisible?.()),\n\n getToggleAllColumnsVisibilityHandler: () => {\n return (e: unknown) => {\n table.toggleAllColumnsVisible(\n ((e as MouseEvent).target as HTMLInputElement)?.checked\n )\n }\n },\n }\n },\n}\n"],"names":["Visibility","getInitialState","state","columnVisibility","getDefaultOptions","table","onColumnVisibilityChange","makeStateUpdater","createColumn","column","toggleVisibility","value","getCanHide","setColumnVisibility","old","id","getIsVisible","_table$getState$colum","_table$getState$colum2","getState","_column$columnDef$ena","_table$options$enable","columnDef","enableHiding","options","getToggleVisibilityHandler","e","target","checked","createRow","row","_getAllVisibleCells","memo","getAllCells","cells","filter","cell","key","process","env","NODE_ENV","debug","_table$options$debugA","debugAll","debugRows","getVisibleCells","getLeftVisibleCells","getCenterVisibleCells","getRightVisibleCells","left","center","right","_table$options$debugA2","createTable","makeVisibleColumnsMethod","getColumns","d","map","join","columns","_table$options$debugA3","debugColumns","getVisibleFlatColumns","getAllFlatColumns","getVisibleLeafColumns","getAllLeafColumns","getLeftVisibleLeafColumns","getLeftLeafColumns","getRightVisibleLeafColumns","getRightLeafColumns","getCenterVisibleLeafColumns","getCenterLeafColumns","updater","resetColumnVisibility","defaultState","_table$initialState$c","initialState","toggleAllColumnsVisible","_value","getIsAllColumnsVisible","reduce","obj","some","getIsSomeColumnsVisible","getToggleAllColumnsVisibilityHandler","_target"],"mappings":";;;;;;;;;;;;;;;;AAyDA;;AAEO,MAAMA,UAAwB,GAAG;EACtCC,eAAe,EAAGC,KAAK,IAA2B;IAChD,OAAO;MACLC,gBAAgB,EAAE,EAAE;MACpB,GAAGD,KAAAA;KACJ,CAAA;GACF;EAEDE,iBAAiB,EACfC,KAAmB,IACU;IAC7B,OAAO;AACLC,MAAAA,wBAAwB,EAAEC,sBAAgB,CAAC,kBAAkB,EAAEF,KAAK,CAAA;KACrE,CAAA;GACF;AAEDG,EAAAA,YAAY,EAAEA,CACZC,MAA6B,EAC7BJ,KAAmB,KACE;IACrB,OAAO;MACLK,gBAAgB,EAAEC,KAAK,IAAI;AACzB,QAAA,IAAIF,MAAM,CAACG,UAAU,EAAE,EAAE;AACvBP,UAAAA,KAAK,CAACQ,mBAAmB,CAACC,GAAG,KAAK;AAChC,YAAA,GAAGA,GAAG;AACN,YAAA,CAACL,MAAM,CAACM,EAAE,GAAGJ,KAAK,IAAA,IAAA,GAALA,KAAK,GAAI,CAACF,MAAM,CAACO,YAAY,EAAC;AAC7C,WAAC,CAAC,CAAC,CAAA;AACL,SAAA;OACD;MACDA,YAAY,EAAEA,MAAM;QAAA,IAAAC,qBAAA,EAAAC,sBAAA,CAAA;QAClB,OAAAD,CAAAA,qBAAA,IAAAC,sBAAA,GAAOb,KAAK,CAACc,QAAQ,EAAE,CAAChB,gBAAgB,KAAjCe,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,sBAAA,CAAoCT,MAAM,CAACM,EAAE,CAAC,KAAA,IAAA,GAAAE,qBAAA,GAAI,IAAI,CAAA;OAC9D;MAED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