@dvrd/dvr-controls 1.0.22 → 1.0.24
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dvrd/dvr-controls",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24",
|
|
4
4
|
"description": "Custom web controls",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"files": [
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"2": "ie >= 11"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@fortawesome/fontawesome-svg-core": "6.
|
|
22
|
-
"@fortawesome/free-brands-svg-icons": "
|
|
23
|
-
"@fortawesome/free-regular-svg-icons": "
|
|
24
|
-
"@fortawesome/free-solid-svg-icons": "6.
|
|
21
|
+
"@fortawesome/fontawesome-svg-core": "6.3.0",
|
|
22
|
+
"@fortawesome/free-brands-svg-icons": "6.3.0",
|
|
23
|
+
"@fortawesome/free-regular-svg-icons": "6.3.0",
|
|
24
|
+
"@fortawesome/free-solid-svg-icons": "6.3.0",
|
|
25
25
|
"@fortawesome/react-fontawesome": "0.2.0",
|
|
26
26
|
"@types/dompurify": "2.4.0",
|
|
27
27
|
"@types/js-cookie": "3.0.2",
|
|
@@ -42,7 +42,6 @@
|
|
|
42
42
|
"react-color": "2.19.3",
|
|
43
43
|
"react-dom": "18.2.0",
|
|
44
44
|
"react-rnd": "10.3.7",
|
|
45
|
-
"react-router": "^6.8.0",
|
|
46
45
|
"react-router-dom": "6.4.3",
|
|
47
46
|
"typescript": "4.9.3",
|
|
48
47
|
"uuid": "9.0.0"
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
directTimeout,
|
|
11
11
|
dispatchCustomEvent,
|
|
12
12
|
DvrdButton,
|
|
13
|
-
generateComponentId,
|
|
14
13
|
generateUUID,
|
|
15
14
|
IndexedObject,
|
|
16
15
|
PDFElementParams,
|
|
@@ -48,10 +47,11 @@ interface Props {
|
|
|
48
47
|
maxWidth?: string;
|
|
49
48
|
supportMultiPage: boolean;
|
|
50
49
|
options?: PDFOptions;
|
|
50
|
+
singleImage: boolean;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
interface State {
|
|
54
|
-
elements: IndexedObject<React.ReactElement>;
|
|
54
|
+
elements: IndexedObject<{ element: React.ReactElement, config: DefaultPDFElementParams<any, any> }>;
|
|
55
55
|
focusedElement: PdfElement | null;
|
|
56
56
|
canUndo: boolean;
|
|
57
57
|
canRedo: boolean;
|
|
@@ -62,25 +62,20 @@ export default class PDFTemplateCreator extends PureComponent<Props, State> {
|
|
|
62
62
|
values: {},
|
|
63
63
|
disableElements: [],
|
|
64
64
|
supportMultiPage: false,
|
|
65
|
+
singleImage: false,
|
|
65
66
|
};
|
|
66
|
-
|
|
67
|
-
private readonly id: string = generateComponentId(this.props.id, true);
|
|
68
67
|
private refObjects: IndexedObject<PdfElement>;
|
|
69
68
|
|
|
70
|
-
state: State = {
|
|
71
|
-
elements: {}, focusedElement: null, canRedo: false, canUndo: false,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
69
|
constructor(props: Props) {
|
|
75
70
|
super(props);
|
|
76
71
|
this.refObjects = {};
|
|
77
|
-
const elements: IndexedObject<React.ReactElement> = this.processItems(props.defaultItems);
|
|
72
|
+
const elements: IndexedObject<{ element: React.ReactElement, config: DefaultPDFElementParams<any, any> }> = this.processItems(props.defaultItems);
|
|
78
73
|
this.state = {elements, focusedElement: null, canRedo: false, canUndo: false};
|
|
79
74
|
}
|
|
80
75
|
|
|
81
76
|
processItems = (items?: DefaultPDFElementParams<any, any>[],
|
|
82
|
-
convertUnits: boolean = true): IndexedObject<React.ReactElement> => {
|
|
83
|
-
const elements: IndexedObject<React.ReactElement> = {};
|
|
77
|
+
convertUnits: boolean = true): IndexedObject<{ element: React.ReactElement, config: DefaultPDFElementParams<any, any> }> => {
|
|
78
|
+
const elements: IndexedObject<{ element: React.ReactElement, config: DefaultPDFElementParams<any, any> }> = {};
|
|
84
79
|
if (items?.length) {
|
|
85
80
|
items = JSON.parse(JSON.stringify(items));
|
|
86
81
|
if (items) {
|
|
@@ -154,12 +149,13 @@ export default class PDFTemplateCreator extends PureComponent<Props, State> {
|
|
|
154
149
|
|
|
155
150
|
onAddElement = (type: PDFElementType) => (evt: React.MouseEvent) => {
|
|
156
151
|
evt.stopPropagation();
|
|
157
|
-
const id = generateUUID()
|
|
158
|
-
|
|
152
|
+
const id = generateUUID();
|
|
153
|
+
const scrollTop = (document.documentElement.scrollTop || document.body.scrollTop) + 50;
|
|
154
|
+
const newElements = Object.assign({}, this.state.elements);
|
|
159
155
|
|
|
160
|
-
|
|
156
|
+
newElements[id] = this.getElement(id,
|
|
161
157
|
{dimensions: {width: 150, height: 100, left: 50, top: scrollTop}, type});
|
|
162
|
-
this.setState({elements:
|
|
158
|
+
this.setState({elements: newElements});
|
|
163
159
|
};
|
|
164
160
|
|
|
165
161
|
onSubmit = () => {
|
|
@@ -189,7 +185,7 @@ export default class PDFTemplateCreator extends PureComponent<Props, State> {
|
|
|
189
185
|
};
|
|
190
186
|
|
|
191
187
|
getElement = (id: string, config: DefaultPDFElementParams<any, any>,
|
|
192
|
-
convertUnits: boolean = true): React.ReactElement => {
|
|
188
|
+
convertUnits: boolean = true): { element: React.ReactElement, config: DefaultPDFElementParams<any, any> } => {
|
|
193
189
|
const {dimensions, linkedID, persistent} = config;
|
|
194
190
|
const position: { x: number; y: number } = {
|
|
195
191
|
x: convertUnits ? ptToPx(dimensions?.left || 0) : (dimensions?.left || 0),
|
|
@@ -212,20 +208,38 @@ export default class PDFTemplateCreator extends PureComponent<Props, State> {
|
|
|
212
208
|
defaultSettings: {...config.dimensions, ...config.options},
|
|
213
209
|
key,
|
|
214
210
|
}
|
|
211
|
+
let element = <div/>;
|
|
215
212
|
switch (config.type) {
|
|
216
213
|
case PDFElementType.TEXT:
|
|
217
|
-
|
|
218
|
-
|
|
214
|
+
element = <PdfText {...sharedProps} values={values} persistent={persistent} mainFont={mainFont}
|
|
215
|
+
linkedID={linkedID}/>;
|
|
216
|
+
break;
|
|
219
217
|
case PDFElementType.IMAGE:
|
|
220
|
-
|
|
221
|
-
|
|
218
|
+
element = <PdfImage {...sharedProps} values={values} width={width} height={height}
|
|
219
|
+
persistent={persistent}/>;
|
|
220
|
+
break;
|
|
222
221
|
case PDFElementType.INVOICE_TABLE:
|
|
223
|
-
|
|
224
|
-
|
|
222
|
+
element = <PdfInvoiceTable {...sharedProps} width={width} height={height} mainFont={mainFont}
|
|
223
|
+
persistent={PDFElementPersist.PERSISTENT}/>;
|
|
224
|
+
break;
|
|
225
225
|
}
|
|
226
|
-
return
|
|
226
|
+
return {element, config};
|
|
227
227
|
};
|
|
228
228
|
|
|
229
|
+
canRenderImageButton = (): boolean => {
|
|
230
|
+
if (this.props.disableElements.includes('image')) return false;
|
|
231
|
+
if (!this.props.singleImage) return true;
|
|
232
|
+
const {elements} = this.state;
|
|
233
|
+
const elementIds = Object.keys(elements);
|
|
234
|
+
if (elementIds.length) {
|
|
235
|
+
for (const id of elementIds) {
|
|
236
|
+
const config = elements[id].config;
|
|
237
|
+
if (config.type === PDFElementType.IMAGE) return false;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
|
|
229
243
|
renderElementButton = (icon: IconName, label: string, type: PDFElementType) => (
|
|
230
244
|
<div className='element-button' onClick={this.onAddElement(type)}>
|
|
231
245
|
<AwesomeIcon name={icon} className='element-icon'/>
|
|
@@ -257,12 +271,13 @@ export default class PDFTemplateCreator extends PureComponent<Props, State> {
|
|
|
257
271
|
<div>
|
|
258
272
|
<DvrdButton onClick={this.onSubmit} label='Opslaan'/>
|
|
259
273
|
{onClickProceed !== undefined &&
|
|
260
|
-
<DvrdButton onClick={this.onClickProceed} label='Naar volgende stap'
|
|
274
|
+
<DvrdButton onClick={this.onClickProceed} label='Naar volgende stap'
|
|
275
|
+
className='proceed-btn'/>}
|
|
261
276
|
</div>
|
|
262
277
|
</div>
|
|
263
278
|
<div/>
|
|
264
279
|
<div className='elements-container'>
|
|
265
|
-
{
|
|
280
|
+
{this.canRenderImageButton() &&
|
|
266
281
|
this.renderElementButton('image', 'Afbeelding', PDFElementType.IMAGE)}
|
|
267
282
|
{!disableElements.includes('text') &&
|
|
268
283
|
this.renderElementButton('font', 'Tekst', PDFElementType.TEXT)}
|
|
@@ -287,7 +302,7 @@ export default class PDFTemplateCreator extends PureComponent<Props, State> {
|
|
|
287
302
|
<div className='pdf-paper' onClick={this.onResetElement}>
|
|
288
303
|
{Object.keys(elements).map((id: string) => (
|
|
289
304
|
<Fragment key={id}>
|
|
290
|
-
{elements[id]}
|
|
305
|
+
{elements[id].element}
|
|
291
306
|
</Fragment>
|
|
292
307
|
))}
|
|
293
308
|
</div>
|