@panneau/core 1.0.0-alpha.97 → 1.0.3-alpha.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.
package/es/contexts.js CHANGED
@@ -13,7 +13,7 @@ import { loadGoogleApi, loadGoogleMaps } from '@folklore/services';
13
13
  import { useIntl } from 'react-intl';
14
14
  import { getDisplayName } from '@panneau/core/utils';
15
15
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
16
- import { generatePath, useHistory } from 'react-router';
16
+ import { generatePath, useNavigate } from 'react-router';
17
17
  import { TrackingContext, TrackingContainer } from '@folklore/tracking';
18
18
  export { TrackingContext } from '@folklore/tracking';
19
19
  import { v1 } from 'uuid';
@@ -233,6 +233,14 @@ var toggle = PropTypes.shape({
233
233
  label: PropTypes.string
234
234
  });
235
235
  PropTypes.arrayOf(toggle);
236
+ var tableColumn = PropTypes.shape({
237
+ id: PropTypes.string,
238
+ component: PropTypes.string,
239
+ path: PropTypes.string,
240
+ field: PropTypes.string,
241
+ columnClassName: PropTypes.string
242
+ });
243
+ PropTypes.arrayOf(tableColumn);
236
244
  /**
237
245
  * Panneau Definitions
238
246
  */
@@ -257,8 +265,7 @@ var page = PropTypes.shape({
257
265
  });
258
266
  var pages = PropTypes.objectOf(page);
