@remarkablejames/editor 0.0.2 → 0.0.3

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 (180) hide show
  1. package/lib/{ActionMenuButton-Bmn3RME4.js → ActionMenuButton-D5HLfRzv.js} +9 -10
  2. package/lib/ActionMenuButton-DN6VHLkp.cjs +1 -0
  3. package/lib/Attachment.cjs +2 -2
  4. package/lib/Attachment.js +31 -33
  5. package/lib/Blockquote.cjs +2 -2
  6. package/lib/Blockquote.js +13 -12
  7. package/lib/Bold.cjs +1 -1
  8. package/lib/Bold.js +11 -10
  9. package/lib/BulletList.cjs +1 -1
  10. package/lib/BulletList.js +9 -8
  11. package/lib/Callout.cjs +1 -1
  12. package/lib/Callout.js +41 -45
  13. package/lib/Clear.cjs +1 -1
  14. package/lib/Clear.js +13 -14
  15. package/lib/Code.cjs +1 -1
  16. package/lib/Code.js +6 -5
  17. package/lib/CodeBlock.cjs +1 -1
  18. package/lib/CodeBlock.js +30 -31
  19. package/lib/CodeView.cjs +1 -1
  20. package/lib/CodeView.js +9 -8
  21. package/lib/Color.cjs +1 -1
  22. package/lib/Color.js +18 -19
  23. package/lib/Column.cjs +1 -1
  24. package/lib/Column.js +9 -8
  25. package/lib/{Drawer-DvGh9aXG.js → Drawer-B9l1SoRJ.js} +41 -47
  26. package/lib/Drawer-BN0lYcnJ.cjs +2 -0
  27. package/lib/Drawer.cjs +1 -1
  28. package/lib/Drawer.js +3 -3
  29. package/lib/Emoji.cjs +1 -1
  30. package/lib/Emoji.js +14 -15
  31. package/lib/Excalidraw.cjs +1 -1
  32. package/lib/Excalidraw.js +24 -28
  33. package/lib/ExportPdf.cjs +3 -3
  34. package/lib/ExportPdf.js +14 -13
  35. package/lib/ExportWord.cjs +1 -1
  36. package/lib/ExportWord.js +6 -6
  37. package/lib/FontFamily.cjs +1 -1
  38. package/lib/FontFamily.js +7 -6
  39. package/lib/FontSize.cjs +1 -1
  40. package/lib/FontSize.js +15 -14
  41. package/lib/Heading.cjs +1 -1
  42. package/lib/Heading.js +26 -26
  43. package/lib/Highlight.cjs +1 -1
  44. package/lib/Highlight.js +22 -23
  45. package/lib/History.cjs +1 -1
  46. package/lib/History.js +11 -11
  47. package/lib/HorizontalRule.cjs +1 -1
  48. package/lib/HorizontalRule.js +10 -9
  49. package/lib/Iframe-CXFk3GEq.cjs +1 -0
  50. package/lib/{Iframe-CnnvV6cK.js → Iframe-MjeJ2OOI.js} +11 -13
  51. package/lib/Iframe.cjs +1 -1
  52. package/lib/Iframe.js +2 -2
  53. package/lib/Image.cjs +1 -1
  54. package/lib/Image.js +4 -5
  55. package/lib/ImageGif.cjs +1 -1
  56. package/lib/ImageGif.js +79 -82
  57. package/lib/ImportWord.cjs +1 -1
  58. package/lib/ImportWord.js +25 -26
  59. package/lib/Indent-BPX9XRos.cjs +1 -0
  60. package/lib/{Indent-Bsj8gKvT.js → Indent-CgwDItIf.js} +31 -30
  61. package/lib/Indent.cjs +1 -1
  62. package/lib/Indent.js +2 -2
  63. package/lib/Italic.cjs +1 -1
  64. package/lib/Italic.js +12 -11
  65. package/lib/{Katex-CilGTz7u.js → Katex-CZ4g3vA9.js} +19 -22
  66. package/lib/Katex-DIgsR_dS.cjs +4 -0
  67. package/lib/Katex.cjs +1 -1
  68. package/lib/Katex.js +2 -2
  69. package/lib/LineHeight.cjs +1 -1
  70. package/lib/LineHeight.js +19 -20
  71. package/lib/Link.cjs +1 -1
  72. package/lib/Link.js +2 -2
  73. package/lib/LinkEditBlock-B2bU0Mcr.cjs +5 -0
  74. package/lib/{LinkEditBlock-BD_WvA3r.js → LinkEditBlock-CaDV3Vq5.js} +19 -24
  75. package/lib/Mention.js +3 -3
  76. package/lib/Mermaid-B9h7XKFo.cjs +2 -0
  77. package/lib/{Mermaid-BrjU75Bs.js → Mermaid-EhYj_ICn.js} +45 -48
  78. package/lib/Mermaid.cjs +1 -1
  79. package/lib/Mermaid.js +2 -2
  80. package/lib/MoreMark.cjs +1 -1
  81. package/lib/MoreMark.js +26 -28
  82. package/lib/OrderedList.cjs +1 -1
  83. package/lib/OrderedList.js +11 -10
  84. package/lib/SearchAndReplace.cjs +1 -1
  85. package/lib/SearchAndReplace.js +37 -42
  86. package/lib/SlashCommand.cjs +1 -1
  87. package/lib/SlashCommand.js +5 -5
  88. package/lib/SlashCommandNodeView-COlWSlnE.cjs +1 -0
  89. package/lib/{SlashCommandNodeView-COx5qZ2y.js → SlashCommandNodeView-CY3peX5x.js} +39 -41
  90. package/lib/Strike.cjs +1 -1
  91. package/lib/Strike.js +12 -11
  92. package/lib/{Table-BlM8yMhr.js → Table-Bw7rLue7.js} +46 -46
  93. package/lib/Table-DLrtX6T7.cjs +5 -0
  94. package/lib/Table.cjs +1 -1
  95. package/lib/Table.js +1 -1
  96. package/lib/TaskList.cjs +1 -1
  97. package/lib/TaskList.js +12 -11
  98. package/lib/TextAlign.cjs +1 -1
  99. package/lib/TextAlign.js +26 -27
  100. package/lib/TextDirection.cjs +1 -1
  101. package/lib/TextDirection.js +18 -19
  102. package/lib/TextUnderline.cjs +1 -1
  103. package/lib/TextUnderline.js +9 -8
  104. package/lib/Twitter-Ck6vGefg.cjs +1 -0
  105. package/lib/{Twitter-BP8sYXX7.js → Twitter-pM0y5Z-L.js} +18 -22
  106. package/lib/Twitter.cjs +1 -1
  107. package/lib/Twitter.js +2 -2
  108. package/lib/Video.cjs +1 -1
  109. package/lib/Video.js +4 -5
  110. package/lib/bubble.cjs +3 -3
  111. package/lib/bubble.js +77 -86
  112. package/lib/{clsx-m_C5j3RU.js → clsx-CDyrfCnw.js} +24 -24
  113. package/lib/{dropdown-menu-CkHN04Mx.cjs → dropdown-menu-DwR8tTs9.cjs} +1 -1
  114. package/lib/{dropdown-menu-C1hdPLCZ.js → dropdown-menu-nX-u8e2w.js} +1 -1
  115. package/lib/extensions/Image/Image.d.ts +11 -0
  116. package/lib/extensions/Image/components/ImageCropper.d.ts +1 -1
  117. package/lib/{index-B3Ijnbxs.js → index-C-tDsIKJ.js} +1 -1
  118. package/lib/{index-C1KQsOcg.js → index-C1WCZhyA.js} +1 -1
  119. package/lib/{index-C8FjP66D.js → index-CsSfYR30.js} +1 -1
  120. package/lib/index-Dib4cXXf.cjs +10 -0
  121. package/lib/{index-s3l5RdyW.js → index-DjDf4BK8.js} +1 -1
  122. package/lib/index-_WrFM-Fk.js +5054 -0
  123. package/lib/index.cjs +4 -4
  124. package/lib/index.js +147 -392
  125. package/lib/{popover-B05Fd8lC.cjs → popover-BY7j9SiD.cjs} +1 -1
  126. package/lib/{popover-CsSXh7w6.js → popover-CSvY4C-l.js} +1 -1
  127. package/lib/{renderNodeView-C_hPIdEs.js → renderNodeView-BJSrgyGj.js} +2 -2
  128. package/lib/{select-B3-5wTqn.js → select-BelNLNvT.js} +1 -1
  129. package/lib/{select-7ubC1NF0.cjs → select-Bu-5iIA9.cjs} +1 -1
  130. package/lib/{separator-CYCA8tSn.js → separator-Br5kcIJa.js} +12 -13
  131. package/lib/separator-Cp9Lg3HU.cjs +1 -0
  132. package/lib/style.css +1 -1
  133. package/lib/{textarea-1FhpmBkP.js → textarea-Ceev4t42.js} +1 -1
  134. package/lib/{textarea-Bjhcpp76.cjs → textarea-DfqvYaA6.cjs} +1 -1
  135. package/lib/theme/theme.d.ts +1 -1
  136. package/lib/{updatePosition-DvfTZHcH.js → updatePosition-e90ZrFWW.js} +2 -2
  137. package/package.json +1 -1
  138. package/lib/ActionMenuButton-C5P0Kzrb.cjs +0 -1
  139. package/lib/Drawer-gz9U5ArC.cjs +0 -2
  140. package/lib/Icon-CKM0tYbW.js +0 -15
  141. package/lib/Icon-CQyFgXeo.cjs +0 -1
  142. package/lib/Iframe-Ds6gG2YO.cjs +0 -1
  143. package/lib/ImageCropper-BKhXlnXN.cjs +0 -1
  144. package/lib/ImageCropper-DUzu_9-6.js +0 -896
  145. package/lib/Indent-D_7HOYYd.cjs +0 -1
  146. package/lib/Katex-lL3bHXJd.cjs +0 -4
  147. package/lib/LinkEditBlock-D3HSHmsU.cjs +0 -5
  148. package/lib/Mermaid-BfeLPzoS.cjs +0 -2
  149. package/lib/SlashCommandNodeView-DD-nlhM-.cjs +0 -1
  150. package/lib/Table-C21AlUrh.cjs +0 -5
  151. package/lib/Twitter-D46MnvPr.cjs +0 -1
  152. package/lib/Video-Bpd8W8l6.js +0 -231
  153. package/lib/Video-BwrHx6B1.cjs +0 -1
  154. package/lib/button-BmTP96NR.cjs +0 -1
  155. package/lib/button-CDIxPURh.js +0 -35
  156. package/lib/checkbox-7sfSdzy9.js +0 -29
  157. package/lib/checkbox-DyVlLWHv.cjs +0 -1
  158. package/lib/dialog-B-jOQ5i3.cjs +0 -1
  159. package/lib/dialog-QWWUWOGP.js +0 -95
  160. package/lib/events.constant-Bh2uzJud.js +0 -71
  161. package/lib/events.constant-ELn21EzG.cjs +0 -1
  162. package/lib/file-BLas99n7.js +0 -43
  163. package/lib/file-i7e4nQY2.cjs +0 -1
  164. package/lib/index-CAiZY1nx.js +0 -2741
  165. package/lib/index-DWSAk_9a.cjs +0 -1
  166. package/lib/input-qvpuOf-3.js +0 -21
  167. package/lib/input-s0JD5kf2.cjs +0 -1
  168. package/lib/isNumber-BTYSVlKo.cjs +0 -1
  169. package/lib/isNumber-WaBzl_0s.js +0 -15
  170. package/lib/label-CFax-gzo.cjs +0 -1
  171. package/lib/label-DC37f2RQ.js +0 -11
  172. package/lib/separator-ncbdw4oq.cjs +0 -1
  173. package/lib/tabs-BeHxylKH.js +0 -46
  174. package/lib/tabs-DBqNpGAq.cjs +0 -1
  175. package/lib/throttle-CRNq0z-O.js +0 -249
  176. package/lib/throttle-gTTvqDTW.cjs +0 -1
  177. package/lib/toggle-DoJTBdvy.js +0 -89
  178. package/lib/toggle-oFwBZC4x.cjs +0 -1
  179. package/lib/useButtonProps-BE10eHkG.js +0 -165
  180. package/lib/useButtonProps-CFu0GHzW.cjs +0 -1
