apps improvements

This commit is contained in:
Ruben Fiszel
2023-01-04 18:37:42 +01:00
parent 47b498da80
commit 7437dc00aa
11 changed files with 62 additions and 50 deletions
+2 -2
View File
@@ -327,17 +327,17 @@
{:else if inputCat == 'date'}
<input {autofocus} class="inline-block" type="datetime-local" bind:value />
{:else if inputCat == 'sql' || inputCat == 'yaml'}
<div class="border mb-4 w-full border-gray-400">
<div class="border my-1 mb-4 w-full border-gray-400">
<SimpleEditor
on:focus={() => dispatch('focus')}
on:blur={() => dispatch('blur')}
bind:this={editor}
lang={inputCat}
bind:code={value}
class="few-lines-editor"
on:change={async () => {
dispatch('input', { rawValue: value, isRaw: false })
}}
autoHeight
/>
</div>
{:else if inputCat == 'base64'}
@@ -49,6 +49,7 @@
<div class="flex flex-row gap-x-1 w-full">
<Select
--height="34px"
value={collection.find((x) => x.value == value)}
bind:justValue={value}
items={collection}
@@ -36,6 +36,8 @@
<AlignWrapper {horizontalAlignment} {verticalAlignment}>
<Select
--height="34px"
class="select"
on:clear={onChange}
on:change={onChange}
{items}
@@ -28,7 +28,7 @@
let search: 'By Runnable' | 'By Component' | 'Disabled' | undefined = undefined
let searchValue = ''
let pagination: boolean | undefined = undefined
let pagination: boolean | undefined = true
$: setSearch(searchValue)
@@ -117,7 +117,6 @@
</script>
<InputValue {id} input={configuration.search} bind:value={search} />
<InputValue {id} input={configuration.pagination} bind:value={pagination} />
<RunnableWrapper bind:componentInput {id} bind:result>
{#if Array.isArray(result) && result.every(isObject)}
@@ -3,6 +3,7 @@
import { faDownload } from '@fortawesome/free-solid-svg-icons'
import type { Table } from '@tanstack/svelte-table'
import type { Readable } from 'svelte/store'
import { tableOptions } from './tableOptions'
type T = Record<string, any>
@@ -22,7 +23,7 @@
</script>
<div class="px-4 py-2 text-xs flex flex-row gap-2 items-center justify-between">
{#if paginationEnabled}
{#if paginationEnabled && result.length > (tableOptions.initialState?.pagination?.pageSize ?? 25)}
<div class="flex items-center gap-2 flex-row">
<Button
size="xs"
@@ -38,6 +38,5 @@
bind:this={input}
on:input={handleInput}
{placeholder}
class="h-full"
/>
</AlignWrapper>
@@ -124,7 +124,7 @@
<Grid
bind:items={$app.grid}
let:dataItem
rowHeight={30}
rowHeight={36}
cols={columnConfiguration}
fastStart={true}
on:pointerup={({ detail }) => selectComponent(detail.id)}
@@ -16,14 +16,16 @@
const { app, selectedComponent } = getContext<AppEditorContext>('AppEditorContext')
function getMinDimensionsByComponent(componentType: AppComponent['type'], column: number): Size {
function getRecommendedDimensionsByComponent(
componentType: AppComponent['type'],
column: number
): Size {
// Dimensions key formula: <mobile width>:<mobile height>-<desktop width>:<desktop height>
const dimensions: Record<`${number}:${number}-${number}:${number}`, AppComponent['type'][]> = {
'4:1-4:1': ['textcomponent'],
'2:1-2:1': ['buttoncomponent'],
'2:2-2:2': ['htmlcomponent'],
'4:2-4:2': [
'checkboxcomponent',
'1:1-3:1': ['textcomponent'],
'1:1-1:1': ['buttoncomponent', 'checkboxcomponent'],
'1:2-1:2': ['htmlcomponent'],
'2:1-3:1': [
'textinputcomponent',
'numberinputcomponent',
'selectcomponent',
@@ -31,14 +33,14 @@
'dateinputcomponent'
],
'3:5-6:5': ['formcomponent'],
'4:12-4:12': [
'2:8-6:8': [
'timeseriescomponent',
'barchartcomponent',
'piechartcomponent',
'displaycomponent',
'scatterchartcomponent'
],
'3:10-6:12': ['tablecomponent']
'3:10-6:10': ['tablecomponent']
}
// Finds the key that is associated with the component type and extracts the dimensions from it
const [dimension] = Object.entries(dimensions).find(([_, value]) =>
@@ -49,22 +51,6 @@
return { w: +size[0], h: +size[1] }
}
function getMaxDimensionsByComponent(componentType: AppComponent['type'], column: number): Size {
if (
[
'textinputcomponent',
'numberinputcomponent',
'selectcomponent',
'dateinputcomponent',
'passwordinputcomponent',
'buttoncomponent'
].includes(componentType)
) {
return { w: column, h: 2 }
}
return { w: column, h: 80 }
}
function addComponent(appComponent: AppComponent) {
$dirtyStore = true
const grid = $app.grid ?? []
@@ -90,12 +76,17 @@
}
gridColumns.forEach((column) => {
const min = getMinDimensionsByComponent(appComponent.type, column)
const max = getMaxDimensionsByComponent(appComponent.type, column)
const rec = getRecommendedDimensionsByComponent(appComponent.type, column)
newItem[column] = { ...newComponent, min, max, w: min.w, h: min.h }
newItem[column] = {
...newComponent,
min: { w: 1, h: 1 },
max: { w: column, h: 100 },
w: rec.w,
h: rec.h
}
const position = gridHelp.findSpace(newItem, grid, column) as { x: number; y: number }
newItem[column] = { ...newItem[column], ...position, min, max }
newItem[column] = { ...newItem[column], ...position }
})
$app.grid = [...grid, newItem]
@@ -5,6 +5,7 @@ const inputs: ComponentSet = {
title: 'Inputs',
components: [
{
softWrap: true,
verticalAlignment: 'center',
id: 'textinputcomponent',
type: 'textinputcomponent',
@@ -20,22 +21,39 @@ const inputs: ComponentSet = {
card: false
},
{
softWrap: true,
verticalAlignment: 'center',
id: 'passwordinputcomponent',
type: 'passwordinputcomponent',
componentInput: undefined,
configuration: {},
configuration: {
placeholder: {
type: 'static',
value: 'Password',
fieldType: 'text',
onlyStatic: true,
},
},
card: false
},
{
softWrap: true,
verticalAlignment: 'center',
id: 'numberinputcomponent',
type: 'numberinputcomponent',
componentInput: undefined,
configuration: {},
configuration: {
placeholder: {
type: 'static',
value: 'Type...',
fieldType: 'text',
onlyStatic: true,
},
},
card: false
},
{
softWrap: true,
verticalAlignment: 'center',
id: 'dateinputcomponent',
type: 'dateinputcomponent',
@@ -53,10 +71,10 @@ const inputs: ComponentSet = {
}
},
card: false,
softWrap: true
},
{
...defaultAlignement,
softWrap: true,
id: 'checkboxcomponent',
type: 'checkboxcomponent',
componentInput: undefined,
@@ -115,9 +133,8 @@ const buttons: ComponentSet = {
configuration: {
label: {
type: 'static',
fieldType: 'text',
value: 'Lorem ipsum'
value: 'Press me'
},
color: {
fieldType: 'select',
@@ -238,12 +255,6 @@ const display: ComponentSet = {
onlyStatic: true,
optionValuesKey: 'tableSearchOptions',
value: 'Disabled'
},
pagination: {
type: 'static',
onlyStatic: true,
fieldType: 'boolean',
value: true
}
},
componentInput: {
@@ -253,13 +264,13 @@ const display: ComponentSet = {
value: [
{
id: 1,
name: 'Lorem ipsum',
name: 'A cell with a long name',
age: 42
},
{
id: 2,
name: 'Lorem ipsum',
age: 42
name: 'A briefer cell',
age: 84
}
],
@@ -103,7 +103,7 @@
acc.push(componentInput.runnable.name)
}
if (componentInput.type === 'tablecomponent') {
if (componentInput?.type === 'tablecomponent') {
componentInput.actionButtons.forEach((actionButton) => {
if (actionButton.componentInput?.type === 'runnable') {
if (actionButton.componentInput.runnable?.type === 'runnableByName') {
@@ -1,3 +1,11 @@
export function defaultCode(component: string, language: string): string | undefined {
if (component === 'tablecomponent' && language === 'deno') {
return `export async function main(x: string) {
return [
{ foo: x, bar: 42 },
{ foo: "static", bar: 84 }]
}
`
}
return undefined
}