cx 26.2.2 → 26.2.4
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/build/charts/Chart.d.ts.map +1 -1
- package/build/charts/Chart.js +5 -4
- package/build/charts/ColumnBarBase.d.ts +3 -3
- package/build/charts/ColumnBarBase.d.ts.map +1 -1
- package/build/charts/ColumnBarBase.js +1 -1
- package/build/charts/Legend.d.ts.map +1 -1
- package/build/charts/Legend.js +11 -4
- package/build/charts/Marker.d.ts +3 -3
- package/build/charts/Marker.d.ts.map +1 -1
- package/build/charts/MarkerLine.d.ts +7 -7
- package/build/charts/MarkerLine.d.ts.map +1 -1
- package/build/charts/MarkerLine.js +14 -10
- package/build/charts/PieChart.d.ts +4 -4
- package/build/charts/PieChart.d.ts.map +1 -1
- package/build/charts/PieChart.js +36 -14
- package/build/charts/PieLabel.d.ts.map +1 -1
- package/build/charts/PieLabel.js +2 -1
- package/build/charts/RangeMarker.d.ts +3 -3
- package/build/charts/RangeMarker.d.ts.map +1 -1
- package/build/charts/RangeMarker.js +1 -1
- package/build/charts/axis/TimeAxis.d.ts +3 -3
- package/build/charts/axis/TimeAxis.d.ts.map +1 -1
- package/build/charts/axis/TimeAxis.js +70 -21
- package/build/charts/helpers/SnapPointFinder.d.ts +2 -2
- package/build/charts/helpers/SnapPointFinder.d.ts.map +1 -1
- package/build/charts/helpers/ValueAtFinder.d.ts +3 -3
- package/build/charts/helpers/ValueAtFinder.d.ts.map +1 -1
- package/build/data/StructuredSelector.js +3 -4
- package/build/data/createAccessorModelProxy.d.ts +6 -11
- package/build/data/createAccessorModelProxy.d.ts.map +1 -1
- package/build/data/createAccessorModelProxy.js +1 -3
- package/build/jsx-runtime.d.ts +2 -1
- package/build/jsx-runtime.d.ts.map +1 -1
- package/build/svg/Ellipse.d.ts +5 -4
- package/build/svg/Ellipse.d.ts.map +1 -1
- package/build/svg/Ellipse.js +9 -6
- package/build/svg/Line.d.ts +1 -0
- package/build/svg/Line.d.ts.map +1 -1
- package/build/svg/Line.js +4 -1
- package/build/svg/Text.d.ts +12 -6
- package/build/svg/Text.d.ts.map +1 -1
- package/build/svg/Text.js +12 -4
- package/build/ui/Controller.d.ts +2 -0
- package/build/ui/Controller.d.ts.map +1 -1
- package/build/ui/Controller.js +3 -0
- package/build/ui/HoverSync.d.ts.map +1 -1
- package/build/ui/HoverSync.js +7 -2
- package/build/ui/Prop.d.ts +1 -1
- package/build/ui/Prop.d.ts.map +1 -1
- package/build/ui/Text.d.ts +3 -3
- package/build/ui/Text.d.ts.map +1 -1
- package/build/ui/Text.js +5 -5
- package/build/ui/adapter/GroupAdapter.d.ts.map +1 -1
- package/build/ui/adapter/GroupAdapter.js +20 -10
- package/build/ui/app/History.js +1 -1
- package/build/ui/createFunctionalComponent.d.ts +4 -1
- package/build/ui/createFunctionalComponent.d.ts.map +1 -1
- package/build/widgets/List.d.ts.map +1 -1
- package/build/widgets/List.js +6 -7
- package/build/widgets/drag-drop/DropZone.d.ts +3 -3
- package/build/widgets/drag-drop/DropZone.d.ts.map +1 -1
- package/build/widgets/form/Calendar.d.ts.map +1 -1
- package/build/widgets/form/Calendar.js +30 -11
- package/build/widgets/form/ColorField.d.ts.map +1 -1
- package/build/widgets/form/ColorField.js +16 -7
- package/build/widgets/form/DateTimeField.d.ts.map +1 -1
- package/build/widgets/form/DateTimeField.js +23 -10
- package/build/widgets/form/Field.d.ts +2 -0
- package/build/widgets/form/Field.d.ts.map +1 -1
- package/build/widgets/form/Field.js +11 -5
- package/build/widgets/form/LookupField.d.ts +1 -1
- package/build/widgets/form/LookupField.d.ts.map +1 -1
- package/build/widgets/form/LookupField.js +6 -6
- package/build/widgets/form/MonthField.d.ts.map +1 -1
- package/build/widgets/form/MonthField.js +15 -7
- package/build/widgets/form/MonthPicker.d.ts +1 -2
- package/build/widgets/form/MonthPicker.d.ts.map +1 -1
- package/build/widgets/form/MonthPicker.js +84 -41
- package/build/widgets/form/NumberField.d.ts +2 -0
- package/build/widgets/form/NumberField.d.ts.map +1 -1
- package/build/widgets/form/NumberField.js +45 -15
- package/build/widgets/form/TextField.d.ts +1 -9
- package/build/widgets/form/TextField.d.ts.map +1 -1
- package/build/widgets/form/TextField.js +1 -1
- package/build/widgets/form/TimeList.d.ts +3 -1
- package/build/widgets/form/TimeList.d.ts.map +1 -1
- package/build/widgets/grid/Grid.d.ts +2 -2
- package/build/widgets/grid/Grid.d.ts.map +1 -1
- package/build/widgets/grid/Grid.js +14 -11
- package/build/widgets/grid/Pagination.d.ts.map +1 -1
- package/build/widgets/grid/Pagination.js +4 -4
- package/build/widgets/grid/TreeNode.d.ts.map +1 -1
- package/build/widgets/grid/TreeNode.js +10 -2
- package/build/widgets/icons/folder.d.ts.map +1 -1
- package/build/widgets/icons/folder.js +1 -0
- package/build/widgets/icons/forward.d.ts.map +1 -1
- package/build/widgets/icons/forward.js +4 -3
- package/build/widgets/icons/loading.d.ts.map +1 -1
- package/build/widgets/icons/loading.js +6 -5
- package/build/widgets/icons/square.d.ts.map +1 -1
- package/build/widgets/icons/square.js +3 -3
- package/build/widgets/index.d.ts +3 -1
- package/build/widgets/index.d.ts.map +1 -1
- package/build/widgets/index.js +3 -1
- package/build/widgets/overlay/ContextMenu.d.ts.map +1 -1
- package/build/widgets/overlay/ContextMenu.js +2 -0
- package/build/widgets/overlay/Dropdown.d.ts +2 -1
- package/build/widgets/overlay/Dropdown.d.ts.map +1 -1
- package/build/widgets/overlay/Dropdown.js +75 -20
- package/build/widgets/overlay/MsgBox.d.ts +1 -0
- package/build/widgets/overlay/MsgBox.d.ts.map +1 -1
- package/build/widgets/overlay/MsgBox.js +2 -2
- package/build/widgets/overlay/Overlay.d.ts +32 -2
- package/build/widgets/overlay/Overlay.d.ts.map +1 -1
- package/build/widgets/overlay/Overlay.js +47 -16
- package/build/widgets/overlay/Toast.d.ts +1 -1
- package/build/widgets/overlay/Toast.d.ts.map +1 -1
- package/build/widgets/overlay/Toast.js +4 -1
- package/build/widgets/overlay/Tooltip.d.ts +6 -0
- package/build/widgets/overlay/Tooltip.d.ts.map +1 -1
- package/build/widgets/overlay/Tooltip.js +24 -9
- package/build/widgets/overlay/Window.d.ts.map +1 -1
- package/build/widgets/overlay/Window.js +24 -9
- package/dist/charts.css +325 -272
- package/dist/charts.js +11 -5
- package/dist/data.js +2 -2
- package/dist/manifest.js +853 -841
- package/dist/svg.css +14 -8
- package/dist/svg.js +9 -1
- package/dist/ui.js +29 -16
- package/dist/widgets.css +997 -294
- package/dist/widgets.js +319 -126
- package/package.json +1 -1
- package/src/charts/Bar.scss +13 -10
- package/src/charts/BarGraph.scss +31 -29
- package/src/charts/BubbleGraph.scss +11 -8
- package/src/charts/Chart.ts +5 -3
- package/src/charts/Column.scss +13 -10
- package/src/charts/ColumnBarBase.tsx +255 -230
- package/src/charts/ColumnGraph.scss +13 -11
- package/src/charts/Gridlines.scss +10 -8
- package/src/charts/Legend.scss +57 -50
- package/src/charts/Legend.tsx +257 -213
- package/src/charts/LegendEntry.scss +35 -29
- package/src/charts/LineGraph.scss +28 -25
- package/src/charts/Marker.scss +12 -10
- package/src/charts/Marker.tsx +3 -2
- package/src/charts/MarkerLine.scss +11 -8
- package/src/charts/MarkerLine.tsx +196 -177
- package/src/charts/PieChart.scss +12 -9
- package/src/charts/PieChart.tsx +717 -591
- package/src/charts/PieLabel.tsx +99 -81
- package/src/charts/Range.scss +11 -8
- package/src/charts/RangeMarker.tsx +204 -187
- package/src/charts/ScatterGraph.scss +12 -9
- package/src/charts/axis/Axis.scss +6 -5
- package/src/charts/axis/CategoryAxis.scss +10 -8
- package/src/charts/axis/NumericAxis.scss +9 -6
- package/src/charts/axis/TimeAxis.scss +9 -6
- package/src/charts/axis/TimeAxis.tsx +753 -637
- package/src/charts/axis/index.scss +4 -5
- package/src/charts/axis/variables.scss +4 -2
- package/src/charts/helpers/SnapPointFinder.ts +136 -136
- package/src/charts/helpers/ValueAtFinder.ts +72 -72
- package/src/charts/index.scss +16 -19
- package/src/charts/maps.scss +0 -0
- package/src/charts/palette.scss +11 -31
- package/src/charts/palette.variables.scss +23 -0
- package/src/charts/variables.scss +35 -3
- package/src/data/StructuredSelector.ts +2 -2
- package/src/data/createAccessorModelProxy.ts +66 -74
- package/src/index.scss +5 -6
- package/src/jsx-runtime.ts +2 -1
- package/src/maps.scss +5 -0
- package/src/svg/Ellipse.tsx +62 -55
- package/src/svg/Line.tsx +57 -42
- package/src/svg/Svg.scss +6 -6
- package/src/svg/Text.scss +19 -0
- package/src/svg/Text.tsx +172 -116
- package/src/svg/index.scss +3 -2
- package/src/svg/maps.scss +0 -0
- package/src/svg/variables.scss +0 -0
- package/src/ui/Container.spec.ts +59 -0
- package/src/ui/Controller.spec.tsx +30 -0
- package/src/ui/Controller.ts +5 -0
- package/src/ui/HoverSync.tsx +179 -147
- package/src/ui/Prop.ts +1 -1
- package/src/ui/Text.ts +12 -9
- package/src/ui/adapter/GroupAdapter.spec.ts +42 -0
- package/src/ui/adapter/GroupAdapter.ts +25 -14
- package/src/ui/app/History.ts +1 -1
- package/src/ui/createFunctionalComponent.spec.tsx +55 -0
- package/src/ui/createFunctionalComponent.ts +12 -2
- package/src/ui/index.scss +1 -1
- package/src/ui/layout/LabelsLeftLayout.scss +5 -7
- package/src/ui/layout/LabelsTopLayout.scss +4 -6
- package/src/ui/layout/index.scss +2 -3
- package/src/ui/maps.scss +0 -0
- package/src/ui/variables.scss +1 -2
- package/src/util/index.scss +4 -2
- package/src/util/maps.scss +1 -0
- package/src/util/scss/besm.scss +15 -0
- package/src/util/scss/calc.scss +103 -11
- package/src/util/scss/defaults.scss +24 -0
- package/src/util/scss/elements.scss +78 -0
- package/src/util/scss/global.scss +15 -0
- package/src/util/scss/include.scss +17 -9
- package/src/util/scss/index.scss +1 -9
- package/src/util/scss/maps.scss +2 -0
- package/src/util/scss/pad-size.scss +9 -0
- package/src/util/scss/padding.scss +6 -0
- package/src/util/scss/screen-size.scss +5 -0
- package/src/util/scss/variables.scss +6 -0
- package/src/util/variables.scss +1 -0
- package/src/variables.scss +5 -217
- package/src/widgets/Button.maps.scss +103 -0
- package/src/widgets/Button.scss +33 -9
- package/src/widgets/Button.variables.scss +8 -104
- package/src/widgets/CxCredit.scss +2 -0
- package/src/widgets/FlexBox.scss +16 -11
- package/src/widgets/Heading.scss +6 -0
- package/src/widgets/HighlightedSearchText.scss +8 -1
- package/src/widgets/Icon.scss +6 -0
- package/src/widgets/List.scss +7 -0
- package/src/widgets/List.tsx +6 -7
- package/src/widgets/ProgressBar.scss +9 -0
- package/src/widgets/Resizer.scss +9 -7
- package/src/widgets/Section.scss +53 -56
- package/src/widgets/animations.scss +4 -2
- package/src/widgets/box.scss +47 -0
- package/src/widgets/drag-drop/DragClone.scss +12 -4
- package/src/widgets/drag-drop/DragHandle.scss +12 -6
- package/src/widgets/drag-drop/DragSource.scss +12 -6
- package/src/widgets/drag-drop/DropZone.scss +9 -0
- package/src/widgets/drag-drop/DropZone.tsx +3 -3
- package/src/widgets/drag-drop/index.scss +4 -4
- package/src/widgets/drag-drop/maps.scss +7 -0
- package/src/widgets/drag-drop/variables.scss +8 -5
- package/src/widgets/form/Calendar.maps.scss +54 -0
- package/src/widgets/form/Calendar.scss +49 -11
- package/src/widgets/form/Calendar.tsx +755 -653
- package/src/widgets/form/Calendar.variables.scss +3 -46
- package/src/widgets/form/Checkbox.maps.scss +34 -0
- package/src/widgets/form/Checkbox.scss +14 -3
- package/src/widgets/form/Checkbox.variables.scss +4 -36
- package/src/widgets/form/ColorField.scss +21 -2
- package/src/widgets/form/ColorField.tsx +485 -431
- package/src/widgets/form/ColorPicker.maps.scss +21 -0
- package/src/widgets/form/ColorPicker.scss +26 -9
- package/src/widgets/form/ColorPicker.variables.scss +3 -16
- package/src/widgets/form/DateTimeField.scss +54 -21
- package/src/widgets/form/DateTimeField.tsx +697 -615
- package/src/widgets/form/DateTimePicker.scss +14 -4
- package/src/widgets/form/Field.maps.scss +122 -0
- package/src/widgets/form/Field.scss +54 -18
- package/src/widgets/form/Field.tsx +611 -504
- package/src/widgets/form/Field.variables.scss +46 -0
- package/src/widgets/form/HelpText.scss +8 -5
- package/src/widgets/form/Label.scss +10 -3
- package/src/widgets/form/LookupField.maps.scss +26 -0
- package/src/widgets/form/LookupField.scss +54 -24
- package/src/widgets/form/LookupField.tsx +25 -21
- package/src/widgets/form/MonthField.scss +48 -26
- package/src/widgets/form/MonthField.tsx +645 -567
- package/src/widgets/form/MonthPicker.maps.scss +50 -0
- package/src/widgets/form/MonthPicker.scss +44 -35
- package/src/widgets/form/MonthPicker.tsx +954 -724
- package/src/widgets/form/MonthPicker.variables.scss +24 -0
- package/src/widgets/form/NumberField.scss +19 -2
- package/src/widgets/form/NumberField.tsx +576 -466
- package/src/widgets/form/Radio.maps.scss +36 -0
- package/src/widgets/form/Radio.scss +12 -2
- package/src/widgets/form/Radio.variables.scss +3 -42
- package/src/widgets/form/Select.scss +25 -9
- package/src/widgets/form/Slider.scss +23 -14
- package/src/widgets/form/Switch.scss +18 -8
- package/src/widgets/form/TextArea.scss +14 -1
- package/src/widgets/form/TextField.scss +24 -3
- package/src/widgets/form/TextField.tsx +9 -21
- package/src/widgets/form/UploadButton.scss +14 -6
- package/src/widgets/form/ValidationError.scss +10 -6
- package/src/widgets/form/Wheel.scss +14 -4
- package/src/widgets/form/index.scss +22 -24
- package/src/widgets/form/maps.scss +81 -0
- package/src/widgets/form/variables.scss +111 -355
- package/src/widgets/grid/Grid.scss +19 -2
- package/src/widgets/grid/Grid.spec.ts +42 -0
- package/src/widgets/grid/Grid.tsx +18 -13
- package/src/widgets/grid/Pagination.scss +11 -2
- package/src/widgets/grid/Pagination.tsx +110 -102
- package/src/widgets/grid/TreeNode.scss +25 -8
- package/src/widgets/grid/TreeNode.tsx +127 -116
- package/src/widgets/grid/index.scss +3 -4
- package/src/widgets/grid/maps.scss +110 -0
- package/src/widgets/grid/variables.scss +48 -137
- package/src/widgets/icons/folder.tsx +1 -2
- package/src/widgets/icons/forward.tsx +23 -20
- package/src/widgets/icons/loading.tsx +22 -19
- package/src/widgets/icons/square.tsx +20 -17
- package/src/widgets/index.scss +16 -16
- package/src/widgets/index.ts +63 -58
- package/src/widgets/lists.scss +42 -0
- package/src/widgets/maps.scss +139 -0
- package/src/widgets/nav/Link.scss +14 -1
- package/src/widgets/nav/Menu.scss +13 -7
- package/src/widgets/nav/Menu.variables.scss +1 -12
- package/src/widgets/nav/MenuItem.scss +21 -6
- package/src/widgets/nav/Scroller.scss +11 -2
- package/src/widgets/nav/Tab.maps.scss +78 -0
- package/src/widgets/nav/Tab.scss +12 -6
- package/src/widgets/nav/Tab.variables.scss +7 -76
- package/src/widgets/nav/cover.scss +6 -4
- package/src/widgets/nav/index.scss +6 -6
- package/src/widgets/nav/maps.scss +32 -0
- package/src/widgets/nav/variables.scss +4 -11
- package/src/widgets/overlay/ContextMenu.ts +3 -0
- package/src/widgets/overlay/Dropdown.scss +47 -16
- package/src/widgets/overlay/Dropdown.tsx +851 -676
- package/src/widgets/overlay/MsgBox.tsx +125 -111
- package/src/widgets/overlay/Overlay.scss +60 -40
- package/src/widgets/overlay/Overlay.tsx +948 -800
- package/src/widgets/overlay/Toast.scss +42 -34
- package/src/widgets/overlay/Toast.ts +11 -1
- package/src/widgets/overlay/Tooltip.scss +27 -96
- package/src/widgets/overlay/Tooltip.tsx +376 -309
- package/src/widgets/overlay/Window.maps.scss +51 -0
- package/src/widgets/overlay/Window.scss +17 -17
- package/src/widgets/overlay/Window.tsx +291 -236
- package/src/widgets/overlay/Window.variables.scss +2 -43
- package/src/widgets/overlay/index.d.ts +11 -11
- package/src/widgets/overlay/index.scss +6 -15
- package/src/widgets/overlay/maps.scss +44 -0
- package/src/widgets/overlay/variables.scss +11 -42
- package/src/widgets/variables.scss +33 -117
- package/src/global.scss +0 -14
|
@@ -8,13 +8,14 @@ import type { RenderingContext } from "../../ui/RenderingContext";
|
|
|
8
8
|
import type { Instance } from "../../ui/Instance";
|
|
9
9
|
import { StringTemplate } from "../../data/StringTemplate";
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
tooltipParentWillReceiveProps,
|
|
12
|
+
tooltipParentWillUnmount,
|
|
13
|
+
tooltipMouseMove,
|
|
14
|
+
tooltipMouseLeave,
|
|
15
|
+
tooltipParentDidMount,
|
|
16
16
|
} from "../overlay/tooltip-ops";
|
|
17
17
|
import { stopPropagation } from "../../util/eventCallbacks";
|
|
18
|
+
import { addEventListenerWithOptions } from "../../util/addEventListenerWithOptions";
|
|
18
19
|
import { Localization } from "../../ui/Localization";
|
|
19
20
|
import ClearIcon from "../icons/clear";
|
|
20
21
|
import { isString } from "../../util/isString";
|
|
@@ -30,152 +31,201 @@ import { Prop, NumberProp, StringProp, BooleanProp } from "../../ui/Prop";
|
|
|
30
31
|
enableCultureSensitiveFormatting();
|
|
31
32
|
|
|
32
33
|
export interface NumberFieldConfig extends FieldConfig {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
34
|
+
value?: NumberProp;
|
|
35
|
+
readOnly?: BooleanProp;
|
|
36
|
+
enabled?: BooleanProp;
|
|
37
|
+
placeholder?: StringProp;
|
|
38
|
+
format?: StringProp;
|
|
39
|
+
minValue?: NumberProp;
|
|
40
|
+
minExclusive?: BooleanProp;
|
|
41
|
+
maxValue?: NumberProp;
|
|
42
|
+
maxExclusive?: BooleanProp;
|
|
43
|
+
constrain?: BooleanProp;
|
|
44
|
+
incrementPercentage?: NumberProp;
|
|
45
|
+
increment?: NumberProp;
|
|
46
|
+
step?: number;
|
|
47
|
+
baseClass?: string;
|
|
48
|
+
snapToIncrement?: boolean;
|
|
49
|
+
showClear?: boolean;
|
|
50
|
+
hideClear?: boolean;
|
|
51
|
+
alwaysShowClear?: boolean;
|
|
52
|
+
reactOn?: string;
|
|
53
|
+
inputType?: "text" | "password";
|
|
54
|
+
maxValueErrorText?: string;
|
|
55
|
+
maxExclusiveErrorText?: string;
|
|
56
|
+
minValueErrorText?: string;
|
|
57
|
+
minExclusiveErrorText?: string;
|
|
58
|
+
inputErrorText?: string;
|
|
59
|
+
scale?: number;
|
|
60
|
+
offset?: number;
|
|
61
|
+
|
|
62
|
+
/** Custom validation function. */
|
|
63
|
+
onValidate?:
|
|
64
|
+
| string
|
|
65
|
+
| ((
|
|
66
|
+
value: number,
|
|
67
|
+
instance: Instance,
|
|
68
|
+
validationParams: Record<string, unknown>,
|
|
69
|
+
) => unknown);
|
|
70
|
+
|
|
71
|
+
/** If `trackFocus` is set, this value will be set when the field receives or loses focus. */
|
|
72
|
+
focused?: BooleanProp;
|
|
63
73
|
}
|
|
64
74
|
|
|
65
|
-
export class NumberField<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
75
|
+
export class NumberField<
|
|
76
|
+
Config extends NumberFieldConfig = NumberFieldConfig,
|
|
77
|
+
> extends Field<Config> {
|
|
78
|
+
declare public baseClass: string;
|
|
79
|
+
declare public reactOn: string;
|
|
80
|
+
declare public format: string;
|
|
81
|
+
declare public inputType: string;
|
|
82
|
+
declare public incrementPercentage: number;
|
|
83
|
+
declare public increment?: number;
|
|
84
|
+
declare public scale: number;
|
|
85
|
+
declare public offset: number;
|
|
86
|
+
declare public step?: number;
|
|
87
|
+
declare public hideClear?: boolean;
|
|
88
|
+
declare public showClear?: boolean;
|
|
89
|
+
declare public alwaysShowClear?: boolean;
|
|
90
|
+
declare public snapToIncrement?: boolean;
|
|
91
|
+
declare public onParseInput?:
|
|
92
|
+
| string
|
|
93
|
+
| ((value: string, instance: Instance) => number | undefined);
|
|
94
|
+
declare public minValueErrorText: string;
|
|
95
|
+
declare public maxValueErrorText: string;
|
|
96
|
+
declare public minExclusiveErrorText: string;
|
|
97
|
+
declare public maxExclusiveErrorText: string;
|
|
98
|
+
declare public inputErrorText?: string;
|
|
99
|
+
|
|
100
|
+
declareData(...args: Record<string, unknown>[]): void {
|
|
101
|
+
super.declareData(
|
|
102
|
+
{
|
|
103
|
+
value: this.emptyValue,
|
|
104
|
+
disabled: undefined,
|
|
105
|
+
readOnly: undefined,
|
|
106
|
+
enabled: undefined,
|
|
107
|
+
placeholder: undefined,
|
|
108
|
+
required: undefined,
|
|
109
|
+
format: undefined,
|
|
110
|
+
minValue: undefined,
|
|
111
|
+
maxValue: undefined,
|
|
112
|
+
constrain: undefined,
|
|
113
|
+
minExclusive: undefined,
|
|
114
|
+
maxExclusive: undefined,
|
|
115
|
+
incrementPercentage: undefined,
|
|
116
|
+
increment: undefined,
|
|
117
|
+
icon: undefined,
|
|
118
|
+
scale: undefined,
|
|
119
|
+
offset: undefined,
|
|
120
|
+
focused: undefined,
|
|
121
|
+
},
|
|
122
|
+
...args,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
init(): void {
|
|
127
|
+
if (isDefined(this.step)) this.increment = this.step;
|
|
128
|
+
|
|
129
|
+
if (isDefined(this.hideClear)) this.showClear = !this.hideClear;
|
|
130
|
+
|
|
131
|
+
if (this.alwaysShowClear) this.showClear = true;
|
|
132
|
+
|
|
133
|
+
super.init();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
prepareData(
|
|
137
|
+
context: RenderingContext,
|
|
138
|
+
instance: FieldInstance<NumberField>,
|
|
139
|
+
): void {
|
|
140
|
+
let { data, state, cached } = instance;
|
|
141
|
+
data.formatted = Format.value(data.value, data.format);
|
|
142
|
+
|
|
143
|
+
if (!cached.data || data.value != cached.data.value)
|
|
144
|
+
state.empty = data.value == null;
|
|
145
|
+
|
|
146
|
+
super.prepareData(context, instance);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
formatValue(
|
|
150
|
+
context: RenderingContext,
|
|
151
|
+
{ data }: FieldInstance<NumberField>,
|
|
152
|
+
): string | number | undefined {
|
|
153
|
+
return data.formatted;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
parseValue(value: string, instance: FieldInstance<NumberField>): number {
|
|
157
|
+
if (this.onParseInput) {
|
|
158
|
+
let result = instance.invoke("onParseInput", value, instance);
|
|
159
|
+
if (result !== undefined) return result;
|
|
160
|
+
}
|
|
161
|
+
return Culture.getNumberCulture().parse(value);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
validate(
|
|
165
|
+
context: RenderingContext,
|
|
166
|
+
instance: FieldInstance<NumberField>,
|
|
167
|
+
): void {
|
|
168
|
+
super.validate(context, instance);
|
|
169
|
+
|
|
170
|
+
let { data } = instance;
|
|
171
|
+
if (isNumber(data.value) && !data.error) {
|
|
172
|
+
if (isNumber(data.minValue)) {
|
|
173
|
+
if (data.value < data.minValue)
|
|
174
|
+
data.error = StringTemplate.format(
|
|
175
|
+
this.minValueErrorText,
|
|
176
|
+
Format.value(data.minValue, data.format),
|
|
177
|
+
);
|
|
178
|
+
else if (data.value == data.minValue && data.minExclusive)
|
|
179
|
+
data.error = StringTemplate.format(
|
|
180
|
+
this.minExclusiveErrorText,
|
|
181
|
+
Format.value(data.minValue, data.format),
|
|
182
|
+
);
|
|
138
183
|
}
|
|
139
|
-
return Culture.getNumberCulture().parse(value);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
validate(context: RenderingContext, instance: FieldInstance<NumberField>): void {
|
|
143
|
-
super.validate(context, instance);
|
|
144
|
-
|
|
145
|
-
let { data } = instance;
|
|
146
|
-
if (isNumber(data.value) && !data.error) {
|
|
147
|
-
if (isNumber(data.minValue)) {
|
|
148
|
-
if (data.value < data.minValue)
|
|
149
|
-
data.error = StringTemplate.format(this.minValueErrorText, Format.value(data.minValue, data.format));
|
|
150
|
-
else if (data.value == data.minValue && data.minExclusive)
|
|
151
|
-
data.error = StringTemplate.format(this.minExclusiveErrorText, Format.value(data.minValue, data.format));
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (isNumber(data.maxValue)) {
|
|
155
|
-
if (data.value > data.maxValue)
|
|
156
|
-
data.error = StringTemplate.format(this.maxValueErrorText, Format.value(data.maxValue, data.format));
|
|
157
|
-
else if (data.value == data.maxValue && data.maxExclusive)
|
|
158
|
-
data.error = StringTemplate.format(this.maxExclusiveErrorText, Format.value(data.maxValue, data.format));
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
renderInput(context: RenderingContext, instance: FieldInstance<NumberField>, key: string): React.ReactNode {
|
|
164
|
-
return (
|
|
165
|
-
<Input
|
|
166
|
-
key={key}
|
|
167
|
-
data={instance.data}
|
|
168
|
-
instance={instance}
|
|
169
|
-
label={this.labelPlacement && getContent(this.renderLabel(context, instance, "label"))}
|
|
170
|
-
help={this.helpPlacement && getContent(this.renderHelp(context, instance, "help"))}
|
|
171
|
-
icon={this.renderIcon(context, instance, "icon")}
|
|
172
|
-
/>
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
184
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
185
|
+
if (isNumber(data.maxValue)) {
|
|
186
|
+
if (data.value > data.maxValue)
|
|
187
|
+
data.error = StringTemplate.format(
|
|
188
|
+
this.maxValueErrorText,
|
|
189
|
+
Format.value(data.maxValue, data.format),
|
|
190
|
+
);
|
|
191
|
+
else if (data.value == data.maxValue && data.maxExclusive)
|
|
192
|
+
data.error = StringTemplate.format(
|
|
193
|
+
this.maxExclusiveErrorText,
|
|
194
|
+
Format.value(data.maxValue, data.format),
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
renderInput(
|
|
201
|
+
context: RenderingContext,
|
|
202
|
+
instance: FieldInstance<NumberField>,
|
|
203
|
+
key: string,
|
|
204
|
+
): React.ReactNode {
|
|
205
|
+
return (
|
|
206
|
+
<Input
|
|
207
|
+
key={key}
|
|
208
|
+
data={instance.data}
|
|
209
|
+
instance={instance}
|
|
210
|
+
label={
|
|
211
|
+
this.labelPlacement &&
|
|
212
|
+
getContent(this.renderLabel(context, instance, "label"))
|
|
213
|
+
}
|
|
214
|
+
help={
|
|
215
|
+
this.helpPlacement &&
|
|
216
|
+
getContent(this.renderHelp(context, instance, "help"))
|
|
217
|
+
}
|
|
218
|
+
icon={this.renderIcon(context, instance, "icon")}
|
|
219
|
+
/>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
validateRequired(
|
|
224
|
+
context: RenderingContext,
|
|
225
|
+
instance: FieldInstance<NumberField>,
|
|
226
|
+
): string | undefined {
|
|
227
|
+
return instance.state.empty && this.requiredText;
|
|
228
|
+
}
|
|
179
229
|
}
|
|
180
230
|
|
|
181
231
|
NumberField.prototype.baseClass = "numberfield";
|
|
@@ -186,7 +236,8 @@ NumberField.prototype.inputType = "text";
|
|
|
186
236
|
NumberField.prototype.maxValueErrorText = "Enter {0} or less.";
|
|
187
237
|
NumberField.prototype.maxExclusiveErrorText = "Enter a number less than {0}.";
|
|
188
238
|
NumberField.prototype.minValueErrorText = "Enter {0} or more.";
|
|
189
|
-
NumberField.prototype.minExclusiveErrorText =
|
|
239
|
+
NumberField.prototype.minExclusiveErrorText =
|
|
240
|
+
"Enter a number greater than {0}.";
|
|
190
241
|
NumberField.prototype.inputErrorText = "Invalid number entered.";
|
|
191
242
|
NumberField.prototype.suppressErrorsUntilVisited = true;
|
|
192
243
|
|
|
@@ -202,342 +253,401 @@ Widget.alias("numberfield", NumberField);
|
|
|
202
253
|
Localization.registerPrototype("cx/widgets/NumberField", NumberField);
|
|
203
254
|
|
|
204
255
|
interface InputProps {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
256
|
+
instance: FieldInstance<NumberField>;
|
|
257
|
+
data: Record<string, any>;
|
|
258
|
+
label?: React.ReactNode;
|
|
259
|
+
help?: React.ReactNode;
|
|
260
|
+
icon?: React.ReactNode;
|
|
210
261
|
}
|
|
211
262
|
|
|
212
263
|
interface InputState {
|
|
213
|
-
|
|
264
|
+
focus: boolean;
|
|
214
265
|
}
|
|
215
266
|
|
|
216
267
|
class Input extends VDOM.Component<InputProps, InputState> {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
)
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
268
|
+
input?: HTMLInputElement;
|
|
269
|
+
unsubscribeOnWheel?: () => void;
|
|
270
|
+
|
|
271
|
+
constructor(props: InputProps) {
|
|
272
|
+
super(props);
|
|
273
|
+
this.state = {
|
|
274
|
+
focus: false,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
render(): React.ReactNode {
|
|
279
|
+
let { data, instance, label, help, icon: iconVDOM } = this.props;
|
|
280
|
+
let { widget, state } = instance;
|
|
281
|
+
let { CSS, baseClass, suppressErrorsUntilVisited } = widget;
|
|
282
|
+
|
|
283
|
+
let icon = iconVDOM && (
|
|
284
|
+
<div className={CSS.element(baseClass, "left-icon")}>{iconVDOM}</div>
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
let insideButton;
|
|
288
|
+
if (!data.readOnly && !data.disabled) {
|
|
289
|
+
if (
|
|
290
|
+
widget.showClear &&
|
|
291
|
+
(((widget.alwaysShowClear || !data.required) && !data.empty) ||
|
|
292
|
+
instance.state.inputError)
|
|
293
|
+
)
|
|
294
|
+
insideButton = (
|
|
295
|
+
<div
|
|
296
|
+
className={CSS.element(baseClass, "clear")}
|
|
297
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
298
|
+
onClick={(e) => this.onClearClick(e)}
|
|
299
|
+
>
|
|
300
|
+
<ClearIcon className={CSS.element(baseClass, "icon")} />
|
|
301
|
+
</div>
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
let empty = this.input ? !this.input.value : data.empty;
|
|
306
|
+
|
|
307
|
+
return (
|
|
308
|
+
<div
|
|
309
|
+
className={CSS.expand(
|
|
310
|
+
data.classNames,
|
|
311
|
+
CSS.state({
|
|
312
|
+
visited: state.visited,
|
|
313
|
+
focus: this.state.focus,
|
|
314
|
+
icon: !!icon,
|
|
315
|
+
empty: empty && !data.placeholder,
|
|
316
|
+
error:
|
|
317
|
+
data.error &&
|
|
318
|
+
(state.visited || !suppressErrorsUntilVisited || !empty),
|
|
319
|
+
}),
|
|
320
|
+
)}
|
|
321
|
+
style={data.style}
|
|
322
|
+
onMouseDown={stopPropagation}
|
|
323
|
+
onTouchStart={stopPropagation}
|
|
324
|
+
>
|
|
325
|
+
<input
|
|
326
|
+
id={data.id}
|
|
327
|
+
type={widget.inputType}
|
|
328
|
+
className={CSS.expand(
|
|
329
|
+
CSS.element(baseClass, "input"),
|
|
330
|
+
data.inputClass,
|
|
331
|
+
)}
|
|
332
|
+
defaultValue={data.formatted}
|
|
333
|
+
ref={(el: HTMLInputElement | null) => {
|
|
334
|
+
this.input = el || undefined;
|
|
335
|
+
}}
|
|
336
|
+
style={data.inputStyle}
|
|
337
|
+
disabled={data.disabled}
|
|
338
|
+
readOnly={data.readOnly}
|
|
339
|
+
tabIndex={data.tabIndex}
|
|
340
|
+
placeholder={data.placeholder}
|
|
341
|
+
{...data.inputAttrs}
|
|
342
|
+
onMouseMove={(e: React.MouseEvent<HTMLInputElement>) =>
|
|
343
|
+
tooltipMouseMove(e, ...getFieldTooltip(this.props.instance))
|
|
344
|
+
}
|
|
345
|
+
onMouseLeave={(e: React.MouseEvent<HTMLInputElement>) =>
|
|
346
|
+
tooltipMouseLeave(e, ...getFieldTooltip(this.props.instance))
|
|
347
|
+
}
|
|
348
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
|
|
349
|
+
this.onChange(e, "change")
|
|
350
|
+
}
|
|
351
|
+
onKeyDown={this.onKeyDown.bind(this)}
|
|
352
|
+
onBlur={(e: React.FocusEvent<HTMLInputElement>) => this.onBlur(e)}
|
|
353
|
+
onFocus={(e: React.FocusEvent<HTMLInputElement>) => this.onFocus()}
|
|
354
|
+
onClick={stopPropagation}
|
|
355
|
+
/>
|
|
356
|
+
{insideButton}
|
|
357
|
+
{icon}
|
|
358
|
+
{label}
|
|
359
|
+
{help}
|
|
360
|
+
</div>
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
UNSAFE_componentWillReceiveProps(props: InputProps): void {
|
|
365
|
+
let { data, state } = props.instance;
|
|
366
|
+
if (this.props.data.formatted != data.formatted && !state.inputError) {
|
|
367
|
+
this.input!.value = props.data.formatted || "";
|
|
368
|
+
props.instance.setState({
|
|
369
|
+
inputError: false,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
tooltipParentWillReceiveProps(
|
|
373
|
+
this.input!,
|
|
374
|
+
...getFieldTooltip(props.instance),
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
componentDidMount(): void {
|
|
379
|
+
tooltipParentDidMount(this.input!, ...getFieldTooltip(this.props.instance));
|
|
380
|
+
autoFocus(this.input, this);
|
|
381
|
+
let { widget } = this.props.instance;
|
|
382
|
+
if (widget.reactOn.indexOf("wheel") !== -1) {
|
|
383
|
+
this.unsubscribeOnWheel = addEventListenerWithOptions(
|
|
384
|
+
this.input!,
|
|
385
|
+
"wheel",
|
|
386
|
+
(e) => {
|
|
387
|
+
this.onChange(e as unknown as React.WheelEvent<HTMLInputElement>, "wheel");
|
|
388
|
+
},
|
|
389
|
+
{ passive: false },
|
|
304
390
|
);
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
componentDidUpdate(): void {
|
|
395
|
+
autoFocus(this.input, this);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
componentWillUnmount(): void {
|
|
399
|
+
if (
|
|
400
|
+
this.input == getActiveElement() &&
|
|
401
|
+
this.input.value != this.props.data.formatted
|
|
402
|
+
) {
|
|
403
|
+
this.onChange(
|
|
404
|
+
{ currentTarget: this.input } as React.SyntheticEvent<HTMLInputElement>,
|
|
405
|
+
"blur",
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
tooltipParentWillUnmount(this.props.instance);
|
|
409
|
+
this.unsubscribeOnWheel?.();
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
getPreCursorDigits(
|
|
413
|
+
text: string,
|
|
414
|
+
cursor: number,
|
|
415
|
+
decimalSeparator: string,
|
|
416
|
+
): string {
|
|
417
|
+
let res = "";
|
|
418
|
+
for (let i = 0; i < cursor; i++) {
|
|
419
|
+
if ("0" <= text[i] && text[i] <= "9") res += text[i];
|
|
420
|
+
else if (text[i] == decimalSeparator) res += ".";
|
|
421
|
+
else if (text[i] == "-") res += "-";
|
|
422
|
+
}
|
|
423
|
+
return res;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
getLengthWithoutSuffix(text: string, decimalSeparator: string): number {
|
|
427
|
+
let l = text.length;
|
|
428
|
+
while (l > 0) {
|
|
429
|
+
if ("0" <= text[l - 1] && text[l - 1] <= "9") break;
|
|
430
|
+
if (text[l - 1] == decimalSeparator) break;
|
|
431
|
+
l--;
|
|
432
|
+
}
|
|
433
|
+
return l;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
getDecimalSeparator(format: string): string | null {
|
|
437
|
+
let text = Format.value(0.11111111, format);
|
|
438
|
+
for (let i = text.length - 1; i >= 0; i--) {
|
|
439
|
+
if ("0" <= text[i] && text[i] <= "9") continue;
|
|
440
|
+
if (text[i] == "," || text[i] == ".") return text[i];
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
updateCursorPosition(preCursorText: string | undefined): void {
|
|
447
|
+
if (isString(preCursorText)) {
|
|
448
|
+
let cursor = 0;
|
|
449
|
+
let preCursor = 0;
|
|
450
|
+
let text = this.input!.value || "";
|
|
451
|
+
while (preCursor < preCursorText.length && cursor < text.length) {
|
|
452
|
+
if (text[cursor] == preCursorText[preCursor]) {
|
|
453
|
+
cursor++;
|
|
454
|
+
preCursor++;
|
|
455
|
+
} else {
|
|
456
|
+
cursor++;
|
|
457
|
+
}
|
|
314
458
|
}
|
|
315
|
-
|
|
316
|
-
|
|
459
|
+
this.input!.setSelectionRange(cursor, cursor);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
calculateIncrement(value: number, strength: number): number {
|
|
464
|
+
if (value == 0) return 0.1;
|
|
465
|
+
let absValue = Math.abs(value * strength);
|
|
466
|
+
let log10 = Math.floor(Math.log10(absValue) + 0.001);
|
|
467
|
+
let size = Math.pow(10, log10);
|
|
468
|
+
if (absValue / size > 4.999) return 5 * size;
|
|
469
|
+
if (absValue / size > 1.999) return 2 * size;
|
|
470
|
+
return size;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
onClearClick(e: React.MouseEvent): void {
|
|
474
|
+
this.input!.value = "";
|
|
475
|
+
let { instance } = this.props;
|
|
476
|
+
instance.set("value", instance.widget.emptyValue, { immediate: true });
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
onKeyDown(e: React.KeyboardEvent<HTMLInputElement>): void {
|
|
480
|
+
let { instance } = this.props;
|
|
481
|
+
if (instance.widget.handleKeyDown(e, instance) === false) return;
|
|
482
|
+
|
|
483
|
+
switch (e.keyCode) {
|
|
484
|
+
case KeyCode.enter:
|
|
485
|
+
this.onChange(e, "enter");
|
|
486
|
+
break;
|
|
487
|
+
|
|
488
|
+
case KeyCode.left:
|
|
489
|
+
case KeyCode.right:
|
|
490
|
+
e.stopPropagation();
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
onChange(
|
|
496
|
+
e:
|
|
497
|
+
| React.SyntheticEvent<HTMLInputElement>
|
|
498
|
+
| React.WheelEvent<HTMLInputElement>,
|
|
499
|
+
change: string,
|
|
500
|
+
): void {
|
|
501
|
+
let { instance, data } = this.props;
|
|
502
|
+
let { widget } = instance;
|
|
503
|
+
let inputValue = e.currentTarget.value;
|
|
504
|
+
|
|
505
|
+
if (data.required) {
|
|
506
|
+
instance.setState({
|
|
507
|
+
empty: !inputValue,
|
|
508
|
+
});
|
|
509
|
+
}
|
|
317
510
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
511
|
+
if (change == "blur" && this.state.focus) {
|
|
512
|
+
this.setState({
|
|
513
|
+
focus: false,
|
|
514
|
+
});
|
|
515
|
+
}
|
|
322
516
|
|
|
323
|
-
|
|
324
|
-
autoFocus(this.input, this);
|
|
325
|
-
}
|
|
517
|
+
let immediate = change == "blur" || change == "enter";
|
|
326
518
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
getPreCursorDigits(text: string, cursor: number, decimalSeparator: string): string {
|
|
335
|
-
let res = "";
|
|
336
|
-
for (let i = 0; i < cursor; i++) {
|
|
337
|
-
if ("0" <= text[i] && text[i] <= "9") res += text[i];
|
|
338
|
-
else if (text[i] == decimalSeparator) res += ".";
|
|
339
|
-
else if (text[i] == "-") res += "-";
|
|
340
|
-
}
|
|
341
|
-
return res;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
getLengthWithoutSuffix(text: string, decimalSeparator: string): number {
|
|
345
|
-
let l = text.length;
|
|
346
|
-
while (l > 0) {
|
|
347
|
-
if ("0" <= text[l - 1] && text[l - 1] <= "9") break;
|
|
348
|
-
if (text[l - 1] == decimalSeparator) break;
|
|
349
|
-
l--;
|
|
350
|
-
}
|
|
351
|
-
return l;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
getDecimalSeparator(format: string): string | null {
|
|
355
|
-
let text = Format.value(0.11111111, format);
|
|
356
|
-
for (let i = text.length - 1; i >= 0; i--) {
|
|
357
|
-
if ("0" <= text[i] && text[i] <= "9") continue;
|
|
358
|
-
if (text[i] == "," || text[i] == ".") return text[i];
|
|
359
|
-
break;
|
|
360
|
-
}
|
|
361
|
-
return null;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
updateCursorPosition(preCursorText: string | undefined): void {
|
|
365
|
-
if (isString(preCursorText)) {
|
|
366
|
-
let cursor = 0;
|
|
367
|
-
let preCursor = 0;
|
|
368
|
-
let text = this.input!.value || "";
|
|
369
|
-
while (preCursor < preCursorText.length && cursor < text.length) {
|
|
370
|
-
if (text[cursor] == preCursorText[preCursor]) {
|
|
371
|
-
cursor++;
|
|
372
|
-
preCursor++;
|
|
373
|
-
} else {
|
|
374
|
-
cursor++;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
this.input!.setSelectionRange(cursor, cursor);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
calculateIncrement(value: number, strength: number): number {
|
|
382
|
-
if (value == 0) return 0.1;
|
|
383
|
-
let absValue = Math.abs(value * strength);
|
|
384
|
-
let log10 = Math.floor(Math.log10(absValue) + 0.001);
|
|
385
|
-
let size = Math.pow(10, log10);
|
|
386
|
-
if (absValue / size > 4.999) return 5 * size;
|
|
387
|
-
if (absValue / size > 1.999) return 2 * size;
|
|
388
|
-
return size;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
onClearClick(e: React.MouseEvent): void {
|
|
392
|
-
this.input!.value = "";
|
|
393
|
-
let { instance } = this.props;
|
|
394
|
-
instance.set("value", instance.widget.emptyValue, { immediate: true });
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
onKeyDown(e: React.KeyboardEvent<HTMLInputElement>): void {
|
|
398
|
-
let { instance } = this.props;
|
|
399
|
-
if (instance.widget.handleKeyDown(e, instance) === false) return;
|
|
400
|
-
|
|
401
|
-
switch (e.keyCode) {
|
|
402
|
-
case KeyCode.enter:
|
|
403
|
-
this.onChange(e, "enter");
|
|
404
|
-
break;
|
|
405
|
-
|
|
406
|
-
case KeyCode.left:
|
|
407
|
-
case KeyCode.right:
|
|
408
|
-
e.stopPropagation();
|
|
409
|
-
break;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
519
|
+
if (
|
|
520
|
+
(widget.reactOn.indexOf(change) == -1 && !immediate) ||
|
|
521
|
+
data.disabled ||
|
|
522
|
+
data.readOnly
|
|
523
|
+
)
|
|
524
|
+
return;
|
|
412
525
|
|
|
413
|
-
|
|
414
|
-
let { instance, data } = this.props;
|
|
415
|
-
let { widget } = instance;
|
|
416
|
-
let inputValue = e.currentTarget.value;
|
|
526
|
+
if (immediate) instance.setState({ visited: true });
|
|
417
527
|
|
|
418
|
-
|
|
419
|
-
instance.setState({
|
|
420
|
-
empty: !inputValue,
|
|
421
|
-
});
|
|
422
|
-
}
|
|
528
|
+
let value = null;
|
|
423
529
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
530
|
+
if (inputValue) {
|
|
531
|
+
let displayValue = widget.parseValue(inputValue, instance);
|
|
532
|
+
if (isNaN(displayValue)) {
|
|
533
|
+
instance.setState({
|
|
534
|
+
inputError: instance.widget.inputErrorText,
|
|
535
|
+
});
|
|
536
|
+
return;
|
|
428
537
|
}
|
|
429
538
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
if (
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
if (data.minValue != null) {
|
|
460
|
-
if (data.minExclusive) {
|
|
461
|
-
if (value <= data.minValue) return;
|
|
462
|
-
} else {
|
|
463
|
-
value = Math.max(value, data.minValue);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
if (data.maxValue != null) {
|
|
468
|
-
if (data.maxExclusive) {
|
|
469
|
-
if (value >= data.maxValue) return;
|
|
470
|
-
} else {
|
|
471
|
-
value = Math.min(value, data.maxValue);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
if (data.constrain) {
|
|
477
|
-
if (data.minValue != null) {
|
|
478
|
-
if (value < data.minValue) {
|
|
479
|
-
value = data.minValue;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
if (data.maxValue != null) {
|
|
484
|
-
if (value > data.maxValue) {
|
|
485
|
-
value = data.maxValue;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
let fmt = data.format;
|
|
491
|
-
let decimalSeparator = this.getDecimalSeparator(fmt) || Format.value(1.1, "n;1")[1];
|
|
492
|
-
|
|
493
|
-
let formatted = Format.value(value, fmt);
|
|
494
|
-
// Re-parse to avoid differences between formatted value and value in the store
|
|
495
|
-
|
|
496
|
-
value = widget.parseValue(formatted, instance) * data.scale + data.offset;
|
|
497
|
-
|
|
498
|
-
// Allow users to type numbers like 100.0003 or -0.05 without interruptions
|
|
499
|
-
// If the last typed character is zero or dot (decimal separator), skip processing it
|
|
500
|
-
let selectionEnd = this.input!.selectionEnd;
|
|
501
|
-
if (
|
|
502
|
-
change == "change" &&
|
|
503
|
-
this.input!.selectionStart == selectionEnd &&
|
|
504
|
-
selectionEnd != null &&
|
|
505
|
-
selectionEnd >= this.getLengthWithoutSuffix(this.input!.value, decimalSeparator) &&
|
|
506
|
-
(inputValue[selectionEnd - 1] == decimalSeparator ||
|
|
507
|
-
(inputValue.indexOf(decimalSeparator) >= 0 && inputValue[selectionEnd - 1] == "0") ||
|
|
508
|
-
(selectionEnd == 2 && inputValue[0] === "-" && inputValue[1] === "0"))
|
|
509
|
-
)
|
|
510
|
-
return;
|
|
511
|
-
|
|
512
|
-
if (change != "blur") {
|
|
513
|
-
// Format, but keep the correct cursor position
|
|
514
|
-
let preCursorText = this.getPreCursorDigits(
|
|
515
|
-
this.input!.value,
|
|
516
|
-
this.input!.selectionStart!,
|
|
517
|
-
decimalSeparator,
|
|
518
|
-
);
|
|
519
|
-
this.input!.value = formatted;
|
|
520
|
-
this.updateCursorPosition(preCursorText);
|
|
521
|
-
} else {
|
|
522
|
-
this.input!.value = formatted;
|
|
523
|
-
}
|
|
539
|
+
value = displayValue * data.scale + data.offset;
|
|
540
|
+
|
|
541
|
+
if (change == "wheel") {
|
|
542
|
+
e.preventDefault();
|
|
543
|
+
let increment =
|
|
544
|
+
data.increment != null
|
|
545
|
+
? data.increment
|
|
546
|
+
: this.calculateIncrement(value, data.incrementPercentage);
|
|
547
|
+
let deltaY = (e as React.WheelEvent<HTMLInputElement>).deltaY;
|
|
548
|
+
value = value + (deltaY < 0 ? increment : -increment);
|
|
549
|
+
if (widget.snapToIncrement) {
|
|
550
|
+
value = Math.round(value / increment) * increment;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
if (data.minValue != null) {
|
|
554
|
+
if (data.minExclusive) {
|
|
555
|
+
if (value <= data.minValue) return;
|
|
556
|
+
} else {
|
|
557
|
+
value = Math.max(value, data.minValue);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (data.maxValue != null) {
|
|
562
|
+
if (data.maxExclusive) {
|
|
563
|
+
if (value >= data.maxValue) return;
|
|
564
|
+
} else {
|
|
565
|
+
value = Math.min(value, data.maxValue);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
524
568
|
}
|
|
525
569
|
|
|
526
|
-
|
|
570
|
+
if (data.constrain) {
|
|
571
|
+
if (data.minValue != null) {
|
|
572
|
+
if (value < data.minValue) {
|
|
573
|
+
value = data.minValue;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
if (data.maxValue != null) {
|
|
578
|
+
if (value > data.maxValue) {
|
|
579
|
+
value = data.maxValue;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
527
583
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
584
|
+
let fmt = data.format;
|
|
585
|
+
let decimalSeparator =
|
|
586
|
+
this.getDecimalSeparator(fmt) || Format.value(1.1, "n;1")[1];
|
|
587
|
+
|
|
588
|
+
let formatted = Format.value(value, fmt);
|
|
589
|
+
// Re-parse to avoid differences between formatted value and value in the store
|
|
590
|
+
|
|
591
|
+
value = widget.parseValue(formatted, instance) * data.scale + data.offset;
|
|
592
|
+
|
|
593
|
+
// Allow users to type numbers like 100.0003 or -0.05 without interruptions
|
|
594
|
+
// If the last typed character is zero or dot (decimal separator), skip processing it
|
|
595
|
+
let selectionEnd = this.input!.selectionEnd;
|
|
596
|
+
if (
|
|
597
|
+
change == "change" &&
|
|
598
|
+
this.input!.selectionStart == selectionEnd &&
|
|
599
|
+
selectionEnd != null &&
|
|
600
|
+
selectionEnd >=
|
|
601
|
+
this.getLengthWithoutSuffix(this.input!.value, decimalSeparator) &&
|
|
602
|
+
(inputValue[selectionEnd - 1] == decimalSeparator ||
|
|
603
|
+
(inputValue.indexOf(decimalSeparator) >= 0 &&
|
|
604
|
+
inputValue[selectionEnd - 1] == "0") ||
|
|
605
|
+
(selectionEnd == 2 && inputValue[0] === "-" && inputValue[1] === "0"))
|
|
606
|
+
)
|
|
607
|
+
return;
|
|
608
|
+
|
|
609
|
+
if (change != "blur") {
|
|
610
|
+
// Format, but keep the correct cursor position
|
|
611
|
+
let preCursorText = this.getPreCursorDigits(
|
|
612
|
+
this.input!.value,
|
|
613
|
+
this.input!.selectionStart!,
|
|
614
|
+
decimalSeparator,
|
|
615
|
+
);
|
|
616
|
+
this.input!.value = formatted;
|
|
617
|
+
this.updateCursorPosition(preCursorText);
|
|
618
|
+
} else {
|
|
619
|
+
this.input!.value = formatted;
|
|
541
620
|
}
|
|
542
|
-
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
instance.set("value", value, { immediate });
|
|
624
|
+
|
|
625
|
+
instance.setState({
|
|
626
|
+
inputError: false,
|
|
627
|
+
visited: true,
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
onFocus(): void {
|
|
632
|
+
let { instance } = this.props;
|
|
633
|
+
let { widget } = instance;
|
|
634
|
+
if (widget.trackFocus) {
|
|
635
|
+
this.setState({
|
|
636
|
+
focus: true,
|
|
637
|
+
});
|
|
638
|
+
instance.set("focused", true);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
onBlur(e: React.FocusEvent<HTMLInputElement>): void {
|
|
643
|
+
let { instance } = this.props;
|
|
644
|
+
let { widget } = instance;
|
|
645
|
+
this.onChange(e, "blur");
|
|
646
|
+
if (widget.trackFocus && this.state.focus) {
|
|
647
|
+
this.setState({
|
|
648
|
+
focus: false,
|
|
649
|
+
});
|
|
650
|
+
instance.set("focused", false);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
543
653
|
}
|