Remove new row component and improve mouse interactions
This commit is contained in:
parent
dfd6633bee
commit
33a4d17278
|
@ -1,44 +1,145 @@
|
||||||
<script>
|
<script>
|
||||||
import SheetCell from "./cells/SheetCell.svelte"
|
import SheetCell from "./cells/SheetCell.svelte"
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
|
import { Icon } from "@budibase/bbui"
|
||||||
|
import SheetScrollWrapper from "./SheetScrollWrapper.svelte"
|
||||||
|
import { getCellRenderer } from "./renderers"
|
||||||
|
|
||||||
const { visibleColumns, hoveredRowId, rows, selectedCellId, reorder } =
|
const {
|
||||||
getContext("sheet")
|
visibleColumns,
|
||||||
|
hoveredRowId,
|
||||||
|
rows,
|
||||||
|
selectedCellId,
|
||||||
|
reorder,
|
||||||
|
stickyColumn,
|
||||||
|
} = getContext("sheet")
|
||||||
|
|
||||||
|
let isAdding = false
|
||||||
|
let newRow = {}
|
||||||
|
|
||||||
$: rowHovered = $hoveredRowId === "new"
|
$: rowHovered = $hoveredRowId === "new"
|
||||||
|
$: width = 40 + ($stickyColumn?.width || 0)
|
||||||
|
|
||||||
const addRow = async field => {
|
const addRow = async field => {
|
||||||
const newRow = await rows.actions.addRow()
|
// const newRow = await rows.actions.addRow()
|
||||||
if (newRow) {
|
// if (newRow) {
|
||||||
$selectedCellId = `${newRow._id}-${field.name}`
|
// $selectedCellId = `${newRow._id}-${field.name}`
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
$: console.log(newRow)
|
||||||
|
|
||||||
|
const startAdding = () => {
|
||||||
|
if (isAdding) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
newRow = {}
|
||||||
|
isAdding = true
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div class="new" on:click={startAdding}>
|
||||||
class="row"
|
{#if !isAdding}
|
||||||
on:focus
|
<div class="add">
|
||||||
on:mouseover={() => ($hoveredRowId = "new")}
|
<div class="icon">
|
||||||
on:mouseleave={() => ($hoveredRowId = null)}
|
<Icon name="Add" size="S" />
|
||||||
>
|
</div>
|
||||||
{#each $visibleColumns as column}
|
<div class="text">Add row</div>
|
||||||
<SheetCell
|
</div>
|
||||||
{rowHovered}
|
{:else}
|
||||||
on:click={() => addRow(column)}
|
<div class="sticky" style="flex: 0 0 {width}px">
|
||||||
width={column.width}
|
<SheetCell width="40" center>
|
||||||
left={column.left}
|
<Icon name="Add" size="S" />
|
||||||
reorderSource={$reorder.sourceColumn === column.name}
|
</SheetCell>
|
||||||
reorderTarget={$reorder.targetColumn === column.name}
|
{#if $stickyColumn}
|
||||||
/>
|
{@const cellId = `new-${$stickyColumn.name}`}
|
||||||
{/each}
|
<SheetCell
|
||||||
|
width={$stickyColumn.width}
|
||||||
|
selected={$selectedCellId === cellId}
|
||||||
|
on:click={() => ($selectedCellId = cellId)}
|
||||||
|
>
|
||||||
|
<svelte:component
|
||||||
|
this={getCellRenderer($stickyColumn)}
|
||||||
|
value={newRow[$stickyColumn.name]}
|
||||||
|
schema={$stickyColumn.schema}
|
||||||
|
selected={$selectedCellId === cellId}
|
||||||
|
onChange={val => (newRow[$stickyColumn.name] = val)}
|
||||||
|
readonly={$stickyColumn.schema.autocolumn}
|
||||||
|
/>
|
||||||
|
</SheetCell>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<SheetScrollWrapper scrollVertically={false}>
|
||||||
|
<div class="row">
|
||||||
|
{#each $visibleColumns as column}
|
||||||
|
{@const cellId = `new-${column.name}`}
|
||||||
|
<SheetCell
|
||||||
|
width={column.width}
|
||||||
|
selected={$selectedCellId === cellId}
|
||||||
|
on:click={() => ($selectedCellId = cellId)}
|
||||||
|
>
|
||||||
|
<svelte:component
|
||||||
|
this={getCellRenderer(column)}
|
||||||
|
value={newRow[column.name]}
|
||||||
|
schema={column.schema}
|
||||||
|
selected={$selectedCellId === cellId}
|
||||||
|
onChange={val => (newRow[column.name] = val)}
|
||||||
|
readonly={column.schema.autocolumn}
|
||||||
|
/>
|
||||||
|
</SheetCell>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</SheetScrollWrapper>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
.new {
|
||||||
|
display: flex;
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: calc(16px + var(--cell-height));
|
||||||
|
padding-bottom: 16px;
|
||||||
|
z-index: 1;
|
||||||
|
background: var(--cell-background);
|
||||||
|
border-top: var(--cell-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.add {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
.add:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
background: var(--cell-background-hover);
|
||||||
|
}
|
||||||
|
.add .icon {
|
||||||
|
flex: 0 0 40px;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
}
|
||||||
|
.add .text {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
padding: var(--cell-padding);
|
||||||
|
}
|
||||||
|
|
||||||
|
.new :global(.cell) {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sticky {
|
||||||
|
z-index: 2;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
/* Don't show borders between cells in the sticky column */
|
||||||
|
.sticky :global(.cell:not(:last-child)) {
|
||||||
|
border-right: none;
|
||||||
|
}
|
||||||
|
|
||||||
.row {
|
.row {
|
||||||
width: 0;
|
width: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
.row:hover :global(.cell) {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
import UserAvatars from "./UserAvatars.svelte"
|
import UserAvatars from "./UserAvatars.svelte"
|
||||||
import KeyboardManager from "./KeyboardManager.svelte"
|
import KeyboardManager from "./KeyboardManager.svelte"
|
||||||
import { clickOutside } from "@budibase/bbui"
|
import { clickOutside } from "@budibase/bbui"
|
||||||
|
import NewRow from "./NewRow.svelte"
|
||||||
|
|
||||||
export let API
|
export let API
|
||||||
export let tableId
|
export let tableId
|
||||||
|
@ -159,17 +160,17 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-items: flex-start;
|
justify-items: flex-start;
|
||||||
align-items: flex-start;
|
align-items: stretch;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
height: 0;
|
height: 0;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
background: var(--spectrum-global-color-gray-75);
|
||||||
}
|
}
|
||||||
.sheet-main {
|
.sheet-main {
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-self: stretch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Controls */
|
/* Controls */
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
<script>
|
<script>
|
||||||
import { getContext, onMount } from "svelte"
|
import { getContext, onMount } from "svelte"
|
||||||
import SheetScrollWrapper from "./SheetScrollWrapper.svelte"
|
import SheetScrollWrapper from "./SheetScrollWrapper.svelte"
|
||||||
import NewRow from "./NewRow.svelte"
|
|
||||||
import SheetRow from "./SheetRow.svelte"
|
import SheetRow from "./SheetRow.svelte"
|
||||||
|
|
||||||
const { bounds, visibleRows, config } = getContext("sheet")
|
const { bounds, visibleRows } = getContext("sheet")
|
||||||
|
|
||||||
let body
|
let body
|
||||||
|
|
||||||
|
@ -25,9 +24,6 @@
|
||||||
{#each $visibleRows as row, idx}
|
{#each $visibleRows as row, idx}
|
||||||
<SheetRow {row} {idx} />
|
<SheetRow {row} {idx} />
|
||||||
{/each}
|
{/each}
|
||||||
{#if $config.allowAddRows}
|
|
||||||
<NewRow />
|
|
||||||
{/if}
|
|
||||||
</SheetScrollWrapper>
|
</SheetScrollWrapper>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import { Checkbox, Icon } from "@budibase/bbui"
|
import { Checkbox } from "@budibase/bbui"
|
||||||
import SheetCell from "./cells/SheetCell.svelte"
|
import SheetCell from "./cells/SheetCell.svelte"
|
||||||
import { getCellRenderer } from "./renderers"
|
import { getCellRenderer } from "./renderers"
|
||||||
import SheetScrollWrapper from "./SheetScrollWrapper.svelte"
|
import SheetScrollWrapper from "./SheetScrollWrapper.svelte"
|
||||||
|
@ -51,18 +51,11 @@
|
||||||
return newState
|
return newState
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const addRow = async field => {
|
|
||||||
const newRow = await rows.actions.addRow()
|
|
||||||
if (newRow) {
|
|
||||||
$selectedCellId = `${newRow._id}-${field.name}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="sticky-column"
|
class="sticky-column"
|
||||||
style="--width:{width}px;"
|
style="flex: 0 0 {width}px"
|
||||||
class:scrolled={scrollLeft > 0}
|
class:scrolled={scrollLeft > 0}
|
||||||
>
|
>
|
||||||
<div class="header row">
|
<div class="header row">
|
||||||
|
@ -88,7 +81,11 @@
|
||||||
{@const rowSelected = !!$selectedRows[row._id]}
|
{@const rowSelected = !!$selectedRows[row._id]}
|
||||||
{@const rowHovered = $hoveredRowId === row._id}
|
{@const rowHovered = $hoveredRowId === row._id}
|
||||||
{@const containsSelectedRow = $selectedCellRow?._id === row._id}
|
{@const containsSelectedRow = $selectedCellRow?._id === row._id}
|
||||||
<div class="row" on:mouseenter={() => ($hoveredRowId = row._id)}>
|
<div
|
||||||
|
class="row"
|
||||||
|
on:mouseover={() => ($hoveredRowId = row._id)}
|
||||||
|
on:mouseleave={() => ($hoveredRowId = null)}
|
||||||
|
>
|
||||||
<SheetCell
|
<SheetCell
|
||||||
rowSelected={rowSelected || containsSelectedRow}
|
rowSelected={rowSelected || containsSelectedRow}
|
||||||
{rowHovered}
|
{rowHovered}
|
||||||
|
@ -138,38 +135,14 @@
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
{#if $config.allowAddRows}
|
|
||||||
<div
|
|
||||||
class="row new"
|
|
||||||
on:focus
|
|
||||||
on:mouseover={() => ($hoveredRowId = "new")}
|
|
||||||
>
|
|
||||||
<SheetCell
|
|
||||||
rowHovered={$hoveredRowId === "new"}
|
|
||||||
on:click={addRow}
|
|
||||||
width="40"
|
|
||||||
center
|
|
||||||
>
|
|
||||||
<Icon name="Add" size="S" />
|
|
||||||
</SheetCell>
|
|
||||||
{#if $stickyColumn}
|
|
||||||
<SheetCell
|
|
||||||
on:click={addRow}
|
|
||||||
width={$stickyColumn.width}
|
|
||||||
rowHovered={$hoveredRowId === "new"}
|
|
||||||
reorderTarget={$reorder.targetColumn === $stickyColumn.name}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</SheetScrollWrapper>
|
</SheetScrollWrapper>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.sticky-column {
|
.sticky-column {
|
||||||
flex: 0 0 var(--width);
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add shadow when scrolled */
|
/* Add shadow when scrolled */
|
||||||
|
@ -205,9 +178,7 @@
|
||||||
.content {
|
.content {
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
}
|
flex: 1 1 auto;
|
||||||
.row.new:hover :global(.cell) {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Styles for label cell */
|
/* Styles for label cell */
|
||||||
|
|
|
@ -110,7 +110,7 @@
|
||||||
<Icon
|
<Icon
|
||||||
size="S"
|
size="S"
|
||||||
name="MoreVertical"
|
name="MoreVertical"
|
||||||
color={`var(--spectrum-global-color-gray-600)`}
|
color="var(--spectrum-global-color-gray-600)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</SheetCell>
|
</SheetCell>
|
||||||
|
@ -147,15 +147,12 @@
|
||||||
.header-cell {
|
.header-cell {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header-cell :global(.cell) {
|
.header-cell :global(.cell) {
|
||||||
background: var(--background);
|
background: var(--background);
|
||||||
padding: 0 var(--cell-padding);
|
padding: 0 var(--cell-padding);
|
||||||
gap: calc(2 * var(--cell-spacing));
|
gap: calc(2 * var(--cell-spacing));
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
}
|
}
|
||||||
.header-cell.sorted :global(.cell) {
|
|
||||||
}
|
|
||||||
|
|
||||||
.name {
|
.name {
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
|
|
Loading…
Reference in New Issue