@lingxiteam/lcdp-ueditor-react 1.0.3-alpha.9 → 1.0.4-alpha.1

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 (67) hide show
  1. package/es/LcdpUeditor.d.ts +10 -4
  2. package/es/LcdpUeditor.d.ts.map +1 -0
  3. package/es/LcdpUeditor.js +77 -11
  4. package/es/ToolBottomBar/FormatModal/index.d.ts +9 -0
  5. package/es/ToolBottomBar/FormatModal/index.d.ts.map +1 -0
  6. package/es/ToolBottomBar/FormatModal/index.js +543 -0
  7. package/es/ToolBottomBar/FormatModal/index.less +276 -0
  8. package/es/ToolBottomBar/ProgressModal/index.d.ts +10 -0
  9. package/es/ToolBottomBar/ProgressModal/index.d.ts.map +1 -0
  10. package/es/ToolBottomBar/ProgressModal/index.js +53 -0
  11. package/es/ToolBottomBar/ProgressModal/index.less +16 -0
  12. package/es/ToolBottomBar/index.d.ts +33 -0
  13. package/es/ToolBottomBar/index.d.ts.map +1 -0
  14. package/es/ToolBottomBar/index.js +296 -0
  15. package/es/ToolBottomBar/index.less +75 -0
  16. package/es/const.d.ts.map +1 -0
  17. package/es/icon/ExportPDF.d.ts +3 -0
  18. package/es/icon/ExportPDF.d.ts.map +1 -0
  19. package/es/icon/ExportPDF.js +24 -0
  20. package/es/icon/TextCopy.d.ts +3 -0
  21. package/es/icon/TextCopy.d.ts.map +1 -0
  22. package/es/icon/TextCopy.js +25 -0
  23. package/es/icon/TextFileIcon.d.ts +3 -0
  24. package/es/icon/TextFileIcon.d.ts.map +1 -0
  25. package/es/icon/TextFileIcon.js +26 -0
  26. package/es/icon/TextIcon.d.ts +3 -0
  27. package/es/icon/TextIcon.d.ts.map +1 -0
  28. package/es/icon/TextIcon.js +28 -0
  29. package/es/index.d.ts.map +1 -0
  30. package/es/tools/UeditorResourceLoader.d.ts.map +1 -0
  31. package/es/tools/exportPDF.d.ts +27 -0
  32. package/es/tools/exportPDF.d.ts.map +1 -0
  33. package/es/tools/exportPDF.js +146 -0
  34. package/es/tools/filterHtmlNode.d.ts.map +1 -0
  35. package/es/tools/generateStylesFromSettings.d.ts +38 -0
  36. package/es/tools/generateStylesFromSettings.d.ts.map +1 -0
  37. package/es/tools/generateStylesFromSettings.js +24 -0
  38. package/es/tools/loadScript.d.ts.map +1 -0
  39. package/es/type.d.ts +21 -0
  40. package/es/type.d.ts.map +1 -0
  41. package/lib/LcdpUeditor.d.ts +10 -4
  42. package/lib/LcdpUeditor.js +62 -8
  43. package/lib/ToolBottomBar/FormatModal/index.d.ts +9 -0
  44. package/lib/ToolBottomBar/FormatModal/index.js +261 -0
  45. package/lib/ToolBottomBar/FormatModal/index.less +276 -0
  46. package/lib/ToolBottomBar/ProgressModal/index.d.ts +10 -0
  47. package/lib/ToolBottomBar/ProgressModal/index.js +73 -0
  48. package/lib/ToolBottomBar/ProgressModal/index.less +16 -0
  49. package/lib/ToolBottomBar/index.d.ts +33 -0
  50. package/lib/ToolBottomBar/index.js +235 -0
  51. package/lib/ToolBottomBar/index.less +75 -0
  52. package/lib/icon/ExportPDF.d.ts +3 -0
  53. package/lib/icon/ExportPDF.js +57 -0
  54. package/lib/icon/TextCopy.d.ts +3 -0
  55. package/lib/icon/TextCopy.js +39 -0
  56. package/lib/icon/TextFileIcon.d.ts +3 -0
  57. package/lib/icon/TextFileIcon.js +39 -0
  58. package/lib/icon/TextIcon.d.ts +3 -0
  59. package/lib/icon/TextIcon.js +39 -0
  60. package/lib/tools/exportPDF.d.ts +27 -0
  61. package/lib/tools/exportPDF.js +95 -0
  62. package/lib/tools/generateStylesFromSettings.d.ts +38 -0
  63. package/lib/tools/generateStylesFromSettings.js +77 -0
  64. package/lib/type.d.ts +21 -0
  65. package/package.json +8 -3
  66. package/ueditor-resource/themes/default/css/ueditor.css +1 -1
  67. package/ueditor-resource/ueditor.all.js +1 -1
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 将HTML内容转换为PDF文档流
3
+ * @param htmlElement HTML元素
4
+ * @param options 配置选项
5
+ * @returns PDF文档的Blob对象
6
+ */
7
+ export declare const html2pdf: (htmlElement: HTMLElement, options?: {
8
+ filename?: string;
9
+ margin?: number;
10
+ image?: {
11
+ type?: 'jpeg' | 'png';
12
+ quality?: number;
13
+ };
14
+ jsPDF?: {
15
+ orientation?: 'portrait' | 'landscape';
16
+ unit?: 'pt' | 'mm' | 'cm' | 'in';
17
+ format?: 'a4' | 'a3' | 'a5' | 'a0';
18
+ };
19
+ }, onProgress?: ((progress: number, title: string) => void) | undefined) => Promise<Blob>;
20
+ /**
21
+ * 将HTML元素转换为PDF文档流并下载
22
+ * @param dom HTML元素
23
+ * @param pageWidth 页面宽度
24
+ * @param fileName 文件名
25
+ * @returns 下载的PDF文件
26
+ */
27
+ export declare const domloadPdf: (dom: HTMLElement, pageWidth: 'a4' | 'a3' | 'a5' | 'a0', fileName?: string, onProgress?: ((progress: number, title: string) => void) | undefined) => Promise<void>;
@@ -0,0 +1,95 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/tools/exportPDF.ts
30
+ var exportPDF_exports = {};
31
+ __export(exportPDF_exports, {
32
+ domloadPdf: () => domloadPdf,
33
+ html2pdf: () => html2pdf
34
+ });
35
+ module.exports = __toCommonJS(exportPDF_exports);
36
+ var html2pdf = async (htmlElement, options = {}, onProgress) => {
37
+ var _a, _b, _c, _d, _e;
38
+ const { jsPDF: JS_PDF } = await import(
39
+ /* webpackChunkName: "jspdf" */
40
+ "jspdf"
41
+ );
42
+ const pdf = new JS_PDF({
43
+ orientation: ((_a = options.jsPDF) == null ? void 0 : _a.orientation) || "portrait",
44
+ unit: ((_b = options.jsPDF) == null ? void 0 : _b.unit) || "pt",
45
+ format: ((_c = options.jsPDF) == null ? void 0 : _c.format) || "a4"
46
+ });
47
+ const { default: html2canvas } = await import("html2canvas");
48
+ onProgress == null ? void 0 : onProgress(20, "渲染页面内容...");
49
+ const canvas = await html2canvas(htmlElement, {
50
+ scale: 2,
51
+ // 提高清晰度
52
+ useCORS: true,
53
+ // 允许跨域图片
54
+ logging: false
55
+ });
56
+ const imageType = ((_d = options.image) == null ? void 0 : _d.type) || "jpeg";
57
+ const imageQuality = ((_e = options.image) == null ? void 0 : _e.quality) || 1;
58
+ const imgData = canvas.toDataURL(`image/${imageType}`, imageQuality);
59
+ const margin = options.margin || 20;
60
+ const pdfWidth = pdf.internal.pageSize.getWidth();
61
+ const pdfHeight = pdf.internal.pageSize.getHeight();
62
+ const imgWidth = pdfWidth - margin * 2;
63
+ const imgHeight = canvas.height * imgWidth / canvas.width;
64
+ let heightLeft = imgHeight;
65
+ let position = margin;
66
+ const pageHeight = pdfHeight - margin * 2;
67
+ pdf.addImage(imgData, imageType.toUpperCase(), margin, position, imgWidth, imgHeight);
68
+ heightLeft -= pageHeight;
69
+ while (heightLeft >= 0) {
70
+ position = heightLeft - imgHeight;
71
+ pdf.addPage();
72
+ pdf.addImage(imgData, imageType.toUpperCase(), margin, position, imgWidth, imgHeight);
73
+ heightLeft -= pageHeight;
74
+ }
75
+ onProgress == null ? void 0 : onProgress(50, "转换HTML内容...");
76
+ return pdf.output("blob");
77
+ };
78
+ var domloadPdf = async (dom, pageWidth, fileName = "未命名", onProgress) => {
79
+ const { saveAs } = await import("file-saver");
80
+ onProgress == null ? void 0 : onProgress(5, "初始化...");
81
+ const blob = await html2pdf(dom, {
82
+ jsPDF: {
83
+ orientation: "portrait",
84
+ unit: "pt",
85
+ format: pageWidth
86
+ }
87
+ }, onProgress);
88
+ onProgress == null ? void 0 : onProgress(80, "生成PDF...");
89
+ return saveAs(blob, `${fileName}.pdf`);
90
+ };
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ domloadPdf,
94
+ html2pdf
95
+ });
@@ -0,0 +1,38 @@
1
+ interface HeadingStyle extends TextStyle {
2
+ marginTop: string;
3
+ marginBottom: string;
4
+ }
5
+ export interface TextStyle {
6
+ fontSize: string;
7
+ fontFamily: string;
8
+ fontWeight: string;
9
+ lineHeight: string;
10
+ color: string;
11
+ }
12
+ interface ListStyle extends TextStyle {
13
+ paddingLeft: string;
14
+ marginTop: string;
15
+ marginBottom: string;
16
+ }
17
+ export interface FormatSettings {
18
+ headings: {
19
+ h1: HeadingStyle;
20
+ h2: HeadingStyle;
21
+ h3: HeadingStyle;
22
+ h4: HeadingStyle;
23
+ h5: HeadingStyle;
24
+ h6: HeadingStyle;
25
+ };
26
+ paragraph: TextStyle;
27
+ lists: {
28
+ ul: ListStyle;
29
+ ol: ListStyle;
30
+ };
31
+ }
32
+ /**
33
+ * 生成CSS样式内容
34
+ * @param settings 格式设置
35
+ * @returns CSS样式字符串
36
+ */
37
+ export declare const generateStylesFromSettings: (settings: FormatSettings) => string;
38
+ export {};
@@ -0,0 +1,77 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/tools/generateStylesFromSettings.ts
20
+ var generateStylesFromSettings_exports = {};
21
+ __export(generateStylesFromSettings_exports, {
22
+ generateStylesFromSettings: () => generateStylesFromSettings
23
+ });
24
+ module.exports = __toCommonJS(generateStylesFromSettings_exports);
25
+ var generateStylesFromSettings = (settings) => {
26
+ let css = "";
27
+ Object.entries(settings.headings).forEach(([heading, style]) => {
28
+ css += `
29
+ ${heading} {
30
+ font-family: ${style.fontFamily};
31
+ font-size: ${style.fontSize};
32
+ font-weight: ${style.fontWeight};
33
+ line-height: ${style.lineHeight};
34
+ color: ${style.color};
35
+ margin-top: ${style.marginTop};
36
+ margin-bottom: ${style.marginBottom};
37
+ }
38
+ `;
39
+ });
40
+ css += `
41
+ p {
42
+ font-family: ${settings.paragraph.fontFamily};
43
+ font-size: ${settings.paragraph.fontSize};
44
+ font-weight: ${settings.paragraph.fontWeight};
45
+ line-height: ${settings.paragraph.lineHeight};
46
+ color: ${settings.paragraph.color};
47
+ }
48
+ `;
49
+ css += `
50
+ ul {
51
+ font-family: ${settings.lists.ul.fontFamily};
52
+ font-size: ${settings.lists.ul.fontSize};
53
+ font-weight: ${settings.lists.ul.fontWeight};
54
+ line-height: ${settings.lists.ul.lineHeight};
55
+ color: ${settings.lists.ul.color};
56
+ padding-left: ${settings.lists.ul.paddingLeft};
57
+ margin-top: ${settings.lists.ul.marginTop};
58
+ margin-bottom: ${settings.lists.ul.marginBottom};
59
+ }
60
+
61
+ ol {
62
+ font-family: ${settings.lists.ol.fontFamily};
63
+ font-size: ${settings.lists.ol.fontSize};
64
+ font-weight: ${settings.lists.ol.fontWeight};
65
+ line-height: ${settings.lists.ol.lineHeight};
66
+ color: ${settings.lists.ol.color};
67
+ padding-left: ${settings.lists.ol.paddingLeft};
68
+ margin-top: ${settings.lists.ol.marginTop};
69
+ margin-bottom: ${settings.lists.ol.marginBottom};
70
+ }
71
+ `;
72
+ return css;
73
+ };
74
+ // Annotate the CommonJS export names for ESM import in node:
75
+ 0 && (module.exports = {
76
+ generateStylesFromSettings
77
+ });
package/lib/type.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { FormatSettings } from './tools/generateStylesFromSettings';
2
3
  interface IUeditorStype extends React.CSSProperties {
3
4
  toolbarColor?: string;
4
5
  }
