zds-pickers 4.0.7 → 4.0.9

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.
Files changed (55) hide show
  1. package/dist/index.cjs.js +11 -11
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.es.js +1194 -1818
  4. package/dist/index.es.js.map +1 -1
  5. package/dist/types/index.d.ts +2 -0
  6. package/dist/types/midi/export.d.ts +8 -9
  7. package/dist/types/other/OctavePlayer.d.ts +7 -1
  8. package/dist/types/other/SVGText.d.ts +11 -0
  9. package/dist/types/other/SoundFontProvider.d.ts +1 -0
  10. package/dist/types/pickers/ChannelMappingPicker.d.ts +2 -1
  11. package/dist/types/pickers/StatusPicker.d.ts +2 -2
  12. package/lib/hooks/useComponentSize.js +40 -0
  13. package/lib/hooks/useStateWithDynamicDefault.js +9 -0
  14. package/lib/index.js +21 -0
  15. package/lib/index.ts +2 -0
  16. package/lib/midi/ccValues.js +134 -0
  17. package/lib/midi/export.js +27 -0
  18. package/lib/midi/export.ts +2 -3
  19. package/lib/other/DefaultTooltip.js +3 -0
  20. package/lib/other/OctavePlayer.js +48 -0
  21. package/lib/other/OctavePlayer.tsx +1 -1
  22. package/lib/other/SVGText.js +109 -0
  23. package/lib/other/SVGText.tsx +2 -0
  24. package/lib/other/SoundFontProvider.js +87 -0
  25. package/lib/other/SoundFontProvider.tsx +2 -0
  26. package/lib/pickers/CCPicker.js +6 -0
  27. package/lib/pickers/ChannelMappingPicker.js +50 -0
  28. package/lib/pickers/ChannelMappingPicker.tsx +5 -1
  29. package/lib/pickers/ChannelPicker.js +21 -0
  30. package/lib/pickers/Knob.js +49 -0
  31. package/lib/pickers/KnobPicker.js +29 -0
  32. package/lib/pickers/LatchPicker.js +9 -0
  33. package/lib/pickers/MappingPicker.js +37 -0
  34. package/lib/pickers/NotePicker.js +45 -0
  35. package/lib/pickers/PianoPicker.js +27 -0
  36. package/lib/pickers/PolarityPicker.js +11 -0
  37. package/lib/pickers/ResponseCurve.js +154 -0
  38. package/lib/pickers/ResponseCurvePicker.js +19 -0
  39. package/lib/pickers/Select.js +79 -0
  40. package/lib/pickers/StatusPicker.js +5 -0
  41. package/lib/pickers/ValuePicker.js +23 -0
  42. package/lib/pickers/knobSkin10.js +93 -0
  43. package/lib/rotaryKnob/InternalInput.js +22 -0
  44. package/lib/rotaryKnob/Types.js +1 -0
  45. package/lib/rotaryKnob/helpers/DrawCircle.js +9 -0
  46. package/lib/rotaryKnob/helpers/DrawLine.js +9 -0
  47. package/lib/rotaryKnob/helpers/HelpersOverlay.js +26 -0
  48. package/lib/rotaryKnob/helpers/KnobVisualHelpers.js +52 -0
  49. package/lib/rotaryKnob/index.js +244 -0
  50. package/lib/rotaryKnob/knobdefaultskin.js +56 -0
  51. package/lib/rotaryKnob/utils.js +106 -0
  52. package/lib/utils.js +21 -0
  53. package/package.json +2 -3
  54. package/tsconfig.json +1 -1
  55. package/vite.config.ts +3 -19
