@iclips/ui 3.1.0 → 4.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.
@@ -1,158 +1,421 @@
1
- import { jsxs as r, jsx as e, Fragment as p } from "react/jsx-runtime";
2
- import * as A from "react";
3
- import { useEditor as x, EditorContent as b } from "@tiptap/react";
4
- import w from "@tiptap/starter-kit";
5
- import N from "@tiptap/extension-image";
6
- import C from "@tiptap/extension-placeholder";
7
- import L from "@tiptap/extension-text-align";
8
- import { cn as o } from "../utils.js";
9
- import { Button as f } from "../primitives/button.js";
10
- import { Separator as h } from "../primitives/separator.js";
11
- import { Undo as T, Redo as H, Heading1 as I, Heading2 as R, Heading3 as q, Bold as y, Italic as z, Underline as U, Strikethrough as B, List as M, ListOrdered as S, AlignLeft as E, AlignCenter as P, AlignRight as j, Quote as D, Link as F, Image as K } from "lucide-react";
12
- import { Toggle as Q } from "../forms/toggle.js";
13
- const l = ({
14
- onClick: i,
15
- isActive: s = !1,
16
- disabled: a = !1,
17
- children: n,
18
- title: t
19
- }) => /* @__PURE__ */ e(
20
- Q,
21
- {
22
- pressed: s,
23
- onPressedChange: i,
24
- disabled: a,
25
- size: "sm",
26
- className: "h-8 w-8 p-0",
27
- title: t,
28
- "aria-label": t,
29
- children: n
1
+ import { jsxs as u, jsx as e, Fragment as D } from "react/jsx-runtime";
2
+ import * as O from "react";
3
+ import { useEditor as re, EditorContent as ne } from "@tiptap/react";
4
+ import ae from "@tiptap/starter-kit";
5
+ import K from "@tiptap/extension-image";
6
+ import oe from "@tiptap/extension-placeholder";
7
+ import le from "@tiptap/extension-text-align";
8
+ import se from "@tiptap/extension-file-handler";
9
+ import { TableKit as ce } from "@tiptap/extension-table";
10
+ import { cn as k } from "../utils.js";
11
+ import { Button as U } from "../primitives/button.js";
12
+ import { Separator as S } from "../primitives/separator.js";
13
+ import { Undo as ue, Redo as me, Bold as he, Italic as de, Underline as ge, Strikethrough as fe, List as pe, ListOrdered as be, AlignLeft as Ae, AlignCenter as we, AlignRight as xe, Quote as ve, Link as Me, Table as Ne, Image as j, Minus as ke, Plus as Te } from "lucide-react";
14
+ import { Toggle as Le } from "../forms/toggle.js";
15
+ import { Select as Ie, SelectTrigger as Ce, SelectValue as Pe, SelectContent as _e, SelectItem as Re } from "../forms/select.js";
16
+ import { DropdownMenu as Se, DropdownMenuTrigger as ye, DropdownMenuContent as Ee, DropdownMenuItem as N, DropdownMenuSeparator as W } from "../overlays/dropdown-menu.js";
17
+ import { Tooltip as E, TooltipTrigger as z, TooltipContent as H } from "../overlays/tooltip.js";
18
+ import { toast as F } from "../feedback/toast.js";
19
+ const q = 96 / 2.54, ze = Math.round(5 * q), He = Math.round(2 * q), J = Math.round(1 * q), De = ["image/png", "image/jpeg", "image/webp"], Oe = 2 * 1024 * 1024, Q = 0.1, A = {
20
+ larguraPx: 794,
21
+ alturaMinPx: 1123,
22
+ margemPx: 40 / 72 * 96
23
+ }, b = Math.round(A.larguraPx - 2 * A.margemPx), Fe = `${(11 / 0.75 / A.larguraPx * 100).toFixed(3)}cqw`, Ue = `${((A.alturaMinPx - 2 * A.margemPx) / A.larguraPx * 100).toFixed(3)}cqw`, qe = `${(A.margemPx / A.larguraPx * 100).toFixed(3)}cqw`;
24
+ function V(t) {
25
+ if (t == null) return null;
26
+ const i = Number.parseInt(t, 10);
27
+ return Number.isFinite(i) && i > 0 ? i : null;
28
+ }
29
+ const Be = ["left", "center", "right"], Ge = K.extend({
30
+ addAttributes() {
31
+ var t;
32
+ return {
33
+ ...(t = this.parent) == null ? void 0 : t.call(this),
34
+ // Fica em `data-align`, não em `style`: o node view de redimensionamento usa o `style` do <img> para o
35
+ // tamanho, e um `text-align` ali o sobrescreveria. Esquerda é o padrão e não sai no HTML.
36
+ align: {
37
+ default: null,
38
+ parseHTML: (i) => {
39
+ const r = i.getAttribute("data-align");
40
+ return Be.includes(r ?? "") && r !== "left" ? r : null;
41
+ },
42
+ renderHTML: (i) => i.align ? { "data-align": i.align } : {}
43
+ },
44
+ width: {
45
+ default: null,
46
+ parseHTML: (i) => V(i.getAttribute("width")),
47
+ renderHTML: (i) => {
48
+ const r = Number(i.width);
49
+ return !Number.isFinite(r) || r <= 0 ? {} : { width: Math.min(Math.round(r), b) };
50
+ }
51
+ },
52
+ height: {
53
+ default: null,
54
+ parseHTML: (i) => V(i.getAttribute("height")),
55
+ renderHTML: (i) => {
56
+ const r = Number(i.width), a = Number(i.height);
57
+ if (!Number.isFinite(a) || a <= 0) return {};
58
+ const n = Number.isFinite(r) && r > b ? b / r : 1;
59
+ return { height: Math.round(a * n) };
60
+ }
61
+ }
62
+ };
63
+ },
64
+ // O node view de redimensionamento só aplica `width`/`height` ao nascer e ao arrastar: mudar os atributos por
65
+ // comando (botões de tamanho, desfazer, refazer) não mudava a imagem na tela. Reaplica a cada atualização.
66
+ addNodeView() {
67
+ var i;
68
+ const t = (i = this.parent) == null ? void 0 : i.call(this);
69
+ return t ? (r) => {
70
+ var f;
71
+ const a = t(r), n = a;
72
+ ("maxSize" in n || "minSize" in n) && (n.maxSize = { ...n.maxSize, width: b }, a.dom.addEventListener(
73
+ "mousedown",
74
+ () => {
75
+ var l;
76
+ const c = (l = a.dom.closest(".ProseMirror")) == null ? void 0 : l.clientWidth;
77
+ n.maxSize = {
78
+ ...n.maxSize,
79
+ width: c ? Math.min(b, c) : b
80
+ };
81
+ },
82
+ !0
83
+ ));
84
+ const m = (c, l) => {
85
+ const h = a.dom.querySelector("img");
86
+ if (!h || !c || !l) return;
87
+ const w = c > b ? b / c : 1;
88
+ h.style.width = `${Math.round(c * w)}px`, h.style.height = `${Math.round(l * w)}px`;
89
+ }, p = (f = a.update) == null ? void 0 : f.bind(a);
90
+ return a.update = (c, ...l) => {
91
+ const h = p ? p(c, ...l) : !0;
92
+ return h && m(c.attrs.width, c.attrs.height), h;
93
+ }, a;
94
+ } : null;
30
95
  }
31
- ), G = ({ editor: i, variant: s }) => {
32
- if (!i) return null;
33
- const a = () => {
34
- const t = i.getAttributes("link").href, c = window.prompt("URL", t);
35
- if (c !== null) {
36
- if (c === "") {
37
- i.chain().focus().extendMarkRange("link").unsetLink().run();
96
+ });
97
+ async function $e(t) {
98
+ var i;
99
+ if (typeof createImageBitmap != "function") return null;
100
+ try {
101
+ const r = await createImageBitmap(t), a = { largura: r.width, altura: r.height };
102
+ return (i = r.close) == null || i.call(r), a;
103
+ } catch {
104
+ return null;
105
+ }
106
+ }
107
+ function Xe(t, i) {
108
+ const r = t.largura / t.altura, a = Math.min(t.largura, i.width, i.maxHeight * r), n = Math.max(1, Math.round(a));
109
+ return { width: n, height: Math.max(1, Math.round(n / r)) };
110
+ }
111
+ const g = ({
112
+ onClick: t,
113
+ isActive: i = !1,
114
+ disabled: r = !1,
115
+ children: a,
116
+ title: n,
117
+ tooltip: m = !1
118
+ }) => {
119
+ const p = /* @__PURE__ */ e(
120
+ Le,
121
+ {
122
+ pressed: i,
123
+ onPressedChange: t,
124
+ disabled: r,
125
+ size: "sm",
126
+ className: "h-8 w-8 p-0",
127
+ title: m ? void 0 : n,
128
+ "aria-label": n,
129
+ children: a
130
+ }
131
+ );
132
+ return !m || !n ? p : /* @__PURE__ */ u(E, { children: [
133
+ /* @__PURE__ */ e(z, { asChild: !0, children: p }),
134
+ /* @__PURE__ */ e(H, { children: n })
135
+ ] });
136
+ }, y = ({
137
+ onClick: t,
138
+ disabled: i,
139
+ label: r,
140
+ tooltip: a,
141
+ children: n
142
+ }) => {
143
+ const m = /* @__PURE__ */ e(U, { variant: "ghost", size: "icon", className: "h-8 w-8", onClick: t, disabled: i, "aria-label": r, children: n });
144
+ return a ? /* @__PURE__ */ u(E, { children: [
145
+ /* @__PURE__ */ e(z, { asChild: !0, children: m }),
146
+ /* @__PURE__ */ e(H, { children: r })
147
+ ] }) : m;
148
+ }, je = [
149
+ { valor: "paragraph", rotulo: "Parágrafo" },
150
+ { valor: "h1", rotulo: "Título 1" },
151
+ { valor: "h2", rotulo: "Título 2" },
152
+ { valor: "h3", rotulo: "Título 3" }
153
+ ];
154
+ function We(t) {
155
+ for (const i of [1, 2, 3])
156
+ if (t.isActive("heading", { level: i })) return `h${i}`;
157
+ return "paragraph";
158
+ }
159
+ function Qe(t, i) {
160
+ const r = t.chain().focus();
161
+ i === "paragraph" ? r.setParagraph().run() : r.setHeading({ level: Number(i.slice(1)) }).run();
162
+ }
163
+ const Ve = ({
164
+ editor: t,
165
+ variant: i,
166
+ onPickImage: r,
167
+ imageHint: a
168
+ }) => {
169
+ if (!t) return null;
170
+ const n = i === "full", m = () => {
171
+ const o = t.getAttributes("link").href, s = window.prompt("URL", o);
172
+ if (s !== null) {
173
+ if (s === "") {
174
+ t.chain().focus().extendMarkRange("link").unsetLink().run();
38
175
  return;
39
176
  }
40
- i.chain().focus().extendMarkRange("link").setLink({ href: c }).run();
177
+ t.chain().focus().extendMarkRange("link").setLink({ href: s }).run();
41
178
  }
42
- }, n = () => {
43
- const t = window.prompt("URL da imagem");
44
- t && i.chain().focus().setImage({ src: t }).run();
179
+ }, p = () => {
180
+ const o = window.prompt("URL da imagem");
181
+ o && t.chain().focus().setImage({ src: o }).run();
182
+ }, f = t.isActive("image"), c = (o) => {
183
+ const { width: s, height: v } = t.getAttributes("image");
184
+ if (!s || !v) return;
185
+ const T = Math.min(b, Math.max(J, Math.round(s * o)));
186
+ t.chain().focus().updateAttributes("image", { width: T, height: Math.round(v * T / s) }).run();
187
+ }, l = t.isActive("table"), h = (o) => f ? (t.getAttributes("image").align ?? "left") === o : t.isActive({ textAlign: o }), w = (o) => {
188
+ f ? t.chain().focus().updateAttributes("image", { align: o === "left" ? null : o }).run() : t.chain().focus().setTextAlign(o).run();
45
189
  };
46
- return /* @__PURE__ */ r("div", { className: o(
190
+ return /* @__PURE__ */ u("div", { className: k(
47
191
  "flex flex-wrap items-center gap-1 p-2 border-b bg-muted/30 sticky top-0 z-10",
48
- s === "full" ? "px-4 py-2" : "px-2 py-1"
192
+ n ? "px-4 py-2" : "px-2 py-1"
49
193
  ), children: [
50
- /* @__PURE__ */ r("div", { className: "flex items-center gap-0.5 mr-2", children: [
51
- /* @__PURE__ */ e(f, { variant: "ghost", size: "icon", className: "h-8 w-8", onClick: () => i.chain().focus().undo().run(), disabled: !i.can().undo(), "aria-label": "Desfazer", children: /* @__PURE__ */ e(T, { className: "h-4 w-4" }) }),
52
- /* @__PURE__ */ e(f, { variant: "ghost", size: "icon", className: "h-8 w-8", onClick: () => i.chain().focus().redo().run(), disabled: !i.can().redo(), "aria-label": "Refazer", children: /* @__PURE__ */ e(H, { className: "h-4 w-4" }) })
194
+ /* @__PURE__ */ u("div", { className: "flex items-center gap-0.5 mr-2", children: [
195
+ /* @__PURE__ */ e(y, { tooltip: n, label: "Desfazer", onClick: () => t.chain().focus().undo().run(), disabled: !t.can().undo(), children: /* @__PURE__ */ e(ue, { className: "h-4 w-4" }) }),
196
+ /* @__PURE__ */ e(y, { tooltip: n, label: "Refazer", onClick: () => t.chain().focus().redo().run(), disabled: !t.can().redo(), children: /* @__PURE__ */ e(me, { className: "h-4 w-4" }) })
197
+ ] }),
198
+ /* @__PURE__ */ e(S, { orientation: "vertical", className: "h-6 mx-1" }),
199
+ n && /* @__PURE__ */ u(D, { children: [
200
+ /* @__PURE__ */ u(Ie, { value: We(t), onValueChange: (o) => Qe(t, o), children: [
201
+ /* @__PURE__ */ e(Ce, { size: "sm", className: "w-[130px]", "aria-label": "Estilo do texto", children: /* @__PURE__ */ e(Pe, {}) }),
202
+ /* @__PURE__ */ e(_e, { children: je.map((o) => /* @__PURE__ */ e(Re, { value: o.valor, children: o.rotulo }, o.valor)) })
203
+ ] }),
204
+ /* @__PURE__ */ e(S, { orientation: "vertical", className: "h-6 mx-1" })
53
205
  ] }),
54
- /* @__PURE__ */ e(h, { orientation: "vertical", className: "h-6 mx-1" }),
55
- s === "full" && /* @__PURE__ */ r(p, { children: [
56
- /* @__PURE__ */ e(l, { onClick: () => i.chain().focus().toggleHeading({ level: 1 }).run(), isActive: i.isActive("heading", { level: 1 }), title: "Título 1", children: /* @__PURE__ */ e(I, { className: "h-4 w-4" }) }),
57
- /* @__PURE__ */ e(l, { onClick: () => i.chain().focus().toggleHeading({ level: 2 }).run(), isActive: i.isActive("heading", { level: 2 }), title: "Título 2", children: /* @__PURE__ */ e(R, { className: "h-4 w-4" }) }),
58
- /* @__PURE__ */ e(l, { onClick: () => i.chain().focus().toggleHeading({ level: 3 }).run(), isActive: i.isActive("heading", { level: 3 }), title: "Título 3", children: /* @__PURE__ */ e(q, { className: "h-4 w-4" }) }),
59
- /* @__PURE__ */ e(h, { orientation: "vertical", className: "h-6 mx-1" })
206
+ /* @__PURE__ */ e(g, { tooltip: n, onClick: () => t.chain().focus().toggleBold().run(), isActive: t.isActive("bold"), title: "Negrito", children: /* @__PURE__ */ e(he, { className: "h-4 w-4" }) }),
207
+ /* @__PURE__ */ e(g, { tooltip: n, onClick: () => t.chain().focus().toggleItalic().run(), isActive: t.isActive("italic"), title: "Itálico", children: /* @__PURE__ */ e(de, { className: "h-4 w-4" }) }),
208
+ /* @__PURE__ */ e(g, { tooltip: n, onClick: () => t.chain().focus().toggleUnderline().run(), isActive: t.isActive("underline"), title: "Sublinhado", children: /* @__PURE__ */ e(ge, { className: "h-4 w-4" }) }),
209
+ n && /* @__PURE__ */ e(g, { tooltip: !0, onClick: () => t.chain().focus().toggleStrike().run(), isActive: t.isActive("strike"), title: "Tachado", children: /* @__PURE__ */ e(fe, { className: "h-4 w-4" }) }),
210
+ /* @__PURE__ */ e(S, { orientation: "vertical", className: "h-6 mx-1" }),
211
+ /* @__PURE__ */ e(g, { tooltip: n, onClick: () => t.chain().focus().toggleBulletList().run(), isActive: t.isActive("bulletList"), title: "Lista com marcadores", children: /* @__PURE__ */ e(pe, { className: "h-4 w-4" }) }),
212
+ /* @__PURE__ */ e(g, { tooltip: n, onClick: () => t.chain().focus().toggleOrderedList().run(), isActive: t.isActive("orderedList"), title: "Lista numerada", children: /* @__PURE__ */ e(be, { className: "h-4 w-4" }) }),
213
+ n && /* @__PURE__ */ u(D, { children: [
214
+ /* @__PURE__ */ e(g, { tooltip: !0, onClick: () => w("left"), isActive: h("left"), title: "Alinhar à esquerda", children: /* @__PURE__ */ e(Ae, { className: "h-4 w-4" }) }),
215
+ /* @__PURE__ */ e(g, { tooltip: !0, onClick: () => w("center"), isActive: h("center"), title: "Centralizar", children: /* @__PURE__ */ e(we, { className: "h-4 w-4" }) }),
216
+ /* @__PURE__ */ e(g, { tooltip: !0, onClick: () => w("right"), isActive: h("right"), title: "Alinhar à direita", children: /* @__PURE__ */ e(xe, { className: "h-4 w-4" }) })
60
217
  ] }),
61
- /* @__PURE__ */ e(l, { onClick: () => i.chain().focus().toggleBold().run(), isActive: i.isActive("bold"), title: "Negrito", children: /* @__PURE__ */ e(y, { className: "h-4 w-4" }) }),
62
- /* @__PURE__ */ e(l, { onClick: () => i.chain().focus().toggleItalic().run(), isActive: i.isActive("italic"), title: "Itálico", children: /* @__PURE__ */ e(z, { className: "h-4 w-4" }) }),
63
- /* @__PURE__ */ e(l, { onClick: () => i.chain().focus().toggleUnderline().run(), isActive: i.isActive("underline"), title: "Sublinhado", children: /* @__PURE__ */ e(U, { className: "h-4 w-4" }) }),
64
- s === "full" && /* @__PURE__ */ e(l, { onClick: () => i.chain().focus().toggleStrike().run(), isActive: i.isActive("strike"), title: "Tachado", children: /* @__PURE__ */ e(B, { className: "h-4 w-4" }) }),
65
- /* @__PURE__ */ e(h, { orientation: "vertical", className: "h-6 mx-1" }),
66
- /* @__PURE__ */ e(l, { onClick: () => i.chain().focus().toggleBulletList().run(), isActive: i.isActive("bulletList"), title: "Lista com marcadores", children: /* @__PURE__ */ e(M, { className: "h-4 w-4" }) }),
67
- /* @__PURE__ */ e(l, { onClick: () => i.chain().focus().toggleOrderedList().run(), isActive: i.isActive("orderedList"), title: "Lista numerada", children: /* @__PURE__ */ e(S, { className: "h-4 w-4" }) }),
68
- s === "full" && /* @__PURE__ */ r(p, { children: [
69
- /* @__PURE__ */ e(l, { onClick: () => i.chain().focus().setTextAlign("left").run(), isActive: i.isActive({ textAlign: "left" }), title: "Alinhar à esquerda", children: /* @__PURE__ */ e(E, { className: "h-4 w-4" }) }),
70
- /* @__PURE__ */ e(l, { onClick: () => i.chain().focus().setTextAlign("center").run(), isActive: i.isActive({ textAlign: "center" }), title: "Centralizar", children: /* @__PURE__ */ e(P, { className: "h-4 w-4" }) }),
71
- /* @__PURE__ */ e(l, { onClick: () => i.chain().focus().setTextAlign("right").run(), isActive: i.isActive({ textAlign: "right" }), title: "Alinhar à direita", children: /* @__PURE__ */ e(j, { className: "h-4 w-4" }) })
218
+ /* @__PURE__ */ e(S, { orientation: "vertical", className: "h-6 mx-1" }),
219
+ /* @__PURE__ */ e(g, { tooltip: n, onClick: () => t.chain().focus().toggleBlockquote().run(), isActive: t.isActive("blockquote"), title: "Citação", children: /* @__PURE__ */ e(ve, { className: "h-4 w-4" }) }),
220
+ /* @__PURE__ */ e(g, { tooltip: n, onClick: m, isActive: t.isActive("link"), title: "Link", children: /* @__PURE__ */ e(Me, { className: "h-4 w-4" }) }),
221
+ n && /* @__PURE__ */ u(Se, { children: [
222
+ /* @__PURE__ */ u(E, { children: [
223
+ /* @__PURE__ */ e(z, { asChild: !0, children: /* @__PURE__ */ e(ye, { asChild: !0, children: /* @__PURE__ */ e(U, { variant: "ghost", size: "icon", className: k("h-8 w-8", l && "bg-secondary text-secondary-foreground"), "aria-label": "Tabela", children: /* @__PURE__ */ e(Ne, { className: "h-4 w-4" }) }) }) }),
224
+ /* @__PURE__ */ e(H, { children: "Tabela" })
225
+ ] }),
226
+ /* @__PURE__ */ u(Ee, { align: "start", children: [
227
+ /* @__PURE__ */ e(N, { onSelect: () => t.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run(), children: "Inserir tabela" }),
228
+ /* @__PURE__ */ e(W, {}),
229
+ /* @__PURE__ */ e(N, { disabled: !l, onSelect: () => t.chain().focus().addRowAfter().run(), children: "Adicionar linha" }),
230
+ /* @__PURE__ */ e(N, { disabled: !l, onSelect: () => t.chain().focus().addColumnAfter().run(), children: "Adicionar coluna" }),
231
+ /* @__PURE__ */ e(N, { disabled: !l, onSelect: () => t.chain().focus().deleteRow().run(), children: "Remover linha" }),
232
+ /* @__PURE__ */ e(N, { disabled: !l, onSelect: () => t.chain().focus().deleteColumn().run(), children: "Remover coluna" }),
233
+ /* @__PURE__ */ e(W, {}),
234
+ /* @__PURE__ */ e(N, { disabled: !l, onSelect: () => t.chain().focus().deleteTable().run(), children: "Remover tabela" })
235
+ ] })
72
236
  ] }),
73
- /* @__PURE__ */ e(h, { orientation: "vertical", className: "h-6 mx-1" }),
74
- /* @__PURE__ */ e(l, { onClick: () => i.chain().focus().toggleBlockquote().run(), isActive: i.isActive("blockquote"), title: "Citação", children: /* @__PURE__ */ e(D, { className: "h-4 w-4" }) }),
75
- /* @__PURE__ */ e(l, { onClick: a, isActive: i.isActive("link"), title: "Link", children: /* @__PURE__ */ e(F, { className: "h-4 w-4" }) }),
76
- s === "full" && /* @__PURE__ */ e(l, { onClick: n, title: "Imagem", children: /* @__PURE__ */ e(K, { className: "h-4 w-4" }) })
237
+ n && r && /* @__PURE__ */ u(D, { children: [
238
+ /* @__PURE__ */ u(E, { children: [
239
+ /* @__PURE__ */ e(z, { asChild: !0, children: /* @__PURE__ */ e(U, { variant: "ghost", size: "icon", className: "h-8 w-8", onClick: r, "aria-label": "Inserir imagem", children: /* @__PURE__ */ e(j, { className: "h-4 w-4" }) }) }),
240
+ /* @__PURE__ */ e(H, { className: "max-w-64", children: a ?? "Inserir imagem" })
241
+ ] }),
242
+ /* @__PURE__ */ e(y, { tooltip: !0, label: "Diminuir imagem", onClick: () => c(1 - Q), disabled: !f, children: /* @__PURE__ */ e(ke, { className: "h-4 w-4" }) }),
243
+ /* @__PURE__ */ e(y, { tooltip: !0, label: "Aumentar imagem", onClick: () => c(1 + Q), disabled: !f, children: /* @__PURE__ */ e(Te, { className: "h-4 w-4" }) })
244
+ ] }),
245
+ n && !r && /* @__PURE__ */ e(g, { tooltip: !0, onClick: p, title: "Imagem", children: /* @__PURE__ */ e(j, { className: "h-4 w-4" }) })
77
246
  ] });
78
247
  };
79
- function le({
80
- content: i = "",
81
- onChange: s,
82
- placeholder: a = "Comece a escrever...",
83
- variant: n = "simple",
84
- className: t,
85
- readOnly: c = !1,
86
- label: g
248
+ function dt({
249
+ content: t = "",
250
+ onChange: i,
251
+ placeholder: r = "Comece a escrever...",
252
+ variant: a = "simple",
253
+ className: n,
254
+ readOnly: m = !1,
255
+ label: p,
256
+ onImageUpload: f,
257
+ imageDefaults: c,
258
+ imageAcceptedTypes: l = De,
259
+ imageMaxBytes: h = Oe,
260
+ imageHint: w,
261
+ page: o
87
262
  }) {
88
- var m, d;
89
- const v = A.useMemo(() => [
90
- w.configure({
91
- heading: {
92
- levels: [1, 2, 3]
93
- }
94
- }),
95
- // Removed explicit Underline and Link to avoid duplicate extension warning
96
- // If these features are missing, check if StarterKit includes them in your version
97
- // Underline,
98
- // Link.configure({
99
- // openOnClick: false,
100
- // HTMLAttributes: {
101
- // class: 'text-primary underline decoration-primary/30 hover:decoration-primary transition-colors cursor-pointer',
102
- // },
103
- // }),
104
- N.configure({
105
- HTMLAttributes: {
106
- class: "rounded-lg border shadow-sm max-w-full"
263
+ var _, $;
264
+ const s = a === "full", v = s && o === "a4", T = c ?? { width: ze, maxHeight: He }, Y = T.width, Z = T.maxHeight, C = s && !!f, P = O.useRef(async () => {
265
+ });
266
+ P.current = async (d, x, I) => {
267
+ if (f)
268
+ for (const M of x) {
269
+ if (!l.includes(M.type)) {
270
+ F.error("Imagem não inserida", { description: "Use uma imagem PNG, JPG ou WEBP." });
271
+ continue;
272
+ }
273
+ if (M.size > h) {
274
+ F.error("Imagem não inserida", {
275
+ description: `A imagem deve ter no máximo ${Math.round(h / 1024 / 1024)} MB.`
276
+ });
277
+ continue;
278
+ }
279
+ try {
280
+ const [R, X] = await Promise.all([f(M), $e(M)]), ie = X ? Xe(X, { width: Y, maxHeight: Z }) : {};
281
+ d.chain().insertContentAt(I ?? d.state.selection.anchor, { type: "image", attrs: { src: R, ...ie } }).focus().run();
282
+ } catch (R) {
283
+ F.error("Não foi possível inserir a imagem", { description: R instanceof Error ? R.message : void 0 });
284
+ }
107
285
  }
108
- }),
109
- C.configure({
110
- placeholder: a
111
- }),
112
- L.configure({
113
- types: ["heading", "paragraph"]
114
- })
115
- ], [a]), u = x({
116
- extensions: v,
117
- content: i,
118
- editable: !c,
119
- onUpdate: ({ editor: k }) => {
120
- s == null || s(k.getHTML());
286
+ };
287
+ const ee = O.useMemo(() => {
288
+ const d = s ? [
289
+ Ge.configure({
290
+ allowBase64: !0,
291
+ HTMLAttributes: { class: "max-w-full h-auto" },
292
+ resize: {
293
+ enabled: !0,
294
+ directions: ["top-left", "top-right", "bottom-left", "bottom-right"],
295
+ minWidth: J,
296
+ minHeight: 1,
297
+ alwaysPreserveAspectRatio: !0
298
+ }
299
+ }),
300
+ ce.configure({ table: { resizable: !0 } })
301
+ ] : [
302
+ K.configure({
303
+ HTMLAttributes: {
304
+ class: "rounded-lg border shadow-sm max-w-full"
305
+ }
306
+ })
307
+ ];
308
+ return [
309
+ ae.configure({
310
+ heading: {
311
+ levels: [1, 2, 3]
312
+ }
313
+ }),
314
+ // Removed explicit Underline and Link to avoid duplicate extension warning
315
+ // If these features are missing, check if StarterKit includes them in your version
316
+ // Underline,
317
+ // Link.configure({
318
+ // openOnClick: false,
319
+ // HTMLAttributes: {
320
+ // class: 'text-primary underline decoration-primary/30 hover:decoration-primary transition-colors cursor-pointer',
321
+ // },
322
+ // }),
323
+ ...d,
324
+ oe.configure({
325
+ placeholder: r
326
+ }),
327
+ le.configure({
328
+ types: ["heading", "paragraph"]
329
+ }),
330
+ ...C ? [
331
+ se.configure({
332
+ allowedMimeTypes: l,
333
+ onDrop: (x, I, M) => {
334
+ P.current(x, I, M);
335
+ },
336
+ onPaste: (x, I) => {
337
+ P.current(x, I);
338
+ }
339
+ })
340
+ ] : []
341
+ ];
342
+ }, [r, s, C, l.join(",")]), L = re({
343
+ extensions: ee,
344
+ content: t,
345
+ editable: !m,
346
+ shouldRerenderOnTransaction: !0,
347
+ onUpdate: ({ editor: d }) => {
348
+ i == null || i(d.getHTML());
121
349
  },
122
350
  editorProps: {
123
351
  attributes: {
124
- class: o(
125
- "prose prose-stone dark:prose-invert max-w-none focus:outline-none",
352
+ class: k(
353
+ v ? "prose prose-stone max-w-none focus:outline-none" : "prose prose-stone dark:prose-invert max-w-none focus:outline-none",
126
354
  "prose-headings:font-semibold prose-headings:tracking-tight",
127
355
  "prose-h1:text-3xl prose-h2:text-2xl prose-h3:text-xl",
128
356
  "prose-p:leading-7 prose-p:my-3",
129
357
  "prose-blockquote:border-l-4 prose-blockquote:border-primary/50 prose-blockquote:pl-4 prose-blockquote:italic",
130
358
  "prose-ul:list-disc prose-ul:pl-6 prose-ol:list-decimal prose-ol:pl-6",
131
- "prose-img:rounded-lg prose-img:shadow-md prose-img:my-6",
132
- n === "full" ? "min-h-[400px] p-8" : "min-h-[120px] px-3 py-2"
133
- )
359
+ !s && "prose-img:rounded-lg prose-img:shadow-md prose-img:my-6",
360
+ // O contêiner do node view de redimensionamento é um flex: o alinhamento da imagem é dele.
361
+ s && "[&_[data-resize-container]:has([data-align=center])]:justify-center [&_[data-resize-container]:has([data-align=right])]:justify-end",
362
+ v ? void 0 : s ? "min-h-[400px] p-8" : "min-h-[120px] px-3 py-2"
363
+ ),
364
+ ...v ? { style: `font-size: ${Fe}; min-height: ${Ue}` } : {}
134
365
  }
135
366
  }
136
- });
137
- return u ? /* @__PURE__ */ r("div", { className: o("flex flex-col w-full", t), children: [
138
- g && /* @__PURE__ */ e("label", { className: "text-sm font-medium mb-1.5 block", children: g }),
139
- /* @__PURE__ */ r("div", { className: o(
140
- "border rounded-lg bg-background overflow-hidden transition-shadow focus-within:ring-2 focus-within:ring-primary/20",
141
- c && "opacity-80 bg-muted/30 pointer-events-none border-transparent"
367
+ }), B = O.useRef(null);
368
+ if (!L) return null;
369
+ const te = C ? () => {
370
+ var d;
371
+ return (d = B.current) == null ? void 0 : d.click();
372
+ } : void 0, G = /* @__PURE__ */ e(ne, { editor: L });
373
+ return /* @__PURE__ */ u("div", { "data-slot": "document-editor", className: k("flex flex-col w-full", n), children: [
374
+ p && /* @__PURE__ */ e("label", { className: "text-sm font-medium mb-1.5 block", children: p }),
375
+ /* @__PURE__ */ u("div", { className: k(
376
+ // flex-1/min-h-0: se o consumidor limita a altura (className="h-full"), a folha rola por dentro e a barra fica fixa.
377
+ "flex flex-col flex-1 min-h-0 border rounded-lg bg-background overflow-hidden transition-shadow focus-within:ring-2 focus-within:ring-primary/20",
378
+ m && "opacity-80 bg-muted/30 pointer-events-none border-transparent"
142
379
  ), children: [
143
- !c && /* @__PURE__ */ e(G, { editor: u, variant: n }),
144
- /* @__PURE__ */ e("div", { className: o(
380
+ !m && /* @__PURE__ */ e(Ve, { editor: L, variant: a, onPickImage: te, imageHint: w }),
381
+ C && /* @__PURE__ */ e(
382
+ "input",
383
+ {
384
+ ref: B,
385
+ type: "file",
386
+ className: "hidden",
387
+ accept: l.join(","),
388
+ "aria-label": "Escolher imagem",
389
+ onChange: (d) => {
390
+ const x = Array.from(d.target.files ?? []);
391
+ d.target.value = "", x.length > 0 && P.current(L, x);
392
+ }
393
+ }
394
+ ),
395
+ v ? (
396
+ // Folha A4: a cor é do papel (branca também no escuro) e o conteúdo escala com a largura da folha.
397
+ /* @__PURE__ */ e("div", { className: "bg-muted/40 p-3 sm:p-6 overflow-auto flex-1 min-h-0", "data-slot": "document-sheet-area", children: /* @__PURE__ */ e(
398
+ "div",
399
+ {
400
+ "data-slot": "document-sheet",
401
+ className: "mx-auto bg-white text-black shadow-md [container-type:inline-size]",
402
+ style: { width: `min(100%, ${A.larguraPx}px)` },
403
+ children: /* @__PURE__ */ e("div", { style: { padding: qe }, className: "[&_img]:max-w-full [&_img]:h-auto", children: G })
404
+ }
405
+ ) })
406
+ ) : /* @__PURE__ */ e("div", { className: k(
145
407
  "bg-background relative",
146
- n === "full" ? "bg-card" : ""
147
- ), children: /* @__PURE__ */ e(b, { editor: u }) })
408
+ s ? "bg-card" : ""
409
+ ), children: G })
148
410
  ] }),
149
- !c && n === "full" && /* @__PURE__ */ r("div", { className: "text-xs text-muted-foreground mt-1.5 text-right px-1", children: [
150
- ((d = (m = u.storage.characterCount) == null ? void 0 : m.words) == null ? void 0 : d.call(m)) || 0,
411
+ !m && s && /* @__PURE__ */ u("div", { className: "text-xs text-muted-foreground mt-1.5 text-right px-1", children: [
412
+ (($ = (_ = L.storage.characterCount) == null ? void 0 : _.words) == null ? void 0 : $.call(_)) || 0,
151
413
  " palavras"
152
414
  ] })
153
- ] }) : null;
415
+ ] });
154
416
  }
155
417
  export {
156
- le as DocumentEditor
418
+ dt as DocumentEditor,
419
+ Xe as tamanhoDeEntrada
157
420
  };
158
421
  //# sourceMappingURL=document-editor.js.map