mirror of
https://github.com/nocodb/nocodb.git
synced 2026-05-01 02:07:07 +00:00
* fix: get rid of barrel files * chore: get rid of explicit imports * fix: use explicit import for classes and enums * fix: use explicit import for enum & class & aliases * fix: build issues
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import type { MaybeRef } from '@vueuse/core'
|
|
|
|
export interface CellUrlOptions {
|
|
behavior?: string
|
|
overlay?: string
|
|
}
|
|
|
|
type ParsedRules = [RegExp, CellUrlOptions]
|
|
|
|
const parseUrlRules = (serialized?: string): ParsedRules[] | undefined => {
|
|
if (!serialized) return undefined
|
|
|
|
try {
|
|
return Object.entries(JSON.parse(serialized)).map(([key, value]) => [new RegExp(key), value] as ParsedRules)
|
|
} catch (err) {
|
|
console.error(err)
|
|
|
|
return undefined
|
|
}
|
|
}
|
|
|
|
export function useCellUrlConfig(url?: MaybeRef<string>) {
|
|
const router = useRouter()
|
|
|
|
const route = router.currentRoute
|
|
|
|
const config = computed(() => ({
|
|
behavior: route.value.query.url_behavior as string | undefined,
|
|
overlay: route.value.query.url_overlay as string | undefined,
|
|
rules: parseUrlRules(route.value.query.url_rules as string),
|
|
}))
|
|
|
|
const options = computed(() => {
|
|
const options = { behavior: config.value.behavior, overlay: config.value.overlay }
|
|
|
|
if (config.value.rules && (!config.value.behavior || !config.value.overlay)) {
|
|
for (const [regex, value] of config.value.rules) {
|
|
if (unref(url)?.match(regex)) return Object.assign(options, value)
|
|
}
|
|
}
|
|
|
|
return options
|
|
})
|
|
|
|
return {
|
|
cellUrlConfig: config.value,
|
|
cellUrlOptions: options,
|
|
}
|
|
}
|