Browse Source

refactor: use jsepCurlyHook from nocodb-sdk

pull/1979/head
Wing-Kam Wong 3 years ago
parent
commit
c624a0e75e
  1. 5
      packages/nc-gui/components/project/spreadsheet/components/editColumn/FormulaOptions.vue
  2. 24
      packages/nc-gui/helpers/formulaCurlyHook.js

5
packages/nc-gui/components/project/spreadsheet/components/editColumn/FormulaOptions.vue

@ -95,9 +95,8 @@
import debounce from 'debounce' import debounce from 'debounce'
import jsep from 'jsep' import jsep from 'jsep'
import { UITypes } from 'nocodb-sdk' import { UITypes, jsepCurlyHook } from 'nocodb-sdk'
import formulaList, { validations } from '../../../../../helpers/formulaList' import formulaList, { validations } from '../../../../../helpers/formulaList'
import curly from '../../../../../helpers/formulaCurlyHook'
import { getWordUntilCaret, insertAtCursor } from '@/helpers' import { getWordUntilCaret, insertAtCursor } from '@/helpers'
import NcAutocompleteTree from '@/helpers/NcAutocompleteTree' import NcAutocompleteTree from '@/helpers/NcAutocompleteTree'
@ -162,7 +161,7 @@ export default {
}, },
created() { created() {
this.formula = { value: this.value || '' } this.formula = { value: this.value || '' }
jsep.plugins.register(curly) jsep.plugins.register(jsepCurlyHook)
}, },
methods: { methods: {
async save() { async save() {

24
packages/nc-gui/helpers/formulaCurlyHook.js

@ -1,24 +0,0 @@
const OCURLY_CODE = 123; // {
const CCURLY_CODE = 125; // }
export default {
name: 'curly',
init(jsep) {
jsep.hooks.add('gobble-token', function gobbleCurlyLiteral(env) {
const { context } = env
if (!jsep.isIdentifierStart(context.code) && context.code === OCURLY_CODE) {
context.index += 1
let nodes = context.gobbleExpressions(CCURLY_CODE)
if (context.code === CCURLY_CODE) {
context.index += 1
if (nodes.length > 0) {
env.node = nodes[0]
}
return env.node
} else {
context.throwError('Unclosed }')
}
}
});
}
}
Loading…
Cancel
Save