mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
Update the nuxt3 version. Co-authored-by: Jonathan Adeline <jonathan@baserow.io> Co-authored-by: Bram Wiepjes <bramw@protonmail.com> Co-authored-by: Cezary <cezary@baserow.io> Co-authored-by: Tsering Paljor <tsering@baserow.io> Co-authored-by: Przemyslaw Kukulski <przemyslaw+gh@baserow.io> Co-authored-by: Bram <bram2w@users.noreply.github.com>
61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
// composables/useResolveFormula.js
|
|
import { computed, unref } from 'vue'
|
|
import { useNuxtApp } from '#app'
|
|
import RuntimeFormulaContext from '@baserow/modules/core/runtimeFormulaContext'
|
|
import { resolveFormula as coreResolveFormula } from '@baserow/modules/core/formula'
|
|
|
|
/**
|
|
* Composable replacement for the resolveFormula mixin.
|
|
*
|
|
* @param {Object|Ref<Object>} applicationContext
|
|
* Usually the result of useApplicationContext().applicationContext
|
|
*
|
|
* Usage:
|
|
* const { applicationContext } = useApplicationContext(props)
|
|
* const { runtimeFormulaContext, formulaFunctions, resolveFormula } =
|
|
* useResolveFormula(applicationContext)
|
|
*/
|
|
export function useResolveFormula({ applicationContext }) {
|
|
const { $registry } = useNuxtApp()
|
|
|
|
const runtimeFormulaContext = computed(() => {
|
|
/**
|
|
* This proxy allows the RuntimeFormulaContext class to act like a regular object.
|
|
*/
|
|
const ctx = new RuntimeFormulaContext(
|
|
$registry.getAll('builderDataProvider'),
|
|
unref(applicationContext)
|
|
)
|
|
|
|
return new Proxy(ctx, {
|
|
get(target, prop) {
|
|
return target.get(prop)
|
|
},
|
|
})
|
|
})
|
|
|
|
const formulaFunctions = {
|
|
get(name) {
|
|
return $registry.get('runtimeFormulaFunction', name)
|
|
},
|
|
}
|
|
|
|
function resolveFormula(formula, formulaContext = null, defaultIfError = '') {
|
|
try {
|
|
return coreResolveFormula(
|
|
formula,
|
|
formulaFunctions,
|
|
formulaContext || unref(runtimeFormulaContext)
|
|
)
|
|
} catch (e) {
|
|
return defaultIfError
|
|
}
|
|
}
|
|
|
|
return {
|
|
//runtimeFormulaContext,
|
|
//formulaFunctions,
|
|
resolveFormula,
|
|
}
|
|
}
|