2023-11-20 13:01:43 +03:00
|
|
|
import { type ViewContext, type ViewContextType } from '@hcengineering/view'
|
2022-04-19 12:38:31 +03:00
|
|
|
import { writable } from 'svelte/store'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2023-05-12 09:41:27 +03:00
|
|
|
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([]))
|