draftly 1.0.7 → 2.0.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.
- package/README.md +12 -0
- package/dist/chunk-3T55CBNZ.cjs +33 -0
- package/dist/chunk-3T55CBNZ.cjs.map +1 -0
- package/dist/chunk-5MC4T7JH.cjs +58 -0
- package/dist/chunk-5MC4T7JH.cjs.map +1 -0
- package/dist/{chunk-72ZYRGRT.cjs → chunk-BWJLMREN.cjs} +11 -9
- package/dist/chunk-BWJLMREN.cjs.map +1 -0
- package/dist/{chunk-KBQDZ5IW.cjs → chunk-CLW73JRX.cjs} +100 -75
- package/dist/chunk-CLW73JRX.cjs.map +1 -0
- package/dist/{chunk-DFQYXFOP.js → chunk-EEHILRG5.js} +26 -3
- package/dist/chunk-EEHILRG5.js.map +1 -0
- package/dist/{chunk-HPSMS2WB.js → chunk-I563H35S.js} +101 -75
- package/dist/chunk-I563H35S.js.map +1 -0
- package/dist/chunk-IAXF4SJL.js +55 -0
- package/dist/chunk-IAXF4SJL.js.map +1 -0
- package/dist/chunk-JF3WXXMJ.js +31 -0
- package/dist/chunk-JF3WXXMJ.js.map +1 -0
- package/dist/{chunk-N3WL3XPB.js → chunk-L2XSK57Y.js} +1761 -478
- package/dist/chunk-L2XSK57Y.js.map +1 -0
- package/dist/{chunk-KDEDLC3D.cjs → chunk-TBVZEK2H.cjs} +27 -2
- package/dist/chunk-TBVZEK2H.cjs.map +1 -0
- package/dist/{chunk-2B3A3VSQ.cjs → chunk-W5ALMXG2.cjs} +1808 -504
- package/dist/chunk-W5ALMXG2.cjs.map +1 -0
- package/dist/{chunk-CG4M4TC7.js → chunk-ZUI3GI3W.js} +7 -5
- package/dist/chunk-ZUI3GI3W.js.map +1 -0
- package/dist/{draftly-BLnx3uGX.d.cts → draftly-BBL-AdOl.d.cts} +5 -1
- package/dist/{draftly-BLnx3uGX.d.ts → draftly-BBL-AdOl.d.ts} +5 -1
- package/dist/editor/index.cjs +22 -14
- package/dist/editor/index.d.cts +2 -1
- package/dist/editor/index.d.ts +2 -1
- package/dist/editor/index.js +2 -2
- package/dist/index.cjs +65 -39
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +6 -4
- package/dist/lib/index.cjs +12 -0
- package/dist/lib/index.cjs.map +1 -0
- package/dist/lib/index.d.cts +16 -0
- package/dist/lib/index.d.ts +16 -0
- package/dist/lib/index.js +3 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/plugins/index.cjs +27 -17
- package/dist/plugins/index.d.cts +144 -9
- package/dist/plugins/index.d.ts +144 -9
- package/dist/plugins/index.js +5 -3
- package/dist/preview/index.cjs +16 -11
- package/dist/preview/index.d.cts +19 -4
- package/dist/preview/index.d.ts +19 -4
- package/dist/preview/index.js +3 -2
- package/package.json +8 -1
- package/src/editor/draftly.ts +1 -0
- package/src/editor/plugin.ts +5 -1
- package/src/editor/theme.ts +1 -0
- package/src/editor/utils.ts +31 -0
- package/src/index.ts +5 -4
- package/src/lib/index.ts +2 -0
- package/src/lib/input-handler.ts +45 -0
- package/src/plugins/code-plugin.theme.ts +426 -0
- package/src/plugins/code-plugin.ts +810 -561
- package/src/plugins/emoji-plugin.ts +140 -0
- package/src/plugins/index.ts +63 -57
- package/src/plugins/inline-plugin.ts +305 -291
- package/src/plugins/math-plugin.ts +12 -0
- package/src/plugins/table-plugin.ts +900 -0
- package/src/preview/context.ts +4 -1
- package/src/preview/css-generator.ts +14 -1
- package/src/preview/index.ts +9 -1
- package/src/preview/preview.ts +2 -1
- package/src/preview/renderer.ts +21 -20
- package/src/preview/syntax-theme.ts +110 -0
- package/src/preview/types.ts +14 -0
- package/dist/chunk-2B3A3VSQ.cjs.map +0 -1
- package/dist/chunk-72ZYRGRT.cjs.map +0 -1
- package/dist/chunk-CG4M4TC7.js.map +0 -1
- package/dist/chunk-DFQYXFOP.js.map +0 -1
- package/dist/chunk-HPSMS2WB.js.map +0 -1
- package/dist/chunk-KBQDZ5IW.cjs.map +0 -1
- package/dist/chunk-KDEDLC3D.cjs.map +0 -1
- package/dist/chunk-N3WL3XPB.js.map +0 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Decoration, WidgetType } from "@codemirror/view";
|
|
2
|
+
import { syntaxTree } from "@codemirror/language";
|
|
3
|
+
import { DecorationContext, DecorationPlugin } from "../editor/plugin";
|
|
4
|
+
import { createTheme } from "../editor";
|
|
5
|
+
import { SyntaxNode } from "@lezer/common";
|
|
6
|
+
import * as emoji from "node-emoji";
|
|
7
|
+
|
|
8
|
+
function shortcodeToEmoji(raw: string): string | null {
|
|
9
|
+
const rendered = emoji.emojify(raw);
|
|
10
|
+
return rendered !== raw ? rendered : null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class EmojiWidget extends WidgetType {
|
|
14
|
+
constructor(readonly rendered: string) {
|
|
15
|
+
super();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override eq(other: EmojiWidget): boolean {
|
|
19
|
+
return other.rendered === this.rendered;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
toDOM() {
|
|
23
|
+
const span = document.createElement("span");
|
|
24
|
+
span.className = "cm-draftly-emoji";
|
|
25
|
+
span.textContent = this.rendered;
|
|
26
|
+
return span;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
override ignoreEvent(): boolean {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Mark decorations for emoji syntax elements
|
|
36
|
+
*/
|
|
37
|
+
const emojiMarkDecorations = {
|
|
38
|
+
"emoji-source": Decoration.mark({ class: "cm-draftly-emoji-source" }),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* EmojiPlugin - Decorates markdown emojis
|
|
43
|
+
*
|
|
44
|
+
* Parses and decorates emoji shortcodes like :smile:
|
|
45
|
+
* - Converts valid shortcodes to Unicode emoji when cursor is outside
|
|
46
|
+
* - Keeps raw shortcode visible while editing (cursor inside token)
|
|
47
|
+
*/
|
|
48
|
+
export class EmojiPlugin extends DecorationPlugin {
|
|
49
|
+
readonly name = "emoji";
|
|
50
|
+
readonly version = "1.0.0";
|
|
51
|
+
override decorationPriority = 20;
|
|
52
|
+
override readonly requiredNodes = ["Emoji", "EmojiMark"] as const;
|
|
53
|
+
|
|
54
|
+
constructor() {
|
|
55
|
+
super();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Plugin theme
|
|
60
|
+
*/
|
|
61
|
+
override get theme() {
|
|
62
|
+
return theme;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Build emoji decorations by iterating the syntax tree
|
|
67
|
+
*/
|
|
68
|
+
buildDecorations(ctx: DecorationContext): void {
|
|
69
|
+
const { view, decorations } = ctx;
|
|
70
|
+
const tree = syntaxTree(view.state);
|
|
71
|
+
|
|
72
|
+
tree.iterate({
|
|
73
|
+
enter: (node) => {
|
|
74
|
+
const { from, to, name } = node;
|
|
75
|
+
|
|
76
|
+
if (name !== "Emoji") {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const raw = view.state.sliceDoc(from, to);
|
|
81
|
+
const rendered = shortcodeToEmoji(raw);
|
|
82
|
+
if (!rendered) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const cursorInNode = ctx.selectionOverlapsRange(from, to);
|
|
87
|
+
if (cursorInNode) {
|
|
88
|
+
decorations.push(emojiMarkDecorations["emoji-source"].range(from, to));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
decorations.push(
|
|
93
|
+
Decoration.replace({
|
|
94
|
+
widget: new EmojiWidget(rendered),
|
|
95
|
+
}).range(from, to)
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
override renderToHTML(
|
|
102
|
+
node: SyntaxNode,
|
|
103
|
+
children: string,
|
|
104
|
+
ctx: {
|
|
105
|
+
sliceDoc(from: number, to: number): string;
|
|
106
|
+
sanitize(html: string): string;
|
|
107
|
+
syntaxHighlighters?: readonly import("@lezer/highlight").Highlighter[];
|
|
108
|
+
}
|
|
109
|
+
): string | null {
|
|
110
|
+
if (node.name === "EmojiMark") {
|
|
111
|
+
return "";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (node.name !== "Emoji") {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const raw = ctx.sliceDoc(node.from, node.to);
|
|
119
|
+
const rendered = shortcodeToEmoji(raw);
|
|
120
|
+
if (!rendered) {
|
|
121
|
+
return `<span class="cm-draftly-emoji-source">${children}</span>`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return `<span class="cm-draftly-emoji">${rendered}</span>`;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const theme = createTheme({
|
|
129
|
+
default: {
|
|
130
|
+
".cm-draftly-emoji": {
|
|
131
|
+
fontFamily: '"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Segoe UI Symbol", sans-serif',
|
|
132
|
+
fontVariantEmoji: "emoji",
|
|
133
|
+
lineHeight: "1.2",
|
|
134
|
+
},
|
|
135
|
+
".cm-draftly-emoji-source": {
|
|
136
|
+
fontFamily: "inherit",
|
|
137
|
+
lineHeight: "inherit",
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
});
|
package/src/plugins/index.ts
CHANGED
|
@@ -1,57 +1,63 @@
|
|
|
1
|
-
// Re-export individual plugins
|
|
2
|
-
export { ParagraphPlugin } from "./paragraph-plugin";
|
|
3
|
-
export { HeadingPlugin } from "./heading-plugin";
|
|
4
|
-
export { InlinePlugin } from "./inline-plugin";
|
|
5
|
-
export { LinkPlugin } from "./link-plugin";
|
|
6
|
-
export { ListPlugin } from "./list-plugin";
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
new
|
|
41
|
-
new
|
|
42
|
-
new
|
|
43
|
-
new
|
|
44
|
-
new
|
|
45
|
-
new
|
|
46
|
-
new
|
|
47
|
-
new
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
1
|
+
// Re-export individual plugins
|
|
2
|
+
export { ParagraphPlugin } from "./paragraph-plugin";
|
|
3
|
+
export { HeadingPlugin } from "./heading-plugin";
|
|
4
|
+
export { InlinePlugin } from "./inline-plugin";
|
|
5
|
+
export { LinkPlugin } from "./link-plugin";
|
|
6
|
+
export { ListPlugin } from "./list-plugin";
|
|
7
|
+
export { TablePlugin } from "./table-plugin";
|
|
8
|
+
export { HTMLPlugin } from "./html-plugin";
|
|
9
|
+
export { ImagePlugin } from "./image-plugin";
|
|
10
|
+
export { MathPlugin } from "./math-plugin";
|
|
11
|
+
export { MermaidPlugin } from "./mermaid-plugin";
|
|
12
|
+
export { CodePlugin } from "./code-plugin";
|
|
13
|
+
export { QuotePlugin } from "./quote-plugin";
|
|
14
|
+
export { HRPlugin } from "./hr-plugin";
|
|
15
|
+
export { EmojiPlugin } from "./emoji-plugin";
|
|
16
|
+
|
|
17
|
+
// Plugin collections
|
|
18
|
+
import { DraftlyPlugin } from "../editor/plugin";
|
|
19
|
+
import { ParagraphPlugin } from "./paragraph-plugin";
|
|
20
|
+
import { HeadingPlugin } from "./heading-plugin";
|
|
21
|
+
import { InlinePlugin } from "./inline-plugin";
|
|
22
|
+
import { LinkPlugin } from "./link-plugin";
|
|
23
|
+
import { ListPlugin } from "./list-plugin";
|
|
24
|
+
import { TablePlugin } from "./table-plugin";
|
|
25
|
+
import { HTMLPlugin } from "./html-plugin";
|
|
26
|
+
import { ImagePlugin } from "./image-plugin";
|
|
27
|
+
import { MathPlugin } from "./math-plugin";
|
|
28
|
+
import { MermaidPlugin } from "./mermaid-plugin";
|
|
29
|
+
import { CodePlugin } from "./code-plugin";
|
|
30
|
+
import { QuotePlugin } from "./quote-plugin";
|
|
31
|
+
import { HRPlugin } from "./hr-plugin";
|
|
32
|
+
import { EmojiPlugin } from "./emoji-plugin";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Default plugins
|
|
36
|
+
*
|
|
37
|
+
* This is the set of essential plugins
|
|
38
|
+
*/
|
|
39
|
+
const essentialPlugins: DraftlyPlugin[] = [
|
|
40
|
+
new ParagraphPlugin(),
|
|
41
|
+
new HeadingPlugin(),
|
|
42
|
+
new InlinePlugin(),
|
|
43
|
+
new LinkPlugin(),
|
|
44
|
+
new ListPlugin(),
|
|
45
|
+
new TablePlugin(),
|
|
46
|
+
new HTMLPlugin(),
|
|
47
|
+
new ImagePlugin(),
|
|
48
|
+
new MathPlugin(),
|
|
49
|
+
new MermaidPlugin(),
|
|
50
|
+
new CodePlugin(),
|
|
51
|
+
new QuotePlugin(),
|
|
52
|
+
new HRPlugin(),
|
|
53
|
+
new EmojiPlugin(),
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* All plugins
|
|
58
|
+
*
|
|
59
|
+
* This is the set of all plugins available with draftly
|
|
60
|
+
*/
|
|
61
|
+
const allPlugins: DraftlyPlugin[] = [...essentialPlugins];
|
|
62
|
+
|
|
63
|
+
export { essentialPlugins, allPlugins };
|