zds-pickers 3.11.2 → 4.0.0

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 (38) hide show
  1. package/dist/index.cjs.js +196 -0
  2. package/dist/index.cjs.js.map +1 -0
  3. package/dist/index.es.js +23698 -0
  4. package/dist/index.es.js.map +1 -0
  5. package/dist/main.d.ts +232 -0
  6. package/package.json +56 -65
  7. package/dist/hooks/useComponentSize.js +0 -54
  8. package/dist/hooks/useStateWithDynamicDefault.js +0 -11
  9. package/dist/index.js +0 -43
  10. package/dist/midi/ccValues.js +0 -137
  11. package/dist/midi/statuses.js +0 -33
  12. package/dist/other/DefaultTooltip.js +0 -8
  13. package/dist/other/OctavePlayer.js +0 -121
  14. package/dist/other/SVGText.js +0 -116
  15. package/dist/other/SoundFontProvider.js +0 -124
  16. package/dist/other/utils.js +0 -52
  17. package/dist/pickers/CCPicker.js +0 -19
  18. package/dist/pickers/ChannelMappingPicker.js +0 -79
  19. package/dist/pickers/ChannelPicker.js +0 -40
  20. package/dist/pickers/Knob.js +0 -86
  21. package/dist/pickers/KnobPicker.js +0 -101
  22. package/dist/pickers/LatchPicker.js +0 -23
  23. package/dist/pickers/MappingPicker.js +0 -61
  24. package/dist/pickers/NotePicker.js +0 -83
  25. package/dist/pickers/PianoPicker.js +0 -104
  26. package/dist/pickers/PolarityPicker.js +0 -32
  27. package/dist/pickers/ResponseCurve.js +0 -263
  28. package/dist/pickers/ResponseCurvePicker.js +0 -58
  29. package/dist/pickers/Select.js +0 -174
  30. package/dist/pickers/StatusPicker.js +0 -22
  31. package/dist/pickers/ValuePicker.js +0 -57
  32. package/dist/pickers/knobSkin10.js +0 -94
  33. package/dist/shapes.js +0 -11
  34. package/dist/stories/assets/General MIDI.js +0 -69
  35. package/dist/stories/assets/mapper.js +0 -82
  36. package/dist/stories/assets/utils.js +0 -6
  37. package/dist/temp/acoustic_grand_piano-mp3.js +0 -94
  38. package/dist/utils.js +0 -45
