@archbase/components 3.0.25 → 4.0.0
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/dist/buttons/ArchbaseSpeedDial.d.ts +59 -0
- package/dist/buttons/index.d.ts +2 -0
- package/dist/charts/ArchbaseArcGauge.d.ts +55 -0
- package/dist/charts/ArchbaseGantt.d.ts +70 -0
- package/dist/charts/ArchbaseLinearGauge.d.ts +55 -0
- package/dist/charts/ArchbaseResourceTimeline.d.ts +61 -0
- package/dist/charts/ArchbaseSparkline.d.ts +45 -0
- package/dist/charts/index.d.ts +10 -0
- package/dist/containers/ArchbaseExpansionPanel.d.ts +60 -0
- package/dist/containers/ArchbaseFloatingPanel.d.ts +91 -0
- package/dist/containers/index.d.ts +4 -0
- package/dist/datagrid/export/ArchbaseDataGridExcelExport.d.ts +67 -0
- package/dist/datagrid/export/index.d.ts +2 -0
- package/dist/datagrid/index.d.ts +1 -0
- package/dist/display/ArchbaseAnimationWrapper.d.ts +73 -0
- package/dist/display/ArchbaseBarcodeGenerator.d.ts +50 -0
- package/dist/display/ArchbaseCarousel.d.ts +100 -0
- package/dist/display/ArchbaseCodeViewer.d.ts +63 -0
- package/dist/display/ArchbaseDiffViewer.d.ts +41 -0
- package/dist/display/ArchbaseJsonTree.d.ts +34 -0
- package/dist/display/ArchbaseLightbox.d.ts +89 -0
- package/dist/display/ArchbaseMarquee.d.ts +46 -0
- package/dist/display/ArchbasePhotoAlbum.d.ts +58 -0
- package/dist/display/ArchbaseQRCode.d.ts +44 -0
- package/dist/display/ArchbaseTooltipRich.d.ts +82 -0
- package/dist/display/ArchbaseVirtualList.d.ts +116 -0
- package/dist/display/index.d.ts +24 -0
- package/dist/editors/ArchbaseAIPromptInput.d.ts +69 -0
- package/dist/editors/ArchbaseAsyncMultiSelect.d.ts +1 -1
- package/dist/editors/ArchbaseAsyncSelect.d.ts +1 -1
- package/dist/editors/ArchbaseBarcodeScanner.d.ts +63 -0
- package/dist/editors/ArchbaseCepInput.d.ts +26 -0
- package/dist/editors/ArchbaseColorGradientPicker.d.ts +80 -0
- package/dist/editors/ArchbaseCpfCnpjInput.d.ts +21 -0
- package/dist/editors/ArchbaseCurrencyInput.d.ts +25 -0
- package/dist/editors/ArchbaseDualListbox.d.ts +61 -0
- package/dist/editors/ArchbaseInPlaceEditor.d.ts +67 -0
- package/dist/editors/ArchbaseLightGrid.d.ts +56 -0
- package/dist/editors/ArchbaseMentionInput.d.ts +75 -0
- package/dist/editors/ArchbaseMultiEmail.d.ts +53 -0
- package/dist/editors/ArchbaseMultiViewCalendar.d.ts +47 -0
- package/dist/editors/ArchbaseNumberStepper.d.ts +66 -0
- package/dist/editors/ArchbaseOTPInput.d.ts +27 -0
- package/dist/editors/ArchbasePhoneInput.d.ts +52 -0
- package/dist/editors/ArchbaseRangeSlider.d.ts +22 -0
- package/dist/editors/ArchbaseSignaturePad.d.ts +60 -0
- package/dist/editors/ArchbaseSpeechToTextInput.d.ts +106 -0
- package/dist/editors/ArchbaseSpreadsheet.d.ts +56 -0
- package/dist/editors/ArchbaseTagInput.d.ts +55 -0
- package/dist/editors/index.d.ts +40 -0
- package/dist/feedback/ArchbaseChunkProgressBar.d.ts +35 -0
- package/dist/feedback/ArchbaseRipple.d.ts +43 -0
- package/dist/feedback/ArchbaseSkeleton.d.ts +115 -0
- package/dist/feedback/index.d.ts +6 -0
- package/dist/filters/ArchbaseColumnSelector.d.ts +38 -0
- package/dist/filters/index.d.ts +2 -0
- package/dist/forms/ArchbaseFieldArray.d.ts +80 -0
- package/dist/forms/ArchbaseFormWizard.d.ts +73 -0
- package/dist/forms/ArchbaseStepper.d.ts +51 -0
- package/dist/forms/index.d.ts +8 -0
- package/dist/forms/useArchbaseFormWizard.d.ts +74 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useArchbaseConfirm.d.ts +59 -0
- package/dist/image/editor/index.d.ts +43 -4
- package/dist/image/index.d.ts +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +22510 -13820
- package/dist/list/ArchbaseTreeList.d.ts +76 -0
- package/dist/list/index.d.ts +2 -0
- package/dist/navigation/ArchbaseActionSheet.d.ts +70 -0
- package/dist/navigation/ArchbaseAppBar.d.ts +63 -0
- package/dist/navigation/ArchbaseBottomNavigation.d.ts +61 -0
- package/dist/navigation/ArchbaseContextMenu.d.ts +76 -0
- package/dist/navigation/ArchbaseKeyboardShortcuts.d.ts +85 -0
- package/dist/navigation/ArchbaseSpotlight.d.ts +69 -0
- package/dist/navigation/index.d.ts +12 -0
- package/dist/notification/ArchbaseNotificationCenter.d.ts +56 -0
- package/dist/notification/index.d.ts +2 -0
- package/dist/onboarding/ArchbaseOnboardingTour.d.ts +27 -76
- package/dist/viewers/ArchbaseDocViewer.d.ts +40 -0
- package/dist/viewers/ArchbasePdfBuilder.d.ts +53 -0
- package/dist/viewers/ArchbaseXmlViewer.d.ts +36 -0
- package/dist/viewers/index.d.ts +6 -0
- package/package.json +41 -18
- package/src/buttons/ArchbaseSpeedDial.tsx +282 -0
- package/src/buttons/index.ts +3 -0
- package/src/charts/ArchbaseArcGauge.tsx +325 -0
- package/src/charts/ArchbaseGantt.tsx +494 -0
- package/src/charts/ArchbaseLinearGauge.tsx +288 -0
- package/src/charts/ArchbaseResourceTimeline.tsx +433 -0
- package/src/charts/ArchbaseSparkline.tsx +193 -0
- package/src/charts/index.ts +20 -1
- package/src/containers/ArchbaseExpansionPanel.tsx +208 -0
- package/src/containers/ArchbaseFloatingPanel.tsx +448 -0
- package/src/containers/index.ts +17 -0
- package/src/datagrid/components/pagination/grid-pagination.tsx +2 -2
- package/src/datagrid/export/ArchbaseDataGridExcelExport.tsx +293 -0
- package/src/datagrid/export/index.ts +8 -0
- package/src/datagrid/index.tsx +2 -0
- package/src/display/ArchbaseAnimationWrapper.tsx +272 -0
- package/src/display/ArchbaseBarcodeGenerator.tsx +303 -0
- package/src/display/ArchbaseCarousel.tsx +679 -0
- package/src/display/ArchbaseCodeViewer.tsx +271 -0
- package/src/display/ArchbaseDiffViewer.tsx +108 -0
- package/src/display/ArchbaseJsonTree.tsx +150 -0
- package/src/display/ArchbaseLightbox.tsx +279 -0
- package/src/display/ArchbaseMarquee.tsx +268 -0
- package/src/display/ArchbasePhotoAlbum.tsx +415 -0
- package/src/display/ArchbaseQRCode.tsx +137 -0
- package/src/display/ArchbaseTooltipRich.tsx +317 -0
- package/src/display/ArchbaseVirtualList.tsx +618 -0
- package/src/display/index.ts +94 -1
- package/src/editors/ArchbaseAIPromptInput.tsx +432 -0
- package/src/editors/ArchbaseBarcodeScanner.tsx +570 -0
- package/src/editors/ArchbaseCepInput.tsx +173 -0
- package/src/editors/ArchbaseColorGradientPicker.tsx +460 -0
- package/src/editors/ArchbaseCpfCnpjInput.tsx +193 -0
- package/src/editors/ArchbaseCurrencyInput.tsx +100 -0
- package/src/editors/ArchbaseDualListbox.tsx +671 -0
- package/src/editors/ArchbaseInPlaceEditor.tsx +406 -0
- package/src/editors/ArchbaseLightGrid.tsx +538 -0
- package/src/editors/ArchbaseMentionInput.tsx +384 -0
- package/src/editors/ArchbaseMultiEmail.tsx +367 -0
- package/src/editors/ArchbaseMultiViewCalendar.tsx +439 -0
- package/src/editors/ArchbaseNumberStepper.tsx +219 -0
- package/src/editors/ArchbaseOTPInput.tsx +133 -0
- package/src/editors/ArchbaseOperationHoursEditor.tsx +1 -1
- package/src/editors/ArchbasePhoneInput.tsx +355 -0
- package/src/editors/ArchbaseRangeSlider.tsx +109 -0
- package/src/editors/ArchbaseSignaturePad.tsx +425 -0
- package/src/editors/ArchbaseSpeechToTextInput.tsx +444 -0
- package/src/editors/ArchbaseSpreadsheet.tsx +388 -0
- package/src/editors/ArchbaseTagInput.tsx +326 -0
- package/src/editors/index.tsx +92 -0
- package/src/feedback/ArchbaseChunkProgressBar.tsx +156 -0
- package/src/feedback/ArchbaseRipple.tsx +278 -0
- package/src/feedback/ArchbaseSkeleton.tsx +419 -0
- package/src/feedback/index.ts +22 -1
- package/src/filters/ArchbaseColumnSelector.tsx +268 -0
- package/src/filters/index.ts +2 -0
- package/src/forms/ArchbaseFieldArray.tsx +305 -0
- package/src/forms/ArchbaseFormWizard.tsx +284 -0
- package/src/forms/ArchbaseStepper.tsx +137 -0
- package/src/forms/index.ts +24 -2
- package/src/forms/useArchbaseFormWizard.ts +283 -0
- package/src/hooks/index.ts +12 -0
- package/src/hooks/useArchbaseConfirm.ts +293 -0
- package/src/image/editor/functions/image-processing.ts +5 -0
- package/src/image/editor/index.tsx +305 -391
- package/src/image/index.ts +1 -0
- package/src/index.ts +3 -0
- package/src/list/ArchbaseTreeList.tsx +422 -0
- package/src/list/index.ts +3 -0
- package/src/navigation/ArchbaseActionSheet.tsx +301 -0
- package/src/navigation/ArchbaseAppBar.tsx +233 -0
- package/src/navigation/ArchbaseBottomNavigation.tsx +243 -0
- package/src/navigation/ArchbaseContextMenu.tsx +298 -0
- package/src/navigation/ArchbaseKeyboardShortcuts.tsx +472 -0
- package/src/navigation/ArchbaseSpotlight.tsx +483 -0
- package/src/navigation/index.ts +48 -1
- package/src/notification/ArchbaseNotificationCenter.tsx +502 -0
- package/src/notification/index.ts +2 -0
- package/src/onboarding/ArchbaseOnboardingTour.tsx +229 -102
- package/src/viewers/ArchbaseDocViewer.tsx +584 -0
- package/src/viewers/ArchbasePdfBuilder.tsx +291 -0
- package/src/viewers/ArchbaseXmlViewer.tsx +142 -0
- package/src/viewers/index.ts +12 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useEffect,
|
|
4
|
+
useImperativeHandle,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
useCallback,
|
|
8
|
+
type CSSProperties,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import { Box, Input } from '@mantine/core';
|
|
11
|
+
import { Designer, Form, Viewer } from '@pdfme/ui';
|
|
12
|
+
import type { Template, Font } from '@pdfme/common';
|
|
13
|
+
import { text, image, barcodes } from '@pdfme/schemas';
|
|
14
|
+
import { generate } from '@pdfme/generator';
|
|
15
|
+
import { useArchbaseV1V2Compatibility } from '@archbase/data';
|
|
16
|
+
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Public ref interface
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
export interface ArchbasePdfBuilderRef {
|
|
22
|
+
/** Generate a PDF from the current template + inputs and return its bytes. */
|
|
23
|
+
generatePdf(): Promise<Uint8Array>;
|
|
24
|
+
/** Return the current pdfme instance (Designer | Form | Viewer) if available. */
|
|
25
|
+
getInstance(): Designer | Form | Viewer | null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Props
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
export interface ArchbasePdfBuilderProps<T = unknown> {
|
|
33
|
+
/** Which pdfme UI to render. */
|
|
34
|
+
mode?: 'designer' | 'form' | 'viewer';
|
|
35
|
+
|
|
36
|
+
/** The pdfme template object. */
|
|
37
|
+
template: Template;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Optional Archbase DataSource – used in `form` mode to populate inputs
|
|
41
|
+
* from the current record.
|
|
42
|
+
*/
|
|
43
|
+
dataSource?: any;
|
|
44
|
+
/** Field path inside the data source record. */
|
|
45
|
+
dataField?: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Standalone inputs for `form` / `viewer` mode.
|
|
49
|
+
* Each element maps schema field names to string values.
|
|
50
|
+
*/
|
|
51
|
+
inputs?: Record<string, string>[];
|
|
52
|
+
|
|
53
|
+
/** Fired whenever the designer changes the template. */
|
|
54
|
+
onTemplateChange?: (template: Template) => void;
|
|
55
|
+
|
|
56
|
+
/** Fired when `generatePdf` completes. */
|
|
57
|
+
onGenerate?: (pdf: Uint8Array) => void;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Additional pdfme schema plugins.
|
|
61
|
+
* Defaults to `[text, image, barcodes]`.
|
|
62
|
+
*/
|
|
63
|
+
plugins?: Record<string, any>;
|
|
64
|
+
|
|
65
|
+
/** Custom font configuration forwarded to pdfme. */
|
|
66
|
+
font?: Font;
|
|
67
|
+
|
|
68
|
+
/** Container height. */
|
|
69
|
+
height?: string | number;
|
|
70
|
+
/** Container width. */
|
|
71
|
+
width?: string | number;
|
|
72
|
+
|
|
73
|
+
/** Optional label rendered above the builder (uses Mantine Input.Wrapper). */
|
|
74
|
+
label?: string;
|
|
75
|
+
/** Optional description rendered below the label. */
|
|
76
|
+
description?: string;
|
|
77
|
+
|
|
78
|
+
/** Extra inline styles applied to the outer wrapper. */
|
|
79
|
+
style?: CSSProperties;
|
|
80
|
+
/** Extra CSS class name applied to the outer wrapper. */
|
|
81
|
+
className?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
// Default plugins helper
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
|
|
88
|
+
const DEFAULT_PLUGINS: Record<string, any> = { Text: text, Image: image, ...barcodes };
|
|
89
|
+
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// Component
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
|
|
94
|
+
function ArchbasePdfBuilderInner<T = unknown>(
|
|
95
|
+
{
|
|
96
|
+
mode = 'designer',
|
|
97
|
+
template,
|
|
98
|
+
dataSource,
|
|
99
|
+
dataField,
|
|
100
|
+
inputs: inputsProp,
|
|
101
|
+
onTemplateChange,
|
|
102
|
+
onGenerate,
|
|
103
|
+
plugins,
|
|
104
|
+
font,
|
|
105
|
+
height = '100vh',
|
|
106
|
+
width = '100%',
|
|
107
|
+
label,
|
|
108
|
+
description,
|
|
109
|
+
style,
|
|
110
|
+
className,
|
|
111
|
+
}: ArchbasePdfBuilderProps<T>,
|
|
112
|
+
ref: React.Ref<ArchbasePdfBuilderRef>,
|
|
113
|
+
) {
|
|
114
|
+
// ---- Container ref ----
|
|
115
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
116
|
+
|
|
117
|
+
// ---- pdfme instance ----
|
|
118
|
+
const instanceRef = useRef<Designer | Form | Viewer | null>(null);
|
|
119
|
+
|
|
120
|
+
// ---- Keep latest template in a ref so callbacks always see current value ----
|
|
121
|
+
const templateRef = useRef<Template>(template);
|
|
122
|
+
templateRef.current = template;
|
|
123
|
+
|
|
124
|
+
// ---- DataSource integration (form mode) ----
|
|
125
|
+
const { currentValue: dsValue, loadDataSourceFieldValue } =
|
|
126
|
+
useArchbaseV1V2Compatibility<Record<string, string>[] | undefined>(
|
|
127
|
+
'ArchbasePdfBuilder',
|
|
128
|
+
dataSource,
|
|
129
|
+
dataField,
|
|
130
|
+
undefined,
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
if (dataSource && dataField) {
|
|
135
|
+
loadDataSourceFieldValue();
|
|
136
|
+
}
|
|
137
|
+
}, [dataSource, dataField, loadDataSourceFieldValue]);
|
|
138
|
+
|
|
139
|
+
// Resolve inputs: prop takes precedence, then data-source value, then empty.
|
|
140
|
+
const resolvedInputs: Record<string, string>[] =
|
|
141
|
+
inputsProp ?? dsValue ?? [{}];
|
|
142
|
+
|
|
143
|
+
// ---- Merged plugins ----
|
|
144
|
+
const mergedPlugins = plugins
|
|
145
|
+
? { ...DEFAULT_PLUGINS, ...plugins }
|
|
146
|
+
: DEFAULT_PLUGINS;
|
|
147
|
+
|
|
148
|
+
// ---- Initialise / re-create pdfme instance ----
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (!containerRef.current) return;
|
|
151
|
+
|
|
152
|
+
// Destroy previous instance
|
|
153
|
+
if (instanceRef.current) {
|
|
154
|
+
instanceRef.current.destroy();
|
|
155
|
+
instanceRef.current = null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const domContainer = containerRef.current;
|
|
159
|
+
|
|
160
|
+
const commonOpts: any = {
|
|
161
|
+
domContainer,
|
|
162
|
+
template,
|
|
163
|
+
plugins: mergedPlugins,
|
|
164
|
+
...(font ? { options: { font } } : {}),
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
if (mode === 'designer') {
|
|
169
|
+
const designer = new Designer(commonOpts);
|
|
170
|
+
|
|
171
|
+
designer.onChangeTemplate((updated: Template) => {
|
|
172
|
+
templateRef.current = updated;
|
|
173
|
+
onTemplateChange?.(updated);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
instanceRef.current = designer;
|
|
177
|
+
} else if (mode === 'form') {
|
|
178
|
+
const form = new Form({
|
|
179
|
+
...commonOpts,
|
|
180
|
+
inputs: resolvedInputs,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
instanceRef.current = form;
|
|
184
|
+
} else {
|
|
185
|
+
// viewer
|
|
186
|
+
const viewer = new Viewer({
|
|
187
|
+
...commonOpts,
|
|
188
|
+
inputs: resolvedInputs,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
instanceRef.current = viewer;
|
|
192
|
+
}
|
|
193
|
+
} catch (err) {
|
|
194
|
+
console.error('[ArchbasePdfBuilder] Failed to initialise pdfme:', err);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return () => {
|
|
198
|
+
if (instanceRef.current) {
|
|
199
|
+
instanceRef.current.destroy();
|
|
200
|
+
instanceRef.current = null;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
// We intentionally re-create when mode or template identity changes.
|
|
204
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
205
|
+
}, [mode, template, font]);
|
|
206
|
+
|
|
207
|
+
// ---- Update inputs on form/viewer when they change ----
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
const inst = instanceRef.current;
|
|
210
|
+
if (!inst) return;
|
|
211
|
+
if (mode === 'form' || mode === 'viewer') {
|
|
212
|
+
try {
|
|
213
|
+
(inst as Form | Viewer).setInputs(resolvedInputs);
|
|
214
|
+
} catch {
|
|
215
|
+
// instance may not be ready yet
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
219
|
+
}, [resolvedInputs, mode]);
|
|
220
|
+
|
|
221
|
+
// ---- Imperative handle ----
|
|
222
|
+
useImperativeHandle(
|
|
223
|
+
ref,
|
|
224
|
+
() => ({
|
|
225
|
+
async generatePdf(): Promise<Uint8Array> {
|
|
226
|
+
const currentTemplate = templateRef.current;
|
|
227
|
+
let currentInputs = resolvedInputs;
|
|
228
|
+
|
|
229
|
+
// In form mode we can grab the latest user-edited inputs
|
|
230
|
+
if (mode === 'form' && instanceRef.current) {
|
|
231
|
+
try {
|
|
232
|
+
currentInputs = (instanceRef.current as Form).getInputs();
|
|
233
|
+
} catch {
|
|
234
|
+
// fallback to prop inputs
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const pdf = await generate({
|
|
239
|
+
template: currentTemplate,
|
|
240
|
+
inputs: currentInputs,
|
|
241
|
+
plugins: mergedPlugins,
|
|
242
|
+
...(font ? { options: { font } } : {}),
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
onGenerate?.(pdf);
|
|
246
|
+
return pdf;
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
getInstance() {
|
|
250
|
+
return instanceRef.current;
|
|
251
|
+
},
|
|
252
|
+
}),
|
|
253
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
254
|
+
[mode, font, resolvedInputs],
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
// ---- Render ----
|
|
258
|
+
const content = (
|
|
259
|
+
<Box
|
|
260
|
+
ref={containerRef}
|
|
261
|
+
style={{
|
|
262
|
+
width: typeof width === 'number' ? `${width}px` : width,
|
|
263
|
+
height: typeof height === 'number' ? `${height}px` : height,
|
|
264
|
+
...style,
|
|
265
|
+
}}
|
|
266
|
+
className={className}
|
|
267
|
+
/>
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
if (label || description) {
|
|
271
|
+
return (
|
|
272
|
+
<Input.Wrapper label={label} description={description}>
|
|
273
|
+
{content}
|
|
274
|
+
</Input.Wrapper>
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return content;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// ---------------------------------------------------------------------------
|
|
282
|
+
// Forward-ref wrapper that preserves the generic parameter
|
|
283
|
+
// ---------------------------------------------------------------------------
|
|
284
|
+
|
|
285
|
+
export const ArchbasePdfBuilder = forwardRef(ArchbasePdfBuilderInner) as <
|
|
286
|
+
T = unknown,
|
|
287
|
+
>(
|
|
288
|
+
props: ArchbasePdfBuilderProps<T> & { ref?: React.Ref<ArchbasePdfBuilderRef> },
|
|
289
|
+
) => React.ReactElement | null;
|
|
290
|
+
|
|
291
|
+
(ArchbasePdfBuilder as any).displayName = 'ArchbasePdfBuilder';
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
2
|
+
import { Box, Input, ScrollArea } from '@mantine/core';
|
|
3
|
+
import { CodeHighlight } from '@mantine/code-highlight';
|
|
4
|
+
import {
|
|
5
|
+
useArchbaseV1V2Compatibility,
|
|
6
|
+
useArchbaseDataSourceListener,
|
|
7
|
+
} from '@archbase/data';
|
|
8
|
+
import type { IArchbaseDataSourceBase } from '@archbase/data';
|
|
9
|
+
|
|
10
|
+
function formatXmlString(xml: string): string {
|
|
11
|
+
let formatted = '';
|
|
12
|
+
let indent = '';
|
|
13
|
+
const tab = ' ';
|
|
14
|
+
xml.split(/>\s*</).forEach((node) => {
|
|
15
|
+
if (node.match(/^\/\w/)) indent = indent.substring(tab.length);
|
|
16
|
+
formatted += indent + '<' + node + '>\n';
|
|
17
|
+
if (node.match(/^<?\w[^>]*[^/]$/) && !node.startsWith('?')) indent += tab;
|
|
18
|
+
});
|
|
19
|
+
return formatted.substring(1, formatted.length - 2);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ArchbaseXmlViewerProps<T> {
|
|
23
|
+
/** DataSource to read the XML string value from */
|
|
24
|
+
dataSource?: IArchbaseDataSourceBase<T>;
|
|
25
|
+
/** Field name within the DataSource */
|
|
26
|
+
dataField?: string;
|
|
27
|
+
/** Standalone XML string value */
|
|
28
|
+
value?: string;
|
|
29
|
+
/** Alias for value - standalone XML string */
|
|
30
|
+
xml?: string;
|
|
31
|
+
/** Label for Input.Wrapper */
|
|
32
|
+
label?: string;
|
|
33
|
+
/** Description for Input.Wrapper */
|
|
34
|
+
description?: string;
|
|
35
|
+
/** Error message for Input.Wrapper */
|
|
36
|
+
error?: string;
|
|
37
|
+
/** Whether to show line numbers @default true */
|
|
38
|
+
showLineNumbers?: boolean;
|
|
39
|
+
/** Whether to show the copy button @default true */
|
|
40
|
+
showCopyButton?: boolean;
|
|
41
|
+
/** Whether to auto-format/indent the XML @default true */
|
|
42
|
+
formatXml?: boolean;
|
|
43
|
+
/** Max height - enables scroll area when set */
|
|
44
|
+
maxHeight?: string | number;
|
|
45
|
+
/** Custom style */
|
|
46
|
+
style?: React.CSSProperties;
|
|
47
|
+
/** Custom class name */
|
|
48
|
+
className?: string;
|
|
49
|
+
/** Width of the viewer */
|
|
50
|
+
width?: string | number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function ArchbaseXmlViewer<T>({
|
|
54
|
+
dataSource,
|
|
55
|
+
dataField,
|
|
56
|
+
value: valueProp,
|
|
57
|
+
xml,
|
|
58
|
+
label,
|
|
59
|
+
description,
|
|
60
|
+
error,
|
|
61
|
+
showCopyButton = true,
|
|
62
|
+
formatXml = true,
|
|
63
|
+
maxHeight,
|
|
64
|
+
style,
|
|
65
|
+
className,
|
|
66
|
+
width,
|
|
67
|
+
}: ArchbaseXmlViewerProps<T>) {
|
|
68
|
+
const resolvedValueProp = valueProp ?? xml;
|
|
69
|
+
|
|
70
|
+
const {
|
|
71
|
+
currentValue,
|
|
72
|
+
loadDataSourceFieldValue,
|
|
73
|
+
} = useArchbaseV1V2Compatibility<string>(
|
|
74
|
+
'ArchbaseXmlViewer',
|
|
75
|
+
dataSource,
|
|
76
|
+
dataField,
|
|
77
|
+
resolvedValueProp,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (dataSource && dataField) {
|
|
82
|
+
loadDataSourceFieldValue();
|
|
83
|
+
}
|
|
84
|
+
}, [dataSource, dataField, loadDataSourceFieldValue]);
|
|
85
|
+
|
|
86
|
+
const dataSourceEvent = useCallback((_event: any) => {
|
|
87
|
+
loadDataSourceFieldValue();
|
|
88
|
+
}, [loadDataSourceFieldValue]);
|
|
89
|
+
|
|
90
|
+
useArchbaseDataSourceListener({
|
|
91
|
+
dataSource,
|
|
92
|
+
listener: dataSourceEvent,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const xmlString = currentValue ?? '';
|
|
96
|
+
|
|
97
|
+
const displayXml = useMemo(() => {
|
|
98
|
+
if (!xmlString) return '';
|
|
99
|
+
if (formatXml) {
|
|
100
|
+
try {
|
|
101
|
+
return formatXmlString(xmlString);
|
|
102
|
+
} catch {
|
|
103
|
+
return xmlString;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return xmlString;
|
|
107
|
+
}, [xmlString, formatXml]);
|
|
108
|
+
|
|
109
|
+
const codeHighlightElement = (
|
|
110
|
+
<CodeHighlight
|
|
111
|
+
code={displayXml}
|
|
112
|
+
language="xml"
|
|
113
|
+
withCopyButton={showCopyButton}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const content = (
|
|
118
|
+
<Box style={{ ...style, width }} className={className}>
|
|
119
|
+
{maxHeight ? (
|
|
120
|
+
<ScrollArea style={{ maxHeight }} type="auto">
|
|
121
|
+
{codeHighlightElement}
|
|
122
|
+
</ScrollArea>
|
|
123
|
+
) : (
|
|
124
|
+
codeHighlightElement
|
|
125
|
+
)}
|
|
126
|
+
</Box>
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
if (label || description || error) {
|
|
130
|
+
return (
|
|
131
|
+
<Input.Wrapper label={label} description={description} error={error}>
|
|
132
|
+
{content}
|
|
133
|
+
</Input.Wrapper>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return content;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
ArchbaseXmlViewer.displayName = 'ArchbaseXmlViewer';
|
|
141
|
+
|
|
142
|
+
export { ArchbaseXmlViewer };
|
package/src/viewers/index.ts
CHANGED
|
@@ -13,5 +13,17 @@ export type {
|
|
|
13
13
|
PDFToolbarActions,
|
|
14
14
|
} from './ArchbasePDFViewer.types';
|
|
15
15
|
|
|
16
|
+
// XML Viewer
|
|
17
|
+
export { ArchbaseXmlViewer } from './ArchbaseXmlViewer';
|
|
18
|
+
export type { ArchbaseXmlViewerProps } from './ArchbaseXmlViewer';
|
|
19
|
+
|
|
20
|
+
// PDF Builder (pdfme)
|
|
21
|
+
export { ArchbasePdfBuilder } from './ArchbasePdfBuilder';
|
|
22
|
+
export type { ArchbasePdfBuilderProps, ArchbasePdfBuilderRef } from './ArchbasePdfBuilder';
|
|
23
|
+
|
|
24
|
+
// Document Viewer
|
|
25
|
+
export { ArchbaseDocViewer } from './ArchbaseDocViewer';
|
|
26
|
+
export type { ArchbaseDocViewerProps } from './ArchbaseDocViewer';
|
|
27
|
+
|
|
16
28
|
// File Previewer
|
|
17
29
|
export * from './file-preview';
|