mirror of https://github.com/nocodb/nocodb
Wing-Kam Wong
2 years ago
48 changed files with 278 additions and 218 deletions
@ -1,48 +1,48 @@
|
||||
import type { ComputedRef } from 'vue' |
||||
import { useRoute } from '#imports' |
||||
import type { MaybeRef } from '@vueuse/core' |
||||
import { computed, unref, useRoute } from '#imports' |
||||
|
||||
export interface CellUrlOptions { |
||||
behavior?: string |
||||
overlay?: string |
||||
} |
||||
|
||||
const parseUrlRules = (serialized: string | undefined): Array<[RegExp, CellUrlOptions]> | undefined => { |
||||
type ParsedRules = [RegExp, CellUrlOptions] |
||||
|
||||
const parseUrlRules = (serialized?: string): ParsedRules[] | undefined => { |
||||
if (!serialized) return undefined |
||||
|
||||
try { |
||||
const rules: Array<[RegExp, {}]> = Object.entries(JSON.parse(serialized)).map(([key, value]) => [ |
||||
new RegExp(key), |
||||
value as {}, |
||||
]) |
||||
return rules |
||||
return Object.entries(JSON.parse(serialized)).map(([key, value]) => [new RegExp(key), value] as ParsedRules) |
||||
} catch (err) { |
||||
console.error(err) |
||||
|
||||
return undefined |
||||
} |
||||
} |
||||
|
||||
const [useProvideCellUrlConfig, useCellUrlGeneralConfig] = useInjectionState(() => { |
||||
export function useCellUrlConfig(url?: MaybeRef<string>) { |
||||
const route = useRoute() |
||||
|
||||
return { |
||||
const config = $computed(() => ({ |
||||
behavior: route.query.url_behavior as string | undefined, |
||||
overlay: route.query.url_overlay as string | undefined, |
||||
rules: parseUrlRules(route.query.url_rules as string), |
||||
} |
||||
}, 'cell-url-config') |
||||
|
||||
export { useProvideCellUrlConfig } |
||||
|
||||
export function useCellUrlConfig(url: ComputedRef<string>) { |
||||
const config = useCellUrlGeneralConfig() |
||||
if (!config) return undefined |
||||
return computed(() => { |
||||
const { behavior, overlay, rules } = config |
||||
const options = { behavior, overlay } |
||||
if (rules && (!behavior || !overlay)) { |
||||
for (const [regex, value] of rules) { |
||||
if (url.value.match(regex)) return Object.assign(options, value) |
||||
})) |
||||
|
||||
const options = computed(() => { |
||||
const options = { behavior: config.behavior, overlay: config.overlay } |
||||
|
||||
if (config.rules && (!config.behavior || !config.overlay)) { |
||||
for (const [regex, value] of config.rules) { |
||||
if (unref(url)?.match(regex)) return Object.assign(options, value) |
||||
} |
||||
} |
||||
|
||||
return options |
||||
}) |
||||
|
||||
return { |
||||
cellUrlConfig: config, |
||||
cellUrlOptions: options, |
||||
} |
||||
} |
||||
|
@ -0,0 +1,20 @@
|
||||
{ |
||||
"$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/v2-preview/web-types.json", |
||||
"name": "nc-gui", |
||||
"framework": "vue", |
||||
"version": "1.0.0", |
||||
"contributions": { |
||||
"html": { |
||||
"vue-directives": [ |
||||
{ |
||||
"name": "e", |
||||
"description": "Telemetry directive" |
||||
}, |
||||
{ |
||||
"name": "t", |
||||
"description": "I18n directive" |
||||
} |
||||
] |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue