@talxis/base-controls 1.2406.12 → 1.2406.13
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/Lookup-85a4c52d.js +3413 -1
- package/dist/Numeral-a0284afb.js +63 -1
- package/dist/components/DateTime/DateTime.js +302 -1
- package/dist/components/Decimal/Decimal.js +167 -1
- package/dist/components/Duration/Duration.js +180 -1
- package/dist/components/Grid/Grid.js +74619 -2
- package/dist/components/Lookup/Lookup.js +14 -1
- package/dist/components/MultiSelectOptionSet/MultiSelectOptionSet.js +72 -1
- package/dist/components/OptionSet/OptionSet.js +59 -1
- package/dist/components/TextField/TextField.js +86 -1
- package/dist/components/TwoOptions/TwoOptions.js +40 -1
- package/dist/hooks/index.js +6 -1
- package/dist/hooks/useComponent.js +83 -1
- package/dist/hooks/useComponentSizing.js +14 -1
- package/dist/hooks/useFocusIn.js +24 -1
- package/dist/hooks/useInputBasedComponent.js +42 -1
- package/dist/hooks/useMouseOver.js +24 -1
- package/package.json +1 -1
|
@@ -1 +1,14 @@
|
|
|
1
|
-
export{L as Lookup}from
|
|
1
|
+
export { L as Lookup } from '../../Lookup-85a4c52d.js';
|
|
2
|
+
import 'react/jsx-runtime';
|
|
3
|
+
import 'react';
|
|
4
|
+
import '@fluentui/react';
|
|
5
|
+
import '@talxis/react-components/dist/components/TagPicker';
|
|
6
|
+
import '../../hooks/useMouseOver.js';
|
|
7
|
+
import '../../hooks/useFocusIn.js';
|
|
8
|
+
import '../../hooks/useComponentSizing.js';
|
|
9
|
+
import '../../hooks/useComponent.js';
|
|
10
|
+
import 'fast-deep-equal/es6';
|
|
11
|
+
import 'merge-anything';
|
|
12
|
+
import 'liquidjs';
|
|
13
|
+
import '@fluentui/react/lib/Text';
|
|
14
|
+
import '@fluentui/react/lib/components/Button/CommandBarButton/CommandBarButton';
|
|
@@ -1 +1,72 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useComponent } from '../../hooks/useComponent.js';
|
|
3
|
+
import { ComboBox } from '@talxis/react-components/dist/components/ComboBox';
|
|
4
|
+
import { useRef, useEffect } from 'react';
|
|
5
|
+
import 'fast-deep-equal/es6';
|
|
6
|
+
import 'merge-anything';
|
|
7
|
+
import 'liquidjs';
|
|
8
|
+
import '../../hooks/useComponentSizing.js';
|
|
9
|
+
|
|
10
|
+
const MultiSelectOptionSet = (props) => {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const { sizing, onNotifyOutputChanged } = useComponent('MultiSelectOptionSet', props);
|
|
13
|
+
const parameters = props.parameters;
|
|
14
|
+
const boundValue = parameters.value;
|
|
15
|
+
const componentRef = useRef(null);
|
|
16
|
+
const { Options } = parameters.value.attributes;
|
|
17
|
+
const context = props.context;
|
|
18
|
+
const comboBoxOptions = Options.map(option => ({
|
|
19
|
+
key: option.Value.toString(),
|
|
20
|
+
text: option.Label,
|
|
21
|
+
}));
|
|
22
|
+
const handleChange = (option) => {
|
|
23
|
+
if (!option) {
|
|
24
|
+
onNotifyOutputChanged({
|
|
25
|
+
value: undefined
|
|
26
|
+
});
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const optionKey = option.key.toString();
|
|
30
|
+
const updatedSelectedKeys = new Set(boundValue.raw || []);
|
|
31
|
+
if (option.selected) {
|
|
32
|
+
updatedSelectedKeys.add(+optionKey);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
updatedSelectedKeys.delete(+optionKey);
|
|
36
|
+
}
|
|
37
|
+
const updatedSelectedKeysArray = Array.from(updatedSelectedKeys);
|
|
38
|
+
onNotifyOutputChanged({
|
|
39
|
+
value: updatedSelectedKeysArray.map(key => +key)
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
if ((_a = parameters.AutoFocus) === null || _a === void 0 ? void 0 : _a.raw) {
|
|
45
|
+
(_b = componentRef.current) === null || _b === void 0 ? void 0 : _b.focus(true);
|
|
46
|
+
}
|
|
47
|
+
}, []);
|
|
48
|
+
return jsx(ComboBox, { componentRef: componentRef, borderless: ((_a = parameters.EnableBorder) === null || _a === void 0 ? void 0 : _a.raw) === false, options: comboBoxOptions, allowFreeInput: true, multiSelect: true, autoComplete: "on", autofill: ((_b = parameters.AutoFocus) === null || _b === void 0 ? void 0 : _b.raw) === true ? {
|
|
49
|
+
autoFocus: true
|
|
50
|
+
} : undefined, readOnly: context.mode.isControlDisabled, errorMessage: boundValue.errorMessage, selectedKey: boundValue.raw ? boundValue.raw.map(key => key.toString()) : [-1], useComboBoxAsMenuWidth: true, styles: {
|
|
51
|
+
root: {
|
|
52
|
+
height: sizing.height,
|
|
53
|
+
width: sizing.width,
|
|
54
|
+
display: 'flex',
|
|
55
|
+
alignItems: 'center',
|
|
56
|
+
},
|
|
57
|
+
callout: {
|
|
58
|
+
maxHeight: '300px !important'
|
|
59
|
+
}
|
|
60
|
+
}, deleteButtonProps: {
|
|
61
|
+
key: 'delete',
|
|
62
|
+
showOnlyOnHover: false,
|
|
63
|
+
iconProps: {
|
|
64
|
+
iconName: 'Delete'
|
|
65
|
+
},
|
|
66
|
+
onClick: (e, value) => {
|
|
67
|
+
handleChange(null);
|
|
68
|
+
}
|
|
69
|
+
}, onChange: (e, option) => handleChange(option) });
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { MultiSelectOptionSet };
|
|
@@ -1 +1,59 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useComponent } from '../../hooks/useComponent.js';
|
|
3
|
+
import { ComboBox } from '@talxis/react-components/dist/components/ComboBox';
|
|
4
|
+
import { useRef, useEffect } from 'react';
|
|
5
|
+
import 'fast-deep-equal/es6';
|
|
6
|
+
import 'merge-anything';
|
|
7
|
+
import 'liquidjs';
|
|
8
|
+
import '../../hooks/useComponentSizing.js';
|
|
9
|
+
|
|
10
|
+
const OptionSet = (props) => {
|
|
11
|
+
var _a, _b, _c;
|
|
12
|
+
const { sizing, onNotifyOutputChanged } = useComponent('OptionSet', props);
|
|
13
|
+
const componentRef = useRef(null);
|
|
14
|
+
const parameters = props.parameters;
|
|
15
|
+
const boundValue = parameters.value;
|
|
16
|
+
const { Options } = parameters.value.attributes;
|
|
17
|
+
const context = props.context;
|
|
18
|
+
const comboBoxOptions = Options.map(option => ({
|
|
19
|
+
key: option.Value.toString(),
|
|
20
|
+
text: option.Label,
|
|
21
|
+
}));
|
|
22
|
+
const handleChange = (option) => {
|
|
23
|
+
let value = undefined;
|
|
24
|
+
if (option) {
|
|
25
|
+
value = parseInt(option.key);
|
|
26
|
+
}
|
|
27
|
+
onNotifyOutputChanged({
|
|
28
|
+
value: value
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
if ((_a = parameters.AutoFocus) === null || _a === void 0 ? void 0 : _a.raw) {
|
|
34
|
+
(_b = componentRef.current) === null || _b === void 0 ? void 0 : _b.focus(true);
|
|
35
|
+
}
|
|
36
|
+
}, []);
|
|
37
|
+
return jsx(ComboBox, { componentRef: componentRef, borderless: ((_a = parameters.EnableBorder) === null || _a === void 0 ? void 0 : _a.raw) === false, options: comboBoxOptions, readOnly: context.mode.isControlDisabled,
|
|
38
|
+
//the defaultValue comes in the raw prop directly, no need to look at it
|
|
39
|
+
selectedKey: (_c = (_b = boundValue.raw) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : -1, errorMessage: boundValue.errorMessage, useComboBoxAsMenuWidth: true, styles: {
|
|
40
|
+
root: {
|
|
41
|
+
height: sizing.height,
|
|
42
|
+
width: sizing.width,
|
|
43
|
+
display: 'flex',
|
|
44
|
+
alignItems: 'center',
|
|
45
|
+
},
|
|
46
|
+
callout: {
|
|
47
|
+
maxHeight: '300px !important'
|
|
48
|
+
}
|
|
49
|
+
}, deleteButtonProps: {
|
|
50
|
+
key: 'delete',
|
|
51
|
+
showOnlyOnHover: true,
|
|
52
|
+
iconProps: {
|
|
53
|
+
iconName: 'Delete'
|
|
54
|
+
},
|
|
55
|
+
onClick: (e, value) => { handleChange(null); }
|
|
56
|
+
}, onChange: (e, option) => handleChange(option) });
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export { OptionSet };
|
|
@@ -1 +1,86 @@
|
|
|
1
|
-
import{jsx
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { TextField as TextField$1 } from '@talxis/react-components/dist/components/TextField';
|
|
3
|
+
import { useRef, useState, useEffect } from 'react';
|
|
4
|
+
import { useInputBasedComponent } from '../../hooks/useInputBasedComponent.js';
|
|
5
|
+
import '../../hooks/useComponent.js';
|
|
6
|
+
import 'fast-deep-equal/es6';
|
|
7
|
+
import 'merge-anything';
|
|
8
|
+
import 'liquidjs';
|
|
9
|
+
import '../../hooks/useComponentSizing.js';
|
|
10
|
+
|
|
11
|
+
const useTextFieldHeight = (ref, initialHeight, isMultiline) => {
|
|
12
|
+
const getInitialHeight = () => {
|
|
13
|
+
if (initialHeight) {
|
|
14
|
+
return initialHeight;
|
|
15
|
+
}
|
|
16
|
+
if (isMultiline) {
|
|
17
|
+
return 80;
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
};
|
|
21
|
+
const hasBeenResizedRef = useRef(false);
|
|
22
|
+
const [height, setHeight] = useState(getInitialHeight());
|
|
23
|
+
const firstRenderRef = useRef(true);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
var _a;
|
|
26
|
+
if (!isMultiline) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
30
|
+
if (firstRenderRef.current || hasBeenResizedRef.current) {
|
|
31
|
+
firstRenderRef.current = false;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
hasBeenResizedRef.current = true;
|
|
35
|
+
setHeight(undefined);
|
|
36
|
+
});
|
|
37
|
+
const textarea = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.querySelector('textarea');
|
|
38
|
+
if (height) {
|
|
39
|
+
textarea.setAttribute('style', `height: ${height}px`);
|
|
40
|
+
}
|
|
41
|
+
resizeObserver.observe(textarea);
|
|
42
|
+
return () => {
|
|
43
|
+
resizeObserver.disconnect();
|
|
44
|
+
};
|
|
45
|
+
}, []);
|
|
46
|
+
return [height];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const TextField = (props) => {
|
|
50
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
51
|
+
const context = props.context;
|
|
52
|
+
const parameters = props.parameters;
|
|
53
|
+
const boundValue = parameters.value;
|
|
54
|
+
const ref = useRef(null);
|
|
55
|
+
const { value, sizing, setValue, onNotifyOutputChanged } = useInputBasedComponent('TextField', props);
|
|
56
|
+
const [height] = useTextFieldHeight(ref, sizing.height, (_a = props.parameters.IsMultiLine) === null || _a === void 0 ? void 0 : _a.raw);
|
|
57
|
+
return (jsx(TextField$1, { readOnly: context.mode.isControlDisabled,
|
|
58
|
+
//TODO: should be inherited by the type, eg TextArea = multiline
|
|
59
|
+
multiline: (_b = parameters.IsMultiLine) === null || _b === void 0 ? void 0 : _b.raw, resizable: (_c = parameters.isResizable) === null || _c === void 0 ? void 0 : _c.raw, autoFocus: (_d = parameters.AutoFocus) === null || _d === void 0 ? void 0 : _d.raw, elementRef: ref, styles: {
|
|
60
|
+
fieldGroup: {
|
|
61
|
+
height: height,
|
|
62
|
+
width: context.mode.allocatedWidth || undefined
|
|
63
|
+
}
|
|
64
|
+
}, borderless: ((_e = parameters.EnableBorder) === null || _e === void 0 ? void 0 : _e.raw) === false, errorMessage: boundValue.errorMessage, deleteButtonProps: ((_f = parameters.EnableDeleteButton) === null || _f === void 0 ? void 0 : _f.raw) === true ? {
|
|
65
|
+
key: 'delete',
|
|
66
|
+
showOnlyOnHover: true,
|
|
67
|
+
iconProps: {
|
|
68
|
+
iconName: 'Delete'
|
|
69
|
+
},
|
|
70
|
+
onClick: () => setValue(undefined)
|
|
71
|
+
} : undefined, clickToCopyProps: ((_g = parameters.EnableCopyButton) === null || _g === void 0 ? void 0 : _g.raw) === true ? {
|
|
72
|
+
key: 'copy',
|
|
73
|
+
showOnlyOnHover: true,
|
|
74
|
+
iconProps: {
|
|
75
|
+
iconName: 'Copy'
|
|
76
|
+
}
|
|
77
|
+
} : undefined, value: value !== null && value !== void 0 ? value : "", onBlur: () => {
|
|
78
|
+
onNotifyOutputChanged({
|
|
79
|
+
value: value !== null && value !== void 0 ? value : undefined
|
|
80
|
+
});
|
|
81
|
+
}, onChange: (e, value) => {
|
|
82
|
+
setValue(value);
|
|
83
|
+
} }));
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export { TextField };
|
|
@@ -1 +1,40 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Toggle } from '@fluentui/react';
|
|
3
|
+
import { useComponent } from '../../hooks/useComponent.js';
|
|
4
|
+
import { useRef, useEffect } from 'react';
|
|
5
|
+
import 'fast-deep-equal/es6';
|
|
6
|
+
import 'merge-anything';
|
|
7
|
+
import 'liquidjs';
|
|
8
|
+
import '../../hooks/useComponentSizing.js';
|
|
9
|
+
|
|
10
|
+
const TwoOptions = (props) => {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const parameters = props.parameters;
|
|
13
|
+
const boundValue = parameters.value;
|
|
14
|
+
const options = boundValue.attributes.Options;
|
|
15
|
+
const { sizing, onNotifyOutputChanged } = useComponent('TwoOptions', props);
|
|
16
|
+
props.context;
|
|
17
|
+
const componentRef = useRef(null);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
var _a;
|
|
20
|
+
if (((_a = parameters.AutoFocus) === null || _a === void 0 ? void 0 : _a.raw) === true) {
|
|
21
|
+
componentRef.current.focus();
|
|
22
|
+
}
|
|
23
|
+
}, []);
|
|
24
|
+
const handleChange = (value) => {
|
|
25
|
+
onNotifyOutputChanged({
|
|
26
|
+
value: value
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
return jsx(Toggle, { styles: {
|
|
30
|
+
root: {
|
|
31
|
+
height: sizing.height,
|
|
32
|
+
width: sizing.width
|
|
33
|
+
},
|
|
34
|
+
container: {
|
|
35
|
+
alignItems: 'center'
|
|
36
|
+
}
|
|
37
|
+
}, checked: boundValue.raw, componentRef: componentRef, inlineLabel: true, onText: ((_a = options.find(option => option.Value === 1)) === null || _a === void 0 ? void 0 : _a.Label) || 'Yes', offText: ((_b = options.find(option => option.Value === 0)) === null || _b === void 0 ? void 0 : _b.Label) || 'No', onChange: (e, value) => handleChange(value) });
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { TwoOptions };
|
package/dist/hooks/index.js
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
export{useComponent}from
|
|
1
|
+
export { useComponent } from './useComponent.js';
|
|
2
|
+
import 'react';
|
|
3
|
+
import 'fast-deep-equal/es6';
|
|
4
|
+
import 'merge-anything';
|
|
5
|
+
import 'liquidjs';
|
|
6
|
+
import './useComponentSizing.js';
|
|
@@ -1 +1,83 @@
|
|
|
1
|
-
import{useRef
|
|
1
|
+
import { useRef, useMemo, useEffect } from 'react';
|
|
2
|
+
import equal from 'fast-deep-equal/es6';
|
|
3
|
+
import { merge } from 'merge-anything';
|
|
4
|
+
import { Liquid } from 'liquidjs';
|
|
5
|
+
import { useComponentSizing } from './useComponentSizing.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Provides automatic checking if the given outputs are different from the provided inputs. Use the provided method any time you want
|
|
9
|
+
* to notify the framework that you wish to write changes. The hook will notify the framework only if the provided output differs from the current inputs.
|
|
10
|
+
*/
|
|
11
|
+
const useComponent = (name, props, defaultTranslations) => {
|
|
12
|
+
const parametersRef = useRef(props.parameters);
|
|
13
|
+
const sizing = useComponentSizing(props.context.mode);
|
|
14
|
+
const liquid = useMemo(() => new Liquid(), []);
|
|
15
|
+
const labels = useMemo(() => {
|
|
16
|
+
var _a;
|
|
17
|
+
const mergedTranslations = merge(defaultTranslations !== null && defaultTranslations !== void 0 ? defaultTranslations : {}, (_a = props.translations) !== null && _a !== void 0 ? _a : {});
|
|
18
|
+
return new Proxy(mergedTranslations, {
|
|
19
|
+
get(target, key) {
|
|
20
|
+
return (variables) => getLabel(key, mergedTranslations, variables);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}, []);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
parametersRef.current = props.parameters;
|
|
26
|
+
}, [props.parameters]);
|
|
27
|
+
const getLabel = (key, translations, variables) => {
|
|
28
|
+
const strigify = (value) => {
|
|
29
|
+
if (typeof value === 'string') {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
return JSON.stringify(value);
|
|
33
|
+
};
|
|
34
|
+
const translation = translations[key];
|
|
35
|
+
if (!translation) {
|
|
36
|
+
console.error(`Translation for the ${key} label of the ${name} component has not been defined!`);
|
|
37
|
+
return key;
|
|
38
|
+
}
|
|
39
|
+
if (typeof translation === 'string' || Array.isArray(translation)) {
|
|
40
|
+
return strigify(translation);
|
|
41
|
+
}
|
|
42
|
+
let label = translation[props.context.userSettings.languageId];
|
|
43
|
+
if (!label) {
|
|
44
|
+
console.info(`Translation for the ${key} label of the ${name} component has not been found. Using default Czech label instead.`);
|
|
45
|
+
label = translation[1029];
|
|
46
|
+
}
|
|
47
|
+
if (!label) {
|
|
48
|
+
console.error(`Translation for the ${key} label of the ${name} component does not exists neither for Czech language and current LCID.`);
|
|
49
|
+
label = key;
|
|
50
|
+
}
|
|
51
|
+
return liquid.parseAndRenderSync(strigify(label), variables);
|
|
52
|
+
};
|
|
53
|
+
const onNotifyOutputChanged = (outputs) => {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
let isDirty = false;
|
|
56
|
+
for (let [key, outputValue] of Object.entries(outputs)) {
|
|
57
|
+
const parameterValue = (_a = parametersRef.current[key]) === null || _a === void 0 ? void 0 : _a.raw;
|
|
58
|
+
if (!equal(parameterValue, outputValue)) {
|
|
59
|
+
if (outputValue === "") {
|
|
60
|
+
outputValue = null;
|
|
61
|
+
}
|
|
62
|
+
// handles undefined X null
|
|
63
|
+
if (parameterValue == outputValue) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
isDirty = true;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!isDirty) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
//console.log(`Change detected, triggering notifyOutputChanged on component ${name}.`);
|
|
74
|
+
(_b = props.onNotifyOutputChanged) === null || _b === void 0 ? void 0 : _b.call(props, outputs);
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
labels,
|
|
78
|
+
sizing,
|
|
79
|
+
onNotifyOutputChanged
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export { useComponent };
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
const
|
|
1
|
+
const useComponentSizing = (mode) => {
|
|
2
|
+
const getAllocationSize = (allocationSize) => {
|
|
3
|
+
if (!allocationSize || allocationSize === -1) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
return allocationSize;
|
|
7
|
+
};
|
|
8
|
+
return {
|
|
9
|
+
height: getAllocationSize(mode.allocatedHeight),
|
|
10
|
+
width: getAllocationSize(mode.allocatedWidth)
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { useComponentSizing };
|
package/dist/hooks/useFocusIn.js
CHANGED
|
@@ -1 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const useFocusIn = (ref) => {
|
|
4
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
const onFocus = () => {
|
|
8
|
+
setIsFocused(true);
|
|
9
|
+
};
|
|
10
|
+
const onBlur = () => {
|
|
11
|
+
setIsFocused(false);
|
|
12
|
+
};
|
|
13
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.addEventListener('focusin', onFocus);
|
|
14
|
+
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.addEventListener('focusout', onBlur);
|
|
15
|
+
return () => {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('focusin', onFocus);
|
|
18
|
+
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('focusout', onBlur);
|
|
19
|
+
};
|
|
20
|
+
}, []);
|
|
21
|
+
return isFocused;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { useFocusIn };
|
|
@@ -1 +1,42 @@
|
|
|
1
|
-
import{useState
|
|
1
|
+
import { useState, useRef, useEffect } from 'react';
|
|
2
|
+
import { useComponent } from './useComponent.js';
|
|
3
|
+
import 'fast-deep-equal/es6';
|
|
4
|
+
import 'merge-anything';
|
|
5
|
+
import 'liquidjs';
|
|
6
|
+
import './useComponentSizing.js';
|
|
7
|
+
|
|
8
|
+
const useInputBasedComponent = (name, props, options) => {
|
|
9
|
+
var _a;
|
|
10
|
+
const { formatter, valueExtractor } = Object.assign({}, options);
|
|
11
|
+
const rawValue = props.parameters.value.raw;
|
|
12
|
+
const [value, setValue] = useState((_a = formatter === null || formatter === void 0 ? void 0 : formatter(rawValue)) !== null && _a !== void 0 ? _a : rawValue);
|
|
13
|
+
const valueRef = useRef(rawValue);
|
|
14
|
+
const { labels, sizing, onNotifyOutputChanged } = useComponent(name, props, options === null || options === void 0 ? void 0 : options.defaultTranslations);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const formattedValue = formatter === null || formatter === void 0 ? void 0 : formatter(rawValue);
|
|
17
|
+
setValue(formattedValue !== null && formattedValue !== void 0 ? formattedValue : rawValue);
|
|
18
|
+
//console.log(`Updating component ${name} with new value: ${formattedValue ?? rawValue}`);
|
|
19
|
+
}, [rawValue]);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
valueRef.current = value;
|
|
22
|
+
}, [value]);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
return () => {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
if (((_a = props.parameters.NotifyOutputChangedOnUnmount) === null || _a === void 0 ? void 0 : _a.raw) === true) {
|
|
27
|
+
onNotifyOutputChanged({
|
|
28
|
+
value: (_b = valueExtractor === null || valueExtractor === void 0 ? void 0 : valueExtractor(valueRef.current)) !== null && _b !== void 0 ? _b : valueRef.current
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}, []);
|
|
33
|
+
return {
|
|
34
|
+
value,
|
|
35
|
+
labels,
|
|
36
|
+
sizing,
|
|
37
|
+
onNotifyOutputChanged,
|
|
38
|
+
setValue
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { useInputBasedComponent };
|
|
@@ -1 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const useMouseOver = (ref) => {
|
|
4
|
+
const [isMouseOver, setIsMouseOver] = useState(false);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
const onMouseEnter = () => {
|
|
8
|
+
setIsMouseOver(true);
|
|
9
|
+
};
|
|
10
|
+
const onMouseLeave = () => {
|
|
11
|
+
setIsMouseOver(false);
|
|
12
|
+
};
|
|
13
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.addEventListener('mouseenter', onMouseEnter);
|
|
14
|
+
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.addEventListener('mouseleave', onMouseLeave);
|
|
15
|
+
return () => {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('mouseenter', onMouseEnter);
|
|
18
|
+
(_b = ref.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('mouseleave', onMouseLeave);
|
|
19
|
+
};
|
|
20
|
+
}, []);
|
|
21
|
+
return isMouseOver;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { useMouseOver };
|
package/package.json
CHANGED