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 type { MaybeRef } from '@vueuse/core' |
||||||
import { useRoute } from '#imports' |
import { computed, unref, useRoute } from '#imports' |
||||||
|
|
||||||
export interface CellUrlOptions { |
export interface CellUrlOptions { |
||||||
behavior?: string |
behavior?: string |
||||||
overlay?: 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 |
if (!serialized) return undefined |
||||||
|
|
||||||
try { |
try { |
||||||
const rules: Array<[RegExp, {}]> = Object.entries(JSON.parse(serialized)).map(([key, value]) => [ |
return Object.entries(JSON.parse(serialized)).map(([key, value]) => [new RegExp(key), value] as ParsedRules) |
||||||
new RegExp(key), |
|
||||||
value as {}, |
|
||||||
]) |
|
||||||
return rules |
|
||||||
} catch (err) { |
} catch (err) { |
||||||
console.error(err) |
console.error(err) |
||||||
|
|
||||||
return undefined |
return undefined |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
const [useProvideCellUrlConfig, useCellUrlGeneralConfig] = useInjectionState(() => { |
export function useCellUrlConfig(url?: MaybeRef<string>) { |
||||||
const route = useRoute() |
const route = useRoute() |
||||||
|
|
||||||
return { |
const config = $computed(() => ({ |
||||||
behavior: route.query.url_behavior as string | undefined, |
behavior: route.query.url_behavior as string | undefined, |
||||||
overlay: route.query.url_overlay as string | undefined, |
overlay: route.query.url_overlay as string | undefined, |
||||||
rules: parseUrlRules(route.query.url_rules as string), |
rules: parseUrlRules(route.query.url_rules as string), |
||||||
} |
})) |
||||||
}, 'cell-url-config') |
|
||||||
|
const options = computed(() => { |
||||||
export { useProvideCellUrlConfig } |
const options = { behavior: config.behavior, overlay: config.overlay } |
||||||
|
|
||||||
export function useCellUrlConfig(url: ComputedRef<string>) { |
if (config.rules && (!config.behavior || !config.overlay)) { |
||||||
const config = useCellUrlGeneralConfig() |
for (const [regex, value] of config.rules) { |
||||||
if (!config) return undefined |
if (unref(url)?.match(regex)) return Object.assign(options, value) |
||||||
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) |
|
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
return options |
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