@clevertask/scribe 0.0.15 → 0.1.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 (61) hide show
  1. package/README.md +21 -15
  2. package/dist/BarMenu-BDtEfu-R.js +327 -0
  3. package/dist/assets/index.css +1 -1
  4. package/dist/components/Menu/BarMenu.d.ts +0 -1
  5. package/dist/components/Menu/BarMenu.d.ts.map +1 -1
  6. package/dist/components/Menu/BarMenu.js +8 -140
  7. package/dist/components/Menu/BubbleMenu.d.ts.map +1 -1
  8. package/dist/components/Menu/BubbleMenu.js +2070 -159
  9. package/dist/components/Menu/Mobile/ListOptionBar.d.ts.map +1 -1
  10. package/dist/components/Menu/Mobile/ListOptionBar.js +42 -22
  11. package/dist/components/Scribe/extension/emoji/EmojiList.d.ts +19 -1
  12. package/dist/components/Scribe/extension/emoji/EmojiList.d.ts.map +1 -1
  13. package/dist/components/Scribe/extension/emoji/EmojiList.js +42 -42
  14. package/dist/components/Scribe/extension/emoji/suggest.d.ts +2 -4
  15. package/dist/components/Scribe/extension/emoji/suggest.d.ts.map +1 -1
  16. package/dist/components/Scribe/extension/emoji/suggest.js +20 -15
  17. package/dist/components/Scribe/extension/extension-link.js +2 -984
  18. package/dist/components/Scribe/extension/extension-markdown-paste.js +4 -4
  19. package/dist/components/Scribe/extension/extension-selectedText.js +1 -1
  20. package/dist/components/Scribe/extension/getPopupMountTarget.d.ts +3 -0
  21. package/dist/components/Scribe/extension/getPopupMountTarget.d.ts.map +1 -0
  22. package/dist/components/Scribe/extension/getPopupMountTarget.js +16 -0
  23. package/dist/components/Scribe/extension/index.d.ts +1 -1
  24. package/dist/components/Scribe/extension/index.d.ts.map +1 -1
  25. package/dist/components/Scribe/extension/index.js +37047 -34
  26. package/dist/components/Scribe/extension/slashCommand/SlashCommandList.d.ts +4 -1
  27. package/dist/components/Scribe/extension/slashCommand/SlashCommandList.d.ts.map +1 -1
  28. package/dist/components/Scribe/extension/slashCommand/SlashCommandList.js +3732 -14
  29. package/dist/components/Scribe/extension/slashCommand/index.js +2 -2
  30. package/dist/components/Scribe/extension/slashCommand/renderItems.d.ts +1 -1
  31. package/dist/components/Scribe/extension/slashCommand/renderItems.d.ts.map +1 -1
  32. package/dist/components/Scribe/extension/slashCommand/renderItems.js +21 -16
  33. package/dist/components/Scribe/index.d.ts +0 -1
  34. package/dist/components/Scribe/index.d.ts.map +1 -1
  35. package/dist/components/Scribe/index.js +85 -82
  36. package/dist/extension-link-D3eyOFkn.js +1030 -0
  37. package/dist/icons/ToolbarIcons.d.ts +19 -0
  38. package/dist/icons/ToolbarIcons.d.ts.map +1 -0
  39. package/dist/icons/ToolbarIcons.js +135 -0
  40. package/dist/index-DZylq4Bc.js +232 -0
  41. package/dist/index-FY_iYS6i.js +1410 -0
  42. package/dist/index-PJNQPLn5.js +841 -0
  43. package/dist/{index-BKFDqQPh.js → index-hHvpW2H6.js} +6547 -5418
  44. package/dist/main.css +200 -1123
  45. package/dist/main.js +1 -1
  46. package/dist/markdown-to-html-BwS08CTi.js +1135 -0
  47. package/dist/tippy.esm-DLHdsnfG.js +1711 -0
  48. package/dist/utils/create-scribe-editor.d.ts +2 -2
  49. package/dist/utils/create-scribe-editor.d.ts.map +1 -1
  50. package/dist/utils/create-scribe-editor.js +2 -2
  51. package/dist/utils/html-to-markdown.d.ts.map +1 -1
  52. package/dist/utils/html-to-markdown.js +663 -18
  53. package/dist/utils/index.js +1 -1
  54. package/dist/utils/markdown-to-html.js +1 -1
  55. package/package.json +24 -27
  56. package/dist/clsx-OuTLNxxd.js +0 -16
  57. package/dist/index-CL2WLiGu.js +0 -159
  58. package/dist/index-Cxf4VEm1.js +0 -50957
  59. package/dist/index-PzbCrHp0.js +0 -2349
  60. package/dist/markdown-to-html-__93dwok.js +0 -1557
  61. package/dist/turndown.browser.es-RmA_HBaI.js +0 -649
