@milkdown/preset-commonmark 7.3.1 → 7.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/lib/__internal__/serialize-text.d.ts +1 -1
  2. package/lib/__internal__/serialize-text.d.ts.map +1 -1
  3. package/lib/__internal__/with-meta.d.ts +1 -1
  4. package/lib/__internal__/with-meta.d.ts.map +1 -1
  5. package/lib/composed/plugins.d.ts.map +1 -1
  6. package/lib/composed/schema.d.ts.map +1 -1
  7. package/lib/index.es.js +74 -33
  8. package/lib/index.es.js.map +1 -1
  9. package/lib/mark/link.d.ts +2 -2
  10. package/lib/mark/link.d.ts.map +1 -1
  11. package/lib/node/heading.d.ts +3 -1
  12. package/lib/node/heading.d.ts.map +1 -1
  13. package/lib/node/hr.d.ts.map +1 -1
  14. package/lib/node/image.d.ts +2 -2
  15. package/lib/node/image.d.ts.map +1 -1
  16. package/lib/node/list-item.d.ts.map +1 -1
  17. package/lib/plugin/inline-sync-plugin/context.d.ts +1 -1
  18. package/lib/plugin/inline-sync-plugin/context.d.ts.map +1 -1
  19. package/lib/plugin/inline-sync-plugin/regexp.d.ts +1 -1
  20. package/lib/plugin/inline-sync-plugin/regexp.d.ts.map +1 -1
  21. package/lib/plugin/inline-sync-plugin/replacer.d.ts +1 -1
  22. package/lib/plugin/inline-sync-plugin/replacer.d.ts.map +1 -1
  23. package/lib/plugin/inline-sync-plugin/utils.d.ts +6 -6
  24. package/lib/plugin/inline-sync-plugin/utils.d.ts.map +1 -1
  25. package/package.json +7 -7
  26. package/src/__internal__/serialize-text.ts +1 -1
  27. package/src/__internal__/with-meta.ts +1 -4
  28. package/src/composed/plugins.ts +2 -1
  29. package/src/composed/schema.ts +2 -1
  30. package/src/mark/link.ts +1 -1
  31. package/src/node/code-block.ts +1 -1
  32. package/src/node/heading.ts +3 -2
  33. package/src/node/hr.ts +2 -1
  34. package/src/node/image.ts +1 -1
  35. package/src/node/list-item.ts +24 -22
  36. package/src/plugin/hardbreak-clear-mark-plugin.ts +1 -1
  37. package/src/plugin/inline-sync-plugin/config.ts +5 -5
  38. package/src/plugin/inline-sync-plugin/context.ts +7 -7
  39. package/src/plugin/inline-sync-plugin/regexp.ts +3 -2
  40. package/src/plugin/inline-sync-plugin/replacer.ts +1 -7
  41. package/src/plugin/inline-sync-plugin/utils.ts +24 -20
  42. package/src/plugin/remark-html-transformer.ts +1 -1
@@ -1,9 +1,9 @@
1
1
  export declare const linkAttr: import("@milkdown/utils").$MarkAttr;
2
2
  export declare const linkSchema: import("@milkdown/utils").$MarkSchema<"link">;
3
- export type UpdateLinkCommandPayload = {
3
+ export interface UpdateLinkCommandPayload {
4
4
  href?: string;
5
5
  title?: string;
6
- };
6
+ }
7
7
  export declare const toggleLinkCommand: import("@milkdown/utils").$Command<UpdateLinkCommandPayload>;
8
8
  export declare const updateLinkCommand: import("@milkdown/utils").$Command<UpdateLinkCommandPayload>;
9
9
  //# sourceMappingURL=link.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/mark/link.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,QAAQ,qCAAoB,CAAA;AAQzC,eAAO,MAAM,UAAU,+CAoCpB,CAAA;AAQH,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAGD,eAAO,MAAM,iBAAiB,8DAAuH,CAAA;AASrJ,eAAO,MAAM,iBAAiB,8DAyC5B,CAAA"}
