@milkdown/core
Advanced tools
Comparing version
# @milkdown/core | ||
## 4.6.0 | ||
### Minor Changes | ||
- e1fbf79: Refactor the plugin system to functional plugin for better extension ability. | ||
## 4.5.3 | ||
@@ -4,0 +10,0 @@ |
@@ -1,34 +0,3 @@ | ||
import type { InputRule } from 'prosemirror-inputrules'; | ||
import type { Node as ProsemirrorNode, Schema } from 'prosemirror-model'; | ||
import type { Plugin as ProsemirrorPlugin } from 'prosemirror-state'; | ||
import type { EditorView, NodeView } from 'prosemirror-view'; | ||
import type { RemarkOptions } from 'remark'; | ||
import type { Processor } from 'unified'; | ||
import type { Mark, Node } from '../abstract'; | ||
import type { LoadState } from '../constant'; | ||
import type { Editor } from '../editor'; | ||
import type { AnyRecord, MarkViewParams, NodeViewParams } from '../utility'; | ||
export declare type GetCurrentContextByState<T extends LoadState> = T extends LoadState.Idle ? IdleContext : T extends LoadState.LoadSchema ? IdleContext : T extends LoadState.SchemaReady ? SchemaReadyContext : T extends LoadState.LoadPlugin ? LoadPluginContext : T extends LoadState.Complete ? CompleteContext : AnyRecord; | ||
export declare type GetNextContextByState<T extends LoadState> = T extends LoadState.Idle ? IdleContext : T extends LoadState.LoadSchema ? SchemaReadyContext : T extends LoadState.SchemaReady ? LoadPluginContext : T extends LoadState.LoadPlugin ? CompleteContext : T extends LoadState.Complete ? CompleteContext : AnyRecord; | ||
export interface IdleContext { | ||
remark: Processor<RemarkOptions>; | ||
loadState: LoadState; | ||
nodes: Node[]; | ||
marks: Mark[]; | ||
editor: Editor; | ||
} | ||
export interface SchemaReadyContext extends Readonly<IdleContext> { | ||
schema: Schema; | ||
parser: (text: string) => ProsemirrorNode | null; | ||
serializer: (node: ProsemirrorNode) => string; | ||
keymap: ProsemirrorPlugin[]; | ||
inputRules: InputRule[]; | ||
nodeViews: Record<string, (...args: NodeViewParams | MarkViewParams) => NodeView>; | ||
} | ||
export interface LoadPluginContext extends Readonly<SchemaReadyContext> { | ||
prosemirrorPlugins: ProsemirrorPlugin[]; | ||
} | ||
export interface CompleteContext extends Readonly<LoadPluginContext> { | ||
editorView: EditorView; | ||
} | ||
export * from './container'; | ||
export * from './ctx'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,9 @@ | ||
export {}; | ||
// import type { Plugin as ProsemirrorPlugin } from 'prosemirror-state'; | ||
// import type { NodeView } from 'prosemirror-view'; | ||
// import type { Editor } from '../editor'; | ||
// import type { MarkViewParams, NodeViewParams } from '../utility'; | ||
// import { createCtx } from './container'; | ||
// export const prosePluginsCtx = createCtx<ProsemirrorPlugin[]>([]); | ||
export * from './container'; | ||
export * from './ctx'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,11 +0,11 @@ | ||
import type { EditorView } from 'prosemirror-view'; | ||
import type { Atom } from '../abstract'; | ||
import { ViewLoaderOptions } from '../loader'; | ||
import { Meta } from '../context'; | ||
import { Configure, Ctx, MilkdownPlugin, Pre } from '../utility'; | ||
export declare class Editor { | ||
#private; | ||
constructor(options: Partial<ViewLoaderOptions>); | ||
use(atom: Atom | Atom[]): this; | ||
create(): void; | ||
get view(): EditorView; | ||
inject: <T>(meta: Meta<T>, resetValue?: T | undefined) => Pre; | ||
use: (plugins: MilkdownPlugin | MilkdownPlugin[]) => this; | ||
config: (configure: Configure) => this; | ||
create: () => Promise<this>; | ||
action: <T>(action: (ctx: Ctx) => T) => T; | ||
} | ||
//# sourceMappingURL=editor.d.ts.map |
@@ -1,70 +0,48 @@ | ||
var _Editor_instances, _Editor_atoms, _Editor_ctx, _Editor_updateCtx, _Editor_injectCtx, _Editor_runAtomByLoadState, _Editor_addAtom; | ||
import { __classPrivateFieldGet } from "tslib"; | ||
import remark from 'remark'; | ||
import { LoadState } from '../constant'; | ||
import { InputRulesLoader, KeymapLoader, NodeViewsLoader, ParserLoader, SchemaLoader, SerializerLoader, ViewLoader, } from '../loader'; | ||
var _Editor_container, _Editor_ctx, _Editor_plugins, _Editor_configure, _Editor_pre, _Editor_loadInternal; | ||
import { __awaiter, __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { createContainer } from '../context'; | ||
import { parser, schema, serializer, editorView, init, keymap, inputRules, config, nodeView } from '../internal-plugin'; | ||
const internalPlugins = [schema, parser, serializer, nodeView, keymap, inputRules, editorView]; | ||
export class Editor { | ||
constructor(options) { | ||
_Editor_instances.add(this); | ||
_Editor_atoms.set(this, []); | ||
constructor() { | ||
_Editor_container.set(this, createContainer()); | ||
_Editor_ctx.set(this, { | ||
loadState: LoadState.Idle, | ||
remark: remark(), | ||
nodes: [], | ||
marks: [], | ||
editor: this, | ||
prosemirrorPlugins: [], | ||
use: __classPrivateFieldGet(this, _Editor_container, "f").getCtx, | ||
get: (meta) => __classPrivateFieldGet(this, _Editor_container, "f").getCtx(meta).get(), | ||
set: (meta, value) => __classPrivateFieldGet(this, _Editor_container, "f").getCtx(meta).set(value), | ||
update: (meta, updater) => __classPrivateFieldGet(this, _Editor_container, "f").getCtx(meta).update(updater), | ||
}); | ||
_Editor_updateCtx.set(this, (value) => { | ||
Object.assign(__classPrivateFieldGet(this, _Editor_ctx, "f"), value); | ||
_Editor_plugins.set(this, new Set()); | ||
_Editor_configure.set(this, () => undefined); | ||
this.inject = (meta, resetValue) => { | ||
meta(__classPrivateFieldGet(this, _Editor_container, "f").contextMap, resetValue); | ||
return __classPrivateFieldGet(this, _Editor_pre, "f"); | ||
}; | ||
_Editor_pre.set(this, { | ||
inject: this.inject, | ||
}); | ||
const viewOptions = Object.assign({ root: document.body, defaultValue: '', listener: {} }, options); | ||
this.use([ | ||
new SchemaLoader(), | ||
new ParserLoader(), | ||
new SerializerLoader(), | ||
new KeymapLoader(), | ||
new InputRulesLoader(), | ||
new NodeViewsLoader(), | ||
new ViewLoader(viewOptions), | ||
]); | ||
} | ||
use(atom) { | ||
if (Array.isArray(atom)) { | ||
atom.forEach((a) => { | ||
__classPrivateFieldGet(this, _Editor_instances, "m", _Editor_addAtom).call(this, a); | ||
_Editor_loadInternal.set(this, () => { | ||
this.use(internalPlugins.concat(init(this)).concat(config(__classPrivateFieldGet(this, _Editor_configure, "f")))); | ||
}); | ||
this.use = (plugins) => { | ||
[plugins].flat().forEach((plugin) => { | ||
__classPrivateFieldGet(this, _Editor_plugins, "f").add(plugin(__classPrivateFieldGet(this, _Editor_pre, "f"))); | ||
}); | ||
return this; | ||
} | ||
__classPrivateFieldGet(this, _Editor_instances, "m", _Editor_addAtom).call(this, atom); | ||
return this; | ||
} | ||
create() { | ||
__classPrivateFieldGet(this, _Editor_instances, "m", _Editor_injectCtx).call(this); | ||
[LoadState.Idle, LoadState.LoadSchema, LoadState.SchemaReady, LoadState.LoadPlugin, LoadState.Complete].forEach((state) => { | ||
__classPrivateFieldGet(this, _Editor_ctx, "f").loadState = state; | ||
__classPrivateFieldGet(this, _Editor_instances, "m", _Editor_runAtomByLoadState).call(this, state); | ||
}; | ||
this.config = (configure) => { | ||
__classPrivateFieldSet(this, _Editor_configure, configure, "f"); | ||
return this; | ||
}; | ||
this.create = () => __awaiter(this, void 0, void 0, function* () { | ||
__classPrivateFieldGet(this, _Editor_loadInternal, "f").call(this); | ||
yield Promise.all([...__classPrivateFieldGet(this, _Editor_plugins, "f")].map((loader) => { | ||
return loader(__classPrivateFieldGet(this, _Editor_ctx, "f")); | ||
})); | ||
return this; | ||
}); | ||
this.action = (action) => action(__classPrivateFieldGet(this, _Editor_ctx, "f")); | ||
} | ||
get view() { | ||
const ctx = __classPrivateFieldGet(this, _Editor_ctx, "f"); | ||
return ctx.editorView; | ||
} | ||
} | ||
_Editor_atoms = new WeakMap(), _Editor_ctx = new WeakMap(), _Editor_updateCtx = new WeakMap(), _Editor_instances = new WeakSet(), _Editor_injectCtx = function _Editor_injectCtx() { | ||
__classPrivateFieldGet(this, _Editor_atoms, "f").forEach((atom) => atom.injectContext(__classPrivateFieldGet(this, _Editor_ctx, "f"), __classPrivateFieldGet(this, _Editor_updateCtx, "f"))); | ||
}, _Editor_runAtomByLoadState = function _Editor_runAtomByLoadState(loadState) { | ||
__classPrivateFieldGet(this, _Editor_atoms, "f") | ||
.filter((atom) => atom.loadAfter === loadState) | ||
.forEach((atom) => { | ||
atom.main(); | ||
}); | ||
}, _Editor_addAtom = function _Editor_addAtom(atom) { | ||
const i = __classPrivateFieldGet(this, _Editor_atoms, "f").findIndex((a) => a.id === atom.id); | ||
if (i >= 0) { | ||
console.warn(`Atom: ${atom.id} is conflicted with previous atom, the previous one will be override.`); | ||
__classPrivateFieldGet(this, _Editor_atoms, "f").splice(i, 1); | ||
} | ||
__classPrivateFieldGet(this, _Editor_atoms, "f").push(atom); | ||
}; | ||
_Editor_container = new WeakMap(), _Editor_ctx = new WeakMap(), _Editor_plugins = new WeakMap(), _Editor_configure = new WeakMap(), _Editor_pre = new WeakMap(), _Editor_loadInternal = new WeakMap(); | ||
//# sourceMappingURL=editor.js.map |
export * from './editor'; | ||
export * from './abstract'; | ||
export * from './loader'; | ||
export * from './parser'; | ||
export * from './serializer'; | ||
export * from './constant'; | ||
export * from './utility'; | ||
export * from './context'; | ||
export * from './internal-plugin'; | ||
//# sourceMappingURL=index.d.ts.map |
export * from './editor'; | ||
export * from './abstract'; | ||
export * from './loader'; | ||
export * from './parser'; | ||
export * from './serializer'; | ||
export * from './constant'; | ||
export * from './utility'; | ||
export * from './context'; | ||
export * from './internal-plugin'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,7 +0,6 @@ | ||
import type { Processor } from 'unified'; | ||
import type { RemarkOptions } from 'remark'; | ||
import type { RemarkParser } from '../internal-plugin'; | ||
import type { Schema } from 'prosemirror-model'; | ||
import type { InnerParserSpecMap } from './types'; | ||
export declare function createParser(schema: Schema, specMap: InnerParserSpecMap, remark: Processor<RemarkOptions>): (text: string) => import("prosemirror-model").Node<any>; | ||
export declare function createParser(schema: Schema, specMap: InnerParserSpecMap, remark: RemarkParser): (text: string) => import("prosemirror-model").Node<any>; | ||
export * from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
import type { MarkType, NodeType, Schema } from 'prosemirror-model'; | ||
import type { Processor } from 'unified'; | ||
import type { RemarkOptions } from 'remark'; | ||
import type { Node as MarkdownNode } from 'unist'; | ||
import type { Attrs, InnerParserSpecMap } from '.'; | ||
import type { Stack } from './stack'; | ||
import type { RemarkParser } from '../internal-plugin'; | ||
export declare class State { | ||
@@ -13,3 +12,3 @@ #private; | ||
constructor(stack: Stack, schema: Schema, specMap: InnerParserSpecMap); | ||
run: (remark: Processor<RemarkOptions>, markdown: string) => this; | ||
run: (remark: RemarkParser, markdown: string) => this; | ||
injectRoot: (node: MarkdownNode, nodeType: NodeType, attrs?: Attrs | undefined) => this; | ||
@@ -16,0 +15,0 @@ addText: (text?: string) => this; |
@@ -1,4 +0,3 @@ | ||
import type { Processor } from 'unified'; | ||
import type { RemarkOptions } from 'remark'; | ||
import type { Node as ProseNode, Fragment, Schema } from 'prosemirror-model'; | ||
import { RemarkParser } from '../internal-plugin'; | ||
import type { Stack } from './stack'; | ||
@@ -18,3 +17,3 @@ import type { InnerSerializerSpecMap } from './types'; | ||
closeNode: StateMethod<'closeNode'>; | ||
toString: (remark: Processor<RemarkOptions>) => string; | ||
toString: (remark: RemarkParser) => string; | ||
withMark: StateMethod<'openMark'>; | ||
@@ -21,0 +20,0 @@ } |
import type { Editor } from '../editor'; | ||
import type { EditorState, Transaction } from 'prosemirror-state'; | ||
import type { Decoration, EditorView, NodeView } from 'prosemirror-view'; | ||
import { Node, Mark, Schema, MarkType, NodeType } from 'prosemirror-model'; | ||
import type { Node, Schema, MarkType, NodeType } from 'prosemirror-model'; | ||
import { Mark } from 'prosemirror-model'; | ||
export declare const hasText: (node: Node) => node is Node<any> & { | ||
@@ -6,0 +7,0 @@ text: string; |
@@ -0,2 +1,17 @@ | ||
import type { Context, Meta } from '../context'; | ||
export declare type AnyRecord = Record<string, any>; | ||
export declare type Ctx = { | ||
use: <T>(meta: Meta<T>) => Context<T>; | ||
get: <T>(meta: Meta<T>) => T; | ||
set: <T>(meta: Meta<T>, value: T) => void; | ||
update: <T>(meta: Meta<T>, updater: (prev: T) => T) => void; | ||
}; | ||
export declare type Pre = { | ||
inject: <T>(meta: Meta<T>, resetValue?: T) => Pre; | ||
}; | ||
export declare type CtxHandler = (ctx: Ctx) => void | Promise<void>; | ||
export declare type MilkdownPlugin = { | ||
(pre: Pre): CtxHandler; | ||
}; | ||
export declare type Configure = CtxHandler; | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "@milkdown/core", | ||
"version": "4.5.3", | ||
"version": "4.6.0", | ||
"main": "lib/index.js", | ||
@@ -8,3 +8,2 @@ "module": "lib/index.js", | ||
"scripts": { | ||
"start": "vite", | ||
"watch": "tsc -w", | ||
@@ -19,2 +18,3 @@ "test": "jest", | ||
"dependencies": { | ||
"@types/lodash-es": "^4.17.4", | ||
"@types/prosemirror-commands": "^1.0.4", | ||
@@ -26,2 +26,3 @@ "@types/prosemirror-inputrules": "^1.0.4", | ||
"@types/prosemirror-view": "^1.17.1", | ||
"lodash-es": "^4.17.21", | ||
"prosemirror-commands": "^1.1.7", | ||
@@ -28,0 +29,0 @@ "prosemirror-inputrules": "^1.1.3", |
@@ -5,14 +5,8 @@ # @milkdown/core | ||
# Example Usage | ||
# Official Documentation | ||
```typescript | ||
import { Editor } from '@milkdown/core'; | ||
import { commonmark } from '@milkdown/preset-commonmark'; | ||
Documentation can be found on the [Milkdown website](https://saul-mirone.github.io/milkdown/). | ||
// import theme and style | ||
import '@milkdown/theme-nord/lib/theme.css'; | ||
import '@milkdown/preset-commonmark/lib/style.css'; | ||
# License | ||
const root = document.body; | ||
new Editor({ root }).use(commonmark).create(); | ||
``` | ||
Milkdown is open sourced software licensed under [MIT license](https://github.com/Saul-Mirone/milkdown/blob/main/LICENSE). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
111360
11.95%152
8.57%1202
8.19%17
13.33%12
-33.33%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added