@visns-studio/visns-components 4.10.23 → 4.10.25
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.25",
|
|
81
81
|
"description": "Various packages to assist in the development of our Custom Applications.",
|
|
82
82
|
"main": "src/index.js",
|
|
83
83
|
"files": [
|
|
@@ -1030,6 +1030,16 @@ function Field({
|
|
|
1030
1030
|
}
|
|
1031
1031
|
dataOptions={dataOptions}
|
|
1032
1032
|
style={style}
|
|
1033
|
+
isCreatable={
|
|
1034
|
+
settings.hasOwnProperty('isCreatable')
|
|
1035
|
+
? settings.isCreatable
|
|
1036
|
+
: false
|
|
1037
|
+
}
|
|
1038
|
+
creatableConfig={
|
|
1039
|
+
settings.hasOwnProperty('creatableConfig')
|
|
1040
|
+
? settings.creatableConfig
|
|
1041
|
+
: {}
|
|
1042
|
+
}
|
|
1033
1043
|
/>
|
|
1034
1044
|
{settings.create && (
|
|
1035
1045
|
<button
|
|
@@ -1,80 +1,73 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import CustomFetch from './Fetch';
|
|
2
3
|
import SelectList from './SelectList';
|
|
3
4
|
import Select, { createFilter } from 'react-select';
|
|
5
|
+
import CreatableSelect from 'react-select/creatable';
|
|
4
6
|
import styles from './styles/AsyncSelect.module.scss';
|
|
5
7
|
|
|
6
8
|
function MultiSelect({
|
|
7
9
|
className,
|
|
8
|
-
inputValue,
|
|
10
|
+
inputValue = [], // Default to an empty array
|
|
9
11
|
multi,
|
|
10
12
|
onChange,
|
|
11
|
-
options,
|
|
13
|
+
options = [], // Default to an empty array
|
|
12
14
|
placeholder,
|
|
13
15
|
settings,
|
|
14
16
|
style,
|
|
17
|
+
isCreatable = false,
|
|
18
|
+
creatableConfig = {},
|
|
15
19
|
}) {
|
|
16
20
|
const [selectOptions, setSelectOptions] = useState([]);
|
|
17
21
|
const [selectValue, setSelectValue] = useState([]);
|
|
18
22
|
|
|
19
23
|
useEffect(() => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
label: labelValue,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
Object.keys(a).forEach((b) => {
|
|
32
|
-
if (b !== 'id' && b !== 'label') {
|
|
33
|
-
_optionItem = {
|
|
34
|
-
..._optionItem,
|
|
35
|
-
[b]: a[b],
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
_options.push(_optionItem);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
setSelectOptions(_options);
|
|
44
|
-
}
|
|
24
|
+
const _options = Array.isArray(options)
|
|
25
|
+
? options.map((a) => ({
|
|
26
|
+
value: a.id,
|
|
27
|
+
label: a.label || a.name || a.description || 'Unknown',
|
|
28
|
+
...a,
|
|
29
|
+
}))
|
|
30
|
+
: [];
|
|
31
|
+
setSelectOptions(_options);
|
|
45
32
|
}, [options]);
|
|
46
33
|
|
|
47
34
|
useEffect(() => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
};
|
|
35
|
+
const _values = Array.isArray(inputValue)
|
|
36
|
+
? inputValue.map((a) => ({
|
|
37
|
+
value: a.id,
|
|
38
|
+
label: a.label || a.name || a.description || 'Unknown',
|
|
39
|
+
...a,
|
|
40
|
+
}))
|
|
41
|
+
: [];
|
|
42
|
+
setSelectValue(_values);
|
|
43
|
+
}, [inputValue]);
|
|
58
44
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
45
|
+
const handleCreate = async (inputValue) => {
|
|
46
|
+
if (creatableConfig.url && creatableConfig.method) {
|
|
47
|
+
const res = await CustomFetch(
|
|
48
|
+
creatableConfig.url,
|
|
49
|
+
creatableConfig.method,
|
|
50
|
+
{ label: inputValue }
|
|
51
|
+
);
|
|
67
52
|
|
|
68
|
-
|
|
69
|
-
|
|
53
|
+
if (res && res.data) {
|
|
54
|
+
const newOption = {
|
|
55
|
+
value: res.data.id,
|
|
56
|
+
label: res.data.label || inputValue,
|
|
57
|
+
...res.data,
|
|
58
|
+
};
|
|
70
59
|
|
|
71
|
-
|
|
60
|
+
setSelectOptions((prevOptions) => [...prevOptions, newOption]);
|
|
61
|
+
setSelectValue((prevValues) => [...prevValues, newOption]);
|
|
62
|
+
}
|
|
72
63
|
}
|
|
73
|
-
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const SelectComponent = isCreatable ? CreatableSelect : Select;
|
|
74
67
|
|
|
75
68
|
return (
|
|
76
|
-
<
|
|
77
|
-
closeMenuOnSelect={multi
|
|
69
|
+
<SelectComponent
|
|
70
|
+
closeMenuOnSelect={!multi}
|
|
78
71
|
isClearable
|
|
79
72
|
isSearchable
|
|
80
73
|
isMulti={multi}
|
|
@@ -101,6 +94,7 @@ function MultiSelect({
|
|
|
101
94
|
}),
|
|
102
95
|
}}
|
|
103
96
|
value={selectValue}
|
|
97
|
+
onCreateOption={handleCreate}
|
|
104
98
|
placeholder={placeholder ? placeholder : 'Select...'}
|
|
105
99
|
/>
|
|
106
100
|
);
|
|
@@ -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
|
}
|