From ed8eecea2aed1651c7be28c10a3d8a0589bfad3a Mon Sep 17 00:00:00 2001 From: Chris Kruining Date: Tue, 17 Dec 2024 13:29:27 +0100 Subject: [PATCH] fix merge issues --- src/components/table/table.tsx | 112 +++++++++++++-------------------- 1 file changed, 43 insertions(+), 69 deletions(-) diff --git a/src/components/table/table.tsx b/src/components/table/table.tsx index 20b533b..c65b371 100644 --- a/src/components/table/table.tsx +++ b/src/components/table/table.tsx @@ -12,17 +12,12 @@ export type Column = { sortable?: boolean, group?: string, readonly groupBy?: (rows: DataSetRowNode[]) => DataSetNode[], - readonly groupBy?: (rows: DataSetRowNode[]) => DataSetNode[], }; -export type CellEditor, K extends keyof T> = (cell: { row: number, column: K, value: T[K] }) => JSX.Element; -export type CellEditors> = { [K in keyof T]?: CellEditor }; export type CellEditor, K extends keyof T> = (cell: { row: number, column: K, value: T[K] }) => JSX.Element; export type CellEditors> = { [K in keyof T]?: CellEditor }; export interface TableApi> { - readonly selection: Accessor[]>; - readonly rows: Accessor>; readonly selection: Accessor[]>; readonly rows: Accessor>; readonly columns: Accessor[]>; @@ -30,10 +25,6 @@ export interface TableApi> { clear(): void; } -interface TableContextType> { - readonly rows: Accessor>, - readonly columns: Accessor[]>, - readonly selection: Accessor[]>, interface TableContextType> { readonly rows: Accessor>, readonly columns: Accessor[]>, @@ -55,7 +46,6 @@ type TableProps> = { class?: string, summary?: string, rows: DataSet, - rows: DataSet, columns: Column[], selectionMode?: SelectionMode, children?: CellEditors, @@ -65,20 +55,18 @@ type TableProps> = { export function Table>(props: TableProps) { const [selection, setSelection] = createSignal[]>([]); - const rows = createMemo(() => props.rows); const rows = createMemo(() => props.rows); const columns = createMemo[]>(() => props.columns ?? []); const selectionMode = createMemo(() => props.selectionMode ?? SelectionMode.None); const cellRenderers = createMemo>(() => props.children ?? {}); const context: TableContextType = { - const context: TableContextType = { - rows, - columns, - selection, - selectionMode, - cellRenderers, - }; + rows, + columns, + selection, + selectionMode, + cellRenderers, + }; return @@ -89,12 +77,10 @@ export function Table>(props: TableProps) { ; }; -type InnerTableProps> = { class?: string, summary?: string, rows: DataSet }; type InnerTableProps> = { class?: string, summary?: string, rows: DataSet }; function InnerTable>(props: InnerTableProps) { const table = useTable(); - const table = useTable(); const selectable = createMemo(() => table.selectionMode() !== SelectionMode.None); const columnCount = createMemo(() => table.columns().length); @@ -109,9 +95,8 @@ function InnerTable>(props: InnerTableProps) { { - { - node => - } + node => + } {/* @@ -127,11 +112,8 @@ function InnerTable>(props: InnerTableProps) { function Api>(props: { api: undefined | ((api: TableApi) => any) }) { const table = useTable(); const selectionContext = useSelection(); - const table = useTable(); - const selectionContext = useSelection(); const api: TableApi = { - selection: selectionContext.selection, selection: selectionContext.selection, rows: table.rows, columns: table.columns, @@ -181,7 +163,6 @@ function Head(props: {}) { { ({ id, label, sortable }) => { - const sort = createMemo(() => table.rows().sort()); const sort = createMemo(() => table.rows().sort()); const by = String(id); @@ -219,53 +200,46 @@ function Head(props: {}) { }; function Node>(props: { node: DataSetNode, depth: number, groupedBy?: keyof T }) { - function Node>(props: { node: DataSetNode, depth: number, groupedBy?: keyof T }) { - return - { - row => - } + return + { + row => + } - { - group => - } - ; - } + { + group => + } + ; +} - function Row>(props: { key: keyof T, value: T, depth: number, groupedBy?: keyof T }) { - const table = useTable(); - const context = useSelection(); - const columns = table.columns; +function Row>(props: { key: keyof T, value: T, depth: number, groupedBy?: keyof T }) { + const table = useTable(); + const context = useSelection(); + const columns = table.columns; - function Row>(props: { key: keyof T, value: T, depth: number, groupedBy?: keyof T }) { - const table = useTable(); - const context = useSelection(); - const columns = table.columns; + const isSelected = context.isSelected(props.key); - const isSelected = context.isSelected(props.key); + return + + + context.select([props.key])} on:pointerdown={e => e.stopPropagation()} /> + + - return - - - context.select([props.key])} on:pointerdown={e => e.stopPropagation()} /> - - + { + ({ id }) => {table.cellRenderers()[id]?.({ row: props.key as number, column: id, value: props.value[id] }) ?? props.value[id]} + } + ; +}; - { - ({ id }) => {table.cellRenderers()[id]?.({ row: props.key as number, column: id, value: props.value[id] }) ?? props.value[id]} - } - ; - }; +function Group>(props: { key: keyof T, groupedBy: keyof T, nodes: DataSetNode[], depth: number }) { + const table = useTable(); - function Group>(props: { key: keyof T, groupedBy: keyof T, nodes: DataSetNode[], depth: number }) { - function Group>(props: { key: keyof T, groupedBy: keyof T, nodes: DataSetNode[], depth: number }) { - const table = useTable(); + return
+ {String(props.key)} + {String(props.key)} - return
- {String(props.key)} - {String(props.key)} - - { - node => - } -
; - }; \ No newline at end of file + { + node => + } +
; +}; \ No newline at end of file