@lobehub/editor 3.15.0 → 3.16.1

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.
@@ -17,6 +17,7 @@ declare const _default: {
17
17
  };
18
18
  image: {
19
19
  broken: string;
20
+ replace: string;
20
21
  };
21
22
  link: {
22
23
  edit: string;
@@ -16,7 +16,8 @@ export default {
16
16
  uploading: 'Uploading file...'
17
17
  },
18
18
  image: {
19
- broken: 'Broken image'
19
+ broken: 'Broken image',
20
+ replace: 'Replace'
20
21
  },
21
22
  link: {
22
23
  edit: 'Edit Link',
@@ -28,7 +28,8 @@ var ReactImagePlugin = function ReactImagePlugin(_ref) {
28
28
  defaultBlockImage = _ref.defaultBlockImage,
29
29
  handleUpload = _ref.handleUpload,
30
30
  needRehost = _ref.needRehost,
31
- handleRehost = _ref.handleRehost;
31
+ handleRehost = _ref.handleRehost,
32
+ onPickFile = _ref.onPickFile;
32
33
  var _useLexicalComposerCo = useLexicalComposerContext(),
33
34
  _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
34
35
  editor = _useLexicalComposerCo2[0];
@@ -42,7 +43,9 @@ var ReactImagePlugin = function ReactImagePlugin(_ref) {
42
43
  renderImage: function renderImage(node) {
43
44
  return /*#__PURE__*/_jsx(Image, {
44
45
  className: className,
45
- node: node
46
+ handleUpload: handleUpload || defaultUpload,
47
+ node: node,
48
+ onPickFile: onPickFile
46
49
  });
47
50
  },
48
51
  theme: theme || styles
@@ -3,7 +3,11 @@ import { BlockImageNode } from '../../node/block-image-node';
3
3
  import { ImageNode } from '../../node/image-node';
4
4
  export interface ImageProps {
5
5
  className?: string;
6
+ handleUpload?: (file: File) => Promise<{
7
+ url: string;
8
+ }>;
6
9
  node: ImageNode | BlockImageNode;
10
+ onPickFile?: () => Promise<File | null>;
7
11
  /** Whether to show scale info when resizing. Defaults to false */
8
12
  showScaleInfo?: boolean;
9
13
  }
@@ -4,25 +4,29 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
4
4
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
5
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { Icon } from '@lobehub/ui';
7
8
  import { cx } from 'antd-style';
8
9
  import { COMMAND_PRIORITY_LOW, SELECTION_CHANGE_COMMAND } from 'lexical';
9
- import React, { memo, useCallback, useMemo, useRef, useState } from 'react';
10
+ import { LoaderCircleIcon } from 'lucide-react';
11
+ import React, { Suspense, memo, useCallback, useMemo, useRef, useState } from 'react';
10
12
  import { useLexicalEditor } from "../../../../editor-kernel/react/useLexicalEditor";
11
13
  import { useLexicalNodeSelection } from "../../../../editor-kernel/react/useLexicalNodeSelection";
12
14
  import { $isBlockImageNode } from "../../node/block-image-node";
13
15
  import BrokenImage from "./BrokenImage";
16
+ import ImageEditPopover from "./ImageEditPopover";
14
17
  import LazyImage from "./LazyImage";
15
18
  import { ResizeHandle } from "./ResizeHandle";
16
19
  import { styles } from "./style";
17
20
  import { jsx as _jsx } from "react/jsx-runtime";
18
21
  import { jsxs as _jsxs } from "react/jsx-runtime";
19
22
  import { Fragment as _Fragment } from "react/jsx-runtime";
20
- // Keep memo: Complex resize logic, state management, and multiple event handlers
21
23
  var Image = /*#__PURE__*/memo(function (_ref) {
22
24
  var node = _ref.node,
23
25
  className = _ref.className,
24
26
  _ref$showScaleInfo = _ref.showScaleInfo,
25
- showScaleInfo = _ref$showScaleInfo === void 0 ? false : _ref$showScaleInfo;
27
+ showScaleInfo = _ref$showScaleInfo === void 0 ? false : _ref$showScaleInfo,
28
+ handleUpload = _ref.handleUpload,
29
+ onPickFile = _ref.onPickFile;
26
30
  var _useLexicalNodeSelect = useLexicalNodeSelection(node.getKey()),
27
31
  _useLexicalNodeSelect2 = _slicedToArray(_useLexicalNodeSelect, 2),
28
32
  isSelected = _useLexicalNodeSelect2[0],
@@ -53,6 +57,7 @@ var Image = /*#__PURE__*/memo(function (_ref) {
53
57
  });
54
58
  var editorRef = useRef(null);
55
59
  var startWidthRef = useRef(0);
60
+ var lastLoadedSrcRef = useRef(null);
56
61
  var isBlock = useMemo(function () {
57
62
  return $isBlockImageNode(node);
58
63
  }, [node]);
@@ -149,15 +154,28 @@ var Image = /*#__PURE__*/memo(function (_ref) {
149
154
  case 'uploaded':
150
155
  case 'loading':
151
156
  {
152
- return /*#__PURE__*/_jsx(LazyImage, {
153
- className: className,
154
- newWidth: newWidth,
155
- node: node,
156
- onLoad: function onLoad(size) {
157
- originalSizeRef.current.width = size.width;
158
- originalSizeRef.current.height = size.height;
159
- setSize(size);
157
+ var fallback = lastLoadedSrcRef.current ? /*#__PURE__*/_jsx("img", {
158
+ alt: node.altText,
159
+ className: cx(styles.lazyImage, className || undefined),
160
+ draggable: "false",
161
+ src: lastLoadedSrcRef.current,
162
+ style: {
163
+ width: '100%'
160
164
  }
165
+ }) : null;
166
+ return /*#__PURE__*/_jsx(Suspense, {
167
+ fallback: fallback,
168
+ children: /*#__PURE__*/_jsx(LazyImage, {
169
+ className: className,
170
+ newWidth: newWidth,
171
+ node: node,
172
+ onLoad: function onLoad(loadedSize) {
173
+ lastLoadedSrcRef.current = node.src;
174
+ originalSizeRef.current.width = loadedSize.width;
175
+ originalSizeRef.current.height = loadedSize.height;
176
+ setSize(loadedSize);
177
+ }
178
+ })
161
179
  });
162
180
  }
163
181
  default:
@@ -195,39 +213,52 @@ var Image = /*#__PURE__*/memo(function (_ref) {
195
213
  }
196
214
  });
197
215
  }, [node]);
198
- return /*#__PURE__*/_jsxs("div", {
199
- className: cx(styles.imageContainer, {
200
- selected: isSelected
201
- }),
202
- draggable: false,
203
- onClick: handleClick,
204
- onDoubleClick: handleDoubleClick,
205
- onMouseEnter: handleMouseEnter,
206
- onMouseLeave: handleMouseLeave,
207
- ref: imageRef,
208
- style: {
209
- width: size.width || 'auto'
210
- },
211
- children: [children, showScaleInfo && isSelected && scale !== 1 && /*#__PURE__*/_jsxs("div", {
212
- className: styles.scaleInfo,
213
- children: [Math.round(scale * 100), "%"]
214
- }), isHovered && node.status === 'uploaded' && /*#__PURE__*/_jsxs(_Fragment, {
215
- children: [/*#__PURE__*/_jsx(ResizeHandle, {
216
- imageRef: imageRef,
217
- isBlock: isBlock,
218
- onResize: handleResize,
219
- onResizeEnd: handleResizeEnd,
220
- onResizeStart: handleResizeStart,
221
- position: "left"
222
- }), /*#__PURE__*/_jsx(ResizeHandle, {
223
- imageRef: imageRef,
224
- isBlock: isBlock,
225
- onResize: handleResize,
226
- onResizeEnd: handleResizeEnd,
227
- onResizeStart: handleResizeStart,
228
- position: "right"
216
+ return /*#__PURE__*/_jsx(ImageEditPopover, {
217
+ handleUpload: handleUpload,
218
+ node: node,
219
+ onPickFile: onPickFile,
220
+ children: /*#__PURE__*/_jsxs("div", {
221
+ className: cx(styles.imageContainer, {
222
+ loading: node.status === 'loading',
223
+ selected: isSelected
224
+ }),
225
+ draggable: false,
226
+ onClick: handleClick,
227
+ onDoubleClick: handleDoubleClick,
228
+ onMouseEnter: handleMouseEnter,
229
+ onMouseLeave: handleMouseLeave,
230
+ ref: imageRef,
231
+ style: {
232
+ width: size.width || 'auto'
233
+ },
234
+ children: [children, node.status === 'loading' && /*#__PURE__*/_jsx("div", {
235
+ className: styles.loadingIcon,
236
+ children: /*#__PURE__*/_jsx(Icon, {
237
+ icon: LoaderCircleIcon,
238
+ size: 24,
239
+ spin: true
240
+ })
241
+ }), showScaleInfo && isSelected && scale !== 1 && /*#__PURE__*/_jsxs("div", {
242
+ className: styles.scaleInfo,
243
+ children: [Math.round(scale * 100), "%"]
244
+ }), isHovered && node.status === 'uploaded' && /*#__PURE__*/_jsxs(_Fragment, {
245
+ children: [/*#__PURE__*/_jsx(ResizeHandle, {
246
+ imageRef: imageRef,
247
+ isBlock: isBlock,
248
+ onResize: handleResize,
249
+ onResizeEnd: handleResizeEnd,
250
+ onResizeStart: handleResizeStart,
251
+ position: "left"
252
+ }), /*#__PURE__*/_jsx(ResizeHandle, {
253
+ imageRef: imageRef,
254
+ isBlock: isBlock,
255
+ onResize: handleResize,
256
+ onResizeEnd: handleResizeEnd,
257
+ onResizeStart: handleResizeStart,
258
+ position: "right"
259
+ })]
229
260
  })]
230
- })]
261
+ })
231
262
  });
232
263
  });
233
264
  Image.displayName = 'Image';
@@ -0,0 +1,17 @@
1
+ import { type FC, type ReactNode } from 'react';
2
+ import { BlockImageNode } from '../../node/block-image-node';
3
+ import { ImageNode } from '../../node/image-node';
4
+ interface ImageEditPopoverProps {
5
+ children: ReactNode;
6
+ handleUpload?: (file: File) => Promise<{
7
+ url: string;
8
+ }>;
9
+ node: ImageNode | BlockImageNode;
10
+ /**
11
+ * Custom file picker for environments where programmatic input.click() is blocked (e.g. Electron).
12
+ * When provided, this will be called instead of triggering the hidden file input.
13
+ */
14
+ onPickFile?: () => Promise<File | null>;
15
+ }
16
+ declare const ImageEditPopover: FC<ImageEditPopoverProps>;
17
+ export default ImageEditPopover;
@@ -0,0 +1,257 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ import { Button, Flexbox, Icon, Input, Popover } from '@lobehub/ui';
12
+ import { cssVar } from 'antd-style';
13
+ import { LinkIcon, UploadIcon } from 'lucide-react';
14
+ import { memo, useCallback, useRef, useState } from 'react';
15
+ import { useEditable } from "../../../../editor-kernel/react/useEditable";
16
+ import { useLexicalEditor } from "../../../../editor-kernel/react/useLexicalEditor";
17
+ import { useTranslation } from "../../../../editor-kernel/react/useTranslation";
18
+ import { jsx as _jsx } from "react/jsx-runtime";
19
+ import { Fragment as _Fragment } from "react/jsx-runtime";
20
+ import { jsxs as _jsxs } from "react/jsx-runtime";
21
+ var ImageEditPopover = /*#__PURE__*/memo(function (_ref) {
22
+ var children = _ref.children,
23
+ node = _ref.node,
24
+ handleUpload = _ref.handleUpload,
25
+ onPickFile = _ref.onPickFile;
26
+ var _useState = useState(false),
27
+ _useState2 = _slicedToArray(_useState, 2),
28
+ open = _useState2[0],
29
+ setOpen = _useState2[1];
30
+ var _useState3 = useState(''),
31
+ _useState4 = _slicedToArray(_useState3, 2),
32
+ url = _useState4[0],
33
+ setUrl = _useState4[1];
34
+ var _useState5 = useState(false),
35
+ _useState6 = _slicedToArray(_useState5, 2),
36
+ uploading = _useState6[0],
37
+ setUploading = _useState6[1];
38
+ var fileInputRef = useRef(null);
39
+ var editorRef = useRef(null);
40
+ var _useEditable = useEditable(),
41
+ editable = _useEditable.editable;
42
+ var t = useTranslation();
43
+ useLexicalEditor(function (editor) {
44
+ editorRef.current = editor;
45
+ return function () {
46
+ editorRef.current = null;
47
+ };
48
+ }, []);
49
+ var handleOpenChange = useCallback(function (nextOpen) {
50
+ if (nextOpen && node.status !== 'uploaded') return;
51
+ if (nextOpen) setUrl(node.src);
52
+ setOpen(nextOpen);
53
+ }, [node]);
54
+ var handleClose = useCallback(function () {
55
+ setOpen(false);
56
+ }, []);
57
+ var handleUrlSubmit = useCallback(function () {
58
+ var editor = editorRef.current;
59
+ if (!editor || !url.trim()) return;
60
+ var trimmedUrl = url.trim();
61
+ handleClose();
62
+ editor.update(function () {
63
+ node.setUploaded(trimmedUrl);
64
+ });
65
+ }, [node, url, handleClose]);
66
+ var handleFileChange = useCallback( /*#__PURE__*/function () {
67
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(e) {
68
+ var _e$target$files;
69
+ var file, editor, result, _editor;
70
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
71
+ while (1) switch (_context.prev = _context.next) {
72
+ case 0:
73
+ file = (_e$target$files = e.target.files) === null || _e$target$files === void 0 ? void 0 : _e$target$files[0];
74
+ if (!(!file || !handleUpload)) {
75
+ _context.next = 3;
76
+ break;
77
+ }
78
+ return _context.abrupt("return");
79
+ case 3:
80
+ handleClose();
81
+ setUploading(true);
82
+ _context.prev = 5;
83
+ editor = editorRef.current;
84
+ if (editor) {
85
+ _context.next = 9;
86
+ break;
87
+ }
88
+ return _context.abrupt("return");
89
+ case 9:
90
+ editor.update(function () {
91
+ node.setStatus('loading');
92
+ });
93
+ _context.next = 12;
94
+ return handleUpload(file);
95
+ case 12:
96
+ result = _context.sent;
97
+ editor.update(function () {
98
+ node.setUploaded(result.url);
99
+ });
100
+ _context.next = 20;
101
+ break;
102
+ case 16:
103
+ _context.prev = 16;
104
+ _context.t0 = _context["catch"](5);
105
+ _editor = editorRef.current;
106
+ if (_editor) {
107
+ _editor.update(function () {
108
+ node.setError('Upload failed');
109
+ });
110
+ }
111
+ case 20:
112
+ _context.prev = 20;
113
+ setUploading(false);
114
+ if (fileInputRef.current) fileInputRef.current.value = '';
115
+ return _context.finish(20);
116
+ case 24:
117
+ case "end":
118
+ return _context.stop();
119
+ }
120
+ }, _callee, null, [[5, 16, 20, 24]]);
121
+ }));
122
+ return function (_x) {
123
+ return _ref2.apply(this, arguments);
124
+ };
125
+ }(), [node, handleUpload, handleClose]);
126
+ var handlePickFile = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
127
+ var _file, editor, result, _editor2, _fileInputRef$current;
128
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
129
+ while (1) switch (_context2.prev = _context2.next) {
130
+ case 0:
131
+ if (!onPickFile) {
132
+ _context2.next = 27;
133
+ break;
134
+ }
135
+ _context2.next = 3;
136
+ return onPickFile();
137
+ case 3:
138
+ _file = _context2.sent;
139
+ if (!(_file && handleUpload)) {
140
+ _context2.next = 25;
141
+ break;
142
+ }
143
+ handleClose();
144
+ setUploading(true);
145
+ _context2.prev = 7;
146
+ editor = editorRef.current;
147
+ if (editor) {
148
+ _context2.next = 11;
149
+ break;
150
+ }
151
+ return _context2.abrupt("return");
152
+ case 11:
153
+ editor.update(function () {
154
+ node.setStatus('loading');
155
+ });
156
+ _context2.next = 14;
157
+ return handleUpload(_file);
158
+ case 14:
159
+ result = _context2.sent;
160
+ editor.update(function () {
161
+ node.setUploaded(result.url);
162
+ });
163
+ _context2.next = 22;
164
+ break;
165
+ case 18:
166
+ _context2.prev = 18;
167
+ _context2.t0 = _context2["catch"](7);
168
+ _editor2 = editorRef.current;
169
+ if (_editor2) {
170
+ _editor2.update(function () {
171
+ node.setError('Upload failed');
172
+ });
173
+ }
174
+ case 22:
175
+ _context2.prev = 22;
176
+ setUploading(false);
177
+ return _context2.finish(22);
178
+ case 25:
179
+ _context2.next = 28;
180
+ break;
181
+ case 27:
182
+ (_fileInputRef$current = fileInputRef.current) === null || _fileInputRef$current === void 0 || _fileInputRef$current.click();
183
+ case 28:
184
+ case "end":
185
+ return _context2.stop();
186
+ }
187
+ }, _callee2, null, [[7, 18, 22, 25]]);
188
+ })), [onPickFile, handleUpload, handleClose, node]);
189
+ var content = /*#__PURE__*/_jsxs(Flexbox, {
190
+ gap: 8,
191
+ style: {
192
+ width: 320
193
+ },
194
+ children: [/*#__PURE__*/_jsx(Input, {
195
+ onChange: function onChange(e) {
196
+ return setUrl(e.target.value);
197
+ },
198
+ onKeyDown: function onKeyDown(e) {
199
+ if (e.key === 'Enter') handleUrlSubmit();
200
+ if (e.key === 'Escape') handleClose();
201
+ },
202
+ placeholder: "https://...",
203
+ prefix: /*#__PURE__*/_jsx(Icon, {
204
+ color: cssVar.colorTextDescription,
205
+ icon: LinkIcon
206
+ }),
207
+ value: url
208
+ }), /*#__PURE__*/_jsxs(Flexbox, {
209
+ gap: 8,
210
+ horizontal: true,
211
+ justify: "flex-end",
212
+ children: [handleUpload && /*#__PURE__*/_jsxs(_Fragment, {
213
+ children: [!onPickFile && /*#__PURE__*/_jsx("input", {
214
+ accept: "image/*",
215
+ onChange: handleFileChange,
216
+ ref: fileInputRef,
217
+ style: {
218
+ display: 'none'
219
+ },
220
+ type: "file"
221
+ }), /*#__PURE__*/_jsx(Button, {
222
+ icon: /*#__PURE__*/_jsx(Icon, {
223
+ icon: UploadIcon
224
+ }),
225
+ loading: uploading,
226
+ onClick: handlePickFile,
227
+ size: "small",
228
+ type: "text",
229
+ children: t('image.replace')
230
+ })]
231
+ }), /*#__PURE__*/_jsx(Button, {
232
+ onClick: handleUrlSubmit,
233
+ size: "small",
234
+ type: "text",
235
+ variant: "filled",
236
+ children: t('confirm')
237
+ })]
238
+ })]
239
+ });
240
+ return /*#__PURE__*/_jsx(Popover, {
241
+ arrow: false,
242
+ content: content,
243
+ disabled: !editable || node.status !== 'uploaded',
244
+ onOpenChange: handleOpenChange,
245
+ open: open,
246
+ placement: "bottom",
247
+ styles: {
248
+ content: {
249
+ padding: 12
250
+ }
251
+ },
252
+ trigger: "click",
253
+ children: children
254
+ });
255
+ });
256
+ ImageEditPopover.displayName = 'ImageEditPopover';
257
+ export default ImageEditPopover;
@@ -2,6 +2,7 @@ export declare const styles: {
2
2
  brokenImage: string;
3
3
  imageContainer: string;
4
4
  lazyImage: string;
5
+ loadingIcon: string;
5
6
  resizeHandle: string;
6
7
  resizeHandleLeft: string;
7
8
  resizeHandleRight: string;
@@ -1,4 +1,4 @@
1
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
1
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8;
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
3
  import { createStaticStyles } from 'antd-style';
4
4
  export var styles = createStaticStyles(function (_ref) {
@@ -6,11 +6,12 @@ export var styles = createStaticStyles(function (_ref) {
6
6
  cssVar = _ref.cssVar;
7
7
  return {
8
8
  brokenImage: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: 200px;\n height: auto;\n "]))),
9
- imageContainer: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n cursor: default;\n user-select: none;\n\n position: relative;\n\n overflow: hidden;\n display: inline-block;\n\n width: auto;\n max-width: 100%;\n height: auto;\n border-radius: ", ";\n\n transition: border-color 0.2s ease;\n\n &.selected {\n cursor: pointer;\n outline: none;\n\n &::after {\n pointer-events: none;\n content: '';\n\n position: absolute;\n z-index: 10;\n inset: 0;\n\n background-color: color-mix(in srgb, ", " 10%, transparent);\n }\n }\n "])), cssVar.borderRadiusSM, cssVar.yellow),
9
+ imageContainer: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n cursor: default;\n user-select: none;\n\n position: relative;\n\n overflow: hidden;\n display: inline-block;\n\n width: auto;\n max-width: 100%;\n height: auto;\n border-radius: ", ";\n\n transition: border-color 0.2s ease;\n\n &.selected {\n cursor: pointer;\n outline: none;\n\n &::after {\n pointer-events: none;\n content: '';\n\n position: absolute;\n z-index: 10;\n inset: 0;\n\n background-color: color-mix(in srgb, ", " 10%, transparent);\n }\n }\n\n &.loading {\n &::after {\n pointer-events: none;\n content: '';\n\n position: absolute;\n z-index: 10;\n inset: 0;\n\n background-color: color-mix(in srgb, ", " 40%, transparent);\n\n animation: image-loading-pulse 1.5s ease-in-out infinite;\n }\n\n @keyframes image-loading-pulse {\n 0%,\n 100% {\n opacity: 1;\n }\n\n 50% {\n opacity: 0.4;\n }\n }\n }\n "])), cssVar.borderRadiusSM, cssVar.yellow, cssVar.colorBgContainer),
10
10
  lazyImage: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n cursor: default;\n "]))),
11
- resizeHandle: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n pointer-events: auto;\n cursor: col-resize;\n\n position: absolute;\n z-index: 9999;\n inset-block-start: 0;\n\n width: 6px;\n height: 100%;\n\n &::after {\n pointer-events: none;\n content: '';\n\n position: absolute;\n inset-block-start: 50%;\n inset-inline-start: 0;\n transform: translateY(-50%);\n\n width: 6px;\n height: min(80px, 80%);\n border: 1px solid color-mix(in srgb, rgb(255, 255, 255) 75%, transparent);\n border-radius: 3px;\n\n background-color: color-mix(in srgb, rgb(0, 0, 0) 50%, transparent);\n }\n "]))),
12
- resizeHandleLeft: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n inset-inline-start: 8px;\n "]))),
13
- resizeHandleRight: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n inset-inline-end: 8px;\n "]))),
14
- scaleInfo: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n pointer-events: none;\n\n position: absolute;\n z-index: 11;\n inset-block-start: 2px;\n inset-inline-start: 2px;\n\n padding-block: 2px;\n padding-inline: 6px;\n border-radius: ", ";\n\n font-size: 12px;\n color: white;\n\n background-color: color-mix(in srgb, rgb(0, 0, 0) 50%, transparent);\n "])), cssVar.borderRadiusSM)
11
+ loadingIcon: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n pointer-events: none;\n\n position: absolute;\n z-index: 11;\n inset: 0;\n\n display: flex;\n align-items: center;\n justify-content: center;\n\n color: ", ";\n "])), cssVar.colorTextSecondary),
12
+ resizeHandle: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n pointer-events: auto;\n cursor: col-resize;\n\n position: absolute;\n z-index: 9999;\n inset-block-start: 0;\n\n width: 6px;\n height: 100%;\n\n &::after {\n pointer-events: none;\n content: '';\n\n position: absolute;\n inset-block-start: 50%;\n inset-inline-start: 0;\n transform: translateY(-50%);\n\n width: 6px;\n height: min(80px, 80%);\n border: 1px solid color-mix(in srgb, rgb(255, 255, 255) 75%, transparent);\n border-radius: 3px;\n\n background-color: color-mix(in srgb, rgb(0, 0, 0) 50%, transparent);\n }\n "]))),
13
+ resizeHandleLeft: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n inset-inline-start: 8px;\n "]))),
14
+ resizeHandleRight: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n inset-inline-end: 8px;\n "]))),
15
+ scaleInfo: css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n pointer-events: none;\n\n position: absolute;\n z-index: 11;\n inset-block-start: 2px;\n inset-inline-start: 2px;\n\n padding-block: 2px;\n padding-inline: 6px;\n border-radius: ", ";\n\n font-size: 12px;\n color: white;\n\n background-color: color-mix(in srgb, rgb(0, 0, 0) 50%, transparent);\n "])), cssVar.borderRadiusSM)
15
16
  };
16
17
  });
@@ -8,6 +8,11 @@ export interface ReactImagePluginProps {
8
8
  url: string;
9
9
  }>;
10
10
  needRehost?: (url: string) => boolean;
11
+ /**
12
+ * Custom file picker for environments where programmatic input.click() is blocked (e.g. Electron).
13
+ * When provided, this will be called instead of triggering the hidden file input.
14
+ */
15
+ onPickFile?: () => Promise<File | null>;
11
16
  theme?: {
12
17
  blockImage?: string;
13
18
  image?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "3.15.0",
3
+ "version": "3.16.1",
4
4
  "description": "A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.",
5
5
  "keywords": [
6
6
  "lobehub",