@milkdown/preset-commonmark 5.3.1 → 5.3.5

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 (85) hide show
  1. package/lib/index.d.ts +1 -34
  2. package/lib/index.es.js +105 -49
  3. package/lib/index.es.js.map +1 -1
  4. package/lib/src/index.d.ts +34 -0
  5. package/lib/src/index.d.ts.map +1 -0
  6. package/lib/{mark → src/mark}/code-inline.d.ts +1 -1
  7. package/lib/src/mark/code-inline.d.ts.map +1 -0
  8. package/lib/{mark → src/mark}/em.d.ts +1 -1
  9. package/lib/src/mark/em.d.ts.map +1 -0
  10. package/lib/src/mark/index.d.ts +6 -0
  11. package/lib/src/mark/index.d.ts.map +1 -0
  12. package/lib/{mark → src/mark}/link.d.ts +1 -1
  13. package/lib/src/mark/link.d.ts.map +1 -0
  14. package/lib/{mark → src/mark}/strong.d.ts +1 -1
  15. package/lib/src/mark/strong.d.ts.map +1 -0
  16. package/lib/{node → src/node}/blockquote.d.ts +1 -1
  17. package/lib/src/node/blockquote.d.ts.map +1 -0
  18. package/lib/{node → src/node}/bullet-list.d.ts +1 -1
  19. package/lib/src/node/bullet-list.d.ts.map +1 -0
  20. package/lib/{node → src/node}/code-fence.d.ts +1 -1
  21. package/lib/src/node/code-fence.d.ts.map +1 -0
  22. package/lib/{node → src/node}/doc.d.ts +1 -1
  23. package/lib/src/node/doc.d.ts.map +1 -0
  24. package/lib/{node → src/node}/hardbreak.d.ts +1 -1
  25. package/lib/src/node/hardbreak.d.ts.map +1 -0
  26. package/lib/{node → src/node}/heading.d.ts +3 -1
  27. package/lib/src/node/heading.d.ts.map +1 -0
  28. package/lib/{node → src/node}/hr.d.ts +1 -1
  29. package/lib/src/node/hr.d.ts.map +1 -0
  30. package/lib/{node → src/node}/image.d.ts +1 -1
  31. package/lib/src/node/image.d.ts.map +1 -0
  32. package/lib/{node → src/node}/index.d.ts +2 -2
  33. package/lib/src/node/index.d.ts.map +1 -0
  34. package/lib/{node → src/node}/list-item.d.ts +1 -1
  35. package/lib/src/node/list-item.d.ts.map +1 -0
  36. package/lib/{node → src/node}/ordered-list.d.ts +1 -1
  37. package/lib/src/node/ordered-list.d.ts.map +1 -0
  38. package/lib/{node → src/node}/paragraph.d.ts +1 -1
  39. package/lib/src/node/paragraph.d.ts.map +1 -0
  40. package/lib/{node → src/node}/text.d.ts +1 -1
  41. package/lib/src/node/text.d.ts.map +1 -0
  42. package/lib/{plugin → src/plugin}/filter-html.d.ts +0 -0
  43. package/lib/src/plugin/filter-html.d.ts.map +1 -0
  44. package/lib/src/plugin/index.d.ts +2 -0
  45. package/lib/src/plugin/index.d.ts.map +1 -0
  46. package/lib/{supported-keys.d.ts → src/supported-keys.d.ts} +0 -0
  47. package/lib/src/supported-keys.d.ts.map +1 -0
  48. package/lib/src/types.d.ts +5 -0
  49. package/package.json +7 -14
  50. package/src/mark/code-inline.ts +6 -7
  51. package/src/mark/link.ts +1 -2
  52. package/src/mark/strong.ts +1 -2
  53. package/src/node/blockquote.ts +1 -2
  54. package/src/node/bullet-list.ts +1 -1
  55. package/src/node/code-fence.ts +3 -4
  56. package/src/node/heading.ts +74 -25
  57. package/src/node/hr.ts +1 -2
  58. package/src/node/image.ts +12 -5
  59. package/src/node/list-item.ts +1 -2
  60. package/src/node/ordered-list.ts +1 -1
  61. package/src/node/paragraph.ts +8 -9
  62. package/lib/index.d.ts.map +0 -1
  63. package/lib/mark/code-inline.d.ts.map +0 -1
  64. package/lib/mark/em.d.ts.map +0 -1
  65. package/lib/mark/index.d.ts +0 -6
  66. package/lib/mark/index.d.ts.map +0 -1
  67. package/lib/mark/link.d.ts.map +0 -1
  68. package/lib/mark/strong.d.ts.map +0 -1
  69. package/lib/node/blockquote.d.ts.map +0 -1
  70. package/lib/node/bullet-list.d.ts.map +0 -1
  71. package/lib/node/code-fence.d.ts.map +0 -1
  72. package/lib/node/doc.d.ts.map +0 -1
  73. package/lib/node/hardbreak.d.ts.map +0 -1
  74. package/lib/node/heading.d.ts.map +0 -1
  75. package/lib/node/hr.d.ts.map +0 -1
  76. package/lib/node/image.d.ts.map +0 -1
  77. package/lib/node/index.d.ts.map +0 -1
  78. package/lib/node/list-item.d.ts.map +0 -1
  79. package/lib/node/ordered-list.d.ts.map +0 -1
  80. package/lib/node/paragraph.d.ts.map +0 -1
  81. package/lib/node/text.d.ts.map +0 -1
  82. package/lib/plugin/filter-html.d.ts.map +0 -1
  83. package/lib/plugin/index.d.ts +0 -2
  84. package/lib/plugin/index.d.ts.map +0 -1
  85. package/lib/supported-keys.d.ts.map +0 -1
