Merge branch 'master' into fix/respect-grid-config

This commit is contained in:
Adria Navarro 2024-12-31 12:55:24 +01:00 committed by GitHub
commit 530d390e52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 130 additions and 61 deletions

View File

@ -37,7 +37,7 @@
} }
} }
export let overBackground export let overBackground = false
</script> </script>
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->

View File

@ -0,0 +1,7 @@
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"
const config = {
preprocess: vitePreprocess(),
}
export default config

View File

@ -1,4 +1,4 @@
<script> <script lang="ts">
import { setContext, onMount } from "svelte" import { setContext, onMount } from "svelte"
import { writable, derived } from "svelte/store" import { writable, derived } from "svelte/store"
import { fade } from "svelte/transition" import { fade } from "svelte/transition"
@ -53,17 +53,16 @@
const gridID = `grid-${Math.random().toString().slice(2)}` const gridID = `grid-${Math.random().toString().slice(2)}`
// Store props in a store for reference in other stores // Store props in a store for reference in other stores
const props = writable($$props) const props: any = writable($$props)
// Build up context // Build up context
let context = { let context = attachStores({
API: API || createAPIClient(), API: API || createAPIClient(),
Constants, Constants,
gridID, gridID,
props, props,
} ...createEventManagers(),
context = { ...context, ...createEventManagers() } })
context = attachStores(context)
// Reference some stores for local use // Reference some stores for local use
const { const {

View File

@ -2,11 +2,11 @@ import { createEventDispatcher } from "svelte"
export const createEventManagers = () => { export const createEventManagers = () => {
const svelteDispatch = createEventDispatcher() const svelteDispatch = createEventDispatcher()
let subscribers = {} let subscribers: Record<string, ((...params: any) => void)[]> = {}
// Dispatches an event, notifying subscribers and also emitting a normal // Dispatches an event, notifying subscribers and also emitting a normal
// svelte event // svelte event
const dispatch = (event, payload) => { const dispatch = (event: string, payload: any) => {
svelteDispatch(event, payload) svelteDispatch(event, payload)
const subs = subscribers[event] || [] const subs = subscribers[event] || []
for (let i = 0; i < subs.length; i++) { for (let i = 0; i < subs.length; i++) {
@ -15,7 +15,7 @@ export const createEventManagers = () => {
} }
// Subscribes to events // Subscribes to events
const subscribe = (event, callback) => { const subscribe = (event: string, callback: () => void) => {
const subs = subscribers[event] || [] const subs = subscribers[event] || []
subscribers[event] = [...subs, callback] subscribers[event] = [...subs, callback]

View File

@ -1,16 +0,0 @@
import { derived, writable } from "svelte/store"
export const createStores = () => {
const bounds = writable({
left: 0,
top: 0,
width: 0,
height: 0,
})
// Derive height and width as primitives to avoid wasted computation
const width = derived(bounds, $bounds => $bounds.width, 0)
const height = derived(bounds, $bounds => $bounds.height, 0)
return { bounds, height, width }
}

View File

@ -0,0 +1,29 @@
import { derived, Readable, Writable, writable } from "svelte/store"
interface BoundsStore {
bounds: Writable<{
left: number
top: number
width: number
height: number
}>
height: Readable<number>
width: Readable<number>
}
export type Store = BoundsStore
export const createStores = (): BoundsStore => {
const bounds = writable({
left: 0,
top: 0,
width: 0,
height: 0,
})
// Derive height and width as primitives to avoid wasted computation
const width = derived(bounds, $bounds => $bounds.width, 0)
const height = derived(bounds, $bounds => $bounds.height, 0)
return { bounds, height, width }
}

View File

@ -1,16 +1,31 @@
export const createActions = context => { import { FindTableResponse } from "@budibase/types"
import { Store as StoreContext } from "."
interface CacheActionStore {
cache: {
actions: {
getPrimaryDisplayForTableId: (tableId: string) => Promise<string>
getTable: (tableId: string) => Promise<FindTableResponse>
resetCache: () => any
}
}
}
export type Store = CacheActionStore
export const createActions = (context: StoreContext): CacheActionStore => {
const { API } = context const { API } = context
// Cache for the primary display columns of different tables. // Cache for the primary display columns of different tables.
// If we ever need to cache table definitions for other purposes then we can // If we ever need to cache table definitions for other purposes then we can
// expand this to be a more generic cache. // expand this to be a more generic cache.
let tableCache = {} let tableCache: Record<string, Promise<FindTableResponse>> = {}
const resetCache = () => { const resetCache = () => {
tableCache = {} tableCache = {}
} }
const fetchTable = async tableId => { const fetchTable = async (tableId: string) => {
// If we've never encountered this tableId before then store a promise that // If we've never encountered this tableId before then store a promise that
// resolves to the primary display so that subsequent invocations before the // resolves to the primary display so that subsequent invocations before the
// promise completes can reuse this promise // promise completes can reuse this promise
@ -21,13 +36,13 @@ export const createActions = context => {
return await tableCache[tableId] return await tableCache[tableId]
} }
const getPrimaryDisplayForTableId = async tableId => { const getPrimaryDisplayForTableId = async (tableId: string) => {
const table = await fetchTable(tableId) const table = await fetchTable(tableId)
const display = table?.primaryDisplay || table?.schema?.[0]?.name const display = table?.primaryDisplay || table?.schema?.[0]?.name
return display return display
} }
const getTable = async tableId => { const getTable = async (tableId: string) => {
const table = await fetchTable(tableId) const table = await fetchTable(tableId)
return table return table
} }
@ -43,7 +58,7 @@ export const createActions = context => {
} }
} }
export const initialise = context => { export const initialise = (context: StoreContext) => {
const { datasource, cache } = context const { datasource, cache } = context
// Wipe the caches whenever the datasource changes to ensure we aren't // Wipe the caches whenever the datasource changes to ensure we aren't

View File

@ -122,7 +122,7 @@ export const initialise = (context: StoreContext) => {
} }
$fetch?.update({ $fetch?.update({
sortOrder: $sort.order || SortOrder.ASCENDING, sortOrder: $sort.order || SortOrder.ASCENDING,
sortColumn: $sort.column, sortColumn: $sort.column ?? undefined,
}) })
}) })
) )

View File

@ -139,7 +139,7 @@ export const initialise = (context: StoreContext) => {
} }
$fetch.update({ $fetch.update({
sortOrder: $sort.order || SortOrder.ASCENDING, sortOrder: $sort.order || SortOrder.ASCENDING,
sortColumn: $sort.column, sortColumn: $sort.column ?? undefined,
}) })
}) })
) )