1
+ {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/mark/link.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,QAAQ,qCAAoB,CAAA;AAQzC,eAAO,MAAM,UAAU,+CAoCpB,CAAA;AAQH,MAAM,WAAW,wBAAwB;IACvC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAGD,eAAO,MAAM,iBAAiB,8DAAuH,CAAA;AASrJ,eAAO,MAAM,iBAAiB,8DAyC5B,CAAA"}
@@ -1,9 +1,11 @@
1
1
  import type { Node } from '@milkdown/prose/model';
2
- export declare const headingIdGenerator: import("@milkdown/utils").$Ctx<(node: Node) => string, "headingIdGenerator">;
2
+ declare function defaultHeadingIdGenerator(node: Node): string;
3
+ export declare const headingIdGenerator: import("@milkdown/utils").$Ctx<typeof defaultHeadingIdGenerator, "headingIdGenerator">;
3
4
  export declare const headingAttr: import("@milkdown/utils").$NodeAttr;
4
5
  export declare const headingSchema: import("@milkdown/utils").$NodeSchema<"heading">;
5
6
  export declare const wrapInHeadingInputRule: import("@milkdown/utils").$InputRule;
6
7
  export declare const wrapInHeadingCommand: import("@milkdown/utils").$Command<number>;
7
8
  export declare const downgradeHeadingCommand: import("@milkdown/utils").$Command<unknown>;
8
9
  export declare const headingKeymap: import("@milkdown/utils").$UserKeymap<"headingKeymap", "DowngradeHeading" | "TurnIntoH1" | "TurnIntoH2" | "TurnIntoH3" | "TurnIntoH4" | "TurnIntoH5" | "TurnIntoH6">;
10
+ export {};
9
11
  //# sourceMappingURL=heading.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../src/node/heading.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAejD,eAAO,MAAM,kBAAkB,wCALU,IAAI,kCAK0C,CAAA;AAQvF,eAAO,MAAM,WAAW,qCAAuB,CAAA;AAQ/C,eAAO,MAAM,aAAa,kDAmDxB,CAAA;AAcF,eAAO,MAAM,sBAAsB,sCAgBjC,CAAA;AAUF,eAAO,MAAM,oBAAoB,4CAS/B,CAAA;AAUF,eAAO,MAAM,uBAAuB,6CAkBhC,CAAA;AAUJ,eAAO,MAAM,aAAa,sKAkDxB,CAAA"}
1
+ {"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../src/node/heading.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAUjD,iBAAS,yBAAyB,CAAC,IAAI,EAAE,IAAI,UAE5C;AAID,eAAO,MAAM,kBAAkB,wFAAwD,CAAA;AAQvF,eAAO,MAAM,WAAW,qCAAuB,CAAA;AAQ/C,eAAO,MAAM,aAAa,kDAmDxB,CAAA;AAcF,eAAO,MAAM,sBAAsB,sCAgBjC,CAAA;AAUF,eAAO,MAAM,oBAAoB,4CAS/B,CAAA;AAUF,eAAO,MAAM,uBAAuB,6CAkBhC,CAAA;AAUJ,eAAO,MAAM,aAAa,sKAkDxB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"hr.d.ts","sourceRoot":"","sources":["../../src/node/hr.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,MAAM,qCAAkB,CAAA;AAQrC,eAAO,MAAM,QAAQ,6CAgBlB,CAAA;AAcH,eAAO,MAAM,iBAAiB,sCAS5B,CAAA;AAQF,eAAO,MAAM,eAAe,6CAkB1B,CAAA"}
1
+ {"version":3,"file":"hr.d.ts","sourceRoot":"","sources":["../../src/node/hr.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,MAAM,qCAAkB,CAAA;AAQrC,eAAO,MAAM,QAAQ,6CAgBlB,CAAA;AAcH,eAAO,MAAM,iBAAiB,sCAU5B,CAAA;AAQF,eAAO,MAAM,eAAe,6CAkB1B,CAAA"}
@@ -1,10 +1,10 @@
1
1
  export declare const imageAttr: import("@milkdown/utils").$NodeAttr;
2
2
  export declare const imageSchema: import("@milkdown/utils").$NodeSchema<"image">;
3
- export type UpdateImageCommandPayload = {
3
+ export interface UpdateImageCommandPayload {
4
4
  src?: string;
5
5
  title?: string;
6
6
  alt?: string;
7
- };
7
+ }
8
8
  export declare const insertImageCommand: import("@milkdown/utils").$Command<UpdateImageCommandPayload>;
9
9
  export declare const updateImageCommand: import("@milkdown/utils").$Command<UpdateImageCommandPayload>;
10
10
  export declare const insertImageInputRule: import("@milkdown/utils").$InputRule;
@@ -1 +1 @@
1
- {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/node/image.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,SAAS,qCAAqB,CAAA;AAQ3C,eAAO,MAAM,WAAW,gDAyDtB,CAAA;AAaF,MAAM,MAAM,yBAAyB,GAAG;IACtC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAID,eAAO,MAAM,kBAAkB,+DAa3B,CAAA;AASJ,eAAO,MAAM,kBAAkB,+DAkB7B,CAAA;AAUF,eAAO,MAAM,oBAAoB,sCAS/B,CAAA"}
1
+ {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/node/image.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,SAAS,qCAAqB,CAAA;AAQ3C,eAAO,MAAM,WAAW,gDAyDtB,CAAA;AAaF,MAAM,WAAW,yBAAyB;IACxC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAID,eAAO,MAAM,kBAAkB,+DAa3B,CAAA;AASJ,eAAO,MAAM,kBAAkB,+DAkB7B,CAAA;AAUF,eAAO,MAAM,oBAAoB,sCAS/B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["../../src/node/list-item.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,YAAY,qCAAwB,CAAA;AAQjD,eAAO,MAAM,cAAc,oDA2DxB,CAAA;AAwBH,eAAO,MAAM,mBAAmB,6CAAgF,CAAA;AAmBhH,eAAO,MAAM,mBAAmB,6CAAiF,CAAA;AAoBjH,eAAO,MAAM,oBAAoB,6CAAkF,CAAA;AAqCnH,eAAO,MAAM,wBAAwB,6CAAqE,CAAA;AAW1G,eAAO,MAAM,cAAc,iIA6BzB,CAAA"}
1
+ {"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["../../src/node/list-item.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,YAAY,qCAAwB,CAAA;AAQjD,eAAO,MAAM,cAAc,oDA2DxB,CAAA;AAwBH,eAAO,MAAM,mBAAmB,6CAAgF,CAAA;AAmBhH,eAAO,MAAM,mBAAmB,6CAAiF,CAAA;AAoBjH,eAAO,MAAM,oBAAoB,6CAAkF,CAAA;AAuCnH,eAAO,MAAM,wBAAwB,6CAAqE,CAAA;AAW1G,eAAO,MAAM,cAAc,iIA6BzB,CAAA"}
@@ -7,5 +7,5 @@ export interface InlineSyncContext {
7
7
  nextNode: Node;
8
8
  placeholder: string;
9
9
  }
10
- export declare const getContextByState: (ctx: Ctx, state: EditorState) => InlineSyncContext | null;
10
+ export declare function getContextByState(ctx: Ctx, state: EditorState): InlineSyncContext | null;
11
11
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAOxD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,IAAI,CAAA;IACd,QAAQ,EAAE,IAAI,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAiED,eAAO,MAAM,iBAAiB,QAAS,GAAG,SAAS,WAAW,KAAG,iBAAiB,GAAG,IAuCpF,CAAA"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAOxD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,IAAI,CAAA;IACd,QAAQ,EAAE,IAAI,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAiED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,GAAG,iBAAiB,GAAG,IAAI,CAuCxF"}
@@ -1,6 +1,6 @@
1
1
  export declare const linkRegexp: RegExp;
2
2
  export declare const keepLinkRegexp: RegExp;
3
- export declare const punctuationRegexp: (holePlaceholder: string) => RegExp;
3
+ export declare function punctuationRegexp(holePlaceholder: string): RegExp;
4
4
  export declare const ZERO_WIDTH_SPACE = "\u200B";
5
5
  export declare const asterisk: string;
6
6
  export declare const asteriskHolder: string;
@@ -1 +1 @@
1
- {"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/regexp.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAA4B,CAAA;AAEnD,eAAO,MAAM,cAAc,QAAyE,CAAA;AAEpG,eAAO,MAAM,iBAAiB,oBAAqB,MAAM,WACK,CAAA;AAE9D,eAAO,MAAM,gBAAgB,WAAW,CAAA;AAExC,eAAO,MAAM,QAAQ,QAAyB,CAAA;AAC9C,eAAO,MAAM,cAAc,QAAyB,CAAA;AACpD,eAAO,MAAM,SAAS,QAAyB,CAAA;AAC/C,eAAO,MAAM,eAAe,QAAyB,CAAA"}
1
+ {"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/regexp.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAA4B,CAAA;AAEnD,eAAO,MAAM,cAAc,QAAyE,CAAA;AAEpG,wBAAgB,iBAAiB,CAAC,eAAe,EAAE,MAAM,UAExD;AAED,eAAO,MAAM,gBAAgB,WAAW,CAAA;AAExC,eAAO,MAAM,QAAQ,QAAyB,CAAA;AAC9C,eAAO,MAAM,cAAc,QAAyB,CAAA;AACpD,eAAO,MAAM,SAAS,QAAyB,CAAA;AAC/C,eAAO,MAAM,eAAe,QAAyB,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import type { Ctx } from '@milkdown/ctx';
2
2
  import type { Attrs } from '@milkdown/prose/model';
3
3
  import type { EditorState, PluginKey, Transaction } from '@milkdown/prose/state';
4
- export declare const runReplacer: (ctx: Ctx, key: PluginKey, state: EditorState, dispatch: (tr: Transaction) => void, attrs: Attrs) => void;
4
+ export declare function runReplacer(ctx: Ctx, key: PluginKey, state: EditorState, dispatch: (tr: Transaction) => void, attrs: Attrs): void;
5
5
  //# sourceMappingURL=replacer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"replacer.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/replacer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAQhF,eAAO,MAAM,WAAW,QACjB,GAAG,OACH,SAAS,SACP,WAAW,iBACH,WAAW,KAAK,IAAI,SAC5B,KAAK,SAuCb,CAAA"}
1
+ {"version":3,"file":"replacer.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/replacer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAQhF,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,IAAI,EAAE,KAAK,EAAE,KAAK,QAsC1H"}
@@ -1,9 +1,9 @@
1
1
  import type { Node } from '@milkdown/prose/model';
2
2
  import type { SyncNodePlaceholder } from './config';
3
- export declare const keepLink: (str: string) => string;
4
- export declare const mergeSlash: (str: string) => string;
5
- export declare const swap: (text: string, first: number, last: number) => string;
6
- export declare const replacePunctuation: (holePlaceholder: string) => (text: string) => string;
7
- export declare const calculatePlaceholder: (placeholder: SyncNodePlaceholder) => (text: string) => string;
8
- export declare const calcOffset: (node: Node, from: number, placeholder: string) => number;
3
+ export declare function keepLink(str: string): string;
4
+ export declare function mergeSlash(str: string): string;
5
+ export declare function swap(text: string, first: number, last: number): string;
6
+ export declare function replacePunctuation(holePlaceholder: string): (text: string) => string;
7
+ export declare function calculatePlaceholder(placeholder: SyncNodePlaceholder): (text: string) => string;
8
+ export declare function calcOffset(node: Node, from: number, placeholder: string): number;
9
9
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAUnD,eAAO,MAAM,QAAQ,QAAS,MAAM,WAUnC,CAAA;AAED,eAAO,MAAM,UAAU,QAAS,MAAM,WAMrC,CAAA;AAED,eAAO,MAAM,IAAI,SAAU,MAAM,SAAS,MAAM,QAAQ,MAAM,WAQ7D,CAAA;AAED,eAAO,MAAM,kBAAkB,oBAAqB,MAAM,YAAY,MAAM,WACtB,CAAA;AAEtD,eAAO,MAAM,oBAAoB,gBAAiB,mBAAmB,YAAY,MAAM,WAkBtF,CAAA;AAED,eAAO,MAAM,UAAU,SAAU,IAAI,QAAQ,MAAM,eAAe,MAAM,WAwBvE,CAAA"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAUnD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,UAUnC;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,UAMrC;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAQ7D;AAED,wBAAgB,kBAAkB,CAAC,eAAe,EAAE,MAAM,UAC1C,MAAM,YAErB;AAED,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,mBAAmB,UACrD,MAAM,YAmBrB;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,UAwBvE"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@milkdown/preset-commonmark",
3
3
  "type": "module",
4
- "version": "7.3.1",
4
+ "version": "7.3.2",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -32,14 +32,14 @@
32
32
  "remark-inline-links": "^7.0.0",
33
33
  "tslib": "^2.5.0",
34
34
  "unist-util-visit": "^5.0.0",
35
- "@milkdown/exception": "7.3.1",
36
- "@milkdown/utils": "7.3.1"
35
+ "@milkdown/exception": "7.3.2",
36
+ "@milkdown/utils": "7.3.2"
37
37
  },
38
38
  "devDependencies": {
39
- "@milkdown/core": "7.3.1",
40
- "@milkdown/ctx": "7.3.1",
41
- "@milkdown/prose": "7.3.1",
42
- "@milkdown/transformer": "7.3.1"
39
+ "@milkdown/core": "7.3.2",
40
+ "@milkdown/ctx": "7.3.2",
41
+ "@milkdown/prose": "7.3.2",
42
+ "@milkdown/transformer": "7.3.2"
43
43
  },
44
44
  "nx": {
45
45
  "targets": {
@@ -3,7 +3,7 @@ import type { SerializerState } from '@milkdown/transformer'
3
3
  import type { Node } from '@milkdown/prose/model'
4
4
  import { Fragment } from '@milkdown/prose/model'
5
5
 
6
- export const serializeText = (state: SerializerState, node: Node) => {
6
+ export function serializeText(state: SerializerState, node: Node) {
7
7
  const lastIsHardBreak
8
8
  = node.childCount >= 1 && node.lastChild?.type.name === 'hardbreak'
9
9
  if (!lastIsHardBreak) {
@@ -1,10 +1,7 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import type { Meta, MilkdownPlugin } from '@milkdown/ctx'
3
3
 
4
- export const withMeta = <T extends MilkdownPlugin>(
5
- plugin: T,
6
- meta: Partial<Meta> & Pick<Meta, 'displayName'>,
7
- ): T => {
4
+ export function withMeta<T extends MilkdownPlugin>(plugin: T, meta: Partial<Meta> & Pick<Meta, 'displayName'>): T {
8
5
  Object.assign(plugin, {
9
6
  meta: {
10
7
  package: '@milkdown/preset-commonmark',
@@ -11,7 +11,8 @@ import {
11
11
  remarkAddOrderInListPlugin,
12
12
  remarkHtmlTransformer,
13
13
  remarkInlineLinkPlugin,
14
- remarkLineBreak, remarkMarker,
14
+ remarkLineBreak,
15
+ remarkMarker,
15
16
  syncHeadingIdPlugin,
16
17
  syncListOrderPlugin,
17
18
  } from '../plugin'
@@ -16,7 +16,8 @@ import {
16
16
  headingIdGenerator,
17
17
  headingSchema,
18
18
  hrAttr,
19
- hrSchema, htmlAttr,
19
+ hrSchema,
20
+ htmlAttr,
20
21
  htmlSchema,
21
22
  imageAttr,
22
23
  imageSchema,
package/src/mark/link.ts CHANGED
@@ -59,7 +59,7 @@ withMeta(linkSchema.mark, {
59
59
  })
60
60
 
61
61
  /// @internal
62
- export type UpdateLinkCommandPayload = {
62
+ export interface UpdateLinkCommandPayload {
63
63
  href?: string
64
64
  title?: string
65
65
  }
@@ -107,7 +107,7 @@ withMeta(createCodeBlockCommand, {
107
107
  })
108
108
 
109
109
  /// A command for updating the code block language of the target position.
110
- export const updateCodeBlockLanguageCommand = $command('UpdateCodeBlockLanguage', () => ({ pos, language }: { pos: number; language: string } = { pos: -1, language: '' }) => (state, dispatch) => {
110
+ export const updateCodeBlockLanguageCommand = $command('UpdateCodeBlockLanguage', () => ({ pos, language }: { pos: number, language: string } = { pos: -1, language: '' }) => (state, dispatch) => {
111
111
  if (pos >= 0) {
112
112
  dispatch?.(state.tr.setNodeAttribute(pos, 'language', language))
113
113
  return true
@@ -13,8 +13,9 @@ const headingIndex = Array(6)
13
13
  .fill(0)
14
14
  .map((_, i) => i + 1)
15
15
 
16
- const defaultHeadingIdGenerator = (node: Node) =>
17
- slugify(node.textContent)
16
+ function defaultHeadingIdGenerator(node: Node) {
17
+ return slugify(node.textContent)
18
+ }
18
19
 
19
20
  /// This is a slice contains a function to generate heading id.
20
21
  /// You can configure it to generate id in your own way.
package/src/node/hr.ts CHANGED
@@ -45,7 +45,8 @@ withMeta(hrSchema.ctx, {
45
45
  /// Input rule to insert a hr.
46
46
  /// For example, `---` will be converted to a hr.
47
47
  export const insertHrInputRule = $inputRule(ctx => new InputRule(
48
- /^(?:---|___\s|\*\*\*\s)$/, (state, match, start, end) => {
48
+ /^(?:---|___\s|\*\*\*\s)$/,
49
+ (state, match, start, end) => {
49
50
  const { tr } = state
50
51
 
51
52
  if (match[0])
package/src/node/image.ts CHANGED
@@ -84,7 +84,7 @@ withMeta(imageSchema.ctx, {
84
84
  })
85
85
 
86
86
  /// @internal
87
- export type UpdateImageCommandPayload = {
87
+ export interface UpdateImageCommandPayload {
88
88
  src?: string
89
89
  title?: string
90
90
  alt?: string
@@ -145,28 +145,30 @@ withMeta(splitListItemCommand, {
145
145
  group: 'ListItem',
146
146
  })
147
147
 
148
- const liftFirstListItem = (ctx: Ctx): Command => (state, dispatch, view) => {
149
- const { selection } = state
150
- if (!(selection instanceof TextSelection))
151
- return false
152
-
153
- const { empty, $from } = selection
154
-
155
- // selection should be empty and at the start of the node
156
- if (!empty || $from.parentOffset !== 0)
157
- return false
158
-
159
- const parentItem = $from.node(-1)
160
- // selection should be in list item and list item should be the first child of the list
161
- if (parentItem.type !== listItemSchema.type(ctx) || parentItem.firstChild !== $from.node())
162
- return false
163
-
164
- const list = $from.node(-2)
165
- // list should have only one list item
166
- if (list.childCount > 1)
167
- return false
168
-
169
- return liftListItem(listItemSchema.type(ctx))(state, dispatch, view)
148
+ function liftFirstListItem(ctx: Ctx): Command {
149
+ return (state, dispatch, view) => {
150
+ const { selection } = state
151
+ if (!(selection instanceof TextSelection))
152
+ return false
153
+
154
+ const { empty, $from } = selection
155
+
156
+ // selection should be empty and at the start of the node
157
+ if (!empty || $from.parentOffset !== 0)
158
+ return false
159
+
160
+ const parentItem = $from.node(-1)
161
+ // selection should be in list item and list item should be the first child of the list
162
+ if (parentItem.type !== listItemSchema.type(ctx) || parentItem.firstChild !== $from.node())
163
+ return false
164
+
165
+ const list = $from.node(-2)
166
+ // list should have only one list item
167
+ if (list.childCount > 1)
168
+ return false
169
+
170
+ return liftListItem(listItemSchema.type(ctx))(state, dispatch, view)
171
+ }
170
172
  }
171
173
 
172
174
  /// The command to remove list item **only if**:
@@ -31,7 +31,7 @@ export const hardbreakClearMarkPlugin = $prose((ctx) => {
31
31
  const isAddMarkStep = step instanceof AddMarkStep
32
32
  if (isAddMarkStep) {
33
33
  let _tr = newState.tr
34
- const { from, to } = step as unknown as { from: number; to: number }
34
+ const { from, to } = step as unknown as { from: number, to: number }
35
35
  newState.doc.nodesBetween(from, to, (node, pos) => {
36
36
  if (node.type === hardbreakSchema.type(ctx))
37
37
  _tr = _tr.setNodeMarkup(pos, hardbreakSchema.type(ctx), undefined, [])
@@ -41,11 +41,11 @@ export const defaultConfig: InlineSyncConfig = {
41
41
  globalNodes: ['footnote_definition'],
42
42
  shouldSyncNode: ({ prevNode, nextNode }) =>
43
43
  prevNode.inlineContent
44
- && nextNode
45
- // if node type changes, do not sync
46
- && prevNode.type === nextNode.type
47
- // if two node fully equal, we don't modify them
48
- && !prevNode.eq(nextNode),
44
+ && nextNode
45
+ // if node type changes, do not sync
46
+ && prevNode.type === nextNode.type
47
+ // if two node fully equal, we don't modify them
48
+ && !prevNode.eq(nextNode),
49
49
  movePlaceholder: (placeholderToMove: string, text: string) => {
50
50
  const symbolsNeedToMove = ['*', '_']
51
51
 
@@ -16,18 +16,18 @@ export interface InlineSyncContext {
16
16
  placeholder: string
17
17
  }
18
18
 
19
- const getNodeFromSelection = (state: EditorState) => {
19
+ function getNodeFromSelection(state: EditorState) {
20
20
  return state.selection.$from.node()
21
21
  }
22
22
 
23
- const getMarkdown = (ctx: Ctx, state: EditorState, node: Node, globalNode: Node[]) => {
23
+ function getMarkdown(ctx: Ctx, state: EditorState, node: Node, globalNode: Node[]) {
24
24
  const serializer = ctx.get(serializerCtx)
25
25
  const doc = state.schema.topNodeType.create(undefined, [node, ...globalNode])
26
26
 
27
27
  return serializer(doc)
28
28
  }
29
29
 
30
- const addPlaceholder = (ctx: Ctx, markdown: string) => {
30
+ function addPlaceholder(ctx: Ctx, markdown: string) {
31
31
  const config = ctx.get(inlineSyncConfig.key)
32
32
  const holePlaceholder = config.placeholderConfig.hole
33
33
 
@@ -47,7 +47,7 @@ const addPlaceholder = (ctx: Ctx, markdown: string) => {
47
47
  return [text, placeholder] as [markdown: string, placeholder: string]
48
48
  }
49
49
 
50
- const getNewNode = (ctx: Ctx, text: string) => {
50
+ function getNewNode(ctx: Ctx, text: string) {
51
51
  const parser = ctx.get(parserCtx)
52
52
  const parsed = parser(text)
53
53
 
@@ -57,7 +57,7 @@ const getNewNode = (ctx: Ctx, text: string) => {
57
57
  return parsed.firstChild
58
58
  }
59
59
 
60
- const collectGlobalNodes = (ctx: Ctx, state: EditorState) => {
60
+ function collectGlobalNodes(ctx: Ctx, state: EditorState) {
61
61
  const { globalNodes } = ctx.get(inlineSyncConfig.key)
62
62
  const nodes: Node[] = []
63
63
 
@@ -75,11 +75,11 @@ const collectGlobalNodes = (ctx: Ctx, state: EditorState) => {
75
75
 
76
76
  const removeGlobalFromText = (text: string) => text.split('\n\n')[0] || ''
77
77
 
78
- const onlyHTML = (node: Node) => {
78
+ function onlyHTML(node: Node) {
79
79
  return node.childCount === 1 && node.child(0).type.name === 'html'
80
80
  }
81
81
 
82
- export const getContextByState = (ctx: Ctx, state: EditorState): InlineSyncContext | null => {
82
+ export function getContextByState(ctx: Ctx, state: EditorState): InlineSyncContext | null {
83
83
  try {
84
84
  const globalNode = collectGlobalNodes(ctx, state)
85
85
  const node = getNodeFromSelection(state)
@@ -4,8 +4,9 @@ export const linkRegexp = /\[([^\]]+)]\([^\s\]]+\)/
4
4
 
5
5
  export const keepLinkRegexp = /\[(?<span>((www|https:\/\/|http:\/\/)[^\s\]]+))]\((?<url>[^\s\]]+)\)/
6
6
 
7
- export const punctuationRegexp = (holePlaceholder: string) =>
8
- new RegExp(`\\\\(?=[^\\w\\s${holePlaceholder}\\\\]|_)`, 'g')
7
+ export function punctuationRegexp(holePlaceholder: string) {
8
+ return new RegExp(`\\\\(?=[^\\w\\s${holePlaceholder}\\\\]|_)`, 'g')
9
+ }
9
10
 
10
11
  export const ZERO_WIDTH_SPACE = '\u200B'
11
12
 
@@ -9,13 +9,7 @@ import { getContextByState } from './context'
9
9
  import { calcOffset } from './utils'
10
10
  import { linkRegexp } from './regexp'
11
11
 
12
- export const runReplacer = (
13
- ctx: Ctx,
14
- key: PluginKey,
15
- state: EditorState,
16
- dispatch: (tr: Transaction) => void,
17
- attrs: Attrs,
18
- ) => {
12
+ export function runReplacer(ctx: Ctx, key: PluginKey, state: EditorState, dispatch: (tr: Transaction) => void, attrs: Attrs) {
19
13
  const { placeholderConfig } = ctx.get(inlineSyncConfig.key)
20
14
  const holePlaceholder = placeholderConfig.hole
21
15
  // insert a placeholder to restore the selection
@@ -12,7 +12,7 @@ import {
12
12
  underlineHolder,
13
13
  } from './regexp'
14
14
 
15
- export const keepLink = (str: string) => {
15
+ export function keepLink(str: string) {
16
16
  let text = str
17
17
  let match = text.match(keepLinkRegexp)
18
18
  while (match && match.groups) {
@@ -24,7 +24,7 @@ export const keepLink = (str: string) => {
24
24
  return text
25
25
  }
26
26
 
27
- export const mergeSlash = (str: string) => {
27
+ export function mergeSlash(str: string) {
28
28
  return str
29
29
  .replaceAll(/\\\\\*/g, asterisk)
30
30
  .replaceAll(/\\\\_/g, underline)
@@ -32,7 +32,7 @@ export const mergeSlash = (str: string) => {
32
32
  .replaceAll(underline, underlineHolder)
33
33
  }
34
34
 
35
- export const swap = (text: string, first: number, last: number) => {
35
+ export function swap(text: string, first: number, last: number) {
36
36
  const arr = text.split('')
37
37
  const temp = arr[first]
38
38
  if (arr[first] && arr[last]) {
@@ -42,30 +42,34 @@ export const swap = (text: string, first: number, last: number) => {
42
42
  return arr.join('').toString()
43
43
  }
44
44
 
45
- export const replacePunctuation = (holePlaceholder: string) => (text: string) =>
46
- text.replace(punctuationRegexp(holePlaceholder), '')
45
+ export function replacePunctuation(holePlaceholder: string) {
46
+ return (text: string) =>
47
+ text.replace(punctuationRegexp(holePlaceholder), '')
48
+ }
47
49
 
48
- export const calculatePlaceholder = (placeholder: SyncNodePlaceholder) => (text: string) => {
49
- const index = text.indexOf(placeholder.hole)
50
- const left = text.charAt(index - 1)
51
- const right = text.charAt(index + 1)
52
- const notAWord = /[^\w]|_/
50
+ export function calculatePlaceholder(placeholder: SyncNodePlaceholder) {
51
+ return (text: string) => {
52
+ const index = text.indexOf(placeholder.hole)
53
+ const left = text.charAt(index - 1)
54
+ const right = text.charAt(index + 1)
55
+ const notAWord = /[^\w]|_/
53
56
 
54
- // cursor on the right
55
- if (!right)
56
- return placeholder.punctuation
57
+ // cursor on the right
58
+ if (!right)
59
+ return placeholder.punctuation
57
60
 
58
- // cursor on the left
59
- if (!left)
60
- return placeholder.char
61
+ // cursor on the left
62
+ if (!left)
63
+ return placeholder.char
61
64
 
62
- if (notAWord.test(left) && notAWord.test(right))
63
- return placeholder.punctuation
65
+ if (notAWord.test(left) && notAWord.test(right))
66
+ return placeholder.punctuation
64
67
 
65
- return placeholder.char
68
+ return placeholder.char
69
+ }
66
70
  }
67
71
 
68
- export const calcOffset = (node: Node, from: number, placeholder: string) => {
72
+ export function calcOffset(node: Node, from: number, placeholder: string) {
69
73
  let offset = from
70
74
  let find = false
71
75
  node.descendants((n) => {
@@ -4,7 +4,7 @@ import type { Node } from '@milkdown/transformer'
4
4
  import { withMeta } from '../__internal__'
5
5
 
6
6
  const isParent = (node: Node): node is Node & { children: Node[] } => !!(node as Node & { children: Node[] }).children
7
- const isHTML = (node: Node): node is Node & { children: Node[]; value: unknown } => node.type === 'html'
7
+ const isHTML = (node: Node): node is Node & { children: Node[], value: unknown } => node.type === 'html'
8
8
 
9
9
  function flatMapWithDepth(ast: Node, fn: (node: Node, index: number, parent: Node | null) => Node[]) {
10
10
  return transform(ast, 0, null)[0]