@@ -1,896 +0,0 @@
1
- import { jsx as o, jsxs as b, Fragment as H } from "react/jsx-runtime";
2
- import * as K from "react";
3
- import X, { useState as E, useMemo as P, useCallback as F, useEffect as ee, useRef as de } from "react";
4
- import ye from "react-image-crop";
5
- import { B } from "./button-CDIxPURh.js";
6
- import { D as ue, a as me, b as he, c as fe, d as xe } from "./dialog-QWWUWOGP.js";
7
- import { h as we, m as Ae, k as ve } from "./clsx-m_C5j3RU.js";
8
- import { a as te, c as Se } from "./throttle-CRNq0z-O.js";
9
- import { I as ie, i as ae, j as Ee, u as ge } from "./index-4Q5IhypJ.js";
10
- import { i as ne, c as Me } from "./isNumber-WaBzl_0s.js";
11
- import { A as _e } from "./toggle-DoJTBdvy.js";
12
- import { f as Ce, u as Le, c as Ne, i as pe } from "./useButtonProps-BE10eHkG.js";
13
- import { d as Oe, r as Re } from "./file-BLas99n7.js";
14
- import { I as Y } from "./Icon-CKM0tYbW.js";
15
- import { T as ze, a as De, b as re, c as se } from "./tabs-BeHxylKH.js";
16
- import { C as ke } from "./checkbox-7sfSdzy9.js";
17
- import { L as le } from "./label-DC37f2RQ.js";
18
- import { I as oe } from "./input-qvpuOf-3.js";
19
- const Ue = 1, Fe = 1e6;
20
- let q = 0;
21
- function He() {
22
- return q = (q + 1) % Number.MAX_SAFE_INTEGER, q.toString();
23
- }
24
- const Z = /* @__PURE__ */ new Map();
25
- function ce(e) {
26
- if (Z.has(e))
27
- return;
28
- const t = setTimeout(() => {
29
- Z.delete(e), j({
30
- type: "REMOVE_TOAST",
31
- toastId: e
32
- });
33
- }, Fe);
34
- Z.set(e, t);
35
- }
36
- function Pe(e, t) {
37
- switch (t.type) {
38
- case "ADD_TOAST":
39
- return {
40
- ...e,
41
- toasts: [t.toast, ...e.toasts].slice(0, Ue)
42
- };
43
- case "UPDATE_TOAST":
44
- return {
45
- ...e,
46
- toasts: e.toasts.map((i) => i.id === t.toast.id ? { ...i, ...t.toast } : i)
47
- };
48
- case "DISMISS_TOAST": {
49
- const { toastId: i } = t;
50
- return i ? ce(i) : e.toasts.forEach((s) => {
51
- ce(s.id);
52
- }), {
53
- ...e,
54
- toasts: e.toasts.map(
55
- (s) => s.id === i || i === void 0 ? {
56
- ...s,
57
- open: !1
58
- } : s
59
- )
60
- };
61
- }
62
- case "REMOVE_TOAST":
63
- return t.toastId === void 0 ? {
64
- ...e,
65
- toasts: []
66
- } : {
67
- ...e,
68
- toasts: e.toasts.filter((i) => i.id !== t.toastId)
69
- };
70
- }
71
- }
72
- const W = [];
73
- let G = { toasts: [] };
74
- function j(e) {
75
- G = Pe(G, e), W.forEach((t) => {
76
- t(G);
77
- });
78
- }
79
- function Be({ ...e }) {
80
- const t = He(), i = (d) => j({
81
- type: "UPDATE_TOAST",
82
- toast: { ...d, id: t }
83
- }), s = () => j({ type: "DISMISS_TOAST", toastId: t });
84
- return j({
85
- type: "ADD_TOAST",
86
- toast: {
87
- ...e,
88
- id: t,
89
- open: !0,
90
- onOpenChange: (d) => {
91
- d || s();
92
- }
93
- }
94
- }), {
95
- id: t,
96
- dismiss: s,
97
- update: i
98
- };
99
- }
100
- function be() {
101
- const [e, t] = K.useState(G);
102
- return K.useEffect(() => (W.push(t), () => {
103
- const i = W.indexOf(t);
104
- i > -1 && W.splice(i, 1);
105
- }), [e]), {
106
- ...e,
107
- toast: Be,
108
- dismiss: (i) => j({ type: "DISMISS_TOAST", toastId: i })
109
- };
110
- }
111
- const $ = {
112
- TOP_LEFT: "tl",
113
- TOP_RIGHT: "tr",
114
- BOTTOM_LEFT: "bl",
115
- BOTTOM_RIGHT: "br"
116
- };
117
- function je(e) {
118
- var g, O, R;
119
- const [t, i] = E({
120
- width: ie,
121
- height: ie
122
- }), [s, d] = E({
123
- width: 0,
124
- height: 0
125
- }), [m] = E([
126
- $.TOP_LEFT,
127
- $.TOP_RIGHT,
128
- $.BOTTOM_LEFT,
129
- $.BOTTOM_RIGHT
130
- ]), [f, x] = E(!1), [h, I] = E({
131
- x: 0,
132
- y: 0,
133
- w: 0,
134
- h: 0,
135
- dir: ""
136
- }), { align: v, inline: w } = (g = e == null ? void 0 : e.node) == null ? void 0 : g.attrs, _ = w && (v === "left" || v === "right"), C = P(() => {
137
- var J;
138
- const { src: l, alt: p, width: a, height: r, flipX: u, flipY: c } = (J = e == null ? void 0 : e.node) == null ? void 0 : J.attrs, T = ne(a) ? `${a}px` : a, y = ne(r) ? `${r}px` : r, V = [];
139
- u && V.push("rotateX(180deg)"), c && V.push("rotateY(180deg)");
140
- const Te = V.join(" ");
141
- return {
142
- src: l || void 0,
143
- alt: p || void 0,
144
- style: {
145
- width: T || void 0,
146
- height: y || void 0,
147
- transform: Te || "none",
148
- ..._ ? { float: v } : {}
149
- }
150
- };
151
- }, [(O = e == null ? void 0 : e.node) == null ? void 0 : O.attrs]), L = P(() => {
152
- const {
153
- style: { width: l }
154
- } = C;
155
- return { width: l === "100%" ? l : void 0 };
156
- }, [C]);
157
- function z(l) {
158
- d({
159
- width: l.target.width,
160
- height: l.target.height
161
- });
162
- }
163
- function N() {
164
- const { editor: l, getPos: p } = e;
165
- l.commands.setNodeSelection(p());
166
- }
167
- const A = F(
168
- te(() => {
169
- const { editor: l } = e, { width: p } = getComputedStyle(l.view.dom);
170
- i((a) => ({
171
- ...a,
172
- width: Number.parseInt(p, 10)
173
- }));
174
- }, ae),
175
- [e == null ? void 0 : e.editor]
176
- );
177
- function M(l, p) {
178
- l.preventDefault(), l.stopPropagation();
179
- const a = s.width, r = s.height, u = a / r;
180
- let c = Number(e.node.attrs.width), T = Number(e.node.attrs.height);
181
- const y = t.width;
182
- c && !T ? (c = c > y ? y : c, T = Math.round(c / u)) : T && !c ? (c = Math.round(T * u), c = c > y ? y : c) : !c && !T ? (c = a > y ? y : a, T = Math.round(c / u)) : c = c > y ? y : c, x(!0), I({
183
- x: l.clientX,
184
- y: l.clientY,
185
- w: c,
186
- h: T,
187
- dir: p
188
- });
189
- }
190
- const S = F(
191
- te((l) => {
192
- if (l.preventDefault(), l.stopPropagation(), !f)
193
- return;
194
- const { x: p, w: a, dir: r } = h, u = (l.clientX - p) * (/l/.test(r) ? -1 : 1), c = Me(a + u, Ee, t.width);
195
- e.updateAttributes({
196
- width: c,
197
- height: null
198
- });
199
- }, ae),
200
- [f, h, t, e.updateAttributes]
201
- ), n = F(
202
- (l) => {
203
- l.preventDefault(), l.stopPropagation(), f && (I({
204
- x: 0,
205
- y: 0,
206
- w: 0,
207
- h: 0,
208
- dir: ""
209
- }), x(!1), N());
210
- },
211
- [f, N]
212
- ), U = F(() => {
213
- document == null || document.addEventListener("mousemove", S, !0), document == null || document.addEventListener("mouseup", n, !0);
214
- }, [S, n]), D = F(() => {
215
- document == null || document.removeEventListener("mousemove", S, !0), document == null || document.removeEventListener("mouseup", n, !0);
216
- }, [S, n]);
217
- ee(() => (f ? U() : D(), () => {
218
- D();
219
- }), [f, U, D]);
220
- const k = P(() => new ResizeObserver(() => A()), [A]);
221
- return ee(() => (k.observe(e.editor.view.dom), () => {
222
- k.disconnect();
223
- }), [e.editor.view.dom, k]), /* @__PURE__ */ o(
224
- we,
225
- {
226
- as: w ? "span" : "div",
227
- className: "image-view",
228
- style: {
229
- float: _ ? v : void 0,
230
- margin: _ ? v === "left" ? "1em 1em 1em 0" : "1em 0 1em 1em" : void 0,
231
- display: w ? "inline" : "block",
232
- textAlign: _ ? void 0 : v,
233
- width: ((R = C.style) == null ? void 0 : R.width) ?? "auto",
234
- ..._ ? {} : L
235
- },
236
- children: /* @__PURE__ */ b(
237
- "div",
238
- {
239
- "data-drag-handle": !0,
240
- draggable: "true",
241
- style: L,
242
- className: `image-view__body ${e != null && e.selected ? "image-view__body--focused" : ""} ${f ? "image-view__body--resizing" : ""}`,
243
- children: [
244
- /* @__PURE__ */ o(
245
- "img",
246
- {
247
- alt: C.alt,
248
- className: "image-view__body__image block",
249
- height: "auto",
250
- onClick: N,
251
- onLoad: z,
252
- src: C.src,
253
- style: C.style
254
- }
255
- ),
256
- (e == null ? void 0 : e.editor.view.editable) && ((e == null ? void 0 : e.selected) || f) && /* @__PURE__ */ o("div", { className: "image-resizer", children: m == null ? void 0 : m.map((l) => /* @__PURE__ */ o(
257
- "span",
258
- {
259
- className: `image-resizer__handler image-resizer__handler--${l}`,
260
- onMouseDown: (p) => M(p, l)
261
- },
262
- `image-dir-${l}`
263
- )) })
264
- ]
265
- }
266
- )
267
- }
268
- );
269
- }
270
- function Xe(e, t) {
271
- const i = e.type, s = e.name.toLowerCase(), d = s.split(".").pop();
272
- if (!d) return !1;
273
- const f = i || {
274
- heif: "image/heif",
275
- heic: "image/heic",
276
- dng: "image/x-adobe-dng",
277
- cr2: "image/x-canon-cr2",
278
- nef: "image/x-nikon-nef",
279
- arw: "image/x-sony-arw",
280
- raf: "image/x-fuji-raf",
281
- orf: "image/x-olympus-orf"
282
- }[d];
283
- return t.some((x) => {
284
- if (x.startsWith("."))
285
- return s.endsWith(x);
286
- if (x.endsWith("/*")) {
287
- const h = x.split("/")[0];
288
- return f == null ? void 0 : f.startsWith(h + "/");
289
- }
290
- return f === x;
291
- });
292
- }
293
- function Ie(e, t) {
294
- const { acceptMimes: i, maxSize: s, t: d, toast: m } = t, f = [];
295
- return (Array.isArray(e) ? e : Object.values(e)).forEach((h) => {
296
- if (!Xe(h, i)) {
297
- t.onError ? t.onError({
298
- type: "type",
299
- message: d("editor.upload.fileTypeNotSupported", {
300
- fileName: h.name
301
- }),
302
- file: h
303
- }) : m({
304
- variant: "destructive",
305
- title: d("editor.upload.fileTypeNotSupported", {
306
- fileName: h.name
307
- })
308
- });
309
- return;
310
- }
311
- if (h.size > s) {
312
- const I = (s / 1024 / 1024).toFixed(2);
313
- t.onError ? t.onError({
314
- type: "size",
315
- message: d("editor.upload.fileSizeTooBig", {
316
- fileName: h.name,
317
- size: I
318
- }),
319
- file: h
320
- }) : m({
321
- variant: "destructive",
322
- title: d("editor.upload.fileSizeTooBig", {
323
- fileName: h.name,
324
- size: I
325
- })
326
- });
327
- return;
328
- }
329
- f.push(h);
330
- }), f;
331
- }
332
- function dt() {
333
- const { t: e } = ge(), { toast: t } = be(), i = Ce(), s = Le(Q.name), { icon: d, tooltip: m } = (s == null ? void 0 : s.componentProps) ?? {}, { editorDisabled: f } = Ne(), [x, h] = E(!1), [I, v] = E(!1), w = pe(Q.name), [_, C] = E(""), [L, z] = E(""), N = de(null), A = (w == null ? void 0 : w.options.defaultInline) || !1, [M, S] = E(A), n = P(() => w == null ? void 0 : w.options, [w]);
334
- async function U(g) {
335
- var l;
336
- const O = (l = g == null ? void 0 : g.target) == null ? void 0 : l.files;
337
- if (!i || i.isDestroyed || O.length === 0 || I) {
338
- g.target.value = "";
339
- return;
340
- }
341
- const R = Ie(O, {
342
- acceptMimes: n == null ? void 0 : n.acceptMimes,
343
- maxSize: n == null ? void 0 : n.maxSize,
344
- t: e,
345
- toast: t,
346
- onError: n.onError
347
- });
348
- if (R.length <= 0) {
349
- g.target.value = "";
350
- return;
351
- }
352
- v(!0);
353
- try {
354
- if (n != null && n.multiple) {
355
- const p = R.map(async (r) => {
356
- if (n.upload) {
357
- const u = await n.upload(r);
358
- return { imageId: u.imageId, src: u.cdnUrl };
359
- } else
360
- return { imageId: void 0, src: URL.createObjectURL(r) };
361
- });
362
- (await Promise.all(p)).forEach(({ imageId: r, src: u }) => {
363
- i.chain().focus().setImageInline({ imageId: r, src: u, inline: M, alt: L }).run();
364
- });
365
- } else {
366
- const p = R[0];
367
- let a, r = "";
368
- if (n.upload) {
369
- const u = await n.upload(p);
370
- a = u.imageId, r = u.cdnUrl;
371
- } else
372
- r = URL.createObjectURL(p);
373
- i.chain().focus().setImageInline({ imageId: a, src: r, inline: M, alt: L }).run();
374
- }
375
- h(!1), z(""), S(A);
376
- } catch (p) {
377
- console.error("Error uploading image", p), n.onError ? n.onError({
378
- type: "upload",
379
- message: e("editor.upload.error")
380
- }) : t({
381
- variant: "destructive",
382
- title: e("editor.upload.error")
383
- });
384
- } finally {
385
- v(!1), g.target.value = "";
386
- }
387
- }
388
- function D(g) {
389
- g.preventDefault(), g.stopPropagation(), i.chain().focus().setImageInline({ src: _, inline: M, alt: L }).run(), h(!1), S(A), C(""), z("");
390
- }
391
- function k(g) {
392
- var O;
393
- g.preventDefault(), (O = N.current) == null || O.click();
394
- }
395
- return s ? /* @__PURE__ */ b(ue, { onOpenChange: h, open: x, children: [
396
- /* @__PURE__ */ o(me, { asChild: !0, children: /* @__PURE__ */ o(
397
- _e,
398
- {
399
- disabled: f,
400
- icon: d,
401
- tooltip: m,
402
- action: () => {
403
- f || h(!0);
404
- }
405
- }
406
- ) }),
407
- /* @__PURE__ */ b(he, { children: [
408
- /* @__PURE__ */ o(fe, { children: e("editor.image.dialog.title") }),
409
- /* @__PURE__ */ b(
410
- ze,
411
- {
412
- activationMode: "manual",
413
- defaultValue: n.resourceImage === "both" || n.resourceImage === "upload" ? "upload" : "link",
414
- children: [
415
- n.resourceImage === "both" && /* @__PURE__ */ b(De, { className: "richtext-grid richtext-w-full richtext-grid-cols-2", children: [
416
- /* @__PURE__ */ o(re, { value: "upload", children: e("editor.image.dialog.tab.upload") }),
417
- /* @__PURE__ */ o(re, { value: "link", children: e("editor.image.dialog.tab.url") })
418
- ] }),
419
- /* @__PURE__ */ b("div", { className: "richtext-my-[10px] richtext-flex richtext-items-center richtext-gap-[4px]", children: [
420
- /* @__PURE__ */ o(
421
- ke,
422
- {
423
- checked: M,
424
- onCheckedChange: (g) => {
425
- S(g);
426
- }
427
- }
428
- ),
429
- /* @__PURE__ */ o(le, { children: e("editor.link.dialog.inline") })
430
- ] }),
431
- n.enableAlt && /* @__PURE__ */ b("div", { className: "richtext-my-[10px]", children: [
432
- /* @__PURE__ */ o(le, { className: "mb-[6px]", children: e("editor.imageUpload.alt") }),
433
- /* @__PURE__ */ o(
434
- oe,
435
- {
436
- onChange: (g) => z(g.target.value),
437
- required: !0,
438
- type: "text",
439
- value: L
440
- }
441
- )
442
- ] }),
443
- /* @__PURE__ */ b(se, { value: "upload", children: [
444
- /* @__PURE__ */ b("div", { className: "richtext-flex richtext-items-center richtext-gap-[10px]", children: [
445
- /* @__PURE__ */ o(
446
- B,
447
- {
448
- className: "richtext-mt-1 richtext-w-full",
449
- disabled: I,
450
- onClick: k,
451
- size: "sm",
452
- children: I ? /* @__PURE__ */ b(H, { children: [
453
- e("editor.imageUpload.uploading"),
454
- /* @__PURE__ */ o(
455
- Y,
456
- {
457
- className: "richtext-ml-1 richtext-animate-spin",
458
- name: "Loader"
459
- }
460
- )
461
- ] }) : e("editor.image.dialog.tab.upload")
462
- }
463
- ),
464
- /* @__PURE__ */ o(
465
- Ye,
466
- {
467
- alt: L,
468
- disabled: I,
469
- editor: i,
470
- imageInline: M,
471
- onClose: () => {
472
- z("");
473
- }
474
- }
475
- )
476
- ] }),
477
- /* @__PURE__ */ o(
478
- "input",
479
- {
480
- accept: n.acceptMimes.join(",") || "image/*",
481
- multiple: n.multiple,
482
- onChange: U,
483
- ref: N,
484
- style: { display: "none" },
485
- type: "file"
486
- }
487
- )
488
- ] }),
489
- /* @__PURE__ */ o(se, { value: "link", children: /* @__PURE__ */ o("form", { onSubmit: D, children: /* @__PURE__ */ b("div", { className: "richtext-flex richtext-items-center richtext-gap-2", children: [
490
- /* @__PURE__ */ o(
491
- oe,
492
- {
493
- autoFocus: !0,
494
- onChange: (g) => C(g.target.value),
495
- placeholder: e("editor.image.dialog.placeholder"),
496
- required: !0,
497
- type: "url",
498
- value: _
499
- }
500
- ),
501
- /* @__PURE__ */ o(B, { type: "submit", children: e("editor.image.dialog.button.apply") })
502
- ] }) }) })
503
- ]
504
- }
505
- )
506
- ] })
507
- ] }) : /* @__PURE__ */ o(H, {});
508
- }
509
- const $e = {
510
- acceptMimes: ["image/jpeg", "image/gif", "image/png", "image/jpg"],
511
- maxSize: 1024 * 1024 * 5,
512
- // 5MB
513
- multiple: !0,
514
- resourceImage: "both",
515
- defaultInline: !1,
516
- enableAlt: !0
517
- }, Q = /* @__PURE__ */ Se.extend({
518
- group: "inline",
519
- inline: !0,
520
- defining: !0,
521
- draggable: !0,
522
- selectable: !0,
523
- addOptions() {
524
- var e;
525
- return {
526
- ...$e,
527
- ...(e = this.parent) == null ? void 0 : e.call(this),
528
- upload: () => Promise.reject("Image Upload Function"),
529
- button: ({
530
- editor: t,
531
- extension: i,
532
- t: s
533
- }) => {
534
- var d, m;
535
- return {
536
- componentProps: {
537
- action: () => !0,
538
- upload: i.options.upload,
539
- /* If setImage is not available(when Image Component is not imported), the button is disabled */
540
- disabled: !((m = (d = t.can()).setImage) != null && m.call(d, {})),
541
- icon: "ImageUp",
542
- tooltip: s("editor.image.tooltip")
543
- }
544
- };
545
- }
546
- };
547
- },
548
- addAttributes() {
549
- var e;
550
- return {
551
- ...(e = this.parent) == null ? void 0 : e.call(this),
552
- imageId: {
553
- default: null,
554
- parseHTML: (t) => t.getAttribute("data-image-id"),
555
- renderHTML: (t) => t.imageId ? { "data-image-id": t.imageId } : {}
556
- },
557
- flipX: {
558
- default: !1
559
- },
560
- flipY: {
561
- default: !1
562
- },
563
- width: {
564
- default: null,
565
- parseHTML: (t) => {
566
- const i = t.style.width || t.getAttribute("width") || null;
567
- return i ? Number.parseInt(i, 10) : null;
568
- },
569
- renderHTML: (t) => ({
570
- width: t.width
571
- })
572
- },
573
- align: {
574
- default: "center",
575
- parseHTML: (t) => t.getAttribute("align"),
576
- renderHTML: (t) => ({
577
- align: t.align
578
- })
579
- },
580
- inline: {
581
- default: !1,
582
- parseHTML: (t) => !!t.getAttribute("inline"),
583
- renderHTML: (t) => ({
584
- inline: t.inline
585
- })
586
- },
587
- alt: {
588
- default: "",
589
- parseHTML: (t) => t.getAttribute("alt"),
590
- renderHTML: (t) => ({
591
- alt: t.alt
592
- })
593
- }
594
- };
595
- },
596
- addNodeView() {
597
- return ve(je);
598
- },
599
- addCommands() {
600
- var e;
601
- return {
602
- ...(e = this.parent) == null ? void 0 : e.call(this),
603
- setImageInline: (t) => ({ commands: i }) => i.insertContent({
604
- type: this.name,
605
- attrs: {
606
- ...t,
607
- imageId: t.imageId ?? null,
608
- inline: t.inline ?? this.options.defaultInline
609
- }
610
- }),
611
- updateImage: (t) => ({ commands: i }) => i.updateAttributes(this.name, t),
612
- setAlignImage: (t) => ({ commands: i }) => i.updateAttributes(this.name, { align: t })
613
- };
614
- },
615
- renderHTML({ HTMLAttributes: e }) {
616
- const { flipX: t, flipY: i, align: s, inline: d } = e, m = d && (s === "left" || s === "right"), f = t || i ? `transform: rotateX(${t ? "180" : "0"}deg) rotateY(${i ? "180" : "0"}deg);` : "", x = m ? "" : `text-align: ${s};`, v = `${m ? `float: ${s};` : ""}${m ? s === "left" ? "margin: 1em 1em 1em 0;" : "margin: 1em 0 1em 1em;" : ""}${f}`;
617
- return [
618
- d ? "span" : "div",
619
- {
620
- style: x,
621
- class: "image"
622
- },
623
- [
624
- "img",
625
- Ae(
626
- {
627
- height: "auto",
628
- style: v
629
- },
630
- this.options.HTMLAttributes,
631
- e
632
- )
633
- ]
634
- ];
635
- },
636
- parseHTML() {
637
- return [
638
- {
639
- tag: "span.image img",
640
- getAttrs: (e) => {
641
- var m;
642
- const t = e == null ? void 0 : e.parentElement, i = e == null ? void 0 : e.getAttribute("width"), s = (e == null ? void 0 : e.getAttribute("flipx")) || !1, d = (e == null ? void 0 : e.getAttribute("flipy")) || !1;
643
- return {
644
- src: e == null ? void 0 : e.getAttribute("src"),
645
- alt: e == null ? void 0 : e.getAttribute("alt"),
646
- caption: e == null ? void 0 : e.getAttribute("caption"),
647
- width: i ? Number.parseInt(i, 10) : null,
648
- align: (e == null ? void 0 : e.getAttribute("align")) || ((m = t == null ? void 0 : t.style) == null ? void 0 : m.textAlign) || null,
649
- inline: (e == null ? void 0 : e.getAttribute("inline")) || !1,
650
- flipX: s === "true",
651
- flipY: d === "true"
652
- };
653
- }
654
- },
655
- {
656
- tag: "div[class=image]",
657
- getAttrs: (e) => {
658
- const t = e.querySelector("img"), i = t == null ? void 0 : t.getAttribute("width"), s = (t == null ? void 0 : t.getAttribute("flipx")) || !1, d = (t == null ? void 0 : t.getAttribute("flipy")) || !1;
659
- return {
660
- src: t == null ? void 0 : t.getAttribute("src"),
661
- alt: t == null ? void 0 : t.getAttribute("alt"),
662
- caption: t == null ? void 0 : t.getAttribute("caption"),
663
- width: i ? Number.parseInt(i, 10) : null,
664
- align: (t == null ? void 0 : t.getAttribute("align")) || e.style.textAlign || null,
665
- inline: (t == null ? void 0 : t.getAttribute("inline")) || !1,
666
- flipX: s === "true",
667
- flipY: d === "true"
668
- };
669
- }
670
- },
671
- {
672
- tag: 'img[src]:not([src^="data:"])'
673
- }
674
- ];
675
- }
676
- // addProseMirrorPlugins() {
677
- // const validateFile = (file: File): boolean => {
678
- // // @ts-expect-error
679
- // if (!this.options.acceptMimes.includes(file.type)) {
680
- // // toast({ description: t.value('editor.imageUpload.fileTypeNotSupported'), duration: 2000 });
681
- // return false;
682
- // }
683
- // // @ts-expect-error
684
- // if (file.size > this.options.maxSize) {
685
- // // toast({
686
- // // description: `${t.value('editor.imageUpload.fileSizeTooBig')} ${formatFileSize(
687
- // // this.options.maxSize,
688
- // // )}.`,
689
- // // duration: 2000,
690
- // // });
691
- // return false;
692
- // }
693
- // return true;
694
- // };
695
- // const uploadFn = createImageUpload({
696
- // validateFn: validateFile,
697
- // onUpload: this.options.upload as any,
698
- // // postUpload: this.options.postUpload,
699
- // defaultInline: this.options.defaultInline,
700
- // });
701
- // return [
702
- // UploadImagesPlugin(),
703
- // new Plugin({
704
- // key: new PluginKey(`richtextCustomPlugin${this.name}`),
705
- // props: {
706
- // handlePaste: (view, event) => {
707
- // const hasFiles =
708
- // event.clipboardData &&
709
- // event.clipboardData.files &&
710
- // event.clipboardData.files?.length;
711
- // if (!hasFiles) {
712
- // return;
713
- // }
714
- // const items = [...(event.clipboardData.files || [])];
715
- // if (items.some(x => x.type === 'text/html')) {
716
- // return false;
717
- // }
718
- // return handleImagePaste(view, event, uploadFn);
719
- // },
720
- // handleDrop: (view, event, _, moved) => {
721
- // if (!(event instanceof DragEvent) || !event.dataTransfer) {
722
- // return false;
723
- // }
724
- // handleImageDrop(view, event, moved, uploadFn);
725
- // return false;
726
- // },
727
- // },
728
- // }),
729
- // ];
730
- // },
731
- });
732
- function Ye({ editor: e, imageInline: t, onClose: i, disabled: s, alt: d }) {
733
- var l, p;
734
- const { t: m } = ge(), { toast: f } = be(), [x, h] = E(!1), [I, v] = E(!1), w = X.useRef(null), [_, C] = X.useState(), [L, z] = X.useState(""), N = de(null), [A, M] = E({
735
- src: "",
736
- file: null
737
- }), S = pe(Q.name), n = P(() => (S == null ? void 0 : S.options) ?? {}, [S]);
738
- function U(a) {
739
- if (w.current && a.width && a.height) {
740
- const r = D(w.current, a);
741
- z(r);
742
- }
743
- }
744
- function D(a, r) {
745
- const u = document.createElement("canvas"), c = a.naturalWidth / a.width, T = a.naturalHeight / a.height;
746
- u.width = r.width * c, u.height = r.height * T;
747
- const y = u.getContext("2d");
748
- return y && (y.imageSmoothingEnabled = !1, y.drawImage(
749
- a,
750
- r.x * c,
751
- r.y * T,
752
- r.width * c,
753
- r.height * T,
754
- 0,
755
- 0,
756
- r.width * c,
757
- r.height * T
758
- )), u.toDataURL("image/png", 1);
759
- }
760
- const k = X.useCallback(async () => {
761
- var a;
762
- if (!I) {
763
- v(!0);
764
- try {
765
- const r = Oe(L, ((a = A == null ? void 0 : A.file) == null ? void 0 : a.name) || "image.png");
766
- let u = "";
767
- n.upload ? u = await n.upload(r) : u = URL.createObjectURL(r), e.chain().focus().setImageInline({ src: u, inline: t, alt: d }).run(), h(!1), M({
768
- src: "",
769
- file: null
770
- }), R(), i();
771
- } catch (r) {
772
- console.error("Error cropping image", r);
773
- } finally {
774
- v(!1);
775
- }
776
- }
777
- }, [
778
- L,
779
- e,
780
- t,
781
- I,
782
- i,
783
- (l = A == null ? void 0 : A.file) == null ? void 0 : l.name,
784
- n
785
- ]);
786
- function g(a) {
787
- var r;
788
- a.preventDefault(), (r = N.current) == null || r.click();
789
- }
790
- const O = async (a) => {
791
- var y;
792
- const r = (y = a == null ? void 0 : a.target) == null ? void 0 : y.files;
793
- if (!e || e.isDestroyed || r.length === 0) {
794
- a.target.value = "";
795
- return;
796
- }
797
- const u = Ie(r, {
798
- acceptMimes: n == null ? void 0 : n.acceptMimes,
799
- maxSize: n == null ? void 0 : n.maxSize,
800
- t: m,
801
- toast: f,
802
- onError: n.onError
803
- });
804
- if (u.length <= 0) {
805
- a.target.value = "";
806
- return;
807
- }
808
- const c = u[0], T = await Re(c);
809
- h(!0), M({
810
- src: T.src,
811
- file: c
812
- });
813
- }, R = () => {
814
- N.current && (N.current.value = "");
815
- };
816
- return /* @__PURE__ */ b(H, { children: [
817
- /* @__PURE__ */ o(
818
- B,
819
- {
820
- className: "richtext-mt-1 richtext-w-full",
821
- disabled: s,
822
- onClick: g,
823
- size: "sm",
824
- children: m("editor.image.dialog.tab.uploadCrop")
825
- }
826
- ),
827
- /* @__PURE__ */ b(
828
- ue,
829
- {
830
- open: x,
831
- onOpenChange: (a) => {
832
- h(a), a || (M({ src: "", file: null }), R());
833
- },
834
- children: [
835
- /* @__PURE__ */ o(me, {}),
836
- /* @__PURE__ */ b(he, { children: [
837
- /* @__PURE__ */ o(fe, { children: m("editor.image.dialog.tab.uploadCrop") }),
838
- /* @__PURE__ */ o("div", { children: A.src && /* @__PURE__ */ o(
839
- ye,
840
- {
841
- className: "richtext-w-full",
842
- crop: _,
843
- onChange: (a) => C(a),
844
- onComplete: (a) => U(a),
845
- children: /* @__PURE__ */ o("img", { alt: "Crop me", ref: w, src: A.src })
846
- }
847
- ) }),
848
- /* @__PURE__ */ b(xe, { children: [
849
- /* @__PURE__ */ b(
850
- B,
851
- {
852
- disabled: I,
853
- onClick: () => {
854
- h(!1), M({
855
- src: "",
856
- file: null
857
- }), R();
858
- },
859
- children: [
860
- m("editor.imageUpload.cancel"),
861
- /* @__PURE__ */ o(Y, { className: "richtext-ml-1", name: "Trash2" })
862
- ]
863
- }
864
- ),
865
- /* @__PURE__ */ o(B, { className: "richtext-w-fit", disabled: I || !_, onClick: k, children: I ? /* @__PURE__ */ b(H, { children: [
866
- m("editor.imageUpload.uploading"),
867
- /* @__PURE__ */ o(Y, { className: "richtext-ml-1 richtext-animate-spin", name: "Loader" })
868
- ] }) : /* @__PURE__ */ b(H, { children: [
869
- m("editor.imageUpload.crop"),
870
- /* @__PURE__ */ o(Y, { className: "richtext-ml-1", name: "Crop" })
871
- ] }) })
872
- ] })
873
- ] })
874
- ]
875
- }
876
- ),
877
- /* @__PURE__ */ o(
878
- "input",
879
- {
880
- accept: ((p = n == null ? void 0 : n.acceptMimes) == null ? void 0 : p.join(",")) || "image/*",
881
- multiple: !1,
882
- onChange: O,
883
- ref: N,
884
- style: { display: "none" },
885
- type: "file"
886
- }
887
- )
888
- ] });
889
- }
890
- export {
891
- Q as I,
892
- dt as R,
893
- Ye as a,
894
- be as u,
895
- Ie as v
896
- };