reactjs-tiptap-editor 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{ActionMenuButton-DTXFBdGX.js → ActionMenuButton-BKqin6Kz.js} +17 -13
- package/lib/ActionMenuButton-CPPHERbq.cjs +1 -0
- package/lib/Attachment.cjs +2 -2
- package/lib/Attachment.js +24 -21
- package/lib/Blockquote.cjs +2 -2
- package/lib/Blockquote.js +7 -5
- package/lib/Bold.cjs +1 -1
- package/lib/Bold.js +11 -9
- package/lib/BulletList.cjs +1 -1
- package/lib/BulletList.js +14 -12
- package/lib/Clear.cjs +1 -1
- package/lib/Clear.js +3 -3
- package/lib/Code.cjs +1 -1
- package/lib/Code.js +11 -9
- package/lib/CodeBlock.cjs +39 -39
- package/lib/CodeBlock.js +842 -948
- package/lib/CodeView.cjs +1 -1
- package/lib/CodeView.js +10 -8
- package/lib/Color.cjs +1 -1
- package/lib/Color.js +20 -18
- package/lib/Column.cjs +1 -1
- package/lib/Column.js +7 -5
- package/lib/{Drawer-D0yQ0wR7.js → Drawer-DUPsBE0H.js} +18 -17
- package/lib/Drawer-fplzqNI6.cjs +1 -0
- package/lib/Drawer.cjs +1 -1
- package/lib/Drawer.js +3 -3
- package/lib/Emoji.cjs +1 -1
- package/lib/Emoji.js +19 -17
- package/lib/{Excalidraw-CO4IRHmG.js → Excalidraw-BEzpvRLx.js} +33 -32
- package/lib/Excalidraw-qjnQspLq.cjs +1 -0
- package/lib/Excalidraw.cjs +1 -1
- package/lib/Excalidraw.js +2 -2
- package/lib/ExportPdf.cjs +2 -2
- package/lib/ExportPdf.js +7 -5
- package/lib/ExportWord.cjs +1 -1
- package/lib/ExportWord.js +7 -5
- package/lib/FontFamily.cjs +1 -1
- package/lib/FontFamily.js +9 -8
- package/lib/FontSize.cjs +1 -1
- package/lib/FontSize.js +13 -12
- package/lib/Heading.cjs +1 -1
- package/lib/Heading.js +25 -24
- package/lib/Highlight.cjs +1 -1
- package/lib/Highlight.js +9 -7
- package/lib/History.cjs +1 -1
- package/lib/History.js +18 -15
- package/lib/HorizontalRule.cjs +1 -1
- package/lib/HorizontalRule.js +7 -5
- package/lib/Icon-CiR8RqdQ.cjs +1 -0
- package/lib/Icon-ONE1AwKo.js +12 -0
- package/lib/{Iframe-BEO28NPs.js → Iframe-CBTnv2mk.js} +45 -43
- package/lib/Iframe-DsUNJ2n2.cjs +1 -0
- package/lib/Iframe.cjs +1 -1
- package/lib/Iframe.js +2 -2
- package/lib/Image.cjs +1 -1
- package/lib/Image.js +52 -50
- package/lib/ImageGif.cjs +1 -1
- package/lib/ImageGif.js +55 -53
- package/lib/ImportWord.cjs +31 -31
- package/lib/ImportWord.js +12 -10
- package/lib/{Indent-CXurBbOr.js → Indent-B00o0P0M.js} +26 -24
- package/lib/Indent-CaGP0qTp.cjs +1 -0
- package/lib/Indent.cjs +1 -1
- package/lib/Indent.js +2 -2
- package/lib/Italic.cjs +1 -1
- package/lib/Italic.js +12 -10
- package/lib/Katex-XsfpKgJU.cjs +4 -0
- package/lib/{Katex-Bvj469K1.js → Katex-x370CSXZ.js} +27 -25
- package/lib/Katex.cjs +1 -1
- package/lib/Katex.js +2 -2
- package/lib/LineHeight.cjs +1 -1
- package/lib/LineHeight.js +17 -15
- package/lib/Link.cjs +1 -1
- package/lib/Link.js +2 -2
- package/lib/{LinkEditBlock-DjXUEubR.js → LinkEditBlock-C_ipl3EA.js} +27 -25
- package/lib/{LinkEditBlock-8ePAZ-G1.cjs → LinkEditBlock-xt88G5fb.cjs} +2 -2
- package/lib/Mention.cjs +1 -1
- package/lib/Mention.js +3 -3
- package/lib/Mermaid.cjs +2 -2
- package/lib/Mermaid.js +29 -28
- package/lib/MoreMark.cjs +1 -1
- package/lib/MoreMark.js +25 -22
- package/lib/OrderedList.cjs +1 -1
- package/lib/OrderedList.js +10 -8
- package/lib/SearchAndReplace.cjs +1 -1
- package/lib/SearchAndReplace.js +48 -46
- package/lib/SlashCommand.cjs +1 -1
- package/lib/SlashCommand.js +6 -6
- package/lib/SlashCommandNodeView-BT5ystah.cjs +1 -0
- package/lib/{SlashCommandNodeView-CcqL8ymb.js → SlashCommandNodeView-DX6axvLs.js} +74 -65
- package/lib/Strike.cjs +1 -1
- package/lib/Strike.js +7 -5
- package/lib/Table-DSRSwtXx.cjs +9 -0
- package/lib/{Table-9Y0Cg8Ab.js → Table-DidusYID.js} +10 -8
- package/lib/Table.cjs +1 -1
- package/lib/Table.js +1 -1
- package/lib/TaskList.cjs +1 -1
- package/lib/TaskList.js +15 -13
- package/lib/TextAlign.cjs +1 -1
- package/lib/TextAlign.js +20 -17
- package/lib/TextDirection.cjs +1 -1
- package/lib/TextDirection.js +20 -17
- package/lib/TextUnderline.cjs +1 -1
- package/lib/TextUnderline.js +7 -5
- package/lib/Twitter-CBuVBQM1.cjs +1 -0
- package/lib/{Twitter-DWwd0vHR.js → Twitter-D58T0Zt3.js} +59 -57
- package/lib/Twitter.cjs +1 -1
- package/lib/Twitter.js +2 -2
- package/lib/Video.cjs +1 -1
- package/lib/Video.js +27 -25
- package/lib/bubble.cjs +4 -4
- package/lib/bubble.js +70 -68
- package/lib/{button-RnHbJfd-.js → button-9_8t7ca7.js} +4 -3
- package/lib/button-Cs9TroWr.cjs +1 -0
- package/lib/{checkbox-CTEN0q4y.cjs → checkbox-BQRKTXXr.cjs} +1 -1
- package/lib/{checkbox-CLSoR1Qj.js → checkbox-DnkkV6qo.js} +1 -1
- package/lib/{index-BBNITgNi.cjs → clsx-CXbNJWDD.cjs} +13 -13
- package/lib/{index-sVScpCFG.js → clsx-DmuN0U_8.js} +228 -228
- package/lib/{dialog-CMC9hsCo.cjs → dialog-BS3zm-T9.cjs} +1 -1
- package/lib/{dialog-D_HCtKvc.js → dialog-DhayAPvV.js} +1 -1
- package/lib/{dropdown-menu-DKSAS-w_.cjs → dropdown-menu-CxwWX0yj.cjs} +1 -1
- package/lib/{dropdown-menu-66q7Ofc5.js → dropdown-menu-DQqKeZcx.js} +1 -1
- package/lib/events.constant-Dq21NPdV.cjs +1 -0
- package/lib/events.constant-do95b767.js +21 -0
- package/lib/{index-CApXPpjF.cjs → index-BCzvbrf5.cjs} +1 -1
- package/lib/{index-0OnGZkVF.js → index-BDX1uE62.js} +78 -312
- package/lib/index-CBFmXCcU.cjs +1 -0
- package/lib/{index-DmPwbBqm.js → index-CKmT9KAQ.js} +1 -1
- package/lib/index-CVFzP1Dc.cjs +1 -0
- package/lib/index-CX4pNJlH.cjs +1 -0
- package/lib/index-CjhjjJsN.cjs +1 -0
- package/lib/index-Cs6cp0Y6.cjs +1 -0
- package/lib/{index-9A6-kVBM.js → index-D1jd7elj.js} +1 -1
- package/lib/{index-C3zg3DPB.js → index-D9JOHlso.js} +493 -1186
- package/lib/{index-DRHrDScg.js → index-DdEmgiAA.js} +1 -1
- package/lib/{index-DKt5wfAc.js → index-DvvwJvau.js} +23 -23
- package/lib/index-EAK64CCA.js +425 -0
- package/lib/{index--nUS7Y66.cjs → index-neeeY2o7.cjs} +3 -3
- package/lib/index.cjs +9 -2
- package/lib/index.js +142 -26
- package/lib/{input-D555880-.cjs → input-BJ7ihMq-.cjs} +1 -1
- package/lib/{input-CvyMYMZG.js → input-YoheBL2D.js} +1 -1
- package/lib/{isNumber-Bv1Qhmw8.cjs → isNumber-BTYSVlKo.cjs} +1 -1
- package/lib/{isNumber-DF0fU3ob.js → isNumber-DmQXlKp3.js} +1 -1
- package/lib/label-C8PLcjFI.js +19 -0
- package/lib/label-Y7_hvqf2.cjs +1 -0
- package/lib/locale-bundle.cjs +1 -1
- package/lib/locale-bundle.js +6 -7
- package/lib/locales/index.d.ts +3 -4316
- package/lib/{popover-BSzR_R01.cjs → popover-BiSrlM4j.cjs} +1 -1
- package/lib/{popover-B7ec5-u2.js → popover-CWmTzHSy.js} +1 -1
- package/lib/react-BEoMZB61.cjs +1 -0
- package/lib/react-c9FSfB30.js +27 -0
- package/lib/separator-C-DKMYmg.js +329 -0
- package/lib/separator-CJ_adziN.cjs +1 -0
- package/lib/store/EditorEditableReactive.d.ts +1 -0
- package/lib/store/ThemeColorReactive.d.ts +1 -0
- package/lib/store/commandList.d.ts +1 -1
- package/lib/store/store.d.ts +6 -7
- package/lib/store-BKMaw1AW.cjs +1 -0
- package/lib/store-DG7cMfET.js +10 -0
- package/lib/{tabs-BTwiZkWd.cjs → tabs-DpHSMyF_.cjs} +1 -1
- package/lib/{tabs-CWr9HYaM.js → tabs-DxlKKM-N.js} +1 -1
- package/lib/{textarea-BdeLXbp8.js → textarea-D7m-apUh.js} +1 -1
- package/lib/{textarea-Yetl_PZi.cjs → textarea-DU9RMi6u.cjs} +1 -1
- package/lib/theme/theme.d.ts +5 -0
- package/lib/theme.cjs +1 -1
- package/lib/theme.js +37 -8
- package/lib/{throttle-DsowOft0.js → throttle-BRtichEP.js} +1 -1
- package/lib/throttle-gTTvqDTW.cjs +1 -0
- package/lib/toggle-BYvLnjCL.cjs +1 -0
- package/lib/toggle-Bxwwb_Kp.js +99 -0
- package/lib/tooltip-BTy5CRrN.js +24 -0
- package/lib/tooltip-COvf4_R-.cjs +1 -0
- package/lib/{updatePosition-Bbd8ETMv.js → updatePosition-CUukgu-Q.js} +2 -2
- package/lib/updatePosition-Cjuj2E26.cjs +1 -0
- package/lib/{useButtonProps-cMoicZgd.js → useButtonProps-CfYtuEnd.js} +48 -36
- package/lib/useButtonProps-CydzndG1.cjs +1 -0
- package/lib/utils/customEvents/events.constant.d.ts +0 -5
- package/package.json +3 -3
- package/lib/ActionMenuButton-BLlse5KO.cjs +0 -1
- package/lib/Drawer-kv6BU_6O.cjs +0 -1
- package/lib/Excalidraw-B82ThkJA.cjs +0 -1
- package/lib/Icon-DRuJhcHK.js +0 -10
- package/lib/Icon-DXePECFW.cjs +0 -1
- package/lib/Iframe-03dn9wcM.cjs +0 -1
- package/lib/Indent-Cqjdn3Jt.cjs +0 -1
- package/lib/Katex-DdWTV5NJ.cjs +0 -4
- package/lib/SlashCommandNodeView-Bl_gwZJB.cjs +0 -1
- package/lib/Table-DBGjezZK.cjs +0 -9
- package/lib/Twitter-Cnvt7GBg.cjs +0 -1
- package/lib/button-BW5bDPz_.cjs +0 -1
- package/lib/events.constant-DQYeJpu5.cjs +0 -1
- package/lib/events.constant-wrlJ_7JZ.js +0 -26
- package/lib/index-BZ6DfR2r.cjs +0 -1
- package/lib/index-C838s-or.cjs +0 -8
- package/lib/index-Cv9Z6dyV.cjs +0 -1
- package/lib/index-FSRjMsxW.cjs +0 -1
- package/lib/label-DsOYPjAo.js +0 -18
- package/lib/label-E6jF3Xud.cjs +0 -1
- package/lib/separator-JaTTqb3J.js +0 -241
- package/lib/separator-PGnA-6Hr.cjs +0 -1
- package/lib/store/ProviderUniqueId.d.ts +0 -6
- package/lib/store-Cf7tFiiI.js +0 -10
- package/lib/store-oDk-lTPM.cjs +0 -1
- package/lib/throttle-BM3Bmbf_.cjs +0 -1
- package/lib/updatePosition-M2IyqkI1.cjs +0 -1
- package/lib/useButtonProps-DfnJiJLV.cjs +0 -1
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as v, B as x, N as k, s as y, n as S, m as I } from "./clsx-DmuN0U_8.js";
|
|
2
2
|
import { jsxs as f, jsx as d, Fragment as P } from "react/jsx-runtime";
|
|
3
3
|
import { useState as M, useCallback as R } from "react";
|
|
4
4
|
import { Resizable as N } from "re-resizable";
|
|
5
|
+
import { B as j } from "./button-9_8t7ca7.js";
|
|
6
|
+
import { I as U } from "./input-YoheBL2D.js";
|
|
7
|
+
import { a as q } from "./index-D9JOHlso.js";
|
|
5
8
|
import { g as l } from "./dom-dataset-CIEeltF6.js";
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import { B as D } from "./button-RnHbJfd-.js";
|
|
9
|
+
import { A } from "./toggle-Bxwwb_Kp.js";
|
|
10
|
+
import "./theme.js";
|
|
11
|
+
import { u as L, a as D } from "./useButtonProps-CfYtuEnd.js";
|
|
10
12
|
const m = {
|
|
11
13
|
youtube: {
|
|
12
14
|
example: "https://www.youtube.com/watch?v=I4sMhHbHYXM",
|
|
@@ -109,15 +111,15 @@ function _(e) {
|
|
|
109
111
|
e.validLink = !0;
|
|
110
112
|
const r = i.split("="), n = r.length;
|
|
111
113
|
if (n > 0) {
|
|
112
|
-
const
|
|
113
|
-
e.src = `${t.srcPrefix}/${
|
|
114
|
+
const a = r[n - 1];
|
|
115
|
+
e.src = `${t.srcPrefix}/${a}`, e.validId = !0;
|
|
114
116
|
}
|
|
115
117
|
return e;
|
|
116
118
|
}
|
|
117
119
|
function $(e) {
|
|
118
|
-
const t = m.youku, i = e.matchedUrl, r = t.idRule, n = new RegExp(r),
|
|
119
|
-
if (
|
|
120
|
-
const o =
|
|
120
|
+
const t = m.youku, i = e.matchedUrl, r = t.idRule, n = new RegExp(r), a = i.match(n);
|
|
121
|
+
if (a && a.length > 0) {
|
|
122
|
+
const o = a[0].slice(3);
|
|
121
123
|
e.validId = !0, e.src = `${t.srcPrefix}/${o}`;
|
|
122
124
|
} else
|
|
123
125
|
e.validId = !1;
|
|
@@ -126,23 +128,23 @@ function $(e) {
|
|
|
126
128
|
function T(e) {
|
|
127
129
|
const t = m.bilibili, r = e.matchedUrl.split("/"), n = r.length;
|
|
128
130
|
if (n > 0) {
|
|
129
|
-
const
|
|
130
|
-
e.src = `${t.srcPrefix}=${
|
|
131
|
+
const a = r[n - 1];
|
|
132
|
+
e.src = `${t.srcPrefix}=${a}`, e.validId = !0;
|
|
131
133
|
}
|
|
132
134
|
return e;
|
|
133
135
|
}
|
|
134
|
-
function
|
|
136
|
+
function Y(e) {
|
|
135
137
|
const t = m.qqvideo, r = e.matchedUrl.split("/"), n = r.length;
|
|
136
138
|
if (n > 0) {
|
|
137
|
-
const
|
|
138
|
-
e.src = `${t.srcPrefix}=${
|
|
139
|
+
const a = r[n - 1];
|
|
140
|
+
e.src = `${t.srcPrefix}=${a}`, e.validId = !0;
|
|
139
141
|
}
|
|
140
142
|
return e;
|
|
141
143
|
}
|
|
142
|
-
function
|
|
144
|
+
function z(e, t) {
|
|
143
145
|
return t.src = e, t.validId = !0, t;
|
|
144
146
|
}
|
|
145
|
-
function
|
|
147
|
+
function C(e, t) {
|
|
146
148
|
return t.src = e, t.validId = !0, t;
|
|
147
149
|
}
|
|
148
150
|
function E(e, t) {
|
|
@@ -177,10 +179,10 @@ function F(e, t, i) {
|
|
|
177
179
|
if (e === "googlemaps")
|
|
178
180
|
return i.validLink = !0, i.matchedUrl = t, i;
|
|
179
181
|
const n = m[e].linkRule;
|
|
180
|
-
for (const
|
|
181
|
-
const o = new RegExp(
|
|
182
|
-
if (
|
|
183
|
-
return i.validLink = !0, i.matchedUrl = e === "youtube" ?
|
|
182
|
+
for (const a of n) {
|
|
183
|
+
const o = new RegExp(a), c = t.match(o);
|
|
184
|
+
if (c && c.length > 0)
|
|
185
|
+
return i.validLink = !0, i.matchedUrl = e === "youtube" ? c[1] : c[0], i;
|
|
184
186
|
}
|
|
185
187
|
return i;
|
|
186
188
|
}
|
|
@@ -208,11 +210,11 @@ function Z(e) {
|
|
|
208
210
|
case "bilibili":
|
|
209
211
|
return T(t);
|
|
210
212
|
case "qqvideo":
|
|
211
|
-
return
|
|
213
|
+
return Y(t);
|
|
212
214
|
case "amap":
|
|
213
|
-
return Y(e, t);
|
|
214
|
-
case "baidu_map":
|
|
215
215
|
return z(e, t);
|
|
216
|
+
case "baidu_map":
|
|
217
|
+
return C(e, t);
|
|
216
218
|
case "googlemaps":
|
|
217
219
|
return E(e, t);
|
|
218
220
|
case "modao":
|
|
@@ -240,13 +242,13 @@ const Q = "_wrap_5y04w_1", ee = "_innerWrap_5y04w_15", w = {
|
|
|
240
242
|
innerWrap: ee
|
|
241
243
|
};
|
|
242
244
|
function te({ editor: e, node: t, updateAttributes: i }) {
|
|
243
|
-
const r =
|
|
245
|
+
const r = q(), { src: n, width: a, height: o } = t.attrs, [c, p] = M("");
|
|
244
246
|
function u() {
|
|
245
|
-
if (!
|
|
247
|
+
if (!c)
|
|
246
248
|
return;
|
|
247
|
-
const s = Z(
|
|
249
|
+
const s = Z(c);
|
|
248
250
|
e.chain().updateAttributes(b.name, {
|
|
249
|
-
src: (s == null ? void 0 : s.src) ||
|
|
251
|
+
src: (s == null ? void 0 : s.src) || c
|
|
250
252
|
}).setNodeSelection(e.state.selection.from).focus().run();
|
|
251
253
|
}
|
|
252
254
|
const g = R(
|
|
@@ -258,18 +260,18 @@ function te({ editor: e, node: t, updateAttributes: i }) {
|
|
|
258
260
|
return /* @__PURE__ */ f(v, { children: [
|
|
259
261
|
!n && /* @__PURE__ */ f("div", { className: "richtext-mx-auto richtext-my-[12px] richtext-flex richtext-max-w-[600px] richtext-items-center richtext-justify-center richtext-gap-[10px] richtext-rounded-[12px] richtext-border richtext-border-solid richtext-border-border richtext-p-[10px]", children: [
|
|
260
262
|
/* @__PURE__ */ d(
|
|
261
|
-
|
|
263
|
+
U,
|
|
262
264
|
{
|
|
263
265
|
autoFocus: !0,
|
|
264
266
|
className: "richtext-flex-1",
|
|
265
267
|
onInput: (s) => p(s.target.value),
|
|
266
268
|
placeholder: "Enter link",
|
|
267
269
|
type: "url",
|
|
268
|
-
value:
|
|
270
|
+
value: c
|
|
269
271
|
}
|
|
270
272
|
),
|
|
271
273
|
/* @__PURE__ */ d(
|
|
272
|
-
|
|
274
|
+
j,
|
|
273
275
|
{
|
|
274
276
|
className: "richtext-w-[60px]",
|
|
275
277
|
onClick: u,
|
|
@@ -280,10 +282,10 @@ function te({ editor: e, node: t, updateAttributes: i }) {
|
|
|
280
282
|
n && /* @__PURE__ */ d(
|
|
281
283
|
N,
|
|
282
284
|
{
|
|
283
|
-
size: { width: Number.parseInt(
|
|
285
|
+
size: { width: Number.parseInt(a), height: Number.parseInt(o) },
|
|
284
286
|
onResizeStop: (s, ie, re, h) => {
|
|
285
287
|
g({
|
|
286
|
-
width: Number.parseInt(
|
|
288
|
+
width: Number.parseInt(a) + h.width,
|
|
287
289
|
height: Number.parseInt(o) + h.height
|
|
288
290
|
});
|
|
289
291
|
},
|
|
@@ -305,22 +307,22 @@ function te({ editor: e, node: t, updateAttributes: i }) {
|
|
|
305
307
|
)
|
|
306
308
|
] });
|
|
307
309
|
}
|
|
308
|
-
function
|
|
309
|
-
const e =
|
|
310
|
+
function fe() {
|
|
311
|
+
const e = L(b.name), {
|
|
310
312
|
icon: t = void 0,
|
|
311
313
|
tooltip: i = void 0,
|
|
312
314
|
shortcutKeys: r = void 0,
|
|
313
315
|
tooltipOptions: n = {},
|
|
314
|
-
action:
|
|
316
|
+
action: a = void 0,
|
|
315
317
|
isActive: o = void 0
|
|
316
|
-
} = (e == null ? void 0 : e.componentProps) ?? {}, { editorDisabled:
|
|
317
|
-
|
|
318
|
+
} = (e == null ? void 0 : e.componentProps) ?? {}, { editorDisabled: c, update: p } = D(o), u = () => {
|
|
319
|
+
c || a && (a(), p());
|
|
318
320
|
};
|
|
319
321
|
return e ? /* @__PURE__ */ d(
|
|
320
|
-
|
|
322
|
+
A,
|
|
321
323
|
{
|
|
322
324
|
action: u,
|
|
323
|
-
disabled:
|
|
325
|
+
disabled: c,
|
|
324
326
|
icon: t,
|
|
325
327
|
shortcutKeys: r,
|
|
326
328
|
tooltip: i,
|
|
@@ -397,8 +399,8 @@ const b = /* @__PURE__ */ k.create({
|
|
|
397
399
|
addCommands() {
|
|
398
400
|
return {
|
|
399
401
|
setIframe: (e) => ({ tr: t, commands: i, chain: r }) => {
|
|
400
|
-
var
|
|
401
|
-
if (((
|
|
402
|
+
var a, o, c;
|
|
403
|
+
if (((c = (o = (a = t.selection) == null ? void 0 : a.node) == null ? void 0 : o.type) == null ? void 0 : c.name) == this.name)
|
|
402
404
|
return i.updateAttributes(this.name, e);
|
|
403
405
|
const n = e || { url: "" };
|
|
404
406
|
return r().insertContent({
|
|
@@ -423,6 +425,6 @@ const b = /* @__PURE__ */ k.create({
|
|
|
423
425
|
});
|
|
424
426
|
export {
|
|
425
427
|
b as I,
|
|
426
|
-
|
|
428
|
+
fe as R,
|
|
427
429
|
Z as g
|
|
428
430
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const u=require("./clsx-CXbNJWDD.cjs"),s=require("react/jsx-runtime"),b=require("react"),y=require("re-resizable"),S=require("./button-Cs9TroWr.cjs"),I=require("./input-BJ7ihMq-.cjs"),P=require("./index-CX4pNJlH.cjs"),h=require("./dom-dataset-BqoJhJXt.cjs"),R=require("./toggle-BYvLnjCL.cjs");require("./theme.cjs");const g=require("./useButtonProps-CydzndG1.cjs"),m={youtube:{example:"https://www.youtube.com/watch?v=I4sMhHbHYXM",src:"https://www.youtube.com/embed/I4sMhHbHYXM",srcPrefix:"https://www.youtube.com/embed",linkRule:[/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\s/]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[&?]v=)|youtu\.be\/)([\w-]{11})/]},youku:{example:"https://v.youku.com/v_show/id_XNDM0NDM4MTcy.html?spm=a2h0c.8166622.PhoneSokuUgc_4.dtitle",src:"https://player.youku.com/embed/XNDM0NDM4MTcy",srcPrefix:"https://player.youku.com/embed",linkRule:[String.raw`v.youku.com\/v_show\/id_\w+\=*`],idRule:String.raw`id_\w+\=*`},bilibili:{example:"https://www.bilibili.com/video/BV1EJ411u7DN",src:"https://player.bilibili.com/player.html?bvid=BV1EJ411u7DN",srcPrefix:"https://player.bilibili.com/player.html?bvid",linkRule:[String.raw`www.bilibili.com\/video\/\w+`]},qqvideo:{example:"https://v.qq.com/x/cover/mzc0020006aw1mn/u0033nvzb5v.html",src:"https://v.qq.com/txp/iframe/player.html?vid=u0033nvzb5v",srcPrefix:"https://v.qq.com/txp/iframe/player.html?vid",linkRule:[String.raw`v.qq.com\/x\/cover\/\w+\/\w+`]},amap:{example:"https://ditu.amap.com/",src:"https://www.amap.com/place/B000A45467",srcPrefix:"",linkRule:[String.raw`\.amap\.com`]},baidu_map:{example:"https://j.map.baidu.com/15/fo",src:"https://j.map.baidu.com/15/fo",srcPrefix:"",linkRule:[String.raw`map\.baidu\.com`]},modao:{example:"https://free.modao.cc/app/2cd26580a6717a147454df7470e7ec464093cba3/embed/v2#screen=sk71k6d1dfxulzx",src:"https://free.modao.cc/app/6UkpAxcGE3nPz52GLqhnOZgC7MATBSy/embed/v2",srcPrefix:"",linkRule:[String.raw`https:\/\/\w+.modao.cc\/app\/\w+\/embed\/v2`],tips:"Modao > More > Share > Embed > COPY"},lanhu:{example:"https://lanhuapp.com/link/#/invite?sid=evP7L",src:"https://lanhuapp.com/url/evP7L",srcPrefix:"",linkRule:[String.raw`https:\/\/lanhuapp.com\/url\/\w+`],tips:"Lanhu > Project > Share > Copy Link"},figma:{example:"https://www.figma.com/file/aS9uSgPXoNpaPkzbjNcK8v/Demo?node-id=0%3A1",src:"https://www.figma.com/file/aS9uSgPXoNpaPkzbjNcK8v/Demo?node-id=0%3A1",srcPrefix:"https://www.figma.com/embed?embed_host=share&url",linkRule:[String.raw`https:\/\/www.figma.com\/file\/\w+`]},canva:{example:"https://www.canva.cn/design/DAD61-t29UI/view",src:"https://www.canva.cn/design/DAD61-t29UI/view",srcPrefix:"",linkRule:[String.raw`https:\/\/www.canva.cn\/design\/.+\/view`]},processon:{example:"https://www.processon.com/embed/5ea99d8607912948b0e6fe78",src:"https://www.processon.com/embed/5ea99d8607912948b0e6fe78",srcPrefix:"",linkRule:[String.raw`https:\/\/www.processon.com\/embed\/\w+`]},codepen:{example:"https://codepen.io/mekery/embed/YzyrKOJ",src:"https://codepen.io/mekery/embed/YzyrKOJ",srcPrefix:"",linkRule:[String.raw`https:\/\/codepen.io\/.+\/embed\/\w+`]},jinshuju:{example:"https://jinshuju.net/f/q9YvVf",src:"https://jinshuju.net/f/q9YvVf",srcPrefix:"",linkRule:[String.raw`https:\/\/jinshuju.net\/f\/\w+`]},iframe:{example:"https://v.youku.com/v_show/id_XNDM0NDM4MTcy.html",src:"https://player.youku.com/embed/XNDM0NDM4MTcy",srcPrefix:"",linkRule:[".+"]},googlemaps:{example:"https://goo.gl/maps/8Ys8b4K1ZJY2",src:"https://www.google.com/maps/embed?pb=https://goo.gl/maps/8Ys8b4K1ZJY2",srcPrefix:"",linkRule:[String.raw`https:\/\/goo.gl\/maps\/\w+`]}};function j(e){const t=m.youtube,i=e.matchedUrl;e.validLink=!0;const r=i.split("="),n=r.length;if(n>0){const c=r[n-1];e.src=`${t.srcPrefix}/${c}`,e.validId=!0}return e}function q(e){const t=m.youku,i=e.matchedUrl,r=t.idRule,n=new RegExp(r),c=i.match(n);if(c&&c.length>0){const o=c[0].slice(3);e.validId=!0,e.src=`${t.srcPrefix}/${o}`}else e.validId=!1;return e}function M(e){const t=m.bilibili,r=e.matchedUrl.split("/"),n=r.length;if(n>0){const c=r[n-1];e.src=`${t.srcPrefix}=${c}`,e.validId=!0}return e}function N(e){const t=m.qqvideo,r=e.matchedUrl.split("/"),n=r.length;if(n>0){const c=r[n-1];e.src=`${t.srcPrefix}=${c}`,e.validId=!0}return e}function U(e,t){return t.src=e,t.validId=!0,t}function A(e,t){return t.src=e,t.validId=!0,t}function D(e,t){return t.src=e,t.validId=!0,t.originalLink=e,t}function L(e){return e.src=e.matchedUrl,e.validId=!0,e.originalLink=e.src,e}function _(e){return e.src=e.matchedUrl,e.validId=!0,e.originalLink=e.src,e}function $(e){const t=m.figma;return e.src=`${t.srcPrefix}=${encodeURIComponent(e.matchedUrl)}`,e.validId=!0,e.originalLink=e.matchedUrl,e}function T(e,t){return t.src=`${t.matchedUrl}?embed`,t.validId=!0,t.originalLink=e,t}function z(e,t){return t.src=`${t.matchedUrl}`,t.validId=!0,t.originalLink=e,t}function Y(e){return e.src=`${e.matchedUrl}`,e.validId=!0,e.originalLink=e.src,e}function C(e,t){return t.src=`${t.matchedUrl}?background=white&banner=show&embedded=true`,t.validId=!0,t.originalLink=e,t}function E(e,t){return t.src=`${t.matchedUrl}`,t.validId=!0,t.originalLink=e,t}function H(e,t,i){if(e==="googlemaps")return i.validLink=!0,i.matchedUrl=t,i;const n=m[e].linkRule;for(const c of n){const o=new RegExp(c),a=t.match(o);if(a&&a.length>0)return i.validLink=!0,i.matchedUrl=e==="youtube"?a[1]:a[0],i}return i}function B(e){var i,r;let t="iframe";return((i=e.includes)!=null&&i.call(e,"youtube")||(r=e.includes)!=null&&r.call(e,"youtu.be"))&&(t="youtube"),e.includes("youku")&&(t="youku"),e.includes("bilibili")&&(t="bilibili"),e.includes("qq")&&(t="qqvideo"),e.includes("amap")&&(t="amap"),e.includes("map.baidu")&&(t="baidu_map"),(e.includes("google.com/maps")||e.includes("maps.app.goo.gl"))&&(t="googlemaps"),e.includes("modao")&&(t="modao"),e.includes("lanhuapp")&&(t="lanhu"),e.includes("figma")&&(t="figma"),e.includes("canva")&&(t="canva"),e.includes("processon")&&(t="processon"),e.includes("codepen")&&(t="codepen"),e.includes("jinshuju")&&(t="jinshuju"),e.includes("iframe")&&(t="iframe"),t}function x(e){let t={validLink:!1,validId:!1,matchedUrl:"",originalLink:e,src:""};const i=B(e);if(t=H(i,e,t),!t.validLink)return t;switch(i){case"youtube":return j(t);case"youku":return q(t);case"bilibili":return M(t);case"qqvideo":return N(t);case"amap":return U(e,t);case"baidu_map":return A(e,t);case"googlemaps":return D(e,t);case"modao":return L(t);case"lanhu":return _(t);case"figma":return $(t);case"canva":return T(e,t);case"processon":return z(e,t);case"codepen":return Y(t);case"jinshuju":return C(e,t);case"iframe":return E(e,t);default:return e}}const V="_wrap_5y04w_1",K="_innerWrap_5y04w_15",v={wrap:V,innerWrap:K};function O({editor:e,node:t,updateAttributes:i}){const r=P.useEditableEditor(),{src:n,width:c,height:o}=t.attrs,[a,p]=b.useState("");function l(){if(!a)return;const d=x(a);e.chain().updateAttributes(f.name,{src:(d==null?void 0:d.src)||a}).setNodeSelection(e.state.selection.from).focus().run()}const k=b.useCallback(d=>{i({width:d.width,height:d.height})},[i]);return s.jsxs(u.NodeViewWrapper,{children:[!n&&s.jsxs("div",{className:"richtext-mx-auto richtext-my-[12px] richtext-flex richtext-max-w-[600px] richtext-items-center richtext-justify-center richtext-gap-[10px] richtext-rounded-[12px] richtext-border richtext-border-solid richtext-border-border richtext-p-[10px]",children:[s.jsx(I.Input,{autoFocus:!0,className:"richtext-flex-1",onInput:d=>p(d.target.value),placeholder:"Enter link",type:"url",value:a}),s.jsx(S.Button,{className:"richtext-w-[60px]",onClick:l,children:"OK"})]}),n&&s.jsx(y.Resizable,{size:{width:Number.parseInt(c),height:Number.parseInt(o)},onResizeStop:(d,J,W,w)=>{k({width:Number.parseInt(c)+w.width,height:Number.parseInt(o)+w.height})},children:s.jsx("div",{className:u.clsx(v.wrap,"render-wrapper"),children:s.jsx("div",{className:v.innerWrap,style:{pointerEvents:r?"none":"auto"},children:s.jsx("iframe",{className:"richtext-my-[12px] ",src:n})})})})]})}function X(){const e=g.useButtonProps(f.name),{icon:t=void 0,tooltip:i=void 0,shortcutKeys:r=void 0,tooltipOptions:n={},action:c=void 0,isActive:o=void 0}=(e==null?void 0:e.componentProps)??{},{editorDisabled:a,update:p}=g.useToggleActive(o),l=()=>{a||c&&(c(),p())};return e?s.jsx(R.ActionButton,{action:l,disabled:a,icon:t,shortcutKeys:r,tooltip:i,tooltipOptions:n}):s.jsx(s.Fragment,{})}const f=u.Node3.create({name:"iframe",content:"",marks:"",group:"block",selectable:!0,atom:!0,draggable:!0,addOptions(){var e;return{...(e=this.parent)==null?void 0:e.call(this),HTMLAttributes:{class:"iframe"},button:({editor:t,extension:i,t:r})=>({componentProps:{action:n=>t.commands.setIframe(n),upload:i.options.upload,icon:"Iframe",tooltip:r("editor.iframe.tooltip")}})}},addAttributes(){return{width:{default:600,parseHTML:h.getDatasetAttribute("width")},height:{default:300,parseHTML:h.getDatasetAttribute("height")},src:{default:null,parseHTML:h.getDatasetAttribute("src")},defaultShowPicker:{default:!1},frameborder:{default:0},allowfullscreen:{default:this.options.allowFullscreen,parseHTML:()=>this.options.allowFullscreen}}},parseHTML(){return[{tag:"iframe"}]},renderHTML({HTMLAttributes:e}){return["iframe",u.mergeAttributes(this.options.HTMLAttributes,e)]},addCommands(){return{setIframe:e=>({tr:t,commands:i,chain:r})=>{var c,o,a;if(((a=(o=(c=t.selection)==null?void 0:c.node)==null?void 0:o.type)==null?void 0:a.name)==this.name)return i.updateAttributes(this.name,e);const n=e||{url:""};return r().insertContent({type:this.name,attrs:n}).run()}}},addInputRules(){return[u.nodeInputRule({find:/^\$iframe\$$/,type:this.type,getAttributes:()=>({width:"100%"})})]},addNodeView(){return u.ReactNodeViewRenderer(O)}});exports.Iframe=f;exports.RichTextIframe=X;exports.getServiceSrc=x;
|
package/lib/Iframe.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./clsx-CXbNJWDD.cjs");const e=require("./Iframe-DsUNJ2n2.cjs");require("./dom-dataset-BqoJhJXt.cjs");exports.Iframe=e.Iframe;exports.RichTextIframe=e.RichTextIframe;
|
package/lib/Iframe.js
CHANGED
package/lib/Image.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("./index-BBNITgNi.cjs"),W=require("./throttle-BM3Bmbf_.cjs"),n=require("react/jsx-runtime"),o=require("react"),F=require("./index-FSRjMsxW.cjs"),Y=require("./isNumber-Bv1Qhmw8.cjs"),ie=require("./index-C838s-or.cjs"),z=require("./dialog-CMC9hsCo.cjs"),ae=require("react-image-crop"),B=require("./button-BW5bDPz_.cjs"),Z=require("./file-i7e4nQY2.cjs"),U=require("./useButtonProps-DfnJiJLV.cjs"),ee=require("./use-toast-Bz3QCOtE.cjs"),P=require("./Icon-DXePECFW.cjs"),re=require("./store-oDk-lTPM.cjs"),J=require("./events.constant-DQYeJpu5.cjs"),q=require("./tabs-BTwiZkWd.cjs"),se=require("./checkbox-CTEN0q4y.cjs"),K=require("./label-E6jF3Xud.cjs"),Q=require("./input-D555880-.cjs"),H={TOP_LEFT:"tl",TOP_RIGHT:"tr",BOTTOM_LEFT:"bl",BOTTOM_RIGHT:"br"};function le(e){var O,d,E;const[t,a]=o.useState({width:F.IMAGE_MAX_SIZE,height:F.IMAGE_MAX_SIZE}),[c,f]=o.useState({width:0,height:0}),[h]=o.useState([H.TOP_LEFT,H.TOP_RIGHT,H.BOTTOM_LEFT,H.BOTTOM_RIGHT]),[x,T]=o.useState(!1),[g,b]=o.useState({x:0,y:0,w:0,h:0,dir:""}),{align:A,inline:j}=(O=e==null?void 0:e.node)==null?void 0:O.attrs,L=j&&(A==="left"||A==="right"),M=o.useMemo(()=>{var V;const{src:r,alt:I,width:i,height:s,flipX:m,flipY:l}=(V=e==null?void 0:e.node)==null?void 0:V.attrs,y=Y.isNumber(i)?`${i}px`:i,w=Y.isNumber(s)?`${s}px`:s,X=[];m&&X.push("rotateX(180deg)"),l&&X.push("rotateY(180deg)");const ne=X.join(" ");return{src:r||void 0,alt:I||void 0,style:{width:y||void 0,height:w||void 0,transform:ne||"none",...L?{float:A}:{}}}},[(d=e==null?void 0:e.node)==null?void 0:d.attrs]),R=o.useMemo(()=>{const{style:{width:r}}=M;return{width:r==="100%"?r:void 0}},[M]);function _(r){f({width:r.target.width,height:r.target.height})}function C(){const{editor:r,getPos:I}=e;r.commands.setNodeSelection(I())}const S=o.useCallback(W.throttle(()=>{const{editor:r}=e,{width:I}=getComputedStyle(r.view.dom);a(i=>({...i,width:Number.parseInt(I,10)}))},F.IMAGE_THROTTLE_WAIT_TIME),[e==null?void 0:e.editor]);function N(r,I){r.preventDefault(),r.stopPropagation();const i=c.width,s=c.height,m=i/s;let l=Number(e.node.attrs.width),y=Number(e.node.attrs.height);const w=t.width;l&&!y?(l=l>w?w:l,y=Math.round(l/m)):y&&!l?(l=Math.round(y*m),l=l>w?w:l):!l&&!y?(l=i>w?w:i,y=Math.round(l/m)):l=l>w?w:l,T(!0),b({x:r.clientX,y:r.clientY,w:l,h:y,dir:I})}const v=o.useCallback(W.throttle(r=>{if(r.preventDefault(),r.stopPropagation(),!x)return;const{x:I,w:i,dir:s}=g,m=(r.clientX-I)*(/l/.test(s)?-1:1),l=Y.clamp(i+m,F.IMAGE_MIN_SIZE,t.width);e.updateAttributes({width:l,height:null})},F.IMAGE_THROTTLE_WAIT_TIME),[x,g,t,e.updateAttributes]),p=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),x&&(b({x:0,y:0,w:0,h:0,dir:""}),T(!1),C())},[x,C]),u=o.useCallback(()=>{document==null||document.addEventListener("mousemove",v,!0),document==null||document.addEventListener("mouseup",p,!0)},[v,p]),k=o.useCallback(()=>{document==null||document.removeEventListener("mousemove",v,!0),document==null||document.removeEventListener("mouseup",p,!0)},[v,p]);o.useEffect(()=>(x?u():k(),()=>{k()}),[x,u,k]);const D=o.useMemo(()=>new ResizeObserver(()=>S()),[S]);return o.useEffect(()=>(D.observe(e.editor.view.dom),()=>{D.disconnect()}),[e.editor.view.dom,D]),n.jsx(G.NodeViewWrapper,{as:j?"span":"div",className:"image-view",style:{float:L?A:void 0,margin:L?A==="left"?"1em 1em 1em 0":"1em 0 1em 1em":void 0,display:j?"inline":"block",textAlign:L?void 0:A,width:((E=M.style)==null?void 0:E.width)??"auto",...L?{}:R},children:n.jsxs("div",{"data-drag-handle":!0,draggable:"true",style:R,className:`image-view__body ${e!=null&&e.selected?"image-view__body--focused":""} ${x?"image-view__body--resizing":""}`,children:[n.jsx("img",{alt:M.alt,className:"image-view__body__image block",height:"auto",onClick:C,onLoad:_,src:M.src,style:M.style}),(e==null?void 0:e.editor.view.editable)&&((e==null?void 0:e.selected)||x)&&n.jsx("div",{className:"image-resizer",children:h==null?void 0:h.map(r=>n.jsx("span",{className:`image-resizer__handler image-resizer__handler--${r}`,onMouseDown:I=>N(I,r)},`image-dir-${r}`))})]})})}function oe(e,t){const a=e.type,c=e.name.toLowerCase(),f=c.split(".").pop();if(!f)return!1;const x=a||{heif:"image/heif",heic:"image/heic",dng:"image/x-adobe-dng",cr2:"image/x-canon-cr2",nef:"image/x-nikon-nef",arw:"image/x-sony-arw",raf:"image/x-fuji-raf",orf:"image/x-olympus-orf"}[f];return t.some(T=>{if(T.startsWith("."))return c.endsWith(T);if(T.endsWith("/*")){const g=T.split("/")[0];return x==null?void 0:x.startsWith(g+"/")}return x===T})}function te(e,t){const{acceptMimes:a,maxSize:c,t:f,toast:h}=t,x=[];return(Array.isArray(e)?e:Object.values(e)).forEach(g=>{if(!oe(g,a)){t.onError?t.onError({type:"type",message:f("editor.upload.fileTypeNotSupported",{fileName:g.name}),file:g}):h({variant:"default",title:f("editor.upload.fileTypeNotSupported",{fileName:g.name})});return}if(g.size>c){const b=(c/1024/1024).toFixed(2);t.onError?t.onError({type:"size",message:f("editor.upload.fileSizeTooBig",{fileName:g.name,size:b}),file:g}):h({variant:"default",title:f("editor.upload.fileSizeTooBig",{fileName:g.name,size:b})});return}x.push(g)}),x}function ce({editor:e,imageInline:t,onClose:a,disabled:c,alt:f}){var r,I;const{t:h}=F.useLocale(),{toast:x}=ee.useToast(),[T,g]=o.useState(!1),[b,A]=o.useState(!1),j=o.useRef(null),[L,M]=o.useState(),[R,_]=o.useState(""),C=o.useRef(null),[S,N]=o.useState({src:"",file:null}),v=U.useExtension($.name),p=o.useMemo(()=>(v==null?void 0:v.options)??{},[v]);function u(i){if(j.current&&i.width&&i.height){const s=k(j.current,i);_(s)}}function k(i,s){const m=document.createElement("canvas"),l=i.naturalWidth/i.width,y=i.naturalHeight/i.height;m.width=s.width*l,m.height=s.height*y;const w=m.getContext("2d");return w&&(w.imageSmoothingEnabled=!1,w.drawImage(i,s.x*l,s.y*y,s.width*l,s.height*y,0,0,s.width*l,s.height*y)),m.toDataURL("image/png",1)}const D=o.useCallback(async()=>{var i;if(!b){A(!0);try{const s=Z.dataURLtoFile(R,((i=S==null?void 0:S.file)==null?void 0:i.name)||"image.png");let m="";p.upload?m=await p.upload(s):m=URL.createObjectURL(s),e.chain().focus().setImageInline({src:m,inline:t,alt:f}).run(),g(!1),N({src:"",file:null}),E(),a()}catch(s){console.log("Error cropping image",s)}finally{A(!1)}}},[R,e,t,b,a,(r=S==null?void 0:S.file)==null?void 0:r.name,p]);function O(i){var s;i.preventDefault(),(s=C.current)==null||s.click()}const d=async i=>{var w;const s=(w=i==null?void 0:i.target)==null?void 0:w.files;if(!e||e.isDestroyed||s.length===0){i.target.value="";return}const m=te(s,{acceptMimes:p==null?void 0:p.acceptMimes,maxSize:p==null?void 0:p.maxSize,t:h,toast:x,onError:p.onError});if(m.length<=0){i.target.value="";return}const l=m[0],y=await Z.readImageAsBase64(l);g(!0),N({src:y.src,file:l})},E=()=>{C.current&&(C.current.value="")};return n.jsxs(n.Fragment,{children:[n.jsx(B.Button,{className:"richtext-mt-1 richtext-w-full",disabled:c,onClick:O,size:"sm",children:h("editor.image.dialog.tab.uploadCrop")}),n.jsxs(z.Dialog,{open:T,onOpenChange:i=>{g(i),i||(N({src:"",file:null}),E())},children:[n.jsx(z.DialogTrigger,{}),n.jsxs(z.DialogContent,{children:[n.jsx(z.DialogTitle,{children:h("editor.image.dialog.tab.uploadCrop")}),n.jsx("div",{children:S.src&&n.jsx(ae,{className:"richtext-w-full",crop:L,onChange:i=>M(i),onComplete:i=>u(i),children:n.jsx("img",{alt:"Crop me",ref:j,src:S.src})})}),n.jsxs(z.DialogFooter,{children:[n.jsxs(B.Button,{disabled:b,onClick:()=>{g(!1),N({src:"",file:null}),E()},children:[h("editor.imageUpload.cancel"),n.jsx(P.IconComponent,{className:"richtext-ml-1",name:"Trash2"})]}),n.jsx(B.Button,{className:"richtext-w-fit",disabled:b||!L,onClick:D,children:b?n.jsxs(n.Fragment,{children:[h("editor.imageUpload.uploading"),n.jsx(P.IconComponent,{className:"richtext-ml-1 richtext-animate-spin",name:"Loader"})]}):n.jsxs(n.Fragment,{children:[h("editor.imageUpload.crop"),n.jsx(P.IconComponent,{className:"richtext-ml-1",name:"Crop"})]})})]})]})]}),n.jsx("input",{accept:((I=p==null?void 0:p.acceptMimes)==null?void 0:I.join(","))||"image/*",multiple:!1,onChange:d,ref:C,style:{display:"none"},type:"file"})]})}function ue(){const{t:e}=F.useLocale(),{toast:t}=ee.useToast(),a=U.useEditorInstance(),c=U.useButtonProps($.name),{icon:f,tooltip:h}=(c==null?void 0:c.componentProps)??{},{editorDisabled:x}=U.useToggleActive(),[T,g]=o.useState(!1),[b,A]=o.useState(!1),j=U.useExtension($.name),L=d=>{g(d.detail)},[M,R]=o.useState(""),[_,C]=o.useState(""),S=o.useRef(null),N=(j==null?void 0:j.options.defaultInline)||!1,[v,p]=o.useState(N),u=o.useMemo(()=>j==null?void 0:j.options,[j]);o.useEffect(()=>{const d=J.listenEvent(J.EVENTS.UPLOAD_IMAGE(a.id),L);return()=>{d()}},[]);async function k(d){var I;const E=(I=d==null?void 0:d.target)==null?void 0:I.files;if(!a||a.isDestroyed||E.length===0||b){d.target.value="";return}const r=te(E,{acceptMimes:u==null?void 0:u.acceptMimes,maxSize:u==null?void 0:u.maxSize,t:e,toast:t,onError:u.onError});if(r.length<=0){d.target.value="";return}A(!0);try{if(u!=null&&u.multiple){const i=r.map(async m=>{let l="";return u.upload?l=await u.upload(m):l=URL.createObjectURL(m),l});(await Promise.all(i)).forEach(m=>{a.chain().focus().setImageInline({src:m,inline:v,alt:_}).run()})}else{const i=r[0];let s="";u.upload?s=await u.upload(i):s=URL.createObjectURL(i),a.chain().focus().setImageInline({src:s,inline:v,alt:_}).run()}g(!1),C(""),p(N)}catch(i){console.error("Error uploading image",i),u.onError?u.onError({type:"upload",message:e("editor.upload.error")}):t({variant:"destructive",title:e("editor.upload.error")})}finally{A(!1),d.target.value=""}}function D(d){d.preventDefault(),d.stopPropagation(),a.chain().focus().setImageInline({src:M,inline:v,alt:_}).run(),g(!1),p(N),R(""),C("")}function O(d){var E;d.preventDefault(),(E=S.current)==null||E.click()}return c?n.jsxs(z.Dialog,{onOpenChange:g,open:T,children:[n.jsx(z.DialogTrigger,{asChild:!0,children:n.jsx(ie.ActionButton,{disabled:x,icon:f,tooltip:h,action:()=>{x||g(!0)}})}),n.jsxs(z.DialogContent,{children:[n.jsx(z.DialogTitle,{children:e("editor.image.dialog.title")}),n.jsxs(q.Tabs,{activationMode:"manual",defaultValue:u.resourceImage==="both"||u.resourceImage==="upload"?"upload":"link",children:[u.resourceImage==="both"&&n.jsxs(q.TabsList,{className:"richtext-grid richtext-w-full richtext-grid-cols-2",children:[n.jsx(q.TabsTrigger,{value:"upload",children:e("editor.image.dialog.tab.upload")}),n.jsx(q.TabsTrigger,{value:"link",children:e("editor.image.dialog.tab.url")})]}),n.jsxs("div",{className:"richtext-my-[10px] richtext-flex richtext-items-center richtext-gap-[4px]",children:[n.jsx(se.Checkbox,{checked:v,onCheckedChange:d=>{p(d)}}),n.jsx(K.Label,{children:e("editor.link.dialog.inline")})]}),u.enableAlt&&n.jsxs("div",{className:"richtext-my-[10px] ",children:[n.jsx(K.Label,{className:"mb-[6px]",children:e("editor.imageUpload.alt")}),n.jsx(Q.Input,{onChange:d=>C(d.target.value),required:!0,type:"text",value:_})]}),n.jsxs(q.TabsContent,{value:"upload",children:[n.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-[10px]",children:[n.jsx(B.Button,{className:"richtext-mt-1 richtext-w-full",disabled:b,onClick:O,size:"sm",children:b?n.jsxs(n.Fragment,{children:[e("editor.imageUpload.uploading"),n.jsx(P.IconComponent,{className:"richtext-ml-1 richtext-animate-spin",name:"Loader"})]}):e("editor.image.dialog.tab.upload")}),n.jsx(ce,{alt:_,disabled:b,editor:a,imageInline:v,onClose:()=>{re.actionDialogImage.setOpen(a.id,!1),C("")}})]}),n.jsx("input",{accept:u.acceptMimes.join(",")||"image/*",multiple:u.multiple,onChange:k,ref:S,style:{display:"none"},type:"file"})]}),n.jsx(q.TabsContent,{value:"link",children:n.jsx("form",{onSubmit:D,children:n.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2",children:[n.jsx(Q.Input,{autoFocus:!0,onChange:d=>R(d.target.value),placeholder:e("editor.image.dialog.placeholder"),required:!0,type:"url",value:M}),n.jsx(B.Button,{type:"submit",children:e("editor.image.dialog.button.apply")})]})})})]})]})]}):n.jsx(n.Fragment,{})}const de={acceptMimes:["image/jpeg","image/gif","image/png","image/jpg"],maxSize:1024*1024*5,multiple:!0,resourceImage:"both",defaultInline:!1,enableAlt:!0},$=W.index_default.extend({group:"inline",inline:!0,defining:!0,draggable:!0,selectable:!0,addOptions(){var e;return{...de,...(e=this.parent)==null?void 0:e.call(this),upload:()=>Promise.reject("Image Upload Function"),button:({editor:t,extension:a,t:c})=>{var f,h;return{componentProps:{action:()=>!0,upload:a.options.upload,disabled:!((h=(f=t.can()).setImage)!=null&&h.call(f,{})),icon:"ImageUp",tooltip:c("editor.image.tooltip")}}}}},addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),flipX:{default:!1},flipY:{default:!1},width:{default:null,parseHTML:t=>{const a=t.style.width||t.getAttribute("width")||null;return a?Number.parseInt(a,10):null},renderHTML:t=>({width:t.width})},align:{default:"center",parseHTML:t=>t.getAttribute("align"),renderHTML:t=>({align:t.align})},inline:{default:!1,parseHTML:t=>!!t.getAttribute("inline"),renderHTML:t=>({inline:t.inline})},alt:{default:"",parseHTML:t=>t.getAttribute("alt"),renderHTML:t=>({alt:t.alt})}}},addNodeView(){return G.ReactNodeViewRenderer(le)},addCommands(){var e;return{...(e=this.parent)==null?void 0:e.call(this),setImageInline:t=>({commands:a})=>a.insertContent({type:this.name,attrs:{...t,inline:t.inline??this.options.defaultInline}}),updateImage:t=>({commands:a})=>a.updateAttributes(this.name,t),setAlignImage:t=>({commands:a})=>a.updateAttributes(this.name,{align:t})}},renderHTML({HTMLAttributes:e}){const{flipX:t,flipY:a,align:c,inline:f}=e,h=f&&(c==="left"||c==="right"),x=t||a?`transform: rotateX(${t?"180":"0"}deg) rotateY(${a?"180":"0"}deg);`:"",T=h?"":`text-align: ${c};`,A=`${h?`float: ${c};`:""}${h?c==="left"?"margin: 1em 1em 1em 0;":"margin: 1em 0 1em 1em;":""}${x}`;return[f?"span":"div",{style:T,class:"image"},["img",G.mergeAttributes({height:"auto",style:A},this.options.HTMLAttributes,e)]]},parseHTML(){return[{tag:"span.image img",getAttrs:e=>{var h;const t=e==null?void 0:e.parentElement,a=e==null?void 0:e.getAttribute("width"),c=(e==null?void 0:e.getAttribute("flipx"))||!1,f=(e==null?void 0:e.getAttribute("flipy"))||!1;return{src:e==null?void 0:e.getAttribute("src"),alt:e==null?void 0:e.getAttribute("alt"),caption:e==null?void 0:e.getAttribute("caption"),width:a?Number.parseInt(a,10):null,align:(e==null?void 0:e.getAttribute("align"))||((h=t==null?void 0:t.style)==null?void 0:h.textAlign)||null,inline:(e==null?void 0:e.getAttribute("inline"))||!1,flipX:c==="true",flipY:f==="true"}}},{tag:"div[class=image]",getAttrs:e=>{const t=e.querySelector("img"),a=t==null?void 0:t.getAttribute("width"),c=(t==null?void 0:t.getAttribute("flipx"))||!1,f=(t==null?void 0:t.getAttribute("flipy"))||!1;return{src:t==null?void 0:t.getAttribute("src"),alt:t==null?void 0:t.getAttribute("alt"),caption:t==null?void 0:t.getAttribute("caption"),width:a?Number.parseInt(a,10):null,align:(t==null?void 0:t.getAttribute("align"))||e.style.textAlign||null,inline:(t==null?void 0:t.getAttribute("inline"))||!1,flipX:c==="true",flipY:f==="true"}}},{tag:'img[src]:not([src^="data:"])'}]}});exports.Image=$;exports.RichTextImage=ue;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("./clsx-CXbNJWDD.cjs"),W=require("./throttle-gTTvqDTW.cjs"),n=require("react/jsx-runtime"),o=require("react"),D=require("./index-CVFzP1Dc.cjs"),Y=require("./isNumber-BTYSVlKo.cjs"),ie=require("./toggle-BYvLnjCL.cjs");require("./index-CX4pNJlH.cjs");require("./theme.cjs");const B=require("./button-Cs9TroWr.cjs"),Z=require("./input-BJ7ihMq-.cjs"),J=require("./label-Y7_hvqf2.cjs"),O=require("./tabs-DpHSMyF_.cjs"),ee=require("./use-toast-Bz3QCOtE.cjs"),ae=require("./checkbox-BQRKTXXr.cjs"),z=require("./dialog-BS3zm-T9.cjs"),re=require("react-image-crop"),U=require("./useButtonProps-CydzndG1.cjs"),K=require("./file-i7e4nQY2.cjs"),P=require("./Icon-CiR8RqdQ.cjs"),se=require("./store-BKMaw1AW.cjs"),Q=require("./events.constant-Dq21NPdV.cjs"),H={TOP_LEFT:"tl",TOP_RIGHT:"tr",BOTTOM_LEFT:"bl",BOTTOM_RIGHT:"br"};function le(e){var F,d,E;const[t,a]=o.useState({width:D.IMAGE_MAX_SIZE,height:D.IMAGE_MAX_SIZE}),[c,f]=o.useState({width:0,height:0}),[h]=o.useState([H.TOP_LEFT,H.TOP_RIGHT,H.BOTTOM_LEFT,H.BOTTOM_RIGHT]),[x,T]=o.useState(!1),[g,b]=o.useState({x:0,y:0,w:0,h:0,dir:""}),{align:A,inline:j}=(F=e==null?void 0:e.node)==null?void 0:F.attrs,L=j&&(A==="left"||A==="right"),M=o.useMemo(()=>{var V;const{src:r,alt:I,width:i,height:s,flipX:m,flipY:l}=(V=e==null?void 0:e.node)==null?void 0:V.attrs,y=Y.isNumber(i)?`${i}px`:i,w=Y.isNumber(s)?`${s}px`:s,$=[];m&&$.push("rotateX(180deg)"),l&&$.push("rotateY(180deg)");const ne=$.join(" ");return{src:r||void 0,alt:I||void 0,style:{width:y||void 0,height:w||void 0,transform:ne||"none",...L?{float:A}:{}}}},[(d=e==null?void 0:e.node)==null?void 0:d.attrs]),R=o.useMemo(()=>{const{style:{width:r}}=M;return{width:r==="100%"?r:void 0}},[M]);function _(r){f({width:r.target.width,height:r.target.height})}function C(){const{editor:r,getPos:I}=e;r.commands.setNodeSelection(I())}const S=o.useCallback(W.throttle(()=>{const{editor:r}=e,{width:I}=getComputedStyle(r.view.dom);a(i=>({...i,width:Number.parseInt(I,10)}))},D.IMAGE_THROTTLE_WAIT_TIME),[e==null?void 0:e.editor]);function N(r,I){r.preventDefault(),r.stopPropagation();const i=c.width,s=c.height,m=i/s;let l=Number(e.node.attrs.width),y=Number(e.node.attrs.height);const w=t.width;l&&!y?(l=l>w?w:l,y=Math.round(l/m)):y&&!l?(l=Math.round(y*m),l=l>w?w:l):!l&&!y?(l=i>w?w:i,y=Math.round(l/m)):l=l>w?w:l,T(!0),b({x:r.clientX,y:r.clientY,w:l,h:y,dir:I})}const v=o.useCallback(W.throttle(r=>{if(r.preventDefault(),r.stopPropagation(),!x)return;const{x:I,w:i,dir:s}=g,m=(r.clientX-I)*(/l/.test(s)?-1:1),l=Y.clamp(i+m,D.IMAGE_MIN_SIZE,t.width);e.updateAttributes({width:l,height:null})},D.IMAGE_THROTTLE_WAIT_TIME),[x,g,t,e.updateAttributes]),p=o.useCallback(r=>{r.preventDefault(),r.stopPropagation(),x&&(b({x:0,y:0,w:0,h:0,dir:""}),T(!1),C())},[x,C]),u=o.useCallback(()=>{document==null||document.addEventListener("mousemove",v,!0),document==null||document.addEventListener("mouseup",p,!0)},[v,p]),k=o.useCallback(()=>{document==null||document.removeEventListener("mousemove",v,!0),document==null||document.removeEventListener("mouseup",p,!0)},[v,p]);o.useEffect(()=>(x?u():k(),()=>{k()}),[x,u,k]);const q=o.useMemo(()=>new ResizeObserver(()=>S()),[S]);return o.useEffect(()=>(q.observe(e.editor.view.dom),()=>{q.disconnect()}),[e.editor.view.dom,q]),n.jsx(G.NodeViewWrapper,{as:j?"span":"div",className:"image-view",style:{float:L?A:void 0,margin:L?A==="left"?"1em 1em 1em 0":"1em 0 1em 1em":void 0,display:j?"inline":"block",textAlign:L?void 0:A,width:((E=M.style)==null?void 0:E.width)??"auto",...L?{}:R},children:n.jsxs("div",{"data-drag-handle":!0,draggable:"true",style:R,className:`image-view__body ${e!=null&&e.selected?"image-view__body--focused":""} ${x?"image-view__body--resizing":""}`,children:[n.jsx("img",{alt:M.alt,className:"image-view__body__image block",height:"auto",onClick:C,onLoad:_,src:M.src,style:M.style}),(e==null?void 0:e.editor.view.editable)&&((e==null?void 0:e.selected)||x)&&n.jsx("div",{className:"image-resizer",children:h==null?void 0:h.map(r=>n.jsx("span",{className:`image-resizer__handler image-resizer__handler--${r}`,onMouseDown:I=>N(I,r)},`image-dir-${r}`))})]})})}function oe(e,t){const a=e.type,c=e.name.toLowerCase(),f=c.split(".").pop();if(!f)return!1;const x=a||{heif:"image/heif",heic:"image/heic",dng:"image/x-adobe-dng",cr2:"image/x-canon-cr2",nef:"image/x-nikon-nef",arw:"image/x-sony-arw",raf:"image/x-fuji-raf",orf:"image/x-olympus-orf"}[f];return t.some(T=>{if(T.startsWith("."))return c.endsWith(T);if(T.endsWith("/*")){const g=T.split("/")[0];return x==null?void 0:x.startsWith(g+"/")}return x===T})}function te(e,t){const{acceptMimes:a,maxSize:c,t:f,toast:h}=t,x=[];return(Array.isArray(e)?e:Object.values(e)).forEach(g=>{if(!oe(g,a)){t.onError?t.onError({type:"type",message:f("editor.upload.fileTypeNotSupported",{fileName:g.name}),file:g}):h({variant:"default",title:f("editor.upload.fileTypeNotSupported",{fileName:g.name})});return}if(g.size>c){const b=(c/1024/1024).toFixed(2);t.onError?t.onError({type:"size",message:f("editor.upload.fileSizeTooBig",{fileName:g.name,size:b}),file:g}):h({variant:"default",title:f("editor.upload.fileSizeTooBig",{fileName:g.name,size:b})});return}x.push(g)}),x}function ce({editor:e,imageInline:t,onClose:a,disabled:c,alt:f}){var r,I;const{t:h}=D.useLocale(),{toast:x}=ee.useToast(),[T,g]=o.useState(!1),[b,A]=o.useState(!1),j=o.useRef(null),[L,M]=o.useState(),[R,_]=o.useState(""),C=o.useRef(null),[S,N]=o.useState({src:"",file:null}),v=U.useExtension(X.name),p=o.useMemo(()=>(v==null?void 0:v.options)??{},[v]);function u(i){if(j.current&&i.width&&i.height){const s=k(j.current,i);_(s)}}function k(i,s){const m=document.createElement("canvas"),l=i.naturalWidth/i.width,y=i.naturalHeight/i.height;m.width=s.width*l,m.height=s.height*y;const w=m.getContext("2d");return w&&(w.imageSmoothingEnabled=!1,w.drawImage(i,s.x*l,s.y*y,s.width*l,s.height*y,0,0,s.width*l,s.height*y)),m.toDataURL("image/png",1)}const q=o.useCallback(async()=>{var i;if(!b){A(!0);try{const s=K.dataURLtoFile(R,((i=S==null?void 0:S.file)==null?void 0:i.name)||"image.png");let m="";p.upload?m=await p.upload(s):m=URL.createObjectURL(s),e.chain().focus().setImageInline({src:m,inline:t,alt:f}).run(),g(!1),N({src:"",file:null}),E(),a()}catch(s){console.error("Error cropping image",s)}finally{A(!1)}}},[R,e,t,b,a,(r=S==null?void 0:S.file)==null?void 0:r.name,p]);function F(i){var s;i.preventDefault(),(s=C.current)==null||s.click()}const d=async i=>{var w;const s=(w=i==null?void 0:i.target)==null?void 0:w.files;if(!e||e.isDestroyed||s.length===0){i.target.value="";return}const m=te(s,{acceptMimes:p==null?void 0:p.acceptMimes,maxSize:p==null?void 0:p.maxSize,t:h,toast:x,onError:p.onError});if(m.length<=0){i.target.value="";return}const l=m[0],y=await K.readImageAsBase64(l);g(!0),N({src:y.src,file:l})},E=()=>{C.current&&(C.current.value="")};return n.jsxs(n.Fragment,{children:[n.jsx(B.Button,{className:"richtext-mt-1 richtext-w-full",disabled:c,onClick:F,size:"sm",children:h("editor.image.dialog.tab.uploadCrop")}),n.jsxs(z.Dialog,{open:T,onOpenChange:i=>{g(i),i||(N({src:"",file:null}),E())},children:[n.jsx(z.DialogTrigger,{}),n.jsxs(z.DialogContent,{children:[n.jsx(z.DialogTitle,{children:h("editor.image.dialog.tab.uploadCrop")}),n.jsx("div",{children:S.src&&n.jsx(re,{className:"richtext-w-full",crop:L,onChange:i=>M(i),onComplete:i=>u(i),children:n.jsx("img",{alt:"Crop me",ref:j,src:S.src})})}),n.jsxs(z.DialogFooter,{children:[n.jsxs(B.Button,{disabled:b,onClick:()=>{g(!1),N({src:"",file:null}),E()},children:[h("editor.imageUpload.cancel"),n.jsx(P.IconComponent,{className:"richtext-ml-1",name:"Trash2"})]}),n.jsx(B.Button,{className:"richtext-w-fit",disabled:b||!L,onClick:q,children:b?n.jsxs(n.Fragment,{children:[h("editor.imageUpload.uploading"),n.jsx(P.IconComponent,{className:"richtext-ml-1 richtext-animate-spin",name:"Loader"})]}):n.jsxs(n.Fragment,{children:[h("editor.imageUpload.crop"),n.jsx(P.IconComponent,{className:"richtext-ml-1",name:"Crop"})]})})]})]})]}),n.jsx("input",{accept:((I=p==null?void 0:p.acceptMimes)==null?void 0:I.join(","))||"image/*",multiple:!1,onChange:d,ref:C,style:{display:"none"},type:"file"})]})}function ue(){const{t:e}=D.useLocale(),{toast:t}=ee.useToast(),a=U.useEditorInstance(),c=U.useButtonProps(X.name),{icon:f,tooltip:h}=(c==null?void 0:c.componentProps)??{},{editorDisabled:x}=U.useToggleActive(),[T,g]=o.useState(!1),[b,A]=o.useState(!1),j=U.useExtension(X.name),L=d=>{g(d.detail)},[M,R]=o.useState(""),[_,C]=o.useState(""),S=o.useRef(null),N=(j==null?void 0:j.options.defaultInline)||!1,[v,p]=o.useState(N),u=o.useMemo(()=>j==null?void 0:j.options,[j]);o.useEffect(()=>{const d=Q.listenEvent(Q.EVENTS.UPLOAD_IMAGE(a.id),L);return()=>{d()}},[]);async function k(d){var I;const E=(I=d==null?void 0:d.target)==null?void 0:I.files;if(!a||a.isDestroyed||E.length===0||b){d.target.value="";return}const r=te(E,{acceptMimes:u==null?void 0:u.acceptMimes,maxSize:u==null?void 0:u.maxSize,t:e,toast:t,onError:u.onError});if(r.length<=0){d.target.value="";return}A(!0);try{if(u!=null&&u.multiple){const i=r.map(async m=>{let l="";return u.upload?l=await u.upload(m):l=URL.createObjectURL(m),l});(await Promise.all(i)).forEach(m=>{a.chain().focus().setImageInline({src:m,inline:v,alt:_}).run()})}else{const i=r[0];let s="";u.upload?s=await u.upload(i):s=URL.createObjectURL(i),a.chain().focus().setImageInline({src:s,inline:v,alt:_}).run()}g(!1),C(""),p(N)}catch(i){console.error("Error uploading image",i),u.onError?u.onError({type:"upload",message:e("editor.upload.error")}):t({variant:"destructive",title:e("editor.upload.error")})}finally{A(!1),d.target.value=""}}function q(d){d.preventDefault(),d.stopPropagation(),a.chain().focus().setImageInline({src:M,inline:v,alt:_}).run(),g(!1),p(N),R(""),C("")}function F(d){var E;d.preventDefault(),(E=S.current)==null||E.click()}return c?n.jsxs(z.Dialog,{onOpenChange:g,open:T,children:[n.jsx(z.DialogTrigger,{asChild:!0,children:n.jsx(ie.ActionButton,{disabled:x,icon:f,tooltip:h,action:()=>{x||g(!0)}})}),n.jsxs(z.DialogContent,{children:[n.jsx(z.DialogTitle,{children:e("editor.image.dialog.title")}),n.jsxs(O.Tabs,{activationMode:"manual",defaultValue:u.resourceImage==="both"||u.resourceImage==="upload"?"upload":"link",children:[u.resourceImage==="both"&&n.jsxs(O.TabsList,{className:"richtext-grid richtext-w-full richtext-grid-cols-2",children:[n.jsx(O.TabsTrigger,{value:"upload",children:e("editor.image.dialog.tab.upload")}),n.jsx(O.TabsTrigger,{value:"link",children:e("editor.image.dialog.tab.url")})]}),n.jsxs("div",{className:"richtext-my-[10px] richtext-flex richtext-items-center richtext-gap-[4px]",children:[n.jsx(ae.Checkbox,{checked:v,onCheckedChange:d=>{p(d)}}),n.jsx(J.Label,{children:e("editor.link.dialog.inline")})]}),u.enableAlt&&n.jsxs("div",{className:"richtext-my-[10px] ",children:[n.jsx(J.Label,{className:"mb-[6px]",children:e("editor.imageUpload.alt")}),n.jsx(Z.Input,{onChange:d=>C(d.target.value),required:!0,type:"text",value:_})]}),n.jsxs(O.TabsContent,{value:"upload",children:[n.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-[10px]",children:[n.jsx(B.Button,{className:"richtext-mt-1 richtext-w-full",disabled:b,onClick:F,size:"sm",children:b?n.jsxs(n.Fragment,{children:[e("editor.imageUpload.uploading"),n.jsx(P.IconComponent,{className:"richtext-ml-1 richtext-animate-spin",name:"Loader"})]}):e("editor.image.dialog.tab.upload")}),n.jsx(ce,{alt:_,disabled:b,editor:a,imageInline:v,onClose:()=>{se.actionDialogImage.setOpen(a.id,!1),C("")}})]}),n.jsx("input",{accept:u.acceptMimes.join(",")||"image/*",multiple:u.multiple,onChange:k,ref:S,style:{display:"none"},type:"file"})]}),n.jsx(O.TabsContent,{value:"link",children:n.jsx("form",{onSubmit:q,children:n.jsxs("div",{className:"richtext-flex richtext-items-center richtext-gap-2",children:[n.jsx(Z.Input,{autoFocus:!0,onChange:d=>R(d.target.value),placeholder:e("editor.image.dialog.placeholder"),required:!0,type:"url",value:M}),n.jsx(B.Button,{type:"submit",children:e("editor.image.dialog.button.apply")})]})})})]})]})]}):n.jsx(n.Fragment,{})}const de={acceptMimes:["image/jpeg","image/gif","image/png","image/jpg"],maxSize:1024*1024*5,multiple:!0,resourceImage:"both",defaultInline:!1,enableAlt:!0},X=W.index_default.extend({group:"inline",inline:!0,defining:!0,draggable:!0,selectable:!0,addOptions(){var e;return{...de,...(e=this.parent)==null?void 0:e.call(this),upload:()=>Promise.reject("Image Upload Function"),button:({editor:t,extension:a,t:c})=>{var f,h;return{componentProps:{action:()=>!0,upload:a.options.upload,disabled:!((h=(f=t.can()).setImage)!=null&&h.call(f,{})),icon:"ImageUp",tooltip:c("editor.image.tooltip")}}}}},addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),flipX:{default:!1},flipY:{default:!1},width:{default:null,parseHTML:t=>{const a=t.style.width||t.getAttribute("width")||null;return a?Number.parseInt(a,10):null},renderHTML:t=>({width:t.width})},align:{default:"center",parseHTML:t=>t.getAttribute("align"),renderHTML:t=>({align:t.align})},inline:{default:!1,parseHTML:t=>!!t.getAttribute("inline"),renderHTML:t=>({inline:t.inline})},alt:{default:"",parseHTML:t=>t.getAttribute("alt"),renderHTML:t=>({alt:t.alt})}}},addNodeView(){return G.ReactNodeViewRenderer(le)},addCommands(){var e;return{...(e=this.parent)==null?void 0:e.call(this),setImageInline:t=>({commands:a})=>a.insertContent({type:this.name,attrs:{...t,inline:t.inline??this.options.defaultInline}}),updateImage:t=>({commands:a})=>a.updateAttributes(this.name,t),setAlignImage:t=>({commands:a})=>a.updateAttributes(this.name,{align:t})}},renderHTML({HTMLAttributes:e}){const{flipX:t,flipY:a,align:c,inline:f}=e,h=f&&(c==="left"||c==="right"),x=t||a?`transform: rotateX(${t?"180":"0"}deg) rotateY(${a?"180":"0"}deg);`:"",T=h?"":`text-align: ${c};`,A=`${h?`float: ${c};`:""}${h?c==="left"?"margin: 1em 1em 1em 0;":"margin: 1em 0 1em 1em;":""}${x}`;return[f?"span":"div",{style:T,class:"image"},["img",G.mergeAttributes({height:"auto",style:A},this.options.HTMLAttributes,e)]]},parseHTML(){return[{tag:"span.image img",getAttrs:e=>{var h;const t=e==null?void 0:e.parentElement,a=e==null?void 0:e.getAttribute("width"),c=(e==null?void 0:e.getAttribute("flipx"))||!1,f=(e==null?void 0:e.getAttribute("flipy"))||!1;return{src:e==null?void 0:e.getAttribute("src"),alt:e==null?void 0:e.getAttribute("alt"),caption:e==null?void 0:e.getAttribute("caption"),width:a?Number.parseInt(a,10):null,align:(e==null?void 0:e.getAttribute("align"))||((h=t==null?void 0:t.style)==null?void 0:h.textAlign)||null,inline:(e==null?void 0:e.getAttribute("inline"))||!1,flipX:c==="true",flipY:f==="true"}}},{tag:"div[class=image]",getAttrs:e=>{const t=e.querySelector("img"),a=t==null?void 0:t.getAttribute("width"),c=(t==null?void 0:t.getAttribute("flipx"))||!1,f=(t==null?void 0:t.getAttribute("flipy"))||!1;return{src:t==null?void 0:t.getAttribute("src"),alt:t==null?void 0:t.getAttribute("alt"),caption:t==null?void 0:t.getAttribute("caption"),width:a?Number.parseInt(a,10):null,align:(t==null?void 0:t.getAttribute("align"))||e.style.textAlign||null,inline:(t==null?void 0:t.getAttribute("inline"))||!1,flipX:c==="true",flipY:f==="true"}}},{tag:'img[src]:not([src^="data:"])'}]}});exports.Image=X;exports.RichTextImage=ue;
|
package/lib/Image.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as q, c as pe } from "./throttle-
|
|
1
|
+
import { o as he, m as fe, s as ge } from "./clsx-DmuN0U_8.js";
|
|
2
|
+
import { a as q, c as pe } from "./throttle-BRtichEP.js";
|
|
3
3
|
import { jsx as o, jsxs as b, Fragment as H } from "react/jsx-runtime";
|
|
4
4
|
import j, { useState as L, useMemo as P, useCallback as F, useEffect as W, useRef as ae } from "react";
|
|
5
|
-
import { I as Z,
|
|
6
|
-
import { i as K, c as xe } from "./isNumber-
|
|
7
|
-
import { A as ye } from "./
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { B } from "./button-
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import { I as
|
|
5
|
+
import { I as Z, i as J, j as be, u as ne } from "./index-BDX1uE62.js";
|
|
6
|
+
import { i as K, c as xe } from "./isNumber-DmQXlKp3.js";
|
|
7
|
+
import { A as ye } from "./toggle-Bxwwb_Kp.js";
|
|
8
|
+
import "./index-D9JOHlso.js";
|
|
9
|
+
import "./theme.js";
|
|
10
|
+
import { B } from "./button-9_8t7ca7.js";
|
|
11
|
+
import { I as Q } from "./input-YoheBL2D.js";
|
|
12
|
+
import { L as ee } from "./label-C8PLcjFI.js";
|
|
13
|
+
import { T as we, a as Ie, b as te, c as ie } from "./tabs-DxlKKM-N.js";
|
|
14
|
+
import { u as re } from "./use-toast-Crf7-q5H.js";
|
|
15
|
+
import { C as ve } from "./checkbox-DnkkV6qo.js";
|
|
16
|
+
import { D as le, a as oe, b as se, c as ce, d as Te } from "./dialog-DhayAPvV.js";
|
|
17
|
+
import Ae from "react-image-crop";
|
|
18
|
+
import { d as de, c as Ce, u as Ee, a as Me } from "./useButtonProps-CfYtuEnd.js";
|
|
19
|
+
import { d as Le, r as Ne } from "./file-BLas99n7.js";
|
|
20
|
+
import { I as $ } from "./Icon-ONE1AwKo.js";
|
|
21
|
+
import { a as Se } from "./store-DG7cMfET.js";
|
|
22
|
+
import { l as _e, E as ze } from "./events.constant-do95b767.js";
|
|
21
23
|
const X = {
|
|
22
24
|
TOP_LEFT: "tl",
|
|
23
25
|
TOP_RIGHT: "tr",
|
|
@@ -231,10 +233,10 @@ function ue(e, t) {
|
|
|
231
233
|
}
|
|
232
234
|
function Ue({ editor: e, imageInline: t, onClose: a, disabled: s, alt: f }) {
|
|
233
235
|
var n, y;
|
|
234
|
-
const { t: u } = ne(), { toast: g } =
|
|
236
|
+
const { t: u } = ne(), { toast: g } = re(), [v, m] = L(!1), [x, C] = L(!1), T = j.useRef(null), [_, S] = j.useState(), [k, R] = j.useState(""), M = ae(null), [E, z] = L({
|
|
235
237
|
src: "",
|
|
236
238
|
file: null
|
|
237
|
-
}), A =
|
|
239
|
+
}), A = de(G.name), p = P(() => (A == null ? void 0 : A.options) ?? {}, [A]);
|
|
238
240
|
function c(i) {
|
|
239
241
|
if (T.current && i.width && i.height) {
|
|
240
242
|
const r = U(T.current, i);
|
|
@@ -262,14 +264,14 @@ function Ue({ editor: e, imageInline: t, onClose: a, disabled: s, alt: f }) {
|
|
|
262
264
|
if (!x) {
|
|
263
265
|
C(!0);
|
|
264
266
|
try {
|
|
265
|
-
const r =
|
|
267
|
+
const r = Le(k, ((i = E == null ? void 0 : E.file) == null ? void 0 : i.name) || "image.png");
|
|
266
268
|
let h = "";
|
|
267
269
|
p.upload ? h = await p.upload(r) : h = URL.createObjectURL(r), e.chain().focus().setImageInline({ src: h, inline: t, alt: f }).run(), m(!1), z({
|
|
268
270
|
src: "",
|
|
269
271
|
file: null
|
|
270
272
|
}), N(), a();
|
|
271
273
|
} catch (r) {
|
|
272
|
-
console.
|
|
274
|
+
console.error("Error cropping image", r);
|
|
273
275
|
} finally {
|
|
274
276
|
C(!1);
|
|
275
277
|
}
|
|
@@ -297,7 +299,7 @@ function Ue({ editor: e, imageInline: t, onClose: a, disabled: s, alt: f }) {
|
|
|
297
299
|
i.target.value = "";
|
|
298
300
|
return;
|
|
299
301
|
}
|
|
300
|
-
const l = h[0], w = await
|
|
302
|
+
const l = h[0], w = await Ne(l);
|
|
301
303
|
m(!0), z({
|
|
302
304
|
src: w.src,
|
|
303
305
|
file: l
|
|
@@ -317,18 +319,18 @@ function Ue({ editor: e, imageInline: t, onClose: a, disabled: s, alt: f }) {
|
|
|
317
319
|
}
|
|
318
320
|
),
|
|
319
321
|
/* @__PURE__ */ b(
|
|
320
|
-
|
|
322
|
+
le,
|
|
321
323
|
{
|
|
322
324
|
open: v,
|
|
323
325
|
onOpenChange: (i) => {
|
|
324
326
|
m(i), i || (z({ src: "", file: null }), N());
|
|
325
327
|
},
|
|
326
328
|
children: [
|
|
327
|
-
/* @__PURE__ */ o(
|
|
328
|
-
/* @__PURE__ */ b(
|
|
329
|
-
/* @__PURE__ */ o(
|
|
329
|
+
/* @__PURE__ */ o(oe, {}),
|
|
330
|
+
/* @__PURE__ */ b(se, { children: [
|
|
331
|
+
/* @__PURE__ */ o(ce, { children: u("editor.image.dialog.tab.uploadCrop") }),
|
|
330
332
|
/* @__PURE__ */ o("div", { children: E.src && /* @__PURE__ */ o(
|
|
331
|
-
|
|
333
|
+
Ae,
|
|
332
334
|
{
|
|
333
335
|
className: "richtext-w-full",
|
|
334
336
|
crop: _,
|
|
@@ -344,7 +346,7 @@ function Ue({ editor: e, imageInline: t, onClose: a, disabled: s, alt: f }) {
|
|
|
344
346
|
)
|
|
345
347
|
}
|
|
346
348
|
) }),
|
|
347
|
-
/* @__PURE__ */ b(
|
|
349
|
+
/* @__PURE__ */ b(Te, { children: [
|
|
348
350
|
/* @__PURE__ */ b(
|
|
349
351
|
B,
|
|
350
352
|
{
|
|
@@ -412,15 +414,15 @@ function Ue({ editor: e, imageInline: t, onClose: a, disabled: s, alt: f }) {
|
|
|
412
414
|
)
|
|
413
415
|
] });
|
|
414
416
|
}
|
|
415
|
-
function
|
|
416
|
-
const { t: e } = ne(), { toast: t } =
|
|
417
|
+
function lt() {
|
|
418
|
+
const { t: e } = ne(), { toast: t } = re(), a = Ce(), s = Ee(G.name), {
|
|
417
419
|
icon: f,
|
|
418
420
|
tooltip: u
|
|
419
|
-
} = (s == null ? void 0 : s.componentProps) ?? {}, { editorDisabled: g } =
|
|
421
|
+
} = (s == null ? void 0 : s.componentProps) ?? {}, { editorDisabled: g } = Me(), [v, m] = L(!1), [x, C] = L(!1), T = de(G.name), _ = (d) => {
|
|
420
422
|
m(d.detail);
|
|
421
423
|
}, [S, k] = L(""), [R, M] = L(""), E = ae(null), z = (T == null ? void 0 : T.options.defaultInline) || !1, [A, p] = L(z), c = P(() => T == null ? void 0 : T.options, [T]);
|
|
422
424
|
W(() => {
|
|
423
|
-
const d =
|
|
425
|
+
const d = _e(ze.UPLOAD_IMAGE(a.id), _);
|
|
424
426
|
return () => {
|
|
425
427
|
d();
|
|
426
428
|
};
|
|
@@ -479,13 +481,13 @@ function nt() {
|
|
|
479
481
|
d.preventDefault(), (N = E.current) == null || N.click();
|
|
480
482
|
}
|
|
481
483
|
return s ? /* @__PURE__ */ b(
|
|
482
|
-
|
|
484
|
+
le,
|
|
483
485
|
{
|
|
484
486
|
onOpenChange: m,
|
|
485
487
|
open: v,
|
|
486
488
|
children: [
|
|
487
489
|
/* @__PURE__ */ o(
|
|
488
|
-
|
|
490
|
+
oe,
|
|
489
491
|
{
|
|
490
492
|
asChild: !0,
|
|
491
493
|
children: /* @__PURE__ */ o(
|
|
@@ -501,21 +503,21 @@ function nt() {
|
|
|
501
503
|
)
|
|
502
504
|
}
|
|
503
505
|
),
|
|
504
|
-
/* @__PURE__ */ b(
|
|
505
|
-
/* @__PURE__ */ o(
|
|
506
|
+
/* @__PURE__ */ b(se, { children: [
|
|
507
|
+
/* @__PURE__ */ o(ce, { children: e("editor.image.dialog.title") }),
|
|
506
508
|
/* @__PURE__ */ b(
|
|
507
|
-
|
|
509
|
+
we,
|
|
508
510
|
{
|
|
509
511
|
activationMode: "manual",
|
|
510
512
|
defaultValue: c.resourceImage === "both" || c.resourceImage === "upload" ? "upload" : "link",
|
|
511
513
|
children: [
|
|
512
|
-
c.resourceImage === "both" && /* @__PURE__ */ b(
|
|
513
|
-
/* @__PURE__ */ o(
|
|
514
|
-
/* @__PURE__ */ o(
|
|
514
|
+
c.resourceImage === "both" && /* @__PURE__ */ b(Ie, { className: "richtext-grid richtext-w-full richtext-grid-cols-2", children: [
|
|
515
|
+
/* @__PURE__ */ o(te, { value: "upload", children: e("editor.image.dialog.tab.upload") }),
|
|
516
|
+
/* @__PURE__ */ o(te, { value: "link", children: e("editor.image.dialog.tab.url") })
|
|
515
517
|
] }),
|
|
516
518
|
/* @__PURE__ */ b("div", { className: "richtext-my-[10px] richtext-flex richtext-items-center richtext-gap-[4px]", children: [
|
|
517
519
|
/* @__PURE__ */ o(
|
|
518
|
-
|
|
520
|
+
ve,
|
|
519
521
|
{
|
|
520
522
|
checked: A,
|
|
521
523
|
onCheckedChange: (d) => {
|
|
@@ -523,12 +525,12 @@ function nt() {
|
|
|
523
525
|
}
|
|
524
526
|
}
|
|
525
527
|
),
|
|
526
|
-
/* @__PURE__ */ o(
|
|
528
|
+
/* @__PURE__ */ o(ee, { children: e("editor.link.dialog.inline") })
|
|
527
529
|
] }),
|
|
528
530
|
c.enableAlt && /* @__PURE__ */ b("div", { className: "richtext-my-[10px] ", children: [
|
|
529
|
-
/* @__PURE__ */ o(
|
|
531
|
+
/* @__PURE__ */ o(ee, { className: "mb-[6px]", children: e("editor.imageUpload.alt") }),
|
|
530
532
|
/* @__PURE__ */ o(
|
|
531
|
-
|
|
533
|
+
Q,
|
|
532
534
|
{
|
|
533
535
|
onChange: (d) => M(d.target.value),
|
|
534
536
|
required: !0,
|
|
@@ -537,7 +539,7 @@ function nt() {
|
|
|
537
539
|
}
|
|
538
540
|
)
|
|
539
541
|
] }),
|
|
540
|
-
/* @__PURE__ */ b(
|
|
542
|
+
/* @__PURE__ */ b(ie, { value: "upload", children: [
|
|
541
543
|
/* @__PURE__ */ b("div", { className: "richtext-flex richtext-items-center richtext-gap-[10px]", children: [
|
|
542
544
|
/* @__PURE__ */ o(
|
|
543
545
|
B,
|
|
@@ -566,7 +568,7 @@ function nt() {
|
|
|
566
568
|
editor: a,
|
|
567
569
|
imageInline: A,
|
|
568
570
|
onClose: () => {
|
|
569
|
-
|
|
571
|
+
Se.setOpen(a.id, !1), M("");
|
|
570
572
|
}
|
|
571
573
|
}
|
|
572
574
|
)
|
|
@@ -583,9 +585,9 @@ function nt() {
|
|
|
583
585
|
}
|
|
584
586
|
)
|
|
585
587
|
] }),
|
|
586
|
-
/* @__PURE__ */ o(
|
|
588
|
+
/* @__PURE__ */ o(ie, { value: "link", children: /* @__PURE__ */ o("form", { onSubmit: D, children: /* @__PURE__ */ b("div", { className: "richtext-flex richtext-items-center richtext-gap-2", children: [
|
|
587
589
|
/* @__PURE__ */ o(
|
|
588
|
-
|
|
590
|
+
Q,
|
|
589
591
|
{
|
|
590
592
|
autoFocus: !0,
|
|
591
593
|
onChange: (d) => k(d.target.value),
|
|
@@ -824,5 +826,5 @@ const De = {
|
|
|
824
826
|
});
|
|
825
827
|
export {
|
|
826
828
|
G as Image,
|
|
827
|
-
|
|
829
|
+
lt as RichTextImage
|
|
828
830
|
};
|
package/lib/ImageGif.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("./clsx-CXbNJWDD.cjs"),N=require("./throttle-gTTvqDTW.cjs"),l=require("react/jsx-runtime"),d=require("react"),G=require("./index-CVFzP1Dc.cjs"),L=require("./isNumber-BTYSVlKo.cjs"),W=require("./toggle-BYvLnjCL.cjs");require("./index-CX4pNJlH.cjs");require("./theme.cjs");const D=require("./input-BJ7ihMq-.cjs"),P=require("./popover-BiSrlM4j.cjs"),k=require("./useButtonProps-CydzndG1.cjs"),S={TOP_LEFT:"tl",TOP_RIGHT:"tr",BOTTOM_LEFT:"bl",BOTTOM_RIGHT:"br"};function B(e){var C,$;const[t,n]=d.useState({width:G.IMAGE_MAX_SIZE,height:G.IMAGE_MAX_SIZE}),[c,i]=d.useState({width:0,height:0}),[r]=d.useState([S.TOP_LEFT,S.TOP_RIGHT,S.BOTTOM_LEFT,S.BOTTOM_RIGHT]),[s,a]=d.useState(!1),[h,b]=d.useState({x:0,y:0,w:0,h:0,dir:""}),{align:x}=(C=e==null?void 0:e.node)==null?void 0:C.attrs,m=d.useMemo(()=>{var v;const{src:o,alt:f,width:w,height:M}=(v=e==null?void 0:e.node)==null?void 0:v.attrs,A=L.isNumber(w)?`${w}px`:w,u=L.isNumber(M)?`${M}px`:M;return{src:o||void 0,alt:f||void 0,style:{width:A||void 0,height:u||void 0}}},[($=e==null?void 0:e.node)==null?void 0:$.attrs]),T=d.useMemo(()=>{const{style:{width:o}}=m;return{width:o==="100%"?o:void 0}},[m]);function g(o){i({width:o.target.width,height:o.target.height})}function _(){const{editor:o,getPos:f}=e;o.commands.setNodeSelection(f())}const y=d.useCallback(N.throttle(()=>{const{editor:o}=e,{width:f}=getComputedStyle(o.view.dom);n(w=>({...w,width:Number.parseInt(f,10)}))},G.IMAGE_THROTTLE_WAIT_TIME),[e==null?void 0:e.editor]);function p(o,f){o.preventDefault(),o.stopPropagation();const w=c.width,M=c.height,A=w/M;let u=Number(e.node.attrs.width),v=Number(e.node.attrs.height);const I=t.width;u&&!v?(u=u>I?I:u,v=Math.round(u/A)):v&&!u?(u=Math.round(v*A),u=u>I?I:u):!u&&!v?(u=w>I?I:w,v=Math.round(u/A)):u=u>I?I:u,a(!0),b({x:o.clientX,y:o.clientY,w:u,h:v,dir:f})}const j=d.useCallback(N.throttle(o=>{if(o.preventDefault(),o.stopPropagation(),!s)return;const{x:f,w,dir:M}=h,A=(o.clientX-f)*(/l/.test(M)?-1:1),u=L.clamp(w+A,G.IMAGE_MIN_SIZE,t.width);e.updateAttributes({width:u,height:null})},G.IMAGE_THROTTLE_WAIT_TIME),[s,h,t,e.updateAttributes]),E=d.useCallback(o=>{o.preventDefault(),o.stopPropagation(),s&&(b({x:0,y:0,w:0,h:0,dir:""}),a(!1),_())},[s,_]),z=d.useCallback(()=>{document==null||document.addEventListener("mousemove",j,!0),document==null||document.addEventListener("mouseup",E,!0)},[j,E]),O=d.useCallback(()=>{document==null||document.removeEventListener("mousemove",j,!0),document==null||document.removeEventListener("mouseup",E,!0)},[j,E]);d.useEffect(()=>(s?z():O(),()=>{O()}),[s,z,O]);const R=d.useMemo(()=>new ResizeObserver(()=>y()),[y]);return d.useEffect(()=>(R.observe(e.editor.view.dom),()=>{R.disconnect()}),[e.editor.view.dom,R]),l.jsx(q.NodeViewWrapper,{className:"image-view",style:{...T,width:"100%",textAlign:x},children:l.jsxs("div",{"data-drag-handle":!0,draggable:"true",style:T,className:`image-view__body ${e!=null&&e.selected?"image-view__body--focused":""} ${s?"image-view__body--resizing":""}`,children:[l.jsx("img",{alt:m.alt,className:"image-view__body__image block",height:"auto",onClick:_,onLoad:g,src:m.src,style:m.style}),(e==null?void 0:e.editor.view.editable)&&((e==null?void 0:e.selected)||s)&&l.jsx("div",{className:"image-resizer",children:r==null?void 0:r.map(o=>l.jsx("span",{className:`image-resizer__handler image-resizer__handler--${o}`,onMouseDown:f=>p(f,o)},`image-dir-${o}`))})]})})}async function F(e){var c;const n=await(await fetch(`https://api.giphy.com/v1/gifs/trending?q=&limit=15&api_key=${e}`)).json();return(c=n==null?void 0:n.data)==null?void 0:c.map(i=>{var r,s,a;return{id:i==null?void 0:i.id,src:(r=i==null?void 0:i.images.original)==null?void 0:r.url,width:+((s=i==null?void 0:i.images.original)==null?void 0:s.width),height:+((a=i==null?void 0:i.images.original)==null?void 0:a.width)}})}async function V(e,t){var i;const c=await(await fetch(`https://api.giphy.com/v1/gifs/search?q=${e}&limit=15&api_key=${t}`)).json();return(i=c==null?void 0:c.data)==null?void 0:i.map(r=>{var s,a,h;return{id:r==null?void 0:r.id,src:(s=r==null?void 0:r.images.original)==null?void 0:s.url,width:+((a=r==null?void 0:r.images.original)==null?void 0:a.width),height:+((h=r==null?void 0:r.images.original)==null?void 0:h.width)}})}async function X(e){var r,s;const t=await fetch(`https://tenor.googleapis.com/v2/trending_terms?key=${e}&limit=10`),n=await(t==null?void 0:t.json()),i=await(await fetch(`https://tenor.googleapis.com/v2/search?key=${e}&q=${(r=n==null?void 0:n.results)==null?void 0:r[0]}&limit=15`)).json();return(s=i==null?void 0:i.results)==null?void 0:s.map(a=>{var h,b,x,m,T,g,_,y;return{id:a==null?void 0:a.id,src:(b=(h=a==null?void 0:a.media_formats)==null?void 0:h.gif)==null?void 0:b.url,width:(T=(m=(x=a==null?void 0:a.media_formats)==null?void 0:x.gif)==null?void 0:m.dims)==null?void 0:T[0],height:(y=(_=(g=a==null?void 0:a.media_formats)==null?void 0:g.gif)==null?void 0:_.dims)==null?void 0:y[1]}})}async function Y(e,t){var i;const c=await(await fetch(`https://tenor.googleapis.com/v2/search?key=${t}&q=${e}&limit=15`)).json();return(i=c==null?void 0:c.results)==null?void 0:i.map(r=>{var s,a,h,b,x,m,T,g;return{id:r==null?void 0:r.id,src:(a=(s=r==null?void 0:r.media_formats)==null?void 0:s.gif)==null?void 0:a.url,width:(x=(b=(h=r==null?void 0:r.media_formats)==null?void 0:h.gif)==null?void 0:b.dims)==null?void 0:x[0],height:(g=(T=(m=r==null?void 0:r.media_formats)==null?void 0:m.gif)==null?void 0:T.dims)==null?void 0:g[1]}})}function Z(e,t){return{searchTrending:async()=>t?e==="giphy"?F(t):e==="tenor"?X(t):[]:[],searchWord:async i=>t?e==="giphy"?V(i,t):e==="tenor"?Y(i,t):[]:[]}}function U({selectImage:e,apiKey:t,provider:n,children:c}){const[i,r]=d.useState(!1),[s,a]=d.useState([]),{editorDisabled:h}=k.useToggleActive(),b=d.useRef(null),{searchTrending:x,searchWord:m}=Z(n,t);d.useEffect(()=>{(async()=>{const g=await x();a(g)})()},[]);const T=d.useCallback(N.debounce(async g=>{if(!g.target.value){const y=await x();a(y);return}const _=await m(g.target.value);a(_)},350),[]);return l.jsxs(P.Popover,{modal:!0,onOpenChange:r,open:i,children:[l.jsx(P.PopoverTrigger,{asChild:!0,disabled:h,children:c}),l.jsx(P.PopoverContent,{align:"start",className:"richtext-size-full richtext-p-2",hideWhenDetached:!0,side:"bottom",children:t?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"richtext-mb-[10px] richtext-w-full",children:l.jsx(D.Input,{onChange:T,placeholder:"Search GIF",ref:b,type:"text"})}),l.jsx("div",{className:"richtext-max-h-[280px] !richtext-max-w-[400px] richtext-overflow-y-auto",children:l.jsx("div",{className:"richtext-grid richtext-grid-cols-2 richtext-gap-1 ",children:s!=null&&s.length?s==null?void 0:s.map(g=>l.jsx("img",{alt:"",className:"richtext-cursor-pointer richtext-object-contain richtext-text-center",src:g.src,onClick:()=>{e(g.src),r(!1)}},g.id)):l.jsx("p",{children:"No GIFs found"})})})]}):l.jsx("div",{children:l.jsx("p",{children:"Missing Giphy API Key"})})})]})}function J(){const e=k.useButtonProps(H.name),{action:t,icon:n,tooltip:c,apiKey:i,provider:r}=(e==null?void 0:e.componentProps)??{},{editorDisabled:s}=k.useToggleActive(),a=h=>{s||t&&t(h)};return l.jsx(U,{apiKey:i,provider:r,selectImage:a,children:l.jsx(W.ActionButton,{disabled:s,icon:n,tooltip:c})})}const H=N.index_default.extend({name:"imageGif",addOptions(){var e;return{...(e=this.parent)==null?void 0:e.call(this),inline:!1,content:"",marks:"",group:"block",API_KEY:"",provider:"giphy",draggable:!1,selectable:!0,atom:!0,button:({editor:t,extension:n,t:c})=>{var s,a;const i=((s=n==null?void 0:n.options)==null?void 0:s.provider)||"",r=((a=n==null?void 0:n.options)==null?void 0:a.API_KEY)||"";return{componentProps:{action:h=>{t.chain().focus().setImageGif({src:h}).run()},isActive:()=>!1,disabled:!1,icon:"GifIcon",tooltip:c("editor.imageGif.tooltip"),apiKey:r,provider:i}}}}},addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),width:{default:null,parseHTML:t=>{const n=t.style.width||t.getAttribute("width")||"10";return n===void 0?null:Number.parseInt(`${n}`,10)},renderHTML:t=>({width:t.width})},align:{default:"center",parseHTML:t=>t.getAttribute("align"),renderHTML:t=>({align:t.align})}}},addNodeView(){return q.ReactNodeViewRenderer(B)},addCommands(){var e;return{...(e=this.parent)==null?void 0:e.call(this),setImageGif:t=>({commands:n})=>n.insertContent({type:this.name,attrs:t}),updateImageGif:t=>({commands:n})=>n.updateAttributes(this.name,t),setAlignImageGif:t=>({commands:n})=>n.updateAttributes(this.name,{align:t})}},renderHTML({HTMLAttributes:e}){const{align:t}=e;return["div",{style:t?`text-align: ${t};`:"",class:"imageGIf"},["img",q.mergeAttributes({height:"auto"},this.options.HTMLAttributes,e)]]},parseHTML(){return[{tag:"div[class=imageGIf]",getAttrs:e=>{const t=e.querySelector("img"),n=t==null?void 0:t.getAttribute("width");return{src:t==null?void 0:t.getAttribute("src"),alt:t==null?void 0:t.getAttribute("alt"),title:t==null?void 0:t.getAttribute("title"),width:n?Number.parseInt(n,10):null,align:(t==null?void 0:t.getAttribute("align"))||e.style.textAlign||null}}}]}});exports.ImageGif=H;exports.RichTextImageGif=J;
|