operp-print-designer 1.0.3 → 1.0.4

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,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,26 @@
1
+ export { default } from './components/PrintDesigner';
2
+ export { default as PrintDesigner } from './components/PrintDesigner';
3
+ export type { PrintDesignerProps } from './components/PrintDesigner';
4
+
5
+ export type {
6
+ CanvasComponent,
7
+ CanvasComponentType,
8
+ PageSettings,
9
+ GridSettings,
10
+ TemplateData,
11
+ DataSource,
12
+ DataSourceType,
13
+ TableColumnConfig,
14
+ DataBinding,
15
+ DataBindingConfig,
16
+ } from './types';
17
+
18
+ export {
19
+ getRenderValue,
20
+ getObjectFromDataSource,
21
+ getArrayFromDataSource,
22
+ safeParseJSON,
23
+ getValueByPath,
24
+ } from './utils/dataHelper';
25
+
26
+ export { useDesignerStore } from './store';
@@ -0,0 +1,29 @@
1
+ import { CanvasComponent, PageSettings, GridSettings, DataSource, TemplateData } from '../types';
2
+ interface DesignerStore {
3
+ components: CanvasComponent[];
4
+ selectedId: string | null;
5
+ pageSettings: PageSettings;
6
+ gridSettings: GridSettings;
7
+ dataSources: DataSource[];
8
+ // Components actions
9
+ addComponent: (comp: Omit<CanvasComponent, 'id'>) => void;
10
+ updateComponent: (id: string, updates: Partial<CanvasComponent>) => void;
11
+ updateComponentProps: (id: string, props: Record<string, unknown>) => void;
12
+ updateComponentTableColumns: (id: string, columns: any[]) => void;
13
+ deleteComponent: (id: string) => void;
14
+ selectComponent: (id: string | null) => void;
15
+ moveComponent: (id: string, x: number, y: number) => void;
16
+ resizeComponent: (id: string, w: number, h: number) => void;
17
+ // Page settings actions
18
+ updatePageSettings: (settings: Partial<PageSettings>) => void;
19
+ // Grid settings actions
20
+ updateGridSettings: (settings: Partial<GridSettings>) => void;
21
+ // Data sources actions
22
+ addDataSource: (ds: Omit<DataSource, 'id'>) => void;
23
+ updateDataSource: (id: string, updates: Partial<DataSource>) => void;
24
+ deleteDataSource: (id: string) => void;
25
+ // Template actions
26
+ loadTemplate: (data: TemplateData) => void;
27
+ exportTemplate: () => TemplateData;
28
+ }
29
+ export declare const useDesignerStore: () => DesignerStore;
@@ -0,0 +1,71 @@
1
+ export type CanvasComponentType = 'text' | 'image' | 'table' | 'barcode' | 'line';
2
+
3
+ export interface DataBinding {
4
+ dataSourceId?: string;
5
+ fieldPath?: string;
6
+ staticValue: string;
7
+ }
8
+
9
+ export type DataBindingConfig = DataBinding;
10
+
11
+ export interface TableColumnConfig {
12
+ title: string;
13
+ fieldPath?: string;
14
+ width?: number;
15
+ editable?: boolean;
16
+ }
17
+
18
+ export interface CanvasComponent {
19
+ id: string;
20
+ type: CanvasComponentType;
21
+ x: number;
22
+ y: number;
23
+ w: number;
24
+ h: number;
25
+ props: Record<string, unknown>;
26
+ tableColumns?: TableColumnConfig[];
27
+ }
28
+
29
+ export type DataSourceType = 'object' | 'array';
30
+
31
+ export interface DataSource {
32
+ id: string;
33
+ name: string;
34
+ type: DataSourceType;
35
+ data: string;
36
+ createdAt: number;
37
+ }
38
+
39
+ export type PaperSizePreset = 'A4' | 'A3' | 'A5' | 'Letter' | 'Legal' | 'custom';
40
+
41
+ export type Orientation = 'portrait' | 'landscape';
42
+
43
+ export interface PageSettings {
44
+ paperSize: PaperSizePreset;
45
+ customWidth: number;
46
+ customHeight: number;
47
+ orientation: Orientation;
48
+ marginTop: number;
49
+ marginRight: number;
50
+ marginBottom: number;
51
+ marginLeft: number;
52
+ showHeader: boolean;
53
+ headerContent: string;
54
+ showFooter: boolean;
55
+ footerContent: string;
56
+ showPageNumber: boolean;
57
+ pageNumberFormat: string;
58
+ }
59
+
60
+ export interface GridSettings {
61
+ cellSize: number;
62
+ cols: number;
63
+ }
64
+
65
+ export interface TemplateData {
66
+ version: string;
67
+ templateName: string;
68
+ pageSettings: PageSettings;
69
+ components: Omit<CanvasComponent, 'id'>[];
70
+ dataSources: Omit<DataSource, 'id'>[];
71
+ }
@@ -0,0 +1,6 @@
1
+ import { CanvasComponent, DataSource } from '../types';
2
+ export declare function safeParseJSON(str: string): any;
3
+ export declare function getValueByPath(obj: any, path: string): any;
4
+ export declare function getObjectFromDataSource(ds: DataSource): any;
5
+ export declare function getArrayFromDataSource(ds: DataSource): any[];
6
+ export declare function getRenderValue(comp: CanvasComponent, propName: string, dataSources: DataSource[]): 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.3",
4
+ "version": "1.0.4",
5
5
  "type": "module",
6
6
  "description": "一个功能强大的打印模板设计器组件,支持拖拽、数据绑定和打印预览",
7
7
  "main": "./dist/print-designer.umd.js",