New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@milkdown/utils

Package Overview
Dependencies
Maintainers
1
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@milkdown/utils - npm Package Compare versions

Comparing version

to
5.0.1

4

lib/atom/atom-list.d.ts
import { MilkdownPlugin } from '@milkdown/core';
import { AddMetadata, AnyFn, Metadata } from '../types';
import { AddMetadata, Metadata } from '../types';
declare type PluginWithMetadata = MilkdownPlugin & Metadata;
declare type Plugin = MilkdownPlugin | PluginWithMetadata;
declare type Factory<T extends AnyFn = AnyFn> = AddMetadata<T>;
declare type Factory = AddMetadata;
export declare class AtomList<T extends Plugin = Plugin> extends Array<T> {

@@ -7,0 +7,0 @@ private findThenRun;

import { Attrs, CmdKey, Ctx } from '@milkdown/core';
import { AddMetadata, AnyFn, CommandConfig, CommonOptions, Methods, UnknownRecord, Utils } from '../types';
import { AddMetadata, CommandConfig, CommonOptions, Factory, GetPlugin, Methods, UnknownRecord, Utils, WithExtend } from '../types';
export declare const getClassName: (className: CommonOptions['className']) => (attrs: Attrs, ...defaultValue: (string | null | undefined)[]) => string;

@@ -7,3 +7,4 @@ export declare const createShortcut: <T>(commandKey: CmdKey<T>, defaultKey: string, args?: T | undefined) => CommandConfig<unknown>;

export declare const applyMethods: <Keys extends string, Type, Options extends UnknownRecord>(ctx: Ctx, plugin: Methods<Keys, Type>, getType: () => Promise<Type>, options?: Partial<CommonOptions<Keys, Options>> | undefined) => Promise<void>;
export declare const addMetadata: <T extends AnyFn>(x: T) => AddMetadata<T>;
export declare const addMetadata: <SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord>(x: GetPlugin<SupportedKeys, Options>) => AddMetadata<SupportedKeys, Options>;
export declare const withExtend: <SupportedKeys extends string, Options extends UnknownRecord, Type, Rest>(factory: Factory<SupportedKeys, Options, Type, Rest>, origin: AddMetadata<SupportedKeys, Options>, creator: (factory: Factory<SupportedKeys, Options, Type, Rest>) => WithExtend<SupportedKeys, Options, Type, Rest>) => WithExtend<SupportedKeys, Options, Type, Rest>;
//# sourceMappingURL=common.d.ts.map

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

export const addMetadata = (x) => {
const fn = (...args) => {
const result = x(...args);
const fn = (options) => {
const result = x(options);
result.origin = fn;

@@ -73,2 +73,8 @@ return result;

};
export const withExtend = (factory, origin, creator) => {
const next = origin;
const extend = (extendFactory) => creator((...args) => extendFactory(factory(...args), ...args));
next.extend = extend;
return next;
};
//# sourceMappingURL=common.js.map

@@ -1,11 +0,12 @@

import { Ctx, MarkSchema, MilkdownPlugin } from '@milkdown/core';
import { Ctx, MarkSchema } from '@milkdown/core';
import { MarkType, MarkViewFactory } from '@milkdown/prose';
import { CommonOptions, Methods, UnknownRecord, Utils } from '../types';
declare type MarkFactory<SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord> = (utils: Utils, options?: Partial<CommonOptions<SupportedKeys, Options>>) => {
import { Factory, UnknownRecord, WithExtend } from '../types';
declare type MarkRest = {
id: string;
schema: (ctx: Ctx) => MarkSchema;
view?: (ctx: Ctx) => MarkViewFactory;
} & Methods<SupportedKeys, MarkType>;
export declare const createMark: <SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord>(factory: MarkFactory<SupportedKeys, Options>) => import("../types").AddMetadata<(options?: Partial<Options> | undefined) => MilkdownPlugin>;
};
declare type MarkFactory<SupportedKeys extends string, Options extends UnknownRecord> = Factory<SupportedKeys, Options, MarkType, MarkRest>;
export declare const createMark: <SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord>(factory: MarkFactory<SupportedKeys, Options>) => WithExtend<SupportedKeys, Options, MarkType<any>, MarkRest>;
export {};
//# sourceMappingURL=create-mark.d.ts.map
/* Copyright 2021, Milkdown by Mirone. */
import { __awaiter } from "tslib";
import { marksCtx, schemaCtx, SchemaReady, viewCtx } from '@milkdown/core';
import { addMetadata, applyMethods, getUtils } from '.';
export const createMark = (factory) => addMetadata((options) => () => (ctx) => __awaiter(void 0, void 0, void 0, function* () {
import { addMetadata, applyMethods, getUtils, withExtend } from './common';
export const createMark = (factory) => withExtend(factory, addMetadata((options) => () => (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const utils = getUtils(ctx, options);

@@ -19,3 +19,3 @@ const plugin = factory(utils, options);

}
}));
})), createMark);
//# sourceMappingURL=create-mark.js.map

@@ -1,11 +0,12 @@

import { Ctx, MilkdownPlugin, NodeSchema } from '@milkdown/core';
import { Ctx, NodeSchema } from '@milkdown/core';
import { NodeType, NodeViewFactory } from '@milkdown/prose';
import { CommonOptions, Methods, UnknownRecord, Utils } from '../types';
declare type NodeFactory<SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord> = (utils: Utils, options?: Partial<CommonOptions<SupportedKeys, Options>>) => {
import { Factory, UnknownRecord, WithExtend } from '../types';
declare type NodeRest = {
id: string;
schema: (ctx: Ctx) => NodeSchema;
view?: (ctx: Ctx) => NodeViewFactory;
} & Methods<SupportedKeys, NodeType>;
export declare const createNode: <SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord>(factory: NodeFactory<SupportedKeys, Options>) => import("../types").AddMetadata<(options?: Partial<CommonOptions<SupportedKeys, Options>> | undefined) => MilkdownPlugin>;
};
declare type NodeFactory<SupportedKeys extends string, Options extends UnknownRecord> = Factory<SupportedKeys, Options, NodeType, NodeRest>;
export declare const createNode: <SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord>(factory: NodeFactory<SupportedKeys, Options>) => WithExtend<SupportedKeys, Options, NodeType<any>, NodeRest>;
export {};
//# sourceMappingURL=create-node.d.ts.map
/* Copyright 2021, Milkdown by Mirone. */
import { __awaiter } from "tslib";
import { nodesCtx, schemaCtx, SchemaReady, viewCtx } from '@milkdown/core';
import { addMetadata, applyMethods } from '.';
import { getUtils } from './common';
export const createNode = (factory) => addMetadata((options) => () => (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const utils = getUtils(ctx, options);
const plugin = factory(utils, options);
yield applyMethods(ctx, plugin, () => __awaiter(void 0, void 0, void 0, function* () {
const node = plugin.schema(ctx);
ctx.update(nodesCtx, (ns) => [...ns, [plugin.id, node]]);
yield ctx.wait(SchemaReady);
const schema = ctx.get(schemaCtx);
return schema.nodes[plugin.id];
}), options);
if (plugin.view) {
const view = plugin.view(ctx);
ctx.update(viewCtx, (v) => [...v, [plugin.id, view]]);
}
}));
import { addMetadata, applyMethods, getUtils, withExtend } from './common';
export const createNode = (factory) => {
const origin = addMetadata((options) => () => (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const utils = getUtils(ctx, options);
const plugin = factory(utils, options);
yield applyMethods(ctx, plugin, () => __awaiter(void 0, void 0, void 0, function* () {
const node = plugin.schema(ctx);
ctx.update(nodesCtx, (ns) => [...ns, [plugin.id, node]]);
yield ctx.wait(SchemaReady);
const schema = ctx.get(schemaCtx);
return schema.nodes[plugin.id];
}), options);
if (plugin.view) {
const view = plugin.view(ctx);
ctx.update(viewCtx, (v) => [...v, [plugin.id, view]]);
}
}));
return withExtend(factory, origin, createNode);
};
//# sourceMappingURL=create-node.js.map

