@lobehub/editor 1.24.0 → 1.26.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.
Files changed (77) hide show
  1. package/README.md +9 -4
  2. package/es/editor-kernel/kernel.d.ts +3 -1
  3. package/es/editor-kernel/kernel.js +27 -8
  4. package/es/editor-kernel/react/useEditable.d.ts +3 -0
  5. package/es/editor-kernel/react/useEditable.js +32 -0
  6. package/es/index.d.ts +2 -0
  7. package/es/index.js +2 -0
  8. package/es/plugins/auto-complete/index.d.ts +2 -0
  9. package/es/plugins/auto-complete/index.js +2 -0
  10. package/es/plugins/auto-complete/node/placeholderNode.d.ts +30 -0
  11. package/es/plugins/auto-complete/node/placeholderNode.js +171 -0
  12. package/es/plugins/auto-complete/plugin/index.d.ts +17 -0
  13. package/es/plugins/auto-complete/plugin/index.js +398 -0
  14. package/es/plugins/auto-complete/react/ReactAutoCompletePlugin.d.ts +4 -0
  15. package/es/plugins/auto-complete/react/ReactAutoCompletePlugin.js +35 -0
  16. package/es/plugins/auto-complete/react/index.d.ts +1 -0
  17. package/es/plugins/auto-complete/react/index.js +1 -0
  18. package/es/plugins/auto-complete/react/style.d.ts +4 -0
  19. package/es/plugins/auto-complete/react/style.js +10 -0
  20. package/es/plugins/auto-complete/react/type.d.ts +11 -0
  21. package/es/plugins/auto-complete/react/type.js +1 -0
  22. package/es/plugins/common/plugin/index.js +0 -1
  23. package/es/plugins/common/plugin/register.js +3 -0
  24. package/es/plugins/common/react/ReactPlainText.js +9 -2
  25. package/es/plugins/common/react/style.js +1 -1
  26. package/es/plugins/common/react/type.d.ts +1 -0
  27. package/es/plugins/image/command/index.d.ts +2 -0
  28. package/es/plugins/image/command/index.js +10 -2
  29. package/es/plugins/image/node/basie-image-node.d.ts +1 -0
  30. package/es/plugins/image/node/basie-image-node.js +5 -0
  31. package/es/plugins/image/node/block-image-node.d.ts +31 -0
  32. package/es/plugins/image/node/block-image-node.js +209 -0
  33. package/es/plugins/image/node/image-node.d.ts +3 -0
  34. package/es/plugins/image/node/image-node.js +17 -0
  35. package/es/plugins/image/plugin/index.d.ts +4 -1
  36. package/es/plugins/image/plugin/index.js +51 -11
  37. package/es/plugins/image/react/ReactImagePlugin.js +3 -1
  38. package/es/plugins/image/react/components/Image.d.ts +4 -3
  39. package/es/plugins/image/react/components/Image.js +272 -24
  40. package/es/plugins/image/react/components/LazyImage.d.ts +7 -1
  41. package/es/plugins/image/react/components/LazyImage.js +11 -3
  42. package/es/plugins/image/react/components/style.d.ts +40 -0
  43. package/es/plugins/image/react/components/style.js +43 -0
  44. package/es/plugins/image/react/style.d.ts +10 -0
  45. package/es/plugins/image/react/style.js +10 -0
  46. package/es/plugins/image/react/type.d.ts +2 -0
  47. package/es/plugins/link/index.d.ts +1 -0
  48. package/es/plugins/link/index.js +2 -1
  49. package/es/plugins/link/plugin/index.js +3 -0
  50. package/es/plugins/link/react/ReactLinkPlugin.js +20 -2
  51. package/es/plugins/link/react/components/LinkEdit.js +4 -1
  52. package/es/plugins/link/react/components/LinkToolbar.d.ts +1 -0
  53. package/es/plugins/link/react/components/LinkToolbar.js +8 -2
  54. package/es/plugins/link/service/i-link-service.d.ts +11 -0
  55. package/es/plugins/link/service/i-link-service.js +46 -0
  56. package/es/plugins/markdown/service/shortcut.d.ts +7 -2
  57. package/es/plugins/markdown/service/shortcut.js +12 -1
  58. package/es/plugins/markdown/utils/index.d.ts +2 -0
  59. package/es/plugins/markdown/utils/index.js +4 -1
  60. package/es/plugins/toolbar/index.d.ts +1 -0
  61. package/es/plugins/toolbar/index.js +1 -0
  62. package/es/plugins/toolbar/react/index.d.ts +3 -0
  63. package/es/plugins/toolbar/react/index.js +80 -0
  64. package/es/plugins/toolbar/react/style.d.ts +1 -0
  65. package/es/plugins/toolbar/react/style.js +9 -0
  66. package/es/plugins/toolbar/react/type.d.ts +5 -0
  67. package/es/plugins/toolbar/react/type.js +1 -0
  68. package/es/plugins/toolbar/utils/getDOMRangeRect.d.ts +8 -0
  69. package/es/plugins/toolbar/utils/getDOMRangeRect.js +21 -0
  70. package/es/plugins/toolbar/utils/setFloatingElemPosition.d.ts +1 -0
  71. package/es/plugins/toolbar/utils/setFloatingElemPosition.js +54 -0
  72. package/es/react/ChatInput/style.js +3 -2
  73. package/es/react/Editor/Editor.js +2 -0
  74. package/es/react/Editor/type.d.ts +1 -0
  75. package/es/react/hooks/useEditorState/index.js +41 -33
  76. package/es/types/kernel.d.ts +14 -1
  77. package/package.json +1 -1
