sykpcomposer 1.19.78 → 1.19.79
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-16bda209.js +933 -0
- package/dist/ImageComponent-16bda209.js.map +1 -0
- package/dist/{InlineImageComponent-faa53bd0.js → InlineImageComponent-5656f011.js} +3 -3
- package/dist/{InlineImageComponent-faa53bd0.js.map → InlineImageComponent-5656f011.js.map} +1 -1
- package/dist/{LexicalNestedComposer.prod-96d2d62e.js → LexicalNestedComposer.prod-ad2829c0.js} +2 -2
- package/dist/{LexicalNestedComposer.prod-96d2d62e.js.map → LexicalNestedComposer.prod-ad2829c0.js.map} +1 -1
- package/dist/{PollComponent-7363f2ab.js → PollComponent-e54def31.js} +2 -2
- package/dist/{PollComponent-7363f2ab.js.map → PollComponent-e54def31.js.map} +1 -1
- package/dist/{index-26eecbcf.js → index-bbfc5e64.js} +42 -40
- package/dist/index-bbfc5e64.js.map +1 -0
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +80 -80
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/dist/ImageComponent-edf96681.js +0 -924
- package/dist/ImageComponent-edf96681.js.map +0 -1
- package/dist/index-26eecbcf.js.map +0 -1
|
@@ -0,0 +1,933 @@
|
|
|
1
|
+
import { j as R, u as ce, a as se, x as F, $ as T, w as Z, d as V, b as te, c as de, e as le, f as ge, C as A, g as ue, k as pe, h as we, I as me, r as fe, i as ye, l as xe, L as Ce, P as ve, m as De, t as be } from "./index-bbfc5e64.js";
|
|
2
|
+
import { d as Re } from "./LexicalNestedComposer.prod-ad2829c0.js";
|
|
3
|
+
import x, { useRef as Y, PureComponent as Ee, createRef as ne, useState as G, useCallback as U, useEffect as q, Suspense as Me } from "react";
|
|
4
|
+
import "react-dom";
|
|
5
|
+
function ee(l, t, e) {
|
|
6
|
+
return Math.min(Math.max(l, t), e);
|
|
7
|
+
}
|
|
8
|
+
const v = {
|
|
9
|
+
east: 1,
|
|
10
|
+
north: 8,
|
|
11
|
+
south: 2,
|
|
12
|
+
west: 4
|
|
13
|
+
};
|
|
14
|
+
function Pe({
|
|
15
|
+
onResizeStart: l,
|
|
16
|
+
onResizeEnd: t,
|
|
17
|
+
buttonRef: e,
|
|
18
|
+
imageRef: o,
|
|
19
|
+
maxWidth: n,
|
|
20
|
+
editor: r,
|
|
21
|
+
showCaption: h,
|
|
22
|
+
setShowCaption: p,
|
|
23
|
+
captionsEnabled: s
|
|
24
|
+
}) {
|
|
25
|
+
const i = Y(null), d = Y({
|
|
26
|
+
priority: "",
|
|
27
|
+
value: "default"
|
|
28
|
+
}), a = 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
|
+
}), g = r.getRootElement(), c = g !== null ? g.getBoundingClientRect().width - 20 : 100, C = g !== null ? g.getBoundingClientRect().height - 20 : 100, P = 100, w = 100, N = (u) => {
|
|
39
|
+
const m = u === v.east || u === v.west, f = u === v.north || u === v.south, $ = u & v.north && u & v.west || u & v.south && u & v.east, H = m ? "ew" : f ? "ns" : $ ? "nwse" : "nesw";
|
|
40
|
+
g !== null && g.style.setProperty(
|
|
41
|
+
"cursor",
|
|
42
|
+
`${H}-resize`,
|
|
43
|
+
"important"
|
|
44
|
+
), document.body !== null && (document.body.style.setProperty(
|
|
45
|
+
"cursor",
|
|
46
|
+
`${H}-resize`,
|
|
47
|
+
"important"
|
|
48
|
+
), d.current.value = document.body.style.getPropertyValue(
|
|
49
|
+
"-webkit-user-select"
|
|
50
|
+
), d.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
|
+
}, K = () => {
|
|
58
|
+
g !== null && g.style.setProperty("cursor", "text"), document.body !== null && (document.body.style.setProperty("cursor", "default"), document.body.style.setProperty(
|
|
59
|
+
"-webkit-user-select",
|
|
60
|
+
d.current.value,
|
|
61
|
+
d.current.priority
|
|
62
|
+
));
|
|
63
|
+
}, k = (u, m) => {
|
|
64
|
+
if (!r.isEditable())
|
|
65
|
+
return;
|
|
66
|
+
const f = o.current, $ = i.current;
|
|
67
|
+
if (f !== null && $ !== null) {
|
|
68
|
+
u.preventDefault();
|
|
69
|
+
const { width: H, height: D } = f.getBoundingClientRect(), b = a.current;
|
|
70
|
+
b.startWidth = H, b.startHeight = D, b.ratio = H / D, b.currentWidth = H, b.currentHeight = D, b.startX = u.clientX, b.startY = u.clientY, b.isResizing = !0, b.direction = m, N(m), l(), $.classList.add("image-control-wrapper--resizing"), f.style.height = `${D}px`, f.style.width = `${H}px`, document.addEventListener("pointermove", L), document.addEventListener("pointerup", M);
|
|
71
|
+
}
|
|
72
|
+
}, L = (u) => {
|
|
73
|
+
const m = o.current, f = a.current, $ = f.direction & (v.east | v.west), H = f.direction & (v.south | v.north);
|
|
74
|
+
if (m !== null && f.isResizing) {
|
|
75
|
+
if ($ && H) {
|
|
76
|
+
let D = Math.floor(f.startX - u.clientX);
|
|
77
|
+
D = f.direction & v.east ? -D : D;
|
|
78
|
+
const b = ee(
|
|
79
|
+
f.startWidth + D,
|
|
80
|
+
P,
|
|
81
|
+
c
|
|
82
|
+
), j = b / f.ratio;
|
|
83
|
+
m.style.width = `${b}px`, m.style.height = `${j}px`, f.currentHeight = j, f.currentWidth = b;
|
|
84
|
+
} else if (H) {
|
|
85
|
+
let D = Math.floor(f.startY - u.clientY);
|
|
86
|
+
D = f.direction & v.south ? -D : D;
|
|
87
|
+
const b = ee(
|
|
88
|
+
f.startHeight + D,
|
|
89
|
+
w,
|
|
90
|
+
C
|
|
91
|
+
);
|
|
92
|
+
m.style.height = `${b}px`, m.style.maxHeight = `${b}px`, f.currentHeight = b;
|
|
93
|
+
} else {
|
|
94
|
+
let D = Math.floor(f.startX - u.clientX);
|
|
95
|
+
D = f.direction & v.east ? -D : D;
|
|
96
|
+
const b = ee(
|
|
97
|
+
f.startWidth + D,
|
|
98
|
+
P,
|
|
99
|
+
c
|
|
100
|
+
);
|
|
101
|
+
m.style.width = `${b}px`, m.style.maxWidth = `${b}px`, f.currentWidth = b;
|
|
102
|
+
}
|
|
103
|
+
m && (m.setAttribute("width", `${f.currentWidth}`), m.setAttribute("height", `${f.currentHeight}`));
|
|
104
|
+
}
|
|
105
|
+
}, M = () => {
|
|
106
|
+
const u = o.current, m = a.current, f = i.current;
|
|
107
|
+
if (u !== null && f !== null && m.isResizing) {
|
|
108
|
+
const $ = m.currentWidth, H = m.currentHeight;
|
|
109
|
+
m.startWidth = 0, m.startHeight = 0, m.ratio = 0, m.startX = 0, m.startY = 0, m.currentWidth = 0, m.currentHeight = 0, m.isResizing = !1, f.classList.remove("image-control-wrapper--resizing"), K(), t($, H), document.removeEventListener("pointermove", L), document.removeEventListener("pointerup", M);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
return /* @__PURE__ */ R.jsxs("div", { ref: i, children: [
|
|
113
|
+
/* @__PURE__ */ R.jsx(
|
|
114
|
+
"div",
|
|
115
|
+
{
|
|
116
|
+
className: "image-resizer image-resizer-n",
|
|
117
|
+
onPointerDown: (u) => {
|
|
118
|
+
k(u, v.north);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
),
|
|
122
|
+
/* @__PURE__ */ R.jsx(
|
|
123
|
+
"div",
|
|
124
|
+
{
|
|
125
|
+
className: "image-resizer image-resizer-ne",
|
|
126
|
+
onPointerDown: (u) => {
|
|
127
|
+
k(u, v.north | v.east);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
),
|
|
131
|
+
/* @__PURE__ */ R.jsx(
|
|
132
|
+
"div",
|
|
133
|
+
{
|
|
134
|
+
className: "image-resizer image-resizer-e",
|
|
135
|
+
onPointerDown: (u) => {
|
|
136
|
+
k(u, v.east);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
),
|
|
140
|
+
/* @__PURE__ */ R.jsx(
|
|
141
|
+
"div",
|
|
142
|
+
{
|
|
143
|
+
className: "image-resizer image-resizer-se",
|
|
144
|
+
onPointerDown: (u) => {
|
|
145
|
+
k(u, v.south | v.east);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
),
|
|
149
|
+
/* @__PURE__ */ R.jsx(
|
|
150
|
+
"div",
|
|
151
|
+
{
|
|
152
|
+
className: "image-resizer image-resizer-s",
|
|
153
|
+
onPointerDown: (u) => {
|
|
154
|
+
k(u, v.south);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
),
|
|
158
|
+
/* @__PURE__ */ R.jsx(
|
|
159
|
+
"div",
|
|
160
|
+
{
|
|
161
|
+
className: "image-resizer image-resizer-sw",
|
|
162
|
+
onPointerDown: (u) => {
|
|
163
|
+
k(u, v.south | v.west);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
),
|
|
167
|
+
/* @__PURE__ */ R.jsx(
|
|
168
|
+
"div",
|
|
169
|
+
{
|
|
170
|
+
className: "image-resizer image-resizer-w",
|
|
171
|
+
onPointerDown: (u) => {
|
|
172
|
+
k(u, v.west);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
),
|
|
176
|
+
/* @__PURE__ */ R.jsx(
|
|
177
|
+
"div",
|
|
178
|
+
{
|
|
179
|
+
className: "image-resizer image-resizer-nw",
|
|
180
|
+
onPointerDown: (u) => {
|
|
181
|
+
k(u, v.north | v.west);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
)
|
|
185
|
+
] });
|
|
186
|
+
}
|
|
187
|
+
const J = {
|
|
188
|
+
x: 0,
|
|
189
|
+
y: 0,
|
|
190
|
+
width: 0,
|
|
191
|
+
height: 0,
|
|
192
|
+
unit: "px"
|
|
193
|
+
}, B = (l, t, e) => Math.min(Math.max(l, t), e), ke = (...l) => l.filter((t) => t && typeof t == "string").join(" "), re = (l, t) => l === t || l.width === t.width && l.height === t.height && l.x === t.x && l.y === t.y && l.unit === t.unit;
|
|
194
|
+
function O(l, t, e) {
|
|
195
|
+
return l.unit === "%" ? { ...J, ...l, unit: "%" } : {
|
|
196
|
+
unit: "%",
|
|
197
|
+
x: l.x ? l.x / t * 100 : 0,
|
|
198
|
+
y: l.y ? l.y / e * 100 : 0,
|
|
199
|
+
width: l.width ? l.width / t * 100 : 0,
|
|
200
|
+
height: l.height ? l.height / e * 100 : 0
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function I(l, t, e) {
|
|
204
|
+
return l.unit ? l.unit === "px" ? { ...J, ...l, unit: "px" } : {
|
|
205
|
+
unit: "px",
|
|
206
|
+
x: l.x ? l.x * t / 100 : 0,
|
|
207
|
+
y: l.y ? l.y * e / 100 : 0,
|
|
208
|
+
width: l.width ? l.width * t / 100 : 0,
|
|
209
|
+
height: l.height ? l.height * e / 100 : 0
|
|
210
|
+
} : { ...J, ...l, unit: "px" };
|
|
211
|
+
}
|
|
212
|
+
function ie(l, t, e, o, n, r = 0, h = 0, p = o, s = n) {
|
|
213
|
+
const i = { ...l };
|
|
214
|
+
let d = Math.min(r, o), a = Math.min(h, n), g = Math.min(p, o), c = Math.min(s, n);
|
|
215
|
+
t && (t > 1 ? (d = h ? h * t : d, a = d / t, g = p * t) : (a = r ? r / t : a, d = a * t, c = s / t)), i.y < 0 && (i.height = Math.max(i.height + i.y, a), i.y = 0), i.x < 0 && (i.width = Math.max(i.width + i.x, d), i.x = 0);
|
|
216
|
+
const C = o - (i.x + i.width);
|
|
217
|
+
C < 0 && (i.x = Math.min(i.x, o - d), i.width += C);
|
|
218
|
+
const P = n - (i.y + i.height);
|
|
219
|
+
if (P < 0 && (i.y = Math.min(i.y, n - a), i.height += P), i.width < d && ((e === "sw" || e == "nw") && (i.x -= d - i.width), i.width = d), i.height < a && ((e === "nw" || e == "ne") && (i.y -= a - i.height), i.height = a), i.width > g && ((e === "sw" || e == "nw") && (i.x -= g - i.width), i.width = g), i.height > c && ((e === "nw" || e == "ne") && (i.y -= c - i.height), i.height = c), t) {
|
|
220
|
+
const w = i.width / i.height;
|
|
221
|
+
if (w < t) {
|
|
222
|
+
const N = Math.max(i.width / t, a);
|
|
223
|
+
(e === "nw" || e == "ne") && (i.y -= N - i.height), i.height = N;
|
|
224
|
+
} else if (w > t) {
|
|
225
|
+
const N = Math.max(i.height * t, d);
|
|
226
|
+
(e === "sw" || e == "nw") && (i.x -= N - i.width), i.width = N;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return i;
|
|
230
|
+
}
|
|
231
|
+
function He(l, t, e, o) {
|
|
232
|
+
const n = { ...l };
|
|
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 W = { capture: !0, passive: !1 };
|
|
236
|
+
let Ne = 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-${Ne++}`, 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 r = 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, p = !!h;
|
|
259
|
+
let s = t.clientX, i = t.clientY, d = r.x, a = r.y;
|
|
260
|
+
if (h) {
|
|
261
|
+
const g = t.clientX - n.x, c = t.clientY - n.y;
|
|
262
|
+
let C = 0, P = 0;
|
|
263
|
+
h === "ne" || h == "e" ? (C = g - (r.x + r.width), P = c - r.y, d = r.x, a = r.y + r.height) : h === "se" || h === "s" ? (C = g - (r.x + r.width), P = c - (r.y + r.height), d = r.x, a = r.y) : h === "sw" || h == "w" ? (C = g - r.x, P = c - (r.y + r.height), d = r.x + r.width, a = r.y) : (h === "nw" || h == "n") && (C = g - r.x, P = c - r.y, d = r.x + r.width, a = r.y + r.height), s = d + n.x + C, i = a + n.y + P;
|
|
264
|
+
}
|
|
265
|
+
this.evData = {
|
|
266
|
+
startClientX: s,
|
|
267
|
+
startClientY: i,
|
|
268
|
+
startCropX: d,
|
|
269
|
+
startCropY: a,
|
|
270
|
+
clientX: t.clientX,
|
|
271
|
+
clientY: t.clientY,
|
|
272
|
+
isResize: p,
|
|
273
|
+
ord: h
|
|
274
|
+
}, this.mouseDownOnCrop = !0, this.setState({ cropIsActive: !0 });
|
|
275
|
+
}, this.onComponentPointerDown = (t) => {
|
|
276
|
+
const { crop: e, disabled: o, locked: n, keepSelection: r, onChange: h } = this.props, p = this.getBox();
|
|
277
|
+
if (o || n || r && e)
|
|
278
|
+
return;
|
|
279
|
+
t.cancelable && t.preventDefault(), this.bindDocMove(), this.componentRef.current.focus({ preventScroll: !0 });
|
|
280
|
+
const s = t.clientX - p.x, i = t.clientY - p.y, d = {
|
|
281
|
+
unit: "px",
|
|
282
|
+
x: s,
|
|
283
|
+
y: i,
|
|
284
|
+
width: 0,
|
|
285
|
+
height: 0
|
|
286
|
+
};
|
|
287
|
+
this.evData = {
|
|
288
|
+
startClientX: t.clientX,
|
|
289
|
+
startClientY: t.clientY,
|
|
290
|
+
startCropX: s,
|
|
291
|
+
startCropY: i,
|
|
292
|
+
clientX: t.clientX,
|
|
293
|
+
clientY: t.clientY,
|
|
294
|
+
isResize: !0
|
|
295
|
+
}, this.mouseDownOnCrop = !0, h(I(d, p.width, p.height), O(d, p.width, p.height)), this.setState({ cropIsActive: !0, newCropIsBeingDrawn: !0 });
|
|
296
|
+
}, this.onDocPointerMove = (t) => {
|
|
297
|
+
const { crop: e, disabled: o, onChange: n, onDragStart: r } = this.props, h = this.getBox();
|
|
298
|
+
if (o || !e || !this.mouseDownOnCrop)
|
|
299
|
+
return;
|
|
300
|
+
t.cancelable && t.preventDefault(), this.dragStarted || (this.dragStarted = !0, r && r(t));
|
|
301
|
+
const { evData: p } = this;
|
|
302
|
+
p.clientX = t.clientX, p.clientY = t.clientY;
|
|
303
|
+
let s;
|
|
304
|
+
p.isResize ? s = this.resizeCrop() : s = this.dragCrop(), re(e, s) || n(
|
|
305
|
+
I(s, h.width, h.height),
|
|
306
|
+
O(s, h.width, h.height)
|
|
307
|
+
);
|
|
308
|
+
}, this.onComponentKeyDown = (t) => {
|
|
309
|
+
const { crop: e, disabled: o, onChange: n, onComplete: r } = this.props;
|
|
310
|
+
if (o)
|
|
311
|
+
return;
|
|
312
|
+
const h = t.key;
|
|
313
|
+
let p = !1;
|
|
314
|
+
if (!e)
|
|
315
|
+
return;
|
|
316
|
+
const s = this.getBox(), i = this.makePixelCrop(s), d = (navigator.platform.match("Mac") ? t.metaKey : t.ctrlKey) ? S.nudgeStepLarge : t.shiftKey ? S.nudgeStepMedium : S.nudgeStep;
|
|
317
|
+
if (h === "ArrowLeft" ? (i.x -= d, p = !0) : h === "ArrowRight" ? (i.x += d, p = !0) : h === "ArrowUp" ? (i.y -= d, p = !0) : h === "ArrowDown" && (i.y += d, p = !0), p) {
|
|
318
|
+
t.cancelable && t.preventDefault(), i.x = B(i.x, 0, s.width - i.width), i.y = B(i.y, 0, s.height - i.height);
|
|
319
|
+
const a = I(i, s.width, s.height), g = O(i, s.width, s.height);
|
|
320
|
+
n(a, g), r && r(a, g);
|
|
321
|
+
}
|
|
322
|
+
}, this.onHandlerKeyDown = (t, e) => {
|
|
323
|
+
const {
|
|
324
|
+
aspect: o = 0,
|
|
325
|
+
crop: n,
|
|
326
|
+
disabled: r,
|
|
327
|
+
minWidth: h = 0,
|
|
328
|
+
minHeight: p = 0,
|
|
329
|
+
maxWidth: s,
|
|
330
|
+
maxHeight: i,
|
|
331
|
+
onChange: d,
|
|
332
|
+
onComplete: a
|
|
333
|
+
} = this.props, g = this.getBox();
|
|
334
|
+
if (r || !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 = I(n, g.width, g.height), P = He(C, t.key, c, e), w = ie(
|
|
341
|
+
P,
|
|
342
|
+
o,
|
|
343
|
+
e,
|
|
344
|
+
g.width,
|
|
345
|
+
g.height,
|
|
346
|
+
h,
|
|
347
|
+
p,
|
|
348
|
+
s,
|
|
349
|
+
i
|
|
350
|
+
);
|
|
351
|
+
if (!re(n, w)) {
|
|
352
|
+
const N = O(w, g.width, g.height);
|
|
353
|
+
d(w, N), a && a(w, N);
|
|
354
|
+
}
|
|
355
|
+
}, this.onDocPointerDone = (t) => {
|
|
356
|
+
const { crop: e, disabled: o, onComplete: n, onDragEnd: r } = this.props, h = this.getBox();
|
|
357
|
+
this.unbindDocMove(), !(o || !e) && this.mouseDownOnCrop && (this.mouseDownOnCrop = !1, this.dragStarted = !1, r && r(t), n && n(I(e, h.width, h.height), O(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: r } = t.getBoundingClientRect();
|
|
373
|
+
return { x: e, y: o, width: n, height: r };
|
|
374
|
+
}
|
|
375
|
+
componentDidUpdate(t) {
|
|
376
|
+
const { crop: e, onComplete: o } = this.props;
|
|
377
|
+
if (o && !t.crop && e) {
|
|
378
|
+
const { width: n, height: r } = this.getBox();
|
|
379
|
+
n && r && o(I(e, n, r), O(e, n, r));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
componentWillUnmount() {
|
|
383
|
+
this.resizeObserver && this.resizeObserver.disconnect(), this.unbindDocMove();
|
|
384
|
+
}
|
|
385
|
+
bindDocMove() {
|
|
386
|
+
this.docMoveBound || (this.document.addEventListener("pointermove", this.onDocPointerMove, W), this.document.addEventListener("pointerup", this.onDocPointerDone, W), this.document.addEventListener("pointercancel", this.onDocPointerDone, W), this.docMoveBound = !0);
|
|
387
|
+
}
|
|
388
|
+
unbindDocMove() {
|
|
389
|
+
this.docMoveBound && (this.document.removeEventListener("pointermove", this.onDocPointerMove, W), this.document.removeEventListener("pointerup", this.onDocPointerDone, W), this.document.removeEventListener("pointercancel", this.onDocPointerDone, W), 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, r = t.clientY - t.startClientY;
|
|
403
|
+
return o.x = B(t.startCropX + n, 0, e.width - o.width), o.y = B(t.startCropY + r, 0, e.height - o.height), o;
|
|
404
|
+
}
|
|
405
|
+
getPointRegion(t, e, o, n) {
|
|
406
|
+
const { evData: r } = this, h = r.clientX - t.x, p = r.clientY - t.y;
|
|
407
|
+
let s;
|
|
408
|
+
n && e ? s = e === "nw" || e === "n" || e === "ne" : s = p < r.startCropY;
|
|
409
|
+
let i;
|
|
410
|
+
return o && e ? i = e === "nw" || e === "w" || e === "sw" : i = h < r.startCropX, i ? s ? "nw" : "sw" : s ? "ne" : "se";
|
|
411
|
+
}
|
|
412
|
+
resolveMinDimensions(t, e, o = 0, n = 0) {
|
|
413
|
+
const r = Math.min(o, t.width), h = Math.min(n, t.height);
|
|
414
|
+
return !e || !r && !h ? [r, h] : e > 1 ? r ? [r, r / e] : [h * e, h] : h ? [h * e, h] : [r, r / e];
|
|
415
|
+
}
|
|
416
|
+
resizeCrop() {
|
|
417
|
+
const { evData: t } = this, { aspect: e = 0, maxWidth: o, maxHeight: n } = this.props, r = this.getBox(), [h, p] = this.resolveMinDimensions(r, e, this.props.minWidth, this.props.minHeight);
|
|
418
|
+
let s = this.makePixelCrop(r);
|
|
419
|
+
const i = this.getPointRegion(r, t.ord, h, p), d = t.ord || i;
|
|
420
|
+
let a = t.clientX - t.startClientX, g = t.clientY - t.startClientY;
|
|
421
|
+
(h && d === "nw" || d === "w" || d === "sw") && (a = Math.min(a, -h)), (p && d === "nw" || d === "n" || d === "ne") && (g = Math.min(g, -p));
|
|
422
|
+
const c = {
|
|
423
|
+
unit: "px",
|
|
424
|
+
x: 0,
|
|
425
|
+
y: 0,
|
|
426
|
+
width: 0,
|
|
427
|
+
height: 0
|
|
428
|
+
};
|
|
429
|
+
i === "ne" ? (c.x = t.startCropX, c.width = a, e ? (c.height = c.width / e, c.y = t.startCropY - c.height) : (c.height = Math.abs(g), c.y = t.startCropY - c.height)) : i === "se" ? (c.x = t.startCropX, c.y = t.startCropY, c.width = a, e ? c.height = c.width / e : c.height = g) : i === "sw" ? (c.x = t.startCropX + a, c.y = t.startCropY, c.width = Math.abs(a), e ? c.height = c.width / e : c.height = g) : i === "nw" && (c.x = t.startCropX + a, c.width = Math.abs(a), e ? (c.height = c.width / e, c.y = t.startCropY - c.height) : (c.height = Math.abs(g), c.y = t.startCropY + g));
|
|
430
|
+
const C = ie(
|
|
431
|
+
c,
|
|
432
|
+
e,
|
|
433
|
+
i,
|
|
434
|
+
r.width,
|
|
435
|
+
r.height,
|
|
436
|
+
h,
|
|
437
|
+
p,
|
|
438
|
+
o,
|
|
439
|
+
n
|
|
440
|
+
);
|
|
441
|
+
return e || S.xyOrds.indexOf(d) > -1 ? s = C : S.xOrds.indexOf(d) > -1 ? (s.x = C.x, s.width = C.width) : S.yOrds.indexOf(d) > -1 && (s.y = C.y, s.height = C.height), s.x = B(s.x, 0, r.width - s.width), s.y = B(s.y, 0, r.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: r,
|
|
450
|
+
crop: h
|
|
451
|
+
} = this.props, p = this.getCropStyle();
|
|
452
|
+
if (h)
|
|
453
|
+
return /* @__PURE__ */ x.createElement(
|
|
454
|
+
"div",
|
|
455
|
+
{
|
|
456
|
+
style: p,
|
|
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__ */ x.createElement("div", { className: "ReactCrop__drag-elements", onFocus: this.onDragFocus }, /* @__PURE__ */ x.createElement("div", { className: "ReactCrop__drag-bar ord-n", "data-ord": "n" }), /* @__PURE__ */ x.createElement("div", { className: "ReactCrop__drag-bar ord-e", "data-ord": "e" }), /* @__PURE__ */ x.createElement("div", { className: "ReactCrop__drag-bar ord-s", "data-ord": "s" }), /* @__PURE__ */ x.createElement("div", { className: "ReactCrop__drag-bar ord-w", "data-ord": "w" }), /* @__PURE__ */ x.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__ */ x.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__ */ x.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__ */ x.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__ */ x.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__ */ x.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__ */ x.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__ */ x.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__ */ x.createElement("div", { className: "ReactCrop__selection-addon", onPointerDown: (s) => s.stopPropagation() }, n(this.state)),
|
|
546
|
+
r && /* @__PURE__ */ x.createElement(x.Fragment, null, /* @__PURE__ */ x.createElement("div", { className: "ReactCrop__rule-of-thirds-hz" }), /* @__PURE__ */ x.createElement("div", { className: "ReactCrop__rule-of-thirds-vt" }))
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
makePixelCrop(t) {
|
|
550
|
+
const e = { ...J, ...this.props.crop || {} };
|
|
551
|
+
return I(e, t.width, t.height);
|
|
552
|
+
}
|
|
553
|
+
render() {
|
|
554
|
+
const { aspect: t, children: e, circularCrop: o, className: n, crop: r, disabled: h, locked: p, style: s, ruleOfThirds: i } = this.props, { cropIsActive: d, newCropIsBeingDrawn: a } = this.state, g = r ? this.renderCropSelection() : null, c = ke(
|
|
555
|
+
"ReactCrop",
|
|
556
|
+
n,
|
|
557
|
+
d && "ReactCrop--active",
|
|
558
|
+
h && "ReactCrop--disabled",
|
|
559
|
+
p && "ReactCrop--locked",
|
|
560
|
+
a && "ReactCrop--new-crop",
|
|
561
|
+
r && t && "ReactCrop--fixed-aspect",
|
|
562
|
+
r && o && "ReactCrop--circular-crop",
|
|
563
|
+
r && i && "ReactCrop--rule-of-thirds",
|
|
564
|
+
!this.dragStarted && r && !r.width && !r.height && "ReactCrop--invisible-crop",
|
|
565
|
+
o && "ReactCrop--no-animate"
|
|
566
|
+
);
|
|
567
|
+
return /* @__PURE__ */ x.createElement("div", { ref: this.componentRef, className: c, style: s }, /* @__PURE__ */ x.createElement("div", { ref: this.mediaRef, className: "ReactCrop__child-wrapper", onPointerDown: this.onComponentPointerDown }, e), r ? /* @__PURE__ */ x.createElement("svg", { className: "ReactCrop__crop-mask", width: "100%", height: "100%" }, /* @__PURE__ */ x.createElement("defs", null, /* @__PURE__ */ x.createElement("mask", { id: `hole-${this.instanceId}` }, /* @__PURE__ */ x.createElement("rect", { width: "100%", height: "100%", fill: "white" }), o ? /* @__PURE__ */ x.createElement(
|
|
568
|
+
"ellipse",
|
|
569
|
+
{
|
|
570
|
+
cx: `${r.x + r.width / 2}${r.unit}`,
|
|
571
|
+
cy: `${r.y + r.height / 2}${r.unit}`,
|
|
572
|
+
rx: `${r.width / 2}${r.unit}`,
|
|
573
|
+
ry: `${r.height / 2}${r.unit}`,
|
|
574
|
+
fill: "black"
|
|
575
|
+
}
|
|
576
|
+
) : /* @__PURE__ */ x.createElement(
|
|
577
|
+
"rect",
|
|
578
|
+
{
|
|
579
|
+
x: `${r.x}${r.unit}`,
|
|
580
|
+
y: `${r.y}${r.unit}`,
|
|
581
|
+
width: `${r.width}${r.unit}`,
|
|
582
|
+
height: `${r.height}${r.unit}`,
|
|
583
|
+
fill: "black"
|
|
584
|
+
}
|
|
585
|
+
))), /* @__PURE__ */ x.createElement("rect", { fill: "black", fillOpacity: 0.5, width: "100%", height: "100%", mask: `url(#hole-${this.instanceId})` })) : void 0, g);
|
|
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 $e = X;
|
|
602
|
+
const oe = be();
|
|
603
|
+
function ze({
|
|
604
|
+
altText: l,
|
|
605
|
+
className: t,
|
|
606
|
+
src: e,
|
|
607
|
+
width: o,
|
|
608
|
+
height: n,
|
|
609
|
+
maxWidth: r,
|
|
610
|
+
imageRef: h,
|
|
611
|
+
startCrop: p,
|
|
612
|
+
setStartCrop: s,
|
|
613
|
+
isFocused: i,
|
|
614
|
+
nodeKey: d
|
|
615
|
+
}) {
|
|
616
|
+
const [a, g] = G(null), [c, C] = G({
|
|
617
|
+
//@ts-ignore
|
|
618
|
+
unit: "px",
|
|
619
|
+
// Can be 'px' or '%'
|
|
620
|
+
x: 25,
|
|
621
|
+
y: 25,
|
|
622
|
+
width: 50,
|
|
623
|
+
height: 50
|
|
624
|
+
}), [P] = se(), w = () => {
|
|
625
|
+
if (a) {
|
|
626
|
+
const M = h.current;
|
|
627
|
+
if (!M || !a)
|
|
628
|
+
return;
|
|
629
|
+
const u = M.naturalWidth / M.width, m = M.naturalHeight / M.height, f = new OffscreenCanvas(
|
|
630
|
+
a.width * u,
|
|
631
|
+
a.height * m
|
|
632
|
+
), $ = f.getContext("2d");
|
|
633
|
+
if (!$)
|
|
634
|
+
throw new Error("No 2D context available");
|
|
635
|
+
$.drawImage(
|
|
636
|
+
M,
|
|
637
|
+
a.x * u,
|
|
638
|
+
a.y * m,
|
|
639
|
+
a.width * u,
|
|
640
|
+
a.height * m,
|
|
641
|
+
0,
|
|
642
|
+
0,
|
|
643
|
+
a.width * u,
|
|
644
|
+
a.height * m
|
|
645
|
+
), f.convertToBlob({ type: "image/png" }).then((H) => {
|
|
646
|
+
s(!1);
|
|
647
|
+
const D = new FileReader();
|
|
648
|
+
D.onload = () => {
|
|
649
|
+
const b = D.result;
|
|
650
|
+
setTimeout(() => {
|
|
651
|
+
P.update(
|
|
652
|
+
() => {
|
|
653
|
+
const j = F(d);
|
|
654
|
+
T(j) && b && j.setSrc(b);
|
|
655
|
+
},
|
|
656
|
+
{ tag: "crop" }
|
|
657
|
+
);
|
|
658
|
+
}, 100);
|
|
659
|
+
}, D.onerror = () => {
|
|
660
|
+
console.error("Error reading the cropped image blob");
|
|
661
|
+
}, D.readAsDataURL(H);
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
}, N = () => {
|
|
665
|
+
p || s((M) => {
|
|
666
|
+
if (M === !1) {
|
|
667
|
+
const u = h.current;
|
|
668
|
+
C({
|
|
669
|
+
unit: "px",
|
|
670
|
+
// Can be 'px' or '%'
|
|
671
|
+
x: 0,
|
|
672
|
+
y: 0,
|
|
673
|
+
width: u.width,
|
|
674
|
+
height: u.height
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
return !M;
|
|
678
|
+
});
|
|
679
|
+
}, K = Y(null), k = Y(null);
|
|
680
|
+
q(() => {
|
|
681
|
+
a && (K.current = a);
|
|
682
|
+
}, [a]);
|
|
683
|
+
const L = (M) => {
|
|
684
|
+
k.current && !k.current.contains(M.target) && s(!1);
|
|
685
|
+
};
|
|
686
|
+
return q(() => (document.addEventListener("mousedown", L), () => {
|
|
687
|
+
document.removeEventListener("mousedown", L);
|
|
688
|
+
}), []), /* @__PURE__ */ R.jsxs("div", { ref: k, children: [
|
|
689
|
+
i && /* @__PURE__ */ R.jsx(
|
|
690
|
+
"button",
|
|
691
|
+
{
|
|
692
|
+
style: { zIndex: 999 },
|
|
693
|
+
className: "image-caption-button",
|
|
694
|
+
onClick: () => N(),
|
|
695
|
+
children: "Crop"
|
|
696
|
+
}
|
|
697
|
+
),
|
|
698
|
+
p && /* @__PURE__ */ R.jsx(
|
|
699
|
+
"button",
|
|
700
|
+
{
|
|
701
|
+
style: { zIndex: 999 },
|
|
702
|
+
className: "image-caption-button",
|
|
703
|
+
onClick: () => w(),
|
|
704
|
+
children: "Apply Crop"
|
|
705
|
+
}
|
|
706
|
+
),
|
|
707
|
+
p ? /* @__PURE__ */ R.jsx(
|
|
708
|
+
$e,
|
|
709
|
+
{
|
|
710
|
+
crop: c,
|
|
711
|
+
onChange: (M) => C(M),
|
|
712
|
+
onComplete: (M) => g(M),
|
|
713
|
+
children: /* @__PURE__ */ R.jsx(
|
|
714
|
+
"img",
|
|
715
|
+
{
|
|
716
|
+
className: t || void 0,
|
|
717
|
+
src: e,
|
|
718
|
+
alt: l,
|
|
719
|
+
ref: h,
|
|
720
|
+
width: typeof o == "number" ? o : void 0,
|
|
721
|
+
height: typeof n == "number" ? n : void 0,
|
|
722
|
+
style: {
|
|
723
|
+
height: n,
|
|
724
|
+
maxWidth: r,
|
|
725
|
+
width: o
|
|
726
|
+
},
|
|
727
|
+
draggable: "false",
|
|
728
|
+
crossOrigin: "anonymous"
|
|
729
|
+
}
|
|
730
|
+
)
|
|
731
|
+
}
|
|
732
|
+
) : (
|
|
733
|
+
// When startCrop is false, show the cropped image or original image
|
|
734
|
+
/* @__PURE__ */ R.jsx(
|
|
735
|
+
"img",
|
|
736
|
+
{
|
|
737
|
+
className: t || void 0,
|
|
738
|
+
src: e,
|
|
739
|
+
alt: l,
|
|
740
|
+
ref: h,
|
|
741
|
+
width: typeof o == "number" ? o : void 0,
|
|
742
|
+
height: typeof n == "number" ? n : void 0,
|
|
743
|
+
style: {
|
|
744
|
+
height: n,
|
|
745
|
+
maxWidth: r,
|
|
746
|
+
width: o
|
|
747
|
+
},
|
|
748
|
+
draggable: "false",
|
|
749
|
+
crossOrigin: "anonymous"
|
|
750
|
+
}
|
|
751
|
+
)
|
|
752
|
+
)
|
|
753
|
+
] });
|
|
754
|
+
}
|
|
755
|
+
function Ye({
|
|
756
|
+
src: l,
|
|
757
|
+
altText: t,
|
|
758
|
+
nodeKey: e,
|
|
759
|
+
width: o,
|
|
760
|
+
height: n,
|
|
761
|
+
maxWidth: r,
|
|
762
|
+
resizable: h,
|
|
763
|
+
showCaption: p,
|
|
764
|
+
caption: s
|
|
765
|
+
}) {
|
|
766
|
+
const i = Y(null), d = Y(null), [a, g, c] = ce(e), [C, P] = G(!1), [w] = se(), [N, K] = G(null), [k, L] = G(!1), M = Y(null), u = U((E) => a ? (E.preventDefault(), w.update(() => {
|
|
767
|
+
const y = F(e);
|
|
768
|
+
T(y) && y.remove();
|
|
769
|
+
}), !0) : !1, [a, w, e]), m = U(
|
|
770
|
+
(E) => {
|
|
771
|
+
const y = Z(), z = d.current;
|
|
772
|
+
if (a && V(y) && y.getNodes().length === 1) {
|
|
773
|
+
if (p)
|
|
774
|
+
return te(null), E.preventDefault(), s.focus(), !0;
|
|
775
|
+
if (z !== null && z !== document.activeElement)
|
|
776
|
+
return E.preventDefault(), z.focus(), !0;
|
|
777
|
+
}
|
|
778
|
+
return !1;
|
|
779
|
+
},
|
|
780
|
+
[s, a, p]
|
|
781
|
+
), f = U(
|
|
782
|
+
(E) => M.current === s || d.current === E.target ? (te(null), w.update(() => {
|
|
783
|
+
g(!0);
|
|
784
|
+
const y = w.getRootElement();
|
|
785
|
+
y !== null && y.focus();
|
|
786
|
+
}), !0) : !1,
|
|
787
|
+
[s, w, g]
|
|
788
|
+
), $ = U(
|
|
789
|
+
(E) => {
|
|
790
|
+
const y = E;
|
|
791
|
+
return C ? !0 : y.target === i.current ? (y.shiftKey ? g(!a) : (c(), g(!0)), !0) : !1;
|
|
792
|
+
},
|
|
793
|
+
[C, a, g, c]
|
|
794
|
+
), H = U(
|
|
795
|
+
(E) => {
|
|
796
|
+
w.getEditorState().read(() => {
|
|
797
|
+
const y = Z();
|
|
798
|
+
E.target.tagName === "IMG" && de(y) && y.getNodes().length === 1 && w.dispatchCommand(
|
|
799
|
+
oe,
|
|
800
|
+
E
|
|
801
|
+
);
|
|
802
|
+
});
|
|
803
|
+
},
|
|
804
|
+
[w]
|
|
805
|
+
);
|
|
806
|
+
q(() => {
|
|
807
|
+
const E = (z) => {
|
|
808
|
+
(z.key === "Delete" || z.key === "Backspace") && a && (z.stopPropagation(), z.preventDefault(), w.update(() => {
|
|
809
|
+
const _ = F(e);
|
|
810
|
+
T(_) && _.remove();
|
|
811
|
+
}));
|
|
812
|
+
}, y = w.getRootElement();
|
|
813
|
+
return y == null || y.addEventListener("keydown", E), () => {
|
|
814
|
+
y == null || y.removeEventListener("keydown", E);
|
|
815
|
+
};
|
|
816
|
+
}, [a, w, e]), q(() => {
|
|
817
|
+
let E = !0;
|
|
818
|
+
const y = w.getRootElement(), z = le(
|
|
819
|
+
w.registerUpdateListener(({ editorState: _ }) => {
|
|
820
|
+
E && K(_.read(() => Z()));
|
|
821
|
+
}),
|
|
822
|
+
w.registerCommand(
|
|
823
|
+
ye,
|
|
824
|
+
(_, he) => (M.current = he, !1),
|
|
825
|
+
A
|
|
826
|
+
),
|
|
827
|
+
w.registerCommand(
|
|
828
|
+
fe,
|
|
829
|
+
$,
|
|
830
|
+
A
|
|
831
|
+
),
|
|
832
|
+
w.registerCommand(
|
|
833
|
+
oe,
|
|
834
|
+
$,
|
|
835
|
+
A
|
|
836
|
+
),
|
|
837
|
+
w.registerCommand(
|
|
838
|
+
me,
|
|
839
|
+
(_) => _.target === i.current ? (_.preventDefault(), !0) : !1,
|
|
840
|
+
A
|
|
841
|
+
),
|
|
842
|
+
w.registerCommand(
|
|
843
|
+
we,
|
|
844
|
+
u,
|
|
845
|
+
4
|
|
846
|
+
),
|
|
847
|
+
w.registerCommand(
|
|
848
|
+
pe,
|
|
849
|
+
u,
|
|
850
|
+
4
|
|
851
|
+
),
|
|
852
|
+
w.registerCommand(ue, m, A),
|
|
853
|
+
w.registerCommand(ge, f, A)
|
|
854
|
+
);
|
|
855
|
+
return y == null || y.addEventListener("contextmenu", H), () => {
|
|
856
|
+
E = !1, z(), y == null || y.removeEventListener("contextmenu", H);
|
|
857
|
+
};
|
|
858
|
+
}, [
|
|
859
|
+
c,
|
|
860
|
+
w,
|
|
861
|
+
C,
|
|
862
|
+
a,
|
|
863
|
+
e,
|
|
864
|
+
// onDelete,
|
|
865
|
+
m,
|
|
866
|
+
f,
|
|
867
|
+
$,
|
|
868
|
+
H,
|
|
869
|
+
g
|
|
870
|
+
]);
|
|
871
|
+
const D = () => {
|
|
872
|
+
w.update(() => {
|
|
873
|
+
const E = F(e);
|
|
874
|
+
T(E) && E.setShowCaption(!0);
|
|
875
|
+
});
|
|
876
|
+
}, b = (E, y) => {
|
|
877
|
+
setTimeout(() => {
|
|
878
|
+
P(!1);
|
|
879
|
+
}, 200), w.update(() => {
|
|
880
|
+
const z = F(e);
|
|
881
|
+
console.log(z, "node"), T(z) && z.setWidthAndHeight(E, y);
|
|
882
|
+
});
|
|
883
|
+
}, j = () => {
|
|
884
|
+
k || P(!0);
|
|
885
|
+
}, ae = a && V(N) && !C, Q = a || C;
|
|
886
|
+
return /* @__PURE__ */ R.jsx(Me, { fallback: null, children: /* @__PURE__ */ R.jsxs(R.Fragment, { children: [
|
|
887
|
+
/* @__PURE__ */ R.jsx("div", { draggable: ae, children: /* @__PURE__ */ R.jsx(
|
|
888
|
+
ze,
|
|
889
|
+
{
|
|
890
|
+
className: Q ? `focused ${V(N) ? "draggable" : ""}` : null,
|
|
891
|
+
src: l,
|
|
892
|
+
altText: t,
|
|
893
|
+
width: o,
|
|
894
|
+
height: n,
|
|
895
|
+
maxWidth: r,
|
|
896
|
+
imageRef: i,
|
|
897
|
+
startCrop: k,
|
|
898
|
+
setStartCrop: L,
|
|
899
|
+
isFocused: Q,
|
|
900
|
+
nodeKey: e
|
|
901
|
+
}
|
|
902
|
+
) }),
|
|
903
|
+
p && /* @__PURE__ */ R.jsx("div", { className: "image-caption-container", children: /* @__PURE__ */ R.jsx(Re, { initialEditor: s, children: /* @__PURE__ */ R.jsx(
|
|
904
|
+
xe,
|
|
905
|
+
{
|
|
906
|
+
contentEditable: /* @__PURE__ */ R.jsx(Ce, { className: "ImageNode__contentEditable" }),
|
|
907
|
+
placeholder: /* @__PURE__ */ R.jsx(ve, { className: "ImageNode__placeholder", children: "Enter a caption..." }),
|
|
908
|
+
ErrorBoundary: De
|
|
909
|
+
}
|
|
910
|
+
) }) }),
|
|
911
|
+
!k && h && V(N) && Q && /* @__PURE__ */ R.jsx(
|
|
912
|
+
Pe,
|
|
913
|
+
{
|
|
914
|
+
showCaption: p,
|
|
915
|
+
setShowCaption: D,
|
|
916
|
+
editor: w,
|
|
917
|
+
buttonRef: d,
|
|
918
|
+
maxWidth: r,
|
|
919
|
+
onResizeStart: k ? () => {
|
|
920
|
+
} : j,
|
|
921
|
+
onResizeEnd: k ? () => {
|
|
922
|
+
} : b,
|
|
923
|
+
captionsEnabled: !1,
|
|
924
|
+
imageRef: i
|
|
925
|
+
}
|
|
926
|
+
)
|
|
927
|
+
] }) });
|
|
928
|
+
}
|
|
929
|
+
export {
|
|
930
|
+
oe as RIGHT_CLICK_IMAGE_COMMAND,
|
|
931
|
+
Ye as default
|
|
932
|
+
};
|
|
933
|
+
//# sourceMappingURL=ImageComponent-16bda209.js.map
|