@milkdown/preset-commonmark 6.3.2 → 6.4.0

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 (45) hide show
  1. package/lib/index.d.ts +1 -0
  2. package/lib/index.d.ts.map +1 -1
  3. package/lib/index.es.js +660 -525
  4. package/lib/index.es.js.map +1 -1
  5. package/lib/mark/code-inline.d.ts.map +1 -1
  6. package/lib/mark/em.d.ts.map +1 -1
  7. package/lib/mark/link.d.ts.map +1 -1
  8. package/lib/mark/strong.d.ts.map +1 -1
  9. package/lib/node/bullet-list.d.ts.map +1 -1
  10. package/lib/node/heading.d.ts.map +1 -1
  11. package/lib/node/image.d.ts.map +1 -1
  12. package/lib/node/list-item.d.ts.map +1 -1
  13. package/lib/node/ordered-list.d.ts.map +1 -1
  14. package/lib/plugin/index.d.ts +2 -0
  15. package/lib/plugin/index.d.ts.map +1 -1
  16. package/lib/plugin/inline-sync/config.d.ts +24 -0
  17. package/lib/plugin/inline-sync/config.d.ts.map +1 -0
  18. package/lib/plugin/inline-sync/context.d.ts +12 -0
  19. package/lib/plugin/inline-sync/context.d.ts.map +1 -0
  20. package/lib/plugin/inline-sync/index.d.ts +6 -0
  21. package/lib/plugin/inline-sync/index.d.ts.map +1 -0
  22. package/lib/plugin/inline-sync/regexp.d.ts +3 -0
  23. package/lib/plugin/inline-sync/regexp.d.ts.map +1 -0
  24. package/lib/plugin/inline-sync/replacer.d.ts +5 -0
  25. package/lib/plugin/inline-sync/replacer.d.ts.map +1 -0
  26. package/lib/plugin/inline-sync/utils.d.ts +8 -0
  27. package/lib/plugin/inline-sync/utils.d.ts.map +1 -0
  28. package/package.json +5 -5
  29. package/src/index.ts +1 -0
  30. package/src/mark/code-inline.ts +25 -4
  31. package/src/mark/em.ts +1 -6
  32. package/src/mark/link.ts +1 -19
  33. package/src/mark/strong.ts +1 -5
  34. package/src/node/bullet-list.ts +33 -4
  35. package/src/node/heading.ts +10 -6
  36. package/src/node/image.ts +4 -5
  37. package/src/node/list-item.ts +9 -4
  38. package/src/node/ordered-list.ts +11 -3
  39. package/src/plugin/index.ts +9 -4
  40. package/src/plugin/inline-sync/config.ts +56 -0
  41. package/src/plugin/inline-sync/context.ts +115 -0
  42. package/src/plugin/inline-sync/index.ts +48 -0
  43. package/src/plugin/inline-sync/regexp.ts +6 -0
  44. package/src/plugin/inline-sync/replacer.ts +43 -0
  45. package/src/plugin/inline-sync/utils.ts +73 -0
