operp-print-designer 1.0.8 → 1.0.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,8 @@
1
+ import React from 'react';
2
+ /** 简易条形码渲染组件(使用Canvas绘制) */
3
+ interface BarcodeProps {
4
+ value: string;
5
+ format: string;
6
+ }
7
+ declare const Barcode: React.FC<BarcodeProps>;
8
+ export default Barcode;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import 'react-grid-layout/css/styles.css';
3
+ import 'react-resizable/css/styles.css';
4
+ declare const Canvas: React.FC<{
5
+ isPreview?: boolean;
6
+ }>;
7
+ export default Canvas;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const ComponentPanel: React.FC;
3
+ export default ComponentPanel;
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ declare const DataSourcePanel: React.FC;
3
+ export default DataSourcePanel;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const HeaderFooterDialog: React.FC;
3
+ export default HeaderFooterDialog;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const LeftPanel: React.FC;
3
+ export default LeftPanel;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const PageSettings: React.FC;
3
+ export default PageSettings;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { TemplateData } from '../../types';
3
+ export interface PrintDesignerProps {
4
+ /** 是否为预览模式(只读) */
5
+ isPreview?: boolean;
6
+ /** 初始模板数据 */
7
+ initialTemplateData?: TemplateData;
8
+ /** 保存回调 */
9
+ onSave?: (templateData: TemplateData) => void;
10
+ /** 打印回调 */
11
+ onPrint?: () => void;
12
+ }
13
+ declare const PrintDesigner: React.FC<PrintDesignerProps>;
14
+ export default PrintDesigner;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const PrintPreview: React.FC;
3
+ export default PrintPreview;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const PropertyPanel: React.FC;
3
+ export default PropertyPanel;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ interface ToolbarProps {
3
+ /** 自定义保存回调 */
4
+ onCustomSave?: () => void;
5
+ /** 自定义打印回调 */
6
+ onCustomPrint?: () => void;
7
+ }
8
+ declare const Toolbar: React.FC<ToolbarProps>;
9
+ export default Toolbar;
@@ -0,0 +1,67 @@
1
+ import { PaperSizePreset } from '../types';
2
+ /** 纸张预设尺寸 - 宽高 mm (portrait) */
3
+ export declare const PAPER_SIZES: Record<Exclude<PaperSizePreset, 'custom'>, {
4
+ width: number;
5
+ height: number;
6
+ }>;
7
+ /** 默认页面设置 */
8
+ export declare const DEFAULT_PAGE_SETTINGS: {
9
+ paperSize: PaperSizePreset;
10
+ customWidth: number;
11
+ customHeight: number;
12
+ orientation: "portrait";
13
+ marginTop: number;
14
+ marginRight: number;
15
+ marginBottom: number;
16
+ marginLeft: number;
17
+ showHeader: boolean;
18
+ headerContent: string;
19
+ showFooter: boolean;
20
+ footerContent: string;
21
+ showPageNumber: boolean;
22
+ pageNumberFormat: string;
23
+ };
24
+ /** 缩放系数: 1mm 对应的像素 */
25
+ export declare const MM_TO_PX_RATIO = 3;
26
+ /** 默认网格设置 */
27
+ export declare const DEFAULT_GRID_SETTINGS: {
28
+ cellSize: number;
29
+ cols: number;
30
+ };
31
+ /** 组件类型中文名 */
32
+ export declare const COMPONENT_TYPE_LABELS: Record<string, string>;
33
+ /** 组件类型默认属性 */
34
+ export declare const COMPONENT_DEFAULTS: {
35
+ text: {
36
+ content: string;
37
+ fontSize: number;
38
+ fontWeight: "normal";
39
+ fontStyle: "normal";
40
+ textAlign: "left";
41
+ color: string;
42
+ backgroundColor: string;
43
+ };
44
+ image: {
45
+ src: string;
46
+ fit: "contain";
47
+ content: string;
48
+ };
49
+ table: {
50
+ rows: number;
51
+ cols: number;
52
+ borderWidth: number;
53
+ borderColor: string;
54
+ content: string;
55
+ };
56
+ barcode: {
57
+ value: string;
58
+ format: "CODE128";
59
+ content: string;
60
+ };
61
+ line: {
62
+ color: string;
63
+ thickness: number;
64
+ style: "solid";
65
+ content: string;
66
+ };
67
+ };
@@ -0,0 +1,7 @@
1
+ import PrintDesigner from './components/PrintDesigner';
2
+ export default PrintDesigner;
3
+ export { PrintDesigner };
4
+ export type { PrintDesignerProps } from './components/PrintDesigner';
5
+ export type { CanvasComponent, CanvasComponentType, PageSettings, GridSettings, TemplateData, DataSource, DataSourceType, TableColumnConfig, DataBinding, DataBindingConfig, } from './types';
6
+ export { getRenderValue, getObjectFromDataSource, getArrayFromDataSource, safeParseJSON, getValueByPath, } from './utils/dataHelper';
7
+ export { useDesignerStore } from './store';
@@ -0,0 +1,33 @@
1
+ import { CanvasComponent, CanvasComponentType, PageSettings, GridSettings, DataSource, TableColumnConfig } from '../types';
2
+ export interface DesignerStore {
3
+ components: CanvasComponent[];
4
+ selectedId: string | null;
5
+ pageSettings: PageSettings;
6
+ gridSettings: GridSettings;
7
+ previewVisible: boolean;
8
+ templateName: string;
9
+ headerFooterVisible: boolean;
10
+ dataSources: DataSource[];
11
+ activeDataSourceId: string | null;
12
+ addComponent: (type: CanvasComponentType, x?: number, y?: number) => void;
13
+ updateComponent: (id: string, props: Partial<CanvasComponent>) => void;
14
+ selectComponent: (id: string | null) => void;
15
+ removeComponent: (id: string) => void;
16
+ setComponents: (components: CanvasComponent[]) => void;
17
+ setPageSettings: (settings: Partial<PageSettings>) => void;
18
+ setPreviewVisible: (visible: boolean) => void;
19
+ setTemplateName: (name: string) => void;
20
+ setHeaderFooterVisible: (visible: boolean) => void;
21
+ addDataSource: (name: string, type: 'object' | 'array', data: string) => void;
22
+ updateDataSource: (id: string, updates: Partial<Omit<DataSource, 'id' | 'createdAt'>>) => void;
23
+ removeDataSource: (id: string) => void;
24
+ setActiveDataSourceId: (id: string | null) => void;
25
+ updateComponentTableColumns: (compId: string, columns: TableColumnConfig[]) => void;
26
+ /** 获取导出用的模板 JSON 字符串 */
27
+ exportJSON: () => string;
28
+ /** 从 JSON 字符串导入模板,返回 null 表示成功,返回 string 表示错误信息 */
29
+ importJSON: (jsonStr: string) => string | null;
30
+ /** 重置整个设计 */
31
+ reset: () => void;
32
+ }
33
+ export declare const useDesignerStore: import("zustand").UseBoundStore<import("zustand").StoreApi<DesignerStore>>;
@@ -0,0 +1,82 @@
1
+ export type CanvasComponentType = 'text' | 'image' | 'table' | 'barcode' | 'line';
2
+ export interface DataBinding {
3
+ /** 绑定的数据源 ID */
4
+ dataSourceId?: string;
5
+ /** 绑定的字段路径(支持点号,如 user.name) */
6
+ fieldPath?: string;
7
+ /** 原始静态值(当未绑定数据时使用) */
8
+ staticValue: string;
9
+ }
10
+ export type DataBindingConfig = DataBinding;
11
+ export interface TableColumnConfig {
12
+ /** 列标题 */
13
+ title: string;
14
+ /** 绑定的字段路径 */
15
+ fieldPath?: string;
16
+ /** 列宽(可选) */
17
+ width?: number;
18
+ /** 是否可编辑 */
19
+ editable?: boolean;
20
+ }
21
+ export interface CanvasComponent {
22
+ id: string;
23
+ type: CanvasComponentType;
24
+ /** 在 react-grid-layout 中的网格单位 */
25
+ x: number;
26
+ y: number;
27
+ w: number;
28
+ h: number;
29
+ /** 组件自定义属性 */
30
+ props: Record<string, unknown>;
31
+ /** 表格组件专用:列配置 */
32
+ tableColumns?: TableColumnConfig[];
33
+ }
34
+ export type DataSourceType = 'object' | 'array';
35
+ export interface DataSource {
36
+ id: string;
37
+ name: string;
38
+ type: DataSourceType;
39
+ /** JSON 字符串存储 */
40
+ data: string;
41
+ /** 创建时间戳 */
42
+ createdAt: number;
43
+ }
44
+ export type PaperSizePreset = 'A4' | 'A3' | 'A5' | 'Letter' | 'Legal' | 'custom';
45
+ export type Orientation = 'portrait' | 'landscape';
46
+ export interface PageSettings {
47
+ paperSize: PaperSizePreset;
48
+ /** 自定义纸张 - mm */
49
+ customWidth: number;
50
+ customHeight: number;
51
+ orientation: Orientation;
52
+ /** 页边距 - mm */
53
+ marginTop: number;
54
+ marginRight: number;
55
+ marginBottom: number;
56
+ marginLeft: number;
57
+ /** 是否显示页眉 */
58
+ showHeader: boolean;
59
+ /** 页眉内容 */
60
+ headerContent: string;
61
+ /** 是否显示页脚 */
62
+ showFooter: boolean;
63
+ /** 页脚内容 */
64
+ footerContent: string;
65
+ /** 是否显示页码 */
66
+ showPageNumber: boolean;
67
+ /** 页码格式,{page} 替换为当前页 */
68
+ pageNumberFormat: string;
69
+ }
70
+ export interface GridSettings {
71
+ /** 每格像素大小 */
72
+ cellSize: number;
73
+ /** 列数 */
74
+ cols: number;
75
+ }
76
+ export interface TemplateData {
77
+ version: string;
78
+ templateName: string;
79
+ pageSettings: PageSettings;
80
+ components: Omit<CanvasComponent, 'id'>[];
81
+ dataSources: Omit<DataSource, 'id'>[];
82
+ }
@@ -0,0 +1,26 @@
1
+ import { DataSource, TableColumnConfig, CanvasComponent } from '../types';
2
+ /**
3
+ * 安全解析 JSON 字符串
4
+ */
5
+ export declare function safeParseJSON(jsonStr: string): any;
6
+ /**
7
+ * 获取组件属性的渲染值(支持数据绑定)
8
+ */
9
+ export declare function getRenderValue(comp: CanvasComponent, propName: string, dataSources: DataSource[]): string;
10
+ /**
11
+ * 通过路径获取对象属性值
12
+ * 例如:obj = {a: {b: 123}}, path = 'a.b' -> return 123
13
+ */
14
+ export declare function getValueByPath(obj: any, path?: string): string;
15
+ /**
16
+ * 从数据源获取对象数据
17
+ */
18
+ export declare function getObjectFromDataSource(dataSource: DataSource): Record<string, any> | null;
19
+ /**
20
+ * 从数据源获取数组数据
21
+ */
22
+ export declare function getArrayFromDataSource(dataSource: DataSource): any[] | null;
23
+ /**
24
+ * 渲染表格行
25
+ */
26
+ export declare function renderTableRow(item: any, columns: TableColumnConfig[]): string[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "operp-print-designer",
3
3
  "private": false,
4
- "version": "1.0.8",
4
+ "version": "1.0.9",
5
5
  "type": "module",
6
6
  "description": "一个功能强大的打印模板设计器组件,支持拖拽、数据绑定和打印预览",
7
7
  "main": "./dist/operp-print-designer.umd.js",
@@ -12,18 +12,18 @@
12
12
  ],
13
13
  "exports": {
14
14
  ".": {
15
+ "types": "./dist/index.d.ts",
15
16
  "import": "./dist/operp-print-designer.es.js",
16
- "require": "./dist/operp-print-designer.umd.js",
17
- "types": "./dist/index.d.ts"
17
+ "require": "./dist/operp-print-designer.umd.js"
18
18
  },
19
19
  "./dist/operp-print-designer.css": "./dist/operp-print-designer.css"
20
20
  },
21
21
  "style": "./dist/operp-print-designer.css",
22
22
  "scripts": {
23
23
  "dev": "vite",
24
- "build": "tsc -b && vite build",
24
+ "build": "vite build && tsc -p tsconfig.lib.json",
25
25
  "preview": "vite preview",
26
- "build:lib": "tsc -p tsconfig.lib.json && vite build"
26
+ "build:lib": "vite build && tsc -p tsconfig.lib.json"
27
27
  },
28
28
  "keywords": [
29
29
  "print",