package/README.md CHANGED
@@ -37,7 +37,9 @@ npm install @clevertask/scribe
37
37
  ### Basic usage
38
38
 
39
39
  ```tsx
40
+ import "@radix-ui/themes/styles.css";
40
41
  import "@clevertask/scribe/dist/main.css";
42
+ import { Theme } from "@radix-ui/themes";
41
43
  import { Scribe, ScribeOnChangeContents } from "@clevertask/scribe";
42
44
 
43
45
  function App() {
@@ -48,14 +50,20 @@ function App() {
48
50
  [],
49
51
  );
50
52
 
51
- return <Scribe onContentChange={onContentChange} />;
53
+ return (
54
+ <Theme>
55
+ <Scribe onContentChange={onContentChange} />
56
+ </Theme>
57
+ );
52
58
  }
53
59
  ```
54
60
 
55
61
  ### With ref
56
62
 
57
63
  ```tsx
64
+ import "@radix-ui/themes/styles.css";
58
65
  import "@clevertask/scribe/dist/main.css";
66
+ import { Theme } from "@radix-ui/themes";
59
67
  import { Scribe, ScribeOnChangeContents } from "@clevertask/scribe";
60
68
 
61
69
  function App() {
@@ -67,37 +75,36 @@ function App() {
67
75
 
68
76
  return (
69
77
  <>
70
- <Scribe ref={editor} />
78
+ <Theme>
79
+ <Scribe ref={editor} />
80
+ </Theme>
71
81
  <button onClick={resetContent}>Reset content</button>
72
82
  </>
73
83
  );
74
84
  }
75
85
  ```
76
86
 
77
- ### With Dark Mode
87
+ ### Using Your App Theme
78
88
 
79
89
  ```tsx
90
+ import "@radix-ui/themes/styles.css";
80
91
  import "@clevertask/scribe/dist/main.css";
81
- import { Scribe, ScribeOnChangeContents } from "@clevertask/scribe";
92
+ import { Theme } from "@radix-ui/themes";
93
+ import { Scribe } from "@clevertask/scribe";
82
94
 
83
95
  function App() {
84
- const editor = useRef<ScribeRef>(null);
85
-
86
- const resetContent = useCallback(() => {
87
- editor.current.resetContent();
88
- }, []);
89
-
90
96
  return (
91
- <>
92
- <Scribe darkMode />
93
- <button onClick={resetContent}>Reset content</button>
94
- </>
97
+ <Theme appearance="dark">
98
+ <Scribe />
99
+ </Theme>
95
100
  );
96
101
  }
97
102
  ```
98
103
 
99
104
  ## Math Expressions
100
105
 
106
+ Scribe's default UI is styled with Radix Themes components. Load `@radix-ui/themes/styles.css` once in your app alongside `@clevertask/scribe/dist/main.css`, and render Scribe somewhere inside a Radix `<Theme>`.
107
+
101
108
  Scribe ships with `@tiptap/extension-mathematics`. The extension renders math when it receives math nodes in the HTML:
102
109
 
