@blocklet/editor 2.0.117 → 2.0.119

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.
@@ -0,0 +1,9 @@
1
+ import { LexicalCommand } from 'lexical';
2
+ interface Payload {
3
+ busy: boolean;
4
+ }
5
+ export declare const UPDATE_BUSY_COMMAND: LexicalCommand<Payload>;
6
+ export declare function BusyPlugin({ onChange }: {
7
+ onChange: (busy: boolean) => void;
8
+ }): null;
9
+ export {};
@@ -0,0 +1,17 @@
1
+ import { useEffect } from 'react';
2
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
3
+ import { COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
4
+ import { mergeRegister } from '@lexical/utils';
5
+ export const UPDATE_BUSY_COMMAND = createCommand('UPDATE_BUSY_COMMAND');
6
+ export function BusyPlugin({ onChange }) {
7
+ const [editor] = useLexicalComposerContext();
8
+ useEffect(() => {
9
+ if (editor.isEditable()) {
10
+ return mergeRegister(editor.registerCommand(UPDATE_BUSY_COMMAND, (payload) => {
11
+ onChange(payload.busy);
12
+ return true;
13
+ }, COMMAND_PRIORITY_EDITOR));
14
+ }
15
+ }, [editor]);
16
+ return null;
17
+ }
@@ -37,6 +37,7 @@ import { useImageDisplayWidth } from '../hooks/hooks';
37
37
  import { useMediumZoom } from '../hooks/medium-zoom';
38
38
  import { FrameMockup, isDeviceFrame } from '../ui/FrameMockup';
39
39
  import { useSafeArea } from '../../ext/SafeAreaPlugin';
40
+ import { UPDATE_BUSY_COMMAND } from '../../ext/BusyPlugin';
40
41
  const imageCache = new Set();
41
42
  // Min size that require user confirm to upload image
42
43
  const REQUIRE_CONFIRM_UPLOAD_SIZE = 10 << 20;
@@ -221,6 +222,7 @@ export default function ImageComponent({ file, src, altText, nodeKey, width, hei
221
222
  }
222
223
  try {
223
224
  setLoading(true);
225
+ editor.dispatchCommand(UPDATE_BUSY_COMMAND, { busy: true });
224
226
  setError(undefined);
225
227
  const { url } = await config.uploader.upload(file);
226
228
  editor.update(() => {
@@ -236,6 +238,7 @@ export default function ImageComponent({ file, src, altText, nodeKey, width, hei
236
238
  }
237
239
  finally {
238
240
  setLoading(false);
241
+ editor.dispatchCommand(UPDATE_BUSY_COMMAND, { busy: false });
239
242
  }
240
243
  }, [file]);
241
244
  const confirmText = !!file && file.size > REQUIRE_CONFIRM_UPLOAD_SIZE
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/editor",
3
- "version": "2.0.117",
3
+ "version": "2.0.119",
4
4
  "main": "lib/index.js",
5
5
  "scripts": {
6
6
  "dev": "npm run storybook",
@@ -40,7 +40,7 @@
40
40
  "@arcblock/ux": "^2.10.12",
41
41
  "@blocklet/embed": "^0.1.11",
42
42
  "@blocklet/pages-kit": "^0.2.390",
43
- "@blocklet/pdf": "2.0.117",
43
+ "@blocklet/pdf": "2.0.119",
44
44
  "@excalidraw/excalidraw": "^0.14.2",
45
45
  "@iconify/iconify": "^3.0.1",
46
46
  "@iconify/icons-tabler": "^1.2.95",
@@ -113,5 +113,5 @@
113
113
  "react": "*",
114
114
  "react-dom": "*"
115
115
  },
116
- "gitHead": "3238c44094b76d4569bba297714fb8c001b7d69e"
116
+ "gitHead": "d4fbfa1d9180513375de802458d6420a7c5bd231"
117
117
  }