Skip to content

Commit

Permalink
Merge pull request #15372 from Budibase/binding-ts-improvements
Browse files Browse the repository at this point in the history
`BindingPanel` typing improvements
  • Loading branch information
mike12345567 authored Jan 17, 2025
2 parents 709b3fb + a79c1e1 commit 01a47bb
Show file tree
Hide file tree
Showing 21 changed files with 506 additions and 211 deletions.
8 changes: 4 additions & 4 deletions packages/bbui/src/Icon/Icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
export let size = "M"
export let hoverable = false
export let disabled = false
export let color
export let hoverColor
export let tooltip
export let color = undefined
export let hoverColor = undefined
export let tooltip = undefined
export let tooltipPosition = TooltipPosition.Bottom
export let tooltipType = TooltipType.Default
export let tooltipColor
export let tooltipColor = undefined
export let tooltipWrap = true
export let newStyles = false
</script>
Expand Down
2 changes: 1 addition & 1 deletion packages/bbui/src/Label/Label.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export let size = "M"
export let tooltip = ""
export let muted
export let muted = undefined
</script>

<TooltipWrapper {tooltip} {size}>
Expand Down
1 change: 1 addition & 0 deletions packages/bbui/src/helpers.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
declare module "./helpers" {
export const cloneDeep: <T>(obj: T) => T
export const copyToClipboard: (value: any) => Promise<void>
}
2 changes: 1 addition & 1 deletion packages/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"dayjs": "^1.10.8",
"downloadjs": "1.4.7",
"fast-json-patch": "^3.1.1",
"json-format-highlight": "^1.0.4",
"lodash": "4.17.21",
"posthog-js": "^1.118.0",
"remixicon": "2.5.0",
Expand All @@ -94,6 +93,7 @@
"@sveltejs/vite-plugin-svelte": "1.4.0",
"@testing-library/jest-dom": "6.4.2",
"@testing-library/svelte": "^4.1.0",
"@types/sanitize-html": "^2.13.0",
"@types/shortid": "^2.2.0",
"babel-jest": "^29.6.2",
"identity-obj-proxy": "^3.0.0",
Expand Down
57 changes: 36 additions & 21 deletions packages/builder/src/components/common/CodeEditor/CodeEditor.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script>
<script lang="ts">
import { Label } from "@budibase/bbui"
import { onMount, createEventDispatcher, onDestroy } from "svelte"
import { FIND_ANY_HBS_REGEX } from "@budibase/string-templates"
Expand All @@ -12,7 +12,6 @@
completionStatus,
} from "@codemirror/autocomplete"
import {
EditorView,
lineNumbers,
keymap,
highlightSpecialChars,
Expand All @@ -25,6 +24,7 @@
MatchDecorator,
ViewPlugin,
Decoration,
EditorView,
} from "@codemirror/view"
import {
bracketMatching,
Expand All @@ -44,12 +44,14 @@
import { javascript } from "@codemirror/lang-javascript"
import { EditorModes } from "./"
import { themeStore } from "@/stores/portal"
export let label
export let completions = []
export let mode = EditorModes.Handlebars
export let value = ""
export let placeholder = null
import type { EditorMode } from "@budibase/types"
export let label: string | undefined = undefined
// TODO: work out what best type fits this
export let completions: any[] = []
export let mode: EditorMode = EditorModes.Handlebars
export let value: string | null = ""
export let placeholder: string | null = null
export let autocompleteEnabled = true
export let autofocus = false
export let jsBindingWrapping = true
Expand All @@ -58,8 +60,8 @@
const dispatch = createEventDispatcher()
let textarea
let editor
let textarea: HTMLDivElement
let editor: EditorView
let mounted = false
let isEditorInitialised = false
let queuedRefresh = false
Expand Down Expand Up @@ -100,15 +102,22 @@
/**
* Will refresh the editor contents only after
* it has been fully initialised
* @param value {string} the editor value
*/
const refresh = (value, initialised, mounted) => {
const refresh = (
value: string | null,
initialised?: boolean,
mounted?: boolean
) => {
if (!initialised || !mounted) {
queuedRefresh = true
return
}
if (editor.state.doc.toString() !== value || queuedRefresh) {
if (
editor &&
value &&
(editor.state.doc.toString() !== value || queuedRefresh)
) {
editor.dispatch({
changes: { from: 0, to: editor.state.doc.length, insert: value },
})
Expand All @@ -120,12 +129,17 @@
export const getCaretPosition = () => {
const selection_range = editor.state.selection.ranges[0]
return {
start: selection_range.from,
end: selection_range.to,
start: selection_range?.from,
end: selection_range?.to,
}
}
export const insertAtPos = opts => {
export const insertAtPos = (opts: {
start: number
end?: number
value: string
cursor: { anchor: number }
}) => {
// Updating the value inside.
// Retain focus
editor.dispatch({
Expand Down Expand Up @@ -192,15 +206,15 @@
const indentWithTabCustom = {
key: "Tab",
run: view => {
run: (view: EditorView) => {
if (completionStatus(view.state) === "active") {
acceptCompletion(view)
return true
}
indentMore(view)
return true
},
shift: view => {
shift: (view: EditorView) => {
indentLess(view)
return true
},
Expand Down Expand Up @@ -232,7 +246,8 @@
// None of this is reactive, but it never has been, so we just assume most
// config flags aren't changed at runtime
const buildExtensions = base => {
// TODO: work out type for base
const buildExtensions = (base: any[]) => {
let complete = [...base]
if (autocompleteEnabled) {
Expand All @@ -242,7 +257,7 @@
closeOnBlur: true,
icons: false,
optionClass: completion =>
completion.simple
"simple" in completion && completion.simple
? "autocomplete-option-simple"
: "autocomplete-option",
})
Expand Down Expand Up @@ -347,7 +362,7 @@

{#if label}
<div>
<Label small>{label}</Label>
<Label size="S">{label}</Label>
</div>
{/if}

Expand Down
Loading

0 comments on commit 01a47bb

Please sign in to comment.