|
129 | 129 | : 24; |
130 | 130 |
|
131 | 131 | let selectedRows = []; |
132 | | - let showExpandIconForId: number | null = null; |
133 | 132 | let spreadsheetContainer: SpreadsheetContainer; |
134 | 133 | let previouslyFocusedElement: Element | null = null; |
135 | 134 |
|
|
207 | 206 | width: getColumnWidth('$id', 250), |
208 | 207 | minimumWidth: 250, |
209 | 208 | draggable: false, |
| 209 | + sticky: $isSmallViewport ? undefined : { side: 'left', offset: 40 }, |
210 | 210 | type: 'string', |
211 | 211 | icon: IconFingerPrint, |
212 | 212 | isEditable: false, |
|
775 | 775 |
|
776 | 776 | $: canShowDatetimePopover = true; |
777 | 777 |
|
778 | | - $: if (table.fields) { |
| 778 | + $: if (table.fields && typeof $isSmallViewport === 'boolean') { |
779 | 779 | makeTableColumns(); |
780 | 780 | } |
781 | 781 |
|
|
789 | 789 | previouslyFocusedElement = null; |
790 | 790 | }); |
791 | 791 | } |
| 792 | +
|
| 793 | + function getSpreadsheetCellProps( |
| 794 | + rowId: string | undefined, |
| 795 | + columnId: string | undefined, |
| 796 | + state |
| 797 | + ) { |
| 798 | + if (columnId !== '$id' || !rowId || state?.isHeader || state?.isEmptyRow) { |
| 799 | + return undefined; |
| 800 | + } |
| 801 | +
|
| 802 | + return { |
| 803 | + style: ` |
| 804 | + --row-expand-opacity: ${state?.hovered ? '1' : '0'}; |
| 805 | + --row-expand-pointer-events: ${state?.hovered ? 'auto' : 'none'}; |
| 806 | + --row-expand-transform: ${state?.hovered ? 'translateX(0)' : 'translateX(4px)'}; |
| 807 | + ` |
| 808 | + }; |
| 809 | + } |
792 | 810 | </script> |
793 | 811 |
|
794 | 812 | <SpreadsheetContainer bind:this={spreadsheetContainer}> |
|
798 | 816 | allowSelection |
799 | 817 | useVirtualizer |
800 | 818 | keyboardNavigation |
| 819 | + showScrollbars |
801 | 820 | bind:selectedRows |
802 | 821 | selection={rowSelection} |
803 | 822 | bind:columns={$tableColumns} |
| 823 | + getCellProps={getSpreadsheetCellProps} |
804 | 824 | loading={$spreadsheetLoading} |
805 | 825 | emptyCells={emptyCellsCount} |
806 | 826 | rowCount={$paginatedRows.virtualLength} |
|
920 | 940 | {#each $tableColumns as { id: columnId, isEditable, hide } (columnId)} |
921 | 941 | {@const rowColumn = $columns.find((col) => col.key === columnId)} |
922 | 942 | {#if columnId === '$id' && !hide} |
923 | | - <button |
924 | | - on:mouseenter={() => { |
925 | | - showExpandIconForId = index; |
926 | | - }} |
927 | | - on:mouseleave={() => { |
928 | | - showExpandIconForId = null; |
929 | | - }}> |
930 | | - <Spreadsheet.Cell {root} {isEditable} column={columnId}> |
931 | | - <Layout.Stack |
932 | | - gap="none" |
933 | | - direction="row" |
934 | | - alignItems="center" |
935 | | - alignContent="center" |
936 | | - justifyContent="space-between"> |
937 | | - <Id value={row.$id} tooltipPortal tooltipDelay={200} |
938 | | - >{row.$id}</Id> |
939 | | - |
940 | | - <Popover let:show let:hide portal padding="none"> |
941 | | - {@const opacityValue = |
942 | | - showExpandIconForId === index ? '1' : '0'} |
943 | | - <button |
944 | | - on:mouseenter={show} |
945 | | - on:mouseleave={hide} |
946 | | - style:opacity={opacityValue} |
947 | | - style:transition="opacity 225ms ease-in-out"> |
948 | | - <Button.Button |
949 | | - size="xs" |
950 | | - icon |
951 | | - variant="secondary" |
952 | | - on:click={() => { |
953 | | - hide(); |
954 | | - previouslyFocusedElement = |
955 | | - document.activeElement; |
956 | | - $databaseRowSheetOptions.autoFocus = false; |
957 | | - onSelectSheetOption( |
958 | | - 'update', |
959 | | - null, |
960 | | - 'row', |
961 | | - row |
962 | | - ); |
963 | | - }}> |
964 | | - <Icon icon={IconArrowExpand} size="s" /> |
965 | | - </Button.Button> |
966 | | - </button> |
| 943 | + <Spreadsheet.Cell {root} {isEditable} column={columnId}> |
| 944 | + <Layout.Stack |
| 945 | + class="row-id-cell-content" |
| 946 | + gap="none" |
| 947 | + direction="row" |
| 948 | + alignItems="center" |
| 949 | + alignContent="center" |
| 950 | + justifyContent="space-between"> |
| 951 | + <Id value={row.$id} tooltipPortal tooltipDelay={200}> |
| 952 | + {row.$id} |
| 953 | + </Id> |
| 954 | + |
| 955 | + <Popover let:show let:hide portal padding="none"> |
| 956 | + <div |
| 957 | + class="row-expand-trigger" |
| 958 | + on:mouseenter={show} |
| 959 | + on:mouseleave={hide}> |
| 960 | + <Button.Button |
| 961 | + size="xs" |
| 962 | + icon |
| 963 | + variant="secondary" |
| 964 | + on:click={() => { |
| 965 | + hide(); |
| 966 | + previouslyFocusedElement = |
| 967 | + document.activeElement; |
| 968 | + $databaseRowSheetOptions.autoFocus = false; |
| 969 | + onSelectSheetOption( |
| 970 | + 'update', |
| 971 | + null, |
| 972 | + 'row', |
| 973 | + row |
| 974 | + ); |
| 975 | + }}> |
| 976 | + <Icon icon={IconArrowExpand} size="s" /> |
| 977 | + </Button.Button> |
| 978 | + </div> |
| 979 | + |
| 980 | + <svelte:fragment slot="tooltip"> |
| 981 | + <Layout.Stack |
| 982 | + inline |
| 983 | + gap="xxs" |
| 984 | + direction="row" |
| 985 | + alignItems="center" |
| 986 | + alignContent="center" |
| 987 | + style="padding: var(--gap-XS, 6px) var(--gap-S, 8px);"> |
| 988 | + Expand row |
967 | 989 |
|
968 | | - <svelte:fragment slot="tooltip"> |
969 | 990 | <Layout.Stack |
970 | 991 | inline |
971 | | - gap="xxs" |
| 992 | + gap="xxxs" |
972 | 993 | direction="row" |
973 | 994 | alignItems="center" |
974 | | - alignContent="center" |
975 | | - style="padding: var(--gap-XS, 6px) var(--gap-S, 8px);"> |
976 | | - Expand row |
977 | | - |
978 | | - <Layout.Stack |
979 | | - inline |
980 | | - gap="xxxs" |
981 | | - direction="row" |
982 | | - alignItems="center" |
983 | | - alignContent="center"> |
984 | | - <Keyboard size="s" key="⌘" /> |
985 | | - <Keyboard |
986 | | - key={'Enter'} |
987 | | - autoWidth |
988 | | - size="s" /> |
989 | | - </Layout.Stack> |
| 995 | + alignContent="center"> |
| 996 | + <Keyboard size="s" key="⌘" /> |
| 997 | + <Keyboard |
| 998 | + key={'Enter'} |
| 999 | + autoWidth |
| 1000 | + size="s" /> |
990 | 1001 | </Layout.Stack> |
991 | | - </svelte:fragment> |
992 | | - </Popover> |
993 | | - </Layout.Stack> |
994 | | - </Spreadsheet.Cell> |
995 | | - </button> |
| 1002 | + </Layout.Stack> |
| 1003 | + </svelte:fragment> |
| 1004 | + </Popover> |
| 1005 | + </Layout.Stack> |
| 1006 | + </Spreadsheet.Cell> |
996 | 1007 | {:else} |
997 | 1008 | <Spreadsheet.Cell {root} {isEditable} column={columnId}> |
998 | 1009 | {#if columnId === '$createdAt' || columnId === '$updatedAt'} |
|
1377 | 1388 | top: 0 !important; |
1378 | 1389 | } |
1379 | 1390 | } |
| 1391 | +
|
| 1392 | + .row-id-cell-content { |
| 1393 | + min-width: 0; |
| 1394 | + } |
| 1395 | +
|
| 1396 | + .row-expand-trigger { |
| 1397 | + display: flex; |
| 1398 | + flex: 0 0 auto; |
| 1399 | + opacity: var(--row-expand-opacity, 0); |
| 1400 | + pointer-events: var(--row-expand-pointer-events, none); |
| 1401 | + transition: |
| 1402 | + opacity 225ms ease-in-out, |
| 1403 | + transform 225ms ease-in-out; |
| 1404 | + transform: var(--row-expand-transform, translateX(4px)); |
| 1405 | + } |
1380 | 1406 | </style> |
0 commit comments