@@ -1,5 +0,4 @@

import { Ctx, MarkSchema, MilkdownPlugin, NodeSchema } from '@milkdown/core';
import { Ctx, MarkSchema, NodeSchema } from '@milkdown/core';
import { MarkType, MarkViewFactory, NodeType, NodeViewFactory } from '@milkdown/prose';
import { Utils } from '..';
import { CommonOptions, Methods, UnknownRecord } from '../types';
import { Factory, UnknownRecord, WithExtend } from '../types';
declare type TypeMapping<NodeKeys extends string, MarkKeys extends string> = {

@@ -15,3 +14,3 @@ [K in NodeKeys]: NodeType;

};
declare type PluginFactory<SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord, NodeKeys extends string = string, MarkKeys extends string = string> = (utils: Utils, options?: Partial<CommonOptions<SupportedKeys, Options>>) => {
declare type PluginRest<NodeKeys extends string, MarkKeys extends string> = {
schema?: (ctx: Ctx) => {

@@ -22,5 +21,6 @@ node?: Record<NodeKeys, NodeSchema>;

view?: (ctx: Ctx) => Partial<ViewMapping<NodeKeys, MarkKeys>>;
} & Methods<SupportedKeys, TypeMapping<NodeKeys, MarkKeys>>;
export declare const createPlugin: <SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord, NodeKeys extends string = string, MarkKeys extends string = string>(factory: PluginFactory<SupportedKeys, Options, NodeKeys, MarkKeys>) => import("../types").AddMetadata<(options?: Partial<CommonOptions<SupportedKeys, Options>> | undefined) => MilkdownPlugin>;
};
declare type PluginFactory<SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord, NodeKeys extends string = string, MarkKeys extends string = string> = Factory<SupportedKeys, Options, TypeMapping<NodeKeys, MarkKeys>, PluginRest<NodeKeys, MarkKeys>>;
export declare const createPlugin: <SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord, NodeKeys extends string = string, MarkKeys extends string = string>(factory: PluginFactory<SupportedKeys, Options, NodeKeys, MarkKeys>) => WithExtend<SupportedKeys, Options, TypeMapping<NodeKeys, MarkKeys>, PluginRest<NodeKeys, MarkKeys>>;
export {};
//# sourceMappingURL=create-plugin.d.ts.map
/* Copyright 2021, Milkdown by Mirone. */
import { __awaiter } from "tslib";
import { marksCtx, nodesCtx, schemaCtx, SchemaReady, viewCtx, } from '@milkdown/core';
import { addMetadata, applyMethods, getUtils } from '.';
export const createPlugin = (factory) => addMetadata((options) => () => (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const utils = getUtils(ctx, options);
const plugin = factory(utils, options);
yield applyMethods(ctx, plugin, () => __awaiter(void 0, void 0, void 0, function* () {
let node = {};
let mark = {};
if (plugin.schema) {
const schemas = plugin.schema(ctx);
if (schemas.node) {
node = schemas.node;
const nodes = Object.entries(schemas.node);
ctx.update(nodesCtx, (ns) => [...ns, ...nodes]);
import { addMetadata, applyMethods, getUtils, withExtend } from './common';
export const createPlugin = (factory) => {
const origin = addMetadata((options) => () => (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const utils = getUtils(ctx, options);
const plugin = factory(utils, options);
yield applyMethods(ctx, plugin, () => __awaiter(void 0, void 0, void 0, function* () {
let node = {};
let mark = {};
if (plugin.schema) {
const schemas = plugin.schema(ctx);
if (schemas.node) {
node = schemas.node;
const nodes = Object.entries(schemas.node);
ctx.update(nodesCtx, (ns) => [...ns, ...nodes]);
}
if (schemas.mark) {
mark = schemas.mark;
const marks = Object.entries(schemas.mark);
ctx.update(marksCtx, (ms) => [...ms, ...marks]);
}
}
if (schemas.mark) {
mark = schemas.mark;
const marks = Object.entries(schemas.mark);
ctx.update(marksCtx, (ms) => [...ms, ...marks]);
}
yield ctx.wait(SchemaReady);
const schema = ctx.get(schemaCtx);
const nodeTypes = Object.keys(node).map((id) => [id, schema.nodes[id]]);
const markTypes = Object.keys(mark).map((id) => [id, schema.marks[id]]);
const type = Object.fromEntries([...nodeTypes, ...markTypes]);
return type;
}), options);
if (plugin.view) {
const view = plugin.view(ctx);
ctx.update(viewCtx, (v) => [
...v,
...Object.entries(view),
]);
}
yield ctx.wait(SchemaReady);
const schema = ctx.get(schemaCtx);
const nodeTypes = Object.keys(node).map((id) => [id, schema.nodes[id]]);
const markTypes = Object.keys(mark).map((id) => [id, schema.marks[id]]);
const type = Object.fromEntries([...nodeTypes, ...markTypes]);
return type;
}), options);
if (plugin.view) {
const view = plugin.view(ctx);
ctx.update(viewCtx, (v) => [
...v,
...Object.entries(view),
]);
}
}));
}));
return withExtend(factory, origin, createPlugin);
};
//# sourceMappingURL=create-plugin.js.map

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

import type { Attrs, CmdKey, ThemeTool } from '@milkdown/core';
import type { Attrs, CmdKey, MilkdownPlugin, ThemeTool } from '@milkdown/core';
import { CmdTuple, Ctx, RemarkPlugin } from '@milkdown/core';

@@ -23,2 +23,3 @@ import { InputRule, Plugin } from '@milkdown/prose';

};
export declare type GetPlugin<SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord> = (options?: Partial<CommonOptions<SupportedKeys, Options>>) => MilkdownPlugin;
export declare type AnyFn = (...args: any[]) => any;

