@lobehub/editor 3.16.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.
@@ -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];
@@ -43,7 +44,8 @@ var ReactImagePlugin = function ReactImagePlugin(_ref) {
43
44
  return /*#__PURE__*/_jsx(Image, {
44
45
  className: className,
45
46
  handleUpload: handleUpload || defaultUpload,
46
- node: node
47
+ node: node,
48
+ onPickFile: onPickFile
47
49
  });
48
50
  },
49
51
  theme: theme || styles
@@ -7,6 +7,7 @@ export interface ImageProps {
7
7
  url: string;
8
8
  }>;
9
9
  node: ImageNode | BlockImageNode;
10
+ onPickFile?: () => Promise<File | null>;
10
11
  /** Whether to show scale info when resizing. Defaults to false */
11
12
  showScaleInfo?: boolean;
12
13
  }
@@ -25,7 +25,8 @@ var Image = /*#__PURE__*/memo(function (_ref) {
25
25
  className = _ref.className,
26
26
  _ref$showScaleInfo = _ref.showScaleInfo,
27
27
  showScaleInfo = _ref$showScaleInfo === void 0 ? false : _ref$showScaleInfo,
28
- handleUpload = _ref.handleUpload;
28
+ handleUpload = _ref.handleUpload,
29
+ onPickFile = _ref.onPickFile;
29
30
  var _useLexicalNodeSelect = useLexicalNodeSelection(node.getKey()),
30
31
  _useLexicalNodeSelect2 = _slicedToArray(_useLexicalNodeSelect, 2),
31
32
  isSelected = _useLexicalNodeSelect2[0],
@@ -215,6 +216,7 @@ var Image = /*#__PURE__*/memo(function (_ref) {
215
216
  return /*#__PURE__*/_jsx(ImageEditPopover, {
216
217
  handleUpload: handleUpload,
217
218
  node: node,
219
+ onPickFile: onPickFile,
218
220
  children: /*#__PURE__*/_jsxs("div", {
219
221
  className: cx(styles.imageContainer, {
220
222
  loading: node.status === 'loading',
@@ -7,6 +7,11 @@ interface ImageEditPopoverProps {
7
7
  url: string;
8
8
  }>;
9
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>;
10
15
  }
11
16
  declare const ImageEditPopover: FC<ImageEditPopoverProps>;
12
17
  export default ImageEditPopover;
@@ -21,7 +21,8 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
21
21
  var ImageEditPopover = /*#__PURE__*/memo(function (_ref) {
22
22
  var children = _ref.children,
23
23
  node = _ref.node,
24
- handleUpload = _ref.handleUpload;
24
+ handleUpload = _ref.handleUpload,
25
+ onPickFile = _ref.onPickFile;
25
26
  var _useState = useState(false),
26
27
  _useState2 = _slicedToArray(_useState, 2),
27
28
  open = _useState2[0],
@@ -122,6 +123,69 @@ var ImageEditPopover = /*#__PURE__*/memo(function (_ref) {
122
123
  return _ref2.apply(this, arguments);
123
124
  };
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]);
125
189
  var content = /*#__PURE__*/_jsxs(Flexbox, {
126
190
  gap: 8,
127
191
  style: {
@@ -146,7 +210,7 @@ var ImageEditPopover = /*#__PURE__*/memo(function (_ref) {
146
210
  horizontal: true,
147
211
  justify: "flex-end",
148
212
  children: [handleUpload && /*#__PURE__*/_jsxs(_Fragment, {
149
- children: [/*#__PURE__*/_jsx("input", {
213
+ children: [!onPickFile && /*#__PURE__*/_jsx("input", {
150
214
  accept: "image/*",
151
215
  onChange: handleFileChange,
152
216
  ref: fileInputRef,
@@ -159,10 +223,7 @@ var ImageEditPopover = /*#__PURE__*/memo(function (_ref) {
159
223
  icon: UploadIcon
160
224
  }),
161
225
  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
- },
226
+ onClick: handlePickFile,
166
227
  size: "small",
167
228
  type: "text",
168
229
  children: t('image.replace')
@@ -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.16.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",