zds-pickers 3.10.0 → 3.11.1

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.
@@ -1,14 +1,18 @@
1
- import _extends from "@babel/runtime/helpers/extends";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";var _excluded = ["channels", "className"];import React, { forwardRef, useCallback } from 'react';
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
2
  import cl from 'classnames';
3
3
  import PropTypes from 'prop-types';
4
4
  import { arraySequence } from '../utils';
5
5
  import Select from './Select';
6
6
 
7
- var options = arraySequence(16).map(function (value) {return { value: value, label: value };});
7
+ var defaultOptions = arraySequence(16).map(function (value) {return { value: value, label: value };});
8
8
 
9
9
  var ChannelMappingPicker = /*#__PURE__*/forwardRef(function (_ref, ref) {var channels = _ref.channels,className = _ref.className,rest = _objectWithoutProperties(_ref, _excluded);
10
10
  var formatOptionLabel = useCallback(
11
- function (_ref2, _ref3) {var value = _ref2.value;var context = _ref3.context;
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
+
12
16
  var mapping = channels[value];
13
17
 
14
18
  return mapping ? /*#__PURE__*/
@@ -32,6 +36,29 @@ var ChannelMappingPicker = /*#__PURE__*/forwardRef(function (_ref, ref) {var cha
32
36
  [channels]
33
37
  );
34
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
+
35
62
  return /*#__PURE__*/(
36
63
  React.createElement(Select, _extends({},
37
64
  rest, {
@@ -1,17 +1,45 @@
1
- import _extends from "@babel/runtime/helpers/extends";import _slicedToArray from "@babel/runtime/helpers/slicedToArray";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";var _excluded = ["channel", "disabled", "mapping", "onChange", "value"];import React, { forwardRef, useCallback } from 'react';
1
+ import _extends from "@babel/runtime/helpers/extends";import _slicedToArray from "@babel/runtime/helpers/slicedToArray";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";var _excluded = ["channel", "disabled", "isMelodicMode", "mapping", "onChange", "value"];import React, { forwardRef, useCallback, useMemo } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { emptyMapping } from 'zds-mappings';
4
+ import { Midi } from 'tonal';
4
5
  import { mappingShape } from '../shapes';
5
6
  import { assertRange } from '../utils';
6
7
  import useStateWithDynamicDefault from '../hooks/useStateWithDynamicDefault';
7
8
  import Select from './Select';
8
9
 
10
+ var midiToNoteName = Midi.midiToNoteName;
11
+
9
12
  var formattedMapEntry = function formattedMapEntry(_ref) {var note = _ref.note,name = _ref.name;return "".concat(note, " ").concat(name.length ? '-' : '', " ").concat(name);};
10
13
  var formattedListEntry = function formattedListEntry(label, idx) {return { label: label, value: idx + 1 };};
11
14
 
12
15
  var NotePicker = /*#__PURE__*/forwardRef(function (props, ref) {
13
- var channel = props.channel,disabled = props.disabled,mapping = props.mapping,onChange = props.onChange,initialValue = props.value,rest = _objectWithoutProperties(props, _excluded);
14
- var options = (mapping || emptyMapping()).map(formattedMapEntry).map(formattedListEntry);
16
+ var
17
+ channel =
18
+
19
+
20
+
21
+
22
+
23
+
24
+ props.channel,disabled = props.disabled,isMelodicMode = props.isMelodicMode,mapping = props.mapping,onChange = props.onChange,initialValue = props.value,rest = _objectWithoutProperties(props, _excluded);
25
+
26
+ var options = useMemo(function () {
27
+ if (isMelodicMode) {
28
+ return emptyMapping().
29
+ map(function (_ref2) {var note = _ref2.note;
30
+ var midiNoteName = midiToNoteName(note, { sharps: false }).
31
+ replace('b', '♭').
32
+ replace('#', '♯');
33
+ return "".concat(midiNoteName, " (#").concat(note, ")");
34
+ }).
35
+ map(formattedListEntry);
36
+ }
37
+
38
+ return (mapping || emptyMapping()).
39
+ map(formattedMapEntry).
40
+ map(formattedListEntry);
41
+ }, [isMelodicMode, mapping]);
42
+
15
43
  var _useStateWithDynamicD = useStateWithDynamicDefault(initialValue),_useStateWithDynamicD2 = _slicedToArray(_useStateWithDynamicD, 2),value = _useStateWithDynamicD2[0],setValue = _useStateWithDynamicD2[1];
16
44
 
17
45
  var handleChange = useCallback(function (v) {
@@ -37,15 +65,17 @@ var NotePicker = /*#__PURE__*/forwardRef(function (props, ref) {
37
65
  });
38
66
 
39
67
  NotePicker.propTypes = {
68
+ channel: PropTypes.number.isRequired,
69
+ disabled: PropTypes.bool,
70
+ isMelodicMode: PropTypes.bool,
40
71
  mapping: PropTypes.arrayOf(mappingShape),
41
72
  onChange: PropTypes.func.isRequired,
42
- disabled: PropTypes.bool,
43
- value: PropTypes.number,
44
- channel: PropTypes.number.isRequired
73
+ value: PropTypes.number
45
74
  };
46
75
 
47
76
  NotePicker.defaultProps = {
48
77
  disabled: false,
78
+ isMelodicMode: false,
49
79
  mapping: undefined,
50
80
  value: undefined
51
81
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zds-pickers",
3
- "version": "3.10.0",
3
+ "version": "3.11.1",
4
4
  "homepage": "https://github.com/dkadrios/zds-pickers#readme",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",