Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@milkdown/core

Package Overview
Dependencies
Maintainers
1
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@milkdown/core - npm Package Compare versions

Comparing version 4.6.2 to 4.6.3

lib/internal-plugin/editor-state.d.ts

6

CHANGELOG.md
# @milkdown/core
## 4.6.3
### Patch Changes
- 8f0ce59: Extract listener plugin.
## 4.6.2

@@ -4,0 +10,0 @@

4

lib/editor/editor.js
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';
import { parser, schema, serializer, editorView, init, keymap, inputRules, config, nodeView, editorState, } from '../internal-plugin';
export class Editor {

@@ -24,3 +24,3 @@ constructor() {

_Editor_loadInternal.set(this, () => {
const internalPlugins = [schema, parser, serializer, nodeView, keymap, inputRules, editorView];
const internalPlugins = [schema, parser, serializer, nodeView, keymap, inputRules, editorState, editorView];
this.use(internalPlugins.concat(init(this)).concat(config(__classPrivateFieldGet(this, _Editor_configure, "f"))));

@@ -27,0 +27,0 @@ });

@@ -1,26 +0,7 @@

import { Node } from 'prosemirror-model';
import { EditorState } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view';
import { AnyRecord, MilkdownPlugin } from '../utility';
export declare type DocListener = (doc: Node) => void;
export declare type MarkdownListener = (getMarkdown: () => string) => void;
export declare type Listener = {
doc?: DocListener[];
markdown?: MarkdownListener[];
};
declare type DefaultValue = string | {
type: 'html';
dom: HTMLElement;
} | {
type: 'json';
value: AnyRecord;
};
declare type EditorOptions = {
root: Element;
defaultValue: DefaultValue;
listener: Listener;
editable?: (editorState: EditorState) => boolean;
};
import { MilkdownPlugin } from '../utility';
declare type EditorOptions = Omit<ConstructorParameters<typeof EditorView>[1], 'state'>;
export declare const editorViewCtx: import("..").Meta<EditorView<any>>;
export declare const editorViewOptionsCtx: import("..").Meta<EditorOptions>;
export declare const rootCtx: import("..").Meta<Node>;
export declare const Complete: {

@@ -27,0 +8,0 @@ (): Promise<unknown>;

import { __awaiter } from "tslib";
import { baseKeymap } from 'prosemirror-commands';
import { inputRules as createInputRules } from 'prosemirror-inputrules';
import { keymap as createKeymap } from 'prosemirror-keymap';
import { Node, DOMParser } from 'prosemirror-model';
import { EditorState } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view';
import { Render, createCtx, inputRulesCtx } from '..';
import { createCtx } from '..';
import { createTiming } from '../timing';
import { keymapCtx } from './keymap';
import { nodeViewCtx } from './node-view';
import { parserCtx } from './parser';
import { prosePluginsCtx } from './prose-plugin-factory';
import { schemaCtx } from './schema';
import { serializerCtx } from './serializer';
import { editorStateCtx, StateReady } from './editor-state';
import { nodeViewCtx, NodeViewReady } from './node-view';
export const editorViewCtx = createCtx({});
export const editorViewOptionsCtx = createCtx({
root: document.body,
defaultValue: '',
listener: {},
});
export const editorViewOptionsCtx = createCtx({});
export const rootCtx = createCtx(document.body);
export const Complete = createTiming('complete');

@@ -33,48 +21,12 @@ const createViewContainer = (root) => {

};
const getDoc = (defaultValue, parser, schema) => {
if (typeof defaultValue === 'string') {
return parser(defaultValue);
}
if (defaultValue.type === 'html') {
return DOMParser.fromSchema(schema).parse(defaultValue.dom);
}
if (defaultValue.type === 'json') {
return Node.fromJSON(schema, defaultValue.value);
}
throw new Error();
};
export const editorView = (pre) => {
pre.inject(editorViewCtx).inject(editorViewOptionsCtx);
pre.inject(rootCtx).inject(editorViewCtx).inject(editorViewOptionsCtx);
return (ctx) => __awaiter(void 0, void 0, void 0, function* () {
yield Render();
const schema = ctx.get(schemaCtx);
const parser = ctx.get(parserCtx);
const serializer = ctx.get(serializerCtx);
const rules = ctx.get(inputRulesCtx);
const keymap = ctx.get(keymapCtx);
yield Promise.all([StateReady(), NodeViewReady()]);
const state = ctx.get(editorStateCtx);
const options = ctx.get(editorViewOptionsCtx);
const nodeView = ctx.get(nodeViewCtx);
const prosePlugins = ctx.get(prosePluginsCtx);
const state = EditorState.create({
schema,
doc: getDoc(options.defaultValue, parser, schema),
plugins: [...keymap, ...prosePlugins, createKeymap(baseKeymap), createInputRules({ rules })],
});
const container = createViewContainer(options.root);
const view = new EditorView(container, {
state,
nodeViews: nodeView,
editable: options.editable,
dispatchTransaction: (tr) => {
var _a, _b;
const nextState = view.state.apply(tr);
view.updateState(nextState);
(_a = options.listener.markdown) === null || _a === void 0 ? void 0 : _a.forEach((markdownListener) => {
markdownListener(() => serializer(view.state.doc));
});
(_b = options.listener.doc) === null || _b === void 0 ? void 0 : _b.forEach((docListener) => {
docListener(view.state.doc);
});
},
});
const root = ctx.get(rootCtx);
const container = createViewContainer(root);
const view = new EditorView(container, Object.assign({ state, nodeViews: nodeView }, options));
prepareViewDom(view.dom);

@@ -81,0 +33,0 @@ ctx.set(editorViewCtx, view);

@@ -6,6 +6,7 @@ export * from './init';

export * from './serializer';
export * from './editor-view';
export * from './keymap';
export * from './input-rules';
export * from './node-view';
export * from './editor-state';
export * from './editor-view';
export * from './mark-factory';

@@ -12,0 +13,0 @@ export * from './node-factory';

@@ -6,6 +6,7 @@ export * from './init';

export * from './serializer';
export * from './editor-view';
export * from './keymap';
export * from './input-rules';
export * from './node-view';
export * from './editor-state';
export * from './editor-view';
export * from './mark-factory';

@@ -12,0 +13,0 @@ export * from './node-factory';

@@ -7,8 +7,4 @@ import type { MilkdownPlugin } from '../utility';

};
export declare const Render: {
(): Promise<unknown>;
done(): void;
};
export declare const editorCtx: import("..").Meta<Editor>;
export declare const init: (editor: Editor) => MilkdownPlugin;
//# sourceMappingURL=init.d.ts.map

@@ -10,3 +10,2 @@ import { __awaiter } from "tslib";

export const Initialize = createTiming('Initialize');
export const Render = createTiming('Render');
export const editorCtx = createCtx({});

@@ -19,3 +18,2 @@ export const init = (editor) => (pre) => {

yield SchemaReady();
Render.done();
yield Complete();

@@ -22,0 +20,0 @@ });

import type { InputRule } from 'prosemirror-inputrules';
import type { MilkdownPlugin } from '../utility';
export declare const inputRulesCtx: import("../context").Meta<InputRule<any>[]>;
export declare const InputRulesReady: {
(): Promise<unknown>;
done(): void;
};
export declare const inputRules: MilkdownPlugin;
//# sourceMappingURL=input-rules.d.ts.map
import { __awaiter } from "tslib";
import { createCtx } from '../context';
import { marksCtx, nodesCtx, schemaCtx, SchemaReady } from '../internal-plugin';
import { createTiming } from '../timing';
export const inputRulesCtx = createCtx([]);
export const InputRulesReady = createTiming('InputRulesReady');
export const inputRules = (pre) => {

@@ -9,5 +11,5 @@ pre.inject(inputRulesCtx);

yield SchemaReady();
const nodes = ctx.use(nodesCtx).get();
const marks = ctx.use(marksCtx).get();
const schema = ctx.use(schemaCtx).get();
const nodes = ctx.get(nodesCtx);
const marks = ctx.get(marksCtx);
const schema = ctx.get(schemaCtx);
const nodesInputRules = nodes.reduce((acc, cur) => {

@@ -26,5 +28,6 @@ const node = schema.nodes[cur.id];

const inputRules = [...nodesInputRules, ...marksInputRules];
ctx.use(inputRulesCtx).set(inputRules);
ctx.set(inputRulesCtx, inputRules);
InputRulesReady.done();
});
};
//# sourceMappingURL=input-rules.js.map
import type { Plugin as ProsemirrorPlugin } from 'prosemirror-state';
import type { MilkdownPlugin } from '../utility';
export declare const keymapCtx: import("../context").Meta<ProsemirrorPlugin<any, any>[]>;
export declare const KeymapReady: {
(): Promise<unknown>;
done(): void;
};
export declare const keymap: MilkdownPlugin;
//# sourceMappingURL=keymap.d.ts.map

@@ -5,3 +5,5 @@ import { __awaiter } from "tslib";

import { marksCtx, nodesCtx, schemaCtx, SchemaReady } from '../internal-plugin';
import { createTiming } from '../timing';
export const keymapCtx = createCtx([]);
export const KeymapReady = createTiming('KeymapReady');
export const keymap = (pre) => {

@@ -11,5 +13,5 @@ pre.inject(keymapCtx);

yield SchemaReady();
const nodes = ctx.use(nodesCtx).get();
const marks = ctx.use(marksCtx).get();
const schema = ctx.use(schemaCtx).get();
const nodes = ctx.get(nodesCtx);
const marks = ctx.get(marksCtx);
const schema = ctx.get(schemaCtx);
const nodesKeymap = nodes.map((cur) => {

@@ -32,5 +34,6 @@ var _a;

.map((keys) => proseKeymap(keys));
ctx.use(keymapCtx).set(keymapList);
ctx.set(keymapCtx, keymapList);
KeymapReady.done();
});
};
//# sourceMappingURL=keymap.js.map

@@ -5,3 +5,7 @@ import type { NodeView } from 'prosemirror-view';

export declare const nodeViewCtx: import("..").Meta<Record<string, (...args: NodeViewParams | MarkViewParams) => NodeView>>;
export declare const NodeViewReady: {
(): Promise<unknown>;
done(): void;
};
export declare const nodeView: MilkdownPlugin;
//# sourceMappingURL=node-view.d.ts.map
import { __awaiter } from "tslib";
import { createCtx } from '..';
import { createTiming } from '../timing';
import { editorCtx } from './init';
import { marksCtx, nodesCtx, schemaCtx, SchemaReady } from './schema';
export const nodeViewCtx = createCtx({});
export const NodeViewReady = createTiming('NodeViewReady');
export const nodeView = (pre) => {

@@ -34,4 +36,5 @@ pre.inject(nodeViewCtx);

ctx.set(nodeViewCtx, nodeView);
NodeViewReady.done();
});
};
//# sourceMappingURL=node-view.js.map

@@ -9,3 +9,7 @@ import type { Node as ProsemirrorNode } from 'prosemirror-model';

export declare const remarkCtx: Meta<RemarkParser>;
export declare const ParserReady: {
(): Promise<unknown>;
done(): void;
};
export declare const parser: MilkdownPlugin;
//# sourceMappingURL=parser.d.ts.map

@@ -5,2 +5,3 @@ import { __awaiter } from "tslib";

import { createParser } from '../parser';
import { createTiming } from '../timing';
import { buildObject } from '../utility';

@@ -11,2 +12,3 @@ import { remarkPluginsCtx } from './remark-plugin-factory';

export const remarkCtx = createCtx(re());
export const ParserReady = createTiming('ParserReady');
export const parser = (pre) => {

@@ -16,10 +18,8 @@ pre.inject(parserCtx).inject(remarkCtx, re());

yield SchemaReady();
const nodes = ctx.use(nodesCtx).get();
const marks = ctx.use(marksCtx).get();
const remark = ctx.use(remarkCtx).get();
const schema = ctx.use(schemaCtx).get();
const nodes = ctx.get(nodesCtx);
const marks = ctx.get(marksCtx);
const remark = ctx.get(remarkCtx);
const schema = ctx.get(schemaCtx);
const remarkPlugins = ctx.get(remarkPluginsCtx);
const re = remarkPlugins.reduce((acc, plug) => {
return acc.use(plug);
}, remark);
const processor = remarkPlugins.reduce((acc, plug) => acc.use(plug), remark);
const children = [

@@ -31,7 +31,8 @@ ...nodes.map((node) => (Object.assign(Object.assign({}, node), { is: 'node' }))),

child.id,
Object.assign(Object.assign({}, child.parser), { is: child.is }),
Object.assign(Object.assign({}, child.parser), { is: child.is, key: child.id }),
]);
ctx.use(parserCtx).set(createParser(schema, spec, re));
ctx.set(parserCtx, createParser(schema, spec, processor));
ParserReady.done();
});
};
//# sourceMappingURL=parser.js.map
import { createCtx } from '..';
export const prosePluginsCtx = createCtx([]);
export const prosePluginFactory = (plugin) => () => {
return (ctx) => {
const plugins = [plugin].flat();
ctx.update(prosePluginsCtx, (prev) => prev.concat(plugins));
};
export const prosePluginFactory = (plugin) => () => (ctx) => {
const plugins = [plugin].flat();
ctx.update(prosePluginsCtx, (prev) => prev.concat(plugins));
};
//# sourceMappingURL=prose-plugin-factory.js.map
import { createCtx } from '..';
export const remarkPluginsCtx = createCtx([]);
export const remarkPluginFactory = (plugin) => () => {
return (ctx) => {
const plugins = [plugin].flat();
ctx.update(remarkPluginsCtx, (prev) => prev.concat(plugins));
};
export const remarkPluginFactory = (plugin) => () => (ctx) => {
const plugins = [plugin].flat();
ctx.update(remarkPluginsCtx, (prev) => prev.concat(plugins));
};
//# sourceMappingURL=remark-plugin-factory.js.map
import { __awaiter } from "tslib";
import { fromPairs } from 'lodash-es';
import { Schema } from 'prosemirror-model';
import { createCtx } from '../context';
import { buildObject } from '../utility';
import { Initialize } from '../internal-plugin';

@@ -15,6 +15,6 @@ import { createTiming } from '../timing';

yield Initialize();
const nodes = buildObject(ctx.use(nodesCtx).get(), (node) => [node.id, node.schema]);
const marks = buildObject(ctx.use(marksCtx).get(), (mark) => [mark.id, mark.schema]);
const schema = ctx.use(schemaCtx);
schema.set(new Schema({
const getAtom = (x) => fromPairs(x.map(({ id, schema }) => [id, schema]));
const nodes = getAtom(ctx.get(nodesCtx));
const marks = getAtom(ctx.get(marksCtx));
ctx.set(schemaCtx, new Schema({
nodes,

@@ -21,0 +21,0 @@ marks,

import type { Node as ProsemirrorNode } from 'prosemirror-model';
import { MilkdownPlugin } from '../utility';
export declare const serializerCtx: import("..").Meta<(node: ProsemirrorNode) => string>;
export declare const SerializerReady: {
(): Promise<unknown>;
done(): void;
};
export declare const serializer: MilkdownPlugin;
//# sourceMappingURL=serializer.d.ts.map

@@ -5,4 +5,6 @@ import { __awaiter } from "tslib";

import { createSerializer } from '../serializer';
import { createTiming } from '../timing';
import { buildObject } from '../utility';
export const serializerCtx = createCtx(() => '');
export const SerializerReady = createTiming('SerializerReady');
export const serializer = (pre) => {

@@ -12,18 +14,12 @@ pre.inject(serializerCtx);

yield SchemaReady();
const nodes = ctx.use(nodesCtx).get();
const marks = ctx.use(marksCtx).get();
const remark = ctx.use(remarkCtx).get();
const schema = ctx.use(schemaCtx).get();
const serializer = ctx.use(serializerCtx);
const children = [
...nodes.map((node) => (Object.assign(Object.assign({}, node), { is: 'node' }))),
...marks.map((mark) => (Object.assign(Object.assign({}, mark), { is: 'mark' }))),
];
const spec = buildObject(children, (child) => [
child.id,
Object.assign(Object.assign({}, child.serializer), { is: child.is }),
]);
serializer.set(createSerializer(schema, spec, remark));
const nodes = ctx.get(nodesCtx);
const marks = ctx.get(marksCtx);
const remark = ctx.get(remarkCtx);
const schema = ctx.get(schemaCtx);
const children = [...nodes, ...marks];
const spec = buildObject(children, (child) => [child.id, child.serializer]);
ctx.set(serializerCtx, createSerializer(schema, spec, remark));
SerializerReady.done();
});
};
//# sourceMappingURL=serializer.js.map

@@ -45,8 +45,3 @@ var _State_instances, _State_matchTarget, _State_runNode;

this.next = (nodes = []) => {
if (Array.isArray(nodes)) {
nodes.forEach((node) => __classPrivateFieldGet(this, _State_instances, "m", _State_runNode).call(this, node));
}
else {
__classPrivateFieldGet(this, _State_instances, "m", _State_runNode).call(this, nodes);
}
[nodes].flat().forEach((node) => __classPrivateFieldGet(this, _State_instances, "m", _State_runNode).call(this, node));
return this;

@@ -57,5 +52,3 @@ };

_State_instances = new WeakSet(), _State_matchTarget = function _State_matchTarget(node) {
const result = Object.entries(this.specMap)
.map(([key, spec]) => (Object.assign({ key }, spec)))
.find((x) => x.match(node));
const result = Object.values(this.specMap).find((x) => x.match(node));
if (!result)

@@ -62,0 +55,0 @@ throw new Error();

@@ -18,6 +18,8 @@ import type { NodeType, MarkType } from 'prosemirror-model';

is: 'node';
key: string;
}) | (MarkParserSpec & {
is: 'mark';
key: string;
});
export declare type InnerParserSpecMap = Record<string, ParserSpecWithType>;
//# sourceMappingURL=types.d.ts.map

@@ -12,8 +12,4 @@ import type { Mark as ProseMark, Node as ProseNode } from 'prosemirror-model';

export declare type SerializerSpec = NodeSerializerSpec | MarkSerializerSpec;
export declare type SerializerSpecWithType = (NodeSerializerSpec & {
is: 'node';
}) | (MarkSerializerSpec & {
is: 'mark';
});
export declare type SerializerSpecWithType = NodeSerializerSpec | MarkSerializerSpec;
export declare type InnerSerializerSpecMap = Record<string, SerializerSpecWithType>;
//# sourceMappingURL=types.d.ts.map

@@ -1,2 +0,2 @@

export declare function buildObject<T, U>(source: T[], fn: (source: T) => [string, U], initial?: Record<string, U>): Record<string, U>;
export declare const buildObject: <T, U>(source: T[], fn: (source: T) => [string, U], initial?: Record<string, U>) => Record<string, U>;
//# sourceMappingURL=build-object.d.ts.map

@@ -1,7 +0,2 @@

export function buildObject(source, fn, initial = {}) {
return source.reduce((acc, cur) => {
const [key, value] = fn(cur);
return Object.assign(Object.assign({}, acc), { [key]: value });
}, initial);
}
export const buildObject = (source, fn, initial = {}) => source.map(fn).reduce((acc, [key, value]) => (Object.assign(Object.assign({}, acc), { [key]: value })), initial);
//# sourceMappingURL=build-object.js.map
import type { Context, Meta } from '../context';
import type { Mark, Node } from '../internal-plugin';
export declare type AnyRecord = Record<string, any>;

@@ -17,2 +18,3 @@ export declare type Ctx = {

export declare type Configure = CtxHandler;
export declare type Atom = Mark | Node;
//# sourceMappingURL=types.d.ts.map
{
"name": "@milkdown/core",
"version": "4.6.2",
"version": "4.6.3",
"main": "lib/index.js",

@@ -5,0 +5,0 @@ "module": "lib/index.js",

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc