@lingxiteam/lcdp-ueditor-react 1.0.4-alpha.2 → 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.
Files changed (33) hide show
  1. package/es/LcdpUeditor.d.ts +1 -0
  2. package/es/LcdpUeditor.js +10 -6
  3. package/es/ToolBottomBar/FormatModal/index.js +79 -75
  4. package/es/ToolBottomBar/index.js +10 -24
  5. package/es/tools/generateStylesFromSettings.d.ts +16 -2
  6. package/es/tools/generateStylesFromSettings.js +187 -7
  7. package/lib/LcdpUeditor.d.ts +1 -0
  8. package/lib/LcdpUeditor.js +5 -1
  9. package/lib/ToolBottomBar/FormatModal/index.js +49 -38
  10. package/lib/ToolBottomBar/index.js +6 -15
  11. package/lib/tools/generateStylesFromSettings.d.ts +16 -2
  12. package/lib/tools/generateStylesFromSettings.js +167 -48
  13. package/package.json +1 -1
  14. package/ueditor-resource/lang/en/en.js +1 -1
  15. package/ueditor-resource/lang/zh-cn/zh-cn.js +1 -1
  16. package/ueditor-resource/lang/zh-tw/zh-tw.js +1 -1
  17. package/ueditor-resource/ueditor.all.js +21 -20
  18. package/es/LcdpUeditor.d.ts.map +0 -1
  19. package/es/ToolBottomBar/FormatModal/index.d.ts.map +0 -1
  20. package/es/ToolBottomBar/ProgressModal/index.d.ts.map +0 -1
  21. package/es/ToolBottomBar/index.d.ts.map +0 -1
  22. package/es/const.d.ts.map +0 -1
  23. package/es/icon/ExportPDF.d.ts.map +0 -1
  24. package/es/icon/TextCopy.d.ts.map +0 -1
  25. package/es/icon/TextFileIcon.d.ts.map +0 -1
  26. package/es/icon/TextIcon.d.ts.map +0 -1
  27. package/es/index.d.ts.map +0 -1
  28. package/es/tools/UeditorResourceLoader.d.ts.map +0 -1
  29. package/es/tools/exportPDF.d.ts.map +0 -1
  30. package/es/tools/filterHtmlNode.d.ts.map +0 -1
  31. package/es/tools/generateStylesFromSettings.d.ts.map +0 -1
  32. package/es/tools/loadScript.d.ts.map +0 -1
  33. package/es/type.d.ts.map +0 -1
