@haklex/rich-renderer-image 0.0.80 → 0.0.82
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/ImageRenderer-BUTTEOl6.js +131 -0
- package/dist/index.mjs +613 -672
- package/dist/rich-renderer-image.css +2 -1
- package/dist/static.mjs +2 -4
- package/package.json +4 -4
- package/dist/ImageRenderer-DyeaT08P.js +0 -130
package/dist/index.mjs
CHANGED
|
@@ -1,703 +1,644 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as root, S as replaceUploadArea, _ as imageState, a as editInput, c as editToolbar, d as editToolbarVisible, f as editTrigger, g as image, h as frameEditMode, i as editFieldIcon, l as editToolbarButton, m as frame, o as editPanel, r as editField, s as editPlaceholder, t as ImageRenderer, u as editToolbarButtonDanger, v as imageVisible, w as semanticClassNames } from "./ImageRenderer-BUTTEOl6.js";
|
|
2
2
|
import { useRendererMode } from "@haklex/rich-editor";
|
|
3
3
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
4
|
-
import { atom, createStore,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { $
|
|
4
|
+
import { Provider, atom, createStore, useAtomValue, useSetAtom, useStore } from "jotai";
|
|
5
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
6
|
+
import { computeImageMeta, decodeThumbHash } from "@haklex/rich-editor/renderers";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { ActionBar, ActionButton, Popover, PopoverPanel, PopoverTrigger, SegmentedControl } from "@haklex/rich-editor-ui";
|
|
9
|
+
import { Captions, Copy, Download, ExternalLink, ImageIcon, Loader2, Replace, Trash2, Type, Upload } from "lucide-react";
|
|
10
|
+
import { $createImageNode, $isImageNode } from "@haklex/rich-editor/nodes";
|
|
11
11
|
import { useImageUpload } from "@haklex/rich-editor/plugins";
|
|
12
12
|
import { $getNearestNodeFromDOMNode } from "lexical";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
return void 0;
|
|
13
|
+
//#region src/atoms.ts
|
|
14
|
+
function getCaptionText(altText, caption) {
|
|
15
|
+
if (caption) return caption;
|
|
16
|
+
if (!altText) return void 0;
|
|
17
|
+
if (altText.startsWith("!") || altText.startsWith("¡")) return altText.slice(1);
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
19
|
+
var srcAtom = atom("");
|
|
20
|
+
var altTextAtom = atom("");
|
|
21
|
+
var widthAtom = atom();
|
|
22
|
+
var heightAtom = atom();
|
|
23
|
+
var captionAtom = atom();
|
|
24
|
+
var thumbhashAtom = atom();
|
|
25
|
+
var accentAtom = atom();
|
|
26
|
+
var loadStateAtom = atom("loading");
|
|
27
|
+
var hoveringAtom = atom(false);
|
|
28
|
+
var metaOpenAtom = atom(false);
|
|
29
|
+
var replaceOpenAtom = atom(false);
|
|
30
|
+
var toolbarVisibleAtom = atom((get) => get(hoveringAtom) || get(metaOpenAtom) || get(replaceOpenAtom));
|
|
31
|
+
var focusCaptionOnOpenAtom = atom(false);
|
|
32
|
+
var editSrcAtom = atom("");
|
|
33
|
+
var editAltTextAtom = atom("");
|
|
34
|
+
var editCaptionAtom = atom("");
|
|
35
|
+
var replaceModeAtom = atom("upload");
|
|
36
|
+
var replaceUrlAtom = atom("");
|
|
37
|
+
var replacePreviewAtom = atom(null);
|
|
38
|
+
var replaceMetaAtom = atom(null);
|
|
39
|
+
var replaceLoadingAtom = atom(false);
|
|
40
|
+
var replaceErrorAtom = atom(null);
|
|
41
|
+
var wrapperRefAtom = atom({ current: null });
|
|
42
|
+
var fileInputRefAtom = atom({ current: null });
|
|
43
|
+
var placeholderUrlAtom = atom((get) => {
|
|
44
|
+
const thumbhash = get(thumbhashAtom);
|
|
45
|
+
return thumbhash ? decodeThumbHash(thumbhash) : void 0;
|
|
47
46
|
});
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
var captionTextAtom = atom((get) => getCaptionText(get(altTextAtom), get(captionAtom)));
|
|
48
|
+
var frameStyleAtom = atom((get) => {
|
|
49
|
+
const placeholderUrl = get(placeholderUrlAtom);
|
|
50
|
+
const accent = get(accentAtom);
|
|
51
|
+
const loadState = get(loadStateAtom);
|
|
52
|
+
const width = get(widthAtom);
|
|
53
|
+
const height = get(heightAtom);
|
|
54
|
+
return {
|
|
55
|
+
backgroundColor: loadState !== "loaded" && !placeholderUrl ? accent || "#f5f5f5" : "transparent",
|
|
56
|
+
backgroundImage: placeholderUrl && loadState !== "loaded" ? `url(${placeholderUrl})` : void 0,
|
|
57
|
+
backgroundSize: "cover",
|
|
58
|
+
width: width ? Math.min(width, 1200) : void 0,
|
|
59
|
+
maxWidth: "100%",
|
|
60
|
+
...width && height ? { aspectRatio: `${width} / ${height}` } : {}
|
|
61
|
+
};
|
|
50
62
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
props.thumbhash,
|
|
111
|
-
props.accent
|
|
112
|
-
]);
|
|
113
|
-
useEffect(() => {
|
|
114
|
-
store.set(editSrcAtom, props.src);
|
|
115
|
-
store.set(editAltTextAtom, props.altText);
|
|
116
|
-
store.set(editCaptionAtom, props.caption || "");
|
|
117
|
-
}, [store, props.src, props.altText, props.caption]);
|
|
118
|
-
useEffect(() => {
|
|
119
|
-
store.set(loadStateAtom, props.src ? "loading" : "error");
|
|
120
|
-
if (!props.src) store.set(replaceOpenAtom, true);
|
|
121
|
-
}, [store, props.src]);
|
|
122
|
-
return /* @__PURE__ */ jsx(Provider, { store, children });
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/ImageEditContext.tsx
|
|
65
|
+
function ImageEditProvider({ props, children }) {
|
|
66
|
+
const wrapperRef = useRef(null);
|
|
67
|
+
const fileInputRef = useRef(null);
|
|
68
|
+
const [store] = useState(() => {
|
|
69
|
+
const s = createStore();
|
|
70
|
+
s.set(srcAtom, props.src);
|
|
71
|
+
s.set(altTextAtom, props.altText);
|
|
72
|
+
s.set(widthAtom, props.width);
|
|
73
|
+
s.set(heightAtom, props.height);
|
|
74
|
+
s.set(captionAtom, props.caption);
|
|
75
|
+
s.set(thumbhashAtom, props.thumbhash);
|
|
76
|
+
s.set(accentAtom, props.accent);
|
|
77
|
+
s.set(editSrcAtom, props.src);
|
|
78
|
+
s.set(editAltTextAtom, props.altText);
|
|
79
|
+
s.set(editCaptionAtom, props.caption || "");
|
|
80
|
+
s.set(wrapperRefAtom, wrapperRef);
|
|
81
|
+
s.set(fileInputRefAtom, fileInputRef);
|
|
82
|
+
s.set(loadStateAtom, props.src ? "loading" : "error");
|
|
83
|
+
s.set(replaceOpenAtom, !props.src);
|
|
84
|
+
return s;
|
|
85
|
+
});
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
store.set(srcAtom, props.src);
|
|
88
|
+
store.set(altTextAtom, props.altText);
|
|
89
|
+
store.set(widthAtom, props.width);
|
|
90
|
+
store.set(heightAtom, props.height);
|
|
91
|
+
store.set(captionAtom, props.caption);
|
|
92
|
+
store.set(thumbhashAtom, props.thumbhash);
|
|
93
|
+
store.set(accentAtom, props.accent);
|
|
94
|
+
}, [
|
|
95
|
+
store,
|
|
96
|
+
props.src,
|
|
97
|
+
props.altText,
|
|
98
|
+
props.width,
|
|
99
|
+
props.height,
|
|
100
|
+
props.caption,
|
|
101
|
+
props.thumbhash,
|
|
102
|
+
props.accent
|
|
103
|
+
]);
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
store.set(editSrcAtom, props.src);
|
|
106
|
+
store.set(editAltTextAtom, props.altText);
|
|
107
|
+
store.set(editCaptionAtom, props.caption || "");
|
|
108
|
+
}, [
|
|
109
|
+
store,
|
|
110
|
+
props.src,
|
|
111
|
+
props.altText,
|
|
112
|
+
props.caption
|
|
113
|
+
]);
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
store.set(loadStateAtom, props.src ? "loading" : "error");
|
|
116
|
+
if (!props.src) store.set(replaceOpenAtom, true);
|
|
117
|
+
}, [store, props.src]);
|
|
118
|
+
return /* @__PURE__ */ jsx(Provider, {
|
|
119
|
+
store,
|
|
120
|
+
children
|
|
121
|
+
});
|
|
123
122
|
}
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/useImageActions.ts
|
|
124
125
|
function isSafeImageSrc(src) {
|
|
125
|
-
|
|
126
|
+
return !/^(?:javascript\s*:|vbscript\s*:|data\s*:(?!image\/))/i.test(src);
|
|
126
127
|
}
|
|
127
128
|
function readAsDataUrl(file) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
return new Promise((resolve, reject) => {
|
|
130
|
+
const reader = new FileReader();
|
|
131
|
+
reader.onload = () => resolve(String(reader.result));
|
|
132
|
+
reader.onerror = () => reject(reader.error ?? /* @__PURE__ */ new Error("File read failed"));
|
|
133
|
+
reader.readAsDataURL(file);
|
|
134
|
+
});
|
|
134
135
|
}
|
|
135
136
|
function loadImageByUrl(src) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
137
|
+
return new Promise((resolve, reject) => {
|
|
138
|
+
const image = new Image();
|
|
139
|
+
image.onload = () => {
|
|
140
|
+
resolve({
|
|
141
|
+
width: image.naturalWidth || image.width,
|
|
142
|
+
height: image.naturalHeight || image.height
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
image.onerror = () => reject(/* @__PURE__ */ new Error("Image load failed"));
|
|
146
|
+
image.src = src;
|
|
147
|
+
});
|
|
147
148
|
}
|
|
148
149
|
function useImageActions() {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
150
|
+
const store = useStore();
|
|
151
|
+
const [editor] = useLexicalComposerContext();
|
|
152
|
+
const uploadImage = useImageUpload();
|
|
153
|
+
const withImageNode = useCallback((updater) => {
|
|
154
|
+
const wrapperRef = store.get(wrapperRefAtom);
|
|
155
|
+
if (!wrapperRef.current) return;
|
|
156
|
+
editor.update(() => {
|
|
157
|
+
const node = $getNearestNodeFromDOMNode(wrapperRef.current);
|
|
158
|
+
if ($isImageNode(node)) updater(node);
|
|
159
|
+
});
|
|
160
|
+
}, [editor, store]);
|
|
161
|
+
const closeReplacePanel = useCallback(() => {
|
|
162
|
+
store.set(replaceOpenAtom, false);
|
|
163
|
+
store.set(replaceModeAtom, "upload");
|
|
164
|
+
store.set(replaceUrlAtom, "");
|
|
165
|
+
store.set(replacePreviewAtom, null);
|
|
166
|
+
store.set(replaceMetaAtom, null);
|
|
167
|
+
store.set(replaceLoadingAtom, false);
|
|
168
|
+
store.set(replaceErrorAtom, null);
|
|
169
|
+
}, [store]);
|
|
170
|
+
const commitMeta = useCallback(() => {
|
|
171
|
+
const editSrc = store.get(editSrcAtom).trim();
|
|
172
|
+
if (!editSrc || !isSafeImageSrc(editSrc)) return;
|
|
173
|
+
withImageNode((node) => {
|
|
174
|
+
node.setSrc(editSrc);
|
|
175
|
+
node.setAltText(store.get(editAltTextAtom).trim());
|
|
176
|
+
node.setCaption(store.get(editCaptionAtom).trim() || void 0);
|
|
177
|
+
});
|
|
178
|
+
store.set(metaOpenAtom, false);
|
|
179
|
+
}, [store, withImageNode]);
|
|
180
|
+
const handleDelete = useCallback(() => {
|
|
181
|
+
const wrapperRef = store.get(wrapperRefAtom);
|
|
182
|
+
if (!wrapperRef.current) return;
|
|
183
|
+
editor.update(() => {
|
|
184
|
+
const node = $getNearestNodeFromDOMNode(wrapperRef.current);
|
|
185
|
+
if (node) node.remove();
|
|
186
|
+
});
|
|
187
|
+
store.set(metaOpenAtom, false);
|
|
188
|
+
closeReplacePanel();
|
|
189
|
+
}, [
|
|
190
|
+
closeReplacePanel,
|
|
191
|
+
editor,
|
|
192
|
+
store
|
|
193
|
+
]);
|
|
194
|
+
const handleOpen = useCallback(() => {
|
|
195
|
+
const src = store.get(srcAtom);
|
|
196
|
+
if (src) window.open(src, "_blank", "noopener,noreferrer");
|
|
197
|
+
}, [store]);
|
|
198
|
+
const handleDownload = useCallback(() => {
|
|
199
|
+
const src = store.get(srcAtom);
|
|
200
|
+
if (!src) return;
|
|
201
|
+
const link = document.createElement("a");
|
|
202
|
+
link.href = src;
|
|
203
|
+
link.download = store.get(altTextAtom) || "image";
|
|
204
|
+
link.click();
|
|
205
|
+
}, [store]);
|
|
206
|
+
const handleDuplicate = useCallback(() => {
|
|
207
|
+
withImageNode((node) => {
|
|
208
|
+
const copy = $createImageNode({
|
|
209
|
+
src: node.getSrc(),
|
|
210
|
+
altText: node.getAltText(),
|
|
211
|
+
width: node.getWidth(),
|
|
212
|
+
height: node.getHeight(),
|
|
213
|
+
caption: node.getCaption(),
|
|
214
|
+
thumbhash: node.getThumbhash(),
|
|
215
|
+
accent: node.getAccent()
|
|
216
|
+
});
|
|
217
|
+
node.insertAfter(copy);
|
|
218
|
+
});
|
|
219
|
+
}, [withImageNode]);
|
|
220
|
+
return {
|
|
221
|
+
commitMeta,
|
|
222
|
+
closeReplacePanel,
|
|
223
|
+
handleReplaceFile: useCallback(async (file) => {
|
|
224
|
+
if (!file || !file.type.startsWith("image/")) return;
|
|
225
|
+
store.set(replaceLoadingAtom, true);
|
|
226
|
+
store.set(replaceErrorAtom, null);
|
|
227
|
+
try {
|
|
228
|
+
const fallbackUploader = async (nextFile) => ({
|
|
229
|
+
src: await readAsDataUrl(nextFile),
|
|
230
|
+
altText: nextFile.name
|
|
231
|
+
});
|
|
232
|
+
const uploader = uploadImage ?? fallbackUploader;
|
|
233
|
+
const [result, meta] = await Promise.all([uploader(file), computeImageMeta(file)]);
|
|
234
|
+
withImageNode((node) => {
|
|
235
|
+
node.setSrc(result.src);
|
|
236
|
+
node.setAltText(result.altText ?? file.name);
|
|
237
|
+
node.setDimensions(result.width ?? meta.width, result.height ?? meta.height);
|
|
238
|
+
node.setThumbhash(result.thumbhash ?? meta.thumbhash);
|
|
239
|
+
});
|
|
240
|
+
closeReplacePanel();
|
|
241
|
+
} catch {
|
|
242
|
+
store.set(replaceErrorAtom, "Failed to replace image");
|
|
243
|
+
} finally {
|
|
244
|
+
store.set(replaceLoadingAtom, false);
|
|
245
|
+
}
|
|
246
|
+
}, [
|
|
247
|
+
closeReplacePanel,
|
|
248
|
+
store,
|
|
249
|
+
uploadImage,
|
|
250
|
+
withImageNode
|
|
251
|
+
]),
|
|
252
|
+
handlePreviewUrl: useCallback(async () => {
|
|
253
|
+
const url = store.get(replaceUrlAtom).trim();
|
|
254
|
+
if (!url || !isSafeImageSrc(url)) {
|
|
255
|
+
store.set(replaceErrorAtom, "Invalid image URL");
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
store.set(replaceLoadingAtom, true);
|
|
259
|
+
store.set(replaceErrorAtom, null);
|
|
260
|
+
try {
|
|
261
|
+
const meta = await loadImageByUrl(url);
|
|
262
|
+
store.set(replacePreviewAtom, url);
|
|
263
|
+
store.set(replaceMetaAtom, meta);
|
|
264
|
+
} catch {
|
|
265
|
+
store.set(replacePreviewAtom, null);
|
|
266
|
+
store.set(replaceMetaAtom, null);
|
|
267
|
+
store.set(replaceErrorAtom, "Image URL could not be loaded");
|
|
268
|
+
} finally {
|
|
269
|
+
store.set(replaceLoadingAtom, false);
|
|
270
|
+
}
|
|
271
|
+
}, [store]),
|
|
272
|
+
handleReplaceByUrl: useCallback(() => {
|
|
273
|
+
const preview = store.get(replacePreviewAtom);
|
|
274
|
+
if (!preview || !isSafeImageSrc(preview)) return;
|
|
275
|
+
const meta = store.get(replaceMetaAtom);
|
|
276
|
+
withImageNode((node) => {
|
|
277
|
+
node.setSrc(preview);
|
|
278
|
+
node.setDimensions(meta?.width, meta?.height);
|
|
279
|
+
node.setThumbhash(void 0);
|
|
280
|
+
});
|
|
281
|
+
closeReplacePanel();
|
|
282
|
+
}, [
|
|
283
|
+
closeReplacePanel,
|
|
284
|
+
store,
|
|
285
|
+
withImageNode
|
|
286
|
+
]),
|
|
287
|
+
handleReplaceOpenChange: useCallback((nextOpen) => {
|
|
288
|
+
store.set(replaceOpenAtom, nextOpen);
|
|
289
|
+
if (!nextOpen) closeReplacePanel();
|
|
290
|
+
}, [closeReplacePanel, store]),
|
|
291
|
+
handleOpen,
|
|
292
|
+
handleDuplicate,
|
|
293
|
+
handleDownload,
|
|
294
|
+
handleDelete
|
|
295
|
+
};
|
|
295
296
|
}
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/EditMetaPopover.tsx
|
|
296
299
|
function EditMetaPopover() {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
className: `${editInput} ${semanticClassNames.editInput}`,
|
|
366
|
-
placeholder: "Caption (optional)",
|
|
367
|
-
ref: captionInputRef,
|
|
368
|
-
type: "text",
|
|
369
|
-
value: editCaption,
|
|
370
|
-
onChange: (event) => setEditCaption(event.target.value)
|
|
371
|
-
}
|
|
372
|
-
)
|
|
373
|
-
] }),
|
|
374
|
-
/* @__PURE__ */ jsxs(ActionBar, { children: [
|
|
375
|
-
/* @__PURE__ */ jsx(ActionButton, { onClick: () => setMetaOpen(false), children: "Close" }),
|
|
376
|
-
/* @__PURE__ */ jsx(ActionButton, { variant: "accent", onClick: commitMeta, children: "Save" })
|
|
377
|
-
] })
|
|
378
|
-
] });
|
|
300
|
+
const editSrc = useAtomValue(editSrcAtom);
|
|
301
|
+
const setEditSrc = useSetAtom(editSrcAtom);
|
|
302
|
+
const editAltText = useAtomValue(editAltTextAtom);
|
|
303
|
+
const setEditAltText = useSetAtom(editAltTextAtom);
|
|
304
|
+
const editCaption = useAtomValue(editCaptionAtom);
|
|
305
|
+
const setEditCaption = useSetAtom(editCaptionAtom);
|
|
306
|
+
const setMetaOpen = useSetAtom(metaOpenAtom);
|
|
307
|
+
const { commitMeta } = useImageActions();
|
|
308
|
+
const captionInputRef = useRef(null);
|
|
309
|
+
const focusCaptionOnOpen = useAtomValue(focusCaptionOnOpenAtom);
|
|
310
|
+
const setFocusCaptionOnOpen = useSetAtom(focusCaptionOnOpenAtom);
|
|
311
|
+
useEffect(() => {
|
|
312
|
+
if (focusCaptionOnOpen && captionInputRef.current) {
|
|
313
|
+
captionInputRef.current.focus();
|
|
314
|
+
captionInputRef.current.select();
|
|
315
|
+
setFocusCaptionOnOpen(false);
|
|
316
|
+
}
|
|
317
|
+
}, [focusCaptionOnOpen, setFocusCaptionOnOpen]);
|
|
318
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
319
|
+
/* @__PURE__ */ jsxs("div", {
|
|
320
|
+
className: `${editField} ${semanticClassNames.editField}`,
|
|
321
|
+
children: [/* @__PURE__ */ jsx(ImageIcon, {
|
|
322
|
+
className: `${editFieldIcon} ${semanticClassNames.editFieldIcon}`,
|
|
323
|
+
size: 14
|
|
324
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
325
|
+
className: `${editInput} ${semanticClassNames.editInput}`,
|
|
326
|
+
placeholder: "Image URL",
|
|
327
|
+
type: "url",
|
|
328
|
+
value: editSrc,
|
|
329
|
+
onChange: (event) => setEditSrc(event.target.value)
|
|
330
|
+
})]
|
|
331
|
+
}),
|
|
332
|
+
/* @__PURE__ */ jsxs("div", {
|
|
333
|
+
className: `${editField} ${semanticClassNames.editField}`,
|
|
334
|
+
children: [/* @__PURE__ */ jsx(Type, {
|
|
335
|
+
className: `${editFieldIcon} ${semanticClassNames.editFieldIcon}`,
|
|
336
|
+
size: 14
|
|
337
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
338
|
+
className: `${editInput} ${semanticClassNames.editInput}`,
|
|
339
|
+
placeholder: "Alt text",
|
|
340
|
+
type: "text",
|
|
341
|
+
value: editAltText,
|
|
342
|
+
onChange: (event) => setEditAltText(event.target.value)
|
|
343
|
+
})]
|
|
344
|
+
}),
|
|
345
|
+
/* @__PURE__ */ jsxs("div", {
|
|
346
|
+
className: `${editField} ${semanticClassNames.editField}`,
|
|
347
|
+
children: [/* @__PURE__ */ jsx(Captions, {
|
|
348
|
+
className: `${editFieldIcon} ${semanticClassNames.editFieldIcon}`,
|
|
349
|
+
size: 14
|
|
350
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
351
|
+
className: `${editInput} ${semanticClassNames.editInput}`,
|
|
352
|
+
placeholder: "Caption (optional)",
|
|
353
|
+
ref: captionInputRef,
|
|
354
|
+
type: "text",
|
|
355
|
+
value: editCaption,
|
|
356
|
+
onChange: (event) => setEditCaption(event.target.value)
|
|
357
|
+
})]
|
|
358
|
+
}),
|
|
359
|
+
/* @__PURE__ */ jsxs(ActionBar, { children: [/* @__PURE__ */ jsx(ActionButton, {
|
|
360
|
+
onClick: () => setMetaOpen(false),
|
|
361
|
+
children: "Close"
|
|
362
|
+
}), /* @__PURE__ */ jsx(ActionButton, {
|
|
363
|
+
variant: "accent",
|
|
364
|
+
onClick: commitMeta,
|
|
365
|
+
children: "Save"
|
|
366
|
+
})] })
|
|
367
|
+
] });
|
|
379
368
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
369
|
+
//#endregion
|
|
370
|
+
//#region src/ReplacePanel.tsx
|
|
371
|
+
var replaceModeItems = [{
|
|
372
|
+
value: "upload",
|
|
373
|
+
label: "Upload"
|
|
374
|
+
}, {
|
|
375
|
+
value: "url",
|
|
376
|
+
label: "URL"
|
|
377
|
+
}];
|
|
384
378
|
function ReplacePanel() {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
)
|
|
459
|
-
] }),
|
|
460
|
-
/* @__PURE__ */ jsxs(ActionBar, { children: [
|
|
461
|
-
/* @__PURE__ */ jsx(
|
|
462
|
-
ActionButton,
|
|
463
|
-
{
|
|
464
|
-
disabled: replaceLoading || !replaceUrl.trim(),
|
|
465
|
-
onClick: handlePreviewUrl,
|
|
466
|
-
children: "Preview"
|
|
467
|
-
}
|
|
468
|
-
),
|
|
469
|
-
/* @__PURE__ */ jsx(ActionButton, { disabled: !replacePreview$1, variant: "accent", onClick: handleReplaceByUrl, children: "Apply" })
|
|
470
|
-
] })
|
|
471
|
-
] }),
|
|
472
|
-
replaceError && /* @__PURE__ */ jsx("span", { className: `${panelHint} ${semanticClassNames.panelHint}`, children: replaceError }),
|
|
473
|
-
replacePreview$1 && /* @__PURE__ */ jsx("div", { className: `${replacePreview} ${semanticClassNames.replacePreview}`, children: /* @__PURE__ */ jsx("img", { alt: "Replace preview", src: replacePreview$1 }) })
|
|
474
|
-
] });
|
|
379
|
+
const replaceMode = useAtomValue(replaceModeAtom);
|
|
380
|
+
const setReplaceMode = useSetAtom(replaceModeAtom);
|
|
381
|
+
const replaceUrl = useAtomValue(replaceUrlAtom);
|
|
382
|
+
const setReplaceUrl = useSetAtom(replaceUrlAtom);
|
|
383
|
+
const replacePreview$1 = useAtomValue(replacePreviewAtom);
|
|
384
|
+
const replaceError = useAtomValue(replaceErrorAtom);
|
|
385
|
+
const replaceLoading = useAtomValue(replaceLoadingAtom);
|
|
386
|
+
const fileInputRef = useAtomValue(fileInputRefAtom);
|
|
387
|
+
const { handleReplaceFile, handlePreviewUrl, handleReplaceByUrl } = useImageActions();
|
|
388
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
389
|
+
/* @__PURE__ */ jsx(SegmentedControl, {
|
|
390
|
+
fullWidth: true,
|
|
391
|
+
items: replaceModeItems,
|
|
392
|
+
value: replaceMode,
|
|
393
|
+
onChange: setReplaceMode
|
|
394
|
+
}),
|
|
395
|
+
replaceMode === "upload" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("input", {
|
|
396
|
+
accept: "image/*",
|
|
397
|
+
ref: fileInputRef,
|
|
398
|
+
style: { display: "none" },
|
|
399
|
+
type: "file",
|
|
400
|
+
onChange: (event) => {
|
|
401
|
+
handleReplaceFile(event.currentTarget.files?.[0] ?? null);
|
|
402
|
+
event.currentTarget.value = "";
|
|
403
|
+
}
|
|
404
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
405
|
+
className: `${replaceUploadArea} ${semanticClassNames.replaceUploadArea}`,
|
|
406
|
+
type: "button",
|
|
407
|
+
onClick: () => fileInputRef.current?.click(),
|
|
408
|
+
children: replaceLoading ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Loader2, { size: 16 }), /* @__PURE__ */ jsx("span", { children: "Uploading image..." })] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Upload, { size: 16 }), /* @__PURE__ */ jsx("span", { children: "Click to upload image" })] })
|
|
409
|
+
})] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
410
|
+
className: `${editField} ${semanticClassNames.editField}`,
|
|
411
|
+
children: [/* @__PURE__ */ jsx(ImageIcon, {
|
|
412
|
+
className: `${editFieldIcon} ${semanticClassNames.editFieldIcon}`,
|
|
413
|
+
size: 14
|
|
414
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
415
|
+
className: `${editInput} ${semanticClassNames.editInput}`,
|
|
416
|
+
placeholder: "https://example.com/image.jpg",
|
|
417
|
+
type: "url",
|
|
418
|
+
value: replaceUrl,
|
|
419
|
+
onChange: (event) => setReplaceUrl(event.target.value),
|
|
420
|
+
onKeyDown: (event) => {
|
|
421
|
+
if (event.key === "Enter") {
|
|
422
|
+
event.preventDefault();
|
|
423
|
+
handlePreviewUrl();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
})]
|
|
427
|
+
}), /* @__PURE__ */ jsxs(ActionBar, { children: [/* @__PURE__ */ jsx(ActionButton, {
|
|
428
|
+
disabled: replaceLoading || !replaceUrl.trim(),
|
|
429
|
+
onClick: handlePreviewUrl,
|
|
430
|
+
children: "Preview"
|
|
431
|
+
}), /* @__PURE__ */ jsx(ActionButton, {
|
|
432
|
+
disabled: !replacePreview$1,
|
|
433
|
+
variant: "accent",
|
|
434
|
+
onClick: handleReplaceByUrl,
|
|
435
|
+
children: "Apply"
|
|
436
|
+
})] })] }),
|
|
437
|
+
replaceError && /* @__PURE__ */ jsx("span", {
|
|
438
|
+
className: `_1n94osfw ${semanticClassNames.panelHint}`,
|
|
439
|
+
children: replaceError
|
|
440
|
+
}),
|
|
441
|
+
replacePreview$1 && /* @__PURE__ */ jsx("div", {
|
|
442
|
+
className: `_1n94osfv ${semanticClassNames.replacePreview}`,
|
|
443
|
+
children: /* @__PURE__ */ jsx("img", {
|
|
444
|
+
alt: "Replace preview",
|
|
445
|
+
src: replacePreview$1
|
|
446
|
+
})
|
|
447
|
+
})
|
|
448
|
+
] });
|
|
475
449
|
}
|
|
450
|
+
//#endregion
|
|
451
|
+
//#region src/ImageEditToolbar.tsx
|
|
476
452
|
function ImageEditToolbar() {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
e.preventDefault();
|
|
566
|
-
e.stopPropagation();
|
|
567
|
-
},
|
|
568
|
-
children: /* @__PURE__ */ jsx(Download, { size: 14 })
|
|
569
|
-
}
|
|
570
|
-
),
|
|
571
|
-
/* @__PURE__ */ jsx(
|
|
572
|
-
"button",
|
|
573
|
-
{
|
|
574
|
-
className: `${editToolbarButton} ${semanticClassNames.editToolbarButton} ${editToolbarButtonDanger} ${semanticClassNames.editToolbarButtonDanger}`,
|
|
575
|
-
title: "Remove image",
|
|
576
|
-
type: "button",
|
|
577
|
-
onClick: handleDelete,
|
|
578
|
-
onMouseDown: (e) => {
|
|
579
|
-
e.preventDefault();
|
|
580
|
-
e.stopPropagation();
|
|
581
|
-
},
|
|
582
|
-
children: /* @__PURE__ */ jsx(Trash2, { size: 14 })
|
|
583
|
-
}
|
|
584
|
-
)
|
|
585
|
-
]
|
|
586
|
-
}
|
|
587
|
-
);
|
|
453
|
+
const toolbarVisible = useAtomValue(toolbarVisibleAtom);
|
|
454
|
+
const metaOpen = useAtomValue(metaOpenAtom);
|
|
455
|
+
const setMetaOpen = useSetAtom(metaOpenAtom);
|
|
456
|
+
const replaceOpen = useAtomValue(replaceOpenAtom);
|
|
457
|
+
const { handleReplaceOpenChange, handleOpen, handleDuplicate, handleDownload, handleDelete } = useImageActions();
|
|
458
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
459
|
+
className: `${editToolbar} ${semanticClassNames.editToolbar} ${toolbarVisible ? `${editToolbarVisible} ${semanticClassNames.editToolbarVisible}` : ""}`,
|
|
460
|
+
children: [
|
|
461
|
+
/* @__PURE__ */ jsxs(Popover, {
|
|
462
|
+
open: metaOpen,
|
|
463
|
+
onOpenChange: (nextOpen) => {
|
|
464
|
+
setMetaOpen(nextOpen);
|
|
465
|
+
if (nextOpen) handleReplaceOpenChange(false);
|
|
466
|
+
},
|
|
467
|
+
children: [/* @__PURE__ */ jsx(PopoverTrigger, {
|
|
468
|
+
className: `${editToolbarButton} ${semanticClassNames.editToolbarButton}`,
|
|
469
|
+
title: "Edit details",
|
|
470
|
+
children: /* @__PURE__ */ jsx(Type, { size: 14 })
|
|
471
|
+
}), /* @__PURE__ */ jsx(PopoverPanel, {
|
|
472
|
+
className: editPanel,
|
|
473
|
+
side: "bottom",
|
|
474
|
+
sideOffset: 8,
|
|
475
|
+
children: /* @__PURE__ */ jsx(EditMetaPopover, {})
|
|
476
|
+
})]
|
|
477
|
+
}),
|
|
478
|
+
/* @__PURE__ */ jsxs(Popover, {
|
|
479
|
+
open: replaceOpen,
|
|
480
|
+
onOpenChange: (nextOpen) => {
|
|
481
|
+
handleReplaceOpenChange(nextOpen);
|
|
482
|
+
if (nextOpen) setMetaOpen(false);
|
|
483
|
+
},
|
|
484
|
+
children: [/* @__PURE__ */ jsx(PopoverTrigger, {
|
|
485
|
+
className: `${editToolbarButton} ${semanticClassNames.editToolbarButton}`,
|
|
486
|
+
title: "Replace image",
|
|
487
|
+
children: /* @__PURE__ */ jsx(Replace, { size: 14 })
|
|
488
|
+
}), /* @__PURE__ */ jsx(PopoverPanel, {
|
|
489
|
+
className: editPanel,
|
|
490
|
+
side: "bottom",
|
|
491
|
+
sideOffset: 8,
|
|
492
|
+
children: /* @__PURE__ */ jsx(ReplacePanel, {})
|
|
493
|
+
})]
|
|
494
|
+
}),
|
|
495
|
+
/* @__PURE__ */ jsx("button", {
|
|
496
|
+
className: `${editToolbarButton} ${semanticClassNames.editToolbarButton}`,
|
|
497
|
+
title: "Open source",
|
|
498
|
+
type: "button",
|
|
499
|
+
onClick: handleOpen,
|
|
500
|
+
onMouseDown: (e) => {
|
|
501
|
+
e.preventDefault();
|
|
502
|
+
e.stopPropagation();
|
|
503
|
+
},
|
|
504
|
+
children: /* @__PURE__ */ jsx(ExternalLink, { size: 14 })
|
|
505
|
+
}),
|
|
506
|
+
/* @__PURE__ */ jsx("button", {
|
|
507
|
+
className: `${editToolbarButton} ${semanticClassNames.editToolbarButton}`,
|
|
508
|
+
title: "Duplicate",
|
|
509
|
+
type: "button",
|
|
510
|
+
onClick: handleDuplicate,
|
|
511
|
+
onMouseDown: (e) => {
|
|
512
|
+
e.preventDefault();
|
|
513
|
+
e.stopPropagation();
|
|
514
|
+
},
|
|
515
|
+
children: /* @__PURE__ */ jsx(Copy, { size: 14 })
|
|
516
|
+
}),
|
|
517
|
+
/* @__PURE__ */ jsx("button", {
|
|
518
|
+
className: `${editToolbarButton} ${semanticClassNames.editToolbarButton}`,
|
|
519
|
+
title: "Download",
|
|
520
|
+
type: "button",
|
|
521
|
+
onClick: handleDownload,
|
|
522
|
+
onMouseDown: (e) => {
|
|
523
|
+
e.preventDefault();
|
|
524
|
+
e.stopPropagation();
|
|
525
|
+
},
|
|
526
|
+
children: /* @__PURE__ */ jsx(Download, { size: 14 })
|
|
527
|
+
}),
|
|
528
|
+
/* @__PURE__ */ jsx("button", {
|
|
529
|
+
className: `${editToolbarButton} ${semanticClassNames.editToolbarButton} ${editToolbarButtonDanger} ${semanticClassNames.editToolbarButtonDanger}`,
|
|
530
|
+
title: "Remove image",
|
|
531
|
+
type: "button",
|
|
532
|
+
onClick: handleDelete,
|
|
533
|
+
onMouseDown: (e) => {
|
|
534
|
+
e.preventDefault();
|
|
535
|
+
e.stopPropagation();
|
|
536
|
+
},
|
|
537
|
+
children: /* @__PURE__ */ jsx(Trash2, { size: 14 })
|
|
538
|
+
})
|
|
539
|
+
]
|
|
540
|
+
});
|
|
588
541
|
}
|
|
542
|
+
//#endregion
|
|
543
|
+
//#region src/ReplacePopover.tsx
|
|
589
544
|
function ReplacePopover() {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
545
|
+
const replaceOpen = useAtomValue(replaceOpenAtom);
|
|
546
|
+
const { handleReplaceOpenChange } = useImageActions();
|
|
547
|
+
return /* @__PURE__ */ jsxs(Popover, {
|
|
548
|
+
open: replaceOpen,
|
|
549
|
+
onOpenChange: handleReplaceOpenChange,
|
|
550
|
+
children: [/* @__PURE__ */ jsxs(PopoverTrigger, {
|
|
551
|
+
className: `${editPlaceholder} ${semanticClassNames.editPlaceholder}`,
|
|
552
|
+
children: [/* @__PURE__ */ jsx(ImageIcon, { size: 24 }), /* @__PURE__ */ jsx("span", { children: "Click to add image" })]
|
|
553
|
+
}), /* @__PURE__ */ jsx(PopoverPanel, {
|
|
554
|
+
className: editPanel,
|
|
555
|
+
side: "bottom",
|
|
556
|
+
sideOffset: 8,
|
|
557
|
+
children: /* @__PURE__ */ jsx(ReplacePanel, {})
|
|
558
|
+
})]
|
|
559
|
+
});
|
|
605
560
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region src/ImageEditRenderer.tsx
|
|
563
|
+
var frameStateSemanticClass = {
|
|
564
|
+
loading: semanticClassNames.frameLoading,
|
|
565
|
+
loaded: semanticClassNames.frameLoaded,
|
|
566
|
+
error: semanticClassNames.frameError
|
|
610
567
|
};
|
|
611
568
|
function ImageEditRenderer(props) {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
return /* @__PURE__ */ jsx(ImageRenderer, { ...props });
|
|
615
|
-
}
|
|
616
|
-
return /* @__PURE__ */ jsx(ImageEditRendererInner, { ...props });
|
|
569
|
+
if (useRendererMode() !== "editor") return /* @__PURE__ */ jsx(ImageRenderer, { ...props });
|
|
570
|
+
return /* @__PURE__ */ jsx(ImageEditRendererInner, { ...props });
|
|
617
571
|
}
|
|
618
572
|
function ImageEditRendererInner(props) {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
573
|
+
const [editor] = useLexicalComposerContext();
|
|
574
|
+
if (!editor.isEditable()) return /* @__PURE__ */ jsx(ImageRenderer, { ...props });
|
|
575
|
+
return /* @__PURE__ */ jsx(ImageEditProvider, {
|
|
576
|
+
props,
|
|
577
|
+
children: /* @__PURE__ */ jsx(ImageEditContent, {})
|
|
578
|
+
});
|
|
625
579
|
}
|
|
626
580
|
function ImageEditContent() {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
{
|
|
689
|
-
className: `${caption} ${semanticClassNames.caption}`,
|
|
690
|
-
onClick: handleCaptionClick,
|
|
691
|
-
children: captionText
|
|
692
|
-
}
|
|
693
|
-
)
|
|
694
|
-
] }) : /* @__PURE__ */ jsx(ReplacePopover, {}),
|
|
695
|
-
src && /* @__PURE__ */ jsx(ImageEditToolbar, {})
|
|
696
|
-
]
|
|
697
|
-
}
|
|
698
|
-
);
|
|
581
|
+
const wrapperRef = useAtomValue(wrapperRefAtom);
|
|
582
|
+
const setHovering = useSetAtom(hoveringAtom);
|
|
583
|
+
const src = useAtomValue(srcAtom);
|
|
584
|
+
const loadState = useAtomValue(loadStateAtom);
|
|
585
|
+
const setLoadState = useSetAtom(loadStateAtom);
|
|
586
|
+
const frameStyle = useAtomValue(frameStyleAtom);
|
|
587
|
+
const altText = useAtomValue(altTextAtom);
|
|
588
|
+
const width = useAtomValue(widthAtom);
|
|
589
|
+
const height = useAtomValue(heightAtom);
|
|
590
|
+
const captionText = useAtomValue(captionTextAtom);
|
|
591
|
+
const setMetaOpen = useSetAtom(metaOpenAtom);
|
|
592
|
+
const setReplaceOpen = useSetAtom(replaceOpenAtom);
|
|
593
|
+
const setFocusCaptionOnOpen = useSetAtom(focusCaptionOnOpenAtom);
|
|
594
|
+
const handleCaptionClick = useCallback((e) => {
|
|
595
|
+
e.stopPropagation();
|
|
596
|
+
const scrollY = window.scrollY;
|
|
597
|
+
setReplaceOpen(false);
|
|
598
|
+
setMetaOpen(true);
|
|
599
|
+
setFocusCaptionOnOpen(true);
|
|
600
|
+
requestAnimationFrame(() => {
|
|
601
|
+
window.scrollTo({ top: scrollY });
|
|
602
|
+
});
|
|
603
|
+
}, [
|
|
604
|
+
setMetaOpen,
|
|
605
|
+
setReplaceOpen,
|
|
606
|
+
setFocusCaptionOnOpen
|
|
607
|
+
]);
|
|
608
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
609
|
+
className: `${editTrigger} ${semanticClassNames.editTrigger}`,
|
|
610
|
+
ref: wrapperRef,
|
|
611
|
+
onMouseEnter: () => setHovering(true),
|
|
612
|
+
onMouseLeave: () => setHovering(false),
|
|
613
|
+
children: [src ? /* @__PURE__ */ jsxs("figure", {
|
|
614
|
+
className: `${root} ${semanticClassNames.root}`,
|
|
615
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
616
|
+
className: `${frame} ${semanticClassNames.frame} ${frameEditMode} ${imageState[loadState]} ${frameStateSemanticClass[loadState]}`.trim(),
|
|
617
|
+
style: frameStyle,
|
|
618
|
+
children: [
|
|
619
|
+
/* @__PURE__ */ jsx("img", {
|
|
620
|
+
alt: altText,
|
|
621
|
+
className: `${image} ${loadState === "loaded" ? imageVisible : ""} ${semanticClassNames.image}`,
|
|
622
|
+
height,
|
|
623
|
+
loading: "lazy",
|
|
624
|
+
src,
|
|
625
|
+
width,
|
|
626
|
+
onError: () => setLoadState("error"),
|
|
627
|
+
onLoad: () => setLoadState("loaded")
|
|
628
|
+
}),
|
|
629
|
+
loadState === "loading" && /* @__PURE__ */ jsx("span", { className: `_1n94osfa ${semanticClassNames.loader}` }),
|
|
630
|
+
loadState === "error" && /* @__PURE__ */ jsx("span", {
|
|
631
|
+
className: `_1n94osfb ${semanticClassNames.errorBadge}`,
|
|
632
|
+
children: "Image failed to load"
|
|
633
|
+
})
|
|
634
|
+
]
|
|
635
|
+
}), captionText && /* @__PURE__ */ jsx("figcaption", {
|
|
636
|
+
className: `_1n94osfc ${semanticClassNames.caption}`,
|
|
637
|
+
onClick: handleCaptionClick,
|
|
638
|
+
children: captionText
|
|
639
|
+
})]
|
|
640
|
+
}) : /* @__PURE__ */ jsx(ReplacePopover, {}), src && /* @__PURE__ */ jsx(ImageEditToolbar, {})]
|
|
641
|
+
});
|
|
699
642
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
ImageRenderer
|
|
703
|
-
};
|
|
643
|
+
//#endregion
|
|
644
|
+
export { ImageEditRenderer, ImageRenderer };
|