|
|
|
@ -51,7 +51,7 @@ export interface EngineContextBase { |
|
|
|
|
nextId: number |
|
|
|
|
/** 数据源 */ |
|
|
|
|
sources: Record<string, Record<string, unknown>> |
|
|
|
|
/** 到处数据 */ |
|
|
|
|
/** 导出数据 */ |
|
|
|
|
export: () => Exported |
|
|
|
|
/** 获取动态数据 */ |
|
|
|
|
value: <T>(blockId: string, key: string) => T | undefined |
|
|
|
@ -74,8 +74,8 @@ export function useContext(): EngineContext { |
|
|
|
|
|
|
|
|
|
export const parentViewIdKey: InjectionKey<string> = Symbol.for('ddd:view:parent:id') |
|
|
|
|
|
|
|
|
|
export function useParentViewId(): string | undefined { |
|
|
|
|
return inject(parentViewIdKey) |
|
|
|
|
export function useParentViewId(): string { |
|
|
|
|
return must(inject(parentViewIdKey), 'no parentViewId no found') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function provideParentViewId(id: string | undefined): void { |
|
|
|
@ -86,7 +86,7 @@ export function provideParentViewId(id: string | undefined): void { |
|
|
|
|
|
|
|
|
|
const blockIdKey: InjectionKey<string> = Symbol.for('ddd:block:id') |
|
|
|
|
|
|
|
|
|
export function useBlockId(): string { |
|
|
|
|
export const useBlockId = (): string => { |
|
|
|
|
return must(inject(blockIdKey), "no block found") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -94,8 +94,9 @@ export function provideBlockId(id: string): void { |
|
|
|
|
provide(blockIdKey, id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const currentViewDOMRectKey: InjectionKey<UnwrapNestedRefs<Partial<DOMRect>>> = Symbol.for('ddd:view:current:domrect') |
|
|
|
|
export const parentViewDOMRectKey: InjectionKey<UnwrapNestedRefs<Partial<DOMRect>>> = Symbol.for('ddd:view:parent:domrect') |
|
|
|
|
type ReactingDomRect = InjectionKey<UnwrapNestedRefs<Partial<DOMRect>>> |
|
|
|
|
export const currentViewDOMRectKey: ReactingDomRect = Symbol.for('ddd:view:current:domrect') |
|
|
|
|
export const parentViewDOMRectKey: ReactingDomRect = Symbol.for('ddd:view:parent:domrect') |
|
|
|
|
|
|
|
|
|
export function useCurrentViewDOMRect(): UnwrapNestedRefs<Partial<DOMRect>> { |
|
|
|
|
return must(inject(currentViewDOMRectKey), 'no DOMReact found') |
|
|
|
@ -163,7 +164,9 @@ export interface TreeData { |
|
|
|
|
value: any |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const treeDataKey: InjectionKey<UnwrapNestedRefs<TreeData>|WritableComputedRef<TreeData> | null> = Symbol.for('ddd:view:tree:data') |
|
|
|
|
type RefTreeData = InjectionKey<UnwrapNestedRefs<TreeData>|WritableComputedRef<TreeData>|null> |
|
|
|
|
|
|
|
|
|
const treeDataKey: RefTreeData = Symbol.for('ddd:view:tree:data') |
|
|
|
|
|
|
|
|
|
export function provideTreeData(data: UnwrapNestedRefs<TreeData> | WritableComputedRef<TreeData> | null) { |
|
|
|
|
provide(treeDataKey, data) |
|
|
|
@ -175,7 +178,9 @@ export function useSource<T = unknown>(source: string | undefined, fallback?: T) |
|
|
|
|
const blockId = useBlockId() |
|
|
|
|
|
|
|
|
|
return computed<T | undefined>({ |
|
|
|
|
|
|
|
|
|
get(): T | undefined { |
|
|
|
|
console.log('get',source,'source',blockId || ctx.activeBlockId,'id') |
|
|
|
|
if (!source) { |
|
|
|
|
return fallback |
|
|
|
|
} |
|
|
|
@ -193,6 +198,7 @@ export function useSource<T = unknown>(source: string | undefined, fallback?: T) |
|
|
|
|
return valueOf(ctx.sources[id], source) ?? fallback |
|
|
|
|
}, |
|
|
|
|
set(value: T | undefined) { |
|
|
|
|
console.log('set',value,'value',source,'source',blockId || ctx.activeBlockId,'id') |
|
|
|
|
if (!source || source.startsWith("$")) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|