@@ -28,3 +29,11 @@ export declare type Metadata<T = unknown> = {

};
export declare type AddMetadata<T extends AnyFn = AnyFn> = (...args: Parameters<T>) => Metadata<T> & ReturnType<T>;
export declare type AddMetadata<SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord> = (options?: Partial<CommonOptions<SupportedKeys, Options>>) => Metadata<GetPlugin<SupportedKeys, Options>> & MilkdownPlugin;
export declare type Spec<SupportedKeys extends string, Type, Rest> = Methods<SupportedKeys, Type> & Rest;
export declare type Factory<SupportedKeys extends string, Options extends UnknownRecord, Type, Rest> = (utils: Utils, options?: Partial<CommonOptions<SupportedKeys, Options>>) => Spec<SupportedKeys, Type, Rest>;
export declare type WithExtend<SupportedKeys extends string, Options extends UnknownRecord, Type, Rest> = AddMetadata<SupportedKeys, Options> & {
extend: <ExtendedSupportedKeys extends string = SupportedKeys, ExtendedOptions extends UnknownRecord = Options, ExtendedType extends Type = Type, ExtendedRest extends Rest = Rest>(extendFactory: (...args: [
original: Spec<SupportedKeys, Type, Rest>,
...rest: Parameters<Factory<ExtendedSupportedKeys, ExtendedOptions, ExtendedType, ExtendedRest>>
]) => Spec<ExtendedSupportedKeys, ExtendedType, ExtendedRest>) => AddMetadata<ExtendedSupportedKeys, ExtendedOptions>;
};
//# sourceMappingURL=types.d.ts.map
{
"name": "@milkdown/utils",
"version": "5.0.0",
"version": "5.0.1",
"main": "lib/index.js",

@@ -17,3 +17,3 @@ "module": "lib/index.js",

"dependencies": {
"@milkdown/exception": " *",
"@milkdown/exception": "5.0.1",
"tslib": "^2.3.1"

@@ -20,0 +20,0 @@ },

@@ -5,3 +5,3 @@ /* Copyright 2021, Milkdown by Mirone. */

import { AddMetadata, AnyFn, Metadata } from '../types';
import { AddMetadata, Metadata } from '../types';

@@ -11,6 +11,6 @@ type PluginWithMetadata = MilkdownPlugin & Metadata;

type Factory<T extends AnyFn = AnyFn> = AddMetadata<T>;
const hasMetadata = (x: Plugin): x is PluginWithMetadata => Object.prototype.hasOwnProperty.call(x, 'origin');
type Factory = AddMetadata;
export class AtomList<T extends Plugin = Plugin> extends Array<T> {

@@ -17,0 +17,0 @@ private findThenRun<U extends Factory>(target: U, callback: (index: number) => void): this {

@@ -16,3 +16,13 @@ /* Copyright 2021, Milkdown by Mirone. */

import { AddMetadata, AnyFn, CommandConfig, CommonOptions, Methods, UnknownRecord, Utils } from '../types';
import {
AddMetadata,
CommandConfig,
CommonOptions,
Factory,
GetPlugin,
Methods,
UnknownRecord,
Utils,
WithExtend,
} from '../types';

@@ -94,5 +104,7 @@ export const getClassName =

export const addMetadata = <T extends AnyFn>(x: T) => {
const fn: AddMetadata<T> = (...args) => {
const result = x(...args);
export const addMetadata = <SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord>(
x: GetPlugin<SupportedKeys, Options>,
): AddMetadata<SupportedKeys, Options> => {
const fn: AddMetadata<SupportedKeys, Options> = (options) => {
const result = x(options) as ReturnType<AddMetadata<SupportedKeys, Options>>;
result.origin = fn;

@@ -103,1 +115,16 @@ return result;

};
export const withExtend = <SupportedKeys extends string, Options extends UnknownRecord, Type, Rest>(
factory: Factory<SupportedKeys, Options, Type, Rest>,
origin: AddMetadata<SupportedKeys, Options>,
creator: (factory: Factory<SupportedKeys, Options, Type, Rest>) => WithExtend<SupportedKeys, Options, Type, Rest>,
): WithExtend<SupportedKeys, Options, Type, Rest> => {
type Ext = WithExtend<SupportedKeys, Options, Type, Rest>;
const next = origin as Ext;
const extend = (extendFactory: Parameters<Ext['extend']>[0]) =>
creator((...args) => extendFactory(factory(...args), ...args));
next.extend = extend as Ext['extend'];
return next;
};

@@ -6,45 +6,53 @@ /* Copyright 2021, Milkdown by Mirone. */

import { CommonOptions, Methods, UnknownRecord, Utils } from '../types';
import { addMetadata, applyMethods, getUtils } from '.';
import { Factory, UnknownRecord, WithExtend } from '../types';
import { addMetadata, applyMethods, getUtils, withExtend } from './common';
type MarkFactory<SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord> = (
utils: Utils,
options?: Partial<CommonOptions<SupportedKeys, Options>>,
) => {
type MarkRest = {
id: string;
schema: (ctx: Ctx) => MarkSchema;
view?: (ctx: Ctx) => MarkViewFactory;
} & Methods<SupportedKeys, MarkType>;
};
type MarkFactory<SupportedKeys extends string, Options extends UnknownRecord> = Factory<
SupportedKeys,
Options,
MarkType,
MarkRest
>;
export const createMark = <SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord>(
factory: MarkFactory<SupportedKeys, Options>,
) =>
addMetadata(
(options?: Partial<Options>): MilkdownPlugin =>
() =>
async (ctx) => {
const utils = getUtils(ctx, options);
): WithExtend<SupportedKeys, Options, MarkType, MarkRest> =>
withExtend(
factory,
addMetadata(
(options?: Partial<Options>): MilkdownPlugin =>
() =>
async (ctx) => {
const utils = getUtils(ctx, options);
const plugin = factory(utils, options);
const plugin = factory(utils, options);
await applyMethods(
ctx,
plugin,
async () => {
const node = plugin.schema(ctx);
ctx.update(marksCtx, (ns) => [...ns, [plugin.id, node] as [string, MarkSchema]]);
await applyMethods(
ctx,
plugin,
async () => {
const node = plugin.schema(ctx);
ctx.update(marksCtx, (ns) => [...ns, [plugin.id, node] as [string, MarkSchema]]);
await ctx.wait(SchemaReady);
await ctx.wait(SchemaReady);
const schema = ctx.get(schemaCtx);
return schema.marks[plugin.id];
},
options,
);
const schema = ctx.get(schemaCtx);
return schema.marks[plugin.id];
},
options,
);
if (plugin.view) {
const view = plugin.view(ctx);
ctx.update(viewCtx, (v) => [...v, [plugin.id, view] as [string, ViewFactory]]);
}
},
if (plugin.view) {
const view = plugin.view(ctx);
ctx.update(viewCtx, (v) => [...v, [plugin.id, view] as [string, ViewFactory]]);
}
},
),
createMark,
);

@@ -6,20 +6,23 @@ /* Copyright 2021, Milkdown by Mirone. */

import { CommonOptions, Methods, UnknownRecord, Utils } from '../types';
import { addMetadata, applyMethods } from '.';
import { getUtils } from './common';
import { Factory, UnknownRecord, WithExtend } from '../types';
import { addMetadata, applyMethods, getUtils, withExtend } from './common';
type NodeFactory<SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord> = (
utils: Utils,
options?: Partial<CommonOptions<SupportedKeys, Options>>,
) => {
type NodeRest = {
id: string;
schema: (ctx: Ctx) => NodeSchema;
view?: (ctx: Ctx) => NodeViewFactory;
} & Methods<SupportedKeys, NodeType>;
};
type NodeFactory<SupportedKeys extends string, Options extends UnknownRecord> = Factory<
SupportedKeys,
Options,
NodeType,
NodeRest
>;
export const createNode = <SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord>(
factory: NodeFactory<SupportedKeys, Options>,
) =>
addMetadata(
(options?: Partial<CommonOptions<SupportedKeys, Options>>): MilkdownPlugin =>
): WithExtend<SupportedKeys, Options, NodeType, NodeRest> => {
const origin = addMetadata<SupportedKeys, Options>(
(options): MilkdownPlugin =>
() =>

@@ -52,1 +55,3 @@ async (ctx) => {

);
return withExtend(factory, origin, createNode);
};

@@ -16,5 +16,4 @@ /* Copyright 2021, Milkdown by Mirone. */

import { Utils } from '..';
import { CommonOptions, Methods, UnknownRecord } from '../types';
import { addMetadata, applyMethods, getUtils } from '.';
import { Factory, UnknownRecord, WithExtend } from '../types';
import { addMetadata, applyMethods, getUtils, withExtend } from './common';

@@ -33,2 +32,9 @@ type TypeMapping<NodeKeys extends string, MarkKeys extends string> = {

type PluginRest<NodeKeys extends string, MarkKeys extends string> = {
schema?: (ctx: Ctx) => {
node?: Record<NodeKeys, NodeSchema>;
mark?: Record<MarkKeys, MarkSchema>;
};
view?: (ctx: Ctx) => Partial<ViewMapping<NodeKeys, MarkKeys>>;
};
type PluginFactory<

@@ -39,12 +45,3 @@ SupportedKeys extends string = string,

MarkKeys extends string = string,
> = (
utils: Utils,
options?: Partial<CommonOptions<SupportedKeys, Options>>,
) => {
schema?: (ctx: Ctx) => {
node?: Record<NodeKeys, NodeSchema>;
mark?: Record<MarkKeys, MarkSchema>;
};
view?: (ctx: Ctx) => Partial<ViewMapping<NodeKeys, MarkKeys>>;
} & Methods<SupportedKeys, TypeMapping<NodeKeys, MarkKeys>>;
> = Factory<SupportedKeys, Options, TypeMapping<NodeKeys, MarkKeys>, PluginRest<NodeKeys, MarkKeys>>;

@@ -58,5 +55,5 @@ export const createPlugin = <

factory: PluginFactory<SupportedKeys, Options, NodeKeys, MarkKeys>,
) =>
addMetadata(
(options?: Partial<CommonOptions<SupportedKeys, Options>>): MilkdownPlugin =>
): WithExtend<SupportedKeys, Options, TypeMapping<NodeKeys, MarkKeys>, PluginRest<NodeKeys, MarkKeys>> => {
const origin = addMetadata<SupportedKeys, Options>(
(options): MilkdownPlugin =>
() =>

@@ -109,1 +106,4 @@ async (ctx) => {

);
return withExtend(factory, origin, createPlugin);
};
/* Copyright 2021, Milkdown by Mirone. */
import type { Attrs, CmdKey, ThemeTool } from '@milkdown/core';
import type { Attrs, CmdKey, MilkdownPlugin, ThemeTool } from '@milkdown/core';
import { CmdTuple, Ctx, RemarkPlugin } from '@milkdown/core';

@@ -30,2 +30,7 @@ import { InputRule, Plugin } from '@milkdown/prose';

// get plugin
export type GetPlugin<SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord> = (
options?: Partial<CommonOptions<SupportedKeys, Options>>,
) => MilkdownPlugin;
// eslint-disable-next-line @typescript-eslint/no-explicit-any

@@ -36,2 +41,29 @@ export type AnyFn = (...args: any[]) => any;

};
export type AddMetadata<T extends AnyFn = AnyFn> = (...args: Parameters<T>) => Metadata<T> & ReturnType<T>;
// export type AddMetadata<T extends AnyFn = AnyFn> = (...args: Parameters<T>) => Metadata<T> & ReturnType<T>;
export type AddMetadata<SupportedKeys extends string = string, Options extends UnknownRecord = UnknownRecord> = (
options?: Partial<CommonOptions<SupportedKeys, Options>>,
) => Metadata<GetPlugin<SupportedKeys, Options>> & MilkdownPlugin;
export type Spec<SupportedKeys extends string, Type, Rest> = Methods<SupportedKeys, Type> & Rest;
export type Factory<SupportedKeys extends string, Options extends UnknownRecord, Type, Rest> = (
utils: Utils,
options?: Partial<CommonOptions<SupportedKeys, Options>>,
) => Spec<SupportedKeys, Type, Rest>;
export type WithExtend<SupportedKeys extends string, Options extends UnknownRecord, Type, Rest> = AddMetadata<
SupportedKeys,
Options
> & {
extend: <
ExtendedSupportedKeys extends string = SupportedKeys,
ExtendedOptions extends UnknownRecord = Options,
ExtendedType extends Type = Type,
ExtendedRest extends Rest = Rest,
>(
extendFactory: (
...args: [
original: Spec<SupportedKeys, Type, Rest>,
...rest: Parameters<Factory<ExtendedSupportedKeys, ExtendedOptions, ExtendedType, ExtendedRest>>
]
) => Spec<ExtendedSupportedKeys, ExtendedType, ExtendedRest>,
) => AddMetadata<ExtendedSupportedKeys, ExtendedOptions>;
};

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