@blocklet/editor 2.5.40 → 2.5.42
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/lib/config.d.ts +1 -0
- package/lib/main/nodes/ImageComponent.js +21 -2
- package/package.json +3 -3
package/lib/config.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export interface EditorConfig {
|
|
|
28
28
|
characterLimitConfig?: CharacterLimitConfig;
|
|
29
29
|
simpleImageComponent?: boolean;
|
|
30
30
|
enableSafeAreaPlugin?: boolean;
|
|
31
|
+
maxContentWidth?: number;
|
|
31
32
|
}
|
|
32
33
|
export declare function EditorConfigProvider({ children, value }: {
|
|
33
34
|
children: React.ReactNode;
|
|
@@ -18,8 +18,9 @@ import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection'
|
|
|
18
18
|
import { mergeRegister } from '@lexical/utils';
|
|
19
19
|
import { Alert, Box, Button, Dialog, LinearProgress, Skeleton } from '@mui/material';
|
|
20
20
|
import { $getNodeByKey, $getSelection, $isNodeSelection, $setSelection, CLICK_COMMAND, COMMAND_PRIORITY_LOW, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, SELECTION_CHANGE_COMMAND, } from 'lexical';
|
|
21
|
-
import { Suspense, useCallback, useEffect, useRef, useState, lazy } from 'react';
|
|
21
|
+
import { Suspense, useCallback, useEffect, useRef, useState, lazy, useMemo } from 'react';
|
|
22
22
|
import { createPortal } from 'react-dom';
|
|
23
|
+
import { withQuery, getQuery } from 'ufo';
|
|
23
24
|
import { useEditorConfig } from '../../config';
|
|
24
25
|
import { useSettings } from '../context/SettingsContext';
|
|
25
26
|
import { useSharedHistoryContext } from '../context/SharedHistoryContext';
|
|
@@ -362,6 +363,24 @@ function SimpleImageComponent({ src, altText = '', width, height, }) {
|
|
|
362
363
|
const [loaded, setLoaded] = useState(false);
|
|
363
364
|
const imageRef = useRef(null);
|
|
364
365
|
const hasFixedSize = typeof width === 'number' && typeof height === 'number' && width > 0 && height > 0;
|
|
366
|
+
const { maxContentWidth } = useEditorConfig();
|
|
367
|
+
const displaySrc = useMemo(() => {
|
|
368
|
+
if (!maxContentWidth)
|
|
369
|
+
return src;
|
|
370
|
+
try {
|
|
371
|
+
const qs = getQuery(src);
|
|
372
|
+
if (qs?.imageFilter)
|
|
373
|
+
return src;
|
|
374
|
+
// 图片剪裁,限制最大宽度
|
|
375
|
+
return withQuery(src, {
|
|
376
|
+
imageFilter: 'resize',
|
|
377
|
+
w: maxContentWidth,
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
catch {
|
|
381
|
+
return src;
|
|
382
|
+
}
|
|
383
|
+
}, [src, maxContentWidth]);
|
|
365
384
|
useMediumZoom(imageRef);
|
|
366
385
|
const renderSkeleton = () => {
|
|
367
386
|
if (hasFixedSize) {
|
|
@@ -376,7 +395,7 @@ function SimpleImageComponent({ src, altText = '', width, height, }) {
|
|
|
376
395
|
borderRadius: 2,
|
|
377
396
|
display: loaded ? 'block' : 'none',
|
|
378
397
|
...(hasFixedSize && { maxWidth: width, mx: 'auto' }),
|
|
379
|
-
}, children: _jsx(Box, { component: "img", src:
|
|
398
|
+
}, children: _jsx(Box, { component: "img", src: displaySrc, alt: altText || '', "data-zoom-src": src, onLoad: () => {
|
|
380
399
|
setLoaded(true);
|
|
381
400
|
}, sx: { width, height }, ref: imageRef }) })] }));
|
|
382
401
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/editor",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.42",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@blocklet/code-editor": "^0.7.7",
|
|
29
29
|
"@blocklet/embed": "^0.3.3",
|
|
30
|
-
"@blocklet/js-sdk": "^1.17.3
|
|
30
|
+
"@blocklet/js-sdk": "^1.17.3",
|
|
31
31
|
"@blocklet/pages-kit": "^0.7.26",
|
|
32
32
|
"@blocklet/pages-kit-runtime": "^0.7.26",
|
|
33
33
|
"@excalidraw/excalidraw": "^0.18.0",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"ufo": "^1.5.4",
|
|
74
74
|
"url-join": "^4.0.1",
|
|
75
75
|
"zustand": "^4.5.5",
|
|
76
|
-
"@blocklet/pdf": "2.5.
|
|
76
|
+
"@blocklet/pdf": "2.5.42"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@babel/core": "^7.25.2",
|