@wangeditor-next/editor 6.4.0 → 6.4.2
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/README.md +21 -0
- package/dist/basic-modules/src/modules/image/menu/WidthBase.d.ts +1 -0
- package/dist/basic-modules/src/modules/image/resize.d.ts +14 -0
- package/dist/basic-modules/src/modules/link/parse-elem-html.d.ts +2 -1
- package/dist/core/src/config/interface.d.ts +22 -0
- package/dist/core/src/index.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/editor/src/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -57,5 +57,26 @@ const { editor, toolbar } = factory.create({
|
|
|
57
57
|
import { createUploader } from '@wangeditor-next/editor/upload'
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
## 图片尺寸单位和校验
|
|
61
|
+
|
|
62
|
+
可通过 `imageResize` 统一配置编辑器内置的图片缩放入口。设置 `resizeUnit: 'px'` 后,修改尺寸、快捷尺寸和拖拽缩放都会使用 px:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
const editorConfig: Partial<IEditorConfig> = {
|
|
66
|
+
imageResize: {
|
|
67
|
+
resizeUnit: 'px',
|
|
68
|
+
resizeOptions: [
|
|
69
|
+
{ label: '200px', value: '200px' },
|
|
70
|
+
],
|
|
71
|
+
checkImageSize({ width, height, source }) {
|
|
72
|
+
if (Number.parseFloat(width) > 1200) return '图片宽度不能超过 1200px'
|
|
73
|
+
return true
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
不配置 `imageResize` 时保持历史行为。HTML 导入仍按原有解析规则处理,避免导入导出回环丢失尺寸信息。
|
|
80
|
+
|
|
60
81
|
交流
|
|
61
82
|
- [提交问题和建议](https://github.com/wangeditor-next/wangEditor-next/issues)
|
|
@@ -7,6 +7,7 @@ declare abstract class ImageWidthBaseClass implements IButtonMenu {
|
|
|
7
7
|
abstract readonly title: string;
|
|
8
8
|
readonly tag = "button";
|
|
9
9
|
abstract readonly value: string;
|
|
10
|
+
getTitle(editor: IDomEditor): string;
|
|
10
11
|
getValue(_editor: IDomEditor): string | boolean;
|
|
11
12
|
isActive(_editor: IDomEditor): boolean;
|
|
12
13
|
private getSelectedNode;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description shared image resize policy
|
|
3
|
+
*/
|
|
4
|
+
import { IDomEditor, IImageResizeOption, ImageResizeSource, ImageResizeUnit } from '@wangeditor-next/core';
|
|
5
|
+
import { Node } from 'slate';
|
|
6
|
+
export interface IImageResizeResult {
|
|
7
|
+
width: string;
|
|
8
|
+
height: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function getImageResizePreset(editor: IDomEditor, defaultValue: string): IImageResizeOption;
|
|
11
|
+
/** Normalize a user value, returning null when it violates a configured unit. */
|
|
12
|
+
export declare function normalizeImageSize(value: string, unit?: ImageResizeUnit, source?: ImageResizeSource): string | null;
|
|
13
|
+
export declare function validateImageSize(editor: IDomEditor, rawWidth: string, rawHeight: string, source: ImageResizeSource): IImageResizeResult | null;
|
|
14
|
+
export declare function updateImageSize(editor: IDomEditor, imageNode: Node, rawWidth: string, rawHeight: string, source: ImageResizeSource): boolean;
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
import { IDomEditor } from '@wangeditor-next/core';
|
|
6
6
|
import { Descendant } from 'slate';
|
|
7
7
|
import { DOMElement } from '../../utils/dom';
|
|
8
|
+
import { ImageElement } from '../image/custom-types';
|
|
8
9
|
import { LinkElement } from './custom-types';
|
|
9
|
-
declare function parseHtml(elem: DOMElement, children: Descendant[], editor: IDomEditor): LinkElement;
|
|
10
|
+
declare function parseHtml(elem: DOMElement, children: Descendant[], editor: IDomEditor): LinkElement | ImageElement;
|
|
10
11
|
export declare const parseHtmlConf: {
|
|
11
12
|
selector: string;
|
|
12
13
|
parseElemHtml: typeof parseHtml;
|
|
@@ -112,6 +112,27 @@ interface IInsertImageConfig extends IImageMenuBaseConfig {
|
|
|
112
112
|
interface IEditImageConfig extends IImageMenuBaseConfig {
|
|
113
113
|
onUpdatedImage?: (imageNode: ImageElement | null) => void;
|
|
114
114
|
}
|
|
115
|
+
export type ImageResizeUnit = 'px' | '%';
|
|
116
|
+
export type ImageResizeSource = 'modal' | 'preset' | 'drag';
|
|
117
|
+
export interface IImageResizeCheckPayload {
|
|
118
|
+
width: string;
|
|
119
|
+
height: string;
|
|
120
|
+
rawWidth: string;
|
|
121
|
+
rawHeight: string;
|
|
122
|
+
source: ImageResizeSource;
|
|
123
|
+
}
|
|
124
|
+
export interface IImageResizeOption {
|
|
125
|
+
label: string;
|
|
126
|
+
value: string;
|
|
127
|
+
}
|
|
128
|
+
export interface IImageResizeConfig {
|
|
129
|
+
/** Resize unit for editor-owned image resize actions. Omit to preserve legacy behavior. */
|
|
130
|
+
resizeUnit?: ImageResizeUnit;
|
|
131
|
+
/** Values for the built-in 30%/50%/100% preset buttons, in their existing order. */
|
|
132
|
+
resizeOptions?: IImageResizeOption[];
|
|
133
|
+
/** Validate normalized image dimensions before they are written to the document. */
|
|
134
|
+
checkImageSize?: (payload: IImageResizeCheckPayload) => boolean | undefined | string;
|
|
135
|
+
}
|
|
115
136
|
interface IEmotionConfig {
|
|
116
137
|
emotions: string[];
|
|
117
138
|
}
|
|
@@ -281,6 +302,7 @@ export interface IEditorConfig {
|
|
|
281
302
|
autoFocus: boolean;
|
|
282
303
|
decorate?: (nodeEntry: NodeEntry) => Range[];
|
|
283
304
|
maxLength?: number;
|
|
305
|
+
imageResize?: IImageResizeConfig;
|
|
284
306
|
MENU_CONF?: IMenuConfigUpdate;
|
|
285
307
|
hoverbarKeys?: IHoverbarConf;
|
|
286
308
|
EXTEND_CONF?: any;
|
package/dist/core/src/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { HtmlTransformFnType, IElemToHtmlConf, styleToHtmlFnType } from './
|
|
|
11
11
|
import createUploaderRuntime from './upload/createUploader';
|
|
12
12
|
import type { IUploadConfig } from './upload/interface';
|
|
13
13
|
export * from './create/index';
|
|
14
|
-
export type { ClassStylePolicy, IClassStyleUnsupportedPayload, IEditorConfig, ISingleMenuConfig, IToolbarConfig, IUploadImageConfig, IUploadVideoConfig, StyleClassTokenType, TextStyleMode, } from './config/interface';
|
|
14
|
+
export type { ClassStylePolicy, IClassStyleUnsupportedPayload, IEditorConfig, IImageResizeCheckPayload, IImageResizeConfig, IImageResizeOption, ImageResizeSource, ImageResizeUnit, ISingleMenuConfig, IToolbarConfig, IUploadImageConfig, IUploadVideoConfig, StyleClassTokenType, TextStyleMode, } from './config/interface';
|
|
15
15
|
export { EditorEvents } from './config/interface';
|
|
16
16
|
export * from './config/style-mode';
|
|
17
17
|
export * from './editor/dom-editor';
|