@@ -82,6 +82,7 @@ declare class LcdpUeditor extends React.Component<ILcdpUeditorProps, {}> {
82
82
  * 初始化编辑器实例
83
83
  */
84
84
  initUeditor(): Promise<void>;
85
+ onSettingChange: (setting: any) => void;
85
86
  /**
86
87
  * 渲染状态栏
87
88
  */
package/es/LcdpUeditor.js CHANGED
@@ -81,6 +81,10 @@ var LcdpUeditor = /*#__PURE__*/function (_React$Component) {
81
81
  * 编辑器配置项
82
82
  */
83
83
  _defineProperty(_assertThisInitialized(_this), "editorConfig", {});
84
+ _defineProperty(_assertThisInitialized(_this), "onSettingChange", function (setting) {
85
+ _this.editorConfig.onSettingChange(setting);
86
+ _this.onContentChange();
87
+ });
84
88
  var config = props.config,
85
89
  prefixCls = props.prefixCls,
86
90
  onSettingChange = props.onSettingChange;
@@ -401,14 +405,14 @@ var LcdpUeditor = /*#__PURE__*/function (_React$Component) {
401
405
  return _initUeditor.apply(this, arguments);
402
406
  }
403
407
  return initUeditor;
404
- }()
408
+ }())
409
+ }, {
410
+ key: "renderStatusBar",
411
+ value:
405
412
  /**
406
413
  * 渲染状态栏
407
414
  */
408
- )
409
- }, {
410
- key: "renderStatusBar",
411
- value: function renderStatusBar() {
415
+ function renderStatusBar() {
412
416
  var _this$containerRef$cu, _this$props2;
413
417
  var _ref4 = this.ueditorInst.ui || {},
414
418
  id = _ref4.id;
@@ -418,7 +422,7 @@ var LcdpUeditor = /*#__PURE__*/function (_React$Component) {
418
422
  prefixCls: this.prefixCls,
419
423
  containerRef: this.containerRef,
420
424
  defaultSetting: this.props.defaultSetting,
421
- onSettingChange: this.editorConfig.onSettingChange,
425
+ onSettingChange: this.onSettingChange,
422
426
  isReady: this.state.isReady,
423
427
  bottomTypes: this.props.bottomTypes,
424
428
  exportFileName: (_this$props2 = this.props) === null || _this$props2 === void 0 || (_this$props2 = _this$props2.config) === null || _this$props2 === void 0 ? void 0 : _this$props2.exportFileName
@@ -99,6 +99,33 @@ var defaultSettings = {
99
99
  }
100
100
  };
101
101
 
102
+ // 字体翻译映射 - 从简体中文国际化文件获取
103
+ var fontFamilyTranslations = {
104
+ default: '默认',
105
+ songti: '宋体',
106
+ kaiti: '楷体',
107
+ heiti: '黑体',
108
+ lishu: '隶书',
109
+ yahei: '微软雅黑',
110
+ fangsong: '仿宋',
111
+ dengxian: '等线',
112
+ segoeUI: 'Segoe UI',
113
+ calibri: 'Calibri',
114
+ arial: 'arial',
115
+ timesNewRoman: 'times new roman',
116
+ pingfangSC: '苹方(简)',
117
+ pingfangTC: '苹方(繁)',
118
+ hiraginoSansGB: '冬青黑体',
119
+ stFangsong: '华文仿宋',
120
+ sanFrancisco: '旧金山字体',
121
+ helveticaNeue: 'Helvetica Neue',
122
+ sourceHanSans: 'Source Han Sans',
123
+ wenQuanYiMicroHei: '文泉驿微米黑',
124
+ wenQuanYiZenHei: '文泉驿正黑',
125
+ dejaVuSans: 'DejaVu Sans',
126
+ liberationSans: 'Liberation Sans'
127
+ };
128
+
102
129
  // 检测操作系统类型
103
130
  var getOSType = function getOSType() {
104
131
  var userAgent = navigator.userAgent.toLowerCase();
@@ -159,121 +186,98 @@ var generateFontOptions = function generateFontOptions() {
159
186
  value: '系统字体',
160
187
  label: '系统字体(推荐)'
161
188
  }, {
162
- value: "-apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Helvetica, Arial, sans-serif",
163
- label: '完整系统字体栈'
164
- }];
189
+ value: 'STHeiti, 黑体, SimHei, "Noto Sans CJK SC"',
190
+ label: fontFamilyTranslations.heiti
191
+ }, {
192
+ value: 'STSong, 宋体, SimSun, "Noto Serif CJK SC"',
193
+ label: fontFamilyTranslations.songti
194
+ }
195
+ // { value: "-apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Helvetica, Arial, sans-serif", label: '完整系统字体栈' },
196
+ ];
165
197
 
166
- // 各平台特定字体
198
+ // 各平台特定字体 - 参考font.js中的getFontList定义,相同label的字体value已合并
167
199
  var platformFonts = {
168
200
  windows: [{
169
- value: '微软雅黑',
170
- label: '微软雅黑'
201
+ value: '微软雅黑,Microsoft YaHei',
202
+ label: fontFamilyTranslations.yahei
171
203
  }, {
172
204
  value: '仿宋',
173
- label: '仿宋'
174
- }, {
175
- value: '黑体',
176
- label: '黑体'
205
+ label: fontFamilyTranslations.fangsong
177
206
  }, {
178
- value: '楷体',
179
- label: '楷体'
207
+ value: 'STKaiti, 楷体, 楷体_GB2312, SimKai',
208
+ label: fontFamilyTranslations.kaiti
180
209
  }, {
181
- value: '宋体',
182
- label: '宋体'
210
+ value: '隶书,SimLi',
211
+ label: fontFamilyTranslations.lishu
183
212
  }, {
184
213
  value: '等线',
185
- label: '等线'
214
+ label: fontFamilyTranslations.dengxian
186
215
  }, {
187
216
  value: 'Segoe UI',
188
- label: 'Segoe UI'
217
+ label: fontFamilyTranslations.segoeUI
189
218
  }, {
190
219
  value: 'Calibri',
191
- label: 'Calibri'
220
+ label: fontFamilyTranslations.calibri
221
+ }, {
222
+ value: 'arial,helvetica,sans-serif',
223
+ label: fontFamilyTranslations.arial
224
+ }, {
225
+ value: 'times new roman',
226
+ label: fontFamilyTranslations.timesNewRoman
192
227
  }],
193
228
  mac: [{
229
+ value: 'STKaiti, 楷体, 楷体_GB2312, SimKai',
230
+ label: fontFamilyTranslations.kaiti
231
+ }, {
194
232
  value: 'PingFang SC',
195
- label: '苹方(简)'
233
+ label: fontFamilyTranslations.pingfangSC
196
234
  }, {
197
235
  value: 'PingFang TC',
198
- label: '苹方(繁)'
236
+ label: fontFamilyTranslations.pingfangTC
199
237
  }, {
200
238
  value: 'Hiragino Sans GB',
201
- label: '冬青黑体'
202
- }, {
203
- value: 'STHeiti',
204
- label: '华文黑体'
205
- }, {
206
- value: 'STKaiti',
207
- label: '华文楷体'
208
- }, {
209
- value: 'STSong',
210
- label: '华文宋体'
239
+ label: fontFamilyTranslations.hiraginoSansGB
211
240
  }, {
212
241
  value: 'STFangsong',
213
- label: '华文仿宋'
242
+ label: fontFamilyTranslations.stFangsong
214
243
  }, {
215
244
  value: 'San Francisco',
216
- label: '旧金山字体'
245
+ label: fontFamilyTranslations.sanFrancisco
217
246
  }, {
218
247
  value: 'Helvetica Neue',
219
- label: 'Helvetica Neue'
248
+ label: fontFamilyTranslations.helveticaNeue
220
249
  }],
221
250
  linux: [{
222
- value: 'Noto Sans CJK SC',
223
- label: '思源黑体'
224
- }, {
225
- value: 'Noto Serif CJK SC',
226
- label: '思源宋体'
227
- }, {
228
251
  value: 'Source Han Sans',
229
- label: 'Source Han Sans'
252
+ label: fontFamilyTranslations.sourceHanSans
230
253
  }, {
231
254
  value: 'WenQuanYi Micro Hei',
232
- label: '文泉驿微米黑'
255
+ label: fontFamilyTranslations.wenQuanYiMicroHei
233
256
  }, {
234
257
  value: 'WenQuanYi Zen Hei',
235
- label: '文泉驿正黑'
258
+ label: fontFamilyTranslations.wenQuanYiZenHei
236
259
  }, {
237
260
  value: 'DejaVu Sans',
238
- label: 'DejaVu Sans'
261
+ label: fontFamilyTranslations.dejaVuSans
239
262
  }, {
240
263
  value: 'Liberation Sans',
241
- label: 'Liberation Sans'
264
+ label: fontFamilyTranslations.liberationSans
242
265
  }]
243
266
  };
244
267
 
245
268
  // 通用Web安全字体
246
- var webSafeFonts = [{
247
- value: 'Arial',
248
- label: 'Arial'
249
- }, {
250
- value: 'Helvetica',
251
- label: 'Helvetica'
252
- }, {
253
- value: 'Times New Roman',
254
- label: 'Times New Roman'
255
- }, {
256
- value: 'Times',
257
- label: 'Times'
258
- }, {
259
- value: 'Courier New',
260
- label: 'Courier New'
261
- }, {
262
- value: 'Georgia',
263
- label: 'Georgia'
264
- }, {
265
- value: 'Verdana',
266
- label: 'Verdana'
267
- }, {
268
- value: 'sans-serif',
269
- label: '系统无衬线字体'
270
- }, {
271
- value: 'serif',
272
- label: '系统衬线字体'
273
- }, {
274
- value: 'monospace',
275
- label: '系统等宽字体'
276
- }];
269
+ // const webSafeFonts = [
270
+ // { value: 'Arial', label: 'Arial' },
271
+ // { value: 'Helvetica', label: 'Helvetica' },
272
+ // { value: 'Times New Roman', label: 'Times New Roman' },
273
+ // { value: 'Times', label: 'Times' },
274
+ // { value: 'Courier New', label: 'Courier New' },
275
+ // { value: 'Georgia', label: 'Georgia' },
276
+ // { value: 'Verdana', label: 'Verdana' },
277
+ // { value: 'sans-serif', label: '系统无衬线字体' },
278
+ // { value: 'serif', label: '系统衬线字体' },
279
+ // { value: 'monospace', label: '系统等宽字体' },
280
+ // ];
277
281
 
278
282
  // 合并字体列表
279
283
  var allFonts = [].concat(baseFonts);
@@ -284,7 +288,7 @@ var generateFontOptions = function generateFontOptions() {
284
288
  }
285
289
 
286
290
  // 添加Web安全字体
287
- allFonts.push.apply(allFonts, webSafeFonts);
291
+ // allFonts.push(...webSafeFonts);
288
292
 
289
293
  // 启用字体检测,但不阻塞界面
290
294
  var availableFonts = allFonts.map(function (font) {
@@ -20,7 +20,6 @@ var MENU_OPTIONS = {
20
20
  a5: 'A5',
21
21
  a0: '铺满'
22
22
  };
23
- var STYLE_ID = 'ueditor-custom-styles';
24
23
  var ToolBottomBar = function ToolBottomBar(props) {
25
24
  var ueditorInst = props.ueditorInst,
26
25
  prefixCls = props.prefixCls,
@@ -145,27 +144,16 @@ var ToolBottomBar = function ToolBottomBar(props) {
145
144
  * @param settings 格式设置
146
145
  */
147
146
  var handleApply = function handleApply(settings) {
148
- var _containerRef$current, _contentDocument;
149
147
  var isUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
150
- // 生成样式
151
- var cssStyles = generateStylesFromSettings(settings);
152
-
153
- // 触发编辑器视图更新
154
- var frame = ueditorInst.frame || (containerRef === null || containerRef === void 0 || (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.querySelector("#".concat(uiId, "_iframeholder > iframe")));
155
- if (frame !== null && frame !== void 0 && (_contentDocument = frame.contentDocument) !== null && _contentDocument !== void 0 && _contentDocument.documentElement) {
156
- var _contentDocument2;
157
- // 查找或创建样式元素
158
- var styleEl = frame === null || frame === void 0 || (_contentDocument2 = frame.contentDocument) === null || _contentDocument2 === void 0 ? void 0 : _contentDocument2.getElementById(STYLE_ID);
159
- if (!styleEl) {
160
- styleEl = document.createElement('style');
161
- styleEl.id = STYLE_ID;
162
- frame.contentDocument.head.appendChild(styleEl);
163
- }
164
- // 设置样式内容
165
- styleEl.textContent = cssStyles;
148
+ if (!settings) {
149
+ return;
166
150
  }
167
151
  setFormatSetting(settings);
168
152
  if (isUpdate) {
153
+ // 生成样式
154
+ if (ueditorInst.body) {
155
+ generateStylesFromSettings(settings, ueditorInst.body);
156
+ }
169
157
  onSettingChange === null || onSettingChange === void 0 || onSettingChange({
170
158
  formatSetting: settings,
171
159
  pageWidth: pageWidth
@@ -173,9 +161,7 @@ var ToolBottomBar = function ToolBottomBar(props) {
173
161
  }
174
162
  };
175
163
  useEffect(function () {
176
- if (defaultSetting !== null && defaultSetting !== void 0 && defaultSetting.formatSetting) {
177
- handleApply(defaultSetting.formatSetting, false);
178
- }
164
+ handleApply(defaultSetting === null || defaultSetting === void 0 ? void 0 : defaultSetting.formatSetting, false);
179
165
  }, [defaultSetting === null || defaultSetting === void 0 ? void 0 : defaultSetting.formatSetting]);
180
166
  var handlePageWidthChange = function handlePageWidthChange(key) {
181
167
  var isUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
@@ -279,7 +265,7 @@ var ToolBottomBar = function ToolBottomBar(props) {
279
265
  content: '导出文档',
280
266
  onClick: function () {
281
267
  var _onClick = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
282
- var _contentDocument3, frame, _contentDocument4;
268
+ var _contentDocument, frame, _contentDocument2;
283
269
  return _regeneratorRuntime().wrap(function _callee$(_context) {
284
270
  while (1) switch (_context.prev = _context.next) {
285
271
  case 0:
@@ -288,12 +274,12 @@ var ToolBottomBar = function ToolBottomBar(props) {
288
274
  break;
289
275
  }
290
276
  frame = ueditorInst.frame || containerRef.current.querySelector("#".concat(uiId, "_iframeholder > iframe"));
291
- if (!(frame !== null && frame !== void 0 && (_contentDocument3 = frame.contentDocument) !== null && _contentDocument3 !== void 0 && _contentDocument3.body)) {
277
+ if (!(frame !== null && frame !== void 0 && (_contentDocument = frame.contentDocument) !== null && _contentDocument !== void 0 && _contentDocument.body)) {
292
278
  _context.next = 6;
293
279
  break;
294
280
  }
295
281
  _context.next = 5;
296
- return domloadPdf(frame === null || frame === void 0 || (_contentDocument4 = frame.contentDocument) === null || _contentDocument4 === void 0 ? void 0 : _contentDocument4.body, pageWidth || 'a0', exportFileName, onProgress);
282
+ return domloadPdf(frame === null || frame === void 0 || (_contentDocument2 = frame.contentDocument) === null || _contentDocument2 === void 0 ? void 0 : _contentDocument2.body, pageWidth || 'a0', exportFileName, onProgress);
297
283
  case 5:
298
284
  onProgress(100, '导出完成');
299
285
  case 6:
@@ -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 {};
@@ -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 css = '';
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
- css += "\n".concat(heading, " {\n font-family: ").concat(style.fontFamily, ";\n font-size: ").concat(style.fontSize, ";\n font-weight: ").concat(style.fontWeight, ";\n line-height: ").concat(style.lineHeight, ";\n color: ").concat(style.color, ";\n margin-top: ").concat(style.marginTop, ";\n margin-bottom: ").concat(style.marginBottom, ";\n}\n");
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
- css += "\np {\n font-family: ".concat(settings.paragraph.fontFamily, ";\n font-size: ").concat(settings.paragraph.fontSize, ";\n font-weight: ").concat(settings.paragraph.fontWeight, ";\n line-height: ").concat(settings.paragraph.lineHeight, ";\n color: ").concat(settings.paragraph.color, ";\n}\n");
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
- css += "\nul {\n font-family: ".concat(settings.lists.ul.fontFamily, ";\n font-size: ").concat(settings.lists.ul.fontSize, ";\n font-weight: ").concat(settings.lists.ul.fontWeight, ";\n line-height: ").concat(settings.lists.ul.lineHeight, ";\n color: ").concat(settings.lists.ul.color, ";\n padding-left: ").concat(settings.lists.ul.paddingLeft, ";\n margin-top: ").concat(settings.lists.ul.marginTop, ";\n margin-bottom: ").concat(settings.lists.ul.marginBottom, ";\n}\n\nol {\n font-family: ").concat(settings.lists.ol.fontFamily, ";\n font-size: ").concat(settings.lists.ol.fontSize, ";\n font-weight: ").concat(settings.lists.ol.fontWeight, ";\n line-height: ").concat(settings.lists.ol.lineHeight, ";\n color: ").concat(settings.lists.ol.color, ";\n padding-left: ").concat(settings.lists.ol.paddingLeft, ";\n margin-top: ").concat(settings.lists.ol.marginTop, ";\n margin-bottom: ").concat(settings.lists.ol.marginBottom, ";\n}\n");
23
- return css;
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
  };
@@ -82,6 +82,7 @@ declare class LcdpUeditor extends React.Component<ILcdpUeditorProps, {}> {
82
82
  * 初始化编辑器实例
83
83
  */
84
84
  initUeditor(): Promise<void>;
85
+ onSettingChange: (setting: any) => void;
85
86
  /**
86
87
  * 渲染状态栏
87
88
  */
@@ -86,6 +86,10 @@ var LcdpUeditor = class extends import_react.default.Component {
86
86
  * 编辑器配置项
87
87
  */
88
88
  this.editorConfig = {};
89
+ this.onSettingChange = (setting) => {
90
+ this.editorConfig.onSettingChange(setting);
91
+ this.onContentChange();
92
+ };
89
93
  const { config, prefixCls, onSettingChange } = props;
90
94
  this.containerId = `ueditor_${Date.now()}_${String(Math.random()).slice(2, 6)}`;
91
95
  if (this.props.ueditorPath) {
@@ -321,7 +325,7 @@ var LcdpUeditor = class extends import_react.default.Component {
321
325
  prefixCls: this.prefixCls,
322
326
  containerRef: this.containerRef,
323
327
  defaultSetting: this.props.defaultSetting,
324
- onSettingChange: this.editorConfig.onSettingChange,
328
+ onSettingChange: this.onSettingChange,
325
329
  isReady: this.state.isReady,
326
330
  bottomTypes: this.props.bottomTypes,
327
331
  exportFileName: (_c = (_b = this.props) == null ? void 0 : _b.config) == null ? void 0 : _c.exportFileName