draftly 1.0.0-alpha.2 → 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.
Files changed (79) hide show
  1. package/README.md +12 -0
  2. package/dist/chunk-3T55CBNZ.cjs +33 -0
  3. package/dist/chunk-3T55CBNZ.cjs.map +1 -0
  4. package/dist/chunk-5MC4T7JH.cjs +58 -0
  5. package/dist/chunk-5MC4T7JH.cjs.map +1 -0
  6. package/dist/{chunk-72ZYRGRT.cjs → chunk-BWJLMREN.cjs} +11 -9
  7. package/dist/chunk-BWJLMREN.cjs.map +1 -0
  8. package/dist/{chunk-KBQDZ5IW.cjs → chunk-CLW73JRX.cjs} +100 -75
  9. package/dist/chunk-CLW73JRX.cjs.map +1 -0
  10. package/dist/{chunk-DFQYXFOP.js → chunk-EEHILRG5.js} +26 -3
  11. package/dist/chunk-EEHILRG5.js.map +1 -0
  12. package/dist/{chunk-HPSMS2WB.js → chunk-I563H35S.js} +101 -75
  13. package/dist/chunk-I563H35S.js.map +1 -0
  14. package/dist/chunk-IAXF4SJL.js +55 -0
  15. package/dist/chunk-IAXF4SJL.js.map +1 -0
  16. package/dist/chunk-JF3WXXMJ.js +31 -0
  17. package/dist/chunk-JF3WXXMJ.js.map +1 -0
  18. package/dist/{chunk-N3WL3XPB.js → chunk-L2XSK57Y.js} +1761 -478
  19. package/dist/chunk-L2XSK57Y.js.map +1 -0
  20. package/dist/{chunk-KDEDLC3D.cjs → chunk-TBVZEK2H.cjs} +27 -2
  21. package/dist/chunk-TBVZEK2H.cjs.map +1 -0
  22. package/dist/{chunk-2B3A3VSQ.cjs → chunk-W5ALMXG2.cjs} +1808 -504
  23. package/dist/chunk-W5ALMXG2.cjs.map +1 -0
  24. package/dist/{chunk-CG4M4TC7.js → chunk-ZUI3GI3W.js} +7 -5
  25. package/dist/chunk-ZUI3GI3W.js.map +1 -0
  26. package/dist/{draftly-BLnx3uGX.d.cts → draftly-BBL-AdOl.d.cts} +5 -1
  27. package/dist/{draftly-BLnx3uGX.d.ts → draftly-BBL-AdOl.d.ts} +5 -1
  28. package/dist/editor/index.cjs +22 -14
  29. package/dist/editor/index.d.cts +2 -1
  30. package/dist/editor/index.d.ts +2 -1
  31. package/dist/editor/index.js +2 -2
  32. package/dist/index.cjs +65 -39
  33. package/dist/index.d.cts +6 -3
  34. package/dist/index.d.ts +6 -3
  35. package/dist/index.js +6 -4
  36. package/dist/lib/index.cjs +12 -0
  37. package/dist/lib/index.cjs.map +1 -0
  38. package/dist/lib/index.d.cts +16 -0
  39. package/dist/lib/index.d.ts +16 -0
  40. package/dist/lib/index.js +3 -0
  41. package/dist/lib/index.js.map +1 -0
  42. package/dist/plugins/index.cjs +27 -17
  43. package/dist/plugins/index.d.cts +144 -9
  44. package/dist/plugins/index.d.ts +144 -9
  45. package/dist/plugins/index.js +5 -3
  46. package/dist/preview/index.cjs +16 -11
  47. package/dist/preview/index.d.cts +19 -4
  48. package/dist/preview/index.d.ts +19 -4
  49. package/dist/preview/index.js +3 -2
  50. package/package.json +8 -1
  51. package/src/editor/draftly.ts +1 -0
  52. package/src/editor/plugin.ts +5 -1
  53. package/src/editor/theme.ts +1 -0
  54. package/src/editor/utils.ts +31 -0
  55. package/src/index.ts +5 -4
  56. package/src/lib/index.ts +2 -0
  57. package/src/lib/input-handler.ts +45 -0
  58. package/src/plugins/code-plugin.theme.ts +426 -0
  59. package/src/plugins/code-plugin.ts +810 -561
  60. package/src/plugins/emoji-plugin.ts +140 -0
  61. package/src/plugins/index.ts +63 -57
  62. package/src/plugins/inline-plugin.ts +305 -291
  63. package/src/plugins/math-plugin.ts +12 -0
  64. package/src/plugins/table-plugin.ts +900 -0
  65. package/src/preview/context.ts +4 -1
  66. package/src/preview/css-generator.ts +14 -1
  67. package/src/preview/index.ts +9 -1
  68. package/src/preview/preview.ts +2 -1
  69. package/src/preview/renderer.ts +21 -20
  70. package/src/preview/syntax-theme.ts +110 -0
  71. package/src/preview/types.ts +14 -0
  72. package/dist/chunk-2B3A3VSQ.cjs.map +0 -1
  73. package/dist/chunk-72ZYRGRT.cjs.map +0 -1
  74. package/dist/chunk-CG4M4TC7.js.map +0 -1
  75. package/dist/chunk-DFQYXFOP.js.map +0 -1
  76. package/dist/chunk-HPSMS2WB.js.map +0 -1
  77. package/dist/chunk-KBQDZ5IW.cjs.map +0 -1
  78. package/dist/chunk-KDEDLC3D.cjs.map +0 -1
  79. 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
+ });
@@ -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 { HTMLPlugin } from "./html-plugin";
8
- export { ImagePlugin } from "./image-plugin";
9
- export { MathPlugin } from "./math-plugin";
10
- export { MermaidPlugin } from "./mermaid-plugin";
11
- export { CodePlugin } from "./code-plugin";
12
- export { QuotePlugin } from "./quote-plugin";
13
- export { HRPlugin } from "./hr-plugin";
14
-
15
- // Plugin collections
16
- import { DraftlyPlugin } from "../editor/plugin";
17
- import { ParagraphPlugin } from "./paragraph-plugin";
18
- import { HeadingPlugin } from "./heading-plugin";
19
- import { InlinePlugin } from "./inline-plugin";
20
- import { LinkPlugin } from "./link-plugin";
21
- import { ListPlugin } from "./list-plugin";
22
- import { HTMLPlugin } from "./html-plugin";
23
- import { ImagePlugin } from "./image-plugin";
24
- import { MathPlugin } from "./math-plugin";
25
- import { MermaidPlugin } from "./mermaid-plugin";
26
- import { CodePlugin } from "./code-plugin";
27
- import { QuotePlugin } from "./quote-plugin";
28
- import { HRPlugin } from "./hr-plugin";
29
-
30
- /**
31
- * Default plugins
32
- *
33
- * This is the set of essential plugins
34
- */
35
- const essentialPlugins: DraftlyPlugin[] = [
36
- new ParagraphPlugin(),
37
- new HeadingPlugin(),
38
- new InlinePlugin(),
39
- new LinkPlugin(),
40
- new ListPlugin(),
41
- new HTMLPlugin(),
42
- new ImagePlugin(),
43
- new MathPlugin(),
44
- new MermaidPlugin(),
45
- new CodePlugin(),
46
- new QuotePlugin(),
47
- new HRPlugin(),
48
- ];
49
-
50
- /**
51
- * All plugins
52
- *
53
- * This is the set of all plugins available with draftly
54
- */
55
- const allPlugins: DraftlyPlugin[] = [...essentialPlugins];
56
-
57
- export { essentialPlugins, allPlugins };
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 };