From 65ef56e416cf8828041e9b44d0d2ce50f55e504d Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 17 Jan 2025 11:02:08 +0000 Subject: [PATCH 1/6] Add basic TS config for BBUI --- packages/bbui/package.json | 5 +++-- packages/bbui/src/helpers.d.ts | 4 ---- packages/bbui/src/{index.js => index.ts} | 0 packages/bbui/svelte.config.js | 7 +++++++ packages/bbui/tsconfig.json | 11 +++++++++++ packages/bbui/vite.config.js | 2 +- 6 files changed, 22 insertions(+), 7 deletions(-) delete mode 100644 packages/bbui/src/helpers.d.ts rename packages/bbui/src/{index.js => index.ts} (100%) create mode 100644 packages/bbui/svelte.config.js create mode 100644 packages/bbui/tsconfig.json diff --git a/packages/bbui/package.json b/packages/bbui/package.json index 89f72bc46d..2caad20bf6 100644 --- a/packages/bbui/package.json +++ b/packages/bbui/package.json @@ -3,7 +3,7 @@ "description": "A UI solution used in the different Budibase projects.", "version": "0.0.0", "license": "MPL-2.0", - "svelte": "src/index.js", + "svelte": "src/index.ts", "module": "dist/bbui.mjs", "exports": { ".": { @@ -14,7 +14,8 @@ "./spectrum-icons-vite.js": "./src/spectrum-icons-vite.js" }, "scripts": { - "build": "vite build" + "build": "vite build", + "dev": "vite build --watch --mode=dev" }, "devDependencies": { "@sveltejs/vite-plugin-svelte": "1.4.0", diff --git a/packages/bbui/src/helpers.d.ts b/packages/bbui/src/helpers.d.ts deleted file mode 100644 index d4e2a45186..0000000000 --- a/packages/bbui/src/helpers.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module "./helpers" { - export const cloneDeep: (obj: T) => T - export const copyToClipboard: (value: any) => Promise -} diff --git a/packages/bbui/src/index.js b/packages/bbui/src/index.ts similarity index 100% rename from packages/bbui/src/index.js rename to packages/bbui/src/index.ts diff --git a/packages/bbui/svelte.config.js b/packages/bbui/svelte.config.js new file mode 100644 index 0000000000..7d908c15d5 --- /dev/null +++ b/packages/bbui/svelte.config.js @@ -0,0 +1,7 @@ +const { vitePreprocess } = require("@sveltejs/vite-plugin-svelte") + +const config = { + preprocess: vitePreprocess(), +} + +module.exports = config diff --git a/packages/bbui/tsconfig.json b/packages/bbui/tsconfig.json new file mode 100644 index 0000000000..0b529c199a --- /dev/null +++ b/packages/bbui/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.build.json", + "compilerOptions": { + "allowJs": true, + "outDir": "./dist", + "lib": ["ESNext"], + "baseUrl": ".", + }, + "include": ["./src/**/*"], + "exclude": ["node_modules", "**/*.json", "**/*.spec.ts", "**/*.spec.js"] +} \ No newline at end of file diff --git a/packages/bbui/vite.config.js b/packages/bbui/vite.config.js index bf0f9fc26d..bccca20e43 100644 --- a/packages/bbui/vite.config.js +++ b/packages/bbui/vite.config.js @@ -9,7 +9,7 @@ export default defineConfig(({ mode }) => { build: { sourcemap: !isProduction, lib: { - entry: "src/index.js", + entry: "src/index.ts", formats: ["es"], }, }, From 50a8caddb9743bd5668fddafb2737610e8d073eb Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 17 Jan 2025 11:15:52 +0000 Subject: [PATCH 2/6] Type BBUI helpers --- packages/bbui/src/{helpers.js => helpers.ts} | 45 ++++++++++---------- packages/bbui/tsconfig.json | 8 ++++ 2 files changed, 31 insertions(+), 22 deletions(-) rename packages/bbui/src/{helpers.js => helpers.ts} (87%) diff --git a/packages/bbui/src/helpers.js b/packages/bbui/src/helpers.ts similarity index 87% rename from packages/bbui/src/helpers.js rename to packages/bbui/src/helpers.ts index 246587af44..dfb5015a8d 100644 --- a/packages/bbui/src/helpers.js +++ b/packages/bbui/src/helpers.ts @@ -6,9 +6,8 @@ export const deepGet = helpers.deepGet /** * Generates a DOM safe UUID. * 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 => { const r = (Math.random() * 16) | 0 const v = c === "x" ? r : (r & 0x3) | 0x8 @@ -18,12 +17,10 @@ export function uuid() { /** * 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) { - return string + return "" } return string.substring(0, 1).toUpperCase() + string.substring(1) } @@ -33,7 +30,7 @@ export const capitalise = 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) { return "0" } @@ -54,11 +51,12 @@ export const hashString = string => { * will override the value "foo" rather than "bar". * If a deep path is specified and the parent keys don't exist then these will * 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 | null, + key: string | null, + value: any +): void => { if (!obj || !key) { return } @@ -84,7 +82,7 @@ export const deepSet = (obj, key, value) => { * Deeply clones an object. Functions are not supported. * @param obj the object to clone */ -export const cloneDeep = obj => { +export const cloneDeep = (obj: T): T => { if (!obj) { return obj } @@ -95,7 +93,7 @@ export const cloneDeep = obj => { * Copies a value to the clipboard * @param value the value to copy */ -export const copyToClipboard = value => { +export const copyToClipboard = (value: string): Promise => { return new Promise(res => { if (navigator.clipboard && window.isSecureContext) { // Try using the clipboard API first @@ -117,9 +115,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. -export const parseDate = (value, { enableTime = true }) => { +export const parseDate = ( + value: string | dayjs.Dayjs | null, + { enableTime = true } +): dayjs.Dayjs | null => { // If empty then invalid if (!value) { return null @@ -128,7 +129,7 @@ export const parseDate = (value, { enableTime = true }) => { // Certain string values need transformed if (typeof value === "string") { // Check for time only values - if (!isNaN(new Date(`0-${value}`))) { + if (!isNaN(new Date(`0-${value}`).valueOf())) { value = `0-${value}` } @@ -153,9 +154,9 @@ export const parseDate = (value, { enableTime = true }) => { // Stringifies a dayjs object to create an ISO string that respects the various // schema flags export const stringifyDate = ( - value, + value: null | dayjs.Dayjs, { enableTime = true, timeOnly = false, ignoreTimezones = false } = {} -) => { +): string | null => { if (!value) { return null } @@ -192,7 +193,7 @@ export const stringifyDate = ( } // Determine the dayjs-compatible format of the browser's default locale -const getPatternForPart = part => { +const getPatternForPart = (part: Intl.DateTimeFormatPart): string => { switch (part.type) { case "day": return "D".repeat(part.value.length) @@ -214,9 +215,9 @@ const localeDateFormat = new Intl.DateTimeFormat() // Formats a dayjs date according to schema flags export const getDateDisplayValue = ( - value, + value: dayjs.Dayjs | null, { enableTime = true, timeOnly = false } = {} -) => { +): string => { if (!value?.isValid()) { return "" } @@ -229,7 +230,7 @@ export const getDateDisplayValue = ( } } -export const hexToRGBA = (color, opacity) => { +export const hexToRGBA = (color: string, opacity: number): string => { if (color.includes("#")) { color = color.replace("#", "") } diff --git a/packages/bbui/tsconfig.json b/packages/bbui/tsconfig.json index 0b529c199a..2fe17da42e 100644 --- a/packages/bbui/tsconfig.json +++ b/packages/bbui/tsconfig.json @@ -5,6 +5,14 @@ "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"] From 3fa7a239326b5bdc33067b500cb40612e9c2b6e7 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 17 Jan 2025 11:23:16 +0000 Subject: [PATCH 3/6] Update helpers --- packages/bbui/src/helpers.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/bbui/src/helpers.ts b/packages/bbui/src/helpers.ts index dfb5015a8d..330f381d53 100644 --- a/packages/bbui/src/helpers.ts +++ b/packages/bbui/src/helpers.ts @@ -27,8 +27,6 @@ export const capitalise = (string?: string | null): 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?: string | null): string => { if (!string) { @@ -80,7 +78,6 @@ export const deepSet = ( /** * Deeply clones an object. Functions are not supported. - * @param obj the object to clone */ export const cloneDeep = (obj: T): T => { if (!obj) { @@ -91,9 +88,8 @@ export const cloneDeep = (obj: T): T => { /** * Copies a value to the clipboard - * @param value the value to copy */ -export const copyToClipboard = (value: string): Promise => { +export const copyToClipboard = (value: any): Promise => { return new Promise(res => { if (navigator.clipboard && window.isSecureContext) { // Try using the clipboard API first From ffd2d7bd18032cee8d2458f175582a20e6145f6d Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 17 Jan 2025 11:28:21 +0000 Subject: [PATCH 4/6] Type heading as example TS svelte component --- packages/bbui/src/Typography/Heading.svelte | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/bbui/src/Typography/Heading.svelte b/packages/bbui/src/Typography/Heading.svelte index 90d53fb208..f48d5d958e 100644 --- a/packages/bbui/src/Typography/Heading.svelte +++ b/packages/bbui/src/Typography/Heading.svelte @@ -2,10 +2,10 @@ import "@spectrum-css/typography/dist/index-vars.css" // Sizes - export let size = "M" - export let textAlign = undefined - export let noPadding = false - export let weight = "default" // light, heavy, default + export let size: "XS" | "S" | "M" | "L" = "M" + export let textAlign: string | undefined = undefined + export let noPadding: boolean = false + export let weight: "light" | "heavy" | "default" = "default"

Date: Fri, 17 Jan 2025 14:15:40 +0000 Subject: [PATCH 5/6] lint --- .../components/automation/SetupPanel/CronBuilder.svelte | 5 ++--- .../backend/DataTable/modals/CreateEditColumn.svelte | 5 +++-- .../data/table/[tableId]/[viewId]/index.svelte | 4 ++-- .../app/[application]/data/table/[tableId]/index.svelte | 5 +++-- .../src/pages/builder/portal/settings/ai/index.svelte | 5 ++--- .../builder/src/pages/builder/portal/settings/index.svelte | 7 +------ 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte b/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte index f04c5454ea..1490baa602 100644 --- a/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte +++ b/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte @@ -9,7 +9,7 @@ } from "@budibase/bbui" import { onMount, createEventDispatcher } from "svelte" import { flags } from "@/stores/builder" - import { featureFlags, licensing } from "@/stores/portal" + import { licensing } from "@/stores/portal" import { API } from "@/api" import MagicWand from "../../../../assets/MagicWand.svelte" @@ -27,8 +27,7 @@ let loadingAICronExpression = false $: aiEnabled = - ($featureFlags.AI_CUSTOM_CONFIGS && $licensing.customAIConfigsEnabled) || - ($featureFlags.BUDIBASE_AI && $licensing.budibaseAIEnabled) + $licensing.customAIConfigsEnabled || $licensing.budibaseAIEnabled $: { if (cronExpression) { try { diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 55ac8474a6..4af1dcc0ee 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -26,7 +26,7 @@ import { createEventDispatcher, getContext, onMount } from "svelte" import { cloneDeep } from "lodash/fp" import { tables, datasources } from "@/stores/builder" - import { featureFlags } from "@/stores/portal" + import { licensing } from "@/stores/portal" import { TableNames, UNEDITABLE_USER_FIELDS } from "@/constants" import { FIELDS, @@ -100,7 +100,8 @@ let optionsValid = true $: rowGoldenSample = RowUtils.generateGoldenSample($rows) - $: aiEnabled = $featureFlags.BUDIBASE_AI || $featureFlags.AI_CUSTOM_CONFIGS + $: aiEnabled = + $licensing.customAIConfigsEnabled || $licensing.budibaseAiEnabled $: if (primaryDisplay) { editableColumn.constraints.presence = { allowEmpty: false } } diff --git a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte index 9ac7ccd715..4d42c0d5d6 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte @@ -1,6 +1,6 @@ From 4d90751988811729d296a3888a153a41661da39d Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Fri, 17 Jan 2025 14:30:17 +0000 Subject: [PATCH 6/6] Bump version to 3.2.46 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index c02b221ec8..d033c24518 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "3.2.45", + "version": "3.2.46", "npmClient": "yarn", "concurrency": 20, "command": {