@@ -1,121 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";var _excluded = ["octave", "height", "width"];import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { /* Midi, */Note } from 'tonal';
4
- import { Piano as ReactPiano } from 'zds-react-piano';
5
- import SoundfontProvider from './SoundFontProvider';
6
- import DefaultTooltip from './DefaultTooltip';
7
-
8
- var baseNotes = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B'];
9
-
10
- // const { midiToFreq, midiToNoteName } = Midi
11
-
12
- // console.log(Note.names(), Note.midi('C4'))
13
-
14
- // const firstNote = 21
15
- // const lastNote = 108
16
- var numNotes = 12;
17
-
18
- var whiteNotes = numNotes * 0.7; // approx
19
-
20
- var audioContext = new (window.AudioContext || window.webkitAudioContext)();
21
-
22
- var OctavePlayer = function OctavePlayer(_ref) {var octave = _ref.octave,height = _ref.height,width = _ref.width,rest = _objectWithoutProperties(_ref, _excluded);
23
- var keyWidth = width / whiteNotes + 2;
24
- var keyWidthToHeight = keyWidth / height;
25
-
26
- var firstNote = Note.midi(baseNotes[0] + String(octave));
27
- var lastNote = Note.midi(baseNotes[baseNotes.length - 1] + String(octave));
28
-
29
- return /*#__PURE__*/(
30
- React.createElement("div", null, /*#__PURE__*/
31
- React.createElement(ReactPiano, _extends({
32
- keyWidthToHeight: keyWidthToHeight,
33
- noteRange: { first: firstNote, last: lastNote },
34
- width: width },
35
- rest)
36
- )
37
- ));
38
-
39
- };
40
-
41
- var WithProvider = function WithProvider(_ref2) {var
42
- format = _ref2.format,
43
- height = _ref2.height,
44
- hostname = _ref2.hostname,
45
- instrumentName = _ref2.instrumentName,
46
- octave = _ref2.octave,
47
- onChange = _ref2.onChange,
48
- onClick = _ref2.onClick,
49
- onDoubleClick = _ref2.onDoubleClick,
50
- onKeyMouseEnter = _ref2.onKeyMouseEnter,
51
- onKeyMouseLeave = _ref2.onKeyMouseLeave,
52
- soundfont = _ref2.soundfont,
53
- Tooltip = _ref2.Tooltip,
54
- width = _ref2.width;return /*#__PURE__*/(
55
-
56
- React.createElement(SoundfontProvider, {
57
-
58
- audioContext: audioContext,
59
- format: format,
60
- hostname: hostname,
61
- instrumentName: instrumentName,
62
- onChange: onChange,
63
- soundfont: soundfont,
64
-
65
- render: function render(_ref3) {var isLoading = _ref3.isLoading,playNote = _ref3.playNote,stopNote = _ref3.stopNote;return /*#__PURE__*/(
66
- React.createElement(OctavePlayer, {
67
- disabled: isLoading,
68
-
69
- height: height,
70
- octave: octave,
71
- onClick: onClick,
72
- onDoubleClick: onDoubleClick,
73
- onKeyMouseEnter: onKeyMouseEnter,
74
- onKeyMouseLeave: onKeyMouseLeave,
75
- playNote: playNote,
76
- stopNote: stopNote,
77
- Tooltip: Tooltip,
78
- width: width }
79
-
80
- ));} }
81
-
82
- ));};
83
-
84
-
85
- OctavePlayer.propTypes = {
86
- height: PropTypes.number.isRequired,
87
- octave: PropTypes.number.isRequired,
88
- width: PropTypes.number.isRequired
89
- };
90
-
91
- WithProvider.propTypes = {
92
- format: PropTypes.oneOf(['mp3', 'ogg']),
93
- height: PropTypes.number.isRequired,
94
- hostname: PropTypes.string,
95
- instrumentName: PropTypes.string,
96
- octave: PropTypes.number,
97
- onChange: PropTypes.func,
98
- onClick: PropTypes.func,
99
- onDoubleClick: PropTypes.func,
100
- onKeyMouseEnter: PropTypes.func,
101
- onKeyMouseLeave: PropTypes.func,
102
- soundfont: PropTypes.oneOf(['MusyngKite', 'FluidR3_GM']),
103
- Tooltip: PropTypes.elementType,
104
- width: PropTypes.number.isRequired
105
- };
106
-
107
- WithProvider.defaultProps = {
108
- format: undefined, // 'mp3',
109
- hostname: undefined,
110
- instrumentName: undefined,
111
- octave: 4,
112
- onChange: undefined,
113
- onClick: undefined,
114
- onDoubleClick: undefined,
115
- onKeyMouseEnter: undefined,
116
- onKeyMouseLeave: undefined,
117
- soundfont: undefined, // 'MusyngKite',
118
- Tooltip: DefaultTooltip
119
- };
120
-
121
- export default WithProvider;
@@ -1,116 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";import _slicedToArray from "@babel/runtime/helpers/slicedToArray";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";var _excluded = ["children", "maxHeight", "maxWidth", "verticalAnchor"]; /* eslint-disable react/destructuring-assignment */
2
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
- import PropTypes from 'prop-types';
4
- import { numberOrString } from '../shapes';
5
- import { MEASUREMENT_ELEMENT_ID, calculateWordWidths, calculateWordsByLines } from './utils';
6
-
7
- var Text = function Text(props) {
8
- var children = props.children,maxHeight = props.maxHeight,maxWidth = props.maxWidth,verticalAnchor = props.verticalAnchor,rest = _objectWithoutProperties(props, _excluded);
9
- var _useState = useState(),_useState2 = _slicedToArray(_useState, 2),wordWidths = _useState2[0],setWordWidths = _useState2[1];
10
- var _useState3 = useState([]),_useState4 = _slicedToArray(_useState3, 2),textLines = _useState4[0],setTextLines = _useState4[1];
11
- var _useState5 = useState(),_useState6 = _slicedToArray(_useState5, 2),style = _useState6[0],setComputedStyle = _useState6[1];
12
- var measureRef = useRef();
13
- var displayedLines = useMemo(
14
- function () {return textLines.filter(function (_ref) {var showLine = _ref.showLine;return showLine;});},
15
- [textLines]
16
- );
17
- var ref = useCallback(function (node) {
18
- setComputedStyle(node !== null ? window.getComputedStyle(node) : '');
19
- }, []);
20
-
21
- useEffect(function () {
22
- var el = document.getElementById(MEASUREMENT_ELEMENT_ID);
23
- if (el === null) {
24
- var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
25
- svg.setAttribute('id', MEASUREMENT_ELEMENT_ID);
26
- document.body.appendChild(svg);
27
- svg.appendChild(document.createElementNS('http://www.w3.org/2000/svg', 'text'));
28
- measureRef.current = svg;
29
- } else {
30
- measureRef.current = el;
31
- }
32
- return function () {return el && document.body.contains(el) ? document.body.removeChild(el) : null;};
33
- }, []);
34
-
35
- useEffect(function () {
36
- var wordWithWidths = calculateWordWidths(style, measureRef.current.firstElementChild, children);
37
- setWordWidths(wordWithWidths);
38
- }, [children, style]);
39
-
40
- useEffect(function () {
41
- if (maxWidth && wordWidths) {
42
- var lines = calculateWordsByLines(children, wordWidths, maxWidth, maxHeight);
43
- setTextLines(lines);
44
- }
45
- }, [maxHeight, maxWidth, wordWidths, children]);
46
-
47
- var startDy = useMemo(function () {
48
- if (wordWidths !== null && wordWidths !== void 0 && wordWidths.lineHeight) {
49
- switch (verticalAnchor) {
50
- case 'start':
51
- return wordWidths.lineHeight;
52
-
53
- case 'middle':
54
- return -((displayedLines.length - 1) * wordWidths.lineHeight / 2);
55
-
56
- default:
57
- return -(displayedLines.length - 1) * wordWidths.lineHeight;
58
- }
59
- } else {
60
- return 0;
61
- }
62
- }, [displayedLines.length, verticalAnchor, wordWidths === null || wordWidths === void 0 ? void 0 : wordWidths.lineHeight]);
63
-
64
- return /*#__PURE__*/(
65
- React.createElement("text", _extends({
66
- ref: ref },
67
- rest),
68
-
69
- textLines.length <= 1 ?
70
- children : /*#__PURE__*/
71
-
72
- React.createElement(React.Fragment, null,
73
- displayedLines.map(function (line, idx) {return /*#__PURE__*/(
74
- React.createElement("tspan", {
75
- dx: props.x + props.dx,
76
- dy: idx === 0 ? startDy + props.dy : wordWidths.lineHeight,
77
- key: idx,
78
- x: 0 },
79
-
80
- line.words.join(' ')
81
- ));}
82
- ),
83
- displayedLines.length !== textLines.length && /*#__PURE__*/
84
- React.createElement(React.Fragment, null, /*#__PURE__*/
85
- React.createElement("tspan", null, "..."), /*#__PURE__*/
86
- React.createElement("title", null, children)
87
- )
88
-
89
- )
90
-
91
- ));
92
-
93
- };
94
-
95
- Text.propTypes = {
96
- children: PropTypes.node.isRequired,
97
- dx: PropTypes.number,
98
- dy: PropTypes.number,
99
- maxHeight: PropTypes.number,
100
- maxWidth: PropTypes.number,
101
- verticalAnchor: PropTypes.oneOf(['start', 'middle', 'end']),
102
- x: numberOrString,
103
- y: numberOrString
104
- };
105
-
106
- Text.defaultProps = {
107
- dx: 0,
108
- dy: 0,
109
- maxHeight: undefined,
110
- maxWidth: undefined,
111
- verticalAnchor: 'start',
112
- x: '50%',
113
- y: '50%'
114
- };
115
-
116
- export default Text;
@@ -1,124 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";import _slicedToArray from "@babel/runtime/helpers/slicedToArray";function ownKeys(e, r) {var t = Object.keys(e);if (Object.getOwnPropertySymbols) {var o = Object.getOwnPropertySymbols(e);r && (o = o.filter(function (r) {return Object.getOwnPropertyDescriptor(e, r).enumerable;})), t.push.apply(t, o);}return t;}function _objectSpread(e) {for (var r = 1; r < arguments.length; r++) {var t = null != arguments[r] ? arguments[r] : {};r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {_defineProperty(e, r, t[r]);}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));});}return e;} // See https://github.com/danigb/soundfont-player
2
- // for more documentation on prop options.
3
- import { useCallback, useEffect, useState } from 'react';
4
- import PropTypes from 'prop-types';
5
- import Soundfont from 'soundfont-player';
6
- import { isDefined } from './utils';
7
- // import '../temp/acoustic_grand_piano-mp3'
8
-
9
- var SoundfontProvider = function SoundfontProvider(props) {
10
- var
11
- audioContext =
12
-
13
-
14
-
15
-
16
-
17
-
18
- props.audioContext,format = props.format,hostname = props.hostname,instrumentName = props.instrumentName,onChange = props.onChange,render = props.render,soundfont = props.soundfont;
19
-
20
- var _useState = useState(true),_useState2 = _slicedToArray(_useState, 2),isLoading = _useState2[0],setIsLoading = _useState2[1];
21
- var _useState3 = useState({}),_useState4 = _slicedToArray(_useState3, 2),activeAudioNodes = _useState4[0],setActiveAudioNodes = _useState4[1];
22
- var _useState5 = useState(null),_useState6 = _slicedToArray(_useState5, 2),instrument = _useState6[0],setInstrument = _useState6[1];
23
-
24
- var loadInstrument = useCallback(function (nm) {
25
- // Re-trigger loading state
26
- setInstrument(null);
27
-
28
- if (isDefined(hostname)) {
29
- // pull from an url
30
- Soundfont.instrument(audioContext, nm, {
31
- format: format,
32
- soundfont: soundfont,
33
- nameToUrl: function nameToUrl(name, sf, fmt) {return "".concat(hostname, "/").concat(sf, "/").concat(name, "-").concat(fmt, ".js");}
34
- }).then(function (newInstrument) {
35
- setInstrument(newInstrument);
36
- });
37
- } else if (isDefined(instrumentName)) {
38
- // the host app has already injected the soundfont into global space
39
- Soundfont.
40
- instrument(audioContext, instrumentName).
41
- then(function (newInstrument) {
42
- setInstrument(newInstrument);
43
- });
44
- } else {
45
- // sound must be disabled
46
- setIsLoading(false);
47
- }
48
- }, [audioContext, format, hostname, instrumentName, soundfont]);
49
-
50
- useEffect(function () {
51
- loadInstrument(instrumentName);
52
- }, [instrumentName, loadInstrument]);
53
-
54
- useEffect(function () {
55
- if (isDefined(instrumentName)) {
56
- setIsLoading(!instrument);
57
- }
58
- }, [instrument, instrumentName]);
59
-
60
- var playNote = function playNote(midiNumber) {
61
- if (instrument) {
62
- audioContext.resume().then(function () {
63
- var audioNode = instrument.play(midiNumber);
64
- setActiveAudioNodes(function (prev) {return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, midiNumber, audioNode));});
65
- });
66
- }
67
- };
68
-
69
- var stopNote = function stopNote(midiNumber) {
70
- audioContext.resume().then(function () {
71
- if (!activeAudioNodes[midiNumber]) {
72
- return;
73
- }
74
- var audioNode = activeAudioNodes[midiNumber];
75
- audioNode.stop();
76
- setActiveAudioNodes(function (prev) {return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, midiNumber, null));});
77
- });
78
- onChange === null || onChange === void 0 || onChange(midiNumber);
79
- };
80
-
81
- // Clear any residual notes that don't get called with stopNote
82
- var stopAllNotes = function stopAllNotes() {
83
- audioContext.resume().then(function () {
84
- var nodes = Object.values(activeAudioNodes);
85
- nodes.forEach(function (node) {
86
- if (node) {
87
- node.stop();
88
- }
89
- });
90
- setActiveAudioNodes(nodes);
91
- });
92
- };
93
-
94
- return render({
95
- isLoading: isLoading,
96
- playNote: playNote,
97
- stopNote: stopNote,
98
- stopAllNotes: stopAllNotes
99
- });
100
- };
101
-
102
- SoundfontProvider.propTypes = {
103
- audioContext: PropTypes.instanceOf(window.AudioContext),
104
- format: PropTypes.oneOf(['mp3', 'ogg']),
105
- hostname: PropTypes.string,
106
- instrumentName: PropTypes.string,
107
- onChange: PropTypes.func,
108
- render: PropTypes.func.isRequired,
109
- soundfont: PropTypes.oneOf(['MusyngKite', 'FluidR3_GM'])
110
- };
111
-
112
- SoundfontProvider.defaultProps = {
113
- format: undefined, // mp3,
114
- hostname: undefined, // https://d1pzp51pvbm36p.cloudfront.net
115
- instrumentName: undefined, // acoustic_grand_piano
116
- onChange: undefined,
117
- soundfont: undefined // MusyngKite,
118
- // soundfont: 'FluidR3_GM',
119
- };
120
-
121
- // https://gleitz.github.io/midi-js-soundfonts/MusyngKite/acoustic_grand_piano-mp3.js
122
- // https://gleitz.github.io/midi-js-soundfonts/FluidR3_GM/.js
123
-
124
- export default SoundfontProvider;
@@ -1,52 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";function ownKeys(e, r) {var t = Object.keys(e);if (Object.getOwnPropertySymbols) {var o = Object.getOwnPropertySymbols(e);r && (o = o.filter(function (r) {return Object.getOwnPropertyDescriptor(e, r).enumerable;})), t.push.apply(t, o);}return t;}function _objectSpread(e) {for (var r = 1; r < arguments.length; r++) {var t = null != arguments[r] ? arguments[r] : {};r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {_defineProperty(e, r, t[r]);}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));});}return e;} /* eslint-disable no-param-reassign */
2
- var MEASUREMENT_ELEMENT_ID = '__react_svg_text_measurement_id';
3
-
4
- var calculateWordsByLines = function calculateWordsByLines(words, wordWidths, maxWidth, maxHeight) {
5
- var lineHeight = wordWidths.lineHeight,spaceWidth = wordWidths.spaceWidth,wordsWithComputedWidth = wordWidths.wordsWithComputedWidth;
6
-
7
- return words.toString().split(/\s+/).reduce(function (result, word) {
8
- var wordWidth = wordsWithComputedWidth[word];
9
- var currentLine = result[result.length - 1];
10
- if (currentLine && currentLine.width + wordWidth + spaceWidth < maxWidth) {
11
- // Word can be added to an existing line
12
- currentLine.words.push(word);
13
- currentLine.width += wordWidth + spaceWidth;
14
- } else {
15
- // Add first word to line or word is too long to scaleToFit on existing line
16
- var newLine = {
17
- words: [word],
18
- width: wordWidth,
19
- showLine: maxHeight ?
20
- lineHeight * (result.length + 1) < maxHeight :
21
- true
22
- };
23
- result.push(newLine);
24
- }
25
- return result;
26
- }, []);
27
- };
28
-
29
- var calculateWordWidths = function calculateWordWidths(style, textNode, words) {
30
- if (style && textNode) {
31
- Array.from(style).forEach(function (key) {return textNode.style.setProperty(
32
- key,
33
- style.getPropertyValue(key),
34
- style.getPropertyPriority(key)
35
- );});
36
- var wordArray = _toConsumableArray(new Set(words.toString().split(/\s+/)));
37
- var wordsWithComputedWidth = wordArray.reduce(function (wordMap, word) {
38
- textNode.textContent = word;
39
- return _objectSpread(_objectSpread({}, wordMap), {}, _defineProperty({}, word, textNode.getBBox().width));
40
- }, {});
41
- textNode.textContent = "\xA0";
42
- var spaceWidth = textNode.getComputedTextLength();
43
- var lineHeight = textNode.getBBox().height;
44
- textNode.setAttribute('style', '');
45
- return { wordsWithComputedWidth: wordsWithComputedWidth, spaceWidth: spaceWidth, lineHeight: lineHeight };
46
- }
47
- return null;
48
- };
49
-
50
- export { calculateWordWidths, calculateWordsByLines, MEASUREMENT_ELEMENT_ID };
51
-
52
- export var isDefined = function isDefined(item) {return item !== undefined && item !== null && item !== Math.NaN;};
@@ -1,19 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";import PropTypes from 'prop-types';
2
- import React, { forwardRef } from 'react';
3
- import ccValues from '../midi/ccValues';
4
- import Select from './Select';
5
-
6
- var CCPicker = /*#__PURE__*/forwardRef(function (props, ref) {return /*#__PURE__*/(
7
- React.createElement(Select, _extends({
8
- options: ccValues },
9
- props, {
10
- ref: ref })
11
- ));}
12
- );
13
-
14
- CCPicker.propTypes = {
15
- onChange: PropTypes.func.isRequired,
16
- value: PropTypes.number.isRequired
17
- };
18
-
19
- export default CCPicker;
@@ -1,79 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";var _excluded = ["channels", "className"];import React, { forwardRef, useCallback, useMemo } from 'react';
2
- import cl from 'classnames';
3
- import PropTypes from 'prop-types';
4
- import { arraySequence } from '../utils';
5
- import Select from './Select';
6
-
7
- var defaultOptions = arraySequence(16).map(function (value) {return { value: value, label: value };});
8
-
9
- var ChannelMappingPicker = /*#__PURE__*/forwardRef(function (_ref, ref) {var channels = _ref.channels,className = _ref.className,rest = _objectWithoutProperties(_ref, _excluded);
10
- var formatOptionLabel = useCallback(
11
- function (_ref2, _ref3) {var value = _ref2.value,label = _ref2.label;var context = _ref3.context;
12
- if (value === 'separator') {
13
- return /*#__PURE__*/React.createElement("span", { className: "zds-mappings-user-mapping" }, label);
14
- }
15
-
16
- var mapping = channels[value];
17
-
18
- return mapping ? /*#__PURE__*/
19
- React.createElement("span", { className: "mapping-entry" }, /*#__PURE__*/
20
- React.createElement("b", null,
21
- value + 1,
22
- context === 'value' && ' -'
23
- ), /*#__PURE__*/
24
- React.createElement("span", { className: "mapping-entry-label" }, mapping)
25
- ) : /*#__PURE__*/
26
-
27
- React.createElement("span", { className: "mapping-entry empty-mapping-entry" }, /*#__PURE__*/
28
- React.createElement("b", null,
29
- value + 1,
30
- context === 'value' && ' -'
31
- ), /*#__PURE__*/
32
- React.createElement("span", { className: "mapping-entry-label" }, "no mapping")
33
- );
34
-
35
- },
36
- [channels]
37
- );
38
-
39
- var options = useMemo(function () {
40
- var result = defaultOptions.sort(function (a, b) {
41
- if (channels[a.value] && !channels[b.value]) {
42
- return -1;
43
- }
44
-
45
- if (!channels[a.value] && channels[b.value]) {
46
- return 1;
47
- }
48
-
49
- return a.value - b.value;
50
- });
51
-
52
- var numFilled = result.filter(function (_ref4) {var value = _ref4.value;return !!channels[value];}).length;
53
-
54
- if (numFilled && numFilled < 16) {
55
- // insert a separator after the count of filled items
56
- result.splice(numFilled, 0, { label: /*#__PURE__*/React.createElement("hr", null), value: 'separator' });
57
- }
58
-
59
- return result;
60
- }, [channels]);
61
-
62
- return /*#__PURE__*/(
63
- React.createElement(Select, _extends({},
64
- rest, {
65
- className: cl(className, 'channel-mapping-picker'),
66
- formatOptionLabel: formatOptionLabel,
67
- options: options,
68
- ref: ref })
69
- ));
70
-
71
- });
72
-
73
- ChannelMappingPicker.propTypes = {
74
- channels: PropTypes.arrayOf(PropTypes.string).isRequired,
75
- onChange: PropTypes.func.isRequired,
76
- value: PropTypes.number.isRequired
77
- };
78
-
79
- export default ChannelMappingPicker;
@@ -1,40 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";var _excluded = ["className"];import React, { forwardRef, useCallback } from 'react';
2
- import PropTypes from 'prop-types';
3
- import cl from 'classnames';
4
- import { arraySequence } from '../utils';
5
- import Select from './Select';
6
-
7
- var options = arraySequence(16).map(function (value) {return {
8
- value: value,
9
- label: "Channel ".concat(value + 1)
10
- };});
11
-
12
- var ChannelPicker = /*#__PURE__*/forwardRef(function (_ref, ref) {var className = _ref.className,rest = _objectWithoutProperties(_ref, _excluded);
13
- var formatOptionLabel = useCallback(
14
- function (option, _ref2) {var context = _ref2.context;return context === 'value' ?
15
- option.label :
16
- option.value + 1;},
17
- []
18
- );
19
- return /*#__PURE__*/(
20
- React.createElement(Select, _extends({},
21
- rest, {
22
- className: cl(className, 'channel-picker'),
23
- formatOptionLabel: formatOptionLabel,
24
- options: options,
25
- ref: ref })
26
- ));
27
-
28
- });
29
-
30
- ChannelPicker.propTypes = {
31
- className: PropTypes.string,
32
- onChange: PropTypes.func.isRequired,
33
- value: PropTypes.number.isRequired
34
- };
35
-
36
- ChannelPicker.defaultProps = {
37
- className: undefined
38
- };
39
-
40
- export default ChannelPicker;
@@ -1,86 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";import _defineProperty from "@babel/runtime/helpers/defineProperty";import _slicedToArray from "@babel/runtime/helpers/slicedToArray";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";var _excluded = ["disabled", "max", "min", "onChange", "value", "wheelEnabled", "wheelSensitivity"];function ownKeys(e, r) {var t = Object.keys(e);if (Object.getOwnPropertySymbols) {var o = Object.getOwnPropertySymbols(e);r && (o = o.filter(function (r) {return Object.getOwnPropertyDescriptor(e, r).enumerable;})), t.push.apply(t, o);}return t;}function _objectSpread(e) {for (var r = 1; r < arguments.length; r++) {var t = null != arguments[r] ? arguments[r] : {};r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {_defineProperty(e, r, t[r]);}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));});}return e;}import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { Knob as RotaryKnob } from 'nebiru-react-rotary-knob';
4
- import useStateWithDynamicDefault from '../hooks/useStateWithDynamicDefault';
5
- import { assertRange } from '../utils';
6
- import knobSkin10 from './knobSkin10';
7
-
8
- var Knob = function Knob(props) {
9
- var
10
- disabled =
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
- props.disabled,max = props.max,min = props.min,onChange = props.onChange,initialValue = props.value,wheelEnabled = props.wheelEnabled,wheelSensitivity = props.wheelSensitivity,rest = _objectWithoutProperties(props, _excluded);
19
-
20
- var _useStateWithDynamicD = useStateWithDynamicDefault(initialValue),_useStateWithDynamicD2 = _slicedToArray(_useStateWithDynamicD, 2),value = _useStateWithDynamicD2[0],setValue = _useStateWithDynamicD2[1];
21
-
22
- var handleChange = function handleChange(val) {
23
- if (disabled) return;
24
-
25
- var newValue = assertRange(parseInt(val, 10), max, min);
26
- setValue(newValue);
27
- if (onChange) {
28
- onChange(newValue);
29
- }
30
- };
31
-
32
- var handleWheel = function handleWheel(_ref) {var deltaY = _ref.deltaY;
33
- var change = Math.trunc(deltaY * wheelSensitivity);
34
- if (change === 0 && deltaY !== 0) {
35
- // Assure that at least a tiny change happens
36
- change += deltaY > 0 ? 1 : -1;
37
- }
38
-
39
- handleChange(value + change);
40
- };
41
-
42
- return /*#__PURE__*/(
43
- React.createElement(RotaryKnob, _extends({
44
- clampMax: 320,
45
- clampMin: 40,
46
- className: "zds-pickers__knob-container",
47
- disabled: disabled,
48
- onChange: handleChange,
49
- onWheel: wheelEnabled ? handleWheel : undefined,
50
- preciseMode: false,
51
- rotateDegrees: 180
52
- /**
53
- * To see all skins:
54
- * http://react-rotary-knob-skins-preview.surge.sh/
55
- *
56
- * NOTE: we've copied the one we use into this package because the skins
57
- * pack package does not work in Electron.
58
- */,
59
- skin: knobSkin10,
60
- style: { opacity: disabled ? 0.4 : 1 },
61
- unlockDistance: 0 }, _objectSpread({
62
- max: max, min: min, value: value }, rest))
63
- ));
64
-
65
- };
66
-
67
- Knob.propTypes = {
68
- disabled: PropTypes.bool,
69
- max: PropTypes.number,
70
- min: PropTypes.number,
71
- wheelEnabled: PropTypes.bool,
72
- onChange: PropTypes.func,
73
- value: PropTypes.number,
74
- wheelSensitivity: PropTypes.number
75
- };
76
- Knob.defaultProps = {
77
- disabled: false,
78
- max: 127,
79
- min: 0,
80
- onChange: undefined,
81
- value: 0,
82
- wheelEnabled: false,
83
- wheelSensitivity: 0.1
84
- };
85
-
86
- export default Knob;