@@ -0,0 +1,50 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import cl from 'classnames';
3
+ import { forwardRef, useCallback, useEffect, useState } from 'react';
4
+ import { arraySequence } from '../utils';
5
+ import Select from './Select';
6
+ const defaultOptions = arraySequence(16).map(value => ({
7
+ value,
8
+ label: value,
9
+ }));
10
+ const ChannelMappingPicker = forwardRef(({ channels, className, ...rest }, ref) => {
11
+ const [options, setOptions] = useState([]);
12
+ const formatOptionLabel = useCallback(({ value, label }, { context }) => {
13
+ if (value === 'separator') {
14
+ return _jsx("span", { className: "zds-mappings-user-mapping", children: label });
15
+ }
16
+ if (typeof value !== 'number')
17
+ return null;
18
+ const mapping = channels[value];
19
+ return mapping ? (_jsxs("span", { className: "mapping-entry", children: [_jsxs("b", { children: [value + 1, context === 'value' && ' -'] }), _jsx("span", { className: "mapping-entry-label", children: mapping.label })] })) : (_jsxs("span", { className: "mapping-entry empty-mapping-entry", children: [_jsxs("b", { children: [value + 1, context === 'value' && ' -'] }), _jsx("span", { className: "mapping-entry-label", children: "no mapping" })] }));
20
+ }, [channels]);
21
+ useEffect(() => {
22
+ const result = defaultOptions.sort((a, b) => {
23
+ if (typeof a.value === 'number' &&
24
+ typeof b.value === 'number' &&
25
+ channels[a.value] &&
26
+ !channels[b.value]) {
27
+ return -1;
28
+ }
29
+ if (typeof a.value === 'number' &&
30
+ typeof b.value === 'number' &&
31
+ !channels[a.value] &&
32
+ channels[b.value]) {
33
+ return 1;
34
+ }
35
+ if (typeof a.value === 'number' && typeof b.value === 'number') {
36
+ return a.value - b.value;
37
+ }
38
+ return 0;
39
+ });
40
+ const numFilled = result.filter(({ value }) => typeof value === 'number' && !!channels[value]).length;
41
+ const separatorExists = result.some(({ value }) => value === 'separator');
42
+ if (numFilled && numFilled < 16 && !separatorExists) {
43
+ // insert a separator after the count of filled items
44
+ result.splice(numFilled, 0, { label: _jsx("hr", {}), value: 'separator' });
45
+ }
46
+ setOptions(result);
47
+ }, [channels]);
48
+ return (_jsx(Select, { ...rest, className: cl(className, 'channel-mapping-picker'), formatOptionLabel: formatOptionLabel, options: options, ref: ref }));
49
+ });
50
+ export default ChannelMappingPicker;
@@ -132,4 +132,8 @@ const ChannelMappingPicker = forwardRef<
132
132
 
133
133
  export default ChannelMappingPicker
134
134
 