@@ -68,6 +69,10 @@ export interface ILcdpUeditorProps {
68
69
  */
69
70
  videoAllowFiles?: string[];
70
71
  maximumWords?: number;
72
+ /**
73
+ * 导出文件名
74
+ */
75
+ exportFileName?: string;
71
76
  };
72
77
  toolbars?: string[][];
73
78
  /**
@@ -100,6 +105,22 @@ export interface ILcdpUeditorProps {
100
105
  * @param val 编辑器内容
101
106
  */
102
107
  onChange?(val: string): void;
108
+ /**
109
+ * 样式前缀
110
+ */
111
+ prefixCls?: string;
112
+ /**
113
+ * 格式设置变化
114
+ */
115
+ onFormatChange?(val: FormatSettings): void;
116
+ /**
117
+ * 默认格式设置
118
+ */
119
+ defaultFormatSetting?: FormatSettings;
120
+ /**
121
+ * 底部功能类型
122
+ */
123
+ bottomTypes?: Array<'chineseCount' | 'charCount' | 'pageWidth' | 'formatSetting' | 'exportPdf' | 'fullScreen' | 'copy'>;
103
124
  }
104
125
  export interface ILcdpUeditorInst {
105
126
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingxiteam/lcdp-ueditor-react",
3
- "version": "1.0.3-alpha.9",
3
+ "version": "1.0.4-alpha.1",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -18,14 +18,19 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/lodash": "^4.14.180",
21
- "father": "^4.1.9"
21
+ "father": "^4.1.9",
22
+ "@types/file-saver": "^2.0.5"
22
23
  },
23
24
  "peerDependencies": {
24
25
  "react": "^16.12.0 || ^17.0.0",
25
26
  "lodash": "^4.0.0"
26
27
  },
27
28
  "dependencies": {
28
- "@babel/runtime": "7.23.2"
29
+ "@babel/runtime": "7.23.2",
30
+ "jspdf": "^2.5.1",
31
+ "file-saver": "^2.0.5",
32
+ "antd": "4.24.13",
33
+ "html2canvas": "^1.4.1"
29
34
  },
30
35
  "publishConfig": {
31
36
  "access": "public",