@visns-studio/visns-components 4.10.24 → 4.10.26
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
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
78
78
|
},
|
|
79
79
|
"name": "@visns-studio/visns-components",
|
|
80
|
-
"version": "4.10.
|
|
80
|
+
"version": "4.10.26",
|
|
81
81
|
"description": "Various packages to assist in the development of our Custom Applications.",
|
|
82
82
|
"main": "src/index.js",
|
|
83
83
|
"files": [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
1
|
+
import React, { useEffect, useState, useRef } from 'react';
|
|
2
2
|
import CustomFetch from './Fetch';
|
|
3
3
|
import SelectList from './SelectList';
|
|
4
4
|
import Select, { createFilter } from 'react-select';
|
|
@@ -19,6 +19,7 @@ function MultiSelect({
|
|
|
19
19
|
}) {
|
|
20
20
|
const [selectOptions, setSelectOptions] = useState([]);
|
|
21
21
|
const [selectValue, setSelectValue] = useState([]);
|
|
22
|
+
const prevInputValueRef = useRef();
|
|
22
23
|
|
|
23
24
|
useEffect(() => {
|
|
24
25
|
const _options = Array.isArray(options)
|
|
@@ -32,14 +33,34 @@ function MultiSelect({
|
|
|
32
33
|
}, [options]);
|
|
33
34
|
|
|
34
35
|
useEffect(() => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
// Only update if `inputValue` content has changed
|
|
37
|
+
if (
|
|
38
|
+
JSON.stringify(prevInputValueRef.current) !==
|
|
39
|
+
JSON.stringify(inputValue)
|
|
40
|
+
) {
|
|
41
|
+
const _values = Array.isArray(inputValue)
|
|
42
|
+
? inputValue.map((a) => ({
|
|
43
|
+
value: a.id,
|
|
44
|
+
label: a.label || a.name || a.description || 'Unknown',
|
|
45
|
+
...a,
|
|
46
|
+
}))
|
|
47
|
+
: inputValue && typeof inputValue === 'object'
|
|
48
|
+
? [
|
|
49
|
+
{
|
|
50
|
+
value: inputValue.id,
|
|
51
|
+
label:
|
|
52
|
+
inputValue.label ||
|
|
53
|
+
inputValue.name ||
|
|
54
|
+
inputValue.description ||
|
|
55
|
+
'Unknown',
|
|
56
|
+
...inputValue,
|
|
57
|
+
},
|
|
58
|
+
]
|
|
59
|
+
: [];
|
|
60
|
+
|
|
61
|
+
setSelectValue(_values);
|
|
62
|
+
prevInputValueRef.current = inputValue;
|
|
63
|
+
}
|
|
43
64
|
}, [inputValue]);
|
|
44
65
|
|
|
45
66
|
const handleCreate = async (inputValue) => {
|
|
@@ -87,14 +87,47 @@ class SketchField extends PureComponent {
|
|
|
87
87
|
crossOrigin: 'anonymous', // Enable CORS
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
+
const imgWidth = img.width;
|
|
91
|
+
const imgHeight = img.height;
|
|
92
|
+
|
|
93
|
+
// Get the aspect ratio of the image
|
|
94
|
+
const aspectRatio = imgWidth / imgHeight;
|
|
95
|
+
|
|
96
|
+
// Calculate the new canvas dimensions based on aspect ratio
|
|
97
|
+
const { width, height } = this.props; // Default width and height
|
|
98
|
+
|
|
99
|
+
let newWidth, newHeight;
|
|
100
|
+
if (aspectRatio > 1) {
|
|
101
|
+
// Landscape orientation: Set width to max and adjust height
|
|
102
|
+
newWidth = width;
|
|
103
|
+
newHeight = width / aspectRatio;
|
|
104
|
+
} else {
|
|
105
|
+
// Portrait orientation: Set height to max and adjust width
|
|
106
|
+
newHeight = height;
|
|
107
|
+
newWidth = height * aspectRatio;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Set the new canvas dimensions
|
|
111
|
+
this._fc.setWidth(newWidth);
|
|
112
|
+
this._fc.setHeight(newHeight);
|
|
113
|
+
|
|
90
114
|
// Scale the image to fit the canvas dimensions
|
|
91
|
-
img.scaleToWidth(
|
|
92
|
-
img.scaleToHeight(
|
|
93
|
-
|
|
115
|
+
img.scaleToWidth(newWidth);
|
|
116
|
+
img.scaleToHeight(newHeight);
|
|
117
|
+
|
|
118
|
+
// Center the image both horizontally and vertically
|
|
119
|
+
img.set({
|
|
120
|
+
left: (newWidth - img.getScaledWidth()) / 2,
|
|
121
|
+
top: (newHeight - img.getScaledHeight()) / 2,
|
|
122
|
+
selectable: false,
|
|
123
|
+
evented: false,
|
|
124
|
+
});
|
|
94
125
|
|
|
95
|
-
// Set the image
|
|
126
|
+
// Set the image as the background directly
|
|
96
127
|
this._fc.backgroundImage = img;
|
|
97
|
-
|
|
128
|
+
|
|
129
|
+
// Render the canvas to apply changes
|
|
130
|
+
this._fc.requestRenderAll();
|
|
98
131
|
} catch (error) {
|
|
99
132
|
console.error('Failed to load background image:', error);
|
|
100
133
|
}
|
|
@@ -193,6 +226,8 @@ class SketchField extends PureComponent {
|
|
|
193
226
|
}
|
|
194
227
|
} else {
|
|
195
228
|
this._fc.clear(); // If no previous state, clear the canvas
|
|
229
|
+
|
|
230
|
+
this.setBackgroundImage(this.props.backgroundImage);
|
|
196
231
|
}
|
|
197
232
|
this._fc.renderAll(); // Re-render canvas
|
|
198
233
|
this.props.onChange && this.props.onChange();
|
|
@@ -271,7 +306,6 @@ class SketchField extends PureComponent {
|
|
|
271
306
|
|
|
272
307
|
// Load the defaultValue to set the initial state of the canvas
|
|
273
308
|
if (defaultValue) {
|
|
274
|
-
console.info('test');
|
|
275
309
|
// Show loading toast
|
|
276
310
|
const toastId = toast.loading('Loading Canvas...');
|
|
277
311
|
setTimeout(() => {
|
|
@@ -334,10 +368,6 @@ class SketchField extends PureComponent {
|
|
|
334
368
|
this.fromJSON(this.props.defaultValue);
|
|
335
369
|
} else {
|
|
336
370
|
if (this.props.backgroundImage !== prevProps.backgroundImage) {
|
|
337
|
-
// console.log(
|
|
338
|
-
// 'Setting new background image:',
|
|
339
|
-
// this.props.backgroundImage
|
|
340
|
-
// );
|
|
341
371
|
this.setBackgroundImage(this.props.backgroundImage);
|
|
342
372
|
}
|
|
343
373
|
}
|