Typing fixes and updates from the BindingPanel
This commit is contained in:
parent
30c0196db6
commit
693cf77a62
|
@ -13,18 +13,18 @@
|
||||||
snippetAutoComplete,
|
snippetAutoComplete,
|
||||||
EditorModes,
|
EditorModes,
|
||||||
bindingsToCompletions,
|
bindingsToCompletions,
|
||||||
|
jsHelperAutocomplete,
|
||||||
} from "../CodeEditor"
|
} from "../CodeEditor"
|
||||||
import { JsonFormatter } from "@budibase/frontend-core"
|
import { JsonFormatter } from "@budibase/frontend-core"
|
||||||
import { licensing } from "@/stores/portal"
|
import { licensing } from "@/stores/portal"
|
||||||
import type {
|
import type {
|
||||||
EnrichedBinding,
|
EnrichedBinding,
|
||||||
BindingCompletion,
|
|
||||||
Snippet,
|
Snippet,
|
||||||
CaretPositionFn,
|
CaretPositionFn,
|
||||||
InsertAtPositionFn,
|
InsertAtPositionFn,
|
||||||
JSONValue,
|
JSONValue,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import type { CompletionContext } from "@codemirror/autocomplete"
|
import type { BindingCompletion, BindingCompletionOption } from "@/types"
|
||||||
import { snippets } from "@/stores/builder"
|
import { snippets } from "@/stores/builder"
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
@ -48,27 +48,31 @@
|
||||||
$: enrichedBindings = enrichBindings(bindings, context, $snippets)
|
$: enrichedBindings = enrichBindings(bindings, context, $snippets)
|
||||||
$: editorMode = EditorModes.JS
|
$: editorMode = EditorModes.JS
|
||||||
$: bindingCompletions = bindingsToCompletions(enrichedBindings, editorMode)
|
$: bindingCompletions = bindingsToCompletions(enrichedBindings, editorMode)
|
||||||
$: jsCompletions = getJSCompletions(
|
$: jsCompletions = getJSCompletions(bindingCompletions, $snippets, {
|
||||||
bindingCompletions,
|
useHelpers: allowHelpers,
|
||||||
$snippets,
|
useSnippets,
|
||||||
useSnippets
|
})
|
||||||
)
|
|
||||||
|
|
||||||
const getJSCompletions = (
|
const getJSCompletions = (
|
||||||
bindingCompletions: BindingCompletion[],
|
bindingCompletions: BindingCompletionOption[],
|
||||||
snippets: Snippet[] | null,
|
snippets: Snippet[] | null,
|
||||||
useSnippets?: boolean
|
config: {
|
||||||
|
useHelpers: boolean
|
||||||
|
useSnippets: boolean
|
||||||
|
}
|
||||||
) => {
|
) => {
|
||||||
const completions: ((_: CompletionContext) => any)[] = [
|
const completions: BindingCompletion[] = []
|
||||||
jsAutocomplete([
|
if (bindingCompletions.length) {
|
||||||
...bindingCompletions,
|
completions.push(jsAutocomplete([...bindingCompletions]))
|
||||||
...(allowHelpers ? getHelperCompletions(EditorModes.JS) : []),
|
}
|
||||||
]),
|
if (config.useHelpers) {
|
||||||
]
|
completions.push(
|
||||||
if (useSnippets && snippets) {
|
jsHelperAutocomplete([...getHelperCompletions(EditorModes.JS)])
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (config.useSnippets && snippets) {
|
||||||
completions.push(snippetAutoComplete(snippets))
|
completions.push(snippetAutoComplete(snippets))
|
||||||
}
|
}
|
||||||
|
|
||||||
return completions
|
return completions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue