Merge branch 'master' into BUDI-8986/ground-work

This commit is contained in:
Adria Navarro 2025-01-17 21:12:08 +01:00 committed by GitHub
commit 93f8ab9bdf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 71 additions and 56 deletions

View File

@ -1,6 +1,6 @@
{ {
"$schema": "node_modules/lerna/schemas/lerna-schema.json", "$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "3.2.45", "version": "3.2.46",
"npmClient": "yarn", "npmClient": "yarn",
"concurrency": 20, "concurrency": 20,
"command": { "command": {

View File

@ -3,7 +3,7 @@
"description": "A UI solution used in the different Budibase projects.", "description": "A UI solution used in the different Budibase projects.",
"version": "0.0.0", "version": "0.0.0",
"license": "MPL-2.0", "license": "MPL-2.0",
"svelte": "src/index.js", "svelte": "src/index.ts",
"module": "dist/bbui.mjs", "module": "dist/bbui.mjs",
"exports": { "exports": {
".": { ".": {
@ -14,7 +14,8 @@
"./spectrum-icons-vite.js": "./src/spectrum-icons-vite.js" "./spectrum-icons-vite.js": "./src/spectrum-icons-vite.js"
}, },
"scripts": { "scripts": {
"build": "vite build" "build": "vite build",
"dev": "vite build --watch --mode=dev"
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/vite-plugin-svelte": "1.4.0", "@sveltejs/vite-plugin-svelte": "1.4.0",

View File

@ -2,10 +2,10 @@
import "@spectrum-css/typography/dist/index-vars.css" import "@spectrum-css/typography/dist/index-vars.css"
// Sizes // Sizes
export let size = "M" export let size: "XS" | "S" | "M" | "L" = "M"
export let textAlign = undefined export let textAlign: string | undefined = undefined
export let noPadding = false export let noPadding: boolean = false
export let weight = "default" // light, heavy, default export let weight: "light" | "heavy" | "default" = "default"
</script> </script>
<h1 <h1

View File

@ -1,4 +0,0 @@
declare module "./helpers" {
export const cloneDeep: <T>(obj: T) => T
export const copyToClipboard: (value: any) => Promise<void>
}

View File

@ -6,9 +6,8 @@ export const deepGet = helpers.deepGet
/** /**
* Generates a DOM safe UUID. * Generates a DOM safe UUID.
* Starting with a letter is important to make it DOM safe. * Starting with a letter is important to make it DOM safe.
* @return {string} a random DOM safe UUID
*/ */
export function uuid() { export function uuid(): string {
return "cxxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, c => { return "cxxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, c => {
const r = (Math.random() * 16) | 0 const r = (Math.random() * 16) | 0
const v = c === "x" ? r : (r & 0x3) | 0x8 const v = c === "x" ? r : (r & 0x3) | 0x8
@ -18,22 +17,18 @@ export function uuid() {
/** /**
* Capitalises a string * Capitalises a string
* @param string the string to capitalise
* @return {string} the capitalised string
*/ */
export const capitalise = string => { export const capitalise = (string?: string | null): string => {
if (!string) { if (!string) {
return string return ""
} }
return string.substring(0, 1).toUpperCase() + string.substring(1) return string.substring(0, 1).toUpperCase() + string.substring(1)
} }
/** /**
* Computes a short hash of a string * Computes a short hash of a string
* @param string the string to compute a hash of
* @return {string} the hash string
*/ */
export const hashString = string => { export const hashString = (string?: string | null): string => {
if (!string) { if (!string) {
return "0" return "0"
} }
@ -54,11 +49,12 @@ export const hashString = string => {
* will override the value "foo" rather than "bar". * will override the value "foo" rather than "bar".
* If a deep path is specified and the parent keys don't exist then these will * If a deep path is specified and the parent keys don't exist then these will
* be created. * be created.
* @param obj the object
* @param key the key
* @param value the value
*/ */
export const deepSet = (obj, key, value) => { export const deepSet = (
obj: Record<string, any> | null,
key: string | null,
value: any
): void => {
if (!obj || !key) { if (!obj || !key) {
return return
} }
@ -82,9 +78,8 @@ export const deepSet = (obj, key, value) => {
/** /**
* Deeply clones an object. Functions are not supported. * Deeply clones an object. Functions are not supported.
* @param obj the object to clone
*/ */
export const cloneDeep = obj => { export const cloneDeep = <T>(obj: T): T => {
if (!obj) { if (!obj) {
return obj return obj
} }
@ -93,9 +88,8 @@ export const cloneDeep = obj => {
/** /**
* Copies a value to the clipboard * Copies a value to the clipboard
* @param value the value to copy
*/ */
export const copyToClipboard = value => { export const copyToClipboard = (value: any): Promise<void> => {
return new Promise(res => { return new Promise(res => {
if (navigator.clipboard && window.isSecureContext) { if (navigator.clipboard && window.isSecureContext) {
// Try using the clipboard API first // Try using the clipboard API first
@ -117,9 +111,12 @@ export const copyToClipboard = value => {
}) })
} }
// Parsed a date value. This is usually an ISO string, but can be a // Parse a date value. This is usually an ISO string, but can be a
// bunch of different formats and shapes depending on schema flags. // bunch of different formats and shapes depending on schema flags.
export const parseDate = (value, { enableTime = true }) => { export const parseDate = (
value: string | dayjs.Dayjs | null,
{ enableTime = true }
): dayjs.Dayjs | null => {
// If empty then invalid // If empty then invalid
if (!value) { if (!value) {
return null return null
@ -128,7 +125,7 @@ export const parseDate = (value, { enableTime = true }) => {
// Certain string values need transformed // Certain string values need transformed
if (typeof value === "string") { if (typeof value === "string") {
// Check for time only values // Check for time only values
if (!isNaN(new Date(`0-${value}`))) { if (!isNaN(new Date(`0-${value}`).valueOf())) {
value = `0-${value}` value = `0-${value}`
} }
@ -153,9 +150,9 @@ export const parseDate = (value, { enableTime = true }) => {
// Stringifies a dayjs object to create an ISO string that respects the various // Stringifies a dayjs object to create an ISO string that respects the various
// schema flags // schema flags
export const stringifyDate = ( export const stringifyDate = (
value, value: null | dayjs.Dayjs,
{ enableTime = true, timeOnly = false, ignoreTimezones = false } = {} { enableTime = true, timeOnly = false, ignoreTimezones = false } = {}
) => { ): string | null => {
if (!value) { if (!value) {
return null return null
} }
@ -192,7 +189,7 @@ export const stringifyDate = (
} }
// Determine the dayjs-compatible format of the browser's default locale // Determine the dayjs-compatible format of the browser's default locale
const getPatternForPart = part => { const getPatternForPart = (part: Intl.DateTimeFormatPart): string => {
switch (part.type) { switch (part.type) {
case "day": case "day":
return "D".repeat(part.value.length) return "D".repeat(part.value.length)
@ -214,9 +211,9 @@ const localeDateFormat = new Intl.DateTimeFormat()
// Formats a dayjs date according to schema flags // Formats a dayjs date according to schema flags
export const getDateDisplayValue = ( export const getDateDisplayValue = (
value, value: dayjs.Dayjs | null,
{ enableTime = true, timeOnly = false } = {} { enableTime = true, timeOnly = false } = {}
) => { ): string => {
if (!value?.isValid()) { if (!value?.isValid()) {
return "" return ""
} }
@ -229,7 +226,7 @@ export const getDateDisplayValue = (
} }
} }
export const hexToRGBA = (color, opacity) => { export const hexToRGBA = (color: string, opacity: number): string => {
if (color.includes("#")) { if (color.includes("#")) {
color = color.replace("#", "") color = color.replace("#", "")
} }

View File

@ -0,0 +1,7 @@
const { vitePreprocess } = require("@sveltejs/vite-plugin-svelte")
const config = {
preprocess: vitePreprocess(),
}
module.exports = config

View File

@ -0,0 +1,19 @@
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"allowJs": true,
"outDir": "./dist",
"lib": ["ESNext"],
"baseUrl": ".",
"paths": {
"@budibase/*": [
"../*/src/index.ts",
"../*/src/index.js",
"../*",
"../../node_modules/@budibase/*"
]
}
},
"include": ["./src/**/*"],
"exclude": ["node_modules", "**/*.json", "**/*.spec.ts", "**/*.spec.js"]
}

View File

@ -9,7 +9,7 @@ export default defineConfig(({ mode }) => {
build: { build: {
sourcemap: !isProduction, sourcemap: !isProduction,
lib: { lib: {
entry: "src/index.js", entry: "src/index.ts",
formats: ["es"], formats: ["es"],
}, },
}, },

View File

@ -9,7 +9,7 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import { onMount, createEventDispatcher } from "svelte" import { onMount, createEventDispatcher } from "svelte"
import { flags } from "@/stores/builder" import { flags } from "@/stores/builder"
import { featureFlags, licensing } from "@/stores/portal" import { licensing } from "@/stores/portal"
import { API } from "@/api" import { API } from "@/api"
import MagicWand from "../../../../assets/MagicWand.svelte" import MagicWand from "../../../../assets/MagicWand.svelte"
@ -27,8 +27,7 @@
let loadingAICronExpression = false let loadingAICronExpression = false
$: aiEnabled = $: aiEnabled =
($featureFlags.AI_CUSTOM_CONFIGS && $licensing.customAIConfigsEnabled) || $licensing.customAIConfigsEnabled || $licensing.budibaseAIEnabled
($featureFlags.BUDIBASE_AI && $licensing.budibaseAIEnabled)
$: { $: {
if (cronExpression) { if (cronExpression) {
try { try {

View File

@ -26,7 +26,7 @@
import { createEventDispatcher, getContext, onMount } from "svelte" import { createEventDispatcher, getContext, onMount } from "svelte"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import { tables, datasources } from "@/stores/builder" import { tables, datasources } from "@/stores/builder"
import { featureFlags } from "@/stores/portal" import { licensing } from "@/stores/portal"
import { TableNames, UNEDITABLE_USER_FIELDS } from "@/constants" import { TableNames, UNEDITABLE_USER_FIELDS } from "@/constants"
import { import {
FIELDS, FIELDS,
@ -100,7 +100,8 @@
let optionsValid = true let optionsValid = true
$: rowGoldenSample = RowUtils.generateGoldenSample($rows) $: rowGoldenSample = RowUtils.generateGoldenSample($rows)
$: aiEnabled = $featureFlags.BUDIBASE_AI || $featureFlags.AI_CUSTOM_CONFIGS $: aiEnabled =
$licensing.customAIConfigsEnabled || $licensing.budibaseAiEnabled
$: if (primaryDisplay) { $: if (primaryDisplay) {
editableColumn.constraints.presence = { allowEmpty: false } editableColumn.constraints.presence = { allowEmpty: false }
} }

View File

@ -1,6 +1,6 @@
<script> <script>
import { viewsV2, rowActions } from "@/stores/builder" import { viewsV2, rowActions } from "@/stores/builder"
import { admin, themeStore, featureFlags } from "@/stores/portal" import { admin, themeStore, licensing } from "@/stores/portal"
import { Grid } from "@budibase/frontend-core" import { Grid } from "@budibase/frontend-core"
import { API } from "@/api" import { API } from "@/api"
import { notifications } from "@budibase/bbui" import { notifications } from "@budibase/bbui"
@ -53,7 +53,7 @@
{buttons} {buttons}
allowAddRows allowAddRows
allowDeleteRows allowDeleteRows
aiEnabled={$featureFlags.BUDIBASE_AI || $featureFlags.AI_CUSTOM_CONFIGS} aiEnabled={$licensing.customAIConfigsEnabled || $licensing.budibaseAiEnabled}
showAvatars={false} showAvatars={false}
on:updatedatasource={handleGridViewUpdate} on:updatedatasource={handleGridViewUpdate}
isCloud={$admin.cloud} isCloud={$admin.cloud}

View File

@ -8,7 +8,7 @@
rowActions, rowActions,
roles, roles,
} from "@/stores/builder" } from "@/stores/builder"
import { themeStore, admin, featureFlags } from "@/stores/portal" import { themeStore, admin, licensing } from "@/stores/portal"
import { TableNames } from "@/constants" import { TableNames } from "@/constants"
import { Grid } from "@budibase/frontend-core" import { Grid } from "@budibase/frontend-core"
import { API } from "@/api" import { API } from "@/api"
@ -130,7 +130,8 @@
schemaOverrides={isUsersTable ? userSchemaOverrides : null} schemaOverrides={isUsersTable ? userSchemaOverrides : null}
showAvatars={false} showAvatars={false}
isCloud={$admin.cloud} isCloud={$admin.cloud}
aiEnabled={$featureFlags.BUDIBASE_AI || $featureFlags.AI_CUSTOM_CONFIGS} aiEnabled={$licensing.customAIConfigsEnabled ||
$licensing.budibaseAIEnabled}
{buttons} {buttons}
buttonsCollapsed buttonsCollapsed
on:updatedatasource={handleGridTableUpdate} on:updatedatasource={handleGridTableUpdate}

View File

@ -12,7 +12,7 @@
Tags, Tags,
Tag, Tag,
} from "@budibase/bbui" } from "@budibase/bbui"
import { admin, licensing, featureFlags } from "@/stores/portal" import { admin, licensing } from "@/stores/portal"
import { API } from "@/api" import { API } from "@/api"
import AIConfigModal from "./ConfigModal.svelte" import AIConfigModal from "./ConfigModal.svelte"
import AIConfigTile from "./AIConfigTile.svelte" import AIConfigTile from "./AIConfigTile.svelte"
@ -27,8 +27,7 @@
let editingUuid let editingUuid
$: isCloud = $admin.cloud $: isCloud = $admin.cloud
$: customAIConfigsEnabled = $: customAIConfigsEnabled = $licensing.customAIConfigsEnabled
$featureFlags.AI_CUSTOM_CONFIGS && $licensing.customAIConfigsEnabled
async function fetchAIConfig() { async function fetchAIConfig() {
try { try {

View File

@ -1,10 +1,5 @@
<script> <script>
import { redirect } from "@roxi/routify" import { redirect } from "@roxi/routify"
import { featureFlags } from "@/stores/portal"
if ($featureFlags.AI_CUSTOM_CONFIGS) { $redirect("./ai")
$redirect("./ai")
} else {
$redirect("./auth")
}
</script> </script>