1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 10:54:44 +00:00

feat: update package.json exports to support new module formats and types

This commit is contained in:
2026-03-08 08:19:01 +07:00
parent bcc9cb2915
commit a996eb74b9
22 changed files with 1022 additions and 38 deletions

View File

@@ -0,0 +1,45 @@
import { ref, shallowRef, toValue } from 'vue';
import type { App, MaybeRefOrGetter, Ref, ShallowRef, UnwrapRef } from 'vue';
import { useContextFactory } from '@robonen/vue';
export type Direction = 'ltr' | 'rtl';
export interface ConfigContext {
dir: Ref<Direction>;
nonce: Ref<string | undefined>;
teleportTarget: ShallowRef<string | HTMLElement>;
}
export interface ConfigOptions {
dir?: MaybeRefOrGetter<Direction>;
nonce?: MaybeRefOrGetter<string | undefined>;
teleportTarget?: MaybeRefOrGetter<string | HTMLElement>;
}
const DEFAULT_CONFIG: UnwrapRef<ConfigContext> = {
dir: 'ltr',
nonce: undefined,
teleportTarget: 'body',
};
const ConfigCtx = useContextFactory<ConfigContext>('ConfigContext');
function resolveContext(options?: ConfigOptions): ConfigContext {
return {
dir: ref(toValue(options?.dir) ?? DEFAULT_CONFIG.dir),
nonce: ref(toValue(options?.nonce) ?? DEFAULT_CONFIG.nonce),
teleportTarget: shallowRef(toValue(options?.teleportTarget) ?? DEFAULT_CONFIG.teleportTarget),
};
}
export function provideConfig(options?: ConfigOptions): ConfigContext {
return ConfigCtx.provide(resolveContext(options));
}
export function provideAppConfig(app: App, options?: ConfigOptions): ConfigContext {
return ConfigCtx.appProvide(app)(resolveContext(options));
}
export function useConfig(): ConfigContext {
return ConfigCtx.inject(resolveContext());
}