sykpcomposer 0.0.388 → 0.0.390
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-8d6f3ac9.js +914 -0
- package/dist/ImageComponent-8d6f3ac9.js.map +1 -0
- package/dist/{InlineImageComponent-3bfb6f6d.js → InlineImageComponent-27043921.js} +7 -7
- package/dist/{InlineImageComponent-3bfb6f6d.js.map → InlineImageComponent-27043921.js.map} +1 -1
- package/dist/{LexicalNestedComposer.esm-e77d6d34.js → LexicalNestedComposer.esm-96df9d51.js} +2 -2
- package/dist/{LexicalNestedComposer.esm-e77d6d34.js.map → LexicalNestedComposer.esm-96df9d51.js.map} +1 -1
- package/dist/{PollComponent-58f1cd72.js → PollComponent-935282aa.js} +37 -37
- package/dist/{PollComponent-58f1cd72.js.map → PollComponent-935282aa.js.map} +1 -1
- package/dist/{index-f441193e.js → index-b0251a90.js} +4264 -4708
- package/dist/{index-f441193e.js.map → index-b0251a90.js.map} +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +113 -151
- package/dist/index.umd.js.map +1 -1
- package/dist/src/lexical/nodes/ImageComponent.d.ts +5 -5
- package/dist/src/lexical/nodes/ImageNode.d.ts +9 -15
- package/dist/src/lexical/plugins/MentionsPlugin/index.d.ts +3 -1
- package/dist/src/lexical/plugins/MsWordPastePlugin.d.ts +9 -0
- package/dist/src/lexical/ui/ImageResizer.d.ts +2 -2
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/dist/ImageComponent-b728d370.js +0 -975
- package/dist/ImageComponent-b728d370.js.map +0 -1
- package/dist/src/lexical/appSettings.d.ts +0 -27
- package/dist/src/lexical/context/SettingsContext.d.ts +0 -18
- package/dist/src/lexical/plugins/TreeViewPlugin/index.d.ts +0 -9
|
@@ -0,0 +1,914 @@
|
|
|
1
|
+
import { j as D, u as ce, a as ae, $ as T, b as V, c as q, d as J, e as ne, f as de, m as le, S as ge, C as z, g as ue, D as pe, K as me, h as we, i as xe, k as Ce, R as fe, L as ye, P as De, l as ve, n as be } from "./index-b0251a90.js";
|
|
2
|
+
import { L as Re } from "./LexicalNestedComposer.esm-96df9d51.js";
|
|
3
|
+
import C, { useRef as A, PureComponent as Ee, createRef as ie, useState as B, useCallback as G, useEffect as te, 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 f = {
|
|
9
|
+
east: 1,
|
|
10
|
+
north: 8,
|
|
11
|
+
south: 2,
|
|
12
|
+
west: 4
|
|
13
|
+
};
|
|
14
|
+
function Ne({
|
|
15
|
+
onResizeStart: l,
|
|
16
|
+
onResizeEnd: t,
|
|
17
|
+
buttonRef: e,
|
|
18
|
+
imageRef: o,
|
|
19
|
+
maxWidth: n,
|
|
20
|
+
editor: i,
|
|
21
|
+
showCaption: h,
|
|
22
|
+
setShowCaption: p,
|
|
23
|
+
captionsEnabled: s
|
|
24
|
+
}) {
|
|
25
|
+
const r = A(null), d = A({
|
|
26
|
+
priority: "",
|
|
27
|
+
value: "default"
|
|
28
|
+
}), a = A({
|
|
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 = i.getRootElement(), c = g !== null ? g.getBoundingClientRect().width - 20 : 100, y = g !== null ? g.getBoundingClientRect().height - 20 : 100, N = 100, x = 100, P = (m) => {
|
|
39
|
+
const u = m === f.east || m === f.west, w = m === f.north || m === f.south, _ = m & f.north && m & f.west || m & f.south && m & f.east, E = u ? "ew" : w ? "ns" : _ ? "nwse" : "nesw";
|
|
40
|
+
g !== null && g.style.setProperty(
|
|
41
|
+
"cursor",
|
|
42
|
+
`${E}-resize`,
|
|
43
|
+
"important"
|
|
44
|
+
), document.body !== null && (document.body.style.setProperty(
|
|
45
|
+
"cursor",
|
|
46
|
+
`${E}-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
|
+
}, W = () => {
|
|
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
|
+
}, S = (m, u) => {
|
|
64
|
+
if (!i.isEditable())
|
|
65
|
+
return;
|
|
66
|
+
const w = o.current, _ = r.current;
|
|
67
|
+
if (w !== null && _ !== null) {
|
|
68
|
+
m.preventDefault();
|
|
69
|
+
const { width: E, height: b } = w.getBoundingClientRect(), v = a.current;
|
|
70
|
+
v.startWidth = E, v.startHeight = b, v.ratio = E / b, v.currentWidth = E, v.currentHeight = b, v.startX = m.clientX, v.startY = m.clientY, v.isResizing = !0, v.direction = u, P(u), l(), _.classList.add("image-control-wrapper--resizing"), w.style.height = `${b}px`, w.style.width = `${E}px`, document.addEventListener("pointermove", X), document.addEventListener("pointerup", I);
|
|
71
|
+
}
|
|
72
|
+
}, X = (m) => {
|
|
73
|
+
const u = o.current, w = a.current, _ = w.direction & (f.east | f.west), E = w.direction & (f.south | f.north);
|
|
74
|
+
if (u !== null && w.isResizing) {
|
|
75
|
+
if (_ && E) {
|
|
76
|
+
let b = Math.floor(w.startX - m.clientX);
|
|
77
|
+
b = w.direction & f.east ? -b : b;
|
|
78
|
+
const v = ee(
|
|
79
|
+
w.startWidth + b,
|
|
80
|
+
N,
|
|
81
|
+
c
|
|
82
|
+
), L = v / w.ratio;
|
|
83
|
+
u.style.width = `${v}px`, u.style.height = `${L}px`, w.currentHeight = L, w.currentWidth = v;
|
|
84
|
+
} else if (E) {
|
|
85
|
+
let b = Math.floor(w.startY - m.clientY);
|
|
86
|
+
b = w.direction & f.south ? -b : b;
|
|
87
|
+
const v = ee(
|
|
88
|
+
w.startHeight + b,
|
|
89
|
+
x,
|
|
90
|
+
y
|
|
91
|
+
);
|
|
92
|
+
u.style.height = `${v}px`, u.style.maxHeight = `${v}px`, w.currentHeight = v;
|
|
93
|
+
} else {
|
|
94
|
+
let b = Math.floor(w.startX - m.clientX);
|
|
95
|
+
b = w.direction & f.east ? -b : b;
|
|
96
|
+
const v = ee(
|
|
97
|
+
w.startWidth + b,
|
|
98
|
+
N,
|
|
99
|
+
c
|
|
100
|
+
);
|
|
101
|
+
u.style.width = `${v}px`, u.style.maxWidth = `${v}px`, w.currentWidth = v;
|
|
102
|
+
}
|
|
103
|
+
u && (u.setAttribute("width", `${w.currentWidth}`), u.setAttribute("height", `${w.currentHeight}`));
|
|
104
|
+
}
|
|
105
|
+
}, I = () => {
|
|
106
|
+
const m = o.current, u = a.current, w = r.current;
|
|
107
|
+
if (m !== null && w !== null && u.isResizing) {
|
|
108
|
+
const _ = u.currentWidth, E = u.currentHeight;
|
|
109
|
+
u.startWidth = 0, u.startHeight = 0, u.ratio = 0, u.startX = 0, u.startY = 0, u.currentWidth = 0, u.currentHeight = 0, u.isResizing = !1, w.classList.remove("image-control-wrapper--resizing"), W(), t(_, E), document.removeEventListener("pointermove", X), document.removeEventListener("pointerup", I);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
return /* @__PURE__ */ D.jsxs("div", { ref: r, children: [
|
|
113
|
+
/* @__PURE__ */ D.jsx(
|
|
114
|
+
"div",
|
|
115
|
+
{
|
|
116
|
+
className: "image-resizer image-resizer-n",
|
|
117
|
+
onPointerDown: (m) => {
|
|
118
|
+
S(m, f.north);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
),
|
|
122
|
+
/* @__PURE__ */ D.jsx(
|
|
123
|
+
"div",
|
|
124
|
+
{
|
|
125
|
+
className: "image-resizer image-resizer-ne",
|
|
126
|
+
onPointerDown: (m) => {
|
|
127
|
+
S(m, f.north | f.east);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
),
|
|
131
|
+
/* @__PURE__ */ D.jsx(
|
|
132
|
+
"div",
|
|
133
|
+
{
|
|
134
|
+
className: "image-resizer image-resizer-e",
|
|
135
|
+
onPointerDown: (m) => {
|
|
136
|
+
S(m, f.east);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
),
|
|
140
|
+
/* @__PURE__ */ D.jsx(
|
|
141
|
+
"div",
|
|
142
|
+
{
|
|
143
|
+
className: "image-resizer image-resizer-se",
|
|
144
|
+
onPointerDown: (m) => {
|
|
145
|
+
S(m, f.south | f.east);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
),
|
|
149
|
+
/* @__PURE__ */ D.jsx(
|
|
150
|
+
"div",
|
|
151
|
+
{
|
|
152
|
+
className: "image-resizer image-resizer-s",
|
|
153
|
+
onPointerDown: (m) => {
|
|
154
|
+
S(m, f.south);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
),
|
|
158
|
+
/* @__PURE__ */ D.jsx(
|
|
159
|
+
"div",
|
|
160
|
+
{
|
|
161
|
+
className: "image-resizer image-resizer-sw",
|
|
162
|
+
onPointerDown: (m) => {
|
|
163
|
+
S(m, f.south | f.west);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
),
|
|
167
|
+
/* @__PURE__ */ D.jsx(
|
|
168
|
+
"div",
|
|
169
|
+
{
|
|
170
|
+
className: "image-resizer image-resizer-w",
|
|
171
|
+
onPointerDown: (m) => {
|
|
172
|
+
S(m, f.west);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
),
|
|
176
|
+
/* @__PURE__ */ D.jsx(
|
|
177
|
+
"div",
|
|
178
|
+
{
|
|
179
|
+
className: "image-resizer image-resizer-nw",
|
|
180
|
+
onPointerDown: (m) => {
|
|
181
|
+
S(m, f.north | f.west);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
)
|
|
185
|
+
] });
|
|
186
|
+
}
|
|
187
|
+
const Q = {
|
|
188
|
+
x: 0,
|
|
189
|
+
y: 0,
|
|
190
|
+
width: 0,
|
|
191
|
+
height: 0,
|
|
192
|
+
unit: "px"
|
|
193
|
+
}, O = (l, t, e) => Math.min(Math.max(l, t), e), _e = (...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 K(l, t, e) {
|
|
195
|
+
return l.unit === "%" ? { ...Q, ...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 Y(l, t, e) {
|
|
204
|
+
return l.unit ? l.unit === "px" ? { ...Q, ...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
|
+
} : { ...Q, ...l, unit: "px" };
|
|
211
|
+
}
|
|
212
|
+
function oe(l, t, e, o, n, i = 0, h = 0, p = o, s = n) {
|
|
213
|
+
const r = { ...l };
|
|
214
|
+
let d = Math.min(i, 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 = i ? i / t : a, d = a * t, c = s / t)), r.y < 0 && (r.height = Math.max(r.height + r.y, a), r.y = 0), r.x < 0 && (r.width = Math.max(r.width + r.x, d), r.x = 0);
|
|
216
|
+
const y = o - (r.x + r.width);
|
|
217
|
+
y < 0 && (r.x = Math.min(r.x, o - d), r.width += y);
|
|
218
|
+
const N = n - (r.y + r.height);
|
|
219
|
+
if (N < 0 && (r.y = Math.min(r.y, n - a), r.height += N), r.width < d && ((e === "sw" || e == "nw") && (r.x -= d - r.width), r.width = d), r.height < a && ((e === "nw" || e == "ne") && (r.y -= a - r.height), r.height = a), r.width > g && ((e === "sw" || e == "nw") && (r.x -= g - r.width), r.width = g), 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 P = Math.max(r.width / t, a);
|
|
223
|
+
(e === "nw" || e == "ne") && (r.y -= P - r.height), r.height = P;
|
|
224
|
+
} else if (x > t) {
|
|
225
|
+
const P = Math.max(r.height * t, d);
|
|
226
|
+
(e === "sw" || e == "nw") && (r.x -= P - r.width), r.width = P;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return r;
|
|
230
|
+
}
|
|
231
|
+
function Pe(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 j = { capture: !0, passive: !1 };
|
|
236
|
+
let Se = 0;
|
|
237
|
+
const k = class $ 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 = ie(), this.mediaRef = ie(), this.initChangeCalled = !1, this.instanceId = `rc-${Se++}`, 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 = Y(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, r = t.clientY, d = i.x, a = i.y;
|
|
260
|
+
if (h) {
|
|
261
|
+
const g = t.clientX - n.x, c = t.clientY - n.y;
|
|
262
|
+
let y = 0, N = 0;
|
|
263
|
+
h === "ne" || h == "e" ? (y = g - (i.x + i.width), N = c - i.y, d = i.x, a = i.y + i.height) : h === "se" || h === "s" ? (y = g - (i.x + i.width), N = c - (i.y + i.height), d = i.x, a = i.y) : h === "sw" || h == "w" ? (y = g - i.x, N = c - (i.y + i.height), d = i.x + i.width, a = i.y) : (h === "nw" || h == "n") && (y = g - i.x, N = c - i.y, d = i.x + i.width, a = i.y + i.height), s = d + n.x + y, r = a + n.y + N;
|
|
264
|
+
}
|
|
265
|
+
this.evData = {
|
|
266
|
+
startClientX: s,
|
|
267
|
+
startClientY: r,
|
|
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: i, onChange: h } = this.props, p = 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 - p.x, r = t.clientY - p.y, d = {
|
|
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(Y(d, p.width, p.height), K(d, p.width, p.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: 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
|
+
Y(s, h.width, h.height),
|
|
306
|
+
K(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 p = !1;
|
|
314
|
+
if (!e)
|
|
315
|
+
return;
|
|
316
|
+
const s = this.getBox(), r = this.makePixelCrop(s), d = (navigator.platform.match("Mac") ? t.metaKey : t.ctrlKey) ? $.nudgeStepLarge : t.shiftKey ? $.nudgeStepMedium : $.nudgeStep;
|
|
317
|
+
if (h === "ArrowLeft" ? (r.x -= d, p = !0) : h === "ArrowRight" ? (r.x += d, p = !0) : h === "ArrowUp" ? (r.y -= d, p = !0) : h === "ArrowDown" && (r.y += d, p = !0), p) {
|
|
318
|
+
t.cancelable && t.preventDefault(), r.x = O(r.x, 0, s.width - r.width), r.y = O(r.y, 0, s.height - r.height);
|
|
319
|
+
const a = Y(r, s.width, s.height), g = K(r, s.width, s.height);
|
|
320
|
+
n(a, g), i && i(a, g);
|
|
321
|
+
}
|
|
322
|
+
}, this.onHandlerKeyDown = (t, e) => {
|
|
323
|
+
const {
|
|
324
|
+
aspect: o = 0,
|
|
325
|
+
crop: n,
|
|
326
|
+
disabled: i,
|
|
327
|
+
minWidth: h = 0,
|
|
328
|
+
minHeight: p = 0,
|
|
329
|
+
maxWidth: s,
|
|
330
|
+
maxHeight: r,
|
|
331
|
+
onChange: d,
|
|
332
|
+
onComplete: a
|
|
333
|
+
} = this.props, g = 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) ? $.nudgeStepLarge : t.shiftKey ? $.nudgeStepMedium : $.nudgeStep, y = Y(n, g.width, g.height), N = Pe(y, t.key, c, e), x = oe(
|
|
341
|
+
N,
|
|
342
|
+
o,
|
|
343
|
+
e,
|
|
344
|
+
g.width,
|
|
345
|
+
g.height,
|
|
346
|
+
h,
|
|
347
|
+
p,
|
|
348
|
+
s,
|
|
349
|
+
r
|
|
350
|
+
);
|
|
351
|
+
if (!re(n, x)) {
|
|
352
|
+
const P = K(x, g.width, g.height);
|
|
353
|
+
d(x, P), a && a(x, P);
|
|
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(Y(e, h.width, h.height), K(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(Y(e, n, i), K(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, j), this.document.addEventListener("pointerup", this.onDocPointerDone, j), this.document.addEventListener("pointercancel", this.onDocPointerDone, j), this.docMoveBound = !0);
|
|
387
|
+
}
|
|
388
|
+
unbindDocMove() {
|
|
389
|
+
this.docMoveBound && (this.document.removeEventListener("pointermove", this.onDocPointerMove, j), this.document.removeEventListener("pointerup", this.onDocPointerDone, j), this.document.removeEventListener("pointercancel", this.onDocPointerDone, j), 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 = O(t.startCropX + n, 0, e.width - o.width), o.y = O(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, p = i.clientY - t.y;
|
|
407
|
+
let s;
|
|
408
|
+
n && e ? s = e === "nw" || e === "n" || e === "ne" : s = p < 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, p] = 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, p), d = t.ord || r;
|
|
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
|
+
r === "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)) : r === "se" ? (c.x = t.startCropX, c.y = t.startCropY, c.width = a, e ? c.height = c.width / e : c.height = g) : r === "sw" ? (c.x = t.startCropX + a, c.y = t.startCropY, c.width = Math.abs(a), e ? c.height = c.width / e : c.height = g) : r === "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 y = oe(
|
|
431
|
+
c,
|
|
432
|
+
e,
|
|
433
|
+
r,
|
|
434
|
+
i.width,
|
|
435
|
+
i.height,
|
|
436
|
+
h,
|
|
437
|
+
p,
|
|
438
|
+
o,
|
|
439
|
+
n
|
|
440
|
+
);
|
|
441
|
+
return e || $.xyOrds.indexOf(d) > -1 ? s = y : $.xOrds.indexOf(d) > -1 ? (s.x = y.x, s.width = y.width) : $.yOrds.indexOf(d) > -1 && (s.y = y.y, s.height = y.height), s.x = O(s.x, 0, i.width - s.width), s.y = O(s.y, 0, i.height - s.height), s;
|
|
442
|
+
}
|
|
443
|
+
renderCropSelection() {
|
|
444
|
+
const {
|
|
445
|
+
ariaLabels: t = $.defaultProps.ariaLabels,
|
|
446
|
+
disabled: e,
|
|
447
|
+
locked: o,
|
|
448
|
+
renderSelectionAddon: n,
|
|
449
|
+
ruleOfThirds: i,
|
|
450
|
+
crop: h
|
|
451
|
+
} = this.props, p = this.getCropStyle();
|
|
452
|
+
if (h)
|
|
453
|
+
return /* @__PURE__ */ C.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__ */ C.createElement("div", { className: "ReactCrop__drag-elements", onFocus: this.onDragFocus }, /* @__PURE__ */ C.createElement("div", { className: "ReactCrop__drag-bar ord-n", "data-ord": "n" }), /* @__PURE__ */ C.createElement("div", { className: "ReactCrop__drag-bar ord-e", "data-ord": "e" }), /* @__PURE__ */ C.createElement("div", { className: "ReactCrop__drag-bar ord-s", "data-ord": "s" }), /* @__PURE__ */ C.createElement("div", { className: "ReactCrop__drag-bar ord-w", "data-ord": "w" }), /* @__PURE__ */ C.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__ */ C.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__ */ C.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__ */ C.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__ */ C.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__ */ C.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__ */ C.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__ */ C.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__ */ C.createElement("div", { className: "ReactCrop__selection-addon", onPointerDown: (s) => s.stopPropagation() }, n(this.state)),
|
|
546
|
+
i && /* @__PURE__ */ C.createElement(C.Fragment, null, /* @__PURE__ */ C.createElement("div", { className: "ReactCrop__rule-of-thirds-hz" }), /* @__PURE__ */ C.createElement("div", { className: "ReactCrop__rule-of-thirds-vt" }))
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
makePixelCrop(t) {
|
|
550
|
+
const e = { ...Q, ...this.props.crop || {} };
|
|
551
|
+
return Y(e, t.width, t.height);
|
|
552
|
+
}
|
|
553
|
+
render() {
|
|
554
|
+
const { aspect: t, children: e, circularCrop: o, className: n, crop: i, disabled: h, locked: p, style: s, ruleOfThirds: r } = this.props, { cropIsActive: d, newCropIsBeingDrawn: a } = this.state, g = i ? this.renderCropSelection() : null, c = _e(
|
|
555
|
+
"ReactCrop",
|
|
556
|
+
n,
|
|
557
|
+
d && "ReactCrop--active",
|
|
558
|
+
h && "ReactCrop--disabled",
|
|
559
|
+
p && "ReactCrop--locked",
|
|
560
|
+
a && "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__ */ C.createElement("div", { ref: this.componentRef, className: c, style: s }, /* @__PURE__ */ C.createElement("div", { ref: this.mediaRef, className: "ReactCrop__child-wrapper", onPointerDown: this.onComponentPointerDown }, e), i ? /* @__PURE__ */ C.createElement("svg", { className: "ReactCrop__crop-mask", width: "100%", height: "100%" }, /* @__PURE__ */ C.createElement("defs", null, /* @__PURE__ */ C.createElement("mask", { id: `hole-${this.instanceId}` }, /* @__PURE__ */ C.createElement("rect", { width: "100%", height: "100%", fill: "white" }), o ? /* @__PURE__ */ C.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__ */ C.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__ */ C.createElement("rect", { fill: "black", fillOpacity: 0.5, width: "100%", height: "100%", mask: `url(#hole-${this.instanceId})` })) : void 0, g);
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
k.xOrds = ["e", "w"], k.yOrds = ["n", "s"], k.xyOrds = ["nw", "ne", "se", "sw"], k.nudgeStep = 1, k.nudgeStepMedium = 10, k.nudgeStepLarge = 100, k.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 He = k;
|
|
602
|
+
const se = be("RIGHT_CLICK_IMAGE_COMMAND");
|
|
603
|
+
function $e({
|
|
604
|
+
altText: l,
|
|
605
|
+
className: t,
|
|
606
|
+
src: e,
|
|
607
|
+
width: o,
|
|
608
|
+
height: n,
|
|
609
|
+
maxWidth: i,
|
|
610
|
+
imageRef: h,
|
|
611
|
+
startCrop: p,
|
|
612
|
+
setStartCrop: s,
|
|
613
|
+
isFocused: r,
|
|
614
|
+
nodeKey: d
|
|
615
|
+
}) {
|
|
616
|
+
const [a, g] = B(null), [c, y] = B(null), [N, x] = B({
|
|
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] = ae(), W = () => {
|
|
625
|
+
if (a) {
|
|
626
|
+
const u = h.current;
|
|
627
|
+
if (!u || !a)
|
|
628
|
+
return;
|
|
629
|
+
const w = u.naturalWidth / u.width, _ = u.naturalHeight / u.height, E = new OffscreenCanvas(
|
|
630
|
+
a.width * w,
|
|
631
|
+
a.height * _
|
|
632
|
+
), b = E.getContext("2d");
|
|
633
|
+
if (!b)
|
|
634
|
+
throw new Error("No 2D context available");
|
|
635
|
+
b.drawImage(
|
|
636
|
+
u,
|
|
637
|
+
a.x * w,
|
|
638
|
+
a.y * _,
|
|
639
|
+
a.width * w,
|
|
640
|
+
a.height * _,
|
|
641
|
+
0,
|
|
642
|
+
0,
|
|
643
|
+
a.width * w,
|
|
644
|
+
a.height * _
|
|
645
|
+
), E.convertToBlob({ type: "image/png" }).then((v) => {
|
|
646
|
+
const L = URL.createObjectURL(v);
|
|
647
|
+
y(L), s(!1), P.update(() => {
|
|
648
|
+
const F = q(d);
|
|
649
|
+
J(F) && F.setSrc(L);
|
|
650
|
+
});
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
}, S = () => {
|
|
654
|
+
p || s((u) => {
|
|
655
|
+
if (u === !1) {
|
|
656
|
+
const w = h.current;
|
|
657
|
+
x({
|
|
658
|
+
unit: "px",
|
|
659
|
+
// Can be 'px' or '%'
|
|
660
|
+
x: 0,
|
|
661
|
+
y: 0,
|
|
662
|
+
width: w.width,
|
|
663
|
+
height: w.height
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
return !u;
|
|
667
|
+
});
|
|
668
|
+
}, X = A(null), I = A(null);
|
|
669
|
+
te(() => {
|
|
670
|
+
a && (X.current = a);
|
|
671
|
+
}, [a]);
|
|
672
|
+
const m = (u) => {
|
|
673
|
+
I.current && !I.current.contains(u.target) && s(!1);
|
|
674
|
+
};
|
|
675
|
+
return te(() => (document.addEventListener("mousedown", m), () => {
|
|
676
|
+
document.removeEventListener("mousedown", m);
|
|
677
|
+
}), []), /* @__PURE__ */ D.jsxs("div", { ref: I, children: [
|
|
678
|
+
r && /* @__PURE__ */ D.jsx(
|
|
679
|
+
"button",
|
|
680
|
+
{
|
|
681
|
+
style: { zIndex: 999 },
|
|
682
|
+
className: "image-caption-button",
|
|
683
|
+
onClick: () => S(),
|
|
684
|
+
children: "Crop"
|
|
685
|
+
}
|
|
686
|
+
),
|
|
687
|
+
p && /* @__PURE__ */ D.jsx(
|
|
688
|
+
"button",
|
|
689
|
+
{
|
|
690
|
+
style: { zIndex: 999 },
|
|
691
|
+
className: "image-caption-button",
|
|
692
|
+
onClick: () => W(),
|
|
693
|
+
children: "Apply Crop"
|
|
694
|
+
}
|
|
695
|
+
),
|
|
696
|
+
p ? /* @__PURE__ */ D.jsx(
|
|
697
|
+
He,
|
|
698
|
+
{
|
|
699
|
+
crop: N,
|
|
700
|
+
onChange: (u) => x(u),
|
|
701
|
+
onComplete: (u) => g(u),
|
|
702
|
+
children: /* @__PURE__ */ D.jsx(
|
|
703
|
+
"img",
|
|
704
|
+
{
|
|
705
|
+
className: t || void 0,
|
|
706
|
+
src: c || e,
|
|
707
|
+
alt: l,
|
|
708
|
+
ref: h,
|
|
709
|
+
style: {
|
|
710
|
+
height: n,
|
|
711
|
+
maxWidth: i,
|
|
712
|
+
width: o
|
|
713
|
+
},
|
|
714
|
+
draggable: "false"
|
|
715
|
+
}
|
|
716
|
+
)
|
|
717
|
+
}
|
|
718
|
+
) : (
|
|
719
|
+
// When startCrop is false, show the cropped image or original image
|
|
720
|
+
/* @__PURE__ */ D.jsx(
|
|
721
|
+
"img",
|
|
722
|
+
{
|
|
723
|
+
className: t || void 0,
|
|
724
|
+
src: c || e,
|
|
725
|
+
alt: l,
|
|
726
|
+
ref: h,
|
|
727
|
+
style: {
|
|
728
|
+
height: n,
|
|
729
|
+
maxWidth: i,
|
|
730
|
+
width: o
|
|
731
|
+
},
|
|
732
|
+
draggable: "false"
|
|
733
|
+
}
|
|
734
|
+
)
|
|
735
|
+
)
|
|
736
|
+
] });
|
|
737
|
+
}
|
|
738
|
+
function Ae({
|
|
739
|
+
src: l,
|
|
740
|
+
altText: t,
|
|
741
|
+
nodeKey: e,
|
|
742
|
+
width: o,
|
|
743
|
+
height: n,
|
|
744
|
+
maxWidth: i,
|
|
745
|
+
resizable: h,
|
|
746
|
+
showCaption: p,
|
|
747
|
+
caption: s
|
|
748
|
+
}) {
|
|
749
|
+
const r = A(null), d = A(null), [a, g, c] = ce(e), [y, N] = B(!1), [x] = ae(), [P, W] = B(null), [S, X] = B(!1), I = A(null), m = G(
|
|
750
|
+
(M) => {
|
|
751
|
+
if (a && T(V())) {
|
|
752
|
+
M.preventDefault();
|
|
753
|
+
const H = q(e);
|
|
754
|
+
if (J(H))
|
|
755
|
+
return H.remove(), !0;
|
|
756
|
+
}
|
|
757
|
+
return !1;
|
|
758
|
+
},
|
|
759
|
+
[a, e]
|
|
760
|
+
), u = G(
|
|
761
|
+
(M) => {
|
|
762
|
+
const R = V(), H = d.current;
|
|
763
|
+
if (a && T(R) && R.getNodes().length === 1) {
|
|
764
|
+
if (p)
|
|
765
|
+
return ne(null), M.preventDefault(), s.focus(), !0;
|
|
766
|
+
if (H !== null && H !== document.activeElement)
|
|
767
|
+
return M.preventDefault(), H.focus(), !0;
|
|
768
|
+
}
|
|
769
|
+
return !1;
|
|
770
|
+
},
|
|
771
|
+
[s, a, p]
|
|
772
|
+
), w = G(
|
|
773
|
+
(M) => I.current === s || d.current === M.target ? (ne(null), x.update(() => {
|
|
774
|
+
g(!0);
|
|
775
|
+
const R = x.getRootElement();
|
|
776
|
+
R !== null && R.focus();
|
|
777
|
+
}), !0) : !1,
|
|
778
|
+
[s, x, g]
|
|
779
|
+
), _ = G(
|
|
780
|
+
(M) => {
|
|
781
|
+
const R = M;
|
|
782
|
+
return y ? !0 : R.target === r.current ? (R.shiftKey ? g(!a) : (c(), g(!0)), !0) : !1;
|
|
783
|
+
},
|
|
784
|
+
[y, a, g, c]
|
|
785
|
+
), E = G(
|
|
786
|
+
(M) => {
|
|
787
|
+
x.getEditorState().read(() => {
|
|
788
|
+
const R = V();
|
|
789
|
+
M.target.tagName === "IMG" && de(R) && R.getNodes().length === 1 && x.dispatchCommand(
|
|
790
|
+
se,
|
|
791
|
+
M
|
|
792
|
+
);
|
|
793
|
+
});
|
|
794
|
+
},
|
|
795
|
+
[x]
|
|
796
|
+
);
|
|
797
|
+
te(() => {
|
|
798
|
+
let M = !0;
|
|
799
|
+
const R = x.getRootElement(), H = le(
|
|
800
|
+
x.registerUpdateListener(({ editorState: U }) => {
|
|
801
|
+
M && W(U.read(() => V()));
|
|
802
|
+
}),
|
|
803
|
+
x.registerCommand(
|
|
804
|
+
ge,
|
|
805
|
+
(U, he) => (I.current = he, !1),
|
|
806
|
+
z
|
|
807
|
+
),
|
|
808
|
+
x.registerCommand(
|
|
809
|
+
ue,
|
|
810
|
+
_,
|
|
811
|
+
z
|
|
812
|
+
),
|
|
813
|
+
x.registerCommand(
|
|
814
|
+
se,
|
|
815
|
+
_,
|
|
816
|
+
z
|
|
817
|
+
),
|
|
818
|
+
x.registerCommand(
|
|
819
|
+
pe,
|
|
820
|
+
(U) => U.target === r.current ? (U.preventDefault(), !0) : !1,
|
|
821
|
+
z
|
|
822
|
+
),
|
|
823
|
+
x.registerCommand(
|
|
824
|
+
me,
|
|
825
|
+
m,
|
|
826
|
+
z
|
|
827
|
+
),
|
|
828
|
+
x.registerCommand(
|
|
829
|
+
we,
|
|
830
|
+
m,
|
|
831
|
+
z
|
|
832
|
+
),
|
|
833
|
+
x.registerCommand(xe, u, z),
|
|
834
|
+
x.registerCommand(Ce, w, z)
|
|
835
|
+
);
|
|
836
|
+
return R == null || R.addEventListener("contextmenu", E), () => {
|
|
837
|
+
M = !1, H(), R == null || R.removeEventListener("contextmenu", E);
|
|
838
|
+
};
|
|
839
|
+
}, [
|
|
840
|
+
c,
|
|
841
|
+
x,
|
|
842
|
+
y,
|
|
843
|
+
a,
|
|
844
|
+
e,
|
|
845
|
+
m,
|
|
846
|
+
u,
|
|
847
|
+
w,
|
|
848
|
+
_,
|
|
849
|
+
E,
|
|
850
|
+
g
|
|
851
|
+
]);
|
|
852
|
+
const b = () => {
|
|
853
|
+
x.update(() => {
|
|
854
|
+
const M = q(e);
|
|
855
|
+
J(M) && M.setShowCaption(!0);
|
|
856
|
+
});
|
|
857
|
+
}, v = (M, R) => {
|
|
858
|
+
setTimeout(() => {
|
|
859
|
+
N(!1);
|
|
860
|
+
}, 200), x.update(() => {
|
|
861
|
+
const H = q(e);
|
|
862
|
+
console.log(H, "node"), J(H) && H.setWidthAndHeight(M, R);
|
|
863
|
+
});
|
|
864
|
+
}, L = () => {
|
|
865
|
+
S || N(!0);
|
|
866
|
+
}, F = a && T(P) && !y, Z = a || y;
|
|
867
|
+
return /* @__PURE__ */ D.jsx(Me, { fallback: null, children: /* @__PURE__ */ D.jsxs(D.Fragment, { children: [
|
|
868
|
+
/* @__PURE__ */ D.jsx("div", { draggable: F, children: /* @__PURE__ */ D.jsx(
|
|
869
|
+
$e,
|
|
870
|
+
{
|
|
871
|
+
className: Z ? `focused ${T(P) ? "draggable" : ""}` : null,
|
|
872
|
+
src: l,
|
|
873
|
+
altText: t,
|
|
874
|
+
width: o,
|
|
875
|
+
height: n,
|
|
876
|
+
maxWidth: i,
|
|
877
|
+
imageRef: r,
|
|
878
|
+
startCrop: S,
|
|
879
|
+
setStartCrop: X,
|
|
880
|
+
isFocused: Z,
|
|
881
|
+
nodeKey: e
|
|
882
|
+
}
|
|
883
|
+
) }),
|
|
884
|
+
p && /* @__PURE__ */ D.jsx("div", { className: "image-caption-container", children: /* @__PURE__ */ D.jsx(Re, { initialEditor: s, children: /* @__PURE__ */ D.jsx(
|
|
885
|
+
fe,
|
|
886
|
+
{
|
|
887
|
+
contentEditable: /* @__PURE__ */ D.jsx(ye, { className: "ImageNode__contentEditable" }),
|
|
888
|
+
placeholder: /* @__PURE__ */ D.jsx(De, { className: "ImageNode__placeholder", children: "Enter a caption..." }),
|
|
889
|
+
ErrorBoundary: ve
|
|
890
|
+
}
|
|
891
|
+
) }) }),
|
|
892
|
+
!S && h && T(P) && Z && /* @__PURE__ */ D.jsx(
|
|
893
|
+
Ne,
|
|
894
|
+
{
|
|
895
|
+
showCaption: p,
|
|
896
|
+
setShowCaption: b,
|
|
897
|
+
editor: x,
|
|
898
|
+
buttonRef: d,
|
|
899
|
+
maxWidth: i,
|
|
900
|
+
onResizeStart: S ? () => {
|
|
901
|
+
} : L,
|
|
902
|
+
onResizeEnd: S ? () => {
|
|
903
|
+
} : v,
|
|
904
|
+
captionsEnabled: !1,
|
|
905
|
+
imageRef: r
|
|
906
|
+
}
|
|
907
|
+
)
|
|
908
|
+
] }) });
|
|
909
|
+
}
|
|
910
|
+
export {
|
|
911
|
+
se as RIGHT_CLICK_IMAGE_COMMAND,
|
|
912
|
+
Ae as default
|
|
913
|
+
};
|
|
914
|
+
//# sourceMappingURL=ImageComponent-8d6f3ac9.js.map
|