@milkdown/preset-commonmark 5.4.1 → 6.0.0-next.1
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.
- package/README.md +5 -4
- package/lib/index.d.ts +34 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.es.js +302 -555
- package/lib/index.es.js.map +1 -1
- package/lib/{src/mark → mark}/code-inline.d.ts +1 -1
- package/lib/mark/code-inline.d.ts.map +1 -0
- package/lib/{src/mark → mark}/em.d.ts +1 -1
- package/lib/mark/em.d.ts.map +1 -0
- package/lib/mark/index.d.ts +6 -0
- package/lib/mark/index.d.ts.map +1 -0
- package/lib/{src/mark → mark}/link.d.ts +7 -1
- package/lib/mark/link.d.ts.map +1 -0
- package/lib/{src/mark → mark}/strong.d.ts +1 -1
- package/lib/mark/strong.d.ts.map +1 -0
- package/lib/{src/node → node}/blockquote.d.ts +1 -1
- package/lib/node/blockquote.d.ts.map +1 -0
- package/lib/{src/node → node}/bullet-list.d.ts +1 -1
- package/lib/node/bullet-list.d.ts.map +1 -0
- package/lib/{src/node → node}/code-fence.d.ts +1 -1
- package/lib/node/code-fence.d.ts.map +1 -0
- package/lib/{src/node → node}/doc.d.ts +1 -1
- package/lib/node/doc.d.ts.map +1 -0
- package/lib/{src/node → node}/hardbreak.d.ts +1 -1
- package/lib/node/hardbreak.d.ts.map +1 -0
- package/lib/{src/node → node}/heading.d.ts +1 -1
- package/lib/node/heading.d.ts.map +1 -0
- package/lib/{src/node → node}/hr.d.ts +1 -1
- package/lib/node/hr.d.ts.map +1 -0
- package/lib/{src/node → node}/image.d.ts +5 -5
- package/lib/node/image.d.ts.map +1 -0
- package/lib/{src/node → node}/index.d.ts +2 -2
- package/lib/node/index.d.ts.map +1 -0
- package/lib/{src/node → node}/list-item.d.ts +1 -1
- package/lib/node/list-item.d.ts.map +1 -0
- package/lib/{src/node → node}/ordered-list.d.ts +1 -1
- package/lib/node/ordered-list.d.ts.map +1 -0
- package/lib/{src/node → node}/paragraph.d.ts +1 -1
- package/lib/node/paragraph.d.ts.map +1 -0
- package/lib/{src/node → node}/text.d.ts +1 -1
- package/lib/node/text.d.ts.map +1 -0
- package/lib/{src/plugin → plugin}/filter-html.d.ts +0 -0
- package/lib/plugin/filter-html.d.ts.map +1 -0
- package/lib/plugin/index.d.ts +2 -0
- package/lib/plugin/index.d.ts.map +1 -0
- package/lib/{src/supported-keys.d.ts → supported-keys.d.ts} +0 -0
- package/lib/supported-keys.d.ts.map +1 -0
- package/package.json +33 -10
- package/src/mark/code-inline.ts +2 -13
- package/src/mark/link.ts +96 -22
- package/src/mark/strong.ts +1 -7
- package/src/node/blockquote.ts +1 -14
- package/src/node/code-fence.ts +79 -187
- package/src/node/hardbreak.ts +2 -1
- package/src/node/heading.ts +14 -45
- package/src/node/hr.ts +1 -8
- package/src/node/image.ts +86 -238
- package/src/node/list-item.ts +34 -53
- package/src/node/ordered-list.ts +2 -2
- package/src/node/paragraph.ts +2 -10
- package/src/node/text.ts +1 -1
- package/src/plugin/filter-html.ts +10 -4
- package/lib/src/index.d.ts +0 -34
- package/lib/src/index.d.ts.map +0 -1
- package/lib/src/mark/code-inline.d.ts.map +0 -1
- package/lib/src/mark/em.d.ts.map +0 -1
- package/lib/src/mark/index.d.ts +0 -6
- package/lib/src/mark/index.d.ts.map +0 -1
- package/lib/src/mark/link.d.ts.map +0 -1
- package/lib/src/mark/strong.d.ts.map +0 -1
- package/lib/src/node/blockquote.d.ts.map +0 -1
- package/lib/src/node/bullet-list.d.ts.map +0 -1
- package/lib/src/node/code-fence.d.ts.map +0 -1
- package/lib/src/node/doc.d.ts.map +0 -1
- package/lib/src/node/hardbreak.d.ts.map +0 -1
- package/lib/src/node/heading.d.ts.map +0 -1
- package/lib/src/node/hr.d.ts.map +0 -1
- package/lib/src/node/image.d.ts.map +0 -1
- package/lib/src/node/index.d.ts.map +0 -1
- package/lib/src/node/list-item.d.ts.map +0 -1
- package/lib/src/node/ordered-list.d.ts.map +0 -1
- package/lib/src/node/paragraph.d.ts.map +0 -1
- package/lib/src/node/text.d.ts.map +0 -1
- package/lib/src/plugin/filter-html.d.ts.map +0 -1
- package/lib/src/plugin/index.d.ts +0 -2
- package/lib/src/plugin/index.d.ts.map +0 -1
- package/lib/src/supported-keys.d.ts.map +0 -1
- package/lib/src/types.d.ts +0 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/node/image.ts"],"names":[],"mappings":"AAKA,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;;;;EAiMhB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const nodes: ((import("@milkdown/utils/lib/
|
|
1
|
+
export declare const nodes: ((import("@milkdown/utils/lib/types").Metadata<import("@milkdown/utils/lib/types").GetPlugin<"CodeFence", {
|
|
2
2
|
languageList?: string[] | undefined;
|
|
3
|
-
}>> & import("@milkdown/core").MilkdownPlugin) | (import("@milkdown/utils/lib/
|
|
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))[];
|
|
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":["../../src/node/index.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,KAAK;;mOAajB,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/
|
|
6
|
+
export declare const listItem: import("@milkdown/utils/lib/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":["../../src/node/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,4CAAgC,CAAC;AAC3D,eAAO,MAAM,YAAY,4CAA+B,CAAC;AACzD,eAAO,MAAM,YAAY,4CAA+B,CAAC;AAEzD,eAAO,MAAM,QAAQ;;;;EAoClB,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/
|
|
2
|
+
export declare const orderedList: import("@milkdown/utils/lib/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":["../../src/node/ordered-list.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,iBAAiB,4CAAoC,CAAC;AAGnE,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/
|
|
2
|
+
export declare const paragraph: import("@milkdown/utils/lib/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":["../../src/node/paragraph.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,YAAY,4CAA+B,CAAC;AAGzD,eAAO,MAAM,SAAS;;;;EAkCpB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const text: import("@milkdown/utils/lib/
|
|
1
|
+
export declare const text: import("@milkdown/utils/lib/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":["../../src/node/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":["../../src/plugin/filter-html.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,IAAI,EAAU,MAAM,OAAO,CAAC;AAgC9C,eAAO,MAAM,gBAAgB,eACE,IAAI,SAUlC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,iBAAiB,4LAI7B,CAAC"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supported-keys.d.ts","sourceRoot":"","sources":["../src/supported-keys.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;CAmBhB,CAAC;AAEX,oBAAY,aAAa,GAAG,OAAO,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkdown/preset-commonmark",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-next.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.es.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -17,24 +17,47 @@
|
|
|
17
17
|
"commonmark"
|
|
18
18
|
],
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@milkdown/core": "
|
|
21
|
-
"@milkdown/prose": "
|
|
22
|
-
"@milkdown/design-system": "5.4.1"
|
|
20
|
+
"@milkdown/core": "6.0.0-next.1",
|
|
21
|
+
"@milkdown/prose": "6.0.0-next.1"
|
|
23
22
|
},
|
|
24
23
|
"peerDependencies": {
|
|
25
|
-
"@milkdown/core": "^
|
|
26
|
-
"@milkdown/prose": "^
|
|
24
|
+
"@milkdown/core": "^6.0.0-next.0",
|
|
25
|
+
"@milkdown/prose": "^6.0.0-next.0"
|
|
27
26
|
},
|
|
28
27
|
"dependencies": {
|
|
29
|
-
"@milkdown/utils": "
|
|
28
|
+
"@milkdown/utils": "6.0.0-next.1",
|
|
30
29
|
"remark-inline-links": "^6.0.0",
|
|
31
30
|
"tslib": "^2.3.1"
|
|
32
31
|
},
|
|
32
|
+
"nx": {
|
|
33
|
+
"targets": {
|
|
34
|
+
"build": {
|
|
35
|
+
"outputs": [
|
|
36
|
+
"packages/preset-commonmark/lib"
|
|
37
|
+
],
|
|
38
|
+
"dependsOn": [
|
|
39
|
+
{
|
|
40
|
+
"target": "build",
|
|
41
|
+
"projects": "dependencies"
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
"tsc": {
|
|
46
|
+
"outputs": [],
|
|
47
|
+
"dependsOn": [
|
|
48
|
+
{
|
|
49
|
+
"target": "build",
|
|
50
|
+
"projects": "dependencies"
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
33
56
|
"scripts": {
|
|
34
|
-
"start": "vite build --watch",
|
|
57
|
+
"start": "concurrently -n es,dts \"vite build --watch\" \"tsc --emitDeclarationOnly --watch\"",
|
|
35
58
|
"test": "vitest",
|
|
36
59
|
"tsc": "tsc --noEmit",
|
|
37
|
-
"build": "vite build"
|
|
60
|
+
"build": "vite build && tsc --emitDeclarationOnly"
|
|
38
61
|
},
|
|
39
|
-
"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
|
|
62
|
+
"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: The placeholder of empty status.\n- isBlock: Whether the image is a block (render as a row).\n- input:\n - placeholder: The placeholder of image url input.\n - buttonText: The button text of image url input.\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"
|
|
40
63
|
}
|
package/src/mark/code-inline.ts
CHANGED
|
@@ -11,17 +11,6 @@ const id = 'code_inline';
|
|
|
11
11
|
export const ToggleInlineCode = createCmdKey('ToggleInlineCode');
|
|
12
12
|
|
|
13
13
|
export const codeInline = createMark<Keys>((utils) => {
|
|
14
|
-
const style = utils.getStyle(
|
|
15
|
-
({ palette, size, font }, { css }) =>
|
|
16
|
-
css`
|
|
17
|
-
background-color: ${palette('neutral')};
|
|
18
|
-
color: ${palette('background')};
|
|
19
|
-
border-radius: ${size.radius};
|
|
20
|
-
font-weight: 500;
|
|
21
|
-
font-family: ${font.code};
|
|
22
|
-
padding: 0 0.2rem;
|
|
23
|
-
`,
|
|
24
|
-
);
|
|
25
14
|
return {
|
|
26
15
|
id,
|
|
27
16
|
schema: () => ({
|
|
@@ -29,12 +18,12 @@ export const codeInline = createMark<Keys>((utils) => {
|
|
|
29
18
|
code: true,
|
|
30
19
|
inclusive: false,
|
|
31
20
|
parseDOM: [{ tag: 'code' }],
|
|
32
|
-
toDOM: (mark) => ['code', { class: utils.getClassName(mark.attrs, 'code-inline'
|
|
21
|
+
toDOM: (mark) => ['code', { class: utils.getClassName(mark.attrs, 'code-inline') }],
|
|
33
22
|
parseMarkdown: {
|
|
34
23
|
match: (node) => node.type === 'inlineCode',
|
|
35
24
|
runner: (state, node, markType) => {
|
|
36
25
|
state.openMark(markType);
|
|
37
|
-
state.addText(node
|
|
26
|
+
state.addText(node['value'] as string);
|
|
38
27
|
state.closeMark(markType);
|
|
39
28
|
},
|
|
40
29
|
},
|
package/src/mark/link.ts
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { createCmd, createCmdKey, schemaCtx } from '@milkdown/core';
|
|
3
|
-
import {
|
|
2
|
+
import { commandsCtx, createCmd, createCmdKey, schemaCtx, ThemeInputChipType } from '@milkdown/core';
|
|
3
|
+
import {
|
|
4
|
+
EditorView,
|
|
5
|
+
InputRule,
|
|
6
|
+
Node as ProseNode,
|
|
7
|
+
Plugin,
|
|
8
|
+
PluginKey,
|
|
9
|
+
TextSelection,
|
|
10
|
+
toggleMark,
|
|
11
|
+
} from '@milkdown/prose';
|
|
4
12
|
import { createMark } from '@milkdown/utils';
|
|
5
13
|
|
|
14
|
+
const key = new PluginKey('MILKDOWN_PLUGIN_LINK_INPUT');
|
|
15
|
+
|
|
6
16
|
export const ToggleLink = createCmdKey<string>('ToggleLink');
|
|
7
17
|
export const ModifyLink = createCmdKey<string>('ModifyLink');
|
|
8
18
|
const id = 'link';
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
transition: all 0.4s ease-in-out;
|
|
17
|
-
font-weight: 500;
|
|
18
|
-
&:hover {
|
|
19
|
-
background-color: ${lineColor};
|
|
20
|
-
box-shadow: 0 0.2rem ${lineColor}, 0 -0.2rem ${lineColor};
|
|
21
|
-
}
|
|
22
|
-
`;
|
|
23
|
-
});
|
|
19
|
+
export type LinkOptions = {
|
|
20
|
+
input: {
|
|
21
|
+
placeholder: string;
|
|
22
|
+
buttonText?: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export const link = createMark<string, LinkOptions>((utils, options) => {
|
|
24
26
|
return {
|
|
25
27
|
id,
|
|
26
28
|
schema: () => ({
|
|
@@ -40,12 +42,12 @@ export const link = createMark((utils) => {
|
|
|
40
42
|
},
|
|
41
43
|
},
|
|
42
44
|
],
|
|
43
|
-
toDOM: (mark) => ['a', { ...mark.attrs, class: utils.getClassName(mark.attrs, id
|
|
45
|
+
toDOM: (mark) => ['a', { ...mark.attrs, class: utils.getClassName(mark.attrs, id) }],
|
|
44
46
|
parseMarkdown: {
|
|
45
47
|
match: (node) => node.type === 'link',
|
|
46
48
|
runner: (state, node, markType) => {
|
|
47
|
-
const url = node
|
|
48
|
-
const title = node
|
|
49
|
+
const url = node['url'] as string;
|
|
50
|
+
const title = node['title'] as string;
|
|
49
51
|
state.openMark(markType, { href: url, title });
|
|
50
52
|
state.next(node.children);
|
|
51
53
|
state.closeMark(markType);
|
|
@@ -55,8 +57,8 @@ export const link = createMark((utils) => {
|
|
|
55
57
|
match: (mark) => mark.type.name === id,
|
|
56
58
|
runner: (state, mark) => {
|
|
57
59
|
state.withMark(mark, 'link', undefined, {
|
|
58
|
-
title: mark.attrs
|
|
59
|
-
url: mark.attrs
|
|
60
|
+
title: mark.attrs['title'],
|
|
61
|
+
url: mark.attrs['href'],
|
|
60
62
|
});
|
|
61
63
|
},
|
|
62
64
|
},
|
|
@@ -115,5 +117,77 @@ export const link = createMark((utils) => {
|
|
|
115
117
|
return tr;
|
|
116
118
|
}),
|
|
117
119
|
],
|
|
120
|
+
prosePlugins: (type, ctx) => {
|
|
121
|
+
const inputChipRenderer = utils.themeManager.get<ThemeInputChipType>('input-chip', {
|
|
122
|
+
placeholder: options?.input?.placeholder ?? 'Input Web Link',
|
|
123
|
+
buttonText: options?.input?.buttonText,
|
|
124
|
+
onUpdate: (value) => {
|
|
125
|
+
ctx.get(commandsCtx).call(ModifyLink, value);
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
const shouldDisplay = (view: EditorView) => {
|
|
129
|
+
const { selection, doc } = view.state;
|
|
130
|
+
const { from, to } = selection;
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
selection.empty &&
|
|
134
|
+
selection instanceof TextSelection &&
|
|
135
|
+
doc.rangeHasMark(from, from === to ? to + 1 : to, type)
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
const getCurrentLink = (view: EditorView) => {
|
|
139
|
+
const { selection } = view.state;
|
|
140
|
+
let node: ProseNode | undefined;
|
|
141
|
+
const { from, to } = selection;
|
|
142
|
+
view.state.doc.nodesBetween(from, from === to ? to + 1 : to, (n) => {
|
|
143
|
+
if (type.isInSet(n.marks)) {
|
|
144
|
+
node = n;
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
return;
|
|
148
|
+
});
|
|
149
|
+
if (!node) return;
|
|
150
|
+
|
|
151
|
+
const mark = node.marks.find((m) => m.type === type);
|
|
152
|
+
if (!mark) return;
|
|
153
|
+
|
|
154
|
+
const value = mark.attrs['href'];
|
|
155
|
+
return value;
|
|
156
|
+
};
|
|
157
|
+
const renderByView = (view: EditorView) => {
|
|
158
|
+
if (!view.editable) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const display = shouldDisplay(view);
|
|
162
|
+
if (display) {
|
|
163
|
+
inputChipRenderer.show(view);
|
|
164
|
+
inputChipRenderer.update(getCurrentLink(view));
|
|
165
|
+
} else {
|
|
166
|
+
inputChipRenderer.hide();
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
return [
|
|
170
|
+
new Plugin({
|
|
171
|
+
key,
|
|
172
|
+
view: (editorView) => {
|
|
173
|
+
inputChipRenderer.init(editorView);
|
|
174
|
+
renderByView(editorView);
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
update: (view, prevState) => {
|
|
178
|
+
const isEqualSelection =
|
|
179
|
+
prevState?.doc.eq(view.state.doc) && prevState.selection.eq(view.state.selection);
|
|
180
|
+
if (isEqualSelection) return;
|
|
181
|
+
|
|
182
|
+
renderByView(view);
|
|
183
|
+
},
|
|
184
|
+
destroy: () => {
|
|
185
|
+
inputChipRenderer.destroy();
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
}),
|
|
190
|
+
];
|
|
191
|
+
},
|
|
118
192
|
};
|
|
119
193
|
});
|
package/src/mark/strong.ts
CHANGED
|
@@ -9,12 +9,6 @@ type Keys = SupportedKeys['Bold'];
|
|
|
9
9
|
const id = 'strong';
|
|
10
10
|
export const ToggleBold = createCmdKey('ToggleBold');
|
|
11
11
|
export const strong = createMark<Keys>((utils) => {
|
|
12
|
-
const style = utils.getStyle(
|
|
13
|
-
(_, { css }) =>
|
|
14
|
-
css`
|
|
15
|
-
font-weight: 600;
|
|
16
|
-
`,
|
|
17
|
-
);
|
|
18
12
|
return {
|
|
19
13
|
id,
|
|
20
14
|
schema: () => ({
|
|
@@ -23,7 +17,7 @@ export const strong = createMark<Keys>((utils) => {
|
|
|
23
17
|
{ tag: 'strong' },
|
|
24
18
|
{ style: 'font-style', getAttrs: (value) => (value === 'bold') as false },
|
|
25
19
|
],
|
|
26
|
-
toDOM: (mark) => ['strong', { class: utils.getClassName(mark.attrs, id
|
|
20
|
+
toDOM: (mark) => ['strong', { class: utils.getClassName(mark.attrs, id) }],
|
|
27
21
|
parseMarkdown: {
|
|
28
22
|
match: (node) => node.type === 'strong',
|
|
29
23
|
runner: (state, node, markType) => {
|
package/src/node/blockquote.ts
CHANGED
|
@@ -12,19 +12,6 @@ const id = 'blockquote';
|
|
|
12
12
|
export const WrapInBlockquote = createCmdKey('WrapInBlockquote');
|
|
13
13
|
|
|
14
14
|
export const blockquote = createNode<Keys>((utils) => {
|
|
15
|
-
const style = utils.getStyle(
|
|
16
|
-
(themeTool, { css }) =>
|
|
17
|
-
css`
|
|
18
|
-
padding-left: 1.875rem;
|
|
19
|
-
line-height: 1.75rem;
|
|
20
|
-
border-left: 4px solid ${themeTool.palette('primary')};
|
|
21
|
-
* {
|
|
22
|
-
font-size: 1rem;
|
|
23
|
-
line-height: 1.5rem;
|
|
24
|
-
}
|
|
25
|
-
`,
|
|
26
|
-
);
|
|
27
|
-
|
|
28
15
|
return {
|
|
29
16
|
id,
|
|
30
17
|
schema: () => ({
|
|
@@ -32,7 +19,7 @@ export const blockquote = createNode<Keys>((utils) => {
|
|
|
32
19
|
group: 'block',
|
|
33
20
|
defining: true,
|
|
34
21
|
parseDOM: [{ tag: 'blockquote' }],
|
|
35
|
-
toDOM: (node) => ['blockquote', { class: utils.getClassName(node.attrs, id
|
|
22
|
+
toDOM: (node) => ['blockquote', { class: utils.getClassName(node.attrs, id) }, 0],
|
|
36
23
|
parseMarkdown: {
|
|
37
24
|
match: ({ type }) => type === id,
|
|
38
25
|
runner: (state, node, type) => {
|