import type { MilkdownPlugin, SliceType } from '@milkdown/ctx' import { createSlice } from '@milkdown/ctx' /// @internal export type $Ctx = MilkdownPlugin & { key: SliceType } /// Create a slice plugin. The plugin will be registered in the `ctx` and can be accessed by other parts of the editor. /// ```ts /// const counterCtx = $ctx(0, 'counter'); /// ``` /// /// Additional property: /// - `key`: The key of the slice. export function $ctx(value: T, name: N): $Ctx { const slice = createSlice(value, name) const plugin: $Ctx = (ctx) => { ctx.inject(slice) return () => { return () => { ctx.remove(slice) } } } plugin.key = slice return plugin }