@lingxiteam/lcdp-ueditor-react 1.0.4-alpha.1 → 1.0.4-alpha.3
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/es/LcdpUeditor.d.ts +1 -0
- package/es/LcdpUeditor.js +17 -12
- package/es/ToolBottomBar/FormatModal/index.js +79 -75
- package/es/ToolBottomBar/index.d.ts +2 -3
- package/es/ToolBottomBar/index.js +55 -46
- package/es/tools/generateStylesFromSettings.d.ts +16 -2
- package/es/tools/generateStylesFromSettings.js +187 -7
- package/es/type.d.ts +4 -5
- package/lib/LcdpUeditor.d.ts +1 -0
- package/lib/LcdpUeditor.js +12 -7
- package/lib/ToolBottomBar/FormatModal/index.js +49 -38
- package/lib/ToolBottomBar/index.d.ts +2 -3
- package/lib/ToolBottomBar/index.js +45 -35
- package/lib/tools/generateStylesFromSettings.d.ts +16 -2
- package/lib/tools/generateStylesFromSettings.js +167 -48
- package/lib/type.d.ts +4 -5
- package/package.json +1 -1
- package/ueditor-resource/lang/en/en.js +1 -1
- package/ueditor-resource/lang/zh-cn/zh-cn.js +1 -1
- package/ueditor-resource/lang/zh-tw/zh-tw.js +1 -1
- package/ueditor-resource/ueditor.all.js +21 -20
- package/es/LcdpUeditor.d.ts.map +0 -1
- package/es/ToolBottomBar/FormatModal/index.d.ts.map +0 -1
- package/es/ToolBottomBar/ProgressModal/index.d.ts.map +0 -1
- package/es/ToolBottomBar/index.d.ts.map +0 -1
- package/es/const.d.ts.map +0 -1
- package/es/icon/ExportPDF.d.ts.map +0 -1
- package/es/icon/TextCopy.d.ts.map +0 -1
- package/es/icon/TextFileIcon.d.ts.map +0 -1
- package/es/icon/TextIcon.d.ts.map +0 -1
- package/es/index.d.ts.map +0 -1
- package/es/tools/UeditorResourceLoader.d.ts.map +0 -1
- package/es/tools/exportPDF.d.ts.map +0 -1
- package/es/tools/filterHtmlNode.d.ts.map +0 -1
- package/es/tools/generateStylesFromSettings.d.ts.map +0 -1
- package/es/tools/loadScript.d.ts.map +0 -1
- package/es/type.d.ts.map +0 -1
|
@@ -1,24 +1,204 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
export var STYLE_ID = 'ueditor-custom-styles';
|
|
4
|
+
|
|
5
|
+
// 自定义格式设置标签,用于回填格式设置
|
|
6
|
+
export var FORMAT_STYLE_TAG = 'format-style';
|
|
7
|
+
|
|
2
8
|
/**
|
|
3
9
|
* 生成CSS样式内容
|
|
10
|
+
* 将css设置到元素上
|
|
4
11
|
* @param settings 格式设置
|
|
5
|
-
* @returns CSS样式字符串
|
|
6
12
|
*/
|
|
7
|
-
export var generateStylesFromSettings = function generateStylesFromSettings(settings) {
|
|
8
|
-
var
|
|
13
|
+
export var generateStylesFromSettings = function generateStylesFromSettings(settings, body) {
|
|
14
|
+
var cssMap = {
|
|
15
|
+
h1: undefined,
|
|
16
|
+
h2: undefined,
|
|
17
|
+
h3: undefined,
|
|
18
|
+
h4: undefined,
|
|
19
|
+
h5: undefined,
|
|
20
|
+
h6: undefined,
|
|
21
|
+
p: undefined,
|
|
22
|
+
ul: undefined,
|
|
23
|
+
ol: undefined
|
|
24
|
+
};
|
|
25
|
+
var cssStyles = '';
|
|
9
26
|
|
|
10
27
|
// 处理标题样式
|
|
11
28
|
Object.entries(settings.headings).forEach(function (_ref) {
|
|
12
29
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
13
30
|
heading = _ref2[0],
|
|
14
31
|
style = _ref2[1];
|
|
15
|
-
|
|
32
|
+
cssMap[heading] = {
|
|
33
|
+
fontFamily: style.fontFamily,
|
|
34
|
+
fontSize: style.fontSize,
|
|
35
|
+
fontWeight: style.fontWeight,
|
|
36
|
+
lineHeight: style.lineHeight,
|
|
37
|
+
color: style.color
|
|
38
|
+
};
|
|
16
39
|
});
|
|
17
40
|
|
|
18
41
|
// 处理段落样式
|
|
19
|
-
|
|
42
|
+
cssMap.p = {
|
|
43
|
+
fontFamily: settings.paragraph.fontFamily,
|
|
44
|
+
fontSize: settings.paragraph.fontSize,
|
|
45
|
+
fontWeight: settings.paragraph.fontWeight,
|
|
46
|
+
lineHeight: settings.paragraph.lineHeight,
|
|
47
|
+
color: settings.paragraph.color
|
|
48
|
+
};
|
|
20
49
|
|
|
21
50
|
// 处理列表样式
|
|
22
|
-
|
|
23
|
-
|
|
51
|
+
cssMap.ul = {
|
|
52
|
+
fontFamily: settings.lists.ul.fontFamily,
|
|
53
|
+
fontSize: settings.lists.ul.fontSize,
|
|
54
|
+
fontWeight: settings.lists.ul.fontWeight,
|
|
55
|
+
lineHeight: settings.lists.ul.lineHeight,
|
|
56
|
+
color: settings.lists.ul.color,
|
|
57
|
+
paddingLeft: settings.lists.ul.paddingLeft,
|
|
58
|
+
marginTop: settings.lists.ul.marginTop,
|
|
59
|
+
marginBottom: settings.lists.ul.marginBottom
|
|
60
|
+
};
|
|
61
|
+
cssMap.ol = {
|
|
62
|
+
fontFamily: settings.lists.ol.fontFamily,
|
|
63
|
+
fontSize: settings.lists.ol.fontSize,
|
|
64
|
+
fontWeight: settings.lists.ol.fontWeight,
|
|
65
|
+
lineHeight: settings.lists.ol.lineHeight,
|
|
66
|
+
color: settings.lists.ol.color,
|
|
67
|
+
paddingLeft: settings.lists.ol.paddingLeft,
|
|
68
|
+
marginTop: settings.lists.ol.marginTop,
|
|
69
|
+
marginBottom: settings.lists.ol.marginBottom
|
|
70
|
+
};
|
|
71
|
+
Object.entries(cssMap).forEach(function (_ref3) {
|
|
72
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
73
|
+
key = _ref4[0],
|
|
74
|
+
value = _ref4[1];
|
|
75
|
+
if (value) {
|
|
76
|
+
cssStyles += "".concat(key, " {").concat(value.fontFamily ? "font-family: ".concat(value.fontFamily, ";\n") : '').concat(value.fontSize ? "font-size: ".concat(value.fontSize, ";\n") : '').concat(value.fontWeight ? "font-weight: ".concat(value.fontWeight, ";\n") : '').concat(value.lineHeight ? "line-height: ".concat(value.lineHeight, ";\n") : '').concat(value.color ? "color: ".concat(value.color, ";\n") : '').concat(value.marginTop ? "margin-top: ".concat(value.marginTop, ";\n") : '').concat(value.marginBottom ? "margin-bottom: ".concat(value.marginBottom, ";\n") : '').concat(value.paddingLeft ? "padding-left: ".concat(value.paddingLeft, ";\n") : '', "\n }");
|
|
77
|
+
body.querySelectorAll(key).forEach(function (item) {
|
|
78
|
+
// 遍历样式属性,仅在元素没有该样式时设置
|
|
79
|
+
Object.entries(value).forEach(function (_ref5) {
|
|
80
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
81
|
+
styleName = _ref6[0],
|
|
82
|
+
styleValue = _ref6[1];
|
|
83
|
+
if (styleValue) {
|
|
84
|
+
item.style[styleName] = styleValue;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return cssStyles;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 从现有样式标签中提取格式设置
|
|
95
|
+
* @param body HTML body元素
|
|
96
|
+
* @returns 格式设置对象,如果未找到样式标签则返回undefined
|
|
97
|
+
*/
|
|
98
|
+
export var extractSettingsFromStyles = function extractSettingsFromStyles(body) {
|
|
99
|
+
var styleElement = body.querySelector("#".concat(STYLE_ID));
|
|
100
|
+
if (!styleElement || !styleElement.textContent) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
var cssText = styleElement.textContent;
|
|
104
|
+
|
|
105
|
+
// 解析CSS规则
|
|
106
|
+
var parseCSSRule = function parseCSSRule(selector) {
|
|
107
|
+
var regex = new RegExp("".concat(selector, "\\s*{([^}]+)}"), 'g');
|
|
108
|
+
var match = regex.exec(cssText);
|
|
109
|
+
if (!match) return {};
|
|
110
|
+
var styleText = match[1];
|
|
111
|
+
var styles = {};
|
|
112
|
+
|
|
113
|
+
// 解析样式属性
|
|
114
|
+
var styleRegex = /([a-zA-Z-]+)\s*:\s*([^;]+);/g;
|
|
115
|
+
var styleMatch = styleRegex.exec(styleText);
|
|
116
|
+
while (styleMatch !== null) {
|
|
117
|
+
var _styleMatch = styleMatch,
|
|
118
|
+
_styleMatch2 = _slicedToArray(_styleMatch, 3),
|
|
119
|
+
property = _styleMatch2[1],
|
|
120
|
+
value = _styleMatch2[2];
|
|
121
|
+
styles[property.trim()] = value.trim();
|
|
122
|
+
styleMatch = styleRegex.exec(styleText);
|
|
123
|
+
}
|
|
124
|
+
return styles;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// 提取文本样式
|
|
128
|
+
var extractTextStyle = function extractTextStyle(selector) {
|
|
129
|
+
var styles = parseCSSRule(selector);
|
|
130
|
+
return {
|
|
131
|
+
fontSize: styles['font-size'] || '16px',
|
|
132
|
+
fontFamily: styles['font-family'] || 'Arial, sans-serif',
|
|
133
|
+
fontWeight: styles['font-weight'] || 'normal',
|
|
134
|
+
lineHeight: styles['line-height'] || '1.5',
|
|
135
|
+
color: styles.color || '#000000'
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// 提取标题样式
|
|
140
|
+
var extractHeadingStyle = function extractHeadingStyle(selector) {
|
|
141
|
+
var textStyle = extractTextStyle(selector);
|
|
142
|
+
var styles = parseCSSRule(selector);
|
|
143
|
+
return _objectSpread(_objectSpread({}, textStyle), {}, {
|
|
144
|
+
marginTop: styles['margin-top'] || '0',
|
|
145
|
+
marginBottom: styles['margin-bottom'] || '0'
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// 提取列表样式
|
|
150
|
+
var extractListStyle = function extractListStyle(selector) {
|
|
151
|
+
var textStyle = extractTextStyle(selector);
|
|
152
|
+
var styles = parseCSSRule(selector);
|
|
153
|
+
return _objectSpread(_objectSpread({}, textStyle), {}, {
|
|
154
|
+
paddingLeft: styles['padding-left'] || '0',
|
|
155
|
+
marginTop: styles['margin-top'] || '0',
|
|
156
|
+
marginBottom: styles['margin-bottom'] || '0'
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// 构建FormatSettings对象
|
|
161
|
+
var formatSettings = {
|
|
162
|
+
headings: {
|
|
163
|
+
h1: extractHeadingStyle('h1'),
|
|
164
|
+
h2: extractHeadingStyle('h2'),
|
|
165
|
+
h3: extractHeadingStyle('h3'),
|
|
166
|
+
h4: extractHeadingStyle('h4'),
|
|
167
|
+
h5: extractHeadingStyle('h5'),
|
|
168
|
+
h6: extractHeadingStyle('h6')
|
|
169
|
+
},
|
|
170
|
+
paragraph: extractTextStyle('p'),
|
|
171
|
+
lists: {
|
|
172
|
+
ul: extractListStyle('ul'),
|
|
173
|
+
ol: extractListStyle('ol')
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
return formatSettings;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 设置格式设置
|
|
181
|
+
* @param body
|
|
182
|
+
* @param settings
|
|
183
|
+
*/
|
|
184
|
+
export var setFormatSettings = function setFormatSettings(body, cssStyles) {
|
|
185
|
+
var styleEl = body.querySelector("#".concat(STYLE_ID));
|
|
186
|
+
if (!styleEl || !cssStyles) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (cssStyles) {
|
|
190
|
+
// 触发编辑器视图更新
|
|
191
|
+
if (body) {
|
|
192
|
+
// 查找或创建样式元素
|
|
193
|
+
var _styleEl = body === null || body === void 0 ? void 0 : body.querySelector("#".concat(STYLE_ID));
|
|
194
|
+
if (!_styleEl) {
|
|
195
|
+
_styleEl = document.createElement(FORMAT_STYLE_TAG);
|
|
196
|
+
_styleEl.style.display = 'none';
|
|
197
|
+
_styleEl.id = STYLE_ID;
|
|
198
|
+
body.insertBefore(_styleEl, body.firstChild);
|
|
199
|
+
}
|
|
200
|
+
// 设置样式内容
|
|
201
|
+
_styleEl.textContent = cssStyles;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
24
204
|
};
|
package/es/type.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { FormatSettings } from './tools/generateStylesFromSettings';
|
|
3
2
|
interface IUeditorStype extends React.CSSProperties {
|
|
4
3
|
toolbarColor?: string;
|
|
5
4
|
}
|
|
@@ -110,13 +109,13 @@ export interface ILcdpUeditorProps {
|
|
|
110
109
|
*/
|
|
111
110
|
prefixCls?: string;
|
|
112
111
|
/**
|
|
113
|
-
*
|
|
112
|
+
* 设置变化
|
|
114
113
|
*/
|
|
115
|
-
|
|
114
|
+
onSettingChange?(val: Record<Required<ILcdpUeditorProps>['bottomTypes'][number], any>): void;
|
|
116
115
|
/**
|
|
117
|
-
*
|
|
116
|
+
* 默认设置
|
|
118
117
|
*/
|
|
119
|
-
|
|
118
|
+
defaultSetting?: Record<Required<ILcdpUeditorProps>['bottomTypes'][number], any>;
|
|
120
119
|
/**
|
|
121
120
|
* 底部功能类型
|
|
122
121
|
*/
|
package/lib/LcdpUeditor.d.ts
CHANGED
package/lib/LcdpUeditor.js
CHANGED
|
@@ -40,6 +40,7 @@ var import_UeditorResourceLoader = __toESM(require("./tools/UeditorResourceLoade
|
|
|
40
40
|
var import_debounce = __toESM(require("lodash/debounce"));
|
|
41
41
|
var import_filterHtmlNode = require("./tools/filterHtmlNode");
|
|
42
42
|
var import_ToolBottomBar = __toESM(require("./ToolBottomBar"));
|
|
43
|
+
var BOTTOM_STATUS_BAR_CLASS = "ueditor-bottom-bar-with-status";
|
|
43
44
|
var LcdpUeditor = class extends import_react.default.Component {
|
|
44
45
|
constructor(props) {
|
|
45
46
|
super(props);
|
|
@@ -85,7 +86,11 @@ var LcdpUeditor = class extends import_react.default.Component {
|
|
|
85
86
|
* 编辑器配置项
|
|
86
87
|
*/
|
|
87
88
|
this.editorConfig = {};
|
|
88
|
-
|
|
89
|
+
this.onSettingChange = (setting) => {
|
|
90
|
+
this.editorConfig.onSettingChange(setting);
|
|
91
|
+
this.onContentChange();
|
|
92
|
+
};
|
|
93
|
+
const { config, prefixCls, onSettingChange } = props;
|
|
89
94
|
this.containerId = `ueditor_${Date.now()}_${String(Math.random()).slice(2, 6)}`;
|
|
90
95
|
if (this.props.ueditorPath) {
|
|
91
96
|
this.ueditorPath = this.props.ueditorPath;
|
|
@@ -121,7 +126,7 @@ var LcdpUeditor = class extends import_react.default.Component {
|
|
|
121
126
|
uploadFunction: this.uploadFunction,
|
|
122
127
|
initialContent: "",
|
|
123
128
|
pasteplain: (config == null ? void 0 : config.pasteplain) === true,
|
|
124
|
-
|
|
129
|
+
onSettingChange,
|
|
125
130
|
exportFileName: (config == null ? void 0 : config.exportFileName) || "未命名"
|
|
126
131
|
};
|
|
127
132
|
this.debounceContentChange = (0, import_debounce.default)(this.onContentChange.bind(this), 300);
|
|
@@ -146,7 +151,7 @@ var LcdpUeditor = class extends import_react.default.Component {
|
|
|
146
151
|
}
|
|
147
152
|
componentDidUpdate(prevProps) {
|
|
148
153
|
var _a, _b, _c;
|
|
149
|
-
if (this.state.isReady && (prevProps.
|
|
154
|
+
if (this.state.isReady && (prevProps.defaultSetting !== this.props.defaultSetting || prevProps.bottomTypes !== this.props.bottomTypes || ((_a = prevProps == null ? void 0 : prevProps.config) == null ? void 0 : _a.exportFileName) !== ((_c = (_b = this.props) == null ? void 0 : _b.config) == null ? void 0 : _c.exportFileName))) {
|
|
150
155
|
this.renderStatusBar();
|
|
151
156
|
}
|
|
152
157
|
}
|
|
@@ -319,8 +324,8 @@ var LcdpUeditor = class extends import_react.default.Component {
|
|
|
319
324
|
ueditorInst: this.ueditorInst,
|
|
320
325
|
prefixCls: this.prefixCls,
|
|
321
326
|
containerRef: this.containerRef,
|
|
322
|
-
|
|
323
|
-
|
|
327
|
+
defaultSetting: this.props.defaultSetting,
|
|
328
|
+
onSettingChange: this.onSettingChange,
|
|
324
329
|
isReady: this.state.isReady,
|
|
325
330
|
bottomTypes: this.props.bottomTypes,
|
|
326
331
|
exportFileName: (_c = (_b = this.props) == null ? void 0 : _b.config) == null ? void 0 : _c.exportFileName
|
|
@@ -328,9 +333,9 @@ var LcdpUeditor = class extends import_react.default.Component {
|
|
|
328
333
|
);
|
|
329
334
|
if (bottomBarContainer) {
|
|
330
335
|
let statusContainer = bottomBarContainer.querySelector(`#${id}_bottomStatusBar`);
|
|
331
|
-
bottomBarContainer.classList.remove(
|
|
336
|
+
bottomBarContainer.classList.remove(BOTTOM_STATUS_BAR_CLASS);
|
|
332
337
|
if ((_d = this.props.bottomTypes) == null ? void 0 : _d.length) {
|
|
333
|
-
bottomBarContainer.classList.add(
|
|
338
|
+
bottomBarContainer.classList.add(BOTTOM_STATUS_BAR_CLASS);
|
|
334
339
|
if (!statusContainer) {
|
|
335
340
|
statusContainer = document.createElement("div");
|
|
336
341
|
statusContainer.id = `${id}_bottomStatusBar`;
|
|
@@ -52,6 +52,31 @@ var defaultSettings = {
|
|
|
52
52
|
ol: { fontSize: "16px", fontFamily: "系统字体", fontWeight: "normal", lineHeight: "1.7", color: "#2c3e50", paddingLeft: "1rem", marginTop: "1rem", marginBottom: "1rem" }
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
|
+
var fontFamilyTranslations = {
|
|
56
|
+
default: "默认",
|
|
57
|
+
songti: "宋体",
|
|
58
|
+
kaiti: "楷体",
|
|
59
|
+
heiti: "黑体",
|
|
60
|
+
lishu: "隶书",
|
|
61
|
+
yahei: "微软雅黑",
|
|
62
|
+
fangsong: "仿宋",
|
|
63
|
+
dengxian: "等线",
|
|
64
|
+
segoeUI: "Segoe UI",
|
|
65
|
+
calibri: "Calibri",
|
|
66
|
+
arial: "arial",
|
|
67
|
+
timesNewRoman: "times new roman",
|
|
68
|
+
pingfangSC: "苹方(简)",
|
|
69
|
+
pingfangTC: "苹方(繁)",
|
|
70
|
+
hiraginoSansGB: "冬青黑体",
|
|
71
|
+
stFangsong: "华文仿宋",
|
|
72
|
+
sanFrancisco: "旧金山字体",
|
|
73
|
+
helveticaNeue: "Helvetica Neue",
|
|
74
|
+
sourceHanSans: "Source Han Sans",
|
|
75
|
+
wenQuanYiMicroHei: "文泉驿微米黑",
|
|
76
|
+
wenQuanYiZenHei: "文泉驿正黑",
|
|
77
|
+
dejaVuSans: "DejaVu Sans",
|
|
78
|
+
liberationSans: "Liberation Sans"
|
|
79
|
+
};
|
|
55
80
|
var getOSType = () => {
|
|
56
81
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
57
82
|
if (userAgent.includes("win"))
|
|
@@ -92,57 +117,43 @@ var generateFontOptions = () => {
|
|
|
92
117
|
const osType = getOSType();
|
|
93
118
|
const baseFonts = [
|
|
94
119
|
{ value: "系统字体", label: "系统字体(推荐)" },
|
|
95
|
-
{ value:
|
|
120
|
+
{ value: 'STHeiti, 黑体, SimHei, "Noto Sans CJK SC"', label: fontFamilyTranslations.heiti },
|
|
121
|
+
{ value: 'STSong, 宋体, SimSun, "Noto Serif CJK SC"', label: fontFamilyTranslations.songti }
|
|
122
|
+
// { value: "-apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Helvetica, Arial, sans-serif", label: '完整系统字体栈' },
|
|
96
123
|
];
|
|
97
124
|
const platformFonts = {
|
|
98
125
|
windows: [
|
|
99
|
-
{ value: "
|
|
100
|
-
{ value: "仿宋", label:
|
|
101
|
-
{ value: "
|
|
102
|
-
{ value: "
|
|
103
|
-
{ value: "
|
|
104
|
-
{ value: "
|
|
105
|
-
{ value: "
|
|
106
|
-
{ value: "
|
|
126
|
+
{ value: "微软雅黑,Microsoft YaHei", label: fontFamilyTranslations.yahei },
|
|
127
|
+
{ value: "仿宋", label: fontFamilyTranslations.fangsong },
|
|
128
|
+
{ value: "STKaiti, 楷体, 楷体_GB2312, SimKai", label: fontFamilyTranslations.kaiti },
|
|
129
|
+
{ value: "隶书,SimLi", label: fontFamilyTranslations.lishu },
|
|
130
|
+
{ value: "等线", label: fontFamilyTranslations.dengxian },
|
|
131
|
+
{ value: "Segoe UI", label: fontFamilyTranslations.segoeUI },
|
|
132
|
+
{ value: "Calibri", label: fontFamilyTranslations.calibri },
|
|
133
|
+
{ value: "arial,helvetica,sans-serif", label: fontFamilyTranslations.arial },
|
|
134
|
+
{ value: "times new roman", label: fontFamilyTranslations.timesNewRoman }
|
|
107
135
|
],
|
|
108
136
|
mac: [
|
|
109
|
-
{ value: "
|
|
110
|
-
{ value: "PingFang
|
|
111
|
-
{ value: "
|
|
112
|
-
{ value: "
|
|
113
|
-
{ value: "
|
|
114
|
-
{ value: "
|
|
115
|
-
{ value: "
|
|
116
|
-
{ value: "San Francisco", label: "旧金山字体" },
|
|
117
|
-
{ value: "Helvetica Neue", label: "Helvetica Neue" }
|
|
137
|
+
{ value: "STKaiti, 楷体, 楷体_GB2312, SimKai", label: fontFamilyTranslations.kaiti },
|
|
138
|
+
{ value: "PingFang SC", label: fontFamilyTranslations.pingfangSC },
|
|
139
|
+
{ value: "PingFang TC", label: fontFamilyTranslations.pingfangTC },
|
|
140
|
+
{ value: "Hiragino Sans GB", label: fontFamilyTranslations.hiraginoSansGB },
|
|
141
|
+
{ value: "STFangsong", label: fontFamilyTranslations.stFangsong },
|
|
142
|
+
{ value: "San Francisco", label: fontFamilyTranslations.sanFrancisco },
|
|
143
|
+
{ value: "Helvetica Neue", label: fontFamilyTranslations.helveticaNeue }
|
|
118
144
|
],
|
|
119
145
|
linux: [
|
|
120
|
-
{ value: "
|
|
121
|
-
{ value: "
|
|
122
|
-
{ value: "
|
|
123
|
-
{ value: "
|
|
124
|
-
{ value: "
|
|
125
|
-
{ value: "DejaVu Sans", label: "DejaVu Sans" },
|
|
126
|
-
{ value: "Liberation Sans", label: "Liberation Sans" }
|
|
146
|
+
{ value: "Source Han Sans", label: fontFamilyTranslations.sourceHanSans },
|
|
147
|
+
{ value: "WenQuanYi Micro Hei", label: fontFamilyTranslations.wenQuanYiMicroHei },
|
|
148
|
+
{ value: "WenQuanYi Zen Hei", label: fontFamilyTranslations.wenQuanYiZenHei },
|
|
149
|
+
{ value: "DejaVu Sans", label: fontFamilyTranslations.dejaVuSans },
|
|
150
|
+
{ value: "Liberation Sans", label: fontFamilyTranslations.liberationSans }
|
|
127
151
|
]
|
|
128
152
|
};
|
|
129
|
-
const webSafeFonts = [
|
|
130
|
-
{ value: "Arial", label: "Arial" },
|
|
131
|
-
{ value: "Helvetica", label: "Helvetica" },
|
|
132
|
-
{ value: "Times New Roman", label: "Times New Roman" },
|
|
133
|
-
{ value: "Times", label: "Times" },
|
|
134
|
-
{ value: "Courier New", label: "Courier New" },
|
|
135
|
-
{ value: "Georgia", label: "Georgia" },
|
|
136
|
-
{ value: "Verdana", label: "Verdana" },
|
|
137
|
-
{ value: "sans-serif", label: "系统无衬线字体" },
|
|
138
|
-
{ value: "serif", label: "系统衬线字体" },
|
|
139
|
-
{ value: "monospace", label: "系统等宽字体" }
|
|
140
|
-
];
|
|
141
153
|
const allFonts = [...baseFonts];
|
|
142
154
|
if (platformFonts[osType]) {
|
|
143
155
|
allFonts.push(...platformFonts[osType]);
|
|
144
156
|
}
|
|
145
|
-
allFonts.push(...webSafeFonts);
|
|
146
157
|
const availableFonts = allFonts.map((font) => ({
|
|
147
158
|
...font,
|
|
148
159
|
available: isFontAvailable(font.value)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { FormatSettings } from '../tools/generateStylesFromSettings';
|
|
3
2
|
import './index.less';
|
|
4
3
|
import { ILcdpUeditorProps } from '../type';
|
|
5
4
|
declare const ToolBottomBar: (props: {
|
|
@@ -15,8 +14,8 @@ declare const ToolBottomBar: (props: {
|
|
|
15
14
|
* 容器引用
|
|
16
15
|
*/
|
|
17
16
|
containerRef?: React.RefObject<HTMLDivElement> | undefined;
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
defaultSetting?: Record<"chineseCount" | "charCount" | "pageWidth" | "formatSetting" | "exportPdf" | "fullScreen" | "copy", any> | undefined;
|
|
18
|
+
onSettingChange?: ((setting: Partial<Record<Required<ILcdpUeditorProps>['bottomTypes'][number], any>>) => void) | undefined;
|
|
20
19
|
/**
|
|
21
20
|
* 是否准备就绪
|
|
22
21
|
*/
|
|
@@ -51,9 +51,8 @@ var MENU_OPTIONS = {
|
|
|
51
51
|
a5: "A5",
|
|
52
52
|
a0: "铺满"
|
|
53
53
|
};
|
|
54
|
-
var STYLE_ID = "ueditor-custom-styles";
|
|
55
54
|
var ToolBottomBar = (props) => {
|
|
56
|
-
const { ueditorInst, prefixCls, containerRef,
|
|
55
|
+
const { ueditorInst, prefixCls, containerRef, defaultSetting, onSettingChange, isReady, bottomTypes, exportFileName } = props;
|
|
57
56
|
const { id: uiId } = ueditorInst.ui || {};
|
|
58
57
|
const [chineseTextCount, setChineseTextCount] = (0, import_react.useState)(0);
|
|
59
58
|
const [totalTextCount, setTotalTextCount] = (0, import_react.useState)(0);
|
|
@@ -62,6 +61,7 @@ var ToolBottomBar = (props) => {
|
|
|
62
61
|
const [pageWidth, setPageWidth] = (0, import_react.useState)(void 0);
|
|
63
62
|
const timer = (0, import_react.useRef)(void 0);
|
|
64
63
|
const progressModalRef = (0, import_react.useRef)(null);
|
|
64
|
+
const [formatSetting, setFormatSetting] = (0, import_react.useState)(void 0);
|
|
65
65
|
const debounceContentChange = (0, import_debounce.default)(() => {
|
|
66
66
|
var _a;
|
|
67
67
|
try {
|
|
@@ -124,27 +124,54 @@ var ToolBottomBar = (props) => {
|
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
126
|
const handleApply = (settings, isUpdate = true) => {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
127
|
+
if (!settings) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
setFormatSetting(settings);
|
|
131
|
+
if (isUpdate) {
|
|
132
|
+
if (ueditorInst.body) {
|
|
133
|
+
(0, import_generateStylesFromSettings.generateStylesFromSettings)(settings, ueditorInst.body);
|
|
134
|
+
}
|
|
135
|
+
onSettingChange == null ? void 0 : onSettingChange({
|
|
136
|
+
formatSetting: settings,
|
|
137
|
+
pageWidth
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
(0, import_react.useEffect)(() => {
|
|
142
|
+
handleApply(defaultSetting == null ? void 0 : defaultSetting.formatSetting, false);
|
|
143
|
+
}, [defaultSetting == null ? void 0 : defaultSetting.formatSetting]);
|
|
144
|
+
const handlePageWidthChange = (key, isUpdate = true) => {
|
|
145
|
+
const newClass = `ueditor-rich-status-content-${key}`;
|
|
146
|
+
const oldClass = `ueditor-rich-status-content-${pageWidth}`;
|
|
147
|
+
if (containerRef == null ? void 0 : containerRef.current) {
|
|
148
|
+
const frame = containerRef.current.querySelector(`#${uiId}_iframeholder`);
|
|
149
|
+
const frameContainer = ueditorInst.container || containerRef.current.querySelector(`#${uiId}`);
|
|
150
|
+
if (frame) {
|
|
151
|
+
frame.classList.remove(oldClass);
|
|
152
|
+
frame.classList.add(newClass);
|
|
153
|
+
}
|
|
154
|
+
if (frameContainer) {
|
|
155
|
+
if (key === "a0") {
|
|
156
|
+
frameContainer.classList.remove("ueditor-rich-status-not-full");
|
|
157
|
+
} else {
|
|
158
|
+
frameContainer.classList.add("ueditor-rich-status-not-full");
|
|
159
|
+
}
|
|
136
160
|
}
|
|
137
|
-
styleEl.textContent = cssStyles;
|
|
138
161
|
}
|
|
162
|
+
setPageWidth(key);
|
|
139
163
|
if (isUpdate) {
|
|
140
|
-
|
|
164
|
+
onSettingChange == null ? void 0 : onSettingChange({
|
|
165
|
+
pageWidth: key,
|
|
166
|
+
formatSetting
|
|
167
|
+
});
|
|
141
168
|
}
|
|
142
169
|
};
|
|
143
170
|
(0, import_react.useEffect)(() => {
|
|
144
|
-
if (
|
|
145
|
-
|
|
171
|
+
if (defaultSetting == null ? void 0 : defaultSetting.pageWidth) {
|
|
172
|
+
handlePageWidthChange(defaultSetting.pageWidth, false);
|
|
146
173
|
}
|
|
147
|
-
}, [
|
|
174
|
+
}, [defaultSetting == null ? void 0 : defaultSetting.pageWidth]);
|
|
148
175
|
const onProgress = (progress, title) => {
|
|
149
176
|
var _a;
|
|
150
177
|
(_a = progressModalRef.current) == null ? void 0 : _a.updateProgress(progress, title);
|
|
@@ -165,24 +192,7 @@ var ToolBottomBar = (props) => {
|
|
|
165
192
|
import_antd.Menu,
|
|
166
193
|
{
|
|
167
194
|
onClick: ({ key }) => {
|
|
168
|
-
|
|
169
|
-
const oldClass = `ueditor-rich-status-content-${pageWidth}`;
|
|
170
|
-
if (containerRef == null ? void 0 : containerRef.current) {
|
|
171
|
-
const frame = containerRef.current.querySelector(`#${uiId}_iframeholder`);
|
|
172
|
-
const frameContainer = ueditorInst.container || containerRef.current.querySelector(`#${uiId}`);
|
|
173
|
-
if (frame) {
|
|
174
|
-
frame.classList.remove(oldClass);
|
|
175
|
-
frame.classList.add(newClass);
|
|
176
|
-
}
|
|
177
|
-
if (frameContainer) {
|
|
178
|
-
if (key === "a0") {
|
|
179
|
-
frameContainer.classList.remove("ueditor-rich-status-not-full");
|
|
180
|
-
} else {
|
|
181
|
-
frameContainer.classList.add("ueditor-rich-status-not-full");
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
setPageWidth(key);
|
|
195
|
+
handlePageWidthChange(key);
|
|
186
196
|
}
|
|
187
197
|
},
|
|
188
198
|
Object.keys(MENU_OPTIONS).map((k) => /* @__PURE__ */ import_react.default.createElement(import_antd.Menu.Item, { key: k }, /* @__PURE__ */ import_react.default.createElement("span", null, "页面宽度 ", MENU_OPTIONS[k])))
|
|
@@ -196,7 +206,7 @@ var ToolBottomBar = (props) => {
|
|
|
196
206
|
import_FormatModal.default,
|
|
197
207
|
{
|
|
198
208
|
onApply: handleApply,
|
|
199
|
-
initialSettings:
|
|
209
|
+
initialSettings: defaultSetting == null ? void 0 : defaultSetting.formatSetting
|
|
200
210
|
},
|
|
201
211
|
getStatusBarItem({
|
|
202
212
|
icon: /* @__PURE__ */ import_react.default.createElement(import_icons.SettingOutlined, null),
|
|
@@ -29,10 +29,24 @@ export interface FormatSettings {
|
|
|
29
29
|
ol: ListStyle;
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
export declare const STYLE_ID = "ueditor-custom-styles";
|
|
33
|
+
export declare const FORMAT_STYLE_TAG = "format-style";
|
|
32
34
|
/**
|
|
33
35
|
* 生成CSS样式内容
|
|
36
|
+
* 将css设置到元素上
|
|
34
37
|
* @param settings 格式设置
|
|
35
|
-
* @returns CSS样式字符串
|
|
36
38
|
*/
|
|
37
|
-
export declare const generateStylesFromSettings: (settings: FormatSettings) => string;
|
|
39
|
+
export declare const generateStylesFromSettings: (settings: FormatSettings, body: HTMLElement) => string;
|
|
40
|
+
/**
|
|
41
|
+
* 从现有样式标签中提取格式设置
|
|
42
|
+
* @param body HTML body元素
|
|
43
|
+
* @returns 格式设置对象,如果未找到样式标签则返回undefined
|
|
44
|
+
*/
|
|
45
|
+
export declare const extractSettingsFromStyles: (body: HTMLElement) => FormatSettings | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* 设置格式设置
|
|
48
|
+
* @param body
|
|
49
|
+
* @param settings
|
|
50
|
+
*/
|
|
51
|
+
export declare const setFormatSettings: (body: HTMLElement, cssStyles: string) => void;
|
|
38
52
|
export {};
|