@@ -1,7 +1,9 @@
1
+ import { PluginKey } from '@milkdown/prose';
1
2
  import { SupportedKeys } from '../supported-keys';
2
3
  declare type Keys = SupportedKeys['H1'] | SupportedKeys['H2'] | SupportedKeys['H3'] | SupportedKeys['H4'] | SupportedKeys['H5'] | SupportedKeys['H6'];
3
4
  export declare const TurnIntoHeading: import("@milkdown/core").CmdKey<number>;
4
- export declare const heading: import("@milkdown/utils/lib/types").WithExtend<Keys, import("@milkdown/utils").UnknownRecord, import("prosemirror-model").NodeType<any>, {
5
+ export declare const headingPluginKey: PluginKey<any, any>;
6
+ export declare const heading: import("@milkdown/utils/lib/src/types").WithExtend<Keys, import("@milkdown/utils").UnknownRecord, import("prosemirror-model").NodeType<any>, {
5
7
  id: string;
6
8
  schema: (ctx: import("@milkdown/core").Ctx) => import("@milkdown/core").NodeSchema;
7
9
  view?: ((ctx: import("@milkdown/core").Ctx) => import("@milkdown/prose").NodeViewFactory) | undefined;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["heading.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,SAAS,EAAwC,MAAM,iBAAiB,CAAC;AAG1F,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,CAAC;AAE1B,eAAO,MAAM,eAAe,yCAAyB,CAAC;AAEtD,eAAO,MAAM,gBAAgB,qBAAsC,CAAC;AAEpE,eAAO,MAAM,OAAO;;;;EAiIlB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  export declare const InsertHr: import("@milkdown/core").CmdKey<string>;
2
- export declare const hr: import("@milkdown/utils/lib/types").WithExtend<string, import("@milkdown/utils").UnknownRecord, import("prosemirror-model").NodeType<any>, {
2
+ export declare const hr: import("@milkdown/utils/lib/src/types").WithExtend<string, import("@milkdown/utils").UnknownRecord, import("prosemirror-model").NodeType<any>, {
3
3
  id: string;
4
4
  schema: (ctx: import("@milkdown/core").Ctx) => import("@milkdown/core").NodeSchema;
5
5
  view?: ((ctx: import("@milkdown/core").Ctx) => import("@milkdown/prose").NodeViewFactory) | undefined;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hr.d.ts","sourceRoot":"","sources":["hr.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ,yCAAyB,CAAC;AAC/C,eAAO,MAAM,EAAE;;;;EAyDb,CAAC"}
@@ -8,7 +8,7 @@ export declare type ImageOptions = {
8
8
  failed: string;
9
9
  };
10
10
  };
11
- export declare const image: import("@milkdown/utils/lib/types").WithExtend<string, ImageOptions, import("prosemirror-model").NodeType<any>, {
11
+ export declare const image: import("@milkdown/utils/lib/src/types").WithExtend<string, ImageOptions, import("prosemirror-model").NodeType<any>, {
12
12
  id: string;
13
13
  schema: (ctx: import("@milkdown/core").Ctx) => import("@milkdown/core").NodeSchema;
14
14
  view?: ((ctx: import("@milkdown/core").Ctx) => import("@milkdown/prose").NodeViewFactory) | undefined;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["image.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,WAAW,yCAAyB,CAAC;AAClD,eAAO,MAAM,WAAW,yCAAyB,CAAC;AAElD,oBAAY,YAAY,GAAG;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE;QACT,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAClB,CAAC;CACL,CAAC;AAEF,eAAO,MAAM,KAAK;;;;EAyVhB,CAAC"}
@@ -1,6 +1,6 @@
1
- export declare const nodes: ((import("@milkdown/utils/lib/types").Metadata<import("@milkdown/utils/lib/types").GetPlugin<"CodeFence", {
1
+ export declare const nodes: ((import("@milkdown/utils/lib/src/types").Metadata<import("@milkdown/utils/lib/src/types").GetPlugin<"CodeFence", {
2
2
  languageList?: string[] | undefined;
3
- }>> & import("@milkdown/core").MilkdownPlugin) | (import("@milkdown/utils/lib/types").Metadata<import("@milkdown/utils/lib/types").GetPlugin<string, import("./image").ImageOptions>> & import("@milkdown/core").MilkdownPlugin))[];
3
+ }>> & import("@milkdown/core").MilkdownPlugin) | (import("@milkdown/utils/lib/src/types").Metadata<import("@milkdown/utils/lib/src/types").GetPlugin<string, import("./image").ImageOptions>> & import("@milkdown/core").MilkdownPlugin))[];
4
4
  export * from './blockquote';
5
5
  export * from './bullet-list';
6
6
  export * from './code-fence';
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,KAAK;;2OAajB,CAAC;AAEF,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,MAAM,CAAC;AACrB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC"}
@@ -3,7 +3,7 @@ declare type Keys = SupportedKeys['SinkListItem'] | SupportedKeys['LiftListItem'
3
3
  export declare const SplitListItem: import("@milkdown/core").CmdKey<undefined>;
4
4
  export declare const SinkListItem: import("@milkdown/core").CmdKey<undefined>;
5
5
  export declare const LiftListItem: import("@milkdown/core").CmdKey<undefined>;
6
- export declare const listItem: import("@milkdown/utils/lib/types").WithExtend<Keys, import("@milkdown/utils").UnknownRecord, import("prosemirror-model").NodeType<any>, {
6
+ export declare const listItem: import("@milkdown/utils/lib/src/types").WithExtend<Keys, import("@milkdown/utils").UnknownRecord, import("prosemirror-model").NodeType<any>, {
7
7
  id: string;
8
8
  schema: (ctx: import("@milkdown/core").Ctx) => import("@milkdown/core").NodeSchema;
9
9
  view?: ((ctx: import("@milkdown/core").Ctx) => import("@milkdown/prose").NodeViewFactory) | undefined;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["list-item.ts"],"names":[],"mappings":"AAKA,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,4CAAiB,CAAC;AAC5C,eAAO,MAAM,YAAY,4CAAiB,CAAC;AAC3C,eAAO,MAAM,YAAY,4CAAiB,CAAC;AAE3C,eAAO,MAAM,QAAQ;;;;EAuDnB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  export declare const WrapInOrderedList: import("@milkdown/core").CmdKey<undefined>;
2
- export declare const orderedList: import("@milkdown/utils/lib/types").WithExtend<"OrderedList", import("@milkdown/utils").UnknownRecord, import("prosemirror-model").NodeType<any>, {
2
+ export declare const orderedList: import("@milkdown/utils/lib/src/types").WithExtend<"OrderedList", import("@milkdown/utils").UnknownRecord, import("prosemirror-model").NodeType<any>, {
3
3
  id: string;
4
4
  schema: (ctx: import("@milkdown/core").Ctx) => import("@milkdown/core").NodeSchema;
5
5
  view?: ((ctx: import("@milkdown/core").Ctx) => import("@milkdown/prose").NodeViewFactory) | undefined;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ordered-list.d.ts","sourceRoot":"","sources":["ordered-list.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,iBAAiB,4CAAiB,CAAC;AAGhD,eAAO,MAAM,WAAW;;;;EAwDrB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  export declare const TurnIntoText: import("@milkdown/core").CmdKey<undefined>;
2
- export declare const paragraph: import("@milkdown/utils/lib/types").WithExtend<"Text", import("@milkdown/utils").UnknownRecord, import("prosemirror-model").NodeType<any>, {
2
+ export declare const paragraph: import("@milkdown/utils/lib/src/types").WithExtend<"Text", import("@milkdown/utils").UnknownRecord, import("prosemirror-model").NodeType<any>, {
3
3
  id: string;
4
4
  schema: (ctx: import("@milkdown/core").Ctx) => import("@milkdown/core").NodeSchema;
5
5
  view?: ((ctx: import("@milkdown/core").Ctx) => import("@milkdown/prose").NodeViewFactory) | undefined;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paragraph.d.ts","sourceRoot":"","sources":["paragraph.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,YAAY,4CAAiB,CAAC;AAG3C,eAAO,MAAM,SAAS;;;;EA0CpB,CAAC"}
@@ -1,4 +1,4 @@
1
- export declare const text: import("@milkdown/utils/lib/types").WithExtend<string, import("@milkdown/utils").UnknownRecord, import("prosemirror-model").NodeType<any>, {
1
+ export declare const text: import("@milkdown/utils/lib/src/types").WithExtend<string, import("@milkdown/utils").UnknownRecord, import("prosemirror-model").NodeType<any>, {
2
2
  id: string;
3
3
  schema: (ctx: import("@milkdown/core").Ctx) => import("@milkdown/core").NodeSchema;
4
4
  view?: ((ctx: import("@milkdown/core").Ctx) => import("@milkdown/prose").NodeViewFactory) | undefined;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["text.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,IAAI;;;;EAiBd,CAAC"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter-html.d.ts","sourceRoot":"","sources":["filter-html.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,IAAI,EAAU,MAAM,OAAO,CAAC;AA0B9C,eAAO,MAAM,gBAAgB,eACE,IAAI,SAUlC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const commonmarkPlugins: (import("@milkdown/utils/lib/src/types").Metadata<import("@milkdown/utils/lib/src/types").GetPlugin<string, import("@milkdown/utils").UnknownRecord>> & import("@milkdown/core").MilkdownPlugin)[];
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,iBAAiB,oMAI7B,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supported-keys.d.ts","sourceRoot":"","sources":["supported-keys.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;CAmBhB,CAAC;AAEX,oBAAY,aAAa,GAAG,OAAO,aAAa,CAAC"}
@@ -0,0 +1,5 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ declare module 'remark-inline-links' {
3
+ let a: never;
4
+ export = a;
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milkdown/preset-commonmark",
3
- "version": "5.3.1",
3
+ "version": "5.3.5",
4
4
  "type": "module",
5
5
  "main": "./lib/index.es.js",
6
6
  "types": "./lib/index.d.ts",
@@ -16,26 +16,19 @@
16
16
  "markdown",
17
17
  "commonmark"
18
18
  ],
19
- "peerDependencies": {
20
- "@milkdown/core": "*"
21
- },
22
19
  "dependencies": {
23
- "@emotion/css": "^11.1.3",
24
- "@milkdown/utils": "5.3.1",
20
+ "@milkdown/prose": "5.3.5",
21
+ "@milkdown/core": "5.3.5",
22
+ "@milkdown/design-system": "5.3.5",
23
+ "@milkdown/utils": "5.3.5",
25
24
  "remark-inline-links": "^6.0.0",
26
25
  "tslib": "^2.3.1"
27
26
  },
28
- "devDependencies": {
29
- "@milkdown/prose": "5.3.1",
30
- "@milkdown/core": "5.3.1",
31
- "@milkdown/design-system": "5.3.1"
32
- },
33
27
  "scripts": {
34
- "start": "vite",
35
- "watch": "vite build --watch",
28
+ "start": "vite build --watch",
36
29
  "test": "vitest",
37
30
  "tsc": "tsc --noEmit",
38
- "build": "vite build && tsc --emitDeclarationOnly"
31
+ "build": "vite build"
39
32
  },
40
33
  "readme": "# @milkdown/preset-commonmark\n\nCommon mark preset for [milkdown](https://saul-mirone.github.io/milkdown/).\nAdd support for commonmark.\n\n# Example Usage\n\n```typescript\nimport { Editor } from '@milkdown/core';\nimport { nord } from '@milkdown/theme-nord';\n\nimport { commonmark } from '@milkdown/preset-commonmark';\n\nEditor.make().use(nord).use(commonmark).create();\n```\n\n## Custom Keymap\n\n```typescript\nimport { commonmarkNodes, commonmarkPlugins, blockquote, SupportedKeys } from '@milkdown/preset-commonmark';\n\nconst nodes = commonmarkNodes.configure(blockquote, {\n keymap: {\n [SupportedKeys.Blockquote]: 'Mod-Shift-b',\n },\n});\n\nEditor.make().use(commonmarkPlugins).use(nodes);\n```\n\nKeymap supported:\n\n- HardBreak\n- Blockquote\n- BulletList\n- OrderedList\n- CodeFence\n- H1\n- H2\n- H3\n- H4\n- H5\n- H6\n- Text\n- CodeInline\n- Em\n- Bold\n- NextListItem\n- SinkListItem\n- LiftListItem\n\n## Custom Style\n\n```typescript\nimport { commonmark, Paragraph, Heading } from '@milkdown/commonmark';\n\nconst nodes = commonmark\n .configure(Paragraph, {\n className: () =>\n 'my-custom-paragraph'\n })\n .configure(Heading, {\n className: (attrs) =>\n `my-custom-heading my-h${attrs.level}`\n })\n\nnew Editor({ ... }).use(nodes);\n```\n\n## Other Options\n\n### Image\n\n- placeholder\n - loading: _string_. The placeholder of loading status.\n - empty: _string_. The placeholder of empty status.\n - failed: _string_. The placeholder of failed status.\n\n### CodeFence\n\n- languageList: _string[]_. The selectable languages list of code fence needs to be enabled.\n\n# License\n\nMilkdown is open sourced software licensed under [MIT license](https://github.com/Saul-Mirone/milkdown/blob/main/LICENSE).\n"
41
34
  }
@@ -1,5 +1,4 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { css } from '@emotion/css';
3
2
  import { createCmd, createCmdKey } from '@milkdown/core';
4
3
  import { markRule, toggleMark } from '@milkdown/prose';
5
4
  import { createMark, createShortcut } from '@milkdown/utils';
@@ -13,7 +12,7 @@ export const ToggleInlineCode = createCmdKey();
13
12
 
14
13
  export const codeInline = createMark<Keys>((utils) => {
15
14
  const style = utils.getStyle(
16
- ({ palette, size, font }) =>
15
+ ({ palette, size, font }, { css }) =>
17
16
  css`
18
17
  background-color: ${palette('neutral')};
19
18
  color: ${palette('background')};
@@ -26,7 +25,9 @@ export const codeInline = createMark<Keys>((utils) => {
26
25
  return {
27
26
  id,
28
27
  schema: () => ({
29
- excludes: '_',
28
+ priority: 100,
29
+ code: true,
30
+ inclusive: false,
30
31
  parseDOM: [{ tag: 'code' }],
31
32
  toDOM: (mark) => ['code', { class: utils.getClassName(mark.attrs, 'code-inline', style) }],
32
33
  parseMarkdown: {
@@ -39,10 +40,8 @@ export const codeInline = createMark<Keys>((utils) => {
39
40
  },
40
41
  toMarkdown: {
41
42
  match: (mark) => mark.type.name === id,
42
- runner: (state, _, node) => {
43
- state.addNode('inlineCode', undefined, node.text || '');
44
-
45
- return true;
43
+ runner: (state, mark, node) => {
44
+ state.withMark(mark, 'inlineCode', node.text || '');
46
45
  },
47
46
  },
48
47
  }),
package/src/mark/link.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { css } from '@emotion/css';
3
2
  import { createCmd, createCmdKey, schemaCtx } from '@milkdown/core';
4
3
  import { InputRule, Node as ProseNode, TextSelection, toggleMark } from '@milkdown/prose';
5
4
  import { createMark } from '@milkdown/utils';
@@ -8,7 +7,7 @@ export const ToggleLink = createCmdKey<string>();
8
7
  export const ModifyLink = createCmdKey<string>();
9
8
  const id = 'link';
10
9
  export const link = createMark((utils) => {
11
- const style = utils.getStyle((themeTool) => {
10
+ const style = utils.getStyle((themeTool, { css }) => {
12
11
  const lineColor = themeTool.palette('line');
13
12
 
14
13
  return css`
@@ -1,5 +1,4 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { css } from '@emotion/css';
3
2
  import { createCmd, createCmdKey } from '@milkdown/core';
4
3
  import { markRule, toggleMark } from '@milkdown/prose';
5
4
  import { createMark, createShortcut } from '@milkdown/utils';
@@ -11,7 +10,7 @@ const id = 'strong';
11
10
  export const ToggleBold = createCmdKey();
12
11
  export const strong = createMark<Keys>((utils) => {
13
12
  const style = utils.getStyle(
14
- () =>
13
+ (_, { css }) =>
15
14
  css`
16
15
  font-weight: 600;
17
16
  `,
@@ -1,5 +1,4 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { css } from '@emotion/css';
3
2
  import { createCmd, createCmdKey } from '@milkdown/core';
4
3
  import { wrapIn, wrappingInputRule } from '@milkdown/prose';
5
4
  import { createNode, createShortcut } from '@milkdown/utils';
@@ -14,7 +13,7 @@ export const WrapInBlockquote = createCmdKey();
14
13
 
15
14
  export const blockquote = createNode<Keys>((utils) => {
16
15
  const style = utils.getStyle(
17
- (themeTool) =>
16
+ (themeTool, { css }) =>
18
17
  css`
19
18
  padding-left: 1.875rem;
20
19
  line-height: 1.75rem;
@@ -36,7 +36,7 @@ export const bulletList = createNode<Keys>((utils) => {
36
36
  inputRules: (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)],
37
37
  commands: (nodeType) => [createCmd(WrapInBulletList, () => wrapIn(nodeType))],
38
38
  shortcuts: {
39
- [SupportedKeys.BulletList]: createShortcut(WrapInBulletList, 'Mod-Shift-8'),
39
+ [SupportedKeys.BulletList]: createShortcut(WrapInBulletList, 'Mod-Alt-8'),
40
40
  },
41
41
  };
42
42
  });
@@ -1,5 +1,4 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { css } from '@emotion/css';
3
2
  import { createCmd, createCmdKey, themeToolCtx } from '@milkdown/core';
4
3
  import { setBlockType, textblockTypeInputRule } from '@milkdown/prose';
5
4
  import { createNode, createShortcut } from '@milkdown/utils';
@@ -34,7 +33,7 @@ export const TurnIntoCodeFence = createCmdKey();
34
33
 
35
34
  const id = 'fence';
36
35
  export const codeFence = createNode<Keys, { languageList?: string[] }>((utils, options) => {
37
- const style = utils.getStyle(({ palette, mixin, size, font }) => {
36
+ const style = utils.getStyle(({ palette, mixin, size, font }, { css }) => {
38
37
  const { shadow, scrollbar, border } = mixin;
39
38
  const { lineWidth, radius } = size;
40
39
  return css`
@@ -171,12 +170,12 @@ export const codeFence = createNode<Keys, { languageList?: string[] }>((utils, o
171
170
  ],
172
171
  toDOM: (node) => {
173
172
  return [
174
- 'div',
173
+ 'pre',
175
174
  {
176
175
  'data-language': node.attrs.language,
177
176
  class: utils.getClassName(node.attrs, 'code-fence', style),
178
177
  },
179
- ['pre', ['code', { spellCheck: 'false' }, 0]],
178
+ ['code', { spellCheck: 'false' }, 0],
180
179
  ];
181
180
  },
182
181
  parseMarkdown: {
@@ -1,7 +1,6 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { css } from '@emotion/css';
3
2
  import { createCmd, createCmdKey } from '@milkdown/core';
4
- import { setBlockType, textblockTypeInputRule } from '@milkdown/prose';
3
+ import { Plugin, PluginKey, setBlockType, textblockTypeInputRule } from '@milkdown/prose';
5
4
  import { createNode, createShortcut } from '@milkdown/utils';
6
5
 
7
6
  import { SupportedKeys } from '../supported-keys';
@@ -20,31 +19,46 @@ type Keys =
20
19
 
21
20
  export const TurnIntoHeading = createCmdKey<number>();
22
21
 
23
- export const heading = createNode<Keys>((utils, options) => {
22
+ export const headingPluginKey = new PluginKey('MILKDOWN_PLUGIN_ID');
23
+
24
+ export const heading = createNode<Keys>((utils) => {
24
25
  const id = 'heading';
25
- const headingMap: Record<number, string> = {
26
- 1: css`
27
- font-size: 3rem;
28
- line-height: 3.5rem;
29
- `,
30
- 2: css`
31
- font-size: 2.125rem;
32
- line-height: 2.25rem;
33
- `,
34
- 3: css`
35
- font-size: 1.5rem;
36
- line-height: 1.5rem;
37
- `,
38
- };
39
26
 
40
27
  const style = (level: number) =>
41
- options?.headless
42
- ? null
43
- : css`
44
- ${headingMap[level] || ''}
45
- margin: 2.5rem 0 !important;
46
- font-weight: 400;
47
- `;
28
+ utils.getStyle((_, { css }) => {
29
+ const headingMap: Record<number, string> = {
30
+ 1: css`
31
+ font-size: 3rem;
32
+ line-height: 3.5rem;
33
+ `,
34
+ 2: css`
35
+ font-size: 2.5rem;
36
+ line-height: 3rem;
37
+ `,
38
+ 3: css`
39
+ font-size: 2.125rem;
40
+ line-height: 2.25rem;
41
+ `,
42
+ 4: css`
43
+ font-size: 1.75rem;
44
+ line-height: 2rem;
45
+ `,
46
+ 5: css`
47
+ font-size: 1.5rem;
48
+ line-height: 1.5rem;
49
+ `,
50
+ 6: css`
51
+ font-size: 1.25rem;
52
+ line-height: 1.25rem;
53
+ `,
54
+ };
55
+
56
+ return css`
57
+ ${headingMap[level] || ''}
58
+ margin: 2.5rem 0 !important;
59
+ font-weight: 400;
60
+ `;
61
+ });
48
62
 
49
63
  return {
50
64
  id,
@@ -53,15 +67,27 @@ export const heading = createNode<Keys>((utils, options) => {
53
67
  group: 'block',
54
68
  defining: true,
55
69
  attrs: {
70
+ id: {
71
+ default: '',
72
+ },
56
73
  level: {
57
74
  default: 1,
58
75
  },
59
76
  },
60
- parseDOM: headingIndex.map((x) => ({ tag: `h${x}`, attrs: { level: x } })),
77
+ parseDOM: headingIndex.map((x) => ({
78
+ tag: `h${x}`,
79
+ getAttrs: (node) => {
80
+ if (!(node instanceof HTMLElement)) {
81
+ throw new Error();
82
+ }
83
+ return { level: x, id: node.id };
84
+ },
85
+ })),
61
86
  toDOM: (node) => {
62
87
  return [
63
88
  `h${node.attrs.level}`,
64
89
  {
90
+ id: node.attrs.id || node.textContent.split(' ').join('-').toLocaleLowerCase(),
65
91
  class: utils.getClassName(node.attrs, `heading h${node.attrs.level}`, style(node.attrs.level)),
66
92
  },
67
93
  0,
@@ -100,5 +126,28 @@ export const heading = createNode<Keys>((utils, options) => {
100
126
  [SupportedKeys.H5]: createShortcut(TurnIntoHeading, 'Mod-Alt-5', 5),
101
127
  [SupportedKeys.H6]: createShortcut(TurnIntoHeading, 'Mod-Alt-6', 6),
102
128
  },
129
+ prosePlugins: (type) => [
130
+ new Plugin({
131
+ key: headingPluginKey,
132
+ appendTransaction: (transactions, _, nextState) => {
133
+ const tr = nextState.tr;
134
+ let modified = false;
135
+ if (transactions.some((transaction) => transaction.docChanged)) {
136
+ nextState.doc.descendants((node, pos) => {
137
+ if (node.type === type) {
138
+ const attrs = node.attrs;
139
+ tr.setNodeMarkup(pos, undefined, {
140
+ ...attrs,
141
+ id: node.textContent.split(' ').join('-').toLocaleLowerCase(),
142
+ });
143
+ modified = true;
144
+ }
145
+ });
146
+ }
147
+
148
+ return modified ? tr : null;
149
+ },
150
+ }),
151
+ ],
103
152
  };
104
153
  });
package/src/node/hr.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { css } from '@emotion/css';
3
2
  import { createCmd, createCmdKey, schemaCtx } from '@milkdown/core';
4
3
  import { InputRule, Selection } from '@milkdown/prose';
5
4
  import { createNode } from '@milkdown/utils';
@@ -8,7 +7,7 @@ const id = 'hr';
8
7
  export const InsertHr = createCmdKey<string>();
9
8
  export const hr = createNode((utils) => {
10
9
  const style = utils.getStyle(
11
- (themeTool) => css`
10
+ (themeTool, { css }) => css`
12
11
  height: ${themeTool.size.lineWidth};
13
12
  background-color: ${themeTool.palette('line')};
14
13
  border-width: 0;
package/src/node/image.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { css } from '@emotion/css';
3
2
  import { createCmd, createCmdKey, themeToolCtx } from '@milkdown/core';
4
3
  import type { Icon } from '@milkdown/design-system';
5
4
  import { findSelectedNodeOfType, InputRule } from '@milkdown/prose';
@@ -16,6 +15,7 @@ export type ImageOptions = {
16
15
  failed: string;
17
16
  };
18
17
  };
18
+
19
19
  export const image = createNode<string, ImageOptions>((utils, options) => {
20
20
  const placeholder = {
21
21
  loading: 'Loading...',
@@ -25,7 +25,7 @@ export const image = createNode<string, ImageOptions>((utils, options) => {
25
25
  };
26
26
  const isBlock = options?.isBlock ?? false;
27
27
  const containerStyle = utils.getStyle(
28
- (themeTool) =>
28
+ (themeTool, { css }) =>
29
29
  css`
30
30
  display: inline-block;
31
31
  position: relative;
@@ -123,7 +123,7 @@ export const image = createNode<string, ImageOptions>((utils, options) => {
123
123
  );
124
124
 
125
125
  const style = utils.getStyle(
126
- () =>
126
+ (_, { css }) =>
127
127
  css`
128
128
  display: inline-block;
129
129
  margin: 0 auto;
@@ -276,8 +276,11 @@ export const image = createNode<string, ImageOptions>((utils, options) => {
276
276
  img.src = src;
277
277
 
278
278
  img.onerror = () => {
279
+ const pos = getPos();
280
+ if (!pos) return;
281
+
279
282
  const { tr } = view.state;
280
- const _tr = tr.setNodeMarkup(getPos(), nodeType, {
283
+ const _tr = tr.setNodeMarkup(pos, nodeType, {
281
284
  ...node.attrs,
282
285
  src,
283
286
  loading: false,
@@ -288,7 +291,11 @@ export const image = createNode<string, ImageOptions>((utils, options) => {
288
291
 
289
292
  img.onload = () => {
290
293
  const { tr } = view.state;
291
- const _tr = tr.setNodeMarkup(getPos(), nodeType, {
294
+
295
+ const pos = getPos();
296
+ if (!pos) return;
297
+
298
+ const _tr = tr.setNodeMarkup(pos, nodeType, {
292
299
  ...node.attrs,
293
300
  width: img.width,
294
301
  src,
@@ -1,5 +1,4 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { css } from '@emotion/css';
3
2
  import { createCmd, createCmdKey } from '@milkdown/core';
4
3
  import { liftListItem, sinkListItem, splitListItem, wrappingInputRule } from '@milkdown/prose';
5
4
  import { createNode, createShortcut } from '@milkdown/utils';
@@ -16,7 +15,7 @@ export const LiftListItem = createCmdKey();
16
15
 
17
16
  export const listItem = createNode<Keys>((utils) => {
18
17
  const style = utils.getStyle(
19
- (themeTool) =>
18
+ (themeTool, { css }) =>
20
19
  css`
21
20
  &,
22
21
  & > * {
@@ -64,6 +64,6 @@ export const orderedList = createNode<Keys>((utils) => ({
64
64
  ],
65
65
  commands: (nodeType) => [createCmd(WrapInOrderedList, () => wrapIn(nodeType))],
66
66
  shortcuts: {
67
- [SupportedKeys.OrderedList]: createShortcut(WrapInOrderedList, 'Mod-Shift-7'),
67
+ [SupportedKeys.OrderedList]: createShortcut(WrapInOrderedList, 'Mod-Alt-7'),
68
68
  },
69
69
  }));
@@ -1,5 +1,4 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { css } from '@emotion/css';
3
2
  import { createCmd, createCmdKey } from '@milkdown/core';
4
3
  import { setBlockType } from '@milkdown/prose';
5
4
  import { createNode, createShortcut } from '@milkdown/utils';
@@ -11,14 +10,14 @@ type Keys = SupportedKeys['Text'];
11
10
  export const TurnIntoText = createCmdKey();
12
11
 
13
12
  const id = 'paragraph';
14
- export const paragraph = createNode<Keys>((utils, options) => {
15
- const style = options?.headless
16
- ? null
17
- : css`
18
- font-size: 1rem;
19
- line-height: 1.5;
20
- letter-spacing: 0.5px;
21
- `;
13
+ export const paragraph = createNode<Keys>((utils) => {
14
+ const style = utils.getStyle((_, { css }) => {
15
+ return css`
16
+ font-size: 1rem;
17
+ line-height: 1.5;
18
+ letter-spacing: 0.5px;
19
+ `;
20
+ });
22
21
 
23
22
  return {
24
23
  id,
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAmB3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AAEjC,eAAO,MAAM,eAAe;;gOAAwC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,eAAO,MAAM,UAAU;;gOAA8D,CAAC;AAEtF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;CAwBX,CAAC;AACX,oBAAY,QAAQ,GAAG,OAAO,QAAQ,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"code-inline.d.ts","sourceRoot":"","sources":["../../src/mark/code-inline.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,gBAAgB,4CAAiB,CAAC;AAE/C,eAAO,MAAM,UAAU;;;;EAyCrB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"em.d.ts","sourceRoot":"","sources":["../../src/mark/em.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,YAAY,4CAAiB,CAAC;AAE3C,eAAO,MAAM,EAAE;;;;EAgCZ,CAAC"}
@@ -1,6 +0,0 @@
1
- export declare const marks: (import("@milkdown/utils/lib/types").Metadata<import("@milkdown/utils/lib/types").GetPlugin<string, import("@milkdown/utils").UnknownRecord>> & import("@milkdown/core").MilkdownPlugin)[];
2
- export * from './code-inline';
3
- export * from './em';
4
- export * from './link';
5
- export * from './strong';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mark/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,KAAK,4LAAyC,CAAC;AAE5D,cAAc,eAAe,CAAC;AAC9B,cAAc,MAAM,CAAC;AACrB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/mark/link.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,UAAU,yCAAyB,CAAC;AACjD,eAAO,MAAM,UAAU,yCAAyB,CAAC;AAEjD,eAAO,MAAM,IAAI;;;;EA8Gf,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"strong.d.ts","sourceRoot":"","sources":["../../src/mark/strong.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,UAAU,4CAAiB,CAAC;AACzC,eAAO,MAAM,MAAM;;;;EAwCjB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"blockquote.d.ts","sourceRoot":"","sources":["../../src/node/blockquote.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,gBAAgB,4CAAiB,CAAC;AAE/C,eAAO,MAAM,UAAU;;;;EAyCrB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"bullet-list.d.ts","sourceRoot":"","sources":["../../src/node/bullet-list.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,gBAAgB,4CAAiB,CAAC;AAE/C,eAAO,MAAM,UAAU;;;;EA8BrB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"code-fence.d.ts","sourceRoot":"","sources":["../../src/node/code-fence.ts"],"names":[],"mappings":"AA6BA,eAAO,MAAM,kBAAkB,QAAoC,CAAC;AACpE,eAAO,MAAM,eAAe,QAAoC,CAAC;AAEjE,eAAO,MAAM,iBAAiB,4CAAiB,CAAC;AAGhD,eAAO,MAAM,SAAS;;;;;;EA2RpB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../../src/node/doc.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,GAAG;;;;EAoBd,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"hardbreak.d.ts","sourceRoot":"","sources":["../../src/node/hardbreak.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,eAAe,4CAAiB,CAAC;AAE9C,eAAO,MAAM,SAAS;;;;EAmEpB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../src/node/heading.ts"],"names":[],"mappings":"AAMA,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,CAAC;AAE1B,eAAO,MAAM,eAAe,yCAAyB,CAAC;AAEtD,eAAO,MAAM,OAAO;;;;EAiFlB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"hr.d.ts","sourceRoot":"","sources":["../../src/node/hr.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,QAAQ,yCAAyB,CAAC;AAC/C,eAAO,MAAM,EAAE;;;;EAyDb,CAAC"}