259
267
  var field = PropTypes.shape({
260
- // type: PropTypes.string.isRequired,
261
- name: PropTypes.isRequired,
268
+ name: PropTypes.string.isRequired,
262
269
  type: PropTypes.string,
263
270
  component: PropTypes.string,
264
271
  label: PropTypes.node
@@ -316,6 +323,8 @@ PropTypes.shape({
316
323
  tus: PropTypes.object
317
324
  }); // eslint-disable-line
318
325
 
326
+ PropTypes.string;
327
+
319
328
  /* eslint-disable react/jsx-props-no-spreading */
320
329
  var DefinitionContext = /*#__PURE__*/React.createContext(null);
321
330
  var useDefinitionContext = function useDefinitionContext() {
@@ -932,6 +941,7 @@ var PanelsProvider = function PanelsProvider(_ref2) {
932
941
  PanelsProvider.propTypes = propTypes$5;
933
942
  PanelsProvider.defaultProps = defaultProps$5;
934
943
 
944
+ var _excluded$3 = ["component"];
935
945
  var PanneauContext = /*#__PURE__*/React.createContext(null);
936
946
  var usePanneau = function usePanneau() {
937
947
  return useContext(PanneauContext);
@@ -988,7 +998,7 @@ var usePanneauComponent = function usePanneauComponent(namespace, name) {
988
998
  if (isObject(component) && isString(component === null || component === void 0 ? void 0 : component.componnent)) {
989
999
  // eslint-disable-next-line no-unused-vars
990
1000
  component.component;
991
- _objectWithoutProperties(component, ["component"]);
1001
+ _objectWithoutProperties(component, _excluded$3);
992
1002
 
993
1003
  return component.component;
994
1004
  }
@@ -1066,14 +1076,16 @@ var useUrlGenerator = function useUrlGenerator() {
1066
1076
  };
1067
1077
  var useRoutePush = function useRoutePush() {
1068
1078
  var url = useUrlGenerator();
1069
- var history = useHistory();
1079
+ var navigate = useNavigate();
1070
1080
  var push = useCallback(function (route, data) {
1071
1081
  for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
1072
1082
  args[_key - 2] = arguments[_key];
1073
1083
  }
1074
1084
 
1075
1085
  if (isString(route)) {
1076
- history.push.apply(history, [url(route, data)].concat(args));
1086
+ var _history;
1087
+
1088
+ (_history = history).push.apply(_history, [url(route, data)].concat(args));
1077
1089
  } else {
1078
1090
  var _ref = route || {},
1079
1091
  _ref$pathname = _ref.pathname,
@@ -1081,20 +1093,20 @@ var useRoutePush = function useRoutePush() {
1081
1093
  _ref$search = _ref.search,
1082
1094
  search = _ref$search === void 0 ? null : _ref$search;
1083
1095
 
1084
- history.push.apply(history, [{
1096
+ navigate.apply(void 0, [{
1085
1097
  pathname: url(pathname, data),
1086
1098
  search: search
1087
1099
  }].concat(args));
1088
1100
  }
1089
- }, [history, url]);
1101
+ }, [navigate, url]);
1090
1102
  return push;
1091
1103
  };
1092
1104
  var useRouteBack = function useRouteBack() {
1093
1105
  var url = useUrlGenerator();
1094
- var history = useHistory();
1106
+ var navigate = useNavigate();
1095
1107
  var back = useCallback(function () {
1096
- return history.goBack();
1097
- }, [history, url]);
1108
+ return navigate(-1);
1109
+ }, [navigate, url]);
1098
1110
  return back;
1099
1111
  };
1100
1112
  var propTypes$2 = {
@@ -1178,7 +1190,7 @@ var useUppyCore = function useUppyCore() {
1178
1190
  }
1179
1191
 
1180
1192
  import('@uppy/core').then(function (_ref) {
1181
- var Uppy = _ref.Uppy;
1193
+ var Uppy = _ref["default"];
1182
1194
  packageCache = Uppy;
1183
1195
 
1184
1196
  if (!canceled) {
@@ -1247,6 +1259,7 @@ var useUppyLocale = function useUppyLocale(locale) {
1247
1259
  return loadedPackage;
1248
1260
  };
1249
1261
 
1262
+ var _excluded$2 = ["default"];
1250
1263
  /**
1251
1264
  * Locale loader
1252
1265
  */
@@ -1320,7 +1333,7 @@ var useUppySources = function useUppySources(sources) {
1320
1333
  var newLoadedPackages = sourcesToLoad.reduce(function (map, source, index) {
1321
1334
  var _packagesLoaded$index = packagesLoaded[index],
1322
1335
  pack = _packagesLoaded$index["default"],
1323
- others = _objectWithoutProperties(_packagesLoaded$index, ["default"]);
1336
+ others = _objectWithoutProperties(_packagesLoaded$index, _excluded$2);
1324
1337
 
1325
1338
  return _objectSpread(_objectSpread({}, map), {}, _defineProperty({}, source, Object.keys(others).reduce(function (otherMap, key) {
1326
1339
  otherMap[key] = others[key]; // eslint-disable-line no-param-reassign
@@ -1343,6 +1356,7 @@ var useUppySources = function useUppySources(sources) {
1343
1356
  return sourcesToLoad.length === 0 ? loadedPackages : null;
1344
1357
  };
1345
1358
 
1359
+ var _excluded$1 = ["default"];
1346
1360
  /**
1347
1361
  * Locale loader
1348
1362
  */
@@ -1385,7 +1399,7 @@ var useUppyTransport = function useUppyTransport(transport) {
1385
1399
 
1386
1400
  packageLoader().then(function (_ref2) {
1387
1401
  var pack = _ref2["default"],
1388
- others = _objectWithoutProperties(_ref2, ["default"]);
1402
+ others = _objectWithoutProperties(_ref2, _excluded$1);
1389
1403
 
1390
1404
  var dep = Object.keys(others).reduce(function (map, key) {
1391
1405
  map[key] = others[key]; // eslint-disable-line no-param-reassign
@@ -1450,6 +1464,8 @@ var getTransloaditMediasFromResponse = function getTransloaditMediasFromResponse
1450
1464
  });
1451
1465
  };
1452
1466
 
1467
+ var _excluded = ["sources"],
1468
+ _excluded2 = ["key", "templateId", "waitForEncoding"];
1453
1469
  var UppyContext = /*#__PURE__*/React.createContext(null);
1454
1470
  var useUppy = function useUppy() {
1455
1471
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
@@ -1553,6 +1569,7 @@ var useUppy = function useUppy() {
1553
1569
  return uppy;
1554
1570
  };
1555
1571
  var propTypes = {
1572
+ id: PropTypes.string,
1556
1573
  children: PropTypes.node.isRequired,
1557
1574
  transport: PropTypes.oneOf(['xhr', 'transloadit', 'tus']),
1558
1575
  locale: PropTypes.string,
@@ -1574,6 +1591,7 @@ var propTypes = {
1574
1591
  })])
1575
1592
  };
1576
1593
  var defaultProps = {
1594
+ id: 'uppy',
1577
1595
  transport: null,
1578
1596
  locale: null,
1579
1597
  sources: null,
@@ -1583,7 +1601,8 @@ var defaultProps = {
1583
1601
  xhr: null
1584
1602
  };
1585
1603
  var UppyProvider = function UppyProvider(_ref5) {
1586
- var children = _ref5.children,
1604
+ var id = _ref5.id,
1605
+ children = _ref5.children,
1587
1606
  providedTransport = _ref5.transport,
1588
1607
  providedLocale = _ref5.locale,
1589
1608
  providedSources = _ref5.sources,
@@ -1633,9 +1652,10 @@ var UppyProvider = function UppyProvider(_ref5) {
1633
1652
  var _ref7 = opts || {},
1634
1653
  _ref7$sources = _ref7.sources,
1635
1654
  customSources = _ref7$sources === void 0 ? sources : _ref7$sources,
1636
- uppyOpts = _objectWithoutProperties(_ref7, ["sources"]);
1655
+ uppyOpts = _objectWithoutProperties(_ref7, _excluded);
1637
1656
 
1638
1657
  var newUppy = new Uppy(_objectSpread({
1658
+ id: id,
1639
1659
  locale: uppyLocale
1640
1660
  }, uppyOpts));
1641
1661
 
@@ -1644,7 +1664,7 @@ var UppyProvider = function UppyProvider(_ref5) {
1644
1664
  templateId = transloadit.templateId,
1645
1665
  _transloadit$waitForE = transloadit.waitForEncoding,
1646
1666
  waitForEncoding = _transloadit$waitForE === void 0 ? true : _transloadit$waitForE,
1647
- transloaditOpts = _objectWithoutProperties(transloadit, ["key", "templateId", "waitForEncoding"]);
1667
+ transloaditOpts = _objectWithoutProperties(transloadit, _excluded2);
1648
1668
 
1649
1669
  newUppy.use(uppyTransport, {
1650
1670
  params: _objectSpread({
@@ -1692,9 +1712,10 @@ var UppyProvider = function UppyProvider(_ref5) {
1692
1712
 
1693
1713
  return newUppy;
1694
1714
  };
1695
- }, [Uppy, uppyLocale, uppyTransport, uppySources, transport, sources, transloadit, companion, tus, xhr]);
1696
- return /*#__PURE__*/React.createElement(UppyContext.Provider, {
1697
- value: {
1715
+ }, [id, Uppy, uppyLocale, uppyTransport, uppySources, transport, sources, transloadit, companion, tus, xhr]);
1716
+ var value = useMemo(function () {
1717
+ return {
1718
+ id: id,
1698
1719
  transport: transport,
1699
1720
  locale: locale,
1700
1721
  sources: sources,
@@ -1707,7 +1728,10 @@ var UppyProvider = function UppyProvider(_ref5) {
1707
1728
  uppySources: uppySources,
1708
1729
  uppyLocale: uppyLocale,
1709
1730
  buildUppy: buildUppy
1710
- }
1731
+ };
1732
+ }, [id, transport, locale, sources, transloadit, companion, tus, xhr, Uppy, uppyTransport, uppySources, uppyLocale, buildUppy]);
1733
+ return /*#__PURE__*/React.createElement(UppyContext.Provider, {
1734
+ value: value
1711
1735
  }, children);
1712
1736
  };
1713
1737
  UppyProvider.propTypes = propTypes;
package/es/hooks.js CHANGED
@@ -10,6 +10,8 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
10
10
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
11
11
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
12
12
  import { getCsrfToken, postJSON, getCSRFHeaders } from '@folklore/fetch';
13
+ import get from 'lodash/get';
14
+ import isArray from 'lodash/isArray';
13
15
  import isObject from 'lodash/isObject';
14
16
  import { useFieldsManager, usePanneauResources, useResource, useUrlGenerator } from '@panneau/core/contexts';
15
17
  import { match } from 'css-mediaquery';
@@ -108,12 +110,15 @@ var useFormattedTime = function useFormattedTime() {
108
110
  var eventsManager$1 = typeof document !== 'undefined' ? new EventsManager(document) : null;
109
111
  var useDocumentEvent = createUseEvent(eventsManager$1);
110
112
 
113
+ var _excluded$1 = ["value", "errors", "onChange"];
114
+
111
115
  var getFieldsPropsFromFields = function getFieldsPropsFromFields(fields, _ref) {
112
116
  var value = _ref.value,
113
117
  errors = _ref.errors,
114
118
  _onChange = _ref.onChange,
115
- props = _objectWithoutProperties(_ref, ["value", "errors", "onChange"]);
119
+ props = _objectWithoutProperties(_ref, _excluded$1);
116
120
 
121
+ var locales = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
117
122
  return fields.reduce(function (allFields, field) {
118
123
  var _ref2 = isObject(field) ? field : {},
119
124
  _ref2$name = _ref2.name,
@@ -121,11 +126,18 @@ var getFieldsPropsFromFields = function getFieldsPropsFromFields(fields, _ref) {
121
126
  _ref2$component = _ref2.component,
122
127
  component = _ref2$component === void 0 ? null : _ref2$component;
123
128
 
129
+ var fieldErrors = errors !== null ? errors[name] || [] : [];
130
+ var localizedErrors = component === 'localized' ? (locales || []).reduce(function (previousErrors, locale) {
131
+ var items = errors !== null ? get(errors, "".concat(name, ".").concat(locale), []) || [] : [];
132
+ var finalItems = isArray(items) ? items : [items];
133
+ var finalPrevious = isArray(previousErrors) ? previousErrors : [];
134
+ return [].concat(_toConsumableArray(finalPrevious), _toConsumableArray(finalItems));
135
+ }, fieldErrors) : fieldErrors;
124
136
  return [].concat(_toConsumableArray(allFields), [_objectSpread(_objectSpread({}, isObject(field) ? field : null), {}, {
125
137
  name: name,
126
138
  component: component,
127
139
  value: value !== null ? value[name] || null : null,
128
- errors: errors !== null ? errors[name] || null : null,
140
+ errors: localizedErrors.length > 0 ? localizedErrors : null,
129
141
  onChange: function onChange(fieldValue) {
130
142
  return _onChange(name, fieldValue);
131
143
  }
@@ -160,7 +172,9 @@ var useForm = function useForm() {
160
172
  _opts$setValue = opts.setValue,
161
173
  setProvidedValue = _opts$setValue === void 0 ? null : _opts$setValue,
162
174
  _opts$onComplete = opts.onComplete,
163
- onComplete = _opts$onComplete === void 0 ? null : _opts$onComplete;
175
+ onComplete = _opts$onComplete === void 0 ? null : _opts$onComplete,
176
+ _opts$locales = opts.locales,
177
+ locales = _opts$locales === void 0 ? [] : _opts$locales;
164
178
 
165
179
  var _useState = useState(initialValue || providedValue),
166
180
  _useState2 = _slicedToArray(_useState, 2),
@@ -200,7 +214,7 @@ var useForm = function useForm() {
200
214
  var hasProvidedGeneralError = setProvidedGeneralError !== null;
201
215
  var generalError = hasProvidedGeneralError ? providedGeneralError : stateGeneralError;
202
216
  var setGeneralError = hasProvidedGeneralError ? setProvidedGeneralError : setStateGeneralError;
203
- var fieldsKey = [value, errors].concat(fields);
217
+ var fieldsKey = [value, errors, locales].concat(fields);
204
218
  var onFieldChange = useCallback(function (fieldName, fieldValue) {
205
219
  var fieldErrors = errors !== null ? errors[fieldName] || null : null;
206
220
 
@@ -215,7 +229,7 @@ var useForm = function useForm() {
215
229
  value: value,
216
230
  errors: errors,
217
231
  onChange: onFieldChange
218
- });
232
+ }, locales);
219
233
  }, fieldsKey);
220
234
  var csrfToken = useMemo(function () {
221
235
  return getCsrfToken();
@@ -246,7 +260,10 @@ var useForm = function useForm() {
246
260
  error: false
247
261
  });
248
262
  setResponse(resp);
249
- onComplete(resp);
263
+
264
+ if (onComplete !== null) {
265
+ onComplete(resp);
266
+ }
250
267
  };
251
268
 
252
269
  var finalPostForm = useCallback(function (postAction, postData) {
@@ -974,6 +991,8 @@ var useResourceUrlGenerator = function useResourceUrlGenerator() {
974
991
  };
975
992
  };
976
993
 
994
+ var _excluded = ["width", "height"];
995
+
977
996
  var useScreenSize = function useScreenSize(_ref) {
978
997
  var _ref$width = _ref.width,
979
998
  width = _ref$width === void 0 ? null : _ref$width,
@@ -1021,7 +1040,7 @@ var useScreenSizeFromElement = function useScreenSizeFromElement() {
1021
1040
  width = _ref4$width === void 0 ? null : _ref4$width,
1022
1041
  _ref4$height = _ref4.height,
1023
1042
  height = _ref4$height === void 0 ? null : _ref4$height,
1024
- opts = _objectWithoutProperties(_ref4, ["width", "height"]);
1043
+ opts = _objectWithoutProperties(_ref4, _excluded);
1025
1044
 
1026
1045
  var _useResizeObserver = useResizeObserver(),
1027
1046
  ref = _useResizeObserver.ref,
package/es/index.js CHANGED
@@ -16,6 +16,8 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
16
16
  import 'lodash/isString';
17
17
  import isArray from 'lodash/isArray';
18
18
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
19
+ import 'lodash/get';
20
+ import 'lodash/capitalize';
19
21
  import 'slugify';
20
22
  import uniqBy from 'lodash/uniqBy';
21
23
  import uniq from 'lodash/uniq';
@@ -61,6 +63,14 @@ var toggle = PropTypes$1.shape({
61
63
  label: PropTypes$1.string
62
64
  });
63
65
  var toggles = PropTypes$1.arrayOf(toggle);
66
+ var tableColumn = PropTypes$1.shape({
67
+ id: PropTypes$1.string,
68
+ component: PropTypes$1.string,
69
+ path: PropTypes$1.string,
70
+ field: PropTypes$1.string,
71
+ columnClassName: PropTypes$1.string
72
+ });
73
+ var tableColumns = PropTypes$1.arrayOf(tableColumn);
64
74
  /**
65
75
  * Panneau Definitions
66
76
  */
@@ -85,8 +95,7 @@ var page = PropTypes$1.shape({
85
95
  });
86
96
  var pages = PropTypes$1.objectOf(page);
87
97
  var field = PropTypes$1.shape({
88
- // type: PropTypes.string.isRequired,
89
- name: PropTypes$1.isRequired,
98
+ name: PropTypes$1.string.isRequired,
90
99
  type: PropTypes$1.string,
91
100
  component: PropTypes$1.string,
92
101
  label: PropTypes$1.node
@@ -144,6 +153,8 @@ var uppy = PropTypes$1.shape({
144
153
  tus: PropTypes$1.object
145
154
  }); // eslint-disable-line
146
155
 
156
+ var triggerUpdate = PropTypes$1.string;
157
+
147
158
  var PropTypes = /*#__PURE__*/Object.freeze({
148
159
  __proto__: null,
149
160
  message: message,
@@ -163,6 +174,8 @@ var PropTypes = /*#__PURE__*/Object.freeze({
163
174
  fieldOptions: fieldOptions,
164
175
  toggle: toggle,
165
176
  toggles: toggles,
177
+ tableColumn: tableColumn,
178
+ tableColumns: tableColumns,
166
179
  routes: routes,
167
180
  intl: intl,
168
181
  page: page,
@@ -184,7 +197,8 @@ var PropTypes = /*#__PURE__*/Object.freeze({
184
197
  feedback: feedback,
185
198
  formError: formError,
186
199
  formErrors: formErrors,
187
- uppy: uppy
200
+ uppy: uppy,
201
+ triggerUpdate: triggerUpdate
188
202
  });
189
203
 
190
204
  var flattenComponents = function flattenComponents(components) {
@@ -471,9 +485,11 @@ var FieldsManager$1 = /*#__PURE__*/function (_DefinitionsManager) {
471
485
  return _super.apply(this, arguments);
472
486
  }
473
487
 
474
- return FieldsManager;
488
+ return _createClass(FieldsManager);
475
489
  }(DefinitionsManager);
476
490
 
491
+ var _excluded$2 = ["fonts"];
492
+
477
493
  var FontsParser = /*#__PURE__*/function () {
478
494
  function FontsParser(_ref) {
479
495
  var fieldsManager = _ref.fieldsManager,
@@ -519,7 +535,7 @@ var FontsParser = /*#__PURE__*/function () {
519
535
  var _this$parse = this.parse(theme),
520
536
  _this$parse$fonts = _this$parse.fonts,
521
537
  themeFonts = _this$parse$fonts === void 0 ? [] : _this$parse$fonts,
522
- newTheme = _objectWithoutProperties(_this$parse, ["fonts"]);
538
+ newTheme = _objectWithoutProperties(_this$parse, _excluded$2);
523
539
 
524
540
  return fonts.length > 0 || themeFonts.length > 0 ? _objectSpread(_objectSpread({}, story), {}, {
525
541
  theme: newTheme,
@@ -614,9 +630,11 @@ var FieldsManager = /*#__PURE__*/function (_ComponentsManager) {
614
630
  return _super.apply(this, arguments);
615
631
  }
616
632
 
617
- return FieldsManager;
633
+ return _createClass(FieldsManager);
618
634
  }(ComponentsManager);
619
635
 
636
+ var _excluded$1 = ["medias"];
637
+
620
638
  var MediasParser = /*#__PURE__*/function () {
621
639
  function MediasParser(_ref) {
622
640
  var fieldsManager = _ref.fieldsManager,
@@ -673,7 +691,7 @@ var MediasParser = /*#__PURE__*/function () {
673
691
  if (theme !== null) {
674
692
  var _this$toPath = this.toPath(theme),
675
693
  themeMedias = _this$toPath.medias,
676
- newTheme = _objectWithoutProperties(_this$toPath, ["medias"]);
694
+ newTheme = _objectWithoutProperties(_this$toPath, _excluded$1);
677
695
 
678
696
  return medias !== null || themeMedias !== null ? _objectSpread(_objectSpread({}, story), {}, {
679
697
  theme: newTheme,
@@ -856,6 +874,9 @@ var MediasParser = /*#__PURE__*/function () {
856
874
  return MediasParser;
857
875
  }();
858
876
 
877
+ var _excluded = ["value"],
878
+ _excluded2 = ["value"];
879
+
859
880
  var Tracking = /*#__PURE__*/function (_BaseTracking) {
860
881
  _inherits(Tracking, _BaseTracking);
861
882
 
@@ -917,7 +938,7 @@ var Tracking = /*#__PURE__*/function (_BaseTracking) {
917
938
  var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
918
939
  _ref2$value = _ref2.value,
919
940
  value = _ref2$value === void 0 ? null : _ref2$value,
920
- opts = _objectWithoutProperties(_ref2, ["value"]);
941
+ opts = _objectWithoutProperties(_ref2, _excluded);
921
942
 
922
943
  var data = _objectSpread(_objectSpread({}, opts), {}, {
923
944
  event: 'eventInteraction',
@@ -935,7 +956,7 @@ var Tracking = /*#__PURE__*/function (_BaseTracking) {
935
956
  var _ref3 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
936
957
  _ref3$value = _ref3.value,
937
958
  value = _ref3$value === void 0 ? null : _ref3$value,
938
- opts = _objectWithoutProperties(_ref3, ["value"]);
959
+ opts = _objectWithoutProperties(_ref3, _excluded2);
939
960
 
940
961
  var _ref4 = media || {},
941
962
  _ref4$id = _ref4.id,
package/es/utils.js CHANGED
@@ -11,6 +11,8 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
11
11
  import isString from 'lodash/isString';
12
12
  import isArray from 'lodash/isArray';
13
13
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
14
+ import get from 'lodash/get';
15
+ import capitalize from 'lodash/capitalize';
14
16
  import slugify from 'slugify';
15
17
 
16
18
  var convertStyleToString = function convertStyleToString(style) {
@@ -69,12 +71,14 @@ var flattenComponents = function flattenComponents(components) {
69
71
  }, {});
70
72
  };
71
73
 
74
+ var _excluded$1 = ["component"];
75
+
72
76
  var getComponent = function getComponent(component) {
73
77
  var _ref = isObject(component) ? component : {
74
78
  component: component
75
79
  };
76
80
  _ref.component;
77
- var props = _objectWithoutProperties(_ref, ["component"]);
81
+ var props = _objectWithoutProperties(_ref, _excluded$1);
78
82
 
79
83
  return {
80
84
  name: component,
@@ -82,6 +86,7 @@ var getComponent = function getComponent(component) {
82
86
  };
83
87
  };
84
88
 
89
+ var _excluded = ["field"];
85
90
  var getColumnFromField = function getColumnFromField(field) {
86
91
  if (field === null) {
87
92
  return null;
@@ -117,7 +122,7 @@ var getColumnsWithFields = function getColumnsWithFields(resource, columns) {
117
122
  } : column,
118
123
  _ref$field = _ref.field,
119
124
  fieldName = _ref$field === void 0 ? null : _ref$field,
120
- otherProps = _objectWithoutProperties(_ref, ["field"]);
125
+ otherProps = _objectWithoutProperties(_ref, _excluded);
121
126
 
122
127
  return _objectSpread(_objectSpread({}, fieldName !== null ? getColumnFromField(fields.find(function (it) {
123
128
  return it.name === fieldName;
@@ -236,11 +241,36 @@ var getFileName = function getFileName() {
236
241
  return url.match(/([^/]+)(\?.*)?$/)[1] || url;
237
242
  };
238
243
 
244
+ var getPathValue = function getPathValue(it, path) {
245
+ var value = get(it, path, null);
246
+ return value !== null && isObject(value) ? Object.values(value).reduce(function (foundValue, value) {
247
+ return foundValue !== null ? foundValue : value;
248
+ }, null) : value;
249
+ };
250
+
239
251
  var getSelectOptions = function getSelectOptions(options) {
240
252
  return options.map(function (it) {
241
- return isObject(it) ? it : {
253
+ if (isObject(it)) {
254
+ var _it$label = it.label,
255
+ label = _it$label === void 0 ? null : _it$label,
256
+ value = it.value;
257
+
258
+ if (label === null) {
259
+ return {
260
+ value: value,
261
+ label: capitalize("".concat(value))
262
+ };
263
+ }
264
+
265
+ return {
266
+ value: value,
267
+ label: "".concat(label)
268
+ };
269
+ }
270
+
271
+ return {
242
272
  value: it,
243
- label: it
273
+ label: capitalize("".concat(it))
244
274
  };
245
275
  });
246
276
  };
@@ -296,4 +326,4 @@ var validateFields = function validateFields(fields, value) {
296
326
  }, true);
297
327
  };
298
328
 
299
- export { convertStyleToString, createNullableOnChange, createUseEvent, flattenComponents, getColumnsWithFields, getComponent, getComponentFromName, getDefinitionFromId, getDisplayName, getFieldByName, getFieldFromPath, getFileName, getSelectOptions, isMessage, setValue as setFieldValue, slug, validateFields };
329
+ export { convertStyleToString, createNullableOnChange, createUseEvent, flattenComponents, getColumnsWithFields, getComponent, getComponentFromName, getDefinitionFromId, getDisplayName, getFieldByName, getFieldFromPath, getFileName, getPathValue, getSelectOptions, isMessage, setValue as setFieldValue, slug, validateFields };