@nice2dev/ui-printing 1.0.28
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/README.md +56 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +3085 -0
- package/dist/print-button/NicePrintButton.d.ts +5 -0
- package/dist/print-button/NicePrintButton.d.ts.map +1 -0
- package/dist/print-button/index.d.ts +2 -0
- package/dist/print-button/index.d.ts.map +1 -0
- package/dist/print-preview/NicePrintPreview.d.ts +5 -0
- package/dist/print-preview/NicePrintPreview.d.ts.map +1 -0
- package/dist/print-preview/index.d.ts +2 -0
- package/dist/print-preview/index.d.ts.map +1 -0
- package/dist/print-queue/NicePrintQueue.d.ts +5 -0
- package/dist/print-queue/NicePrintQueue.d.ts.map +1 -0
- package/dist/print-queue/index.d.ts +2 -0
- package/dist/print-queue/index.d.ts.map +1 -0
- package/dist/style.css +1 -0
- package/dist/template-browser/NiceTemplateBrowser.d.ts +5 -0
- package/dist/template-browser/NiceTemplateBrowser.d.ts.map +1 -0
- package/dist/template-browser/index.d.ts +2 -0
- package/dist/template-browser/index.d.ts.map +1 -0
- package/dist/template-editor/NiceTemplateEditor.d.ts +6 -0
- package/dist/template-editor/NiceTemplateEditor.d.ts.map +1 -0
- package/dist/template-editor/index.d.ts +2 -0
- package/dist/template-editor/index.d.ts.map +1 -0
- package/dist/types/printingTypes.d.ts +249 -0
- package/dist/types/printingTypes.d.ts.map +1 -0
- package/package.json +66 -0
- package/src/globals.d.ts +9 -0
- package/src/index.ts +69 -0
- package/src/print-button/NicePrintButton.tsx +182 -0
- package/src/print-button/PrintButton.module.css +167 -0
- package/src/print-button/index.ts +1 -0
- package/src/print-preview/NicePrintPreview.tsx +417 -0
- package/src/print-preview/PrintPreview.module.css +122 -0
- package/src/print-preview/index.ts +1 -0
- package/src/print-queue/NicePrintQueue.tsx +350 -0
- package/src/print-queue/PrintQueue.module.css +203 -0
- package/src/print-queue/index.ts +1 -0
- package/src/template-browser/NiceTemplateBrowser.tsx +221 -0
- package/src/template-browser/TemplateBrowser.module.css +277 -0
- package/src/template-browser/index.ts +1 -0
- package/src/template-editor/NiceTemplateEditor.tsx +2386 -0
- package/src/template-editor/NiceTemplateEditor.tsx.first +1011 -0
- package/src/template-editor/NiceTemplateEditor.tsx.tmp +392 -0
- package/src/template-editor/TemplateEditor.module.css +1462 -0
- package/src/template-editor/index.ts +1 -0
- package/src/types/printingTypes.ts +301 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { NiceTemplateEditor } from './NiceTemplateEditor';
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
// ─── Primitives ───────────────────────────────────────────────────────────────
|
|
2
|
+
export type TemplateId = string;
|
|
3
|
+
export type PrintJobId = string;
|
|
4
|
+
export type PrinterId = string;
|
|
5
|
+
export type FieldId = string;
|
|
6
|
+
|
|
7
|
+
// ─── Paper ───────────────────────────────────────────────────────────────────
|
|
8
|
+
export type PaperSize = 'A3' | 'A4' | 'A5' | 'A6' | 'Letter' | 'Legal' | 'Tabloid' | 'custom';
|
|
9
|
+
export type PaperOrientation = 'portrait' | 'landscape';
|
|
10
|
+
|
|
11
|
+
export interface PaperMargins {
|
|
12
|
+
top: number; // mm
|
|
13
|
+
right: number;
|
|
14
|
+
bottom: number;
|
|
15
|
+
left: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface CustomPaperSize {
|
|
19
|
+
widthMm: number;
|
|
20
|
+
heightMm: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// ─── Fields ───────────────────────────────────────────────────────────────────
|
|
24
|
+
export type PrintFieldType =
|
|
25
|
+
| 'text'
|
|
26
|
+
| 'number'
|
|
27
|
+
| 'currency'
|
|
28
|
+
| 'date'
|
|
29
|
+
| 'datetime'
|
|
30
|
+
| 'boolean'
|
|
31
|
+
| 'image'
|
|
32
|
+
| 'barcode'
|
|
33
|
+
| 'qr'
|
|
34
|
+
| 'signature'
|
|
35
|
+
| 'static_text'
|
|
36
|
+
| 'static_image'
|
|
37
|
+
| 'line'
|
|
38
|
+
| 'rect'
|
|
39
|
+
| 'page_number'
|
|
40
|
+
| 'total_pages'
|
|
41
|
+
| 'print_date';
|
|
42
|
+
|
|
43
|
+
export type BarcodeType = 'ean13' | 'ean8' | 'code128' | 'code39' | 'upc' | 'itf14' | 'datamatrix';
|
|
44
|
+
|
|
45
|
+
export interface FieldPosition {
|
|
46
|
+
x: number; // mm from left
|
|
47
|
+
y: number; // mm from top
|
|
48
|
+
width: number; // mm
|
|
49
|
+
height: number; // mm
|
|
50
|
+
zIndex?: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface FieldStyle {
|
|
54
|
+
fontFamily?: string;
|
|
55
|
+
fontSize?: number; // pt
|
|
56
|
+
fontWeight?: 'normal' | 'bold';
|
|
57
|
+
fontStyle?: 'normal' | 'italic';
|
|
58
|
+
color?: string;
|
|
59
|
+
backgroundColor?: string;
|
|
60
|
+
textAlign?: 'left' | 'center' | 'right' | 'justify';
|
|
61
|
+
verticalAlign?: 'top' | 'middle' | 'bottom';
|
|
62
|
+
borderWidth?: number;
|
|
63
|
+
borderColor?: string;
|
|
64
|
+
borderStyle?: 'solid' | 'dashed' | 'dotted';
|
|
65
|
+
borderRadius?: number;
|
|
66
|
+
padding?: number; // mm
|
|
67
|
+
lineHeight?: number;
|
|
68
|
+
letterSpacing?: number; // em
|
|
69
|
+
opacity?: number;
|
|
70
|
+
rotation?: number; // degrees
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface PrintDataField {
|
|
74
|
+
id: FieldId;
|
|
75
|
+
name: string;
|
|
76
|
+
label: string;
|
|
77
|
+
type: PrintFieldType;
|
|
78
|
+
dataPath: string; // dot-notation e.g. "invoice.number"
|
|
79
|
+
format?: string; // e.g. "DD.MM.YYYY", "#,##0.00", "EUR"
|
|
80
|
+
fallback?: string; // shown when dataPath resolves to null
|
|
81
|
+
barcodeType?: BarcodeType;
|
|
82
|
+
position: FieldPosition;
|
|
83
|
+
style: FieldStyle;
|
|
84
|
+
conditional?: {
|
|
85
|
+
field: string;
|
|
86
|
+
operator: 'eq' | 'neq' | 'gt' | 'lt' | 'contains';
|
|
87
|
+
value: unknown;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ─── Watermark ────────────────────────────────────────────────────────────────
|
|
92
|
+
export type WatermarkType = 'text' | 'image';
|
|
93
|
+
|
|
94
|
+
export interface PrintWatermark {
|
|
95
|
+
id: string;
|
|
96
|
+
type: WatermarkType;
|
|
97
|
+
text?: string;
|
|
98
|
+
imageUrl?: string;
|
|
99
|
+
opacity: number; // 0-1
|
|
100
|
+
angle: number; // degrees
|
|
101
|
+
fontSize?: number; // pt for text watermarks
|
|
102
|
+
color?: string;
|
|
103
|
+
repeat?: boolean; // tile watermark across page
|
|
104
|
+
position?: 'center' | 'diagonal' | 'tile' | { x: number; y: number };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ─── Signature ────────────────────────────────────────────────────────────────
|
|
108
|
+
export interface PrintSignature {
|
|
109
|
+
id: string;
|
|
110
|
+
label: string; // "Podpis zleceniodawcy"
|
|
111
|
+
position: FieldPosition;
|
|
112
|
+
signerName?: string; // pre-filled name
|
|
113
|
+
signerEmail?: string;
|
|
114
|
+
showDate?: boolean;
|
|
115
|
+
showLine?: boolean; // draw signature line
|
|
116
|
+
style?: FieldStyle;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ─── Template sections ────────────────────────────────────────────────────────
|
|
120
|
+
export type SectionType = 'header' | 'body' | 'footer' | 'background';
|
|
121
|
+
|
|
122
|
+
export interface PrintSection {
|
|
123
|
+
id: string;
|
|
124
|
+
type: SectionType;
|
|
125
|
+
heightMm?: number; // fixed height; undefined = auto for body
|
|
126
|
+
fields: PrintDataField[];
|
|
127
|
+
repeatForEach?: string; // data path for repeated sections e.g. "invoice.items"
|
|
128
|
+
showOnFirstPage?: boolean;
|
|
129
|
+
showOnLastPage?: boolean;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ─── Template ─────────────────────────────────────────────────────────────────
|
|
133
|
+
export interface PrintTemplate {
|
|
134
|
+
id: TemplateId;
|
|
135
|
+
name: string;
|
|
136
|
+
description?: string;
|
|
137
|
+
category?: string;
|
|
138
|
+
tags?: string[];
|
|
139
|
+
paperSize: PaperSize;
|
|
140
|
+
customSize?: CustomPaperSize;
|
|
141
|
+
orientation: PaperOrientation;
|
|
142
|
+
margins: PaperMargins;
|
|
143
|
+
sections: PrintSection[];
|
|
144
|
+
watermarks?: PrintWatermark[];
|
|
145
|
+
signatures?: PrintSignature[];
|
|
146
|
+
dataSchema?: DataSourceSchema;
|
|
147
|
+
previewImageUrl?: string;
|
|
148
|
+
createdAt?: string;
|
|
149
|
+
updatedAt?: string;
|
|
150
|
+
version?: number;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ─── Data source ──────────────────────────────────────────────────────────────
|
|
154
|
+
export interface DataSourceField {
|
|
155
|
+
path: string; // e.g. "invoice.number"
|
|
156
|
+
label: string;
|
|
157
|
+
type: 'string' | 'number' | 'boolean' | 'date' | 'image' | 'array' | 'object';
|
|
158
|
+
description?: string;
|
|
159
|
+
example?: unknown;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface DataSourceSchema {
|
|
163
|
+
entityName: string;
|
|
164
|
+
entityLabel: string;
|
|
165
|
+
fields: DataSourceField[];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface TemplateSampleData {
|
|
169
|
+
entityName: string;
|
|
170
|
+
label?: string;
|
|
171
|
+
data: Record<string, unknown>;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ─── Printer ──────────────────────────────────────────────────────────────────
|
|
175
|
+
export interface PrinterCapabilities {
|
|
176
|
+
color: boolean;
|
|
177
|
+
duplex: boolean;
|
|
178
|
+
paperSizes: PaperSize[];
|
|
179
|
+
maxCopies?: number;
|
|
180
|
+
dpi?: number[];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface PrinterInfo {
|
|
184
|
+
id: PrinterId;
|
|
185
|
+
name: string;
|
|
186
|
+
isDefault: boolean;
|
|
187
|
+
isOnline: boolean;
|
|
188
|
+
status?: 'ready' | 'busy' | 'offline' | 'error';
|
|
189
|
+
location?: string;
|
|
190
|
+
capabilities: PrinterCapabilities;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ─── Print job ────────────────────────────────────────────────────────────────
|
|
194
|
+
export type PrintJobStatus = 'queued' | 'printing' | 'done' | 'error' | 'paused' | 'cancelled';
|
|
195
|
+
|
|
196
|
+
export interface PrintJobOptions {
|
|
197
|
+
copies: number;
|
|
198
|
+
printerId: PrinterId;
|
|
199
|
+
paperSize?: PaperSize;
|
|
200
|
+
orientation?: PaperOrientation;
|
|
201
|
+
colorMode?: 'color' | 'grayscale' | 'black_white';
|
|
202
|
+
duplex?: boolean;
|
|
203
|
+
quality?: 'draft' | 'normal' | 'high';
|
|
204
|
+
pageRanges?: string; // e.g. "1-3,5"
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface PrintJob {
|
|
208
|
+
id: PrintJobId;
|
|
209
|
+
templateId: TemplateId;
|
|
210
|
+
templateName: string;
|
|
211
|
+
entityData?: Record<string, unknown>;
|
|
212
|
+
entityLabel?: string; // human-readable e.g. "Faktura #2024/001"
|
|
213
|
+
options: PrintJobOptions;
|
|
214
|
+
status: PrintJobStatus;
|
|
215
|
+
progress?: number; // 0-100 for printing
|
|
216
|
+
errorMessage?: string;
|
|
217
|
+
pages?: number;
|
|
218
|
+
createdAt: string;
|
|
219
|
+
startedAt?: string;
|
|
220
|
+
completedAt?: string;
|
|
221
|
+
priority?: number; // lower = higher priority
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ─── Component props ──────────────────────────────────────────────────────────
|
|
225
|
+
import type { CSSProperties } from 'react';
|
|
226
|
+
|
|
227
|
+
export interface NiceTemplateEditorProps {
|
|
228
|
+
template?: PrintTemplate;
|
|
229
|
+
dataSchema?: DataSourceSchema;
|
|
230
|
+
sampleData?: TemplateSampleData[];
|
|
231
|
+
availableEntities?: TemplateSampleData[];
|
|
232
|
+
onChange?: (template: PrintTemplate) => void;
|
|
233
|
+
onSave?: (template: PrintTemplate) => void;
|
|
234
|
+
readOnly?: boolean;
|
|
235
|
+
className?: string;
|
|
236
|
+
style?: CSSProperties;
|
|
237
|
+
theme?: 'light' | 'dark';
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export interface NiceTemplateBrowserProps {
|
|
241
|
+
templates: PrintTemplate[];
|
|
242
|
+
selectedId?: TemplateId;
|
|
243
|
+
onSelect?: (template: PrintTemplate) => void;
|
|
244
|
+
onImport?: (template: PrintTemplate) => void;
|
|
245
|
+
onExport?: (template: PrintTemplate) => void;
|
|
246
|
+
onDelete?: (templateId: TemplateId) => void;
|
|
247
|
+
onNew?: () => void;
|
|
248
|
+
className?: string;
|
|
249
|
+
style?: CSSProperties;
|
|
250
|
+
theme?: 'light' | 'dark';
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export interface NicePrintPreviewProps {
|
|
254
|
+
template: PrintTemplate;
|
|
255
|
+
entities?: Record<string, unknown>[];
|
|
256
|
+
sampleData?: TemplateSampleData;
|
|
257
|
+
activePrinterId?: PrinterId;
|
|
258
|
+
onPrint?: (options: Partial<PrintJobOptions>) => void;
|
|
259
|
+
className?: string;
|
|
260
|
+
style?: CSSProperties;
|
|
261
|
+
theme?: 'light' | 'dark';
|
|
262
|
+
/**
|
|
263
|
+
* When true (default), preview renders inside a portaled overlay with a close button.
|
|
264
|
+
* When false, renders inline at the call site (legacy behavior — replaces current page area).
|
|
265
|
+
*/
|
|
266
|
+
asPopup?: boolean;
|
|
267
|
+
/** Controls overlay visibility when asPopup is true (uncontrolled if omitted). */
|
|
268
|
+
open?: boolean;
|
|
269
|
+
/** Called when the user closes the popup. */
|
|
270
|
+
onClose?: () => void;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface NicePrintQueueProps {
|
|
274
|
+
jobs: PrintJob[];
|
|
275
|
+
printers?: PrinterInfo[];
|
|
276
|
+
onJobUpdate: (id: PrintJobId, patch: Partial<PrintJob>) => void;
|
|
277
|
+
onJobRemove: (id: PrintJobId) => void;
|
|
278
|
+
onJobReorder: (fromIndex: number, toIndex: number) => void;
|
|
279
|
+
onJobPrint: (id: PrintJobId) => void;
|
|
280
|
+
onBulkRemove?: (ids: PrintJobId[]) => void;
|
|
281
|
+
onBulkPrint?: (ids: PrintJobId[]) => void;
|
|
282
|
+
maxHeight?: number;
|
|
283
|
+
className?: string;
|
|
284
|
+
style?: CSSProperties;
|
|
285
|
+
theme?: 'light' | 'dark';
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export interface NicePrintButtonProps {
|
|
289
|
+
onPrint: (options: PrintJobOptions) => void;
|
|
290
|
+
printers?: PrinterInfo[];
|
|
291
|
+
defaultPrinterId?: PrinterId;
|
|
292
|
+
defaultCopies?: number;
|
|
293
|
+
disabled?: boolean;
|
|
294
|
+
loading?: boolean;
|
|
295
|
+
label?: string;
|
|
296
|
+
variant?: 'primary' | 'secondary' | 'ghost';
|
|
297
|
+
size?: 'sm' | 'md' | 'lg';
|
|
298
|
+
className?: string;
|
|
299
|
+
style?: CSSProperties;
|
|
300
|
+
theme?: 'light' | 'dark';
|
|
301
|
+
}
|