|
|
@ -51,7 +51,7 @@ export interface EngineContextBase { |
|
|
|
nextId: number |
|
|
|
nextId: number |
|
|
|
/** 数据源 */ |
|
|
|
/** 数据源 */ |
|
|
|
sources: Record<string, Record<string, unknown>> |
|
|
|
sources: Record<string, Record<string, unknown>> |
|
|
|
/** 到处数据 */ |
|
|
|
/** 导出数据 */ |
|
|
|
export: () => Exported |
|
|
|
export: () => Exported |
|
|
|
/** 获取动态数据 */ |
|
|
|
/** 获取动态数据 */ |
|
|
|
value: <T>(blockId: string, key: string) => T | undefined |
|
|
|
value: <T>(blockId: string, key: string) => T | undefined |
|
|
@ -62,7 +62,7 @@ export type EngineContext = UnwrapNestedRefs<EngineContextBase> |
|
|
|
export const contextKey: InjectionKey<EngineContext> = Symbol.for('ddd:engine') |
|
|
|
export const contextKey: InjectionKey<EngineContext> = Symbol.for('ddd:engine') |
|
|
|
|
|
|
|
|
|
|
|
const must = <T>(v: T | undefined, error: string): T => { |
|
|
|
const must = <T>(v: T | undefined, error: string): T => { |
|
|
|
if (v == null) { |
|
|
|
if(v==null){ |
|
|
|
throw new Error(error) |
|
|
|
throw new Error(error) |
|
|
|
} |
|
|
|
} |
|
|
|
return v |
|
|
|
return v |
|
|
@ -74,8 +74,8 @@ export function useContext(): EngineContext { |
|
|
|
|
|
|
|
|
|
|
|
export const parentViewIdKey: InjectionKey<string> = Symbol.for('ddd:view:parent:id') |
|
|
|
export const parentViewIdKey: InjectionKey<string> = Symbol.for('ddd:view:parent:id') |
|
|
|
|
|
|
|
|
|
|
|
export function useParentViewId(): string | undefined { |
|
|
|
export function useParentViewId(): string { |
|
|
|
return inject(parentViewIdKey) |
|
|
|
return must(inject(parentViewIdKey), 'no parentViewId no found') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function provideParentViewId(id: string | undefined): void { |
|
|
|
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') |
|
|
|
const blockIdKey: InjectionKey<string> = Symbol.for('ddd:block:id') |
|
|
|
|
|
|
|
|
|
|
|
export function useBlockId(): string { |
|
|
|
export const useBlockId = (): string => { |
|
|
|
return must(inject(blockIdKey), "no block found") |
|
|
|
return must(inject(blockIdKey), "no block found") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -94,8 +94,9 @@ export function provideBlockId(id: string): void { |
|
|
|
provide(blockIdKey, id) |
|
|
|
provide(blockIdKey, id) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const currentViewDOMRectKey: InjectionKey<UnwrapNestedRefs<Partial<DOMRect>>> = Symbol.for('ddd:view:current:domrect') |
|
|
|
type ReactingDomRect = InjectionKey<UnwrapNestedRefs<Partial<DOMRect>>> |
|
|
|
export const parentViewDOMRectKey: InjectionKey<UnwrapNestedRefs<Partial<DOMRect>>> = Symbol.for('ddd:view:parent: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>> { |
|
|
|
export function useCurrentViewDOMRect(): UnwrapNestedRefs<Partial<DOMRect>> { |
|
|
|
return must(inject(currentViewDOMRectKey), 'no DOMReact found') |
|
|
|
return must(inject(currentViewDOMRectKey), 'no DOMReact found') |
|
|
@ -106,9 +107,9 @@ export function useParentViewDOMRect(): UnwrapNestedRefs<Partial<DOMRect>> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function getModule(ctx: UnwrapNestedRefs<EngineContextBase>, mid: string): Module | undefined { |
|
|
|
export function getModule(ctx: UnwrapNestedRefs<EngineContextBase>, mid: string): Module | undefined { |
|
|
|
for (const category of ctx.categories) { |
|
|
|
for(const category of ctx.categories){ |
|
|
|
for (const module of category.modules) { |
|
|
|
for(const module of category.modules){ |
|
|
|
if (module.mid === mid) { |
|
|
|
if(module.mid === mid) { |
|
|
|
return module |
|
|
|
return module |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -116,15 +117,15 @@ export function getModule(ctx: UnwrapNestedRefs<EngineContextBase>, mid: string) |
|
|
|
return undefined |
|
|
|
return undefined |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function useModule() { |
|
|
|
export function useModule(){ |
|
|
|
const ctx = useContext() |
|
|
|
const ctx = useContext() |
|
|
|
|
|
|
|
|
|
|
|
return computed((): Module | undefined => { |
|
|
|
return computed((): Module | undefined => { |
|
|
|
for (const block of ctx.blocks) { |
|
|
|
for(const block of ctx.blocks){ |
|
|
|
if (block.vid !== ctx.activeBlockId) { |
|
|
|
if(block.vid !== ctx.activeBlockId){ |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
const module = getModule(ctx, block.mid) |
|
|
|
const module = getModule(ctx,block.mid) |
|
|
|
if (module != null) { |
|
|
|
if (module != null) { |
|
|
|
return module |
|
|
|
return module |
|
|
|
} |
|
|
|
} |
|
|
@ -163,7 +164,9 @@ export interface TreeData { |
|
|
|
value: any |
|
|
|
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) { |
|
|
|
export function provideTreeData(data: UnwrapNestedRefs<TreeData> | WritableComputedRef<TreeData> | null) { |
|
|
|
provide(treeDataKey, data) |
|
|
|
provide(treeDataKey, data) |
|
|
@ -175,7 +178,9 @@ export function useSource<T = unknown>(source: string | undefined, fallback?: T) |
|
|
|
const blockId = useBlockId() |
|
|
|
const blockId = useBlockId() |
|
|
|
|
|
|
|
|
|
|
|
return computed<T | undefined>({ |
|
|
|
return computed<T | undefined>({ |
|
|
|
|
|
|
|
|
|
|
|
get(): T | undefined { |
|
|
|
get(): T | undefined { |
|
|
|
|
|
|
|
console.log('get',source,'source',blockId || ctx.activeBlockId,'id') |
|
|
|
if (!source) { |
|
|
|
if (!source) { |
|
|
|
return fallback |
|
|
|
return fallback |
|
|
|
} |
|
|
|
} |
|
|
@ -193,6 +198,7 @@ export function useSource<T = unknown>(source: string | undefined, fallback?: T) |
|
|
|
return valueOf(ctx.sources[id], source) ?? fallback |
|
|
|
return valueOf(ctx.sources[id], source) ?? fallback |
|
|
|
}, |
|
|
|
}, |
|
|
|
set(value: T | undefined) { |
|
|
|
set(value: T | undefined) { |
|
|
|
|
|
|
|
console.log('set',value,'value',source,'source',blockId || ctx.activeBlockId,'id') |
|
|
|
if (!source || source.startsWith("$")) { |
|
|
|
if (!source || source.startsWith("$")) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|