dynamic-mui 1.1.0 → 1.1.2

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.
@@ -30,10 +30,11 @@ const getValue = function () {
30
30
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
31
31
  let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
32
32
  let isMultiple = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
33
+ let separator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ',';
33
34
  if (isMultiple) {
34
- let separator = ',';
35
- if (defaultValue !== null && defaultValue !== void 0 && defaultValue.includes(',')) separator = ',';else if (defaultValue !== null && defaultValue !== void 0 && defaultValue.includes(';')) separator = ';';
36
- const dValueSet = new Set(defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.split(separator));
35
+ let tempSeparator = separator;
36
+ if (defaultValue !== null && defaultValue !== void 0 && defaultValue.includes(',')) tempSeparator = ',';else if (defaultValue !== null && defaultValue !== void 0 && defaultValue.includes(';')) tempSeparator = ';';
37
+ const dValueSet = new Set(defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.split(tempSeparator));
37
38
  return options === null || options === void 0 ? void 0 : options.filter(_ref => {
38
39
  let {
39
40
  value
@@ -60,7 +61,7 @@ function Select(_ref3) {
60
61
  id = '',
61
62
  InputProps = {}
62
63
  } = attributes;
63
- const [value, setValue] = _react.default.useState((attributes === null || attributes === void 0 ? void 0 : attributes.value) && getValue(options, attributes === null || attributes === void 0 ? void 0 : attributes.value, MuiAttributes.multiple));
64
+ const [value, setValue] = _react.default.useState((attributes === null || attributes === void 0 ? void 0 : attributes.value) && getValue(options, attributes === null || attributes === void 0 ? void 0 : attributes.value, MuiAttributes.multiple, attributes === null || attributes === void 0 ? void 0 : attributes.separator));
64
65
  const getMuiAttributes = () => {
65
66
  if (MuiAttributes.multiple) {
66
67
  MuiAttributes.renderOption = function (props) {
@@ -83,20 +84,30 @@ function Select(_ref3) {
83
84
  };
84
85
  const extractValue = option => (option === null || option === void 0 ? void 0 : option.value) || (option === null || option === void 0 ? void 0 : option.title) || (option === null || option === void 0 ? void 0 : option.label);
85
86
  const onChangeEvent = (0, _react.useCallback)((event, newValue) => {
87
+ var _attributes$separator;
86
88
  setValue(newValue);
89
+
90
+ // Use attributes?.separator, default to ';'
91
+ const separator = (_attributes$separator = attributes === null || attributes === void 0 ? void 0 : attributes.separator) !== null && _attributes$separator !== void 0 ? _attributes$separator : ';';
87
92
  if (newValue) {
88
93
  const data = MuiAttributes.multiple ? newValue.map(extractValue) : extractValue(newValue);
94
+ const customValue = MuiAttributes.multiple ? data.join(separator) // <-- use custom separator here
95
+ : data;
89
96
  onChange({
90
97
  id,
91
- value: MuiAttributes.multiple ? data.toString() : data,
98
+ value: customValue,
92
99
  option: newValue
93
100
  });
94
- } else onChange({
95
- id,
96
- value: '',
97
- option: newValue
98
- });
99
- }, []);
101
+ } else {
102
+ onChange({
103
+ id,
104
+ value: '',
105
+ option: newValue
106
+ });
107
+ }
108
+ }, [id, onChange, attributes === null || attributes === void 0 ? void 0 : attributes.separator,
109
+ // so changes to separator update the callback
110
+ MuiAttributes.multiple, extractValue]);
100
111
  return /*#__PURE__*/_react.default.createElement(_Autocomplete.default, _extends({
101
112
  disablePortal: false
102
113
  }, getMuiAttributes(), {
@@ -12,37 +12,74 @@ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
12
12
  var _material = require("@mui/material");
13
13
  var _xDatePickers = require("@mui/x-date-pickers");
14
14
  var _react = _interopRequireDefault(require("react"));
15
+ const _excluded = ["xs", "sm", "md", "lg", "xl", "size"];
15
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
16
18
  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; }
17
19
  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; }
18
20
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
19
21
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
20
22
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
21
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
23
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
24
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
22
25
  function generateLayout(data) {
23
26
  const layout = {
24
27
  wrows: [],
25
28
  worows: []
26
29
  };
27
- // All Items
28
30
  const wrows = (0, _lodash.clone)(data);
29
- // Remove Without Rows
30
- layout.worows = (0, _lodash.remove)(wrows, item => {
31
+
32
+ // Items without a row -> worows
33
+ const removed = (0, _lodash.remove)(wrows, item => {
31
34
  const isLayout = item.layout ? item.layout.row : item.layout;
32
35
  return isLayout === undefined;
33
- }); // Concat all items without rows
36
+ });
37
+
38
+ // Create a new item with MUI v7-friendly layout.size (no param reassign)
39
+ const normalizeItem = it => {
40
+ var _it$layout;
41
+ const l = (_it$layout = it.layout) !== null && _it$layout !== void 0 ? _it$layout : {};
42
+ const computedSize = (() => {
43
+ if (l.size && typeof l.size === 'object') return l.size;
44
+ const s = {};
45
+ if (l.xs != null) s.xs = l.xs;
46
+ if (l.sm != null) s.sm = l.sm;
47
+ if (l.md != null) s.md = l.md;
48
+ if (l.lg != null) s.lg = l.lg;
49
+ if (l.xl != null) s.xl = l.xl;
50
+ return Object.keys(s).length ? s : {
51
+ xs: 12
52
+ };
53
+ })();
34
54
 
35
- // All row indices
55
+ // strip legacy breakpoint keys; keep everything else on layout
56
+ const {
57
+ xs,
58
+ sm,
59
+ md,
60
+ lg,
61
+ xl,
62
+ size
63
+ } = l,
64
+ restLayout = _objectWithoutProperties(l, _excluded);
65
+ const normalizedLayout = _objectSpread(_objectSpread({}, restLayout), {}, {
66
+ size: size !== null && size !== void 0 ? size : computedSize
67
+ });
68
+ return _objectSpread(_objectSpread({}, it), {}, {
69
+ layout: normalizedLayout
70
+ });
71
+ };
72
+ layout.worows = removed.map(normalizeItem);
73
+
74
+ // Group remaining items by row
36
75
  const rowIndex = (0, _lodash.map)(wrows, 'layout.row');
37
76
  const uniqIndex = (0, _lodash.uniq)(rowIndex);
38
77
  const sortedIndex = (0, _lodash.sortBy)(uniqIndex);
39
78
  (0, _lodash.each)(sortedIndex, value => {
40
79
  const rows = [];
41
- (0, _lodash.each)(wrows, item => {
42
- if (item.layout) {
43
- if (item.layout.row === value) {
44
- rows.push(item);
45
- }
80
+ (0, _lodash.each)(wrows, it => {
81
+ if (it.layout && it.layout.row === value) {
82
+ rows.push(normalizeItem(it));
46
83
  }
47
84
  });
48
85
  layout.wrows.push(rows);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dynamic-mui",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "author": "Dinakaran S",
5
5
  "user": "dinakarans",
6
6
  "repository": {
@@ -28,7 +28,7 @@
28
28
  "@testing-library/react": "^16.1.0",
29
29
  "@testing-library/user-event": "^14.5.2",
30
30
  "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
31
- "dayjs": "^1.11.13",
31
+ "dayjs": "^1.11.19",
32
32
  "lodash": "^4.17.21",
33
33
  "numeral": "^2.0.6",
34
34
  "prop-types": "^15.8.1",