@lobehub/editor 3.15.0 → 3.16.0
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/es/locale/index.d.ts +1 -0
- package/es/locale/index.js +2 -1
- package/es/plugins/image/react/ReactImagePlugin.js +1 -0
- package/es/plugins/image/react/components/Image.d.ts +3 -0
- package/es/plugins/image/react/components/Image.js +72 -43
- package/es/plugins/image/react/components/ImageEditPopover.d.ts +12 -0
- package/es/plugins/image/react/components/ImageEditPopover.js +196 -0
- package/es/plugins/image/react/components/style.d.ts +1 -0
- package/es/plugins/image/react/components/style.js +7 -6
- package/package.json +1 -1
package/es/locale/index.d.ts
CHANGED
package/es/locale/index.js
CHANGED
|
@@ -3,6 +3,9 @@ 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;
|
|
7
10
|
/** Whether to show scale info when resizing. Defaults to false */
|
|
8
11
|
showScaleInfo?: boolean;
|
|
@@ -4,25 +4,28 @@ 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
|
|
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;
|
|
26
29
|
var _useLexicalNodeSelect = useLexicalNodeSelection(node.getKey()),
|
|
27
30
|
_useLexicalNodeSelect2 = _slicedToArray(_useLexicalNodeSelect, 2),
|
|
28
31
|
isSelected = _useLexicalNodeSelect2[0],
|
|
@@ -53,6 +56,7 @@ var Image = /*#__PURE__*/memo(function (_ref) {
|
|
|
53
56
|
});
|
|
54
57
|
var editorRef = useRef(null);
|
|
55
58
|
var startWidthRef = useRef(0);
|
|
59
|
+
var lastLoadedSrcRef = useRef(null);
|
|
56
60
|
var isBlock = useMemo(function () {
|
|
57
61
|
return $isBlockImageNode(node);
|
|
58
62
|
}, [node]);
|
|
@@ -149,15 +153,28 @@ var Image = /*#__PURE__*/memo(function (_ref) {
|
|
|
149
153
|
case 'uploaded':
|
|
150
154
|
case 'loading':
|
|
151
155
|
{
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
setSize(size);
|
|
156
|
+
var fallback = lastLoadedSrcRef.current ? /*#__PURE__*/_jsx("img", {
|
|
157
|
+
alt: node.altText,
|
|
158
|
+
className: cx(styles.lazyImage, className || undefined),
|
|
159
|
+
draggable: "false",
|
|
160
|
+
src: lastLoadedSrcRef.current,
|
|
161
|
+
style: {
|
|
162
|
+
width: '100%'
|
|
160
163
|
}
|
|
164
|
+
}) : null;
|
|
165
|
+
return /*#__PURE__*/_jsx(Suspense, {
|
|
166
|
+
fallback: fallback,
|
|
167
|
+
children: /*#__PURE__*/_jsx(LazyImage, {
|
|
168
|
+
className: className,
|
|
169
|
+
newWidth: newWidth,
|
|
170
|
+
node: node,
|
|
171
|
+
onLoad: function onLoad(loadedSize) {
|
|
172
|
+
lastLoadedSrcRef.current = node.src;
|
|
173
|
+
originalSizeRef.current.width = loadedSize.width;
|
|
174
|
+
originalSizeRef.current.height = loadedSize.height;
|
|
175
|
+
setSize(loadedSize);
|
|
176
|
+
}
|
|
177
|
+
})
|
|
161
178
|
});
|
|
162
179
|
}
|
|
163
180
|
default:
|
|
@@ -195,39 +212,51 @@ var Image = /*#__PURE__*/memo(function (_ref) {
|
|
|
195
212
|
}
|
|
196
213
|
});
|
|
197
214
|
}, [node]);
|
|
198
|
-
return /*#__PURE__*/
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
children: [/*#__PURE__*/_jsx(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}), /*#__PURE__*/
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
215
|
+
return /*#__PURE__*/_jsx(ImageEditPopover, {
|
|
216
|
+
handleUpload: handleUpload,
|
|
217
|
+
node: node,
|
|
218
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
219
|
+
className: cx(styles.imageContainer, {
|
|
220
|
+
loading: node.status === 'loading',
|
|
221
|
+
selected: isSelected
|
|
222
|
+
}),
|
|
223
|
+
draggable: false,
|
|
224
|
+
onClick: handleClick,
|
|
225
|
+
onDoubleClick: handleDoubleClick,
|
|
226
|
+
onMouseEnter: handleMouseEnter,
|
|
227
|
+
onMouseLeave: handleMouseLeave,
|
|
228
|
+
ref: imageRef,
|
|
229
|
+
style: {
|
|
230
|
+
width: size.width || 'auto'
|
|
231
|
+
},
|
|
232
|
+
children: [children, node.status === 'loading' && /*#__PURE__*/_jsx("div", {
|
|
233
|
+
className: styles.loadingIcon,
|
|
234
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
|
235
|
+
icon: LoaderCircleIcon,
|
|
236
|
+
size: 24,
|
|
237
|
+
spin: true
|
|
238
|
+
})
|
|
239
|
+
}), showScaleInfo && isSelected && scale !== 1 && /*#__PURE__*/_jsxs("div", {
|
|
240
|
+
className: styles.scaleInfo,
|
|
241
|
+
children: [Math.round(scale * 100), "%"]
|
|
242
|
+
}), isHovered && node.status === 'uploaded' && /*#__PURE__*/_jsxs(_Fragment, {
|
|
243
|
+
children: [/*#__PURE__*/_jsx(ResizeHandle, {
|
|
244
|
+
imageRef: imageRef,
|
|
245
|
+
isBlock: isBlock,
|
|
246
|
+
onResize: handleResize,
|
|
247
|
+
onResizeEnd: handleResizeEnd,
|
|
248
|
+
onResizeStart: handleResizeStart,
|
|
249
|
+
position: "left"
|
|
250
|
+
}), /*#__PURE__*/_jsx(ResizeHandle, {
|
|
251
|
+
imageRef: imageRef,
|
|
252
|
+
isBlock: isBlock,
|
|
253
|
+
onResize: handleResize,
|
|
254
|
+
onResizeEnd: handleResizeEnd,
|
|
255
|
+
onResizeStart: handleResizeStart,
|
|
256
|
+
position: "right"
|
|
257
|
+
})]
|
|
229
258
|
})]
|
|
230
|
-
})
|
|
259
|
+
})
|
|
231
260
|
});
|
|
232
261
|
});
|
|
233
262
|
Image.displayName = 'Image';
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
declare const ImageEditPopover: FC<ImageEditPopoverProps>;
|
|
12
|
+
export default ImageEditPopover;
|
|
@@ -0,0 +1,196 @@
|
|
|
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
|
+
var _useState = useState(false),
|
|
26
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
27
|
+
open = _useState2[0],
|
|
28
|
+
setOpen = _useState2[1];
|
|
29
|
+
var _useState3 = useState(''),
|
|
30
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
31
|
+
url = _useState4[0],
|
|
32
|
+
setUrl = _useState4[1];
|
|
33
|
+
var _useState5 = useState(false),
|
|
34
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
35
|
+
uploading = _useState6[0],
|
|
36
|
+
setUploading = _useState6[1];
|
|
37
|
+
var fileInputRef = useRef(null);
|
|
38
|
+
var editorRef = useRef(null);
|
|
39
|
+
var _useEditable = useEditable(),
|
|
40
|
+
editable = _useEditable.editable;
|
|
41
|
+
var t = useTranslation();
|
|
42
|
+
useLexicalEditor(function (editor) {
|
|
43
|
+
editorRef.current = editor;
|
|
44
|
+
return function () {
|
|
45
|
+
editorRef.current = null;
|
|
46
|
+
};
|
|
47
|
+
}, []);
|
|
48
|
+
var handleOpenChange = useCallback(function (nextOpen) {
|
|
49
|
+
if (nextOpen && node.status !== 'uploaded') return;
|
|
50
|
+
if (nextOpen) setUrl(node.src);
|
|
51
|
+
setOpen(nextOpen);
|
|
52
|
+
}, [node]);
|
|
53
|
+
var handleClose = useCallback(function () {
|
|
54
|
+
setOpen(false);
|
|
55
|
+
}, []);
|
|
56
|
+
var handleUrlSubmit = useCallback(function () {
|
|
57
|
+
var editor = editorRef.current;
|
|
58
|
+
if (!editor || !url.trim()) return;
|
|
59
|
+
var trimmedUrl = url.trim();
|
|
60
|
+
handleClose();
|
|
61
|
+
editor.update(function () {
|
|
62
|
+
node.setUploaded(trimmedUrl);
|
|
63
|
+
});
|
|
64
|
+
}, [node, url, handleClose]);
|
|
65
|
+
var handleFileChange = useCallback( /*#__PURE__*/function () {
|
|
66
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(e) {
|
|
67
|
+
var _e$target$files;
|
|
68
|
+
var file, editor, result, _editor;
|
|
69
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
70
|
+
while (1) switch (_context.prev = _context.next) {
|
|
71
|
+
case 0:
|
|
72
|
+
file = (_e$target$files = e.target.files) === null || _e$target$files === void 0 ? void 0 : _e$target$files[0];
|
|
73
|
+
if (!(!file || !handleUpload)) {
|
|
74
|
+
_context.next = 3;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
return _context.abrupt("return");
|
|
78
|
+
case 3:
|
|
79
|
+
handleClose();
|
|
80
|
+
setUploading(true);
|
|
81
|
+
_context.prev = 5;
|
|
82
|
+
editor = editorRef.current;
|
|
83
|
+
if (editor) {
|
|
84
|
+
_context.next = 9;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
return _context.abrupt("return");
|
|
88
|
+
case 9:
|
|
89
|
+
editor.update(function () {
|
|
90
|
+
node.setStatus('loading');
|
|
91
|
+
});
|
|
92
|
+
_context.next = 12;
|
|
93
|
+
return handleUpload(file);
|
|
94
|
+
case 12:
|
|
95
|
+
result = _context.sent;
|
|
96
|
+
editor.update(function () {
|
|
97
|
+
node.setUploaded(result.url);
|
|
98
|
+
});
|
|
99
|
+
_context.next = 20;
|
|
100
|
+
break;
|
|
101
|
+
case 16:
|
|
102
|
+
_context.prev = 16;
|
|
103
|
+
_context.t0 = _context["catch"](5);
|
|
104
|
+
_editor = editorRef.current;
|
|
105
|
+
if (_editor) {
|
|
106
|
+
_editor.update(function () {
|
|
107
|
+
node.setError('Upload failed');
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
case 20:
|
|
111
|
+
_context.prev = 20;
|
|
112
|
+
setUploading(false);
|
|
113
|
+
if (fileInputRef.current) fileInputRef.current.value = '';
|
|
114
|
+
return _context.finish(20);
|
|
115
|
+
case 24:
|
|
116
|
+
case "end":
|
|
117
|
+
return _context.stop();
|
|
118
|
+
}
|
|
119
|
+
}, _callee, null, [[5, 16, 20, 24]]);
|
|
120
|
+
}));
|
|
121
|
+
return function (_x) {
|
|
122
|
+
return _ref2.apply(this, arguments);
|
|
123
|
+
};
|
|
124
|
+
}(), [node, handleUpload, handleClose]);
|
|
125
|
+
var content = /*#__PURE__*/_jsxs(Flexbox, {
|
|
126
|
+
gap: 8,
|
|
127
|
+
style: {
|
|
128
|
+
width: 320
|
|
129
|
+
},
|
|
130
|
+
children: [/*#__PURE__*/_jsx(Input, {
|
|
131
|
+
onChange: function onChange(e) {
|
|
132
|
+
return setUrl(e.target.value);
|
|
133
|
+
},
|
|
134
|
+
onKeyDown: function onKeyDown(e) {
|
|
135
|
+
if (e.key === 'Enter') handleUrlSubmit();
|
|
136
|
+
if (e.key === 'Escape') handleClose();
|
|
137
|
+
},
|
|
138
|
+
placeholder: "https://...",
|
|
139
|
+
prefix: /*#__PURE__*/_jsx(Icon, {
|
|
140
|
+
color: cssVar.colorTextDescription,
|
|
141
|
+
icon: LinkIcon
|
|
142
|
+
}),
|
|
143
|
+
value: url
|
|
144
|
+
}), /*#__PURE__*/_jsxs(Flexbox, {
|
|
145
|
+
gap: 8,
|
|
146
|
+
horizontal: true,
|
|
147
|
+
justify: "flex-end",
|
|
148
|
+
children: [handleUpload && /*#__PURE__*/_jsxs(_Fragment, {
|
|
149
|
+
children: [/*#__PURE__*/_jsx("input", {
|
|
150
|
+
accept: "image/*",
|
|
151
|
+
onChange: handleFileChange,
|
|
152
|
+
ref: fileInputRef,
|
|
153
|
+
style: {
|
|
154
|
+
display: 'none'
|
|
155
|
+
},
|
|
156
|
+
type: "file"
|
|
157
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
158
|
+
icon: /*#__PURE__*/_jsx(Icon, {
|
|
159
|
+
icon: UploadIcon
|
|
160
|
+
}),
|
|
161
|
+
loading: uploading,
|
|
162
|
+
onClick: function onClick() {
|
|
163
|
+
var _fileInputRef$current;
|
|
164
|
+
return (_fileInputRef$current = fileInputRef.current) === null || _fileInputRef$current === void 0 ? void 0 : _fileInputRef$current.click();
|
|
165
|
+
},
|
|
166
|
+
size: "small",
|
|
167
|
+
type: "text",
|
|
168
|
+
children: t('image.replace')
|
|
169
|
+
})]
|
|
170
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
171
|
+
onClick: handleUrlSubmit,
|
|
172
|
+
size: "small",
|
|
173
|
+
type: "text",
|
|
174
|
+
variant: "filled",
|
|
175
|
+
children: t('confirm')
|
|
176
|
+
})]
|
|
177
|
+
})]
|
|
178
|
+
});
|
|
179
|
+
return /*#__PURE__*/_jsx(Popover, {
|
|
180
|
+
arrow: false,
|
|
181
|
+
content: content,
|
|
182
|
+
disabled: !editable || node.status !== 'uploaded',
|
|
183
|
+
onOpenChange: handleOpenChange,
|
|
184
|
+
open: open,
|
|
185
|
+
placement: "bottom",
|
|
186
|
+
styles: {
|
|
187
|
+
content: {
|
|
188
|
+
padding: 12
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
trigger: "click",
|
|
192
|
+
children: children
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
ImageEditPopover.displayName = 'ImageEditPopover';
|
|
196
|
+
export default ImageEditPopover;
|
|
@@ -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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
});
|
package/package.json
CHANGED