@iclips/ui 4.0.0 → 4.1.1

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,416 @@
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 H } from "react/jsx-runtime";
2
+ import * as O from "react";
3
+ import { useEditor as te, EditorContent as ie } from "@tiptap/react";
4
+ import re from "@tiptap/starter-kit";
5
+ import Q from "@tiptap/extension-image";
6
+ import ne from "@tiptap/extension-placeholder";
7
+ import ae from "@tiptap/extension-text-align";
8
+ import oe from "@tiptap/extension-file-handler";
9
+ import { TableKit as le } from "@tiptap/extension-table";
10
+ import { cn as k } from "../utils.js";
11
+ import { Button as F } from "../primitives/button.js";
12
+ import { Separator as R } from "../primitives/separator.js";
13
+ import { Undo as se, Redo as ce, Bold as ue, Italic as me, Underline as he, Strikethrough as de, List as ge, ListOrdered as fe, AlignLeft as pe, AlignCenter as be, AlignRight as Ae, Quote as we, Link as xe, Table as ve, Image as $, Minus as Me, Plus as Ne } from "lucide-react";
14
+ import { Toggle as ke } from "../forms/toggle.js";
15
+ import { Select as Te, SelectTrigger as Le, SelectValue as Ie, SelectContent as Pe, SelectItem as Ce } from "../forms/select.js";
16
+ import { DropdownMenu as _e, DropdownMenuTrigger as Re, DropdownMenuContent as Se, DropdownMenuItem as N, DropdownMenuSeparator as X } from "../overlays/dropdown-menu.js";
17
+ import { Tooltip as y, TooltipTrigger as E, TooltipContent as z } from "../overlays/tooltip.js";
18
+ import { toast as D } from "../feedback/toast.js";
19
+ const U = 96 / 2.54, ye = Math.round(5 * U), Ee = Math.round(2 * U), V = Math.round(1 * U), ze = ["image/png", "image/jpeg", "image/webp"], He = 2 * 1024 * 1024, j = 0.1, A = {
20
+ larguraPx: 794,
21
+ alturaMinPx: 1123,
22
+ margemPx: 40 / 72 * 96
23
+ }, b = Math.round(A.larguraPx - 2 * A.margemPx), Oe = `${(11 / 0.75 / A.larguraPx * 100).toFixed(3)}cqw`, De = `${((A.alturaMinPx - 2 * A.margemPx) / A.larguraPx * 100).toFixed(3)}cqw`, Fe = `${(A.margemPx / A.larguraPx * 100).toFixed(3)}cqw`;
24
+ function W(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 Ue = ["left", "center", "right"], qe = Q.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 Ue.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) => W(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) => W(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 s = (l = a.dom.closest(".ProseMirror")) == null ? void 0 : l.clientWidth;
77
+ n.maxSize = {
78
+ ...n.maxSize,
79
+ width: s ? Math.min(b, s) : b
80
+ };
81
+ },
82
+ !0
83
+ ));
84
+ const m = (s, l) => {
85
+ const h = a.dom.querySelector("img");
86
+ if (!h || !s || !l) return;
87
+ const w = s > b ? b / s : 1;
88
+ h.style.width = `${Math.round(s * 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 = (s, ...l) => {
91
+ const h = p ? p(s, ...l) : !0;
92
+ return h && m(s.attrs.width, s.attrs.height), h;
93
+ }, a;
94
+ } : null;
95
+ }
96
+ });
97
+ async function Be(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;
30
105
  }
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);
106
+ }
107
+ function Ge(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
+ ke,
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(y, { children: [
133
+ /* @__PURE__ */ e(E, { asChild: !0, children: p }),
134
+ /* @__PURE__ */ e(z, { children: n })
135
+ ] });
136
+ }, S = ({
137
+ onClick: t,
138
+ disabled: i,
139
+ label: r,
140
+ tooltip: a,
141
+ children: n
142
+ }) => {
143
+ const m = /* @__PURE__ */ e(F, { variant: "ghost", size: "icon", className: "h-8 w-8", onClick: t, disabled: i, "aria-label": r, children: n });
144
+ return a ? /* @__PURE__ */ u(y, { children: [
145
+ /* @__PURE__ */ e(E, { asChild: !0, children: m }),
146
+ /* @__PURE__ */ e(z, { children: r })
147
+ ] }) : m;
148
+ }, $e = [
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 Xe(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 je(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 We = ({
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, c = window.prompt("URL", o);
35
172
  if (c !== null) {
36
173
  if (c === "") {
37
- i.chain().focus().extendMarkRange("link").unsetLink().run();
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: c }).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"), s = (o) => {
183
+ const { width: c, height: v } = t.getAttributes("image");
184
+ if (!c || !v) return;
185
+ const T = Math.min(b, Math.max(V, Math.round(c * o)));
186
+ t.chain().focus().updateAttributes("image", { width: T, height: Math.round(v * T / c) }).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(S, { tooltip: n, label: "Desfazer", onClick: () => t.chain().focus().undo().run(), disabled: !t.can().undo(), children: /* @__PURE__ */ e(se, { className: "h-4 w-4" }) }),
196
+ /* @__PURE__ */ e(S, { tooltip: n, label: "Refazer", onClick: () => t.chain().focus().redo().run(), disabled: !t.can().redo(), children: /* @__PURE__ */ e(ce, { className: "h-4 w-4" }) })
53
197
  ] }),
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" })
198
+ /* @__PURE__ */ e(R, { orientation: "vertical", className: "h-6 mx-1" }),
199
+ n && /* @__PURE__ */ u(H, { children: [
200
+ /* @__PURE__ */ u(Te, { value: Xe(t), onValueChange: (o) => je(t, o), children: [
201
+ /* @__PURE__ */ e(Le, { size: "sm", className: "w-[130px]", "aria-label": "Estilo do texto", children: /* @__PURE__ */ e(Ie, {}) }),
202
+ /* @__PURE__ */ e(Pe, { children: $e.map((o) => /* @__PURE__ */ e(Ce, { value: o.valor, children: o.rotulo }, o.valor)) })
203
+ ] }),
204
+ /* @__PURE__ */ e(R, { orientation: "vertical", className: "h-6 mx-1" })
60
205
  ] }),
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" }) })
206
+ /* @__PURE__ */ e(g, { tooltip: n, onClick: () => t.chain().focus().toggleBold().run(), isActive: t.isActive("bold"), title: "Negrito", children: /* @__PURE__ */ e(ue, { 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(me, { 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(he, { 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(de, { className: "h-4 w-4" }) }),
210
+ /* @__PURE__ */ e(R, { 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(ge, { 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(fe, { className: "h-4 w-4" }) }),
213
+ n && /* @__PURE__ */ u(H, { children: [
214
+ /* @__PURE__ */ e(g, { tooltip: !0, onClick: () => w("left"), isActive: h("left"), title: "Alinhar à esquerda", children: /* @__PURE__ */ e(pe, { className: "h-4 w-4" }) }),
215
+ /* @__PURE__ */ e(g, { tooltip: !0, onClick: () => w("center"), isActive: h("center"), title: "Centralizar", children: /* @__PURE__ */ e(be, { className: "h-4 w-4" }) }),
216
+ /* @__PURE__ */ e(g, { tooltip: !0, onClick: () => w("right"), isActive: h("right"), title: "Alinhar à direita", children: /* @__PURE__ */ e(Ae, { className: "h-4 w-4" }) })
72
217
  ] }),
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" }) })
218
+ /* @__PURE__ */ e(R, { 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(we, { className: "h-4 w-4" }) }),
220
+ /* @__PURE__ */ e(g, { tooltip: n, onClick: m, isActive: t.isActive("link"), title: "Link", children: /* @__PURE__ */ e(xe, { className: "h-4 w-4" }) }),
221
+ n && /* @__PURE__ */ u(_e, { children: [
222
+ /* @__PURE__ */ u(y, { children: [
223
+ /* @__PURE__ */ e(E, { asChild: !0, children: /* @__PURE__ */ e(Re, { asChild: !0, children: /* @__PURE__ */ e(F, { variant: "ghost", size: "icon", className: k("h-8 w-8", l && "bg-secondary text-secondary-foreground"), "aria-label": "Tabela", children: /* @__PURE__ */ e(ve, { className: "h-4 w-4" }) }) }) }),
224
+ /* @__PURE__ */ e(z, { children: "Tabela" })
225
+ ] }),
226
+ /* @__PURE__ */ u(Se, { 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(X, {}),
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(X, {}),
234
+ /* @__PURE__ */ e(N, { disabled: !l, onSelect: () => t.chain().focus().deleteTable().run(), children: "Remover tabela" })
235
+ ] })
236
+ ] }),
237
+ n && r && /* @__PURE__ */ u(H, { children: [
238
+ /* @__PURE__ */ u(y, { children: [
239
+ /* @__PURE__ */ e(E, { asChild: !0, children: /* @__PURE__ */ e(F, { variant: "ghost", size: "icon", className: "h-8 w-8", onClick: r, "aria-label": "Inserir imagem", children: /* @__PURE__ */ e($, { className: "h-4 w-4" }) }) }),
240
+ /* @__PURE__ */ e(z, { className: "max-w-64", children: a ?? "Inserir imagem" })
241
+ ] }),
242
+ /* @__PURE__ */ e(S, { tooltip: !0, label: "Diminuir imagem", onClick: () => s(1 - j), disabled: !f, children: /* @__PURE__ */ e(Me, { className: "h-4 w-4" }) }),
243
+ /* @__PURE__ */ e(S, { tooltip: !0, label: "Aumentar imagem", onClick: () => s(1 + j), disabled: !f, children: /* @__PURE__ */ e(Ne, { className: "h-4 w-4" }) })
244
+ ] }),
245
+ n && !r && /* @__PURE__ */ e(g, { tooltip: !0, onClick: p, title: "Imagem", children: /* @__PURE__ */ e($, { 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 mt({
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: s,
258
+ imageAcceptedTypes: l = ze,
259
+ imageMaxBytes: h = He,
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
+ const c = a === "full", v = c && o === "a4", T = s ?? { width: ye, maxHeight: Ee }, K = T.width, J = T.maxHeight, I = c && !!f, P = O.useRef(async () => {
264
+ });
265
+ P.current = async (d, x, L) => {
266
+ if (f)
267
+ for (const M of x) {
268
+ if (!l.includes(M.type)) {
269
+ D.error("Imagem não inserida", { description: "Use uma imagem PNG, JPG ou WEBP." });
270
+ continue;
271
+ }
272
+ if (M.size > h) {
273
+ D.error("Imagem não inserida", {
274
+ description: `A imagem deve ter no máximo ${Math.round(h / 1024 / 1024)} MB.`
275
+ });
276
+ continue;
277
+ }
278
+ try {
279
+ const [_, G] = await Promise.all([f(M), Be(M)]), ee = G ? Ge(G, { width: K, maxHeight: J }) : {};
280
+ d.chain().insertContentAt(L ?? d.state.selection.anchor, { type: "image", attrs: { src: _, ...ee } }).focus().run();
281
+ } catch (_) {
282
+ D.error("Não foi possível inserir a imagem", { description: _ instanceof Error ? _.message : void 0 });
283
+ }
107
284
  }
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());
285
+ };
286
+ const Y = O.useMemo(() => {
287
+ const d = c ? [
288
+ qe.configure({
289
+ allowBase64: !0,
290
+ HTMLAttributes: { class: "max-w-full h-auto" },
291
+ resize: {
292
+ enabled: !0,
293
+ directions: ["top-left", "top-right", "bottom-left", "bottom-right"],
294
+ minWidth: V,
295
+ minHeight: 1,
296
+ alwaysPreserveAspectRatio: !0
297
+ }
298
+ }),
299
+ le.configure({ table: { resizable: !0 } })
300
+ ] : [
301
+ Q.configure({
302
+ HTMLAttributes: {
303
+ class: "rounded-lg border shadow-sm max-w-full"
304
+ }
305
+ })
306
+ ];
307
+ return [
308
+ re.configure({
309
+ heading: {
310
+ levels: [1, 2, 3]
311
+ }
312
+ }),
313
+ // Removed explicit Underline and Link to avoid duplicate extension warning
314
+ // If these features are missing, check if StarterKit includes them in your version
315
+ // Underline,
316
+ // Link.configure({
317
+ // openOnClick: false,
318
+ // HTMLAttributes: {
319
+ // class: 'text-primary underline decoration-primary/30 hover:decoration-primary transition-colors cursor-pointer',
320
+ // },
321
+ // }),
322
+ ...d,
323
+ ne.configure({
324
+ placeholder: r
325
+ }),
326
+ ae.configure({
327
+ types: ["heading", "paragraph"]
328
+ }),
329
+ ...I ? [
330
+ oe.configure({
331
+ allowedMimeTypes: l,
332
+ onDrop: (x, L, M) => {
333
+ P.current(x, L, M);
334
+ },
335
+ onPaste: (x, L) => {
336
+ P.current(x, L);
337
+ }
338
+ })
339
+ ] : []
340
+ ];
341
+ }, [r, c, I, l.join(",")]), C = te({
342
+ extensions: Y,
343
+ content: t,
344
+ editable: !m,
345
+ shouldRerenderOnTransaction: !0,
346
+ onUpdate: ({ editor: d }) => {
347
+ i == null || i(d.getHTML());
121
348
  },
122
349
  editorProps: {
123
350
  attributes: {
124
- class: o(
125
- "prose prose-stone dark:prose-invert max-w-none focus:outline-none",
351
+ class: k(
352
+ v ? "prose prose-stone max-w-none focus:outline-none" : "prose prose-stone dark:prose-invert max-w-none focus:outline-none",
126
353
  "prose-headings:font-semibold prose-headings:tracking-tight",
127
354
  "prose-h1:text-3xl prose-h2:text-2xl prose-h3:text-xl",
128
355
  "prose-p:leading-7 prose-p:my-3",
129
356
  "prose-blockquote:border-l-4 prose-blockquote:border-primary/50 prose-blockquote:pl-4 prose-blockquote:italic",
130
357
  "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
- )
358
+ !c && "prose-img:rounded-lg prose-img:shadow-md prose-img:my-6",
359
+ // O contêiner do node view de redimensionamento é um flex: o alinhamento da imagem é dele.
360
+ c && "[&_[data-resize-container]:has([data-align=center])]:justify-center [&_[data-resize-container]:has([data-align=right])]:justify-end",
361
+ v ? void 0 : c ? "min-h-[400px] p-8" : "min-h-[120px] px-3 py-2"
362
+ ),
363
+ ...v ? { style: `font-size: ${Oe}; min-height: ${De}` } : {}
134
364
  }
135
365
  }
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"
366
+ }), q = O.useRef(null);
367
+ if (!C) return null;
368
+ const Z = I ? () => {
369
+ var d;
370
+ return (d = q.current) == null ? void 0 : d.click();
371
+ } : void 0, B = /* @__PURE__ */ e(ie, { editor: C });
372
+ return /* @__PURE__ */ u("div", { "data-slot": "document-editor", className: k("flex flex-col w-full", n), children: [
373
+ p && /* @__PURE__ */ e("label", { className: "text-sm font-medium mb-1.5 block", children: p }),
374
+ /* @__PURE__ */ u("div", { className: k(
375
+ // flex-1/min-h-0: se o consumidor limita a altura (className="h-full"), a folha rola por dentro e a barra fica fixa.
376
+ "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",
377
+ m && "opacity-80 bg-muted/30 pointer-events-none border-transparent"
142
378
  ), children: [
143
- !c && /* @__PURE__ */ e(G, { editor: u, variant: n }),
144
- /* @__PURE__ */ e("div", { className: o(
379
+ !m && /* @__PURE__ */ e(We, { editor: C, variant: a, onPickImage: Z, imageHint: w }),
380
+ I && /* @__PURE__ */ e(
381
+ "input",
382
+ {
383
+ ref: q,
384
+ type: "file",
385
+ className: "hidden",
386
+ accept: l.join(","),
387
+ "aria-label": "Escolher imagem",
388
+ onChange: (d) => {
389
+ const x = Array.from(d.target.files ?? []);
390
+ d.target.value = "", x.length > 0 && P.current(C, x);
391
+ }
392
+ }
393
+ ),
394
+ v ? (
395
+ // Folha A4: a cor é do papel (branca também no escuro) e o conteúdo escala com a largura da folha.
396
+ /* @__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(
397
+ "div",
398
+ {
399
+ "data-slot": "document-sheet",
400
+ className: "mx-auto bg-white text-black shadow-md [container-type:inline-size]",
401
+ style: { width: `min(100%, ${A.larguraPx}px)` },
402
+ children: /* @__PURE__ */ e("div", { style: { padding: Fe }, className: "[&_img]:max-w-full [&_img]:h-auto", children: B })
403
+ }
404
+ ) })
405
+ ) : /* @__PURE__ */ e("div", { className: k(
145
406
  "bg-background relative",
146
- n === "full" ? "bg-card" : ""
147
- ), children: /* @__PURE__ */ e(b, { editor: u }) })
148
- ] }),
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,
151
- " palavras"
407
+ c ? "bg-card" : ""
408
+ ), children: B })
152
409
  ] })
153
- ] }) : null;
410
+ ] });
154
411
  }
155
412
  export {
156
- le as DocumentEditor
413
+ mt as DocumentEditor,
414
+ Ge as tamanhoDeEntrada
157
415
  };
158
416
  //# sourceMappingURL=document-editor.js.map