@@ -0,0 +1,31 @@
1
+ import { DOMConversionMap, EditorConfig, LexicalNode } from 'lexical';
2
+ import { BaseImageNode, ImagePayload, SerializedImageNode } from './basie-image-node';
3
+ export declare class BlockImageNode extends BaseImageNode {
4
+ private static _decorate;
5
+ static setDecorate(decorate: (node: BlockImageNode) => any): void;
6
+ static getType(): string;
7
+ private __loading;
8
+ private __status;
9
+ private __message;
10
+ private __extra;
11
+ get isLoading(): boolean;
12
+ get status(): 'uploaded' | 'loading' | 'error';
13
+ get message(): string | null;
14
+ get src(): string;
15
+ get altText(): string;
16
+ get maxWidth(): number;
17
+ get width(): number | string;
18
+ get height(): number | string;
19
+ isInline(): boolean;
20
+ setMaxWidth(maxWidth: number): void;
21
+ setWidth(width: number): void;
22
+ setUploaded(url: string): void;
23
+ setError(message: string): void;
24
+ static clone(node: BlockImageNode): BlockImageNode;
25
+ static importJSON(serializedNode: SerializedImageNode): BlockImageNode;
26
+ static importDOM(): DOMConversionMap | null;
27
+ decorate(): any;
28
+ createDOM(config: EditorConfig): HTMLElement;
29
+ }
30
+ export declare function $createBlockImageNode({ altText, height, maxWidth, captionsEnabled, src, width, showCaption, caption, key, }: ImagePayload): BlockImageNode;
31
+ export declare function $isBlockImageNode(node: LexicalNode): node is BlockImageNode;
@@ -0,0 +1,209 @@
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
6
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
7
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
9
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
10
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
11
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
12
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
14
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
+ import { $applyNodeReplacement } from 'lexical';
16
+ import { BaseImageNode } from "./basie-image-node";
17
+ export var BlockImageNode = /*#__PURE__*/function (_BaseImageNode) {
18
+ _inherits(BlockImageNode, _BaseImageNode);
19
+ var _super = _createSuper(BlockImageNode);
20
+ function BlockImageNode() {
21
+ var _this;
22
+ _classCallCheck(this, BlockImageNode);
23
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
24
+ args[_key] = arguments[_key];
25
+ }
26
+ _this = _super.call.apply(_super, [this].concat(args));
27
+ _defineProperty(_assertThisInitialized(_this), "__loading", true);
28
+ _defineProperty(_assertThisInitialized(_this), "__status", 'uploaded');
29
+ _defineProperty(_assertThisInitialized(_this), "__message", null);
30
+ _defineProperty(_assertThisInitialized(_this), "__extra", null);
31
+ return _this;
32
+ }
33
+ _createClass(BlockImageNode, [{
34
+ key: "isLoading",
35
+ get: function get() {
36
+ return this.__loading;
37
+ }
38
+ }, {
39
+ key: "status",
40
+ get: function get() {
41
+ return this.__status;
42
+ }
43
+ }, {
44
+ key: "message",
45
+ get: function get() {
46
+ return this.__message;
47
+ }
48
+ }, {
49
+ key: "src",
50
+ get: function get() {
51
+ return this.__src;
52
+ }
53
+ }, {
54
+ key: "altText",
55
+ get: function get() {
56
+ return this.__altText;
57
+ }
58
+ }, {
59
+ key: "maxWidth",
60
+ get: function get() {
61
+ return this.__maxWidth;
62
+ }
63
+ }, {
64
+ key: "width",
65
+ get: function get() {
66
+ return this.__width;
67
+ }
68
+ }, {
69
+ key: "height",
70
+ get: function get() {
71
+ return this.__height;
72
+ }
73
+ }, {
74
+ key: "isInline",
75
+ value: function isInline() {
76
+ return false;
77
+ }
78
+ }, {
79
+ key: "setMaxWidth",
80
+ value: function setMaxWidth(maxWidth) {
81
+ var writable = this.getWritable();
82
+ writable.__maxWidth = maxWidth;
83
+ }
84
+ }, {
85
+ key: "setWidth",
86
+ value: function setWidth(width) {
87
+ var writable = this.getWritable();
88
+ writable.__width = width;
89
+ }
90
+ }, {
91
+ key: "setUploaded",
92
+ value: function setUploaded(url) {
93
+ var writable = this.getWritable();
94
+ writable.__loading = false;
95
+ writable.__src = url;
96
+ writable.__status = 'uploaded';
97
+ }
98
+ }, {
99
+ key: "setError",
100
+ value: function setError(message) {
101
+ var writable = this.getWritable();
102
+ writable.__loading = false;
103
+ writable.__status = 'error';
104
+ writable.__message = message;
105
+ }
106
+ }, {
107
+ key: "decorate",
108
+ value: function decorate() {
109
+ return BlockImageNode._decorate(this);
110
+ }
111
+ }, {
112
+ key: "createDOM",
113
+ value: function createDOM(config) {
114
+ var span = document.createElement('div');
115
+ var theme = config.theme;
116
+ var className = theme.blockImage;
117
+ if (className !== undefined) {
118
+ span.className = className;
119
+ }
120
+ return span;
121
+ }
122
+ }], [{
123
+ key: "setDecorate",
124
+ value: function setDecorate(decorate) {
125
+ BlockImageNode._decorate = decorate;
126
+ }
127
+ }, {
128
+ key: "getType",
129
+ value: function getType() {
130
+ return 'block-image';
131
+ }
132
+ }, {
133
+ key: "clone",
134
+ value: function clone(node) {
135
+ return new BlockImageNode(node.__src, node.__altText, node.__maxWidth, node.__width, node.__height, node.__showCaption, node.__caption, node.__captionsEnabled, node.__key);
136
+ }
137
+ }, {
138
+ key: "importJSON",
139
+ value: function importJSON(serializedNode) {
140
+ var altText = serializedNode.altText,
141
+ height = serializedNode.height,
142
+ width = serializedNode.width,
143
+ maxWidth = serializedNode.maxWidth,
144
+ src = serializedNode.src,
145
+ showCaption = serializedNode.showCaption;
146
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
147
+ return $createBlockImageNode({
148
+ altText: altText,
149
+ height: height,
150
+ maxWidth: maxWidth,
151
+ showCaption: showCaption,
152
+ src: src,
153
+ width: width
154
+ }).updateFromJSON(serializedNode);
155
+ }
156
+ }, {
157
+ key: "importDOM",
158
+ value: function importDOM() {
159
+ return {
160
+ img: function img() {
161
+ return {
162
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
163
+ conversion: $convertImageElement,
164
+ priority: 0
165
+ };
166
+ }
167
+ };
168
+ }
169
+ }]);
170
+ return BlockImageNode;
171
+ }(BaseImageNode);
172
+ _defineProperty(BlockImageNode, "_decorate", function () {
173
+ return null;
174
+ });
175
+ export function $createBlockImageNode(_ref) {
176
+ var altText = _ref.altText,
177
+ height = _ref.height,
178
+ _ref$maxWidth = _ref.maxWidth,
179
+ maxWidth = _ref$maxWidth === void 0 ? 500 : _ref$maxWidth,
180
+ captionsEnabled = _ref.captionsEnabled,
181
+ src = _ref.src,
182
+ width = _ref.width,
183
+ showCaption = _ref.showCaption,
184
+ caption = _ref.caption,
185
+ key = _ref.key;
186
+ return $applyNodeReplacement(new BlockImageNode(src, altText, maxWidth, width, height, showCaption, caption, captionsEnabled, key));
187
+ }
188
+ function $convertImageElement(domNode) {
189
+ var img = domNode;
190
+ if (img.src.startsWith('file:///')) {
191
+ return null;
192
+ }
193
+ var altText = img.alt,
194
+ src = img.src,
195
+ width = img.width,
196
+ height = img.height;
197
+ var node = $createBlockImageNode({
198
+ altText: altText,
199
+ height: height,
200
+ src: src,
201
+ width: width
202
+ });
203
+ return {
204
+ node: node
205
+ };
206
+ }
207
+ export function $isBlockImageNode(node) {
208
+ return node.getType() === BlockImageNode.getType();
209
+ }
@@ -15,6 +15,9 @@ export declare class ImageNode extends BaseImageNode {
15
15
  get altText(): string;
16
16
  get maxWidth(): number;
17
17
  get width(): number | string;
18
+ get height(): number | string;
19
+ setMaxWidth(maxWidth: number): void;
20
+ setWidth(width: number): void;
18
21
  setUploaded(url: string): void;
19
22
  setError(message: string): void;
20
23
  static clone(node: ImageNode): ImageNode;
@@ -65,6 +65,23 @@ export var ImageNode = /*#__PURE__*/function (_BaseImageNode) {
65
65
  get: function get() {
66
66
  return this.__width;
67
67
  }
68
+ }, {
69
+ key: "height",
70
+ get: function get() {
71
+ return this.__height;
72
+ }
73
+ }, {
74
+ key: "setMaxWidth",
75
+ value: function setMaxWidth(maxWidth) {
76
+ var writable = this.getWritable();
77
+ writable.__maxWidth = maxWidth;
78
+ }
79
+ }, {
80
+ key: "setWidth",
81
+ value: function setWidth(width) {
82
+ var writable = this.getWritable();
83
+ writable.__width = width;
84
+ }
68
85
  }, {
69
86
  key: "setUploaded",
70
87
  value: function setUploaded(url) {
@@ -1,12 +1,15 @@
1
1
  import type { JSX } from 'react';
2
2
  import { IEditorPluginConstructor } from "../../../types";
3
+ import { BlockImageNode } from '../node/block-image-node';
3
4
  import { ImageNode } from '../node/image-node';
4
5
  export interface ImagePluginOptions {
6
+ defaultBlockImage?: boolean;
5
7
  handleUpload: (file: File) => Promise<{
6
8
  url: string;
7
9
  }>;
8
- renderImage: (node: ImageNode) => JSX.Element | null;
10
+ renderImage: (node: ImageNode | BlockImageNode) => JSX.Element | null;
9
11
  theme?: {
12
+ blockImage?: string;
10
13
  image?: string;
11
14
  };
12
15
  }
@@ -20,44 +20,60 @@ import { KernelPlugin } from "../../../editor-kernel/plugin";
20
20
  import { IMarkdownShortCutService } from "../../markdown/service/shortcut";
21
21
  import { IUploadService, UPLOAD_PRIORITY_HIGH } from "../../upload";
22
22
  import { INSERT_IMAGE_COMMAND, registerImageCommand } from "../command";
23
+ import { $isBlockImageNode, BlockImageNode } from "../node/block-image-node";
23
24
  import { $isImageNode, ImageNode } from "../node/image-node";
24
25
  export var ImagePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
25
26
  _inherits(ImagePlugin, _KernelPlugin);
26
27
  var _super = _createSuper(ImagePlugin);
27
28
  function ImagePlugin(kernel, config) {
28
- var _kernel$requireServic;
29
29
  var _this;
30
30
  _classCallCheck(this, ImagePlugin);
31
31
  _this = _super.call(this);
32
32
  _this.kernel = kernel;
33
33
  _this.config = config;
34
- kernel.registerNodes([ImageNode]);
34
+ kernel.registerNodes([ImageNode, BlockImageNode]);
35
35
  ImageNode.setDecorate(config.renderImage);
36
+ BlockImageNode.setDecorate(config.renderImage);
36
37
  if (config !== null && config !== void 0 && config.theme) {
37
38
  kernel.registerThemes(config.theme);
38
39
  }
39
- (_kernel$requireServic = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic === void 0 || _kernel$requireServic.registerMarkdownWriter(ImageNode.getType(), function (ctx, node) {
40
- if ($isImageNode(node)) {
41
- ctx.appendLine("![".concat(node.altText, "](").concat(node.src, ")"));
42
- }
43
- });
44
40
  return _this;
45
41
  }
46
42
  _createClass(ImagePlugin, [{
47
43
  key: "onInit",
48
44
  value: function onInit(editor) {
49
- var _this$kernel$requireS;
50
- // Register the upload handler if provided
51
- (_this$kernel$requireS = this.kernel.requireService(IUploadService)) === null || _this$kernel$requireS === void 0 || _this$kernel$requireS.registerUpload( /*#__PURE__*/function () {
45
+ var _this$kernel$requireS,
46
+ _this$kernel$requireS2,
47
+ _this$kernel$requireS3,
48
+ _this2 = this;
49
+ (_this$kernel$requireS = this.kernel.requireService(IMarkdownShortCutService)) === null || _this$kernel$requireS === void 0 || _this$kernel$requireS.registerMarkdownWriter(ImageNode.getType(), function (ctx, node) {
50
+ if ($isImageNode(node)) {
51
+ ctx.appendLine("![".concat(node.altText, "](").concat(node.src, ")"));
52
+ }
53
+ });
54
+ (_this$kernel$requireS2 = this.kernel.requireService(IMarkdownShortCutService)) === null || _this$kernel$requireS2 === void 0 || _this$kernel$requireS2.registerMarkdownWriter(BlockImageNode.getType(), function (ctx, node) {
55
+ if ($isBlockImageNode(node)) {
56
+ ctx.appendLine("![".concat(node.altText, "](").concat(node.src, ")\n\n"));
57
+ }
58
+ });
59
+ (_this$kernel$requireS3 = this.kernel.requireService(IUploadService)) === null || _this$kernel$requireS3 === void 0 || _this$kernel$requireS3.registerUpload( /*#__PURE__*/function () {
52
60
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file, from, range) {
61
+ var _this2$config;
62
+ var imageWidth;
53
63
  return _regeneratorRuntime().wrap(function _callee$(_context) {
54
64
  while (1) switch (_context.prev = _context.next) {
55
65
  case 0:
66
+ _context.next = 2;
67
+ return _this2.getImageWidth(file);
68
+ case 2:
69
+ imageWidth = _context.sent;
56
70
  return _context.abrupt("return", editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
71
+ block: (_this2$config = _this2.config) === null || _this2$config === void 0 ? void 0 : _this2$config.defaultBlockImage,
57
72
  file: file,
73
+ maxWidth: imageWidth,
58
74
  range: range
59
75
  }));
60
- case 1:
76
+ case 4:
61
77
  case "end":
62
78
  return _context.stop();
63
79
  }
@@ -69,6 +85,30 @@ export var ImagePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
69
85
  }(), UPLOAD_PRIORITY_HIGH);
70
86
  this.register(registerImageCommand(editor, this.config.handleUpload));
71
87
  }
88
+ }, {
89
+ key: "getImageWidth",
90
+ value: function getImageWidth(file) {
91
+ return new Promise(function (resolve) {
92
+ var reader = new FileReader();
93
+ reader.addEventListener('load', function (e) {
94
+ var _e$target;
95
+ var img = new Image();
96
+ img.addEventListener('load', function () {
97
+ resolve(img.naturalWidth);
98
+ });
99
+ img.addEventListener('error', function () {
100
+ // Default width if image fails to load
101
+ resolve(800);
102
+ });
103
+ img.src = (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.result;
104
+ });
105
+ reader.addEventListener('error', function () {
106
+ // Default width if file reading fails
107
+ resolve(800);
108
+ });
109
+ reader.readAsDataURL(file);
110
+ });
111
+ }
72
112
  }]);
73
113
  return ImagePlugin;
74
114
  }(KernelPlugin), _defineProperty(_class, "pluginName", 'ImagePlugin'), _class);
@@ -15,7 +15,8 @@ import { useStyles } from "./style";
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  var ReactImagePlugin = function ReactImagePlugin(_ref) {
17
17
  var theme = _ref.theme,
18
- className = _ref.className;
18
+ className = _ref.className,
19
+ defaultBlockImage = _ref.defaultBlockImage;
19
20
  var _useLexicalComposerCo = useLexicalComposerContext(),
20
21
  _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
21
22
  editor = _useLexicalComposerCo2[0];
@@ -24,6 +25,7 @@ var ReactImagePlugin = function ReactImagePlugin(_ref) {
24
25
  useLayoutEffect(function () {
25
26
  editor.registerPlugin(UploadPlugin);
26
27
  editor.registerPlugin(ImagePlugin, {
28
+ defaultBlockImage: defaultBlockImage,
27
29
  handleUpload: function handleUpload(file) {
28
30
  return new Promise(function (resolve) {
29
31
  setTimeout(function () {
@@ -1,7 +1,8 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
+ import { BlockImageNode } from '../../node/block-image-node';
2
3
  import { ImageNode } from '../../node/image-node';
3
- declare const Image: import("react").NamedExoticComponent<{
4
+ declare const Image: React.NamedExoticComponent<{
4
5
  className?: string | undefined;
5
- node: ImageNode;
6
+ node: ImageNode | BlockImageNode;
6
7
  }>;
7
8
  export default Image;