generated from surplex/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from surplex/feature/Adjust_tabula_concept
Feature/adjust tabula concept
- Loading branch information
Showing
16 changed files
with
201 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { ColumnDefinition } from "../ColumnDefinition"; | ||
import { RowDefinition } from "../RowDefinition"; | ||
|
||
export interface EditEvent { | ||
columnDefinition: ColumnDefinition; | ||
rowDefinition: RowDefinition; | ||
value: string; | ||
rawEvent: Event; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export interface HeaderDefinition { | ||
text: string; | ||
sortable: boolean; | ||
filterable: boolean; | ||
} | ||
prop: string; | ||
name: string; | ||
sortable: boolean; | ||
filterable: boolean; | ||
editable: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { ColumnDefinition } from "./ColumnDefinition"; | ||
export interface RowDefinition { | ||
columns: ColumnDefinition[]; | ||
prop: string; | ||
value: string; | ||
editable: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,57 @@ | ||
<script lang="ts"> | ||
import Column from "./Column.svelte"; | ||
import { onMount } from "svelte"; | ||
import { HeaderDefinition } from "./Interfaces/HeaderDefinition"; | ||
import { RowDefinition } from "./Interfaces/RowDefinition"; | ||
import { headerDefinitions } from "./stores"; | ||
import { createEventDispatcher } from "svelte"; | ||
export let row: Object; | ||
const dispatch = createEventDispatcher(); | ||
let tableData: RowDefinition[]; | ||
let editActive: boolean = false; | ||
export let rowDefinition: RowDefinition; | ||
headerDefinitions.subscribe((headerDefinitionsValue: HeaderDefinition[]) => { | ||
tableData = headerDefinitionsValue.map( | ||
(headerDefinition: HeaderDefinition) => { | ||
if (!Object.keys(row).includes(headerDefinition.prop)) { | ||
return; | ||
} | ||
return { | ||
prop: headerDefinition.prop, | ||
value: row[headerDefinition.prop], | ||
editable: headerDefinition.editable, | ||
}; | ||
} | ||
); | ||
}); | ||
const triggerEditEvent = ( | ||
event: KeyboardEvent, | ||
rowDefinition: RowDefinition | ||
) => { | ||
if (event.code != "Enter") { | ||
return; | ||
} | ||
editActive = false; | ||
dispatch("edit", { rowDefinition, rawEvent: event }); | ||
}; | ||
</script> | ||
|
||
<tr> | ||
{#each rowDefinition.columns as column} | ||
<Column on:edit columnDefinition={column} /> | ||
{#each tableData as rowDefinition} | ||
{#if $$slots[rowDefinition.prop]} | ||
<!-- TODO: Implement dynamic slots or another solution --> | ||
{:else} | ||
<td | ||
on:click={() => (rowDefinition.editable ? (editActive = true) : null)} | ||
> | ||
{#if rowDefinition.editable && editActive} | ||
<textarea | ||
on:keydown={(event) => triggerEditEvent(event, rowDefinition)} | ||
/> | ||
{:else} | ||
{rowDefinition.value} | ||
{/if} | ||
</td> | ||
{/if} | ||
{/each} | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
<script lang="ts"> | ||
import Row from "./Row.svelte"; | ||
import Header from "./Header.svelte"; | ||
import { HeaderDefinition } from "./Interfaces/HeaderDefinition"; | ||
import { RowDefinition } from "./Interfaces/RowDefinition"; | ||
export let headers: HeaderDefinition[] = []; | ||
export let data: RowDefinition[] = []; | ||
import { getContext, setContext } from "svelte"; | ||
import { optionsKey } from "./context"; | ||
export let options: any = undefined; | ||
setContext(optionsKey, { | ||
options, | ||
getClassesForElement: (element: string) => { | ||
if (!Object.keys(options).includes(element)) { | ||
return "default_style"; | ||
} | ||
return options[element].join(" "); | ||
} | ||
}); | ||
const { getClassesForElement } = getContext(optionsKey); | ||
</script> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
{#each headers as header} | ||
<Header on:sort on:filter headerDefinition={header} /> | ||
{/each} | ||
</tr> | ||
<table class={getClassesForElement("table")}> | ||
<thead class={getClassesForElement("thead")}> | ||
<slot name="head" /> | ||
</thead> | ||
<tbody> | ||
{#each data as row} | ||
<Row on:edit rowDefinition={row} /> | ||
{/each} | ||
<tbody class={getClassesForElement("tbody")}> | ||
<slot name="body" /> | ||
</tbody> | ||
</table> | ||
|
||
<style> | ||
.default_style { | ||
border: 1px solid black; | ||
padding: .5rem; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const optionsKey = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
export { RowDefinitionFactory } from "./Factory/RowDefinitionFactory"; | ||
export type { RowDefinition } from "./Interfaces/RowDefinition"; | ||
export type { ColumnDefinition } from "./Interfaces/ColumnDefinition"; | ||
export type { HeaderDefinition } from "./Interfaces/HeaderDefinition"; | ||
export type { RowDefinition } from "./Interfaces/RowDefinition"; | ||
export type { EditEvent } from "./Interfaces/Events/EditEvent"; | ||
export type { FilterEvent } from "./Interfaces/Events/FilterEvent"; | ||
export type { Sort, SortEvent } from "./Interfaces/Events/SortEvent"; | ||
export { default as Table } from "./Table.svelte"; | ||
export { default as Row } from "./Row.svelte"; | ||
export { default as Column } from "./Column.svelte"; | ||
export { default as Header } from "./Header.svelte"; | ||
export { default as Header } from "./Header.svelte"; | ||
export { default as SortFilter } from "./Filters/SortFilter.svelte"; | ||
export { default as TextFilter } from "./Filters/TextFilter.svelte"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Writable, writable } from "svelte/store"; | ||
import { HeaderDefinition } from "./Interfaces/HeaderDefinition"; | ||
|
||
export const headerDefinitions: Writable<Array<HeaderDefinition>> = writable(new Array<HeaderDefinition>()); |