|
|
@ -313,10 +313,13 @@ function validateAgainstMeta(parsedTree: any, errors = new Set(), typeErrors = n |
|
|
|
|
|
|
|
|
|
|
|
function isCurlyBracketBalanced() { |
|
|
|
function isCurlyBracketBalanced() { |
|
|
|
// count number of opening curly brackets and closing curly brackets |
|
|
|
// count number of opening curly brackets and closing curly brackets |
|
|
|
const cntCurlyBrackets = (formulaRef.value.value.match(/\{|}/g) || []).reduce((acc: Record<number, number>, cur: number) => { |
|
|
|
const cntCurlyBrackets = (formulaRef.value.$el.value.match(/\{|}/g) || []).reduce( |
|
|
|
|
|
|
|
(acc: Record<number, number>, cur: number) => { |
|
|
|
acc[cur] = (acc[cur] || 0) + 1 |
|
|
|
acc[cur] = (acc[cur] || 0) + 1 |
|
|
|
return acc |
|
|
|
return acc |
|
|
|
}, {}) |
|
|
|
}, |
|
|
|
|
|
|
|
{}, |
|
|
|
|
|
|
|
) |
|
|
|
return (cntCurlyBrackets['{'] || 0) === (cntCurlyBrackets['}'] || 0) |
|
|
|
return (cntCurlyBrackets['{'] || 0) === (cntCurlyBrackets['}'] || 0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -324,11 +327,11 @@ function appendText(it: Record<string, any>) { |
|
|
|
const text = it.text |
|
|
|
const text = it.text |
|
|
|
const len = wordToComplete.value?.length || 0 |
|
|
|
const len = wordToComplete.value?.length || 0 |
|
|
|
if (it.type === 'function') { |
|
|
|
if (it.type === 'function') { |
|
|
|
formula.value = insertAtCursor(formula.value, text, len, 1) |
|
|
|
formState.value.colOptions.formula_raw = insertAtCursor(formulaRef.value.$el, text, len, 1) |
|
|
|
} else if (it.type === 'column') { |
|
|
|
} else if (it.type === 'column') { |
|
|
|
formula.value = insertAtCursor(formula.value, `{${text}}`, len + +!isCurlyBracketBalanced()) |
|
|
|
formState.value.colOptions.formula_raw = insertAtCursor(formulaRef.value.$el, `{${text}}`, len + +!isCurlyBracketBalanced()) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
formula.value = insertAtCursor(formula.value, text, len) |
|
|
|
formState.value.colOptions.formula_raw = insertAtCursor(formulaRef.value.$el, text, len) |
|
|
|
} |
|
|
|
} |
|
|
|
autocomplete.value = false |
|
|
|
autocomplete.value = false |
|
|
|
suggestion.value = null |
|
|
|
suggestion.value = null |
|
|
@ -341,7 +344,7 @@ const handleInputDeb = useDebounceFn(function () { |
|
|
|
function handleInput() { |
|
|
|
function handleInput() { |
|
|
|
selected.value = 0 |
|
|
|
selected.value = 0 |
|
|
|
suggestion.value = null |
|
|
|
suggestion.value = null |
|
|
|
const query = getWordUntilCaret(formulaRef.value) |
|
|
|
const query = getWordUntilCaret(formulaRef.value.$el) |
|
|
|
const parts = query.split(/\W+/) |
|
|
|
const parts = query.split(/\W+/) |
|
|
|
wordToComplete.value = parts.pop() || '' |
|
|
|
wordToComplete.value = parts.pop() || '' |
|
|
|
suggestion.value = acTree.value.complete(wordToComplete.value)?.sort((x, y) => sortOrder[x.type] - sortOrder[y.type]) // TODO: check .type |
|
|
|
suggestion.value = acTree.value.complete(wordToComplete.value)?.sort((x, y) => sortOrder[x.type] - sortOrder[y.type]) // TODO: check .type |
|
|
@ -421,9 +424,11 @@ formState.value.colOptions = { |
|
|
|
Hint: Use {} to reference columns, e.g: {column_name}. For more, please check out |
|
|
|
Hint: Use {} to reference columns, e.g: {column_name}. For more, please check out |
|
|
|
<a href="https://docs.nocodb.com/setup-and-usages/formulas#available-formula-features" target="_blank">Formulas</a>. |
|
|
|
<a href="https://docs.nocodb.com/setup-and-usages/formulas#available-formula-features" target="_blank">Formulas</a>. |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
<!-- TODO: close drawer when EditOrAdd is closed --> |
|
|
|
<a-drawer |
|
|
|
<a-drawer |
|
|
|
v-model:visible="formulaSuggestionDrawer" |
|
|
|
v-model:visible="formulaSuggestionDrawer" |
|
|
|
:closable="false" |
|
|
|
:closable="false" |
|
|
|
|
|
|
|
:mask-closable="false" |
|
|
|
placement="right" |
|
|
|
placement="right" |
|
|
|
width="500px" |
|
|
|
width="500px" |
|
|
|
class="h-full overflow-auto" |
|
|
|
class="h-full overflow-auto" |
|
|
@ -437,7 +442,8 @@ formState.value.colOptions = { |
|
|
|
sugOptionsRef[index] = el |
|
|
|
sugOptionsRef[index] = el |
|
|
|
} |
|
|
|
} |
|
|
|
" |
|
|
|
" |
|
|
|
@mousedown.prevent="appendText(item)" |
|
|
|
class="cursor-pointer" |
|
|
|
|
|
|
|
@mousedown.stop="appendText(item)" |
|
|
|
> |
|
|
|
> |
|
|
|
<a-list-item-meta> |
|
|
|
<a-list-item-meta> |
|
|
|
<template v-if="item.type === 'function'" #description> |
|
|
|
<template v-if="item.type === 'function'" #description> |
|
|
|