platform/packages/presentation/src/context.ts

24 lines
605 B
TypeScript
Raw Normal View History

import { type ViewContext, type ViewContextType } from '@hcengineering/view'
import { writable } from 'svelte/store'
/**
* @public
*/
export class ContextStore {
constructor (readonly contexts: ViewContext[]) {}
getLastContext (): ViewContext | undefined {
return this.contexts[this.contexts.length - 1]
}
isIncludes (type: ViewContextType): boolean {
return (
this.contexts.find((it) => it.mode === type || (Array.isArray(it.mode) && it.mode.includes(type))) !== undefined
)
}
}
/**
* @public
*/
export const contextStore = writable<ContextStore>(new ContextStore([]))