103
110
  ```html
@@ -142,7 +149,6 @@ If your content arrives as HTML (for example from a server), use the helper belo
142
149
  | `mainContainerStyle` | `React.CSSProperties` | `undefined` | You can send a CSS object to style the main editor container |
143
150
  | `mainContainerClassName` | `string` | `undefined` | The same idea of `mainContainerStyle` but with classes. |
144
151
  | `onKeyDown` | `KeyboardEventHandler` | `undefined` | A callback function that is triggered when a key is pressed within the editor. This allows you to handle custom keyboard shortcuts. For example, you can use this prop to implement a "send message" functionality when `Ctrl + Enter` is pressed. |
145
- | `darkMode` | `boolean` | `false` | You can switch the darkMode value to change the text editor's theme |
146
152
 
147
153
  ## Helper Functions
148
154
 
@@ -0,0 +1,327 @@
1
+ import { jsx as i, jsxs as l } from "react/jsx-runtime";
2
+ import { Box as A, Flex as r, Popover as g, IconButton as B, Text as m, TextField as R, Button as f, Separator as F } from "@radix-ui/themes";
3
+ import { u as H } from "./index-PJNQPLn5.js";
4
+ import { useState as v, useCallback as u, Fragment as U } from "react";
5
+ import { getPopupMountTarget as V } from "./components/Scribe/extension/getPopupMountTarget.js";
6
+ import { BoldIcon as q, ItalicIcon as E, StrikeIcon as W, InlineCodeIcon as Q, HighlightIcon as G, UnorderedListIcon as J, OrderedListIcon as K, LinkIcon as X, ImageIcon as Y, CodeBlockIcon as Z, BlockQuoteIcon as _, HorizontalLineIcon as ee } from "./icons/ToolbarIcons.js";
7
+ function O(e) {
8
+ var s, a, t = "";
9
+ if (typeof e == "string" || typeof e == "number") t += e;
10
+ else if (typeof e == "object") if (Array.isArray(e)) {
11
+ var h = e.length;
12
+ for (s = 0; s < h; s++) e[s] && (a = O(e[s])) && (t && (t += " "), t += a);
13
+ } else for (a in e) e[a] && (t && (t += " "), t += a);
14
+ return t;
15
+ }
16
+ function I() {
17
+ for (var e, s, a = 0, t = "", h = arguments.length; a < h; a++) (e = arguments[a]) && (s = O(e)) && (t && (t += " "), t += s);
18
+ return t;
19
+ }
20
+ const ce = ({ editor: e }) => {
21
+ const [s, a] = v(!1), [t, h] = v(!1), [p, y] = v(""), [b, L] = v(""), C = V(e), c = H({
22
+ editor: e,
23
+ selector: ({ editor: n }) => n ? {
24
+ isBold: n.isActive("bold"),
25
+ isItalic: n.isActive("italic"),
26
+ isStrike: n.isActive("strike"),
27
+ isCode: n.isActive("code"),
28
+ isHighlight: n.isActive("highlight"),
29
+ isBulletList: n.isActive("bulletList"),
30
+ isOrderedList: n.isActive("orderedList"),
31
+ isLink: n.isActive("link"),
32
+ isImage: n.isActive("image"),
33
+ isCodeBlock: n.isActive("codeBlock"),
34
+ isBlockquote: n.isActive("blockquote")
35
+ } : null
36
+ }), z = u(
37
+ (n) => {
38
+ if (n) {
39
+ const d = e.getAttributes("link").href ?? "";
40
+ y(d), h(!1);
41
+ }
42
+ a(n);
43
+ },
44
+ [e]
45
+ ), M = u(
46
+ (n) => {
47
+ if (n) {
48
+ const d = e.getAttributes("image").src ?? "";
49
+ L(d), a(!1);
50
+ }
51
+ h(n);
52
+ },
53
+ [e]
54
+ ), S = u(() => {
55
+ const n = p.trim();
56
+ if (n.length === 0) {
57
+ e.chain().focus().extendMarkRange("link").unsetLink().run(), a(!1);
58
+ return;
59
+ }
60
+ e.chain().focus().extendMarkRange("link").setLink({ href: n }).selectTextblockEnd().run(), a(!1);
61
+ }, [e, p]), P = u(() => {
62
+ e.chain().focus().extendMarkRange("link").unsetLink().run(), a(!1);
63
+ }, [e]), T = u(() => {
64
+ const n = b.trim();
65
+ n && (e.chain().focus().setImage({ src: n }).run(), h(!1));
66
+ }, [e, b]), D = u(
67
+ (n, d) => {
68
+ n.preventDefault(), d();
69
+ },
70
+ []
71
+ ), w = u((n) => {
72
+ n.preventDefault();
73
+ }, []), N = u(
74
+ ({ target: { value: n } }) => {
75
+ y(n);
76
+ },
77
+ []
78
+ ), $ = u(
79
+ ({ target: { value: n } }) => {
80
+ L(n);
81
+ },
82
+ []
83
+ ), x = [
84
+ [
85
+ {
86
+ name: "bold",
87
+ icon: q,
88
+ command: () => e.chain().focus().toggleBold().run(),
89
+ isActive: () => !!c?.isBold
90
+ },
91
+ {
92
+ name: "italic",
93
+ icon: E,
94
+ command: () => e.chain().focus().toggleItalic().run(),
95
+ isActive: () => !!c?.isItalic
96
+ },
97
+ {
98
+ name: "strike",
99
+ icon: W,
100
+ command: () => e.chain().focus().toggleStrike().run(),
101
+ isActive: () => !!c?.isStrike
102
+ }
103
+ ],
104
+ [
105
+ {
106
+ name: "inline-code",
107
+ icon: Q,
108
+ command: () => e.chain().focus().toggleCode().run(),
109
+ isActive: () => !!c?.isCode
110
+ },
111
+ {
112
+ name: "highlight",
113
+ icon: G,
114
+ command: () => e.chain().focus().toggleHighlight().run(),
115
+ isActive: () => !!c?.isHighlight
116
+ }
117
+ ],
118
+ [
119
+ {
120
+ name: "unordered-list",
121
+ icon: J,
122
+ command: () => e.chain().focus().toggleBulletList().run(),
123
+ isActive: () => !!c?.isBulletList
124
+ },
125
+ {
126
+ name: "ordered-list",
127
+ icon: K,
128
+ command: () => e.chain().focus().toggleOrderedList().run(),
129
+ isActive: () => !!c?.isOrderedList
130
+ }
131
+ ],
132
+ [
133
+ {
134
+ name: "link",
135
+ icon: X,
136
+ isActive: () => !!c?.isLink,
137
+ popover: "link"
138
+ },
139
+ {
140
+ name: "image",
141
+ icon: Y,
142
+ isActive: () => !!c?.isImage,
143
+ disabled: !1,
144
+ popover: "image"
145
+ },
146
+ {
147
+ name: "code-block",
148
+ icon: Z,
149
+ command: () => e.chain().focus().toggleCodeBlock().run(),
150
+ isActive: () => !!c?.isCodeBlock
151
+ },
152
+ {
153
+ name: "block-quote",
154
+ icon: _,
155
+ command: () => e.chain().focus().toggleBlockquote().run(),
156
+ isActive: () => !!c?.isBlockquote
157
+ },
158
+ {
159
+ name: "horizontal-line",
160
+ icon: ee,
161
+ command: () => e.chain().focus().setHorizontalRule().run(),
162
+ isActive: () => !1
163
+ }
164
+ ]
165
+ ];
166
+ return /* @__PURE__ */ i(A, { className: "scribe-toolbar", children: /* @__PURE__ */ i(r, { align: "center", gap: "3", wrap: "wrap", children: x.map((n, d) => /* @__PURE__ */ l(U, { children: [
167
+ /* @__PURE__ */ i(r, { align: "center", gap: "2", wrap: "wrap", children: n.map((o, k) => o.popover === "link" ? /* @__PURE__ */ l(
168
+ g.Root,
169
+ {
170
+ open: s,
171
+ onOpenChange: z,
172
+ children: [
173
+ /* @__PURE__ */ i(g.Trigger, { children: /* @__PURE__ */ i(
174
+ B,
175
+ {
176
+ type: "button",
177
+ radius: "medium",
178
+ color: "gray",
179
+ variant: o.isActive() ? "soft" : "ghost",
180
+ disabled: o.disabled || !e.isEditable,
181
+ title: o.name,
182
+ onMouseDown: w,
183
+ className: I(o.disabled && "scribe-toolbar-button--disabled"),
184
+ children: /* @__PURE__ */ i(o.icon, { className: "scribe-toolbar-icon" })
185
+ }
186
+ ) }),
187
+ /* @__PURE__ */ i(
188
+ g.Content,
189
+ {
190
+ container: C,
191
+ size: "2",
192
+ side: "bottom",
193
+ align: "start",
194
+ style: { maxWidth: "calc(100vw - 32px)", width: 320 },
195
+ children: /* @__PURE__ */ l(r, { direction: "column", gap: "4", children: [
196
+ /* @__PURE__ */ l(A, { children: [
197
+ /* @__PURE__ */ i(m, { as: "p", size: "3", weight: "medium", children: "Link" }),
198
+ /* @__PURE__ */ i(m, { as: "p", size: "2", color: "gray", children: "Add or update a link for the current selection." })
199
+ ] }),
200
+ /* @__PURE__ */ i("label", { children: /* @__PURE__ */ l(r, { direction: "column", gap: "2", children: [
201
+ /* @__PURE__ */ i(m, { as: "span", size: "2", weight: "medium", children: "URL" }),
202
+ /* @__PURE__ */ i(
203
+ R.Root,
204
+ {
205
+ autoFocus: !0,
206
+ placeholder: "https://example.com",
207
+ value: p,
208
+ onChange: N
209
+ }
210
+ )
211
+ ] }) }),
212
+ /* @__PURE__ */ l(r, { justify: "between", gap: "3", wrap: "wrap", children: [
213
+ /* @__PURE__ */ i(
214
+ f,
215
+ {
216
+ type: "button",
217
+ color: "red",
218
+ variant: "soft",
219
+ disabled: !((e.getAttributes("link").href ?? "").trim() || p.trim()),
220
+ onClick: P,
221
+ children: "Remove link"
222
+ }
223
+ ),
224
+ /* @__PURE__ */ l(r, { gap: "2", justify: "end", style: { marginLeft: "auto" }, children: [
225
+ /* @__PURE__ */ i(g.Close, { children: /* @__PURE__ */ i(f, { type: "button", variant: "soft", color: "gray", children: "Cancel" }) }),
226
+ /* @__PURE__ */ i(
227
+ f,
228
+ {
229
+ type: "button",
230
+ disabled: p.trim().length === 0,
231
+ onClick: S,
232
+ children: "Save"
233
+ }
234
+ )
235
+ ] })
236
+ ] })
237
+ ] })
238
+ }
239
+ )
240
+ ]
241
+ },
242
+ `${o.name}-${k}`
243
+ ) : o.popover === "image" ? /* @__PURE__ */ l(
244
+ g.Root,
245
+ {
246
+ open: t,
247
+ onOpenChange: M,
248
+ children: [
249
+ /* @__PURE__ */ i(g.Trigger, { children: /* @__PURE__ */ i(
250
+ B,
251
+ {
252
+ type: "button",
253
+ radius: "medium",
254
+ color: "gray",
255
+ variant: o.isActive() ? "soft" : "ghost",
256
+ disabled: o.disabled || !e.isEditable,
257
+ title: o.name,
258
+ onMouseDown: w,
259
+ className: I(o.disabled && "scribe-toolbar-button--disabled"),
260
+ children: /* @__PURE__ */ i(o.icon, { className: "scribe-toolbar-icon" })
261
+ }
262
+ ) }),
263
+ /* @__PURE__ */ i(
264
+ g.Content,
265
+ {
266
+ container: C,
267
+ size: "2",
268
+ side: "bottom",
269
+ align: "start",
270
+ style: { maxWidth: "calc(100vw - 32px)", width: 320 },
271
+ children: /* @__PURE__ */ l(r, { direction: "column", gap: "4", children: [
272
+ /* @__PURE__ */ l(A, { children: [
273
+ /* @__PURE__ */ i(m, { as: "p", size: "3", weight: "medium", children: "Image" }),
274
+ /* @__PURE__ */ i(m, { as: "p", size: "2", color: "gray", children: "Insert an image from a URL." })
275
+ ] }),
276
+ /* @__PURE__ */ i("label", { children: /* @__PURE__ */ l(r, { direction: "column", gap: "2", children: [
277
+ /* @__PURE__ */ i(m, { as: "span", size: "2", weight: "medium", children: "Image URL" }),
278
+ /* @__PURE__ */ i(
279
+ R.Root,
280
+ {
281
+ autoFocus: !0,
282
+ placeholder: "https://example.com/image.png",
283
+ value: b,
284
+ onChange: $
285
+ }
286
+ )
287
+ ] }) }),
288
+ /* @__PURE__ */ l(r, { justify: "end", gap: "2", children: [
289
+ /* @__PURE__ */ i(g.Close, { children: /* @__PURE__ */ i(f, { type: "button", variant: "soft", color: "gray", children: "Cancel" }) }),
290
+ /* @__PURE__ */ i(
291
+ f,
292
+ {
293
+ type: "button",
294
+ disabled: b.trim().length === 0,
295
+ onClick: T,
296
+ children: "Save"
297
+ }
298
+ )
299
+ ] })
300
+ ] })
301
+ }
302
+ )
303
+ ]
304
+ },
305
+ `${o.name}-${k}`
306
+ ) : /* @__PURE__ */ i(
307
+ B,
308
+ {
309
+ type: "button",
310
+ radius: "medium",
311
+ color: "gray",
312
+ variant: o.isActive() ? "soft" : "ghost",
313
+ disabled: o.disabled || !e.isEditable,
314
+ title: o.name,
315
+ onMouseDown: (j) => D(j, o.command),
316
+ className: I(o.disabled && "scribe-toolbar-button--disabled"),
317
+ children: /* @__PURE__ */ i(o.icon, { className: "scribe-toolbar-icon" })
318
+ },
319
+ `${o.name}-${k}`
320
+ )) }),
321
+ d !== x.length - 1 ? /* @__PURE__ */ i(F, { orientation: "vertical", decorative: !0, style: { height: 20 } }) : null
322
+ ] }, `format-group-${d}`)) }) });
323
+ };
324
+ export {
325
+ ce as B,
326
+ I as c
327
+ };