@talogic/editor 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +68 -2
- package/index.d.ts +4 -0
- package/index.js +735 -0
- package/index.js.map +1 -0
- package/package.json +74 -4
- package/rich-text-editor/editor-content.recipe.d.ts +6 -0
- package/rich-text-editor/editor-extensions.config.d.ts +9 -0
- package/rich-text-editor/index.d.ts +2 -0
- package/rich-text-editor/rich-text-editor.component.d.ts +42 -0
- package/toolbar/button-tools.config.d.ts +16 -0
- package/toolbar/editor-toolbar.component.d.ts +18 -0
- package/toolbar/heading-menu.component.d.ts +16 -0
- package/toolbar/index.d.ts +6 -0
- package/toolbar/link-popover.component.d.ts +16 -0
- package/toolbar/rich-text-labels.content.d.ts +30 -0
- package/toolbar/rich-text-presets.content.d.ts +9 -0
- package/toolbar/rich-text-tool.contract.d.ts +4 -0
- package/toolbar/table-menu.component.d.ts +17 -0
- package/toolbar/text-color-menu.component.d.ts +17 -0
- package/toolbar/toolbar-button.component.d.ts +19 -0
package/index.js
ADDED
|
@@ -0,0 +1,735 @@
|
|
|
1
|
+
import { Button as e, DropdownMenu as t, DropdownMenuContent as n, DropdownMenuItem as r, DropdownMenuRadioGroup as i, DropdownMenuRadioItem as a, DropdownMenuSeparator as o, DropdownMenuTrigger as s, Input as c, Popover as l, PopoverContent as u, PopoverTrigger as d, Separator as f, Tooltip as p, TooltipContent as m, TooltipTrigger as ee, cn as h } from "@talogic/react";
|
|
2
|
+
import { EditorContent as te, useEditor as ne, useEditorState as re } from "@tiptap/react";
|
|
3
|
+
import { useEffect as g, useState as _ } from "react";
|
|
4
|
+
import { AlignCenterIcon as ie, AlignJustifyIcon as ae, AlignLeftIcon as oe, AlignRightIcon as se, BlockquoteIcon as ce, BoldIcon as le, ClearFormattingIcon as ue, CodeBlockIcon as de, CodeInlineIcon as fe, Heading1Icon as v, Heading2Icon as y, Heading3Icon as b, Heading4Icon as x, Heading5Icon as S, Heading6Icon as C, HighlightIcon as w, HorizontalRuleIcon as T, IndentIcon as E, ItalicIcon as D, LinkIcon as O, ListChecksIcon as k, ListIcon as A, ListOrderedIcon as j, OutdentIcon as M, ParagraphIcon as N, RedoIcon as P, StrikethroughIcon as F, SubscriptIcon as I, SuperscriptIcon as L, TableCellsMergeIcon as R, TableCellsSplitIcon as z, TableColumnDeleteIcon as B, TableColumnInsertLeftIcon as V, TableColumnInsertRightIcon as pe, TableDeleteIcon as me, TableHeaderColumnIcon as he, TableHeaderRowIcon as ge, TableIcon as _e, TablePlusIcon as ve, TableRowDeleteIcon as ye, TableRowInsertAboveIcon as be, TableRowInsertBelowIcon as xe, TextColorIcon as Se, UnderlineIcon as Ce, UndoIcon as we } from "@talogic/icons";
|
|
5
|
+
import { jsx as H, jsxs as U } from "react/jsx-runtime";
|
|
6
|
+
import Te from "@tiptap/extension-highlight";
|
|
7
|
+
import { ListKit as Ee } from "@tiptap/extension-list";
|
|
8
|
+
import De from "@tiptap/extension-subscript";
|
|
9
|
+
import Oe from "@tiptap/extension-superscript";
|
|
10
|
+
import { TableKit as ke } from "@tiptap/extension-table";
|
|
11
|
+
import Ae from "@tiptap/extension-text-align";
|
|
12
|
+
import { TextStyleKit as je } from "@tiptap/extension-text-style";
|
|
13
|
+
import { Placeholder as Me } from "@tiptap/extensions";
|
|
14
|
+
import { Markdown as Ne } from "@tiptap/markdown";
|
|
15
|
+
import Pe from "@tiptap/starter-kit";
|
|
16
|
+
// src/toolbar/button-tools.config.tsx
|
|
17
|
+
var W = (e) => e.chain().focus();
|
|
18
|
+
function G(e, t, n) {
|
|
19
|
+
let r = t === "in" ? "sinkListItem" : "liftListItem";
|
|
20
|
+
return ["listItem", "taskItem"].some((t) => n ? e.can()[r](t) : W(e)[r](t).run());
|
|
21
|
+
}
|
|
22
|
+
var K = {
|
|
23
|
+
undo: {
|
|
24
|
+
icon: /* @__PURE__ */ H(we, {}),
|
|
25
|
+
shortcut: "Mod-Z",
|
|
26
|
+
run: (e) => W(e).undo().run(),
|
|
27
|
+
canRun: (e) => e.can().undo()
|
|
28
|
+
},
|
|
29
|
+
redo: {
|
|
30
|
+
icon: /* @__PURE__ */ H(P, {}),
|
|
31
|
+
shortcut: "Mod-Shift-Z",
|
|
32
|
+
run: (e) => W(e).redo().run(),
|
|
33
|
+
canRun: (e) => e.can().redo()
|
|
34
|
+
},
|
|
35
|
+
bold: {
|
|
36
|
+
icon: /* @__PURE__ */ H(le, {}),
|
|
37
|
+
shortcut: "Mod-B",
|
|
38
|
+
run: (e) => W(e).toggleBold().run(),
|
|
39
|
+
canRun: (e) => e.can().toggleBold(),
|
|
40
|
+
isActive: (e) => e.isActive("bold")
|
|
41
|
+
},
|
|
42
|
+
italic: {
|
|
43
|
+
icon: /* @__PURE__ */ H(D, {}),
|
|
44
|
+
shortcut: "Mod-I",
|
|
45
|
+
run: (e) => W(e).toggleItalic().run(),
|
|
46
|
+
canRun: (e) => e.can().toggleItalic(),
|
|
47
|
+
isActive: (e) => e.isActive("italic")
|
|
48
|
+
},
|
|
49
|
+
underline: {
|
|
50
|
+
icon: /* @__PURE__ */ H(Ce, {}),
|
|
51
|
+
shortcut: "Mod-U",
|
|
52
|
+
run: (e) => W(e).toggleUnderline().run(),
|
|
53
|
+
canRun: (e) => e.can().toggleUnderline(),
|
|
54
|
+
isActive: (e) => e.isActive("underline")
|
|
55
|
+
},
|
|
56
|
+
strike: {
|
|
57
|
+
icon: /* @__PURE__ */ H(F, {}),
|
|
58
|
+
shortcut: "Mod-Shift-S",
|
|
59
|
+
run: (e) => W(e).toggleStrike().run(),
|
|
60
|
+
canRun: (e) => e.can().toggleStrike(),
|
|
61
|
+
isActive: (e) => e.isActive("strike")
|
|
62
|
+
},
|
|
63
|
+
code: {
|
|
64
|
+
icon: /* @__PURE__ */ H(fe, {}),
|
|
65
|
+
shortcut: "Mod-E",
|
|
66
|
+
run: (e) => W(e).toggleCode().run(),
|
|
67
|
+
canRun: (e) => e.can().toggleCode(),
|
|
68
|
+
isActive: (e) => e.isActive("code")
|
|
69
|
+
},
|
|
70
|
+
subscript: {
|
|
71
|
+
icon: /* @__PURE__ */ H(I, {}),
|
|
72
|
+
shortcut: "Mod-,",
|
|
73
|
+
run: (e) => W(e).toggleSubscript().run(),
|
|
74
|
+
canRun: (e) => e.can().toggleSubscript(),
|
|
75
|
+
isActive: (e) => e.isActive("subscript")
|
|
76
|
+
},
|
|
77
|
+
superscript: {
|
|
78
|
+
icon: /* @__PURE__ */ H(L, {}),
|
|
79
|
+
shortcut: "Mod-.",
|
|
80
|
+
run: (e) => W(e).toggleSuperscript().run(),
|
|
81
|
+
canRun: (e) => e.can().toggleSuperscript(),
|
|
82
|
+
isActive: (e) => e.isActive("superscript")
|
|
83
|
+
},
|
|
84
|
+
highlight: {
|
|
85
|
+
icon: /* @__PURE__ */ H(w, {}),
|
|
86
|
+
shortcut: "Mod-Shift-H",
|
|
87
|
+
run: (e) => W(e).toggleHighlight().run(),
|
|
88
|
+
canRun: (e) => e.can().toggleHighlight(),
|
|
89
|
+
isActive: (e) => e.isActive("highlight")
|
|
90
|
+
},
|
|
91
|
+
clearFormatting: {
|
|
92
|
+
icon: /* @__PURE__ */ H(ue, {}),
|
|
93
|
+
run: (e) => W(e).unsetAllMarks().clearNodes().run(),
|
|
94
|
+
canRun: (e) => e.can().unsetAllMarks()
|
|
95
|
+
},
|
|
96
|
+
bulletList: {
|
|
97
|
+
icon: /* @__PURE__ */ H(A, {}),
|
|
98
|
+
shortcut: "Mod-Shift-8",
|
|
99
|
+
run: (e) => W(e).toggleBulletList().run(),
|
|
100
|
+
canRun: (e) => e.can().toggleBulletList(),
|
|
101
|
+
isActive: (e) => e.isActive("bulletList")
|
|
102
|
+
},
|
|
103
|
+
orderedList: {
|
|
104
|
+
icon: /* @__PURE__ */ H(j, {}),
|
|
105
|
+
shortcut: "Mod-Shift-7",
|
|
106
|
+
run: (e) => W(e).toggleOrderedList().run(),
|
|
107
|
+
canRun: (e) => e.can().toggleOrderedList(),
|
|
108
|
+
isActive: (e) => e.isActive("orderedList")
|
|
109
|
+
},
|
|
110
|
+
taskList: {
|
|
111
|
+
icon: /* @__PURE__ */ H(k, {}),
|
|
112
|
+
shortcut: "Mod-Shift-9",
|
|
113
|
+
run: (e) => W(e).toggleTaskList().run(),
|
|
114
|
+
canRun: (e) => e.can().toggleTaskList(),
|
|
115
|
+
isActive: (e) => e.isActive("taskList")
|
|
116
|
+
},
|
|
117
|
+
indent: {
|
|
118
|
+
icon: /* @__PURE__ */ H(E, {}),
|
|
119
|
+
shortcut: "Tab",
|
|
120
|
+
run: (e) => {
|
|
121
|
+
G(e, "in", !1);
|
|
122
|
+
},
|
|
123
|
+
canRun: (e) => G(e, "in", !0)
|
|
124
|
+
},
|
|
125
|
+
outdent: {
|
|
126
|
+
icon: /* @__PURE__ */ H(M, {}),
|
|
127
|
+
shortcut: "Shift-Tab",
|
|
128
|
+
run: (e) => {
|
|
129
|
+
G(e, "out", !1);
|
|
130
|
+
},
|
|
131
|
+
canRun: (e) => G(e, "out", !0)
|
|
132
|
+
},
|
|
133
|
+
blockquote: {
|
|
134
|
+
icon: /* @__PURE__ */ H(ce, {}),
|
|
135
|
+
shortcut: "Mod-Shift-B",
|
|
136
|
+
run: (e) => W(e).toggleBlockquote().run(),
|
|
137
|
+
canRun: (e) => e.can().toggleBlockquote(),
|
|
138
|
+
isActive: (e) => e.isActive("blockquote")
|
|
139
|
+
},
|
|
140
|
+
codeBlock: {
|
|
141
|
+
icon: /* @__PURE__ */ H(de, {}),
|
|
142
|
+
shortcut: "Mod-Alt-C",
|
|
143
|
+
run: (e) => W(e).toggleCodeBlock().run(),
|
|
144
|
+
canRun: (e) => e.can().toggleCodeBlock(),
|
|
145
|
+
isActive: (e) => e.isActive("codeBlock")
|
|
146
|
+
},
|
|
147
|
+
horizontalRule: {
|
|
148
|
+
icon: /* @__PURE__ */ H(T, {}),
|
|
149
|
+
run: (e) => W(e).setHorizontalRule().run(),
|
|
150
|
+
canRun: (e) => e.can().setHorizontalRule()
|
|
151
|
+
},
|
|
152
|
+
alignLeft: {
|
|
153
|
+
icon: /* @__PURE__ */ H(oe, {}),
|
|
154
|
+
shortcut: "Mod-Shift-L",
|
|
155
|
+
run: (e) => W(e).setTextAlign("left").run(),
|
|
156
|
+
canRun: (e) => e.can().setTextAlign("left"),
|
|
157
|
+
isActive: (e) => e.isActive({ textAlign: "left" })
|
|
158
|
+
},
|
|
159
|
+
alignCenter: {
|
|
160
|
+
icon: /* @__PURE__ */ H(ie, {}),
|
|
161
|
+
shortcut: "Mod-Shift-E",
|
|
162
|
+
run: (e) => W(e).setTextAlign("center").run(),
|
|
163
|
+
canRun: (e) => e.can().setTextAlign("center"),
|
|
164
|
+
isActive: (e) => e.isActive({ textAlign: "center" })
|
|
165
|
+
},
|
|
166
|
+
alignRight: {
|
|
167
|
+
icon: /* @__PURE__ */ H(se, {}),
|
|
168
|
+
shortcut: "Mod-Shift-R",
|
|
169
|
+
run: (e) => W(e).setTextAlign("right").run(),
|
|
170
|
+
canRun: (e) => e.can().setTextAlign("right"),
|
|
171
|
+
isActive: (e) => e.isActive({ textAlign: "right" })
|
|
172
|
+
},
|
|
173
|
+
alignJustify: {
|
|
174
|
+
icon: /* @__PURE__ */ H(ae, {}),
|
|
175
|
+
shortcut: "Mod-Shift-J",
|
|
176
|
+
run: (e) => W(e).setTextAlign("justify").run(),
|
|
177
|
+
canRun: (e) => e.can().setTextAlign("justify"),
|
|
178
|
+
isActive: (e) => e.isActive({ textAlign: "justify" })
|
|
179
|
+
}
|
|
180
|
+
}, q = typeof navigator < "u" && /Mac|iPhone|iPad/.test(navigator.userAgent), Fe = q ? "⌘" : "Ctrl", Ie = q ? "⌥" : "Alt", Le = q ? "Meta" : "Control";
|
|
181
|
+
function J({ label: t, icon: n, shortcut: r, pressed: i, ...a }) {
|
|
182
|
+
let o = r?.replace("Mod", () => Fe).replace("Alt", () => Ie).replaceAll("-", "+");
|
|
183
|
+
return /* @__PURE__ */ U(p, { children: [/* @__PURE__ */ H(ee, {
|
|
184
|
+
asChild: !0,
|
|
185
|
+
children: /* @__PURE__ */ H(e, {
|
|
186
|
+
type: "button",
|
|
187
|
+
variant: "ghost",
|
|
188
|
+
size: "icon-sm",
|
|
189
|
+
"aria-label": t,
|
|
190
|
+
"aria-pressed": i,
|
|
191
|
+
"aria-keyshortcuts": r?.replace("Mod", () => Le).replaceAll("-", "+"),
|
|
192
|
+
"data-active": i || void 0,
|
|
193
|
+
className: "data-active:bg-brand-soft data-active:text-brand-text [&_svg]:size-[18px]",
|
|
194
|
+
onMouseDown: (e) => {
|
|
195
|
+
e.preventDefault();
|
|
196
|
+
},
|
|
197
|
+
...a,
|
|
198
|
+
children: n
|
|
199
|
+
})
|
|
200
|
+
}), /* @__PURE__ */ U(m, { children: [t, o && /* @__PURE__ */ H("span", {
|
|
201
|
+
className: "ms-2 opacity-70",
|
|
202
|
+
children: o
|
|
203
|
+
})] })] });
|
|
204
|
+
}
|
|
205
|
+
// src/toolbar/heading-menu.component.tsx
|
|
206
|
+
var Y = [
|
|
207
|
+
{
|
|
208
|
+
level: 0,
|
|
209
|
+
icon: /* @__PURE__ */ H(N, {}),
|
|
210
|
+
label: "paragraph",
|
|
211
|
+
text: "text-sm"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
level: 1,
|
|
215
|
+
icon: /* @__PURE__ */ H(v, {}),
|
|
216
|
+
label: "heading1",
|
|
217
|
+
text: "text-xl font-semibold"
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
level: 2,
|
|
221
|
+
icon: /* @__PURE__ */ H(y, {}),
|
|
222
|
+
label: "heading2",
|
|
223
|
+
text: "text-lg font-semibold"
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
level: 3,
|
|
227
|
+
icon: /* @__PURE__ */ H(b, {}),
|
|
228
|
+
label: "heading3",
|
|
229
|
+
text: "text-base font-semibold"
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
level: 4,
|
|
233
|
+
icon: /* @__PURE__ */ H(x, {}),
|
|
234
|
+
label: "heading4",
|
|
235
|
+
text: "text-sm font-semibold"
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
level: 5,
|
|
239
|
+
icon: /* @__PURE__ */ H(S, {}),
|
|
240
|
+
label: "heading5",
|
|
241
|
+
text: "text-sm font-medium"
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
level: 6,
|
|
245
|
+
icon: /* @__PURE__ */ H(C, {}),
|
|
246
|
+
label: "heading6",
|
|
247
|
+
text: "text-xs font-medium uppercase"
|
|
248
|
+
}
|
|
249
|
+
];
|
|
250
|
+
function X({ editor: e, level: r, labels: o }) {
|
|
251
|
+
let c = Y.find((e) => e.level === r) ?? Y[0];
|
|
252
|
+
function l(t) {
|
|
253
|
+
let n = Number(t);
|
|
254
|
+
n === 0 ? e.chain().focus().setParagraph().run() : e.chain().focus().setHeading({ level: n }).run();
|
|
255
|
+
}
|
|
256
|
+
return /* @__PURE__ */ U(t, { children: [/* @__PURE__ */ H(s, {
|
|
257
|
+
asChild: !0,
|
|
258
|
+
children: /* @__PURE__ */ H(J, {
|
|
259
|
+
label: `${o.heading}: ${o[c?.label ?? "paragraph"]}`,
|
|
260
|
+
icon: c?.icon
|
|
261
|
+
})
|
|
262
|
+
}), /* @__PURE__ */ H(n, {
|
|
263
|
+
align: "start",
|
|
264
|
+
children: /* @__PURE__ */ H(i, {
|
|
265
|
+
value: String(r),
|
|
266
|
+
onValueChange: l,
|
|
267
|
+
children: Y.map((e) => /* @__PURE__ */ H(a, {
|
|
268
|
+
value: String(e.level),
|
|
269
|
+
className: e.text,
|
|
270
|
+
children: o[e.label]
|
|
271
|
+
}, e.level))
|
|
272
|
+
})
|
|
273
|
+
})] });
|
|
274
|
+
}
|
|
275
|
+
// src/toolbar/link-popover.component.tsx
|
|
276
|
+
function Re({ editor: t, href: n, labels: r }) {
|
|
277
|
+
let [i, a] = _(!1), [o, s] = _("");
|
|
278
|
+
function f(e) {
|
|
279
|
+
e.preventDefault();
|
|
280
|
+
let n = o.trim(), r = t.chain().focus().extendMarkRange("link");
|
|
281
|
+
n ? r.setLink({ href: n }).run() : r.unsetLink().run(), a(!1);
|
|
282
|
+
}
|
|
283
|
+
return /* @__PURE__ */ U(l, {
|
|
284
|
+
open: i,
|
|
285
|
+
onOpenChange: (e) => {
|
|
286
|
+
a(e), e && s(n ?? "");
|
|
287
|
+
},
|
|
288
|
+
children: [/* @__PURE__ */ H(d, {
|
|
289
|
+
asChild: !0,
|
|
290
|
+
children: /* @__PURE__ */ H(J, {
|
|
291
|
+
label: r.link,
|
|
292
|
+
icon: /* @__PURE__ */ H(O, {}),
|
|
293
|
+
shortcut: "Mod-K",
|
|
294
|
+
pressed: n !== void 0
|
|
295
|
+
})
|
|
296
|
+
}), /* @__PURE__ */ H(u, {
|
|
297
|
+
align: "start",
|
|
298
|
+
className: "w-80",
|
|
299
|
+
children: /* @__PURE__ */ U("form", {
|
|
300
|
+
className: "flex flex-col gap-2",
|
|
301
|
+
onSubmit: f,
|
|
302
|
+
children: [/* @__PURE__ */ H(c, {
|
|
303
|
+
"aria-label": r.linkUrl,
|
|
304
|
+
type: "url",
|
|
305
|
+
inputMode: "url",
|
|
306
|
+
placeholder: "https://",
|
|
307
|
+
value: o,
|
|
308
|
+
onChange: (e) => {
|
|
309
|
+
s(e.target.value);
|
|
310
|
+
}
|
|
311
|
+
}), /* @__PURE__ */ U("div", {
|
|
312
|
+
className: "flex justify-end gap-2",
|
|
313
|
+
children: [n !== void 0 && /* @__PURE__ */ H(e, {
|
|
314
|
+
type: "button",
|
|
315
|
+
variant: "ghost",
|
|
316
|
+
size: "sm",
|
|
317
|
+
onClick: () => {
|
|
318
|
+
t.chain().focus().extendMarkRange("link").unsetLink().run(), a(!1);
|
|
319
|
+
},
|
|
320
|
+
children: r.linkRemove
|
|
321
|
+
}), /* @__PURE__ */ H(e, {
|
|
322
|
+
type: "submit",
|
|
323
|
+
size: "sm",
|
|
324
|
+
children: r.linkApply
|
|
325
|
+
})]
|
|
326
|
+
})]
|
|
327
|
+
})
|
|
328
|
+
})]
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
// src/toolbar/table-menu.component.tsx
|
|
332
|
+
var ze = [
|
|
333
|
+
[
|
|
334
|
+
{
|
|
335
|
+
label: "tableRowAbove",
|
|
336
|
+
icon: /* @__PURE__ */ H(be, {}),
|
|
337
|
+
command: (e) => e.addRowBefore()
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
label: "tableRowBelow",
|
|
341
|
+
icon: /* @__PURE__ */ H(xe, {}),
|
|
342
|
+
command: (e) => e.addRowAfter()
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
label: "tableRowDelete",
|
|
346
|
+
icon: /* @__PURE__ */ H(ye, {}),
|
|
347
|
+
command: (e) => e.deleteRow()
|
|
348
|
+
}
|
|
349
|
+
],
|
|
350
|
+
[
|
|
351
|
+
{
|
|
352
|
+
label: "tableColumnLeft",
|
|
353
|
+
icon: /* @__PURE__ */ H(V, {}),
|
|
354
|
+
command: (e) => e.addColumnBefore()
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
label: "tableColumnRight",
|
|
358
|
+
icon: /* @__PURE__ */ H(pe, {}),
|
|
359
|
+
command: (e) => e.addColumnAfter()
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
label: "tableColumnDelete",
|
|
363
|
+
icon: /* @__PURE__ */ H(B, {}),
|
|
364
|
+
command: (e) => e.deleteColumn()
|
|
365
|
+
}
|
|
366
|
+
],
|
|
367
|
+
[
|
|
368
|
+
{
|
|
369
|
+
label: "tableMergeCells",
|
|
370
|
+
icon: /* @__PURE__ */ H(R, {}),
|
|
371
|
+
command: (e) => e.mergeCells()
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
label: "tableSplitCell",
|
|
375
|
+
icon: /* @__PURE__ */ H(z, {}),
|
|
376
|
+
command: (e) => e.splitCell()
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
label: "tableHeaderRow",
|
|
380
|
+
icon: /* @__PURE__ */ H(ge, {}),
|
|
381
|
+
command: (e) => e.toggleHeaderRow()
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
label: "tableHeaderColumn",
|
|
385
|
+
icon: /* @__PURE__ */ H(he, {}),
|
|
386
|
+
command: (e) => e.toggleHeaderColumn()
|
|
387
|
+
}
|
|
388
|
+
],
|
|
389
|
+
[{
|
|
390
|
+
label: "tableDelete",
|
|
391
|
+
icon: /* @__PURE__ */ H(me, {}),
|
|
392
|
+
command: (e) => e.deleteTable()
|
|
393
|
+
}]
|
|
394
|
+
];
|
|
395
|
+
function Be({ editor: e, inTable: i, labels: a }) {
|
|
396
|
+
return /* @__PURE__ */ U(t, { children: [/* @__PURE__ */ H(s, {
|
|
397
|
+
asChild: !0,
|
|
398
|
+
children: /* @__PURE__ */ H(J, {
|
|
399
|
+
label: a.table,
|
|
400
|
+
icon: /* @__PURE__ */ H(_e, {}),
|
|
401
|
+
pressed: i
|
|
402
|
+
})
|
|
403
|
+
}), /* @__PURE__ */ U(n, {
|
|
404
|
+
align: "start",
|
|
405
|
+
children: [/* @__PURE__ */ U(r, {
|
|
406
|
+
disabled: i,
|
|
407
|
+
onSelect: () => e.chain().focus().insertTable({
|
|
408
|
+
rows: 3,
|
|
409
|
+
cols: 3,
|
|
410
|
+
withHeaderRow: !0
|
|
411
|
+
}).run(),
|
|
412
|
+
children: [/* @__PURE__ */ H(ve, {}), a.tableInsert]
|
|
413
|
+
}), ze.map((t) => /* @__PURE__ */ U("div", {
|
|
414
|
+
role: "none",
|
|
415
|
+
children: [/* @__PURE__ */ H(o, {}), t.map((t) => /* @__PURE__ */ U(r, {
|
|
416
|
+
disabled: !i || !t.command(e.can().chain()).run(),
|
|
417
|
+
onSelect: () => t.command(e.chain().focus()).run(),
|
|
418
|
+
children: [t.icon, a[t.label]]
|
|
419
|
+
}, t.label))]
|
|
420
|
+
}, t[0]?.label))]
|
|
421
|
+
})] });
|
|
422
|
+
}
|
|
423
|
+
// src/toolbar/text-color-menu.component.tsx
|
|
424
|
+
var Ve = [
|
|
425
|
+
"red",
|
|
426
|
+
"orange",
|
|
427
|
+
"amber",
|
|
428
|
+
"green",
|
|
429
|
+
"teal",
|
|
430
|
+
"blue",
|
|
431
|
+
"violet",
|
|
432
|
+
"pink"
|
|
433
|
+
].map((e) => `var(--color-${e}-600)`);
|
|
434
|
+
function He({ editor: e, color: t, labels: n }) {
|
|
435
|
+
let [r, i] = _(!1);
|
|
436
|
+
function a(t) {
|
|
437
|
+
t ? e.chain().focus().setColor(t).run() : e.chain().focus().unsetColor().run(), i(!1);
|
|
438
|
+
}
|
|
439
|
+
return /* @__PURE__ */ U(l, {
|
|
440
|
+
open: r,
|
|
441
|
+
onOpenChange: i,
|
|
442
|
+
children: [/* @__PURE__ */ H(d, {
|
|
443
|
+
asChild: !0,
|
|
444
|
+
children: /* @__PURE__ */ H(J, {
|
|
445
|
+
label: n.textColor,
|
|
446
|
+
icon: /* @__PURE__ */ H(Se, {}),
|
|
447
|
+
style: t ? { color: t } : void 0
|
|
448
|
+
})
|
|
449
|
+
}), /* @__PURE__ */ H(u, {
|
|
450
|
+
align: "start",
|
|
451
|
+
className: "w-auto p-2",
|
|
452
|
+
children: /* @__PURE__ */ U("div", {
|
|
453
|
+
role: "group",
|
|
454
|
+
"aria-label": n.textColor,
|
|
455
|
+
className: "grid grid-cols-5 gap-1.5",
|
|
456
|
+
children: [/* @__PURE__ */ H("button", {
|
|
457
|
+
type: "button",
|
|
458
|
+
"aria-label": n.colorDefault,
|
|
459
|
+
"aria-pressed": t === void 0,
|
|
460
|
+
className: "size-7 cursor-pointer rounded-md border border-border bg-foreground outline-none focus-visible:ring-2 focus-visible:ring-ring aria-pressed:ring-2 aria-pressed:ring-ring",
|
|
461
|
+
onClick: () => {
|
|
462
|
+
a(void 0);
|
|
463
|
+
}
|
|
464
|
+
}), Ve.map((e) => /* @__PURE__ */ H("button", {
|
|
465
|
+
type: "button",
|
|
466
|
+
"aria-label": e.slice(14, -5),
|
|
467
|
+
"aria-pressed": t === e,
|
|
468
|
+
className: h("size-7 cursor-pointer rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring aria-pressed:ring-2 aria-pressed:ring-ring"),
|
|
469
|
+
style: { background: e },
|
|
470
|
+
onClick: () => {
|
|
471
|
+
a(e);
|
|
472
|
+
}
|
|
473
|
+
}, e))]
|
|
474
|
+
})
|
|
475
|
+
})]
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
// src/toolbar/editor-toolbar.component.tsx
|
|
479
|
+
var Ue = /* @__PURE__ */ new Set([
|
|
480
|
+
"heading",
|
|
481
|
+
"link",
|
|
482
|
+
"table",
|
|
483
|
+
"textColor"
|
|
484
|
+
]);
|
|
485
|
+
function We(e) {
|
|
486
|
+
if (![
|
|
487
|
+
"ArrowLeft",
|
|
488
|
+
"ArrowRight",
|
|
489
|
+
"Home",
|
|
490
|
+
"End"
|
|
491
|
+
].includes(e.key)) return;
|
|
492
|
+
let t = [...e.currentTarget.querySelectorAll("button:not(:disabled)")], n = t.indexOf(document.activeElement), r = e.key === "ArrowRight" != (getComputedStyle(e.currentTarget).direction === "rtl"), i = {
|
|
493
|
+
Home: 0,
|
|
494
|
+
End: t.length - 1
|
|
495
|
+
}[e.key] ?? (n + (r ? 1 : -1) + t.length) % t.length;
|
|
496
|
+
e.preventDefault(), t[i]?.focus();
|
|
497
|
+
}
|
|
498
|
+
function Ge({ editor: e, items: t, labels: n }) {
|
|
499
|
+
let r = re({
|
|
500
|
+
editor: e,
|
|
501
|
+
selector: ({ editor: e }) => ({
|
|
502
|
+
buttons: Object.fromEntries(t.filter((e) => e !== "|" && !Ue.has(e)).map((t) => {
|
|
503
|
+
let n = K[t];
|
|
504
|
+
return [t, {
|
|
505
|
+
enabled: e.isEditable && n.canRun(e),
|
|
506
|
+
active: n.isActive?.(e)
|
|
507
|
+
}];
|
|
508
|
+
})),
|
|
509
|
+
level: [
|
|
510
|
+
1,
|
|
511
|
+
2,
|
|
512
|
+
3,
|
|
513
|
+
4,
|
|
514
|
+
5,
|
|
515
|
+
6
|
|
516
|
+
].find((t) => e.isActive("heading", { level: t })) ?? 0,
|
|
517
|
+
href: e.isActive("link") ? String(e.getAttributes("link").href) : void 0,
|
|
518
|
+
color: e.getAttributes("textStyle").color,
|
|
519
|
+
inTable: e.isActive("table")
|
|
520
|
+
})
|
|
521
|
+
});
|
|
522
|
+
return /* @__PURE__ */ H("div", {
|
|
523
|
+
role: "toolbar",
|
|
524
|
+
"aria-label": n.toolbar,
|
|
525
|
+
"data-slot": "editor-toolbar",
|
|
526
|
+
className: "flex flex-wrap items-center gap-0.5 border-b border-border p-1",
|
|
527
|
+
onKeyDown: We,
|
|
528
|
+
children: t.map((t, i) => {
|
|
529
|
+
let a = `${t}-${String(i)}`;
|
|
530
|
+
if (t === "|") return /* @__PURE__ */ H(f, {
|
|
531
|
+
orientation: "vertical",
|
|
532
|
+
className: "mx-1 h-5"
|
|
533
|
+
}, a);
|
|
534
|
+
if (t === "heading") return /* @__PURE__ */ H(X, {
|
|
535
|
+
editor: e,
|
|
536
|
+
level: r.level,
|
|
537
|
+
labels: n
|
|
538
|
+
}, a);
|
|
539
|
+
if (t === "link") return /* @__PURE__ */ H(Re, {
|
|
540
|
+
editor: e,
|
|
541
|
+
href: r.href,
|
|
542
|
+
labels: n
|
|
543
|
+
}, a);
|
|
544
|
+
if (t === "table") return /* @__PURE__ */ H(Be, {
|
|
545
|
+
editor: e,
|
|
546
|
+
inTable: r.inTable,
|
|
547
|
+
labels: n
|
|
548
|
+
}, a);
|
|
549
|
+
if (t === "textColor") return /* @__PURE__ */ H(He, {
|
|
550
|
+
editor: e,
|
|
551
|
+
color: r.color,
|
|
552
|
+
labels: n
|
|
553
|
+
}, a);
|
|
554
|
+
let o = K[t], s = r.buttons[t];
|
|
555
|
+
return /* @__PURE__ */ H(J, {
|
|
556
|
+
label: n[t],
|
|
557
|
+
icon: o.icon,
|
|
558
|
+
shortcut: o.shortcut,
|
|
559
|
+
pressed: s?.active,
|
|
560
|
+
disabled: !s?.enabled,
|
|
561
|
+
onClick: () => {
|
|
562
|
+
o.run(e);
|
|
563
|
+
}
|
|
564
|
+
}, a);
|
|
565
|
+
})
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
// src/toolbar/rich-text-labels.content.ts
|
|
569
|
+
var Z = {
|
|
570
|
+
toolbar: "Formatting",
|
|
571
|
+
undo: "Undo",
|
|
572
|
+
redo: "Redo",
|
|
573
|
+
heading: "Text style",
|
|
574
|
+
bold: "Bold",
|
|
575
|
+
italic: "Italic",
|
|
576
|
+
underline: "Underline",
|
|
577
|
+
strike: "Strikethrough",
|
|
578
|
+
code: "Inline code",
|
|
579
|
+
subscript: "Subscript",
|
|
580
|
+
superscript: "Superscript",
|
|
581
|
+
highlight: "Highlight",
|
|
582
|
+
textColor: "Text colour",
|
|
583
|
+
clearFormatting: "Clear formatting",
|
|
584
|
+
bulletList: "Bulleted list",
|
|
585
|
+
orderedList: "Numbered list",
|
|
586
|
+
taskList: "Checklist",
|
|
587
|
+
indent: "Indent",
|
|
588
|
+
outdent: "Outdent",
|
|
589
|
+
blockquote: "Quote",
|
|
590
|
+
codeBlock: "Code block",
|
|
591
|
+
horizontalRule: "Divider",
|
|
592
|
+
link: "Link",
|
|
593
|
+
table: "Table",
|
|
594
|
+
alignLeft: "Align left",
|
|
595
|
+
alignCenter: "Align centre",
|
|
596
|
+
alignRight: "Align right",
|
|
597
|
+
alignJustify: "Justify",
|
|
598
|
+
paragraph: "Paragraph",
|
|
599
|
+
heading1: "Heading 1",
|
|
600
|
+
heading2: "Heading 2",
|
|
601
|
+
heading3: "Heading 3",
|
|
602
|
+
heading4: "Heading 4",
|
|
603
|
+
heading5: "Heading 5",
|
|
604
|
+
heading6: "Heading 6",
|
|
605
|
+
linkUrl: "Link address",
|
|
606
|
+
linkApply: "Apply",
|
|
607
|
+
linkRemove: "Remove link",
|
|
608
|
+
colorDefault: "Default colour",
|
|
609
|
+
tableInsert: "Insert table",
|
|
610
|
+
tableRowAbove: "Insert row above",
|
|
611
|
+
tableRowBelow: "Insert row below",
|
|
612
|
+
tableRowDelete: "Delete row",
|
|
613
|
+
tableColumnLeft: "Insert column left",
|
|
614
|
+
tableColumnRight: "Insert column right",
|
|
615
|
+
tableColumnDelete: "Delete column",
|
|
616
|
+
tableMergeCells: "Merge cells",
|
|
617
|
+
tableSplitCell: "Split cell",
|
|
618
|
+
tableHeaderRow: "Header row",
|
|
619
|
+
tableHeaderColumn: "Header column",
|
|
620
|
+
tableDelete: "Delete table"
|
|
621
|
+
}, Q = {
|
|
622
|
+
minimal: [
|
|
623
|
+
"bold",
|
|
624
|
+
"italic",
|
|
625
|
+
"link",
|
|
626
|
+
"|",
|
|
627
|
+
"bulletList",
|
|
628
|
+
"orderedList"
|
|
629
|
+
],
|
|
630
|
+
standard: [
|
|
631
|
+
"undo",
|
|
632
|
+
"redo",
|
|
633
|
+
"|",
|
|
634
|
+
"heading",
|
|
635
|
+
"|",
|
|
636
|
+
"bold",
|
|
637
|
+
"italic",
|
|
638
|
+
"underline",
|
|
639
|
+
"strike",
|
|
640
|
+
"code",
|
|
641
|
+
"|",
|
|
642
|
+
"bulletList",
|
|
643
|
+
"orderedList",
|
|
644
|
+
"taskList",
|
|
645
|
+
"|",
|
|
646
|
+
"blockquote",
|
|
647
|
+
"codeBlock",
|
|
648
|
+
"link"
|
|
649
|
+
],
|
|
650
|
+
full: /* @__PURE__ */ "undo.redo.|.heading.|.bold.italic.underline.strike.code.subscript.superscript.highlight.textColor.clearFormatting.|.bulletList.orderedList.taskList.outdent.indent.|.alignLeft.alignCenter.alignRight.alignJustify.|.blockquote.codeBlock.horizontalRule.link.table".split(".")
|
|
651
|
+
};
|
|
652
|
+
// src/rich-text-editor/editor-extensions.config.ts
|
|
653
|
+
function Ke(e = "") {
|
|
654
|
+
return [
|
|
655
|
+
Pe.configure({
|
|
656
|
+
bulletList: !1,
|
|
657
|
+
orderedList: !1,
|
|
658
|
+
listItem: !1,
|
|
659
|
+
listKeymap: !1,
|
|
660
|
+
link: {
|
|
661
|
+
openOnClick: !1,
|
|
662
|
+
autolink: !0,
|
|
663
|
+
defaultProtocol: "https"
|
|
664
|
+
}
|
|
665
|
+
}),
|
|
666
|
+
Ee.configure({ taskItem: { nested: !0 } }),
|
|
667
|
+
ke.configure({ table: { resizable: !1 } }),
|
|
668
|
+
Ae.configure({ types: ["heading", "paragraph"] }),
|
|
669
|
+
je.configure({
|
|
670
|
+
backgroundColor: !1,
|
|
671
|
+
fontFamily: !1,
|
|
672
|
+
fontSize: !1,
|
|
673
|
+
lineHeight: !1
|
|
674
|
+
}),
|
|
675
|
+
Te,
|
|
676
|
+
De,
|
|
677
|
+
Oe,
|
|
678
|
+
Me.configure({ placeholder: e }),
|
|
679
|
+
Ne
|
|
680
|
+
];
|
|
681
|
+
}
|
|
682
|
+
// src/rich-text-editor/editor-content.recipe.ts
|
|
683
|
+
var qe = "[&_.ProseMirror]:min-h-40 [&_.ProseMirror]:px-4 [&_.ProseMirror]:py-3 [&_.ProseMirror]:outline-none [&_.ProseMirror]:text-sm [&_.ProseMirror]:leading-relaxed [&_.ProseMirror>*+*]:mt-3 [&_h1]:text-2xl [&_h1]:font-semibold [&_h2]:text-xl [&_h2]:font-semibold [&_h3]:text-lg [&_h3]:font-semibold [&_h4]:text-base [&_h4]:font-semibold [&_h5]:text-sm [&_h5]:font-semibold [&_h6]:text-xs [&_h6]:font-semibold [&_h6]:uppercase [&_ul]:list-disc [&_ul]:ps-6 [&_ol]:list-decimal [&_ol]:ps-6 [&_li>p]:my-0.5 [&_ul[data-type=taskList]]:list-none [&_ul[data-type=taskList]]:ps-1 [&_ul[data-type=taskList]>li]:flex [&_ul[data-type=taskList]>li]:gap-2 [&_ul[data-type=taskList]>li>label]:mt-0.5 [&_ul[data-type=taskList]>li>label]:flex-none [&_ul[data-type=taskList]>li>label>input]:size-4 [&_ul[data-type=taskList]>li>label>input]:accent-(--color-brand) [&_ul[data-type=taskList]>li>div]:flex-1 [&_li[data-checked=true]>div]:text-muted-foreground [&_li[data-checked=true]>div]:line-through [&_blockquote]:border-s-4 [&_blockquote]:border-brand-soft [&_blockquote]:ps-4 [&_blockquote]:text-muted-foreground [&_:not(pre)>code]:rounded-sm [&_:not(pre)>code]:bg-muted [&_:not(pre)>code]:px-1 [&_:not(pre)>code]:font-mono [&_:not(pre)>code]:text-[0.9em] [&_pre]:overflow-x-auto [&_pre]:rounded-md [&_pre]:bg-muted [&_pre]:p-3 [&_pre]:font-mono [&_pre]:text-[13px] [&_hr]:my-4 [&_hr]:border-border [&_a]:text-brand-text [&_a]:underline [&_a]:underline-offset-2 [&_mark]:rounded-sm [&_mark]:bg-warning-soft [&_mark]:px-0.5 [&_table]:w-full [&_table]:border-collapse [&_table]:table-fixed [&_td]:border [&_td]:border-border [&_td]:p-2 [&_td]:align-top [&_th]:border [&_th]:border-border [&_th]:bg-muted [&_th]:p-2 [&_th]:text-start [&_th]:font-semibold [&_.selectedCell]:bg-brand-soft [&_.is-editor-empty:first-child]:before:pointer-events-none [&_.is-editor-empty:first-child]:before:float-start [&_.is-editor-empty:first-child]:before:h-0 [&_.is-editor-empty:first-child]:before:text-muted-foreground [&_.is-editor-empty:first-child]:before:content-[attr(data-placeholder)]";
|
|
684
|
+
// src/rich-text-editor/rich-text-editor.component.tsx
|
|
685
|
+
function Je({ tools: e = Q.standard, value: t, defaultValue: n, format: r = "markdown", onChange: i, placeholder: a, editable: o = !0, labels: s, extensions: c = [], onEditorReady: l, "aria-label": u, className: d, contentClassName: f }) {
|
|
686
|
+
let p = ne({
|
|
687
|
+
extensions: [...Ke(a), ...c],
|
|
688
|
+
content: t ?? n ?? "",
|
|
689
|
+
contentType: r,
|
|
690
|
+
editable: o,
|
|
691
|
+
immediatelyRender: !0,
|
|
692
|
+
shouldRerenderOnTransaction: !1,
|
|
693
|
+
editorProps: { attributes: {
|
|
694
|
+
role: "textbox",
|
|
695
|
+
"aria-multiline": "true",
|
|
696
|
+
...u && { "aria-label": u }
|
|
697
|
+
} },
|
|
698
|
+
onCreate: ({ editor: e }) => l?.(e),
|
|
699
|
+
onUpdate: ({ editor: e }) => i?.($(e, r))
|
|
700
|
+
});
|
|
701
|
+
g(() => {
|
|
702
|
+
t !== void 0 && t !== $(p, r) && p.commands.setContent(t, {
|
|
703
|
+
contentType: r,
|
|
704
|
+
emitUpdate: !1
|
|
705
|
+
});
|
|
706
|
+
}, [
|
|
707
|
+
p,
|
|
708
|
+
t,
|
|
709
|
+
r
|
|
710
|
+
]), g(() => {
|
|
711
|
+
p.setEditable(o);
|
|
712
|
+
}, [p, o]);
|
|
713
|
+
let m = {
|
|
714
|
+
...Z,
|
|
715
|
+
...s
|
|
716
|
+
};
|
|
717
|
+
return /* @__PURE__ */ U("div", {
|
|
718
|
+
"data-slot": "rich-text-editor",
|
|
719
|
+
className: h("flex flex-col overflow-hidden rounded-md border border-input bg-background focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/25", d),
|
|
720
|
+
children: [o && e.length > 0 && /* @__PURE__ */ H(Ge, {
|
|
721
|
+
editor: p,
|
|
722
|
+
items: e,
|
|
723
|
+
labels: m
|
|
724
|
+
}), /* @__PURE__ */ H(te, {
|
|
725
|
+
editor: p,
|
|
726
|
+
className: h("flex-1 overflow-y-auto", qe, f)
|
|
727
|
+
})]
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
function $(e, t) {
|
|
731
|
+
return t === "markdown" ? e.getMarkdown() : e.getHTML();
|
|
732
|
+
}
|
|
733
|
+
export { Z as DEFAULT_RICH_TEXT_LABELS, Q as RICH_TEXT_PRESETS, Je as RichTextEditor };
|
|
734
|
+
|
|
735
|
+
//# sourceMappingURL=index.js.map
|