@wangeditor-next/core 1.7.7 → 1.7.9

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,22 @@
1
+ /**
2
+ * @description image element
3
+ * @author wangfupeng
4
+ */
5
+ type EmptyText = {
6
+ text: '';
7
+ };
8
+ export type ImageStyle = {
9
+ width?: string;
10
+ height?: string;
11
+ };
12
+ export type ImageElement = {
13
+ type: 'image';
14
+ src: string;
15
+ alt?: string;
16
+ href?: string;
17
+ width?: string;
18
+ height?: string;
19
+ style?: ImageStyle;
20
+ children: EmptyText[];
21
+ };
22
+ export {};
@@ -2,9 +2,12 @@
2
2
  * @description config interface
3
3
  * @author wangfupeng
4
4
  */
5
- import { Range, NodeEntry, Node } from 'slate';
5
+ import { ImageElement } from 'packages/basic-modules/src/modules/image/custom-types';
6
+ import { VideoElement } from 'packages/video-module/src/module/custom-types';
7
+ import { Node, NodeEntry, Range } from 'slate';
6
8
  import { IDomEditor } from '../editor/interface';
7
9
  import { IMenuGroup } from '../menus/interface';
10
+ import { IUploadConfig } from '../upload';
8
11
  interface IHoverbarConf {
9
12
  [key: string]: {
10
13
  match?: (editor: IDomEditor, n: Node) => boolean;
@@ -14,9 +17,139 @@ interface IHoverbarConf {
14
17
  export type AlertType = 'success' | 'info' | 'warning' | 'error';
15
18
  export interface ISingleMenuConfig {
16
19
  [key: string]: any;
20
+ iconSvg?: string;
21
+ }
22
+ interface IColorConfig {
23
+ colors: string[];
24
+ }
25
+ interface IFontSizeItem {
26
+ name: string;
27
+ value: string;
28
+ }
29
+ interface IFontSizeConfig {
30
+ fontSizeList: (string | IFontSizeItem)[];
31
+ }
32
+ interface IFontFamilyItem {
33
+ name: string;
34
+ value: string;
35
+ }
36
+ interface IFontFamilyConfig {
37
+ fontFamilyList: (string | IFontFamilyItem)[];
38
+ }
39
+ interface ILineHeightConfig {
40
+ lineHeightList: string[];
41
+ }
42
+ interface IImageMenuBaseConfig {
43
+ checkImage?: (src: string, alt: string, url: string) => boolean | undefined | string;
44
+ parseImageSrc?: (src: string) => string;
45
+ }
46
+ interface IInsertImageConfig extends IImageMenuBaseConfig {
47
+ onInsertedImage?: (imageNode: ImageElement | null) => void;
48
+ }
49
+ interface IEditImageConfig extends IImageMenuBaseConfig {
50
+ onUpdatedImage?: (imageNode: ImageElement | null) => void;
51
+ }
52
+ interface IEmotionConfig {
53
+ emotions: string[];
54
+ }
55
+ interface IInsertTableConfig {
56
+ minWidth: number;
57
+ tableHeader: {
58
+ selected: boolean;
59
+ };
60
+ tableFullWidth: {
61
+ selected: boolean;
62
+ };
63
+ }
64
+ interface ILinkConfig {
65
+ checkLink: (text: string, url: string) => string | boolean | undefined;
66
+ parseLinkUrl: (url: string) => string;
67
+ }
68
+ interface IInsertVideoConfig {
69
+ onInsertedVideo: (videoNode: VideoElement) => NodeEntry | Range;
70
+ checkVideo: (src: string, poster: string) => string | boolean | undefined;
71
+ parseVideoSrc: (url: string) => string;
72
+ }
73
+ interface IUploadVideoConfig extends IUploadConfig {
74
+ }
75
+ interface IUploadImageConfig extends IUploadConfig {
76
+ base64LimitSize?: number;
77
+ }
78
+ interface ICodeLangConfig {
79
+ codeLangs: {
80
+ text: string;
81
+ value: string;
82
+ }[];
17
83
  }
18
84
  export interface IMenuConfig {
19
- [key: string]: ISingleMenuConfig;
85
+ bold: ISingleMenuConfig;
86
+ underline: ISingleMenuConfig;
87
+ italic: ISingleMenuConfig;
88
+ through: ISingleMenuConfig;
89
+ code: ISingleMenuConfig;
90
+ sub: ISingleMenuConfig;
91
+ sup: ISingleMenuConfig;
92
+ clearStyle: ISingleMenuConfig;
93
+ color: IColorConfig;
94
+ bgColor: IColorConfig;
95
+ fontSize: IFontSizeConfig;
96
+ fontFamily: IFontFamilyConfig;
97
+ indent: ISingleMenuConfig;
98
+ delIndent: ISingleMenuConfig;
99
+ justifyLeft: ISingleMenuConfig;
100
+ justifyRight: ISingleMenuConfig;
101
+ justifyCenter: ISingleMenuConfig;
102
+ justifyJustify: ISingleMenuConfig;
103
+ lineHeight: ILineHeightConfig;
104
+ insertImage: IInsertImageConfig;
105
+ deleteImage: ISingleMenuConfig;
106
+ editImage: IEditImageConfig;
107
+ viewImageLink: ISingleMenuConfig;
108
+ imageWidth30: ISingleMenuConfig;
109
+ imageWidth50: ISingleMenuConfig;
110
+ imageWidth100: ISingleMenuConfig;
111
+ editorImageSizeMenu: ISingleMenuConfig;
112
+ divider: ISingleMenuConfig;
113
+ emotion: IEmotionConfig;
114
+ insertLink: ILinkConfig;
115
+ editLink: ILinkConfig;
116
+ unLink: ISingleMenuConfig;
117
+ viewLink: ISingleMenuConfig;
118
+ codeBlock: ISingleMenuConfig;
119
+ blockquote: ISingleMenuConfig;
120
+ headerSelect: ISingleMenuConfig;
121
+ header1: ISingleMenuConfig;
122
+ header2: ISingleMenuConfig;
123
+ header3: ISingleMenuConfig;
124
+ header4: ISingleMenuConfig;
125
+ header5: ISingleMenuConfig;
126
+ header6: ISingleMenuConfig;
127
+ todo: ISingleMenuConfig;
128
+ formatPainter: ISingleMenuConfig;
129
+ redo: ISingleMenuConfig;
130
+ undo: ISingleMenuConfig;
131
+ fullScreen: ISingleMenuConfig;
132
+ enter: ISingleMenuConfig;
133
+ bulletedList: ISingleMenuConfig;
134
+ numberedList: ISingleMenuConfig;
135
+ insertTable: ISingleMenuConfig;
136
+ deleteTable: ISingleMenuConfig;
137
+ insertTableRow: IInsertTableConfig;
138
+ deleteTableRow: ISingleMenuConfig;
139
+ insertTableCol: ISingleMenuConfig;
140
+ deleteTableCol: ISingleMenuConfig;
141
+ tableHeader: ISingleMenuConfig;
142
+ tableFullWidth: ISingleMenuConfig;
143
+ mergeTableCell: ISingleMenuConfig;
144
+ splitTableCell: ISingleMenuConfig;
145
+ setTableProperty: ISingleMenuConfig;
146
+ setTableCellProperty: ISingleMenuConfig;
147
+ insertVideo: IInsertVideoConfig;
148
+ uploadVideo: IUploadVideoConfig;
149
+ editVideoSize: ISingleMenuConfig;
150
+ editVideoSrc: ISingleMenuConfig;
151
+ uploadImage: IUploadImageConfig;
152
+ codeSelectLang: ICodeLangConfig;
20
153
  }
21
154
  /**
22
155
  * editor config
@@ -39,7 +172,7 @@ export interface IEditorConfig {
39
172
  autoFocus: boolean;
40
173
  decorate?: (nodeEntry: NodeEntry) => Range[];
41
174
  maxLength?: number;
42
- MENU_CONF?: IMenuConfig;
175
+ MENU_CONF?: Partial<IMenuConfig>;
43
176
  hoverbarKeys?: IHoverbarConf;
44
177
  EXTEND_CONF?: any;
45
178
  }
@@ -3,7 +3,7 @@
3
3
  * @author wangfupeng
4
4
  */
5
5
  import { IMenuConfig, ISingleMenuConfig } from '../config/interface';
6
- export declare const GLOBAL_MENU_CONF: IMenuConfig;
6
+ export declare const GLOBAL_MENU_CONF: Partial<IMenuConfig>;
7
7
  /**
8
8
  * 注册全局菜单配置
9
9
  * @param key menu key
@@ -2,14 +2,15 @@
2
2
  * @description editor interface
3
3
  * @author wangfupeng
4
4
  */
5
- import { Editor, Location, Node, Ancestor, Element } from 'slate';
6
5
  import ee from 'event-emitter';
7
- import { IEditorConfig, AlertType, ISingleMenuConfig } from '../config/interface';
6
+ import { Ancestor, Editor, Element, Location, Node } from 'slate';
7
+ import { AlertType, IEditorConfig, IMenuConfig, ISingleMenuConfig } from '../config/interface';
8
8
  import { IPositionStyle } from '../menus/interface';
9
9
  import { DOMElement } from '../utils/dom';
10
10
  export type ElementWithId = Element & {
11
11
  id: string;
12
12
  };
13
+ export type getMenuConfigReturnType<K> = K extends keyof IMenuConfig ? IMenuConfig[K] : ISingleMenuConfig;
13
14
  /**
14
15
  * 扩展 slate Editor 接口
15
16
  */
@@ -17,7 +18,7 @@ export interface IDomEditor extends Editor {
17
18
  insertData: (data: DataTransfer) => void;
18
19
  setFragmentData: (data: Pick<DataTransfer, 'getData' | 'setData'>) => void;
19
20
  getConfig: () => IEditorConfig;
20
- getMenuConfig: (menuKey: string) => ISingleMenuConfig;
21
+ getMenuConfig: <K extends string>(menuKey: K) => getMenuConfigReturnType<K>;
21
22
  getAllMenuKeys: () => string[];
22
23
  alert: (info: string, type: AlertType) => void;
23
24
  handleTab: () => void;
@@ -2,7 +2,7 @@
2
2
  * @description hover bar class
3
3
  * @author wangfupeng
4
4
  */
5
- import { IButtonMenu, ISelectMenu, IDropPanelMenu, IModalMenu } from '../interface';
5
+ import { IButtonMenu, IDropPanelMenu, IModalMenu, ISelectMenu } from '../interface';
6
6
  type MenuType = IButtonMenu | ISelectMenu | IDropPanelMenu | IModalMenu;
7
7
  declare class HoverBar {
8
8
  private readonly $elem;
@@ -3,8 +3,8 @@
3
3
  * @author wangfupeng
4
4
  */
5
5
  import { Node } from 'slate';
6
- import { Dom7Array } from '../../utils/dom';
7
6
  import { IDomEditor } from '../../editor/interface';
7
+ import { Dom7Array } from '../../utils/dom';
8
8
  import { IPositionStyle } from '../interface';
9
9
  /**
10
10
  * 获取 textContainer 尺寸和定位
@@ -3,6 +3,7 @@
3
3
  * @author wangfupeng
4
4
  */
5
5
  import { Node } from 'slate';
6
+ import { ISingleMenuConfig } from '../config/interface';
6
7
  import { IDomEditor } from '../editor/interface';
7
8
  import { DOMElement } from '../utils/dom';
8
9
  export interface IMenuGroup {
@@ -59,8 +60,6 @@ export type MenuFactoryType = () => IButtonMenu | ISelectMenu | IDropPanelMenu |
59
60
  export interface IRegisterMenuConf {
60
61
  key: string;
61
62
  factory: MenuFactoryType;
62
- config?: {
63
- [key: string]: any;
64
- };
63
+ config?: ISingleMenuConfig;
65
64
  }
66
65
  export {};
@@ -2,7 +2,8 @@
2
2
  * @description register menu
3
3
  * @author wangfupeng
4
4
  */
5
- import { MenuFactoryType, IRegisterMenuConf } from './interface';
5
+ import { ISingleMenuConfig } from '../config/interface';
6
+ import { IRegisterMenuConf, MenuFactoryType } from './interface';
6
7
  export declare const MENU_ITEM_FACTORIES: {
7
8
  [key: string]: MenuFactoryType;
8
9
  };
@@ -11,6 +12,4 @@ export declare const MENU_ITEM_FACTORIES: {
11
12
  * @param registerMenuConf { key, factory, config } ,各个 menu key 不能重复
12
13
  * @param customConfig 自定义 menu config
13
14
  */
14
- export declare function registerMenu(registerMenuConf: IRegisterMenuConf, customConfig?: {
15
- [key: string]: any;
16
- }): void;
15
+ export declare function registerMenu(registerMenuConf: IRegisterMenuConf, customConfig?: ISingleMenuConfig): void;
@@ -3,12 +3,6 @@
3
3
  * @author wangfupeng
4
4
  */
5
5
  import $, { Dom7Array } from 'dom7';
6
- export { Dom7Array } from 'dom7';
7
- export default $;
8
- export declare const isDocument: (value: any) => value is Document;
9
- export declare const isShadowRoot: (value: any) => value is ShadowRoot;
10
- export declare const isDataTransfer: (value: any) => value is DataTransfer;
11
- export declare const isHTMLElememt: (value: any) => value is HTMLElement;
12
6
  import DOMNode = globalThis.Node;
13
7
  import DOMComment = globalThis.Comment;
14
8
  import DOMElement = globalThis.Element;
@@ -16,12 +10,22 @@ import DOMText = globalThis.Text;
16
10
  import DOMRange = globalThis.Range;
17
11
  import DOMSelection = globalThis.Selection;
18
12
  import DOMStaticRange = globalThis.StaticRange;
19
- export { DOMNode, DOMComment, DOMElement, DOMText, DOMRange, DOMSelection, DOMStaticRange };
13
+ export { Dom7Array } from 'dom7';
14
+ export default $;
15
+ export declare const isDocument: (value: any) => value is Document;
16
+ export declare const isShadowRoot: (value: any) => value is ShadowRoot;
17
+ export declare const isDataTransfer: (value: any) => value is DataTransfer;
18
+ export declare const isHTMLElememt: (value: any) => value is HTMLElement;
19
+ export { DOMComment, DOMElement, DOMNode, DOMRange, DOMSelection, DOMStaticRange, DOMText, };
20
20
  export type DOMPoint = [Node, number];
21
21
  /**
22
22
  * Returns the host window of a DOM node
23
23
  */
24
24
  export declare const getDefaultView: (value: any) => Window | null;
25
+ /**
26
+ * Check if a value is a DOM node.
27
+ */
28
+ export declare const isDOMNode: (value: any) => value is DOMNode;
25
29
  /**
26
30
  * Check if a DOM node is a comment node.
27
31
  */
@@ -30,10 +34,6 @@ export declare const isDOMComment: (value: any) => value is DOMComment;
30
34
  * Check if a DOM node is an element node.
31
35
  */
32
36
  export declare const isDOMElement: (value: any) => value is DOMElement;
33
- /**
34
- * Check if a value is a DOM node.
35
- */
36
- export declare const isDOMNode: (value: any) => value is DOMNode;
37
37
  /**
38
38
  * Check if a value is a DOM selection.
39
39
  */