sykpcomposer 0.0.141 → 0.0.144
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/dist/ImageComponent-d523586d.js +895 -0
- package/dist/ImageComponent-d523586d.js.map +1 -0
- package/dist/{InlineImageComponent-a5f103d0.js → InlineImageComponent-6f9fac77.js} +3 -3
- package/dist/{InlineImageComponent-a5f103d0.js.map → InlineImageComponent-6f9fac77.js.map} +1 -1
- package/dist/{Placeholder-478af7a4.js → Placeholder-7390c80d.js} +19 -19
- package/dist/{Placeholder-478af7a4.js.map → Placeholder-7390c80d.js.map} +1 -1
- package/dist/{index-3c0a98fe.js → index-21f517a3.js} +8673 -8640
- package/dist/{index-3c0a98fe.js.map → index-21f517a3.js.map} +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +124 -124
- package/dist/index.umd.js.map +1 -1
- package/dist/src/components/Editor.d.ts +2 -2
- package/dist/src/components/plugins/H.d.ts +6 -0
- package/dist/src/components/plugins/InsertExternalNodesPlugin.d.ts +3 -1
- package/dist/src/components/plugins/TablePlugin.d.ts +3 -1
- package/dist/src/components/plugins/ToolbarPlugin.d.ts +1 -1
- package/dist/src/components/ui/ImageResizer.d.ts +4 -1
- package/dist/style.css +1 -1
- package/package.json +2 -1
- package/dist/ImageComponent-de5210be.js +0 -851
- package/dist/ImageComponent-de5210be.js.map +0 -1
|
@@ -0,0 +1,895 @@
|
|
|
1
|
+
import { j as v, u as he, d as U, w as G, x as J, $ as Q, a as te, b as ce, c as de, e as le, C as I, f as ge, k as ue, g as pe, I as we, r as me, h as xe, i as fe, l as ye, t as Ce } from "./index-21f517a3.js";
|
|
2
|
+
import { u as ve, d as De, L as be, P as Re } from "./Placeholder-7390c80d.js";
|
|
3
|
+
import f, { useRef as Y, PureComponent as Ee, createRef as ne, useState as O, useCallback as F, useEffect as ee, Suspense as Me } from "react";
|
|
4
|
+
import "react-dom";
|
|
5
|
+
function Z(g, t, e) {
|
|
6
|
+
return Math.min(Math.max(g, t), e);
|
|
7
|
+
}
|
|
8
|
+
const y = {
|
|
9
|
+
east: 1,
|
|
10
|
+
north: 8,
|
|
11
|
+
south: 2,
|
|
12
|
+
west: 4
|
|
13
|
+
};
|
|
14
|
+
function Pe({
|
|
15
|
+
onResizeStart: g,
|
|
16
|
+
onResizeEnd: t,
|
|
17
|
+
buttonRef: e,
|
|
18
|
+
imageRef: o,
|
|
19
|
+
maxWidth: n,
|
|
20
|
+
editor: i,
|
|
21
|
+
showCaption: h,
|
|
22
|
+
setShowCaption: u,
|
|
23
|
+
captionsEnabled: s
|
|
24
|
+
}) {
|
|
25
|
+
const r = Y(null), a = Y({
|
|
26
|
+
priority: "",
|
|
27
|
+
value: "default"
|
|
28
|
+
}), d = Y({
|
|
29
|
+
currentHeight: 0,
|
|
30
|
+
currentWidth: 0,
|
|
31
|
+
direction: 0,
|
|
32
|
+
isResizing: !1,
|
|
33
|
+
ratio: 0,
|
|
34
|
+
startHeight: 0,
|
|
35
|
+
startWidth: 0,
|
|
36
|
+
startX: 0,
|
|
37
|
+
startY: 0
|
|
38
|
+
}), l = i.getRootElement(), c = l !== null ? l.getBoundingClientRect().width - 20 : 100, C = l !== null ? l.getBoundingClientRect().height - 20 : 100, M = 100, x = 100, z = (p) => {
|
|
39
|
+
const w = p === y.east || p === y.west, m = p === y.north || p === y.south, N = p & y.north && p & y.west || p & y.south && p & y.east, $ = w ? "ew" : m ? "ns" : N ? "nwse" : "nesw";
|
|
40
|
+
l !== null && l.style.setProperty(
|
|
41
|
+
"cursor",
|
|
42
|
+
`${$}-resize`,
|
|
43
|
+
"important"
|
|
44
|
+
), document.body !== null && (document.body.style.setProperty(
|
|
45
|
+
"cursor",
|
|
46
|
+
`${$}-resize`,
|
|
47
|
+
"important"
|
|
48
|
+
), a.current.value = document.body.style.getPropertyValue(
|
|
49
|
+
"-webkit-user-select"
|
|
50
|
+
), a.current.priority = document.body.style.getPropertyPriority(
|
|
51
|
+
"-webkit-user-select"
|
|
52
|
+
), document.body.style.setProperty(
|
|
53
|
+
"-webkit-user-select",
|
|
54
|
+
"none",
|
|
55
|
+
"important"
|
|
56
|
+
));
|
|
57
|
+
}, W = () => {
|
|
58
|
+
l !== null && l.style.setProperty("cursor", "text"), document.body !== null && (document.body.style.setProperty("cursor", "default"), document.body.style.setProperty(
|
|
59
|
+
"-webkit-user-select",
|
|
60
|
+
a.current.value,
|
|
61
|
+
a.current.priority
|
|
62
|
+
));
|
|
63
|
+
}, H = (p, w) => {
|
|
64
|
+
if (!i.isEditable())
|
|
65
|
+
return;
|
|
66
|
+
const m = o.current, N = r.current;
|
|
67
|
+
if (m !== null && N !== null) {
|
|
68
|
+
p.preventDefault();
|
|
69
|
+
const { width: $, height: D } = m.getBoundingClientRect(), b = d.current;
|
|
70
|
+
b.startWidth = $, b.startHeight = D, b.ratio = $ / D, b.currentWidth = $, b.currentHeight = D, b.startX = p.clientX, b.startY = p.clientY, b.isResizing = !0, b.direction = w, z(w), g(), N.classList.add("image-control-wrapper--resizing"), m.style.height = `${D}px`, m.style.width = `${$}px`, document.addEventListener("pointermove", L), document.addEventListener("pointerup", R);
|
|
71
|
+
}
|
|
72
|
+
}, L = (p) => {
|
|
73
|
+
const w = o.current, m = d.current, N = m.direction & (y.east | y.west), $ = m.direction & (y.south | y.north);
|
|
74
|
+
if (w !== null && m.isResizing) {
|
|
75
|
+
if (N && $) {
|
|
76
|
+
let D = Math.floor(m.startX - p.clientX);
|
|
77
|
+
D = m.direction & y.east ? -D : D;
|
|
78
|
+
const b = Z(
|
|
79
|
+
m.startWidth + D,
|
|
80
|
+
M,
|
|
81
|
+
c
|
|
82
|
+
), T = b / m.ratio;
|
|
83
|
+
w.style.width = `${b}px`, w.style.height = `${T}px`, m.currentHeight = T, m.currentWidth = b;
|
|
84
|
+
} else if ($) {
|
|
85
|
+
let D = Math.floor(m.startY - p.clientY);
|
|
86
|
+
D = m.direction & y.south ? -D : D;
|
|
87
|
+
const b = Z(
|
|
88
|
+
m.startHeight + D,
|
|
89
|
+
x,
|
|
90
|
+
C
|
|
91
|
+
);
|
|
92
|
+
w.style.height = `${b}px`, w.style.maxHeight = `${b}px`, m.currentHeight = b;
|
|
93
|
+
} else {
|
|
94
|
+
let D = Math.floor(m.startX - p.clientX);
|
|
95
|
+
D = m.direction & y.east ? -D : D;
|
|
96
|
+
const b = Z(
|
|
97
|
+
m.startWidth + D,
|
|
98
|
+
M,
|
|
99
|
+
c
|
|
100
|
+
);
|
|
101
|
+
w.style.width = `${b}px`, w.style.maxWidth = `${b}px`, m.currentWidth = b;
|
|
102
|
+
}
|
|
103
|
+
w && (w.setAttribute("width", `${m.currentWidth}`), w.setAttribute("height", `${m.currentHeight}`));
|
|
104
|
+
}
|
|
105
|
+
}, R = () => {
|
|
106
|
+
const p = o.current, w = d.current, m = r.current;
|
|
107
|
+
if (p !== null && m !== null && w.isResizing) {
|
|
108
|
+
const N = w.currentWidth, $ = w.currentHeight;
|
|
109
|
+
w.startWidth = 0, w.startHeight = 0, w.ratio = 0, w.startX = 0, w.startY = 0, w.currentWidth = 0, w.currentHeight = 0, w.isResizing = !1, m.classList.remove("image-control-wrapper--resizing"), W(), t(N, $), document.removeEventListener("pointermove", L), document.removeEventListener("pointerup", R);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
return /* @__PURE__ */ v.jsxs("div", { ref: r, children: [
|
|
113
|
+
/* @__PURE__ */ v.jsx(
|
|
114
|
+
"div",
|
|
115
|
+
{
|
|
116
|
+
className: "image-resizer image-resizer-n",
|
|
117
|
+
onPointerDown: (p) => {
|
|
118
|
+
H(p, y.north);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
),
|
|
122
|
+
/* @__PURE__ */ v.jsx(
|
|
123
|
+
"div",
|
|
124
|
+
{
|
|
125
|
+
className: "image-resizer image-resizer-ne",
|
|
126
|
+
onPointerDown: (p) => {
|
|
127
|
+
H(p, y.north | y.east);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
),
|
|
131
|
+
/* @__PURE__ */ v.jsx(
|
|
132
|
+
"div",
|
|
133
|
+
{
|
|
134
|
+
className: "image-resizer image-resizer-e",
|
|
135
|
+
onPointerDown: (p) => {
|
|
136
|
+
H(p, y.east);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
),
|
|
140
|
+
/* @__PURE__ */ v.jsx(
|
|
141
|
+
"div",
|
|
142
|
+
{
|
|
143
|
+
className: "image-resizer image-resizer-se",
|
|
144
|
+
onPointerDown: (p) => {
|
|
145
|
+
H(p, y.south | y.east);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
),
|
|
149
|
+
/* @__PURE__ */ v.jsx(
|
|
150
|
+
"div",
|
|
151
|
+
{
|
|
152
|
+
className: "image-resizer image-resizer-s",
|
|
153
|
+
onPointerDown: (p) => {
|
|
154
|
+
H(p, y.south);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
),
|
|
158
|
+
/* @__PURE__ */ v.jsx(
|
|
159
|
+
"div",
|
|
160
|
+
{
|
|
161
|
+
className: "image-resizer image-resizer-sw",
|
|
162
|
+
onPointerDown: (p) => {
|
|
163
|
+
H(p, y.south | y.west);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
),
|
|
167
|
+
/* @__PURE__ */ v.jsx(
|
|
168
|
+
"div",
|
|
169
|
+
{
|
|
170
|
+
className: "image-resizer image-resizer-w",
|
|
171
|
+
onPointerDown: (p) => {
|
|
172
|
+
H(p, y.west);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
),
|
|
176
|
+
/* @__PURE__ */ v.jsx(
|
|
177
|
+
"div",
|
|
178
|
+
{
|
|
179
|
+
className: "image-resizer image-resizer-nw",
|
|
180
|
+
onPointerDown: (p) => {
|
|
181
|
+
H(p, y.north | y.west);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
)
|
|
185
|
+
] });
|
|
186
|
+
}
|
|
187
|
+
const V = {
|
|
188
|
+
x: 0,
|
|
189
|
+
y: 0,
|
|
190
|
+
width: 0,
|
|
191
|
+
height: 0,
|
|
192
|
+
unit: "px"
|
|
193
|
+
}, j = (g, t, e) => Math.min(Math.max(g, t), e), He = (...g) => g.filter((t) => t && typeof t == "string").join(" "), ie = (g, t) => g === t || g.width === t.width && g.height === t.height && g.x === t.x && g.y === t.y && g.unit === t.unit;
|
|
194
|
+
function A(g, t, e) {
|
|
195
|
+
return g.unit === "%" ? { ...V, ...g, unit: "%" } : {
|
|
196
|
+
unit: "%",
|
|
197
|
+
x: g.x ? g.x / t * 100 : 0,
|
|
198
|
+
y: g.y ? g.y / e * 100 : 0,
|
|
199
|
+
width: g.width ? g.width / t * 100 : 0,
|
|
200
|
+
height: g.height ? g.height / e * 100 : 0
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function _(g, t, e) {
|
|
204
|
+
return g.unit ? g.unit === "px" ? { ...V, ...g, unit: "px" } : {
|
|
205
|
+
unit: "px",
|
|
206
|
+
x: g.x ? g.x * t / 100 : 0,
|
|
207
|
+
y: g.y ? g.y * e / 100 : 0,
|
|
208
|
+
width: g.width ? g.width * t / 100 : 0,
|
|
209
|
+
height: g.height ? g.height * e / 100 : 0
|
|
210
|
+
} : { ...V, ...g, unit: "px" };
|
|
211
|
+
}
|
|
212
|
+
function re(g, t, e, o, n, i = 0, h = 0, u = o, s = n) {
|
|
213
|
+
const r = { ...g };
|
|
214
|
+
let a = Math.min(i, o), d = Math.min(h, n), l = Math.min(u, o), c = Math.min(s, n);
|
|
215
|
+
t && (t > 1 ? (a = h ? h * t : a, d = a / t, l = u * t) : (d = i ? i / t : d, a = d * t, c = s / t)), r.y < 0 && (r.height = Math.max(r.height + r.y, d), r.y = 0), r.x < 0 && (r.width = Math.max(r.width + r.x, a), r.x = 0);
|
|
216
|
+
const C = o - (r.x + r.width);
|
|
217
|
+
C < 0 && (r.x = Math.min(r.x, o - a), r.width += C);
|
|
218
|
+
const M = n - (r.y + r.height);
|
|
219
|
+
if (M < 0 && (r.y = Math.min(r.y, n - d), r.height += M), r.width < a && ((e === "sw" || e == "nw") && (r.x -= a - r.width), r.width = a), r.height < d && ((e === "nw" || e == "ne") && (r.y -= d - r.height), r.height = d), r.width > l && ((e === "sw" || e == "nw") && (r.x -= l - r.width), r.width = l), r.height > c && ((e === "nw" || e == "ne") && (r.y -= c - r.height), r.height = c), t) {
|
|
220
|
+
const x = r.width / r.height;
|
|
221
|
+
if (x < t) {
|
|
222
|
+
const z = Math.max(r.width / t, d);
|
|
223
|
+
(e === "nw" || e == "ne") && (r.y -= z - r.height), r.height = z;
|
|
224
|
+
} else if (x > t) {
|
|
225
|
+
const z = Math.max(r.height * t, a);
|
|
226
|
+
(e === "sw" || e == "nw") && (r.x -= z - r.width), r.width = z;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return r;
|
|
230
|
+
}
|
|
231
|
+
function $e(g, t, e, o) {
|
|
232
|
+
const n = { ...g };
|
|
233
|
+
return t === "ArrowLeft" ? o === "nw" ? (n.x -= e, n.y -= e, n.width += e, n.height += e) : o === "w" ? (n.x -= e, n.width += e) : o === "sw" ? (n.x -= e, n.width += e, n.height += e) : o === "ne" ? (n.y += e, n.width -= e, n.height -= e) : o === "e" ? n.width -= e : o === "se" && (n.width -= e, n.height -= e) : t === "ArrowRight" && (o === "nw" ? (n.x += e, n.y += e, n.width -= e, n.height -= e) : o === "w" ? (n.x += e, n.width -= e) : o === "sw" ? (n.x += e, n.width -= e, n.height -= e) : o === "ne" ? (n.y -= e, n.width += e, n.height += e) : o === "e" ? n.width += e : o === "se" && (n.width += e, n.height += e)), t === "ArrowUp" ? o === "nw" ? (n.x -= e, n.y -= e, n.width += e, n.height += e) : o === "n" ? (n.y -= e, n.height += e) : o === "ne" ? (n.y -= e, n.width += e, n.height += e) : o === "sw" ? (n.x += e, n.width -= e, n.height -= e) : o === "s" ? n.height -= e : o === "se" && (n.width -= e, n.height -= e) : t === "ArrowDown" && (o === "nw" ? (n.x += e, n.y += e, n.width -= e, n.height -= e) : o === "n" ? (n.y += e, n.height -= e) : o === "ne" ? (n.y += e, n.width -= e, n.height -= e) : o === "sw" ? (n.x -= e, n.width += e, n.height += e) : o === "s" ? n.height += e : o === "se" && (n.width += e, n.height += e)), n;
|
|
234
|
+
}
|
|
235
|
+
const B = { capture: !0, passive: !1 };
|
|
236
|
+
let ze = 0;
|
|
237
|
+
const X = class S extends Ee {
|
|
238
|
+
constructor() {
|
|
239
|
+
super(...arguments), this.docMoveBound = !1, this.mouseDownOnCrop = !1, this.dragStarted = !1, this.evData = {
|
|
240
|
+
startClientX: 0,
|
|
241
|
+
startClientY: 0,
|
|
242
|
+
startCropX: 0,
|
|
243
|
+
startCropY: 0,
|
|
244
|
+
clientX: 0,
|
|
245
|
+
clientY: 0,
|
|
246
|
+
isResize: !0
|
|
247
|
+
}, this.componentRef = ne(), this.mediaRef = ne(), this.initChangeCalled = !1, this.instanceId = `rc-${ze++}`, this.state = {
|
|
248
|
+
cropIsActive: !1,
|
|
249
|
+
newCropIsBeingDrawn: !1
|
|
250
|
+
}, this.onCropPointerDown = (t) => {
|
|
251
|
+
const { crop: e, disabled: o } = this.props, n = this.getBox();
|
|
252
|
+
if (!e)
|
|
253
|
+
return;
|
|
254
|
+
const i = _(e, n.width, n.height);
|
|
255
|
+
if (o)
|
|
256
|
+
return;
|
|
257
|
+
t.cancelable && t.preventDefault(), this.bindDocMove(), this.componentRef.current.focus({ preventScroll: !0 });
|
|
258
|
+
const h = t.target.dataset.ord, u = !!h;
|
|
259
|
+
let s = t.clientX, r = t.clientY, a = i.x, d = i.y;
|
|
260
|
+
if (h) {
|
|
261
|
+
const l = t.clientX - n.x, c = t.clientY - n.y;
|
|
262
|
+
let C = 0, M = 0;
|
|
263
|
+
h === "ne" || h == "e" ? (C = l - (i.x + i.width), M = c - i.y, a = i.x, d = i.y + i.height) : h === "se" || h === "s" ? (C = l - (i.x + i.width), M = c - (i.y + i.height), a = i.x, d = i.y) : h === "sw" || h == "w" ? (C = l - i.x, M = c - (i.y + i.height), a = i.x + i.width, d = i.y) : (h === "nw" || h == "n") && (C = l - i.x, M = c - i.y, a = i.x + i.width, d = i.y + i.height), s = a + n.x + C, r = d + n.y + M;
|
|
264
|
+
}
|
|
265
|
+
this.evData = {
|
|
266
|
+
startClientX: s,
|
|
267
|
+
startClientY: r,
|
|
268
|
+
startCropX: a,
|
|
269
|
+
startCropY: d,
|
|
270
|
+
clientX: t.clientX,
|
|
271
|
+
clientY: t.clientY,
|
|
272
|
+
isResize: u,
|
|
273
|
+
ord: h
|
|
274
|
+
}, this.mouseDownOnCrop = !0, this.setState({ cropIsActive: !0 });
|
|
275
|
+
}, this.onComponentPointerDown = (t) => {
|
|
276
|
+
const { crop: e, disabled: o, locked: n, keepSelection: i, onChange: h } = this.props, u = this.getBox();
|
|
277
|
+
if (o || n || i && e)
|
|
278
|
+
return;
|
|
279
|
+
t.cancelable && t.preventDefault(), this.bindDocMove(), this.componentRef.current.focus({ preventScroll: !0 });
|
|
280
|
+
const s = t.clientX - u.x, r = t.clientY - u.y, a = {
|
|
281
|
+
unit: "px",
|
|
282
|
+
x: s,
|
|
283
|
+
y: r,
|
|
284
|
+
width: 0,
|
|
285
|
+
height: 0
|
|
286
|
+
};
|
|
287
|
+
this.evData = {
|
|
288
|
+
startClientX: t.clientX,
|
|
289
|
+
startClientY: t.clientY,
|
|
290
|
+
startCropX: s,
|
|
291
|
+
startCropY: r,
|
|
292
|
+
clientX: t.clientX,
|
|
293
|
+
clientY: t.clientY,
|
|
294
|
+
isResize: !0
|
|
295
|
+
}, this.mouseDownOnCrop = !0, h(_(a, u.width, u.height), A(a, u.width, u.height)), this.setState({ cropIsActive: !0, newCropIsBeingDrawn: !0 });
|
|
296
|
+
}, this.onDocPointerMove = (t) => {
|
|
297
|
+
const { crop: e, disabled: o, onChange: n, onDragStart: i } = this.props, h = this.getBox();
|
|
298
|
+
if (o || !e || !this.mouseDownOnCrop)
|
|
299
|
+
return;
|
|
300
|
+
t.cancelable && t.preventDefault(), this.dragStarted || (this.dragStarted = !0, i && i(t));
|
|
301
|
+
const { evData: u } = this;
|
|
302
|
+
u.clientX = t.clientX, u.clientY = t.clientY;
|
|
303
|
+
let s;
|
|
304
|
+
u.isResize ? s = this.resizeCrop() : s = this.dragCrop(), ie(e, s) || n(
|
|
305
|
+
_(s, h.width, h.height),
|
|
306
|
+
A(s, h.width, h.height)
|
|
307
|
+
);
|
|
308
|
+
}, this.onComponentKeyDown = (t) => {
|
|
309
|
+
const { crop: e, disabled: o, onChange: n, onComplete: i } = this.props;
|
|
310
|
+
if (o)
|
|
311
|
+
return;
|
|
312
|
+
const h = t.key;
|
|
313
|
+
let u = !1;
|
|
314
|
+
if (!e)
|
|
315
|
+
return;
|
|
316
|
+
const s = this.getBox(), r = this.makePixelCrop(s), a = (navigator.platform.match("Mac") ? t.metaKey : t.ctrlKey) ? S.nudgeStepLarge : t.shiftKey ? S.nudgeStepMedium : S.nudgeStep;
|
|
317
|
+
if (h === "ArrowLeft" ? (r.x -= a, u = !0) : h === "ArrowRight" ? (r.x += a, u = !0) : h === "ArrowUp" ? (r.y -= a, u = !0) : h === "ArrowDown" && (r.y += a, u = !0), u) {
|
|
318
|
+
t.cancelable && t.preventDefault(), r.x = j(r.x, 0, s.width - r.width), r.y = j(r.y, 0, s.height - r.height);
|
|
319
|
+
const d = _(r, s.width, s.height), l = A(r, s.width, s.height);
|
|
320
|
+
n(d, l), i && i(d, l);
|
|
321
|
+
}
|
|
322
|
+
}, this.onHandlerKeyDown = (t, e) => {
|
|
323
|
+
const {
|
|
324
|
+
aspect: o = 0,
|
|
325
|
+
crop: n,
|
|
326
|
+
disabled: i,
|
|
327
|
+
minWidth: h = 0,
|
|
328
|
+
minHeight: u = 0,
|
|
329
|
+
maxWidth: s,
|
|
330
|
+
maxHeight: r,
|
|
331
|
+
onChange: a,
|
|
332
|
+
onComplete: d
|
|
333
|
+
} = this.props, l = this.getBox();
|
|
334
|
+
if (i || !n)
|
|
335
|
+
return;
|
|
336
|
+
if (t.key === "ArrowUp" || t.key === "ArrowDown" || t.key === "ArrowLeft" || t.key === "ArrowRight")
|
|
337
|
+
t.stopPropagation(), t.preventDefault();
|
|
338
|
+
else
|
|
339
|
+
return;
|
|
340
|
+
const c = (navigator.platform.match("Mac") ? t.metaKey : t.ctrlKey) ? S.nudgeStepLarge : t.shiftKey ? S.nudgeStepMedium : S.nudgeStep, C = _(n, l.width, l.height), M = $e(C, t.key, c, e), x = re(
|
|
341
|
+
M,
|
|
342
|
+
o,
|
|
343
|
+
e,
|
|
344
|
+
l.width,
|
|
345
|
+
l.height,
|
|
346
|
+
h,
|
|
347
|
+
u,
|
|
348
|
+
s,
|
|
349
|
+
r
|
|
350
|
+
);
|
|
351
|
+
if (!ie(n, x)) {
|
|
352
|
+
const z = A(x, l.width, l.height);
|
|
353
|
+
a(x, z), d && d(x, z);
|
|
354
|
+
}
|
|
355
|
+
}, this.onDocPointerDone = (t) => {
|
|
356
|
+
const { crop: e, disabled: o, onComplete: n, onDragEnd: i } = this.props, h = this.getBox();
|
|
357
|
+
this.unbindDocMove(), !(o || !e) && this.mouseDownOnCrop && (this.mouseDownOnCrop = !1, this.dragStarted = !1, i && i(t), n && n(_(e, h.width, h.height), A(e, h.width, h.height)), this.setState({ cropIsActive: !1, newCropIsBeingDrawn: !1 }));
|
|
358
|
+
}, this.onDragFocus = () => {
|
|
359
|
+
var t;
|
|
360
|
+
(t = this.componentRef.current) == null || t.scrollTo(0, 0);
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
get document() {
|
|
364
|
+
return document;
|
|
365
|
+
}
|
|
366
|
+
// We unfortunately get the bounding box every time as x+y changes
|
|
367
|
+
// due to scrolling.
|
|
368
|
+
getBox() {
|
|
369
|
+
const t = this.mediaRef.current;
|
|
370
|
+
if (!t)
|
|
371
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
372
|
+
const { x: e, y: o, width: n, height: i } = t.getBoundingClientRect();
|
|
373
|
+
return { x: e, y: o, width: n, height: i };
|
|
374
|
+
}
|
|
375
|
+
componentDidUpdate(t) {
|
|
376
|
+
const { crop: e, onComplete: o } = this.props;
|
|
377
|
+
if (o && !t.crop && e) {
|
|
378
|
+
const { width: n, height: i } = this.getBox();
|
|
379
|
+
n && i && o(_(e, n, i), A(e, n, i));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
componentWillUnmount() {
|
|
383
|
+
this.resizeObserver && this.resizeObserver.disconnect(), this.unbindDocMove();
|
|
384
|
+
}
|
|
385
|
+
bindDocMove() {
|
|
386
|
+
this.docMoveBound || (this.document.addEventListener("pointermove", this.onDocPointerMove, B), this.document.addEventListener("pointerup", this.onDocPointerDone, B), this.document.addEventListener("pointercancel", this.onDocPointerDone, B), this.docMoveBound = !0);
|
|
387
|
+
}
|
|
388
|
+
unbindDocMove() {
|
|
389
|
+
this.docMoveBound && (this.document.removeEventListener("pointermove", this.onDocPointerMove, B), this.document.removeEventListener("pointerup", this.onDocPointerDone, B), this.document.removeEventListener("pointercancel", this.onDocPointerDone, B), this.docMoveBound = !1);
|
|
390
|
+
}
|
|
391
|
+
getCropStyle() {
|
|
392
|
+
const { crop: t } = this.props;
|
|
393
|
+
if (t)
|
|
394
|
+
return {
|
|
395
|
+
top: `${t.y}${t.unit}`,
|
|
396
|
+
left: `${t.x}${t.unit}`,
|
|
397
|
+
width: `${t.width}${t.unit}`,
|
|
398
|
+
height: `${t.height}${t.unit}`
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
dragCrop() {
|
|
402
|
+
const { evData: t } = this, e = this.getBox(), o = this.makePixelCrop(e), n = t.clientX - t.startClientX, i = t.clientY - t.startClientY;
|
|
403
|
+
return o.x = j(t.startCropX + n, 0, e.width - o.width), o.y = j(t.startCropY + i, 0, e.height - o.height), o;
|
|
404
|
+
}
|
|
405
|
+
getPointRegion(t, e, o, n) {
|
|
406
|
+
const { evData: i } = this, h = i.clientX - t.x, u = i.clientY - t.y;
|
|
407
|
+
let s;
|
|
408
|
+
n && e ? s = e === "nw" || e === "n" || e === "ne" : s = u < i.startCropY;
|
|
409
|
+
let r;
|
|
410
|
+
return o && e ? r = e === "nw" || e === "w" || e === "sw" : r = h < i.startCropX, r ? s ? "nw" : "sw" : s ? "ne" : "se";
|
|
411
|
+
}
|
|
412
|
+
resolveMinDimensions(t, e, o = 0, n = 0) {
|
|
413
|
+
const i = Math.min(o, t.width), h = Math.min(n, t.height);
|
|
414
|
+
return !e || !i && !h ? [i, h] : e > 1 ? i ? [i, i / e] : [h * e, h] : h ? [h * e, h] : [i, i / e];
|
|
415
|
+
}
|
|
416
|
+
resizeCrop() {
|
|
417
|
+
const { evData: t } = this, { aspect: e = 0, maxWidth: o, maxHeight: n } = this.props, i = this.getBox(), [h, u] = this.resolveMinDimensions(i, e, this.props.minWidth, this.props.minHeight);
|
|
418
|
+
let s = this.makePixelCrop(i);
|
|
419
|
+
const r = this.getPointRegion(i, t.ord, h, u), a = t.ord || r;
|
|
420
|
+
let d = t.clientX - t.startClientX, l = t.clientY - t.startClientY;
|
|
421
|
+
(h && a === "nw" || a === "w" || a === "sw") && (d = Math.min(d, -h)), (u && a === "nw" || a === "n" || a === "ne") && (l = Math.min(l, -u));
|
|
422
|
+
const c = {
|
|
423
|
+
unit: "px",
|
|
424
|
+
x: 0,
|
|
425
|
+
y: 0,
|
|
426
|
+
width: 0,
|
|
427
|
+
height: 0
|
|
428
|
+
};
|
|
429
|
+
r === "ne" ? (c.x = t.startCropX, c.width = d, e ? (c.height = c.width / e, c.y = t.startCropY - c.height) : (c.height = Math.abs(l), c.y = t.startCropY - c.height)) : r === "se" ? (c.x = t.startCropX, c.y = t.startCropY, c.width = d, e ? c.height = c.width / e : c.height = l) : r === "sw" ? (c.x = t.startCropX + d, c.y = t.startCropY, c.width = Math.abs(d), e ? c.height = c.width / e : c.height = l) : r === "nw" && (c.x = t.startCropX + d, c.width = Math.abs(d), e ? (c.height = c.width / e, c.y = t.startCropY - c.height) : (c.height = Math.abs(l), c.y = t.startCropY + l));
|
|
430
|
+
const C = re(
|
|
431
|
+
c,
|
|
432
|
+
e,
|
|
433
|
+
r,
|
|
434
|
+
i.width,
|
|
435
|
+
i.height,
|
|
436
|
+
h,
|
|
437
|
+
u,
|
|
438
|
+
o,
|
|
439
|
+
n
|
|
440
|
+
);
|
|
441
|
+
return e || S.xyOrds.indexOf(a) > -1 ? s = C : S.xOrds.indexOf(a) > -1 ? (s.x = C.x, s.width = C.width) : S.yOrds.indexOf(a) > -1 && (s.y = C.y, s.height = C.height), s.x = j(s.x, 0, i.width - s.width), s.y = j(s.y, 0, i.height - s.height), s;
|
|
442
|
+
}
|
|
443
|
+
renderCropSelection() {
|
|
444
|
+
const {
|
|
445
|
+
ariaLabels: t = S.defaultProps.ariaLabels,
|
|
446
|
+
disabled: e,
|
|
447
|
+
locked: o,
|
|
448
|
+
renderSelectionAddon: n,
|
|
449
|
+
ruleOfThirds: i,
|
|
450
|
+
crop: h
|
|
451
|
+
} = this.props, u = this.getCropStyle();
|
|
452
|
+
if (h)
|
|
453
|
+
return /* @__PURE__ */ f.createElement(
|
|
454
|
+
"div",
|
|
455
|
+
{
|
|
456
|
+
style: u,
|
|
457
|
+
className: "ReactCrop__crop-selection",
|
|
458
|
+
onPointerDown: this.onCropPointerDown,
|
|
459
|
+
"aria-label": t.cropArea,
|
|
460
|
+
tabIndex: 0,
|
|
461
|
+
onKeyDown: this.onComponentKeyDown,
|
|
462
|
+
role: "group"
|
|
463
|
+
},
|
|
464
|
+
!e && !o && /* @__PURE__ */ f.createElement("div", { className: "ReactCrop__drag-elements", onFocus: this.onDragFocus }, /* @__PURE__ */ f.createElement("div", { className: "ReactCrop__drag-bar ord-n", "data-ord": "n" }), /* @__PURE__ */ f.createElement("div", { className: "ReactCrop__drag-bar ord-e", "data-ord": "e" }), /* @__PURE__ */ f.createElement("div", { className: "ReactCrop__drag-bar ord-s", "data-ord": "s" }), /* @__PURE__ */ f.createElement("div", { className: "ReactCrop__drag-bar ord-w", "data-ord": "w" }), /* @__PURE__ */ f.createElement(
|
|
465
|
+
"div",
|
|
466
|
+
{
|
|
467
|
+
className: "ReactCrop__drag-handle ord-nw",
|
|
468
|
+
"data-ord": "nw",
|
|
469
|
+
tabIndex: 0,
|
|
470
|
+
"aria-label": t.nwDragHandle,
|
|
471
|
+
onKeyDown: (s) => this.onHandlerKeyDown(s, "nw"),
|
|
472
|
+
role: "button"
|
|
473
|
+
}
|
|
474
|
+
), /* @__PURE__ */ f.createElement(
|
|
475
|
+
"div",
|
|
476
|
+
{
|
|
477
|
+
className: "ReactCrop__drag-handle ord-n",
|
|
478
|
+
"data-ord": "n",
|
|
479
|
+
tabIndex: 0,
|
|
480
|
+
"aria-label": t.nDragHandle,
|
|
481
|
+
onKeyDown: (s) => this.onHandlerKeyDown(s, "n"),
|
|
482
|
+
role: "button"
|
|
483
|
+
}
|
|
484
|
+
), /* @__PURE__ */ f.createElement(
|
|
485
|
+
"div",
|
|
486
|
+
{
|
|
487
|
+
className: "ReactCrop__drag-handle ord-ne",
|
|
488
|
+
"data-ord": "ne",
|
|
489
|
+
tabIndex: 0,
|
|
490
|
+
"aria-label": t.neDragHandle,
|
|
491
|
+
onKeyDown: (s) => this.onHandlerKeyDown(s, "ne"),
|
|
492
|
+
role: "button"
|
|
493
|
+
}
|
|
494
|
+
), /* @__PURE__ */ f.createElement(
|
|
495
|
+
"div",
|
|
496
|
+
{
|
|
497
|
+
className: "ReactCrop__drag-handle ord-e",
|
|
498
|
+
"data-ord": "e",
|
|
499
|
+
tabIndex: 0,
|
|
500
|
+
"aria-label": t.eDragHandle,
|
|
501
|
+
onKeyDown: (s) => this.onHandlerKeyDown(s, "e"),
|
|
502
|
+
role: "button"
|
|
503
|
+
}
|
|
504
|
+
), /* @__PURE__ */ f.createElement(
|
|
505
|
+
"div",
|
|
506
|
+
{
|
|
507
|
+
className: "ReactCrop__drag-handle ord-se",
|
|
508
|
+
"data-ord": "se",
|
|
509
|
+
tabIndex: 0,
|
|
510
|
+
"aria-label": t.seDragHandle,
|
|
511
|
+
onKeyDown: (s) => this.onHandlerKeyDown(s, "se"),
|
|
512
|
+
role: "button"
|
|
513
|
+
}
|
|
514
|
+
), /* @__PURE__ */ f.createElement(
|
|
515
|
+
"div",
|
|
516
|
+
{
|
|
517
|
+
className: "ReactCrop__drag-handle ord-s",
|
|
518
|
+
"data-ord": "s",
|
|
519
|
+
tabIndex: 0,
|
|
520
|
+
"aria-label": t.sDragHandle,
|
|
521
|
+
onKeyDown: (s) => this.onHandlerKeyDown(s, "s"),
|
|
522
|
+
role: "button"
|
|
523
|
+
}
|
|
524
|
+
), /* @__PURE__ */ f.createElement(
|
|
525
|
+
"div",
|
|
526
|
+
{
|
|
527
|
+
className: "ReactCrop__drag-handle ord-sw",
|
|
528
|
+
"data-ord": "sw",
|
|
529
|
+
tabIndex: 0,
|
|
530
|
+
"aria-label": t.swDragHandle,
|
|
531
|
+
onKeyDown: (s) => this.onHandlerKeyDown(s, "sw"),
|
|
532
|
+
role: "button"
|
|
533
|
+
}
|
|
534
|
+
), /* @__PURE__ */ f.createElement(
|
|
535
|
+
"div",
|
|
536
|
+
{
|
|
537
|
+
className: "ReactCrop__drag-handle ord-w",
|
|
538
|
+
"data-ord": "w",
|
|
539
|
+
tabIndex: 0,
|
|
540
|
+
"aria-label": t.wDragHandle,
|
|
541
|
+
onKeyDown: (s) => this.onHandlerKeyDown(s, "w"),
|
|
542
|
+
role: "button"
|
|
543
|
+
}
|
|
544
|
+
)),
|
|
545
|
+
n && /* @__PURE__ */ f.createElement("div", { className: "ReactCrop__selection-addon", onPointerDown: (s) => s.stopPropagation() }, n(this.state)),
|
|
546
|
+
i && /* @__PURE__ */ f.createElement(f.Fragment, null, /* @__PURE__ */ f.createElement("div", { className: "ReactCrop__rule-of-thirds-hz" }), /* @__PURE__ */ f.createElement("div", { className: "ReactCrop__rule-of-thirds-vt" }))
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
makePixelCrop(t) {
|
|
550
|
+
const e = { ...V, ...this.props.crop || {} };
|
|
551
|
+
return _(e, t.width, t.height);
|
|
552
|
+
}
|
|
553
|
+
render() {
|
|
554
|
+
const { aspect: t, children: e, circularCrop: o, className: n, crop: i, disabled: h, locked: u, style: s, ruleOfThirds: r } = this.props, { cropIsActive: a, newCropIsBeingDrawn: d } = this.state, l = i ? this.renderCropSelection() : null, c = He(
|
|
555
|
+
"ReactCrop",
|
|
556
|
+
n,
|
|
557
|
+
a && "ReactCrop--active",
|
|
558
|
+
h && "ReactCrop--disabled",
|
|
559
|
+
u && "ReactCrop--locked",
|
|
560
|
+
d && "ReactCrop--new-crop",
|
|
561
|
+
i && t && "ReactCrop--fixed-aspect",
|
|
562
|
+
i && o && "ReactCrop--circular-crop",
|
|
563
|
+
i && r && "ReactCrop--rule-of-thirds",
|
|
564
|
+
!this.dragStarted && i && !i.width && !i.height && "ReactCrop--invisible-crop",
|
|
565
|
+
o && "ReactCrop--no-animate"
|
|
566
|
+
);
|
|
567
|
+
return /* @__PURE__ */ f.createElement("div", { ref: this.componentRef, className: c, style: s }, /* @__PURE__ */ f.createElement("div", { ref: this.mediaRef, className: "ReactCrop__child-wrapper", onPointerDown: this.onComponentPointerDown }, e), i ? /* @__PURE__ */ f.createElement("svg", { className: "ReactCrop__crop-mask", width: "100%", height: "100%" }, /* @__PURE__ */ f.createElement("defs", null, /* @__PURE__ */ f.createElement("mask", { id: `hole-${this.instanceId}` }, /* @__PURE__ */ f.createElement("rect", { width: "100%", height: "100%", fill: "white" }), o ? /* @__PURE__ */ f.createElement(
|
|
568
|
+
"ellipse",
|
|
569
|
+
{
|
|
570
|
+
cx: `${i.x + i.width / 2}${i.unit}`,
|
|
571
|
+
cy: `${i.y + i.height / 2}${i.unit}`,
|
|
572
|
+
rx: `${i.width / 2}${i.unit}`,
|
|
573
|
+
ry: `${i.height / 2}${i.unit}`,
|
|
574
|
+
fill: "black"
|
|
575
|
+
}
|
|
576
|
+
) : /* @__PURE__ */ f.createElement(
|
|
577
|
+
"rect",
|
|
578
|
+
{
|
|
579
|
+
x: `${i.x}${i.unit}`,
|
|
580
|
+
y: `${i.y}${i.unit}`,
|
|
581
|
+
width: `${i.width}${i.unit}`,
|
|
582
|
+
height: `${i.height}${i.unit}`,
|
|
583
|
+
fill: "black"
|
|
584
|
+
}
|
|
585
|
+
))), /* @__PURE__ */ f.createElement("rect", { fill: "black", fillOpacity: 0.5, width: "100%", height: "100%", mask: `url(#hole-${this.instanceId})` })) : void 0, l);
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
X.xOrds = ["e", "w"], X.yOrds = ["n", "s"], X.xyOrds = ["nw", "ne", "se", "sw"], X.nudgeStep = 1, X.nudgeStepMedium = 10, X.nudgeStepLarge = 100, X.defaultProps = {
|
|
589
|
+
ariaLabels: {
|
|
590
|
+
cropArea: "Use the arrow keys to move the crop selection area",
|
|
591
|
+
nwDragHandle: "Use the arrow keys to move the north west drag handle to change the crop selection area",
|
|
592
|
+
nDragHandle: "Use the up and down arrow keys to move the north drag handle to change the crop selection area",
|
|
593
|
+
neDragHandle: "Use the arrow keys to move the north east drag handle to change the crop selection area",
|
|
594
|
+
eDragHandle: "Use the up and down arrow keys to move the east drag handle to change the crop selection area",
|
|
595
|
+
seDragHandle: "Use the arrow keys to move the south east drag handle to change the crop selection area",
|
|
596
|
+
sDragHandle: "Use the up and down arrow keys to move the south drag handle to change the crop selection area",
|
|
597
|
+
swDragHandle: "Use the arrow keys to move the south west drag handle to change the crop selection area",
|
|
598
|
+
wDragHandle: "Use the up and down arrow keys to move the west drag handle to change the crop selection area"
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
let Ne = X;
|
|
602
|
+
const oe = Ce();
|
|
603
|
+
function ke({
|
|
604
|
+
altText: g,
|
|
605
|
+
className: t,
|
|
606
|
+
src: e,
|
|
607
|
+
width: o,
|
|
608
|
+
height: n,
|
|
609
|
+
maxWidth: i,
|
|
610
|
+
imageRef: h,
|
|
611
|
+
startCrop: u,
|
|
612
|
+
setStartCrop: s,
|
|
613
|
+
isFocused: r
|
|
614
|
+
}) {
|
|
615
|
+
const [a, d] = O(null), [l, c] = O(null), [C, M] = O({
|
|
616
|
+
//@ts-ignore
|
|
617
|
+
aspect: 1,
|
|
618
|
+
x: 0,
|
|
619
|
+
y: 0,
|
|
620
|
+
width: 100,
|
|
621
|
+
height: 100
|
|
622
|
+
}), x = () => {
|
|
623
|
+
if (a) {
|
|
624
|
+
const R = h.current;
|
|
625
|
+
if (!R || !a)
|
|
626
|
+
return;
|
|
627
|
+
const p = R.naturalWidth / R.width, w = R.naturalHeight / R.height, m = new OffscreenCanvas(
|
|
628
|
+
a.width * p,
|
|
629
|
+
a.height * w
|
|
630
|
+
), N = m.getContext("2d");
|
|
631
|
+
if (!N)
|
|
632
|
+
throw new Error("No 2D context available");
|
|
633
|
+
N.drawImage(
|
|
634
|
+
R,
|
|
635
|
+
a.x * p,
|
|
636
|
+
a.y * w,
|
|
637
|
+
a.width * p,
|
|
638
|
+
a.height * w,
|
|
639
|
+
0,
|
|
640
|
+
0,
|
|
641
|
+
a.width * p,
|
|
642
|
+
a.height * w
|
|
643
|
+
), m.convertToBlob({ type: "image/png" }).then(($) => {
|
|
644
|
+
const D = URL.createObjectURL($);
|
|
645
|
+
c(D), s(!1);
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
}, z = () => {
|
|
649
|
+
u || s((R) => (R === !1 && M({ aspect: 1, x: 0, y: 0, width: 100, height: 100 }), !R));
|
|
650
|
+
}, W = Y(null), H = Y(null);
|
|
651
|
+
ee(() => {
|
|
652
|
+
a && (W.current = a);
|
|
653
|
+
}, [a]);
|
|
654
|
+
const L = (R) => {
|
|
655
|
+
H.current && !H.current.contains(R.target) && s(!1);
|
|
656
|
+
};
|
|
657
|
+
return ee(() => (document.addEventListener("mousedown", L), () => {
|
|
658
|
+
document.removeEventListener("mousedown", L);
|
|
659
|
+
}), []), /* @__PURE__ */ v.jsxs("div", { ref: H, children: [
|
|
660
|
+
r && /* @__PURE__ */ v.jsx(
|
|
661
|
+
"button",
|
|
662
|
+
{
|
|
663
|
+
style: { zIndex: 999 },
|
|
664
|
+
className: "image-caption-button",
|
|
665
|
+
onClick: () => z(),
|
|
666
|
+
children: "Crop"
|
|
667
|
+
}
|
|
668
|
+
),
|
|
669
|
+
u && /* @__PURE__ */ v.jsx(
|
|
670
|
+
"button",
|
|
671
|
+
{
|
|
672
|
+
style: { zIndex: 999 },
|
|
673
|
+
className: "image-caption-button",
|
|
674
|
+
onClick: () => x(),
|
|
675
|
+
children: "Apply Crop"
|
|
676
|
+
}
|
|
677
|
+
),
|
|
678
|
+
u ? /* @__PURE__ */ v.jsx(
|
|
679
|
+
Ne,
|
|
680
|
+
{
|
|
681
|
+
crop: C,
|
|
682
|
+
onChange: (R) => M(R),
|
|
683
|
+
onComplete: (R) => d(R),
|
|
684
|
+
children: /* @__PURE__ */ v.jsx(
|
|
685
|
+
"img",
|
|
686
|
+
{
|
|
687
|
+
className: t || void 0,
|
|
688
|
+
src: l || e,
|
|
689
|
+
alt: g,
|
|
690
|
+
ref: h,
|
|
691
|
+
style: {
|
|
692
|
+
height: n,
|
|
693
|
+
maxWidth: i,
|
|
694
|
+
width: o
|
|
695
|
+
},
|
|
696
|
+
draggable: "false"
|
|
697
|
+
}
|
|
698
|
+
)
|
|
699
|
+
}
|
|
700
|
+
) : (
|
|
701
|
+
// When startCrop is false, show the cropped image or original image
|
|
702
|
+
/* @__PURE__ */ v.jsx(
|
|
703
|
+
"img",
|
|
704
|
+
{
|
|
705
|
+
className: t || void 0,
|
|
706
|
+
src: l || e,
|
|
707
|
+
alt: g,
|
|
708
|
+
ref: h,
|
|
709
|
+
style: {
|
|
710
|
+
height: n,
|
|
711
|
+
maxWidth: i,
|
|
712
|
+
width: o
|
|
713
|
+
},
|
|
714
|
+
draggable: "false"
|
|
715
|
+
}
|
|
716
|
+
)
|
|
717
|
+
)
|
|
718
|
+
] });
|
|
719
|
+
}
|
|
720
|
+
function Ye({
|
|
721
|
+
src: g,
|
|
722
|
+
altText: t,
|
|
723
|
+
nodeKey: e,
|
|
724
|
+
width: o,
|
|
725
|
+
height: n,
|
|
726
|
+
maxWidth: i,
|
|
727
|
+
resizable: h,
|
|
728
|
+
showCaption: u,
|
|
729
|
+
caption: s
|
|
730
|
+
}) {
|
|
731
|
+
const r = Y(null), a = Y(null), [d, l, c] = ve(e), [C, M] = O(!1), [x] = he(), [z, W] = O(null), [H, L] = O(!1), R = Y(null), p = F(
|
|
732
|
+
(P) => {
|
|
733
|
+
if (d && U(G())) {
|
|
734
|
+
P.preventDefault();
|
|
735
|
+
const k = J(e);
|
|
736
|
+
if (Q(k))
|
|
737
|
+
return k.remove(), !0;
|
|
738
|
+
}
|
|
739
|
+
return !1;
|
|
740
|
+
},
|
|
741
|
+
[d, e]
|
|
742
|
+
), w = F(
|
|
743
|
+
(P) => {
|
|
744
|
+
const E = G(), k = a.current;
|
|
745
|
+
if (d && U(E) && E.getNodes().length === 1) {
|
|
746
|
+
if (u)
|
|
747
|
+
return te(null), P.preventDefault(), s.focus(), !0;
|
|
748
|
+
if (k !== null && k !== document.activeElement)
|
|
749
|
+
return P.preventDefault(), k.focus(), !0;
|
|
750
|
+
}
|
|
751
|
+
return !1;
|
|
752
|
+
},
|
|
753
|
+
[s, d, u]
|
|
754
|
+
), m = F(
|
|
755
|
+
(P) => R.current === s || a.current === P.target ? (te(null), x.update(() => {
|
|
756
|
+
l(!0);
|
|
757
|
+
const E = x.getRootElement();
|
|
758
|
+
E !== null && E.focus();
|
|
759
|
+
}), !0) : !1,
|
|
760
|
+
[s, x, l]
|
|
761
|
+
), N = F(
|
|
762
|
+
(P) => {
|
|
763
|
+
const E = P;
|
|
764
|
+
return C ? !0 : E.target === r.current ? (E.shiftKey ? l(!d) : (c(), l(!0)), !0) : !1;
|
|
765
|
+
},
|
|
766
|
+
[C, d, l, c]
|
|
767
|
+
), $ = F(
|
|
768
|
+
(P) => {
|
|
769
|
+
x.getEditorState().read(() => {
|
|
770
|
+
const E = G();
|
|
771
|
+
P.target.tagName === "IMG" && ce(E) && E.getNodes().length === 1 && x.dispatchCommand(
|
|
772
|
+
oe,
|
|
773
|
+
P
|
|
774
|
+
);
|
|
775
|
+
});
|
|
776
|
+
},
|
|
777
|
+
[x]
|
|
778
|
+
);
|
|
779
|
+
ee(() => {
|
|
780
|
+
let P = !0;
|
|
781
|
+
const E = x.getRootElement(), k = de(
|
|
782
|
+
x.registerUpdateListener(({ editorState: K }) => {
|
|
783
|
+
P && W(K.read(() => G()));
|
|
784
|
+
}),
|
|
785
|
+
x.registerCommand(
|
|
786
|
+
xe,
|
|
787
|
+
(K, ae) => (R.current = ae, !1),
|
|
788
|
+
I
|
|
789
|
+
),
|
|
790
|
+
x.registerCommand(
|
|
791
|
+
me,
|
|
792
|
+
N,
|
|
793
|
+
I
|
|
794
|
+
),
|
|
795
|
+
x.registerCommand(
|
|
796
|
+
oe,
|
|
797
|
+
N,
|
|
798
|
+
I
|
|
799
|
+
),
|
|
800
|
+
x.registerCommand(
|
|
801
|
+
we,
|
|
802
|
+
(K) => K.target === r.current ? (K.preventDefault(), !0) : !1,
|
|
803
|
+
I
|
|
804
|
+
),
|
|
805
|
+
x.registerCommand(
|
|
806
|
+
pe,
|
|
807
|
+
p,
|
|
808
|
+
I
|
|
809
|
+
),
|
|
810
|
+
x.registerCommand(
|
|
811
|
+
ue,
|
|
812
|
+
p,
|
|
813
|
+
I
|
|
814
|
+
),
|
|
815
|
+
x.registerCommand(ge, w, I),
|
|
816
|
+
x.registerCommand(le, m, I)
|
|
817
|
+
);
|
|
818
|
+
return E == null || E.addEventListener("contextmenu", $), () => {
|
|
819
|
+
P = !1, k(), E == null || E.removeEventListener("contextmenu", $);
|
|
820
|
+
};
|
|
821
|
+
}, [
|
|
822
|
+
c,
|
|
823
|
+
x,
|
|
824
|
+
C,
|
|
825
|
+
d,
|
|
826
|
+
e,
|
|
827
|
+
p,
|
|
828
|
+
w,
|
|
829
|
+
m,
|
|
830
|
+
N,
|
|
831
|
+
$,
|
|
832
|
+
l
|
|
833
|
+
]);
|
|
834
|
+
const D = () => {
|
|
835
|
+
x.update(() => {
|
|
836
|
+
const P = J(e);
|
|
837
|
+
Q(P) && P.setShowCaption(!0);
|
|
838
|
+
});
|
|
839
|
+
}, b = (P, E) => {
|
|
840
|
+
setTimeout(() => {
|
|
841
|
+
M(!1);
|
|
842
|
+
}, 200), x.update(() => {
|
|
843
|
+
const k = J(e);
|
|
844
|
+
Q(k) && k.setWidthAndHeight(P, E);
|
|
845
|
+
});
|
|
846
|
+
}, T = () => {
|
|
847
|
+
H || M(!0);
|
|
848
|
+
}, se = d && U(z) && !C, q = d || C;
|
|
849
|
+
return /* @__PURE__ */ v.jsx(Me, { fallback: null, children: /* @__PURE__ */ v.jsxs(v.Fragment, { children: [
|
|
850
|
+
/* @__PURE__ */ v.jsx("div", { draggable: se, children: /* @__PURE__ */ v.jsx(
|
|
851
|
+
ke,
|
|
852
|
+
{
|
|
853
|
+
className: q ? `focused ${U(z) ? "draggable" : ""}` : null,
|
|
854
|
+
src: g,
|
|
855
|
+
altText: t,
|
|
856
|
+
width: o,
|
|
857
|
+
height: n,
|
|
858
|
+
maxWidth: i,
|
|
859
|
+
imageRef: r,
|
|
860
|
+
startCrop: H,
|
|
861
|
+
setStartCrop: L,
|
|
862
|
+
isFocused: q
|
|
863
|
+
}
|
|
864
|
+
) }),
|
|
865
|
+
u && /* @__PURE__ */ v.jsx("div", { className: "image-caption-container", children: /* @__PURE__ */ v.jsx(De, { initialEditor: s, children: /* @__PURE__ */ v.jsx(
|
|
866
|
+
fe,
|
|
867
|
+
{
|
|
868
|
+
contentEditable: /* @__PURE__ */ v.jsx(be, { className: "ImageNode__contentEditable" }),
|
|
869
|
+
placeholder: /* @__PURE__ */ v.jsx(Re, { className: "ImageNode__placeholder", children: "Enter a caption..." }),
|
|
870
|
+
ErrorBoundary: ye
|
|
871
|
+
}
|
|
872
|
+
) }) }),
|
|
873
|
+
!H && h && U(z) && q && /* @__PURE__ */ v.jsx(
|
|
874
|
+
Pe,
|
|
875
|
+
{
|
|
876
|
+
showCaption: u,
|
|
877
|
+
setShowCaption: D,
|
|
878
|
+
editor: x,
|
|
879
|
+
buttonRef: a,
|
|
880
|
+
maxWidth: i,
|
|
881
|
+
onResizeStart: H ? () => {
|
|
882
|
+
} : T,
|
|
883
|
+
onResizeEnd: H ? () => {
|
|
884
|
+
} : b,
|
|
885
|
+
captionsEnabled: !1,
|
|
886
|
+
imageRef: r
|
|
887
|
+
}
|
|
888
|
+
)
|
|
889
|
+
] }) });
|
|
890
|
+
}
|
|
891
|
+
export {
|
|
892
|
+
oe as RIGHT_CLICK_IMAGE_COMMAND,
|
|
893
|
+
Ye as default
|
|
894
|
+
};
|
|
895
|
+
//# sourceMappingURL=ImageComponent-d523586d.js.map
|