135
- export type { ChannelMappingPickerProps, ChannelMappingPickerRef }
135
+ export type {
136
+ ChannelMappingOption,
137
+ ChannelMappingPickerProps,
138
+ ChannelMappingPickerRef,
139
+ }
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import cl from 'classnames';
3
+ import { forwardRef } from 'react';
4
+ import { arraySequence } from '../utils';
5
+ import Select from './Select';
6
+ const options = arraySequence(16).map(value => ({
7
+ value: value,
8
+ label: `Channel ${value + 1}`,
9
+ }));
10
+ const formatOptionLabel = (option, { context }) => context === 'value' ? option.label : Number.parseInt(String(option.value)) + 1; // menu, e.g. the list of options
11
+ const filterOptions = (option, input) => {
12
+ // console.log(option, input)
13
+ if (input) {
14
+ return String(option.label).toLowerCase().includes(input.toLowerCase());
15
+ }
16
+ return true;
17
+ };
18
+ const ChannelPicker = forwardRef(({ className, ...rest }, ref) => {
19
+ return (_jsx(Select, { ...rest, className: cl(className, 'channel-picker'), filterOptions: filterOptions, formatOptionLabel: formatOptionLabel, options: options, ref: ref }));
20
+ });
21
+ export default ChannelPicker;
@@ -0,0 +1,49 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback } from 'react';
3
+ import useStateWithDynamicDefault from '../hooks/useStateWithDynamicDefault';
4
+ import RotaryKnob from '../rotaryKnob';
5
+ import { assertRange } from '../utils';
6
+ import knobSkin10 from './knobSkin10';
7
+ const Knob = (props) => {
8
+ const { disabled = false, max = 127, min = 0, onChange, value: initialValue = 0, wheelEnabled = false, wheelSensitivity = 0.1, ...rest } = props;
9
+ const [value, setValue] = useStateWithDynamicDefault(initialValue);
10
+ const handleChange = (val) => {
11
+ if (disabled)
12
+ return;
13
+ const newValue = assertRange(Number.parseInt(String(val), 10), max, min);
14
+ setValue(newValue);
15
+ if (onChange) {
16
+ onChange(newValue);
17
+ }
18
+ };
19
+ const handleWheel = useCallback((event) => {
20
+ if (!wheelEnabled || disabled)
21
+ return;
22
+ event.preventDefault();
23
+ const delta = -event.deltaY * wheelSensitivity;
24
+ const newValue = assertRange(value + delta, max, min);
25
+ setValue(newValue);
26
+ if (onChange) {
27
+ onChange(newValue);
28
+ }
29
+ }, [
30
+ wheelEnabled,
31
+ disabled,
32
+ wheelSensitivity,
33
+ value,
34
+ max,
35
+ min,
36
+ onChange,
37
+ setValue,
38
+ ]);
39
+ return (_jsx(RotaryKnob, { clampMax: 320, clampMin: 40, className: "zds-pickers__knob-container", disabled: disabled, onChange: handleChange, onWheel: wheelEnabled ? handleWheel : undefined, preciseMode: false, rotateDegrees: 180,
40
+ /**
41
+ * To see all skins:
42
+ * http://react-rotary-knob-skins-preview.surge.sh/
43
+ *
44
+ * NOTE: we've copied the one we use into this package because the skins
45
+ * pack package does not work in Electron.
46
+ */
47
+ skin: knobSkin10, style: { opacity: disabled ? 0.4 : 1 }, unlockDistance: 0, defaultValue: value, max, min, value, ...rest }));
48
+ };
49
+ export default Knob;
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useMemo } from 'react';
3
+ import { arraySequence } from '../utils';
4
+ import Knob from './Knob';
5
+ import Select from './Select';
6
+ const KnobPicker = forwardRef((props, ref) => {
7
+ const { disabled, highToLow, includeLabel, includePicker, knobProps, label, max = 127, min = 0, onChange, shrinkLabel, value = 0, wheelEnabled, wheelSensitivity = 0.1, ...rest } = props;
8
+ const options = useMemo(() => {
9
+ const result = arraySequence(max - min + 1)
10
+ .map(i => min + i)
11
+ .map((i) => ({ value: i, label: String(i) }));
12
+ return highToLow ? result.reverse() : result;
13
+ }, [highToLow, max, min]);
14
+ return (_jsxs("div", { className: "zds-pickers__container", children: [Boolean(!shrinkLabel && Boolean(label)) && (_jsx("span", { className: "zds-pickers__label", children: label })), _jsxs("div", { style: { display: 'inline-flex', gap: 10, alignItems: 'center' }, children: [Boolean(includePicker) && (_jsx(Select, { ...rest,
15
+ disabled,
16
+ isDisabled: disabled,
17
+ onChange,
18
+ options,
19
+ ref,
20
+ value })), _jsx(Knob, { disabled,
21
+ max,
22
+ min,
23
+ onChange,
24
+ value,
25
+ wheelEnabled,
26
+ wheelSensitivity,
27
+ ...knobProps })] })] }));
28
+ });
29
+ export default KnobPicker;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from 'react';
3
+ import Select from './Select';
4
+ const options = [
5
+ { value: 0, label: 'Momentary' },
6
+ { value: 1, label: 'Latching' },
7
+ ];
8
+ const LatchPicker = forwardRef((props, ref) => (_jsx(Select, { ...props, options: options, ref: ref })));
9
+ export default LatchPicker;
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useMemo } from 'react';
3
+ import { getStockNames, getUserMappingNames } from 'zds-mappings';
4
+ import Select from './Select';
5
+ const MappingPicker = forwardRef(({ allowClearing, ...rest }, ref) => {
6
+ const stockMappings = getStockNames();
7
+ const userMappings = getUserMappingNames();
8
+ const options = useMemo(() => {
9
+ const result = allowClearing
10
+ ? [
11
+ {
12
+ value: 'No Mapping',
13
+ label: (_jsx("span", { className: "zds-mappings-clear-mapping", children: "No Mapping" })),
14
+ },
15
+ ]
16
+ : [];
17
+ return [
18
+ ...result,
19
+ {
20
+ label: allowClearing ? _jsx("hr", {}) : '',
21
+ options: userMappings.map(label => ({
22
+ value: label,
23
+ label: _jsx("span", { className: "zds-mappings-user-mapping", children: label }),
24
+ })),
25
+ },
26
+ {
27
+ label: userMappings.length ? _jsx("hr", {}) : allowClearing ? _jsx("hr", {}) : '',
28
+ options: stockMappings.map(label => ({
29
+ label,
30
+ value: label,
31
+ })),
32
+ },
33
+ ];
34
+ }, [allowClearing, stockMappings, userMappings]);
35
+ return (_jsx(Select, { ...rest, options: options, ref: ref }));
36
+ });
37
+ export default MappingPicker;
@@ -0,0 +1,45 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useCallback, useMemo } from 'react';
3
+ import { Midi } from 'tonal';
4
+ import { emptyMapping } from 'zds-mappings';
5
+ import useStateWithDynamicDefault from '../hooks/useStateWithDynamicDefault';
6
+ import { assertRange } from '../utils';
7
+ import Select from './Select';
8
+ const { midiToNoteName } = Midi;
9
+ const formattedMapEntry = ({ note, name }) => `${note} ${name.length ? '-' : ''} ${name}`;
10
+ const formattedListEntry = (label, idx) => ({
11
+ label,
12
+ value: idx + 1,
13
+ });
14
+ const NotePicker = forwardRef((props, ref) => {
15
+ const { channel, disabled = false, isMelodicMode = false, mapping, onChange, value: initialValue, ...rest } = props;
16
+ const options = useMemo(() => {
17
+ if (isMelodicMode) {
18
+ return emptyMapping()
19
+ .map(({ note }) => {
20
+ const midiNoteName = midiToNoteName(note, { sharps: false })
21
+ .replace('b', '♭')
22
+ .replace('#', '♯');
23
+ return `${midiNoteName} (#${note})`;
24
+ })
25
+ .map(formattedListEntry);
26
+ }
27
+ return (mapping || emptyMapping())
28
+ .map(formattedMapEntry)
29
+ .map(formattedListEntry);
30
+ }, [isMelodicMode, mapping]);
31
+ const [value, setValue] = useStateWithDynamicDefault(initialValue);
32
+ const handleChange = useCallback((v) => {
33
+ if (typeof v === 'string')
34
+ return;
35
+ const possibleNoteNumber = assertRange(v, 128, 0);
36
+ if (possibleNoteNumber > 0) {
37
+ onChange(possibleNoteNumber);
38
+ }
39
+ setValue(v);
40
+ }, [onChange, setValue]);
41
+ return (_jsx(Select, { ...rest, disabled: disabled,
42
+ // isDisabled={disabled}
43
+ onChange: handleChange, options: options, ref: ref, value: value }));
44
+ });
45
+ export default NotePicker;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Piano as ReactPiano } from 'zds-react-piano';
3
+ import SoundfontProvider from '../other/SoundFontProvider';
4
+ const firstNote = 21;
5
+ const lastNote = 108;
6
+ const numNotes = lastNote - firstNote - 1;
7
+ const whiteNotes = numNotes * 0.7; // approx
8
+ const audioContext = new window.AudioContext();
9
+ const PianoPicker = ({ height, width, ...rest }) => {
10
+ const keyWidth = width / whiteNotes + 2;
11
+ const keyWidthToHeight = keyWidth / height;
12
+ return (_jsx("div", { children: _jsx(ReactPiano, { keyWidthToHeight: keyWidthToHeight, noteRange: { first: firstNote, last: lastNote }, width: width, ...rest }) }));
13
+ };
14
+ const WithProvider = ({ format, height, hostname, instrumentName, onChange, onClick, onDoubleClick, onKeyMouseEnter, onKeyMouseLeave, soundfont, width, }) => (_jsx(SoundfontProvider, { audioContext,
15
+ format,
16
+ hostname,
17
+ instrumentName,
18
+ onChange,
19
+ soundfont, render: ({ isLoading, playNote, stopNote }) => (_jsx(PianoPicker, { disabled: isLoading, height,
20
+ onClick,
21
+ onDoubleClick,
22
+ onKeyMouseEnter,
23
+ onKeyMouseLeave,
24
+ playNote,
25
+ stopNote,
26
+ width })) }));
27
+ export default WithProvider;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from 'react';
3
+ import Select from './Select';
4
+ const PolarityPicker = forwardRef(({ labelOff = 'Normally Off', labelOn = 'Normally On', ...rest }, ref) => {
5
+ const options = [
6
+ { value: 0, label: labelOff },
7
+ { value: 1, label: labelOn },
8
+ ];
9
+ return (_jsx(Select, { ...rest, options: options, ref: ref }));
10
+ });
11
+ export default PolarityPicker;
@@ -0,0 +1,154 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef } from 'react';
3
+ import useComponentSize from '../hooks/useComponentSize';
4
+ import DefaultTooltip from '../other/DefaultTooltip';
5
+ import SVGText from '../other/SVGText';
6
+ const RESPONSE_CURVE_0 = 0;
7
+ const RESPONSE_CURVE_1 = 1;
8
+ const RESPONSE_CURVE_2 = 2;
9
+ const RESPONSE_CURVE_3 = 3;
10
+ const RESPONSE_CURVE_4 = 4;
11
+ const RESPONSE_CURVE_5 = 5;
12
+ const RESPONSE_CURVE_6 = 6;
13
+ const RESPONSE_CURVE_7 = 7;
14
+ const RESPONSE_CURVES = [
15
+ {
16
+ value: RESPONSE_CURVE_7,
17
+ label: 'Always maxed out.',
18
+ },
19
+ {
20
+ value: RESPONSE_CURVE_6,
21
+ label: 'Most sensitive.',
22
+ },
23
+ {
24
+ value: RESPONSE_CURVE_5,
25
+ label: 'Moderately sensitive.',
26
+ },
27
+ {
28
+ value: RESPONSE_CURVE_4,
29
+ label: 'A little sensitive.',
30
+ },
31
+ {
32
+ value: RESPONSE_CURVE_0,
33
+ label: 'Linear, no change.',
34
+ },
35
+ {
36
+ value: RESPONSE_CURVE_1,
37
+ label: 'A little less sensitive.',
38
+ },
39
+ {
40
+ value: RESPONSE_CURVE_2,
41
+ label: 'Even less sensitive.',
42
+ },
43
+ {
44
+ value: RESPONSE_CURVE_3,
45
+ label: 'Least sensitive.',
46
+ },
47
+ ];
48
+ // const width = 218
49
+ // const height = 150
50
+ const axisOffset = 20;
51
+ const buttonSize = 15;
52
+ const axisX1 = axisOffset;
53
+ const axisY1 = axisOffset;
54
+ const ResponseCurve = (props) => {
55
+ const { Tooltip = DefaultTooltip, autosize, disabled, inverted, onChange, value: responseCurve, } = props;
56
+ const ref = useRef(null);
57
+ const svgRef = useRef(null);
58
+ const { height: ourHeight, width: ourWidth } = useComponentSize(ref);
59
+ const width = autosize ? ourWidth || 218 : 218;
60
+ const height = autosize ? ourHeight || 150 : 150;
61
+ const axisX2 = width - axisOffset;
62
+ const axisY2 = height - axisOffset;
63
+ const xMid = width / 2;
64
+ const yMid = height / 2;
65
+ const svgProps = { ref: svgRef };
66
+ const responseCurves = RESPONSE_CURVES.map(
67
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
68
+ ({ value, label }) => {
69
+ let c1 = 0;
70
+ let c2 = 0;
71
+ let x1 = axisX1;
72
+ let y1 = inverted ? axisY1 : axisY2;
73
+ let x2 = axisX2;
74
+ let y2 = inverted ? axisY2 : axisY1;
75
+ let labelX = xMid;
76
+ let labelY = yMid;
77
+ switch (value) {
78
+ case RESPONSE_CURVE_0:
79
+ c1 = xMid;
80
+ c2 = yMid;
81
+ labelY += 3;
82
+ break;
83
+ case RESPONSE_CURVE_1:
84
+ c1 = inverted ? xMid + width * 0.13 : xMid - width * 0.13;
85
+ c2 = yMid - height * 0.13;
86
+ labelX = inverted ? xMid + width * 0.1 : xMid - width * 0.1;
87
+ labelY = yMid - height * 0.09;
88
+ break;
89
+ case RESPONSE_CURVE_2:
90
+ c1 = inverted ? xMid + width * 0.25 : xMid - width * 0.25;
91
+ c2 = yMid - height * 0.25;
92
+ labelX = inverted ? xMid + width * 0.2 : xMid - width * 0.2;
93
+ labelY = yMid - height * 0.17;
94
+ break;
95
+ case RESPONSE_CURVE_3:
96
+ c1 = inverted ? xMid + width * 0.35 : xMid - width * 0.35;
97
+ c2 = yMid - height * 0.35;
98
+ labelX = inverted ? xMid + width * 0.28 : xMid - width * 0.28;
99
+ labelY = yMid - height * 0.25;
100
+ break;
101
+ case RESPONSE_CURVE_4:
102
+ c1 = inverted ? xMid - width * 0.13 : xMid + width * 0.13;
103
+ c2 = yMid + height * 0.13;
104
+ labelX = inverted ? xMid - width * 0.1 : xMid + width * 0.1;
105
+ labelY = yMid + height * 0.1;
106
+ break;
107
+ case RESPONSE_CURVE_5:
108
+ c1 = inverted ? xMid - width * 0.25 : xMid + width * 0.25;
109
+ c2 = yMid + height * 0.25;
110
+ labelX = inverted ? xMid - width * 0.2 : xMid + width * 0.2;
111
+ labelY = yMid + height * 0.18;
112
+ break;
113
+ case RESPONSE_CURVE_6:
114
+ c1 = inverted ? xMid - width * 0.35 : xMid + width * 0.35;
115
+ c2 = yMid + height * 0.35;
116
+ labelX = inverted ? xMid - width * 0.28 : xMid + width * 0.28;
117
+ labelY = yMid + height * 0.25;
118
+ break;
119
+ case RESPONSE_CURVE_7:
120
+ x1 = inverted ? axisX1 : axisX2;
121
+ y1 = axisY1;
122
+ x2 = x1;
123
+ y2 = axisY2;
124
+ c1 = x1;
125
+ c2 = yMid;
126
+ labelX = x1 - 5;
127
+ labelY = height - 30;
128
+ break;
129
+ default:
130
+ break;
131
+ }
132
+ return {
133
+ value,
134
+ label,
135
+ c1,
136
+ c2,
137
+ x1,
138
+ y1,
139
+ x2,
140
+ y2,
141
+ labelX,
142
+ labelY,
143
+ };
144
+ });
145
+ return (_jsx("div", { className: "response-curve-picker", ref: ref, children: _jsxs("svg", { ...svgProps, children: [_jsx("rect", { className: "container", height: height, rx: 3, ry: 3, width: width, x: 0, y: 0 }), _jsx(SVGText, { className: "axis", textAnchor: "middle", transform: `translate(${axisX1 - 14} ${height / 2}) rotate(90)`, x: 0, y: 0, text: "Applied force" }), _jsx(SVGText, { className: "axis", textAnchor: "middle", transform: `translate(${width / 2} ${axisY2 + 13})`, x: 0, y: 0, text: "Output (velocity)" }), _jsx("line", { className: "axis", x1: axisX1, x2: axisX1, y1: axisY1, y2: axisY2 }), _jsx("line", { className: "axis", x1: axisX1, x2: axisX2, y1: axisY2, y2: axisY2 }), responseCurves.map(({ value, label, x1, y1, x2, y2, c1, c2, labelX, labelY }) => (_jsxs("g", { children: [_jsx("path", { className: value === responseCurve ? 'curve-selected' : 'curve', d: `M${x1} ${y1} C ${c1} ${c2}, ${c1} ${c2}, ${x2} ${y2}` }), _jsx(Tooltip, { placement: "left", title: label, children: _jsx("rect", { className: value === responseCurve ? 'button-selected' : 'button', height: buttonSize, onClick: disabled
146
+ ? f => f
147
+ : () => onChange({
148
+ target: {
149
+ value: Number.parseInt(String(value)),
150
+ },
151
+ }), transform: `translate(${labelX + 3} ${labelY - buttonSize / 1.05}) rotate(45)`, width: buttonSize }) }), _jsxs("text", { className: value === responseCurve ? 'button-selected' : 'button', transform: `translate(${labelX} ${labelY})`, children: [value, _jsx("title", { children: label })] })] }, value)))] }) }));
152
+ };
153
+ export default ResponseCurve;
154
+ export { RESPONSE_CURVES };
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useCallback } from 'react';
3
+ import DefaultTooltip from '../other/DefaultTooltip';
4
+ import { findObj } from '../utils';
5
+ import ResponseCurve, { RESPONSE_CURVES } from './ResponseCurve';
6
+ import Select from './Select';
7
+ const ResponseCurvePicker = forwardRef((props, ref) => {
8
+ const { Tooltip = DefaultTooltip, inverted = false, onChange, value, ...rest } = props;
9
+ const Placeholder = useCallback(() => (_jsx("div", { className: "singleValue", children: findObj('value', value)(RESPONSE_CURVES)?.label })), [value]);
10
+ const MenuList = useCallback(({ setValue }) => (_jsx(ResponseCurve, { autosize: true, inverted: inverted, onChange: ({ target: { value: v } }) => {
11
+ setValue(v);
12
+ onChange(v);
13
+ }, Tooltip: Tooltip, value: Number.parseInt(String(value)) })), [Tooltip, inverted, onChange, value]);
14
+ return (_jsx(Select, { ...rest, components: {
15
+ Placeholder,
16
+ MenuList,
17
+ }, isSearchable: false, onChange: f => f, ref: ref, value: value }));
18
+ });
19
+ export default ResponseCurvePicker;
@@ -0,0 +1,79 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { Children, forwardRef, isValidElement, useCallback, useMemo, } from 'react';
3
+ import ReactSelect, { components as originalComponents, } from 'react-select';
4
+ import { omit } from '../utils';
5
+ const { IndicatorsContainer, Placeholder, ValueContainer } = originalComponents;
6
+ const CustomIndicatorsContainer = ({ children, ...rest }) => {
7
+ const actionButton = rest.selectProps?.actionButton;
8
+ return (_jsx(IndicatorsContainer, { ...rest, children: _jsxs("div", { onMouseDown: e => {
9
+ e.stopPropagation();
10
+ e.preventDefault();
11
+ }, style: { display: 'flex' }, children: [actionButton, children] }) }));
12
+ };
13
+ const CustomValueContainer = ({ children, ...props }) => (_jsxs(ValueContainer, { ...props, children: [_jsx(Placeholder, { ...props, innerProps: props.innerProps || {}, className: props.hasValue || props.selectProps.inputValue ? 'shrunk' : '', isFocused: props.isFocused ?? false, children: props.selectProps.placeholder }), Children.map(children, child => isValidElement(child) && child.type !== Placeholder ? child : null)] }));
14
+ const Select = forwardRef((props, ref) => {
15
+ const { components, disabled, label, onChange, options = [], preserveMenuWidth, shrinkLabel, value, ...rest } = props;
16
+ const handleChange = useCallback((option) => {
17
+ if (option) {
18
+ onChange(option.value);
19
+ }
20
+ }, [onChange]);
21
+ const flatOptionsList = options.reduce((acc, entry) => {
22
+ if ('entries' in entry) {
23
+ return acc.concat(entry.entries);
24
+ }
25
+ return acc.concat(entry);
26
+ }, []);
27
+ const selectedOption = flatOptionsList.find(option => value === option.value) || undefined;
28
+ const styles = useMemo(() => {
29
+ const base = preserveMenuWidth
30
+ ? {
31
+ menu: (base) => omit('width')(base),
32
+ menuList: (base) => ({
33
+ ...base,
34
+ overflowX: 'hidden',
35
+ }),
36
+ option: (base) => ({
37
+ ...base,
38
+ whiteSpace: 'nowrap',
39
+ paddingRight: 10,
40
+ }),
41
+ }
42
+ : {};
43
+ return shrinkLabel
44
+ ? {
45
+ ...base,
46
+ container: (provided /* , state */) => ({
47
+ ...provided,
48
+ marginTop: 10,
49
+ }),
50
+ placeholder: (_provided, state) => ({
51
+ position: 'absolute',
52
+ left: state.hasValue || state.selectProps.inputValue ? -2 : '4%',
53
+ top: state.hasValue || state.selectProps.inputValue ? -12 : '50%',
54
+ transition: 'top 0.1s, font-size 0.1s, color 0.1s',
55
+ fontSize: (state.hasValue || state.selectProps.inputValue) && 13,
56
+ }),
57
+ valueContainer: (provided /* , state */) => ({
58
+ ...provided,
59
+ overflow: 'visible',
60
+ }),
61
+ }
62
+ : {
63
+ ...base,
64
+ };
65
+ }, [preserveMenuWidth, shrinkLabel]);
66
+ return shrinkLabel ? (_jsx("div", { className: "zds-pickers__container", children: _jsx(ReactSelect, { ...rest, classNamePrefix: "zds-pickers", components: {
67
+ IndicatorsContainer: CustomIndicatorsContainer,
68
+ ValueContainer: CustomValueContainer,
69
+ ...components,
70
+ }, isDisabled: disabled, onChange: handleChange, options: flatOptionsList, placeholder: label,
71
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
72
+ ref: ref, styles: styles, value: selectedOption }) })) : (_jsxs("div", { className: "zds-pickers__container", children: [Boolean(label) && _jsx("span", { className: "zds-pickers__label", children: label }), _jsx(ReactSelect, { ...rest, classNamePrefix: "zds-pickers", components: {
73
+ IndicatorsContainer: CustomIndicatorsContainer,
74
+ ...components,
75
+ }, isDisabled: disabled, onChange: handleChange, options: flatOptionsList,
76
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
77
+ ref: ref, styles: styles, value: selectedOption })] }));
78
+ });
79
+ export default Select;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from 'react';
3
+ import Select from './Select';
4
+ const StatusPicker = forwardRef(({ statuses, ...rest }, ref) => (_jsx(Select, { ...rest, options: statuses, ref: ref })));
5
+ export default StatusPicker;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useCallback, useMemo } from 'react';
3
+ import useStateWithDynamicDefault from '../hooks/useStateWithDynamicDefault';
4
+ import { arraySequence, assertRange } from '../utils';
5
+ import Select from './Select';
6
+ const ValuePicker = forwardRef((props, ref) => {
7
+ const { disabled, highToLow, max = 127, min = 0, onChange, value: initialValue = 0, ...rest } = props;
8
+ const options = useMemo(() => {
9
+ const result = arraySequence(max - min + 1)
10
+ .map(i => min + i)
11
+ .map(value => ({ value, label: value }));
12
+ return (highToLow
13
+ ? result.reverse()
14
+ : result);
15
+ }, [highToLow, max, min]);
16
+ const [value, setValue] = useStateWithDynamicDefault(initialValue);
17
+ const handleChange = useCallback((v) => {
18
+ onChange(assertRange(v, max, min));
19
+ setValue(Number.parseInt(String(v), 10));
20
+ }, [max, min, onChange, setValue]);
21
+ return (_jsx(Select, { ...rest, disabled: disabled, onChange: handleChange, options: options, ref: ref, value: value }));
22
+ });
23
+ export default ValuePicker;