@@ -1 +1 @@
1
- {"version":3,"file":"code-inline.d.ts","sourceRoot":"","sources":["../../src/mark/code-inline.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,gBAAgB,4CAAmC,CAAC;AAEjE,eAAO,MAAM,UAAU,wFA8BrB,CAAC"}
1
+ {"version":3,"file":"code-inline.d.ts","sourceRoot":"","sources":["../../src/mark/code-inline.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,gBAAgB,4CAAmC,CAAC;AAEjE,eAAO,MAAM,UAAU,wFAoDrB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"em.d.ts","sourceRoot":"","sources":["../../src/mark/em.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,YAAY,4CAA+B,CAAC;AAEzD,eAAO,MAAM,EAAE,wFAgCZ,CAAC"}
1
+ {"version":3,"file":"em.d.ts","sourceRoot":"","sources":["../../src/mark/em.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,YAAY,4CAA+B,CAAC;AACzD,eAAO,MAAM,EAAE,wFA6BZ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/mark/link.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,UAAU,yCAAqC,CAAC;AAC7D,eAAO,MAAM,UAAU,yCAAqC,CAAC;AAE7D,oBAAY,WAAW,GAAG;IACtB,KAAK,EAAE;QACH,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACL,CAAC;AACF,eAAO,MAAM,IAAI,4DAwNf,CAAC"}
1
+ {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/mark/link.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,UAAU,yCAAqC,CAAC;AAC7D,eAAO,MAAM,UAAU,yCAAqC,CAAC;AAE7D,oBAAY,WAAW,GAAG;IACtB,KAAK,EAAE;QACH,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACL,CAAC;AACF,eAAO,MAAM,IAAI,4DAuMf,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"strong.d.ts","sourceRoot":"","sources":["../../src/mark/strong.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,UAAU,4CAA6B,CAAC;AACrD,eAAO,MAAM,MAAM,wFAkCjB,CAAC"}
1
+ {"version":3,"file":"strong.d.ts","sourceRoot":"","sources":["../../src/mark/strong.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,UAAU,4CAA6B,CAAC;AACrD,eAAO,MAAM,MAAM,wFA+BjB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"bullet-list.d.ts","sourceRoot":"","sources":["../../src/node/bullet-list.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,gBAAgB,4CAAmC,CAAC;AAEjE,eAAO,MAAM,UAAU,8FA8BrB,CAAC"}
1
+ {"version":3,"file":"bullet-list.d.ts","sourceRoot":"","sources":["../../src/node/bullet-list.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,gBAAgB,4CAAmC,CAAC;AAEjE,eAAO,MAAM,UAAU,8FA0DrB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../src/node/heading.ts"],"names":[],"mappings":"AAMA,OAAO,EAAY,IAAI,EAAY,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAuB,SAAS,EAAe,MAAM,uBAAuB,CAAC;AAIpF,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMlD,aAAK,IAAI,GACH,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,kBAAkB,CAAC,CAAC;AAExC,eAAO,MAAM,eAAe,yCAA0C,CAAC;AACvE,eAAO,MAAM,gBAAgB,4CAAmC,CAAC;AAEjE,eAAO,MAAM,kBAAkB,gBAAuC,CAAC;AACvE,eAAO,MAAM,oBAAoB,gBAAyC,CAAC;AA6I3E,eAAO,MAAM,OAAO;kBAAoC,IAAI,KAAK,MAAM;oBAAkB,OAAO;EAwI/F,CAAC"}
1
+ {"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../src/node/heading.ts"],"names":[],"mappings":"AAMA,OAAO,EAAY,IAAI,EAAY,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAuB,SAAS,EAAe,MAAM,uBAAuB,CAAC;AAIpF,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMlD,aAAK,IAAI,GACH,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,IAAI,CAAC,GACnB,aAAa,CAAC,kBAAkB,CAAC,CAAC;AAExC,eAAO,MAAM,eAAe,yCAA0C,CAAC;AACvE,eAAO,MAAM,gBAAgB,4CAAmC,CAAC;AAEjE,eAAO,MAAM,kBAAkB,gBAAuC,CAAC;AACvE,eAAO,MAAM,oBAAoB,gBAAyC,CAAC;AAiJ3E,eAAO,MAAM,OAAO;kBAAoC,IAAI,KAAK,MAAM;oBAAkB,OAAO;EAwI/F,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/node/image.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,WAAW,yCAAsC,CAAC;AAC/D,eAAO,MAAM,WAAW,yCAAsC,CAAC;AAE/D,oBAAY,YAAY,GAAG;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE;QACH,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACL,CAAC;AAGF,eAAO,MAAM,KAAK,6DAoMhB,CAAC"}
1
+ {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/node/image.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,WAAW,yCAAsC,CAAC;AAC/D,eAAO,MAAM,WAAW,yCAAsC,CAAC;AAE/D,oBAAY,YAAY,GAAG;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE;QACH,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACL,CAAC;AAGF,eAAO,MAAM,KAAK,6DAmMhB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["../../src/node/list-item.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,aAAK,IAAI,GAAG,aAAa,CAAC,cAAc,CAAC,GAAG,aAAa,CAAC,cAAc,CAAC,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;AAI1G,eAAO,MAAM,aAAa,4CAAgC,CAAC;AAC3D,eAAO,MAAM,YAAY,4CAA+B,CAAC;AACzD,eAAO,MAAM,YAAY,4CAA+B,CAAC;AAmDzD,eAAO,MAAM,QAAQ,sFAyElB,CAAC"}
1
+ {"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["../../src/node/list-item.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,aAAK,IAAI,GAAG,aAAa,CAAC,cAAc,CAAC,GAAG,aAAa,CAAC,cAAc,CAAC,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;AAI1G,eAAO,MAAM,aAAa,4CAAgC,CAAC;AAC3D,eAAO,MAAM,YAAY,4CAA+B,CAAC;AACzD,eAAO,MAAM,YAAY,4CAA+B,CAAC;AAkDzD,eAAO,MAAM,QAAQ,sFA+ElB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ordered-list.d.ts","sourceRoot":"","sources":["../../src/node/ordered-list.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,iBAAiB,4CAAoC,CAAC;AAGnE,eAAO,MAAM,WAAW,+FAwDrB,CAAC"}
1
+ {"version":3,"file":"ordered-list.d.ts","sourceRoot":"","sources":["../../src/node/ordered-list.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,iBAAiB,4CAAoC,CAAC;AAGnE,eAAO,MAAM,WAAW,+FAgErB,CAAC"}
@@ -1,2 +1,4 @@
1
+ import { inlineSyncConfigCtx } from './inline-sync';
2
+ export { inlineSyncConfigCtx };
1
3
  export declare const commonmarkPlugins: (import("@milkdown/utils").Metadata<import("@milkdown/utils").GetPlugin<string, import("@milkdown/utils").UnknownRecord>> & import("@milkdown/core").MilkdownPlugin)[];
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,iBAAiB,wKAK7B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAuB,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzE,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAC/B,eAAO,MAAM,iBAAiB,wKAQ7B,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { Ctx } from '@milkdown/core';
2
+ import { Node, NodeType } from '@milkdown/prose/model';
3
+ import { Transaction } from '@milkdown/prose/state';
4
+ export declare type ShouldSyncNode = (context: {
5
+ prevNode: Node;
6
+ nextNode: Node;
7
+ ctx: Ctx;
8
+ tr: Transaction;
9
+ text: string;
10
+ }) => boolean;
11
+ export declare type SyncNodePlaceholder = {
12
+ hole: string;
13
+ punctuation: string;
14
+ char: string;
15
+ };
16
+ export declare type InlineSyncConfig = {
17
+ placeholderConfig: SyncNodePlaceholder;
18
+ shouldSyncNode: ShouldSyncNode;
19
+ globalNodes: Array<NodeType | string>;
20
+ movePlaceholder: (placeholderToMove: string, text: string) => string;
21
+ };
22
+ export declare const defaultConfig: InlineSyncConfig;
23
+ export declare const inlineSyncConfigCtx: import("@milkdown/core").Slice<InlineSyncConfig, "inlineSyncConfig">;
24
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIpD,oBAAY,cAAc,GAAG,CAAC,OAAO,EAAE;IACnC,QAAQ,EAAE,IAAI,CAAC;IACf,QAAQ,EAAE,IAAI,CAAC;IACf,GAAG,EAAE,GAAG,CAAC;IACT,EAAE,EAAE,WAAW,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CAChB,KAAK,OAAO,CAAC;AAEd,oBAAY,mBAAmB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,oBAAY,gBAAgB,GAAG;IAC3B,iBAAiB,EAAE,mBAAmB,CAAC;IACvC,cAAc,EAAE,cAAc,CAAC;IAC/B,WAAW,EAAE,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,CAAC;IACtC,eAAe,EAAE,CAAC,iBAAiB,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACxE,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,gBAyB3B,CAAC;AAEF,eAAO,MAAM,mBAAmB,sEAAuF,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { Ctx } from '@milkdown/core';
2
+ import { Node } from '@milkdown/prose/model';
3
+ import { EditorState } from '@milkdown/prose/state';
4
+ export * from './config';
5
+ export declare type InlineSyncContext = {
6
+ text: string;
7
+ prevNode: Node;
8
+ nextNode: Node;
9
+ placeholder: string;
10
+ };
11
+ export declare const getContextByState: (ctx: Ctx, state: EditorState) => InlineSyncContext | null;
12
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAA4B,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAMpD,cAAc,UAAU,CAAC;AAEzB,oBAAY,iBAAiB,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,IAAI,CAAC;IACf,QAAQ,EAAE,IAAI,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACvB,CAAC;AAiEF,eAAO,MAAM,iBAAiB,QAAS,GAAG,SAAS,WAAW,KAAG,iBAAiB,GAAG,IAiCpF,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { Ctx } from '@milkdown/core';
2
+ import { Plugin, PluginKey } from '@milkdown/prose/state';
3
+ export * from './config';
4
+ export declare const inlineSyncPluginKey: PluginKey<any>;
5
+ export declare const getInlineSyncPlugin: (ctx: Ctx) => Plugin<null>;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAiB,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAM1D,cAAc,UAAU,CAAC;AAEzB,eAAO,MAAM,mBAAmB,gBAAwC,CAAC;AACzE,eAAO,MAAM,mBAAmB,QAAS,GAAG,iBAoC3C,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const linkRegexp: RegExp;
2
+ export declare const punctuationRegexp: (holePlaceholder: string) => RegExp;
3
+ //# sourceMappingURL=regexp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/regexp.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAA+D,CAAC;AAEvF,eAAO,MAAM,iBAAiB,oBAAqB,MAAM,WACO,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Ctx } from '@milkdown/core';
2
+ import { Attrs } from '@milkdown/prose/model';
3
+ import { 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;
5
+ //# sourceMappingURL=replacer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replacer.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/replacer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAiB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAM3F,eAAO,MAAM,WAAW,QACf,GAAG,OACH,SAAS,SACP,WAAW,iBACH,WAAW,KAAK,IAAI,SAC5B,KAAK,SA4Bf,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Node } from '@milkdown/prose/model';
2
+ import { SyncNodePlaceholder } from './config';
3
+ export declare const keepLink: (str: string) => string;
4
+ export declare const swap: (text: string, first: number, last: number) => string;
5
+ export declare const replacePunctuation: (holePlaceholder: string) => (text: string) => string;
6
+ export declare const calculatePlaceholder: (placeholder: SyncNodePlaceholder) => (text: string) => string;
7
+ export declare const calcOffset: (node: Node, from: number, placeholder: string) => number;
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAG/C,eAAO,MAAM,QAAQ,QAAS,MAAM,WAUnC,CAAC;AAEF,eAAO,MAAM,IAAI,SAAU,MAAM,SAAS,MAAM,QAAQ,MAAM,WAQ7D,CAAC;AAEF,eAAO,MAAM,kBAAkB,oBAAqB,MAAM,YAAY,MAAM,WACpB,CAAC;AAEzD,eAAO,MAAM,oBAAoB,gBAAiB,mBAAmB,YAAY,MAAM,WAqBtF,CAAC;AAEF,eAAO,MAAM,UAAU,SAAU,IAAI,QAAQ,MAAM,eAAe,MAAM,WAiBvE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milkdown/preset-commonmark",
3
- "version": "6.3.2",
3
+ "version": "6.4.0",
4
4
  "type": "module",
5
5
  "main": "./lib/index.es.js",
6
6
  "types": "./lib/index.d.ts",
@@ -17,8 +17,8 @@
17
17
  "commonmark"
18
18
  ],
19
19
  "devDependencies": {
20
- "@milkdown/core": "6.3.2",
21
- "@milkdown/prose": "6.3.2",
20
+ "@milkdown/core": "6.4.0",
21
+ "@milkdown/prose": "6.4.0",
22
22
  "@types/unist": "^2.0.6"
23
23
  },
24
24
  "peerDependencies": {
@@ -26,8 +26,8 @@
26
26
  "@milkdown/prose": "^6.0.1"
27
27
  },
28
28
  "dependencies": {
29
- "@milkdown/utils": "6.3.2",
30
- "@milkdown/exception": "6.3.2",
29
+ "@milkdown/utils": "6.4.0",
30
+ "@milkdown/exception": "6.4.0",
31
31
  "unist-util-visit": "^4.0.0",
32
32
  "remark-inline-links": "^6.0.0",
33
33
  "tslib": "^2.4.0"
package/src/index.ts CHANGED
@@ -22,6 +22,7 @@ import { commonmarkPlugins } from './plugin';
22
22
 
23
23
  export * from './mark';
24
24
  export * from './node';
25
+ export { inlineSyncConfigCtx } from './plugin';
25
26
  export * from './supported-keys';
26
27
 
27
28
  export const commonmarkNodes = AtomList.create([...nodes, ...marks]);
@@ -1,7 +1,6 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { createCmd, createCmdKey } from '@milkdown/core';
3
- import { markRule } from '@milkdown/prose';
4
- import { toggleMark } from '@milkdown/prose/commands';
3
+ import { MarkType } from '@milkdown/prose/model';
5
4
  import { createMark, createShortcut } from '@milkdown/utils';
6
5
 
7
6
  import { SupportedKeys } from '../supported-keys';
@@ -35,8 +34,30 @@ export const codeInline = createMark<Keys>((utils) => {
35
34
  },
36
35
  },
37
36
  }),
38
- inputRules: (markType) => [markRule(/(?:^|[^`])(`([^`]+)`)$/, markType)],
39
- commands: (markType) => [createCmd(ToggleInlineCode, () => toggleMark(markType))],
37
+ commands: (markType) => [
38
+ createCmd(ToggleInlineCode, () => (state, dispatch) => {
39
+ const { selection, tr } = state;
40
+ if (selection.empty) return false;
41
+ const { from, to } = selection;
42
+
43
+ const has = state.doc.rangeHasMark(from, to, markType);
44
+ if (has) {
45
+ dispatch?.(tr.removeMark(from, to, markType));
46
+ return true;
47
+ }
48
+
49
+ const restMarksName = Object.keys(state.schema.marks).filter((x) => x !== markType.name);
50
+
51
+ restMarksName
52
+ .map((name) => state.schema.marks[name] as MarkType)
53
+ .forEach((t) => {
54
+ tr.removeMark(from, to, t);
55
+ });
56
+
57
+ dispatch?.(tr.addMark(from, to, markType.create()));
58
+ return true;
59
+ }),
60
+ ],
40
61
  shortcuts: {
41
62
  [SupportedKeys.CodeInline]: createShortcut(ToggleInlineCode, 'Mod-e'),
42
63
  },
package/src/mark/em.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { createCmd, createCmdKey } from '@milkdown/core';
3
- import { markRule } from '@milkdown/prose';
4
3
  import { toggleMark } from '@milkdown/prose/commands';
5
4
  import { createMark, createShortcut } from '@milkdown/utils';
6
5
 
@@ -11,10 +10,10 @@ type Keys = SupportedKeys['Em'];
11
10
  const id = 'em';
12
11
 
13
12
  export const ToggleItalic = createCmdKey('ToggleItalic');
14
-
15
13
  export const em = createMark<Keys>((utils) => ({
16
14
  id,
17
15
  schema: () => ({
16
+ inclusive: false,
18
17
  parseDOM: [
19
18
  { tag: 'i' },
20
19
  { tag: 'em' },
@@ -36,10 +35,6 @@ export const em = createMark<Keys>((utils) => ({
36
35
  },
37
36
  },
38
37
  }),
39
- inputRules: (markType) => [
40
- markRule(/(?:^|[^_])(_([^_]+)_)$/, markType),
41
- markRule(/(?:^|[^*])(\*([^*]+)\*)$/, markType),
42
- ],
43
38
  commands: (markType) => [createCmd(ToggleItalic, () => toggleMark(markType))],
44
39
  shortcuts: {
45
40
  [SupportedKeys.Em]: createShortcut(ToggleItalic, 'Mod-i'),
package/src/mark/link.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { commandsCtx, createCmd, createCmdKey, schemaCtx, ThemeInputChipType } from '@milkdown/core';
2
+ import { commandsCtx, createCmd, createCmdKey, ThemeInputChipType } from '@milkdown/core';
3
3
  import { expectDomTypeError, missingRootElement } from '@milkdown/exception';
4
4
  import { calculateTextPosition } from '@milkdown/prose';
5
5
  import { toggleMark } from '@milkdown/prose/commands';
6
- import { InputRule } from '@milkdown/prose/inputrules';
7
6
  import { Node as ProseNode } from '@milkdown/prose/model';
8
7
  import { NodeSelection, Plugin, PluginKey, TextSelection } from '@milkdown/prose/state';
9
8
  import { EditorView } from '@milkdown/prose/view';
@@ -28,7 +27,6 @@ export const link = createMark<string, LinkOptions>((utils, options) => {
28
27
  href: {},
29
28
  title: { default: null },
30
29
  },
31
- inclusive: false,
32
30
  parseDOM: [
33
31
  {
34
32
  tag: 'a[href]',
@@ -101,22 +99,6 @@ export const link = createMark<string, LinkOptions>((utils, options) => {
101
99
  return true;
102
100
  }),
103
101
  ],
104
- inputRules: (markType, ctx) => [
105
- new InputRule(/\[(?<text>.*?)]\((?<href>.*?)(?=“|\))"?(?<title>[^"]+)?"?\)/, (state, match, start, end) => {
106
- const [okay, text = '', href, title] = match;
107
- const { tr } = state;
108
- if (okay) {
109
- const content = text || 'link';
110
- tr.replaceWith(start, end, ctx.get(schemaCtx).text(content)).addMark(
111
- start,
112
- content.length + start,
113
- markType.create({ title, href }),
114
- );
115
- }
116
-
117
- return tr;
118
- }),
119
- ],
120
102
  prosePlugins: (type, ctx) => {
121
103
  let renderOnTop = false;
122
104
  return [
@@ -1,6 +1,5 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { createCmd, createCmdKey } from '@milkdown/core';
3
- import { markRule } from '@milkdown/prose';
4
3
  import { toggleMark } from '@milkdown/prose/commands';
5
4
  import { createMark, createShortcut } from '@milkdown/utils';
6
5
 
@@ -13,6 +12,7 @@ export const strong = createMark<Keys>((utils) => {
13
12
  return {
14
13
  id,
15
14
  schema: () => ({
15
+ inclusive: false,
16
16
  parseDOM: [
17
17
  { tag: 'b' },
18
18
  { tag: 'strong' },
@@ -34,10 +34,6 @@ export const strong = createMark<Keys>((utils) => {
34
34
  },
35
35
  },
36
36
  }),
37
- inputRules: (markType) => [
38
- markRule(/(?:__)([^_]+)(?:__)$/, markType),
39
- markRule(/(?:\*\*)([^*]+)(?:\*\*)$/, markType),
40
- ],
41
37
  commands: (markType) => [createCmd(ToggleBold, () => toggleMark(markType))],
42
38
  shortcuts: {
43
39
  [SupportedKeys.Bold]: createShortcut(ToggleBold, 'Mod-b'),
@@ -1,5 +1,6 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { createCmd, createCmdKey } from '@milkdown/core';
3
+ import { expectDomTypeError } from '@milkdown/exception';
3
4
  import { wrapIn } from '@milkdown/prose/commands';
4
5
  import { wrappingInputRule } from '@milkdown/prose/inputrules';
5
6
  import { createNode, createShortcut } from '@milkdown/utils';
@@ -17,20 +18,48 @@ export const bulletList = createNode<Keys>((utils) => {
17
18
  schema: () => ({
18
19
  content: 'listItem+',
19
20
  group: 'block',
20
- parseDOM: [{ tag: 'ul' }],
21
+ attrs: {
22
+ spread: {
23
+ default: false,
24
+ },
25
+ },
26
+ parseDOM: [
27
+ {
28
+ tag: 'ul',
29
+ getAttrs: (dom) => {
30
+ if (!(dom instanceof HTMLElement)) {
31
+ throw expectDomTypeError(dom);
32
+ }
33
+ return {
34
+ spread: dom.dataset['spread'],
35
+ };
36
+ },
37
+ },
38
+ ],
21
39
  toDOM: (node) => {
22
- return ['ul', { class: utils.getClassName(node.attrs, 'bullet-list') }, 0];
40
+ return [
41
+ 'ul',
42
+ {
43
+ 'data-spread': node.attrs['spread'],
44
+ class: utils.getClassName(node.attrs, 'bullet-list'),
45
+ },
46
+ 0,
47
+ ];
23
48
  },
24
49
  parseMarkdown: {
25
50
  match: ({ type, ordered }) => type === 'list' && !ordered,
26
51
  runner: (state, node, type) => {
27
- state.openNode(type).next(node.children).closeNode();
52
+ const spread = node['spread'] != null ? `${node['spread']}` : 'false';
53
+ state.openNode(type, { spread }).next(node.children).closeNode();
28
54
  },
29
55
  },
30
56
  toMarkdown: {
31
57
  match: (node) => node.type.name === id,
32
58
  runner: (state, node) => {
33
- state.openNode('list', undefined, { ordered: false }).next(node.content).closeNode();
59
+ state
60
+ .openNode('list', undefined, { ordered: false, spread: node.attrs['spread'] === 'true' })
61
+ .next(node.content)
62
+ .closeNode();
34
63
  },
35
64
  },
36
65
  }),
@@ -7,7 +7,7 @@ import { textblockTypeInputRule } from '@milkdown/prose/inputrules';
7
7
  import { Fragment, Node, NodeType } from '@milkdown/prose/model';
8
8
  import { EditorState, Plugin, PluginKey, Transaction } from '@milkdown/prose/state';
9
9
  import { Decoration, DecorationSet } from '@milkdown/prose/view';
10
- import { createNode, createShortcut, Utils } from '@milkdown/utils';
10
+ import { createNode, createShortcut, ThemeUtils } from '@milkdown/utils';
11
11
 
12
12
  import { SupportedKeys } from '../supported-keys';
13
13
 
@@ -40,7 +40,8 @@ const createId = (node: Node) =>
40
40
  const headingIdPlugin = (ctx: Ctx, type: NodeType, getId: (node: Node) => string): Plugin => {
41
41
  let lock = false;
42
42
  const walkThrough = (state: EditorState, callback: (tr: Transaction) => void) => {
43
- const tr = state.tr;
43
+ const tr = state.tr.setMeta('addToHistory', false);
44
+ let found = false;
44
45
  state.doc.descendants((node, pos) => {
45
46
  if (node.type === type && !lock) {
46
47
  if (node.textContent.trim().length === 0) {
@@ -50,6 +51,7 @@ const headingIdPlugin = (ctx: Ctx, type: NodeType, getId: (node: Node) => string
50
51
  const id = getId(node);
51
52
 
52
53
  if (attrs['id'] !== id) {
54
+ found = true;
53
55
  tr.setMeta(headingIdPluginKey, true).setNodeMarkup(pos, undefined, {
54
56
  ...attrs,
55
57
  id,
@@ -57,7 +59,9 @@ const headingIdPlugin = (ctx: Ctx, type: NodeType, getId: (node: Node) => string
57
59
  }
58
60
  }
59
61
  });
60
- callback(tr);
62
+ if (found) {
63
+ callback(tr);
64
+ }
61
65
  };
62
66
  return new Plugin({
63
67
  key: headingIdPluginKey,
@@ -93,7 +97,7 @@ const headingIdPlugin = (ctx: Ctx, type: NodeType, getId: (node: Node) => string
93
97
  },
94
98
  view: (view) => {
95
99
  const doc = view.state.doc;
96
- let tr = view.state.tr;
100
+ let tr = view.state.tr.setMeta('addToHistory', false);
97
101
  doc.descendants((node, pos) => {
98
102
  if (node.type.name === 'heading' && node.attrs['level']) {
99
103
  if (!node.attrs['id']) {
@@ -110,7 +114,7 @@ const headingIdPlugin = (ctx: Ctx, type: NodeType, getId: (node: Node) => string
110
114
  });
111
115
  };
112
116
 
113
- const headingHashPlugin = (ctx: Ctx, type: NodeType, utils: Utils): Plugin => {
117
+ const headingHashPlugin = (ctx: Ctx, type: NodeType, utils: ThemeUtils): Plugin => {
114
118
  return new Plugin({
115
119
  key: headingHashPluginKey,
116
120
  state: {
@@ -119,7 +123,7 @@ const headingHashPlugin = (ctx: Ctx, type: NodeType, utils: Utils): Plugin => {
119
123
  },
120
124
  apply: (tr) => {
121
125
  const view = ctx.get(editorViewCtx);
122
- if (!view.hasFocus || !view.editable) return DecorationSet.empty;
126
+ if (!view.hasFocus?.() || !view.editable) return DecorationSet.empty;
123
127
 
124
128
  const { $from } = tr.selection;
125
129
  const node = $from.node();
package/src/node/image.ts CHANGED
@@ -34,8 +34,8 @@ export const image = createNode<string, ImageOptions>((utils, options) => {
34
34
  isolating: true,
35
35
  attrs: {
36
36
  src: { default: '' },
37
- alt: { default: null },
38
- title: { default: null },
37
+ alt: { default: '' },
38
+ title: { default: '' },
39
39
  },
40
40
  parseDOM: [
41
41
  {
@@ -46,9 +46,8 @@ export const image = createNode<string, ImageOptions>((utils, options) => {
46
46
  }
47
47
  return {
48
48
  src: dom.getAttribute('src') || '',
49
- alt: dom.getAttribute('alt'),
50
- title: dom.getAttribute('title') || dom.getAttribute('alt'),
51
- width: dom.getAttribute('width'),
49
+ alt: dom.getAttribute('alt') || '',
50
+ title: dom.getAttribute('title') || dom.getAttribute('alt') || '',
52
51
  };
53
52
  },
54
53
  },
@@ -35,8 +35,7 @@ const createKeepListOrderPlugin = (type: NodeType) => {
35
35
 
36
36
  const base = parent?.maybeChild(0);
37
37
  if (base && base.type === type && base.attrs['listType'] === 'ordered') {
38
- const label = base.attrs['label'];
39
- attrs['label'] = `${Number(label.slice(0, -1)) + index}.`;
38
+ attrs['label'] = `${index + 1}.`;
40
39
  changed = true;
41
40
  }
42
41
 
@@ -79,6 +78,9 @@ export const listItem = createNode<Keys>((utils) => ({
79
78
  listType: {
80
79
  default: 'bullet',
81
80
  },
81
+ spread: {
82
+ default: 'true',
83
+ },
82
84
  },
83
85
  defining: true,
84
86
  parseDOM: [
@@ -91,6 +93,7 @@ export const listItem = createNode<Keys>((utils) => ({
91
93
  return {
92
94
  label: dom.dataset['label'],
93
95
  listType: dom.dataset['list-type'],
96
+ spread: dom.dataset['spread'],
94
97
  };
95
98
  },
96
99
  contentElement: 'div.list-item_body',
@@ -104,6 +107,7 @@ export const listItem = createNode<Keys>((utils) => ({
104
107
  class: utils.getClassName(node.attrs, 'list-item'),
105
108
  'data-label': node.attrs['label'],
106
109
  'data-list-type': node.attrs['listType'],
110
+ 'data-spread': node.attrs['spread'],
107
111
  },
108
112
  ['div', { class: utils.getClassName(node.attrs, 'list-item_label') }, node.attrs['label']],
109
113
  ['div', { class: utils.getClassName(node.attrs, 'list-item_body') }, 0],
@@ -114,7 +118,8 @@ export const listItem = createNode<Keys>((utils) => ({
114
118
  runner: (state, node, type) => {
115
119
  const label = node['label'] != null ? `${node['label']}.` : '•';
116
120
  const listType = node['label'] != null ? 'ordered' : 'bullet';
117
- state.openNode(type, { label, listType });
121
+ const spread = node['spread'] != null ? `${node['spread']}` : 'true';
122
+ state.openNode(type, { label, listType, spread });
118
123
  state.next(node.children);
119
124
  state.closeNode();
120
125
  },
@@ -122,7 +127,7 @@ export const listItem = createNode<Keys>((utils) => ({
122
127
  toMarkdown: {
123
128
  match: (node) => node.type.name === id,
124
129
  runner: (state, node) => {
125
- state.openNode('listItem');
130
+ state.openNode('listItem', undefined, { spread: node.attrs['spread'] === 'true' });
126
131
  state.next(node.content);
127
132
  state.closeNode();
128
133
  },
@@ -21,6 +21,9 @@ export const orderedList = createNode<Keys>((utils) => ({
21
21
  order: {
22
22
  default: 1,
23
23
  },
24
+ spread: {
25
+ default: false,
26
+ },
24
27
  },
25
28
  parseDOM: [
26
29
  {
@@ -29,7 +32,10 @@ export const orderedList = createNode<Keys>((utils) => ({
29
32
  if (!(dom instanceof HTMLElement)) {
30
33
  throw expectDomTypeError(dom);
31
34
  }
32
- return { order: dom.hasAttribute('start') ? Number(dom.getAttribute('start')) : 1 };
35
+ return {
36
+ spread: dom.dataset['spread'],
37
+ order: dom.hasAttribute('start') ? Number(dom.getAttribute('start')) : 1,
38
+ };
33
39
  },
34
40
  },
35
41
  ],
@@ -37,6 +43,7 @@ export const orderedList = createNode<Keys>((utils) => ({
37
43
  'ol',
38
44
  {
39
45
  ...(node.attrs['order'] === 1 ? {} : node.attrs['order']),
46
+ 'data-spread': node.attrs['spread'],
40
47
  class: utils.getClassName(node.attrs, 'ordered-list'),
41
48
  },
42
49
  0,
@@ -44,13 +51,14 @@ export const orderedList = createNode<Keys>((utils) => ({
44
51
  parseMarkdown: {
45
52
  match: ({ type, ordered }) => type === 'list' && !!ordered,
46
53
  runner: (state, node, type) => {
47
- state.openNode(type).next(node.children).closeNode();
54
+ const spread = node['spread'] != null ? `${node['spread']}` : 'true';
55
+ state.openNode(type, { spread }).next(node.children).closeNode();
48
56
  },
49
57
  },
50
58
  toMarkdown: {
51
59
  match: (node) => node.type.name === id,
52
60
  runner: (state, node) => {
53
- state.openNode('list', undefined, { ordered: true, start: 1 });
61
+ state.openNode('list', undefined, { ordered: true, start: 1, spread: node.attrs['spread'] === 'true' });
54
62
  state.next(node.content);
55
63
  state.closeNode();
56
64
  },
@@ -5,10 +5,15 @@ import links from 'remark-inline-links';
5
5
  import { addOrderInList } from './add-order-in-list';
6
6
  import { filterHTMLPlugin } from './filter-html';
7
7
  import { getInlineNodesCursorPlugin } from './inline-nodes-cursor';
8
+ import { getInlineSyncPlugin, inlineSyncConfigCtx } from './inline-sync';
8
9
 
10
+ export { inlineSyncConfigCtx };
9
11
  export const commonmarkPlugins = [
10
- createPlugin(() => ({
11
- prosePlugins: () => [getInlineNodesCursorPlugin()],
12
- remarkPlugins: () => [links, filterHTMLPlugin, addOrderInList],
13
- }))(),
12
+ createPlugin(
13
+ () => ({
14
+ prosePlugins: (_, ctx) => [getInlineNodesCursorPlugin(), getInlineSyncPlugin(ctx)],
15
+ remarkPlugins: () => [links, filterHTMLPlugin, addOrderInList],
16
+ }),
17
+ [inlineSyncConfigCtx],
18
+ )(),
14
19
  ];