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

@milkdown/preset-commonmark

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@milkdown/preset-commonmark - npm Package Compare versions

Comparing version 4.5.1 to 4.5.2

lib/supported-keys.d.ts

6

CHANGELOG.md
# @milkdown/preset-commonmark
## 4.5.2
### Patch Changes
- 0dd0320: Add configurable keyboard shortcuts feature.
## 4.5.1

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

1

lib/index.d.ts
import type { Atom } from '@milkdown/core';
export * from './node';
export * from './mark';
export * from './supported-keys';
declare type ConstructorOf<T> = T extends InstanceType<infer U> ? U : T;

@@ -5,0 +6,0 @@ declare class NodeList<T extends Atom = Atom> extends Array<T> {

@@ -5,2 +5,3 @@ import { marks } from './mark';

export * from './mark';
export * from './supported-keys';
class NodeList extends Array {

@@ -7,0 +8,0 @@ configure(Target, config) {

12

lib/mark/code-inline.d.ts

@@ -0,6 +1,8 @@

import type { MarkParserSpec, MarkSerializerSpec } from '@milkdown/core';
import type { InputRule } from 'prosemirror-inputrules';
import type { MarkSpec, MarkType } from 'prosemirror-model';
import { MarkParserSpec, MarkSerializerSpec } from '@milkdown/core';
import type { InputRule } from 'prosemirror-inputrules';
import { CommonMark } from '../utility';
export declare class CodeInline extends CommonMark {
import { SupportedKeys } from '../supported-keys';
import { BaseMark } from '../utility';
declare type Keys = SupportedKeys.CodeInline;
export declare class CodeInline extends BaseMark<Keys> {
readonly id = "code_inline";

@@ -11,3 +13,5 @@ readonly schema: MarkSpec;

readonly inputRules: (markType: MarkType) => InputRule[];
readonly commands: BaseMark<Keys>['commands'];
}
export {};
//# sourceMappingURL=code-inline.d.ts.map

@@ -1,3 +0,5 @@

import { CommonMark, markRule } from '../utility';
export class CodeInline extends CommonMark {
import { toggleMark } from 'prosemirror-commands';
import { SupportedKeys } from '../supported-keys';
import { BaseMark, markRule } from '../utility';
export class CodeInline extends BaseMark {
constructor() {

@@ -26,4 +28,10 @@ super(...arguments);

this.inputRules = (markType) => [markRule(/(?:^|[^`])(`([^`]+)`)$/, markType)];
this.commands = (markType) => ({
[SupportedKeys.CodeInline]: {
defaultKey: 'Mod-e',
command: toggleMark(markType),
},
});
}
}
//# sourceMappingURL=code-inline.js.map

@@ -0,7 +1,8 @@

import type { MarkParserSpec, MarkSerializerSpec } from '@milkdown/core';
import type { InputRule } from 'prosemirror-inputrules';
import type { MarkSpec, MarkType } from 'prosemirror-model';
import type { Keymap } from 'prosemirror-commands';
import type { InputRule } from 'prosemirror-inputrules';
import { MarkParserSpec, MarkSerializerSpec } from '@milkdown/core';
import { CommonMark } from '../utility';
export declare class Em extends CommonMark {
import { SupportedKeys } from '../supported-keys';
import { BaseMark } from '../utility';
declare type Keys = SupportedKeys.Em;
export declare class Em extends BaseMark {
readonly id = "em";

@@ -12,4 +13,5 @@ readonly schema: MarkSpec;

readonly inputRules: (markType: MarkType) => InputRule[];
readonly keymap: (markType: MarkType) => Keymap;
readonly commands: BaseMark<Keys>['commands'];
}
export {};
//# sourceMappingURL=em.d.ts.map
import { toggleMark } from 'prosemirror-commands';
import { CommonMark, markRule } from '../utility';
export class Em extends CommonMark {
import { SupportedKeys } from '../supported-keys';
import { BaseMark, markRule } from '../utility';
export class Em extends BaseMark {
constructor() {

@@ -33,4 +34,7 @@ super(...arguments);

];
this.keymap = (markType) => ({
'Mod-i': toggleMark(markType),
this.commands = (markType) => ({
[SupportedKeys.Em]: {
defaultKey: 'Mod-i',
command: toggleMark(markType),
},
});

@@ -37,0 +41,0 @@ }

import type { MarkSpec, MarkType, Schema } from 'prosemirror-model';
import { MarkParserSpec, MarkSerializerSpec } from '@milkdown/core';
import { InputRule } from 'prosemirror-inputrules';
import { CommonMark } from '../utility';
export declare class Link extends CommonMark {
import { BaseMark } from '../utility';
export declare class Link extends BaseMark {
readonly id = "link";

@@ -7,0 +7,0 @@ readonly schema: MarkSpec;

import { InputRule } from 'prosemirror-inputrules';
import { CommonMark } from '../utility';
export class Link extends CommonMark {
import { BaseMark } from '../utility';
export class Link extends BaseMark {
constructor() {

@@ -5,0 +5,0 @@ super(...arguments);

import { MarkParserSpec, MarkSerializerSpec } from '@milkdown/core';
import type { Keymap } from 'prosemirror-commands';
import type { InputRule } from 'prosemirror-inputrules';
import type { MarkSpec, MarkType } from 'prosemirror-model';
import { CommonMark } from '../utility';
export declare class Strong extends CommonMark {
import { SupportedKeys } from '../supported-keys';
import { BaseMark } from '../utility';
declare type Keys = SupportedKeys.Bold;
export declare class Strong extends BaseMark<Keys> {
readonly id = "strong";

@@ -12,4 +13,5 @@ readonly schema: MarkSpec;

readonly inputRules: (markType: MarkType) => InputRule[];
readonly keymap: (markType: MarkType) => Keymap;
readonly commands: BaseMark<Keys>['commands'];
}
export {};
//# sourceMappingURL=strong.d.ts.map
import { toggleMark } from 'prosemirror-commands';
import { CommonMark, markRule } from '../utility';
export class Strong extends CommonMark {
import { SupportedKeys } from '../supported-keys';
import { BaseMark, markRule } from '../utility';
export class Strong extends BaseMark {
constructor() {

@@ -33,4 +34,7 @@ super(...arguments);

];
this.keymap = (markType) => ({
'Mod-b': toggleMark(markType),
this.commands = (markType) => ({
[SupportedKeys.Bold]: {
defaultKey: 'Mod-b',
command: toggleMark(markType),
},
});

@@ -37,0 +41,0 @@ }

@@ -0,5 +1,7 @@

import type { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import type { NodeSpec, NodeType } from 'prosemirror-model';
import { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import { CommonNode } from '../utility';
export declare class Blockquote extends CommonNode {
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
declare type Keys = SupportedKeys.Blockquote;
export declare class Blockquote extends BaseNode<Keys> {
readonly id = "blockquote";

@@ -10,3 +12,5 @@ readonly schema: NodeSpec;

readonly inputRules: (nodeType: NodeType) => import("prosemirror-inputrules").InputRule<any>[];
readonly commands: BaseNode<Keys>['commands'];
}
export {};
//# sourceMappingURL=blockquote.d.ts.map

@@ -0,4 +1,6 @@

import { wrapIn } from 'prosemirror-commands';
import { wrappingInputRule } from 'prosemirror-inputrules';
import { CommonNode } from '../utility';
export class Blockquote extends CommonNode {
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
export class Blockquote extends BaseNode {
constructor() {

@@ -27,4 +29,10 @@ super(...arguments);

this.inputRules = (nodeType) => [wrappingInputRule(/^\s*>\s$/, nodeType)];
this.commands = (nodeType) => ({
[SupportedKeys.Blockquote]: {
defaultKey: 'Mod-Shift-b',
command: wrapIn(nodeType),
},
});
}
}
//# sourceMappingURL=blockquote.js.map

@@ -1,5 +0,7 @@

import type { NodeType, NodeSpec } from 'prosemirror-model';
import { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import { CommonNode } from '../utility';
export declare class BulletList extends CommonNode {
import type { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import type { NodeSpec, NodeType } from 'prosemirror-model';
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
declare type Keys = SupportedKeys.BulletList;
export declare class BulletList extends BaseNode<Keys> {
readonly id = "bullet_list";

@@ -10,3 +12,5 @@ readonly schema: NodeSpec;

inputRules: (nodeType: NodeType) => import("prosemirror-inputrules").InputRule<any>[];
readonly commands: BaseNode<Keys>['commands'];
}
export {};
//# sourceMappingURL=bullet-list.d.ts.map

@@ -0,4 +1,6 @@

import { wrapIn } from 'prosemirror-commands';
import { wrappingInputRule } from 'prosemirror-inputrules';
import { CommonNode } from '../utility';
export class BulletList extends CommonNode {
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
export class BulletList extends BaseNode {
constructor() {

@@ -28,4 +30,10 @@ super(...arguments);

this.inputRules = (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)];
this.commands = (nodeType) => ({
[SupportedKeys.BulletList]: {
defaultKey: 'Mod-Shift-8',
command: wrapIn(nodeType),
},
});
}
}
//# sourceMappingURL=bullet-list.js.map

@@ -0,9 +1,10 @@

import { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import type { NodeSpec, NodeType } from 'prosemirror-model';
import { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import { Keymap } from 'prosemirror-commands';
import { CommonNode } from '../utility';
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
declare type CodeFenceOptions = {
languageList?: string[];
};
export declare class CodeFence extends CommonNode<CodeFenceOptions> {
declare type Keys = SupportedKeys.CodeFence;
export declare class CodeFence extends BaseNode<Keys, CodeFenceOptions> {
#private;

@@ -15,5 +16,5 @@ readonly id = "fence";

readonly inputRules: (nodeType: NodeType) => import("prosemirror-inputrules").InputRule<any>[];
readonly keymap: () => Keymap;
readonly commands: BaseNode<Keys>['commands'];
}
export {};
//# sourceMappingURL=code-fence.d.ts.map
var _CodeFence_instances, _CodeFence_onChangeLanguage, _CodeFence_createSelectElement;
import { __classPrivateFieldGet } from "tslib";
import { LoadState } from '@milkdown/core';
import { setBlockType } from 'prosemirror-commands';
import { textblockTypeInputRule } from 'prosemirror-inputrules';
import { CommonNode } from '../utility';
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
const languageOptions = [

@@ -24,3 +26,3 @@ '',

];
export class CodeFence extends CommonNode {
export class CodeFence extends BaseNode {
constructor() {

@@ -85,10 +87,17 @@ super(...arguments);

this.inputRules = (nodeType) => [textblockTypeInputRule(/^```$/, nodeType)];
this.keymap = () => ({
Tab: (state, dispatch) => {
const { tr, selection } = state;
if (!dispatch) {
return false;
}
dispatch(tr.insertText(' ', selection.from, selection.to));
return true;
// override readonly keymap = (nodeType: NodeType): Keymap => ({
// Tab: (state: EditorState, dispatch) => {
// const { tr, selection } = state;
// if (!dispatch) {
// return false;
// }
// dispatch(tr.insertText(' ', selection.from, selection.to));
// return true;
// },
// 'Mod-Alt-c': setBlockType(nodeType),
// });
this.commands = (nodeType) => ({
[SupportedKeys.CodeFence]: {
defaultKey: 'Mod-Alt-c',
command: setBlockType(nodeType),
},

@@ -95,0 +104,0 @@ });

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

import type { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import type { NodeSpec } from 'prosemirror-model';
import { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import { CommonNode } from '../utility/base';
export declare class Doc extends CommonNode {
import { BaseNode } from '../utility/base';
export declare class Doc extends BaseNode {
readonly id = "doc";

@@ -6,0 +6,0 @@ readonly schema: NodeSpec;

@@ -1,3 +0,3 @@

import { CommonNode } from '../utility/base';
export class Doc extends CommonNode {
import { BaseNode } from '../utility/base';
export class Doc extends BaseNode {
constructor() {

@@ -4,0 +4,0 @@ super(...arguments);

@@ -1,6 +0,7 @@

import type { Keymap } from 'prosemirror-commands';
import type { NodeSpec, NodeType } from 'prosemirror-model';
import { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import { CommonNode } from '../utility';
export declare class HardBreak extends CommonNode {
import type { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import type { NodeSpec } from 'prosemirror-model';
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
declare type Keys = SupportedKeys.HardBreak;
export declare class HardBreak extends BaseNode<Keys> {
readonly id = "hardbreak";

@@ -10,4 +11,5 @@ readonly schema: NodeSpec;

readonly serializer: NodeSerializerSpec;
readonly keymap: (nodeType: NodeType) => Keymap;
readonly commands: BaseNode<Keys>['commands'];
}
export {};
//# sourceMappingURL=hard-break.d.ts.map

@@ -1,3 +0,4 @@

import { CommonNode } from '../utility';
export class HardBreak extends CommonNode {
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
export class HardBreak extends BaseNode {
constructor() {

@@ -25,6 +26,9 @@ super(...arguments);

};
this.keymap = (nodeType) => ({
'Shift-Enter': (state, dispatch) => {
dispatch === null || dispatch === void 0 ? void 0 : dispatch(state.tr.replaceSelectionWith(nodeType.create()).scrollIntoView());
return true;
this.commands = (nodeType) => ({
[SupportedKeys.HardBreak]: {
defaultKey: 'Shift-Enter',
command: (state, dispatch) => {
dispatch === null || dispatch === void 0 ? void 0 : dispatch(state.tr.replaceSelectionWith(nodeType.create()).scrollIntoView());
return true;
},
},

@@ -31,0 +35,0 @@ });

@@ -0,5 +1,7 @@

import type { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import type { NodeSpec, NodeType } from 'prosemirror-model';
import { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import { CommonNode } from '../utility/base';
export declare class Heading extends CommonNode {
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
declare type Keys = SupportedKeys.H1 | SupportedKeys.H2 | SupportedKeys.H3 | SupportedKeys.H4 | SupportedKeys.H5 | SupportedKeys.H6;
export declare class Heading extends BaseNode<Keys> {
id: string;

@@ -10,3 +12,5 @@ schema: NodeSpec;

inputRules: (nodeType: NodeType) => import("prosemirror-inputrules").InputRule<any>[];
readonly commands: BaseNode<Keys>['commands'];
}
export {};
//# sourceMappingURL=heading.d.ts.map

@@ -0,7 +1,9 @@

import { setBlockType } from 'prosemirror-commands';
import { textblockTypeInputRule } from 'prosemirror-inputrules';
import { CommonNode } from '../utility/base';
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
const headingIndex = Array(5)
.fill(0)
.map((_, i) => i + 1);
export class Heading extends CommonNode {
export class Heading extends BaseNode {
constructor() {

@@ -45,4 +47,30 @@ super(...arguments);

})));
this.commands = (nodeType) => ({
[SupportedKeys.H1]: {
defaultKey: 'Mod-Alt-1',
command: setBlockType(nodeType, { level: 1 }),
},
[SupportedKeys.H2]: {
defaultKey: 'Mod-Alt-2',
command: setBlockType(nodeType, { level: 2 }),
},
[SupportedKeys.H3]: {
defaultKey: 'Mod-Alt-3',
command: setBlockType(nodeType, { level: 3 }),
},
[SupportedKeys.H4]: {
defaultKey: 'Mod-Alt-4',
command: setBlockType(nodeType, { level: 4 }),
},
[SupportedKeys.H5]: {
defaultKey: 'Mod-Alt-5',
command: setBlockType(nodeType, { level: 5 }),
},
[SupportedKeys.H6]: {
defaultKey: 'Mod-Alt-6',
command: setBlockType(nodeType, { level: 6 }),
},
});
}
}
//# sourceMappingURL=heading.js.map

@@ -1,6 +0,6 @@

import type { NodeSpec, NodeType } from 'prosemirror-model';
import type { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import { InputRule } from 'prosemirror-inputrules';
import { CommonNode } from '../utility';
export declare class Hr extends CommonNode {
import type { NodeSpec, NodeType } from 'prosemirror-model';
import { BaseNode } from '../utility';
export declare class Hr extends BaseNode {
readonly id = "hr";

@@ -7,0 +7,0 @@ readonly schema: NodeSpec;

import { InputRule } from 'prosemirror-inputrules';
import { CommonNode } from '../utility';
export class Hr extends CommonNode {
import { BaseNode } from '../utility';
export class Hr extends BaseNode {
constructor() {

@@ -5,0 +5,0 @@ super(...arguments);

@@ -0,6 +1,6 @@

import type { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import { InputRule } from 'prosemirror-inputrules';
import type { NodeSpec, NodeType } from 'prosemirror-model';
import { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import { InputRule } from 'prosemirror-inputrules';
import { CommonNode } from '../utility';
export declare class Image extends CommonNode {
import { BaseNode } from '../utility';
export declare class Image extends BaseNode {
readonly id = "image";

@@ -7,0 +7,0 @@ readonly schema: NodeSpec;

import { InputRule } from 'prosemirror-inputrules';
import { CommonNode } from '../utility';
export class Image extends CommonNode {
import { BaseNode } from '../utility';
export class Image extends BaseNode {
constructor() {

@@ -5,0 +5,0 @@ super(...arguments);

@@ -1,6 +0,7 @@

import type { NodeType, NodeSpec } from 'prosemirror-model';
import type { Keymap } from 'prosemirror-commands';
import { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import { CommonNode } from '../utility';
export declare class ListItem extends CommonNode {
import type { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import type { NodeSpec } from 'prosemirror-model';
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
declare type Keys = SupportedKeys.SinkListItem | SupportedKeys.LiftListItem | SupportedKeys.NextListItem;
export declare class ListItem extends BaseNode<Keys> {
readonly id = "list_item";

@@ -10,4 +11,5 @@ readonly schema: NodeSpec;

readonly serializer: NodeSerializerSpec;
readonly keymap: (type: NodeType) => Keymap;
readonly commands: BaseNode<Keys>['commands'];
}
export {};
//# sourceMappingURL=list-item.d.ts.map
import { liftListItem, sinkListItem, splitListItem } from 'prosemirror-schema-list';
import { CommonNode } from '../utility';
export class ListItem extends CommonNode {
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
export class ListItem extends BaseNode {
constructor() {

@@ -29,6 +30,15 @@ super(...arguments);

};
this.keymap = (type) => ({
Enter: splitListItem(type),
'Mod-]': sinkListItem(type),
'Mod-[': liftListItem(type),
this.commands = (nodeType) => ({
[SupportedKeys.NextListItem]: {
defaultKey: 'Enter',
command: splitListItem(nodeType),
},
[SupportedKeys.SinkListItem]: {
defaultKey: 'Mod-]',
command: sinkListItem(nodeType),
},
[SupportedKeys.LiftListItem]: {
defaultKey: 'Mod-[',
command: liftListItem(nodeType),
},
});

@@ -35,0 +45,0 @@ }

@@ -0,5 +1,7 @@

import type { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import type { NodeSpec, NodeType } from 'prosemirror-model';
import { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import { CommonNode } from '../utility/base';
export declare class OrderedList extends CommonNode {
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
declare type Keys = SupportedKeys.OrderedList;
export declare class OrderedList extends BaseNode<Keys> {
readonly id = "ordered_list";

@@ -10,3 +12,5 @@ readonly schema: NodeSpec;

readonly inputRules: (nodeType: NodeType) => import("prosemirror-inputrules").InputRule<any>[];
readonly commands: BaseNode<Keys>['commands'];
}
export {};
//# sourceMappingURL=ordered-list.d.ts.map

@@ -0,4 +1,6 @@

import { wrapIn } from 'prosemirror-commands';
import { wrappingInputRule } from 'prosemirror-inputrules';
import { CommonNode } from '../utility/base';
export class OrderedList extends CommonNode {
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
export class OrderedList extends BaseNode {
constructor() {

@@ -51,4 +53,10 @@ super(...arguments);

];
this.commands = (nodeType) => ({
[SupportedKeys.OrderedList]: {
defaultKey: 'Mod-Shift-7',
command: wrapIn(nodeType),
},
});
}
}
//# sourceMappingURL=ordered-list.js.map

@@ -0,5 +1,7 @@

import type { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import type { NodeSpec } from 'prosemirror-model';
import { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import { CommonNode } from '../utility/base';
export declare class Paragraph extends CommonNode {
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
declare type Keys = SupportedKeys.Text;
export declare class Paragraph extends BaseNode<Keys> {
readonly id = "paragraph";

@@ -9,3 +11,5 @@ readonly schema: NodeSpec;

readonly serializer: NodeSerializerSpec;
readonly commands: BaseNode<Keys>['commands'];
}
export {};
//# sourceMappingURL=paragraph.d.ts.map

@@ -1,3 +0,5 @@

import { CommonNode } from '../utility/base';
export class Paragraph extends CommonNode {
import { setBlockType } from 'prosemirror-commands';
import { SupportedKeys } from '../supported-keys';
import { BaseNode } from '../utility';
export class Paragraph extends BaseNode {
constructor() {

@@ -33,4 +35,10 @@ super(...arguments);

};
this.commands = (nodeType) => ({
[SupportedKeys.Text]: {
defaultKey: 'Mod-Alt-0',
command: setBlockType(nodeType),
},
});
}
}
//# sourceMappingURL=paragraph.js.map

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

import type { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import type { NodeSpec } from 'prosemirror-model';
import { NodeParserSpec, NodeSerializerSpec } from '@milkdown/core';
import { CommonNode } from '../utility/base';
export declare class Text extends CommonNode {
import { BaseNode } from '../utility';
export declare class Text extends BaseNode {
readonly id = "text";

@@ -6,0 +6,0 @@ readonly schema: NodeSpec;

@@ -1,3 +0,3 @@

import { CommonNode } from '../utility/base';
export class Text extends CommonNode {
import { BaseNode } from '../utility';
export class Text extends BaseNode {
constructor() {

@@ -4,0 +4,0 @@ super(...arguments);

import { Node, Mark, NodeViewFactory, MarkViewFactory } from '@milkdown/core';
import { NodeType, MarkType } from 'prosemirror-model';
import { Command, Keymap } from 'prosemirror-commands';
import { AnyRecord } from './types';
declare type CommonOptions = {
declare type Empty = Record<string, unknown>;
declare type CommonOptions<SupportedKeys extends string> = {
className?: (attrs: AnyRecord) => string;
keymap?: Partial<Record<SupportedKeys, string | string[]>>;
};
declare type CommandValue = {
command: Command;
defaultKey: string;
};
declare type Commands<T extends string> = Record<T, CommandValue>;
interface NodeOptional<T extends string> {
readonly commands?: (nodeType: NodeType) => Commands<T>;
}
interface MarkOptional<T extends string> {
readonly commands?: (nodeType: MarkType) => Commands<T>;
}
declare type NodeOptions = {
view?: NodeViewFactory;
readonly view?: NodeViewFactory;
};
declare type MarkOptions = {
view?: MarkViewFactory;
readonly view?: MarkViewFactory;
};
export declare abstract class CommonNode<Options = Record<string, unknown>> extends Node<Options & CommonOptions & NodeOptions> {
export declare abstract class BaseNode<SupportedKeys extends string = string, Options = Empty> extends Node<Options & CommonOptions<SupportedKeys> & NodeOptions> implements NodeOptional<SupportedKeys> {
commands?: NodeOptional<SupportedKeys>['commands'];
readonly keymap: (nodeType: NodeType) => Keymap;
protected getKeymap(key: SupportedKeys, defaultKey: string, command: Command): Record<string, Command>;
protected getClassName(attrs: AnyRecord, defaultValue?: string): string;
readonly view?: NodeViewFactory;
}
export declare abstract class CommonMark<Options = Record<string, unknown>> extends Mark<Options & CommonOptions & MarkOptions> {
export declare abstract class BaseMark<SupportedKeys extends string = never, Options = Empty> extends Mark<Options & CommonOptions<SupportedKeys> & MarkOptions> implements MarkOptional<SupportedKeys> {
commands?: MarkOptional<SupportedKeys>['commands'];
protected getClassName(attrs: AnyRecord, defaultValue?: string): string;
readonly view?: MarkViewFactory;
readonly keymap: (markType: MarkType) => Keymap;
protected getKeymap(key: SupportedKeys, defaultKey: string, command: Command): Record<string, Command>;
}
export {};
//# sourceMappingURL=base.d.ts.map
import { Node, Mark } from '@milkdown/core';
export class CommonNode extends Node {
export class BaseNode extends Node {
constructor() {
super(...arguments);
this.keymap = (nodeType) => {
const { commands } = this;
if (!commands)
return {};
const map = commands(nodeType);
const entries = Object.entries(map);
return entries.reduce((acc, [key, { command, defaultKey }]) => (Object.assign(Object.assign({}, acc), this.getKeymap(key, defaultKey, command))), {});
};
this.view = this.options.view;
}
getKeymap(key, defaultKey, command) {
const { keymap } = this.options;
if (!keymap)
return { [defaultKey]: command };
const value = keymap[key];
if (!value)
return { [defaultKey]: command };
if (Array.isArray(value)) {
return value.reduce((acc, cur) => (Object.assign(Object.assign({}, acc), { [cur]: command })), {});
}
return { [value]: command };
}
getClassName(attrs, defaultValue = this.id) {

@@ -12,6 +32,14 @@ var _a, _b, _c;

}
export class CommonMark extends Mark {
export class BaseMark extends Mark {
constructor() {
super(...arguments);
this.view = this.options.view;
this.keymap = (markType) => {
const { commands } = this;
if (!commands)
return {};
const map = commands(markType);
const entries = Object.entries(map);
return entries.reduce((acc, [key, { command, defaultKey }]) => (Object.assign(Object.assign({}, acc), this.getKeymap(key, defaultKey, command))), {});
};
}

@@ -22,3 +50,15 @@ getClassName(attrs, defaultValue = this.id) {

}
getKeymap(key, defaultKey, command) {
const { keymap } = this.options;
if (!keymap)
return { [defaultKey]: command };
const value = keymap[key];
if (!value)
return { [defaultKey]: command };
if (Array.isArray(value)) {
return value.reduce((acc, cur) => (Object.assign(Object.assign({}, acc), { [cur]: command })), {});
}
return { [value]: command };
}
}
//# sourceMappingURL=base.js.map
{
"name": "@milkdown/preset-commonmark",
"version": "4.5.1",
"version": "4.5.2",
"main": "lib/index.js",

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

"devDependencies": {
"@milkdown/core": "4.5.1"
"@milkdown/core": "4.5.2"
},

@@ -32,0 +32,0 @@ "scripts": {

@@ -18,1 +18,55 @@ # @milkdown/preset-commonmark

```
## Custom Keymap
```typescript
import { commonmark, Blockquote, SupportedKeys } from '@milkdown/preset-commonmark';
const nodes = commonmark
.configure(Blockquote, {
keymap: {
[SupportedKeys.Blockquote]: 'Mod-Shift-b',
},
});
new Editor({ ... }).use(nodes);
```
Keymap supported:
- HardBreak
- Blockquote
- BulletList
- OrderedList
- CodeFence
- H1
- H2
- H3
- H4
- H5
- H6
- Text
- CodeInline
- Em
- Bold
- NextListItem
- SinkListItem
- LiftListItem
## Custom Style
```typescript
import { commonmark, Paragraph, Heading } from '@milkdown/commonmark';
const nodes = commonmark
.configure(Paragraph, {
className: () =>
'my-custom-paragraph'
})
.configure(Heading, {
className: (attrs) =>
`my-custom-heading my-h${attrs.level}`
})
new Editor({ ... }).use(nodes);
```

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

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