View File

@ -173,7 +173,7 @@ export const initialise = (context: StoreContext) => {
await datasource.actions.saveDefinition({ await datasource.actions.saveDefinition({
...$view, ...$view,
sort: { sort: {
field: $sort.column, field: $sort.column!,
order: $sort.order || SortOrder.ASCENDING, order: $sort.order || SortOrder.ASCENDING,
}, },
}) })
@ -187,7 +187,7 @@ export const initialise = (context: StoreContext) => {
} }
$fetch.update({ $fetch.update({
sortOrder: $sort.order, sortOrder: $sort.order,
sortColumn: $sort.column, sortColumn: $sort.column ?? undefined,
}) })
}) })
) )

View File

@ -1,4 +1,4 @@
import { Readable, Writable } from "svelte/store" import { Writable } from "svelte/store"
import type { APIClient } from "../../../api/types" import type { APIClient } from "../../../api/types"
import * as Bounds from "./bounds" import * as Bounds from "./bounds"
@ -25,6 +25,7 @@ import * as NonPlus from "./datasources/nonPlus"
import * as Cache from "./cache" import * as Cache from "./cache"
import * as Conditions from "./conditions" import * as Conditions from "./conditions"
import { SortOrder, UIDatasource, UISearchFilter } from "@budibase/types" import { SortOrder, UIDatasource, UISearchFilter } from "@budibase/types"
import * as Constants from "../lib/constants"
const DependencyOrderedStores = [ const DependencyOrderedStores = [
Sort, Sort,
@ -73,12 +74,16 @@ export interface BaseStoreProps {
canEditColumns?: boolean canEditColumns?: boolean
canExpandRows?: boolean canExpandRows?: boolean
canSaveSchema?: boolean canSaveSchema?: boolean
minHeight?: number
} }
export interface BaseStore { export interface BaseStore {
API: APIClient API: APIClient
gridID: string gridID: string
props: Writable<BaseStoreProps> props: Writable<BaseStoreProps>
subscribe: any
dispatch: (event: string, data: any) => any
Constants: typeof Constants
} }
export type Store = BaseStore & export type Store = BaseStore &
@ -93,22 +98,19 @@ export type Store = BaseStore &
Filter.Store & Filter.Store &
UI.Store & UI.Store &
Clipboard.Store & Clipboard.Store &
Scroll.Store & { Scroll.Store &
// TODO while typing the rest of stores Rows.Store &
sort: Writable<any>
subscribe: any
dispatch: (event: string, data: any) => any
notifications: Writable<any>
width: Writable<number>
bounds: Readable<any>
height: Readable<number>
} & Rows.Store &
Reorder.Store & Reorder.Store &
Resize.Store & Resize.Store &
Config.Store & Config.Store &
Conditions.Store Conditions.Store &
Cache.Store &
Viewport.Store &
Notifications.Store &
Sort.Store &
Bounds.Store
export const attachStores = (context: Store): Store => { export const attachStores = (context: BaseStore): Store => {
// Atomic store creation // Atomic store creation
for (let store of DependencyOrderedStores) { for (let store of DependencyOrderedStores) {
if ("createStores" in store) { if ("createStores" in store) {

View File

@ -1,7 +1,17 @@
import { notifications as BBUINotifications } from "@budibase/bbui" import { notifications as BBUINotifications } from "@budibase/bbui"
import { derived } from "svelte/store" import { derived, Readable } from "svelte/store"
import { Store as StoreContext } from "."
export const createStores = context => { interface NotificationStore {
notifications: Readable<{
success: (message: string) => void
error: (message: string) => void
}>
}
export type Store = NotificationStore
export const createStores = (context: StoreContext): NotificationStore => {
const { notifySuccess, notifyError } = context const { notifySuccess, notifyError } = context
// Normally we would not derive a store in "createStores" as it should be // Normally we would not derive a store in "createStores" as it should be

View File

@ -1,6 +1,7 @@
import { derived } from "svelte/store" import { derived } from "svelte/store"
import { Store as StoreContext } from "."
export const initialise = context => { export const initialise = (context: StoreContext) => {
const { scrolledRowCount, rows, visualRowCapacity } = context const { scrolledRowCount, rows, visualRowCapacity } = context
// Derive how many rows we have in total // Derive how many rows we have in total

View File

@ -1,8 +1,18 @@
import { derived, get } from "svelte/store" import { derived, get, Writable } from "svelte/store"
import { memo } from "../../../utils" import { memo } from "../../../utils"
import { SortOrder } from "@budibase/types" import { SortOrder } from "@budibase/types"
import { Store as StoreContext } from "."
export const createStores = context => { interface SortStore {
sort: Writable<{
column: string | null | undefined
order: SortOrder
}>
}
export type Store = SortStore
export const createStores = (context: StoreContext): SortStore => {
const { props } = context const { props } = context
const $props = get(props) const $props = get(props)
@ -17,7 +27,7 @@ export const createStores = context => {
} }
} }
export const initialise = context => { export const initialise = (context: StoreContext) => {
const { sort, initialSortColumn, initialSortOrder, schema } = context const { sort, initialSortColumn, initialSortOrder, schema } = context
// Reset sort when initial sort props change // Reset sort when initial sort props change

View File

@ -1,7 +1,18 @@
import { derived } from "svelte/store" import { derived, Readable } from "svelte/store"
import { MinColumnWidth } from "../lib/constants" import { MinColumnWidth } from "../lib/constants"
import { Store as StoreContext } from "."
import { Row } from "@budibase/types"
export const deriveStores = context => { interface ViewportDerivedStore {
scrolledRowCount: Readable<number>
visualRowCapacity: Readable<number>
renderedRows: Readable<Row>
columnRenderMap: Readable<Record<string, true>>
}
export type Store = ViewportDerivedStore
export const deriveStores = (context: StoreContext): ViewportDerivedStore => {
const { const {
rowHeight, rowHeight,
scrollableColumns, scrollableColumns,
@ -77,7 +88,7 @@ export const deriveStores = context => {
leftEdge += $scrollableColumns[endColIdx].width leftEdge += $scrollableColumns[endColIdx].width
endColIdx++ endColIdx++
} }
let next = {} let next: Record<string, true> = {}
$scrollableColumns $scrollableColumns
.slice(Math.max(0, startColIdx), endColIdx) .slice(Math.max(0, startColIdx), endColIdx)
.forEach(col => { .forEach(col => {

View File

@ -122,7 +122,7 @@
"server-destroy": "1.0.1", "server-destroy": "1.0.1",
"snowflake-sdk": "^1.15.0", "snowflake-sdk": "^1.15.0",
"socket.io": "4.8.1", "socket.io": "4.8.1",
"svelte": "^4.2.10", "svelte": "4.2.19",
"tar": "6.2.1", "tar": "6.2.1",
"tmp": "0.2.3", "tmp": "0.2.3",
"to-json-schema": "0.2.5", "to-json-schema": "0.2.5",

View File

@ -19,7 +19,8 @@
"@budibase/pro": ["./packages/pro/src"], "@budibase/pro": ["./packages/pro/src"],
"@budibase/string-templates": ["./packages/string-templates/src"], "@budibase/string-templates": ["./packages/string-templates/src"],
"@budibase/string-templates/*": ["./packages/string-templates/*"], "@budibase/string-templates/*": ["./packages/string-templates/*"],
"@budibase/frontend-core": ["./packages/frontend-core/src"] "@budibase/frontend-core": ["./packages/frontend-core/src"],
"@budibase/bbui": ["./packages/bbui/src"]
} }
}, },
"exclude": [] "exclude": []

View File

@ -18991,7 +18991,7 @@ svelte-spa-router@^4.0.1:
dependencies: dependencies:
regexparam "2.0.2" regexparam "2.0.2"
svelte@4.2.19, svelte@^4.2.10: svelte@4.2.19:
version "4.2.19" version "4.2.19"
resolved "https://registry.yarnpkg.com/svelte/-/svelte-4.2.19.tgz#4e6e84a8818e2cd04ae0255fcf395bc211e61d4c" resolved "https://registry.yarnpkg.com/svelte/-/svelte-4.2.19.tgz#4e6e84a8818e2cd04ae0255fcf395bc211e61d4c"
integrity sha512-IY1rnGr6izd10B0A8LqsBfmlT5OILVuZ7XsI0vdGPEvuonFV7NYEUK4dAkm9Zg2q0Um92kYjTpS1CAP3Nh/KWw== integrity sha512-IY1rnGr6izd10B0A8LqsBfmlT5OILVuZ7XsI0vdGPEvuonFV7NYEUK4dAkm9Zg2q0Um92kYjTpS1CAP3Nh/KWw==