index.es.js.map 50 KB

1
  1. {"version":3,"file":"index.es.js","sources":["../src/__internal__/utils.ts","../src/__internal__/remark-handlers.ts","../src/internal-plugin/config.ts","../src/internal-plugin/init.ts","../src/internal-plugin/schema.ts","../src/internal-plugin/parser.ts","../src/internal-plugin/serializer.ts","../src/internal-plugin/editor-state.ts","../src/internal-plugin/editor-view.ts","../src/internal-plugin/commands.ts","../src/editor/editor.ts"],"sourcesContent":["/* Copyright 2021, Milkdown by Mirone. */\nimport type { Meta, MilkdownPlugin } from '@milkdown/ctx'\n\nexport function withMeta<T extends MilkdownPlugin>(plugin: T, meta: Partial<Meta> & Pick<Meta, 'displayName'>): T {\n plugin.meta = {\n package: '@milkdown/core',\n group: 'System',\n ...meta,\n }\n\n return plugin\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { Options } from 'remark-stringify'\n\nexport const remarkHandlers: Required<Options>['handlers'] = {\n strong: (node, _, state, info) => {\n const marker = node.marker || state.options.strong || '*'\n const exit = state.enter('strong')\n const tracker = state.createTracker(info)\n let value = tracker.move(marker + marker)\n value += tracker.move(\n state.containerPhrasing(node, {\n before: value,\n after: marker,\n ...tracker.current(),\n }),\n )\n value += tracker.move(marker + marker)\n exit()\n return value\n },\n emphasis: (node, _, state, info) => {\n const marker = node.marker || state.options.emphasis || '*'\n const exit = state.enter('emphasis')\n const tracker = state.createTracker(info)\n let value = tracker.move(marker)\n value += tracker.move(\n state.containerPhrasing(node, {\n before: value,\n after: marker,\n ...tracker.current(),\n }),\n )\n value += tracker.move(marker)\n exit()\n return value\n },\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { Ctx, MilkdownPlugin } from '@milkdown/ctx'\nimport { createTimer } from '@milkdown/ctx'\nimport { withMeta } from '../__internal__'\n\n/// @internal\nexport type Config = (ctx: Ctx) => void | Promise<void>\n\n/// The timer which will be resolved when the config plugin is ready.\nexport const ConfigReady = createTimer('ConfigReady')\n\n/// The config plugin.\n/// This plugin will load all user configs.\nexport function config(configure: Config): MilkdownPlugin {\n const plugin: MilkdownPlugin = (ctx) => {\n ctx.record(ConfigReady)\n\n return async () => {\n await configure(ctx)\n ctx.done(ConfigReady)\n\n return () => {\n ctx.clearTimer(ConfigReady)\n }\n }\n }\n\n withMeta(plugin, {\n displayName: 'Config',\n })\n\n return plugin\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { MilkdownPlugin, SliceType, TimerType } from '@milkdown/ctx'\nimport { createSlice, createTimer } from '@milkdown/ctx'\nimport type { InputRule } from '@milkdown/prose/inputrules'\nimport type { Plugin } from '@milkdown/prose/state'\nimport type { MarkViewConstructor, NodeViewConstructor } from '@milkdown/prose/view'\nimport type { RemarkParser, RemarkPlugin } from '@milkdown/transformer'\nimport remarkParse from 'remark-parse'\nimport type { Options } from 'remark-stringify'\nimport remarkStringify from 'remark-stringify'\nimport { unified } from 'unified'\n\nimport type { Editor } from '../editor'\nimport { remarkHandlers, withMeta } from '../__internal__'\nimport { ConfigReady } from './config'\n\n/// The timer which will be resolved when the init plugin is ready.\nexport const InitReady = createTimer('InitReady')\n\n/// A slice which stores timers that need to be waited for before starting to run the plugin.\n/// By default, it's `[ConfigReady]`.\nexport const initTimerCtx = createSlice([] as TimerType[], 'initTimer')\n\n/// A slice which stores the editor instance.\nexport const editorCtx = createSlice({} as Editor, 'editor')\n\n/// A slice which stores the input rules.\nexport const inputRulesCtx = createSlice([] as InputRule[], 'inputRules')\n\n/// A slice which stores the prosemirror plugins.\nexport const prosePluginsCtx = createSlice([] as Plugin[], 'prosePlugins')\n\n/// A slice which stores the remark plugins.\nexport const remarkPluginsCtx = createSlice([] as RemarkPlugin[], 'remarkPlugins')\n\ntype NodeView = [nodeId: string, view: NodeViewConstructor]\n\n/// A slice which stores the prosemirror node views.\nexport const nodeViewCtx = createSlice([] as NodeView[], 'nodeView')\n\ntype MarkView = [nodeId: string, view: MarkViewConstructor]\n\n/// A slice which stores the prosemirror mark views.\nexport const markViewCtx = createSlice([] as MarkView[], 'markView')\n\n/// A slice which stores the remark instance.\nexport const remarkCtx: SliceType<RemarkParser, 'remark'> = createSlice(unified().use(remarkParse).use(remarkStringify), 'remark')\n\n/// A slice which stores the remark stringify options.\nexport const remarkStringifyOptionsCtx = createSlice({\n handlers: remarkHandlers,\n} as Options, 'remarkStringifyOptions')\n\n/// The init plugin.\n/// This plugin prepare slices that needed by other plugins. And create a remark instance.\n///\n/// This plugin will wait for the config plugin.\nexport function init(editor: Editor): MilkdownPlugin {\n const plugin: MilkdownPlugin = (ctx) => {\n ctx.inject(editorCtx, editor)\n .inject(prosePluginsCtx, [])\n .inject(remarkPluginsCtx, [])\n .inject(inputRulesCtx, [])\n .inject(nodeViewCtx, [])\n .inject(markViewCtx, [])\n .inject(remarkStringifyOptionsCtx, {\n handlers: remarkHandlers,\n })\n .inject(remarkCtx, unified().use(remarkParse).use(remarkStringify))\n .inject(initTimerCtx, [ConfigReady])\n .record(InitReady)\n\n return async () => {\n await ctx.waitTimers(initTimerCtx)\n const options = ctx.get(remarkStringifyOptionsCtx)\n ctx.set(remarkCtx, unified().use(remarkParse).use(remarkStringify, options))\n\n ctx.done(InitReady)\n\n return () => {\n ctx.remove(editorCtx)\n .remove(prosePluginsCtx)\n .remove(remarkPluginsCtx)\n .remove(inputRulesCtx)\n .remove(nodeViewCtx)\n .remove(markViewCtx)\n .remove(remarkStringifyOptionsCtx)\n .remove(remarkCtx)\n .remove(initTimerCtx)\n .clearTimer(InitReady)\n }\n }\n }\n withMeta(plugin, {\n displayName: 'Init',\n })\n\n return plugin\n}\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { MilkdownPlugin, TimerType } from '@milkdown/ctx'\nimport { createSlice, createTimer } from '@milkdown/ctx'\nimport { Schema } from '@milkdown/prose/model'\nimport type { MarkSchema, NodeSchema, RemarkParser } from '@milkdown/transformer'\n\nimport { withMeta } from '../__internal__'\nimport { InitReady, remarkCtx, remarkPluginsCtx } from '.'\n\n/// The timer which will be resolved when the schema plugin is ready.\nexport const SchemaReady = createTimer('SchemaReady')\n\n/// A slice which stores timers that need to be waited for before starting to run the plugin.\n/// By default, it's `[InitReady]`.\nexport const schemaTimerCtx = createSlice([] as TimerType[], 'schemaTimer')\n\n/// A slice which contains the schema.\nexport const schemaCtx = createSlice({} as Schema, 'schema')\n\n/// A slice which stores the nodes spec.\nexport const nodesCtx = createSlice([] as Array<[string, NodeSchema]>, 'nodes')\n\n/// A slice which stores the marks spec.\nexport const marksCtx = createSlice([] as Array<[string, MarkSchema]>, 'marks')\n\nfunction extendPriority<T extends NodeSchema | MarkSchema>(x: T): T {\n return {\n ...x,\n parseDOM: x.parseDOM?.map(rule => ({ priority: x.priority, ...rule })),\n }\n}\n\n/// The schema plugin.\n/// This plugin will load all nodes spec and marks spec and create a schema.\n///\n/// This plugin will wait for the init plugin.\nexport const schema: MilkdownPlugin = (ctx) => {\n ctx\n .inject(schemaCtx, {} as Schema)\n .inject(nodesCtx, [])\n .inject(marksCtx, [])\n .inject(schemaTimerCtx, [InitReady])\n .record(SchemaReady)\n\n return async () => {\n await ctx.waitTimers(schemaTimerCtx)\n\n const remark = ctx.get(remarkCtx)\n const remarkPlugins = ctx.get(remarkPluginsCtx)\n\n const processor = remarkPlugins.reduce((acc: RemarkParser, plug) => acc.use(plug.plugin, plug.options) as unknown as RemarkParser, remark)\n ctx.set(remarkCtx, processor)\n\n const nodes = Object.fromEntries(ctx.get(nodesCtx).map(([key, x]) => [key, extendPriority(x)]))\n const marks = Object.fromEntries(ctx.get(marksCtx).map(([key, x]) => [key, extendPriority(x)]))\n const schema = new Schema({ nodes, marks })\n\n ctx.set(schemaCtx, schema)\n\n ctx.done(SchemaReady)\n\n return () => {\n ctx.remove(schemaCtx).remove(nodesCtx).remove(marksCtx).remove(schemaTimerCtx).clearTimer(SchemaReady)\n }\n }\n}\n\nwithMeta(schema, {\n displayName: 'Schema',\n})\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { MilkdownPlugin, TimerType } from '@milkdown/ctx'\nimport { createSlice, createTimer } from '@milkdown/ctx'\nimport { ctxCallOutOfScope } from '@milkdown/exception'\nimport type { Parser } from '@milkdown/transformer'\nimport { ParserState } from '@milkdown/transformer'\n\nimport { withMeta } from '../__internal__'\nimport { remarkCtx } from './init'\nimport { SchemaReady, schemaCtx } from './schema'\n\n/// The timer which will be resolved when the parser plugin is ready.\nexport const ParserReady = createTimer('ParserReady')\n\nconst outOfScope = (() => {\n throw ctxCallOutOfScope()\n}) as Parser\n\n/// A slice which contains the parser.\nexport const parserCtx = createSlice(outOfScope, 'parser')\n\n/// A slice which stores timers that need to be waited for before starting to run the plugin.\n/// By default, it's `[SchemaReady]`.\nexport const parserTimerCtx = createSlice([] as TimerType[], 'parserTimer')\n\n/// The parser plugin.\n/// This plugin will create a parser.\n///\n/// This plugin will wait for the schema plugin.\nexport const parser: MilkdownPlugin = (ctx) => {\n ctx.inject(parserCtx, outOfScope).inject(parserTimerCtx, [SchemaReady]).record(ParserReady)\n\n return async () => {\n await ctx.waitTimers(parserTimerCtx)\n const remark = ctx.get(remarkCtx)\n const schema = ctx.get(schemaCtx)\n\n ctx.set(parserCtx, ParserState.create(schema, remark))\n ctx.done(ParserReady)\n return () => {\n ctx.remove(parserCtx).remove(parserTimerCtx).clearTimer(ParserReady)\n }\n }\n}\n\nwithMeta(parser, {\n displayName: 'Parser',\n})\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { MilkdownPlugin, TimerType } from '@milkdown/ctx'\nimport { createSlice, createTimer } from '@milkdown/ctx'\nimport type { Serializer } from '@milkdown/transformer'\nimport { SerializerState } from '@milkdown/transformer'\n\nimport { ctxCallOutOfScope } from '@milkdown/exception'\nimport { withMeta } from '../__internal__'\nimport { remarkCtx } from './init'\nimport { SchemaReady, schemaCtx } from './schema'\n\n/// The timer which will be resolved when the serializer plugin is ready.\nexport const SerializerReady = createTimer('SerializerReady')\n\n/// A slice which stores timers that need to be waited for before starting to run the plugin.\n/// By default, it's `[SchemaReady]`.\nexport const serializerTimerCtx = createSlice([] as TimerType[], 'serializerTimer')\n\nconst outOfScope = (() => {\n throw ctxCallOutOfScope()\n}) as Serializer\n\n/// A slice which contains the serializer.\nexport const serializerCtx = createSlice<Serializer, 'serializer'>(outOfScope, 'serializer')\n\n/// The serializer plugin.\n/// This plugin will create a serializer.\n///\n/// This plugin will wait for the schema plugin.\nexport const serializer: MilkdownPlugin = (ctx) => {\n ctx\n .inject(serializerCtx, outOfScope)\n .inject(serializerTimerCtx, [SchemaReady])\n .record(SerializerReady)\n\n return async () => {\n await ctx.waitTimers(serializerTimerCtx)\n const remark = ctx.get(remarkCtx)\n const schema = ctx.get(schemaCtx)\n\n ctx.set(serializerCtx, SerializerState.create(schema, remark))\n ctx.done(SerializerReady)\n\n return () => {\n ctx.remove(serializerCtx).remove(serializerTimerCtx).clearTimer(SerializerReady)\n }\n }\n}\n\nwithMeta(serializer, {\n displayName: 'Serializer',\n})\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { MilkdownPlugin, TimerType } from '@milkdown/ctx'\nimport { createSlice, createTimer } from '@milkdown/ctx'\nimport { docTypeError } from '@milkdown/exception'\nimport { customInputRules as createInputRules } from '@milkdown/prose'\nimport { baseKeymap, chainCommands, deleteSelection, joinBackward, selectNodeBackward } from '@milkdown/prose/commands'\nimport { undoInputRule } from '@milkdown/prose/inputrules'\nimport { keymap as createKeymap } from '@milkdown/prose/keymap'\nimport type { Schema } from '@milkdown/prose/model'\nimport { DOMParser, Node } from '@milkdown/prose/model'\nimport type { Command } from '@milkdown/prose/state'\nimport { EditorState, Plugin, PluginKey } from '@milkdown/prose/state'\nimport type { JSONRecord, Parser } from '@milkdown/transformer'\n\nimport { withMeta } from '../__internal__'\nimport { inputRulesCtx, prosePluginsCtx } from './init'\nimport { ParserReady, parserCtx } from './parser'\nimport { schemaCtx } from './schema'\nimport { SerializerReady } from './serializer'\nimport { CommandsReady } from '.'\n\n/// @internal\nexport type DefaultValue = string | { type: 'html', dom: HTMLElement } | { type: 'json', value: JSONRecord }\ntype StateOptions = Parameters<typeof EditorState.create>[0]\ntype StateOptionsOverride = (prev: StateOptions) => StateOptions\n\n/// A slice which contains the default value of the editor.\n/// Can be markdown string, html string or json.\nexport const defaultValueCtx = createSlice('' as DefaultValue, 'defaultValue')\n\n/// A slice which contains the editor state.\nexport const editorStateCtx = createSlice({} as EditorState, 'editorState')\n\n/// A slice which contains the options which is used to create the editor state.\nexport const editorStateOptionsCtx = createSlice<StateOptionsOverride>(x => x, 'stateOptions')\n\n/// A slice which stores timers that need to be waited for before starting to run the plugin.\n/// By default, it's `[ParserReady, SerializerReady, CommandsReady]`.\nexport const editorStateTimerCtx = createSlice([] as TimerType[], 'editorStateTimer')\n\n/// The timer which will be resolved when the editor state plugin is ready.\nexport const EditorStateReady = createTimer('EditorStateReady')\n\n/// @internal\nexport function getDoc(defaultValue: DefaultValue, parser: Parser, schema: Schema) {\n if (typeof defaultValue === 'string')\n return parser(defaultValue)\n\n if (defaultValue.type === 'html')\n return DOMParser.fromSchema(schema).parse(defaultValue.dom)\n\n if (defaultValue.type === 'json')\n return Node.fromJSON(schema, defaultValue.value)\n\n throw docTypeError(defaultValue)\n}\n\nconst key = new PluginKey('MILKDOWN_STATE_TRACKER')\n\nfunction overrideBaseKeymap(keymap: Record<string, Command>) {\n const handleBackspace = chainCommands(\n undoInputRule,\n deleteSelection,\n joinBackward,\n selectNodeBackward,\n )\n keymap.Backspace = handleBackspace\n return keymap\n}\n\n/// The editor state plugin.\n/// This plugin will create a prosemirror editor state.\n///\n/// This plugin will wait for the parser plugin, serializer plugin and commands plugin.\nexport const editorState: MilkdownPlugin = (ctx) => {\n ctx.inject(defaultValueCtx, '')\n .inject(editorStateCtx, {} as EditorState)\n .inject(editorStateOptionsCtx, x => x)\n .inject(editorStateTimerCtx, [ParserReady, SerializerReady, CommandsReady])\n .record(EditorStateReady)\n\n return async () => {\n await ctx.waitTimers(editorStateTimerCtx)\n\n const schema = ctx.get(schemaCtx)\n const parser = ctx.get(parserCtx)\n const rules = ctx.get(inputRulesCtx)\n const optionsOverride = ctx.get(editorStateOptionsCtx)\n const prosePlugins = ctx.get(prosePluginsCtx)\n const defaultValue = ctx.get(defaultValueCtx)\n const doc = getDoc(defaultValue, parser, schema)\n\n const plugins = [\n ...prosePlugins,\n new Plugin({\n key,\n state: {\n init: () => {\n // do nothing\n },\n apply: (_tr, _value, _oldState, newState) => {\n ctx.set(editorStateCtx, newState)\n },\n },\n }),\n createInputRules({ rules }),\n createKeymap(overrideBaseKeymap(baseKeymap)),\n ]\n\n ctx.set(prosePluginsCtx, plugins)\n\n const options = optionsOverride({\n schema,\n doc,\n plugins,\n })\n\n const state = EditorState.create(options)\n ctx.set(editorStateCtx, state)\n ctx.done(EditorStateReady)\n\n return () => {\n ctx.remove(defaultValueCtx)\n .remove(editorStateCtx)\n .remove(editorStateOptionsCtx)\n .remove(editorStateTimerCtx)\n .clearTimer(EditorStateReady)\n }\n }\n}\n\nwithMeta(editorState, {\n displayName: 'EditorState',\n})\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { Ctx, MilkdownPlugin, TimerType } from '@milkdown/ctx'\nimport { createSlice, createTimer } from '@milkdown/ctx'\nimport { Plugin, PluginKey } from '@milkdown/prose/state'\nimport type { DirectEditorProps } from '@milkdown/prose/view'\nimport { EditorView } from '@milkdown/prose/view'\n\nimport { withMeta } from '../__internal__'\nimport { EditorStateReady, editorStateCtx } from './editor-state'\nimport { InitReady, markViewCtx, nodeViewCtx, prosePluginsCtx } from './init'\n\ntype EditorOptions = Omit<DirectEditorProps, 'state'>\n\ntype RootType = Node | undefined | null | string\n\n/// The timer which will be resolved when the editor view plugin is ready.\nexport const EditorViewReady = createTimer('EditorViewReady')\n\n/// A slice which contains the editor view instance.\nexport const editorViewCtx = createSlice({} as EditorView, 'editorView')\n\n/// A slice which stores timers that need to be waited for before starting to run the plugin.\n/// By default, it's `[EditorStateReady]`.\nexport const editorViewTimerCtx = createSlice([] as TimerType[], 'editorViewTimer')\n\n/// A slice which contains the editor view options which will be passed to the editor view.\nexport const editorViewOptionsCtx = createSlice({} as Partial<EditorOptions>, 'editorViewOptions')\n\n/// A slice which contains the value to get the root element.\n/// Can be a selector string, a node or null.\n/// If it's null, the editor will be created in the body.\nexport const rootCtx = createSlice(null as RootType, 'root')\n\n/// A slice which contains the actually root element.\nexport const rootDOMCtx = createSlice(null as unknown as HTMLElement, 'rootDOM')\n\n/// A slice which contains the root element attributes.\n/// You can add attributes to the root element by this slice.\nexport const rootAttrsCtx = createSlice({} as Record<string, string>, 'rootAttrs')\n\nfunction createViewContainer(root: Node, ctx: Ctx) {\n const container = document.createElement('div')\n container.className = 'milkdown'\n root.appendChild(container)\n ctx.set(rootDOMCtx, container)\n\n const attrs = ctx.get(rootAttrsCtx)\n Object.entries(attrs).forEach(([key, value]) => container.setAttribute(key, value))\n\n return container\n}\n\nfunction prepareViewDom(dom: Element) {\n dom.classList.add('editor')\n dom.setAttribute('role', 'textbox')\n}\n\nconst key = new PluginKey('MILKDOWN_VIEW_CLEAR')\n\n/// The editor view plugin.\n/// This plugin will create an editor view.\n///\n/// This plugin will wait for the editor state plugin.\nexport const editorView: MilkdownPlugin = (ctx) => {\n ctx.inject(rootCtx, document.body)\n .inject(editorViewCtx, {} as EditorView)\n .inject(editorViewOptionsCtx, {})\n .inject(rootDOMCtx, null as unknown as HTMLElement)\n .inject(rootAttrsCtx, {})\n .inject(editorViewTimerCtx, [EditorStateReady])\n .record(EditorViewReady)\n\n return async () => {\n await ctx.wait(InitReady)\n\n const root = ctx.get(rootCtx) || document.body\n const el = typeof root === 'string' ? document.querySelector(root) : root\n\n ctx.update(prosePluginsCtx, xs => [\n new Plugin({\n key,\n view: (editorView) => {\n const container = el ? createViewContainer(el, ctx) : undefined\n\n const handleDOM = () => {\n if (container && el) {\n const editor = editorView.dom\n el.replaceChild(container, editor)\n container.appendChild(editor)\n }\n }\n handleDOM()\n return {\n destroy: () => {\n if (container?.parentNode)\n container?.parentNode.replaceChild(editorView.dom, container)\n\n container?.remove()\n },\n }\n },\n }),\n ...xs,\n ])\n\n await ctx.waitTimers(editorViewTimerCtx)\n\n const state = ctx.get(editorStateCtx)\n const options = ctx.get(editorViewOptionsCtx)\n const nodeViews = Object.fromEntries(ctx.get(nodeViewCtx))\n const markViews = Object.fromEntries(ctx.get(markViewCtx))\n const view = new EditorView(el as Node, {\n state,\n nodeViews,\n markViews,\n ...options,\n })\n prepareViewDom(view.dom)\n ctx.set(editorViewCtx, view)\n ctx.done(EditorViewReady)\n\n return () => {\n view?.destroy()\n ctx.remove(rootCtx)\n .remove(editorViewCtx)\n .remove(editorViewOptionsCtx)\n .remove(rootDOMCtx)\n .remove(rootAttrsCtx)\n .remove(editorViewTimerCtx)\n .clearTimer(EditorViewReady)\n }\n }\n}\n\nwithMeta(editorView, {\n displayName: 'EditorView',\n})\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { Ctx, MilkdownPlugin, SliceType } from '@milkdown/ctx'\nimport { Container, createSlice, createTimer } from '@milkdown/ctx'\nimport { callCommandBeforeEditorView } from '@milkdown/exception'\nimport type { Command } from '@milkdown/prose/state'\n\nimport { withMeta } from '../__internal__'\nimport { editorViewCtx } from './editor-view'\nimport { SchemaReady } from './schema'\n\n/// @internal\nexport type Cmd<T = undefined> = (payload?: T) => Command\n\n/// @internal\nexport type CmdKey<T = undefined> = SliceType<Cmd<T>>\n\ntype InferParams<T> = T extends CmdKey<infer U> ? U : never\n\n/// The command manager.\n/// This manager will manage all commands in editor.\n/// Generally, you don't need to use this manager directly.\n/// You can use the `$command` and `$commandAsync` in `@milkdown/utils` to create and call a command.\nexport class CommandManager {\n /// @internal\n #container = new Container()\n\n /// @internal\n #ctx: Ctx | null = null\n\n /// @internal\n setCtx = (ctx: Ctx) => {\n this.#ctx = ctx\n }\n\n get ctx() {\n return this.#ctx\n }\n\n /// Register a command into the manager.\n create<T>(meta: CmdKey<T>, value: Cmd<T>) {\n const slice = meta.create(this.#container.sliceMap)\n slice.set(value)\n return slice\n }\n\n /// Get a command from the manager.\n get<T extends CmdKey<any>>(slice: string): Cmd<InferParams<T>>\n get<T>(slice: CmdKey<T>): Cmd<T>\n get(slice: string | CmdKey<any>): Cmd<any>\n get(slice: string | CmdKey<any>): Cmd<any> {\n return this.#container.get(slice).get()\n }\n\n /// Remove a command from the manager.\n remove<T extends CmdKey<any>>(slice: string): void\n remove<T>(slice: CmdKey<T>): void\n remove(slice: string | CmdKey<any>): void\n remove(slice: string | CmdKey<any>): void {\n return this.#container.remove(slice)\n }\n\n /// Call a registered command.\n call<T extends CmdKey<any>>(slice: string, payload?: InferParams<T>): boolean\n call<T>(slice: CmdKey<T>, payload?: T): boolean\n call(slice: string | CmdKey<any>, payload?: any): boolean\n call(slice: string | CmdKey<any>, payload?: any): boolean {\n if (this.#ctx == null)\n throw callCommandBeforeEditorView()\n\n const cmd = this.get(slice)\n const command = cmd(payload)\n const view = this.#ctx.get(editorViewCtx)\n return command(view.state, view.dispatch, view)\n }\n}\n\n/// Create a command key, which is a slice type that contains a command.\nexport function createCmdKey<T = undefined>(key = 'cmdKey'): CmdKey<T> {\n return createSlice((() => () => false) as Cmd<T>, key)\n}\n\n/// A slice which contains the command manager.\nexport const commandsCtx = createSlice(new CommandManager(), 'commands')\n\n/// A slice which stores timers that need to be waited for before starting to run the plugin.\n/// By default, it's `[SchemaReady]`.\nexport const commandsTimerCtx = createSlice([SchemaReady], 'commandsTimer')\n\n/// The timer which will be resolved when the commands plugin is ready.\nexport const CommandsReady = createTimer('CommandsReady')\n\n/// The commands plugin.\n/// This plugin will create a command manager.\n///\n/// This plugin will wait for the schema plugin.\nexport const commands: MilkdownPlugin = (ctx) => {\n const cmd = new CommandManager()\n cmd.setCtx(ctx)\n ctx.inject(commandsCtx, cmd).inject(commandsTimerCtx, [SchemaReady]).record(CommandsReady)\n return async () => {\n await ctx.waitTimers(commandsTimerCtx)\n\n ctx.done(CommandsReady)\n\n return () => {\n ctx.remove(commandsCtx).remove(commandsTimerCtx).clearTimer(CommandsReady)\n }\n }\n}\n\nwithMeta(commands, {\n displayName: 'Commands',\n})\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { CtxRunner, MilkdownPlugin, Telemetry } from '@milkdown/ctx'\nimport { Clock, Container, Ctx } from '@milkdown/ctx'\n\nimport type { Config } from '../internal-plugin'\nimport {\n commands,\n config,\n editorState,\n editorView,\n init,\n parser,\n schema,\n serializer,\n} from '../internal-plugin'\n\n/// The status of the editor.\nexport enum EditorStatus {\n /// The editor is not initialized.\n Idle = 'Idle',\n /// The editor is creating.\n OnCreate = 'OnCreate',\n /// The editor has been created and ready to use.\n Created = 'Created',\n /// The editor is destroying.\n OnDestroy = 'OnDestroy',\n /// The editor has been destroyed.\n Destroyed = 'Destroyed',\n}\n\n/// Type for the callback called when editor status changed.\nexport type OnStatusChange = (status: EditorStatus) => void\n\ntype EditorPluginStore = Map<\n MilkdownPlugin,\n {\n ctx: Ctx | undefined\n handler: CtxRunner | undefined\n cleanup: ReturnType<CtxRunner>\n }\n>\n\n/// The milkdown editor class.\nexport class Editor {\n /// Create a new editor instance.\n static make() {\n return new Editor()\n }\n\n /// @internal\n #enableInspector = false\n /// @internal\n #status = EditorStatus.Idle\n /// @internal\n #configureList: Config[] = []\n /// @internal\n #onStatusChange: OnStatusChange = () => undefined\n\n /// @internal\n readonly #container = new Container()\n /// @internal\n readonly #clock = new Clock()\n\n /// @internal\n readonly #usrPluginStore: EditorPluginStore = new Map()\n\n /// @internal\n readonly #sysPluginStore: EditorPluginStore = new Map()\n\n /// @internal\n readonly #ctx = new Ctx(this.#container, this.#clock)\n\n /// @internal\n readonly #loadInternal = () => {\n const configPlugin = config(async (ctx) => {\n await Promise.all(this.#configureList.map(fn => fn(ctx)))\n })\n const internalPlugins = [\n schema,\n parser,\n serializer,\n commands,\n editorState,\n editorView,\n init(this),\n configPlugin,\n ]\n this.#prepare(internalPlugins, this.#sysPluginStore)\n }\n\n /// @internal\n readonly #prepare = (plugins: MilkdownPlugin[], store: EditorPluginStore) => {\n plugins.forEach((plugin) => {\n const ctx = this.#ctx.produce(this.#enableInspector ? plugin.meta : undefined)\n const handler = plugin(ctx)\n store.set(plugin, { ctx, handler, cleanup: undefined })\n })\n }\n\n /// @internal\n readonly #cleanup = (plugins: MilkdownPlugin[], remove = false) => {\n return Promise.all(\n [plugins].flat().map((plugin) => {\n const loader = this.#usrPluginStore.get(plugin)\n const cleanup = loader?.cleanup\n if (remove)\n this.#usrPluginStore.delete(plugin)\n else\n this.#usrPluginStore.set(plugin, { ctx: undefined, handler: undefined, cleanup: undefined })\n\n if (typeof cleanup === 'function')\n return cleanup()\n\n return cleanup\n }),\n )\n }\n\n /// @internal\n readonly #cleanupInternal = async () => {\n await Promise.all([...this.#sysPluginStore.entries()].map(([_, { cleanup }]) => {\n if (typeof cleanup === 'function')\n return cleanup()\n\n return cleanup\n }))\n this.#sysPluginStore.clear()\n }\n\n /// @internal\n readonly #setStatus = (status: EditorStatus) => {\n this.#status = status\n this.#onStatusChange(status)\n }\n\n /// @internal\n readonly #loadPluginInStore = (store: EditorPluginStore) => {\n return [...store.entries()].map(async ([key, loader]) => {\n const { ctx, handler } = loader\n if (!handler)\n return\n\n const cleanup = await handler()\n\n store.set(key, { ctx, handler, cleanup })\n })\n }\n\n /// Get the ctx of the editor.\n get ctx() {\n return this.#ctx\n }\n\n /// Get the status of the editor.\n get status() {\n return this.#status\n }\n\n /// Enable the inspector for the editor.\n /// You can also pass `false` to disable the inspector.\n readonly enableInspector = (enable = true) => {\n this.#enableInspector = enable\n\n return this\n }\n\n /// Subscribe to the status change event for the editor.\n /// The new subscription will replace the old one.\n readonly onStatusChange = (onChange: OnStatusChange) => {\n this.#onStatusChange = onChange\n return this\n }\n\n /// Add a config for the editor.\n readonly config = (configure: Config) => {\n this.#configureList.push(configure)\n return this\n }\n\n /// Remove a config for the editor.\n readonly removeConfig = (configure: Config) => {\n this.#configureList = this.#configureList.filter(x => x !== configure)\n return this\n }\n\n /// Use a plugin or a list of plugins for the editor.\n readonly use = (plugins: MilkdownPlugin | MilkdownPlugin[]) => {\n const _plugins = [plugins].flat()\n _plugins.flat().forEach((plugin) => {\n this.#usrPluginStore.set(plugin, {\n ctx: undefined,\n handler: undefined,\n cleanup: undefined,\n })\n })\n\n if (this.#status === EditorStatus.Created)\n this.#prepare(_plugins, this.#usrPluginStore)\n\n return this\n }\n\n /// Remove a plugin or a list of plugins from the editor.\n readonly remove = async (plugins: MilkdownPlugin | MilkdownPlugin[]): Promise<Editor> => {\n if (this.#status === EditorStatus.OnCreate) {\n console.warn('[Milkdown]: You are trying to remove plugins when the editor is creating, this is not recommended, please check your code.')\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(this.remove(plugins))\n }, 50)\n })\n }\n\n await this.#cleanup([plugins].flat(), true)\n return this\n }\n\n /// Create the editor with current config and plugins.\n /// If the editor is already created, it will be recreated.\n readonly create = async (): Promise<Editor> => {\n if (this.#status === EditorStatus.OnCreate)\n return this\n\n if (this.#status === EditorStatus.Created)\n await this.destroy()\n\n this.#setStatus(EditorStatus.OnCreate)\n\n this.#loadInternal()\n this.#prepare([...this.#usrPluginStore.keys()], this.#usrPluginStore)\n\n await Promise.all(\n [\n this.#loadPluginInStore(this.#sysPluginStore),\n this.#loadPluginInStore(this.#usrPluginStore),\n ].flat(),\n )\n\n this.#setStatus(EditorStatus.Created)\n return this\n }\n\n /// Destroy the editor.\n /// If you want to clear all plugins, set `clearPlugins` to `true`.\n readonly destroy = async (clearPlugins = false): Promise<Editor> => {\n if (this.#status === EditorStatus.Destroyed || this.#status === EditorStatus.OnDestroy)\n return this\n\n if (this.#status === EditorStatus.OnCreate) {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(this.destroy(clearPlugins))\n }, 50)\n })\n }\n\n if (clearPlugins)\n this.#configureList = []\n\n this.#setStatus(EditorStatus.OnDestroy)\n await this.#cleanup([...this.#usrPluginStore.keys()], clearPlugins)\n await this.#cleanupInternal()\n\n this.#setStatus(EditorStatus.Destroyed)\n return this\n }\n\n /// Call an action with the ctx of the editor.\n /// This method should be used after the editor is created.\n readonly action = <T>(action: (ctx: Ctx) => T) => action(this.#ctx)\n\n /// Get inspections of plugins in editor.\n /// Make sure you have enabled inspector by `editor.enableInspector()` before calling this method.\n readonly inspect = (): Telemetry[] => {\n if (!this.#enableInspector) {\n console.warn('[Milkdown]: You are trying to collect inspection when inspector is disabled, please enable inspector by `editor.enableInspector()` first.')\n return []\n }\n return [...this.#sysPluginStore.values(), ...this.#usrPluginStore.values()]\n .map(({ ctx }) => ctx?.inspector?.read())\n .filter((x): x is Telemetry => Boolean(x))\n }\n}\n"],"names":["withMeta","plugin","meta","remarkHandlers","node","_","state","info","marker","exit","tracker","value","ConfigReady","createTimer","config","configure","ctx","InitReady","initTimerCtx","createSlice","editorCtx","inputRulesCtx","prosePluginsCtx","remarkPluginsCtx","nodeViewCtx","markViewCtx","remarkCtx","unified","remarkParse","remarkStringify","remarkStringifyOptionsCtx","init","editor","options","SchemaReady","schemaTimerCtx","schemaCtx","nodesCtx","marksCtx","extendPriority","x","_a","rule","schema","remark","processor","acc","plug","nodes","key","marks","Schema","ParserReady","outOfScope","ctxCallOutOfScope","parserCtx","parserTimerCtx","parser","ParserState","SerializerReady","serializerTimerCtx","serializerCtx","serializer","SerializerState","defaultValueCtx","editorStateCtx","editorStateOptionsCtx","editorStateTimerCtx","EditorStateReady","getDoc","defaultValue","DOMParser","Node","docTypeError","PluginKey","overrideBaseKeymap","keymap","handleBackspace","chainCommands","undoInputRule","deleteSelection","joinBackward","selectNodeBackward","editorState","CommandsReady","rules","optionsOverride","prosePlugins","doc","plugins","Plugin","_tr","_value","_oldState","newState","createInputRules","createKeymap","baseKeymap","EditorState","EditorViewReady","editorViewCtx","editorViewTimerCtx","editorViewOptionsCtx","rootCtx","rootDOMCtx","rootAttrsCtx","createViewContainer","root","container","attrs","prepareViewDom","dom","editorView","el","xs","nodeViews","markViews","view","EditorView","CommandManager","__privateAdd","_container","_ctx","__privateSet","Container","__privateGet","slice","payload","callCommandBeforeEditorView","command","createCmdKey","commandsCtx","commandsTimerCtx","commands","cmd","EditorStatus","_Editor","_enableInspector","_status","_configureList","_onStatusChange","_clock","_usrPluginStore","_sysPluginStore","_loadInternal","_prepare","_cleanup","_cleanupInternal","_setStatus","_loadPluginInStore","Clock","Ctx","configPlugin","fn","internalPlugins","store","handler","remove","loader","cleanup","status","enable","onChange","_plugins","resolve","clearPlugins","action","Editor"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAGgB,SAAAA,EAAmCC,GAAWC,GAAoD;AAChH,SAAAD,EAAO,OAAO;AAAA,IACZ,SAAS;AAAA,IACT,OAAO;AAAA,IACP,GAAGC;AAAA,EAAA,GAGED;AACT;ACRO,MAAME,KAAgD;AAAA,EAC3D,QAAQ,CAACC,GAAMC,GAAGC,GAAOC,MAAS;AAChC,UAAMC,IAASJ,EAAK,UAAUE,EAAM,QAAQ,UAAU,KAChDG,IAAOH,EAAM,MAAM,QAAQ,GAC3BI,IAAUJ,EAAM,cAAcC,CAAI;AACxC,QAAII,IAAQD,EAAQ,KAAKF,IAASA,CAAM;AACxC,WAAAG,KAASD,EAAQ;AAAA,MACfJ,EAAM,kBAAkBF,GAAM;AAAA,QAC5B,QAAQO;AAAA,QACR,OAAOH;AAAA,QACP,GAAGE,EAAQ,QAAQ;AAAA,MAAA,CACpB;AAAA,IAAA,GAEMC,KAAAD,EAAQ,KAAKF,IAASA,CAAM,GAChCC,KACEE;AAAA,EACT;AAAA,EACA,UAAU,CAACP,GAAMC,GAAGC,GAAOC,MAAS;AAClC,UAAMC,IAASJ,EAAK,UAAUE,EAAM,QAAQ,YAAY,KAClDG,IAAOH,EAAM,MAAM,UAAU,GAC7BI,IAAUJ,EAAM,cAAcC,CAAI;AACpC,QAAAI,IAAQD,EAAQ,KAAKF,CAAM;AAC/B,WAAAG,KAASD,EAAQ;AAAA,MACfJ,EAAM,kBAAkBF,GAAM;AAAA,QAC5B,QAAQO;AAAA,QACR,OAAOH;AAAA,QACP,GAAGE,EAA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