datastake-daf 0.6.459 → 0.6.461
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/components/index.js +2 -2
- package/package.json +4 -1
- package/src/@daf/core/components/Dashboard/PdfView/index.jsx +1 -1
- package/src/@daf/core/components/Document/WordDocument/Preview/WordDocument.stories.js +491 -0
- package/src/@daf/core/components/Document/WordDocument/Preview/index.js +104 -0
- package/src/@daf/core/components/Document/WordDocument/createDocument.js +364 -0
- package/src/@daf/core/components/Document/WordDocument/index.js +9 -0
- package/src/@daf/core/components/EditForm/storyConfig.js +1 -1
- package/src/@daf/core/components/EditForm/storyConfig1.js +9932 -131
- package/src/@daf/core/components/ViewForm/components/DataLink/flat.js +1 -1
package/dist/components/index.js
CHANGED
|
@@ -14630,7 +14630,7 @@ function PdfView(_ref2) {
|
|
|
14630
14630
|
});
|
|
14631
14631
|
setPages(_pages);
|
|
14632
14632
|
}
|
|
14633
|
-
}, [sectionsConfig,
|
|
14633
|
+
}, [sectionsConfig, customMarginBottom, config === null || config === void 0 ? void 0 : config.length]);
|
|
14634
14634
|
React.useEffect(() => {
|
|
14635
14635
|
doSizing();
|
|
14636
14636
|
}, [doSizing]);
|
|
@@ -26579,8 +26579,8 @@ function DataLinkFlat$1({
|
|
|
26579
26579
|
return (dataLinkFormData || []).map(d => {
|
|
26580
26580
|
const dataLinkData = d[dataLinkKey];
|
|
26581
26581
|
return {
|
|
26582
|
-
...dataLinkData,
|
|
26583
26582
|
...d,
|
|
26583
|
+
...dataLinkData,
|
|
26584
26584
|
dataLinkKey: undefined
|
|
26585
26585
|
};
|
|
26586
26586
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "datastake-daf",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.461",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@ant-design/icons": "^5.2.5",
|
|
6
6
|
"@antv/g2": "^5.1.1",
|
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
"datastake-daf": "^0.6.378",
|
|
19
19
|
"dayjs": "^1.11.12",
|
|
20
20
|
"deepmerge": "^4.3.1",
|
|
21
|
+
"docx": "^9.5.1",
|
|
22
|
+
"docx-preview": "^0.3.7",
|
|
21
23
|
"dot-object": "^2.1.5",
|
|
24
|
+
"file-saver": "^2.0.5",
|
|
22
25
|
"leaflet": "^1.0.3",
|
|
23
26
|
"leaflet-editable": "^1.3.0",
|
|
24
27
|
"leaflet-geosearch": "^3.1.0",
|
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import WordDocumentPreview from "./index";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
title: "Core/Document/WordDocument",
|
|
5
|
+
component: WordDocumentPreview,
|
|
6
|
+
tags: ["autodocs"],
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const Primary = {
|
|
10
|
+
name: "WordDocument",
|
|
11
|
+
args: {
|
|
12
|
+
title: "React Word Document Example",
|
|
13
|
+
content: "This is a sample Word document created with docx library.",
|
|
14
|
+
fileName: "document.docx",
|
|
15
|
+
config: [
|
|
16
|
+
{
|
|
17
|
+
type: 'paragraph',
|
|
18
|
+
data: "This is a sample Word document created with docx library.",
|
|
19
|
+
meta: { bold: true, size: 32 },
|
|
20
|
+
style: {
|
|
21
|
+
spacing: { before: 200 }
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const CustomTitle = {
|
|
29
|
+
name: "Custom Title",
|
|
30
|
+
args: {
|
|
31
|
+
title: "My Custom Document Title",
|
|
32
|
+
content: "This document has a custom title and content. You can modify these props in Storybook!",
|
|
33
|
+
fileName: "custom-document.docx"
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const AllTypes = {
|
|
38
|
+
name: "All Element Types",
|
|
39
|
+
args: {
|
|
40
|
+
title: "Document with All Element Types",
|
|
41
|
+
content: "A comprehensive example showing all supported element types.",
|
|
42
|
+
fileName: "all-types-example.docx",
|
|
43
|
+
config: [
|
|
44
|
+
// Heading Example
|
|
45
|
+
{
|
|
46
|
+
type: 'heading',
|
|
47
|
+
data: 'Main Document Title',
|
|
48
|
+
style: {
|
|
49
|
+
heading: 'HEADING_1', // HeadingLevel.HEADING_1
|
|
50
|
+
spacing: { after: 200 }
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
// Paragraph Example
|
|
54
|
+
{
|
|
55
|
+
type: 'paragraph',
|
|
56
|
+
data: 'This is a regular paragraph with normal text. It demonstrates the paragraph type.',
|
|
57
|
+
meta: { size: 24 },
|
|
58
|
+
style: {
|
|
59
|
+
spacing: { after: 100 }
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
// Paragraph with Bold Text
|
|
63
|
+
{
|
|
64
|
+
type: 'paragraph',
|
|
65
|
+
data: 'This is a bold paragraph.',
|
|
66
|
+
meta: { bold: true, size: 24 },
|
|
67
|
+
style: {
|
|
68
|
+
spacing: { after: 100 }
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
// TextRun Example
|
|
72
|
+
{
|
|
73
|
+
type: 'textRun',
|
|
74
|
+
data: 'This is a text run with italic styling.',
|
|
75
|
+
meta: { italic: true, size: 22, color: '0000FF' },
|
|
76
|
+
style: {
|
|
77
|
+
spacing: { after: 100 }
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
// Heading Level 2
|
|
81
|
+
{
|
|
82
|
+
type: 'heading',
|
|
83
|
+
data: 'Lists Section',
|
|
84
|
+
style: {
|
|
85
|
+
heading: 'HEADING_2',
|
|
86
|
+
spacing: { before: 300, after: 200 }
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
// Bullet List Example
|
|
90
|
+
{
|
|
91
|
+
type: 'bulletList',
|
|
92
|
+
data: 'First bullet point',
|
|
93
|
+
style: {
|
|
94
|
+
level: 0,
|
|
95
|
+
spacing: { after: 50 }
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
type: 'bulletList',
|
|
100
|
+
data: 'Second bullet point',
|
|
101
|
+
style: {
|
|
102
|
+
level: 0,
|
|
103
|
+
spacing: { after: 50 }
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
type: 'bulletList',
|
|
108
|
+
data: 'Nested bullet point',
|
|
109
|
+
style: {
|
|
110
|
+
level: 1,
|
|
111
|
+
spacing: { after: 100 }
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
// Numbered List Example
|
|
115
|
+
{
|
|
116
|
+
type: 'numberedList',
|
|
117
|
+
data: 'First numbered item',
|
|
118
|
+
style: {
|
|
119
|
+
reference: 'default-numbering',
|
|
120
|
+
level: 0,
|
|
121
|
+
spacing: { after: 50 }
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
type: 'numberedList',
|
|
126
|
+
data: 'Second numbered item',
|
|
127
|
+
style: {
|
|
128
|
+
reference: 'default-numbering',
|
|
129
|
+
level: 0,
|
|
130
|
+
spacing: { after: 100 }
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
// Heading for Table Section
|
|
134
|
+
{
|
|
135
|
+
type: 'heading',
|
|
136
|
+
data: 'Table Section',
|
|
137
|
+
style: {
|
|
138
|
+
heading: 'HEADING_2',
|
|
139
|
+
spacing: { before: 300, after: 200 }
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
// Table Example
|
|
143
|
+
{
|
|
144
|
+
type: 'table',
|
|
145
|
+
data: [
|
|
146
|
+
['Header 1', 'Header 2', 'Header 3'],
|
|
147
|
+
['Row 1, Cell 1', 'Row 1, Cell 2', 'Row 1, Cell 3'],
|
|
148
|
+
['Row 2, Cell 1', 'Row 2, Cell 2', 'Row 2, Cell 3'],
|
|
149
|
+
['Row 3, Cell 1', 'Row 3, Cell 2', 'Row 3, Cell 3']
|
|
150
|
+
],
|
|
151
|
+
style: {
|
|
152
|
+
width: {
|
|
153
|
+
size: 100,
|
|
154
|
+
type: 'pct'
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
// Page Break Example
|
|
159
|
+
{
|
|
160
|
+
type: 'pageBreak'
|
|
161
|
+
},
|
|
162
|
+
// Content after page break
|
|
163
|
+
{
|
|
164
|
+
type: 'heading',
|
|
165
|
+
data: 'Page 2 - After Page Break',
|
|
166
|
+
style: {
|
|
167
|
+
heading: 'HEADING_1',
|
|
168
|
+
spacing: { after: 200 }
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
type: 'paragraph',
|
|
173
|
+
data: 'This content appears on a new page after the page break.',
|
|
174
|
+
meta: { size: 24 },
|
|
175
|
+
style: {
|
|
176
|
+
spacing: { after: 100 }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
]
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export const HeadingExample = {
|
|
184
|
+
name: "Heading Types",
|
|
185
|
+
args: {
|
|
186
|
+
title: "Heading Examples",
|
|
187
|
+
fileName: "headings-example.docx",
|
|
188
|
+
config: [
|
|
189
|
+
{
|
|
190
|
+
type: 'heading',
|
|
191
|
+
data: 'Heading Level 1',
|
|
192
|
+
style: { heading: 'HEADING_1', spacing: { after: 200 } }
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
type: 'heading',
|
|
196
|
+
data: 'Heading Level 2',
|
|
197
|
+
style: { heading: 'HEADING_2', spacing: { after: 200 } }
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
type: 'heading',
|
|
201
|
+
data: 'Heading Level 3',
|
|
202
|
+
style: { heading: 'HEADING_3', spacing: { after: 200 } }
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export const TableExample = {
|
|
209
|
+
name: "Table Example",
|
|
210
|
+
args: {
|
|
211
|
+
title: "Table Document",
|
|
212
|
+
fileName: "table-example.docx",
|
|
213
|
+
config: [
|
|
214
|
+
{
|
|
215
|
+
type: 'heading',
|
|
216
|
+
data: 'Employee Data',
|
|
217
|
+
style: { heading: 'HEADING_1', spacing: { after: 200 } }
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
type: 'table',
|
|
221
|
+
data: [
|
|
222
|
+
['Employee ID', 'Name', 'Department', 'Salary'],
|
|
223
|
+
['001', 'John Doe', 'Engineering', '$75,000'],
|
|
224
|
+
['002', 'Jane Smith', 'Marketing', '$65,000'],
|
|
225
|
+
['003', 'Bob Johnson', 'Sales', '$70,000']
|
|
226
|
+
]
|
|
227
|
+
}
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
export const ListsExample = {
|
|
233
|
+
name: "Lists Example",
|
|
234
|
+
args: {
|
|
235
|
+
title: "Lists Document",
|
|
236
|
+
fileName: "lists-example.docx",
|
|
237
|
+
config: [
|
|
238
|
+
{
|
|
239
|
+
type: 'heading',
|
|
240
|
+
data: 'Shopping List (Bullets)',
|
|
241
|
+
style: { heading: 'HEADING_2', spacing: { after: 200 } }
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
type: 'bulletList',
|
|
245
|
+
data: 'Milk',
|
|
246
|
+
style: { level: 0 }
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
type: 'bulletList',
|
|
250
|
+
data: 'Bread',
|
|
251
|
+
style: { level: 0 }
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
type: 'bulletList',
|
|
255
|
+
data: 'Eggs',
|
|
256
|
+
style: { level: 0 }
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
type: 'heading',
|
|
260
|
+
data: 'Instructions (Numbered)',
|
|
261
|
+
style: { heading: 'HEADING_2', spacing: { before: 300, after: 200 } }
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
type: 'numberedList',
|
|
265
|
+
data: 'Preheat oven to 350°F',
|
|
266
|
+
style: { reference: 'default-numbering', level: 0 }
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
type: 'numberedList',
|
|
270
|
+
data: 'Mix ingredients in a bowl',
|
|
271
|
+
style: { reference: 'default-numbering', level: 0 }
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
type: 'numberedList',
|
|
275
|
+
data: 'Bake for 25 minutes',
|
|
276
|
+
style: { reference: 'default-numbering', level: 0 }
|
|
277
|
+
}
|
|
278
|
+
]
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
export const ReportTemplate = {
|
|
283
|
+
name: "Report Template (Like Image)",
|
|
284
|
+
args: {
|
|
285
|
+
title: "Inspection Report",
|
|
286
|
+
fileName: "inspection-report.docx",
|
|
287
|
+
config: [
|
|
288
|
+
// Image with Text Section 1
|
|
289
|
+
{
|
|
290
|
+
type: 'imageWithText',
|
|
291
|
+
data: {
|
|
292
|
+
imageTitle: 'Facility Overview - Main Entrance',
|
|
293
|
+
// Sample industrial facility image from Unsplash
|
|
294
|
+
imageUrl: 'https://images.unsplash.com/photo-1581094794329-c8112a89af12?w=600&h=400&fit=crop',
|
|
295
|
+
image: null, // Will be populated from imageUrl
|
|
296
|
+
imageWidth: 280,
|
|
297
|
+
imageHeight: 200,
|
|
298
|
+
text: 'Main entrance facility showing security gates and access control points. Observation date: 2025-10-13. Weather conditions: Clear. Temperature: 22°C.'
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
// Image with Text Section 2 - Image on RIGHT side
|
|
302
|
+
{
|
|
303
|
+
type: 'imageWithText',
|
|
304
|
+
data: {
|
|
305
|
+
imageTitle: 'Storage Area - Chemical Warehouse',
|
|
306
|
+
// Sample warehouse image from Unsplash
|
|
307
|
+
imageUrl: 'https://images.unsplash.com/photo-1553413077-190dd305871c?w=600&h=400&fit=crop',
|
|
308
|
+
image: null, // Will be populated from imageUrl
|
|
309
|
+
imageWidth: 280,
|
|
310
|
+
imageHeight: 200,
|
|
311
|
+
imagePosition: 'right', // Image on the right, text on the left
|
|
312
|
+
text: 'Chemical storage warehouse with proper ventilation and safety signage. All containers are properly labeled. Emergency equipment is accessible and well-maintained.'
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
// Main Takeaways Section with Border
|
|
316
|
+
{
|
|
317
|
+
type: 'borderedSection',
|
|
318
|
+
data: {
|
|
319
|
+
title: 'Provide your main takeaways here',
|
|
320
|
+
content: 'Editable - to be filled by the user\n\nThis is a bordered section where the user can add their main observations and conclusions from the inspection.'
|
|
321
|
+
},
|
|
322
|
+
style: {
|
|
323
|
+
margins: {
|
|
324
|
+
top: 300,
|
|
325
|
+
bottom: 300
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
// Mercury Management Section with percentage
|
|
330
|
+
{
|
|
331
|
+
type: 'commentSection',
|
|
332
|
+
data: {
|
|
333
|
+
title: 'Mercury management',
|
|
334
|
+
percentage: 51,
|
|
335
|
+
description: 'Automatic filled by comments contained in associated sub-criteria - editable',
|
|
336
|
+
comments: [
|
|
337
|
+
'Mercury storage areas are properly labeled and secured with restricted access',
|
|
338
|
+
'Safety protocols are documented and clearly displayed in work areas',
|
|
339
|
+
'Regular monitoring of mercury levels is conducted with weekly reports',
|
|
340
|
+
'Emergency response kits are available and inspected monthly',
|
|
341
|
+
'Staff training records are up to date for all personnel handling mercury'
|
|
342
|
+
]
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
// Cyanide Management Section with percentage
|
|
346
|
+
{
|
|
347
|
+
type: 'commentSection',
|
|
348
|
+
data: {
|
|
349
|
+
title: 'Cyanide management',
|
|
350
|
+
percentage: 51,
|
|
351
|
+
description: 'Automatic filled by comments contained in associated sub-criteria - editable',
|
|
352
|
+
comments: [
|
|
353
|
+
'Cyanide storage facilities meet international safety standards',
|
|
354
|
+
'Emergency response procedures are documented and regularly tested',
|
|
355
|
+
'Staff training on cyanide safety is up to date and comprehensive',
|
|
356
|
+
'Proper ventilation systems are installed and functioning correctly',
|
|
357
|
+
'Neutralization agents are stored nearby and easily accessible'
|
|
358
|
+
]
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
// Page Break
|
|
362
|
+
// {
|
|
363
|
+
// type: 'pageBreak'
|
|
364
|
+
// },
|
|
365
|
+
// Climate Change Section on new page
|
|
366
|
+
{
|
|
367
|
+
type: 'commentSection',
|
|
368
|
+
data: {
|
|
369
|
+
title: 'Climate change',
|
|
370
|
+
percentage: 51,
|
|
371
|
+
description: 'Automatic filled by comments contained in associated sub-criteria - editable',
|
|
372
|
+
comments: [
|
|
373
|
+
'Carbon emission reduction strategies are actively implemented',
|
|
374
|
+
'Energy efficiency measures have reduced consumption by 15% year-over-year',
|
|
375
|
+
'Renewable energy sources provide 30% of total energy requirements',
|
|
376
|
+
'Water conservation programs are in place with recycling systems',
|
|
377
|
+
'Environmental impact assessments are conducted quarterly'
|
|
378
|
+
]
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
]
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
export const ImageWithTextExample = {
|
|
386
|
+
name: "Image With Text Layout",
|
|
387
|
+
args: {
|
|
388
|
+
title: "Image and Text Layout Example",
|
|
389
|
+
fileName: "image-text-layout.docx",
|
|
390
|
+
config: [
|
|
391
|
+
{
|
|
392
|
+
type: 'imageWithText',
|
|
393
|
+
data: {
|
|
394
|
+
imageTitle: 'Image on Left Side',
|
|
395
|
+
// Sample office/building image from Unsplash
|
|
396
|
+
imageUrl: 'https://images.unsplash.com/photo-1486406146926-c627a92ad1ab?w=600&h=400&fit=crop',
|
|
397
|
+
image: null,
|
|
398
|
+
imageWidth: 300,
|
|
399
|
+
imageHeight: 200,
|
|
400
|
+
imagePosition: 'left', // Default: image on left
|
|
401
|
+
text: 'This is a two-column layout with the image on the LEFT side and text on the right. Both columns have borders.'
|
|
402
|
+
}
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
type: 'imageWithText',
|
|
406
|
+
data: {
|
|
407
|
+
imageTitle: 'Image on Right Side',
|
|
408
|
+
// Sample technology image from Unsplash
|
|
409
|
+
imageUrl: 'https://images.unsplash.com/photo-1451187580459-43490279c0fa?w=600&h=400&fit=crop',
|
|
410
|
+
image: null,
|
|
411
|
+
imageWidth: 300,
|
|
412
|
+
imageHeight: 200,
|
|
413
|
+
imagePosition: 'right', // Image on right
|
|
414
|
+
text: 'This shows the same two-column layout but with the image on the RIGHT side and text on the left. You can alternate the positions for visual variety.'
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
]
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
export const BorderedSectionExample = {
|
|
422
|
+
name: "Bordered Section Example",
|
|
423
|
+
args: {
|
|
424
|
+
title: "Bordered Section Example",
|
|
425
|
+
fileName: "bordered-section.docx",
|
|
426
|
+
config: [
|
|
427
|
+
{
|
|
428
|
+
type: 'borderedSection',
|
|
429
|
+
data: {
|
|
430
|
+
title: 'Important Notice',
|
|
431
|
+
content: 'This is a bordered section with a gray background. It can be used for editable areas, important notices, or user input fields.'
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
]
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
export const CommentSectionExample = {
|
|
439
|
+
name: "Comment Section Example",
|
|
440
|
+
args: {
|
|
441
|
+
title: "Comment Section Example",
|
|
442
|
+
fileName: "comment-section.docx",
|
|
443
|
+
config: [
|
|
444
|
+
{
|
|
445
|
+
type: 'commentSection',
|
|
446
|
+
data: {
|
|
447
|
+
title: 'Legitimacy of ASM',
|
|
448
|
+
percentage: 51,
|
|
449
|
+
description: 'Automatic filled by comments contained in associated sub-criteria - editable',
|
|
450
|
+
comments: []
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
type: 'commentSection',
|
|
455
|
+
data: {
|
|
456
|
+
title: 'Ensure traceability',
|
|
457
|
+
percentage: 51,
|
|
458
|
+
comments: [
|
|
459
|
+
'Comment 1',
|
|
460
|
+
'Comment 2',
|
|
461
|
+
'Comment 3',
|
|
462
|
+
'...'
|
|
463
|
+
]
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
type: 'commentSection',
|
|
468
|
+
data: {
|
|
469
|
+
title: 'ASM Companies',
|
|
470
|
+
percentage: 51,
|
|
471
|
+
description: 'Automatic filled by comments contained in associated sub-criteria - editable',
|
|
472
|
+
comments: [
|
|
473
|
+
'Comment 1',
|
|
474
|
+
'Comment 2',
|
|
475
|
+
'Comment 3',
|
|
476
|
+
'...'
|
|
477
|
+
]
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
type: 'commentSection',
|
|
482
|
+
data: {
|
|
483
|
+
title: 'Armed conflict',
|
|
484
|
+
percentage: 51,
|
|
485
|
+
description: 'Automatic filled by comments contained in associated sub-criteria - editable',
|
|
486
|
+
comments: []
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
]
|
|
490
|
+
}
|
|
491
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { Packer } from 'docx';
|
|
3
|
+
import { saveAs } from 'file-saver';
|
|
4
|
+
import { renderAsync } from 'docx-preview';
|
|
5
|
+
import createDocument from '../createDocument';
|
|
6
|
+
|
|
7
|
+
const WordDocumentPreview = ({ title = "React Word Document Example", content = "This is a sample Word document created with docx library.", fileName = "document.docx", config = [] }) => {
|
|
8
|
+
const previewRef = useRef(null);
|
|
9
|
+
|
|
10
|
+
// Helper function to fetch image from URL and convert to buffer
|
|
11
|
+
const fetchImageAsBuffer = async (url) => {
|
|
12
|
+
try {
|
|
13
|
+
const response = await fetch(url);
|
|
14
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
15
|
+
return arrayBuffer;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.error('Error fetching image:', error);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Process config to fetch images from URLs
|
|
23
|
+
const processConfig = async (configArray) => {
|
|
24
|
+
const processedConfig = await Promise.all(
|
|
25
|
+
configArray.map(async (item) => {
|
|
26
|
+
if (item.type === 'imageWithText' && item.data?.imageUrl && !item.data.image) {
|
|
27
|
+
const imageBuffer = await fetchImageAsBuffer(item.data.imageUrl);
|
|
28
|
+
return {
|
|
29
|
+
...item,
|
|
30
|
+
data: {
|
|
31
|
+
...item.data,
|
|
32
|
+
image: imageBuffer
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return item;
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
return processedConfig;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const downloadDocument = async () => {
|
|
43
|
+
const processedConfig = await processConfig(config);
|
|
44
|
+
const doc = createDocument({ title, content, config: processedConfig });
|
|
45
|
+
const blob = await Packer.toBlob(doc);
|
|
46
|
+
saveAs(blob, fileName);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const renderPreview = async () => {
|
|
51
|
+
if (previewRef.current) {
|
|
52
|
+
const processedConfig = await processConfig(config);
|
|
53
|
+
const doc = createDocument({ title, content, config: processedConfig });
|
|
54
|
+
const blob = await Packer.toBlob(doc);
|
|
55
|
+
|
|
56
|
+
await renderAsync(blob, previewRef.current, null, {
|
|
57
|
+
className: "docx-preview",
|
|
58
|
+
inWrapper: true,
|
|
59
|
+
ignoreWidth: false,
|
|
60
|
+
ignoreHeight: false,
|
|
61
|
+
renderHeaders: true,
|
|
62
|
+
renderFooters: true,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
renderPreview();
|
|
68
|
+
}, [title, content, config]);
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<div style={{ padding: '20px' }}>
|
|
72
|
+
<div style={{ marginBottom: '20px' }}>
|
|
73
|
+
<button
|
|
74
|
+
onClick={downloadDocument}
|
|
75
|
+
style={{
|
|
76
|
+
padding: '10px 20px',
|
|
77
|
+
fontSize: '16px',
|
|
78
|
+
backgroundColor: '#4CAF50',
|
|
79
|
+
color: 'white',
|
|
80
|
+
border: 'none',
|
|
81
|
+
borderRadius: '4px',
|
|
82
|
+
cursor: 'pointer'
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
Download Word Document
|
|
86
|
+
</button>
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
<div
|
|
90
|
+
ref={previewRef}
|
|
91
|
+
style={{
|
|
92
|
+
border: '1px solid #ddd',
|
|
93
|
+
borderRadius: '4px',
|
|
94
|
+
padding: '20px',
|
|
95
|
+
backgroundColor: 'white',
|
|
96
|
+
minHeight: '400px',
|
|
97
|
+
maxWidth: '800px'
|
|
98
|
+
}}
|
|
99
|
+
/>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export default WordDocumentPreview;
|